From 34be6968c3570d8e03fcafcd60c02f315b8f4602 Mon Sep 17 00:00:00 2001 From: Andrew Jeffery Date: Mon, 31 Jan 2022 13:54:05 +1030 Subject: gpio: Add gpio_request_by_line_name() Add support for the upstream gpio-line-names property already described in the common GPIO binding document[1]. The ability to search for a line name allows boards to lift the implementation of common GPIO behaviours away from specific line indexes on a GPIO controller. [1] https://github.com/devicetree-org/dt-schema/blob/3c35bfee83c2e38e2ae7af5f83eb89ca94a521e8/dtschema/schemas/gpio/gpio.yaml#L17 Signed-off-by: Andrew Jeffery --- drivers/gpio/gpio-uclass.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'drivers') diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c index 125ae53d612..be00a1f7d87 100644 --- a/drivers/gpio/gpio-uclass.c +++ b/drivers/gpio/gpio-uclass.c @@ -1187,6 +1187,32 @@ int gpio_request_by_name(struct udevice *dev, const char *list_name, int index, index, desc, flags, index > 0, NULL); } +int gpio_request_by_line_name(struct udevice *dev, const char *line_name, + struct gpio_desc *desc, int flags) +{ + int ret; + + ret = dev_read_stringlist_search(dev, "gpio-line-names", line_name); + if (ret < 0) + return ret; + + desc->dev = dev; + desc->offset = ret; + desc->flags = 0; + + ret = dm_gpio_request(desc, line_name); + if (ret) { + debug("%s: dm_gpio_requestf failed\n", __func__); + return ret; + } + + ret = dm_gpio_set_dir_flags(desc, flags | desc->flags); + if (ret) + debug("%s: dm_gpio_set_dir failed\n", __func__); + + return ret; +} + int gpio_request_list_by_name_nodev(ofnode node, const char *list_name, struct gpio_desc *desc, int max_count, int flags) -- cgit v1.2.3 From 1d99e673c752bc7d55aa25b02e050741496f7109 Mon Sep 17 00:00:00 2001 From: Eddie James Date: Mon, 7 Feb 2022 17:09:01 -0600 Subject: gpio: Enable hogging support in SPL Use the CONFIG macros to conditionally build the GPIO hogging support in either the SPL or U-Boot, or both, depending on the configuration. Also call the GPIO hog probe function in the common SPL board initialization as an equivalent to adding it to the U-Boot init sequence functions. Signed-off-by: Eddie James Reviewed-by: Simon Glass --- drivers/gpio/Kconfig | 9 +++++++++ drivers/gpio/gpio-uclass.c | 8 ++++---- 2 files changed, 13 insertions(+), 4 deletions(-) (limited to 'drivers') diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index a55e3686934..89068c7800d 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -57,6 +57,15 @@ config GPIO_HOG is a mechanism providing automatic GPIO request and config- uration as part of the gpio-controller's driver probe function. +config SPL_GPIO_HOG + bool "Enable GPIO hog support in SPL" + depends on SPL_GPIO_SUPPORT + help + Enable gpio hog support in SPL + The GPIO chip may contain GPIO hog definitions. GPIO hogging + is a mechanism providing automatic GPIO request and config- + uration as part of the gpio-controller's driver probe function. + config DM_GPIO_LOOKUP_LABEL bool "Enable searching for gpio labelnames" depends on DM_GPIO diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c index be00a1f7d87..0ed32b72170 100644 --- a/drivers/gpio/gpio-uclass.c +++ b/drivers/gpio/gpio-uclass.c @@ -1458,9 +1458,6 @@ void devm_gpiod_put(struct udevice *dev, struct gpio_desc *desc) static int gpio_post_bind(struct udevice *dev) { - struct udevice *child; - ofnode node; - #if defined(CONFIG_NEEDS_MANUAL_RELOC) struct dm_gpio_ops *ops = (struct dm_gpio_ops *)device_get_ops(dev); static int reloc_done; @@ -1491,7 +1488,10 @@ static int gpio_post_bind(struct udevice *dev) } #endif - if (CONFIG_IS_ENABLED(OF_REAL) && IS_ENABLED(CONFIG_GPIO_HOG)) { + if (CONFIG_IS_ENABLED(GPIO_HOG)) { + struct udevice *child; + ofnode node; + dev_for_each_subnode(node, dev) { if (ofnode_read_bool(node, "gpio-hog")) { const char *name = ofnode_get_name(node); -- cgit v1.2.3 From c170fe0a77738df1344a805acfe53133e5d15e43 Mon Sep 17 00:00:00 2001 From: Luca Ellero Date: Tue, 22 Mar 2022 15:38:36 +0100 Subject: gpio: pca953x_gpio: add PCA957X support Take as reference Linux kernel code: drivers/gpio/gpio-pca953x.c Signed-off-by: Luca Ellero Reviewed-by: Simon Glass --- drivers/gpio/pca953x_gpio.c | 50 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 10 deletions(-) (limited to 'drivers') diff --git a/drivers/gpio/pca953x_gpio.c b/drivers/gpio/pca953x_gpio.c index dc8911a8eb9..e98e1e56dbc 100644 --- a/drivers/gpio/pca953x_gpio.c +++ b/drivers/gpio/pca953x_gpio.c @@ -35,6 +35,12 @@ #define PCA953X_INVERT 2 #define PCA953X_DIRECTION 3 +#define PCA957X_INPUT 0 +#define PCA957X_OUTPUT 5 +#define PCA957X_INVERT 1 +#define PCA957X_DIRECTION 4 + + #define PCA_GPIO_MASK 0x00FF #define PCA_INT 0x0100 #define PCA953X_TYPE 0x1000 @@ -50,8 +56,29 @@ enum { #define MAX_BANK 5 #define BANK_SZ 8 +struct pca95xx_reg { + int input; + int output; + int invert; + int direction; +}; + +static const struct pca95xx_reg pca953x_regs = { + .direction = PCA953X_DIRECTION, + .output = PCA953X_OUTPUT, + .input = PCA953X_INPUT, + .invert = PCA953X_INVERT, +}; + +static const struct pca95xx_reg pca957x_regs = { + .direction = PCA957X_DIRECTION, + .output = PCA957X_OUTPUT, + .input = PCA957X_INPUT, + .invert = PCA957X_INVERT, +}; + /* - * struct pca953x_info - Data for pca953x + * struct pca953x_info - Data for pca953x/pca957x * * @dev: udevice structure for the device * @addr: i2c slave address @@ -61,6 +88,7 @@ enum { * @bank_count: the number of banks that the device supports * @reg_output: array to hold the value of output registers * @reg_direction: array to hold the value of direction registers + * @regs: struct to hold the registers addresses */ struct pca953x_info { struct udevice *dev; @@ -71,6 +99,7 @@ struct pca953x_info { int bank_count; u8 reg_output[MAX_BANK]; u8 reg_direction[MAX_BANK]; + const struct pca95xx_reg *regs; }; static int pca953x_write_single(struct udevice *dev, int reg, u8 val, @@ -171,12 +200,13 @@ static int pca953x_is_output(struct udevice *dev, int offset) static int pca953x_get_value(struct udevice *dev, uint offset) { + struct pca953x_info *info = dev_get_plat(dev); int ret; u8 val = 0; int off = offset % BANK_SZ; - ret = pca953x_read_single(dev, PCA953X_INPUT, &val, offset); + ret = pca953x_read_single(dev, info->regs->input, &val, offset); if (ret) return ret; @@ -196,7 +226,7 @@ static int pca953x_set_value(struct udevice *dev, uint offset, int value) else val = info->reg_output[bank] & ~(1 << off); - ret = pca953x_write_single(dev, PCA953X_OUTPUT, val, offset); + ret = pca953x_write_single(dev, info->regs->output, val, offset); if (ret) return ret; @@ -218,7 +248,7 @@ static int pca953x_set_direction(struct udevice *dev, uint offset, int dir) else val = info->reg_direction[bank] & ~(1 << off); - ret = pca953x_write_single(dev, PCA953X_DIRECTION, val, offset); + ret = pca953x_write_single(dev, info->regs->direction, val, offset); if (ret) return ret; @@ -296,14 +326,14 @@ static int pca953x_probe(struct udevice *dev) } info->chip_type = PCA_CHIP_TYPE(driver_data); - if (info->chip_type != PCA953X_TYPE) { - dev_err(dev, "Only support PCA953X chip type now.\n"); - return -EINVAL; - } + if (info->chip_type == PCA953X_TYPE) + info->regs = &pca953x_regs; + else + info->regs = &pca957x_regs; info->bank_count = DIV_ROUND_UP(info->gpio_count, BANK_SZ); - ret = pca953x_read_regs(dev, PCA953X_OUTPUT, info->reg_output); + ret = pca953x_read_regs(dev, info->regs->output, info->reg_output); if (ret) { dev_err(dev, "Error reading output register\n"); return ret; @@ -327,7 +357,7 @@ static int pca953x_probe(struct udevice *dev) /* Clear the polarity registers to no invert */ memset(val, 0, MAX_BANK); - ret = pca953x_write_regs(dev, PCA953X_INVERT, val); + ret = pca953x_write_regs(dev, info->regs->invert, val); if (ret < 0) { dev_err(dev, "Error writing invert register\n"); return ret; -- cgit v1.2.3