aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonghwa Lee <jonghwa3.lee@samsung.com>2013-06-24 21:08:38 -0400
committerMark Brown <broonie@linaro.org>2013-06-25 06:31:29 -0400
commit80b022e29bfdffb6c9ac0a283bcad3e1030c4c7e (patch)
treeda245ac34d194fc608aad26c5f162860a8754397
parent9e895ace5d82df8929b16f58e9f515f6d54ab82d (diff)
regulator: max77693: Add max77693 regualtor driver.
This patch adds new regulator driver to support max77693 chip's regulators. max77693 has two linear voltage regulators and one current regulator which can be controlled through I2C bus. This driver also supports device tree. Signed-off-by: Jonghwa Lee <jonghwa3.lee@samsung.com> Signed-off-by: Myungjoo Ham <myungjoo.ham@samsung.com> Signed-off-by: Mark Brown <broonie@linaro.org>
-rw-r--r--Documentation/devicetree/bindings/mfd/max77693.txt55
-rw-r--r--drivers/regulator/Kconfig9
-rw-r--r--drivers/regulator/Makefile1
-rw-r--r--drivers/regulator/max77693.c324
-rw-r--r--include/linux/mfd/max77693-private.h13
-rw-r--r--include/linux/mfd/max77693.h18
6 files changed, 420 insertions, 0 deletions
diff --git a/Documentation/devicetree/bindings/mfd/max77693.txt b/Documentation/devicetree/bindings/mfd/max77693.txt
new file mode 100644
index 000000000000..11921cc417bf
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/max77693.txt
@@ -0,0 +1,55 @@
1Maxim MAX77693 multi-function device
2
3MAX77693 is a Multifunction device with the following submodules:
4- PMIC,
5- CHARGER,
6- LED,
7- MUIC,
8- HAPTIC
9
10It is interfaced to host controller using i2c.
11This document describes the bindings for the mfd device.
12
13Required properties:
14- compatible : Must be "maxim,max77693".
15- reg : Specifies the i2c slave address of PMIC block.
16- interrupts : This i2c device has an IRQ line connected to the main SoC.
17- interrupt-parent : The parent interrupt controller.
18
19Optional properties:
20- regulators : The regulators of max77693 have to be instantiated under subnod
21 named "regulators" using the following format.
22
23 regulators {
24 regualtor-compatible = ESAFEOUT1/ESAFEOUT2/CHARGER
25 standard regulator constratints[*].
26 };
27
28 [*] refer Documentation/devicetree/bindings/regulator/regulator.txt
29
30Example:
31 max77693@66 {
32 compatible = "maxim,max77693";
33 reg = <0x66>;
34 interrupt-parent = <&gpx1>;
35 interrupts = <5 2>;
36
37 regulators {
38 esafeout@1 {
39 regulator-compatible = "ESAFEOUT1";
40 regulator-name = "ESAFEOUT1";
41 regulator-boot-on;
42 };
43 esafeout@2 {
44 regulator-compatible = "ESAFEOUT2";
45 regulator-name = "ESAFEOUT2";
46 };
47 charger@0 {
48 regulator-compatible = "CHARGER";
49 regulator-name = "CHARGER";
50 regulator-min-microamp = <60000>;
51 regulator-max-microamp = <2580000>;
52 regulator-boot-on;
53 };
54 };
55 };
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 8bb26446037e..9744437afe32 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -250,6 +250,15 @@ config REGULATOR_MAX77686
250 via I2C bus. The provided regulator is suitable for 250 via I2C bus. The provided regulator is suitable for
251 Exynos-4 chips to control VARM and VINT voltages. 251 Exynos-4 chips to control VARM and VINT voltages.
252 252
253config REGULATOR_MAX77693
254 tristate "Maxim MAX77693 regulator"
255 depends on MFD_MAX77693
256 help
257 This driver controls a Maxim 77693 regulator via I2C bus.
258 The regulators include two LDOs, 'SAFEOUT1', 'SAFEOUT2'
259 and one current regulator 'CHARGER'. This is suitable for
260 Exynos-4x12 chips.
261
253config REGULATOR_PCAP 262config REGULATOR_PCAP
254 tristate "Motorola PCAP2 regulator driver" 263 tristate "Motorola PCAP2 regulator driver"
255 depends on EZX_PCAP 264 depends on EZX_PCAP
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 47a34ff88f98..a4094cd274be 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -41,6 +41,7 @@ obj-$(CONFIG_REGULATOR_MAX8973) += max8973-regulator.o
41obj-$(CONFIG_REGULATOR_MAX8997) += max8997.o 41obj-$(CONFIG_REGULATOR_MAX8997) += max8997.o
42obj-$(CONFIG_REGULATOR_MAX8998) += max8998.o 42obj-$(CONFIG_REGULATOR_MAX8998) += max8998.o
43obj-$(CONFIG_REGULATOR_MAX77686) += max77686.o 43obj-$(CONFIG_REGULATOR_MAX77686) += max77686.o
44obj-$(CONFIG_REGULATOR_MAX77693) += max77693.o
44obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o 45obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o
45obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o 46obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o
46obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o 47obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o
diff --git a/drivers/regulator/max77693.c b/drivers/regulator/max77693.c
new file mode 100644
index 000000000000..674ece7c832b
--- /dev/null
+++ b/drivers/regulator/max77693.c
@@ -0,0 +1,324 @@
1/*
2 * max77693.c - Regulator driver for the Maxim 77693
3 *
4 * Copyright (C) 2013 Samsung Electronics
5 * Jonghwa Lee <jonghwa3.lee@samsung.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 * This driver is based on max77686.c
22 */
23
24#include <linux/err.h>
25#include <linux/slab.h>
26#include <linux/platform_device.h>
27#include <linux/module.h>
28#include <linux/export.h>
29#include <linux/regulator/driver.h>
30#include <linux/regulator/machine.h>
31#include <linux/mfd/max77693.h>
32#include <linux/mfd/max77693-private.h>
33#include <linux/regulator/of_regulator.h>
34
35#define CHGIN_ILIM_STEP_20mA 20000
36
37struct max77693_pmic_dev {
38 struct device *dev;
39 struct max77693_dev *iodev;
40 int num_regulators;
41 struct regulator_dev **rdev;
42};
43
44/* CHARGER regulator ops */
45/* CHARGER regulator uses two bits for enabling */
46static int max77693_chg_is_enabled(struct regulator_dev *rdev)
47{
48 int ret;
49 u8 val;
50
51 ret = max77693_read_reg(rdev->regmap, rdev->desc->enable_reg, &val);
52 if (ret)
53 return ret;
54
55 return (val & rdev->desc->enable_mask) == rdev->desc->enable_mask;
56}
57
58/*
59 * CHARGER regulator - Min : 20mA, Max : 2580mA, step : 20mA
60 * 0x00, 0x01, 0x2, 0x03 = 60 mA
61 * 0x04 ~ 0x7E = (60 + (X - 3) * 20) mA
62 */
63static int max77693_chg_get_current_limit(struct regulator_dev *rdev)
64{
65 unsigned int chg_min_uA = rdev->constraints->min_uA;
66 unsigned int chg_max_uA = rdev->constraints->max_uA;
67 u8 reg, sel;
68 unsigned int val;
69 int ret;
70
71 ret = max77693_read_reg(rdev->regmap,
72 MAX77693_CHG_REG_CHG_CNFG_09, &reg);
73 if (ret < 0)
74 return ret;
75
76 sel = reg & CHG_CNFG_09_CHGIN_ILIM_MASK;
77
78 /* the first four codes for charger current are all 60mA */
79 if (sel <= 3)
80 sel = 0;
81 else
82 sel -= 3;
83
84 val = chg_min_uA + CHGIN_ILIM_STEP_20mA * sel;
85 if (val > chg_max_uA)
86 return -EINVAL;
87
88 return val;
89}
90
91static int max77693_chg_set_current_limit(struct regulator_dev *rdev,
92 int min_uA, int max_uA)
93{
94 unsigned int chg_min_uA = rdev->constraints->min_uA;
95 int sel = 0;
96
97 while (chg_min_uA + CHGIN_ILIM_STEP_20mA * sel < min_uA)
98 sel++;
99
100 if (chg_min_uA * CHGIN_ILIM_STEP_20mA * sel > max_uA)
101 return -EINVAL;
102
103 /* the first four codes for charger current are all 60mA */
104 sel += 3;
105
106 return max77693_write_reg(rdev->regmap,
107 MAX77693_CHG_REG_CHG_CNFG_09, sel);
108}
109/* end of CHARGER regulator ops */
110
111static const unsigned int max77693_safeout_table[] = {
112 4850000,
113 4900000,
114 4950000,
115 3300000,
116};
117
118static struct regulator_ops max77693_safeout_ops = {
119 .list_voltage = regulator_list_voltage_table,
120 .is_enabled = regulator_is_enabled_regmap,
121 .enable = regulator_enable_regmap,
122 .disable = regulator_disable_regmap,
123 .get_voltage_sel = regulator_get_voltage_sel_regmap,
124 .set_voltage_sel = regulator_set_voltage_sel_regmap,
125};
126
127static struct regulator_ops max77693_charger_ops = {
128 .is_enabled = max77693_chg_is_enabled,
129 .enable = regulator_enable_regmap,
130 .disable = regulator_disable_regmap,
131 .get_current_limit = max77693_chg_get_current_limit,
132 .set_current_limit = max77693_chg_set_current_limit,
133};
134
135#define regulator_desc_esafeout(_num) { \
136 .name = "ESAFEOUT"#_num, \
137 .id = MAX77693_ESAFEOUT##_num, \
138 .n_voltages = 4, \
139 .ops = &max77693_safeout_ops, \
140 .type = REGULATOR_VOLTAGE, \
141 .volt_table = max77693_safeout_table, \
142 .vsel_reg = MAX77693_CHG_REG_SAFEOUT_CTRL, \
143 .vsel_mask = SAFEOUT_CTRL_SAFEOUT##_num##_MASK, \
144 .enable_reg = MAX77693_CHG_REG_SAFEOUT_CTRL, \
145 .enable_mask = SAFEOUT_CTRL_ENSAFEOUT##_num##_MASK , \
146}
147
148static struct regulator_desc regulators[] = {
149 regulator_desc_esafeout(1),
150 regulator_desc_esafeout(2),
151 {
152 .name = "CHARGER",
153 .id = MAX77693_CHARGER,
154 .ops = &max77693_charger_ops,
155 .type = REGULATOR_CURRENT,
156 .owner = THIS_MODULE,
157 .enable_reg = MAX77693_CHG_REG_CHG_CNFG_00,
158 .enable_mask = CHG_CNFG_00_CHG_MASK |
159 CHG_CNFG_00_BUCK_MASK,
160 },
161};
162
163#ifdef CONFIG_OF
164static int max77693_pmic_dt_parse_rdata(struct device *dev,
165 struct max77693_regulator_data **rdata)
166{
167 struct device_node *np;
168 struct of_regulator_match *rmatch;
169 struct max77693_regulator_data *tmp;
170 int i, matched = 0;
171
172 np = of_find_node_by_name(dev->parent->of_node, "regulators");
173 if (!np)
174 return -EINVAL;
175
176 rmatch = devm_kzalloc(dev,
177 sizeof(*rmatch) * ARRAY_SIZE(regulators), GFP_KERNEL);
178 if (!rmatch)
179 return -ENOMEM;
180
181 for (i = 0; i < ARRAY_SIZE(regulators); i++)
182 rmatch[i].name = regulators[i].name;
183
184 matched = of_regulator_match(dev, np, rmatch, ARRAY_SIZE(regulators));
185 if (matched <= 0)
186 return matched;
187 *rdata = devm_kzalloc(dev, sizeof(**rdata) * matched, GFP_KERNEL);
188 if (!(*rdata))
189 return -ENOMEM;
190
191 tmp = *rdata;
192
193 for (i = 0; i < ARRAY_SIZE(regulators); i++) {
194 if (!rmatch[i].init_data)
195 continue;
196 tmp->initdata = rmatch[i].init_data;
197 tmp->of_node = rmatch[i].of_node;
198 tmp->id = regulators[i].id;
199 tmp++;
200 }
201
202 return matched;
203}
204#else
205static int max77693_pmic_dt_parse_rdata(struct device *dev,
206 struct max77693_regulator_data **rdata)
207{
208 return 0;
209}
210#endif /* CONFIG_OF */
211
212static int max77693_pmic_init_rdata(struct device *dev,
213 struct max77693_regulator_data **rdata)
214{
215 struct max77693_platform_data *pdata;
216 int num_regulators = 0;
217
218 pdata = dev_get_platdata(dev->parent);
219 if (pdata) {
220 *rdata = pdata->regulators;
221 num_regulators = pdata->num_regulators;
222 }
223
224 if (!(*rdata) && dev->parent->of_node)
225 num_regulators = max77693_pmic_dt_parse_rdata(dev, rdata);
226
227 return num_regulators;
228}
229
230static int max77693_pmic_probe(struct platform_device *pdev)
231{
232 struct max77693_dev *iodev = dev_get_drvdata(pdev->dev.parent);
233 struct max77693_pmic_dev *max77693_pmic;
234 struct max77693_regulator_data *rdata = NULL;
235 int num_rdata, i, ret;
236 struct regulator_config config;
237
238 num_rdata = max77693_pmic_init_rdata(&pdev->dev, &rdata);
239 if (!rdata || num_rdata <= 0) {
240 dev_err(&pdev->dev, "No init data supplied.\n");
241 return -ENODEV;
242 }
243
244 max77693_pmic = devm_kzalloc(&pdev->dev,
245 sizeof(struct max77693_pmic_dev),
246 GFP_KERNEL);
247 if (!max77693_pmic)
248 return -ENOMEM;
249
250 max77693_pmic->rdev = devm_kzalloc(&pdev->dev,
251 sizeof(struct regulator_dev *) * num_rdata,
252 GFP_KERNEL);
253 if (!max77693_pmic->rdev)
254 return -ENOMEM;
255
256 max77693_pmic->dev = &pdev->dev;
257 max77693_pmic->iodev = iodev;
258 max77693_pmic->num_regulators = num_rdata;
259
260 config.dev = &pdev->dev;
261 config.regmap = iodev->regmap;
262 config.driver_data = max77693_pmic;
263 platform_set_drvdata(pdev, max77693_pmic);
264
265 for (i = 0; i < max77693_pmic->num_regulators; i++) {
266 int id = rdata[i].id;
267
268 config.init_data = rdata[i].initdata;
269 config.of_node = rdata[i].of_node;
270
271 max77693_pmic->rdev[i] = regulator_register(&regulators[id],
272 &config);
273 if (IS_ERR(max77693_pmic->rdev[i])) {
274 ret = PTR_ERR(max77693_pmic->rdev[i]);
275 dev_err(max77693_pmic->dev,
276 "Failed to initialize regulator-%d\n", id);
277 max77693_pmic->rdev[i] = NULL;
278 goto err;
279 }
280 }
281
282 return 0;
283 err:
284 while (--i >= 0)
285 regulator_unregister(max77693_pmic->rdev[i]);
286
287 return ret;
288}
289
290static int max77693_pmic_remove(struct platform_device *pdev)
291{
292 struct max77693_pmic_dev *max77693_pmic = platform_get_drvdata(pdev);
293 struct regulator_dev **rdev = max77693_pmic->rdev;
294 int i;
295
296 for (i = 0; i < max77693_pmic->num_regulators; i++)
297 if (rdev[i])
298 regulator_unregister(rdev[i]);
299
300 return 0;
301}
302
303static const struct platform_device_id max77693_pmic_id[] = {
304 {"max77693-pmic", 0},
305 {},
306};
307
308MODULE_DEVICE_TABLE(platform, max77693_pmic_id);
309
310static struct platform_driver max77693_pmic_driver = {
311 .driver = {
312 .name = "max77693-pmic",
313 .owner = THIS_MODULE,
314 },
315 .probe = max77693_pmic_probe,
316 .remove = max77693_pmic_remove,
317 .id_table = max77693_pmic_id,
318};
319
320module_platform_driver(max77693_pmic_driver);
321
322MODULE_DESCRIPTION("MAXIM MAX77693 regulator driver");
323MODULE_AUTHOR("Jonghwa Lee <jonghwa3.lee@samsung.com>");
324MODULE_LICENSE("GPL");
diff --git a/include/linux/mfd/max77693-private.h b/include/linux/mfd/max77693-private.h
index 1aa4f13cdfa6..244fb0d51589 100644
--- a/include/linux/mfd/max77693-private.h
+++ b/include/linux/mfd/max77693-private.h
@@ -85,6 +85,19 @@ enum max77693_pmic_reg {
85 MAX77693_PMIC_REG_END, 85 MAX77693_PMIC_REG_END,
86}; 86};
87 87
88/* MAX77693 CHG_CNFG_00 register */
89#define CHG_CNFG_00_CHG_MASK 0x1
90#define CHG_CNFG_00_BUCK_MASK 0x4
91
92/* MAX77693 CHG_CNFG_09 Register */
93#define CHG_CNFG_09_CHGIN_ILIM_MASK 0x7F
94
95/* MAX77693 CHG_CTRL Register */
96#define SAFEOUT_CTRL_SAFEOUT1_MASK 0x3
97#define SAFEOUT_CTRL_SAFEOUT2_MASK 0xC
98#define SAFEOUT_CTRL_ENSAFEOUT1_MASK 0x40
99#define SAFEOUT_CTRL_ENSAFEOUT2_MASK 0x80
100
88/* Slave addr = 0x4A: MUIC */ 101/* Slave addr = 0x4A: MUIC */
89enum max77693_muic_reg { 102enum max77693_muic_reg {
90 MAX77693_MUIC_REG_ID = 0x00, 103 MAX77693_MUIC_REG_ID = 0x00,
diff --git a/include/linux/mfd/max77693.h b/include/linux/mfd/max77693.h
index 3109a6c5c948..676f0f388992 100644
--- a/include/linux/mfd/max77693.h
+++ b/include/linux/mfd/max77693.h
@@ -30,6 +30,20 @@
30#ifndef __LINUX_MFD_MAX77693_H 30#ifndef __LINUX_MFD_MAX77693_H
31#define __LINUX_MFD_MAX77693_H 31#define __LINUX_MFD_MAX77693_H
32 32
33/* MAX77686 regulator IDs */
34enum max77693_regulators {
35 MAX77693_ESAFEOUT1 = 0,
36 MAX77693_ESAFEOUT2,
37 MAX77693_CHARGER,
38 MAX77693_REG_MAX,
39};
40
41struct max77693_regulator_data {
42 int id;
43 struct regulator_init_data *initdata;
44 struct device_node *of_node;
45};
46
33struct max77693_reg_data { 47struct max77693_reg_data {
34 u8 addr; 48 u8 addr;
35 u8 data; 49 u8 data;
@@ -52,6 +66,10 @@ struct max77693_muic_platform_data {
52struct max77693_platform_data { 66struct max77693_platform_data {
53 int wakeup; 67 int wakeup;
54 68
69 /* regulator data */
70 struct max77693_regulator_data *regulators;
71 int num_regulators;
72
55 /* muic data */ 73 /* muic data */
56 struct max77693_muic_platform_data *muic_data; 74 struct max77693_muic_platform_data *muic_data;
57}; 75};