From patchwork Tue Jun 14 09:13:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris BREZILLON X-Patchwork-Id: 9175287 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 A57CE60772 for ; Tue, 14 Jun 2016 09:15:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 93A3B28236 for ; Tue, 14 Jun 2016 09:15:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 87D7728294; Tue, 14 Jun 2016 09:15:41 +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=-3.2 required=2.0 tests=BAYES_00,FSL_HELO_HOME, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1ADC025EF7 for ; Tue, 14 Jun 2016 09:15:41 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1bCkRg-0008RB-0i; Tue, 14 Jun 2016 09:15:40 +0000 Received: from down.free-electrons.com ([37.187.137.238] helo=mail.free-electrons.com) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1bCkQC-0005R7-Rq; Tue, 14 Jun 2016 09:14:11 +0000 Received: by mail.free-electrons.com (Postfix, from userid 110) id 593BC4A4; Tue, 14 Jun 2016 11:13:29 +0200 (CEST) Received: from bbrezillon.home (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.free-electrons.com (Postfix) with ESMTPSA id AD6C047D; Tue, 14 Jun 2016 11:13:28 +0200 (CEST) From: Boris Brezillon To: Thierry Reding , linux-pwm@vger.kernel.org, Mark Brown , Liam Girdwood Subject: [PATCH v3 07/14] pwm: sti: Add support for hardware readout Date: Tue, 14 Jun 2016 11:13:15 +0200 Message-Id: <1465895602-31008-8-git-send-email-boris.brezillon@free-electrons.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1465895602-31008-1-git-send-email-boris.brezillon@free-electrons.com> References: <1465895602-31008-1-git-send-email-boris.brezillon@free-electrons.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160614_021409_312044_95B59765 X-CRM114-Status: GOOD ( 13.11 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Milo Kim , Heiko Stuebner , Patrice Chotard , Laxman Dewangan , kernel@stlinux.com, Boris Brezillon , Brian Norris , Stephen Barber , linux-rockchip@lists.infradead.org, Caesar Wang , devicetree@vger.kernel.org, Pawel Moll , Ian Campbell , Doug Anderson , Rob Herring , linux-arm-kernel@lists.infradead.org, Maxime Coquelin , Srinivas Kandagatla , linux-kernel@vger.kernel.org, Kumar Gala , Ajit Pal Singh 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 Implement ->get_state() to provide support for initial state retrieval. Signed-off-by: Boris Brezillon --- drivers/pwm/pwm-sti.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/drivers/pwm/pwm-sti.c b/drivers/pwm/pwm-sti.c index 92abbd5..6300d3e 100644 --- a/drivers/pwm/pwm-sti.c +++ b/drivers/pwm/pwm-sti.c @@ -238,6 +238,43 @@ static void sti_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) mutex_unlock(&pc->sti_pwm_lock); } +static void sti_pwm_get_state(struct pwm_chip *chip, + struct pwm_device *pwm, + struct pwm_state *state) +{ + struct sti_pwm_chip *pc = to_sti_pwmchip(chip); + unsigned int regval, prescaler; + int ret; + + /* The clock has to be enabled to access PWM registers */ + ret = clk_enable(pc->clk); + if (ret) { + dev_err(chip->dev, "Failed to enable PWM clk"); + return; + } + + regmap_field_read(pc->prescale_high, ®val); + prescaler = regval << 4; + regmap_field_read(pc->prescale_low, ®val); + prescaler |= regval; + state->period = DIV_ROUND_CLOSEST_ULL((u64)(prescaler + 1) * + NSEC_PER_SEC * + (pc->cdata->max_pwm_cnt + 1), + pc->clk_rate); + + regmap_read(pc->regmap, STI_DS_REG(pwm->hwpwm), ®val); + state->duty_cycle = DIV_ROUND_CLOSEST_ULL((u64)(regval + 1) * + state->period, + pc->cdata->max_pwm_cnt + 1); + + regmap_field_read(pc->pwm_en, ®val); + state->enabled = regval; + + state->polarity = PWM_POLARITY_NORMAL; + + clk_disable(pc->clk); +} + static void sti_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) { struct sti_pwm_chip *pc = to_sti_pwmchip(chip); @@ -249,6 +286,7 @@ static const struct pwm_ops sti_pwm_ops = { .config = sti_pwm_config, .enable = sti_pwm_enable, .disable = sti_pwm_disable, + .get_state = sti_pwm_get_state, .free = sti_pwm_free, .owner = THIS_MODULE, };