Lines Matching refs:vctrl

54 static int vctrl_calc_ctrl_voltage(struct vctrl_data *vctrl, int out_uV)  in vctrl_calc_ctrl_voltage()  argument
56 struct vctrl_voltage_range *ctrl = &vctrl->vrange.ctrl; in vctrl_calc_ctrl_voltage()
57 struct vctrl_voltage_range *out = &vctrl->vrange.out; in vctrl_calc_ctrl_voltage()
65 static int vctrl_calc_output_voltage(struct vctrl_data *vctrl, int ctrl_uV) in vctrl_calc_output_voltage() argument
67 struct vctrl_voltage_range *ctrl = &vctrl->vrange.ctrl; in vctrl_calc_output_voltage()
68 struct vctrl_voltage_range *out = &vctrl->vrange.out; in vctrl_calc_output_voltage()
89 struct vctrl_data *vctrl = rdev_get_drvdata(rdev); in vctrl_get_voltage() local
90 int ctrl_uV = regulator_get_voltage(vctrl->ctrl_reg); in vctrl_get_voltage()
92 return vctrl_calc_output_voltage(vctrl, ctrl_uV); in vctrl_get_voltage()
99 struct vctrl_data *vctrl = rdev_get_drvdata(rdev); in vctrl_set_voltage() local
100 struct regulator *ctrl_reg = vctrl->ctrl_reg; in vctrl_set_voltage()
102 int uV = vctrl_calc_output_voltage(vctrl, orig_ctrl_uV); in vctrl_set_voltage()
105 if (req_min_uV >= uV || !vctrl->ovp_threshold) in vctrl_set_voltage()
109 vctrl_calc_ctrl_voltage(vctrl, req_min_uV), in vctrl_set_voltage()
110 vctrl_calc_ctrl_voltage(vctrl, req_max_uV)); in vctrl_set_voltage()
113 int max_drop_uV = (uV * vctrl->ovp_threshold) / 100; in vctrl_set_voltage()
123 next_ctrl_uV = vctrl_calc_ctrl_voltage(vctrl, next_uV); in vctrl_set_voltage()
131 delay = DIV_ROUND_UP(uV - next_uV, vctrl->min_slew_down_rate); in vctrl_set_voltage()
148 struct vctrl_data *vctrl = rdev_get_drvdata(rdev); in vctrl_get_voltage_sel() local
150 return vctrl->sel; in vctrl_get_voltage_sel()
156 struct vctrl_data *vctrl = rdev_get_drvdata(rdev); in vctrl_set_voltage_sel() local
157 struct regulator *ctrl_reg = vctrl->ctrl_reg; in vctrl_set_voltage_sel()
158 unsigned int orig_sel = vctrl->sel; in vctrl_set_voltage_sel()
164 if (selector >= vctrl->sel || !vctrl->ovp_threshold) { in vctrl_set_voltage_sel()
167 vctrl->vtable[selector].ctrl, in vctrl_set_voltage_sel()
168 vctrl->vtable[selector].ctrl); in vctrl_set_voltage_sel()
170 vctrl->sel = selector; in vctrl_set_voltage_sel()
175 while (vctrl->sel != selector) { in vctrl_set_voltage_sel()
179 if (selector >= vctrl->vtable[vctrl->sel].ovp_min_sel) in vctrl_set_voltage_sel()
182 next_sel = vctrl->vtable[vctrl->sel].ovp_min_sel; in vctrl_set_voltage_sel()
185 vctrl->vtable[next_sel].ctrl, in vctrl_set_voltage_sel()
186 vctrl->vtable[next_sel].ctrl); in vctrl_set_voltage_sel()
190 vctrl->vtable[next_sel].ctrl); in vctrl_set_voltage_sel()
193 vctrl->sel = next_sel; in vctrl_set_voltage_sel()
195 delay = DIV_ROUND_UP(vctrl->vtable[vctrl->sel].out - in vctrl_set_voltage_sel()
196 vctrl->vtable[next_sel].out, in vctrl_set_voltage_sel()
197 vctrl->min_slew_down_rate); in vctrl_set_voltage_sel()
204 if (vctrl->sel != orig_sel) { in vctrl_set_voltage_sel()
207 vctrl->vtable[orig_sel].ctrl, in vctrl_set_voltage_sel()
208 vctrl->vtable[orig_sel].ctrl)) in vctrl_set_voltage_sel()
209 vctrl->sel = orig_sel; in vctrl_set_voltage_sel()
221 struct vctrl_data *vctrl = rdev_get_drvdata(rdev); in vctrl_list_voltage() local
226 return vctrl->vtable[selector].out; in vctrl_list_voltage()
230 struct vctrl_data *vctrl) in vctrl_parse_dt() argument
237 vctrl->ctrl_reg = devm_regulator_get(&pdev->dev, "ctrl"); in vctrl_parse_dt()
238 if (IS_ERR(vctrl->ctrl_reg)) in vctrl_parse_dt()
239 return PTR_ERR(vctrl->ctrl_reg); in vctrl_parse_dt()
243 vctrl->ovp_threshold = pval; in vctrl_parse_dt()
244 if (vctrl->ovp_threshold > 100) { in vctrl_parse_dt()
247 vctrl->ovp_threshold); in vctrl_parse_dt()
254 vctrl->min_slew_down_rate = pval; in vctrl_parse_dt()
257 if (vctrl->min_slew_down_rate == 0) { in vctrl_parse_dt()
261 } else if (vctrl->min_slew_down_rate > INT_MAX) { in vctrl_parse_dt()
263 vctrl->min_slew_down_rate); in vctrl_parse_dt()
268 if (vctrl->ovp_threshold && !vctrl->min_slew_down_rate) { in vctrl_parse_dt()
280 vctrl->vrange.out.min_uV = pval; in vctrl_parse_dt()
288 vctrl->vrange.out.max_uV = pval; in vctrl_parse_dt()
304 vctrl->vrange.ctrl.min_uV = vrange_ctrl[0]; in vctrl_parse_dt()
305 vctrl->vrange.ctrl.max_uV = vrange_ctrl[1]; in vctrl_parse_dt()
320 struct vctrl_data *vctrl = platform_get_drvdata(pdev); in vctrl_init_vtable() local
321 struct regulator_desc *rdesc = &vctrl->desc; in vctrl_init_vtable()
322 struct regulator *ctrl_reg = vctrl->ctrl_reg; in vctrl_init_vtable()
323 struct vctrl_voltage_range *vrange_ctrl = &vctrl->vrange.ctrl; in vctrl_init_vtable()
348 vctrl->vtable = devm_kcalloc(&pdev->dev, rdesc->n_voltages, in vctrl_init_vtable()
351 if (!vctrl->vtable) in vctrl_init_vtable()
362 vctrl->vtable[idx_vt].ctrl = ctrl_uV; in vctrl_init_vtable()
363 vctrl->vtable[idx_vt].out = in vctrl_init_vtable()
364 vctrl_calc_output_voltage(vctrl, ctrl_uV); in vctrl_init_vtable()
369 sort(vctrl->vtable, rdesc->n_voltages, in vctrl_init_vtable()
376 int ovp_min_uV = (vctrl->vtable[i].out * in vctrl_init_vtable()
377 (100 - vctrl->ovp_threshold)) / 100; in vctrl_init_vtable()
380 if (vctrl->vtable[j].out >= ovp_min_uV) { in vctrl_init_vtable()
381 vctrl->vtable[i].ovp_min_sel = j; in vctrl_init_vtable()
388 vctrl->vtable[i].out); in vctrl_init_vtable()
390 vctrl->vtable[i].ovp_min_sel = i - 1; in vctrl_init_vtable()
399 struct vctrl_data *vctrl = rdev_get_drvdata(rdev); in vctrl_enable() local
400 int ret = regulator_enable(vctrl->ctrl_reg); in vctrl_enable()
403 vctrl->enabled = true; in vctrl_enable()
410 struct vctrl_data *vctrl = rdev_get_drvdata(rdev); in vctrl_disable() local
411 int ret = regulator_disable(vctrl->ctrl_reg); in vctrl_disable()
414 vctrl->enabled = false; in vctrl_disable()
421 struct vctrl_data *vctrl = rdev_get_drvdata(rdev); in vctrl_is_enabled() local
423 return vctrl->enabled; in vctrl_is_enabled()
447 struct vctrl_data *vctrl; in vctrl_probe() local
455 vctrl = devm_kzalloc(&pdev->dev, sizeof(struct vctrl_data), in vctrl_probe()
457 if (!vctrl) in vctrl_probe()
460 platform_set_drvdata(pdev, vctrl); in vctrl_probe()
462 ret = vctrl_parse_dt(pdev, vctrl); in vctrl_probe()
466 vrange_ctrl = &vctrl->vrange.ctrl; in vctrl_probe()
468 rdesc = &vctrl->desc; in vctrl_probe()
473 if ((regulator_get_linear_step(vctrl->ctrl_reg) == 1) || in vctrl_probe()
474 (regulator_count_voltages(vctrl->ctrl_reg) == -EINVAL)) { in vctrl_probe()
487 cfg.driver_data = vctrl; in vctrl_probe()
495 ctrl_uV = regulator_get_voltage(vctrl->ctrl_reg); in vctrl_probe()
503 vctrl->sel = 0; in vctrl_probe()
505 vctrl->sel = rdesc->n_voltages - 1; in vctrl_probe()
510 if (ctrl_uV == vctrl->vtable[i].ctrl) { in vctrl_probe()
511 vctrl->sel = i; in vctrl_probe()
518 vctrl->rdev = devm_regulator_register(&pdev->dev, rdesc, &cfg); in vctrl_probe()
519 if (IS_ERR(vctrl->rdev)) { in vctrl_probe()
520 ret = PTR_ERR(vctrl->rdev); in vctrl_probe()