aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/gpio/gpio-gpio-mm.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/drivers/gpio/gpio-gpio-mm.c b/drivers/gpio/gpio-gpio-mm.c
index 11ade5b288f8..d496cc56c2a2 100644
--- a/drivers/gpio/gpio-gpio-mm.c
+++ b/drivers/gpio/gpio-gpio-mm.c
@@ -14,6 +14,7 @@
14 * This driver supports the following Diamond Systems devices: GPIO-MM and 14 * This driver supports the following Diamond Systems devices: GPIO-MM and
15 * GPIO-MM-12. 15 * GPIO-MM-12.
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>
@@ -171,6 +172,51 @@ static int gpiomm_gpio_get(struct gpio_chip *chip, unsigned int offset)
171 return !!(port_state & mask); 172 return !!(port_state & mask);
172} 173}
173 174
175static int gpiomm_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask,
176 unsigned long *bits)
177{
178 struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip);
179 size_t i;
180 const size_t ports[] = { 0, 1, 2, 4, 5, 6 };
181 const unsigned int gpio_reg_size = 8;
182 unsigned int bits_offset;
183 size_t word_index;
184 unsigned int word_offset;
185 unsigned long word_mask;
186 const unsigned long port_mask = GENMASK(gpio_reg_size - 1, 0);
187 unsigned long port_state;
188
189 /* clear bits array to a clean slate */
190 bitmap_zero(bits, chip->ngpio);
191
192 /* get bits are evaluated a gpio port register at a time */
193 for (i = 0; i < ARRAY_SIZE(ports); i++) {
194 /* gpio offset in bits array */
195 bits_offset = i * gpio_reg_size;
196
197 /* word index for bits array */
198 word_index = BIT_WORD(bits_offset);
199
200 /* gpio offset within current word of bits array */
201 word_offset = bits_offset % BITS_PER_LONG;
202
203 /* mask of get bits for current gpio within current word */
204 word_mask = mask[word_index] & (port_mask << word_offset);
205 if (!word_mask) {
206 /* no get bits in this port so skip to next one */
207 continue;
208 }
209
210 /* read bits from current gpio port */
211 port_state = inb(gpiommgpio->base + ports[i]);
212
213 /* store acquired bits at respective bits array offset */
214 bits[word_index] |= port_state << word_offset;
215 }
216
217 return 0;
218}
219
174static void gpiomm_gpio_set(struct gpio_chip *chip, unsigned int offset, 220static void gpiomm_gpio_set(struct gpio_chip *chip, unsigned int offset,
175 int value) 221 int value)
176{ 222{
@@ -268,6 +314,7 @@ static int gpiomm_probe(struct device *dev, unsigned int id)
268 gpiommgpio->chip.direction_input = gpiomm_gpio_direction_input; 314 gpiommgpio->chip.direction_input = gpiomm_gpio_direction_input;
269 gpiommgpio->chip.direction_output = gpiomm_gpio_direction_output; 315 gpiommgpio->chip.direction_output = gpiomm_gpio_direction_output;
270 gpiommgpio->chip.get = gpiomm_gpio_get; 316 gpiommgpio->chip.get = gpiomm_gpio_get;
317 gpiommgpio->chip.get_multiple = gpiomm_gpio_get_multiple;
271 gpiommgpio->chip.set = gpiomm_gpio_set; 318 gpiommgpio->chip.set = gpiomm_gpio_set;
272 gpiommgpio->chip.set_multiple = gpiomm_gpio_set_multiple; 319 gpiommgpio->chip.set_multiple = gpiomm_gpio_set_multiple;
273 gpiommgpio->base = base[id]; 320 gpiommgpio->base = base[id];