From: Chen Feng <puck.chen@hisilicon.com>
To: <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>,
<xuwei5@hisilicon.com>, <puck.chen@hisilicon.com>,
<puck.chen@aliyun.com>, <yudongbin@hisilicon.com>,
<saberlily.xia@hisilicon.com>, <suzhuangluan@hisilicon.com>,
<kong.kongxinwei@hisilicon.com>, <xuyiping@hisilicon.com>,
<z.liuxinliang@hisilicon.com>, <weidong2@hisilicon.com>,
<w.f@huawei.com>
Cc: <qijiwen@hisilicon.com>, <peter.panshilin@hisilicon.com>,
<dan.zhao@hisilicon.com>, <linuxarm@huawei.com>
Subject: [PATCH v3 3/5] mfd: hi655x: Add hi665x pmic driver
Date: Tue, 15 Dec 2015 20:54:14 +0800 [thread overview]
Message-ID: <1450184056-79851-4-git-send-email-puck.chen@hisilicon.com> (raw)
In-Reply-To: <1450184056-79851-1-git-send-email-puck.chen@hisilicon.com>
Add mfd driver to support hisilicon hi665x PMIC.
Signed-off-by: Chen Feng <puck.chen@hisilicon.com>
Signed-off-by: Fei Wang <w.f@huawei.com>
Tested-by: Xinwei Kong <kong.kongxinwei@hisilicon.com>
---
drivers/mfd/Kconfig | 9 +++
drivers/mfd/Makefile | 1 +
drivers/mfd/hi655x-pmic.c | 170 ++++++++++++++++++++++++++++++++++++++++
include/linux/mfd/hi655x-pmic.h | 56 +++++++++++++
4 files changed, 236 insertions(+)
create mode 100644 drivers/mfd/hi655x-pmic.c
create mode 100644 include/linux/mfd/hi655x-pmic.h
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 4d92df6..cb70b53 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -284,6 +284,15 @@ config MFD_HI6421_PMIC
menus in order to enable them.
We communicate with the Hi6421 via memory-mapped I/O.
+config MFD_HI655X_PMIC
+ tristate "HiSilicon Hi655X series PMU/Codec IC"
+ depends on OF
+ select MFD_CORE
+ select REGMAP_MMIO
+ select REGMAP_IRQ
+ help
+ Select this option to enable Hisilicon hi655x series pmic driver.
+
config HTC_EGPIO
bool "HTC EGPIO support"
depends on GPIOLIB && ARM
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index a8b76b8..6a7b0e1 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -186,6 +186,7 @@ obj-$(CONFIG_MFD_STW481X) += stw481x.o
obj-$(CONFIG_MFD_IPAQ_MICRO) += ipaq-micro.o
obj-$(CONFIG_MFD_MENF21BMC) += menf21bmc.o
obj-$(CONFIG_MFD_HI6421_PMIC) += hi6421-pmic-core.o
+obj-$(CONFIG_MFD_HI655X_PMIC) += hi655x-pmic.o
obj-$(CONFIG_MFD_DLN2) += dln2.o
obj-$(CONFIG_MFD_RT5033) += rt5033.o
obj-$(CONFIG_MFD_SKY81452) += sky81452.o
diff --git a/drivers/mfd/hi655x-pmic.c b/drivers/mfd/hi655x-pmic.c
new file mode 100644
index 0000000..2ee455e
--- /dev/null
+++ b/drivers/mfd/hi655x-pmic.c
@@ -0,0 +1,170 @@
+/*
+ * Device driver for PMIC DRIVER in HI655X IC
+ *
+ * Copyright (c) 2015 Hisilicon Co. Ltd
+ *
+ * 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/io.h>
+#include <linux/irq.h>
+#include <linux/err.h>
+#include <linux/interrupt.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/of_gpio.h>
+#include <linux/platform_device.h>
+#include <linux/of_platform.h>
+#include <linux/mfd/hi655x-pmic.h>
+#include <linux/regmap.h>
+
+
+static const struct of_device_id of_hi655x_pmic_child_match_tbl[] = {
+ { .compatible = "hisilicon,hi655x-regulator-pmic", },
+ {},
+};
+
+static const struct of_device_id of_hi655x_pmic_match_tbl[] = {
+ { .compatible = "hisilicon,hi655x-pmic", },
+ {},
+};
+
+static const struct regmap_irq hi655x_irqs[] = {
+ { .reg_offset = 0, .mask = OTMP_D1R_INT },
+ { .reg_offset = 0, .mask = VSYS_2P5_R_INT },
+ { .reg_offset = 0, .mask = VSYS_UV_D3R_INT },
+ { .reg_offset = 0, .mask = VSYS_6P0_D200UR_INT },
+ { .reg_offset = 0, .mask = PWRON_D4SR_INT },
+ { .reg_offset = 0, .mask = PWRON_D20F_INT },
+ { .reg_offset = 0, .mask = PWRON_D20R_INT },
+ { .reg_offset = 0, .mask = RESERVE_INT },
+};
+
+static const struct regmap_irq_chip hi655x_irq_chip = {
+ .name = "hi655x-pmic",
+ .irqs = hi655x_irqs,
+ .num_regs = 1,
+ .num_irqs = ARRAY_SIZE(hi655x_irqs),
+ .status_base = HI655X_IRQ_STAT_BASE,
+ .mask_base = HI655X_IRQ_MASK_BASE,
+};
+
+static unsigned int hi655x_pmic_get_version(struct hi655x_pmic *pmic)
+{
+ u32 val;
+
+ regmap_read(pmic->regmap,
+ HI655X_BUS_ADDR(HI655X_VER_REG), &val);
+
+ return val;
+}
+
+static struct regmap_config hi655x_regmap_config = {
+ .reg_bits = 32,
+ .reg_stride = HI655X_STRIDE,
+ .val_bits = 8,
+ .max_register = HI655X_BUS_ADDR(0xFFF),
+};
+
+static void hi655x_local_irq_clear(struct regmap *map)
+{
+ unsigned int i;
+
+ regmap_write(map, HI655X_ANA_IRQM_BASE, HI655X_IRQ_CLR);
+ for (i = 0; i < HI655X_IRQ_ARRAY; i++) {
+ regmap_write(map, HI655X_IRQ_STAT_BASE + i * HI655X_STRIDE,
+ HI655X_IRQ_CLR);
+ }
+}
+
+static int hi655x_pmic_probe(struct platform_device *pdev)
+{
+ int ret;
+ struct hi655x_pmic *pmic;
+ struct device_node *gpio_np;
+
+ struct device *dev = &pdev->dev;
+ struct device_node *np = dev->of_node;
+ void __iomem *base;
+
+ pmic = devm_kzalloc(dev, sizeof(*pmic), GFP_KERNEL);
+ pmic->dev = dev;
+
+ pmic->res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!pmic->res) {
+ dev_err(dev, "platform_get_resource err\n");
+ return -ENOENT;
+ }
+ base = devm_ioremap_resource(&pdev->dev, pmic->res);
+ if (!base) {
+ dev_err(dev, "cannot map register memory\n");
+ return -ENOMEM;
+ }
+ pmic->regmap = devm_regmap_init_mmio_clk(dev, NULL, base,
+ &hi655x_regmap_config);
+
+ pmic->ver = hi655x_pmic_get_version(pmic);
+ if ((pmic->ver < PMU_VER_START) || (pmic->ver > PMU_VER_END)) {
+ dev_warn(dev, "it is wrong pmu version\n");
+ return -EINVAL;
+ }
+
+ hi655x_local_irq_clear(pmic->regmap);
+
+ gpio_np = of_parse_phandle(np, "pmic-gpios", 0);
+ if (!gpio_np) {
+ dev_err(dev, "can't parse property\n");
+ ret = -EPROBE_DEFER;
+ return ret;
+ }
+
+ ret = gpio_request_one(pmic->gpio, GPIOF_IN, "hi655x_pmic_irq");
+ if (ret < 0) {
+ dev_err(dev, "failed to request gpio %d ret = %d\n",
+ pmic->gpio, ret);
+ return ret;
+ }
+ pmic->irq = gpio_to_irq(pmic->gpio);
+
+ ret = regmap_add_irq_chip(pmic->regmap, pmic->irq,
+ IRQF_TRIGGER_LOW | IRQF_NO_SUSPEND, 0,
+ &hi655x_irq_chip, &pmic->irq_data);
+ if (ret) {
+ gpio_free(pmic->gpio);
+ return ret;
+ }
+
+ platform_set_drvdata(pdev, pmic);
+
+ /**
+ * populate sub nodes
+ */
+ ret = of_platform_populate(np, of_hi655x_pmic_child_match_tbl,
+ NULL, dev);
+ if (ret) {
+ gpio_free(pmic->gpio);
+ regmap_del_irq_chip(pmic->irq, pmic->irq_data);
+ return ret;
+ }
+
+ return 0;
+}
+
+static struct platform_driver hi655x_pmic_driver = {
+ .driver = {
+ .name = "hi655x-pmic",
+ .owner = THIS_MODULE,
+ .of_match_table = of_hi655x_pmic_match_tbl,
+ },
+ .probe = hi655x_pmic_probe,
+};
+module_platform_driver(hi655x_pmic_driver);
+
+MODULE_AUTHOR("Chen Feng <puck.chen@hisilicon.com>");
+MODULE_DESCRIPTION("Hisilicon hi655x pmic driver");
+MODULE_LICENSE("GPL v2");
diff --git a/include/linux/mfd/hi655x-pmic.h b/include/linux/mfd/hi655x-pmic.h
new file mode 100644
index 0000000..9b677f92
--- /dev/null
+++ b/include/linux/mfd/hi655x-pmic.h
@@ -0,0 +1,56 @@
+/*
+ * Header file for device driver Hi655X PMIC
+ *
+ * Copyright (C) 2015 Hisilicon Co. Ltd.
+ *
+ * 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.
+ */
+
+#ifndef __HI655X_PMIC_H
+#define __HI655X_PMIC_H
+
+/* Hi655x registers are mapped to memory bus in 4 bytes stride */
+#define HI655X_STRIDE (4)
+#define HI655X_BUS_ADDR(x) ((x) << 2)
+
+#define HI655X_BITS (8)
+
+#define HI655X_NR_IRQ (32)
+
+#define HI655X_IRQ_STAT_BASE (0x003 << 2)
+#define HI655X_IRQ_MASK_BASE (0x007 << 2)
+#define HI655X_ANA_IRQM_BASE (0x1b5 << 2)
+#define HI655X_IRQ_ARRAY (4)
+#define HI655X_IRQ_MASK (0xFF)
+#define HI655X_IRQ_CLR (0xFF)
+#define HI655X_VER_REG (0x00)
+
+#define PMU_VER_START (0x10)
+#define PMU_VER_END (0x38)
+
+#define RESERVE_INT (BIT(7))
+#define PWRON_D20R_INT (BIT(6))
+#define PWRON_D20F_INT (BIT(5))
+#define PWRON_D4SR_INT (BIT(4))
+#define VSYS_6P0_D200UR_INT (BIT(3))
+#define VSYS_UV_D3R_INT (BIT(2))
+#define VSYS_2P5_R_INT (BIT(1))
+#define OTMP_D1R_INT (BIT(0))
+
+struct hi655x_pmic {
+ struct resource *res;
+ struct device *dev;
+ struct regmap *regmap;
+ struct clk *clk;
+ int irq;
+ int gpio;
+ unsigned int ver;
+ struct regmap_irq_chip_data *irq_data;
+};
+
+#endif
--
1.9.1
next prev parent reply other threads:[~2015-12-15 12:58 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-15 12:54 [PATCH v3 0/5] Add Support for Hi6220 PMIC Hi6553 MFD Core Chen Feng
2015-12-15 12:54 ` [PATCH v3 1/5] doc: bindings: Add document for mfd hi665x PMIC Chen Feng
2015-12-15 12:54 ` [PATCH v3 2/5] doc: bindings: Document for hi655x regulator driver Chen Feng
2015-12-15 12:54 ` Chen Feng [this message]
2015-12-15 13:29 ` [PATCH v3 3/5] mfd: hi655x: Add hi665x pmic driver kbuild test robot
2015-12-15 13:29 ` [PATCH] mfd: hi655x: fix platform_no_drv_owner.cocci warnings kbuild test robot
2015-12-15 12:54 ` [PATCH v3 4/5] regulator: add regulator driver of hi655x PMIC Chen Feng
2015-12-16 19:16 ` Mark Brown
2015-12-17 3:18 ` chenfeng
2015-12-15 12:54 ` [PATCH v3 5/5] hisilicon/dts: Add hi655x pmic dts node Chen Feng
2015-12-17 3:27 ` chenfeng
2015-12-18 17:58 ` Mark Brown
2015-12-21 3:01 ` chenfeng
2015-12-21 6:20 ` chenfeng
2015-12-23 0:46 ` Mark Brown
2015-12-24 2:43 ` chenfeng
2015-12-22 16:08 ` Mark Brown
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=1450184056-79851-4-git-send-email-puck.chen@hisilicon.com \
--to=puck.chen@hisilicon.com \
--cc=broonie@kernel.org \
--cc=dan.zhao@hisilicon.com \
--cc=galak@codeaurora.org \
--cc=ijc+devicetree@hellion.org.uk \
--cc=kong.kongxinwei@hisilicon.com \
--cc=lee.jones@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=puck.chen@aliyun.com \
--cc=qijiwen@hisilicon.com \
--cc=robh+dt@kernel.org \
--cc=saberlily.xia@hisilicon.com \
--cc=suzhuangluan@hisilicon.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
all inboxes | Powered by JetHome®