Lines Matching +full:lock +full:- +full:offset
1 // SPDX-License-Identifier: GPL-2.0-only
3 * 74Hx164 - Generic serial-in/parallel-out 8-bits shift register GPIO driver
22 struct mutex lock; member
37 return spi_write(to_spi_device(chip->gpio_chip.parent), chip->buffer, in __gen_74x164_write_config()
38 chip->registers); in __gen_74x164_write_config()
41 static int gen_74x164_get_value(struct gpio_chip *gc, unsigned offset) in gen_74x164_get_value() argument
44 u8 bank = chip->registers - 1 - offset / 8; in gen_74x164_get_value()
45 u8 pin = offset % 8; in gen_74x164_get_value()
48 mutex_lock(&chip->lock); in gen_74x164_get_value()
49 ret = (chip->buffer[bank] >> pin) & 0x1; in gen_74x164_get_value()
50 mutex_unlock(&chip->lock); in gen_74x164_get_value()
56 unsigned offset, int val) in gen_74x164_set_value() argument
59 u8 bank = chip->registers - 1 - offset / 8; in gen_74x164_set_value()
60 u8 pin = offset % 8; in gen_74x164_set_value()
62 mutex_lock(&chip->lock); in gen_74x164_set_value()
64 chip->buffer[bank] |= (1 << pin); in gen_74x164_set_value()
66 chip->buffer[bank] &= ~(1 << pin); in gen_74x164_set_value()
69 mutex_unlock(&chip->lock); in gen_74x164_set_value()
76 unsigned long offset; in gen_74x164_set_multiple() local
81 mutex_lock(&chip->lock); in gen_74x164_set_multiple()
82 for_each_set_clump8(offset, bankmask, mask, chip->registers * 8) { in gen_74x164_set_multiple()
83 bank = chip->registers - 1 - offset / 8; in gen_74x164_set_multiple()
84 bitmask = bitmap_get_value8(bits, offset) & bankmask; in gen_74x164_set_multiple()
86 chip->buffer[bank] &= ~bankmask; in gen_74x164_set_multiple()
87 chip->buffer[bank] |= bitmask; in gen_74x164_set_multiple()
90 mutex_unlock(&chip->lock); in gen_74x164_set_multiple()
94 unsigned offset, int val) in gen_74x164_direction_output() argument
96 gen_74x164_set_value(gc, offset, val); in gen_74x164_direction_output()
109 spi->bits_per_word = 8; in gen_74x164_probe()
115 ret = device_property_read_u32(&spi->dev, "registers-number", &nregs); in gen_74x164_probe()
117 dev_err(&spi->dev, "Missing 'registers-number' property.\n"); in gen_74x164_probe()
118 return -EINVAL; in gen_74x164_probe()
121 chip = devm_kzalloc(&spi->dev, sizeof(*chip) + nregs, GFP_KERNEL); in gen_74x164_probe()
123 return -ENOMEM; in gen_74x164_probe()
125 chip->gpiod_oe = devm_gpiod_get_optional(&spi->dev, "enable", in gen_74x164_probe()
127 if (IS_ERR(chip->gpiod_oe)) in gen_74x164_probe()
128 return PTR_ERR(chip->gpiod_oe); in gen_74x164_probe()
132 chip->gpio_chip.label = spi->modalias; in gen_74x164_probe()
133 chip->gpio_chip.direction_output = gen_74x164_direction_output; in gen_74x164_probe()
134 chip->gpio_chip.get = gen_74x164_get_value; in gen_74x164_probe()
135 chip->gpio_chip.set = gen_74x164_set_value; in gen_74x164_probe()
136 chip->gpio_chip.set_multiple = gen_74x164_set_multiple; in gen_74x164_probe()
137 chip->gpio_chip.base = -1; in gen_74x164_probe()
139 chip->registers = nregs; in gen_74x164_probe()
140 chip->gpio_chip.ngpio = GEN_74X164_NUMBER_GPIOS * chip->registers; in gen_74x164_probe()
142 chip->gpio_chip.can_sleep = true; in gen_74x164_probe()
143 chip->gpio_chip.parent = &spi->dev; in gen_74x164_probe()
144 chip->gpio_chip.owner = THIS_MODULE; in gen_74x164_probe()
146 mutex_init(&chip->lock); in gen_74x164_probe()
150 dev_err(&spi->dev, "Failed writing: %d\n", ret); in gen_74x164_probe()
154 gpiod_set_value_cansleep(chip->gpiod_oe, 1); in gen_74x164_probe()
156 ret = gpiochip_add_data(&chip->gpio_chip, chip); in gen_74x164_probe()
161 mutex_destroy(&chip->lock); in gen_74x164_probe()
170 gpiod_set_value_cansleep(chip->gpiod_oe, 0); in gen_74x164_remove()
171 gpiochip_remove(&chip->gpio_chip); in gen_74x164_remove()
172 mutex_destroy(&chip->lock); in gen_74x164_remove()
202 MODULE_DESCRIPTION("GPIO expander driver for 74X164 8-bits shift register");