1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2022 Starfive Technology Co., Ltd.
4 * Author: Mason Huo <mason.huo@starfivetech.com>
8 #include <linux/gpio.h>
10 #include <linux/init.h>
11 #include <linux/interrupt.h>
12 #include <linux/module.h>
13 #include <linux/regmap.h>
14 #include <linux/regulator/driver.h>
15 #include <linux/regulator/machine.h>
16 #include <linux/regulator/of_regulator.h>
17 #include <linux/regulator/jh7110.h>
18 #include <linux/slab.h>
20 #define JH7110_PM_POWER_SW_0 0x80
21 #define JH7110_PM_POWER_SW_1 0x81
22 #define ENABLE_MASK(id) BIT(id)
25 static const struct regmap_config jh7110_regmap_config = {
28 .max_register = JH7110_PM_POWER_SW_1,
29 .cache_type = REGCACHE_FLAT,
32 static const struct regulator_ops jh7110_ldo_ops = {
33 .enable = regulator_enable_regmap,
34 .disable = regulator_disable_regmap,
35 .is_enabled = regulator_is_enabled_regmap,
38 #define JH7110_LDO(_id, _name, en_reg, en_mask) \
41 .ops = &jh7110_ldo_ops,\
42 .of_match = of_match_ptr(_name),\
43 .regulators_node = of_match_ptr("regulators"),\
44 .type = REGULATOR_VOLTAGE,\
45 .id = JH7110_ID_##_id,\
46 .owner = THIS_MODULE,\
47 .enable_reg = JH7110_PM_POWER_SW_##en_reg,\
48 .enable_mask = ENABLE_MASK(en_mask),\
51 static const struct regulator_desc jh7110_regulators[] = {
52 JH7110_LDO(LDO_REG1, "hdmi_1p8", 0, 0),
53 JH7110_LDO(LDO_REG2, "mipitx_1p8", 0, 1),
54 JH7110_LDO(LDO_REG3, "mipirx_1p8", 0, 2),
55 JH7110_LDO(LDO_REG4, "hdmi_0p9", 0, 3),
56 JH7110_LDO(LDO_REG5, "mipitx_0p9", 0, 4),
57 JH7110_LDO(LDO_REG6, "mipirx_0p9", 0, 5),
58 JH7110_LDO(LDO_REG7, "sdio_vdd", 1, 0),
61 static int jh7110_i2c_probe(struct i2c_client *i2c)
63 struct regulator_config config = { };
64 struct regulator_dev *rdev;
65 struct regulator_init_data *init_data;
66 struct regmap *regmap;
69 regmap = devm_regmap_init_i2c(i2c, &jh7110_regmap_config);
71 ret = PTR_ERR(regmap);
72 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
77 init_data = of_get_regulator_init_data(&i2c->dev, i2c->dev.of_node, NULL);
80 config.init_data = init_data;
82 for (i = 0; i < JH7110_MAX_REGULATORS; i++) {
83 config.dev = &i2c->dev;
84 config.regmap = regmap;
86 rdev = devm_regulator_register(&i2c->dev,
87 &jh7110_regulators[i], &config);
90 "Failed to register JH7110 regulator\n");
98 static const struct i2c_device_id jh7110_i2c_id[] = {
99 {"jh7110_evb_reg", 0},
102 MODULE_DEVICE_TABLE(i2c, jh7110_i2c_id);
105 static const struct of_device_id jh7110_dt_ids[] = {
106 { .compatible = "starfive,jh7110-evb-regulator",
107 .data = &jh7110_i2c_id[0] },
110 MODULE_DEVICE_TABLE(of, jh7110_dt_ids);
113 static struct i2c_driver jh7110_regulator_driver = {
115 .name = "jh7110-evb-regulator",
116 .of_match_table = of_match_ptr(jh7110_dt_ids),
118 .probe_new = jh7110_i2c_probe,
119 .id_table = jh7110_i2c_id,
122 module_i2c_driver(jh7110_regulator_driver);
124 MODULE_AUTHOR("Mason Huo <mason.huo@starfivetech.com>");
125 MODULE_DESCRIPTION("Regulator device driver for Starfive JH7110");
126 MODULE_LICENSE("GPL v2");