.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * 74Hx164 - Generic serial-in/parallel-out 8-bits shift register GPIO driver |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org> |
---|
5 | 6 | * 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. |
---|
10 | 7 | */ |
---|
11 | 8 | |
---|
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> |
---|
16 | 10 | #include <linux/gpio/consumer.h> |
---|
17 | | -#include <linux/slab.h> |
---|
| 11 | +#include <linux/gpio/driver.h> |
---|
18 | 12 | #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> |
---|
19 | 17 | |
---|
20 | 18 | #define GEN_74X164_NUMBER_GPIOS 8 |
---|
21 | 19 | |
---|
.. | .. |
---|
75 | 73 | unsigned long *bits) |
---|
76 | 74 | { |
---|
77 | 75 | 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; |
---|
80 | 80 | |
---|
81 | 81 | 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; |
---|
89 | 85 | |
---|
90 | 86 | chip->buffer[bank] &= ~bankmask; |
---|
91 | | - chip->buffer[bank] |= bankmask & (bits[idx] >> shift); |
---|
| 87 | + chip->buffer[bank] |= bitmask; |
---|
92 | 88 | } |
---|
93 | 89 | __gen_74x164_write_config(chip); |
---|
94 | 90 | mutex_unlock(&chip->lock); |
---|
.. | .. |
---|
116 | 112 | if (ret < 0) |
---|
117 | 113 | return ret; |
---|
118 | 114 | |
---|
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"); |
---|
123 | 118 | return -EINVAL; |
---|
124 | 119 | } |
---|
125 | 120 | |
---|