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

gpio: mxc: use new generic GPIO chip API

Convert the driver to using the new generic GPIO chip interfaces from
linux/gpio/generic.h.

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/20250702-gpio-mmio-rework-v2-3-6b77aab684d8@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

+24 -17
+24 -17
drivers/gpio/gpio-mxc.c
··· 23 23 #include <linux/spinlock.h> 24 24 #include <linux/syscore_ops.h> 25 25 #include <linux/gpio/driver.h> 26 + #include <linux/gpio/generic.h> 26 27 #include <linux/of.h> 27 28 #include <linux/bug.h> 28 29 ··· 66 65 int irq_high; 67 66 void (*mx_irq_handler)(struct irq_desc *desc); 68 67 struct irq_domain *domain; 69 - struct gpio_chip gc; 68 + struct gpio_generic_chip gen_gc; 70 69 struct device *dev; 71 70 u32 both_edges; 72 71 struct mxc_gpio_reg_saved gpio_saved_reg; ··· 180 179 if (GPIO_EDGE_SEL >= 0) { 181 180 edge = GPIO_INT_BOTH_EDGES; 182 181 } else { 183 - val = port->gc.get(&port->gc, gpio_idx); 182 + val = port->gen_gc.gc.get(&port->gen_gc.gc, gpio_idx); 184 183 if (val) { 185 184 edge = GPIO_INT_LOW_LEV; 186 185 pr_debug("mxc: set GPIO %d to low trigger\n", gpio_idx); ··· 201 200 return -EINVAL; 202 201 } 203 202 204 - scoped_guard(raw_spinlock_irqsave, &port->gc.bgpio_lock) { 203 + scoped_guard(gpio_generic_lock_irqsave, &port->gen_gc) { 205 204 if (GPIO_EDGE_SEL >= 0) { 206 205 val = readl(port->base + GPIO_EDGE_SEL); 207 206 if (edge == GPIO_INT_BOTH_EDGES) ··· 223 222 port->pad_type[gpio_idx] = type; 224 223 } 225 224 226 - return port->gc.direction_input(&port->gc, gpio_idx); 225 + return port->gen_gc.gc.direction_input(&port->gen_gc.gc, gpio_idx); 227 226 } 228 227 229 228 static void mxc_flip_edge(struct mxc_gpio_port *port, u32 gpio) ··· 232 231 u32 bit, val; 233 232 int edge; 234 233 235 - guard(raw_spinlock_irqsave)(&port->gc.bgpio_lock); 234 + guard(gpio_generic_lock_irqsave)(&port->gen_gc); 236 235 237 236 reg += GPIO_ICR1 + ((gpio & 0x10) >> 2); /* lower or upper register */ 238 237 bit = gpio & 0xf; ··· 415 414 416 415 static int mxc_gpio_probe(struct platform_device *pdev) 417 416 { 417 + struct gpio_generic_chip_config config = { }; 418 418 struct device_node *np = pdev->dev.of_node; 419 419 struct mxc_gpio_port *port; 420 420 int irq_count; ··· 475 473 port->mx_irq_handler = mx3_gpio_irq_handler; 476 474 477 475 mxc_update_irq_chained_handler(port, true); 478 - err = bgpio_init(&port->gc, &pdev->dev, 4, 479 - port->base + GPIO_PSR, 480 - port->base + GPIO_DR, NULL, 481 - port->base + GPIO_GDIR, NULL, 482 - BGPIOF_READ_OUTPUT_REG_SET); 476 + 477 + config.dev = &pdev->dev; 478 + config.sz = 4; 479 + config.dat = port->base + GPIO_PSR; 480 + config.set = port->base + GPIO_DR; 481 + config.dirout = port->base + GPIO_GDIR; 482 + config.flags = BGPIOF_READ_OUTPUT_REG_SET; 483 + 484 + err = gpio_generic_chip_init(&port->gen_gc, &config); 483 485 if (err) 484 486 goto out_bgio; 485 487 486 - port->gc.request = mxc_gpio_request; 487 - port->gc.free = mxc_gpio_free; 488 - port->gc.to_irq = mxc_gpio_to_irq; 488 + port->gen_gc.gc.request = mxc_gpio_request; 489 + port->gen_gc.gc.free = mxc_gpio_free; 490 + port->gen_gc.gc.to_irq = mxc_gpio_to_irq; 489 491 /* 490 492 * Driver is DT-only, so a fixed base needs only be maintained for legacy 491 493 * userspace with sysfs interface. 492 494 */ 493 495 if (IS_ENABLED(CONFIG_GPIO_SYSFS)) 494 - port->gc.base = of_alias_get_id(np, "gpio") * 32; 496 + port->gen_gc.gc.base = of_alias_get_id(np, "gpio") * 32; 495 497 else /* silence boot time warning */ 496 - port->gc.base = -1; 498 + port->gen_gc.gc.base = -1; 497 499 498 - err = devm_gpiochip_add_data(&pdev->dev, &port->gc, port); 500 + err = devm_gpiochip_add_data(&pdev->dev, &port->gen_gc.gc, port); 499 501 if (err) 500 502 goto out_bgio; 501 503 ··· 573 567 if (of_device_is_compatible(np, "fsl,imx8dxl-gpio") || 574 568 of_device_is_compatible(np, "fsl,imx8qxp-gpio") || 575 569 of_device_is_compatible(np, "fsl,imx8qm-gpio")) 576 - return (gpiochip_generic_config(&port->gc, offset, conf) == 0); 570 + return (gpiochip_generic_config(&port->gen_gc.gc, 571 + offset, conf) == 0); 577 572 578 573 return false; 579 574 }