blob: c9c0c3d7011f95ebfda47c2916885d903ecfecc8 [file] [log] [blame]
Mauro Carvalho Chehab4b5e9b32020-08-17 09:10:33 +02001// SPDX-License-Identifier: GPL-2.0
Mauro Carvalho Chehabfb7ba182021-01-29 20:51:55 +01002/*
3 * Device driver for regulators in HISI PMIC IC
4 *
5 * Copyright (c) 2013 Linaro Ltd.
6 * Copyright (c) 2011 Hisilicon.
Mauro Carvalho Chehab49bd5092021-07-17 11:58:14 +02007 * Copyright (c) 2020-2021 Huawei Technologies Co., Ltd.
Mauro Carvalho Chehabfb7ba182021-01-29 20:51:55 +01008 */
Mayulong4524ac52020-08-17 09:10:30 +02009
Mauro Carvalho Chehabcf0f27b2020-08-17 09:10:35 +020010#include <linux/mfd/core.h>
Mauro Carvalho Chehab6b946692020-08-17 09:10:41 +020011#include <linux/module.h>
Mauro Carvalho Chehab6b946692020-08-17 09:10:41 +020012#include <linux/platform_device.h>
Mauro Carvalho Chehabbb3b6552021-07-17 11:58:15 +020013#include <linux/regmap.h>
Mauro Carvalho Chehab6b946692020-08-17 09:10:41 +020014#include <linux/slab.h>
Mayulong4524ac52020-08-17 09:10:30 +020015#include <linux/spmi.h>
Mayulong4524ac52020-08-17 09:10:30 +020016
Mauro Carvalho Chehabcf0f27b2020-08-17 09:10:35 +020017static const struct mfd_cell hi6421v600_devs[] = {
Mauro Carvalho Chehabbb3b6552021-07-17 11:58:15 +020018 { .name = "hi6421v600-irq", },
Mauro Carvalho Chehabcf0f27b2020-08-17 09:10:35 +020019 { .name = "hi6421v600-regulator", },
Mayulong4524ac52020-08-17 09:10:30 +020020};
21
Mauro Carvalho Chehaba2e904f2021-01-29 20:51:50 +010022static const struct regmap_config regmap_config = {
Mauro Carvalho Chehab5ff96c92021-06-25 09:46:00 +020023 .reg_bits = 16,
24 .val_bits = BITS_PER_BYTE,
25 .max_register = 0xffff,
26 .fast_io = true
Mauro Carvalho Chehabfb02e3e2021-01-29 20:51:47 +010027};
28
Mauro Carvalho Chehabb82d45a2021-07-17 11:58:12 +020029static int hi6421_spmi_pmic_probe(struct spmi_device *sdev)
Mayulong4524ac52020-08-17 09:10:30 +020030{
Mauro Carvalho Chehabb82d45a2021-07-17 11:58:12 +020031 struct device *dev = &sdev->dev;
Mauro Carvalho Chehabe68ce0f2021-09-02 14:47:48 +020032 struct regmap *regmap;
Mauro Carvalho Chehabbb3b6552021-07-17 11:58:15 +020033 int ret;
Mayulong4524ac52020-08-17 09:10:30 +020034
Mauro Carvalho Chehabe68ce0f2021-09-02 14:47:48 +020035 regmap = devm_regmap_init_spmi_ext(sdev, &regmap_config);
36 if (IS_ERR(regmap))
37 return PTR_ERR(regmap);
Mauro Carvalho Chehabfb02e3e2021-01-29 20:51:47 +010038
Mauro Carvalho Chehabe68ce0f2021-09-02 14:47:48 +020039 dev_set_drvdata(&sdev->dev, regmap);
Mauro Carvalho Chehabcf0f27b2020-08-17 09:10:35 +020040
Mauro Carvalho Chehabb82d45a2021-07-17 11:58:12 +020041 ret = devm_mfd_add_devices(&sdev->dev, PLATFORM_DEVID_NONE,
Mauro Carvalho Chehabcf0f27b2020-08-17 09:10:35 +020042 hi6421v600_devs, ARRAY_SIZE(hi6421v600_devs),
43 NULL, 0, NULL);
Mauro Carvalho Chehaba2e904f2021-01-29 20:51:50 +010044 if (ret < 0)
45 dev_err(dev, "Failed to add child devices: %d\n", ret);
Mauro Carvalho Chehab6b946692020-08-17 09:10:41 +020046
Mayulong4524ac52020-08-17 09:10:30 +020047 return ret;
48}
49
Mauro Carvalho Chehabcf0f27b2020-08-17 09:10:35 +020050static const struct of_device_id pmic_spmi_id_table[] = {
Mauro Carvalho Chehab9f46c342020-08-18 16:58:56 +020051 { .compatible = "hisilicon,hi6421-spmi" },
Mauro Carvalho Chehabcf0f27b2020-08-17 09:10:35 +020052 { }
53};
54MODULE_DEVICE_TABLE(of, pmic_spmi_id_table);
Mayulong4524ac52020-08-17 09:10:30 +020055
Mauro Carvalho Chehab1eb27842020-08-17 09:10:38 +020056static struct spmi_driver hi6421_spmi_pmic_driver = {
Mayulong4524ac52020-08-17 09:10:30 +020057 .driver = {
Mauro Carvalho Chehabcf0f27b2020-08-17 09:10:35 +020058 .name = "hi6421-spmi-pmic",
59 .of_match_table = pmic_spmi_id_table,
Mayulong4524ac52020-08-17 09:10:30 +020060 },
Mauro Carvalho Chehab1eb27842020-08-17 09:10:38 +020061 .probe = hi6421_spmi_pmic_probe,
Mayulong4524ac52020-08-17 09:10:30 +020062};
Mauro Carvalho Chehab1eb27842020-08-17 09:10:38 +020063module_spmi_driver(hi6421_spmi_pmic_driver);
Mayulong4524ac52020-08-17 09:10:30 +020064
Mauro Carvalho Chehabcf0f27b2020-08-17 09:10:35 +020065MODULE_DESCRIPTION("HiSilicon Hi6421v600 SPMI PMIC driver");
Mayulong4524ac52020-08-17 09:10:30 +020066MODULE_LICENSE("GPL v2");