hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/gpio/gpio-max3191x.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * gpio-max3191x.c - GPIO driver for Maxim MAX3191x industrial serializer
34 *
....@@ -27,13 +28,10 @@
2728 * https://datasheets.maximintegrated.com/en/ds/MAX31912.pdf
2829 * https://datasheets.maximintegrated.com/en/ds/MAX31913.pdf
2930 * https://datasheets.maximintegrated.com/en/ds/MAX31953-MAX31963.pdf
30
- *
31
- * This program is free software; you can redistribute it and/or modify
32
- * it under the terms of the GNU General Public License (version 2) as
33
- * published by the Free Software Foundation.
3431 */
3532
3633 #include <linux/bitmap.h>
34
+#include <linux/bitops.h>
3735 #include <linux/crc8.h>
3836 #include <linux/gpio/consumer.h>
3937 #include <linux/gpio/driver.h>
....@@ -97,7 +95,7 @@
9795
9896 static int max3191x_get_direction(struct gpio_chip *gpio, unsigned int offset)
9997 {
100
- return 1; /* always in */
98
+ return GPIO_LINE_DIRECTION_IN; /* always in */
10199 }
102100
103101 static int max3191x_direction_input(struct gpio_chip *gpio, unsigned int offset)
....@@ -235,16 +233,20 @@
235233 unsigned long *bits)
236234 {
237235 struct max3191x_chip *max3191x = gpiochip_get_data(gpio);
238
- int ret, bit = 0, wordlen = max3191x_wordlen(max3191x);
236
+ const unsigned int wordlen = max3191x_wordlen(max3191x);
237
+ int ret;
238
+ unsigned long bit;
239
+ unsigned long gpio_mask;
240
+ unsigned long in;
239241
240242 mutex_lock(&max3191x->lock);
241243 ret = max3191x_readout_locked(max3191x);
242244 if (ret)
243245 goto out_unlock;
244246
245
- while ((bit = find_next_bit(mask, gpio->ngpio, bit)) != gpio->ngpio) {
247
+ bitmap_zero(bits, gpio->ngpio);
248
+ for_each_set_clump8(bit, gpio_mask, mask, gpio->ngpio) {
246249 unsigned int chipnum = bit / MAX3191X_NGPIO;
247
- unsigned long in, shift, index;
248250
249251 if (max3191x_chip_is_faulting(max3191x, chipnum)) {
250252 ret = -EIO;
....@@ -252,12 +254,8 @@
252254 }
253255
254256 in = ((u8 *)max3191x->xfer.rx_buf)[chipnum * wordlen];
255
- shift = round_down(bit % BITS_PER_LONG, MAX3191X_NGPIO);
256
- index = bit / BITS_PER_LONG;
257
- bits[index] &= ~(mask[index] & (0xff << shift));
258
- bits[index] |= mask[index] & (in << shift); /* copy bits */
259
-
260
- bit = (chipnum + 1) * MAX3191X_NGPIO; /* go to next chip */
257
+ in &= gpio_mask;
258
+ bitmap_set_value8(bits, in, bit);
261259 }
262260
263261 out_unlock:
....@@ -313,18 +311,21 @@
313311
314312 static void gpiod_set_array_single_value_cansleep(unsigned int ndescs,
315313 struct gpio_desc **desc,
314
+ struct gpio_array *info,
316315 int value)
317316 {
318
- int i, *values;
317
+ unsigned long *values;
319318
320
- values = kmalloc_array(ndescs, sizeof(*values), GFP_KERNEL);
319
+ values = bitmap_alloc(ndescs, GFP_KERNEL);
321320 if (!values)
322321 return;
323322
324
- for (i = 0; i < ndescs; i++)
325
- values[i] = value;
323
+ if (value)
324
+ bitmap_fill(values, ndescs);
325
+ else
326
+ bitmap_zero(values, ndescs);
326327
327
- gpiod_set_array_value_cansleep(ndescs, desc, values);
328
+ gpiod_set_array_value_cansleep(ndescs, desc, info, values);
328329 kfree(values);
329330 }
330331
....@@ -397,7 +398,8 @@
397398 if (max3191x->modesel_pins)
398399 gpiod_set_array_single_value_cansleep(
399400 max3191x->modesel_pins->ndescs,
400
- max3191x->modesel_pins->desc, max3191x->mode);
401
+ max3191x->modesel_pins->desc,
402
+ max3191x->modesel_pins->info, max3191x->mode);
401403
402404 max3191x->ignore_uv = device_property_read_bool(dev,
403405 "maxim,ignore-undervoltage");