From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: barebox@lists.infradead.org
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>
Subject: [PATCH 07/21] regulator: Port ANATOP driver from Linux
Date: Tue, 8 Jan 2019 23:11:56 -0800 [thread overview]
Message-ID: <20190109071210.18896-8-andrew.smirnov@gmail.com> (raw)
In-Reply-To: <20190109071210.18896-1-andrew.smirnov@gmail.com>
Port a subset of Linux driver sufficient enough to support feature
needed for PCIe on i.MX7.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
drivers/regulator/Kconfig | 8 ++
drivers/regulator/Makefile | 3 +-
drivers/regulator/anatop-regulator.c | 161 +++++++++++++++++++++++++++
3 files changed, 171 insertions(+), 1 deletion(-)
create mode 100644 drivers/regulator/anatop-regulator.c
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 92db8dc0e..c734ef5ef 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -21,4 +21,12 @@ config REGULATOR_PFUZE
depends on I2C
depends on ARCH_IMX6
+config REGULATOR_ANATOP
+ tristate "Freescale i.MX on-chip ANATOP LDO regulators"
+ depends on MFD_SYSCON
+ help
+ Say y here to support Freescale i.MX on-chip ANATOP LDOs
+ regulators. It is recommended that this option be
+ enabled on i.MX6 platform.
+
endif
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 36ce3e87f..b2fc5b79b 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -1,4 +1,5 @@
obj-$(CONFIG_REGULATOR) += core.o helpers.o
obj-$(CONFIG_REGULATOR_FIXED) += fixed.o
obj-$(CONFIG_REGULATOR_BCM283X) += bcm2835.o
-obj-$(CONFIG_REGULATOR_PFUZE) += pfuze.o
\ No newline at end of file
+obj-$(CONFIG_REGULATOR_PFUZE) += pfuze.o
+obj-$(CONFIG_REGULATOR_ANATOP) += anatop-regulator.o
\ No newline at end of file
diff --git a/drivers/regulator/anatop-regulator.c b/drivers/regulator/anatop-regulator.c
new file mode 100644
index 000000000..3944fd592
--- /dev/null
+++ b/drivers/regulator/anatop-regulator.c
@@ -0,0 +1,161 @@
+/*
+ * Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights Reserved.
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <common.h>
+#include <init.h>
+#include <mfd/syscon.h>
+#include <regmap.h>
+#include <regulator.h>
+
+struct anatop_regulator {
+ u32 control_reg;
+ struct regmap *anatop;
+ int vol_bit_shift;
+ int vol_bit_width;
+ u32 delay_reg;
+ int delay_bit_shift;
+ int delay_bit_width;
+ int min_bit_val;
+ int min_voltage;
+ int max_voltage;
+
+ struct regulator_dev rdev;
+ struct regulator_desc rdesc;
+
+ bool bypass;
+ int sel;
+};
+
+static struct regulator_ops anatop_rops = {
+ .set_voltage_sel = regulator_set_voltage_sel_regmap,
+ .list_voltage = regulator_list_voltage_linear,
+};
+
+static int anatop_regulator_probe(struct device_d *dev)
+{
+ struct device_node *np = dev->device_node;
+ struct device_node *anatop_np;
+ struct regulator_desc *rdesc;
+ struct regulator_dev *rdev;
+ struct anatop_regulator *sreg;
+ int ret = 0;
+
+ sreg = xzalloc(sizeof(*sreg));
+ rdesc = &sreg->rdesc;
+ rdev = &sreg->rdev;
+
+ anatop_np = of_get_parent(np);
+ if (!anatop_np)
+ return -ENODEV;
+
+ rdev->desc = rdesc;
+ rdev->regmap = syscon_node_to_regmap(anatop_np);
+ if (IS_ERR(rdev->regmap))
+ return PTR_ERR(rdev->regmap);
+
+ ret = of_property_read_u32(np, "anatop-reg-offset",
+ &sreg->control_reg);
+ if (ret) {
+ dev_err(dev, "no anatop-reg-offset property set\n");
+ return ret;
+ }
+ ret = of_property_read_u32(np, "anatop-vol-bit-width",
+ &sreg->vol_bit_width);
+ if (ret) {
+ dev_err(dev, "no anatop-vol-bit-width property set\n");
+ return ret;
+ }
+ ret = of_property_read_u32(np, "anatop-vol-bit-shift",
+ &sreg->vol_bit_shift);
+ if (ret) {
+ dev_err(dev, "no anatop-vol-bit-shift property set\n");
+ return ret;
+ }
+ ret = of_property_read_u32(np, "anatop-min-bit-val",
+ &sreg->min_bit_val);
+ if (ret) {
+ dev_err(dev, "no anatop-min-bit-val property set\n");
+ return ret;
+ }
+ ret = of_property_read_u32(np, "anatop-min-voltage",
+ &sreg->min_voltage);
+ if (ret) {
+ dev_err(dev, "no anatop-min-voltage property set\n");
+ return ret;
+ }
+ ret = of_property_read_u32(np, "anatop-max-voltage",
+ &sreg->max_voltage);
+ if (ret) {
+ dev_err(dev, "no anatop-max-voltage property set\n");
+ return ret;
+ }
+
+ /* read LDO ramp up setting, only for core reg */
+ of_property_read_u32(np, "anatop-delay-reg-offset",
+ &sreg->delay_reg);
+ of_property_read_u32(np, "anatop-delay-bit-width",
+ &sreg->delay_bit_width);
+ of_property_read_u32(np, "anatop-delay-bit-shift",
+ &sreg->delay_bit_shift);
+
+ rdesc->n_voltages = (sreg->max_voltage - sreg->min_voltage) / 25000 + 1
+ + sreg->min_bit_val;
+ rdesc->min_uV = sreg->min_voltage;
+ rdesc->uV_step = 25000;
+ rdesc->linear_min_sel = sreg->min_bit_val;
+ rdesc->vsel_reg = sreg->control_reg;
+ rdesc->vsel_mask = GENMASK(sreg->vol_bit_width + sreg->vol_bit_shift,
+ sreg->vol_bit_shift);
+
+ /* Only core regulators have the ramp up delay configuration. */
+ if (sreg->control_reg && sreg->delay_bit_width) {
+ free(sreg);
+ return -ENODEV;
+ } else {
+ u32 enable_bit;
+
+ rdesc->ops = &anatop_rops;
+
+ if (!of_property_read_u32(np, "anatop-enable-bit",
+ &enable_bit)) {
+ anatop_rops.enable = regulator_enable_regmap;
+ anatop_rops.disable = regulator_disable_regmap;
+ anatop_rops.is_enabled = regulator_is_enabled_regmap;
+
+ rdesc->enable_reg = sreg->control_reg;
+ rdesc->enable_mask = BIT(enable_bit);
+ }
+ }
+
+ return of_regulator_register(rdev, dev->device_node);
+}
+
+static const struct of_device_id of_anatop_regulator_match_tbl[] = {
+ { .compatible = "fsl,anatop-regulator", },
+ { /* end */ }
+};
+
+static struct driver_d anatop_regulator_driver = {
+ .name = "anatop_regulator",
+ .probe = anatop_regulator_probe,
+ .of_compatible = DRV_OF_COMPAT(of_anatop_regulator_match_tbl),
+};
+device_platform_driver(anatop_regulator_driver);
+
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2019-01-09 7:12 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-09 7:11 [PATCH 00/21] PCIe support for i.MX7 Andrey Smirnov
2019-01-09 7:11 ` [PATCH 01/21] regulator: Convert drivers to use struct regulator_desc Andrey Smirnov
2019-01-09 7:11 ` [PATCH 02/21] regulator: Port basic regmap regulator functions Andrey Smirnov
2019-01-09 7:11 ` [PATCH 03/21] regulator: Add support for setting regulator's voltage Andrey Smirnov
2019-01-09 7:11 ` [PATCH 04/21] base: driver: Drop redundant list_empty() check Andrey Smirnov
2019-01-09 7:11 ` [PATCH 05/21] base: Port driver_deferred_probe_check_state() from Linux Andrey Smirnov
2019-01-09 7:11 ` [PATCH 06/21] regulator: Add primitive support for deferred probe Andrey Smirnov
2019-01-09 7:11 ` Andrey Smirnov [this message]
2019-01-09 7:11 ` [PATCH 08/21] drivers: base: Port power management code from Linux Andrey Smirnov
2019-01-09 7:11 ` [PATCH 09/21] soc: imx: Add GPCv2 power gating driver Andrey Smirnov
2019-01-09 7:11 ` [PATCH 10/21] soc: imx: gpcv2: fix regulator deferred probe Andrey Smirnov
2019-01-10 7:37 ` Sascha Hauer
2019-01-10 19:20 ` Andrey Smirnov
2019-01-09 7:12 ` [PATCH 11/21] soc: imx: gpcv2: correct PGC offset Andrey Smirnov
2019-01-09 7:12 ` [PATCH 12/21] reset: Add i.MX7 SRC reset driver Andrey Smirnov
2019-01-09 7:12 ` [PATCH 13/21] reset: imx7: Fix always writing bits as 0 Andrey Smirnov
2019-01-10 7:38 ` Sascha Hauer
2019-01-09 7:12 ` [PATCH 14/21] reset: Mark local functions as static Andrey Smirnov
2019-01-09 7:12 ` [PATCH 15/21] PCI: imx6: Add code to support i.MX7D Andrey Smirnov
2019-01-09 7:12 ` [PATCH 16/21] PCI: imx6: Allow probe deferral by reset GPIO Andrey Smirnov
2019-01-10 8:05 ` Sascha Hauer
2019-01-12 4:24 ` Andrey Smirnov
2019-01-09 7:12 ` [PATCH 17/21] PCI: imx6: Do not wait for speed change on i.MX7 Andrey Smirnov
2019-01-09 7:12 ` [PATCH 18/21] PCI: imx6: Do not switch speed if Gen2 is disabled Andrey Smirnov
2019-01-09 7:12 ` [PATCH 19/21] PCI: imx6: Fix spelling mistake: "contol" -> "control" Andrey Smirnov
2019-01-09 7:12 ` [PATCH 20/21] PCI: imx6: Drop unnecessary root_bus_nr setting Andrey Smirnov
2019-01-09 7:12 ` [PATCH 21/21] PCI: imx6: Port imx6_pcie_ltssm_enable() Andrey Smirnov
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=20190109071210.18896-8-andrew.smirnov@gmail.com \
--to=andrew.smirnov@gmail.com \
--cc=barebox@lists.infradead.org \
/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