mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-22 14:41:27 +00:00
gpio: Introduce ->get_multiple callback
SPI-attached GPIO controllers typically read out all inputs in one go. If callers desire the values of multipe inputs, ideally a single readout should take place to return the desired values. However the current driver API only offers a ->get callback but no ->get_multiple (unlike ->set_multiple, which is present). Thus, to read multiple inputs, a full readout needs to be performed for every single value (barring driver-internal caching), which is inefficient. In fact, the lack of a ->get_multiple callback has been bemoaned repeatedly by the gpio subsystem maintainer: http://www.spinics.net/lists/linux-gpio/msg10571.html http://www.spinics.net/lists/devicetree/msg121734.html Introduce the missing callback. Add corresponding consumer functions such as gpiod_get_array_value(). Amend linehandle_ioctl() to take advantage of the newly added infrastructure. Update the documentation. Cc: Rojhalat Ibrahim <imr@rtschenk.de> Signed-off-by: Lukas Wunner <lukas@wunner.de> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
This commit is contained in:
parent
5307e2ad69
commit
eec1d566cd
5 changed files with 250 additions and 22 deletions
|
@ -295,9 +295,22 @@ as possible, especially by drivers which should not care about the actual
|
|||
physical line level and worry about the logical value instead.
|
||||
|
||||
|
||||
Set multiple GPIO outputs with a single function call
|
||||
-----------------------------------------------------
|
||||
The following functions set the output values of an array of GPIOs:
|
||||
Access multiple GPIOs with a single function call
|
||||
-------------------------------------------------
|
||||
The following functions get or set the values of an array of GPIOs:
|
||||
|
||||
int gpiod_get_array_value(unsigned int array_size,
|
||||
struct gpio_desc **desc_array,
|
||||
int *value_array);
|
||||
int gpiod_get_raw_array_value(unsigned int array_size,
|
||||
struct gpio_desc **desc_array,
|
||||
int *value_array);
|
||||
int gpiod_get_array_value_cansleep(unsigned int array_size,
|
||||
struct gpio_desc **desc_array,
|
||||
int *value_array);
|
||||
int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
|
||||
struct gpio_desc **desc_array,
|
||||
int *value_array);
|
||||
|
||||
void gpiod_set_array_value(unsigned int array_size,
|
||||
struct gpio_desc **desc_array,
|
||||
|
@ -312,34 +325,40 @@ The following functions set the output values of an array of GPIOs:
|
|||
struct gpio_desc **desc_array,
|
||||
int *value_array)
|
||||
|
||||
The array can be an arbitrary set of GPIOs. The functions will try to set
|
||||
The array can be an arbitrary set of GPIOs. The functions will try to access
|
||||
GPIOs belonging to the same bank or chip simultaneously if supported by the
|
||||
corresponding chip driver. In that case a significantly improved performance
|
||||
can be expected. If simultaneous setting is not possible the GPIOs will be set
|
||||
sequentially.
|
||||
can be expected. If simultaneous access is not possible the GPIOs will be
|
||||
accessed sequentially.
|
||||
|
||||
The gpiod_set_array() functions take three arguments:
|
||||
The functions take three arguments:
|
||||
* array_size - the number of array elements
|
||||
* desc_array - an array of GPIO descriptors
|
||||
* value_array - an array of values to assign to the GPIOs
|
||||
* value_array - an array to store the GPIOs' values (get) or
|
||||
an array of values to assign to the GPIOs (set)
|
||||
|
||||
The descriptor array can be obtained using the gpiod_get_array() function
|
||||
or one of its variants. If the group of descriptors returned by that function
|
||||
matches the desired group of GPIOs, those GPIOs can be set by simply using
|
||||
matches the desired group of GPIOs, those GPIOs can be accessed by simply using
|
||||
the struct gpio_descs returned by gpiod_get_array():
|
||||
|
||||
struct gpio_descs *my_gpio_descs = gpiod_get_array(...);
|
||||
gpiod_set_array_value(my_gpio_descs->ndescs, my_gpio_descs->desc,
|
||||
my_gpio_values);
|
||||
|
||||
It is also possible to set a completely arbitrary array of descriptors. The
|
||||
It is also possible to access a completely arbitrary array of descriptors. The
|
||||
descriptors may be obtained using any combination of gpiod_get() and
|
||||
gpiod_get_array(). Afterwards the array of descriptors has to be setup
|
||||
manually before it can be used with gpiod_set_array().
|
||||
manually before it can be passed to one of the above functions.
|
||||
|
||||
Note that for optimal performance GPIOs belonging to the same chip should be
|
||||
contiguous within the array of descriptors.
|
||||
|
||||
The return value of gpiod_get_array_value() and its variants is 0 on success
|
||||
or negative on error. Note the difference to gpiod_get_value(), which returns
|
||||
0 or 1 on success to convey the GPIO value. With the array functions, the GPIO
|
||||
values are stored in value_array rather than passed back as return value.
|
||||
|
||||
|
||||
GPIOs mapped to IRQs
|
||||
--------------------
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue