From patchwork Wed Aug 13 11:33:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guodong Xu X-Patchwork-Id: 35347 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f197.google.com (mail-pd0-f197.google.com [209.85.192.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 368A8203C5 for ; Wed, 13 Aug 2014 11:35:42 +0000 (UTC) Received: by mail-pd0-f197.google.com with SMTP id y10sf73675800pdj.8 for ; Wed, 13 Aug 2014 04:35:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=moboV717Jtbyj0PAhNdFVMUspWh/YhVPVTqObkUsyeE=; b=ifHDm22GcqZ63hOsZCYJcBVtBDx5QFW6tpuQBE03Cvso8sHnAICSZb20sFcyH8Q2Fn zQaBjE8+vO7OxZfn4BvIBWo1nLGn6knSNvrc5R6oMebUpB/BcAz3xpN235N1GejNWm6Z PdxW4d0a2ZFAXFpTtlGDNQB6Q3L6r4/noB0AsV1THw8kox+YAs//YYk4VXGCJ1oUZwqx OiBk5trBQgACZXSPOYQ87zUTOH/sOw9T+s8tsJyef5zoaR0t2cbedvVHEbKcQ/b1Kngt f4CWiY74rkh1feCJ+upuT6z2CcBznlwL5sKBL2lanI6P+NKVu2F1vhMCn4m+FqT5DXZh OfiA== X-Gm-Message-State: ALoCoQkWFXqledpSJ66LXz3IuwT2p0KTPFfacBUzjvDyKh7Wlb+fhhUnJhSZnVi47DIjT8+EWCv1 X-Received: by 10.67.5.228 with SMTP id cp4mr2147159pad.8.1407929741496; Wed, 13 Aug 2014 04:35:41 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.21.197 with SMTP id 63ls585763qgl.58.gmail; Wed, 13 Aug 2014 04:35:41 -0700 (PDT) X-Received: by 10.220.167.9 with SMTP id o9mr3048995vcy.8.1407929741343; Wed, 13 Aug 2014 04:35:41 -0700 (PDT) Received: from mail-vc0-f180.google.com (mail-vc0-f180.google.com [209.85.220.180]) by mx.google.com with ESMTPS id o10si897277vdj.82.2014.08.13.04.35.41 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 13 Aug 2014 04:35:41 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.180 as permitted sender) client-ip=209.85.220.180; Received: by mail-vc0-f180.google.com with SMTP id ij19so14842771vcb.11 for ; Wed, 13 Aug 2014 04:35:41 -0700 (PDT) X-Received: by 10.220.174.137 with SMTP id t9mr3082271vcz.12.1407929741177; Wed, 13 Aug 2014 04:35:41 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp323218vcb; Wed, 13 Aug 2014 04:35:40 -0700 (PDT) X-Received: by 10.70.62.5 with SMTP id u5mr3583846pdr.100.1407929740178; Wed, 13 Aug 2014 04:35:40 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id xr5si1318317pbc.47.2014.08.13.04.35.39 for ; Wed, 13 Aug 2014 04:35:40 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752616AbaHMLfd (ORCPT + 23 others); Wed, 13 Aug 2014 07:35:33 -0400 Received: from mail-pd0-f177.google.com ([209.85.192.177]:48576 "EHLO mail-pd0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752579AbaHMLf1 (ORCPT ); Wed, 13 Aug 2014 07:35:27 -0400 Received: by mail-pd0-f177.google.com with SMTP id p10so14217435pdj.22 for ; Wed, 13 Aug 2014 04:35:27 -0700 (PDT) X-Received: by 10.66.157.40 with SMTP id wj8mr3625036pab.42.1407929727390; Wed, 13 Aug 2014 04:35:27 -0700 (PDT) Received: from localhost.localdomain ([120.136.45.59]) by mx.google.com with ESMTPSA id ya1sm1832872pbb.91.2014.08.13.04.35.19 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 13 Aug 2014 04:35:25 -0700 (PDT) From: Guodong Xu To: robh+dt@kernel.org, pawel.moll@arm.com, mark.rutland@arm.com, ijc+devicetree@hellion.org.uk, galak@codeaurora.org, linux@arm.linux.org.uk, sameo@linux.intel.com, lee.jones@linaro.org, lgirdwood@gmail.com, broonie@kernel.org, grant.likely@linaro.org, khilman@linaro.org, haojian.zhuang@linaro.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Guodong Xu Subject: [PATCH v5 4/7] mfd: Add hi6421 PMIC core driver Date: Wed, 13 Aug 2014 19:33:41 +0800 Message-Id: <1407929624-8737-5-git-send-email-guodong.xu@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1407929624-8737-1-git-send-email-guodong.xu@linaro.org> References: <1407929624-8737-1-git-send-email-guodong.xu@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: guodong.xu@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.180 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This adds driver to support HiSilicon Hi6421 PMIC. Hi6421 includes multi- functions, such as regulators, codec, ADCs, Coulomb counter, etc. This driver includes core APIs _only_. Drivers for individul components, like voltage regulators, are implemented in corresponding driver directories and files. Registers in Hi6421 are memory mapped, so using regmap-mmio API. Signed-off-by: Guodong Xu --- Documentation/devicetree/bindings/mfd/hi6421.txt | 37 +++++++ drivers/mfd/Kconfig | 13 +++ drivers/mfd/Makefile | 1 + drivers/mfd/hi6421-pmic-core.c | 119 +++++++++++++++++++++++ include/linux/mfd/hi6421-pmic.h | 39 ++++++++ 5 files changed, 209 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/hi6421.txt create mode 100644 drivers/mfd/hi6421-pmic-core.c create mode 100644 include/linux/mfd/hi6421-pmic.h diff --git a/Documentation/devicetree/bindings/mfd/hi6421.txt b/Documentation/devicetree/bindings/mfd/hi6421.txt new file mode 100644 index 0000000..1512123 --- /dev/null +++ b/Documentation/devicetree/bindings/mfd/hi6421.txt @@ -0,0 +1,37 @@ +* HI6421 Multi-Functional Device (MFD), by HiSilicon Ltd. + +Required parent device properties: +- reg : register range space of hi6421; + +Supported Hi6421 sub-devices include: + +Device IRQ Names Supply Names Description +------ --------- ------------ ----------- +regulators : : : Regulators + +Required child device properties: +None. + +Example: + pmic: pmic@c00000 { + compatible = "hisilicon,hi6421-pmic"; + reg = <0xc00000 0x0180>; /* 0x60 << 2 */ + + regulators { + // supply for MLC NAND/ eMMC + hi6421_vout0_reg: hi6421_vout0 { + regulator-name = "VOUT0"; + regulator-min-microvolt = <2850000>; + regulator-max-microvolt = <2850000>; + }; + + // supply for 26M Oscillator + hi6421_vout1_reg: hi6421_vout1 { + regulator-name = "VOUT1"; + regulator-min-microvolt = <1700000>; + regulator-max-microvolt = <2000000>; + regulator-boot-on; + regulator-always-on; + }; + }; + }; diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 6cc4b6a..f25ae4e 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -209,6 +209,19 @@ config MFD_MC13XXX_I2C help Select this if your MC13xxx is connected via an I2C bus. +config MFD_HI6421_PMIC + tristate "HiSilicon Hi6421 PMU/Codec IC" + depends on OF + select MFD_CORE + select REGMAP_MMIO + help + This driver supports HiSilicon Hi6421 PMIC. Hi6421 includes multi- + functions, such as regulators, codec, ADCs, Coulomb counter, etc. + This driver includes core APIs _only_. You have to select + individul components like voltage regulators under corresponding + menus in order to enable them. + Memory-mapped I/O is the way to communicate with Hi6421. + config HTC_EGPIO bool "HTC EGPIO support" depends on GPIOLIB && ARM diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 8afedba..4c52a6a6 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -169,3 +169,4 @@ obj-$(CONFIG_MFD_AS3711) += as3711.o obj-$(CONFIG_MFD_AS3722) += as3722.o obj-$(CONFIG_MFD_STW481X) += stw481x.o obj-$(CONFIG_MFD_IPAQ_MICRO) += ipaq-micro.o +obj-$(CONFIG_MFD_HI6421_PMIC) += hi6421-pmic-core.o diff --git a/drivers/mfd/hi6421-pmic-core.c b/drivers/mfd/hi6421-pmic-core.c new file mode 100644 index 0000000..bd4935b --- /dev/null +++ b/drivers/mfd/hi6421-pmic-core.c @@ -0,0 +1,119 @@ +/* + * Device driver for Hi6421 IC + * + * Copyright (c) <2011-2014> HiSilicon Technologies Co., Ltd. + * http://www.hisilicon.com + * Copyright (c) <2013-2014> Linaro Ltd. + * http://www.linaro.org + * + * Author: Guodong Xu + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static struct of_device_id of_hi6421_pmic_match_tbl[] = { + { + .compatible = "hisilicon,hi6421-pmic", + }, + { /* end */ } +}; + +static const struct mfd_cell hi6421_devs[] = { + { + .name = "hi6421-regulator", + }, +}; + +static struct regmap_config hi6421_regmap_config = { + .reg_bits = 32, + .reg_stride = 4, + .val_bits = 8, + .max_register = HI6421_REG_TO_BUS_ADDR(0xFF), +}; + +static int hi6421_pmic_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct hi6421_pmic *pmic = NULL; + struct resource *res; + void __iomem *base; + int ret; + + pmic = devm_kzalloc(dev, sizeof(*pmic), GFP_KERNEL); + if (!pmic) { + dev_err(dev, "cannot allocate hi6421_pmic device info\n"); + return -ENOMEM; + } + + /* get resources */ + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (unlikely(!res)) { + dev_err(&pdev->dev, "Invalid mem resource.\n"); + return -ENODEV; + } + + base = devm_request_and_ioremap(dev, res); + if (!base) { + dev_err(dev, "cannot map register memory\n"); + return -ENOMEM; + } + + pmic->regmap = devm_regmap_init_mmio_clk(&pdev->dev, NULL, base, + &hi6421_regmap_config); + if (IS_ERR(pmic->regmap)) { + dev_err(&pdev->dev, "regmap init failed: %ld\n", + PTR_ERR(pmic->regmap)); + return PTR_ERR(pmic->regmap); + } + + pmic->dev = dev; + platform_set_drvdata(pdev, pmic); + + /* set over-current protection debounce 8ms*/ + regmap_update_bits(pmic->regmap, HI6421_OCP_DEB_CTRL_REG, + (HI6421_OCP_DEB_SEL_MASK | HI6421_OCP_EN_DEBOUNCE_MASK | + HI6421_OCP_AUTO_STOP_MASK), + (HI6421_OCP_DEB_SEL_8MS | HI6421_OCP_EN_DEBOUNCE_ENABLE)); + + ret = mfd_add_devices(dev, 0, hi6421_devs, + ARRAY_SIZE(hi6421_devs), NULL, 0, NULL); + + return ret; +} + +static int hi6421_pmic_remove(struct platform_device *pdev) +{ + mfd_remove_devices(&pdev->dev); + + return 0; +} + +static struct platform_driver hi6421_pmic_driver = { + .driver = { + .name = "hi6421_pmic", + .owner = THIS_MODULE, + .of_match_table = of_hi6421_pmic_match_tbl, + }, + .probe = hi6421_pmic_probe, + .remove = hi6421_pmic_remove, +}; +module_platform_driver(hi6421_pmic_driver); + +MODULE_AUTHOR("Guodong Xu "); +MODULE_DESCRIPTION("Hi6421 PMIC driver"); +MODULE_LICENSE("GPL v2"); diff --git a/include/linux/mfd/hi6421-pmic.h b/include/linux/mfd/hi6421-pmic.h new file mode 100644 index 0000000..36bcb34 --- /dev/null +++ b/include/linux/mfd/hi6421-pmic.h @@ -0,0 +1,39 @@ +/* + * Header file for device driver Hi6421 PMIC + * + * Copyright (c) <2011-2014> HiSilicon Technologies Co., Ltd. + * http://www.hisilicon.com + * Copyright (c) <2013-2014> Linaro Ltd. + * http://www.linaro.org + * + * Author: Guodong Xu + * + * 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 __HI6421_PMIC_H +#define __HI6421_PMIC_H + +/* Hi6421 registers are mapped to memory bus in 4 bytes stride */ +#define HI6421_REG_TO_BUS_ADDR(x) (x << 2) + +/* Hi6421 OCP (over current protection) and DEB (debounce) control register */ +#define HI6421_OCP_DEB_CTRL_REG HI6421_REG_TO_BUS_ADDR(0x51) +#define HI6421_OCP_DEB_SEL_MASK (0x0C) +#define HI6421_OCP_DEB_SEL_8MS (0x00) +#define HI6421_OCP_DEB_SEL_16MS (0x04) +#define HI6421_OCP_DEB_SEL_32MS (0x08) +#define HI6421_OCP_DEB_SEL_64MS (0x0C) +#define HI6421_OCP_EN_DEBOUNCE_MASK (0x02) +#define HI6421_OCP_EN_DEBOUNCE_ENABLE (0x02) +#define HI6421_OCP_AUTO_STOP_MASK (0x01) +#define HI6421_OCP_AUTO_STOP_ENABLE (0x01) + +struct hi6421_pmic { + struct device *dev; + struct regmap *regmap; +}; + +#endif /* __HI6421_PMIC_H */