Lines Matching +full:a +full:- +full:gpio

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Driver for pcf857x, pca857x, and pca967x I2C GPIO expanders
8 #include <linux/gpio/driver.h>
58 * write register. Writing a "one" bit (to match the reset state) lets
59 * that pin be used as an input; it's not an open-drain model, but acts
60 * a bit like one. This is described as "quasi-bidirectional"; read the
63 * Many other I2C GPIO expander chips (like the pca953x models) have
80 /*-------------------------------------------------------------------------*/
82 /* Talk to 8-bit I/O expander */
94 /* Talk to 16-bit I/O expander */
116 /*-------------------------------------------------------------------------*/
120 struct pcf857x *gpio = gpiochip_get_data(chip); in pcf857x_input() local
123 mutex_lock(&gpio->lock); in pcf857x_input()
124 gpio->out |= (1 << offset); in pcf857x_input()
125 status = gpio->write(gpio->client, gpio->out); in pcf857x_input()
126 mutex_unlock(&gpio->lock); in pcf857x_input()
133 struct pcf857x *gpio = gpiochip_get_data(chip); in pcf857x_get() local
136 value = gpio->read(gpio->client); in pcf857x_get()
143 struct pcf857x *gpio = gpiochip_get_data(chip); in pcf857x_get_multiple() local
144 int value = gpio->read(gpio->client); in pcf857x_get_multiple()
157 struct pcf857x *gpio = gpiochip_get_data(chip); in pcf857x_output() local
161 mutex_lock(&gpio->lock); in pcf857x_output()
163 gpio->out |= bit; in pcf857x_output()
165 gpio->out &= ~bit; in pcf857x_output()
166 status = gpio->write(gpio->client, gpio->out); in pcf857x_output()
167 mutex_unlock(&gpio->lock); in pcf857x_output()
180 struct pcf857x *gpio = gpiochip_get_data(chip); in pcf857x_set_multiple() local
182 mutex_lock(&gpio->lock); in pcf857x_set_multiple()
183 gpio->out &= ~*mask; in pcf857x_set_multiple()
184 gpio->out |= *bits & *mask; in pcf857x_set_multiple()
185 gpio->write(gpio->client, gpio->out); in pcf857x_set_multiple()
186 mutex_unlock(&gpio->lock); in pcf857x_set_multiple()
189 /*-------------------------------------------------------------------------*/
193 struct pcf857x *gpio = data; in pcf857x_irq() local
196 status = gpio->read(gpio->client); in pcf857x_irq()
199 * call the interrupt handler iff gpio is used as in pcf857x_irq()
202 mutex_lock(&gpio->lock); in pcf857x_irq()
203 change = (gpio->status ^ status) & gpio->irq_enabled; in pcf857x_irq()
204 gpio->status = status; in pcf857x_irq()
205 mutex_unlock(&gpio->lock); in pcf857x_irq()
207 for_each_set_bit(i, &change, gpio->chip.ngpio) in pcf857x_irq()
208 handle_nested_irq(irq_find_mapping(gpio->chip.irq.domain, i)); in pcf857x_irq()
220 struct pcf857x *gpio = irq_data_get_irq_chip_data(data); in pcf857x_irq_set_wake() local
222 return irq_set_irq_wake(gpio->client->irq, on); in pcf857x_irq_set_wake()
227 struct pcf857x *gpio = irq_data_get_irq_chip_data(data); in pcf857x_irq_enable() local
230 gpiochip_enable_irq(&gpio->chip, hwirq); in pcf857x_irq_enable()
231 gpio->irq_enabled |= (1 << hwirq); in pcf857x_irq_enable()
236 struct pcf857x *gpio = irq_data_get_irq_chip_data(data); in pcf857x_irq_disable() local
239 gpio->irq_enabled &= ~(1 << hwirq); in pcf857x_irq_disable()
240 gpiochip_disable_irq(&gpio->chip, hwirq); in pcf857x_irq_disable()
245 struct pcf857x *gpio = irq_data_get_irq_chip_data(data); in pcf857x_irq_bus_lock() local
247 mutex_lock(&gpio->lock); in pcf857x_irq_bus_lock()
252 struct pcf857x *gpio = irq_data_get_irq_chip_data(data); in pcf857x_irq_bus_sync_unlock() local
254 mutex_unlock(&gpio->lock); in pcf857x_irq_bus_sync_unlock()
271 /*-------------------------------------------------------------------------*/
275 struct pcf857x *gpio; in pcf857x_probe() local
279 device_property_read_u32(&client->dev, "lines-initial-states", &n_latch); in pcf857x_probe()
282 gpio = devm_kzalloc(&client->dev, sizeof(*gpio), GFP_KERNEL); in pcf857x_probe()
283 if (!gpio) in pcf857x_probe()
284 return -ENOMEM; in pcf857x_probe()
286 mutex_init(&gpio->lock); in pcf857x_probe()
288 gpio->chip.base = -1; in pcf857x_probe()
289 gpio->chip.can_sleep = true; in pcf857x_probe()
290 gpio->chip.parent = &client->dev; in pcf857x_probe()
291 gpio->chip.owner = THIS_MODULE; in pcf857x_probe()
292 gpio->chip.get = pcf857x_get; in pcf857x_probe()
293 gpio->chip.get_multiple = pcf857x_get_multiple; in pcf857x_probe()
294 gpio->chip.set = pcf857x_set; in pcf857x_probe()
295 gpio->chip.set_multiple = pcf857x_set_multiple; in pcf857x_probe()
296 gpio->chip.direction_input = pcf857x_input; in pcf857x_probe()
297 gpio->chip.direction_output = pcf857x_output; in pcf857x_probe()
298 gpio->chip.ngpio = (uintptr_t)i2c_get_match_data(client); in pcf857x_probe()
301 * these parts, notably for output. It has a low-resolution in pcf857x_probe()
306 /* 8574 addresses are 0x20..0x27; 8574a uses 0x38..0x3f; in pcf857x_probe()
307 * 9670, 9672, 9764, and 9764a use quite a variety. in pcf857x_probe()
309 * NOTE: we don't distinguish here between *4 and *4a parts. in pcf857x_probe()
311 if (gpio->chip.ngpio == 8) { in pcf857x_probe()
312 gpio->write = i2c_write_le8; in pcf857x_probe()
313 gpio->read = i2c_read_le8; in pcf857x_probe()
315 if (!i2c_check_functionality(client->adapter, in pcf857x_probe()
317 status = -EIO; in pcf857x_probe()
324 * the '75c doesn't have a current source pulling high. in pcf857x_probe()
325 * 9671, 9673, and 9765 use quite a variety of addresses. in pcf857x_probe()
329 } else if (gpio->chip.ngpio == 16) { in pcf857x_probe()
330 gpio->write = i2c_write_le16; in pcf857x_probe()
331 gpio->read = i2c_read_le16; in pcf857x_probe()
333 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) in pcf857x_probe()
334 status = -EIO; in pcf857x_probe()
341 dev_dbg(&client->dev, "unsupported number of gpios\n"); in pcf857x_probe()
342 status = -EINVAL; in pcf857x_probe()
348 gpio->chip.label = client->name; in pcf857x_probe()
350 gpio->client = client; in pcf857x_probe()
351 i2c_set_clientdata(client, gpio); in pcf857x_probe()
353 /* NOTE: these chips have strange "quasi-bidirectional" I/O pins. in pcf857x_probe()
354 * We can't actually know whether a pin is configured (a) as output in pcf857x_probe()
355 * and driving the signal low, or (b) as input and reporting a low in pcf857x_probe()
365 * our software copy of the "latch" then matches the chip's all-ones in pcf857x_probe()
368 gpio->out = ~n_latch; in pcf857x_probe()
369 gpio->status = gpio->read(gpio->client); in pcf857x_probe()
372 if (client->irq) { in pcf857x_probe()
375 status = devm_request_threaded_irq(&client->dev, client->irq, in pcf857x_probe()
378 dev_name(&client->dev), gpio); in pcf857x_probe()
382 girq = &gpio->chip.irq; in pcf857x_probe()
385 girq->parent_handler = NULL; in pcf857x_probe()
386 girq->num_parents = 0; in pcf857x_probe()
387 girq->parents = NULL; in pcf857x_probe()
388 girq->default_type = IRQ_TYPE_NONE; in pcf857x_probe()
389 girq->handler = handle_level_irq; in pcf857x_probe()
390 girq->threaded = true; in pcf857x_probe()
393 status = devm_gpiochip_add_data(&client->dev, &gpio->chip, gpio); in pcf857x_probe()
397 dev_info(&client->dev, "probed\n"); in pcf857x_probe()
402 dev_dbg(&client->dev, "probe error %d for '%s'\n", status, in pcf857x_probe()
403 client->name); in pcf857x_probe()
410 struct pcf857x *gpio = i2c_get_clientdata(client); in pcf857x_shutdown() local
413 gpio->write(gpio->client, BIT(gpio->chip.ngpio) - 1); in pcf857x_shutdown()
441 MODULE_DESCRIPTION("Driver for pcf857x, pca857x, and pca967x I2C GPIO expanders");