Skip to contentSkip to conversation

Add rockchip RK808 pmic driver

PATCH Superseded Chris Zhong 5 participants 19 messages Sep 1, 2014 – Sep 3, 2014

Subsystems (6)

v7 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v7 cover Add rockchip RK808 pmic driver

This is the initial version of the RK808 PMIC. This is a power management IC for multimedia products.

It provides regulators that are able to supply power to processor cores and other components. The chip provides other modules including RTC, Clockout

Changes in v7:
Advices by Mark Rutland
- modify description about clock-cells
- update the example
Adviced by Lee Jones
- coding style
- remove rk808_pre_init function
Adviced by Doug
- add "&& OF" to the dependencies
- add .init_ack_masked = true in rk808_irq_chip
Adviced by doug
- read rtc time from shadowed registers
Adviced by Dmitry
- use CONFIG_PM_SLEEP replace CONFIG_PM
- use SIMPLE_DEV_PM_OPS replace dev_pm_ops
- fix dev_warn
- coding style
Adviced by Heiko
- remove rtc_ctl
Adviced by doug
-fix coding style problems
- remove pdata struct from header file, add rk808_regulator struct

Changes in v6:
Advices by Mark Rutland
- add description about clock-cells
Advices by Doug
- modify description about regulator
- remove pinctrl description
Adviced by Lee Jones in v2
- rk808_i2c_client instead of g_rk808
- remove pdata form struct rk808
Adviced by doug
- move RTC_READSEL setting into probe
Adviced by doug
- use correct argument call of_clk_add_provider in probe
- remove the redundant code

Changes in v5:
Advices by Mark Brown
- add description about regulator valid name.
- add a header file "rockchip,rk808".
- fixed a bug about set_time failed
Adviced by doug
- add some error checking in probe
- move "rockchip,rk808.h" into the patch about dt-bindings
- re-edit base on Mark's branch

Changes in v4:
Advices by Doug
- add a "#clock-cells" propertiy
- update the example
Adviced by Lee Jones in v2
- modify the description in Kconfig
- remove some unnecessary header files
- remove dev from struct rk808
- use enum for define RK808_ID...
- use &client->dev replace rk808->dev
Adviced by doug
- add "clock-output-names" propertiey
- add a header file "rockchip,rk808.h"
- use &client->dev replace rk808->dev

Changes in v3:
- fix compile err
- fix compile err

Changes in v2:
Adviced by Mark Browm:
- use defines for register setting value
- remove rtc alarm disable in shutdown
- remove while(1) in shutdown
- remove read 0x2f in probe
Adviced by javier.martinez
- Add a separate clock driver, rather than in RTC driver Adviced by javier.martinez
- separated from rtc-rk808.c
Adviced by Mark Browm:
- change of_find_node_by_name to find_child_by_name
- use RK808_NUM_REGULATORS as the name of the constant
- create a pdata when missing platform data
- use the rk808_reg name to supply_regulator name
- replace regulator_register with devm_regulator_register
- some other problem with coding style

Chris Zhong (5):
dt-bindings: Add RK808 device tree bindings document
MFD: RK808: Add new mfd driver for RK808
RTC: RK808: add RTC driver for RK808
clk: RK808: Add clkout driver for RK808
regulator: RK808: Remove pdata from the regulator

 Documentation/devicetree/bindings/mfd/rk808.txt |  166 +++++++++
 drivers/clk/Kconfig                             |    9 +
 drivers/clk/Makefile                            |    1 +
 drivers/clk/clk-rk808.c                         |  160 +++++++++
 drivers/mfd/Kconfig                             |   13 +
 drivers/mfd/Makefile                            |    1 +
 drivers/mfd/rk808.c                             |  243 +++++++++++++
 drivers/regulator/rk808-regulator.c             |   52 ++-
 drivers/rtc/Kconfig                             |   10 +
 drivers/rtc/Makefile                            |    1 +
 drivers/rtc/rtc-rk808.c                         |  419 +++++++++++++++++++++++
 include/dt-bindings/clock/rockchip,rk808.h      |   11 +
 include/linux/mfd/rk808.h                       |  196 +++++++++++
 13 files changed, 1250 insertions(+), 32 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mfd/rk808.txt
 create mode 100644 drivers/clk/clk-rk808.c
 create mode 100644 drivers/mfd/rk808.c
 create mode 100644 drivers/rtc/rtc-rk808.c
 create mode 100644 include/dt-bindings/clock/rockchip,rk808.h
 create mode 100644 include/linux/mfd/rk808.h
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v7 1/5 dt-bindings: Add RK808 device tree bindings document

Add device tree bindings documentation and a header file for rockchip's RK808 pmic.

---

Changes in v7:
Advices by Mark Rutland
- modify description about clock-cells
- update the example

Changes in v6:
Advices by Mark Rutland
- add description about clock-cells
Advices by Doug
- modify description about regulator
- remove pinctrl description

Changes in v5:
Advices by Mark Brown
- add description about regulator valid name.
- add a header file "rockchip,rk808".

Changes in v4:
Advices by Doug
- add a "#clock-cells" propertiy
- update the example

Changes in v3: None
Changes in v2: None

 Documentation/devicetree/bindings/mfd/rk808.txt |  166 +++++++++++++++++++++++
 include/dt-bindings/clock/rockchip,rk808.h      |   11 ++
 2 files changed, 177 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/rk808.txt
 create mode 100644 include/dt-bindings/clock/rockchip,rk808.h
Documentation/devicetree/bindings/mfd/rk808.txt new file +166 -0
new file mode 100644
index 0000000..f8932ac
@@ -0,0 +1,166 @@
+RK808 Power Management Integrated Circuit
+
+Required properties:
+- compatible: "rockchip,rk808"
+- reg: I2C slave address
+- interrupt-parent: The parent interrupt controller.
+- interrupts: the interrupt outputs of the controller.
+- #clock-cells: from common clock binding; shall be set to 1 (multiple clock
+  outputs)
+
+Optional properties:
+- clock-output-names: From common clock binding to override the
+  default output clock name
+- rockchip,system-power-controller: Telling whether or not this pmic is controlling
+  the system power.
+
+Regulators: All the regulators of RK808 to be instantiated shall be
+listed in a child node named 'regulators'. Each regulator is represented
+by a child node of the 'regulators' node.
+
+	regulator-name {
+		/* standard regulator bindings here */
+	};
+
+Following regulators of the RK808 PMIC block are supported. Note that
+the 'n' in regulator name, as in DCDC_REGn or LDOn, represents the DCDC or LDO
+number as described in RK808 datasheet.
+
+	- DCDC_REGn
+		- valid values for n are 1 to 4.
+	- LDO_REGn
+		- valid values for n are 1 to 8.
+	- SWITCH_REGn
+		- valid values for n are 1 to 2
+
+Standard regulator bindings are used inside regulator subnodes. Check
+  Documentation/devicetree/bindings/regulator/regulator.txt
+for more details
+
+Example:
+	rk808: pmic@1b {
+		compatible = "rockchip,rk808";
+		clock-output-names = "xin32k", "rk808-clkout2";
+		interrupt-parent = <&gpio0>;
+		interrupts = <4 IRQ_TYPE_LEVEL_LOW>;
+		pinctrl-names = "default";
+		pinctrl-0 = <&pmic_int>;
+		reg = <0x1b>;
+		rockchip,system-power-controller;
+		wakeup-source;
+		#clock-cells = <1>;
+
+		vcc8-supply = <&vcc_18>;
+		vcc9-supply = <&vcc_io>;
+		vcc10-supply = <&vcc_io>;
+		vcc12-supply = <&vcc_io>;
+		vddio-supply = <&vccio_pmu>;
+
+		regulators {
+			vdd_cpu: DCDC_REG1 {
+				regulator-always-on;
+				regulator-boot-on;
+				regulator-min-microvolt = <750000>;
+				regulator-max-microvolt = <1300000>;
+				regulator-name = "vdd_arm";
+			};
+
+			vdd_gpu: DCDC_REG2 {
+				regulator-always-on;
+				regulator-boot-on;
+				regulator-min-microvolt = <850000>;
+				regulator-max-microvolt = <1250000>;
+				regulator-name = "vdd_gpu";
+			};
+
+			vcc_ddr: DCDC_REG3 {
+				regulator-always-on;
+				regulator-boot-on;
+				regulator-name = "vcc_ddr";
+			};
+
+			vcc_io: DCDC_REG4 {
+				regulator-always-on;
+				regulator-boot-on;
+				regulator-min-microvolt = <3300000>;
+				regulator-max-microvolt = <3300000>;
+				regulator-name = "vcc_io";
+			};
+
+			vccio_pmu: LDO_REG1 {
+				regulator-always-on;
+				regulator-boot-on;
+				regulator-min-microvolt = <3300000>;
+				regulator-max-microvolt = <3300000>;
+				regulator-name = "vccio_pmu";
+			};
+
+			vcc_tp: LDO_REG2 {
+				regulator-always-on;
+				regulator-boot-on;
+				regulator-min-microvolt = <3300000>;
+				regulator-max-microvolt = <3300000>;
+				regulator-name = "vcc_tp";
+			};
+
+			vdd_10: LDO_REG3 {
+				regulator-always-on;
+				regulator-boot-on;
+				regulator-min-microvolt = <1000000>;
+				regulator-max-microvolt = <1000000>;
+				regulator-name = "vdd_10";
+			};
+
+			vcc18_lcd: LDO_REG4 {
+				regulator-always-on;
+				regulator-boot-on;
+				regulator-min-microvolt = <1800000>;
+				regulator-max-microvolt = <1800000>;
+				regulator-name = "vcc18_lcd";
+			};
+
+			vccio_sd: LDO_REG5 {
+				regulator-always-on;
+				regulator-boot-on;
+				regulator-min-microvolt = <1800000>;
+				regulator-max-microvolt = <3300000>;
+				regulator-name = "vccio_sd";
+			};
+
+			vdd10_lcd: LDO_REG6 {
+				regulator-always-on;
+				regulator-boot-on;
+				regulator-min-microvolt = <1000000>;
+				regulator-max-microvolt = <1000000>;
+				regulator-name = "vdd10_lcd";
+			};
+
+			vcc_18: LDO_REG7 {
+				regulator-always-on;
+				regulator-boot-on;
+				regulator-min-microvolt = <1800000>;
+				regulator-max-microvolt = <1800000>;
+				regulator-name = "vcc_18";
+			};
+
+			vcca_codec: LDO_REG8 {
+				regulator-always-on;
+				regulator-boot-on;
+				regulator-min-microvolt = <3300000>;
+				regulator-max-microvolt = <3300000>;
+				regulator-name = "vcca_codec";
+			};
+
+			vcc_wl: SWITCH_REG1 {
+				regulator-always-on;
+				regulator-boot-on;
+				regulator-name = "vcc_wl";
+			};
+
+			vcc_lcd: SWITCH_REG2 {
+				regulator-always-on;
+				regulator-boot-on;
+				regulator-name = "vcc_lcd";
+			};
+		};
+	};
include/dt-bindings/clock/rockchip,rk808.h new file +11 -0
new file mode 100644
index 0000000..1a87343
@@ -0,0 +1,11 @@
+/*
+ * This header provides constants clk index RK808 pmic clkout
+ */
+#ifndef _CLK_ROCKCHIP_RK808
+#define _CLK_ROCKCHIP_RK808
+
+/* CLOCKOUT index */
+#define RK808_CLKOUT0		0
+#define RK808_CLKOUT1		1
+
+#endif
Signature · 6 lines
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reviewed-by on v7 1/5
#2 lore raw

Re: [PATCH v7 1/5] dt-bindings: Add RK808 device tree bindings document

Chris,

Quoted 45 lines · Chris Zhong

Add device tree bindings documentation and a header file for rockchip's RK808 pmic.

---

Changes in v7:
Advices by Mark Rutland
- modify description about clock-cells
- update the example

Changes in v6:
Advices by Mark Rutland
- add description about clock-cells
Advices by Doug
- modify description about regulator
- remove pinctrl description

Changes in v5:
Advices by Mark Brown
- add description about regulator valid name.
- add a header file "rockchip,rk808".

Changes in v4:
Advices by Doug
- add a "#clock-cells" propertiy
- update the example

Changes in v3: None
Changes in v2: None

 Documentation/devicetree/bindings/mfd/rk808.txt |  166 +++++++++++++++++++++++
 include/dt-bindings/clock/rockchip,rk808.h      |   11 ++
 2 files changed, 177 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/rk808.txt
 create mode 100644 include/dt-bindings/clock/rockchip,rk808.h
Documentation/devicetree/bindings/mfd/rk808.txt new file +0 -0
new file mode 100644
index 0000000..f8932ac

Documentation/devicetree/bindings/mfd/rk808.txt line 9

Quoted 9 lines
Documentation/devicetree/bindings/mfd/rk808.txt new file +9 -0
@@ -0,0 +1,166 @@
+RK808 Power Management Integrated Circuit
+
+Required properties:
+- compatible: "rockchip,rk808"
+- reg: I2C slave address
+- interrupt-parent: The parent interrupt controller.
+- interrupts: the interrupt outputs of the controller.
+- #clock-cells: from common clock binding; shall be set to 1 (multiple clock
+  outputs)

I think Mark Rutland was looking for something like:

- #clock-cells: from common clock binding; shall be set to 1 (multiple clock outputs). See <dt-bindings/clock/rockchip,rk808.h> for clock IDs.

Quoted 37 lines
Documentation/devicetree/bindings/mfd/rk808.txt new file +37 -0
+Optional properties:
+- clock-output-names: From common clock binding to override the
+  default output clock name
+- rockchip,system-power-controller: Telling whether or not this pmic is controlling
+  the system power.
+
+Regulators: All the regulators of RK808 to be instantiated shall be
+listed in a child node named 'regulators'. Each regulator is represented
+by a child node of the 'regulators' node.
+
+       regulator-name {
+               /* standard regulator bindings here */
+       };
+
+Following regulators of the RK808 PMIC block are supported. Note that
+the 'n' in regulator name, as in DCDC_REGn or LDOn, represents the DCDC or LDO
+number as described in RK808 datasheet.
+
+       - DCDC_REGn
+               - valid values for n are 1 to 4.
+       - LDO_REGn
+               - valid values for n are 1 to 8.
+       - SWITCH_REGn
+               - valid values for n are 1 to 2
+
+Standard regulator bindings are used inside regulator subnodes. Check
+  Documentation/devicetree/bindings/regulator/regulator.txt
+for more details
+
+Example:
+       rk808: pmic@1b {
+               compatible = "rockchip,rk808";
+               clock-output-names = "xin32k", "rk808-clkout2";
+               interrupt-parent = <&gpio0>;
+               interrupts = <4 IRQ_TYPE_LEVEL_LOW>;
+               pinctrl-names = "default";
+               pinctrl-0 = <&pmic_int>;

Documentation/devicetree/bindings/mfd/rk808.txt line 57

Quoted 10 lines
Documentation/devicetree/bindings/mfd/rk808.txt new file +10 -0
+               reg = <0x1b>;
+               rockchip,system-power-controller;
+               wakeup-source;
+               #clock-cells = <1>;
+
+               vcc8-supply = <&vcc_18>;
+               vcc9-supply = <&vcc_io>;
+               vcc10-supply = <&vcc_io>;
+               vcc12-supply = <&vcc_io>;
+               vddio-supply = <&vccio_pmu>;

Technically the "-supply" section shouldn't be here. I plan to add support for input supplies once you've landed your series. See
<https://chromium-review.googlesource.com/#/c/214596/> for a preview. Just leave the "-supply" section out for now.

Other than that, this looks great.

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

Reviewed-by on v7 1/5
#3 lore raw

Re: [PATCH v7 1/5] dt-bindings: Add RK808 device tree bindings document

In reply to Chris Zhong

Chris,

Quoted 45 lines · Chris Zhong

Add device tree bindings documentation and a header file for rockchip's RK808 pmic.

---

Changes in v7:
Advices by Mark Rutland
- modify description about clock-cells
- update the example

Changes in v6:
Advices by Mark Rutland
- add description about clock-cells
Advices by Doug
- modify description about regulator
- remove pinctrl description

Changes in v5:
Advices by Mark Brown
- add description about regulator valid name.
- add a header file "rockchip,rk808".

Changes in v4:
Advices by Doug
- add a "#clock-cells" propertiy
- update the example

Changes in v3: None
Changes in v2: None

 Documentation/devicetree/bindings/mfd/rk808.txt |  166 +++++++++++++++++++++++
 include/dt-bindings/clock/rockchip,rk808.h      |   11 ++
 2 files changed, 177 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/rk808.txt
 create mode 100644 include/dt-bindings/clock/rockchip,rk808.h
Documentation/devicetree/bindings/mfd/rk808.txt new file +0 -0
new file mode 100644
index 0000000..f8932ac

Documentation/devicetree/bindings/mfd/rk808.txt line 9

Quoted 9 lines
Documentation/devicetree/bindings/mfd/rk808.txt new file +9 -0
@@ -0,0 +1,166 @@
+RK808 Power Management Integrated Circuit
+
+Required properties:
+- compatible: "rockchip,rk808"
+- reg: I2C slave address
+- interrupt-parent: The parent interrupt controller.
+- interrupts: the interrupt outputs of the controller.
+- #clock-cells: from common clock binding; shall be set to 1 (multiple clock
+  outputs)

I think Mark Rutland was looking for something like:

- #clock-cells: from common clock binding; shall be set to 1 (multiple clock outputs). See <dt-bindings/clock/rockchip,rk808.h> for clock IDs.

Quoted 37 lines
Documentation/devicetree/bindings/mfd/rk808.txt new file +37 -0
+Optional properties:
+- clock-output-names: From common clock binding to override the
+  default output clock name
+- rockchip,system-power-controller: Telling whether or not this pmic is controlling
+  the system power.
+
+Regulators: All the regulators of RK808 to be instantiated shall be
+listed in a child node named 'regulators'. Each regulator is represented
+by a child node of the 'regulators' node.
+
+       regulator-name {
+               /* standard regulator bindings here */
+       };
+
+Following regulators of the RK808 PMIC block are supported. Note that
+the 'n' in regulator name, as in DCDC_REGn or LDOn, represents the DCDC or LDO
+number as described in RK808 datasheet.
+
+       - DCDC_REGn
+               - valid values for n are 1 to 4.
+       - LDO_REGn
+               - valid values for n are 1 to 8.
+       - SWITCH_REGn
+               - valid values for n are 1 to 2
+
+Standard regulator bindings are used inside regulator subnodes. Check
+  Documentation/devicetree/bindings/regulator/regulator.txt
+for more details
+
+Example:
+       rk808: pmic@1b {
+               compatible = "rockchip,rk808";
+               clock-output-names = "xin32k", "rk808-clkout2";
+               interrupt-parent = <&gpio0>;
+               interrupts = <4 IRQ_TYPE_LEVEL_LOW>;
+               pinctrl-names = "default";
+               pinctrl-0 = <&pmic_int>;

Documentation/devicetree/bindings/mfd/rk808.txt line 57

Quoted 10 lines
Documentation/devicetree/bindings/mfd/rk808.txt new file +10 -0
+               reg = <0x1b>;
+               rockchip,system-power-controller;
+               wakeup-source;
+               #clock-cells = <1>;
+
+               vcc8-supply = <&vcc_18>;
+               vcc9-supply = <&vcc_io>;
+               vcc10-supply = <&vcc_io>;
+               vcc12-supply = <&vcc_io>;
+               vddio-supply = <&vccio_pmu>;

Technically the "-supply" section shouldn't be here. I plan to add support for input supplies once you've landed your series. See
<https://chromium-review.googlesource.com/#/c/214596/> for a preview. Just leave the "-supply" section out for now.

Other than that, this looks great.

Reviewed-by on v7 1/5
#4 lore raw

Re: [PATCH v7 1/5] dt-bindings: Add RK808 device tree bindings document

In reply to Chris Zhong

Chris,

Quoted 45 lines · Chris Zhong

Add device tree bindings documentation and a header file for rockchip's RK808 pmic.

---

Changes in v7:
Advices by Mark Rutland
- modify description about clock-cells
- update the example

Changes in v6:
Advices by Mark Rutland
- add description about clock-cells
Advices by Doug
- modify description about regulator
- remove pinctrl description

Changes in v5:
Advices by Mark Brown
- add description about regulator valid name.
- add a header file "rockchip,rk808".

Changes in v4:
Advices by Doug
- add a "#clock-cells" propertiy
- update the example

Changes in v3: None
Changes in v2: None

 Documentation/devicetree/bindings/mfd/rk808.txt |  166 +++++++++++++++++++++++
 include/dt-bindings/clock/rockchip,rk808.h      |   11 ++
 2 files changed, 177 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/rk808.txt
 create mode 100644 include/dt-bindings/clock/rockchip,rk808.h
Documentation/devicetree/bindings/mfd/rk808.txt new file +0 -0
new file mode 100644
index 0000000..f8932ac

Documentation/devicetree/bindings/mfd/rk808.txt line 9

Quoted 9 lines
Documentation/devicetree/bindings/mfd/rk808.txt new file +9 -0
@@ -0,0 +1,166 @@
+RK808 Power Management Integrated Circuit
+
+Required properties:
+- compatible: "rockchip,rk808"
+- reg: I2C slave address
+- interrupt-parent: The parent interrupt controller.
+- interrupts: the interrupt outputs of the controller.
+- #clock-cells: from common clock binding; shall be set to 1 (multiple clock
+  outputs)

I think Mark Rutland was looking for something like:

- #clock-cells: from common clock binding; shall be set to 1 (multiple clock outputs). See <dt-bindings/clock/rockchip,rk808.h> for clock IDs.

Quoted 37 lines
Documentation/devicetree/bindings/mfd/rk808.txt new file +37 -0
+Optional properties:
+- clock-output-names: From common clock binding to override the
+  default output clock name
+- rockchip,system-power-controller: Telling whether or not this pmic is controlling
+  the system power.
+
+Regulators: All the regulators of RK808 to be instantiated shall be
+listed in a child node named 'regulators'. Each regulator is represented
+by a child node of the 'regulators' node.
+
+       regulator-name {
+               /* standard regulator bindings here */
+       };
+
+Following regulators of the RK808 PMIC block are supported. Note that
+the 'n' in regulator name, as in DCDC_REGn or LDOn, represents the DCDC or LDO
+number as described in RK808 datasheet.
+
+       - DCDC_REGn
+               - valid values for n are 1 to 4.
+       - LDO_REGn
+               - valid values for n are 1 to 8.
+       - SWITCH_REGn
+               - valid values for n are 1 to 2
+
+Standard regulator bindings are used inside regulator subnodes. Check
+  Documentation/devicetree/bindings/regulator/regulator.txt
+for more details
+
+Example:
+       rk808: pmic@1b {
+               compatible = "rockchip,rk808";
+               clock-output-names = "xin32k", "rk808-clkout2";
+               interrupt-parent = <&gpio0>;
+               interrupts = <4 IRQ_TYPE_LEVEL_LOW>;
+               pinctrl-names = "default";
+               pinctrl-0 = <&pmic_int>;

Documentation/devicetree/bindings/mfd/rk808.txt line 57

Quoted 10 lines
Documentation/devicetree/bindings/mfd/rk808.txt new file +10 -0
+               reg = <0x1b>;
+               rockchip,system-power-controller;
+               wakeup-source;
+               #clock-cells = <1>;
+
+               vcc8-supply = <&vcc_18>;
+               vcc9-supply = <&vcc_io>;
+               vcc10-supply = <&vcc_io>;
+               vcc12-supply = <&vcc_io>;
+               vddio-supply = <&vccio_pmu>;

Technically the "-supply" section shouldn't be here. I plan to add support for input supplies once you've landed your series. See
<https://chromium-review.googlesource.com/#/c/214596/> for a preview. Just leave the "-supply" section out for now.

Other than that, this looks great.

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

#5 lore raw

PATCH v7 2/5 MFD: RK808: Add new mfd driver for RK808

In reply to Chris Zhong

The RK808 chip is a power management IC for multimedia and handheld devices. It contains the following components:

- Regulators
- RTC
- Clkout

The RK808 core driver is registered as a platform driver and provides communication through I2C with the host device for the different components.

---

Changes in v7:
Adviced by Lee Jones
- coding style
- remove rk808_pre_init function
Adviced by Doug
- add "&& OF" to the dependencies
- add .init_ack_masked = true in rk808_irq_chip

Changes in v6:
Adviced by Lee Jones in v2
- rk808_i2c_client instead of g_rk808
- remove pdata form struct rk808

Changes in v5: None
Changes in v4:
Adviced by Lee Jones in v2
- modify the description in Kconfig
- remove some unnecessary header files
- remove dev from struct rk808
- use enum for define RK808_ID...

Changes in v3:
- fix compile err

Changes in v2:
Adviced by Mark Browm:
- use defines for register setting value
- remove rtc alarm disable in shutdown
- remove while(1) in shutdown
- remove read 0x2f in probe

 drivers/mfd/Kconfig       |   13 +++
 drivers/mfd/Makefile      |    1 +
 drivers/mfd/rk808.c       |  243 +++++++++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/rk808.h |  196 ++++++++++++++++++++++++++++++++++++
 4 files changed, 453 insertions(+)
 create mode 100644 drivers/mfd/rk808.c
 create mode 100644 include/linux/mfd/rk808.h
drivers/mfd/Kconfig +13 -0
index de5abf2..4097793 100644
@@ -582,6 +582,19 @@ config MFD_RC5T583
 	  Additional drivers must be enabled in order to use the
 	  different functionality of the device.
 
+config MFD_RK808
+	tristate "Rockchip RK808 Power Management chip"
+	depends on I2C && OF
+	select MFD_CORE
+	select REGMAP_I2C
+	select REGMAP_IRQ
+	help
+	  If you say yes here you get support for the RK808
+	  Power Management chips.
+	  This driver provides common support for accessing the device
+	  through I2C interface. The device supports multiple sub-devices
+	  including interrupts, RTC, LDO & DCDC regulators, and onkey.
+
 config MFD_SEC_CORE
 	bool "SAMSUNG Electronics PMIC Series Support"
 	depends on I2C=y
drivers/mfd/Makefile +1 -0
index f001487..dbc28e7 100644
@@ -160,6 +160,7 @@ obj-$(CONFIG_MFD_INTEL_MSIC)	+= intel_msic.o
 obj-$(CONFIG_MFD_PALMAS)	+= palmas.o
 obj-$(CONFIG_MFD_VIPERBOARD)    += viperboard.o
 obj-$(CONFIG_MFD_RC5T583)	+= rc5t583.o rc5t583-irq.o
+obj-$(CONFIG_MFD_RK808)		+= rk808.o
 obj-$(CONFIG_MFD_SEC_CORE)	+= sec-core.o sec-irq.o
 obj-$(CONFIG_MFD_SYSCON)	+= syscon.o
 obj-$(CONFIG_MFD_LM3533)	+= lm3533-core.o lm3533-ctrlbank.o
drivers/mfd/rk808.c new file +243 -0

243 lines not on this page · raw message

include/linux/mfd/rk808.h new file +196 -0

196 lines not on this page · raw message

Signature · 1 line
1.7.9.5
Acked-by on v7 2/5
#6 lore raw

Re: [PATCH v7 2/5] MFD: RK808: Add new mfd driver for RK808

Quoted 7 lines · Chris Zhong

The RK808 chip is a power management IC for multimedia and handheld devices. It contains the following components:

- Regulators
- RTC
- Clkout

Quoted 6 lines

The RK808 core driver is registered as a platform driver and provides communication through I2C with the host device for the different components.

Couple of nits. Once fixed you can apply my:

[...]

Quoted 4 lines

+/*
+ * MFD core driver for Rockchip RK808
+ *
+ * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd

Author?

Quoted 9 lines

+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ */

[...]

drivers/mfd/rk808.c line 143

Quoted 8 lines
drivers/mfd/rk808.c new file +8 -0
+static int rk808_probe(struct i2c_client *client,
+		       const struct i2c_device_id *id)
+{
+	int i;
+	int ret;
+	int pm_off = 0;
+	struct rk808 *rk808;
+	struct device_node *np = client->dev.of_node;

Reverse these declarations please, structs at the top etc.

[...]

drivers/mfd/rk808.c line 180

Quoted 2 lines
drivers/mfd/rk808.c new file +2 -0
+	rk808->i2c = client;
+	i2c_set_clientdata(client, rk808);

'\n' here.

drivers/mfd/rk808.c line 189

Quoted 9 lines
drivers/mfd/rk808.c new file +9 -0
+	ret = mfd_add_devices(&client->dev, -1,
+			      rk808s, ARRAY_SIZE(rk808s),
+			      NULL, 0, regmap_irq_get_domain(rk808->irq_data));
+	if (ret) {
+		dev_err(&client->dev, "failed to add MFD devices %d\n", ret);
+		goto err_irq;
+	}
+
+	if (np) {

There has to be an 'np'. The driver depends on OF.

Quoted 14 lines
drivers/mfd/rk808.c new file +14 -0
+		pm_off = of_property_read_bool(np,
+					"rockchip,system-power-controller");
+		if (pm_off && !pm_power_off) {
+			rk808_i2c_client = client;
+			pm_power_off = rk808_device_shutdown;
+		}
+	}
+
+	return 0;
+
+err_irq:
+	regmap_del_irq_chip(client->irq, rk808->irq_data);
+	return ret;
+}

[...]

drivers/mfd/rk808.c line 231

Quoted 4 lines
drivers/mfd/rk808.c new file +4 -0
+static struct i2c_driver rk808_i2c_driver = {
+	.driver = {
+		.name = "rk808",
+		.of_match_table = of_match_ptr(rk808_of_match),

No need to use of_match_ptr() now that you depend on OF.

Quoted 12 lines
drivers/mfd/rk808.c new file +12 -0
+	},
+	.probe    = rk808_probe,
+	.remove   = rk808_remove,
+	.id_table = rk808_ids,
+};
+
+module_i2c_driver(rk808_i2c_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Chris Zhong <[email protected]>");
+MODULE_AUTHOR("Zhang Qing <[email protected]>");
+MODULE_DESCRIPTION("RK808 PMIC driver");

[...]

Signature · 8 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#7 lore raw

Re: [PATCH v7 2/5] MFD: RK808: Add new mfd driver for RK808

Hi,

Quoted 20 lines · Lee Jones
Quoted 7 lines · Chris Zhong

The RK808 chip is a power management IC for multimedia and handheld devices. It contains the following components:

- Regulators
- RTC
- Clkout

Quoted 6 lines

The RK808 core driver is registered as a platform driver and provides communication through I2C with the host device for the different components.

Couple of nits. Once fixed you can apply my:

Quoted 8 lines

[...]

Quoted 4 lines

+/*
+ * MFD core driver for Rockchip RK808
+ *
+ * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd

Author?

I asked Chris to remove the author in my response to an earlier version since it's at the bottom (MODULE_AUTHOR) and it seems extra duplication. You are the boss though, so if it should go both places then Chris should add this back. Sorry for the bad advice, Chris.

-Doug

#8 lore raw

Re: [PATCH v7 2/5] MFD: RK808: Add new mfd driver for RK808

Quoted 28 lines · Doug Anderson
Quoted 27 lines · Lee Jones
Quoted 7 lines · Chris Zhong

The RK808 chip is a power management IC for multimedia and handheld devices. It contains the following components:

- Regulators
- RTC
- Clkout

Quoted 6 lines

The RK808 core driver is registered as a platform driver and provides communication through I2C with the host device for the different components.

Couple of nits. Once fixed you can apply my:

[...]

Quoted 4 lines

+/*
+ * MFD core driver for Rockchip RK808
+ *
+ * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd

Quoted 6 lines
Quoted 1 line

Author?

I asked Chris to remove the author in my response to an earlier version since it's at the bottom (MODULE_AUTHOR) and it seems extra duplication. You are the boss though, so if it should go both places then Chris should add this back. Sorry for the bad advice, Chris.

Yes, both places please. They do different things.

Signature · 8 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#9 lore raw

PATCH v7 3/5 RTC: RK808: add RTC driver for RK808

In reply to Chris Zhong

Adding RTC driver for supporting RTC device present inside RK808 PMIC.

---

Changes in v7:
Adviced by doug
- read rtc time from shadowed registers
Adviced by Dmitry
- use CONFIG_PM_SLEEP replace CONFIG_PM
- use SIMPLE_DEV_PM_OPS replace dev_pm_ops
- fix dev_warn
- coding style
Adviced by Heiko
- remove rtc_ctl

Changes in v6:
Adviced by doug
- move RTC_READSEL setting into probe

Changes in v5:
- fixed a bug about set_time failed

Changes in v4:
- use &client->dev replace rk808->dev

Changes in v3: None
Changes in v2:
Adviced by javier.martinez
- Add a separate clock driver, rather than in RTC driver

 drivers/rtc/Kconfig     |   10 ++
 drivers/rtc/Makefile    |    1 +
 drivers/rtc/rtc-rk808.c |  419 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 430 insertions(+)
 create mode 100644 drivers/rtc/rtc-rk808.c
drivers/rtc/Kconfig +10 -0
index a168e96..aeab9d9 100644
@@ -288,6 +288,16 @@ config RTC_DRV_MAX77686
 	  This driver can also be built as a module. If so, the module
 	  will be called rtc-max77686.
 
+config RTC_DRV_RK808
+	tristate "Rockchip RK808 RTC"
+	depends on MFD_RK808
+	help
+	  If you say yes here you will get support for the
+	  RTC of RK808 PMIC.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called rk808-rtc.
+
 config RTC_DRV_RS5C372
 	tristate "Ricoh R2025S/D, RS5C372A/B, RV5C386, RV5C387A"
 	help
drivers/rtc/Makefile +1 -0
index 56f061c..91fe4647 100644
@@ -109,6 +109,7 @@ obj-$(CONFIG_RTC_DRV_PUV3)	+= rtc-puv3.o
 obj-$(CONFIG_RTC_DRV_PXA)	+= rtc-pxa.o
 obj-$(CONFIG_RTC_DRV_R9701)	+= rtc-r9701.o
 obj-$(CONFIG_RTC_DRV_RC5T583)	+= rtc-rc5t583.o
+obj-$(CONFIG_RTC_DRV_RK808)	+= rtc-rk808.o
 obj-$(CONFIG_RTC_DRV_RP5C01)	+= rtc-rp5c01.o
 obj-$(CONFIG_RTC_DRV_RS5C313)	+= rtc-rs5c313.o
 obj-$(CONFIG_RTC_DRV_RS5C348)	+= rtc-rs5c348.o
drivers/rtc/rtc-rk808.c new file +419 -0

419 lines not on this page · raw message

Signature · 6 lines
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#10 lore raw

Re: [PATCH v7 3/5] RTC: RK808: add RTC driver for RK808

Chris,

Quoted 163 lines · Chris Zhong

Adding RTC driver for supporting RTC device present inside RK808 PMIC.

---

Changes in v7:
Adviced by doug
- read rtc time from shadowed registers
Adviced by Dmitry
- use CONFIG_PM_SLEEP replace CONFIG_PM
- use SIMPLE_DEV_PM_OPS replace dev_pm_ops
- fix dev_warn
- coding style
Adviced by Heiko
- remove rtc_ctl

Changes in v6:
Adviced by doug
- move RTC_READSEL setting into probe

Changes in v5:
- fixed a bug about set_time failed

Changes in v4:
- use &client->dev replace rk808->dev

Changes in v3: None
Changes in v2:
Adviced by javier.martinez
- Add a separate clock driver, rather than in RTC driver

 drivers/rtc/Kconfig     |   10 ++
 drivers/rtc/Makefile    |    1 +
 drivers/rtc/rtc-rk808.c |  419 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 430 insertions(+)
 create mode 100644 drivers/rtc/rtc-rk808.c
drivers/rtc/Kconfig +10 -0
index a168e96..aeab9d9 100644
@@ -288,6 +288,16 @@ config RTC_DRV_MAX77686
          This driver can also be built as a module. If so, the module
          will be called rtc-max77686.
 
+config RTC_DRV_RK808
+       tristate "Rockchip RK808 RTC"
+       depends on MFD_RK808
+       help
+         If you say yes here you will get support for the
+         RTC of RK808 PMIC.
+
+         This driver can also be built as a module. If so, the module
+         will be called rk808-rtc.
+
 config RTC_DRV_RS5C372
        tristate "Ricoh R2025S/D, RS5C372A/B, RV5C386, RV5C387A"
        help
drivers/rtc/Makefile +1 -0
index 56f061c..91fe4647 100644
@@ -109,6 +109,7 @@ obj-$(CONFIG_RTC_DRV_PUV3)  += rtc-puv3.o
 obj-$(CONFIG_RTC_DRV_PXA)      += rtc-pxa.o
 obj-$(CONFIG_RTC_DRV_R9701)    += rtc-r9701.o
 obj-$(CONFIG_RTC_DRV_RC5T583)  += rtc-rc5t583.o
+obj-$(CONFIG_RTC_DRV_RK808)    += rtc-rk808.o
 obj-$(CONFIG_RTC_DRV_RP5C01)   += rtc-rp5c01.o
 obj-$(CONFIG_RTC_DRV_RS5C313)  += rtc-rs5c313.o
 obj-$(CONFIG_RTC_DRV_RS5C348)  += rtc-rs5c348.o
drivers/rtc/rtc-rk808.c new file +85 -0
new file mode 100644
index 0000000..3de78e8
@@ -0,0 +1,419 @@
+/*
+ * RTC driver for Rockchip RK808
+ *
+ * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/rtc.h>
+#include <linux/bcd.h>
+#include <linux/mfd/rk808.h>
+#include <linux/platform_device.h>
+#include <linux/i2c.h>
+
+/* RTC_CTRL_REG bitfields */
+#define BIT_RTC_CTRL_REG_STOP_RTC_M            BIT(0)
+
+/* RK808 has a shadowed register for saving a "frozen" RTC time.
+ * When user setting "GET_TIME" to 1, the time will save in this shadowed
+ * register. If set "READSEL" to 1, user read rtc time register, actually
+ * get the time of that moment. If we need the real time, clr this bit.
+ */
+#define BIT_RTC_CTRL_REG_RTC_GET_TIME          BIT(6)
+#define BIT_RTC_CTRL_REG_RTC_READSEL_M         BIT(7)
+#define BIT_RTC_INTERRUPTS_REG_IT_ALARM_M      BIT(3)
+#define RTC_STATUS_MASK                0xFE
+
+#define SECONDS_REG_MSK                0x7F
+#define MINUTES_REG_MAK                0x7F
+#define HOURS_REG_MSK          0x3F
+#define DAYS_REG_MSK           0x3F
+#define MONTHS_REG_MSK         0x1F
+#define YEARS_REG_MSK          0xFF
+#define WEEKS_REG_MSK          0x7
+
+/* REG_SECONDS_REG through REG_YEARS_REG is how many registers? */
+
+#define NUM_TIME_REGS  (RK808_WEEKS_REG - RK808_SECONDS_REG + 1)
+#define NUM_ALARM_REGS (RK808_ALARM_YEARS_REG - RK808_ALARM_SECONDS_REG + 1)
+
+struct rk808_rtc {
+       struct rk808 *rk808;
+       struct rtc_device *rtc;
+       int irq;
+};
+
+/* Read current time and date in RTC */
+static int rk808_rtc_readtime(struct device *dev, struct rtc_time *tm)
+{
+       struct rk808_rtc *rk808_rtc = dev_get_drvdata(dev);
+       struct rk808 *rk808 = rk808_rtc->rk808;
+       u8 rtc_data[NUM_TIME_REGS];
+       int ret;
+
+       ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
+                                BIT_RTC_CTRL_REG_RTC_GET_TIME,
+                                BIT_RTC_CTRL_REG_RTC_GET_TIME);
+       if (ret) {
+               dev_err(dev, "Failed to update bits rtc_ctrl: %d\n", ret);
+               return ret;
+       }
+
+       ret = regmap_bulk_read(rk808->regmap, RK808_SECONDS_REG,
+                              rtc_data, NUM_TIME_REGS);
+       if (ret) {
+               dev_err(dev, "Failed to bulk read rtc_data: %d\n", ret);
+               goto reset_read_sel;
+       }
+
+       tm->tm_sec = bcd2bin(rtc_data[0] & SECONDS_REG_MSK);
+       tm->tm_min = bcd2bin(rtc_data[1] & MINUTES_REG_MAK);
+       tm->tm_hour = bcd2bin(rtc_data[2] & HOURS_REG_MSK);
+       tm->tm_mday = bcd2bin(rtc_data[3] & DAYS_REG_MSK);
+       tm->tm_mon = (bcd2bin(rtc_data[4] & MONTHS_REG_MSK)) - 1;
+       tm->tm_year = (bcd2bin(rtc_data[5] & YEARS_REG_MSK)) + 100;
+       tm->tm_wday = bcd2bin(rtc_data[6] & WEEKS_REG_MSK);

drivers/rtc/rtc-rk808.c line 95

Quoted 10 lines
drivers/rtc/rtc-rk808.c new file +10 -0
+       dev_dbg(dev, "RTC date/time %4d-%02d-%02d(%d) %02d:%02d:%02d\n",
+               1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday,
+               tm->tm_wday, tm->tm_hour , tm->tm_min, tm->tm_sec);
+
+reset_read_sel:
+       ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
+                                BIT_RTC_CTRL_REG_RTC_GET_TIME, 0);
+       if (ret)
+               dev_err(dev, "Failed to update bits rtc_ctrl: %d\n", ret);
+       return ret;

Nit: blank line before "return ret;"

Quoted 245 lines
drivers/rtc/rtc-rk808.c new file +245 -0
+}
+
+/* Set current time and date in RTC */
+static int rk808_rtc_set_time(struct device *dev, struct rtc_time *tm)
+{
+       struct rk808_rtc *rk808_rtc = dev_get_drvdata(dev);
+       struct rk808 *rk808 = rk808_rtc->rk808;
+       u8 rtc_data[NUM_TIME_REGS];
+       int ret;
+
+       rtc_data[0] = bin2bcd(tm->tm_sec);
+       rtc_data[1] = bin2bcd(tm->tm_min);
+       rtc_data[2] = bin2bcd(tm->tm_hour);
+       rtc_data[3] = bin2bcd(tm->tm_mday);
+       rtc_data[4] = bin2bcd(tm->tm_mon + 1);
+       rtc_data[5] = bin2bcd(tm->tm_year - 100);
+       rtc_data[6] = bin2bcd(tm->tm_wday);
+       dev_dbg(dev, "set RTC date/time %4d-%02d-%02d(%d) %02d:%02d:%02d\n",
+               1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday,
+               tm->tm_wday, tm->tm_hour , tm->tm_min, tm->tm_sec);
+
+       /* Stop RTC while updating the RTC registers */
+       ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
+                                BIT_RTC_CTRL_REG_STOP_RTC_M,
+                                BIT_RTC_CTRL_REG_STOP_RTC_M);
+       if (ret) {
+               dev_err(dev, "Failed to update RTC control: %d\n", ret);
+               return ret;
+       }
+
+       ret = regmap_bulk_write(rk808->regmap, RK808_SECONDS_REG,
+                               rtc_data, NUM_TIME_REGS);
+       if (ret) {
+               dev_err(dev, "Failed to bull write rtc_data: %d\n", ret);
+               return ret;
+       }
+       /* Start RTC again */
+       ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
+                                BIT_RTC_CTRL_REG_STOP_RTC_M, 0);
+       if (ret) {
+               dev_err(dev, "Failed to update RTC control: %d\n", ret);
+               return ret;
+       }
+       return 0;
+}
+
+/* Read alarm time and date in RTC */
+static int rk808_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
+{
+       struct rk808_rtc *rk808_rtc = dev_get_drvdata(dev);
+       struct rk808 *rk808 = rk808_rtc->rk808;
+       u8 alrm_data[NUM_ALARM_REGS];
+       uint32_t int_reg;
+       int ret;
+
+       ret = regmap_bulk_read(rk808->regmap, RK808_ALARM_SECONDS_REG,
+                              alrm_data, NUM_ALARM_REGS);
+
+       alrm->time.tm_sec = bcd2bin(alrm_data[0] & SECONDS_REG_MSK);
+       alrm->time.tm_min = bcd2bin(alrm_data[1] & MINUTES_REG_MAK);
+       alrm->time.tm_hour = bcd2bin(alrm_data[2] & HOURS_REG_MSK);
+       alrm->time.tm_mday = bcd2bin(alrm_data[3] & DAYS_REG_MSK);
+       alrm->time.tm_mon = (bcd2bin(alrm_data[4] & MONTHS_REG_MSK)) - 1;
+       alrm->time.tm_year = (bcd2bin(alrm_data[5] & YEARS_REG_MSK)) + 100;
+
+       ret = regmap_read(rk808->regmap, RK808_RTC_INT_REG, &int_reg);
+       if (ret) {
+               dev_err(dev, "Failed to read RTC INT REG: %d\n", ret);
+               return ret;
+       }
+
+       dev_dbg(dev, "alrm read RTC date/time %4d-%02d-%02d(%d) %02d:%02d:%02d\n",
+               1900 + alrm->time.tm_year, alrm->time.tm_mon + 1,
+               alrm->time.tm_mday, alrm->time.tm_wday, alrm->time.tm_hour,
+               alrm->time.tm_min, alrm->time.tm_sec);
+
+       alrm->enabled = (int_reg & BIT_RTC_INTERRUPTS_REG_IT_ALARM_M) ? 1 : 0;
+
+       return 0;
+}
+
+static int rk808_rtc_stop_alarm(struct rk808_rtc *rk808_rtc)
+{
+       struct rk808 *rk808 = rk808_rtc->rk808;
+       int ret;
+
+       ret = regmap_update_bits(rk808->regmap, RK808_RTC_INT_REG,
+                                BIT_RTC_INTERRUPTS_REG_IT_ALARM_M, 0);
+
+       return ret;
+}
+
+static int rk808_rtc_start_alarm(struct rk808_rtc *rk808_rtc)
+{
+       struct rk808 *rk808 = rk808_rtc->rk808;
+       int ret;
+
+       ret = regmap_update_bits(rk808->regmap, RK808_RTC_INT_REG,
+                                BIT_RTC_INTERRUPTS_REG_IT_ALARM_M,
+                                BIT_RTC_INTERRUPTS_REG_IT_ALARM_M);
+
+       return ret;
+}
+
+static int rk808_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
+{
+       struct rk808_rtc *rk808_rtc = dev_get_drvdata(dev);
+       struct rk808 *rk808 = rk808_rtc->rk808;
+       u8 alrm_data[NUM_ALARM_REGS];
+       int ret;
+
+       ret = rk808_rtc_stop_alarm(rk808_rtc);
+       if (ret) {
+               dev_err(dev, "Failed to stop alarm: %d\n", ret);
+               return ret;
+       }
+       dev_dbg(dev, "alrm set RTC date/time %4d-%02d-%02d(%d) %02d:%02d:%02d\n",
+               1900 + alrm->time.tm_year, alrm->time.tm_mon + 1,
+               alrm->time.tm_mday, alrm->time.tm_wday, alrm->time.tm_hour,
+               alrm->time.tm_min, alrm->time.tm_sec);
+
+       alrm_data[0] = bin2bcd(alrm->time.tm_sec);
+       alrm_data[1] = bin2bcd(alrm->time.tm_min);
+       alrm_data[2] = bin2bcd(alrm->time.tm_hour);
+       alrm_data[3] = bin2bcd(alrm->time.tm_mday);
+       alrm_data[4] = bin2bcd(alrm->time.tm_mon + 1);
+       alrm_data[5] = bin2bcd(alrm->time.tm_year - 100);
+
+       ret = regmap_bulk_write(rk808->regmap, RK808_ALARM_SECONDS_REG,
+                               alrm_data, NUM_ALARM_REGS);
+       if (ret) {
+               dev_err(dev, "Failed to bulk write: %d\n", ret);
+               return ret;
+       }
+       if (alrm->enabled) {
+               ret = rk808_rtc_start_alarm(rk808_rtc);
+               if (ret) {
+                       dev_err(dev, "Failed to start alarm: %d\n", ret);
+                       return ret;
+               }
+       }
+       return 0;
+}
+
+static int rk808_rtc_alarm_irq_enable(struct device *dev,
+                                     unsigned int enabled)
+{
+       struct rk808_rtc *rk808_rtc = dev_get_drvdata(dev);
+
+       if (enabled)
+               return rk808_rtc_start_alarm(rk808_rtc);
+
+       return rk808_rtc_stop_alarm(rk808_rtc);
+}
+
+/*
+ * We will just handle setting the frequency and make use the framework for
+ * reading the periodic interupts.
+ *
+ * @freq: Current periodic IRQ freq:
+ * bit 0: every second
+ * bit 1: every minute
+ * bit 2: every hour
+ * bit 3: every day
+ */
+static irqreturn_t rk808_alarm_irq(int irq, void *data)
+{
+       struct rk808_rtc *rk808_rtc = data;
+       struct rk808 *rk808 = rk808_rtc->rk808;
+       struct i2c_client *client = rk808->i2c;
+       int ret;
+
+       ret = regmap_write(rk808->regmap, RK808_RTC_STATUS_REG,
+                          RTC_STATUS_MASK);
+       if (ret) {
+               dev_err(&client->dev,
+                       "%s:Failed to update RTC status: %d\n", __func__, ret);
+               return ret;
+       }
+
+       rtc_update_irq(rk808_rtc->rtc, 1, RTC_IRQF | RTC_AF);
+       dev_dbg(&client->dev,
+                "%s:irq=%d\n", __func__, irq);
+       return IRQ_HANDLED;
+}
+
+static const struct rtc_class_ops rk808_rtc_ops = {
+       .read_time = rk808_rtc_readtime,
+       .set_time = rk808_rtc_set_time,
+       .read_alarm = rk808_rtc_readalarm,
+       .set_alarm = rk808_rtc_setalarm,
+       .alarm_irq_enable = rk808_rtc_alarm_irq_enable,
+};
+
+#ifdef CONFIG_PM_SLEEP
+/* Turn off the alarm if it should not be a wake source. */
+static int rk808_rtc_suspend(struct device *dev)
+{
+       struct platform_device *pdev = to_platform_device(dev);
+       struct rk808_rtc *rk808_rtc = dev_get_drvdata(&pdev->dev);
+
+       if (device_may_wakeup(dev))
+               enable_irq_wake(rk808_rtc->irq);
+
+       return 0;
+}
+
+/* Enable the alarm if it should be enabled (in case it was disabled to
+ * prevent use as a wake source).
+ */
+static int rk808_rtc_resume(struct device *dev)
+{
+       struct platform_device *pdev = to_platform_device(dev);
+       struct rk808_rtc *rk808_rtc = dev_get_drvdata(&pdev->dev);
+
+       if (device_may_wakeup(dev))
+               disable_irq_wake(rk808_rtc->irq);
+
+       return 0;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(rk808_rtc_pm_ops,
+       rk808_rtc_suspend, rk808_rtc_resume);
+
+/* 2014.1.1 12:00:00 Saturday */
+struct rtc_time tm_def = {
+                       .tm_wday = 6,
+                       .tm_year = 114,
+                       .tm_mon = 0,
+                       .tm_mday = 1,
+                       .tm_hour = 12,
+                       .tm_min = 0,
+                       .tm_sec = 0,
+};
+
+static int rk808_rtc_probe(struct platform_device *pdev)
+{
+       struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent);
+       struct rk808_rtc *rk808_rtc;
+       struct rtc_time tm;
+       int ret;
+
+       rk808_rtc = devm_kzalloc(&pdev->dev, sizeof(*rk808_rtc), GFP_KERNEL);
+       if (rk808_rtc == NULL)

drivers/rtc/rtc-rk808.c line 350

Quoted 10 lines
drivers/rtc/rtc-rk808.c new file +10 -0
+               return -ENOMEM;
+
+       platform_set_drvdata(pdev, rk808_rtc);
+       rk808_rtc->rk808 = rk808;
+
+       /* start rtc running by default, and use shadowed timer. */
+       ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
+                                BIT_RTC_CTRL_REG_STOP_RTC_M |
+                                BIT_RTC_CTRL_REG_RTC_READSEL_M,
+                                BIT_RTC_CTRL_REG_RTC_READSEL_M);

I think this should still be setting to 0, not to BIT_RTC_CTRL_REG_RTC_READSEL_M. Otherwise the first read of the time will return that time that was frozen at probe time, right? AKA: if probe happens at 11:00:00 and then we read the time at 11:00:05 we'll still read 11:00:00 the first time.

Quoted 31 lines
drivers/rtc/rtc-rk808.c new file +31 -0
+       if (ret) {
+               dev_err(&pdev->dev,
+                       "Failed to update RTC control: %d\n", ret);
+               return ret;
+       }
+
+       ret = regmap_write(rk808->regmap, RK808_RTC_STATUS_REG,
+                          RTC_STATUS_MASK);
+       if (ret) {
+               dev_err(&pdev->dev,
+                       "Failed to write RTC status: %d\n", ret);
+                       return ret;
+       }
+
+       /* set init time */
+       ret = rk808_rtc_readtime(&pdev->dev, &tm);
+       if (ret) {
+               dev_err(&pdev->dev, "Failed to read RTC time\n");
+               return ret;
+       }
+       ret = rtc_valid_tm(&tm);
+       if (ret) {
+               dev_warn(&pdev->dev, "invalid date/time and init time\n");
+               rk808_rtc_set_time(&pdev->dev, &tm_def);
+       }
+
+       device_init_wakeup(&pdev->dev, 1);
+
+       rk808_rtc->rtc = devm_rtc_device_register(&pdev->dev, "rk808-rtc",
+                                                 &rk808_rtc_ops, THIS_MODULE);
+       if (IS_ERR(rk808_rtc->rtc)) {

drivers/rtc/rtc-rk808.c line 391

Quoted 10 lines
drivers/rtc/rtc-rk808.c new file +10 -0
+               ret = PTR_ERR(rk808_rtc->rtc);
+               return ret;
+       }
+
+       rk808_rtc->irq = platform_get_irq(pdev, 0);
+       if (rk808_rtc->irq <= 0) {
+               dev_err(&pdev->dev, "Wake up is not possible as irq = %d\n",
+                       rk808_rtc->irq);
+               return -ENXIO;
+       }

I think you misinterpreted Dmitry. He said this block was wrong, but you didn't quite make the right fix. I believe the correct fix is that an IRQ of "0" is a valid IRQ. Thus, you should have:

       rk808_rtc->irq = platform_get_irq(pdev, 0);
       if (rk808_rtc->irq < 0) {
               dev_err(&pdev->dev, "Wake up is not possible as irq = %d\n",
                       rk808_rtc->irq);
               return rk808_rtc->irq;
       }
Quoted 29 lines
drivers/rtc/rtc-rk808.c new file +28 -1
+
+       /* request alarm irq of rk808 */
+       ret = devm_request_threaded_irq(&pdev->dev, rk808_rtc->irq, NULL,
+                                       rk808_alarm_irq, 0,
+                                       "RTC alarm", rk808_rtc);
+       if (ret) {
+               dev_err(&pdev->dev, "Failed to request alarm IRQ %d: %d\n",
+                       rk808_rtc->irq, ret);
+       }
+
+       return ret;
+}
+
+static struct platform_driver rk808_rtc_driver = {
+       .probe = rk808_rtc_probe,
+       .driver = {
+               .name = "rk808-rtc",
+               .pm = &rk808_rtc_pm_ops,
+       },
+};
+
+module_platform_driver(rk808_rtc_driver);
+
+MODULE_DESCRIPTION("RTC driver for the rk808 series PMICs");
+MODULE_AUTHOR("Chris Zhong <[email protected]>");
+MODULE_AUTHOR("Zhang Qing <[email protected]>");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:rk808-rtc");
--
Quoted 2 lines

1.7.9.5

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

#11 lore raw

Re: [PATCH v7 3/5] RTC: RK808: add RTC driver for RK808

Quoted 16 lines · Doug Anderson
Quoted 16 lines

+static int rk808_rtc_probe(struct platform_device *pdev)

Quoted 15 lines
drivers/rtc/rtc-rk808.c new file +15 -0
+{
+       struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent);
+       struct rk808_rtc *rk808_rtc;
+       struct rtc_time tm;
+       int ret;
+
+       rk808_rtc = devm_kzalloc(&pdev->dev, sizeof(*rk808_rtc), GFP_KERNEL);
+       if (rk808_rtc == NULL)
+               return -ENOMEM;
+
+       platform_set_drvdata(pdev, rk808_rtc);
+       rk808_rtc->rk808 = rk808;
+
+       /* start rtc running by default, and use shadowed timer. */
+       ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
Quoted 9 lines
Quoted 3 lines

drivers/rtc/rtc-rk808.c line 350

Quoted 3 lines
drivers/rtc/rtc-rk808.c new file +3 -0
+                                BIT_RTC_CTRL_REG_STOP_RTC_M |
+                                BIT_RTC_CTRL_REG_RTC_READSEL_M,
+                                BIT_RTC_CTRL_REG_RTC_READSEL_M);

I think this should still be setting to 0, not to BIT_RTC_CTRL_REG_RTC_READSEL_M. Otherwise the first read of the time will return that time that was frozen at probe time, right? AKA: if probe happens at 11:00:00 and then we read the time at 11:00:05 we'll still read 11:00:00 the first time.

Sorry, I did not describe correctly, in the previous mail.
Actually, RK808 has a "GET_TIME" switch bit. When "GET_TIME" bit rising thansiton to 1, the current time will save in a shadowed register.
If "READSEL" = 1, read rtc time register, return the frozen time.
If we need the real time, clr this "READSEL" bit.

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

#12 lore raw

Re: [PATCH v7 3/5] RTC: RK808: add RTC driver for RK808

Chris,

Quoted 30 lines · Chris Zhong
Quoted 19 lines · Doug Anderson
Quoted 19 lines

+static int rk808_rtc_probe(struct platform_device *pdev)

Quoted 17 lines
drivers/rtc/rtc-rk808.c new file +7 -0
+{
+       struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent);
+       struct rk808_rtc *rk808_rtc;
+       struct rtc_time tm;
+       int ret;
+
+       rk808_rtc = devm_kzalloc(&pdev->dev, sizeof(*rk808_rtc),

GFP_KERNEL);

drivers/rtc/rtc-rk808.c new file +9 -0
+       if (rk808_rtc == NULL)
+               return -ENOMEM;
+
+       platform_set_drvdata(pdev, rk808_rtc);
+       rk808_rtc->rk808 = rk808;
+
+       /* start rtc running by default, and use shadowed timer. */
+       ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
+                                BIT_RTC_CTRL_REG_STOP_RTC_M |
Quoted 9 lines
Quoted 2 lines

drivers/rtc/rtc-rk808.c line 350

Quoted 2 lines
drivers/rtc/rtc-rk808.c new file +2 -0
+                                BIT_RTC_CTRL_REG_RTC_READSEL_M,
+                                BIT_RTC_CTRL_REG_RTC_READSEL_M);

I think this should still be setting to 0, not to BIT_RTC_CTRL_REG_RTC_READSEL_M. Otherwise the first read of the time will return that time that was frozen at probe time, right? AKA: if probe happens at 11:00:00 and then we read the time at 11:00:05 we'll still read 11:00:00 the first time.

Quoted 6 lines

Sorry, I did not describe correctly, in the previous mail. Actually, RK808 has a "GET_TIME" switch bit. When "GET_TIME" bit rising
thansiton to 1,
the current time will save in a shadowed register.
If "READSEL" = 1, read rtc time register, return the frozen time. If we need the real time, clr this "READSEL" bit.

Ohhhhh! I see. I clearly didn't look closely enough at the whole register description in the user manual. I think you've got it right, then.

I think this would be more obvious if you added a comment and you set both the high and low bits at the same time. AKA:

+ /* Force an update of the shadowed registers right now */
+ ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
+ BIT_RTC_CTRL_REG_RTC_GET_TIME,
+ BIT_RTC_CTRL_REG_RTC_GET_TIME);
+ if (ret) {
+ dev_err(dev, "Failed to update bits rtc_ctrl: %d\n", ret);
+ return ret;
+ }
+
+ ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
+ BIT_RTC_CTRL_REG_RTC_GET_TIME,
+ BIT_RTC_CTRL_REG_RTC_GET_TIME);
+ if (ret) {
+ dev_err(dev, "Failed to update bits rtc_ctrl: %d\n", ret);
+ return ret;
+ }

...doing them both at the same time makes it obvious that this is a one-time copy triggered by the "rising edge" of this bit. It also means you don't need any "goto" for error handling.

-Doug
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#13 lore raw

Re: [PATCH v7 3/5] RTC: RK808: add RTC driver for RK808

Hi,

Quoted 49 lines · Doug Anderson

Chris,

Quoted 30 lines · Chris Zhong
Quoted 19 lines · Doug Anderson
Quoted 19 lines

+static int rk808_rtc_probe(struct platform_device *pdev)

Quoted 17 lines
drivers/rtc/rtc-rk808.c new file +7 -0
+{
+       struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent);
+       struct rk808_rtc *rk808_rtc;
+       struct rtc_time tm;
+       int ret;
+
+       rk808_rtc = devm_kzalloc(&pdev->dev, sizeof(*rk808_rtc),

GFP_KERNEL);

drivers/rtc/rtc-rk808.c new file +9 -0
+       if (rk808_rtc == NULL)
+               return -ENOMEM;
+
+       platform_set_drvdata(pdev, rk808_rtc);
+       rk808_rtc->rk808 = rk808;
+
+       /* start rtc running by default, and use shadowed timer. */
+       ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
+                                BIT_RTC_CTRL_REG_STOP_RTC_M |
Quoted 9 lines
Quoted 2 lines

drivers/rtc/rtc-rk808.c line 350

Quoted 2 lines
drivers/rtc/rtc-rk808.c new file +2 -0
+                                BIT_RTC_CTRL_REG_RTC_READSEL_M,
+                                BIT_RTC_CTRL_REG_RTC_READSEL_M);

I think this should still be setting to 0, not to BIT_RTC_CTRL_REG_RTC_READSEL_M. Otherwise the first read of the time will return that time that was frozen at probe time, right? AKA: if probe happens at 11:00:00 and then we read the time at 11:00:05 we'll still read 11:00:00 the first time.

Quoted 6 lines

Sorry, I did not describe correctly, in the previous mail. Actually, RK808 has a "GET_TIME" switch bit. When "GET_TIME" bit rising
thansiton to 1,
the current time will save in a shadowed register.
If "READSEL" = 1, read rtc time register, return the frozen time. If we need the real time, clr this "READSEL" bit.

Ohhhhh! I see. I clearly didn't look closely enough at the whole register description in the user manual. I think you've got it right, then.

I think this would be more obvious if you added a comment and you set both the high and low bits at the same time. AKA:

drivers/rtc/rtc-rk808.c new file +2 -0
+       /* Force an update of the shadowed registers right now */
+       ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,

drivers/rtc/rtc-rk808.c

Quoted 10 lines
drivers/rtc/rtc-rk808.c new file +10 -0
+                                BIT_RTC_CTRL_REG_RTC_GET_TIME,
+                                BIT_RTC_CTRL_REG_RTC_GET_TIME);
+       if (ret) {
+               dev_err(dev, "Failed to update bits rtc_ctrl: %d\n", ret);
+               return ret;
+       }
+
+       ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
+                                BIT_RTC_CTRL_REG_RTC_GET_TIME,
+                                BIT_RTC_CTRL_REG_RTC_GET_TIME);

Doh, this one was supposed to be setting it back to 0.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#14 lore raw

PATCH v7 4/5 clk: RK808: Add clkout driver for RK808

In reply to Chris Zhong

---

Changes in v7:
Adviced by doug
-fix coding style problems

Changes in v6:
Adviced by doug
- use correct argument call of_clk_add_provider in probe

Changes in v5:
Adviced by doug
- add some error checking in probe
- move "rockchip,rk808.h" into the patch about dt-bindings

Changes in v4:
Adviced by doug
- add "clock-output-names" propertiey
- add a header file "rockchip,rk808.h"

Changes in v3:
- fix compile err

Changes in v2:
Adviced by javier.martinez
- separated from rtc-rk808.c

 drivers/clk/Kconfig     |    9 +++
 drivers/clk/Makefile    |    1 +
 drivers/clk/clk-rk808.c |  160 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 170 insertions(+)
 create mode 100644 drivers/clk/clk-rk808.c
drivers/clk/Kconfig +9 -0
index cfd3af7..84e0590 100644
@@ -38,6 +38,15 @@ config COMMON_CLK_MAX77686
 	---help---
 	  This driver supports Maxim 77686 crystal oscillator clock. 
 
+config COMMON_CLK_RK808
+	tristate "Clock driver for RK808"
+	depends on MFD_RK808
+	---help---
+	  This driver supports RK808 crystal oscillator clock. These
+	  multi-function devices have two fixed-rate oscillators,
+	  clocked at 32KHz each. Clkout1 is always on, Clkout2 can off
+	  by control register.
+
 config COMMON_CLK_SI5351
 	tristate "Clock driver for SiLabs 5351A/B/C"
 	depends on I2C
drivers/clk/Makefile +1 -0
index f537a0b..99f53d5 100644
@@ -28,6 +28,7 @@ obj-$(CONFIG_ARCH_NOMADIK)		+= clk-nomadik.o
 obj-$(CONFIG_ARCH_NSPIRE)		+= clk-nspire.o
 obj-$(CONFIG_COMMON_CLK_PALMAS)		+= clk-palmas.o
 obj-$(CONFIG_CLK_PPC_CORENET)		+= clk-ppc-corenet.o
+obj-$(CONFIG_COMMON_CLK_RK808)		+= clk-rk808.o
 obj-$(CONFIG_COMMON_CLK_S2MPS11)	+= clk-s2mps11.o
 obj-$(CONFIG_COMMON_CLK_SI5351)		+= clk-si5351.o
 obj-$(CONFIG_COMMON_CLK_SI570)		+= clk-si570.o
drivers/clk/clk-rk808.c new file +160 -0

160 lines not on this page · raw message

Signature · 6 lines
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reviewed-by Doug Anderson Tested-by Doug Anderson on v7 4/5
#15 lore raw

Re: [PATCH v7 4/5] clk: RK808: Add clkout driver for RK808

Quoting Chris Zhong (2014-09-01 02:46:40)

Quoted 5 lines

Hello Chris,

Thanks for submitting this patch. Could you fill in a proper changelog? Also you should reorder the tags like so:

<snip>

drivers/clk/clk-rk808.c line 51

Quoted 10 lines
drivers/clk/clk-rk808.c new file +10 -0
+static int rk808_clkout2_control(struct clk_hw *hw, bool enable)
+{
+       struct rk808_clkout *rk808_clkout = container_of(hw,
+                                                        struct rk808_clkout,
+                                                        clkout2_hw);
+       struct rk808 *rk808 = rk808_clkout->rk808;
+
+       return regmap_update_bits(rk808->regmap, RK808_CLK32OUT_REG,
+                                 CLK32KOUT2_EN, enable ? CLK32KOUT2_EN : 0);
+}

Nitpick: can you rename "control" to "enable" or "ungate"? That makes it more obvious what the function is doing without having to inspect the code in the function body.

<snip>

Quoted 8 lines
drivers/clk/clk-rk808.c new file +8 -0
+static int rk808_clkout_probe(struct platform_device *pdev)
+{
+       struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent);
+       struct i2c_client *client = rk808->i2c;
+       struct device_node *node = client->dev.of_node;
+       struct clk_init_data init = {};
+       struct clk **clk_table;
+       struct rk808_clkout *rk808_clkout;

drivers/clk/clk-rk808.c line 108

Quoted 10 lines
drivers/clk/clk-rk808.c new file +10 -0
+
+       rk808_clkout = devm_kzalloc(&client->dev,
+                                   sizeof(*rk808_clkout), GFP_KERNEL);
+       if (!rk808_clkout)
+               return -ENOMEM;
+
+       rk808_clkout->rk808 = rk808;
+
+       clk_table = devm_kzalloc(&client->dev,
+                                2 * sizeof(struct clk *), GFP_KERNEL);

Better to use devm_kcalloc. Also good to define a constant like:

#define RK808_NR_OUTPUT 2

... and then use RK8808_NR_OUTPUT instead of hard-coding the value 2 in the driver.

Quoted 24 lines
drivers/clk/clk-rk808.c new file +24 -0
+       if (!clk_table)
+               return -ENOMEM;
+
+       init.flags = CLK_IS_ROOT;
+       init.parent_names = NULL;
+       init.num_parents = 0;
+       init.name = "rk808-clkout1";
+       init.ops = &rk808_clkout1_ops;
+       rk808_clkout->clkout1_hw.init = &init;
+
+       /* optional override of the clockname */
+       of_property_read_string_index(node, "clock-output-names",
+                                     0, &init.name);
+
+       clk_table[0] = devm_clk_register(&client->dev,
+                                        &rk808_clkout->clkout1_hw);
+       if (IS_ERR(clk_table[0]))
+               return PTR_ERR(clk_table[0]);
+
+       init.name = "rk808-clkout2";
+       init.ops = &rk808_clkout2_ops;
+       rk808_clkout->clkout2_hw.init = &init;
+
+       /* optional override of the clockname */

drivers/clk/clk-rk808.c line 142

Quoted 10 lines
drivers/clk/clk-rk808.c new file +10 -0
+       of_property_read_string_index(node, "clock-output-names",
+                                     1, &init.name);
+
+       clk_table[1] = devm_clk_register(&client->dev,
+                                        &rk808_clkout->clkout2_hw);
+       if (IS_ERR(clk_table[1]))
+               return PTR_ERR(clk_table[1]);
+
+       rk808_clkout->clk_data.clks = clk_table;
+       rk808_clkout->clk_data.clk_num = 2;

Again, here you can use RK808_NR_OUTPUT.

Otherwise the driver looks pretty good to me.

Thanks,
Mike
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#16 lore raw

PATCH v7 5/5 regulator: RK808: Remove pdata from the regulator

In reply to Chris Zhong

---

Changes in v7:
- remove pdata struct from header file, add rk808_regulator struct

Changes in v6:
- remove the redundant code

Changes in v5:
- re-edit base on Mark's branch

Changes in v4:
- use &client->dev replace rk808->dev

Changes in v3: None
Changes in v2:
Adviced by Mark Browm:
- change of_find_node_by_name to find_child_by_name
- use RK808_NUM_REGULATORS as the name of the constant
- create a pdata when missing platform data
- use the rk808_reg name to supply_regulator name
- replace regulator_register with devm_regulator_register
- some other problem with coding style

 drivers/regulator/rk808-regulator.c |   52 ++++++++++++++---------------------
 1 file changed, 20 insertions(+), 32 deletions(-)
drivers/regulator/rk808-regulator.c +20 -32
index 0d11df1..4d543a9 100644
@@ -3,9 +3,6 @@
  *
  * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
  *
- * Author: Chris Zhong <[email protected]>
- * Author: Zhang Qing <[email protected]>
- *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
  * version 2, as published by the Free Software Foundation.
@@ -14,28 +11,25 @@
  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
- *
  */
 
 #include <linux/module.h>
-#include <linux/init.h>
 #include <linux/i2c.h>
-#include <linux/err.h>
-#include <linux/platform_device.h>
 #include <linux/mfd/rk808.h>
-#include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/regulator/driver.h>
 #include <linux/regulator/of_regulator.h>
-#include <linux/regmap.h>
-#include <linux/slab.h>
-/*
- * Field Definitions.
- */
+
+/* Field Definitions */
 #define RK808_BUCK_VSEL_MASK	0x3f
 #define RK808_BUCK4_VSEL_MASK	0xf
 #define RK808_LDO_VSEL_MASK	0x1f
 
+struct rk808_regulator {
+	struct regulator_init_data *rk808_init_data[RK808_NUM_REGULATORS];
+	struct device_node *of_node[RK808_NUM_REGULATORS];
+};
+
 static const int buck_set_vol_base_addr[] = {
 	RK808_BUCK1_ON_VSEL_REG,
 	RK808_BUCK2_ON_VSEL_REG,
@@ -50,10 +44,6 @@ static const int buck_contr_base_addr[] = {
 	RK808_BUCK4_CONFIG_REG,
 };
 
-#define rk808_BUCK_SET_VOL_REG(x) (buck_set_vol_base_addr[x])
-#define rk808_BUCK_CONTR_REG(x) (buck_contr_base_addr[x])
-#define rk808_LDO_SET_VOL_REG(x) (ldo_set_vol_base_addr[x])
-
 static const int ldo_set_vol_base_addr[] = {
 	RK808_LDO1_ON_VSEL_REG,
 	RK808_LDO2_ON_VSEL_REG,
@@ -65,9 +55,7 @@ static const int ldo_set_vol_base_addr[] = {
 	RK808_LDO8_ON_VSEL_REG,
 };
 
-/*
- * rk808 voltage number
- */
+/* rk808 voltage number */
 static const struct regulator_linear_range rk808_buck_voltage_ranges[] = {
 	REGULATOR_LINEAR_RANGE(700000, 0, 63, 12500),
 };
@@ -295,7 +283,7 @@ static struct of_regulator_match rk808_reg_matches[] = {
 };
 
 static int rk808_regulator_dts(struct i2c_client *client,
-			       struct rk808_board *pdata)
+			       struct rk808_regulator *rk808_regulator)
 {
 	struct device_node *np, *reg_np;
 	int i, ret;
@@ -323,8 +311,9 @@ static int rk808_regulator_dts(struct i2c_client *client,
 		    !rk808_reg_matches[i].of_node)
 			continue;
 
-		pdata->rk808_init_data[i] = rk808_reg_matches[i].init_data;
-		pdata->of_node[i] = rk808_reg_matches[i].of_node;
+		rk808_regulator->rk808_init_data[i] =
+				rk808_reg_matches[i].init_data;
+		rk808_regulator->of_node[i] = rk808_reg_matches[i].of_node;
 	}
 
 	return 0;
@@ -334,26 +323,25 @@ static int rk808_regulator_probe(struct platform_device *pdev)
 {
 	struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent);
 	struct i2c_client *client = rk808->i2c;
-	struct rk808_board *pdata = dev_get_platdata(&client->dev);
+	struct rk808_regulator *rk808_regulator;
 	struct regulator_config config = {};
 	struct regulator_dev *rk808_rdev;
 	struct regulator_init_data *reg_data;
 	int i = 0;
 	int ret = 0;
 
-	if (!pdata) {
-		pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
-		if (!pdata)
-			return -ENOMEM;
-	}
+	rk808_regulator = devm_kzalloc(&pdev->dev, sizeof(*rk808_regulator),
+				       GFP_KERNEL);
+	if (!rk808_regulator)
+		return -ENOMEM;
 
-	ret = rk808_regulator_dts(client, pdata);
+	ret = rk808_regulator_dts(client, rk808_regulator);
 	if (ret)
 		return ret;
 
 	/* Instantiate the regulators */
 	for (i = 0; i < RK808_NUM_REGULATORS; i++) {
-		reg_data = pdata->rk808_init_data[i];
+		reg_data = rk808_regulator->rk808_init_data[i];
 		if (!reg_data)
 			continue;
 
@@ -362,7 +350,7 @@ static int rk808_regulator_probe(struct platform_device *pdev)
 		config.regmap = rk808->regmap;
 
 		if (client->dev.of_node)
-			config.of_node = pdata->of_node[i];
+			config.of_node = rk808_regulator->of_node[i];
 
 		reg_data->supply_regulator = rk808_reg[i].name;
 		config.init_data = reg_data;
Signature · 6 lines
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#17 lore raw

Re: [PATCH v7 5/5] regulator: RK808: Remove pdata from the regulator

Chris,

Quoted 133 lines · Chris Zhong

---

Changes in v7:
- remove pdata struct from header file, add rk808_regulator struct

Changes in v6:
- remove the redundant code

Changes in v5:
- re-edit base on Mark's branch

Changes in v4:
- use &client->dev replace rk808->dev

Changes in v3: None
Changes in v2:
Adviced by Mark Browm:
- change of_find_node_by_name to find_child_by_name
- use RK808_NUM_REGULATORS as the name of the constant
- create a pdata when missing platform data
- use the rk808_reg name to supply_regulator name
- replace regulator_register with devm_regulator_register
- some other problem with coding style

 drivers/regulator/rk808-regulator.c |   52 ++++++++++++++---------------------
 1 file changed, 20 insertions(+), 32 deletions(-)
drivers/regulator/rk808-regulator.c +13 -24
index 0d11df1..4d543a9 100644
@@ -3,9 +3,6 @@
  *
  * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
  *
- * Author: Chris Zhong <[email protected]>
- * Author: Zhang Qing <[email protected]>
- *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
  * version 2, as published by the Free Software Foundation.
@@ -14,28 +11,25 @@
  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
- *
  */
 
 #include <linux/module.h>
-#include <linux/init.h>
 #include <linux/i2c.h>
-#include <linux/err.h>
-#include <linux/platform_device.h>
 #include <linux/mfd/rk808.h>
-#include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/regulator/driver.h>
 #include <linux/regulator/of_regulator.h>
-#include <linux/regmap.h>
-#include <linux/slab.h>
-/*
- * Field Definitions.
- */
+
+/* Field Definitions */
 #define RK808_BUCK_VSEL_MASK   0x3f
 #define RK808_BUCK4_VSEL_MASK  0xf
 #define RK808_LDO_VSEL_MASK    0x1f
 
+struct rk808_regulator {
+       struct regulator_init_data *rk808_init_data[RK808_NUM_REGULATORS];
+       struct device_node *of_node[RK808_NUM_REGULATORS];
+};
+
 static const int buck_set_vol_base_addr[] = {
        RK808_BUCK1_ON_VSEL_REG,
        RK808_BUCK2_ON_VSEL_REG,
@@ -50,10 +44,6 @@ static const int buck_contr_base_addr[] = {
        RK808_BUCK4_CONFIG_REG,
 };
 
-#define rk808_BUCK_SET_VOL_REG(x) (buck_set_vol_base_addr[x])
-#define rk808_BUCK_CONTR_REG(x) (buck_contr_base_addr[x])
-#define rk808_LDO_SET_VOL_REG(x) (ldo_set_vol_base_addr[x])
-
 static const int ldo_set_vol_base_addr[] = {
        RK808_LDO1_ON_VSEL_REG,
        RK808_LDO2_ON_VSEL_REG,
@@ -65,9 +55,7 @@ static const int ldo_set_vol_base_addr[] = {
        RK808_LDO8_ON_VSEL_REG,
 };
 
-/*
- * rk808 voltage number
- */
+/* rk808 voltage number */
 static const struct regulator_linear_range rk808_buck_voltage_ranges[] = {
        REGULATOR_LINEAR_RANGE(700000, 0, 63, 12500),
 };
@@ -295,7 +283,7 @@ static struct of_regulator_match rk808_reg_matches[] = {
 };
 
 static int rk808_regulator_dts(struct i2c_client *client,
-                              struct rk808_board *pdata)
+                              struct rk808_regulator *rk808_regulator)
 {
        struct device_node *np, *reg_np;
        int i, ret;
@@ -323,8 +311,9 @@ static int rk808_regulator_dts(struct i2c_client *client,
                    !rk808_reg_matches[i].of_node)
                        continue;
 
-               pdata->rk808_init_data[i] = rk808_reg_matches[i].init_data;
-               pdata->of_node[i] = rk808_reg_matches[i].of_node;
+               rk808_regulator->rk808_init_data[i] =
+                               rk808_reg_matches[i].init_data;
+               rk808_regulator->of_node[i] = rk808_reg_matches[i].of_node;
        }
 
        return 0;
@@ -334,26 +323,25 @@ static int rk808_regulator_probe(struct platform_device *pdev)
 {
        struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent);
        struct i2c_client *client = rk808->i2c;
-       struct rk808_board *pdata = dev_get_platdata(&client->dev);
+       struct rk808_regulator *rk808_regulator;
        struct regulator_config config = {};
        struct regulator_dev *rk808_rdev;
        struct regulator_init_data *reg_data;
        int i = 0;
        int ret = 0;

drivers/regulator/rk808-regulator.c static int rk808_regulator_probe(struct platform_device *pdev) · line 336

Quoted 10 lines
drivers/regulator/rk808-regulator.c +4 -5
 
-       if (!pdata) {
-               pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
-               if (!pdata)
-                       return -ENOMEM;
-       }
+       rk808_regulator = devm_kzalloc(&pdev->dev, sizeof(*rk808_regulator),
+                                      GFP_KERNEL);
+       if (!rk808_regulator)
+               return -ENOMEM;

Totally remove rk808_regulator_dts() function. Totally remove "rk808_regulator" local variable (and allocation, and typedef). Then you can just use "rk808_reg_matches" in the "for" loop in your probe function, right? You're going to get rid of a ton of code...

Remember, you can also remove the check about "client->dev.of_node". You depend on OF... Also it appears that "of_regulator_match" prints an error for you in at least the common error case, so I think you can get rid of "failed to parse regulator data: %d\n" printout.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer Tested-by on the v7 series
#18 lore raw
In reply to Chris Zhong

Am Montag, 1. September 2014, 17:07:43 schrieb Chris Zhong:

Quoted 6 lines

This is the initial version of the RK808 PMIC. This is a power management IC for multimedia products.

It provides regulators that are able to supply power to processor cores and other components. The chip provides other modules including RTC, Clockout

The whole series on a 3-17-rc1 with the already applied regulator commits pulled in and used by my pending cpufreq patches to set the core voltage

Quoted 106 lines

Changes in v7:
Advices by Mark Rutland
- modify description about clock-cells
- update the example
Adviced by Lee Jones
- coding style
- remove rk808_pre_init function
Adviced by Doug
- add "&& OF" to the dependencies
- add .init_ack_masked = true in rk808_irq_chip
Adviced by doug
- read rtc time from shadowed registers
Adviced by Dmitry
- use CONFIG_PM_SLEEP replace CONFIG_PM
- use SIMPLE_DEV_PM_OPS replace dev_pm_ops
- fix dev_warn
- coding style
Adviced by Heiko
- remove rtc_ctl
Adviced by doug
-fix coding style problems
- remove pdata struct from header file, add rk808_regulator struct

Changes in v6:
Advices by Mark Rutland
- add description about clock-cells
Advices by Doug
- modify description about regulator
- remove pinctrl description
Adviced by Lee Jones in v2
- rk808_i2c_client instead of g_rk808
- remove pdata form struct rk808
Adviced by doug
- move RTC_READSEL setting into probe
Adviced by doug
- use correct argument call of_clk_add_provider in probe
- remove the redundant code

Changes in v5:
Advices by Mark Brown
- add description about regulator valid name.
- add a header file "rockchip,rk808".
- fixed a bug about set_time failed
Adviced by doug
- add some error checking in probe
- move "rockchip,rk808.h" into the patch about dt-bindings
- re-edit base on Mark's branch

Changes in v4:
Advices by Doug
- add a "#clock-cells" propertiy
- update the example
Adviced by Lee Jones in v2
- modify the description in Kconfig
- remove some unnecessary header files
- remove dev from struct rk808
- use enum for define RK808_ID...
- use &client->dev replace rk808->dev
Adviced by doug
- add "clock-output-names" propertiey
- add a header file "rockchip,rk808.h"
- use &client->dev replace rk808->dev

Changes in v3:
- fix compile err
- fix compile err

Changes in v2:
Adviced by Mark Browm:
- use defines for register setting value
- remove rtc alarm disable in shutdown
- remove while(1) in shutdown
- remove read 0x2f in probe
Adviced by javier.martinez
- Add a separate clock driver, rather than in RTC driver Adviced by javier.martinez
- separated from rtc-rk808.c
Adviced by Mark Browm:
- change of_find_node_by_name to find_child_by_name
- use RK808_NUM_REGULATORS as the name of the constant
- create a pdata when missing platform data
- use the rk808_reg name to supply_regulator name
- replace regulator_register with devm_regulator_register
- some other problem with coding style

Chris Zhong (5):
dt-bindings: Add RK808 device tree bindings document
MFD: RK808: Add new mfd driver for RK808
RTC: RK808: add RTC driver for RK808
clk: RK808: Add clkout driver for RK808
regulator: RK808: Remove pdata from the regulator

 Documentation/devicetree/bindings/mfd/rk808.txt |  166 +++++++++
 drivers/clk/Kconfig                             |    9 +
 drivers/clk/Makefile                            |    1 +
 drivers/clk/clk-rk808.c                         |  160 +++++++++
 drivers/mfd/Kconfig                             |   13 +
 drivers/mfd/Makefile                            |    1 +
 drivers/mfd/rk808.c                             |  243 +++++++++++++
 drivers/regulator/rk808-regulator.c             |   52 ++-
 drivers/rtc/Kconfig                             |   10 +
 drivers/rtc/Makefile                            |    1 +
 drivers/rtc/rtc-rk808.c                         |  419

+++++++++++++++++++++++ include/dt-bindings/clock/rockchip,rk808.h |
11 +

Quoted 8 lines
 include/linux/mfd/rk808.h                       |  196 +++++++++++
 13 files changed, 1250 insertions(+), 32 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mfd/rk808.txt
 create mode 100644 drivers/clk/clk-rk808.c
 create mode 100644 drivers/mfd/rk808.c
 create mode 100644 drivers/rtc/rtc-rk808.c
 create mode 100644 include/dt-bindings/clock/rockchip,rk808.h
 create mode 100644 include/linux/mfd/rk808.h

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