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

gpiolib: Pass bitmaps, not integer arrays, to get/set array

Most users of get/set array functions iterate consecutive bits of data,
usually a single integer, while processing array of results obtained
from, or building an array of values to be passed to those functions.
Save time wasted on those iterations by changing the functions' API to
accept bitmaps.

All current users are updated as well.

More benefits from the change are expected as soon as planned support
for accepting/passing those bitmaps directly from/to respective GPIO
chip callbacks if applicable is implemented.

Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>
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>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Tested-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Janusz Krzysztofik and committed by
Linus Walleij
b9762beb 5b394b2d

+136 -176
+11 -11
Documentation/driver-api/gpio/consumer.rst
··· 323 323 324 324 int gpiod_get_array_value(unsigned int array_size, 325 325 struct gpio_desc **desc_array, 326 - int *value_array); 326 + unsigned long *value_bitmap); 327 327 int gpiod_get_raw_array_value(unsigned int array_size, 328 328 struct gpio_desc **desc_array, 329 - int *value_array); 329 + unsigned long *value_bitmap); 330 330 int gpiod_get_array_value_cansleep(unsigned int array_size, 331 331 struct gpio_desc **desc_array, 332 - int *value_array); 332 + unsigned long *value_bitmap); 333 333 int gpiod_get_raw_array_value_cansleep(unsigned int array_size, 334 334 struct gpio_desc **desc_array, 335 - int *value_array); 335 + unsigned long *value_bitmap); 336 336 337 337 void gpiod_set_array_value(unsigned int array_size, 338 338 struct gpio_desc **desc_array, 339 - int *value_array) 339 + unsigned long *value_bitmap) 340 340 void gpiod_set_raw_array_value(unsigned int array_size, 341 341 struct gpio_desc **desc_array, 342 - int *value_array) 342 + unsigned long *value_bitmap) 343 343 void gpiod_set_array_value_cansleep(unsigned int array_size, 344 344 struct gpio_desc **desc_array, 345 - int *value_array) 345 + unsigned long *value_bitmap) 346 346 void gpiod_set_raw_array_value_cansleep(unsigned int array_size, 347 347 struct gpio_desc **desc_array, 348 - int *value_array) 348 + unsigned long *value_bitmap) 349 349 350 350 The array can be an arbitrary set of GPIOs. The functions will try to access 351 351 GPIOs belonging to the same bank or chip simultaneously if supported by the ··· 356 356 The functions take three arguments: 357 357 * array_size - the number of array elements 358 358 * desc_array - an array of GPIO descriptors 359 - * value_array - an array to store the GPIOs' values (get) or 360 - an array of values to assign to the GPIOs (set) 359 + * value_bitmap - a bitmap to store the GPIOs' values (get) or 360 + a bitmap of values to assign to the GPIOs (set) 361 361 362 362 The descriptor array can be obtained using the gpiod_get_array() function 363 363 or one of its variants. If the group of descriptors returned by that function ··· 366 366 367 367 struct gpio_descs *my_gpio_descs = gpiod_get_array(...); 368 368 gpiod_set_array_value(my_gpio_descs->ndescs, my_gpio_descs->desc, 369 - my_gpio_values); 369 + my_gpio_value_bitmap); 370 370 371 371 It is also possible to access a completely arbitrary array of descriptors. The 372 372 descriptors may be obtained using any combination of gpiod_get() and
+19 -38
drivers/auxdisplay/hd44780.c
··· 62 62 /* write to an LCD panel register in 8 bit GPIO mode */ 63 63 static void hd44780_write_gpio8(struct hd44780 *hd, u8 val, unsigned int rs) 64 64 { 65 - int values[10]; /* for DATA[0-7], RS, RW */ 66 - unsigned int i, n; 65 + DECLARE_BITMAP(values, 10); /* for DATA[0-7], RS, RW */ 66 + unsigned int n; 67 67 68 - for (i = 0; i < 8; i++) 69 - values[PIN_DATA0 + i] = !!(val & BIT(i)); 70 - values[PIN_CTRL_RS] = rs; 71 - n = 9; 72 - if (hd->pins[PIN_CTRL_RW]) { 73 - values[PIN_CTRL_RW] = 0; 74 - n++; 75 - } 68 + values[0] = val; 69 + __assign_bit(8, values, rs); 70 + n = hd->pins[PIN_CTRL_RW] ? 10 : 9; 76 71 77 72 /* Present the data to the port */ 78 73 gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA0], values); ··· 78 83 /* write to an LCD panel register in 4 bit GPIO mode */ 79 84 static void hd44780_write_gpio4(struct hd44780 *hd, u8 val, unsigned int rs) 80 85 { 81 - int values[10]; /* for DATA[0-7], RS, RW, but DATA[0-3] is unused */ 82 - unsigned int i, n; 86 + DECLARE_BITMAP(values, 6); /* for DATA[4-7], RS, RW */ 87 + unsigned int n; 83 88 84 89 /* High nibble + RS, RW */ 85 - for (i = 4; i < 8; i++) 86 - values[PIN_DATA0 + i] = !!(val & BIT(i)); 87 - values[PIN_CTRL_RS] = rs; 88 - n = 5; 89 - if (hd->pins[PIN_CTRL_RW]) { 90 - values[PIN_CTRL_RW] = 0; 91 - n++; 92 - } 90 + values[0] = val >> 4; 91 + __assign_bit(4, values, rs); 92 + n = hd->pins[PIN_CTRL_RW] ? 6 : 5; 93 93 94 94 /* Present the data to the port */ 95 - gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4], 96 - &values[PIN_DATA4]); 95 + gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4], values); 97 96 98 97 hd44780_strobe_gpio(hd); 99 98 100 99 /* Low nibble */ 101 - for (i = 0; i < 4; i++) 102 - values[PIN_DATA4 + i] = !!(val & BIT(i)); 100 + values[0] &= ~0x0fUL; 101 + values[0] |= val & 0x0f; 103 102 104 103 /* Present the data to the port */ 105 - gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4], 106 - &values[PIN_DATA4]); 104 + gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4], values); 107 105 108 106 hd44780_strobe_gpio(hd); 109 107 } ··· 143 155 /* Send 4-bits of a command to the LCD panel in raw 4 bit GPIO mode */ 144 156 static void hd44780_write_cmd_raw_gpio4(struct charlcd *lcd, int cmd) 145 157 { 146 - int values[10]; /* for DATA[0-7], RS, RW, but DATA[0-3] is unused */ 158 + DECLARE_BITMAP(values, 6); /* for DATA[4-7], RS, RW */ 147 159 struct hd44780 *hd = lcd->drvdata; 148 - unsigned int i, n; 160 + unsigned int n; 149 161 150 162 /* Command nibble + RS, RW */ 151 - for (i = 0; i < 4; i++) 152 - values[PIN_DATA4 + i] = !!(cmd & BIT(i)); 153 - values[PIN_CTRL_RS] = 0; 154 - n = 5; 155 - if (hd->pins[PIN_CTRL_RW]) { 156 - values[PIN_CTRL_RW] = 0; 157 - n++; 158 - } 163 + values[0] = cmd & 0x0f; 164 + n = hd->pins[PIN_CTRL_RW] ? 6 : 5; 159 165 160 166 /* Present the data to the port */ 161 - gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4], 162 - &values[PIN_DATA4]); 167 + gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4], values); 163 168 164 169 hd44780_strobe_gpio(hd); 165 170 }
+4 -11
drivers/bus/ts-nbus.c
··· 110 110 */ 111 111 static void ts_nbus_reset_bus(struct ts_nbus *ts_nbus) 112 112 { 113 - int i; 114 - int values[8]; 113 + DECLARE_BITMAP(values, 8); 115 114 116 - for (i = 0; i < 8; i++) 117 - values[i] = 0; 115 + values[0] = 0; 118 116 119 117 gpiod_set_array_value_cansleep(8, ts_nbus->data->desc, values); 120 118 gpiod_set_value_cansleep(ts_nbus->csn, 0); ··· 155 157 static void ts_nbus_write_byte(struct ts_nbus *ts_nbus, u8 byte) 156 158 { 157 159 struct gpio_descs *gpios = ts_nbus->data; 158 - int i; 159 - int values[8]; 160 + DECLARE_BITMAP(values, 8); 160 161 161 - for (i = 0; i < 8; i++) 162 - if (byte & BIT(i)) 163 - values[i] = 1; 164 - else 165 - values[i] = 0; 162 + values[0] = byte; 166 163 167 164 gpiod_set_array_value_cansleep(8, gpios->desc, values); 168 165 }
+6 -4
drivers/gpio/gpio-max3191x.c
··· 315 315 struct gpio_desc **desc, 316 316 int value) 317 317 { 318 - int i, *values; 318 + unsigned long *values; 319 319 320 - values = kmalloc_array(ndescs, sizeof(*values), GFP_KERNEL); 320 + values = bitmap_alloc(ndescs, GFP_KERNEL); 321 321 if (!values) 322 322 return; 323 323 324 - for (i = 0; i < ndescs; i++) 325 - values[i] = value; 324 + if (value) 325 + bitmap_fill(values, ndescs); 326 + else 327 + bitmap_zero(values, ndescs); 326 328 327 329 gpiod_set_array_value_cansleep(ndescs, desc, values); 328 330 kfree(values);
+43 -39
drivers/gpio/gpiolib.c
··· 427 427 struct linehandle_state *lh = filep->private_data; 428 428 void __user *ip = (void __user *)arg; 429 429 struct gpiohandle_data ghd; 430 - int vals[GPIOHANDLES_MAX]; 430 + DECLARE_BITMAP(vals, GPIOHANDLES_MAX); 431 431 int i; 432 432 433 433 if (cmd == GPIOHANDLE_GET_LINE_VALUES_IOCTL) { ··· 442 442 443 443 memset(&ghd, 0, sizeof(ghd)); 444 444 for (i = 0; i < lh->numdescs; i++) 445 - ghd.values[i] = vals[i]; 445 + ghd.values[i] = test_bit(i, vals); 446 446 447 447 if (copy_to_user(ip, &ghd, sizeof(ghd))) 448 448 return -EFAULT; ··· 461 461 462 462 /* Clamp all values to [0,1] */ 463 463 for (i = 0; i < lh->numdescs; i++) 464 - vals[i] = !!ghd.values[i]; 464 + __assign_bit(i, vals, ghd.values[i]); 465 465 466 466 /* Reuse the array setting function */ 467 467 return gpiod_set_array_value_complex(false, ··· 2784 2784 int gpiod_get_array_value_complex(bool raw, bool can_sleep, 2785 2785 unsigned int array_size, 2786 2786 struct gpio_desc **desc_array, 2787 - int *value_array) 2787 + unsigned long *value_bitmap) 2788 2788 { 2789 2789 int i = 0; 2790 2790 ··· 2835 2835 2836 2836 if (!raw && test_bit(FLAG_ACTIVE_LOW, &desc->flags)) 2837 2837 value = !value; 2838 - value_array[j] = value; 2838 + __assign_bit(j, value_bitmap, value); 2839 2839 trace_gpio_value(desc_to_gpio(desc), 1, value); 2840 2840 } 2841 2841 ··· 2895 2895 2896 2896 /** 2897 2897 * gpiod_get_raw_array_value() - read raw values from an array of GPIOs 2898 - * @array_size: number of elements in the descriptor / value arrays 2898 + * @array_size: number of elements in the descriptor array / value bitmap 2899 2899 * @desc_array: array of GPIO descriptors whose values will be read 2900 - * @value_array: array to store the read values 2900 + * @value_bitmap: bitmap to store the read values 2901 2901 * 2902 2902 * Read the raw values of the GPIOs, i.e. the values of the physical lines 2903 2903 * without regard for their ACTIVE_LOW status. Return 0 in case of success, ··· 2907 2907 * and it will complain if the GPIO chip functions potentially sleep. 2908 2908 */ 2909 2909 int gpiod_get_raw_array_value(unsigned int array_size, 2910 - struct gpio_desc **desc_array, int *value_array) 2910 + struct gpio_desc **desc_array, 2911 + unsigned long *value_bitmap) 2911 2912 { 2912 2913 if (!desc_array) 2913 2914 return -EINVAL; 2914 2915 return gpiod_get_array_value_complex(true, false, array_size, 2915 - desc_array, value_array); 2916 + desc_array, value_bitmap); 2916 2917 } 2917 2918 EXPORT_SYMBOL_GPL(gpiod_get_raw_array_value); 2918 2919 2919 2920 /** 2920 2921 * gpiod_get_array_value() - read values from an array of GPIOs 2921 - * @array_size: number of elements in the descriptor / value arrays 2922 + * @array_size: number of elements in the descriptor array / value bitmap 2922 2923 * @desc_array: array of GPIO descriptors whose values will be read 2923 - * @value_array: array to store the read values 2924 + * @value_bitmap: bitmap to store the read values 2924 2925 * 2925 2926 * Read the logical values of the GPIOs, i.e. taking their ACTIVE_LOW status 2926 2927 * into account. Return 0 in case of success, else an error code. ··· 2930 2929 * and it will complain if the GPIO chip functions potentially sleep. 2931 2930 */ 2932 2931 int gpiod_get_array_value(unsigned int array_size, 2933 - struct gpio_desc **desc_array, int *value_array) 2932 + struct gpio_desc **desc_array, 2933 + unsigned long *value_bitmap) 2934 2934 { 2935 2935 if (!desc_array) 2936 2936 return -EINVAL; 2937 2937 return gpiod_get_array_value_complex(false, false, array_size, 2938 - desc_array, value_array); 2938 + desc_array, value_bitmap); 2939 2939 } 2940 2940 EXPORT_SYMBOL_GPL(gpiod_get_array_value); 2941 2941 ··· 3029 3027 int gpiod_set_array_value_complex(bool raw, bool can_sleep, 3030 3028 unsigned int array_size, 3031 3029 struct gpio_desc **desc_array, 3032 - int *value_array) 3030 + unsigned long *value_bitmap) 3033 3031 { 3034 3032 int i = 0; 3035 3033 ··· 3058 3056 do { 3059 3057 struct gpio_desc *desc = desc_array[i]; 3060 3058 int hwgpio = gpio_chip_hwgpio(desc); 3061 - int value = value_array[i]; 3059 + int value = test_bit(i, value_bitmap); 3062 3060 3063 3061 if (!raw && test_bit(FLAG_ACTIVE_LOW, &desc->flags)) 3064 3062 value = !value; ··· 3154 3152 3155 3153 /** 3156 3154 * gpiod_set_raw_array_value() - assign values to an array of GPIOs 3157 - * @array_size: number of elements in the descriptor / value arrays 3155 + * @array_size: number of elements in the descriptor array / value bitmap 3158 3156 * @desc_array: array of GPIO descriptors whose values will be assigned 3159 - * @value_array: array of values to assign 3157 + * @value_bitmap: bitmap of values to assign 3160 3158 * 3161 3159 * Set the raw values of the GPIOs, i.e. the values of the physical lines 3162 3160 * without regard for their ACTIVE_LOW status. ··· 3165 3163 * complain if the GPIO chip functions potentially sleep. 3166 3164 */ 3167 3165 int gpiod_set_raw_array_value(unsigned int array_size, 3168 - struct gpio_desc **desc_array, int *value_array) 3166 + struct gpio_desc **desc_array, 3167 + unsigned long *value_bitmap) 3169 3168 { 3170 3169 if (!desc_array) 3171 3170 return -EINVAL; 3172 3171 return gpiod_set_array_value_complex(true, false, array_size, 3173 - desc_array, value_array); 3172 + desc_array, value_bitmap); 3174 3173 } 3175 3174 EXPORT_SYMBOL_GPL(gpiod_set_raw_array_value); 3176 3175 3177 3176 /** 3178 3177 * gpiod_set_array_value() - assign values to an array of GPIOs 3179 - * @array_size: number of elements in the descriptor / value arrays 3178 + * @array_size: number of elements in the descriptor array / value bitmap 3180 3179 * @desc_array: array of GPIO descriptors whose values will be assigned 3181 - * @value_array: array of values to assign 3180 + * @value_bitmap: bitmap of values to assign 3182 3181 * 3183 3182 * Set the logical values of the GPIOs, i.e. taking their ACTIVE_LOW status 3184 3183 * into account. ··· 3188 3185 * complain if the GPIO chip functions potentially sleep. 3189 3186 */ 3190 3187 void gpiod_set_array_value(unsigned int array_size, 3191 - struct gpio_desc **desc_array, int *value_array) 3188 + struct gpio_desc **desc_array, 3189 + unsigned long *value_bitmap) 3192 3190 { 3193 3191 if (!desc_array) 3194 3192 return; 3195 3193 gpiod_set_array_value_complex(false, false, array_size, desc_array, 3196 - value_array); 3194 + value_bitmap); 3197 3195 } 3198 3196 EXPORT_SYMBOL_GPL(gpiod_set_array_value); 3199 3197 ··· 3414 3410 3415 3411 /** 3416 3412 * gpiod_get_raw_array_value_cansleep() - read raw values from an array of GPIOs 3417 - * @array_size: number of elements in the descriptor / value arrays 3413 + * @array_size: number of elements in the descriptor array / value bitmap 3418 3414 * @desc_array: array of GPIO descriptors whose values will be read 3419 - * @value_array: array to store the read values 3415 + * @value_bitmap: bitmap to store the read values 3420 3416 * 3421 3417 * Read the raw values of the GPIOs, i.e. the values of the physical lines 3422 3418 * without regard for their ACTIVE_LOW status. Return 0 in case of success, ··· 3426 3422 */ 3427 3423 int gpiod_get_raw_array_value_cansleep(unsigned int array_size, 3428 3424 struct gpio_desc **desc_array, 3429 - int *value_array) 3425 + unsigned long *value_bitmap) 3430 3426 { 3431 3427 might_sleep_if(extra_checks); 3432 3428 if (!desc_array) 3433 3429 return -EINVAL; 3434 3430 return gpiod_get_array_value_complex(true, true, array_size, 3435 - desc_array, value_array); 3431 + desc_array, value_bitmap); 3436 3432 } 3437 3433 EXPORT_SYMBOL_GPL(gpiod_get_raw_array_value_cansleep); 3438 3434 3439 3435 /** 3440 3436 * gpiod_get_array_value_cansleep() - read values from an array of GPIOs 3441 - * @array_size: number of elements in the descriptor / value arrays 3437 + * @array_size: number of elements in the descriptor array / value bitmap 3442 3438 * @desc_array: array of GPIO descriptors whose values will be read 3443 - * @value_array: array to store the read values 3439 + * @value_bitmap: bitmap to store the read values 3444 3440 * 3445 3441 * Read the logical values of the GPIOs, i.e. taking their ACTIVE_LOW status 3446 3442 * into account. Return 0 in case of success, else an error code. ··· 3449 3445 */ 3450 3446 int gpiod_get_array_value_cansleep(unsigned int array_size, 3451 3447 struct gpio_desc **desc_array, 3452 - int *value_array) 3448 + unsigned long *value_bitmap) 3453 3449 { 3454 3450 might_sleep_if(extra_checks); 3455 3451 if (!desc_array) 3456 3452 return -EINVAL; 3457 3453 return gpiod_get_array_value_complex(false, true, array_size, 3458 - desc_array, value_array); 3454 + desc_array, value_bitmap); 3459 3455 } 3460 3456 EXPORT_SYMBOL_GPL(gpiod_get_array_value_cansleep); 3461 3457 ··· 3497 3493 3498 3494 /** 3499 3495 * gpiod_set_raw_array_value_cansleep() - assign values to an array of GPIOs 3500 - * @array_size: number of elements in the descriptor / value arrays 3496 + * @array_size: number of elements in the descriptor array / value bitmap 3501 3497 * @desc_array: array of GPIO descriptors whose values will be assigned 3502 - * @value_array: array of values to assign 3498 + * @value_bitmap: bitmap of values to assign 3503 3499 * 3504 3500 * Set the raw values of the GPIOs, i.e. the values of the physical lines 3505 3501 * without regard for their ACTIVE_LOW status. ··· 3508 3504 */ 3509 3505 int gpiod_set_raw_array_value_cansleep(unsigned int array_size, 3510 3506 struct gpio_desc **desc_array, 3511 - int *value_array) 3507 + unsigned long *value_bitmap) 3512 3508 { 3513 3509 might_sleep_if(extra_checks); 3514 3510 if (!desc_array) 3515 3511 return -EINVAL; 3516 3512 return gpiod_set_array_value_complex(true, true, array_size, desc_array, 3517 - value_array); 3513 + value_bitmap); 3518 3514 } 3519 3515 EXPORT_SYMBOL_GPL(gpiod_set_raw_array_value_cansleep); 3520 3516 ··· 3537 3533 3538 3534 /** 3539 3535 * gpiod_set_array_value_cansleep() - assign values to an array of GPIOs 3540 - * @array_size: number of elements in the descriptor / value arrays 3536 + * @array_size: number of elements in the descriptor array / value bitmap 3541 3537 * @desc_array: array of GPIO descriptors whose values will be assigned 3542 - * @value_array: array of values to assign 3538 + * @value_bitmap: bitmap of values to assign 3543 3539 * 3544 3540 * Set the logical values of the GPIOs, i.e. taking their ACTIVE_LOW status 3545 3541 * into account. ··· 3548 3544 */ 3549 3545 void gpiod_set_array_value_cansleep(unsigned int array_size, 3550 3546 struct gpio_desc **desc_array, 3551 - int *value_array) 3547 + unsigned long *value_bitmap) 3552 3548 { 3553 3549 might_sleep_if(extra_checks); 3554 3550 if (!desc_array) 3555 3551 return; 3556 3552 gpiod_set_array_value_complex(false, true, array_size, desc_array, 3557 - value_array); 3553 + value_bitmap); 3558 3554 } 3559 3555 EXPORT_SYMBOL_GPL(gpiod_set_array_value_cansleep); 3560 3556
+2 -2
drivers/gpio/gpiolib.h
··· 187 187 int gpiod_get_array_value_complex(bool raw, bool can_sleep, 188 188 unsigned int array_size, 189 189 struct gpio_desc **desc_array, 190 - int *value_array); 190 + unsigned long *value_bitmap); 191 191 int gpiod_set_array_value_complex(bool raw, bool can_sleep, 192 192 unsigned int array_size, 193 193 struct gpio_desc **desc_array, 194 - int *value_array); 194 + unsigned long *value_bitmap); 195 195 196 196 /* This is just passed between gpiolib and devres */ 197 197 struct gpio_desc *gpiod_get_from_of_node(struct device_node *node,
+4 -9
drivers/i2c/muxes/i2c-mux-gpio.c
··· 22 22 struct i2c_mux_gpio_platform_data data; 23 23 unsigned gpio_base; 24 24 struct gpio_desc **gpios; 25 - int *values; 26 25 }; 27 26 28 27 static void i2c_mux_gpio_set(const struct gpiomux *mux, unsigned val) 29 28 { 30 - int i; 29 + DECLARE_BITMAP(values, BITS_PER_TYPE(val)); 31 30 32 - for (i = 0; i < mux->data.n_gpios; i++) 33 - mux->values[i] = (val >> i) & 1; 31 + values[0] = val; 34 32 35 - gpiod_set_array_value_cansleep(mux->data.n_gpios, 36 - mux->gpios, mux->values); 33 + gpiod_set_array_value_cansleep(mux->data.n_gpios, mux->gpios, values); 37 34 } 38 35 39 36 static int i2c_mux_gpio_select(struct i2c_mux_core *muxc, u32 chan) ··· 179 182 return -EPROBE_DEFER; 180 183 181 184 muxc = i2c_mux_alloc(parent, &pdev->dev, mux->data.n_values, 182 - mux->data.n_gpios * sizeof(*mux->gpios) + 183 - mux->data.n_gpios * sizeof(*mux->values), 0, 185 + mux->data.n_gpios * sizeof(*mux->gpios), 0, 184 186 i2c_mux_gpio_select, NULL); 185 187 if (!muxc) { 186 188 ret = -ENOMEM; 187 189 goto alloc_failed; 188 190 } 189 191 mux->gpios = muxc->priv; 190 - mux->values = (int *)(mux->gpios + mux->data.n_gpios); 191 192 muxc->priv = mux; 192 193 193 194 platform_set_drvdata(pdev, muxc);
+4 -9
drivers/mmc/core/pwrseq_simple.c
··· 40 40 struct gpio_descs *reset_gpios = pwrseq->reset_gpios; 41 41 42 42 if (!IS_ERR(reset_gpios)) { 43 - int i, *values; 43 + DECLARE_BITMAP(values, BITS_PER_TYPE(value)); 44 44 int nvalues = reset_gpios->ndescs; 45 45 46 - values = kmalloc_array(nvalues, sizeof(int), GFP_KERNEL); 47 - if (!values) 48 - return; 46 + values[0] = value; 49 47 50 - for (i = 0; i < nvalues; i++) 51 - values[i] = value; 52 - 53 - gpiod_set_array_value_cansleep(nvalues, reset_gpios->desc, values); 54 - kfree(values); 48 + gpiod_set_array_value_cansleep(nvalues, reset_gpios->desc, 49 + values); 55 50 } 56 51 } 57 52
+4 -9
drivers/mux/gpio.c
··· 17 17 18 18 struct mux_gpio { 19 19 struct gpio_descs *gpios; 20 - int *val; 21 20 }; 22 21 23 22 static int mux_gpio_set(struct mux_control *mux, int state) 24 23 { 25 24 struct mux_gpio *mux_gpio = mux_chip_priv(mux->chip); 26 - int i; 25 + DECLARE_BITMAP(values, BITS_PER_TYPE(state)); 27 26 28 - for (i = 0; i < mux_gpio->gpios->ndescs; i++) 29 - mux_gpio->val[i] = (state >> i) & 1; 27 + values[0] = state; 30 28 31 29 gpiod_set_array_value_cansleep(mux_gpio->gpios->ndescs, 32 - mux_gpio->gpios->desc, 33 - mux_gpio->val); 30 + mux_gpio->gpios->desc, values); 34 31 35 32 return 0; 36 33 } ··· 55 58 if (pins < 0) 56 59 return pins; 57 60 58 - mux_chip = devm_mux_chip_alloc(dev, 1, sizeof(*mux_gpio) + 59 - pins * sizeof(*mux_gpio->val)); 61 + mux_chip = devm_mux_chip_alloc(dev, 1, sizeof(*mux_gpio)); 60 62 if (IS_ERR(mux_chip)) 61 63 return PTR_ERR(mux_chip); 62 64 63 65 mux_gpio = mux_chip_priv(mux_chip); 64 - mux_gpio->val = (int *)(mux_gpio + 1); 65 66 mux_chip->ops = &mux_gpio_ops; 66 67 67 68 mux_gpio->gpios = devm_gpiod_get_array(dev, "mux", GPIOD_OUT_LOW);
+4 -7
drivers/net/phy/mdio-mux-gpio.c
··· 20 20 struct mdio_mux_gpio_state { 21 21 struct gpio_descs *gpios; 22 22 void *mux_handle; 23 - int values[]; 24 23 }; 25 24 26 25 static int mdio_mux_gpio_switch_fn(int current_child, int desired_child, 27 26 void *data) 28 27 { 29 28 struct mdio_mux_gpio_state *s = data; 30 - unsigned int n; 29 + DECLARE_BITMAP(values, BITS_PER_TYPE(desired_child)); 31 30 32 31 if (current_child == desired_child) 33 32 return 0; 34 33 35 - for (n = 0; n < s->gpios->ndescs; n++) 36 - s->values[n] = (desired_child >> n) & 1; 34 + values[0] = desired_child; 37 35 38 36 gpiod_set_array_value_cansleep(s->gpios->ndescs, s->gpios->desc, 39 - s->values); 37 + values); 40 38 41 39 return 0; 42 40 } ··· 49 51 if (IS_ERR(gpios)) 50 52 return PTR_ERR(gpios); 51 53 52 - s = devm_kzalloc(&pdev->dev, struct_size(s, values, gpios->ndescs), 53 - GFP_KERNEL); 54 + s = devm_kzalloc(&pdev->dev, sizeof(*s), GFP_KERNEL); 54 55 if (!s) { 55 56 gpiod_put_array(gpios); 56 57 return -ENOMEM;
+4 -3
drivers/pcmcia/soc_common.c
··· 351 351 352 352 if (ret == 0) { 353 353 struct gpio_desc *descs[2]; 354 - int values[2], n = 0; 354 + DECLARE_BITMAP(values, 2); 355 + int n = 0; 355 356 356 357 if (skt->gpio_reset) { 357 358 descs[n] = skt->gpio_reset; 358 - values[n++] = !!(state->flags & SS_RESET); 359 + __assign_bit(n++, values, state->flags & SS_RESET); 359 360 } 360 361 if (skt->gpio_bus_enable) { 361 362 descs[n] = skt->gpio_bus_enable; 362 - values[n++] = !!(state->flags & SS_OUTPUT_ENA); 363 + __assign_bit(n++, values, state->flags & SS_OUTPUT_ENA); 363 364 } 364 365 365 366 if (n)
+6 -9
drivers/phy/motorola/phy-mapphone-mdm6600.c
··· 157 157 */ 158 158 static void phy_mdm6600_cmd(struct phy_mdm6600 *ddata, int val) 159 159 { 160 - int values[PHY_MDM6600_NR_CMD_LINES]; 161 - int i; 160 + DECLARE_BITMAP(values, PHY_MDM6600_NR_CMD_LINES); 162 161 163 - val &= (1 << PHY_MDM6600_NR_CMD_LINES) - 1; 164 - for (i = 0; i < PHY_MDM6600_NR_CMD_LINES; i++) 165 - values[i] = (val & BIT(i)) >> i; 162 + values[0] = val; 166 163 167 164 gpiod_set_array_value_cansleep(PHY_MDM6600_NR_CMD_LINES, 168 165 ddata->cmd_gpios->desc, values); ··· 173 176 { 174 177 struct phy_mdm6600 *ddata; 175 178 struct device *dev; 176 - int values[PHY_MDM6600_NR_STATUS_LINES]; 179 + DECLARE_BITMAP(values, PHY_MDM6600_NR_STATUS_LINES); 177 180 int error, i, val = 0; 178 181 179 182 ddata = container_of(work, struct phy_mdm6600, status_work.work); ··· 186 189 return; 187 190 188 191 for (i = 0; i < PHY_MDM6600_NR_STATUS_LINES; i++) { 189 - val |= values[i] << i; 192 + val |= test_bit(i, values) << i; 190 193 dev_dbg(ddata->dev, "XXX %s: i: %i values[i]: %i val: %i\n", 191 - __func__, i, values[i], val); 194 + __func__, i, test_bit(i, values), val); 192 195 } 193 - ddata->status = val; 196 + ddata->status = values[0]; 194 197 195 198 dev_info(dev, "modem status: %i %s\n", 196 199 ddata->status,
+3 -6
drivers/staging/iio/adc/ad7606.c
··· 202 202 long mask) 203 203 { 204 204 struct ad7606_state *st = iio_priv(indio_dev); 205 - int values[3]; 205 + DECLARE_BITMAP(values, 3); 206 206 int ret, i; 207 207 208 208 switch (mask) { ··· 227 227 if (ret < 0) 228 228 return ret; 229 229 230 - values[0] = (ret >> 0) & 1; 231 - values[1] = (ret >> 1) & 1; 232 - values[2] = (ret >> 2) & 1; 230 + values[0] = ret; 233 231 234 232 mutex_lock(&st->lock); 235 - gpiod_set_array_value(ARRAY_SIZE(values), st->gpio_os->desc, 236 - values); 233 + gpiod_set_array_value(3, st->gpio_os->desc, values); 237 234 st->oversampling = val; 238 235 mutex_unlock(&st->lock); 239 236
+4 -3
drivers/tty/serial/serial_mctrl_gpio.c
··· 40 40 { 41 41 enum mctrl_gpio_idx i; 42 42 struct gpio_desc *desc_array[UART_GPIO_MAX]; 43 - int value_array[UART_GPIO_MAX]; 43 + DECLARE_BITMAP(values, UART_GPIO_MAX); 44 44 unsigned int count = 0; 45 45 46 46 if (gpios == NULL) ··· 49 49 for (i = 0; i < UART_GPIO_MAX; i++) 50 50 if (gpios->gpio[i] && mctrl_gpios_desc[i].dir_out) { 51 51 desc_array[count] = gpios->gpio[i]; 52 - value_array[count] = !!(mctrl & mctrl_gpios_desc[i].mctrl); 52 + __assign_bit(count, values, 53 + mctrl & mctrl_gpios_desc[i].mctrl); 53 54 count++; 54 55 } 55 - gpiod_set_array_value(count, desc_array, value_array); 56 + gpiod_set_array_value(count, desc_array, values); 56 57 } 57 58 EXPORT_SYMBOL_GPL(mctrl_gpio_set); 58 59
+18 -16
include/linux/gpio/consumer.h
··· 104 104 /* Value get/set from non-sleeping context */ 105 105 int gpiod_get_value(const struct gpio_desc *desc); 106 106 int gpiod_get_array_value(unsigned int array_size, 107 - struct gpio_desc **desc_array, int *value_array); 107 + struct gpio_desc **desc_array, 108 + unsigned long *value_bitmap); 108 109 void gpiod_set_value(struct gpio_desc *desc, int value); 109 110 void gpiod_set_array_value(unsigned int array_size, 110 - struct gpio_desc **desc_array, int *value_array); 111 + struct gpio_desc **desc_array, 112 + unsigned long *value_bitmap); 111 113 int gpiod_get_raw_value(const struct gpio_desc *desc); 112 114 int gpiod_get_raw_array_value(unsigned int array_size, 113 115 struct gpio_desc **desc_array, 114 - int *value_array); 116 + unsigned long *value_bitmap); 115 117 void gpiod_set_raw_value(struct gpio_desc *desc, int value); 116 118 int gpiod_set_raw_array_value(unsigned int array_size, 117 119 struct gpio_desc **desc_array, 118 - int *value_array); 120 + unsigned long *value_bitmap); 119 121 120 122 /* Value get/set from sleeping context */ 121 123 int gpiod_get_value_cansleep(const struct gpio_desc *desc); 122 124 int gpiod_get_array_value_cansleep(unsigned int array_size, 123 125 struct gpio_desc **desc_array, 124 - int *value_array); 126 + unsigned long *value_bitmap); 125 127 void gpiod_set_value_cansleep(struct gpio_desc *desc, int value); 126 128 void gpiod_set_array_value_cansleep(unsigned int array_size, 127 129 struct gpio_desc **desc_array, 128 - int *value_array); 130 + unsigned long *value_bitmap); 129 131 int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc); 130 132 int gpiod_get_raw_array_value_cansleep(unsigned int array_size, 131 133 struct gpio_desc **desc_array, 132 - int *value_array); 134 + unsigned long *value_bitmap); 133 135 void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value); 134 136 int gpiod_set_raw_array_value_cansleep(unsigned int array_size, 135 137 struct gpio_desc **desc_array, 136 - int *value_array); 138 + unsigned long *value_bitmap); 137 139 138 140 int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce); 139 141 int gpiod_set_transitory(struct gpio_desc *desc, bool transitory); ··· 332 330 } 333 331 static inline int gpiod_get_array_value(unsigned int array_size, 334 332 struct gpio_desc **desc_array, 335 - int *value_array) 333 + unsigned long *value_bitmap) 336 334 { 337 335 /* GPIO can never have been requested */ 338 336 WARN_ON(1); ··· 345 343 } 346 344 static inline void gpiod_set_array_value(unsigned int array_size, 347 345 struct gpio_desc **desc_array, 348 - int *value_array) 346 + unsigned long *value_bitmap) 349 347 { 350 348 /* GPIO can never have been requested */ 351 349 WARN_ON(1); ··· 358 356 } 359 357 static inline int gpiod_get_raw_array_value(unsigned int array_size, 360 358 struct gpio_desc **desc_array, 361 - int *value_array) 359 + unsigned long *value_bitmap) 362 360 { 363 361 /* GPIO can never have been requested */ 364 362 WARN_ON(1); ··· 371 369 } 372 370 static inline int gpiod_set_raw_array_value(unsigned int array_size, 373 371 struct gpio_desc **desc_array, 374 - int *value_array) 372 + unsigned long *value_bitmap) 375 373 { 376 374 /* GPIO can never have been requested */ 377 375 WARN_ON(1); ··· 386 384 } 387 385 static inline int gpiod_get_array_value_cansleep(unsigned int array_size, 388 386 struct gpio_desc **desc_array, 389 - int *value_array) 387 + unsigned long *value_bitmap) 390 388 { 391 389 /* GPIO can never have been requested */ 392 390 WARN_ON(1); ··· 399 397 } 400 398 static inline void gpiod_set_array_value_cansleep(unsigned int array_size, 401 399 struct gpio_desc **desc_array, 402 - int *value_array) 400 + unsigned long *value_bitmap) 403 401 { 404 402 /* GPIO can never have been requested */ 405 403 WARN_ON(1); ··· 412 410 } 413 411 static inline int gpiod_get_raw_array_value_cansleep(unsigned int array_size, 414 412 struct gpio_desc **desc_array, 415 - int *value_array) 413 + unsigned long *value_bitmap) 416 414 { 417 415 /* GPIO can never have been requested */ 418 416 WARN_ON(1); ··· 426 424 } 427 425 static inline int gpiod_set_raw_array_value_cansleep(unsigned int array_size, 428 426 struct gpio_desc **desc_array, 429 - int *value_array) 427 + unsigned long *value_bitmap) 430 428 { 431 429 /* GPIO can never have been requested */ 432 430 WARN_ON(1);