#define GPIO_MOCKUP_MAX_GC 10 /* * We're storing two values per chip: the GPIO base and the number * of GPIO lines.
*/ #define GPIO_MOCKUP_MAX_RANGES (GPIO_MOCKUP_MAX_GC * 2) /* Maximum of four properties + the sentinel. */ #define GPIO_MOCKUP_MAX_PROP 5
/* * struct gpio_pin_status - structure describing a GPIO status * @dir: Configures direction of gpio as "in" or "out" * @value: Configures status of the gpio as 0(low) or 1(high) * @pull: Configures the current pull of the GPIO as 0 (pull-down) or * 1 (pull-up) * @requested: Request status of this GPIO
*/ struct gpio_mockup_line_status { int dir; int value; int pull; bool requested;
};
staticint gpio_mockup_apply_pull(struct gpio_mockup_chip *chip, unsignedint offset, int value)
{ struct gpio_mockup_line_status *line = &chip->lines[offset]; int curr, irq, irq_type, ret = 0;
guard(mutex)(&chip->lock);
if (line->requested && line->dir == GPIO_LINE_DIRECTION_IN) {
curr = __gpio_mockup_get(chip, offset); if (curr == value) goto out;
irq = irq_find_mapping(chip->irq_sim_domain, offset); if (!irq) /* * This is fine - it just means, nobody is listening * for interrupts on this line, otherwise * irq_create_mapping() would have been called from * the to_irq() callback.
*/ goto set_value;
irq_type = irq_get_trigger_type(irq);
if ((value == 1 && (irq_type & IRQ_TYPE_EDGE_RISING)) ||
(value == 0 && (irq_type & IRQ_TYPE_EDGE_FALLING))) {
ret = irq_set_irqchip_state(irq, IRQCHIP_STATE_PENDING, true); if (ret) goto out;
}
}
set_value: /* Change the value unless we're actively driving the line. */ if (!line->requested || line->dir == GPIO_LINE_DIRECTION_IN)
__gpio_mockup_set(chip, offset, value);
/* * Each mockup chip is represented by a directory named after the chip's device * name under /sys/kernel/debug/gpio-mockup/. Each line is represented by * a file using the line's offset as the name under the chip's directory. * * Reading from the line's file yields the current *value*, writing to the * line's file changes the current *pull*. Default pull for mockup lines is * down. * * Examples: * - when a line pulled down is requested in output mode and driven high, its * value will return to 0 once it's released * - when the line is requested in output mode and driven high, writing 0 to * the corresponding debugfs file will change the pull to down but the * reported value will still be 1 until the line is released * - line requested in input mode always reports the same value as its pull * configuration * - when the line is requested in input mode and monitored for events, writing * the same value to the debugfs file will be a noop, while writing the * opposite value will generate a dummy interrupt with an appropriate edge
*/ staticconststruct file_operations gpio_mockup_debugfs_ops = {
.owner = THIS_MODULE,
.open = gpio_mockup_debugfs_open,
.read = gpio_mockup_debugfs_read,
.write = gpio_mockup_debugfs_write,
.release = single_release,
};
/* * There can only be a single GPIO device per platform device in * gpio-mockup so using device_find_any_child() is OK.
*/ struct device *child __free(put_device) = device_find_any_child(dev); if (!child) return;
staticint __init gpio_mockup_init(void)
{ int i, num_chips, err;
if ((gpio_mockup_num_ranges % 2) ||
(gpio_mockup_num_ranges > GPIO_MOCKUP_MAX_RANGES)) return -EINVAL;
/* Each chip is described by two values. */
num_chips = gpio_mockup_num_ranges / 2;
/* * The second value in the <base GPIO - number of GPIOS> pair must * always be greater than 0.
*/ for (i = 0; i < num_chips; i++) { if (gpio_mockup_range_ngpio(i) < 0) return -EINVAL;
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.5Bemerkung:
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.