From patchwork Thu May 9 15:31:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 13659824 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D19A9C25B10 for ; Thu, 9 May 2024 15:31:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=a+QUrHqwqxTttVXISRmyHPhUoX4uUarMahNEgwypGmk=; b=L5Fghcnxm9VMB+ qu3CzQZ4hUskyVwpb0Y/MDPKSr5uvfA9SiVpKpoP6rtlPlgwnRQOeuFnzvkX8TeUW0ERfHSr9apmo bvyUfTL5g5hMC7IWtDUhaiSH+HpsgnCmF3e0hplqxtGKFCHx81kDUguKp+1q6Bzc9Y8Eg8+TfW4Mn OAhawsZ0twRRBmU1l/nVJ1o0adsoHT3BUA9+StkLppOyQRYkRQmde0O0lsPr4XsNN/FrHB2R4gljI yQWaU3YtnW0gZz5UVWAOV6R/XWUbNTT33tBunzpq+puDU08hSAd7zochM9aMuEOjmJKouryAo869Y Unek/6Rdx5feDYPgyf5A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s55js-00000001tnY-0d27; Thu, 09 May 2024 15:31:20 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s55jp-00000001tmc-1SWE for linux-arm-kernel@lists.infradead.org; Thu, 09 May 2024 15:31:18 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 67C9B61D79; Thu, 9 May 2024 15:31:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 14375C116B1; Thu, 9 May 2024 15:31:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715268676; bh=Mk/kaGfo1nd9dUr4W4lbqu4SomACMK5r/e5cywhFtl8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ADaZwSgZJu7O+aKWRjHMGcfG9AvFhTn6OAghl0gAx0X3BNJ2bRiqEBawS3yHds1RA ubwlqC3kioPCC3+bmJkNnBG2CNytIRRM8aCxjhcCAFdsJUxV2GNnujGAPBiGBtWDSt 8XTXp1Yc5J3XXn/hPeUnKp4AJpj0e+Oa6AgE0iBdzjvGxIxyQRB6olbqYI/HrJnuVl JZdnE5/nSxjOuBpKQ2BCMu/M+HSryBK9NGuRyIRklgB0O3s8YoJFzGKP8fYncPQgvh txjHINbkPy7x5AyhS6K1qmQ9AszIaJx+2VoUINt/yEFlF89mngXSEfq1Dj1C53Ugvy mnmS4sYZcRdLw== Received: by wens.tw (Postfix, from userid 1000) id AD61C5F9B4; Thu, 9 May 2024 23:31:13 +0800 (CST) From: Chen-Yu Tsai To: Mark Brown Cc: Samuel Holland , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jernej Skrabec , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, Krzysztof Kozlowski , Chen-Yu Tsai Subject: [PATCH v6 1/2] regulator: dt-bindings: Add Allwinner D1 system LDOs Date: Thu, 9 May 2024 23:31:06 +0800 Message-Id: <20240509153107.438220-2-wens@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240509153107.438220-1-wens@kernel.org> References: <20240509153107.438220-1-wens@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240509_083117_452664_515BA63D X-CRM114-Status: GOOD ( 11.67 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Samuel Holland The Allwinner D1 SoC contains two pairs of in-package LDOs. The pair of "system" LDOs is for general purpose use. LDOA generally powers the board's 1.8 V rail. LDOB powers the in-package DRAM, where applicable. Reviewed-by: Krzysztof Kozlowski Signed-off-by: Samuel Holland Signed-off-by: Chen-Yu Tsai --- .../allwinner,sun20i-d1-system-ldos.yaml | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Documentation/devicetree/bindings/regulator/allwinner,sun20i-d1-system-ldos.yaml diff --git a/Documentation/devicetree/bindings/regulator/allwinner,sun20i-d1-system-ldos.yaml b/Documentation/devicetree/bindings/regulator/allwinner,sun20i-d1-system-ldos.yaml new file mode 100644 index 000000000000..ec6695c8d2e3 --- /dev/null +++ b/Documentation/devicetree/bindings/regulator/allwinner,sun20i-d1-system-ldos.yaml @@ -0,0 +1,37 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/regulator/allwinner,sun20i-d1-system-ldos.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Allwinner D1 System LDOs + +maintainers: + - Samuel Holland + +description: + Allwinner D1 contains a pair of general-purpose LDOs which are designed to + supply power inside and outside the SoC. They are controlled by a register + within the system control MMIO space. + +properties: + compatible: + enum: + - allwinner,sun20i-d1-system-ldos + + reg: + maxItems: 1 + +patternProperties: + "^ldo[ab]$": + type: object + $ref: regulator.yaml# + unevaluatedProperties: false + +required: + - compatible + - reg + +additionalProperties: false + +... From patchwork Thu May 9 15:31:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 13659825 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 673EAC10F1A for ; Thu, 9 May 2024 15:31:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=yvwhZanlaAXoM4uVahL8fLfF6k9wM/bob9oAd7HGt6U=; b=yCqrqZcp8Vvz2N UwPHpidQXBWQqGuIzuS1TBNe9nbnZ0nsXKQWXRm6Dscl1mtlO8y7fwKOI9gxorH2TB8/FChLLeXT/ CaQMWYbRYRZfyBLNde0ghtItnOyfUKD7dOIutOeLo/1PydVG0HmFuucL7NV/ZMeJT4PbW2wwX1flb B9xEf0X8qLV6UfkuKT+3mfwdL0E0NR2J53ZBi5xR+gOlkGS9y0PUIW6PZ847Dywso2Pkvy/LSjqnm W709rT4O+s8VyagkdN+JF2kc80fkO1/QxHTpr1ZtT6wauS1d0KrXbwbuuQK3Yc08bDE9b571YPsSj GAbazgLmOtEilrcyE3zA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s55jr-00000001tnS-29Xd; Thu, 09 May 2024 15:31:19 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s55jp-00000001tmd-1SMq for linux-arm-kernel@lists.infradead.org; Thu, 09 May 2024 15:31:18 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id A2BF761D7F; Thu, 9 May 2024 15:31:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 256F8C4AF0B; Thu, 9 May 2024 15:31:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715268676; bh=6dJFzoz5/zPfJ2iN6WbR60T4ax8pQQwJWw+X5KaXXVM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kRya/aK2RBV9u5OnjE/IwaEJG7bykOEM9DXVA/obwlUPNN0NTHgsBY+8B8V3bOljW D3PZzukHqR7s+Q0qujXF8jQR5Bu+BAy/BQCR3Yzt4VKAhx31Ytu5nqduqPt59PrJEk BzOPKmDLQ49Hsytwea0qHLHilTsFsOVqp8IFVgn41X0iXiofWJzth6INYNWbQh9NEb 9ZbY/hGReOUWR9ezk0iaanZeKdgQjSbPp3PNWINLMDDT7EayWHBMuZapN5h8kHs/MN 3xmSqn7ZgYMmt4m6pz+nF84/GYPJyGv3HLv2xtKE21oifKoSQP6E9YemOt0Y8O7C8q a+5Th+alpxFWQ== Received: by wens.tw (Postfix, from userid 1000) id BB4A95FD4B; Thu, 9 May 2024 23:31:13 +0800 (CST) From: Chen-Yu Tsai To: Mark Brown Cc: Samuel Holland , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jernej Skrabec , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, Andre Przywara , Chen-Yu Tsai Subject: [PATCH v6 2/2] regulator: sun20i: Add Allwinner D1 LDOs driver Date: Thu, 9 May 2024 23:31:07 +0800 Message-Id: <20240509153107.438220-3-wens@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240509153107.438220-1-wens@kernel.org> References: <20240509153107.438220-1-wens@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240509_083117_500601_F975E29C X-CRM114-Status: GOOD ( 24.77 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Samuel Holland D1 contains two pairs of LDOs, "analog" LDOs and "system" LDOs. They are similar and can share a driver, but only the system LDOs have a DT binding defined so far. The system LDOs have a single linear range. The voltage step is not an integer, so a custom .list_voltage is needed to get the rounding right. Signed-off-by: Samuel Holland Reviewed-by: Andre Przywara Reviewed-by: Jernej Skrabec Signed-off-by: Chen-Yu Tsai --- drivers/regulator/Kconfig | 8 ++ drivers/regulator/Makefile | 1 + drivers/regulator/sun20i-regulator.c | 157 +++++++++++++++++++++++++++ 3 files changed, 166 insertions(+) create mode 100644 drivers/regulator/sun20i-regulator.c diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index 7db0a29b5b8d..acdb02a4ac0c 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -1415,6 +1415,14 @@ config REGULATOR_STW481X_VMMC This driver supports the internal VMMC regulator in the STw481x PMIC chips. +config REGULATOR_SUN20I + tristate "Allwinner D1 internal LDOs" + depends on ARCH_SUNXI || COMPILE_TEST + select MFD_SYSCON + default ARCH_SUNXI + help + This driver supports the internal LDOs in the Allwinner D1 SoC. + config REGULATOR_SY7636A tristate "Silergy SY7636A voltage regulator" depends on MFD_SY7636A diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index 46fb569e6be8..ba15fa5f30ad 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -163,6 +163,7 @@ obj-$(CONFIG_REGULATOR_STM32_VREFBUF) += stm32-vrefbuf.o obj-$(CONFIG_REGULATOR_STM32_PWR) += stm32-pwr.o obj-$(CONFIG_REGULATOR_STPMIC1) += stpmic1_regulator.o obj-$(CONFIG_REGULATOR_STW481X_VMMC) += stw481x-vmmc.o +obj-$(CONFIG_REGULATOR_SUN20I) += sun20i-regulator.o obj-$(CONFIG_REGULATOR_SY7636A) += sy7636a-regulator.o obj-$(CONFIG_REGULATOR_SY8106A) += sy8106a-regulator.o obj-$(CONFIG_REGULATOR_SY8824X) += sy8824x.o diff --git a/drivers/regulator/sun20i-regulator.c b/drivers/regulator/sun20i-regulator.c new file mode 100644 index 000000000000..e09be44859e7 --- /dev/null +++ b/drivers/regulator/sun20i-regulator.c @@ -0,0 +1,157 @@ +// SPDX-License-Identifier: GPL-2.0-only +// +// Copyright (c) 2021-2022 Samuel Holland +// + +#include +#include +#include +#include +#include +#include +#include + +#define SUN20I_SYS_LDO_CTRL_REG 0x150 + +struct sun20i_regulator_data { + const struct regulator_desc *descs; + unsigned int ndescs; +}; + +/* regulator_list_voltage_linear() modified for the non-integral uV_step. */ +static int sun20i_d1_system_ldo_list_voltage(struct regulator_dev *rdev, + unsigned int selector) +{ + const struct regulator_desc *desc = rdev->desc; + unsigned int fraction, uV; + + if (selector >= desc->n_voltages) + return -EINVAL; + + uV = desc->min_uV + (desc->uV_step * selector); + fraction = selector + (desc->min_uV % 4); + + if (uV > 1606667) + uV += 6667; + else + fraction++; + + /* Produce correctly-rounded absolute voltages. */ + return uV + (fraction / 3); +} + +static const struct regulator_ops sun20i_d1_system_ldo_ops = { + .list_voltage = sun20i_d1_system_ldo_list_voltage, + .map_voltage = regulator_map_voltage_ascend, + .set_voltage_sel = regulator_set_voltage_sel_regmap, + .get_voltage_sel = regulator_get_voltage_sel_regmap, +}; + +static const struct regulator_desc sun20i_d1_system_ldo_descs[] = { + { + .name = "ldoa", + .supply_name = "ldo-in", + .of_match = "ldoa", + .ops = &sun20i_d1_system_ldo_ops, + .type = REGULATOR_VOLTAGE, + .owner = THIS_MODULE, + .n_voltages = 32, + .min_uV = 1593333, + .uV_step = 13333, /* repeating */ + .vsel_reg = SUN20I_SYS_LDO_CTRL_REG, + .vsel_mask = GENMASK(7, 0), + }, + { + .name = "ldob", + .supply_name = "ldo-in", + .of_match = "ldob", + .ops = &sun20i_d1_system_ldo_ops, + .type = REGULATOR_VOLTAGE, + .owner = THIS_MODULE, + .n_voltages = 64, + .min_uV = 1166666, + .uV_step = 13333, /* repeating */ + .vsel_reg = SUN20I_SYS_LDO_CTRL_REG, + .vsel_mask = GENMASK(15, 8), + }, +}; + +static const struct sun20i_regulator_data sun20i_d1_system_ldos = { + .descs = sun20i_d1_system_ldo_descs, + .ndescs = ARRAY_SIZE(sun20i_d1_system_ldo_descs), +}; + +static struct regmap *sun20i_regulator_get_regmap(struct device *dev) +{ + struct regmap *regmap; + + /* + * First try the syscon interface. The system control device is not + * compatible with "syscon", so fall back to getting the regmap from + * its platform device. This is ugly, but required for devicetree + * backward compatibility. + */ + regmap = syscon_node_to_regmap(dev->parent->of_node); + if (!IS_ERR(regmap)) + return regmap; + + regmap = dev_get_regmap(dev->parent, NULL); + if (regmap) + return regmap; + + return ERR_PTR(-EPROBE_DEFER); +} + +static int sun20i_regulator_probe(struct platform_device *pdev) +{ + const struct sun20i_regulator_data *data; + struct device *dev = &pdev->dev; + struct regulator_config config; + struct regmap *regmap; + + data = of_device_get_match_data(dev); + if (!data) + return -EINVAL; + + regmap = sun20i_regulator_get_regmap(dev); + if (IS_ERR(regmap)) + return dev_err_probe(dev, PTR_ERR(regmap), "Failed to get regmap\n"); + + config = (struct regulator_config) { + .dev = dev, + .regmap = regmap, + }; + + for (unsigned int i = 0; i < data->ndescs; ++i) { + const struct regulator_desc *desc = &data->descs[i]; + struct regulator_dev *rdev; + + rdev = devm_regulator_register(dev, desc, &config); + if (IS_ERR(rdev)) + return PTR_ERR(rdev); + } + + return 0; +} + +static const struct of_device_id sun20i_regulator_of_match[] = { + { + .compatible = "allwinner,sun20i-d1-system-ldos", + .data = &sun20i_d1_system_ldos, + }, + { }, +}; +MODULE_DEVICE_TABLE(of, sun20i_regulator_of_match); + +static struct platform_driver sun20i_regulator_driver = { + .probe = sun20i_regulator_probe, + .driver = { + .name = "sun20i-regulator", + .of_match_table = sun20i_regulator_of_match, + }, +}; +module_platform_driver(sun20i_regulator_driver); + +MODULE_AUTHOR("Samuel Holland "); +MODULE_DESCRIPTION("Allwinner D1 internal LDO driver"); +MODULE_LICENSE("GPL");