mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chen Feng <puck.chen@hisilicon.com>
To: <puck.chen@hisilicon.com>, <lee.jones@linaro.org>,
	<linux-kernel@vger.kernel.org>, <lgirdwood@gmail.com>,
	<broonie@kernel.org>, <yudongbin@hisilicon.com>,
	<saberlily.xia@hisilicon.com>, <suzhuangluan@hisilicon.com>,
	<kong.kongxinwei@hisilicon.com>, <xuyiping@hisilicon.com>,
	<z.liuxinliang@hisilicon.com>, <puck.chenfeng@gmail.com>,
	<weidong2@hisilicon.com>, <w.f@huawei.com>
Cc: <qijiwen@hisilicon.com>, <peter.panshilin@hisilicon.com>,
	<dan.zhao@hisilicon.com>, <linuxarm@huawei.com>,
	<liguozhu@hisilicon.com>
Subject: [PATCH v5 4/5] regulator: add regulator driver of hi655x pmic
Date: Mon, 11 Jan 2016 20:20:16 +0800	[thread overview]
Message-ID: <1452514817-118311-5-git-send-email-puck.chen@hisilicon.com> (raw)
In-Reply-To: <1452514817-118311-1-git-send-email-puck.chen@hisilicon.com>

Add regulator support for hi655x pmic

Signed-off-by: Chen Feng <puck.chen@hisilicon.com>
Signed-off-by: Fei Wang <w.f@huawei.com>
Signed-off-by: Xinwei Kong <kong.kongxinwei@hisilicon.com>
---
 drivers/regulator/Kconfig            |   8 ++
 drivers/regulator/Makefile           |   1 +
 drivers/regulator/hi655x-regulator.c | 256 +++++++++++++++++++++++++++++++++++
 3 files changed, 265 insertions(+)
 create mode 100644 drivers/regulator/hi655x-regulator.c

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 8df0b0e..c00c915 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -261,6 +261,14 @@ config REGULATOR_HI6421
 	  21 general purpose LDOs, 3 dedicated LDOs, and 5 BUCKs. All
 	  of them come with support to either ECO (idle) or sleep mode.
 
+config REGULATOR_HI655X
+	tristate "Hisilicon HI655X PMIC regulators support"
+	depends on ARCH_HISI || (COMPILE_TEST && ARM64)
+	depends on MFD_HI655X_PMIC && OF
+	help
+	  This driver provides support for the voltage regulators of the
+	  Hisilicon Hi655x PMIC device.
+
 config REGULATOR_ISL9305
 	tristate "Intersil ISL9305 regulator"
 	depends on I2C
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 0f81749..8e4db96 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -34,6 +34,7 @@ obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o
 obj-$(CONFIG_REGULATOR_FAN53555) += fan53555.o
 obj-$(CONFIG_REGULATOR_GPIO) += gpio-regulator.o
 obj-$(CONFIG_REGULATOR_HI6421) += hi6421-regulator.o
+obj-$(CONFIG_REGULATOR_HI655X) += hi655x-regulator.o
 obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o
 obj-$(CONFIG_REGULATOR_ISL9305) += isl9305.o
 obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o
diff --git a/drivers/regulator/hi655x-regulator.c b/drivers/regulator/hi655x-regulator.c
new file mode 100644
index 0000000..e8e9995
--- /dev/null
+++ b/drivers/regulator/hi655x-regulator.c
@@ -0,0 +1,256 @@
+/*
+ * Device driver for regulators in hi655x IC
+ *
+ * Copyright (c) 2016 Hisilicon.
+ *
+ * Chen Feng <puck.chen@hisilicon.com>
+ * Fei  Wang <w.f@huawei.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/bitops.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/module.h>
+#include <linux/io.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <linux/regulator/driver.h>
+#include <linux/regulator/machine.h>
+#include <linux/regulator/of_regulator.h>
+#include <linux/mfd/hi655x-pmic.h>
+
+struct hi655x_regulator {
+	unsigned int disable_reg;
+	unsigned int status_reg;
+	unsigned int ctrl_regs;
+	unsigned int ctrl_mask;
+	struct regulator_desc rdesc;
+};
+
+/* LDO7 & LDO10 */
+static const unsigned int ldo7_voltages[] = {
+	1800000, 1850000, 2850000, 2900000,
+	3000000, 3100000, 3200000, 3300000,
+};
+
+static const unsigned int ldo19_voltages[] = {
+	1800000, 1850000, 1900000, 1750000,
+	2800000, 2850000, 2900000, 3000000,
+};
+
+static const unsigned int ldo22_voltages[] = {
+	 900000, 1000000, 1050000, 1100000,
+	1150000, 1175000, 1185000, 1200000,
+};
+
+enum hi655x_regulator_id {
+	HI655X_LDO0,
+	HI655X_LDO1,
+	HI655X_LDO2,
+	HI655X_LDO3,
+	HI655X_LDO4,
+	HI655X_LDO5,
+	HI655X_LDO6,
+	HI655X_LDO7,
+	HI655X_LDO8,
+	HI655X_LDO9,
+	HI655X_LDO10,
+	HI655X_LDO11,
+	HI655X_LDO12,
+	HI655X_LDO13,
+	HI655X_LDO14,
+	HI655X_LDO15,
+	HI655X_LDO16,
+	HI655X_LDO17,
+	HI655X_LDO18,
+	HI655X_LDO19,
+	HI655X_LDO20,
+	HI655X_LDO21,
+	HI655X_LDO22,
+};
+
+static int hi655x_is_enabled(struct regulator_dev *rdev)
+{
+	unsigned int value = 0;
+
+	struct hi655x_regulator *regulator = rdev_get_drvdata(rdev);
+
+	regmap_read(rdev->regmap, regulator->status_reg, &value);
+	return (value & BIT(regulator->ctrl_mask));
+}
+
+static int hi655x_disable(struct regulator_dev *rdev)
+{
+	int ret = 0;
+
+	struct hi655x_regulator *regulator = rdev_get_drvdata(rdev);
+
+	ret = regmap_write(rdev->regmap, regulator->disable_reg,
+			   BIT(regulator->ctrl_mask));
+	return ret;
+}
+
+static struct regulator_ops hi655x_regulator_ops = {
+	.enable = regulator_enable_regmap,
+	.disable = hi655x_disable,
+	.is_enabled = hi655x_is_enabled,
+	.list_voltage = regulator_list_voltage_table,
+	.get_voltage_sel = regulator_get_voltage_sel_regmap,
+	.set_voltage_sel = regulator_set_voltage_sel_regmap,
+};
+
+static struct regulator_ops hi655x_ldo_linear_ops = {
+	.enable = regulator_enable_regmap,
+	.disable = hi655x_disable,
+	.is_enabled = hi655x_is_enabled,
+	.list_voltage = regulator_list_voltage_linear,
+	.get_voltage_sel = regulator_get_voltage_sel_regmap,
+	.set_voltage_sel = regulator_set_voltage_sel_regmap,
+};
+
+#define HI655X_LDO(_ID, vreg, vmask, ereg, dreg,                \
+		   sreg, cmask, vtable) {                       \
+	.rdesc = {                                              \
+		.name           = #_ID,                         \
+		.ops            = &hi655x_regulator_ops,        \
+		.type           = REGULATOR_VOLTAGE,            \
+		.id             = HI655X_##_ID,                 \
+		.owner          = THIS_MODULE,                  \
+		.n_voltages     = ARRAY_SIZE(vtable),           \
+		.volt_table     = vtable,                       \
+		.vsel_reg       = HI655X_BUS_ADDR(vreg),        \
+		.vsel_mask      = vmask,                        \
+		.enable_reg     = HI655X_BUS_ADDR(ereg),        \
+		.enable_mask    = cmask,                        \
+	},                                                      \
+	.disable_reg = HI655X_BUS_ADDR(dreg),                   \
+	.status_reg = HI655X_BUS_ADDR(sreg),                    \
+	.ctrl_mask = cmask,                                     \
+}
+
+#define HI655X_LDO_LINEAR(_ID, vreg, vmask, ereg, dreg,         \
+			  sreg, cmask, minv, nvolt, vstep) {    \
+	.rdesc = {                                              \
+		.name           = #_ID,                         \
+		.ops            = &hi655x_ldo_linear_ops,       \
+		.type           = REGULATOR_VOLTAGE,            \
+		.id             = HI655X_##_ID,                 \
+		.owner          = THIS_MODULE,                  \
+		.min_uV         = minv,                         \
+		.n_voltages     = nvolt,                        \
+		.uV_step        = vstep,                        \
+		.uV_step        = vstep,                        \
+		.vsel_reg       = HI655X_BUS_ADDR(vreg),        \
+		.vsel_mask      = vmask,                        \
+		.enable_reg     = HI655X_BUS_ADDR(ereg),        \
+		.enable_mask    = cmask,                        \
+	},                                                      \
+	.disable_reg = HI655X_BUS_ADDR(dreg),                   \
+	.status_reg = HI655X_BUS_ADDR(sreg),                    \
+	.ctrl_mask = cmask,                                     \
+}
+
+static struct hi655x_regulator regulators[] = {
+	HI655X_LDO_LINEAR(LDO2, 0x72, 0x07, 0x29, 0x2a, 0x2b, 0x01,
+			  2500000, 8, 100000),
+	HI655X_LDO(LDO7, 0x78, 0x07, 0x29, 0x2a, 0x2b, 0x06, ldo7_voltages),
+	HI655X_LDO(LDO10, 0x78, 0x07, 0x29, 0x2a, 0x2b, 0x01, ldo7_voltages),
+	HI655X_LDO_LINEAR(LDO13, 0x7e, 0x07, 0x2c, 0x2d, 0x2e, 0x04,
+			  1600000, 8, 50000),
+	HI655X_LDO_LINEAR(LDO14, 0x7f, 0x07, 0x2c, 0x2d, 0x2e, 0x05,
+			  2500000, 8, 100000),
+	HI655X_LDO_LINEAR(LDO15, 0x80, 0x07, 0x2c, 0x2d, 0x2e, 0x06,
+			  1600000, 8, 50000),
+	HI655X_LDO_LINEAR(LDO17, 0x82, 0x07, 0x2f, 0x30, 0x31, 0x00,
+			  2500000, 8, 100000),
+	HI655X_LDO(LDO19, 0x84, 0x07, 0x2f, 0x30, 0x31, 0x02, ldo19_voltages),
+	HI655X_LDO_LINEAR(LDO21, 0x86, 0x07, 0x2f, 0x30, 0x31, 0x04,
+			  1650000, 8, 50000),
+	HI655X_LDO(LDO22, 0x87, 0x07, 0x2f, 0x30, 0x31, 0x05, ldo22_voltages),
+};
+
+static struct of_regulator_match hi655x_regulator_match[] = {
+	{ .name	= "ldo2", .driver_data = (void *)HI655X_LDO0, },
+	{ .name	= "ldo7", .driver_data = (void *)HI655X_LDO7, },
+	{ .name	= "ldo10", .driver_data = (void *)HI655X_LDO10, },
+	{ .name	= "ldo13", .driver_data = (void *)HI655X_LDO13, },
+	{ .name	= "ldo14", .driver_data = (void *)HI655X_LDO14, },
+	{ .name = "ldo15", .driver_data = (void *)HI655X_LDO15, },
+	{ .name	= "ldo17", .driver_data = (void *)HI655X_LDO17, },
+	{ .name	= "ldo19", .driver_data = (void *)HI655X_LDO19, },
+	{ .name	= "ldo21", .driver_data = (void *)HI655X_LDO21, },
+	{ .name	= "ldo22", .driver_data = (void *)HI655X_LDO22, },
+};
+
+static int hi655x_regulator_probe(struct platform_device *pdev)
+{
+	unsigned int i;
+	int ret;
+	struct hi655x_regulator *regulator;
+	struct hi655x_pmic *pmic;
+	struct regulator_config config = { };
+	struct device *dev = &pdev->dev;
+	struct regulator_dev *rdev;
+	struct device_node *np;
+
+	np = of_get_child_by_name(dev->parent->of_node, "regulators");
+	if (!np)
+		return -ENODEV;
+
+	ret = of_regulator_match(dev, np,
+				 hi655x_regulator_match,
+				 ARRAY_SIZE(hi655x_regulator_match));
+	of_node_put(np);
+	if (ret < 0) {
+		dev_err(dev, "Error parsing regulator init data: %d\n", ret);
+		return ret;
+	}
+
+	pmic = dev_get_drvdata(pdev->dev.parent);
+	if (!pmic) {
+		dev_err(dev, "no pmic in the regulator parent node\n");
+		return -ENODEV;
+	}
+
+	regulator = devm_kzalloc(dev, sizeof(*regulator), GFP_KERNEL);
+	if (!regulator)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, regulator);
+
+	for (i = 0; i < ARRAY_SIZE(regulators); i++) {
+		config.dev = &pdev->dev;
+		config.driver_data = regulator;
+		config.regmap = pmic->regmap;
+		config.of_node = hi655x_regulator_match[i].of_node;
+		config.init_data = hi655x_regulator_match[i].init_data;
+
+		/* register regulator with framework */
+		rdev = devm_regulator_register(&pdev->dev,
+					       &regulators[i].rdesc,
+					       &config);
+		if (IS_ERR(rdev)) {
+			dev_err(&pdev->dev, "failed to register regulator %s\n",
+				regulator->rdesc.name);
+			return PTR_ERR(rdev);
+		}
+	}
+	return 0;
+}
+
+static struct platform_driver hi655x_regulator_driver = {
+	.driver = {
+		.name	= "hi655x-regulator",
+	},
+	.probe	= hi655x_regulator_probe,
+};
+module_platform_driver(hi655x_regulator_driver);
+
+MODULE_AUTHOR("Chen Feng <puck.chen@hisilicon.com>");
+MODULE_DESCRIPTION("Hisilicon hi655x regulator driver");
+MODULE_LICENSE("GPL v2");
-- 
1.9.1

  parent reply	other threads:[~2016-01-11 12:21 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-11 12:20 [PATCH v5 0/5] Add Support for Hi6220 PMIC Hi6553 MFD Core Chen Feng
2016-01-11 12:20 ` [PATCH v5 1/5] doc: bindings: Add document for mfd hi665x PMIC Chen Feng
2016-01-25 12:53   ` Lee Jones
2016-01-26  6:26     ` chenfeng
2016-01-11 12:20 ` [PATCH v5 2/5] doc: bindings: Document for hi655x regulator driver Chen Feng
2016-01-11 18:17   ` Mark Brown
2016-01-12  2:07     ` chenfeng
2016-01-11 12:20 ` [PATCH v5 3/5] mfd: hi655x: Add hi665x pmic driver Chen Feng
2016-01-25 14:22   ` Lee Jones
2016-01-26  6:32     ` chenfeng
2016-01-28  9:48     ` chenfeng
2016-01-28 11:30       ` Lee Jones
2016-01-11 12:20 ` Chen Feng [this message]
2016-01-11 18:24   ` [PATCH v5 4/5] regulator: add regulator driver of hi655x pmic Mark Brown
2016-01-12  2:18     ` chenfeng
2016-01-15 18:07       ` Mark Brown
2016-01-18  8:26         ` chenfeng
2016-01-11 12:20 ` [PATCH v5 5/5] hisilicon/dts: Add hi655x pmic dts node Chen Feng

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=1452514817-118311-5-git-send-email-puck.chen@hisilicon.com \
    --to=puck.chen@hisilicon.com \
    --cc=broonie@kernel.org \
    --cc=dan.zhao@hisilicon.com \
    --cc=kong.kongxinwei@hisilicon.com \
    --cc=lee.jones@linaro.org \
    --cc=lgirdwood@gmail.com \
    --cc=liguozhu@hisilicon.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=peter.panshilin@hisilicon.com \
    --cc=puck.chenfeng@gmail.com \
    --cc=qijiwen@hisilicon.com \
    --cc=saberlily.xia@hisilicon.com \
    --cc=suzhuangluan@hisilicon.com \
    --cc=w.f@huawei.com \
    --cc=weidong2@hisilicon.com \
    --cc=xuyiping@hisilicon.com \
    --cc=yudongbin@hisilicon.com \
    --cc=z.liuxinliang@hisilicon.com \
    /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

all inboxes | Powered by JetHome®