a4ae8b38a952e9322e6a95a31296cca73246dd57
[openwrt.git] / target / linux / mediatek / patches-4.4 / 0047-regulator-mt6323-Add-support-for-MT6323-regulator.patch
1 From 031a2ff537366855e88bc95e5d42ea522b6c5ad8 Mon Sep 17 00:00:00 2001
2 From: Chen Zhong <chen.zhong@mediatek.com>
3 Date: Fri, 8 Jan 2016 04:17:37 +0100
4 Subject: [PATCH 47/81] regulator: mt6323: Add support for MT6323 regulator
5
6 The MT6323 is a regulator found on boards based on MediaTek MT7623 and
7 probably other SoCs. It is a so called pmic and connects as a slave to
8 SoC using SPI, wrapped inside the pmic-wrapper.
9
10 Signed-off-by: Chen Zhong <chen.zhong@mediatek.com>
11 Signed-off-by: John Crispin <blogic@openwrt.org>
12 ---
13  drivers/regulator/Kconfig                  |    9 +
14  drivers/regulator/Makefile                 |    1 +
15  drivers/regulator/mt6323-regulator.c       |  432 ++++++++++++++++++++++++++++
16  include/linux/regulator/mt6323-regulator.h |   52 ++++
17  4 files changed, 494 insertions(+)
18  create mode 100644 drivers/regulator/mt6323-regulator.c
19  create mode 100644 include/linux/regulator/mt6323-regulator.h
20
21 diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
22 index 8df0b0e..4aec931 100644
23 --- a/drivers/regulator/Kconfig
24 +++ b/drivers/regulator/Kconfig
25 @@ -452,6 +452,15 @@ config REGULATOR_MT6311
26           This driver supports the control of different power rails of device
27           through regulator interface.
28  
29 +config REGULATOR_MT6323
30 +       tristate "MediaTek MT6323 PMIC"
31 +       depends on MFD_MT6397
32 +       help
33 +         Say y here to select this option to enable the power regulator of
34 +         MediaTek MT6323 PMIC.
35 +         This driver supports the control of different power rails of device
36 +         through regulator interface.
37 +
38  config REGULATOR_MT6397
39         tristate "MediaTek MT6397 PMIC"
40         depends on MFD_MT6397
41 diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
42 index 0f81749..b42a84e 100644
43 --- a/drivers/regulator/Makefile
44 +++ b/drivers/regulator/Makefile
45 @@ -60,6 +60,7 @@ obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o
46  obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o
47  obj-$(CONFIG_REGULATOR_MC13XXX_CORE) +=  mc13xxx-regulator-core.o
48  obj-$(CONFIG_REGULATOR_MT6311) += mt6311-regulator.o
49 +obj-$(CONFIG_REGULATOR_MT6323) += mt6323-regulator.o
50  obj-$(CONFIG_REGULATOR_MT6397) += mt6397-regulator.o
51  obj-$(CONFIG_REGULATOR_QCOM_RPM) += qcom_rpm-regulator.o
52  obj-$(CONFIG_REGULATOR_QCOM_SMD_RPM) += qcom_smd-regulator.o
53 diff --git a/drivers/regulator/mt6323-regulator.c b/drivers/regulator/mt6323-regulator.c
54 new file mode 100644
55 index 0000000..28ebbda
56 --- /dev/null
57 +++ b/drivers/regulator/mt6323-regulator.c
58 @@ -0,0 +1,432 @@
59 +/*
60 + * Copyright (c) 2016 MediaTek Inc.
61 + * Author: Chen Zhong <chen.zhong@mediatek.com>
62 + *
63 + * This program is free software; you can redistribute it and/or modify
64 + * it under the terms of the GNU General Public License version 2 as
65 + * published by the Free Software Foundation.
66 + */
67 +
68 +#include <linux/module.h>
69 +#include <linux/of.h>
70 +#include <linux/platform_device.h>
71 +#include <linux/regmap.h>
72 +#include <linux/mfd/mt6397/core.h>
73 +#include <linux/mfd/mt6323/registers.h>
74 +#include <linux/regulator/driver.h>
75 +#include <linux/regulator/machine.h>
76 +#include <linux/regulator/mt6323-regulator.h>
77 +#include <linux/regulator/of_regulator.h>
78 +
79 +#define MT6323_LDO_MODE_NORMAL 0
80 +#define MT6323_LDO_MODE_LP     1
81 +
82 +/*
83 + * MT6323 regulators' information
84 + *
85 + * @desc: standard fields of regulator description.
86 + * @qi: Mask for query enable signal status of regulators
87 + * @vselon_reg: Register sections for hardware control mode of bucks
88 + * @vselctrl_reg: Register for controlling the buck control mode.
89 + * @vselctrl_mask: Mask for query buck's voltage control mode.
90 + */
91 +struct mt6323_regulator_info {
92 +       struct regulator_desc desc;
93 +       u32 qi;
94 +       u32 vselon_reg;
95 +       u32 vselctrl_reg;
96 +       u32 vselctrl_mask;
97 +       u32 modeset_reg;
98 +       u32 modeset_mask;
99 +};
100 +
101 +#define MT6323_BUCK(match, vreg, min, max, step, volt_ranges, enreg,   \
102 +               vosel, vosel_mask, voselon, vosel_ctrl)                 \
103 +[MT6323_ID_##vreg] = {                                                 \
104 +       .desc = {                                                       \
105 +               .name = #vreg,                                          \
106 +               .of_match = of_match_ptr(match),                        \
107 +               .ops = &mt6323_volt_range_ops,                          \
108 +               .type = REGULATOR_VOLTAGE,                              \
109 +               .id = MT6323_ID_##vreg,                                 \
110 +               .owner = THIS_MODULE,                                   \
111 +               .n_voltages = (max - min)/step + 1,                     \
112 +               .linear_ranges = volt_ranges,                           \
113 +               .n_linear_ranges = ARRAY_SIZE(volt_ranges),             \
114 +               .vsel_reg = vosel,                                      \
115 +               .vsel_mask = vosel_mask,                                \
116 +               .enable_reg = enreg,                                    \
117 +               .enable_mask = BIT(0),                                  \
118 +       },                                                              \
119 +       .qi = BIT(13),                                                  \
120 +       .vselon_reg = voselon,                                          \
121 +       .vselctrl_reg = vosel_ctrl,                                     \
122 +       .vselctrl_mask = BIT(1),                                        \
123 +}
124 +
125 +#define MT6323_LDO(match, vreg, ldo_volt_table, enreg, enbit, vosel,   \
126 +               vosel_mask, _modeset_reg, _modeset_mask)                \
127 +[MT6323_ID_##vreg] = {                                                 \
128 +       .desc = {                                                       \
129 +               .name = #vreg,                                          \
130 +               .of_match = of_match_ptr(match),                        \
131 +               .ops = &mt6323_volt_table_ops,                          \
132 +               .type = REGULATOR_VOLTAGE,                              \
133 +               .id = MT6323_ID_##vreg,                                 \
134 +               .owner = THIS_MODULE,                                   \
135 +               .n_voltages = ARRAY_SIZE(ldo_volt_table),               \
136 +               .volt_table = ldo_volt_table,                           \
137 +               .vsel_reg = vosel,                                      \
138 +               .vsel_mask = vosel_mask,                                \
139 +               .enable_reg = enreg,                                    \
140 +               .enable_mask = BIT(enbit),                              \
141 +       },                                                              \
142 +       .qi = BIT(15),                                                  \
143 +       .modeset_reg = _modeset_reg,                                    \
144 +       .modeset_mask = _modeset_mask,                                  \
145 +}
146 +
147 +#define MT6323_REG_FIXED(match, vreg, enreg, enbit, volt,              \
148 +               _modeset_reg, _modeset_mask)                            \
149 +[MT6323_ID_##vreg] = {                                                 \
150 +       .desc = {                                                       \
151 +               .name = #vreg,                                          \
152 +               .of_match = of_match_ptr(match),                        \
153 +               .ops = &mt6323_volt_fixed_ops,                          \
154 +               .type = REGULATOR_VOLTAGE,                              \
155 +               .id = MT6323_ID_##vreg,                                 \
156 +               .owner = THIS_MODULE,                                   \
157 +               .n_voltages = 1,                                        \
158 +               .enable_reg = enreg,                                    \
159 +               .enable_mask = BIT(enbit),                              \
160 +               .min_uV = volt,                                         \
161 +       },                                                              \
162 +       .qi = BIT(15),                                                  \
163 +       .modeset_reg = _modeset_reg,                                    \
164 +       .modeset_mask = _modeset_mask,                                  \
165 +}
166 +
167 +static const struct regulator_linear_range buck_volt_range1[] = {
168 +       REGULATOR_LINEAR_RANGE(700000, 0, 0x7f, 6250),
169 +};
170 +
171 +static const struct regulator_linear_range buck_volt_range2[] = {
172 +       REGULATOR_LINEAR_RANGE(1400000, 0, 0x7f, 12500),
173 +};
174 +
175 +static const struct regulator_linear_range buck_volt_range3[] = {
176 +       REGULATOR_LINEAR_RANGE(500000, 0, 0x3f, 50000),
177 +};
178 +
179 +static const u32 ldo_volt_table1[] = {
180 +       3300000, 3400000, 3500000, 3600000,
181 +};
182 +
183 +static const u32 ldo_volt_table2[] = {
184 +       1500000, 1800000, 2500000, 2800000,
185 +};
186 +
187 +static const u32 ldo_volt_table3[] = {
188 +       1800000, 3300000,
189 +};
190 +
191 +static const u32 ldo_volt_table4[] = {
192 +       3000000, 3300000,
193 +};
194 +
195 +static const u32 ldo_volt_table5[] = {
196 +       1200000, 1300000, 1500000, 1800000, 2000000, 2800000, 3000000, 3300000,
197 +};
198 +
199 +static const u32 ldo_volt_table6[] = {
200 +       1200000, 1300000, 1500000, 1800000, 2500000, 2800000, 3000000, 2000000,
201 +};
202 +
203 +static const u32 ldo_volt_table7[] = {
204 +       1200000, 1300000, 1500000, 1800000,
205 +};
206 +
207 +static const u32 ldo_volt_table8[] = {
208 +       1800000, 3000000,
209 +};
210 +
211 +static const u32 ldo_volt_table9[] = {
212 +       1200000, 1350000, 1500000, 1800000,
213 +};
214 +
215 +static const u32 ldo_volt_table10[] = {
216 +       1200000, 1300000, 1500000, 1800000,
217 +};
218 +
219 +static int mt6323_get_status(struct regulator_dev *rdev)
220 +{
221 +       int ret;
222 +       u32 regval;
223 +       struct mt6323_regulator_info *info = rdev_get_drvdata(rdev);
224 +
225 +       ret = regmap_read(rdev->regmap, info->desc.enable_reg, &regval);
226 +       if (ret != 0) {
227 +               dev_err(&rdev->dev, "Failed to get enable reg: %d\n", ret);
228 +               return ret;
229 +       }
230 +
231 +       return (regval & info->qi) ? REGULATOR_STATUS_ON : REGULATOR_STATUS_OFF;
232 +}
233 +
234 +static int mt6323_ldo_set_mode(struct regulator_dev *rdev, unsigned int mode)
235 +{
236 +       int ret, val = 0;
237 +       struct mt6323_regulator_info *info = rdev_get_drvdata(rdev);
238 +
239 +       if (!info->modeset_mask) {
240 +               dev_err(&rdev->dev, "regulator %s doesn't support set_mode\n",
241 +                       info->desc.name);
242 +               return -EINVAL;
243 +       }
244 +
245 +       switch (mode) {
246 +       case REGULATOR_MODE_STANDBY:
247 +               val = MT6323_LDO_MODE_LP;
248 +               break;
249 +       case REGULATOR_MODE_NORMAL:
250 +               val = MT6323_LDO_MODE_NORMAL;
251 +               break;
252 +       default:
253 +               return -EINVAL;
254 +       }
255 +
256 +       val <<= ffs(info->modeset_mask) - 1;
257 +
258 +       ret = regmap_update_bits(rdev->regmap, info->modeset_reg,
259 +                                 info->modeset_mask, val);
260 +
261 +       return ret;
262 +}
263 +
264 +static unsigned int mt6323_ldo_get_mode(struct regulator_dev *rdev)
265 +{
266 +       unsigned int val;
267 +       unsigned int mode;
268 +       int ret;
269 +       struct mt6323_regulator_info *info = rdev_get_drvdata(rdev);
270 +
271 +       if (!info->modeset_mask) {
272 +               dev_err(&rdev->dev, "regulator %s doesn't support get_mode\n",
273 +                       info->desc.name);
274 +               return -EINVAL;
275 +       }
276 +
277 +       ret = regmap_read(rdev->regmap, info->modeset_reg, &val);
278 +       if (ret < 0)
279 +               return ret;
280 +
281 +       val &= info->modeset_mask;
282 +       val >>= ffs(info->modeset_mask) - 1;
283 +
284 +       if (val & 0x1)
285 +               mode = REGULATOR_MODE_STANDBY;
286 +       else
287 +               mode = REGULATOR_MODE_NORMAL;
288 +
289 +       return mode;
290 +}
291 +
292 +static struct regulator_ops mt6323_volt_range_ops = {
293 +       .list_voltage = regulator_list_voltage_linear_range,
294 +       .map_voltage = regulator_map_voltage_linear_range,
295 +       .set_voltage_sel = regulator_set_voltage_sel_regmap,
296 +       .get_voltage_sel = regulator_get_voltage_sel_regmap,
297 +       .set_voltage_time_sel = regulator_set_voltage_time_sel,
298 +       .enable = regulator_enable_regmap,
299 +       .disable = regulator_disable_regmap,
300 +       .is_enabled = regulator_is_enabled_regmap,
301 +       .get_status = mt6323_get_status,
302 +};
303 +
304 +static struct regulator_ops mt6323_volt_table_ops = {
305 +       .list_voltage = regulator_list_voltage_table,
306 +       .map_voltage = regulator_map_voltage_iterate,
307 +       .set_voltage_sel = regulator_set_voltage_sel_regmap,
308 +       .get_voltage_sel = regulator_get_voltage_sel_regmap,
309 +       .set_voltage_time_sel = regulator_set_voltage_time_sel,
310 +       .enable = regulator_enable_regmap,
311 +       .disable = regulator_disable_regmap,
312 +       .is_enabled = regulator_is_enabled_regmap,
313 +       .get_status = mt6323_get_status,
314 +       .set_mode = mt6323_ldo_set_mode,
315 +       .get_mode = mt6323_ldo_get_mode,
316 +};
317 +
318 +static struct regulator_ops mt6323_volt_fixed_ops = {
319 +       .list_voltage = regulator_list_voltage_linear,
320 +       .enable = regulator_enable_regmap,
321 +       .disable = regulator_disable_regmap,
322 +       .is_enabled = regulator_is_enabled_regmap,
323 +       .get_status = mt6323_get_status,
324 +       .set_mode = mt6323_ldo_set_mode,
325 +       .get_mode = mt6323_ldo_get_mode,
326 +};
327 +
328 +/* The array is indexed by id(MT6323_ID_XXX) */
329 +static struct mt6323_regulator_info mt6323_regulators[] = {
330 +       MT6323_BUCK("buck_vproc", VPROC, 700000, 1493750, 6250,
331 +               buck_volt_range1, MT6323_VPROC_CON7, MT6323_VPROC_CON9, 0x7f,
332 +               MT6323_VPROC_CON10, MT6323_VPROC_CON5),
333 +       MT6323_BUCK("buck_vsys", VSYS, 1400000, 2987500, 12500,
334 +               buck_volt_range2, MT6323_VSYS_CON7, MT6323_VSYS_CON9, 0x7f,
335 +               MT6323_VSYS_CON10, MT6323_VSYS_CON5),
336 +       MT6323_BUCK("buck_vpa", VPA, 500000, 3650000, 50000,
337 +               buck_volt_range3, MT6323_VPA_CON7, MT6323_VPA_CON9,
338 +               0x3f, MT6323_VPA_CON10, MT6323_VPA_CON5),
339 +       MT6323_REG_FIXED("ldo_vtcxo", VTCXO, MT6323_ANALDO_CON1, 10, 2800000,
340 +               MT6323_ANALDO_CON1, 0x2),
341 +       MT6323_REG_FIXED("ldo_vcn28", VCN28, MT6323_ANALDO_CON19, 12, 2800000,
342 +               MT6323_ANALDO_CON20, 0x2),
343 +       MT6323_LDO("ldo_vcn33_bt", VCN33_BT, ldo_volt_table1,
344 +               MT6323_ANALDO_CON16, 7, MT6323_ANALDO_CON16, 0xC,
345 +               MT6323_ANALDO_CON21, 0x2),
346 +       MT6323_LDO("ldo_vcn33_wifi", VCN33_WIFI, ldo_volt_table1,
347 +               MT6323_ANALDO_CON17, 12, MT6323_ANALDO_CON16, 0xC,
348 +               MT6323_ANALDO_CON21, 0x2),
349 +       MT6323_REG_FIXED("ldo_va", VA, MT6323_ANALDO_CON2, 14, 2800000,
350 +               MT6323_ANALDO_CON2, 0x2),
351 +       MT6323_LDO("ldo_vcama", VCAMA, ldo_volt_table2,
352 +               MT6323_ANALDO_CON4, 15, MT6323_ANALDO_CON10, 0x60, -1, 0),
353 +       MT6323_REG_FIXED("ldo_vio28", VIO28, MT6323_DIGLDO_CON0, 14, 2800000,
354 +               MT6323_DIGLDO_CON0, 0x2),
355 +       MT6323_REG_FIXED("ldo_vusb", VUSB, MT6323_DIGLDO_CON2, 14, 3300000,
356 +               MT6323_DIGLDO_CON2, 0x2),
357 +       MT6323_LDO("ldo_vmc", VMC, ldo_volt_table3,
358 +               MT6323_DIGLDO_CON3, 12, MT6323_DIGLDO_CON24, 0x10,
359 +               MT6323_DIGLDO_CON3, 0x2),
360 +       MT6323_LDO("ldo_vmch", VMCH, ldo_volt_table4,
361 +               MT6323_DIGLDO_CON5, 14, MT6323_DIGLDO_CON26, 0x80,
362 +               MT6323_DIGLDO_CON5, 0x2),
363 +       MT6323_LDO("ldo_vemc3v3", VEMC3V3, ldo_volt_table4,
364 +               MT6323_DIGLDO_CON6, 14, MT6323_DIGLDO_CON27, 0x80,
365 +               MT6323_DIGLDO_CON6, 0x2),
366 +       MT6323_LDO("ldo_vgp1", VGP1, ldo_volt_table5,
367 +               MT6323_DIGLDO_CON7, 15, MT6323_DIGLDO_CON28, 0xE0,
368 +               MT6323_DIGLDO_CON7, 0x2),
369 +       MT6323_LDO("ldo_vgp2", VGP2, ldo_volt_table6,
370 +               MT6323_DIGLDO_CON8, 15, MT6323_DIGLDO_CON29, 0xE0,
371 +               MT6323_DIGLDO_CON8, 0x2),
372 +       MT6323_LDO("ldo_vgp3", VGP3, ldo_volt_table7,
373 +               MT6323_DIGLDO_CON9, 15, MT6323_DIGLDO_CON30, 0x60,
374 +               MT6323_DIGLDO_CON9, 0x2),
375 +       MT6323_REG_FIXED("ldo_vcn18", VCN18, MT6323_DIGLDO_CON11, 14, 1800000,
376 +               MT6323_DIGLDO_CON11, 0x2),
377 +       MT6323_LDO("ldo_vsim1", VSIM1, ldo_volt_table8,
378 +               MT6323_DIGLDO_CON13, 15, MT6323_DIGLDO_CON34, 0x20,
379 +               MT6323_DIGLDO_CON13, 0x2),
380 +       MT6323_LDO("ldo_vsim2", VSIM2, ldo_volt_table8,
381 +               MT6323_DIGLDO_CON14, 15, MT6323_DIGLDO_CON35, 0x20,
382 +               MT6323_DIGLDO_CON14, 0x2),
383 +       MT6323_REG_FIXED("ldo_vrtc", VRTC, MT6323_DIGLDO_CON15, 8, 2800000,
384 +               -1, 0),
385 +       MT6323_LDO("ldo_vcamaf", VCAMAF, ldo_volt_table5,
386 +               MT6323_DIGLDO_CON31, 15, MT6323_DIGLDO_CON32, 0xE0,
387 +               MT6323_DIGLDO_CON31, 0x2),
388 +       MT6323_LDO("ldo_vibr", VIBR, ldo_volt_table5,
389 +               MT6323_DIGLDO_CON39, 15, MT6323_DIGLDO_CON40, 0xE0,
390 +               MT6323_DIGLDO_CON39, 0x2),
391 +       MT6323_REG_FIXED("ldo_vrf18", VRF18, MT6323_DIGLDO_CON45, 15, 1825000,
392 +               MT6323_DIGLDO_CON45, 0x2),
393 +       MT6323_LDO("ldo_vm", VM, ldo_volt_table9,
394 +               MT6323_DIGLDO_CON47, 14, MT6323_DIGLDO_CON48, 0x30,
395 +               MT6323_DIGLDO_CON47, 0x2),
396 +       MT6323_REG_FIXED("ldo_vio18", VIO18, MT6323_DIGLDO_CON49, 14, 1800000,
397 +               MT6323_DIGLDO_CON49, 0x2),
398 +       MT6323_LDO("ldo_vcamd", VCAMD, ldo_volt_table10,
399 +               MT6323_DIGLDO_CON51, 14, MT6323_DIGLDO_CON52, 0x60,
400 +               MT6323_DIGLDO_CON51, 0x2),
401 +       MT6323_REG_FIXED("ldo_vcamio", VCAMIO, MT6323_DIGLDO_CON53, 14, 1800000,
402 +               MT6323_DIGLDO_CON53, 0x2),
403 +};
404 +
405 +static int mt6323_set_buck_vosel_reg(struct platform_device *pdev)
406 +{
407 +       struct mt6397_chip *mt6323 = dev_get_drvdata(pdev->dev.parent);
408 +       int i;
409 +       u32 regval;
410 +
411 +       for (i = 0; i < MT6323_MAX_REGULATOR; i++) {
412 +               if (mt6323_regulators[i].vselctrl_reg) {
413 +                       if (regmap_read(mt6323->regmap,
414 +                               mt6323_regulators[i].vselctrl_reg,
415 +                               &regval) < 0) {
416 +                               dev_err(&pdev->dev,
417 +                                       "Failed to read buck ctrl\n");
418 +                               return -EIO;
419 +                       }
420 +
421 +                       if (regval & mt6323_regulators[i].vselctrl_mask) {
422 +                               mt6323_regulators[i].desc.vsel_reg =
423 +                               mt6323_regulators[i].vselon_reg;
424 +                       }
425 +               }
426 +       }
427 +
428 +       return 0;
429 +}
430 +
431 +static int mt6323_regulator_probe(struct platform_device *pdev)
432 +{
433 +       struct mt6397_chip *mt6323 = dev_get_drvdata(pdev->dev.parent);
434 +       struct regulator_config config = {};
435 +       struct regulator_dev *rdev;
436 +       int i;
437 +       u32 reg_value;
438 +
439 +       /* Query buck controller to select activated voltage register part */
440 +       if (mt6323_set_buck_vosel_reg(pdev))
441 +               return -EIO;
442 +
443 +       /* Read PMIC chip revision to update constraints and voltage table */
444 +       if (regmap_read(mt6323->regmap, MT6323_CID, &reg_value) < 0) {
445 +               dev_err(&pdev->dev, "Failed to read Chip ID\n");
446 +               return -EIO;
447 +       }
448 +       dev_info(&pdev->dev, "Chip ID = 0x%x\n", reg_value);
449 +
450 +       for (i = 0; i < MT6323_MAX_REGULATOR; i++) {
451 +               config.dev = &pdev->dev;
452 +               config.driver_data = &mt6323_regulators[i];
453 +               config.regmap = mt6323->regmap;
454 +               rdev = devm_regulator_register(&pdev->dev,
455 +                               &mt6323_regulators[i].desc, &config);
456 +               if (IS_ERR(rdev)) {
457 +                       dev_err(&pdev->dev, "failed to register %s\n",
458 +                               mt6323_regulators[i].desc.name);
459 +                       return PTR_ERR(rdev);
460 +               }
461 +       }
462 +       return 0;
463 +}
464 +
465 +static const struct platform_device_id mt6323_platform_ids[] = {
466 +       {"mt6323-regulator", 0},
467 +       { /* sentinel */ },
468 +};
469 +MODULE_DEVICE_TABLE(platform, mt6323_platform_ids);
470 +
471 +static const struct of_device_id mt6323_of_match[] = {
472 +       { .compatible = "mediatek,mt6323-regulator", },
473 +       { /* sentinel */ },
474 +};
475 +MODULE_DEVICE_TABLE(of, mt6323_of_match);
476 +
477 +static struct platform_driver mt6323_regulator_driver = {
478 +       .driver = {
479 +               .name = "mt6323-regulator",
480 +               .of_match_table = of_match_ptr(mt6323_of_match),
481 +       },
482 +       .probe = mt6323_regulator_probe,
483 +       .id_table = mt6323_platform_ids,
484 +};
485 +
486 +module_platform_driver(mt6323_regulator_driver);
487 +
488 +MODULE_AUTHOR("Chen Zhong <chen.zhong@mediatek.com>");
489 +MODULE_DESCRIPTION("Regulator Driver for MediaTek MT6397 PMIC");
490 +MODULE_LICENSE("GPL v2");
491 diff --git a/include/linux/regulator/mt6323-regulator.h b/include/linux/regulator/mt6323-regulator.h
492 new file mode 100644
493 index 0000000..67011cd
494 --- /dev/null
495 +++ b/include/linux/regulator/mt6323-regulator.h
496 @@ -0,0 +1,52 @@
497 +/*
498 + * Copyright (c) 2016 MediaTek Inc.
499 + * Author: Chen Zhong <chen.zhong@mediatek.com>
500 + *
501 + * This program is free software; you can redistribute it and/or modify
502 + * it under the terms of the GNU General Public License version 2 as
503 + * published by the Free Software Foundation.
504 + *
505 + * This program is distributed in the hope that it will be useful,
506 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
507 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
508 + * GNU General Public License for more details.
509 + */
510 +
511 +#ifndef __LINUX_REGULATOR_MT6323_H
512 +#define __LINUX_REGULATOR_MT6323_H
513 +
514 +enum {
515 +       MT6323_ID_VPROC = 0,
516 +       MT6323_ID_VSYS,
517 +       MT6323_ID_VPA,
518 +       MT6323_ID_VTCXO,
519 +       MT6323_ID_VCN28,
520 +       MT6323_ID_VCN33_BT,
521 +       MT6323_ID_VCN33_WIFI,
522 +       MT6323_ID_VA,
523 +       MT6323_ID_VCAMA,
524 +       MT6323_ID_VIO28 = 9,
525 +       MT6323_ID_VUSB,
526 +       MT6323_ID_VMC,
527 +       MT6323_ID_VMCH,
528 +       MT6323_ID_VEMC3V3,
529 +       MT6323_ID_VGP1,
530 +       MT6323_ID_VGP2,
531 +       MT6323_ID_VGP3,
532 +       MT6323_ID_VCN18,
533 +       MT6323_ID_VSIM1,
534 +       MT6323_ID_VSIM2,
535 +       MT6323_ID_VRTC,
536 +       MT6323_ID_VCAMAF,
537 +       MT6323_ID_VIBR,
538 +       MT6323_ID_VRF18,
539 +       MT6323_ID_VM,
540 +       MT6323_ID_VIO18,
541 +       MT6323_ID_VCAMD,
542 +       MT6323_ID_VCAMIO,
543 +       MT6323_ID_RG_MAX,
544 +};
545 +
546 +#define MT6323_MAX_REGULATOR   MT6323_ID_RG_MAX
547 +
548 +#endif /* __LINUX_REGULATOR_MT6323_H */
549 -- 
550 1.7.10.4
551