Re: [RFC PATCH 2/8] regulator: Add Dialog DA906x voltage regulators support.

From
Krystian Garbaciak <hidden>
Date
2012-08-29 14:49:27
Also in
linux-watchdog, lkml
Reply to
Mark Brown, 2012-08-25
quoted
+static int da906x_set_voltage(struct regulator_dev *rdev,
+				int min_uV, int max_uV, unsigned *selector)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	const struct field *fvol = &regl->info->voltage;
+	int ret;
+	unsigned val;
+
+	val = regulator_map_voltage_linear(rdev, min_uV, max_uV);
+	if (val < 0)
+		return -EINVAL;
+
+	val = (val + fvol->offset) << fvol->shift;
+	ret = da906x_reg_update(regl->hw, fvol->addr, fvol->mask, val);
+	if (ret >= 0)
+		*selector = val;
+
+	return ret;
+}
This is just set_voltage_sel_regmap().
Because, for some regulators, this is required: val += fvol->offset,
I was only able to reduce it to the following form.

+static int da9063_set_voltage(struct regulator_dev *rdev,
+			      int min_uV, int max_uV, unsigned *selector)
+{
+	struct da9063_regulator *regl = rdev_get_drvdata(rdev);
+	const struct field *fvol = &regl->info->voltage;
+	int ret;
+	unsigned val;
+
+	val = regulator_map_voltage_linear(rdev, min_uV, max_uV);
+	if (val < 0)
+		return -EINVAL;
+
+	val += fvol->offset;
+
+	ret = regulator_set_voltage_sel_regmap(rdev, val);
+	if (ret >= 0)
+		*selector = val;
+
+	return ret;
+}
quoted
+static int da906x_enable(struct regulator_dev *rdev)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	int ret;
+
+	if (regl->info->suspend.mask) {
+		/* Make sure to exit from suspend mode on enable */
+		ret = da906x_reg_clear_bits(regl->hw, regl->info->suspend.addr,
+					    regl->info->suspend.mask);
+		if (ret < 0)
+			return ret;
+
+		/* BUCKs need mode update after wake-up from suspend state. */
+		ret = da906x_update_mode_internal(regl, SYS_STATE_NORMAL);
+		if (ret < 0)
+			return ret;
+	}
+
+	return regulator_enable_regmap(rdev);
If suspend_mask is optional the regulators using it should just use the
standard operation.
I guess, you meant here to call regulator_enable_regmap() directly for
regulators NOT using suspend.mask. Then, I will do it.
quoted
+/* Regulator event handlers */
+irqreturn_t da906x_ldo_lim_event(int irq, void *data)
By "event handler" you mean "interrupt"
Yes. I think, I will update the comment line.
quoted
+	bits = da906x_reg_read(hw, DA906X_REG_STATUS_D);
+	if (bits < 0)
+		return IRQ_HANDLED;
If you fail to detect an interrupt you report that you handled one...?
For me there is no sensible return value for this case.
However, I consider changing the reaction on read failure by reporting event
for all regulators, that might cause this interrupt:
+	bits = da9063_reg_read(hw, DA9063_REG_STATUS_D);
+	if (bits < 0)
+		bits = ~0;

I will update the driver according to your remaining comments.

Thank you for your comments,
Krystian
Thread (19 messages) 19 messages, 4 authors, last reply 2012-08-31
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help