···193193194194The line will be hogged as soon as the gpiochip is created or - in case the195195chip was created earlier - when the hog table is registered.196196+197197+Arrays of pins198198+--------------199199+In addition to requesting pins belonging to a function one by one, a device may200200+also request an array of pins assigned to the function. The way those pins are201201+mapped to the device determines if the array qualifies for fast bitmap202202+processing. If yes, a bitmap is passed over get/set array functions directly203203+between a caller and a respective .get/set_multiple() callback of a GPIO chip.204204+205205+In order to qualify for fast bitmap processing, the pin mapping must meet the206206+following requirements:207207+- it must belong to the same chip as other 'fast' pins of the function,208208+- its index within the function must match its hardware number within the chip.209209+210210+Open drain and open source pins are excluded from fast bitmap output processing.
+33-13
Documentation/driver-api/gpio/consumer.rst
···109109 enum gpiod_flags flags)110110111111This function returns a struct gpio_descs which contains an array of112112-descriptors::112112+descriptors. It also contains a pointer to a gpiolib private structure which,113113+if passed back to get/set array functions, may speed up I/O proocessing::113114114115 struct gpio_descs {116116+ struct gpio_array *info;115117 unsigned int ndescs;116118 struct gpio_desc *desc[];117119 }···325323326324 int gpiod_get_array_value(unsigned int array_size,327325 struct gpio_desc **desc_array,328328- int *value_array);326326+ struct gpio_array *array_info,327327+ unsigned long *value_bitmap);329328 int gpiod_get_raw_array_value(unsigned int array_size,330329 struct gpio_desc **desc_array,331331- int *value_array);330330+ struct gpio_array *array_info,331331+ unsigned long *value_bitmap);332332 int gpiod_get_array_value_cansleep(unsigned int array_size,333333 struct gpio_desc **desc_array,334334- int *value_array);334334+ struct gpio_array *array_info,335335+ unsigned long *value_bitmap);335336 int gpiod_get_raw_array_value_cansleep(unsigned int array_size,336337 struct gpio_desc **desc_array,337337- int *value_array);338338+ struct gpio_array *array_info,339339+ unsigned long *value_bitmap);338340339341 void gpiod_set_array_value(unsigned int array_size,340342 struct gpio_desc **desc_array,341341- int *value_array)343343+ struct gpio_array *array_info,344344+ unsigned long *value_bitmap)342345 void gpiod_set_raw_array_value(unsigned int array_size,343346 struct gpio_desc **desc_array,344344- int *value_array)347347+ struct gpio_array *array_info,348348+ unsigned long *value_bitmap)345349 void gpiod_set_array_value_cansleep(unsigned int array_size,346350 struct gpio_desc **desc_array,347347- int *value_array)351351+ struct gpio_array *array_info,352352+ unsigned long *value_bitmap)348353 void gpiod_set_raw_array_value_cansleep(unsigned int array_size,349354 struct gpio_desc **desc_array,350350- int *value_array)355355+ struct gpio_array *array_info,356356+ unsigned long *value_bitmap)351357352358The array can be an arbitrary set of GPIOs. The functions will try to access353359GPIOs belonging to the same bank or chip simultaneously if supported by the···366356The functions take three arguments:367357 * array_size - the number of array elements368358 * desc_array - an array of GPIO descriptors369369- * value_array - an array to store the GPIOs' values (get) or370370- an array of values to assign to the GPIOs (set)359359+ * array_info - optional information obtained from gpiod_array_get()360360+ * value_bitmap - a bitmap to store the GPIOs' values (get) or361361+ a bitmap of values to assign to the GPIOs (set)371362372363The descriptor array can be obtained using the gpiod_get_array() function373364or one of its variants. If the group of descriptors returned by that function···377366378367 struct gpio_descs *my_gpio_descs = gpiod_get_array(...);379368 gpiod_set_array_value(my_gpio_descs->ndescs, my_gpio_descs->desc,380380- my_gpio_values);369369+ my_gpio_descs->info, my_gpio_value_bitmap);381370382371It is also possible to access a completely arbitrary array of descriptors. The383372descriptors may be obtained using any combination of gpiod_get() and384373gpiod_get_array(). Afterwards the array of descriptors has to be setup385385-manually before it can be passed to one of the above functions.374374+manually before it can be passed to one of the above functions. In that case,375375+array_info should be set to NULL.386376387377Note that for optimal performance GPIOs belonging to the same chip should be388378contiguous within the array of descriptors.379379+380380+Still better performance may be achieved if array indexes of the descriptors381381+match hardware pin numbers of a single chip. If an array passed to a get/set382382+array function matches the one obtained from gpiod_get_array() and array_info383383+associated with the array is also passed, the function may take a fast bitmap384384+processing path, passing the value_bitmap argument directly to the respective385385+.get/set_multiple() callback of the chip. That allows for utilization of GPIO386386+banks as data I/O ports without much loss of performance.389387390388The return value of gpiod_get_array_value() and its variants is 0 on success391389or negative on error. Note the difference to gpiod_get_value(), which returns
+20-39
drivers/auxdisplay/hd44780.c
···6262/* write to an LCD panel register in 8 bit GPIO mode */6363static void hd44780_write_gpio8(struct hd44780 *hd, u8 val, unsigned int rs)6464{6565- int values[10]; /* for DATA[0-7], RS, RW */6666- unsigned int i, n;6565+ DECLARE_BITMAP(values, 10); /* for DATA[0-7], RS, RW */6666+ unsigned int n;67676868- for (i = 0; i < 8; i++)6969- values[PIN_DATA0 + i] = !!(val & BIT(i));7070- values[PIN_CTRL_RS] = rs;7171- n = 9;7272- if (hd->pins[PIN_CTRL_RW]) {7373- values[PIN_CTRL_RW] = 0;7474- n++;7575- }6868+ values[0] = val;6969+ __assign_bit(8, values, rs);7070+ n = hd->pins[PIN_CTRL_RW] ? 10 : 9;76717772 /* Present the data to the port */7878- gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA0], values);7373+ gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA0], NULL, values);79748075 hd44780_strobe_gpio(hd);8176}···7883/* write to an LCD panel register in 4 bit GPIO mode */7984static void hd44780_write_gpio4(struct hd44780 *hd, u8 val, unsigned int rs)8085{8181- int values[10]; /* for DATA[0-7], RS, RW, but DATA[0-3] is unused */8282- unsigned int i, n;8686+ DECLARE_BITMAP(values, 6); /* for DATA[4-7], RS, RW */8787+ unsigned int n;83888489 /* High nibble + RS, RW */8585- for (i = 4; i < 8; i++)8686- values[PIN_DATA0 + i] = !!(val & BIT(i));8787- values[PIN_CTRL_RS] = rs;8888- n = 5;8989- if (hd->pins[PIN_CTRL_RW]) {9090- values[PIN_CTRL_RW] = 0;9191- n++;9292- }9090+ values[0] = val >> 4;9191+ __assign_bit(4, values, rs);9292+ n = hd->pins[PIN_CTRL_RW] ? 6 : 5;93939494 /* Present the data to the port */9595- gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4],9696- &values[PIN_DATA4]);9595+ gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4], NULL, values);97969897 hd44780_strobe_gpio(hd);999810099 /* Low nibble */101101- for (i = 0; i < 4; i++)102102- values[PIN_DATA4 + i] = !!(val & BIT(i));100100+ values[0] &= ~0x0fUL;101101+ values[0] |= val & 0x0f;103102104103 /* Present the data to the port */105105- gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4],106106- &values[PIN_DATA4]);104104+ gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4], NULL, values);107105108106 hd44780_strobe_gpio(hd);109107}···143155/* Send 4-bits of a command to the LCD panel in raw 4 bit GPIO mode */144156static void hd44780_write_cmd_raw_gpio4(struct charlcd *lcd, int cmd)145157{146146- int values[10]; /* for DATA[0-7], RS, RW, but DATA[0-3] is unused */158158+ DECLARE_BITMAP(values, 6); /* for DATA[4-7], RS, RW */147159 struct hd44780 *hd = lcd->drvdata;148148- unsigned int i, n;160160+ unsigned int n;149161150162 /* Command nibble + RS, RW */151151- for (i = 0; i < 4; i++)152152- values[PIN_DATA4 + i] = !!(cmd & BIT(i));153153- values[PIN_CTRL_RS] = 0;154154- n = 5;155155- if (hd->pins[PIN_CTRL_RW]) {156156- values[PIN_CTRL_RW] = 0;157157- n++;158158- }163163+ values[0] = cmd & 0x0f;164164+ n = hd->pins[PIN_CTRL_RW] ? 6 : 5;159165160166 /* Present the data to the port */161161- gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4],162162- &values[PIN_DATA4]);167167+ gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4], NULL, values);163168164169 hd44780_strobe_gpio(hd);165170}
+7-13
drivers/bus/ts-nbus.c
···110110 */111111static void ts_nbus_reset_bus(struct ts_nbus *ts_nbus)112112{113113- int i;114114- int values[8];113113+ DECLARE_BITMAP(values, 8);115114116116- for (i = 0; i < 8; i++)117117- values[i] = 0;115115+ values[0] = 0;118116119119- gpiod_set_array_value_cansleep(8, ts_nbus->data->desc, values);117117+ gpiod_set_array_value_cansleep(8, ts_nbus->data->desc,118118+ ts_nbus->data->info, values);120119 gpiod_set_value_cansleep(ts_nbus->csn, 0);121120 gpiod_set_value_cansleep(ts_nbus->strobe, 0);122121 gpiod_set_value_cansleep(ts_nbus->ale, 0);···156157static void ts_nbus_write_byte(struct ts_nbus *ts_nbus, u8 byte)157158{158159 struct gpio_descs *gpios = ts_nbus->data;159159- int i;160160- int values[8];160160+ DECLARE_BITMAP(values, 8);161161162162- for (i = 0; i < 8; i++)163163- if (byte & BIT(i))164164- values[i] = 1;165165- else166166- values[i] = 0;162162+ values[0] = byte;167163168168- gpiod_set_array_value_cansleep(8, gpios->desc, values);164164+ gpiod_set_array_value_cansleep(8, gpios->desc, gpios->info, values);169165}170166171167/*
+10-6
drivers/gpio/gpio-max3191x.c
···313313314314static void gpiod_set_array_single_value_cansleep(unsigned int ndescs,315315 struct gpio_desc **desc,316316+ struct gpio_array *info,316317 int value)317318{318318- int i, *values;319319+ unsigned long *values;319320320320- values = kmalloc_array(ndescs, sizeof(*values), GFP_KERNEL);321321+ values = bitmap_alloc(ndescs, GFP_KERNEL);321322 if (!values)322323 return;323324324324- for (i = 0; i < ndescs; i++)325325- values[i] = value;325325+ if (value)326326+ bitmap_fill(values, ndescs);327327+ else328328+ bitmap_zero(values, ndescs);326329327327- gpiod_set_array_value_cansleep(ndescs, desc, values);330330+ gpiod_set_array_value_cansleep(ndescs, desc, info, values);328331 kfree(values);329332}330333···400397 if (max3191x->modesel_pins)401398 gpiod_set_array_single_value_cansleep(402399 max3191x->modesel_pins->ndescs,403403- max3191x->modesel_pins->desc, max3191x->mode);400400+ max3191x->modesel_pins->desc,401401+ max3191x->modesel_pins->info, max3191x->mode);404402405403 max3191x->ignore_uv = device_property_read_bool(dev,406404 "maxim,ignore-undervoltage");
+220-45
drivers/gpio/gpiolib.c
···427427 struct linehandle_state *lh = filep->private_data;428428 void __user *ip = (void __user *)arg;429429 struct gpiohandle_data ghd;430430- int vals[GPIOHANDLES_MAX];430430+ DECLARE_BITMAP(vals, GPIOHANDLES_MAX);431431 int i;432432433433 if (cmd == GPIOHANDLE_GET_LINE_VALUES_IOCTL) {···436436 true,437437 lh->numdescs,438438 lh->descs,439439+ NULL,439440 vals);440441 if (ret)441442 return ret;442443443444 memset(&ghd, 0, sizeof(ghd));444445 for (i = 0; i < lh->numdescs; i++)445445- ghd.values[i] = vals[i];446446+ ghd.values[i] = test_bit(i, vals);446447447448 if (copy_to_user(ip, &ghd, sizeof(ghd)))448449 return -EFAULT;···462461463462 /* Clamp all values to [0,1] */464463 for (i = 0; i < lh->numdescs; i++)465465- vals[i] = !!ghd.values[i];464464+ __assign_bit(i, vals, ghd.values[i]);466465467466 /* Reuse the array setting function */468467 return gpiod_set_array_value_complex(false,469468 true,470469 lh->numdescs,471470 lh->descs,471471+ NULL,472472 vals);473473 }474474 return -EINVAL;···28152813int gpiod_get_array_value_complex(bool raw, bool can_sleep,28162814 unsigned int array_size,28172815 struct gpio_desc **desc_array,28182818- int *value_array)28162816+ struct gpio_array *array_info,28172817+ unsigned long *value_bitmap)28192818{28202820- int i = 0;28192819+ int err, i = 0;28202820+28212821+ /*28222822+ * Validate array_info against desc_array and its size.28232823+ * It should immediately follow desc_array if both28242824+ * have been obtained from the same gpiod_get_array() call.28252825+ */28262826+ if (array_info && array_info->desc == desc_array &&28272827+ array_size <= array_info->size &&28282828+ (void *)array_info == desc_array + array_info->size) {28292829+ if (!can_sleep)28302830+ WARN_ON(array_info->chip->can_sleep);28312831+28322832+ err = gpio_chip_get_multiple(array_info->chip,28332833+ array_info->get_mask,28342834+ value_bitmap);28352835+ if (err)28362836+ return err;28372837+28382838+ if (!raw && !bitmap_empty(array_info->invert_mask, array_size))28392839+ bitmap_xor(value_bitmap, value_bitmap,28402840+ array_info->invert_mask, array_size);28412841+28422842+ if (bitmap_full(array_info->get_mask, array_size))28432843+ return 0;28442844+28452845+ i = find_first_zero_bit(array_info->get_mask, array_size);28462846+ } else {28472847+ array_info = NULL;28482848+ }2821284928222850 while (i < array_size) {28232851 struct gpio_chip *chip = desc_array[i]->gdev->chip;···28782846 int hwgpio = gpio_chip_hwgpio(desc);2879284728802848 __set_bit(hwgpio, mask);28812881- i++;28492849+28502850+ if (array_info)28512851+ find_next_zero_bit(array_info->get_mask,28522852+ array_size, i);28532853+ else28542854+ i++;28822855 } while ((i < array_size) &&28832856 (desc_array[i]->gdev->chip == chip));28842857···28942857 return ret;28952858 }2896285928972897- for (j = first; j < i; j++) {28602860+ for (j = first; j < i; ) {28982861 const struct gpio_desc *desc = desc_array[j];28992862 int hwgpio = gpio_chip_hwgpio(desc);29002863 int value = test_bit(hwgpio, bits);2901286429022865 if (!raw && test_bit(FLAG_ACTIVE_LOW, &desc->flags))29032866 value = !value;29042904- value_array[j] = value;28672867+ __assign_bit(j, value_bitmap, value);29052868 trace_gpio_value(desc_to_gpio(desc), 1, value);28692869+28702870+ if (array_info)28712871+ find_next_zero_bit(array_info->get_mask, i, j);28722872+ else28732873+ j++;29062874 }2907287529082876 if (mask != fastpath)···2966292429672925/**29682926 * gpiod_get_raw_array_value() - read raw values from an array of GPIOs29692969- * @array_size: number of elements in the descriptor / value arrays29272927+ * @array_size: number of elements in the descriptor array / value bitmap29702928 * @desc_array: array of GPIO descriptors whose values will be read29712971- * @value_array: array to store the read values29292929+ * @array_info: information on applicability of fast bitmap processing path29302930+ * @value_bitmap: bitmap to store the read values29722931 *29732932 * Read the raw values of the GPIOs, i.e. the values of the physical lines29742933 * without regard for their ACTIVE_LOW status. Return 0 in case of success,···29792936 * and it will complain if the GPIO chip functions potentially sleep.29802937 */29812938int gpiod_get_raw_array_value(unsigned int array_size,29822982- struct gpio_desc **desc_array, int *value_array)29392939+ struct gpio_desc **desc_array,29402940+ struct gpio_array *array_info,29412941+ unsigned long *value_bitmap)29832942{29842943 if (!desc_array)29852944 return -EINVAL;29862945 return gpiod_get_array_value_complex(true, false, array_size,29872987- desc_array, value_array);29462946+ desc_array, array_info,29472947+ value_bitmap);29882948}29892949EXPORT_SYMBOL_GPL(gpiod_get_raw_array_value);2990295029912951/**29922952 * gpiod_get_array_value() - read values from an array of GPIOs29932993- * @array_size: number of elements in the descriptor / value arrays29532953+ * @array_size: number of elements in the descriptor array / value bitmap29942954 * @desc_array: array of GPIO descriptors whose values will be read29952995- * @value_array: array to store the read values29552955+ * @array_info: information on applicability of fast bitmap processing path29562956+ * @value_bitmap: bitmap to store the read values29962957 *29972958 * Read the logical values of the GPIOs, i.e. taking their ACTIVE_LOW status29982959 * into account. Return 0 in case of success, else an error code.···30052958 * and it will complain if the GPIO chip functions potentially sleep.30062959 */30072960int gpiod_get_array_value(unsigned int array_size,30083008- struct gpio_desc **desc_array, int *value_array)29612961+ struct gpio_desc **desc_array,29622962+ struct gpio_array *array_info,29632963+ unsigned long *value_bitmap)30092964{30102965 if (!desc_array)30112966 return -EINVAL;30122967 return gpiod_get_array_value_complex(false, false, array_size,30133013- desc_array, value_array);29682968+ desc_array, array_info,29692969+ value_bitmap);30142970}30152971EXPORT_SYMBOL_GPL(gpiod_get_array_value);30162972···31063056int gpiod_set_array_value_complex(bool raw, bool can_sleep,31073057 unsigned int array_size,31083058 struct gpio_desc **desc_array,31093109- int *value_array)30593059+ struct gpio_array *array_info,30603060+ unsigned long *value_bitmap)31103061{31113062 int i = 0;30633063+30643064+ /*30653065+ * Validate array_info against desc_array and its size.30663066+ * It should immediately follow desc_array if both30673067+ * have been obtained from the same gpiod_get_array() call.30683068+ */30693069+ if (array_info && array_info->desc == desc_array &&30703070+ array_size <= array_info->size &&30713071+ (void *)array_info == desc_array + array_info->size) {30723072+ if (!can_sleep)30733073+ WARN_ON(array_info->chip->can_sleep);30743074+30753075+ if (!raw && !bitmap_empty(array_info->invert_mask, array_size))30763076+ bitmap_xor(value_bitmap, value_bitmap,30773077+ array_info->invert_mask, array_size);30783078+30793079+ gpio_chip_set_multiple(array_info->chip, array_info->set_mask,30803080+ value_bitmap);30813081+30823082+ if (bitmap_full(array_info->set_mask, array_size))30833083+ return 0;30843084+30853085+ i = find_first_zero_bit(array_info->set_mask, array_size);30863086+ } else {30873087+ array_info = NULL;30883088+ }3112308931133090 while (i < array_size) {31143091 struct gpio_chip *chip = desc_array[i]->gdev->chip;···31623085 do {31633086 struct gpio_desc *desc = desc_array[i];31643087 int hwgpio = gpio_chip_hwgpio(desc);31653165- int value = value_array[i];30883088+ int value = test_bit(i, value_bitmap);3166308931673167- if (!raw && test_bit(FLAG_ACTIVE_LOW, &desc->flags))30903090+ /*30913091+ * Pins applicable for fast input but not for30923092+ * fast output processing may have been already30933093+ * inverted inside the fast path, skip them.30943094+ */30953095+ if (!raw && !(array_info &&30963096+ test_bit(i, array_info->invert_mask)) &&30973097+ test_bit(FLAG_ACTIVE_LOW, &desc->flags))31683098 value = !value;31693099 trace_gpio_value(desc_to_gpio(desc), 0, value);31703100 /*···31903106 __clear_bit(hwgpio, bits);31913107 count++;31923108 }31933193- i++;31093109+31103110+ if (array_info)31113111+ find_next_zero_bit(array_info->set_mask,31123112+ array_size, i);31133113+ else31143114+ i++;31943115 } while ((i < array_size) &&31953116 (desc_array[i]->gdev->chip == chip));31963117 /* push collected bits to outputs */···3270318132713182/**32723183 * gpiod_set_raw_array_value() - assign values to an array of GPIOs32733273- * @array_size: number of elements in the descriptor / value arrays31843184+ * @array_size: number of elements in the descriptor array / value bitmap32743185 * @desc_array: array of GPIO descriptors whose values will be assigned32753275- * @value_array: array of values to assign31863186+ * @array_info: information on applicability of fast bitmap processing path31873187+ * @value_bitmap: bitmap of values to assign32763188 *32773189 * Set the raw values of the GPIOs, i.e. the values of the physical lines32783190 * without regard for their ACTIVE_LOW status.···32823192 * complain if the GPIO chip functions potentially sleep.32833193 */32843194int gpiod_set_raw_array_value(unsigned int array_size,32853285- struct gpio_desc **desc_array, int *value_array)31953195+ struct gpio_desc **desc_array,31963196+ struct gpio_array *array_info,31973197+ unsigned long *value_bitmap)32863198{32873199 if (!desc_array)32883200 return -EINVAL;32893201 return gpiod_set_array_value_complex(true, false, array_size,32903290- desc_array, value_array);32023202+ desc_array, array_info, value_bitmap);32913203}32923204EXPORT_SYMBOL_GPL(gpiod_set_raw_array_value);3293320532943206/**32953207 * gpiod_set_array_value() - assign values to an array of GPIOs32963296- * @array_size: number of elements in the descriptor / value arrays32083208+ * @array_size: number of elements in the descriptor array / value bitmap32973209 * @desc_array: array of GPIO descriptors whose values will be assigned32983298- * @value_array: array of values to assign32103210+ * @array_info: information on applicability of fast bitmap processing path32113211+ * @value_bitmap: bitmap of values to assign32993212 *33003213 * Set the logical values of the GPIOs, i.e. taking their ACTIVE_LOW status33013214 * into account.···33073214 * complain if the GPIO chip functions potentially sleep.33083215 */33093216void gpiod_set_array_value(unsigned int array_size,33103310- struct gpio_desc **desc_array, int *value_array)32173217+ struct gpio_desc **desc_array,32183218+ struct gpio_array *array_info,32193219+ unsigned long *value_bitmap)33113220{33123221 if (!desc_array)33133222 return;33143223 gpiod_set_array_value_complex(false, false, array_size, desc_array,33153315- value_array);32243224+ array_info, value_bitmap);33163225}33173226EXPORT_SYMBOL_GPL(gpiod_set_array_value);33183227···3582348735833488/**35843489 * gpiod_get_raw_array_value_cansleep() - read raw values from an array of GPIOs35853585- * @array_size: number of elements in the descriptor / value arrays34903490+ * @array_size: number of elements in the descriptor array / value bitmap35863491 * @desc_array: array of GPIO descriptors whose values will be read35873587- * @value_array: array to store the read values34923492+ * @array_info: information on applicability of fast bitmap processing path34933493+ * @value_bitmap: bitmap to store the read values35883494 *35893495 * Read the raw values of the GPIOs, i.e. the values of the physical lines35903496 * without regard for their ACTIVE_LOW status. Return 0 in case of success,···35953499 */35963500int gpiod_get_raw_array_value_cansleep(unsigned int array_size,35973501 struct gpio_desc **desc_array,35983598- int *value_array)35023502+ struct gpio_array *array_info,35033503+ unsigned long *value_bitmap)35993504{36003505 might_sleep_if(extra_checks);36013506 if (!desc_array)36023507 return -EINVAL;36033508 return gpiod_get_array_value_complex(true, true, array_size,36043604- desc_array, value_array);35093509+ desc_array, array_info,35103510+ value_bitmap);36053511}36063512EXPORT_SYMBOL_GPL(gpiod_get_raw_array_value_cansleep);3607351336083514/**36093515 * gpiod_get_array_value_cansleep() - read values from an array of GPIOs36103610- * @array_size: number of elements in the descriptor / value arrays35163516+ * @array_size: number of elements in the descriptor array / value bitmap36113517 * @desc_array: array of GPIO descriptors whose values will be read36123612- * @value_array: array to store the read values35183518+ * @array_info: information on applicability of fast bitmap processing path35193519+ * @value_bitmap: bitmap to store the read values36133520 *36143521 * Read the logical values of the GPIOs, i.e. taking their ACTIVE_LOW status36153522 * into account. Return 0 in case of success, else an error code.···36213522 */36223523int gpiod_get_array_value_cansleep(unsigned int array_size,36233524 struct gpio_desc **desc_array,36243624- int *value_array)35253525+ struct gpio_array *array_info,35263526+ unsigned long *value_bitmap)36253527{36263528 might_sleep_if(extra_checks);36273529 if (!desc_array)36283530 return -EINVAL;36293531 return gpiod_get_array_value_complex(false, true, array_size,36303630- desc_array, value_array);35323532+ desc_array, array_info,35333533+ value_bitmap);36313534}36323535EXPORT_SYMBOL_GPL(gpiod_get_array_value_cansleep);36333536···3671357036723571/**36733572 * gpiod_set_raw_array_value_cansleep() - assign values to an array of GPIOs36743674- * @array_size: number of elements in the descriptor / value arrays35733573+ * @array_size: number of elements in the descriptor array / value bitmap36753574 * @desc_array: array of GPIO descriptors whose values will be assigned36763676- * @value_array: array of values to assign35753575+ * @array_info: information on applicability of fast bitmap processing path35763576+ * @value_bitmap: bitmap of values to assign36773577 *36783578 * Set the raw values of the GPIOs, i.e. the values of the physical lines36793579 * without regard for their ACTIVE_LOW status.···36833581 */36843582int gpiod_set_raw_array_value_cansleep(unsigned int array_size,36853583 struct gpio_desc **desc_array,36863686- int *value_array)35843584+ struct gpio_array *array_info,35853585+ unsigned long *value_bitmap)36873586{36883587 might_sleep_if(extra_checks);36893588 if (!desc_array)36903589 return -EINVAL;36913590 return gpiod_set_array_value_complex(true, true, array_size, desc_array,36923692- value_array);35913591+ array_info, value_bitmap);36933592}36943593EXPORT_SYMBOL_GPL(gpiod_set_raw_array_value_cansleep);36953594···3713361037143611/**37153612 * gpiod_set_array_value_cansleep() - assign values to an array of GPIOs37163716- * @array_size: number of elements in the descriptor / value arrays36133613+ * @array_size: number of elements in the descriptor array / value bitmap37173614 * @desc_array: array of GPIO descriptors whose values will be assigned37183718- * @value_array: array of values to assign36153615+ * @array_info: information on applicability of fast bitmap processing path36163616+ * @value_bitmap: bitmap of values to assign37193617 *37203618 * Set the logical values of the GPIOs, i.e. taking their ACTIVE_LOW status37213619 * into account.···37253621 */37263622void gpiod_set_array_value_cansleep(unsigned int array_size,37273623 struct gpio_desc **desc_array,37283728- int *value_array)36243624+ struct gpio_array *array_info,36253625+ unsigned long *value_bitmap)37293626{37303627 might_sleep_if(extra_checks);37313628 if (!desc_array)37323629 return;37333630 gpiod_set_array_value_complex(false, true, array_size, desc_array,37343734- value_array);36313631+ array_info, value_bitmap);37353632}37363633EXPORT_SYMBOL_GPL(gpiod_set_array_value_cansleep);37373634···43524247{43534248 struct gpio_desc *desc;43544249 struct gpio_descs *descs;43554355- int count;42504250+ struct gpio_array *array_info = NULL;42514251+ struct gpio_chip *chip;42524252+ int count, bitmap_size;4356425343574254 count = gpiod_count(dev, con_id);43584255 if (count < 0)···43704263 gpiod_put_array(descs);43714264 return ERR_CAST(desc);43724265 }42664266+43734267 descs->desc[descs->ndescs] = desc;42684268+42694269+ chip = gpiod_to_chip(desc);42704270+ /*42714271+ * Select a chip of first array member42724272+ * whose index matches its pin hardware number42734273+ * as a candidate for fast bitmap processing.42744274+ */42754275+ if (!array_info && gpio_chip_hwgpio(desc) == descs->ndescs) {42764276+ struct gpio_descs *array;42774277+42784278+ bitmap_size = BITS_TO_LONGS(chip->ngpio > count ?42794279+ chip->ngpio : count);42804280+42814281+ array = kzalloc(struct_size(descs, desc, count) +42824282+ struct_size(array_info, invert_mask,42834283+ 3 * bitmap_size), GFP_KERNEL);42844284+ if (!array) {42854285+ gpiod_put_array(descs);42864286+ return ERR_PTR(-ENOMEM);42874287+ }42884288+42894289+ memcpy(array, descs,42904290+ struct_size(descs, desc, descs->ndescs + 1));42914291+ kfree(descs);42924292+42934293+ descs = array;42944294+ array_info = (void *)(descs->desc + count);42954295+ array_info->get_mask = array_info->invert_mask +42964296+ bitmap_size;42974297+ array_info->set_mask = array_info->get_mask +42984298+ bitmap_size;42994299+43004300+ array_info->desc = descs->desc;43014301+ array_info->size = count;43024302+ array_info->chip = chip;43034303+ bitmap_set(array_info->get_mask, descs->ndescs,43044304+ count - descs->ndescs);43054305+ bitmap_set(array_info->set_mask, descs->ndescs,43064306+ count - descs->ndescs);43074307+ descs->info = array_info;43084308+ }43094309+ /*43104310+ * Unmark members which don't qualify for fast bitmap43114311+ * processing (different chip, not in hardware order)43124312+ */43134313+ if (array_info && (chip != array_info->chip ||43144314+ gpio_chip_hwgpio(desc) != descs->ndescs)) {43154315+ __clear_bit(descs->ndescs, array_info->get_mask);43164316+ __clear_bit(descs->ndescs, array_info->set_mask);43174317+ } else if (array_info) {43184318+ /* Exclude open drain or open source from fast output */43194319+ if (gpiochip_line_is_open_drain(chip, descs->ndescs) ||43204320+ gpiochip_line_is_open_source(chip, descs->ndescs))43214321+ __clear_bit(descs->ndescs,43224322+ array_info->set_mask);43234323+ /* Identify 'fast' pins which require invertion */43244324+ if (gpiod_is_active_low(desc))43254325+ __set_bit(descs->ndescs,43264326+ array_info->invert_mask);43274327+ }43284328+43744329 descs->ndescs++;43754330 }43314331+ if (array_info)43324332+ dev_dbg(dev,43334333+ "GPIO array info: chip=%s, size=%d, get_mask=%lx, set_mask=%lx, invert_mask=%lx\n",43344334+ array_info->chip->label, array_info->size,43354335+ *array_info->get_mask, *array_info->set_mask,43364336+ *array_info->invert_mask);43764337 return descs;43774338}43784339EXPORT_SYMBOL_GPL(gpiod_get_array);
+13-2
drivers/gpio/gpiolib.h
···183183}184184#endif185185186186+struct gpio_array {187187+ struct gpio_desc **desc;188188+ unsigned int size;189189+ struct gpio_chip *chip;190190+ unsigned long *get_mask;191191+ unsigned long *set_mask;192192+ unsigned long invert_mask[];193193+};194194+186195struct gpio_desc *gpiochip_get_desc(struct gpio_chip *chip, u16 hwnum);187196int gpiod_get_array_value_complex(bool raw, bool can_sleep,188197 unsigned int array_size,189198 struct gpio_desc **desc_array,190190- int *value_array);199199+ struct gpio_array *array_info,200200+ unsigned long *value_bitmap);191201int gpiod_set_array_value_complex(bool raw, bool can_sleep,192202 unsigned int array_size,193203 struct gpio_desc **desc_array,194194- int *value_array);204204+ struct gpio_array *array_info,205205+ unsigned long *value_bitmap);195206196207/* This is just passed between gpiolib and devres */197208struct gpio_desc *gpiod_get_from_of_node(struct device_node *node,
···4040{4141 enum mctrl_gpio_idx i;4242 struct gpio_desc *desc_array[UART_GPIO_MAX];4343- int value_array[UART_GPIO_MAX];4343+ DECLARE_BITMAP(values, UART_GPIO_MAX);4444 unsigned int count = 0;45454646 if (gpios == NULL)···4949 for (i = 0; i < UART_GPIO_MAX; i++)5050 if (gpios->gpio[i] && mctrl_gpios_desc[i].dir_out) {5151 desc_array[count] = gpios->gpio[i];5252- value_array[count] = !!(mctrl & mctrl_gpios_desc[i].mctrl);5252+ __assign_bit(count, values,5353+ mctrl & mctrl_gpios_desc[i].mctrl);5354 count++;5455 }5555- gpiod_set_array_value(count, desc_array, value_array);5656+ gpiod_set_array_value(count, desc_array, NULL, values);5657}5758EXPORT_SYMBOL_GPL(mctrl_gpio_set);5859
+43-16
include/linux/gpio/consumer.h
···1818struct gpio_desc;19192020/**2121+ * Opaque descriptor for a structure of GPIO array attributes. This structure2222+ * is attached to struct gpiod_descs obtained from gpiod_get_array() and can be2323+ * passed back to get/set array functions in order to activate fast processing2424+ * path if applicable.2525+ */2626+struct gpio_array;2727+2828+/**2129 * Struct containing an array of descriptors that can be obtained using2230 * gpiod_get_array().2331 */2432struct gpio_descs {3333+ struct gpio_array *info;2534 unsigned int ndescs;2635 struct gpio_desc *desc[];2736};···113104/* Value get/set from non-sleeping context */114105int gpiod_get_value(const struct gpio_desc *desc);115106int gpiod_get_array_value(unsigned int array_size,116116- struct gpio_desc **desc_array, int *value_array);107107+ struct gpio_desc **desc_array,108108+ struct gpio_array *array_info,109109+ unsigned long *value_bitmap);117110void gpiod_set_value(struct gpio_desc *desc, int value);118111void gpiod_set_array_value(unsigned int array_size,119119- struct gpio_desc **desc_array, int *value_array);112112+ struct gpio_desc **desc_array,113113+ struct gpio_array *array_info,114114+ unsigned long *value_bitmap);120115int gpiod_get_raw_value(const struct gpio_desc *desc);121116int gpiod_get_raw_array_value(unsigned int array_size,122117 struct gpio_desc **desc_array,123123- int *value_array);118118+ struct gpio_array *array_info,119119+ unsigned long *value_bitmap);124120void gpiod_set_raw_value(struct gpio_desc *desc, int value);125121int gpiod_set_raw_array_value(unsigned int array_size,126122 struct gpio_desc **desc_array,127127- int *value_array);123123+ struct gpio_array *array_info,124124+ unsigned long *value_bitmap);128125129126/* Value get/set from sleeping context */130127int gpiod_get_value_cansleep(const struct gpio_desc *desc);131128int gpiod_get_array_value_cansleep(unsigned int array_size,132129 struct gpio_desc **desc_array,133133- int *value_array);130130+ struct gpio_array *array_info,131131+ unsigned long *value_bitmap);134132void gpiod_set_value_cansleep(struct gpio_desc *desc, int value);135133void gpiod_set_array_value_cansleep(unsigned int array_size,136134 struct gpio_desc **desc_array,137137- int *value_array);135135+ struct gpio_array *array_info,136136+ unsigned long *value_bitmap);138137int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc);139138int gpiod_get_raw_array_value_cansleep(unsigned int array_size,140139 struct gpio_desc **desc_array,141141- int *value_array);140140+ struct gpio_array *array_info,141141+ unsigned long *value_bitmap);142142void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value);143143int gpiod_set_raw_array_value_cansleep(unsigned int array_size,144144 struct gpio_desc **desc_array,145145- int *value_array);145145+ struct gpio_array *array_info,146146+ unsigned long *value_bitmap);146147147148int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce);148149int gpiod_set_transitory(struct gpio_desc *desc, bool transitory);···349330}350331static inline int gpiod_get_array_value(unsigned int array_size,351332 struct gpio_desc **desc_array,352352- int *value_array)333333+ struct gpio_array *array_info,334334+ unsigned long *value_bitmap)353335{354336 /* GPIO can never have been requested */355337 WARN_ON(1);···363343}364344static inline void gpiod_set_array_value(unsigned int array_size,365345 struct gpio_desc **desc_array,366366- int *value_array)346346+ struct gpio_array *array_info,347347+ unsigned long *value_bitmap)367348{368349 /* GPIO can never have been requested */369350 WARN_ON(1);···377356}378357static inline int gpiod_get_raw_array_value(unsigned int array_size,379358 struct gpio_desc **desc_array,380380- int *value_array)359359+ struct gpio_array *array_info,360360+ unsigned long *value_bitmap)381361{382362 /* GPIO can never have been requested */383363 WARN_ON(1);···391369}392370static inline int gpiod_set_raw_array_value(unsigned int array_size,393371 struct gpio_desc **desc_array,394394- int *value_array)372372+ struct gpio_array *array_info,373373+ unsigned long *value_bitmap)395374{396375 /* GPIO can never have been requested */397376 WARN_ON(1);···407384}408385static inline int gpiod_get_array_value_cansleep(unsigned int array_size,409386 struct gpio_desc **desc_array,410410- int *value_array)387387+ struct gpio_array *array_info,388388+ unsigned long *value_bitmap)411389{412390 /* GPIO can never have been requested */413391 WARN_ON(1);···421397}422398static inline void gpiod_set_array_value_cansleep(unsigned int array_size,423399 struct gpio_desc **desc_array,424424- int *value_array)400400+ struct gpio_array *array_info,401401+ unsigned long *value_bitmap)425402{426403 /* GPIO can never have been requested */427404 WARN_ON(1);···435410}436411static inline int gpiod_get_raw_array_value_cansleep(unsigned int array_size,437412 struct gpio_desc **desc_array,438438- int *value_array)413413+ struct gpio_array *array_info,414414+ unsigned long *value_bitmap)439415{440416 /* GPIO can never have been requested */441417 WARN_ON(1);···450424}451425static inline int gpiod_set_raw_array_value_cansleep(unsigned int array_size,452426 struct gpio_desc **desc_array,453453- int *value_array)427427+ struct gpio_array *array_info,428428+ unsigned long *value_bitmap)454429{455430 /* GPIO can never have been requested */456431 WARN_ON(1);