// SPDX-License-Identifier: GPL-2.0+ /* * Raspberry Pi 3 expander GPIO driver * * Uses the firmware mailbox service to communicate with the * GPIO expander on the VPU. * * Copyright (C) 2017 Raspberry Pi Trading Ltd.
*/
set_in.gpio = off + RPI_EXP_GPIO_BASE; /* GPIO to update */
set_in.direction = RPI_EXP_GPIO_DIR_IN;
set_in.term_en = 0; /* termination disabled */
set_in.term_pull_up = 0; /* n/a as termination disabled */
set_in.state = 0; /* n/a as configured as an input */
ret = rpi_exp_gpio_get_polarity(gc, off); if (ret < 0) return ret;
set_in.polarity = ret; /* Retain existing setting */
ret = rpi_firmware_property(gpio->fw, RPI_FIRMWARE_SET_GPIO_CONFIG,
&set_in, sizeof(set_in)); if (ret || set_in.gpio != 0) {
dev_err(gc->parent, "Failed to set GPIO %u to input (%d %x)\n",
off, ret, set_in.gpio); return ret ? ret : -EIO;
} return0;
}
staticint rpi_exp_gpio_dir_out(struct gpio_chip *gc, unsignedint off, int val)
{ struct rpi_exp_gpio *gpio; struct gpio_set_config set_out; int ret;
gpio = gpiochip_get_data(gc);
set_out.gpio = off + RPI_EXP_GPIO_BASE; /* GPIO to update */
set_out.direction = RPI_EXP_GPIO_DIR_OUT;
set_out.term_en = 0; /* n/a as an output */
set_out.term_pull_up = 0; /* n/a as termination disabled */
set_out.state = val; /* Output state */
ret = rpi_exp_gpio_get_polarity(gc, off); if (ret < 0) return ret;
set_out.polarity = ret; /* Retain existing setting */
ret = rpi_firmware_property(gpio->fw, RPI_FIRMWARE_SET_GPIO_CONFIG,
&set_out, sizeof(set_out)); if (ret || set_out.gpio != 0) {
dev_err(gc->parent, "Failed to set GPIO %u to output (%d %x)\n",
off, ret, set_out.gpio); return ret ? ret : -EIO;
} return0;
}
get.gpio = off + RPI_EXP_GPIO_BASE; /* GPIO to update */
get.state = 0; /* storage for returned value */
ret = rpi_firmware_property(gpio->fw, RPI_FIRMWARE_GET_GPIO_STATE,
&get, sizeof(get)); if (ret || get.gpio != 0) {
dev_err(gc->parent, "Failed to get GPIO %u state (%d %x)\n", off, ret,
get.gpio); return ret ? ret : -EIO;
} return !!get.state;
}
staticint rpi_exp_gpio_set(struct gpio_chip *gc, unsignedint off, int val)
{ struct rpi_exp_gpio *gpio; struct gpio_get_set_state set; int ret;
gpio = gpiochip_get_data(gc);
set.gpio = off + RPI_EXP_GPIO_BASE; /* GPIO to update */
set.state = val; /* Output state */
ret = rpi_firmware_property(gpio->fw, RPI_FIRMWARE_SET_GPIO_STATE,
&set, sizeof(set)); if (ret || set.gpio != 0) {
dev_err(gc->parent, "Failed to set GPIO %u state (%d %x)\n", off, ret,
set.gpio); return ret ? ret : -EIO;
}
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.