Lines Matching +full:quasi +full:- +full:bidirectional

1 // SPDX-License-Identifier: GPL-2.0-or-later
63 * that pin be used as an input; it's not an open-drain model, but acts
64 * a bit like one. This is described as "quasi-bidirectional"; read the
84 /*-------------------------------------------------------------------------*/
86 /* Talk to 8-bit I/O expander */
98 /* Talk to 16-bit I/O expander */
120 /*-------------------------------------------------------------------------*/
127 mutex_lock(&gpio->lock); in pcf857x_input()
128 gpio->out |= (1 << offset); in pcf857x_input()
129 status = gpio->write(gpio->client, gpio->out); in pcf857x_input()
130 mutex_unlock(&gpio->lock); in pcf857x_input()
140 value = gpio->read(gpio->client); in pcf857x_get()
150 mutex_lock(&gpio->lock); in pcf857x_output()
152 gpio->out |= bit; in pcf857x_output()
154 gpio->out &= ~bit; in pcf857x_output()
155 status = gpio->write(gpio->client, gpio->out); in pcf857x_output()
156 mutex_unlock(&gpio->lock); in pcf857x_output()
166 /*-------------------------------------------------------------------------*/
173 status = gpio->read(gpio->client); in pcf857x_irq()
179 mutex_lock(&gpio->lock); in pcf857x_irq()
180 change = (gpio->status ^ status) & gpio->irq_enabled; in pcf857x_irq()
181 gpio->status = status; in pcf857x_irq()
182 mutex_unlock(&gpio->lock); in pcf857x_irq()
184 for_each_set_bit(i, &change, gpio->chip.ngpio) in pcf857x_irq()
185 handle_nested_irq(irq_find_mapping(gpio->chip.irq.domain, i)); in pcf857x_irq()
199 return irq_set_irq_wake(gpio->client->irq, on); in pcf857x_irq_set_wake()
207 gpiochip_enable_irq(&gpio->chip, hwirq); in pcf857x_irq_enable()
208 gpio->irq_enabled |= (1 << hwirq); in pcf857x_irq_enable()
216 gpio->irq_enabled &= ~(1 << hwirq); in pcf857x_irq_disable()
217 gpiochip_disable_irq(&gpio->chip, hwirq); in pcf857x_irq_disable()
224 mutex_lock(&gpio->lock); in pcf857x_irq_bus_lock()
231 mutex_unlock(&gpio->lock); in pcf857x_irq_bus_sync_unlock()
248 /*-------------------------------------------------------------------------*/
253 struct pcf857x_platform_data *pdata = dev_get_platdata(&client->dev); in pcf857x_probe()
254 struct device_node *np = client->dev.of_node; in pcf857x_probe()
260 of_property_read_u32(np, "lines-initial-states", &n_latch); in pcf857x_probe()
262 n_latch = pdata->n_latch; in pcf857x_probe()
264 dev_dbg(&client->dev, "no platform data\n"); in pcf857x_probe()
267 gpio = devm_kzalloc(&client->dev, sizeof(*gpio), GFP_KERNEL); in pcf857x_probe()
269 return -ENOMEM; in pcf857x_probe()
271 mutex_init(&gpio->lock); in pcf857x_probe()
273 gpio->chip.base = pdata ? pdata->gpio_base : -1; in pcf857x_probe()
274 gpio->chip.can_sleep = true; in pcf857x_probe()
275 gpio->chip.parent = &client->dev; in pcf857x_probe()
276 gpio->chip.owner = THIS_MODULE; in pcf857x_probe()
277 gpio->chip.get = pcf857x_get; in pcf857x_probe()
278 gpio->chip.set = pcf857x_set; in pcf857x_probe()
279 gpio->chip.direction_input = pcf857x_input; in pcf857x_probe()
280 gpio->chip.direction_output = pcf857x_output; in pcf857x_probe()
281 gpio->chip.ngpio = id->driver_data; in pcf857x_probe()
284 * these parts, notably for output. It has a low-resolution in pcf857x_probe()
294 if (gpio->chip.ngpio == 8) { in pcf857x_probe()
295 gpio->write = i2c_write_le8; in pcf857x_probe()
296 gpio->read = i2c_read_le8; in pcf857x_probe()
298 if (!i2c_check_functionality(client->adapter, in pcf857x_probe()
300 status = -EIO; in pcf857x_probe()
312 } else if (gpio->chip.ngpio == 16) { in pcf857x_probe()
313 gpio->write = i2c_write_le16; in pcf857x_probe()
314 gpio->read = i2c_read_le16; in pcf857x_probe()
316 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) in pcf857x_probe()
317 status = -EIO; in pcf857x_probe()
324 dev_dbg(&client->dev, "unsupported number of gpios\n"); in pcf857x_probe()
325 status = -EINVAL; in pcf857x_probe()
331 gpio->chip.label = client->name; in pcf857x_probe()
333 gpio->client = client; in pcf857x_probe()
336 /* NOTE: these chips have strange "quasi-bidirectional" I/O pins. in pcf857x_probe()
348 * our software copy of the "latch" then matches the chip's all-ones in pcf857x_probe()
351 gpio->out = ~n_latch; in pcf857x_probe()
352 gpio->status = gpio->read(gpio->client); in pcf857x_probe()
355 if (client->irq) { in pcf857x_probe()
358 status = devm_request_threaded_irq(&client->dev, client->irq, in pcf857x_probe()
361 dev_name(&client->dev), gpio); in pcf857x_probe()
365 girq = &gpio->chip.irq; in pcf857x_probe()
368 girq->parent_handler = NULL; in pcf857x_probe()
369 girq->num_parents = 0; in pcf857x_probe()
370 girq->parents = NULL; in pcf857x_probe()
371 girq->default_type = IRQ_TYPE_NONE; in pcf857x_probe()
372 girq->handler = handle_level_irq; in pcf857x_probe()
373 girq->threaded = true; in pcf857x_probe()
376 status = devm_gpiochip_add_data(&client->dev, &gpio->chip, gpio); in pcf857x_probe()
383 if (pdata && pdata->setup) { in pcf857x_probe()
384 status = pdata->setup(client, in pcf857x_probe()
385 gpio->chip.base, gpio->chip.ngpio, in pcf857x_probe()
386 pdata->context); in pcf857x_probe()
388 dev_warn(&client->dev, "setup --> %d\n", status); in pcf857x_probe()
391 dev_info(&client->dev, "probed\n"); in pcf857x_probe()
396 dev_dbg(&client->dev, "probe error %d for '%s'\n", status, in pcf857x_probe()
397 client->name); in pcf857x_probe()
404 struct pcf857x_platform_data *pdata = dev_get_platdata(&client->dev); in pcf857x_remove()
407 if (pdata && pdata->teardown) in pcf857x_remove()
408 pdata->teardown(client, gpio->chip.base, gpio->chip.ngpio, in pcf857x_remove()
409 pdata->context); in pcf857x_remove()
417 gpio->write(gpio->client, BIT(gpio->chip.ngpio) - 1); in pcf857x_shutdown()