Skip to content

Commit 30a464a

Browse files
author
Linus Walleij
committed
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()
2 parents a28e1c0 + 9755162 commit 30a464a

11 files changed

Lines changed: 57 additions & 25 deletions

File tree

‎Documentation/driver-api/gpio/driver.rst‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ The preferred way to set up the helpers is to fill in the
416416
struct gpio_irq_chip inside struct gpio_chip before adding the gpio_chip.
417417
If you do this, the additional irq_chip will be set up by gpiolib at the
418418
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:
420420

421421
.. code-block:: c
422422
@@ -453,7 +453,7 @@ is a typical example of a cascaded interrupt handler using gpio_irq_chip::
453453
return devm_gpiochip_add_data(dev, &g->gc, g);
454454
455455
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:
457457

458458
.. code-block:: c
459459

‎drivers/gpio/Kconfig‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,13 +394,13 @@ config GPIO_MVEBU
394394

395395
config GPIO_MXC
396396
def_bool y
397-
depends on ARCH_MXC
397+
depends on ARCH_MXC || COMPILE_TEST
398398
select GPIO_GENERIC
399399
select GENERIC_IRQ_CHIP
400400

401401
config GPIO_MXS
402402
def_bool y
403-
depends on ARCH_MXS
403+
depends on ARCH_MXS || COMPILE_TEST
404404
select GPIO_GENERIC
405405
select GENERIC_IRQ_CHIP
406406

‎drivers/gpio/gpio-mmio.c‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,12 +389,10 @@ static int bgpio_get_dir(struct gpio_chip *gc, unsigned int gpio)
389389
return GPIO_LINE_DIRECTION_IN;
390390
}
391391

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)
393393
{
394394
unsigned long flags;
395395

396-
gc->set(gc, gpio, val);
397-
398396
spin_lock_irqsave(&gc->bgpio_lock, flags);
399397

400398
gc->bgpio_dir |= bgpio_line2mask(gc, gpio);
@@ -405,7 +403,21 @@ static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
405403
gc->write_reg(gc->reg_dir_out, gc->bgpio_dir);
406404

407405
spin_unlock_irqrestore(&gc->bgpio_lock, flags);
406+
}
408407

408+
static int bgpio_dir_out_dir_first(struct gpio_chip *gc, unsigned int gpio,
409+
int val)
410+
{
411+
bgpio_dir_out(gc, gpio, val);
412+
gc->set(gc, gpio, val);
413+
return 0;
414+
}
415+
416+
static int bgpio_dir_out_val_first(struct gpio_chip *gc, unsigned int gpio,
417+
int val)
418+
{
419+
gc->set(gc, gpio, val);
420+
bgpio_dir_out(gc, gpio, val);
409421
return 0;
410422
}
411423

@@ -538,7 +550,10 @@ static int bgpio_setup_direction(struct gpio_chip *gc,
538550
if (dirout || dirin) {
539551
gc->reg_dir_out = dirout;
540552
gc->reg_dir_in = dirin;
541-
gc->direction_output = bgpio_dir_out;
553+
if (flags & BGPIOF_NO_SET_ON_INPUT)
554+
gc->direction_output = bgpio_dir_out_dir_first;
555+
else
556+
gc->direction_output = bgpio_dir_out_val_first;
542557
gc->direction_input = bgpio_dir_in;
543558
gc->get_direction = bgpio_get_dir;
544559
} else {

‎drivers/gpio/gpio-mt7621.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ mediatek_gpio_bank_probe(struct device *dev,
227227
ctrl = mtk->base + GPIO_REG_DCLR + (rg->bank * GPIO_BANK_STRIDE);
228228
diro = mtk->base + GPIO_REG_CTRL + (rg->bank * GPIO_BANK_STRIDE);
229229

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);
232232
if (ret) {
233233
dev_err(dev, "bgpio_init() failed\n");
234234
return ret;

‎drivers/gpio/gpio-mvebu.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,7 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
12471247
* pins.
12481248
*/
12491249
for (i = 0; i < 4; i++) {
1250-
int irq = platform_get_irq(pdev, i);
1250+
int irq = platform_get_irq_optional(pdev, i);
12511251

12521252
if (irq < 0)
12531253
continue;

‎drivers/gpio/gpio-pl061.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,8 @@ static int pl061_probe(struct amba_device *adev, const struct amba_id *id)
326326

327327
writeb(0, pl061->base + GPIOIE); /* disable irqs */
328328
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");
333331
pl061->parent_irq = irq;
334332

335333
girq = &pl061->gc.irq;

‎drivers/gpio/gpiolib.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,9 @@ static struct gpio_desc *gpio_name_to_desc(const char * const name)
301301
struct gpio_device *gdev;
302302
unsigned long flags;
303303

304+
if (!name)
305+
return NULL;
306+
304307
spin_lock_irqsave(&gpio_lock, flags);
305308

306309
list_for_each_entry(gdev, &gpio_devices, list) {
@@ -309,7 +312,7 @@ static struct gpio_desc *gpio_name_to_desc(const char * const name)
309312
for (i = 0; i != gdev->ngpio; ++i) {
310313
struct gpio_desc *desc = &gdev->descs[i];
311314

312-
if (!desc->name || !name)
315+
if (!desc->name)
313316
continue;
314317

315318
if (!strcmp(desc->name, name)) {

‎include/linux/gpio/driver.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,7 @@ int bgpio_init(struct gpio_chip *gc, struct device *dev,
572572
#define BGPIOF_BIG_ENDIAN_BYTE_ORDER BIT(3)
573573
#define BGPIOF_READ_OUTPUT_REG_SET BIT(4) /* reg_set stores output value */
574574
#define BGPIOF_NO_OUTPUT BIT(5) /* only input */
575+
#define BGPIOF_NO_SET_ON_INPUT BIT(6)
575576

576577
int gpiochip_irq_map(struct irq_domain *d, unsigned int irq,
577578
irq_hw_number_t hwirq);

‎include/uapi/linux/gpio.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* struct gpiochip_info - Information about a certain GPIO chip
1919
* @name: the Linux kernel name of this GPIO chip
2020
* @label: a functional name for this GPIO chip, such as a product
21-
* number, may be NULL
21+
* number, may be empty
2222
* @lines: number of GPIO lines on this chip
2323
*/
2424
struct gpiochip_info {
@@ -44,10 +44,10 @@ struct gpiochip_info {
4444
* @flags: various flags for this line
4545
* @name: the name of this GPIO line, such as the output pin of the line on the
4646
* 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
4848
* @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
5151
*/
5252
struct gpioline_info {
5353
__u32 line_offset;

‎tools/gpio/gpio-hammer.c‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ int hammer_device(const char *device_name, unsigned int *lines, int nlines,
7777

7878
fprintf(stdout, "[%c] ", swirr[j]);
7979
j++;
80-
if (j == sizeof(swirr)-1)
80+
if (j == sizeof(swirr) - 1)
8181
j = 0;
8282

8383
fprintf(stdout, "[");
@@ -135,14 +135,29 @@ int main(int argc, char **argv)
135135
device_name = optarg;
136136
break;
137137
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+
139146
i++;
140147
break;
141148
case '?':
142149
print_usage();
143150
return -1;
144151
}
145152
}
153+
154+
if (i >= GPIOHANDLES_MAX) {
155+
fprintf(stderr,
156+
"Only %d occurrences of '-o' are allowed, %d were found\n",
157+
GPIOHANDLES_MAX, i + 1);
158+
return -1;
159+
}
160+
146161
nlines = i;
147162

148163
if (!device_name || !nlines) {

0 commit comments

Comments
 (0)