static int wm831x_buckv_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV, unsigned *selector) { struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); struct wm831x *wm831x = dcdc->wm831x; int on_reg = dcdc->base + WM831X_DCDC_ON_CONFIG; int dvs_reg = dcdc->base + WM831X_DCDC_DVS_CONTROL; int vsel, ret; vsel = wm831x_buckv_select_min_voltage(rdev, min_uV, max_uV); if (vsel < 0) return vsel; *selector = vsel; /* If this value is already set then do a GPIO update if we can */ if (dcdc->dvs_gpio && dcdc->on_vsel == vsel) return wm831x_buckv_set_dvs(rdev, 0); if (dcdc->dvs_gpio && dcdc->dvs_vsel == vsel) return wm831x_buckv_set_dvs(rdev, 1); /* Always set the ON status to the minimum voltage */ ret = wm831x_set_bits(wm831x, on_reg, WM831X_DC1_ON_VSEL_MASK, vsel); if (ret < 0) return ret; dcdc->on_vsel = vsel; if (!dcdc->dvs_gpio) return ret; /* Kick the voltage transition now */ ret = wm831x_buckv_set_dvs(rdev, 0); if (ret < 0) return ret; /* Set the high voltage as the DVS voltage. This is optimised * for CPUfreq usage, most processors will keep the maximum * voltage constant and lower the minimum with the frequency. */ vsel = wm831x_buckv_select_max_voltage(rdev, min_uV, max_uV); if (vsel < 0) { /* This should never happen - at worst the same vsel * should be chosen */ WARN_ON(vsel < 0); return 0; } /* Don't bother if it's the same VSEL we're already using */ if (vsel == dcdc->on_vsel) return 0; ret = wm831x_set_bits(wm831x, dvs_reg, WM831X_DC1_DVS_VSEL_MASK, vsel); if (ret == 0) dcdc->dvs_vsel = vsel; else dev_warn(wm831x->dev, "Failed to set DCDC DVS VSEL: %d\n", ret); return 0; }
static int wm831x_buckv_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV, unsigned *selector) { struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); struct wm831x *wm831x = dcdc->wm831x; int on_reg = dcdc->base + WM831X_DCDC_ON_CONFIG; int dvs_reg = dcdc->base + WM831X_DCDC_DVS_CONTROL; int vsel, ret; vsel = wm831x_buckv_select_min_voltage(rdev, min_uV, max_uV); if (vsel < 0) return vsel; *selector = vsel; /* If this value is already set then do a GPIO update if we can */ if (dcdc->dvs_gpio && dcdc->on_vsel == vsel) return wm831x_buckv_set_dvs(rdev, 0); if (dcdc->dvs_gpio && dcdc->dvs_vsel == vsel) return wm831x_buckv_set_dvs(rdev, 1); /* Always set the ON status to the minimum voltage */ ret = wm831x_set_bits(wm831x, on_reg, WM831X_DC1_ON_VSEL_MASK, vsel); if (ret < 0) return ret; dcdc->on_vsel = vsel; if (!dcdc->dvs_gpio) return ret; /* Kick the voltage transition now */ ret = wm831x_buckv_set_dvs(rdev, 0); if (ret < 0) return ret; /* * If this VSEL is higher than the last one we've seen then * remember it as the DVS VSEL. This is optimised for CPUfreq * usage where we want to get to the highest voltage very * quickly. */ if (vsel > dcdc->dvs_vsel) { ret = wm831x_set_bits(wm831x, dvs_reg, WM831X_DC1_DVS_VSEL_MASK, dcdc->dvs_vsel); if (ret == 0) dcdc->dvs_vsel = vsel; else dev_warn(wm831x->dev, "Failed to set DCDC DVS VSEL: %d\n", ret); } return 0; }