diff options
author | Henry Chen <henryc.chen@mediatek.com> | 2015-07-24 01:24:41 -0400 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2015-07-24 07:30:49 -0400 |
commit | 8766018b6ef73ca124d13b0d0a06dec906726cc8 (patch) | |
tree | 38d7d5d50a60c868fd6e8ba9577b812599b84edc | |
parent | 678cdb2fbd7e44b8905a8f4e770c694eb77f0395 (diff) |
regulator: mt6311: Add support for mt6311 regulator
Add regulator support for mt6311.
It has 2 regulaotrs - Buck and LDO, provide the related buck/ldo voltage
data to the driver, and creates the regulator_desc table. Supported
operations for Buck are enabled/disabled and voltage change, only
enabled/disabled for LDO.
Signed-off-by: Henry Chen <henryc.chen@mediatek.com>
Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r-- | drivers/regulator/Kconfig | 9 | ||||
-rw-r--r-- | drivers/regulator/Makefile | 1 | ||||
-rw-r--r-- | drivers/regulator/mt6311-regulator.c | 180 | ||||
-rw-r--r-- | drivers/regulator/mt6311-regulator.h | 65 | ||||
-rw-r--r-- | include/linux/regulator/mt6311.h | 29 |
5 files changed, 284 insertions, 0 deletions
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index bef3bde6971b..aab09ac499a0 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig | |||
@@ -451,6 +451,15 @@ config REGULATOR_MC13892 | |||
451 | Say y here to support the regulators found on the Freescale MC13892 | 451 | Say y here to support the regulators found on the Freescale MC13892 |
452 | PMIC. | 452 | PMIC. |
453 | 453 | ||
454 | config REGULATOR_MT6311 | ||
455 | tristate "MediaTek MT6311 PMIC" | ||
456 | depends on I2C | ||
457 | help | ||
458 | Say y here to select this option to enable the power regulator of | ||
459 | MediaTek MT6311 PMIC. | ||
460 | This driver supports the control of different power rails of device | ||
461 | through regulator interface. | ||
462 | |||
454 | config REGULATOR_MT6397 | 463 | config REGULATOR_MT6397 |
455 | tristate "MediaTek MT6397 PMIC" | 464 | tristate "MediaTek MT6397 PMIC" |
456 | depends on MFD_MT6397 | 465 | depends on MFD_MT6397 |
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index 91bf76267404..45e790f92715 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile | |||
@@ -60,6 +60,7 @@ obj-$(CONFIG_REGULATOR_MAX77843) += max77843.o | |||
60 | obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o | 60 | obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o |
61 | obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o | 61 | obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o |
62 | obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o | 62 | obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o |
63 | obj-$(CONFIG_REGULATOR_MT6311) += mt6311-regulator.o | ||
63 | obj-$(CONFIG_REGULATOR_MT6397) += mt6397-regulator.o | 64 | obj-$(CONFIG_REGULATOR_MT6397) += mt6397-regulator.o |
64 | obj-$(CONFIG_REGULATOR_QCOM_RPM) += qcom_rpm-regulator.o | 65 | obj-$(CONFIG_REGULATOR_QCOM_RPM) += qcom_rpm-regulator.o |
65 | obj-$(CONFIG_REGULATOR_QCOM_SPMI) += qcom_spmi-regulator.o | 66 | obj-$(CONFIG_REGULATOR_QCOM_SPMI) += qcom_spmi-regulator.o |
diff --git a/drivers/regulator/mt6311-regulator.c b/drivers/regulator/mt6311-regulator.c new file mode 100644 index 000000000000..096e6202be1c --- /dev/null +++ b/drivers/regulator/mt6311-regulator.c | |||
@@ -0,0 +1,180 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2015 MediaTek Inc. | ||
3 | * Author: Henry Chen <henryc.chen@mediatek.com> | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License version 2 as | ||
7 | * published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | */ | ||
14 | |||
15 | #include <linux/err.h> | ||
16 | #include <linux/gpio.h> | ||
17 | #include <linux/i2c.h> | ||
18 | #include <linux/init.h> | ||
19 | #include <linux/interrupt.h> | ||
20 | #include <linux/module.h> | ||
21 | #include <linux/regmap.h> | ||
22 | #include <linux/regulator/driver.h> | ||
23 | #include <linux/regulator/machine.h> | ||
24 | #include <linux/regulator/of_regulator.h> | ||
25 | #include <linux/regulator/mt6311.h> | ||
26 | #include <linux/slab.h> | ||
27 | #include "mt6311-regulator.h" | ||
28 | |||
29 | static const struct regmap_config mt6311_regmap_config = { | ||
30 | .reg_bits = 8, | ||
31 | .val_bits = 8, | ||
32 | .max_register = MT6311_FQMTR_CON4, | ||
33 | }; | ||
34 | |||
35 | /* Default limits measured in millivolts and milliamps */ | ||
36 | #define MT6311_MIN_UV 600000 | ||
37 | #define MT6311_MAX_UV 1400000 | ||
38 | #define MT6311_STEP_UV 6250 | ||
39 | |||
40 | static const struct regulator_linear_range buck_volt_range[] = { | ||
41 | REGULATOR_LINEAR_RANGE(MT6311_MIN_UV, 0, 0x7f, MT6311_STEP_UV), | ||
42 | }; | ||
43 | |||
44 | static struct regulator_ops mt6311_buck_ops = { | ||
45 | .list_voltage = regulator_list_voltage_linear_range, | ||
46 | .map_voltage = regulator_map_voltage_linear_range, | ||
47 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | ||
48 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | ||
49 | .set_voltage_time_sel = regulator_set_voltage_time_sel, | ||
50 | .enable = regulator_enable_regmap, | ||
51 | .disable = regulator_disable_regmap, | ||
52 | .is_enabled = regulator_is_enabled_regmap, | ||
53 | }; | ||
54 | |||
55 | static struct regulator_ops mt6311_ldo_ops = { | ||
56 | .enable = regulator_enable_regmap, | ||
57 | .disable = regulator_disable_regmap, | ||
58 | .is_enabled = regulator_is_enabled_regmap, | ||
59 | }; | ||
60 | |||
61 | #define MT6311_BUCK(_id) \ | ||
62 | {\ | ||
63 | .name = #_id,\ | ||
64 | .ops = &mt6311_buck_ops,\ | ||
65 | .of_match = of_match_ptr(#_id),\ | ||
66 | .regulators_node = of_match_ptr("regulators"),\ | ||
67 | .type = REGULATOR_VOLTAGE,\ | ||
68 | .id = MT6311_ID_##_id,\ | ||
69 | .n_voltages = (MT6311_MAX_UV - MT6311_MIN_UV) / MT6311_STEP_UV + 1,\ | ||
70 | .min_uV = MT6311_MIN_UV,\ | ||
71 | .uV_step = MT6311_STEP_UV,\ | ||
72 | .owner = THIS_MODULE,\ | ||
73 | .linear_ranges = buck_volt_range, \ | ||
74 | .n_linear_ranges = ARRAY_SIZE(buck_volt_range), \ | ||
75 | .enable_reg = MT6311_VDVFS11_CON9,\ | ||
76 | .enable_mask = MT6311_PMIC_VDVFS11_EN_MASK,\ | ||
77 | .vsel_reg = MT6311_VDVFS11_CON12,\ | ||
78 | .vsel_mask = MT6311_PMIC_VDVFS11_VOSEL_MASK,\ | ||
79 | } | ||
80 | |||
81 | #define MT6311_LDO(_id) \ | ||
82 | {\ | ||
83 | .name = #_id,\ | ||
84 | .ops = &mt6311_ldo_ops,\ | ||
85 | .of_match = of_match_ptr(#_id),\ | ||
86 | .regulators_node = of_match_ptr("regulators"),\ | ||
87 | .type = REGULATOR_VOLTAGE,\ | ||
88 | .id = MT6311_ID_##_id,\ | ||
89 | .owner = THIS_MODULE,\ | ||
90 | .enable_reg = MT6311_LDO_CON3,\ | ||
91 | .enable_mask = MT6311_PMIC_RG_VBIASN_EN_MASK,\ | ||
92 | } | ||
93 | |||
94 | static struct regulator_desc mt6311_regulators[] = { | ||
95 | MT6311_BUCK(VDVFS), | ||
96 | MT6311_LDO(VBIASN), | ||
97 | }; | ||
98 | |||
99 | /* | ||
100 | * I2C driver interface functions | ||
101 | */ | ||
102 | static int mt6311_i2c_probe(struct i2c_client *i2c, | ||
103 | const struct i2c_device_id *id) | ||
104 | { | ||
105 | struct regulator_config config = { }; | ||
106 | struct regulator_dev *rdev; | ||
107 | struct regmap *regmap; | ||
108 | int error, i, ret; | ||
109 | unsigned int data; | ||
110 | |||
111 | regmap = devm_regmap_init_i2c(i2c, &mt6311_regmap_config); | ||
112 | if (IS_ERR(regmap)) { | ||
113 | error = PTR_ERR(regmap); | ||
114 | dev_err(&i2c->dev, "Failed to allocate register map: %d\n", | ||
115 | error); | ||
116 | return error; | ||
117 | } | ||
118 | |||
119 | ret = regmap_read(regmap, MT6311_SWCID, &data); | ||
120 | if (ret < 0) { | ||
121 | dev_err(&i2c->dev, "Failed to read DEVICE_ID reg: %d\n", ret); | ||
122 | return ret; | ||
123 | } | ||
124 | |||
125 | switch (data) { | ||
126 | case MT6311_E1_CID_CODE: | ||
127 | case MT6311_E2_CID_CODE: | ||
128 | case MT6311_E3_CID_CODE: | ||
129 | break; | ||
130 | default: | ||
131 | dev_err(&i2c->dev, "Unsupported device id = 0x%x.\n", data); | ||
132 | return -ENODEV; | ||
133 | } | ||
134 | |||
135 | for (i = 0; i < MT6311_MAX_REGULATORS; i++) { | ||
136 | config.dev = &i2c->dev; | ||
137 | config.regmap = regmap; | ||
138 | |||
139 | rdev = devm_regulator_register(&i2c->dev, | ||
140 | &mt6311_regulators[i], &config); | ||
141 | if (IS_ERR(rdev)) { | ||
142 | dev_err(&i2c->dev, | ||
143 | "Failed to register MT6311 regulator\n"); | ||
144 | return PTR_ERR(rdev); | ||
145 | } | ||
146 | } | ||
147 | |||
148 | return 0; | ||
149 | } | ||
150 | |||
151 | static const struct i2c_device_id mt6311_i2c_id[] = { | ||
152 | {"mt6311", 0}, | ||
153 | {}, | ||
154 | }; | ||
155 | MODULE_DEVICE_TABLE(i2c, mt6311_i2c_id); | ||
156 | |||
157 | #ifdef CONFIG_OF | ||
158 | static const struct of_device_id mt6311_dt_ids[] = { | ||
159 | { .compatible = "mediatek,mt6311-regulator", | ||
160 | .data = &mt6311_i2c_id[0] }, | ||
161 | {}, | ||
162 | }; | ||
163 | MODULE_DEVICE_TABLE(of, mt6311_dt_ids); | ||
164 | #endif | ||
165 | |||
166 | static struct i2c_driver mt6311_regulator_driver = { | ||
167 | .driver = { | ||
168 | .name = "mt6311", | ||
169 | .owner = THIS_MODULE, | ||
170 | .of_match_table = of_match_ptr(mt6311_dt_ids), | ||
171 | }, | ||
172 | .probe = mt6311_i2c_probe, | ||
173 | .id_table = mt6311_i2c_id, | ||
174 | }; | ||
175 | |||
176 | module_i2c_driver(mt6311_regulator_driver); | ||
177 | |||
178 | MODULE_AUTHOR("Henry Chen <henryc.chen@mediatek.com>"); | ||
179 | MODULE_DESCRIPTION("Regulator device driver for Mediatek MT6311"); | ||
180 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/regulator/mt6311-regulator.h b/drivers/regulator/mt6311-regulator.h new file mode 100644 index 000000000000..5218db46a798 --- /dev/null +++ b/drivers/regulator/mt6311-regulator.h | |||
@@ -0,0 +1,65 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2015 MediaTek Inc. | ||
3 | * Author: Henry Chen <henryc.chen@mediatek.com> | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License version 2 as | ||
7 | * published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | */ | ||
14 | |||
15 | #ifndef __MT6311_REGULATOR_H__ | ||
16 | #define __MT6311_REGULATOR_H__ | ||
17 | |||
18 | #define MT6311_SWCID 0x01 | ||
19 | |||
20 | #define MT6311_TOP_INT_CON 0x18 | ||
21 | #define MT6311_TOP_INT_MON 0x19 | ||
22 | |||
23 | #define MT6311_VDVFS11_CON0 0x87 | ||
24 | #define MT6311_VDVFS11_CON7 0x88 | ||
25 | #define MT6311_VDVFS11_CON8 0x89 | ||
26 | #define MT6311_VDVFS11_CON9 0x8A | ||
27 | #define MT6311_VDVFS11_CON10 0x8B | ||
28 | #define MT6311_VDVFS11_CON11 0x8C | ||
29 | #define MT6311_VDVFS11_CON12 0x8D | ||
30 | #define MT6311_VDVFS11_CON13 0x8E | ||
31 | #define MT6311_VDVFS11_CON14 0x8F | ||
32 | #define MT6311_VDVFS11_CON15 0x90 | ||
33 | #define MT6311_VDVFS11_CON16 0x91 | ||
34 | #define MT6311_VDVFS11_CON17 0x92 | ||
35 | #define MT6311_VDVFS11_CON18 0x93 | ||
36 | #define MT6311_VDVFS11_CON19 0x94 | ||
37 | |||
38 | #define MT6311_LDO_CON0 0xCC | ||
39 | #define MT6311_LDO_OCFB0 0xCD | ||
40 | #define MT6311_LDO_CON2 0xCE | ||
41 | #define MT6311_LDO_CON3 0xCF | ||
42 | #define MT6311_LDO_CON4 0xD0 | ||
43 | #define MT6311_FQMTR_CON0 0xD1 | ||
44 | #define MT6311_FQMTR_CON1 0xD2 | ||
45 | #define MT6311_FQMTR_CON2 0xD3 | ||
46 | #define MT6311_FQMTR_CON3 0xD4 | ||
47 | #define MT6311_FQMTR_CON4 0xD5 | ||
48 | |||
49 | #define MT6311_PMIC_RG_INT_POL_MASK 0x1 | ||
50 | #define MT6311_PMIC_RG_INT_EN_MASK 0x2 | ||
51 | #define MT6311_PMIC_RG_BUCK_OC_INT_STATUS_MASK 0x10 | ||
52 | |||
53 | #define MT6311_PMIC_VDVFS11_EN_CTRL_MASK 0x1 | ||
54 | #define MT6311_PMIC_VDVFS11_VOSEL_CTRL_MASK 0x2 | ||
55 | #define MT6311_PMIC_VDVFS11_EN_SEL_MASK 0x3 | ||
56 | #define MT6311_PMIC_VDVFS11_VOSEL_SEL_MASK 0xc | ||
57 | #define MT6311_PMIC_VDVFS11_EN_MASK 0x1 | ||
58 | #define MT6311_PMIC_VDVFS11_VOSEL_MASK 0x7F | ||
59 | #define MT6311_PMIC_VDVFS11_VOSEL_ON_MASK 0x7F | ||
60 | #define MT6311_PMIC_VDVFS11_VOSEL_SLEEP_MASK 0x7F | ||
61 | #define MT6311_PMIC_NI_VDVFS11_VOSEL_MASK 0x7F | ||
62 | |||
63 | #define MT6311_PMIC_RG_VBIASN_EN_MASK 0x1 | ||
64 | |||
65 | #endif | ||
diff --git a/include/linux/regulator/mt6311.h b/include/linux/regulator/mt6311.h new file mode 100644 index 000000000000..8473259395b6 --- /dev/null +++ b/include/linux/regulator/mt6311.h | |||
@@ -0,0 +1,29 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2015 MediaTek Inc. | ||
3 | * Author: Henry Chen <henryc.chen@mediatek.com> | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License version 2 as | ||
7 | * published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | */ | ||
14 | |||
15 | #ifndef __LINUX_REGULATOR_MT6311_H | ||
16 | #define __LINUX_REGULATOR_MT6311_H | ||
17 | |||
18 | #define MT6311_MAX_REGULATORS 2 | ||
19 | |||
20 | enum { | ||
21 | MT6311_ID_VDVFS = 0, | ||
22 | MT6311_ID_VBIASN, | ||
23 | }; | ||
24 | |||
25 | #define MT6311_E1_CID_CODE 0x10 | ||
26 | #define MT6311_E2_CID_CODE 0x20 | ||
27 | #define MT6311_E3_CID_CODE 0x30 | ||
28 | |||
29 | #endif /* __LINUX_REGULATOR_MT6311_H */ | ||