Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

MIPS/mtd: Handle READY GPIO in generic NAND platform data

The callbacks into the MIPS RB532 platform to read the GPIO pin
indicating that the NAND chip is ready are oldschool and does
not assign GPIOs as properties to the NAND device.

Add a capability to the generic platform NAND chip driver to use
a GPIO line to detect if a NAND chip is ready and override the
platform-local drv_ready() callback with this check if the GPIO
is present.

This makes it possible to drop the legacy include header
<linux/gpio.h> from the RB532 devices.

Signed-off-by: Linus Walleij <linusw@kernel.org>
Acked-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>

authored by

Linus Walleij and committed by
Thomas Bogendoerfer
15513eef 42671e9c

+44 -16
+21 -15
arch/mips/rb532/devices.c
··· 14 14 #include <linux/platform_device.h> 15 15 #include <linux/mtd/platnand.h> 16 16 #include <linux/mtd/mtd.h> 17 - #include <linux/gpio.h> 18 17 #include <linux/gpio/machine.h> 19 18 #include <linux/gpio/property.h> 20 19 #include <linux/gpio_keys.h> ··· 134 135 .num_resources = ARRAY_SIZE(cf_slot0_res), 135 136 }; 136 137 137 - /* Resources and device for NAND */ 138 - static int rb532_dev_ready(struct nand_chip *chip) 139 - { 140 - return gpio_get_value(GPIO_RDY); 141 - } 142 - 143 138 static void rb532_cmd_ctrl(struct nand_chip *chip, int cmd, unsigned int ctrl) 144 139 { 145 140 unsigned char orbits, nandbits; ··· 159 166 }; 160 167 161 168 static struct platform_nand_data rb532_nand_data = { 162 - .ctrl.dev_ready = rb532_dev_ready, 163 169 .ctrl.cmd_ctrl = rb532_cmd_ctrl, 164 170 }; 165 171 166 - static struct platform_device nand_slot0 = { 167 - .name = "gen_nand", 168 - .id = -1, 169 - .resource = nand_slot0_res, 170 - .num_resources = ARRAY_SIZE(nand_slot0_res), 171 - .dev.platform_data = &rb532_nand_data, 172 + static const struct property_entry nand0_properties[] = { 173 + PROPERTY_ENTRY_GPIO("ready-gpios", &rb532_gpio0_node, 174 + GPIO_RDY, GPIO_ACTIVE_HIGH), 175 + { } 176 + }; 177 + 178 + static const struct platform_device_info nand0_info __initconst = { 179 + .name = "gen_nand", 180 + .id = PLATFORM_DEVID_NONE, 181 + .res = nand_slot0_res, 182 + .num_res = ARRAY_SIZE(nand_slot0_res), 183 + .data = &rb532_nand_data, 184 + .size_data = sizeof(struct platform_nand_data), 185 + .properties = nand0_properties, 172 186 }; 173 187 174 188 static struct mtd_partition rb532_partition_info[] = { ··· 234 234 235 235 static struct platform_device *rb532_devs[] = { 236 236 &korina_dev0, 237 - &nand_slot0, 238 237 &cf_slot0, 239 238 &rb532_led, 240 239 &rb532_uart, ··· 319 320 * register the node for the GPIO chip. 320 321 */ 321 322 software_node_register(&rb532_gpio0_node); 323 + 324 + pd = platform_device_register_full(&nand0_info); 325 + ret = PTR_ERR_OR_ZERO(pd); 326 + if (ret) { 327 + pr_err("failed to create NAND slot0 device: %d\n", ret); 328 + return ret; 329 + } 322 330 323 331 pd = platform_device_register_full(&rb532_button_info); 324 332 ret = PTR_ERR_OR_ZERO(pd);
+23 -1
drivers/mtd/nand/raw/plat_nand.c
··· 6 6 */ 7 7 8 8 #include <linux/err.h> 9 + #include <linux/gpio/consumer.h> 9 10 #include <linux/io.h> 10 11 #include <linux/module.h> 11 12 #include <linux/platform_device.h> ··· 18 17 struct nand_controller controller; 19 18 struct nand_chip chip; 20 19 void __iomem *io_base; 20 + struct gpio_desc *ready_gpio; 21 21 }; 22 22 23 23 static int plat_nand_attach_chip(struct nand_chip *chip) ··· 34 32 .attach_chip = plat_nand_attach_chip, 35 33 }; 36 34 35 + /* Resources and device for NAND */ 36 + static int plat_nand_gpio_dev_ready(struct nand_chip *chip) 37 + { 38 + struct plat_nand_data *data = nand_get_controller_data(chip); 39 + 40 + return gpiod_get_value(data->ready_gpio); 41 + } 42 + 37 43 /* 38 44 * Probe for the NAND device. 39 45 */ ··· 51 41 struct plat_nand_data *data; 52 42 struct mtd_info *mtd; 53 43 const char **part_types; 44 + struct nand_chip *chip; 54 45 int err = 0; 55 46 56 47 if (!pdata) { ··· 70 59 if (!data) 71 60 return -ENOMEM; 72 61 62 + data->ready_gpio = devm_gpiod_get_optional(&pdev->dev, "ready", 63 + GPIOD_IN); 64 + if (IS_ERR(data->ready_gpio)) 65 + return dev_err_probe(&pdev->dev, PTR_ERR(data->ready_gpio), 66 + "could not get READY GPIO\n"); 67 + 73 68 data->controller.ops = &plat_nand_ops; 74 69 nand_controller_init(&data->controller); 75 70 data->chip.controller = &data->controller; 71 + chip = &data->chip; 72 + nand_set_controller_data(chip, data); 76 73 77 74 data->io_base = devm_platform_ioremap_resource(pdev, 0); 78 75 if (IS_ERR(data->io_base)) ··· 93 74 data->chip.legacy.IO_ADDR_R = data->io_base; 94 75 data->chip.legacy.IO_ADDR_W = data->io_base; 95 76 data->chip.legacy.cmd_ctrl = pdata->ctrl.cmd_ctrl; 96 - data->chip.legacy.dev_ready = pdata->ctrl.dev_ready; 77 + if (data->ready_gpio) 78 + data->chip.legacy.dev_ready = plat_nand_gpio_dev_ready; 79 + else 80 + data->chip.legacy.dev_ready = pdata->ctrl.dev_ready; 97 81 data->chip.legacy.select_chip = pdata->ctrl.select_chip; 98 82 data->chip.legacy.write_buf = pdata->ctrl.write_buf; 99 83 data->chip.legacy.read_buf = pdata->ctrl.read_buf;