Skip to content

Commit

Permalink
Merge tag 'gpio-updates-for-v5.7-part4' of git://git.kernel.org/pub/s…
Browse files Browse the repository at this point in the history
…cm/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()
  • Loading branch information
Linus Walleij committed Mar 25, 2020
2 parents a28e1c0 + 9755162 commit 30a464a
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Documentation/driver-api/gpio/driver.rst
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ The preferred way to set up the helpers is to fill in the
struct gpio_irq_chip inside struct gpio_chip before adding the gpio_chip.
If you do this, the additional irq_chip will be set up by gpiolib at the
same time as setting up the rest of the GPIO functionality. The following
is a typical example of a cascaded interrupt handler using gpio_irq_chip::
is a typical example of a cascaded interrupt handler using gpio_irq_chip:

.. code-block:: c
Expand Down Expand Up @@ -453,7 +453,7 @@ is a typical example of a cascaded interrupt handler using gpio_irq_chip::
return devm_gpiochip_add_data(dev, &g->gc, g);
The helper support using hierarchical interrupt controllers as well.
In this case the typical set-up will look like this::
In this case the typical set-up will look like this:

.. code-block:: c
Expand Down
4 changes: 2 additions & 2 deletions drivers/gpio/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -394,13 +394,13 @@ config GPIO_MVEBU

config GPIO_MXC
def_bool y
depends on ARCH_MXC
depends on ARCH_MXC || COMPILE_TEST
select GPIO_GENERIC
select GENERIC_IRQ_CHIP

config GPIO_MXS
def_bool y
depends on ARCH_MXS
depends on ARCH_MXS || COMPILE_TEST
select GPIO_GENERIC
select GENERIC_IRQ_CHIP

Expand Down
23 changes: 19 additions & 4 deletions drivers/gpio/gpio-mmio.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,12 +389,10 @@ static int bgpio_get_dir(struct gpio_chip *gc, unsigned int gpio)
return GPIO_LINE_DIRECTION_IN;
}

static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
static void bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
{
unsigned long flags;

gc->set(gc, gpio, val);

spin_lock_irqsave(&gc->bgpio_lock, flags);

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

spin_unlock_irqrestore(&gc->bgpio_lock, flags);
}

static int bgpio_dir_out_dir_first(struct gpio_chip *gc, unsigned int gpio,
int val)
{
bgpio_dir_out(gc, gpio, val);
gc->set(gc, gpio, val);
return 0;
}

static int bgpio_dir_out_val_first(struct gpio_chip *gc, unsigned int gpio,
int val)
{
gc->set(gc, gpio, val);
bgpio_dir_out(gc, gpio, val);
return 0;
}

Expand Down Expand Up @@ -538,7 +550,10 @@ static int bgpio_setup_direction(struct gpio_chip *gc,
if (dirout || dirin) {
gc->reg_dir_out = dirout;
gc->reg_dir_in = dirin;
gc->direction_output = bgpio_dir_out;
if (flags & BGPIOF_NO_SET_ON_INPUT)
gc->direction_output = bgpio_dir_out_dir_first;
else
gc->direction_output = bgpio_dir_out_val_first;
gc->direction_input = bgpio_dir_in;
gc->get_direction = bgpio_get_dir;
} else {
Expand Down
4 changes: 2 additions & 2 deletions drivers/gpio/gpio-mt7621.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ mediatek_gpio_bank_probe(struct device *dev,
ctrl = mtk->base + GPIO_REG_DCLR + (rg->bank * GPIO_BANK_STRIDE);
diro = mtk->base + GPIO_REG_CTRL + (rg->bank * GPIO_BANK_STRIDE);

ret = bgpio_init(&rg->chip, dev, 4,
dat, set, ctrl, diro, NULL, 0);
ret = bgpio_init(&rg->chip, dev, 4, dat, set, ctrl, diro, NULL,
BGPIOF_NO_SET_ON_INPUT);
if (ret) {
dev_err(dev, "bgpio_init() failed\n");
return ret;
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpio/gpio-mvebu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
* pins.
*/
for (i = 0; i < 4; i++) {
int irq = platform_get_irq(pdev, i);
int irq = platform_get_irq_optional(pdev, i);

if (irq < 0)
continue;
Expand Down
6 changes: 2 additions & 4 deletions drivers/gpio/gpio-pl061.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,8 @@ static int pl061_probe(struct amba_device *adev, const struct amba_id *id)

writeb(0, pl061->base + GPIOIE); /* disable irqs */
irq = adev->irq[0];
if (irq < 0) {
dev_err(&adev->dev, "invalid IRQ\n");
return -ENODEV;
}
if (!irq)
dev_warn(&adev->dev, "IRQ support disabled\n");
pl061->parent_irq = irq;

girq = &pl061->gc.irq;
Expand Down
5 changes: 4 additions & 1 deletion drivers/gpio/gpiolib.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ static struct gpio_desc *gpio_name_to_desc(const char * const name)
struct gpio_device *gdev;
unsigned long flags;

if (!name)
return NULL;

spin_lock_irqsave(&gpio_lock, flags);

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

if (!desc->name || !name)
if (!desc->name)
continue;

if (!strcmp(desc->name, name)) {
Expand Down
1 change: 1 addition & 0 deletions include/linux/gpio/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ int bgpio_init(struct gpio_chip *gc, struct device *dev,
#define BGPIOF_BIG_ENDIAN_BYTE_ORDER BIT(3)
#define BGPIOF_READ_OUTPUT_REG_SET BIT(4) /* reg_set stores output value */
#define BGPIOF_NO_OUTPUT BIT(5) /* only input */
#define BGPIOF_NO_SET_ON_INPUT BIT(6)

int gpiochip_irq_map(struct irq_domain *d, unsigned int irq,
irq_hw_number_t hwirq);
Expand Down
8 changes: 4 additions & 4 deletions include/uapi/linux/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* struct gpiochip_info - Information about a certain GPIO chip
* @name: the Linux kernel name of this GPIO chip
* @label: a functional name for this GPIO chip, such as a product
* number, may be NULL
* number, may be empty
* @lines: number of GPIO lines on this chip
*/
struct gpiochip_info {
Expand All @@ -44,10 +44,10 @@ struct gpiochip_info {
* @flags: various flags for this line
* @name: the name of this GPIO line, such as the output pin of the line on the
* chip, a rail or a pin header name on a board, as specified by the gpio
* chip, may be NULL
* chip, may be empty
* @consumer: a functional name for the consumer of this GPIO line as set by
* whatever is using it, will be NULL if there is no current user but may
* also be NULL if the consumer doesn't set this up
* whatever is using it, will be empty if there is no current user but may
* also be empty if the consumer doesn't set this up
*/
struct gpioline_info {
__u32 line_offset;
Expand Down
19 changes: 17 additions & 2 deletions tools/gpio/gpio-hammer.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ int hammer_device(const char *device_name, unsigned int *lines, int nlines,

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

fprintf(stdout, "[");
Expand Down Expand Up @@ -135,14 +135,29 @@ int main(int argc, char **argv)
device_name = optarg;
break;
case 'o':
lines[i] = strtoul(optarg, NULL, 10);
/*
* Avoid overflow. Do not immediately error, we want to
* be able to accurately report on the amount of times
* '-o' was given to give an accurate error message
*/
if (i < GPIOHANDLES_MAX)
lines[i] = strtoul(optarg, NULL, 10);

i++;
break;
case '?':
print_usage();
return -1;
}
}

if (i >= GPIOHANDLES_MAX) {
fprintf(stderr,
"Only %d occurrences of '-o' are allowed, %d were found\n",
GPIOHANDLES_MAX, i + 1);
return -1;
}

nlines = i;

if (!device_name || !nlines) {
Expand Down
6 changes: 3 additions & 3 deletions tools/gpio/gpio-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <linux/gpio.h>
#include "gpio-utils.h"

#define COMSUMER "gpio-utils"
#define CONSUMER "gpio-utils"

/**
* doc: Operation of gpio
Expand Down Expand Up @@ -209,7 +209,7 @@ int gpiotools_gets(const char *device_name, unsigned int *lines,

ret = gpiotools_request_linehandle(device_name, lines, nlines,
GPIOHANDLE_REQUEST_INPUT, data,
COMSUMER);
CONSUMER);
if (ret < 0)
return ret;

Expand Down Expand Up @@ -259,7 +259,7 @@ int gpiotools_sets(const char *device_name, unsigned int *lines,

ret = gpiotools_request_linehandle(device_name, lines, nlines,
GPIOHANDLE_REQUEST_OUTPUT, data,
COMSUMER);
CONSUMER);
if (ret < 0)
return ret;

Expand Down

0 comments on commit 30a464a

Please sign in to comment.