Skip to contentSkip to conversation

Add DM support for omap PWM backlight

PATCH Superseded Dario Binacchi 4 participants 43 messages Aug 25, 2020 – Sep 5, 2020

Subsystems (9)

v1 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

cover Add DM support for omap PWM backlight

The series was born from the need to manage the PWM backlight of the display connected to my beaglebone board. To hit the target, I had to develop drivers for PWM management which in turn relied on drivers for managing timers and clocks, all developed according to the driver model. My intention was to use the SoC-specific API only at strictly necessary points in the code. My previous patches for migrating the AM335x display driver to the driver model had required the implementation of additional functions outside the concerns of the driver, (settings for dividing the pixel clock rate, configuring the display DPLL rate, ....) not being able to use the API of the related clock drivers. This series shouldn't have repeated the same kind of mistake. Furthermore, I also wanted to fix that kind of forced choice. Almost everything should have been accessible via the driver model API. In the series there are also some patches that could be submitted separately, but which I have however inserted to avoid applying future patches to incorporate them.
With this last consideration, I hope I have convincingly justified the large number of patches in the series.

The patch enabling address translation into a CPU physical address from device-tree even in case of crossing levels with #size-cells = <0>, is crucial for the series. The previous implementation was unable to perform the address translation required by the am33xx device tree. I tried to apply in a conservative way as few changes as possible and to verify the execution of all the tests already developed, as well as the new ones I added for the new feature.

Dario Binacchi (31):
clk: remove a redundant header
clk: export generic routines
arch: sandbox: fix typo in clk.h
clk: add clk_round_rate()
clk: ti: add mux clock driver
arm: ti: am33xx: add DPLL_EN_FAST_RELOCK_BYPASS macro
clk: ti: am33xx: add DPLL clock drivers
clk: ti: add divider clock driver
clk: ti: refactor mux and divider clock drivers
clk: ti: add gate clock driver
ti: am33xx: fix do_enable_clocks() to accept NULL parameters
clk: ti: add support for clkctrl clocks
clk: ti: move drivers to 'ti' directory
clk: ti: omap4: add clock manager driver
clk: ti: am335x: add clock manager driver
fdt: translate address if #size-cells = <0>
omap: timer: fix the rate setting
misc: am33xx: add control module driver
pwm: ti: am33xx: add enhanced pwm driver
pwm: ti: am33xx: add subsystem driver
video: backlight: fix pwm's duty cycle calculation
video: backlight: fix pwm data structure description
dm: core: improve uclass_get_device_by_phandle_id() description
gpio: fix gpio_request_by_name() description
dm: core: add a function to decode display timings
video: omap: add panel driver
video: omap: enable LCD clock domain through DM API
video: omap: set LCD clock rate through DM API
video: omap: split the legacy code from the DM code
video: omap: move drivers to 'ti' directory
board: ti: am335x-ice: get CDCE913 clock device

 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/am33xx.dtsi                      |  12 +
 arch/arm/dts/da850-evm-u-boot.dtsi            |   8 +-
 arch/arm/include/asm/arch-am33xx/clock.h      |   1 +
 arch/arm/mach-omap2/am33xx/clock.c            |  10 +-
 arch/arm/mach-omap2/am33xx/clock_am33xx.c     |   2 +-
 arch/sandbox/dts/test.dts                     |  67 +++
 arch/sandbox/include/asm/clk.h                |  35 +-
 board/ti/am335x/board.c                       |   2 +-
 board/ti/am43xx/board.c                       |   2 +-
 common/fdt_support.c                          |  10 +-
 doc/device-tree-bindings/arm/omap,ctrl.txt    |  82 +++
 doc/device-tree-bindings/arm/omap,prcm.txt    |  63 +++
 .../clock/clock-bindings.txt                  | 186 +++++++
 .../clock/gpio-gate-clock.txt                 |  21 +
 .../clock/ti,autoidle.txt                     |  39 ++
 doc/device-tree-bindings/clock/ti,clkctrl.txt |  61 +++
 .../clock/ti,clockdomain.txt                  |  24 +
 doc/device-tree-bindings/clock/ti,divider.txt | 117 +++++
 doc/device-tree-bindings/clock/ti,dpll.txt    |  85 ++++
 doc/device-tree-bindings/clock/ti,gate.txt    | 106 ++++
 doc/device-tree-bindings/clock/ti,mux.txt     |  79 +++
 .../pinctrl/pinctrl-single.txt                | 255 ++++++++++
 doc/device-tree-bindings/pwm/ti,ehrpwm.txt    |  49 ++
 doc/device-tree-bindings/pwm/ti,pwmss.txt     |  58 +++
 drivers/clk/Kconfig                           |   9 +-
 drivers/clk/Makefile                          |   2 +-
 drivers/clk/clk-divider.c                     |  18 +-
 drivers/clk/clk-uclass.c                      |  15 +
 drivers/clk/clk_sandbox.c                     |  17 +
 drivers/clk/clk_sandbox_test.c                |  10 +
 drivers/clk/ti/Kconfig                        |  42 ++
 drivers/clk/ti/Makefile                       |  18 +
 drivers/clk/ti/am3-prcm.c                     |  73 +++
 drivers/clk/ti/clk-am3-dpll-x2.c              |  78 +++
 drivers/clk/ti/clk-am3-dpll.c                 | 267 ++++++++++
 drivers/clk/ti/clk-ctrl.c                     | 102 ++++
 drivers/clk/ti/clk-divider.c                  | 380 ++++++++++++++
 drivers/clk/ti/clk-gate.c                     |  92 ++++
 drivers/clk/ti/clk-mux.c                      | 252 ++++++++++
 drivers/clk/{clk-ti-sci.c => ti/clk-sci.c}    |   0
 drivers/clk/ti/clk.c                          |  34 ++
 drivers/clk/ti/clk.h                          |  13 +
 drivers/clk/ti/omap4-cm.c                     |  22 +
 drivers/core/Kconfig                          |  12 +
 drivers/core/fdtaddr.c                        |   2 +-
 drivers/core/of_addr.c                        |  14 +-
 drivers/core/ofnode.c                         |  11 +-
 drivers/core/read.c                           |   6 +
 drivers/misc/Kconfig                          |   7 +
 drivers/misc/Makefile                         |   1 +
 drivers/misc/ti-am3-scm.c                     |  90 ++++
 drivers/pwm/Kconfig                           |  13 +
 drivers/pwm/Makefile                          |   2 +
 drivers/pwm/pwm-ti-ehrpwm.c                   | 465 ++++++++++++++++++
 drivers/pwm/pwm-ti-pwmss.c                    |  95 ++++
 drivers/timer/omap-timer.c                    |   6 +-
 drivers/video/Kconfig                         |   5 +-
 drivers/video/Makefile                        |   2 +-
 drivers/video/pwm_backlight.c                 |   4 +-
 drivers/video/ti/Kconfig                      |   8 +
 drivers/video/ti/Makefile                     |  10 +
 drivers/video/{ => ti}/am335x-fb.c            | 342 +------------
 drivers/video/{ => ti}/am335x-fb.h            |   4 -
 drivers/video/ti/tilcdc-panel.c               | 171 +++++++
 drivers/video/ti/tilcdc-panel.h               |  14 +
 drivers/video/ti/tilcdc.c                     | 438 +++++++++++++++++
 drivers/video/ti/tilcdc.h                     |  38 ++
 include/asm-generic/gpio.h                    |   2 +-
 include/clk-uclass.h                          |   8 +
 include/clk.h                                 |  29 ++
 include/dm/read.h                             |  24 +
 include/dm/uclass.h                           |   3 +-
 include/linux/clk-provider.h                  |  11 +-
 test/dm/clk.c                                 |  22 +
 test/dm/panel.c                               |  12 +-
 test/dm/test-fdt.c                            | 153 +++++-
 87 files changed, 4459 insertions(+), 438 deletions(-)
 create mode 100644 doc/device-tree-bindings/arm/omap,ctrl.txt
 create mode 100644 doc/device-tree-bindings/arm/omap,prcm.txt
 create mode 100644 doc/device-tree-bindings/clock/clock-bindings.txt
 create mode 100644 doc/device-tree-bindings/clock/gpio-gate-clock.txt
 create mode 100644 doc/device-tree-bindings/clock/ti,autoidle.txt
 create mode 100644 doc/device-tree-bindings/clock/ti,clkctrl.txt
 create mode 100644 doc/device-tree-bindings/clock/ti,clockdomain.txt
 create mode 100644 doc/device-tree-bindings/clock/ti,divider.txt
 create mode 100644 doc/device-tree-bindings/clock/ti,dpll.txt
 create mode 100644 doc/device-tree-bindings/clock/ti,gate.txt
 create mode 100644 doc/device-tree-bindings/clock/ti,mux.txt
 create mode 100644 doc/device-tree-bindings/pinctrl/pinctrl-single.txt
 create mode 100644 doc/device-tree-bindings/pwm/ti,ehrpwm.txt
 create mode 100644 doc/device-tree-bindings/pwm/ti,pwmss.txt
 create mode 100644 drivers/clk/ti/Kconfig
 create mode 100644 drivers/clk/ti/Makefile
 create mode 100644 drivers/clk/ti/am3-prcm.c
 create mode 100644 drivers/clk/ti/clk-am3-dpll-x2.c
 create mode 100644 drivers/clk/ti/clk-am3-dpll.c
 create mode 100644 drivers/clk/ti/clk-ctrl.c
 create mode 100644 drivers/clk/ti/clk-divider.c
 create mode 100644 drivers/clk/ti/clk-gate.c
 create mode 100644 drivers/clk/ti/clk-mux.c
 rename drivers/clk/{clk-ti-sci.c => ti/clk-sci.c} (100%)
 create mode 100644 drivers/clk/ti/clk.c
 create mode 100644 drivers/clk/ti/clk.h
 create mode 100644 drivers/clk/ti/omap4-cm.c
 create mode 100644 drivers/misc/ti-am3-scm.c
 create mode 100644 drivers/pwm/pwm-ti-ehrpwm.c
 create mode 100644 drivers/pwm/pwm-ti-pwmss.c
 create mode 100644 drivers/video/ti/Kconfig
 create mode 100644 drivers/video/ti/Makefile
 rename drivers/video/{ => ti}/am335x-fb.c (54%)
 rename drivers/video/{ => ti}/am335x-fb.h (97%)
 create mode 100644 drivers/video/ti/tilcdc-panel.c
 create mode 100644 drivers/video/ti/tilcdc-panel.h
 create mode 100644 drivers/video/ti/tilcdc.c
 create mode 100644 drivers/video/ti/tilcdc.h
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/31 clk: remove a redundant header

The linux/err.h header file was included twice.

---

 include/linux/clk-provider.h | 1 -
 1 file changed, 1 deletion(-)
include/linux/clk-provider.h +0 -1
index 79dce8f0ad..a2630056de 100644
@@ -12,7 +12,6 @@
 #include <linux/bitops.h>
 #include <linux/err.h>
 #include <clk-uclass.h>
-#include <linux/err.h>
 
 struct udevice;
 
Signature · 1 line
2.17.1
#3 lore raw

PATCH 2/31 clk: export generic routines

In reply to Dario Binacchi

Export routines that can be used by other drivers avoiding duplicating code.

---

 drivers/clk/clk-divider.c    | 18 +++++++++---------
 include/linux/clk-provider.h | 10 ++++++++++
 2 files changed, 19 insertions(+), 9 deletions(-)
drivers/clk/clk-divider.c +9 -9
index 8f59d7fb72..9fd5fa8423 100644
@@ -28,7 +28,7 @@
 
 #define UBOOT_DM_CLK_CCF_DIVIDER "ccf_clk_divider"
 
-static unsigned int _get_table_div(const struct clk_div_table *table,
+unsigned int divider_get_table_div(const struct clk_div_table *table,
 				   unsigned int val)
 {
 	const struct clk_div_table *clkt;
@@ -49,7 +49,7 @@ static unsigned int _get_div(const struct clk_div_table *table,
 	if (flags & CLK_DIVIDER_MAX_AT_ZERO)
 		return val ? val : clk_div_mask(width) + 1;
 	if (table)
-		return _get_table_div(table, val);
+		return divider_get_table_div(table, val);
 	return val + 1;
 }
 
@@ -89,7 +89,7 @@ static ulong clk_divider_recalc_rate(struct clk *clk)
 				   divider->flags, divider->width);
 }
 
-static bool _is_valid_table_div(const struct clk_div_table *table,
+bool divider_is_valid_table_div(const struct clk_div_table *table,
 				unsigned int div)
 {
 	const struct clk_div_table *clkt;
@@ -100,17 +100,17 @@ static bool _is_valid_table_div(const struct clk_div_table *table,
 	return false;
 }
 
-static bool _is_valid_div(const struct clk_div_table *table, unsigned int div,
-			  unsigned long flags)
+bool divider_is_valid_div(const struct clk_div_table *table,
+			  unsigned int div, unsigned long flags)
 {
 	if (flags & CLK_DIVIDER_POWER_OF_TWO)
 		return is_power_of_2(div);
 	if (table)
-		return _is_valid_table_div(table, div);
+		return divider_is_valid_table_div(table, div);
 	return true;
 }
 
-static unsigned int _get_table_val(const struct clk_div_table *table,
+unsigned int divider_get_table_val(const struct clk_div_table *table,
 				   unsigned int div)
 {
 	const struct clk_div_table *clkt;
@@ -131,7 +131,7 @@ static unsigned int _get_val(const struct clk_div_table *table,
 	if (flags & CLK_DIVIDER_MAX_AT_ZERO)
 		return (div == clk_div_mask(width) + 1) ? 0 : div;
 	if (table)
-		return  _get_table_val(table, div);
+		return  divider_get_table_val(table, div);
 	return div - 1;
 }
 int divider_get_val(unsigned long rate, unsigned long parent_rate,
@@ -142,7 +142,7 @@ int divider_get_val(unsigned long rate, unsigned long parent_rate,
 
 	div = DIV_ROUND_UP_ULL((u64)parent_rate, rate);
 
-	if (!_is_valid_div(table, div, flags))
+	if (!divider_is_valid_div(table, div, flags))
 		return -EINVAL;
 
 	value = _get_val(table, div, flags, width);
include/linux/clk-provider.h +10 -0
index a2630056de..b7cc8d89f1 100644
@@ -74,6 +74,7 @@ struct clk_mux {
 #define to_clk_mux(_clk) container_of(_clk, struct clk_mux, clk)
 extern const struct clk_ops clk_mux_ops;
 u8 clk_mux_get_parent(struct clk *clk);
+unsigned int clk_mux_index_to_val(u32 *table, unsigned int flags, u8 index);
 
 struct clk_gate {
 	struct clk	clk;
@@ -124,6 +125,15 @@ struct clk_divider {
 #define CLK_DIVIDER_READ_ONLY		BIT(5)
 #define CLK_DIVIDER_MAX_AT_ZERO		BIT(6)
 extern const struct clk_ops clk_divider_ops;
+
+unsigned int divider_get_table_div(const struct clk_div_table *table,
+				   unsigned int val);
+unsigned int divider_get_table_val(const struct clk_div_table *table,
+				   unsigned int div);
+bool divider_is_valid_div(const struct clk_div_table *table,
+			  unsigned int div, unsigned long flags);
+bool divider_is_valid_table_div(const struct clk_div_table *table,
+				unsigned int div);
 unsigned long divider_recalc_rate(struct clk *hw, unsigned long parent_rate,
 				  unsigned int val,
 				  const struct clk_div_table *table,
Signature · 1 line
2.17.1
#4 lore raw

PATCH 2/31 clk: export generic routines

Hi Dario,

Quoted 16 lines · Dario Binacchi

Export routines that can be used by other drivers avoiding duplicating code.

---

 drivers/clk/clk-divider.c    | 18 +++++++++---------
 include/linux/clk-provider.h | 10 ++++++++++
 2 files changed, 19 insertions(+), 9 deletions(-)
drivers/clk/clk-divider.c +0 -0
index 8f59d7fb72..9fd5fa8423 100644

drivers/clk/clk-divider.c line 32

Quoted 6 lines
drivers/clk/clk-divider.c +1 -1
@@ -28,7 +28,7 @@
 
 #define UBOOT_DM_CLK_CCF_DIVIDER "ccf_clk_divider"
 
-static unsigned int _get_table_div(const struct clk_div_table *table,
+unsigned int divider_get_table_div(const struct clk_div_table *table,
                                   unsigned int val)

I think clkdiv_ or clk_divider_ might be a good prefix for the expected functions in this file, so it is clear it relates to clock.

Quoted 75 lines
drivers/clk/clk-divider.c +8 -8
 {
        const struct clk_div_table *clkt;
@@ -49,7 +49,7 @@ static unsigned int _get_div(const struct clk_div_table *table,
        if (flags & CLK_DIVIDER_MAX_AT_ZERO)
                return val ? val : clk_div_mask(width) + 1;
        if (table)
-               return _get_table_div(table, val);
+               return divider_get_table_div(table, val);
        return val + 1;
 }
 
@@ -89,7 +89,7 @@ static ulong clk_divider_recalc_rate(struct clk *clk)
                                   divider->flags, divider->width);
 }
 
-static bool _is_valid_table_div(const struct clk_div_table *table,
+bool divider_is_valid_table_div(const struct clk_div_table *table,
                                unsigned int div)
 {
        const struct clk_div_table *clkt;
@@ -100,17 +100,17 @@ static bool _is_valid_table_div(const struct clk_div_table *table,
        return false;
 }
 
-static bool _is_valid_div(const struct clk_div_table *table, unsigned int div,
-                         unsigned long flags)
+bool divider_is_valid_div(const struct clk_div_table *table,
+                         unsigned int div, unsigned long flags)
 {
        if (flags & CLK_DIVIDER_POWER_OF_TWO)
                return is_power_of_2(div);
        if (table)
-               return _is_valid_table_div(table, div);
+               return divider_is_valid_table_div(table, div);
        return true;
 }
 
-static unsigned int _get_table_val(const struct clk_div_table *table,
+unsigned int divider_get_table_val(const struct clk_div_table *table,
                                   unsigned int div)
 {
        const struct clk_div_table *clkt;
@@ -131,7 +131,7 @@ static unsigned int _get_val(const struct clk_div_table *table,
        if (flags & CLK_DIVIDER_MAX_AT_ZERO)
                return (div == clk_div_mask(width) + 1) ? 0 : div;
        if (table)
-               return  _get_table_val(table, div);
+               return  divider_get_table_val(table, div);
        return div - 1;
 }
 int divider_get_val(unsigned long rate, unsigned long parent_rate,
@@ -142,7 +142,7 @@ int divider_get_val(unsigned long rate, unsigned long parent_rate,
 
        div = DIV_ROUND_UP_ULL((u64)parent_rate, rate);
 
-       if (!_is_valid_div(table, div, flags))
+       if (!divider_is_valid_div(table, div, flags))
                return -EINVAL;
 
        value = _get_val(table, div, flags, width);
include/linux/clk-provider.h +1 -0
index a2630056de..b7cc8d89f1 100644
@@ -74,6 +74,7 @@ struct clk_mux {
 #define to_clk_mux(_clk) container_of(_clk, struct clk_mux, clk)
 extern const struct clk_ops clk_mux_ops;
 u8 clk_mux_get_parent(struct clk *clk);
+unsigned int clk_mux_index_to_val(u32 *table, unsigned int flags, u8 index);
 
 struct clk_gate {
        struct clk      clk;
@@ -124,6 +125,15 @@ struct clk_divider {
 #define CLK_DIVIDER_READ_ONLY          BIT(5)
 #define CLK_DIVIDER_MAX_AT_ZERO                BIT(6)

include/linux/clk-provider.h struct clk_divider { · line 136

Quoted 10 lines
include/linux/clk-provider.h +9 -0
 extern const struct clk_ops clk_divider_ops;
+
+unsigned int divider_get_table_div(const struct clk_div_table *table,
+                                  unsigned int val);
+unsigned int divider_get_table_val(const struct clk_div_table *table,
+                                  unsigned int div);
+bool divider_is_valid_div(const struct clk_div_table *table,
+                         unsigned int div, unsigned long flags);
+bool divider_is_valid_table_div(const struct clk_div_table *table,
+                               unsigned int div);

These need full function comments.

Quoted 6 lines
include/linux/clk-provider.h +0 -1
 unsigned long divider_recalc_rate(struct clk *hw, unsigned long parent_rate,
                                  unsigned int val,
                                  const struct clk_div_table *table,
--

2.17.1

Regards,
SImon

#5 lore raw

PATCH 3/31 arch: sandbox: fix typo in clk.h

In reply to Dario Binacchi

Fix the 'devivce' typo in arch/sandbox/include/asm/clk.h.

---

 arch/sandbox/include/asm/clk.h | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)
arch/sandbox/include/asm/clk.h +13 -13
index c184c4bffc..1163e61026 100644
@@ -74,7 +74,7 @@ int sandbox_clk_query_requested(struct udevice *dev, int id);
  * sandbox_clk_test_get - Ask the sandbox clock test device to request its
  * clocks.
  *
- * @dev:	The sandbox clock test (client) devivce.
+ * @dev:	The sandbox clock test (client) device.
  * @return:	0 if OK, or a negative error code.
  */
 int sandbox_clk_test_get(struct udevice *dev);
@@ -83,7 +83,7 @@ int sandbox_clk_test_get(struct udevice *dev);
  * sandbox_clk_test_devm_get - Ask the sandbox clock test device to request its
  * clocks using the managed API.
  *
- * @dev:	The sandbox clock test (client) devivce.
+ * @dev:	The sandbox clock test (client) device.
  * @return:	0 if OK, or a negative error code.
  */
 int sandbox_clk_test_devm_get(struct udevice *dev);
@@ -92,7 +92,7 @@ int sandbox_clk_test_devm_get(struct udevice *dev);
  * sandbox_clk_test_get_bulk - Ask the sandbox clock test device to request its
  * clocks with the bulk clk API.
  *
- * @dev:	The sandbox clock test (client) devivce.
+ * @dev:	The sandbox clock test (client) device.
  * @return:	0 if OK, or a negative error code.
  */
 int sandbox_clk_test_get_bulk(struct udevice *dev);
@@ -100,7 +100,7 @@ int sandbox_clk_test_get_bulk(struct udevice *dev);
  * sandbox_clk_test_get_rate - Ask the sandbox clock test device to query a
  * clock's rate.
  *
- * @dev:	The sandbox clock test (client) devivce.
+ * @dev:	The sandbox clock test (client) device.
  * @id:		The test device's clock ID to query.
  * @return:	The rate of the clock.
  */
@@ -109,7 +109,7 @@ ulong sandbox_clk_test_get_rate(struct udevice *dev, int id);
  * sandbox_clk_test_set_rate - Ask the sandbox clock test device to set a
  * clock's rate.
  *
- * @dev:	The sandbox clock test (client) devivce.
+ * @dev:	The sandbox clock test (client) device.
  * @id:		The test device's clock ID to configure.
  * @return:	The new rate of the clock.
  */
@@ -118,7 +118,7 @@ ulong sandbox_clk_test_set_rate(struct udevice *dev, int id, ulong rate);
  * sandbox_clk_test_enable - Ask the sandbox clock test device to enable a
  * clock.
  *
- * @dev:	The sandbox clock test (client) devivce.
+ * @dev:	The sandbox clock test (client) device.
  * @id:		The test device's clock ID to configure.
  * @return:	0 if OK, or a negative error code.
  */
@@ -127,7 +127,7 @@ int sandbox_clk_test_enable(struct udevice *dev, int id);
  * sandbox_clk_test_enable_bulk - Ask the sandbox clock test device to enable
  * all clocks in it's clock bulk struct.
  *
- * @dev:	The sandbox clock test (client) devivce.
+ * @dev:	The sandbox clock test (client) device.
  * @return:	0 if OK, or a negative error code.
  */
 int sandbox_clk_test_enable_bulk(struct udevice *dev);
@@ -135,7 +135,7 @@ int sandbox_clk_test_enable_bulk(struct udevice *dev);
  * sandbox_clk_test_disable - Ask the sandbox clock test device to disable a
  * clock.
  *
- * @dev:	The sandbox clock test (client) devivce.
+ * @dev:	The sandbox clock test (client) device.
  * @id:		The test device's clock ID to configure.
  * @return:	0 if OK, or a negative error code.
  */
@@ -144,7 +144,7 @@ int sandbox_clk_test_disable(struct udevice *dev, int id);
  * sandbox_clk_test_disable_bulk - Ask the sandbox clock test device to disable
  * all clocks in it's clock bulk struct.
  *
- * @dev:	The sandbox clock test (client) devivce.
+ * @dev:	The sandbox clock test (client) device.
  * @return:	0 if OK, or a negative error code.
  */
 int sandbox_clk_test_disable_bulk(struct udevice *dev);
@@ -152,7 +152,7 @@ int sandbox_clk_test_disable_bulk(struct udevice *dev);
  * sandbox_clk_test_free - Ask the sandbox clock test device to free its
  * clocks.
  *
- * @dev:	The sandbox clock test (client) devivce.
+ * @dev:	The sandbox clock test (client) device.
  * @return:	0 if OK, or a negative error code.
  */
 int sandbox_clk_test_free(struct udevice *dev);
@@ -160,7 +160,7 @@ int sandbox_clk_test_free(struct udevice *dev);
  * sandbox_clk_test_release_bulk - Ask the sandbox clock test device to release
  * all clocks in it's clock bulk struct.
  *
- * @dev:	The sandbox clock test (client) devivce.
+ * @dev:	The sandbox clock test (client) device.
  * @return:	0 if OK, or a negative error code.
  */
 int sandbox_clk_test_release_bulk(struct udevice *dev);
@@ -168,7 +168,7 @@ int sandbox_clk_test_release_bulk(struct udevice *dev);
  * sandbox_clk_test_valid - Ask the sandbox clock test device to check its
  * clocks are valid.
  *
- * @dev:	The sandbox clock test (client) devivce.
+ * @dev:	The sandbox clock test (client) device.
  * @return:	0 if OK, or a negative error code.
  */
 int sandbox_clk_test_valid(struct udevice *dev);
@@ -176,7 +176,7 @@ int sandbox_clk_test_valid(struct udevice *dev);
  * sandbox_clk_test_valid - Ask the sandbox clock test device to check its
  * clocks are valid.
  *
- * @dev:	The sandbox clock test (client) devivce.
+ * @dev:	The sandbox clock test (client) device.
  * @return:	0 if OK, or a negative error code.
  */
 struct clk *sandbox_clk_test_get_devm_clk(struct udevice *dev, int id);
Signature · 1 line
2.17.1
#7 lore raw

PATCH 4/31 clk: add clk_round_rate()

In reply to Dario Binacchi

It returns the rate which will be set if you ask clk_set_rate() to set that rate. It provides a way to query exactly what rate you'll get if you call clk_set_rate() with that same argument.
So essentially, clk_round_rate() and clk_set_rate() are equivalent except the former does not modify the clock hardware in any way.

---

 arch/sandbox/include/asm/clk.h |  9 +++++++++
 drivers/clk/clk-uclass.c       | 15 +++++++++++++++
 drivers/clk/clk_sandbox.c      | 17 +++++++++++++++++
 drivers/clk/clk_sandbox_test.c | 10 ++++++++++
 include/clk-uclass.h           |  8 ++++++++
 include/clk.h                  | 29 +++++++++++++++++++++++++++++
 test/dm/clk.c                  | 22 ++++++++++++++++++++++
 7 files changed, 110 insertions(+)
arch/sandbox/include/asm/clk.h +9 -0
index 1163e61026..68a8687f57 100644
@@ -105,6 +105,15 @@ int sandbox_clk_test_get_bulk(struct udevice *dev);
  * @return:	The rate of the clock.
  */
 ulong sandbox_clk_test_get_rate(struct udevice *dev, int id);
+/**
+ * sandbox_clk_test_round_rate - Ask the sandbox clock test device to round a
+ * clock's rate.
+ *
+ * @dev:	The sandbox clock test (client) device.
+ * @id:		The test device's clock ID to configure.
+ * @return:	The rounded rate of the clock.
+ */
+ulong sandbox_clk_test_round_rate(struct udevice *dev, int id, ulong rate);
 /**
  * sandbox_clk_test_set_rate - Ask the sandbox clock test device to set a
  * clock's rate.
drivers/clk/clk-uclass.c +15 -0
index 934cd5787a..1b5541c3af 100644
@@ -494,6 +494,21 @@ long long clk_get_parent_rate(struct clk *clk)
 	return pclk->rate;
 }
 
+ulong clk_round_rate(struct clk *clk, ulong rate)
+{
+	const struct clk_ops *ops;
+
+	debug("%s(clk=%p, rate=%lu)\n", __func__, clk, rate);
+	if (!clk_valid(clk))
+		return 0;
+
+	ops = clk_dev_ops(clk->dev);
+	if (!ops->round_rate)
+		return -ENOSYS;
+
+	return ops->round_rate(clk, rate);
+}
+
 ulong clk_set_rate(struct clk *clk, ulong rate)
 {
 	const struct clk_ops *ops;
drivers/clk/clk_sandbox.c +17 -0
index 768fbb7c52..8361b930df 100644
@@ -30,6 +30,22 @@ static ulong sandbox_clk_get_rate(struct clk *clk)
 	return priv->rate[clk->id];
 }
 
+static ulong sandbox_clk_round_rate(struct clk *clk, ulong rate)
+{
+	struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
+
+	if (!priv->probed)
+		return -ENODEV;
+
+	if (clk->id >= SANDBOX_CLK_ID_COUNT)
+		return -EINVAL;
+
+	if (!rate)
+		return -EINVAL;
+
+	return rate;
+}
+
 static ulong sandbox_clk_set_rate(struct clk *clk, ulong rate)
 {
 	struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
@@ -103,6 +119,7 @@ static int sandbox_clk_free(struct clk *clk)
 }
 
 static struct clk_ops sandbox_clk_ops = {
+	.round_rate	= sandbox_clk_round_rate,
 	.get_rate	= sandbox_clk_get_rate,
 	.set_rate	= sandbox_clk_set_rate,
 	.enable		= sandbox_clk_enable,
drivers/clk/clk_sandbox_test.c +10 -0
index 873383856f..f7b77aa674 100644
@@ -86,6 +86,16 @@ ulong sandbox_clk_test_get_rate(struct udevice *dev, int id)
 	return clk_get_rate(sbct->clkps[id]);
 }
 
+ulong sandbox_clk_test_round_rate(struct udevice *dev, int id, ulong rate)
+{
+	struct sandbox_clk_test *sbct = dev_get_priv(dev);
+
+	if (id < 0 || id >= SANDBOX_CLK_TEST_ID_COUNT)
+		return -EINVAL;
+
+	return clk_round_rate(sbct->clkps[id], rate);
+}
+
 ulong sandbox_clk_test_set_rate(struct udevice *dev, int id, ulong rate)
 {
 	struct sandbox_clk_test *sbct = dev_get_priv(dev);
include/clk-uclass.h +8 -0
index dac42dab36..50e8681b55 100644
@@ -61,6 +61,14 @@ struct clk_ops {
 	 * @return 0 if OK, or a negative error code.
 	 */
 	int (*rfree)(struct clk *clock);
+	/**
+	 * round_rate() - Adjust a rate to the exact rate a clock can provide.
+	 *
+	 * @clk:	The clock to manipulate.
+	 * @rate:	Desidered clock rate in Hz.
+	 * @return rounded rate in Hz, or -ve error code.
+	 */
+	ulong (*round_rate)(struct clk *clk, ulong rate);
 	/**
 	 * get_rate() - Get current clock rate.
 	 *
include/clk.h +29 -0
index a62e2efa2c..cce763b05b 100644
@@ -366,6 +366,30 @@ struct clk *clk_get_parent(struct clk *clk);
  */
 long long clk_get_parent_rate(struct clk *clk);
 
+/**
+ * clk_round_rate() - Adjust a rate to the exact rate a clock can provide
+ *
+ * This answers the question "if I were to pass @rate to clk_set_rate(),
+ * what clock rate would I end up with?" without changing the hardware
+ * in any way.  In other words:
+ *
+ *   rate = clk_round_rate(clk, r);
+ *
+ * and:
+ *
+ *   clk_set_rate(clk, r);
+ *   rate = clk_get_rate(clk);
+ *
+ * are equivalent except the former does not modify the clock hardware
+ * in any way.
+ *
+ * @clk: A clock struct that was previously successfully requested by
+ *       clk_request/get_by_*().
+ * @rate: desired clock rate in Hz.
+ * @return rounded rate in Hz, or -ve error code.
+ */
+ulong clk_round_rate(struct clk *clk, ulong rate);
+
 /**
  * clk_set_rate() - Set current clock rate.
  *
@@ -482,6 +506,11 @@ static inline long long clk_get_parent_rate(struct clk *clk)
 	return -ENOSYS;
 }
 
+static inline ulong clk_round_rate(struct clk *clk, ulong rate)
+{
+	return -ENOSYS;
+}
+
 static inline ulong clk_set_rate(struct clk *clk, ulong rate)
 {
 	return -ENOSYS;
test/dm/clk.c +22 -0
index edca3b49f6..21997ed892 100644
@@ -112,6 +112,28 @@ static int dm_test_clk(struct unit_test_state *uts)
 	rate = sandbox_clk_test_set_rate(dev_test, SANDBOX_CLK_TEST_ID_I2C, 0);
 	ut_assert(IS_ERR_VALUE(rate));
 
+	ut_asserteq(10000, sandbox_clk_test_get_rate(dev_test,
+						     SANDBOX_CLK_TEST_ID_SPI));
+	ut_asserteq(20000, sandbox_clk_test_get_rate(dev_test,
+						     SANDBOX_CLK_TEST_ID_I2C));
+
+	ut_asserteq(5000, sandbox_clk_test_round_rate(dev_test,
+						      SANDBOX_CLK_TEST_ID_SPI,
+						      5000));
+	ut_asserteq(7000, sandbox_clk_test_round_rate(dev_test,
+						      SANDBOX_CLK_TEST_ID_I2C,
+						      7000));
+
+	ut_asserteq(10000, sandbox_clk_test_get_rate(dev_test,
+						     SANDBOX_CLK_TEST_ID_SPI));
+	ut_asserteq(20000, sandbox_clk_test_get_rate(dev_test,
+						     SANDBOX_CLK_TEST_ID_I2C));
+
+	rate = sandbox_clk_test_round_rate(dev_test, SANDBOX_CLK_TEST_ID_SPI, 0);
+	ut_assert(IS_ERR_VALUE(rate));
+	rate = sandbox_clk_test_round_rate(dev_test, SANDBOX_CLK_TEST_ID_I2C, 0);
+	ut_assert(IS_ERR_VALUE(rate));
+
 	ut_asserteq(10000, sandbox_clk_test_get_rate(dev_test,
 						     SANDBOX_CLK_TEST_ID_SPI));
 	ut_asserteq(20000, sandbox_clk_test_get_rate(dev_test,
Signature · 1 line
2.17.1
#8 lore raw

PATCH 4/31 clk: add clk_round_rate()

Hi Dario,

+Stephen Warren

Quoted 10 lines · Dario Binacchi

It returns the rate which will be set if you ask clk_set_rate() to set that rate. It provides a way to query exactly what rate you'll get if you call clk_set_rate() with that same argument.
So essentially, clk_round_rate() and clk_set_rate() are equivalent except the former does not modify the clock hardware in any way.

---

Quoted 9 lines
 arch/sandbox/include/asm/clk.h |  9 +++++++++
 drivers/clk/clk-uclass.c       | 15 +++++++++++++++
 drivers/clk/clk_sandbox.c      | 17 +++++++++++++++++
 drivers/clk/clk_sandbox_test.c | 10 ++++++++++
 include/clk-uclass.h           |  8 ++++++++
 include/clk.h                  | 29 +++++++++++++++++++++++++++++
 test/dm/clk.c                  | 22 ++++++++++++++++++++++
 7 files changed, 110 insertions(+)

But I wonder if we should change the set_rate() uclass interface to have a flag value, one of the flags being 'dry run' which doesn't actually set the value?

You would still have the same call to the uclass functions clk_set_rate() and clk_round_rate() but the driver API would implement both with calls to set_rate()?

#9 lore raw

PATCH 4/31 clk: add clk_round_rate()

Quoted 26 lines · Simon Glass

Hi Dario,

+Stephen Warren

Quoted 10 lines · Dario Binacchi

It returns the rate which will be set if you ask clk_set_rate() to set that rate. It provides a way to query exactly what rate you'll get if you call clk_set_rate() with that same argument.
So essentially, clk_round_rate() and clk_set_rate() are equivalent except the former does not modify the clock hardware in any way.

---

Quoted 9 lines
 arch/sandbox/include/asm/clk.h |  9 +++++++++
 drivers/clk/clk-uclass.c       | 15 +++++++++++++++
 drivers/clk/clk_sandbox.c      | 17 +++++++++++++++++
 drivers/clk/clk_sandbox_test.c | 10 ++++++++++
 include/clk-uclass.h           |  8 ++++++++
 include/clk.h                  | 29 +++++++++++++++++++++++++++++
 test/dm/clk.c                  | 22 ++++++++++++++++++++++
 7 files changed, 110 insertions(+)
Quoted 7 lines

But I wonder if we should change the set_rate() uclass interface to have a flag value, one of the flags being 'dry run' which doesn't actually set the value?

You would still have the same call to the uclass functions clk_set_rate() and clk_round_rate() but the driver API would implement both with calls to set_rate()?

Linux uses separate clk_ops functions for this purpose

Quoted 8 lines

* @recalc_rate Recalculate the rate of this clock, by querying hardware. The
* parent rate is an input parameter. It is up to the caller to
* ensure that the prepare_mutex is held across this call.
* Returns the calculated rate. Optional, but recommended - if
* this op is not set then clock rate will be initialized to 0.
(...snip...)

	long		(*round_rate)(struct clk_hw *hw, unsigned long rate,
					unsigned long *parent_rate);

Besides matching their interface, I think there is good reason for keeping these functions separate. Existing clock drivers would need to be rewritten so they don't set the clock rate when you just want to do a dry run. This way, it's very clear when a driver supports recalc_rate.

--Sean

#10 lore raw

PATCH 4/31 clk: add clk_round_rate()

Quoted 32 lines · Sean Anderson
Quoted 30 lines · Simon Glass

Hi Dario,

+Stephen Warren

Quoted 10 lines · Dario Binacchi

It returns the rate which will be set if you ask clk_set_rate() to set that rate. It provides a way to query exactly what rate you'll get if you call clk_set_rate() with that same argument.
So essentially, clk_round_rate() and clk_set_rate() are equivalent except the former does not modify the clock hardware in any way.

---

Quoted 9 lines
 arch/sandbox/include/asm/clk.h |  9 +++++++++
 drivers/clk/clk-uclass.c       | 15 +++++++++++++++
 drivers/clk/clk_sandbox.c      | 17 +++++++++++++++++
 drivers/clk/clk_sandbox_test.c | 10 ++++++++++
 include/clk-uclass.h           |  8 ++++++++
 include/clk.h                  | 29 +++++++++++++++++++++++++++++
 test/dm/clk.c                  | 22 ++++++++++++++++++++++
 7 files changed, 110 insertions(+)

But I wonder if we should change the set_rate() uclass interface to have a flag value, one of the flags being 'dry run' which doesn't actually set the value?

Quoted 11 lines
Quoted 3 lines

You would still have the same call to the uclass functions clk_set_rate() and clk_round_rate() but the driver API would implement both with calls to set_rate()?

Linux uses separate clk_ops functions for this purpose

Quoted 5 lines

* @recalc_rate Recalculate the rate of this clock, by querying hardware. The
* parent rate is an input parameter. It is up to the caller to
* ensure that the prepare_mutex is held across this call.
* Returns the calculated rate. Optional, but recommended - if
* this op is not set then clock rate will be initialized to 0.

err, I meant to quote

Quoted 15 lines

* @round_rate: Given a target rate as input, returns the closest rate actually
* supported by the clock. The parent rate is an input/output
* parameter.

Quoted 3 lines

(...snip...)

	long		(*round_rate)(struct clk_hw *hw, unsigned long rate,
					unsigned long *parent_rate);

Besides matching their interface, I think there is good reason for keeping these functions separate. Existing clock drivers would need to be rewritten so they don't set the clock rate when you just want to do a dry run. This way, it's very clear when a driver supports recalc_rate.

--Sean

#11 lore raw

PATCH 4/31 clk: add clk_round_rate()

Quoted 43 lines

Il 29/08/2020 23:50 Sean Anderson <[email protected]> ha scritto:

Quoted 38 lines · Sean Anderson
Quoted 26 lines · Simon Glass

Hi Dario,

+Stephen Warren

Quoted 10 lines · Dario Binacchi

It returns the rate which will be set if you ask clk_set_rate() to set that rate. It provides a way to query exactly what rate you'll get if you call clk_set_rate() with that same argument.
So essentially, clk_round_rate() and clk_set_rate() are equivalent except the former does not modify the clock hardware in any way.

---

Quoted 9 lines
 arch/sandbox/include/asm/clk.h |  9 +++++++++
 drivers/clk/clk-uclass.c       | 15 +++++++++++++++
 drivers/clk/clk_sandbox.c      | 17 +++++++++++++++++
 drivers/clk/clk_sandbox_test.c | 10 ++++++++++
 include/clk-uclass.h           |  8 ++++++++
 include/clk.h                  | 29 +++++++++++++++++++++++++++++
 test/dm/clk.c                  | 22 ++++++++++++++++++++++
 7 files changed, 110 insertions(+)
Quoted 7 lines

But I wonder if we should change the set_rate() uclass interface to have a flag value, one of the flags being 'dry run' which doesn't actually set the value?

You would still have the same call to the uclass functions clk_set_rate() and clk_round_rate() but the driver API would implement both with calls to set_rate()?

Linux uses separate clk_ops functions for this purpose

Quoted 20 lines
Quoted 5 lines
Quoted 5 lines

* @recalc_rate Recalculate the rate of this clock, by querying hardware. The
* parent rate is an input parameter. It is up to the caller to
* ensure that the prepare_mutex is held across this call.
* Returns the calculated rate. Optional, but recommended - if
* this op is not set then clock rate will be initialized to 0.

err, I meant to quote

Quoted 12 lines

* @round_rate: Given a target rate as input, returns the closest rate actually
* supported by the clock. The parent rate is an input/output
* parameter.

Quoted 3 lines

(...snip...)

	long		(*round_rate)(struct clk_hw *hw, unsigned long rate,
					unsigned long *parent_rate);

Besides matching their interface, I think there is good reason for keeping these functions separate. Existing clock drivers would need to be rewritten so they don't set the clock rate when you just want to do a dry run. This way, it's very clear when a driver supports recalc_rate.

I agree.

Quoted 3 lines
Quoted 3 lines

--Sean

#12 lore raw

PATCH 5/31 clk: ti: add mux clock driver

In reply to Dario Binacchi

The driver manages a register-mapped multiplexer with multiple input clock signals or parents, one of which can be selected as output. It uses routines provided by the common clock framework (ccf).

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

---

 .../clock/clock-bindings.txt                  | 186 ++++++++++++
 doc/device-tree-bindings/clock/ti,mux.txt     |  79 +++++
 drivers/clk/Kconfig                           |   6 +
 drivers/clk/Makefile                          |   1 +
 drivers/clk/clk-ti-mux.c                      | 275 ++++++++++++++++++
 5 files changed, 547 insertions(+)
 create mode 100644 doc/device-tree-bindings/clock/clock-bindings.txt
 create mode 100644 doc/device-tree-bindings/clock/ti,mux.txt
 create mode 100644 drivers/clk/clk-ti-mux.c
doc/device-tree-bindings/clock/clock-bindings.txt new file +186 -0
new file mode 100644
index 0000000000..8a55fdcf96
@@ -0,0 +1,186 @@
+This binding is a work-in-progress, and are based on some experimental
+work by benh[1].
+
+Sources of clock signal can be represented by any node in the device
+tree.  Those nodes are designated as clock providers.  Clock consumer
+nodes use a phandle and clock specifier pair to connect clock provider
+outputs to clock inputs.  Similar to the gpio specifiers, a clock
+specifier is an array of zero, one or more cells identifying the clock
+output on a device.  The length of a clock specifier is defined by the
+value of a #clock-cells property in the clock provider node.
+
+[1] http://patchwork.ozlabs.org/patch/31551/
+
+==Clock providers==
+
+Required properties:
+#clock-cells:	   Number of cells in a clock specifier; Typically 0 for nodes
+		   with a single clock output and 1 for nodes with multiple
+		   clock outputs.
+
+Optional properties:
+clock-output-names: Recommended to be a list of strings of clock output signal
+		    names indexed by the first cell in the clock specifier.
+		    However, the meaning of clock-output-names is domain
+		    specific to the clock provider, and is only provided to
+		    encourage using the same meaning for the majority of clock
+		    providers.  This format may not work for clock providers
+		    using a complex clock specifier format.  In those cases it
+		    is recommended to omit this property and create a binding
+		    specific names property.
+
+		    Clock consumer nodes must never directly reference
+		    the provider's clock-output-names property.
+
+For example:
+
+    oscillator {
+        #clock-cells = <1>;
+        clock-output-names = "ckil", "ckih";
+    };
+
+- this node defines a device with two clock outputs, the first named
+  "ckil" and the second named "ckih".  Consumer nodes always reference
+  clocks by index. The names should reflect the clock output signal
+  names for the device.
+
+clock-indices:	   If the identifying number for the clocks in the node
+		   is not linear from zero, then this allows the mapping of
+		   identifiers into the clock-output-names array.
+
+For example, if we have two clocks <&oscillator 1> and <&oscillator 3>:
+
+	oscillator {
+		compatible = "myclocktype";
+		#clock-cells = <1>;
+		clock-indices = <1>, <3>;
+		clock-output-names = "clka", "clkb";
+	}
+
+	This ensures we do not have any empty strings in clock-output-names
+
+
+==Clock consumers==
+
+Required properties:
+clocks:		List of phandle and clock specifier pairs, one pair
+		for each clock input to the device.  Note: if the
+		clock provider specifies '0' for #clock-cells, then
+		only the phandle portion of the pair will appear.
+
+Optional properties:
+clock-names:	List of clock input name strings sorted in the same
+		order as the clocks property.  Consumers drivers
+		will use clock-names to match clock input names
+		with clocks specifiers.
+clock-ranges:	Empty property indicating that child nodes can inherit named
+		clocks from this node. Useful for bus nodes to provide a
+		clock to their children.
+
+For example:
+
+    device {
+        clocks = <&osc 1>, <&ref 0>;
+        clock-names = "baud", "register";
+    };
+
+
+This represents a device with two clock inputs, named "baud" and "register".
+The baud clock is connected to output 1 of the &osc device, and the register
+clock is connected to output 0 of the &ref.
+
+==Example==
+
+    /* external oscillator */
+    osc: oscillator {
+        compatible = "fixed-clock";
+        #clock-cells = <0>;
+        clock-frequency  = <32678>;
+        clock-output-names = "osc";
+    };
+
+    /* phase-locked-loop device, generates a higher frequency clock
+     * from the external oscillator reference */
+    pll: pll at 4c000 {
+        compatible = "vendor,some-pll-interface"
+        #clock-cells = <1>;
+        clocks = <&osc 0>;
+        clock-names = "ref";
+        reg = <0x4c000 0x1000>;
+        clock-output-names = "pll", "pll-switched";
+    };
+
+    /* UART, using the low frequency oscillator for the baud clock,
+     * and the high frequency switched PLL output for register
+     * clocking */
+    uart at a000 {
+        compatible = "fsl,imx-uart";
+        reg = <0xa000 0x1000>;
+        interrupts = <33>;
+        clocks = <&osc 0>, <&pll 1>;
+        clock-names = "baud", "register";
+    };
+
+This DT fragment defines three devices: an external oscillator to provide a
+low-frequency reference clock, a PLL device to generate a higher frequency
+clock signal, and a UART.
+
+* The oscillator is fixed-frequency, and provides one clock output, named "osc".
+* The PLL is both a clock provider and a clock consumer. It uses the clock
+  signal generated by the external oscillator, and provides two output signals
+  ("pll" and "pll-switched").
+* The UART has its baud clock connected the external oscillator and its
+  register clock connected to the PLL clock (the "pll-switched" signal)
+
+==Assigned clock parents and rates==
+
+Some platforms may require initial configuration of default parent clocks
+and clock frequencies. Such a configuration can be specified in a device tree
+node through assigned-clocks, assigned-clock-parents and assigned-clock-rates
+properties. The assigned-clock-parents property should contain a list of parent
+clocks in the form of a phandle and clock specifier pair and the
+assigned-clock-rates property should contain a list of frequencies in Hz. Both
+these properties should correspond to the clocks listed in the assigned-clocks
+property.
+
+To skip setting parent or rate of a clock its corresponding entry should be
+set to 0, or can be omitted if it is not followed by any non-zero entry.
+
+    uart at a000 {
+        compatible = "fsl,imx-uart";
+        reg = <0xa000 0x1000>;
+        ...
+        clocks = <&osc 0>, <&pll 1>;
+        clock-names = "baud", "register";
+
+        assigned-clocks = <&clkcon 0>, <&pll 2>;
+        assigned-clock-parents = <&pll 2>;
+        assigned-clock-rates = <0>, <460800>;
+    };
+
+In this example the <&pll 2> clock is set as parent of clock <&clkcon 0> and
+the <&pll 2> clock is assigned a frequency value of 460800 Hz.
+
+Configuring a clock's parent and rate through the device node that consumes
+the clock can be done only for clocks that have a single user. Specifying
+conflicting parent or rate configuration in multiple consumer nodes for
+a shared clock is forbidden.
+
+Configuration of common clocks, which affect multiple consumer devices can
+be similarly specified in the clock provider node.
+
+==Protected clocks==
+
+Some platforms or firmwares may not fully expose all the clocks to the OS, such
+as in situations where those clks are used by drivers running in ARM secure
+execution levels. Such a configuration can be specified in device tree with the
+protected-clocks property in the form of a clock specifier list. This property should
+only be specified in the node that is providing the clocks being protected:
+
+   clock-controller at a000f000 {
+        compatible = "vendor,clk95;
+        reg = <0xa000f000 0x1000>
+        #clocks-cells = <1>;
+        ...
+        protected-clocks = <UART3_CLK>, <SPI5_CLK>;
+   };
doc/device-tree-bindings/clock/ti,mux.txt new file +79 -0

79 lines not on this page · raw message

drivers/clk/Kconfig +6 -0
index 6003e140b5..f070d2637f 100644
@@ -98,6 +98,12 @@ config CLK_STM32F
 	  This clock driver adds support for RCC clock management
 	  for STM32F4 and STM32F7 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
drivers/clk/Makefile +1 -0
index cda4b4b605..c0dfe4b599 100644
@@ -46,6 +46,7 @@ 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_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/clk-ti-mux.c new file +275 -0

275 lines not on this page · raw message

Signature · 1 line
2.17.1
#13 lore raw

PATCH 6/31 arm: ti: am33xx: add DPLL_EN_FAST_RELOCK_BYPASS macro

In reply to Dario Binacchi

Add missing DPLL_EN_FAST_RELOCK_BYPASS macro. Used to put the DPLL in idle bypass fast relock mode.

---

 arch/arm/include/asm/arch-am33xx/clock.h | 1 +
 1 file changed, 1 insertion(+)
arch/arm/include/asm/arch-am33xx/clock.h +1 -0
index dc7a9b188d..5d775902bb 100644
@@ -66,6 +66,7 @@
 #define DPLL_EN_STOP			1
 #define DPLL_EN_MN_BYPASS		4
 #define DPLL_EN_LOW_POWER_BYPASS	5
+#define DPLL_EN_FAST_RELOCK_BYPASS	6
 #define DPLL_EN_LOCK			7
 
 /* CM_IDLEST_DPLL fields */
Signature · 1 line
2.17.1
#14 lore raw

PATCH 7/31 clk: ti: am33xx: add DPLL clock drivers

In reply to Dario Binacchi

The digital phase-locked loop (DPLL) provides all interface clocks and functional clocks to the processor of the AM33xx device. The AM33xx device integrates five different DPLLs:
* Core DPLL
* Per DPLL
* LCD DPLL
* DDR DPLL
* MPU DPLL

The patch adds support for the compatible strings:
* "ti,am3-dpll-core-clock"
* "ti,am3-dpll-no-gate-clock"
* "ti,am3-dpll-no-gate-j-type-clock"
* "ti,am3-dpll-x2-clock"

The code is loosely based on the drivers/clk/ti/dpll.c drivers of the Linux kernel.

---

 doc/device-tree-bindings/clock/ti,dpll.txt |  85 +++++++
 drivers/clk/Kconfig                        |   7 +
 drivers/clk/Makefile                       |   1 +
 drivers/clk/clk-ti-am3-dpll-x2.c           |  78 ++++++
 drivers/clk/clk-ti-am3-dpll.c              | 267 +++++++++++++++++++++
 5 files changed, 438 insertions(+)
 create mode 100644 doc/device-tree-bindings/clock/ti,dpll.txt
 create mode 100644 drivers/clk/clk-ti-am3-dpll-x2.c
 create mode 100644 drivers/clk/clk-ti-am3-dpll.c
doc/device-tree-bindings/clock/ti,dpll.txt new file +85 -0
new file mode 100644
index 0000000000..a807b09241
@@ -0,0 +1,85 @@
+Binding for Texas Instruments DPLL 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 DPLL with usually two selectable input clocks
+(reference clock and bypass clock), with digital phase locked
+loop logic for multiplying the input clock to a desired output
+clock. This clock also typically supports different operation
+modes (locked, low power stop etc.) This binding has several
+sub-types, which effectively result in slightly different setup
+for the actual DPLL clock.
+
+[1] doc/device-tree-bindings/clock/clock-bindings.txt
+
+Required properties:
+- compatible : shall be one of:
+		"ti,omap3-dpll-clock",
+		"ti,omap3-dpll-core-clock",
+		"ti,omap3-dpll-per-clock",
+		"ti,omap3-dpll-per-j-type-clock",
+		"ti,omap4-dpll-clock",
+		"ti,omap4-dpll-x2-clock",
+		"ti,omap4-dpll-core-clock",
+		"ti,omap4-dpll-m4xen-clock",
+		"ti,omap4-dpll-j-type-clock",
+		"ti,omap5-mpu-dpll-clock",
+		"ti,am3-dpll-no-gate-clock",
+		"ti,am3-dpll-j-type-clock",
+		"ti,am3-dpll-no-gate-j-type-clock",
+		"ti,am3-dpll-clock",
+		"ti,am3-dpll-core-clock",
+		"ti,am3-dpll-x2-clock",
+		"ti,omap2-dpll-core-clock",
+
+- #clock-cells : from common clock binding; shall be set to 0.
+- clocks : link phandles of parent clocks, first entry lists reference clock
+  and second entry bypass clock
+- reg : offsets for the register set for controlling the DPLL.
+  Registers are listed in following order:
+	"control" - contains the control register base address
+	"idlest" - contains the idle status register base address
+	"mult-div1" - contains the multiplier / divider register base address
+	"autoidle" - contains the autoidle register base address (optional)
+  ti,am3-* dpll types do not have autoidle register
+  ti,omap2-* dpll type does not support idlest / autoidle registers
+
+Optional properties:
+- DPLL mode setting - defining any one or more of the following overrides
+  default setting.
+	- ti,low-power-stop : DPLL supports low power stop mode, gating output
+	- ti,low-power-bypass : DPLL output matches rate of parent bypass clock
+	- ti,lock : DPLL locks in programmed rate
+
+Examples:
+	dpll_core_ck: dpll_core_ck at 44e00490 {
+		#clock-cells = <0>;
+		compatible = "ti,omap4-dpll-core-clock";
+		clocks = <&sys_clkin_ck>, <&sys_clkin_ck>;
+		reg = <0x490>, <0x45c>, <0x488>, <0x468>;
+	};
+
+	dpll2_ck: dpll2_ck at 48004004 {
+		#clock-cells = <0>;
+		compatible = "ti,omap3-dpll-clock";
+		clocks = <&sys_ck>, <&dpll2_fck>;
+		ti,low-power-stop;
+		ti,low-power-bypass;
+		ti,lock;
+		reg = <0x4>, <0x24>, <0x34>, <0x40>;
+	};
+
+	dpll_core_ck: dpll_core_ck at 44e00490 {
+		#clock-cells = <0>;
+		compatible = "ti,am3-dpll-core-clock";
+		clocks = <&sys_clkin_ck>, <&sys_clkin_ck>;
+		reg = <0x90>, <0x5c>, <0x68>;
+	};
+
+	dpll_ck: dpll_ck {
+		#clock-cells = <0>;
+		compatible = "ti,omap2-dpll-core-clock";
+		clocks = <&sys_ck>, <&sys_ck>;
+		reg = <0x0500>, <0x0540>;
+	};
drivers/clk/Kconfig +7 -0
index f070d2637f..bddb454b7c 100644
@@ -98,6 +98,13 @@ 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_MUX
 	bool "TI mux clock driver"
 	depends on CLK && OF_CONTROL && CLK_CCF
drivers/clk/Makefile +1 -0
index c0dfe4b599..cc20279a20 100644
@@ -46,6 +46,7 @@ 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_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-am3-dpll-x2.c new file +78 -0

78 lines not on this page · raw message

drivers/clk/clk-ti-am3-dpll.c new file +267 -0

267 lines not on this page · raw message

Signature · 1 line
2.17.1
#15 lore raw

PATCH 8/31 clk: ti: add divider clock driver

In reply to Dario Binacchi

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.

---

 .../clock/ti,autoidle.txt                     |  39 ++
 doc/device-tree-bindings/clock/ti,divider.txt | 117 +++++
 drivers/clk/Kconfig                           |   6 +
 drivers/clk/Makefile                          |   1 +
 drivers/clk/clk-ti-divider.c                  | 403 ++++++++++++++++++
 5 files changed, 566 insertions(+)
 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
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 +1 -0
index cc20279a20..0fcfcc1837 100644
@@ -47,6 +47,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 +403 -0

403 lines not on this page · raw message

Signature · 1 line
2.17.1
#16 lore raw

PATCH 9/31 clk: ti: refactor mux and divider clock drivers

In reply to Dario Binacchi

The patch removes duplicate routines used by the two drivers.

---

 drivers/clk/Makefile         |  1 +
 drivers/clk/clk-ti-divider.c | 27 ++-------------------------
 drivers/clk/clk-ti-mux.c     | 27 ++-------------------------
 drivers/clk/clk-ti.c         | 34 ++++++++++++++++++++++++++++++++++
 drivers/clk/clk-ti.h         | 13 +++++++++++++
 5 files changed, 52 insertions(+), 50 deletions(-)
 create mode 100644 drivers/clk/clk-ti.c
 create mode 100644 drivers/clk/clk-ti.h
drivers/clk/Makefile +1 -0
index 0fcfcc1837..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/
drivers/clk/clk-ti-divider.c +2 -25
index fa9d60a2d5..d16cc30cb7 100644
@@ -16,6 +16,7 @@
 #include <linux/clk-provider.h>
 #include <linux/kernel.h>
 #include <linux/log2.h>
+#include "clk-ti.h"
 
 /*
  * The reverse of DIV_ROUND_UP: The maximum number which
@@ -36,30 +37,6 @@ struct clk_ti_divider_priv {
 	u16 mask;
 };
 
-static void clk_ti_divider_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_divider_latch(fdt_addr_t reg, s8 shift)
-{
-	u32 latch;
-
-	if (shift < 0)
-		return;
-
-	latch = 1 << shift;
-
-	clk_ti_divider_rmw(latch, latch, reg);
-	clk_ti_divider_rmw(0, latch, reg);
-	readl(reg);		/* OCP barrier */
-}
-
 static unsigned int _get_div(const struct clk_div_table *table, ulong flags,
 			     unsigned int val)
 {
@@ -226,7 +203,7 @@ static ulong clk_ti_divider_set_rate(struct clk *clk, ulong rate)
 	v &= ~(priv->mask << priv->shift);
 	v |= val << priv->shift;
 	writel(v, priv->reg);
-	clk_ti_divider_latch(priv->reg, priv->latch);
+	clk_ti_latch(priv->reg, priv->latch);
 
 	return clk_get_rate(clk);
 }
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
#17 lore raw

PATCH 9/31 clk: ti: refactor mux and divider clock drivers

Quoted 3 lines · Dario Binacchi

The patch removes duplicate routines used by the two drivers.

Please squash it into previous patches.

Thanks and regards,
Lokesh

Quoted 187 lines

---

 drivers/clk/Makefile         |  1 +
 drivers/clk/clk-ti-divider.c | 27 ++-------------------------
 drivers/clk/clk-ti-mux.c     | 27 ++-------------------------
 drivers/clk/clk-ti.c         | 34 ++++++++++++++++++++++++++++++++++
 drivers/clk/clk-ti.h         | 13 +++++++++++++
 5 files changed, 52 insertions(+), 50 deletions(-)
 create mode 100644 drivers/clk/clk-ti.c
 create mode 100644 drivers/clk/clk-ti.h
drivers/clk/Makefile +1 -0
index 0fcfcc1837..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/
drivers/clk/clk-ti-divider.c +2 -25
index fa9d60a2d5..d16cc30cb7 100644
@@ -16,6 +16,7 @@
 #include <linux/clk-provider.h>
 #include <linux/kernel.h>
 #include <linux/log2.h>
+#include "clk-ti.h"
 
 /*
  * The reverse of DIV_ROUND_UP: The maximum number which
@@ -36,30 +37,6 @@ struct clk_ti_divider_priv {
 	u16 mask;
 };
 
-static void clk_ti_divider_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_divider_latch(fdt_addr_t reg, s8 shift)
-{
-	u32 latch;
-
-	if (shift < 0)
-		return;
-
-	latch = 1 << shift;
-
-	clk_ti_divider_rmw(latch, latch, reg);
-	clk_ti_divider_rmw(0, latch, reg);
-	readl(reg);		/* OCP barrier */
-}
-
 static unsigned int _get_div(const struct clk_div_table *table, ulong flags,
 			     unsigned int val)
 {
@@ -226,7 +203,7 @@ static ulong clk_ti_divider_set_rate(struct clk *clk, ulong rate)
 	v &= ~(priv->mask << priv->shift);
 	v |= val << priv->shift;
 	writel(v, priv->reg);
-	clk_ti_divider_latch(priv->reg, priv->latch);
+	clk_ti_latch(priv->reg, priv->latch);
 
 	return clk_get_rate(clk);
 }
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 */
#18 lore raw

PATCH 10/31 clk: ti: add gate clock driver

In reply to Dario Binacchi

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.

---

 .../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
#19 lore raw

PATCH 11/31 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.

---

 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
#20 lore raw

PATCH 11/31 ti: am33xx: fix do_enable_clocks() to accept NULL parameters

Quoted 10 lines · 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.

---

 arch/arm/mach-omap2/am33xx/clock.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
#21 lore raw

PATCH 12/31 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.

---

 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
#22 lore raw

PATCH 13/31 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.

---

 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 d16cc30cb7..65b6abd18b 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
#23 lore raw

PATCH 14/31 clk: ti: omap4: add clock manager driver

In reply to Dario Binacchi

This minimal driver is only used to bind child devices.

---

 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
#24 lore raw

PATCH 15/31 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.

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>;
	};
	...
};

---

 drivers/clk/ti/Makefile   |  8 ++++-
 drivers/clk/ti/am3-prcm.c | 73 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 80 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 +73 -0

73 lines not on this page · raw message

Signature · 1 line
2.17.1
#25 lore raw

PATCH 16/31 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 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.

---

 arch/sandbox/dts/test.dts | 21 +++++++++++
 common/fdt_support.c      | 10 ++++--
 drivers/core/Kconfig      | 12 +++++++
 drivers/core/fdtaddr.c    |  2 +-
 drivers/core/of_addr.c    | 14 +++-----
 drivers/core/ofnode.c     | 11 ++++--
 test/dm/test-fdt.c        | 73 +++++++++++++++++++++++++++++++++++++--
 7 files changed, 127 insertions(+), 16 deletions(-)
arch/sandbox/dts/test.dts +21 -0
index 1d8956abbe..7f5d8f3aeb 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;
@@ -977,6 +978,7 @@
 			  1 0x100 0x9000 0x1000
 			  2 0x200 0xA000 0x1000
 			  3 0x300 0xB000 0x1000
+			  4 0x400 0xC000 0x1000
 			 >;
 
 		dma-ranges = <0 0x000 0x10000000 0x1000
@@ -1013,6 +1015,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 +8 -2
index a565b470f8..402401e073 100644
@@ -1001,8 +1001,14 @@ 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_ADDR_COUNT(na) ((na) > 0 && (na) <= OF_MAX_ADDR_CELLS)
+#if defined(CONFIG_OF_TRANSLATE_ZERO_SIZE_CELLS)
+#define OF_CHECK_SIZE_COUNT(ns) ((ns) >= 0)
+#else
+#define OF_CHECK_SIZE_COUNT(ns) ((ns) > 0)
+#endif
+#define OF_CHECK_COUNTS(na, ns) (OF_CHECK_ADDR_COUNT(na) && \
+				 OF_CHECK_SIZE_COUNT(ns))
 
 /* 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..5a9f08aa44 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 (IS_ENABLED(CONFIG_OF_TRANSLATE_ZERO_SIZE_CELLS) || ns) {
 			/*
 			 * Use the full-fledged translate function for complex
 			 * bus setups.
drivers/core/of_addr.c +5 -9
index ca34d84922..ddac5f9a2b 100644
@@ -18,7 +18,11 @@
 /* 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)
+#if defined(CONFIG_OF_TRANSLATE_ZERO_SIZE_CELLS)
+#define OF_CHECK_COUNTS(na, ns)	(OF_CHECK_ADDR_COUNT(na) && (ns) >= 0)
+#else
 #define OF_CHECK_COUNTS(na, ns)	(OF_CHECK_ADDR_COUNT(na) && (ns) > 0)
+#endif
 
 static struct of_bus *of_match_bus(struct device_node *np);
 
@@ -162,11 +166,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 +192,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 +9 -2
index d02d8d33fe..b5744e86c3 100644
@@ -304,7 +304,10 @@ 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 ||
+		     (IS_ENABLED(CONFIG_OF_TRANSLATE_ZERO_SIZE_CELLS) &&
+		      ns >= 0))) {
 			return of_translate_address(ofnode_to_np(node), prop_val);
 		} else {
 			na = of_n_addr_cells(ofnode_to_np(node));
@@ -655,8 +658,12 @@ 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 ||
+		     (IS_ENABLED(CONFIG_OF_TRANSLATE_ZERO_SIZE_CELLS) &&
+		      ns >= 0))) {
 			return of_translate_address(np, prop);
+		}
 		else
 			return of_read_number(prop, na);
 	} else {
test/dm/test-fdt.c +71 -2

87 lines not on this page · raw message

Signature · 1 line
2.17.1
#26 lore raw

PATCH 16/31 fdt: translate address if #size-cells = <0>

Hi Dario,

Quoted 4 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

there is something missing here. Do you have a # at the start of the line?

Quoted 151 lines

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.

---

 arch/sandbox/dts/test.dts | 21 +++++++++++
 common/fdt_support.c      | 10 ++++--
 drivers/core/Kconfig      | 12 +++++++
 drivers/core/fdtaddr.c    |  2 +-
 drivers/core/of_addr.c    | 14 +++-----
 drivers/core/ofnode.c     | 11 ++++--
 test/dm/test-fdt.c        | 73 +++++++++++++++++++++++++++++++++++++--
 7 files changed, 127 insertions(+), 16 deletions(-)
arch/sandbox/dts/test.dts +21 -0
index 1d8956abbe..7f5d8f3aeb 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;
@@ -977,6 +978,7 @@
                          1 0x100 0x9000 0x1000
                          2 0x200 0xA000 0x1000
                          3 0x300 0xB000 0x1000
+                         4 0x400 0xC000 0x1000
                         >;
 
                dma-ranges = <0 0x000 0x10000000 0x1000
@@ -1013,6 +1015,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 +8 -2
index a565b470f8..402401e073 100644
@@ -1001,8 +1001,14 @@ 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_ADDR_COUNT(na) ((na) > 0 && (na) <= OF_MAX_ADDR_CELLS)
+#if defined(CONFIG_OF_TRANSLATE_ZERO_SIZE_CELLS)
+#define OF_CHECK_SIZE_COUNT(ns) ((ns) >= 0)
+#else
+#define OF_CHECK_SIZE_COUNT(ns) ((ns) > 0)
+#endif
+#define OF_CHECK_COUNTS(na, ns) (OF_CHECK_ADDR_COUNT(na) && \
+                                OF_CHECK_SIZE_COUNT(ns))
 
 /* 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 +0 -0
index 8b48aa5bc5..5a9f08aa44 100644

drivers/core/fdtaddr.c fdt_addr_t devfdt_get_addr_index(const struct udevice *dev, int index) · line 52

Quoted 5 lines
drivers/core/fdtaddr.c +1 -1
@@ -49,7 +49,7 @@ fdt_addr_t devfdt_get_addr_index(const struct udevice *dev, int index)
 
                reg += index * (na + ns);
 
-               if (ns) {
+               if (IS_ENABLED(CONFIG_OF_TRANSLATE_ZERO_SIZE_CELLS) || ns) {

Here we should check a flag, perhaps in a new gd->dm_flags value, to determine the behaviour. The problem with using a CONFIG here is that you cannot test it without recompiling. Also the code-size difference is negligible.

So you can use the CONFIG to set the flag, perhaps in dm_init(), and add a helper to change the setting, which can be used in tests.

Quoted 8 lines
drivers/core/fdtaddr.c +0 -0
                        /*
                         * Use the full-fledged translate function for complex
                         * bus setups.
drivers/core/of_addr.c +0 -0
index ca34d84922..ddac5f9a2b 100644

drivers/core/of_addr.c line 24

Quoted 7 lines
drivers/core/of_addr.c +3 -0
@@ -18,7 +18,11 @@
 /* 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)
+#if defined(CONFIG_OF_TRANSLATE_ZERO_SIZE_CELLS)
+#define OF_CHECK_COUNTS(na, ns)        (OF_CHECK_ADDR_COUNT(na) && (ns) >= 0)
+#else
 #define OF_CHECK_COUNTS(na, ns)        (OF_CHECK_ADDR_COUNT(na) && (ns) > 0)

This could be changed to have just one #define by bringing the CONFIG into the expression.

Quoted 129 lines
drivers/core/of_addr.c +2 -9
+#endif
 
 static struct of_bus *of_match_bus(struct device_node *np);
 
@@ -162,11 +166,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 +192,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 +9 -2
index d02d8d33fe..b5744e86c3 100644
@@ -304,7 +304,10 @@ 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 ||
+                    (IS_ENABLED(CONFIG_OF_TRANSLATE_ZERO_SIZE_CELLS) &&
+                     ns >= 0))) {
                        return of_translate_address(ofnode_to_np(node), prop_val);
                } else {
                        na = of_n_addr_cells(ofnode_to_np(node));
@@ -655,8 +658,12 @@ 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 ||
+                    (IS_ENABLED(CONFIG_OF_TRANSLATE_ZERO_SIZE_CELLS) &&
+                     ns >= 0))) {
                        return of_translate_address(np, prop);
+               }
                else
                        return of_read_number(prop, na);
        } else {
test/dm/test-fdt.c +58 -0
index 04802deb7f..30a7a933dd 100644
@@ -581,6 +581,64 @@ U_BOOT_DRIVER(fdt_dummy_drv) = {
        .id     = UCLASS_TEST_DUMMY,
 };
 
+static int zero_size_cells_bus_bind(struct udevice *dev)
+{
+       ofnode child;
+       int err;
+
+       ofnode_for_each_subnode(child, dev_ofnode(dev)) {
+               if (ofnode_get_property(child, "compatible", NULL))
+                       continue;
+
+               err = device_bind_driver_to_node(dev,
+                                                "zero_size_cells_bus_child_drv",
+                                                "zero_size_cells_bus_child",
+                                                child, NULL);
+               if (err) {
+                       dev_err(dev, "%s: failed to bind %s\n", __func__,
+                               ofnode_get_name(child));
+                       return err;
+               }
+       }
+
+       return 0;
+}
+
+static const struct udevice_id zero_size_cells_bus_ids[] = {
+       { .compatible = "sandbox,zero-size-cells-bus" },
+       { }
+};
+
+U_BOOT_DRIVER(zero_size_cells_bus) = {
+       .name = "zero_size_cells_bus_drv",
+       .id = UCLASS_TEST_DUMMY,
+       .of_match = zero_size_cells_bus_ids,
+       .bind = zero_size_cells_bus_bind,
+};
+
+static int zero_size_cells_bus_child_bind(struct udevice *dev)
+{
+       ofnode child;
+       int err;
+
+       ofnode_for_each_subnode(child, dev_ofnode(dev)) {
+               err = lists_bind_fdt(dev, child, NULL, false);
+               if (err) {
+                       dev_err(dev, "%s: lists_bind_fdt, err=%d\n",
+                               __func__, err);
+                       return err;
+               }
+       }
+
+       return 0;
+}
+
+U_BOOT_DRIVER(zero_size_cells_bus_child_drv) = {
+       .name = "zero_size_cells_bus_child_drv",
+       .id = UCLASS_TEST_DUMMY,
+       .bind = zero_size_cells_bus_child_bind,
+};
+
 static int dm_test_fdt_translation(struct unit_test_state *uts)
 {
        struct udevice *dev;

test/dm/test-fdt.c static int dm_test_fdt_translation(struct unit_test_state *uts) · line 663

Quoted 9 lines
test/dm/test-fdt.c +2 -2
@@ -599,10 +657,21 @@ static int dm_test_fdt_translation(struct unit_test_state *uts)
        ut_asserteq_str("dev at 2,200", dev->name);
        ut_asserteq(0xA000, dev_read_addr(dev));
 
-       /* No translation for busses with #size-cells == 0 */
        ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 3, true, &dev));
        ut_asserteq_str("dev at 42", dev->name);
-       ut_asserteq(0x42, dev_read_addr(dev));
+
+       if (!IS_ENABLED(CONFIG_OF_TRANSLATE_ZERO_SIZE_CELLS)) {

Here, adjust the flag so you can run both tests one after the other.

test/dm/test-fdt.c static int dm_test_fdt_translation(struct unit_test_state *uts) · line 673

Quoted 10 lines
test/dm/test-fdt.c +10 -0
+               /* No translation for busses with #size-cells == 0 */
+               ut_asserteq(0x42, dev_read_addr(dev));
+       } else {
+               /* Translation for busses with #size-cells == 0 */
+               ut_asserteq(0x8042, dev_read_addr(dev));
+
+               ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 4, true,
+                                                     &dev));
+               ut_asserteq_str("dev at 19", dev->name);
+               ut_asserteq(0xC019, dev_read_addr(dev));

lower-case hex please

Quoted 7 lines
test/dm/test-fdt.c +1 -1
+       }
 
        /* dma address translation */
        ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev));
--

2.17.1

Regards,
Simon

#27 lore raw

PATCH 17/31 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.

---

 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
#28 lore raw

PATCH 18/31 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.

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>;
		};
	};
};

---

 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                     |  90 +++++++
 5 files changed, 435 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 +90 -0

90 lines not on this page · raw message

Signature · 1 line
2.17.1
#29 lore raw

PATCH 18/31 misc: am33xx: add control module driver

Quoted 25 lines · 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.

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>;
		};
	};
};
Quoted 5 lines

---

 doc/device-tree-bindings/arm/omap,ctrl.txt    |  82 ++++++
 .../pinctrl/pinctrl-single.txt                | 255 ++++++++++++++++++

This documentation does not belong to this patch.

Quoted 96 lines
 drivers/misc/Kconfig                          |   7 +
 drivers/misc/Makefile                         |   1 +
 drivers/misc/ti-am3-scm.c                     |  90 +++++++
 5 files changed, 435 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>;
+	};
+};

[...snip...]

Quoted 65 lines
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 +34 -0
new file mode 100644
index 0000000000..e5f4f09261
@@ -0,0 +1,90 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * AM335x specific control module (scm)
+ *
+ * Copyright (C) 2020 Dario Binacchi <[email protected]>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <dm/lists.h>
+#include <linux/err.h>
+
+static int ti_am3_scm_bind(struct udevice *dev)
+{
+	int err;
+	struct udevice *conf_dev;
+	ofnode clocks_node, conf_node;
+
+	err = dm_scan_fdt_dev(dev);
+	if (err) {
+		dev_err(dev, "%s: dm_scan_fdt, err=%d\n", __func__, err);
+		return err;
+	}
+
+	conf_node = dev_read_subnode(dev, "scm_conf at 0");
+	if (!ofnode_valid(conf_node)) {
+		dev_err(dev, "%s: failed to get conf sub-node\n", __func__);
+		return -ENODEV;
+	}
+
+	if (uclass_get_device_by_ofnode(UCLASS_SYSCON, conf_node, &conf_dev)) {
+		if (uclass_get_device_by_ofnode(UCLASS_SIMPLE_BUS, conf_node,
+						&conf_dev)) {
+			dev_err(dev, "%s: failed to get conf device\n",

drivers/misc/ti-am3-scm.c line 44

Quoted 10 lines
drivers/misc/ti-am3-scm.c new file +10 -0
+				__func__);
+			return -ENODEV;
+		}
+	}
+
+	clocks_node = dev_read_subnode(conf_dev, "clocks");
+	if (!ofnode_valid(clocks_node)) {
+		dev_err(dev, "%s: failed to get clocks sub-node\n", __func__);
+		return -ENODEV;
+	}

Isn't clock node an optional property?

Also do we really need a separate UBOOT_DRIVER for scm_clocks? Can it be handled in the same driver?

Thanks and regards,
Lokesh

Quoted 47 lines
drivers/misc/ti-am3-scm.c new file +46 -0
+
+	err = device_bind_driver_to_node(conf_dev, "ti_am3_scm_clocks",
+					 "scm_clocks", clocks_node, NULL);
+	if (err) {
+		dev_err(dev, "%s: failed to bind scm_clocks\n", __func__);
+		return err;
+	}
+
+	return 0;
+}
+
+static const struct udevice_id ti_am3_scm_ids[] = {
+	{.compatible = "ti,am3-scm"},
+	{}
+};
+
+U_BOOT_DRIVER(ti_am3_scm) = {
+	.name = "ti_am3_scm",
+	.id = UCLASS_SIMPLE_BUS,
+	.of_match = ti_am3_scm_ids,
+	.bind = ti_am3_scm_bind,
+};
+
+static int ti_am3_scm_clocks_bind(struct udevice *dev)
+{
+	ofnode node;
+	int err;
+
+	dev_dbg(dev, "%s: dev=%p\n", __func__, dev);
+	ofnode_for_each_subnode(node, dev_ofnode(dev)) {
+		err = lists_bind_fdt(dev, node, NULL, false);
+		if (err) {
+			dev_err(dev, "%s: lists_bind_fdt, err=%d\n",
+				__func__, err);
+			return err;
+		}
+	}
+
+	return 0;
+}
+
+U_BOOT_DRIVER(ti_am3_scm_clocks) = {
+	.name = "ti_am3_scm_clocks",
+	.id = UCLASS_SIMPLE_BUS,
+	.bind = ti_am3_scm_clocks_bind,
+};
#30 lore raw

PATCH 18/31 misc: am33xx: add control module driver

Hi Lokesh,

Quoted 29 lines

Il 03/09/2020 08:31 Lokesh Vutla <[email protected]> ha scritto:

Quoted 25 lines · 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.

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>;
		};
	};
};
Quoted 7 lines
Quoted 5 lines

---

 doc/device-tree-bindings/arm/omap,ctrl.txt    |  82 ++++++
 .../pinctrl/pinctrl-single.txt                | 255 ++++++++++++++++++

This documentation does not belong to this patch.

The omap,ctrl.txt file references to the pinctrl-single.txt document. I thought it was better to add it rather than remove that reference from the omap,ctrl.txt file.

Quoted 179 lines
Quoted 97 lines
 drivers/misc/Kconfig                          |   7 +
 drivers/misc/Makefile                         |   1 +
 drivers/misc/ti-am3-scm.c                     |  90 +++++++
 5 files changed, 435 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>;
+	};
+};

[...snip...]

Quoted 65 lines
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 +34 -0
new file mode 100644
index 0000000000..e5f4f09261
@@ -0,0 +1,90 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * AM335x specific control module (scm)
+ *
+ * Copyright (C) 2020 Dario Binacchi <[email protected]>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <dm/lists.h>
+#include <linux/err.h>
+
+static int ti_am3_scm_bind(struct udevice *dev)
+{
+	int err;
+	struct udevice *conf_dev;
+	ofnode clocks_node, conf_node;
+
+	err = dm_scan_fdt_dev(dev);
+	if (err) {
+		dev_err(dev, "%s: dm_scan_fdt, err=%d\n", __func__, err);
+		return err;
+	}
+
+	conf_node = dev_read_subnode(dev, "scm_conf at 0");
+	if (!ofnode_valid(conf_node)) {
+		dev_err(dev, "%s: failed to get conf sub-node\n", __func__);
+		return -ENODEV;
+	}
+
+	if (uclass_get_device_by_ofnode(UCLASS_SYSCON, conf_node, &conf_dev)) {
+		if (uclass_get_device_by_ofnode(UCLASS_SIMPLE_BUS, conf_node,
+						&conf_dev)) {
+			dev_err(dev, "%s: failed to get conf device\n",

drivers/misc/ti-am3-scm.c line 44

Quoted 10 lines
drivers/misc/ti-am3-scm.c new file +10 -0
+				__func__);
+			return -ENODEV;
+		}
+	}
+
+	clocks_node = dev_read_subnode(conf_dev, "clocks");
+	if (!ofnode_valid(clocks_node)) {
+		dev_err(dev, "%s: failed to get clocks sub-node\n", __func__);
+		return -ENODEV;
+	}

Isn't clock node an optional property?

Quoted 3 lines

Also do we really need a separate UBOOT_DRIVER for scm_clocks? Can it be handled in the same driver?

In the next version of the series, scm_clocks will be handled by the same driver.

Regards,
Dario

Quoted 50 lines

Thanks and regards,
Lokesh

Quoted 47 lines
drivers/misc/ti-am3-scm.c new file +46 -0
+
+	err = device_bind_driver_to_node(conf_dev, "ti_am3_scm_clocks",
+					 "scm_clocks", clocks_node, NULL);
+	if (err) {
+		dev_err(dev, "%s: failed to bind scm_clocks\n", __func__);
+		return err;
+	}
+
+	return 0;
+}
+
+static const struct udevice_id ti_am3_scm_ids[] = {
+	{.compatible = "ti,am3-scm"},
+	{}
+};
+
+U_BOOT_DRIVER(ti_am3_scm) = {
+	.name = "ti_am3_scm",
+	.id = UCLASS_SIMPLE_BUS,
+	.of_match = ti_am3_scm_ids,
+	.bind = ti_am3_scm_bind,
+};
+
+static int ti_am3_scm_clocks_bind(struct udevice *dev)
+{
+	ofnode node;
+	int err;
+
+	dev_dbg(dev, "%s: dev=%p\n", __func__, dev);
+	ofnode_for_each_subnode(node, dev_ofnode(dev)) {
+		err = lists_bind_fdt(dev, node, NULL, false);
+		if (err) {
+			dev_err(dev, "%s: lists_bind_fdt, err=%d\n",
+				__func__, err);
+			return err;
+		}
+	}
+
+	return 0;
+}
+
+U_BOOT_DRIVER(ti_am3_scm_clocks) = {
+	.name = "ti_am3_scm_clocks",
+	.id = UCLASS_SIMPLE_BUS,
+	.bind = ti_am3_scm_clocks_bind,
+};
#31 lore raw

PATCH 19/31 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.

---

 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
#32 lore raw

PATCH 20/31 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.

---

 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
#33 lore raw

PATCH 21/31 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.

---

 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
#34 lore raw

PATCH 21/31 video: backlight: fix pwm's duty cycle calculation

Quoted 11 lines · Dario Binacchi

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

---

 drivers/video/pwm_backlight.c |  2 +-
 test/dm/panel.c               | 12 ++++++------
 2 files changed, 7 insertions(+), 7 deletions(-)
#35 lore raw

PATCH 22/31 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.

---

 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
#36 lore raw

PATCH 23/31 dm: core: improve uclass_get_device_by_phandle_id() description

In reply to Dario Binacchi

Complete the devp parameter description.

---

 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
#38 lore raw

PATCH 24/31 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.

---

 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
#40 lore raw

PATCH 25/31 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.

---

 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 7f5d8f3aeb..dcf1a94b82 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 8bb456bc3f..27715942d0 100644
@@ -359,3 +359,9 @@ int dev_get_child_count(const struct udevice *dev)
 {
 	return ofnode_get_child_count(dev_ofnode(dev));
 }
+
+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 0a7aacd2d0..7c15d51cf2 100644
@@ -680,6 +680,23 @@ int dev_read_alias_highest_id(const char *stem);
  */
 int dev_get_child_count(const struct udevice *dev);
 
+/**
+ * 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,
@@ -1002,6 +1019,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
#41 lore raw

PATCH 25/31 dm: core: add a function to decode display timings

Quoted 4 lines · Dario Binacchi

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

Quoted 8 lines

---

 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(+)
#42 lore raw

PATCH 26/31 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.

---

 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