From: Dario Binacchi <dariobin@libero.it>
To: u-boot@lists.denx.de
Subject: [PATCH v3 03/27] bus: ti: add minimal sysc interconnect target driver
Date: Sun, 11 Oct 2020 14:13:16 +0200 [thread overview]
Message-ID: <20201011121340.21660-4-dariobin@libero.it> (raw)
In-Reply-To: <20201011121340.21660-1-dariobin@libero.it>
We can handle the sysc interconnect target module in a generic way for
many TI SoCs. Initially let's just enable domain clocks before the
children are probed.
The code is loosely based on the drivers/bus/ti-sysc.c of the Linux
kernel version 5.9-rc7.
For DT binding details see:
- Documentation/devicetree/bindings/bus/ti-sysc.txt
Signed-off-by: Dario Binacchi <dariobin@libero.it>
---
(no changes since v1)
arch/arm/Kconfig | 1 +
drivers/bus/Kconfig | 7 ++
drivers/bus/Makefile | 1 +
drivers/bus/ti-sysc.c | 165 ++++++++++++++++++++++++++++++++++++++++++
4 files changed, 174 insertions(+)
create mode 100644 drivers/bus/ti-sysc.c
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index a067a07676..1da101e636 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -799,6 +799,7 @@ config ARCH_OMAP2PLUS
select SPL_BOARD_INIT if SPL
select SPL_STACK_R if SPL
select SUPPORT_SPL
+ select TI_SYSC
imply FIT
config ARCH_MESON
diff --git a/drivers/bus/Kconfig b/drivers/bus/Kconfig
index 07a33c6287..733bec5a56 100644
--- a/drivers/bus/Kconfig
+++ b/drivers/bus/Kconfig
@@ -5,6 +5,13 @@
menu "Bus devices"
+config TI_SYSC
+ bool "TI sysc interconnect target module driver"
+ depends on ARCH_OMAP2PLUS
+ help
+ Generic driver for Texas Instruments interconnect target module
+ found on many TI SoCs.
+
config UNIPHIER_SYSTEM_BUS
bool "UniPhier System Bus driver"
depends on ARCH_UNIPHIER
diff --git a/drivers/bus/Makefile b/drivers/bus/Makefile
index 0b97fc1f8b..875bb4ed42 100644
--- a/drivers/bus/Makefile
+++ b/drivers/bus/Makefile
@@ -3,4 +3,5 @@
# Makefile for the bus drivers.
#
+obj-$(CONFIG_TI_SYSC) += ti-sysc.o
obj-$(CONFIG_UNIPHIER_SYSTEM_BUS) += uniphier-system-bus.o
diff --git a/drivers/bus/ti-sysc.c b/drivers/bus/ti-sysc.c
new file mode 100644
index 0000000000..44898e356e
--- /dev/null
+++ b/drivers/bus/ti-sysc.c
@@ -0,0 +1,165 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Texas Instruments sysc interconnect target driver
+ *
+ * Copyright (C) 2020 Dario Binacchi <dariobin@libero.it>
+ */
+
+#include <common.h>
+#include <clk.h>
+#include <dm.h>
+
+enum ti_sysc_clocks {
+ TI_SYSC_FCK,
+ TI_SYSC_ICK,
+ TI_SYSC_MAX_CLOCKS,
+};
+
+static const char *const clock_names[] = {"fck", "ick"};
+
+struct ti_sysc_priv {
+ int clocks_count;
+ struct clk clocks[TI_SYSC_MAX_CLOCKS];
+};
+
+static const struct udevice_id ti_sysc_ids[] = {
+ {.compatible = "ti,sysc-omap2"},
+ {.compatible = "ti,sysc-omap4"},
+ {.compatible = "ti,sysc-omap4-simple"},
+ {.compatible = "ti,sysc-omap3430-sr"},
+ {.compatible = "ti,sysc-omap3630-sr"},
+ {.compatible = "ti,sysc-omap4-sr"},
+ {.compatible = "ti,sysc-omap3-sham"},
+ {.compatible = "ti,sysc-omap-aes"},
+ {.compatible = "ti,sysc-mcasp"},
+ {.compatible = "ti,sysc-usb-host-fs"},
+ {}
+};
+
+static int ti_sysc_get_one_clock(struct udevice *dev, enum ti_sysc_clocks index)
+{
+ struct ti_sysc_priv *priv = dev_get_priv(dev);
+ const char *name;
+ int err;
+
+ switch (index) {
+ case TI_SYSC_FCK:
+ break;
+ case TI_SYSC_ICK:
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ name = clock_names[index];
+
+ err = clk_get_by_name(dev, name, &priv->clocks[index]);
+ if (err) {
+ if (err == -ENODATA)
+ return 0;
+
+ dev_err(dev, "failed to get %s clock\n", name);
+ return err;
+ }
+
+ return 0;
+}
+
+static int ti_sysc_put_clocks(struct udevice *dev)
+{
+ struct ti_sysc_priv *priv = dev_get_priv(dev);
+ int err;
+
+ err = clk_release_all(priv->clocks, priv->clocks_count);
+ if (err)
+ dev_err(dev, "failed to release all clocks\n");
+
+ return err;
+}
+
+static int ti_sysc_get_clocks(struct udevice *dev)
+{
+ struct ti_sysc_priv *priv = dev_get_priv(dev);
+ int i, err;
+
+ for (i = 0; i < TI_SYSC_MAX_CLOCKS; i++) {
+ err = ti_sysc_get_one_clock(dev, i);
+ if (!err)
+ priv->clocks_count++;
+ else if (err != -ENOENT)
+ return err;
+ }
+
+ return 0;
+}
+
+static int ti_sysc_child_post_remove(struct udevice *dev)
+{
+ struct ti_sysc_priv *priv = dev_get_priv(dev->parent);
+ int i, err;
+
+ for (i = 0; i < priv->clocks_count; i++) {
+ err = clk_disable(&priv->clocks[i]);
+ if (err) {
+ dev_err(dev->parent, "failed to disable %s clock\n",
+ clock_names[i]);
+ return err;
+ }
+ }
+
+ return 0;
+}
+
+static int ti_sysc_child_pre_probe(struct udevice *dev)
+{
+ struct ti_sysc_priv *priv = dev_get_priv(dev->parent);
+ int i, err;
+
+ for (i = 0; i < priv->clocks_count; i++) {
+ err = clk_enable(&priv->clocks[i]);
+ if (err) {
+ dev_err(dev->parent, "failed to enable %s clock\n",
+ clock_names[i]);
+ return err;
+ }
+ }
+
+ return 0;
+}
+
+static int ti_sysc_remove(struct udevice *dev)
+{
+ return ti_sysc_put_clocks(dev);
+}
+
+static int ti_sysc_probe(struct udevice *dev)
+{
+ int err;
+
+ err = ti_sysc_get_clocks(dev);
+ if (err)
+ goto clocks_err;
+
+ return 0;
+
+clocks_err:
+ ti_sysc_put_clocks(dev);
+ return err;
+}
+
+UCLASS_DRIVER(ti_sysc) = {
+ .id = UCLASS_SIMPLE_BUS,
+ .name = "ti_sysc",
+ .post_bind = dm_scan_fdt_dev
+};
+
+U_BOOT_DRIVER(ti_sysc) = {
+ .name = "ti_sysc",
+ .id = UCLASS_SIMPLE_BUS,
+ .of_match = ti_sysc_ids,
+ .probe = ti_sysc_probe,
+ .remove = ti_sysc_remove,
+ .child_pre_probe = ti_sysc_child_pre_probe,
+ .child_post_remove = ti_sysc_child_post_remove,
+ .priv_auto_alloc_size = sizeof(struct ti_sysc_priv)
+};
--
2.17.1
next prev parent reply other threads:[~2020-10-11 12:13 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-11 12:13 [PATCH v3 00/27] Add DM support for omap PWM backlight Dario Binacchi
2020-10-11 12:13 ` [PATCH v3 01/27] clk: export generic routines Dario Binacchi
2020-10-11 12:13 ` [PATCH v3 02/27] dt-bindings: bus: ti-sysc: resync with Linux 5.9-rc7 Dario Binacchi
2020-10-11 12:13 ` Dario Binacchi [this message]
2020-10-11 12:13 ` [PATCH v3 04/27] arm: dts: sync am33xx " Dario Binacchi
2020-10-11 12:13 ` [PATCH v3 05/27] clk: add clk_round_rate() Dario Binacchi
2020-10-11 12:26 ` Sean Anderson
2020-10-11 12:13 ` [PATCH v3 06/27] clk: ti: add mux clock driver Dario Binacchi
2020-10-11 12:13 ` [PATCH v3 07/27] arm: ti: am33xx: add DPLL_EN_FAST_RELOCK_BYPASS macro Dario Binacchi
2020-10-11 12:13 ` [PATCH v3 08/27] clk: ti: am33xx: add DPLL clock drivers Dario Binacchi
2020-10-11 12:13 ` [PATCH v3 09/27] clk: ti: add divider clock driver Dario Binacchi
2020-10-11 12:13 ` [PATCH v3 10/27] clk: ti: add gate " Dario Binacchi
2020-10-11 12:13 ` [PATCH v3 11/27] ti: am33xx: fix do_enable_clocks() to accept NULL parameters Dario Binacchi
2020-10-11 12:13 ` [PATCH v3 12/27] clk: ti: add support for clkctrl clocks Dario Binacchi
2020-10-11 12:13 ` [PATCH v3 13/27] clk: ti: move drivers to 'ti' directory Dario Binacchi
2020-10-11 12:13 ` [PATCH v3 14/27] clk: ti: omap4: add clock manager driver Dario Binacchi
2020-10-11 12:13 ` [PATCH v3 15/27] clk: ti: am335x: " Dario Binacchi
2020-10-11 12:13 ` [PATCH v3 16/27] fdt: translate address if #size-cells = <0> Dario Binacchi
2020-10-11 12:13 ` [PATCH v3 17/27] omap: timer: fix the rate setting Dario Binacchi
2020-10-11 12:13 ` [PATCH v3 18/27] misc: am33xx: add control module driver Dario Binacchi
2020-10-14 8:22 ` [PATCH v3 00/27] Add DM support for omap PWM backlight Felix Brack
2020-10-14 21:22 ` Dario Binacchi
2020-10-15 8:53 ` Felix Brack
2020-10-15 18:56 ` Dario Binacchi
2020-10-16 8:41 ` Felix Brack
2020-10-16 20:31 ` Dario Binacchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201011121340.21660-4-dariobin@libero.it \
--to=dariobin@libero.it \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox