Skip to contentSkip to conversation

sunxi: DM-based CLK, RESET and PINCTRL

PATCH Superseded Philipp Tomsich 2 participants 12 messages Mar 1, 2017 – Mar 6, 2017

Subsystems (8)
lore
Share & tools
lore
#0 lore raw

v3 cover sunxi: DM-based CLK, RESET and PINCTRL

Hi everyone,

here's the the new version of CLK, RESET and PINCTRL drivers to configure sunxi from the device-tree. This adds support for the upstream CCU node (for reset and pinctrl) and tries to address the various concerns people had.

Note that (to stay in sync with the Linux files), some of the patches may not fully adhere to the style (e.g. some of the code reused verbatim from Linux and in the config tables).

This has been tested with Ethernet, I2C, SPI and MMC on the A64-uQ7. See my separate patchsets for the conversion of these drivers over to support DM-based CLK, RESET and PINCTRL configuration.

Changes is v3:
* add support for the 'new-style' clock subsystem (CCU) by porting from Linux and adding the necessary glue implementation
- add a CCU reset-driver (in addition to the legacy driver, which will still be required for the R_* device nodes), which reuses the reset-table from ccu-<SOC>.c
- add a clk-sunxi-ccu.c implementation based on Linux and reusing both the low-level clock implementation (ccu_*.h) and the config table (ccu-<SOC>.c) from Linux
* reuse the 'allwinner,pinctrl.txt' documentation for the pinctrl binding from Linux
* adds the includes for the CCU dt-bindings from Linux
* adds support for printing the CCU subsystem via 'clk dump'

Philipp Tomsich (9):
sunxi: add pinctrl (UCLASS_PINCTRL) support for sunxi
dm: core: Allow multiple drivers to bind for a single node
sunxi: CONFIG_DM_ALLOW_MULTIPLE_DRIVERS for gpio/pinctrl binding
Kconfig: sunxi: Select new option for allow multiple drivers to bind
sunxi: add module reset (UCLASS_RESET) support for sunxi linux/kernel.h: sync DIV_ROUND_UP_ULL from kernel
clk: clk-uclass: add clk_get_by_output_name
sunxi: add clock driver (UCLASS_CLK) support for sunxi
cmd: move CONFIG_CMD_CLK to Kconfig

 arch/arm/Kconfig                                   |   1 +
 arch/arm/include/asm/arch-sunxi/gpio-internal.h    |  19 +
 cmd/Kconfig                                        |  10 +
 .../pinctrl/allwinner,pinctrl.txt                  | 142 ++++
 drivers/clk/Makefile                               |   1 +
 drivers/clk/clk-uclass.c                           |  30 +
 drivers/clk/sunxi/Makefile                         |  30 +
 drivers/clk/sunxi/ccu-compatibility.h              | 232 ++++++
 drivers/clk/sunxi/ccu-runtime-divider.c            | 115 +++
 drivers/clk/sunxi/ccu-runtime-fixedfactor.c        |  17 +
 drivers/clk/sunxi/ccu-sun50i-a64.c                 | 810 +++++++++++++++++++++
 drivers/clk/sunxi/ccu-sun50i-a64.h                 |  64 ++
 drivers/clk/sunxi/ccu_common.c                     |  27 +
 drivers/clk/sunxi/ccu_common.h                     |  67 ++
 drivers/clk/sunxi/ccu_div.c                        | 134 ++++
 drivers/clk/sunxi/ccu_div.h                        | 170 +++++
 drivers/clk/sunxi/ccu_frac.c                       | 106 +++
 drivers/clk/sunxi/ccu_frac.h                       |  46 ++
 drivers/clk/sunxi/ccu_gate.c                       |  80 ++
 drivers/clk/sunxi/ccu_gate.h                       |  45 ++
 drivers/clk/sunxi/ccu_mp.c                         | 159 ++++
 drivers/clk/sunxi/ccu_mp.h                         |  70 ++
 drivers/clk/sunxi/ccu_mult.h                       |  39 +
 drivers/clk/sunxi/ccu_mux.c                        | 201 +++++
 drivers/clk/sunxi/ccu_mux.h                        | 105 +++
 drivers/clk/sunxi/ccu_nk.c                         | 154 ++++
 drivers/clk/sunxi/ccu_nk.h                         |  64 ++
 drivers/clk/sunxi/ccu_nkm.c                        | 184 +++++
 drivers/clk/sunxi/ccu_nkm.h                        |  84 +++
 drivers/clk/sunxi/ccu_nkmp.c                       | 171 +++++
 drivers/clk/sunxi/ccu_nkmp.h                       |  64 ++
 drivers/clk/sunxi/ccu_nm.c                         | 148 ++++
 drivers/clk/sunxi/ccu_nm.h                         |  84 +++
 drivers/clk/sunxi/clk-sunxi-ccu.c                  | 550 ++++++++++++++
 drivers/clk/sunxi/clk-sunxi-gate.c                 |  92 +++
 drivers/clk/sunxi/clk-sunxi-mod.c                  | 241 ++++++
 drivers/core/Kconfig                               |  14 +
 drivers/core/lists.c                               |  12 +-
 drivers/gpio/sunxi_gpio.c                          |  15 +-
 drivers/pinctrl/Kconfig                            |  10 +
 drivers/pinctrl/Makefile                           |   2 +
 drivers/pinctrl/sunxi/Makefile                     |  10 +
 drivers/pinctrl/sunxi/pinctrl-sun50i-a64-r.c       |  92 +++
 drivers/pinctrl/sunxi/pinctrl-sun50i-a64.c         | 577 +++++++++++++++
 drivers/pinctrl/sunxi/pinctrl-sunxi.c              | 355 +++++++++
 drivers/pinctrl/sunxi/pinctrl-sunxi.h              | 311 ++++++++
 drivers/reset/Kconfig                              |   9 +
 drivers/reset/Makefile                             |   1 +
 drivers/reset/sunxi/Makefile                       |   6 +
 drivers/reset/sunxi/ccu-sun50i-a64.c               |  75 ++
 drivers/reset/sunxi/ccu_reset.h                    |   9 +
 drivers/reset/sunxi/reset-sunxi.c                  | 168 +++++
 include/clk.h                                      |  22 +
 include/dt-bindings/clock/sun50i-a64-ccu.h         | 134 ++++
 include/dt-bindings/reset/sun50i-a64-ccu.h         |  98 +++
 include/linux/kernel.h                             |   2 +
 56 files changed, 6470 insertions(+), 8 deletions(-)
 create mode 100644 arch/arm/include/asm/arch-sunxi/gpio-internal.h
 create mode 100644 doc/device-tree-bindings/pinctrl/allwinner,pinctrl.txt
 create mode 100644 drivers/clk/sunxi/Makefile
 create mode 100644 drivers/clk/sunxi/ccu-compatibility.h
 create mode 100644 drivers/clk/sunxi/ccu-runtime-divider.c
 create mode 100644 drivers/clk/sunxi/ccu-runtime-fixedfactor.c
 create mode 100644 drivers/clk/sunxi/ccu-sun50i-a64.c
 create mode 100644 drivers/clk/sunxi/ccu-sun50i-a64.h
 create mode 100644 drivers/clk/sunxi/ccu_common.c
 create mode 100644 drivers/clk/sunxi/ccu_common.h
 create mode 100644 drivers/clk/sunxi/ccu_div.c
 create mode 100644 drivers/clk/sunxi/ccu_div.h
 create mode 100644 drivers/clk/sunxi/ccu_frac.c
 create mode 100644 drivers/clk/sunxi/ccu_frac.h
 create mode 100644 drivers/clk/sunxi/ccu_gate.c
 create mode 100644 drivers/clk/sunxi/ccu_gate.h
 create mode 100644 drivers/clk/sunxi/ccu_mp.c
 create mode 100644 drivers/clk/sunxi/ccu_mp.h
 create mode 100644 drivers/clk/sunxi/ccu_mult.h
 create mode 100644 drivers/clk/sunxi/ccu_mux.c
 create mode 100644 drivers/clk/sunxi/ccu_mux.h
 create mode 100644 drivers/clk/sunxi/ccu_nk.c
 create mode 100644 drivers/clk/sunxi/ccu_nk.h
 create mode 100644 drivers/clk/sunxi/ccu_nkm.c
 create mode 100644 drivers/clk/sunxi/ccu_nkm.h
 create mode 100644 drivers/clk/sunxi/ccu_nkmp.c
 create mode 100644 drivers/clk/sunxi/ccu_nkmp.h
 create mode 100644 drivers/clk/sunxi/ccu_nm.c
 create mode 100644 drivers/clk/sunxi/ccu_nm.h
 create mode 100644 drivers/clk/sunxi/clk-sunxi-ccu.c
 create mode 100644 drivers/clk/sunxi/clk-sunxi-gate.c
 create mode 100644 drivers/clk/sunxi/clk-sunxi-mod.c
 create mode 100644 drivers/pinctrl/sunxi/Makefile
 create mode 100644 drivers/pinctrl/sunxi/pinctrl-sun50i-a64-r.c
 create mode 100644 drivers/pinctrl/sunxi/pinctrl-sun50i-a64.c
 create mode 100644 drivers/pinctrl/sunxi/pinctrl-sunxi.c
 create mode 100644 drivers/pinctrl/sunxi/pinctrl-sunxi.h
 create mode 100644 drivers/reset/sunxi/Makefile
 create mode 100644 drivers/reset/sunxi/ccu-sun50i-a64.c
 create mode 100644 drivers/reset/sunxi/ccu_reset.h
 create mode 100644 drivers/reset/sunxi/reset-sunxi.c
 create mode 100644 include/dt-bindings/clock/sun50i-a64-ccu.h
 create mode 100644 include/dt-bindings/reset/sun50i-a64-ccu.h
Signature · 1 line
1.9.1
#1 lore raw

PATCH v3 1/9 sunxi: add pinctrl (UCLASS_PINCTRL) support for sunxi

This change adds a full device-model pinctrl driver for sunxi (tested with sun50iw1p1) based on the support available in Linux.

Details are:
* implements a driver for pinctrl devices and assigns sun50i-a64-pinctrl and sun50i-a64-r-pinctrl to it
* dynamically creates the driver_data for a sunxi_gpio (see sunxi_gpio.c) driver and binds it to the same device-tree node
* lifts and reuses the pinctrl-sunxi.h and pinctrl-sun50i-a64.c files from Linux (thanks to Maxime and Andre) and adds a pinctrl-sun50i-a64-r.c (to be picked up for inclusion into Linux again)

---
 arch/arm/include/asm/arch-sunxi/gpio-internal.h    |  19 +
 .../pinctrl/allwinner,pinctrl.txt                  | 142 +++++
 drivers/gpio/sunxi_gpio.c                          |  15 +-
 drivers/pinctrl/Kconfig                            |  10 +
 drivers/pinctrl/Makefile                           |   2 +
 drivers/pinctrl/sunxi/Makefile                     |  10 +
 drivers/pinctrl/sunxi/pinctrl-sun50i-a64-r.c       |  92 ++++
 drivers/pinctrl/sunxi/pinctrl-sun50i-a64.c         | 577 +++++++++++++++++++++
 drivers/pinctrl/sunxi/pinctrl-sunxi.c              | 351 +++++++++++++
 drivers/pinctrl/sunxi/pinctrl-sunxi.h              | 311 +++++++++++
 10 files changed, 1522 insertions(+), 7 deletions(-)
 create mode 100644 arch/arm/include/asm/arch-sunxi/gpio-internal.h
 create mode 100644 doc/device-tree-bindings/pinctrl/allwinner,pinctrl.txt
 create mode 100644 drivers/pinctrl/sunxi/Makefile
 create mode 100644 drivers/pinctrl/sunxi/pinctrl-sun50i-a64-r.c
 create mode 100644 drivers/pinctrl/sunxi/pinctrl-sun50i-a64.c
 create mode 100644 drivers/pinctrl/sunxi/pinctrl-sunxi.c
 create mode 100644 drivers/pinctrl/sunxi/pinctrl-sunxi.h
arch/arm/include/asm/arch-sunxi/gpio-internal.h new file +19 -0
new file mode 100644
index 0000000..4dcdd34
@@ -0,0 +1,19 @@
+/*
+ * (C) Copyright 2017 Theobroma Systems Design und Consulting GmbH
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+
+#ifndef _SUNXI_GPIO_INTERNAL_H
+#define _SUNXI_GPIO_INTERNAL_H
+
+/* This data structure is shared between the sunxi_gpio driver and
+ * the sunxi_pinctrl driver.
+ */
+struct sunxi_gpio_soc_data {
+	int start;
+	int no_banks;
+};
+
+#endif
doc/device-tree-bindings/pinctrl/allwinner,pinctrl.txt new file +142 -0

142 lines not on this page · raw message

drivers/gpio/sunxi_gpio.c +8 -7
index 2b7bc7f..fd0c1ac 100644
@@ -16,6 +16,7 @@
 #include <fdtdec.h>
 #include <malloc.h>
 #include <asm/arch/gpio.h>
+#include <asm/arch/gpio-internal.h>
 #include <asm/io.h>
 #include <asm/gpio.h>
 #include <dm/device-internal.h>
@@ -275,11 +276,6 @@ static int gpio_sunxi_probe(struct udevice *dev)
 	return 0;
 }
 
-struct sunxi_gpio_soc_data {
-	int start;
-	int no_banks;
-};
-
 /**
  * We have a top-level GPIO device with no actual GPIOs. It has a child
  * device for each Sunxi bank.
@@ -353,18 +349,22 @@ static const struct udevice_id sunxi_gpio_ids[] = {
 	ID("allwinner,sun8i-a83t-pinctrl",	a_all),
 	ID("allwinner,sun8i-h3-pinctrl",	a_all),
 	ID("allwinner,sun9i-a80-pinctrl",	a_all),
+#if !defined(CONFIG_SUNXI_PINCTRL)
 	/* This is not strictly correct for the A64, as it is missing
 	 * bank 'A'. Yet, the register layout in the pinctrl block is
 	 * backward compatible and any accesses to the registers that
 	 * normally control bank 'A' will have no adverse effect.
 	 */
-	ID("allwinner,sun50i-a64-pinctrl",      a_all),
+	ID("allwinner,sun50i-a64-pinctrl",	a_all),
+#endif
 	ID("allwinner,sun6i-a31-r-pinctrl",	l_2),
 	ID("allwinner,sun8i-a23-r-pinctrl",	l_1),
 	ID("allwinner,sun8i-a83t-r-pinctrl",	l_1),
 	ID("allwinner,sun8i-h3-r-pinctrl",	l_1),
 	ID("allwinner,sun9i-a80-r-pinctrl",	l_3),
-	ID("allwinner,sun50i-a64-r-pinctrl",    l_1),
+#if !defined(CONFIG_SUNXI_PINCTRL)
+	ID("allwinner,sun50i-a64-r-pinctrl",	l_1),
+#endif
 	{ }
 };
 
@@ -376,4 +376,5 @@ U_BOOT_DRIVER(gpio_sunxi) = {
 	.bind	= gpio_sunxi_bind,
 	.probe	= gpio_sunxi_probe,
 };
+
 #endif
drivers/pinctrl/Kconfig +10 -0
index efcb4c0..064a682 100644
@@ -175,6 +175,16 @@ config PIC32_PINCTRL
 	  by a device tree node which contains both GPIO defintion and pin control
 	  functions.
 
+config SUNXI_PINCTRL
+        bool "Allwinner Axx pin-control and pin-mux driver"
+	depends on DM && ARCH_SUNXI
+	default y
+	help
+	  Supports pin multiplexing control, drive-strength and bias control on
+	  Allwinner Axx SoCs. The driver is controlled by a device tree node which
+	  contains both the GPIO definitions and the pin control functions for
+	  each multiplex function.
+
 endif
 
 source "drivers/pinctrl/meson/Kconfig"
drivers/pinctrl/Makefile +2 -0
index 512112a..da27a91 100644
@@ -16,3 +16,5 @@ obj-$(CONFIG_PIC32_PINCTRL)	+= pinctrl_pic32.o
 obj-$(CONFIG_PINCTRL_EXYNOS)	+= exynos/
 obj-$(CONFIG_PINCTRL_MESON)	+= meson/
 obj-$(CONFIG_PINCTRL_MVEBU)	+= mvebu/
+
+obj-$(CONFIG_ARCH_SUNXI)        += sunxi/
\ No newline at end of file
drivers/pinctrl/sunxi/Makefile new file +10 -0
new file mode 100644
index 0000000..11549ec
@@ -0,0 +1,10 @@
+#
+# Copyright (c) 2017 Theobroma Systems Design und Consulting GmbH
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+obj-$(CONFIG_SUNXI_PINCTRL) += pinctrl-sunxi.o
+ifdef CONFIG_SUNXI_PINCTRL
+obj-$(CONFIG_MACH_SUN50I)   += pinctrl-sun50i-a64.o pinctrl-sun50i-a64-r.o
+endif
drivers/pinctrl/sunxi/pinctrl-sun50i-a64-r.c new file +92 -0

92 lines not on this page · raw message

drivers/pinctrl/sunxi/pinctrl-sun50i-a64.c new file +577 -0

577 lines not on this page · raw message

drivers/pinctrl/sunxi/pinctrl-sunxi.c new file +351 -0

351 lines not on this page · raw message

drivers/pinctrl/sunxi/pinctrl-sunxi.h new file +311 -0

311 lines not on this page · raw message

Signature · 1 line
1.9.1
#2 lore raw

PATCH v3 2/9 dm: core: Allow multiple drivers to bind for a single node

In reply to Philipp Tomsich

Currently, driver binding stops once it encounters the first compatible driver that doesn't refuse to bind. However, there are cases where a single node will need to be handled by multiple driver classes. For those cases we provide a configurable option to continue to bind after the first driver has been found.

The first use cases for this are from the DM conversion of the sunxi (Allwinner) architecture:
* pinctrl (UCLASS_PINCTRL) and gpio (UCLASS_GPIO) drivers need to bind against a single node
* clock (UCLASS_CLK) and reset (UCLASS_RESET) drivers also need to bind against a single node

---
 drivers/core/Kconfig | 14 ++++++++++++++
 drivers/core/lists.c | 12 +++++++++++-
 2 files changed, 25 insertions(+), 1 deletion(-)
drivers/core/Kconfig +14 -0
index 8749561..913101c 100644
@@ -31,6 +31,20 @@ config DM_WARN
 	  This will cause dm_warn() to be compiled out - it will do nothing
 	  when called.
 
+config DM_ALLOW_MULTIPLE_DRIVERS
+        bool "Allow multiple drivers to bind for one node"
+	depends on DM
+	default n
+	help
+	  The driver model in U-Boot originally did not allow multiple
+	  drivers to bind for a single device node.
+
+	  If enabled, multiple drivers can now bind for a single node
+	  by using the same compatible string for matching: lists_bind_fdt()
+	  will assume that binding multiple drivers is desirable, if the
+	  caller does not request the pointer to the udevice structure to
+	  be returned (i.e. if devp is NULL).
+
 config DM_DEVICE_REMOVE
 	bool "Support device removal"
 	depends on DM
drivers/core/lists.c +11 -1
index 23b6ba7..9124693 100644
@@ -166,7 +166,11 @@ int lists_bind_fdt(struct udevice *parent, const void *blob, int offset,
 		dm_dbg("   - attempt to match compatible string '%s'\n",
 		       compat);
 
-		for (entry = driver; entry != driver + n_ents; entry++) {
+		entry = driver;
+#if defined(CONFIG_DM_ALLOW_MULTIPLE_DRIVERS)
+allow_more_matches:
+#endif
+		for (; entry != driver + n_ents; entry++) {
 			ret = driver_check_compatible(entry->of_match, &id,
 						      compat);
 			if (!ret)
@@ -190,6 +194,12 @@ int lists_bind_fdt(struct udevice *parent, const void *blob, int offset,
 			found = true;
 			if (devp)
 				*devp = dev;
+#if defined(CONFIG_DM_ALLOW_MULTIPLE_DRIVERS)
+			else {
+				entry++;
+				goto allow_more_matches;
+			}
+#endif
 		}
 		break;
 	}
Signature · 1 line
1.9.1
#3 lore raw

PATCH v3 3/9 sunxi: CONFIG_DM_ALLOW_MULTIPLE_DRIVERS for gpio/pinctrl binding

In reply to Philipp Tomsich

Our gpio and pinctrl driver need to be bound against the same node. While this can be done by hand (i.e. explicitly looking up the driver, creating the driver-data and binding the device), it is much easier done when the new option for the binding of multiple drivers against a single node is configured.

---
 drivers/gpio/sunxi_gpio.c             | 4 ++--
 drivers/pinctrl/sunxi/pinctrl-sunxi.c | 8 ++++++--
 2 files changed, 8 insertions(+), 4 deletions(-)
drivers/gpio/sunxi_gpio.c +2 -2
index fd0c1ac..cbec1b9 100644
@@ -349,7 +349,7 @@ static const struct udevice_id sunxi_gpio_ids[] = {
 	ID("allwinner,sun8i-a83t-pinctrl",	a_all),
 	ID("allwinner,sun8i-h3-pinctrl",	a_all),
 	ID("allwinner,sun9i-a80-pinctrl",	a_all),
-#if !defined(CONFIG_SUNXI_PINCTRL)
+#if !defined(CONFIG_SUNXI_PINCTRL) || defined(CONFIG_DM_ALLOW_MULTIPLE_DRIVERS)
 	/* This is not strictly correct for the A64, as it is missing
 	 * bank 'A'. Yet, the register layout in the pinctrl block is
 	 * backward compatible and any accesses to the registers that
@@ -362,7 +362,7 @@ static const struct udevice_id sunxi_gpio_ids[] = {
 	ID("allwinner,sun8i-a83t-r-pinctrl",	l_1),
 	ID("allwinner,sun8i-h3-r-pinctrl",	l_1),
 	ID("allwinner,sun9i-a80-r-pinctrl",	l_3),
-#if !defined(CONFIG_SUNXI_PINCTRL)
+#if !defined(CONFIG_SUNXI_PINCTRL) || defined(CONFIG_DM_ALLOW_MULTIPLE_DRIVERS)
 	ID("allwinner,sun50i-a64-r-pinctrl",	l_1),
 #endif
 	{ }
drivers/pinctrl/sunxi/pinctrl-sunxi.c +6 -2
index 1e659fc..dc1a1f7 100644
@@ -16,7 +16,9 @@
 #include <asm/io.h>
 #include <asm/arch/clock.h>
 #include <asm/gpio.h>
+#if defined(CONFIG_DM_GPIO) && !defined(CONFIG_DM_ALLOW_MULTIPLE_DRIVERS)
 #include <asm/arch/gpio-internal.h>
+#endif
 #include <dm/device-internal.h>
 #include <dm/lists.h>
 #include <dm/pinctrl.h>
@@ -29,7 +31,7 @@ DECLARE_GLOBAL_DATA_PTR;
 
 struct sunxi_pctrl_priv {
 	void *base;
-#if defined(CONFIG_DM_GPIO)
+#if defined(CONFIG_DM_GPIO) && !defined(CONFIG_DM_ALLOW_MULTIPLE_DRIVERS)
 	struct sunxi_gpio_soc_data gpio_soc_data;
 	struct udevice *gpio_dev;
 #endif
@@ -251,6 +253,7 @@ static int sunxi_pctrl_set_state(struct udevice *dev, struct udevice *config)
 	return 0;
 }
 
+#if defined(CONFIG_DM_GPIO) && !defined(CONFIG_DM_ALLOW_MULTIPLE_DRIVERS)
 static inline void soc_data_from_desc(const struct sunxi_pinctrl_desc *data,
 				      struct sunxi_gpio_soc_data *soc_data)
 {
@@ -270,10 +273,11 @@ static inline void soc_data_from_desc(const struct sunxi_pinctrl_desc *data,
 	soc_data->start = low;
 	soc_data->no_banks = high - low + 1;
 }
+#endif
 
 static int sunxi_pctrl_bind_gpio(struct udevice *dev)
 {
-#if defined(CONFIG_DM_GPIO)
+#if defined(CONFIG_DM_GPIO) && !defined(CONFIG_DM_ALLOW_MULTIPLE_DRIVERS)
 	struct sunxi_pctrl_priv *priv = dev_get_priv(dev);
 	const struct sunxi_pinctrl_desc *data =
 		(struct sunxi_pinctrl_desc *)dev_get_driver_data(dev);
Signature · 1 line
1.9.1
#4 lore raw

PATCH v3 4/9 Kconfig: sunxi: Select new option for allow multiple drivers to bind

In reply to Philipp Tomsich

For pinctrl & gpio and reset & clk, the sunxi (Allwinner SoC) board support needs to bind multiple drivers to a single DT node. Select the necessary config-option when selecting ARCH_SUNXI.

---
 arch/arm/Kconfig | 1 +
 1 file changed, 1 insertion(+)
arch/arm/Kconfig +1 -0
index 0229800..c62d61b 100644
@@ -644,6 +644,7 @@ config ARCH_SUNXI
 	select CMD_MMC if MMC
 	select CMD_USB if DISTRO_DEFAULTS
 	select DM
+	select DM_ALLOW_MULTIPLE_DRIVERS
 	select DM_ETH
 	select DM_GPIO
 	select DM_KEYBOARD
Signature · 1 line
1.9.1
#5 lore raw

PATCH v3 5/9 sunxi: add module reset (UCLASS_RESET) support for sunxi

In reply to Philipp Tomsich

In order to have the device model describe the module reset bits on sunxi (well, at least for anything newer than sun6i), we need a (rather simple) driver for 'allwinner,sun6i-a31-clock-reset' nodes.

---
 drivers/reset/Kconfig                      |   9 ++
 drivers/reset/Makefile                     |   1 +
 drivers/reset/sunxi/Makefile               |   6 ++
 drivers/reset/sunxi/ccu-sun50i-a64.c       |  75 +++++++++++++
 drivers/reset/sunxi/ccu_reset.h            |   9 ++
 drivers/reset/sunxi/reset-sunxi.c          | 168 +++++++++++++++++++++++++++++
 include/dt-bindings/reset/sun50i-a64-ccu.h |  98 +++++++++++++++++
 7 files changed, 366 insertions(+)
 create mode 100644 drivers/reset/sunxi/Makefile
 create mode 100644 drivers/reset/sunxi/ccu-sun50i-a64.c
 create mode 100644 drivers/reset/sunxi/ccu_reset.h
 create mode 100644 drivers/reset/sunxi/reset-sunxi.c
 create mode 100644 include/dt-bindings/reset/sun50i-a64-ccu.h
drivers/reset/Kconfig +9 -0
index c42b0bc..8db25fc 100644
@@ -43,4 +43,13 @@ config RESET_UNIPHIER
 	  Say Y if you want to control reset signals provided by System Control
 	  block, Media I/O block, Peripheral Block.
 
+config RESET_SUNXI
+        bool "Reset controller driver for Allwiner SoCs"
+	depends on DM_RESET && ARCH_SUNXI
+	default y
+	help
+	  Support for reset controllers on Allwinner SoCs.
+	  Say Y if you want to control reset signals provided by CCU (e.g. sun50i)
+	  or PRCM (e.g. sun6i, sun9i) blocks.
+
 endmenu
drivers/reset/Makefile +1 -0
index 5c4305c..a4994e9 100644
@@ -8,3 +8,4 @@ obj-$(CONFIG_SANDBOX_MBOX) += sandbox-reset-test.o
 obj-$(CONFIG_TEGRA_CAR_RESET) += tegra-car-reset.o
 obj-$(CONFIG_TEGRA186_RESET) += tegra186-reset.o
 obj-$(CONFIG_RESET_UNIPHIER) += reset-uniphier.o
+obj-$(CONFIG_RESET_SUNXI) += sunxi/
drivers/reset/sunxi/Makefile new file +6 -0
new file mode 100644
index 0000000..559c79a
@@ -0,0 +1,6 @@
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+obj-y += reset-sunxi.o
+obj-$(CONFIG_MACH_SUN50I) += ccu-sun50i-a64.o
\ No newline at end of file
drivers/reset/sunxi/ccu-sun50i-a64.c new file +75 -0

75 lines not on this page · raw message

drivers/reset/sunxi/ccu_reset.h new file +9 -0
new file mode 100644
index 0000000..83b30a0
@@ -0,0 +1,9 @@
+#ifndef _CCU_RESET_H_
+#define _CCU_RESET_H_
+
+struct ccu_reset_map {
+	uint16_t reg;
+	uint32_t bit;
+};
+
+#endif /* _CCU_RESET_H_ */
drivers/reset/sunxi/reset-sunxi.c new file +168 -0

168 lines not on this page · raw message

include/dt-bindings/reset/sun50i-a64-ccu.h new file +98 -0

98 lines not on this page · raw message

Signature · 1 line
1.9.1
#6 lore raw

PATCH v3 6/9 linux/kernel.h: sync DIV_ROUND_UP_ULL from kernel

In reply to Philipp Tomsich

The DIV_ROUND_UP_ULL is required for porting the sunxi clock (CCU) binding from linux.

---
 include/linux/kernel.h | 2 ++
 1 file changed, 2 insertions(+)
include/linux/kernel.h +2 -0
index 0b61671..dc3f36a 100644
@@ -56,6 +56,8 @@
 
 #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
+#define DIV_ROUND_UP_ULL(ll,d) \
+	({ unsigned long long _tmp = (ll)+(d)-1; do_div(_tmp, d); _tmp; })
 
 #if BITS_PER_LONG == 32
 # define DIV_ROUND_UP_SECTOR_T(ll,d) DIV_ROUND_UP_ULL(ll, d)
Signature · 1 line
1.9.1
#7 lore raw

PATCH v3 7/9 clk: clk-uclass: add clk_get_by_output_name

In reply to Philipp Tomsich
---
 drivers/clk/clk-uclass.c | 30 ++++++++++++++++++++++++++++++
 include/clk.h            | 22 ++++++++++++++++++++++
 2 files changed, 52 insertions(+)
drivers/clk/clk-uclass.c +30 -0
index 6fcfd69..a6a65b2 100644
@@ -10,6 +10,7 @@
 #include <clk.h>
 #include <clk-uclass.h>
 #include <dm.h>
+#include <dm/uclass-internal.h>
 #include <dt-structs.h>
 #include <errno.h>
 
@@ -113,6 +114,35 @@ int clk_get_by_name(struct udevice *dev, const char *name, struct clk *clk)
 
 	return clk_get_by_index(dev, index, clk);
 }
+
+int clk_get_by_output_name(const char *output_name, struct clk *clk)
+{
+	struct udevice *dev;
+	int idx;
+	int ret;
+
+	debug("%s(output=%s, clk==%p)\n", __func__, output_name, clk);
+
+	/* Try to find the clock among the already registered devices */
+	for (ret = uclass_find_first_device(UCLASS_CLK, &dev); dev;
+	     ret = uclass_find_next_device(&dev)) {
+		if (ret)
+			continue;
+
+		idx = fdt_stringlist_search(gd->fdt_blob,
+					    dev_of_offset(dev),
+					    "clock-output-names",
+					    output_name);
+		if (idx < 0)
+			continue;
+
+		clk->dev = dev;
+		clk->id = idx;
+		return idx;
+	}
+
+	return -ENOENT;
+}
 #endif /* OF_CONTROL */
 
 int clk_request(struct udevice *dev, struct clk *clk)
include/clk.h +22 -0
index 5a5c2ff..d12b896 100644
@@ -98,6 +98,22 @@ int clk_get_by_index(struct udevice *dev, int index, struct clk *clk);
  * @return 0 if OK, or a negative error code.
  */
 int clk_get_by_name(struct udevice *dev, const char *name, struct clk *clk);
+
+/**
+ * clk_get_by_output_name - Get a clock by its output name
+ *
+ * This looks up a clock from the bound clock-devices. The output_name
+ * is a string that should be present in the 'clock-output-names' list
+ * of one of those clocks.
+ *
+ * @output_name: A name contained in the output-name list of the node
+ *               associated with the target node.
+ * @clk:         A pointer to a clock structure to initialize.
+ * @return the index (of the name in the output-name list) if found, or
+ *             a negative error code.
+ */
+
+int clk_get_by_output_name(const char *output_name, struct clk *clk);
 #else
 static inline int clk_get_by_index(struct udevice *dev, int index,
 				   struct clk *clk)
@@ -110,6 +126,12 @@ static inline int clk_get_by_name(struct udevice *dev, const char *name,
 {
 	return -ENOSYS;
 }
+
+static inline int clk_get_by_output_name(const char *output_name,
+					 struct clk *clk)
+{
+	return -ENOSYS;
+}
 #endif
 
 /**
Signature · 1 line
1.9.1
#8 lore raw

PATCH v3 8/9 sunxi: add clock driver (UCLASS_CLK) support for sunxi

In reply to Philipp Tomsich

When CONFIG_CLK is defined, we now provide support for the basic clock configuration of peripherals on sunxi:
* clk-sunxi-ccu.c implements the CCU based (new-style) binding based on the Linux implementation.

And for handling the binding of the always-on (R_*) subsystems:
* clk-sunxi-mod.c implements support for module clocks, which performs parent selection (determined via the device-tree) and determines/configures a pre-divider and divider when setting a clock-rate
* clk-sunxi-gate.c: implements an clk-gate to gate individual modules (i.e. 'allwinner,sunxi-multi-bus-gates-clk')

---
 drivers/clk/Makefile                        |   1 +
 drivers/clk/sunxi/Makefile                  |  30 ++
 drivers/clk/sunxi/ccu-compatibility.h       | 232 ++++++++
 drivers/clk/sunxi/ccu-runtime-divider.c     | 115 ++++
 drivers/clk/sunxi/ccu-runtime-fixedfactor.c |  17 +
 drivers/clk/sunxi/ccu-sun50i-a64.c          | 810 ++++++++++++++++++++++++++++
 drivers/clk/sunxi/ccu-sun50i-a64.h          |  64 +++
 drivers/clk/sunxi/ccu_common.c              |  27 +
 drivers/clk/sunxi/ccu_common.h              |  67 +++
 drivers/clk/sunxi/ccu_div.c                 | 134 +++++
 drivers/clk/sunxi/ccu_div.h                 | 170 ++++++
 drivers/clk/sunxi/ccu_frac.c                | 106 ++++
 drivers/clk/sunxi/ccu_frac.h                |  46 ++
 drivers/clk/sunxi/ccu_gate.c                |  80 +++
 drivers/clk/sunxi/ccu_gate.h                |  45 ++
 drivers/clk/sunxi/ccu_mp.c                  | 159 ++++++
 drivers/clk/sunxi/ccu_mp.h                  |  70 +++
 drivers/clk/sunxi/ccu_mult.h                |  39 ++
 drivers/clk/sunxi/ccu_mux.c                 | 201 +++++++
 drivers/clk/sunxi/ccu_mux.h                 | 105 ++++
 drivers/clk/sunxi/ccu_nk.c                  | 154 ++++++
 drivers/clk/sunxi/ccu_nk.h                  |  64 +++
 drivers/clk/sunxi/ccu_nkm.c                 | 184 +++++++
 drivers/clk/sunxi/ccu_nkm.h                 |  84 +++
 drivers/clk/sunxi/ccu_nkmp.c                | 171 ++++++
 drivers/clk/sunxi/ccu_nkmp.h                |  64 +++
 drivers/clk/sunxi/ccu_nm.c                  | 148 +++++
 drivers/clk/sunxi/ccu_nm.h                  |  84 +++
 drivers/clk/sunxi/clk-sunxi-ccu.c           | 550 +++++++++++++++++++
 drivers/clk/sunxi/clk-sunxi-gate.c          |  92 ++++
 drivers/clk/sunxi/clk-sunxi-mod.c           | 241 +++++++++
 include/dt-bindings/clock/sun50i-a64-ccu.h  | 134 +++++
 32 files changed, 4488 insertions(+)
 create mode 100644 drivers/clk/sunxi/Makefile
 create mode 100644 drivers/clk/sunxi/ccu-compatibility.h
 create mode 100644 drivers/clk/sunxi/ccu-runtime-divider.c
 create mode 100644 drivers/clk/sunxi/ccu-runtime-fixedfactor.c
 create mode 100644 drivers/clk/sunxi/ccu-sun50i-a64.c
 create mode 100644 drivers/clk/sunxi/ccu-sun50i-a64.h
 create mode 100644 drivers/clk/sunxi/ccu_common.c
 create mode 100644 drivers/clk/sunxi/ccu_common.h
 create mode 100644 drivers/clk/sunxi/ccu_div.c
 create mode 100644 drivers/clk/sunxi/ccu_div.h
 create mode 100644 drivers/clk/sunxi/ccu_frac.c
 create mode 100644 drivers/clk/sunxi/ccu_frac.h
 create mode 100644 drivers/clk/sunxi/ccu_gate.c
 create mode 100644 drivers/clk/sunxi/ccu_gate.h
 create mode 100644 drivers/clk/sunxi/ccu_mp.c
 create mode 100644 drivers/clk/sunxi/ccu_mp.h
 create mode 100644 drivers/clk/sunxi/ccu_mult.h
 create mode 100644 drivers/clk/sunxi/ccu_mux.c
 create mode 100644 drivers/clk/sunxi/ccu_mux.h
 create mode 100644 drivers/clk/sunxi/ccu_nk.c
 create mode 100644 drivers/clk/sunxi/ccu_nk.h
 create mode 100644 drivers/clk/sunxi/ccu_nkm.c
 create mode 100644 drivers/clk/sunxi/ccu_nkm.h
 create mode 100644 drivers/clk/sunxi/ccu_nkmp.c
 create mode 100644 drivers/clk/sunxi/ccu_nkmp.h
 create mode 100644 drivers/clk/sunxi/ccu_nm.c
 create mode 100644 drivers/clk/sunxi/ccu_nm.h
 create mode 100644 drivers/clk/sunxi/clk-sunxi-ccu.c
 create mode 100644 drivers/clk/sunxi/clk-sunxi-gate.c
 create mode 100644 drivers/clk/sunxi/clk-sunxi-mod.c
 create mode 100644 include/dt-bindings/clock/sun50i-a64-ccu.h
drivers/clk/Makefile +1 -0
index 884c21c..7ae8029 100644
@@ -7,6 +7,7 @@
 
 obj-$(CONFIG_CLK) += clk-uclass.o clk_fixed_rate.o
 obj-$(CONFIG_ARCH_ROCKCHIP) += rockchip/
+obj-$(CONFIG_ARCH_SUNXI) += sunxi/
 obj-$(CONFIG_SANDBOX) += clk_sandbox.o
 obj-$(CONFIG_SANDBOX) += clk_sandbox_test.o
 obj-$(CONFIG_MACH_PIC32) += clk_pic32.o
drivers/clk/sunxi/Makefile new file +30 -0
new file mode 100644
index 0000000..8124b99
@@ -0,0 +1,30 @@
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+# Legacy clock drivers (used for the always-on subsystem)
+obj-y += clk-sunxi-mod.o
+obj-y += clk-sunxi-gate.o
+
+# CCU modules (ported from Linux)
+obj-y += \
+	 ccu_common.o \
+	 ccu_div.o \
+	 ccu_frac.o \
+	 ccu_gate.o \
+	 ccu_mp.o \
+	 ccu_mux.o \
+	 ccu_nk.o \
+	 ccu_nkm.o \
+	 ccu_nkmp.o \
+	 ccu_nm.o
+
+# CCU runtime
+obj-y += ccu-runtime-divider.o \
+	 ccu-runtime-fixedfactor.o
+
+obj-y += clk-sunxi-ccu.o
+
+# CCU per-cpu config
+obj-$(CONFIG_MACH_SUN50I) += ccu-sun50i-a64.o
+
drivers/clk/sunxi/ccu-compatibility.h new file +232 -0

232 lines not on this page · raw message

drivers/clk/sunxi/ccu-runtime-divider.c new file +115 -0

115 lines not on this page · raw message

drivers/clk/sunxi/ccu-runtime-fixedfactor.c new file +17 -0
new file mode 100644
index 0000000..53a727b
@@ -0,0 +1,17 @@
+/*
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include "ccu_common.h"
+
+static unsigned long clk_fixed_factor_recalc_rate(struct clk_hw *hw,
+						  unsigned long parent_rate)
+{
+	struct clk_fixed_factor *cff = to_clk_fixed_factor(hw);
+	return (parent_rate * cff->mult) / cff->div;
+}
+
+const struct sunxi_ccu_clk_ops clk_fixed_factor_ops = {
+	.recalc_rate = clk_fixed_factor_recalc_rate,
+};
drivers/clk/sunxi/ccu-sun50i-a64.c new file +810 -0

810 lines not on this page · raw message

drivers/clk/sunxi/ccu-sun50i-a64.h new file +64 -0

64 lines not on this page · raw message

drivers/clk/sunxi/ccu_common.c new file +27 -0
new file mode 100644
index 0000000..6dba33c
@@ -0,0 +1,27 @@
+/*
+ * Derived from drivers/clk/sunxi-ng/ccu_common.c in Linux, which is
+ *   Copyright (C) 2016 Maxime Ripard
+ *   Maxime Ripard <[email protected]>
+ *
+ * Ported to U-Boot by
+ *   Theobroma Systems Design und Consulting GmbH
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <linux/compat.h>
+#include <linux/iopoll.h>
+
+#include "ccu_common.h"
+
+void ccu_helper_wait_for_lock(struct ccu_common *common, u32 lock)
+{
+	u32 reg;
+
+	if (!lock)
+		return;
+
+	WARN_ON(readl_poll_timeout(common->base + common->reg, reg,
+				   reg & lock, 70000));
+}
drivers/clk/sunxi/ccu_common.h new file +67 -0

67 lines not on this page · raw message

drivers/clk/sunxi/ccu_div.c new file +134 -0

134 lines not on this page · raw message

drivers/clk/sunxi/ccu_div.h new file +170 -0

170 lines not on this page · raw message

drivers/clk/sunxi/ccu_frac.c new file +106 -0

106 lines not on this page · raw message

drivers/clk/sunxi/ccu_frac.h new file +46 -0

46 lines not on this page · raw message

drivers/clk/sunxi/ccu_gate.c new file +80 -0

80 lines not on this page · raw message

drivers/clk/sunxi/ccu_gate.h new file +45 -0

45 lines not on this page · raw message

drivers/clk/sunxi/ccu_mp.c new file +159 -0

159 lines not on this page · raw message

drivers/clk/sunxi/ccu_mp.h new file +70 -0

70 lines not on this page · raw message

drivers/clk/sunxi/ccu_mult.h new file +39 -0
new file mode 100644
index 0000000..2d77fdc
@@ -0,0 +1,39 @@
+/*
+ * Derived from drivers/clk/sunxi-ng/ccu_mult.h in Linux, which is
+ *   Copyright (C) 2016 Maxime Ripard
+ *   Maxime Ripard <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef _CCU_MULT_H_
+#define _CCU_MULT_H_
+
+#include "ccu_common.h"
+#include "ccu_mux.h"
+
+struct ccu_mult_internal {
+	u8	shift;
+	u8	width;
+	u8	min;
+};
+
+#define _SUNXI_CCU_MULT_MIN(_shift, _width, _min)	\
+	{						\
+		.shift	= _shift,			\
+		.width	= _width,			\
+		.min	= _min,				\
+	}
+
+#define _SUNXI_CCU_MULT(_shift, _width)		\
+	_SUNXI_CCU_MULT_MIN(_shift, _width, 1)
+
+struct ccu_mult {
+	u32			enable;
+
+	struct ccu_mult_internal	mult;
+	struct ccu_mux_internal	mux;
+	struct ccu_common	common;
+};
+
+#endif /* _CCU_MULT_H_ */
drivers/clk/sunxi/ccu_mux.c new file +201 -0

201 lines not on this page · raw message

drivers/clk/sunxi/ccu_mux.h new file +105 -0

105 lines not on this page · raw message

drivers/clk/sunxi/ccu_nk.c new file +154 -0

154 lines not on this page · raw message

drivers/clk/sunxi/ccu_nk.h new file +64 -0

64 lines not on this page · raw message

drivers/clk/sunxi/ccu_nkm.c new file +184 -0

184 lines not on this page · raw message

drivers/clk/sunxi/ccu_nkm.h new file +84 -0

74 lines not on this page · raw message

drivers/clk/sunxi/ccu_nkmp.c new file +171 -0

171 lines not on this page · raw message

drivers/clk/sunxi/ccu_nkmp.h new file +64 -0

64 lines not on this page · raw message

drivers/clk/sunxi/ccu_nm.c new file +148 -0

148 lines not on this page · raw message

drivers/clk/sunxi/ccu_nm.h new file +84 -0

84 lines not on this page · raw message

drivers/clk/sunxi/clk-sunxi-ccu.c new file +550 -0

550 lines not on this page · raw message

drivers/clk/sunxi/clk-sunxi-gate.c new file +92 -0

92 lines not on this page · raw message

drivers/clk/sunxi/clk-sunxi-mod.c new file +241 -0

241 lines not on this page · raw message

include/dt-bindings/clock/sun50i-a64-ccu.h new file +134 -0

134 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.9.1

Part of the diff is not shown here. View the raw message.

#9 lore raw

PATCH v3 9/9 cmd: move CONFIG_CMD_CLK to Kconfig

In reply to Philipp Tomsich

The CMD_CLK configuration allows the clk-command today (having only the 'clk dump' action for printing the clock configuration using a per-SoC weak function).

It is currently only selected by ZYNC and PIC32. To make it easier to use this command for other platforms and to select it via defconfig, we are moving it into Kconfig.

Given that this is a debug/maintainer command, the default was chosen as 'n' and thus should cause no warning messages to board that still enable it in their respective header files.

---
 cmd/Kconfig | 10 ++++++++++
 1 file changed, 10 insertions(+)
cmd/Kconfig +10 -0
index ef53156..119a600 100644
@@ -144,6 +144,16 @@ config CMD_CONSOLE
 	help
 	  Print console devices and information.
 
+config CMD_CLK
+        bool "clk"
+	default n
+	help
+	  Print information about clocks.
+
+	  This normally shows a list of clocks and their current
+	  configuration.  The implementation and details of the output
+	  are manufacturer specific.
+
 config CMD_CPU
 	bool "cpu"
 	help
Signature · 1 line
1.9.1
#10 lore raw

v3 cover sunxi: DM-based CLK, RESET and PINCTRL

In reply to Philipp Tomsich
Quoted 11 lines · Philipp Tomsich

Hi everyone,

here's the the new version of CLK, RESET and PINCTRL drivers to configure sunxi from the device-tree. This adds support for the upstream CCU node (for reset and pinctrl) and tries to address the various concerns people had.

Note that (to stay in sync with the Linux files), some of the patches may not fully adhere to the style (e.g. some of the code reused verbatim from Linux and in the config tables).

Quoted 7 lines

This has been tested with Ethernet, I2C, SPI and MMC on the A64-uQ7. See my separate patchsets for the conversion of these drivers over to support DM-based CLK, RESET and PINCTRL configuration.

Changes is v3:
* add support for the 'new-style' clock subsystem (CCU) by porting from Linux and adding the necessary glue implementation

Gah, is this really necessary? Do we really need to pull in the whole of the complex Linux clock driver?
In the end all that U-Boot needs to do is to program a few simple clocks, a task which it easily did so far with just some register writes. I don't think it's appropriate for U-Boot to get the whole complex clock driver from Linux for just that purpose.
One indication of this being too much is that the mailing list seemed to have blocked patch 8/9, probably because it's too big ;-)
I am especially scared when it comes to adding all of the other SoC's clock drivers to the code base as well.

So can't we do a much simpler (because limited) implementation? If a peripheral driver gets the clock index from the DT and asks the clock driver to program (or just enable) clock "75", can't we just have a simple function which redirects this clock number to our already existing code?
Something like (rough sketch):
int sun50i_clk_set_freq(int nr, int freq)

{
	int idx;

	switch (nr) {
	case CLK_MMC0 ... CLK_MMC2:
		idx = nr - CLK_MMC0;
		return mmc_set_mod_clk(idx,
				       clkreg_addr[MMC_CLK + idx],
				       freq);
	}
}

... with mmc_set_mod_clk() being a slightly changed version of the existing implementation?

I think that would seriously reduce the bloat and be a better fit for U-Boot. And it might even allow the SPL to reuse this by just calling into the dispatch function with hardcoded parameters.

Cheers,
Andre.

Quoted 124 lines

- add a CCU reset-driver (in addition to the legacy driver, which will still be required for the R_* device nodes), which reuses the reset-table from ccu-<SOC>.c
- add a clk-sunxi-ccu.c implementation based on Linux and reusing both the low-level clock implementation (ccu_*.h) and the config table (ccu-<SOC>.c) from Linux
* reuse the 'allwinner,pinctrl.txt' documentation for the pinctrl binding from Linux
* adds the includes for the CCU dt-bindings from Linux
* adds support for printing the CCU subsystem via 'clk dump'

Philipp Tomsich (9):
sunxi: add pinctrl (UCLASS_PINCTRL) support for sunxi
dm: core: Allow multiple drivers to bind for a single node
sunxi: CONFIG_DM_ALLOW_MULTIPLE_DRIVERS for gpio/pinctrl binding
Kconfig: sunxi: Select new option for allow multiple drivers to bind
sunxi: add module reset (UCLASS_RESET) support for sunxi linux/kernel.h: sync DIV_ROUND_UP_ULL from kernel
clk: clk-uclass: add clk_get_by_output_name
sunxi: add clock driver (UCLASS_CLK) support for sunxi
cmd: move CONFIG_CMD_CLK to Kconfig

 arch/arm/Kconfig                                   |   1 +
 arch/arm/include/asm/arch-sunxi/gpio-internal.h    |  19 +
 cmd/Kconfig                                        |  10 +
 .../pinctrl/allwinner,pinctrl.txt                  | 142 ++++
 drivers/clk/Makefile                               |   1 +
 drivers/clk/clk-uclass.c                           |  30 +
 drivers/clk/sunxi/Makefile                         |  30 +
 drivers/clk/sunxi/ccu-compatibility.h              | 232 ++++++
 drivers/clk/sunxi/ccu-runtime-divider.c            | 115 +++
 drivers/clk/sunxi/ccu-runtime-fixedfactor.c        |  17 +
 drivers/clk/sunxi/ccu-sun50i-a64.c                 | 810 +++++++++++++++++++++
 drivers/clk/sunxi/ccu-sun50i-a64.h                 |  64 ++
 drivers/clk/sunxi/ccu_common.c                     |  27 +
 drivers/clk/sunxi/ccu_common.h                     |  67 ++
 drivers/clk/sunxi/ccu_div.c                        | 134 ++++
 drivers/clk/sunxi/ccu_div.h                        | 170 +++++
 drivers/clk/sunxi/ccu_frac.c                       | 106 +++
 drivers/clk/sunxi/ccu_frac.h                       |  46 ++
 drivers/clk/sunxi/ccu_gate.c                       |  80 ++
 drivers/clk/sunxi/ccu_gate.h                       |  45 ++
 drivers/clk/sunxi/ccu_mp.c                         | 159 ++++
 drivers/clk/sunxi/ccu_mp.h                         |  70 ++
 drivers/clk/sunxi/ccu_mult.h                       |  39 +
 drivers/clk/sunxi/ccu_mux.c                        | 201 +++++
 drivers/clk/sunxi/ccu_mux.h                        | 105 +++
 drivers/clk/sunxi/ccu_nk.c                         | 154 ++++
 drivers/clk/sunxi/ccu_nk.h                         |  64 ++
 drivers/clk/sunxi/ccu_nkm.c                        | 184 +++++
 drivers/clk/sunxi/ccu_nkm.h                        |  84 +++
 drivers/clk/sunxi/ccu_nkmp.c                       | 171 +++++
 drivers/clk/sunxi/ccu_nkmp.h                       |  64 ++
 drivers/clk/sunxi/ccu_nm.c                         | 148 ++++
 drivers/clk/sunxi/ccu_nm.h                         |  84 +++
 drivers/clk/sunxi/clk-sunxi-ccu.c                  | 550 ++++++++++++++
 drivers/clk/sunxi/clk-sunxi-gate.c                 |  92 +++
 drivers/clk/sunxi/clk-sunxi-mod.c                  | 241 ++++++
 drivers/core/Kconfig                               |  14 +
 drivers/core/lists.c                               |  12 +-
 drivers/gpio/sunxi_gpio.c                          |  15 +-
 drivers/pinctrl/Kconfig                            |  10 +
 drivers/pinctrl/Makefile                           |   2 +
 drivers/pinctrl/sunxi/Makefile                     |  10 +
 drivers/pinctrl/sunxi/pinctrl-sun50i-a64-r.c       |  92 +++
 drivers/pinctrl/sunxi/pinctrl-sun50i-a64.c         | 577 +++++++++++++++
 drivers/pinctrl/sunxi/pinctrl-sunxi.c              | 355 +++++++++
 drivers/pinctrl/sunxi/pinctrl-sunxi.h              | 311 ++++++++
 drivers/reset/Kconfig                              |   9 +
 drivers/reset/Makefile                             |   1 +
 drivers/reset/sunxi/Makefile                       |   6 +
 drivers/reset/sunxi/ccu-sun50i-a64.c               |  75 ++
 drivers/reset/sunxi/ccu_reset.h                    |   9 +
 drivers/reset/sunxi/reset-sunxi.c                  | 168 +++++
 include/clk.h                                      |  22 +
 include/dt-bindings/clock/sun50i-a64-ccu.h         | 134 ++++
 include/dt-bindings/reset/sun50i-a64-ccu.h         |  98 +++
 include/linux/kernel.h                             |   2 +
 56 files changed, 6470 insertions(+), 8 deletions(-)
 create mode 100644 arch/arm/include/asm/arch-sunxi/gpio-internal.h
 create mode 100644 doc/device-tree-bindings/pinctrl/allwinner,pinctrl.txt
 create mode 100644 drivers/clk/sunxi/Makefile
 create mode 100644 drivers/clk/sunxi/ccu-compatibility.h
 create mode 100644 drivers/clk/sunxi/ccu-runtime-divider.c
 create mode 100644 drivers/clk/sunxi/ccu-runtime-fixedfactor.c
 create mode 100644 drivers/clk/sunxi/ccu-sun50i-a64.c
 create mode 100644 drivers/clk/sunxi/ccu-sun50i-a64.h
 create mode 100644 drivers/clk/sunxi/ccu_common.c
 create mode 100644 drivers/clk/sunxi/ccu_common.h
 create mode 100644 drivers/clk/sunxi/ccu_div.c
 create mode 100644 drivers/clk/sunxi/ccu_div.h
 create mode 100644 drivers/clk/sunxi/ccu_frac.c
 create mode 100644 drivers/clk/sunxi/ccu_frac.h
 create mode 100644 drivers/clk/sunxi/ccu_gate.c
 create mode 100644 drivers/clk/sunxi/ccu_gate.h
 create mode 100644 drivers/clk/sunxi/ccu_mp.c
 create mode 100644 drivers/clk/sunxi/ccu_mp.h
 create mode 100644 drivers/clk/sunxi/ccu_mult.h
 create mode 100644 drivers/clk/sunxi/ccu_mux.c
 create mode 100644 drivers/clk/sunxi/ccu_mux.h
 create mode 100644 drivers/clk/sunxi/ccu_nk.c
 create mode 100644 drivers/clk/sunxi/ccu_nk.h
 create mode 100644 drivers/clk/sunxi/ccu_nkm.c
 create mode 100644 drivers/clk/sunxi/ccu_nkm.h
 create mode 100644 drivers/clk/sunxi/ccu_nkmp.c
 create mode 100644 drivers/clk/sunxi/ccu_nkmp.h
 create mode 100644 drivers/clk/sunxi/ccu_nm.c
 create mode 100644 drivers/clk/sunxi/ccu_nm.h
 create mode 100644 drivers/clk/sunxi/clk-sunxi-ccu.c
 create mode 100644 drivers/clk/sunxi/clk-sunxi-gate.c
 create mode 100644 drivers/clk/sunxi/clk-sunxi-mod.c
 create mode 100644 drivers/pinctrl/sunxi/Makefile
 create mode 100644 drivers/pinctrl/sunxi/pinctrl-sun50i-a64-r.c
 create mode 100644 drivers/pinctrl/sunxi/pinctrl-sun50i-a64.c
 create mode 100644 drivers/pinctrl/sunxi/pinctrl-sunxi.c
 create mode 100644 drivers/pinctrl/sunxi/pinctrl-sunxi.h
 create mode 100644 drivers/reset/sunxi/Makefile
 create mode 100644 drivers/reset/sunxi/ccu-sun50i-a64.c
 create mode 100644 drivers/reset/sunxi/ccu_reset.h
 create mode 100644 drivers/reset/sunxi/reset-sunxi.c
 create mode 100644 include/dt-bindings/clock/sun50i-a64-ccu.h
 create mode 100644 include/dt-bindings/reset/sun50i-a64-ccu.h
#11 lore raw

v3 cover sunxi: DM-based CLK, RESET and PINCTRL

Andre,

Quoted 18 lines · André Przywara
Quoted 15 lines · Philipp Tomsich

Hi everyone,

here's the the new version of CLK, RESET and PINCTRL drivers to configure sunxi from the device-tree. This adds support for the upstream CCU node (for reset and pinctrl) and tries to address the various concerns people had.

Note that (to stay in sync with the Linux files), some of the patches may not fully adhere to the style (e.g. some of the code reused verbatim from Linux and in the config tables).

This has been tested with Ethernet, I2C, SPI and MMC on the A64-uQ7. See my separate patchsets for the conversion of these drivers over to support DM-based CLK, RESET and PINCTRL configuration.

Quoted 6 lines
Quoted 3 lines

Changes is v3:
* add support for the 'new-style' clock subsystem (CCU) by porting from Linux and adding the necessary glue implementation

Gah, is this really necessary? Do we really need to pull in the whole of the complex Linux clock driver?

It’s not necessary and I’d be more than happy to reduce the list of the clocks in the table, but reusing the Linux driver (and it’s infrastructure) allows us to add new SoCs by reusing the table from Linux. However, reducing the number of table entries will not reduce the “bulk” much, as these are only config entries (and the code to support the various types of clocks should be present nonetheless).

Given that these tables are fully tested on the Linux side, I believe this to be of more value than to keep this small for U-Boot… after all, the full CCU-support will only be used for the final U-Boot stage (which runs from DRAM) and never considered for SPL/TPL.

Quoted 4 lines

In the end all that U-Boot needs to do is to program a few simple clocks, a task which it easily did so far with just some register writes. I don't think it's appropriate for U-Boot to get the whole complex clock driver from Linux for just that purpose.

I beg to differ on the “a few simple clocks” aspect of this. A full-featured U-Boot should require (including reparenting) clocks for SPI, I2C, MMC, EMAC, USB (incl. PHYs) and video (on the SoCs where simplefb is supported).

It’s best to keep all of this in sync with Linux, as this will simplify the long-term maintenance.

Quoted 4 lines

One indication of this being too much is that the mailing list seemed to have blocked patch 8/9, probably because it's too big ;-)
I am especially scared when it comes to adding all of the other SoC's clock drivers to the code base as well.

It was just a couple bytes over the limit to require moderation ;-)

The benefit of this approach is that all the ccu_*.c clock implementations and the configuration table can be reused almost verbatim from Linux. The only change necessary will be in the list of headers included and the change of the _ops datatype.

Quoted 18 lines

So can't we do a much simpler (because limited) implementation? If a peripheral driver gets the clock index from the DT and asks the clock driver to program (or just enable) clock "75", can't we just have a simple function which redirects this clock number to our already existing code?
Something like (rough sketch):
int sun50i_clk_set_freq(int nr, int freq)

{
	int idx;

	switch (nr) {
	case CLK_MMC0 ... CLK_MMC2:
		idx = nr - CLK_MMC0;
		return mmc_set_mod_clk(idx,
				       clkreg_addr[MMC_CLK + idx],
				       freq);
	}
}
Quoted 2 lines

... with mmc_set_mod_clk() being a slightly changed version of the existing implementation?

This will not help with many of the use-cases, such as reparenting clocks dynamically as we change clocks on SPI.

It seems to be a good alternative implementation for the SPL use-case, though and I’d be happy to add this in as the SPL-alternative.

Quoted 3 lines

I think that would seriously reduce the bloat and be a better fit for U-Boot. And it might even allow the SPL to reuse this by just calling into the dispatch function with hardcoded parameters.

The total bulk added is not trivial, but appears to be be reasonable (for the final-stage U-Boot):
1. code to support the various clocks: +33KB
2. worst-case config-table (i.e. what we have on the sun50iw1p1): +15KB

And the config-table can easily be reduced to a more manageable size to removing clocks that we’ll never need (e.g. GPU, audio, …).

Cheers,
Philipp.