Lines Matching +full:gpio +full:- +full:dir
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Driver for the Diolan DLN-2 USB-GPIO adapter
15 #include <linux/gpio/driver.h>
48 struct gpio_chip gpio; member
56 /* active IRQs - not synced to hardware */
58 /* active IRQS - synced to hardware */
83 return -EPROTO; in dln2_gpio_get_pin_count()
94 return dln2_transfer_tx(dln2->pdev, cmd, &req, sizeof(req)); in dln2_gpio_pin_cmd()
106 ret = dln2_transfer(dln2->pdev, cmd, &req, sizeof(req), &rsp, &len); in dln2_gpio_pin_val()
110 return -EPROTO; in dln2_gpio_pin_val()
143 return dln2_transfer_tx(dln2->pdev, DLN2_GPIO_PIN_SET_OUT_VAL, &req, in dln2_gpio_pin_set_out_val()
165 ret = dln2_transfer(dln2->pdev, DLN2_GPIO_PIN_GET_DIRECTION, in dln2_gpio_request()
170 ret = -EPROTO; in dln2_gpio_request()
176 clear_bit(offset, dln2->output_enabled); in dln2_gpio_request()
179 set_bit(offset, dln2->output_enabled); in dln2_gpio_request()
182 ret = -EPROTO; in dln2_gpio_request()
202 if (test_bit(offset, dln2->output_enabled)) in dln2_gpio_get_direction()
211 int dir; in dln2_gpio_get() local
213 dir = dln2_gpio_get_direction(chip, offset); in dln2_gpio_get()
214 if (dir < 0) in dln2_gpio_get()
215 return dir; in dln2_gpio_get()
217 if (dir == GPIO_LINE_DIRECTION_IN) in dln2_gpio_get()
231 unsigned dir) in dln2_gpio_set_direction() argument
236 .value = dir, in dln2_gpio_set_direction()
240 ret = dln2_transfer_tx(dln2->pdev, DLN2_GPIO_PIN_SET_DIRECTION, in dln2_gpio_set_direction()
245 if (dir == DLN2_GPIO_DIRECTION_OUT) in dln2_gpio_set_direction()
246 set_bit(offset, dln2->output_enabled); in dln2_gpio_set_direction()
248 clear_bit(offset, dln2->output_enabled); in dln2_gpio_set_direction()
278 return -ENOTSUPP; in dln2_gpio_set_config()
281 return dln2_transfer_tx(dln2->pdev, DLN2_GPIO_SET_DEBOUNCE, in dln2_gpio_set_config()
298 return dln2_transfer_tx(dln2->pdev, DLN2_GPIO_PIN_SET_EVENT_CFG, in dln2_gpio_set_event_cfg()
309 set_bit(pin, dln2->unmasked_irqs); in dln2_irq_unmask()
318 clear_bit(pin, dln2->unmasked_irqs); in dln2_irq_mask()
330 dln2->irq_type[pin] = DLN2_GPIO_EVENT_LVL_HIGH; in dln2_irq_set_type()
333 dln2->irq_type[pin] = DLN2_GPIO_EVENT_LVL_LOW; in dln2_irq_set_type()
336 dln2->irq_type[pin] = DLN2_GPIO_EVENT_CHANGE; in dln2_irq_set_type()
339 dln2->irq_type[pin] = DLN2_GPIO_EVENT_CHANGE_RISING; in dln2_irq_set_type()
342 dln2->irq_type[pin] = DLN2_GPIO_EVENT_CHANGE_FALLING; in dln2_irq_set_type()
345 return -EINVAL; in dln2_irq_set_type()
356 mutex_lock(&dln2->irq_lock); in dln2_irq_bus_lock()
368 enabled = test_bit(pin, dln2->enabled_irqs); in dln2_irq_bus_unlock()
369 unmasked = test_bit(pin, dln2->unmasked_irqs); in dln2_irq_bus_unlock()
373 type = dln2->irq_type[pin] & DLN2_GPIO_EVENT_MASK; in dln2_irq_bus_unlock()
374 set_bit(pin, dln2->enabled_irqs); in dln2_irq_bus_unlock()
377 clear_bit(pin, dln2->enabled_irqs); in dln2_irq_bus_unlock()
382 dev_err(dln2->gpio.parent, "failed to set event\n"); in dln2_irq_bus_unlock()
385 mutex_unlock(&dln2->irq_lock); in dln2_irq_bus_unlock()
389 .name = "dln2-irq",
413 dev_err(dln2->gpio.parent, "short event message\n"); in dln2_gpio_event()
417 pin = le16_to_cpu(event->pin); in dln2_gpio_event()
418 if (pin >= dln2->gpio.ngpio) { in dln2_gpio_event()
419 dev_err(dln2->gpio.parent, "out of bounds pin %d\n", pin); in dln2_gpio_event()
423 switch (dln2->irq_type[pin]) { in dln2_gpio_event()
425 if (!event->value) in dln2_gpio_event()
429 if (event->value) in dln2_gpio_event()
434 ret = generic_handle_domain_irq(dln2->gpio.irq.domain, pin); in dln2_gpio_event()
436 dev_err(dln2->gpio.parent, "pin %d not mapped to IRQ\n", pin); in dln2_gpio_event()
442 struct device *dev = &pdev->dev; in dln2_gpio_probe()
457 dln2 = devm_kzalloc(&pdev->dev, sizeof(*dln2), GFP_KERNEL); in dln2_gpio_probe()
459 return -ENOMEM; in dln2_gpio_probe()
461 mutex_init(&dln2->irq_lock); in dln2_gpio_probe()
463 dln2->pdev = pdev; in dln2_gpio_probe()
465 dln2->gpio.label = "dln2"; in dln2_gpio_probe()
466 dln2->gpio.parent = dev; in dln2_gpio_probe()
467 dln2->gpio.owner = THIS_MODULE; in dln2_gpio_probe()
468 dln2->gpio.base = -1; in dln2_gpio_probe()
469 dln2->gpio.ngpio = pins; in dln2_gpio_probe()
470 dln2->gpio.can_sleep = true; in dln2_gpio_probe()
471 dln2->gpio.set = dln2_gpio_set; in dln2_gpio_probe()
472 dln2->gpio.get = dln2_gpio_get; in dln2_gpio_probe()
473 dln2->gpio.request = dln2_gpio_request; in dln2_gpio_probe()
474 dln2->gpio.free = dln2_gpio_free; in dln2_gpio_probe()
475 dln2->gpio.get_direction = dln2_gpio_get_direction; in dln2_gpio_probe()
476 dln2->gpio.direction_input = dln2_gpio_direction_input; in dln2_gpio_probe()
477 dln2->gpio.direction_output = dln2_gpio_direction_output; in dln2_gpio_probe()
478 dln2->gpio.set_config = dln2_gpio_set_config; in dln2_gpio_probe()
480 girq = &dln2->gpio.irq; in dln2_gpio_probe()
483 girq->parent_handler = NULL; in dln2_gpio_probe()
484 girq->num_parents = 0; in dln2_gpio_probe()
485 girq->parents = NULL; in dln2_gpio_probe()
486 girq->default_type = IRQ_TYPE_NONE; in dln2_gpio_probe()
487 girq->handler = handle_simple_irq; in dln2_gpio_probe()
491 ret = devm_gpiochip_add_data(dev, &dln2->gpio, dln2); in dln2_gpio_probe()
493 dev_err(dev, "failed to add gpio chip: %d\n", ret); in dln2_gpio_probe()
513 .driver.name = "dln2-gpio",
521 MODULE_DESCRIPTION("Driver for the Diolan DLN2 GPIO interface");
523 MODULE_ALIAS("platform:dln2-gpio");