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) { |
| 81 | gpio_set_value(gpiomtd->plat.gpio_nce, !(ctrl & NAND_NCE)); |
| 82 | gpio_set_value(gpiomtd->plat.gpio_cle, !!(ctrl & NAND_CLE)); |
| 83 | gpio_set_value(gpiomtd->plat.gpio_ale, !!(ctrl & NAND_ALE)); |
| 84 | gpio_nand_dosync(gpiomtd); |
| 85 | } |
| 86 | if (cmd == NAND_CMD_NONE) |
| 87 | return; |
| 88 | |
| 89 | writeb(cmd, gpiomtd->nand_chip.IO_ADDR_W); |
| 90 | gpio_nand_dosync(gpiomtd); |
| 91 | } |
| 92 | |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 93 | static int gpio_nand_devready(struct mtd_info *mtd) |
| 94 | { |
| 95 | struct gpiomtd *gpiomtd = gpio_nand_getpriv(mtd); |
Alexander Shiyan | 18afbc5 | 2012-10-17 10:08:27 +0400 | [diff] [blame] | 96 | |
Alexander Shiyan | c85d32d5 | 2013-05-06 17:53:49 +0400 | [diff] [blame] | 97 | return gpio_get_value(gpiomtd->plat.gpio_rdy); |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 98 | } |
| 99 | |
Jamie Iles | 775c3220 | 2011-12-18 10:00:49 +0000 | [diff] [blame] | 100 | #ifdef CONFIG_OF |
| 101 | static const struct of_device_id gpio_nand_id_table[] = { |
| 102 | { .compatible = "gpio-control-nand" }, |
| 103 | {} |
| 104 | }; |
| 105 | MODULE_DEVICE_TABLE(of, gpio_nand_id_table); |
| 106 | |
| 107 | static int gpio_nand_get_config_of(const struct device *dev, |
| 108 | struct gpio_nand_platdata *plat) |
| 109 | { |
| 110 | u32 val; |
| 111 | |
Alexander Shiyan | ee4f366 | 2013-05-06 17:53:50 +0400 | [diff] [blame] | 112 | if (!dev->of_node) |
| 113 | return -ENODEV; |
| 114 | |
Jamie Iles | 775c3220 | 2011-12-18 10:00:49 +0000 | [diff] [blame] | 115 | if (!of_property_read_u32(dev->of_node, "bank-width", &val)) { |
| 116 | if (val == 2) { |
| 117 | plat->options |= NAND_BUSWIDTH_16; |
| 118 | } else if (val != 1) { |
| 119 | dev_err(dev, "invalid bank-width %u\n", val); |
| 120 | return -EINVAL; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | plat->gpio_rdy = of_get_gpio(dev->of_node, 0); |
| 125 | plat->gpio_nce = of_get_gpio(dev->of_node, 1); |
| 126 | plat->gpio_ale = of_get_gpio(dev->of_node, 2); |
| 127 | plat->gpio_cle = of_get_gpio(dev->of_node, 3); |
| 128 | plat->gpio_nwp = of_get_gpio(dev->of_node, 4); |
| 129 | |
| 130 | if (!of_property_read_u32(dev->of_node, "chip-delay", &val)) |
| 131 | plat->chip_delay = val; |
| 132 | |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | static struct resource *gpio_nand_get_io_sync_of(struct platform_device *pdev) |
| 137 | { |
Brian Norris | 103cdd8 | 2013-12-13 21:19:58 -0800 | [diff] [blame] | 138 | struct resource *r; |
Jamie Iles | 775c3220 | 2011-12-18 10:00:49 +0000 | [diff] [blame] | 139 | u64 addr; |
| 140 | |
Brian Norris | 103cdd8 | 2013-12-13 21:19:58 -0800 | [diff] [blame] | 141 | if (of_property_read_u64(pdev->dev.of_node, |
Jamie Iles | 775c3220 | 2011-12-18 10:00:49 +0000 | [diff] [blame] | 142 | "gpio-control-nand,io-sync-reg", &addr)) |
| 143 | return NULL; |
| 144 | |
Brian Norris | 103cdd8 | 2013-12-13 21:19:58 -0800 | [diff] [blame] | 145 | r = devm_kzalloc(&pdev->dev, sizeof(*r), GFP_KERNEL); |
| 146 | if (!r) |
| 147 | return NULL; |
| 148 | |
Jamie Iles | 775c3220 | 2011-12-18 10:00:49 +0000 | [diff] [blame] | 149 | r->start = addr; |
| 150 | r->end = r->start + 0x3; |
| 151 | r->flags = IORESOURCE_MEM; |
| 152 | |
| 153 | return r; |
| 154 | } |
| 155 | #else /* CONFIG_OF */ |
Jamie Iles | 775c3220 | 2011-12-18 10:00:49 +0000 | [diff] [blame] | 156 | static inline int gpio_nand_get_config_of(const struct device *dev, |
| 157 | struct gpio_nand_platdata *plat) |
| 158 | { |
| 159 | return -ENOSYS; |
| 160 | } |
| 161 | |
| 162 | static inline struct resource * |
| 163 | gpio_nand_get_io_sync_of(struct platform_device *pdev) |
| 164 | { |
| 165 | return NULL; |
| 166 | } |
| 167 | #endif /* CONFIG_OF */ |
| 168 | |
| 169 | static inline int gpio_nand_get_config(const struct device *dev, |
| 170 | struct gpio_nand_platdata *plat) |
| 171 | { |
| 172 | int ret = gpio_nand_get_config_of(dev, plat); |
| 173 | |
| 174 | if (!ret) |
| 175 | return ret; |
| 176 | |
Jingoo Han | 453810b | 2013-07-30 17:18:33 +0900 | [diff] [blame] | 177 | if (dev_get_platdata(dev)) { |
| 178 | memcpy(plat, dev_get_platdata(dev), sizeof(*plat)); |
Jamie Iles | 775c3220 | 2011-12-18 10:00:49 +0000 | [diff] [blame] | 179 | return 0; |
| 180 | } |
| 181 | |
| 182 | return -EINVAL; |
| 183 | } |
| 184 | |
| 185 | static inline struct resource * |
| 186 | gpio_nand_get_io_sync(struct platform_device *pdev) |
| 187 | { |
| 188 | struct resource *r = gpio_nand_get_io_sync_of(pdev); |
| 189 | |
| 190 | if (r) |
| 191 | return r; |
| 192 | |
| 193 | return platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 194 | } |
| 195 | |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 196 | static int gpio_nand_remove(struct platform_device *pdev) |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 197 | { |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 198 | struct gpiomtd *gpiomtd = platform_get_drvdata(pdev); |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 199 | |
Boris BREZILLON | dc2948c | 2015-12-10 09:00:06 +0100 | [diff] [blame] | 200 | nand_release(nand_to_mtd(&gpiomtd->nand_chip)); |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 201 | |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 202 | if (gpio_is_valid(gpiomtd->plat.gpio_nwp)) |
| 203 | gpio_set_value(gpiomtd->plat.gpio_nwp, 0); |
| 204 | gpio_set_value(gpiomtd->plat.gpio_nce, 1); |
| 205 | |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 206 | return 0; |
| 207 | } |
| 208 | |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 209 | static int gpio_nand_probe(struct platform_device *pdev) |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 210 | { |
| 211 | struct gpiomtd *gpiomtd; |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 212 | struct nand_chip *chip; |
Boris BREZILLON | dc2948c | 2015-12-10 09:00:06 +0100 | [diff] [blame] | 213 | struct mtd_info *mtd; |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 214 | struct resource *res; |
Jamie Iles | 775c3220 | 2011-12-18 10:00:49 +0000 | [diff] [blame] | 215 | int ret = 0; |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 216 | |
Jingoo Han | 453810b | 2013-07-30 17:18:33 +0900 | [diff] [blame] | 217 | if (!pdev->dev.of_node && !dev_get_platdata(&pdev->dev)) |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 218 | return -EINVAL; |
| 219 | |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 220 | gpiomtd = devm_kzalloc(&pdev->dev, sizeof(*gpiomtd), GFP_KERNEL); |
Jingoo Han | 24e9971 | 2013-12-26 12:17:42 +0900 | [diff] [blame] | 221 | if (!gpiomtd) |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 222 | return -ENOMEM; |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 223 | |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 224 | chip = &gpiomtd->nand_chip; |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 225 | |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 226 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 227 | chip->IO_ADDR_R = devm_ioremap_resource(&pdev->dev, res); |
| 228 | if (IS_ERR(chip->IO_ADDR_R)) |
| 229 | return PTR_ERR(chip->IO_ADDR_R); |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 230 | |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 231 | res = gpio_nand_get_io_sync(pdev); |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 232 | if (res) { |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 233 | gpiomtd->io_sync = devm_ioremap_resource(&pdev->dev, res); |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 234 | if (IS_ERR(gpiomtd->io_sync)) |
| 235 | return PTR_ERR(gpiomtd->io_sync); |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 236 | } |
| 237 | |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 238 | ret = gpio_nand_get_config(&pdev->dev, &gpiomtd->plat); |
Jamie Iles | 775c3220 | 2011-12-18 10:00:49 +0000 | [diff] [blame] | 239 | if (ret) |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 240 | return ret; |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 241 | |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 242 | ret = devm_gpio_request(&pdev->dev, gpiomtd->plat.gpio_nce, "NAND NCE"); |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 243 | if (ret) |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 244 | return ret; |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 245 | gpio_direction_output(gpiomtd->plat.gpio_nce, 1); |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 246 | |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 247 | if (gpio_is_valid(gpiomtd->plat.gpio_nwp)) { |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 248 | ret = devm_gpio_request(&pdev->dev, gpiomtd->plat.gpio_nwp, |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 249 | "NAND NWP"); |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 250 | if (ret) |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 251 | return ret; |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 252 | } |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 253 | |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 254 | ret = devm_gpio_request(&pdev->dev, gpiomtd->plat.gpio_ale, "NAND ALE"); |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 255 | if (ret) |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 256 | return ret; |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 257 | gpio_direction_output(gpiomtd->plat.gpio_ale, 0); |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 258 | |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 259 | ret = devm_gpio_request(&pdev->dev, gpiomtd->plat.gpio_cle, "NAND CLE"); |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 260 | if (ret) |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 261 | return ret; |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 262 | gpio_direction_output(gpiomtd->plat.gpio_cle, 0); |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 263 | |
Alexander Shiyan | 18afbc5 | 2012-10-17 10:08:27 +0400 | [diff] [blame] | 264 | if (gpio_is_valid(gpiomtd->plat.gpio_rdy)) { |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 265 | ret = devm_gpio_request(&pdev->dev, gpiomtd->plat.gpio_rdy, |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 266 | "NAND RDY"); |
Alexander Shiyan | 18afbc5 | 2012-10-17 10:08:27 +0400 | [diff] [blame] | 267 | if (ret) |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 268 | return ret; |
Alexander Shiyan | 18afbc5 | 2012-10-17 10:08:27 +0400 | [diff] [blame] | 269 | gpio_direction_input(gpiomtd->plat.gpio_rdy); |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 270 | chip->dev_ready = gpio_nand_devready; |
Alexander Shiyan | 18afbc5 | 2012-10-17 10:08:27 +0400 | [diff] [blame] | 271 | } |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 272 | |
Brian Norris | a61ae81 | 2015-10-30 20:33:25 -0700 | [diff] [blame] | 273 | nand_set_flash_node(chip, pdev->dev.of_node); |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 274 | chip->IO_ADDR_W = chip->IO_ADDR_R; |
| 275 | chip->ecc.mode = NAND_ECC_SOFT; |
Rafał Miłecki | 050658c | 2016-04-08 12:23:45 +0200 | [diff] [blame] | 276 | chip->ecc.algo = NAND_ECC_HAMMING; |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 277 | chip->options = gpiomtd->plat.options; |
| 278 | chip->chip_delay = gpiomtd->plat.chip_delay; |
| 279 | chip->cmd_ctrl = gpio_nand_cmd_ctrl; |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 280 | |
Boris BREZILLON | dc2948c | 2015-12-10 09:00:06 +0100 | [diff] [blame] | 281 | mtd = nand_to_mtd(chip); |
Boris BREZILLON | dc2948c | 2015-12-10 09:00:06 +0100 | [diff] [blame] | 282 | mtd->dev.parent = &pdev->dev; |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 283 | |
Alexander Shiyan | f8e81c2 | 2013-05-06 17:53:53 +0400 | [diff] [blame] | 284 | platform_set_drvdata(pdev, gpiomtd); |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 285 | |
| 286 | if (gpio_is_valid(gpiomtd->plat.gpio_nwp)) |
| 287 | gpio_direction_output(gpiomtd->plat.gpio_nwp, 1); |
| 288 | |
Boris BREZILLON | dc2948c | 2015-12-10 09:00:06 +0100 | [diff] [blame] | 289 | if (nand_scan(mtd, 1)) { |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 290 | ret = -ENXIO; |
| 291 | goto err_wp; |
| 292 | } |
| 293 | |
| 294 | if (gpiomtd->plat.adjust_parts) |
Boris BREZILLON | dc2948c | 2015-12-10 09:00:06 +0100 | [diff] [blame] | 295 | gpiomtd->plat.adjust_parts(&gpiomtd->plat, mtd->size); |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 296 | |
Boris BREZILLON | dc2948c | 2015-12-10 09:00:06 +0100 | [diff] [blame] | 297 | ret = mtd_device_register(mtd, gpiomtd->plat.parts, |
Brian Norris | a61ae81 | 2015-10-30 20:33:25 -0700 | [diff] [blame] | 298 | gpiomtd->plat.num_parts); |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 299 | if (!ret) |
| 300 | return 0; |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 301 | |
| 302 | err_wp: |
| 303 | if (gpio_is_valid(gpiomtd->plat.gpio_nwp)) |
| 304 | gpio_set_value(gpiomtd->plat.gpio_nwp, 0); |
Alexander Shiyan | 283df42 | 2013-05-06 17:53:48 +0400 | [diff] [blame] | 305 | |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 306 | return ret; |
| 307 | } |
| 308 | |
| 309 | static struct platform_driver gpio_nand_driver = { |
| 310 | .probe = gpio_nand_probe, |
| 311 | .remove = gpio_nand_remove, |
| 312 | .driver = { |
| 313 | .name = "gpio-nand", |
Sachin Kamat | b57d43f | 2013-03-14 15:37:03 +0530 | [diff] [blame] | 314 | .of_match_table = of_match_ptr(gpio_nand_id_table), |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 315 | }, |
| 316 | }; |
| 317 | |
Sachin Kamat | 2fe87ae | 2012-09-05 15:31:32 +0530 | [diff] [blame] | 318 | module_platform_driver(gpio_nand_driver); |
Mike Rapoport | aaf7ea2 | 2008-10-15 08:38:49 +0200 | [diff] [blame] | 319 | |
| 320 | MODULE_LICENSE("GPL"); |
| 321 | MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>"); |
| 322 | MODULE_DESCRIPTION("GPIO NAND Driver"); |