From patchwork Sat Jul 8 04:03:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wu X-Patchwork-Id: 9831345 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 939DE602BC for ; Sat, 8 Jul 2017 04:01:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7E68928399 for ; Sat, 8 Jul 2017 04:01:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6FB9D284FC; Sat, 8 Jul 2017 04:01:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EE3A028399 for ; Sat, 8 Jul 2017 04:01:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=cvW5dPFpIqkNx91EwbzTZfF6JDAr39GQ5k+EOGzpes0=; b=DCFJpO+xk8kwcb5KnbMY8yMVen L9pABk03aj49LL19C8ts4yaOM8arzuHRjXlhK8j/4lc5F3JnbGYH+4Kr4YTg4J19gNl2FVw/B+/KU +kIVACcz5O1sEKmdq0Msbr/CW33Xegjl0FmBef0tL5dUgdFPJXQBW55+5E0IBiOu28x6zC9MeYBs+ Vewxw2lae60kcf0pDLoxdJSOXFMvWUXQ3Vqy9qfToh9QHMwl44k4QzYhGyRExcaFDb792PfW/Skll 51/WDEaV3+mPvjfsFh+15GO4b/EciwIUNQ7j7jetFE2H3uXmv1hZyebg4BcIEa9RqdUH5vm8O4m0T fBC/Ylcg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dTgva-00015t-JU; Sat, 08 Jul 2017 04:01:06 +0000 Received: from ca-mx01.263.net ([50.18.194.75] helo=smtphy.263.net) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dTgvE-00007q-6E; Sat, 08 Jul 2017 04:00:47 +0000 Received: from transport.263xmail.com (unknown [38.83.106.156]) by smtphy.263.net (Postfix) with ESMTPS id 41D3E1206AE; Sat, 8 Jul 2017 12:00:22 +0800 (CST) Received: from lucky1.263xmail.com (unknown [192.168.165.181]) by transportlucky.263xmail.com (Postfix) with ESMTP id 6B09240B6; Sat, 8 Jul 2017 12:00:19 +0800 (CST) Received: from david.wu?rock-chips.com (unknown [192.168.167.233]) by lucky1.263xmail.com (Postfix) with ESMTP id 1A9B064298; Sat, 8 Jul 2017 12:00:10 +0800 (CST) X-263anti-spam: KSV:0; X-MAIL-GRAY: 1 X-MAIL-DELIVERY: 0 X-KSVirus-check: 0 X-ABS-CHECKED: 4 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.263.net (Postfix) with ESMTPA id 84471383; Sat, 8 Jul 2017 12:00:01 +0800 (CST) X-RL-SENDER: david.wu@rock-chips.com X-FST-TO: thierry.reding@gmail.com X-SENDER-IP: 58.22.7.114 X-LOGIN-NAME: david.wu@rock-chips.com X-UNIQUE-TAG: <3783d81ee1be08aefebc56fb4cfaa87e> X-ATTACHMENT-NUM: 0 X-SENDER: wdc@rock-chips.com X-DNS-TYPE: 0 Received: from unknown (unknown [58.22.7.114]) by smtp.263.net (Postfix) whith SMTP id 19530I8GWN7; Sat, 08 Jul 2017 12:00:09 +0800 (CST) From: David Wu To: thierry.reding@gmail.com, heiko@sntech.de, boris.brezillon@free-electrons.com, robh+dt@kernel.org Subject: [PATCH v2 4/7] pwm: rockchip: Use pwm_apply instead of the pwm_enable Date: Sat, 8 Jul 2017 12:03:46 +0800 Message-Id: <1499486629-9659-5-git-send-email-david.wu@rock-chips.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1499486629-9659-1-git-send-email-david.wu@rock-chips.com> References: <1499486629-9659-1-git-send-email-david.wu@rock-chips.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170707_210044_431398_CEDEB03B X-CRM114-Status: GOOD ( 12.66 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, huangtao@rock-chips.com, linux-pwm@vger.kernel.org, catalin.marinas@arm.com, briannorris@chromium.org, dianders@chromium.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, devicetree@vger.kernel.org, David Wu , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Drop the custom hook of pwm_enable and implement pwm_apply_v1 and pwm_apply_v2 instead. Signed-off-by: David Wu --- drivers/pwm/pwm-rockchip.c | 141 +++++++++++++++++++++++++-------------------- 1 file changed, 77 insertions(+), 64 deletions(-) diff --git a/drivers/pwm/pwm-rockchip.c b/drivers/pwm/pwm-rockchip.c index 85f9515..12e7b4a8 100644 --- a/drivers/pwm/pwm-rockchip.c +++ b/drivers/pwm/pwm-rockchip.c @@ -51,11 +51,10 @@ struct rockchip_pwm_data { bool supports_polarity; const struct pwm_ops *ops; - void (*set_enable)(struct pwm_chip *chip, - struct pwm_device *pwm, bool enable, - enum pwm_polarity polarity); void (*get_state)(struct pwm_chip *chip, struct pwm_device *pwm, struct pwm_state *state); + int (*pwm_apply)(struct pwm_chip *chip, struct pwm_device *pwm, + struct pwm_state *state); }; static inline struct rockchip_pwm_chip *to_rockchip_pwm_chip(struct pwm_chip *c) @@ -63,24 +62,6 @@ static inline struct rockchip_pwm_chip *to_rockchip_pwm_chip(struct pwm_chip *c) return container_of(c, struct rockchip_pwm_chip, chip); } -static void rockchip_pwm_set_enable_v1(struct pwm_chip *chip, - struct pwm_device *pwm, bool enable, - enum pwm_polarity polarity) -{ - struct rockchip_pwm_chip *pc = to_rockchip_pwm_chip(chip); - u32 enable_conf = PWM_CTRL_OUTPUT_EN | PWM_CTRL_TIMER_EN; - u32 val; - - val = readl_relaxed(pc->base + pc->data->regs.ctrl); - - if (enable) - val |= enable_conf; - else - val &= ~enable_conf; - - writel_relaxed(val, pc->base + pc->data->regs.ctrl); -} - static void rockchip_pwm_get_state_v1(struct pwm_chip *chip, struct pwm_device *pwm, struct pwm_state *state) @@ -94,30 +75,6 @@ static void rockchip_pwm_get_state_v1(struct pwm_chip *chip, state->enabled = true; } -static void rockchip_pwm_set_enable_v2(struct pwm_chip *chip, - struct pwm_device *pwm, bool enable, - enum pwm_polarity polarity) -{ - struct rockchip_pwm_chip *pc = to_rockchip_pwm_chip(chip); - u32 enable_conf = PWM_OUTPUT_LEFT | PWM_LP_DISABLE | PWM_ENABLE | - PWM_CONTINUOUS; - u32 val; - - if (polarity == PWM_POLARITY_INVERSED) - enable_conf |= PWM_DUTY_NEGATIVE | PWM_INACTIVE_POSITIVE; - else - enable_conf |= PWM_DUTY_POSITIVE | PWM_INACTIVE_NEGATIVE; - - val = readl_relaxed(pc->base + pc->data->regs.ctrl); - - if (enable) - val |= enable_conf; - else - val &= ~enable_conf; - - writel_relaxed(val, pc->base + pc->data->regs.ctrl); -} - static void rockchip_pwm_get_state_v2(struct pwm_chip *chip, struct pwm_device *pwm, struct pwm_state *state) @@ -193,10 +150,12 @@ static void rockchip_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, static int rockchip_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm, bool enable, - enum pwm_polarity polarity) + enum pwm_polarity polarity, + u32 enable_conf) { struct rockchip_pwm_chip *pc = to_rockchip_pwm_chip(chip); int ret; + u32 val; if (enable) { ret = clk_enable(pc->clk); @@ -204,7 +163,23 @@ static int rockchip_pwm_enable(struct pwm_chip *chip, return ret; } - pc->data->set_enable(chip, pwm, enable, polarity); + if (pc->data->supports_polarity) { + if (polarity == PWM_POLARITY_INVERSED) + enable_conf |= PWM_DUTY_NEGATIVE | + PWM_INACTIVE_POSITIVE; + else + enable_conf |= PWM_DUTY_POSITIVE | + PWM_INACTIVE_NEGATIVE; + } + + val = readl_relaxed(pc->base + pc->data->regs.ctrl); + + if (enable) + val |= enable_conf; + else + val &= ~enable_conf; + + writel_relaxed(val, pc->base + pc->data->regs.ctrl); if (!enable) clk_disable(pc->clk); @@ -212,37 +187,75 @@ static int rockchip_pwm_enable(struct pwm_chip *chip, return 0; } -static int rockchip_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, - struct pwm_state *state) +static int rockchip_pwm_apply_v1(struct pwm_chip *chip, struct pwm_device *pwm, + struct pwm_state *state) { - struct rockchip_pwm_chip *pc = to_rockchip_pwm_chip(chip); + u32 enable_conf = PWM_CTRL_OUTPUT_EN | PWM_CTRL_TIMER_EN; struct pwm_state curstate; bool enabled; - int ret; + int ret = 0; pwm_get_state(pwm, &curstate); enabled = curstate.enabled; - ret = clk_enable(pc->pclk); - if (ret) - return ret; - if (state->polarity != curstate.polarity && enabled) { - ret = rockchip_pwm_enable(chip, pwm, false, state->polarity); + ret = rockchip_pwm_enable(chip, pwm, false, state->polarity, + enable_conf); if (ret) - goto out; + return ret; enabled = false; } rockchip_pwm_config(chip, pwm, state->duty_cycle, state->period); - - if (state->enabled != enabled) { + if (state->enabled != enabled) ret = rockchip_pwm_enable(chip, pwm, state->enabled, - state->polarity); + state->polarity, enable_conf); + + return ret; +} + +static int rockchip_pwm_apply_v2(struct pwm_chip *chip, struct pwm_device *pwm, + struct pwm_state *state) +{ + u32 enable_conf = PWM_OUTPUT_LEFT | PWM_LP_DISABLE | PWM_ENABLE | + PWM_CONTINUOUS; + struct pwm_state curstate; + bool enabled; + int ret = 0; + + pwm_get_state(pwm, &curstate); + enabled = curstate.enabled; + + if (state->polarity != curstate.polarity && enabled) { + ret = rockchip_pwm_enable(chip, pwm, false, state->polarity, + enable_conf); if (ret) - goto out; + return ret; + enabled = false; } + rockchip_pwm_config(chip, pwm, state->duty_cycle, state->period); + if (state->enabled != enabled) + ret = rockchip_pwm_enable(chip, pwm, state->enabled, + state->polarity, enable_conf); + + return ret; +} + +static int rockchip_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, + struct pwm_state *state) +{ + struct rockchip_pwm_chip *pc = to_rockchip_pwm_chip(chip); + int ret; + + ret = clk_enable(pc->pclk); + if (ret) + return ret; + + ret = pc->data->pwm_apply(chip, pwm, state); + if (ret) + goto out; + /* * Update the state with the real hardware, which can differ a bit * because of period/duty_cycle approximation. @@ -270,8 +283,8 @@ static int rockchip_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, }, .prescaler = 2, .ops = &rockchip_pwm_ops, - .set_enable = rockchip_pwm_set_enable_v1, .get_state = rockchip_pwm_get_state_v1, + .pwm_apply = rockchip_pwm_apply_v1, }; static const struct rockchip_pwm_data pwm_data_v2 = { @@ -284,8 +297,8 @@ static int rockchip_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, .prescaler = 1, .supports_polarity = true, .ops = &rockchip_pwm_ops, - .set_enable = rockchip_pwm_set_enable_v2, .get_state = rockchip_pwm_get_state_v2, + .pwm_apply = rockchip_pwm_apply_v2, }; static const struct rockchip_pwm_data pwm_data_vop = { @@ -298,8 +311,8 @@ static int rockchip_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, .prescaler = 1, .supports_polarity = true, .ops = &rockchip_pwm_ops, - .set_enable = rockchip_pwm_set_enable_v2, .get_state = rockchip_pwm_get_state_v2, + .pwm_apply = rockchip_pwm_apply_v2, }; static const struct of_device_id rockchip_pwm_dt_ids[] = {