Lines Matching +full:tps62361 +full:- +full:vout
1 // SPDX-License-Identifier: GPL-2.0-only
3 * tps62360.c -- TI tps62360
40 enum chips {TPS62360, TPS62361, TPS62362, TPS62363}; enumerator
72 * - If it is already there then it will make that register as most
76 * - If requested voltage is not found then it will use the least
86 int new_vset_reg = tps->lru_index[3]; in find_voltage_set_register()
90 if (tps->curr_vset_vsel[tps->lru_index[i]] == req_vsel) { in find_voltage_set_register()
91 new_vset_reg = tps->lru_index[i]; in find_voltage_set_register()
99 for (i = found_index; i > 0; i--) in find_voltage_set_register()
100 tps->lru_index[i] = tps->lru_index[i - 1]; in find_voltage_set_register()
102 tps->lru_index[0] = new_vset_reg; in find_voltage_set_register()
114 ret = regmap_read(tps->regmap, REG_VSET0 + tps->curr_vset_id, &data); in tps62360_dcdc_get_voltage_sel()
116 dev_err(tps->dev, "%s(): register %d read failed with err %d\n", in tps62360_dcdc_get_voltage_sel()
117 __func__, REG_VSET0 + tps->curr_vset_id, ret); in tps62360_dcdc_get_voltage_sel()
120 vsel = (int)data & tps->voltage_reg_mask; in tps62360_dcdc_get_voltage_sel()
130 int new_vset_id = tps->curr_vset_id; in tps62360_dcdc_set_voltage_sel()
136 if (tps->valid_gpios) in tps62360_dcdc_set_voltage_sel()
140 ret = regmap_update_bits(tps->regmap, REG_VSET0 + new_vset_id, in tps62360_dcdc_set_voltage_sel()
141 tps->voltage_reg_mask, selector); in tps62360_dcdc_set_voltage_sel()
143 dev_err(tps->dev, in tps62360_dcdc_set_voltage_sel()
148 tps->curr_vset_id = new_vset_id; in tps62360_dcdc_set_voltage_sel()
149 tps->curr_vset_vsel[new_vset_id] = selector; in tps62360_dcdc_set_voltage_sel()
153 if (tps->valid_gpios) { in tps62360_dcdc_set_voltage_sel()
154 gpiod_set_value_cansleep(tps->vsel0_gpio, new_vset_id & 0x1); in tps62360_dcdc_set_voltage_sel()
155 gpiod_set_value_cansleep(tps->vsel1_gpio, in tps62360_dcdc_set_voltage_sel()
179 return -EINVAL; in tps62360_set_mode()
182 if (!tps->valid_gpios) { in tps62360_set_mode()
183 ret = regmap_update_bits(tps->regmap, in tps62360_set_mode()
184 REG_VSET0 + tps->curr_vset_id, FORCE_PWM_ENABLE, val); in tps62360_set_mode()
186 dev_err(tps->dev, in tps62360_set_mode()
188 __func__, REG_VSET0 + tps->curr_vset_id, ret); in tps62360_set_mode()
194 ret = regmap_update_bits(tps->regmap, in tps62360_set_mode()
197 dev_err(tps->dev, in tps62360_set_mode()
212 ret = regmap_read(tps->regmap, REG_VSET0 + tps->curr_vset_id, &data); in tps62360_get_mode()
214 dev_err(tps->dev, "%s(): register %d read failed with err %d\n", in tps62360_get_mode()
215 __func__, REG_VSET0 + tps->curr_vset_id, ret); in tps62360_get_mode()
239 if (tps->en_internal_pulldn) in tps62360_init_dcdc()
240 ret = regmap_write(tps->regmap, REG_CONTROL, 0xE0); in tps62360_init_dcdc()
242 ret = regmap_write(tps->regmap, REG_CONTROL, 0x0); in tps62360_init_dcdc()
244 dev_err(tps->dev, in tps62360_init_dcdc()
251 ret = regmap_update_bits(tps->regmap, REG_RAMPCTRL, BIT(2), 0); in tps62360_init_dcdc()
253 dev_err(tps->dev, in tps62360_init_dcdc()
260 ret = regmap_read(tps->regmap, REG_RAMPCTRL, &ramp_ctrl); in tps62360_init_dcdc()
262 dev_err(tps->dev, in tps62360_init_dcdc()
270 tps->desc.ramp_delay = DIV_ROUND_UP(32000, BIT(ramp_ctrl)); in tps62360_init_dcdc()
286 struct device_node *np = dev->of_node; in of_get_tps62360_platform_data()
292 pdata->reg_init_data = of_get_regulator_init_data(dev, dev->of_node, in of_get_tps62360_platform_data()
294 if (!pdata->reg_init_data) { in of_get_tps62360_platform_data()
299 if (of_find_property(np, "ti,vsel0-state-high", NULL)) in of_get_tps62360_platform_data()
300 pdata->vsel0_def_state = 1; in of_get_tps62360_platform_data()
302 if (of_find_property(np, "ti,vsel1-state-high", NULL)) in of_get_tps62360_platform_data()
303 pdata->vsel1_def_state = 1; in of_get_tps62360_platform_data()
305 if (of_find_property(np, "ti,enable-pull-down", NULL)) in of_get_tps62360_platform_data()
306 pdata->en_internal_pulldn = true; in of_get_tps62360_platform_data()
308 if (of_find_property(np, "ti,enable-vout-discharge", NULL)) in of_get_tps62360_platform_data()
309 pdata->en_discharge = true; in of_get_tps62360_platform_data()
317 { .compatible = "ti,tps62361", .data = (void *)TPS62361},
337 pdata = dev_get_platdata(&client->dev); in tps62360_probe()
339 tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); in tps62360_probe()
341 return -ENOMEM; in tps62360_probe()
343 tps->desc.name = client->name; in tps62360_probe()
344 tps->desc.id = 0; in tps62360_probe()
345 tps->desc.ops = &tps62360_dcdc_ops; in tps62360_probe()
346 tps->desc.type = REGULATOR_VOLTAGE; in tps62360_probe()
347 tps->desc.owner = THIS_MODULE; in tps62360_probe()
348 tps->desc.uV_step = 10000; in tps62360_probe()
350 if (client->dev.of_node) { in tps62360_probe()
353 &client->dev); in tps62360_probe()
355 dev_err(&client->dev, "Error: No device match found\n"); in tps62360_probe()
356 return -ENODEV; in tps62360_probe()
358 chip_id = (int)(long)match->data; in tps62360_probe()
360 pdata = of_get_tps62360_platform_data(&client->dev, in tps62360_probe()
361 &tps->desc); in tps62360_probe()
363 chip_id = id->driver_data; in tps62360_probe()
365 dev_err(&client->dev, "No device tree match or id table match found\n"); in tps62360_probe()
366 return -ENODEV; in tps62360_probe()
370 dev_err(&client->dev, "%s(): Platform data not found\n", in tps62360_probe()
372 return -EIO; in tps62360_probe()
375 tps->en_discharge = pdata->en_discharge; in tps62360_probe()
376 tps->en_internal_pulldn = pdata->en_internal_pulldn; in tps62360_probe()
377 tps->dev = &client->dev; in tps62360_probe()
382 tps->desc.min_uV = TPS62360_BASE_VOLTAGE; in tps62360_probe()
383 tps->voltage_reg_mask = 0x3F; in tps62360_probe()
384 tps->desc.n_voltages = TPS62360_N_VOLTAGES; in tps62360_probe()
386 case TPS62361: in tps62360_probe()
388 tps->desc.min_uV = TPS62361_BASE_VOLTAGE; in tps62360_probe()
389 tps->voltage_reg_mask = 0x7F; in tps62360_probe()
390 tps->desc.n_voltages = TPS62361_N_VOLTAGES; in tps62360_probe()
393 return -ENODEV; in tps62360_probe()
396 tps->regmap = devm_regmap_init_i2c(client, &tps62360_regmap_config); in tps62360_probe()
397 if (IS_ERR(tps->regmap)) { in tps62360_probe()
398 ret = PTR_ERR(tps->regmap); in tps62360_probe()
399 dev_err(&client->dev, in tps62360_probe()
406 tps->curr_vset_id = (pdata->vsel1_def_state & 1) * 2 + in tps62360_probe()
407 (pdata->vsel0_def_state & 1); in tps62360_probe()
408 tps->lru_index[0] = tps->curr_vset_id; in tps62360_probe()
409 tps->valid_gpios = false; in tps62360_probe()
411 gpio_flags = (pdata->vsel0_def_state) ? in tps62360_probe()
413 tps->vsel0_gpio = devm_gpiod_get_optional(&client->dev, "vsel0", gpio_flags); in tps62360_probe()
414 if (IS_ERR(tps->vsel0_gpio)) { in tps62360_probe()
415 dev_err(&client->dev, in tps62360_probe()
417 __func__, PTR_ERR(tps->vsel0_gpio)); in tps62360_probe()
418 return PTR_ERR(tps->vsel0_gpio); in tps62360_probe()
421 gpio_flags = (pdata->vsel1_def_state) ? in tps62360_probe()
423 tps->vsel1_gpio = devm_gpiod_get_optional(&client->dev, "vsel1", gpio_flags); in tps62360_probe()
424 if (IS_ERR(tps->vsel1_gpio)) { in tps62360_probe()
425 dev_err(&client->dev, in tps62360_probe()
427 __func__, PTR_ERR(tps->vsel1_gpio)); in tps62360_probe()
428 return PTR_ERR(tps->vsel1_gpio); in tps62360_probe()
431 if (tps->vsel0_gpio != NULL && tps->vsel1_gpio != NULL) { in tps62360_probe()
432 tps->valid_gpios = true; in tps62360_probe()
437 * set with the tps->curr_vset_id */ in tps62360_probe()
439 tps->lru_index[i] = i; in tps62360_probe()
440 tps->lru_index[0] = tps->curr_vset_id; in tps62360_probe()
441 tps->lru_index[tps->curr_vset_id] = 0; in tps62360_probe()
446 dev_err(tps->dev, "%s(): Init failed with err = %d\n", in tps62360_probe()
451 config.dev = &client->dev; in tps62360_probe()
452 config.init_data = pdata->reg_init_data; in tps62360_probe()
454 config.of_node = client->dev.of_node; in tps62360_probe()
457 rdev = devm_regulator_register(&client->dev, &tps->desc, &config); in tps62360_probe()
459 dev_err(tps->dev, in tps62360_probe()
461 __func__, id->name); in tps62360_probe()
465 tps->rdev = rdev; in tps62360_probe()
474 if (!tps->en_discharge) in tps62360_shutdown()
478 st = regmap_update_bits(tps->regmap, REG_RAMPCTRL, BIT(2), BIT(2)); in tps62360_shutdown()
480 dev_err(tps->dev, in tps62360_shutdown()
487 {.name = "tps62361", .driver_data = TPS62361},