Skip to content

Commit 4df6ed4

Browse files
miquelraynalBoris Brezillon
authored andcommitted
mtd: nand: fsmc: get rid of IO_ADDR_[R|W]
Remove the use of IO_ADDR_[R|W] in the fsmc_nand driver. Instead, use a pointer to the control registers to avoid doing several arithmetic operations (including a multiplication) each time a control register is read or written. All references to IO_ADDR_[R|W] are not entirely removed from the driver as, at this time, these values are needed by the NAND core in the default ->read/write_byte/word() hooks. These references will be entirely removed when switching to ->exec_op(), that does not make use of these hooks anymore. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
1 parent 9c3736a commit 4df6ed4

1 file changed

Lines changed: 42 additions & 58 deletions

File tree

‎drivers/mtd/nand/raw/fsmc_nand.c‎

Lines changed: 42 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,6 @@
103103
#define ECC3 0x1C
104104
#define FSMC_NAND_BANK_SZ 0x20
105105

106-
#define FSMC_NAND_REG(base, bank, reg) (base + FSMC_NOR_REG_SIZE + \
107-
(FSMC_NAND_BANK_SZ * (bank)) + \
108-
reg)
109-
110106
#define FSMC_BUSY_WAIT_TIMEOUT (1 * HZ)
111107

112108
struct fsmc_nand_timings {
@@ -143,7 +139,7 @@ enum access_mode {
143139
* @data_va: NAND port for Data.
144140
* @cmd_va: NAND port for Command.
145141
* @addr_va: NAND port for Address.
146-
* @regs_va: FSMC regs base address.
142+
* @regs_va: Registers base address for a given bank.
147143
*/
148144
struct fsmc_nand_data {
149145
u32 pid;
@@ -265,8 +261,6 @@ static void fsmc_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
265261
{
266262
struct nand_chip *this = mtd_to_nand(mtd);
267263
struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
268-
void __iomem *regs = host->regs_va;
269-
unsigned int bank = host->bank;
270264

271265
if (ctrl & NAND_CTRL_CHANGE) {
272266
u32 pc;
@@ -282,12 +276,12 @@ static void fsmc_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
282276
this->IO_ADDR_W = host->data_va;
283277
}
284278

285-
pc = readl(FSMC_NAND_REG(regs, bank, PC));
279+
pc = readl(host->regs_va + PC);
286280
if (ctrl & NAND_NCE)
287281
pc |= FSMC_ENABLE;
288282
else
289283
pc &= ~FSMC_ENABLE;
290-
writel_relaxed(pc, FSMC_NAND_REG(regs, bank, PC));
284+
writel_relaxed(pc, host->regs_va + PC);
291285
}
292286

293287
mb();
@@ -307,8 +301,6 @@ static void fsmc_nand_setup(struct fsmc_nand_data *host,
307301
{
308302
uint32_t value = FSMC_DEVTYPE_NAND | FSMC_ENABLE | FSMC_WAITON;
309303
uint32_t tclr, tar, thiz, thold, twait, tset;
310-
unsigned int bank = host->bank;
311-
void __iomem *regs = host->regs_va;
312304

313305
tclr = (tims->tclr & FSMC_TCLR_MASK) << FSMC_TCLR_SHIFT;
314306
tar = (tims->tar & FSMC_TAR_MASK) << FSMC_TAR_SHIFT;
@@ -318,18 +310,14 @@ static void fsmc_nand_setup(struct fsmc_nand_data *host,
318310
tset = (tims->tset & FSMC_TSET_MASK) << FSMC_TSET_SHIFT;
319311

320312
if (host->nand.options & NAND_BUSWIDTH_16)
321-
writel_relaxed(value | FSMC_DEVWID_16,
322-
FSMC_NAND_REG(regs, bank, PC));
313+
writel_relaxed(value | FSMC_DEVWID_16, host->regs_va + PC);
323314
else
324-
writel_relaxed(value | FSMC_DEVWID_8,
325-
FSMC_NAND_REG(regs, bank, PC));
326-
327-
writel_relaxed(readl(FSMC_NAND_REG(regs, bank, PC)) | tclr | tar,
328-
FSMC_NAND_REG(regs, bank, PC));
329-
writel_relaxed(thiz | thold | twait | tset,
330-
FSMC_NAND_REG(regs, bank, COMM));
331-
writel_relaxed(thiz | thold | twait | tset,
332-
FSMC_NAND_REG(regs, bank, ATTRIB));
315+
writel_relaxed(value | FSMC_DEVWID_8, host->regs_va + PC);
316+
317+
writel_relaxed(readl(host->regs_va + PC) | tclr | tar,
318+
host->regs_va + PC);
319+
writel_relaxed(thiz | thold | twait | tset, host->regs_va + COMM);
320+
writel_relaxed(thiz | thold | twait | tset, host->regs_va + ATTRIB);
333321
}
334322

335323
static int fsmc_calc_timings(struct fsmc_nand_data *host,
@@ -419,15 +407,13 @@ static int fsmc_setup_data_interface(struct mtd_info *mtd, int csline,
419407
static void fsmc_enable_hwecc(struct mtd_info *mtd, int mode)
420408
{
421409
struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
422-
void __iomem *regs = host->regs_va;
423-
uint32_t bank = host->bank;
424-
425-
writel_relaxed(readl(FSMC_NAND_REG(regs, bank, PC)) & ~FSMC_ECCPLEN_256,
426-
FSMC_NAND_REG(regs, bank, PC));
427-
writel_relaxed(readl(FSMC_NAND_REG(regs, bank, PC)) & ~FSMC_ECCEN,
428-
FSMC_NAND_REG(regs, bank, PC));
429-
writel_relaxed(readl(FSMC_NAND_REG(regs, bank, PC)) | FSMC_ECCEN,
430-
FSMC_NAND_REG(regs, bank, PC));
410+
411+
writel_relaxed(readl(host->regs_va + PC) & ~FSMC_ECCPLEN_256,
412+
host->regs_va + PC);
413+
writel_relaxed(readl(host->regs_va + PC) & ~FSMC_ECCEN,
414+
host->regs_va + PC);
415+
writel_relaxed(readl(host->regs_va + PC) | FSMC_ECCEN,
416+
host->regs_va + PC);
431417
}
432418

433419
/*
@@ -439,13 +425,11 @@ static int fsmc_read_hwecc_ecc4(struct mtd_info *mtd, const uint8_t *data,
439425
uint8_t *ecc)
440426
{
441427
struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
442-
void __iomem *regs = host->regs_va;
443-
uint32_t bank = host->bank;
444428
uint32_t ecc_tmp;
445429
unsigned long deadline = jiffies + FSMC_BUSY_WAIT_TIMEOUT;
446430

447431
do {
448-
if (readl_relaxed(FSMC_NAND_REG(regs, bank, STS)) & FSMC_CODE_RDY)
432+
if (readl_relaxed(host->regs_va + STS) & FSMC_CODE_RDY)
449433
break;
450434
else
451435
cond_resched();
@@ -456,25 +440,25 @@ static int fsmc_read_hwecc_ecc4(struct mtd_info *mtd, const uint8_t *data,
456440
return -ETIMEDOUT;
457441
}
458442

459-
ecc_tmp = readl_relaxed(FSMC_NAND_REG(regs, bank, ECC1));
443+
ecc_tmp = readl_relaxed(host->regs_va + ECC1);
460444
ecc[0] = (uint8_t) (ecc_tmp >> 0);
461445
ecc[1] = (uint8_t) (ecc_tmp >> 8);
462446
ecc[2] = (uint8_t) (ecc_tmp >> 16);
463447
ecc[3] = (uint8_t) (ecc_tmp >> 24);
464448

465-
ecc_tmp = readl_relaxed(FSMC_NAND_REG(regs, bank, ECC2));
449+
ecc_tmp = readl_relaxed(host->regs_va + ECC2);
466450
ecc[4] = (uint8_t) (ecc_tmp >> 0);
467451
ecc[5] = (uint8_t) (ecc_tmp >> 8);
468452
ecc[6] = (uint8_t) (ecc_tmp >> 16);
469453
ecc[7] = (uint8_t) (ecc_tmp >> 24);
470454

471-
ecc_tmp = readl_relaxed(FSMC_NAND_REG(regs, bank, ECC3));
455+
ecc_tmp = readl_relaxed(host->regs_va + ECC3);
472456
ecc[8] = (uint8_t) (ecc_tmp >> 0);
473457
ecc[9] = (uint8_t) (ecc_tmp >> 8);
474458
ecc[10] = (uint8_t) (ecc_tmp >> 16);
475459
ecc[11] = (uint8_t) (ecc_tmp >> 24);
476460

477-
ecc_tmp = readl_relaxed(FSMC_NAND_REG(regs, bank, STS));
461+
ecc_tmp = readl_relaxed(host->regs_va + STS);
478462
ecc[12] = (uint8_t) (ecc_tmp >> 16);
479463

480464
return 0;
@@ -489,11 +473,9 @@ static int fsmc_read_hwecc_ecc1(struct mtd_info *mtd, const uint8_t *data,
489473
uint8_t *ecc)
490474
{
491475
struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
492-
void __iomem *regs = host->regs_va;
493-
uint32_t bank = host->bank;
494476
uint32_t ecc_tmp;
495477

496-
ecc_tmp = readl_relaxed(FSMC_NAND_REG(regs, bank, ECC1));
478+
ecc_tmp = readl_relaxed(host->regs_va + ECC1);
497479
ecc[0] = (uint8_t) (ecc_tmp >> 0);
498480
ecc[1] = (uint8_t) (ecc_tmp >> 8);
499481
ecc[2] = (uint8_t) (ecc_tmp >> 16);
@@ -598,18 +580,18 @@ static int dma_xfer(struct fsmc_nand_data *host, void *buffer, int len,
598580
*/
599581
static void fsmc_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
600582
{
583+
struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
601584
int i;
602-
struct nand_chip *chip = mtd_to_nand(mtd);
603585

604586
if (IS_ALIGNED((uint32_t)buf, sizeof(uint32_t)) &&
605587
IS_ALIGNED(len, sizeof(uint32_t))) {
606588
uint32_t *p = (uint32_t *)buf;
607589
len = len >> 2;
608590
for (i = 0; i < len; i++)
609-
writel_relaxed(p[i], chip->IO_ADDR_W);
591+
writel_relaxed(p[i], host->data_va);
610592
} else {
611593
for (i = 0; i < len; i++)
612-
writeb_relaxed(buf[i], chip->IO_ADDR_W);
594+
writeb_relaxed(buf[i], host->data_va);
613595
}
614596
}
615597

@@ -621,18 +603,18 @@ static void fsmc_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
621603
*/
622604
static void fsmc_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
623605
{
606+
struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
624607
int i;
625-
struct nand_chip *chip = mtd_to_nand(mtd);
626608

627609
if (IS_ALIGNED((uint32_t)buf, sizeof(uint32_t)) &&
628610
IS_ALIGNED(len, sizeof(uint32_t))) {
629611
uint32_t *p = (uint32_t *)buf;
630612
len = len >> 2;
631613
for (i = 0; i < len; i++)
632-
p[i] = readl_relaxed(chip->IO_ADDR_R);
614+
p[i] = readl_relaxed(host->data_va);
633615
} else {
634616
for (i = 0; i < len; i++)
635-
buf[i] = readb_relaxed(chip->IO_ADDR_R);
617+
buf[i] = readb_relaxed(host->data_va);
636618
}
637619
}
638620

@@ -754,13 +736,11 @@ static int fsmc_bch8_correct_data(struct mtd_info *mtd, uint8_t *dat,
754736
{
755737
struct nand_chip *chip = mtd_to_nand(mtd);
756738
struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
757-
void __iomem *regs = host->regs_va;
758-
unsigned int bank = host->bank;
759739
uint32_t err_idx[8];
760740
uint32_t num_err, i;
761741
uint32_t ecc1, ecc2, ecc3, ecc4;
762742

763-
num_err = (readl_relaxed(FSMC_NAND_REG(regs, bank, STS)) >> 10) & 0xF;
743+
num_err = (readl_relaxed(host->regs_va + STS) >> 10) & 0xF;
764744

765745
/* no bit flipping */
766746
if (likely(num_err == 0))
@@ -803,10 +783,10 @@ static int fsmc_bch8_correct_data(struct mtd_info *mtd, uint8_t *dat,
803783
* uint64_t array and error offset indexes are populated in err_idx
804784
* array
805785
*/
806-
ecc1 = readl_relaxed(FSMC_NAND_REG(regs, bank, ECC1));
807-
ecc2 = readl_relaxed(FSMC_NAND_REG(regs, bank, ECC2));
808-
ecc3 = readl_relaxed(FSMC_NAND_REG(regs, bank, ECC3));
809-
ecc4 = readl_relaxed(FSMC_NAND_REG(regs, bank, STS));
786+
ecc1 = readl_relaxed(host->regs_va + ECC1);
787+
ecc2 = readl_relaxed(host->regs_va + ECC2);
788+
ecc3 = readl_relaxed(host->regs_va + ECC3);
789+
ecc4 = readl_relaxed(host->regs_va + STS);
810790

811791
err_idx[0] = (ecc1 >> 0) & 0x1FFF;
812792
err_idx[1] = (ecc1 >> 13) & 0x1FFF;
@@ -889,6 +869,7 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
889869
struct mtd_info *mtd;
890870
struct nand_chip *nand;
891871
struct resource *res;
872+
void __iomem *base;
892873
dma_cap_mask_t mask;
893874
int ret = 0;
894875
u32 pid;
@@ -923,9 +904,12 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
923904
return PTR_ERR(host->cmd_va);
924905

925906
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fsmc_regs");
926-
host->regs_va = devm_ioremap_resource(&pdev->dev, res);
927-
if (IS_ERR(host->regs_va))
928-
return PTR_ERR(host->regs_va);
907+
base = devm_ioremap_resource(&pdev->dev, res);
908+
if (IS_ERR(base))
909+
return PTR_ERR(base);
910+
911+
host->regs_va = base + FSMC_NOR_REG_SIZE +
912+
(host->bank * FSMC_NAND_BANK_SZ);
929913

930914
host->clk = devm_clk_get(&pdev->dev, NULL);
931915
if (IS_ERR(host->clk)) {
@@ -942,7 +926,7 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
942926
* AMBA PrimeCell bus. However it is not a PrimeCell.
943927
*/
944928
for (pid = 0, i = 0; i < 4; i++)
945-
pid |= (readl(host->regs_va + resource_size(res) - 0x20 + 4 * i) & 255) << (i * 8);
929+
pid |= (readl(base + resource_size(res) - 0x20 + 4 * i) & 255) << (i * 8);
946930
host->pid = pid;
947931
dev_info(&pdev->dev, "FSMC device partno %03x, manufacturer %02x, "
948932
"revision %02x, config %02x\n",

0 commit comments

Comments
 (0)