All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 00/23] DM: Cmd: GPIO/LED/STM32/CLK: provide command-line support for device-tree configured gpios and leds
@ 2016-06-18 12:55 Benjamin Tietz
  2016-06-18 12:55 ` [U-Boot] [PATCH01/23] stm32: gpio: fix otype access Benjamin Tietz
                   ` (23 more replies)
  0 siblings, 24 replies; 25+ messages in thread
From: Benjamin Tietz @ 2016-06-18 12:55 UTC (permalink / raw)
  To: u-boot

This series begins to provide device-tree support on stm32 devices,
starting with a the stack of a simple clock-driver (at least
enabling/disabling peripheral clocks), the gpio driver and leds.

As the current led command-line interface isn't aware of any device-tree
configured led, the command gets rewritten and extended for device-tree LEDs
on the way. These changes are architecture indipendent.

To accomplish these changes the led-uclass driver had to be extended, too.


The first three (bugfix-)patches had already been sent to list, but hadn't
received any reply, yet.
---

Benjamin Tietz (23):
      stm32: gpio: fix otype access
      stm32: gpio_direction_output: make sure, output is set to push-pull
      stm32: gpio_get_value: always return 0 or 1
      stm32f429-discovery: config: enable status leds
      Cmd: led: provide a selector in kconfig
      DTS: stm32f429: provide device-tree files (from linux kernel)
      driver: clock: allow disabling a peripheral clock
      Cmd: clk: make clk-command selectable in kconfig
      STM32: clock: provide dts-accessible clock driver
      DTS: STM32f429: add gpio-banks
      STM32: gpio: group SOC-specific code to one ifdef/elif construct
      GPIO: STM32: make DTS-aware
      STM32F429-discovery: led: disable board-specific code, if DM is selected
      GPIO/LED: make more robust, if STATUS_LED isn't selected
      Cmd: LED: rewrite to prepare non-static access
      DTS: STM32F429-disco: add board leds and enable rcc
      LED: add function to retrieve a device's label
      LED: provide function to count and get all (DM-)LEDs
      cmd: LED: be aware of DTS-configured leds
      LED: provide functionality to get led status
      LED: GPIO: provide get_on() op
      LED: provide toggling interface
      Cmd: LED: make DM-leds toggle


 arch/arm/dts/Makefile                 |    2 
 arch/arm/dts/armv7-m.dtsi             |   24 ++
 arch/arm/dts/stm32429i-eval.dts       |   75 ++++++
 arch/arm/dts/stm32f429-disco.dts      |   97 ++++++++
 arch/arm/dts/stm32f429.dtsi           |  282 +++++++++++++++++++++++
 board/st/stm32f429-discovery/Makefile |    3 
 cmd/Kconfig                           |    9 +
 cmd/led.c                             |  398 ++++++++++++++++++++++++---------
 drivers/clk/Kconfig                   |    4 
 drivers/clk/Makefile                  |    1 
 drivers/clk/clk-uclass.c              |   10 +
 drivers/clk/clk_stm32.c               |  112 +++++++++
 drivers/gpio/stm32_gpio.c             |  202 ++++++++++++++---
 drivers/led/led-uclass.c              |   83 +++++++
 drivers/led/led_gpio.c                |   11 +
 drivers/misc/gpio_led.c               |    4 
 drivers/misc/status_led.c             |    2 
 include/clk.h                         |   18 +
 include/configs/stm32f429-discovery.h |   14 +
 include/led.h                         |   65 +++++
 include/status_led.h                  |    4 
 21 files changed, 1279 insertions(+), 141 deletions(-)
 create mode 100644 arch/arm/dts/armv7-m.dtsi
 create mode 100644 arch/arm/dts/stm32429i-eval.dts
 create mode 100644 arch/arm/dts/stm32f429-disco.dts
 create mode 100644 arch/arm/dts/stm32f429.dtsi
 create mode 100644 drivers/clk/clk_stm32.c

--
best regards

Benjamin Tietz

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [U-Boot] [PATCH01/23] stm32: gpio: fix otype access
  2016-06-18 12:55 [U-Boot] [PATCH 00/23] DM: Cmd: GPIO/LED/STM32/CLK: provide command-line support for device-tree configured gpios and leds Benjamin Tietz
@ 2016-06-18 12:55 ` Benjamin Tietz
  2016-06-18 12:55 ` [U-Boot] [PATCH02/23] stm32: gpio_direction_output: make sure, output is set to push-pull Benjamin Tietz
                   ` (22 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Benjamin Tietz @ 2016-06-18 12:55 UTC (permalink / raw)
  To: u-boot

the GPIOx_OTYPER register has only one bit for every pin.
---
 drivers/gpio/stm32_gpio.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
-------------- next part --------------
the GPIOx_OTYPER register has only one bit for every pin.
---
 drivers/gpio/stm32_gpio.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpio/stm32_gpio.c b/drivers/gpio/stm32_gpio.c
index 50f86d3..2457211 100644
--- a/drivers/gpio/stm32_gpio.c
+++ b/drivers/gpio/stm32_gpio.c
@@ -66,7 +66,7 @@ int stm32_gpio_config(const struct stm32_gpio_dsc *dsc,
 	i = dsc->pin * 2;
 
 	clrsetbits_le32(&gpio_regs->moder, 0x3 << i, ctl->mode << i);
-	clrsetbits_le32(&gpio_regs->otyper, 0x3 << i, ctl->otype << i);
+	clrsetbits_le32(&gpio_regs->otyper, 0x1 << dsc->pin, ctl->otype << dsc->pin);
 	clrsetbits_le32(&gpio_regs->ospeedr, 0x3 << i, ctl->speed << i);
 	clrsetbits_le32(&gpio_regs->pupdr, 0x3 << i, ctl->pupd << i);
 

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [U-Boot] [PATCH02/23] stm32: gpio_direction_output: make sure, output is set to push-pull
  2016-06-18 12:55 [U-Boot] [PATCH 00/23] DM: Cmd: GPIO/LED/STM32/CLK: provide command-line support for device-tree configured gpios and leds Benjamin Tietz
  2016-06-18 12:55 ` [U-Boot] [PATCH01/23] stm32: gpio: fix otype access Benjamin Tietz
@ 2016-06-18 12:55 ` Benjamin Tietz
  2016-06-18 12:55 ` [U-Boot] [PATCH03/23] stm32: gpio_get_value: always return 0 or 1 Benjamin Tietz
                   ` (21 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Benjamin Tietz @ 2016-06-18 12:55 UTC (permalink / raw)
  To: u-boot

otherwise, the output type is uninitialized
---
 drivers/gpio/stm32_gpio.c |    1 +
 1 file changed, 1 insertion(+)
-------------- next part --------------
otherwise, the output type is uninitialized
---
 drivers/gpio/stm32_gpio.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpio/stm32_gpio.c b/drivers/gpio/stm32_gpio.c
index 2457211..d092c8f 100644
--- a/drivers/gpio/stm32_gpio.c
+++ b/drivers/gpio/stm32_gpio.c
@@ -236,6 +236,7 @@ int gpio_direction_output(unsigned gpio, int value)
 #if defined(CONFIG_STM32F4) || defined(CONFIG_STM32F7)
 	ctl.af = STM32_GPIO_AF0;
 	ctl.mode = STM32_GPIO_MODE_OUT;
+	ctl.otype = STM32_GPIO_OTYPE_PP;
 	ctl.pupd = STM32_GPIO_PUPD_NO;
 	ctl.speed = STM32_GPIO_SPEED_50M;
 #elif defined(CONFIG_STM32F1)

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [U-Boot] [PATCH03/23] stm32: gpio_get_value: always return 0 or 1
  2016-06-18 12:55 [U-Boot] [PATCH 00/23] DM: Cmd: GPIO/LED/STM32/CLK: provide command-line support for device-tree configured gpios and leds Benjamin Tietz
  2016-06-18 12:55 ` [U-Boot] [PATCH01/23] stm32: gpio: fix otype access Benjamin Tietz
  2016-06-18 12:55 ` [U-Boot] [PATCH02/23] stm32: gpio_direction_output: make sure, output is set to push-pull Benjamin Tietz
@ 2016-06-18 12:55 ` Benjamin Tietz
  2016-06-18 12:55 ` [U-Boot] [PATCH04/23] stm32f429-discovery: config: enable status leds Benjamin Tietz
                   ` (20 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Benjamin Tietz @ 2016-06-18 12:55 UTC (permalink / raw)
  To: u-boot

Previously, a set gpio had returned any power of 2. Some function check for 1 explicitly.
---
 drivers/gpio/stm32_gpio.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
-------------- next part --------------
Previously, a set gpio had returned any power of 2. Some function check for 1 explicitly.
---
 drivers/gpio/stm32_gpio.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpio/stm32_gpio.c b/drivers/gpio/stm32_gpio.c
index d092c8f..516dfcc 100644
--- a/drivers/gpio/stm32_gpio.c
+++ b/drivers/gpio/stm32_gpio.c
@@ -263,7 +263,7 @@ int gpio_get_value(unsigned gpio)
 	dsc.port = stm32_gpio_to_port(gpio);
 	dsc.pin = stm32_gpio_to_pin(gpio);
 
-	return stm32_gpin_get(&dsc);
+	return !!stm32_gpin_get(&dsc);
 }
 
 int gpio_set_value(unsigned gpio, int value)

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [U-Boot] [PATCH04/23] stm32f429-discovery: config: enable status leds
  2016-06-18 12:55 [U-Boot] [PATCH 00/23] DM: Cmd: GPIO/LED/STM32/CLK: provide command-line support for device-tree configured gpios and leds Benjamin Tietz
                   ` (2 preceding siblings ...)
  2016-06-18 12:55 ` [U-Boot] [PATCH03/23] stm32: gpio_get_value: always return 0 or 1 Benjamin Tietz
@ 2016-06-18 12:55 ` Benjamin Tietz
  2016-06-18 12:55 ` [U-Boot] [PATCH05/23] Cmd: led: provide a selector in kconfig Benjamin Tietz
                   ` (19 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Benjamin Tietz @ 2016-06-18 12:55 UTC (permalink / raw)
  To: u-boot

From: Benjamin Tietz <benjamin@micronet24.de>


---
 include/configs/stm32f429-discovery.h |    8 ++++++++
 1 file changed, 8 insertions(+)
-------------- next part --------------
From: Benjamin Tietz <benjamin@micronet24.de>


---
 include/configs/stm32f429-discovery.h |    8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/include/configs/stm32f429-discovery.h b/include/configs/stm32f429-discovery.h
index 8bbe580..9d275c0 100644
--- a/include/configs/stm32f429-discovery.h
+++ b/include/configs/stm32f429-discovery.h
@@ -45,6 +45,14 @@
 #define CONFIG_BOARD_SPECIFIC_LED
 #define CONFIG_RED_LED			110
 #define CONFIG_GREEN_LED		109
+#define CONFIG_GPIO_LED		1
+#define CONFIG_STATUS_LED
+#define STATUS_LED_BIT		CONFIG_RED_LED
+#define STATUS_LED_STATE	0
+#define STATUS_LED_PERIOD	0
+#define STATUS_LED_BIT1		CONFIG_GREEN_LED
+#define STATUS_LED_STATE1	0
+#define STATUS_LED_PERIOD1	0
 
 #define CONFIG_STM32_GPIO
 #define CONFIG_STM32_FLASH

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [U-Boot] [PATCH05/23] Cmd: led: provide a selector in kconfig
  2016-06-18 12:55 [U-Boot] [PATCH 00/23] DM: Cmd: GPIO/LED/STM32/CLK: provide command-line support for device-tree configured gpios and leds Benjamin Tietz
                   ` (3 preceding siblings ...)
  2016-06-18 12:55 ` [U-Boot] [PATCH04/23] stm32f429-discovery: config: enable status leds Benjamin Tietz
@ 2016-06-18 12:55 ` Benjamin Tietz
  2016-06-18 12:55 ` [U-Boot] [PATCH06/23] DTS: stm32f429: provide device-tree files (from linux kernel) Benjamin Tietz
                   ` (18 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Benjamin Tietz @ 2016-06-18 12:55 UTC (permalink / raw)
  To: u-boot

From: Benjamin Tietz <benjamin@micronet24.de>


---
 cmd/Kconfig |    4 ++++
 1 file changed, 4 insertions(+)
-------------- next part --------------
From: Benjamin Tietz <benjamin@micronet24.de>


---
 cmd/Kconfig |    4 ++++
 1 file changed, 4 insertions(+)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index d51645c..f49ff47 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -421,6 +421,10 @@ config CMD_GPIO
 	help
 	  GPIO support.
 
+config CMD_LED
+	bool "led"
+	help
+	  support for accessing and toggeling LEDs
 endmenu
 
 

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [U-Boot] [PATCH06/23] DTS: stm32f429: provide device-tree files (from linux kernel)
  2016-06-18 12:55 [U-Boot] [PATCH 00/23] DM: Cmd: GPIO/LED/STM32/CLK: provide command-line support for device-tree configured gpios and leds Benjamin Tietz
                   ` (4 preceding siblings ...)
  2016-06-18 12:55 ` [U-Boot] [PATCH05/23] Cmd: led: provide a selector in kconfig Benjamin Tietz
@ 2016-06-18 12:55 ` Benjamin Tietz
  2016-06-18 12:56 ` [U-Boot] [PATCH07/23] driver: clock: allow disabling a peripheral clock Benjamin Tietz
                   ` (17 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Benjamin Tietz @ 2016-06-18 12:55 UTC (permalink / raw)
  To: u-boot

From: Benjamin Tietz <benjamin@micronet24.de>


---
 arch/arm/dts/Makefile            |    2 
 arch/arm/dts/armv7-m.dtsi        |   24 +++++
 arch/arm/dts/stm32429i-eval.dts  |   75 +++++++++++++++
 arch/arm/dts/stm32f429-disco.dts |   75 +++++++++++++++
 arch/arm/dts/stm32f429.dtsi      |  190 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 366 insertions(+)
 create mode 100644 arch/arm/dts/armv7-m.dtsi
 create mode 100644 arch/arm/dts/stm32429i-eval.dts
 create mode 100644 arch/arm/dts/stm32f429-disco.dts
 create mode 100644 arch/arm/dts/stm32f429.dtsi
-------------- next part --------------
From: Benjamin Tietz <benjamin@micronet24.de>


---
 arch/arm/dts/Makefile            |    2 
 arch/arm/dts/armv7-m.dtsi        |   24 +++++
 arch/arm/dts/stm32429i-eval.dts  |   75 +++++++++++++++
 arch/arm/dts/stm32f429-disco.dts |   75 +++++++++++++++
 arch/arm/dts/stm32f429.dtsi      |  190 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 366 insertions(+)
 create mode 100644 arch/arm/dts/armv7-m.dtsi
 create mode 100644 arch/arm/dts/stm32429i-eval.dts
 create mode 100644 arch/arm/dts/stm32f429-disco.dts
 create mode 100644 arch/arm/dts/stm32f429.dtsi

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index a827613..ff5fe03 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -103,6 +103,8 @@ dtb-$(CONFIG_AM43XX) += am437x-gp-evm.dtb am437x-sk-evm.dtb	\
 	am437x-idk-evm.dtb
 dtb-$(CONFIG_THUNDERX) += thunderx-88xx.dtb
 
+dtb-$(CONFIG_STM32F4) += stm32f429-disco.dtb
+
 dtb-$(CONFIG_ARCH_SOCFPGA) +=				\
 	socfpga_arria5_socdk.dtb			\
 	socfpga_cyclone5_mcvevk.dtb			\
diff --git a/arch/arm/dts/armv7-m.dtsi b/arch/arm/dts/armv7-m.dtsi
new file mode 100644
index 0000000..b1ad7cf
--- /dev/null
+++ b/arch/arm/dts/armv7-m.dtsi
@@ -0,0 +1,24 @@
+#include "skeleton.dtsi"
+
+/ {
+	nvic: nv-interrupt-controller  {
+		compatible = "arm,armv7m-nvic";
+		interrupt-controller;
+		#interrupt-cells = <1>;
+		reg = <0xe000e100 0xc00>;
+	};
+
+	systick: timer at e000e010 {
+		compatible = "arm,armv7m-systick";
+		reg = <0xe000e010 0x10>;
+		status = "disabled";
+	};
+
+	soc {
+		#address-cells = <1>;
+		#size-cells = <1>;
+		compatible = "simple-bus";
+		interrupt-parent = <&nvic>;
+		ranges;
+	};
+};
diff --git a/arch/arm/dts/stm32429i-eval.dts b/arch/arm/dts/stm32429i-eval.dts
new file mode 100644
index 0000000..6964fc9
--- /dev/null
+++ b/arch/arm/dts/stm32429i-eval.dts
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2015 - Maxime Coquelin <mcoquelin.stm32@gmail.com>
+ *
+ * This file is dual-licensed: you can use it either under the terms
+ * of the GPL or the X11 license, at your option. Note that this dual
+ * licensing only applies to this file, and not this project as a
+ * whole.
+ *
+ *  a) This file is free software; you can redistribute it and/or
+ *     modify it under the terms of the GNU General Public License as
+ *     published by the Free Software Foundation; either version 2 of the
+ *     License, or (at your option) any later version.
+ *
+ *     This file is distributed in the hope that it will be useful,
+ *     but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *     GNU General Public License for more details.
+ *
+ *     You should have received a copy of the GNU General Public
+ *     License along with this file; if not, write to the Free
+ *     Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ *     MA 02110-1301 USA
+ *
+ * Or, alternatively,
+ *
+ *  b) Permission is hereby granted, free of charge, to any person
+ *     obtaining a copy of this software and associated documentation
+ *     files (the "Software"), to deal in the Software without
+ *     restriction, including without limitation the rights to use,
+ *     copy, modify, merge, publish, distribute, sublicense, and/or
+ *     sell copies of the Software, and to permit persons to whom the
+ *     Software is furnished to do so, subject to the following
+ *     conditions:
+ *
+ *     The above copyright notice and this permission notice shall be
+ *     included in all copies or substantial portions of the Software.
+ *
+ *     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ *     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ *     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ *     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ *     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ *     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ *     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ *     OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/dts-v1/;
+#include "stm32f429.dtsi"
+
+/ {
+	model = "STMicroelectronics STM32429i-EVAL board";
+	compatible = "st,stm32429i-eval", "st,stm32f429";
+
+	chosen {
+		bootargs = "root=/dev/ram rdinit=/linuxrc";
+		stdout-path = "serial0:115200n8";
+	};
+
+	memory {
+		reg = <0xc0000000 0x2000000>;
+	};
+
+	aliases {
+		serial0 = &usart1;
+	};
+};
+
+&clk_hse {
+	clock-frequency = <25000000>;
+};
+
+&usart1 {
+	status = "okay";
+};
diff --git a/arch/arm/dts/stm32f429-disco.dts b/arch/arm/dts/stm32f429-disco.dts
new file mode 100644
index 0000000..2bae81c
--- /dev/null
+++ b/arch/arm/dts/stm32f429-disco.dts
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2015 - Maxime Coquelin <mcoquelin.stm32@gmail.com>
+ *
+ * This file is dual-licensed: you can use it either under the terms
+ * of the GPL or the X11 license, at your option. Note that this dual
+ * licensing only applies to this file, and not this project as a
+ * whole.
+ *
+ *  a) This file is free software; you can redistribute it and/or
+ *     modify it under the terms of the GNU General Public License as
+ *     published by the Free Software Foundation; either version 2 of the
+ *     License, or (at your option) any later version.
+ *
+ *     This file is distributed in the hope that it will be useful,
+ *     but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *     GNU General Public License for more details.
+ *
+ *     You should have received a copy of the GNU General Public
+ *     License along with this file; if not, write to the Free
+ *     Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ *     MA 02110-1301 USA
+ *
+ * Or, alternatively,
+ *
+ *  b) Permission is hereby granted, free of charge, to any person
+ *     obtaining a copy of this software and associated documentation
+ *     files (the "Software"), to deal in the Software without
+ *     restriction, including without limitation the rights to use,
+ *     copy, modify, merge, publish, distribute, sublicense, and/or
+ *     sell copies of the Software, and to permit persons to whom the
+ *     Software is furnished to do so, subject to the following
+ *     conditions:
+ *
+ *     The above copyright notice and this permission notice shall be
+ *     included in all copies or substantial portions of the Software.
+ *
+ *     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ *     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ *     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ *     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ *     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ *     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ *     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ *     OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/dts-v1/;
+#include "stm32f429.dtsi"
+
+/ {
+	model = "STMicroelectronics STM32F429i-DISCO board";
+	compatible = "st,stm32f429i-disco", "st,stm32f429";
+
+	chosen {
+		bootargs = "root=/dev/ram";
+		stdout-path = "serial0:115200n8";
+	};
+
+	memory {
+		reg = <0x90000000 0x800000>;
+	};
+
+	aliases {
+		serial0 = &usart1;
+	};
+};
+
+&clk_hse {
+	clock-frequency = <8000000>;
+};
+
+&usart1 {
+	status = "okay";
+};
diff --git a/arch/arm/dts/stm32f429.dtsi b/arch/arm/dts/stm32f429.dtsi
new file mode 100644
index 0000000..5e1e234
--- /dev/null
+++ b/arch/arm/dts/stm32f429.dtsi
@@ -0,0 +1,190 @@
+/*
+ * Copyright 2015 - Maxime Coquelin <mcoquelin.stm32@gmail.com>
+ *
+ * This file is dual-licensed: you can use it either under the terms
+ * of the GPL or the X11 license, at your option. Note that this dual
+ * licensing only applies to this file, and not this project as a
+ * whole.
+ *
+ *  a) This file is free software; you can redistribute it and/or
+ *     modify it under the terms of the GNU General Public License as
+ *     published by the Free Software Foundation; either version 2 of the
+ *     License, or (at your option) any later version.
+ *
+ *     This file is distributed in the hope that it will be useful,
+ *     but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *     GNU General Public License for more details.
+ *
+ *     You should have received a copy of the GNU General Public
+ *     License along with this file; if not, write to the Free
+ *     Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ *     MA 02110-1301 USA
+ *
+ * Or, alternatively,
+ *
+ *  b) Permission is hereby granted, free of charge, to any person
+ *     obtaining a copy of this software and associated documentation
+ *     files (the "Software"), to deal in the Software without
+ *     restriction, including without limitation the rights to use,
+ *     copy, modify, merge, publish, distribute, sublicense, and/or
+ *     sell copies of the Software, and to permit persons to whom the
+ *     Software is furnished to do so, subject to the following
+ *     conditions:
+ *
+ *     The above copyright notice and this permission notice shall be
+ *     included in all copies or substantial portions of the Software.
+ *
+ *     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ *     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ *     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ *     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ *     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ *     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ *     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ *     OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "armv7-m.dtsi"
+
+/ {
+	clocks {
+		clk_hse: clk-hse {
+			#clock-cells = <0>;
+			compatible = "fixed-clock";
+			clock-frequency = <0>;
+		};
+	};
+
+	soc {
+		timer2: timer at 40000000 {
+			compatible = "st,stm32-timer";
+			reg = <0x40000000 0x400>;
+			interrupts = <28>;
+			clocks = <&rcc 0 128>;
+			status = "disabled";
+		};
+
+		timer3: timer at 40000400 {
+			compatible = "st,stm32-timer";
+			reg = <0x40000400 0x400>;
+			interrupts = <29>;
+			clocks = <&rcc 0 129>;
+			status = "disabled";
+		};
+
+		timer4: timer at 40000800 {
+			compatible = "st,stm32-timer";
+			reg = <0x40000800 0x400>;
+			interrupts = <30>;
+			clocks = <&rcc 0 130>;
+			status = "disabled";
+		};
+
+		timer5: timer at 40000c00 {
+			compatible = "st,stm32-timer";
+			reg = <0x40000c00 0x400>;
+			interrupts = <50>;
+			clocks = <&rcc 0 131>;
+		};
+
+		timer6: timer at 40001000 {
+			compatible = "st,stm32-timer";
+			reg = <0x40001000 0x400>;
+			interrupts = <54>;
+			clocks = <&rcc 0 132>;
+			status = "disabled";
+		};
+
+		timer7: timer at 40001400 {
+			compatible = "st,stm32-timer";
+			reg = <0x40001400 0x400>;
+			interrupts = <55>;
+			clocks = <&rcc 0 133>;
+			status = "disabled";
+		};
+
+		usart2: serial at 40004400 {
+			compatible = "st,stm32-usart", "st,stm32-uart";
+			reg = <0x40004400 0x400>;
+			interrupts = <38>;
+			clocks =  <&rcc 0 145>;
+			status = "disabled";
+		};
+
+		usart3: serial at 40004800 {
+			compatible = "st,stm32-usart", "st,stm32-uart";
+			reg = <0x40004800 0x400>;
+			interrupts = <39>;
+			clocks = <&rcc 0 146>;
+			status = "disabled";
+		};
+
+		usart4: serial at 40004c00 {
+			compatible = "st,stm32-uart";
+			reg = <0x40004c00 0x400>;
+			interrupts = <52>;
+			clocks = <&rcc 0 147>;
+			status = "disabled";
+		};
+
+		usart5: serial at 40005000 {
+			compatible = "st,stm32-uart";
+			reg = <0x40005000 0x400>;
+			interrupts = <53>;
+			clocks = <&rcc 0 148>;
+			status = "disabled";
+		};
+
+		usart7: serial at 40007800 {
+			compatible = "st,stm32-usart", "st,stm32-uart";
+			reg = <0x40007800 0x400>;
+			interrupts = <82>;
+			clocks = <&rcc 0 158>;
+			status = "disabled";
+		};
+
+		usart8: serial at 40007c00 {
+			compatible = "st,stm32-usart", "st,stm32-uart";
+			reg = <0x40007c00 0x400>;
+			interrupts = <83>;
+			clocks = <&rcc 0 159>;
+			status = "disabled";
+		};
+
+		usart1: serial at 40011000 {
+			compatible = "st,stm32-usart", "st,stm32-uart";
+			reg = <0x40011000 0x400>;
+			interrupts = <37>;
+			clocks = <&rcc 0 164>;
+			status = "disabled";
+		};
+
+		usart6: serial at 40011400 {
+			compatible = "st,stm32-usart", "st,stm32-uart";
+			reg = <0x40011400 0x400>;
+			interrupts = <71>;
+			clocks = <&rcc 0 165>;
+			status = "disabled";
+		};
+
+		rcc: rcc at 40023810 {
+			#clock-cells = <2>;
+			compatible = "st,stm32f42xx-rcc", "st,stm32-rcc";
+			reg = <0x40023800 0x400>;
+			clocks = <&clk_hse>;
+		};
+
+		rng: rng at 50060800 {
+			compatible = "st,stm32-rng";
+			reg = <0x50060800 0x400>;
+			interrupts = <80>;
+			clocks = <&rcc 0 38>;
+		};
+	};
+};
+
+&systick {
+	clocks = <&rcc 1 0>;
+	status = "okay";
+};

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [U-Boot] [PATCH07/23] driver: clock: allow disabling a peripheral clock
  2016-06-18 12:55 [U-Boot] [PATCH 00/23] DM: Cmd: GPIO/LED/STM32/CLK: provide command-line support for device-tree configured gpios and leds Benjamin Tietz
                   ` (5 preceding siblings ...)
  2016-06-18 12:55 ` [U-Boot] [PATCH06/23] DTS: stm32f429: provide device-tree files (from linux kernel) Benjamin Tietz
@ 2016-06-18 12:56 ` Benjamin Tietz
  2016-06-18 12:56 ` [U-Boot] [PATCH08/23] Cmd: clk: make clk-command selectable in kconfig Benjamin Tietz
                   ` (16 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Benjamin Tietz @ 2016-06-18 12:56 UTC (permalink / raw)
  To: u-boot

From: Benjamin Tietz <benjamin@micronet24.de>


---
 drivers/clk/clk-uclass.c |   10 ++++++++++
 include/clk.h            |   18 ++++++++++++++++++
 2 files changed, 28 insertions(+)
-------------- next part --------------
From: Benjamin Tietz <benjamin@micronet24.de>


---
 drivers/clk/clk-uclass.c |   10 ++++++++++
 include/clk.h            |   18 ++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index b483c1e..462f5f8 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -44,6 +44,16 @@ int clk_enable(struct udevice *dev, int periph)
 	return ops->enable(dev, periph);
 }
 
+int clk_disable(struct udevice *dev, int periph)
+{
+	struct clk_ops *ops = clk_get_ops(dev);
+
+	if (!ops->disable)
+		return -ENOSYS;
+
+	return ops->disable(dev, periph);
+}
+
 ulong clk_get_periph_rate(struct udevice *dev, int periph)
 {
 	struct clk_ops *ops = clk_get_ops(dev);
diff --git a/include/clk.h b/include/clk.h
index ca20c3d..395f813 100644
--- a/include/clk.h
+++ b/include/clk.h
@@ -43,6 +43,15 @@ struct clk_ops {
 	int (*enable)(struct udevice *dev, int periph);
 
 	/**
+	 * disable() - Disable the clock for a peripheral
+	 *
+	 * @dev:	clock provider
+	 * @periph:	Peripheral ID to enable
+	 * @return zero on success, or -ve error code
+	 */
+	int (*disable)(struct udevice *dev, int periph);
+
+	/**
 	 * get_periph_rate() - Get clock rate for a peripheral
 	 *
 	 * @dev:	Device to check (UCLASS_CLK)
@@ -90,6 +99,15 @@ ulong clk_set_rate(struct udevice *dev, ulong rate);
 int clk_enable(struct udevice *dev, int periph);
 
 /**
+ * clk_disable() - Disable the clock for a peripheral
+ *
+ * @dev:	clock provider
+ * @periph:	Peripheral ID to enable
+ * @return zero on success, or -ve error code
+ */
+int clk_disable(struct udevice *dev, int periph);
+
+/**
  * clk_get_periph_rate() - Get current clock rate for a peripheral
  *
  * @dev:	Device to check (UCLASS_CLK)

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [U-Boot] [PATCH08/23] Cmd: clk: make clk-command selectable in kconfig
  2016-06-18 12:55 [U-Boot] [PATCH 00/23] DM: Cmd: GPIO/LED/STM32/CLK: provide command-line support for device-tree configured gpios and leds Benjamin Tietz
                   ` (6 preceding siblings ...)
  2016-06-18 12:56 ` [U-Boot] [PATCH07/23] driver: clock: allow disabling a peripheral clock Benjamin Tietz
@ 2016-06-18 12:56 ` Benjamin Tietz
  2016-06-18 12:56 ` [U-Boot] [PATCH09/23] STM32: clock: provide dts-accessible clock driver Benjamin Tietz
                   ` (15 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Benjamin Tietz @ 2016-06-18 12:56 UTC (permalink / raw)
  To: u-boot

From: Benjamin Tietz <benjamin@micronet24.de>


---
 cmd/Kconfig |    5 +++++
 1 file changed, 5 insertions(+)
-------------- next part --------------
From: Benjamin Tietz <benjamin@micronet24.de>


---
 cmd/Kconfig |    5 +++++
 1 file changed, 5 insertions(+)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index f49ff47..ec9d6ed 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -124,6 +124,11 @@ config CMD_BDI
 	help
 	  Print board info
 
+config CMD_CLK
+	bool "clock"
+	help
+	  print clock frequencies
+
 config CMD_CONSOLE
 	bool "coninfo"
 	default y

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [U-Boot] [PATCH09/23] STM32: clock: provide dts-accessible clock driver
  2016-06-18 12:55 [U-Boot] [PATCH 00/23] DM: Cmd: GPIO/LED/STM32/CLK: provide command-line support for device-tree configured gpios and leds Benjamin Tietz
                   ` (7 preceding siblings ...)
  2016-06-18 12:56 ` [U-Boot] [PATCH08/23] Cmd: clk: make clk-command selectable in kconfig Benjamin Tietz
@ 2016-06-18 12:56 ` Benjamin Tietz
  2016-06-18 12:56 ` [U-Boot] [PATCH10/23] DTS: STM32f429: add gpio-banks Benjamin Tietz
                   ` (14 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Benjamin Tietz @ 2016-06-18 12:56 UTC (permalink / raw)
  To: u-boot

From: Benjamin Tietz <benjamin@micronet24.de>


---
 drivers/clk/Kconfig     |    4 ++
 drivers/clk/Makefile    |    1 
 drivers/clk/clk_stm32.c |  112 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 117 insertions(+)
 create mode 100644 drivers/clk/clk_stm32.c
-------------- next part --------------
From: Benjamin Tietz <benjamin@micronet24.de>


---
 drivers/clk/Kconfig     |    4 ++
 drivers/clk/Makefile    |    1 
 drivers/clk/clk_stm32.c |  112 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 117 insertions(+)
 create mode 100644 drivers/clk/clk_stm32.c

diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index 6eee8eb..ebef031 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -23,4 +23,8 @@ config SPL_CLK
 source "drivers/clk/uniphier/Kconfig"
 source "drivers/clk/exynos/Kconfig"
 
+config CLK_STM32
+	bool "Enable clock driver for STM32 devices"
+	depends on CLK
+
 endmenu
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index 81fe600..e7fd05a 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -12,3 +12,4 @@ obj-$(CONFIG_SANDBOX) += clk_sandbox.o
 obj-$(CONFIG_MACH_PIC32) += clk_pic32.o
 obj-$(CONFIG_CLK_UNIPHIER) += uniphier/
 obj-$(CONFIG_CLK_EXYNOS) += exynos/
+obj-$(CONFIG_CLK_STM32) += clk_stm32.o
diff --git a/drivers/clk/clk_stm32.c b/drivers/clk/clk_stm32.c
new file mode 100644
index 0000000..b707270
--- /dev/null
+++ b/drivers/clk/clk_stm32.c
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2016 Benjamin Tietz <uboot@dresden.micronet24.de>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ *
+ */
+#include <common.h>
+#include <clk.h>
+#include <dm.h>
+#include <asm/io.h>
+#include <asm/arch/stm32.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct stm32_rcc_clk_priv {
+	struct stm32_rcc_regs *regs;
+};
+
+#define PLLCFGR_PLLN(reg)	(((reg)>>6)&0x1ff)
+#define PLLCFGR_PLLM(reg)	(((reg)>>0)&0x3f)
+#define PLLCFGR_PLLP(reg)	(((reg)>>16)&0x3)
+#define PLLCFGR_PLLQ(reg)	(((reg)>>24)&0x0f)
+#define PLLCFGR_HSE(reg)	(reg & (1<<22))
+
+static long stm32_rcc_get_vco_rate(struct udevice *dev, u32 *regptr) {
+	struct stm32_rcc_clk_priv *data = dev_get_priv(dev);
+	long freq = 16000000;
+	if(!(data && data->regs))
+		return -EINVAL;
+	u32 reg = readl(&data->regs->pllcfgr);
+	if(regptr) *regptr = reg;
+	if(PLLCFGR_HSE(reg)) {
+		struct udevice *pclk;
+		int ret;
+		if((ret = clk_get_by_index(dev, 0, &pclk)) < 0)
+			return ret;
+
+		freq = clk_get_rate(pclk);
+	}
+	if(freq < 0) return freq;
+	return freq * PLLCFGR_PLLM(reg) / PLLCFGR_PLLN(reg);
+}
+
+static ulong stm32_rcc_get_rate(struct udevice *dev) {
+	u32 reg = 0;
+	long freq = stm32_rcc_get_vco_rate(dev, &reg);
+	if(freq < 0) return freq;
+	return freq * PLLCFGR_PLLP(reg);
+}
+
+static int stm32_rcc_xxable(struct udevice *dev, int periph, int on) {
+	struct stm32_rcc_clk_priv *data = dev_get_priv(dev);
+	if(!(data && data->regs))
+		return -EINVAL;
+
+	int port = periph >> 5;
+	int bit = periph & 0x1f;
+	if(port >= 8)
+		return -ENOSYS;
+
+	u32 *enr = &data->regs->ahb1enr;
+	on ? 
+		setbits_le32(&enr[port], 1<<bit):
+		clrbits_le32(&enr[port], 1<<bit);
+	return 0;
+}
+
+static int stm32_rcc_enable(struct udevice *dev, int periph) {
+	return stm32_rcc_xxable(dev, periph, 1);
+}
+
+static int stm32_rcc_disable(struct udevice *dev, int periph) {
+	return stm32_rcc_xxable(dev, periph, 0);
+}
+
+static struct clk_ops stm32_rcc_clk_ops = {
+	.get_rate = stm32_rcc_get_rate,
+	.enable = stm32_rcc_enable,
+	.disable = stm32_rcc_disable,
+};
+
+static int stm32_rcc_clk_probe(struct udevice *dev) {
+	struct stm32_rcc_clk_priv *priv = dev_get_priv(dev);
+	fdt_addr_t addr;
+	fdt_size_t size;
+
+	addr = fdtdec_get_addr_size(gd->fdt_blob, dev->of_offset, "reg", &size);
+	if (addr == FDT_ADDR_T_NONE)
+		return -EINVAL;
+
+	if(size < sizeof(*priv->regs))
+		return -EINVAL;
+
+	priv->regs = (struct stm32_rcc_regs *) addr;
+
+	return 0;
+}
+
+static const struct udevice_id stm32_rcc_clk_ids[] = {
+	{ .compatible = "st,stm32f42xx-rcc", },
+	{}
+};
+
+U_BOOT_DRIVER(stm32_rcc_clk) = {
+	.name		= "stm32_rcc_clk",
+	.id		= UCLASS_CLK,
+	.of_match	= stm32_rcc_clk_ids,
+	.flags		= DM_FLAG_PRE_RELOC,
+	.ops		= &stm32_rcc_clk_ops,
+	.probe		= stm32_rcc_clk_probe,
+	.priv_auto_alloc_size = sizeof(struct stm32_rcc_clk_priv),
+};

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [U-Boot] [PATCH10/23] DTS: STM32f429: add gpio-banks
  2016-06-18 12:55 [U-Boot] [PATCH 00/23] DM: Cmd: GPIO/LED/STM32/CLK: provide command-line support for device-tree configured gpios and leds Benjamin Tietz
                   ` (8 preceding siblings ...)
  2016-06-18 12:56 ` [U-Boot] [PATCH09/23] STM32: clock: provide dts-accessible clock driver Benjamin Tietz
@ 2016-06-18 12:56 ` Benjamin Tietz
  2016-06-18 12:56 ` [U-Boot] [PATCH11/23] STM32: gpio: group SOC-specific code to one ifdef/elif construct Benjamin Tietz
                   ` (13 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Benjamin Tietz @ 2016-06-18 12:56 UTC (permalink / raw)
  To: u-boot

From: Benjamin Tietz <benjamin@micronet24.de>


---
 arch/arm/dts/stm32f429.dtsi |   92 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 92 insertions(+)
-------------- next part --------------
From: Benjamin Tietz <benjamin@micronet24.de>


---
 arch/arm/dts/stm32f429.dtsi |   92 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 92 insertions(+)

diff --git a/arch/arm/dts/stm32f429.dtsi b/arch/arm/dts/stm32f429.dtsi
index 5e1e234..0d032fb 100644
--- a/arch/arm/dts/stm32f429.dtsi
+++ b/arch/arm/dts/stm32f429.dtsi
@@ -57,6 +57,98 @@
 	};
 
 	soc {
+		gpioA:	gpio at 40020000 {
+			#gpio-cells = <1>;
+			gpio-controller;
+			compatible = "st,stm32-gpio";
+			reg = <0x40020000 0x400>;
+			clocks = <&rcc 0 0>;
+		};
+
+		gpioB:	gpio at 40020400 {
+			#gpio-cells = <1>;
+			gpio-controller;
+			compatible = "st,stm32-gpio";
+			reg = <0x40020400 0x400>;
+			clocks = <&rcc 0 1>;
+		};
+
+		gpioC:	gpio at 40020800 {
+			#gpio-cells = <1>;
+			gpio-controller;
+			compatible = "st,stm32-gpio";
+			reg = <0x40020800 0x400>;
+			clocks = <&rcc 0 2>;
+		};
+
+		gpioD:	gpio at 40020c00 {
+			#gpio-cells = <1>;
+			gpio-controller;
+			compatible = "st,stm32-gpio";
+			reg = <0x40020c00 0x400>;
+			clocks = <&rcc 0 3>;
+		};
+
+		gpioE:	gpio at 40021000 {
+			#gpio-cells = <1>;
+			gpio-controller;
+			compatible = "st,stm32-gpio";
+			reg = <0x40021000 0x400>;
+			clocks = <&rcc 0 4>;
+		};
+
+		gpioF:	gpio at 40021400 {
+			#gpio-cells = <1>;
+			gpio-controller;
+			compatible = "st,stm32-gpio";
+			reg = <0x40021400 0x400>;
+			clocks = <&rcc 0 5>;
+		};
+
+		gpioG:	gpio at 40021800 {
+			#gpio-cells = <1>;
+			gpio-controller;
+			compatible = "st,stm32-gpio";
+			reg = <0x40021800 0x400>;
+			clocks = <&rcc 0 6>;
+		};
+
+		gpioH:	gpio at 40021c00 {
+			#gpio-cells = <1>;
+			gpio-count = <2>;
+			gpio-controller;
+			compatible = "st,stm32-gpio";
+			reg = <0x40021c00 0x400>;
+			clocks = <&rcc 0 7>;
+		};
+
+		gpioI:	gpio at 40022000 {
+			#gpio-cells = <1>;
+			gpio-controller;
+			compatible = "st,stm32-gpio";
+			reg = <0x40022000 0x400>;
+			clocks = <&rcc 0 8>;
+			status = "disabled";
+		};
+
+		gpioJ:	gpio at 40022400 {
+			#gpio-cells = <1>;
+			gpio-controller;
+			compatible = "st,stm32-gpio";
+			reg = <0x40022400 0x400>;
+			clocks = <&rcc 0 9>;
+			status = "disabled";
+		};
+
+		gpioK:	gpio at 40022800 {
+			#gpio-cells = <1>;
+			gpio-controller;
+			compatible = "st,stm32-gpio";
+			reg = <0x40022800 0x400>;
+			clocks = <&rcc 0 10>;
+			status = "disabled";
+		};
+
 		timer2: timer at 40000000 {
 			compatible = "st,stm32-timer";
 			reg = <0x40000000 0x400>;

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [U-Boot] [PATCH11/23] STM32: gpio: group SOC-specific code to one ifdef/elif construct
  2016-06-18 12:55 [U-Boot] [PATCH 00/23] DM: Cmd: GPIO/LED/STM32/CLK: provide command-line support for device-tree configured gpios and leds Benjamin Tietz
                   ` (9 preceding siblings ...)
  2016-06-18 12:56 ` [U-Boot] [PATCH10/23] DTS: STM32f429: add gpio-banks Benjamin Tietz
@ 2016-06-18 12:56 ` Benjamin Tietz
  2016-06-18 12:56 ` [U-Boot] [PATCH12/23] GPIO: STM32: make DTS-aware Benjamin Tietz
                   ` (12 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Benjamin Tietz @ 2016-06-18 12:56 UTC (permalink / raw)
  To: u-boot

From: Benjamin Tietz <benjamin@micronet24.de>


---
 drivers/gpio/stm32_gpio.c |   66 +++++++++++++++++++++++----------------------
 1 file changed, 34 insertions(+), 32 deletions(-)
-------------- next part --------------
From: Benjamin Tietz <benjamin@micronet24.de>


---
 drivers/gpio/stm32_gpio.c |   66 +++++++++++++++++++++++----------------------
 1 file changed, 34 insertions(+), 32 deletions(-)

diff --git a/drivers/gpio/stm32_gpio.c b/drivers/gpio/stm32_gpio.c
index 516dfcc..be662c3 100644
--- a/drivers/gpio/stm32_gpio.c
+++ b/drivers/gpio/stm32_gpio.c
@@ -74,6 +74,23 @@ int stm32_gpio_config(const struct stm32_gpio_dsc *dsc,
 out:
 	return rv;
 }
+
+static struct stm32_gpio_ctl ctl_in = {
+	.af = STM32_GPIO_AF0,
+	.mode = STM32_GPIO_MODE_IN,
+	.otype = STM32_GPIO_OTYPE_PP,
+	.pupd = STM32_GPIO_PUPD_NO,
+	.speed = STM32_GPIO_SPEED_50M,
+};
+
+static struct stm32_gpio_ctl ctl_out = {
+	.af = STM32_GPIO_AF0,
+	.mode = STM32_GPIO_MODE_OUT,
+	.otype = STM32_GPIO_OTYPE_PP,
+	.pupd = STM32_GPIO_PUPD_NO,
+	.speed = STM32_GPIO_SPEED_50M,
+};
+
 #elif defined(CONFIG_STM32F1)
 static const unsigned long io_base[] = {
 	STM32_GPIOA_BASE, STM32_GPIOB_BASE, STM32_GPIOC_BASE,
@@ -146,6 +163,21 @@ int stm32_gpio_config(const struct stm32_gpio_dsc *dsc,
 out:
 	return rv;
 }
+
+static struct stm32_gpio_ctl ctl_in = {
+	.mode = STM32_GPIO_MODE_IN,
+	.icnf = STM32_GPIO_ICNF_IN_FLT,
+	.ocnf = STM32_GPIO_OCNF_GP_PP,	/* ignored for input */
+	.pupd = STM32_GPIO_PUPD_UP,	/* ignored for floating */
+};
+
+static struct stm32_gpio_ctl ctl_out = {
+	.mode = STM32_GPIO_MODE_OUT_50M,
+	.ocnf = STM32_GPIO_OCNF_GP_PP,
+	.icnf = STM32_GPIO_ICNF_IN_FLT,	/* ignored for output */
+	.pupd = STM32_GPIO_PUPD_UP,	/* ignored for output */
+};
+
 #else
 #error STM32 family not supported
 #endif
@@ -203,52 +235,22 @@ int gpio_free(unsigned gpio)
 int gpio_direction_input(unsigned gpio)
 {
 	struct stm32_gpio_dsc dsc;
-	struct stm32_gpio_ctl ctl;
 
 	dsc.port = stm32_gpio_to_port(gpio);
 	dsc.pin = stm32_gpio_to_pin(gpio);
-#if defined(CONFIG_STM32F4) || defined(CONFIG_STM32F7)
-	ctl.af = STM32_GPIO_AF0;
-	ctl.mode = STM32_GPIO_MODE_IN;
-	ctl.otype = STM32_GPIO_OTYPE_PP;
-	ctl.pupd = STM32_GPIO_PUPD_NO;
-	ctl.speed = STM32_GPIO_SPEED_50M;
-#elif defined(CONFIG_STM32F1)
-	ctl.mode = STM32_GPIO_MODE_IN;
-	ctl.icnf = STM32_GPIO_ICNF_IN_FLT;
-	ctl.ocnf = STM32_GPIO_OCNF_GP_PP;	/* ignored for input */
-	ctl.pupd = STM32_GPIO_PUPD_UP;		/* ignored for floating */
-#else
-#error STM32 family not supported
-#endif
 
-	return stm32_gpio_config(&dsc, &ctl);
+	return stm32_gpio_config(&dsc, &ctl_in);
 }
 
 int gpio_direction_output(unsigned gpio, int value)
 {
 	struct stm32_gpio_dsc dsc;
-	struct stm32_gpio_ctl ctl;
 	int res;
 
 	dsc.port = stm32_gpio_to_port(gpio);
 	dsc.pin = stm32_gpio_to_pin(gpio);
-#if defined(CONFIG_STM32F4) || defined(CONFIG_STM32F7)
-	ctl.af = STM32_GPIO_AF0;
-	ctl.mode = STM32_GPIO_MODE_OUT;
-	ctl.otype = STM32_GPIO_OTYPE_PP;
-	ctl.pupd = STM32_GPIO_PUPD_NO;
-	ctl.speed = STM32_GPIO_SPEED_50M;
-#elif defined(CONFIG_STM32F1)
-	ctl.mode = STM32_GPIO_MODE_OUT_50M;
-	ctl.ocnf = STM32_GPIO_OCNF_GP_PP;
-	ctl.icnf = STM32_GPIO_ICNF_IN_FLT;	/* ignored for output */
-	ctl.pupd = STM32_GPIO_PUPD_UP;		/* ignored for output */
-#else
-#error STM32 family not supported
-#endif
 
-	res = stm32_gpio_config(&dsc, &ctl);
+	res = stm32_gpio_config(&dsc, &ctl_out);
 	if (res < 0)
 		goto out;
 	res = stm32_gpout_set(&dsc, value);

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [U-Boot] [PATCH12/23] GPIO: STM32: make DTS-aware
  2016-06-18 12:55 [U-Boot] [PATCH 00/23] DM: Cmd: GPIO/LED/STM32/CLK: provide command-line support for device-tree configured gpios and leds Benjamin Tietz
                   ` (10 preceding siblings ...)
  2016-06-18 12:56 ` [U-Boot] [PATCH11/23] STM32: gpio: group SOC-specific code to one ifdef/elif construct Benjamin Tietz
@ 2016-06-18 12:56 ` Benjamin Tietz
  2016-06-18 12:56 ` [U-Boot] [PATCH13/23] STM32F429-discovery: led: disable board-specific code, if DM is selected Benjamin Tietz
                   ` (11 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Benjamin Tietz @ 2016-06-18 12:56 UTC (permalink / raw)
  To: u-boot

From: Benjamin Tietz <benjamin@micronet24.de>

will bind as a gpio-driver, if DM_GPIO was selected. Defaults to the old behaviour.
---
 drivers/gpio/stm32_gpio.c |  133 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 133 insertions(+)
-------------- next part --------------
From: Benjamin Tietz <benjamin@micronet24.de>

will bind as a gpio-driver, if DM_GPIO was selected. Defaults to the old behaviour.
---
 drivers/gpio/stm32_gpio.c |  133 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 133 insertions(+)

diff --git a/drivers/gpio/stm32_gpio.c b/drivers/gpio/stm32_gpio.c
index be662c3..844b3e1 100644
--- a/drivers/gpio/stm32_gpio.c
+++ b/drivers/gpio/stm32_gpio.c
@@ -220,6 +220,138 @@ out:
 	return rv;
 }
 
+#ifdef CONFIG_DM_GPIO
+#include <asm-generic/gpio.h>
+#include <dm/device.h>
+#include <clk.h>
+#include <dt-bindings/gpio/gpio.h>
+
+struct stm32_gpio_priv {
+	int portnum;
+	u32 requested;
+};
+
+static int stm32_gpio_request(struct udevice *dev, unsigned offset, const char *label)
+{
+	struct stm32_gpio_priv *priv = dev_get_priv(dev);
+	if(priv->requested & (1<<offset))
+		return -EBUSY;
+	if(!priv->requested) {
+		struct udevice *clk = NULL;
+		int clk_id;
+		if((clk_id = clk_get_by_index(dev, 0, &clk)) >= 0)
+			clk_enable(clk, clk_id);
+	}
+	priv->requested |= 1<<offset;
+	return 0;
+}
+
+static int stm32_gpio_free(struct udevice *dev, unsigned offset)
+{
+	struct stm32_gpio_priv *priv = dev_get_priv(dev);
+	priv->requested &= ~(1<<offset);
+	if(!priv->requested) {
+		struct udevice *clk = NULL;
+		int clk_id;
+		if((clk_id = clk_get_by_index(dev, 0, &clk)) >= 0)
+			clk_disable(clk, clk_id);
+	}
+	return 0;
+}
+
+static int stm32_gpio_direction_input(struct udevice *dev, unsigned offset)
+{
+	struct stm32_gpio_priv *priv = dev_get_priv(dev);
+	struct stm32_gpio_dsc dsc = {
+		.port = priv->portnum,
+		.pin = offset,
+	};
+	return stm32_gpio_config(&dsc, &ctl_in);
+}
+
+static int stm32_gpio_direction_output(struct udevice *dev, unsigned offset, int value)
+{
+	struct stm32_gpio_priv *priv = dev_get_priv(dev);
+	struct stm32_gpio_dsc dsc = {
+		.port = priv->portnum,
+		.pin = offset,
+	};
+	int ret = stm32_gpio_config(&dsc, &ctl_out);
+	if(ret >= 0)
+		ret = stm32_gpout_set(&dsc, value);
+	return ret;
+}
+
+static int stm32_gpio_get_value(struct udevice *dev, unsigned offset)
+{
+	struct stm32_gpio_priv *priv = dev_get_priv(dev);
+	struct stm32_gpio_dsc dsc = {
+		.port = priv->portnum,
+		.pin = offset,
+	};
+	return !!stm32_gpin_get(&dsc);
+}
+
+static int stm32_gpio_set_value(struct udevice *dev, unsigned offset, int value)
+{
+	struct stm32_gpio_priv *priv = dev_get_priv(dev);
+	struct stm32_gpio_dsc dsc = {
+		.port = priv->portnum,
+		.pin = offset,
+	};
+	return stm32_gpout_set(&dsc, value);
+}
+
+static struct dm_gpio_ops stm32_gpio_ops = {
+	.request = stm32_gpio_request,
+	.free = stm32_gpio_free,
+	.direction_input = stm32_gpio_direction_input,
+	.direction_output = stm32_gpio_direction_output,
+	.get_value = stm32_gpio_get_value,
+	.set_value = stm32_gpio_set_value,
+};
+
+static int stm32_gpio_probe(struct udevice *dev)
+{
+	struct stm32_gpio_priv *priv = dev_get_priv(dev);
+	struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
+	fdt_addr_t addr;
+	fdt_size_t size;
+	int i;
+	priv->requested = 0;
+
+	addr = fdtdec_get_addr_size(gd->fdt_blob, dev->of_offset, "reg", &size);
+	if (addr == FDT_ADDR_T_NONE)
+		return -EINVAL;
+
+	if(size < sizeof(struct stm32_gpio_ctl))
+		return -EINVAL;
+
+	for(i=0; i < sizeof(io_base)/sizeof(io_base[0]); i++) {
+		if(io_base[i] != addr)
+			continue;
+		priv->portnum = i;
+		uc_priv->bank_name = dev->name;
+		uc_priv->gpio_count = fdtdec_get_int(gd->fdt_blob, dev->of_offset, "gpio-count", 16);
+		return 0;
+	}
+	return -ENXIO;
+}
+
+static const struct udevice_id stm32_gpio_ids[] = {
+	{ .compatible = "st,stm32-gpio" },
+	{ }
+};
+
+U_BOOT_DRIVER(stm32_gpio) = {
+	.name		= "stm32_gpio",
+	.id		= UCLASS_GPIO,
+	.ops		= &stm32_gpio_ops,
+	.probe		= stm32_gpio_probe,
+	.priv_auto_alloc_size = sizeof(struct stm32_gpio_priv),
+	.of_match	= stm32_gpio_ids,
+};
+#else
 /* Common GPIO API */
 
 int gpio_request(unsigned gpio, const char *label)
@@ -277,3 +409,4 @@ int gpio_set_value(unsigned gpio, int value)
 
 	return stm32_gpout_set(&dsc, value);
 }
+#endif

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [U-Boot] [PATCH13/23] STM32F429-discovery: led: disable board-specific code, if DM is selected
  2016-06-18 12:55 [U-Boot] [PATCH 00/23] DM: Cmd: GPIO/LED/STM32/CLK: provide command-line support for device-tree configured gpios and leds Benjamin Tietz
                   ` (11 preceding siblings ...)
  2016-06-18 12:56 ` [U-Boot] [PATCH12/23] GPIO: STM32: make DTS-aware Benjamin Tietz
@ 2016-06-18 12:56 ` Benjamin Tietz
  2016-06-18 12:56 ` [U-Boot] [PATCH14/23] GPIO/LED: make more robust, if STATUS_LED isn't selected Benjamin Tietz
                   ` (10 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Benjamin Tietz @ 2016-06-18 12:56 UTC (permalink / raw)
  To: u-boot

From: Benjamin Tietz <benjamin@micronet24.de>

If the device-tree gpio selection is selected, the board-specific led-initialization will fail.
---
 board/st/stm32f429-discovery/Makefile |    3 +++
 include/configs/stm32f429-discovery.h |   10 +++++++---
 2 files changed, 10 insertions(+), 3 deletions(-)
-------------- next part --------------
From: Benjamin Tietz <benjamin@micronet24.de>

If the device-tree gpio selection is selected, the board-specific led-initialization will fail.
---
 board/st/stm32f429-discovery/Makefile |    3 +++
 include/configs/stm32f429-discovery.h |   10 +++++++---
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/board/st/stm32f429-discovery/Makefile b/board/st/stm32f429-discovery/Makefile
index d94059d..34ee711 100644
--- a/board/st/stm32f429-discovery/Makefile
+++ b/board/st/stm32f429-discovery/Makefile
@@ -9,4 +9,7 @@
 #
 
 obj-y	:= stm32f429-discovery.o
+
+ifndef CONFIG_DM_GPIO
 obj-y	+= led.o
+endif
diff --git a/include/configs/stm32f429-discovery.h b/include/configs/stm32f429-discovery.h
index 9d275c0..04066ff 100644
--- a/include/configs/stm32f429-discovery.h
+++ b/include/configs/stm32f429-discovery.h
@@ -42,17 +42,21 @@
 #define CONFIG_ENV_SECT_SIZE		(128 << 10)
 #define CONFIG_ENV_SIZE			(8 << 10)
 
-#define CONFIG_BOARD_SPECIFIC_LED
+#define CONFIG_GPIO_LED		1
+#ifndef CONFIG_DM_GPIO
 #define CONFIG_RED_LED			110
 #define CONFIG_GREEN_LED		109
-#define CONFIG_GPIO_LED		1
-#define CONFIG_STATUS_LED
+#ifdef CONFIG_STATUS_LED
+#define CONFIG_BOARD_SPECIFIC_LED
+#define STATUS_LED_RED	CONFIG_RED_LED
 #define STATUS_LED_BIT		CONFIG_RED_LED
 #define STATUS_LED_STATE	0
 #define STATUS_LED_PERIOD	0
 #define STATUS_LED_BIT1		CONFIG_GREEN_LED
 #define STATUS_LED_STATE1	0
 #define STATUS_LED_PERIOD1	0
+#endif
+#endif
 
 #define CONFIG_STM32_GPIO
 #define CONFIG_STM32_FLASH

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [U-Boot] [PATCH14/23] GPIO/LED: make more robust, if STATUS_LED isn't selected
  2016-06-18 12:55 [U-Boot] [PATCH 00/23] DM: Cmd: GPIO/LED/STM32/CLK: provide command-line support for device-tree configured gpios and leds Benjamin Tietz
                   ` (12 preceding siblings ...)
  2016-06-18 12:56 ` [U-Boot] [PATCH13/23] STM32F429-discovery: led: disable board-specific code, if DM is selected Benjamin Tietz
@ 2016-06-18 12:56 ` Benjamin Tietz
  2016-06-18 12:56 ` [U-Boot] [PATCH15/23] Cmd: LED: rewrite to prepare non-static access Benjamin Tietz
                   ` (9 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Benjamin Tietz @ 2016-06-18 12:56 UTC (permalink / raw)
  To: u-boot

From: Benjamin Tietz <benjamin@micronet24.de>


---
 drivers/misc/gpio_led.c   |    4 ++++
 drivers/misc/status_led.c |    2 ++
 include/status_led.h      |    4 ++++
 3 files changed, 10 insertions(+)
-------------- next part --------------
From: Benjamin Tietz <benjamin@micronet24.de>


---
 drivers/misc/gpio_led.c   |    4 ++++
 drivers/misc/status_led.c |    2 ++
 include/status_led.h      |    4 ++++
 3 files changed, 10 insertions(+)

diff --git a/drivers/misc/gpio_led.c b/drivers/misc/gpio_led.c
index 164c30d..9c0ea13 100644
--- a/drivers/misc/gpio_led.c
+++ b/drivers/misc/gpio_led.c
@@ -13,6 +13,10 @@
 #define CONFIG_GPIO_LED_INVERTED_TABLE {}
 #endif
 
+#ifndef STATUS_LED_ON
+#define STATUS_LED_ON 2
+#endif
+
 static led_id_t gpio_led_inv[] = CONFIG_GPIO_LED_INVERTED_TABLE;
 
 static int gpio_led_gpio_value(led_id_t mask, int state)
diff --git a/drivers/misc/status_led.c b/drivers/misc/status_led.c
index 31e8831..052ecf0 100644
--- a/drivers/misc/status_led.c
+++ b/drivers/misc/status_led.c
@@ -27,11 +27,13 @@ typedef struct {
 } led_dev_t;
 
 led_dev_t led_dev[] = {
+#if defined(STATUS_LED_BIT)
     {	STATUS_LED_BIT,
 	STATUS_LED_STATE,
 	STATUS_LED_PERIOD,
 	0,
     },
+#endif
 #if defined(STATUS_LED_BIT1)
     {	STATUS_LED_BIT1,
 	STATUS_LED_STATE1,
diff --git a/include/status_led.h b/include/status_led.h
index 396ea88..2185855 100644
--- a/include/status_led.h
+++ b/include/status_led.h
@@ -103,6 +103,10 @@ void __led_blink(led_id_t mask, int freq);
 # include <asm/status_led.h>
 #endif
 
+#else
+
+typedef int led_id_t;
+
 #endif	/* CONFIG_STATUS_LED	*/
 
 /*

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [U-Boot] [PATCH15/23] Cmd: LED: rewrite to prepare non-static access
  2016-06-18 12:55 [U-Boot] [PATCH 00/23] DM: Cmd: GPIO/LED/STM32/CLK: provide command-line support for device-tree configured gpios and leds Benjamin Tietz
                   ` (13 preceding siblings ...)
  2016-06-18 12:56 ` [U-Boot] [PATCH14/23] GPIO/LED: make more robust, if STATUS_LED isn't selected Benjamin Tietz
@ 2016-06-18 12:56 ` Benjamin Tietz
  2016-06-18 12:56 ` [U-Boot] [PATCH16/23] DTS: STM32F429-disco: add board leds and enable rcc Benjamin Tietz
                   ` (8 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Benjamin Tietz @ 2016-06-18 12:56 UTC (permalink / raw)
  To: u-boot

From: Benjamin Tietz <benjamin@micronet24.de>

Previously, all knwon LED were hold in a single array and computed at compile-time.
With the new variant, if all LEDs are known, these will also be computed at compile-time.
Using functions will allow additional dynamic (eg. DM-based) LED allocation.

Apart from that, the led-command becomes indipendent from the STATUS_LED setting.
---
 cmd/led.c |  337 ++++++++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 230 insertions(+), 107 deletions(-)
-------------- next part --------------
From: Benjamin Tietz <benjamin@micronet24.de>

Previously, all knwon LED were hold in a single array and computed at compile-time.
With the new variant, if all LEDs are known, these will also be computed at compile-time.
Using functions will allow additional dynamic (eg. DM-based) LED allocation.

Apart from that, the led-command becomes indipendent from the STATUS_LED setting.
---
 cmd/led.c |  337 ++++++++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 230 insertions(+), 107 deletions(-)

diff --git a/cmd/led.c b/cmd/led.c
index b0f1a61..e020b92 100644
--- a/cmd/led.c
+++ b/cmd/led.c
@@ -15,53 +15,241 @@
 #include <command.h>
 #include <status_led.h>
 
+enum led_cmd { LED_ON, LED_OFF, LED_TOGGLE, LED_BLINK, LED_LIST, LED_MAX_OP };
+
+struct led_tbl_s;
+
+typedef void (* led_op)(const struct led_tbl_s *, enum led_cmd, char *arg);
+
 struct led_tbl_s {
-	char		*string;	/* String for use in the command */
+	const char	*string;	/* String for use in the command */
 	led_id_t	mask;		/* Mask used for calling __led_set() */
-	void		(*off)(void);	/* Optional function for turning LED off */
-	void		(*on)(void);	/* Optional function for turning LED on */
-	void		(*toggle)(void);/* Optional function for toggling LED */
+	led_op op[LED_MAX_OP];		/* functions for handling LED commands */
 };
 
 typedef struct led_tbl_s led_tbl_t;
 
-static const led_tbl_t led_commands[] = {
+static int call_led(const char *name, enum led_cmd cmd, char *arg);
+
+static void _led_list_name(const led_tbl_t *led, enum led_cmd cmd, char *arg) {
+	printf("%s\n", led->string);
+}
+
+#define LED_MASK_FUNC(fnc)	((led_op) fnc)
+#define LED_TEST_RET(name, ret)	if(strcmp(name, ret.string) == 0) return &ret;
+#define LED_TBL_COLOURED(clr)	static const led_tbl_t _led_##clr = { \
+	.string = #clr, \
+	.op = { \
+		[LED_ON] = LED_MASK_FUNC(clr ## _led_on), \
+		[LED_OFF] = LED_MASK_FUNC(clr ## _led_off), \
+		[LED_LIST] = _led_list_name, \
+	}, \
+}
+
+#ifdef STATUS_LED_GREEN
+LED_TBL_COLOURED(green);
+#define LED_NAME_GREEN		_led_green.string
+#define LED_TEST_GREEN(name)	LED_TEST_RET(name, _led_green)
+#else
+#define LED_NAME_GREEN		NULL
+#define LED_TEST_GREEN(name)	while(0)
+#endif
+
+#ifdef STATUS_LED_YELLOW
+LED_TBL_COLOURED(yellow);
+#define LED_NAME_YELLOW		_led_yellow.string
+#define LED_TEST_YELLOW(name)	LED_TEST_RET(name, _led_yellow)
+#else
+#define LED_NAME_YELLOW		NULL
+#define LED_TEST_YELLOW(name)	while(0)
+#endif
+
+#ifdef STATUS_LED_RED
+LED_TBL_COLOURED(red);
+#define LED_NAME_RED		_led_red.string
+#define LED_TEST_RED(name)	LED_TEST_RET(name, _led_red)
+#else
+#define LED_NAME_RED		NULL
+#define LED_TEST_RED(name)	while(0)
+#endif
+
+#ifdef STATUS_LED_BLUE
+LED_TBL_COLOURED(blue);
+#define LED_NAME_BLUE		_led_blue.string
+#define LED_TEST_BLUE(name)	LED_TEST_RET(name, _led_blue)
+#else
+#define LED_NAME_BLUE		NULL
+#define LED_TEST_BLUE(name)	while(0)
+#endif
+
 #ifdef CONFIG_BOARD_SPECIFIC_LED
+/*
+ * LED drivers providing a blinking LED functionality, like the
+ * PCA9551, can override this empty weak function
+ */
+void __weak __led_blink(led_id_t mask, int freq)
+{
+}
+
+static void _led_status_onoff(const led_tbl_t *led, enum led_cmd cmd, char *arg) {
+	__led_set(led->mask, cmd != LED_ON ? STATUS_LED_OFF : STATUS_LED_ON);
+}
+static void _led_status_toggle(const led_tbl_t *led, enum led_cmd cmd, char *arg) {
+	__led_toggle(led->mask);
+}
+static void _led_status_blink(const led_tbl_t *led, enum led_cmd cmd, char *freq) {
+	if (!freq)
+		return;
+
+	__led_blink(led->mask, simple_strtoul(freq, NULL, 10));
+}
+
+#define LED_TBL_STATUS(name, _mask)	static const led_tbl_t _led_##name = { \
+	.string = #name, \
+	.mask = _mask, \
+	.op = { \
+		[LED_ON] = _led_status_onoff, \
+		[LED_OFF] = _led_status_onoff, \
+		[LED_TOGGLE] = _led_status_toggle, \
+		[LED_BLINK] = _led_status_blink, \
+		[LED_LIST] = _led_list_name, \
+	}, \
+}
+
 #ifdef STATUS_LED_BIT
-	{ "0", STATUS_LED_BIT, NULL, NULL, NULL },
+LED_TBL_STATUS(0, STATUS_LED_BIT);
+#define LED_NAME_0		_led_0.string
+#define LED_TEST_0(name)	LED_TEST_RET(name, _led_0)
 #endif
+
 #ifdef STATUS_LED_BIT1
-	{ "1", STATUS_LED_BIT1, NULL, NULL, NULL },
+LED_TBL_STATUS(1, STATUS_LED_BIT1);
+#define LED_NAME_1		_led_1.string
+#define LED_TEST_1(name)	LED_TEST_RET(name, _led_1)
 #endif
+
 #ifdef STATUS_LED_BIT2
-	{ "2", STATUS_LED_BIT2, NULL, NULL, NULL },
+LED_TBL_STATUS(2, STATUS_LED_BIT2);
+#define LED_NAME_2		_led_2.string
+#define LED_TEST_2(name)	LED_TEST_RET(name, _led_2)
 #endif
+
 #ifdef STATUS_LED_BIT3
-	{ "3", STATUS_LED_BIT3, NULL, NULL, NULL },
+LED_TBL_STATUS(3, STATUS_LED_BIT3);
+#define LED_NAME_3		_led_3.string
+#define LED_TEST_3(name)	LED_TEST_RET(name, _led_3)
 #endif
+
 #ifdef STATUS_LED_BIT4
-	{ "4", STATUS_LED_BIT4, NULL, NULL, NULL },
+LED_TBL_STATUS(4, STATUS_LED_BIT4);
+#define LED_NAME_4		_led_4.string
+#define LED_TEST_4(name)	LED_TEST_RET(name, _led_4)
 #endif
+
 #ifdef STATUS_LED_BIT5
-	{ "5", STATUS_LED_BIT5, NULL, NULL, NULL },
+LED_TBL_STATUS(5, STATUS_LED_BIT5);
+#define LED_NAME_5		_led_5.string
+#define LED_TEST_5(name)	LED_TEST_RET(name, _led_5)
 #endif
+#endif  /* CONFIG_BOARD_SPECIFIC_LED */
+
+#ifndef LED_NAME_0
+#define LED_NAME_0		NULL
+#define LED_TEST_0(name)	while(0)
 #endif
-#ifdef STATUS_LED_GREEN
-	{ "green", STATUS_LED_GREEN, green_led_off, green_led_on, NULL },
+
+#ifndef LED_NAME_1
+#define LED_NAME_1		NULL
+#define LED_TEST_1(name)	while(0)
 #endif
-#ifdef STATUS_LED_YELLOW
-	{ "yellow", STATUS_LED_YELLOW, yellow_led_off, yellow_led_on, NULL },
+
+#ifndef LED_NAME_2
+#define LED_NAME_2		NULL
+#define LED_TEST_2(name)	while(0)
 #endif
-#ifdef STATUS_LED_RED
-	{ "red", STATUS_LED_RED, red_led_off, red_led_on, NULL },
+
+#ifndef LED_NAME_3
+#define LED_NAME_3		NULL
+#define LED_TEST_3(name)	while(0)
 #endif
-#ifdef STATUS_LED_BLUE
-	{ "blue", STATUS_LED_BLUE, blue_led_off, blue_led_on, NULL },
+
+#ifndef LED_NAME_4
+#define LED_NAME_4		NULL
+#define LED_TEST_4(name)	while(0)
 #endif
-	{ NULL, 0, NULL, NULL, NULL }
+
+#ifndef LED_NAME_5
+#define LED_NAME_5		NULL
+#define LED_TEST_5(name)	while(0)
+#endif
+
+static int _led_count(void) {
+	int i = 0;
+	if(LED_NAME_GREEN) i++;
+	if(LED_NAME_RED) i++;
+	if(LED_NAME_BLUE) i++;
+	if(LED_NAME_YELLOW) i++;
+	if(LED_NAME_0) i++;
+	if(LED_NAME_1) i++;
+	if(LED_NAME_2) i++;
+	if(LED_NAME_3) i++;
+	if(LED_NAME_4) i++;
+	if(LED_NAME_5) i++;
+	return i;
+}
+
+#define TEST_ADD_NAME(name, tbl, size) do { if((name) && ((size) > 0)) { *tbl++ = name; size--; } } while(0)
+static int _led_list(const char **tbl, int size) {
+	int init_size = size;
+	TEST_ADD_NAME(LED_NAME_GREEN, tbl, size);
+	TEST_ADD_NAME(LED_NAME_RED, tbl, size);
+	TEST_ADD_NAME(LED_NAME_BLUE, tbl, size);
+	TEST_ADD_NAME(LED_NAME_YELLOW, tbl, size);
+	TEST_ADD_NAME(LED_NAME_0, tbl, size);
+	TEST_ADD_NAME(LED_NAME_1, tbl, size);
+	TEST_ADD_NAME(LED_NAME_2, tbl, size);
+	TEST_ADD_NAME(LED_NAME_3, tbl, size);
+	TEST_ADD_NAME(LED_NAME_4, tbl, size);
+	TEST_ADD_NAME(LED_NAME_5, tbl, size);
+	return init_size - size;
+}
+
+static void _led_all_cmd(const led_tbl_t *led, enum led_cmd cmd, char *arg) {
+	int cnt = _led_count();
+	const char *leds[cnt];
+	int i;
+
+	_led_list(leds, cnt);
+	for(i=0; i < cnt; i++)
+		call_led(leds[i], cmd, arg);
+}
+
+static const led_tbl_t _led_all = {
+	.string = "all",
+	.op = {
+		[LED_ON] = _led_all_cmd,
+		[LED_OFF] = _led_all_cmd,
+		[LED_TOGGLE] = _led_all_cmd,
+		[LED_BLINK] = _led_all_cmd,
+		[LED_LIST] = _led_all_cmd,
+	},
 };
+#define LED_TEST_ALL(name)	LED_TEST_RET(name, _led_all)
 
-enum led_cmd { LED_ON, LED_OFF, LED_TOGGLE, LED_BLINK };
+static const led_tbl_t *get_led(const char *name) {
+	LED_TEST_ALL(name);
+	LED_TEST_GREEN(name);
+	LED_TEST_YELLOW(name);
+	LED_TEST_RED(name);
+	LED_TEST_BLUE(name);
+	LED_TEST_0(name);
+	LED_TEST_1(name);
+	LED_TEST_2(name);
+	LED_TEST_3(name);
+	LED_TEST_4(name);
+	LED_TEST_5(name);
+	return NULL;
+}
 
 enum led_cmd get_led_cmd(char *var)
 {
@@ -73,23 +261,29 @@ enum led_cmd get_led_cmd(char *var)
 		return LED_TOGGLE;
 	if (strcmp(var, "blink") == 0)
 		return LED_BLINK;
+	if (strcmp(var, "list") == 0)
+		return LED_LIST;
 
 	return -1;
 }
 
-/*
- * LED drivers providing a blinking LED functionality, like the
- * PCA9551, can override this empty weak function
- */
-void __weak __led_blink(led_id_t mask, int freq)
+static int call_led(const char *name, enum led_cmd cmd, char *arg)
 {
+	const led_tbl_t *led = get_led(name);
+	if(!led)
+		return CMD_RET_USAGE;
+
+	if(cmd >= LED_MAX_OP)
+		return CMD_RET_USAGE;
+	if(led->op[cmd])
+		led->op[cmd](led, cmd, arg);
+	return 0;
+
 }
 
 int do_led (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
-	int i, match = 0;
 	enum led_cmd cmd;
-	int freq;
 
 	/* Validate arguments */
 	if ((argc < 3) || (argc > 4))
@@ -100,87 +294,16 @@ int do_led (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		return CMD_RET_USAGE;
 	}
 
-	for (i = 0; led_commands[i].string; i++) {
-		if ((strcmp("all", argv[1]) == 0) ||
-		    (strcmp(led_commands[i].string, argv[1]) == 0)) {
-			match = 1;
-			switch (cmd) {
-			case LED_ON:
-				if (led_commands[i].on)
-					led_commands[i].on();
-				else
-					__led_set(led_commands[i].mask,
-							  STATUS_LED_ON);
-				break;
-			case LED_OFF:
-				if (led_commands[i].off)
-					led_commands[i].off();
-				else
-					__led_set(led_commands[i].mask,
-							  STATUS_LED_OFF);
-				break;
-			case LED_TOGGLE:
-				if (led_commands[i].toggle)
-					led_commands[i].toggle();
-				else
-					__led_toggle(led_commands[i].mask);
-				break;
-			case LED_BLINK:
-				if (argc != 4)
-					return CMD_RET_USAGE;
-
-				freq = simple_strtoul(argv[3], NULL, 10);
-				__led_blink(led_commands[i].mask, freq);
-			}
-			/* Need to set only 1 led if led_name wasn't 'all' */
-			if (strcmp("all", argv[1]) != 0)
-				break;
-		}
-	}
-
-	/* If we ran out of matches, print Usage */
-	if (!match) {
-		return CMD_RET_USAGE;
-	}
-
-	return 0;
+	return call_led(argv[1], cmd, argc != 4 ? NULL : argv[3]);
 }
 
 U_BOOT_CMD(
 	led, 4, 1, do_led,
-	"["
-#ifdef CONFIG_BOARD_SPECIFIC_LED
-#ifdef STATUS_LED_BIT
-	"0|"
-#endif
-#ifdef STATUS_LED_BIT1
-	"1|"
-#endif
-#ifdef STATUS_LED_BIT2
-	"2|"
-#endif
-#ifdef STATUS_LED_BIT3
-	"3|"
-#endif
-#ifdef STATUS_LED_BIT4
-	"4|"
-#endif
-#ifdef STATUS_LED_BIT5
-	"5|"
-#endif
-#endif
-#ifdef STATUS_LED_GREEN
-	"green|"
-#endif
-#ifdef STATUS_LED_YELLOW
-	"yellow|"
-#endif
-#ifdef STATUS_LED_RED
-	"red|"
-#endif
-#ifdef STATUS_LED_BLUE
-	"blue|"
-#endif
-	"all] [on|off|toggle|blink] [blink-freq in ms]",
-	"[led_name] [on|off|toggle|blink] sets or clears led(s)"
+	"[led_name|all] [on|off|toggle|blink|list] [blink-freq in ms]",
+	"if 'all' is given as led-name, all known leds will be affected by the command\n"
+	"[on] sets an led\n"
+	"[off] clears an led\n"
+	"[toggle] inverts an led\n"
+	"[blink freq] let an led blink, if supported by the controller\n"
+	"[list] shows the name of known led\n"
 );

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [U-Boot] [PATCH16/23] DTS: STM32F429-disco: add board leds and enable rcc
  2016-06-18 12:55 [U-Boot] [PATCH 00/23] DM: Cmd: GPIO/LED/STM32/CLK: provide command-line support for device-tree configured gpios and leds Benjamin Tietz
                   ` (14 preceding siblings ...)
  2016-06-18 12:56 ` [U-Boot] [PATCH15/23] Cmd: LED: rewrite to prepare non-static access Benjamin Tietz
@ 2016-06-18 12:56 ` Benjamin Tietz
  2016-06-18 12:56 ` [U-Boot] [PATCH17/23] LED: add function to retrieve a device's label Benjamin Tietz
                   ` (7 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Benjamin Tietz @ 2016-06-18 12:56 UTC (permalink / raw)
  To: u-boot

From: Benjamin Tietz <benjamin@micronet24.de>


---
 arch/arm/dts/stm32f429-disco.dts |   22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
-------------- next part --------------
From: Benjamin Tietz <benjamin@micronet24.de>


---
 arch/arm/dts/stm32f429-disco.dts |   22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/arch/arm/dts/stm32f429-disco.dts b/arch/arm/dts/stm32f429-disco.dts
index 2bae81c..7159f82 100644
--- a/arch/arm/dts/stm32f429-disco.dts
+++ b/arch/arm/dts/stm32f429-disco.dts
@@ -64,6 +64,20 @@
 	aliases {
 		serial0 = &usart1;
 	};
+
+	leds {
+		compatible = "gpio-leds";
+		user1 {
+			label = "user:green";
+			gpios = <&gpioG 13 0>;
+		};
+
+		user2 {
+			label = "user:red";
+			gpios = <&gpioG 14 0>;
+		};
+	};
+
 };
 
 &clk_hse {
@@ -73,3 +87,11 @@
 &usart1 {
 	status = "okay";
 };
+
+&rcc {
+	status = "okay";
+};
+
+&gpioG {
+	status = "okay";
+};

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [U-Boot] [PATCH17/23] LED: add function to retrieve a device's label
  2016-06-18 12:55 [U-Boot] [PATCH 00/23] DM: Cmd: GPIO/LED/STM32/CLK: provide command-line support for device-tree configured gpios and leds Benjamin Tietz
                   ` (15 preceding siblings ...)
  2016-06-18 12:56 ` [U-Boot] [PATCH16/23] DTS: STM32F429-disco: add board leds and enable rcc Benjamin Tietz
@ 2016-06-18 12:56 ` Benjamin Tietz
  2016-06-18 12:56 ` [U-Boot] [PATCH18/23] LED: provide function to count and get all (DM-)LEDs Benjamin Tietz
                   ` (6 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Benjamin Tietz @ 2016-06-18 12:56 UTC (permalink / raw)
  To: u-boot

From: Benjamin Tietz <benjamin@micronet24.de>


---
 drivers/led/led-uclass.c |    6 ++++++
 include/led.h            |    8 ++++++++
 2 files changed, 14 insertions(+)
-------------- next part --------------
From: Benjamin Tietz <benjamin@micronet24.de>


---
 drivers/led/led-uclass.c |    6 ++++++
 include/led.h            |    8 ++++++++
 2 files changed, 14 insertions(+)

diff --git a/drivers/led/led-uclass.c b/drivers/led/led-uclass.c
index 784ac87..f5fbbcb 100644
--- a/drivers/led/led-uclass.c
+++ b/drivers/led/led-uclass.c
@@ -32,6 +32,12 @@ int led_get_by_label(const char *label, struct udevice **devp)
 	return -ENODEV;
 }
 
+const char *led_get_label(struct udevice *dev)
+{
+	struct led_uclass_plat *uc_plat = dev_get_uclass_platdata(dev);
+	return uc_plat->label;
+}
+
 int led_set_on(struct udevice *dev, int on)
 {
 	struct led_ops *ops = led_get_ops(dev);
diff --git a/include/led.h b/include/led.h
index b929d0c..32e0dec 100644
--- a/include/led.h
+++ b/include/led.h
@@ -40,6 +40,14 @@ struct led_ops {
 int led_get_by_label(const char *label, struct udevice **devp);
 
 /**
+ * led_get_label() - get the label of a given led-device
+ *
+ * @dev:	led device
+ * @return the name of the led
+ */
+const char *led_get_label(struct udevice *dev);
+
+/**
  * led_set_on() - set the state of an LED
  *
  * @dev:	LED device to change

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [U-Boot] [PATCH18/23] LED: provide function to count and get all (DM-)LEDs
  2016-06-18 12:55 [U-Boot] [PATCH 00/23] DM: Cmd: GPIO/LED/STM32/CLK: provide command-line support for device-tree configured gpios and leds Benjamin Tietz
                   ` (16 preceding siblings ...)
  2016-06-18 12:56 ` [U-Boot] [PATCH17/23] LED: add function to retrieve a device's label Benjamin Tietz
@ 2016-06-18 12:56 ` Benjamin Tietz
  2016-06-18 12:57 ` [U-Boot] [PATCH19/23] cmd: LED: be aware of DTS-configured leds Benjamin Tietz
                   ` (5 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Benjamin Tietz @ 2016-06-18 12:56 UTC (permalink / raw)
  To: u-boot

From: Benjamin Tietz <benjamin@micronet24.de>


---
 drivers/led/led-uclass.c |   53 ++++++++++++++++++++++++++++++++++++++++++++++
 include/led.h            |   18 ++++++++++++++++
 2 files changed, 71 insertions(+)
-------------- next part --------------
From: Benjamin Tietz <benjamin@micronet24.de>


---
 drivers/led/led-uclass.c |   53 ++++++++++++++++++++++++++++++++++++++++++++++
 include/led.h            |   18 ++++++++++++++++
 2 files changed, 71 insertions(+)

diff --git a/drivers/led/led-uclass.c b/drivers/led/led-uclass.c
index f5fbbcb..ce519d0 100644
--- a/drivers/led/led-uclass.c
+++ b/drivers/led/led-uclass.c
@@ -32,6 +32,59 @@ int led_get_by_label(const char *label, struct udevice **devp)
 	return -ENODEV;
 }
 
+int led_count(void)
+{
+	int cnt = 0;
+	struct udevice *dev;
+	struct uclass *uc;
+	int ret;
+
+	ret = uclass_get(UCLASS_LED, &uc);
+	if (ret)
+		return ret;
+
+	uclass_foreach_dev(dev, uc) {
+		struct led_uclass_plat *uc_plat = dev_get_uclass_platdata(dev);
+
+		/* Ignore the top-level LED node */
+		if (uc_plat->label)
+			cnt++;
+	}
+
+	return cnt;
+}
+
+int led_get_all(struct udevice **devarr, int maxret)
+{
+	int cnt = 0;
+	struct udevice *dev;
+	struct uclass *uc;
+	int ret;
+
+	ret = uclass_get(UCLASS_LED, &uc);
+	if (ret)
+		return ret;
+
+	if(maxret <= cnt)
+		return cnt;
+
+	uclass_foreach_dev(dev, uc) {
+		struct led_uclass_plat *uc_plat = dev_get_uclass_platdata(dev);
+
+		/* Ignore the top-level LED node */
+		if (uc_plat->label) {
+			ret = uclass_get_device_tail(dev, 0, &devarr[cnt]);
+			if(ret)
+				return ret;
+			cnt++;
+			if(cnt >= maxret)
+				return cnt;
+		}
+	}
+
+	return cnt;
+}
+
 const char *led_get_label(struct udevice *dev)
 {
 	struct led_uclass_plat *uc_plat = dev_get_uclass_platdata(dev);
diff --git a/include/led.h b/include/led.h
index 32e0dec..4b1bd56 100644
--- a/include/led.h
+++ b/include/led.h
@@ -48,6 +48,24 @@ int led_get_by_label(const char *label, struct udevice **devp);
 const char *led_get_label(struct udevice *dev);
 
 /**
+ * led_count() - retrieve the number of DM-configured LEDs
+ *
+ * @return the number of leds found
+ */
+int led_count(void);
+
+/**
+ * led_get_all() - retrieve an array of DM-configured LEDs
+ *
+ * Should return at most led_count() leds.
+ *
+ * @devarr:	pointer to an array of led-device, to be filled.
+ * @maxitm:	pre-allocated size of the array
+ * @return number of leds filled into @devarr
+ */
+int led_get_all(struct udevice **devarr, int maxitm);
+
+/**
  * led_set_on() - set the state of an LED
  *
  * @dev:	LED device to change

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [U-Boot] [PATCH19/23] cmd: LED: be aware of DTS-configured leds
  2016-06-18 12:55 [U-Boot] [PATCH 00/23] DM: Cmd: GPIO/LED/STM32/CLK: provide command-line support for device-tree configured gpios and leds Benjamin Tietz
                   ` (17 preceding siblings ...)
  2016-06-18 12:56 ` [U-Boot] [PATCH18/23] LED: provide function to count and get all (DM-)LEDs Benjamin Tietz
@ 2016-06-18 12:57 ` Benjamin Tietz
  2016-06-18 12:57 ` [U-Boot] [PATCH20/23] LED: provide functionality to get led status Benjamin Tietz
                   ` (4 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Benjamin Tietz @ 2016-06-18 12:57 UTC (permalink / raw)
  To: u-boot

From: Benjamin Tietz <benjamin@micronet24.de>


---
 cmd/led.c |   53 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 52 insertions(+), 1 deletion(-)
-------------- next part --------------
From: Benjamin Tietz <benjamin@micronet24.de>


---
 cmd/led.c |   53 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 52 insertions(+), 1 deletion(-)

diff --git a/cmd/led.c b/cmd/led.c
index e020b92..99358c6 100644
--- a/cmd/led.c
+++ b/cmd/led.c
@@ -183,6 +183,54 @@ LED_TBL_STATUS(5, STATUS_LED_BIT5);
 #define LED_TEST_5(name)	while(0)
 #endif
 
+#ifdef CONFIG_LED
+#include <led.h>
+
+static void _led_dm_onoff(const led_tbl_t *led, enum led_cmd cmd, char *arg)
+{
+	struct udevice *dev = NULL;
+	if(led_get_by_label(led->string, &dev))
+		return;
+	if(dev)
+		led_set_on(dev, cmd == LED_ON);
+}
+
+// this isn't const, as the string will be replaced by the current led's label, always.
+static led_tbl_t _led_dm = {
+	.op = {
+		[LED_ON] = _led_dm_onoff,
+		[LED_OFF] = _led_dm_onoff,
+		[LED_LIST] = _led_list_name,
+	},
+};
+
+static const led_tbl_t *_led_dm_get(const char *name) {
+	struct udevice *dev = NULL;
+	if(led_get_by_label(name, &dev))
+		return NULL;
+	if(!dev)
+		return NULL;
+	_led_dm.string = name;
+	return &_led_dm;
+}
+
+#define LED_DM_COUNT()	led_count()
+static int led_dm_list(const char **tbl, int size) {
+	struct udevice *devs[size];
+	int cnt = led_get_all(devs, size);
+	int i;
+	for(i = 0; i < cnt; i++)
+		tbl[i] = led_get_label(devs[i]);
+	return cnt;
+}
+#define LED_TEST_DM(name) return _led_dm_get(name)
+
+#else
+#define LED_TEST_DM(name)	return NULL
+#define LED_DM_COUNT()		0
+#define led_dm_list(tbl, size)	0
+#endif
+
 static int _led_count(void) {
 	int i = 0;
 	if(LED_NAME_GREEN) i++;
@@ -195,6 +243,7 @@ static int _led_count(void) {
 	if(LED_NAME_3) i++;
 	if(LED_NAME_4) i++;
 	if(LED_NAME_5) i++;
+	i += LED_DM_COUNT();
 	return i;
 }
 
@@ -211,6 +260,7 @@ static int _led_list(const char **tbl, int size) {
 	TEST_ADD_NAME(LED_NAME_3, tbl, size);
 	TEST_ADD_NAME(LED_NAME_4, tbl, size);
 	TEST_ADD_NAME(LED_NAME_5, tbl, size);
+	size -= led_dm_list(tbl, size);
 	return init_size - size;
 }
 
@@ -248,7 +298,8 @@ static const led_tbl_t *get_led(const char *name) {
 	LED_TEST_3(name);
 	LED_TEST_4(name);
 	LED_TEST_5(name);
-	return NULL;
+	// must be last, returns always
+	LED_TEST_DM(name);
 }
 
 enum led_cmd get_led_cmd(char *var)

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [U-Boot] [PATCH20/23] LED: provide functionality to get led status
  2016-06-18 12:55 [U-Boot] [PATCH 00/23] DM: Cmd: GPIO/LED/STM32/CLK: provide command-line support for device-tree configured gpios and leds Benjamin Tietz
                   ` (18 preceding siblings ...)
  2016-06-18 12:57 ` [U-Boot] [PATCH19/23] cmd: LED: be aware of DTS-configured leds Benjamin Tietz
@ 2016-06-18 12:57 ` Benjamin Tietz
  2016-06-18 12:57 ` [U-Boot] [PATCH21/23] LED: GPIO: provide get_on() op Benjamin Tietz
                   ` (3 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Benjamin Tietz @ 2016-06-18 12:57 UTC (permalink / raw)
  To: u-boot

From: Benjamin Tietz <benjamin@micronet24.de>


---
 drivers/led/led-uclass.c |   10 ++++++++++
 include/led.h            |   18 ++++++++++++++++++
 2 files changed, 28 insertions(+)
-------------- next part --------------
From: Benjamin Tietz <benjamin@micronet24.de>


---
 drivers/led/led-uclass.c |   10 ++++++++++
 include/led.h            |   18 ++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/drivers/led/led-uclass.c b/drivers/led/led-uclass.c
index ce519d0..7d7dec3 100644
--- a/drivers/led/led-uclass.c
+++ b/drivers/led/led-uclass.c
@@ -101,6 +101,16 @@ int led_set_on(struct udevice *dev, int on)
 	return ops->set_on(dev, on);
 }
 
+int led_get_on(struct udevice *dev)
+{
+	struct led_ops *ops = led_get_ops(dev);
+
+	if (!ops->get_on)
+		return -ENOSYS;
+
+	return ops->get_on(dev);
+}
+
 UCLASS_DRIVER(led) = {
 	.id		= UCLASS_LED,
 	.name		= "led",
diff --git a/include/led.h b/include/led.h
index 4b1bd56..4709013 100644
--- a/include/led.h
+++ b/include/led.h
@@ -26,6 +26,16 @@ struct led_ops {
 	 * @return 0 if OK, -ve on error
 	 */
 	int (*set_on)(struct udevice *dev, int on);
+
+	/**
+	 * get_on() - get the current state of an LED
+	 *
+	 * function is optional.
+	 *
+	 * @dev:	LED device to check
+	 * @return 0 if OFF, 1 if ON, -ve on error
+	 */
+	int (*get_on)(struct udevice *dev);
 };
 
 #define led_get_ops(dev)	((struct led_ops *)(dev)->driver->ops)
@@ -74,4 +84,12 @@ int led_get_all(struct udevice **devarr, int maxitm);
  */
 int led_set_on(struct udevice *dev, int on);
 
+/**
+ * led_get_on() - get the current state of an LED
+ *
+ * @dev:	LED device to check
+ * @return 0 if OFF, 1 if ON, -ve on error
+ */
+int led_get_on(struct udevice *dev);
+
 #endif

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [U-Boot] [PATCH21/23] LED: GPIO: provide get_on() op
  2016-06-18 12:55 [U-Boot] [PATCH 00/23] DM: Cmd: GPIO/LED/STM32/CLK: provide command-line support for device-tree configured gpios and leds Benjamin Tietz
                   ` (19 preceding siblings ...)
  2016-06-18 12:57 ` [U-Boot] [PATCH20/23] LED: provide functionality to get led status Benjamin Tietz
@ 2016-06-18 12:57 ` Benjamin Tietz
  2016-06-18 12:57 ` [U-Boot] [PATCH22/23] LED: provide toggling interface Benjamin Tietz
                   ` (2 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: Benjamin Tietz @ 2016-06-18 12:57 UTC (permalink / raw)
  To: u-boot

From: Benjamin Tietz <benjamin@micronet24.de>


---
 drivers/led/led_gpio.c |   11 +++++++++++
 1 file changed, 11 insertions(+)
-------------- next part --------------
From: Benjamin Tietz <benjamin@micronet24.de>


---
 drivers/led/led_gpio.c |   11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/led/led_gpio.c b/drivers/led/led_gpio.c
index cb6e996..80e0f72 100644
--- a/drivers/led/led_gpio.c
+++ b/drivers/led/led_gpio.c
@@ -28,6 +28,16 @@ static int gpio_led_set_on(struct udevice *dev, int on)
 	return dm_gpio_set_value(&priv->gpio, on);
 }
 
+static int gpio_led_get_on(struct udevice *dev)
+{
+	struct led_gpio_priv *priv = dev_get_priv(dev);
+
+	if (!dm_gpio_is_valid(&priv->gpio))
+		return -EREMOTEIO;
+
+	return dm_gpio_get_value(&priv->gpio);
+}
+
 static int led_gpio_probe(struct udevice *dev)
 {
 	struct led_uclass_plat *uc_plat = dev_get_uclass_platdata(dev);
@@ -88,6 +98,7 @@ static int led_gpio_bind(struct udevice *parent)
 
 static const struct led_ops gpio_led_ops = {
 	.set_on		= gpio_led_set_on,
+	.get_on		= gpio_led_get_on,
 };
 
 static const struct udevice_id led_gpio_ids[] = {

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [U-Boot] [PATCH22/23] LED: provide toggling interface
  2016-06-18 12:55 [U-Boot] [PATCH 00/23] DM: Cmd: GPIO/LED/STM32/CLK: provide command-line support for device-tree configured gpios and leds Benjamin Tietz
                   ` (20 preceding siblings ...)
  2016-06-18 12:57 ` [U-Boot] [PATCH21/23] LED: GPIO: provide get_on() op Benjamin Tietz
@ 2016-06-18 12:57 ` Benjamin Tietz
  2016-06-18 12:57 ` [U-Boot] [PATCH23/23] Cmd: LED: make DM-leds toggle Benjamin Tietz
  2016-06-18 14:07 ` [U-Boot] [PATCH 00/23] DM: Cmd: GPIO/LED/STM32/CLK: provide command-line support for device-tree configured gpios and leds Bin Meng
  23 siblings, 0 replies; 25+ messages in thread
From: Benjamin Tietz @ 2016-06-18 12:57 UTC (permalink / raw)
  To: u-boot

From: Benjamin Tietz <benjamin@micronet24.de>

if not supported directly by the driver, the led will be toggled by calling led_set_on(!led_get_on()), transparently.
---
 drivers/led/led-uclass.c |   14 ++++++++++++++
 include/led.h            |   21 +++++++++++++++++++++
 2 files changed, 35 insertions(+)
-------------- next part --------------
From: Benjamin Tietz <benjamin@micronet24.de>

if not supported directly by the driver, the led will be toggled by calling led_set_on(!led_get_on()), transparently.
---
 drivers/led/led-uclass.c |   14 ++++++++++++++
 include/led.h            |   21 +++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/drivers/led/led-uclass.c b/drivers/led/led-uclass.c
index 7d7dec3..22d2264 100644
--- a/drivers/led/led-uclass.c
+++ b/drivers/led/led-uclass.c
@@ -111,6 +111,20 @@ int led_get_on(struct udevice *dev)
 	return ops->get_on(dev);
 }
 
+int led_toggle(struct udevice *dev)
+{
+	struct led_ops *ops = led_get_ops(dev);
+	int on;
+
+	if (ops->toggle)
+		return ops->toggle(dev);
+
+	on = led_get_on(dev);
+	if(on < 0)
+		return -ENOSYS;
+	return led_set_on(dev, !on);
+}
+
 UCLASS_DRIVER(led) = {
 	.id		= UCLASS_LED,
 	.name		= "led",
diff --git a/include/led.h b/include/led.h
index 4709013..f70db00 100644
--- a/include/led.h
+++ b/include/led.h
@@ -36,6 +36,17 @@ struct led_ops {
 	 * @return 0 if OFF, 1 if ON, -ve on error
 	 */
 	int (*get_on)(struct udevice *dev);
+
+	/**
+	 * toggle() - toggle the state of an LED
+	 *
+	 * will turn off the LED if it's on and vice versa.
+	 * Optional. If not given, a fallback using get_on/set_on is provided.
+	 *
+	 * @dev:	LED device to change
+	 * @return 0 if OK, -ve on error
+	 */
+	int (*toggle)(struct udevice *dev);
 };
 
 #define led_get_ops(dev)	((struct led_ops *)(dev)->driver->ops)
@@ -92,4 +103,14 @@ int led_set_on(struct udevice *dev, int on);
  */
 int led_get_on(struct udevice *dev);
 
+/**
+ * led_toggle() - toggle the state of an LED
+ *
+ * will turn off the LED if it's on and vice versa.
+ *
+ * @dev:	LED device to change
+ * @return 0 if OK, -ve on error
+ */
+int led_toggle(struct udevice *dev);
+
 #endif

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [U-Boot] [PATCH23/23] Cmd: LED: make DM-leds toggle
  2016-06-18 12:55 [U-Boot] [PATCH 00/23] DM: Cmd: GPIO/LED/STM32/CLK: provide command-line support for device-tree configured gpios and leds Benjamin Tietz
                   ` (21 preceding siblings ...)
  2016-06-18 12:57 ` [U-Boot] [PATCH22/23] LED: provide toggling interface Benjamin Tietz
@ 2016-06-18 12:57 ` Benjamin Tietz
  2016-06-18 14:07 ` [U-Boot] [PATCH 00/23] DM: Cmd: GPIO/LED/STM32/CLK: provide command-line support for device-tree configured gpios and leds Bin Meng
  23 siblings, 0 replies; 25+ messages in thread
From: Benjamin Tietz @ 2016-06-18 12:57 UTC (permalink / raw)
  To: u-boot

From: Benjamin Tietz <benjamin@micronet24.de>


---
 cmd/led.c |   10 ++++++++++
 1 file changed, 10 insertions(+)
-------------- next part --------------
From: Benjamin Tietz <benjamin@micronet24.de>


---
 cmd/led.c |   10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/cmd/led.c b/cmd/led.c
index 99358c6..3728d30 100644
--- a/cmd/led.c
+++ b/cmd/led.c
@@ -195,11 +195,21 @@ static void _led_dm_onoff(const led_tbl_t *led, enum led_cmd cmd, char *arg)
 		led_set_on(dev, cmd == LED_ON);
 }
 
+static void _led_dm_toggle(const led_tbl_t *led, enum led_cmd cmd, char *arg)
+{
+	struct udevice *dev = NULL;
+	if(led_get_by_label(led->string, &dev))
+		return;
+	if(dev)
+		led_toggle(dev);
+}
+
 // this isn't const, as the string will be replaced by the current led's label, always.
 static led_tbl_t _led_dm = {
 	.op = {
 		[LED_ON] = _led_dm_onoff,
 		[LED_OFF] = _led_dm_onoff,
+		[LED_TOGGLE] = _led_dm_toggle,
 		[LED_LIST] = _led_list_name,
 	},
 };

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [U-Boot] [PATCH 00/23] DM: Cmd: GPIO/LED/STM32/CLK: provide command-line support for device-tree configured gpios and leds
  2016-06-18 12:55 [U-Boot] [PATCH 00/23] DM: Cmd: GPIO/LED/STM32/CLK: provide command-line support for device-tree configured gpios and leds Benjamin Tietz
                   ` (22 preceding siblings ...)
  2016-06-18 12:57 ` [U-Boot] [PATCH23/23] Cmd: LED: make DM-leds toggle Benjamin Tietz
@ 2016-06-18 14:07 ` Bin Meng
  23 siblings, 0 replies; 25+ messages in thread
From: Bin Meng @ 2016-06-18 14:07 UTC (permalink / raw)
  To: u-boot

On Sat, Jun 18, 2016 at 8:55 PM, Benjamin Tietz
<uboot@dresden.micronet24.de> wrote:
> This series begins to provide device-tree support on stm32 devices,
> starting with a the stack of a simple clock-driver (at least
> enabling/disabling peripheral clocks), the gpio driver and leds.
>
> As the current led command-line interface isn't aware of any device-tree
> configured led, the command gets rewritten and extended for device-tree LEDs
> on the way. These changes are architecture indipendent.
>
> To accomplish these changes the led-uclass driver had to be extended, too.
>
>
> The first three (bugfix-)patches had already been sent to list, but hadn't
> received any reply, yet.
> ---
>

Please do not send your patch in an attachment. Instead, send the
patch content directly. Also, please write something as the commit
message to describe the changes in each commit.

Regards,
Bin

^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2016-06-18 14:07 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-18 12:55 [U-Boot] [PATCH 00/23] DM: Cmd: GPIO/LED/STM32/CLK: provide command-line support for device-tree configured gpios and leds Benjamin Tietz
2016-06-18 12:55 ` [U-Boot] [PATCH01/23] stm32: gpio: fix otype access Benjamin Tietz
2016-06-18 12:55 ` [U-Boot] [PATCH02/23] stm32: gpio_direction_output: make sure, output is set to push-pull Benjamin Tietz
2016-06-18 12:55 ` [U-Boot] [PATCH03/23] stm32: gpio_get_value: always return 0 or 1 Benjamin Tietz
2016-06-18 12:55 ` [U-Boot] [PATCH04/23] stm32f429-discovery: config: enable status leds Benjamin Tietz
2016-06-18 12:55 ` [U-Boot] [PATCH05/23] Cmd: led: provide a selector in kconfig Benjamin Tietz
2016-06-18 12:55 ` [U-Boot] [PATCH06/23] DTS: stm32f429: provide device-tree files (from linux kernel) Benjamin Tietz
2016-06-18 12:56 ` [U-Boot] [PATCH07/23] driver: clock: allow disabling a peripheral clock Benjamin Tietz
2016-06-18 12:56 ` [U-Boot] [PATCH08/23] Cmd: clk: make clk-command selectable in kconfig Benjamin Tietz
2016-06-18 12:56 ` [U-Boot] [PATCH09/23] STM32: clock: provide dts-accessible clock driver Benjamin Tietz
2016-06-18 12:56 ` [U-Boot] [PATCH10/23] DTS: STM32f429: add gpio-banks Benjamin Tietz
2016-06-18 12:56 ` [U-Boot] [PATCH11/23] STM32: gpio: group SOC-specific code to one ifdef/elif construct Benjamin Tietz
2016-06-18 12:56 ` [U-Boot] [PATCH12/23] GPIO: STM32: make DTS-aware Benjamin Tietz
2016-06-18 12:56 ` [U-Boot] [PATCH13/23] STM32F429-discovery: led: disable board-specific code, if DM is selected Benjamin Tietz
2016-06-18 12:56 ` [U-Boot] [PATCH14/23] GPIO/LED: make more robust, if STATUS_LED isn't selected Benjamin Tietz
2016-06-18 12:56 ` [U-Boot] [PATCH15/23] Cmd: LED: rewrite to prepare non-static access Benjamin Tietz
2016-06-18 12:56 ` [U-Boot] [PATCH16/23] DTS: STM32F429-disco: add board leds and enable rcc Benjamin Tietz
2016-06-18 12:56 ` [U-Boot] [PATCH17/23] LED: add function to retrieve a device's label Benjamin Tietz
2016-06-18 12:56 ` [U-Boot] [PATCH18/23] LED: provide function to count and get all (DM-)LEDs Benjamin Tietz
2016-06-18 12:57 ` [U-Boot] [PATCH19/23] cmd: LED: be aware of DTS-configured leds Benjamin Tietz
2016-06-18 12:57 ` [U-Boot] [PATCH20/23] LED: provide functionality to get led status Benjamin Tietz
2016-06-18 12:57 ` [U-Boot] [PATCH21/23] LED: GPIO: provide get_on() op Benjamin Tietz
2016-06-18 12:57 ` [U-Boot] [PATCH22/23] LED: provide toggling interface Benjamin Tietz
2016-06-18 12:57 ` [U-Boot] [PATCH23/23] Cmd: LED: make DM-leds toggle Benjamin Tietz
2016-06-18 14:07 ` [U-Boot] [PATCH 00/23] DM: Cmd: GPIO/LED/STM32/CLK: provide command-line support for device-tree configured gpios and leds Bin Meng

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.