From patchwork Tue Feb 11 06:04:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1236168 X-Patchwork-Delegate: uboot@andestech.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=eiZ47jE6; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48GshH3swLz9sRN for ; Tue, 11 Feb 2020 17:05:35 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A177C80EA2; Tue, 11 Feb 2020 07:05:15 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="eiZ47jE6"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2A60480827; Tue, 11 Feb 2020 07:05:10 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8EC5480827 for ; Tue, 11 Feb 2020 07:05:03 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qk1-x742.google.com with SMTP id d11so9045235qko.8 for ; Mon, 10 Feb 2020 22:05:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=X0Ic1vRRhQDDP4gtVGyPQHAfntrFETjVTp0lbD9lIzc=; b=eiZ47jE6y74gY6LsgF3ILpX8OUfOocaoOZ4YeuYq/8xdAG6zhzltTbSA7gwXr7NjON 05tN7/4lkzgwFT46cni9E6PiGbRDMqaPsYxRF2JZtgL7cihI6UUd/l8bhlB5/H2pVabw YXHv9vp7n91g989u9Eo4jBX65JCg/cMckYgJXebSrV86c8sEavN85z/4g1D1CqLs5AJJ 9I0nORRFlUbDPscouuTqVkPdoJf1MSZ333m3uxkvonFVlf9Z4ojv4TlbtiBUk+9bJgtg 5Gox3M+PtWDC+qGRxfbDw6Zhf0bOdyJ5GTikO30pXhtmdHYtbuCwEMtnT/3OWTrjJ8tL vb/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=X0Ic1vRRhQDDP4gtVGyPQHAfntrFETjVTp0lbD9lIzc=; b=jD77RCE3ecbgJ4rB4b/aYfSyxR8+qzW/+WHbRPvKTYiaDu9WwehUgO7JsMlGjHHGpG El65QnFl6QBHXt+oh0Z8/lB5TH+8r54L+ZzDOQSxUY0cjOdjgxGFPS+42EshpRzx/4TB RU36xwDkRWLFu79i6Td2NtWOi5b/OMD0I12zMjxu/fOm6224vu/NAsjal4LAX0ACCo+f sOD+q3eIoXXB0Z7ovqH4IjbbMoMJloKd+IuuhqMeZgNkwpM+MWfCIAz6yoXMxZh13pc5 4pYFuSoMMsGm6YZ0fN7iFKuY3BrBTItFiqDTtyC7woDvhkKxaBw05Xxdnl6FBdNTuTI3 ZECQ== X-Gm-Message-State: APjAAAUmmZavWiDJOWGjwgqKrGUHBW5Qm+SGbfQBg3y9Ek5Lcau/FJI/ T2pzept5piV2zRQVwpDPVJS1Hqeg7sovwA== X-Google-Smtp-Source: APXvYqxVBFOU1jtOYueDwVHeIuHJwVarOIQMdkqSkj6PqZC7xto5Aak6ExZr/uXI5Z6etvGjSQmqSQ== X-Received: by 2002:a05:620a:210b:: with SMTP id l11mr4771818qkl.10.1581401102090; Mon, 10 Feb 2020 22:05:02 -0800 (PST) Received: from localhost.localdomain ([75.102.135.197]) by smtp.gmail.com with ESMTPSA id n4sm1497608qti.55.2020.02.10.22.05.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2020 22:05:01 -0800 (PST) From: Sean Anderson To: u-boot@lists.denx.de Subject: [PATCH v4 05/17] dm: Add support for simple-pm-bus Date: Tue, 11 Feb 2020 01:04:13 -0500 Message-Id: <20200211060425.1619471-6-seanga2@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200211060425.1619471-1-seanga2@gmail.com> References: <20200211060425.1619471-1-seanga2@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rick Chen Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.1 at phobos.denx.de X-Virus-Status: Clean 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 Reviewed-by: Simon Glass --- Changes in v4: - Split the bus off into its own driver - Add test - Fix line spacing in Kconfig - Lint Changes in v3: - New arch/sandbox/dts/test.dts | 6 ++ arch/sandbox/include/asm/clk.h | 1 + configs/sandbox_defconfig | 1 + .../bus/simple-pm-bus.txt | 44 +++++++++++++++ drivers/core/Kconfig | 7 +++ drivers/core/Makefile | 1 + drivers/core/simple-pm-bus.c | 55 +++++++++++++++++++ test/dm/Makefile | 1 + test/dm/simple-pm-bus.c | 44 +++++++++++++++ 9 files changed, 160 insertions(+) create mode 100644 doc/device-tree-bindings/bus/simple-pm-bus.txt create mode 100644 drivers/core/simple-pm-bus.c create mode 100644 test/dm/simple-pm-bus.c diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 23f2aefd43..648f21239a 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -929,6 +929,12 @@ compatible = "sandbox,mdio"; }; + pm-bus-test { + compatible = "simple-pm-bus"; + clocks = <&clk_sandbox 4>; + power-domains = <&pwrdom 1>; + }; + resetc2: syscon-reset { compatible = "syscon-reset"; #reset-cells = <1>; diff --git a/arch/sandbox/include/asm/clk.h b/arch/sandbox/include/asm/clk.h index 1573e4a134..c184c4bffc 100644 --- a/arch/sandbox/include/asm/clk.h +++ b/arch/sandbox/include/asm/clk.h @@ -21,6 +21,7 @@ enum sandbox_clk_id { SANDBOX_CLK_ID_I2C, SANDBOX_CLK_ID_UART1, SANDBOX_CLK_ID_UART2, + SANDBOX_CLK_ID_BUS, SANDBOX_CLK_ID_COUNT, }; diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 19970f1db5..c637b39b96 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -89,6 +89,7 @@ CONFIG_REGMAP=y CONFIG_SYSCON=y CONFIG_DEVRES=y CONFIG_DEBUG_DEVRES=y +CONFIG_SIMPLE_PM_BUS=y CONFIG_ADC=y CONFIG_ADC_SANDBOX=y CONFIG_AXI=y 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@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/Kconfig b/drivers/core/Kconfig index 3b95b5387b..0cd687526e 100644 --- a/drivers/core/Kconfig +++ b/drivers/core/Kconfig @@ -195,6 +195,13 @@ config SPL_SIMPLE_BUS Supports the 'simple-bus' driver, which is used on some systems in SPL. +config SIMPLE_PM_BUS + bool "Support simple-pm-bus driver" + depends on DM && OF_CONTROL && CLK && POWER_DOMAIN + help + Supports the 'simple-pm-bus' driver, which is used for busses that + have power domains and/or clocks which need to be enabled before use. + config OF_TRANSLATE bool "Translate addresses using fdt_translate_address" depends on DM && OF_CONTROL diff --git a/drivers/core/Makefile b/drivers/core/Makefile index bce7467da1..284af7caaa 100644 --- a/drivers/core/Makefile +++ b/drivers/core/Makefile @@ -6,6 +6,7 @@ obj-y += device.o fdtaddr.o lists.o root.o uclass.o util.o obj-$(CONFIG_DEVRES) += devres.o obj-$(CONFIG_$(SPL_)DM_DEVICE_REMOVE) += device-remove.o obj-$(CONFIG_$(SPL_)SIMPLE_BUS) += simple-bus.o +obj-$(CONFIG_SIMPLE_PM_BUS) += simple-pm-bus.o obj-$(CONFIG_DM) += dump.o obj-$(CONFIG_$(SPL_TPL_)REGMAP) += regmap.o obj-$(CONFIG_$(SPL_TPL_)SYSCON) += syscon-uclass.o diff --git a/drivers/core/simple-pm-bus.c b/drivers/core/simple-pm-bus.c new file mode 100644 index 0000000000..3ee54531d1 --- /dev/null +++ b/drivers/core/simple-pm-bus.c @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2020 Sean Anderson + */ + +#include +#include + +/* + * Power domains are taken care of by driver_probe, so we just have to enable + * clocks + */ +static const int simple_pm_bus_probe(struct udevice *dev) +{ + int ret; + struct clk_bulk *bulk = dev_get_priv(dev); + + 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; + } + return 0; +} + +static const int simple_pm_bus_remove(struct udevice *dev) +{ + int ret; + struct clk_bulk *bulk = dev_get_priv(dev); + + ret = clk_release_bulk(bulk); + if (ret && ret != -ENOSYS && ret != -ENOTSUPP) + return ret; + else + return 0; +} + +static const struct udevice_id simple_pm_bus_ids[] = { + { .compatible = "simple-pm-bus" }, + { } +}; + +U_BOOT_DRIVER(simple_pm_bus_drv) = { + .name = "simple_pm_bus", + .id = UCLASS_SIMPLE_BUS, + .of_match = simple_pm_bus_ids, + .probe = simple_pm_bus_probe, + .remove = simple_pm_bus_remove, + .priv_auto_alloc_size = sizeof(struct clk_bulk), + .flags = DM_FLAG_PRE_RELOC, +}; diff --git a/test/dm/Makefile b/test/dm/Makefile index 1f0e0febb4..a760ab8b14 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -71,4 +71,5 @@ obj-$(CONFIG_DM_MDIO) += mdio.o obj-$(CONFIG_DM_MDIO_MUX) += mdio_mux.o obj-$(CONFIG_DM_RNG) += rng.o obj-$(CONFIG_RESET_SYSCON) += syscon-reset.o +obj-$(CONFIG_SIMPLE_PM_BUS) += simple-pm-bus.o endif diff --git a/test/dm/simple-pm-bus.c b/test/dm/simple-pm-bus.c new file mode 100644 index 0000000000..1b42415ccd --- /dev/null +++ b/test/dm/simple-pm-bus.c @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2020 Sean Anderson + */ + +#include +#include +#include +#include +#include +#include + +/* These must match the ids in the device tree */ +#define TEST_CLOCK_ID 4 +#define TEST_POWER_ID 1 + +static int dm_test_simple_pm_bus(struct unit_test_state *uts) +{ + struct udevice *power; + struct udevice *clock; + struct udevice *bus; + + ut_assertok(uclass_get_device_by_name(UCLASS_POWER_DOMAIN, + "power-domain", &power)); + ut_assertok(uclass_get_device_by_name(UCLASS_CLK, "clk-sbox", + &clock)); + ut_asserteq(0, sandbox_power_domain_query(power, TEST_POWER_ID)); + ut_asserteq(0, sandbox_clk_query_enable(clock, TEST_CLOCK_ID)); + + ut_assertok(uclass_get_device_by_name(UCLASS_SIMPLE_BUS, "pm-bus-test", + &bus)); + ut_asserteq(1, sandbox_power_domain_query(power, TEST_POWER_ID)); + ut_asserteq(1, sandbox_clk_query_enable(clock, TEST_CLOCK_ID)); + + ut_assertok(device_remove(bus, DM_REMOVE_NORMAL)); + /* must re-probe since device_remove also removes the power domain */ + ut_assertok(uclass_get_device_by_name(UCLASS_POWER_DOMAIN, + "power-domain", &power)); + ut_asserteq(0, sandbox_power_domain_query(power, TEST_POWER_ID)); + ut_asserteq(0, sandbox_clk_query_enable(clock, TEST_CLOCK_ID)); + + return 0; +} +DM_TEST(dm_test_simple_pm_bus, DM_TESTF_SCAN_FDT);