13 #include <linux/slab.h>
14 #include <linux/module.h>
25 #define TXX9_NDFDTR 0x00
26 #define TXX9_NDFMCR 0x04
27 #define TXX9_NDFSR 0x08
28 #define TXX9_NDFISR 0x0c
29 #define TXX9_NDFIMR 0x10
30 #define TXX9_NDFSPR 0x14
31 #define TXX9_NDFRSTR 0x18
34 #define TXX9_NDFMCR_WE 0x80
35 #define TXX9_NDFMCR_ECC_ALL 0x60
36 #define TXX9_NDFMCR_ECC_RESET 0x60
37 #define TXX9_NDFMCR_ECC_READ 0x40
38 #define TXX9_NDFMCR_ECC_ON 0x20
39 #define TXX9_NDFMCR_ECC_OFF 0x00
40 #define TXX9_NDFMCR_CE 0x10
41 #define TXX9_NDFMCR_BSPRT 0x04
42 #define TXX9_NDFMCR_ALE 0x02
43 #define TXX9_NDFMCR_CLE 0x01
45 #define TXX9_NDFMCR_X16 0x0400
46 #define TXX9_NDFMCR_DMAREQ_MASK 0x0300
47 #define TXX9_NDFMCR_DMAREQ_NODMA 0x0000
48 #define TXX9_NDFMCR_DMAREQ_128 0x0100
49 #define TXX9_NDFMCR_DMAREQ_256 0x0200
50 #define TXX9_NDFMCR_DMAREQ_512 0x0300
51 #define TXX9_NDFMCR_CS_MASK 0x0c
52 #define TXX9_NDFMCR_CS(ch) ((ch) << 2)
55 #define TXX9_NDFSR_BUSY 0x80
57 #define TXX9_NDFSR_DMARUN 0x40
60 #define TXX9_NDFRSTR_RST 0x01
70 #define MAX_TXX9NDFMC_DEV 4
83 return txx9_priv->
dev;
91 return drvdata->
base + (reg << plat->
shift);
100 u32 val,
unsigned int reg)
125 static void txx9ndfmc_read_buf(
struct mtd_info *mtd,
uint8_t *buf,
int len)
134 static void txx9ndfmc_cmd_ctrl(
struct mtd_info *mtd,
int cmd,
150 if (txx9_priv->
cs >= 0 && (ctrl &
NAND_NCE)) {
166 static int txx9ndfmc_dev_ready(
struct mtd_info *mtd)
184 for (eccbytes = chip->
ecc.bytes; eccbytes > 0; eccbytes -= 3) {
194 static int txx9ndfmc_correct_data(
struct mtd_info *mtd,
unsigned char *buf,
195 unsigned char *read_ecc,
unsigned char *calc_ecc)
202 for (eccsize = chip->
ecc.size; eccsize > 0; eccsize -= 256) {
214 static void txx9ndfmc_enable_hwecc(
struct mtd_info *mtd,
int mode)
254 #define TXX9NDFMC_NS_TO_CYC(gbusclk, ns) \
255 DIV_ROUND_UP((ns) * DIV_ROUND_UP(gbusclk, 1000), 1000000)
257 static int txx9ndfmc_nand_scan(
struct mtd_info *mtd)
266 chip->
ecc.size = 512;
293 hold = plat->
hold ?: 20;
294 spw = plat->
spw ?: 90;
301 hold =
clamp(hold, 1, 15);
302 drvdata->
hold = hold;
303 spw =
clamp(spw, 1, 15);
306 (gbusclk + 500000) / 1000000, hold, spw);
311 platform_set_drvdata(dev, drvdata);
312 txx9ndfmc_initialize(dev);
319 if (!(plat->
ch_mask & (1 << i)))
325 "TXx9 NDFMC MTD device structure.\n");
328 chip = &txx9_priv->
chip;
329 mtd = &txx9_priv->
mtd;
335 chip->
read_buf = txx9ndfmc_read_buf;
337 chip->
cmd_ctrl = txx9ndfmc_cmd_ctrl;
339 chip->
ecc.calculate = txx9ndfmc_calculate_ecc;
340 chip->
ecc.correct = txx9ndfmc_correct_data;
341 chip->
ecc.hwctl = txx9ndfmc_enable_hwecc;
344 chip->
ecc.size = 256;
346 chip->
ecc.strength = 1;
350 chip->
priv = txx9_priv;
356 dev_name(&dev->
dev), i);
364 dev_err(&dev->
dev,
"Unable to allocate MTD name.\n");
370 if (txx9ndfmc_nand_scan(mtd)) {
378 drvdata->
mtds[
i] = mtd;
389 platform_set_drvdata(dev,
NULL);
400 txx9_priv = chip->
priv;
412 if (platform_get_drvdata(dev))
413 txx9ndfmc_initialize(dev);
417 #define txx9ndfmc_resume NULL
421 .remove =
__exit_p(txx9ndfmc_remove),
429 static int __init txx9ndfmc_init(
void)
434 static void __exit txx9ndfmc_exit(
void)