gpio-mmio.c (24efd94bc38290dc1d9775a1e767ed4685d8a79b) gpio-mmio.c (80057cb417b2873cf645ac85568118c32f038f4c)
1/*
2 * Generic driver for memory-mapped GPIO controllers.
3 *
4 * Copyright 2008 MontaVista Software, Inc.
5 * Copyright 2008,2010 Anton Vorontsov <cbouatmailru@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the

--- 129 unchanged lines hidden (view full) ---

138 unsigned long pinmask = bgpio_line2mask(gc, gpio);
139
140 if (gc->bgpio_dir & pinmask)
141 return !!(gc->read_reg(gc->reg_set) & pinmask);
142 else
143 return !!(gc->read_reg(gc->reg_dat) & pinmask);
144}
145
1/*
2 * Generic driver for memory-mapped GPIO controllers.
3 *
4 * Copyright 2008 MontaVista Software, Inc.
5 * Copyright 2008,2010 Anton Vorontsov <cbouatmailru@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the

--- 129 unchanged lines hidden (view full) ---

138 unsigned long pinmask = bgpio_line2mask(gc, gpio);
139
140 if (gc->bgpio_dir & pinmask)
141 return !!(gc->read_reg(gc->reg_set) & pinmask);
142 else
143 return !!(gc->read_reg(gc->reg_dat) & pinmask);
144}
145
146/*
147 * This assumes that the bits in the GPIO register are in native endianness.
148 * We only assign the function pointer if we have that.
149 */
150static int bgpio_get_set_multiple(struct gpio_chip *gc, unsigned long *mask,
151 unsigned long *bits)
152{
153 unsigned long get_mask = 0;
154 unsigned long set_mask = 0;
155 int bit = 0;
156
157 while ((bit = find_next_bit(mask, gc->ngpio, bit)) != gc->ngpio) {
158 if (gc->bgpio_dir & BIT(bit))
159 set_mask |= BIT(bit);
160 else
161 get_mask |= BIT(bit);
162 }
163
164 if (set_mask)
165 *bits |= gc->read_reg(gc->reg_set) & set_mask;
166 if (get_mask)
167 *bits |= gc->read_reg(gc->reg_dat) & get_mask;
168
169 return 0;
170}
171
146static int bgpio_get(struct gpio_chip *gc, unsigned int gpio)
147{
148 return !!(gc->read_reg(gc->reg_dat) & bgpio_line2mask(gc, gpio));
149}
150
172static int bgpio_get(struct gpio_chip *gc, unsigned int gpio)
173{
174 return !!(gc->read_reg(gc->reg_dat) & bgpio_line2mask(gc, gpio));
175}
176
177/*
178 * This only works if the bits in the GPIO register are in native endianness.
179 * It is dirt simple and fast in this case. (Also the most common case.)
180 */
181static int bgpio_get_multiple(struct gpio_chip *gc, unsigned long *mask,
182 unsigned long *bits)
183{
184
185 *bits = gc->read_reg(gc->reg_dat) & *mask;
186 return 0;
187}
188
189/*
190 * With big endian mirrored bit order it becomes more tedious.
191 */
192static int bgpio_get_multiple_be(struct gpio_chip *gc, unsigned long *mask,
193 unsigned long *bits)
194{
195 unsigned long readmask = 0;
196 unsigned long val;
197 int bit;
198
199 /* Create a mirrored mask */
200 bit = 0;
201 while ((bit = find_next_bit(mask, gc->ngpio, bit)) != gc->ngpio)
202 readmask |= bgpio_line2mask(gc, bit);
203
204 /* Read the register */
205 val = gc->read_reg(gc->reg_dat) & readmask;
206
207 /*
208 * Mirror the result into the "bits" result, this will give line 0
209 * in bit 0 ... line 31 in bit 31 for a 32bit register.
210 */
211 bit = 0;
212 while ((bit = find_next_bit(&val, gc->ngpio, bit)) != gc->ngpio)
213 *bits |= bgpio_line2mask(gc, bit);
214
215 return 0;
216}
217
151static void bgpio_set_none(struct gpio_chip *gc, unsigned int gpio, int val)
152{
153}
154
155static void bgpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
156{
157 unsigned long mask = bgpio_line2mask(gc, gpio);
158 unsigned long flags;

--- 291 unchanged lines hidden (view full) ---

450 gc->set = bgpio_set_none;
451 gc->set_multiple = NULL;
452 } else {
453 gc->set = bgpio_set;
454 gc->set_multiple = bgpio_set_multiple;
455 }
456
457 if (!(flags & BGPIOF_UNREADABLE_REG_SET) &&
218static void bgpio_set_none(struct gpio_chip *gc, unsigned int gpio, int val)
219{
220}
221
222static void bgpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
223{
224 unsigned long mask = bgpio_line2mask(gc, gpio);
225 unsigned long flags;

--- 291 unchanged lines hidden (view full) ---

517 gc->set = bgpio_set_none;
518 gc->set_multiple = NULL;
519 } else {
520 gc->set = bgpio_set;
521 gc->set_multiple = bgpio_set_multiple;
522 }
523
524 if (!(flags & BGPIOF_UNREADABLE_REG_SET) &&
458 (flags & BGPIOF_READ_OUTPUT_REG_SET))
525 (flags & BGPIOF_READ_OUTPUT_REG_SET)) {
459 gc->get = bgpio_get_set;
526 gc->get = bgpio_get_set;
460 else
527 if (!gc->be_bits)
528 gc->get_multiple = bgpio_get_set_multiple;
529 /*
530 * We deliberately avoid assigning the ->get_multiple() call
531 * for big endian mirrored registers which are ALSO reflecting
532 * their value in the set register when used as output. It is
533 * simply too much complexity, let the GPIO core fall back to
534 * reading each line individually in that fringe case.
535 */
536 } else {
461 gc->get = bgpio_get;
537 gc->get = bgpio_get;
538 if (gc->be_bits)
539 gc->get_multiple = bgpio_get_multiple_be;
540 else
541 gc->get_multiple = bgpio_get_multiple;
542 }
462
463 return 0;
464}
465
466static int bgpio_setup_direction(struct gpio_chip *gc,
467 void __iomem *dirout,
468 void __iomem *dirin,
469 unsigned long flags)

--- 44 unchanged lines hidden (view full) ---

514 return -EINVAL;
515
516 spin_lock_init(&gc->bgpio_lock);
517 gc->parent = dev;
518 gc->label = dev_name(dev);
519 gc->base = -1;
520 gc->ngpio = gc->bgpio_bits;
521 gc->request = bgpio_request;
543
544 return 0;
545}
546
547static int bgpio_setup_direction(struct gpio_chip *gc,
548 void __iomem *dirout,
549 void __iomem *dirin,
550 unsigned long flags)

--- 44 unchanged lines hidden (view full) ---

595 return -EINVAL;
596
597 spin_lock_init(&gc->bgpio_lock);
598 gc->parent = dev;
599 gc->label = dev_name(dev);
600 gc->base = -1;
601 gc->ngpio = gc->bgpio_bits;
602 gc->request = bgpio_request;
603 gc->be_bits = !!(flags & BGPIOF_BIG_ENDIAN);
522
523 ret = bgpio_setup_io(gc, dat, set, clr, flags);
524 if (ret)
525 return ret;
526
604
605 ret = bgpio_setup_io(gc, dat, set, clr, flags);
606 if (ret)
607 return ret;
608
527 gc->be_bits = !!(flags & BGPIOF_BIG_ENDIAN);
528 ret = bgpio_setup_accessors(dev, gc, flags & BGPIOF_BIG_ENDIAN_BYTE_ORDER);
529 if (ret)
530 return ret;
531
532 ret = bgpio_setup_direction(gc, dirout, dirin, flags);
533 if (ret)
534 return ret;
535

--- 170 unchanged lines hidden ---
609 ret = bgpio_setup_accessors(dev, gc, flags & BGPIOF_BIG_ENDIAN_BYTE_ORDER);
610 if (ret)
611 return ret;
612
613 ret = bgpio_setup_direction(gc, dirout, dirin, flags);
614 if (ret)
615 return ret;
616

--- 170 unchanged lines hidden ---