input: touchscreen: Add gt9xx driver support
[platform/kernel/linux-starfive.git] / drivers / regulator / starfive-jh7110-regulator.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2022 Starfive Technology Co., Ltd.
4  * Author: Mason Huo <mason.huo@starfivetech.com>
5  */
6
7 #include <linux/err.h>
8 #include <linux/gpio.h>
9 #include <linux/i2c.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>
19
20 #define JH7110_PM_POWER_SW_0            0x80
21 #define JH7110_PM_POWER_SW_1            0x81
22 #define ENABLE_MASK(id)                 BIT(id)
23
24
25 static const struct regmap_config jh7110_regmap_config = {
26         .reg_bits = 8,
27         .val_bits = 8,
28         .max_register = JH7110_PM_POWER_SW_1,
29         .cache_type = REGCACHE_FLAT,
30 };
31
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,
36 };
37
38 #define JH7110_LDO(_id, _name, en_reg, en_mask) \
39 {\
40         .name = (_name),\
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),\
49 }
50
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),
59 };
60
61 static int jh7110_i2c_probe(struct i2c_client *i2c)
62 {
63         struct regulator_config config = { };
64         struct regulator_dev *rdev;
65         struct regulator_init_data *init_data;
66         struct regmap *regmap;
67         int i, ret;
68
69         regmap = devm_regmap_init_i2c(i2c, &jh7110_regmap_config);
70         if (IS_ERR(regmap)) {
71                 ret = PTR_ERR(regmap);
72                 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
73                         ret);
74                 return ret;
75         }
76
77         init_data = of_get_regulator_init_data(&i2c->dev, i2c->dev.of_node, NULL);
78         if (!init_data)
79                 return -ENOMEM;
80         config.init_data = init_data;
81
82         for (i = 0; i < JH7110_MAX_REGULATORS; i++) {
83                 config.dev = &i2c->dev;
84                 config.regmap = regmap;
85
86                 rdev = devm_regulator_register(&i2c->dev,
87                         &jh7110_regulators[i], &config);
88                 if (IS_ERR(rdev)) {
89                         dev_err(&i2c->dev,
90                                 "Failed to register JH7110 regulator\n");
91                         return PTR_ERR(rdev);
92                 }
93         }
94
95         return 0;
96 }
97
98 static const struct i2c_device_id jh7110_i2c_id[] = {
99         {"jh7110_evb_reg", 0},
100         {},
101 };
102 MODULE_DEVICE_TABLE(i2c, jh7110_i2c_id);
103
104 #ifdef CONFIG_OF
105 static const struct of_device_id jh7110_dt_ids[] = {
106         { .compatible = "starfive,jh7110-evb-regulator",
107           .data = &jh7110_i2c_id[0] },
108         {},
109 };
110 MODULE_DEVICE_TABLE(of, jh7110_dt_ids);
111 #endif
112
113 static struct i2c_driver jh7110_regulator_driver = {
114         .driver = {
115                 .name = "jh7110-evb-regulator",
116                 .of_match_table = of_match_ptr(jh7110_dt_ids),
117         },
118         .probe_new = jh7110_i2c_probe,
119         .id_table = jh7110_i2c_id,
120 };
121
122 module_i2c_driver(jh7110_regulator_driver);
123
124 MODULE_AUTHOR("Mason Huo <mason.huo@starfivetech.com>");
125 MODULE_DESCRIPTION("Regulator device driver for Starfive JH7110");
126 MODULE_LICENSE("GPL v2");