switch (type) { case hwmon_curr: switch (attr) { case hwmon_curr_input:
ret = max5970_read_adc(regmap, MAX5970_REG_CURRENT_H(channel), val); if (ret < 0) return ret; /* * Calculate current from ADC value, IRNG range & shunt resistor value. * ddata->irng holds the voltage corresponding to the maximum value the * 10-bit ADC can measure. * To obtain the output, multiply the ADC value by the IRNG range (in * millivolts) and then divide it by the maximum value of the 10-bit ADC.
*/
*val = (*val * ddata->irng) >> 10; /* Convert the voltage measurement across shunt resistor to current */
*val = (*val * 1000) / ddata->shunt_micro_ohms; return 0; default: return -EOPNOTSUPP;
}
case hwmon_in: switch (attr) { case hwmon_in_input:
ret = max5970_read_adc(regmap, MAX5970_REG_VOLTAGE_H(channel), val); if (ret < 0) return ret; /* * Calculate voltage from ADC value and MON range. * ddata->mon_rng holds the voltage corresponding to the maximum value the * 10-bit ADC can measure. * To obtain the output, multiply the ADC value by the MON range (in * microvolts) and then divide it by the maximum value of the 10-bit ADC.
*/
*val = mul_u64_u32_shr(*val, ddata->mon_rng, 10); /* uV to mV */
*val = *val / 1000; return 0; default: return -EOPNOTSUPP;
} default: return -EOPNOTSUPP;
}
}
ret = regmap_write(rdev->regmap, off_h, MAX5970_VAL2REG_H(reg)); if (ret) return ret;
ret = regmap_write(rdev->regmap, off_l, MAX5970_VAL2REG_L(reg)); if (ret) return ret;
return 0;
}
staticint max597x_set_uvp(struct regulator_dev *rdev, int lim_uV, int severity, bool enable)
{ int ret;
/* * MAX5970 has enable control as a special value in limit reg. Can't * set limit but keep feature disabled or enable W/O given limit.
*/ if ((lim_uV && !enable) || (!lim_uV && enable)) return -EINVAL;
ret = max597x_uvp_ovp_check_mode(rdev, severity); if (ret) return ret;
staticint max597x_set_ovp(struct regulator_dev *rdev, int lim_uV, int severity, bool enable)
{ int ret;
/* * MAX5970 has enable control as a special value in limit reg. Can't * set limit but keep feature disabled or enable W/O given limit.
*/ if ((lim_uV && !enable) || (!lim_uV && enable)) return -EINVAL;
ret = max597x_uvp_ovp_check_mode(rdev, severity); if (ret) return ret;
staticint max597x_set_ocp(struct regulator_dev *rdev, int lim_uA, int severity, bool enable)
{ int val, reg; unsignedint vthst, vthfst;
struct max5970_regulator *data = rdev_get_drvdata(rdev); int rdev_id = rdev_get_id(rdev); /* * MAX5970 doesn't has enable control for ocp. * If limit is specified but enable is not set then hold the value in * variable & later use it when ocp needs to be enabled.
*/ if (lim_uA != 0 && lim_uA != data->lim_uA)
data->lim_uA = lim_uA;
if (severity != REGULATOR_SEVERITY_PROT) return -EINVAL;
/* * As recommended in datasheed, add 20% margin to avoid * spurious event & passive component tolerance.
*/
vthst = div_u64(mul_u32_u32(vthst, 120), 100);
/* Calc fast Vtrip threshold in uV */
vthfst = vthst * (MAX5970_FAST2SLOW_RATIO / 100);
if (vthfst > data->irng) {
dev_err(&rdev->dev, "Current limit out of range\n"); return -EINVAL;
} /* Fast trip threshold to be programmed */
val = div_u64(mul_u32_u32(0xFF, vthfst), data->irng);
} else /* * Since there is no option to disable ocp, set limit to max * value
*/
val = 0xFF;
reg = MAX5970_REG_DAC_FAST(rdev_id);
return regmap_write(rdev->regmap, reg, val);
}
staticint max597x_get_status(struct regulator_dev *rdev)
{ int val, ret;
ret = regmap_read(rdev->regmap, MAX5970_REG_STATUS3, &val); if (ret) return ret;
if (val & MAX5970_STATUS3_ALERT) return REGULATOR_STATUS_ERROR;
ret = regulator_is_enabled_regmap(rdev); if (ret < 0) return ret;
/* Register notifiers - can fail if IRQ is not given */
irq_helper = devm_regulator_irq_helper(dev, &max597x_notif,
irq, 0, errs, NULL,
&rdevs[0], num_switches); if (IS_ERR(irq_helper)) { if (PTR_ERR(irq_helper) == -EPROBE_DEFER) return -EPROBE_DEFER;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.