Lines Matching +full:enable +full:- +full:active +full:- +full:discharge
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>
121 * - If it is already there then it will make that register as most
125 * - If requested voltage is not found then it will use the least
135 int new_vout_reg = tps->lru_index[MAX8973_MAX_VOUT_REG - 1]; in find_voltage_set_register()
136 int found_index = MAX8973_MAX_VOUT_REG - 1; in find_voltage_set_register()
139 if (tps->curr_vout_val[tps->lru_index[i]] == req_vsel) { in find_voltage_set_register()
140 new_vout_reg = tps->lru_index[i]; in find_voltage_set_register()
148 for (i = found_index; i > 0; i--) in find_voltage_set_register()
149 tps->lru_index[i] = tps->lru_index[i - 1]; in find_voltage_set_register()
151 tps->lru_index[0] = new_vout_reg; in find_voltage_set_register()
163 ret = regmap_read(max->regmap, max->curr_vout_reg, &data); in max8973_dcdc_get_voltage_sel()
165 dev_err(max->dev, "register %d read failed, err = %d\n", in max8973_dcdc_get_voltage_sel()
166 max->curr_vout_reg, ret); in max8973_dcdc_get_voltage_sel()
178 int vout_reg = max->curr_vout_reg; in max8973_dcdc_set_voltage_sel()
179 int gpio_val = max->curr_gpio_val; in max8973_dcdc_set_voltage_sel()
185 if (max->dvs_gpiod) in max8973_dcdc_set_voltage_sel()
190 ret = regmap_update_bits(max->regmap, vout_reg, in max8973_dcdc_set_voltage_sel()
193 dev_err(max->dev, "register %d update failed, err %d\n", in max8973_dcdc_set_voltage_sel()
197 max->curr_vout_reg = vout_reg; in max8973_dcdc_set_voltage_sel()
198 max->curr_vout_val[gpio_val] = vsel; in max8973_dcdc_set_voltage_sel()
202 if (max->dvs_gpiod) { in max8973_dcdc_set_voltage_sel()
203 gpiod_set_value_cansleep(max->dvs_gpiod, gpio_val & 0x1); in max8973_dcdc_set_voltage_sel()
204 max->curr_gpio_val = gpio_val; in max8973_dcdc_set_voltage_sel()
215 /* Enable force PWM mode in FAST mode only. */ in max8973_dcdc_set_mode()
226 return -EINVAL; in max8973_dcdc_set_mode()
229 ret = regmap_update_bits(max->regmap, MAX8973_CONTROL1, in max8973_dcdc_set_mode()
232 dev_err(max->dev, "register %d update failed, err %d\n", in max8973_dcdc_set_mode()
243 ret = regmap_read(max->regmap, MAX8973_CONTROL1, &data); in max8973_dcdc_get_mode()
245 dev_err(max->dev, "register %d read failed, err %d\n", in max8973_dcdc_get_mode()
267 ret = regmap_update_bits(max->regmap, MAX8973_CONTROL2, in max8973_set_current_limit()
270 dev_err(max->dev, "register %d update failed: %d\n", in max8973_set_current_limit()
283 ret = regmap_read(max->regmap, MAX8973_CONTROL2, &control2); in max8973_get_current_limit()
285 dev_err(max->dev, "register %d read failed: %d\n", in max8973_get_current_limit()
324 ret = regmap_read(max->regmap, MAX8973_CONTROL1, &data); in max8973_init_dcdc()
326 dev_err(max->dev, "register %d read failed, err = %d", in max8973_init_dcdc()
333 max->desc.ramp_delay = 12000; in max8973_init_dcdc()
336 max->desc.ramp_delay = 25000; in max8973_init_dcdc()
339 max->desc.ramp_delay = 50000; in max8973_init_dcdc()
342 max->desc.ramp_delay = 200000; in max8973_init_dcdc()
346 if (pdata->control_flags & MAX8973_CONTROL_REMOTE_SENSE_ENABLE) in max8973_init_dcdc()
349 if (!(pdata->control_flags & MAX8973_CONTROL_FALLING_SLEW_RATE_ENABLE)) in max8973_init_dcdc()
352 if (pdata->control_flags & MAX8973_CONTROL_OUTPUT_ACTIVE_DISCH_ENABLE) in max8973_init_dcdc()
355 if (pdata->control_flags & MAX8973_CONTROL_BIAS_ENABLE) { in max8973_init_dcdc()
357 max->desc.enable_time = 20; in max8973_init_dcdc()
359 max->desc.enable_time = 240; in max8973_init_dcdc()
362 if (pdata->control_flags & MAX8973_CONTROL_FREQ_SHIFT_9PER_ENABLE) in max8973_init_dcdc()
365 if ((pdata->junction_temp_warning == MAX77621_TJINT_WARNING_TEMP_120) && in max8973_init_dcdc()
366 (max->id == MAX77621)) in max8973_init_dcdc()
369 if (!(pdata->control_flags & MAX8973_CONTROL_PULL_DOWN_ENABLE)) in max8973_init_dcdc()
373 switch (pdata->control_flags & MAX8973_CONTROL_CLKADV_TRIP_MASK) { in max8973_init_dcdc()
392 switch (pdata->control_flags & MAX8973_CONTROL_INDUCTOR_VALUE_MASK) { in max8973_init_dcdc()
410 ret = regmap_write(max->regmap, MAX8973_CONTROL1, control1); in max8973_init_dcdc()
412 dev_err(max->dev, "register %d write failed, err = %d", in max8973_init_dcdc()
417 ret = regmap_write(max->regmap, MAX8973_CONTROL2, control2); in max8973_init_dcdc()
419 dev_err(max->dev, "register %d write failed, err = %d", in max8973_init_dcdc()
425 if (max->enable_external_control && (max->id == MAX8973)) { in max8973_init_dcdc()
426 ret = regmap_update_bits(max->regmap, MAX8973_VOUT, in max8973_init_dcdc()
429 dev_err(max->dev, "register %d update failed, err = %d", in max8973_init_dcdc()
441 ret = regmap_read(mchip->regmap, MAX8973_CHIPID1, &val); in max8973_thermal_read_temp()
443 dev_err(mchip->dev, "Failed to read register CHIPID1, %d", ret); in max8973_thermal_read_temp()
449 *temp = mchip->junction_temp_warning + 1000; in max8973_thermal_read_temp()
460 thermal_zone_device_update(mchip->tz_device, in max8973_thermal_irq()
476 if (mchip->id != MAX77621) in max8973_thermal_init()
479 tzd = devm_thermal_of_zone_register(mchip->dev, 0, mchip, in max8973_thermal_init()
483 dev_err(mchip->dev, "Failed to register thermal sensor: %d\n", in max8973_thermal_init()
488 if (mchip->irq <= 0) in max8973_thermal_init()
491 irq_flags = irq_get_trigger_type(mchip->irq); in max8973_thermal_init()
493 ret = devm_request_threaded_irq(mchip->dev, mchip->irq, NULL, in max8973_thermal_init()
496 dev_name(mchip->dev), mchip); in max8973_thermal_init()
498 dev_err(mchip->dev, "Failed to request irq %d, %d\n", in max8973_thermal_init()
499 mchip->irq, ret); in max8973_thermal_init()
517 struct device_node *np = dev->of_node; in max8973_parse_dt()
527 pdata->enable_ext_control = of_property_read_bool(np, in max8973_parse_dt()
528 "maxim,externally-enable"); in max8973_parse_dt()
530 ret = of_property_read_u32(np, "maxim,dvs-default-state", &pval); in max8973_parse_dt()
532 pdata->dvs_def_state = pval; in max8973_parse_dt()
534 if (of_property_read_bool(np, "maxim,enable-remote-sense")) in max8973_parse_dt()
535 pdata->control_flags |= MAX8973_CONTROL_REMOTE_SENSE_ENABLE; in max8973_parse_dt()
537 if (of_property_read_bool(np, "maxim,enable-falling-slew-rate")) in max8973_parse_dt()
538 pdata->control_flags |= in max8973_parse_dt()
541 if (of_property_read_bool(np, "maxim,enable-active-discharge")) in max8973_parse_dt()
542 pdata->control_flags |= in max8973_parse_dt()
545 if (of_property_read_bool(np, "maxim,enable-frequency-shift")) in max8973_parse_dt()
546 pdata->control_flags |= MAX8973_CONTROL_FREQ_SHIFT_9PER_ENABLE; in max8973_parse_dt()
548 if (of_property_read_bool(np, "maxim,enable-bias-control")) in max8973_parse_dt()
549 pdata->control_flags |= MAX8973_CONTROL_BIAS_ENABLE; in max8973_parse_dt()
551 etr_enable = of_property_read_bool(np, "maxim,enable-etr"); in max8973_parse_dt()
553 "maxim,enable-high-etr-sensitivity"); in max8973_parse_dt()
559 pdata->control_flags |= in max8973_parse_dt()
562 pdata->control_flags |= in max8973_parse_dt()
565 pdata->control_flags |= MAX8973_CONTROL_CLKADV_TRIP_DISABLED; in max8973_parse_dt()
568 pdata->junction_temp_warning = MAX77621_TJINT_WARNING_TEMP_140; in max8973_parse_dt()
569 ret = of_property_read_u32(np, "junction-warn-millicelsius", &pval); in max8973_parse_dt()
571 pdata->junction_temp_warning = MAX77621_TJINT_WARNING_TEMP_120; in max8973_parse_dt()
597 pdata = dev_get_platdata(&client->dev); in max8973_probe()
599 if (!pdata && client->dev.of_node) { in max8973_probe()
600 pdata = max8973_parse_dt(&client->dev); in max8973_probe()
605 dev_err(&client->dev, "No Platform data"); in max8973_probe()
606 return -EIO; in max8973_probe()
609 max = devm_kzalloc(&client->dev, sizeof(*max), GFP_KERNEL); in max8973_probe()
611 return -ENOMEM; in max8973_probe()
613 max->dvs_gpiod = devm_gpiod_get_optional(&client->dev, "maxim,dvs", in max8973_probe()
614 (pdata->dvs_def_state) ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW); in max8973_probe()
615 if (IS_ERR(max->dvs_gpiod)) in max8973_probe()
616 return dev_err_probe(&client->dev, PTR_ERR(max->dvs_gpiod), in max8973_probe()
618 gpiod_set_consumer_name(max->dvs_gpiod, "max8973-dvs"); in max8973_probe()
620 max->regmap = devm_regmap_init_i2c(client, &max8973_regmap_config); in max8973_probe()
621 if (IS_ERR(max->regmap)) { in max8973_probe()
622 ret = PTR_ERR(max->regmap); in max8973_probe()
623 dev_err(&client->dev, "regmap init failed, err %d\n", ret); in max8973_probe()
627 if (client->dev.of_node) { in max8973_probe()
631 &client->dev); in max8973_probe()
633 return -ENODATA; in max8973_probe()
634 max->id = (u32)((uintptr_t)match->data); in max8973_probe()
636 max->id = id->driver_data; in max8973_probe()
639 ret = regmap_read(max->regmap, MAX8973_CHIPID1, &chip_id); in max8973_probe()
641 dev_err(&client->dev, "register CHIPID1 read failed, %d", ret); in max8973_probe()
645 dev_info(&client->dev, "CHIP-ID OTP: 0x%02x ID_M: 0x%02x\n", in max8973_probe()
649 max->ops = max8973_dcdc_ops; in max8973_probe()
650 max->dev = &client->dev; in max8973_probe()
651 max->desc.name = id->name; in max8973_probe()
652 max->desc.id = 0; in max8973_probe()
653 max->desc.ops = &max->ops; in max8973_probe()
654 max->desc.type = REGULATOR_VOLTAGE; in max8973_probe()
655 max->desc.owner = THIS_MODULE; in max8973_probe()
656 max->desc.min_uV = MAX8973_MIN_VOLATGE; in max8973_probe()
657 max->desc.uV_step = MAX8973_VOLATGE_STEP; in max8973_probe()
658 max->desc.n_voltages = MAX8973_BUCK_N_VOLTAGE; in max8973_probe()
659 max->desc.ramp_reg = MAX8973_CONTROL1; in max8973_probe()
660 max->desc.ramp_mask = MAX8973_RAMP_MASK; in max8973_probe()
661 max->desc.ramp_delay_table = max8973_buck_ramp_table; in max8973_probe()
662 max->desc.n_ramp_values = ARRAY_SIZE(max8973_buck_ramp_table); in max8973_probe()
664 max->enable_external_control = pdata->enable_ext_control; in max8973_probe()
665 max->curr_gpio_val = pdata->dvs_def_state; in max8973_probe()
666 max->curr_vout_reg = MAX8973_VOUT + pdata->dvs_def_state; in max8973_probe()
667 max->junction_temp_warning = pdata->junction_temp_warning; in max8973_probe()
669 max->lru_index[0] = max->curr_vout_reg; in max8973_probe()
671 if (max->dvs_gpiod) { in max8973_probe()
677 * set with the max->curr_vout_reg */ in max8973_probe()
679 max->lru_index[i] = i; in max8973_probe()
680 max->lru_index[0] = max->curr_vout_reg; in max8973_probe()
681 max->lru_index[max->curr_vout_reg] = 0; in max8973_probe()
687 max->ops.set_voltage_sel = regulator_set_voltage_sel_regmap; in max8973_probe()
688 max->ops.get_voltage_sel = regulator_get_voltage_sel_regmap; in max8973_probe()
689 max->desc.vsel_reg = max->curr_vout_reg; in max8973_probe()
690 max->desc.vsel_mask = MAX8973_VOUT_MASK; in max8973_probe()
694 pdata->reg_init_data = of_get_regulator_init_data(&client->dev, in max8973_probe()
695 client->dev.of_node, &max->desc); in max8973_probe()
697 ridata = pdata->reg_init_data; in max8973_probe()
698 switch (max->id) { in max8973_probe()
700 if (!pdata->enable_ext_control) { in max8973_probe()
701 max->desc.enable_reg = MAX8973_VOUT; in max8973_probe()
702 max->desc.enable_mask = MAX8973_VOUT_ENABLE; in max8973_probe()
703 max->ops.enable = regulator_enable_regmap; in max8973_probe()
704 max->ops.disable = regulator_disable_regmap; in max8973_probe()
705 max->ops.is_enabled = regulator_is_enabled_regmap; in max8973_probe()
709 if (ridata && (ridata->constraints.always_on || in max8973_probe()
710 ridata->constraints.boot_on)) in max8973_probe()
715 gpiod = devm_gpiod_get_optional(&client->dev, in max8973_probe()
716 "maxim,enable", in max8973_probe()
722 max->enable_external_control = true; in max8973_probe()
732 gpiod = devm_gpiod_get_optional(&client->dev, in max8973_probe()
733 "maxim,enable", in max8973_probe()
738 max->enable_external_control = true; in max8973_probe()
740 max->desc.enable_reg = MAX8973_VOUT; in max8973_probe()
741 max->desc.enable_mask = MAX8973_VOUT_ENABLE; in max8973_probe()
742 max->ops.enable = regulator_enable_regmap; in max8973_probe()
743 max->ops.disable = regulator_disable_regmap; in max8973_probe()
744 max->ops.is_enabled = regulator_is_enabled_regmap; in max8973_probe()
745 max->ops.set_current_limit = max8973_set_current_limit; in max8973_probe()
746 max->ops.get_current_limit = max8973_get_current_limit; in max8973_probe()
754 dev_err(max->dev, "Max8973 Init failed, err = %d\n", ret); in max8973_probe()
758 config.dev = &client->dev; in max8973_probe()
759 config.init_data = pdata->reg_init_data; in max8973_probe()
761 config.of_node = client->dev.of_node; in max8973_probe()
762 config.regmap = max->regmap; in max8973_probe()
770 devm_gpiod_unhinge(&client->dev, config.ena_gpiod); in max8973_probe()
771 rdev = devm_regulator_register(&client->dev, &max->desc, &config); in max8973_probe()
774 dev_err(max->dev, "regulator register failed, err %d\n", ret); in max8973_probe()