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

gpio: mxc: Convert the driver to DT-only

Since 5.10-rc1 i.MX is a devicetree-only platform, so simplify the code
by removing the unused non-DT support.

Signed-off-by: Fabio Estevam <festevam@gmail.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20201117105917.27591-1-festevam@gmail.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Fabio Estevam and committed by
Linus Walleij
0f2c7af4 8b516583

+21 -79
+21 -79
drivers/gpio/gpio-mxc.c
··· 24 24 #include <linux/of_device.h> 25 25 #include <linux/bug.h> 26 26 27 - enum mxc_gpio_hwtype { 28 - IMX1_GPIO, /* runs on i.mx1 */ 29 - IMX21_GPIO, /* runs on i.mx21 and i.mx27 */ 30 - IMX31_GPIO, /* runs on i.mx31 */ 31 - IMX35_GPIO, /* runs on all other i.mx */ 32 - }; 33 - 34 27 /* device type dependent stuff */ 35 28 struct mxc_gpio_hwdata { 36 29 unsigned dr_reg; ··· 61 68 u32 both_edges; 62 69 struct mxc_gpio_reg_saved gpio_saved_reg; 63 70 bool power_off; 71 + const struct mxc_gpio_hwdata *hwdata; 64 72 }; 65 73 66 74 static struct mxc_gpio_hwdata imx1_imx21_gpio_hwdata = { ··· 109 115 .fall_edge = 0x03, 110 116 }; 111 117 112 - static enum mxc_gpio_hwtype mxc_gpio_hwtype; 113 - static struct mxc_gpio_hwdata *mxc_gpio_hwdata; 118 + #define GPIO_DR (port->hwdata->dr_reg) 119 + #define GPIO_GDIR (port->hwdata->gdir_reg) 120 + #define GPIO_PSR (port->hwdata->psr_reg) 121 + #define GPIO_ICR1 (port->hwdata->icr1_reg) 122 + #define GPIO_ICR2 (port->hwdata->icr2_reg) 123 + #define GPIO_IMR (port->hwdata->imr_reg) 124 + #define GPIO_ISR (port->hwdata->isr_reg) 125 + #define GPIO_EDGE_SEL (port->hwdata->edge_sel_reg) 114 126 115 - #define GPIO_DR (mxc_gpio_hwdata->dr_reg) 116 - #define GPIO_GDIR (mxc_gpio_hwdata->gdir_reg) 117 - #define GPIO_PSR (mxc_gpio_hwdata->psr_reg) 118 - #define GPIO_ICR1 (mxc_gpio_hwdata->icr1_reg) 119 - #define GPIO_ICR2 (mxc_gpio_hwdata->icr2_reg) 120 - #define GPIO_IMR (mxc_gpio_hwdata->imr_reg) 121 - #define GPIO_ISR (mxc_gpio_hwdata->isr_reg) 122 - #define GPIO_EDGE_SEL (mxc_gpio_hwdata->edge_sel_reg) 123 - 124 - #define GPIO_INT_LOW_LEV (mxc_gpio_hwdata->low_level) 125 - #define GPIO_INT_HIGH_LEV (mxc_gpio_hwdata->high_level) 126 - #define GPIO_INT_RISE_EDGE (mxc_gpio_hwdata->rise_edge) 127 - #define GPIO_INT_FALL_EDGE (mxc_gpio_hwdata->fall_edge) 127 + #define GPIO_INT_LOW_LEV (port->hwdata->low_level) 128 + #define GPIO_INT_HIGH_LEV (port->hwdata->high_level) 129 + #define GPIO_INT_RISE_EDGE (port->hwdata->rise_edge) 130 + #define GPIO_INT_FALL_EDGE (port->hwdata->fall_edge) 128 131 #define GPIO_INT_BOTH_EDGES 0x4 129 132 130 - static const struct platform_device_id mxc_gpio_devtype[] = { 131 - { 132 - .name = "imx1-gpio", 133 - .driver_data = IMX1_GPIO, 134 - }, { 135 - .name = "imx21-gpio", 136 - .driver_data = IMX21_GPIO, 137 - }, { 138 - .name = "imx31-gpio", 139 - .driver_data = IMX31_GPIO, 140 - }, { 141 - .name = "imx35-gpio", 142 - .driver_data = IMX35_GPIO, 143 - }, { 144 - /* sentinel */ 145 - } 146 - }; 147 - 148 133 static const struct of_device_id mxc_gpio_dt_ids[] = { 149 - { .compatible = "fsl,imx1-gpio", .data = &mxc_gpio_devtype[IMX1_GPIO], }, 150 - { .compatible = "fsl,imx21-gpio", .data = &mxc_gpio_devtype[IMX21_GPIO], }, 151 - { .compatible = "fsl,imx31-gpio", .data = &mxc_gpio_devtype[IMX31_GPIO], }, 152 - { .compatible = "fsl,imx35-gpio", .data = &mxc_gpio_devtype[IMX35_GPIO], }, 153 - { .compatible = "fsl,imx7d-gpio", .data = &mxc_gpio_devtype[IMX35_GPIO], }, 134 + { .compatible = "fsl,imx1-gpio", .data = &imx1_imx21_gpio_hwdata }, 135 + { .compatible = "fsl,imx21-gpio", .data = &imx1_imx21_gpio_hwdata }, 136 + { .compatible = "fsl,imx31-gpio", .data = &imx31_gpio_hwdata }, 137 + { .compatible = "fsl,imx35-gpio", .data = &imx35_gpio_hwdata }, 138 + { .compatible = "fsl,imx7d-gpio", .data = &imx35_gpio_hwdata }, 154 139 { /* sentinel */ } 155 140 }; 156 141 MODULE_DEVICE_TABLE(of, mxc_gpio_dt_ids); ··· 345 372 return rv; 346 373 } 347 374 348 - static void mxc_gpio_get_hw(struct platform_device *pdev) 349 - { 350 - const struct of_device_id *of_id = 351 - of_match_device(mxc_gpio_dt_ids, &pdev->dev); 352 - enum mxc_gpio_hwtype hwtype; 353 - 354 - if (of_id) 355 - pdev->id_entry = of_id->data; 356 - hwtype = pdev->id_entry->driver_data; 357 - 358 - if (mxc_gpio_hwtype) { 359 - /* 360 - * The driver works with a reasonable presupposition, 361 - * that is all gpio ports must be the same type when 362 - * running on one soc. 363 - */ 364 - BUG_ON(mxc_gpio_hwtype != hwtype); 365 - return; 366 - } 367 - 368 - if (hwtype == IMX35_GPIO) 369 - mxc_gpio_hwdata = &imx35_gpio_hwdata; 370 - else if (hwtype == IMX31_GPIO) 371 - mxc_gpio_hwdata = &imx31_gpio_hwdata; 372 - else 373 - mxc_gpio_hwdata = &imx1_imx21_gpio_hwdata; 374 - 375 - mxc_gpio_hwtype = hwtype; 376 - } 377 - 378 375 static int mxc_gpio_to_irq(struct gpio_chip *gc, unsigned offset) 379 376 { 380 377 struct mxc_gpio_port *port = gpiochip_get_data(gc); ··· 360 417 int irq_base; 361 418 int err; 362 419 363 - mxc_gpio_get_hw(pdev); 364 - 365 420 port = devm_kzalloc(&pdev->dev, sizeof(*port), GFP_KERNEL); 366 421 if (!port) 367 422 return -ENOMEM; 368 423 369 424 port->dev = &pdev->dev; 425 + 426 + port->hwdata = device_get_match_data(&pdev->dev); 370 427 371 428 port->base = devm_platform_ioremap_resource(pdev, 0); 372 429 if (IS_ERR(port->base)) ··· 404 461 writel(0, port->base + GPIO_IMR); 405 462 writel(~0, port->base + GPIO_ISR); 406 463 407 - if (mxc_gpio_hwtype == IMX21_GPIO) { 464 + if (of_device_is_compatible(np, "fsl,imx21-gpio")) { 408 465 /* 409 466 * Setup one handler for all GPIO interrupts. Actually setting 410 467 * the handler is needed only once, but doing it for every port ··· 539 596 .suppress_bind_attrs = true, 540 597 }, 541 598 .probe = mxc_gpio_probe, 542 - .id_table = mxc_gpio_devtype, 543 599 }; 544 600 545 601 static int __init gpio_mxc_init(void)