/** * modepin_gpio_get_value - Get the state of the specified pin of GPIO device * @chip: gpio_chip instance to be worked on * @pin: gpio pin number within the device * * This function reads the state of the specified pin of the GPIO device. * * Return: 0 if the pin is low, 1 if pin is high, -EINVAL wrong pin configured * or error value.
*/ staticint modepin_gpio_get_value(struct gpio_chip *chip, unsignedint pin)
{
u32 regval = 0; int ret;
ret = zynqmp_pm_bootmode_read(®val); if (ret) return ret;
/* When [0:3] corresponding bit is set, then read output bit [8:11], * if the bit is clear then read input bit [4:7] for status or value.
*/ if (regval & BIT(pin)) return !!(regval & BIT(pin + 8)); else return !!(regval & BIT(pin + 4));
}
/** * modepin_gpio_set_value - Modify the state of the pin with specified value * @chip: gpio_chip instance to be worked on * @pin: gpio pin number within the device * @state: value used to modify the state of the specified pin * * This function reads the state of the specified pin of the GPIO device, mask * with the capture state of GPIO pin, and update pin of GPIO device. * * Return: None.
*/ staticint modepin_gpio_set_value(struct gpio_chip *chip, unsignedint pin, int state)
{
u32 bootpin_val = 0; int ret;
zynqmp_pm_bootmode_read(&bootpin_val);
/* Configure pin as an output by set bit [0:3] */
bootpin_val |= BIT(pin);
/* Configure bootpin value */
ret = zynqmp_pm_bootmode_write(bootpin_val); if (ret)
pr_err("modepin: set value error %d for pin %d\n", ret, pin);
return ret;
}
/** * modepin_gpio_dir_in - Set the direction of the specified GPIO pin as input * @chip: gpio_chip instance to be worked on * @pin: gpio pin number within the device * * Return: 0 always
*/ staticint modepin_gpio_dir_in(struct gpio_chip *chip, unsignedint pin)
{ return 0;
}
/** * modepin_gpio_dir_out - Set the direction of the specified GPIO pin as output * @chip: gpio_chip instance to be worked on * @pin: gpio pin number within the device * @state: value to be written to specified pin * * Return: 0 always
*/ staticint modepin_gpio_dir_out(struct gpio_chip *chip, unsignedint pin, int state)
{ return modepin_gpio_set_value(chip, pin, state);
}
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.