diff options
Diffstat (limited to 'drivers/regulator')
-rw-r--r-- | drivers/regulator/Kconfig | 11 | ||||
-rw-r--r-- | drivers/regulator/Makefile | 1 | ||||
-rw-r--r-- | drivers/regulator/core.c | 39 | ||||
-rw-r--r-- | drivers/regulator/palmas-regulator.c | 37 | ||||
-rw-r--r-- | drivers/regulator/tps51632-regulator.c | 332 |
5 files changed, 375 insertions, 45 deletions
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index a162573d4944..10b1edc89621 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig | |||
@@ -345,6 +345,17 @@ config REGULATOR_PALMAS | |||
345 | on the muxing. This is handled automatically in the driver by | 345 | on the muxing. This is handled automatically in the driver by |
346 | reading the mux info from OTP. | 346 | reading the mux info from OTP. |
347 | 347 | ||
348 | config REGULATOR_TPS51632 | ||
349 | tristate "TI TPS51632 Power Regulator" | ||
350 | depends on I2C | ||
351 | select REGMAP_I2C | ||
352 | help | ||
353 | This driver supports TPS51632 voltage regulator chip. | ||
354 | The TPS51632 is 3-2-1 Phase D-Cap+ Step Down Driverless Controller | ||
355 | with Serial VID control and DVFS. | ||
356 | The voltage output can be configure through I2C interface or PWM | ||
357 | interface. | ||
358 | |||
348 | config REGULATOR_TPS6105X | 359 | config REGULATOR_TPS6105X |
349 | tristate "TI TPS6105X Power regulators" | 360 | tristate "TI TPS6105X Power regulators" |
350 | depends on TPS6105X | 361 | depends on TPS6105X |
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index 4b754e958aed..bdaca617e2f2 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile | |||
@@ -42,6 +42,7 @@ obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o | |||
42 | obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o | 42 | obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o |
43 | obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o | 43 | obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o |
44 | obj-$(CONFIG_REGULATOR_PALMAS) += palmas-regulator.o | 44 | obj-$(CONFIG_REGULATOR_PALMAS) += palmas-regulator.o |
45 | obj-$(CONFIG_REGULATOR_TPS51632) += tps51632-regulator.o | ||
45 | obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o | 46 | obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o |
46 | obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o | 47 | obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o |
47 | obj-$(CONFIG_REGULATOR_RC5T583) += rc5t583-regulator.o | 48 | obj-$(CONFIG_REGULATOR_RC5T583) += rc5t583-regulator.o |
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 5c4829cba6a6..02a249b024b3 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c | |||
@@ -1381,22 +1381,14 @@ struct regulator *regulator_get_exclusive(struct device *dev, const char *id) | |||
1381 | } | 1381 | } |
1382 | EXPORT_SYMBOL_GPL(regulator_get_exclusive); | 1382 | EXPORT_SYMBOL_GPL(regulator_get_exclusive); |
1383 | 1383 | ||
1384 | /** | 1384 | /* Locks held by regulator_put() */ |
1385 | * regulator_put - "free" the regulator source | 1385 | static void _regulator_put(struct regulator *regulator) |
1386 | * @regulator: regulator source | ||
1387 | * | ||
1388 | * Note: drivers must ensure that all regulator_enable calls made on this | ||
1389 | * regulator source are balanced by regulator_disable calls prior to calling | ||
1390 | * this function. | ||
1391 | */ | ||
1392 | void regulator_put(struct regulator *regulator) | ||
1393 | { | 1386 | { |
1394 | struct regulator_dev *rdev; | 1387 | struct regulator_dev *rdev; |
1395 | 1388 | ||
1396 | if (regulator == NULL || IS_ERR(regulator)) | 1389 | if (regulator == NULL || IS_ERR(regulator)) |
1397 | return; | 1390 | return; |
1398 | 1391 | ||
1399 | mutex_lock(®ulator_list_mutex); | ||
1400 | rdev = regulator->rdev; | 1392 | rdev = regulator->rdev; |
1401 | 1393 | ||
1402 | debugfs_remove_recursive(regulator->debugfs); | 1394 | debugfs_remove_recursive(regulator->debugfs); |
@@ -1412,6 +1404,20 @@ void regulator_put(struct regulator *regulator) | |||
1412 | rdev->exclusive = 0; | 1404 | rdev->exclusive = 0; |
1413 | 1405 | ||
1414 | module_put(rdev->owner); | 1406 | module_put(rdev->owner); |
1407 | } | ||
1408 | |||
1409 | /** | ||
1410 | * regulator_put - "free" the regulator source | ||
1411 | * @regulator: regulator source | ||
1412 | * | ||
1413 | * Note: drivers must ensure that all regulator_enable calls made on this | ||
1414 | * regulator source are balanced by regulator_disable calls prior to calling | ||
1415 | * this function. | ||
1416 | */ | ||
1417 | void regulator_put(struct regulator *regulator) | ||
1418 | { | ||
1419 | mutex_lock(®ulator_list_mutex); | ||
1420 | _regulator_put(regulator); | ||
1415 | mutex_unlock(®ulator_list_mutex); | 1421 | mutex_unlock(®ulator_list_mutex); |
1416 | } | 1422 | } |
1417 | EXPORT_SYMBOL_GPL(regulator_put); | 1423 | EXPORT_SYMBOL_GPL(regulator_put); |
@@ -1891,6 +1897,10 @@ int regulator_list_voltage_linear(struct regulator_dev *rdev, | |||
1891 | { | 1897 | { |
1892 | if (selector >= rdev->desc->n_voltages) | 1898 | if (selector >= rdev->desc->n_voltages) |
1893 | return -EINVAL; | 1899 | return -EINVAL; |
1900 | if (selector < rdev->desc->linear_min_sel) | ||
1901 | return 0; | ||
1902 | |||
1903 | selector -= rdev->desc->linear_min_sel; | ||
1894 | 1904 | ||
1895 | return rdev->desc->min_uV + (rdev->desc->uV_step * selector); | 1905 | return rdev->desc->min_uV + (rdev->desc->uV_step * selector); |
1896 | } | 1906 | } |
@@ -1974,7 +1984,7 @@ int regulator_is_supported_voltage(struct regulator *regulator, | |||
1974 | if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) { | 1984 | if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) { |
1975 | ret = regulator_get_voltage(regulator); | 1985 | ret = regulator_get_voltage(regulator); |
1976 | if (ret >= 0) | 1986 | if (ret >= 0) |
1977 | return (min_uV >= ret && ret <= max_uV); | 1987 | return (min_uV <= ret && ret <= max_uV); |
1978 | else | 1988 | else |
1979 | return ret; | 1989 | return ret; |
1980 | } | 1990 | } |
@@ -2114,6 +2124,8 @@ int regulator_map_voltage_linear(struct regulator_dev *rdev, | |||
2114 | if (ret < 0) | 2124 | if (ret < 0) |
2115 | return ret; | 2125 | return ret; |
2116 | 2126 | ||
2127 | ret += rdev->desc->linear_min_sel; | ||
2128 | |||
2117 | /* Map back into a voltage to verify we're still in bounds */ | 2129 | /* Map back into a voltage to verify we're still in bounds */ |
2118 | voltage = rdev->desc->ops->list_voltage(rdev, ret); | 2130 | voltage = rdev->desc->ops->list_voltage(rdev, ret); |
2119 | if (voltage < min_uV || voltage > max_uV) | 2131 | if (voltage < min_uV || voltage > max_uV) |
@@ -3365,7 +3377,7 @@ regulator_register(const struct regulator_desc *regulator_desc, | |||
3365 | if (ret != 0) { | 3377 | if (ret != 0) { |
3366 | rdev_err(rdev, "Failed to request enable GPIO%d: %d\n", | 3378 | rdev_err(rdev, "Failed to request enable GPIO%d: %d\n", |
3367 | config->ena_gpio, ret); | 3379 | config->ena_gpio, ret); |
3368 | goto clean; | 3380 | goto wash; |
3369 | } | 3381 | } |
3370 | 3382 | ||
3371 | rdev->ena_gpio = config->ena_gpio; | 3383 | rdev->ena_gpio = config->ena_gpio; |
@@ -3445,10 +3457,11 @@ unset_supplies: | |||
3445 | 3457 | ||
3446 | scrub: | 3458 | scrub: |
3447 | if (rdev->supply) | 3459 | if (rdev->supply) |
3448 | regulator_put(rdev->supply); | 3460 | _regulator_put(rdev->supply); |
3449 | if (rdev->ena_gpio) | 3461 | if (rdev->ena_gpio) |
3450 | gpio_free(rdev->ena_gpio); | 3462 | gpio_free(rdev->ena_gpio); |
3451 | kfree(rdev->constraints); | 3463 | kfree(rdev->constraints); |
3464 | wash: | ||
3452 | device_unregister(&rdev->dev); | 3465 | device_unregister(&rdev->dev); |
3453 | /* device core frees rdev */ | 3466 | /* device core frees rdev */ |
3454 | rdev = ERR_PTR(ret); | 3467 | rdev = ERR_PTR(ret); |
diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c index 07aee694ba92..111d76b04bb5 100644 --- a/drivers/regulator/palmas-regulator.c +++ b/drivers/regulator/palmas-regulator.c | |||
@@ -436,44 +436,14 @@ static int palmas_is_enabled_ldo(struct regulator_dev *dev) | |||
436 | return !!(reg); | 436 | return !!(reg); |
437 | } | 437 | } |
438 | 438 | ||
439 | static int palmas_list_voltage_ldo(struct regulator_dev *dev, | ||
440 | unsigned selector) | ||
441 | { | ||
442 | if (!selector) | ||
443 | return 0; | ||
444 | |||
445 | /* voltage is 0.85V + (selector * 0.05v) */ | ||
446 | return 850000 + (selector * 50000); | ||
447 | } | ||
448 | |||
449 | static int palmas_map_voltage_ldo(struct regulator_dev *rdev, | ||
450 | int min_uV, int max_uV) | ||
451 | { | ||
452 | int ret, voltage; | ||
453 | |||
454 | if (min_uV == 0) | ||
455 | return 0; | ||
456 | |||
457 | if (min_uV < 900000) | ||
458 | min_uV = 900000; | ||
459 | ret = DIV_ROUND_UP(min_uV - 900000, 50000) + 1; | ||
460 | |||
461 | /* Map back into a voltage to verify we're still in bounds */ | ||
462 | voltage = palmas_list_voltage_ldo(rdev, ret); | ||
463 | if (voltage < min_uV || voltage > max_uV) | ||
464 | return -EINVAL; | ||
465 | |||
466 | return ret; | ||
467 | } | ||
468 | |||
469 | static struct regulator_ops palmas_ops_ldo = { | 439 | static struct regulator_ops palmas_ops_ldo = { |
470 | .is_enabled = palmas_is_enabled_ldo, | 440 | .is_enabled = palmas_is_enabled_ldo, |
471 | .enable = regulator_enable_regmap, | 441 | .enable = regulator_enable_regmap, |
472 | .disable = regulator_disable_regmap, | 442 | .disable = regulator_disable_regmap, |
473 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | 443 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
474 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | 444 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
475 | .list_voltage = palmas_list_voltage_ldo, | 445 | .list_voltage = regulator_list_voltage_linear, |
476 | .map_voltage = palmas_map_voltage_ldo, | 446 | .map_voltage = regulator_map_voltage_linear, |
477 | }; | 447 | }; |
478 | 448 | ||
479 | /* | 449 | /* |
@@ -821,6 +791,9 @@ static __devinit int palmas_probe(struct platform_device *pdev) | |||
821 | 791 | ||
822 | pmic->desc[id].type = REGULATOR_VOLTAGE; | 792 | pmic->desc[id].type = REGULATOR_VOLTAGE; |
823 | pmic->desc[id].owner = THIS_MODULE; | 793 | pmic->desc[id].owner = THIS_MODULE; |
794 | pmic->desc[id].min_uV = 900000; | ||
795 | pmic->desc[id].uV_step = 50000; | ||
796 | pmic->desc[id].linear_min_sel = 1; | ||
824 | pmic->desc[id].vsel_reg = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, | 797 | pmic->desc[id].vsel_reg = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, |
825 | palmas_regs_info[id].vsel_addr); | 798 | palmas_regs_info[id].vsel_addr); |
826 | pmic->desc[id].vsel_mask = PALMAS_LDO1_VOLTAGE_VSEL_MASK; | 799 | pmic->desc[id].vsel_mask = PALMAS_LDO1_VOLTAGE_VSEL_MASK; |
diff --git a/drivers/regulator/tps51632-regulator.c b/drivers/regulator/tps51632-regulator.c new file mode 100644 index 000000000000..34603640d6d9 --- /dev/null +++ b/drivers/regulator/tps51632-regulator.c | |||
@@ -0,0 +1,332 @@ | |||
1 | /* | ||
2 | * tps51632-regulator.c -- TI TPS51632 | ||
3 | * | ||
4 | * Regulator driver for TPS51632 3-2-1 Phase D-Cap Step Down Driverless | ||
5 | * Controller with serial VID control and DVFS. | ||
6 | * | ||
7 | * Copyright (c) 2012, NVIDIA Corporation. | ||
8 | * | ||
9 | * Author: Laxman Dewangan <ldewangan@nvidia.com> | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or | ||
12 | * modify it under the terms of the GNU General Public License as | ||
13 | * published by the Free Software Foundation version 2. | ||
14 | * | ||
15 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, | ||
16 | * whether express or implied; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
18 | * General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License | ||
21 | * along with this program; if not, write to the Free Software | ||
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | ||
23 | * 02111-1307, USA | ||
24 | */ | ||
25 | |||
26 | #include <linux/err.h> | ||
27 | #include <linux/i2c.h> | ||
28 | #include <linux/init.h> | ||
29 | #include <linux/kernel.h> | ||
30 | #include <linux/module.h> | ||
31 | #include <linux/platform_device.h> | ||
32 | #include <linux/regmap.h> | ||
33 | #include <linux/regulator/driver.h> | ||
34 | #include <linux/regulator/machine.h> | ||
35 | #include <linux/regulator/tps51632-regulator.h> | ||
36 | #include <linux/slab.h> | ||
37 | |||
38 | /* Register definitions */ | ||
39 | #define TPS51632_VOLTAGE_SELECT_REG 0x0 | ||
40 | #define TPS51632_VOLTAGE_BASE_REG 0x1 | ||
41 | #define TPS51632_OFFSET_REG 0x2 | ||
42 | #define TPS51632_IMON_REG 0x3 | ||
43 | #define TPS51632_VMAX_REG 0x4 | ||
44 | #define TPS51632_DVFS_CONTROL_REG 0x5 | ||
45 | #define TPS51632_POWER_STATE_REG 0x6 | ||
46 | #define TPS51632_SLEW_REGS 0x7 | ||
47 | #define TPS51632_FAULT_REG 0x14 | ||
48 | |||
49 | #define TPS51632_MAX_REG 0x15 | ||
50 | |||
51 | #define TPS51632_VOUT_MASK 0x7F | ||
52 | #define TPS51632_VOUT_OFFSET_MASK 0x1F | ||
53 | #define TPS51632_VMAX_MASK 0x7F | ||
54 | #define TPS51632_VMAX_LOCK 0x80 | ||
55 | |||
56 | /* TPS51632_DVFS_CONTROL_REG */ | ||
57 | #define TPS51632_DVFS_PWMEN 0x1 | ||
58 | #define TPS51632_DVFS_STEP_20 0x2 | ||
59 | #define TPS51632_DVFS_VMAX_PG 0x4 | ||
60 | #define TPS51632_DVFS_PWMRST 0x8 | ||
61 | #define TPS51632_DVFS_OCA_EN 0x10 | ||
62 | #define TPS51632_DVFS_FCCM 0x20 | ||
63 | |||
64 | /* TPS51632_POWER_STATE_REG */ | ||
65 | #define TPS51632_POWER_STATE_MASK 0x03 | ||
66 | #define TPS51632_POWER_STATE_MULTI_PHASE_CCM 0x0 | ||
67 | #define TPS51632_POWER_STATE_SINGLE_PHASE_CCM 0x1 | ||
68 | #define TPS51632_POWER_STATE_SINGLE_PHASE_DCM 0x2 | ||
69 | |||
70 | #define TPS51632_MIN_VOLATGE 500000 | ||
71 | #define TPS51632_MAX_VOLATGE 1520000 | ||
72 | #define TPS51632_VOLATGE_STEP_10mV 10000 | ||
73 | #define TPS51632_VOLATGE_STEP_20mV 20000 | ||
74 | #define TPS51632_MAX_VSEL 0x7F | ||
75 | #define TPS51632_MIN_VSEL 0x19 | ||
76 | #define TPS51632_DEFAULT_RAMP_DELAY 6000 | ||
77 | #define TPS51632_VOLT_VSEL(uV) \ | ||
78 | (DIV_ROUND_UP(uV - TPS51632_MIN_VOLATGE, \ | ||
79 | TPS51632_VOLATGE_STEP_10mV) + \ | ||
80 | TPS51632_MIN_VSEL) | ||
81 | |||
82 | /* TPS51632 chip information */ | ||
83 | struct tps51632_chip { | ||
84 | struct device *dev; | ||
85 | struct regulator_desc desc; | ||
86 | struct regulator_dev *rdev; | ||
87 | struct regmap *regmap; | ||
88 | bool enable_pwm_dvfs; | ||
89 | }; | ||
90 | |||
91 | static int tps51632_dcdc_get_voltage_sel(struct regulator_dev *rdev) | ||
92 | { | ||
93 | struct tps51632_chip *tps = rdev_get_drvdata(rdev); | ||
94 | unsigned int data; | ||
95 | int ret; | ||
96 | unsigned int reg = TPS51632_VOLTAGE_SELECT_REG; | ||
97 | int vsel; | ||
98 | |||
99 | if (tps->enable_pwm_dvfs) | ||
100 | reg = TPS51632_VOLTAGE_BASE_REG; | ||
101 | |||
102 | ret = regmap_read(tps->regmap, reg, &data); | ||
103 | if (ret < 0) { | ||
104 | dev_err(tps->dev, "reg read failed, err %d\n", ret); | ||
105 | return ret; | ||
106 | } | ||
107 | |||
108 | vsel = data & TPS51632_VOUT_MASK; | ||
109 | |||
110 | if (vsel < TPS51632_MIN_VSEL) | ||
111 | return 0; | ||
112 | else | ||
113 | return vsel - TPS51632_MIN_VSEL; | ||
114 | } | ||
115 | |||
116 | static int tps51632_dcdc_set_voltage_sel(struct regulator_dev *rdev, | ||
117 | unsigned selector) | ||
118 | { | ||
119 | struct tps51632_chip *tps = rdev_get_drvdata(rdev); | ||
120 | int vsel; | ||
121 | int ret; | ||
122 | unsigned int reg = TPS51632_VOLTAGE_SELECT_REG; | ||
123 | |||
124 | if (tps->enable_pwm_dvfs) | ||
125 | reg = TPS51632_VOLTAGE_BASE_REG; | ||
126 | |||
127 | vsel = selector + TPS51632_MIN_VSEL; | ||
128 | if (vsel > TPS51632_MAX_VSEL) | ||
129 | return -EINVAL; | ||
130 | |||
131 | ret = regmap_write(tps->regmap, TPS51632_VOLTAGE_SELECT_REG, vsel); | ||
132 | if (ret < 0) | ||
133 | dev_err(tps->dev, "reg write failed, err %d\n", ret); | ||
134 | return ret; | ||
135 | } | ||
136 | |||
137 | static int tps51632_dcdc_set_ramp_delay(struct regulator_dev *rdev, | ||
138 | int ramp_delay) | ||
139 | { | ||
140 | struct tps51632_chip *tps = rdev_get_drvdata(rdev); | ||
141 | int bit = ramp_delay/6000; | ||
142 | int ret; | ||
143 | |||
144 | if (bit) | ||
145 | bit--; | ||
146 | ret = regmap_write(tps->regmap, TPS51632_SLEW_REGS, BIT(bit)); | ||
147 | if (ret < 0) | ||
148 | dev_err(tps->dev, "SLEW reg write failed, err %d\n", ret); | ||
149 | return ret; | ||
150 | } | ||
151 | |||
152 | static struct regulator_ops tps51632_dcdc_ops = { | ||
153 | .get_voltage_sel = tps51632_dcdc_get_voltage_sel, | ||
154 | .set_voltage_sel = tps51632_dcdc_set_voltage_sel, | ||
155 | .list_voltage = regulator_list_voltage_linear, | ||
156 | .set_voltage_time_sel = regulator_set_voltage_time_sel, | ||
157 | .set_ramp_delay = tps51632_dcdc_set_ramp_delay, | ||
158 | }; | ||
159 | |||
160 | static int __devinit tps51632_init_dcdc(struct tps51632_chip *tps, | ||
161 | struct tps51632_regulator_platform_data *pdata) | ||
162 | { | ||
163 | int ret; | ||
164 | uint8_t control = 0; | ||
165 | int vsel; | ||
166 | |||
167 | if (!pdata->enable_pwm_dvfs) | ||
168 | goto skip_pwm_config; | ||
169 | |||
170 | control |= TPS51632_DVFS_PWMEN; | ||
171 | tps->enable_pwm_dvfs = pdata->enable_pwm_dvfs; | ||
172 | vsel = TPS51632_VOLT_VSEL(pdata->base_voltage_uV); | ||
173 | ret = regmap_write(tps->regmap, TPS51632_VOLTAGE_BASE_REG, vsel); | ||
174 | if (ret < 0) { | ||
175 | dev_err(tps->dev, "BASE reg write failed, err %d\n", ret); | ||
176 | return ret; | ||
177 | } | ||
178 | |||
179 | if (pdata->dvfs_step_20mV) | ||
180 | control |= TPS51632_DVFS_STEP_20; | ||
181 | |||
182 | if (pdata->max_voltage_uV) { | ||
183 | unsigned int vmax; | ||
184 | /** | ||
185 | * TPS51632 hw behavior: VMAX register can be write only | ||
186 | * once as it get locked after first write. The lock get | ||
187 | * reset only when device is power-reset. | ||
188 | * Write register only when lock bit is not enabled. | ||
189 | */ | ||
190 | ret = regmap_read(tps->regmap, TPS51632_VMAX_REG, &vmax); | ||
191 | if (ret < 0) { | ||
192 | dev_err(tps->dev, "VMAX read failed, err %d\n", ret); | ||
193 | return ret; | ||
194 | } | ||
195 | if (!(vmax & TPS51632_VMAX_LOCK)) { | ||
196 | vsel = TPS51632_VOLT_VSEL(pdata->max_voltage_uV); | ||
197 | ret = regmap_write(tps->regmap, TPS51632_VMAX_REG, | ||
198 | vsel); | ||
199 | if (ret < 0) { | ||
200 | dev_err(tps->dev, | ||
201 | "VMAX write failed, err %d\n", ret); | ||
202 | return ret; | ||
203 | } | ||
204 | } | ||
205 | } | ||
206 | |||
207 | skip_pwm_config: | ||
208 | ret = regmap_write(tps->regmap, TPS51632_DVFS_CONTROL_REG, control); | ||
209 | if (ret < 0) | ||
210 | dev_err(tps->dev, "DVFS reg write failed, err %d\n", ret); | ||
211 | return ret; | ||
212 | } | ||
213 | |||
214 | static bool rd_wr_reg(struct device *dev, unsigned int reg) | ||
215 | { | ||
216 | if ((reg >= 0x8) && (reg <= 0x10)) | ||
217 | return false; | ||
218 | return true; | ||
219 | } | ||
220 | |||
221 | static const struct regmap_config tps51632_regmap_config = { | ||
222 | .reg_bits = 8, | ||
223 | .val_bits = 8, | ||
224 | .writeable_reg = rd_wr_reg, | ||
225 | .readable_reg = rd_wr_reg, | ||
226 | .max_register = TPS51632_MAX_REG - 1, | ||
227 | .cache_type = REGCACHE_RBTREE, | ||
228 | }; | ||
229 | |||
230 | static int __devinit tps51632_probe(struct i2c_client *client, | ||
231 | const struct i2c_device_id *id) | ||
232 | { | ||
233 | struct tps51632_regulator_platform_data *pdata; | ||
234 | struct regulator_dev *rdev; | ||
235 | struct tps51632_chip *tps; | ||
236 | int ret; | ||
237 | struct regulator_config config = { }; | ||
238 | |||
239 | pdata = client->dev.platform_data; | ||
240 | if (!pdata) { | ||
241 | dev_err(&client->dev, "No Platform data\n"); | ||
242 | return -EINVAL; | ||
243 | } | ||
244 | |||
245 | tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); | ||
246 | if (!tps) { | ||
247 | dev_err(&client->dev, "Memory allocation failed\n"); | ||
248 | return -ENOMEM; | ||
249 | } | ||
250 | |||
251 | tps->dev = &client->dev; | ||
252 | tps->desc.name = id->name; | ||
253 | tps->desc.id = 0; | ||
254 | tps->desc.ramp_delay = TPS51632_DEFAULT_RAMP_DELAY; | ||
255 | tps->desc.min_uV = TPS51632_MIN_VOLATGE; | ||
256 | tps->desc.uV_step = TPS51632_VOLATGE_STEP_10mV; | ||
257 | tps->desc.n_voltages = (TPS51632_MAX_VSEL - TPS51632_MIN_VSEL) + 1; | ||
258 | tps->desc.ops = &tps51632_dcdc_ops; | ||
259 | tps->desc.type = REGULATOR_VOLTAGE; | ||
260 | tps->desc.owner = THIS_MODULE; | ||
261 | |||
262 | tps->regmap = devm_regmap_init_i2c(client, &tps51632_regmap_config); | ||
263 | if (IS_ERR(tps->regmap)) { | ||
264 | ret = PTR_ERR(tps->regmap); | ||
265 | dev_err(&client->dev, "regmap init failed, err %d\n", ret); | ||
266 | return ret; | ||
267 | } | ||
268 | i2c_set_clientdata(client, tps); | ||
269 | |||
270 | ret = tps51632_init_dcdc(tps, pdata); | ||
271 | if (ret < 0) { | ||
272 | dev_err(tps->dev, "Init failed, err = %d\n", ret); | ||
273 | return ret; | ||
274 | } | ||
275 | |||
276 | /* Register the regulators */ | ||
277 | config.dev = &client->dev; | ||
278 | config.init_data = pdata->reg_init_data; | ||
279 | config.driver_data = tps; | ||
280 | config.regmap = tps->regmap; | ||
281 | config.of_node = client->dev.of_node; | ||
282 | |||
283 | rdev = regulator_register(&tps->desc, &config); | ||
284 | if (IS_ERR(rdev)) { | ||
285 | dev_err(tps->dev, "regulator register failed\n"); | ||
286 | return PTR_ERR(rdev); | ||
287 | } | ||
288 | |||
289 | tps->rdev = rdev; | ||
290 | return 0; | ||
291 | } | ||
292 | |||
293 | static int __devexit tps51632_remove(struct i2c_client *client) | ||
294 | { | ||
295 | struct tps51632_chip *tps = i2c_get_clientdata(client); | ||
296 | |||
297 | regulator_unregister(tps->rdev); | ||
298 | return 0; | ||
299 | } | ||
300 | |||
301 | static const struct i2c_device_id tps51632_id[] = { | ||
302 | {.name = "tps51632",}, | ||
303 | {}, | ||
304 | }; | ||
305 | |||
306 | MODULE_DEVICE_TABLE(i2c, tps51632_id); | ||
307 | |||
308 | static struct i2c_driver tps51632_i2c_driver = { | ||
309 | .driver = { | ||
310 | .name = "tps51632", | ||
311 | .owner = THIS_MODULE, | ||
312 | }, | ||
313 | .probe = tps51632_probe, | ||
314 | .remove = __devexit_p(tps51632_remove), | ||
315 | .id_table = tps51632_id, | ||
316 | }; | ||
317 | |||
318 | static int __init tps51632_init(void) | ||
319 | { | ||
320 | return i2c_add_driver(&tps51632_i2c_driver); | ||
321 | } | ||
322 | subsys_initcall(tps51632_init); | ||
323 | |||
324 | static void __exit tps51632_cleanup(void) | ||
325 | { | ||
326 | i2c_del_driver(&tps51632_i2c_driver); | ||
327 | } | ||
328 | module_exit(tps51632_cleanup); | ||
329 | |||
330 | MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>"); | ||
331 | MODULE_DESCRIPTION("TPS51632 voltage regulator driver"); | ||
332 | MODULE_LICENSE("GPL v2"); | ||