aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Breathitt Gray <vilhelm.gray@gmail.com>2018-03-22 09:00:11 -0400
committerLinus Walleij <linus.walleij@linaro.org>2018-03-26 04:26:14 -0400
commitd2d02bcdd52b889ec1bcabf8d0da6f3c2b87e9fc (patch)
treef004e1650334c2354f891b87b56391e7edb75b71
parentca37081595a2fa1d67c962d416392d36ae8d05ad (diff)
gpio: 104-dio-48e: Implement get_multiple callback
The ACCES I/O 104-DIO-48E series of devices contain two Programmable Peripheral Interface (PPI) chips of type 82C55, which each feature three 8-bit ports of I/O. Since eight input lines are acquired on a single port input read, the 104-DIO-48E GPIO driver may improve multiple input reads by utilizing a get_multiple callback. This patch implements the dio48e_gpio_get_multiple function which serves as the respective get_multiple callback. Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
-rw-r--r--drivers/gpio/gpio-104-dio-48e.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/drivers/gpio/gpio-104-dio-48e.c b/drivers/gpio/gpio-104-dio-48e.c
index bab3b94c5cbc..31e22c93e844 100644
--- a/drivers/gpio/gpio-104-dio-48e.c
+++ b/drivers/gpio/gpio-104-dio-48e.c
@@ -14,6 +14,7 @@
14 * This driver supports the following ACCES devices: 104-DIO-48E and 14 * This driver supports the following ACCES devices: 104-DIO-48E and
15 * 104-DIO-24E. 15 * 104-DIO-24E.
16 */ 16 */
17#include <linux/bitmap.h>
17#include <linux/bitops.h> 18#include <linux/bitops.h>
18#include <linux/device.h> 19#include <linux/device.h>
19#include <linux/errno.h> 20#include <linux/errno.h>
@@ -182,6 +183,51 @@ static int dio48e_gpio_get(struct gpio_chip *chip, unsigned offset)
182 return !!(port_state & mask); 183 return !!(port_state & mask);
183} 184}
184 185
186static int dio48e_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask,
187 unsigned long *bits)
188{
189 struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip);
190 size_t i;
191 const size_t ports[] = { 0, 1, 2, 4, 5, 6 };
192 const unsigned int gpio_reg_size = 8;
193 unsigned int bits_offset;
194 size_t word_index;
195 unsigned int word_offset;
196 unsigned long word_mask;
197 const unsigned long port_mask = GENMASK(gpio_reg_size - 1, 0);
198 unsigned long port_state;
199
200 /* clear bits array to a clean slate */
201 bitmap_zero(bits, chip->ngpio);
202
203 /* get bits are evaluated a gpio port register at a time */
204 for (i = 0; i < ARRAY_SIZE(ports); i++) {
205 /* gpio offset in bits array */
206 bits_offset = i * gpio_reg_size;
207
208 /* word index for bits array */
209 word_index = BIT_WORD(bits_offset);
210
211 /* gpio offset within current word of bits array */
212 word_offset = bits_offset % BITS_PER_LONG;
213
214 /* mask of get bits for current gpio within current word */
215 word_mask = mask[word_index] & (port_mask << word_offset);
216 if (!word_mask) {
217 /* no get bits in this port so skip to next one */
218 continue;
219 }
220
221 /* read bits from current gpio port */
222 port_state = inb(dio48egpio->base + ports[i]);
223
224 /* store acquired bits at respective bits array offset */
225 bits[word_index] |= port_state << word_offset;
226 }
227
228 return 0;
229}
230
185static void dio48e_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 231static void dio48e_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
186{ 232{
187 struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip); 233 struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip);
@@ -384,6 +430,7 @@ static int dio48e_probe(struct device *dev, unsigned int id)
384 dio48egpio->chip.direction_input = dio48e_gpio_direction_input; 430 dio48egpio->chip.direction_input = dio48e_gpio_direction_input;
385 dio48egpio->chip.direction_output = dio48e_gpio_direction_output; 431 dio48egpio->chip.direction_output = dio48e_gpio_direction_output;
386 dio48egpio->chip.get = dio48e_gpio_get; 432 dio48egpio->chip.get = dio48e_gpio_get;
433 dio48egpio->chip.get_multiple = dio48e_gpio_get_multiple;
387 dio48egpio->chip.set = dio48e_gpio_set; 434 dio48egpio->chip.set = dio48e_gpio_set;
388 dio48egpio->chip.set_multiple = dio48e_gpio_set_multiple; 435 dio48egpio->chip.set_multiple = dio48e_gpio_set_multiple;
389 dio48egpio->base = base[id]; 436 dio48egpio->base = base[id];