Linux Audio

Check our new training course

Real-Time Linux with PREEMPT_RT training

Feb 18-20, 2025
Register
Loading...
v6.2
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Device driver for Hi6421 PMIC
  4 *
  5 * Copyright (c) <2011-2014> HiSilicon Technologies Co., Ltd.
  6 *              http://www.hisilicon.com
  7 * Copyright (c) <2013-2017> Linaro Ltd.
  8 *              https://www.linaro.org
  9 *
 10 * Author: Guodong Xu <guodong.xu@linaro.org>
 
 
 
 
 
 
 
 
 
 
 
 
 
 11 */
 12
 13#include <linux/device.h>
 14#include <linux/err.h>
 15#include <linux/mfd/core.h>
 16#include <linux/mfd/hi6421-pmic.h>
 17#include <linux/module.h>
 18#include <linux/of_device.h>
 19#include <linux/platform_device.h>
 20#include <linux/regmap.h>
 
 21
 22static const struct mfd_cell hi6421_devs[] = {
 23	{ .name = "hi6421-regulator", },
 24};
 25
 26static const struct mfd_cell hi6421v530_devs[] = {
 27	{ .name = "hi6421v530-regulator", },
 28};
 29
 30static const struct regmap_config hi6421_regmap_config = {
 31	.reg_bits = 32,
 32	.reg_stride = 4,
 33	.val_bits = 8,
 34	.max_register = HI6421_REG_TO_BUS_ADDR(HI6421_REG_MAX),
 35};
 36
 37static const struct of_device_id of_hi6421_pmic_match[] = {
 38	{
 39		.compatible = "hisilicon,hi6421-pmic",
 40		.data = (void *)HI6421
 41	},
 42	{
 43		.compatible = "hisilicon,hi6421v530-pmic",
 44		.data = (void *)HI6421_V530
 45	},
 46	{ },
 47};
 48MODULE_DEVICE_TABLE(of, of_hi6421_pmic_match);
 49
 50static int hi6421_pmic_probe(struct platform_device *pdev)
 51{
 52	struct hi6421_pmic *pmic;
 53	struct resource *res;
 54	const struct of_device_id *id;
 55	const struct mfd_cell *subdevs;
 56	enum hi6421_type type;
 57	void __iomem *base;
 58	int n_subdevs, ret;
 59
 60	id = of_match_device(of_hi6421_pmic_match, &pdev->dev);
 61	if (!id)
 62		return -EINVAL;
 63	type = (enum hi6421_type)id->data;
 64
 65	pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL);
 66	if (!pmic)
 67		return -ENOMEM;
 68
 69	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 70	base = devm_ioremap_resource(&pdev->dev, res);
 71	if (IS_ERR(base))
 72		return PTR_ERR(base);
 73
 74	pmic->regmap = devm_regmap_init_mmio_clk(&pdev->dev, NULL, base,
 75						 &hi6421_regmap_config);
 76	if (IS_ERR(pmic->regmap)) {
 77		dev_err(&pdev->dev, "Failed to initialise Regmap: %ld\n",
 78						PTR_ERR(pmic->regmap));
 79		return PTR_ERR(pmic->regmap);
 80	}
 81
 82	platform_set_drvdata(pdev, pmic);
 83
 84	switch (type) {
 85	case HI6421:
 86		/* set over-current protection debounce 8ms */
 87		regmap_update_bits(pmic->regmap, HI6421_OCP_DEB_CTRL_REG,
 88				(HI6421_OCP_DEB_SEL_MASK
 89				 | HI6421_OCP_EN_DEBOUNCE_MASK
 90				 | HI6421_OCP_AUTO_STOP_MASK),
 91				(HI6421_OCP_DEB_SEL_8MS
 92				 | HI6421_OCP_EN_DEBOUNCE_ENABLE));
 93
 94		subdevs = hi6421_devs;
 95		n_subdevs = ARRAY_SIZE(hi6421_devs);
 96		break;
 97	case HI6421_V530:
 98		subdevs = hi6421v530_devs;
 99		n_subdevs = ARRAY_SIZE(hi6421v530_devs);
100		break;
101	default:
102		dev_err(&pdev->dev, "Unknown device type %d\n",
103						(unsigned int)type);
104		return -EINVAL;
105	}
106
107	ret = devm_mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE,
108				   subdevs, n_subdevs, NULL, 0, NULL);
109	if (ret) {
110		dev_err(&pdev->dev, "Failed to add child devices: %d\n", ret);
111		return ret;
112	}
113
114	return 0;
115}
116
 
 
 
 
 
 
117static struct platform_driver hi6421_pmic_driver = {
118	.driver = {
119		.name = "hi6421_pmic",
120		.of_match_table = of_hi6421_pmic_match,
121	},
122	.probe	= hi6421_pmic_probe,
123};
124module_platform_driver(hi6421_pmic_driver);
125
126MODULE_AUTHOR("Guodong Xu <guodong.xu@linaro.org>");
127MODULE_DESCRIPTION("Hi6421 PMIC driver");
128MODULE_LICENSE("GPL v2");
v4.10.11
 
  1/*
  2 * Device driver for Hi6421 IC
  3 *
  4 * Copyright (c) <2011-2014> HiSilicon Technologies Co., Ltd.
  5 *              http://www.hisilicon.com
  6 * Copyright (c) <2013-2014> Linaro Ltd.
  7 *              http://www.linaro.org
  8 *
  9 * Author: Guodong Xu <guodong.xu@linaro.org>
 10 *
 11 * This program is free software; you can redistribute it and/or modify
 12 * it under the terms of the GNU General Public License as published by
 13 * the Free Software Foundation; either version 2 of the License, or
 14 * (at your option) any later version.
 15 *
 16 * This program is distributed in the hope it will be useful, but WITHOUT
 17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 18 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 19 * more details.
 20 *
 21 * You should have received a copy of the GNU General Public License
 22 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 23 */
 24
 25#include <linux/device.h>
 26#include <linux/err.h>
 27#include <linux/mfd/core.h>
 
 28#include <linux/module.h>
 29#include <linux/of.h>
 30#include <linux/platform_device.h>
 31#include <linux/regmap.h>
 32#include <linux/mfd/hi6421-pmic.h>
 33
 34static const struct mfd_cell hi6421_devs[] = {
 35	{ .name = "hi6421-regulator", },
 36};
 37
 
 
 
 
 38static const struct regmap_config hi6421_regmap_config = {
 39	.reg_bits = 32,
 40	.reg_stride = 4,
 41	.val_bits = 8,
 42	.max_register = HI6421_REG_TO_BUS_ADDR(HI6421_REG_MAX),
 43};
 44
 
 
 
 
 
 
 
 
 
 
 
 
 
 45static int hi6421_pmic_probe(struct platform_device *pdev)
 46{
 47	struct hi6421_pmic *pmic;
 48	struct resource *res;
 
 
 
 49	void __iomem *base;
 50	int ret;
 
 
 
 
 
 51
 52	pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL);
 53	if (!pmic)
 54		return -ENOMEM;
 55
 56	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 57	base = devm_ioremap_resource(&pdev->dev, res);
 58	if (IS_ERR(base))
 59		return PTR_ERR(base);
 60
 61	pmic->regmap = devm_regmap_init_mmio_clk(&pdev->dev, NULL, base,
 62						 &hi6421_regmap_config);
 63	if (IS_ERR(pmic->regmap)) {
 64		dev_err(&pdev->dev,
 65			"regmap init failed: %ld\n", PTR_ERR(pmic->regmap));
 66		return PTR_ERR(pmic->regmap);
 67	}
 68
 69	/* set over-current protection debounce 8ms */
 70	regmap_update_bits(pmic->regmap, HI6421_OCP_DEB_CTRL_REG,
 
 
 
 
 71				(HI6421_OCP_DEB_SEL_MASK
 72				 | HI6421_OCP_EN_DEBOUNCE_MASK
 73				 | HI6421_OCP_AUTO_STOP_MASK),
 74				(HI6421_OCP_DEB_SEL_8MS
 75				 | HI6421_OCP_EN_DEBOUNCE_ENABLE));
 76
 77	platform_set_drvdata(pdev, pmic);
 
 
 
 
 
 
 
 
 
 
 
 78
 79	ret = devm_mfd_add_devices(&pdev->dev, 0, hi6421_devs,
 80				   ARRAY_SIZE(hi6421_devs), NULL, 0, NULL);
 81	if (ret) {
 82		dev_err(&pdev->dev, "add mfd devices failed: %d\n", ret);
 83		return ret;
 84	}
 85
 86	return 0;
 87}
 88
 89static const struct of_device_id of_hi6421_pmic_match_tbl[] = {
 90	{ .compatible = "hisilicon,hi6421-pmic", },
 91	{ },
 92};
 93MODULE_DEVICE_TABLE(of, of_hi6421_pmic_match_tbl);
 94
 95static struct platform_driver hi6421_pmic_driver = {
 96	.driver = {
 97		.name	= "hi6421_pmic",
 98		.of_match_table = of_hi6421_pmic_match_tbl,
 99	},
100	.probe	= hi6421_pmic_probe,
101};
102module_platform_driver(hi6421_pmic_driver);
103
104MODULE_AUTHOR("Guodong Xu <guodong.xu@linaro.org>");
105MODULE_DESCRIPTION("Hi6421 PMIC driver");
106MODULE_LICENSE("GPL v2");