Skip to content

Commit c7a94e9

Browse files
bastien-curutchetmiquelraynal
authored andcommitted
mtd: rawnand: davinci: Implement setup_interface() operation
The setup_interface() operation isn't implemented. It forces the driver to use the ONFI mode 0, though it could use more optimal modes. Implement the setup_interface() operation. It uses the aemif_set_cs_timings() function from the AEMIF driver to update the chip select timings. The calculation of the register's contents is directly extracted from §20.3.2.3 of the DaVinci TRM [1] MAX_TH_PS and MAX_TSU_PS are the worst case timings based on the Keystone2 and DaVinci datasheets. [1] : https://www.ti.com/lit/ug/spruh77c/spruh77c.pdf Signed-off-by: Bastien Curutchet <[email protected]> Signed-off-by: Miquel Raynal <[email protected]>
1 parent a873eae commit c7a94e9

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

drivers/mtd/nand/raw/davinci_nand.c

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/err.h>
1515
#include <linux/iopoll.h>
1616
#include <linux/kernel.h>
17+
#include <linux/memory/ti-aemif.h>
1718
#include <linux/module.h>
1819
#include <linux/mtd/partitions.h>
1920
#include <linux/mtd/rawnand.h>
@@ -44,6 +45,9 @@
4445
#define MASK_ALE 0x08
4546
#define MASK_CLE 0x10
4647

48+
#define MAX_TSU_PS 3000 /* Input setup time in ps */
49+
#define MAX_TH_PS 1600 /* Input hold time in ps */
50+
4751
struct davinci_nand_pdata {
4852
uint32_t mask_ale;
4953
uint32_t mask_cle;
@@ -121,6 +125,7 @@ struct davinci_nand_info {
121125
uint32_t core_chipsel;
122126

123127
struct clk *clk;
128+
struct aemif_device *aemif;
124129
};
125130

126131
static DEFINE_SPINLOCK(davinci_nand_lock);
@@ -771,9 +776,82 @@ static int davinci_nand_exec_op(struct nand_chip *chip,
771776
return 0;
772777
}
773778

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+
774851
static const struct nand_controller_ops davinci_nand_controller_ops = {
775852
.attach_chip = davinci_nand_attach_chip,
776853
.exec_op = davinci_nand_exec_op,
854+
.setup_interface = davinci_nand_setup_interface,
777855
};
778856

779857
static int nand_davinci_probe(struct platform_device *pdev)
@@ -836,6 +914,7 @@ static int nand_davinci_probe(struct platform_device *pdev)
836914
info->pdev = pdev;
837915
info->base = base;
838916
info->vaddr = vaddr;
917+
info->aemif = dev_get_drvdata(pdev->dev.parent);
839918

840919
mtd = nand_to_mtd(&info->chip);
841920
mtd->dev.parent = &pdev->dev;

0 commit comments

Comments
 (0)