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

ieee802154: ca8210: Switch to using gpiod API

This updates the driver to gpiod API, and removes yet another use of
of_get_named_gpio().

With this, invert the logic of the reset pin which is active-low
and add a quirk for the legacy and incorrect device tree descriptions.

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/20250305105656.2133487-4-andriy.shevchenko@linux.intel.com
Signed-off-by: Stefan Schmidt <stefan@datenfreihafen.org>

authored by

Andy Shevchenko and committed by
Stefan Schmidt
20629a48 0a3e89b0

+28 -38
+9
drivers/gpio/gpiolib-of.c
··· 203 203 */ 204 204 { "qi,lb60", "rb-gpios", true }, 205 205 #endif 206 + #if IS_ENABLED(CONFIG_IEEE802154_CA8210) 207 + /* 208 + * According to the datasheet, the NRST pin 27 is an active-low 209 + * signal. However, the device tree schema and admittedly 210 + * the out-of-tree implementations have been used for a long 211 + * time incorrectly by describing reset GPIO as active-high. 212 + */ 213 + { "cascoda,ca8210", "reset-gpio", false }, 214 + #endif 206 215 #if IS_ENABLED(CONFIG_PCI_LANTIQ) 207 216 /* 208 217 * According to the PCI specification, the RST# pin is an
+19 -38
drivers/net/ieee802154/ca8210.c
··· 52 52 #include <linux/debugfs.h> 53 53 #include <linux/delay.h> 54 54 #include <linux/gpio/consumer.h> 55 - #include <linux/gpio.h> 56 55 #include <linux/ieee802154.h> 57 56 #include <linux/io.h> 58 57 #include <linux/kfifo.h> 59 58 #include <linux/of.h> 60 - #include <linux/of_gpio.h> 61 59 #include <linux/module.h> 62 60 #include <linux/mutex.h> 63 61 #include <linux/poll.h> ··· 348 350 * @extclockenable: true if the external clock is to be enabled 349 351 * @extclockfreq: frequency of the external clock 350 352 * @extclockgpio: ca8210 output gpio of the external clock 351 - * @gpio_reset: gpio number of ca8210 reset line 352 - * @gpio_irq: gpio number of ca8210 interrupt line 353 + * @reset_gpio: ca8210 reset GPIO descriptor 354 + * @irq_gpio: ca8210 interrupt GPIO descriptor 353 355 * @irq_id: identifier for the ca8210 irq 354 356 * 355 357 */ ··· 357 359 bool extclockenable; 358 360 unsigned int extclockfreq; 359 361 unsigned int extclockgpio; 360 - int gpio_reset; 361 - int gpio_irq; 362 + struct gpio_desc *reset_gpio; 363 + struct gpio_desc *irq_gpio; 362 364 int irq_id; 363 365 }; 364 366 ··· 630 632 struct ca8210_priv *priv = spi_get_drvdata(spi); 631 633 long status; 632 634 633 - gpio_set_value(pdata->gpio_reset, 0); 635 + gpiod_set_value(pdata->reset_gpio, 1); 634 636 reinit_completion(&priv->ca8210_is_awake); 635 637 msleep(ms); 636 - gpio_set_value(pdata->gpio_reset, 1); 638 + gpiod_set_value(pdata->reset_gpio, 0); 637 639 priv->promiscuous = false; 638 640 639 641 /* Wait until wakeup indication seen */ ··· 2786 2788 { 2787 2789 struct device *dev = &spi->dev; 2788 2790 struct ca8210_platform_data *pdata = dev_get_platdata(dev); 2789 - int ret; 2790 2791 2791 - pdata->gpio_reset = of_get_named_gpio( 2792 - spi->dev.of_node, 2793 - "reset-gpio", 2794 - 0 2795 - ); 2796 - 2797 - ret = gpio_direction_output(pdata->gpio_reset, 1); 2798 - if (ret < 0) { 2799 - dev_crit( 2800 - &spi->dev, 2801 - "Reset GPIO %d did not set to output mode\n", 2802 - pdata->gpio_reset 2803 - ); 2792 + pdata->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); 2793 + if (IS_ERR(pdata->reset_gpio)) { 2794 + dev_crit(dev, "Reset GPIO did not set to output mode\n"); 2795 + return PTR_ERR(pdata->reset_gpio); 2804 2796 } 2805 2797 2806 - return ret; 2798 + return 0; 2807 2799 } 2808 2800 2809 2801 /** ··· 2808 2820 struct ca8210_platform_data *pdata = dev_get_platdata(dev); 2809 2821 int ret; 2810 2822 2811 - pdata->gpio_irq = of_get_named_gpio( 2812 - spi->dev.of_node, 2813 - "irq-gpio", 2814 - 0 2815 - ); 2823 + pdata->irq_gpio = devm_gpiod_get(dev, "irq", GPIOD_IN); 2824 + if (IS_ERR(pdata->irq_gpio)) { 2825 + dev_crit(dev, "Could not retrieve IRQ GPIO\n"); 2826 + return PTR_ERR(pdata->irq_gpio); 2827 + } 2816 2828 2817 - pdata->irq_id = gpio_to_irq(pdata->gpio_irq); 2829 + pdata->irq_id = gpiod_to_irq(pdata->irq_gpio); 2818 2830 if (pdata->irq_id < 0) { 2819 - dev_crit( 2820 - &spi->dev, 2821 - "Could not get irq for gpio pin %d\n", 2822 - pdata->gpio_irq 2823 - ); 2824 - gpio_free(pdata->gpio_irq); 2831 + dev_crit(dev, "Could not get irq for IRQ GPIO\n"); 2825 2832 return pdata->irq_id; 2826 2833 } 2827 2834 ··· 2827 2844 "ca8210-irq", 2828 2845 spi_get_drvdata(spi) 2829 2846 ); 2830 - if (ret) { 2847 + if (ret) 2831 2848 dev_crit(&spi->dev, "request_irq %d failed\n", pdata->irq_id); 2832 - gpio_free(pdata->gpio_irq); 2833 - } 2834 2849 2835 2850 return ret; 2836 2851 }