Lines Matching +full:pwm +full:- +full:regulator
1 // SPDX-License-Identifier: GPL-2.0+
5 * Based on kernel drivers/regulator/pwm-regulator.c
6 * Copyright (C) 2014 - STMicroelectronics Inc.
13 #include <pwm.h>
14 #include <power/regulator.h>
19 /* pwm id corresponding to the PWM driver */
21 /* the period of one PWM cycle */
24 * the polarity of one PWM
29 struct udevice *pwm; member
30 /* initialize voltage of regulator */
32 /* the maximum voltage of regulator */
34 /* the minimum voltage of regulator */
36 /* the current voltage of regulator */
44 return pwm_set_enable(priv->pwm, priv->pwm_id, enable); in pwm_regulator_enable()
50 int min_uV = priv->min_voltage; in pwm_voltage_to_duty_cycle_percentage()
51 int max_uV = priv->max_voltage; in pwm_voltage_to_duty_cycle_percentage()
52 int diff = max_uV - min_uV; in pwm_voltage_to_duty_cycle_percentage()
54 return ((req_uV * 100) - (min_uV * 100)) / diff; in pwm_voltage_to_duty_cycle_percentage()
61 return priv->volt_uV; in pwm_regulator_get_voltage()
72 ret = pwm_set_invert(priv->pwm, priv->pwm_id, priv->polarity); in pwm_regulator_set_voltage()
74 dev_err(dev, "Failed to init PWM\n"); in pwm_regulator_set_voltage()
78 ret = pwm_set_config(priv->pwm, priv->pwm_id, in pwm_regulator_set_voltage()
79 priv->period_ns, (priv->period_ns / 100) * duty_cycle); in pwm_regulator_set_voltage()
81 dev_err(dev, "Failed to configure PWM\n"); in pwm_regulator_set_voltage()
85 priv->volt_uV = uvolt; in pwm_regulator_set_voltage()
96 ret = dev_read_phandle_with_args(dev, "pwms", "#pwm-cells", 0, 0, &args); in pwm_regulator_ofdata_to_platdata()
98 debug("%s: Cannot get PWM phandle: ret=%d\n", __func__, ret); in pwm_regulator_ofdata_to_platdata()
102 priv->period_ns = args.args[1]; in pwm_regulator_ofdata_to_platdata()
103 priv->polarity = args.args[2]; in pwm_regulator_ofdata_to_platdata()
105 priv->init_voltage = dev_read_u32_default(dev, "regulator-init-microvolt", -1); in pwm_regulator_ofdata_to_platdata()
106 if (priv->init_voltage < 0) { in pwm_regulator_ofdata_to_platdata()
107 printf("Cannot find regulator pwm init_voltage\n"); in pwm_regulator_ofdata_to_platdata()
108 return -EINVAL; in pwm_regulator_ofdata_to_platdata()
111 ret = uclass_get_device_by_ofnode(UCLASS_PWM, args.node, &priv->pwm); in pwm_regulator_ofdata_to_platdata()
113 debug("%s: Cannot get PWM: ret=%d\n", __func__, ret); in pwm_regulator_ofdata_to_platdata()
127 uc_pdata->type = REGULATOR_TYPE_BUCK; in pwm_regulator_probe()
128 uc_pdata->mode_count = 0; in pwm_regulator_probe()
129 priv->max_voltage = uc_pdata->max_uV; in pwm_regulator_probe()
130 priv->min_voltage = uc_pdata->min_uV; in pwm_regulator_probe()
132 if (priv->init_voltage) in pwm_regulator_probe()
133 pwm_regulator_set_voltage(dev, priv->init_voltage); in pwm_regulator_probe()
145 { .compatible = "pwm-regulator" },