Lines Matching +full:vsel +full:- +full:high

1 // SPDX-License-Identifier: GPL-2.0+
3 // wm831x-dcdc.c -- DC-DC buck converter driver for the WM831x series
63 struct wm831x *wm831x = dcdc->wm831x; in wm831x_dcdc_get_mode()
64 u16 reg = dcdc->base + WM831X_DCDC_ON_CONFIG; in wm831x_dcdc_get_mode()
84 return -EINVAL; in wm831x_dcdc_get_mode()
107 return -EINVAL; in wm831x_dcdc_set_mode_int()
117 struct wm831x *wm831x = dcdc->wm831x; in wm831x_dcdc_set_mode()
118 u16 reg = dcdc->base + WM831X_DCDC_ON_CONFIG; in wm831x_dcdc_set_mode()
127 struct wm831x *wm831x = dcdc->wm831x; in wm831x_dcdc_set_suspend_mode()
128 u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL; in wm831x_dcdc_set_suspend_mode()
136 struct wm831x *wm831x = dcdc->wm831x; in wm831x_dcdc_get_status()
145 dev_dbg(wm831x->dev, "DCDC%d under voltage\n", in wm831x_dcdc_get_status()
150 /* DCDC1 and DCDC2 can additionally detect high voltage/current */ in wm831x_dcdc_get_status()
153 dev_dbg(wm831x->dev, "DCDC%d over voltage\n", in wm831x_dcdc_get_status()
159 dev_dbg(wm831x->dev, "DCDC%d over current\n", in wm831x_dcdc_get_status()
181 regulator_notifier_call_chain(dcdc->regulator, in wm831x_dcdc_uv_irq()
192 regulator_notifier_call_chain(dcdc->regulator, in wm831x_dcdc_oc_irq()
212 if (state == dcdc->dvs_gpio_state) in wm831x_buckv_set_dvs()
215 dcdc->dvs_gpio_state = state; in wm831x_buckv_set_dvs()
216 gpiod_set_value(dcdc->dvs_gpiod, state); in wm831x_buckv_set_dvs()
227 unsigned vsel) in wm831x_buckv_set_voltage_sel() argument
230 struct wm831x *wm831x = dcdc->wm831x; in wm831x_buckv_set_voltage_sel()
231 int on_reg = dcdc->base + WM831X_DCDC_ON_CONFIG; in wm831x_buckv_set_voltage_sel()
232 int dvs_reg = dcdc->base + WM831X_DCDC_DVS_CONTROL; in wm831x_buckv_set_voltage_sel()
236 if (dcdc->dvs_gpiod && dcdc->on_vsel == vsel) in wm831x_buckv_set_voltage_sel()
239 if (dcdc->dvs_gpiod && dcdc->dvs_vsel == vsel) in wm831x_buckv_set_voltage_sel()
243 ret = wm831x_set_bits(wm831x, on_reg, WM831X_DC1_ON_VSEL_MASK, vsel); in wm831x_buckv_set_voltage_sel()
246 dcdc->on_vsel = vsel; in wm831x_buckv_set_voltage_sel()
248 if (!dcdc->dvs_gpiod) in wm831x_buckv_set_voltage_sel()
257 * If this VSEL is higher than the last one we've seen then in wm831x_buckv_set_voltage_sel()
258 * remember it as the DVS VSEL. This is optimised for CPUfreq in wm831x_buckv_set_voltage_sel()
262 if (vsel > dcdc->dvs_vsel) { in wm831x_buckv_set_voltage_sel()
265 vsel); in wm831x_buckv_set_voltage_sel()
267 dcdc->dvs_vsel = vsel; in wm831x_buckv_set_voltage_sel()
269 dev_warn(wm831x->dev, in wm831x_buckv_set_voltage_sel()
270 "Failed to set DCDC DVS VSEL: %d\n", ret); in wm831x_buckv_set_voltage_sel()
280 struct wm831x *wm831x = dcdc->wm831x; in wm831x_buckv_set_suspend_voltage()
281 u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL; in wm831x_buckv_set_suspend_voltage()
282 int vsel; in wm831x_buckv_set_suspend_voltage() local
284 vsel = regulator_map_voltage_linear_range(rdev, uV, uV); in wm831x_buckv_set_suspend_voltage()
285 if (vsel < 0) in wm831x_buckv_set_suspend_voltage()
286 return vsel; in wm831x_buckv_set_suspend_voltage()
288 return wm831x_set_bits(wm831x, reg, WM831X_DC1_SLP_VSEL_MASK, vsel); in wm831x_buckv_set_suspend_voltage()
295 if (dcdc->dvs_gpiod && dcdc->dvs_gpio_state) in wm831x_buckv_get_voltage_sel()
296 return dcdc->dvs_vsel; in wm831x_buckv_get_voltage_sel()
298 return dcdc->on_vsel; in wm831x_buckv_get_voltage_sel()
332 struct wm831x *wm831x = dcdc->wm831x; in wm831x_buckv_dvs_init()
342 dcdc->dvs_gpio_state = pdata->dvs_init_state; in wm831x_buckv_dvs_init()
344 dcdc->dvs_gpiod = devm_gpiod_get(&pdev->dev, "dvs", in wm831x_buckv_dvs_init()
345 dcdc->dvs_gpio_state ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW); in wm831x_buckv_dvs_init()
346 if (IS_ERR(dcdc->dvs_gpiod)) { in wm831x_buckv_dvs_init()
347 dev_err(wm831x->dev, "Failed to get %s DVS GPIO: %ld\n", in wm831x_buckv_dvs_init()
348 dcdc->name, PTR_ERR(dcdc->dvs_gpiod)); in wm831x_buckv_dvs_init()
352 switch (pdata->dvs_control_src) { in wm831x_buckv_dvs_init()
360 dev_err(wm831x->dev, "Invalid DVS control source %d for %s\n", in wm831x_buckv_dvs_init()
361 pdata->dvs_control_src, dcdc->name); in wm831x_buckv_dvs_init()
368 if (!dcdc->dvs_vsel) { in wm831x_buckv_dvs_init()
370 dcdc->base + WM831X_DCDC_DVS_CONTROL, in wm831x_buckv_dvs_init()
371 WM831X_DC1_DVS_VSEL_MASK, dcdc->on_vsel); in wm831x_buckv_dvs_init()
373 dcdc->dvs_vsel = dcdc->on_vsel; in wm831x_buckv_dvs_init()
375 dev_warn(wm831x->dev, "Failed to set DVS_VSEL: %d\n", in wm831x_buckv_dvs_init()
379 ret = wm831x_set_bits(wm831x, dcdc->base + WM831X_DCDC_DVS_CONTROL, in wm831x_buckv_dvs_init()
382 dev_err(wm831x->dev, "Failed to set %s DVS source: %d\n", in wm831x_buckv_dvs_init()
383 dcdc->name, ret); in wm831x_buckv_dvs_init()
389 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); in wm831x_buckv_probe()
390 struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev); in wm831x_buckv_probe()
397 if (pdata && pdata->wm831x_num) in wm831x_buckv_probe()
398 id = (pdata->wm831x_num * 10) + 1; in wm831x_buckv_probe()
401 id = pdev->id - id; in wm831x_buckv_probe()
403 dev_dbg(&pdev->dev, "Probing DCDC%d\n", id + 1); in wm831x_buckv_probe()
405 dcdc = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_dcdc), in wm831x_buckv_probe()
408 return -ENOMEM; in wm831x_buckv_probe()
410 dcdc->wm831x = wm831x; in wm831x_buckv_probe()
414 dev_err(&pdev->dev, "No REG resource\n"); in wm831x_buckv_probe()
415 ret = -EINVAL; in wm831x_buckv_probe()
418 dcdc->base = res->start; in wm831x_buckv_probe()
420 snprintf(dcdc->name, sizeof(dcdc->name), "DCDC%d", id + 1); in wm831x_buckv_probe()
421 dcdc->desc.name = dcdc->name; in wm831x_buckv_probe()
423 snprintf(dcdc->supply_name, sizeof(dcdc->supply_name), in wm831x_buckv_probe()
425 dcdc->desc.supply_name = dcdc->supply_name; in wm831x_buckv_probe()
427 dcdc->desc.id = id; in wm831x_buckv_probe()
428 dcdc->desc.type = REGULATOR_VOLTAGE; in wm831x_buckv_probe()
429 dcdc->desc.n_voltages = WM831X_BUCKV_MAX_SELECTOR + 1; in wm831x_buckv_probe()
430 dcdc->desc.linear_ranges = wm831x_buckv_ranges; in wm831x_buckv_probe()
431 dcdc->desc.n_linear_ranges = ARRAY_SIZE(wm831x_buckv_ranges); in wm831x_buckv_probe()
432 dcdc->desc.ops = &wm831x_buckv_ops; in wm831x_buckv_probe()
433 dcdc->desc.owner = THIS_MODULE; in wm831x_buckv_probe()
434 dcdc->desc.enable_reg = WM831X_DCDC_ENABLE; in wm831x_buckv_probe()
435 dcdc->desc.enable_mask = 1 << id; in wm831x_buckv_probe()
436 dcdc->desc.csel_reg = dcdc->base + WM831X_DCDC_CONTROL_2; in wm831x_buckv_probe()
437 dcdc->desc.csel_mask = WM831X_DC1_HC_THR_MASK; in wm831x_buckv_probe()
438 dcdc->desc.n_current_limits = ARRAY_SIZE(wm831x_dcdc_ilim); in wm831x_buckv_probe()
439 dcdc->desc.curr_table = wm831x_dcdc_ilim; in wm831x_buckv_probe()
441 ret = wm831x_reg_read(wm831x, dcdc->base + WM831X_DCDC_ON_CONFIG); in wm831x_buckv_probe()
443 dev_err(wm831x->dev, "Failed to read ON VSEL: %d\n", ret); in wm831x_buckv_probe()
446 dcdc->on_vsel = ret & WM831X_DC1_ON_VSEL_MASK; in wm831x_buckv_probe()
448 ret = wm831x_reg_read(wm831x, dcdc->base + WM831X_DCDC_DVS_CONTROL); in wm831x_buckv_probe()
450 dev_err(wm831x->dev, "Failed to read DVS VSEL: %d\n", ret); in wm831x_buckv_probe()
453 dcdc->dvs_vsel = ret & WM831X_DC1_DVS_VSEL_MASK; in wm831x_buckv_probe()
455 if (pdata && pdata->dcdc[id]) in wm831x_buckv_probe()
457 pdata->dcdc[id]->driver_data); in wm831x_buckv_probe()
459 config.dev = pdev->dev.parent; in wm831x_buckv_probe()
461 config.init_data = pdata->dcdc[id]; in wm831x_buckv_probe()
463 config.regmap = wm831x->regmap; in wm831x_buckv_probe()
465 dcdc->regulator = devm_regulator_register(&pdev->dev, &dcdc->desc, in wm831x_buckv_probe()
467 if (IS_ERR(dcdc->regulator)) { in wm831x_buckv_probe()
468 ret = PTR_ERR(dcdc->regulator); in wm831x_buckv_probe()
469 dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n", in wm831x_buckv_probe()
475 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, in wm831x_buckv_probe()
478 dcdc->name, dcdc); in wm831x_buckv_probe()
480 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", in wm831x_buckv_probe()
486 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, in wm831x_buckv_probe()
489 dcdc->name, dcdc); in wm831x_buckv_probe()
491 dev_err(&pdev->dev, "Failed to request HC IRQ %d: %d\n", in wm831x_buckv_probe()
507 .name = "wm831x-buckv",
519 struct wm831x *wm831x = dcdc->wm831x; in wm831x_buckp_set_suspend_voltage()
520 u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL; in wm831x_buckp_set_suspend_voltage()
548 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); in wm831x_buckp_probe()
549 struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev); in wm831x_buckp_probe()
556 if (pdata && pdata->wm831x_num) in wm831x_buckp_probe()
557 id = (pdata->wm831x_num * 10) + 1; in wm831x_buckp_probe()
560 id = pdev->id - id; in wm831x_buckp_probe()
562 dev_dbg(&pdev->dev, "Probing DCDC%d\n", id + 1); in wm831x_buckp_probe()
564 dcdc = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_dcdc), in wm831x_buckp_probe()
567 return -ENOMEM; in wm831x_buckp_probe()
569 dcdc->wm831x = wm831x; in wm831x_buckp_probe()
573 dev_err(&pdev->dev, "No REG resource\n"); in wm831x_buckp_probe()
574 ret = -EINVAL; in wm831x_buckp_probe()
577 dcdc->base = res->start; in wm831x_buckp_probe()
579 snprintf(dcdc->name, sizeof(dcdc->name), "DCDC%d", id + 1); in wm831x_buckp_probe()
580 dcdc->desc.name = dcdc->name; in wm831x_buckp_probe()
582 snprintf(dcdc->supply_name, sizeof(dcdc->supply_name), in wm831x_buckp_probe()
584 dcdc->desc.supply_name = dcdc->supply_name; in wm831x_buckp_probe()
586 dcdc->desc.id = id; in wm831x_buckp_probe()
587 dcdc->desc.type = REGULATOR_VOLTAGE; in wm831x_buckp_probe()
588 dcdc->desc.n_voltages = WM831X_BUCKP_MAX_SELECTOR + 1; in wm831x_buckp_probe()
589 dcdc->desc.ops = &wm831x_buckp_ops; in wm831x_buckp_probe()
590 dcdc->desc.owner = THIS_MODULE; in wm831x_buckp_probe()
591 dcdc->desc.vsel_reg = dcdc->base + WM831X_DCDC_ON_CONFIG; in wm831x_buckp_probe()
592 dcdc->desc.vsel_mask = WM831X_DC3_ON_VSEL_MASK; in wm831x_buckp_probe()
593 dcdc->desc.enable_reg = WM831X_DCDC_ENABLE; in wm831x_buckp_probe()
594 dcdc->desc.enable_mask = 1 << id; in wm831x_buckp_probe()
595 dcdc->desc.min_uV = 850000; in wm831x_buckp_probe()
596 dcdc->desc.uV_step = 25000; in wm831x_buckp_probe()
598 config.dev = pdev->dev.parent; in wm831x_buckp_probe()
600 config.init_data = pdata->dcdc[id]; in wm831x_buckp_probe()
602 config.regmap = wm831x->regmap; in wm831x_buckp_probe()
604 dcdc->regulator = devm_regulator_register(&pdev->dev, &dcdc->desc, in wm831x_buckp_probe()
606 if (IS_ERR(dcdc->regulator)) { in wm831x_buckp_probe()
607 ret = PTR_ERR(dcdc->regulator); in wm831x_buckp_probe()
608 dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n", in wm831x_buckp_probe()
614 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, in wm831x_buckp_probe()
617 dcdc->name, dcdc); in wm831x_buckp_probe()
619 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", in wm831x_buckp_probe()
635 .name = "wm831x-buckp",
647 struct wm831x *wm831x = dcdc->wm831x; in wm831x_boostp_get_status()
656 dev_dbg(wm831x->dev, "DCDC%d under voltage\n", in wm831x_boostp_get_status()
681 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); in wm831x_boostp_probe()
682 struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev); in wm831x_boostp_probe()
684 int id = pdev->id % ARRAY_SIZE(pdata->dcdc); in wm831x_boostp_probe()
689 dev_dbg(&pdev->dev, "Probing DCDC%d\n", id + 1); in wm831x_boostp_probe()
691 if (pdata == NULL || pdata->dcdc[id] == NULL) in wm831x_boostp_probe()
692 return -ENODEV; in wm831x_boostp_probe()
694 dcdc = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_dcdc), GFP_KERNEL); in wm831x_boostp_probe()
696 return -ENOMEM; in wm831x_boostp_probe()
698 dcdc->wm831x = wm831x; in wm831x_boostp_probe()
702 dev_err(&pdev->dev, "No REG resource\n"); in wm831x_boostp_probe()
703 return -EINVAL; in wm831x_boostp_probe()
705 dcdc->base = res->start; in wm831x_boostp_probe()
707 snprintf(dcdc->name, sizeof(dcdc->name), "DCDC%d", id + 1); in wm831x_boostp_probe()
708 dcdc->desc.name = dcdc->name; in wm831x_boostp_probe()
709 dcdc->desc.id = id; in wm831x_boostp_probe()
710 dcdc->desc.type = REGULATOR_VOLTAGE; in wm831x_boostp_probe()
711 dcdc->desc.ops = &wm831x_boostp_ops; in wm831x_boostp_probe()
712 dcdc->desc.owner = THIS_MODULE; in wm831x_boostp_probe()
713 dcdc->desc.enable_reg = WM831X_DCDC_ENABLE; in wm831x_boostp_probe()
714 dcdc->desc.enable_mask = 1 << id; in wm831x_boostp_probe()
716 config.dev = pdev->dev.parent; in wm831x_boostp_probe()
718 config.init_data = pdata->dcdc[id]; in wm831x_boostp_probe()
720 config.regmap = wm831x->regmap; in wm831x_boostp_probe()
722 dcdc->regulator = devm_regulator_register(&pdev->dev, &dcdc->desc, in wm831x_boostp_probe()
724 if (IS_ERR(dcdc->regulator)) { in wm831x_boostp_probe()
725 ret = PTR_ERR(dcdc->regulator); in wm831x_boostp_probe()
726 dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n", in wm831x_boostp_probe()
732 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, in wm831x_boostp_probe()
735 dcdc->name, in wm831x_boostp_probe()
738 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", in wm831x_boostp_probe()
751 .name = "wm831x-boostp",
774 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); in wm831x_epe_probe()
775 struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev); in wm831x_epe_probe()
777 int id = pdev->id % ARRAY_SIZE(pdata->epe); in wm831x_epe_probe()
781 dev_dbg(&pdev->dev, "Probing EPE%d\n", id + 1); in wm831x_epe_probe()
783 dcdc = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_dcdc), GFP_KERNEL); in wm831x_epe_probe()
785 return -ENOMEM; in wm831x_epe_probe()
787 dcdc->wm831x = wm831x; in wm831x_epe_probe()
792 snprintf(dcdc->name, sizeof(dcdc->name), "EPE%d", id + 1); in wm831x_epe_probe()
793 dcdc->desc.name = dcdc->name; in wm831x_epe_probe()
794 dcdc->desc.id = id + WM831X_EPE_BASE; /* Offset in DCDC registers */ in wm831x_epe_probe()
795 dcdc->desc.ops = &wm831x_epe_ops; in wm831x_epe_probe()
796 dcdc->desc.type = REGULATOR_VOLTAGE; in wm831x_epe_probe()
797 dcdc->desc.owner = THIS_MODULE; in wm831x_epe_probe()
798 dcdc->desc.enable_reg = WM831X_DCDC_ENABLE; in wm831x_epe_probe()
799 dcdc->desc.enable_mask = 1 << dcdc->desc.id; in wm831x_epe_probe()
801 config.dev = pdev->dev.parent; in wm831x_epe_probe()
803 config.init_data = pdata->epe[id]; in wm831x_epe_probe()
805 config.regmap = wm831x->regmap; in wm831x_epe_probe()
807 dcdc->regulator = devm_regulator_register(&pdev->dev, &dcdc->desc, in wm831x_epe_probe()
809 if (IS_ERR(dcdc->regulator)) { in wm831x_epe_probe()
810 ret = PTR_ERR(dcdc->regulator); in wm831x_epe_probe()
811 dev_err(wm831x->dev, "Failed to register EPE%d: %d\n", in wm831x_epe_probe()
827 .name = "wm831x-epe",
853 MODULE_DESCRIPTION("WM831x DC-DC convertor driver");
855 MODULE_ALIAS("platform:wm831x-buckv");
856 MODULE_ALIAS("platform:wm831x-buckp");
857 MODULE_ALIAS("platform:wm831x-boostp");
858 MODULE_ALIAS("platform:wm831x-epe");