aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio
diff options
context:
space:
mode:
authorMans Rullgard <mans@mansr.com>2015-01-21 12:17:49 -0500
committerLinus Walleij <linus.walleij@linaro.org>2015-01-30 04:45:56 -0500
commit161af6cd899508506ac5df101af7e569f28aa0e6 (patch)
treef2175c8f6b01455946541e669f73d2c38d401ba9 /drivers/gpio
parent920dfd824789b4058e91d26e2c6dd01a00ab28ec (diff)
gpio: max732x: add set_multiple function
This adds a set_multiple function to the MAX732x GPIO driver, allowing for performance gains when using gpiod_set_array(). Signed-off-by: Mans Rullgard <mans@mansr.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio')
-rw-r--r--drivers/gpio/gpio-max732x.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/drivers/gpio/gpio-max732x.c b/drivers/gpio/gpio-max732x.c
index 5fbab135f4a7..745698d977a5 100644
--- a/drivers/gpio/gpio-max732x.c
+++ b/drivers/gpio/gpio-max732x.c
@@ -212,10 +212,11 @@ static int max732x_gpio_get_value(struct gpio_chip *gc, unsigned off)
212 return reg_val & (1u << (off & 0x7)); 212 return reg_val & (1u << (off & 0x7));
213} 213}
214 214
215static void max732x_gpio_set_value(struct gpio_chip *gc, unsigned off, int val) 215static void max732x_gpio_set_mask(struct gpio_chip *gc, unsigned off, int mask,
216 int val)
216{ 217{
217 struct max732x_chip *chip; 218 struct max732x_chip *chip;
218 uint8_t reg_out, mask = 1u << (off & 0x7); 219 uint8_t reg_out;
219 int ret; 220 int ret;
220 221
221 chip = container_of(gc, struct max732x_chip, gpio_chip); 222 chip = container_of(gc, struct max732x_chip, gpio_chip);
@@ -223,7 +224,7 @@ static void max732x_gpio_set_value(struct gpio_chip *gc, unsigned off, int val)
223 mutex_lock(&chip->lock); 224 mutex_lock(&chip->lock);
224 225
225 reg_out = (off > 7) ? chip->reg_out[1] : chip->reg_out[0]; 226 reg_out = (off > 7) ? chip->reg_out[1] : chip->reg_out[0];
226 reg_out = (val) ? reg_out | mask : reg_out & ~mask; 227 reg_out = (reg_out & ~mask) | (val & mask);
227 228
228 ret = max732x_writeb(chip, is_group_a(chip, off), reg_out); 229 ret = max732x_writeb(chip, is_group_a(chip, off), reg_out);
229 if (ret < 0) 230 if (ret < 0)
@@ -238,6 +239,26 @@ out:
238 mutex_unlock(&chip->lock); 239 mutex_unlock(&chip->lock);
239} 240}
240 241
242static void max732x_gpio_set_value(struct gpio_chip *gc, unsigned off, int val)
243{
244 unsigned base = off & ~0x7;
245 uint8_t mask = 1u << (off & 0x7);
246
247 max732x_gpio_set_mask(gc, base, mask, val << (off & 0x7));
248}
249
250static void max732x_gpio_set_multiple(struct gpio_chip *gc,
251 unsigned long *mask, unsigned long *bits)
252{
253 unsigned mask_lo = mask[0] & 0xff;
254 unsigned mask_hi = (mask[0] >> 8) & 0xff;
255
256 if (mask_lo)
257 max732x_gpio_set_mask(gc, 0, mask_lo, bits[0] & 0xff);
258 if (mask_hi)
259 max732x_gpio_set_mask(gc, 8, mask_hi, (bits[0] >> 8) & 0xff);
260}
261
241static int max732x_gpio_direction_input(struct gpio_chip *gc, unsigned off) 262static int max732x_gpio_direction_input(struct gpio_chip *gc, unsigned off)
242{ 263{
243 struct max732x_chip *chip; 264 struct max732x_chip *chip;
@@ -621,6 +642,7 @@ static int max732x_setup_gpio(struct max732x_chip *chip,
621 if (chip->dir_output) { 642 if (chip->dir_output) {
622 gc->direction_output = max732x_gpio_direction_output; 643 gc->direction_output = max732x_gpio_direction_output;
623 gc->set = max732x_gpio_set_value; 644 gc->set = max732x_gpio_set_value;
645 gc->set_multiple = max732x_gpio_set_multiple;
624 } 646 }
625 gc->get = max732x_gpio_get_value; 647 gc->get = max732x_gpio_get_value;
626 gc->can_sleep = true; 648 gc->can_sleep = true;