Lines Matching +full:vsel1 +full:- +full:state +full:- +full:high
1 // SPDX-License-Identifier: GPL-2.0-only
3 * tps62360.c -- TI tps62360
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 pdata->vsel0_def_state = of_property_read_bool(np, "ti,vsel0-state-high"); in of_get_tps62360_platform_data()
300 pdata->vsel1_def_state = of_property_read_bool(np, "ti,vsel1-state-high"); in of_get_tps62360_platform_data()
301 pdata->en_internal_pulldn = of_property_read_bool(np, "ti,enable-pull-down"); in of_get_tps62360_platform_data()
302 pdata->en_discharge = of_property_read_bool(np, "ti,enable-vout-discharge"); in of_get_tps62360_platform_data()
330 pdata = dev_get_platdata(&client->dev); in tps62360_probe()
332 tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); in tps62360_probe()
334 return -ENOMEM; in tps62360_probe()
336 tps->desc.name = client->name; in tps62360_probe()
337 tps->desc.id = 0; in tps62360_probe()
338 tps->desc.ops = &tps62360_dcdc_ops; in tps62360_probe()
339 tps->desc.type = REGULATOR_VOLTAGE; in tps62360_probe()
340 tps->desc.owner = THIS_MODULE; in tps62360_probe()
341 tps->desc.uV_step = 10000; in tps62360_probe()
343 if (client->dev.of_node) { in tps62360_probe()
346 &client->dev); in tps62360_probe()
348 dev_err(&client->dev, "Error: No device match found\n"); in tps62360_probe()
349 return -ENODEV; in tps62360_probe()
351 chip_id = (int)(long)match->data; in tps62360_probe()
353 pdata = of_get_tps62360_platform_data(&client->dev, in tps62360_probe()
354 &tps->desc); in tps62360_probe()
356 chip_id = id->driver_data; in tps62360_probe()
358 dev_err(&client->dev, "No device tree match or id table match found\n"); in tps62360_probe()
359 return -ENODEV; in tps62360_probe()
363 dev_err(&client->dev, "%s(): Platform data not found\n", in tps62360_probe()
365 return -EIO; in tps62360_probe()
368 tps->en_discharge = pdata->en_discharge; in tps62360_probe()
369 tps->en_internal_pulldn = pdata->en_internal_pulldn; in tps62360_probe()
370 tps->dev = &client->dev; in tps62360_probe()
375 tps->desc.min_uV = TPS62360_BASE_VOLTAGE; in tps62360_probe()
376 tps->voltage_reg_mask = 0x3F; in tps62360_probe()
377 tps->desc.n_voltages = TPS62360_N_VOLTAGES; in tps62360_probe()
381 tps->desc.min_uV = TPS62361_BASE_VOLTAGE; in tps62360_probe()
382 tps->voltage_reg_mask = 0x7F; in tps62360_probe()
383 tps->desc.n_voltages = TPS62361_N_VOLTAGES; in tps62360_probe()
386 return -ENODEV; in tps62360_probe()
389 tps->regmap = devm_regmap_init_i2c(client, &tps62360_regmap_config); in tps62360_probe()
390 if (IS_ERR(tps->regmap)) { in tps62360_probe()
391 ret = PTR_ERR(tps->regmap); in tps62360_probe()
392 dev_err(&client->dev, in tps62360_probe()
399 tps->curr_vset_id = (pdata->vsel1_def_state & 1) * 2 + in tps62360_probe()
400 (pdata->vsel0_def_state & 1); in tps62360_probe()
401 tps->lru_index[0] = tps->curr_vset_id; in tps62360_probe()
402 tps->valid_gpios = false; in tps62360_probe()
404 gpio_flags = (pdata->vsel0_def_state) ? in tps62360_probe()
406 tps->vsel0_gpio = devm_gpiod_get_optional(&client->dev, "vsel0", gpio_flags); in tps62360_probe()
407 if (IS_ERR(tps->vsel0_gpio)) { in tps62360_probe()
408 dev_err(&client->dev, in tps62360_probe()
410 __func__, PTR_ERR(tps->vsel0_gpio)); in tps62360_probe()
411 return PTR_ERR(tps->vsel0_gpio); in tps62360_probe()
414 gpio_flags = (pdata->vsel1_def_state) ? in tps62360_probe()
416 tps->vsel1_gpio = devm_gpiod_get_optional(&client->dev, "vsel1", gpio_flags); in tps62360_probe()
417 if (IS_ERR(tps->vsel1_gpio)) { in tps62360_probe()
418 dev_err(&client->dev, in tps62360_probe()
419 "%s(): Could not obtain vsel1 GPIO: %ld\n", in tps62360_probe()
420 __func__, PTR_ERR(tps->vsel1_gpio)); in tps62360_probe()
421 return PTR_ERR(tps->vsel1_gpio); in tps62360_probe()
424 if (tps->vsel0_gpio != NULL && tps->vsel1_gpio != NULL) { in tps62360_probe()
425 tps->valid_gpios = true; in tps62360_probe()
430 * set with the tps->curr_vset_id */ in tps62360_probe()
432 tps->lru_index[i] = i; in tps62360_probe()
433 tps->lru_index[0] = tps->curr_vset_id; in tps62360_probe()
434 tps->lru_index[tps->curr_vset_id] = 0; in tps62360_probe()
439 dev_err(tps->dev, "%s(): Init failed with err = %d\n", in tps62360_probe()
444 config.dev = &client->dev; in tps62360_probe()
445 config.init_data = pdata->reg_init_data; in tps62360_probe()
447 config.of_node = client->dev.of_node; in tps62360_probe()
450 rdev = devm_regulator_register(&client->dev, &tps->desc, &config); in tps62360_probe()
452 dev_err(tps->dev, in tps62360_probe()
454 __func__, id->name); in tps62360_probe()
458 tps->rdev = rdev; in tps62360_probe()
467 if (!tps->en_discharge) in tps62360_shutdown()
471 st = regmap_update_bits(tps->regmap, REG_RAMPCTRL, BIT(2), BIT(2)); in tps62360_shutdown()
473 dev_err(tps->dev, in tps62360_shutdown()