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

Merge tag 'gpio-updates-for-v5.7-part4' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux into devel

gpio updates for v5.7 part 4

- improve comments in the uapi header
- fix documentation issues
- add a warning to gpio-pl061 when the IRQ line is not configured
- allow building gpio-mxc and gpio-mxs with COMPILE_TEST enabled
- don't print an error message when an optional IRQ is missing in gpio-mvebu
- fix a potential segfault in gpio-hammer
- fix a couple typos and coding style issues in gpio tools
- provide a new flag in gpio-mmio and use it in mt7621 to fix an issue with
the controller ignoring value setting when a GPIO is in input mode
- slightly refactor gpio_name_to_desc()

+57 -25
+2 -2
Documentation/driver-api/gpio/driver.rst
··· 416 416 struct gpio_irq_chip inside struct gpio_chip before adding the gpio_chip. 417 417 If you do this, the additional irq_chip will be set up by gpiolib at the 418 418 same time as setting up the rest of the GPIO functionality. The following 419 - is a typical example of a cascaded interrupt handler using gpio_irq_chip:: 419 + is a typical example of a cascaded interrupt handler using gpio_irq_chip: 420 420 421 421 .. code-block:: c 422 422 ··· 453 453 return devm_gpiochip_add_data(dev, &g->gc, g); 454 454 455 455 The helper support using hierarchical interrupt controllers as well. 456 - In this case the typical set-up will look like this:: 456 + In this case the typical set-up will look like this: 457 457 458 458 .. code-block:: c 459 459
+2 -2
drivers/gpio/Kconfig
··· 394 394 395 395 config GPIO_MXC 396 396 def_bool y 397 - depends on ARCH_MXC 397 + depends on ARCH_MXC || COMPILE_TEST 398 398 select GPIO_GENERIC 399 399 select GENERIC_IRQ_CHIP 400 400 401 401 config GPIO_MXS 402 402 def_bool y 403 - depends on ARCH_MXS 403 + depends on ARCH_MXS || COMPILE_TEST 404 404 select GPIO_GENERIC 405 405 select GENERIC_IRQ_CHIP 406 406
+19 -4
drivers/gpio/gpio-mmio.c
··· 389 389 return GPIO_LINE_DIRECTION_IN; 390 390 } 391 391 392 - static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) 392 + static void bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) 393 393 { 394 394 unsigned long flags; 395 - 396 - gc->set(gc, gpio, val); 397 395 398 396 spin_lock_irqsave(&gc->bgpio_lock, flags); 399 397 ··· 403 405 gc->write_reg(gc->reg_dir_out, gc->bgpio_dir); 404 406 405 407 spin_unlock_irqrestore(&gc->bgpio_lock, flags); 408 + } 406 409 410 + static int bgpio_dir_out_dir_first(struct gpio_chip *gc, unsigned int gpio, 411 + int val) 412 + { 413 + bgpio_dir_out(gc, gpio, val); 414 + gc->set(gc, gpio, val); 415 + return 0; 416 + } 417 + 418 + static int bgpio_dir_out_val_first(struct gpio_chip *gc, unsigned int gpio, 419 + int val) 420 + { 421 + gc->set(gc, gpio, val); 422 + bgpio_dir_out(gc, gpio, val); 407 423 return 0; 408 424 } 409 425 ··· 550 538 if (dirout || dirin) { 551 539 gc->reg_dir_out = dirout; 552 540 gc->reg_dir_in = dirin; 553 - gc->direction_output = bgpio_dir_out; 541 + if (flags & BGPIOF_NO_SET_ON_INPUT) 542 + gc->direction_output = bgpio_dir_out_dir_first; 543 + else 544 + gc->direction_output = bgpio_dir_out_val_first; 554 545 gc->direction_input = bgpio_dir_in; 555 546 gc->get_direction = bgpio_get_dir; 556 547 } else {
+2 -2
drivers/gpio/gpio-mt7621.c
··· 227 227 ctrl = mtk->base + GPIO_REG_DCLR + (rg->bank * GPIO_BANK_STRIDE); 228 228 diro = mtk->base + GPIO_REG_CTRL + (rg->bank * GPIO_BANK_STRIDE); 229 229 230 - ret = bgpio_init(&rg->chip, dev, 4, 231 - dat, set, ctrl, diro, NULL, 0); 230 + ret = bgpio_init(&rg->chip, dev, 4, dat, set, ctrl, diro, NULL, 231 + BGPIOF_NO_SET_ON_INPUT); 232 232 if (ret) { 233 233 dev_err(dev, "bgpio_init() failed\n"); 234 234 return ret;
+1 -1
drivers/gpio/gpio-mvebu.c
··· 1247 1247 * pins. 1248 1248 */ 1249 1249 for (i = 0; i < 4; i++) { 1250 - int irq = platform_get_irq(pdev, i); 1250 + int irq = platform_get_irq_optional(pdev, i); 1251 1251 1252 1252 if (irq < 0) 1253 1253 continue;
+2 -4
drivers/gpio/gpio-pl061.c
··· 326 326 327 327 writeb(0, pl061->base + GPIOIE); /* disable irqs */ 328 328 irq = adev->irq[0]; 329 - if (irq < 0) { 330 - dev_err(&adev->dev, "invalid IRQ\n"); 331 - return -ENODEV; 332 - } 329 + if (!irq) 330 + dev_warn(&adev->dev, "IRQ support disabled\n"); 333 331 pl061->parent_irq = irq; 334 332 335 333 girq = &pl061->gc.irq;
+4 -1
drivers/gpio/gpiolib.c
··· 301 301 struct gpio_device *gdev; 302 302 unsigned long flags; 303 303 304 + if (!name) 305 + return NULL; 306 + 304 307 spin_lock_irqsave(&gpio_lock, flags); 305 308 306 309 list_for_each_entry(gdev, &gpio_devices, list) { ··· 312 309 for (i = 0; i != gdev->ngpio; ++i) { 313 310 struct gpio_desc *desc = &gdev->descs[i]; 314 311 315 - if (!desc->name || !name) 312 + if (!desc->name) 316 313 continue; 317 314 318 315 if (!strcmp(desc->name, name)) {
+1
include/linux/gpio/driver.h
··· 572 572 #define BGPIOF_BIG_ENDIAN_BYTE_ORDER BIT(3) 573 573 #define BGPIOF_READ_OUTPUT_REG_SET BIT(4) /* reg_set stores output value */ 574 574 #define BGPIOF_NO_OUTPUT BIT(5) /* only input */ 575 + #define BGPIOF_NO_SET_ON_INPUT BIT(6) 575 576 576 577 int gpiochip_irq_map(struct irq_domain *d, unsigned int irq, 577 578 irq_hw_number_t hwirq);
+4 -4
include/uapi/linux/gpio.h
··· 18 18 * struct gpiochip_info - Information about a certain GPIO chip 19 19 * @name: the Linux kernel name of this GPIO chip 20 20 * @label: a functional name for this GPIO chip, such as a product 21 - * number, may be NULL 21 + * number, may be empty 22 22 * @lines: number of GPIO lines on this chip 23 23 */ 24 24 struct gpiochip_info { ··· 44 44 * @flags: various flags for this line 45 45 * @name: the name of this GPIO line, such as the output pin of the line on the 46 46 * chip, a rail or a pin header name on a board, as specified by the gpio 47 - * chip, may be NULL 47 + * chip, may be empty 48 48 * @consumer: a functional name for the consumer of this GPIO line as set by 49 - * whatever is using it, will be NULL if there is no current user but may 50 - * also be NULL if the consumer doesn't set this up 49 + * whatever is using it, will be empty if there is no current user but may 50 + * also be empty if the consumer doesn't set this up 51 51 */ 52 52 struct gpioline_info { 53 53 __u32 line_offset;
+17 -2
tools/gpio/gpio-hammer.c
··· 77 77 78 78 fprintf(stdout, "[%c] ", swirr[j]); 79 79 j++; 80 - if (j == sizeof(swirr)-1) 80 + if (j == sizeof(swirr) - 1) 81 81 j = 0; 82 82 83 83 fprintf(stdout, "["); ··· 135 135 device_name = optarg; 136 136 break; 137 137 case 'o': 138 - lines[i] = strtoul(optarg, NULL, 10); 138 + /* 139 + * Avoid overflow. Do not immediately error, we want to 140 + * be able to accurately report on the amount of times 141 + * '-o' was given to give an accurate error message 142 + */ 143 + if (i < GPIOHANDLES_MAX) 144 + lines[i] = strtoul(optarg, NULL, 10); 145 + 139 146 i++; 140 147 break; 141 148 case '?': ··· 150 143 return -1; 151 144 } 152 145 } 146 + 147 + if (i >= GPIOHANDLES_MAX) { 148 + fprintf(stderr, 149 + "Only %d occurrences of '-o' are allowed, %d were found\n", 150 + GPIOHANDLES_MAX, i + 1); 151 + return -1; 152 + } 153 + 153 154 nlines = i; 154 155 155 156 if (!device_name || !nlines) {
+3 -3
tools/gpio/gpio-utils.c
··· 17 17 #include <linux/gpio.h> 18 18 #include "gpio-utils.h" 19 19 20 - #define COMSUMER "gpio-utils" 20 + #define CONSUMER "gpio-utils" 21 21 22 22 /** 23 23 * doc: Operation of gpio ··· 209 209 210 210 ret = gpiotools_request_linehandle(device_name, lines, nlines, 211 211 GPIOHANDLE_REQUEST_INPUT, data, 212 - COMSUMER); 212 + CONSUMER); 213 213 if (ret < 0) 214 214 return ret; 215 215 ··· 259 259 260 260 ret = gpiotools_request_linehandle(device_name, lines, nlines, 261 261 GPIOHANDLE_REQUEST_OUTPUT, data, 262 - COMSUMER); 262 + CONSUMER); 263 263 if (ret < 0) 264 264 return ret; 265 265