Skip to contentSkip to conversation

clk: ti: add divider clock driver

PATCH Superseded Dario Binacchi 3 participants 22 messages Sep 6, 2020 – Sep 11, 2020

Subsystems (9)

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 8/30 clk: ti: add divider clock driver

The patch adds support for TI divider clock binding. The driver uses routines provided by the common clock framework (ccf).

The code is based on the drivers/clk/ti/divider.c driver of the Linux kernel.

---

Changes in v2:
- Merged to patch [09/31] clk: ti: refactor mux and divider clock drivers.

 .../clock/ti,autoidle.txt                     |  39 ++
 doc/device-tree-bindings/clock/ti,divider.txt | 117 ++++++
 drivers/clk/Kconfig                           |   6 +
 drivers/clk/Makefile                          |   2 +
 drivers/clk/clk-ti-divider.c                  | 380 ++++++++++++++++++
 drivers/clk/clk-ti-mux.c                      |  27 +-
 drivers/clk/clk-ti.c                          |  34 ++
 drivers/clk/clk-ti.h                          |  13 +
 8 files changed, 593 insertions(+), 25 deletions(-)
 create mode 100644 doc/device-tree-bindings/clock/ti,autoidle.txt
 create mode 100644 doc/device-tree-bindings/clock/ti,divider.txt
 create mode 100644 drivers/clk/clk-ti-divider.c
 create mode 100644 drivers/clk/clk-ti.c
 create mode 100644 drivers/clk/clk-ti.h
doc/device-tree-bindings/clock/ti,autoidle.txt new file +39 -0
new file mode 100644
index 0000000000..6c5b77e18c
@@ -0,0 +1,39 @@
+Binding for Texas Instruments autoidle clock.
+
+Binding status: Unstable - ABI compatibility may be broken in the future
+
+This binding uses the common clock binding[1]. It assumes a register mapped
+clock which can be put to idle automatically by hardware based on the usage
+and a configuration bit setting. Autoidle clock is never an individual
+clock, it is always a derivative of some basic clock like a gate, divider,
+or fixed-factor.
+
+[1] doc/device-tree-bindings/clock/clock-bindings.txt
+
+Required properties:
+- reg : offset for the register controlling the autoidle
+- ti,autoidle-shift : bit shift of the autoidle enable bit
+- ti,invert-autoidle-bit : autoidle is enabled by setting the bit to 0
+
+Examples:
+	dpll_core_m4_ck: dpll_core_m4_ck {
+		#clock-cells = <0>;
+		compatible = "ti,divider-clock";
+		clocks = <&dpll_core_x2_ck>;
+		ti,max-div = <31>;
+		ti,autoidle-shift = <8>;
+		reg = <0x2d38>;
+		ti,index-starts-at-one;
+		ti,invert-autoidle-bit;
+	};
+
+	dpll_usb_clkdcoldo_ck: dpll_usb_clkdcoldo_ck {
+		#clock-cells = <0>;
+		compatible = "ti,fixed-factor-clock";
+		clocks = <&dpll_usb_ck>;
+		ti,clock-div = <1>;
+		ti,autoidle-shift = <8>;
+		reg = <0x01b4>;
+		ti,clock-mult = <1>;
+		ti,invert-autoidle-bit;
+	};
doc/device-tree-bindings/clock/ti,divider.txt new file +117 -0

117 lines not on this page · raw message

drivers/clk/Kconfig +6 -0
index bddb454b7c..d7b546d9db 100644
@@ -105,6 +105,12 @@ config CLK_TI_AM3_DPLL
 	  This enables the DPLL clock drivers support on AM33XX SoCs. The DPLL
 	  provides all interface clocks and functional clocks to the processor.
 
+config CLK_TI_DIVIDER
+	bool "TI divider clock driver"
+	depends on CLK && OF_CONTROL && CLK_CCF
+	help
+	  This enables the divider clock driver support on TI's SoCs.
+
 config CLK_TI_MUX
 	bool "TI mux clock driver"
 	depends on CLK && OF_CONTROL && CLK_CCF
drivers/clk/Makefile +2 -0
index cc20279a20..21b1e9c364 100644
@@ -18,6 +18,7 @@ obj-$(CONFIG_ARCH_ASPEED) += aspeed/
 obj-$(CONFIG_ARCH_MEDIATEK) += mediatek/
 obj-$(CONFIG_ARCH_MTMIPS) += mtmips/
 obj-$(CONFIG_ARCH_MESON) += meson/
+obj-$(CONFIG_ARCH_OMAP2PLUS) += clk-ti.o
 obj-$(CONFIG_ARCH_ROCKCHIP) += rockchip/
 obj-$(CONFIG_ARCH_SOCFPGA) += altera/
 obj-$(CONFIG_CLK_AT91) += at91/
@@ -47,6 +48,7 @@ obj-$(CONFIG_SANDBOX) += clk_sandbox_test.o
 obj-$(CONFIG_SANDBOX_CLK_CCF) += clk_sandbox_ccf.o
 obj-$(CONFIG_STM32H7) += clk_stm32h7.o
 obj-$(CONFIG_CLK_TI_AM3_DPLL) += clk-ti-am3-dpll.o clk-ti-am3-dpll-x2.o
+obj-$(CONFIG_CLK_TI_DIVIDER) += clk-ti-divider.o
 obj-$(CONFIG_CLK_TI_MUX) += clk-ti-mux.o
 obj-$(CONFIG_CLK_TI_SCI) += clk-ti-sci.o
 obj-$(CONFIG_CLK_VERSAL) += clk_versal.o
drivers/clk/clk-ti-divider.c new file +380 -0

380 lines not on this page · raw message

drivers/clk/clk-ti-mux.c +2 -25
index 7e39dd3477..e4b190bbcc 100644
@@ -12,6 +12,7 @@
 #include <clk-uclass.h>
 #include <asm/io.h>
 #include <linux/clk-provider.h>
+#include "clk-ti.h"
 
 struct clk_ti_mux_priv {
 	struct clk_bulk parents;
@@ -23,30 +24,6 @@ struct clk_ti_mux_priv {
 	s32 latch;
 };
 
-static void clk_ti_mux_rmw(u32 val, u32 mask, fdt_addr_t reg)
-{
-	u32 v;
-
-	v = readl(reg);
-	v &= ~mask;
-	v |= val;
-	writel(v, reg);
-}
-
-static void clk_ti_mux_latch(fdt_addr_t reg, s8 shift)
-{
-	u32 latch;
-
-	if (shift < 0)
-		return;
-
-	latch = 1 << shift;
-
-	clk_ti_mux_rmw(latch, latch, reg);
-	clk_ti_mux_rmw(0, latch, reg);
-	readl(reg);		/* OCP barrier */
-}
-
 static struct clk *clk_ti_mux_get_parent_by_index(struct clk_bulk *parents,
 						  int index)
 {
@@ -119,7 +96,7 @@ static int clk_ti_mux_set_parent(struct clk *clk, struct clk *parent)
 
 	val |= index << priv->shift;
 	writel(val, priv->reg);
-	clk_ti_mux_latch(priv->reg, priv->latch);
+	clk_ti_latch(priv->reg, priv->latch);
 	return 0;
 }
 
drivers/clk/clk-ti.c new file +34 -0
new file mode 100644
index 0000000000..594ef75270
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * TI clock utilities
+ *
+ * Copyright (C) 2020 Dario Binacchi <[email protected]>
+ */
+
+#include <common.h>
+#include <asm/io.h>
+#include "clk-ti.h"
+
+static void clk_ti_rmw(u32 val, u32 mask, fdt_addr_t reg)
+{
+	u32 v;
+
+	v = readl(reg);
+	v &= ~mask;
+	v |= val;
+	writel(v, reg);
+}
+
+void clk_ti_latch(fdt_addr_t reg, s8 shift)
+{
+	u32 latch;
+
+	if (shift < 0)
+		return;
+
+	latch = 1 << shift;
+
+	clk_ti_rmw(latch, latch, reg);
+	clk_ti_rmw(0, latch, reg);
+	readl(reg);		/* OCP barrier */
+}
drivers/clk/clk-ti.h new file +13 -0
new file mode 100644
index 0000000000..601c3823f7
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * TI clock utilities header
+ *
+ * Copyright (C) 2020 Dario Binacchi <[email protected]>
+ */
+
+#ifndef _CLK_TI_H
+#define _CLK_TI_H
+
+void clk_ti_latch(fdt_addr_t reg, s8 shift);
+
+#endif /* #ifndef _CLK_TI_H */
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 9/30 clk: ti: add gate clock driver

The patch adds support for TI gate clock binding. The code is based on the drivers/clk/ti/gate.c driver of the Linux kernel.

---

(no changes since v1)

 .../clock/gpio-gate-clock.txt                 |  21 ++++
 .../clock/ti,clockdomain.txt                  |  24 ++++
 doc/device-tree-bindings/clock/ti,gate.txt    | 106 ++++++++++++++++++
 drivers/clk/Kconfig                           |   6 +
 drivers/clk/Makefile                          |   1 +
 drivers/clk/clk-ti-gate.c                     |  92 +++++++++++++++
 6 files changed, 250 insertions(+)
 create mode 100644 doc/device-tree-bindings/clock/gpio-gate-clock.txt
 create mode 100644 doc/device-tree-bindings/clock/ti,clockdomain.txt
 create mode 100644 doc/device-tree-bindings/clock/ti,gate.txt
 create mode 100644 drivers/clk/clk-ti-gate.c
doc/device-tree-bindings/clock/gpio-gate-clock.txt new file +21 -0
new file mode 100644
index 0000000000..7cba766cbe
@@ -0,0 +1,21 @@
+Binding for simple gpio gated clock.
+
+This binding uses the common clock binding[1].
+
+[1] doc/device-tree-bindings/clock/clock-bindings.txt
+
+Required properties:
+- compatible : shall be "gpio-gate-clock".
+- #clock-cells : from common clock binding; shall be set to 0.
+- enable-gpios : GPIO reference for enabling and disabling the clock.
+
+Optional properties:
+- clocks: Maximum of one parent clock is supported.
+
+Example:
+	clock {
+		compatible = "gpio-gate-clock";
+		clocks = <&parentclk>;
+		#clock-cells = <0>;
+		enable-gpios = <&gpio 1 GPIO_ACTIVE_HIGH>;
+	};
doc/device-tree-bindings/clock/ti,clockdomain.txt new file +24 -0
new file mode 100644
index 0000000000..cf05ee8bb9
@@ -0,0 +1,24 @@
+Binding for Texas Instruments clockdomain.
+
+Binding status: Unstable - ABI compatibility may be broken in the future
+
+This binding uses the common clock binding[1] in consumer role.
+Every clock on TI SoC belongs to one clockdomain, but software
+only needs this information for specific clocks which require
+their parent clockdomain to be controlled when the clock is
+enabled/disabled. This binding doesn't define a new clock
+binding type, it is used to group existing clock nodes under
+hardware hierarchy.
+
+[1] doc/device-tree-bindings/clock/clock-bindings.txt
+
+Required properties:
+- compatible : shall be "ti,clockdomain"
+- #clock-cells : from common clock binding; shall be set to 0.
+- clocks : link phandles of clocks within this domain
+
+Examples:
+	dss_clkdm: dss_clkdm {
+		compatible = "ti,clockdomain";
+		clocks = <&dss1_alwon_fck_3430es2>, <&dss_ick_3430es2>;
+	};
doc/device-tree-bindings/clock/ti,gate.txt new file +106 -0

106 lines not on this page · raw message

drivers/clk/Kconfig +6 -0
index d7b546d9db..c0528c2aeb 100644
@@ -111,6 +111,12 @@ config CLK_TI_DIVIDER
 	help
 	  This enables the divider clock driver support on TI's SoCs.
 
+config CLK_TI_GATE
+	bool "TI gate clock driver"
+	depends on CLK && OF_CONTROL
+	help
+	  This enables the gate clock driver support on TI's SoCs.
+
 config CLK_TI_MUX
 	bool "TI mux clock driver"
 	depends on CLK && OF_CONTROL && CLK_CCF
drivers/clk/Makefile +1 -0
index 21b1e9c364..4d16fb7a50 100644
@@ -49,6 +49,7 @@ obj-$(CONFIG_SANDBOX_CLK_CCF) += clk_sandbox_ccf.o
 obj-$(CONFIG_STM32H7) += clk_stm32h7.o
 obj-$(CONFIG_CLK_TI_AM3_DPLL) += clk-ti-am3-dpll.o clk-ti-am3-dpll-x2.o
 obj-$(CONFIG_CLK_TI_DIVIDER) += clk-ti-divider.o
+obj-$(CONFIG_CLK_TI_GATE) += clk-ti-gate.o
 obj-$(CONFIG_CLK_TI_MUX) += clk-ti-mux.o
 obj-$(CONFIG_CLK_TI_SCI) += clk-ti-sci.o
 obj-$(CONFIG_CLK_VERSAL) += clk_versal.o
drivers/clk/clk-ti-gate.c new file +92 -0

92 lines not on this page · raw message

Signature · 1 line
2.17.1
#2 lore raw

PATCH v2 10/30 ti: am33xx: fix do_enable_clocks() to accept NULL parameters

In reply to Dario Binacchi

Up till this commit passing NULL as input parameter was allowed, but not handled properly. When a NULL parameter was passed to the function a data abort was raised.

---

(no changes since v1)

 arch/arm/mach-omap2/am33xx/clock.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
arch/arm/mach-omap2/am33xx/clock.c +6 -4
index 8819062aaa..130ee6c6e3 100644
@@ -194,13 +194,14 @@ void do_enable_clocks(u32 *const *clk_domains,
 	u32 i, max = 100;
 
 	/* Put the clock domains in SW_WKUP mode */
-	for (i = 0; (i < max) && clk_domains[i]; i++) {
+	for (i = 0; (i < max) && clk_domains && clk_domains[i]; i++) {
 		enable_clock_domain(clk_domains[i],
 				    CD_CLKCTRL_CLKTRCTRL_SW_WKUP);
 	}
 
 	/* Clock modules that need to be put in SW_EXPLICIT_EN mode */
-	for (i = 0; (i < max) && clk_modules_explicit_en[i]; i++) {
+	for (i = 0; (i < max) && clk_modules_explicit_en &&
+	     clk_modules_explicit_en[i]; i++) {
 		enable_clock_module(clk_modules_explicit_en[i],
 				    MODULE_CLKCTRL_MODULEMODE_SW_EXPLICIT_EN,
 				    wait_for_enable);
@@ -215,12 +216,13 @@ void do_disable_clocks(u32 *const *clk_domains,
 
 
 	/* Clock modules that need to be put in SW_DISABLE */
-	for (i = 0; (i < max) && clk_modules_disable[i]; i++)
+	for (i = 0; (i < max) && clk_modules_disable && clk_modules_disable[i];
+	     i++)
 		disable_clock_module(clk_modules_disable[i],
 				     wait_for_disable);
 
 	/* Put the clock domains in SW_SLEEP mode */
-	for (i = 0; (i < max) && clk_domains[i]; i++)
+	for (i = 0; (i < max) && clk_domains && clk_domains[i]; i++)
 		disable_clock_domain(clk_domains[i]);
 }
 
Signature · 1 line
2.17.1
#3 lore raw

PATCH v2 11/30 clk: ti: add support for clkctrl clocks

In reply to Dario Binacchi

Until now the clkctrl clocks have been enabled/disabled through platform routines. Thanks to this patch they can be enabled and configured directly by the probed devices that need to use them.

---

(no changes since v1)

 doc/device-tree-bindings/clock/ti,clkctrl.txt |  61 +++++++++++
 drivers/clk/Kconfig                           |   6 ++
 drivers/clk/Makefile                          |   1 +
 drivers/clk/clk-ti-ctrl.c                     | 102 ++++++++++++++++++
 4 files changed, 170 insertions(+)
 create mode 100644 doc/device-tree-bindings/clock/ti,clkctrl.txt
 create mode 100644 drivers/clk/clk-ti-ctrl.c
doc/device-tree-bindings/clock/ti,clkctrl.txt new file +61 -0
new file mode 100644
index 0000000000..0f73f6295a
@@ -0,0 +1,61 @@
+Texas Instruments clkctrl clock binding
+
+Texas Instruments SoCs can have a clkctrl clock controller for each
+interconnect target module. The clkctrl clock controller manages functional
+and interface clocks for each module. Each clkctrl controller can also
+gate one or more optional functional clocks for a module, and can have one
+or more clock muxes. There is a clkctrl clock controller typically for each
+interconnect target module on omap4 and later variants.
+
+The clock consumers can specify the index of the clkctrl clock using
+the hardware offset from the clkctrl instance register space. The optional
+clocks can be specified by clkctrl hardware offset and the index of the
+optional clock.
+
+For more information, please see the Linux clock framework binding at
+doc/device-tree-bindings/clock/clock-bindings.txt.
+
+Required properties :
+- compatible : shall be "ti,clkctrl" or a clock domain specific name:
+	       "ti,clkctrl-l4-cfg"
+	       "ti,clkctrl-l4-per"
+	       "ti,clkctrl-l4-secure"
+	       "ti,clkctrl-l4-wkup"
+- #clock-cells : shall contain 2 with the first entry being the instance
+		 offset from the clock domain base and the second being the
+		 clock index
+- reg : clock registers
+
+Example: Clock controller node on omap 4430:
+
+&cm2 {
+	l4per: cm at 1400 {
+		cm_l4per at 0 {
+			cm_l4per_clkctrl: clock at 20 {
+				compatible = "ti,clkctrl-l4-per", "ti,clkctrl";
+				reg = <0x20 0x1b0>;
+				#clock-cells = <2>;
+			};
+		};
+	};
+};
+
+Example: Preprocessor helper macros in dt-bindings/clock/ti-clkctrl.h
+
+#define OMAP4_CLKCTRL_OFFSET		0x20
+#define OMAP4_CLKCTRL_INDEX(offset)	((offset) - OMAP4_CLKCTRL_OFFSET)
+#define MODULEMODE_HWCTRL		1
+#define MODULEMODE_SWCTRL		2
+
+#define OMAP4_GPTIMER10_CLKTRL		OMAP4_CLKCTRL_INDEX(0x28)
+#define OMAP4_GPTIMER11_CLKTRL		OMAP4_CLKCTRL_INDEX(0x30)
+#define OMAP4_GPTIMER2_CLKTRL		OMAP4_CLKCTRL_INDEX(0x38)
+...
+#define OMAP4_GPIO2_CLKCTRL		OMAP_CLKCTRL_INDEX(0x60)
+
+Example: Clock consumer node for GPIO2:
+
+&gpio2 {
+       clocks = <&cm_l4per_clkctrl OMAP4_GPIO2_CLKCTRL 0
+		 &cm_l4per_clkctrl OMAP4_GPIO2_CLKCTRL 8>;
+};
drivers/clk/Kconfig +6 -0
index c0528c2aeb..90c953667a 100644
@@ -105,6 +105,12 @@ config CLK_TI_AM3_DPLL
 	  This enables the DPLL clock drivers support on AM33XX SoCs. The DPLL
 	  provides all interface clocks and functional clocks to the processor.
 
+config CLK_TI_CTRL
+	bool "TI OMAP4 clock controller"
+	depends on CLK && OF_CONTROL
+	help
+	  This enables the clock controller driver support on TI's SoCs.
+
 config CLK_TI_DIVIDER
 	bool "TI divider clock driver"
 	depends on CLK && OF_CONTROL && CLK_CCF
drivers/clk/Makefile +1 -0
index 4d16fb7a50..cdc3102ad7 100644
@@ -48,6 +48,7 @@ obj-$(CONFIG_SANDBOX) += clk_sandbox_test.o
 obj-$(CONFIG_SANDBOX_CLK_CCF) += clk_sandbox_ccf.o
 obj-$(CONFIG_STM32H7) += clk_stm32h7.o
 obj-$(CONFIG_CLK_TI_AM3_DPLL) += clk-ti-am3-dpll.o clk-ti-am3-dpll-x2.o
+obj-$(CONFIG_CLK_TI_CTRL) += clk-ti-ctrl.o
 obj-$(CONFIG_CLK_TI_DIVIDER) += clk-ti-divider.o
 obj-$(CONFIG_CLK_TI_GATE) += clk-ti-gate.o
 obj-$(CONFIG_CLK_TI_MUX) += clk-ti-mux.o
drivers/clk/clk-ti-ctrl.c new file +102 -0

102 lines not on this page · raw message

Signature · 1 line
2.17.1
#4 lore raw

PATCH v2 12/30 clk: ti: move drivers to 'ti' directory

In reply to Dario Binacchi

Add drivers/clk/ti/ folder and move all TI's code in this folder for better maintenance.

---

(no changes since v1)

 drivers/clk/Kconfig                           | 40 +-----------------
 drivers/clk/Makefile                          |  8 +---
 drivers/clk/ti/Kconfig                        | 42 +++++++++++++++++++
 drivers/clk/ti/Makefile                       | 12 ++++++
 .../clk-am3-dpll-x2.c}                        |  0
 .../{clk-ti-am3-dpll.c => ti/clk-am3-dpll.c}  |  0
 drivers/clk/{clk-ti-ctrl.c => ti/clk-ctrl.c}  |  0
 .../{clk-ti-divider.c => ti/clk-divider.c}    |  2 +-
 drivers/clk/{clk-ti-gate.c => ti/clk-gate.c}  |  0
 drivers/clk/{clk-ti-mux.c => ti/clk-mux.c}    |  2 +-
 drivers/clk/{clk-ti-sci.c => ti/clk-sci.c}    |  0
 drivers/clk/{clk-ti.c => ti/clk.c}            |  2 +-
 drivers/clk/{clk-ti.h => ti/clk.h}            |  0
 13 files changed, 59 insertions(+), 49 deletions(-)
 create mode 100644 drivers/clk/ti/Kconfig
 create mode 100644 drivers/clk/ti/Makefile
 rename drivers/clk/{clk-ti-am3-dpll-x2.c => ti/clk-am3-dpll-x2.c} (100%)
 rename drivers/clk/{clk-ti-am3-dpll.c => ti/clk-am3-dpll.c} (100%)
 rename drivers/clk/{clk-ti-ctrl.c => ti/clk-ctrl.c} (100%)
 rename drivers/clk/{clk-ti-divider.c => ti/clk-divider.c} (99%)
 rename drivers/clk/{clk-ti-gate.c => ti/clk-gate.c} (100%)
 rename drivers/clk/{clk-ti-mux.c => ti/clk-mux.c} (99%)
 rename drivers/clk/{clk-ti-sci.c => ti/clk-sci.c} (100%)
 rename drivers/clk/{clk-ti.c => ti/clk.c} (96%)
 rename drivers/clk/{clk-ti.h => ti/clk.h} (100%)
drivers/clk/Kconfig +1 -39
index 90c953667a..42ed6939e6 100644
@@ -98,45 +98,6 @@ config CLK_STM32F
 	  This clock driver adds support for RCC clock management
 	  for STM32F4 and STM32F7 SoCs.
 
-config CLK_TI_AM3_DPLL
-	bool "TI AM33XX Digital Phase-Locked Loop (DPLL) clock drivers"
-	depends on CLK && OF_CONTROL
-	help
-	  This enables the DPLL clock drivers support on AM33XX SoCs. The DPLL
-	  provides all interface clocks and functional clocks to the processor.
-
-config CLK_TI_CTRL
-	bool "TI OMAP4 clock controller"
-	depends on CLK && OF_CONTROL
-	help
-	  This enables the clock controller driver support on TI's SoCs.
-
-config CLK_TI_DIVIDER
-	bool "TI divider clock driver"
-	depends on CLK && OF_CONTROL && CLK_CCF
-	help
-	  This enables the divider clock driver support on TI's SoCs.
-
-config CLK_TI_GATE
-	bool "TI gate clock driver"
-	depends on CLK && OF_CONTROL
-	help
-	  This enables the gate clock driver support on TI's SoCs.
-
-config CLK_TI_MUX
-	bool "TI mux clock driver"
-	depends on CLK && OF_CONTROL && CLK_CCF
-	help
-	  This enables the mux clock driver support on TI's SoCs.
-
-config CLK_TI_SCI
-	bool "TI System Control Interface (TI SCI) clock driver"
-	depends on CLK && TI_SCI_PROTOCOL && OF_CONTROL
-	help
-	  This enables the clock driver support over TI System Control Interface
-	  available on some new TI's SoCs. If you wish to use clock resources
-	  managed by the TI System Controller, say Y here. Otherwise, say N.
-
 config CLK_HSDK
 	bool "Enable cgu clock driver for HSDK boards"
 	depends on CLK && TARGET_HSDK
@@ -201,6 +162,7 @@ source "drivers/clk/owl/Kconfig"
 source "drivers/clk/renesas/Kconfig"
 source "drivers/clk/sunxi/Kconfig"
 source "drivers/clk/sifive/Kconfig"
+source "drivers/clk/ti/Kconfig"
 source "drivers/clk/tegra/Kconfig"
 source "drivers/clk/uniphier/Kconfig"
 
drivers/clk/Makefile +1 -7
index cdc3102ad7..e48e17479f 100644
@@ -13,12 +13,12 @@ obj-$(CONFIG_$(SPL_TPL_)CLK_COMPOSITE_CCF) += clk-composite.o
 
 obj-y += analogbits/
 obj-y += imx/
+obj-y += ti/
 obj-y += tegra/
 obj-$(CONFIG_ARCH_ASPEED) += aspeed/
 obj-$(CONFIG_ARCH_MEDIATEK) += mediatek/
 obj-$(CONFIG_ARCH_MTMIPS) += mtmips/
 obj-$(CONFIG_ARCH_MESON) += meson/
-obj-$(CONFIG_ARCH_OMAP2PLUS) += clk-ti.o
 obj-$(CONFIG_ARCH_ROCKCHIP) += rockchip/
 obj-$(CONFIG_ARCH_SOCFPGA) += altera/
 obj-$(CONFIG_CLK_AT91) += at91/
@@ -47,11 +47,5 @@ obj-$(CONFIG_SANDBOX) += clk_sandbox.o
 obj-$(CONFIG_SANDBOX) += clk_sandbox_test.o
 obj-$(CONFIG_SANDBOX_CLK_CCF) += clk_sandbox_ccf.o
 obj-$(CONFIG_STM32H7) += clk_stm32h7.o
-obj-$(CONFIG_CLK_TI_AM3_DPLL) += clk-ti-am3-dpll.o clk-ti-am3-dpll-x2.o
-obj-$(CONFIG_CLK_TI_CTRL) += clk-ti-ctrl.o
-obj-$(CONFIG_CLK_TI_DIVIDER) += clk-ti-divider.o
-obj-$(CONFIG_CLK_TI_GATE) += clk-ti-gate.o
-obj-$(CONFIG_CLK_TI_MUX) += clk-ti-mux.o
-obj-$(CONFIG_CLK_TI_SCI) += clk-ti-sci.o
 obj-$(CONFIG_CLK_VERSAL) += clk_versal.o
 obj-$(CONFIG_CLK_CDCE9XX) += clk-cdce9xx.o
drivers/clk/ti/Kconfig new file +42 -0

42 lines not on this page · raw message

drivers/clk/ti/Makefile new file +12 -0
new file mode 100644
index 0000000000..a279a2838d
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (C) 2020 Dario Binacchi <[email protected]>
+#
+
+obj-$(CONFIG_ARCH_OMAP2PLUS) += clk.o
+obj-$(CONFIG_CLK_TI_AM3_DPLL) += clk-am3-dpll.o clk-am3-dpll-x2.o
+obj-$(CONFIG_CLK_TI_CTRL) += clk-ctrl.o
+obj-$(CONFIG_CLK_TI_DIVIDER) += clk-divider.o
+obj-$(CONFIG_CLK_TI_GATE) += clk-gate.o
+obj-$(CONFIG_CLK_TI_MUX) += clk-mux.o
+obj-$(CONFIG_CLK_TI_SCI) += clk-sci.o
drivers/clk/ti/clk-am3-dpll-x2.c renamed from drivers/clk/clk-ti-am3-dpll-x2.c +0 -0
similarity index 100%
rename from drivers/clk/clk-ti-am3-dpll-x2.c
rename to drivers/clk/ti/clk-am3-dpll-x2.c
drivers/clk/ti/clk-am3-dpll.c renamed from drivers/clk/clk-ti-am3-dpll.c +0 -0
similarity index 100%
rename from drivers/clk/clk-ti-am3-dpll.c
rename to drivers/clk/ti/clk-am3-dpll.c
drivers/clk/ti/clk-ctrl.c renamed from drivers/clk/clk-ti-ctrl.c +0 -0
similarity index 100%
rename from drivers/clk/clk-ti-ctrl.c
rename to drivers/clk/ti/clk-ctrl.c
drivers/clk/ti/clk-divider.c renamed from drivers/clk/clk-ti-divider.c +1 -1
similarity index 99%
rename from drivers/clk/clk-ti-divider.c
rename to drivers/clk/ti/clk-divider.c
index e89650883b..6c5c47f568 100644
@@ -16,7 +16,7 @@
 #include <linux/clk-provider.h>
 #include <linux/kernel.h>
 #include <linux/log2.h>
-#include "clk-ti.h"
+#include "clk.h"
 
 /*
  * The reverse of DIV_ROUND_UP: The maximum number which
drivers/clk/ti/clk-gate.c renamed from drivers/clk/clk-ti-gate.c +0 -0
similarity index 100%
rename from drivers/clk/clk-ti-gate.c
rename to drivers/clk/ti/clk-gate.c
drivers/clk/ti/clk-mux.c renamed from drivers/clk/clk-ti-mux.c +1 -1
similarity index 99%
rename from drivers/clk/clk-ti-mux.c
rename to drivers/clk/ti/clk-mux.c
index e4b190bbcc..a3ebef251c 100644
@@ -12,7 +12,7 @@
 #include <clk-uclass.h>
 #include <asm/io.h>
 #include <linux/clk-provider.h>
-#include "clk-ti.h"
+#include "clk.h"
 
 struct clk_ti_mux_priv {
 	struct clk_bulk parents;
drivers/clk/ti/clk-sci.c renamed from drivers/clk/clk-ti-sci.c +0 -0
similarity index 100%
rename from drivers/clk/clk-ti-sci.c
rename to drivers/clk/ti/clk-sci.c
drivers/clk/ti/clk.c renamed from drivers/clk/clk-ti.c +1 -1
similarity index 96%
rename from drivers/clk/clk-ti.c
rename to drivers/clk/ti/clk.c
index 594ef75270..e44b90ad6a 100644
@@ -7,7 +7,7 @@
 
 #include <common.h>
 #include <asm/io.h>
-#include "clk-ti.h"
+#include "clk.h"
 
 static void clk_ti_rmw(u32 val, u32 mask, fdt_addr_t reg)
 {
drivers/clk/ti/clk.h renamed from drivers/clk/clk-ti.h +0 -0
similarity index 100%
rename from drivers/clk/clk-ti.h
rename to drivers/clk/ti/clk.h
Signature · 1 line
2.17.1
#5 lore raw

PATCH v2 13/30 clk: ti: omap4: add clock manager driver

In reply to Dario Binacchi

This minimal driver is only used to bind child devices.

---

(no changes since v1)

 doc/device-tree-bindings/arm/omap,prcm.txt | 63 ++++++++++++++++++++++
 drivers/clk/ti/Makefile                    |  2 +-
 drivers/clk/ti/omap4-cm.c                  | 22 ++++++++
 3 files changed, 86 insertions(+), 1 deletion(-)
 create mode 100644 doc/device-tree-bindings/arm/omap,prcm.txt
 create mode 100644 drivers/clk/ti/omap4-cm.c
doc/device-tree-bindings/arm/omap,prcm.txt new file +63 -0
new file mode 100644
index 0000000000..123b17bd84
@@ -0,0 +1,63 @@
+OMAP PRCM bindings
+
+Power Reset and Clock Manager lists the device clocks and clockdomains under
+a DT hierarchy. Each TI SoC can have multiple PRCM entities listed for it,
+each describing one module and the clock hierarchy under it. see [1] for
+documentation about the individual clock/clockdomain nodes.
+
+[1] doc/device-tree-bindings/clock/ti,*.txt
+
+Required properties:
+- compatible:	Must be one of:
+		"ti,am3-prcm"
+		"ti,am4-prcm"
+		"ti,omap2-prcm"
+		"ti,omap3-prm"
+		"ti,omap3-cm"
+		"ti,omap4-cm1"
+		"ti,omap4-prm"
+		"ti,omap4-cm2"
+		"ti,omap4-scrm"
+		"ti,omap5-prm"
+		"ti,omap5-cm-core-aon"
+		"ti,omap5-scrm"
+		"ti,omap5-cm-core"
+		"ti,dra7-prm"
+		"ti,dra7-cm-core-aon"
+		"ti,dra7-cm-core"
+		"ti,dm814-prcm"
+		"ti,dm816-prcm"
+- reg:		Contains PRCM module register address range
+		(base address and length)
+- clocks:	clocks for this module
+- clockdomains:	clockdomains for this module
+
+Example:
+
+cm: cm at 48004000 {
+	compatible = "ti,omap3-cm";
+	reg = <0x48004000 0x4000>;
+
+	cm_clocks: clocks {
+		#address-cells = <1>;
+		#size-cells = <0>;
+	};
+
+	cm_clockdomains: clockdomains {
+	};
+}
+
+&cm_clocks {
+	omap2_32k_fck: omap_32k_fck {
+		#clock-cells = <0>;
+		compatible = "fixed-clock";
+		clock-frequency = <32768>;
+	};
+};
+
+&cm_clockdomains {
+	core_l3_clkdm: core_l3_clkdm {
+		compatible = "ti,clockdomain";
+		clocks = <&sdrc_ick>;
+	};
+};
drivers/clk/ti/Makefile +1 -1
index a279a2838d..0b7e61cdf7 100644
@@ -3,7 +3,7 @@
 # Copyright (C) 2020 Dario Binacchi <[email protected]>
 #
 
-obj-$(CONFIG_ARCH_OMAP2PLUS) += clk.o
+obj-$(CONFIG_ARCH_OMAP2PLUS) += clk.o omap4-cm.o
 obj-$(CONFIG_CLK_TI_AM3_DPLL) += clk-am3-dpll.o clk-am3-dpll-x2.o
 obj-$(CONFIG_CLK_TI_CTRL) += clk-ctrl.o
 obj-$(CONFIG_CLK_TI_DIVIDER) += clk-divider.o
drivers/clk/ti/omap4-cm.c new file +22 -0
new file mode 100644
index 0000000000..3cdc9b2888
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * OMAP4 clock manager (cm)
+ *
+ * Copyright (C) 2020 Dario Binacchi <[email protected]>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <dm/lists.h>
+
+static const struct udevice_id ti_omap4_cm_ids[] = {
+	{.compatible = "ti,omap4-cm"},
+	{}
+};
+
+U_BOOT_DRIVER(ti_omap4_cm) = {
+	.name = "ti_omap4_cm",
+	.id = UCLASS_SIMPLE_BUS,
+	.of_match = ti_omap4_cm_ids,
+	.bind = dm_scan_fdt_dev,
+};
Signature · 1 line
2.17.1
#6 lore raw

PATCH v2 14/30 clk: ti: am335x: add clock manager driver

In reply to Dario Binacchi

The implementation of this driver was needed to bind the sub-nodes of the 'clocks' node. In fact, the lack of the compatible property in the 'clocks' node does not allow the generic 'simple-bus' driver to bind the 'clocks' node and in turn its sub-nodes.
The 'prcm at 200000' node is therefore the node closest to the 'clocks' node whose driver can bind all the 'clocks' sub-nodes. In this way, the address translation functions are able to walk along the device tree towards the upper nodes until the address composition is completed.

prcm: prcm at 200000 {
	compatible = "ti,am3-prcm", "simple-bus";
	reg = <0x200000 0x4000>;
	#address-cells = <1>;
	#size-cells = <1>;
	ranges = <0 0x200000 0x4000>;

	prcm_clocks: clocks {
		#address-cells = <1>;
		#size-cells = <0>;
	};

	prcm_clockdomains: clockdomains {
	};
};
&prcm_clocks {
	...
	dpll_core_ck: dpll_core_ck at 490 {
        	#clock-cells = <0>;
		compatible = "ti,am3-dpll-core-clock";
		clocks = <&sys_clkin_ck>, <&sys_clkin_ck>;
		reg = <0x0490>, <0x045c>, <0x0468>;
	};
	...
};

---

Changes in v2:
- Remove the 'ti_am3_prcm_clocks' driver. Handle 'prcm_clocks' node in the 'ti_am3_prcm' driver.
- Update the commit message.

 drivers/clk/ti/Makefile   |  8 ++++-
 drivers/clk/ti/am3-prcm.c | 65 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+), 1 deletion(-)
 create mode 100644 drivers/clk/ti/am3-prcm.c
drivers/clk/ti/Makefile +7 -1
index 0b7e61cdf7..3d6e0cd79d 100644
@@ -3,7 +3,13 @@
 # Copyright (C) 2020 Dario Binacchi <[email protected]>
 #
 
-obj-$(CONFIG_ARCH_OMAP2PLUS) += clk.o omap4-cm.o
+ifeq ($(CONFIG_ARCH_OMAP2PLUS), y)
+
+obj-y += clk.o omap4-cm.o
+obj-$(CONFIG_AM33XX) += am3-prcm.o
+
+endif # CONFIG_ARCH_OMAP2PLUS
+
 obj-$(CONFIG_CLK_TI_AM3_DPLL) += clk-am3-dpll.o clk-am3-dpll-x2.o
 obj-$(CONFIG_CLK_TI_CTRL) += clk-ctrl.o
 obj-$(CONFIG_CLK_TI_DIVIDER) += clk-divider.o
drivers/clk/ti/am3-prcm.c new file +65 -0

65 lines not on this page · raw message

Signature · 1 line
2.17.1
#7 lore raw

PATCH v2 15/30 fdt: translate address if #size-cells = <0>

In reply to Dario Binacchi

The __of_translate_address routine translates an address from the device tree into a CPU physical address. A note in the description of the routine explains that the crossing of any level with #size-cells = <0> is to be considered an error not by specification but since inherited from IBM. This does not happen for Texas Instruments, or at least for the beaglebone device tree. Without this patch, in fact, the translation into physical addresses of the registers contained in the am33xx-clocks.dtsi nodes would not be possible. They all have a parent with #size-cells = <0>.

The CONFIG_OF_TRANSLATE_ZERO_SIZE_CELLS symbol makes translation possible even in the case of crossing levels with #size-cells = <0>.

The patch acts conservatively on address translation, except for removing a check within the of_translate_one function in the drivers/core/of_addr.c file:

+

        ranges = of_get_property(parent, rprop, &rlen);

- if (ranges == NULL && !of_empty_ranges_quirk(parent)) {
- debug("no ranges; cannot translate\n");
- return 1;
- }

        if (ranges == NULL || rlen == 0) {
                offset = of_read_number(addr, na);
                memset(addr, 0, pna * 4);
		debug("empty ranges; 1:1 translation\n");

There are two reasons:
1 The function of_empty_ranges_quirk always returns false, invalidating
the following if statement in case of null ranges. Therefore one of the two checks is useless.

2 The implementation of the of_translate_one function found in the
common/fdt_support.c file has removed this check while keeping the one about the 1:1 translation.

The patch adds a test and modifies a check for the correctness of an address in the case of enabling translation also for zero size cells. The added test checks translations of addresses generated by nodes of a device tree similar to those you can find in the files am33xx.dtsi and am33xx-clocks.dtsi for which the patch was created.

The patch was also tested on a beaglebone black board. The addresses generated for the registers of the loaded drivers are those specified by the AM335x reference manual.

---

Changes in v2:
- Fix a missing line in the commit message.
- Add dm_flags to global_data structure and GD_DM_FLG_SIZE_CELLS_0 macro to test without recompiling.
- Update the OF_CHECK_COUNTS macro in order to have just one #define by bringing the GD_DM_FLG_SIZE_CELLS_0 into the expression.
- Lower-case the 0xC019 hex number.

 arch/sandbox/dts/test.dts         | 21 ++++++++++
 common/fdt_support.c              |  6 ++-
 drivers/core/Kconfig              | 12 ++++++
 drivers/core/fdtaddr.c            |  2 +-
 drivers/core/of_addr.c            | 14 ++-----
 drivers/core/ofnode.c             |  7 +++-
 drivers/core/root.c               |  3 ++
 include/asm-generic/global_data.h |  6 +++
 test/dm/test-fdt.c                | 68 ++++++++++++++++++++++++++++++-
 9 files changed, 123 insertions(+), 16 deletions(-)
arch/sandbox/dts/test.dts +21 -0
index 9f45c48e4e..af701d2086 100644
@@ -39,6 +39,7 @@
 		fdt-dummy1 = "/translation-test at 8000/dev at 1,100";
 		fdt-dummy2 = "/translation-test at 8000/dev at 2,200";
 		fdt-dummy3 = "/translation-test at 8000/noxlatebus at 3,300/dev at 42";
+		fdt-dummy4 = "/translation-test at 8000/xlatebus at 4,400/devs/dev at 19";
 		usb0 = &usb_0;
 		usb1 = &usb_1;
 		usb2 = &usb_2;
@@ -978,6 +979,7 @@
 			  1 0x100 0x9000 0x1000
 			  2 0x200 0xA000 0x1000
 			  3 0x300 0xB000 0x1000
+			  4 0x400 0xC000 0x1000
 			 >;
 
 		dma-ranges = <0 0x000 0x10000000 0x1000
@@ -1014,6 +1016,25 @@
 				reg = <0x42>;
 			};
 		};
+
+		xlatebus at 4,400 {
+			compatible = "sandbox,zero-size-cells-bus";
+			reg = <4 0x400 0x1000>;
+			#address-cells = <1>;
+			#size-cells = <1>;
+			ranges = <0 4 0x400 0x1000>;
+
+			devs {
+				#address-cells = <1>;
+				#size-cells = <0>;
+
+				dev at 19 {
+					compatible = "denx,u-boot-fdt-dummy";
+					reg = <0x19>;
+				};
+			};
+		};
+
 	};
 
 	osd {
common/fdt_support.c +4 -2
index a565b470f8..d8cf6f5725 100644
@@ -20,6 +20,8 @@
 #include <exports.h>
 #include <fdtdec.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
 /**
  * fdt_getprop_u32_default_node - Return a node's property or a default
  *
@@ -1001,8 +1003,8 @@ void fdt_del_node_and_alias(void *blob, const char *alias)
 /* Max address size we deal with */
 #define OF_MAX_ADDR_CELLS	4
 #define OF_BAD_ADDR	FDT_ADDR_T_NONE
-#define OF_CHECK_COUNTS(na, ns)	((na) > 0 && (na) <= OF_MAX_ADDR_CELLS && \
-			(ns) > 0)
+#define OF_CHECK_COUNTS(na, ns) (((na) > 0 && (na) <= OF_MAX_ADDR_CELLS) && \
+			 ((ns) > 0 || (gd->dm_flags & GD_DM_FLG_SIZE_CELLS_0)))
 
 /* Debug utility */
 #ifdef DEBUG
drivers/core/Kconfig +12 -0
index 00d1d80dc3..2a683ae404 100644
@@ -217,6 +217,18 @@ config OF_TRANSLATE
 	  used for the address translation. This function is faster and
 	  smaller in size than fdt_translate_address().
 
+config OF_TRANSLATE_ZERO_SIZE_CELLS
+	bool "Enable translation for zero size cells"
+	depends on OF_TRANSLATE
+	default n
+	help
+	  The routine used to translate an FDT address into a physical CPU
+	  address was developed by IBM. It considers that crossing any level
+	  with #size-cells = <0> makes translation impossible, even if it is
+	  not the way it was specified.
+	  Enabling this option makes translation possible even in the case
+	  of crossing levels with #size-cells = <0>.
+
 config SPL_OF_TRANSLATE
 	bool "Translate addresses using fdt_translate_address in SPL"
 	depends on SPL_DM && SPL_OF_CONTROL
drivers/core/fdtaddr.c +1 -1
index 8b48aa5bc5..51a0093d65 100644
@@ -49,7 +49,7 @@ fdt_addr_t devfdt_get_addr_index(const struct udevice *dev, int index)
 
 		reg += index * (na + ns);
 
-		if (ns) {
+		if (ns || (gd->dm_flags & GD_DM_FLG_SIZE_CELLS_0)) {
 			/*
 			 * Use the full-fledged translate function for complex
 			 * bus setups.
drivers/core/of_addr.c +4 -10
index ca34d84922..a590533c8a 100644
@@ -18,7 +18,9 @@
 /* Max address size we deal with */
 #define OF_MAX_ADDR_CELLS	4
 #define OF_CHECK_ADDR_COUNT(na)	((na) > 0 && (na) <= OF_MAX_ADDR_CELLS)
-#define OF_CHECK_COUNTS(na, ns)	(OF_CHECK_ADDR_COUNT(na) && (ns) > 0)
+#define OF_CHECK_COUNTS(na, ns)	(OF_CHECK_ADDR_COUNT(na) && \
+				 ((ns) > 0 || \
+				  (gd->dm_flags & GD_DM_FLG_SIZE_CELLS_0)))
 
 static struct of_bus *of_match_bus(struct device_node *np);
 
@@ -162,11 +164,6 @@ const __be32 *of_get_address(const struct device_node *dev, int index,
 }
 EXPORT_SYMBOL(of_get_address);
 
-static int of_empty_ranges_quirk(const struct device_node *np)
-{
-	return false;
-}
-
 static int of_translate_one(const struct device_node *parent,
 			    struct of_bus *bus, struct of_bus *pbus,
 			    __be32 *addr, int na, int ns, int pna,
@@ -193,11 +190,8 @@ static int of_translate_one(const struct device_node *parent,
 	 * As far as we know, this damage only exists on Apple machines, so
 	 * This code is only enabled on powerpc. --gcl
 	 */
+
 	ranges = of_get_property(parent, rprop, &rlen);
-	if (ranges == NULL && !of_empty_ranges_quirk(parent)) {
-		debug("no ranges; cannot translate\n");
-		return 1;
-	}
 	if (ranges == NULL || rlen == 0) {
 		offset = of_read_number(addr, na);
 		memset(addr, 0, pna * 4);
drivers/core/ofnode.c +5 -2
index d02d8d33fe..ab97332f1d 100644
@@ -304,7 +304,8 @@ fdt_addr_t ofnode_get_addr_size_index(ofnode node, int index, fdt_size_t *size)
 
 		ns = of_n_size_cells(ofnode_to_np(node));
 
-		if (IS_ENABLED(CONFIG_OF_TRANSLATE) && ns > 0) {
+		if (IS_ENABLED(CONFIG_OF_TRANSLATE) &&
+		    (ns > 0 || (gd->dm_flags & GD_DM_FLG_SIZE_CELLS_0))) {
 			return of_translate_address(ofnode_to_np(node), prop_val);
 		} else {
 			na = of_n_addr_cells(ofnode_to_np(node));
@@ -655,8 +656,10 @@ fdt_addr_t ofnode_get_addr_size(ofnode node, const char *property,
 		ns = of_n_size_cells(np);
 		*sizep = of_read_number(prop + na, ns);
 
-		if (CONFIG_IS_ENABLED(OF_TRANSLATE) && ns > 0)
+		if (CONFIG_IS_ENABLED(OF_TRANSLATE) &&
+		    (ns > 0 || (gd->dm_flags & GD_DM_FLG_SIZE_CELLS_0))) {
 			return of_translate_address(np, prop);
+		}
 		else
 			return of_read_number(prop, na);
 	} else {
drivers/core/root.c +3 -0
index 0726be6b79..193164238a 100644
@@ -135,6 +135,9 @@ int dm_init(bool of_live)
 {
 	int ret;
 
+	if (IS_ENABLED(CONFIG_OF_TRANSLATE_ZERO_SIZE_CELLS))
+		gd->dm_flags |= GD_DM_FLG_SIZE_CELLS_0;
+
 	if (gd->dm_root) {
 		dm_warn("Virtual root driver already exists!\n");
 		return -EINVAL;
include/asm-generic/global_data.h +6 -0
index d4a4e2215d..d0014e812c 100644
@@ -64,6 +64,7 @@ typedef struct global_data {
 	struct global_data *new_gd;	/* relocated global data */
 
 #ifdef CONFIG_DM
+	unsigned long dm_flags;
 	struct udevice	*dm_root;	/* Root instance for Driver Model */
 	struct udevice	*dm_root_f;	/* Pre-relocation root instance */
 	struct list_head uclass_root;	/* Head of core tree */
@@ -169,4 +170,9 @@ typedef struct global_data {
 #define GD_FLG_SKIP_LL_INIT	0x20000	/* Don't perform low-level init	   */
 #define GD_FLG_SMP_READY	0x40000	/* SMP init is complete		   */
 
+/*
+ * Global Data Driver Model Flags
+ */
+#define GD_DM_FLG_SIZE_CELLS_0	0x00001	/* Enable #size-cells=<0> translation */
+
 #endif /* __ASM_GENERIC_GBL_DATA_H */
test/dm/test-fdt.c +67 -1

84 lines not on this page · raw message

Signature · 1 line
2.17.1
#8 lore raw

PATCH v2 15/30 fdt: translate address if #size-cells = <0>

Hi Dario,

Quoted 61 lines · Dario Binacchi

The __of_translate_address routine translates an address from the device tree into a CPU physical address. A note in the description of the routine explains that the crossing of any level with #size-cells = <0> is to be considered an error not by specification but since inherited from IBM. This does not happen for Texas Instruments, or at least for the beaglebone device tree. Without this patch, in fact, the translation into physical addresses of the registers contained in the am33xx-clocks.dtsi nodes would not be possible. They all have a parent with #size-cells = <0>.

The CONFIG_OF_TRANSLATE_ZERO_SIZE_CELLS symbol makes translation possible even in the case of crossing levels with #size-cells = <0>.

The patch acts conservatively on address translation, except for removing a check within the of_translate_one function in the drivers/core/of_addr.c file:

drivers/core/of_addr.c +1 -4
+
        ranges = of_get_property(parent, rprop, &rlen);
-       if (ranges == NULL && !of_empty_ranges_quirk(parent)) {
-               debug("no ranges; cannot translate\n");
-               return 1;
-       }
        if (ranges == NULL || rlen == 0) {
                offset = of_read_number(addr, na);
                memset(addr, 0, pna * 4);
                debug("empty ranges; 1:1 translation\n");

There are two reasons:
1 The function of_empty_ranges_quirk always returns false, invalidating
the following if statement in case of null ranges. Therefore one of the two checks is useless.

2 The implementation of the of_translate_one function found in the
common/fdt_support.c file has removed this check while keeping the one about the 1:1 translation.

The patch adds a test and modifies a check for the correctness of an address in the case of enabling translation also for zero size cells. The added test checks translations of addresses generated by nodes of a device tree similar to those you can find in the files am33xx.dtsi and am33xx-clocks.dtsi for which the patch was created.

The patch was also tested on a beaglebone black board. The addresses generated for the registers of the loaded drivers are those specified by the AM335x reference manual.

---

Changes in v2:
- Fix a missing line in the commit message.
- Add dm_flags to global_data structure and GD_DM_FLG_SIZE_CELLS_0 macro to test without recompiling.
- Update the OF_CHECK_COUNTS macro in order to have just one #define by bringing the GD_DM_FLG_SIZE_CELLS_0 into the expression.
- Lower-case the 0xC019 hex number.

Quoted 10 lines
 arch/sandbox/dts/test.dts         | 21 ++++++++++
 common/fdt_support.c              |  6 ++-
 drivers/core/Kconfig              | 12 ++++++
 drivers/core/fdtaddr.c            |  2 +-
 drivers/core/of_addr.c            | 14 ++-----
 drivers/core/ofnode.c             |  7 +++-
 drivers/core/root.c               |  3 ++
 include/asm-generic/global_data.h |  6 +++
 test/dm/test-fdt.c                | 68 ++++++++++++++++++++++++++++++-
 9 files changed, 123 insertions(+), 16 deletions(-)

Looks very nice.

+Stefan Roese as an example of using run-time control in tests to handle both cases in sandbox.

Nit below

[..]

include/asm-generic/global_data.h typedef struct global_data { · line 67

Quoted 9 lines
include/asm-generic/global_data.h +1 -0
index d4a4e2215d..d0014e812c 100644
@@ -64,6 +64,7 @@ typedef struct global_data {
        struct global_data *new_gd;     /* relocated global data */
 
 #ifdef CONFIG_DM
+       unsigned long dm_flags;

comment

include/asm-generic/global_data.h typedef struct global_data { · line 178

Quoted 13 lines
include/asm-generic/global_data.h +5 -0
        struct udevice  *dm_root;       /* Root instance for Driver Model */
        struct udevice  *dm_root_f;     /* Pre-relocation root instance */
        struct list_head uclass_root;   /* Head of core tree */
@@ -169,4 +170,9 @@ typedef struct global_data {
 #define GD_FLG_SKIP_LL_INIT    0x20000 /* Don't perform low-level init    */
 #define GD_FLG_SMP_READY       0x40000 /* SMP init is complete            */
 
+/*
+ * Global Data Driver Model Flags
+ */
+#define GD_DM_FLG_SIZE_CELLS_0 0x00001 /* Enable #size-cells=<0> translation */
+
 #endif /* __ASM_GENERIC_GBL_DATA_H */

Regards,
Simon

#9 lore raw

PATCH v2 16/30 omap: timer: fix the rate setting

In reply to Dario Binacchi

The prescaler (PTV) setting must be taken into account even when the timer input clock frequency has been set.

---

(no changes since v1)

 drivers/timer/omap-timer.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/timer/omap-timer.c +3 -3
index cf3d27b96b..60af68e677 100644
@@ -19,8 +19,6 @@
 #define TCLR_PRE_EN			BIT(5)	/* Pre-scaler enable */
 #define TCLR_PTV_SHIFT			(2)	/* Pre-scaler shift value */
 
-#define TIMER_CLOCK             (V_SCLK / (2 << CONFIG_SYS_PTV))
-
 struct omap_gptimer_regs {
 	unsigned int tidr;		/* offset 0x00 */
 	unsigned char res1[12];
@@ -63,7 +61,9 @@ static int omap_timer_probe(struct udevice *dev)
 	struct omap_timer_priv *priv = dev_get_priv(dev);
 
 	if (!uc_priv->clock_rate)
-		uc_priv->clock_rate = TIMER_CLOCK;
+		uc_priv->clock_rate = V_SCLK;
+
+	uc_priv->clock_rate /= (2 << CONFIG_SYS_PTV);
 
 	/* start the counter ticking up, reload value on overflow */
 	writel(0, &priv->regs->tldr);
Signature · 1 line
2.17.1
#10 lore raw

PATCH v2 17/30 misc: am33xx: add control module driver

In reply to Dario Binacchi

The implementation of this driver was needed to bind the device tree sub-nodes of the 'clocks' node. In fact, the lack of the compatible property in the 'clocks' node does not allow the generic 'syscon' or 'simple-bus' drivers linked to the 'scm_conf at 0' node to bind the 'clocks' node and in turn its sub-nodes.
The 'scm at 210000' node is therefore the node closest to the 'clocks' node whose driver can bind all the 'clocks' sub-nodes. In this way, the address translation functions are able to walk along the device tree towards the upper nodes until the address composition is completed.

scm: scm at 210000 {
	compatible = "ti,am3-scm", "simple-bus";
	...

	scm_conf: scm_conf at 0 {
		compatible = "syscon", "simple-bus";
		#address-cells = <1>;
		#size-cells = <1>;
		ranges = <0 0 0x800>;

		scm_clocks: clocks {
			#address-cells = <1>;
			#size-cells = <0>;
		};
	};
};

---

Changes in v2:
- Remove the 'ti_am3_scm_clocks' driver. Handle 'scm_clocks' node in the 'ti_am3_scm' driver.
- Update the commit message.

 doc/device-tree-bindings/arm/omap,ctrl.txt    |  82 ++++++
 .../pinctrl/pinctrl-single.txt                | 255 ++++++++++++++++++
 drivers/misc/Kconfig                          |   7 +
 drivers/misc/Makefile                         |   1 +
 drivers/misc/ti-am3-scm.c                     |  81 ++++++
 5 files changed, 426 insertions(+)
 create mode 100644 doc/device-tree-bindings/arm/omap,ctrl.txt
 create mode 100644 doc/device-tree-bindings/pinctrl/pinctrl-single.txt
 create mode 100644 drivers/misc/ti-am3-scm.c
doc/device-tree-bindings/arm/omap,ctrl.txt new file +82 -0
new file mode 100644
index 0000000000..8efd321cfa
@@ -0,0 +1,82 @@
+OMAP Control Module bindings
+
+Control Module contains miscellaneous features under it based on SoC type.
+Pincontrol is one common feature, and it has a specialized support
+described in [1]. Typically some clock nodes are also under control module.
+Syscon is used to share register level access to drivers external to
+control module driver itself.
+
+See [2] for documentation about clock/clockdomain nodes.
+
+[1] doc/device-tree-bindings/pinctrl/pinctrl-single.txt
+[2] doc/device-tree-bindings/clock/ti,*.txt
+
+Required properties:
+- compatible:	Must be one of:
+		"ti,am3-scm"
+		"ti,am4-scm"
+		"ti,dm814-scrm"
+		"ti,dm816-scrm"
+		"ti,omap2-scm"
+		"ti,omap3-scm"
+		"ti,omap4-scm-core"
+		"ti,omap4-scm-padconf-core"
+		"ti,omap4-scm-wkup"
+		"ti,omap4-scm-padconf-wkup"
+		"ti,omap5-scm-core"
+		"ti,omap5-scm-padconf-core"
+		"ti,omap5-scm-wkup-pad-conf"
+		"ti,dra7-scm-core"
+- reg:		Contains Control Module register address range
+		(base address and length)
+
+Optional properties:
+- clocks:	clocks for this module
+- clockdomains:	clockdomains for this module
+
+Examples:
+
+scm: scm at 2000 {
+	compatible = "ti,omap3-scm", "simple-bus";
+	reg = <0x2000 0x2000>;
+	#address-cells = <1>;
+	#size-cells = <1>;
+	ranges = <0 0x2000 0x2000>;
+
+	omap3_pmx_core: pinmux at 30 {
+		compatible = "ti,omap3-padconf",
+			     "pinctrl-single";
+		reg = <0x30 0x230>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+		#interrupt-cells = <1>;
+		interrupt-controller;
+		pinctrl-single,register-width = <16>;
+		pinctrl-single,function-mask = <0xff1f>;
+	};
+
+	scm_conf: scm_conf at 270 {
+		compatible = "syscon";
+		reg = <0x270 0x330>;
+		#address-cells = <1>;
+		#size-cells = <1>;
+
+		scm_clocks: clocks {
+			#address-cells = <1>;
+			#size-cells = <0>;
+		};
+	};
+
+	scm_clockdomains: clockdomains {
+	};
+}
+
+&scm_clocks {
+	mcbsp5_mux_fck: mcbsp5_mux_fck {
+		#clock-cells = <0>;
+		compatible = "ti,composite-mux-clock";
+		clocks = <&core_96m_fck>, <&mcbsp_clks>;
+		ti,bit-shift = <4>;
+		reg = <0x02d8>;
+	};
+};
doc/device-tree-bindings/pinctrl/pinctrl-single.txt new file +255 -0

255 lines not on this page · raw message

drivers/misc/Kconfig +7 -0
index b67e906a76..9e8b676637 100644
@@ -500,4 +500,11 @@ config ESM_PMIC
 	  Support ESM (Error Signal Monitor) on PMIC devices. ESM is used
 	  typically to reboot the board in error condition.
 
+config TI_AM3_SCM
+	bool "AM33XX specific control module support (SCM)"
+	depends on ARCH_OMAP2PLUS
+	help
+	 The control module includes status and control logic not addressed
+	 within the peripherals or the rest of the device infrastructure.
+
 endmenu
drivers/misc/Makefile +1 -0
index 947bd3a647..056fb3b522 100644
@@ -75,3 +75,4 @@ obj-$(CONFIG_MICROCHIP_FLEXCOM) += microchip_flexcom.o
 obj-$(CONFIG_K3_AVS0) += k3_avs.o
 obj-$(CONFIG_ESM_K3) += k3_esm.o
 obj-$(CONFIG_ESM_PMIC) += esm_pmic.o
+obj-$(CONFIG_TI_AM3_SCM) += ti-am3-scm.o
drivers/misc/ti-am3-scm.c new file +81 -0

81 lines not on this page · raw message

Signature · 1 line
2.17.1
#11 lore raw

PATCH v2 18/30 pwm: ti: am33xx: add enhanced pwm driver

In reply to Dario Binacchi

Enhanced high resolution PWM module (EHRPWM) hardware can be used to generate PWM output over 2 channels. This commit adds PWM driver support for EHRPWM device present on AM33XX SOC.

The code is based on the drivers/pwm/pwm-tiehrpwm.c driver of the Linux kernel.

---

(no changes since v1)

 doc/device-tree-bindings/pwm/ti,ehrpwm.txt |  49 +++
 drivers/pwm/Kconfig                        |   6 +
 drivers/pwm/Makefile                       |   1 +
 drivers/pwm/pwm-ti-ehrpwm.c                | 465 +++++++++++++++++++++
 4 files changed, 521 insertions(+)
 create mode 100644 doc/device-tree-bindings/pwm/ti,ehrpwm.txt
 create mode 100644 drivers/pwm/pwm-ti-ehrpwm.c
doc/device-tree-bindings/pwm/ti,ehrpwm.txt new file +49 -0
new file mode 100644
index 0000000000..12f1e3bf80
@@ -0,0 +1,49 @@
+TI SOC EHRPWM based PWM controller
+
+Required properties:
+- compatible: Must be "ti,<soc>-ehrpwm".
+  for am33xx  - compatible = "ti,am3352-ehrpwm", "ti,am33xx-ehrpwm";
+  for am4372  - compatible = "ti,am4372-ehrpwm", "ti-am3352-ehrpwm", "ti,am33xx-ehrpwm";
+  for am654   - compatible = "ti,am654-ehrpwm", "ti-am3352-ehrpwm";
+  for da850   - compatible = "ti,da850-ehrpwm", "ti-am3352-ehrpwm", "ti,am33xx-ehrpwm";
+  for dra746 - compatible = "ti,dra746-ehrpwm", "ti-am3352-ehrpwm";
+- #pwm-cells: should be 3. The only third cell flag supported by this binding is
+  PWM_POLARITY_INVERTED.
+- reg: physical base address and size of the registers map.
+
+Optional properties:
+- clocks: Handle to the PWM's time-base and functional clock.
+- clock-names: Must be set to "tbclk" and "fck".
+
+Example:
+
+ehrpwm0: pwm at 48300200 { /* EHRPWM on am33xx */
+	compatible = "ti,am3352-ehrpwm", "ti,am33xx-ehrpwm";
+	#pwm-cells = <3>;
+	reg = <0x48300200 0x100>;
+	clocks = <&ehrpwm0_tbclk>, <&l4ls_gclk>;
+	clock-names = "tbclk", "fck";
+};
+
+ehrpwm0: pwm at 48300200 { /* EHRPWM on am4372 */
+	compatible = "ti,am4372-ehrpwm", "ti,am3352-ehrpwm", "ti,am33xx-ehrpwm";
+	#pwm-cells = <3>;
+	reg = <0x48300200 0x80>;
+	clocks = <&ehrpwm0_tbclk>, <&l4ls_gclk>;
+	clock-names = "tbclk", "fck";
+	ti,hwmods = "ehrpwm0";
+};
+
+ehrpwm0: pwm at 1f00000 { /* EHRPWM on da850 */
+	compatible = "ti,da850-ehrpwm", "ti,am3352-ehrpwm", "ti,am33xx-ehrpwm";
+	#pwm-cells = <3>;
+	reg = <0x1f00000 0x2000>;
+};
+
+ehrpwm0: pwm at 4843e200 { /* EHRPWM on dra746 */
+	compatible = "ti,dra746-ehrpwm", "ti,am3352-ehrpwm";
+	#pwm-cells = <3>;
+	reg = <0x4843e200 0x80>;
+	clocks = <&ehrpwm0_tbclk>, <&l4_root_clk_div>;
+	clock-names = "tbclk", "fck";
+};
drivers/pwm/Kconfig +6 -0
index 61eb468cde..e4ba8b3d80 100644
@@ -68,3 +68,9 @@ config PWM_SUNXI
 	help
 	  This PWM is found on H3, A64 and other Allwinner SoCs. It supports a
 	  programmable period and duty cycle. A 16-bit counter is used.
+
+config PWM_TI_EHRPWM
+	bool "Enable support for the AM335x EHRPWM"
+	depends on DM_PWM
+	help
+	  This enables the AM335x EHRPWM driver support on TI's SoCs.
drivers/pwm/Makefile +1 -0
index 0f4e84b04d..c5f88f7501 100644
@@ -18,3 +18,4 @@ obj-$(CONFIG_PWM_SANDBOX)	+= sandbox_pwm.o
 obj-$(CONFIG_PWM_SIFIVE)	+= pwm-sifive.o
 obj-$(CONFIG_PWM_TEGRA)		+= tegra_pwm.o
 obj-$(CONFIG_PWM_SUNXI)		+= sunxi_pwm.o
+obj-$(CONFIG_PWM_TI_EHRPWM)	+= pwm-ti-ehrpwm.o
drivers/pwm/pwm-ti-ehrpwm.c new file +465 -0

465 lines not on this page · raw message

Signature · 1 line
2.17.1
#12 lore raw

PATCH v2 19/30 pwm: ti: am33xx: add subsystem driver

In reply to Dario Binacchi

The TI PWMSS driver is a simple bus driver for providing clock and power management for the PWM peripherals on TI AM33xx SoCs, namely eCAP, eHRPWM and eQEP.

Based on more recent versions of the device tree inside the linux kernel, I added the clock domain for each subsystem in am33x.dtsi so it can be enabled before probing the peripheral child device and disabled after its removal.

---

(no changes since v1)

 arch/arm/dts/am33xx.dtsi                  |  9 +++
 doc/device-tree-bindings/pwm/ti,pwmss.txt | 58 ++++++++++++++
 drivers/pwm/Kconfig                       |  9 ++-
 drivers/pwm/Makefile                      |  1 +
 drivers/pwm/pwm-ti-pwmss.c                | 95 +++++++++++++++++++++++
 5 files changed, 171 insertions(+), 1 deletion(-)
 create mode 100644 doc/device-tree-bindings/pwm/ti,pwmss.txt
 create mode 100644 drivers/pwm/pwm-ti-pwmss.c
arch/arm/dts/am33xx.dtsi +9 -0
index d3dd6a16e7..fa7492a9b6 100644
@@ -758,6 +758,9 @@
 				  0x48300180 0x48300180 0x80   /* EQEP */
 				  0x48300200 0x48300200 0x80>; /* EHRPWM */
 
+			clocks = <&l4_per_clkctrl AM3_EPWMSS0_CLKCTRL 0>;
+			clock-names = "fck";
+
 			ecap0: ecap at 48300100 {
 				compatible = "ti,am3352-ecap",
 					     "ti,am33xx-ecap";
@@ -792,6 +795,9 @@
 				  0x48302180 0x48302180 0x80   /* EQEP */
 				  0x48302200 0x48302200 0x80>; /* EHRPWM */
 
+			clocks = <&l4_per_clkctrl AM3_EPWMSS1_CLKCTRL 0>;
+			clock-names = "fck";
+
 			ecap1: ecap at 48302100 {
 				compatible = "ti,am3352-ecap",
 					     "ti,am33xx-ecap";
@@ -826,6 +832,9 @@
 				  0x48304180 0x48304180 0x80   /* EQEP */
 				  0x48304200 0x48304200 0x80>; /* EHRPWM */
 
+			clocks = <&l4_per_clkctrl AM3_EPWMSS2_CLKCTRL 0>;
+			clock-names = "fck";
+
 			ecap2: ecap at 48304100 {
 				compatible = "ti,am3352-ecap",
 					     "ti,am33xx-ecap";
doc/device-tree-bindings/pwm/ti,pwmss.txt new file +58 -0

58 lines not on this page · raw message

drivers/pwm/Kconfig +8 -1
index e4ba8b3d80..129f5d77ca 100644
@@ -69,8 +69,15 @@ config PWM_SUNXI
 	  This PWM is found on H3, A64 and other Allwinner SoCs. It supports a
 	  programmable period and duty cycle. A 16-bit counter is used.
 
+config PWM_TI_PWMSS
+	bool "Enable support for the AM335x PWM Subsystem"
+	depends on DM_PWM
+	help
+	  This enables the AM335x PWM subsystem driver support on TI's SOCs.
+
 config PWM_TI_EHRPWM
 	bool "Enable support for the AM335x EHRPWM"
-	depends on DM_PWM
+	depends on PWM_TI_PWMSS
+	default y
 	help
 	  This enables the AM335x EHRPWM driver support on TI's SoCs.
drivers/pwm/Makefile +1 -0
index c5f88f7501..df9c54e764 100644
@@ -19,3 +19,4 @@ obj-$(CONFIG_PWM_SIFIVE)	+= pwm-sifive.o
 obj-$(CONFIG_PWM_TEGRA)		+= tegra_pwm.o
 obj-$(CONFIG_PWM_SUNXI)		+= sunxi_pwm.o
 obj-$(CONFIG_PWM_TI_EHRPWM)	+= pwm-ti-ehrpwm.o
+obj-$(CONFIG_PWM_TI_PWMSS)	+= pwm-ti-pwmss.o
drivers/pwm/pwm-ti-pwmss.c new file +95 -0

95 lines not on this page · raw message

Signature · 1 line
2.17.1
#13 lore raw

PATCH v2 19/30 pwm: ti: am33xx: add subsystem driver

Hi Dario,

Quoted 48 lines · Dario Binacchi

The TI PWMSS driver is a simple bus driver for providing clock and power management for the PWM peripherals on TI AM33xx SoCs, namely eCAP, eHRPWM and eQEP.

Based on more recent versions of the device tree inside the linux kernel, I added the clock domain for each subsystem in am33x.dtsi so it can be enabled before probing the peripheral child device and disabled after its removal.

---

(no changes since v1)

 arch/arm/dts/am33xx.dtsi                  |  9 +++
 doc/device-tree-bindings/pwm/ti,pwmss.txt | 58 ++++++++++++++
 drivers/pwm/Kconfig                       |  9 ++-
 drivers/pwm/Makefile                      |  1 +
 drivers/pwm/pwm-ti-pwmss.c                | 95 +++++++++++++++++++++++
 5 files changed, 171 insertions(+), 1 deletion(-)
 create mode 100644 doc/device-tree-bindings/pwm/ti,pwmss.txt
 create mode 100644 drivers/pwm/pwm-ti-pwmss.c
arch/arm/dts/am33xx.dtsi +6 -0
index d3dd6a16e7..fa7492a9b6 100644
@@ -758,6 +758,9 @@
 				  0x48300180 0x48300180 0x80   /* EQEP */
 				  0x48300200 0x48300200 0x80>; /* EHRPWM */
 
+			clocks = <&l4_per_clkctrl AM3_EPWMSS0_CLKCTRL 0>;
+			clock-names = "fck";
+
 			ecap0: ecap at 48300100 {
 				compatible = "ti,am3352-ecap",
 					     "ti,am33xx-ecap";
@@ -792,6 +795,9 @@
 				  0x48302180 0x48302180 0x80   /* EQEP */
 				  0x48302200 0x48302200 0x80>; /* EHRPWM */
 
+			clocks = <&l4_per_clkctrl AM3_EPWMSS1_CLKCTRL 0>;
+			clock-names = "fck";
+
 			ecap1: ecap at 48302100 {
 				compatible = "ti,am3352-ecap",
 					     "ti,am33xx-ecap";

arch/arm/dts/am33xx.dtsi line 836

Quoted 5 lines
arch/arm/dts/am33xx.dtsi +2 -0
@@ -826,6 +832,9 @@
 				  0x48304180 0x48304180 0x80   /* EQEP */
 				  0x48304200 0x48304200 0x80>; /* EHRPWM */
 
+			clocks = <&l4_per_clkctrl AM3_EPWMSS2_CLKCTRL 0>;
+			clock-names = "fck";

hmm..I do not see these changes in upstream kernel v5.9-rc3 DT. Which version of kernel are you using? I see al PWM nodes under am33xx-l4.dtsi

Quoted 170 lines
arch/arm/dts/am33xx.dtsi +1 -0
+
 			ecap2: ecap at 48304100 {
 				compatible = "ti,am3352-ecap",
 					     "ti,am33xx-ecap";
doc/device-tree-bindings/pwm/ti,pwmss.txt new file +58 -0
new file mode 100644
index 0000000000..4633697fbd
@@ -0,0 +1,58 @@
+TI SOC based PWM Subsystem
+
+Required properties:
+- compatible: Must be "ti,<soc>-pwmss".
+  for am33xx  - compatible = "ti,am33xx-pwmss";
+  for am4372  - compatible = "ti,am4372-pwmss","ti,am33xx-pwmss";
+  for dra746 - compatible = "ti,dra746-pwmss", "ti,am33xx-pwmss"
+
+- reg: physical base address and size of the registers map.
+- address-cells: Specify the number of u32 entries needed in child nodes.
+		  Should set to 1.
+- size-cells: specify number of u32 entries needed to specify child nodes size
+		in reg property. Should set to 1.
+- ranges: describes the address mapping of a memory-mapped bus. Should set to
+	   physical address map of child's base address, physical address within
+	   parent's address  space and length of the address map. For am33xx,
+	   3 set of child register maps present, ECAP register space, EQEP
+	   register space, EHRPWM register space.
+
+Also child nodes should also populated under PWMSS DT node.
+
+Example:
+epwmss0: epwmss at 48300000 { /* PWMSS for am33xx */
+	compatible = "ti,am33xx-pwmss";
+	reg = <0x48300000 0x10>;
+	ti,hwmods = "epwmss0";
+	#address-cells = <1>;
+	#size-cells = <1>;
+	ranges = <0x48300100 0x48300100 0x80   /* ECAP */
+		  0x48300180 0x48300180 0x80   /* EQEP */
+		  0x48300200 0x48300200 0x80>; /* EHRPWM */
+
+	/* child nodes go here */
+};
+
+epwmss0: epwmss at 48300000 { /* PWMSS for am4372 */
+	compatible = "ti,am4372-pwmss","ti,am33xx-pwmss"
+	reg = <0x48300000 0x10>;
+	ti,hwmods = "epwmss0";
+	#address-cells = <1>;
+	#size-cells = <1>;
+	ranges = <0x48300100 0x48300100 0x80   /* ECAP */
+		  0x48300180 0x48300180 0x80   /* EQEP */
+		  0x48300200 0x48300200 0x80>; /* EHRPWM */
+
+	/* child nodes go here */
+};
+
+epwmss0: epwmss at 4843e000 { /* PWMSS for DRA7xx */
+	compatible = "ti,dra746-pwmss", "ti,am33xx-pwmss";
+	reg = <0x4843e000 0x30>;
+	ti,hwmods = "epwmss0";
+	#address-cells = <1>;
+	#size-cells = <1>;
+	ranges;
+
+	/* child nodes go here */
+};
drivers/pwm/Kconfig +8 -1
index e4ba8b3d80..129f5d77ca 100644
@@ -69,8 +69,15 @@ config PWM_SUNXI
 	  This PWM is found on H3, A64 and other Allwinner SoCs. It supports a
 	  programmable period and duty cycle. A 16-bit counter is used.
 
+config PWM_TI_PWMSS
+	bool "Enable support for the AM335x PWM Subsystem"
+	depends on DM_PWM
+	help
+	  This enables the AM335x PWM subsystem driver support on TI's SOCs.
+
 config PWM_TI_EHRPWM
 	bool "Enable support for the AM335x EHRPWM"
-	depends on DM_PWM
+	depends on PWM_TI_PWMSS
+	default y
 	help
 	  This enables the AM335x EHRPWM driver support on TI's SoCs.
drivers/pwm/Makefile +1 -0
index c5f88f7501..df9c54e764 100644
@@ -19,3 +19,4 @@ obj-$(CONFIG_PWM_SIFIVE)	+= pwm-sifive.o
 obj-$(CONFIG_PWM_TEGRA)		+= tegra_pwm.o
 obj-$(CONFIG_PWM_SUNXI)		+= sunxi_pwm.o
 obj-$(CONFIG_PWM_TI_EHRPWM)	+= pwm-ti-ehrpwm.o
+obj-$(CONFIG_PWM_TI_PWMSS)	+= pwm-ti-pwmss.o
drivers/pwm/pwm-ti-pwmss.c new file +66 -0
new file mode 100644
index 0000000000..57f86512d6
@@ -0,0 +1,95 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Pulse-Width Modulation Subsystem (pwmss)
+ *
+ * Copyright (C) 2020 Dario Binacchi <[email protected]>
+ */
+#define DEBUG
+#undef CONFIG_LOGLEVEL
+#define CONFIG_LOGLEVEL 8
+
+#include <common.h>
+#include <clk.h>
+#include <dm.h>
+
+struct ti_pwmss_priv {
+	int child_count;
+	struct clk clkdm;
+};
+
+static const struct udevice_id ti_pwmss_ids[] = {
+	{.compatible = "ti,am33xx-pwmss"},
+	{}
+};
+
+static int ti_pwmss_child_post_remove(struct udevice *dev)
+{
+	struct ti_pwmss_priv *priv = dev_get_priv(dev->parent);
+	int err;
+
+	if (--priv->child_count > 0)
+		return 0;
+
+	err = clk_disable(&priv->clkdm);
+	if (err) {
+		dev_err(dev->parent, "%s: failed to disable clock domain\n",
+			__func__);
+		goto clkdm_disable_err;
+	}
+
+	err = clk_release_all(&priv->clkdm, 1);
+	if (err) {
+		dev_err(dev->parent, "%s: failed to release clock domain\n",
+			__func__);
+		goto clkdm_release_err;
+	}
+
+	return 0;
+
+clkdm_release_err:
+	clk_enable(&priv->clkdm);
+clkdm_disable_err:
+	priv->child_count++;
+	return err;
+}
+
+static int ti_pwmss_child_pre_probe(struct udevice *dev)
+{
+	struct ti_pwmss_priv *priv = dev_get_priv(dev->parent);
+	int err;
+
+	if (++priv->child_count > 1)
+		return 0;
+
+	err = clk_get_by_name(dev->parent, "fck", &priv->clkdm);
+	if (err) {
+		dev_err(dev->parent, "%s: failed to get clock domain\n",

drivers/pwm/pwm-ti-pwmss.c line 76

Quoted 10 lines
drivers/pwm/pwm-ti-pwmss.c new file +10 -0
+			__func__);
+		goto clkdm_get_err;
+	}
+
+	err = clk_enable(&priv->clkdm);
+	if (err) {
+		dev_err(dev->parent, "%s: failed to enable clock domain\n",
+			__func__);
+		goto clkdm_enable_err;
+	}

Do we need a whole subsystem driver just for enabling the clocks? Can't the same be happen in driver?

Thanks and regards,
Lokesh

#14 lore raw

PATCH v2 19/30 pwm: ti: am33xx: add subsystem driver

Hi Lokesh,

Quoted 57 lines

Il 07/09/2020 07:32 Lokesh Vutla <[email protected]> ha scritto:

Hi Dario,

Quoted 51 lines · Dario Binacchi

The TI PWMSS driver is a simple bus driver for providing clock and power management for the PWM peripherals on TI AM33xx SoCs, namely eCAP, eHRPWM and eQEP.

Based on more recent versions of the device tree inside the linux kernel, I added the clock domain for each subsystem in am33x.dtsi so it can be enabled before probing the peripheral child device and disabled after its removal.

---

(no changes since v1)

 arch/arm/dts/am33xx.dtsi                  |  9 +++
 doc/device-tree-bindings/pwm/ti,pwmss.txt | 58 ++++++++++++++
 drivers/pwm/Kconfig                       |  9 ++-
 drivers/pwm/Makefile                      |  1 +
 drivers/pwm/pwm-ti-pwmss.c                | 95 +++++++++++++++++++++++
 5 files changed, 171 insertions(+), 1 deletion(-)
 create mode 100644 doc/device-tree-bindings/pwm/ti,pwmss.txt
 create mode 100644 drivers/pwm/pwm-ti-pwmss.c
arch/arm/dts/am33xx.dtsi +6 -0
index d3dd6a16e7..fa7492a9b6 100644
@@ -758,6 +758,9 @@
 				  0x48300180 0x48300180 0x80   /* EQEP */
 				  0x48300200 0x48300200 0x80>; /* EHRPWM */
 
+			clocks = <&l4_per_clkctrl AM3_EPWMSS0_CLKCTRL 0>;
+			clock-names = "fck";
+
 			ecap0: ecap at 48300100 {
 				compatible = "ti,am3352-ecap",
 					     "ti,am33xx-ecap";
@@ -792,6 +795,9 @@
 				  0x48302180 0x48302180 0x80   /* EQEP */
 				  0x48302200 0x48302200 0x80>; /* EHRPWM */
 
+			clocks = <&l4_per_clkctrl AM3_EPWMSS1_CLKCTRL 0>;
+			clock-names = "fck";
+
 			ecap1: ecap at 48302100 {
 				compatible = "ti,am3352-ecap",
 					     "ti,am33xx-ecap";
@@ -826,6 +832,9 @@
 				  0x48304180 0x48304180 0x80   /* EQEP */
 				  0x48304200 0x48304200 0x80>; /* EHRPWM */
 
Quoted 7 lines

arch/arm/dts/am33xx.dtsi line 836

Quoted 2 lines
arch/arm/dts/am33xx.dtsi +2 -0
+			clocks = <&l4_per_clkctrl AM3_EPWMSS2_CLKCTRL 0>;
+			clock-names = "fck";

hmm..I do not see these changes in upstream kernel v5.9-rc3 DT. Which version of kernel are you using? I see al PWM nodes under am33xx-l4.dtsi

The kernel device tree for am335x is very different from the one in U-boot. The U-boot device tree is certainly older and an alignment with the kernel would require heavy code changes and that's not what I need.

Let's compare the 'epwmss at 0' node of the kernel device tree with that of U-boot:

/* kernel v5.9-rc4 am33xx-l4.dtsi */
segment at 300000 { /* 0x48300000 */

	compatible = "simple-bus";
	#address-cells = <1>;
	#size-cells = <1>;
	ranges = <0x00000000 0x00300000 0x001000>,	/* ap 66 */
		 <0x00001000 0x00301000 0x001000>,	/* ap 67 */
		 <0x00002000 0x00302000 0x001000>,	/* ap 68 */
		 <0x00003000 0x00303000 0x001000>,	/* ap 69 */
		 <0x00004000 0x00304000 0x001000>,	/* ap 70 */
		 <0x00005000 0x00305000 0x001000>,	/* ap 71 */
		 <0x0000e000 0x0030e000 0x001000>,	/* ap 72 */
		 <0x0000f000 0x0030f000 0x001000>,	/* ap 73 */
		 <0x00018000 0x00318000 0x004000>,	/* ap 74 */
		 <0x0001c000 0x0031c000 0x001000>,	/* ap 75 */
		 <0x00010000 0x00310000 0x002000>,	/* ap 76 */
		 <0x00012000 0x00312000 0x001000>,	/* ap 93 */
		 <0x00015000 0x00315000 0x001000>,	/* ap 94 */
		 <0x00016000 0x00316000 0x001000>,	/* ap 95 */
		 <0x00017000 0x00317000 0x001000>,	/* ap 96 */
		 <0x00013000 0x00313000 0x001000>,	/* ap 97 */
		 <0x00014000 0x00314000 0x001000>,	/* ap 98 */
		 <0x00020000 0x00320000 0x001000>,	/* ap 99 */
		 <0x00021000 0x00321000 0x001000>,	/* ap 100 */
		 <0x00022000 0x00322000 0x001000>,	/* ap 101 */
		 <0x00023000 0x00323000 0x001000>,	/* ap 102 */
		 <0x00024000 0x00324000 0x001000>,	/* ap 103 */
		 <0x00025000 0x00325000 0x001000>;	/* ap 104 */

	 target-module at 0 {			/* 0x48300000, ap 66 48.0 */
	 	compatible = "ti,sysc-omap4", "ti,sysc";
		reg = <0x0 0x4>,
		      <0x4 0x4>;
	      	reg-names = "rev", "sysc";
		ti,sysc-midle = <SYSC_IDLE_FORCE>,
				<SYSC_IDLE_NO>,
				<SYSC_IDLE_SMART>,
				<SYSC_IDLE_SMART_WKUP>;
		ti,sysc-sidle = <SYSC_IDLE_FORCE>,
				<SYSC_IDLE_NO>,
				<SYSC_IDLE_SMART>,
				<SYSC_IDLE_SMART_WKUP>;
		/* Domains (P, C): per_pwrdm, l4ls_clkdm */
		clocks = <&l4ls_clkctrl AM3_L4LS_EPWMSS0_CLKCTRL 0>;
		clock-names = "fck";
		#address-cells = <1>;
		#size-cells = <1>;
		ranges = <0x0 0x0 0x1000>;

		epwmss0: epwmss at 0 {
			 compatible = "ti,am33xx-pwmss";
			 reg = <0x0 0x10>;
			 #address-cells = <1>;
			 #size-cells = <1>;
			 status = "disabled";
			 ranges = <0 0 0x1000>;

			 ecap0: ecap at 100 {
			 	compatible = "ti,am3352-ecap",
					     "ti,am33xx-ecap";
			 	#pwm-cells = <3>;
				reg = <0x100 0x80>;
				clocks = <&l4ls_gclk>;
				clock-names = "fck";
				interrupts = <31>;
				interrupt-names = "ecap0";
				status = "disabled";
			};

			ehrpwm0: pwm at 200 {
				 compatible = "ti,am3352-ehrpwm",
				 	      "ti,am33xx-ehrpwm";
			 	#pwm-cells = <3>;
				reg = <0x200 0x80>;
				clocks = <&ehrpwm0_tbclk>, <&l4ls_gclk>;
				clock-names = "tbclk", "fck";
				status = "disabled";
			};
		};
	};
};

/* u-boot am33xx.dtsi */

epwmss0: epwmss at 48300000 {
	compatible = "ti,am33xx-pwmss";
	reg = <0x48300000 0x10>;
	ti,hwmods = "epwmss0";
	#address-cells = <1>;
	#size-cells = <1>;
	status = "disabled";
	ranges = <0x48300100 0x48300100 0x80   /* ECAP */
		  0x48300180 0x48300180 0x80   /* EQEP */
		  0x48300200 0x48300200 0x80>; /* EHRPWM */

	ecap0: ecap at 48300100 {
		compatible = "ti,am3352-ecap",
			     "ti,am33xx-ecap";
		#pwm-cells = <3>;
		reg = <0x48300100 0x80>;
		clocks = <&l4ls_gclk>;
		clock-names = "fck";
		interrupts = <31>;
		interrupt-names = "ecap0";
		status = "disabled";
	};

	ehrpwm0: pwm at 48300200 {
		compatible = "ti,am3352-ehrpwm",
			     "ti,am33xx-ehrpwm";
		#pwm-cells = <3>;
		reg = <0x48300200 0x80>;
		clocks = <&ehrpwm0_tbclk>, <&l4ls_gclk>;
		clock-names = "tbclk", "fck";
		status = "disabled";
	};
};

What can I say?
1 The epwmss0 node differs for the properties used for the definition
of the registers addresses ('ranges' and 'reg' properties) due to their parents. I don't want to make changes for something that already works. The patch will not heavily modify the device tree.
2 The target-module at 0 node, parent of epwmss0 in the kernel device tree,
references the domain clock (clocks = <&l4ls_clkctrl AM3_L4LS_EPWMSS0_CLKCTRL 0>). I have developed the clkctrl (compatible = "ti, clkctrl") driver and therefore, I would like to enable/disable domain clock using the driver model API. So, I think that the best point of the U-boot device tree where to add the reference to the domain clock is in the epwmss0 node and in any case outside the ecap0 and ehrpwm0 nodes. While it's not in the same location as the kernel device tree, I think it's still an improvement. In the future, when uboot's device tree is more like the current kernel device tree, we will change the location of the domain clock reference.

Quoted 175 lines
Quoted 175 lines
arch/arm/dts/am33xx.dtsi +1 -0
+
 			ecap2: ecap at 48304100 {
 				compatible = "ti,am3352-ecap",
 					     "ti,am33xx-ecap";
doc/device-tree-bindings/pwm/ti,pwmss.txt new file +58 -0
new file mode 100644
index 0000000000..4633697fbd
@@ -0,0 +1,58 @@
+TI SOC based PWM Subsystem
+
+Required properties:
+- compatible: Must be "ti,<soc>-pwmss".
+  for am33xx  - compatible = "ti,am33xx-pwmss";
+  for am4372  - compatible = "ti,am4372-pwmss","ti,am33xx-pwmss";
+  for dra746 - compatible = "ti,dra746-pwmss", "ti,am33xx-pwmss"
+
+- reg: physical base address and size of the registers map.
+- address-cells: Specify the number of u32 entries needed in child nodes.
+		  Should set to 1.
+- size-cells: specify number of u32 entries needed to specify child nodes size
+		in reg property. Should set to 1.
+- ranges: describes the address mapping of a memory-mapped bus. Should set to
+	   physical address map of child's base address, physical address within
+	   parent's address  space and length of the address map. For am33xx,
+	   3 set of child register maps present, ECAP register space, EQEP
+	   register space, EHRPWM register space.
+
+Also child nodes should also populated under PWMSS DT node.
+
+Example:
+epwmss0: epwmss at 48300000 { /* PWMSS for am33xx */
+	compatible = "ti,am33xx-pwmss";
+	reg = <0x48300000 0x10>;
+	ti,hwmods = "epwmss0";
+	#address-cells = <1>;
+	#size-cells = <1>;
+	ranges = <0x48300100 0x48300100 0x80   /* ECAP */
+		  0x48300180 0x48300180 0x80   /* EQEP */
+		  0x48300200 0x48300200 0x80>; /* EHRPWM */
+
+	/* child nodes go here */
+};
+
+epwmss0: epwmss at 48300000 { /* PWMSS for am4372 */
+	compatible = "ti,am4372-pwmss","ti,am33xx-pwmss"
+	reg = <0x48300000 0x10>;
+	ti,hwmods = "epwmss0";
+	#address-cells = <1>;
+	#size-cells = <1>;
+	ranges = <0x48300100 0x48300100 0x80   /* ECAP */
+		  0x48300180 0x48300180 0x80   /* EQEP */
+		  0x48300200 0x48300200 0x80>; /* EHRPWM */
+
+	/* child nodes go here */
+};
+
+epwmss0: epwmss at 4843e000 { /* PWMSS for DRA7xx */
+	compatible = "ti,dra746-pwmss", "ti,am33xx-pwmss";
+	reg = <0x4843e000 0x30>;
+	ti,hwmods = "epwmss0";
+	#address-cells = <1>;
+	#size-cells = <1>;
+	ranges;
+
+	/* child nodes go here */
+};
drivers/pwm/Kconfig +8 -1
index e4ba8b3d80..129f5d77ca 100644
@@ -69,8 +69,15 @@ config PWM_SUNXI
 	  This PWM is found on H3, A64 and other Allwinner SoCs. It supports a
 	  programmable period and duty cycle. A 16-bit counter is used.
 
+config PWM_TI_PWMSS
+	bool "Enable support for the AM335x PWM Subsystem"
+	depends on DM_PWM
+	help
+	  This enables the AM335x PWM subsystem driver support on TI's SOCs.
+
 config PWM_TI_EHRPWM
 	bool "Enable support for the AM335x EHRPWM"
-	depends on DM_PWM
+	depends on PWM_TI_PWMSS
+	default y
 	help
 	  This enables the AM335x EHRPWM driver support on TI's SoCs.
drivers/pwm/Makefile +1 -0
index c5f88f7501..df9c54e764 100644
@@ -19,3 +19,4 @@ obj-$(CONFIG_PWM_SIFIVE)	+= pwm-sifive.o
 obj-$(CONFIG_PWM_TEGRA)		+= tegra_pwm.o
 obj-$(CONFIG_PWM_SUNXI)		+= sunxi_pwm.o
 obj-$(CONFIG_PWM_TI_EHRPWM)	+= pwm-ti-ehrpwm.o
+obj-$(CONFIG_PWM_TI_PWMSS)	+= pwm-ti-pwmss.o
drivers/pwm/pwm-ti-pwmss.c new file +71 -0
new file mode 100644
index 0000000000..57f86512d6
@@ -0,0 +1,95 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Pulse-Width Modulation Subsystem (pwmss)
+ *
+ * Copyright (C) 2020 Dario Binacchi <[email protected]>
+ */
+#define DEBUG
+#undef CONFIG_LOGLEVEL
+#define CONFIG_LOGLEVEL 8
+
+#include <common.h>
+#include <clk.h>
+#include <dm.h>
+
+struct ti_pwmss_priv {
+	int child_count;
+	struct clk clkdm;
+};
+
+static const struct udevice_id ti_pwmss_ids[] = {
+	{.compatible = "ti,am33xx-pwmss"},
+	{}
+};
+
+static int ti_pwmss_child_post_remove(struct udevice *dev)
+{
+	struct ti_pwmss_priv *priv = dev_get_priv(dev->parent);
+	int err;
+
+	if (--priv->child_count > 0)
+		return 0;
+
+	err = clk_disable(&priv->clkdm);
+	if (err) {
+		dev_err(dev->parent, "%s: failed to disable clock domain\n",
+			__func__);
+		goto clkdm_disable_err;
+	}
+
+	err = clk_release_all(&priv->clkdm, 1);
+	if (err) {
+		dev_err(dev->parent, "%s: failed to release clock domain\n",
+			__func__);
+		goto clkdm_release_err;
+	}
+
+	return 0;
+
+clkdm_release_err:
+	clk_enable(&priv->clkdm);
+clkdm_disable_err:
+	priv->child_count++;
+	return err;
+}
+
+static int ti_pwmss_child_pre_probe(struct udevice *dev)
+{
+	struct ti_pwmss_priv *priv = dev_get_priv(dev->parent);
+	int err;
+
+	if (++priv->child_count > 1)
+		return 0;
+
+	err = clk_get_by_name(dev->parent, "fck", &priv->clkdm);
+	if (err) {
+		dev_err(dev->parent, "%s: failed to get clock domain\n",
+			__func__);
+		goto clkdm_get_err;
+	}
+
+	err = clk_enable(&priv->clkdm);
Quoted 8 lines

drivers/pwm/pwm-ti-pwmss.c line 76

Quoted 5 lines
drivers/pwm/pwm-ti-pwmss.c new file +5 -0
+	if (err) {
+		dev_err(dev->parent, "%s: failed to enable clock domain\n",
+			__func__);
+		goto clkdm_enable_err;
+	}

Do we need a whole subsystem driver just for enabling the clocks? Can't the same be happen in driver?

We need this driver also and especially to bind (through the dm_scan_fdt_dev) its child devices in the device tree:

U_BOOT_DRIVER(ti_pwmss) = {
...
.bind = dm_scan_fdt_dev,
...
};

Without this driver the nodes ecap0 and ehrpwm0 will not be bound.

Regards,
Dario

Quoted 3 lines

Thanks and regards,
Lokesh

#15 lore raw

PATCH v2 19/30 pwm: ti: am33xx: add subsystem driver

Quoted 67 lines · Dario Binacchi

Hi Lokesh,

Quoted 57 lines

Il 07/09/2020 07:32 Lokesh Vutla <[email protected]> ha scritto:

Hi Dario,

Quoted 51 lines · Dario Binacchi

The TI PWMSS driver is a simple bus driver for providing clock and power management for the PWM peripherals on TI AM33xx SoCs, namely eCAP, eHRPWM and eQEP.

Based on more recent versions of the device tree inside the linux kernel, I added the clock domain for each subsystem in am33x.dtsi so it can be enabled before probing the peripheral child device and disabled after its removal.

---

(no changes since v1)

 arch/arm/dts/am33xx.dtsi                  |  9 +++
 doc/device-tree-bindings/pwm/ti,pwmss.txt | 58 ++++++++++++++
 drivers/pwm/Kconfig                       |  9 ++-
 drivers/pwm/Makefile                      |  1 +
 drivers/pwm/pwm-ti-pwmss.c                | 95 +++++++++++++++++++++++
 5 files changed, 171 insertions(+), 1 deletion(-)
 create mode 100644 doc/device-tree-bindings/pwm/ti,pwmss.txt
 create mode 100644 drivers/pwm/pwm-ti-pwmss.c
arch/arm/dts/am33xx.dtsi +6 -0
index d3dd6a16e7..fa7492a9b6 100644
@@ -758,6 +758,9 @@
 				  0x48300180 0x48300180 0x80   /* EQEP */
 				  0x48300200 0x48300200 0x80>; /* EHRPWM */
 
+			clocks = <&l4_per_clkctrl AM3_EPWMSS0_CLKCTRL 0>;
+			clock-names = "fck";
+
 			ecap0: ecap at 48300100 {
 				compatible = "ti,am3352-ecap",
 					     "ti,am33xx-ecap";
@@ -792,6 +795,9 @@
 				  0x48302180 0x48302180 0x80   /* EQEP */
 				  0x48302200 0x48302200 0x80>; /* EHRPWM */
 
+			clocks = <&l4_per_clkctrl AM3_EPWMSS1_CLKCTRL 0>;
+			clock-names = "fck";
+
 			ecap1: ecap at 48302100 {
 				compatible = "ti,am3352-ecap",
 					     "ti,am33xx-ecap";
@@ -826,6 +832,9 @@
 				  0x48304180 0x48304180 0x80   /* EQEP */
 				  0x48304200 0x48304200 0x80>; /* EHRPWM */
 
Quoted 7 lines

arch/arm/dts/am33xx.dtsi line 836

Quoted 2 lines
arch/arm/dts/am33xx.dtsi +2 -0
+			clocks = <&l4_per_clkctrl AM3_EPWMSS2_CLKCTRL 0>;
+			clock-names = "fck";

hmm..I do not see these changes in upstream kernel v5.9-rc3 DT. Which version of kernel are you using? I see al PWM nodes under am33xx-l4.dtsi

Quoted 4 lines

The kernel device tree for am335x is very different from the one in U-boot. The U-boot device tree is certainly older and an alignment with the kernel would require heavy code changes and that's not what I need.

kernel dts gets synced to U-Boot at some point. Won't that break your use-case?

Quoted 120 lines

Let's compare the 'epwmss at 0' node of the kernel device tree with that of U-boot:

/* kernel v5.9-rc4 am33xx-l4.dtsi */
segment at 300000 { /* 0x48300000 */

	compatible = "simple-bus";
	#address-cells = <1>;
	#size-cells = <1>;
	ranges = <0x00000000 0x00300000 0x001000>,	/* ap 66 */
		 <0x00001000 0x00301000 0x001000>,	/* ap 67 */
		 <0x00002000 0x00302000 0x001000>,	/* ap 68 */
		 <0x00003000 0x00303000 0x001000>,	/* ap 69 */
		 <0x00004000 0x00304000 0x001000>,	/* ap 70 */
		 <0x00005000 0x00305000 0x001000>,	/* ap 71 */
		 <0x0000e000 0x0030e000 0x001000>,	/* ap 72 */
		 <0x0000f000 0x0030f000 0x001000>,	/* ap 73 */
		 <0x00018000 0x00318000 0x004000>,	/* ap 74 */
		 <0x0001c000 0x0031c000 0x001000>,	/* ap 75 */
		 <0x00010000 0x00310000 0x002000>,	/* ap 76 */
		 <0x00012000 0x00312000 0x001000>,	/* ap 93 */
		 <0x00015000 0x00315000 0x001000>,	/* ap 94 */
		 <0x00016000 0x00316000 0x001000>,	/* ap 95 */
		 <0x00017000 0x00317000 0x001000>,	/* ap 96 */
		 <0x00013000 0x00313000 0x001000>,	/* ap 97 */
		 <0x00014000 0x00314000 0x001000>,	/* ap 98 */
		 <0x00020000 0x00320000 0x001000>,	/* ap 99 */
		 <0x00021000 0x00321000 0x001000>,	/* ap 100 */
		 <0x00022000 0x00322000 0x001000>,	/* ap 101 */
		 <0x00023000 0x00323000 0x001000>,	/* ap 102 */
		 <0x00024000 0x00324000 0x001000>,	/* ap 103 */
		 <0x00025000 0x00325000 0x001000>;	/* ap 104 */

	 target-module at 0 {			/* 0x48300000, ap 66 48.0 */
	 	compatible = "ti,sysc-omap4", "ti,sysc";
		reg = <0x0 0x4>,
		      <0x4 0x4>;
	      	reg-names = "rev", "sysc";
		ti,sysc-midle = <SYSC_IDLE_FORCE>,
				<SYSC_IDLE_NO>,
				<SYSC_IDLE_SMART>,
				<SYSC_IDLE_SMART_WKUP>;
		ti,sysc-sidle = <SYSC_IDLE_FORCE>,
				<SYSC_IDLE_NO>,
				<SYSC_IDLE_SMART>,
				<SYSC_IDLE_SMART_WKUP>;
		/* Domains (P, C): per_pwrdm, l4ls_clkdm */
		clocks = <&l4ls_clkctrl AM3_L4LS_EPWMSS0_CLKCTRL 0>;
		clock-names = "fck";
		#address-cells = <1>;
		#size-cells = <1>;
		ranges = <0x0 0x0 0x1000>;

		epwmss0: epwmss at 0 {
			 compatible = "ti,am33xx-pwmss";
			 reg = <0x0 0x10>;
			 #address-cells = <1>;
			 #size-cells = <1>;
			 status = "disabled";
			 ranges = <0 0 0x1000>;

			 ecap0: ecap at 100 {
			 	compatible = "ti,am3352-ecap",
					     "ti,am33xx-ecap";
			 	#pwm-cells = <3>;
				reg = <0x100 0x80>;
				clocks = <&l4ls_gclk>;
				clock-names = "fck";
				interrupts = <31>;
				interrupt-names = "ecap0";
				status = "disabled";
			};

			ehrpwm0: pwm at 200 {
				 compatible = "ti,am3352-ehrpwm",
				 	      "ti,am33xx-ehrpwm";
			 	#pwm-cells = <3>;
				reg = <0x200 0x80>;
				clocks = <&ehrpwm0_tbclk>, <&l4ls_gclk>;
				clock-names = "tbclk", "fck";
				status = "disabled";
			};
		};
	};
};

/* u-boot am33xx.dtsi */

epwmss0: epwmss at 48300000 {
	compatible = "ti,am33xx-pwmss";
	reg = <0x48300000 0x10>;
	ti,hwmods = "epwmss0";
	#address-cells = <1>;
	#size-cells = <1>;
	status = "disabled";
	ranges = <0x48300100 0x48300100 0x80   /* ECAP */
		  0x48300180 0x48300180 0x80   /* EQEP */
		  0x48300200 0x48300200 0x80>; /* EHRPWM */

	ecap0: ecap at 48300100 {
		compatible = "ti,am3352-ecap",
			     "ti,am33xx-ecap";
		#pwm-cells = <3>;
		reg = <0x48300100 0x80>;
		clocks = <&l4ls_gclk>;
		clock-names = "fck";
		interrupts = <31>;
		interrupt-names = "ecap0";
		status = "disabled";
	};

	ehrpwm0: pwm at 48300200 {
		compatible = "ti,am3352-ehrpwm",
			     "ti,am33xx-ehrpwm";
		#pwm-cells = <3>;
		reg = <0x48300200 0x80>;
		clocks = <&ehrpwm0_tbclk>, <&l4ls_gclk>;
		clock-names = "tbclk", "fck";
		status = "disabled";
	};
};
Quoted 5 lines

What can I say?
1 The epwmss0 node differs for the properties used for the definition
of the registers addresses ('ranges' and 'reg' properties) due to their parents. I don't want to make changes for something that already works. The patch will not heavily modify the device tree.

Old dtb cannot be used for soo long. Today syncing the DT doesn't harm anything but this series is going to break on DT sync. I would suggest we start with latest DT bindings.

Thanks and regards,
Lokesh

Quoted 210 lines

2 The target-module at 0 node, parent of epwmss0 in the kernel device tree,
references the domain clock (clocks = <&l4ls_clkctrl AM3_L4LS_EPWMSS0_CLKCTRL 0>). I have developed the clkctrl (compatible = "ti, clkctrl") driver and therefore, I would like to enable/disable domain clock using the driver model API. So, I think that the best point of the U-boot device tree where to add the reference to the domain clock is in the epwmss0 node and in any case outside the ecap0 and ehrpwm0 nodes. While it's not in the same location as the kernel device tree, I think it's still an improvement. In the future, when uboot's device tree is more like the current kernel device tree, we will change the location of the domain clock reference.

Quoted 175 lines
Quoted 175 lines
arch/arm/dts/am33xx.dtsi +1 -0
+
 			ecap2: ecap at 48304100 {
 				compatible = "ti,am3352-ecap",
 					     "ti,am33xx-ecap";
doc/device-tree-bindings/pwm/ti,pwmss.txt new file +58 -0
new file mode 100644
index 0000000000..4633697fbd
@@ -0,0 +1,58 @@
+TI SOC based PWM Subsystem
+
+Required properties:
+- compatible: Must be "ti,<soc>-pwmss".
+  for am33xx  - compatible = "ti,am33xx-pwmss";
+  for am4372  - compatible = "ti,am4372-pwmss","ti,am33xx-pwmss";
+  for dra746 - compatible = "ti,dra746-pwmss", "ti,am33xx-pwmss"
+
+- reg: physical base address and size of the registers map.
+- address-cells: Specify the number of u32 entries needed in child nodes.
+		  Should set to 1.
+- size-cells: specify number of u32 entries needed to specify child nodes size
+		in reg property. Should set to 1.
+- ranges: describes the address mapping of a memory-mapped bus. Should set to
+	   physical address map of child's base address, physical address within
+	   parent's address  space and length of the address map. For am33xx,
+	   3 set of child register maps present, ECAP register space, EQEP
+	   register space, EHRPWM register space.
+
+Also child nodes should also populated under PWMSS DT node.
+
+Example:
+epwmss0: epwmss at 48300000 { /* PWMSS for am33xx */
+	compatible = "ti,am33xx-pwmss";
+	reg = <0x48300000 0x10>;
+	ti,hwmods = "epwmss0";
+	#address-cells = <1>;
+	#size-cells = <1>;
+	ranges = <0x48300100 0x48300100 0x80   /* ECAP */
+		  0x48300180 0x48300180 0x80   /* EQEP */
+		  0x48300200 0x48300200 0x80>; /* EHRPWM */
+
+	/* child nodes go here */
+};
+
+epwmss0: epwmss at 48300000 { /* PWMSS for am4372 */
+	compatible = "ti,am4372-pwmss","ti,am33xx-pwmss"
+	reg = <0x48300000 0x10>;
+	ti,hwmods = "epwmss0";
+	#address-cells = <1>;
+	#size-cells = <1>;
+	ranges = <0x48300100 0x48300100 0x80   /* ECAP */
+		  0x48300180 0x48300180 0x80   /* EQEP */
+		  0x48300200 0x48300200 0x80>; /* EHRPWM */
+
+	/* child nodes go here */
+};
+
+epwmss0: epwmss at 4843e000 { /* PWMSS for DRA7xx */
+	compatible = "ti,dra746-pwmss", "ti,am33xx-pwmss";
+	reg = <0x4843e000 0x30>;
+	ti,hwmods = "epwmss0";
+	#address-cells = <1>;
+	#size-cells = <1>;
+	ranges;
+
+	/* child nodes go here */
+};
drivers/pwm/Kconfig +8 -1
index e4ba8b3d80..129f5d77ca 100644
@@ -69,8 +69,15 @@ config PWM_SUNXI
 	  This PWM is found on H3, A64 and other Allwinner SoCs. It supports a
 	  programmable period and duty cycle. A 16-bit counter is used.
 
+config PWM_TI_PWMSS
+	bool "Enable support for the AM335x PWM Subsystem"
+	depends on DM_PWM
+	help
+	  This enables the AM335x PWM subsystem driver support on TI's SOCs.
+
 config PWM_TI_EHRPWM
 	bool "Enable support for the AM335x EHRPWM"
-	depends on DM_PWM
+	depends on PWM_TI_PWMSS
+	default y
 	help
 	  This enables the AM335x EHRPWM driver support on TI's SoCs.
drivers/pwm/Makefile +1 -0
index c5f88f7501..df9c54e764 100644
@@ -19,3 +19,4 @@ obj-$(CONFIG_PWM_SIFIVE)	+= pwm-sifive.o
 obj-$(CONFIG_PWM_TEGRA)		+= tegra_pwm.o
 obj-$(CONFIG_PWM_SUNXI)		+= sunxi_pwm.o
 obj-$(CONFIG_PWM_TI_EHRPWM)	+= pwm-ti-ehrpwm.o
+obj-$(CONFIG_PWM_TI_PWMSS)	+= pwm-ti-pwmss.o
drivers/pwm/pwm-ti-pwmss.c new file +71 -0
new file mode 100644
index 0000000000..57f86512d6
@@ -0,0 +1,95 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Pulse-Width Modulation Subsystem (pwmss)
+ *
+ * Copyright (C) 2020 Dario Binacchi <[email protected]>
+ */
+#define DEBUG
+#undef CONFIG_LOGLEVEL
+#define CONFIG_LOGLEVEL 8
+
+#include <common.h>
+#include <clk.h>
+#include <dm.h>
+
+struct ti_pwmss_priv {
+	int child_count;
+	struct clk clkdm;
+};
+
+static const struct udevice_id ti_pwmss_ids[] = {
+	{.compatible = "ti,am33xx-pwmss"},
+	{}
+};
+
+static int ti_pwmss_child_post_remove(struct udevice *dev)
+{
+	struct ti_pwmss_priv *priv = dev_get_priv(dev->parent);
+	int err;
+
+	if (--priv->child_count > 0)
+		return 0;
+
+	err = clk_disable(&priv->clkdm);
+	if (err) {
+		dev_err(dev->parent, "%s: failed to disable clock domain\n",
+			__func__);
+		goto clkdm_disable_err;
+	}
+
+	err = clk_release_all(&priv->clkdm, 1);
+	if (err) {
+		dev_err(dev->parent, "%s: failed to release clock domain\n",
+			__func__);
+		goto clkdm_release_err;
+	}
+
+	return 0;
+
+clkdm_release_err:
+	clk_enable(&priv->clkdm);
+clkdm_disable_err:
+	priv->child_count++;
+	return err;
+}
+
+static int ti_pwmss_child_pre_probe(struct udevice *dev)
+{
+	struct ti_pwmss_priv *priv = dev_get_priv(dev->parent);
+	int err;
+
+	if (++priv->child_count > 1)
+		return 0;
+
+	err = clk_get_by_name(dev->parent, "fck", &priv->clkdm);
+	if (err) {
+		dev_err(dev->parent, "%s: failed to get clock domain\n",
+			__func__);
+		goto clkdm_get_err;
+	}
+
+	err = clk_enable(&priv->clkdm);
Quoted 8 lines

drivers/pwm/pwm-ti-pwmss.c line 76

Quoted 5 lines
drivers/pwm/pwm-ti-pwmss.c new file +5 -0
+	if (err) {
+		dev_err(dev->parent, "%s: failed to enable clock domain\n",
+			__func__);
+		goto clkdm_enable_err;
+	}

Do we need a whole subsystem driver just for enabling the clocks? Can't the same be happen in driver?

We need this driver also and especially to bind (through the dm_scan_fdt_dev) its child devices in the device tree:

U_BOOT_DRIVER(ti_pwmss) = {
...
.bind = dm_scan_fdt_dev,
...
};

Without this driver the nodes ecap0 and ehrpwm0 will not be bound.

Regards,
Dario

Quoted 3 lines

Thanks and regards,
Lokesh

#16 lore raw

PATCH v2 20/30 video: backlight: fix pwm's duty cycle calculation

In reply to Dario Binacchi

For levels equal to the maximum value, the duty cycle must be equal to the period.

---

(no changes since v1)

 drivers/video/pwm_backlight.c |  2 +-
 test/dm/panel.c               | 12 ++++++------
 2 files changed, 7 insertions(+), 7 deletions(-)
drivers/video/pwm_backlight.c +1 -1
index 468a5703bd..199ccc030f 100644
@@ -63,7 +63,7 @@ static int set_pwm(struct pwm_backlight_priv *priv)
 	int ret;
 
 	duty_cycle = priv->period_ns * (priv->cur_level - priv->min_level) /
-		(priv->max_level - priv->min_level + 1);
+		(priv->max_level - priv->min_level);
 	ret = pwm_set_config(priv->pwm, priv->channel, priv->period_ns,
 			     duty_cycle);
 	if (ret)
test/dm/panel.c +6 -6
index a840fb4951..49f5ac7169 100644
@@ -40,7 +40,7 @@ static int dm_test_panel(struct unit_test_state *uts)
 	ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
 					   &enable, &polarity));
 	ut_asserteq(1000, period_ns);
-	ut_asserteq(170 * 1000 / 256, duty_ns);
+	ut_asserteq(170 * 1000 / 255, duty_ns);
 	ut_asserteq(true, enable);
 	ut_asserteq(false, polarity);
 	ut_asserteq(1, sandbox_gpio_get_value(gpio, 1));
@@ -49,29 +49,29 @@ static int dm_test_panel(struct unit_test_state *uts)
 	ut_assertok(panel_set_backlight(dev, 40));
 	ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
 					   &enable, &polarity));
-	ut_asserteq(64 * 1000 / 256, duty_ns);
+	ut_asserteq(64 * 1000 / 255, duty_ns);
 
 	ut_assertok(panel_set_backlight(dev, BACKLIGHT_MAX));
 	ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
 					   &enable, &polarity));
-	ut_asserteq(255 * 1000 / 256, duty_ns);
+	ut_asserteq(255 * 1000 / 255, duty_ns);
 
 	ut_assertok(panel_set_backlight(dev, BACKLIGHT_MIN));
 	ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
 					   &enable, &polarity));
-	ut_asserteq(0 * 1000 / 256, duty_ns);
+	ut_asserteq(0 * 1000 / 255, duty_ns);
 	ut_asserteq(1, sandbox_gpio_get_value(gpio, 1));
 
 	ut_assertok(panel_set_backlight(dev, BACKLIGHT_DEFAULT));
 	ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
 					   &enable, &polarity));
 	ut_asserteq(true, enable);
-	ut_asserteq(170 * 1000 / 256, duty_ns);
+	ut_asserteq(170 * 1000 / 255, duty_ns);
 
 	ut_assertok(panel_set_backlight(dev, BACKLIGHT_OFF));
 	ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
 					   &enable, &polarity));
-	ut_asserteq(0 * 1000 / 256, duty_ns);
+	ut_asserteq(0 * 1000 / 255, duty_ns);
 	ut_asserteq(0, sandbox_gpio_get_value(gpio, 1));
 	ut_asserteq(false, regulator_get_enable(reg));
 
Signature · 1 line
2.17.1
#17 lore raw

PATCH v2 21/30 video: backlight: fix pwm data structure description

In reply to Dario Binacchi

The description of the 'max_level' field was incorrectly assigned to the 'min_level' field.

---

(no changes since v1)

 drivers/video/pwm_backlight.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/video/pwm_backlight.c +1 -1
index 199ccc030f..9519180ceb 100644
@@ -33,7 +33,7 @@
  * @cur_level: Current level for the backlight (index or value)
  * @default_level: Default level for the backlight (index or value)
  * @min_level: Minimum level of the backlight (full off)
- * @min_level: Maximum level of the backlight (full on)
+ * @max_level: Maximum level of the backlight (full on)
  * @enabled: true if backlight is enabled
  */
 struct pwm_backlight_priv {
Signature · 1 line
2.17.1
#18 lore raw

PATCH v2 22/30 dm: core: improve uclass_get_device_by_phandle_id() description

In reply to Dario Binacchi

Complete the devp parameter description.

---

(no changes since v1)

 include/dm/uclass.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/dm/uclass.h +2 -1
index 67ff7466c8..7188304304 100644
@@ -224,7 +224,8 @@ int uclass_get_device_by_ofnode(enum uclass_id id, ofnode node,
  *
  * @id: uclass ID to look up
  * @phandle_id: the phandle id to look up
- * @devp: Returns pointer to device (there is only one for each node)
+ * @devp: Returns pointer to device (there is only one for each node). NULL if
+ *	there is no such device.
  * @return 0 if OK, -ENODEV if there is no device match the phandle, other
  *	-ve on error
  */
Signature · 1 line
2.17.1
#19 lore raw

PATCH v2 23/30 gpio: fix gpio_request_by_name() description

In reply to Dario Binacchi

Replace 'dev->dev' with '@desc->dev' in the gpio_request_by_name function desc parameter description.

---

(no changes since v1)

 include/asm-generic/gpio.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/asm-generic/gpio.h +1 -1
index a57dd2665c..f469564f83 100644
@@ -496,7 +496,7 @@ int gpio_claim_vector(const int *gpio_num_array, const char *fmt);
  * @list_name:	Name of GPIO list (e.g. "board-id-gpios")
  * @index:	Index number of the GPIO in that list use request (0=first)
  * @desc:	Returns GPIO description information. If there is no such
- *		GPIO, dev->dev will be NULL.
+ *		GPIO, @desc->dev will be NULL.
  * @flags:	Indicates the GPIO input/output settings (GPIOD_...)
  * @return 0 if OK, -ENOENT if the GPIO does not exist, -EINVAL if there is
  * something wrong with the list, or other -ve for another error (e.g.
Signature · 1 line
2.17.1
#20 lore raw

PATCH v2 24/30 dm: core: add a function to decode display timings

In reply to Dario Binacchi

The patch adds a function to get display timings from the device tree node attached to the device.

---

(no changes since v1)

 arch/sandbox/dts/test.dts | 46 ++++++++++++++++++++++
 drivers/core/read.c       |  6 +++
 include/dm/read.h         | 24 ++++++++++++
 test/dm/test-fdt.c        | 80 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 156 insertions(+)
arch/sandbox/dts/test.dts +46 -0
index af701d2086..03626ab289 100644
@@ -129,6 +129,52 @@
 		str-value = "test string";
 		interrupts-extended = <&irq 3 0>;
 		acpi,name = "GHIJ";
+		display-timings {
+			timing0: 240x320 {
+				clock-frequency = <6500000>;
+				hactive = <240>;
+				vactive = <320>;
+				hfront-porch = <6>;
+				hback-porch = <7>;
+				hsync-len = <1>;
+				vback-porch = <5>;
+				vfront-porch = <8>;
+				vsync-len = <2>;
+				hsync-active = <1>;
+				vsync-active = <0>;
+				de-active = <1>;
+				pixelclk-active = <1>;
+				interlaced;
+				doublescan;
+				doubleclk;
+			};
+			timing1: 480x800 {
+				clock-frequency = <9000000>;
+				hactive = <480>;
+				vactive = <800>;
+				hfront-porch = <10>;
+				hback-porch = <59>;
+				hsync-len = <12>;
+				vback-porch = <15>;
+				vfront-porch = <17>;
+				vsync-len = <16>;
+				hsync-active = <0>;
+				vsync-active = <1>;
+				de-active = <0>;
+				pixelclk-active = <0>;
+			};
+			timing2: 800x480 {
+				clock-frequency = <33500000>;
+				hactive = <800>;
+				vactive = <480>;
+				hback-porch = <89>;
+				hfront-porch = <164>;
+				vback-porch = <23>;
+				vfront-porch = <10>;
+				hsync-len = <11>;
+				vsync-len = <13>;
+			};
+		};
 	};
 
 	junk {
drivers/core/read.c +6 -0
index 86f3f88170..f4fc0fa345 100644
@@ -376,3 +376,9 @@ int dev_read_pci_bus_range(const struct udevice *dev,
 
 	return 0;
 }
+
+int dev_decode_display_timing(const struct udevice *dev, int index,
+			      struct display_timing *config)
+{
+	return ofnode_decode_display_timing(dev_ofnode(dev), index, config);
+}
include/dm/read.h +24 -0
index 67db94adfc..a8d3f13198 100644
@@ -692,6 +692,23 @@ int dev_get_child_count(const struct udevice *dev);
  */
 int dev_read_pci_bus_range(const struct udevice *dev, struct resource *res);
 
+/**
+ * dev_decode_display_timing() - decode display timings
+ *
+ * Decode display timings from the supplied 'display-timings' node.
+ * See doc/device-tree-bindings/video/display-timing.txt for binding
+ * information.
+ *
+ * @dev: device to read DT display timings from. The node linked to the device
+ *       contains a child node called 'display-timings' which in turn contains
+ *       one or more display timing nodes.
+ * @index: index number to read (0=first timing subnode)
+ * @config: place to put timings
+ * @return 0 if OK, -FDT_ERR_NOTFOUND if not found
+ */
+int dev_decode_display_timing(const struct udevice *dev, int index,
+			      struct display_timing *config);
+
 #else /* CONFIG_DM_DEV_READ_INLINE is enabled */
 
 static inline int dev_read_u32(const struct udevice *dev,
@@ -1014,6 +1031,13 @@ static inline int dev_get_child_count(const struct udevice *dev)
 	return ofnode_get_child_count(dev_ofnode(dev));
 }
 
+static inline int dev_decode_display_timing(const struct udevice *dev,
+					    int index,
+					    struct display_timing *config)
+{
+	return ofnode_decode_display_timing(dev_ofnode(dev), index, config);
+}
+
 #endif /* CONFIG_DM_DEV_READ_INLINE */
 
 /**
test/dm/test-fdt.c +80 -0

83 lines not on this page · raw message

Signature · 1 line
2.17.1
#21 lore raw

PATCH v2 25/30 video: omap: add panel driver

In reply to Dario Binacchi

The previous version of am335x-fb.c contained the functionalities of two drivers that this patch has split. It was a video type driver that used the same registration compatible string that now registers a panel type driver. The proof of this is that two compatible strings were referred to within the same driver.
There are now two drivers, each with its own compatible string, functions and API.
Furthermore, the panel driver, in addition to decoding the display timings, is now also able to manage the backlight.

---

(no changes since v1)

 arch/arm/dts/am335x-brppt1-mmc.dts       |   3 +-
 arch/arm/dts/am335x-brppt1-nand.dts      |   3 +-
 arch/arm/dts/am335x-brppt1-spi.dts       |   3 +-
 arch/arm/dts/am335x-brsmarc1.dts         |   2 +-
 arch/arm/dts/am335x-brxre1.dts           |   3 +-
 arch/arm/dts/am335x-evm-u-boot.dtsi      |   7 +-
 arch/arm/dts/am335x-evmsk-u-boot.dtsi    |   6 +-
 arch/arm/dts/am335x-guardian-u-boot.dtsi |   8 +-
 arch/arm/dts/am335x-pdu001-u-boot.dtsi   |   8 +-
 arch/arm/dts/am335x-pxm50-u-boot.dtsi    |   6 +-
 arch/arm/dts/am335x-rut-u-boot.dtsi      |   6 +-
 arch/arm/dts/da850-evm-u-boot.dtsi       |   8 +-
 drivers/video/Makefile                   |   1 +
 drivers/video/am335x-fb.c                | 255 ++++++++++-------------
 drivers/video/am335x-fb.h                |  31 +++
 drivers/video/tilcdc-panel.c             | 171 +++++++++++++++
 drivers/video/tilcdc-panel.h             |  14 ++
 17 files changed, 347 insertions(+), 188 deletions(-)
 create mode 100644 drivers/video/tilcdc-panel.c
 create mode 100644 drivers/video/tilcdc-panel.h
arch/arm/dts/am335x-brppt1-mmc.dts +1 -2
index 6f919711f0..9de48bcdde 100644
@@ -53,8 +53,6 @@
 		bkl-pwm = <&pwmbacklight>;
 		bkl-tps = <&tps_bl>;
 
-		u-boot,dm-pre-reloc;
-
 		panel-info {
 			ac-bias		= <255>;
 			ac-bias-intrpt	= <0>;
@@ -239,6 +237,7 @@
 };
 
 &lcdc {
+	u-boot,dm-pre-reloc;
 	status = "disabled";
 };
 
arch/arm/dts/am335x-brppt1-nand.dts +1 -2
index 9d4340f591..c09651cf13 100644
@@ -53,8 +53,6 @@
 		bkl-pwm = <&pwmbacklight>;
 		bkl-tps = <&tps_bl>;
 
-		u-boot,dm-pre-reloc;
-
 		panel-info {
 			ac-bias		= <255>;
 			ac-bias-intrpt	= <0>;
@@ -229,6 +227,7 @@
 };
 
 &lcdc {
+	u-boot,dm-pre-reloc;
 	status = "disabled";
 };
 
arch/arm/dts/am335x-brppt1-spi.dts +1 -2
index c078af8fba..6c86d56906 100644
@@ -54,8 +54,6 @@
 		bkl-pwm = <&pwmbacklight>;
 		bkl-tps = <&tps_bl>;
 
-		u-boot,dm-pre-reloc;
-
 		panel-info {
 			ac-bias		= <255>;
 			ac-bias-intrpt	= <0>;
@@ -260,6 +258,7 @@
 };
 
 &lcdc {
+	u-boot,dm-pre-reloc;
 	status = "disabled";
 };
 
arch/arm/dts/am335x-brsmarc1.dts +1 -1
index 7e9516e8f8..309adbc1ab 100644
@@ -59,7 +59,6 @@
 		/*backlight = <&tps_bl>; */
 		compatible = "ti,tilcdc,panel";
 		status = "okay";
-		u-boot,dm-pre-reloc;
 
 		panel-info {
 			ac-bias		= <255>;
@@ -299,6 +298,7 @@
 };
 
 &lcdc {
+	u-boot,dm-pre-reloc;
 	status = "okay";
 	ti,no-reset-on-init;
 	ti,no-idle-on-init;
arch/arm/dts/am335x-brxre1.dts +1 -2
index 6091a12fb7..89e84c8e1a 100644
@@ -79,8 +79,6 @@
 
 		backlight = <&tps_bl>;
 
-		u-boot,dm-pre-reloc;
-
 		panel-info {
 			ac-bias		= <255>;
 			ac-bias-intrpt	= <0>;
@@ -255,6 +253,7 @@
 };
 
 &lcdc {
+	u-boot,dm-pre-reloc;
 	status = "okay";
 	ti,no-reset-on-init;
 	ti,no-idle-on-init;
arch/arm/dts/am335x-evm-u-boot.dtsi +2 -5
index d7b049ef20..4a61cbbd49 100644
@@ -3,13 +3,10 @@
  * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
  */
 
-/ {
-	panel {
-		u-boot,dm-pre-reloc;
-	};
+&lcdc {
+	u-boot,dm-pre-reloc;
 };
 
-
 &mmc3 {
 	status = "disabled";
 };
arch/arm/dts/am335x-evmsk-u-boot.dtsi +2 -4
index 599fb377e6..b15ba0dcae 100644
@@ -5,8 +5,6 @@
  * Copyright (C) 2020 Dario Binacchi <[email protected]>
  */
 
-/ {
-	panel {
-		u-boot,dm-pre-reloc;
-	};
+&lcdc {
+	u-boot,dm-pre-reloc;
 };
arch/arm/dts/am335x-guardian-u-boot.dtsi +4 -4
index 705ef335bf..15578b945e 100644
@@ -8,16 +8,16 @@
 	ocp {
 		u-boot,dm-pre-reloc;
 	};
-
-	panel {
-		u-boot,dm-pre-reloc;
-	};
 };
 
 &l4_wkup {
 	u-boot,dm-pre-reloc;
 };
 
+&lcdc {
+	u-boot,dm-pre-reloc;
+};
+
 &mmc1 {
 	u-boot,dm-pre-reloc;
 };
arch/arm/dts/am335x-pdu001-u-boot.dtsi +4 -4
index a799fe9bc3..39e1a6129c 100644
@@ -7,16 +7,16 @@
 	ocp {
 		u-boot,dm-pre-reloc;
 	};
-
-	panel {
-		u-boot,dm-pre-reloc;
-	};
 };
 
 &l4_wkup {
 	u-boot,dm-pre-reloc;
 };
 
+&lcdc {
+	u-boot,dm-pre-reloc;
+};
+
 &scm {
 	u-boot,dm-pre-reloc;
 };
arch/arm/dts/am335x-pxm50-u-boot.dtsi +2 -4
index 77dfe6e262..b13d271e8b 100644
@@ -5,8 +5,6 @@
  * Copyright (C) 2020 Dario Binacchi <[email protected]>
  */
 
-/ {
-	panel {
-		u-boot,dm-pre-reloc;
-	};
+&lcdc {
+	u-boot,dm-pre-reloc;
 };
arch/arm/dts/am335x-rut-u-boot.dtsi +2 -4
index b2b4aa596a..4fc8c9bc2b 100644
@@ -5,8 +5,6 @@
  * Copyright (C) 2020 Dario Binacchi <[email protected]>
  */
 
-/ {
-	panel {
-		u-boot,dm-pre-reloc;
-	};
+&lcdc {
+	u-boot,dm-pre-reloc;
 };
arch/arm/dts/da850-evm-u-boot.dtsi +4 -4
index d588628641..b55dcbbe52 100644
@@ -14,10 +14,6 @@
 	nand {
 		compatible = "ti,davinci-nand";
 	};
-
-	panel {
-		u-boot,dm-pre-reloc;
-	};
 };
 
 &eth0 {
@@ -28,6 +24,10 @@
 	compatible = "m25p64", "jedec,spi-nor";
 };
 
+&lcdc {
+	u-boot,dm-pre-reloc;
+};
+
 &mmc0 {
 	u-boot,dm-spl;
 };
drivers/video/Makefile +1 -0
index 67a492a2d6..132a63ecea 100644
@@ -16,6 +16,7 @@ obj-$(CONFIG_DM_VIDEO) += video-uclass.o vidconsole-uclass.o
 obj-$(CONFIG_DM_VIDEO) += video_bmp.o
 obj-$(CONFIG_PANEL) += panel-uclass.o
 obj-$(CONFIG_SIMPLE_PANEL) += simple_panel.o
+obj-$(CONFIG_AM335X_LCD) += tilcdc-panel.o
 endif
 
 obj-${CONFIG_EXYNOS_FB} += exynos/
drivers/video/am335x-fb.c +105 -150

355 lines not on this page · raw message

drivers/video/am335x-fb.h +31 -0
index c9f92bc389..4952dd96e9 100644
@@ -70,6 +70,37 @@ struct am335x_lcdpanel {
 
 int am335xfb_init(struct am335x_lcdpanel *panel);
 
+#else /* CONFIG_DM_VIDEO */
+
+/**
+ * tilcdc_panel_info: Panel parameters
+ *
+ * @ac_bias: AC Bias Pin Frequency
+ * @ac_bias_intrpt: AC Bias Pin Transitions per Interrupt
+ * @dma_burst_sz: DMA burst size
+ * @bpp: Bits per pixel
+ * @fdd: FIFO DMA Request Delay
+ * @tft_alt_mode: TFT Alternative Signal Mapping (Only for active)
+ * @invert_pxl_clk: Invert pixel clock
+ * @sync_edge: Horizontal and Vertical Sync Edge: 0=rising 1=falling
+ * @sync_ctrl: Horizontal and Vertical Sync: Control: 0=ignore
+ * @raster_order: Raster Data Order Select: 1=Most-to-least 0=Least-to-most
+ * @fifo_th: DMA FIFO threshold
+ */
+struct tilcdc_panel_info {
+	u32 ac_bias;
+	u32 ac_bias_intrpt;
+	u32 dma_burst_sz;
+	u32 bpp;
+	u32 fdd;
+	bool tft_alt_mode;
+	bool invert_pxl_clk;
+	u32 sync_edge;
+	u32 sync_ctrl;
+	u32 raster_order;
+	u32 fifo_th;
+};
+
 #endif  /* CONFIG_DM_VIDEO */
 
 #endif  /* AM335X_FB_H */
drivers/video/tilcdc-panel.c new file +171 -0

171 lines not on this page · raw message

drivers/video/tilcdc-panel.h new file +14 -0
new file mode 100644
index 0000000000..6b40731304
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2020 Dario Binacchi <[email protected]>
+ */
+
+#ifndef _TILCDC_PANEL_H
+#define _TILCDC_PANEL_H
+
+#include "am335x-fb.h"
+
+int tilcdc_panel_get_display_info(struct udevice *dev,
+				  struct tilcdc_panel_info *info);
+
+#endif /* _TILCDC_PANEL_H */
Signature · 1 line
2.17.1