Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 1 | /* |
| 2 | * drivers/mtd/nand/gpio.c |
| 3 | * |
| 4 | * Updated, and converted to generic GPIO based driver by Russell King. |
| 5 | * |
| 6 | * Written by Ben Dooks <ben@simtec.co.uk> |
| 7 | * Based on 2.4 version by Mark Whittaker |
| 8 | * |
| 9 | * © 2004 Simtec Electronics |
| 10 | * |
Gerhard Sittig | c9d79c4 | 2014-08-05 10:37:26 +0200 | [diff] [blame] | 11 | * Device driver for NAND flash that uses a memory mapped interface to |
| 12 | * read/write the NAND commands and data, and GPIO pins for control signals |
| 13 | * (the DT binding refers to this as "GPIO assisted NAND flash") |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 14 | * |
| 15 | * This program is free software; you can redistribute it and/or modify |
| 16 | * it under the terms of the GNU General Public License version 2 as |
| 17 | * published by the Free Software Foundation. |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | #include <linux/kernel.h> |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 22 | #include <linux/err.h> |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 23 | #include <linux/slab.h> |
| 24 | #include <linux/module.h> |
| 25 | #include <linux/platform_device.h> |
| 26 | #include <linux/gpio.h> |
| 27 | #include <linux/io.h> |
| 28 | #include <linux/mtd/mtd.h> |
| 29 | #include <linux/mtd/nand.h> |
| 30 | #include <linux/mtd/partitions.h> |
| 31 | #include <linux/mtd/nand-gpio.h> |
Jamie Iles | 775c3220 | 2011-12-18 10:00:49 +0000 | [diff] [blame] | 32 | #include <linux/of.h> |
| 33 | #include <linux/of_address.h> |
| 34 | #include <linux/of_gpio.h> |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 35 | |
| 36 | struct gpiomtd { |
| 37 | void __iomem *io_sync; |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 38 | struct nand_chip nand_chip; |
| 39 | struct gpio_nand_platdata plat; |
| 40 | }; |
| 41 | |
Boris BREZILLON | dc2948c | 2015-12-10 09:00:06 +0100 | [diff] [blame] | 42 | static inline struct gpiomtd *gpio_nand_getpriv(struct mtd_info *mtd) |
| 43 | { |
| 44 | return container_of(mtd_to_nand(mtd), struct gpiomtd, nand_chip); |
| 45 | } |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 46 | |
| 47 | |
| 48 | #ifdef CONFIG_ARM |
| 49 | /* gpio_nand_dosync() |
| 50 | * |
| 51 | * Make sure the GPIO state changes occur in-order with writes to NAND |
| 52 | * memory region. |
| 53 | * Needed on PXA due to bus-reordering within the SoC itself (see section on |
| 54 | * I/O ordering in PXA manual (section 2.3, p35) |
| 55 | */ |
| 56 | static void gpio_nand_dosync(struct gpiomtd *gpiomtd) |
| 57 | { |
| 58 | unsigned long tmp; |
| 59 | |
| 60 | if (gpiomtd->io_sync) { |
| 61 | /* |
| 62 | * Linux memory barriers don't cater for what's required here. |
| 63 | * What's required is what's here - a read from a separate |
| 64 | * region with a dependency on that read. |
| 65 | */ |
| 66 | tmp = readl(gpiomtd->io_sync); |
| 67 | asm volatile("mov %1, %0\n" : "=r" (tmp) : "r" (tmp)); |
| 68 | } |
| 69 | } |
| 70 | #else |
| 71 | static inline void gpio_nand_dosync(struct gpiomtd *gpiomtd) {} |
| 72 | #endif |
| 73 | |
| 74 | static void gpio_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl) |
| 75 | { |
| 76 | struct gpiomtd *gpiomtd = gpio_nand_getpriv(mtd); |
| 77 | |
| 78 | gpio_nand_dosync(gpiomtd); |
| 79 | |
| 80 | if (ctrl & NAND_CTRL_CHANGE) { |
Christophe Leroy | 44dd182 | 2017-02-10 15:01:10 +0100 | [diff] [blame^] | 81 | if (gpio_is_valid(gpiomtd->plat.gpio_nce)) |
| 82 | gpio_set_value(gpiomtd->plat.gpio_nce, |
| 83 | !(ctrl & NAND_NCE)); |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 84 | gpio_set_value(gpiomtd->plat.gpio_cle, !!(ctrl & NAND_CLE)); |
| 85 | gpio_set_value(gpiomtd->plat.gpio_ale, !!(ctrl & NAND_ALE)); |
| 86 | gpio_nand_dosync(gpiomtd); |
| 87 | } |
| 88 | if (cmd == NAND_CMD_NONE) |
| 89 | return; |
| 90 | |
| 91 | writeb(cmd, gpiomtd->nand_chip.IO_ADDR_W); |
| 92 | gpio_nand_dosync(gpiomtd); |
| 93 | } |
| 94 | |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 95 | static int gpio_nand_devready(struct mtd_info *mtd) |
| 96 | { |
| 97 | struct gpiomtd *gpiomtd = gpio_nand_getpriv(mtd); |
Alexander Shiyan | 18afbc5 | 2012-10-17 10:08:27 +0400 | [diff] [blame] | 98 | |
Alexander Shiyan | c85d32d5 | 2013-05-06 17:53:49 +0400 | [diff] [blame] | 99 | return gpio_get_value(gpiomtd->plat.gpio_rdy); |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 100 | } |
| 101 | |
Jamie Iles | 775c3220 | 2011-12-18 10:00:49 +0000 | [diff] [blame] | 102 | #ifdef CONFIG_OF |
| 103 | static const struct of_device_id gpio_nand_id_table[] = { |
| 104 | { .compatible = "gpio-control-nand" }, |
| 105 | {} |
| 106 | }; |
| 107 | MODULE_DEVICE_TABLE(of, gpio_nand_id_table); |
| 108 | |
| 109 | static int gpio_nand_get_config_of(const struct device *dev, |
| 110 | struct gpio_nand_platdata *plat) |
| 111 | { |
| 112 | u32 val; |
| 113 | |
Alexander Shiyan | ee4f366 | 2013-05-06 17:53:50 +0400 | [diff] [blame] | 114 | if (!dev->of_node) |
| 115 | return -ENODEV; |
| 116 | |
Jamie Iles | 775c3220 | 2011-12-18 10:00:49 +0000 | [diff] [blame] | 117 | if (!of_property_read_u32(dev->of_node, "bank-width", &val)) { |
| 118 | if (val == 2) { |
| 119 | plat->options |= NAND_BUSWIDTH_16; |
| 120 | } else if (val != 1) { |
| 121 | dev_err(dev, "invalid bank-width %u\n", val); |
| 122 | return -EINVAL; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | plat->gpio_rdy = of_get_gpio(dev->of_node, 0); |
| 127 | plat->gpio_nce = of_get_gpio(dev->of_node, 1); |
| 128 | plat->gpio_ale = of_get_gpio(dev->of_node, 2); |
| 129 | plat->gpio_cle = of_get_gpio(dev->of_node, 3); |
| 130 | plat->gpio_nwp = of_get_gpio(dev->of_node, 4); |
| 131 | |
| 132 | if (!of_property_read_u32(dev->of_node, "chip-delay", &val)) |
| 133 | plat->chip_delay = val; |
| 134 | |
| 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | static struct resource *gpio_nand_get_io_sync_of(struct platform_device *pdev) |
| 139 | { |
Brian Norris | 103cdd8 | 2013-12-13 21:19:58 -0800 | [diff] [blame] | 140 | struct resource *r; |
Jamie Iles | 775c3220 | 2011-12-18 10:00:49 +0000 | [diff] [blame] | 141 | u64 addr; |
| 142 | |
Brian Norris | 103cdd8 | 2013-12-13 21:19:58 -0800 | [diff] [blame] | 143 | if (of_property_read_u64(pdev->dev.of_node, |
Jamie Iles | 775c3220 | 2011-12-18 10:00:49 +0000 | [diff] [blame] | 144 | "gpio-control-nand,io-sync-reg", &addr)) |
| 145 | return NULL; |
| 146 | |
Brian Norris | 103cdd8 | 2013-12-13 21:19:58 -0800 | [diff] [blame] | 147 | r = devm_kzalloc(&pdev->dev, sizeof(*r), GFP_KERNEL); |
| 148 | if (!r) |
| 149 | return NULL; |
| 150 | |
Jamie Iles | 775c3220 | 2011-12-18 10:00:49 +0000 | [diff] [blame] | 151 | r->start = addr; |
| 152 | r->end = r->start + 0x3; |
| 153 | r->flags = IORESOURCE_MEM; |
| 154 | |
| 155 | return r; |
| 156 | } |
| 157 | #else /* CONFIG_OF */ |
Jamie Iles | 775c3220 | 2011-12-18 10:00:49 +0000 | [diff] [blame] | 158 | static inline int gpio_nand_get_config_of(const struct device *dev, |
| 159 | struct gpio_nand_platdata *plat) |
| 160 | { |
| 161 | return -ENOSYS; |
| 162 | } |
| 163 | |
| 164 | static inline struct resource * |
| 165 | gpio_nand_get_io_sync_of(struct platform_device *pdev) |
| 166 | { |
| 167 | return NULL; |
| 168 | } |
| 169 | #endif /* CONFIG_OF */ |
| 170 | |
| 171 | static inline int gpio_nand_get_config(const struct device *dev, |
| 172 | struct gpio_nand_platdata *plat) |
| 173 | { |
| 174 | int ret = gpio_nand_get_config_of(dev, plat); |
| 175 | |
| 176 | if (!ret) |
| 177 | return ret; |
| 178 | |
Jingoo Han | 453810b | 2013-07-30 17:18:33 +0900 | [diff] [blame] | 179 | if (dev_get_platdata(dev)) { |
| 180 | memcpy(plat, dev_get_platdata(dev), sizeof(*plat)); |
Jamie Iles | 775c3220 | 2011-12-18 10:00:49 +0000 | [diff] [blame] | 181 | return 0; |
| 182 | } |
| 183 | |
| 184 | return -EINVAL; |
| 185 | } |
| 186 | |
| 187 | static inline struct resource * |
| 188 | gpio_nand_get_io_sync(struct platform_device *pdev) |
| 189 | { |
| 190 | struct resource *r = gpio_nand_get_io_sync_of(pdev); |
| 191 | |
| 192 | if (r) |
| 193 | return r; |
| 194 | |
| 195 | return platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 196 | } |
| 197 | |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 198 | static int gpio_nand_remove(struct platform_device *pdev) |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 199 | { |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 200 | struct gpiomtd *gpiomtd = platform_get_drvdata(pdev); |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 201 | |
Boris BREZILLON | dc2948c | 2015-12-10 09:00:06 +0100 | [diff] [blame] | 202 | nand_release(nand_to_mtd(&gpiomtd->nand_chip)); |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 203 | |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 204 | if (gpio_is_valid(gpiomtd->plat.gpio_nwp)) |
| 205 | gpio_set_value(gpiomtd->plat.gpio_nwp, 0); |
Christophe Leroy | 44dd182 | 2017-02-10 15:01:10 +0100 | [diff] [blame^] | 206 | if (gpio_is_valid(gpiomtd->plat.gpio_nce)) |
| 207 | gpio_set_value(gpiomtd->plat.gpio_nce, 1); |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 208 | |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 209 | return 0; |
| 210 | } |
| 211 | |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 212 | static int gpio_nand_probe(struct platform_device *pdev) |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 213 | { |
| 214 | struct gpiomtd *gpiomtd; |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 215 | struct nand_chip *chip; |
Boris BREZILLON | dc2948c | 2015-12-10 09:00:06 +0100 | [diff] [blame] | 216 | struct mtd_info *mtd; |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 217 | struct resource *res; |
Jamie Iles | 775c3220 | 2011-12-18 10:00:49 +0000 | [diff] [blame] | 218 | int ret = 0; |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 219 | |
Jingoo Han | 453810b | 2013-07-30 17:18:33 +0900 | [diff] [blame] | 220 | if (!pdev->dev.of_node && !dev_get_platdata(&pdev->dev)) |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 221 | return -EINVAL; |
| 222 | |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 223 | gpiomtd = devm_kzalloc(&pdev->dev, sizeof(*gpiomtd), GFP_KERNEL); |
Jingoo Han | 24e9971 | 2013-12-26 12:17:42 +0900 | [diff] [blame] | 224 | if (!gpiomtd) |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 225 | return -ENOMEM; |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 226 | |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 227 | chip = &gpiomtd->nand_chip; |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 228 | |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 229 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 230 | chip->IO_ADDR_R = devm_ioremap_resource(&pdev->dev, res); |
| 231 | if (IS_ERR(chip->IO_ADDR_R)) |
| 232 | return PTR_ERR(chip->IO_ADDR_R); |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 233 | |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 234 | res = gpio_nand_get_io_sync(pdev); |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 235 | if (res) { |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 236 | gpiomtd->io_sync = devm_ioremap_resource(&pdev->dev, res); |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 237 | if (IS_ERR(gpiomtd->io_sync)) |
| 238 | return PTR_ERR(gpiomtd->io_sync); |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 239 | } |
| 240 | |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 241 | ret = gpio_nand_get_config(&pdev->dev, &gpiomtd->plat); |
Jamie Iles | 775c3220 | 2011-12-18 10:00:49 +0000 | [diff] [blame] | 242 | if (ret) |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 243 | return ret; |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 244 | |
Christophe Leroy | 44dd182 | 2017-02-10 15:01:10 +0100 | [diff] [blame^] | 245 | if (gpio_is_valid(gpiomtd->plat.gpio_nce)) { |
| 246 | ret = devm_gpio_request(&pdev->dev, gpiomtd->plat.gpio_nce, |
| 247 | "NAND NCE"); |
| 248 | if (ret) |
| 249 | return ret; |
| 250 | gpio_direction_output(gpiomtd->plat.gpio_nce, 1); |
| 251 | } |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 252 | |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 253 | if (gpio_is_valid(gpiomtd->plat.gpio_nwp)) { |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 254 | ret = devm_gpio_request(&pdev->dev, gpiomtd->plat.gpio_nwp, |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 255 | "NAND NWP"); |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 256 | if (ret) |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 257 | return ret; |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 258 | } |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 259 | |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 260 | ret = devm_gpio_request(&pdev->dev, gpiomtd->plat.gpio_ale, "NAND ALE"); |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 261 | if (ret) |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 262 | return ret; |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 263 | gpio_direction_output(gpiomtd->plat.gpio_ale, 0); |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 264 | |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 265 | ret = devm_gpio_request(&pdev->dev, gpiomtd->plat.gpio_cle, "NAND CLE"); |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 266 | if (ret) |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 267 | return ret; |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 268 | gpio_direction_output(gpiomtd->plat.gpio_cle, 0); |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 269 | |
Alexander Shiyan | 18afbc5 | 2012-10-17 10:08:27 +0400 | [diff] [blame] | 270 | if (gpio_is_valid(gpiomtd->plat.gpio_rdy)) { |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 271 | ret = devm_gpio_request(&pdev->dev, gpiomtd->plat.gpio_rdy, |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 272 | "NAND RDY"); |
Alexander Shiyan | 18afbc5 | 2012-10-17 10:08:27 +0400 | [diff] [blame] | 273 | if (ret) |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 274 | return ret; |
Alexander Shiyan | 18afbc5 | 2012-10-17 10:08:27 +0400 | [diff] [blame] | 275 | gpio_direction_input(gpiomtd->plat.gpio_rdy); |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 276 | chip->dev_ready = gpio_nand_devready; |
Alexander Shiyan | 18afbc5 | 2012-10-17 10:08:27 +0400 | [diff] [blame] | 277 | } |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 278 | |
Brian Norris | a61ae81 | 2015-10-30 20:33:25 -0700 | [diff] [blame] | 279 | nand_set_flash_node(chip, pdev->dev.of_node); |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 280 | chip->IO_ADDR_W = chip->IO_ADDR_R; |
| 281 | chip->ecc.mode = NAND_ECC_SOFT; |
Rafał Miłecki | 050658c | 2016-04-08 12:23:45 +0200 | [diff] [blame] | 282 | chip->ecc.algo = NAND_ECC_HAMMING; |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 283 | chip->options = gpiomtd->plat.options; |
| 284 | chip->chip_delay = gpiomtd->plat.chip_delay; |
| 285 | chip->cmd_ctrl = gpio_nand_cmd_ctrl; |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 286 | |
Boris BREZILLON | dc2948c | 2015-12-10 09:00:06 +0100 | [diff] [blame] | 287 | mtd = nand_to_mtd(chip); |
Boris BREZILLON | dc2948c | 2015-12-10 09:00:06 +0100 | [diff] [blame] | 288 | mtd->dev.parent = &pdev->dev; |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 289 | |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 290 | platform_set_drvdata(pdev, gpiomtd); |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 291 | |
| 292 | if (gpio_is_valid(gpiomtd->plat.gpio_nwp)) |
| 293 | gpio_direction_output(gpiomtd->plat.gpio_nwp, 1); |
| 294 | |
Masahiro Yamada | 408bf51 | 2016-11-04 19:42:52 +0900 | [diff] [blame] | 295 | ret = nand_scan(mtd, 1); |
| 296 | if (ret) |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 297 | goto err_wp; |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 298 | |
| 299 | if (gpiomtd->plat.adjust_parts) |
Boris BREZILLON | dc2948c | 2015-12-10 09:00:06 +0100 | [diff] [blame] | 300 | gpiomtd->plat.adjust_parts(&gpiomtd->plat, mtd->size); |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 301 | |
Boris BREZILLON | dc2948c | 2015-12-10 09:00:06 +0100 | [diff] [blame] | 302 | ret = mtd_device_register(mtd, gpiomtd->plat.parts, |
Brian Norris | a61ae81 | 2015-10-30 20:33:25 -0700 | [diff] [blame] | 303 | gpiomtd->plat.num_parts); |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 304 | if (!ret) |
| 305 | return 0; |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 306 | |
| 307 | err_wp: |
| 308 | if (gpio_is_valid(gpiomtd->plat.gpio_nwp)) |
| 309 | gpio_set_value(gpiomtd->plat.gpio_nwp, 0); |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 310 | |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 311 | return ret; |
| 312 | } |
| 313 | |
| 314 | static struct platform_driver gpio_nand_driver = { |
| 315 | .probe = gpio_nand_probe, |
| 316 | .remove = gpio_nand_remove, |
| 317 | .driver = { |
| 318 | .name = "gpio-nand", |
Sachin Kamat | b57d43f | 2013-03-14 15:37:03 +0530 | [diff] [blame] | 319 | .of_match_table = of_match_ptr(gpio_nand_id_table), |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 320 | }, |
| 321 | }; |
| 322 | |
Sachin Kamat | 2fe87ae | 2012-09-05 15:31:32 +0530 | [diff] [blame] | 323 | module_platform_driver(gpio_nand_driver); |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 324 | |
| 325 | MODULE_LICENSE("GPL"); |
| 326 | MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>"); |
| 327 | MODULE_DESCRIPTION("GPIO NAND Driver"); |