Lines Matching +full:vsel +full:- +full:state +full:- +full:high

1 // SPDX-License-Identifier: GPL-2.0-only
3 * max8973-regulator.c -- Maxim max8973A
5 * Regulator driver for MAXIM 8973A DC-DC step-down switching regulator.
21 #include <linux/regulator/max8973-regulator.h>
123 * - If it is already there then it will make that register as most
127 * - If requested voltage is not found then it will use the least
137 int new_vout_reg = tps->lru_index[MAX8973_MAX_VOUT_REG - 1]; in find_voltage_set_register()
138 int found_index = MAX8973_MAX_VOUT_REG - 1; in find_voltage_set_register()
141 if (tps->curr_vout_val[tps->lru_index[i]] == req_vsel) { in find_voltage_set_register()
142 new_vout_reg = tps->lru_index[i]; in find_voltage_set_register()
150 for (i = found_index; i > 0; i--) in find_voltage_set_register()
151 tps->lru_index[i] = tps->lru_index[i - 1]; in find_voltage_set_register()
153 tps->lru_index[0] = new_vout_reg; in find_voltage_set_register()
165 ret = regmap_read(max->regmap, max->curr_vout_reg, &data); in max8973_dcdc_get_voltage_sel()
167 dev_err(max->dev, "register %d read failed, err = %d\n", in max8973_dcdc_get_voltage_sel()
168 max->curr_vout_reg, ret); in max8973_dcdc_get_voltage_sel()
175 unsigned vsel) in max8973_dcdc_set_voltage_sel() argument
180 int vout_reg = max->curr_vout_reg; in max8973_dcdc_set_voltage_sel()
181 int gpio_val = max->curr_gpio_val; in max8973_dcdc_set_voltage_sel()
187 if (gpio_is_valid(max->dvs_gpio)) in max8973_dcdc_set_voltage_sel()
188 found = find_voltage_set_register(max, vsel, in max8973_dcdc_set_voltage_sel()
192 ret = regmap_update_bits(max->regmap, vout_reg, in max8973_dcdc_set_voltage_sel()
193 MAX8973_VOUT_MASK, vsel); in max8973_dcdc_set_voltage_sel()
195 dev_err(max->dev, "register %d update failed, err %d\n", in max8973_dcdc_set_voltage_sel()
199 max->curr_vout_reg = vout_reg; in max8973_dcdc_set_voltage_sel()
200 max->curr_vout_val[gpio_val] = vsel; in max8973_dcdc_set_voltage_sel()
204 if (gpio_is_valid(max->dvs_gpio)) { in max8973_dcdc_set_voltage_sel()
205 gpio_set_value_cansleep(max->dvs_gpio, gpio_val & 0x1); in max8973_dcdc_set_voltage_sel()
206 max->curr_gpio_val = gpio_val; in max8973_dcdc_set_voltage_sel()
228 return -EINVAL; in max8973_dcdc_set_mode()
231 ret = regmap_update_bits(max->regmap, MAX8973_CONTROL1, in max8973_dcdc_set_mode()
234 dev_err(max->dev, "register %d update failed, err %d\n", in max8973_dcdc_set_mode()
245 ret = regmap_read(max->regmap, MAX8973_CONTROL1, &data); in max8973_dcdc_get_mode()
247 dev_err(max->dev, "register %d read failed, err %d\n", in max8973_dcdc_get_mode()
269 ret = regmap_update_bits(max->regmap, MAX8973_CONTROL2, in max8973_set_current_limit()
272 dev_err(max->dev, "register %d update failed: %d\n", in max8973_set_current_limit()
285 ret = regmap_read(max->regmap, MAX8973_CONTROL2, &control2); in max8973_get_current_limit()
287 dev_err(max->dev, "register %d read failed: %d\n", in max8973_get_current_limit()
326 ret = regmap_read(max->regmap, MAX8973_CONTROL1, &data); in max8973_init_dcdc()
328 dev_err(max->dev, "register %d read failed, err = %d", in max8973_init_dcdc()
335 max->desc.ramp_delay = 12000; in max8973_init_dcdc()
338 max->desc.ramp_delay = 25000; in max8973_init_dcdc()
341 max->desc.ramp_delay = 50000; in max8973_init_dcdc()
344 max->desc.ramp_delay = 200000; in max8973_init_dcdc()
348 if (pdata->control_flags & MAX8973_CONTROL_REMOTE_SENSE_ENABLE) in max8973_init_dcdc()
351 if (!(pdata->control_flags & MAX8973_CONTROL_FALLING_SLEW_RATE_ENABLE)) in max8973_init_dcdc()
354 if (pdata->control_flags & MAX8973_CONTROL_OUTPUT_ACTIVE_DISCH_ENABLE) in max8973_init_dcdc()
357 if (pdata->control_flags & MAX8973_CONTROL_BIAS_ENABLE) { in max8973_init_dcdc()
359 max->desc.enable_time = 20; in max8973_init_dcdc()
361 max->desc.enable_time = 240; in max8973_init_dcdc()
364 if (pdata->control_flags & MAX8973_CONTROL_FREQ_SHIFT_9PER_ENABLE) in max8973_init_dcdc()
367 if ((pdata->junction_temp_warning == MAX77621_TJINT_WARNING_TEMP_120) && in max8973_init_dcdc()
368 (max->id == MAX77621)) in max8973_init_dcdc()
371 if (!(pdata->control_flags & MAX8973_CONTROL_PULL_DOWN_ENABLE)) in max8973_init_dcdc()
375 switch (pdata->control_flags & MAX8973_CONTROL_CLKADV_TRIP_MASK) { in max8973_init_dcdc()
394 switch (pdata->control_flags & MAX8973_CONTROL_INDUCTOR_VALUE_MASK) { in max8973_init_dcdc()
412 ret = regmap_write(max->regmap, MAX8973_CONTROL1, control1); in max8973_init_dcdc()
414 dev_err(max->dev, "register %d write failed, err = %d", in max8973_init_dcdc()
419 ret = regmap_write(max->regmap, MAX8973_CONTROL2, control2); in max8973_init_dcdc()
421 dev_err(max->dev, "register %d write failed, err = %d", in max8973_init_dcdc()
427 if (max->enable_external_control && (max->id == MAX8973)) { in max8973_init_dcdc()
428 ret = regmap_update_bits(max->regmap, MAX8973_VOUT, in max8973_init_dcdc()
431 dev_err(max->dev, "register %d update failed, err = %d", in max8973_init_dcdc()
439 struct max8973_chip *mchip = tz->devdata; in max8973_thermal_read_temp()
443 ret = regmap_read(mchip->regmap, MAX8973_CHIPID1, &val); in max8973_thermal_read_temp()
445 dev_err(mchip->dev, "Failed to read register CHIPID1, %d", ret); in max8973_thermal_read_temp()
451 *temp = mchip->junction_temp_warning + 1000; in max8973_thermal_read_temp()
462 thermal_zone_device_update(mchip->tz_device, in max8973_thermal_irq()
479 if (mchip->id != MAX77621) in max8973_thermal_init()
482 tzd = devm_thermal_of_zone_register(mchip->dev, 0, mchip, in max8973_thermal_init()
486 dev_err(mchip->dev, "Failed to register thermal sensor: %d\n", in max8973_thermal_init()
491 if (mchip->irq <= 0) in max8973_thermal_init()
494 irq_data = irq_get_irq_data(mchip->irq); in max8973_thermal_init()
498 ret = devm_request_threaded_irq(mchip->dev, mchip->irq, NULL, in max8973_thermal_init()
501 dev_name(mchip->dev), mchip); in max8973_thermal_init()
503 dev_err(mchip->dev, "Failed to request irq %d, %d\n", in max8973_thermal_init()
504 mchip->irq, ret); in max8973_thermal_init()
522 struct device_node *np = dev->of_node; in max8973_parse_dt()
532 pdata->enable_ext_control = of_property_read_bool(np, in max8973_parse_dt()
533 "maxim,externally-enable"); in max8973_parse_dt()
534 pdata->dvs_gpio = of_get_named_gpio(np, "maxim,dvs-gpio", 0); in max8973_parse_dt()
536 ret = of_property_read_u32(np, "maxim,dvs-default-state", &pval); in max8973_parse_dt()
538 pdata->dvs_def_state = pval; in max8973_parse_dt()
540 if (of_property_read_bool(np, "maxim,enable-remote-sense")) in max8973_parse_dt()
541 pdata->control_flags |= MAX8973_CONTROL_REMOTE_SENSE_ENABLE; in max8973_parse_dt()
543 if (of_property_read_bool(np, "maxim,enable-falling-slew-rate")) in max8973_parse_dt()
544 pdata->control_flags |= in max8973_parse_dt()
547 if (of_property_read_bool(np, "maxim,enable-active-discharge")) in max8973_parse_dt()
548 pdata->control_flags |= in max8973_parse_dt()
551 if (of_property_read_bool(np, "maxim,enable-frequency-shift")) in max8973_parse_dt()
552 pdata->control_flags |= MAX8973_CONTROL_FREQ_SHIFT_9PER_ENABLE; in max8973_parse_dt()
554 if (of_property_read_bool(np, "maxim,enable-bias-control")) in max8973_parse_dt()
555 pdata->control_flags |= MAX8973_CONTROL_BIAS_ENABLE; in max8973_parse_dt()
557 etr_enable = of_property_read_bool(np, "maxim,enable-etr"); in max8973_parse_dt()
559 "maxim,enable-high-etr-sensitivity"); in max8973_parse_dt()
565 pdata->control_flags |= in max8973_parse_dt()
568 pdata->control_flags |= in max8973_parse_dt()
571 pdata->control_flags |= MAX8973_CONTROL_CLKADV_TRIP_DISABLED; in max8973_parse_dt()
574 pdata->junction_temp_warning = MAX77621_TJINT_WARNING_TEMP_140; in max8973_parse_dt()
575 ret = of_property_read_u32(np, "junction-warn-millicelsius", &pval); in max8973_parse_dt()
577 pdata->junction_temp_warning = MAX77621_TJINT_WARNING_TEMP_120; in max8973_parse_dt()
603 pdata = dev_get_platdata(&client->dev); in max8973_probe()
605 if (!pdata && client->dev.of_node) { in max8973_probe()
606 pdata = max8973_parse_dt(&client->dev); in max8973_probe()
611 dev_err(&client->dev, "No Platform data"); in max8973_probe()
612 return -EIO; in max8973_probe()
615 if (pdata->dvs_gpio == -EPROBE_DEFER) in max8973_probe()
616 return -EPROBE_DEFER; in max8973_probe()
618 max = devm_kzalloc(&client->dev, sizeof(*max), GFP_KERNEL); in max8973_probe()
620 return -ENOMEM; in max8973_probe()
622 max->regmap = devm_regmap_init_i2c(client, &max8973_regmap_config); in max8973_probe()
623 if (IS_ERR(max->regmap)) { in max8973_probe()
624 ret = PTR_ERR(max->regmap); in max8973_probe()
625 dev_err(&client->dev, "regmap init failed, err %d\n", ret); in max8973_probe()
629 if (client->dev.of_node) { in max8973_probe()
633 &client->dev); in max8973_probe()
635 return -ENODATA; in max8973_probe()
636 max->id = (u32)((uintptr_t)match->data); in max8973_probe()
638 max->id = id->driver_data; in max8973_probe()
641 ret = regmap_read(max->regmap, MAX8973_CHIPID1, &chip_id); in max8973_probe()
643 dev_err(&client->dev, "register CHIPID1 read failed, %d", ret); in max8973_probe()
647 dev_info(&client->dev, "CHIP-ID OTP: 0x%02x ID_M: 0x%02x\n", in max8973_probe()
651 max->ops = max8973_dcdc_ops; in max8973_probe()
652 max->dev = &client->dev; in max8973_probe()
653 max->desc.name = id->name; in max8973_probe()
654 max->desc.id = 0; in max8973_probe()
655 max->desc.ops = &max->ops; in max8973_probe()
656 max->desc.type = REGULATOR_VOLTAGE; in max8973_probe()
657 max->desc.owner = THIS_MODULE; in max8973_probe()
658 max->desc.min_uV = MAX8973_MIN_VOLATGE; in max8973_probe()
659 max->desc.uV_step = MAX8973_VOLATGE_STEP; in max8973_probe()
660 max->desc.n_voltages = MAX8973_BUCK_N_VOLTAGE; in max8973_probe()
661 max->desc.ramp_reg = MAX8973_CONTROL1; in max8973_probe()
662 max->desc.ramp_mask = MAX8973_RAMP_MASK; in max8973_probe()
663 max->desc.ramp_delay_table = max8973_buck_ramp_table; in max8973_probe()
664 max->desc.n_ramp_values = ARRAY_SIZE(max8973_buck_ramp_table); in max8973_probe()
666 max->dvs_gpio = (pdata->dvs_gpio) ? pdata->dvs_gpio : -EINVAL; in max8973_probe()
667 max->enable_external_control = pdata->enable_ext_control; in max8973_probe()
668 max->curr_gpio_val = pdata->dvs_def_state; in max8973_probe()
669 max->curr_vout_reg = MAX8973_VOUT + pdata->dvs_def_state; in max8973_probe()
670 max->junction_temp_warning = pdata->junction_temp_warning; in max8973_probe()
672 max->lru_index[0] = max->curr_vout_reg; in max8973_probe()
674 if (gpio_is_valid(max->dvs_gpio)) { in max8973_probe()
678 gpio_flags = (pdata->dvs_def_state) ? in max8973_probe()
680 ret = devm_gpio_request_one(&client->dev, max->dvs_gpio, in max8973_probe()
681 gpio_flags, "max8973-dvs"); in max8973_probe()
683 dev_err(&client->dev, in max8973_probe()
685 max->dvs_gpio, ret); in max8973_probe()
692 * set with the max->curr_vout_reg */ in max8973_probe()
694 max->lru_index[i] = i; in max8973_probe()
695 max->lru_index[0] = max->curr_vout_reg; in max8973_probe()
696 max->lru_index[max->curr_vout_reg] = 0; in max8973_probe()
702 max->ops.set_voltage_sel = regulator_set_voltage_sel_regmap; in max8973_probe()
703 max->ops.get_voltage_sel = regulator_get_voltage_sel_regmap; in max8973_probe()
704 max->desc.vsel_reg = max->curr_vout_reg; in max8973_probe()
705 max->desc.vsel_mask = MAX8973_VOUT_MASK; in max8973_probe()
709 pdata->reg_init_data = of_get_regulator_init_data(&client->dev, in max8973_probe()
710 client->dev.of_node, &max->desc); in max8973_probe()
712 ridata = pdata->reg_init_data; in max8973_probe()
713 switch (max->id) { in max8973_probe()
715 if (!pdata->enable_ext_control) { in max8973_probe()
716 max->desc.enable_reg = MAX8973_VOUT; in max8973_probe()
717 max->desc.enable_mask = MAX8973_VOUT_ENABLE; in max8973_probe()
718 max->ops.enable = regulator_enable_regmap; in max8973_probe()
719 max->ops.disable = regulator_disable_regmap; in max8973_probe()
720 max->ops.is_enabled = regulator_is_enabled_regmap; in max8973_probe()
724 if (ridata && (ridata->constraints.always_on || in max8973_probe()
725 ridata->constraints.boot_on)) in max8973_probe()
730 gpiod = devm_gpiod_get_optional(&client->dev, in max8973_probe()
737 max->enable_external_control = true; in max8973_probe()
747 gpiod = devm_gpiod_get_optional(&client->dev, in max8973_probe()
753 max->enable_external_control = true; in max8973_probe()
755 max->desc.enable_reg = MAX8973_VOUT; in max8973_probe()
756 max->desc.enable_mask = MAX8973_VOUT_ENABLE; in max8973_probe()
757 max->ops.enable = regulator_enable_regmap; in max8973_probe()
758 max->ops.disable = regulator_disable_regmap; in max8973_probe()
759 max->ops.is_enabled = regulator_is_enabled_regmap; in max8973_probe()
760 max->ops.set_current_limit = max8973_set_current_limit; in max8973_probe()
761 max->ops.get_current_limit = max8973_get_current_limit; in max8973_probe()
769 dev_err(max->dev, "Max8973 Init failed, err = %d\n", ret); in max8973_probe()
773 config.dev = &client->dev; in max8973_probe()
774 config.init_data = pdata->reg_init_data; in max8973_probe()
776 config.of_node = client->dev.of_node; in max8973_probe()
777 config.regmap = max->regmap; in max8973_probe()
785 devm_gpiod_unhinge(&client->dev, config.ena_gpiod); in max8973_probe()
786 rdev = devm_regulator_register(&client->dev, &max->desc, &config); in max8973_probe()
789 dev_err(max->dev, "regulator register failed, err %d\n", ret); in max8973_probe()