Skip to contentSkip to conversation

Palmas updates

PATCH Applied Ian Lartey 11 participants 32 messages Mar 22, 2013 – Aug 20, 2013

Subsystems (10)
lore
Share & tools
lore

Ian Lartey

author
#0 lore raw

v10 cover Palmas updates

This patchset adds to the support for the Palmas series of PMIC chips.

Some of the patches have previously been submitted individually. The DT bindings doc has been added first due to comments that it was missing.

Patches based on linux-next-20130319

Changes since v9
Added in missing [PATCH 01/12] mfd: DT bindings.
Now all patch sequence numbers with the v9 changes below are correct. Please refer to the changes below as they have not been reviewed.

Changes since v8
The .compatible = "palmas-charger-xxx" has been removed from the DT for all palmas source files as the charger driver is not yet present.

[PATCH 01/12] mfd: DT bindings... - Added in missing descriptions for properties and added in properties that were missing

[PATCH 08/12] gpio: Palmas.... - Added palmas_gpio_(read|write|update) gpio parameter renamed to offset
palmas_gpio_write renamed to palmas_gpio_clear_and_set
as it no longer takes a data value instead it always sets the offset bit and clears all other bits -
this is how it was being used by the callers

[PATCH 09/12] leds: Add support... - Combined patches for drivers/leds/leds-palmas.c, drivers/leds/Kconfig and drivers/leds/Makefile. palmas_dt_to_pdata - added bounds checking for DT values and removed use of child node.
palmas_led.on_time and palmas_led.period both changed to enums. palmas_get_crtl_and_period added which contains factored code from palmas_leds_work for maintainability.

[PATCH 10/12] clk: Add a clock... - clock names taken from DT if provided

palmas-regulator not in patchset - patch Now applied by Mark Brown

[PATCH 12/12] regulator: palmas-charger-pmic removed from DT compatible list

 .../devicetree/bindings/clock/palmas-clk.txt       |   27 +
 .../devicetree/bindings/gpio/gpio-palmas.txt       |   35 ++
 .../devicetree/bindings/input/palmas-pwrbutton.txt |   26 +
 .../devicetree/bindings/leds/leds-palmas.txt       |   36 ++
 Documentation/devicetree/bindings/mfd/palmas.txt   |   81 +++
 .../devicetree/bindings/regulator/palmas-pmic.txt  |  168 ++++++
 .../devicetree/bindings/rtc/palmas-rtc.txt         |   21 +
 .../devicetree/bindings/watchdog/palmas-wdt.txt    |   21 +
 drivers/clk/Kconfig                                |    8 +
 drivers/clk/Makefile                               |    1 +
 drivers/clk/clk-palmas.c                           |  275 ++++++++++
 drivers/gpio/gpio-palmas.c                         |   90 +++-
 drivers/leds/Kconfig                               |    9 +
 drivers/leds/Makefile                              |    1 +
 drivers/leds/leds-palmas.c                         |  561 ++++++++++++++++++++
 drivers/mfd/palmas.c                               |  102 +++-
 drivers/regulator/palmas-regulator.c               |    1 -
 drivers/watchdog/Kconfig                           |    8 +
 drivers/watchdog/Makefile                          |    1 +
 drivers/watchdog/palmas_wdt.c                      |  169 ++++++
 include/linux/mfd/palmas.h                         |  139 +++++-
 21 files changed, 1739 insertions(+), 41 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/clock/palmas-clk.txt
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-palmas.txt
 create mode 100644 Documentation/devicetree/bindings/input/palmas-pwrbutton.txt
 create mode 100644 Documentation/devicetree/bindings/leds/leds-palmas.txt
 create mode 100644 Documentation/devicetree/bindings/mfd/palmas.txt
 create mode 100644 Documentation/devicetree/bindings/regulator/palmas-pmic.txt
 create mode 100644 Documentation/devicetree/bindings/rtc/palmas-rtc.txt
 create mode 100644 Documentation/devicetree/bindings/watchdog/palmas-wdt.txt
 create mode 100644 drivers/clk/clk-palmas.c
 create mode 100644 drivers/leds/leds-palmas.c
 create mode 100644 drivers/watchdog/palmas_wdt.c
author
#1 lore raw

PATCH v10 1/12 mfd: DT bindings for the palmas family MFD

From: Graeme Gregory <[email protected]>

Add the various binding files for the palmas family of chips. There is a top level MFD binding then a seperate binding for IP blocks on chips.

---
 .../devicetree/bindings/clock/palmas-clk.txt       |   27 +++
 .../devicetree/bindings/gpio/gpio-palmas.txt       |   35 ++++
 .../devicetree/bindings/input/palmas-pwrbutton.txt |   26 +++
 .../devicetree/bindings/leds/leds-palmas.txt       |   36 ++++
 Documentation/devicetree/bindings/mfd/palmas.txt   |   81 ++++++++++
 .../devicetree/bindings/regulator/palmas-pmic.txt  |  168 ++++++++++++++++++++
 .../devicetree/bindings/rtc/palmas-rtc.txt         |   21 +++
 .../devicetree/bindings/watchdog/palmas-wdt.txt    |   21 +++
 8 files changed, 415 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/clock/palmas-clk.txt
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-palmas.txt
 create mode 100644 Documentation/devicetree/bindings/input/palmas-pwrbutton.txt
 create mode 100644 Documentation/devicetree/bindings/leds/leds-palmas.txt
 create mode 100644 Documentation/devicetree/bindings/mfd/palmas.txt
 create mode 100644 Documentation/devicetree/bindings/regulator/palmas-pmic.txt
 create mode 100644 Documentation/devicetree/bindings/rtc/palmas-rtc.txt
 create mode 100644 Documentation/devicetree/bindings/watchdog/palmas-wdt.txt
Documentation/devicetree/bindings/clock/palmas-clk.txt new file +27 -0
new file mode 100644
index 0000000..26fbc9f
@@ -0,0 +1,27 @@
+* palmas and palmas-charger resource clock IP block devicetree bindings
+
+Required properties:
+- compatible : Should be from the list
+  ti,twl6035-clk
+  ti,twl6036-clk
+  ti,twl6037-clk
+  ti,tps65913-clk
+  ti,tps65914-clk
+  ti,tps80036-clk
+and also the generic series names
+  ti,palmas-clk
+
+Optional properties:
+- ti,clk32g-mode-sleep		- mode to adopt in pmic sleep 0 - off, 1 - on
+- ti,clkg32kgaudio-mode-sleep	- see above
+
+Example:
+
+clk {
+    compatible = "ti,twl6035-clk", "ti,palmas-clk";
+    ti,clk32kg-mode-sleep = <0>;
+    ti,clk32kgaudio-mode-sleep = <0>;
+    #clock-cells = <1>;
+    clock-frequency = <32000000>;
+    clock-names = "clk32kg", "clk32kgaudio";
+};
Documentation/devicetree/bindings/gpio/gpio-palmas.txt new file +35 -0
new file mode 100644
index 0000000..688eebb
@@ -0,0 +1,35 @@
+* palmas and palmas charger GPIO IP block devicetree bindings
+
+Required properties:
+- compatible : Should be from the list
+  ti,twl6035-gpio
+  ti,twl6036-gpio
+  ti,twl6037-gpio
+  ti,tps65913-gpio
+  ti,tps65914-gpio
+  ti,tps80036-gpio
+
+and also the generic series names
+
+  ti,palmas-gpio
+
+- gpio-controller: mark the device as a GPIO controller
+- gpio-cells = <1>:  GPIO lines are provided.
+- interrupt-controller : palmas has its own internal IRQs
+- #interrupt-cells : should be set to 2 for IRQ number and flags
+  The first cell is the IRQ number.
+  The second cell is the flags, encoded as the trigger masks from
+  Documentation/devicetree/bindings/interrupts.txt
+- interrupt-parent : The parent interrupt controller.
+
+Example:
+
+gpio {
+    compatible = "ti,twl6035-gpio", "ti,palmas-gpio";
+
+    gpio-controller;
+    #gpio-cells = <1>;
+    interrupt-parent = <&palmas>;
+    interrupt-controller;
+    #interrupt-cells = <2>;
+};
Documentation/devicetree/bindings/input/palmas-pwrbutton.txt new file +26 -0
new file mode 100644
index 0000000..722ca94
@@ -0,0 +1,26 @@
+* palmas and palmas-charger Button IP block devicetree bindings
+
+Required properties:
+- compatible : Should be from the list
+  ti,twl6035-pwrbutton
+  ti,twl6036-pwrbutton
+  ti,twl6037-pwrbutton
+  ti,tps65913-pwrbutton
+  ti,tps65914-pwrbutton
+  ti,tps80036-pwrbutton
+and also the generic series names
+  ti,palmas-pwrbutton
+
+- interrupts: the interrupt outputs of the controller.
+- interrupt-names : Should be the name of irq resource. Each interrupt
+  binds its interrupt-name.
+- interrupt-parent : The parent interrupt controller.
+
+Example:
+
+pwrbutton {
+    compatible = "ti,twl6035-pwrbutton", "ti,palmas-pwrbutton";
+    interrupt-parent = <&palmas>;
+    interrupts = <1 0>;
+    interrupt-names = "pwron-irq";
+};
Documentation/devicetree/bindings/leds/leds-palmas.txt new file +36 -0
new file mode 100644
index 0000000..a825f43
@@ -0,0 +1,36 @@
+* palmas and palmas-charger LED IP block devicetree bindings
+
+Required properties:
+- compatible : Should be from the list
+  ti,twl6035-leds
+  ti,twl6036-leds
+  ti,twl6037-leds
+  ti,tps65913-leds
+  ti,tps65914-leds
+  ti,tps80036-leds
+and also the generic series names
+  ti,palmas-leds
+
+Optional properties:
+-ti,led1-current	- sink current setting 0 - 0mA, 1 - 25mA, 2 - 5mA,
+				3 - 0mA, 4 - 5mA, 5 - 5mA, 6 - 10.0mA, 7 - 0mA
+-ti,led2-current	- see above
+-ti,led3-current	- see above
+-ti,led4-current	- see above
+-ti,chrg-led-mode	- only valid for charger - mode for charging led operation
+				0 - Charging indicator
+				1 - controlled as a general purpose LED
+-ti,chrg-led-vbat-low	- only valid for charger - blinking of low battery led 
+				0 - blinking is enabled,
+				1 - blinking is disabled
+
+Example:
+leds {
+	compatible = "ti,twl6035-leds", "ti,palmas-leds";
+	ti,led1-current = <0>;
+	ti,led2-current = <0>;
+	ti,led3-current = <0>;
+	ti,led4-current = <0>;
+	ti,chrg-led-mode = <0>;
+	ti,chrg-led-vbat-low = <0>;
+};
Documentation/devicetree/bindings/mfd/palmas.txt new file +81 -0

81 lines not on this page · raw message

Documentation/devicetree/bindings/regulator/palmas-pmic.txt new file +168 -0

168 lines not on this page · raw message

Documentation/devicetree/bindings/rtc/palmas-rtc.txt new file +21 -0
new file mode 100644
index 0000000..f405b36
@@ -0,0 +1,21 @@
+* palmas and palmas-charger RTC IP block devicetree bindings
+
+Required properties:
+- compatible : Should be from the list
+  ti,twl6035-rtc
+  ti,twl6036-rtc
+  ti,twl6037-rtc
+  ti,tps65913-rtc
+  ti,tps65914-rtc
+  ti,tps80036-rtc
+and also the generic series names
+  ti,palmas-rtc
+
+Examples:
+
+rtc {
+    compatible = "ti,twl6035-rtc", "ti,palmas-rtc";
+    interrupt-parent = <&palmas>;
+    interrupts = <8 0 9 0>;
+    interrupt-name = "alarm-irq", "timer-irq";
+};
Documentation/devicetree/bindings/watchdog/palmas-wdt.txt new file +21 -0
new file mode 100644
index 0000000..1553a0d
@@ -0,0 +1,21 @@
+* palmas and palmas-charger Watchdog IP block devicetree bindings
+
+Required properties:
+- compatible : Should be from the list
+  ti,twl6035-wdt
+  ti,twl6036-wdt
+  ti,twl6037-wdt
+  ti,tps65913-wdt
+  ti,tps65914-wdt
+  ti,tps80036-wdt
+and also the generic series names
+  ti,palmas-wdt
+
+Examples:
+
+wdt {
+    compatible = "ti,twl6035-wdt", "ti,palmas-wdt";
+    interrupt-parent = <&palmas>;
+    interrupts = <10 0>;
+    interrupt-name = "watchdog-irq";
+};
Signature · 1 line
1.7.0.4
#2 lore raw

Re: [PATCH v10 01/12] mfd: DT bindings for the palmas family MFD

Documentation/devicetree/bindings/clock/palmas-clk.txt

Quoted 6 lines · Ian Lartey

From: Graeme Gregory <[email protected]>

Add the various binding files for the palmas family of chips. There is a top level MFD binding then a seperate binding for IP blocks on chips.

Documentation/devicetree/bindings/clock/palmas-clk.txt +0 -0

Where is the reg property; if you're instantiating the clk device as a standalone DT node and driver, it should be possible to retrieve the address of this IP block instance from DT, not using driver-internal APIs.

This same comment likely applies everywhere, so I won't repeat it.

Documentation/devicetree/bindings/clock/palmas-clk.txt line 26

Quoted 10 lines
Documentation/devicetree/bindings/clock/palmas-clk.txt +9 -0
+Example:
+
+clk {
+    compatible = "ti,twl6035-clk", "ti,palmas-clk";
+    ti,clk32kg-mode-sleep = <0>;
+    ti,clk32kgaudio-mode-sleep = <0>;
 
+    #clock-cells = <1>;
+    clock-frequency = <32000000>;
+    clock-names = "clk32kg", "clk32kgaudio";

The binding description itself should describe what clocks this node provides and consumes.

What is clock-frequency; which clock does it affect?

The presence of #clock-cells implies this is a clock provider. This binding should define the format of the clock cells that this property implies. I assume it's just the ID of the output clocks, but what values correspond to which output clocks? That mapping table needs to be listed here.

The presence of clock-names implies this is a clock consumer. However, there is no clocks property in the example. Is clks missing from the example, or should this property be clock-output-names instead? If this node is a clock consumer, the list of which clocks it requires should be documented.

Documentation/devicetree/bindings/gpio/gpio-palmas.txt line 17

Quoted 4 lines
Documentation/devicetree/bindings/gpio/gpio-palmas.txt +2 -0
 
+- gpio-controller: mark the device as a GPIO controller
+- gpio-cells = <1>:  GPIO lines are provided.

That's #gpio-cells not gpio-cells.

I assume that cell simply contains the GPIO ID/number. That should be documented for clarity.

Surely gpio-cells should be 2 not 1, so there is space for flags. At least an "inverted" or "active-low" flag should be included; GPIO consumers would typically implement that flag in SW, so there' no requirement that the flag only be supported if the HW supports the feature.

Documentation/devicetree/bindings/gpio/gpio-palmas.txt line 22

Quoted 5 lines
+- interrupt-controller : palmas has its own internal IRQs
+- #interrupt-cells : should be set to 2 for IRQ number and flags
Documentation/devicetree/bindings/gpio/gpio-palmas.txt +3 -0
+  The first cell is the IRQ number.
+  The second cell is the flags, encoded as the trigger masks from
+  Documentation/devicetree/bindings/interrupts.txt

You need "/interrupt-controller" before the filename there.

Quoted 1 line

+- interrupt-parent : The parent interrupt controller.

If this IP block has interrupt outputs, it should require an "interrupts" property too. This is the same concept that drives the need for a reg property. This same comment likely applies everywhere, so I won't repeat it.

Documentation/devicetree/bindings/input/palmas-pwrbutton.txt

Quoted 3 lines
Documentation/devicetree/bindings/input/palmas-pwrbutton.txt +1 -0
 
+- interrupts: the interrupt outputs of the controller.

How many entries are there, what do they mean, and in what order must they appear? (Note that the binding of a node must define the order of the interrupts property, since historically it's been accessed by index, not by name, and all bindings must allow that access method to be used).

Quoted 2 lines
+- interrupt-names : Should be the name of irq resource. Each interrupt
+  binds its interrupt-name.

The binding needs to define standard names for the entries in this property, or define that interrupts are only retrieved by index, in which case interrupt-names shouldn't be present. This same comment likely applies everywhere, so I won't repeat it.

Documentation/devicetree/bindings/mfd/palmas.txt

Quoted 3 lines
Documentation/devicetree/bindings/mfd/palmas.txt +1 -0
 
+Required properties:

...

I believe the Palmas devices have many separate I2C addresses, even buses, which are I think are at least partially independently SW configurable. In that case, the reg property for this node should probably enumerate all the I2C addresses that this chip responds to, so that they can each be passed down to the child nodes.

Documentation/devicetree/bindings/regulator/palmas-pmic.txt line 25

Quoted 11 lines
Documentation/devicetree/bindings/regulator/palmas-pmic.txt +9 -0
 
+Optional nodes:
+- regulators : should contain the constrains and init information for the
+	       regulators. It should contain a subnode per regulator from the
+	       list.
+	       For ti,palmas-pmic - smps12, smps123, smps3 depending on OTP,
+	       smps45, smps457, smps7 depending on varient, smps6, smps[8-10],
+	       ldo[1-9], ldoln, ldousb
+	       For ti,palmas-charger-pmic - smps12, smps123, smps3 depending on OTP,
+	       smps[6-9], boost, ldo[1-14], ldoln, ldousb

The list of legal compatible values for this node above doesn't include both ti,palmas-pmic and ti,palmas-charger-pmic. Should it? This node should describe this PMIC block in a completely standalone fashion, without the need to go look at the top-level node to see if it's a "charger" variant or not.

Documentation/devicetree/bindings/regulator/palmas-pmic.txt line 29

Quoted 3 lines
Documentation/devicetree/bindings/regulator/palmas-pmic.txt +3 -0
+	       optional chip specific regulator fields :-
+	       ti,warm-reset - maintain voltage during warm reset
+	       ti,roof-floor - control voltage selection by pin

I assume those are Boolean not integer. It's worth mentioning the type of each property.

#3 lore raw

Re: [PATCH v10 01/12] mfd: DT bindings for the palmas family MFD

Quoted 18 lines · Stephen Warren

Documentation/devicetree/bindings/regulator/palmas-pmic.txt line 25

Quoted 11 lines · Ian Lartey

From: Graeme Gregory <[email protected]>

Documentation/devicetree/bindings/regulator/palmas-pmic.txt new file +9 -0
+Optional nodes:
+- regulators : should contain the constrains and init information for the
+	       regulators. It should contain a subnode per regulator from the
+	       list.
+	       For ti,palmas-pmic - smps12, smps123, smps3 depending on OTP,
+	       smps45, smps457, smps7 depending on varient, smps6, smps[8-10],
+	       ldo[1-9], ldoln, ldousb
+	       For ti,palmas-charger-pmic - smps12, smps123, smps3 depending on OTP,
+	       smps[6-9], boost, ldo[1-14], ldoln, ldousb

The list of legal compatible values for this node above doesn't include both ti,palmas-pmic and ti,palmas-charger-pmic. Should it? This node should describe this PMIC block in a completely standalone fashion, without the need to go look at the top-level node to see if it's a "charger" variant or not.

The latter was removed from the code in this series, only palmas-pmic is present now.

Just as a general thing there seems to be an awful lot of stuff here
about the boilerplate for the generic properties like the interrupt
and GPIO controller stuff - we probably need to spin round and look at
factoring this out to make life easier. There seems to be a lot of
boiler plate in the bindings that is factored out well by the frameworks
in the code so people don't even need to think about it.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130325/8d8b256f/attachment.sig>

#4 lore raw

Re: [PATCH v10 01/12] mfd: DT bindings for the palmas family MFD

In reply to Stephen Warren
Quoted 91 lines · Stephen Warren

Documentation/devicetree/bindings/clock/palmas-clk.txt

Quoted 6 lines · Ian Lartey

From: Graeme Gregory <[email protected]>

Add the various binding files for the palmas family of chips. There is a top level MFD binding then a seperate binding for IP blocks on chips.

Documentation/devicetree/bindings/clock/palmas-clk.txt +0 -0

Where is the reg property; if you're instantiating the clk device as a standalone DT node and driver, it should be possible to retrieve the address of this IP block instance from DT, not using driver-internal APIs.

This same comment likely applies everywhere, so I won't repeat it.

Documentation/devicetree/bindings/clock/palmas-clk.txt line 26

Quoted 10 lines
Documentation/devicetree/bindings/clock/palmas-clk.txt +9 -0
+Example:
+
+clk {
+    compatible = "ti,twl6035-clk", "ti,palmas-clk";
+    ti,clk32kg-mode-sleep = <0>;
+    ti,clk32kgaudio-mode-sleep = <0>;
 
+    #clock-cells = <1>;
+    clock-frequency = <32000000>;
+    clock-names = "clk32kg", "clk32kgaudio";

The binding description itself should describe what clocks this node provides and consumes.

What is clock-frequency; which clock does it affect?

The presence of #clock-cells implies this is a clock provider. This binding should define the format of the clock cells that this property implies. I assume it's just the ID of the output clocks, but what values correspond to which output clocks? That mapping table needs to be listed here.

The presence of clock-names implies this is a clock consumer. However, there is no clocks property in the example. Is clks missing from the example, or should this property be clock-output-names instead? If this node is a clock consumer, the list of which clocks it requires should be documented.

Documentation/devicetree/bindings/gpio/gpio-palmas.txt line 17

Quoted 4 lines
Documentation/devicetree/bindings/gpio/gpio-palmas.txt +2 -0
 
+- gpio-controller: mark the device as a GPIO controller
+- gpio-cells = <1>:  GPIO lines are provided.

That's #gpio-cells not gpio-cells.

I assume that cell simply contains the GPIO ID/number. That should be documented for clarity.

Surely gpio-cells should be 2 not 1, so there is space for flags. At least an "inverted" or "active-low" flag should be included; GPIO consumers would typically implement that flag in SW, so there' no requirement that the flag only be supported if the HW supports the feature.

Documentation/devicetree/bindings/gpio/gpio-palmas.txt line 22

Quoted 5 lines
+- interrupt-controller : palmas has its own internal IRQs
+- #interrupt-cells : should be set to 2 for IRQ number and flags
Documentation/devicetree/bindings/gpio/gpio-palmas.txt +3 -0
+  The first cell is the IRQ number.
+  The second cell is the flags, encoded as the trigger masks from
+  Documentation/devicetree/bindings/interrupts.txt

You need "/interrupt-controller" before the filename there.

Quoted 1 line

+- interrupt-parent : The parent interrupt controller.

If this IP block has interrupt outputs, it should require an "interrupts" property too. This is the same concept that drives the need for a reg property. This same comment likely applies everywhere, so I won't repeat it.

Documentation/devicetree/bindings/input/palmas-pwrbutton.txt

Quoted 3 lines
Documentation/devicetree/bindings/input/palmas-pwrbutton.txt +1 -0
 
+- interrupts: the interrupt outputs of the controller.

How many entries are there, what do they mean, and in what order must they appear? (Note that the binding of a node must define the order of the interrupts property, since historically it's been accessed by index, not by name, and all bindings must allow that access method to be used).

Quoted 2 lines
+- interrupt-names : Should be the name of irq resource. Each interrupt
+  binds its interrupt-name.

The binding needs to define standard names for the entries in this property, or define that interrupts are only retrieved by index, in which case interrupt-names shouldn't be present. This same comment likely applies everywhere, so I won't repeat it.

Quoted 1 line
Documentation/devicetree/bindings/mfd/palmas.txt +0 -0
Quoted 8 lines
Quoted 1 line

+Required properties:

...

I believe the Palmas devices have many separate I2C addresses, even buses, which are I think are at least partially independently SW configurable. In that case, the reg property for this node should probably enumerate all the I2C addresses that this chip responds to, so that they can each be passed down to the child nodes.

Stephen,

The palmas devices do have multiple I2C slave IDs. From OMAP5 as the master all the palmas slave devices are connected via I2C1 bus.

I did not understand the SW configurable part. It is more board dependent. Correct me if i understood it wrongly.

Graeme,

Can i send a separate Documentation patch for palmas-core and palmas-regulators outside this series since the drivers are already part of mainline kernel. This will ensure at least the bare minimal DT support for palmas family will be available in the mainline kernel?

Quoted 20 lines

Documentation/devicetree/bindings/regulator/palmas-pmic.txt line 25

Quoted 13 lines
Documentation/devicetree/bindings/regulator/palmas-pmic.txt +9 -0
 
+Optional nodes:
+- regulators : should contain the constrains and init information for the
+	       regulators. It should contain a subnode per regulator from the
+	       list.
+	       For ti,palmas-pmic - smps12, smps123, smps3 depending on OTP,
+	       smps45, smps457, smps7 depending on varient, smps6, smps[8-10],
+	       ldo[1-9], ldoln, ldousb
+	       For ti,palmas-charger-pmic - smps12, smps123, smps3 depending on OTP,
+	       smps[6-9], boost, ldo[1-14], ldoln, ldousb

The list of legal compatible values for this node above doesn't include both ti,palmas-pmic and ti,palmas-charger-pmic. Should it? This node should describe this PMIC block in a completely standalone fashion, without the need to go look at the top-level node to see if it's a "charger" variant or not.

Quoted 6 lines

Documentation/devicetree/bindings/regulator/palmas-pmic.txt line 29

Quoted 3 lines
Documentation/devicetree/bindings/regulator/palmas-pmic.txt +3 -0
+	       optional chip specific regulator fields :-
+	       ti,warm-reset - maintain voltage during warm reset
+	       ti,roof-floor - control voltage selection by pin

I assume those are Boolean not integer. It's worth mentioning the type of each property.

Reagrds,
Keerthy

#5 lore raw

Re: [PATCH v10 01/12] mfd: DT bindings for the palmas family MFD

Quoted 104 lines · keerthy
Quoted 91 lines · Stephen Warren

Documentation/devicetree/bindings/clock/palmas-clk.txt

Quoted 6 lines · Ian Lartey

From: Graeme Gregory <[email protected]>

Add the various binding files for the palmas family of chips. There is a top level MFD binding then a seperate binding for IP blocks on chips.

Documentation/devicetree/bindings/clock/palmas-clk.txt +0 -0

Where is the reg property; if you're instantiating the clk device as a standalone DT node and driver, it should be possible to retrieve the address of this IP block instance from DT, not using driver-internal APIs.

This same comment likely applies everywhere, so I won't repeat it.

Documentation/devicetree/bindings/clock/palmas-clk.txt line 26

Quoted 10 lines
Documentation/devicetree/bindings/clock/palmas-clk.txt +9 -0
+Example:
+
+clk {
+    compatible = "ti,twl6035-clk", "ti,palmas-clk";
+    ti,clk32kg-mode-sleep = <0>;
+    ti,clk32kgaudio-mode-sleep = <0>;
 
+    #clock-cells = <1>;
+    clock-frequency = <32000000>;
+    clock-names = "clk32kg", "clk32kgaudio";

The binding description itself should describe what clocks this node provides and consumes.

What is clock-frequency; which clock does it affect?

The presence of #clock-cells implies this is a clock provider. This binding should define the format of the clock cells that this property implies. I assume it's just the ID of the output clocks, but what values correspond to which output clocks? That mapping table needs to be listed here.

The presence of clock-names implies this is a clock consumer. However, there is no clocks property in the example. Is clks missing from the example, or should this property be clock-output-names instead? If this node is a clock consumer, the list of which clocks it requires should be documented.

Documentation/devicetree/bindings/gpio/gpio-palmas.txt line 17

Quoted 4 lines
Documentation/devicetree/bindings/gpio/gpio-palmas.txt +2 -0
 
+- gpio-controller: mark the device as a GPIO controller
+- gpio-cells = <1>:  GPIO lines are provided.

That's #gpio-cells not gpio-cells.

I assume that cell simply contains the GPIO ID/number. That should be documented for clarity.

Surely gpio-cells should be 2 not 1, so there is space for flags. At least an "inverted" or "active-low" flag should be included; GPIO consumers would typically implement that flag in SW, so there' no requirement that the flag only be supported if the HW supports the feature.

Documentation/devicetree/bindings/gpio/gpio-palmas.txt line 22

Quoted 5 lines
+- interrupt-controller : palmas has its own internal IRQs
+- #interrupt-cells : should be set to 2 for IRQ number and flags
Documentation/devicetree/bindings/gpio/gpio-palmas.txt +3 -0
+  The first cell is the IRQ number.
+  The second cell is the flags, encoded as the trigger masks from
+  Documentation/devicetree/bindings/interrupts.txt

You need "/interrupt-controller" before the filename there.

Quoted 1 line

+- interrupt-parent : The parent interrupt controller.

If this IP block has interrupt outputs, it should require an "interrupts" property too. This is the same concept that drives the need for a reg property. This same comment likely applies everywhere, so I won't repeat it.

Documentation/devicetree/bindings/input/palmas-pwrbutton.txt

Quoted 3 lines
Documentation/devicetree/bindings/input/palmas-pwrbutton.txt +1 -0
 
+- interrupts: the interrupt outputs of the controller.

How many entries are there, what do they mean, and in what order must they appear? (Note that the binding of a node must define the order of the interrupts property, since historically it's been accessed by index, not by name, and all bindings must allow that access method to be used).

Quoted 2 lines
+- interrupt-names : Should be the name of irq resource. Each interrupt
+  binds its interrupt-name.

The binding needs to define standard names for the entries in this property, or define that interrupts are only retrieved by index, in which case interrupt-names shouldn't be present. This same comment likely applies everywhere, so I won't repeat it.

Quoted 1 line
Documentation/devicetree/bindings/mfd/palmas.txt +0 -0
Quoted 8 lines
Quoted 1 line

+Required properties:

...

I believe the Palmas devices have many separate I2C addresses, even buses, which are I think are at least partially independently SW configurable. In that case, the reg property for this node should probably enumerate all the I2C addresses that this chip responds to, so that they can each be passed down to the child nodes.

Quoted 7 lines

Stephen,

The palmas devices do have multiple I2C slave IDs. From OMAP5 as the master all the palmas slave devices are connected via I2C1 bus.

I did not understand the SW configurable part. It is more board dependent. Correct me if i understood it wrongly.

IIRC (and I may not sine it's been a while since I looked at this), there are SW registers that can modify the I2C address that the chip will respond to, so you could access the main I2C address, then program which other I2C addresses get used.

Or, perhaps I was just thinking of the fact that there are strapping pins on the chip that affect both the main I2C address, and some/all of the other I2C addresses, so the driver needs to be told each and every I2C address, not just one single overall I2C address.

#6 lore raw

PATCH v10 1/12 mfd: DT bindings for the palmas family MFD

Hi Stephen,

Quoted 140 lines

-----Original Message-----
From: Stephen Warren [mailto:swarren at wwwdotorg.org]
Sent: Friday, May 31, 2013 4:34 AM
To: J, KEERTHY
Cc: gg at slimlogic.co.uk; Ian Lartey; linux-kernel at vger.kernel.org; linux-doc at vger.kernel.org; linux-arm-kernel at lists.infradead.org; linux- leds at vger.kernel.org; linux-watchdog at vger.kernel.org; devicetree- discuss at lists.ozlabs.org; grant.likely at secretlab.ca; broonie at opensource.wolfsonmicro.com; rob.herring at calxeda.com; rob at landley.net; mturquette at linaro.org; linus.walleij at linaro.org; cooloney at gmail.com; sfr at canb.auug.org.au; rpurdie at rpsys.net; akpm at linux-foundation.org; sameo at linux.intel.com; wim at iguana.be; lgirdwood at gmail.com; ldewangan at nvidia.com; Kristo, Tero
Subject: Re: [PATCH v10 01/12] mfd: DT bindings for the palmas family MFD

Quoted 8 lines · keerthy
Quoted 5 lines · Stephen Warren
Quoted 4 lines · Ian Lartey

From: Graeme Gregory <[email protected]>

Add the various binding files for the palmas family of chips. There is a top level MFD binding then a seperate binding for IP blocks on

chips.

Quoted 7 lines
Quoted 7 lines

Documentation/devicetree/bindings/clock/palmas-clk.txt

Quoted 3 lines
Documentation/devicetree/bindings/clock/palmas-clk.txt +0 -0

Where is the reg property; if you're instantiating the clk device as a standalone DT node and driver, it should be possible to retrieve the address of this IP block instance from DT, not using driver-

internal APIs.

Quoted 14 lines
Quoted 14 lines

This same comment likely applies everywhere, so I won't repeat it.

Quoted 10 lines
Documentation/devicetree/bindings/clock/palmas-clk.txt +9 -0
+Example:
+
+clk {
+    compatible = "ti,twl6035-clk", "ti,palmas-clk";
+    ti,clk32kg-mode-sleep = <0>;
+    ti,clk32kgaudio-mode-sleep = <0>;
 
+    #clock-cells = <1>;
+    clock-frequency = <32000000>;
+    clock-names = "clk32kg", "clk32kgaudio";
Quoted 8 lines
Quoted 8 lines

The binding description itself should describe what clocks this node provides and consumes.

What is clock-frequency; which clock does it affect?

The presence of #clock-cells implies this is a clock provider. This binding should define the format of the clock cells that this property implies. I assume it's just the ID of the output clocks,

but

Quoted 12 lines
Quoted 12 lines

what values correspond to which output clocks? That mapping table needs to be listed here.

The presence of clock-names implies this is a clock consumer. However, there is no clocks property in the example. Is clks missing from the example, or should this property be clock-output-names instead? If this node is a clock consumer, the list of which clocks it requires should be documented.

Quoted 2 lines
Documentation/devicetree/bindings/gpio/gpio-palmas.txt +0 -0
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
+- gpio-controller: mark the device as a GPIO controller
+- gpio-cells = <1>:  GPIO lines are provided.

That's #gpio-cells not gpio-cells.

I assume that cell simply contains the GPIO ID/number. That should

be

Quoted 6 lines
Quoted 6 lines

documented for clarity.

Surely gpio-cells should be 2 not 1, so there is space for flags. At least an "inverted" or "active-low" flag should be included; GPIO consumers would typically implement that flag in SW, so there' no requirement that the flag only be supported if the HW supports the

feature.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
+- interrupt-controller : palmas has its own internal IRQs
+- #interrupt-cells : should be set to 2 for IRQ number and flags
Documentation/devicetree/bindings/gpio/gpio-palmas.txt +3 -0
+  The first cell is the IRQ number.
+  The second cell is the flags, encoded as the trigger masks from
+  Documentation/devicetree/bindings/interrupts.txt
Quoted 7 lines
Quoted 7 lines

You need "/interrupt-controller" before the filename there.

Quoted 1 line

+- interrupt-parent : The parent interrupt controller.

If this IP block has interrupt outputs, it should require an "interrupts" property too. This is the same concept that drives the need for a reg property. This same comment likely applies

everywhere,

Quoted 9 lines
Quoted 9 lines

so I won't repeat it.

Quoted 5 lines

diff --git a/Documentation/devicetree/bindings/input/palmas-pwrbutton.txt b/Documentation/devicetree/bindings/input/palmas-pwrbutton.txt

+- interrupts: the interrupt outputs of the controller.

How many entries are there, what do they mean, and in what order

must

Quoted 3 lines
Quoted 3 lines

they appear? (Note that the binding of a node must define the order of the interrupts property, since historically it's been accessed by index, not by name, and all bindings must allow that access method

to be used).

Quoted 28 lines
Quoted 13 lines

Documentation/devicetree/bindings/gpio/gpio-palmas.txt

Quoted 4 lines

+- interrupt-names : Should be the name of irq resource. Each

Documentation/devicetree/bindings/gpio/gpio-palmas.txt +2 -0
+interrupt
+  binds its interrupt-name.

The binding needs to define standard names for the entries in this property, or define that interrupts are only retrieved by index, in which case interrupt-names shouldn't be present. This same comment likely applies everywhere, so I won't repeat it.

Quoted 2 lines
Documentation/devicetree/bindings/mfd/palmas.txt +0 -0
Quoted 8 lines
Quoted 1 line

+Required properties:

...

I believe the Palmas devices have many separate I2C addresses, even buses, which are I think are at least partially independently SW configurable. In that case, the reg property for this node should probably enumerate all the I2C addresses that this chip responds to, so that they can each be passed down to the child nodes.

Stephen,

The palmas devices do have multiple I2C slave IDs. From OMAP5 as the master all the palmas slave devices are connected via I2C1 bus.

Quoted 7 lines
Quoted 2 lines

I did not understand the SW configurable part. It is more board dependent. Correct me if i understood it wrongly.

IIRC (and I may not sine it's been a while since I looked at this), there are SW registers that can modify the I2C address that the chip will respond to, so you could access the main I2C address, then program which other I2C addresses get used.

Ok. I guess you are referring to the I2C_SPI register of Palmas. This register is indeed SW configurable and I tried changing the Slave IDs on the fly and I could change them. AFAIK these are OTP And never changed through software on the fly.

Quoted 5 lines

Or, perhaps I was just thinking of the fact that there are strapping pins on the chip that affect both the main I2C address, and some/all of the other I2C addresses, so the driver needs to be told each and every I2C address, not just one single overall I2C address.

Looking at the register spec there seem to be 2 possible combinations:
0x48, 0x49, 0x4A or 0x58, 0x59, 0x5A. Again these are OTP. By default It is 0x48, 0x49, 0x4A. So passing 0x48 or 0x58 as the main I2C Address seems sufficient here.

Regards,
Keerthy

#7 lore raw

RE: [PATCH v10 01/12] mfd: DT bindings for the palmas family MFD

Quoted 164 lines · KEERTHY

Hi Stephen,

Quoted 141 lines

-----Original Message-----
From: Stephen Warren [mailto:swarren at wwwdotorg.org]
Sent: Friday, May 31, 2013 4:34 AM
To: J, KEERTHY
Cc: gg at slimlogic.co.uk; Ian Lartey; linux-kernel at vger.kernel.org; linux-doc at vger.kernel.org; linux-arm-kernel at lists.infradead.org; linux-
leds at vger.kernel.org; linux-watchdog at vger.kernel.org; devicetree- discuss at lists.ozlabs.org; grant.likely at secretlab.ca; broonie at opensource.wolfsonmicro.com; rob.herring at calxeda.com; rob at landley.net; mturquette at linaro.org; linus.walleij at linaro.org; cooloney at gmail.com; sfr at canb.auug.org.au; rpurdie at rpsys.net; akpm at linux-foundation.org; sameo at linux.intel.com; wim at iguana.be; lgirdwood at gmail.com; ldewangan at nvidia.com; Kristo, Tero
Subject: Re: [PATCH v10 01/12] mfd: DT bindings for the palmas family MFD

Quoted 8 lines · keerthy
Quoted 5 lines · Stephen Warren
Quoted 4 lines · Ian Lartey

From: Graeme Gregory <[email protected]>

Add the various binding files for the palmas family of chips. There is a top level MFD binding then a seperate binding for IP blocks on

chips.

Quoted 7 lines
Quoted 7 lines

Documentation/devicetree/bindings/clock/palmas-clk.txt

Quoted 3 lines
Documentation/devicetree/bindings/clock/palmas-clk.txt +0 -0

Where is the reg property; if you're instantiating the clk device as a standalone DT node and driver, it should be possible to retrieve the address of this IP block instance from DT, not using driver-

internal APIs.

Quoted 14 lines
Quoted 14 lines

This same comment likely applies everywhere, so I won't repeat it.

Quoted 10 lines
Documentation/devicetree/bindings/clock/palmas-clk.txt +9 -0
+Example:
+
+clk {
+    compatible = "ti,twl6035-clk", "ti,palmas-clk";
+    ti,clk32kg-mode-sleep = <0>;
+    ti,clk32kgaudio-mode-sleep = <0>;
 
+    #clock-cells = <1>;
+    clock-frequency = <32000000>;
+    clock-names = "clk32kg", "clk32kgaudio";
Quoted 8 lines
Quoted 8 lines

The binding description itself should describe what clocks this node provides and consumes.

What is clock-frequency; which clock does it affect?

The presence of #clock-cells implies this is a clock provider. This binding should define the format of the clock cells that this property implies. I assume it's just the ID of the output clocks,

but

Quoted 12 lines
Quoted 12 lines

what values correspond to which output clocks? That mapping table needs to be listed here.

The presence of clock-names implies this is a clock consumer. However, there is no clocks property in the example. Is clks missing from the example, or should this property be clock-output-names instead? If this node is a clock consumer, the list of which clocks it requires should be documented.

Quoted 2 lines
Documentation/devicetree/bindings/gpio/gpio-palmas.txt +0 -0
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
+- gpio-controller: mark the device as a GPIO controller
+- gpio-cells = <1>:  GPIO lines are provided.

That's #gpio-cells not gpio-cells.

I assume that cell simply contains the GPIO ID/number. That should

be

Quoted 6 lines
Quoted 6 lines

documented for clarity.

Surely gpio-cells should be 2 not 1, so there is space for flags. At least an "inverted" or "active-low" flag should be included; GPIO consumers would typically implement that flag in SW, so there' no requirement that the flag only be supported if the HW supports the

feature.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
+- interrupt-controller : palmas has its own internal IRQs
+- #interrupt-cells : should be set to 2 for IRQ number and flags
Documentation/devicetree/bindings/gpio/gpio-palmas.txt +3 -0
+  The first cell is the IRQ number.
+  The second cell is the flags, encoded as the trigger masks from
+  Documentation/devicetree/bindings/interrupts.txt
Quoted 7 lines
Quoted 7 lines

You need "/interrupt-controller" before the filename there.

Quoted 1 line

+- interrupt-parent : The parent interrupt controller.

If this IP block has interrupt outputs, it should require an "interrupts" property too. This is the same concept that drives the need for a reg property. This same comment likely applies

everywhere,

Quoted 9 lines
Quoted 9 lines

so I won't repeat it.

Quoted 5 lines

diff --git a/Documentation/devicetree/bindings/input/palmas-pwrbutton.txt b/Documentation/devicetree/bindings/input/palmas-pwrbutton.txt

+- interrupts: the interrupt outputs of the controller.

How many entries are there, what do they mean, and in what order

must

Quoted 3 lines
Quoted 3 lines

they appear? (Note that the binding of a node must define the order of the interrupts property, since historically it's been accessed by index, not by name, and all bindings must allow that access method

to be used).

Quoted 28 lines
Quoted 13 lines

Documentation/devicetree/bindings/gpio/gpio-palmas.txt

Quoted 4 lines

+- interrupt-names : Should be the name of irq resource. Each

Documentation/devicetree/bindings/gpio/gpio-palmas.txt +2 -0
+interrupt
+  binds its interrupt-name.

The binding needs to define standard names for the entries in this property, or define that interrupts are only retrieved by index, in which case interrupt-names shouldn't be present. This same comment likely applies everywhere, so I won't repeat it.

Quoted 2 lines
Documentation/devicetree/bindings/mfd/palmas.txt +0 -0
Quoted 8 lines
Quoted 1 line

+Required properties:

...

I believe the Palmas devices have many separate I2C addresses, even buses, which are I think are at least partially independently SW configurable. In that case, the reg property for this node should probably enumerate all the I2C addresses that this chip responds to, so that they can each be passed down to the child nodes.

Stephen,

The palmas devices do have multiple I2C slave IDs. From OMAP5 as the master all the palmas slave devices are connected via I2C1 bus.

Quoted 8 lines
Quoted 2 lines

I did not understand the SW configurable part. It is more board dependent. Correct me if i understood it wrongly.

IIRC (and I may not sine it's been a while since I looked at this), there are SW registers that can modify the I2C address that the chip will respond to, so you could access the main I2C address, then program
which other I2C addresses get used.

Ok. I guess you are referring to the I2C_SPI register of Palmas. This register is indeed SW configurable and I tried changing the Slave IDs on the fly and I could change them. AFAIK these are OTP And never changed through software on the fly.

Quoted 6 lines

Or, perhaps I was just thinking of the fact that there are strapping pins on the chip that affect both the main I2C address, and some/all of
the other I2C addresses, so the driver needs to be told each and every I2C address, not just one single overall I2C address.

Quoted 5 lines

Looking at the register spec there seem to be 2 possible combinations:
0x48, 0x49, 0x4A or 0x58, 0x59, 0x5A. Again these are OTP. By default It is 0x48, 0x49, 0x4A. So passing 0x48 or 0x58 as the main I2C Address seems sufficient here.

The I2C addresses are set in OTP, I do not think they should ever be changed
on the fly.

Graeme

author
#8 lore raw

PATCH v10 2/12 mfd: palmas: is_palmas_charger needed by multiple drivers

In reply to Ian Lartey

is_palmas_charger checks for the presence of charging functionality in the device

---
 include/linux/mfd/palmas.h |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)
include/linux/mfd/palmas.h +11 -1
index 3bbda22..4a066d0 100644
@@ -1,9 +1,10 @@
 /*
  * TI Palmas
  *
- * Copyright 2011 Texas Instruments Inc.
+ * Copyright 2011-2013 Texas Instruments Inc.
  *
  * Author: Graeme Gregory <[email protected]>
+ * Author: Ian Lartey <[email protected]>
  *
  *  This program is free software; you can redistribute it and/or modify it
  *  under  the terms of the GNU General  Public License as published by the
@@ -22,6 +23,15 @@
 
 #define PALMAS_NUM_CLIENTS		3
 
+/* The ID_REVISION NUMBERS */
+#define PALMAS_CHIP_OLD_ID		0x0000
+#define PALMAS_CHIP_ID			0xC035
+#define PALMAS_CHIP_CHARGER_ID		0xC036
+
+#define is_palmas(a)	(((a) == PALMAS_CHIP_OLD_ID) || \
+			((a) == PALMAS_CHIP_ID))
+#define is_palmas_charger(a) ((a) == PALMAS_CHIP_CHARGER_ID)
+
 struct palmas_pmic;
 struct palmas_gpadc;
 struct palmas_resource;
Signature · 1 line
1.7.0.4
Applied
#9 lore raw

Re: [PATCH v10 02/12] mfd: palmas: is_palmas_charger needed by multiple drivers

Hi Ian,

Quoted 9 lines · Ian Lartey

is_palmas_charger checks for the presence of charging functionality in the device

---
 include/linux/mfd/palmas.h |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)

I applied this one now, thanks.

Cheers,
Samuel.

Signature · 2 lines
Intel Open Source Technology Centre
http://oss.intel.com/
author
#10 lore raw

PATCH v10 3/12 mfd: palmas add variant and OTP detection

In reply to Ian Lartey

From: Graeme Gregory <[email protected]>

Read the chip varient and the OTP information from the chip and display this on probe to aid in debugging of issues.

Older palmas chips do not have the USB_ID programmed and will therefore return 0x0000 for this field.

palmas register read/write/update API is now used

palmas_read_product_id_and_revs used by palmas_i2c_probe to get the device id, design and software revisions

id field of pamas struct renamed to device_id

Updated the DT parsing to agree with the bindings document, just some minor value name changes.

---
 drivers/mfd/palmas.c       |  102 ++++++++++++++++++++++++++++++++++----------
 include/linux/mfd/palmas.h |   35 +++++++++++++++-
 2 files changed, 113 insertions(+), 24 deletions(-)
drivers/mfd/palmas.c +79 -23
index 73bf76d..913416f 100644
@@ -1,9 +1,10 @@
 /*
  * TI Palmas MFD Driver
  *
- * Copyright 2011-2012 Texas Instruments Inc.
+ * Copyright 2011-2013 Texas Instruments Inc.
  *
  * Author: Graeme Gregory <[email protected]>
+ * Author: Ian Lartey <[email protected]>
  *
  *  This program is free software; you can redistribute it and/or modify it
  *  under  the terms of the GNU General  Public License as published by the
@@ -257,6 +258,56 @@ static struct regmap_irq_chip palmas_irq_chip = {
 			PALMAS_INT1_MASK),
 };
 
+static int palmas_read_product_id_and_revs(struct palmas *palmas)
+{
+	int ret;
+	unsigned int reg;
+
+	/* Read variant info from the device */
+	ret = palmas_read(palmas, PALMAS_ID_BASE, PALMAS_PRODUCT_ID_LSB, &reg);
+	if (ret < 0) {
+		dev_err(palmas->dev, "Unable to read ID err: %d\n", ret);
+		return ret;
+	}
+
+	palmas->product_id = reg;
+
+	ret = palmas_read(palmas, PALMAS_ID_BASE, PALMAS_PRODUCT_ID_MSB, &reg);
+	if (ret < 0) {
+		dev_err(palmas->dev, "Unable to read ID err: %d\n", ret);
+		return ret;
+	}
+
+	palmas->product_id |= reg << 8;
+
+	dev_info(palmas->dev, "Product ID %x\n", palmas->product_id);
+
+	ret = palmas_read(palmas, PALMAS_DESIGNREV_BASE,
+				PALMAS_DESIGNREV, &reg);
+	if (ret < 0) {
+		dev_err(palmas->dev, "Unable to read DESIGNREV err: %d\n", ret);
+		return ret;
+	}
+
+	palmas->designrev = reg & PALMAS_DESIGNREV_DESIGNREV_MASK;
+
+	dev_info(palmas->dev, "Product Design Rev %x\n", palmas->designrev);
+
+	ret = palmas_read(palmas, PALMAS_PMU_CONTROL_BASE, PALMAS_SW_REVISION,
+			&reg);
+	if (ret < 0) {
+		dev_err(palmas->dev, "Unable to read SW_REVISION err: %d\n",
+				ret);
+		return ret;
+	}
+
+	palmas->sw_revision = reg;
+
+	dev_info(palmas->dev, "Product SW Rev %x\n", palmas->sw_revision);
+
+	return 0;
+}
+
 static int palmas_set_pdata_irq_flag(struct i2c_client *i2c,
 		struct palmas_platform_data *pdata)
 {
@@ -278,20 +329,20 @@ static void palmas_dt_to_pdata(struct i2c_client *i2c,
 	int ret;
 	u32 prop;
 
-	ret = of_property_read_u32(node, "ti,mux_pad1", &prop);
+	ret = of_property_read_u32(node, "ti,mux-pad1", &prop);
 	if (!ret) {
 		pdata->mux_from_pdata = 1;
 		pdata->pad1 = prop;
 	}
 
-	ret = of_property_read_u32(node, "ti,mux_pad2", &prop);
+	ret = of_property_read_u32(node, "ti,mux-pad2", &prop);
 	if (!ret) {
 		pdata->mux_from_pdata = 1;
 		pdata->pad2 = prop;
 	}
 
 	/* The default for this register is all masked */
-	ret = of_property_read_u32(node, "ti,power_ctrl", &prop);
+	ret = of_property_read_u32(node, "ti,power-ctrl", &prop);
 	if (!ret)
 		pdata->power_ctrl = prop;
 	else
@@ -309,7 +360,7 @@ static int palmas_i2c_probe(struct i2c_client *i2c,
 	struct palmas_platform_data *pdata;
 	struct device_node *node = i2c->dev.of_node;
 	int ret = 0, i;
-	unsigned int reg, addr;
+	unsigned int reg;
 	int slave;
 	struct mfd_cell *children;
 
@@ -333,7 +384,7 @@ static int palmas_i2c_probe(struct i2c_client *i2c,
 
 	i2c_set_clientdata(i2c, palmas);
 	palmas->dev = &i2c->dev;
-	palmas->id = id->driver_data;
+	palmas->product_id = id->driver_data;
 	palmas->irq = i2c->irq;
 
 	for (i = 0; i < PALMAS_NUM_CLIENTS; i++) {
@@ -374,12 +425,16 @@ static int palmas_i2c_probe(struct i2c_client *i2c,
 		goto err;
 	}
 
+	/* Read variant info from the device */
+	ret = palmas_read_product_id_and_revs(palmas);
+	if (ret < 0)
+		goto err;
+
 	/* Change IRQ into clear on read mode for efficiency */
 	slave = PALMAS_BASE_TO_SLAVE(PALMAS_INTERRUPT_BASE);
-	addr = PALMAS_BASE_TO_REG(PALMAS_INTERRUPT_BASE, PALMAS_INT_CTRL);
 	reg = PALMAS_INT_CTRL_INT_CLEAR;
 
-	regmap_write(palmas->regmap[slave], addr, reg);
+	ret = palmas_write(palmas, PALMAS_INTERRUPT_BASE, PALMAS_INT_CTRL, reg);
 
 	ret = regmap_add_irq_chip(palmas->regmap[slave], palmas->irq,
 			IRQF_ONESHOT | pdata->irq_flags, 0, &palmas_irq_chip,
@@ -387,17 +442,15 @@ static int palmas_i2c_probe(struct i2c_client *i2c,
 	if (ret < 0)
 		goto err;
 
-	slave = PALMAS_BASE_TO_SLAVE(PALMAS_PU_PD_OD_BASE);
-	addr = PALMAS_BASE_TO_REG(PALMAS_PU_PD_OD_BASE,
-			PALMAS_PRIMARY_SECONDARY_PAD1);
-
 	if (pdata->mux_from_pdata) {
 		reg = pdata->pad1;
-		ret = regmap_write(palmas->regmap[slave], addr, reg);
+		ret = palmas_write(palmas, PALMAS_PU_PD_OD_BASE,
+				PALMAS_PRIMARY_SECONDARY_PAD1, reg);
 		if (ret)
 			goto err_irq;
 	} else {
-		ret = regmap_read(palmas->regmap[slave], addr, &reg);
+		ret = palmas_read(palmas, PALMAS_PU_PD_OD_BASE,
+				PALMAS_PRIMARY_SECONDARY_PAD1, &reg);
 		if (ret)
 			goto err_irq;
 	}
@@ -423,16 +476,15 @@ static int palmas_i2c_probe(struct i2c_client *i2c,
 	if (!(reg & PALMAS_PRIMARY_SECONDARY_PAD1_GPIO_3))
 		palmas->gpio_muxed |= PALMAS_GPIO_3_MUXED;
 
-	addr = PALMAS_BASE_TO_REG(PALMAS_PU_PD_OD_BASE,
-			PALMAS_PRIMARY_SECONDARY_PAD2);
-
 	if (pdata->mux_from_pdata) {
 		reg = pdata->pad2;
-		ret = regmap_write(palmas->regmap[slave], addr, reg);
+		ret = palmas_write(palmas, PALMAS_PU_PD_OD_BASE,
+				PALMAS_PRIMARY_SECONDARY_PAD2, reg);
 		if (ret)
 			goto err_irq;
 	} else {
-		ret = regmap_read(palmas->regmap[slave], addr, &reg);
+		ret = palmas_read(palmas, PALMAS_PU_PD_OD_BASE,
+				PALMAS_PRIMARY_SECONDARY_PAD2, &reg);
 		if (ret)
 			goto err_irq;
 	}
@@ -452,10 +504,8 @@ static int palmas_i2c_probe(struct i2c_client *i2c,
 
 	reg = pdata->power_ctrl;
 
-	slave = PALMAS_BASE_TO_SLAVE(PALMAS_PMU_CONTROL_BASE);
-	addr = PALMAS_BASE_TO_REG(PALMAS_PMU_CONTROL_BASE, PALMAS_POWER_CTRL);
-
-	ret = regmap_write(palmas->regmap[slave], addr, reg);
+	ret = palmas_write(palmas, PALMAS_PU_PD_OD_BASE,
+			PALMAS_PRIMARY_SECONDARY_PAD2, reg);
 	if (ret)
 		goto err_irq;
 
@@ -534,6 +584,12 @@ MODULE_DEVICE_TABLE(i2c, palmas_i2c_id);
 
 static struct of_device_id of_palmas_match_tbl[] = {
 	{ .compatible = "ti,palmas", },
+	{ .compatible = "ti,twl6035", },
+	{ .compatible = "ti,twl6036", },
+	{ .compatible = "ti,twl6037", },
+	{ .compatible = "ti,tps65913", },
+	{ .compatible = "ti,tps65914", },
+	{ .compatible = "ti,tps80036", },
 	{ /* end */ }
 };
 
include/linux/mfd/palmas.h +34 -1
index 4a066d0..4cffe31 100644
@@ -44,7 +44,9 @@ struct palmas {
 	struct regmap *regmap[PALMAS_NUM_CLIENTS];
 
 	/* Stored chip id */
-	int id;
+	int product_id;
+	int designrev;
+	int sw_revision;
 
 	/* IRQ Data */
 	int irq;
@@ -438,11 +440,13 @@ enum usb_irq_events {
 #define PALMAS_PU_PD_OD_BASE					0x1F4
 #define PALMAS_LED_BASE						0x200
 #define PALMAS_INTERRUPT_BASE					0x210
+#define PALMAS_ID_BASE						0x24F
 #define PALMAS_USB_OTG_BASE					0x250
 #define PALMAS_VIBRATOR_BASE					0x270
 #define PALMAS_GPIO_BASE					0x280
 #define PALMAS_USB_BASE						0x290
 #define PALMAS_GPADC_BASE					0x2C0
+#define PALMAS_DESIGNREV_BASE					0x357
 #define PALMAS_TRIM_GPADC_BASE					0x3CD
 
 /* Registers for function RTC */
@@ -2160,6 +2164,28 @@ enum usb_irq_events {
 #define PALMAS_INT_CTRL_INT_CLEAR				0x01
 #define PALMAS_INT_CTRL_INT_CLEAR_SHIFT				0
 
+/* Registers for function ID */
+#define PALMAS_VENDOR_ID_LSB					0x0
+#define PALMAS_VENDOR_ID_MSB					0x1
+#define PALMAS_PRODUCT_ID_LSB					0x2
+#define PALMAS_PRODUCT_ID_MSB					0x3
+
+/* Bit definitions for VENDOR_ID_LSB */
+#define PALMAS_VENDOR_ID_LSB_VENDOR_ID_MASK			0xff
+#define PALMAS_VENDOR_ID_LSB_VENDOR_ID_SHIFT			0
+
+/* Bit definitions for VENDOR_ID_MSB */
+#define PALMAS_VENDOR_ID_MSB_VENDOR_ID_MASK			0xff
+#define PALMAS_VENDOR_ID_MSB_VENDOR_ID_SHIFT			0
+
+/* Bit definitions for PRODUCT_ID_LSB */
+#define PALMAS_PRODUCT_ID_LSB_PRODUCT_ID_MASK			0xff
+#define PALMAS_PRODUCT_ID_LSB_PRODUCT_ID_SHIFT			0
+
+/* Bit definitions for PRODUCT_ID_MSB */
+#define PALMAS_PRODUCT_ID_MSB_PRODUCT_ID_MASK			0xff
+#define PALMAS_PRODUCT_ID_MSB_PRODUCT_ID_SHIFT			0
+
 /* Registers for function USB_OTG */
 #define PALMAS_USB_WAKEUP					0x3
 #define PALMAS_USB_VBUS_CTRL_SET				0x4
@@ -2782,6 +2808,13 @@ enum usb_irq_events {
 #define PALMAS_GPADC_SMPS_VSEL_MONITORING_SMPS_VSEL_MONITORING_MASK	0x7f
 #define PALMAS_GPADC_SMPS_VSEL_MONITORING_SMPS_VSEL_MONITORING_SHIFT	0
 
+/* Registers for function DESIGNREV */
+#define PALMAS_DESIGNREV					0x0
+
+/* Bit definitions for DESIGNREV */
+#define PALMAS_DESIGNREV_DESIGNREV_MASK				0x0f
+#define PALMAS_DESIGNREV_DESIGNREV_SHIFT			0
+
 /* Registers for function GPADC */
 #define PALMAS_GPADC_TRIM1					0x0
 #define PALMAS_GPADC_TRIM2					0x1
Signature · 1 line
1.7.0.4
#11 lore raw

Re: [PATCH v10 03/12] mfd: palmas add variant and OTP detection

Hi Ian,

Quoted 25 lines · Ian Lartey
drivers/mfd/palmas.c +3 -3
@@ -278,20 +329,20 @@ static void palmas_dt_to_pdata(struct i2c_client *i2c,
 	int ret;
 	u32 prop;
 
-	ret = of_property_read_u32(node, "ti,mux_pad1", &prop);
+	ret = of_property_read_u32(node, "ti,mux-pad1", &prop);
 	if (!ret) {
 		pdata->mux_from_pdata = 1;
 		pdata->pad1 = prop;
 	}
 
-	ret = of_property_read_u32(node, "ti,mux_pad2", &prop);
+	ret = of_property_read_u32(node, "ti,mux-pad2", &prop);
 	if (!ret) {
 		pdata->mux_from_pdata = 1;
 		pdata->pad2 = prop;
 	}
 
 	/* The default for this register is all masked */
-	ret = of_property_read_u32(node, "ti,power_ctrl", &prop);
+	ret = of_property_read_u32(node, "ti,power-ctrl", &prop);
 	if (!ret)
 		pdata->power_ctrl = prop;
 	else

drivers/mfd/palmas.c static int palmas_i2c_probe(struct i2c_client *i2c, · line 365

Quoted 7 lines
drivers/mfd/palmas.c +1 -1
@@ -309,7 +360,7 @@ static int palmas_i2c_probe(struct i2c_client *i2c,
 	struct palmas_platform_data *pdata;
 	struct device_node *node = i2c->dev.of_node;
 	int ret = 0, i;
-	unsigned int reg, addr;
+	unsigned int reg;
 	int slave;
 	struct mfd_cell *children;

The '-' to '_' fix has been sent by J Keerthy and is on my mfd-next tree aready. Would you mind removing it from this patch ?

Cheers,
Samuel.

Signature · 2 lines
Intel Open Source Technology Centre
http://oss.intel.com/
author
#12 lore raw

PATCH v10 4/12 watchdog: add Palmas Watchdog support

In reply to Ian Lartey

From: Graeme Gregory <[email protected]>

Add support for the Palmas watchdog timer which has a timeout configurable from 1s to 128s.

---
 drivers/watchdog/palmas_wdt.c |  169 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 169 insertions(+), 0 deletions(-)
 create mode 100644 drivers/watchdog/palmas_wdt.c
drivers/watchdog/palmas_wdt.c new file +169 -0
new file mode 100644
index 0000000..da7e379
@@ -0,0 +1,169 @@
+/*
+ * Driver for Watchdog part of Palmas PMIC Chips
+ *
+ * Copyright 2011-2013 Texas Instruments Inc.
+ *
+ * Author: Graeme Gregory <[email protected]>
+ * Author: Ian Lartey <[email protected]>
+ *
+ * Based on twl4030_wdt.c
+ *
+ * Author: Timo Kokkonen <[email protected]>
+ *
+ *  This program is free software; you can redistribute it and/or modify it
+ *  under  the terms of the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the License, or (at your
+ *  option) any later version.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/slab.h>
+#include <linux/kernel.h>
+#include <linux/fs.h>
+#include <linux/watchdog.h>
+#include <linux/platform_device.h>
+#include <linux/watchdog.h>
+#include <linux/mfd/palmas.h>
+
+struct palmas_wdt {
+	struct palmas *palmas;
+	struct watchdog_device wdt;
+	struct device *dev;
+
+	int timer_margin;
+};
+
+
+static int nowayout = WATCHDOG_NOWAYOUT;
+module_param(nowayout, int, 0);
+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started "
+	"(default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
+
+static int palmas_wdt_write(struct palmas *palmas, unsigned int data)
+{
+	unsigned int addr;
+
+	addr = PALMAS_BASE_TO_REG(PALMAS_PMU_CONTROL_BASE, PALMAS_WATCHDOG);
+
+	return palmas_write(palmas, PALMAS_PMU_CONTROL_BASE, addr, addr);
+}
+
+static int palmas_wdt_enable(struct watchdog_device *wdt)
+{
+	struct palmas_wdt *driver_data = watchdog_get_drvdata(wdt);
+	struct palmas *palmas = driver_data->palmas;
+
+	return palmas_wdt_write(palmas, driver_data->timer_margin |
+				PALMAS_WATCHDOG_ENABLE);
+}
+
+static int palmas_wdt_disable(struct watchdog_device *wdt)
+{
+	struct palmas_wdt *driver_data = watchdog_get_drvdata(wdt);
+	struct palmas *palmas = driver_data->palmas;
+
+	return palmas_wdt_write(palmas, driver_data->timer_margin);
+}
+
+static int palmas_wdt_set_timeout(struct watchdog_device *wdt, unsigned timeout)
+{
+	struct palmas_wdt *driver_data = watchdog_get_drvdata(wdt);
+
+	if (timeout < 1 || timeout > 128) {
+		dev_warn(driver_data->dev,
+			"Timeout can only be in the range [1-128] seconds");
+		return -EINVAL;
+	}
+	driver_data->timer_margin = fls(timeout) - 1;
+	return 0;
+}
+
+static const struct watchdog_info palmas_wdt_info = {
+	.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
+	.identity = "Palmas Watchdog",
+	.firmware_version = 0,
+};
+
+static const struct watchdog_ops palmas_wdt_ops = {
+	.owner = THIS_MODULE,
+	.start = palmas_wdt_enable,
+	.stop = palmas_wdt_disable,
+	.ping = palmas_wdt_enable,
+	.set_timeout = palmas_wdt_set_timeout,
+};
+
+static int palmas_wdt_probe(struct platform_device *pdev)
+{
+	struct palmas *palmas = dev_get_drvdata(pdev->dev.parent);
+	struct palmas_wdt *driver_data;
+	struct watchdog_device *palmas_wdt;
+	int ret = 0;
+
+	driver_data = devm_kzalloc(&pdev->dev, sizeof(*driver_data),
+				   GFP_KERNEL);
+	if (!driver_data) {
+		dev_err(&pdev->dev, "Unable to alloacate watchdog device\n");
+		ret = -ENOMEM;
+		goto err;
+	}
+
+	driver_data->palmas = palmas;
+
+	palmas_wdt = &driver_data->wdt;
+
+	palmas_wdt->info = &palmas_wdt_info;
+	palmas_wdt->ops = &palmas_wdt_ops;
+	watchdog_set_nowayout(palmas_wdt, nowayout);
+	watchdog_set_drvdata(palmas_wdt, driver_data);
+
+	ret = watchdog_register_device(&driver_data->wdt);
+	if (ret) {
+		platform_set_drvdata(pdev, NULL);
+		goto err;
+	}
+
+	dev_set_drvdata(&pdev->dev, driver_data);
+
+	return 0;
+err:
+	return ret;
+}
+
+static int palmas_wdt_remove(struct platform_device *pdev)
+{
+	struct palmas_wdt *driver_data = dev_get_drvdata(&pdev->dev);
+
+	watchdog_unregister_device(&driver_data->wdt);
+
+	return 0;
+}
+
+static struct of_device_id of_palmas_match_tbl[] = {
+	{ .compatible = "ti,palmas-wdt", },
+	{ .compatible = "ti,twl6035-wdt", },
+	{ .compatible = "ti,twl6036-wdt", },
+	{ .compatible = "ti,twl6037-wdt", },
+	{ .compatible = "ti,tps65913-wdt", },
+	{ .compatible = "ti,tps65914-wdt", },
+	{ .compatible = "ti,tps80036-wdt", },
+	{ /* end */ }
+};
+
+static struct platform_driver palmas_wdt_driver = {
+	.probe = palmas_wdt_probe,
+	.remove = palmas_wdt_remove,
+	.driver = {
+		.owner = THIS_MODULE,
+		.of_match_table = of_palmas_match_tbl,
+		.name = "palmas-wdt",
+	},
+};
+
+module_platform_driver(palmas_wdt_driver);
+
+MODULE_AUTHOR("Graeme Gregory <[email protected]>");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:palmas-wdt");
+MODULE_DEVICE_TABLE(of, of_palmas_match_tbl);
Signature · 1 line
1.7.0.4
maintainer
#13 lore raw

Re: [PATCH v10 04/12] watchdog: add Palmas Watchdog support

Quoted 46 lines · Ian Lartey

From: Graeme Gregory <[email protected]>

Add support for the Palmas watchdog timer which has a timeout configurable from 1s to 128s.

---
 drivers/watchdog/palmas_wdt.c |  169 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 169 insertions(+), 0 deletions(-)
 create mode 100644 drivers/watchdog/palmas_wdt.c
drivers/watchdog/palmas_wdt.c new file +28 -0
new file mode 100644
index 0000000..da7e379
@@ -0,0 +1,169 @@
+/*
+ * Driver for Watchdog part of Palmas PMIC Chips
+ *
+ * Copyright 2011-2013 Texas Instruments Inc.
+ *
+ * Author: Graeme Gregory <[email protected]>
+ * Author: Ian Lartey <[email protected]>
+ *
+ * Based on twl4030_wdt.c
+ *
+ * Author: Timo Kokkonen <timo.t.kokkonen at nokia.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify it
+ *  under  the terms of the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the License, or (at your
+ *  option) any later version.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/slab.h>
+#include <linux/kernel.h>
+#include <linux/fs.h>
+#include <linux/watchdog.h>
+#include <linux/platform_device.h>
+#include <linux/watchdog.h>
+#include <linux/mfd/palmas.h>

drivers/watchdog/palmas_wdt.c line 38

Quoted 10 lines
drivers/watchdog/palmas_wdt.c new file +10 -0
+
+struct palmas_wdt {
+	struct palmas *palmas;
+	struct watchdog_device wdt;
+	struct device *dev;
+
+	int timer_margin;
+};
+
+

One empty line would be sufficient.

drivers/watchdog/palmas_wdt.c line 50

Quoted 12 lines
drivers/watchdog/palmas_wdt.c new file +12 -0
+static int nowayout = WATCHDOG_NOWAYOUT;
+module_param(nowayout, int, 0);
+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started "
+	"(default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
+
+static int palmas_wdt_write(struct palmas *palmas, unsigned int data)
+{
+	unsigned int addr;
+
+	addr = PALMAS_BASE_TO_REG(PALMAS_PMU_CONTROL_BASE, PALMAS_WATCHDOG);
+
+	return palmas_write(palmas, PALMAS_PMU_CONTROL_BASE, addr, addr);

2 x addr ? Should the second one (last parameter) be data ?

Quoted 7 lines
drivers/watchdog/palmas_wdt.c new file +7 -0
+}
+
+static int palmas_wdt_enable(struct watchdog_device *wdt)
+{
+	struct palmas_wdt *driver_data = watchdog_get_drvdata(wdt);
+	struct palmas *palmas = driver_data->palmas;
+

drivers/watchdog/palmas_wdt.c line 67

Quoted 10 lines
drivers/watchdog/palmas_wdt.c new file +10 -0
+	return palmas_wdt_write(palmas, driver_data->timer_margin |
+				PALMAS_WATCHDOG_ENABLE);
+}
+
+static int palmas_wdt_disable(struct watchdog_device *wdt)
+{
+	struct palmas_wdt *driver_data = watchdog_get_drvdata(wdt);
+	struct palmas *palmas = driver_data->palmas;
+
+	return palmas_wdt_write(palmas, driver_data->timer_margin);

Just wondering - why not just write 0 ?

drivers/watchdog/palmas_wdt.c line 78

Quoted 11 lines
drivers/watchdog/palmas_wdt.c new file +11 -0
+}
+
+static int palmas_wdt_set_timeout(struct watchdog_device *wdt, unsigned timeout)
+{
+	struct palmas_wdt *driver_data = watchdog_get_drvdata(wdt);
+
+	if (timeout < 1 || timeout > 128) {
+		dev_warn(driver_data->dev,
+			"Timeout can only be in the range [1-128] seconds");
+		return -EINVAL;
+	}

The watchdog core supports limit checking. Might as well use it.

On a side note, it might be an interesting experience if you try setting a value of 0 or larger than 128. Unless I am missing something, driver_data->dev is never initialized.

Quoted 19 lines
drivers/watchdog/palmas_wdt.c new file +19 -0
+	driver_data->timer_margin = fls(timeout) - 1;
+	return 0;
+}
+
+static const struct watchdog_info palmas_wdt_info = {
+	.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
+	.identity = "Palmas Watchdog",
+	.firmware_version = 0,
+};
+
+static const struct watchdog_ops palmas_wdt_ops = {
+	.owner = THIS_MODULE,
+	.start = palmas_wdt_enable,
+	.stop = palmas_wdt_disable,
+	.ping = palmas_wdt_enable,
+	.set_timeout = palmas_wdt_set_timeout,
+};
+
+static int palmas_wdt_probe(struct platform_device *pdev)

drivers/watchdog/palmas_wdt.c line 107

Quoted 10 lines
drivers/watchdog/palmas_wdt.c new file +10 -0
+{
+	struct palmas *palmas = dev_get_drvdata(pdev->dev.parent);
+	struct palmas_wdt *driver_data;
+	struct watchdog_device *palmas_wdt;
+	int ret = 0;
+
+	driver_data = devm_kzalloc(&pdev->dev, sizeof(*driver_data),
+				   GFP_KERNEL);
+	if (!driver_data) {
+		dev_err(&pdev->dev, "Unable to alloacate watchdog device\n");

AFAIK devm_ functions already issue a message on errors, so it is unnecessary to issue another one here.

drivers/watchdog/palmas_wdt.c line 120

Quoted 13 lines
drivers/watchdog/palmas_wdt.c new file +13 -0
+		ret = -ENOMEM;
+		goto err;
+	}
+
+	driver_data->palmas = palmas;
+
+	palmas_wdt = &driver_data->wdt;
+
+	palmas_wdt->info = &palmas_wdt_info;
+	palmas_wdt->ops = &palmas_wdt_ops;
+	watchdog_set_nowayout(palmas_wdt, nowayout);
+	watchdog_set_drvdata(palmas_wdt, driver_data);
+

There is no call to watchdog_init_timeout, and the timeout value is not initialized in palmas_wdt. So the driver depends on the limit being set from user space with WDIOC_SETTIMEOUT. But that can not happen until after it was opened and started, meaning it is initially 0 when the watchdog is started. Is that on purpose ? A more common default would be 60 seconds.

Also, if user space does not explicitly set the timeout but requests it with WDIOC_GETTIMEOUT, it will get a value of 0.

drivers/watchdog/palmas_wdt.c line 123

Quoted 3 lines
drivers/watchdog/palmas_wdt.c new file +3 -0
+	ret = watchdog_register_device(&driver_data->wdt);
+	if (ret) {
+		platform_set_drvdata(pdev, NULL);

It is unnecessary to set the platform data to NULL. Besides, it isn't even set yet (you only set it with dev_set_drvdata below).

drivers/watchdog/palmas_wdt.c line 127

Quoted 4 lines
drivers/watchdog/palmas_wdt.c new file +4 -0
+		goto err;
+	}
+
+	dev_set_drvdata(&pdev->dev, driver_data);

Might use platform_set_drvdata.

drivers/watchdog/palmas_wdt.c line 131

Quoted 4 lines
drivers/watchdog/palmas_wdt.c new file +4 -0
+
+	return 0;
+err:
+	return ret;

Personal style, but I think this is unnecessary. Coding style examples suggest to return directly in such cases (ie if there is no cleanup to do).

drivers/watchdog/palmas_wdt.c line 137

Quoted 6 lines
drivers/watchdog/palmas_wdt.c new file +6 -0
+}
+
+static int palmas_wdt_remove(struct platform_device *pdev)
+{
+	struct palmas_wdt *driver_data = dev_get_drvdata(&pdev->dev);
+

platform_get_drvdata ?

Quoted 43 lines
drivers/watchdog/palmas_wdt.c new file +32 -0
+	watchdog_unregister_device(&driver_data->wdt);
+
+	return 0;
+}
+
+static struct of_device_id of_palmas_match_tbl[] = {
+	{ .compatible = "ti,palmas-wdt", },
+	{ .compatible = "ti,twl6035-wdt", },
+	{ .compatible = "ti,twl6036-wdt", },
+	{ .compatible = "ti,twl6037-wdt", },
+	{ .compatible = "ti,tps65913-wdt", },
+	{ .compatible = "ti,tps65914-wdt", },
+	{ .compatible = "ti,tps80036-wdt", },
+	{ /* end */ }
+};
+
+static struct platform_driver palmas_wdt_driver = {
+	.probe = palmas_wdt_probe,
+	.remove = palmas_wdt_remove,
+	.driver = {
+		.owner = THIS_MODULE,
+		.of_match_table = of_palmas_match_tbl,
+		.name = "palmas-wdt",
+	},
+};
+
+module_platform_driver(palmas_wdt_driver);
+
+MODULE_AUTHOR("Graeme Gregory <[email protected]>");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:palmas-wdt");
+MODULE_DEVICE_TABLE(of, of_palmas_match_tbl);
Signature · 7 lines
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
#14 lore raw

Re: [PATCH v10 04/12] watchdog: add Palmas Watchdog support

In reply to Ian Lartey

Hi Ian,

drivers/watchdog/palmas_wdt.c line 81

Quoted 12 lines
drivers/watchdog/palmas_wdt.c new file +12 -0
+static int palmas_wdt_set_timeout(struct watchdog_device *wdt, unsigned timeout)
+{
+	struct palmas_wdt *driver_data = watchdog_get_drvdata(wdt);
+
+	if (timeout < 1 || timeout > 128) {
+		dev_warn(driver_data->dev,
+			"Timeout can only be in the range [1-128] seconds");
+		return -EINVAL;
+	}
+	driver_data->timer_margin = fls(timeout) - 1;
+	return 0;
+}

The core can test this also with the .min_timeout and .max_timeout fields of the watchdog_device.

drivers/watchdog/palmas_wdt.c line 93

Quoted 12 lines
drivers/watchdog/palmas_wdt.c new file +12 -0
+
+static const struct watchdog_info palmas_wdt_info = {
+	.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
+	.identity = "Palmas Watchdog",
+	.firmware_version = 0,
+};
+
+static const struct watchdog_ops palmas_wdt_ops = {
+	.owner = THIS_MODULE,
+	.start = palmas_wdt_enable,
+	.stop = palmas_wdt_disable,
+	.ping = palmas_wdt_enable,

Since .ping is the same as .start you don't need to add .ping .

Quoted 16 lines
drivers/watchdog/palmas_wdt.c new file +16 -0
+	.set_timeout = palmas_wdt_set_timeout,
+};
+
+static int palmas_wdt_probe(struct platform_device *pdev)
+{
+	struct palmas *palmas = dev_get_drvdata(pdev->dev.parent);
+	struct palmas_wdt *driver_data;
+	struct watchdog_device *palmas_wdt;
+	int ret = 0;
+
+	driver_data = devm_kzalloc(&pdev->dev, sizeof(*driver_data),
+				   GFP_KERNEL);
+	if (!driver_data) {
+		dev_err(&pdev->dev, "Unable to alloacate watchdog device\n");
+		ret = -ENOMEM;
+		goto err;

drivers/watchdog/palmas_wdt.c line 119

Quoted 10 lines
drivers/watchdog/palmas_wdt.c new file +10 -0
+	}
+
+	driver_data->palmas = palmas;
+
+	palmas_wdt = &driver_data->wdt;
+
+	palmas_wdt->info = &palmas_wdt_info;
+	palmas_wdt->ops = &palmas_wdt_ops;
+	watchdog_set_nowayout(palmas_wdt, nowayout);
+	watchdog_set_drvdata(palmas_wdt, driver_data);

I think you want a watchdog_init_timeout(struct watchdog_device *wdd, unsigned int timeout_parm, struct device *dev); here. And also make sure that the watchdog isn't running.

Quoted 53 lines
drivers/watchdog/palmas_wdt.c new file +50 -0
+
+	ret = watchdog_register_device(&driver_data->wdt);
+	if (ret) {
+		platform_set_drvdata(pdev, NULL);
+		goto err;
+	}
+
+	dev_set_drvdata(&pdev->dev, driver_data);
+
+	return 0;
+err:
+	return ret;
+}
+
+static int palmas_wdt_remove(struct platform_device *pdev)
+{
+	struct palmas_wdt *driver_data = dev_get_drvdata(&pdev->dev);
+
+	watchdog_unregister_device(&driver_data->wdt);
+
+	return 0;
+}
+
+static struct of_device_id of_palmas_match_tbl[] = {
+	{ .compatible = "ti,palmas-wdt", },
+	{ .compatible = "ti,twl6035-wdt", },
+	{ .compatible = "ti,twl6036-wdt", },
+	{ .compatible = "ti,twl6037-wdt", },
+	{ .compatible = "ti,tps65913-wdt", },
+	{ .compatible = "ti,tps65914-wdt", },
+	{ .compatible = "ti,tps80036-wdt", },
+	{ /* end */ }
+};
+
+static struct platform_driver palmas_wdt_driver = {
+	.probe = palmas_wdt_probe,
+	.remove = palmas_wdt_remove,
+	.driver = {
+		.owner = THIS_MODULE,
+		.of_match_table = of_palmas_match_tbl,
+		.name = "palmas-wdt",
+	},
+};
+
+module_platform_driver(palmas_wdt_driver);
+
+MODULE_AUTHOR("Graeme Gregory <[email protected]>");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:palmas-wdt");
+MODULE_DEVICE_TABLE(of, of_palmas_match_tbl);
Signature · 1 line
1.7.0.4

If you can add the devicetree bindings Documentation and the Kconfig patch together with the revised version of this patch into a single patch then we can complete the review.

Kind regards,
Wim.

author
#15 lore raw

PATCH v10 5/12 watchdog: Kconfig for Palmas watchdog

In reply to Ian Lartey

Add the Kconfig and Makefile for the Palmas watchdog driver

---
 drivers/watchdog/Kconfig  |    8 ++++++++
 drivers/watchdog/Makefile |    1 +
 2 files changed, 9 insertions(+), 0 deletions(-)
drivers/watchdog/Kconfig +8 -0
index 9fcc70c..d48cb0e 100644
@@ -103,6 +103,14 @@ config WM8350_WATCHDOG
 	  Support for the watchdog in the WM8350 AudioPlus PMIC.  When
 	  the watchdog triggers the system will be reset.
 
+config PALMAS_WATCHDOG
+	tristate "Palmas Watchdog"
+	depends on MFD_PALMAS
+	select WATCHDOG_CORE
+	help
+	  Support for the watchdog in the Palmas family of PMICs. When the
+	  watchdog times out system will be reset.
+
 # ALPHA Architecture
 
 # ARM Architecture
drivers/watchdog/Makefile +1 -0
index a300b94..e845c21 100644
@@ -171,3 +171,4 @@ obj-$(CONFIG_WM831X_WATCHDOG) += wm831x_wdt.o
 obj-$(CONFIG_WM8350_WATCHDOG) += wm8350_wdt.o
 obj-$(CONFIG_MAX63XX_WATCHDOG) += max63xx_wdt.o
 obj-$(CONFIG_SOFT_WATCHDOG) += softdog.o
+obj-$(CONFIG_PALMAS_WATCHDOG) += palmas_wdt.o
Signature · 1 line
1.7.0.4
author
#17 lore raw

PATCH v10 6/12 gpio: palmas: add in GPIO support for palmas charger

In reply to Ian Lartey

Palmas charger has 16 GPIOs
add palmas_gpio_[read|write|update] api to take account second bank of GPIOs

---
 drivers/gpio/gpio-palmas.c |   77 ++++++++++++++++++++++++++++++++++++--------
 include/linux/mfd/palmas.h |   12 ++++++-
 2 files changed, 74 insertions(+), 15 deletions(-)
drivers/gpio/gpio-palmas.c +63 -14
index e3a4e56..636648c 100644
@@ -1,7 +1,7 @@
 /*
- * TI Palma series PMIC's GPIO driver.
+ * TI Palmas series PMIC's GPIO driver.
  *
- * Copyright (c) 2012, NVIDIA CORPORATION.  All rights reserved.
+ * Copyright (c) 2012-2012, NVIDIA CORPORATION.  All rights reserved.
  *
  * Author: Laxman Dewangan <[email protected]>
  *
@@ -31,6 +31,36 @@ struct palmas_gpio {
 	struct palmas *palmas;
 };
 
+static int palmas_gpio_read(struct palmas *palmas, unsigned int reg,
+		int gpio, unsigned int *dest)
+{
+	/* registers for second bank are identical and offset by 0x9 */
+	if (gpio > 7)
+		reg += PALMAS_GPIO_DATA_IN2;
+
+	return palmas_read(palmas, PALMAS_GPIO_BASE, reg, dest);
+}
+
+static int palmas_gpio_write(struct palmas *palmas, unsigned int reg,
+		int gpio, unsigned int data)
+{
+	/* registers for second bank are identical and offset by 0x9 */
+	if (gpio > 7)
+		reg += PALMAS_GPIO_DATA_IN2;
+
+	return palmas_write(palmas, PALMAS_GPIO_BASE, reg, data);
+}
+
+static int palmas_gpio_update_bits(struct palmas *palmas, unsigned int reg,
+		int gpio, unsigned int mask, unsigned int data)
+{
+	/* registers for second bank are identical and offset by 0x9 */
+	if (gpio > 7)
+		reg += PALMAS_GPIO_DATA_IN2;
+
+	return palmas_update_bits(palmas, PALMAS_GPIO_BASE, reg, mask, data);
+}
+
 static inline struct palmas_gpio *to_palmas_gpio(struct gpio_chip *chip)
 {
 	return container_of(chip, struct palmas_gpio, gpio_chip);
@@ -43,12 +73,12 @@ static int palmas_gpio_get(struct gpio_chip *gc, unsigned offset)
 	unsigned int val;
 	int ret;
 
-	ret = palmas_read(palmas, PALMAS_GPIO_BASE, PALMAS_GPIO_DATA_IN, &val);
+	ret = palmas_gpio_read(palmas, PALMAS_GPIO_DATA_IN, offset, &val);
 	if (ret < 0) {
 		dev_err(gc->dev, "GPIO_DATA_IN read failed, err = %d\n", ret);
 		return ret;
 	}
-	return !!(val & BIT(offset));
+	return !!(val & BIT(offset % 8));
 }
 
 static void palmas_gpio_set(struct gpio_chip *gc, unsigned offset,
@@ -59,11 +89,11 @@ static void palmas_gpio_set(struct gpio_chip *gc, unsigned offset,
 	int ret;
 
 	if (value)
-		ret = palmas_write(palmas, PALMAS_GPIO_BASE,
-				PALMAS_GPIO_SET_DATA_OUT, BIT(offset));
+		ret = palmas_gpio_write(palmas, PALMAS_GPIO_SET_DATA_OUT,
+				offset, BIT(offset % 8));
 	else
-		ret = palmas_write(palmas, PALMAS_GPIO_BASE,
-				PALMAS_GPIO_CLEAR_DATA_OUT, BIT(offset));
+		ret = palmas_gpio_write(palmas, PALMAS_GPIO_CLEAR_DATA_OUT,
+				offset, BIT(offset % 8));
 	if (ret < 0)
 		dev_err(gc->dev, "%s write failed, err = %d\n",
 			(value) ? "GPIO_SET_DATA_OUT" : "GPIO_CLEAR_DATA_OUT",
@@ -80,8 +110,8 @@ static int palmas_gpio_output(struct gpio_chip *gc, unsigned offset,
 	/* Set the initial value */
 	palmas_gpio_set(gc, offset, value);
 
-	ret = palmas_update_bits(palmas, PALMAS_GPIO_BASE,
-		PALMAS_GPIO_DATA_DIR, BIT(offset), BIT(offset));
+	ret = palmas_gpio_update_bits(palmas, PALMAS_GPIO_DATA_DIR,
+			offset, 1 << (offset % 8), 1 << (offset % 8));
 	if (ret < 0)
 		dev_err(gc->dev, "GPIO_DATA_DIR write failed, err = %d\n", ret);
 	return ret;
@@ -93,8 +123,8 @@ static int palmas_gpio_input(struct gpio_chip *gc, unsigned offset)
 	struct palmas *palmas = pg->palmas;
 	int ret;
 
-	ret = palmas_update_bits(palmas, PALMAS_GPIO_BASE,
-		PALMAS_GPIO_DATA_DIR, BIT(offset), 0);
+	ret =  palmas_gpio_update_bits(palmas, PALMAS_GPIO_DATA_DIR,
+				offset, 1 << (offset % 8), 0);
 	if (ret < 0)
 		dev_err(gc->dev, "GPIO_DATA_DIR write failed, err = %d\n", ret);
 	return ret;
@@ -108,7 +138,21 @@ static int palmas_gpio_to_irq(struct gpio_chip *gc, unsigned offset)
 	return palmas_irq_get_virq(palmas, PALMAS_GPIO_0_IRQ + offset);
 }
 
-static int palmas_gpio_probe(struct platform_device *pdev)
+static int palmas_gpio_set_debounce(struct gpio_chip *gc, unsigned offset,
+				    unsigned debounce)
+{
+	struct palmas_gpio *palmas_gpio = to_palmas_gpio(gc);
+	struct palmas *palmas = palmas_gpio->palmas;
+	unsigned int data = 0;
+
+	if (debounce)
+		data = 0xff;
+
+	return palmas_gpio_update_bits(palmas, PALMAS_GPIO_DEBOUNCE_EN,
+			offset, 1 << (offset % 8), data);
+}
+
+static int  palmas_gpio_probe(struct platform_device *pdev)
 {
 	struct palmas *palmas = dev_get_drvdata(pdev->dev.parent);
 	struct palmas_platform_data *palmas_pdata;
@@ -125,10 +169,15 @@ static int palmas_gpio_probe(struct platform_device *pdev)
 	palmas_gpio->palmas = palmas;
 	palmas_gpio->gpio_chip.owner = THIS_MODULE;
 	palmas_gpio->gpio_chip.label = dev_name(&pdev->dev);
-	palmas_gpio->gpio_chip.ngpio = 8;
+	/* palmas charger has 16 gpios */
+	if (is_palmas_charger(palmas->product_id))
+		palmas_gpio->gpio_chip.ngpio = 16;
+	else
+		palmas_gpio->gpio_chip.ngpio = 8;
 	palmas_gpio->gpio_chip.can_sleep = 1;
 	palmas_gpio->gpio_chip.direction_input = palmas_gpio_input;
 	palmas_gpio->gpio_chip.direction_output = palmas_gpio_output;
+	palmas_gpio->gpio_chip.set_debounce = palmas_gpio_set_debounce,
 	palmas_gpio->gpio_chip.to_irq = palmas_gpio_to_irq;
 	palmas_gpio->gpio_chip.set	= palmas_gpio_set;
 	palmas_gpio->gpio_chip.get	= palmas_gpio_get;
include/linux/mfd/palmas.h +11 -1
index 4cffe31..d8c303b 100644
@@ -244,7 +244,7 @@ struct palmas_platform_data {
 	 * then the two value to load into the registers if true
 	 */
 	int mux_from_pdata;
-	u8 pad1, pad2;
+	u8 pad1, pad2, pad3, pad4;
 
 	struct palmas_pmic_platform_data *pmic_pdata;
 	struct palmas_gpadc_platform_data *gpadc_pdata;
@@ -2513,6 +2513,16 @@ enum usb_irq_events {
 #define PALMAS_PU_PD_GPIO_CTRL1					0x6
 #define PALMAS_PU_PD_GPIO_CTRL2					0x7
 #define PALMAS_OD_OUTPUT_GPIO_CTRL				0x8
+#define PALMAS_GPIO_DATA_IN2					0x9
+#define PALMAS_GPIO_DATA_DIR2					0xA
+#define PALMAS_GPIO_DATA_OUT2					0xB
+#define PALMAS_GPIO_DEBOUNCE_EN2				0xC
+#define PALMAS_GPIO_CLEAR_DATA_OUT2				0xD
+#define PALMAS_GPIO_SET_DATA_OUT2				0xE
+#define PALMAS_PU_PD_GPIO_CTRL3					0xF
+#define PALMAS_PU_PD_GPIO_CTRL4					0x10
+#define PALMAS_OD_OUTPUT_GPIO_CTRL2				0x11
+#define PALMAS_GPO_CTRL						0x12
 
 /* Bit definitions for GPIO_DATA_IN */
 #define PALMAS_GPIO_DATA_IN_GPIO_7_IN				0x80
Signature · 1 line
1.7.0.4
author
#18 lore raw

PATCH v10 7/12 gpio: palmas: Enable DT support for palmas gpio.

In reply to Ian Lartey

From: J Keerthy <[email protected]>

Enable DT support for palmas gpio.

---
 drivers/gpio/gpio-palmas.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
drivers/gpio/gpio-palmas.c +13 -0
index 636648c..04da57a 100644
@@ -208,9 +208,22 @@ static int palmas_gpio_remove(struct platform_device *pdev)
 	return gpiochip_remove(&palmas_gpio->gpio_chip);
 }
 
+static struct of_device_id of_palmas_match_tbl[] = {
+	{ .compatible = "ti,palmas-gpio", },
+	{ .compatible = "ti,palmas-charger-gpio", },
+	{ .compatible = "ti,twl6035-gpio", },
+	{ .compatible = "ti,twl6036-gpio", },
+	{ .compatible = "ti,twl6037-gpio", },
+	{ .compatible = "ti,tps65913-gpio", },
+	{ .compatible = "ti,tps65914-gpio", },
+	{ .compatible = "ti,tps80036-gpio", },
+	{ /* end */ }
+};
+
 static struct platform_driver palmas_gpio_driver = {
 	.driver.name	= "palmas-gpio",
 	.driver.owner	= THIS_MODULE,
+	.driver.of_match_table = of_palmas_match_tbl,
 	.probe		= palmas_gpio_probe,
 	.remove		= palmas_gpio_remove,
 };
Signature · 1 line
1.7.0.4
author
#19 lore raw

PATCH v10 8/12 gpio: Palmas palmas_gpio_(read|write|update) factoring

In reply to Ian Lartey

palmas_gpio_(read|write|update) gpio parameter renamed to offset
palmas_gpio_write renamed to palmas_gpio_clear_and_set
as it no longer takes a data value instead it always sets the offset bit and clears all other bits -

---
 drivers/gpio/gpio-palmas.c |   32 ++++++++++++++++----------------
 1 files changed, 16 insertions(+), 16 deletions(-)
drivers/gpio/gpio-palmas.c +16 -16
index 04da57a..689c633 100644
@@ -32,30 +32,31 @@ struct palmas_gpio {
 };
 
 static int palmas_gpio_read(struct palmas *palmas, unsigned int reg,
-		int gpio, unsigned int *dest)
+		int offset, unsigned int *dest)
 {
 	/* registers for second bank are identical and offset by 0x9 */
-	if (gpio > 7)
+	if (offset > 7)
 		reg += PALMAS_GPIO_DATA_IN2;
 
 	return palmas_read(palmas, PALMAS_GPIO_BASE, reg, dest);
 }
 
-static int palmas_gpio_write(struct palmas *palmas, unsigned int reg,
-		int gpio, unsigned int data)
+/* Note: This procedure sets 1 bit and clears _all_ others */
+static int palmas_gpio_clear_and_set(struct palmas *palmas, unsigned int reg,
+		int offset)
 {
 	/* registers for second bank are identical and offset by 0x9 */
-	if (gpio > 7)
+	if (offset > 7)
 		reg += PALMAS_GPIO_DATA_IN2;
 
-	return palmas_write(palmas, PALMAS_GPIO_BASE, reg, data);
+	return palmas_write(palmas, PALMAS_GPIO_BASE, reg, BIT(offset % 8));
 }
 
 static int palmas_gpio_update_bits(struct palmas *palmas, unsigned int reg,
-		int gpio, unsigned int mask, unsigned int data)
+		int offset, unsigned int mask, unsigned int data)
 {
 	/* registers for second bank are identical and offset by 0x9 */
-	if (gpio > 7)
+	if (offset > 7)
 		reg += PALMAS_GPIO_DATA_IN2;
 
 	return palmas_update_bits(palmas, PALMAS_GPIO_BASE, reg, mask, data);
@@ -89,11 +90,11 @@ static void palmas_gpio_set(struct gpio_chip *gc, unsigned offset,
 	int ret;
 
 	if (value)
-		ret = palmas_gpio_write(palmas, PALMAS_GPIO_SET_DATA_OUT,
-				offset, BIT(offset % 8));
+		ret = palmas_gpio_clear_and_set(palmas,
+				PALMAS_GPIO_SET_DATA_OUT, offset);
 	else
-		ret = palmas_gpio_write(palmas, PALMAS_GPIO_CLEAR_DATA_OUT,
-				offset, BIT(offset % 8));
+		ret = palmas_gpio_clear_and_set(palmas,
+				PALMAS_GPIO_CLEAR_DATA_OUT, offset);
 	if (ret < 0)
 		dev_err(gc->dev, "%s write failed, err = %d\n",
 			(value) ? "GPIO_SET_DATA_OUT" : "GPIO_CLEAR_DATA_OUT",
@@ -111,7 +112,7 @@ static int palmas_gpio_output(struct gpio_chip *gc, unsigned offset,
 	palmas_gpio_set(gc, offset, value);
 
 	ret = palmas_gpio_update_bits(palmas, PALMAS_GPIO_DATA_DIR,
-			offset, 1 << (offset % 8), 1 << (offset % 8));
+			offset, BIT(offset % 8), BIT(offset % 8));
 	if (ret < 0)
 		dev_err(gc->dev, "GPIO_DATA_DIR write failed, err = %d\n", ret);
 	return ret;
@@ -124,7 +125,7 @@ static int palmas_gpio_input(struct gpio_chip *gc, unsigned offset)
 	int ret;
 
 	ret =  palmas_gpio_update_bits(palmas, PALMAS_GPIO_DATA_DIR,
-				offset, 1 << (offset % 8), 0);
+				offset, BIT(offset % 8), 0);
 	if (ret < 0)
 		dev_err(gc->dev, "GPIO_DATA_DIR write failed, err = %d\n", ret);
 	return ret;
@@ -149,7 +150,7 @@ static int palmas_gpio_set_debounce(struct gpio_chip *gc, unsigned offset,
 		data = 0xff;
 
 	return palmas_gpio_update_bits(palmas, PALMAS_GPIO_DEBOUNCE_EN,
-			offset, 1 << (offset % 8), data);
+			offset, BIT(offset % 8), data);
 }
 
 static int  palmas_gpio_probe(struct platform_device *pdev)
@@ -210,7 +211,6 @@ static int palmas_gpio_remove(struct platform_device *pdev)
 
 static struct of_device_id of_palmas_match_tbl[] = {
 	{ .compatible = "ti,palmas-gpio", },
-	{ .compatible = "ti,palmas-charger-gpio", },
 	{ .compatible = "ti,twl6035-gpio", },
 	{ .compatible = "ti,twl6036-gpio", },
 	{ .compatible = "ti,twl6037-gpio", },
Signature · 1 line
1.7.0.4
author
#20 lore raw

PATCH v10 9/12 leds: Add support for Palmas LEDs

In reply to Ian Lartey

The Palmas familly of chips has LED support. This is not always muxed to output pins so depending on the setting of the mux this driver will create the appropriate LED class devices.

---
 drivers/leds/Kconfig       |    9 +
 drivers/leds/Makefile      |    1 +
 drivers/leds/leds-palmas.c |  561 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/palmas.h |   80 +++++++
 4 files changed, 651 insertions(+), 0 deletions(-)
 create mode 100644 drivers/leds/leds-palmas.c
drivers/leds/Kconfig +9 -0
index d44806d..249027e 100644
@@ -479,6 +479,15 @@ config LEDS_BLINKM
 	  This option enables support for the BlinkM RGB LED connected
 	  through I2C. Say Y to enable support for the BlinkM LED.
 
+config LEDS_PALMAS
+	bool "LED support for the Palmas family of PMICs"
+	depends on LEDS_CLASS
+	depends on MFD_PALMAS
+	help
+	  This option enables the driver for LED1 & LED2 pins on Palmas PMIC
+	  if these pins are enabled in the mux configuration. The driver support
+	  ON/OFF and blinking with hardware control.
+
 comment "LED Triggers"
 source "drivers/leds/trigger/Kconfig"
 
drivers/leds/Makefile +1 -0
index ac28977..3acb116 100644
@@ -53,6 +53,7 @@ obj-$(CONFIG_LEDS_RENESAS_TPU)		+= leds-renesas-tpu.o
 obj-$(CONFIG_LEDS_MAX8997)		+= leds-max8997.o
 obj-$(CONFIG_LEDS_LM355x)		+= leds-lm355x.o
 obj-$(CONFIG_LEDS_BLINKM)		+= leds-blinkm.o
+obj-$(CONFIG_LEDS_PALMAS)		+= leds-palmas.o
 
 # LED SPI Drivers
 obj-$(CONFIG_LEDS_DAC124S085)		+= leds-dac124s085.o
drivers/leds/leds-palmas.c new file +561 -0

561 lines not on this page · raw message

include/linux/mfd/palmas.h +80 -0

98 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#21 lore raw

PATCH v10 9/12 leds: Add support for Palmas LEDs

Hi Ian,

Quoted 6 lines

The Palmas familly of chips has LED support. This is not always muxed to output pins so depending on the setting of the mux this driver will create the appropriate LED class devices.

Please see my comments below.

Quoted 26 lines
---
 drivers/leds/Kconfig       |    9 +
 drivers/leds/Makefile      |    1 +
 drivers/leds/leds-palmas.c |  561
++++++++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/palmas.h |   80 +++++++
 4 files changed, 651 insertions(+), 0 deletions(-)
 create mode 100644 drivers/leds/leds-palmas.c
drivers/leds/Kconfig +6 -0
index d44806d..249027e 100644
@@ -479,6 +479,15 @@ config LEDS_BLINKM
 	  This option enables support for the BlinkM RGB LED connected
 	  through I2C. Say Y to enable support for the BlinkM LED.
 
+config LEDS_PALMAS
+	bool "LED support for the Palmas family of PMICs"
+	depends on LEDS_CLASS
+	depends on MFD_PALMAS
+	help
+	  This option enables the driver for LED1 & LED2 pins on Palmas

PMIC

drivers/leds/Kconfig +1 -0
+	  if these pins are enabled in the mux configuration. The driver

support

drivers/leds/Kconfig config LEDS_BLINKM · line 490

Quoted 2 lines
drivers/leds/Kconfig +2 -0
+	  ON/OFF and blinking with hardware control.
+

LEDS_CLASS can be built as module, but LEDS_PALAMS is boolean type. Undefined LED functions symbol errors can happen. Therefore, dependency should be LED_CLASS=y.

Quoted 159 lines

comment "LED Triggers"
source "drivers/leds/trigger/Kconfig"

drivers/leds/Makefile +0 -0
index ac28977..3acb116 100644
@@ -53,6 +53,7 @@ obj-$(CONFIG_LEDS_RENESAS_TPU)		+= leds-

renesas-tpu.o
obj-$(CONFIG_LEDS_MAX8997) += leds-max8997.o
obj-$(CONFIG_LEDS_LM355x) += leds-lm355x.o
obj-$(CONFIG_LEDS_BLINKM) += leds-blinkm.o

drivers/leds/Makefile +1 -0
+obj-$(CONFIG_LEDS_PALMAS)		+= leds-palmas.o
 
 # LED SPI Drivers
 obj-$(CONFIG_LEDS_DAC124S085)		+= leds-dac124s085.o
drivers/leds/leds-palmas.c new file +9 -0
new file mode 100644
index 0000000..e9da4d1
@@ -0,0 +1,561 @@
+/*
+ * Driver for LED part of Palmas PMIC Chips
+ *
+ * Copyright 2011-2013 Texas Instruments Inc.
+ *
+ * Author: Graeme Gregory <[email protected]>
+ * Author: Ian Lartey <[email protected]>
+ *
+ *  This program is free software; you can redistribute it and/or

modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */

drivers/leds/leds-palmas.c new file +109 -0
+
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/leds.h>
+#include <linux/mfd/palmas.h>
+#include <linux/module.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+
+struct palmas_leds_data;
+
+enum palmas_led_on_time {
+	LED_ON_62_5MS = 0x00,
+	LED_ON_125MS = 0x01,
+	LED_ON_250MS = 0x02,
+	LED_ON_500MS = 0x03,
+};
+
+enum palmas_led_period {
+	LED_PERIOD_OFF = 0x00,
+	LED_PERIOD_125MS = 0x01,
+	LED_PERIOD_250MS = 0x02,
+	LED_PERIOD_500MS = 0x03,
+	LED_PERIOD_1000MS = 0x04,
+	LED_PERIOD_2000MS = 0x05,
+	LED_PERIOD_4000MS = 0x06,
+	LED_PERIOD_8000MS = 0x07,
+};
+
+struct palmas_led {
+	struct led_classdev cdev;
+	struct palmas_leds_data *leds_data;
+	int led_no;
+	struct work_struct work;
+	struct mutex mutex;
+
+	spinlock_t value_lock;
+
+	int blink;
+	enum palmas_led_on_time on_time;
+	enum palmas_led_period period;
+	enum led_brightness brightness;
+};
+
+struct palmas_leds_data {
+	struct device *dev;
+	struct led_classdev cdev;
+	struct palmas *palmas;
+
+	struct palmas_led *palmas_led;
+	int no_leds;
+};
+
+#define to_palmas_led(led_cdev) \
+	container_of(led_cdev, struct palmas_led, cdev)
+
+static char *palmas_led_names[] = {
+	"palmas:led1",
+	"palmas:led2",
+	"palmas:led3",
+	"palmas:led4",
+};
+
+struct palmas_led_info {
+	int mask;
+	int shift;
+};
+
+struct palmas_led_info led_period_info[] = {
+	{
+		PALMAS_LED_PERIOD_CTRL_LED_1_PERIOD_MASK,
+		PALMAS_LED_PERIOD_CTRL_LED_1_PERIOD_SHIFT,
+	},
+	{
+		PALMAS_LED_PERIOD_CTRL_LED_2_PERIOD_MASK,
+		PALMAS_LED_PERIOD_CTRL_LED_2_PERIOD_SHIFT,
+	},
+	{
+		PALMAS_LED_PERIOD2_CTRL_LED_3_PERIOD_MASK,
+		PALMAS_LED_PERIOD2_CTRL_LED_3_PERIOD_SHIFT,
+	},
+	{
+		PALMAS_LED_PERIOD2_CTRL_CHRG_LED_PERIOD_MASK,
+		PALMAS_LED_PERIOD2_CTRL_CHRG_LED_PERIOD_SHIFT,
+	},
+};
+
+struct palmas_led_info led_time_info[] = {
+	{
+		PALMAS_LED_CTRL_LED_1_ON_TIME_MASK,
+		PALMAS_LED_CTRL_LED_1_ON_TIME_SHIFT,
+	},
+	{
+		PALMAS_LED_CTRL_LED_2_ON_TIME_MASK,
+		PALMAS_LED_CTRL_LED_2_ON_TIME_SHIFT,
+	},
+	{
+		PALMAS_LED_CTRL2_LED_3_ON_TIME_MASK,
+		PALMAS_LED_CTRL2_LED_3_ON_TIME_SHIFT,
+	},
+	{
+		PALMAS_LED_CTRL2_CHRG_LED_ON_TIME_MASK,
+		PALMAS_LED_CTRL2_CHRG_LED_ON_TIME_SHIFT,
+	},
+};
+
+static int palmas_led_read(struct palmas_leds_data *leds, unsigned int

reg,

drivers/leds/leds-palmas.c new file +6 -0
+		unsigned int *dest)
+{
+	return palmas_read(leds->palmas, PALMAS_LED_BASE, reg, dest);
+}
+
+static int palmas_led_write(struct palmas_leds_data *leds, unsigned

int reg,

drivers/leds/leds-palmas.c new file +3 -0
+		unsigned int value)
+{
+	return palmas_write(leds->palmas, PALMAS_LED_BASE, reg, value);

drivers/leds/leds-palmas.c line 142

Quoted 10 lines
drivers/leds/leds-palmas.c new file +10 -0
+}
+
+static int palmas_led_update_bits(struct palmas_leds_data *leds,
+		unsigned int reg, unsigned int mask, unsigned int value)
+{
+	return palmas_update_bits(leds->palmas, PALMAS_LED_BASE,
+			reg, mask, value);
+}
+
+static void palmas_get_crtl_and_period(struct palmas_led *led,

It looks typo, _crtl_ -> _ctrl_.

Quoted 53 lines
drivers/leds/leds-palmas.c new file +10 -0
+static int palmas_leds_probe(struct platform_device *pdev)
+{
+	struct palmas *palmas = dev_get_drvdata(pdev->dev.parent);
+	struct palmas_leds_platform_data *pdata = pdev->dev.platform_data;
+	struct palmas_leds_data *leds_data;
+	struct device_node *node = pdev->dev.of_node;
+	int ret, i;
+	int offset = 0;
+
+	if (!palmas->led_muxed && !is_palmas_charger(palmas->product_id))

{

drivers/leds/leds-palmas.c new file +19 -0
+		dev_err(&pdev->dev, "there are no LEDs muxed\n");
+		return -EINVAL;
+	}
+
+	/* Palmas charger requires platform data */
+	if (is_palmas_charger(palmas->product_id) && node && !pdata) {
+
+		if (!pdata)
+			return -ENOMEM;
+
+		ret = palmas_dt_to_pdata(&pdev->dev, node, pdata);
+		if (ret)
+			return ret;
+	}
+
+	if (is_palmas_charger(palmas->product_id) && !pdata)
+		return -EINVAL;
+
+	leds_data = devm_kzalloc(&pdev->dev, sizeof(*leds_data),

GFP_KERNEL);

drivers/leds/leds-palmas.c new file +22 -0
+	if (!leds_data)
+		return -ENOMEM;
+	platform_set_drvdata(pdev, leds_data);
+
+	leds_data->palmas = palmas;
+
+	switch (palmas->led_muxed) {
+	case PALMAS_LED1_MUXED | PALMAS_LED2_MUXED:
+		leds_data->no_leds = 2;
+		break;
+	case PALMAS_LED1_MUXED:
+	case PALMAS_LED2_MUXED:
+		leds_data->no_leds = 1;
+		break;
+	default:
+		leds_data->no_leds = 0;
+		break;
+	}
+
+	if (is_palmas_charger(palmas->product_id)) {
+		if (pdata->chrg_led_mode)
+			leds_data->no_leds += 2;

drivers/leds/leds-palmas.c line 438

Quoted 10 lines
drivers/leds/leds-palmas.c new file +10 -0
+		else
+			leds_data->no_leds++;
+	}
+
+	if (leds_data->no_leds == 0)
+		leds_data->palmas_led = NULL;
+	else
+		leds_data = devm_kzalloc(&pdev->dev,
+				leds_data->no_leds * sizeof(*leds_data),
+				GFP_KERNEL);

Mem alloc, should it be 'leds_data->palmas_led' instead of 'leds_data'? Additionaly, size should be leds_data->no_leds * sizeof(*palmas_led) as well.

Quoted 36 lines
drivers/leds/leds-palmas.c new file +19 -0
+
+	/* Initialise LED1 */
+	if (palmas->led_muxed & PALMAS_LED1_MUXED) {
+		palmas_init_led(leds_data, offset, 1);
+		offset++;
+	}
+
+	/* Initialise LED2 */
+	if (palmas->led_muxed & PALMAS_LED2_MUXED) {
+		palmas_init_led(leds_data, offset, 2);
+		offset++;
+	}
+
+	if (is_palmas_charger(palmas->product_id)) {
+		palmas_init_led(leds_data, offset, 3);
+		offset++;
+
+		if (pdata->chrg_led_mode) {
+			palmas_led_update_bits(leds_data,

PALMAS_CHRG_LED_CTRL,

drivers/leds/leds-palmas.c new file +16 -0
+					PALMAS_CHRG_LED_CTRL_CHRG_LED_MODE,
+					PALMAS_CHRG_LED_CTRL_CHRG_LED_MODE);
+
+			palmas_init_led(leds_data, offset, 4);
+		}
+	}
+
+	for (i = 0; i < leds_data->no_leds; i++) {
+		ret = led_classdev_register(leds_data->dev,
+				&leds_data->palmas_led[i].cdev);
+		if (ret < 0) {
+			dev_err(&pdev->dev,
+				"Failed to register LED no: %d err: %d\n",
+				i, ret);
+			goto err_led;
+		}

drivers/leds/leds-palmas.c line 483

Quoted 10 lines
drivers/leds/leds-palmas.c new file +10 -0
+	}
+
+	if (!is_palmas_charger(palmas->product_id))
+		return 0;
+
+	/* Set the LED current registers if set in platform data */
+	if (pdata->led1_current)
+		palmas_led_update_bits(leds_data, PALMAS_LED_CURRENT_CTRL1,
+				PALMAS_LED_CURRENT_CTRL1_LED_1_CURRENT_MASK,
+				pdata->led1_current);

For better readability, mask and shifted values are recommended even if the shift is 0. These shift bits are already defined in a header.

Quoted 6 lines
drivers/leds/leds-palmas.c new file +6 -0
+
+	if (pdata->led2_current)
+		palmas_led_update_bits(leds_data, PALMAS_LED_CURRENT_CTRL1,
+				PALMAS_LED_CURRENT_CTRL1_LED_2_CURRENT_MASK,
+				pdata->led2_current <<
+				PALMAS_LED_CURRENT_CTRL1_LED_2_CURRENT_SHIFT);

drivers/leds/leds-palmas.c line 499

Quoted 10 lines
drivers/leds/leds-palmas.c new file +10 -0
+
+	if (pdata->led3_current)
+		palmas_led_update_bits(leds_data, PALMAS_LED_CURRENT_CTRL2,
+				PALMAS_LED_CURRENT_CTRL2_LED_3_CURRENT_MASK,
+				pdata->led3_current);
+
+	if (pdata->led3_current)
+		palmas_led_update_bits(leds_data, PALMAS_LED_CURRENT_CTRL2,
+				PALMAS_LED_CURRENT_CTRL2_LED_3_CURRENT_MASK,
+				pdata->led3_current);

Updating 'led3_current' is a duplicate. Please remove it. Shift bit operation also is needed.

Quoted 20 lines
drivers/leds/leds-palmas.c new file +20 -0
+
+	if (pdata->led4_current)
+		palmas_led_update_bits(leds_data, PALMAS_CHRG_LED_CTRL,
+				PALMAS_CHRG_LED_CTRL_CHRG_LED_CURRENT_MASK,
+				pdata->led4_current <<
+				PALMAS_CHRG_LED_CTRL_CHRG_LED_CURRENT_SHIFT);
+
+	if (pdata->chrg_led_vbat_low)
+		palmas_led_update_bits(leds_data, PALMAS_CHRG_LED_CTRL,
+				PALMAS_CHRG_LED_CTRL_CHRG_LOWBAT_BLK_DIS,
+				PALMAS_CHRG_LED_CTRL_CHRG_LOWBAT_BLK_DIS);
+
+	return 0;
+
+err_led:
+	for (i = 0; i < leds_data->no_leds; i++)
+		led_classdev_unregister(&leds_data->palmas_led[i].cdev);
+	return ret;
+}
+

drivers/leds/leds-palmas.c line 529

Quoted 10 lines
drivers/leds/leds-palmas.c new file +10 -0
+static int palmas_leds_remove(struct platform_device *pdev)
+{
+	struct palmas_leds_data *leds_data = platform_get_drvdata(pdev);
+	int i;
+
+	for (i = 0; i < leds_data->no_leds; i++)
+		led_classdev_unregister(&leds_data->palmas_led[i].cdev);
+	if (i)
+		kfree(leds_data->palmas_led);
+	kfree(leds_data);

Kfree()s are not required because both were allocated by devm_kzalloc()s.

Quoted 40 lines
drivers/leds/leds-palmas.c new file +32 -0
+
+	return 0;
+}
+
+static struct of_device_id of_palmas_match_tbl[] = {
+	{ .compatible = "ti,palmas-leds", },
+	{ .compatible = "ti,twl6035-leds", },
+	{ .compatible = "ti,twl6036-leds", },
+	{ .compatible = "ti,twl6037-leds", },
+	{ .compatible = "ti,tps65913-leds", },
+	{ .compatible = "ti,tps65914-leds", },
+	{ .compatible = "ti,tps80036-leds", },
+	{ /* end */ }
+};
+
+static struct platform_driver palmas_leds_driver = {
+	.driver = {
+		.name = "palmas-leds",
+		.of_match_table = of_palmas_match_tbl,
+		.owner = THIS_MODULE,
+	},
+	.probe = palmas_leds_probe,
+	.remove = palmas_leds_remove,
+};
+
+module_platform_driver(palmas_leds_driver);
+
+MODULE_AUTHOR("Graeme Gregory <[email protected]>");
+MODULE_DESCRIPTION("Palmas LED driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:palmas-leds");
+MODULE_DEVICE_TABLE(of, of_palmas_match_tbl);
include/linux/mfd/palmas.h +0 -0
index d8c303b..73186c8 100644
@@ -232,6 +232,36 @@ struct palmas_clk_platform_data {
 	int clk32kgaudio_mode_sleep;
 };
 

include/linux/mfd/palmas.h struct palmas_clk_platform_data { · line 244

Quoted 10 lines
include/linux/mfd/palmas.h +10 -0
+enum palmas_led_current {
+	PALMAS_ILED_0mA = 0,		/*  0    mA */
+	PALMAS_ILED_0m25A,		/*  0.25 mA */
+	PALMAS_ILED_0m5A,		/*  0.5  mA */
+	PALMAS_ILED_1m0A,		/*  1.0  mA */
+	PALMAS_ILED_2m5A,		/*  2.5  mA */
+	PALMAS_ILED_5m0A,		/*  5.0  mA */
+	PALMAS_ILED_10m0A,		/* 10.0  mA */
+	PALMAS_ILED_0m0A,		/*  0    mA */
+};

It's a trivial comment - why don't you use micro unit such like 250uA, 500uA?

Quoted 5 lines
include/linux/mfd/palmas.h +5 -0
+
+#define is_palmas_led_current_ok(a) (((a) == PALMAS_ILED_0mA) || \
+		((a) == PALMAS_ILED_0m25A) || \
+		((a) == PALMAS_ILED_0m5A) || \
+		((a) == PALMAS_ILED_1m0A) || \

include/linux/mfd/palmas.h struct palmas_clk_platform_data { · line 259

Quoted 10 lines
include/linux/mfd/palmas.h +10 -0
+		((a) == PALMAS_ILED_2m5A) || \
+		((a) == PALMAS_ILED_5m0A) || \
+		((a) == PALMAS_ILED_10m0A) || \
+		((a) == PALMAS_ILED_0m0A))
+
+struct palmas_leds_platform_data {
+	int led1_current;
+	int led2_current;
+	int led3_current;
+	int led4_current;

Please define enum palmas_led_current type for ledN_current instead of integer.

Quoted 80 lines
include/linux/mfd/palmas.h +55 -1
+
+	int chrg_led_mode;
+	int chrg_led_vbat_low;
+};
+
 struct palmas_platform_data {
 	int irq_flags;
 	int gpio_base;
@@ -1856,6 +1886,12 @@ enum usb_irq_events {
 #define PALMAS_LED_CTRL						0x1
 #define PALMAS_PWM_CTRL1					0x2
 #define PALMAS_PWM_CTRL2					0x3
+#define PALMAS_LED_PERIOD2_CTRL					0x4
+#define PALMAS_LED_CTRL2					0x5
+#define PALMAS_LED_CURRENT_CTRL1				0x6
+#define PALMAS_LED_CURRENT_CTRL2				0x7
+#define PALMAS_CHRG_LED_CTRL					0x8
+#define PALMAS_LED_EN						0x9
 
 /* Bit definitions for LED_PERIOD_CTRL */
 #define PALMAS_LED_PERIOD_CTRL_LED_2_PERIOD_MASK		0x38
@@ -1883,6 +1919,50 @@ enum usb_irq_events {
 #define PALMAS_PWM_CTRL2_PWM_DUTY_SEL_MASK			0xff
 #define PALMAS_PWM_CTRL2_PWM_DUTY_SEL_SHIFT			0
 
+/* Bit definitions for LED_PERIOD2_CTRL */
+#define PALMAS_LED_PERIOD2_CTRL_CHRG_LED_PERIOD_MASK		0x38
+#define PALMAS_LED_PERIOD2_CTRL_CHRG_LED_PERIOD_SHIFT		3
+#define PALMAS_LED_PERIOD2_CTRL_LED_3_PERIOD_MASK		0x07
+#define PALMAS_LED_PERIOD2_CTRL_LED_3_PERIOD_SHIFT		0
+
+/* Bit definitions for LED_CTRL2 */
+#define PALMAS_LED_CTRL2_CHRG_LED_SEQ				0x20
+#define PALMAS_LED_CTRL2_CHRG_LED_SEQ_SHIFT			5
+#define PALMAS_LED_CTRL2_LED_3_SEQ				0x10
+#define PALMAS_LED_CTRL2_LED_3_SEQ_SHIFT			4
+#define PALMAS_LED_CTRL2_CHRG_LED_ON_TIME_MASK			0x0c
+#define PALMAS_LED_CTRL2_CHRG_LED_ON_TIME_SHIFT			2
+#define PALMAS_LED_CTRL2_LED_3_ON_TIME_MASK			0x03
+#define PALMAS_LED_CTRL2_LED_3_ON_TIME_SHIFT			0
+
+/* Bit definitions for LED_CURRENT_CTRL1 */
+#define PALMAS_LED_CURRENT_CTRL1_LED_2_CURRENT_MASK		0x38
+#define PALMAS_LED_CURRENT_CTRL1_LED_2_CURRENT_SHIFT		3
+#define PALMAS_LED_CURRENT_CTRL1_LED_1_CURRENT_MASK		0x07
+#define PALMAS_LED_CURRENT_CTRL1_LED_1_CURRENT_SHIFT		0
+
+/* Bit definitions for LED_CURRENT_CTRL2 */
+#define PALMAS_LED_CURRENT_CTRL2_LED_3_CURRENT_MASK		0x07
+#define PALMAS_LED_CURRENT_CTRL2_LED_3_CURRENT_SHIFT		0
+
+/* Bit definitions for CHRG_LED_CTRL */
+#define PALMAS_CHRG_LED_CTRL_CHRG_LED_CURRENT_MASK		0x38
+#define PALMAS_CHRG_LED_CTRL_CHRG_LED_CURRENT_SHIFT		3
+#define PALMAS_CHRG_LED_CTRL_CHRG_LOWBAT_BLK_DIS		0x02
+#define PALMAS_CHRG_LED_CTRL_CHRG_LOWBAT_BLK_DIS_SHIFT		1
+#define PALMAS_CHRG_LED_CTRL_CHRG_LED_MODE			0x01
+#define PALMAS_CHRG_LED_CTRL_CHRG_LED_MODE_SHIFT		0
+
+/* Bit definitions for LED_EN */
+#define PALMAS_LED_EN_CHRG_LED_EN				0x08
+#define PALMAS_LED_EN_CHRG_LED_EN_SHIFT				3
+#define PALMAS_LED_EN_LED_3_EN					0x04
+#define PALMAS_LED_EN_LED_3_EN_SHIFT				2
+#define PALMAS_LED_EN_LED_2_EN					0x02
+#define PALMAS_LED_EN_LED_2_EN_SHIFT				1
+#define PALMAS_LED_EN_LED_1_EN					0x01
+#define PALMAS_LED_EN_LED_1_EN_SHIFT				0
+
 /* Registers for function INTERRUPT */
 #define PALMAS_INT1_STATUS					0x0
 #define PALMAS_INT1_MASK					0x1
--

1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-leds" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#22 lore raw

PATCH v10 10/12 clk: add a clock driver for palmas

In reply to Ian Lartey

Palmas has two clock generators in it, clk32kg and clk32kg audio. They are fixed frequency clocks that only have enable/disable functionality.

---
 drivers/clk/clk-palmas.c |  275 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 275 insertions(+), 0 deletions(-)
 create mode 100644 drivers/clk/clk-palmas.c
drivers/clk/clk-palmas.c new file +275 -0
new file mode 100644
index 0000000..aea7710
@@ -0,0 +1,275 @@
+/*
+ * PALMAS resource clock module driver
+ *
+ * Copyright (C) 2011-2013 Texas Instruments Inc.
+ * Graeme Gregory <[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.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/clk.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/platform_device.h>
+#include <linux/mfd/palmas.h>
+#include <linux/clk-provider.h>
+#include <linux/of_platform.h>
+
+struct palmas_clk {
+	struct palmas *palmas;
+	struct device *dev;
+	struct clk_hw clk32kg;
+	struct clk_hw clk32kgaudio;
+	int clk32kgaudio_mode_sleep;
+	int clk32kg_mode_sleep;
+};
+
+static int palmas_clock_setbits(struct palmas *palmas, unsigned int reg,
+		unsigned int data)
+{
+	return palmas_update_bits(palmas, PALMAS_RESOURCE_BASE,
+			reg, data, data);
+}
+
+static int palmas_clock_clrbits(struct palmas *palmas, unsigned int reg,
+		unsigned int data)
+{
+	return palmas_update_bits(palmas, PALMAS_RESOURCE_BASE,
+			reg, data, 0);
+}
+
+static int palmas_prepare_clk32kg(struct clk_hw *hw)
+{
+	struct palmas_clk *palmas_clk = container_of(hw, struct palmas_clk,
+			clk32kg);
+	int ret;
+
+	ret = palmas_clock_setbits(palmas_clk->palmas,
+			PALMAS_CLK32KG_CTRL, PALMAS_CLK32KG_CTRL_MODE_ACTIVE);
+	if (ret)
+		dev_err(palmas_clk->dev, "Failed to enable clk32kg: %d\n", ret);
+
+	return ret;
+}
+
+static void palmas_unprepare_clk32kg(struct clk_hw *hw)
+{
+	struct palmas_clk *palmas_clk = container_of(hw, struct palmas_clk,
+			clk32kg);
+	int ret;
+
+	ret = palmas_clock_clrbits(palmas_clk->palmas,
+			PALMAS_CLK32KG_CTRL, PALMAS_CLK32KG_CTRL_MODE_ACTIVE);
+	if (ret)
+		dev_err(palmas_clk->dev, "Failed to enable clk32kg: %d\n", ret);
+
+	return;
+}
+
+static const struct clk_ops palmas_clk32kg_ops = {
+	.prepare = palmas_prepare_clk32kg,
+	.unprepare = palmas_unprepare_clk32kg,
+};
+
+static int palmas_prepare_clk32kgaudio(struct clk_hw *hw)
+{
+	struct palmas_clk *palmas_clk = container_of(hw, struct palmas_clk,
+			clk32kgaudio);
+	int ret;
+
+	ret = palmas_clock_setbits(palmas_clk->palmas,
+		PALMAS_CLK32KGAUDIO_CTRL, PALMAS_CLK32KGAUDIO_CTRL_MODE_ACTIVE);
+	if (ret)
+		dev_err(palmas_clk->dev,
+				"Failed to enable clk32kgaudio: %d\n", ret);
+
+	return ret;
+}
+
+static void palmas_unprepare_clk32kgaudio(struct clk_hw *hw)
+{
+	struct palmas_clk *palmas_clk = container_of(hw, struct palmas_clk,
+			clk32kgaudio);
+	int ret;
+
+	ret = palmas_clock_clrbits(palmas_clk->palmas,
+		PALMAS_CLK32KGAUDIO_CTRL, PALMAS_CLK32KGAUDIO_CTRL_MODE_ACTIVE);
+	if (ret)
+		dev_err(palmas_clk->dev,
+				"Failed to enable clk32kgaudio: %d\n", ret);
+
+	return;
+}
+
+static const struct clk_ops palmas_clk32kgaudio_ops = {
+	.prepare = palmas_prepare_clk32kgaudio,
+	.unprepare = palmas_unprepare_clk32kgaudio,
+};
+
+static int palmas_initialise_clk(struct palmas_clk *palmas_clk)
+{
+	int ret;
+
+	if (palmas_clk->clk32kg_mode_sleep) {
+		ret = palmas_clock_setbits(palmas_clk->palmas,
+			PALMAS_CLK32KG_CTRL, PALMAS_CLK32KG_CTRL_MODE_SLEEP);
+		if (ret)
+			return ret;
+	}
+
+	if (palmas_clk->clk32kgaudio_mode_sleep) {
+		ret = palmas_clock_setbits(palmas_clk->palmas,
+			PALMAS_CLK32KGAUDIO_CTRL,
+			PALMAS_CLK32KGAUDIO_CTRL_MODE_SLEEP);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
+static void palmas_dt_to_pdata(struct device_node *node,
+		struct palmas_clk_platform_data *pdata,
+		const char **name1, const char **name2)
+{
+	int ret;
+	u32 prop;
+
+	ret = of_property_read_u32(node, "ti,clk32kg-mode-sleep", &prop);
+	if (!ret)
+		pdata->clk32kg_mode_sleep = prop;
+
+	ret = of_property_read_u32(node, "ti,clk32kgaudio-mode-sleep", &prop);
+	if (!ret)
+		pdata->clk32kgaudio_mode_sleep = prop;
+
+	of_property_read_string_index(node, "clock-names", 1, name1);
+
+	of_property_read_string_index(node, "clock-names", 2, name2);
+}
+
+static int palmas_clk_probe(struct platform_device *pdev)
+{
+	struct palmas *palmas = dev_get_drvdata(pdev->dev.parent);
+	struct palmas_clk_platform_data *pdata = pdev->dev.platform_data;
+	struct device_node *node = pdev->dev.of_node;
+	struct palmas_clk *palmas_clk;
+	struct clk *clk;
+	struct clk_init_data init_clk32g, init_clk32gaudio;
+	int ret;
+
+	if (node && !pdata) {
+		pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
+
+		if (!pdata)
+			return -ENOMEM;
+
+		palmas_dt_to_pdata(node, pdata, &init_clk32g.name,
+				&init_clk32gaudio.name);
+	}
+
+	palmas_clk = devm_kzalloc(&pdev->dev, sizeof(*palmas_clk), GFP_KERNEL);
+	if (!palmas_clk)
+		return -ENOMEM;
+
+	palmas_clk->palmas = palmas;
+	palmas_clk->dev = &pdev->dev;
+
+	if (!init_clk32g.name)
+		init_clk32g.name = "clk32kg";
+	init_clk32g.ops = &palmas_clk32kg_ops;
+	init_clk32g.parent_names = NULL;
+	init_clk32g.num_parents = 0;
+	palmas_clk->clk32kg.init = &init_clk32g;
+
+	clk = clk_register(palmas_clk->dev, &palmas_clk->clk32kg);
+	if (IS_ERR(clk)) {
+		dev_dbg(&pdev->dev, "clk32kg clock register failed %ld\n",
+				PTR_ERR(clk));
+		ret = PTR_ERR(clk);
+		goto err_clk32kg;
+	}
+
+	if (!init_clk32gaudio.name)
+		init_clk32gaudio.name = "clk32kgaudio";
+	init_clk32gaudio.ops = &palmas_clk32kgaudio_ops;
+	init_clk32gaudio.parent_names = NULL;
+	init_clk32gaudio.num_parents = 0;
+	palmas_clk->clk32kgaudio.init = &init_clk32gaudio;
+
+	clk = clk_register(palmas_clk->dev, &palmas_clk->clk32kgaudio);
+	if (IS_ERR(clk)) {
+		dev_dbg(&pdev->dev, "clk32kgaudio clock register failed %ld\n",
+		PTR_ERR(clk));
+		ret = PTR_ERR(clk);
+		goto err_audio;
+	}
+
+	ret = palmas_initialise_clk(palmas_clk);
+	if (ret)
+		goto err;
+
+	dev_set_drvdata(&pdev->dev, palmas_clk);
+
+	return 0;
+
+err:
+	clk_unregister(palmas_clk->clk32kgaudio.clk);
+err_audio:
+	clk_unregister(palmas_clk->clk32kg.clk);
+err_clk32kg:
+
+	return ret;
+}
+
+static int palmas_clk_remove(struct platform_device *pdev)
+{
+	struct palmas_clk *palmas_clk = dev_get_drvdata(&pdev->dev);
+
+	clk_unregister(palmas_clk->clk32kgaudio.clk);
+	clk_unregister(palmas_clk->clk32kg.clk);
+
+	return 0;
+}
+
+static struct of_device_id of_palmas_match_tbl[] = {
+	{ .compatible = "ti,palmas-clk", },
+	{ .compatible = "ti,twl6035-clk", },
+	{ .compatible = "ti,twl6036-clk", },
+	{ .compatible = "ti,twl6037-clk", },
+	{ .compatible = "ti,tps65913-clk", },
+	{ .compatible = "ti,tps65914-clk", },
+	{ .compatible = "ti,tps80036-clk", },
+	{ /* end */ }
+};
+MODULE_DEVICE_TABLE(of, of_palmas_match_tbl);
+
+static struct platform_driver palmas_clk_driver = {
+	.probe = palmas_clk_probe,
+	.remove = palmas_clk_remove,
+	.driver = {
+		.name = "palmas-clk",
+		.of_match_table = of_palmas_match_tbl,
+		.owner = THIS_MODULE,
+	},
+};
+
+module_platform_driver(palmas_clk_driver);
+
+MODULE_AUTHOR("Graeme Gregory <[email protected]>");
+MODULE_DESCRIPTION("PALMAS clock driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:palmas-clk");
Signature · 1 line
1.7.0.4
author
#23 lore raw

PATCH v10 11/12 clk: Kconfig for Palmas clock driver

In reply to Ian Lartey
---
 drivers/clk/Kconfig  |    8 ++++++++
 drivers/clk/Makefile |    1 +
 2 files changed, 9 insertions(+), 0 deletions(-)
drivers/clk/Kconfig +8 -0
index a47e6ee..a8e0655 100644
@@ -63,6 +63,14 @@ config CLK_TWL6040
 	  McPDM. McPDM module is using the external bit clock on the McPDM bus
 	  as functional clock.
 
+config CLK_PALMAS
+	tristate "Palmas PMIC Clock Support"
+	depends on MFD_PALMAS
+	---help---
+	  Enable clock support for the two clocks on Palmas PMIC chips:
+	  - A 32KHz audio-gated clock (primarily for audio devices)
+	  - A digitally-gated 32KHz clock
+
 endmenu
 
 source "drivers/clk/mvebu/Kconfig"
drivers/clk/Makefile +1 -0
index 0147022..34f8d97 100644
@@ -35,3 +35,4 @@ obj-$(CONFIG_X86)		+= x86/
 obj-$(CONFIG_COMMON_CLK_WM831X) += clk-wm831x.o
 obj-$(CONFIG_COMMON_CLK_MAX77686) += clk-max77686.o
 obj-$(CONFIG_CLK_TWL6040)	+= clk-twl6040.o
+obj-$(CONFIG_CLK_PALMAS)	+= clk-palmas.o
Signature · 1 line
1.7.0.4
author
#24 lore raw

PATCH v10 12/12 regulator: palmas remove palmas-charger option from DT bindings

In reply to Ian Lartey
---
 drivers/regulator/palmas-regulator.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
drivers/regulator/palmas-regulator.c +0 -1
index a9b558e..6b2d829 100644
@@ -803,7 +803,6 @@ static int palmas_remove(struct platform_device *pdev)
 
 static struct of_device_id of_palmas_match_tbl[] = {
 	{ .compatible = "ti,palmas-pmic", },
-	{ .compatible = "ti,palmas-charger-pmic", },
 	{ .compatible = "ti,twl6035-pmic", },
 	{ .compatible = "ti,twl6036-pmic", },
 	{ .compatible = "ti,twl6037-pmic", },
Signature · 1 line
1.7.0.4
#26 lore raw
In reply to Ian Lartey

Hi Ian,

Quoted 7 lines · On Fri, 22 Mar 2013 14:55:10 +0000 Ian Lartey <[email protected]> wrote:

This patchset adds to the support for the Palmas series of PMIC chips.

Some of the patches have previously been submitted individually. The DT bindings doc has been added first due to comments that it was missing.

Patches based on linux-next-20130319

I can't really comment on the patch set except to say that you should not base on linux-next, you should base on the tree to which you expect the patch set to be applied.

Signature · 9 lines
Cheers,
Stephen Rothwell                    sfr at canb.auug.org.au
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130323/2ca1b24a/attachment.sig>
#27 lore raw
Quoted 7 lines · Stephen Rothwell
Quoted 1 line · On Fri, 22 Mar 2013 14:55:10 +0000 Ian Lartey <[email protected]> wrote:

Patches based on linux-next-20130319

I can't really comment on the patch set except to say that you should not base on linux-next, you should base on the tree to which you expect the patch set to be applied.

It's fairly common to suggest to people working over lots of subsystems
like this that they use -next since for most subsystems it contains the
trees that should be submitted against and it's much more efficient.
This works OK most of the time when people are posting patches as
opposed to pull requests, though obviously cross tree issues do happen
from time to time.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130324/e88a0cbc/attachment.sig>

#28 lore raw

v10 cover Palmas updates

In reply to Ian Lartey
Quoted 7 lines · Ian Lartey

This patchset adds to the support for the Palmas series of PMIC chips.

Some of the patches have previously been submitted individually. The DT bindings doc has been added first due to comments that it was missing.

Patches based on linux-next-20130319

Series looks good. Minor issue in code but can be taken on later.

#29 lore raw
In reply to Ian Lartey

Hi Ian,

Quoted 6 lines · Ian Lartey

This patchset adds to the support for the Palmas series of PMIC chips.

Some of the patches have previously been submitted individually. The DT bindings doc has been added first due to comments that it was missing.

Patches based on linux-next-20130319

Are you expecting all those patches to go through the MFD tree ? Also, you stil have a few comments from Milo and Stephen to adress. Are you planning to send a v11 ?

Cheers,
Samuel.

Signature · 2 lines
Intel Open Source Technology Centre
http://oss.intel.com/
#30 lore raw
Quoted 5 lines · Samuel Ortiz

Hi Ian,

Quoted 2 lines · Ian Lartey

This patchset adds to the support for the Palmas series of PMIC chips.

Quoted 9 lines
Quoted 4 lines

Some of the patches have previously been submitted individually. The DT bindings doc has been added first due to comments that it was missing.

Patches based on linux-next-20130319

Are you expecting all those patches to go through the MFD tree ? Also, you stil have a few comments from Milo and Stephen to adress. Are you planning to send a v11 ?

Hi Samuel,

The device is an MFD so I suspect the best path is through MFD tree although I notice you have applied the patch that was required by all other patches so maybe this is not so much the case now!

Real life has got in the way of the next updated series of patches but they will be issued just as soon as we can.

Thanks

Graeme

#31 lore raw

Hi Graeme,

Quoted 10 lines · Graeme Gregory
Quoted 9 lines · Samuel Ortiz

Hi Ian,

Quoted 6 lines · Ian Lartey

This patchset adds to the support for the Palmas series of PMIC chips.

Some of the patches have previously been submitted individually. The DT bindings doc has been added first due to comments that it was missing.

Patches based on linux-next-20130319

Quoted 8 lines
Quoted 5 lines

Are you expecting all those patches to go through the MFD tree ? Also, you stil have a few comments from Milo and Stephen to adress. Are you planning to send a v11 ?

Hi Samuel,

The device is an MFD so I suspect the best path is through MFD tree

Yes, that's fine. I just need to make sure everyone is on sync.

Quoted 5 lines

although I notice you have applied the patch that was required by all other patches so maybe this is not so much the case now!

Real life has got in the way of the next updated series of patches but they will be issued just as soon as we can.

I know about real life getting in the way, no worries ;)

Cheers,
Samuel.

Signature · 2 lines
Intel Open Source Technology Centre
http://oss.intel.com/