Lines Matching full:mtd
21 #include <linux/mtd/mtd.h>
22 #include <linux/mtd/rawnand.h>
23 #include <linux/mtd/partitions.h>
119 static void mpc5121_nfc_done(struct mtd_info *mtd);
122 static inline u16 nfc_read(struct mtd_info *mtd, uint reg) in nfc_read() argument
124 struct nand_chip *chip = mtd_to_nand(mtd); in nfc_read()
131 static inline void nfc_write(struct mtd_info *mtd, uint reg, u16 val) in nfc_write() argument
133 struct nand_chip *chip = mtd_to_nand(mtd); in nfc_write()
140 static inline void nfc_set(struct mtd_info *mtd, uint reg, u16 bits) in nfc_set() argument
142 nfc_write(mtd, reg, nfc_read(mtd, reg) | bits); in nfc_set()
146 static inline void nfc_clear(struct mtd_info *mtd, uint reg, u16 bits) in nfc_clear() argument
148 nfc_write(mtd, reg, nfc_read(mtd, reg) & ~bits); in nfc_clear()
152 static inline void mpc5121_nfc_send_addr(struct mtd_info *mtd, u16 addr) in mpc5121_nfc_send_addr() argument
154 nfc_write(mtd, NFC_FLASH_ADDR, addr); in mpc5121_nfc_send_addr()
155 nfc_write(mtd, NFC_CONFIG2, NFC_ADDRESS); in mpc5121_nfc_send_addr()
156 mpc5121_nfc_done(mtd); in mpc5121_nfc_send_addr()
160 static inline void mpc5121_nfc_send_cmd(struct mtd_info *mtd, u16 cmd) in mpc5121_nfc_send_cmd() argument
162 nfc_write(mtd, NFC_FLASH_CMD, cmd); in mpc5121_nfc_send_cmd()
163 nfc_write(mtd, NFC_CONFIG2, NFC_COMMAND); in mpc5121_nfc_send_cmd()
164 mpc5121_nfc_done(mtd); in mpc5121_nfc_send_cmd()
168 static inline void mpc5121_nfc_send_prog_page(struct mtd_info *mtd) in mpc5121_nfc_send_prog_page() argument
170 nfc_clear(mtd, NFC_BUF_ADDR, NFC_RBA_MASK); in mpc5121_nfc_send_prog_page()
171 nfc_write(mtd, NFC_CONFIG2, NFC_INPUT); in mpc5121_nfc_send_prog_page()
172 mpc5121_nfc_done(mtd); in mpc5121_nfc_send_prog_page()
176 static inline void mpc5121_nfc_send_read_page(struct mtd_info *mtd) in mpc5121_nfc_send_read_page() argument
178 nfc_clear(mtd, NFC_BUF_ADDR, NFC_RBA_MASK); in mpc5121_nfc_send_read_page()
179 nfc_write(mtd, NFC_CONFIG2, NFC_OUTPUT); in mpc5121_nfc_send_read_page()
180 mpc5121_nfc_done(mtd); in mpc5121_nfc_send_read_page()
184 static inline void mpc5121_nfc_send_read_id(struct mtd_info *mtd) in mpc5121_nfc_send_read_id() argument
186 nfc_clear(mtd, NFC_BUF_ADDR, NFC_RBA_MASK); in mpc5121_nfc_send_read_id()
187 nfc_write(mtd, NFC_CONFIG2, NFC_ID); in mpc5121_nfc_send_read_id()
188 mpc5121_nfc_done(mtd); in mpc5121_nfc_send_read_id()
192 static inline void mpc5121_nfc_send_read_status(struct mtd_info *mtd) in mpc5121_nfc_send_read_status() argument
194 nfc_clear(mtd, NFC_BUF_ADDR, NFC_RBA_MASK); in mpc5121_nfc_send_read_status()
195 nfc_write(mtd, NFC_CONFIG2, NFC_STATUS); in mpc5121_nfc_send_read_status()
196 mpc5121_nfc_done(mtd); in mpc5121_nfc_send_read_status()
202 struct mtd_info *mtd = data; in mpc5121_nfc_irq() local
203 struct nand_chip *chip = mtd_to_nand(mtd); in mpc5121_nfc_irq()
206 nfc_set(mtd, NFC_CONFIG1, NFC_INT_MASK); in mpc5121_nfc_irq()
213 static void mpc5121_nfc_done(struct mtd_info *mtd) in mpc5121_nfc_done() argument
215 struct nand_chip *chip = mtd_to_nand(mtd); in mpc5121_nfc_done()
219 if ((nfc_read(mtd, NFC_CONFIG2) & NFC_INT) == 0) { in mpc5121_nfc_done()
220 nfc_clear(mtd, NFC_CONFIG1, NFC_INT_MASK); in mpc5121_nfc_done()
222 (nfc_read(mtd, NFC_CONFIG2) & NFC_INT), NFC_TIMEOUT); in mpc5121_nfc_done()
229 nfc_clear(mtd, NFC_CONFIG2, NFC_INT); in mpc5121_nfc_done()
233 static void mpc5121_nfc_addr_cycle(struct mtd_info *mtd, int column, int page) in mpc5121_nfc_addr_cycle() argument
235 struct nand_chip *chip = mtd_to_nand(mtd); in mpc5121_nfc_addr_cycle()
239 mpc5121_nfc_send_addr(mtd, column); in mpc5121_nfc_addr_cycle()
240 if (mtd->writesize > 512) in mpc5121_nfc_addr_cycle()
241 mpc5121_nfc_send_addr(mtd, column >> 8); in mpc5121_nfc_addr_cycle()
246 mpc5121_nfc_send_addr(mtd, page & 0xFF); in mpc5121_nfc_addr_cycle()
256 struct mtd_info *mtd = nand_to_mtd(nand); in mpc5121_nfc_select_chip() local
259 nfc_clear(mtd, NFC_CONFIG1, NFC_CE); in mpc5121_nfc_select_chip()
263 nfc_clear(mtd, NFC_BUF_ADDR, NFC_ACTIVE_CS_MASK); in mpc5121_nfc_select_chip()
264 nfc_set(mtd, NFC_BUF_ADDR, (chip << NFC_ACTIVE_CS_SHIFT) & in mpc5121_nfc_select_chip()
266 nfc_set(mtd, NFC_CONFIG1, NFC_CE); in mpc5121_nfc_select_chip()
270 static int ads5121_chipselect_init(struct mtd_info *mtd) in ads5121_chipselect_init() argument
272 struct nand_chip *chip = mtd_to_nand(mtd); in ads5121_chipselect_init()
294 struct mtd_info *mtd = nand_to_mtd(nand); in ads5121_select_chip() local
324 struct mtd_info *mtd = nand_to_mtd(chip); in mpc5121_nfc_command() local
332 mpc5121_nfc_send_prog_page(mtd); in mpc5121_nfc_command()
369 mpc5121_nfc_send_cmd(mtd, command); in mpc5121_nfc_command()
370 mpc5121_nfc_addr_cycle(mtd, column, page); in mpc5121_nfc_command()
374 if (mtd->writesize > 512) in mpc5121_nfc_command()
375 mpc5121_nfc_send_cmd(mtd, NAND_CMD_READSTART); in mpc5121_nfc_command()
376 mpc5121_nfc_send_read_page(mtd); in mpc5121_nfc_command()
380 mpc5121_nfc_send_read_id(mtd); in mpc5121_nfc_command()
384 mpc5121_nfc_send_read_status(mtd); in mpc5121_nfc_command()
394 static void mpc5121_nfc_copy_spare(struct mtd_info *mtd, uint offset, in mpc5121_nfc_copy_spare() argument
397 struct nand_chip *nand = mtd_to_nand(mtd); in mpc5121_nfc_copy_spare()
417 sbsize = (mtd->oobsize / (mtd->writesize / 512)) & ~1; in mpc5121_nfc_copy_spare()
446 static void mpc5121_nfc_buf_copy(struct mtd_info *mtd, u_char *buf, int len, in mpc5121_nfc_buf_copy() argument
449 struct nand_chip *chip = mtd_to_nand(mtd); in mpc5121_nfc_buf_copy()
455 if (prv->spareonly || c >= mtd->writesize) { in mpc5121_nfc_buf_copy()
457 if (c >= mtd->writesize) in mpc5121_nfc_buf_copy()
458 c -= mtd->writesize; in mpc5121_nfc_buf_copy()
461 mpc5121_nfc_copy_spare(mtd, c, buf, len, wr); in mpc5121_nfc_buf_copy()
469 l = min((uint)len, mtd->writesize - c); in mpc5121_nfc_buf_copy()
481 mpc5121_nfc_buf_copy(mtd, buf, len, wr); in mpc5121_nfc_buf_copy()
515 static int mpc5121_nfc_read_hw_config(struct mtd_info *mtd) in mpc5121_nfc_read_hw_config() argument
517 struct nand_chip *chip = mtd_to_nand(mtd); in mpc5121_nfc_read_hw_config()
577 mtd->writesize = rcw_pagesize; in mpc5121_nfc_read_hw_config()
578 mtd->oobsize = rcw_sparesize; in mpc5121_nfc_read_hw_config()
594 static void mpc5121_nfc_free(struct device *dev, struct mtd_info *mtd) in mpc5121_nfc_free() argument
596 struct nand_chip *chip = mtd_to_nand(mtd); in mpc5121_nfc_free()
627 struct mtd_info *mtd; in mpc5121_nfc_probe() local
650 mtd = nand_to_mtd(chip); in mpc5121_nfc_probe()
656 mtd->dev.parent = dev; in mpc5121_nfc_probe()
662 retval = mpc5121_nfc_read_hw_config(mtd); in mpc5121_nfc_probe()
700 mtd->name = "MPC5121 NAND"; in mpc5121_nfc_probe()
713 retval = ads5121_chipselect_init(mtd); in mpc5121_nfc_probe()
737 nfc_set(mtd, NFC_CONFIG1, NFC_RESET); in mpc5121_nfc_probe()
738 while (nfc_read(mtd, NFC_CONFIG1) & NFC_RESET) { in mpc5121_nfc_probe()
749 nfc_write(mtd, NFC_CONFIG, NFC_BLS_UNLOCKED); in mpc5121_nfc_probe()
752 nfc_write(mtd, NFC_UNLOCKSTART_BLK0, 0x0000); in mpc5121_nfc_probe()
753 nfc_write(mtd, NFC_UNLOCKEND_BLK0, 0xFFFF); in mpc5121_nfc_probe()
754 nfc_write(mtd, NFC_WRPROT, NFC_WPC_UNLOCK); in mpc5121_nfc_probe()
761 nfc_write(mtd, NFC_CONFIG1, NFC_BIG_ENDIAN | NFC_INT_MASK | in mpc5121_nfc_probe()
765 nfc_write(mtd, NFC_SPAS, mtd->oobsize >> 1); in mpc5121_nfc_probe()
769 mtd); in mpc5121_nfc_probe()
783 switch (mtd->erasesize / mtd->writesize) { in mpc5121_nfc_probe()
785 nfc_set(mtd, NFC_CONFIG1, NFC_PPB_32); in mpc5121_nfc_probe()
789 nfc_set(mtd, NFC_CONFIG1, NFC_PPB_64); in mpc5121_nfc_probe()
793 nfc_set(mtd, NFC_CONFIG1, NFC_PPB_128); in mpc5121_nfc_probe()
797 nfc_set(mtd, NFC_CONFIG1, NFC_PPB_256); in mpc5121_nfc_probe()
806 dev_set_drvdata(dev, mtd); in mpc5121_nfc_probe()
808 /* Register device in MTD */ in mpc5121_nfc_probe()
809 retval = mtd_device_register(mtd, NULL, 0); in mpc5121_nfc_probe()
811 dev_err(dev, "Error adding MTD device!\n"); in mpc5121_nfc_probe()
817 mpc5121_nfc_free(dev, mtd); in mpc5121_nfc_probe()
824 struct mtd_info *mtd = dev_get_drvdata(dev); in mpc5121_nfc_remove() local
827 ret = mtd_device_unregister(mtd); in mpc5121_nfc_remove()
829 nand_cleanup(mtd_to_nand(mtd)); in mpc5121_nfc_remove()
830 mpc5121_nfc_free(dev, mtd); in mpc5121_nfc_remove()
853 MODULE_DESCRIPTION("MPC5121 NAND MTD driver");