Skip to contentSkip to conversation

PWM changes for rk3288-evb

PATCH Superseded Doug Anderson 1 participant 5 messages Aug 20, 2014

Subsystems (3)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover PWM changes for rk3288-evb

These patches enable the PWM backlight for the rk3288-evb board. There were tested by watching the backlight grow from off to max with the following instructions:

  cd /sys/class/backlight/backlight*/
  for i in $(seq 255); do echo $i > brightness; sleep .01; done

The first patch switches PWM cells from 2 to 3 on rk3288. I think it could land in Thierry's tree. This patch will break backward compatibility for rk3288 until changes land handling PWM cells more dynamically, but since there are no rk3288 boards shipping yet it seems OK.

The second patch enables the proper IP. This will also break backward compatibility, but again should be OK since there are no users. If needed we could make the "grf" optional and assume any shipping boards enabled the bit in their bootloader. I think this could land in Thierry's tree with Heiko's ACK.

The 3rd and 4th patches are DTS ones. They could land in Heiko's tree after the first two patches. They are based atop his current WIP 3.18 dts tree. Note that instantiating the PWM backlight will cause the system to hang unless Heiko's (clk: rockchip: protect critical clocks from getting disabled) <patchwork.kernel.org/patch/4725391> is landed.

There are no compile time or runtime dependencies between these patches except that patch #3 needs to come before patch #4. ...and of course the PWM won't work without all 4 patches.

Changes in v4:
- Updated comment not to add caveats about pwm_cells 3.
- rockchip_pwm_set_polarity() is now static.
- Separate pwm_ops for v1 and v2; no set_polarity() in v1.
- Added a blank line.
- Totally rewrote to go in the PWM driver.
- Reordered IP switch to be atop invert patch.
- Add rockchip,grf to pwm nodes.

Changes in v3:
- Don't store a private copy of polarity.
- Use true instead of 1.
- Cleanup init order with "has_invert".
- Fix space to tab in 2 places in DTS.
- Make sure PWM is upper case in prose.

Changes in v2:
- Check for failed ioremap()

Doug Anderson (4):
pwm: rockchip: Allow polarity invert on rk3288
ARM: rockchip: rk3288: Switch to use the proper PWM IP
ARM: dts: Add main PWM info to rk3288
ARM: dts: Enable PWM backlight on rk3288-evb

 .../devicetree/bindings/pwm/pwm-rockchip.txt       |  8 +-
 arch/arm/boot/dts/rk3288-evb.dtsi                  | 53 +++++++++++++
 arch/arm/boot/dts/rk3288.dtsi                      | 72 ++++++++++++++++++
 drivers/pwm/pwm-rockchip.c                         | 86 +++++++++++++++++++---
 4 files changed, 208 insertions(+), 11 deletions(-)
Signature · 1 line
2.1.0.rc2.206.gedb03e5
#1 lore raw

PATCH v4 1/4 pwm: rockchip: Allow polarity invert on rk3288

The rk3288 has the ability to invert the polarity of the PWM. Let's enable that ability. Note that this increases pwm_cells to 3 for rk3288.

---
Changes in v4:
- Updated comment not to add caveats about pwm_cells 3.
- rockchip_pwm_set_polarity() is now static.
- Separate pwm_ops for v1 and v2; no set_polarity() in v1.
- Added a blank line.

Changes in v3:
- Don't store a private copy of polarity.
- Use true instead of 1.
- Cleanup init order with "has_invert".

Changes in v2: None

 .../devicetree/bindings/pwm/pwm-rockchip.txt       |  4 +-
 drivers/pwm/pwm-rockchip.c                         | 57 ++++++++++++++++++----
 2 files changed, 50 insertions(+), 11 deletions(-)
Documentation/devicetree/bindings/pwm/pwm-rockchip.txt +2 -2
index d47d15a..b8be3d0 100644
@@ -7,8 +7,8 @@ Required properties:
    "rockchip,vop-pwm": found integrated in VOP on RK3288 SoC
  - reg: physical base address and length of the controller's registers
  - clocks: phandle and clock specifier of the PWM reference clock
- - #pwm-cells: should be 2. See pwm.txt in this directory for a
-   description of the cell format.
+ - #pwm-cells: must be 2 (rk2928) or 3 (rk3288). See pwm.txt in this directory
+   for a description of the cell format.
 
 Example:
 
drivers/pwm/pwm-rockchip.c +48 -9

143 lines not on this page · raw message

Signature · 1 line
2.1.0.rc2.206.gedb03e5
#2 lore raw

PATCH v4 2/4 ARM: rockchip: rk3288: Switch to use the proper PWM IP

In reply to Doug Anderson

The rk3288 SoC has an option to switch all of the PWMs in the system between the old IP block and the new IP block. The rk3288 PWM driver is written for the new block, so make sure that we enable the new block in the GRF (general register file) when the PWM driver probes.

We emulate the solution to this problem used in i2c-rk3x.c. One difference for the PWM is that there's a single "enable new IP" that's used for all 4 PWMs. That means we set this bit 4 times if we've got all 4 PWMs enabled. That shouldn't hurt.

---
Changes in v4:
- Totally rewrote to go in the PWM driver.
- Reordered IP switch to be atop invert patch.

Changes in v3: None
Changes in v2:
- Check for failed ioremap()

 .../devicetree/bindings/pwm/pwm-rockchip.txt       |  4 +++
 drivers/pwm/pwm-rockchip.c                         | 29 ++++++++++++++++++++++
 2 files changed, 33 insertions(+)
Documentation/devicetree/bindings/pwm/pwm-rockchip.txt +4 -0
index b8be3d0..39190ec 100644
@@ -10,6 +10,10 @@ Required properties:
  - #pwm-cells: must be 2 (rk2928) or 3 (rk3288). See pwm.txt in this directory
    for a description of the cell format.
 
+Required for "rockchip,rk3288-pwm":
+ - rockchip,grf : the phandle of the syscon node for the general register
+		  file (GRF)
+
 Example:
 
 	pwm0: pwm at 20030000 {
drivers/pwm/pwm-rockchip.c +29 -0
index 9442df2..08cbde6 100644
@@ -16,7 +16,12 @@
 #include <linux/of_device.h>
 #include <linux/platform_device.h>
 #include <linux/pwm.h>
+#include <linux/regmap.h>
 #include <linux/time.h>
+#include <linux/mfd/syscon.h>
+
+#define RK3288_GRF_PWM_ENABLE_OFFSET	0x024c
+#define RK3288_GRF_PWM_ENABLE_BIT	0
 
 #define PWM_CTRL_TIMER_EN	(1 << 0)
 #define PWM_CTRL_OUTPUT_EN	(1 << 3)
@@ -231,6 +236,7 @@ MODULE_DEVICE_TABLE(of, rockchip_pwm_dt_ids);
 
 static int rockchip_pwm_probe(struct platform_device *pdev)
 {
+	struct device_node *np = pdev->dev.of_node;
 	const struct of_device_id *id;
 	struct rockchip_pwm_chip *pc;
 	struct resource *r;
@@ -240,6 +246,29 @@ static int rockchip_pwm_probe(struct platform_device *pdev)
 	if (!id)
 		return -EINVAL;
 
+	/*
+	 * Switch to new interface on rk3288.
+	 * The control bit is located in the GRF register space.
+	 */
+	if (of_device_is_compatible(np, "rockchip,rk3288-pwm")) {
+		struct regmap *grf;
+
+		grf = syscon_regmap_lookup_by_phandle(np, "rockchip,grf");
+		if (IS_ERR(grf)) {
+			dev_err(&pdev->dev, "Missing rockchip,grf property\n");
+			return PTR_ERR(grf);
+		}
+
+		/* Set bit 16 for write mask, 0 for switch to new IP */
+		ret = regmap_write(grf, RK3288_GRF_PWM_ENABLE_OFFSET,
+				   BIT(RK3288_GRF_PWM_ENABLE_BIT + 16) |
+				   BIT(RK3288_GRF_PWM_ENABLE_BIT));
+		if (ret != 0) {
+			dev_err(&pdev->dev, "Could not access GRF: %d\n", ret);
+			return ret;
+		}
+	}
+
 	pc = devm_kzalloc(&pdev->dev, sizeof(*pc), GFP_KERNEL);
 	if (!pc)
 		return -ENOMEM;
Signature · 1 line
2.1.0.rc2.206.gedb03e5
#3 lore raw

PATCH v4 3/4 ARM: dts: Add main PWM info to rk3288

In reply to Doug Anderson

This adds the PWM info (other than the VOP PWM) to the main rk3288 dtsi file.

---
Changes in v4:
- Add rockchip,grf to pwm nodes.

Changes in v3: None
Changes in v2: None

 arch/arm/boot/dts/rk3288.dtsi | 72 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 72 insertions(+)
arch/arm/boot/dts/rk3288.dtsi +72 -0
index 36be7bb..9074205 100644
@@ -261,6 +261,54 @@
 		status = "disabled";
 	};
 
+	pwm0: pwm at ff680000 {
+		compatible = "rockchip,rk3288-pwm";
+		reg = <0xff680000 0x10>;
+		#pwm-cells = <3>;
+		pinctrl-names = "default";
+		pinctrl-0 = <&pwm0_pin>;
+		clocks = <&cru PCLK_PWM>;
+		clock-names = "pwm";
+		rockchip,grf = <&grf>;
+		status = "disabled";
+	};
+
+	pwm1: pwm at ff680010 {
+		compatible = "rockchip,rk3288-pwm";
+		reg = <0xff680010 0x10>;
+		#pwm-cells = <3>;
+		pinctrl-names = "default";
+		pinctrl-0 = <&pwm1_pin>;
+		clocks = <&cru PCLK_PWM>;
+		clock-names = "pwm";
+		rockchip,grf = <&grf>;
+		status = "disabled";
+	};
+
+	pwm2: pwm at ff680020 {
+		compatible = "rockchip,rk3288-pwm";
+		reg = <0xff680020 0x10>;
+		#pwm-cells = <3>;
+		pinctrl-names = "default";
+		pinctrl-0 = <&pwm2_pin>;
+		clocks = <&cru PCLK_PWM>;
+		clock-names = "pwm";
+		rockchip,grf = <&grf>;
+		status = "disabled";
+	};
+
+	pwm3: pwm at ff680030 {
+		compatible = "rockchip,rk3288-pwm";
+		reg = <0xff680030 0x10>;
+		#pwm-cells = <2>;
+		pinctrl-names = "default";
+		pinctrl-0 = <&pwm3_pin>;
+		clocks = <&cru PCLK_PWM>;
+		clock-names = "pwm";
+		rockchip,grf = <&grf>;
+		status = "disabled";
+	};
+
 	pmu: power-management at ff730000 {
 		compatible = "rockchip,rk3288-pmu", "syscon";
 		reg = <0xff730000 0x100>;
@@ -611,5 +659,29 @@
 				rockchip,pins = <5 15 3 &pcfg_pull_none>;
 			};
 		};
+
+		pwm0 {
+			pwm0_pin: pwm0-pin {
+				rockchip,pins = <7 0 RK_FUNC_1 &pcfg_pull_none>;
+			};
+		};
+
+		pwm1 {
+			pwm1_pin: pwm1-pin {
+				rockchip,pins = <7 1 RK_FUNC_1 &pcfg_pull_none>;
+			};
+		};
+
+		pwm2 {
+			pwm2_pin: pwm2-pin {
+				rockchip,pins = <7 22 RK_FUNC_3 &pcfg_pull_none>;
+			};
+		};
+
+		pwm3 {
+			pwm3_pin: pwm3-pin {
+				rockchip,pins = <7 23 RK_FUNC_3 &pcfg_pull_none>;
+			};
+		};
 	};
 };
Signature · 1 line
2.1.0.rc2.206.gedb03e5
#4 lore raw

PATCH v4 4/4 ARM: dts: Enable PWM backlight on rk3288-evb

In reply to Doug Anderson

PWM0 is the PWM associated with the LCD backlight. Enable it.

---
Changes in v4: None
Changes in v3:
- Fix space to tab in 2 places in DTS.
- Make sure PWM is upper case in prose.

Changes in v2: None

 arch/arm/boot/dts/rk3288-evb.dtsi | 53 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
arch/arm/boot/dts/rk3288-evb.dtsi +53 -0
index 2964370..98b69d0 100644
@@ -10,6 +10,7 @@
  * GNU General Public License for more details.
  */
 
+#include <dt-bindings/pwm/pwm.h>
 #include "rk3288.dtsi"
 
 / {
@@ -17,6 +18,48 @@
 		reg = <0x0 0x80000000>;
 	};
 
+	backlight {
+		compatible = "pwm-backlight";
+		brightness-levels = <
+			  0   1   2   3   4   5   6   7
+			  8   9  10  11  12  13  14  15
+			 16  17  18  19  20  21  22  23
+			 24  25  26  27  28  29  30  31
+			 32  33  34  35  36  37  38  39
+			 40  41  42  43  44  45  46  47
+			 48  49  50  51  52  53  54  55
+			 56  57  58  59  60  61  62  63
+			 64  65  66  67  68  69  70  71
+			 72  73  74  75  76  77  78  79
+			 80  81  82  83  84  85  86  87
+			 88  89  90  91  92  93  94  95
+			 96  97  98  99 100 101 102 103
+			104 105 106 107 108 109 110 111
+			112 113 114 115 116 117 118 119
+			120 121 122 123 124 125 126 127
+			128 129 130 131 132 133 134 135
+			136 137 138 139 140 141 142 143
+			144 145 146 147 148 149 150 151
+			152 153 154 155 156 157 158 159
+			160 161 162 163 164 165 166 167
+			168 169 170 171 172 173 174 175
+			176 177 178 179 180 181 182 183
+			184 185 186 187 188 189 190 191
+			192 193 194 195 196 197 198 199
+			200 201 202 203 204 205 206 207
+			208 209 210 211 212 213 214 215
+			216 217 218 219 220 221 222 223
+			224 225 226 227 228 229 230 231
+			232 233 234 235 236 237 238 239
+			240 241 242 243 244 245 246 247
+			248 249 250 251 252 253 254 255>;
+		default-brightness-level = <128>;
+		enable-gpios = <&gpio7 2 GPIO_ACTIVE_HIGH>;
+		pinctrl-names = "default";
+		pinctrl-0 = <&bl_en>;
+		pwms = <&pwm0 0 1000000 PWM_POLARITY_INVERTED>;
+	};
+
 	gpio-keys {
 		compatible = "gpio-keys";
 		#address-cells = <1>;
@@ -81,6 +124,10 @@
 	status = "okay";
 };
 
+&pwm0 {
+	status = "okay";
+};
+
 &uart0 {
 	status = "okay";
 };
@@ -102,6 +149,12 @@
 };
 
 &pinctrl {
+	backlight {
+		bl_en: bl-en {
+			rockchip,pins = <7 2 RK_FUNC_GPIO &pcfg_pull_none>;
+		};
+	};
+
 	buttons {
 		pwrbtn: pwrbtn {
 			rockchip,pins = <0 5 RK_FUNC_GPIO &pcfg_pull_up>;
Signature · 1 line
2.1.0.rc2.206.gedb03e5