|
14 | 14 | #include <linux/err.h>
|
15 | 15 | #include <linux/iopoll.h>
|
16 | 16 | #include <linux/kernel.h>
|
| 17 | +#include <linux/memory/ti-aemif.h> |
17 | 18 | #include <linux/module.h>
|
18 | 19 | #include <linux/mtd/partitions.h>
|
19 | 20 | #include <linux/mtd/rawnand.h>
|
|
44 | 45 | #define MASK_ALE 0x08
|
45 | 46 | #define MASK_CLE 0x10
|
46 | 47 |
|
| 48 | +#define MAX_TSU_PS 3000 /* Input setup time in ps */ |
| 49 | +#define MAX_TH_PS 1600 /* Input hold time in ps */ |
| 50 | + |
47 | 51 | struct davinci_nand_pdata {
|
48 | 52 | uint32_t mask_ale;
|
49 | 53 | uint32_t mask_cle;
|
@@ -121,6 +125,7 @@ struct davinci_nand_info {
|
121 | 125 | uint32_t core_chipsel;
|
122 | 126 |
|
123 | 127 | struct clk *clk;
|
| 128 | + struct aemif_device *aemif; |
124 | 129 | };
|
125 | 130 |
|
126 | 131 | static DEFINE_SPINLOCK(davinci_nand_lock);
|
@@ -771,9 +776,82 @@ static int davinci_nand_exec_op(struct nand_chip *chip,
|
771 | 776 | return 0;
|
772 | 777 | }
|
773 | 778 |
|
| 779 | +#define TO_CYCLES(ps, period_ns) (DIV_ROUND_UP((ps) / 1000, (period_ns))) |
| 780 | + |
| 781 | +static int davinci_nand_setup_interface(struct nand_chip *chip, int chipnr, |
| 782 | + const struct nand_interface_config *conf) |
| 783 | +{ |
| 784 | + struct davinci_nand_info *info = to_davinci_nand(nand_to_mtd(chip)); |
| 785 | + const struct nand_sdr_timings *sdr; |
| 786 | + struct aemif_cs_timings timings; |
| 787 | + s32 cfg, min, cyc_ns; |
| 788 | + int ret; |
| 789 | + |
| 790 | + cyc_ns = 1000000000 / clk_get_rate(info->clk); |
| 791 | + |
| 792 | + sdr = nand_get_sdr_timings(conf); |
| 793 | + if (IS_ERR(sdr)) |
| 794 | + return PTR_ERR(sdr); |
| 795 | + |
| 796 | + cfg = TO_CYCLES(sdr->tCLR_min, cyc_ns) - 1; |
| 797 | + timings.rsetup = cfg > 0 ? cfg : 0; |
| 798 | + |
| 799 | + cfg = max_t(s32, TO_CYCLES(sdr->tREA_max + MAX_TSU_PS, cyc_ns), |
| 800 | + TO_CYCLES(sdr->tRP_min, cyc_ns)) - 1; |
| 801 | + timings.rstrobe = cfg > 0 ? cfg : 0; |
| 802 | + |
| 803 | + min = TO_CYCLES(sdr->tCEA_max + MAX_TSU_PS, cyc_ns) - 2; |
| 804 | + while ((s32)(timings.rsetup + timings.rstrobe) < min) |
| 805 | + timings.rstrobe++; |
| 806 | + |
| 807 | + cfg = TO_CYCLES((s32)(MAX_TH_PS - sdr->tCHZ_max), cyc_ns) - 1; |
| 808 | + timings.rhold = cfg > 0 ? cfg : 0; |
| 809 | + |
| 810 | + min = TO_CYCLES(sdr->tRC_min, cyc_ns) - 3; |
| 811 | + while ((s32)(timings.rsetup + timings.rstrobe + timings.rhold) < min) |
| 812 | + timings.rhold++; |
| 813 | + |
| 814 | + cfg = TO_CYCLES((s32)(sdr->tRHZ_max - (timings.rhold + 1) * cyc_ns * 1000), cyc_ns); |
| 815 | + cfg = max_t(s32, cfg, TO_CYCLES(sdr->tCHZ_max, cyc_ns)) - 1; |
| 816 | + timings.ta = cfg > 0 ? cfg : 0; |
| 817 | + |
| 818 | + cfg = TO_CYCLES(sdr->tWP_min, cyc_ns) - 1; |
| 819 | + timings.wstrobe = cfg > 0 ? cfg : 0; |
| 820 | + |
| 821 | + cfg = max_t(s32, TO_CYCLES(sdr->tCLS_min, cyc_ns), TO_CYCLES(sdr->tALS_min, cyc_ns)); |
| 822 | + cfg = max_t(s32, cfg, TO_CYCLES(sdr->tCS_min, cyc_ns)) - 1; |
| 823 | + timings.wsetup = cfg > 0 ? cfg : 0; |
| 824 | + |
| 825 | + min = TO_CYCLES(sdr->tDS_min, cyc_ns) - 2; |
| 826 | + while ((s32)(timings.wsetup + timings.wstrobe) < min) |
| 827 | + timings.wstrobe++; |
| 828 | + |
| 829 | + cfg = max_t(s32, TO_CYCLES(sdr->tCLH_min, cyc_ns), TO_CYCLES(sdr->tALH_min, cyc_ns)); |
| 830 | + cfg = max_t(s32, cfg, TO_CYCLES(sdr->tCH_min, cyc_ns)); |
| 831 | + cfg = max_t(s32, cfg, TO_CYCLES(sdr->tDH_min, cyc_ns)) - 1; |
| 832 | + timings.whold = cfg > 0 ? cfg : 0; |
| 833 | + |
| 834 | + min = TO_CYCLES(sdr->tWC_min, cyc_ns) - 2; |
| 835 | + while ((s32)(timings.wsetup + timings.wstrobe + timings.whold) < min) |
| 836 | + timings.whold++; |
| 837 | + |
| 838 | + dev_dbg(&info->pdev->dev, "RSETUP %x RSTROBE %x RHOLD %x\n", |
| 839 | + timings.rsetup, timings.rstrobe, timings.rhold); |
| 840 | + dev_dbg(&info->pdev->dev, "TA %x\n", timings.ta); |
| 841 | + dev_dbg(&info->pdev->dev, "WSETUP %x WSTROBE %x WHOLD %x\n", |
| 842 | + timings.wsetup, timings.wstrobe, timings.whold); |
| 843 | + |
| 844 | + ret = aemif_check_cs_timings(&timings); |
| 845 | + if (ret || chipnr == NAND_DATA_IFACE_CHECK_ONLY) |
| 846 | + return ret; |
| 847 | + |
| 848 | + return aemif_set_cs_timings(info->aemif, info->core_chipsel, &timings); |
| 849 | +} |
| 850 | + |
774 | 851 | static const struct nand_controller_ops davinci_nand_controller_ops = {
|
775 | 852 | .attach_chip = davinci_nand_attach_chip,
|
776 | 853 | .exec_op = davinci_nand_exec_op,
|
| 854 | + .setup_interface = davinci_nand_setup_interface, |
777 | 855 | };
|
778 | 856 |
|
779 | 857 | static int nand_davinci_probe(struct platform_device *pdev)
|
@@ -836,6 +914,7 @@ static int nand_davinci_probe(struct platform_device *pdev)
|
836 | 914 | info->pdev = pdev;
|
837 | 915 | info->base = base;
|
838 | 916 | info->vaddr = vaddr;
|
| 917 | + info->aemif = dev_get_drvdata(pdev->dev.parent); |
839 | 918 |
|
840 | 919 | mtd = nand_to_mtd(&info->chip);
|
841 | 920 | mtd->dev.parent = &pdev->dev;
|
|
0 commit comments