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.

gpio: hlwd: 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/20250910-gpio-mmio-gpio-conv-part4-v2-3-f3d1a4c57124@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

+54 -51
+54 -51
drivers/gpio/gpio-hlwd.c
··· 6 6 // Nintendo Wii (Hollywood) GPIO driver 7 7 8 8 #include <linux/gpio/driver.h> 9 + #include <linux/gpio/generic.h> 9 10 #include <linux/io.h> 10 11 #include <linux/kernel.h> 11 12 #include <linux/module.h> ··· 49 48 #define HW_GPIO_OWNER 0x3c 50 49 51 50 struct hlwd_gpio { 52 - struct gpio_chip gpioc; 51 + struct gpio_generic_chip gpioc; 53 52 struct device *dev; 54 53 void __iomem *regs; 55 54 int irq; ··· 62 61 struct hlwd_gpio *hlwd = 63 62 gpiochip_get_data(irq_desc_get_handler_data(desc)); 64 63 struct irq_chip *chip = irq_desc_get_chip(desc); 65 - unsigned long flags; 66 64 unsigned long pending; 67 65 int hwirq; 68 66 u32 emulated_pending; 69 67 70 - raw_spin_lock_irqsave(&hlwd->gpioc.bgpio_lock, flags); 71 - pending = ioread32be(hlwd->regs + HW_GPIOB_INTFLAG); 72 - pending &= ioread32be(hlwd->regs + HW_GPIOB_INTMASK); 68 + scoped_guard(gpio_generic_lock_irqsave, &hlwd->gpioc) { 69 + pending = ioread32be(hlwd->regs + HW_GPIOB_INTFLAG); 70 + pending &= ioread32be(hlwd->regs + HW_GPIOB_INTMASK); 73 71 74 - /* Treat interrupts due to edge trigger emulation separately */ 75 - emulated_pending = hlwd->edge_emulation & pending; 76 - pending &= ~emulated_pending; 77 - if (emulated_pending) { 78 - u32 level, rising, falling; 72 + /* Treat interrupts due to edge trigger emulation separately */ 73 + emulated_pending = hlwd->edge_emulation & pending; 74 + pending &= ~emulated_pending; 75 + if (emulated_pending) { 76 + u32 level, rising, falling; 79 77 80 - level = ioread32be(hlwd->regs + HW_GPIOB_INTLVL); 81 - rising = level & emulated_pending; 82 - falling = ~level & emulated_pending; 78 + level = ioread32be(hlwd->regs + HW_GPIOB_INTLVL); 79 + rising = level & emulated_pending; 80 + falling = ~level & emulated_pending; 83 81 84 - /* Invert the levels */ 85 - iowrite32be(level ^ emulated_pending, 86 - hlwd->regs + HW_GPIOB_INTLVL); 82 + /* Invert the levels */ 83 + iowrite32be(level ^ emulated_pending, 84 + hlwd->regs + HW_GPIOB_INTLVL); 87 85 88 - /* Ack all emulated-edge interrupts */ 89 - iowrite32be(emulated_pending, hlwd->regs + HW_GPIOB_INTFLAG); 86 + /* Ack all emulated-edge interrupts */ 87 + iowrite32be(emulated_pending, hlwd->regs + HW_GPIOB_INTFLAG); 90 88 91 - /* Signal interrupts only on the correct edge */ 92 - rising &= hlwd->rising_edge; 93 - falling &= hlwd->falling_edge; 89 + /* Signal interrupts only on the correct edge */ 90 + rising &= hlwd->rising_edge; 91 + falling &= hlwd->falling_edge; 94 92 95 - /* Mark emulated interrupts as pending */ 96 - pending |= rising | falling; 93 + /* Mark emulated interrupts as pending */ 94 + pending |= rising | falling; 95 + } 97 96 } 98 - raw_spin_unlock_irqrestore(&hlwd->gpioc.bgpio_lock, flags); 99 97 100 98 chained_irq_enter(chip, desc); 101 99 102 100 for_each_set_bit(hwirq, &pending, 32) 103 - generic_handle_domain_irq(hlwd->gpioc.irq.domain, hwirq); 101 + generic_handle_domain_irq(hlwd->gpioc.gc.irq.domain, hwirq); 104 102 105 103 chained_irq_exit(chip, desc); 106 104 } ··· 116 116 { 117 117 struct hlwd_gpio *hlwd = 118 118 gpiochip_get_data(irq_data_get_irq_chip_data(data)); 119 - unsigned long flags; 120 119 u32 mask; 121 120 122 - raw_spin_lock_irqsave(&hlwd->gpioc.bgpio_lock, flags); 123 - mask = ioread32be(hlwd->regs + HW_GPIOB_INTMASK); 124 - mask &= ~BIT(data->hwirq); 125 - iowrite32be(mask, hlwd->regs + HW_GPIOB_INTMASK); 126 - raw_spin_unlock_irqrestore(&hlwd->gpioc.bgpio_lock, flags); 127 - gpiochip_disable_irq(&hlwd->gpioc, irqd_to_hwirq(data)); 121 + scoped_guard(gpio_generic_lock_irqsave, &hlwd->gpioc) { 122 + mask = ioread32be(hlwd->regs + HW_GPIOB_INTMASK); 123 + mask &= ~BIT(data->hwirq); 124 + iowrite32be(mask, hlwd->regs + HW_GPIOB_INTMASK); 125 + } 126 + gpiochip_disable_irq(&hlwd->gpioc.gc, irqd_to_hwirq(data)); 128 127 } 129 128 130 129 static void hlwd_gpio_irq_unmask(struct irq_data *data) 131 130 { 132 131 struct hlwd_gpio *hlwd = 133 132 gpiochip_get_data(irq_data_get_irq_chip_data(data)); 134 - unsigned long flags; 135 133 u32 mask; 136 134 137 - gpiochip_enable_irq(&hlwd->gpioc, irqd_to_hwirq(data)); 138 - raw_spin_lock_irqsave(&hlwd->gpioc.bgpio_lock, flags); 135 + gpiochip_enable_irq(&hlwd->gpioc.gc, irqd_to_hwirq(data)); 136 + 137 + guard(gpio_generic_lock_irqsave)(&hlwd->gpioc); 138 + 139 139 mask = ioread32be(hlwd->regs + HW_GPIOB_INTMASK); 140 140 mask |= BIT(data->hwirq); 141 141 iowrite32be(mask, hlwd->regs + HW_GPIOB_INTMASK); 142 - raw_spin_unlock_irqrestore(&hlwd->gpioc.bgpio_lock, flags); 143 142 } 144 143 145 144 static void hlwd_gpio_irq_enable(struct irq_data *data) ··· 172 173 { 173 174 struct hlwd_gpio *hlwd = 174 175 gpiochip_get_data(irq_data_get_irq_chip_data(data)); 175 - unsigned long flags; 176 176 u32 level; 177 177 178 - raw_spin_lock_irqsave(&hlwd->gpioc.bgpio_lock, flags); 178 + guard(gpio_generic_lock_irqsave)(&hlwd->gpioc); 179 179 180 180 hlwd->edge_emulation &= ~BIT(data->hwirq); 181 181 ··· 195 197 hlwd_gpio_irq_setup_emulation(hlwd, data->hwirq, flow_type); 196 198 break; 197 199 default: 198 - raw_spin_unlock_irqrestore(&hlwd->gpioc.bgpio_lock, flags); 199 200 return -EINVAL; 200 201 } 201 202 202 - raw_spin_unlock_irqrestore(&hlwd->gpioc.bgpio_lock, flags); 203 203 return 0; 204 204 } 205 205 ··· 221 225 222 226 static int hlwd_gpio_probe(struct platform_device *pdev) 223 227 { 228 + struct gpio_generic_chip_config config; 224 229 struct hlwd_gpio *hlwd; 225 230 u32 ngpios; 226 231 int res; ··· 241 244 * systems where the AHBPROT memory firewall hasn't been configured to 242 245 * permit PPC access to HW_GPIO_*. 243 246 * 244 - * Note that this has to happen before bgpio_init reads the 245 - * HW_GPIOB_OUT and HW_GPIOB_DIR, because otherwise it reads the wrong 246 - * values. 247 + * Note that this has to happen before gpio_generic_chip_init() reads 248 + * the HW_GPIOB_OUT and HW_GPIOB_DIR, because otherwise it reads the 249 + * wrong values. 247 250 */ 248 251 iowrite32be(0xffffffff, hlwd->regs + HW_GPIO_OWNER); 249 252 250 - res = bgpio_init(&hlwd->gpioc, &pdev->dev, 4, 251 - hlwd->regs + HW_GPIOB_IN, hlwd->regs + HW_GPIOB_OUT, 252 - NULL, hlwd->regs + HW_GPIOB_DIR, NULL, 253 - BGPIOF_BIG_ENDIAN_BYTE_ORDER); 253 + config = (struct gpio_generic_chip_config) { 254 + .dev = &pdev->dev, 255 + .sz = 4, 256 + .dat = hlwd->regs + HW_GPIOB_IN, 257 + .set = hlwd->regs + HW_GPIOB_OUT, 258 + .dirout = hlwd->regs + HW_GPIOB_DIR, 259 + .flags = BGPIOF_BIG_ENDIAN_BYTE_ORDER, 260 + }; 261 + 262 + res = gpio_generic_chip_init(&hlwd->gpioc, &config); 254 263 if (res < 0) { 255 - dev_warn(&pdev->dev, "bgpio_init failed: %d\n", res); 264 + dev_warn(&pdev->dev, "failed to initialize generic GPIO chip: %d\n", res); 256 265 return res; 257 266 } 258 267 259 268 res = of_property_read_u32(pdev->dev.of_node, "ngpios", &ngpios); 260 269 if (res) 261 270 ngpios = 32; 262 - hlwd->gpioc.ngpio = ngpios; 271 + hlwd->gpioc.gc.ngpio = ngpios; 263 272 264 273 /* Mask and ack all interrupts */ 265 274 iowrite32be(0, hlwd->regs + HW_GPIOB_INTMASK); ··· 285 282 return hlwd->irq; 286 283 } 287 284 288 - girq = &hlwd->gpioc.irq; 285 + girq = &hlwd->gpioc.gc.irq; 289 286 gpio_irq_chip_set_chip(girq, &hlwd_gpio_irq_chip); 290 287 girq->parent_handler = hlwd_gpio_irqhandler; 291 288 girq->num_parents = 1; ··· 299 296 girq->handler = handle_level_irq; 300 297 } 301 298 302 - return devm_gpiochip_add_data(&pdev->dev, &hlwd->gpioc, hlwd); 299 + return devm_gpiochip_add_data(&pdev->dev, &hlwd->gpioc.gc, hlwd); 303 300 } 304 301 305 302 static const struct of_device_id hlwd_gpio_match[] = {