Skip to contentSkip to conversation

leds: add leds-mt6323 support on MT7623 SoC

PATCH Superseded [email protected] 5 participants 11 messages Mar 3, 2017 – Mar 14, 2017

Subsystems (5)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

v5 cover leds: add leds-mt6323 support on MT7623 SoC

From: Sean Wang <[email protected]>

MT7623 SoC uses MT6323 PMIC as the default power supply which has LED function insides. The patchset introduces the LED support for MT6323 with on, off and hardware dimmed and blinked and it should work on other similar SoCs if also using MT6323.

Changes since v1:
- fixed typo in the comments
- sorted include directives alphabetically
- applied all register definitions with MT6323 prefix
- removed the redundant structure declaration
- fixed coding style defined in kernel doc format consistently
- added error handling into all the occurrences where regmap APIs are used
- removed loudly debug message
- made magic constant into meaningful macro
- added missing mutex_destroy when module removed called
- updated module license with GPL
- fixed sparse warnings

Changes since v2:
- fixed the typo in devicetree Documentation
- cleaned up the style and explanation in the comments
- applied all macro/struct/function definitions with MT6323 prefix
- put the logic about the setup from device tree into function for simplicity

Changes since v3:
- changed the variable current_brightness into the proper type
- removed the redundant member led_num from mt6323_leds structure
- collected the brightness setting into mt6323_led_hw_brightness() call
- added brightness_get() support into the core layer
- fixed zero duty cycle handling due to hardware doesn't support
- fixed duty cycle calculation mapping to the hardware register
- added the brightness as the input in mt6323_led_hw_on() call
- enhanced error handling in mt6323_led_set_dt_default() call
- fixed potential issue which caused accessing unallocated memory if excessive the led controller nodes are defined
- fixed redundant memory allocation in mt6323_leds structure
- added reg property for defining the led controller for which the child node is predestined

Changes since v4:
- enhanced the example in leds-mt6323.txt for patch 1/4 with adding the missing #address-cell and #size-cell, correcting sub-node naming with led at 0 style, removing the unrelated setup for LED and moving the description for the node properties into the right place
- enhanced the documentation in mt6397.txt for patch 2/4
- changed the subject prefixes into "dt-bindings: ..." for the device tree commits
- fixed that missing of_node_put() in the error path called from mt6323_led_probe()
- fixed that incorrect duty_cycle calculation mapping into the hardware register in case duty ratio is lower than 1/64 rather than 0

Sean Wang (4):
dt-bindings: leds: Add document bindings for leds-mt6323
dt-bindings: mfd: Add LED subnode binding for MT6323 PMIC
leds: Add LED support for MT6323 PMIC
mfd: mt6397: Add MT6323 LED support into MT6397 driver

 .../devicetree/bindings/leds/leds-mt6323.txt       |  63 +++
 Documentation/devicetree/bindings/mfd/mt6397.txt   |   5 +
 drivers/leds/Kconfig                               |   8 +
 drivers/leds/Makefile                              |   1 +
 drivers/leds/leds-mt6323.c                         | 502 +++++++++++++++++++++
 drivers/mfd/mt6397-core.c                          |   4 +
 6 files changed, 583 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/leds-mt6323.txt
 create mode 100644 drivers/leds/leds-mt6323.c
Signature · 1 line
1.9.1
author maintainer
#1 lore raw

PATCH v5 1/4 dt-bindings: leds: Add document bindings for leds-mt6323

From: Sean Wang <[email protected]>

This patch adds documentation for devicetree bindings for LED support on MT6323 PMIC

---
 .../devicetree/bindings/leds/leds-mt6323.txt       | 63 ++++++++++++++++++++++
 1 file changed, 63 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/leds-mt6323.txt
Documentation/devicetree/bindings/leds/leds-mt6323.txt new file +63 -0
new file mode 100644
index 0000000..135c441
@@ -0,0 +1,63 @@
+Device Tree Bindings for LED support on MT6323 PMIC
+
+MT6323 LED controller is subfunction provided by
+MT6323 PMIC, so the LED controllers are defined as
+the subnode of the function node provided by MT6323
+PMIC controller that is being defined as one kind of
+Muti-Function Device (MFD) using shared bus called
+PMIC wrapper for each subfunction to access remote
+MT6323 PMIC hardware.
+
+For MT6323 MFD bindings see:
+Documentation/devicetree/bindings/mfd/mt6397.txt
+For MediaTek PMIC wrapper bindings see:
+Documentation/devicetree/bindings/soc/mediatek/pwrap.txt
+
+There's sub-node for the LED controller that describes
+the initial behavior for each LED physically and currently
+only four LED sub-nodes can be supported.
+
+Required properties:
+- compatible : Must be "mediatek,mt6323-led"
+- address-cells : Must be 1
+- size-cells : Must be 0
+
+LED sub-node properties:
+- reg : LED channel number (0..3)
+- label : (optional)
+  see Documentation/devicetree/bindings/leds/common.txt
+- linux,default-trigger : (optional)
+  see Documentation/devicetree/bindings/leds/common.txt
+- default-state: (optional) The initial state of the LED
+  see Documentation/devicetree/bindings/leds/common.txt
+
+Example:
+
+	pmic: mt6323 {
+		compatible = "mediatek,mt6323";
+
+		...
+
+		mt6323led: leds {
+			compatible = "mediatek,mt6323-led";
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			led at 0 {
+				reg = <0>;
+				label = "LED0";
+				linux,default-trigger = "timer";
+				default-state = "on";
+			};
+			led at 1 {
+				reg = <1>;
+				label = "LED1";
+				default-state = "off";
+			};
+			led at 2 {
+				reg = <2>;
+				label = "LED2";
+				default-state = "on";
+			};
+		};
+	};
Signature · 1 line
1.9.1
maintainer
#2 lore raw

Re: [PATCH v5 1/4] dt-bindings: leds: Add document bindings for leds-mt6323

Quoted 17 lines · sean.wang at mediatek.com

From: Sean Wang <[email protected]>

This patch adds documentation for devicetree bindings for LED support on MT6323 PMIC

---
 .../devicetree/bindings/leds/leds-mt6323.txt       | 63 ++++++++++++++++++++++
 1 file changed, 63 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/leds-mt6323.txt
Documentation/devicetree/bindings/leds/leds-mt6323.txt new file +0 -0
new file mode 100644
index 0000000..135c441

Documentation/devicetree/bindings/leds/leds-mt6323.txt line 9

Quoted 9 lines
Documentation/devicetree/bindings/leds/leds-mt6323.txt new file +9 -0
@@ -0,0 +1,63 @@
+Device Tree Bindings for LED support on MT6323 PMIC
+
+MT6323 LED controller is subfunction provided by
+MT6323 PMIC, so the LED controllers are defined as
+the subnode of the function node provided by MT6323
+PMIC controller that is being defined as one kind of
+Muti-Function Device (MFD) using shared bus called
+PMIC wrapper for each subfunction to access remote
+MT6323 PMIC hardware.

Your line wrap is kind of short. Fix you line wrap to 72-80 char.

Quoted 13 lines
Documentation/devicetree/bindings/leds/leds-mt6323.txt new file +13 -0
+
+For MT6323 MFD bindings see:
+Documentation/devicetree/bindings/mfd/mt6397.txt
+For MediaTek PMIC wrapper bindings see:
+Documentation/devicetree/bindings/soc/mediatek/pwrap.txt
+
+There's sub-node for the LED controller that describes
+the initial behavior for each LED physically and currently
+only four LED sub-nodes can be supported.
+
+Required properties:
+- compatible : Must be "mediatek,mt6323-led"
+- address-cells : Must be 1

Documentation/devicetree/bindings/leds/leds-mt6323.txt line 32

Quoted 10 lines
Documentation/devicetree/bindings/leds/leds-mt6323.txt new file +10 -0
+- size-cells : Must be 0
+
+LED sub-node properties:
+- reg : LED channel number (0..3)
+- label : (optional)
+  see Documentation/devicetree/bindings/leds/common.txt
+- linux,default-trigger : (optional)
+  see Documentation/devicetree/bindings/leds/common.txt
+- default-state: (optional) The initial state of the LED
+  see Documentation/devicetree/bindings/leds/common.txt

Group these by required and optional. You can drop "The initial state of the LED".

Documentation/devicetree/bindings/leds/leds-mt6323.txt line 36

Quoted 4 lines
Documentation/devicetree/bindings/leds/leds-mt6323.txt new file +4 -0
+
+Example:
+
+	pmic: mt6323 {

mt6323: pmic {

Quoted 30 lines
Documentation/devicetree/bindings/leds/leds-mt6323.txt new file +27 -0
+		compatible = "mediatek,mt6323";
+
+		...
+
+		mt6323led: leds {
+			compatible = "mediatek,mt6323-led";
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			led at 0 {
+				reg = <0>;
+				label = "LED0";
+				linux,default-trigger = "timer";
+				default-state = "on";
+			};
+			led at 1 {
+				reg = <1>;
+				label = "LED1";
+				default-state = "off";
+			};
+			led at 2 {
+				reg = <2>;
+				label = "LED2";
+				default-state = "on";
+			};
+		};
+	};
Signature · 1 line
1.9.1
author maintainer
#3 lore raw

PATCH v5 2/4 dt-bindings: mfd: Add LED subnode binding for MT6323 PMIC

In reply to [email protected]

From: Sean Wang <[email protected]>

This patch adds documentation for devicetree bindings for LED support as the subnode of MT6323 PMIC

---
 Documentation/devicetree/bindings/mfd/mt6397.txt | 5 +++++
 1 file changed, 5 insertions(+)
Documentation/devicetree/bindings/mfd/mt6397.txt +5 -0
index 949c85f..522a3bb 100644
@@ -6,6 +6,7 @@ MT6397/MT6323 is a multifunction device with the following sub modules:
 - Audio codec
 - GPIO
 - Clock
+- LED
 
 It is interfaced to host controller using SPI interface by a proprietary hardware
 called PMIC wrapper or pwrap. MT6397/MT6323 MFD is a child device of pwrap.
@@ -34,6 +35,10 @@ Optional subnodes:
 - clk
 	Required properties:
 		- compatible: "mediatek,mt6397-clk"
+- led
+	Required properties:
+		- compatible: "mediatek,mt6323-led"
+	see Documentation/devicetree/bindings/leds/leds-mt6323.txt
 
 Example:
 	pwrap: pwrap at 1000f000 {
Signature · 1 line
1.9.1
maintainer Acked-by on v5 2/4
#4 lore raw

Re: [PATCH v5 2/4] dt-bindings: mfd: Add LED subnode binding for MT6323 PMIC

Quoted 9 lines · sean.wang at mediatek.com

From: Sean Wang <[email protected]>

This patch adds documentation for devicetree bindings for LED support as the subnode of MT6323 PMIC

---
 Documentation/devicetree/bindings/mfd/mt6397.txt | 5 +++++
 1 file changed, 5 insertions(+)
maintainer
#5 lore raw

Re: [PATCH v5 2/4] dt-bindings: mfd: Add LED subnode binding for MT6323 PMIC

In reply to [email protected]
Quoted 23 lines · sean.wang at mediatek.com

From: Sean Wang <[email protected]>

This patch adds documentation for devicetree bindings for LED support as the subnode of MT6323 PMIC

---
 Documentation/devicetree/bindings/mfd/mt6397.txt | 5 +++++
 1 file changed, 5 insertions(+)
Documentation/devicetree/bindings/mfd/mt6397.txt +1 -0
index 949c85f..522a3bb 100644
@@ -6,6 +6,7 @@ MT6397/MT6323 is a multifunction device with the following sub modules:
 - Audio codec
 - GPIO
 - Clock
+- LED
 
 It is interfaced to host controller using SPI interface by a proprietary hardware
 called PMIC wrapper or pwrap. MT6397/MT6323 MFD is a child device of pwrap.

Documentation/devicetree/bindings/mfd/mt6397.txt Optional subnodes: · line 41

Quoted 7 lines
Documentation/devicetree/bindings/mfd/mt6397.txt +4 -0
@@ -34,6 +35,10 @@ Optional subnodes:
 - clk
 	Required properties:
 		- compatible: "mediatek,mt6397-clk"
+- led
+	Required properties:
+		- compatible: "mediatek,mt6323-led"
+	see Documentation/devicetree/bindings/leds/leds-mt6323.txt

Part of this patch is already part of linux-next:
05daab3 ("Documentation: devicetree: Add LED subnode binding for MT6323 PMIC")

Regards,
Matthias

#6 lore raw

Re: [PATCH v5 2/4] dt-bindings: mfd: Add LED subnode binding for MT6323 PMIC

Hi Matthias,

Quoted 25 lines · Matthias Brugger
Quoted 22 lines · sean.wang at mediatek.com

From: Sean Wang <[email protected]>

This patch adds documentation for devicetree bindings for LED support as the subnode of MT6323 PMIC

---
 Documentation/devicetree/bindings/mfd/mt6397.txt | 5 +++++
 1 file changed, 5 insertions(+)
Documentation/devicetree/bindings/mfd/mt6397.txt +0 -0
index 949c85f..522a3bb 100644
@@ -6,6 +6,7 @@ MT6397/MT6323 is a multifunction device with the

following sub modules:
- Audio codec
- GPIO
- Clock
+- LED

Quoted 16 lines

Documentation/devicetree/bindings/mfd/mt6397.txt Optional subnodes: · line 41

Quoted 12 lines

It is interfaced to host controller using SPI interface by a
proprietary hardware
called PMIC wrapper or pwrap. MT6397/MT6323 MFD is a child device of
pwrap.

Documentation/devicetree/bindings/mfd/mt6397.txt +4 -0
@@ -34,6 +35,10 @@ Optional subnodes:
 - clk
     Required properties:
         - compatible: "mediatek,mt6397-clk"
+- led
+    Required properties:
+        - compatible: "mediatek,mt6323-led"
+    see Documentation/devicetree/bindings/leds/leds-mt6323.txt

Part of this patch is already part of linux-next:
05daab3 ("Documentation: devicetree: Add LED subnode binding for MT6323 PMIC")

Yes, it's been merged via mfd tree. It doesn't break anything besides that it points to non-existent file. Hopefully we will manage to merge the LED part before merge window, otherwise the mfd part will have to be dropped.

Signature · 2 lines
Best regards,
Jacek Anaszewski
author maintainer
#7 lore raw

Re: [PATCH v5 2/4] dt-bindings: mfd: Add LED subnode binding for MT6323 PMIC

In reply to Matthias Brugger
Quoted 22 lines · Matthias Brugger
Quoted 20 lines · sean.wang at mediatek.com

From: Sean Wang <[email protected]>

This patch adds documentation for devicetree bindings for LED support as the subnode of MT6323 PMIC

---
 Documentation/devicetree/bindings/mfd/mt6397.txt | 5 +++++
 1 file changed, 5 insertions(+)
Documentation/devicetree/bindings/mfd/mt6397.txt +1 -0
index 949c85f..522a3bb 100644
@@ -6,6 +6,7 @@ MT6397/MT6323 is a multifunction device with the following sub modules:
 - Audio codec
 - GPIO
 - Clock
+- LED
 
Quoted 15 lines

Documentation/devicetree/bindings/mfd/mt6397.txt Optional subnodes: · line 41

Quoted 10 lines
Documentation/devicetree/bindings/mfd/mt6397.txt +4 -0
 It is interfaced to host controller using SPI interface by a proprietary hardware
 called PMIC wrapper or pwrap. MT6397/MT6323 MFD is a child device of pwrap.
@@ -34,6 +35,10 @@ Optional subnodes:
 - clk
 	Required properties:
 		- compatible: "mediatek,mt6397-clk"
+- led
+	Required properties:
+		- compatible: "mediatek,mt6323-led"
+	see Documentation/devicetree/bindings/leds/leds-mt6323.txt

Part of this patch is already part of linux-next:
05daab3 ("Documentation: devicetree: Add LED subnode binding for MT6323 PMIC")

Hi Matthias,

There is still small differences from the merged patch.

I will submit the series for the next version based on newer kernel and

split the already merged ones out. Thanks for your kindly remainder.

Sean

Quoted 2 lines

Regards,
Matthias

author maintainer
#8 lore raw

PATCH v5 3/4 leds: Add LED support for MT6323 PMIC

In reply to [email protected]

From: Sean Wang <[email protected]>

MT6323 PMIC is a multi-function device that includes LED function. It allows attaching up to 4 LEDs which can either be on, off or dimmed and/or blinked with the controller.

---
 drivers/leds/Kconfig       |   8 +
 drivers/leds/Makefile      |   1 +
 drivers/leds/leds-mt6323.c | 502 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 511 insertions(+)
 create mode 100644 drivers/leds/leds-mt6323.c
drivers/leds/Kconfig +8 -0
index c621cbb..30095fc 100644
@@ -117,6 +117,14 @@ config LEDS_MIKROTIK_RB532
 	  This option enables support for the so called "User LED" of
 	  Mikrotik's Routerboard 532.
 
+config LEDS_MT6323
+	tristate "LED Support for Mediatek MT6323 PMIC"
+	depends on LEDS_CLASS
+	depends on MFD_MT6397
+	help
+	  This option enables support for on-chip LED drivers found on
+	  Mediatek MT6323 PMIC.
+
 config LEDS_S3C24XX
 	tristate "LED Support for Samsung S3C24XX GPIO LEDs"
 	depends on LEDS_CLASS
drivers/leds/Makefile +1 -0
index 6b82737..4feb332 100644
@@ -72,6 +72,7 @@ obj-$(CONFIG_LEDS_IS31FL32XX)		+= leds-is31fl32xx.o
 obj-$(CONFIG_LEDS_PM8058)		+= leds-pm8058.o
 obj-$(CONFIG_LEDS_MLXCPLD)		+= leds-mlxcpld.o
 obj-$(CONFIG_LEDS_NIC78BX)		+= leds-nic78bx.o
+obj-$(CONFIG_LEDS_MT6323)		+= leds-mt6323.o
 
 # LED SPI Drivers
 obj-$(CONFIG_LEDS_DAC124S085)		+= leds-dac124s085.o
drivers/leds/leds-mt6323.c new file +502 -0

502 lines not on this page · raw message

Signature · 1 line
1.9.1
author maintainer
#9 lore raw

PATCH v5 4/4 mfd: mt6397: Add MT6323 LED support into MT6397 driver

In reply to [email protected]

From: Sean Wang <[email protected]>

Add compatible string as "mt6323-led" that will make the OF core spawn child devices for the LED subnode of that MT6323 MFD device.

---
 drivers/mfd/mt6397-core.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/mfd/mt6397-core.c +4 -0
index e14d8b0..8e601c8 100644
@@ -48,6 +48,10 @@
 		.name = "mt6323-regulator",
 		.of_compatible = "mediatek,mt6323-regulator"
 	},
+	{
+		.name = "mt6323-led",
+		.of_compatible = "mediatek,mt6323-led"
+	},
 };
 
 static const struct mfd_cell mt6397_devs[] = {
Signature · 1 line
1.9.1
#10 lore raw

Re: [PATCH v5 4/4] mfd: mt6397: Add MT6323 LED support into MT6397 driver

Quoted 10 lines · sean.wang at mediatek.com

From: Sean Wang <[email protected]>

Add compatible string as "mt6323-led" that will make the OF core spawn child devices for the LED subnode of that MT6323 MFD device.

---
 drivers/mfd/mt6397-core.c | 4 ++++
 1 file changed, 4 insertions(+)

For my own reference:

drivers/mfd/mt6397-core.c line 51

Quoted 9 lines
drivers/mfd/mt6397-core.c +1 -0
index e14d8b0..8e601c8 100644
@@ -48,6 +48,10 @@
 		.name = "mt6323-regulator",
 		.of_compatible = "mediatek,mt6323-regulator"
 	},
+	{

Put this on the line above.

Quoted 6 lines
drivers/mfd/mt6397-core.c +3 -0
+		.name = "mt6323-led",
+		.of_compatible = "mediatek,mt6323-led"
+	},
 };
 
 static const struct mfd_cell mt6397_devs[] = {
Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org ? Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog