25 #include <linux/kernel.h>
26 #include <linux/module.h>
38 #include <linux/i2c.h>
39 #include <linux/slab.h>
49 #define REG_RAMPCTRL 6
52 #define FORCE_PWM_ENABLE BIT(7)
56 #define TPS62360_BASE_VOLTAGE 770000
57 #define TPS62360_N_VOLTAGES 64
59 #define TPS62361_BASE_VOLTAGE 500000
60 #define TPS62361_N_VOLTAGES 128
96 int req_vsel,
int *vset_reg_id)
103 for (i = 0; i < 4; ++
i) {
108 goto update_lru_index;
113 for (i = found_index; i > 0; i--)
117 *vset_reg_id = new_vset_reg;
130 dev_err(tps->
dev,
"%s(): register %d read failed with err %d\n",
138 static int tps62360_dcdc_set_voltage_sel(
struct regulator_dev *dev,
151 found = find_voltage_set_register(tps, selector, &new_vset_id);
158 "%s(): register %d update failed with err %d\n",
170 (new_vset_id >> 1) & 0x1);
201 "%s(): register %d update failed with err %d\n",
207 for (i = 0; i < 4; ++
i) {
212 "%s(): register %d update failed with err %d\n",
220 static unsigned int tps62360_get_mode(
struct regulator_dev *rdev)
228 dev_err(tps->
dev,
"%s(): register %d read failed with err %d\n",
237 .get_voltage_sel = tps62360_dcdc_get_voltage_sel,
238 .set_voltage_sel = tps62360_dcdc_set_voltage_sel,
242 .set_mode = tps62360_set_mode,
243 .get_mode = tps62360_get_mode,
250 unsigned int ramp_ctrl;
259 "%s(): register %d write failed with err %d\n",
268 "%s(): register %d update failed with err %d\n",
277 "%s(): register %d read failed with err %d\n",
281 ramp_ctrl = (ramp_ctrl >> 4) & 0x7;
288 static const struct regmap_config tps62360_regmap_config = {
296 of_get_tps62360_platform_data(
struct device *dev)
303 dev_err(dev,
"Memory alloc failed for platform data\n");
309 dev_err(dev,
"Not able to get OF regulator init data\n");
313 pdata->
vsel0_gpio = of_get_named_gpio(np,
"vsel0-gpio", 0);
314 pdata->
vsel1_gpio = of_get_named_gpio(np,
"vsel1-gpio", 0);
331 #if defined(CONFIG_OF)
332 static const struct of_device_id tps62360_of_match[] = {
334 { .compatible =
"ti,tps62361", .data = (
void *)
TPS62361},
335 { .compatible =
"ti,tps62362", .data = (
void *)
TPS62362},
336 { .compatible =
"ti,tps62363", .data = (
void *)
TPS62363},
353 pdata = client->
dev.platform_data;
354 chip_id =
id->driver_data;
356 if (client->
dev.of_node) {
361 dev_err(&client->
dev,
"Error: No device match found\n");
366 pdata = of_get_tps62360_platform_data(&client->
dev);
370 dev_err(&client->
dev,
"%s(): Platform data not found\n",
377 dev_err(&client->
dev,
"%s(): Memory allocation failed\n",
405 tps->
desc.name =
id->name;
407 tps->
desc.ops = &tps62360_dcdc_ops;
410 tps->
desc.uV_step = 10000;
413 if (IS_ERR(tps->
regmap)) {
414 ret = PTR_ERR(tps->
regmap);
416 "%s(): regmap allocation failed with err %d\n",
420 i2c_set_clientdata(client, tps);
432 gpio_flags,
"tps62360-vsel0");
435 "%s(): Could not obtain vsel0 GPIO %d: %d\n",
443 gpio_flags,
"tps62360-vsel1");
446 "%s(): Could not obtain vsel1 GPIO %d: %d\n",
456 for (i = 0; i < 4; ++
i)
462 ret = tps62360_init_dcdc(tps, pdata);
464 dev_err(tps->
dev,
"%s(): Init failed with err = %d\n",
469 config.
dev = &client->
dev;
478 "%s(): regulator register failed with err %s\n",
480 return PTR_ERR(rdev);
501 static void tps62360_shutdown(
struct i2c_client *client)
513 "%s(): register %d update failed with err %d\n",
518 {.name =
"tps62360", .driver_data =
TPS62360},
519 {.name =
"tps62361", .driver_data =
TPS62361},
520 {.name =
"tps62362", .driver_data =
TPS62362},
521 {.name =
"tps62363", .driver_data =
TPS62363},
527 static struct i2c_driver tps62360_i2c_driver = {
533 .probe = tps62360_probe,
535 .shutdown = tps62360_shutdown,
536 .id_table = tps62360_id,
539 static int __init tps62360_init(
void)
541 return i2c_add_driver(&tps62360_i2c_driver);
545 static void __exit tps62360_cleanup(
void)