Implement GPIO cells for PALMAS and MAX77663 PMICs
Subsystems (2)
cover Implement GPIO cells for PALMAS and MAX77663 PMICs
This patchset adds support for gpio-uclass to work with pmic gpio childrens properly and implements MAX77663 and PALMAS GPIO cells/children as a reference and to be further used in devices I am currently maintaining.
All drivers are tested on actual hardware and confirmed to work as expected. MAX77663 GPIO cell is tested on wexler qc750 tegra 3 device and PALMAS GPIO cell is tested on tegra note 7 tegra 4 device.
These patches require "Add support for PMICs used on Tegra 3 devices" patches to be merged first for proper work.
Svyatoslav Ryhel (3):
drivers: gpio-uclass: support PMIC GPIO children
drivers: gpio: implement MAX77663 GPIO cell
drivers: gpio: implement PALMAS GPIO cell
drivers/gpio/Kconfig | 16 +++ drivers/gpio/Makefile | 2 + drivers/gpio/gpio-uclass.c | 19 ++- drivers/gpio/max77663_gpio.c | 179 ++++++++++++++++++++++++++++ drivers/gpio/palmas_gpio.c | 133 +++++++++++++++++++++ drivers/power/pmic/max77663.c | 9 ++ drivers/power/pmic/palmas.c | 10 +- include/dt-bindings/pmic/max77663.h | 18 +++ include/power/max77663.h | 1 + include/power/palmas.h | 12 ++ 10 files changed, 395 insertions(+), 4 deletions(-) create mode 100644 drivers/gpio/max77663_gpio.c create mode 100644 drivers/gpio/palmas_gpio.c create mode 100644 include/dt-bindings/pmic/max77663.h
Signature · 1 line
2.39.2
PATCH 1/3 drivers: gpio-uclass: support PMIC GPIO children
UCLASS_PMIC may have GPIO children without exposed fdt node, in this case if requesting fails, check if uclass is PMIC. If so, iterate through its children to find correct device.
--- drivers/gpio/gpio-uclass.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
drivers/gpio/gpio-uclass.c +16 -3
@@ -1143,9 +1143,22 @@ static int gpio_request_tail(int ret, const char *nodename, ret =uclass_get_device_by_ofnode (UCLASS_GPIO , args->node, &desc->dev);if (ret) { -debug ("%s: uclass_get_device_by_ofnode failed\n" , - __func__); - goto err; +struct udevice *pmic; + ret =uclass_get_device_by_ofnode (UCLASS_PMIC , args->node, + &pmic); +if (ret) { +log_err ("PMIC device get failed, err %d\n" , ret); + goto err; + } + + device_foreach_child(desc->dev, pmic) { +if (device_get_uclass_id (desc->dev) ==UCLASS_GPIO ) +break ; + } + +/* if loop exits without GPIO device return error */ +if (device_get_uclass_id (desc->dev) !=UCLASS_GPIO ) + goto err; } } ret =gpio_find_and_xlate (desc, args);
Signature · 1 line
2.39.2
Re: [PATCH v1 1/3] drivers: gpio-uclass: support PMIC GPIO children
Quoted 29 lines · Svyatoslav Ryhel
UCLASS_PMICmay have GPIO children without exposed fdt node, in this case if requesting fails, check if uclass is PMIC. If so, iterate through its children to find correct device.Signed-off-by Svyatoslav Ryhel <[email protected]>--- drivers/gpio/gpio-uclass.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)drivers/gpio/gpio-uclass.c +9
-3@@ -1143,9 +1143,22 @@ static int gpio_request_tail(int ret, const char *nodename, ret =uclass_get_device_by_ofnode (UCLASS_GPIO , args->node, &desc->dev);if (ret) { -debug ("%s: uclass_get_device_by_ofnode failed\n" , - __func__); - goto err; +struct udevice *pmic; + ret =uclass_get_device_by_ofnode (UCLASS_PMIC , args->node, + &pmic); +if (ret) { +log_err ("PMIC device get failed, err %d\n" , ret); + goto err; + } + + device_foreach_child(desc->dev, pmic) {
drivers/gpio/gpio-uclass.c static int gpio_request_tail(int ret, const char *nodename, · line 1164
Quoted 10 lines
drivers/gpio/gpio-uclass.c +7
-0+if (device_get_uclass_id (desc->dev) ==UCLASS_GPIO ) +break ; + } + +/* if loop exits without GPIO device return error */ +if (device_get_uclass_id (desc->dev) !=UCLASS_GPIO ) + goto err; } } ret =gpio_find_and_xlate (desc, args);
This needs to check for DM_PMIC or so as it leads to a lot of size increase and one failure to link due to running out of space now.
Signature · 1 line
Tom
Re: [PATCH v1 1/3] drivers: gpio-uclass: support PMIC GPIO children
3 листопада 2023 р. 21:03:39 GMT+02:00, Tom Rini <[email protected]> написав(-ла):
Quoted 36 lines · Svyatoslav Ryhel
Quoted 35 lines
UCLASS_PMICmay have GPIO children without exposed fdt node, in this case if requesting fails, check if uclass is PMIC. If so, iterate through its children to find correct device.Signed-off-by Svyatoslav Ryhel <[email protected]>--- drivers/gpio/gpio-uclass.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)drivers/gpio/gpio-uclass.c +14
-3@@ -1143,9 +1143,22 @@ static int gpio_request_tail(int ret, const char *nodename, ret =uclass_get_device_by_ofnode (UCLASS_GPIO , args->node, &desc->dev);if (ret) { -debug ("%s: uclass_get_device_by_ofnode failed\n" , - __func__); - goto err; +struct udevice *pmic; + ret =uclass_get_device_by_ofnode (UCLASS_PMIC , args->node, + &pmic); +if (ret) { +log_err ("PMIC device get failed, err %d\n" , ret); + goto err; + } + + device_foreach_child(desc->dev, pmic) { +if (device_get_uclass_id (desc->dev) ==UCLASS_GPIO ) +break ; + } + +/* if loop exits without GPIO device return error */
Quoted 8 lines
drivers/gpio/gpio-uclass.c static int gpio_request_tail(int ret, const char *nodename, · line 1164
Quoted 5 lines
drivers/gpio/gpio-uclass.c +2
-0+if (device_get_uclass_id (desc->dev) !=UCLASS_GPIO ) + goto err; } } ret =gpio_find_and_xlate (desc, args);This needs to check for
DM_PMICor so as it leads to a lot of size increase and one failure to link due to running out of space now.
Thanks for checking! I will look into it deeper to reduce the size inflation, not sure though why it occurs at all. Best regards,
Svyatoslav R.
Re: [PATCH v1 1/3] drivers: gpio-uclass: support PMIC GPIO children
Quoted 48 lines · Svyatoslav Ryhel
3 листопада 2023 р. 21:03:39 GMT+02:00, Tom Rini <[email protected]> написав(-ла):
Quoted 36 lines · Svyatoslav Ryhel
Quoted 35 lines
UCLASS_PMICmay have GPIO children without exposed fdt node, in this case if requesting fails, check if uclass is PMIC. If so, iterate through its children to find correct device.Signed-off-by Svyatoslav Ryhel <[email protected]>--- drivers/gpio/gpio-uclass.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)drivers/gpio/gpio-uclass.c +14
-3@@ -1143,9 +1143,22 @@ static int gpio_request_tail(int ret, const char *nodename, ret =uclass_get_device_by_ofnode (UCLASS_GPIO , args->node, &desc->dev);if (ret) { -debug ("%s: uclass_get_device_by_ofnode failed\n" , - __func__); - goto err; +struct udevice *pmic; + ret =uclass_get_device_by_ofnode (UCLASS_PMIC , args->node, + &pmic); +if (ret) { +log_err ("PMIC device get failed, err %d\n" , ret); + goto err; + } + + device_foreach_child(desc->dev, pmic) { +if (device_get_uclass_id (desc->dev) ==UCLASS_GPIO ) +break ; + } + +/* if loop exits without GPIO device return error */ Quoted 8 lines
drivers/gpio/gpio-uclass.c static int gpio_request_tail(int ret, const char *nodename, · line 1164
Quoted 5 lines
drivers/gpio/gpio-uclass.c +2
-0+if (device_get_uclass_id (desc->dev) !=UCLASS_GPIO ) + goto err; } } ret =gpio_find_and_xlate (desc, args);This needs to check for
DM_PMICor so as it leads to a lot of size increase and one failure to link due to running out of space now.
Quoted 1 line
Thanks for checking! I will look into it deeper to reduce the size inflation, not sure though why it occurs at all.
Note that it's not a huge inflation (it's 128 bytes), but for every board that includes this file, in SPL, it grows that much, and then sometimes might also be "and now we pull in funcX" as well.
Signature · 1 line
Tom
PATCH 2/3 drivers: gpio: implement MAX77663 GPIO cell
In reply to Svyatoslav RyhelMAXIM Semiconductor's PMIC, MAX77663 has 8 GPIO pins and 3 GPIO-like pins. It also supports interrupts from these pins.
Add GPIO driver for these pins to control via GPIO APIs.
--- drivers/gpio/Kconfig | 9 ++ drivers/gpio/Makefile | 1 + drivers/gpio/max77663_gpio.c | 179 ++++++++++++++++++++++++++++ drivers/power/pmic/max77663.c | 9 ++ include/dt-bindings/pmic/max77663.h | 18 +++ include/power/max77663.h | 1 + 6 files changed, 217 insertions(+) create mode 100644 drivers/gpio/max77663_gpio.c create mode 100644 include/dt-bindings/pmic/max77663.h
drivers/gpio/Kconfig +9 -0
@@ -238,6 +238,15 @@ config MAX7320_GPIO original maxim device has 8 push/pull outputs, some clones offers 16bit. +config MAX77663_GPIO + bool "MAX77663 GPIO cell of PMIC driver" + depends on DM_GPIO && DM_PMIC_MAX77663 + help + GPIO driver for MAX77663 PMIC from Maxim Semiconductor. + MAX77663 PMIC has 8 pins that can be configured as GPIOs + and 3 GPIO-like pins dedicated for power/reset buttons + and LID sensor. + config MCP230XX_GPIO bool "MCP230XX GPIO driver" depends on DM
drivers/gpio/Makefile +1 -0
@@ -68,6 +68,7 @@ obj-$(CONFIG_NX_GPIO) += nx_gpio.o obj-$(CONFIG_SIFIVE_GPIO) += sifive-gpio.o obj-$(CONFIG_NOMADIK_GPIO) += nmk_gpio.o obj-$(CONFIG_MAX7320_GPIO) += max7320_gpio.o +obj-$(CONFIG_$(SPL_)MAX77663_GPIO) += max77663_gpio.o obj-$(CONFIG_SL28CPLD_GPIO) += sl28cpld-gpio.o obj-$(CONFIG_ZYNQMP_GPIO_MODEPIN) += zynqmp_gpio_modepin.o obj-$(CONFIG_SLG7XL45106_I2C_GPO) += gpio_slg7xl45106.o
drivers/gpio/max77663_gpio.c new file +179 -0
179 lines not on this page · raw message
drivers/power/pmic/max77663.c +9 -0
@@ -61,6 +61,15 @@ static int max77663_bind(struct udevice *dev) } } +if (IS_ENABLED (CONFIG_MAX77663_GPIO )) { + ret =device_bind_driver (dev,MAX77663_GPIO_DRIVER , +"gpio" ,NULL ); +if (ret) { +log_err ("cannot bind GPIOs (ret = %d)\n" , ret); +return ret; + } + } + regulators_node =dev_read_subnode (dev,"regulators" );if (!ofnode_valid (regulators_node)) {log_err ("%s regulators subnode not found!\n" , dev->name);
include/dt-bindings/pmic/max77663.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright(C) 2023 Svyatoslav Ryhel <[email protected]> +*/ + +#ifndef _DT_BINDINGS_MAX77663_H_ +#define _DT_BINDINGS_MAX77663_H_ + +/* +* MAX77663 has 8 GPIO (0 to 7) and 3 KEYS +* KEYS are appended after GPIOs +*/ + +#define EN0 10 +#define ACOK 9 +#define LID 8 + +#endif
include/power/max77663.h +1 -0
@@ -13,6 +13,7 @@#define MAX77663_LDO_DRIVER "max77663_ldo"#define MAX77663_SD_DRIVER "max77663_sd"#define MAX77663_RST_DRIVER "max77663_rst" +#define MAX77663_GPIO_DRIVER "max77663_gpio"/* Step-Down (SD) Regulator calculations */ #define SD_STATUS_MASK 0x30
Signature · 1 line
2.39.2
PATCH 3/3 drivers: gpio: implement PALMAS GPIO cell
In reply to Svyatoslav RyhelAdd gpio driver for TI Palmas series PMIC. This has 8 gpio which can work as input/output.
--- drivers/gpio/Kconfig | 7 ++ drivers/gpio/Makefile | 1 + drivers/gpio/palmas_gpio.c | 133 ++++++++++++++++++++++++++++++++++++ drivers/power/pmic/palmas.c | 10 ++- include/power/palmas.h | 12 ++++ 5 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 drivers/gpio/palmas_gpio.c
drivers/gpio/Kconfig +7 -0
@@ -428,6 +428,13 @@ config VYBRID_GPIO help Say yes here to support Vybrid vf610 GPIOs. +config PALMAS_GPIO + bool "TI PALMAS series PMICs GPIO" + depends on DM_GPIO && PMIC_PALMAS + help + Select this option to enable GPIO driver for the TI PALMAS + series chip family. + config PIC32_GPIO bool "Microchip PIC32 GPIO driver" depends on DM_GPIO && MACH_PIC32
drivers/gpio/Makefile +1 -0
@@ -55,6 +55,7 @@ obj-$(CONFIG_VYBRID_GPIO) += vybrid_gpio.o obj-$(CONFIG_HIKEY_GPIO) += hi6220_gpio.o obj-$(CONFIG_HSDK_CREG_GPIO) += hsdk-creg-gpio.o obj-$(CONFIG_IMX_RGPIO2P) += imx_rgpio2p.o +obj-$(CONFIG_$(SPL_)PALMAS_GPIO) += palmas_gpio.o obj-$(CONFIG_PIC32_GPIO) += pic32_gpio.o obj-$(CONFIG_OCTEON_GPIO) += octeon_gpio.o obj-$(CONFIG_MVEBU_GPIO) += mvebu_gpio.o
drivers/gpio/palmas_gpio.c new file +133 -0
133 lines not on this page · raw message
drivers/power/pmic/palmas.c +9 -1
@@ -46,7 +46,7 @@ static int palmas_read(struct udevice *dev, uint reg, uint8_t *buff, int len)static int palmas_bind (struct udevice *dev) {ofnode pmic_node =ofnode_null (), regulators_node; -ofnode subnode; +ofnode subnode, gpio_node;int children, ret;if (IS_ENABLED (CONFIG_SYSRESET_PALMAS )) {
@@ -58,6 +58,14 @@ static int palmas_bind(struct udevice *dev) } } + gpio_node =ofnode_find_subnode (dev_ofnode (dev),"gpio" ); +if (ofnode_valid (gpio_node)) { + ret =device_bind_driver_to_node (dev,PALMAS_GPIO_DRIVER , +"gpio" , gpio_node,NULL ); +if (ret) +log_err ("cannot bind GPIOs (ret = %d)\n" , ret); + } +dev_for_each_subnode (subnode, dev) {const char *name;char *temp;
include/power/palmas.h +12 -0
@@ -15,6 +15,7 @@ struct palmas_priv {#define PALMAS_LDO_DRIVER "palmas_ldo"#define PALMAS_SMPS_DRIVER "palmas_smps"#define PALMAS_RST_DRIVER "palmas_rst" +#define PALMAS_GPIO_DRIVER "palmas_gpio"#define PALMAS_SMPS_VOLT_MASK 0x7F#define PALMAS_SMPS_RANGE_MASK 0x80
@@ -35,3 +36,14 @@ struct palmas_priv {#define DEV_OFF 0x00#define PALMAS_INT3_MASK 0x1B#define MASK_VBUS BIT(7) + +/* second chip */ +#define PALMAS_GPIO_DATA_IN 0x80 +#define PALMAS_GPIO_DATA_DIR 0x81 +#define PALMAS_GPIO_DATA_OUT 0x82 +#define PALMAS_GPIO_DEBOUNCE_EN 0x83 +#define PALMAS_GPIO_CLEAR_DATA_OUT 0x84 +#define PALMAS_GPIO_SET_DATA_OUT 0x85 +#define PALMAS_PU_PD_GPIO_CTRL1 0x86 +#define PALMAS_PU_PD_GPIO_CTRL2 0x87 +#define PALMAS_OD_OUTPUT_GPIO_CTRL 0x88
Signature · 1 line
2.39.2