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: mt7621: 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-8-f3d1a4c57124@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

+32 -19
+32 -19
drivers/gpio/gpio-mt7621.c
··· 6 6 7 7 #include <linux/err.h> 8 8 #include <linux/gpio/driver.h> 9 + #include <linux/gpio/generic.h> 9 10 #include <linux/interrupt.h> 10 11 #include <linux/io.h> 11 12 #include <linux/module.h> ··· 31 30 32 31 struct mtk_gc { 33 32 struct irq_chip irq_chip; 34 - struct gpio_chip chip; 33 + struct gpio_generic_chip chip; 35 34 spinlock_t lock; 36 35 int bank; 37 36 u32 rising; ··· 60 59 static inline struct mtk_gc * 61 60 to_mediatek_gpio(struct gpio_chip *chip) 62 61 { 63 - return container_of(chip, struct mtk_gc, chip); 62 + struct gpio_generic_chip *gen_gc = to_gpio_generic_chip(chip); 63 + 64 + return container_of(gen_gc, struct mtk_gc, chip); 64 65 } 65 66 66 67 static inline void 67 68 mtk_gpio_w32(struct mtk_gc *rg, u32 offset, u32 val) 68 69 { 69 - struct gpio_chip *gc = &rg->chip; 70 + struct gpio_chip *gc = &rg->chip.gc; 70 71 struct mtk *mtk = gpiochip_get_data(gc); 71 72 72 73 offset = (rg->bank * GPIO_BANK_STRIDE) + offset; 73 - gc->write_reg(mtk->base + offset, val); 74 + gpio_generic_write_reg(&rg->chip, mtk->base + offset, val); 74 75 } 75 76 76 77 static inline u32 77 78 mtk_gpio_r32(struct mtk_gc *rg, u32 offset) 78 79 { 79 - struct gpio_chip *gc = &rg->chip; 80 + struct gpio_chip *gc = &rg->chip.gc; 80 81 struct mtk *mtk = gpiochip_get_data(gc); 81 82 82 83 offset = (rg->bank * GPIO_BANK_STRIDE) + offset; 83 - return gc->read_reg(mtk->base + offset); 84 + return gpio_generic_read_reg(&rg->chip, mtk->base + offset); 84 85 } 85 86 86 87 static irqreturn_t ··· 223 220 static int 224 221 mediatek_gpio_bank_probe(struct device *dev, int bank) 225 222 { 223 + struct gpio_generic_chip_config config; 226 224 struct mtk *mtk = dev_get_drvdata(dev); 227 225 struct mtk_gc *rg; 228 226 void __iomem *dat, *set, *ctrl, *diro; ··· 240 236 ctrl = mtk->base + GPIO_REG_DCLR + (rg->bank * GPIO_BANK_STRIDE); 241 237 diro = mtk->base + GPIO_REG_CTRL + (rg->bank * GPIO_BANK_STRIDE); 242 238 243 - ret = bgpio_init(&rg->chip, dev, 4, dat, set, ctrl, diro, NULL, 244 - BGPIOF_NO_SET_ON_INPUT); 239 + config = (struct gpio_generic_chip_config) { 240 + .dev = dev, 241 + .sz = 4, 242 + .dat = dat, 243 + .set = set, 244 + .clr = ctrl, 245 + .dirout = diro, 246 + .flags = BGPIOF_NO_SET_ON_INPUT, 247 + }; 248 + 249 + ret = gpio_generic_chip_init(&rg->chip, &config); 245 250 if (ret) { 246 - dev_err(dev, "bgpio_init() failed\n"); 251 + dev_err(dev, "failed to initialize generic GPIO chip\n"); 247 252 return ret; 248 253 } 249 254 250 - rg->chip.of_gpio_n_cells = 2; 251 - rg->chip.of_xlate = mediatek_gpio_xlate; 252 - rg->chip.label = devm_kasprintf(dev, GFP_KERNEL, "%s-bank%d", 255 + rg->chip.gc.of_gpio_n_cells = 2; 256 + rg->chip.gc.of_xlate = mediatek_gpio_xlate; 257 + rg->chip.gc.label = devm_kasprintf(dev, GFP_KERNEL, "%s-bank%d", 253 258 dev_name(dev), bank); 254 - if (!rg->chip.label) 259 + if (!rg->chip.gc.label) 255 260 return -ENOMEM; 256 261 257 - rg->chip.offset = bank * MTK_BANK_WIDTH; 262 + rg->chip.gc.offset = bank * MTK_BANK_WIDTH; 258 263 259 264 if (mtk->gpio_irq) { 260 265 struct gpio_irq_chip *girq; ··· 274 261 */ 275 262 ret = devm_request_irq(dev, mtk->gpio_irq, 276 263 mediatek_gpio_irq_handler, IRQF_SHARED, 277 - rg->chip.label, &rg->chip); 264 + rg->chip.gc.label, &rg->chip.gc); 278 265 279 266 if (ret) { 280 267 dev_err(dev, "Error requesting IRQ %d: %d\n", ··· 282 269 return ret; 283 270 } 284 271 285 - girq = &rg->chip.irq; 272 + girq = &rg->chip.gc.irq; 286 273 gpio_irq_chip_set_chip(girq, &mt7621_irq_chip); 287 274 /* This will let us handle the parent IRQ in the driver */ 288 275 girq->parent_handler = NULL; ··· 292 279 girq->handler = handle_simple_irq; 293 280 } 294 281 295 - ret = devm_gpiochip_add_data(dev, &rg->chip, mtk); 282 + ret = devm_gpiochip_add_data(dev, &rg->chip.gc, mtk); 296 283 if (ret < 0) { 297 284 dev_err(dev, "Could not register gpio %d, ret=%d\n", 298 - rg->chip.ngpio, ret); 285 + rg->chip.gc.ngpio, ret); 299 286 return ret; 300 287 } 301 288 302 289 /* set polarity to low for all gpios */ 303 290 mtk_gpio_w32(rg, GPIO_REG_POL, 0); 304 291 305 - dev_info(dev, "registering %d gpios\n", rg->chip.ngpio); 292 + dev_info(dev, "registering %d gpios\n", rg->chip.gc.ngpio); 306 293 307 294 return 0; 308 295 }