diff options
author | Alexandre Courbot <acourbot@nvidia.com> | 2013-12-02 22:20:11 -0500 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2013-12-09 08:05:51 -0500 |
commit | ad824783fb23bbc8295cffb6214b3b82d25f7d4a (patch) | |
tree | 745d128c1d04dca7a6c7b10dd737f116f13ddcb1 /Documentation | |
parent | bdc54ef45d7670aeb52ce73f8b7ad5f3e5563661 (diff) |
gpio: better lookup method for platform GPIOs
Change the format of the platform GPIO lookup tables to make them less
confusing and improve lookup efficiency.
The previous format was a single linked-list that required to compare
the device name and function ID of every single GPIO defined for each
lookup. Switch that to a list of per-device tables, so that the lookup
can be done in two steps, omitting the GPIOs that are not relevant for a
particular device.
The matching rules are now defined as follows:
- The device name must match *exactly*, and can be NULL for GPIOs not
assigned to a particular device,
- If the function ID in the lookup table is NULL, the con_id argument of
gpiod_get() will not be used for lookup. However, if it is defined, it
must match exactly.
- The index must always match.
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'Documentation')
-rw-r--r-- | Documentation/gpio/board.txt | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/Documentation/gpio/board.txt b/Documentation/gpio/board.txt index 0d03506f2cc5..ba169faad5c6 100644 --- a/Documentation/gpio/board.txt +++ b/Documentation/gpio/board.txt | |||
@@ -72,10 +72,11 @@ where | |||
72 | 72 | ||
73 | - chip_label is the label of the gpiod_chip instance providing the GPIO | 73 | - chip_label is the label of the gpiod_chip instance providing the GPIO |
74 | - chip_hwnum is the hardware number of the GPIO within the chip | 74 | - chip_hwnum is the hardware number of the GPIO within the chip |
75 | - dev_id is the identifier of the device that will make use of this GPIO. If | 75 | - dev_id is the identifier of the device that will make use of this GPIO. It |
76 | NULL, the GPIO will be available to all devices. | 76 | can be NULL, in which case it will be matched for calls to gpiod_get() |
77 | with a NULL device. | ||
77 | - con_id is the name of the GPIO function from the device point of view. It | 78 | - con_id is the name of the GPIO function from the device point of view. It |
78 | can be NULL. | 79 | can be NULL, in which case it will match any function. |
79 | - idx is the index of the GPIO within the function. | 80 | - idx is the index of the GPIO within the function. |
80 | - flags is defined to specify the following properties: | 81 | - flags is defined to specify the following properties: |
81 | * GPIOF_ACTIVE_LOW - to configure the GPIO as active-low | 82 | * GPIOF_ACTIVE_LOW - to configure the GPIO as active-low |
@@ -86,18 +87,23 @@ In the future, these flags might be extended to support more properties. | |||
86 | 87 | ||
87 | Note that GPIO_LOOKUP() is just a shortcut to GPIO_LOOKUP_IDX() where idx = 0. | 88 | Note that GPIO_LOOKUP() is just a shortcut to GPIO_LOOKUP_IDX() where idx = 0. |
88 | 89 | ||
89 | A lookup table can then be defined as follows: | 90 | A lookup table can then be defined as follows, with an empty entry defining its |
91 | end: | ||
90 | 92 | ||
91 | struct gpiod_lookup gpios_table[] = { | 93 | struct gpiod_lookup_table gpios_table = { |
92 | GPIO_LOOKUP_IDX("gpio.0", 15, "foo.0", "led", 0, GPIO_ACTIVE_HIGH), | 94 | .dev_id = "foo.0", |
93 | GPIO_LOOKUP_IDX("gpio.0", 16, "foo.0", "led", 1, GPIO_ACTIVE_HIGH), | 95 | .table = { |
94 | GPIO_LOOKUP_IDX("gpio.0", 17, "foo.0", "led", 2, GPIO_ACTIVE_HIGH), | 96 | GPIO_LOOKUP_IDX("gpio.0", 15, "led", 0, GPIO_ACTIVE_HIGH), |
95 | GPIO_LOOKUP("gpio.0", 1, "foo.0", "power", GPIO_ACTIVE_LOW), | 97 | GPIO_LOOKUP_IDX("gpio.0", 16, "led", 1, GPIO_ACTIVE_HIGH), |
96 | }; | 98 | GPIO_LOOKUP_IDX("gpio.0", 17, "led", 2, GPIO_ACTIVE_HIGH), |
99 | GPIO_LOOKUP("gpio.0", 1, "power", GPIO_ACTIVE_LOW), | ||
100 | { }, | ||
101 | }, | ||
102 | }; | ||
97 | 103 | ||
98 | And the table can be added by the board code as follows: | 104 | And the table can be added by the board code as follows: |
99 | 105 | ||
100 | gpiod_add_table(gpios_table, ARRAY_SIZE(gpios_table)); | 106 | gpiod_add_lookup_table(&gpios_table); |
101 | 107 | ||
102 | The driver controlling "foo.0" will then be able to obtain its GPIOs as follows: | 108 | The driver controlling "foo.0" will then be able to obtain its GPIOs as follows: |
103 | 109 | ||