Implement get_multiple for ACCES and PC104 drivers
Subsystems (9)
cover Implement get_multiple for ACCES and PC104 drivers
This patchset implements get_multiple callbacks for the PC104 GPIO drivers as well as the PCI-IDIO-16 and PCIe-IDIO-24 GPIO drivers. These devices all acquire the multiple input lines with a single read, so utilizing the get_multiple callback can provide improvement for those users who regularly access multiple input lines.
While developing this patchset I noticed many of these devices make use of Intel 8255 compatible interfaces for their I/O. I may write a generic 8255 GPIO driver in the future to reduce some of the redundant code I see pop among the drivers for these devices.
William Breathitt Gray (8):
iio: stx104: Implement get_multiple callback
gpio: 104-idio-16: Implement get_multiple callback
gpio: pci-idio-16: Implement get_multiple callback
gpio: pcie-idio-24: Implement get_multiple callback
gpio: 104-dio-48e: Implement get_multiple callback
gpio: 104-idi-48: Implement get_multiple callback
gpio: gpio-mm: Implement get_multiple callback
gpio: ws16c48: Implement get_multiple callback
drivers/gpio/gpio-104-dio-48e.c | 41 ++++++++++++++++++++++++++ drivers/gpio/gpio-104-idi-48.c | 41 ++++++++++++++++++++++++++ drivers/gpio/gpio-104-idio-16.c | 15 ++++++++++ drivers/gpio/gpio-gpio-mm.c | 41 ++++++++++++++++++++++++++ drivers/gpio/gpio-pci-idio-16.c | 48 ++++++++++++++++++++++++++++++ drivers/gpio/gpio-pcie-idio-24.c | 63 ++++++++++++++++++++++++++++++++++++++++ drivers/gpio/gpio-ws16c48.c | 39 +++++++++++++++++++++++++ drivers/iio/adc/stx104.c | 11 +++++++ 8 files changed, 299 insertions(+)
Signature · 1 line
2.16.2
PATCH 1/8 iio: stx104: Implement get_multiple callback
The Apex Embedded Systems STX104 series of devices provides 4 TTL compatible lines of inputs accessed via a single 4-bit port. Since four input lines are acquired on a single port input read, the STX104 GPIO driver may improve multiple input reads by utilizing a get_multiple callback. This patch implements the stx104_gpio_get_multiple function which serves as the respective get_multiple callback.
--- drivers/iio/adc/stx104.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/iio/adc/stx104.c +11 -0
@@ -233,6 +233,16 @@ static int stx104_gpio_get(struct gpio_chip *chip, unsigned int offset)return !!(inb (stx104gpio->base) &BIT (offset)); } +static int stx104_gpio_get_multiple (struct gpio_chip *chip,unsigned long *mask, +unsigned long *bits) +{ +struct stx104_gpio *const stx104gpio =gpiochip_get_data (chip); + + *bits =inb (stx104gpio->base); + +return 0 ; +} +static void stx104_gpio_set (struct gpio_chip *chip,unsigned int offset,int value) {
@@ -342,6 +352,7 @@ static int stx104_probe(struct device *dev, unsigned int id) stx104gpio->chip.direction_input = stx104_gpio_direction_input; stx104gpio->chip.direction_output = stx104_gpio_direction_output; stx104gpio->chip.get = stx104_gpio_get; + stx104gpio->chip.get_multiple = stx104_gpio_get_multiple; stx104gpio->chip.set = stx104_gpio_set; stx104gpio->chip.set_multiple = stx104_gpio_set_multiple; stx104gpio->base = base[id] +3 ;
Signature · 1 line
2.16.2
PATCH 2/8 gpio: 104-idio-16: Implement get_multiple callback
In reply to William Breathitt GrayThe ACCES I/O 104-IDIO-16 series of devices provides 16 optically-isolated digital inputs accessed via two 8-bit ports. Since eight input lines are acquired on a single port input read, the 104-IDIO-16 GPIO driver may improve multiple input reads by utilizing a get_multiple callback. This patch implements the idio_16_gpio_get_multiple function which serves as the respective get_multiple callback.
--- drivers/gpio/gpio-104-idio-16.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/gpio/gpio-104-idio-16.c +15 -0
@@ -90,6 +90,20 @@ static int idio_16_gpio_get(struct gpio_chip *chip, unsigned offset)return !!(inb (idio16gpio->base +5 ) & (mask>>8 )); } +static int idio_16_gpio_get_multiple (struct gpio_chip *chip, +unsigned long *mask,unsigned long *bits) +{ +struct idio_16_gpio *const idio16gpio =gpiochip_get_data (chip); + + *bits =0 ; +if (*mask &0xFF0000 ) + *bits |= (unsigned long )inb (idio16gpio->base +1 ) <<16 ; +if (*mask &0xFF000000 ) + *bits |= (unsigned long )inb (idio16gpio->base +5 ) <<24 ; + +return 0 ; +} +static void idio_16_gpio_set (struct gpio_chip *chip,unsigned offset,int value) {struct idio_16_gpio *const idio16gpio =gpiochip_get_data (chip);
@@ -244,6 +258,7 @@ static int idio_16_probe(struct device *dev, unsigned int id) idio16gpio->chip.direction_input = idio_16_gpio_direction_input; idio16gpio->chip.direction_output = idio_16_gpio_direction_output; idio16gpio->chip.get = idio_16_gpio_get; + idio16gpio->chip.get_multiple = idio_16_gpio_get_multiple; idio16gpio->chip.set = idio_16_gpio_set; idio16gpio->chip.set_multiple = idio_16_gpio_set_multiple; idio16gpio->base = base[id];
Signature · 1 line
2.16.2
PATCH 3/8 gpio: pci-idio-16: Implement get_multiple callback
In reply to William Breathitt GrayThe ACCES I/O PCI-IDIO-16 series of devices provides 16 optically-isolated digital inputs accessed via two 8-bit ports. Since eight input lines are acquired on a single port input read, the PCI-IDIO-16 GPIO driver may improve multiple input reads by utilizing a get_multiple callback. This patch implements the idio_16_gpio_get_multiple function which serves as the respective get_multiple callback.
--- drivers/gpio/gpio-pci-idio-16.c | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+)
drivers/gpio/gpio-pci-idio-16.c +48 -0
@@ -103,6 +103,53 @@ static int idio_16_gpio_get(struct gpio_chip *chip, unsigned int offset)return !!(ioread8 (&idio16gpio->reg->in8_15) & (mask >>24 )); } +static int idio_16_gpio_get_multiple (struct gpio_chip *chip, +unsigned long *mask,unsigned long *bits) +{ +struct idio_16_gpio *const idio16gpio =gpiochip_get_data (chip); +unsigned int i; +const unsigned int gpio_reg_size =8 ; +unsigned int bit_word_offset; +unsigned int bits_mask; +const unsigned long reg_mask =GENMASK (gpio_reg_size,0 ); +unsigned long port_state; + +/* clear bits array to a clean slate */ +for (i =0 ; i < chip->ngpio; i +=BITS_PER_LONG ) + bits[i /BITS_PER_LONG ] =0 ; + +/* get bits are evaluated a gpio register size at a time */ +for (i =0 ; i < chip->ngpio; i += gpio_reg_size) { + bit_word_offset = i %BITS_PER_LONG ; + bits_mask = mask[BIT_WORD (i)] & (reg_mask << bit_word_offset); +if (!bits_mask) { +/* no get bits in this register so skip to next one */ +continue ; + } + +/* read bits from current gpio register */ +switch (i / gpio_reg_size) { +case 0 : + port_state =ioread8 (&idio16gpio->reg->out0_7); +break ; +case 1 : + port_state =ioread8 (&idio16gpio->reg->out8_15); +break ; +case 2 : + port_state =ioread8 (&idio16gpio->reg->in0_7); +break ; +case 3 : + port_state =ioread8 (&idio16gpio->reg->in8_15); +break ; + } + +/* store acquired bits */ + bits[BIT_WORD (i)] |= port_state << bit_word_offset; + } + +return 0 ; +} +static void idio_16_gpio_set (struct gpio_chip *chip,unsigned int offset,int value) {
@@ -299,6 +346,7 @@ static int idio_16_probe(struct pci_dev *pdev, const struct pci_device_id *id) idio16gpio->chip.direction_input = idio_16_gpio_direction_input; idio16gpio->chip.direction_output = idio_16_gpio_direction_output; idio16gpio->chip.get = idio_16_gpio_get; + idio16gpio->chip.get_multiple = idio_16_gpio_get_multiple; idio16gpio->chip.set = idio_16_gpio_set; idio16gpio->chip.set_multiple = idio_16_gpio_set_multiple;
Signature · 1 line
2.16.2
kbuild test robot
build botRe: [PATCH 3/8] gpio: pci-idio-16: Implement get_multiple callback
I love your patch! Perhaps something to improve:
Hi William,
I love your patch! Perhaps something to improve:
[auto build test WARNING on linus/master]
[also build test WARNING on v4.16-rc5 next-20180313]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/William-Breathitt-Gray/Implement-get_multiple-for-ACCES-and-PC104-drivers/20180313-202244
config: x86_64-randconfig-x015-201810 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 Note: it may well be a FALSE warning. FWIW you are at least aware of it now.
http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings
All warnings (new ones prefixed by >>):
drivers//gpio/gpio-pci-idio-16.c: In function 'idio_16_gpio_get_multiple':
>> drivers//gpio/gpio-pci-idio-16.c:147:35: warning: 'port_state' may be used uninitialized in this function [-Wmaybe-uninitialized]
bits[BIT_WORD(i)] |= port_state << bit_word_offset;
~~~~~~~~~~~^~~~~~~~~~~~~~~~~~vim +/port_state +147 drivers//gpio/gpio-pci-idio-16.c
105
106 static int idio_16_gpio_get_multiple(struct gpio_chip *chip,
107 unsigned long *mask, unsigned long *bits)
108 {
109 struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip);
110 unsigned int i;
111 const unsigned int gpio_reg_size = 8;
112 unsigned int bit_word_offset;
113 unsigned int bits_mask;
114 const unsigned long reg_mask = GENMASK(gpio_reg_size, 0);
115 unsigned long port_state;
116
117 /* clear bits array to a clean slate */
118 for (i = 0; i < chip->ngpio; i += BITS_PER_LONG)
119 bits[i / BITS_PER_LONG] = 0;
120
121 /* get bits are evaluated a gpio register size at a time */
122 for (i = 0; i < chip->ngpio; i += gpio_reg_size) {
123 bit_word_offset = i % BITS_PER_LONG;
124 bits_mask = mask[BIT_WORD(i)] & (reg_mask << bit_word_offset);
125 if (!bits_mask) {
126 /* no get bits in this register so skip to next one */
127 continue;
128 }
129
130 /* read bits from current gpio register */
131 switch (i / gpio_reg_size) {
132 case 0:
133 port_state = ioread8(&idio16gpio->reg->out0_7);
134 break;
135 case 1:
136 port_state = ioread8(&idio16gpio->reg->out8_15);
137 break;
138 case 2:
139 port_state = ioread8(&idio16gpio->reg->in0_7);
140 break;
141 case 3:
142 port_state = ioread8(&idio16gpio->reg->in8_15);
143 break;
144 }
145
146 /* store acquired bits */
> 147 bits[BIT_WORD(i)] |= port_state << bit_word_offset;
148 }
149
150 return 0;
151 }
152
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Re: [PATCH 3/8] gpio: pci-idio-16: Implement get_multiple callback
In reply to William Breathitt Graydrivers/gpio/gpio-pci-idio-16.c static int idio_16_gpio_get(struct gpio_chip *chip, unsigned int offset) · line 119
Quoted 8 lines · William Breathitt Gray
drivers/gpio/gpio-pci-idio-16.c +6
-0+static int idio_16_gpio_get_multiple (struct gpio_chip *chip, +unsigned long *mask,unsigned long *bits) +{ +/* clear bits array to a clean slate */ +for (i =0 ; i < chip->ngpio; i +=BITS_PER_LONG ) + bits[i /BITS_PER_LONG ] =0 ;
bitmap_clear() or bitmap_zero()
drivers/gpio/gpio-pci-idio-16.c static int idio_16_gpio_get(struct gpio_chip *chip, unsigned int offset) · line 128
Quoted 8 lines
drivers/gpio/gpio-pci-idio-16.c +8
-0+/* get bits are evaluated a gpio register size at a time */ +for (i =0 ; i < chip->ngpio; i += gpio_reg_size) { + bit_word_offset = i %BITS_PER_LONG ; + bits_mask = mask[BIT_WORD (i)] & (reg_mask << bit_word_offset); +if (!bits_mask) { +/* no get bits in this register so skip to next one */ +continue ; + }
for_each_set_bit() ?
drivers/gpio/gpio-pci-idio-16.c static int idio_16_gpio_get(struct gpio_chip *chip, unsigned int offset) · line 147
Quoted 2 lines
drivers/gpio/gpio-pci-idio-16.c +2
-0+/* store acquired bits */ + bits[BIT_WORD (i)] |= port_state << bit_word_offset;
__set_bit()__clear_bit()
We have bitmap API for *ages*. Is it too hard to check?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 3/8] gpio: pci-idio-16: Implement get_multiple callback
Quoted 8 lines · Andy Shevchenko
Quoted 3 lines · William Breathitt Gray
drivers/gpio/gpio-pci-idio-16.c +3
-0+static int idio_16_gpio_get_multiple (struct gpio_chip *chip, +unsigned long *mask,unsigned long *bits) +{
Quoted 5 lines
drivers/gpio/gpio-pci-idio-16.c static int idio_16_gpio_get(struct gpio_chip *chip, unsigned int offset) · line 119
Quoted 3 lines
drivers/gpio/gpio-pci-idio-16.c +3
-0+/* clear bits array to a clean slate */ +for (i =0 ; i < chip->ngpio; i +=BITS_PER_LONG ) + bits[i /BITS_PER_LONG ] =0 ;
bitmap_clear()orbitmap_zero()
bitmap_zero() would be perfect for this situation. I'll submit a version 2 of this patchset with this change for the various drivers herein.
Quoted 10 lines
drivers/gpio/gpio-pci-idio-16.c static int idio_16_gpio_get(struct gpio_chip *chip, unsigned int offset) · line 128
Quoted 9 lines
drivers/gpio/gpio-pci-idio-16.c +8
-0+/* get bits are evaluated a gpio register size at a time */ +for (i =0 ; i < chip->ngpio; i += gpio_reg_size) { + bit_word_offset = i %BITS_PER_LONG ; + bits_mask = mask[BIT_WORD (i)] & (reg_mask << bit_word_offset); +if (!bits_mask) { +/* no get bits in this register so skip to next one */ +continue ; + }
Quoted 7 lines
for_each_set_bit()?drivers/gpio/gpio-pci-idio-16.c static int idio_16_gpio_get(struct gpio_chip *chip, unsigned int offset) · line 147
Quoted 2 lines
drivers/gpio/gpio-pci-idio-16.c +2
-0+/* store acquired bits */ + bits[BIT_WORD (i)] |= port_state << bit_word_offset;
__set_bit()__clear_bit()
I'm not sure for_each_set_bit() and __set_bit()/__clear_bit() would be good for this particular situation since I'm working with the entire register word (8 bits for this specific device) at a time.
Since I know each register word is 8-bits, I can make 8-bit jumps and skips rather than evaluating each bit individually. Similarly, it seems more efficient to store the input 8 bits at a time rather than breaking it up to individual bits.
However, I do see how all these inline bitwise operations could make it difficult to follow the code, so perhaps I can break it up across more lines so that the logic of the loop becomes easier to read.
William Breathitt Gray
Quoted 6 lines
We have bitmap API for *ages*. Is it too hard to check?
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 4/8 gpio: pcie-idio-24: Implement get_multiple callback
In reply to William Breathitt GrayThe ACCES I/O PCIe-IDIO-24 series of devices provides 24 optically-isolated digital inputs accessed via three 8-bit ports. Since eight input lines are acquired on a single port input read, the PCIe-IDIO-24 GPIO driver may improve multiple input reads by utilizing a get_multiple callback. This patch implements the idio_24_gpio_get_multiple function which serves as the respective get_multiple callback.
--- drivers/gpio/gpio-pcie-idio-24.c | 63 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+)
drivers/gpio/gpio-pcie-idio-24.c +63 -0
@@ -193,6 +193,68 @@ static int idio_24_gpio_get(struct gpio_chip *chip, unsigned int offset)return !!(ioread8 (&idio24gpio->reg->ttl_in0_7) & offset_mask); } +static int idio_24_gpio_get_multiple (struct gpio_chip *chip, +unsigned long *mask,unsigned long *bits) +{ +struct idio_24_gpio *const idio24gpio =gpiochip_get_data (chip); +struct idio_24_gpio_reg __iomem *const reg = idio24gpio->reg; +unsigned int i; +const unsigned int gpio_reg_size =8 ; +unsigned int bit_word_offset; +unsigned int bits_mask; +const unsigned long reg_mask =GENMASK (gpio_reg_size,0 ); +unsigned long port_state; +const unsigned long out_mode_mask =BIT (1 ); + +/* clear bits array to a clean slate */ +for (i =0 ; i < chip->ngpio; i +=BITS_PER_LONG ) + bits[i /BITS_PER_LONG ] =0 ; + +/* get bits are evaluated a gpio register size at a time */ +for (i =0 ; i < chip->ngpio; i += gpio_reg_size) { + bit_word_offset = i %BITS_PER_LONG ; + bits_mask = mask[BIT_WORD (i)] & (reg_mask << bit_word_offset); +if (!bits_mask) { +/* no get bits in this register so skip to next one */ +continue ; + } + +/* read bits from current gpio register */ +switch (i / gpio_reg_size) { +case 0 : + port_state =ioread8 (®->out0_7); +break ; +case 1 : + port_state =ioread8 (®->out8_15); +break ; +case 2 : + port_state =ioread8 (®->out16_23); +break ; +case 3 : + port_state =ioread8 (®->in0_7); +break ; +case 4 : + port_state =ioread8 (®->in8_15); +break ; +case 5 : + port_state =ioread8 (®->in16_23); +break ; +case 6 : +/* TTL/CMOS Outputs/Inputs */ +if (ioread8 (®->ctl) & out_mode_mask) + port_state =ioread8 (®->ttl_out0_7); +else + port_state =ioread8 (®->ttl_in0_7); +break ; + } + +/* store acquired bits */ + bits[BIT_WORD (i)] |= port_state << bit_word_offset; + } + +return 0 ; +} +static void idio_24_gpio_set (struct gpio_chip *chip,unsigned int offset,int value) {
@@ -397,6 +459,7 @@ static int idio_24_probe(struct pci_dev *pdev, const struct pci_device_id *id) idio24gpio->chip.direction_input = idio_24_gpio_direction_input; idio24gpio->chip.direction_output = idio_24_gpio_direction_output; idio24gpio->chip.get = idio_24_gpio_get; + idio24gpio->chip.get_multiple = idio_24_gpio_get_multiple; idio24gpio->chip.set = idio_24_gpio_set;raw_spin_lock_init (&idio24gpio->lock);
Signature · 1 line
2.16.2
kbuild test robot
build botRe: [PATCH 4/8] gpio: pcie-idio-24: Implement get_multiple callback
I love your patch! Perhaps something to improve:
Hi William,
I love your patch! Perhaps something to improve:
[auto build test WARNING on linus/master]
[also build test WARNING on v4.16-rc5 next-20180313]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/William-Breathitt-Gray/Implement-get_multiple-for-ACCES-and-PC104-drivers/20180313-202244
config: x86_64-randconfig-x014-201810 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 Note: it may well be a FALSE warning. FWIW you are at least aware of it now.
http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings
All warnings (new ones prefixed by >>):
drivers//gpio/gpio-pcie-idio-24.c: In function 'idio_24_gpio_get_multiple':
>> drivers//gpio/gpio-pcie-idio-24.c:252:35: warning: 'port_state' may be used uninitialized in this function [-Wmaybe-uninitialized]
bits[BIT_WORD(i)] |= port_state << bit_word_offset;
~~~~~~~~~~~^~~~~~~~~~~~~~~~~~vim +/port_state +252 drivers//gpio/gpio-pcie-idio-24.c
195
196 static int idio_24_gpio_get_multiple(struct gpio_chip *chip,
197 unsigned long *mask, unsigned long *bits)
198 {
199 struct idio_24_gpio *const idio24gpio = gpiochip_get_data(chip);
200 struct idio_24_gpio_reg __iomem *const reg = idio24gpio->reg;
201 unsigned int i;
202 const unsigned int gpio_reg_size = 8;
203 unsigned int bit_word_offset;
204 unsigned int bits_mask;
205 const unsigned long reg_mask = GENMASK(gpio_reg_size, 0);
206 unsigned long port_state;
207 const unsigned long out_mode_mask = BIT(1);
208
209 /* clear bits array to a clean slate */
210 for (i = 0; i < chip->ngpio; i += BITS_PER_LONG)
211 bits[i / BITS_PER_LONG] = 0;
212
213 /* get bits are evaluated a gpio register size at a time */
214 for (i = 0; i < chip->ngpio; i += gpio_reg_size) {
215 bit_word_offset = i % BITS_PER_LONG;
216 bits_mask = mask[BIT_WORD(i)] & (reg_mask << bit_word_offset);
217 if (!bits_mask) {
218 /* no get bits in this register so skip to next one */
219 continue;
220 }
221
222 /* read bits from current gpio register */
223 switch (i / gpio_reg_size) {
224 case 0:
225 port_state = ioread8(®->out0_7);
226 break;
227 case 1:
228 port_state = ioread8(®->out8_15);
229 break;
230 case 2:
231 port_state = ioread8(®->out16_23);
232 break;
233 case 3:
234 port_state = ioread8(®->in0_7);
235 break;
236 case 4:
237 port_state = ioread8(®->in8_15);
238 break;
239 case 5:
240 port_state = ioread8(®->in16_23);
241 break;
242 case 6:
243 /* TTL/CMOS Outputs/Inputs */
244 if (ioread8(®->ctl) & out_mode_mask)
245 port_state = ioread8(®->ttl_out0_7);
246 else
247 port_state = ioread8(®->ttl_in0_7);
248 break;
249 }
250
251 /* store acquired bits */
> 252 bits[BIT_WORD(i)] |= port_state << bit_word_offset;
253 }
254
255 return 0;
256 }
257
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
PATCH 5/8 gpio: 104-dio-48e: Implement get_multiple callback
In reply to William Breathitt GrayThe 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.
--- drivers/gpio/gpio-104-dio-48e.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
drivers/gpio/gpio-104-dio-48e.c +41 -0
@@ -182,6 +182,46 @@ static int dio48e_gpio_get(struct gpio_chip *chip, unsigned offset)return !!(port_state & mask); } +static int dio48e_gpio_get_multiple (struct gpio_chip *chip,unsigned long *mask, +unsigned long *bits) +{ +struct dio48e_gpio *const dio48egpio =gpiochip_get_data (chip); +unsigned int i; +const unsigned int gpio_reg_size =8 ; +unsigned int bit_word_offset; +unsigned int bits_mask; +const unsigned long reg_mask =GENMASK (gpio_reg_size,0 ); +unsigned int port; +unsigned int in_port; +unsigned long port_state; + +/* clear bits array to a clean slate */ +for (i =0 ; i < chip->ngpio; i +=BITS_PER_LONG ) + bits[i /BITS_PER_LONG ] =0 ; + +/* get bits are evaluated a gpio register size at a time */ +for (i =0 ; i < chip->ngpio; i += gpio_reg_size) { + bit_word_offset = i %BITS_PER_LONG ; + bits_mask = mask[BIT_WORD (i)] & (reg_mask << bit_word_offset); +if (!bits_mask) { +/* no get bits in this register so skip to next one */ +continue ; + } + +/* compute input port offset */ + port = i / gpio_reg_size; + in_port = (port >2 ) ? port +1 : port; + +/* get input bits */ + port_state =inb (dio48egpio->base + in_port); + +/* store acquired bits */ + bits[BIT_WORD (i)] |= port_state << bit_word_offset; + } + +return 0 ; +} +static void dio48e_gpio_set (struct gpio_chip *chip,unsigned offset,int value) {struct dio48e_gpio *const dio48egpio =gpiochip_get_data (chip);
@@ -384,6 +424,7 @@ static int dio48e_probe(struct device *dev, unsigned int id) dio48egpio->chip.direction_input = dio48e_gpio_direction_input; dio48egpio->chip.direction_output = dio48e_gpio_direction_output; dio48egpio->chip.get = dio48e_gpio_get; + dio48egpio->chip.get_multiple = dio48e_gpio_get_multiple; dio48egpio->chip.set = dio48e_gpio_set; dio48egpio->chip.set_multiple = dio48e_gpio_set_multiple; dio48egpio->base = base[id];
Signature · 1 line
2.16.2
PATCH 6/8 gpio: 104-idi-48: Implement get_multiple callback
In reply to William Breathitt GrayThe ACCES I/O 104-IDI-48 series of devices provides 48 optically-isolated inputs accessed via six 8-bit ports. Since eight input lines are acquired on a single port input read, the 104-IDI-48 GPIO driver may improve multiple input reads by utilizing a get_multiple callback. This patch implements the idi_48_gpio_get_multiple function which serves as the respective get_multiple callback.
--- drivers/gpio/gpio-104-idi-48.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
drivers/gpio/gpio-104-idi-48.c +41 -0
@@ -88,6 +88,46 @@ static int idi_48_gpio_get(struct gpio_chip *chip, unsigned offset)return 0 ; } +static int idi_48_gpio_get_multiple (struct gpio_chip *chip,unsigned long *mask, +unsigned long *bits) +{ +struct idi_48_gpio *const idi48gpio =gpiochip_get_data (chip); +unsigned int i; +const unsigned int gpio_reg_size =8 ; +unsigned int bit_word_offset; +unsigned int bits_mask; +const unsigned long reg_mask =GENMASK (gpio_reg_size,0 ); +unsigned int port; +unsigned int in_port; +unsigned long port_state; + +/* clear bits array to a clean slate */ +for (i =0 ; i < chip->ngpio; i +=BITS_PER_LONG ) + bits[i /BITS_PER_LONG ] =0 ; + +/* get bits are evaluated a gpio register size at a time */ +for (i =0 ; i < chip->ngpio; i += gpio_reg_size) { + bit_word_offset = i %BITS_PER_LONG ; + bits_mask = mask[BIT_WORD (i)] & (reg_mask << bit_word_offset); +if (!bits_mask) { +/* no get bits in this register so skip to next one */ +continue ; + } + +/* compute input port offset */ + port = i / gpio_reg_size; + in_port = (port >2 ) ? port +1 : port; + +/* get input bits */ + port_state =inb (idi48gpio->base + in_port); + +/* store acquired bits */ + bits[BIT_WORD (i)] |= port_state << bit_word_offset; + } + +return 0 ; +} +static void idi_48_irq_ack (struct irq_data *data) { }
@@ -256,6 +296,7 @@ static int idi_48_probe(struct device *dev, unsigned int id) idi48gpio->chip.get_direction = idi_48_gpio_get_direction; idi48gpio->chip.direction_input = idi_48_gpio_direction_input; idi48gpio->chip.get = idi_48_gpio_get; + idi48gpio->chip.get_multiple = idi_48_gpio_get_multiple; idi48gpio->base = base[id];raw_spin_lock_init (&idi48gpio->lock);
Signature · 1 line
2.16.2
PATCH 7/8 gpio: gpio-mm: Implement get_multiple callback
In reply to William Breathitt GrayThe Diamond Systems GPIO-MM series of devices contain two 82C55A devices, which each feature three 8-bit ports of I/O. Since eight input lines are acquired on a single port input read, the GPIO-MM GPIO driver may improve multiple input reads by utilizing a get_multiple callback. This patch implements the gpiomm_gpio_get_multiple function which serves as the respective get_multiple callback.
--- drivers/gpio/gpio-gpio-mm.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
drivers/gpio/gpio-gpio-mm.c +41 -0
@@ -171,6 +171,46 @@ static int gpiomm_gpio_get(struct gpio_chip *chip, unsigned int offset)return !!(port_state & mask); } +static int gpiomm_gpio_get_multiple (struct gpio_chip *chip,unsigned long *mask, +unsigned long *bits) +{ +struct gpiomm_gpio *const gpiommgpio =gpiochip_get_data (chip); +unsigned int i; +const unsigned int gpio_reg_size =8 ; +unsigned int bit_word_offset; +unsigned int bits_mask; +const unsigned long reg_mask =GENMASK (gpio_reg_size,0 ); +unsigned int port; +unsigned int in_port; +unsigned long port_state; + +/* clear bits array to a clean slate */ +for (i =0 ; i < chip->ngpio; i +=BITS_PER_LONG ) + bits[i /BITS_PER_LONG ] =0 ; + +/* get bits are evaluated a gpio register size at a time */ +for (i =0 ; i < chip->ngpio; i += gpio_reg_size) { + bit_word_offset = i %BITS_PER_LONG ; + bits_mask = mask[BIT_WORD (i)] & (reg_mask << bit_word_offset); +if (!bits_mask) { +/* no get bits in this register so skip to next one */ +continue ; + } + +/* compute input port offset */ + port = i / gpio_reg_size; + in_port = (port >2 ) ? port +1 : port; + +/* get input bits */ + port_state =inb (gpiommgpio->base + in_port); + +/* store acquired bits */ + bits[BIT_WORD (i)] |= port_state << bit_word_offset; + } + +return 0 ; +} +static void gpiomm_gpio_set (struct gpio_chip *chip,unsigned int offset,int value) {
@@ -268,6 +308,7 @@ static int gpiomm_probe(struct device *dev, unsigned int id) gpiommgpio->chip.direction_input = gpiomm_gpio_direction_input; gpiommgpio->chip.direction_output = gpiomm_gpio_direction_output; gpiommgpio->chip.get = gpiomm_gpio_get; + gpiommgpio->chip.get_multiple = gpiomm_gpio_get_multiple; gpiommgpio->chip.set = gpiomm_gpio_set; gpiommgpio->chip.set_multiple = gpiomm_gpio_set_multiple; gpiommgpio->base = base[id];
Signature · 1 line
2.16.2
PATCH 8/8 gpio: ws16c48: Implement get_multiple callback
In reply to William Breathitt GrayThe WinSystems WS16C48 device provides 48 lines of digital I/O accessed via six 8-bit ports. Since eight input lines are acquired on a single port input read, the WS16C48 GPIO driver may improve multiple input reads by utilizing a get_multiple callback. This patch implements the ws16c48_gpio_get_multiple function which serves as the respective get_multiple callback.
--- drivers/gpio/gpio-ws16c48.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)
drivers/gpio/gpio-ws16c48.c +39 -0
@@ -129,6 +129,44 @@ static int ws16c48_gpio_get(struct gpio_chip *chip, unsigned offset)return !!(port_state & mask); } +static int ws16c48_gpio_get_multiple (struct gpio_chip *chip, +unsigned long *mask,unsigned long *bits) +{ +struct ws16c48_gpio *const ws16c48gpio =gpiochip_get_data (chip); +unsigned int i; +const unsigned int gpio_reg_size =8 ; +unsigned int bit_word_offset; +unsigned int bits_mask; +const unsigned long reg_mask =GENMASK (gpio_reg_size,0 ); +unsigned int in_port; +unsigned long port_state; + +/* clear bits array to a clean slate */ +for (i =0 ; i < chip->ngpio; i +=BITS_PER_LONG ) + bits[i /BITS_PER_LONG ] =0 ; + +/* get bits are evaluated a gpio register size at a time */ +for (i =0 ; i < chip->ngpio; i += gpio_reg_size) { + bit_word_offset = i %BITS_PER_LONG ; + bits_mask = mask[BIT_WORD (i)] & (reg_mask << bit_word_offset); +if (!bits_mask) { +/* no get bits in this register so skip to next one */ +continue ; + } + +/* compute input port offset */ + in_port = i / gpio_reg_size; + +/* get input bits */ + port_state =inb (ws16c48gpio->base + in_port); + +/* store acquired bits */ + bits[BIT_WORD (i)] |= port_state << bit_word_offset; + } + +return 0 ; +} +static void ws16c48_gpio_set (struct gpio_chip *chip,unsigned offset,int value) {struct ws16c48_gpio *const ws16c48gpio =gpiochip_get_data (chip);
@@ -383,6 +421,7 @@ static int ws16c48_probe(struct device *dev, unsigned int id) ws16c48gpio->chip.direction_input = ws16c48_gpio_direction_input; ws16c48gpio->chip.direction_output = ws16c48_gpio_direction_output; ws16c48gpio->chip.get = ws16c48_gpio_get; + ws16c48gpio->chip.get_multiple = ws16c48_gpio_get_multiple; ws16c48gpio->chip.set = ws16c48_gpio_set; ws16c48gpio->chip.set_multiple = ws16c48_gpio_set_multiple; ws16c48gpio->base = base[id];
Signature · 1 line
2.16.2
Re: [PATCH 8/8] gpio: ws16c48: Implement get_multiple callback
On Mon, Mar 12, 2018 at 10:50 PM, William Breathitt Gray <[email protected]> wrote:
For all your patches, just read the bitmap API.
Signature · 2 lines
With Best Regards, Andy Shevchenko