diff mbox series

[v3,05/12] dm: Add support for simple-pm-bus

Message ID 3b86c607-9616-8e3e-b6af-e4064c7e5782@gmail.com
State New
Headers show
Series riscv: Add Sipeed Maix support | expand

Commit Message

Sean Anderson Feb. 2, 2020, 8:02 p.m. UTC
This type of bus is used in Linux to designate busses which have power domains
and/or clocks which need to be enabled before their child devices can be used.
Because power domains are automatically enabled before probing in u-boot, we
just need to enable any clocks present.

Signed-off-by: Sean Anderson <seanga2 at gmail.com>
---
  Changes for v3:
  - New

 .../bus/simple-pm-bus.txt                     | 44 ++++++++++++++
 drivers/core/simple-bus.c                     | 57 ++++++++++++++++++-
 2 files changed, 99 insertions(+), 2 deletions(-)
 create mode 100644 doc/device-tree-bindings/bus/simple-pm-bus.txt

Comments

Simon Glass Feb. 3, 2020, 12:04 a.m. UTC | #1
Hi Sean,

On Sun, 2 Feb 2020 at 13:02, Sean Anderson <seanga2 at gmail.com> wrote:
>
> This type of bus is used in Linux to designate busses which have power domains
> and/or clocks which need to be enabled before their child devices can be used.
> Because power domains are automatically enabled before probing in u-boot, we
> just need to enable any clocks present.
>
> Signed-off-by: Sean Anderson <seanga2 at gmail.com>
> ---
>   Changes for v3:
>   - New
>
>  .../bus/simple-pm-bus.txt                     | 44 ++++++++++++++
>  drivers/core/simple-bus.c                     | 57 ++++++++++++++++++-
>  2 files changed, 99 insertions(+), 2 deletions(-)
>  create mode 100644 doc/device-tree-bindings/bus/simple-pm-bus.txt

Please can you add a test for this new functionality?

Thanks,
Simon
Sean Anderson Feb. 3, 2020, 11:15 p.m. UTC | #2
> Please can you add a test for this new functionality?

Should this be separate from test/dm/bus.c? As far as I can tell, that
file tests the concept of busses, and not the bus uclass.

--Sean
Bin Meng Feb. 4, 2020, 11:13 a.m. UTC | #3
On Mon, Feb 3, 2020 at 4:02 AM Sean Anderson <seanga2 at gmail.com> wrote:
>
> This type of bus is used in Linux to designate busses which have power domains
> and/or clocks which need to be enabled before their child devices can be used.
> Because power domains are automatically enabled before probing in u-boot, we
> just need to enable any clocks present.
>
> Signed-off-by: Sean Anderson <seanga2 at gmail.com>
> ---
>   Changes for v3:
>   - New
>
>  .../bus/simple-pm-bus.txt                     | 44 ++++++++++++++
>  drivers/core/simple-bus.c                     | 57 ++++++++++++++++++-
>  2 files changed, 99 insertions(+), 2 deletions(-)
>  create mode 100644 doc/device-tree-bindings/bus/simple-pm-bus.txt
>

Reviewed-by: Bin Meng <bmeng.cn at gmail.com>
Simon Glass Feb. 5, 2020, 12:16 a.m. UTC | #4
Hi Sean,

On Mon, 3 Feb 2020 at 16:15, Sean Anderson <seanga2 at gmail.com> wrote:
>
> > Please can you add a test for this new functionality?
>
> Should this be separate from test/dm/bus.c? As far as I can tell, that
> file tests the concept of busses, and not the bus uclass.

Yes it is fine to add a test/dm/simple-bus.c

Regards,
Simon
diff mbox series

Patch

diff --git a/doc/device-tree-bindings/bus/simple-pm-bus.txt b/doc/device-tree-bindings/bus/simple-pm-bus.txt
new file mode 100644
index 0000000000..6f15037131
--- /dev/null
+++ b/doc/device-tree-bindings/bus/simple-pm-bus.txt
@@ -0,0 +1,44 @@ 
+Simple Power-Managed Bus
+========================
+
+A Simple Power-Managed Bus is a transparent bus that doesn't need a real
+driver, as it's typically initialized by the boot loader.
+
+However, its bus controller is part of a PM domain, or under the control of a
+functional clock.  Hence, the bus controller's PM domain and/or clock must be
+enabled for child devices connected to the bus (either on-SoC or externally)
+to function.
+
+While "simple-pm-bus" follows the "simple-bus" set of properties, as specified
+in the Devicetree Specification, it is not an extension of "simple-bus".
+
+
+Required properties:
+  - compatible: Must contain at least "simple-pm-bus".
+		Must not contain "simple-bus".
+		It's recommended to let this be preceded by one or more
+		vendor-specific compatible values.
+  - #address-cells, #size-cells, ranges: Must describe the mapping between
+		parent address and child address spaces.
+
+Optional platform-specific properties for clock or PM domain control (at least
+one of them is required):
+  - clocks: Must contain a reference to the functional clock(s),
+  - power-domains: Must contain a reference to the PM domain.
+Please refer to the binding documentation for the clock and/or PM domain
+providers for more details.
+
+
+Example:
+
+	bsc: bus at fec10000 {
+		compatible = "renesas,bsc-sh73a0", "renesas,bsc",
+			     "simple-pm-bus";
+		#address-cells = <1>;
+		#size-cells = <1>;
+		ranges = <0 0 0x20000000>;
+		reg = <0xfec10000 0x400>;
+		interrupts = <0 39 IRQ_TYPE_LEVEL_HIGH>;
+		clocks = <&zb_clk>;
+		power-domains = <&pd_a4s>;
+	};
diff --git a/drivers/core/simple-bus.c b/drivers/core/simple-bus.c
index 7fc23ef82d..d94567e98d 100644
--- a/drivers/core/simple-bus.c
+++ b/drivers/core/simple-bus.c
@@ -5,6 +5,11 @@ 
 
 #include <common.h>
 #include <dm.h>
+#include <clk.h>
+
+#define SIMPLE_BUS 0
+#define SIMPLE_MFD 1
+#define SIMPLE_PM_BUS 2
 
 struct simple_bus_plat {
 	u32 base;
@@ -50,9 +55,55 @@  UCLASS_DRIVER(simple_bus) = {
 	.per_device_platdata_auto_alloc_size = sizeof(struct simple_bus_plat),
 };
 
+static const int generic_simple_bus_probe(struct udevice *dev)
+{
+#if CONFIG_IS_ENABLED(CLK)
+	int ret;
+	struct clk_bulk *bulk;
+	ulong type = dev_get_driver_data(dev);
+
+	if (type == SIMPLE_PM_BUS) {
+		bulk = kzalloc(sizeof(*bulk), GFP_KERNEL);
+		if (!bulk)
+			return -ENOMEM;
+
+		ret = clk_get_bulk(dev, bulk);
+		if (ret)
+			return ret;
+		
+		ret = clk_enable_bulk(bulk);
+		if (ret && ret != -ENOSYS && ret != -ENOTSUPP) {
+			clk_release_bulk(bulk);
+			return ret;
+		}
+		dev->priv = bulk;
+	}
+#endif
+	return 0;
+}
+
+static const int generic_simple_bus_remove(struct udevice *dev)
+{
+	int ret = 0;
+#if CONFIG_IS_ENABLED(CLK)
+	struct clk_bulk *bulk;
+	ulong type = dev_get_driver_data(dev);
+
+	if (type == SIMPLE_PM_BUS) {
+		bulk = dev_get_priv(dev);
+		ret = clk_release_bulk(bulk);
+		kfree(bulk);
+		if (ret == -ENOSYS)
+			ret = 0;
+	}
+#endif
+	return ret;
+}
+
 static const struct udevice_id generic_simple_bus_ids[] = {
-	{ .compatible = "simple-bus" },
-	{ .compatible = "simple-mfd" },
+	{ .compatible = "simple-bus", .data = SIMPLE_BUS },
+	{ .compatible = "simple-mfd", .data = SIMPLE_MFD },
+	{ .compatible = "simple-pm-bus", .data = SIMPLE_PM_BUS },
 	{ }
 };
 
@@ -60,5 +111,7 @@  U_BOOT_DRIVER(simple_bus_drv) = {
 	.name	= "generic_simple_bus",
 	.id	= UCLASS_SIMPLE_BUS,
 	.of_match = generic_simple_bus_ids,
+	.probe = generic_simple_bus_probe,
+	.remove = generic_simple_bus_remove,
 	.flags	= DM_FLAG_PRE_RELOC,
 };