From: Elaine Zhang <zhangqing@rock-chips.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] power: regulator: pwm: support pwm polarity setting
Date: Mon, 10 Apr 2017 09:50:28 +0800 [thread overview]
Message-ID: <58EAE4E4.9040204@rock-chips.com> (raw)
In-Reply-To: <20e5c0d8-79aa-50eb-1bba-6f6f1b612bcf@samsung.com>
On 04/07/2017 07:28 PM, Jaehoon Chung wrote:
> Hi Kever,
>
> On 04/07/2017 08:02 PM, Kever Yang wrote:
>> The latest kernel PWM drivers enable the polarity settings. When system
>> run from U-Boot to kerenl, if there are differences in polarity set or
>> duty cycle, the PMW will re-init:
>> close -> set polarity and duty cycle -> enable the PWM.
>> The power supply controled by pwm regulator may have voltage shaking,
>> which lead to the system not stable.
>>
>> Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
>> ---
>>
>> drivers/power/regulator/pwm_regulator.c | 12 ++++++++++--
>> drivers/pwm/pwm-uclass.c | 10 ++++++++++
>> drivers/pwm/rk_pwm.c | 17 ++++++++++++++++-
>> include/pwm.h | 9 +++++++++
>> 4 files changed, 45 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/power/regulator/pwm_regulator.c b/drivers/power/regulator/pwm_regulator.c
>> index 4875238..f8a6712 100644
>> --- a/drivers/power/regulator/pwm_regulator.c
>> +++ b/drivers/power/regulator/pwm_regulator.c
>> @@ -24,6 +24,8 @@ struct pwm_regulator_info {
>> int pwm_id;
>> /* the period of one PWM cycle */
>> int period_ns;
>> + /* the polarity of one PWM */
>> + int polarity;
>> struct udevice *pwm;
>> /* initialize voltage of regulator */
>> unsigned int init_voltage;
>> @@ -49,7 +51,7 @@ static int pwm_voltage_to_duty_cycle_percentage(struct udevice *dev, int req_uV)
>> int max_uV = priv->max_voltage;
>> int diff = max_uV - min_uV;
>>
>> - return 100 - (((req_uV * 100) - (min_uV * 100)) / diff);
>> + return ((req_uV * 100) - (min_uV * 100)) / diff;
>> }
>>
>> static int pwm_regulator_get_voltage(struct udevice *dev)
>> @@ -67,6 +69,12 @@ static int pwm_regulator_set_voltage(struct udevice *dev, int uvolt)
>>
>> duty_cycle = pwm_voltage_to_duty_cycle_percentage(dev, uvolt);
>>
>> + ret = pwm_set_init(priv->pwm, priv->pwm_id, priv->polarity);
>> + if (ret) {
>> + dev_err(dev, "Failed to init PWM\n");
>> + return ret;
>> + }
>> +
>> ret = pwm_set_config(priv->pwm, priv->pwm_id,
>> (priv->period_ns / 100) * duty_cycle, priv->period_ns);
>> if (ret) {
>> @@ -97,9 +105,9 @@ static int pwm_regulator_ofdata_to_platdata(struct udevice *dev)
>> debug("%s: Cannot get PWM phandle: ret=%d\n", __func__, ret);
>> return ret;
>> }
>> - /* TODO: pwm_id here from device tree if needed */
>>
>> priv->period_ns = args.args[1];
>> + priv->polarity = args.args[2];
>>
>> priv->init_voltage = fdtdec_get_int(blob, node,
>> "regulator-init-microvolt", -1);
>> diff --git a/drivers/pwm/pwm-uclass.c b/drivers/pwm/pwm-uclass.c
>> index c2200af..287a7f3 100644
>> --- a/drivers/pwm/pwm-uclass.c
>> +++ b/drivers/pwm/pwm-uclass.c
>> @@ -9,6 +9,16 @@
>> #include <dm.h>
>> #include <pwm.h>
>>
>> +int pwm_set_init(struct udevice *dev, uint channel, uint polarity)
>> +{
>> + struct pwm_ops *ops = pwm_get_ops(dev);
>> +
>> + if (!ops->set_init)
>> + return -ENOSYS;
>> +
>> + return ops->set_init(dev, channel, polarity);
>> +}
>> +
>> int pwm_set_config(struct udevice *dev, uint channel, uint period_ns,
>> uint duty_ns)
>> {
>> diff --git a/drivers/pwm/rk_pwm.c b/drivers/pwm/rk_pwm.c
>> index 9254f5b..5ff1e00 100644
>> --- a/drivers/pwm/rk_pwm.c
>> +++ b/drivers/pwm/rk_pwm.c
>> @@ -21,8 +21,22 @@ DECLARE_GLOBAL_DATA_PTR;
>> struct rk_pwm_priv {
>> struct rk3288_pwm *regs;
>> ulong freq;
>> + uint enable_conf;
>> };
>>
>> +static int rk_pwm_set_init(struct udevice *dev, uint channel, uint polarity)
>> +{
>
> "channel" is need?
Don't need.
>
>> + struct rk_pwm_priv *priv = dev_get_priv(dev);
>> +
>> + debug("%s: polarity=%u\n", __func__, polarity);
>> + if (polarity)
>> + priv->enable_conf |= PWM_DUTY_NEGATIVE | PWM_INACTIVE_POSTIVE;
>> + else
>> + priv->enable_conf |= PWM_DUTY_POSTIVE | PWM_INACTIVE_NEGATIVE;
>> +
>> + return 0;
>> +}
>> +
>> static int rk_pwm_set_config(struct udevice *dev, uint channel, uint period_ns,
>> uint duty_ns)
>> {
>> @@ -32,7 +46,7 @@ static int rk_pwm_set_config(struct udevice *dev, uint channel, uint period_ns,
>>
>> debug("%s: period_ns=%u, duty_ns=%u\n", __func__, period_ns, duty_ns);
>> writel(PWM_SEL_SRC_CLK | PWM_OUTPUT_LEFT | PWM_LP_DISABLE |
>> - PWM_CONTINUOUS | PWM_DUTY_POSTIVE | PWM_INACTIVE_POSTIVE |
>> + PWM_CONTINUOUS | priv->enable_conf |
>> RK_PWM_DISABLE,
>> ®s->ctrl);
>>
>> @@ -83,6 +97,7 @@ static int rk_pwm_probe(struct udevice *dev)
>> }
>>
>> static const struct pwm_ops rk_pwm_ops = {
>> + .set_init = rk_pwm_set_init,
>> .set_config = rk_pwm_set_config,
>> .set_enable = rk_pwm_set_enable,
>> };
>> diff --git a/include/pwm.h b/include/pwm.h
>> index 851915e..a66ee1f 100644
>> --- a/include/pwm.h
>> +++ b/include/pwm.h
>> @@ -14,6 +14,15 @@
>> /* struct pwm_ops: Operations for the PWM uclass */
>> struct pwm_ops {
>> /**
>> + * set_init() - Set the PWM invert
>> + *
>> + * @dev: PWM device to update
>> + * @channel: PWM channel to update
>> + * @polarity: PWM invert polarity
>> + * @return 0 if OK, -ve on error
>> + */
>> + int (*set_init)(struct udevice *dev, uint channel, uint polarity);
>
> Is there a reason about using int type? It's always return 0...
> Otherwise do you have a plan to use "int" type?
>
No particular reason.
just follow as set_config and set_enable.
> Best Regards,
> Jaehoon Chung
>
>> + /**
>> * set_config() - Set the PWM configuration
>> *
>> * @dev: PWM device to update
>>
>
>
>
>
next prev parent reply other threads:[~2017-04-10 1:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20170407110305epcas5p2925521ec1111cac490a7b7a1bd7d6cc5@epcas5p2.samsung.com>
2017-04-07 11:02 ` [U-Boot] [PATCH] power: regulator: pwm: support pwm polarity setting Kever Yang
2017-04-07 11:28 ` Jaehoon Chung
2017-04-10 1:50 ` Elaine Zhang [this message]
2017-04-09 19:28 ` Simon Glass
2017-04-10 2:09 ` Elaine Zhang
2017-04-17 3:03 ` Simon Glass
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=58EAE4E4.9040204@rock-chips.com \
--to=zhangqing@rock-chips.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.