From patchwork Tue Apr 11 08:35:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kever Yang X-Patchwork-Id: 749379 X-Patchwork-Delegate: jh80.chung@samsung.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3w2L481B1Qz9s8Y for ; Tue, 11 Apr 2017 18:36:07 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="KqldUp6m"; dkim-atps=neutral Received: by lists.denx.de (Postfix, from userid 105) id BC713C21C71; Tue, 11 Apr 2017 08:35:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 10C75C21C31; Tue, 11 Apr 2017 08:35:57 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 866C2C21C2B; Tue, 11 Apr 2017 08:35:55 +0000 (UTC) Received: from mail-pg0-f67.google.com (mail-pg0-f67.google.com [74.125.83.67]) by lists.denx.de (Postfix) with ESMTPS id D19D2C21C28 for ; Tue, 11 Apr 2017 08:35:54 +0000 (UTC) Received: by mail-pg0-f67.google.com with SMTP id 79so28933498pgf.0 for ; Tue, 11 Apr 2017 01:35:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=UAKvVvMsjrJIiTCeTjhmthTtoEQBgGGDrVJFXlaZ9rI=; b=KqldUp6meKVwFadzNXPX7W65jQVznHrUDEsQn39qLEqJiuVTuTbGUvkXjEQMx1GGmY N8KyAqFEJrPhXxE7oOcbaD7UsgSJuFMkPBJGRsPpxqCyIPxE810xjbwXCvod57r/P50R oMEXqP4WCeA2qGw9O115EALAKMWCbZVM5EuSLmuTjaRGvWqruANlKQG/7lXhKmXHR1JM fDgWBTYwOGD3FflfkyD4F31267zA4QwladLi0KH73xCS6kkjhrAAzYLr/TcW0kKDTMGU +DHt4RmQ0kzAyibOUQg7BKJR15NzIn+4iYXtsO3fM35hg6d3VQimyXlGGtiHrlo6VIAp aWdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=UAKvVvMsjrJIiTCeTjhmthTtoEQBgGGDrVJFXlaZ9rI=; b=VG1ncfPaZCEP+Kd2elZ6gY0C9T6DiVYKku6tyA0+i4DcLXT9Hx7+EdaYF9rjCxz7kw 8+srk4zu79XoF7Q2lhKYAJys0QBKqT+0AHGJQOjvTvPceh3olDoT1Kw5wBpkpyPvKlJ1 PfhQ/BFn8doJJC7NGZhWBsVjAY0yztE9KRTw8lajVTKlxO6lK+Q73L1DjK2XG/kGKM8s rD6bKOwGK8VGP8+fUqqDv+aJBkQNlTohbl/5el/9hhiq/slp9uJTP9R4pznjAcIgh/mO uy/QZqpw0X2GvqBywRlMehjk82rMkcnDOB6aujHBIedqfJN1k8TZoQMbbKO4rgOSRxAE A1wQ== X-Gm-Message-State: AFeK/H2VR9KwaISBeHRdG1xMuSPaMatTkQK2+F2EF9nmOGfIcp8YiDxuhSMWRtuiCUVaxg== X-Received: by 10.84.205.70 with SMTP id o6mr73481314plh.63.1491899753282; Tue, 11 Apr 2017 01:35:53 -0700 (PDT) Received: from localhost.localdomain ([103.29.142.67]) by smtp.gmail.com with ESMTPSA id b128sm29092646pgc.16.2017.04.11.01.35.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 11 Apr 2017 01:35:52 -0700 (PDT) From: Kever Yang To: heiko@sntech.de Date: Tue, 11 Apr 2017 16:35:37 +0800 Message-Id: <1491899738-10087-1-git-send-email-kever.yang@rock-chips.com> X-Mailer: git-send-email 1.9.1 Cc: u-boot@lists.denx.de, Elaine Zhang , linux-rockchip@lists.infradead.org Subject: [U-Boot] [PATCH v2 1/2] power: regulator: pwm: support pwm polarity setting X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" 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: Elaine Zhang Signed-off-by: Kever Yang --- Changes in v2: - use pwm_set_invert() instead of pwm_set_init() - add comment for polarity drivers/power/regulator/pwm_regulator.c | 16 ++++++++++++++-- drivers/pwm/pwm-uclass.c | 10 ++++++++++ drivers/pwm/rk_pwm.c | 17 ++++++++++++++++- include/pwm.h | 9 +++++++++ 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/drivers/power/regulator/pwm_regulator.c b/drivers/power/regulator/pwm_regulator.c index 4875238..3ffe3a1 100644 --- a/drivers/power/regulator/pwm_regulator.c +++ b/drivers/power/regulator/pwm_regulator.c @@ -24,6 +24,12 @@ struct pwm_regulator_info { int pwm_id; /* the period of one PWM cycle */ int period_ns; + /* + * the polarity of one PWM + * 0: normal polarity + * 1: inverted polarity + */ + int polarity; struct udevice *pwm; /* initialize voltage of regulator */ unsigned int init_voltage; @@ -49,7 +55,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 +73,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_invert(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 +109,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..d1d7fce 100644 --- a/drivers/pwm/pwm-uclass.c +++ b/drivers/pwm/pwm-uclass.c @@ -9,6 +9,16 @@ #include #include +int pwm_set_invert(struct udevice *dev, uint channel, uint polarity) +{ + struct pwm_ops *ops = pwm_get_ops(dev); + + if (!ops->set_invert) + return -ENOSYS; + + return ops->set_invert(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..f003d09 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_invert(struct udevice *dev, uint channel, uint polarity) +{ + 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_invert = rk_pwm_set_invert, .set_config = rk_pwm_set_config, .set_enable = rk_pwm_set_enable, }; diff --git a/include/pwm.h b/include/pwm.h index 851915e..66c6bf0 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_invert() - 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_invert)(struct udevice *dev, uint channel, uint polarity); + /** * set_config() - Set the PWM configuration * * @dev: PWM device to update