Skip to content

Commit 593cd87

Browse files
Linus WalleijDavid Woodhouse
authored andcommitted
mtd: FSMC NAND use the PrimeCell identifier macros
The FSMC actually has a standard ARM PrimeCell ID register, and the "revision" part of that register contains the thing that the code is looking at. Reuse the infrastructure from the AMBA bus abstraction and rid local defines. Signed-off-by: Linus Walleij <linus.walleij@stericsson.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
1 parent 4ad916b commit 593cd87

2 files changed

Lines changed: 20 additions & 22 deletions

File tree

‎drivers/mtd/nand/fsmc_nand.c‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <linux/io.h>
3232
#include <linux/slab.h>
3333
#include <linux/mtd/fsmc.h>
34+
#include <linux/amba/bus.h>
3435
#include <mtd/mtd-abi.h>
3536

3637
static struct nand_ecclayout fsmc_ecc1_layout = {
@@ -184,8 +185,9 @@ const char *part_probes[] = { "cmdlinepart", NULL };
184185
#endif
185186

186187
/**
187-
* struct fsmc_nand_data - atructure for FSMC NAND device state
188+
* struct fsmc_nand_data - structure for FSMC NAND device state
188189
*
190+
* @pid: Part ID on the AMBA PrimeCell format
189191
* @mtd: MTD info for a NAND flash.
190192
* @nand: Chip related info for a NAND flash.
191193
* @partitions: Partition info for a NAND Flash.
@@ -201,6 +203,7 @@ const char *part_probes[] = { "cmdlinepart", NULL };
201203
* @regs_va: FSMC regs base address.
202204
*/
203205
struct fsmc_nand_data {
206+
u32 pid;
204207
struct mtd_info mtd;
205208
struct nand_chip nand;
206209
struct mtd_partition *partitions;
@@ -541,6 +544,8 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
541544
struct fsmc_regs *regs;
542545
struct resource *res;
543546
int ret = 0;
547+
u32 pid;
548+
int i;
544549

545550
if (!pdata) {
546551
dev_err(&pdev->dev, "platform data is NULL\n");
@@ -630,6 +635,18 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
630635
if (ret)
631636
goto err_probe1;
632637

638+
/*
639+
* This device ID is actually a common AMBA ID as used on the
640+
* AMBA PrimeCell bus. However it is not a PrimeCell.
641+
*/
642+
for (pid = 0, i = 0; i < 4; i++)
643+
pid |= (readl(host->regs_va + resource_size(res) - 0x20 + 4 * i) & 255) << (i * 8);
644+
host->pid = pid;
645+
dev_info(&pdev->dev, "FSMC device partno %03x, manufacturer %02x, "
646+
"revision %02x, config %02x\n",
647+
AMBA_PART_BITS(pid), AMBA_MANF_BITS(pid),
648+
AMBA_REV_BITS(pid), AMBA_CONFIG_BITS(pid));
649+
633650
host->bank = pdata->bank;
634651
host->select_chip = pdata->select_bank;
635652
regs = host->regs_va;
@@ -657,7 +674,7 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
657674

658675
fsmc_nand_setup(regs, host->bank, nand->options & NAND_BUSWIDTH_16);
659676

660-
if (get_fsmc_version(host->regs_va) == FSMC_VER8) {
677+
if (AMBA_REV_BITS(host->pid) >= 8) {
661678
nand->ecc.read_page = fsmc_read_page_hwecc;
662679
nand->ecc.calculate = fsmc_read_hwecc_ecc4;
663680
nand->ecc.correct = fsmc_correct_data;
@@ -677,7 +694,7 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
677694
goto err_probe;
678695
}
679696

680-
if (get_fsmc_version(host->regs_va) == FSMC_VER8) {
697+
if (AMBA_REV_BITS(host->pid) >= 8) {
681698
if (host->mtd.writesize == 512) {
682699
nand->ecc.layout = &fsmc_ecc4_sp_layout;
683700
host->ecc_place = &fsmc_ecc4_sp_place;

‎include/linux/mtd/fsmc.h‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -115,25 +115,6 @@ struct fsmc_regs {
115115
#define FSMC_THOLD_4 (4 << 16)
116116
#define FSMC_THIZ_1 (1 << 24)
117117

118-
/* peripid2 register definitions */
119-
#define FSMC_REVISION_MSK (0xf)
120-
#define FSMC_REVISION_SHFT (0x4)
121-
122-
#define FSMC_VER1 1
123-
#define FSMC_VER2 2
124-
#define FSMC_VER3 3
125-
#define FSMC_VER4 4
126-
#define FSMC_VER5 5
127-
#define FSMC_VER6 6
128-
#define FSMC_VER7 7
129-
#define FSMC_VER8 8
130-
131-
static inline uint32_t get_fsmc_version(struct fsmc_regs *regs)
132-
{
133-
return (readl(&regs->peripid2) >> FSMC_REVISION_SHFT) &
134-
FSMC_REVISION_MSK;
135-
}
136-
137118
/*
138119
* There are 13 bytes of ecc for every 512 byte block in FSMC version 8
139120
* and it has to be read consecutively and immediately after the 512

0 commit comments

Comments
 (0)