public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Chen Feng <puck.chen@hisilicon.com>
To: <w.f@huawei.com>, <sameo@linux.intel.com>, <lee.jones@linaro.org>,
	<linux-kernel@vger.kernel.org>, <lgirdwood@gmail.com>,
	<broonie@kernel.org>, <robh+dt@kernel.org>, <pawel.moll@arm.com>,
	<mark.rutland@arm.com>, <ijc+devicetree@hellion.org.uk>,
	<galak@codeaurora.org>, <puck.chen@hisilicon.com>,
	<joro@8bytes.org>, <iommu@lists.linux-foundation.org>,
	<haojian.zhuang@linaro.org>, <devicetree@vger.kernel.org>,
	<xuwei5@hisilicon.com>, <xuyiping@hisilicon.com>,
	<kong.kongxinwei@hisilicon.com>, <z.liuxinliang@hisilicon.com>,
	<yudongbin@hisilicon.com>, <weidong2@hisilicon.com>,
	<saberlily.xia@hisilicon.com>, <haojian.zhuang@outlook.com>,
	<leo.yan@linaro.org>
Cc: <linuxarm@huawei.com>, <dan.zhao@hisilicon.com>,
	<peter.panshilin@hisilicon.com>, <qijiwen@hisilicon.com>
Subject: [PATCH 5/7] regulator: add driver for mtcmos voltage regulator on hi6220 SoC
Date: Thu, 5 Nov 2015 21:34:46 +0800	[thread overview]
Message-ID: <1446730488-31930-6-git-send-email-puck.chen@hisilicon.com> (raw)
In-Reply-To: <1446730488-31930-1-git-send-email-puck.chen@hisilicon.com>

Add driver to support mtcmos on hi6220

Signed-off-by: Chen Feng <puck.chen@hisilicon.com>
Signed-off-by: Fei Wang <w.f@huawei.com>
---
 drivers/regulator/hi6220-mtcmos.c | 245 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 245 insertions(+)
 create mode 100644 drivers/regulator/hi6220-mtcmos.c

diff --git a/drivers/regulator/hi6220-mtcmos.c b/drivers/regulator/hi6220-mtcmos.c
new file mode 100644
index 0000000..c79ffc0
--- /dev/null
+++ b/drivers/regulator/hi6220-mtcmos.c
@@ -0,0 +1,245 @@
+/*
+ * Device driver for regulators in hi6220 mtcmos
+ *
+ * Copyright (c) 2015 Hisilicon.
+ *
+ * Fei Wang <w.f@huawei.com>
+ * Chen Feng <puck.chen@hisilicon.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/slab.h>
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/platform_device.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/of_address.h>
+#include <linux/regmap.h>
+#include <linux/regulator/driver.h>
+#include <linux/regulator/machine.h>
+#include <linux/regulator/of_regulator.h>
+#include <linux/sizes.h>
+
+enum {
+	HI6220_MTCMOS1,
+	HI6220_MTCMOS2,
+	HI6220_RG_MAX,
+};
+
+struct hi6220_mtcmos_ctrl_regs {
+	unsigned int enable_reg;
+	unsigned int disable_reg;
+	unsigned int status_reg;
+};
+
+struct hi6220_mtcmos_ctrl_data {
+	int shift;
+	unsigned int mask;
+};
+
+struct hi6220_mtcmos_info {
+	struct regulator_desc rdesc;
+	struct hi6220_mtcmos_ctrl_regs ctrl_regs;
+	struct hi6220_mtcmos_ctrl_data ctrl_data;
+};
+
+struct hi6220_mtcmos {
+	struct regulator_dev *rdev[HI6220_RG_MAX];
+	void __iomem *sc_on_regs;
+};
+
+static int hi6220_mtcmos_is_on(struct hi6220_mtcmos *mtcmos,
+			       unsigned int regs, unsigned int mask, int shift)
+{
+	unsigned int ret;
+
+	ret = readl(mtcmos->sc_on_regs + regs);
+	ret &= (mask << shift);
+
+	return ret;
+}
+
+static int hi6220_mtcmos_is_enabled(struct regulator_dev *rdev)
+{
+	int ret;
+	struct hi6220_mtcmos_info *sreg = rdev_get_drvdata(rdev);
+	struct platform_device *pdev =
+		container_of(rdev->dev.parent, struct platform_device, dev);
+	struct hi6220_mtcmos *mtcmos = platform_get_drvdata(pdev);
+	struct hi6220_mtcmos_ctrl_regs *ctrl_regs = &sreg->ctrl_regs;
+	struct hi6220_mtcmos_ctrl_data *ctrl_data = &sreg->ctrl_data;
+
+	ret = hi6220_mtcmos_is_on(mtcmos, ctrl_regs->status_reg,
+				  ctrl_data->mask, ctrl_data->shift);
+	return ret;
+}
+
+static int hi6220_mtcmos_op(struct hi6220_mtcmos *mtcmos,
+		      unsigned int regs, unsigned int mask, int shift)
+{
+	writel(mask << shift, mtcmos->sc_on_regs + regs);
+
+	return 0;
+}
+
+static int hi6220_mtcmos_enable(struct regulator_dev *rdev)
+{
+	int ret;
+	struct hi6220_mtcmos_info *sreg = rdev_get_drvdata(rdev);
+	struct platform_device *pdev =
+		container_of(rdev->dev.parent, struct platform_device, dev);
+	struct hi6220_mtcmos *mtcmos = platform_get_drvdata(pdev);
+	struct hi6220_mtcmos_ctrl_regs *ctrl_regs = &sreg->ctrl_regs;
+	struct hi6220_mtcmos_ctrl_data *ctrl_data = &sreg->ctrl_data;
+
+	hi6220_mtcmos_op(mtcmos, ctrl_regs->enable_reg,
+			 ctrl_data->mask, ctrl_data->shift);
+	ret =  hi6220_mtcmos_is_on(mtcmos, ctrl_regs->status_reg,
+				   ctrl_data->mask, ctrl_data->shift)
+	return ret;
+}
+
+static int hi6220_mtcmos_disable(struct regulator_dev *rdev)
+{
+	int ret;
+	struct hi6220_mtcmos_info *sreg = rdev_get_drvdata(rdev);
+	struct platform_device *pdev =
+		container_of(rdev->dev.parent, struct platform_device, dev);
+	struct hi6220_mtcmos *mtcmos = platform_get_drvdata(pdev);
+	struct hi6220_mtcmos_ctrl_regs  *ctrl_regs = &sreg->ctrl_regs;
+	struct hi6220_mtcmos_ctrl_data  *ctrl_data = &sreg->ctrl_data;
+
+	ret = hi6220_mtcmos_op(mtcmos, ctrl_regs->disable_reg,
+			       ctrl_data->mask, ctrl_data->shift);
+
+	return ret;
+}
+
+static struct regulator_ops hi6220_mtcmos_mtcmos_rops = {
+	.is_enabled = hi6220_mtcmos_is_enabled,
+	.enable = hi6220_mtcmos_enable,
+	.disable = hi6220_mtcmos_disable,
+};
+
+#define HI6220_MTCMOS(vreg) \
+{								\
+	.rdesc = {					\
+		.name = #vreg,			\
+		.ops	= &hi6220_mtcmos_mtcmos_rops, \
+		.type = REGULATOR_VOLTAGE,			\
+		.owner = THIS_MODULE,		\
+	},							\
+}
+
+static struct hi6220_mtcmos_info hi6220_mtcmos_info[] = {
+	HI6220_MTCMOS(MTCMOS1),
+	HI6220_MTCMOS(MTCMOS2),
+};
+
+static struct of_regulator_match hi6220_mtcmos_matches[] = {
+	{ .name = "mtcmos1",
+		.driver_data = &hi6220_mtcmos_info[HI6220_MTCMOS1], },
+	{ .name = "mtcmos2",
+		.driver_data = &hi6220_mtcmos_info[HI6220_MTCMOS2], },
+};
+
+static int hi6220_mtcmos_probe(struct platform_device *pdev)
+{
+	int ret;
+	struct hi6220_mtcmos *mtcmos;
+	const __be32 *sc_on_regs = NULL;
+	void __iomem	*regs;
+	struct device *dev;
+	struct device_node *np, *child;
+	int i;
+	struct regulator_config config = { };
+	struct regulator_init_data *init_data;
+	struct hi6220_mtcmos_info *sreg;
+	u32 off_on_delay = 0;
+
+	dev = &pdev->dev;
+	np = dev->of_node;
+	mtcmos = devm_kzalloc(dev, sizeof(struct hi6220_mtcmos), GFP_KERNEL);
+	if (!mtcmos)
+		return -ENOMEM;
+
+	sc_on_regs = of_get_property(np, "hisilicon,mtcmos-sc-on-base", NULL);
+	if (sc_on_regs) {
+		regs = ioremap(be32_to_cpu(*sc_on_regs), SZ_4K);
+		mtcmos->sc_on_regs = regs;
+	} else
+		return -ENODEV;
+	of_property_read_u32(np, "hisilicon,mtcmos-steady-us", &off_on_delay);
+
+	for (i = 0; i < HI6220_RG_MAX; i++) {
+		init_data = hi6220_mtcmos_matches[i].init_data;
+		if (!init_data)
+			continue;
+		sreg = hi6220_mtcmos_matches[i].driver_data;
+		sreg->rdesc.off_on_delay = off_on_delay;
+		config.dev = &pdev->dev;
+		config.init_data = init_data;
+		config.driver_data = sreg;
+		config.of_node = hi6220_mtcmos_matches[i].of_node;
+		child = config.of_node;
+
+		ret = of_property_read_u32_array(child, "hisilicon,ctrl-regs",
+						 (u32 *)(&sreg->ctrl_regs),
+						 0x3);
+		ret = of_property_read_u32_array(child, "hisilicon,ctrl-data",
+						 (u32 *)(&sreg->ctrl_data),
+						 0x2);
+
+		mtcmos->rdev[i] = regulator_register(&sreg->rdesc, &config);
+		if (IS_ERR(mtcmos->rdev[i])) {
+			ret = PTR_ERR(mtcmos->rdev[i]);
+			dev_err(&pdev->dev, "failed to register mtcmos %s\n",
+				sreg->rdesc.name);
+			while (--i >= 0)
+				regulator_unregister(mtcmos->rdev[i]);
+
+			return ret;
+		}
+	}
+
+	platform_set_drvdata(pdev, mtcmos);
+
+	return 0;
+}
+
+static const struct of_device_id of_hi6220_mtcmos_match_tbl[] = {
+	{ .compatible = "hisilicon,hi6220-mtcmos-driver", },
+	{}
+};
+
+static struct platform_driver mtcmos_driver = {
+	.driver = {
+		.name = "hisi_hi6220_mtcmos",
+		.owner = THIS_MODULE,
+		.of_match_table = of_hi6220_mtcmos_match_tbl,
+	},
+	.probe = hi6220_mtcmos_probe,
+};
+
+static int __init hi6220_mtcmos_init(void)
+{
+	return platform_driver_register(&mtcmos_driver);
+}
+
+static void __exit hi6220_mtcmos_exit(void)
+{
+	platform_driver_unregister(&mtcmos_driver);
+}
+
+fs_initcall(hi6220_mtcmos_init);
+module_exit(hi6220_mtcmos_exit);
+
+MODULE_AUTHOR("Fei Wang <w.f@huawei.com>");
+MODULE_DESCRIPTION("Hi6220 mtcmos interface driver");
+MODULE_LICENSE("GPL v2");
-- 
1.9.1


  parent reply	other threads:[~2015-11-05 13:49 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-05 13:34 [PATCH 0/7] Add Support for Hi6220 PMIC Hi6553 MFD Core Chen Feng
2015-11-05 13:34 ` [PATCH 1/7] doc:bindings:Add document for mfd hi665x PMIC Chen Feng
2015-11-05 14:04   ` Mark Brown
2015-11-05 13:34 ` [PATCH 2/7] doc:bindings:Document for mtcmos regulator on hi6220 SoC Chen Feng
2015-11-05 14:14   ` Mark Brown
2015-11-05 20:31   ` Rob Herring
2015-11-05 13:34 ` [PATCH 3/7] doc:bindings:Document for hi655x pmic driver Chen Feng
2015-11-05 14:23   ` Mark Brown
2015-11-05 13:34 ` [PATCH 4/7] mfd: hi655x: Add hi665x " Chen Feng
2015-11-05 14:30   ` Mark Brown
2015-11-06 20:21   ` Andy Shevchenko
2015-11-05 13:34 ` Chen Feng [this message]
2015-11-05 14:44   ` [PATCH 5/7] regulator: add driver for mtcmos voltage regulator on hi6220 SoC Mark Brown
2015-11-05 13:34 ` [PATCH 6/7] regulator: hisilicon: Add hi655x pmic voltage regulator driver Chen Feng
2015-11-05 14:52   ` Mark Brown
2015-11-06 11:47   ` kbuild test robot
2015-11-06 21:29   ` Andy Shevchenko
2015-11-05 13:34 ` [PATCH 7/7] arm64: dts: Add mtcmos and pmic node for hi6220 HiKey board 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=1446730488-31930-6-git-send-email-puck.chen@hisilicon.com \
    --to=puck.chen@hisilicon.com \
    --cc=broonie@kernel.org \
    --cc=dan.zhao@hisilicon.com \
    --cc=devicetree@vger.kernel.org \
    --cc=galak@codeaurora.org \
    --cc=haojian.zhuang@linaro.org \
    --cc=haojian.zhuang@outlook.com \
    --cc=ijc+devicetree@hellion.org.uk \
    --cc=iommu@lists.linux-foundation.org \
    --cc=joro@8bytes.org \
    --cc=kong.kongxinwei@hisilicon.com \
    --cc=lee.jones@linaro.org \
    --cc=leo.yan@linaro.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=mark.rutland@arm.com \
    --cc=pawel.moll@arm.com \
    --cc=peter.panshilin@hisilicon.com \
    --cc=qijiwen@hisilicon.com \
    --cc=robh+dt@kernel.org \
    --cc=saberlily.xia@hisilicon.com \
    --cc=sameo@linux.intel.com \
    --cc=w.f@huawei.com \
    --cc=weidong2@hisilicon.com \
    --cc=xuwei5@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