Lines Matching +full:oc +full:- +full:level +full:- +full:select

1 // SPDX-License-Identifier: GPL-2.0-only
3 // DA9121 Single-channel dual-phase 10A buck converter
7 // DA9130 Single-channel dual-phase 10A buck converter (Automotive)
8 // DA9217 Single-channel dual-phase 6A buck converter
9 // DA9122 Dual-channel single-phase 5A buck converter
10 // DA9131 Dual-channel single-phase 5A buck converter (Automotive)
11 // DA9220 Dual-channel single-phase 3A buck converter
12 // DA9132 Dual-channel single-phase 3A buck converter (Automotive)
29 #include "da9121-regulator.h"
135 int buck_id; /* 0=core, 1/2-buck */
141 char *warn; /* if NULL, notify - otherwise dev_warn this string */
164 * re-occur. When this driver starts, it is expected that these will have
165 * self-cleared for when the IRQs are enabled, so these should never be seen.
192 variant_parameters[chip->variant_id].current_range; in da9121_get_current_limit()
196 ret = regmap_read(chip->regmap, da9121_current_field[id].reg, &val); in da9121_get_current_limit()
198 dev_err(chip->dev, "Cannot read BUCK register: %d\n", ret); in da9121_get_current_limit()
202 if (val < range->reg_min) { in da9121_get_current_limit()
203 ret = -EACCES; in da9121_get_current_limit()
207 if (val > range->reg_max) { in da9121_get_current_limit()
208 ret = -EINVAL; in da9121_get_current_limit()
212 return range->val_min + (range->val_stp * (val - range->reg_min)); in da9121_get_current_limit()
223 variant_parameters[chip->variant_id].current_range; in da9121_ceiling_selector()
224 unsigned int level; in da9121_ceiling_selector() local
229 if (range->val_min > max || range->val_max < min) { in da9121_ceiling_selector()
230 dev_err(chip->dev, in da9121_ceiling_selector()
232 ret = -EINVAL; in da9121_ceiling_selector()
236 level = range->val_max; in da9121_ceiling_selector()
237 for (i = range->reg_max; i >= range->reg_min; i--) { in da9121_ceiling_selector()
238 if (level <= max) { in da9121_ceiling_selector()
242 level -= range->val_stp; in da9121_ceiling_selector()
245 if (level < min) { in da9121_ceiling_selector()
246 dev_err(chip->dev, in da9121_ceiling_selector()
248 ret = -EINVAL; in da9121_ceiling_selector()
263 variant_parameters[chip->variant_id].current_range; in da9121_set_current_limit()
267 if (min_ua < range->val_min || in da9121_set_current_limit()
268 max_ua > range->val_max) { in da9121_set_current_limit()
269 ret = -EINVAL; in da9121_set_current_limit()
273 if (rdev->desc->ops->is_enabled(rdev)) { in da9121_set_current_limit()
274 ret = -EBUSY; in da9121_set_current_limit()
282 ret = regmap_update_bits(chip->regmap, in da9121_set_current_limit()
287 dev_err(chip->dev, "Cannot update BUCK current limit, err: %d\n", ret); in da9121_set_current_limit()
329 return -EINVAL; in da9121_buck_set_mode()
332 return regmap_update_bits(chip->regmap, in da9121_buck_set_mode()
345 ret = regmap_read(chip->regmap, da9121_mode_field[id].reg, &val); in da9121_buck_get_mode()
347 dev_err(chip->dev, "Cannot read BUCK register: %d\n", ret); in da9121_buck_get_mode()
348 return -EINVAL; in da9121_buck_get_mode()
353 return -EINVAL; in da9121_buck_get_mode()
380 struct da9121 *chip = config->driver_data; in da9121_of_parse_cb()
384 if (chip->pdata == NULL) { in da9121_of_parse_cb()
385 pdata = devm_kzalloc(chip->dev, sizeof(*pdata), GFP_KERNEL); in da9121_of_parse_cb()
387 return -ENOMEM; in da9121_of_parse_cb()
389 pdata = chip->pdata; in da9121_of_parse_cb()
392 pdata->num_buck++; in da9121_of_parse_cb()
394 if (pdata->num_buck > variant_parameters[chip->variant_id].num_bucks) { in da9121_of_parse_cb()
395 dev_err(chip->dev, "Error: excessive regulators for device\n"); in da9121_of_parse_cb()
396 return -ENODEV; in da9121_of_parse_cb()
402 "da9121-enable"); in da9121_of_parse_cb()
404 config->ena_gpiod = ena_gpiod; in da9121_of_parse_cb()
406 if (variant_parameters[chip->variant_id].num_bucks == 2) { in da9121_of_parse_cb()
411 if (of_property_read_u32(da9121_matches[pdata->num_buck-1].of_node, in da9121_of_parse_cb()
412 "dlg,ripple-cancel", &ripple_cancel)) { in da9121_of_parse_cb()
413 if (pdata->num_buck > 1) in da9121_of_parse_cb()
418 ret = regmap_update_bits(chip->regmap, ripple_reg, in da9121_of_parse_cb()
422 dev_err(chip->dev, "Cannot set ripple mode, err: %d\n", ret); in da9121_of_parse_cb()
433 #define DA9121_N_VOLTAGES (((DA9121_MAX_MV - DA9121_MIN_MV) / DA9121_STEP_MV) \
566 #define DA914X_N_VOLTAGES (((DA914X_MAX_MV - DA914X_MIN_MV) / DA914X_STEP_MV) \
628 ret = regmap_bulk_read(chip->regmap, DA9121_REG_SYS_STATUS_0, status, 2); in da9121_status_poll_on()
630 dev_err(chip->dev, in da9121_status_poll_on()
637 * and the respective state cleared - then flagged to unmask for next IRQ. in da9121_status_poll_on()
641 int reg_idx = item->reg_index; in da9121_status_poll_on()
642 bool relevant = (item->buck_id <= variant_parameters[chip->variant_id].num_bucks); in da9121_status_poll_on()
643 bool supported = (item->warn == NULL); in da9121_status_poll_on()
644 bool persisting = (chip->persistent[reg_idx] & item->event_bit); in da9121_status_poll_on()
645 bool now_cleared = !(status[reg_idx] & item->status_bit); in da9121_status_poll_on()
648 clear[reg_idx] |= item->mask_bit; in da9121_status_poll_on()
649 chip->persistent[reg_idx] &= ~item->event_bit; in da9121_status_poll_on()
658 ret = regmap_update_bits(chip->regmap, reg, mbit, 0); in da9121_status_poll_on()
660 dev_err(chip->dev, in da9121_status_poll_on()
668 if (chip->persistent[0] | chip->persistent[1]) { in da9121_status_poll_on()
669 delay = msecs_to_jiffies(chip->passive_delay); in da9121_status_poll_on()
670 queue_delayed_work(system_freezable_wq, &chip->work, delay); in da9121_status_poll_on()
688 err = regmap_bulk_read(chip->regmap, DA9121_REG_SYS_EVENT_0, event, 3); in da9121_irq_handler()
690 dev_err(chip->dev, "Failed to read EVENT registers %d\n", err); in da9121_irq_handler()
695 err = regmap_bulk_read(chip->regmap, DA9121_REG_SYS_MASK_0, mask, 3); in da9121_irq_handler()
697 dev_err(chip->dev, in da9121_irq_handler()
703 rdev = chip->rdev[DA9121_IDX_BUCK1]; in da9121_irq_handler()
707 * or a warning given for unexpected events - those from device POR, and in da9121_irq_handler()
712 int reg_idx = item->reg_index; in da9121_irq_handler()
713 bool relevant = (item->buck_id <= variant_parameters[chip->variant_id].num_bucks); in da9121_irq_handler()
714 bool enabled = !(mask[reg_idx] & item->mask_bit); in da9121_irq_handler()
715 bool active = (event[reg_idx] & item->event_bit); in da9121_irq_handler()
716 bool notify = (item->warn == NULL); in da9121_irq_handler()
720 chip->persistent[reg_idx] |= item->event_bit; in da9121_irq_handler()
721 regulator_notifier_call_chain(rdev, item->notification, NULL); in da9121_irq_handler()
723 dev_warn(chip->dev, item->warn); in da9121_irq_handler()
724 handled[reg_idx] |= item->event_bit; in da9121_irq_handler()
732 dev_warn(chip->dev, in da9121_irq_handler()
738 /* Mask the interrupts for persistent events OV, OC, UV, WARN, CRIT */ in da9121_irq_handler()
744 err = regmap_update_bits(chip->regmap, reg, mbit, mbit); in da9121_irq_handler()
746 dev_err(chip->dev, in da9121_irq_handler()
757 err = regmap_bulk_write(chip->regmap, DA9121_REG_SYS_EVENT_0, handled, 3); in da9121_irq_handler()
759 dev_err(chip->dev, "Fail to write EVENTs %d\n", err); in da9121_irq_handler()
765 queue_delayed_work(system_freezable_wq, &chip->work, 0); in da9121_irq_handler()
773 unsigned int max_matches = variant_parameters[chip->variant_id].num_bucks; in da9121_set_regulator_config()
779 local_da9121_regulators[chip->variant_id][i]; in da9121_set_regulator_config()
781 config.dev = chip->dev; in da9121_set_regulator_config()
783 config.regmap = chip->regmap; in da9121_set_regulator_config()
785 chip->rdev[i] = devm_regulator_register(chip->dev, in da9121_set_regulator_config()
787 if (IS_ERR(chip->rdev[i])) { in da9121_set_regulator_config()
788 dev_err(chip->dev, "Failed to register regulator %s, %d/%d\n", in da9121_set_regulator_config()
789 regl_desc->name, (i+1), max_matches); in da9121_set_regulator_config()
790 ret = PTR_ERR(chip->rdev[i]); in da9121_set_regulator_config()
898 ret = regmap_read(chip->regmap, DA9121_REG_OTP_DEVICE_ID, &device_id); in da9121_check_device_type()
900 dev_err(chip->dev, "Cannot read device ID: %d\n", ret); in da9121_check_device_type()
904 ret = regmap_read(chip->regmap, DA9121_REG_OTP_VARIANT_ID, &variant_id); in da9121_check_device_type()
906 dev_err(chip->dev, "Cannot read variant ID: %d\n", ret); in da9121_check_device_type()
911 dev_err(chip->dev, "Invalid device ID: 0x%02x\n", device_id); in da9121_check_device_type()
912 ret = -ENODEV; in da9121_check_device_type()
918 switch (chip->subvariant_id) { in da9121_check_device_type()
953 switch (chip->subvariant_id) { in da9121_check_device_type()
968 dev_info(chip->dev, in da9121_check_device_type()
969 "Device detected (device-ID: 0x%02X, var-ID: 0x%02X, %s)\n", in da9121_check_device_type()
973 dev_err(chip->dev, "Device tree configuration does not match detected device.\n"); in da9121_check_device_type()
974 ret = -EINVAL; in da9121_check_device_type()
985 dev_err(chip->dev, in da9121_check_device_type()
987 ret = -EINVAL; in da9121_check_device_type()
999 chip->dev = &i2c->dev; in da9121_assign_chip_model()
1001 /* Use configured subtype to select the regulator descriptor index and in da9121_assign_chip_model()
1004 switch (chip->subvariant_id) { in da9121_assign_chip_model()
1007 chip->variant_id = DA9121_TYPE_DA9121_DA9130; in da9121_assign_chip_model()
1011 chip->variant_id = DA9121_TYPE_DA9217; in da9121_assign_chip_model()
1016 chip->variant_id = DA9121_TYPE_DA9122_DA9131; in da9121_assign_chip_model()
1021 chip->variant_id = DA9121_TYPE_DA9220_DA9132; in da9121_assign_chip_model()
1025 chip->variant_id = DA9121_TYPE_DA9141; in da9121_assign_chip_model()
1029 chip->variant_id = DA9121_TYPE_DA9142; in da9121_assign_chip_model()
1033 return -EINVAL; in da9121_assign_chip_model()
1037 da9121_matches[0].desc = local_da9121_regulators[chip->variant_id][0]; in da9121_assign_chip_model()
1038 da9121_matches[1].desc = local_da9121_regulators[chip->variant_id][1]; in da9121_assign_chip_model()
1040 chip->regmap = devm_regmap_init_i2c(i2c, regmap); in da9121_assign_chip_model()
1041 if (IS_ERR(chip->regmap)) { in da9121_assign_chip_model()
1042 ret = PTR_ERR(chip->regmap); in da9121_assign_chip_model()
1043 dev_err(chip->dev, "Failed to configure a register map: %d\n", in da9121_assign_chip_model()
1060 chip->chip_irq = i2c->irq; in da9121_config_irq()
1062 if (chip->chip_irq != 0) { in da9121_config_irq()
1063 if (!of_property_read_u32(chip->dev->of_node, in da9121_config_irq()
1064 "dlg,irq-polling-delay-passive-ms", in da9121_config_irq()
1068 dev_warn(chip->dev, in da9121_config_irq()
1069 "Out-of-range polling period %d ms\n", in da9121_config_irq()
1075 chip->passive_delay = p_delay; in da9121_config_irq()
1077 ret = request_threaded_irq(chip->chip_irq, NULL, in da9121_config_irq()
1082 dev_err(chip->dev, "Failed IRQ request: %d\n", in da9121_config_irq()
1083 chip->chip_irq); in da9121_config_irq()
1087 ret = regmap_bulk_write(chip->regmap, DA9121_REG_SYS_MASK_0, mask_all, 4); in da9121_config_irq()
1089 dev_err(chip->dev, "Failed to set IRQ masks: %d\n", in da9121_config_irq()
1094 INIT_DELAYED_WORK(&chip->work, da9121_status_poll_on); in da9121_config_irq()
1095 dev_info(chip->dev, "Interrupt polling period set at %d ms\n", in da9121_config_irq()
1096 chip->passive_delay); in da9121_config_irq()
1101 free_irq(chip->chip_irq, chip); in da9121_config_irq()
1125 chip = devm_kzalloc(&i2c->dev, sizeof(struct da9121), GFP_KERNEL); in da9121_i2c_probe()
1127 ret = -ENOMEM; in da9121_i2c_probe()
1131 chip->pdata = i2c->dev.platform_data; in da9121_i2c_probe()
1132 chip->subvariant_id = (enum da9121_subvariant)i2c_get_match_data(i2c); in da9121_i2c_probe()
1138 ret = regmap_bulk_write(chip->regmap, DA9121_REG_SYS_MASK_0, mask_all, 4); in da9121_i2c_probe()
1140 dev_err(chip->dev, "Failed to set IRQ masks: %d\n", ret); in da9121_i2c_probe()
1160 free_irq(chip->chip_irq, chip); in da9121_i2c_remove()
1161 cancel_delayed_work_sync(&chip->work); in da9121_i2c_remove()
1163 ret = regmap_bulk_write(chip->regmap, DA9121_REG_SYS_MASK_0, mask_all, 4); in da9121_i2c_remove()
1165 dev_err(chip->dev, "Failed to set IRQ masks: %d\n", ret); in da9121_i2c_remove()