2015-11-02 05:24:46

by Kim, Milo

[permalink] [raw]
Subject: [PATCH RESEND 00/16] Support TI LMU devices

TI LMU(Lighting Management Unit) driver supports lighting devices below.

Enable pin Backlights HWMON LEDs Regulators
---------- ---------- ----- ---- ------------
LM3532 o o x x x
LM3631 o o x x 5 regulators
LM3632 o o x x 3 regulators
LM3633 o o o o x
LM3695 o o x x x
LM3697 o o o x x

This patch-set consists of several parts below.

DT bindings : Binding information for each module
TI LMU MFD : Device registration, HW enable pin control and
I2C register access
TI LMU backlight : Common driver for TI LMU backlight devices
Each backlight driver : Chip dependent code
HWMON : LMU hardware fault monitoring driver
LM3633 LED : LED subsystem and dimming pattern generation
supported
LM363X regulator : LM3631 and LM3632 regulator driver for the
display bias

Git location:
Please refer to the location below. Branch name is 'ti-lmu'.
git clone -b ti-lmu https://github.com/milokim/linux.git

Milo Kim (16):
Documentation: dt-bindings: mfd: add TI LMU device binding information
Documentation: dt-bindings: backlight: add TI LMU backlight binding
information
Documentation: dt-bindings: hwmon: add TI LMU HWMON binding
information
Documentation: dt-bindings: leds: add LM3633 LED binding information
Documentation: dt-bindings: regulator: add LM363x regulator binding
information
mfd: add TI LMU driver
backlight: add TI LMU backlight common driver
backlight: ti-lmu-backlight: add LM3532 driver
backlight: ti-lmu-backlight: add LM3631 driver
backlight: ti-lmu-backlight: add LM3632 driver
backlight: ti-lmu-backlight: add LM3633 driver
backlight: ti-lmu-backlight: add LM3695 driver
backlight: ti-lmu-backlight: add LM3697 driver
hwmon: add TI LMU hardware fault monitoring driver
leds: add LM3633 driver
regulator: add LM363X driver

Documentation/ABI/testing/sysfs-class-led-lm3633 | 60 ++
.../devicetree/bindings/hwmon/ti-lmu-hwmon.txt | 12 +
.../devicetree/bindings/leds/leds-lm3633.txt | 28 +
Documentation/devicetree/bindings/mfd/ti-lmu.txt | 282 ++++++++
.../bindings/regulator/lm363x-regulator.txt | 28 +
.../bindings/video/backlight/ti-lmu-backlight.txt | 67 ++
drivers/hwmon/Kconfig | 10 +
drivers/hwmon/Makefile | 1 +
drivers/hwmon/ti-lmu-hwmon.c | 393 +++++++++++
drivers/leds/Kconfig | 10 +
drivers/leds/Makefile | 1 +
drivers/leds/leds-lm3633.c | 749 +++++++++++++++++++++
drivers/mfd/Kconfig | 12 +
drivers/mfd/Makefile | 1 +
drivers/mfd/ti-lmu.c | 324 +++++++++
drivers/regulator/Kconfig | 9 +
drivers/regulator/Makefile | 1 +
drivers/regulator/lm363x-regulator.c | 349 ++++++++++
drivers/video/backlight/Kconfig | 62 ++
drivers/video/backlight/Makefile | 7 +
drivers/video/backlight/lm3532_bl.c | 183 +++++
drivers/video/backlight/lm3631_bl.c | 129 ++++
drivers/video/backlight/lm3632_bl.c | 125 ++++
drivers/video/backlight/lm3633_bl.c | 210 ++++++
drivers/video/backlight/lm3695_bl.c | 91 +++
drivers/video/backlight/lm3697_bl.c | 187 +++++
drivers/video/backlight/ti-lmu-backlight.c | 429 ++++++++++++
drivers/video/backlight/ti-lmu-backlight.h | 152 +++++
include/linux/mfd/ti-lmu-register.h | 277 ++++++++
include/linux/mfd/ti-lmu.h | 81 +++
30 files changed, 4270 insertions(+)
create mode 100644 Documentation/ABI/testing/sysfs-class-led-lm3633
create mode 100644 Documentation/devicetree/bindings/hwmon/ti-lmu-hwmon.txt
create mode 100644 Documentation/devicetree/bindings/leds/leds-lm3633.txt
create mode 100644 Documentation/devicetree/bindings/mfd/ti-lmu.txt
create mode 100644 Documentation/devicetree/bindings/regulator/lm363x-regulator.txt
create mode 100644 Documentation/devicetree/bindings/video/backlight/ti-lmu-backlight.txt
create mode 100644 drivers/hwmon/ti-lmu-hwmon.c
create mode 100644 drivers/leds/leds-lm3633.c
create mode 100644 drivers/mfd/ti-lmu.c
create mode 100644 drivers/regulator/lm363x-regulator.c
create mode 100644 drivers/video/backlight/lm3532_bl.c
create mode 100644 drivers/video/backlight/lm3631_bl.c
create mode 100644 drivers/video/backlight/lm3632_bl.c
create mode 100644 drivers/video/backlight/lm3633_bl.c
create mode 100644 drivers/video/backlight/lm3695_bl.c
create mode 100644 drivers/video/backlight/lm3697_bl.c
create mode 100644 drivers/video/backlight/ti-lmu-backlight.c
create mode 100644 drivers/video/backlight/ti-lmu-backlight.h
create mode 100644 include/linux/mfd/ti-lmu-register.h
create mode 100644 include/linux/mfd/ti-lmu.h

--
1.9.1


2015-11-02 05:25:39

by Kim, Milo

[permalink] [raw]
Subject: [PATCH RESEND 01/16] Documentation: dt-bindings: mfd: add TI LMU device binding information

This patch describes overall binding for TI LMU MFD devices.

Cc: [email protected]
Cc: Lee Jones <[email protected]>
Cc: [email protected]
Signed-off-by: Milo Kim <[email protected]>
---
Documentation/devicetree/bindings/mfd/ti-lmu.txt | 282 +++++++++++++++++++++++
1 file changed, 282 insertions(+)
create mode 100644 Documentation/devicetree/bindings/mfd/ti-lmu.txt

diff --git a/Documentation/devicetree/bindings/mfd/ti-lmu.txt b/Documentation/devicetree/bindings/mfd/ti-lmu.txt
new file mode 100644
index 0000000..7ccf07e
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/ti-lmu.txt
@@ -0,0 +1,282 @@
+TI LMU(Lighting Management Unit) device tree bindings
+
+TI LMU driver supports lighting devices belows.
+
+ Name Child nodes
+ ------ -------------------------
+ LM3532 Backlight
+ LM3631 Backlight and regulator
+ LM3632 Backlight and regulator
+ LM3633 Backlight, LED and HWMON
+ LM3695 Backlight
+ LM3697 Backlight and HWMON
+
+Required properties:
+ - compatible: Should be one of lists below.
+ "ti,lm3532"
+ "ti,lm3631"
+ "ti,lm3632"
+ "ti,lm3633"
+ "ti,lm3695"
+ "ti,lm3697"
+ - reg: I2C slave address.
+ 0x11 is LM3632
+ 0x29 is LM3631
+ 0x36 is LM3633, LM3697
+ 0x38 is LM3532
+ 0x63 is LM3695
+
+Optional properties:
+ - enable-gpios: A GPIO specifier for hardware enable pin.
+
+Required node:
+ - backlight: All LMU devices have backlight child nodes.
+ For the properties, please refer to [1].
+
+Optional nodes:
+ - hwmon: Hardware fault monitoring driver for LM3633 and LM3697.
+ For the property, please refer to [2].
+ - leds: LED properties for LM3633. Please refer to [3].
+ - regulators: Regulator properties for LM3631 and LM3632.
+ Please refer to [4].
+
+[1] Documentation/devicetree/bindings/video/backlight/ti-lmu-backlight.txt
+[2] Documentation/devicetree/bindings/hwm/ti-lmu-hwmon.txt
+[3] Documentation/devicetree/bindings/leds/leds-lm3633.txt
+[4] Documentation/devicetree/bindings/regulator/lm363x-regulator.txt
+
+Examples:
+
+LM3532 has a backlight device. External GPIO is used for enabling LM3532.
+
+lm3532@38 {
+ compatible = "ti,lm3532";
+ reg = <0x38>;
+
+ enable-gpios = <&pioC 2 GPIO_ACTIVE_HIGH>;
+
+ backlight {
+ compatible = "ti,lm3532-backlight";
+
+ lcd {
+ hvled1-used;
+ hvled2-used;
+ hvled3-used;
+
+ ramp-up-msec = <30>;
+ ramp-down-msec = <0>;
+
+ backlight-max-microamp = <5000>;
+ };
+ };
+};
+
+LM3631 has 5 regulators with one backlight device.
+
+lm3631@29 {
+ compatible = "ti,lm3631";
+ reg = <0x29>;
+
+ regulators {
+ compatible = "ti,lm363x-regulator";
+
+ vboost {
+ regulator-name = "lcd_boost";
+ regulator-min-microvolt = <4500000>;
+ regulator-max-microvolt = <6350000>;
+ regulator-always-on;
+ };
+
+ vcont {
+ regulator-name = "lcd_vcont";
+ regulator-min-microvolt = <1800000>;
+ regulator-max-microvolt = <3300000>;
+ };
+
+ voref {
+ regulator-name = "lcd_voref";
+ regulator-min-microvolt = <4000000>;
+ regulator-max-microvolt = <6000000>;
+ };
+
+ vpos {
+ regulator-name = "lcd_vpos";
+ regulator-min-microvolt = <4000000>;
+ regulator-max-microvolt = <6000000>;
+ regulator-boot-on;
+ };
+
+ vneg {
+ regulator-name = "lcd_vneg";
+ regulator-min-microvolt = <4000000>;
+ regulator-max-microvolt = <6000000>;
+ regulator-boot-on;
+ };
+ };
+
+ backlight {
+ compatible = "ti,lm3631-backlight";
+
+ lcd {
+ backlight-name = "lcd_bl";
+ hvled1-used;
+ hvled2-used;
+
+ ramp-up-msec = <300>;
+ };
+ };
+};
+
+LM3632 has 3 regulators with one backlight device. External GPIO is
+used for enabling LM3632.
+
+lm3632@11 {
+ compatible = "ti,lm3632";
+ reg = <0x11>;
+
+ enable-gpios = <&pioC 2 GPIO_ACTIVE_HIGH>;
+
+ regulators {
+ compatible = "ti,lm363x-regulator";
+
+ ti,lcm-en1-gpio = <&pioC 0 GPIO_ACTIVE_HIGH>;
+ ti,lcm-en2-gpio = <&pioC 1 GPIO_ACTIVE_HIGH>;
+
+ vboost {
+ regulator-name = "lcd_boost";
+ regulator-min-microvolt = <4500000>;
+ regulator-max-microvolt = <6400000>;
+ regulator-always-on;
+ };
+
+ vpos {
+ regulator-name = "lcd_vpos";
+ regulator-min-microvolt = <4000000>;
+ regulator-max-microvolt = <6000000>;
+ };
+
+ vneg {
+ regulator-name = "lcd_vneg";
+ regulator-min-microvolt = <4000000>;
+ regulator-max-microvolt = <6000000>;
+ };
+ };
+
+ backlight {
+ compatible = "ti,lm3632-backlight";
+
+ lcd {
+ backlight-name = "lcd";
+ hvled1-used;
+ hvled2-used;
+ };
+ };
+};
+
+LM3633 has multiple backlight channels, LED channels and hardware fault
+monitoring driver. External GPIO is used for enabling LM3633.
+
+lm3633@36 {
+ compatible = "ti,lm3633";
+ reg = <0x36>;
+
+ enable-gpios = <&pioC 2 GPIO_ACTIVE_HIGH>;
+
+ backlight {
+ compatible = "ti,lm3633-backlight";
+
+ pwms = <&pwm0 0 10000 0>; /* pwm number, period, polarity */
+ pwm-names = "lmu-backlight";
+
+ main {
+ backlight-name = "main_lcd";
+ hvled2-used;
+ hvled3-used;
+ backlight-max-microamp = <20000>;
+
+ ramp-up-msec = <500>;
+ ramp-down-msec = <500>;
+ };
+
+ front {
+ backlight-name = "front_lcd";
+ hvled1-used;
+
+ ramp-up-msec = <1000>;
+ ramp-down-msec = <0>;
+
+ pwm-period = <10000>;
+ };
+ };
+
+ leds {
+ compatible = "ti,lm3633-leds";
+
+ chan2 {
+ channel-name = "status";
+ lvled2-used;
+ led-max-microamp = <6000>;
+ };
+
+ chan456 {
+ channel-name = "rgb";
+ lvled4-used;
+ lvled5-used;
+ lvled6-used;
+ };
+ };
+
+ hwmon {
+ compatible = "ti,lm3633-hwmon";
+ };
+};
+
+LM3695 is single backlight device.
+
+lm3695@63 {
+ compatible = "ti,lm3695";
+ reg = <0x63>;
+
+ backlight {
+ compatible = "ti,lm3695-backlight";
+
+ lcd {
+ hvled1-used;
+ hvled2-used;
+ backlight-max-microamp = <20000>;
+ };
+ };
+};
+
+LM3697 has one backlight device and hardware fault monitoring driver.
+External GPIO is used for enabling LM3697.
+
+lm3697@36 {
+ compatible = "ti,lm3697";
+ reg = <0x36>;
+
+ enable-gpios = <&pioC 2 GPIO_ACTIVE_HIGH>;
+
+ backlight {
+ compatible = "ti,lm3697-backlight";
+
+ pwms = <&pwm0 0 10000 0>; /* pwm number, period, polarity */
+ pwm-names = "lmu-backlight";
+
+ lcd {
+ backlight-name = "bl";
+ hvled1-used;
+ hvled2-used;
+ hvled3-used;
+ backlight-max-microamp = <20000>;
+
+ ramp-up-msec = <500>;
+ ramp-down-msec = <500>;
+ pwm-period = <10000>;
+ };
+ };
+
+ hwmon {
+ compatible = "ti,lm3697-hwmon";
+ };
+};
--
1.9.1

2015-11-02 05:25:34

by Kim, Milo

[permalink] [raw]
Subject: [PATCH RESEND 02/16] Documentation: dt-bindings: backlight: add TI LMU backlight binding information

LM3532, LM3631, LM3632, LM3633, LM3695 and LM3697 use common dt-bindings
for describing device.

Cc: [email protected]
Cc: Jingoo Han <[email protected]>
Cc: Lee Jones <[email protected]>
Cc: [email protected]
Signed-off-by: Milo Kim <[email protected]>
---
.../bindings/video/backlight/ti-lmu-backlight.txt | 67 ++++++++++++++++++++++
1 file changed, 67 insertions(+)
create mode 100644 Documentation/devicetree/bindings/video/backlight/ti-lmu-backlight.txt

diff --git a/Documentation/devicetree/bindings/video/backlight/ti-lmu-backlight.txt b/Documentation/devicetree/bindings/video/backlight/ti-lmu-backlight.txt
new file mode 100644
index 0000000..27b0036
--- /dev/null
+++ b/Documentation/devicetree/bindings/video/backlight/ti-lmu-backlight.txt
@@ -0,0 +1,67 @@
+TI LMU backlight device tree bindings
+
+Required properties:
+ - compatible: Should be one of lists below.
+ "ti,lm3532-backlight"
+ "ti,lm3631-backlight"
+ "ti,lm3632-backlight"
+ "ti,lm3633-backlight"
+ "ti,lm3695-backlight"
+ "ti,lm3697-backlight"
+
+Optional properties:
+ There are two backlight control mode. One is I2C, the other is PWM mode.
+ Following properties are only specified in PWM mode.
+ Please note that LMU backlight device can have only one PWM channel.
+
+ - pwms: OF device-tree PWM specification.
+ - pwm-names: a list of names for the PWM devices specified in the "pwms"
+ property.
+
+ For the PWM user nodes, please refer to [1].
+
+Child nodes:
+ LMU backlight is represented as sub-nodes of the TI LMU device [2].
+ So, LMU backlight should have more than one backlight child node.
+ Each node exactly matches with backlight control bank configuration.
+ Maximum numbers of child nodes depend on the device.
+ 1 = LM3631, LM3632, LM3695
+ 2 = LM3633, LM3697
+ 3 = LM3532
+
+ Required property of a child node:
+ - hvled1-used, hvled2-used, hvled3-used:
+ High voltage backlight strings configuration. Type is <boolean>.
+ Please describe which output backlight string is used.
+ Please refer to the datasheets [3].
+
+ Optional properties of a child node:
+ - backlight-name: Name string for backlight device identification.
+ It is used for creating backlight sysfs,
+ /sys/class/backlight/<backlight-name>/.
+ - backlight-max-microamp: Max current setting. Type is <u32>.
+ Unit is microampere.
+ Range is from 5000 to 30000.
+ - initial-brightness: Backlight initial brightness value. Type is <u32>.
+ It is set as soon as backlight device is created.
+ 0 ~ 2047 = LM3631, LM3632, LM3633, LM3695 and LM3697
+ 0 ~ 255 = LM3532
+ - ramp-up-msec, ramp-down-msec: Light dimming effect properties.
+ Type is <u32>. Unit is millisecond.
+ 0 ~ 65 msec = LM3532
+ 0 ~ 4000 msec = LM3631
+ 0 ~ 16000 msec = LM3633 and LM3697
+ - pwm-period: PWM period. Only valid in PWM brightness mode.
+ Type is <u32>. If this property is missing, then control
+ mode is set to I2C by default.
+
+Examples: Please refer to ti-lmu dt-bindings. [2].
+
+[1] Documentation/devicetree/bindings/pwm/pwm.txt
+[2] Documentation/devicetree/bindings/mfd/ti-lmu.txt
+[3] LM3532: http://www.ti.com/product/LM3532/datasheet
+ LM3631: http://www.ti.com/product/LM3631/datasheet
+ LM3632: http://www.ti.com/product/LM3632A/datasheet
+ LM3633: http://www.ti.com/product/LM3633/datasheet
+ LM3695: Datasheet is not opened yet, but only two strings are used.
+ LM3697: http://www.ti.com/product/LM3697/datasheet
--
1.9.1

2015-11-02 05:26:23

by Kim, Milo

[permalink] [raw]
Subject: [PATCH RESEND 03/16] Documentation: dt-bindings: hwmon: add TI LMU HWMON binding information

Hardware fault monitoring driver is used in LM3633 and LM3697 device.
Just 'compatible' property is required to describe the driver.

Cc: [email protected]
Cc: Guenter Roeck <[email protected]>
Cc: Jean Delvare <[email protected]>
Cc: Lee Jones <[email protected]>
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Milo Kim <[email protected]>
---
Documentation/devicetree/bindings/hwmon/ti-lmu-hwmon.txt | 12 ++++++++++++
1 file changed, 12 insertions(+)
create mode 100644 Documentation/devicetree/bindings/hwmon/ti-lmu-hwmon.txt

diff --git a/Documentation/devicetree/bindings/hwmon/ti-lmu-hwmon.txt b/Documentation/devicetree/bindings/hwmon/ti-lmu-hwmon.txt
new file mode 100644
index 0000000..99cb241
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/ti-lmu-hwmon.txt
@@ -0,0 +1,12 @@
+TI LMU Hardware Monotoring device tree bindings
+
+LMU HWON driver monitors hardware fault situation of LMU devices,
+LM3633 and LM3697.
+
+Required properties:
+ - compatible: Should be one of lists below.
+ "ti,lm3633-hwmon"
+ "ti,lm3697-hwmon"
+
+Examples: Please refer to ti-lmu dt-bindings.
+ Documentation/devicetree/bindings/mfd/ti-lmu.txt
--
1.9.1

2015-11-02 05:25:44

by Kim, Milo

[permalink] [raw]
Subject: [PATCH RESEND 04/16] Documentation: dt-bindings: leds: add LM3633 LED binding information

LM3633 LED device is one of TI LMU device list.

Cc: [email protected]
Cc: Jacek Anaszewski <[email protected]>
Cc: Lee Jones <[email protected]>
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Milo Kim <[email protected]>
---
.../devicetree/bindings/leds/leds-lm3633.txt | 28 ++++++++++++++++++++++
1 file changed, 28 insertions(+)
create mode 100644 Documentation/devicetree/bindings/leds/leds-lm3633.txt

diff --git a/Documentation/devicetree/bindings/leds/leds-lm3633.txt b/Documentation/devicetree/bindings/leds/leds-lm3633.txt
new file mode 100644
index 0000000..bb7f213
--- /dev/null
+++ b/Documentation/devicetree/bindings/leds/leds-lm3633.txt
@@ -0,0 +1,28 @@
+TI LMU LM3633 LED device tree bindings
+
+Required properties:
+ - compatible: "ti,lm3633-leds"
+
+Child nodes:
+ Each node matches with LED control bank.
+ Please refer to the datasheet [1].
+
+ Required properties of a child node:
+ - lvled1-used, lvled2-used, lvled3-used,
+ lvled4-used, lvled5-used, lvled6-used:
+ Low voltage LED string configuration. Type is <boolean>.
+ Please describe which output LED string is used.
+
+ Optional properties of a child node:
+ - channel-name: Name string for LED channel identification
+ It is used for creating LED sysfs,
+ /sys/class/leds/<channel-name>/.
+ If this property is empty, then default name is set to
+ "indicator:<id>" by the driver.
+ - led-max-microamp: Max current setting. Type is <u32>.
+ Unit is microampere. Range is from 5000 to 30000.
+
+Examples: Please refer to ti-lmu dt-bindings [2].
+
+[1] http://www.ti.com/product/LM3633/datasheet
+[2] Documentation/devicetree/bindings/mfd/ti-lmu.txt
--
1.9.1

2015-11-02 05:25:48

by Kim, Milo

[permalink] [raw]
Subject: [PATCH RESEND 05/16] Documentation: dt-bindings: regulator: add LM363x regulator binding information

This binding supports LM3631 and LM3632 regulator configuration.

Cc: [email protected]
Cc: Lee Jones <[email protected]>
Cc: Mark Brown <[email protected]>
Cc: [email protected]
Signed-off-by: Milo Kim <[email protected]>
---
.../bindings/regulator/lm363x-regulator.txt | 28 ++++++++++++++++++++++
1 file changed, 28 insertions(+)
create mode 100644 Documentation/devicetree/bindings/regulator/lm363x-regulator.txt

diff --git a/Documentation/devicetree/bindings/regulator/lm363x-regulator.txt b/Documentation/devicetree/bindings/regulator/lm363x-regulator.txt
new file mode 100644
index 0000000..597716f
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/lm363x-regulator.txt
@@ -0,0 +1,28 @@
+TI LMU LM363x regulator device tree bindings
+
+LM363x regulator driver supports LM3631 and LM3632.
+LM3631 has five regulators and LM3632 supports three regulators.
+
+Required properties:
+ - compatible: "ti,lm363x-regulator"
+
+Child nodes:
+ LM3631
+ - vboost
+ - vcont
+ - voref
+ - vpos
+ - vneg
+
+ LM3632
+ - vboost
+ - vpos
+ - vneg
+
+ Optional properties of each node:
+ Please refer to [1].
+
+Examples: Please refer to ti-lmu dt-bindings [2].
+
+[1] Documentation/devicetree/bindings/regulator/regulator.txt
+[2] Documentation/devicetree/bindings/mfd/ti-lmu.txt
--
1.9.1

2015-11-02 05:26:32

by Kim, Milo

[permalink] [raw]
Subject: [PATCH RESEND 06/16] mfd: add TI LMU driver

TI LMU(Lighting Management Unit) driver supports lighting devices below.

LM3532, LM3631, LM3632, LM3633, LM3695 and LM3697.

LMU devices have common features.
- I2C interface for accessing device registers
- Hardware enable pin control
- Backlight brightness control
- Max current conversion helper function
- Notifier for hardware fault monitoring
- Regulators for LCD display bias

It contains backlight, HWMON, LED and regulator driver.

Backlight
---------
It's handled by TI LMU backlight common driver and chip dependent driver.
Please refer to separate patches for ti-lmu-backlight.

HWMON
-----
LM3633 and LM3697 provide hardware monitoring feature.
It enables opened or shorted circuit detection.
After monitoring is done, each device should be re-initialized.
Notifier is used for this case.
Please refer to separate patch for ti-lmu-hwmon.

LED indicator
-------------
LM3633 has 6 indicator LEDs. Programmable pattern is also supported.
Please refer to separate patch for leds-lm3633.

Regulator
---------
LM3631 has 5 regulators for the display bias.
LM3632 supports 3 regulators. One consolidated driver enables it.
Please refer to separate patch for lm363x-regulator.

Cc: Lee Jones <[email protected]>
Cc: Jingoo Han <[email protected]>
Cc: Guenter Roeck <[email protected]>
Cc: Jean Delvare <[email protected]>
Cc: Jacek Anaszewski <[email protected]>
Cc: Mark Brown <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Milo Kim <[email protected]>
---
drivers/mfd/Kconfig | 12 ++
drivers/mfd/Makefile | 1 +
drivers/mfd/ti-lmu.c | 324 ++++++++++++++++++++++++++++++++++++
include/linux/mfd/ti-lmu-register.h | 277 ++++++++++++++++++++++++++++++
include/linux/mfd/ti-lmu.h | 81 +++++++++
5 files changed, 695 insertions(+)
create mode 100644 drivers/mfd/ti-lmu.c
create mode 100644 include/linux/mfd/ti-lmu-register.h
create mode 100644 include/linux/mfd/ti-lmu.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 99d6367..a53a38e 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -1037,6 +1037,18 @@ config MFD_LP8788
TI LP8788 PMU supports regulators, battery charger, RTC,
ADC, backlight driver and current sinks.

+config MFD_TI_LMU
+ tristate "TI Lighting Management Unit driver"
+ depends on I2C
+ select MFD_CORE
+ select REGMAP_I2C
+ help
+ Say yes here to enable support for TI LMU chips.
+
+ TI LMU MFD supports LM3532, LM3631, LM3632, LM3633, LM3695 and LM3697.
+ It consists of backlight, hwmon, LED and regulator driver.
+ It provides consistent device controls for lighting functions.
+
config MFD_OMAP_USB_HOST
bool "TI OMAP USBHS core and TLL driver"
depends on USB_EHCI_HCD_OMAP || USB_OHCI_HCD_OMAP3
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index a59e3fc..32920f8 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -110,6 +110,7 @@ obj-$(CONFIG_MFD_AXP20X) += axp20x.o

obj-$(CONFIG_MFD_LP3943) += lp3943.o
obj-$(CONFIG_MFD_LP8788) += lp8788.o lp8788-irq.o
+obj-$(CONFIG_MFD_TI_LMU) += ti-lmu.o

da9055-objs := da9055-core.o da9055-i2c.o
obj-$(CONFIG_MFD_DA9055) += da9055.o
diff --git a/drivers/mfd/ti-lmu.c b/drivers/mfd/ti-lmu.c
new file mode 100644
index 0000000..e86a0ea
--- /dev/null
+++ b/drivers/mfd/ti-lmu.c
@@ -0,0 +1,324 @@
+/*
+ * TI LMU(Lighting Management Unit) Core Driver
+ *
+ * Copyright 2015 Texas Instruments
+ *
+ * Author: Milo Kim <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <linux/gpio.h>
+#include <linux/i2c.h>
+#include <linux/kernel.h>
+#include <linux/mfd/core.h>
+#include <linux/mfd/ti-lmu.h>
+#include <linux/mfd/ti-lmu-register.h>
+#include <linux/module.h>
+#include <linux/notifier.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/of_gpio.h>
+#include <linux/slab.h>
+
+#define LMU_IMAX_OFFSET 6
+
+enum ti_lmu_id {
+ LM3532,
+ LM3631,
+ LM3632,
+ LM3633,
+ LM3695,
+ LM3697,
+};
+
+struct ti_lmu_data {
+ struct mfd_cell *cells;
+ int num_cells;
+ unsigned int max_register;
+};
+
+int ti_lmu_read_byte(struct ti_lmu *lmu, u8 reg, u8 *read)
+{
+ int ret;
+ unsigned int val;
+
+ ret = regmap_read(lmu->regmap, reg, &val);
+ if (ret < 0)
+ return ret;
+
+ *read = (u8)val;
+ return 0;
+}
+EXPORT_SYMBOL_GPL(ti_lmu_read_byte);
+
+int ti_lmu_write_byte(struct ti_lmu *lmu, u8 reg, u8 data)
+{
+ return regmap_write(lmu->regmap, reg, data);
+}
+EXPORT_SYMBOL_GPL(ti_lmu_write_byte);
+
+int ti_lmu_update_bits(struct ti_lmu *lmu, u8 reg, u8 mask, u8 data)
+{
+ return regmap_update_bits(lmu->regmap, reg, mask, data);
+}
+EXPORT_SYMBOL_GPL(ti_lmu_update_bits);
+
+/*
+ * LMU backlight and LED devices use shared max current table.
+ * This function finds appropriate register index and return it.
+ */
+enum ti_lmu_max_current ti_lmu_get_current_code(u32 imax_microamp)
+{
+ u8 imax_milliamp = imax_microamp / 1000;
+
+ const enum ti_lmu_max_current imax_table[] = {
+ LMU_IMAX_6mA, LMU_IMAX_7mA, LMU_IMAX_8mA, LMU_IMAX_9mA,
+ LMU_IMAX_10mA, LMU_IMAX_11mA, LMU_IMAX_12mA, LMU_IMAX_13mA,
+ LMU_IMAX_14mA, LMU_IMAX_15mA, LMU_IMAX_16mA, LMU_IMAX_17mA,
+ LMU_IMAX_18mA, LMU_IMAX_19mA, LMU_IMAX_20mA, LMU_IMAX_21mA,
+ LMU_IMAX_22mA, LMU_IMAX_23mA, LMU_IMAX_24mA, LMU_IMAX_25mA,
+ LMU_IMAX_26mA, LMU_IMAX_27mA, LMU_IMAX_28mA, LMU_IMAX_29mA,
+ };
+
+ /* Valid range is from 5mA to 30mA */
+ if (imax_milliamp <= 5)
+ return LMU_IMAX_5mA;
+
+ if (imax_milliamp >= 30)
+ return LMU_IMAX_30mA;
+
+ return imax_table[imax_milliamp - LMU_IMAX_OFFSET];
+}
+EXPORT_SYMBOL_GPL(ti_lmu_get_current_code);
+
+static int ti_lmu_enable_hw(struct ti_lmu *lmu, enum ti_lmu_id id)
+{
+ int ret;
+
+ if (gpio_is_valid(lmu->en_gpio)) {
+ ret = devm_gpio_request_one(lmu->dev, lmu->en_gpio,
+ GPIOF_OUT_INIT_HIGH, "lmu_hwen");
+ if (ret) {
+ dev_err(lmu->dev, "Can not request enable GPIO: %d\n",
+ ret);
+ return ret;
+ }
+ }
+
+ /* Delay about 1ms after HW enable pin control */
+ usleep_range(1000, 1500);
+
+ /* LM3631 has additional power up sequence - enable LCD_EN bit. */
+ if (id == LM3631) {
+ return ti_lmu_update_bits(lmu, LM3631_REG_DEVCTRL,
+ LM3631_LCD_EN_MASK,
+ LM3631_LCD_EN_MASK);
+ }
+
+ return 0;
+}
+
+static void ti_lmu_disable_hw(struct ti_lmu *lmu)
+{
+ if (gpio_is_valid(lmu->en_gpio))
+ gpio_set_value(lmu->en_gpio, 0);
+}
+
+static struct mfd_cell lm3532_devices[] = {
+ {
+ .name = "lm3532-backlight",
+ .of_compatible = "ti,lm3532-backlight",
+ },
+};
+
+#define LM363X_REGULATOR(_id) \
+{ \
+ .name = "lm363x-regulator", \
+ .id = _id, \
+ .of_compatible = "ti,lm363x-regulator", \
+} \
+
+static struct mfd_cell lm3631_devices[] = {
+ /* 5 regulators */
+ LM363X_REGULATOR(LM3631_BOOST),
+ LM363X_REGULATOR(LM3631_LDO_CONT),
+ LM363X_REGULATOR(LM3631_LDO_OREF),
+ LM363X_REGULATOR(LM3631_LDO_POS),
+ LM363X_REGULATOR(LM3631_LDO_NEG),
+ /* Backlight */
+ {
+ .name = "lm3631-backlight",
+ .of_compatible = "ti,lm3631-backlight",
+ },
+};
+
+static struct mfd_cell lm3632_devices[] = {
+ /* 3 regulators */
+ LM363X_REGULATOR(LM3632_BOOST),
+ LM363X_REGULATOR(LM3632_LDO_POS),
+ LM363X_REGULATOR(LM3632_LDO_NEG),
+ /* Backlight */
+ {
+ .name = "lm3632-backlight",
+ .of_compatible = "ti,lm3632-backlight",
+ },
+};
+
+static struct mfd_cell lm3633_devices[] = {
+ /* Backlight */
+ {
+ .name = "lm3633-backlight",
+ .of_compatible = "ti,lm3633-backlight",
+ },
+ /* LED */
+ {
+ .name = "lm3633-leds",
+ .of_compatible = "ti,lm3633-leds",
+ },
+ /* HWMON for opened/shorted circuit detection */
+ {
+ .name = "ti-lmu-hwmon",
+ .of_compatible = "ti,lm3633-hwmon",
+ },
+};
+
+static struct mfd_cell lm3695_devices[] = {
+ {
+ .name = "lm3695-backlight",
+ .of_compatible = "ti,lm3695-backlight",
+ },
+};
+
+static struct mfd_cell lm3697_devices[] = {
+ /* Backlight */
+ {
+ .name = "lm3697-backlight",
+ .of_compatible = "ti,lm3697-backlight",
+ },
+ /* HWMON for opened/shorted circuit detection */
+ {
+ .name = "ti-lmu-hwmon",
+ .of_compatible = "ti,lm3697-hwmon",
+ },
+};
+
+#define TI_LMU_DATA(chip, max_reg) \
+static const struct ti_lmu_data chip##_data = \
+{ \
+ .cells = chip##_devices, \
+ .num_cells = ARRAY_SIZE(chip##_devices),\
+ .max_register = max_reg, \
+} \
+
+TI_LMU_DATA(lm3532, LM3532_MAX_REG); /* lm3532_data */
+TI_LMU_DATA(lm3631, LM3631_MAX_REG); /* lm3631_data */
+TI_LMU_DATA(lm3632, LM3632_MAX_REG); /* lm3632_data */
+TI_LMU_DATA(lm3633, LM3633_MAX_REG); /* lm3633_data */
+TI_LMU_DATA(lm3695, LM3695_MAX_REG); /* lm3695_data */
+TI_LMU_DATA(lm3697, LM3697_MAX_REG); /* lm3697_data */
+
+static const struct of_device_id ti_lmu_of_match[] = {
+ { .compatible = "ti,lm3532", .data = &lm3532_data },
+ { .compatible = "ti,lm3631", .data = &lm3631_data },
+ { .compatible = "ti,lm3632", .data = &lm3632_data },
+ { .compatible = "ti,lm3633", .data = &lm3633_data },
+ { .compatible = "ti,lm3695", .data = &lm3695_data },
+ { .compatible = "ti,lm3697", .data = &lm3697_data },
+ { }
+};
+MODULE_DEVICE_TABLE(of, ti_lmu_of_match);
+
+static int ti_lmu_probe(struct i2c_client *cl, const struct i2c_device_id *id)
+{
+ struct device *dev = &cl->dev;
+ const struct of_device_id *match;
+ const struct ti_lmu_data *data;
+ struct regmap_config regmap_cfg;
+ struct ti_lmu *lmu;
+ int ret;
+
+ match = of_match_device(ti_lmu_of_match, dev);
+ if (!match)
+ return -ENODEV;
+ /*
+ * Get device specific data from of_match table.
+ * This data is defined by using TI_LMU_DATA() macro.
+ */
+ data = (struct ti_lmu_data *)match->data;
+
+ lmu = devm_kzalloc(dev, sizeof(*lmu), GFP_KERNEL);
+ if (!lmu)
+ return -ENOMEM;
+
+ lmu->dev = &cl->dev;
+
+ /* Setup regmap */
+ memset(&regmap_cfg, 0, sizeof(struct regmap_config));
+ regmap_cfg.reg_bits = 8;
+ regmap_cfg.val_bits = 8;
+ regmap_cfg.name = id->name;
+ regmap_cfg.max_register = data->max_register;
+
+ lmu->regmap = devm_regmap_init_i2c(cl, &regmap_cfg);
+ if (IS_ERR(lmu->regmap))
+ return PTR_ERR(lmu->regmap);
+
+ /* HW enable pin control and additional power up sequence if required */
+ lmu->en_gpio = of_get_named_gpio(dev->of_node, "enable-gpios", 0);
+ ret = ti_lmu_enable_hw(lmu, id->driver_data);
+ if (ret)
+ return ret;
+
+ /*
+ * Fault circuit(opened/shorted) can be detected by ti-lmu-hwmon.
+ * After fault detection is done, some devices should re-initialize
+ * configuration. The notifier enables such kind of handling.
+ */
+ BLOCKING_INIT_NOTIFIER_HEAD(&lmu->notifier);
+
+ i2c_set_clientdata(cl, lmu);
+
+ return mfd_add_devices(lmu->dev, 0, data->cells,
+ data->num_cells, NULL, 0, NULL);
+}
+
+static int ti_lmu_remove(struct i2c_client *cl)
+{
+ struct ti_lmu *lmu = i2c_get_clientdata(cl);
+
+ ti_lmu_disable_hw(lmu);
+ mfd_remove_devices(lmu->dev);
+ return 0;
+}
+
+static const struct i2c_device_id ti_lmu_ids[] = {
+ { "lm3532", LM3532 },
+ { "lm3631", LM3631 },
+ { "lm3632", LM3632 },
+ { "lm3633", LM3633 },
+ { "lm3695", LM3695 },
+ { "lm3697", LM3697 },
+ { }
+};
+MODULE_DEVICE_TABLE(i2c, ti_lmu_ids);
+
+static struct i2c_driver ti_lmu_driver = {
+ .probe = ti_lmu_probe,
+ .remove = ti_lmu_remove,
+ .driver = {
+ .name = "ti-lmu",
+ .of_match_table = ti_lmu_of_match,
+ },
+ .id_table = ti_lmu_ids,
+};
+
+module_i2c_driver(ti_lmu_driver);
+
+MODULE_DESCRIPTION("TI LMU MFD Core Driver");
+MODULE_AUTHOR("Milo Kim");
+MODULE_LICENSE("GPL v2");
diff --git a/include/linux/mfd/ti-lmu-register.h b/include/linux/mfd/ti-lmu-register.h
new file mode 100644
index 0000000..39f5771
--- /dev/null
+++ b/include/linux/mfd/ti-lmu-register.h
@@ -0,0 +1,277 @@
+/*
+ * TI LMU(Lighting Management Unit) Device Register Map
+ *
+ * Copyright 2015 Texas Instruments
+ *
+ * Author: Milo Kim <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __MFD_TI_LMU_REGISTER_H__
+#define __MFD_TI_LMU_REGISTER_H__
+
+#include <linux/mfd/ti-lmu.h>
+
+/* LM3532 */
+#define LM3532_REG_OUTPUT_CFG 0x10
+#define LM3532_ILED1_CFG_MASK 0x03
+#define LM3532_ILED2_CFG_MASK 0x0C
+#define LM3532_ILED3_CFG_MASK 0x30
+#define LM3532_ILED1_CFG_SHIFT 0
+#define LM3532_ILED2_CFG_SHIFT 2
+#define LM3532_ILED3_CFG_SHIFT 4
+
+#define LM3532_REG_RAMPUP 0x12
+#define LM3532_REG_RAMPDN LM3532_REG_RAMPUP
+#define LM3532_RAMPUP_MASK 0x07
+#define LM3532_RAMPUP_SHIFT 0
+#define LM3532_RAMPDN_MASK 0x38
+#define LM3532_RAMPDN_SHIFT 3
+
+#define LM3532_REG_ENABLE 0x1D
+
+#define LM3532_REG_PWM_CFG_BASE 0x13
+#define LM3532_PWM_SEL_A_MASK 0x05 /* zone 0 */
+#define LM3532_PWM_SEL_B_MASK 0x09 /* zone 1 */
+#define LM3532_PWM_SEL_C_MASK 0x11 /* zone 2 */
+#define LM3532_PWM_SEL_A_SHIFT 2
+#define LM3532_PWM_SEL_B_SHIFT 3
+#define LM3532_PWM_SEL_C_SHIFT 4
+
+#define LM3532_REG_ZONE_CFG_A 0x16
+#define LM3532_REG_ZONE_CFG_B 0x18
+#define LM3532_REG_ZONE_CFG_C 0x1A
+#define LM3532_ZONE_CFG_MASK (BIT(2) | BIT(3) | BIT(4))
+#define LM3532_ZONE_CFG_SHIFT 2
+
+#define LM3532_REG_IMAX_A 0x17
+#define LM3532_REG_IMAX_B 0x19
+#define LM3532_REG_IMAX_C 0x1B
+
+#define LM3532_REG_BRT_A 0x70 /* zone 0 */
+#define LM3532_REG_BRT_B 0x76 /* zone 1 */
+#define LM3532_REG_BRT_C 0x7C /* zone 2 */
+
+#define LM3532_MAX_REG 0x7E
+
+/* LM3631 */
+#define LM3631_REG_DEVCTRL 0x00
+#define LM3631_LCD_EN_MASK BIT(1)
+#define LM3631_BL_EN_MASK BIT(0)
+
+#define LM3631_REG_BRT_LSB 0x01
+#define LM3631_BRT_LSB_MASK (BIT(0) | BIT(1) | BIT(2))
+#define LM3631_REG_BRT_MSB 0x02
+#define LM3631_BRT_MSB_SHIFT 3
+
+#define LM3631_REG_BL_CFG 0x06
+#define LM3631_BL_STRING_MASK BIT(3)
+#define LM3631_BL_TWO_STRINGS 0
+#define LM3631_BL_ONE_STRING BIT(3)
+#define LM3631_MAP_MASK BIT(5)
+#define LM3631_EXPONENTIAL_MAP 0
+
+#define LM3631_REG_BRT_MODE 0x08
+#define LM3631_EN_SLOPE_MASK BIT(1)
+#define LM3631_MODE_MASK (BIT(2) | BIT(3))
+#define LM3631_MODE_I2C 0
+#define LM3631_MODE_PWM BIT(2)
+#define LM3631_MODE_COMB1 BIT(3)
+#define LM3631_MODE_COMB2 (BIT(2) | BIT(3))
+
+#define LM3631_REG_SLOPE 0x09
+#define LM3631_SLOPE_MASK 0xF0
+#define LM3631_SLOPE_SHIFT 4
+
+#define LM3631_REG_LDO_CTRL1 0x0A
+#define LM3631_EN_OREF_MASK BIT(0)
+#define LM3631_EN_VNEG_MASK BIT(1)
+#define LM3631_EN_VPOS_MASK BIT(2)
+
+#define LM3631_REG_LDO_CTRL2 0x0B
+#define LM3631_EN_CONT_MASK BIT(0)
+
+#define LM3631_REG_VOUT_CONT 0x0C
+#define LM3631_VOUT_CONT_MASK (BIT(6) | BIT(7))
+
+#define LM3631_REG_VOUT_BOOST 0x0C
+#define LM3631_REG_VOUT_POS 0x0D
+#define LM3631_REG_VOUT_NEG 0x0E
+#define LM3631_REG_VOUT_OREF 0x0F
+#define LM3631_VOUT_MASK 0x3F
+
+#define LM3631_REG_ENTIME_VCONT 0x0B
+#define LM3631_ENTIME_CONT_MASK 0x70
+
+#define LM3631_REG_ENTIME_VOREF 0x0F
+#define LM3631_REG_ENTIME_VPOS 0x10
+#define LM3631_REG_ENTIME_VNEG 0x11
+#define LM3631_ENTIME_MASK 0xF0
+#define LM3631_ENTIME_SHIFT 4
+
+#define LM3631_MAX_REG 0x16
+
+/* LM3632 */
+#define LM3632_REG_CONFIG1 0x02
+#define LM3632_OVP_MASK (BIT(5) | BIT(6) | BIT(7))
+#define LM3632_OVP_25V BIT(6)
+
+#define LM3632_REG_CONFIG2 0x03
+#define LM3632_SWFREQ_MASK BIT(7)
+#define LM3632_SWFREQ_1MHZ BIT(7)
+
+#define LM3632_REG_BRT_LSB 0x04
+#define LM3632_BRT_LSB_MASK (BIT(0) | BIT(1) | BIT(2))
+#define LM3632_REG_BRT_MSB 0x05
+#define LM3632_BRT_MSB_SHIFT 3
+
+#define LM3632_REG_IO_CTRL 0x09
+#define LM3632_PWM_MASK BIT(6)
+#define LM3632_I2C_MODE 0
+#define LM3632_PWM_MODE BIT(6)
+
+#define LM3632_REG_ENABLE 0x0A
+#define LM3632_BL_EN_MASK BIT(0)
+#define LM3632_BL_STRING_MASK (BIT(3) | BIT(4))
+#define LM3632_BL_ONE_STRING BIT(4)
+#define LM3632_BL_TWO_STRINGS BIT(3)
+
+#define LM3632_REG_BIAS_CONFIG 0x0C
+#define LM3632_EXT_EN_MASK BIT(0)
+#define LM3632_EN_VNEG_MASK BIT(1)
+#define LM3632_EN_VPOS_MASK BIT(2)
+
+#define LM3632_REG_VOUT_BOOST 0x0D
+#define LM3632_REG_VOUT_POS 0x0E
+#define LM3632_REG_VOUT_NEG 0x0F
+#define LM3632_VOUT_MASK 0x3F
+
+#define LM3632_MAX_REG 0x10
+
+/* LM3633 */
+#define LM3633_REG_HVLED_OUTPUT_CFG 0x10
+
+#define LM3633_REG_BANK_SEL 0x11
+
+#define LM3633_REG_BL0_RAMPUP 0x12
+#define LM3633_REG_BL0_RAMPDN LM3633_REG_BL0_RAMPUP
+#define LM3633_REG_BL1_RAMPUP 0x13
+#define LM3633_REG_BL1_RAMPDN LM3633_REG_BL1_RAMPUP
+#define LM3633_BL_RAMPUP_MASK 0xF0
+#define LM3633_BL_RAMPUP_SHIFT 4
+#define LM3633_BL_RAMPDN_MASK 0x0F
+#define LM3633_BL_RAMPDN_SHIFT 0
+
+#define LM3633_REG_BL_RAMP_CONF 0x1B
+#define LM3633_BL_RAMP_MASK 0x0F
+#define LM3633_BL_RAMP_EACH 0x05
+
+#define LM3633_REG_PTN0_RAMP 0x1C
+#define LM3633_REG_PTN1_RAMP 0x1D
+#define LM3633_PTN_RAMPUP_MASK 0x70
+#define LM3633_PTN_RAMPUP_SHIFT 4
+#define LM3633_PTN_RAMPDN_MASK 0x07
+#define LM3633_PTN_RAMPDN_SHIFT 0
+
+#define LM3633_REG_IMAX_HVLED_A 0x20
+#define LM3633_REG_IMAX_HVLED_B 0x21
+#define LM3633_REG_IMAX_LVLED_BASE 0x22
+
+#define LM3633_REG_BL_FEEDBACK_ENABLE 0x28
+
+#define LM3633_REG_ENABLE 0x2B
+#define LM3633_LED_BANK_OFFSET 2
+
+#define LM3633_REG_PATTERN 0x2C
+
+#define LM3633_REG_BOOST_CFG 0x2D
+#define LM3633_BOOST_OVP_MASK (BIT(1) | BIT(2))
+#define LM3633_BOOST_OVP_40V 0x6
+
+#define LM3633_REG_PWM_CFG 0x2F
+
+#define LM3633_REG_BRT_HVLED_A_LSB 0x40
+#define LM3633_REG_BRT_HVLED_A_MSB 0x41
+#define LM3633_REG_BRT_HVLED_B_LSB 0x42
+#define LM3633_REG_BRT_HVLED_B_MSB 0x43
+#define LM3633_BRT_HVLED_LSB_MASK (BIT(0) | BIT(1) | BIT(2))
+#define LM3633_BRT_HVLED_MSB_SHIFT 3
+
+#define LM3633_REG_BRT_LVLED_BASE 0x44
+
+#define LM3633_REG_PTN_DELAY 0x50
+
+#define LM3633_REG_PTN_LOWTIME 0x51
+
+#define LM3633_REG_PTN_HIGHTIME 0x52
+
+#define LM3633_REG_PTN_LOWBRT 0x53
+
+#define LM3633_REG_PTN_HIGHBRT LM3633_REG_BRT_LVLED_BASE
+
+#define LM3633_REG_BL_OPEN_FAULT_STATUS 0xB0
+
+#define LM3633_REG_BL_SHORT_FAULT_STATUS 0xB2
+
+#define LM3633_REG_MONITOR_ENABLE 0xB4
+
+#define LM3633_MAX_REG 0xB4
+
+/* LM3695 */
+#define LM3695_REG_GP 0x10
+#define LM3695_BL_STRING_MASK BIT(3)
+#define LM3695_BL_TWO_STRINGS 0
+#define LM3695_BL_ONE_STRING BIT(3)
+#define LM3695_BRT_RW_MASK BIT(2)
+#define LM3695_BL_EN_MASK BIT(0)
+
+#define LM3695_REG_BRT_LSB 0x13
+#define LM3695_BRT_LSB_MASK (BIT(0) | BIT(1) | BIT(2))
+#define LM3695_REG_BRT_MSB 0x14
+#define LM3695_BRT_MSB_SHIFT 3
+
+#define LM3695_MAX_REG 0x14
+
+/* LM3697 */
+#define LM3697_REG_HVLED_OUTPUT_CFG 0x10
+
+#define LM3697_REG_BL0_RAMPUP 0x11
+#define LM3697_REG_BL0_RAMPDN LM3697_REG_BL0_RAMPUP
+#define LM3697_REG_BL1_RAMPUP 0x12
+#define LM3697_REG_BL1_RAMPDN LM3697_REG_BL1_RAMPUP
+#define LM3697_BL_RAMPUP_MASK 0xF0
+#define LM3697_BL_RAMPUP_SHIFT 4
+#define LM3697_BL_RAMPDN_MASK 0x0F
+#define LM3697_BL_RAMPDN_SHIFT 0
+
+#define LM3697_REG_RAMP_CONF 0x14
+#define LM3697_RAMP_MASK 0x0F
+#define LM3697_RAMP_EACH 0x05
+
+#define LM3697_REG_PWM_CFG 0x1C
+
+#define LM3697_REG_IMAX_A 0x17
+#define LM3697_REG_IMAX_B 0x18
+
+#define LM3697_REG_FEEDBACK_ENABLE 0x19
+
+#define LM3697_REG_BRT_A_LSB 0x20
+#define LM3697_REG_BRT_A_MSB 0x21
+#define LM3697_REG_BRT_B_LSB 0x22
+#define LM3697_REG_BRT_B_MSB 0x23
+#define LM3697_BRT_LSB_MASK (BIT(0) | BIT(1) | BIT(2))
+#define LM3697_BRT_MSB_SHIFT 3
+
+#define LM3697_REG_ENABLE 0x24
+
+#define LM3697_REG_OPEN_FAULT_STATUS 0xB0
+
+#define LM3697_REG_SHORT_FAULT_STATUS 0xB2
+
+#define LM3697_REG_MONITOR_ENABLE 0xB4
+
+#define LM3697_MAX_REG 0xB4
+#endif
diff --git a/include/linux/mfd/ti-lmu.h b/include/linux/mfd/ti-lmu.h
new file mode 100644
index 0000000..eeb6b9e
--- /dev/null
+++ b/include/linux/mfd/ti-lmu.h
@@ -0,0 +1,81 @@
+/*
+ * TI LMU(Lighting Management Unit) Devices
+ *
+ * Copyright 2015 Texas Instruments
+ *
+ * Author: Milo Kim <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __MFD_TI_LMU_H__
+#define __MFD_TI_LMU_H__
+
+#include <linux/gpio.h>
+#include <linux/regmap.h>
+
+/* Notifier event */
+#define LMU_EVENT_HWMON_DONE 0x01
+
+enum ti_lmu_max_current {
+ LMU_IMAX_5mA,
+ LMU_IMAX_6mA,
+ LMU_IMAX_7mA = 0x03,
+ LMU_IMAX_8mA,
+ LMU_IMAX_9mA,
+ LMU_IMAX_10mA = 0x07,
+ LMU_IMAX_11mA,
+ LMU_IMAX_12mA,
+ LMU_IMAX_13mA,
+ LMU_IMAX_14mA,
+ LMU_IMAX_15mA = 0x0D,
+ LMU_IMAX_16mA,
+ LMU_IMAX_17mA,
+ LMU_IMAX_18mA,
+ LMU_IMAX_19mA,
+ LMU_IMAX_20mA = 0x13,
+ LMU_IMAX_21mA,
+ LMU_IMAX_22mA,
+ LMU_IMAX_23mA = 0x17,
+ LMU_IMAX_24mA,
+ LMU_IMAX_25mA,
+ LMU_IMAX_26mA,
+ LMU_IMAX_27mA = 0x1C,
+ LMU_IMAX_28mA,
+ LMU_IMAX_29mA,
+ LMU_IMAX_30mA,
+};
+
+enum lm363x_regulator_id {
+ LM3631_BOOST, /* Boost output */
+ LM3631_LDO_CONT, /* Display panel controller */
+ LM3631_LDO_OREF, /* Gamma reference */
+ LM3631_LDO_POS, /* Positive display bias output */
+ LM3631_LDO_NEG, /* Negative display bias output */
+ LM3632_BOOST, /* Boost output */
+ LM3632_LDO_POS, /* Positive display bias output */
+ LM3632_LDO_NEG, /* Negative display bias output */
+};
+
+/**
+ * struct ti_lmu
+ *
+ * @dev: Parent device pointer
+ * @regmap: Used for i2c communcation on accessing registers
+ * @en_gpio: GPIO for HWEN pin [Optional]
+ * @notifier: Notifier for reporting hwmon event
+ */
+struct ti_lmu {
+ struct device *dev;
+ struct regmap *regmap;
+ int en_gpio;
+ struct blocking_notifier_head notifier;
+};
+
+int ti_lmu_read_byte(struct ti_lmu *lmu, u8 reg, u8 *read);
+int ti_lmu_write_byte(struct ti_lmu *lmu, u8 reg, u8 data);
+int ti_lmu_update_bits(struct ti_lmu *lmu, u8 reg, u8 mask, u8 data);
+enum ti_lmu_max_current ti_lmu_get_current_code(u32 imax_microamp);
+#endif
--
1.9.1

2015-11-02 05:25:52

by Kim, Milo

[permalink] [raw]
Subject: [PATCH RESEND 07/16] backlight: add TI LMU backlight common driver

TI LMU backlight driver provides common driver features.
Chip specific configuration is handled by each backlight driver such like
LM3532, LM3631, LM3632, LM3633, LM3695 and LM3697.

It supports common features as below.
- Backlight subsystem control
- Consistent device control flow
- Control bank assignment
- HWMON notifier handling
- PWM brightness control
- Shared device tree node

Operation
---------
Each LMU backlight driver uses two macros for device registration.
TI_LMU_BL_OF_DEVICE() and TI_LMU_BL_PLATFORM_DRIVER().

(Common driver code) (Chip dependent code)

Define device operations, 'ti_lmu_bl_ops'
: init, configure, update brightness,
enable, max brightness, light effect
and LMU HWMON event option

_probe()
register backlight
parsing the device tree
create data from the DT
init -> init()
configure -> configure()
add backlight device

Helper
convert ramp time value to
register index

Update brightness
pwm mode
I2C mode -> enable(), update_brightness()

LMU HWMON event handling -> check 'hwmon_notifier_used'
reinitialize device -> init(), configure()

_remove()
unregister notifier if used
turn off the backlight

Data structure
--------------
ti_lmu_bl_ops: Configure device specific operation and option.
ti_lmu_bl_chip: Backlight device data.
ti_lmu_bl: Backlight output channel data.
One backlight device can have multiple backlight
channels.

Cc: Jingoo Han <[email protected]>
Cc: Lee Jones <[email protected]>
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Milo Kim <[email protected]>
---
drivers/video/backlight/Kconfig | 9 +
drivers/video/backlight/Makefile | 1 +
drivers/video/backlight/ti-lmu-backlight.c | 429 +++++++++++++++++++++++++++++
drivers/video/backlight/ti-lmu-backlight.h | 152 ++++++++++
4 files changed, 591 insertions(+)
create mode 100644 drivers/video/backlight/ti-lmu-backlight.c
create mode 100644 drivers/video/backlight/ti-lmu-backlight.h

diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
index 5ffa4b4..f26eb1c 100644
--- a/drivers/video/backlight/Kconfig
+++ b/drivers/video/backlight/Kconfig
@@ -390,6 +390,15 @@ config BACKLIGHT_LM3639
help
This supports TI LM3639 Backlight + 1.5A Flash LED Driver

+config TI_LMU_BACKLIGHT
+ tristate "Backlight driver for TI LMU"
+ depends on BACKLIGHT_LM3532 || BACKLIGHT_LM3631 || \
+ BACKLIGHT_LM3632 || BACKLIGHT_LM3633 || \
+ BACKLIGHT_LM3695 || BACKLIGHT_LM3697
+ help
+ TI LMU backlight driver provides common driver features.
+ Chip specific configuration is handled by each backlight driver.
+
config BACKLIGHT_LP855X
tristate "Backlight driver for TI LP855X"
depends on BACKLIGHT_CLASS_DEVICE && I2C && PWM
diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile
index 16ec534..9e475dc 100644
--- a/drivers/video/backlight/Makefile
+++ b/drivers/video/backlight/Makefile
@@ -55,3 +55,4 @@ obj-$(CONFIG_BACKLIGHT_SKY81452) += sky81452-backlight.o
obj-$(CONFIG_BACKLIGHT_TOSA) += tosa_bl.o
obj-$(CONFIG_BACKLIGHT_TPS65217) += tps65217_bl.o
obj-$(CONFIG_BACKLIGHT_WM831X) += wm831x_bl.o
+obj-$(CONFIG_TI_LMU_BACKLIGHT) += ti-lmu-backlight.o
diff --git a/drivers/video/backlight/ti-lmu-backlight.c b/drivers/video/backlight/ti-lmu-backlight.c
new file mode 100644
index 0000000..ca59c07
--- /dev/null
+++ b/drivers/video/backlight/ti-lmu-backlight.c
@@ -0,0 +1,429 @@
+/*
+ * TI LMU(Lighting Management Unit) Backlight Common Driver
+ *
+ * Copyright 2015 Texas Instruments
+ *
+ * Author: Milo Kim <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/backlight.h>
+#include <linux/err.h>
+#include <linux/kernel.h>
+#include <linux/mfd/ti-lmu.h>
+#include <linux/module.h>
+#include <linux/notifier.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+#include <linux/pwm.h>
+#include <linux/slab.h>
+
+#include "ti-lmu-backlight.h"
+
+#define DEFAULT_BL_NAME "lcd-backlight"
+#define DEFAULT_PWM_NAME "lmu-backlight"
+
+static int ti_lmu_backlight_enable(struct ti_lmu_bl *lmu_bl, int enable)
+{
+ const struct ti_lmu_bl_ops *ops = lmu_bl->chip->ops;
+
+ if (ops->bl_enable)
+ return ops->bl_enable(lmu_bl, enable);
+
+ return 0;
+}
+
+static void ti_lmu_backlight_pwm_ctrl(struct ti_lmu_bl *lmu_bl, int br,
+ int max_br)
+{
+ struct pwm_device *pwm;
+ unsigned int duty, period;
+
+ /* Request a PWM device with the consumer name */
+ if (!lmu_bl->pwm) {
+ pwm = devm_pwm_get(lmu_bl->chip->dev, DEFAULT_PWM_NAME);
+ if (IS_ERR(pwm)) {
+ dev_err(lmu_bl->chip->dev,
+ "Can not get PWM device, err: %ld\n",
+ PTR_ERR(pwm));
+ return;
+ }
+
+ lmu_bl->pwm = pwm;
+ }
+
+ period = lmu_bl->pwm_period;
+ duty = br * period / max_br;
+
+ pwm_config(lmu_bl->pwm, duty, period);
+ if (duty)
+ pwm_enable(lmu_bl->pwm);
+ else
+ pwm_disable(lmu_bl->pwm);
+}
+
+static int ti_lmu_backlight_update_status(struct backlight_device *bl_dev)
+{
+ struct ti_lmu_bl *lmu_bl = bl_get_data(bl_dev);
+ const struct ti_lmu_bl_ops *ops = lmu_bl->chip->ops;
+ int brightness = bl_dev->props.brightness;
+ int ret;
+
+ if (bl_dev->props.state & BL_CORE_SUSPENDED)
+ brightness = 0;
+
+ if (brightness > 0)
+ ret = ti_lmu_backlight_enable(lmu_bl, 1);
+ else
+ ret = ti_lmu_backlight_enable(lmu_bl, 0);
+ if (ret)
+ return ret;
+
+ if (lmu_bl->mode == BL_PWM_BASED)
+ ti_lmu_backlight_pwm_ctrl(lmu_bl, brightness,
+ bl_dev->props.max_brightness);
+
+ /*
+ * In some devices, additional handling is required after PWM control.
+ * So, just call device-specific brightness function.
+ */
+ if (ops->update_brightness)
+ return ops->update_brightness(lmu_bl, brightness);
+
+ return 0;
+}
+
+static const struct backlight_ops lmu_bl_common_ops = {
+ .options = BL_CORE_SUSPENDRESUME,
+ .update_status = ti_lmu_backlight_update_status,
+};
+
+static int ti_lmu_backlight_of_create(struct ti_lmu_bl_chip *chip,
+ struct device_node *np)
+{
+ struct device_node *child;
+ struct ti_lmu_bl *lmu_bl, *each;
+ int num_backlights;
+ int i = 0;
+ u32 imax;
+
+ num_backlights = of_get_child_count(np);
+ if (num_backlights == 0) {
+ dev_err(chip->dev, "No backlight strings\n");
+ return -EINVAL;
+ }
+
+ /* One chip can have mulitple backlight strings */
+ lmu_bl = devm_kzalloc(chip->dev, sizeof(*lmu_bl) * num_backlights,
+ GFP_KERNEL);
+ if (!lmu_bl)
+ return -ENOMEM;
+
+ for_each_child_of_node(np, child) {
+ each = lmu_bl + i;
+ each->bank_id = i;
+ each->chip = chip;
+
+ of_property_read_string(child, "backlight-name",
+ &each->name);
+
+ /* Backlight string configuration */
+ each->bl_string = 0;
+ if (of_property_read_bool(child, "hvled1-used"))
+ each->bl_string |= LMU_HVLED1;
+ if (of_property_read_bool(child, "hvled2-used"))
+ each->bl_string |= LMU_HVLED2;
+ if (of_property_read_bool(child, "hvled3-used"))
+ each->bl_string |= LMU_HVLED3;
+
+ imax = 0;
+ of_property_read_u32(child, "backlight-max-microamp", &imax);
+ each->imax = ti_lmu_get_current_code(imax);
+
+ of_property_read_u32(child, "initial-brightness",
+ &each->init_brightness);
+
+ /* Lighting effect properties */
+ of_property_read_u32(child, "ramp-up-msec",
+ &each->ramp_up_msec);
+ of_property_read_u32(child, "ramp-down-msec",
+ &each->ramp_down_msec);
+
+ /* PWM mode */
+ of_property_read_u32(child, "pwm-period", &each->pwm_period);
+ if (each->pwm_period > 0)
+ each->mode = BL_PWM_BASED;
+ else
+ each->mode = BL_REGISTER_BASED;
+
+ each->chip = chip;
+ i++;
+ }
+
+ chip->lmu_bl = lmu_bl;
+ chip->num_backlights = num_backlights;
+
+ return 0;
+}
+
+static int ti_lmu_backlight_configure(struct ti_lmu_bl *lmu_bl)
+{
+ const struct ti_lmu_bl_ops *ops = lmu_bl->chip->ops;
+
+ if (ops->configure)
+ return ops->configure(lmu_bl);
+
+ return 0;
+}
+
+static int ti_lmu_backlight_reload(struct ti_lmu_bl_chip *chip)
+{
+ struct ti_lmu_bl *each;
+ int i, ret;
+
+ if (chip->ops->init) {
+ ret = chip->ops->init(chip);
+ if (ret)
+ return ret;
+ }
+
+ for (i = 0; i < chip->num_backlights; i++) {
+ each = chip->lmu_bl + i;
+ ret = ti_lmu_backlight_configure(each);
+ if (ret)
+ return ret;
+
+ backlight_update_status(each->bl_dev);
+ }
+
+ return 0;
+}
+
+static int ti_lmu_backlight_hwmon_notifier(struct notifier_block *nb,
+ unsigned long action, void *unused)
+{
+ struct ti_lmu_bl_chip *chip = container_of(nb, struct ti_lmu_bl_chip,
+ nb);
+ int ret;
+
+ /*
+ * LMU HWMON driver reset the device, so backlight should be
+ * re-initialized after hwmon detection procedure is done.
+ */
+ if (action == LMU_EVENT_HWMON_DONE) {
+ ret = ti_lmu_backlight_reload(chip);
+ if (ret)
+ return NOTIFY_STOP;
+ }
+
+ return NOTIFY_OK;
+}
+
+static int ti_lmu_backlight_init(struct ti_lmu_bl_chip *chip,
+ struct device_node *np)
+{
+ int ret;
+
+ ret = ti_lmu_backlight_of_create(chip, np);
+ if (ret)
+ return ret;
+
+ if (chip->ops->init) {
+ ret = chip->ops->init(chip);
+ if (ret)
+ return ret;
+ }
+
+ /* Register notifier for LMU HWMON event */
+ if (chip->ops->hwmon_notifier_used) {
+ chip->nb.notifier_call = ti_lmu_backlight_hwmon_notifier;
+ ret = blocking_notifier_chain_register(&chip->lmu->notifier,
+ &chip->nb);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
+static int ti_lmu_backlight_add_device(struct device *dev,
+ struct ti_lmu_bl *lmu_bl)
+{
+ struct backlight_device *bl_dev;
+ struct backlight_properties props;
+ int max_brightness = lmu_bl->chip->ops->max_brightness;
+ char name[20];
+
+ memset(&props, 0, sizeof(struct backlight_properties));
+ props.type = BACKLIGHT_PLATFORM;
+ props.brightness = lmu_bl->init_brightness;
+ props.max_brightness = max_brightness;
+
+ /* Backlight device name */
+ if (!lmu_bl->name)
+ snprintf(name, sizeof(name), "%s:%d", DEFAULT_BL_NAME,
+ lmu_bl->bank_id);
+ else
+ snprintf(name, sizeof(name), "%s", lmu_bl->name);
+
+ bl_dev = devm_backlight_device_register(dev, name, lmu_bl->chip->dev,
+ lmu_bl, &lmu_bl_common_ops,
+ &props);
+ if (IS_ERR(bl_dev))
+ return PTR_ERR(bl_dev);
+
+ lmu_bl->bl_dev = bl_dev;
+
+ return 0;
+}
+
+static struct ti_lmu_bl_chip *
+ti_lmu_backlight_register(struct device *dev, struct ti_lmu *lmu,
+ const struct ti_lmu_bl_ops *ops)
+{
+ struct device_node *np = dev->of_node;
+ struct ti_lmu_bl_chip *chip;
+ struct ti_lmu_bl *each;
+ int i, ret;
+
+ if (!ops) {
+ dev_err(dev, "Operation is not configured\n");
+ return ERR_PTR(-EINVAL);
+ }
+
+ chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
+ if (!chip)
+ return ERR_PTR(-ENOMEM);
+
+ chip->dev = dev;
+ chip->lmu = lmu;
+ chip->ops = ops;
+
+ ret = ti_lmu_backlight_init(chip, np);
+ if (ret) {
+ dev_err(dev, "Backlight init err: %d\n", ret);
+ return ERR_PTR(ret);
+ }
+
+ /* Add backlight strings */
+ for (i = 0; i < chip->num_backlights; i++) {
+ each = chip->lmu_bl + i;
+
+ ret = ti_lmu_backlight_configure(each);
+ if (ret) {
+ dev_err(dev, "Backlight config err: %d\n", ret);
+ return ERR_PTR(ret);
+ }
+
+ ret = ti_lmu_backlight_add_device(dev, each);
+ if (ret) {
+ dev_err(dev, "Backlight device err: %d\n", ret);
+ return ERR_PTR(ret);
+ }
+
+ backlight_update_status(each->bl_dev);
+ }
+
+ return chip;
+}
+
+static void ti_lmu_backlight_unregister(struct ti_lmu_bl_chip *chip)
+{
+ struct ti_lmu_bl *each;
+ int i;
+
+ for (i = 0; i < chip->num_backlights; i++) {
+ each = chip->lmu_bl + i;
+ each->bl_dev->props.brightness = 0;
+ backlight_update_status(each->bl_dev);
+ }
+}
+
+/* Common probe() function for LMU backlight drivers */
+int ti_lmu_backlight_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct ti_lmu *lmu = dev_get_drvdata(dev->parent);
+ struct ti_lmu_bl_chip *chip;
+ const struct of_device_id *match;
+ const struct ti_lmu_bl_ops *ops;
+
+ match = of_match_device(dev->driver->of_match_table, dev);
+ if (!match) {
+ dev_err(dev, "No matched device is found\n");
+ return -ENODEV;
+ }
+
+ /*
+ * Get device specific data(ti_lmu_bl_ops) from of_match table.
+ * This data is defined by TI_LMU_BL_OF_DEVICE() of each device.
+ */
+ ops = (struct ti_lmu_bl_ops *)match->data;
+ chip = ti_lmu_backlight_register(&pdev->dev, lmu, ops);
+ if (IS_ERR(chip))
+ return PTR_ERR(chip);
+
+ platform_set_drvdata(pdev, chip);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(ti_lmu_backlight_probe);
+
+/* Common remove() function for LMU backlight drivers */
+int ti_lmu_backlight_remove(struct platform_device *pdev)
+{
+ struct ti_lmu_bl_chip *chip = platform_get_drvdata(pdev);
+
+ if (chip->ops->hwmon_notifier_used)
+ blocking_notifier_chain_unregister(&chip->lmu->notifier,
+ &chip->nb);
+
+ ti_lmu_backlight_unregister(chip);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(ti_lmu_backlight_remove);
+
+/*
+ * Convert ramp up/down time into register index value.
+ * Get appropriate index by comparing ramp time table.
+ */
+int ti_lmu_backlight_get_ramp_index(struct ti_lmu_bl *lmu_bl,
+ enum ti_lmu_bl_ramp_mode mode)
+{
+ const int *table = lmu_bl->chip->ops->ramp_table;
+ const int size = lmu_bl->chip->ops->size_ramp;
+ unsigned int ramp_time;
+ int i;
+
+ if (!table)
+ return -EINVAL;
+
+ if (mode == BL_RAMP_UP)
+ ramp_time = lmu_bl->ramp_up_msec;
+ else if (mode == BL_RAMP_DOWN)
+ ramp_time = lmu_bl->ramp_down_msec;
+ else
+ return -EINVAL;
+
+ if (ramp_time <= table[0])
+ return 0;
+
+ if (ramp_time >= table[size - 1])
+ return size - 1;
+
+ for (i = 1; i < size; i++)
+ if (ramp_time >= table[i - 1] && ramp_time < table[i])
+ return i - 1;
+
+ return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(ti_lmu_backlight_get_ramp_index);
+
+MODULE_DESCRIPTION("TI LMU Backlight Common Driver");
+MODULE_AUTHOR("Milo Kim");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/video/backlight/ti-lmu-backlight.h b/drivers/video/backlight/ti-lmu-backlight.h
new file mode 100644
index 0000000..f3f3784
--- /dev/null
+++ b/drivers/video/backlight/ti-lmu-backlight.h
@@ -0,0 +1,152 @@
+/*
+ * TI LMU(Lighting Management Unit) Backlight Common Driver
+ *
+ * Copyright 2015 Texas Instruments
+ *
+ * Author: Milo Kim <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __TI_LMU_BACKLIGHT_H__
+#define __TI_LMU_BACKLIGHT_H__
+
+#include <linux/mfd/ti-lmu.h>
+#include <linux/notifier.h>
+#include <linux/platform_device.h>
+
+/* Macro for LMU backlight of_device_id */
+#define TI_LMU_BL_OF_DEVICE(chip, compat) \
+static const struct of_device_id chip##_bl_of_match[] = { \
+ { .compatible = compat, .data = &chip##_lmu_ops }, \
+ { } \
+}; \
+MODULE_DEVICE_TABLE(of, chip##_bl_of_match) \
+
+/* Macro for LMU backlight platform driver */
+#define TI_LMU_BL_PLATFORM_DRIVER(chip, _name) \
+static struct platform_driver chip##_bl_driver = { \
+ .probe = ti_lmu_backlight_probe, \
+ .remove = ti_lmu_backlight_remove, \
+ .driver = { \
+ .name = _name, \
+ .of_match_table = chip##_bl_of_match, \
+ }, \
+}; \
+ \
+module_platform_driver(chip##_bl_driver)
+
+enum ti_lmu_bl_ctrl_mode {
+ BL_REGISTER_BASED,
+ BL_PWM_BASED,
+};
+
+enum ti_lmu_bl_ramp_mode {
+ BL_RAMP_UP,
+ BL_RAMP_DOWN,
+};
+
+struct ti_lmu_bl;
+struct ti_lmu_bl_chip;
+
+/**
+ * struct ti_lmu_bl_ops
+ *
+ * @init: Device initialization function
+ * @configure: Device string configuration function
+ * @update_brightness: Device brightness control function
+ * @bl_enable: Device backlight enable/disable control function
+ * @hwmon_notifier_used:Set true if the device needs to handle LMU HWMON event
+ * @max_brightness: Max brightness value of backlight device
+ * @ramp_table: Ramp time table for lighting effect.
+ * It's used for searching appropriate register index.
+ * Please refer to ti_lmu_backlight_get_ramp_index().
+ * @size_ramp: Size of ramp table
+ *
+ * TI LMU backlight device should call ti_lmu_backlight_register() with
+ * each device operation.
+ */
+struct ti_lmu_bl_ops {
+ int (*init)(struct ti_lmu_bl_chip *lmu_chip);
+ int (*configure)(struct ti_lmu_bl *lmu_bl);
+ int (*update_brightness)(struct ti_lmu_bl *lmu_bl, int brightness);
+ int (*bl_enable)(struct ti_lmu_bl *lmu_bl, int enable);
+ bool hwmon_notifier_used;
+ const int max_brightness;
+ const int *ramp_table;
+ const int size_ramp;
+};
+
+/**
+ * struct ti_lmu_bl_chip
+ *
+ * @dev: Parent device pointer
+ * @lmu: LMU structure. Used for register R/W access.
+ * @ops: Device specific operation
+ * @lmu_bl: Multiple backlight strings
+ * @num_backlights: Number of backlight strings
+ * @nb: Notifier block for handling hwmon event
+ *
+ * One backlight chip can have multiple backlight strings, 'ti_lmu_bl'.
+ */
+struct ti_lmu_bl_chip {
+ struct device *dev;
+ struct ti_lmu *lmu;
+ const struct ti_lmu_bl_ops *ops;
+ struct ti_lmu_bl *lmu_bl;
+ int num_backlights;
+ struct notifier_block nb;
+};
+
+/**
+ * struct ti_lmu_bl
+ *
+ * @chip: Pointer to parent backlight device
+ * @bl_dev: Backlight subsystem device structure
+ * @bank_id: Backlight bank ID
+ * @name: Backlight channel name
+ * @mode: Backlight control mode
+ * @bl_string: Backlight string configuration.
+ * Bit mask is set on parsing DT.
+ * @imax: [Optional] Max current index.
+ * It's result of ti_lmu_get_current_code().
+ * @init_brightness: [Optional] Initial brightness value
+ * @ramp_up_msec: [Optional] Ramp up time
+ * @ramp_down_msec: [Optional] Ramp down time
+ * @pwm_period: [Optional] PWM period
+ * @pwm: [Optional] PWM subsystem structure
+ *
+ * Each backlight device has its own channel configuration.
+ * For chip control, parent chip data structure is used.
+ */
+struct ti_lmu_bl {
+ struct ti_lmu_bl_chip *chip;
+ struct backlight_device *bl_dev;
+
+ int bank_id;
+ const char *name;
+ enum ti_lmu_bl_ctrl_mode mode;
+ unsigned long bl_string; /* bit OR mask of LMU_HVLEDx */
+ #define LMU_HVLED1 BIT(0)
+ #define LMU_HVLED2 BIT(1)
+ #define LMU_HVLED3 BIT(2)
+
+ enum ti_lmu_max_current imax;
+ unsigned int init_brightness;
+
+ /* Used for lighting effect */
+ unsigned int ramp_up_msec;
+ unsigned int ramp_down_msec;
+
+ /* Only valid in case of PWM mode */
+ unsigned int pwm_period;
+ struct pwm_device *pwm;
+};
+
+int ti_lmu_backlight_probe(struct platform_device *pdev);
+int ti_lmu_backlight_remove(struct platform_device *pdev);
+int ti_lmu_backlight_get_ramp_index(struct ti_lmu_bl *lmu_bl,
+ enum ti_lmu_bl_ramp_mode mode);
+#endif
--
1.9.1

2015-11-02 05:25:56

by Kim, Milo

[permalink] [raw]
Subject: [PATCH RESEND 08/16] backlight: ti-lmu-backlight: add LM3532 driver

LM3532 has 3 backlight strings and 8 bit dimming is supported.
PWM brightness control is also supported.

Common backlight driver is controlled by TI LMU backlight driver.
Only LM3532 specific code is implemented here.

Cc: Jingoo Han <[email protected]>
Cc: Lee Jones <[email protected]>
Cc: [email protected]
Signed-off-by: Milo Kim <[email protected]>
---
drivers/video/backlight/Kconfig | 9 ++
drivers/video/backlight/Makefile | 1 +
drivers/video/backlight/lm3532_bl.c | 183 ++++++++++++++++++++++++++++++++++++
3 files changed, 193 insertions(+)
create mode 100644 drivers/video/backlight/lm3532_bl.c

diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
index f26eb1c..86d7946 100644
--- a/drivers/video/backlight/Kconfig
+++ b/drivers/video/backlight/Kconfig
@@ -390,6 +390,15 @@ config BACKLIGHT_LM3639
help
This supports TI LM3639 Backlight + 1.5A Flash LED Driver

+config BACKLIGHT_LM3532
+ tristate "Backlight driver for TI LM3532"
+ depends on BACKLIGHT_CLASS_DEVICE && MFD_TI_LMU
+ select TI_LMU_BACKLIGHT
+ help
+ Say Y to enable the backlight driver for TI LM3532.
+ Up to 3 backlight strings and 8 bit dimming is supported.
+ PWM brightness control is also supported.
+
config TI_LMU_BACKLIGHT
tristate "Backlight driver for TI LMU"
depends on BACKLIGHT_LM3532 || BACKLIGHT_LM3631 || \
diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile
index 9e475dc..e037f57 100644
--- a/drivers/video/backlight/Makefile
+++ b/drivers/video/backlight/Makefile
@@ -36,6 +36,7 @@ obj-$(CONFIG_BACKLIGHT_GPIO) += gpio_backlight.o
obj-$(CONFIG_BACKLIGHT_HP680) += hp680_bl.o
obj-$(CONFIG_BACKLIGHT_HP700) += jornada720_bl.o
obj-$(CONFIG_BACKLIGHT_IPAQ_MICRO) += ipaq_micro_bl.o
+obj-$(CONFIG_BACKLIGHT_LM3532) += lm3532_bl.o
obj-$(CONFIG_BACKLIGHT_LM3533) += lm3533_bl.o
obj-$(CONFIG_BACKLIGHT_LM3630A) += lm3630a_bl.o
obj-$(CONFIG_BACKLIGHT_LM3639) += lm3639_bl.o
diff --git a/drivers/video/backlight/lm3532_bl.c b/drivers/video/backlight/lm3532_bl.c
new file mode 100644
index 0000000..fd21a3c
--- /dev/null
+++ b/drivers/video/backlight/lm3532_bl.c
@@ -0,0 +1,183 @@
+/*
+ * TI LM3532 Backlight Driver
+ *
+ * Copyright 2015 Texas Instruments
+ *
+ * Author: Milo Kim <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/kernel.h>
+#include <linux/mfd/ti-lmu.h>
+#include <linux/mfd/ti-lmu-register.h>
+#include <linux/module.h>
+
+#include "ti-lmu-backlight.h"
+
+#define LM3532_PWM1 0
+#define LM3532_BL_MAX_STRINGS 3
+#define LM3532_MAX_ZONE_CFG 3
+#define LM3532_MAX_BRIGHTNESS 255
+
+static int lm3532_bl_init(struct ti_lmu_bl_chip *chip)
+{
+ int i, ret;
+ u8 lm3532_regs[] = { LM3532_REG_ZONE_CFG_A, LM3532_REG_ZONE_CFG_B,
+ LM3532_REG_ZONE_CFG_C, };
+
+ /*
+ * Assign zone targets as below.
+ * Zone target 0 for control A
+ * Zone target 1 for control B
+ * Zone target 2 for control C
+ */
+
+ for (i = 0; i < LM3532_MAX_ZONE_CFG; i++) {
+ ret = ti_lmu_update_bits(chip->lmu, lm3532_regs[i],
+ LM3532_ZONE_CFG_MASK,
+ i << LM3532_ZONE_CFG_SHIFT);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
+static int lm3532_bl_enable(struct ti_lmu_bl *lmu_bl, int enable)
+{
+ return ti_lmu_update_bits(lmu_bl->chip->lmu, LM3532_REG_ENABLE,
+ BIT(lmu_bl->bank_id),
+ enable << lmu_bl->bank_id);
+}
+
+static int lm3532_bl_set_brightness(struct ti_lmu_bl *lmu_bl, int brightness)
+{
+ u8 reg[] = { LM3532_REG_BRT_A, LM3532_REG_BRT_B, LM3532_REG_BRT_C, };
+
+ return ti_lmu_write_byte(lmu_bl->chip->lmu, reg[lmu_bl->bank_id],
+ brightness);
+}
+
+static int lm3532_bl_select_pwm_bank(struct ti_lmu_bl *lmu_bl, int bank_id)
+{
+ struct ti_lmu *lmu = lmu_bl->chip->lmu;
+ u8 mask[] = { LM3532_PWM_SEL_A_MASK, LM3532_PWM_SEL_B_MASK,
+ LM3532_PWM_SEL_C_MASK, };
+ u8 shift[] = { LM3532_PWM_SEL_A_SHIFT, LM3532_PWM_SEL_B_SHIFT,
+ LM3532_PWM_SEL_C_SHIFT, };
+
+ /* Limitation: only PWM1 is supported. PWM2 is not supported. */
+
+ return ti_lmu_update_bits(lmu, LM3532_REG_PWM_CFG_BASE + bank_id,
+ mask[bank_id],
+ (1 << shift[bank_id]) | LM3532_PWM1);
+}
+
+static int lm3532_bl_string_configure(struct ti_lmu_bl *lmu_bl)
+{
+ struct ti_lmu *lmu = lmu_bl->chip->lmu;
+ int bank_id = lmu_bl->bank_id;
+ int is_detected = 0;
+ int i, ret;
+ u8 mask[] = { LM3532_ILED1_CFG_MASK, LM3532_ILED2_CFG_MASK,
+ LM3532_ILED3_CFG_MASK, };
+ u8 shift[] = { LM3532_ILED1_CFG_SHIFT, LM3532_ILED2_CFG_SHIFT,
+ LM3532_ILED3_CFG_SHIFT, };
+
+ /* Assign control bank from backlight string configuration */
+ for (i = 0; i < LM3532_BL_MAX_STRINGS; i++) {
+ if (test_bit(i, &lmu_bl->bl_string)) {
+ ret = ti_lmu_update_bits(lmu, LM3532_REG_OUTPUT_CFG,
+ mask[i], bank_id << shift[i]);
+ if (ret)
+ return ret;
+
+ is_detected = 1;
+ }
+ }
+
+ if (!is_detected) {
+ dev_err(lmu_bl->chip->dev, "No backlight string found\n");
+ return -EINVAL;
+ }
+
+ if (lmu_bl->mode == BL_PWM_BASED)
+ return lm3532_bl_select_pwm_bank(lmu_bl, bank_id);
+
+ return 0;
+}
+
+static int lm3532_bl_set_current_limit(struct ti_lmu_bl *lmu_bl)
+{
+ u8 reg[] = { LM3532_REG_IMAX_A, LM3532_REG_IMAX_B, LM3532_REG_IMAX_C };
+
+ return ti_lmu_write_byte(lmu_bl->chip->lmu, reg[lmu_bl->bank_id],
+ lmu_bl->imax);
+}
+
+static int lm3532_bl_set_ramp(struct ti_lmu_bl *lmu_bl)
+{
+ int ret, index;
+
+ index = ti_lmu_backlight_get_ramp_index(lmu_bl, BL_RAMP_UP);
+ if (index > 0) {
+ ret = ti_lmu_update_bits(lmu_bl->chip->lmu, LM3532_REG_RAMPUP,
+ LM3532_RAMPUP_MASK,
+ index << LM3532_RAMPUP_SHIFT);
+ if (ret)
+ return ret;
+ }
+
+ index = ti_lmu_backlight_get_ramp_index(lmu_bl, BL_RAMP_DOWN);
+ if (index > 0) {
+ ret = ti_lmu_update_bits(lmu_bl->chip->lmu, LM3532_REG_RAMPDN,
+ LM3532_RAMPDN_MASK,
+ index << LM3532_RAMPDN_SHIFT);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
+static int lm3532_bl_configure(struct ti_lmu_bl *lmu_bl)
+{
+ int ret;
+
+ ret = lm3532_bl_string_configure(lmu_bl);
+ if (ret)
+ return ret;
+
+ ret = lm3532_bl_set_current_limit(lmu_bl);
+ if (ret)
+ return ret;
+
+ return lm3532_bl_set_ramp(lmu_bl);
+}
+
+/* Backlight ramp up/down time. Unit is msec. */
+static const int lm3532_ramp_table[] = { 0, 1, 2, 4, 8, 16, 32, 65 };
+
+static const struct ti_lmu_bl_ops lm3532_lmu_ops = {
+ .init = lm3532_bl_init,
+ .configure = lm3532_bl_configure,
+ .update_brightness = lm3532_bl_set_brightness,
+ .bl_enable = lm3532_bl_enable,
+ .max_brightness = LM3532_MAX_BRIGHTNESS,
+ .ramp_table = lm3532_ramp_table,
+ .size_ramp = ARRAY_SIZE(lm3532_ramp_table),
+};
+
+/* LM3532 backlight of_device_id */
+TI_LMU_BL_OF_DEVICE(lm3532, "ti,lm3532-backlight");
+
+/* LM3532 backlight platform driver */
+TI_LMU_BL_PLATFORM_DRIVER(lm3532, "lm3532-backlight");
+
+MODULE_DESCRIPTION("TI LM3532 Backlight Driver");
+MODULE_AUTHOR("Milo Kim");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:lm3532-backlight");
--
1.9.1

2015-11-02 05:25:59

by Kim, Milo

[permalink] [raw]
Subject: [PATCH RESEND 09/16] backlight: ti-lmu-backlight: add LM3631 driver

LM3631 has 2 backlight strings and 11 bit dimming is supported.
PWM brightness control is also supported.

Common backlight driver is controlled by TI LMU backlight driver.
Only LM3631 specific code is implemented here.

Cc: Jingoo Han <[email protected]>
Cc: Lee Jones <[email protected]>
Cc: [email protected]
Signed-off-by: Milo Kim <[email protected]>
---
drivers/video/backlight/Kconfig | 9 +++
drivers/video/backlight/Makefile | 1 +
drivers/video/backlight/lm3631_bl.c | 129 ++++++++++++++++++++++++++++++++++++
3 files changed, 139 insertions(+)
create mode 100644 drivers/video/backlight/lm3631_bl.c

diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
index 86d7946..986842e 100644
--- a/drivers/video/backlight/Kconfig
+++ b/drivers/video/backlight/Kconfig
@@ -399,6 +399,15 @@ config BACKLIGHT_LM3532
Up to 3 backlight strings and 8 bit dimming is supported.
PWM brightness control is also supported.

+config BACKLIGHT_LM3631
+ tristate "Backlight driver for TI LM3631"
+ depends on BACKLIGHT_CLASS_DEVICE && MFD_TI_LMU
+ select TI_LMU_BACKLIGHT
+ help
+ Say Y to enable the backlight driver for TI LM3631.
+ Up to 2 backlight strings and 11 bit dimming is supported.
+ PWM brightness control is also supported.
+
config TI_LMU_BACKLIGHT
tristate "Backlight driver for TI LMU"
depends on BACKLIGHT_LM3532 || BACKLIGHT_LM3631 || \
diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile
index e037f57..e8891e8 100644
--- a/drivers/video/backlight/Makefile
+++ b/drivers/video/backlight/Makefile
@@ -39,6 +39,7 @@ obj-$(CONFIG_BACKLIGHT_IPAQ_MICRO) += ipaq_micro_bl.o
obj-$(CONFIG_BACKLIGHT_LM3532) += lm3532_bl.o
obj-$(CONFIG_BACKLIGHT_LM3533) += lm3533_bl.o
obj-$(CONFIG_BACKLIGHT_LM3630A) += lm3630a_bl.o
+obj-$(CONFIG_BACKLIGHT_LM3631) += lm3631_bl.o
obj-$(CONFIG_BACKLIGHT_LM3639) += lm3639_bl.o
obj-$(CONFIG_BACKLIGHT_LOCOMO) += locomolcd.o
obj-$(CONFIG_BACKLIGHT_LP855X) += lp855x_bl.o
diff --git a/drivers/video/backlight/lm3631_bl.c b/drivers/video/backlight/lm3631_bl.c
new file mode 100644
index 0000000..1a914e5
--- /dev/null
+++ b/drivers/video/backlight/lm3631_bl.c
@@ -0,0 +1,129 @@
+/*
+ * TI LM3631 Backlight Driver
+ *
+ * Copyright 2015 Texas Instruments
+ *
+ * Author: Milo Kim <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/kernel.h>
+#include <linux/mfd/ti-lmu.h>
+#include <linux/mfd/ti-lmu-register.h>
+#include <linux/module.h>
+
+#include "ti-lmu-backlight.h"
+
+/* Default backlight mode: PWM x I2C before sloping */
+#define LM3631_DEFAULT_MODE LM3631_MODE_COMB1
+#define LM3631_FULL_STRINGS (LMU_HVLED1 | LMU_HVLED2)
+#define LM3631_MAX_BRIGHTNESS 2047
+
+static int lm3631_bl_init(struct ti_lmu_bl_chip *chip)
+{
+ /* Set the brightness mode to 'comb1' by default */
+ return ti_lmu_update_bits(chip->lmu, LM3631_REG_BRT_MODE,
+ LM3631_MODE_MASK, LM3631_DEFAULT_MODE);
+}
+
+static int lm3631_bl_enable(struct ti_lmu_bl *lmu_bl, int enable)
+{
+ return ti_lmu_update_bits(lmu_bl->chip->lmu, LM3631_REG_DEVCTRL,
+ LM3631_BL_EN_MASK, enable);
+}
+
+static int lm3631_bl_set_brightness(struct ti_lmu_bl *lmu_bl, int brightness)
+{
+ u8 data;
+ int ret;
+
+ if (lmu_bl->mode == BL_PWM_BASED)
+ return 0;
+
+ data = brightness & LM3631_BRT_LSB_MASK;
+ ret = ti_lmu_update_bits(lmu_bl->chip->lmu, LM3631_REG_BRT_LSB,
+ LM3631_BRT_LSB_MASK, data);
+ if (ret)
+ return ret;
+
+ data = (brightness >> LM3631_BRT_MSB_SHIFT) & 0xFF;
+ return ti_lmu_write_byte(lmu_bl->chip->lmu, LM3631_REG_BRT_MSB,
+ data);
+}
+
+static int lm3631_bl_string_configure(struct ti_lmu_bl *lmu_bl)
+{
+ u8 val;
+
+ if (lmu_bl->bl_string == LM3631_FULL_STRINGS)
+ val = LM3631_BL_TWO_STRINGS;
+ else
+ val = LM3631_BL_ONE_STRING;
+
+ return ti_lmu_update_bits(lmu_bl->chip->lmu, LM3631_REG_BL_CFG,
+ LM3631_BL_STRING_MASK, val);
+}
+
+static int lm3631_bl_configure(struct ti_lmu_bl *lmu_bl)
+{
+ int ret;
+ int index;
+
+ ret = lm3631_bl_string_configure(lmu_bl);
+ if (ret)
+ return ret;
+
+ /* Set exponential mapping */
+ ret = ti_lmu_update_bits(lmu_bl->chip->lmu, LM3631_REG_BL_CFG,
+ LM3631_MAP_MASK, LM3631_EXPONENTIAL_MAP);
+ if (ret)
+ return ret;
+
+ /* Enable slope bit before updating slope time value */
+ ret = ti_lmu_update_bits(lmu_bl->chip->lmu, LM3631_REG_BRT_MODE,
+ LM3631_EN_SLOPE_MASK, LM3631_EN_SLOPE_MASK);
+ if (ret)
+ return ret;
+
+ /* Slope time configuration */
+ index = ti_lmu_backlight_get_ramp_index(lmu_bl, BL_RAMP_UP);
+ if (index > 0) {
+ ret = ti_lmu_update_bits(lmu_bl->chip->lmu, LM3631_REG_SLOPE,
+ LM3631_SLOPE_MASK,
+ index << LM3631_SLOPE_SHIFT);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
+/* Backlight ramp up time. Unit is msec. */
+static const int lm3631_ramp_table[] = {
+ 0, 1, 2, 5, 10, 20, 50, 100,
+ 250, 500, 750, 1000, 1500, 2000, 3000, 4000,
+};
+
+static const struct ti_lmu_bl_ops lm3631_lmu_ops = {
+ .init = lm3631_bl_init,
+ .configure = lm3631_bl_configure,
+ .update_brightness = lm3631_bl_set_brightness,
+ .bl_enable = lm3631_bl_enable,
+ .max_brightness = LM3631_MAX_BRIGHTNESS,
+ .ramp_table = lm3631_ramp_table,
+ .size_ramp = ARRAY_SIZE(lm3631_ramp_table),
+};
+
+/* LM3631 backlight of_device_id */
+TI_LMU_BL_OF_DEVICE(lm3631, "ti,lm3631-backlight");
+
+/* LM3631 backlight platform driver */
+TI_LMU_BL_PLATFORM_DRIVER(lm3631, "lm3631-backlight");
+
+MODULE_DESCRIPTION("TI LM3631 Backlight Driver");
+MODULE_AUTHOR("Milo Kim");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:lm3631-backlight");
--
1.9.1

2015-11-02 05:26:00

by Kim, Milo

[permalink] [raw]
Subject: [PATCH RESEND 10/16] backlight: ti-lmu-backlight: add LM3632 driver

LM3632 has 2 backlight strings and 11 bit dimming is supported.
PWM brightness control is also supported.

Common backlight driver is controlled by TI LMU backlight driver.
Only LM3632 specific code is implemented here.

Cc: Jingoo Han <[email protected]>
Cc: Lee Jones <[email protected]>
Cc: [email protected]
Signed-off-by: Milo Kim <[email protected]>
---
drivers/video/backlight/Kconfig | 9 +++
drivers/video/backlight/Makefile | 1 +
drivers/video/backlight/lm3632_bl.c | 125 ++++++++++++++++++++++++++++++++++++
3 files changed, 135 insertions(+)
create mode 100644 drivers/video/backlight/lm3632_bl.c

diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
index 986842e..e3bf905 100644
--- a/drivers/video/backlight/Kconfig
+++ b/drivers/video/backlight/Kconfig
@@ -408,6 +408,15 @@ config BACKLIGHT_LM3631
Up to 2 backlight strings and 11 bit dimming is supported.
PWM brightness control is also supported.

+config BACKLIGHT_LM3632
+ tristate "Backlight driver for TI LM3632"
+ depends on BACKLIGHT_CLASS_DEVICE && MFD_TI_LMU
+ select TI_LMU_BACKLIGHT
+ help
+ Say Y to enable the backlight driver for TI LM3632.
+ Up to 2 backlight strings and 11 bit dimming is supported.
+ PWM brightness control is also supported.
+
config TI_LMU_BACKLIGHT
tristate "Backlight driver for TI LMU"
depends on BACKLIGHT_LM3532 || BACKLIGHT_LM3631 || \
diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile
index e8891e8..6cd5232 100644
--- a/drivers/video/backlight/Makefile
+++ b/drivers/video/backlight/Makefile
@@ -40,6 +40,7 @@ obj-$(CONFIG_BACKLIGHT_LM3532) += lm3532_bl.o
obj-$(CONFIG_BACKLIGHT_LM3533) += lm3533_bl.o
obj-$(CONFIG_BACKLIGHT_LM3630A) += lm3630a_bl.o
obj-$(CONFIG_BACKLIGHT_LM3631) += lm3631_bl.o
+obj-$(CONFIG_BACKLIGHT_LM3632) += lm3632_bl.o
obj-$(CONFIG_BACKLIGHT_LM3639) += lm3639_bl.o
obj-$(CONFIG_BACKLIGHT_LOCOMO) += locomolcd.o
obj-$(CONFIG_BACKLIGHT_LP855X) += lp855x_bl.o
diff --git a/drivers/video/backlight/lm3632_bl.c b/drivers/video/backlight/lm3632_bl.c
new file mode 100644
index 0000000..7a3eb73
--- /dev/null
+++ b/drivers/video/backlight/lm3632_bl.c
@@ -0,0 +1,125 @@
+/*
+ * TI LM3632 Backlight Driver
+ *
+ * Copyright 2015 Texas Instruments
+ *
+ * Author: Milo Kim <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/kernel.h>
+#include <linux/mfd/ti-lmu.h>
+#include <linux/mfd/ti-lmu-register.h>
+#include <linux/module.h>
+
+#include "ti-lmu-backlight.h"
+
+#define LM3632_DEFAULT_OVP LM3632_OVP_25V
+#define LM3632_FULL_STRINGS (LMU_HVLED1 | LMU_HVLED2)
+#define LM3632_MAX_BRIGHTNESS 2047
+
+static int lm3632_bl_enable(struct ti_lmu_bl *lmu_bl, int enable)
+{
+ return ti_lmu_update_bits(lmu_bl->chip->lmu, LM3632_REG_ENABLE,
+ LM3632_BL_EN_MASK, enable);
+}
+
+static int lm3632_bl_set_brightness(struct ti_lmu_bl *lmu_bl, int brightness)
+{
+ u8 data;
+ int ret;
+
+ if (lmu_bl->mode == BL_PWM_BASED)
+ return 0;
+
+ data = brightness & LM3632_BRT_LSB_MASK;
+ ret = ti_lmu_update_bits(lmu_bl->chip->lmu, LM3632_REG_BRT_LSB,
+ LM3632_BRT_LSB_MASK, data);
+ if (ret)
+ return ret;
+
+ data = (brightness >> LM3632_BRT_MSB_SHIFT) & 0xFF;
+ return ti_lmu_write_byte(lmu_bl->chip->lmu, LM3632_REG_BRT_MSB,
+ data);
+}
+
+static int lm3632_bl_string_configure(struct ti_lmu_bl *lmu_bl)
+{
+ u8 val;
+
+ if (lmu_bl->bl_string == LM3632_FULL_STRINGS)
+ val = LM3632_BL_TWO_STRINGS;
+ else
+ val = LM3632_BL_ONE_STRING;
+
+ return ti_lmu_update_bits(lmu_bl->chip->lmu, LM3632_REG_ENABLE,
+ LM3632_BL_STRING_MASK, val);
+}
+
+static int lm3632_bl_set_ovp(struct ti_lmu_bl *lmu_bl)
+{
+ return ti_lmu_update_bits(lmu_bl->chip->lmu, LM3632_REG_CONFIG1,
+ LM3632_OVP_MASK, LM3632_DEFAULT_OVP);
+}
+
+static int lm3632_bl_set_swfreq(struct ti_lmu_bl *lmu_bl)
+{
+ return ti_lmu_update_bits(lmu_bl->chip->lmu, LM3632_REG_CONFIG2,
+ LM3632_SWFREQ_MASK, LM3632_SWFREQ_1MHZ);
+}
+
+static int lm3632_bl_set_ctrl_mode(struct ti_lmu_bl *lmu_bl)
+{
+ u8 val;
+
+ if (lmu_bl->mode == BL_PWM_BASED)
+ val = LM3632_PWM_MODE;
+ else
+ val = LM3632_I2C_MODE;
+
+ return ti_lmu_update_bits(lmu_bl->chip->lmu, LM3632_REG_IO_CTRL,
+ LM3632_PWM_MASK, val);
+}
+
+static int lm3632_bl_configure(struct ti_lmu_bl *lmu_bl)
+{
+ int ret;
+
+ ret = lm3632_bl_string_configure(lmu_bl);
+ if (ret)
+ return ret;
+
+ /* Select OVP level */
+ ret = lm3632_bl_set_ovp(lmu_bl);
+ if (ret)
+ return ret;
+
+ /* Select switching frequency */
+ ret = lm3632_bl_set_swfreq(lmu_bl);
+ if (ret)
+ return ret;
+
+ /* Backlight control mode - PWM or I2C */
+ return lm3632_bl_set_ctrl_mode(lmu_bl);
+}
+
+static const struct ti_lmu_bl_ops lm3632_lmu_ops = {
+ .configure = lm3632_bl_configure,
+ .update_brightness = lm3632_bl_set_brightness,
+ .bl_enable = lm3632_bl_enable,
+ .max_brightness = LM3632_MAX_BRIGHTNESS,
+};
+
+/* LM3632 backlight of_device_id */
+TI_LMU_BL_OF_DEVICE(lm3632, "ti,lm3632-backlight");
+
+/* LM3632 backlight platform driver */
+TI_LMU_BL_PLATFORM_DRIVER(lm3632, "lm3632-backlight");
+
+MODULE_DESCRIPTION("TI LM3632 Backlight Driver");
+MODULE_AUTHOR("Milo Kim");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:lm3632-backlight");
--
1.9.1

2015-11-02 05:26:03

by Kim, Milo

[permalink] [raw]
Subject: [PATCH RESEND 11/16] backlight: ti-lmu-backlight: add LM3633 driver

LM3633 has 3 backlight strings and 11 bit dimming is supported.
PWM brightness control is also supported.

LM3633 MFD has HWMON driver which monitors hardware fault detection.
After this monitoring is done, LM3633 backlight device should be
reinitialized. To enable this, 'hwmon_notifier_used' is set to true.
Then, TI LMU backlight handles LMU HWMON event in
ti_lmu_backlight_hwmon_notifier().

Common backlight driver is controlled by TI LMU backlight driver.
Only LM3633 specific code is implemented here.

Cc: Jingoo Han <[email protected]>
Cc: Lee Jones <[email protected]>
Cc: [email protected]
Signed-off-by: Milo Kim <[email protected]>
---
drivers/video/backlight/Kconfig | 9 ++
drivers/video/backlight/Makefile | 1 +
drivers/video/backlight/lm3633_bl.c | 210 ++++++++++++++++++++++++++++++++++++
3 files changed, 220 insertions(+)
create mode 100644 drivers/video/backlight/lm3633_bl.c

diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
index e3bf905..e3c4adb 100644
--- a/drivers/video/backlight/Kconfig
+++ b/drivers/video/backlight/Kconfig
@@ -417,6 +417,15 @@ config BACKLIGHT_LM3632
Up to 2 backlight strings and 11 bit dimming is supported.
PWM brightness control is also supported.

+config BACKLIGHT_LM3633
+ tristate "Backlight driver for TI LM3633"
+ depends on BACKLIGHT_CLASS_DEVICE && MFD_TI_LMU
+ select TI_LMU_BACKLIGHT
+ help
+ Say Y to enable the backlight driver for TI LM3633.
+ Up to 3 backlight strings and 11 bit dimming is supported.
+ PWM brightness control is also supported.
+
config TI_LMU_BACKLIGHT
tristate "Backlight driver for TI LMU"
depends on BACKLIGHT_LM3532 || BACKLIGHT_LM3631 || \
diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile
index 6cd5232..364b854 100644
--- a/drivers/video/backlight/Makefile
+++ b/drivers/video/backlight/Makefile
@@ -41,6 +41,7 @@ obj-$(CONFIG_BACKLIGHT_LM3533) += lm3533_bl.o
obj-$(CONFIG_BACKLIGHT_LM3630A) += lm3630a_bl.o
obj-$(CONFIG_BACKLIGHT_LM3631) += lm3631_bl.o
obj-$(CONFIG_BACKLIGHT_LM3632) += lm3632_bl.o
+obj-$(CONFIG_BACKLIGHT_LM3633) += lm3633_bl.o
obj-$(CONFIG_BACKLIGHT_LM3639) += lm3639_bl.o
obj-$(CONFIG_BACKLIGHT_LOCOMO) += locomolcd.o
obj-$(CONFIG_BACKLIGHT_LP855X) += lp855x_bl.o
diff --git a/drivers/video/backlight/lm3633_bl.c b/drivers/video/backlight/lm3633_bl.c
new file mode 100644
index 0000000..6e01746
--- /dev/null
+++ b/drivers/video/backlight/lm3633_bl.c
@@ -0,0 +1,210 @@
+/*
+ * TI LM3633 Backlight Driver
+ *
+ * Copyright 2015 Texas Instruments
+ *
+ * Author: Milo Kim <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/kernel.h>
+#include <linux/mfd/ti-lmu.h>
+#include <linux/mfd/ti-lmu-register.h>
+#include <linux/module.h>
+
+#include "ti-lmu-backlight.h"
+
+#define LM3633_DEFAULT_OVP LM3633_BOOST_OVP_40V
+#define LM3633_BL_MAX_STRINGS 3
+#define LM3633_BL_MAX_BRIGHTNESS 2047
+
+static int lm3633_bl_init(struct ti_lmu_bl_chip *chip)
+{
+ /* Configure ramp selection for each bank */
+ return ti_lmu_update_bits(chip->lmu, LM3633_REG_BL_RAMP_CONF,
+ LM3633_BL_RAMP_MASK, LM3633_BL_RAMP_EACH);
+}
+
+static int lm3633_bl_enable(struct ti_lmu_bl *lmu_bl, int enable)
+{
+ return ti_lmu_update_bits(lmu_bl->chip->lmu, LM3633_REG_ENABLE,
+ BIT(lmu_bl->bank_id),
+ enable << lmu_bl->bank_id);
+}
+
+static int lm3633_bl_set_brightness(struct ti_lmu_bl *lmu_bl, int brightness)
+{
+ int ret;
+ u8 data;
+ u8 reg_lsb[] = { LM3633_REG_BRT_HVLED_A_LSB,
+ LM3633_REG_BRT_HVLED_B_LSB, };
+ u8 reg_msb[] = { LM3633_REG_BRT_HVLED_A_MSB,
+ LM3633_REG_BRT_HVLED_B_MSB, };
+
+ if (lmu_bl->mode == BL_PWM_BASED) {
+ /*
+ * PWM can start from any non-zero code and dim down to zero.
+ * So, brightness register should be updated even in PWM mode.
+ */
+ if (brightness > 0)
+ brightness = LM3633_BL_MAX_BRIGHTNESS;
+ else
+ brightness = 0;
+ }
+
+ data = brightness & LM3633_BRT_HVLED_LSB_MASK;
+ ret = ti_lmu_update_bits(lmu_bl->chip->lmu, reg_lsb[lmu_bl->bank_id],
+ LM3633_BRT_HVLED_LSB_MASK, data);
+ if (ret)
+ return ret;
+
+ data = (brightness >> LM3633_BRT_HVLED_MSB_SHIFT) & 0xFF;
+ return ti_lmu_write_byte(lmu_bl->chip->lmu, reg_msb[lmu_bl->bank_id],
+ data);
+}
+
+static int lm3633_bl_boost_configure(struct ti_lmu_bl *lmu_bl)
+{
+ return ti_lmu_update_bits(lmu_bl->chip->lmu, LM3633_REG_BOOST_CFG,
+ LM3633_BOOST_OVP_MASK, LM3633_DEFAULT_OVP);
+}
+
+static int lm3633_bl_set_ctrl_mode(struct ti_lmu_bl *lmu_bl)
+{
+ int bank_id = lmu_bl->bank_id;
+
+ if (lmu_bl->mode == BL_PWM_BASED)
+ return ti_lmu_update_bits(lmu_bl->chip->lmu,
+ LM3633_REG_PWM_CFG,
+ BIT(bank_id), 1 << bank_id);
+
+ return 0;
+}
+
+static int lm3633_bl_string_configure(struct ti_lmu_bl *lmu_bl)
+{
+ struct ti_lmu *lmu = lmu_bl->chip->lmu;
+ int is_detected = 0;
+ int i, ret;
+
+ /* Assign control bank from backlight string configuration */
+ for (i = 0; i < LM3633_BL_MAX_STRINGS; i++) {
+ if (test_bit(i, &lmu_bl->bl_string)) {
+ ret = ti_lmu_update_bits(lmu,
+ LM3633_REG_HVLED_OUTPUT_CFG,
+ BIT(i), lmu_bl->bank_id << i);
+ if (ret)
+ return ret;
+
+ is_detected = 1;
+ }
+ }
+
+ if (!is_detected) {
+ dev_err(lmu_bl->chip->dev, "No backlight string found\n");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int lm3633_bl_set_current_limit(struct ti_lmu_bl *lmu_bl)
+{
+ u8 reg[] = { LM3633_REG_IMAX_HVLED_A, LM3633_REG_IMAX_HVLED_B, };
+
+ return ti_lmu_write_byte(lmu_bl->chip->lmu, reg[lmu_bl->bank_id],
+ lmu_bl->imax);
+}
+
+static int lm3633_bl_set_ramp(struct ti_lmu_bl *lmu_bl)
+{
+ int ret, index;
+ u8 reg;
+
+ index = ti_lmu_backlight_get_ramp_index(lmu_bl, BL_RAMP_UP);
+ if (index > 0) {
+ if (lmu_bl->bank_id == 0)
+ reg = LM3633_REG_BL0_RAMPUP;
+ else
+ reg = LM3633_REG_BL1_RAMPUP;
+
+ ret = ti_lmu_update_bits(lmu_bl->chip->lmu, reg,
+ LM3633_BL_RAMPUP_MASK,
+ index << LM3633_BL_RAMPUP_SHIFT);
+ if (ret)
+ return ret;
+ }
+
+ index = ti_lmu_backlight_get_ramp_index(lmu_bl, BL_RAMP_DOWN);
+ if (index > 0) {
+ if (lmu_bl->bank_id == 0)
+ reg = LM3633_REG_BL0_RAMPDN;
+ else
+ reg = LM3633_REG_BL1_RAMPDN;
+
+ ret = ti_lmu_update_bits(lmu_bl->chip->lmu, reg,
+ LM3633_BL_RAMPDN_MASK,
+ index << LM3633_BL_RAMPDN_SHIFT);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
+static int lm3633_bl_configure(struct ti_lmu_bl *lmu_bl)
+{
+ int ret;
+
+ ret = lm3633_bl_boost_configure(lmu_bl);
+ if (ret)
+ return ret;
+
+ ret = lm3633_bl_set_ctrl_mode(lmu_bl);
+ if (ret)
+ return ret;
+
+ ret = lm3633_bl_string_configure(lmu_bl);
+ if (ret)
+ return ret;
+
+ ret = lm3633_bl_set_current_limit(lmu_bl);
+ if (ret)
+ return ret;
+
+ ret = lm3633_bl_set_ramp(lmu_bl);
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
+/* Backlight ramp up/down time. Unit is msec. */
+static const int lm3633_ramp_table[] = {
+ 2, 250, 500, 1000, 2000, 4000, 8000, 16000,
+};
+
+static const struct ti_lmu_bl_ops lm3633_lmu_ops = {
+ .init = lm3633_bl_init,
+ .configure = lm3633_bl_configure,
+ .update_brightness = lm3633_bl_set_brightness,
+ .bl_enable = lm3633_bl_enable,
+ .hwmon_notifier_used = true,
+ .max_brightness = LM3633_BL_MAX_BRIGHTNESS,
+ .ramp_table = lm3633_ramp_table,
+ .size_ramp = ARRAY_SIZE(lm3633_ramp_table),
+};
+
+/* LM3633 backlight of_device_id */
+TI_LMU_BL_OF_DEVICE(lm3633, "ti,lm3633-backlight");
+
+/* LM3633 backlight platform driver */
+TI_LMU_BL_PLATFORM_DRIVER(lm3633, "lm3633-backlight");
+
+MODULE_DESCRIPTION("TI LM3633 Backlight Driver");
+MODULE_AUTHOR("Milo Kim");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:lm3633-backlight");
--
1.9.1

2015-11-02 05:26:07

by Kim, Milo

[permalink] [raw]
Subject: [PATCH RESEND 12/16] backlight: ti-lmu-backlight: add LM3695 driver

LM3695 has 2 backlight strings and 11 bit dimming is supported.

Common backlight driver is controlled by TI LMU backlight driver.
Only LM3695 specific code is implemented here.

Cc: Jingoo Han <[email protected]>
Cc: Lee Jones <[email protected]>
Cc: [email protected]
Signed-off-by: Milo Kim <[email protected]>
---
drivers/video/backlight/Kconfig | 8 ++++
drivers/video/backlight/Makefile | 1 +
drivers/video/backlight/lm3695_bl.c | 91 +++++++++++++++++++++++++++++++++++++
3 files changed, 100 insertions(+)
create mode 100644 drivers/video/backlight/lm3695_bl.c

diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
index e3c4adb..c1dc908 100644
--- a/drivers/video/backlight/Kconfig
+++ b/drivers/video/backlight/Kconfig
@@ -426,6 +426,14 @@ config BACKLIGHT_LM3633
Up to 3 backlight strings and 11 bit dimming is supported.
PWM brightness control is also supported.

+config BACKLIGHT_LM3695
+ tristate "Backlight driver for TI LM3695"
+ depends on BACKLIGHT_CLASS_DEVICE && MFD_TI_LMU
+ select TI_LMU_BACKLIGHT
+ help
+ Say Y to enable the backlight driver for TI LM3695.
+ Up to 2 backlight strings and 11 bit dimming is supported.
+
config TI_LMU_BACKLIGHT
tristate "Backlight driver for TI LMU"
depends on BACKLIGHT_LM3532 || BACKLIGHT_LM3631 || \
diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile
index 364b854..af20285 100644
--- a/drivers/video/backlight/Makefile
+++ b/drivers/video/backlight/Makefile
@@ -43,6 +43,7 @@ obj-$(CONFIG_BACKLIGHT_LM3631) += lm3631_bl.o
obj-$(CONFIG_BACKLIGHT_LM3632) += lm3632_bl.o
obj-$(CONFIG_BACKLIGHT_LM3633) += lm3633_bl.o
obj-$(CONFIG_BACKLIGHT_LM3639) += lm3639_bl.o
+obj-$(CONFIG_BACKLIGHT_LM3695) += lm3695_bl.o
obj-$(CONFIG_BACKLIGHT_LOCOMO) += locomolcd.o
obj-$(CONFIG_BACKLIGHT_LP855X) += lp855x_bl.o
obj-$(CONFIG_BACKLIGHT_LP8788) += lp8788_bl.o
diff --git a/drivers/video/backlight/lm3695_bl.c b/drivers/video/backlight/lm3695_bl.c
new file mode 100644
index 0000000..fe47d00
--- /dev/null
+++ b/drivers/video/backlight/lm3695_bl.c
@@ -0,0 +1,91 @@
+/*
+ * TI LM3695 Backlight Driver
+ *
+ * Copyright 2015 Texas Instruments
+ *
+ * Author: Milo Kim <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/delay.h>
+#include <linux/kernel.h>
+#include <linux/mfd/ti-lmu.h>
+#include <linux/mfd/ti-lmu-register.h>
+#include <linux/module.h>
+
+#include "ti-lmu-backlight.h"
+
+#define LM3695_FULL_STRINGS (LMU_HVLED1 | LMU_HVLED2)
+#define LM3695_MAX_BRIGHTNESS 2047
+
+static int lm3695_bl_enable(struct ti_lmu_bl *lmu_bl, int enable)
+{
+ int ret;
+
+ ret = ti_lmu_update_bits(lmu_bl->chip->lmu, LM3695_REG_GP,
+ LM3695_BL_EN_MASK, enable);
+ if (ret)
+ return ret;
+
+ /* Wait time for brightness register wake up */
+ usleep_range(600, 700);
+
+ return 0;
+}
+
+static int lm3695_bl_set_brightness(struct ti_lmu_bl *lmu_bl, int brightness)
+{
+ u8 data;
+ int ret;
+
+ data = brightness & LM3695_BRT_LSB_MASK;
+ ret = ti_lmu_update_bits(lmu_bl->chip->lmu, LM3695_REG_BRT_LSB,
+ LM3695_BRT_LSB_MASK, data);
+ if (ret)
+ return ret;
+
+ data = (brightness >> LM3695_BRT_MSB_SHIFT) & 0xFF;
+ return ti_lmu_write_byte(lmu_bl->chip->lmu, LM3695_REG_BRT_MSB,
+ data);
+}
+
+static int lm3695_bl_init(struct ti_lmu_bl_chip *chip)
+{
+ return ti_lmu_update_bits(chip->lmu, LM3695_REG_GP,
+ LM3695_BRT_RW_MASK, LM3695_BRT_RW_MASK);
+}
+
+static int lm3695_bl_configure(struct ti_lmu_bl *lmu_bl)
+{
+ u8 val;
+
+ if (lmu_bl->bl_string == LM3695_FULL_STRINGS)
+ val = LM3695_BL_TWO_STRINGS;
+ else
+ val = LM3695_BL_ONE_STRING;
+
+ return ti_lmu_update_bits(lmu_bl->chip->lmu, LM3695_REG_GP,
+ LM3695_BL_STRING_MASK, val);
+}
+
+static const struct ti_lmu_bl_ops lm3695_lmu_ops = {
+ .init = lm3695_bl_init,
+ .configure = lm3695_bl_configure,
+ .update_brightness = lm3695_bl_set_brightness,
+ .bl_enable = lm3695_bl_enable,
+ .max_brightness = LM3695_MAX_BRIGHTNESS,
+};
+
+/* LM3695 backlight of_device_id */
+TI_LMU_BL_OF_DEVICE(lm3695, "ti,lm3695-backlight");
+
+/* LM3695 backlight platform driver */
+TI_LMU_BL_PLATFORM_DRIVER(lm3695, "lm3695-backlight");
+
+MODULE_DESCRIPTION("TI LM3695 Backlight Driver");
+MODULE_AUTHOR("Milo Kim");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:lm3695-backlight");
--
1.9.1

2015-11-02 05:26:10

by Kim, Milo

[permalink] [raw]
Subject: [PATCH RESEND 13/16] backlight: ti-lmu-backlight: add LM3697 driver

LM3697 has 3 backlight strings and 11 bit dimming is supported.
PWM brightness control is also supported.

LM3697 MFD has HWMON driver which monitors hardware fault detection.
After this monitoring is done, LM3697 backlight device should be
reinitialized. To enable this, 'hwmon_notifier_used' is set to true.
Then, TI LMU backlight handles LMU HWMON event in
ti_lmu_backlight_hwmon_notifier().

Common backlight driver is controlled by TI LMU backlight driver.
Only LM3697 specific code is implemented here.

Cc: Jingoo Han <[email protected]>
Cc: Lee Jones <[email protected]>
Cc: [email protected]
Signed-off-by: Milo Kim <[email protected]>
---
drivers/video/backlight/Kconfig | 9 ++
drivers/video/backlight/Makefile | 1 +
drivers/video/backlight/lm3697_bl.c | 187 ++++++++++++++++++++++++++++++++++++
3 files changed, 197 insertions(+)
create mode 100644 drivers/video/backlight/lm3697_bl.c

diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
index c1dc908..c672073 100644
--- a/drivers/video/backlight/Kconfig
+++ b/drivers/video/backlight/Kconfig
@@ -434,6 +434,15 @@ config BACKLIGHT_LM3695
Say Y to enable the backlight driver for TI LM3695.
Up to 2 backlight strings and 11 bit dimming is supported.

+config BACKLIGHT_LM3697
+ tristate "Backlight driver for TI LM3697"
+ depends on BACKLIGHT_CLASS_DEVICE && MFD_TI_LMU
+ select TI_LMU_BACKLIGHT
+ help
+ Say Y to enable the backlight driver for TI LM3697.
+ Up to 3 backlight strings and 11 bit dimming is supported.
+ PWM brightness control is also supported.
+
config TI_LMU_BACKLIGHT
tristate "Backlight driver for TI LMU"
depends on BACKLIGHT_LM3532 || BACKLIGHT_LM3631 || \
diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile
index af20285..abb7fe0 100644
--- a/drivers/video/backlight/Makefile
+++ b/drivers/video/backlight/Makefile
@@ -44,6 +44,7 @@ obj-$(CONFIG_BACKLIGHT_LM3632) += lm3632_bl.o
obj-$(CONFIG_BACKLIGHT_LM3633) += lm3633_bl.o
obj-$(CONFIG_BACKLIGHT_LM3639) += lm3639_bl.o
obj-$(CONFIG_BACKLIGHT_LM3695) += lm3695_bl.o
+obj-$(CONFIG_BACKLIGHT_LM3697) += lm3697_bl.o
obj-$(CONFIG_BACKLIGHT_LOCOMO) += locomolcd.o
obj-$(CONFIG_BACKLIGHT_LP855X) += lp855x_bl.o
obj-$(CONFIG_BACKLIGHT_LP8788) += lp8788_bl.o
diff --git a/drivers/video/backlight/lm3697_bl.c b/drivers/video/backlight/lm3697_bl.c
new file mode 100644
index 0000000..bb0c2bf
--- /dev/null
+++ b/drivers/video/backlight/lm3697_bl.c
@@ -0,0 +1,187 @@
+/*
+ * TI LM3697 Backlight Driver
+ *
+ * Copyright 2015 Texas Instruments
+ *
+ * Author: Milo Kim <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/kernel.h>
+#include <linux/mfd/ti-lmu.h>
+#include <linux/mfd/ti-lmu-register.h>
+#include <linux/module.h>
+
+#include "ti-lmu-backlight.h"
+
+#define LM3697_BL_MAX_STRINGS 3
+#define LM3697_MAX_BRIGHTNESS 2047
+
+static int lm3697_bl_init(struct ti_lmu_bl_chip *chip)
+{
+ /* Configure ramp selection for each bank */
+ return ti_lmu_update_bits(chip->lmu, LM3697_REG_RAMP_CONF,
+ LM3697_RAMP_MASK, LM3697_RAMP_EACH);
+}
+
+static int lm3697_bl_enable(struct ti_lmu_bl *lmu_bl, int enable)
+{
+ return ti_lmu_update_bits(lmu_bl->chip->lmu, LM3697_REG_ENABLE,
+ BIT(lmu_bl->bank_id),
+ enable << lmu_bl->bank_id);
+}
+
+static int lm3697_bl_set_brightness(struct ti_lmu_bl *lmu_bl, int brightness)
+{
+ int ret;
+ u8 data;
+ u8 reg_lsb[] = { LM3697_REG_BRT_A_LSB, LM3697_REG_BRT_B_LSB, };
+ u8 reg_msb[] = { LM3697_REG_BRT_A_MSB, LM3697_REG_BRT_B_MSB, };
+
+ data = brightness & LM3697_BRT_LSB_MASK;
+ ret = ti_lmu_update_bits(lmu_bl->chip->lmu, reg_lsb[lmu_bl->bank_id],
+ LM3697_BRT_LSB_MASK, data);
+ if (ret)
+ return ret;
+
+ data = (brightness >> LM3697_BRT_MSB_SHIFT) & 0xFF;
+ return ti_lmu_write_byte(lmu_bl->chip->lmu, reg_msb[lmu_bl->bank_id],
+ data);
+}
+
+static int lm3697_bl_set_ctrl_mode(struct ti_lmu_bl *lmu_bl)
+{
+ int bank_id = lmu_bl->bank_id;
+
+ if (lmu_bl->mode == BL_PWM_BASED)
+ return ti_lmu_update_bits(lmu_bl->chip->lmu,
+ LM3697_REG_PWM_CFG,
+ BIT(bank_id), 1 << bank_id);
+
+ return 0;
+}
+
+static int lm3697_bl_string_configure(struct ti_lmu_bl *lmu_bl)
+{
+ struct ti_lmu *lmu = lmu_bl->chip->lmu;
+ int bank_id = lmu_bl->bank_id;
+ int is_detected = 0;
+ int i, ret;
+
+ /* Assign control bank from backlight string configuration */
+ for (i = 0; i < LM3697_BL_MAX_STRINGS; i++) {
+ if (test_bit(i, &lmu_bl->bl_string)) {
+ ret = ti_lmu_update_bits(lmu,
+ LM3697_REG_HVLED_OUTPUT_CFG,
+ BIT(i), bank_id << i);
+ if (ret)
+ return ret;
+
+ is_detected = 1;
+ }
+ }
+
+ if (!is_detected) {
+ dev_err(lmu_bl->chip->dev, "No backlight string found\n");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int lm3697_bl_set_current_limit(struct ti_lmu_bl *lmu_bl)
+{
+ u8 reg[] = { LM3697_REG_IMAX_A, LM3697_REG_IMAX_B, };
+
+ return ti_lmu_write_byte(lmu_bl->chip->lmu, reg[lmu_bl->bank_id],
+ lmu_bl->imax);
+}
+
+static int lm3697_bl_set_ramp(struct ti_lmu_bl *lmu_bl)
+{
+ int ret, index;
+ u8 reg;
+
+ index = ti_lmu_backlight_get_ramp_index(lmu_bl, BL_RAMP_UP);
+ if (index > 0) {
+ if (lmu_bl->bank_id == 0)
+ reg = LM3697_REG_BL0_RAMPUP;
+ else
+ reg = LM3697_REG_BL1_RAMPUP;
+
+ ret = ti_lmu_update_bits(lmu_bl->chip->lmu, reg,
+ LM3697_BL_RAMPUP_MASK,
+ index << LM3697_BL_RAMPUP_SHIFT);
+ if (ret)
+ return ret;
+ }
+
+ index = ti_lmu_backlight_get_ramp_index(lmu_bl, BL_RAMP_DOWN);
+ if (index > 0) {
+ if (lmu_bl->bank_id == 0)
+ reg = LM3697_REG_BL0_RAMPDN;
+ else
+ reg = LM3697_REG_BL1_RAMPDN;
+
+ ret = ti_lmu_update_bits(lmu_bl->chip->lmu, reg,
+ LM3697_BL_RAMPDN_MASK,
+ index << LM3697_BL_RAMPDN_SHIFT);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
+static int lm3697_bl_configure(struct ti_lmu_bl *lmu_bl)
+{
+ int ret;
+
+ ret = lm3697_bl_set_ctrl_mode(lmu_bl);
+ if (ret)
+ return ret;
+
+ ret = lm3697_bl_string_configure(lmu_bl);
+ if (ret)
+ return ret;
+
+ ret = lm3697_bl_set_current_limit(lmu_bl);
+ if (ret)
+ return ret;
+
+ ret = lm3697_bl_set_ramp(lmu_bl);
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
+/* Backlight ramp up/down time. Unit is msec. */
+static const int lm3697_ramp_table[] = {
+ 2, 250, 500, 1000, 2000, 4000, 8000, 16000,
+};
+
+static const struct ti_lmu_bl_ops lm3697_lmu_ops = {
+ .init = lm3697_bl_init,
+ .configure = lm3697_bl_configure,
+ .update_brightness = lm3697_bl_set_brightness,
+ .bl_enable = lm3697_bl_enable,
+ .hwmon_notifier_used = true,
+ .max_brightness = LM3697_MAX_BRIGHTNESS,
+ .ramp_table = lm3697_ramp_table,
+ .size_ramp = ARRAY_SIZE(lm3697_ramp_table),
+};
+
+/* LM3697 backlight of_device_id */
+TI_LMU_BL_OF_DEVICE(lm3697, "ti,lm3697-backlight");
+
+/* LM3697 backlight platform driver */
+TI_LMU_BL_PLATFORM_DRIVER(lm3697, "lm3697-backlight");
+
+MODULE_DESCRIPTION("TI LM3697 Backlight Driver");
+MODULE_AUTHOR("Milo Kim");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:lm3697-backlight");
--
1.9.1

2015-11-02 05:26:38

by Kim, Milo

[permalink] [raw]
Subject: [PATCH RESEND 14/16] hwmon: add TI LMU hardware fault monitoring driver

LM3633 and LM3697 are TI LMU MFD device.
Those device have hardware monitoring feature which detects opened or
shorted circuit case.

Attributes
----------
Two attributes are registered.
open_fault: check backlight output channel is opened or not
short_fault: check backlight output channel is shorted or not

With register R/W operations, LMU HWMON driver checks the
status of backlight output channels.
LM3633 and LM3697 have same sequence to check channels, so common
functions are used.

Operations
----------
Two devices have common control flow but register addresses are different.
The structure, 'ti_lmu_reg' is used for device configuration.

HWMON notifier
--------------
After LMU HWMON operation is done, backlight device should be
reinitialized. LMU HWMON driver notifies an event as soon as
the monitoring is done. Then, LM3633 and LM3697 backlight driver handles
this event.

Cc: Guenter Roeck <[email protected]>
Cc: Jean Delvare <[email protected]>
Cc: Lee Jones <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Milo Kim <[email protected]>
---
drivers/hwmon/Kconfig | 10 ++
drivers/hwmon/Makefile | 1 +
drivers/hwmon/ti-lmu-hwmon.c | 393 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 404 insertions(+)
create mode 100644 drivers/hwmon/ti-lmu-hwmon.c

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index e13c902..989e1fa 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -1483,6 +1483,16 @@ config SENSORS_THMC50
This driver can also be built as a module. If so, the module
will be called thmc50.

+config SENSORS_TI_LMU
+ tristate "Texas Instruments LMU Hardware Fault Monitoring Driver"
+ depends on MFD_TI_LMU
+ help
+ Say Y here to include support for the TI LMU opened and shorted
+ circuit fault detection.
+
+ This driver can also be built as a module. If so the module
+ will be called ti-lmu-hwmon.
+
config SENSORS_TMP102
tristate "Texas Instruments TMP102"
depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 9e0f3dd..de11b74 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -143,6 +143,7 @@ obj-$(CONFIG_SENSORS_SMSC47M192)+= smsc47m192.o
obj-$(CONFIG_SENSORS_AMC6821) += amc6821.o
obj-$(CONFIG_SENSORS_TC74) += tc74.o
obj-$(CONFIG_SENSORS_THMC50) += thmc50.o
+obj-$(CONFIG_SENSORS_TI_LMU) += ti-lmu-hwmon.o
obj-$(CONFIG_SENSORS_TMP102) += tmp102.o
obj-$(CONFIG_SENSORS_TMP103) += tmp103.o
obj-$(CONFIG_SENSORS_TMP401) += tmp401.o
diff --git a/drivers/hwmon/ti-lmu-hwmon.c b/drivers/hwmon/ti-lmu-hwmon.c
new file mode 100644
index 0000000..c297cf9
--- /dev/null
+++ b/drivers/hwmon/ti-lmu-hwmon.c
@@ -0,0 +1,393 @@
+/*
+ * TI LMU(Lighting Management Unit) Hardware Fault Monitoring Driver
+ *
+ * Copyright 2015 Texas Instruments
+ *
+ * Author: Milo Kim <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/device.h>
+#include <linux/delay.h>
+#include <linux/gpio.h>
+#include <linux/hwmon.h>
+#include <linux/kernel.h>
+#include <linux/mfd/ti-lmu.h>
+#include <linux/mfd/ti-lmu-register.h>
+#include <linux/module.h>
+#include <linux/notifier.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+
+#define LMU_BANK_MASK(n) (~BIT(n) & 0x07)
+#define LMU_BL_MAX_CHANNELS 3
+#define LMU_DEFAULT_BANK 0
+#define LMU_DELAY_STARTUP 500
+#define LMU_DELAY_FEEDBACK 5
+#define LMU_ENABLE_FEEDBACK (BIT(0) | BIT(1) | BIT(2))
+#define LMU_MAX_BRIGHTNESS 0xFF
+#define LMU_NO_RAMP 0
+
+enum ti_lmu_hwmon_id {
+ LMU_HWMON_OPEN,
+ LMU_HWMON_SHORT,
+};
+
+/**
+ * struct ti_lmu_reg
+ *
+ * @monitor: Enable monitoring register
+ * @bank: Bank configuration register
+ * @ramp: Ramp(speed) configuration register
+ * @imax: Current limit setting register
+ * @feedback: Feedback enable register
+ * @brightness: Brightness register
+ * @enable: Bank enable register
+ * @open_fault: Detect opened circuit status register
+ * @short_fault: Detect shorted circuit status register
+ *
+ * To detect hardware fault, several registers are used.
+ * Device specific register addresses are configured in this structure.
+ */
+struct ti_lmu_reg {
+ u8 monitor;
+ u8 bank;
+ u8 ramp;
+ u8 imax;
+ u8 feedback;
+ u8 brightness;
+ u8 enable;
+ u8 open_fault;
+ u8 short_fault;
+};
+
+struct ti_lmu_hwmon {
+ struct ti_lmu *lmu;
+ struct device *dev; /* hwmon dev */
+ const struct ti_lmu_reg *regs;
+};
+
+struct ti_lmu_hwmon_data {
+ const char *name;
+ const struct attribute_group **groups;
+ const struct ti_lmu_reg *regs;
+};
+
+static void ti_lmu_hwmon_reset_device(struct ti_lmu_hwmon *hwmon)
+{
+ unsigned int en_gpio = hwmon->lmu->en_gpio;
+
+ /* POR(power on reset) by enable pin control */
+ gpio_set_value(en_gpio, 0);
+ msleep(LMU_DELAY_STARTUP);
+
+ gpio_set_value(en_gpio, 1);
+ msleep(LMU_DELAY_STARTUP);
+}
+
+static int ti_lmu_hwmon_enable_monitoring(struct ti_lmu_hwmon *hwmon,
+ enum ti_lmu_hwmon_id id)
+{
+ struct ti_lmu *lmu = hwmon->lmu;
+ u8 reg = hwmon->regs->monitor;
+
+ if (id == LMU_HWMON_OPEN)
+ return ti_lmu_write_byte(lmu, reg, BIT(0));
+ else if (id == LMU_HWMON_SHORT)
+ return ti_lmu_write_byte(lmu, reg, BIT(1));
+ else
+ return -EINVAL;
+}
+
+static int ti_lmu_hwmon_assign_bank(struct ti_lmu_hwmon *hwmon, u8 val)
+{
+ return ti_lmu_write_byte(hwmon->lmu, hwmon->regs->bank, val);
+}
+
+static int ti_lmu_hwmon_channel_config(struct ti_lmu_hwmon *hwmon)
+{
+ struct ti_lmu *lmu = hwmon->lmu;
+ const struct ti_lmu_reg *reg = hwmon->regs;
+ int ret;
+
+ /* Set ramp time to the fatest setting */
+ ret = ti_lmu_write_byte(lmu, reg->ramp, LMU_NO_RAMP);
+ if (ret)
+ return ret;
+
+ /* Set max current to 20mA */
+ ret = ti_lmu_write_byte(lmu, reg->imax, LMU_IMAX_20mA);
+ if (ret)
+ return ret;
+
+ /* Enable feedback */
+ ret = ti_lmu_write_byte(lmu, reg->feedback, LMU_ENABLE_FEEDBACK);
+ if (ret)
+ return ret;
+
+ /* Set max brightness */
+ ret = ti_lmu_write_byte(lmu, reg->brightness, LMU_MAX_BRIGHTNESS);
+ if (ret)
+ return ret;
+
+ /* Enable a bank */
+ ret = ti_lmu_write_byte(lmu, reg->enable, 1);
+ if (ret)
+ return ret;
+
+ /* Wait until device completes fault detection */
+ msleep(LMU_DELAY_FEEDBACK);
+
+ return 0;
+}
+
+static int ti_lmu_hwmon_get_open_fault_result(struct ti_lmu_hwmon *hwmon,
+ char *result)
+{
+ int ret, channel, len, offset = 0;
+ u8 status = 0;
+
+ ret = ti_lmu_read_byte(hwmon->lmu, hwmon->regs->open_fault, &status);
+ if (ret)
+ return ret;
+
+ for (channel = 0; channel < LMU_BL_MAX_CHANNELS; channel++) {
+ if (BIT(channel) & status)
+ len = sprintf(&result[offset], "Channel %d is opened\n",
+ channel);
+ else
+ len = sprintf(&result[offset], "Channel %d works\n",
+ channel);
+
+ offset += len;
+ }
+
+ return 0;
+}
+
+static ssize_t ti_lmu_hwmon_get_short_fault_result(struct ti_lmu_hwmon *hwmon,
+ char *buf, int channel)
+{
+ int ret;
+ u8 status = 0;
+
+ ret = ti_lmu_read_byte(hwmon->lmu, hwmon->regs->short_fault, &status);
+ if (ret)
+ return ret;
+
+ if (BIT(channel) & status)
+ return sprintf(buf, "Channel %d is shorted\n", channel);
+ else
+ return sprintf(buf, "Channel %d works\n", channel);
+}
+
+static int ti_lmu_hwmon_disable_all_banks(struct ti_lmu_hwmon *hwmon)
+{
+ return ti_lmu_write_byte(hwmon->lmu, hwmon->regs->enable, 0);
+}
+
+static int ti_lmu_hwmon_notifier_call_chain(struct ti_lmu_hwmon *hwmon)
+{
+ int ret;
+
+ ti_lmu_hwmon_reset_device(hwmon);
+
+ ret = blocking_notifier_call_chain(&hwmon->lmu->notifier,
+ LMU_EVENT_HWMON_DONE, NULL);
+ if (ret == NOTIFY_OK || ret == NOTIFY_DONE)
+ return 0;
+ else
+ return -EINVAL;
+}
+
+static ssize_t ti_lmu_hwmon_open_fault_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buffer)
+{
+ struct ti_lmu_hwmon *hwmon = dev_get_drvdata(dev);
+ char result[100];
+ int ret;
+
+ /* Device should be reset prior to fault detection */
+ ti_lmu_hwmon_reset_device(hwmon);
+
+ ret = ti_lmu_hwmon_enable_monitoring(hwmon, LMU_HWMON_OPEN);
+ if (ret)
+ return ret;
+
+ ret = ti_lmu_hwmon_assign_bank(hwmon, LMU_DEFAULT_BANK);
+ if (ret)
+ return ret;
+
+ ret = ti_lmu_hwmon_channel_config(hwmon);
+ if (ret)
+ return ret;
+
+ memset(result, 0, sizeof(result));
+ ret = ti_lmu_hwmon_get_open_fault_result(hwmon, result);
+ if (ret)
+ return ret;
+
+ /* Notify an event */
+ ret = ti_lmu_hwmon_notifier_call_chain(hwmon);
+ if (ret)
+ dev_warn(dev, "Notify hwmon err\n");
+
+ return snprintf(buffer, PAGE_SIZE, "%s\n", result);
+}
+
+static ssize_t ti_lmu_hwmon_short_fault_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buffer)
+{
+ struct ti_lmu_hwmon *hwmon = dev_get_drvdata(dev);
+ int ret, i, len, offset = 0;
+ char result[100];
+
+ /* Device should be reset prior to fault detection */
+ ti_lmu_hwmon_reset_device(hwmon);
+
+ ret = ti_lmu_hwmon_enable_monitoring(hwmon, LMU_HWMON_SHORT);
+ if (ret)
+ return ret;
+
+ memset(result, 0, sizeof(result));
+
+ /* Shorted circuit detection is done by checking the bank one by one */
+ for (i = 0; i < LMU_BL_MAX_CHANNELS; i++) {
+ ret = ti_lmu_hwmon_assign_bank(hwmon, LMU_BANK_MASK(i));
+ if (ret)
+ return ret;
+
+ ret = ti_lmu_hwmon_channel_config(hwmon);
+ if (ret)
+ return ret;
+
+ len = ti_lmu_hwmon_get_short_fault_result(hwmon,
+ &result[offset], i);
+ if (len < 0)
+ return len;
+
+ offset += len;
+
+ ret = ti_lmu_hwmon_disable_all_banks(hwmon);
+ if (ret)
+ return ret;
+ }
+
+ /* Notify an event */
+ ret = ti_lmu_hwmon_notifier_call_chain(hwmon);
+ if (ret)
+ dev_warn(dev, "Notify hwmon err\n");
+
+ return snprintf(buffer, PAGE_SIZE, "%s\n", result);
+}
+
+static DEVICE_ATTR(open_fault, S_IRUGO, ti_lmu_hwmon_open_fault_show, NULL);
+static DEVICE_ATTR(short_fault, S_IRUGO, ti_lmu_hwmon_short_fault_show, NULL);
+
+static struct attribute *ti_lmu_hwmon_attrs[] = {
+ &dev_attr_open_fault.attr,
+ &dev_attr_short_fault.attr,
+ NULL,
+};
+ATTRIBUTE_GROUPS(ti_lmu_hwmon);
+
+/*
+ * Operations are dependent on the device.
+ * Device registers configuration is required.
+ */
+static const struct ti_lmu_reg lm3633_regs = {
+ .monitor = LM3633_REG_MONITOR_ENABLE,
+ .bank = LM3633_REG_HVLED_OUTPUT_CFG,
+ .ramp = LM3633_REG_BL0_RAMPUP,
+ .imax = LM3633_REG_IMAX_HVLED_A,
+ .feedback = LM3633_REG_BL_FEEDBACK_ENABLE,
+ .brightness = LM3633_REG_BRT_HVLED_A_MSB,
+ .enable = LM3633_REG_ENABLE,
+ .open_fault = LM3633_REG_BL_OPEN_FAULT_STATUS,
+ .short_fault = LM3633_REG_BL_SHORT_FAULT_STATUS,
+};
+
+static const struct ti_lmu_reg lm3697_regs = {
+ .monitor = LM3697_REG_MONITOR_ENABLE,
+ .bank = LM3697_REG_HVLED_OUTPUT_CFG,
+ .ramp = LM3697_REG_BL0_RAMPUP,
+ .imax = LM3697_REG_IMAX_A,
+ .feedback = LM3697_REG_FEEDBACK_ENABLE,
+ .brightness = LM3697_REG_BRT_A_MSB,
+ .enable = LM3697_REG_ENABLE,
+ .open_fault = LM3697_REG_OPEN_FAULT_STATUS,
+ .short_fault = LM3697_REG_SHORT_FAULT_STATUS,
+};
+
+static const struct ti_lmu_hwmon_data lm3633_hwmon_data = {
+ .name = "lm3633_fault_status",
+ .groups = ti_lmu_hwmon_groups,
+ .regs = &lm3633_regs,
+};
+
+static const struct ti_lmu_hwmon_data lm3697_hwmon_data = {
+ .name = "lm3697_fault_status",
+ .groups = ti_lmu_hwmon_groups,
+ .regs = &lm3697_regs,
+};
+
+static const struct of_device_id ti_lmu_hwmon_of_match[] = {
+ { .compatible = "ti,lm3633-hwmon", .data = &lm3633_hwmon_data },
+ { .compatible = "ti,lm3697-hwmon", .data = &lm3697_hwmon_data },
+ { }
+};
+MODULE_DEVICE_TABLE(of, ti_lmu_hwmon_of_match);
+
+static int ti_lmu_hwmon_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct ti_lmu *lmu = dev_get_drvdata(dev->parent);
+ const struct of_device_id *match;
+ struct ti_lmu_hwmon *hwmon;
+ const struct ti_lmu_hwmon_data *data;
+
+ match = of_match_device(ti_lmu_hwmon_of_match, dev);
+ if (!match)
+ return -ENODEV;
+
+ /* To monitor hardware fault, enable pin control should be required. */
+ if (!gpio_is_valid(lmu->en_gpio))
+ return -EINVAL;
+
+ hwmon = devm_kzalloc(dev, sizeof(*hwmon), GFP_KERNEL);
+ if (!hwmon)
+ return -ENOMEM;
+
+ /*
+ * Get device specific data(name, groups and registers) from
+ * of_match table.
+ */
+ data = (struct ti_lmu_hwmon_data *)match->data;
+ hwmon->lmu = lmu;
+ hwmon->regs = data->regs;
+
+ hwmon->dev = devm_hwmon_device_register_with_groups(dev, data->name,
+ hwmon, data->groups);
+
+ return PTR_ERR_OR_ZERO(hwmon->dev);
+}
+
+static struct platform_driver ti_lmu_hwmon_driver = {
+ .probe = ti_lmu_hwmon_probe,
+ .driver = {
+ .name = "ti-lmu-hwmon",
+ .of_match_table = ti_lmu_hwmon_of_match,
+ },
+};
+
+module_platform_driver(ti_lmu_hwmon_driver);
+
+MODULE_DESCRIPTION("TI LMU Hardware Fault Monitoring Driver");
+MODULE_AUTHOR("Milo Kim");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:ti-lmu-hwmon");
--
1.9.1

2015-11-02 05:26:16

by Kim, Milo

[permalink] [raw]
Subject: [PATCH RESEND 15/16] leds: add LM3633 driver

LM3633 LED driver supports generic LED functions and pattern generation.
Pattern is generated through the sysfs. ABI documentation is also added.

Device creation from device tree
--------------------------------
LED channel name, LED string usage and max current settings are
configured inside the DT.

LED dimming pattern generation
------------------------------
LM3633 supports programmable dimming pattern generator.
To enable it, three attributes are used.
'pattern_times', 'pattern_levels' and 'run_pattern'.
Sysfs ABI describes it.

LMU HWMON event handling
------------------------
As soon as LMU HWMON operation is done, LMU HWMON driver sends the event,
'LMU_EVENT_HWMON_DONE'. Then, LM3633 device should be reinitialized
because the device was reset by LMU HWMON driver.
lm3633_led_hwmon_notifier() handles this event.

Data structure
--------------
ti_lmu_led_chip: LED device data.
ti_lmu_led: LED output channel data.
One LED device can have multiple LED channels.

Cc: Jacek Anaszewski <[email protected]>
Cc: [email protected]
Cc: Lee Jones <[email protected]>
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Milo Kim <[email protected]>
---
Documentation/ABI/testing/sysfs-class-led-lm3633 | 60 ++
drivers/leds/Kconfig | 10 +
drivers/leds/Makefile | 1 +
drivers/leds/leds-lm3633.c | 749 +++++++++++++++++++++++
4 files changed, 820 insertions(+)
create mode 100644 Documentation/ABI/testing/sysfs-class-led-lm3633
create mode 100644 drivers/leds/leds-lm3633.c

diff --git a/Documentation/ABI/testing/sysfs-class-led-lm3633 b/Documentation/ABI/testing/sysfs-class-led-lm3633
new file mode 100644
index 0000000..c1d8759
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-class-led-lm3633
@@ -0,0 +1,60 @@
+LM3633 LED driver generates programmable pattern via the sysfs.
+
+LED Pattern Generator Structure
+
+ (3)
+ (a) ---------------> ___________
+ / \
+ (2) / \ (4)
+ (b) ----> _________/ \_________ ...
+ (1) (5)
+
+ |<----- period -----> |
+
+What: /sys/class/leds/<led>/pattern_times
+Date: Oct 2015
+KernelVersion: 4.3
+Contact: Milo Kim <[email protected]>
+Description: read/write
+ Set pattern time dimension. There are five arguments.
+ (1) startup delay
+ (2) rising dimming time
+ (3) how much time stays at high level
+ (4) falling dimming time
+ (5) how much time stays at low level
+ Ranges are
+ (1), (3), (5): 0 ~ 10000. Unit is millisecond.
+ (2), (4): 0 ~ 16000. Unit is millisecond.
+
+ Example:
+ No delay, rising 200ms, high 300ms, falling 100ms, low 400ms.
+ echo "0 200 300 100 400" > /sys/class/leds/<led>/pattern_times
+
+ cat /sys/class/leds/<led>/pattern_times
+ delay: 0, rise: 200, high: 300, fall: 100, low: 400
+
+What: /sys/class/leds/<led>/pattern_levels
+Date: Oct 2015
+KernelVersion: 4.3
+Contact: Milo Kim <[email protected]>
+Description: read/write
+ Set pattern level(brightness). There are two arguments.
+ (a) Low brightness level
+ (b) High brightness level
+ Ranges are from 0 to 255.
+
+ Example:
+ Low level is 0, high level is 255.
+ echo "0 255" > /sys/class/leds/<led>/pattern_levels
+
+ cat /sys/class/leds/<led>/pattern_levels
+ low brightness: 0, high brightness: 255
+
+What: /sys/class/leds/<led>/run_pattern
+Date: Oct 2015
+KernelVersion: 4.3
+Contact: Milo Kim <[email protected]>
+Description: write only
+ After 'pattern_times' and 'pattern_levels' are updated,
+ run the pattern by writing 1 to 'run_pattern'.
+ To stop running pattern, writes 0 to 'run_pattern'.
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 42990f2..bc41a0e 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -88,6 +88,16 @@ config LEDS_LM3533
hardware-accelerated blinking with maximum on and off periods of 9.8
and 77 seconds respectively.

+config LEDS_LM3633
+ tristate "LED support for the TI LM3633 LMU"
+ depends on LEDS_CLASS
+ depends on MFD_TI_LMU
+ help
+ This option enables support for the LEDs on the LM3633.
+ LM3633 has 6 low voltage indicator LEDs.
+ All low voltage current sinks can have a programmable pattern
+ modulated onto LED output strings.
+
config LEDS_LM3642
tristate "LED support for LM3642 Chip"
depends on LEDS_CLASS && I2C
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index b503f92..984f44a 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -14,6 +14,7 @@ obj-$(CONFIG_LEDS_BD2802) += leds-bd2802.o
obj-$(CONFIG_LEDS_LOCOMO) += leds-locomo.o
obj-$(CONFIG_LEDS_LM3530) += leds-lm3530.o
obj-$(CONFIG_LEDS_LM3533) += leds-lm3533.o
+obj-$(CONFIG_LEDS_LM3633) += leds-lm3633.o
obj-$(CONFIG_LEDS_LM3642) += leds-lm3642.o
obj-$(CONFIG_LEDS_MIKROTIK_RB532) += leds-rb532.o
obj-$(CONFIG_LEDS_S3C24XX) += leds-s3c24xx.o
diff --git a/drivers/leds/leds-lm3633.c b/drivers/leds/leds-lm3633.c
new file mode 100644
index 0000000..66da609
--- /dev/null
+++ b/drivers/leds/leds-lm3633.c
@@ -0,0 +1,749 @@
+/*
+ * TI LM3633 LED driver
+ *
+ * Copyright 2015 Texas Instruments
+ *
+ * Author: Milo Kim <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/kernel.h>
+#include <linux/leds.h>
+#include <linux/mfd/ti-lmu.h>
+#include <linux/mfd/ti-lmu-register.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/notifier.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+
+#define LM3633_LED_MAX_BRIGHTNESS 255
+#define LM3633_DEFAULT_LED_NAME "indicator"
+#define LM3633_MAX_PERIOD 9700
+#define LM3633_SHORT_TIMESTEP 16
+#define LM3633_LONG_TIMESTEP 131
+#define LM3633_TIME_OFFSET 61
+#define LM3633_PATTERN_REG_OFFSET 16
+
+enum lm3633_led_bank_id {
+ LM3633_LED_BANK_C,
+ LM3633_LED_BANK_D,
+ LM3633_LED_BANK_E,
+ LM3633_LED_BANK_F,
+ LM3633_LED_BANK_G,
+ LM3633_LED_BANK_H,
+ LM3633_MAX_LEDS,
+};
+
+struct lm3633_pattern_time {
+ unsigned int delay;
+ unsigned int rise;
+ unsigned int high;
+ unsigned int fall;
+ unsigned int low;
+};
+
+struct lm3633_pattern_level {
+ u8 low;
+ u8 high;
+};
+
+/**
+ * struct ti_lmu_led_chip
+ *
+ * @dev: Parent device pointer
+ * @lmu: LMU structure. Used for register R/W access.
+ * @lock: Secure handling for multiple user interface access
+ * @lmu_led: Multiple LED strings
+ * @num_leds: Number of LED strings
+ * @nb: Notifier block for handling hwmon event
+ *
+ * One LED chip can have multiple LED strings.
+ */
+struct ti_lmu_led_chip {
+ struct device *dev;
+ struct ti_lmu *lmu;
+ struct mutex lock;
+ struct ti_lmu_led *lmu_led;
+ int num_leds;
+ struct notifier_block nb;
+};
+
+/**
+ * struct ti_lmu_led
+ *
+ * @chip: Pointer to parent LED device
+ * @bank_id: LED bank ID
+ * @cdev: LED subsystem device structure
+ * @name: LED channel name
+ * @led_string: LED string configuration.
+ * Bit mask is set on parsing DT.
+ * @imax: [Optional] Max current index.
+ * It's result of ti_lmu_get_current_code().
+ * @work: Used for scheduling brightness control
+ * @brightness: Brightness value
+ * @time: Pattern time dimension
+ * @level: Pattern level dimension
+ *
+ * Each LED device has its own channel configuration.
+ * For chip control, parent chip data structure is used.
+ */
+struct ti_lmu_led {
+ struct ti_lmu_led_chip *chip;
+ enum lm3633_led_bank_id bank_id;
+ struct led_classdev cdev;
+ const char *name;
+
+ unsigned long led_string; /* bit OR mask of LMU_LVLEDx */;
+ #define LMU_LVLED1 BIT(0)
+ #define LMU_LVLED2 BIT(1)
+ #define LMU_LVLED3 BIT(2)
+ #define LMU_LVLED4 BIT(3)
+ #define LMU_LVLED5 BIT(4)
+ #define LMU_LVLED6 BIT(5)
+
+ struct work_struct work;
+ enum led_brightness brightness;
+ enum ti_lmu_max_current imax;
+
+ /* Pattern specific data */
+ struct lm3633_pattern_time time;
+ struct lm3633_pattern_level level;
+};
+
+static struct ti_lmu_led *to_ti_lmu_led(struct device *dev)
+{
+ struct led_classdev *cdev = dev_get_drvdata(dev);
+
+ return container_of(cdev, struct ti_lmu_led, cdev);
+}
+
+static u8 lm3633_led_get_enable_mask(struct ti_lmu_led *lmu_led)
+{
+ return 1 << (lmu_led->bank_id + LM3633_LED_BANK_OFFSET);
+}
+
+static int lm3633_led_enable_bank(struct ti_lmu_led *lmu_led)
+{
+ u8 mask = lm3633_led_get_enable_mask(lmu_led);
+
+ return ti_lmu_update_bits(lmu_led->chip->lmu, LM3633_REG_ENABLE,
+ mask, mask);
+}
+
+static int lm3633_led_disable_bank(struct ti_lmu_led *lmu_led)
+{
+ u8 mask = lm3633_led_get_enable_mask(lmu_led);
+
+ return ti_lmu_update_bits(lmu_led->chip->lmu, LM3633_REG_ENABLE,
+ mask, 0);
+}
+
+static int lm3633_led_enable_pattern(struct ti_lmu_led *lmu_led)
+{
+ u8 mask = lm3633_led_get_enable_mask(lmu_led);
+
+ return ti_lmu_update_bits(lmu_led->chip->lmu, LM3633_REG_PATTERN, mask,
+ mask);
+}
+
+static int lm3633_led_disable_pattern(struct ti_lmu_led *lmu_led)
+{
+ u8 mask = lm3633_led_get_enable_mask(lmu_led);
+
+ return ti_lmu_update_bits(lmu_led->chip->lmu, LM3633_REG_PATTERN, mask,
+ 0);
+}
+
+static int lm3633_led_config_bank(struct ti_lmu_led *lmu_led)
+{
+ const u8 group_led[] = { 0, BIT(0), BIT(0), 0, BIT(3), BIT(3), };
+ const enum lm3633_led_bank_id default_id[] = {
+ LM3633_LED_BANK_C, LM3633_LED_BANK_C, LM3633_LED_BANK_C,
+ LM3633_LED_BANK_F, LM3633_LED_BANK_F, LM3633_LED_BANK_F,
+ };
+ const enum lm3633_led_bank_id separate_id[] = {
+ LM3633_LED_BANK_C, LM3633_LED_BANK_D, LM3633_LED_BANK_E,
+ LM3633_LED_BANK_F, LM3633_LED_BANK_G, LM3633_LED_BANK_H,
+ };
+ int i, ret;
+ u8 val;
+
+ /*
+ * Check configured LED string and assign control bank
+ *
+ * Each LED is tied with other LEDS (group):
+ * the default control bank is assigned
+ *
+ * Otherwise:
+ * separate bank is assigned
+ */
+
+ for (i = 0; i < LM3633_MAX_LEDS; i++) {
+ /* LED 0 and LED 3 are fixed, so no assignment is required */
+ if (i == 0 || i == 3)
+ continue;
+
+ if (test_bit(i, &lmu_led->led_string)) {
+ if (lmu_led->led_string & group_led[i]) {
+ lmu_led->bank_id = default_id[i];
+ val = 0;
+ } else {
+ lmu_led->bank_id = separate_id[i];
+ val = BIT(i);
+ }
+
+ ret = ti_lmu_update_bits(lmu_led->chip->lmu,
+ LM3633_REG_BANK_SEL,
+ BIT(i), val);
+ if (ret)
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
+static ssize_t lm3633_led_show_pattern_times(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct ti_lmu_led *lmu_led = to_ti_lmu_led(dev);
+
+ return sprintf(buf,
+ "delay: %u, rise: %u, high: %u, fall: %u, low: %u\n",
+ lmu_led->time.delay, lmu_led->time.rise,
+ lmu_led->time.high, lmu_led->time.fall,
+ lmu_led->time.low);
+}
+
+static u8 lm3633_convert_time_to_index(unsigned int msec)
+{
+ u8 idx, offset;
+
+ /*
+ * Find appropriate register index around input time value
+ *
+ * 0 <= time <= 1000 : 16ms step
+ * 1000 < time <= 9700 : 131ms step, base index is 61
+ */
+
+ msec = min_t(int, msec, LM3633_MAX_PERIOD);
+
+ if (msec <= 1000) {
+ idx = msec / LM3633_SHORT_TIMESTEP;
+ if (idx > 1)
+ idx--;
+ offset = 0;
+ } else {
+ idx = (msec - 1000) / LM3633_LONG_TIMESTEP;
+ offset = LM3633_TIME_OFFSET;
+ }
+
+ return idx + offset;
+}
+
+static u8 lm3633_convert_ramp_to_index(unsigned int msec)
+{
+ const int ramp_table[] = { 2, 250, 500, 1000, 2000, 4000, 8000, 16000 };
+ int size = ARRAY_SIZE(ramp_table);
+ int i;
+
+ if (msec <= ramp_table[0])
+ return 0;
+
+ if (msec > ramp_table[size - 1])
+ return size - 1;
+
+ for (i = 1; i < size; i++) {
+ if (msec == ramp_table[i])
+ return i;
+
+ /* Find the most closest value by looking up the table */
+ if (msec > ramp_table[i - 1] && msec < ramp_table[i]) {
+ if (msec - ramp_table[i - 1] < ramp_table[i] - msec)
+ return i - 1;
+ else
+ return i;
+ }
+ }
+
+ return 0;
+}
+
+static ssize_t lm3633_led_store_pattern_times(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t len)
+{
+ struct ti_lmu_led *lmu_led = to_ti_lmu_led(dev);
+ struct ti_lmu_led_chip *chip = lmu_led->chip;
+ struct lm3633_pattern_time *time = &lmu_led->time;
+ u8 offset = lmu_led->bank_id * LM3633_PATTERN_REG_OFFSET;
+ int ret;
+ u8 reg, val;
+
+ /*
+ * Sequence
+ *
+ * 1) Read pattern time data (unit: msec)
+ * 2) Update DELAY register
+ * 3) Update HIGH TIME register
+ * 4) Update LOW TIME register
+ * 5) Update RAMP TIME registers
+ *
+ * Time register addresses need offset number based on the LED bank.
+ * Register values are index domain, so input time value should be
+ * converted to index.
+ * Please note that ramp register address has no offset value.
+ */
+
+ ret = sscanf(buf, "%u %u %u %u %u", &time->delay, &time->rise,
+ &time->high, &time->fall, &time->low);
+ if (ret != 5)
+ return -EINVAL;
+
+ mutex_lock(&chip->lock);
+
+ reg = LM3633_REG_PTN_DELAY + offset;
+ val = lm3633_convert_time_to_index(time->delay);
+ ret = ti_lmu_write_byte(chip->lmu, reg, val);
+ if (ret)
+ goto skip;
+
+ reg = LM3633_REG_PTN_HIGHTIME + offset;
+ val = lm3633_convert_time_to_index(time->high);
+ ret = ti_lmu_write_byte(chip->lmu, reg, val);
+ if (ret)
+ goto skip;
+
+ reg = LM3633_REG_PTN_LOWTIME + offset;
+ val = lm3633_convert_time_to_index(time->low);
+ ret = ti_lmu_write_byte(chip->lmu, reg, val);
+ if (ret)
+ goto skip;
+
+ switch (lmu_led->bank_id) {
+ case LM3633_LED_BANK_C:
+ case LM3633_LED_BANK_D:
+ case LM3633_LED_BANK_E:
+ reg = LM3633_REG_PTN0_RAMP;
+ break;
+ case LM3633_LED_BANK_F:
+ case LM3633_LED_BANK_G:
+ case LM3633_LED_BANK_H:
+ reg = LM3633_REG_PTN1_RAMP;
+ break;
+ default:
+ ret = -EINVAL;
+ goto skip;
+ }
+
+ val = lm3633_convert_ramp_to_index(time->rise);
+ ret = ti_lmu_update_bits(chip->lmu, reg, LM3633_PTN_RAMPUP_MASK,
+ val << LM3633_PTN_RAMPUP_SHIFT);
+ if (ret)
+ goto skip;
+
+ val = lm3633_convert_ramp_to_index(time->fall);
+ ret = ti_lmu_update_bits(chip->lmu, reg, LM3633_PTN_RAMPDN_MASK,
+ val << LM3633_PTN_RAMPDN_SHIFT);
+ if (ret)
+ goto skip;
+
+ mutex_unlock(&chip->lock);
+ return len;
+
+skip:
+ mutex_unlock(&chip->lock);
+ return ret;
+}
+
+static ssize_t lm3633_led_show_pattern_levels(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct ti_lmu_led *lmu_led = to_ti_lmu_led(dev);
+
+ return sprintf(buf, "low brightness: %u, high brightness: %u\n",
+ lmu_led->level.low, lmu_led->level.high);
+}
+
+static ssize_t lm3633_led_store_pattern_levels(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t len)
+{
+ struct ti_lmu_led *lmu_led = to_ti_lmu_led(dev);
+ struct ti_lmu_led_chip *chip = lmu_led->chip;
+ unsigned int low, high;
+ u8 reg, offset, val;
+ int ret;
+
+ /*
+ * Sequence
+ *
+ * 1) Read pattern level data
+ * 2) Disable a bank before programming a pattern
+ * 3) Update LOW BRIGHTNESS register
+ * 4) Update HIGH BRIGHTNESS register
+ *
+ * Level register addresses have offset number based on the LED bank.
+ */
+
+ ret = sscanf(buf, "%u %u", &low, &high);
+ if (ret != 2)
+ return -EINVAL;
+
+ low = min_t(unsigned int, low, LM3633_LED_MAX_BRIGHTNESS);
+ high = min_t(unsigned int, high, LM3633_LED_MAX_BRIGHTNESS);
+ lmu_led->level.low = (u8)low;
+ lmu_led->level.high = (u8)high;
+
+ mutex_lock(&chip->lock);
+ ret = lm3633_led_disable_bank(lmu_led);
+ if (ret)
+ goto skip;
+
+ offset = lmu_led->bank_id * LM3633_PATTERN_REG_OFFSET;
+ reg = LM3633_REG_PTN_LOWBRT + offset;
+ val = lmu_led->level.low;
+ ret = ti_lmu_write_byte(chip->lmu, reg, val);
+ if (ret)
+ goto skip;
+
+ offset = lmu_led->bank_id;
+ reg = LM3633_REG_PTN_HIGHBRT + offset;
+ val = lmu_led->level.high;
+ ret = ti_lmu_write_byte(chip->lmu, reg, val);
+ if (ret)
+ goto skip;
+
+ mutex_unlock(&chip->lock);
+ return len;
+
+skip:
+ mutex_unlock(&chip->lock);
+ return ret;
+}
+
+static ssize_t lm3633_led_run_pattern(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t len)
+{
+ struct ti_lmu_led *lmu_led = to_ti_lmu_led(dev);
+ struct ti_lmu_led_chip *chip = lmu_led->chip;
+ unsigned long enable;
+ int ret;
+
+ if (kstrtoul(buf, 0, &enable))
+ return -EINVAL;
+
+ mutex_lock(&chip->lock);
+
+ if (enable)
+ ret = lm3633_led_enable_pattern(lmu_led);
+ else
+ ret = lm3633_led_disable_pattern(lmu_led);
+
+ if (ret) {
+ mutex_unlock(&chip->lock);
+ return ret;
+ }
+
+ if (enable)
+ lm3633_led_enable_bank(lmu_led);
+
+ mutex_unlock(&chip->lock);
+
+ return len;
+}
+
+static DEVICE_ATTR(pattern_times, S_IRUGO | S_IWUSR,
+ lm3633_led_show_pattern_times,
+ lm3633_led_store_pattern_times);
+static DEVICE_ATTR(pattern_levels, S_IRUGO | S_IWUSR,
+ lm3633_led_show_pattern_levels,
+ lm3633_led_store_pattern_levels);
+static DEVICE_ATTR(run_pattern, S_IWUSR, NULL,
+ lm3633_led_run_pattern);
+
+static struct attribute *lm3633_led_attrs[] = {
+ &dev_attr_pattern_times.attr,
+ &dev_attr_pattern_levels.attr,
+ &dev_attr_run_pattern.attr,
+ NULL,
+};
+ATTRIBUTE_GROUPS(lm3633_led); /* lm3633_led_groups */
+
+static int lm3633_led_set_max_current(struct ti_lmu_led *lmu_led)
+{
+ u8 reg = LM3633_REG_IMAX_LVLED_BASE + lmu_led->bank_id;
+
+ return ti_lmu_write_byte(lmu_led->chip->lmu, reg, lmu_led->imax);
+}
+
+static void lm3633_led_work(struct work_struct *work)
+{
+ struct ti_lmu_led *lmu_led = container_of(work, struct ti_lmu_led,
+ work);
+ struct ti_lmu_led_chip *chip = lmu_led->chip;
+ int ret;
+
+ mutex_lock(&chip->lock);
+
+ ret = ti_lmu_write_byte(chip->lmu,
+ LM3633_REG_BRT_LVLED_BASE + lmu_led->bank_id,
+ lmu_led->brightness);
+ if (ret) {
+ mutex_unlock(&chip->lock);
+ return;
+ }
+
+ if (lmu_led->brightness == 0)
+ lm3633_led_disable_bank(lmu_led);
+ else
+ lm3633_led_enable_bank(lmu_led);
+
+ mutex_unlock(&chip->lock);
+}
+
+static void lm3633_led_brightness_set(struct led_classdev *cdev,
+ enum led_brightness brt_val)
+{
+ struct ti_lmu_led *lmu_led = container_of(cdev, struct ti_lmu_led,
+ cdev);
+
+ lmu_led->brightness = brt_val;
+ schedule_work(&lmu_led->work);
+}
+
+static int lm3633_led_init(struct ti_lmu_led *lmu_led, int bank_id)
+{
+ struct device *dev = lmu_led->chip->dev;
+ char name[12];
+ int ret;
+
+ /*
+ * Sequence
+ *
+ * 1) Configure LED bank which is used for brightness control
+ * 2) Set max current for each output channel
+ * 3) Add LED device
+ */
+
+ ret = lm3633_led_config_bank(lmu_led);
+ if (ret) {
+ dev_err(dev, "Output bank register err: %d\n", ret);
+ return ret;
+ }
+
+ ret = lm3633_led_set_max_current(lmu_led);
+ if (ret) {
+ dev_err(dev, "Set max current err: %d\n", ret);
+ return ret;
+ }
+
+ lmu_led->cdev.max_brightness = LM3633_LED_MAX_BRIGHTNESS;
+ lmu_led->cdev.brightness_set = lm3633_led_brightness_set;
+ lmu_led->cdev.groups = lm3633_led_groups;
+
+ if (lmu_led->name) {
+ lmu_led->cdev.name = lmu_led->name;
+ } else {
+ snprintf(name, sizeof(name), "%s:%d", LM3633_DEFAULT_LED_NAME,
+ bank_id);
+ lmu_led->cdev.name = name;
+ }
+
+ ret = led_classdev_register(dev, &lmu_led->cdev);
+ if (ret) {
+ dev_err(dev, "LED register err: %d\n", ret);
+ return ret;
+ }
+
+ INIT_WORK(&lmu_led->work, lm3633_led_work);
+
+ return 0;
+}
+
+static int lm3633_led_of_create(struct ti_lmu_led_chip *chip,
+ struct device_node *np)
+{
+ struct device_node *child;
+ struct device *dev = chip->dev;
+ struct ti_lmu_led *lmu_led, *each;
+ int num_leds;
+ int i = 0;
+ u32 imax;
+
+ if (!np)
+ return -ENODEV;
+
+ num_leds = of_get_child_count(np);
+ if (num_leds == 0 || num_leds > LM3633_MAX_LEDS) {
+ dev_err(dev, "Invalid number of LEDs: %d\n", num_leds);
+ return -EINVAL;
+ }
+
+ lmu_led = devm_kzalloc(dev, sizeof(*lmu_led) * num_leds, GFP_KERNEL);
+ if (!lmu_led)
+ return -ENOMEM;
+
+ for_each_child_of_node(np, child) {
+ each = lmu_led + i;
+
+ of_property_read_string(child, "channel-name", &each->name);
+
+ /* Make LED strings */
+ each->led_string = 0;
+ if (of_property_read_bool(child, "lvled1-used"))
+ each->led_string |= LMU_LVLED1;
+ if (of_property_read_bool(child, "lvled2-used"))
+ each->led_string |= LMU_LVLED2;
+ if (of_property_read_bool(child, "lvled3-used"))
+ each->led_string |= LMU_LVLED3;
+ if (of_property_read_bool(child, "lvled4-used"))
+ each->led_string |= LMU_LVLED4;
+ if (of_property_read_bool(child, "lvled5-used"))
+ each->led_string |= LMU_LVLED5;
+ if (of_property_read_bool(child, "lvled6-used"))
+ each->led_string |= LMU_LVLED6;
+
+ imax = 0;
+ of_property_read_u32(child, "led-max-microamp", &imax);
+ each->imax = ti_lmu_get_current_code(imax);
+
+ each->bank_id = 0;
+ each->chip = chip;
+ i++;
+ }
+
+ chip->lmu_led = lmu_led;
+ chip->num_leds = num_leds;
+
+ return 0;
+}
+
+static int lm3633_led_hwmon_notifier(struct notifier_block *nb,
+ unsigned long action, void *unused)
+{
+ struct ti_lmu_led_chip *chip = container_of(nb, struct ti_lmu_led_chip,
+ nb);
+ struct ti_lmu_led *each;
+ int i, ret;
+
+ /* LED should be reconfigured after hwmon procedure is done */
+ if (action == LMU_EVENT_HWMON_DONE) {
+ for (i = 0; i < chip->num_leds; i++) {
+ each = chip->lmu_led + i;
+ ret = lm3633_led_config_bank(each);
+ if (ret) {
+ dev_err(chip->dev,
+ "Output bank register err: %d\n", ret);
+ return NOTIFY_STOP;
+ }
+
+ ret = lm3633_led_set_max_current(each);
+ if (ret) {
+ dev_err(chip->dev, "Set max current err: %d\n",
+ ret);
+ return NOTIFY_STOP;
+ }
+ }
+ }
+
+ return NOTIFY_OK;
+}
+
+static int lm3633_led_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct ti_lmu *lmu = dev_get_drvdata(dev->parent);
+ struct ti_lmu_led_chip *chip;
+ struct ti_lmu_led *each;
+ int i, ret;
+
+ chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
+ if (!chip)
+ return -ENOMEM;
+
+ chip->dev = dev;
+ chip->lmu = lmu;
+
+ ret = lm3633_led_of_create(chip, dev->of_node);
+ if (ret)
+ return ret;
+
+ /*
+ * Notifier callback is required because LED device needs
+ * reconfiguration after opened/shorted circuit fault monitoring
+ * by ti-lmu-hwmon driver.
+ */
+ chip->nb.notifier_call = lm3633_led_hwmon_notifier;
+ ret = blocking_notifier_chain_register(&chip->lmu->notifier, &chip->nb);
+ if (ret)
+ return ret;
+
+ for (i = 0; i < chip->num_leds; i++) {
+ each = chip->lmu_led + i;
+ ret = lm3633_led_init(each, i);
+ if (ret) {
+ dev_err(dev, "LED initialization err: %d\n", ret);
+ goto cleanup_leds;
+ }
+ }
+
+ mutex_init(&chip->lock);
+ platform_set_drvdata(pdev, chip);
+
+ return 0;
+
+cleanup_leds:
+ while (--i >= 0) {
+ each = chip->lmu_led + i;
+ led_classdev_unregister(&each->cdev);
+ }
+ return ret;
+}
+
+static int lm3633_led_remove(struct platform_device *pdev)
+{
+ struct ti_lmu_led_chip *chip = platform_get_drvdata(pdev);
+ struct ti_lmu_led *each;
+ int i;
+
+ blocking_notifier_chain_unregister(&chip->lmu->notifier, &chip->nb);
+
+ for (i = 0; i < chip->num_leds; i++) {
+ each = chip->lmu_led + i;
+ led_classdev_unregister(&each->cdev);
+ flush_work(&each->work);
+ }
+
+ return 0;
+}
+
+static const struct of_device_id lm3633_led_of_match[] = {
+ { .compatible = "ti,lm3633-leds" },
+ { }
+};
+MODULE_DEVICE_TABLE(of, lm3633_led_of_match);
+
+static struct platform_driver lm3633_led_driver = {
+ .probe = lm3633_led_probe,
+ .remove = lm3633_led_remove,
+ .driver = {
+ .name = "lm3633-leds",
+ .of_match_table = lm3633_led_of_match,
+ },
+};
+
+module_platform_driver(lm3633_led_driver);
+
+MODULE_DESCRIPTION("TI LM3633 LED Driver");
+MODULE_AUTHOR("Milo Kim");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:lm3633-leds");
--
1.9.1

2015-11-02 05:26:19

by Kim, Milo

[permalink] [raw]
Subject: [PATCH RESEND 16/16] regulator: add LM363X driver

LM363X regulator driver supports LM3631 and LM3632.
LM3631 has 5 regulators. LM3632 provides 3 regulators.
One boost output and LDOs are used for the display module.
Boost voltage is configurable but always on.
Supported operations for LDOs are enabled/disabled and voltage change.

Two LDOs of LM3632 can be controlled by external pins.
Those are described in the device tree bindings.

Cc: Mark Brown <[email protected]>
Cc: Lee Jones <[email protected]>
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Milo Kim <[email protected]>
---
drivers/regulator/Kconfig | 9 +
drivers/regulator/Makefile | 1 +
drivers/regulator/lm363x-regulator.c | 349 +++++++++++++++++++++++++++++++++++
3 files changed, 359 insertions(+)
create mode 100644 drivers/regulator/lm363x-regulator.c

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 64bccff..efac1eb 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -274,6 +274,15 @@ config REGULATOR_ISL6271A
help
This driver supports ISL6271A voltage regulator chip.

+config REGULATOR_LM363X
+ tristate "TI LM363X voltage regulators"
+ depends on MFD_TI_LMU
+ help
+ This driver supports LM3631 and LM3632 voltage regulators for
+ the LCD bias.
+ One boost output voltage is configurable and always on.
+ Other LDOs are used for the display module.
+
config REGULATOR_LP3971
tristate "National Semiconductors LP3971 PMIC regulator driver"
depends on I2C
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 0f81749..0ea87cd 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -36,6 +36,7 @@ obj-$(CONFIG_REGULATOR_GPIO) += gpio-regulator.o
obj-$(CONFIG_REGULATOR_HI6421) += hi6421-regulator.o
obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o
obj-$(CONFIG_REGULATOR_ISL9305) += isl9305.o
+obj-$(CONFIG_REGULATOR_LM363X) += lm363x-regulator.o
obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o
obj-$(CONFIG_REGULATOR_LP3972) += lp3972.o
obj-$(CONFIG_REGULATOR_LP872X) += lp872x.o
diff --git a/drivers/regulator/lm363x-regulator.c b/drivers/regulator/lm363x-regulator.c
new file mode 100644
index 0000000..28408d4
--- /dev/null
+++ b/drivers/regulator/lm363x-regulator.c
@@ -0,0 +1,349 @@
+/*
+ * TI LM363X Regulator Driver
+ *
+ * Copyright 2015 Texas Instruments
+ *
+ * Author: Milo Kim <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/err.h>
+#include <linux/kernel.h>
+#include <linux/mfd/ti-lmu.h>
+#include <linux/mfd/ti-lmu-register.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_gpio.h>
+#include <linux/platform_device.h>
+#include <linux/regulator/driver.h>
+#include <linux/regulator/of_regulator.h>
+#include <linux/slab.h>
+
+/* LM3631 */
+#define LM3631_BOOST_VSEL_MAX 0x25
+#define LM3631_LDO_VSEL_MAX 0x28
+#define LM3631_CONT_VSEL_MAX 0x03
+#define LM3631_VBOOST_MIN 4500000
+#define LM3631_VCONT_MIN 1800000
+#define LM3631_VLDO_MIN 4000000
+#define ENABLE_TIME_USEC 1000
+
+/* LM3632 */
+#define LM3632_BOOST_VSEL_MAX 0x26
+#define LM3632_LDO_VSEL_MAX 0x29
+#define LM3632_VBOOST_MIN 4500000
+#define LM3632_VLDO_MIN 4000000
+
+/* Common */
+#define LM363X_STEP_50mV 50000
+#define LM363X_STEP_500mV 500000
+
+struct lm363x_regulator {
+ struct ti_lmu *lmu;
+ struct regulator_dev *regulator;
+};
+
+const int ldo_cont_enable_time[] = {
+ 0, 2000, 5000, 10000, 20000, 50000, 100000, 200000,
+};
+
+static int lm363x_regulator_enable_time(struct regulator_dev *rdev)
+{
+ struct lm363x_regulator *lm363x_regulator = rdev_get_drvdata(rdev);
+ enum lm363x_regulator_id id = rdev_get_id(rdev);
+ u8 val, addr, mask;
+
+ switch (id) {
+ case LM3631_LDO_CONT:
+ addr = LM3631_REG_ENTIME_VCONT;
+ mask = LM3631_ENTIME_CONT_MASK;
+ break;
+ case LM3631_LDO_OREF:
+ addr = LM3631_REG_ENTIME_VOREF;
+ mask = LM3631_ENTIME_MASK;
+ break;
+ case LM3631_LDO_POS:
+ addr = LM3631_REG_ENTIME_VPOS;
+ mask = LM3631_ENTIME_MASK;
+ break;
+ case LM3631_LDO_NEG:
+ addr = LM3631_REG_ENTIME_VNEG;
+ mask = LM3631_ENTIME_MASK;
+ break;
+ default:
+ return 0;
+ }
+
+ if (ti_lmu_read_byte(lm363x_regulator->lmu, addr, &val))
+ return -EINVAL;
+
+ val = (val & mask) >> LM3631_ENTIME_SHIFT;
+
+ if (id == LM3631_LDO_CONT)
+ return ldo_cont_enable_time[val];
+ else
+ return ENABLE_TIME_USEC * val;
+}
+
+static struct regulator_ops lm363x_boost_voltage_table_ops = {
+ .list_voltage = regulator_list_voltage_linear,
+ .set_voltage_sel = regulator_set_voltage_sel_regmap,
+ .get_voltage_sel = regulator_get_voltage_sel_regmap,
+};
+
+static struct regulator_ops lm363x_regulator_voltage_table_ops = {
+ .list_voltage = regulator_list_voltage_linear,
+ .set_voltage_sel = regulator_set_voltage_sel_regmap,
+ .get_voltage_sel = regulator_get_voltage_sel_regmap,
+ .enable = regulator_enable_regmap,
+ .disable = regulator_disable_regmap,
+ .is_enabled = regulator_is_enabled_regmap,
+ .enable_time = lm363x_regulator_enable_time,
+};
+
+static const struct regulator_desc lm363x_regulator_desc[] = {
+ /* LM3631 */
+ {
+ .name = "vboost",
+ .id = LM3631_BOOST,
+ .ops = &lm363x_boost_voltage_table_ops,
+ .n_voltages = LM3631_BOOST_VSEL_MAX + 1,
+ .min_uV = LM3631_VBOOST_MIN,
+ .uV_step = LM363X_STEP_50mV,
+ .type = REGULATOR_VOLTAGE,
+ .owner = THIS_MODULE,
+ .vsel_reg = LM3631_REG_VOUT_BOOST,
+ .vsel_mask = LM3631_VOUT_MASK,
+ },
+ {
+ .name = "ldo_cont",
+ .id = LM3631_LDO_CONT,
+ .ops = &lm363x_regulator_voltage_table_ops,
+ .n_voltages = LM3631_CONT_VSEL_MAX + 1,
+ .min_uV = LM3631_VCONT_MIN,
+ .uV_step = LM363X_STEP_500mV,
+ .type = REGULATOR_VOLTAGE,
+ .owner = THIS_MODULE,
+ .vsel_reg = LM3631_REG_VOUT_CONT,
+ .vsel_mask = LM3631_VOUT_CONT_MASK,
+ .enable_reg = LM3631_REG_LDO_CTRL2,
+ .enable_mask = LM3631_EN_CONT_MASK,
+ },
+ {
+ .name = "ldo_oref",
+ .id = LM3631_LDO_OREF,
+ .ops = &lm363x_regulator_voltage_table_ops,
+ .n_voltages = LM3631_LDO_VSEL_MAX + 1,
+ .min_uV = LM3631_VLDO_MIN,
+ .uV_step = LM363X_STEP_50mV,
+ .type = REGULATOR_VOLTAGE,
+ .owner = THIS_MODULE,
+ .vsel_reg = LM3631_REG_VOUT_OREF,
+ .vsel_mask = LM3631_VOUT_MASK,
+ .enable_reg = LM3631_REG_LDO_CTRL1,
+ .enable_mask = LM3631_EN_OREF_MASK,
+ },
+ {
+ .name = "ldo_vpos",
+ .id = LM3631_LDO_POS,
+ .ops = &lm363x_regulator_voltage_table_ops,
+ .n_voltages = LM3631_LDO_VSEL_MAX + 1,
+ .min_uV = LM3631_VLDO_MIN,
+ .uV_step = LM363X_STEP_50mV,
+ .type = REGULATOR_VOLTAGE,
+ .owner = THIS_MODULE,
+ .vsel_reg = LM3631_REG_VOUT_POS,
+ .vsel_mask = LM3631_VOUT_MASK,
+ .enable_reg = LM3631_REG_LDO_CTRL1,
+ .enable_mask = LM3631_EN_VPOS_MASK,
+ },
+ {
+ .name = "ldo_vneg",
+ .id = LM3631_LDO_NEG,
+ .ops = &lm363x_regulator_voltage_table_ops,
+ .n_voltages = LM3631_LDO_VSEL_MAX + 1,
+ .min_uV = LM3631_VLDO_MIN,
+ .uV_step = LM363X_STEP_50mV,
+ .type = REGULATOR_VOLTAGE,
+ .owner = THIS_MODULE,
+ .vsel_reg = LM3631_REG_VOUT_NEG,
+ .vsel_mask = LM3631_VOUT_MASK,
+ .enable_reg = LM3631_REG_LDO_CTRL1,
+ .enable_mask = LM3631_EN_VNEG_MASK,
+ },
+ /* LM3632 */
+ {
+ .name = "vboost",
+ .id = LM3632_BOOST,
+ .ops = &lm363x_boost_voltage_table_ops,
+ .n_voltages = LM3632_BOOST_VSEL_MAX + 1,
+ .min_uV = LM3632_VBOOST_MIN,
+ .uV_step = LM363X_STEP_50mV,
+ .type = REGULATOR_VOLTAGE,
+ .owner = THIS_MODULE,
+ .vsel_reg = LM3632_REG_VOUT_BOOST,
+ .vsel_mask = LM3632_VOUT_MASK,
+ },
+ {
+ .name = "ldo_vpos",
+ .id = LM3632_LDO_POS,
+ .ops = &lm363x_regulator_voltage_table_ops,
+ .n_voltages = LM3632_LDO_VSEL_MAX + 1,
+ .min_uV = LM3632_VLDO_MIN,
+ .uV_step = LM363X_STEP_50mV,
+ .type = REGULATOR_VOLTAGE,
+ .owner = THIS_MODULE,
+ .vsel_reg = LM3632_REG_VOUT_POS,
+ .vsel_mask = LM3632_VOUT_MASK,
+ .enable_reg = LM3632_REG_BIAS_CONFIG,
+ .enable_mask = LM3632_EN_VPOS_MASK,
+ },
+ {
+ .name = "ldo_vneg",
+ .id = LM3632_LDO_NEG,
+ .ops = &lm363x_regulator_voltage_table_ops,
+ .n_voltages = LM3632_LDO_VSEL_MAX + 1,
+ .min_uV = LM3632_VLDO_MIN,
+ .uV_step = LM363X_STEP_50mV,
+ .type = REGULATOR_VOLTAGE,
+ .owner = THIS_MODULE,
+ .vsel_reg = LM3632_REG_VOUT_NEG,
+ .vsel_mask = LM3632_VOUT_MASK,
+ .enable_reg = LM3632_REG_BIAS_CONFIG,
+ .enable_mask = LM3632_EN_VNEG_MASK,
+ },
+};
+
+static struct of_regulator_match lm363x_regulator_matches[] = {
+ [LM3631_BOOST] = { .name = "vboost" },
+ [LM3631_LDO_CONT] = { .name = "vcont" },
+ [LM3631_LDO_OREF] = { .name = "voref" },
+ [LM3631_LDO_POS] = { .name = "vpos" },
+ [LM3631_LDO_NEG] = { .name = "vneg" },
+ [LM3632_BOOST] = { .name = "vboost" },
+ [LM3632_LDO_POS] = { .name = "vpos" },
+ [LM3632_LDO_NEG] = { .name = "vneg" },
+};
+
+static struct regulator_init_data *
+lm363x_regulator_of_get_init_data(struct device *dev,
+ struct lm363x_regulator *lm363x_regulator, int id)
+{
+ struct device_node *np = dev->of_node;
+ int count;
+
+ count = of_regulator_match(dev, np, &lm363x_regulator_matches[id], 1);
+ if (count <= 0)
+ return ERR_PTR(-ENODEV);
+
+ return lm363x_regulator_matches[id].init_data;
+}
+
+static int lm363x_regulator_of_get_enable_gpio(struct device *dev, int id)
+{
+ struct device_node *np = dev->of_node;
+ int gpio = -1;
+
+ /*
+ * Check LCM_EN1/2_GPIO is configured.
+ * Those pins are used for enabling VPOS/VNEG LDOs.
+ */
+ if (id == LM3632_LDO_POS)
+ gpio = of_get_named_gpio(np, "ti,lcm-en1-gpio", 0);
+ else if (id == LM3632_LDO_NEG)
+ gpio = of_get_named_gpio(np, "ti,lcm-en2-gpio", 0);
+
+ return gpio;
+}
+
+static int lm363x_regulator_probe(struct platform_device *pdev)
+{
+ struct ti_lmu *lmu = dev_get_drvdata(pdev->dev.parent);
+ struct lm363x_regulator *lm363x_regulator;
+ struct regulator_init_data *init_data;
+ struct regulator_config cfg = { };
+ struct regulator_dev *rdev;
+ struct device *dev = &pdev->dev;
+ int id = pdev->id;
+ int ret, ena_gpio;
+
+ lm363x_regulator = devm_kzalloc(dev, sizeof(*lm363x_regulator),
+ GFP_KERNEL);
+ if (!lm363x_regulator)
+ return -ENOMEM;
+
+ lm363x_regulator->lmu = lmu;
+
+ init_data = lm363x_regulator_of_get_init_data(dev, lm363x_regulator,
+ id);
+ if (IS_ERR(init_data))
+ return PTR_ERR(init_data);
+
+ cfg.dev = dev->parent;
+ cfg.init_data = init_data;
+ cfg.driver_data = lm363x_regulator;
+ cfg.regmap = lmu->regmap;
+
+ /*
+ * LM3632 LDOs can be controlled by external pin.
+ * Register update is required if the pin is used.
+ */
+ ena_gpio = lm363x_regulator_of_get_enable_gpio(dev, id);
+ if (gpio_is_valid(ena_gpio)) {
+ cfg.ena_gpio = ena_gpio;
+ cfg.ena_gpio_flags = GPIOF_OUT_INIT_LOW;
+
+ ret = ti_lmu_update_bits(lmu, LM3632_REG_BIAS_CONFIG,
+ LM3632_EXT_EN_MASK,
+ LM3632_EXT_EN_MASK);
+ if (ret) {
+ dev_err(dev, "External pin err: %d\n", ret);
+ return ret;
+ }
+ }
+
+ rdev = regulator_register(&lm363x_regulator_desc[id], &cfg);
+ if (IS_ERR(rdev)) {
+ ret = PTR_ERR(rdev);
+ dev_err(dev, "[%d] regulator register err: %d\n", id, ret);
+ return ret;
+ }
+
+ lm363x_regulator->regulator = rdev;
+ platform_set_drvdata(pdev, lm363x_regulator);
+
+ return 0;
+}
+
+static int lm363x_regulator_remove(struct platform_device *pdev)
+{
+ struct lm363x_regulator *lm363x_regulator = platform_get_drvdata(pdev);
+
+ regulator_unregister(lm363x_regulator->regulator);
+ return 0;
+}
+
+static const struct of_device_id lm363x_regulator_of_match[] = {
+ { .compatible = "ti,lm363x-regulator" },
+ { }
+};
+MODULE_DEVICE_TABLE(of, lm363x_regulator_of_match);
+
+static struct platform_driver lm363x_regulator_driver = {
+ .probe = lm363x_regulator_probe,
+ .remove = lm363x_regulator_remove,
+ .driver = {
+ .name = "lm363x-regulator",
+ .of_match_table = lm363x_regulator_of_match,
+ },
+};
+
+module_platform_driver(lm363x_regulator_driver);
+
+MODULE_DESCRIPTION("TI LM363X Regulator Driver");
+MODULE_AUTHOR("Milo Kim");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:lm363x-regulator");
--
1.9.1

2015-11-02 05:37:54

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH RESEND 08/16] backlight: ti-lmu-backlight: add LM3532 driver

Hi Milo,

[auto build test ERROR on ljones-mfd/for-mfd-next -- if it's inappropriate base, please suggest rules for selecting the more suitable base]

url: https://github.com/0day-ci/linux/commits/Milo-Kim/Support-TI-LMU-devices/20151102-130804
config: mips-allyesconfig (attached as .config)
reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=mips

All errors (new ones prefixed by >>):

In file included from drivers/video/backlight/lm3532_bl.c:14:0:
>> include/linux/mfd/ti-lmu.h:74:32: error: field 'notifier' has incomplete type
struct blocking_notifier_head notifier;
^

vim +/notifier +74 include/linux/mfd/ti-lmu.h

51194f72 Milo Kim 2015-11-02 68 * @notifier: Notifier for reporting hwmon event
51194f72 Milo Kim 2015-11-02 69 */
51194f72 Milo Kim 2015-11-02 70 struct ti_lmu {
51194f72 Milo Kim 2015-11-02 71 struct device *dev;
51194f72 Milo Kim 2015-11-02 72 struct regmap *regmap;
51194f72 Milo Kim 2015-11-02 73 int en_gpio;
51194f72 Milo Kim 2015-11-02 @74 struct blocking_notifier_head notifier;
51194f72 Milo Kim 2015-11-02 75 };
51194f72 Milo Kim 2015-11-02 76
51194f72 Milo Kim 2015-11-02 77 int ti_lmu_read_byte(struct ti_lmu *lmu, u8 reg, u8 *read);

:::::: The code at line 74 was first introduced by commit
:::::: 51194f72221b7b83a8f6a5ba9bf0c49a10233ca2 mfd: add TI LMU driver

:::::: TO: Milo Kim <[email protected]>
:::::: CC: 0day robot <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation


Attachments:
(No filename) (1.77 kB)
.config.gz (38.35 kB)
Download all attachments

2015-11-02 07:34:04

by Kim, Milo

[permalink] [raw]
Subject: Re: [PATCH RESEND 08/16] backlight: ti-lmu-backlight: add LM3532 driver

Ouch! The notifier.h must be included. I didn't notice this error in ARM
architecture. Let me fix this error in next patch-set.
Thanks a lot for catching this!

Best regards,
Milo

diff --git a/include/linux/mfd/ti-lmu.h b/include/linux/mfd/ti-lmu.h
index eeb6b9e..44268c7 100644
--- a/include/linux/mfd/ti-lmu.h
+++ b/include/linux/mfd/ti-lmu.h
@@ -14,6 +14,7 @@
#define __MFD_TI_LMU_H__

#include <linux/gpio.h>
+#include <linux/notifier.h>
#include <linux/regmap.h>

/* Notifier event */

On 11/2/2015 2:37 PM, kbuild test robot wrote:
> Hi Milo,
>
> [auto build test ERROR on ljones-mfd/for-mfd-next -- if it's inappropriate base, please suggest rules for selecting the more suitable base]
>
> url: https://github.com/0day-ci/linux/commits/Milo-Kim/Support-TI-LMU-devices/20151102-130804
> config: mips-allyesconfig (attached as .config)
> reproduce:
> wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
> chmod +x ~/bin/make.cross
> # save the attached .config to linux build tree
> make.cross ARCH=mips
>
> All errors (new ones prefixed by >>):
>
> In file included from drivers/video/backlight/lm3532_bl.c:14:0:
>>> include/linux/mfd/ti-lmu.h:74:32: error: field 'notifier' has incomplete type
> struct blocking_notifier_head notifier;
> ^
>
> vim +/notifier +74 include/linux/mfd/ti-lmu.h
>
> 51194f72 Milo Kim 2015-11-02 68 * @notifier: Notifier for reporting hwmon event
> 51194f72 Milo Kim 2015-11-02 69 */
> 51194f72 Milo Kim 2015-11-02 70 struct ti_lmu {
> 51194f72 Milo Kim 2015-11-02 71 struct device *dev;
> 51194f72 Milo Kim 2015-11-02 72 struct regmap *regmap;
> 51194f72 Milo Kim 2015-11-02 73 int en_gpio;
> 51194f72 Milo Kim 2015-11-02 @74 struct blocking_notifier_head notifier;
> 51194f72 Milo Kim 2015-11-02 75 };
> 51194f72 Milo Kim 2015-11-02 76
> 51194f72 Milo Kim 2015-11-02 77 int ti_lmu_read_byte(struct ti_lmu *lmu, u8 reg, u8 *read);
>
> :::::: The code at line 74 was first introduced by commit
> :::::: 51194f72221b7b83a8f6a5ba9bf0c49a10233ca2 mfd: add TI LMU driver
>
> :::::: TO: Milo Kim <[email protected]>
> :::::: CC: 0day robot <[email protected]>
>
> ---
> 0-DAY kernel test infrastructure Open Source Technology Center
> https://lists.01.org/pipermail/kbuild-all Intel Corporation
>

2015-11-02 08:59:31

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH RESEND 00/16] Support TI LMU devices

On Mon, 02 Nov 2015, Milo Kim wrote:

> TI LMU(Lighting Management Unit) driver supports lighting devices below.
>
> Enable pin Backlights HWMON LEDs Regulators
> ---------- ---------- ----- ---- ------------
> LM3532 o o x x x
> LM3631 o o x x 5 regulators
> LM3632 o o x x 3 regulators
> LM3633 o o o o x
> LM3695 o o x x x
> LM3697 o o o x x
>
> This patch-set consists of several parts below.
>
> DT bindings : Binding information for each module
> TI LMU MFD : Device registration, HW enable pin control and
> I2C register access
> TI LMU backlight : Common driver for TI LMU backlight devices
> Each backlight driver : Chip dependent code
> HWMON : LMU hardware fault monitoring driver
> LM3633 LED : LED subsystem and dimming pattern generation
> supported
> LM363X regulator : LM3631 and LM3632 regulator driver for the
> display bias
>
> Git location:
> Please refer to the location below. Branch name is 'ti-lmu'.
> git clone -b ti-lmu https://github.com/milokim/linux.git
>
> Milo Kim (16):
> Documentation: dt-bindings: mfd: add TI LMU device binding information
> Documentation: dt-bindings: backlight: add TI LMU backlight binding
> information
> Documentation: dt-bindings: hwmon: add TI LMU HWMON binding
> information
> Documentation: dt-bindings: leds: add LM3633 LED binding information
> Documentation: dt-bindings: regulator: add LM363x regulator binding
> information
> mfd: add TI LMU driver
> backlight: add TI LMU backlight common driver
> backlight: ti-lmu-backlight: add LM3532 driver
> backlight: ti-lmu-backlight: add LM3631 driver
> backlight: ti-lmu-backlight: add LM3632 driver
> backlight: ti-lmu-backlight: add LM3633 driver
> backlight: ti-lmu-backlight: add LM3695 driver
> backlight: ti-lmu-backlight: add LM3697 driver
> hwmon: add TI LMU hardware fault monitoring driver
> leds: add LM3633 driver
> regulator: add LM363X driver
>
> Documentation/ABI/testing/sysfs-class-led-lm3633 | 60 ++
> .../devicetree/bindings/hwmon/ti-lmu-hwmon.txt | 12 +
> .../devicetree/bindings/leds/leds-lm3633.txt | 28 +
> Documentation/devicetree/bindings/mfd/ti-lmu.txt | 282 ++++++++
> .../bindings/regulator/lm363x-regulator.txt | 28 +
> .../bindings/video/backlight/ti-lmu-backlight.txt | 67 ++
> drivers/hwmon/Kconfig | 10 +
> drivers/hwmon/Makefile | 1 +
> drivers/hwmon/ti-lmu-hwmon.c | 393 +++++++++++
> drivers/leds/Kconfig | 10 +
> drivers/leds/Makefile | 1 +
> drivers/leds/leds-lm3633.c | 749 +++++++++++++++++++++
> drivers/mfd/Kconfig | 12 +
> drivers/mfd/Makefile | 1 +
> drivers/mfd/ti-lmu.c | 324 +++++++++
> drivers/regulator/Kconfig | 9 +
> drivers/regulator/Makefile | 1 +
> drivers/regulator/lm363x-regulator.c | 349 ++++++++++
> drivers/video/backlight/Kconfig | 62 ++
> drivers/video/backlight/Makefile | 7 +
> drivers/video/backlight/lm3532_bl.c | 183 +++++
> drivers/video/backlight/lm3631_bl.c | 129 ++++
> drivers/video/backlight/lm3632_bl.c | 125 ++++
> drivers/video/backlight/lm3633_bl.c | 210 ++++++
> drivers/video/backlight/lm3695_bl.c | 91 +++
> drivers/video/backlight/lm3697_bl.c | 187 +++++
> drivers/video/backlight/ti-lmu-backlight.c | 429 ++++++++++++
> drivers/video/backlight/ti-lmu-backlight.h | 152 +++++

How different are all of these drivers?

Can you create one driver that supports them all instead?

> include/linux/mfd/ti-lmu-register.h | 277 ++++++++
> include/linux/mfd/ti-lmu.h | 81 +++
> 30 files changed, 4270 insertions(+)
> create mode 100644 Documentation/ABI/testing/sysfs-class-led-lm3633
> create mode 100644 Documentation/devicetree/bindings/hwmon/ti-lmu-hwmon.txt
> create mode 100644 Documentation/devicetree/bindings/leds/leds-lm3633.txt
> create mode 100644 Documentation/devicetree/bindings/mfd/ti-lmu.txt
> create mode 100644 Documentation/devicetree/bindings/regulator/lm363x-regulator.txt
> create mode 100644 Documentation/devicetree/bindings/video/backlight/ti-lmu-backlight.txt
> create mode 100644 drivers/hwmon/ti-lmu-hwmon.c
> create mode 100644 drivers/leds/leds-lm3633.c
> create mode 100644 drivers/mfd/ti-lmu.c
> create mode 100644 drivers/regulator/lm363x-regulator.c
> create mode 100644 drivers/video/backlight/lm3532_bl.c
> create mode 100644 drivers/video/backlight/lm3631_bl.c
> create mode 100644 drivers/video/backlight/lm3632_bl.c
> create mode 100644 drivers/video/backlight/lm3633_bl.c
> create mode 100644 drivers/video/backlight/lm3695_bl.c
> create mode 100644 drivers/video/backlight/lm3697_bl.c
> create mode 100644 drivers/video/backlight/ti-lmu-backlight.c
> create mode 100644 drivers/video/backlight/ti-lmu-backlight.h
> create mode 100644 include/linux/mfd/ti-lmu-register.h
> create mode 100644 include/linux/mfd/ti-lmu.h
>

--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

2015-11-02 09:00:12

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH RESEND 00/16] Support TI LMU devices

Is it just me, or have you missed lots of people off Cc?

> TI LMU(Lighting Management Unit) driver supports lighting devices below.
>
> Enable pin Backlights HWMON LEDs Regulators
> ---------- ---------- ----- ---- ------------
> LM3532 o o x x x
> LM3631 o o x x 5 regulators
> LM3632 o o x x 3 regulators
> LM3633 o o o o x
> LM3695 o o x x x
> LM3697 o o o x x
>
> This patch-set consists of several parts below.
>
> DT bindings : Binding information for each module
> TI LMU MFD : Device registration, HW enable pin control and
> I2C register access
> TI LMU backlight : Common driver for TI LMU backlight devices
> Each backlight driver : Chip dependent code
> HWMON : LMU hardware fault monitoring driver
> LM3633 LED : LED subsystem and dimming pattern generation
> supported
> LM363X regulator : LM3631 and LM3632 regulator driver for the
> display bias
>
> Git location:
> Please refer to the location below. Branch name is 'ti-lmu'.
> git clone -b ti-lmu https://github.com/milokim/linux.git
>
> Milo Kim (16):
> Documentation: dt-bindings: mfd: add TI LMU device binding information
> Documentation: dt-bindings: backlight: add TI LMU backlight binding
> information
> Documentation: dt-bindings: hwmon: add TI LMU HWMON binding
> information
> Documentation: dt-bindings: leds: add LM3633 LED binding information
> Documentation: dt-bindings: regulator: add LM363x regulator binding
> information
> mfd: add TI LMU driver
> backlight: add TI LMU backlight common driver
> backlight: ti-lmu-backlight: add LM3532 driver
> backlight: ti-lmu-backlight: add LM3631 driver
> backlight: ti-lmu-backlight: add LM3632 driver
> backlight: ti-lmu-backlight: add LM3633 driver
> backlight: ti-lmu-backlight: add LM3695 driver
> backlight: ti-lmu-backlight: add LM3697 driver
> hwmon: add TI LMU hardware fault monitoring driver
> leds: add LM3633 driver
> regulator: add LM363X driver
>
> Documentation/ABI/testing/sysfs-class-led-lm3633 | 60 ++
> .../devicetree/bindings/hwmon/ti-lmu-hwmon.txt | 12 +
> .../devicetree/bindings/leds/leds-lm3633.txt | 28 +
> Documentation/devicetree/bindings/mfd/ti-lmu.txt | 282 ++++++++
> .../bindings/regulator/lm363x-regulator.txt | 28 +
> .../bindings/video/backlight/ti-lmu-backlight.txt | 67 ++
> drivers/hwmon/Kconfig | 10 +
> drivers/hwmon/Makefile | 1 +
> drivers/hwmon/ti-lmu-hwmon.c | 393 +++++++++++
> drivers/leds/Kconfig | 10 +
> drivers/leds/Makefile | 1 +
> drivers/leds/leds-lm3633.c | 749 +++++++++++++++++++++
> drivers/mfd/Kconfig | 12 +
> drivers/mfd/Makefile | 1 +
> drivers/mfd/ti-lmu.c | 324 +++++++++
> drivers/regulator/Kconfig | 9 +
> drivers/regulator/Makefile | 1 +
> drivers/regulator/lm363x-regulator.c | 349 ++++++++++
> drivers/video/backlight/Kconfig | 62 ++
> drivers/video/backlight/Makefile | 7 +
> drivers/video/backlight/lm3532_bl.c | 183 +++++
> drivers/video/backlight/lm3631_bl.c | 129 ++++
> drivers/video/backlight/lm3632_bl.c | 125 ++++
> drivers/video/backlight/lm3633_bl.c | 210 ++++++
> drivers/video/backlight/lm3695_bl.c | 91 +++
> drivers/video/backlight/lm3697_bl.c | 187 +++++
> drivers/video/backlight/ti-lmu-backlight.c | 429 ++++++++++++
> drivers/video/backlight/ti-lmu-backlight.h | 152 +++++
> include/linux/mfd/ti-lmu-register.h | 277 ++++++++
> include/linux/mfd/ti-lmu.h | 81 +++
> 30 files changed, 4270 insertions(+)
> create mode 100644 Documentation/ABI/testing/sysfs-class-led-lm3633
> create mode 100644 Documentation/devicetree/bindings/hwmon/ti-lmu-hwmon.txt
> create mode 100644 Documentation/devicetree/bindings/leds/leds-lm3633.txt
> create mode 100644 Documentation/devicetree/bindings/mfd/ti-lmu.txt
> create mode 100644 Documentation/devicetree/bindings/regulator/lm363x-regulator.txt
> create mode 100644 Documentation/devicetree/bindings/video/backlight/ti-lmu-backlight.txt
> create mode 100644 drivers/hwmon/ti-lmu-hwmon.c
> create mode 100644 drivers/leds/leds-lm3633.c
> create mode 100644 drivers/mfd/ti-lmu.c
> create mode 100644 drivers/regulator/lm363x-regulator.c
> create mode 100644 drivers/video/backlight/lm3532_bl.c
> create mode 100644 drivers/video/backlight/lm3631_bl.c
> create mode 100644 drivers/video/backlight/lm3632_bl.c
> create mode 100644 drivers/video/backlight/lm3633_bl.c
> create mode 100644 drivers/video/backlight/lm3695_bl.c
> create mode 100644 drivers/video/backlight/lm3697_bl.c
> create mode 100644 drivers/video/backlight/ti-lmu-backlight.c
> create mode 100644 drivers/video/backlight/ti-lmu-backlight.h
> create mode 100644 include/linux/mfd/ti-lmu-register.h
> create mode 100644 include/linux/mfd/ti-lmu.h
>

--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

2015-11-02 12:26:48

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH RESEND 16/16] regulator: add LM363X driver

On Mon, Nov 02, 2015 at 02:24:35PM +0900, Milo Kim wrote:
> LM363X regulator driver supports LM3631 and LM3632.
> LM3631 has 5 regulators. LM3632 provides 3 regulators.
> One boost output and LDOs are used for the display module.
> Boost voltage is configurable but always on.
> Supported operations for LDOs are enabled/disabled and voltage change.

As far as I can tell this is another partial resend of a series you
originally sent about 15 minutes previously - what's going on here?


Attachments:
(No filename) (487.00 B)
signature.asc (473.00 B)
Download all attachments

2015-11-02 14:27:44

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH RESEND 14/16] hwmon: add TI LMU hardware fault monitoring driver

On 11/01/2015 09:24 PM, Milo Kim wrote:
> LM3633 and LM3697 are TI LMU MFD device.
> Those device have hardware monitoring feature which detects opened or
> shorted circuit case.
>
Sure, but it only makes sense if you provide standard hwmon attributes
which can be interpreted by the "sensors" command. Which is not the case
here. You neither have a standard device type (light is not handled by hwmon),
nor standard attributes, nor do the attributes return standard values.

I think there may be a basic misunderstanding. hwmon is not intended
to monitor a specific chip on the board. Its scope is to monitor the
system (such as temperature, voltages, or current).

In your case, it might be better to attach the attributes to the mfd device.

Thanks,
Guenter

2015-11-02 15:02:58

by Rob Herring (Arm)

[permalink] [raw]
Subject: Re: [PATCH RESEND 02/16] Documentation: dt-bindings: backlight: add TI LMU backlight binding information

On Sun, Nov 1, 2015 at 11:24 PM, Milo Kim <[email protected]> wrote:
> LM3532, LM3631, LM3632, LM3633, LM3695 and LM3697 use common dt-bindings
> for describing device.
>
> Cc: [email protected]
> Cc: Jingoo Han <[email protected]>
> Cc: Lee Jones <[email protected]>
> Cc: [email protected]
> Signed-off-by: Milo Kim <[email protected]>
> ---
> .../bindings/video/backlight/ti-lmu-backlight.txt | 67 ++++++++++++++++++++++

Please move to bindings/leds/backlight/

> 1 file changed, 67 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/video/backlight/ti-lmu-backlight.txt
>
> diff --git a/Documentation/devicetree/bindings/video/backlight/ti-lmu-backlight.txt b/Documentation/devicetree/bindings/video/backlight/ti-lmu-backlight.txt
> new file mode 100644
> index 0000000..27b0036
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/video/backlight/ti-lmu-backlight.txt
> @@ -0,0 +1,67 @@
> +TI LMU backlight device tree bindings
> +
> +Required properties:
> + - compatible: Should be one of lists below.
> + "ti,lm3532-backlight"
> + "ti,lm3631-backlight"
> + "ti,lm3632-backlight"
> + "ti,lm3633-backlight"
> + "ti,lm3695-backlight"
> + "ti,lm3697-backlight"
> +
> +Optional properties:
> + There are two backlight control mode. One is I2C, the other is PWM mode.
> + Following properties are only specified in PWM mode.
> + Please note that LMU backlight device can have only one PWM channel.
> +
> + - pwms: OF device-tree PWM specification.
> + - pwm-names: a list of names for the PWM devices specified in the "pwms"
> + property.
> +
> + For the PWM user nodes, please refer to [1].
> +
> +Child nodes:
> + LMU backlight is represented as sub-nodes of the TI LMU device [2].
> + So, LMU backlight should have more than one backlight child node.
> + Each node exactly matches with backlight control bank configuration.
> + Maximum numbers of child nodes depend on the device.
> + 1 = LM3631, LM3632, LM3695
> + 2 = LM3633, LM3697
> + 3 = LM3532
> +
> + Required property of a child node:
> + - hvled1-used, hvled2-used, hvled3-used:
> + High voltage backlight strings configuration. Type is <boolean>.
> + Please describe which output backlight string is used.
> + Please refer to the datasheets [3].

Use led-sources.

> +
> + Optional properties of a child node:
> + - backlight-name: Name string for backlight device identification.
> + It is used for creating backlight sysfs,
> + /sys/class/backlight/<backlight-name>/.

Use label.

> + - backlight-max-microamp: Max current setting. Type is <u32>.
> + Unit is microampere.
> + Range is from 5000 to 30000.

Use led-max-microamp

> + - initial-brightness: Backlight initial brightness value. Type is <u32>.
> + It is set as soon as backlight device is created.
> + 0 ~ 2047 = LM3631, LM3632, LM3633, LM3695 and LM3697
> + 0 ~ 255 = LM3532

Use default-brightness-level

> + - ramp-up-msec, ramp-down-msec: Light dimming effect properties.
> + Type is <u32>. Unit is millisecond.
> + 0 ~ 65 msec = LM3532
> + 0 ~ 4000 msec = LM3631
> + 0 ~ 16000 msec = LM3633 and LM3697
> + - pwm-period: PWM period. Only valid in PWM brightness mode.
> + Type is <u32>. If this property is missing, then control
> + mode is set to I2C by default.
> +
> +Examples: Please refer to ti-lmu dt-bindings. [2].
> +
> +[1] Documentation/devicetree/bindings/pwm/pwm.txt
> +[2] Documentation/devicetree/bindings/mfd/ti-lmu.txt
> +[3] LM3532: http://www.ti.com/product/LM3532/datasheet
> + LM3631: http://www.ti.com/product/LM3631/datasheet
> + LM3632: http://www.ti.com/product/LM3632A/datasheet
> + LM3633: http://www.ti.com/product/LM3633/datasheet
> + LM3695: Datasheet is not opened yet, but only two strings are used.
> + LM3697: http://www.ti.com/product/LM3697/datasheet
> --
> 1.9.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe devicetree" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

2015-11-03 06:52:44

by Kim, Milo

[permalink] [raw]
Subject: Re: [PATCH RESEND 00/16] Support TI LMU devices

Hi Lee,

On 11/2/2015 5:59 PM, Lee Jones wrote:
>> drivers/video/backlight/Kconfig | 62 ++
>> > drivers/video/backlight/Makefile | 7 +
>> > drivers/video/backlight/lm3532_bl.c | 183 +++++
>> > drivers/video/backlight/lm3631_bl.c | 129 ++++
>> > drivers/video/backlight/lm3632_bl.c | 125 ++++
>> > drivers/video/backlight/lm3633_bl.c | 210 ++++++
>> > drivers/video/backlight/lm3695_bl.c | 91 +++
>> > drivers/video/backlight/lm3697_bl.c | 187 +++++
>> > drivers/video/backlight/ti-lmu-backlight.c | 429 ++++++++++++
>> > drivers/video/backlight/ti-lmu-backlight.h | 152 +++++
> How different are all of these drivers?
>
> Can you create one driver that supports them all instead?
>

Thanks for your suggestion.

'ti-lmu-backlight' is the common part of lmxxxx_bl drivers. And each
lmxxx_bl has its own operation functions by using ti_lmu_bl_ops.
I've tried to make consolidated driver but it contained too much device
specific code in one file. So I prefer simple drivers structure -
'common part' and 'device specific operations'.
It would be appreciated if you could introduce better idea.

Best regards,
Milo

2015-11-03 06:56:36

by Kim, Milo

[permalink] [raw]
Subject: Re: [PATCH RESEND 00/16] Support TI LMU devices

Hi Lee,

On 11/2/2015 6:00 PM, Lee Jones wrote:
> Is it just me, or have you missed lots of people off Cc?

Ah, that's what I was hesitating...
What is the best way to submit MFD code patches? Cc for all people from
get_maintainer.pl?

Best regards,
Milo

2015-11-03 06:59:26

by Kim, Milo

[permalink] [raw]
Subject: Re: [PATCH RESEND 16/16] regulator: add LM363X driver

On 11/2/2015 9:26 PM, Mark Brown wrote:
> On Mon, Nov 02, 2015 at 02:24:35PM +0900, Milo Kim wrote:
>> LM363X regulator driver supports LM3631 and LM3632.
>> LM3631 has 5 regulators. LM3632 provides 3 regulators.
>> One boost output and LDOs are used for the display module.
>> Boost voltage is configurable but always on.
>> Supported operations for LDOs are enabled/disabled and voltage change.
>
> As far as I can tell this is another partial resend of a series you
> originally sent about 15 minutes previously - what's going on here?
>

My apologies, I did send patches without --thread and
--no-chain-reply-to options. So I've resent the patch-set.

Best regards,
Milo

2015-11-03 07:03:12

by Kim, Milo

[permalink] [raw]
Subject: Re: [PATCH RESEND 14/16] hwmon: add TI LMU hardware fault monitoring driver

Hi Guenter,

On 11/2/2015 11:27 PM, Guenter Roeck wrote:
> On 11/01/2015 09:24 PM, Milo Kim wrote:
>> LM3633 and LM3697 are TI LMU MFD device.
>> Those device have hardware monitoring feature which detects opened or
>> shorted circuit case.
>>
> Sure, but it only makes sense if you provide standard hwmon attributes
> which can be interpreted by the "sensors" command. Which is not the case
> here. You neither have a standard device type (light is not handled by hwmon),
> nor standard attributes, nor do the attributes return standard values.
>
> I think there may be a basic misunderstanding. hwmon is not intended
> to monitor a specific chip on the board. Its scope is to monitor the
> system (such as temperature, voltages, or current).
>
> In your case, it might be better to attach the attributes to the mfd device.
>

OK, got your point. Thanks a lot for your suggestion.

Best regards,
Milo

2015-11-03 07:13:32

by Kim, Milo

[permalink] [raw]
Subject: Re: [PATCH RESEND 02/16] Documentation: dt-bindings: backlight: add TI LMU backlight binding information


On 11/3/2015 12:02 AM, Rob Herring wrote:
> On Sun, Nov 1, 2015 at 11:24 PM, Milo Kim <[email protected]> wrote:
>> LM3532, LM3631, LM3632, LM3633, LM3695 and LM3697 use common dt-bindings
>> for describing device.
>>
>> Cc: [email protected]
>> Cc: Jingoo Han <[email protected]>
>> Cc: Lee Jones <[email protected]>
>> Cc: [email protected]
>> Signed-off-by: Milo Kim <[email protected]>
>> ---
>> .../bindings/video/backlight/ti-lmu-backlight.txt | 67 ++++++++++++++++++++++
>
> Please move to bindings/leds/backlight/

There are backlight bindings under video/backlight. I'd like to know why
this 'led' location is preferred. My guess is most of properties are
from common LED properties. Any other reasons?

>
>> 1 file changed, 67 insertions(+)
>> create mode 100644 Documentation/devicetree/bindings/video/backlight/ti-lmu-backlight.txt
>>
>> diff --git a/Documentation/devicetree/bindings/video/backlight/ti-lmu-backlight.txt b/Documentation/devicetree/bindings/video/backlight/ti-lmu-backlight.txt
>> new file mode 100644
>> index 0000000..27b0036
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/video/backlight/ti-lmu-backlight.txt
>> @@ -0,0 +1,67 @@
>> +TI LMU backlight device tree bindings
>> +
>> +Required properties:
>> + - compatible: Should be one of lists below.
>> + "ti,lm3532-backlight"
>> + "ti,lm3631-backlight"
>> + "ti,lm3632-backlight"
>> + "ti,lm3633-backlight"
>> + "ti,lm3695-backlight"
>> + "ti,lm3697-backlight"
>> +
>> +Optional properties:
>> + There are two backlight control mode. One is I2C, the other is PWM mode.
>> + Following properties are only specified in PWM mode.
>> + Please note that LMU backlight device can have only one PWM channel.
>> +
>> + - pwms: OF device-tree PWM specification.
>> + - pwm-names: a list of names for the PWM devices specified in the "pwms"
>> + property.
>> +
>> + For the PWM user nodes, please refer to [1].
>> +
>> +Child nodes:
>> + LMU backlight is represented as sub-nodes of the TI LMU device [2].
>> + So, LMU backlight should have more than one backlight child node.
>> + Each node exactly matches with backlight control bank configuration.
>> + Maximum numbers of child nodes depend on the device.
>> + 1 = LM3631, LM3632, LM3695
>> + 2 = LM3633, LM3697
>> + 3 = LM3532
>> +
>> + Required property of a child node:
>> + - hvled1-used, hvled2-used, hvled3-used:
>> + High voltage backlight strings configuration. Type is <boolean>.
>> + Please describe which output backlight string is used.
>> + Please refer to the datasheets [3].
>
> Use led-sources.

OK.

>
>> +
>> + Optional properties of a child node:
>> + - backlight-name: Name string for backlight device identification.
>> + It is used for creating backlight sysfs,
>> + /sys/class/backlight/<backlight-name>/.
>
> Use label.

Got it.

>
>> + - backlight-max-microamp: Max current setting. Type is <u32>.
>> + Unit is microampere.
>> + Range is from 5000 to 30000.
>
> Use led-max-microamp

OK.

>
>> + - initial-brightness: Backlight initial brightness value. Type is <u32>.
>> + It is set as soon as backlight device is created.
>> + 0 ~ 2047 = LM3631, LM3632, LM3633, LM3695 and LM3697
>> + 0 ~ 255 = LM3532
>
> Use default-brightness-level
>

I'll update the bindings and drivers based on your review. Many thanks!

Best regards,
Milo

2015-11-03 08:33:52

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH RESEND 00/16] Support TI LMU devices

On Tue, 03 Nov 2015, Kim, Milo wrote:

> Hi Lee,
>
> On 11/2/2015 5:59 PM, Lee Jones wrote:
> >> drivers/video/backlight/Kconfig | 62 ++
> >>> drivers/video/backlight/Makefile | 7 +
> >>> drivers/video/backlight/lm3532_bl.c | 183 +++++
> >>> drivers/video/backlight/lm3631_bl.c | 129 ++++
> >>> drivers/video/backlight/lm3632_bl.c | 125 ++++
> >>> drivers/video/backlight/lm3633_bl.c | 210 ++++++
> >>> drivers/video/backlight/lm3695_bl.c | 91 +++
> >>> drivers/video/backlight/lm3697_bl.c | 187 +++++
> >>> drivers/video/backlight/ti-lmu-backlight.c | 429 ++++++++++++
> >>> drivers/video/backlight/ti-lmu-backlight.h | 152 +++++
> >How different are all of these drivers?
> >
> >Can you create one driver that supports them all instead?
> >
>
> Thanks for your suggestion.
>
> 'ti-lmu-backlight' is the common part of lmxxxx_bl drivers. And each
> lmxxx_bl has its own operation functions by using ti_lmu_bl_ops.
> I've tried to make consolidated driver but it contained too much
> device specific code in one file. So I prefer simple drivers
> structure - 'common part' and 'device specific operations'.
> It would be appreciated if you could introduce better idea.

I wish to avoid having to apply the patches to conduct my own analysis
of the files, as I am severely restricted on time. Can you tell me how
much duplicated code there is between the files? How many lines would
be saved by supporting all of the lm* drivers in a single file?

--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

2015-11-03 08:35:46

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH RESEND 00/16] Support TI LMU devices

On Tue, 03 Nov 2015, Kim, Milo wrote:

> Hi Lee,
>
> On 11/2/2015 6:00 PM, Lee Jones wrote:
> >Is it just me, or have you missed lots of people off Cc?
>
> Ah, that's what I was hesitating...
> What is the best way to submit MFD code patches? Cc for all people
> from get_maintainer.pl?

As this is a 0th patch of a set which touches many different
subsystems, I suggest that you should have Cc'ed all of the
Maintainers of the subsystems you changed.

--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

2015-11-03 09:08:24

by Kim, Milo

[permalink] [raw]
Subject: Re: [PATCH RESEND 00/16] Support TI LMU devices


On 11/3/2015 5:33 PM, Lee Jones wrote:
> On Tue, 03 Nov 2015, Kim, Milo wrote:
>
>> Hi Lee,
>>
>> On 11/2/2015 5:59 PM, Lee Jones wrote:
>>>> drivers/video/backlight/Kconfig | 62 ++
>>>>> drivers/video/backlight/Makefile | 7 +
>>>>> drivers/video/backlight/lm3532_bl.c | 183 +++++
>>>>> drivers/video/backlight/lm3631_bl.c | 129 ++++
>>>>> drivers/video/backlight/lm3632_bl.c | 125 ++++
>>>>> drivers/video/backlight/lm3633_bl.c | 210 ++++++
>>>>> drivers/video/backlight/lm3695_bl.c | 91 +++
>>>>> drivers/video/backlight/lm3697_bl.c | 187 +++++
>>>>> drivers/video/backlight/ti-lmu-backlight.c | 429 ++++++++++++
>>>>> drivers/video/backlight/ti-lmu-backlight.h | 152 +++++
>>> How different are all of these drivers?
>>>
>>> Can you create one driver that supports them all instead?
>>>
>>
>> Thanks for your suggestion.
>>
>> 'ti-lmu-backlight' is the common part of lmxxxx_bl drivers. And each
>> lmxxx_bl has its own operation functions by using ti_lmu_bl_ops.
>> I've tried to make consolidated driver but it contained too much
>> device specific code in one file. So I prefer simple drivers
>> structure - 'common part' and 'device specific operations'.
>> It would be appreciated if you could introduce better idea.
>
> I wish to avoid having to apply the patches to conduct my own analysis
> of the files, as I am severely restricted on time. Can you tell me how
> much duplicated code there is between the files? How many lines would
> be saved by supporting all of the lm* drivers in a single file?
>

Understood. Let me try it again. I'll get back to you soon.
Thanks for your help.

Best regards,
Milo

2015-11-03 15:34:00

by Rob Herring (Arm)

[permalink] [raw]
Subject: Re: [PATCH RESEND 02/16] Documentation: dt-bindings: backlight: add TI LMU backlight binding information

On Tue, Nov 3, 2015 at 1:13 AM, Kim, Milo <[email protected]> wrote:
>
> On 11/3/2015 12:02 AM, Rob Herring wrote:
>>
>> On Sun, Nov 1, 2015 at 11:24 PM, Milo Kim <[email protected]> wrote:
>>>
>>> LM3532, LM3631, LM3632, LM3633, LM3695 and LM3697 use common dt-bindings
>>> for describing device.
>>>
>>> Cc: [email protected]
>>> Cc: Jingoo Han <[email protected]>
>>> Cc: Lee Jones <[email protected]>
>>> Cc: [email protected]
>>> Signed-off-by: Milo Kim <[email protected]>
>>> ---
>>> .../bindings/video/backlight/ti-lmu-backlight.txt | 67
>>> ++++++++++++++++++++++
>>
>>
>> Please move to bindings/leds/backlight/
>
>
> There are backlight bindings under video/backlight. I'd like to know why

Not if you look in linux-next.

> this 'led' location is preferred. My guess is most of properties are from
> common LED properties. Any other reasons?

Yes, that is the main reason.

Rob

2015-11-03 16:15:18

by Jacek Anaszewski

[permalink] [raw]
Subject: Re: [PATCH RESEND 04/16] Documentation: dt-bindings: leds: add LM3633 LED binding information

Hi Milo,

Thanks for the patch. Apart from the issues
pointed out by Rob, I have one more suggestion below.

On 11/02/2015 06:24 AM, Milo Kim wrote:
> LM3633 LED device is one of TI LMU device list.
>
> Cc: [email protected]
> Cc: Jacek Anaszewski <[email protected]>
> Cc: Lee Jones <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Signed-off-by: Milo Kim <[email protected]>
> ---
> .../devicetree/bindings/leds/leds-lm3633.txt | 28 ++++++++++++++++++++++
> 1 file changed, 28 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/leds/leds-lm3633.txt
>
> diff --git a/Documentation/devicetree/bindings/leds/leds-lm3633.txt b/Documentation/devicetree/bindings/leds/leds-lm3633.txt
> new file mode 100644
> index 0000000..bb7f213
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/leds/leds-lm3633.txt
> @@ -0,0 +1,28 @@
> +TI LMU LM3633 LED device tree bindings
> +
> +Required properties:
> + - compatible: "ti,lm3633-leds"
> +
> +Child nodes:
> + Each node matches with LED control bank.
> + Please refer to the datasheet [1].
> +
> + Required properties of a child node:
> + - lvled1-used, lvled2-used, lvled3-used,
> + lvled4-used, lvled5-used, lvled6-used:
> + Low voltage LED string configuration. Type is <boolean>.
> + Please describe which output LED string is used.
> +
> + Optional properties of a child node:
> + - channel-name: Name string for LED channel identification
> + It is used for creating LED sysfs,
> + /sys/class/leds/<channel-name>/.
> + If this property is empty, then default name is set to
> + "indicator:<id>" by the driver.
> + - led-max-microamp: Max current setting. Type is <u32>.
> + Unit is microampere. Range is from 5000 to 30000.

Could you specify also a step?

> +Examples: Please refer to ti-lmu dt-bindings [2].
> +
> +[1] http://www.ti.com/product/LM3633/datasheet
> +[2] Documentation/devicetree/bindings/mfd/ti-lmu.txt
>


--
Best Regards,
Jacek Anaszewski

2015-11-03 16:15:31

by Jacek Anaszewski

[permalink] [raw]
Subject: Re: [PATCH RESEND 15/16] leds: add LM3633 driver

Hi Milo,

Thanks for the patch. Please find my comments in the code.

On 11/02/2015 06:24 AM, Milo Kim wrote:
> LM3633 LED driver supports generic LED functions and pattern generation.
> Pattern is generated through the sysfs. ABI documentation is also added.
>
> Device creation from device tree
> --------------------------------
> LED channel name, LED string usage and max current settings are
> configured inside the DT.
>
> LED dimming pattern generation
> ------------------------------
> LM3633 supports programmable dimming pattern generator.
> To enable it, three attributes are used.
> 'pattern_times', 'pattern_levels' and 'run_pattern'.
> Sysfs ABI describes it.
>
> LMU HWMON event handling
> ------------------------
> As soon as LMU HWMON operation is done, LMU HWMON driver sends the event,
> 'LMU_EVENT_HWMON_DONE'. Then, LM3633 device should be reinitialized
> because the device was reset by LMU HWMON driver.
> lm3633_led_hwmon_notifier() handles this event.
>
> Data structure
> --------------
> ti_lmu_led_chip: LED device data.
> ti_lmu_led: LED output channel data.
> One LED device can have multiple LED channels.
>
> Cc: Jacek Anaszewski <[email protected]>
> Cc: [email protected]
> Cc: Lee Jones <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Signed-off-by: Milo Kim <[email protected]>
> ---
> Documentation/ABI/testing/sysfs-class-led-lm3633 | 60 ++
> drivers/leds/Kconfig | 10 +
> drivers/leds/Makefile | 1 +
> drivers/leds/leds-lm3633.c | 749 +++++++++++++++++++++++
> 4 files changed, 820 insertions(+)
> create mode 100644 Documentation/ABI/testing/sysfs-class-led-lm3633
> create mode 100644 drivers/leds/leds-lm3633.c
>
> diff --git a/Documentation/ABI/testing/sysfs-class-led-lm3633 b/Documentation/ABI/testing/sysfs-class-led-lm3633
> new file mode 100644
> index 0000000..c1d8759
> --- /dev/null
> +++ b/Documentation/ABI/testing/sysfs-class-led-lm3633
> @@ -0,0 +1,60 @@
> +LM3633 LED driver generates programmable pattern via the sysfs.
> +
> +LED Pattern Generator Structure
> +
> + (3)
> + (a) ---------------> ___________
> + / \
> + (2) / \ (4)
> + (b) ----> _________/ \_________ ...
> + (1) (5)
> +
> + |<----- period -----> |
> +
> +What: /sys/class/leds/<led>/pattern_times

"time" noun is uncountable.

> +Date: Oct 2015
> +KernelVersion: 4.3

These properties certainly will not appear in 4.3.

> +Contact: Milo Kim <[email protected]>
> +Description: read/write
> + Set pattern time dimension. There are five arguments.
> + (1) startup delay
> + (2) rising dimming time
> + (3) how much time stays at high level
> + (4) falling dimming time
> + (5) how much time stays at low level
> + Ranges are
> + (1), (3), (5): 0 ~ 10000. Unit is millisecond.
> + (2), (4): 0 ~ 16000. Unit is millisecond.
> +
> + Example:
> + No delay, rising 200ms, high 300ms, falling 100ms, low 400ms.
> + echo "0 200 300 100 400" > /sys/class/leds/<led>/pattern_times
> +
> + cat /sys/class/leds/<led>/pattern_times
> + delay: 0, rise: 200, high: 300, fall: 100, low: 400

Generally a sysfs attribute should represent a single value.
There are cases where the attribute comprises a list of space separated
values, but certainly colons and commas adds to much noise, and are
cumbersome to parse. I'd opt for creating a separate sysfs attribute
for each of the above 5 properties.

> +What: /sys/class/leds/<led>/pattern_levels
> +Date: Oct 2015
> +KernelVersion: 4.3
> +Contact: Milo Kim <[email protected]>
> +Description: read/write
> + Set pattern level(brightness). There are two arguments.
> + (a) Low brightness level
> + (b) High brightness level
> + Ranges are from 0 to 255.
> +
> + Example:
> + Low level is 0, high level is 255.
> + echo "0 255" > /sys/class/leds/<led>/pattern_levels

I'd go also for two separate attributes. E.g. pattern_brightness_lo and
pattern_brightness_hi, or maybe you'll have better idea.

> + cat /sys/class/leds/<led>/pattern_levels
> + low brightness: 0, high brightness: 255
> +
> +What: /sys/class/leds/<led>/run_pattern
> +Date: Oct 2015
> +KernelVersion: 4.3
> +Contact: Milo Kim <[email protected]>
> +Description: write only
> + After 'pattern_times' and 'pattern_levels' are updated,
> + run the pattern by writing 1 to 'run_pattern'.
> + To stop running pattern, writes 0 to 'run_pattern'.

I wonder how registering an in-driver trigger would work. It would
allow for hiding above pattern attributes when the trigger is inactive,
and thus making the sysfs interface more transparent. You could avoid
the need for run_pattern attribute, as setting the trigger would itself
activate the pattern, and setting brightness to 0 would turn it off.

> diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
> index 42990f2..bc41a0e 100644
> --- a/drivers/leds/Kconfig
> +++ b/drivers/leds/Kconfig
> @@ -88,6 +88,16 @@ config LEDS_LM3533
> hardware-accelerated blinking with maximum on and off periods of 9.8
> and 77 seconds respectively.
>
> +config LEDS_LM3633
> + tristate "LED support for the TI LM3633 LMU"
> + depends on LEDS_CLASS
> + depends on MFD_TI_LMU
> + help
> + This option enables support for the LEDs on the LM3633.
> + LM3633 has 6 low voltage indicator LEDs.
> + All low voltage current sinks can have a programmable pattern
> + modulated onto LED output strings.
> +
> config LEDS_LM3642
> tristate "LED support for LM3642 Chip"
> depends on LEDS_CLASS && I2C
> diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
> index b503f92..984f44a 100644
> --- a/drivers/leds/Makefile
> +++ b/drivers/leds/Makefile
> @@ -14,6 +14,7 @@ obj-$(CONFIG_LEDS_BD2802) += leds-bd2802.o
> obj-$(CONFIG_LEDS_LOCOMO) += leds-locomo.o
> obj-$(CONFIG_LEDS_LM3530) += leds-lm3530.o
> obj-$(CONFIG_LEDS_LM3533) += leds-lm3533.o
> +obj-$(CONFIG_LEDS_LM3633) += leds-lm3633.o
> obj-$(CONFIG_LEDS_LM3642) += leds-lm3642.o
> obj-$(CONFIG_LEDS_MIKROTIK_RB532) += leds-rb532.o
> obj-$(CONFIG_LEDS_S3C24XX) += leds-s3c24xx.o
> diff --git a/drivers/leds/leds-lm3633.c b/drivers/leds/leds-lm3633.c
> new file mode 100644
> index 0000000..66da609
> --- /dev/null
> +++ b/drivers/leds/leds-lm3633.c
> @@ -0,0 +1,749 @@
> +/*
> + * TI LM3633 LED driver
> + *
> + * Copyright 2015 Texas Instruments
> + *
> + * Author: Milo Kim <[email protected]>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/leds.h>
> +#include <linux/mfd/ti-lmu.h>
> +#include <linux/mfd/ti-lmu-register.h>
> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/notifier.h>
> +#include <linux/of.h>
> +#include <linux/platform_device.h>
> +#include <linux/slab.h>
> +
> +#define LM3633_LED_MAX_BRIGHTNESS 255
> +#define LM3633_DEFAULT_LED_NAME "indicator"
> +#define LM3633_MAX_PERIOD 9700
> +#define LM3633_SHORT_TIMESTEP 16
> +#define LM3633_LONG_TIMESTEP 131
> +#define LM3633_TIME_OFFSET 61
> +#define LM3633_PATTERN_REG_OFFSET 16
> +
> +enum lm3633_led_bank_id {
> + LM3633_LED_BANK_C,
> + LM3633_LED_BANK_D,
> + LM3633_LED_BANK_E,
> + LM3633_LED_BANK_F,
> + LM3633_LED_BANK_G,
> + LM3633_LED_BANK_H,
> + LM3633_MAX_LEDS,
> +};
> +
> +struct lm3633_pattern_time {
> + unsigned int delay;
> + unsigned int rise;
> + unsigned int high;
> + unsigned int fall;
> + unsigned int low;
> +};
> +
> +struct lm3633_pattern_level {
> + u8 low;
> + u8 high;
> +};
> +
> +/**
> + * struct ti_lmu_led_chip
> + *
> + * @dev: Parent device pointer
> + * @lmu: LMU structure. Used for register R/W access.
> + * @lock: Secure handling for multiple user interface access
> + * @lmu_led: Multiple LED strings
> + * @num_leds: Number of LED strings
> + * @nb: Notifier block for handling hwmon event
> + *
> + * One LED chip can have multiple LED strings.
> + */
> +struct ti_lmu_led_chip {
> + struct device *dev;
> + struct ti_lmu *lmu;
> + struct mutex lock;
> + struct ti_lmu_led *lmu_led;
> + int num_leds;
> + struct notifier_block nb;
> +};
> +
> +/**
> + * struct ti_lmu_led
> + *
> + * @chip: Pointer to parent LED device
> + * @bank_id: LED bank ID
> + * @cdev: LED subsystem device structure
> + * @name: LED channel name
> + * @led_string: LED string configuration.
> + * Bit mask is set on parsing DT.
> + * @imax: [Optional] Max current index.
> + * It's result of ti_lmu_get_current_code().

Why is this optional?

> + * @work: Used for scheduling brightness control
> + * @brightness: Brightness value
> + * @time: Pattern time dimension
> + * @level: Pattern level dimension
> + *
> + * Each LED device has its own channel configuration.
> + * For chip control, parent chip data structure is used.
> + */
> +struct ti_lmu_led {
> + struct ti_lmu_led_chip *chip;
> + enum lm3633_led_bank_id bank_id;
> + struct led_classdev cdev;
> + const char *name;
> +
> + unsigned long led_string; /* bit OR mask of LMU_LVLEDx */;
> + #define LMU_LVLED1 BIT(0)
> + #define LMU_LVLED2 BIT(1)
> + #define LMU_LVLED3 BIT(2)
> + #define LMU_LVLED4 BIT(3)
> + #define LMU_LVLED5 BIT(4)
> + #define LMU_LVLED6 BIT(5)
> +
> + struct work_struct work;
> + enum led_brightness brightness;
> + enum ti_lmu_max_current imax;
> +
> + /* Pattern specific data */
> + struct lm3633_pattern_time time;
> + struct lm3633_pattern_level level;
> +};
> +
> +static struct ti_lmu_led *to_ti_lmu_led(struct device *dev)
> +{
> + struct led_classdev *cdev = dev_get_drvdata(dev);
> +
> + return container_of(cdev, struct ti_lmu_led, cdev);
> +}
> +
> +static u8 lm3633_led_get_enable_mask(struct ti_lmu_led *lmu_led)
> +{
> + return 1 << (lmu_led->bank_id + LM3633_LED_BANK_OFFSET);
> +}
> +
> +static int lm3633_led_enable_bank(struct ti_lmu_led *lmu_led)
> +{
> + u8 mask = lm3633_led_get_enable_mask(lmu_led);
> +
> + return ti_lmu_update_bits(lmu_led->chip->lmu, LM3633_REG_ENABLE,
> + mask, mask);
> +}
> +
> +static int lm3633_led_disable_bank(struct ti_lmu_led *lmu_led)
> +{
> + u8 mask = lm3633_led_get_enable_mask(lmu_led);
> +
> + return ti_lmu_update_bits(lmu_led->chip->lmu, LM3633_REG_ENABLE,
> + mask, 0);
> +}
> +
> +static int lm3633_led_enable_pattern(struct ti_lmu_led *lmu_led)
> +{
> + u8 mask = lm3633_led_get_enable_mask(lmu_led);
> +
> + return ti_lmu_update_bits(lmu_led->chip->lmu, LM3633_REG_PATTERN, mask,
> + mask);
> +}
> +
> +static int lm3633_led_disable_pattern(struct ti_lmu_led *lmu_led)
> +{
> + u8 mask = lm3633_led_get_enable_mask(lmu_led);
> +
> + return ti_lmu_update_bits(lmu_led->chip->lmu, LM3633_REG_PATTERN, mask,
> + 0);
> +}
> +
> +static int lm3633_led_config_bank(struct ti_lmu_led *lmu_led)
> +{
> + const u8 group_led[] = { 0, BIT(0), BIT(0), 0, BIT(3), BIT(3), };
> + const enum lm3633_led_bank_id default_id[] = {
> + LM3633_LED_BANK_C, LM3633_LED_BANK_C, LM3633_LED_BANK_C,
> + LM3633_LED_BANK_F, LM3633_LED_BANK_F, LM3633_LED_BANK_F,
> + };
> + const enum lm3633_led_bank_id separate_id[] = {
> + LM3633_LED_BANK_C, LM3633_LED_BANK_D, LM3633_LED_BANK_E,
> + LM3633_LED_BANK_F, LM3633_LED_BANK_G, LM3633_LED_BANK_H,
> + };
> + int i, ret;
> + u8 val;
> +
> + /*
> + * Check configured LED string and assign control bank
> + *
> + * Each LED is tied with other LEDS (group):
> + * the default control bank is assigned
> + *
> + * Otherwise:
> + * separate bank is assigned
> + */
> + for (i = 0; i < LM3633_MAX_LEDS; i++) {
> + /* LED 0 and LED 3 are fixed, so no assignment is required */
> + if (i == 0 || i == 3)
> + continue;
> +
> + if (test_bit(i, &lmu_led->led_string)) {
> + if (lmu_led->led_string & group_led[i]) {
> + lmu_led->bank_id = default_id[i];
> + val = 0;
> + } else {
> + lmu_led->bank_id = separate_id[i];
> + val = BIT(i);
> + }
> +
> + ret = ti_lmu_update_bits(lmu_led->chip->lmu,
> + LM3633_REG_BANK_SEL,
> + BIT(i), val);
> + if (ret)
> + return ret;
> + }
> + }
> +
> + return 0;
> +}
> +
> +static ssize_t lm3633_led_show_pattern_times(struct device *dev,
> + struct device_attribute *attr,
> + char *buf)
> +{
> + struct ti_lmu_led *lmu_led = to_ti_lmu_led(dev);
> +
> + return sprintf(buf,
> + "delay: %u, rise: %u, high: %u, fall: %u, low: %u\n",
> + lmu_led->time.delay, lmu_led->time.rise,
> + lmu_led->time.high, lmu_led->time.fall,
> + lmu_led->time.low);
> +}
> +
> +static u8 lm3633_convert_time_to_index(unsigned int msec)
> +{
> + u8 idx, offset;
> +
> + /*
> + * Find appropriate register index around input time value
> + *
> + * 0 <= time <= 1000 : 16ms step
> + * 1000 < time <= 9700 : 131ms step, base index is 61
> + */
> +
> + msec = min_t(int, msec, LM3633_MAX_PERIOD);
> +
> + if (msec <= 1000) {
> + idx = msec / LM3633_SHORT_TIMESTEP;
> + if (idx > 1)
> + idx--;
> + offset = 0;
> + } else {
> + idx = (msec - 1000) / LM3633_LONG_TIMESTEP;
> + offset = LM3633_TIME_OFFSET;
> + }
> +
> + return idx + offset;
> +}
> +
> +static u8 lm3633_convert_ramp_to_index(unsigned int msec)
> +{
> + const int ramp_table[] = { 2, 250, 500, 1000, 2000, 4000, 8000, 16000 };
> + int size = ARRAY_SIZE(ramp_table);
> + int i;
> +
> + if (msec <= ramp_table[0])
> + return 0;
> +
> + if (msec > ramp_table[size - 1])
> + return size - 1;
> +
> + for (i = 1; i < size; i++) {
> + if (msec == ramp_table[i])
> + return i;
> +
> + /* Find the most closest value by looking up the table */
> + if (msec > ramp_table[i - 1] && msec < ramp_table[i]) {
> + if (msec - ramp_table[i - 1] < ramp_table[i] - msec)
> + return i - 1;
> + else
> + return i;
> + }
> + }
> +
> + return 0;
> +}
> +
> +static ssize_t lm3633_led_store_pattern_times(struct device *dev,
> + struct device_attribute *attr,
> + const char *buf, size_t len)
> +{
> + struct ti_lmu_led *lmu_led = to_ti_lmu_led(dev);
> + struct ti_lmu_led_chip *chip = lmu_led->chip;
> + struct lm3633_pattern_time *time = &lmu_led->time;
> + u8 offset = lmu_led->bank_id * LM3633_PATTERN_REG_OFFSET;
> + int ret;
> + u8 reg, val;
> +
> + /*
> + * Sequence
> + *
> + * 1) Read pattern time data (unit: msec)
> + * 2) Update DELAY register
> + * 3) Update HIGH TIME register
> + * 4) Update LOW TIME register
> + * 5) Update RAMP TIME registers
> + *
> + * Time register addresses need offset number based on the LED bank.
> + * Register values are index domain, so input time value should be
> + * converted to index.
> + * Please note that ramp register address has no offset value.
> + */
> +
> + ret = sscanf(buf, "%u %u %u %u %u", &time->delay, &time->rise,
> + &time->high, &time->fall, &time->low);
> + if (ret != 5)
> + return -EINVAL;
> +
> + mutex_lock(&chip->lock);
> +
> + reg = LM3633_REG_PTN_DELAY + offset;
> + val = lm3633_convert_time_to_index(time->delay);
> + ret = ti_lmu_write_byte(chip->lmu, reg, val);
> + if (ret)
> + goto skip;
> +
> + reg = LM3633_REG_PTN_HIGHTIME + offset;
> + val = lm3633_convert_time_to_index(time->high);
> + ret = ti_lmu_write_byte(chip->lmu, reg, val);
> + if (ret)
> + goto skip;
> +
> + reg = LM3633_REG_PTN_LOWTIME + offset;
> + val = lm3633_convert_time_to_index(time->low);
> + ret = ti_lmu_write_byte(chip->lmu, reg, val);
> + if (ret)
> + goto skip;
> +
> + switch (lmu_led->bank_id) {
> + case LM3633_LED_BANK_C:
> + case LM3633_LED_BANK_D:
> + case LM3633_LED_BANK_E:
> + reg = LM3633_REG_PTN0_RAMP;
> + break;
> + case LM3633_LED_BANK_F:
> + case LM3633_LED_BANK_G:
> + case LM3633_LED_BANK_H:
> + reg = LM3633_REG_PTN1_RAMP;
> + break;
> + default:
> + ret = -EINVAL;
> + goto skip;
> + }
> +
> + val = lm3633_convert_ramp_to_index(time->rise);
> + ret = ti_lmu_update_bits(chip->lmu, reg, LM3633_PTN_RAMPUP_MASK,
> + val << LM3633_PTN_RAMPUP_SHIFT);
> + if (ret)
> + goto skip;
> +
> + val = lm3633_convert_ramp_to_index(time->fall);
> + ret = ti_lmu_update_bits(chip->lmu, reg, LM3633_PTN_RAMPDN_MASK,
> + val << LM3633_PTN_RAMPDN_SHIFT);
> + if (ret)
> + goto skip;
> +
> + mutex_unlock(&chip->lock);
> + return len;
> +
> +skip:
> + mutex_unlock(&chip->lock);
> + return ret;
> +}
> +
> +static ssize_t lm3633_led_show_pattern_levels(struct device *dev,
> + struct device_attribute *attr,
> + char *buf)
> +{
> + struct ti_lmu_led *lmu_led = to_ti_lmu_led(dev);
> +
> + return sprintf(buf, "low brightness: %u, high brightness: %u\n",
> + lmu_led->level.low, lmu_led->level.high);
> +}
> +
> +static ssize_t lm3633_led_store_pattern_levels(struct device *dev,
> + struct device_attribute *attr,
> + const char *buf, size_t len)
> +{
> + struct ti_lmu_led *lmu_led = to_ti_lmu_led(dev);
> + struct ti_lmu_led_chip *chip = lmu_led->chip;
> + unsigned int low, high;
> + u8 reg, offset, val;
> + int ret;
> +
> + /*
> + * Sequence
> + *
> + * 1) Read pattern level data
> + * 2) Disable a bank before programming a pattern
> + * 3) Update LOW BRIGHTNESS register
> + * 4) Update HIGH BRIGHTNESS register
> + *
> + * Level register addresses have offset number based on the LED bank.
> + */
> +
> + ret = sscanf(buf, "%u %u", &low, &high);
> + if (ret != 2)
> + return -EINVAL;
> +
> + low = min_t(unsigned int, low, LM3633_LED_MAX_BRIGHTNESS);

Why don't you take into account the value defined by led-max-microamp
DT property here?

> + high = min_t(unsigned int, high, LM3633_LED_MAX_BRIGHTNESS);

Ditto.

> + lmu_led->level.low = (u8)low;
> + lmu_led->level.high = (u8)high;
> +
> + mutex_lock(&chip->lock);
> + ret = lm3633_led_disable_bank(lmu_led);
> + if (ret)
> + goto skip;
> +
> + offset = lmu_led->bank_id * LM3633_PATTERN_REG_OFFSET;
> + reg = LM3633_REG_PTN_LOWBRT + offset;
> + val = lmu_led->level.low;
> + ret = ti_lmu_write_byte(chip->lmu, reg, val);
> + if (ret)
> + goto skip;
> +
> + offset = lmu_led->bank_id;
> + reg = LM3633_REG_PTN_HIGHBRT + offset;
> + val = lmu_led->level.high;
> + ret = ti_lmu_write_byte(chip->lmu, reg, val);
> + if (ret)
> + goto skip;
> +
> + mutex_unlock(&chip->lock);
> + return len;
> +
> +skip:
> + mutex_unlock(&chip->lock);
> + return ret;
> +}
> +
> +static ssize_t lm3633_led_run_pattern(struct device *dev,
> + struct device_attribute *attr,
> + const char *buf, size_t len)
> +{
> + struct ti_lmu_led *lmu_led = to_ti_lmu_led(dev);
> + struct ti_lmu_led_chip *chip = lmu_led->chip;
> + unsigned long enable;
> + int ret;
> +
> + if (kstrtoul(buf, 0, &enable))
> + return -EINVAL;
> +
> + mutex_lock(&chip->lock);
> +
> + if (enable)
> + ret = lm3633_led_enable_pattern(lmu_led);
> + else
> + ret = lm3633_led_disable_pattern(lmu_led);
> +
> + if (ret) {
> + mutex_unlock(&chip->lock);
> + return ret;
> + }
> +
> + if (enable)
> + lm3633_led_enable_bank(lmu_led);
> +
> + mutex_unlock(&chip->lock);
> +
> + return len;
> +}
> +
> +static DEVICE_ATTR(pattern_times, S_IRUGO | S_IWUSR,
> + lm3633_led_show_pattern_times,
> + lm3633_led_store_pattern_times);
> +static DEVICE_ATTR(pattern_levels, S_IRUGO | S_IWUSR,
> + lm3633_led_show_pattern_levels,
> + lm3633_led_store_pattern_levels);
> +static DEVICE_ATTR(run_pattern, S_IWUSR, NULL,
> + lm3633_led_run_pattern);
> +
> +static struct attribute *lm3633_led_attrs[] = {
> + &dev_attr_pattern_times.attr,
> + &dev_attr_pattern_levels.attr,
> + &dev_attr_run_pattern.attr,
> + NULL,
> +};
> +ATTRIBUTE_GROUPS(lm3633_led); /* lm3633_led_groups */
> +
> +static int lm3633_led_set_max_current(struct ti_lmu_led *lmu_led)
> +{
> + u8 reg = LM3633_REG_IMAX_LVLED_BASE + lmu_led->bank_id;
> +
> + return ti_lmu_write_byte(lmu_led->chip->lmu, reg, lmu_led->imax);
> +}
> +
> +static void lm3633_led_work(struct work_struct *work)
> +{
> + struct ti_lmu_led *lmu_led = container_of(work, struct ti_lmu_led,
> + work);
> + struct ti_lmu_led_chip *chip = lmu_led->chip;
> + int ret;
> +
> + mutex_lock(&chip->lock);
> +
> + ret = ti_lmu_write_byte(chip->lmu,
> + LM3633_REG_BRT_LVLED_BASE + lmu_led->bank_id,
> + lmu_led->brightness);
> + if (ret) {
> + mutex_unlock(&chip->lock);
> + return;
> + }
> +
> + if (lmu_led->brightness == 0)
> + lm3633_led_disable_bank(lmu_led);
> + else
> + lm3633_led_enable_bank(lmu_led);

Is it possible to control a brightness of a whole bank only,
and not individual LEDs?

> + mutex_unlock(&chip->lock);
> +}
> +
> +static void lm3633_led_brightness_set(struct led_classdev *cdev,
> + enum led_brightness brt_val)
> +{
> + struct ti_lmu_led *lmu_led = container_of(cdev, struct ti_lmu_led,
> + cdev);
> +
> + lmu_led->brightness = brt_val;
> + schedule_work(&lmu_led->work);
> +}
> +
> +static int lm3633_led_init(struct ti_lmu_led *lmu_led, int bank_id)
> +{
> + struct device *dev = lmu_led->chip->dev;
> + char name[12];
> + int ret;
> +
> + /*
> + * Sequence
> + *
> + * 1) Configure LED bank which is used for brightness control
> + * 2) Set max current for each output channel
> + * 3) Add LED device
> + */
> +
> + ret = lm3633_led_config_bank(lmu_led);
> + if (ret) {
> + dev_err(dev, "Output bank register err: %d\n", ret);
> + return ret;
> + }
> +
> + ret = lm3633_led_set_max_current(lmu_led);
> + if (ret) {
> + dev_err(dev, "Set max current err: %d\n", ret);
> + return ret;
> + }
> +
> + lmu_led->cdev.max_brightness = LM3633_LED_MAX_BRIGHTNESS;

The value assigned here should be determined by led-max-microamp
DT property.

> + lmu_led->cdev.brightness_set = lm3633_led_brightness_set;
> + lmu_led->cdev.groups = lm3633_led_groups;
> +
> + if (lmu_led->name) {
> + lmu_led->cdev.name = lmu_led->name;
> + } else {
> + snprintf(name, sizeof(name), "%s:%d", LM3633_DEFAULT_LED_NAME,
> + bank_id);
> + lmu_led->cdev.name = name;
> + }
> +
> + ret = led_classdev_register(dev, &lmu_led->cdev);

Please use devm prefixed version.

> + if (ret) {
> + dev_err(dev, "LED register err: %d\n", ret);
> + return ret;
> + }
> +
> + INIT_WORK(&lmu_led->work, lm3633_led_work);

Work queue should be initialized before LED class device is registered.

> + return 0;
> +}
> +
> +static int lm3633_led_of_create(struct ti_lmu_led_chip *chip,
> + struct device_node *np)
> +{
> + struct device_node *child;
> + struct device *dev = chip->dev;
> + struct ti_lmu_led *lmu_led, *each;
> + int num_leds;
> + int i = 0;
> + u32 imax;
> +
> + if (!np)
> + return -ENODEV;
> +
> + num_leds = of_get_child_count(np);
> + if (num_leds == 0 || num_leds > LM3633_MAX_LEDS) {
> + dev_err(dev, "Invalid number of LEDs: %d\n", num_leds);
> + return -EINVAL;
> + }
> +
> + lmu_led = devm_kzalloc(dev, sizeof(*lmu_led) * num_leds, GFP_KERNEL);
> + if (!lmu_led)
> + return -ENOMEM;
> +
> + for_each_child_of_node(np, child) {
> + each = lmu_led + i;
> +
> + of_property_read_string(child, "channel-name", &each->name);
> +
> + /* Make LED strings */
> + each->led_string = 0;
> + if (of_property_read_bool(child, "lvled1-used"))
> + each->led_string |= LMU_LVLED1;
> + if (of_property_read_bool(child, "lvled2-used"))
> + each->led_string |= LMU_LVLED2;
> + if (of_property_read_bool(child, "lvled3-used"))
> + each->led_string |= LMU_LVLED3;
> + if (of_property_read_bool(child, "lvled4-used"))
> + each->led_string |= LMU_LVLED4;
> + if (of_property_read_bool(child, "lvled5-used"))
> + each->led_string |= LMU_LVLED5;
> + if (of_property_read_bool(child, "lvled6-used"))
> + each->led_string |= LMU_LVLED6;
> +
> + imax = 0;
> + of_property_read_u32(child, "led-max-microamp", &imax);
> + each->imax = ti_lmu_get_current_code(imax);
> +
> + each->bank_id = 0;
> + each->chip = chip;
> + i++;
> + }
> +
> + chip->lmu_led = lmu_led;
> + chip->num_leds = num_leds;
> +
> + return 0;
> +}
> +
> +static int lm3633_led_hwmon_notifier(struct notifier_block *nb,
> + unsigned long action, void *unused)
> +{
> + struct ti_lmu_led_chip *chip = container_of(nb, struct ti_lmu_led_chip,
> + nb);
> + struct ti_lmu_led *each;
> + int i, ret;
> +
> + /* LED should be reconfigured after hwmon procedure is done */
> + if (action == LMU_EVENT_HWMON_DONE) {
> + for (i = 0; i < chip->num_leds; i++) {
> + each = chip->lmu_led + i;
> + ret = lm3633_led_config_bank(each);
> + if (ret) {
> + dev_err(chip->dev,
> + "Output bank register err: %d\n", ret);
> + return NOTIFY_STOP;
> + }
> +
> + ret = lm3633_led_set_max_current(each);
> + if (ret) {
> + dev_err(chip->dev, "Set max current err: %d\n",
> + ret);
> + return NOTIFY_STOP;
> + }
> + }
> + }
> +
> + return NOTIFY_OK;
> +}
> +
> +static int lm3633_led_probe(struct platform_device *pdev)
> +{
> + struct device *dev = &pdev->dev;
> + struct ti_lmu *lmu = dev_get_drvdata(dev->parent);
> + struct ti_lmu_led_chip *chip;
> + struct ti_lmu_led *each;
> + int i, ret;
> +
> + chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
> + if (!chip)
> + return -ENOMEM;
> +
> + chip->dev = dev;
> + chip->lmu = lmu;
> +
> + ret = lm3633_led_of_create(chip, dev->of_node);
> + if (ret)
> + return ret;
> +
> + /*
> + * Notifier callback is required because LED device needs
> + * reconfiguration after opened/shorted circuit fault monitoring

Shouldn't this be open/short circuit?

> + * by ti-lmu-hwmon driver.
> + */
> + chip->nb.notifier_call = lm3633_led_hwmon_notifier;
> + ret = blocking_notifier_chain_register(&chip->lmu->notifier, &chip->nb);
> + if (ret)
> + return ret;
> +
> + for (i = 0; i < chip->num_leds; i++) {
> + each = chip->lmu_led + i;
> + ret = lm3633_led_init(each, i);
> + if (ret) {
> + dev_err(dev, "LED initialization err: %d\n", ret);
> + goto cleanup_leds;
> + }
> + }
> +
> + mutex_init(&chip->lock);

Please initialize the mutex above the loop.

> + platform_set_drvdata(pdev, chip);
> +
> + return 0;
> +
> +cleanup_leds:
> + while (--i >= 0) {
> + each = chip->lmu_led + i;
> + led_classdev_unregister(&each->cdev);
> + }
> + return ret;
> +}
> +
> +static int lm3633_led_remove(struct platform_device *pdev)
> +{
> + struct ti_lmu_led_chip *chip = platform_get_drvdata(pdev);
> + struct ti_lmu_led *each;
> + int i;
> +
> + blocking_notifier_chain_unregister(&chip->lmu->notifier, &chip->nb);
> +
> + for (i = 0; i < chip->num_leds; i++) {
> + each = chip->lmu_led + i;
> + led_classdev_unregister(&each->cdev);
> + flush_work(&each->work);
> + }
> +
> + return 0;
> +}
> +
> +static const struct of_device_id lm3633_led_of_match[] = {
> + { .compatible = "ti,lm3633-leds" },
> + { }
> +};
> +MODULE_DEVICE_TABLE(of, lm3633_led_of_match);
> +
> +static struct platform_driver lm3633_led_driver = {
> + .probe = lm3633_led_probe,
> + .remove = lm3633_led_remove,
> + .driver = {
> + .name = "lm3633-leds",
> + .of_match_table = lm3633_led_of_match,
> + },
> +};
> +
> +module_platform_driver(lm3633_led_driver);
> +
> +MODULE_DESCRIPTION("TI LM3633 LED Driver");
> +MODULE_AUTHOR("Milo Kim");
> +MODULE_LICENSE("GPL v2");
> +MODULE_ALIAS("platform:lm3633-leds");
>


--
Best Regards,
Jacek Anaszewski

2015-11-04 13:59:29

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH RESEND 16/16] regulator: add LM363X driver

On Mon, Nov 02, 2015 at 02:24:35PM +0900, Milo Kim wrote:

This looks mostly good, just a few fairly small things:

> +lm363x_regulator_of_get_init_data(struct device *dev,
> + struct lm363x_regulator *lm363x_regulator, int id)
> +{
> + struct device_node *np = dev->of_node;
> + int count;
> +
> + count = of_regulator_match(dev, np, &lm363x_regulator_matches[id], 1);
> + if (count <= 0)
> + return ERR_PTR(-ENODEV);
> +
> + return lm363x_regulator_matches[id].init_data;
> +}

Don't open code DT matching, use of_match in the regulator_desc and let
the core do it for you.

> + /*
> + * Check LCM_EN1/2_GPIO is configured.
> + * Those pins are used for enabling VPOS/VNEG LDOs.
> + */
> + if (id == LM3632_LDO_POS)
> + gpio = of_get_named_gpio(np, "ti,lcm-en1-gpio", 0);
> + else if (id == LM3632_LDO_NEG)
> + gpio = of_get_named_gpio(np, "ti,lcm-en2-gpio", 0);

This looks like it should be a switch statement.

> + rdev = regulator_register(&lm363x_regulator_desc[id], &cfg);
> + if (IS_ERR(rdev)) {

Use devm_regulator_register().

> +static const struct of_device_id lm363x_regulator_of_match[] = {
> + { .compatible = "ti,lm363x-regulator" },
> + { }
> +};
> +MODULE_DEVICE_TABLE(of, lm363x_regulator_of_match);

You shouldn't need a compatible string for a device like this, the MFD
should just register a platform device based on the compatible string
for the MFD.


Attachments:
(No filename) (1.35 kB)
signature.asc (473.00 B)
Download all attachments

2015-11-06 01:58:05

by Rob Herring (Arm)

[permalink] [raw]
Subject: Re: [PATCH RESEND 03/16] Documentation: dt-bindings: hwmon: add TI LMU HWMON binding information

On Mon, Nov 02, 2015 at 02:24:22PM +0900, Milo Kim wrote:
> Hardware fault monitoring driver is used in LM3633 and LM3697 device.
> Just 'compatible' property is required to describe the driver.
>
> Cc: [email protected]
> Cc: Guenter Roeck <[email protected]>
> Cc: Jean Delvare <[email protected]>
> Cc: Lee Jones <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Signed-off-by: Milo Kim <[email protected]>

Acked-by: Rob Herring <[email protected]>

> ---
> Documentation/devicetree/bindings/hwmon/ti-lmu-hwmon.txt | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/hwmon/ti-lmu-hwmon.txt
>
> diff --git a/Documentation/devicetree/bindings/hwmon/ti-lmu-hwmon.txt b/Documentation/devicetree/bindings/hwmon/ti-lmu-hwmon.txt
> new file mode 100644
> index 0000000..99cb241
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/hwmon/ti-lmu-hwmon.txt
> @@ -0,0 +1,12 @@
> +TI LMU Hardware Monotoring device tree bindings
> +
> +LMU HWON driver monitors hardware fault situation of LMU devices,
> +LM3633 and LM3697.
> +
> +Required properties:
> + - compatible: Should be one of lists below.
> + "ti,lm3633-hwmon"
> + "ti,lm3697-hwmon"
> +
> +Examples: Please refer to ti-lmu dt-bindings.
> + Documentation/devicetree/bindings/mfd/ti-lmu.txt
> --
> 1.9.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe devicetree" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

2015-11-06 02:00:55

by Rob Herring (Arm)

[permalink] [raw]
Subject: Re: [PATCH RESEND 01/16] Documentation: dt-bindings: mfd: add TI LMU device binding information

On Mon, Nov 02, 2015 at 02:24:20PM +0900, Milo Kim wrote:
> This patch describes overall binding for TI LMU MFD devices.
>
> Cc: [email protected]
> Cc: Lee Jones <[email protected]>
> Cc: [email protected]
> Signed-off-by: Milo Kim <[email protected]>

Acked-by: Rob Herring <[email protected]>

> ---
> Documentation/devicetree/bindings/mfd/ti-lmu.txt | 282 +++++++++++++++++++++++
> 1 file changed, 282 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/mfd/ti-lmu.txt
>
> diff --git a/Documentation/devicetree/bindings/mfd/ti-lmu.txt b/Documentation/devicetree/bindings/mfd/ti-lmu.txt
> new file mode 100644
> index 0000000..7ccf07e
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/mfd/ti-lmu.txt
> @@ -0,0 +1,282 @@
> +TI LMU(Lighting Management Unit) device tree bindings
> +
> +TI LMU driver supports lighting devices belows.
> +
> + Name Child nodes
> + ------ -------------------------
> + LM3532 Backlight
> + LM3631 Backlight and regulator
> + LM3632 Backlight and regulator
> + LM3633 Backlight, LED and HWMON
> + LM3695 Backlight
> + LM3697 Backlight and HWMON
> +
> +Required properties:
> + - compatible: Should be one of lists below.
> + "ti,lm3532"
> + "ti,lm3631"
> + "ti,lm3632"
> + "ti,lm3633"
> + "ti,lm3695"
> + "ti,lm3697"
> + - reg: I2C slave address.
> + 0x11 is LM3632
> + 0x29 is LM3631
> + 0x36 is LM3633, LM3697
> + 0x38 is LM3532
> + 0x63 is LM3695
> +
> +Optional properties:
> + - enable-gpios: A GPIO specifier for hardware enable pin.
> +
> +Required node:
> + - backlight: All LMU devices have backlight child nodes.
> + For the properties, please refer to [1].
> +
> +Optional nodes:
> + - hwmon: Hardware fault monitoring driver for LM3633 and LM3697.
> + For the property, please refer to [2].
> + - leds: LED properties for LM3633. Please refer to [3].
> + - regulators: Regulator properties for LM3631 and LM3632.
> + Please refer to [4].
> +
> +[1] Documentation/devicetree/bindings/video/backlight/ti-lmu-backlight.txt
> +[2] Documentation/devicetree/bindings/hwm/ti-lmu-hwmon.txt
> +[3] Documentation/devicetree/bindings/leds/leds-lm3633.txt
> +[4] Documentation/devicetree/bindings/regulator/lm363x-regulator.txt
> +
> +Examples:
> +
> +LM3532 has a backlight device. External GPIO is used for enabling LM3532.
> +
> +lm3532@38 {
> + compatible = "ti,lm3532";
> + reg = <0x38>;
> +
> + enable-gpios = <&pioC 2 GPIO_ACTIVE_HIGH>;
> +
> + backlight {
> + compatible = "ti,lm3532-backlight";
> +
> + lcd {
> + hvled1-used;
> + hvled2-used;
> + hvled3-used;
> +
> + ramp-up-msec = <30>;
> + ramp-down-msec = <0>;
> +
> + backlight-max-microamp = <5000>;
> + };
> + };
> +};
> +
> +LM3631 has 5 regulators with one backlight device.
> +
> +lm3631@29 {
> + compatible = "ti,lm3631";
> + reg = <0x29>;
> +
> + regulators {
> + compatible = "ti,lm363x-regulator";
> +
> + vboost {
> + regulator-name = "lcd_boost";
> + regulator-min-microvolt = <4500000>;
> + regulator-max-microvolt = <6350000>;
> + regulator-always-on;
> + };
> +
> + vcont {
> + regulator-name = "lcd_vcont";
> + regulator-min-microvolt = <1800000>;
> + regulator-max-microvolt = <3300000>;
> + };
> +
> + voref {
> + regulator-name = "lcd_voref";
> + regulator-min-microvolt = <4000000>;
> + regulator-max-microvolt = <6000000>;
> + };
> +
> + vpos {
> + regulator-name = "lcd_vpos";
> + regulator-min-microvolt = <4000000>;
> + regulator-max-microvolt = <6000000>;
> + regulator-boot-on;
> + };
> +
> + vneg {
> + regulator-name = "lcd_vneg";
> + regulator-min-microvolt = <4000000>;
> + regulator-max-microvolt = <6000000>;
> + regulator-boot-on;
> + };
> + };
> +
> + backlight {
> + compatible = "ti,lm3631-backlight";
> +
> + lcd {
> + backlight-name = "lcd_bl";
> + hvled1-used;
> + hvled2-used;
> +
> + ramp-up-msec = <300>;
> + };
> + };
> +};
> +
> +LM3632 has 3 regulators with one backlight device. External GPIO is
> +used for enabling LM3632.
> +
> +lm3632@11 {
> + compatible = "ti,lm3632";
> + reg = <0x11>;
> +
> + enable-gpios = <&pioC 2 GPIO_ACTIVE_HIGH>;
> +
> + regulators {
> + compatible = "ti,lm363x-regulator";
> +
> + ti,lcm-en1-gpio = <&pioC 0 GPIO_ACTIVE_HIGH>;
> + ti,lcm-en2-gpio = <&pioC 1 GPIO_ACTIVE_HIGH>;
> +
> + vboost {
> + regulator-name = "lcd_boost";
> + regulator-min-microvolt = <4500000>;
> + regulator-max-microvolt = <6400000>;
> + regulator-always-on;
> + };
> +
> + vpos {
> + regulator-name = "lcd_vpos";
> + regulator-min-microvolt = <4000000>;
> + regulator-max-microvolt = <6000000>;
> + };
> +
> + vneg {
> + regulator-name = "lcd_vneg";
> + regulator-min-microvolt = <4000000>;
> + regulator-max-microvolt = <6000000>;
> + };
> + };
> +
> + backlight {
> + compatible = "ti,lm3632-backlight";
> +
> + lcd {
> + backlight-name = "lcd";
> + hvled1-used;
> + hvled2-used;
> + };
> + };
> +};
> +
> +LM3633 has multiple backlight channels, LED channels and hardware fault
> +monitoring driver. External GPIO is used for enabling LM3633.
> +
> +lm3633@36 {
> + compatible = "ti,lm3633";
> + reg = <0x36>;
> +
> + enable-gpios = <&pioC 2 GPIO_ACTIVE_HIGH>;
> +
> + backlight {
> + compatible = "ti,lm3633-backlight";
> +
> + pwms = <&pwm0 0 10000 0>; /* pwm number, period, polarity */
> + pwm-names = "lmu-backlight";
> +
> + main {
> + backlight-name = "main_lcd";
> + hvled2-used;
> + hvled3-used;
> + backlight-max-microamp = <20000>;
> +
> + ramp-up-msec = <500>;
> + ramp-down-msec = <500>;
> + };
> +
> + front {
> + backlight-name = "front_lcd";
> + hvled1-used;
> +
> + ramp-up-msec = <1000>;
> + ramp-down-msec = <0>;
> +
> + pwm-period = <10000>;
> + };
> + };
> +
> + leds {
> + compatible = "ti,lm3633-leds";
> +
> + chan2 {
> + channel-name = "status";
> + lvled2-used;
> + led-max-microamp = <6000>;
> + };
> +
> + chan456 {
> + channel-name = "rgb";
> + lvled4-used;
> + lvled5-used;
> + lvled6-used;
> + };
> + };
> +
> + hwmon {
> + compatible = "ti,lm3633-hwmon";
> + };
> +};
> +
> +LM3695 is single backlight device.
> +
> +lm3695@63 {
> + compatible = "ti,lm3695";
> + reg = <0x63>;
> +
> + backlight {
> + compatible = "ti,lm3695-backlight";
> +
> + lcd {
> + hvled1-used;
> + hvled2-used;
> + backlight-max-microamp = <20000>;
> + };
> + };
> +};
> +
> +LM3697 has one backlight device and hardware fault monitoring driver.
> +External GPIO is used for enabling LM3697.
> +
> +lm3697@36 {
> + compatible = "ti,lm3697";
> + reg = <0x36>;
> +
> + enable-gpios = <&pioC 2 GPIO_ACTIVE_HIGH>;
> +
> + backlight {
> + compatible = "ti,lm3697-backlight";
> +
> + pwms = <&pwm0 0 10000 0>; /* pwm number, period, polarity */
> + pwm-names = "lmu-backlight";
> +
> + lcd {
> + backlight-name = "bl";
> + hvled1-used;
> + hvled2-used;
> + hvled3-used;
> + backlight-max-microamp = <20000>;
> +
> + ramp-up-msec = <500>;
> + ramp-down-msec = <500>;
> + pwm-period = <10000>;
> + };
> + };
> +
> + hwmon {
> + compatible = "ti,lm3697-hwmon";
> + };
> +};
> --
> 1.9.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe devicetree" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

2015-11-06 03:49:41

by Kim, Milo

[permalink] [raw]
Subject: Re: [PATCH RESEND 03/16] Documentation: dt-bindings: hwmon: add TI LMU HWMON binding information


On 11/6/2015 10:57 AM, Rob Herring wrote:
> On Mon, Nov 02, 2015 at 02:24:22PM +0900, Milo Kim wrote:
>> Hardware fault monitoring driver is used in LM3633 and LM3697 device.
>> Just 'compatible' property is required to describe the driver.
>>
>> Cc: [email protected]
>> Cc: Guenter Roeck <[email protected]>
>> Cc: Jean Delvare <[email protected]>
>> Cc: Lee Jones <[email protected]>
>> Cc: [email protected]
>> Cc: [email protected]
>> Signed-off-by: Milo Kim <[email protected]>
>
> Acked-by: Rob Herring <[email protected]>

Thanks for your review, Rob.
HWMON maintainer, Guenter suggested moving LMU HWMON driver to MFD as
the sysfs attributes because it has no sensor data like temperature or
voltage.
So I'll move this property to mfd/ti-lmu.txt in the next patch.

Best regards,
Milo

2015-11-10 07:02:07

by Kim, Milo

[permalink] [raw]
Subject: Re: [PATCH RESEND 04/16] Documentation: dt-bindings: leds: add LM3633 LED binding information

Hi Jacek,

On 11/4/2015 1:15 AM, Jacek Anaszewski wrote:
>> + - led-max-microamp: Max current setting. Type is <u32>.
>> >+ Unit is microampere. Range is from 5000 to 30000.
> Could you specify also a step?
>

Yep, step is 1000. Thanks for catching this.
I'll update the binding in the next patch.

Best regards,
Milo

2015-11-10 07:39:05

by Kim, Milo

[permalink] [raw]
Subject: Re: [PATCH RESEND 15/16] leds: add LM3633 driver

Hi Jacek,

On 11/4/2015 1:15 AM, Jacek Anaszewski wrote:
> Hi Milo,
>
> Thanks for the patch. Please find my comments in the code.
>
>> diff --git a/Documentation/ABI/testing/sysfs-class-led-lm3633 b/Documentation/ABI/testing/sysfs-class-led-lm3633
>> new file mode 100644
>> index 0000000..c1d8759
>> --- /dev/null
>> +++ b/Documentation/ABI/testing/sysfs-class-led-lm3633
>> @@ -0,0 +1,60 @@
>> +LM3633 LED driver generates programmable pattern via the sysfs.
>> +
>> +LED Pattern Generator Structure
>> +
>> + (3)
>> + (a) ---------------> ___________
>> + / \
>> + (2) / \ (4)
>> + (b) ----> _________/ \_________ ...
>> + (1) (5)
>> +
>> + |<----- period -----> |
>> +
>> +What: /sys/class/leds/<led>/pattern_times
>
> "time" noun is uncountable.
>
>> +Date: Oct 2015
>> +KernelVersion: 4.3
>
> These properties certainly will not appear in 4.3.

Oops! 4.4 gonna be OK?

>
>> +Contact: Milo Kim <[email protected]>
>> +Description: read/write
>> + Set pattern time dimension. There are five arguments.
>> + (1) startup delay
>> + (2) rising dimming time
>> + (3) how much time stays at high level
>> + (4) falling dimming time
>> + (5) how much time stays at low level
>> + Ranges are
>> + (1), (3), (5): 0 ~ 10000. Unit is millisecond.
>> + (2), (4): 0 ~ 16000. Unit is millisecond.
>> +
>> + Example:
>> + No delay, rising 200ms, high 300ms, falling 100ms, low 400ms.
>> + echo "0 200 300 100 400" > /sys/class/leds/<led>/pattern_times
>> +
>> + cat /sys/class/leds/<led>/pattern_times
>> + delay: 0, rise: 200, high: 300, fall: 100, low: 400
>
> Generally a sysfs attribute should represent a single value.
> There are cases where the attribute comprises a list of space separated
> values, but certainly colons and commas adds to much noise, and are
> cumbersome to parse. I'd opt for creating a separate sysfs attribute
> for each of the above 5 properties.

Got it, thanks!

>
>> +What: /sys/class/leds/<led>/pattern_levels
>> +Date: Oct 2015
>> +KernelVersion: 4.3
>> +Contact: Milo Kim <[email protected]>
>> +Description: read/write
>> + Set pattern level(brightness). There are two arguments.
>> + (a) Low brightness level
>> + (b) High brightness level
>> + Ranges are from 0 to 255.
>> +
>> + Example:
>> + Low level is 0, high level is 255.
>> + echo "0 255" > /sys/class/leds/<led>/pattern_levels
>
> I'd go also for two separate attributes. E.g. pattern_brightness_lo and
> pattern_brightness_hi, or maybe you'll have better idea.

OK.

>
>> + cat /sys/class/leds/<led>/pattern_levels
>> + low brightness: 0, high brightness: 255
>> +
>> +What: /sys/class/leds/<led>/run_pattern
>> +Date: Oct 2015
>> +KernelVersion: 4.3
>> +Contact: Milo Kim <[email protected]>
>> +Description: write only
>> + After 'pattern_times' and 'pattern_levels' are updated,
>> + run the pattern by writing 1 to 'run_pattern'.
>> + To stop running pattern, writes 0 to 'run_pattern'.
>
> I wonder how registering an in-driver trigger would work. It would
> allow for hiding above pattern attributes when the trigger is inactive,
> and thus making the sysfs interface more transparent. You could avoid
> the need for run_pattern attribute, as setting the trigger would itself
> activate the pattern, and setting brightness to 0 would turn it off.

I like this idea, let me try to fix it.

>> +/**
>> + * struct ti_lmu_led
>> + *
>> + * @chip: Pointer to parent LED device
>> + * @bank_id: LED bank ID
>> + * @cdev: LED subsystem device structure
>> + * @name: LED channel name
>> + * @led_string: LED string configuration.
>> + * Bit mask is set on parsing DT.
>> + * @imax: [Optional] Max current index.
>> + * It's result of ti_lmu_get_current_code().
>
> Why is this optional?

You're correct, this is not optional. DT property is optional.

>> +static ssize_t lm3633_led_store_pattern_levels(struct device *dev,
>> + struct device_attribute *attr,
>> + const char *buf, size_t len)
>> +{
>> + struct ti_lmu_led *lmu_led = to_ti_lmu_led(dev);
>> + struct ti_lmu_led_chip *chip = lmu_led->chip;
>> + unsigned int low, high;
>> + u8 reg, offset, val;
>> + int ret;
>> +
>> + /*
>> + * Sequence
>> + *
>> + * 1) Read pattern level data
>> + * 2) Disable a bank before programming a pattern
>> + * 3) Update LOW BRIGHTNESS register
>> + * 4) Update HIGH BRIGHTNESS register
>> + *
>> + * Level register addresses have offset number based on the LED bank.
>> + */
>> +
>> + ret = sscanf(buf, "%u %u", &low, &high);
>> + if (ret != 2)
>> + return -EINVAL;
>> +
>> + low = min_t(unsigned int, low, LM3633_LED_MAX_BRIGHTNESS);
>
> Why don't you take into account the value defined by led-max-microamp
> DT property here?

'low' and 'high' are brightness value. The range is from 0 to 255. It is
mostly related with LED sysfs - /sys/class/led/<led>/brightness.
On the other hand, led-max-microamp is current limit. It is from 5mA to
30mA. It's different configuration in this device.

>> +static void lm3633_led_work(struct work_struct *work)
>> +{
>> + struct ti_lmu_led *lmu_led = container_of(work, struct ti_lmu_led,
>> + work);
>> + struct ti_lmu_led_chip *chip = lmu_led->chip;
>> + int ret;
>> +
>> + mutex_lock(&chip->lock);
>> +
>> + ret = ti_lmu_write_byte(chip->lmu,
>> + LM3633_REG_BRT_LVLED_BASE + lmu_led->bank_id,
>> + lmu_led->brightness);
>> + if (ret) {
>> + mutex_unlock(&chip->lock);
>> + return;
>> + }
>> +
>> + if (lmu_led->brightness == 0)
>> + lm3633_led_disable_bank(lmu_led);
>> + else
>> + lm3633_led_enable_bank(lmu_led);
>
> Is it possible to control a brightness of a whole bank only,
> and not individual LEDs?

No, LM3633 has internal control banks. Let me assume that two LED groups
are assigned below.
LED 1, 2, 3 - RGB
LED 4 - status
Two control banks should be allocated. The bank should be controlled
separately. If we try to enable/disabe all banks, then 6 output LED
channels are controlled at the same time.

>> +static int lm3633_led_init(struct ti_lmu_led *lmu_led, int bank_id)
>> +{
>> + struct device *dev = lmu_led->chip->dev;
>> + char name[12];
>> + int ret;
>> +
>> + /*
>> + * Sequence
>> + *
>> + * 1) Configure LED bank which is used for brightness control
>> + * 2) Set max current for each output channel
>> + * 3) Add LED device
>> + */
>> +
>> + ret = lm3633_led_config_bank(lmu_led);
>> + if (ret) {
>> + dev_err(dev, "Output bank register err: %d\n", ret);
>> + return ret;
>> + }
>> +
>> + ret = lm3633_led_set_max_current(lmu_led);
>> + if (ret) {
>> + dev_err(dev, "Set max current err: %d\n", ret);
>> + return ret;
>> + }
>> +
>> + lmu_led->cdev.max_brightness = LM3633_LED_MAX_BRIGHTNESS;
>
> The value assigned here should be determined by led-max-microamp
> DT property.

Ditto. Current limit is different configuration from brightness value.

>> +static int lm3633_led_probe(struct platform_device *pdev)
>> +{
>> + struct device *dev = &pdev->dev;
>> + struct ti_lmu *lmu = dev_get_drvdata(dev->parent);
>> + struct ti_lmu_led_chip *chip;
>> + struct ti_lmu_led *each;
>> + int i, ret;
>> +
>> + chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
>> + if (!chip)
>> + return -ENOMEM;
>> +
>> + chip->dev = dev;
>> + chip->lmu = lmu;
>> +
>> + ret = lm3633_led_of_create(chip, dev->of_node);
>> + if (ret)
>> + return ret;
>> +
>> + /*
>> + * Notifier callback is required because LED device needs
>> + * reconfiguration after opened/shorted circuit fault monitoring
>
> Shouldn't this be open/short circuit?

You're correct. Thanks!

Best regards,
Milo

2015-11-10 07:54:35

by Kim, Milo

[permalink] [raw]
Subject: Re: [PATCH RESEND 16/16] regulator: add LM363X driver


On 11/4/2015 10:59 PM, Mark Brown wrote:
> On Mon, Nov 02, 2015 at 02:24:35PM +0900, Milo Kim wrote:
>
> This looks mostly good, just a few fairly small things:
>
>> +lm363x_regulator_of_get_init_data(struct device *dev,
>> + struct lm363x_regulator *lm363x_regulator, int id)
>> +{
>> + struct device_node *np = dev->of_node;
>> + int count;
>> +
>> + count = of_regulator_match(dev, np, &lm363x_regulator_matches[id], 1);
>> + if (count <= 0)
>> + return ERR_PTR(-ENODEV);
>> +
>> + return lm363x_regulator_matches[id].init_data;
>> +}
>
> Don't open code DT matching, use of_match in the regulator_desc and let
> the core do it for you.

OK, good.
I've also found wrong pointer reference of regulator_cfg.dev. It should
be pdev->dev instead of pdev->dev->parent.

- cfg.dev = dev->parent;
+ cfg.dev = dev;

Old code affects wrong parsing from the DT. So, registered regulator has
different operation mask. In the end, regulators which has zero use
count never gonna be disabled in regulator_init_compelete().

>
>> + /*
>> + * Check LCM_EN1/2_GPIO is configured.
>> + * Those pins are used for enabling VPOS/VNEG LDOs.
>> + */
>> + if (id == LM3632_LDO_POS)
>> + gpio = of_get_named_gpio(np, "ti,lcm-en1-gpio", 0);
>> + else if (id == LM3632_LDO_NEG)
>> + gpio = of_get_named_gpio(np, "ti,lcm-en2-gpio", 0);
>
> This looks like it should be a switch statement.

Yep!

>
>> + rdev = regulator_register(&lm363x_regulator_desc[id], &cfg);
>> + if (IS_ERR(rdev)) {
>
> Use devm_regulator_register().

OK.

>
>> +static const struct of_device_id lm363x_regulator_of_match[] = {
>> + { .compatible = "ti,lm363x-regulator" },
>> + { }
>> +};
>> +MODULE_DEVICE_TABLE(of, lm363x_regulator_of_match);
>
> You shouldn't need a compatible string for a device like this, the MFD
> should just register a platform device based on the compatible string
> for the MFD.
>

Thanks for catching this.
Let me apply all your comments in the next patch.

Best regards,
Milo

2015-11-10 13:44:58

by Jacek Anaszewski

[permalink] [raw]
Subject: Re: [PATCH RESEND 15/16] leds: add LM3633 driver

On 11/10/2015 08:38 AM, Kim, Milo wrote:
> Hi Jacek,
>
> On 11/4/2015 1:15 AM, Jacek Anaszewski wrote:
>> Hi Milo,
>>
>> Thanks for the patch. Please find my comments in the code.
>>
>>> diff --git a/Documentation/ABI/testing/sysfs-class-led-lm3633
>>> b/Documentation/ABI/testing/sysfs-class-led-lm3633
>>> new file mode 100644
>>> index 0000000..c1d8759
>>> --- /dev/null
>>> +++ b/Documentation/ABI/testing/sysfs-class-led-lm3633
>>> @@ -0,0 +1,60 @@
>>> +LM3633 LED driver generates programmable pattern via the sysfs.
>>> +
>>> +LED Pattern Generator Structure
>>> +
>>> + (3)
>>> + (a) ---------------> ___________
>>> + / \
>>> + (2) / \ (4)
>>> + (b) ----> _________/ \_________ ...
>>> + (1) (5)
>>> +
>>> + |<----- period -----> |
>>> +
>>> +What: /sys/class/leds/<led>/pattern_times
>>
>> "time" noun is uncountable.
>>
>>> +Date: Oct 2015
>>> +KernelVersion: 4.3
>>
>> These properties certainly will not appear in 4.3.
>
> Oops! 4.4 gonna be OK?

We have currently 4.4 merge window, so the most plausible is 4.5.

>>
>>> +Contact: Milo Kim <[email protected]>
>>> +Description: read/write
>>> + Set pattern time dimension. There are five arguments.
>>> + (1) startup delay
>>> + (2) rising dimming time
>>> + (3) how much time stays at high level
>>> + (4) falling dimming time
>>> + (5) how much time stays at low level
>>> + Ranges are
>>> + (1), (3), (5): 0 ~ 10000. Unit is millisecond.
>>> + (2), (4): 0 ~ 16000. Unit is millisecond.
>>> +
>>> + Example:
>>> + No delay, rising 200ms, high 300ms, falling 100ms,
>>> low 400ms.
>>> + echo "0 200 300 100 400" >
>>> /sys/class/leds/<led>/pattern_times
>>> +
>>> + cat /sys/class/leds/<led>/pattern_times
>>> + delay: 0, rise: 200, high: 300, fall: 100, low: 400
>>
>> Generally a sysfs attribute should represent a single value.
>> There are cases where the attribute comprises a list of space separated
>> values, but certainly colons and commas adds to much noise, and are
>> cumbersome to parse. I'd opt for creating a separate sysfs attribute
>> for each of the above 5 properties.
>
> Got it, thanks!
>
>>
>>> +What: /sys/class/leds/<led>/pattern_levels
>>> +Date: Oct 2015
>>> +KernelVersion: 4.3
>>> +Contact: Milo Kim <[email protected]>
>>> +Description: read/write
>>> + Set pattern level(brightness). There are two arguments.
>>> + (a) Low brightness level
>>> + (b) High brightness level
>>> + Ranges are from 0 to 255.
>>> +
>>> + Example:
>>> + Low level is 0, high level is 255.
>>> + echo "0 255" > /sys/class/leds/<led>/pattern_levels
>>
>> I'd go also for two separate attributes. E.g. pattern_brightness_lo and
>> pattern_brightness_hi, or maybe you'll have better idea.
>
> OK.
>
>>
>>> + cat /sys/class/leds/<led>/pattern_levels
>>> + low brightness: 0, high brightness: 255
>>> +
>>> +What: /sys/class/leds/<led>/run_pattern
>>> +Date: Oct 2015
>>> +KernelVersion: 4.3
>>> +Contact: Milo Kim <[email protected]>
>>> +Description: write only
>>> + After 'pattern_times' and 'pattern_levels' are updated,
>>> + run the pattern by writing 1 to 'run_pattern'.
>>> + To stop running pattern, writes 0 to 'run_pattern'.
>>
>> I wonder how registering an in-driver trigger would work. It would
>> allow for hiding above pattern attributes when the trigger is inactive,
>> and thus making the sysfs interface more transparent. You could avoid
>> the need for run_pattern attribute, as setting the trigger would itself
>> activate the pattern, and setting brightness to 0 would turn it off.
>
> I like this idea, let me try to fix it.
>
>>> +/**
>>> + * struct ti_lmu_led
>>> + *
>>> + * @chip: Pointer to parent LED device
>>> + * @bank_id: LED bank ID
>>> + * @cdev: LED subsystem device structure
>>> + * @name: LED channel name
>>> + * @led_string: LED string configuration.
>>> + * Bit mask is set on parsing DT.
>>> + * @imax: [Optional] Max current index.
>>> + * It's result of ti_lmu_get_current_code().
>>
>> Why is this optional?
>
> You're correct, this is not optional. DT property is optional.
>
>>> +static ssize_t lm3633_led_store_pattern_levels(struct device *dev,
>>> + struct device_attribute *attr,
>>> + const char *buf, size_t len)
>>> +{
>>> + struct ti_lmu_led *lmu_led = to_ti_lmu_led(dev);
>>> + struct ti_lmu_led_chip *chip = lmu_led->chip;
>>> + unsigned int low, high;
>>> + u8 reg, offset, val;
>>> + int ret;
>>> +
>>> + /*
>>> + * Sequence
>>> + *
>>> + * 1) Read pattern level data
>>> + * 2) Disable a bank before programming a pattern
>>> + * 3) Update LOW BRIGHTNESS register
>>> + * 4) Update HIGH BRIGHTNESS register
>>> + *
>>> + * Level register addresses have offset number based on the LED
>>> bank.
>>> + */
>>> +
>>> + ret = sscanf(buf, "%u %u", &low, &high);
>>> + if (ret != 2)
>>> + return -EINVAL;
>>> +
>>> + low = min_t(unsigned int, low, LM3633_LED_MAX_BRIGHTNESS);
>>
>> Why don't you take into account the value defined by led-max-microamp
>> DT property here?
>
> 'low' and 'high' are brightness value. The range is from 0 to 255. It is
> mostly related with LED sysfs - /sys/class/led/<led>/brightness.
> On the other hand, led-max-microamp is current limit. It is from 5mA to
> 30mA. It's different configuration in this device.

Doesn't the current has direct influence on the LED brightness?
Are there other means for adjusting brightness than current setting?
I see in your enum ti_lmu_max_current, that there are 26 possible
current levels. I think that they should reflect 26 possible
brightness levels, so max_brightness can be at most 26.

led-max-microamp was designed for defining max brightness limit.
It should be converted into max brightness level in the driver and
assigned to max_brightness property of struct led_classdev.
This attribute overrides legacy 0-255 brightness scale.

>>> +static void lm3633_led_work(struct work_struct *work)
>>> +{
>>> + struct ti_lmu_led *lmu_led = container_of(work, struct ti_lmu_led,
>>> + work);
>>> + struct ti_lmu_led_chip *chip = lmu_led->chip;
>>> + int ret;
>>> +
>>> + mutex_lock(&chip->lock);
>>> +
>>> + ret = ti_lmu_write_byte(chip->lmu,
>>> + LM3633_REG_BRT_LVLED_BASE + lmu_led->bank_id,
>>> + lmu_led->brightness);
>>> + if (ret) {
>>> + mutex_unlock(&chip->lock);
>>> + return;
>>> + }
>>> +
>>> + if (lmu_led->brightness == 0)
>>> + lm3633_led_disable_bank(lmu_led);
>>> + else
>>> + lm3633_led_enable_bank(lmu_led);
>>
>> Is it possible to control a brightness of a whole bank only,
>> and not individual LEDs?
>
> No, LM3633 has internal control banks. Let me assume that two LED groups
> are assigned below.
> LED 1, 2, 3 - RGB
> LED 4 - status
> Two control banks should be allocated. The bank should be controlled
> separately. If we try to enable/disabe all banks, then 6 output LED
> channels are controlled at the same time.

OK, I'll wait for the next version of the patch to discuss this in
detail.

>>> +static int lm3633_led_init(struct ti_lmu_led *lmu_led, int bank_id)
>>> +{
>>> + struct device *dev = lmu_led->chip->dev;
>>> + char name[12];
>>> + int ret;
>>> +
>>> + /*
>>> + * Sequence
>>> + *
>>> + * 1) Configure LED bank which is used for brightness control
>>> + * 2) Set max current for each output channel
>>> + * 3) Add LED device
>>> + */
>>> +
>>> + ret = lm3633_led_config_bank(lmu_led);
>>> + if (ret) {
>>> + dev_err(dev, "Output bank register err: %d\n", ret);
>>> + return ret;
>>> + }
>>> +
>>> + ret = lm3633_led_set_max_current(lmu_led);
>>> + if (ret) {
>>> + dev_err(dev, "Set max current err: %d\n", ret);
>>> + return ret;
>>> + }
>>> +
>>> + lmu_led->cdev.max_brightness = LM3633_LED_MAX_BRIGHTNESS;
>>
>> The value assigned here should be determined by led-max-microamp
>> DT property.
>
> Ditto. Current limit is different configuration from brightness value.

It should be converted to the corresponding brightness level. See other
LED class drivers using led-max-microamp property (e.g. leds-aat1290).

--
Best Regards,
Jacek Anaszewski

2015-11-11 02:16:13

by Kim, Milo

[permalink] [raw]
Subject: Re: [PATCH RESEND 15/16] leds: add LM3633 driver

Hi Jacek,

On 11/10/2015 10:44 PM, Jacek Anaszewski wrote:
>>>> +static ssize_t lm3633_led_store_pattern_levels(struct device *dev,
>>>> >>>+ struct device_attribute *attr,
>>>> >>>+ const char *buf, size_t len)
>>>> >>>+{
>>>> >>>+ struct ti_lmu_led *lmu_led = to_ti_lmu_led(dev);
>>>> >>>+ struct ti_lmu_led_chip *chip = lmu_led->chip;
>>>> >>>+ unsigned int low, high;
>>>> >>>+ u8 reg, offset, val;
>>>> >>>+ int ret;
>>>> >>>+
>>>> >>>+ /*
>>>> >>>+ * Sequence
>>>> >>>+ *
>>>> >>>+ * 1) Read pattern level data
>>>> >>>+ * 2) Disable a bank before programming a pattern
>>>> >>>+ * 3) Update LOW BRIGHTNESS register
>>>> >>>+ * 4) Update HIGH BRIGHTNESS register
>>>> >>>+ *
>>>> >>>+ * Level register addresses have offset number based on the LED
>>>> >>>bank.
>>>> >>>+ */
>>>> >>>+
>>>> >>>+ ret = sscanf(buf, "%u %u", &low, &high);
>>>> >>>+ if (ret != 2)
>>>> >>>+ return -EINVAL;
>>>> >>>+
>>>> >>>+ low = min_t(unsigned int, low, LM3633_LED_MAX_BRIGHTNESS);
>>> >>
>>> >>Why don't you take into account the value defined by led-max-microamp
>>> >>DT property here?
>> >
>> >'low' and 'high' are brightness value. The range is from 0 to 255. It is
>> >mostly related with LED sysfs -/sys/class/led/<led>/brightness.
>> >On the other hand, led-max-microamp is current limit. It is from 5mA to
>> >30mA. It's different configuration in this device.
> Doesn't the current has direct influence on the LED brightness?
> Are there other means for adjusting brightness than current setting?
> I see in your enum ti_lmu_max_current, that there are 26 possible
> current levels. I think that they should reflect 26 possible
> brightness levels, so max_brightness can be at most 26.

Let me describe LM3633 in more details. I'd like to have your opinion
about led-max-microamp and max_brightness usages. Datasheet would be
better to figure out characteristics.

http://www.ti.com/lit/ds/symlink/lm3633.pdf

Max current level is not same as brightness level in LM3633.
LM3633 device has two parameters for output brightness control.
One is brightness code(base register address is 0x44). The other is
current limit(base register address is 0x22). It also provides hardware
protection like excessive current.

0 <= brightness_code <= 0xff
0 <= current_limit_code <= 0x1f, it means
5mA <= current_limit <= 30mA.

LM3633 device calculates the output current below.

(1) Linear brightness mode
Iout = current_limit * brightness_code/255

(2) Exponential brightness mode
Iout = current_limit * 0.85 ^ (44 - (brightness_code + 1)/5.18)

So output current(Iout) can not be in excess of current_limit.

>
> led-max-microamp was designed for defining max brightness limit.
> It should be converted into max brightness level in the driver and
> assigned to max_brightness property of struct led_classdev.
> This attribute overrides legacy 0-255 brightness scale.
>

It could be applied when brightness is determined by only one parameter
- current level. Flash/torch device would be a good example. In this
device, current setting is directly scaled to the output brightness.

However, LM3633 has two parameters for the brightness control - current
limit and brightness level. Max current setting is one of brightness
control parameters. In this patch, 'led-max-microamp' from DT is
converted to 'current_limit_code'. Then, this value is written once when
the driver is initialized. On the other hand, 'brightness_code' can be
changed at run time. And 'max_brightness' of led_classdev is set to max
brightness register value, 0xff.

It sounds 'led-max-microamp' property might not be a general usage in
LM3633. Do you have some idea?

Best regards,
Milo

2015-11-11 09:49:35

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH RESEND 01/16] Documentation: dt-bindings: mfd: add TI LMU device binding information

On Mon, 02 Nov 2015, Milo Kim wrote:

> This patch describes overall binding for TI LMU MFD devices.
>
> Cc: [email protected]
> Cc: Lee Jones <[email protected]>
> Cc: [email protected]
> Signed-off-by: Milo Kim <[email protected]>
> ---
> Documentation/devicetree/bindings/mfd/ti-lmu.txt | 282 +++++++++++++++++++++++
> 1 file changed, 282 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/mfd/ti-lmu.txt
>
> diff --git a/Documentation/devicetree/bindings/mfd/ti-lmu.txt b/Documentation/devicetree/bindings/mfd/ti-lmu.txt
> new file mode 100644
> index 0000000..7ccf07e
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/mfd/ti-lmu.txt
> @@ -0,0 +1,282 @@
> +TI LMU(Lighting Management Unit) device tree bindings

' ' here -^

> +TI LMU driver supports lighting devices belows.

s/belows./below:/

> + Name Child nodes
> + ------ -------------------------
> + LM3532 Backlight
> + LM3631 Backlight and regulator
> + LM3632 Backlight and regulator
> + LM3633 Backlight, LED and HWMON
> + LM3695 Backlight
> + LM3697 Backlight and HWMON
> +
> +Required properties:
> + - compatible: Should be one of lists below.

s/ lists below./:/

> + "ti,lm3532"
> + "ti,lm3631"
> + "ti,lm3632"
> + "ti,lm3633"
> + "ti,lm3695"
> + "ti,lm3697"
> + - reg: I2C slave address.
> + 0x11 is LM3632
> + 0x29 is LM3631
> + 0x36 is LM3633, LM3697
> + 0x38 is LM3532
> + 0x63 is LM3695

s/is/for/

> +Optional properties:
> + - enable-gpios: A GPIO specifier for hardware enable pin.
> +
> +Required node:
> + - backlight: All LMU devices have backlight child nodes.
> + For the properties, please refer to [1].
> +
> +Optional nodes:
> + - hwmon: Hardware fault monitoring driver for LM3633 and LM3697.
> + For the property, please refer to [2].
> + - leds: LED properties for LM3633. Please refer to [3].
> + - regulators: Regulator properties for LM3631 and LM3632.
> + Please refer to [4].
> +
> +[1] Documentation/devicetree/bindings/video/backlight/ti-lmu-backlight.txt
> +[2] Documentation/devicetree/bindings/hwm/ti-lmu-hwmon.txt
> +[3] Documentation/devicetree/bindings/leds/leds-lm3633.txt
> +[4] Documentation/devicetree/bindings/regulator/lm363x-regulator.txt

s/Documentation/devicetree/bindings/../

> +Examples:

These aren't examples, they're actual DT entries.

Please trim them down to just one, fully enabled node, only to be used
as an 'example'.

> +LM3532 has a backlight device. External GPIO is used for enabling LM3532.
> +
> +lm3532@38 {
> + compatible = "ti,lm3532";
> + reg = <0x38>;
> +
> + enable-gpios = <&pioC 2 GPIO_ACTIVE_HIGH>;
> +
> + backlight {
> + compatible = "ti,lm3532-backlight";
> +
> + lcd {
> + hvled1-used;
> + hvled2-used;
> + hvled3-used;
> +
> + ramp-up-msec = <30>;
> + ramp-down-msec = <0>;
> +
> + backlight-max-microamp = <5000>;
> + };
> + };
> +};
> +
> +LM3631 has 5 regulators with one backlight device.
> +
> +lm3631@29 {
> + compatible = "ti,lm3631";
> + reg = <0x29>;
> +
> + regulators {
> + compatible = "ti,lm363x-regulator";
> +
> + vboost {
> + regulator-name = "lcd_boost";
> + regulator-min-microvolt = <4500000>;
> + regulator-max-microvolt = <6350000>;
> + regulator-always-on;
> + };
> +
> + vcont {
> + regulator-name = "lcd_vcont";
> + regulator-min-microvolt = <1800000>;
> + regulator-max-microvolt = <3300000>;
> + };
> +
> + voref {
> + regulator-name = "lcd_voref";
> + regulator-min-microvolt = <4000000>;
> + regulator-max-microvolt = <6000000>;
> + };
> +
> + vpos {
> + regulator-name = "lcd_vpos";
> + regulator-min-microvolt = <4000000>;
> + regulator-max-microvolt = <6000000>;
> + regulator-boot-on;
> + };
> +
> + vneg {
> + regulator-name = "lcd_vneg";
> + regulator-min-microvolt = <4000000>;
> + regulator-max-microvolt = <6000000>;
> + regulator-boot-on;
> + };
> + };
> +
> + backlight {
> + compatible = "ti,lm3631-backlight";
> +
> + lcd {
> + backlight-name = "lcd_bl";
> + hvled1-used;
> + hvled2-used;
> +
> + ramp-up-msec = <300>;
> + };
> + };
> +};
> +
> +LM3632 has 3 regulators with one backlight device. External GPIO is
> +used for enabling LM3632.
> +
> +lm3632@11 {
> + compatible = "ti,lm3632";
> + reg = <0x11>;
> +
> + enable-gpios = <&pioC 2 GPIO_ACTIVE_HIGH>;
> +
> + regulators {
> + compatible = "ti,lm363x-regulator";
> +
> + ti,lcm-en1-gpio = <&pioC 0 GPIO_ACTIVE_HIGH>;
> + ti,lcm-en2-gpio = <&pioC 1 GPIO_ACTIVE_HIGH>;
> +
> + vboost {
> + regulator-name = "lcd_boost";
> + regulator-min-microvolt = <4500000>;
> + regulator-max-microvolt = <6400000>;
> + regulator-always-on;
> + };
> +
> + vpos {
> + regulator-name = "lcd_vpos";
> + regulator-min-microvolt = <4000000>;
> + regulator-max-microvolt = <6000000>;
> + };
> +
> + vneg {
> + regulator-name = "lcd_vneg";
> + regulator-min-microvolt = <4000000>;
> + regulator-max-microvolt = <6000000>;
> + };
> + };
> +
> + backlight {
> + compatible = "ti,lm3632-backlight";
> +
> + lcd {
> + backlight-name = "lcd";
> + hvled1-used;
> + hvled2-used;
> + };
> + };
> +};
> +
> +LM3633 has multiple backlight channels, LED channels and hardware fault
> +monitoring driver. External GPIO is used for enabling LM3633.
> +
> +lm3633@36 {
> + compatible = "ti,lm3633";
> + reg = <0x36>;
> +
> + enable-gpios = <&pioC 2 GPIO_ACTIVE_HIGH>;
> +
> + backlight {
> + compatible = "ti,lm3633-backlight";
> +
> + pwms = <&pwm0 0 10000 0>; /* pwm number, period, polarity */
> + pwm-names = "lmu-backlight";
> +
> + main {
> + backlight-name = "main_lcd";
> + hvled2-used;
> + hvled3-used;
> + backlight-max-microamp = <20000>;
> +
> + ramp-up-msec = <500>;
> + ramp-down-msec = <500>;
> + };
> +
> + front {
> + backlight-name = "front_lcd";
> + hvled1-used;
> +
> + ramp-up-msec = <1000>;
> + ramp-down-msec = <0>;
> +
> + pwm-period = <10000>;
> + };
> + };
> +
> + leds {
> + compatible = "ti,lm3633-leds";
> +
> + chan2 {
> + channel-name = "status";
> + lvled2-used;
> + led-max-microamp = <6000>;
> + };
> +
> + chan456 {
> + channel-name = "rgb";
> + lvled4-used;
> + lvled5-used;
> + lvled6-used;
> + };
> + };
> +
> + hwmon {
> + compatible = "ti,lm3633-hwmon";
> + };
> +};
> +
> +LM3695 is single backlight device.
> +
> +lm3695@63 {
> + compatible = "ti,lm3695";
> + reg = <0x63>;
> +
> + backlight {
> + compatible = "ti,lm3695-backlight";
> +
> + lcd {
> + hvled1-used;
> + hvled2-used;
> + backlight-max-microamp = <20000>;
> + };
> + };
> +};
> +
> +LM3697 has one backlight device and hardware fault monitoring driver.
> +External GPIO is used for enabling LM3697.
> +
> +lm3697@36 {
> + compatible = "ti,lm3697";
> + reg = <0x36>;
> +
> + enable-gpios = <&pioC 2 GPIO_ACTIVE_HIGH>;
> +
> + backlight {
> + compatible = "ti,lm3697-backlight";
> +
> + pwms = <&pwm0 0 10000 0>; /* pwm number, period, polarity */
> + pwm-names = "lmu-backlight";
> +
> + lcd {
> + backlight-name = "bl";
> + hvled1-used;
> + hvled2-used;
> + hvled3-used;
> + backlight-max-microamp = <20000>;
> +
> + ramp-up-msec = <500>;
> + ramp-down-msec = <500>;
> + pwm-period = <10000>;
> + };
> + };
> +
> + hwmon {
> + compatible = "ti,lm3697-hwmon";
> + };
> +};

--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

2015-11-12 00:05:49

by Kim, Milo

[permalink] [raw]
Subject: Re: [PATCH RESEND 01/16] Documentation: dt-bindings: mfd: add TI LMU device binding information

Thanks for all your comments. I'll create the 2nd patch-set in few weeks.

Best regards,
Milo

On 11/11/2015 6:49 PM, Lee Jones wrote:
> On Mon, 02 Nov 2015, Milo Kim wrote:
>
>> This patch describes overall binding for TI LMU MFD devices.
>>
>> Cc: [email protected]
>> Cc: Lee Jones <[email protected]>
>> Cc: [email protected]
>> Signed-off-by: Milo Kim <[email protected]>
>> ---
>> Documentation/devicetree/bindings/mfd/ti-lmu.txt | 282 +++++++++++++++++++++++
>> 1 file changed, 282 insertions(+)
>> create mode 100644 Documentation/devicetree/bindings/mfd/ti-lmu.txt
>>
>> diff --git a/Documentation/devicetree/bindings/mfd/ti-lmu.txt b/Documentation/devicetree/bindings/mfd/ti-lmu.txt
>> new file mode 100644
>> index 0000000..7ccf07e
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/mfd/ti-lmu.txt
>> @@ -0,0 +1,282 @@
>> +TI LMU(Lighting Management Unit) device tree bindings
>
> ' ' here -^
>
>> +TI LMU driver supports lighting devices belows.
>
> s/belows./below:/
>
>> + Name Child nodes
>> + ------ -------------------------
>> + LM3532 Backlight
>> + LM3631 Backlight and regulator
>> + LM3632 Backlight and regulator
>> + LM3633 Backlight, LED and HWMON
>> + LM3695 Backlight
>> + LM3697 Backlight and HWMON
>> +
>> +Required properties:
>> + - compatible: Should be one of lists below.
>
> s/ lists below./:/
>
>> + "ti,lm3532"
>> + "ti,lm3631"
>> + "ti,lm3632"
>> + "ti,lm3633"
>> + "ti,lm3695"
>> + "ti,lm3697"
>> + - reg: I2C slave address.
>> + 0x11 is LM3632
>> + 0x29 is LM3631
>> + 0x36 is LM3633, LM3697
>> + 0x38 is LM3532
>> + 0x63 is LM3695
>
> s/is/for/
>
>> +Optional properties:
>> + - enable-gpios: A GPIO specifier for hardware enable pin.
>> +
>> +Required node:
>> + - backlight: All LMU devices have backlight child nodes.
>> + For the properties, please refer to [1].
>> +
>> +Optional nodes:
>> + - hwmon: Hardware fault monitoring driver for LM3633 and LM3697.
>> + For the property, please refer to [2].
>> + - leds: LED properties for LM3633. Please refer to [3].
>> + - regulators: Regulator properties for LM3631 and LM3632.
>> + Please refer to [4].
>> +
>> +[1] Documentation/devicetree/bindings/video/backlight/ti-lmu-backlight.txt
>> +[2] Documentation/devicetree/bindings/hwm/ti-lmu-hwmon.txt
>> +[3] Documentation/devicetree/bindings/leds/leds-lm3633.txt
>> +[4] Documentation/devicetree/bindings/regulator/lm363x-regulator.txt
>
> s/Documentation/devicetree/bindings/../
>
>> +Examples:
>
> These aren't examples, they're actual DT entries.
>
> Please trim them down to just one, fully enabled node, only to be used
> as an 'example'.
>
>> +LM3532 has a backlight device. External GPIO is used for enabling LM3532.
>> +
>> +lm3532@38 {
>> + compatible = "ti,lm3532";
>> + reg = <0x38>;
>> +
>> + enable-gpios = <&pioC 2 GPIO_ACTIVE_HIGH>;
>> +
>> + backlight {
>> + compatible = "ti,lm3532-backlight";
>> +
>> + lcd {
>> + hvled1-used;
>> + hvled2-used;
>> + hvled3-used;
>> +
>> + ramp-up-msec = <30>;
>> + ramp-down-msec = <0>;
>> +
>> + backlight-max-microamp = <5000>;
>> + };
>> + };
>> +};
>> +
>> +LM3631 has 5 regulators with one backlight device.
>> +
>> +lm3631@29 {
>> + compatible = "ti,lm3631";
>> + reg = <0x29>;
>> +
>> + regulators {
>> + compatible = "ti,lm363x-regulator";
>> +
>> + vboost {
>> + regulator-name = "lcd_boost";
>> + regulator-min-microvolt = <4500000>;
>> + regulator-max-microvolt = <6350000>;
>> + regulator-always-on;
>> + };
>> +
>> + vcont {
>> + regulator-name = "lcd_vcont";
>> + regulator-min-microvolt = <1800000>;
>> + regulator-max-microvolt = <3300000>;
>> + };
>> +
>> + voref {
>> + regulator-name = "lcd_voref";
>> + regulator-min-microvolt = <4000000>;
>> + regulator-max-microvolt = <6000000>;
>> + };
>> +
>> + vpos {
>> + regulator-name = "lcd_vpos";
>> + regulator-min-microvolt = <4000000>;
>> + regulator-max-microvolt = <6000000>;
>> + regulator-boot-on;
>> + };
>> +
>> + vneg {
>> + regulator-name = "lcd_vneg";
>> + regulator-min-microvolt = <4000000>;
>> + regulator-max-microvolt = <6000000>;
>> + regulator-boot-on;
>> + };
>> + };
>> +
>> + backlight {
>> + compatible = "ti,lm3631-backlight";
>> +
>> + lcd {
>> + backlight-name = "lcd_bl";
>> + hvled1-used;
>> + hvled2-used;
>> +
>> + ramp-up-msec = <300>;
>> + };
>> + };
>> +};
>> +
>> +LM3632 has 3 regulators with one backlight device. External GPIO is
>> +used for enabling LM3632.
>> +
>> +lm3632@11 {
>> + compatible = "ti,lm3632";
>> + reg = <0x11>;
>> +
>> + enable-gpios = <&pioC 2 GPIO_ACTIVE_HIGH>;
>> +
>> + regulators {
>> + compatible = "ti,lm363x-regulator";
>> +
>> + ti,lcm-en1-gpio = <&pioC 0 GPIO_ACTIVE_HIGH>;
>> + ti,lcm-en2-gpio = <&pioC 1 GPIO_ACTIVE_HIGH>;
>> +
>> + vboost {
>> + regulator-name = "lcd_boost";
>> + regulator-min-microvolt = <4500000>;
>> + regulator-max-microvolt = <6400000>;
>> + regulator-always-on;
>> + };
>> +
>> + vpos {
>> + regulator-name = "lcd_vpos";
>> + regulator-min-microvolt = <4000000>;
>> + regulator-max-microvolt = <6000000>;
>> + };
>> +
>> + vneg {
>> + regulator-name = "lcd_vneg";
>> + regulator-min-microvolt = <4000000>;
>> + regulator-max-microvolt = <6000000>;
>> + };
>> + };
>> +
>> + backlight {
>> + compatible = "ti,lm3632-backlight";
>> +
>> + lcd {
>> + backlight-name = "lcd";
>> + hvled1-used;
>> + hvled2-used;
>> + };
>> + };
>> +};
>> +
>> +LM3633 has multiple backlight channels, LED channels and hardware fault
>> +monitoring driver. External GPIO is used for enabling LM3633.
>> +
>> +lm3633@36 {
>> + compatible = "ti,lm3633";
>> + reg = <0x36>;
>> +
>> + enable-gpios = <&pioC 2 GPIO_ACTIVE_HIGH>;
>> +
>> + backlight {
>> + compatible = "ti,lm3633-backlight";
>> +
>> + pwms = <&pwm0 0 10000 0>; /* pwm number, period, polarity */
>> + pwm-names = "lmu-backlight";
>> +
>> + main {
>> + backlight-name = "main_lcd";
>> + hvled2-used;
>> + hvled3-used;
>> + backlight-max-microamp = <20000>;
>> +
>> + ramp-up-msec = <500>;
>> + ramp-down-msec = <500>;
>> + };
>> +
>> + front {
>> + backlight-name = "front_lcd";
>> + hvled1-used;
>> +
>> + ramp-up-msec = <1000>;
>> + ramp-down-msec = <0>;
>> +
>> + pwm-period = <10000>;
>> + };
>> + };
>> +
>> + leds {
>> + compatible = "ti,lm3633-leds";
>> +
>> + chan2 {
>> + channel-name = "status";
>> + lvled2-used;
>> + led-max-microamp = <6000>;
>> + };
>> +
>> + chan456 {
>> + channel-name = "rgb";
>> + lvled4-used;
>> + lvled5-used;
>> + lvled6-used;
>> + };
>> + };
>> +
>> + hwmon {
>> + compatible = "ti,lm3633-hwmon";
>> + };
>> +};
>> +
>> +LM3695 is single backlight device.
>> +
>> +lm3695@63 {
>> + compatible = "ti,lm3695";
>> + reg = <0x63>;
>> +
>> + backlight {
>> + compatible = "ti,lm3695-backlight";
>> +
>> + lcd {
>> + hvled1-used;
>> + hvled2-used;
>> + backlight-max-microamp = <20000>;
>> + };
>> + };
>> +};
>> +
>> +LM3697 has one backlight device and hardware fault monitoring driver.
>> +External GPIO is used for enabling LM3697.
>> +
>> +lm3697@36 {
>> + compatible = "ti,lm3697";
>> + reg = <0x36>;
>> +
>> + enable-gpios = <&pioC 2 GPIO_ACTIVE_HIGH>;
>> +
>> + backlight {
>> + compatible = "ti,lm3697-backlight";
>> +
>> + pwms = <&pwm0 0 10000 0>; /* pwm number, period, polarity */
>> + pwm-names = "lmu-backlight";
>> +
>> + lcd {
>> + backlight-name = "bl";
>> + hvled1-used;
>> + hvled2-used;
>> + hvled3-used;
>> + backlight-max-microamp = <20000>;
>> +
>> + ramp-up-msec = <500>;
>> + ramp-down-msec = <500>;
>> + pwm-period = <10000>;
>> + };
>> + };
>> +
>> + hwmon {
>> + compatible = "ti,lm3697-hwmon";
>> + };
>> +};
>

2015-11-12 09:04:35

by Jacek Anaszewski

[permalink] [raw]
Subject: Re: [PATCH RESEND 15/16] leds: add LM3633 driver

Hi Milo,

On 11/11/2015 03:16 AM, Kim, Milo wrote:
> Hi Jacek,
>
> On 11/10/2015 10:44 PM, Jacek Anaszewski wrote:
>>>>> +static ssize_t lm3633_led_store_pattern_levels(struct device *dev,
>>>>> >>>+ struct device_attribute *attr,
>>>>> >>>+ const char *buf, size_t len)
>>>>> >>>+{
>>>>> >>>+ struct ti_lmu_led *lmu_led = to_ti_lmu_led(dev);
>>>>> >>>+ struct ti_lmu_led_chip *chip = lmu_led->chip;
>>>>> >>>+ unsigned int low, high;
>>>>> >>>+ u8 reg, offset, val;
>>>>> >>>+ int ret;
>>>>> >>>+
>>>>> >>>+ /*
>>>>> >>>+ * Sequence
>>>>> >>>+ *
>>>>> >>>+ * 1) Read pattern level data
>>>>> >>>+ * 2) Disable a bank before programming a pattern
>>>>> >>>+ * 3) Update LOW BRIGHTNESS register
>>>>> >>>+ * 4) Update HIGH BRIGHTNESS register
>>>>> >>>+ *
>>>>> >>>+ * Level register addresses have offset number based on the
>>>>> LED
>>>>> >>>bank.
>>>>> >>>+ */
>>>>> >>>+
>>>>> >>>+ ret = sscanf(buf, "%u %u", &low, &high);
>>>>> >>>+ if (ret != 2)
>>>>> >>>+ return -EINVAL;
>>>>> >>>+
>>>>> >>>+ low = min_t(unsigned int, low, LM3633_LED_MAX_BRIGHTNESS);
>>>> >>
>>>> >>Why don't you take into account the value defined by led-max-microamp
>>>> >>DT property here?
>>> >
>>> >'low' and 'high' are brightness value. The range is from 0 to 255.
>>> It is
>>> >mostly related with LED sysfs -/sys/class/led/<led>/brightness.
>>> >On the other hand, led-max-microamp is current limit. It is from 5mA to
>>> >30mA. It's different configuration in this device.
>> Doesn't the current has direct influence on the LED brightness?
>> Are there other means for adjusting brightness than current setting?
>> I see in your enum ti_lmu_max_current, that there are 26 possible
>> current levels. I think that they should reflect 26 possible
>> brightness levels, so max_brightness can be at most 26.
>
> Let me describe LM3633 in more details. I'd like to have your opinion
> about led-max-microamp and max_brightness usages. Datasheet would be
> better to figure out characteristics.
>
> http://www.ti.com/lit/ds/symlink/lm3633.pdf
>
> Max current level is not same as brightness level in LM3633.
> LM3633 device has two parameters for output brightness control.
> One is brightness code(base register address is 0x44). The other is
> current limit(base register address is 0x22). It also provides hardware
> protection like excessive current.
>
> 0 <= brightness_code <= 0xff
> 0 <= current_limit_code <= 0x1f, it means
> 5mA <= current_limit <= 30mA.
>
> LM3633 device calculates the output current below.
>
> (1) Linear brightness mode
> Iout = current_limit * brightness_code/255
>
> (2) Exponential brightness mode
> Iout = current_limit * 0.85 ^ (44 - (brightness_code + 1)/5.18)
>
> So output current(Iout) can not be in excess of current_limit.
>
>>
>> led-max-microamp was designed for defining max brightness limit.
>> It should be converted into max brightness level in the driver and
>> assigned to max_brightness property of struct led_classdev.
>> This attribute overrides legacy 0-255 brightness scale.
>>
>
> It could be applied when brightness is determined by only one parameter
> - current level. Flash/torch device would be a good example. In this
> device, current setting is directly scaled to the output brightness.
>
> However, LM3633 has two parameters for the brightness control - current
> limit and brightness level. Max current setting is one of brightness
> control parameters. In this patch, 'led-max-microamp' from DT is
> converted to 'current_limit_code'. Then, this value is written once when
> the driver is initialized. On the other hand, 'brightness_code' can be
> changed at run time. And 'max_brightness' of led_classdev is set to max
> brightness register value, 0xff.
>
> It sounds 'led-max-microamp' property might not be a general usage in
> LM3633. Do you have some idea?

There are defined formulas for calculating the current for given
combination of current_limit and brightness_code. If you made one
of this parameters constant, then you'd be able to control the current
with the other one. I propose to set current limit to max, i.e.
"Full-Scale Current Setting" (base addr 0x22 for LVLEDn) should
be set to 0x1F (29.8 mA). Then, you can control the output current
with the registers "Control N Brightness" (base addr 0x44 for LVLEDn).

Taking above into account, you can set the led-max-microamp to the
exact max current value you want for given LED. The driver will be
responsible for clamping this to the greatest possible value of
"Control N Brightness", which will be assigned to max_brightness
property.

You can refer to drivers/leds/leds-aat1290.c, which presents
the same approach.

Apart from the above considerations - in the beginning of the
next week I will apply LED core optimizations to the for-next
branch of LED git tree, which will remove the need for using
work queues internally in LED class drivers. Please rebase your
code on those changes, remove work queue use from your driver,
and implement brightness_set_blocking op instead of brightness_set.
You can refer to the patches on devel branch, which adjust
flash drivers to those modifications.

git://git.kernel.org/pub/scm/linux/kernel/git/j.anaszewski/linux-leds.git
branch: devel
base commit:
26eb03b leds: core: Add two new LED_BLINK_ flags

--
Best Regards,
Jacek Anaszewski

2015-11-20 09:23:01

by Jacek Anaszewski

[permalink] [raw]
Subject: Re: [PATCH RESEND 15/16] leds: add LM3633 driver

On 11/10/2015 08:38 AM, Kim, Milo wrote:
[...]
>>> + cat /sys/class/leds/<led>/pattern_levels
>>> + low brightness: 0, high brightness: 255
>>> +
>>> +What: /sys/class/leds/<led>/run_pattern
>>> +Date: Oct 2015
>>> +KernelVersion: 4.3
>>> +Contact: Milo Kim <[email protected]>
>>> +Description: write only
>>> + After 'pattern_times' and 'pattern_levels' are updated,
>>> + run the pattern by writing 1 to 'run_pattern'.
>>> + To stop running pattern, writes 0 to 'run_pattern'.
>>
>> I wonder how registering an in-driver trigger would work. It would
>> allow for hiding above pattern attributes when the trigger is inactive,
>> and thus making the sysfs interface more transparent. You could avoid
>> the need for run_pattern attribute, as setting the trigger would itself
>> activate the pattern, and setting brightness to 0 would turn it off.
>
> I like this idea, let me try to fix it.

After thinking it over, I came to conclusion that implementing it as
an in-driver trigger is not a proper way to go, since triggers are
defined as kernel based source of LED events.

This is somehow abused in case of timer trigger which takes hardware
blinking feature as a first choice and applies software blinking as
a fallback only. To be consistent with that, we could go for adding
generic pattern trigger and add a led_pattern_set() API, similarly
to existing led_blink_set().

The problem is that different LED controllers may implement blinking
patterns that are configured with different set of parameters. This
subject would definitely require thorough analysis.

For now, please just expose pattern settings as separate sysfs
attributes of a LED class device.

--
Best Regards,
Jacek Anaszewski

2015-11-22 23:40:28

by Kim, Milo

[permalink] [raw]
Subject: Re: [PATCH RESEND 15/16] leds: add LM3633 driver

Hi Jacek,

On 11/20/2015 6:22 PM, Jacek Anaszewski wrote:
> On 11/10/2015 08:38 AM, Kim, Milo wrote:
> [...]
>>>> + cat /sys/class/leds/<led>/pattern_levels
>>>> + low brightness: 0, high brightness: 255
>>>> +
>>>> +What: /sys/class/leds/<led>/run_pattern
>>>> +Date: Oct 2015
>>>> +KernelVersion: 4.3
>>>> +Contact: Milo Kim <[email protected]>
>>>> +Description: write only
>>>> + After 'pattern_times' and 'pattern_levels' are updated,
>>>> + run the pattern by writing 1 to 'run_pattern'.
>>>> + To stop running pattern, writes 0 to 'run_pattern'.
>>>
>>> I wonder how registering an in-driver trigger would work. It would
>>> allow for hiding above pattern attributes when the trigger is inactive,
>>> and thus making the sysfs interface more transparent. You could avoid
>>> the need for run_pattern attribute, as setting the trigger would itself
>>> activate the pattern, and setting brightness to 0 would turn it off.
>>
>> I like this idea, let me try to fix it.
>
> After thinking it over, I came to conclusion that implementing it as
> an in-driver trigger is not a proper way to go, since triggers are
> defined as kernel based source of LED events.
>
> This is somehow abused in case of timer trigger which takes hardware
> blinking feature as a first choice and applies software blinking as
> a fallback only. To be consistent with that, we could go for adding
> generic pattern trigger and add a led_pattern_set() API, similarly
> to existing led_blink_set().
>
> The problem is that different LED controllers may implement blinking
> patterns that are configured with different set of parameters. This
> subject would definitely require thorough analysis.
>
> For now, please just expose pattern settings as separate sysfs
> attributes of a LED class device.
>

Thanks for your suggestion.
Then, LM3633 LED driver will support 8 device attributes.

pattern_time_delay
pattern_time_rise
pattern_time_high
pattern_time_fall
pattern_time_low
pattern_brightness_low
pattern_brightness_high
pattern_run_pattern

Details will be updated in Documentation/ABI/testing/sysfs-class-led-lm3633.

Best regards,
Milo

2015-11-23 10:30:36

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH RESEND 06/16] mfd: add TI LMU driver

On Mon, 02 Nov 2015, Milo Kim wrote:

> TI LMU(Lighting Management Unit) driver supports lighting devices below.

Really small nit, I'd prefer a ' ' between "LMU" and "(".

> LM3532, LM3631, LM3632, LM3633, LM3695 and LM3697.
>
> LMU devices have common features.
> - I2C interface for accessing device registers
> - Hardware enable pin control
> - Backlight brightness control
> - Max current conversion helper function
> - Notifier for hardware fault monitoring
> - Regulators for LCD display bias
>
> It contains backlight, HWMON, LED and regulator driver.
>
> Backlight
> ---------
> It's handled by TI LMU backlight common driver and chip dependent driver.
> Please refer to separate patches for ti-lmu-backlight.
>
> HWMON
> -----
> LM3633 and LM3697 provide hardware monitoring feature.
> It enables opened or shorted circuit detection.
> After monitoring is done, each device should be re-initialized.
> Notifier is used for this case.
> Please refer to separate patch for ti-lmu-hwmon.
>
> LED indicator
> -------------
> LM3633 has 6 indicator LEDs. Programmable pattern is also supported.
> Please refer to separate patch for leds-lm3633.
>
> Regulator
> ---------
> LM3631 has 5 regulators for the display bias.
> LM3632 supports 3 regulators. One consolidated driver enables it.
> Please refer to separate patch for lm363x-regulator.
>
> Cc: Lee Jones <[email protected]>
> Cc: Jingoo Han <[email protected]>
> Cc: Guenter Roeck <[email protected]>
> Cc: Jean Delvare <[email protected]>
> Cc: Jacek Anaszewski <[email protected]>
> Cc: Mark Brown <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Cc: [email protected]
> Cc: [email protected]
> Signed-off-by: Milo Kim <[email protected]>
> ---
> drivers/mfd/Kconfig | 12 ++
> drivers/mfd/Makefile | 1 +
> drivers/mfd/ti-lmu.c | 324 ++++++++++++++++++++++++++++++++++++
> include/linux/mfd/ti-lmu-register.h | 277 ++++++++++++++++++++++++++++++
> include/linux/mfd/ti-lmu.h | 81 +++++++++
> 5 files changed, 695 insertions(+)
> create mode 100644 drivers/mfd/ti-lmu.c
> create mode 100644 include/linux/mfd/ti-lmu-register.h
> create mode 100644 include/linux/mfd/ti-lmu.h
>
> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> index 99d6367..a53a38e 100644
> --- a/drivers/mfd/Kconfig
> +++ b/drivers/mfd/Kconfig
> @@ -1037,6 +1037,18 @@ config MFD_LP8788
> TI LP8788 PMU supports regulators, battery charger, RTC,
> ADC, backlight driver and current sinks.
>
> +config MFD_TI_LMU
> + tristate "TI Lighting Management Unit driver"
> + depends on I2C
> + select MFD_CORE
> + select REGMAP_I2C
> + help
> + Say yes here to enable support for TI LMU chips.
> +
> + TI LMU MFD supports LM3532, LM3631, LM3632, LM3633, LM3695 and LM3697.
> + It consists of backlight, hwmon, LED and regulator driver.
> + It provides consistent device controls for lighting functions.
> +
> config MFD_OMAP_USB_HOST
> bool "TI OMAP USBHS core and TLL driver"
> depends on USB_EHCI_HCD_OMAP || USB_OHCI_HCD_OMAP3
> diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
> index a59e3fc..32920f8 100644
> --- a/drivers/mfd/Makefile
> +++ b/drivers/mfd/Makefile
> @@ -110,6 +110,7 @@ obj-$(CONFIG_MFD_AXP20X) += axp20x.o
>
> obj-$(CONFIG_MFD_LP3943) += lp3943.o
> obj-$(CONFIG_MFD_LP8788) += lp8788.o lp8788-irq.o
> +obj-$(CONFIG_MFD_TI_LMU) += ti-lmu.o
>
> da9055-objs := da9055-core.o da9055-i2c.o
> obj-$(CONFIG_MFD_DA9055) += da9055.o
> diff --git a/drivers/mfd/ti-lmu.c b/drivers/mfd/ti-lmu.c
> new file mode 100644
> index 0000000..e86a0ea
> --- /dev/null
> +++ b/drivers/mfd/ti-lmu.c
> @@ -0,0 +1,324 @@
> +/*
> + * TI LMU(Lighting Management Unit) Core Driver
> + *
> + * Copyright 2015 Texas Instruments
> + *
> + * Author: Milo Kim <[email protected]>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + */
> +
> +#include <linux/delay.h>
> +#include <linux/err.h>
> +#include <linux/gpio.h>
> +#include <linux/i2c.h>
> +#include <linux/kernel.h>
> +#include <linux/mfd/core.h>
> +#include <linux/mfd/ti-lmu.h>
> +#include <linux/mfd/ti-lmu-register.h>
> +#include <linux/module.h>
> +#include <linux/notifier.h>
> +#include <linux/of.h>
> +#include <linux/of_device.h>
> +#include <linux/of_gpio.h>
> +#include <linux/slab.h>
> +
> +#define LMU_IMAX_OFFSET 6
> +
> +enum ti_lmu_id {
> + LM3532,
> + LM3631,
> + LM3632,
> + LM3633,
> + LM3695,
> + LM3697,
> +};
> +
> +struct ti_lmu_data {
> + struct mfd_cell *cells;
> + int num_cells;
> + unsigned int max_register;
> +};
> +
> +int ti_lmu_read_byte(struct ti_lmu *lmu, u8 reg, u8 *read)
> +{
> + int ret;
> + unsigned int val;
> +
> + ret = regmap_read(lmu->regmap, reg, &val);
> + if (ret < 0)
> + return ret;
> +
> + *read = (u8)val;
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(ti_lmu_read_byte);

It doesn't get much more simple than this.

What's the purpose of abstracting it?

> +int ti_lmu_write_byte(struct ti_lmu *lmu, u8 reg, u8 data)
> +{
> + return regmap_write(lmu->regmap, reg, data);
> +}
> +EXPORT_SYMBOL_GPL(ti_lmu_write_byte);
> +
> +int ti_lmu_update_bits(struct ti_lmu *lmu, u8 reg, u8 mask, u8 data)
> +{
> + return regmap_update_bits(lmu->regmap, reg, mask, data);
> +}
> +EXPORT_SYMBOL_GPL(ti_lmu_update_bits);

Okay, I lied, it does get more simple.

Seems like abstraction for the sake of abstraction here.

Feel free to try and convince me otherwise.

> +/*
> + * LMU backlight and LED devices use shared max current table.
> + * This function finds appropriate register index and return it.
> + */
> +enum ti_lmu_max_current ti_lmu_get_current_code(u32 imax_microamp)
> +{
> + u8 imax_milliamp = imax_microamp / 1000;
> +
> + const enum ti_lmu_max_current imax_table[] = {
> + LMU_IMAX_6mA, LMU_IMAX_7mA, LMU_IMAX_8mA, LMU_IMAX_9mA,
> + LMU_IMAX_10mA, LMU_IMAX_11mA, LMU_IMAX_12mA, LMU_IMAX_13mA,
> + LMU_IMAX_14mA, LMU_IMAX_15mA, LMU_IMAX_16mA, LMU_IMAX_17mA,
> + LMU_IMAX_18mA, LMU_IMAX_19mA, LMU_IMAX_20mA, LMU_IMAX_21mA,
> + LMU_IMAX_22mA, LMU_IMAX_23mA, LMU_IMAX_24mA, LMU_IMAX_25mA,
> + LMU_IMAX_26mA, LMU_IMAX_27mA, LMU_IMAX_28mA, LMU_IMAX_29mA,
> + };
> +
> + /* Valid range is from 5mA to 30mA */
> + if (imax_milliamp <= 5)
> + return LMU_IMAX_5mA;
> +
> + if (imax_milliamp >= 30)
> + return LMU_IMAX_30mA;
> +
> + return imax_table[imax_milliamp - LMU_IMAX_OFFSET];
> +}
> +EXPORT_SYMBOL_GPL(ti_lmu_get_current_code);
> +
> +static int ti_lmu_enable_hw(struct ti_lmu *lmu, enum ti_lmu_id id)
> +{
> + int ret;
> +
> + if (gpio_is_valid(lmu->en_gpio)) {
> + ret = devm_gpio_request_one(lmu->dev, lmu->en_gpio,
> + GPIOF_OUT_INIT_HIGH, "lmu_hwen");
> + if (ret) {
> + dev_err(lmu->dev, "Can not request enable GPIO: %d\n",
> + ret);
> + return ret;
> + }
> + }
> +
> + /* Delay about 1ms after HW enable pin control */
> + usleep_range(1000, 1500);
> +
> + /* LM3631 has additional power up sequence - enable LCD_EN bit. */
> + if (id == LM3631) {
> + return ti_lmu_update_bits(lmu, LM3631_REG_DEVCTRL,
> + LM3631_LCD_EN_MASK,
> + LM3631_LCD_EN_MASK);
> + }
> +
> + return 0;
> +}
> +
> +static void ti_lmu_disable_hw(struct ti_lmu *lmu)
> +{
> + if (gpio_is_valid(lmu->en_gpio))
> + gpio_set_value(lmu->en_gpio, 0);
> +}
> +
> +static struct mfd_cell lm3532_devices[] = {
> + {
> + .name = "lm3532-backlight",
> + .of_compatible = "ti,lm3532-backlight",
> + },
> +};
> +
> +#define LM363X_REGULATOR(_id) \
> +{ \
> + .name = "lm363x-regulator", \
> + .id = _id, \
> + .of_compatible = "ti,lm363x-regulator", \
> +} \
> +
> +static struct mfd_cell lm3631_devices[] = {
> + /* 5 regulators */

No need for this, we can read and count.

> + LM363X_REGULATOR(LM3631_BOOST),
> + LM363X_REGULATOR(LM3631_LDO_CONT),
> + LM363X_REGULATOR(LM3631_LDO_OREF),
> + LM363X_REGULATOR(LM3631_LDO_POS),
> + LM363X_REGULATOR(LM3631_LDO_NEG),
> + /* Backlight */

These comments are a bit redundant.

> + {
> + .name = "lm3631-backlight",
> + .of_compatible = "ti,lm3631-backlight",
> + },
> +};
> +
> +static struct mfd_cell lm3632_devices[] = {
> + /* 3 regulators */
> + LM363X_REGULATOR(LM3632_BOOST),
> + LM363X_REGULATOR(LM3632_LDO_POS),
> + LM363X_REGULATOR(LM3632_LDO_NEG),
> + /* Backlight */
> + {
> + .name = "lm3632-backlight",
> + .of_compatible = "ti,lm3632-backlight",
> + },
> +};
> +
> +static struct mfd_cell lm3633_devices[] = {
> + /* Backlight */
> + {
> + .name = "lm3633-backlight",
> + .of_compatible = "ti,lm3633-backlight",
> + },
> + /* LED */

The clue is in the words "-led".

> + {
> + .name = "lm3633-leds",
> + .of_compatible = "ti,lm3633-leds",
> + },
> + /* HWMON for opened/shorted circuit detection */
> + {
> + .name = "ti-lmu-hwmon",
> + .of_compatible = "ti,lm3633-hwmon",
> + },
> +};
> +
> +static struct mfd_cell lm3695_devices[] = {
> + {
> + .name = "lm3695-backlight",
> + .of_compatible = "ti,lm3695-backlight",
> + },
> +};
> +
> +static struct mfd_cell lm3697_devices[] = {
> + /* Backlight */
> + {
> + .name = "lm3697-backlight",
> + .of_compatible = "ti,lm3697-backlight",
> + },
> + /* HWMON for opened/shorted circuit detection */
> + {
> + .name = "ti-lmu-hwmon",
> + .of_compatible = "ti,lm3697-hwmon",
> + },
> +};
> +
> +#define TI_LMU_DATA(chip, max_reg) \
> +static const struct ti_lmu_data chip##_data = \
> +{ \
> + .cells = chip##_devices, \
> + .num_cells = ARRAY_SIZE(chip##_devices),\
> + .max_register = max_reg, \
> +} \
> +
> +TI_LMU_DATA(lm3532, LM3532_MAX_REG); /* lm3532_data */
> +TI_LMU_DATA(lm3631, LM3631_MAX_REG); /* lm3631_data */
> +TI_LMU_DATA(lm3632, LM3632_MAX_REG); /* lm3632_data */
> +TI_LMU_DATA(lm3633, LM3633_MAX_REG); /* lm3633_data */
> +TI_LMU_DATA(lm3695, LM3695_MAX_REG); /* lm3695_data */
> +TI_LMU_DATA(lm3697, LM3697_MAX_REG); /* lm3697_data */

Again with the pointless comments.

> +static const struct of_device_id ti_lmu_of_match[] = {
> + { .compatible = "ti,lm3532", .data = &lm3532_data },
> + { .compatible = "ti,lm3631", .data = &lm3631_data },
> + { .compatible = "ti,lm3632", .data = &lm3632_data },
> + { .compatible = "ti,lm3633", .data = &lm3633_data },
> + { .compatible = "ti,lm3695", .data = &lm3695_data },
> + { .compatible = "ti,lm3697", .data = &lm3697_data },
> + { }
> +};
> +MODULE_DEVICE_TABLE(of, ti_lmu_of_match);
> +
> +static int ti_lmu_probe(struct i2c_client *cl, const struct i2c_device_id *id)
> +{
> + struct device *dev = &cl->dev;
> + const struct of_device_id *match;
> + const struct ti_lmu_data *data;
> + struct regmap_config regmap_cfg;
> + struct ti_lmu *lmu;
> + int ret;
> +
> + match = of_match_device(ti_lmu_of_match, dev);
> + if (!match)
> + return -ENODEV;
> + /*
> + * Get device specific data from of_match table.
> + * This data is defined by using TI_LMU_DATA() macro.
> + */
> + data = (struct ti_lmu_data *)match->data;
> +
> + lmu = devm_kzalloc(dev, sizeof(*lmu), GFP_KERNEL);
> + if (!lmu)
> + return -ENOMEM;
> +
> + lmu->dev = &cl->dev;
> +
> + /* Setup regmap */
> + memset(&regmap_cfg, 0, sizeof(struct regmap_config));
> + regmap_cfg.reg_bits = 8;
> + regmap_cfg.val_bits = 8;
> + regmap_cfg.name = id->name;
> + regmap_cfg.max_register = data->max_register;
> +
> + lmu->regmap = devm_regmap_init_i2c(cl, &regmap_cfg);
> + if (IS_ERR(lmu->regmap))
> + return PTR_ERR(lmu->regmap);
> +
> + /* HW enable pin control and additional power up sequence if required */
> + lmu->en_gpio = of_get_named_gpio(dev->of_node, "enable-gpios", 0);
> + ret = ti_lmu_enable_hw(lmu, id->driver_data);
> + if (ret)
> + return ret;
> +
> + /*
> + * Fault circuit(opened/shorted) can be detected by ti-lmu-hwmon.
> + * After fault detection is done, some devices should re-initialize
> + * configuration. The notifier enables such kind of handling.
> + */
> + BLOCKING_INIT_NOTIFIER_HEAD(&lmu->notifier);
> +
> + i2c_set_clientdata(cl, lmu);
> +
> + return mfd_add_devices(lmu->dev, 0, data->cells,
> + data->num_cells, NULL, 0, NULL);
> +}
> +
> +static int ti_lmu_remove(struct i2c_client *cl)
> +{
> + struct ti_lmu *lmu = i2c_get_clientdata(cl);
> +
> + ti_lmu_disable_hw(lmu);
> + mfd_remove_devices(lmu->dev);
> + return 0;
> +}
> +
> +static const struct i2c_device_id ti_lmu_ids[] = {
> + { "lm3532", LM3532 },
> + { "lm3631", LM3631 },
> + { "lm3632", LM3632 },
> + { "lm3633", LM3633 },
> + { "lm3695", LM3695 },
> + { "lm3697", LM3697 },
> + { }
> +};
> +MODULE_DEVICE_TABLE(i2c, ti_lmu_ids);
> +
> +static struct i2c_driver ti_lmu_driver = {
> + .probe = ti_lmu_probe,
> + .remove = ti_lmu_remove,
> + .driver = {
> + .name = "ti-lmu",
> + .of_match_table = ti_lmu_of_match,
> + },
> + .id_table = ti_lmu_ids,
> +};
> +
> +module_i2c_driver(ti_lmu_driver);
> +
> +MODULE_DESCRIPTION("TI LMU MFD Core Driver");
> +MODULE_AUTHOR("Milo Kim");
> +MODULE_LICENSE("GPL v2");
> diff --git a/include/linux/mfd/ti-lmu-register.h b/include/linux/mfd/ti-lmu-register.h
> new file mode 100644
> index 0000000..39f5771
> --- /dev/null
> +++ b/include/linux/mfd/ti-lmu-register.h
> @@ -0,0 +1,277 @@
> +/*
> + * TI LMU(Lighting Management Unit) Device Register Map
> + *
> + * Copyright 2015 Texas Instruments
> + *
> + * Author: Milo Kim <[email protected]>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + */
> +
> +#ifndef __MFD_TI_LMU_REGISTER_H__
> +#define __MFD_TI_LMU_REGISTER_H__
> +
> +#include <linux/mfd/ti-lmu.h>
> +
> +/* LM3532 */
> +#define LM3532_REG_OUTPUT_CFG 0x10
> +#define LM3532_ILED1_CFG_MASK 0x03
> +#define LM3532_ILED2_CFG_MASK 0x0C
> +#define LM3532_ILED3_CFG_MASK 0x30
> +#define LM3532_ILED1_CFG_SHIFT 0
> +#define LM3532_ILED2_CFG_SHIFT 2
> +#define LM3532_ILED3_CFG_SHIFT 4
> +
> +#define LM3532_REG_RAMPUP 0x12
> +#define LM3532_REG_RAMPDN LM3532_REG_RAMPUP
> +#define LM3532_RAMPUP_MASK 0x07
> +#define LM3532_RAMPUP_SHIFT 0
> +#define LM3532_RAMPDN_MASK 0x38
> +#define LM3532_RAMPDN_SHIFT 3
> +
> +#define LM3532_REG_ENABLE 0x1D
> +
> +#define LM3532_REG_PWM_CFG_BASE 0x13
> +#define LM3532_PWM_SEL_A_MASK 0x05 /* zone 0 */
> +#define LM3532_PWM_SEL_B_MASK 0x09 /* zone 1 */
> +#define LM3532_PWM_SEL_C_MASK 0x11 /* zone 2 */
> +#define LM3532_PWM_SEL_A_SHIFT 2
> +#define LM3532_PWM_SEL_B_SHIFT 3
> +#define LM3532_PWM_SEL_C_SHIFT 4
> +
> +#define LM3532_REG_ZONE_CFG_A 0x16
> +#define LM3532_REG_ZONE_CFG_B 0x18
> +#define LM3532_REG_ZONE_CFG_C 0x1A
> +#define LM3532_ZONE_CFG_MASK (BIT(2) | BIT(3) | BIT(4))
> +#define LM3532_ZONE_CFG_SHIFT 2
> +
> +#define LM3532_REG_IMAX_A 0x17
> +#define LM3532_REG_IMAX_B 0x19
> +#define LM3532_REG_IMAX_C 0x1B
> +
> +#define LM3532_REG_BRT_A 0x70 /* zone 0 */
> +#define LM3532_REG_BRT_B 0x76 /* zone 1 */
> +#define LM3532_REG_BRT_C 0x7C /* zone 2 */
> +
> +#define LM3532_MAX_REG 0x7E
> +
> +/* LM3631 */
> +#define LM3631_REG_DEVCTRL 0x00
> +#define LM3631_LCD_EN_MASK BIT(1)
> +#define LM3631_BL_EN_MASK BIT(0)
> +
> +#define LM3631_REG_BRT_LSB 0x01
> +#define LM3631_BRT_LSB_MASK (BIT(0) | BIT(1) | BIT(2))
> +#define LM3631_REG_BRT_MSB 0x02
> +#define LM3631_BRT_MSB_SHIFT 3
> +
> +#define LM3631_REG_BL_CFG 0x06
> +#define LM3631_BL_STRING_MASK BIT(3)
> +#define LM3631_BL_TWO_STRINGS 0
> +#define LM3631_BL_ONE_STRING BIT(3)
> +#define LM3631_MAP_MASK BIT(5)
> +#define LM3631_EXPONENTIAL_MAP 0
> +
> +#define LM3631_REG_BRT_MODE 0x08
> +#define LM3631_EN_SLOPE_MASK BIT(1)
> +#define LM3631_MODE_MASK (BIT(2) | BIT(3))
> +#define LM3631_MODE_I2C 0
> +#define LM3631_MODE_PWM BIT(2)
> +#define LM3631_MODE_COMB1 BIT(3)
> +#define LM3631_MODE_COMB2 (BIT(2) | BIT(3))
> +
> +#define LM3631_REG_SLOPE 0x09
> +#define LM3631_SLOPE_MASK 0xF0
> +#define LM3631_SLOPE_SHIFT 4
> +
> +#define LM3631_REG_LDO_CTRL1 0x0A
> +#define LM3631_EN_OREF_MASK BIT(0)
> +#define LM3631_EN_VNEG_MASK BIT(1)
> +#define LM3631_EN_VPOS_MASK BIT(2)
> +
> +#define LM3631_REG_LDO_CTRL2 0x0B
> +#define LM3631_EN_CONT_MASK BIT(0)
> +
> +#define LM3631_REG_VOUT_CONT 0x0C
> +#define LM3631_VOUT_CONT_MASK (BIT(6) | BIT(7))
> +
> +#define LM3631_REG_VOUT_BOOST 0x0C
> +#define LM3631_REG_VOUT_POS 0x0D
> +#define LM3631_REG_VOUT_NEG 0x0E
> +#define LM3631_REG_VOUT_OREF 0x0F
> +#define LM3631_VOUT_MASK 0x3F
> +
> +#define LM3631_REG_ENTIME_VCONT 0x0B
> +#define LM3631_ENTIME_CONT_MASK 0x70
> +
> +#define LM3631_REG_ENTIME_VOREF 0x0F
> +#define LM3631_REG_ENTIME_VPOS 0x10
> +#define LM3631_REG_ENTIME_VNEG 0x11
> +#define LM3631_ENTIME_MASK 0xF0
> +#define LM3631_ENTIME_SHIFT 4
> +
> +#define LM3631_MAX_REG 0x16
> +
> +/* LM3632 */
> +#define LM3632_REG_CONFIG1 0x02
> +#define LM3632_OVP_MASK (BIT(5) | BIT(6) | BIT(7))
> +#define LM3632_OVP_25V BIT(6)
> +
> +#define LM3632_REG_CONFIG2 0x03
> +#define LM3632_SWFREQ_MASK BIT(7)
> +#define LM3632_SWFREQ_1MHZ BIT(7)
> +
> +#define LM3632_REG_BRT_LSB 0x04
> +#define LM3632_BRT_LSB_MASK (BIT(0) | BIT(1) | BIT(2))
> +#define LM3632_REG_BRT_MSB 0x05
> +#define LM3632_BRT_MSB_SHIFT 3
> +
> +#define LM3632_REG_IO_CTRL 0x09
> +#define LM3632_PWM_MASK BIT(6)
> +#define LM3632_I2C_MODE 0
> +#define LM3632_PWM_MODE BIT(6)
> +
> +#define LM3632_REG_ENABLE 0x0A
> +#define LM3632_BL_EN_MASK BIT(0)
> +#define LM3632_BL_STRING_MASK (BIT(3) | BIT(4))
> +#define LM3632_BL_ONE_STRING BIT(4)
> +#define LM3632_BL_TWO_STRINGS BIT(3)
> +
> +#define LM3632_REG_BIAS_CONFIG 0x0C
> +#define LM3632_EXT_EN_MASK BIT(0)
> +#define LM3632_EN_VNEG_MASK BIT(1)
> +#define LM3632_EN_VPOS_MASK BIT(2)
> +
> +#define LM3632_REG_VOUT_BOOST 0x0D
> +#define LM3632_REG_VOUT_POS 0x0E
> +#define LM3632_REG_VOUT_NEG 0x0F
> +#define LM3632_VOUT_MASK 0x3F
> +
> +#define LM3632_MAX_REG 0x10
> +
> +/* LM3633 */
> +#define LM3633_REG_HVLED_OUTPUT_CFG 0x10
> +
> +#define LM3633_REG_BANK_SEL 0x11
> +
> +#define LM3633_REG_BL0_RAMPUP 0x12
> +#define LM3633_REG_BL0_RAMPDN LM3633_REG_BL0_RAMPUP
> +#define LM3633_REG_BL1_RAMPUP 0x13
> +#define LM3633_REG_BL1_RAMPDN LM3633_REG_BL1_RAMPUP
> +#define LM3633_BL_RAMPUP_MASK 0xF0
> +#define LM3633_BL_RAMPUP_SHIFT 4
> +#define LM3633_BL_RAMPDN_MASK 0x0F
> +#define LM3633_BL_RAMPDN_SHIFT 0
> +
> +#define LM3633_REG_BL_RAMP_CONF 0x1B
> +#define LM3633_BL_RAMP_MASK 0x0F
> +#define LM3633_BL_RAMP_EACH 0x05
> +
> +#define LM3633_REG_PTN0_RAMP 0x1C
> +#define LM3633_REG_PTN1_RAMP 0x1D
> +#define LM3633_PTN_RAMPUP_MASK 0x70
> +#define LM3633_PTN_RAMPUP_SHIFT 4
> +#define LM3633_PTN_RAMPDN_MASK 0x07
> +#define LM3633_PTN_RAMPDN_SHIFT 0
> +
> +#define LM3633_REG_IMAX_HVLED_A 0x20
> +#define LM3633_REG_IMAX_HVLED_B 0x21
> +#define LM3633_REG_IMAX_LVLED_BASE 0x22
> +
> +#define LM3633_REG_BL_FEEDBACK_ENABLE 0x28
> +
> +#define LM3633_REG_ENABLE 0x2B
> +#define LM3633_LED_BANK_OFFSET 2
> +
> +#define LM3633_REG_PATTERN 0x2C
> +
> +#define LM3633_REG_BOOST_CFG 0x2D
> +#define LM3633_BOOST_OVP_MASK (BIT(1) | BIT(2))
> +#define LM3633_BOOST_OVP_40V 0x6
> +
> +#define LM3633_REG_PWM_CFG 0x2F
> +
> +#define LM3633_REG_BRT_HVLED_A_LSB 0x40
> +#define LM3633_REG_BRT_HVLED_A_MSB 0x41
> +#define LM3633_REG_BRT_HVLED_B_LSB 0x42
> +#define LM3633_REG_BRT_HVLED_B_MSB 0x43
> +#define LM3633_BRT_HVLED_LSB_MASK (BIT(0) | BIT(1) | BIT(2))
> +#define LM3633_BRT_HVLED_MSB_SHIFT 3
> +
> +#define LM3633_REG_BRT_LVLED_BASE 0x44
> +
> +#define LM3633_REG_PTN_DELAY 0x50
> +
> +#define LM3633_REG_PTN_LOWTIME 0x51
> +
> +#define LM3633_REG_PTN_HIGHTIME 0x52
> +
> +#define LM3633_REG_PTN_LOWBRT 0x53
> +
> +#define LM3633_REG_PTN_HIGHBRT LM3633_REG_BRT_LVLED_BASE
> +
> +#define LM3633_REG_BL_OPEN_FAULT_STATUS 0xB0
> +
> +#define LM3633_REG_BL_SHORT_FAULT_STATUS 0xB2
> +
> +#define LM3633_REG_MONITOR_ENABLE 0xB4
> +
> +#define LM3633_MAX_REG 0xB4
> +
> +/* LM3695 */
> +#define LM3695_REG_GP 0x10
> +#define LM3695_BL_STRING_MASK BIT(3)
> +#define LM3695_BL_TWO_STRINGS 0
> +#define LM3695_BL_ONE_STRING BIT(3)
> +#define LM3695_BRT_RW_MASK BIT(2)
> +#define LM3695_BL_EN_MASK BIT(0)
> +
> +#define LM3695_REG_BRT_LSB 0x13
> +#define LM3695_BRT_LSB_MASK (BIT(0) | BIT(1) | BIT(2))
> +#define LM3695_REG_BRT_MSB 0x14
> +#define LM3695_BRT_MSB_SHIFT 3
> +
> +#define LM3695_MAX_REG 0x14
> +
> +/* LM3697 */
> +#define LM3697_REG_HVLED_OUTPUT_CFG 0x10
> +
> +#define LM3697_REG_BL0_RAMPUP 0x11
> +#define LM3697_REG_BL0_RAMPDN LM3697_REG_BL0_RAMPUP
> +#define LM3697_REG_BL1_RAMPUP 0x12
> +#define LM3697_REG_BL1_RAMPDN LM3697_REG_BL1_RAMPUP
> +#define LM3697_BL_RAMPUP_MASK 0xF0
> +#define LM3697_BL_RAMPUP_SHIFT 4
> +#define LM3697_BL_RAMPDN_MASK 0x0F
> +#define LM3697_BL_RAMPDN_SHIFT 0
> +
> +#define LM3697_REG_RAMP_CONF 0x14
> +#define LM3697_RAMP_MASK 0x0F
> +#define LM3697_RAMP_EACH 0x05
> +
> +#define LM3697_REG_PWM_CFG 0x1C
> +
> +#define LM3697_REG_IMAX_A 0x17
> +#define LM3697_REG_IMAX_B 0x18
> +
> +#define LM3697_REG_FEEDBACK_ENABLE 0x19
> +
> +#define LM3697_REG_BRT_A_LSB 0x20
> +#define LM3697_REG_BRT_A_MSB 0x21
> +#define LM3697_REG_BRT_B_LSB 0x22
> +#define LM3697_REG_BRT_B_MSB 0x23
> +#define LM3697_BRT_LSB_MASK (BIT(0) | BIT(1) | BIT(2))
> +#define LM3697_BRT_MSB_SHIFT 3
> +
> +#define LM3697_REG_ENABLE 0x24
> +
> +#define LM3697_REG_OPEN_FAULT_STATUS 0xB0
> +
> +#define LM3697_REG_SHORT_FAULT_STATUS 0xB2
> +
> +#define LM3697_REG_MONITOR_ENABLE 0xB4
> +
> +#define LM3697_MAX_REG 0xB4
> +#endif
> diff --git a/include/linux/mfd/ti-lmu.h b/include/linux/mfd/ti-lmu.h
> new file mode 100644
> index 0000000..eeb6b9e
> --- /dev/null
> +++ b/include/linux/mfd/ti-lmu.h
> @@ -0,0 +1,81 @@
> +/*
> + * TI LMU(Lighting Management Unit) Devices
> + *
> + * Copyright 2015 Texas Instruments
> + *
> + * Author: Milo Kim <[email protected]>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + */
> +
> +#ifndef __MFD_TI_LMU_H__
> +#define __MFD_TI_LMU_H__
> +
> +#include <linux/gpio.h>
> +#include <linux/regmap.h>
> +
> +/* Notifier event */
> +#define LMU_EVENT_HWMON_DONE 0x01
> +
> +enum ti_lmu_max_current {
> + LMU_IMAX_5mA,
> + LMU_IMAX_6mA,
> + LMU_IMAX_7mA = 0x03,
> + LMU_IMAX_8mA,
> + LMU_IMAX_9mA,
> + LMU_IMAX_10mA = 0x07,
> + LMU_IMAX_11mA,
> + LMU_IMAX_12mA,
> + LMU_IMAX_13mA,
> + LMU_IMAX_14mA,
> + LMU_IMAX_15mA = 0x0D,
> + LMU_IMAX_16mA,
> + LMU_IMAX_17mA,
> + LMU_IMAX_18mA,
> + LMU_IMAX_19mA,
> + LMU_IMAX_20mA = 0x13,
> + LMU_IMAX_21mA,
> + LMU_IMAX_22mA,
> + LMU_IMAX_23mA = 0x17,
> + LMU_IMAX_24mA,
> + LMU_IMAX_25mA,
> + LMU_IMAX_26mA,
> + LMU_IMAX_27mA = 0x1C,
> + LMU_IMAX_28mA,
> + LMU_IMAX_29mA,
> + LMU_IMAX_30mA,
> +};
> +
> +enum lm363x_regulator_id {
> + LM3631_BOOST, /* Boost output */
> + LM3631_LDO_CONT, /* Display panel controller */
> + LM3631_LDO_OREF, /* Gamma reference */
> + LM3631_LDO_POS, /* Positive display bias output */
> + LM3631_LDO_NEG, /* Negative display bias output */
> + LM3632_BOOST, /* Boost output */
> + LM3632_LDO_POS, /* Positive display bias output */
> + LM3632_LDO_NEG, /* Negative display bias output */
> +};
> +
> +/**
> + * struct ti_lmu
> + *
> + * @dev: Parent device pointer
> + * @regmap: Used for i2c communcation on accessing registers
> + * @en_gpio: GPIO for HWEN pin [Optional]
> + * @notifier: Notifier for reporting hwmon event
> + */
> +struct ti_lmu {
> + struct device *dev;
> + struct regmap *regmap;
> + int en_gpio;
> + struct blocking_notifier_head notifier;
> +};
> +
> +int ti_lmu_read_byte(struct ti_lmu *lmu, u8 reg, u8 *read);
> +int ti_lmu_write_byte(struct ti_lmu *lmu, u8 reg, u8 data);
> +int ti_lmu_update_bits(struct ti_lmu *lmu, u8 reg, u8 mask, u8 data);
> +enum ti_lmu_max_current ti_lmu_get_current_code(u32 imax_microamp);
> +#endif

--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

2015-11-23 11:17:21

by Jacek Anaszewski

[permalink] [raw]
Subject: Re: [PATCH RESEND 15/16] leds: add LM3633 driver

Hi Milo,

On 11/23/2015 12:40 AM, Kim, Milo wrote:
> Hi Jacek,
>
> On 11/20/2015 6:22 PM, Jacek Anaszewski wrote:
>> On 11/10/2015 08:38 AM, Kim, Milo wrote:
>> [...]
>>>>> + cat /sys/class/leds/<led>/pattern_levels
>>>>> + low brightness: 0, high brightness: 255
>>>>> +
>>>>> +What: /sys/class/leds/<led>/run_pattern
>>>>> +Date: Oct 2015
>>>>> +KernelVersion: 4.3
>>>>> +Contact: Milo Kim <[email protected]>
>>>>> +Description: write only
>>>>> + After 'pattern_times' and 'pattern_levels' are
>>>>> updated,
>>>>> + run the pattern by writing 1 to 'run_pattern'.
>>>>> + To stop running pattern, writes 0 to 'run_pattern'.
>>>>
>>>> I wonder how registering an in-driver trigger would work. It would
>>>> allow for hiding above pattern attributes when the trigger is inactive,
>>>> and thus making the sysfs interface more transparent. You could avoid
>>>> the need for run_pattern attribute, as setting the trigger would itself
>>>> activate the pattern, and setting brightness to 0 would turn it off.
>>>
>>> I like this idea, let me try to fix it.
>>
>> After thinking it over, I came to conclusion that implementing it as
>> an in-driver trigger is not a proper way to go, since triggers are
>> defined as kernel based source of LED events.
>>
>> This is somehow abused in case of timer trigger which takes hardware
>> blinking feature as a first choice and applies software blinking as
>> a fallback only. To be consistent with that, we could go for adding
>> generic pattern trigger and add a led_pattern_set() API, similarly
>> to existing led_blink_set().
>>
>> The problem is that different LED controllers may implement blinking
>> patterns that are configured with different set of parameters. This
>> subject would definitely require thorough analysis.
>>
>> For now, please just expose pattern settings as separate sysfs
>> attributes of a LED class device.
>>
>
> Thanks for your suggestion.
> Then, LM3633 LED driver will support 8 device attributes.
>
> pattern_time_delay
> pattern_time_rise
> pattern_time_high
> pattern_time_fall
> pattern_time_low
> pattern_brightness_low
> pattern_brightness_high
> pattern_run_pattern
>
> Details will be updated in
> Documentation/ABI/testing/sysfs-class-led-lm3633.

OK, it looks reasonable.

--
Best Regards,
Jacek Anaszewski

2015-11-24 02:37:26

by Kim, Milo

[permalink] [raw]
Subject: Re: [PATCH RESEND 06/16] mfd: add TI LMU driver

Hi Lee,

Thanks for all your comments. Please see my comments below.

On 11/23/2015 7:30 PM, Lee Jones wrote:
>> +int ti_lmu_read_byte(struct ti_lmu *lmu, u8 reg, u8 *read)
>> >+{
>> >+ int ret;
>> >+ unsigned int val;
>> >+
>> >+ ret = regmap_read(lmu->regmap, reg, &val);
>> >+ if (ret < 0)
>> >+ return ret;
>> >+
>> >+ *read = (u8)val;
>> >+ return 0;
>> >+}
>> >+EXPORT_SYMBOL_GPL(ti_lmu_read_byte);
> It doesn't get much more simple than this.
>
> What's the purpose of abstracting it?
>
>> >+int ti_lmu_write_byte(struct ti_lmu *lmu, u8 reg, u8 data)
>> >+{
>> >+ return regmap_write(lmu->regmap, reg, data);
>> >+}
>> >+EXPORT_SYMBOL_GPL(ti_lmu_write_byte);
>> >+
>> >+int ti_lmu_update_bits(struct ti_lmu *lmu, u8 reg, u8 mask, u8 data)
>> >+{
>> >+ return regmap_update_bits(lmu->regmap, reg, mask, data);
>> >+}
>> >+EXPORT_SYMBOL_GPL(ti_lmu_update_bits);
> Okay, I lied, it does get more simple.
>
> Seems like abstraction for the sake of abstraction here.
>
> Feel free to try and convince me otherwise.
>

The main reason was that LMU MFD core provides consistent register
access among LMU drivers like ti-lmu-backlight, leds-lm3633,
lm363x-regulator and ti-lmu-fault-monitor('ti-lmu-hwmon' will be changed
to this in the 2nd patch).

However, LMU register helpers are exactly same as regmap interface
except using ti_lmu data structure. So let me replace them with regmap
functions. Thanks for pointing this out.

Best regards,
Milo

2015-11-24 06:41:14

by Kim, Milo

[permalink] [raw]
Subject: Re: [PATCH RESEND 06/16] mfd: add TI LMU driver

On 11/24/2015 11:35 AM, Kim, Milo wrote:
> Hi Lee,
>
> Thanks for all your comments. Please see my comments below.
>
> On 11/23/2015 7:30 PM, Lee Jones wrote:
>>> +int ti_lmu_read_byte(struct ti_lmu *lmu, u8 reg, u8 *read)
>>>> +{
>>>> + int ret;
>>>> + unsigned int val;
>>>> +
>>>> + ret = regmap_read(lmu->regmap, reg, &val);
>>>> + if (ret < 0)
>>>> + return ret;
>>>> +
>>>> + *read = (u8)val;
>>>> + return 0;
>>>> +}
>>>> +EXPORT_SYMBOL_GPL(ti_lmu_read_byte);
>> It doesn't get much more simple than this.
>>
>> What's the purpose of abstracting it?
>>
>>>> +int ti_lmu_write_byte(struct ti_lmu *lmu, u8 reg, u8 data)
>>>> +{
>>>> + return regmap_write(lmu->regmap, reg, data);
>>>> +}
>>>> +EXPORT_SYMBOL_GPL(ti_lmu_write_byte);
>>>> +
>>>> +int ti_lmu_update_bits(struct ti_lmu *lmu, u8 reg, u8 mask, u8 data)
>>>> +{
>>>> + return regmap_update_bits(lmu->regmap, reg, mask, data);
>>>> +}
>>>> +EXPORT_SYMBOL_GPL(ti_lmu_update_bits);
>> Okay, I lied, it does get more simple.
>>
>> Seems like abstraction for the sake of abstraction here.
>>
>> Feel free to try and convince me otherwise.
>>
>
> The main reason was that LMU MFD core provides consistent register
> access among LMU drivers like ti-lmu-backlight, leds-lm3633,
> lm363x-regulator and ti-lmu-fault-monitor('ti-lmu-hwmon' will be changed
> to this in the 2nd patch).
>
> However, LMU register helpers are exactly same as regmap interface
> except using ti_lmu data structure. So let me replace them with regmap
> functions. Thanks for pointing this out.

I just realized LMU MFD core helpers also provide module dependencies by
using EXPORT_SYMBOL_GPL().

# modprobe -D ti-lmu-backlight
insmod /lib/modules/<ver>/kernel/drivers/base/regmap/regmap-i2c.ko
insmod /lib/modules/<ver>/kernel/drivers/mfd/mfd-core.ko
insmod /lib/modules/<ver>/kernel/drivers/mfd/ti-lmu.ko
insmod /lib/modules/<ver>/kernel/drivers/video/backlight/ti-lmu-backlight.ko
# modprobe -D ti-lmu-fault-monitor
insmod /lib/modules/<ver>/kernel/drivers/base/regmap/regmap-i2c.ko
insmod /lib/modules/<ver>/kernel/drivers/mfd/mfd-core.ko
insmod /lib/modules/<ver>/kernel/drivers/mfd/ti-lmu.ko
insmod /lib/modules/<ver>/kernel/drivers/mfd/ti-lmu-fault-monitor.ko
# modprobe -D lm363x-regulator
insmod /lib/modules/<ver>/kernel/drivers/base/regmap/regmap-i2c.ko
insmod /lib/modules/<ver>/kernel/drivers/mfd/mfd-core.ko
insmod /lib/modules/<ver>/kernel/drivers/mfd/ti-lmu.ko
insmod /lib/modules/<ver>/kernel/drivers/regulator/lm363x-regulator.ko
# modprobe -D leds-lm3633
insmod /lib/modules/<ver>/kernel/drivers/base/regmap/regmap-i2c.ko
insmod /lib/modules/<ver>/kernel/drivers/mfd/mfd-core.ko
insmod /lib/modules/<ver>/kernel/drivers/mfd/ti-lmu.ko
insmod /lib/modules/<ver>/kernel/drivers/leds/leds-lm3633.ko

ti-lmu.ko should be loaded first because it has hardware enable pin
control code. Four other drivers have dependency on this module. Without
EXPORT_SYMBOL_GPL(), this dependency will be gone like below.

# modprobe -D ti-lmu-backlight
insmod /lib/modules/<ver>/kernel/drivers/video/backlight/ti-lmu-backlight.ko
# modprobe -D ti-lmu-fault-monitor
insmod /lib/modules/<ver>/kernel/drivers/mfd/ti-lmu-fault-monitor.ko
# modprobe -D lm363x-regulator
insmod /lib/modules/<ver>/kernel/drivers/regulator/lm363x-regulator.ko
# modprobe -D leds-lm3633
insmod /lib/modules/<ver>/kernel/drivers/leds/leds-lm3633.ko

If LMU MFD core module is not loaded and other modules call regmap
helpers, then loaded drivers will not work because hardware is not
enabled yet.

So I'd like to keep LMU MFD helpers for module dependencies.
Additionally, I'll modify 'ti_lmu_read_byte()' as follows.

int ti_lmu_read_byte(struct ti_lmu *lmu, u8 reg, u8 *read)
{
return regmap_read(lmu->regmap, reg, (unsigned int *)read);
}
EXPORT_SYMBOL_GPL(ti_lmu_read_byte);

Please let me know if you have better idea.

Best regards,
Milo

2015-11-24 08:18:54

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH RESEND 06/16] mfd: add TI LMU driver

On Tue, 24 Nov 2015, Kim, Milo wrote:

> On 11/24/2015 11:35 AM, Kim, Milo wrote:
> >Hi Lee,
> >
> >Thanks for all your comments. Please see my comments below.
> >
> >On 11/23/2015 7:30 PM, Lee Jones wrote:
> >>>+int ti_lmu_read_byte(struct ti_lmu *lmu, u8 reg, u8 *read)
> >>>>+{
> >>>>+ int ret;
> >>>>+ unsigned int val;
> >>>>+
> >>>>+ ret = regmap_read(lmu->regmap, reg, &val);
> >>>>+ if (ret < 0)
> >>>>+ return ret;
> >>>>+
> >>>>+ *read = (u8)val;
> >>>>+ return 0;
> >>>>+}
> >>>>+EXPORT_SYMBOL_GPL(ti_lmu_read_byte);
> >>It doesn't get much more simple than this.
> >>
> >>What's the purpose of abstracting it?
> >>
> >>>>+int ti_lmu_write_byte(struct ti_lmu *lmu, u8 reg, u8 data)
> >>>>+{
> >>>>+ return regmap_write(lmu->regmap, reg, data);
> >>>>+}
> >>>>+EXPORT_SYMBOL_GPL(ti_lmu_write_byte);
> >>>>+
> >>>>+int ti_lmu_update_bits(struct ti_lmu *lmu, u8 reg, u8 mask, u8 data)
> >>>>+{
> >>>>+ return regmap_update_bits(lmu->regmap, reg, mask, data);
> >>>>+}
> >>>>+EXPORT_SYMBOL_GPL(ti_lmu_update_bits);
> >>Okay, I lied, it does get more simple.
> >>
> >>Seems like abstraction for the sake of abstraction here.
> >>
> >>Feel free to try and convince me otherwise.
> >>
> >
> >The main reason was that LMU MFD core provides consistent register
> >access among LMU drivers like ti-lmu-backlight, leds-lm3633,
> >lm363x-regulator and ti-lmu-fault-monitor('ti-lmu-hwmon' will be changed
> >to this in the 2nd patch).
> >
> >However, LMU register helpers are exactly same as regmap interface
> >except using ti_lmu data structure. So let me replace them with regmap
> >functions. Thanks for pointing this out.
>
> I just realized LMU MFD core helpers also provide module
> dependencies by using EXPORT_SYMBOL_GPL().
>
> # modprobe -D ti-lmu-backlight
> insmod /lib/modules/<ver>/kernel/drivers/base/regmap/regmap-i2c.ko
> insmod /lib/modules/<ver>/kernel/drivers/mfd/mfd-core.ko
> insmod /lib/modules/<ver>/kernel/drivers/mfd/ti-lmu.ko
> insmod /lib/modules/<ver>/kernel/drivers/video/backlight/ti-lmu-backlight.ko
> # modprobe -D ti-lmu-fault-monitor
> insmod /lib/modules/<ver>/kernel/drivers/base/regmap/regmap-i2c.ko
> insmod /lib/modules/<ver>/kernel/drivers/mfd/mfd-core.ko
> insmod /lib/modules/<ver>/kernel/drivers/mfd/ti-lmu.ko
> insmod /lib/modules/<ver>/kernel/drivers/mfd/ti-lmu-fault-monitor.ko
> # modprobe -D lm363x-regulator
> insmod /lib/modules/<ver>/kernel/drivers/base/regmap/regmap-i2c.ko
> insmod /lib/modules/<ver>/kernel/drivers/mfd/mfd-core.ko
> insmod /lib/modules/<ver>/kernel/drivers/mfd/ti-lmu.ko
> insmod /lib/modules/<ver>/kernel/drivers/regulator/lm363x-regulator.ko
> # modprobe -D leds-lm3633
> insmod /lib/modules/<ver>/kernel/drivers/base/regmap/regmap-i2c.ko
> insmod /lib/modules/<ver>/kernel/drivers/mfd/mfd-core.ko
> insmod /lib/modules/<ver>/kernel/drivers/mfd/ti-lmu.ko
> insmod /lib/modules/<ver>/kernel/drivers/leds/leds-lm3633.ko
>
> ti-lmu.ko should be loaded first because it has hardware enable pin
> control code. Four other drivers have dependency on this module.
> Without EXPORT_SYMBOL_GPL(), this dependency will be gone like
> below.
>
> # modprobe -D ti-lmu-backlight
> insmod /lib/modules/<ver>/kernel/drivers/video/backlight/ti-lmu-backlight.ko
> # modprobe -D ti-lmu-fault-monitor
> insmod /lib/modules/<ver>/kernel/drivers/mfd/ti-lmu-fault-monitor.ko
> # modprobe -D lm363x-regulator
> insmod /lib/modules/<ver>/kernel/drivers/regulator/lm363x-regulator.ko
> # modprobe -D leds-lm3633
> insmod /lib/modules/<ver>/kernel/drivers/leds/leds-lm3633.ko
>
> If LMU MFD core module is not loaded and other modules call regmap
> helpers, then loaded drivers will not work because hardware is not
> enabled yet.
>
> So I'd like to keep LMU MFD helpers for module dependencies.
> Additionally, I'll modify 'ti_lmu_read_byte()' as follows.
>
> int ti_lmu_read_byte(struct ti_lmu *lmu, u8 reg, u8 *read)
> {
> return regmap_read(lmu->regmap, reg, (unsigned int *)read);
> }
> EXPORT_SYMBOL_GPL(ti_lmu_read_byte);
>
> Please let me know if you have better idea.

You're keeping the helpers for the wrong reasons. This has now become
a hack. If you have dependencies between modules, either use the init
levels or defer probe in the usual way.

--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

2015-11-25 08:12:22

by Kim, Milo

[permalink] [raw]
Subject: Re: [PATCH RESEND 06/16] mfd: add TI LMU driver

On 11/24/2015 5:18 PM, Lee Jones wrote:
> On Tue, 24 Nov 2015, Kim, Milo wrote:
>
>> On 11/24/2015 11:35 AM, Kim, Milo wrote:
>>> Hi Lee,
>>>
>>> Thanks for all your comments. Please see my comments below.
>>>
>>> On 11/23/2015 7:30 PM, Lee Jones wrote:
>>>>> +int ti_lmu_read_byte(struct ti_lmu *lmu, u8 reg, u8 *read)
>>>>>> +{
>>>>>> + int ret;
>>>>>> + unsigned int val;
>>>>>> +
>>>>>> + ret = regmap_read(lmu->regmap, reg, &val);
>>>>>> + if (ret < 0)
>>>>>> + return ret;
>>>>>> +
>>>>>> + *read = (u8)val;
>>>>>> + return 0;
>>>>>> +}
>>>>>> +EXPORT_SYMBOL_GPL(ti_lmu_read_byte);
>>>> It doesn't get much more simple than this.
>>>>
>>>> What's the purpose of abstracting it?
>>>>
>>>>>> +int ti_lmu_write_byte(struct ti_lmu *lmu, u8 reg, u8 data)
>>>>>> +{
>>>>>> + return regmap_write(lmu->regmap, reg, data);
>>>>>> +}
>>>>>> +EXPORT_SYMBOL_GPL(ti_lmu_write_byte);
>>>>>> +
>>>>>> +int ti_lmu_update_bits(struct ti_lmu *lmu, u8 reg, u8 mask, u8 data)
>>>>>> +{
>>>>>> + return regmap_update_bits(lmu->regmap, reg, mask, data);
>>>>>> +}
>>>>>> +EXPORT_SYMBOL_GPL(ti_lmu_update_bits);
>>>> Okay, I lied, it does get more simple.
>>>>
>>>> Seems like abstraction for the sake of abstraction here.
>>>>
>>>> Feel free to try and convince me otherwise.
>>>>
>>>
>>> The main reason was that LMU MFD core provides consistent register
>>> access among LMU drivers like ti-lmu-backlight, leds-lm3633,
>>> lm363x-regulator and ti-lmu-fault-monitor('ti-lmu-hwmon' will be changed
>>> to this in the 2nd patch).
>>>
>>> However, LMU register helpers are exactly same as regmap interface
>>> except using ti_lmu data structure. So let me replace them with regmap
>>> functions. Thanks for pointing this out.
>>
>> I just realized LMU MFD core helpers also provide module
>> dependencies by using EXPORT_SYMBOL_GPL().
>>
>> # modprobe -D ti-lmu-backlight
>> insmod /lib/modules/<ver>/kernel/drivers/base/regmap/regmap-i2c.ko
>> insmod /lib/modules/<ver>/kernel/drivers/mfd/mfd-core.ko
>> insmod /lib/modules/<ver>/kernel/drivers/mfd/ti-lmu.ko
>> insmod /lib/modules/<ver>/kernel/drivers/video/backlight/ti-lmu-backlight.ko
>> # modprobe -D ti-lmu-fault-monitor
>> insmod /lib/modules/<ver>/kernel/drivers/base/regmap/regmap-i2c.ko
>> insmod /lib/modules/<ver>/kernel/drivers/mfd/mfd-core.ko
>> insmod /lib/modules/<ver>/kernel/drivers/mfd/ti-lmu.ko
>> insmod /lib/modules/<ver>/kernel/drivers/mfd/ti-lmu-fault-monitor.ko
>> # modprobe -D lm363x-regulator
>> insmod /lib/modules/<ver>/kernel/drivers/base/regmap/regmap-i2c.ko
>> insmod /lib/modules/<ver>/kernel/drivers/mfd/mfd-core.ko
>> insmod /lib/modules/<ver>/kernel/drivers/mfd/ti-lmu.ko
>> insmod /lib/modules/<ver>/kernel/drivers/regulator/lm363x-regulator.ko
>> # modprobe -D leds-lm3633
>> insmod /lib/modules/<ver>/kernel/drivers/base/regmap/regmap-i2c.ko
>> insmod /lib/modules/<ver>/kernel/drivers/mfd/mfd-core.ko
>> insmod /lib/modules/<ver>/kernel/drivers/mfd/ti-lmu.ko
>> insmod /lib/modules/<ver>/kernel/drivers/leds/leds-lm3633.ko
>>
>> ti-lmu.ko should be loaded first because it has hardware enable pin
>> control code. Four other drivers have dependency on this module.
>> Without EXPORT_SYMBOL_GPL(), this dependency will be gone like
>> below.
>>
>> # modprobe -D ti-lmu-backlight
>> insmod /lib/modules/<ver>/kernel/drivers/video/backlight/ti-lmu-backlight.ko
>> # modprobe -D ti-lmu-fault-monitor
>> insmod /lib/modules/<ver>/kernel/drivers/mfd/ti-lmu-fault-monitor.ko
>> # modprobe -D lm363x-regulator
>> insmod /lib/modules/<ver>/kernel/drivers/regulator/lm363x-regulator.ko
>> # modprobe -D leds-lm3633
>> insmod /lib/modules/<ver>/kernel/drivers/leds/leds-lm3633.ko
>>
>> If LMU MFD core module is not loaded and other modules call regmap
>> helpers, then loaded drivers will not work because hardware is not
>> enabled yet.
>>
>> So I'd like to keep LMU MFD helpers for module dependencies.
>> Additionally, I'll modify 'ti_lmu_read_byte()' as follows.
>>
>> int ti_lmu_read_byte(struct ti_lmu *lmu, u8 reg, u8 *read)
>> {
>> return regmap_read(lmu->regmap, reg, (unsigned int *)read);
>> }
>> EXPORT_SYMBOL_GPL(ti_lmu_read_byte);
>>
>> Please let me know if you have better idea.
>
> You're keeping the helpers for the wrong reasons. This has now become
> a hack. If you have dependencies between modules, either use the init
> levels or defer probe in the usual way.
>

Yes, I was wrong. In case LMU MFD core is not loaded, other LMU modules
like ti-lmu-backlight isn't probed because no platform device (mfd
device) exists. So the situation which I've mentioned never happens.
And if GPIO controller is not ready and HW enable GPIO request gets
failed on LMU MFD initialization, this will be processed later because
it returns as error code '-EPROBE_DEFER' from GPIO subsystem. In other
words, there is no dependency issue between LMU modules. Those are just
platform device and driver.

OK, I'll remove LMU register helpers in the 2nd patch. Then, each LMU
driver will call regmap helpers directly.
Thanks for your comments.

Best regards,
Milo

2015-11-25 08:15:25

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH RESEND 06/16] mfd: add TI LMU driver

On Wed, 25 Nov 2015, Kim, Milo wrote:

> On 11/24/2015 5:18 PM, Lee Jones wrote:
> >On Tue, 24 Nov 2015, Kim, Milo wrote:
> >
> >>On 11/24/2015 11:35 AM, Kim, Milo wrote:
> >>>Hi Lee,
> >>>
> >>>Thanks for all your comments. Please see my comments below.
> >>>
> >>>On 11/23/2015 7:30 PM, Lee Jones wrote:
> >>>>>+int ti_lmu_read_byte(struct ti_lmu *lmu, u8 reg, u8 *read)
> >>>>>>+{
> >>>>>>+ int ret;
> >>>>>>+ unsigned int val;
> >>>>>>+
> >>>>>>+ ret = regmap_read(lmu->regmap, reg, &val);
> >>>>>>+ if (ret < 0)
> >>>>>>+ return ret;
> >>>>>>+
> >>>>>>+ *read = (u8)val;
> >>>>>>+ return 0;
> >>>>>>+}
> >>>>>>+EXPORT_SYMBOL_GPL(ti_lmu_read_byte);
> >>>>It doesn't get much more simple than this.
> >>>>
> >>>>What's the purpose of abstracting it?
> >>>>
> >>>>>>+int ti_lmu_write_byte(struct ti_lmu *lmu, u8 reg, u8 data)
> >>>>>>+{
> >>>>>>+ return regmap_write(lmu->regmap, reg, data);
> >>>>>>+}
> >>>>>>+EXPORT_SYMBOL_GPL(ti_lmu_write_byte);
> >>>>>>+
> >>>>>>+int ti_lmu_update_bits(struct ti_lmu *lmu, u8 reg, u8 mask, u8 data)
> >>>>>>+{
> >>>>>>+ return regmap_update_bits(lmu->regmap, reg, mask, data);
> >>>>>>+}
> >>>>>>+EXPORT_SYMBOL_GPL(ti_lmu_update_bits);
> >>>>Okay, I lied, it does get more simple.
> >>>>
> >>>>Seems like abstraction for the sake of abstraction here.
> >>>>
> >>>>Feel free to try and convince me otherwise.
> >>>>
> >>>
> >>>The main reason was that LMU MFD core provides consistent register
> >>>access among LMU drivers like ti-lmu-backlight, leds-lm3633,
> >>>lm363x-regulator and ti-lmu-fault-monitor('ti-lmu-hwmon' will be changed
> >>>to this in the 2nd patch).
> >>>
> >>>However, LMU register helpers are exactly same as regmap interface
> >>>except using ti_lmu data structure. So let me replace them with regmap
> >>>functions. Thanks for pointing this out.
> >>
> >>I just realized LMU MFD core helpers also provide module
> >>dependencies by using EXPORT_SYMBOL_GPL().
> >>
> >># modprobe -D ti-lmu-backlight
> >>insmod /lib/modules/<ver>/kernel/drivers/base/regmap/regmap-i2c.ko
> >>insmod /lib/modules/<ver>/kernel/drivers/mfd/mfd-core.ko
> >>insmod /lib/modules/<ver>/kernel/drivers/mfd/ti-lmu.ko
> >>insmod /lib/modules/<ver>/kernel/drivers/video/backlight/ti-lmu-backlight.ko
> >># modprobe -D ti-lmu-fault-monitor
> >>insmod /lib/modules/<ver>/kernel/drivers/base/regmap/regmap-i2c.ko
> >>insmod /lib/modules/<ver>/kernel/drivers/mfd/mfd-core.ko
> >>insmod /lib/modules/<ver>/kernel/drivers/mfd/ti-lmu.ko
> >>insmod /lib/modules/<ver>/kernel/drivers/mfd/ti-lmu-fault-monitor.ko
> >># modprobe -D lm363x-regulator
> >>insmod /lib/modules/<ver>/kernel/drivers/base/regmap/regmap-i2c.ko
> >>insmod /lib/modules/<ver>/kernel/drivers/mfd/mfd-core.ko
> >>insmod /lib/modules/<ver>/kernel/drivers/mfd/ti-lmu.ko
> >>insmod /lib/modules/<ver>/kernel/drivers/regulator/lm363x-regulator.ko
> >># modprobe -D leds-lm3633
> >>insmod /lib/modules/<ver>/kernel/drivers/base/regmap/regmap-i2c.ko
> >>insmod /lib/modules/<ver>/kernel/drivers/mfd/mfd-core.ko
> >>insmod /lib/modules/<ver>/kernel/drivers/mfd/ti-lmu.ko
> >>insmod /lib/modules/<ver>/kernel/drivers/leds/leds-lm3633.ko
> >>
> >>ti-lmu.ko should be loaded first because it has hardware enable pin
> >>control code. Four other drivers have dependency on this module.
> >>Without EXPORT_SYMBOL_GPL(), this dependency will be gone like
> >>below.
> >>
> >># modprobe -D ti-lmu-backlight
> >>insmod /lib/modules/<ver>/kernel/drivers/video/backlight/ti-lmu-backlight.ko
> >># modprobe -D ti-lmu-fault-monitor
> >>insmod /lib/modules/<ver>/kernel/drivers/mfd/ti-lmu-fault-monitor.ko
> >># modprobe -D lm363x-regulator
> >>insmod /lib/modules/<ver>/kernel/drivers/regulator/lm363x-regulator.ko
> >># modprobe -D leds-lm3633
> >>insmod /lib/modules/<ver>/kernel/drivers/leds/leds-lm3633.ko
> >>
> >>If LMU MFD core module is not loaded and other modules call regmap
> >>helpers, then loaded drivers will not work because hardware is not
> >>enabled yet.
> >>
> >>So I'd like to keep LMU MFD helpers for module dependencies.
> >>Additionally, I'll modify 'ti_lmu_read_byte()' as follows.
> >>
> >>int ti_lmu_read_byte(struct ti_lmu *lmu, u8 reg, u8 *read)
> >>{
> >> return regmap_read(lmu->regmap, reg, (unsigned int *)read);
> >>}
> >>EXPORT_SYMBOL_GPL(ti_lmu_read_byte);
> >>
> >>Please let me know if you have better idea.
> >
> >You're keeping the helpers for the wrong reasons. This has now become
> >a hack. If you have dependencies between modules, either use the init
> >levels or defer probe in the usual way.
> >
>
> Yes, I was wrong. In case LMU MFD core is not loaded, other LMU
> modules like ti-lmu-backlight isn't probed because no platform
> device (mfd device) exists. So the situation which I've mentioned
> never happens.
> And if GPIO controller is not ready and HW enable GPIO request gets
> failed on LMU MFD initialization, this will be processed later
> because it returns as error code '-EPROBE_DEFER' from GPIO
> subsystem. In other words, there is no dependency issue between LMU
> modules. Those are just platform device and driver.
>
> OK, I'll remove LMU register helpers in the 2nd patch. Then, each
> LMU driver will call regmap helpers directly.
> Thanks for your comments.

No problem. You are welcome.

--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

2015-11-25 08:51:12

by Kim, Milo

[permalink] [raw]
Subject: Re: [PATCH RESEND 00/16] Support TI LMU devices

On 11/3/2015 5:33 PM, Lee Jones wrote:
> On Tue, 03 Nov 2015, Kim, Milo wrote:
>
>> Hi Lee,
>>
>> On 11/2/2015 5:59 PM, Lee Jones wrote:
>>>> drivers/video/backlight/Kconfig | 62 ++
>>>>> drivers/video/backlight/Makefile | 7 +
>>>>> drivers/video/backlight/lm3532_bl.c | 183 +++++
>>>>> drivers/video/backlight/lm3631_bl.c | 129 ++++
>>>>> drivers/video/backlight/lm3632_bl.c | 125 ++++
>>>>> drivers/video/backlight/lm3633_bl.c | 210 ++++++
>>>>> drivers/video/backlight/lm3695_bl.c | 91 +++
>>>>> drivers/video/backlight/lm3697_bl.c | 187 +++++
>>>>> drivers/video/backlight/ti-lmu-backlight.c | 429 ++++++++++++
>>>>> drivers/video/backlight/ti-lmu-backlight.h | 152 +++++
>>> How different are all of these drivers?
>>>
>>> Can you create one driver that supports them all instead?
>>>
>>
>> Thanks for your suggestion.
>>
>> 'ti-lmu-backlight' is the common part of lmxxxx_bl drivers. And each
>> lmxxx_bl has its own operation functions by using ti_lmu_bl_ops.
>> I've tried to make consolidated driver but it contained too much
>> device specific code in one file. So I prefer simple drivers
>> structure - 'common part' and 'device specific operations'.
>> It would be appreciated if you could introduce better idea.
>
> I wish to avoid having to apply the patches to conduct my own analysis
> of the files, as I am severely restricted on time. Can you tell me how
> much duplicated code there is between the files? How many lines would
> be saved by supporting all of the lm* drivers in a single file?
>

Now, consolidated driver is ready. It improves not only lines of code
but also code size. Patch v2 will be sent soon.

Lines of code
-------------
194 lines are saved in consolidated driver.

Patch v1: 1420 (8 files*)
Patch v2: 1226 (3 files**)

* ti-lmu-backlight.c (429)
ti-lmu-backlight.h (152)
lm3532_bl.c (183)
lm3631_bl.c (129)
lm3632_bl.c (125)
lm3633_bl.c (210)
lm3695_bl.c (95)
lm3697_bl.c (97)

** ti-lmu-backlight-core.c (649)
ti-lmu-backlight-data.c (287)
ti-lmu-backlight.h (290)

Size
----
The text segment is decreased by removing duplicate instructions.

Patch v1
text data bss dec hex filename
12202 720 40 12962 32a2 drivers/video/backlight/built-in.o

Patch v2
text data bss dec hex filename
6883 712 41 7636 1dd4 drivers/video/backlight/built-in.o

Test environment
----------------
- Kernel version: 4.4.0-rc2 (linux-next)
- backlight/built-in.o includes backlight core and ti-lmu-backlight
drivers. No other backlight drivers included.

Change details will be described in the patch-set.

Best regards,
Milo

2015-11-25 09:06:03

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH RESEND 00/16] Support TI LMU devices

On Wed, 25 Nov 2015, Kim, Milo wrote:

> On 11/3/2015 5:33 PM, Lee Jones wrote:
> >On Tue, 03 Nov 2015, Kim, Milo wrote:
> >
> >>Hi Lee,
> >>
> >>On 11/2/2015 5:59 PM, Lee Jones wrote:
> >>>> drivers/video/backlight/Kconfig | 62 ++
> >>>>> drivers/video/backlight/Makefile | 7 +
> >>>>> drivers/video/backlight/lm3532_bl.c | 183 +++++
> >>>>> drivers/video/backlight/lm3631_bl.c | 129 ++++
> >>>>> drivers/video/backlight/lm3632_bl.c | 125 ++++
> >>>>> drivers/video/backlight/lm3633_bl.c | 210 ++++++
> >>>>> drivers/video/backlight/lm3695_bl.c | 91 +++
> >>>>> drivers/video/backlight/lm3697_bl.c | 187 +++++
> >>>>> drivers/video/backlight/ti-lmu-backlight.c | 429 ++++++++++++
> >>>>> drivers/video/backlight/ti-lmu-backlight.h | 152 +++++
> >>>How different are all of these drivers?
> >>>
> >>>Can you create one driver that supports them all instead?
> >>>
> >>
> >>Thanks for your suggestion.
> >>
> >>'ti-lmu-backlight' is the common part of lmxxxx_bl drivers. And each
> >>lmxxx_bl has its own operation functions by using ti_lmu_bl_ops.
> >>I've tried to make consolidated driver but it contained too much
> >>device specific code in one file. So I prefer simple drivers
> >>structure - 'common part' and 'device specific operations'.
> >>It would be appreciated if you could introduce better idea.
> >
> >I wish to avoid having to apply the patches to conduct my own analysis
> >of the files, as I am severely restricted on time. Can you tell me how
> >much duplicated code there is between the files? How many lines would
> >be saved by supporting all of the lm* drivers in a single file?
> >
>
> Now, consolidated driver is ready. It improves not only lines of
> code but also code size. Patch v2 will be sent soon.
>
> Lines of code
> -------------
> 194 lines are saved in consolidated driver.
>
> Patch v1: 1420 (8 files*)
> Patch v2: 1226 (3 files**)
>
> * ti-lmu-backlight.c (429)
> ti-lmu-backlight.h (152)
> lm3532_bl.c (183)
> lm3631_bl.c (129)
> lm3632_bl.c (125)
> lm3633_bl.c (210)
> lm3695_bl.c (95)
> lm3697_bl.c (97)
>
> ** ti-lmu-backlight-core.c (649)
> ti-lmu-backlight-data.c (287)
> ti-lmu-backlight.h (290)
>
> Size
> ----
> The text segment is decreased by removing duplicate instructions.
>
> Patch v1
> text data bss dec hex filename
> 12202 720 40 12962 32a2 drivers/video/backlight/built-in.o
>
> Patch v2
> text data bss dec hex filename
> 6883 712 41 7636 1dd4 drivers/video/backlight/built-in.o
>
> Test environment
> ----------------
> - Kernel version: 4.4.0-rc2 (linux-next)
> - backlight/built-in.o includes backlight core and ti-lmu-backlight
> drivers. No other backlight drivers included.
>
> Change details will be described in the patch-set.

Excellent news. Thanks for carrying out this work.

--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog