26 #include <linux/kernel.h>
27 #include <linux/module.h>
40 #include <linux/slab.h>
47 #define CCR_COMMAND 0x04
56 #define CCR_NFPSC 0x62
64 #define FCR_STATUS 0x05
69 #define FCR_MODE_DATA 0x94
70 #define FCR_MODE_COMMAND 0x95
71 #define FCR_MODE_ADDRESS 0x96
73 #define FCR_MODE_HWECC_CALC 0xB4
74 #define FCR_MODE_HWECC_RESULT 0xD4
75 #define FCR_MODE_HWECC_RESET 0xF4
77 #define FCR_MODE_POWER_ON 0x0C
78 #define FCR_MODE_POWER_OFF 0x08
80 #define FCR_MODE_LED_OFF 0x00
81 #define FCR_MODE_LED_ON 0x04
83 #define FCR_MODE_EJECT_ON 0x68
84 #define FCR_MODE_EJECT_OFF 0x08
86 #define FCR_MODE_LOCK 0x6C
87 #define FCR_MODE_UNLOCK 0x0C
89 #define FCR_MODE_CONTROLLER_ID 0x40
90 #define FCR_MODE_STANDBY 0x00
92 #define FCR_MODE_WE 0x80
93 #define FCR_MODE_ECC1 0x40
94 #define FCR_MODE_ECC0 0x20
95 #define FCR_MODE_CE 0x10
96 #define FCR_MODE_PCNT1 0x08
97 #define FCR_MODE_PCNT0 0x04
98 #define FCR_MODE_ALE 0x02
99 #define FCR_MODE_CLE 0x01
101 #define FCR_STATUS_BUSY 0x80
122 #define mtd_to_tmio(m) container_of(m, struct tmio_nand, mtd)
127 static void tmio_nand_hwcontrol(
struct mtd_info *mtd,
int cmd,
160 static int tmio_nand_dev_ready(
struct mtd_info *mtd)
189 tmio_nand_wait(
struct mtd_info *mtd,
struct nand_chip *nand_chip)
199 tmio_nand_dev_ready(mtd),
202 if (
unlikely(!tmio_nand_dev_ready(mtd))) {
204 dev_warn(&tmio->
dev->dev,
"still busy with %s after %d ms\n",
210 dev_warn(&tmio->
dev->dev,
"timeout waiting for interrupt\n");
234 tmio->
read = data >> 8;
259 static void tmio_nand_enable_hwecc(
struct mtd_info *mtd,
int mode)
278 ecc_code[0] = ecc >> 8;
281 ecc_code[4] = ecc >> 8;
284 ecc_code[5] = ecc >> 8;
290 static int tmio_nand_correct_data(
struct mtd_info *mtd,
unsigned char *
buf,
291 unsigned char *read_ecc,
unsigned char *calc_ecc)
307 const struct mfd_cell *cell = mfd_get_cell(dev);
351 const struct mfd_cell *cell = mfd_get_cell(dev);
368 struct nand_chip *nand_chip;
382 platform_set_drvdata(dev, tmio);
384 nand_chip = &tmio->
chip;
385 mtd->
priv = nand_chip;
386 mtd->
name =
"tmio-nand";
401 retval = tmio_hw_init(dev, tmio);
410 nand_chip->
cmd_ctrl = tmio_nand_hwcontrol;
411 nand_chip->
dev_ready = tmio_nand_dev_ready;
412 nand_chip->
read_byte = tmio_nand_read_byte;
413 nand_chip->
write_buf = tmio_nand_write_buf;
414 nand_chip->
read_buf = tmio_nand_read_buf;
418 nand_chip->
ecc.size = 512;
419 nand_chip->
ecc.bytes = 6;
420 nand_chip->
ecc.strength = 2;
421 nand_chip->
ecc.hwctl = tmio_nand_enable_hwecc;
422 nand_chip->
ecc.calculate = tmio_nand_calculate_ecc;
423 nand_chip->
ecc.correct = tmio_nand_correct_data;
434 dev_err(&dev->
dev,
"request_irq error %d\n", retval);
439 nand_chip->
waitfunc = tmio_nand_wait;
459 tmio_hw_stop(dev, tmio);
472 struct tmio_nand *tmio = platform_get_drvdata(dev);
477 tmio_hw_stop(dev, tmio);
487 const struct mfd_cell *cell = mfd_get_cell(dev);
492 tmio_hw_stop(dev, platform_get_drvdata(dev));
498 const struct mfd_cell *cell = mfd_get_cell(dev);
503 tmio_hw_init(dev, platform_get_drvdata(dev));
511 #define tmio_suspend NULL
512 #define tmio_resume NULL
516 .driver.name =
"tmio-nand",
519 .remove = tmio_remove,
527 MODULE_AUTHOR(
"Ian Molton, Dirk Opfer, Chris Humbert, Dmitry Baryshkov");