hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/gpio/gpio-74x164.c
....@@ -1,21 +1,19 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * 74Hx164 - Generic serial-in/parallel-out 8-bits shift register GPIO driver
34 *
45 * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
56 * Copyright (C) 2010 Miguel Gaio <miguel.gaio@efixo.com>
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License version 2 as
9
- * published by the Free Software Foundation.
107 */
118
12
-#include <linux/init.h>
13
-#include <linux/mutex.h>
14
-#include <linux/spi/spi.h>
15
-#include <linux/gpio/driver.h>
9
+#include <linux/bitops.h>
1610 #include <linux/gpio/consumer.h>
17
-#include <linux/slab.h>
11
+#include <linux/gpio/driver.h>
1812 #include <linux/module.h>
13
+#include <linux/mutex.h>
14
+#include <linux/property.h>
15
+#include <linux/slab.h>
16
+#include <linux/spi/spi.h>
1917
2018 #define GEN_74X164_NUMBER_GPIOS 8
2119
....@@ -75,20 +73,18 @@
7573 unsigned long *bits)
7674 {
7775 struct gen_74x164_chip *chip = gpiochip_get_data(gc);
78
- unsigned int i, idx, shift;
79
- u8 bank, bankmask;
76
+ unsigned long offset;
77
+ unsigned long bankmask;
78
+ size_t bank;
79
+ unsigned long bitmask;
8080
8181 mutex_lock(&chip->lock);
82
- for (i = 0, bank = chip->registers - 1; i < chip->registers;
83
- i++, bank--) {
84
- idx = i / sizeof(*mask);
85
- shift = i % sizeof(*mask) * BITS_PER_BYTE;
86
- bankmask = mask[idx] >> shift;
87
- if (!bankmask)
88
- continue;
82
+ for_each_set_clump8(offset, bankmask, mask, chip->registers * 8) {
83
+ bank = chip->registers - 1 - offset / 8;
84
+ bitmask = bitmap_get_value8(bits, offset) & bankmask;
8985
9086 chip->buffer[bank] &= ~bankmask;
91
- chip->buffer[bank] |= bankmask & (bits[idx] >> shift);
87
+ chip->buffer[bank] |= bitmask;
9288 }
9389 __gen_74x164_write_config(chip);
9490 mutex_unlock(&chip->lock);
....@@ -116,10 +112,9 @@
116112 if (ret < 0)
117113 return ret;
118114
119
- if (of_property_read_u32(spi->dev.of_node, "registers-number",
120
- &nregs)) {
121
- dev_err(&spi->dev,
122
- "Missing registers-number property in the DT.\n");
115
+ ret = device_property_read_u32(&spi->dev, "registers-number", &nregs);
116
+ if (ret) {
117
+ dev_err(&spi->dev, "Missing 'registers-number' property.\n");
123118 return -EINVAL;
124119 }
125120