Lines Matching +full:static +full:- +full:enable
1 // SPDX-License-Identifier: GPL-2.0
35 static int max597x_uvp_ovp_check_mode(struct regulator_dev *rdev, int severity) in max597x_uvp_ovp_check_mode()
40 ret = regmap_read(rdev->regmap, MAX5970_REG_STATUS1, ®); in max597x_uvp_ovp_check_mode()
47 return -EOPNOTSUPP; in max597x_uvp_ovp_check_mode()
52 return -EOPNOTSUPP; in max597x_uvp_ovp_check_mode()
57 static int max597x_set_vp(struct regulator_dev *rdev, int lim_uV, int severity, in max597x_set_vp()
58 bool enable, bool overvoltage) in max597x_set_vp() argument
82 if (enable) in max597x_set_vp()
83 /* reg = ADC_MASK * (lim_uV / 1000000) / (data->mon_rng / 1000000) */ in max597x_set_vp()
84 reg = ADC_MASK * lim_uV / data->mon_rng; in max597x_set_vp()
88 ret = regmap_write(rdev->regmap, off_h, MAX5970_VAL2REG_H(reg)); in max597x_set_vp()
92 ret = regmap_write(rdev->regmap, off_l, MAX5970_VAL2REG_L(reg)); in max597x_set_vp()
99 static int max597x_set_uvp(struct regulator_dev *rdev, int lim_uV, int severity, in max597x_set_uvp()
100 bool enable) in max597x_set_uvp() argument
105 * MAX5970 has enable control as a special value in limit reg. Can't in max597x_set_uvp()
106 * set limit but keep feature disabled or enable W/O given limit. in max597x_set_uvp()
108 if ((lim_uV && !enable) || (!lim_uV && enable)) in max597x_set_uvp()
109 return -EINVAL; in max597x_set_uvp()
115 return max597x_set_vp(rdev, lim_uV, severity, enable, false); in max597x_set_uvp()
118 static int max597x_set_ovp(struct regulator_dev *rdev, int lim_uV, int severity, in max597x_set_ovp()
119 bool enable) in max597x_set_ovp() argument
124 * MAX5970 has enable control as a special value in limit reg. Can't in max597x_set_ovp()
125 * set limit but keep feature disabled or enable W/O given limit. in max597x_set_ovp()
127 if ((lim_uV && !enable) || (!lim_uV && enable)) in max597x_set_ovp()
128 return -EINVAL; in max597x_set_ovp()
134 return max597x_set_vp(rdev, lim_uV, severity, enable, true); in max597x_set_ovp()
137 static int max597x_set_ocp(struct regulator_dev *rdev, int lim_uA, in max597x_set_ocp()
138 int severity, bool enable) in max597x_set_ocp() argument
146 * MAX5970 doesn't has enable control for ocp. in max597x_set_ocp()
147 * If limit is specified but enable is not set then hold the value in in max597x_set_ocp()
150 if (lim_uA != 0 && lim_uA != data->lim_uA) in max597x_set_ocp()
151 data->lim_uA = lim_uA; in max597x_set_ocp()
154 return -EINVAL; in max597x_set_ocp()
156 if (enable) { in max597x_set_ocp()
160 div_u64(mul_u32_u32(data->shunt_micro_ohms, data->lim_uA), in max597x_set_ocp()
172 if (vthfst > data->irng) { in max597x_set_ocp()
173 dev_err(&rdev->dev, "Current limit out of range\n"); in max597x_set_ocp()
174 return -EINVAL; in max597x_set_ocp()
177 val = div_u64(mul_u32_u32(0xFF, vthfst), data->irng); in max597x_set_ocp()
187 return regmap_write(rdev->regmap, reg, val); in max597x_set_ocp()
190 static int max597x_get_status(struct regulator_dev *rdev) in max597x_get_status()
194 ret = regmap_read(rdev->regmap, MAX5970_REG_STATUS3, &val); in max597x_get_status()
211 static const struct regulator_ops max597x_switch_ops = {
212 .enable = regulator_enable_regmap,
221 static int max597x_dt_parse(struct device_node *np, in max597x_dt_parse()
225 struct max597x_regulator *data = cfg->driver_data; in max597x_dt_parse()
229 of_property_read_u32(np, "shunt-resistor-micro-ohms", in max597x_dt_parse()
230 &data->shunt_micro_ohms); in max597x_dt_parse()
232 dev_err(cfg->dev, in max597x_dt_parse()
233 "property 'shunt-resistor-micro-ohms' not found, err %d\n", in max597x_dt_parse()
253 static const struct regulator_desc regulators[] = {
258 static int max597x_regmap_read_clear(struct regmap *map, unsigned int reg, in max597x_regmap_read_clear()
273 static int max597x_irq_handler(int irq, struct regulator_irq_data *rid, in max597x_irq_handler()
277 struct max597x_regulator *d = (struct max597x_regulator *)rid->data; in max597x_irq_handler()
280 ret = max597x_regmap_read_clear(d->regmap, MAX5970_REG_FAULT0, &val); in max597x_irq_handler()
285 for (i = 0; i < d->num_switches; i++) { in max597x_irq_handler()
286 stat = &rid->states[i]; in max597x_irq_handler()
287 stat->notifs = 0; in max597x_irq_handler()
288 stat->errors = 0; in max597x_irq_handler()
291 for (i = 0; i < d->num_switches; i++) { in max597x_irq_handler()
292 stat = &rid->states[i]; in max597x_irq_handler()
296 stat->notifs |= REGULATOR_EVENT_UNDER_VOLTAGE; in max597x_irq_handler()
297 stat->errors |= REGULATOR_ERROR_UNDER_VOLTAGE; in max597x_irq_handler()
300 stat->notifs |= REGULATOR_EVENT_UNDER_VOLTAGE_WARN; in max597x_irq_handler()
301 stat->errors |= REGULATOR_ERROR_UNDER_VOLTAGE_WARN; in max597x_irq_handler()
305 ret = max597x_regmap_read_clear(d->regmap, MAX5970_REG_FAULT1, &val); in max597x_irq_handler()
309 for (i = 0; i < d->num_switches; i++) { in max597x_irq_handler()
310 stat = &rid->states[i]; in max597x_irq_handler()
314 stat->notifs |= REGULATOR_EVENT_REGULATION_OUT; in max597x_irq_handler()
315 stat->errors |= REGULATOR_ERROR_REGULATION_OUT; in max597x_irq_handler()
318 stat->notifs |= REGULATOR_EVENT_OVER_VOLTAGE_WARN; in max597x_irq_handler()
319 stat->errors |= REGULATOR_ERROR_OVER_VOLTAGE_WARN; in max597x_irq_handler()
323 ret = max597x_regmap_read_clear(d->regmap, MAX5970_REG_FAULT2, &val); in max597x_irq_handler()
327 for (i = 0; i < d->num_switches; i++) { in max597x_irq_handler()
328 stat = &rid->states[i]; in max597x_irq_handler()
332 stat->notifs |= REGULATOR_EVENT_OVER_CURRENT_WARN; in max597x_irq_handler()
333 stat->errors |= REGULATOR_ERROR_OVER_CURRENT_WARN; in max597x_irq_handler()
337 ret = regmap_read(d->regmap, MAX5970_REG_STATUS0, &val); in max597x_irq_handler()
341 for (i = 0; i < d->num_switches; i++) { in max597x_irq_handler()
342 stat = &rid->states[i]; in max597x_irq_handler()
347 stat->notifs |= in max597x_irq_handler()
350 stat->errors |= in max597x_irq_handler()
353 /* Clear the sub-IRQ status */ in max597x_irq_handler()
354 regulator_disable_regmap(stat->rdev); in max597x_irq_handler()
360 static const struct regmap_config max597x_regmap_config = {
366 static int max597x_adc_range(struct regmap *regmap, const int ch, in max597x_adc_range()
387 return -EINVAL; in max597x_adc_range()
400 static int max597x_setup_irq(struct device *dev, in max597x_setup_irq()
406 .name = "max597x-irq", in max597x_setup_irq()
418 /* Register notifiers - can fail if IRQ is not given */ in max597x_setup_irq()
423 if (PTR_ERR(irq_helper) == -EPROBE_DEFER) in max597x_setup_irq()
424 return -EPROBE_DEFER; in max597x_setup_irq()
432 static int max597x_regulator_probe(struct platform_device *pdev) in max597x_regulator_probe()
436 struct max597x_data *max597x = dev_get_drvdata(pdev->dev.parent); in max597x_regulator_probe()
442 int num_switches = max597x->num_switches; in max597x_regulator_probe()
447 devm_kzalloc(max597x->dev, sizeof(struct max597x_regulator), in max597x_regulator_probe()
450 return -ENOMEM; in max597x_regulator_probe()
452 data->num_switches = num_switches; in max597x_regulator_probe()
453 data->regmap = max597x->regmap; in max597x_regulator_probe()
455 ret = max597x_adc_range(data->regmap, i, &max597x->irng[i], &max597x->mon_rng[i]); in max597x_regulator_probe()
459 data->irng = max597x->irng[i]; in max597x_regulator_probe()
460 data->mon_rng = max597x->mon_rng[i]; in max597x_regulator_probe()
462 config.dev = max597x->dev; in max597x_regulator_probe()
464 config.regmap = data->regmap; in max597x_regulator_probe()
465 rdev = devm_regulator_register(max597x->dev, in max597x_regulator_probe()
468 dev_err(max597x->dev, "failed to register regulator %s\n", in max597x_regulator_probe()
473 max597x->shunt_micro_ohms[i] = data->shunt_micro_ohms; in max597x_regulator_probe()
476 if (max597x->irq) { in max597x_regulator_probe()
478 max597x_setup_irq(max597x->dev, max597x->irq, rdevs, num_switches, in max597x_regulator_probe()
481 dev_err(max597x->dev, "IRQ setup failed"); in max597x_regulator_probe()
489 static struct platform_driver max597x_regulator_driver = {
491 .name = "max597x-regulator",
500 MODULE_DESCRIPTION("MAX5970_hot-swap controller driver");