Lines Matching +full:gpio +full:- +full:lines

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * GPIO Testing Device Driver
6 * Copyright (C) 2015-2016 Bamvor Jian Zhang <bamv2005@gmail.com>
13 #include <linux/gpio/driver.h>
30 * We're storing two values per chip: the GPIO base and the number
31 * of GPIO lines.
38 * struct gpio_pin_status - structure describing a GPIO status
39 * @dir: Configures direction of gpio as "in" or "out"
40 * @value: Configures status of the gpio as 0(low) or 1(high)
50 struct gpio_mockup_line_status *lines; member
85 return chip->lines[offset].value; in __gpio_mockup_get()
93 mutex_lock(&chip->lock); in gpio_mockup_get()
95 mutex_unlock(&chip->lock); in gpio_mockup_get()
106 mutex_lock(&chip->lock); in gpio_mockup_get_multiple()
107 for_each_set_bit(bit, mask, gc->ngpio) { in gpio_mockup_get_multiple()
111 mutex_unlock(&chip->lock); in gpio_mockup_get_multiple()
119 chip->lines[offset].value = !!value; in __gpio_mockup_set()
127 mutex_lock(&chip->lock); in gpio_mockup_set()
129 mutex_unlock(&chip->lock); in gpio_mockup_set()
138 mutex_lock(&chip->lock); in gpio_mockup_set_multiple()
139 for_each_set_bit(bit, mask, gc->ngpio) in gpio_mockup_set_multiple()
141 mutex_unlock(&chip->lock); in gpio_mockup_set_multiple()
147 struct gpio_chip *gc = &chip->gc; in gpio_mockup_apply_pull()
151 mutex_lock(&chip->lock); in gpio_mockup_apply_pull()
153 if (test_bit(FLAG_REQUESTED, &desc->flags) && in gpio_mockup_apply_pull()
154 !test_bit(FLAG_IS_OUT, &desc->flags)) { in gpio_mockup_apply_pull()
159 irq = irq_find_mapping(chip->irq_sim_domain, offset); in gpio_mockup_apply_pull()
162 * This is fine - it just means, nobody is listening in gpio_mockup_apply_pull()
182 if (!test_bit(FLAG_REQUESTED, &desc->flags) || in gpio_mockup_apply_pull()
183 !test_bit(FLAG_IS_OUT, &desc->flags)) in gpio_mockup_apply_pull()
187 chip->lines[offset].pull = value; in gpio_mockup_apply_pull()
188 mutex_unlock(&chip->lock); in gpio_mockup_apply_pull()
205 return -ENOTSUPP; in gpio_mockup_set_config()
213 mutex_lock(&chip->lock); in gpio_mockup_dirout()
214 chip->lines[offset].dir = GPIO_LINE_DIRECTION_OUT; in gpio_mockup_dirout()
216 mutex_unlock(&chip->lock); in gpio_mockup_dirout()
225 mutex_lock(&chip->lock); in gpio_mockup_dirin()
226 chip->lines[offset].dir = GPIO_LINE_DIRECTION_IN; in gpio_mockup_dirin()
227 mutex_unlock(&chip->lock); in gpio_mockup_dirin()
237 mutex_lock(&chip->lock); in gpio_mockup_get_direction()
238 direction = chip->lines[offset].dir; in gpio_mockup_get_direction()
239 mutex_unlock(&chip->lock); in gpio_mockup_get_direction()
248 return irq_create_mapping(chip->irq_sim_domain, offset); in gpio_mockup_to_irq()
255 __gpio_mockup_set(chip, offset, chip->lines[offset].pull); in gpio_mockup_free()
272 sfile = file->private_data; in gpio_mockup_debugfs_read()
273 priv = sfile->private; in gpio_mockup_debugfs_read()
274 chip = priv->chip; in gpio_mockup_debugfs_read()
275 gc = &chip->gc; in gpio_mockup_debugfs_read()
277 val = gpio_mockup_get(gc, priv->offset); in gpio_mockup_debugfs_read()
292 return -EINVAL; in gpio_mockup_debugfs_write()
298 return -EINVAL; in gpio_mockup_debugfs_write()
300 sfile = file->private_data; in gpio_mockup_debugfs_write()
301 priv = sfile->private; in gpio_mockup_debugfs_write()
302 rv = gpio_mockup_apply_pull(priv->chip, priv->offset, val); in gpio_mockup_debugfs_write()
311 return single_open(file, NULL, inode->i_private); in gpio_mockup_debugfs_open()
316 * name under /sys/kernel/debug/gpio-mockup/. Each line is represented by
320 * line's file changes the current *pull*. Default pull for mockup lines is
324 * - when a line pulled down is requested in output mode and driven high, its
326 * - when the line is requested in output mode and driven high, writing 0 to
329 * - line requested in input mode always reports the same value as its pull
331 * - when the line is requested in input mode and monitored for events, writing
353 gc = &chip->gc; in gpio_mockup_debugfs_setup()
354 devname = dev_name(&gc->gpiodev->dev); in gpio_mockup_debugfs_setup()
356 chip->dbg_dir = debugfs_create_dir(devname, gpio_mockup_dbg_dir); in gpio_mockup_debugfs_setup()
358 for (i = 0; i < gc->ngpio; i++) { in gpio_mockup_debugfs_setup()
367 priv->chip = chip; in gpio_mockup_debugfs_setup()
368 priv->offset = i; in gpio_mockup_debugfs_setup()
369 priv->desc = gpiochip_get_desc(gc, i); in gpio_mockup_debugfs_setup()
371 debugfs_create_file(name, 0200, chip->dbg_dir, priv, in gpio_mockup_debugfs_setup()
380 debugfs_remove_recursive(chip->dbg_dir); in gpio_mockup_debugfs_cleanup()
386 struct gpio_chip *gc = &chip->gc; in gpio_mockup_dispose_mappings()
389 for (i = 0; i < gc->ngpio; i++) { in gpio_mockup_dispose_mappings()
390 irq = irq_find_mapping(chip->irq_sim_domain, i); in gpio_mockup_dispose_mappings()
405 dev = &pdev->dev; in gpio_mockup_probe()
407 rv = device_property_read_u32(dev, "gpio-base", &base); in gpio_mockup_probe()
409 base = -1; in gpio_mockup_probe()
411 rv = device_property_read_u16(dev, "nr-gpios", &ngpio); in gpio_mockup_probe()
415 rv = device_property_read_string(dev, "chip-label", &name); in gpio_mockup_probe()
421 return -ENOMEM; in gpio_mockup_probe()
423 mutex_init(&chip->lock); in gpio_mockup_probe()
425 gc = &chip->gc; in gpio_mockup_probe()
426 gc->base = base; in gpio_mockup_probe()
427 gc->ngpio = ngpio; in gpio_mockup_probe()
428 gc->label = name; in gpio_mockup_probe()
429 gc->owner = THIS_MODULE; in gpio_mockup_probe()
430 gc->parent = dev; in gpio_mockup_probe()
431 gc->get = gpio_mockup_get; in gpio_mockup_probe()
432 gc->set = gpio_mockup_set; in gpio_mockup_probe()
433 gc->get_multiple = gpio_mockup_get_multiple; in gpio_mockup_probe()
434 gc->set_multiple = gpio_mockup_set_multiple; in gpio_mockup_probe()
435 gc->direction_output = gpio_mockup_dirout; in gpio_mockup_probe()
436 gc->direction_input = gpio_mockup_dirin; in gpio_mockup_probe()
437 gc->get_direction = gpio_mockup_get_direction; in gpio_mockup_probe()
438 gc->set_config = gpio_mockup_set_config; in gpio_mockup_probe()
439 gc->to_irq = gpio_mockup_to_irq; in gpio_mockup_probe()
440 gc->free = gpio_mockup_free; in gpio_mockup_probe()
442 chip->lines = devm_kcalloc(dev, gc->ngpio, in gpio_mockup_probe()
443 sizeof(*chip->lines), GFP_KERNEL); in gpio_mockup_probe()
444 if (!chip->lines) in gpio_mockup_probe()
445 return -ENOMEM; in gpio_mockup_probe()
447 for (i = 0; i < gc->ngpio; i++) in gpio_mockup_probe()
448 chip->lines[i].dir = GPIO_LINE_DIRECTION_IN; in gpio_mockup_probe()
450 chip->irq_sim_domain = devm_irq_domain_create_sim(dev, NULL, in gpio_mockup_probe()
451 gc->ngpio); in gpio_mockup_probe()
452 if (IS_ERR(chip->irq_sim_domain)) in gpio_mockup_probe()
453 return PTR_ERR(chip->irq_sim_domain); in gpio_mockup_probe()
459 rv = devm_gpiochip_add_data(dev, &chip->gc, chip); in gpio_mockup_probe()
469 { .compatible = "gpio-mockup", },
476 .name = "gpio-mockup",
495 fwnode = dev_fwnode(&pdev->dev); in gpio_mockup_unregister_pdevs()
515 snprintf(chip_label, sizeof(chip_label), "gpio-mockup-%c", idx + 'A'); in gpio_mockup_register_chip()
516 properties[prop++] = PROPERTY_ENTRY_STRING("chip-label", chip_label); in gpio_mockup_register_chip()
520 properties[prop++] = PROPERTY_ENTRY_U32("gpio-base", base); in gpio_mockup_register_chip()
523 : gpio_mockup_range_ngpio(idx) - base; in gpio_mockup_register_chip()
524 properties[prop++] = PROPERTY_ENTRY_U16("nr-gpios", ngpio); in gpio_mockup_register_chip()
529 return -ENOMEM; in gpio_mockup_register_chip()
532 "gpio-line-names", line_names, ngpio); in gpio_mockup_register_chip()
541 pdevinfo.name = "gpio-mockup"; in gpio_mockup_register_chip()
564 return -EINVAL; in gpio_mockup_init()
570 * The second value in the <base GPIO - number of GPIOS> pair must in gpio_mockup_init()
575 return -EINVAL; in gpio_mockup_init()
578 gpio_mockup_dbg_dir = debugfs_create_dir("gpio-mockup", NULL); in gpio_mockup_init()
613 MODULE_DESCRIPTION("GPIO Testing driver");