Lines Matching +full:output +full:- +full:ngpios
1 // SPDX-License-Identifier: GPL-2.0-only
5 // Copyright (C) 2019-2020 Glider bv
7 #define DRV_NAME "gpio-aggregator"
50 lookups = krealloc(aggr->lookups, struct_size(lookups, table, *n + 2), in aggr_add_gpio()
53 return -ENOMEM; in aggr_add_gpio()
55 lookups->table[*n] = GPIO_LOOKUP_IDX(key, hwnum, NULL, *n, 0); in aggr_add_gpio()
58 memset(&lookups->table[*n], 0, sizeof(lookups->table[*n])); in aggr_add_gpio()
60 aggr->lookups = lookups; in aggr_add_gpio()
66 char *args = skip_spaces(aggr->args); in aggr_parse()
74 return -ENOMEM; in aggr_parse()
109 error = -EINVAL; in aggr_parse()
127 return -ENOMEM; in new_device_store()
129 memcpy(aggr->args, buf, count + 1); in new_device_store()
131 aggr->lookups = kzalloc(struct_size(aggr->lookups, table, 1), in new_device_store()
133 if (!aggr->lookups) { in new_device_store()
134 res = -ENOMEM; in new_device_store()
147 aggr->lookups->dev_id = kasprintf(GFP_KERNEL, "%s.%d", DRV_NAME, id); in new_device_store()
148 if (!aggr->lookups->dev_id) { in new_device_store()
149 res = -ENOMEM; in new_device_store()
157 gpiod_add_lookup_table(aggr->lookups); in new_device_store()
165 aggr->pdev = pdev; in new_device_store()
169 gpiod_remove_lookup_table(aggr->lookups); in new_device_store()
171 kfree(aggr->lookups->dev_id); in new_device_store()
177 kfree(aggr->lookups); in new_device_store()
187 platform_device_unregister(aggr->pdev); in gpio_aggregator_free()
188 gpiod_remove_lookup_table(aggr->lookups); in gpio_aggregator_free()
189 kfree(aggr->lookups->dev_id); in gpio_aggregator_free()
190 kfree(aggr->lookups); in gpio_aggregator_free()
202 return -EINVAL; in delete_device_store()
212 return -ENOENT; in delete_device_store()
261 #define fwd_tmp_values(fwd) &(fwd)->tmp[0]
262 #define fwd_tmp_descs(fwd) (void *)&(fwd)->tmp[BITS_TO_LONGS((fwd)->chip.ngpio)]
264 #define fwd_tmp_size(ngpios) (BITS_TO_LONGS((ngpios)) + (ngpios)) argument
270 return gpiod_get_direction(fwd->descs[offset]); in gpio_fwd_get_direction()
277 return gpiod_direction_input(fwd->descs[offset]); in gpio_fwd_direction_input()
285 return gpiod_direction_output(fwd->descs[offset], value); in gpio_fwd_direction_output()
292 return chip->can_sleep ? gpiod_get_value_cansleep(fwd->descs[offset]) in gpio_fwd_get()
293 : gpiod_get_value(fwd->descs[offset]); in gpio_fwd_get()
304 bitmap_clear(values, 0, fwd->chip.ngpio); in gpio_fwd_get_multiple()
305 for_each_set_bit(i, mask, fwd->chip.ngpio) in gpio_fwd_get_multiple()
306 descs[j++] = fwd->descs[i]; in gpio_fwd_get_multiple()
308 if (fwd->chip.can_sleep) in gpio_fwd_get_multiple()
316 for_each_set_bit(i, mask, fwd->chip.ngpio) in gpio_fwd_get_multiple()
329 if (chip->can_sleep) { in gpio_fwd_get_multiple_locked()
330 mutex_lock(&fwd->mlock); in gpio_fwd_get_multiple_locked()
332 mutex_unlock(&fwd->mlock); in gpio_fwd_get_multiple_locked()
334 spin_lock_irqsave(&fwd->slock, flags); in gpio_fwd_get_multiple_locked()
336 spin_unlock_irqrestore(&fwd->slock, flags); in gpio_fwd_get_multiple_locked()
346 bool is_active_low = gpiod_is_active_low(fwd->descs[offset]); in gpio_fwd_delay()
349 delay_timings = &fwd->delay_timings[offset]; in gpio_fwd_delay()
351 delay_us = delay_timings->ramp_up_us; in gpio_fwd_delay()
353 delay_us = delay_timings->ramp_down_us; in gpio_fwd_delay()
357 if (chip->can_sleep) in gpio_fwd_delay()
367 if (chip->can_sleep) in gpio_fwd_set()
368 gpiod_set_value_cansleep(fwd->descs[offset], value); in gpio_fwd_set()
370 gpiod_set_value(fwd->descs[offset], value); in gpio_fwd_set()
372 if (fwd->delay_timings) in gpio_fwd_set()
383 for_each_set_bit(i, mask, fwd->chip.ngpio) { in gpio_fwd_set_multiple()
385 descs[j++] = fwd->descs[i]; in gpio_fwd_set_multiple()
388 if (fwd->chip.can_sleep) in gpio_fwd_set_multiple()
400 if (chip->can_sleep) { in gpio_fwd_set_multiple_locked()
401 mutex_lock(&fwd->mlock); in gpio_fwd_set_multiple_locked()
403 mutex_unlock(&fwd->mlock); in gpio_fwd_set_multiple_locked()
405 spin_lock_irqsave(&fwd->slock, flags); in gpio_fwd_set_multiple_locked()
407 spin_unlock_irqrestore(&fwd->slock, flags); in gpio_fwd_set_multiple_locked()
416 return gpiod_set_config(fwd->descs[offset], config); in gpio_fwd_set_config()
423 return gpiod_to_irq(fwd->descs[offset]); in gpio_fwd_to_irq()
428 * for the GPIO ramp-up or ramp-down delays. This can serve the following
430 * - Open-drain output using an RC filter
443 if (gpiospec->args_count != chip->of_gpio_n_cells) in gpiochip_fwd_delay_of_xlate()
444 return -EINVAL; in gpiochip_fwd_delay_of_xlate()
446 line = gpiospec->args[0]; in gpiochip_fwd_delay_of_xlate()
447 if (line >= chip->ngpio) in gpiochip_fwd_delay_of_xlate()
448 return -EINVAL; in gpiochip_fwd_delay_of_xlate()
450 timings = &fwd->delay_timings[line]; in gpiochip_fwd_delay_of_xlate()
451 timings->ramp_up_us = gpiospec->args[1]; in gpiochip_fwd_delay_of_xlate()
452 timings->ramp_down_us = gpiospec->args[2]; in gpiochip_fwd_delay_of_xlate()
460 fwd->delay_timings = devm_kcalloc(dev, chip->ngpio, in gpiochip_fwd_setup_delay_line()
461 sizeof(*fwd->delay_timings), in gpiochip_fwd_setup_delay_line()
463 if (!fwd->delay_timings) in gpiochip_fwd_setup_delay_line()
464 return -ENOMEM; in gpiochip_fwd_setup_delay_line()
466 chip->of_xlate = gpiochip_fwd_delay_of_xlate; in gpiochip_fwd_setup_delay_line()
467 chip->of_gpio_n_cells = 3; in gpiochip_fwd_setup_delay_line()
480 * gpiochip_fwd_create() - Create a new GPIO forwarder
482 * @ngpios: Number of GPIOs in the forwarder.
484 * This array must contain @ngpios entries, and must not be deallocated
491 * Return: An opaque object pointer, or an ERR_PTR()-encoded negative error
495 unsigned int ngpios, in gpiochip_fwd_create() argument
505 fwd = devm_kzalloc(dev, struct_size(fwd, tmp, fwd_tmp_size(ngpios)), in gpiochip_fwd_create()
508 return ERR_PTR(-ENOMEM); in gpiochip_fwd_create()
510 chip = &fwd->chip; in gpiochip_fwd_create()
518 for (i = 0; i < ngpios; i++) { in gpiochip_fwd_create()
525 chip->can_sleep = true; in gpiochip_fwd_create()
526 if (parent && parent->set_config) in gpiochip_fwd_create()
527 chip->set_config = gpio_fwd_set_config; in gpiochip_fwd_create()
530 chip->label = label; in gpiochip_fwd_create()
531 chip->parent = dev; in gpiochip_fwd_create()
532 chip->owner = THIS_MODULE; in gpiochip_fwd_create()
533 chip->get_direction = gpio_fwd_get_direction; in gpiochip_fwd_create()
534 chip->direction_input = gpio_fwd_direction_input; in gpiochip_fwd_create()
535 chip->direction_output = gpio_fwd_direction_output; in gpiochip_fwd_create()
536 chip->get = gpio_fwd_get; in gpiochip_fwd_create()
537 chip->get_multiple = gpio_fwd_get_multiple_locked; in gpiochip_fwd_create()
538 chip->set = gpio_fwd_set; in gpiochip_fwd_create()
539 chip->set_multiple = gpio_fwd_set_multiple_locked; in gpiochip_fwd_create()
540 chip->to_irq = gpio_fwd_to_irq; in gpiochip_fwd_create()
541 chip->base = -1; in gpiochip_fwd_create()
542 chip->ngpio = ngpios; in gpiochip_fwd_create()
543 fwd->descs = descs; in gpiochip_fwd_create()
545 if (chip->can_sleep) in gpiochip_fwd_create()
546 mutex_init(&fwd->mlock); in gpiochip_fwd_create()
548 spin_lock_init(&fwd->slock); in gpiochip_fwd_create()
570 struct device *dev = &pdev->dev; in gpio_aggregator_probe()
582 return -ENOMEM; in gpio_aggregator_probe()
601 .compatible = "gpio-delay",
605 * Add GPIO-operated devices controlled from userspace below,