19 #include <linux/kernel.h>
21 #include <linux/slab.h>
22 #include <linux/module.h>
41 #define gpio_nand_getpriv(x) container_of(x, struct gpiomtd, mtd_info)
63 asm volatile(
"mov %1, %0\n" :
"=r" (
tmp) :
"r" (tmp));
70 static void gpio_nand_cmd_ctrl(
struct mtd_info *mtd,
int cmd,
unsigned int ctrl)
74 gpio_nand_dosync(gpiomtd);
80 gpio_nand_dosync(gpiomtd);
86 gpio_nand_dosync(gpiomtd);
112 unsigned short *
ptr = (
unsigned short *)buf;
114 for (i = 0; i < len; i += 2, ptr++)
119 static void gpio_nand_readbuf16(
struct mtd_info *mtd,
u_char *buf,
int len)
127 unsigned short *ptr = (
unsigned short *)buf;
129 for (i = 0; i < len; i += 2, ptr++)
134 static int gpio_nand_devready(
struct mtd_info *mtd)
142 { .compatible =
"gpio-control-nand" },
147 static int gpio_nand_get_config_of(
const struct device *
dev,
152 if (!of_property_read_u32(dev->
of_node,
"bank-width", &val)) {
155 }
else if (val != 1) {
156 dev_err(dev,
"invalid bank-width %u\n", val);
167 if (!of_property_read_u32(dev->
of_node,
"chip-delay", &val))
179 "gpio-control-nand,io-sync-reg", &addr))
189 #define gpio_nand_id_table NULL
190 static inline int gpio_nand_get_config_of(
const struct device *dev,
203 static inline int gpio_nand_get_config(
const struct device *dev,
206 int ret = gpio_nand_get_config_of(dev, plat);
222 struct resource *r = gpio_nand_get_io_sync_of(pdev);
232 struct gpiomtd *gpiomtd = platform_get_drvdata(dev);
237 res = gpio_nand_get_io_sync(dev);
246 if (gpio_is_valid(gpiomtd->
plat.gpio_nwp))
253 if (gpio_is_valid(gpiomtd->
plat.gpio_nwp))
282 struct gpiomtd *gpiomtd;
288 if (!dev->
dev.of_node && !dev->
dev.platform_data)
295 gpiomtd = kzalloc(
sizeof(*gpiomtd),
GFP_KERNEL);
296 if (gpiomtd ==
NULL) {
297 dev_err(&dev->
dev,
"failed to create NAND MTD\n");
302 this->IO_ADDR_R = request_and_remap(res0, 2,
"NAND", &ret);
303 if (!this->IO_ADDR_R) {
308 res1 = gpio_nand_get_io_sync(dev);
310 gpiomtd->
io_sync = request_and_remap(res1, 4,
"NAND sync", &ret);
312 dev_err(&dev->
dev,
"unable to map sync NAND\n");
317 ret = gpio_nand_get_config(&dev->
dev, &gpiomtd->
plat);
325 if (gpio_is_valid(gpiomtd->
plat.gpio_nwp)) {
345 this->IO_ADDR_W = this->IO_ADDR_R;
348 this->chip_delay = gpiomtd->
plat.chip_delay;
351 this->cmd_ctrl = gpio_nand_cmd_ctrl;
352 this->dev_ready = gpio_nand_devready;
355 this->read_buf = gpio_nand_readbuf16;
358 this->read_buf = gpio_nand_readbuf;
372 if (gpiomtd->
plat.adjust_parts)
373 gpiomtd->
plat.adjust_parts(&gpiomtd->
plat,
379 gpiomtd->
plat.num_parts);
382 platform_set_drvdata(dev, gpiomtd);
387 if (gpio_is_valid(gpiomtd->
plat.gpio_nwp))
395 if (gpio_is_valid(gpiomtd->
plat.gpio_nwp))
412 .probe = gpio_nand_probe,
413 .remove = gpio_nand_remove,