Re: [PATCH u-boot-mvebu v3 14/18] gpio: turris_omnia_mcu: Add support for system power off via sysreset

2024-03-28 Thread Stefan Roese

On 3/27/24 17:23, Marek Behún wrote:

Add support for system power off via UCLASS_SYSRESET. Newer versions of
Turris Omnia MCU firmware can power off the board (MCU will disable
almost all voltage regulators and go into low power mode).

Move the MCU driver into drivers/misc and register it under UCLASS_MISC.
The sysreset and gpio device are bound as child devices of the MCU device.

Signed-off-by: Marek Behún 


Reviewed-by: Stefan Roese 

Thanks,
Stefan


---
  configs/turris_omnia_defconfig|   1 +
  drivers/gpio/Kconfig  |   7 -
  drivers/gpio/Makefile |   1 -
  drivers/misc/Kconfig  |  10 ++
  drivers/misc/Makefile |   1 +
  drivers/{gpio => misc}/turris_omnia_mcu.c | 150 --
  6 files changed, 120 insertions(+), 50 deletions(-)
  rename drivers/{gpio => misc}/turris_omnia_mcu.c (60%)

diff --git a/configs/turris_omnia_defconfig b/configs/turris_omnia_defconfig
index 39e15043df..9d5171c6a8 100644
--- a/configs/turris_omnia_defconfig
+++ b/configs/turris_omnia_defconfig
@@ -113,6 +113,7 @@ CONFIG_SPL_DEBUG_UART_BASE=0xd0012000
  CONFIG_DEBUG_UART_SHIFT=2
  CONFIG_SYS_NS16550=y
  CONFIG_KIRKWOOD_SPI=y
+CONFIG_SYSRESET=y
  CONFIG_USB=y
  CONFIG_USB_XHCI_HCD=y
  CONFIG_USB_EHCI_HCD=y
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 2df3dc42d0..020c6ae74c 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -662,13 +662,6 @@ config SLG7XL45106_I2C_GPO
   8-bit gpo expander, all gpo lines are controlled by writing
   value into data register.
  
-config TURRIS_OMNIA_MCU

-   bool "Turris Omnia MCU GPIO driver"
-   depends on DM_GPIO
-   default y if TARGET_TURRIS_OMNIA
-   help
-  Support for GPIOs on MCU connected to Turris Omnia via i2c.
-
  config FTGPIO010
bool "Faraday Technology FTGPIO010 driver"
depends on DM_GPIO
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index da3da5da2b..d637895c7a 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -73,7 +73,6 @@ 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
-obj-$(CONFIG_$(SPL_TPL_)TURRIS_OMNIA_MCU)  += turris_omnia_mcu.o
  obj-$(CONFIG_FTGPIO010)   += ftgpio010.o
  obj-$(CONFIG_ADP5585_GPIO)+= adp5585_gpio.o
  obj-$(CONFIG_RZG2L_GPIO)  += rzg2l-gpio.o
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index f11ce72525..844a21be47 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -505,6 +505,16 @@ config TEST_DRV
  model. This should only be enabled for testing as it is not useful for
  anything else.
  
+config TURRIS_OMNIA_MCU

+   bool "Enable Turris Omnia MCU driver"
+   depends on DM_I2C
+   depends on DM_GPIO
+   depends on SYSRESET
+   default y if TARGET_TURRIS_OMNIA
+   help
+ This enables support for Turris Omnia MCU connected GPIOs and
+ board power off.
+
  config USB_HUB_USB251XB
tristate "USB251XB Hub Controller Configuration Driver"
depends on I2C
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 0432db6ed1..3cd8e2fd48 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -81,6 +81,7 @@ obj-$(CONFIG_SYS_DPAA_QBMAN) += fsl_portals.o
  obj-$(CONFIG_TEGRA186_BPMP) += tegra186_bpmp.o
  obj-$(CONFIG_TEGRA_CAR) += tegra_car.o
  obj-$(CONFIG_TEST_DRV) += test_drv.o
+obj-$(CONFIG_$(SPL_TPL_)TURRIS_OMNIA_MCU) += turris_omnia_mcu.o
  obj-$(CONFIG_TWL4030_LED) += twl4030_led.o
  obj-$(CONFIG_VEXPRESS_CONFIG) += vexpress_config.o
  obj-$(CONFIG_WINBOND_W83627) += winbond_w83627.o
diff --git a/drivers/gpio/turris_omnia_mcu.c b/drivers/misc/turris_omnia_mcu.c
similarity index 60%
rename from drivers/gpio/turris_omnia_mcu.c
rename to drivers/misc/turris_omnia_mcu.c
index 40ced261e3..77a0424d61 100644
--- a/drivers/gpio/turris_omnia_mcu.c
+++ b/drivers/misc/turris_omnia_mcu.c
@@ -1,9 +1,14 @@
  // SPDX-License-Identifier: GPL-2.0+
-// (C) 2022 Pali Rohár 
+/*
+ * Copyright (C) 2022 Pali Rohár 
+ * Copyright (C) 2024 Marek Behún 
+ */
  
  #include 

  #include 
+#include 
  #include 
+#include 
  #include 
  #include 
  #include 
@@ -13,9 +18,9 @@ struct turris_omnia_mcu_info {
u32 features;
  };
  
-static int turris_omnia_mcu_get_function(struct udevice *dev, uint offset)

+static int omnia_gpio_get_function(struct udevice *dev, uint offset)
  {
-   struct turris_omnia_mcu_info *info = dev_get_plat(dev);
+   struct turris_omnia_mcu_info *info = dev_get_priv(dev->parent);
  
  	switch (offset) {

/* bank 0 */
@@ -49,9 +54,9 @@ static int turris_omnia_mcu_get_function(struct udevice *dev, 
uint offset)
}
  }
  
-static int turris_omnia_mcu_get_value(struct udevice *dev, uint offset)


[PATCH u-boot-mvebu v3 14/18] gpio: turris_omnia_mcu: Add support for system power off via sysreset

2024-03-27 Thread Marek Behún
Add support for system power off via UCLASS_SYSRESET. Newer versions of
Turris Omnia MCU firmware can power off the board (MCU will disable
almost all voltage regulators and go into low power mode).

Move the MCU driver into drivers/misc and register it under UCLASS_MISC.
The sysreset and gpio device are bound as child devices of the MCU device.

Signed-off-by: Marek Behún 
---
 configs/turris_omnia_defconfig|   1 +
 drivers/gpio/Kconfig  |   7 -
 drivers/gpio/Makefile |   1 -
 drivers/misc/Kconfig  |  10 ++
 drivers/misc/Makefile |   1 +
 drivers/{gpio => misc}/turris_omnia_mcu.c | 150 --
 6 files changed, 120 insertions(+), 50 deletions(-)
 rename drivers/{gpio => misc}/turris_omnia_mcu.c (60%)

diff --git a/configs/turris_omnia_defconfig b/configs/turris_omnia_defconfig
index 39e15043df..9d5171c6a8 100644
--- a/configs/turris_omnia_defconfig
+++ b/configs/turris_omnia_defconfig
@@ -113,6 +113,7 @@ CONFIG_SPL_DEBUG_UART_BASE=0xd0012000
 CONFIG_DEBUG_UART_SHIFT=2
 CONFIG_SYS_NS16550=y
 CONFIG_KIRKWOOD_SPI=y
+CONFIG_SYSRESET=y
 CONFIG_USB=y
 CONFIG_USB_XHCI_HCD=y
 CONFIG_USB_EHCI_HCD=y
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 2df3dc42d0..020c6ae74c 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -662,13 +662,6 @@ config SLG7XL45106_I2C_GPO
   8-bit gpo expander, all gpo lines are controlled by writing
   value into data register.
 
-config TURRIS_OMNIA_MCU
-   bool "Turris Omnia MCU GPIO driver"
-   depends on DM_GPIO
-   default y if TARGET_TURRIS_OMNIA
-   help
-  Support for GPIOs on MCU connected to Turris Omnia via i2c.
-
 config FTGPIO010
bool "Faraday Technology FTGPIO010 driver"
depends on DM_GPIO
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index da3da5da2b..d637895c7a 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -73,7 +73,6 @@ 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
-obj-$(CONFIG_$(SPL_TPL_)TURRIS_OMNIA_MCU)  += turris_omnia_mcu.o
 obj-$(CONFIG_FTGPIO010)+= ftgpio010.o
 obj-$(CONFIG_ADP5585_GPIO) += adp5585_gpio.o
 obj-$(CONFIG_RZG2L_GPIO)   += rzg2l-gpio.o
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index f11ce72525..844a21be47 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -505,6 +505,16 @@ config TEST_DRV
  model. This should only be enabled for testing as it is not useful for
  anything else.
 
+config TURRIS_OMNIA_MCU
+   bool "Enable Turris Omnia MCU driver"
+   depends on DM_I2C
+   depends on DM_GPIO
+   depends on SYSRESET
+   default y if TARGET_TURRIS_OMNIA
+   help
+ This enables support for Turris Omnia MCU connected GPIOs and
+ board power off.
+
 config USB_HUB_USB251XB
tristate "USB251XB Hub Controller Configuration Driver"
depends on I2C
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 0432db6ed1..3cd8e2fd48 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -81,6 +81,7 @@ obj-$(CONFIG_SYS_DPAA_QBMAN) += fsl_portals.o
 obj-$(CONFIG_TEGRA186_BPMP) += tegra186_bpmp.o
 obj-$(CONFIG_TEGRA_CAR) += tegra_car.o
 obj-$(CONFIG_TEST_DRV) += test_drv.o
+obj-$(CONFIG_$(SPL_TPL_)TURRIS_OMNIA_MCU) += turris_omnia_mcu.o
 obj-$(CONFIG_TWL4030_LED) += twl4030_led.o
 obj-$(CONFIG_VEXPRESS_CONFIG) += vexpress_config.o
 obj-$(CONFIG_WINBOND_W83627) += winbond_w83627.o
diff --git a/drivers/gpio/turris_omnia_mcu.c b/drivers/misc/turris_omnia_mcu.c
similarity index 60%
rename from drivers/gpio/turris_omnia_mcu.c
rename to drivers/misc/turris_omnia_mcu.c
index 40ced261e3..77a0424d61 100644
--- a/drivers/gpio/turris_omnia_mcu.c
+++ b/drivers/misc/turris_omnia_mcu.c
@@ -1,9 +1,14 @@
 // SPDX-License-Identifier: GPL-2.0+
-// (C) 2022 Pali Rohár 
+/*
+ * Copyright (C) 2022 Pali Rohár 
+ * Copyright (C) 2024 Marek Behún 
+ */
 
 #include 
 #include 
+#include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -13,9 +18,9 @@ struct turris_omnia_mcu_info {
u32 features;
 };
 
-static int turris_omnia_mcu_get_function(struct udevice *dev, uint offset)
+static int omnia_gpio_get_function(struct udevice *dev, uint offset)
 {
-   struct turris_omnia_mcu_info *info = dev_get_plat(dev);
+   struct turris_omnia_mcu_info *info = dev_get_priv(dev->parent);
 
switch (offset) {
/* bank 0 */
@@ -49,9 +54,9 @@ static int turris_omnia_mcu_get_function(struct udevice *dev, 
uint offset)
}
 }
 
-static int turris_omnia_mcu_get_value(struct udevice *dev, uint offset)
+static int omnia_gpio_get_value(struct udevice *dev, uint offset)
 {
-   struct turris_omnia_mcu_info *info =