1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Device driver for regulators in HISI PMIC IC
4 *
5 * Copyright (c) 2013 Linaro Ltd.
6 * Copyright (c) 2011 Hisilicon.
7 * Copyright (c) 2020-2021 Huawei Technologies Co., Ltd.
8 */
9
10 #include <linux/mfd/core.h>
11 #include <linux/mfd/hi6421-spmi-pmic.h>
12 #include <linux/module.h>
13 #include <linux/platform_device.h>
14 #include <linux/regmap.h>
15 #include <linux/slab.h>
16 #include <linux/spmi.h>
17
18 static const struct mfd_cell hi6421v600_devs[] = {
19 { .name = "hi6421v600-irq", },
20 { .name = "hi6421v600-regulator", },
21 };
22
23 static const struct regmap_config regmap_config = {
24 .reg_bits = 16,
25 .val_bits = BITS_PER_BYTE,
26 .max_register = 0xffff,
27 .fast_io = true
28 };
29
hi6421_spmi_pmic_probe(struct spmi_device * sdev)30 static int hi6421_spmi_pmic_probe(struct spmi_device *sdev)
31 {
32 struct device *dev = &sdev->dev;
33 int ret;
34 struct hi6421_spmi_pmic *ddata;
35 ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL);
36 if (!ddata)
37 return -ENOMEM;
38
39 ddata->regmap = devm_regmap_init_spmi_ext(sdev, ®map_config);
40 if (IS_ERR(ddata->regmap))
41 return PTR_ERR(ddata->regmap);
42
43 ddata->dev = dev;
44
45 dev_set_drvdata(&sdev->dev, ddata);
46
47 ret = devm_mfd_add_devices(&sdev->dev, PLATFORM_DEVID_NONE,
48 hi6421v600_devs, ARRAY_SIZE(hi6421v600_devs),
49 NULL, 0, NULL);
50 if (ret < 0)
51 dev_err(dev, "Failed to add child devices: %d\n", ret);
52
53 return ret;
54 }
55
56 static const struct of_device_id pmic_spmi_id_table[] = {
57 { .compatible = "hisilicon,hi6421-spmi" },
58 { }
59 };
60 MODULE_DEVICE_TABLE(of, pmic_spmi_id_table);
61
62 static struct spmi_driver hi6421_spmi_pmic_driver = {
63 .driver = {
64 .name = "hi6421-spmi-pmic",
65 .of_match_table = pmic_spmi_id_table,
66 },
67 .probe = hi6421_spmi_pmic_probe,
68 };
69 module_spmi_driver(hi6421_spmi_pmic_driver);
70
71 MODULE_DESCRIPTION("HiSilicon Hi6421v600 SPMI PMIC driver");
72 MODULE_LICENSE("GPL v2");
73