Skip to content

Commit 77588c1

Browse files
jkrzysztLinus Walleij
authored andcommitted
gpiolib: Pass array info to get/set array functions
In order to make use of array info obtained from gpiod_get_array() and speed up processing of arrays matching single GPIO chip layout, that information must be passed to get/set array functions. Extend the functions' API with that additional parameter and update all users. Pass NULL if a user builds an array itself from single GPIOs. Cc: Jonathan Corbet <corbet@lwn.net> Cc: Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com> Cc: Geert Uytterhoeven <geert@linux-m68k.org> Cc: Sebastien Bourdelin <sebastien.bourdelin@savoirfairelinux.com> Cc: Lukas Wunner <lukas@wunner.de> Cc: Peter Korsgaard <peter.korsgaard@barco.com> Cc: Peter Rosin <peda@axentia.se> Cc: Andrew Lunn <andrew@lunn.ch> Cc: Florian Fainelli <f.fainelli@gmail.com> Cc: "David S. Miller" <davem@davemloft.net> Cc: Rojhalat Ibrahim <imr@rtschenk.de> Cc: Dominik Brodowski <linux@dominikbrodowski.net> Cc: Russell King <rmk+kernel@armlinux.org.uk> Cc: Kishon Vijay Abraham I <kishon@ti.com> Cc: Tony Lindgren <tony@atomide.com> Cc: Lars-Peter Clausen <lars@metafoo.de> Cc: Michael Hennerich <Michael.Hennerich@analog.com> Cc: Jonathan Cameron <jic23@kernel.org> Cc: Hartmut Knaack <knaack.h@gmx.de> Cc: Peter Meerwald-Stadler <pmeerw@pmeerw.net> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Jiri Slaby <jslaby@suse.com> Cc: Yegor Yefremov <yegorslists@googlemail.com> Cc: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com> Acked-by: Ulf Hansson <ulf.hansson@linaro.org> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent bf9346f commit 77588c1

15 files changed

Lines changed: 86 additions & 26 deletions

File tree

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,28 +325,36 @@ The following functions get or set the values of an array of GPIOs::
325325

326326
int gpiod_get_array_value(unsigned int array_size,
327327
struct gpio_desc **desc_array,
328+
struct gpio_array *array_info,
328329
unsigned long *value_bitmap);
329330
int gpiod_get_raw_array_value(unsigned int array_size,
330331
struct gpio_desc **desc_array,
332+
struct gpio_array *array_info,
331333
unsigned long *value_bitmap);
332334
int gpiod_get_array_value_cansleep(unsigned int array_size,
333335
struct gpio_desc **desc_array,
336+
struct gpio_array *array_info,
334337
unsigned long *value_bitmap);
335338
int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
336339
struct gpio_desc **desc_array,
340+
struct gpio_array *array_info,
337341
unsigned long *value_bitmap);
338342

339343
void gpiod_set_array_value(unsigned int array_size,
340344
struct gpio_desc **desc_array,
345+
struct gpio_array *array_info,
341346
unsigned long *value_bitmap)
342347
void gpiod_set_raw_array_value(unsigned int array_size,
343348
struct gpio_desc **desc_array,
349+
struct gpio_array *array_info,
344350
unsigned long *value_bitmap)
345351
void gpiod_set_array_value_cansleep(unsigned int array_size,
346352
struct gpio_desc **desc_array,
353+
struct gpio_array *array_info,
347354
unsigned long *value_bitmap)
348355
void gpiod_set_raw_array_value_cansleep(unsigned int array_size,
349356
struct gpio_desc **desc_array,
357+
struct gpio_array *array_info,
350358
unsigned long *value_bitmap)
351359

352360
The array can be an arbitrary set of GPIOs. The functions will try to access
@@ -358,6 +366,7 @@ accessed sequentially.
358366
The functions take three arguments:
359367
* array_size - the number of array elements
360368
* desc_array - an array of GPIO descriptors
369+
* array_info - optional information obtained from gpiod_array_get()
361370
* value_bitmap - a bitmap to store the GPIOs' values (get) or
362371
a bitmap of values to assign to the GPIOs (set)
363372

@@ -368,12 +377,13 @@ the struct gpio_descs returned by gpiod_get_array()::
368377

369378
struct gpio_descs *my_gpio_descs = gpiod_get_array(...);
370379
gpiod_set_array_value(my_gpio_descs->ndescs, my_gpio_descs->desc,
371-
my_gpio_value_bitmap);
380+
my_gpio_descs->info, my_gpio_value_bitmap);
372381

373382
It is also possible to access a completely arbitrary array of descriptors. The
374383
descriptors may be obtained using any combination of gpiod_get() and
375384
gpiod_get_array(). Afterwards the array of descriptors has to be setup
376-
manually before it can be passed to one of the above functions.
385+
manually before it can be passed to one of the above functions. In that case,
386+
array_info should be set to NULL.
377387

378388
Note that for optimal performance GPIOs belonging to the same chip should be
379389
contiguous within the array of descriptors.

‎drivers/auxdisplay/hd44780.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static void hd44780_write_gpio8(struct hd44780 *hd, u8 val, unsigned int rs)
7070
n = hd->pins[PIN_CTRL_RW] ? 10 : 9;
7171

7272
/* Present the data to the port */
73-
gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA0], values);
73+
gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA0], NULL, values);
7474

7575
hd44780_strobe_gpio(hd);
7676
}
@@ -87,7 +87,7 @@ static void hd44780_write_gpio4(struct hd44780 *hd, u8 val, unsigned int rs)
8787
n = hd->pins[PIN_CTRL_RW] ? 6 : 5;
8888

8989
/* Present the data to the port */
90-
gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4], values);
90+
gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4], NULL, values);
9191

9292
hd44780_strobe_gpio(hd);
9393

@@ -96,7 +96,7 @@ static void hd44780_write_gpio4(struct hd44780 *hd, u8 val, unsigned int rs)
9696
values[0] |= val & 0x0f;
9797

9898
/* Present the data to the port */
99-
gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4], values);
99+
gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4], NULL, values);
100100

101101
hd44780_strobe_gpio(hd);
102102
}
@@ -152,7 +152,7 @@ static void hd44780_write_cmd_raw_gpio4(struct charlcd *lcd, int cmd)
152152
n = hd->pins[PIN_CTRL_RW] ? 6 : 5;
153153

154154
/* Present the data to the port */
155-
gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4], values);
155+
gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4], NULL, values);
156156

157157
hd44780_strobe_gpio(hd);
158158
}

‎drivers/bus/ts-nbus.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ static void ts_nbus_reset_bus(struct ts_nbus *ts_nbus)
114114

115115
values[0] = 0;
116116

117-
gpiod_set_array_value_cansleep(8, ts_nbus->data->desc, values);
117+
gpiod_set_array_value_cansleep(8, ts_nbus->data->desc,
118+
ts_nbus->data->info, values);
118119
gpiod_set_value_cansleep(ts_nbus->csn, 0);
119120
gpiod_set_value_cansleep(ts_nbus->strobe, 0);
120121
gpiod_set_value_cansleep(ts_nbus->ale, 0);
@@ -159,7 +160,7 @@ static void ts_nbus_write_byte(struct ts_nbus *ts_nbus, u8 byte)
159160

160161
values[0] = byte;
161162

162-
gpiod_set_array_value_cansleep(8, gpios->desc, values);
163+
gpiod_set_array_value_cansleep(8, gpios->desc, gpios->info, values);
163164
}
164165

165166
/*

‎drivers/gpio/gpio-max3191x.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ static int max3191x_set_config(struct gpio_chip *gpio, unsigned int offset,
313313

314314
static void gpiod_set_array_single_value_cansleep(unsigned int ndescs,
315315
struct gpio_desc **desc,
316+
struct gpio_array *info,
316317
int value)
317318
{
318319
unsigned long *values;
@@ -326,7 +327,7 @@ static void gpiod_set_array_single_value_cansleep(unsigned int ndescs,
326327
else
327328
bitmap_zero(values, ndescs);
328329

329-
gpiod_set_array_value_cansleep(ndescs, desc, values);
330+
gpiod_set_array_value_cansleep(ndescs, desc, info, values);
330331
kfree(values);
331332
}
332333

@@ -399,7 +400,8 @@ static int max3191x_probe(struct spi_device *spi)
399400
if (max3191x->modesel_pins)
400401
gpiod_set_array_single_value_cansleep(
401402
max3191x->modesel_pins->ndescs,
402-
max3191x->modesel_pins->desc, max3191x->mode);
403+
max3191x->modesel_pins->desc,
404+
max3191x->modesel_pins->info, max3191x->mode);
403405

404406
max3191x->ignore_uv = device_property_read_bool(dev,
405407
"maxim,ignore-undervoltage");

‎drivers/gpio/gpiolib.c‎

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ static long linehandle_ioctl(struct file *filep, unsigned int cmd,
436436
true,
437437
lh->numdescs,
438438
lh->descs,
439+
NULL,
439440
vals);
440441
if (ret)
441442
return ret;
@@ -468,6 +469,7 @@ static long linehandle_ioctl(struct file *filep, unsigned int cmd,
468469
true,
469470
lh->numdescs,
470471
lh->descs,
472+
NULL,
471473
vals);
472474
}
473475
return -EINVAL;
@@ -2784,6 +2786,7 @@ static int gpio_chip_get_multiple(struct gpio_chip *chip,
27842786
int gpiod_get_array_value_complex(bool raw, bool can_sleep,
27852787
unsigned int array_size,
27862788
struct gpio_desc **desc_array,
2789+
struct gpio_array *array_info,
27872790
unsigned long *value_bitmap)
27882791
{
27892792
int i = 0;
@@ -2897,6 +2900,7 @@ EXPORT_SYMBOL_GPL(gpiod_get_value);
28972900
* gpiod_get_raw_array_value() - read raw values from an array of GPIOs
28982901
* @array_size: number of elements in the descriptor array / value bitmap
28992902
* @desc_array: array of GPIO descriptors whose values will be read
2903+
* @array_info: information on applicability of fast bitmap processing path
29002904
* @value_bitmap: bitmap to store the read values
29012905
*
29022906
* Read the raw values of the GPIOs, i.e. the values of the physical lines
@@ -2908,19 +2912,22 @@ EXPORT_SYMBOL_GPL(gpiod_get_value);
29082912
*/
29092913
int gpiod_get_raw_array_value(unsigned int array_size,
29102914
struct gpio_desc **desc_array,
2915+
struct gpio_array *array_info,
29112916
unsigned long *value_bitmap)
29122917
{
29132918
if (!desc_array)
29142919
return -EINVAL;
29152920
return gpiod_get_array_value_complex(true, false, array_size,
2916-
desc_array, value_bitmap);
2921+
desc_array, array_info,
2922+
value_bitmap);
29172923
}
29182924
EXPORT_SYMBOL_GPL(gpiod_get_raw_array_value);
29192925

29202926
/**
29212927
* gpiod_get_array_value() - read values from an array of GPIOs
29222928
* @array_size: number of elements in the descriptor array / value bitmap
29232929
* @desc_array: array of GPIO descriptors whose values will be read
2930+
* @array_info: information on applicability of fast bitmap processing path
29242931
* @value_bitmap: bitmap to store the read values
29252932
*
29262933
* Read the logical values of the GPIOs, i.e. taking their ACTIVE_LOW status
@@ -2931,12 +2938,14 @@ EXPORT_SYMBOL_GPL(gpiod_get_raw_array_value);
29312938
*/
29322939
int gpiod_get_array_value(unsigned int array_size,
29332940
struct gpio_desc **desc_array,
2941+
struct gpio_array *array_info,
29342942
unsigned long *value_bitmap)
29352943
{
29362944
if (!desc_array)
29372945
return -EINVAL;
29382946
return gpiod_get_array_value_complex(false, false, array_size,
2939-
desc_array, value_bitmap);
2947+
desc_array, array_info,
2948+
value_bitmap);
29402949
}
29412950
EXPORT_SYMBOL_GPL(gpiod_get_array_value);
29422951

@@ -3029,6 +3038,7 @@ static void gpio_chip_set_multiple(struct gpio_chip *chip,
30293038
int gpiod_set_array_value_complex(bool raw, bool can_sleep,
30303039
unsigned int array_size,
30313040
struct gpio_desc **desc_array,
3041+
struct gpio_array *array_info,
30323042
unsigned long *value_bitmap)
30333043
{
30343044
int i = 0;
@@ -3156,6 +3166,7 @@ EXPORT_SYMBOL_GPL(gpiod_set_value);
31563166
* gpiod_set_raw_array_value() - assign values to an array of GPIOs
31573167
* @array_size: number of elements in the descriptor array / value bitmap
31583168
* @desc_array: array of GPIO descriptors whose values will be assigned
3169+
* @array_info: information on applicability of fast bitmap processing path
31593170
* @value_bitmap: bitmap of values to assign
31603171
*
31613172
* Set the raw values of the GPIOs, i.e. the values of the physical lines
@@ -3166,19 +3177,21 @@ EXPORT_SYMBOL_GPL(gpiod_set_value);
31663177
*/
31673178
int gpiod_set_raw_array_value(unsigned int array_size,
31683179
struct gpio_desc **desc_array,
3180+
struct gpio_array *array_info,
31693181
unsigned long *value_bitmap)
31703182
{
31713183
if (!desc_array)
31723184
return -EINVAL;
31733185
return gpiod_set_array_value_complex(true, false, array_size,
3174-
desc_array, value_bitmap);
3186+
desc_array, array_info, value_bitmap);
31753187
}
31763188
EXPORT_SYMBOL_GPL(gpiod_set_raw_array_value);
31773189

31783190
/**
31793191
* gpiod_set_array_value() - assign values to an array of GPIOs
31803192
* @array_size: number of elements in the descriptor array / value bitmap
31813193
* @desc_array: array of GPIO descriptors whose values will be assigned
3194+
* @array_info: information on applicability of fast bitmap processing path
31823195
* @value_bitmap: bitmap of values to assign
31833196
*
31843197
* Set the logical values of the GPIOs, i.e. taking their ACTIVE_LOW status
@@ -3189,12 +3202,13 @@ EXPORT_SYMBOL_GPL(gpiod_set_raw_array_value);
31893202
*/
31903203
void gpiod_set_array_value(unsigned int array_size,
31913204
struct gpio_desc **desc_array,
3205+
struct gpio_array *array_info,
31923206
unsigned long *value_bitmap)
31933207
{
31943208
if (!desc_array)
31953209
return;
31963210
gpiod_set_array_value_complex(false, false, array_size, desc_array,
3197-
value_bitmap);
3211+
array_info, value_bitmap);
31983212
}
31993213
EXPORT_SYMBOL_GPL(gpiod_set_array_value);
32003214

@@ -3416,6 +3430,7 @@ EXPORT_SYMBOL_GPL(gpiod_get_value_cansleep);
34163430
* gpiod_get_raw_array_value_cansleep() - read raw values from an array of GPIOs
34173431
* @array_size: number of elements in the descriptor array / value bitmap
34183432
* @desc_array: array of GPIO descriptors whose values will be read
3433+
* @array_info: information on applicability of fast bitmap processing path
34193434
* @value_bitmap: bitmap to store the read values
34203435
*
34213436
* Read the raw values of the GPIOs, i.e. the values of the physical lines
@@ -3426,20 +3441,23 @@ EXPORT_SYMBOL_GPL(gpiod_get_value_cansleep);
34263441
*/
34273442
int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
34283443
struct gpio_desc **desc_array,
3444+
struct gpio_array *array_info,
34293445
unsigned long *value_bitmap)
34303446
{
34313447
might_sleep_if(extra_checks);
34323448
if (!desc_array)
34333449
return -EINVAL;
34343450
return gpiod_get_array_value_complex(true, true, array_size,
3435-
desc_array, value_bitmap);
3451+
desc_array, array_info,
3452+
value_bitmap);
34363453
}
34373454
EXPORT_SYMBOL_GPL(gpiod_get_raw_array_value_cansleep);
34383455

34393456
/**
34403457
* gpiod_get_array_value_cansleep() - read values from an array of GPIOs
34413458
* @array_size: number of elements in the descriptor array / value bitmap
34423459
* @desc_array: array of GPIO descriptors whose values will be read
3460+
* @array_info: information on applicability of fast bitmap processing path
34433461
* @value_bitmap: bitmap to store the read values
34443462
*
34453463
* Read the logical values of the GPIOs, i.e. taking their ACTIVE_LOW status
@@ -3449,13 +3467,15 @@ EXPORT_SYMBOL_GPL(gpiod_get_raw_array_value_cansleep);
34493467
*/
34503468
int gpiod_get_array_value_cansleep(unsigned int array_size,
34513469
struct gpio_desc **desc_array,
3470+
struct gpio_array *array_info,
34523471
unsigned long *value_bitmap)
34533472
{
34543473
might_sleep_if(extra_checks);
34553474
if (!desc_array)
34563475
return -EINVAL;
34573476
return gpiod_get_array_value_complex(false, true, array_size,
3458-
desc_array, value_bitmap);
3477+
desc_array, array_info,
3478+
value_bitmap);
34593479
}
34603480
EXPORT_SYMBOL_GPL(gpiod_get_array_value_cansleep);
34613481

@@ -3499,6 +3519,7 @@ EXPORT_SYMBOL_GPL(gpiod_set_value_cansleep);
34993519
* gpiod_set_raw_array_value_cansleep() - assign values to an array of GPIOs
35003520
* @array_size: number of elements in the descriptor array / value bitmap
35013521
* @desc_array: array of GPIO descriptors whose values will be assigned
3522+
* @array_info: information on applicability of fast bitmap processing path
35023523
* @value_bitmap: bitmap of values to assign
35033524
*
35043525
* Set the raw values of the GPIOs, i.e. the values of the physical lines
@@ -3508,13 +3529,14 @@ EXPORT_SYMBOL_GPL(gpiod_set_value_cansleep);
35083529
*/
35093530
int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
35103531
struct gpio_desc **desc_array,
3532+
struct gpio_array *array_info,
35113533
unsigned long *value_bitmap)
35123534
{
35133535
might_sleep_if(extra_checks);
35143536
if (!desc_array)
35153537
return -EINVAL;
35163538
return gpiod_set_array_value_complex(true, true, array_size, desc_array,
3517-
value_bitmap);
3539+
array_info, value_bitmap);
35183540
}
35193541
EXPORT_SYMBOL_GPL(gpiod_set_raw_array_value_cansleep);
35203542

@@ -3539,6 +3561,7 @@ void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n)
35393561
* gpiod_set_array_value_cansleep() - assign values to an array of GPIOs
35403562
* @array_size: number of elements in the descriptor array / value bitmap
35413563
* @desc_array: array of GPIO descriptors whose values will be assigned
3564+
* @array_info: information on applicability of fast bitmap processing path
35423565
* @value_bitmap: bitmap of values to assign
35433566
*
35443567
* Set the logical values of the GPIOs, i.e. taking their ACTIVE_LOW status
@@ -3548,13 +3571,14 @@ void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n)
35483571
*/
35493572
void gpiod_set_array_value_cansleep(unsigned int array_size,
35503573
struct gpio_desc **desc_array,
3574+
struct gpio_array *array_info,
35513575
unsigned long *value_bitmap)
35523576
{
35533577
might_sleep_if(extra_checks);
35543578
if (!desc_array)
35553579
return;
35563580
gpiod_set_array_value_complex(false, true, array_size, desc_array,
3557-
value_bitmap);
3581+
array_info, value_bitmap);
35583582
}
35593583
EXPORT_SYMBOL_GPL(gpiod_set_array_value_cansleep);
35603584

‎drivers/gpio/gpiolib.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,12 @@ struct gpio_desc *gpiochip_get_desc(struct gpio_chip *chip, u16 hwnum);
196196
int gpiod_get_array_value_complex(bool raw, bool can_sleep,
197197
unsigned int array_size,
198198
struct gpio_desc **desc_array,
199+
struct gpio_array *array_info,
199200
unsigned long *value_bitmap);
200201
int gpiod_set_array_value_complex(bool raw, bool can_sleep,
201202
unsigned int array_size,
202203
struct gpio_desc **desc_array,
204+
struct gpio_array *array_info,
203205
unsigned long *value_bitmap);
204206

205207
/* This is just passed between gpiolib and devres */

‎drivers/i2c/muxes/i2c-mux-gpio.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ static void i2c_mux_gpio_set(const struct gpiomux *mux, unsigned val)
3030

3131
values[0] = val;
3232

33-
gpiod_set_array_value_cansleep(mux->data.n_gpios, mux->gpios, values);
33+
gpiod_set_array_value_cansleep(mux->data.n_gpios, mux->gpios, NULL,
34+
values);
3435
}
3536

3637
static int i2c_mux_gpio_select(struct i2c_mux_core *muxc, u32 chan)

‎drivers/mmc/core/pwrseq_simple.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static void mmc_pwrseq_simple_set_gpios_value(struct mmc_pwrseq_simple *pwrseq,
4646
values[0] = value;
4747

4848
gpiod_set_array_value_cansleep(nvalues, reset_gpios->desc,
49-
values);
49+
reset_gpios->info, values);
5050
}
5151
}
5252

0 commit comments

Comments
 (0)