From patchwork Mon Feb 20 20:16:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 730183 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3vRw0100b3z9s7s for ; Tue, 21 Feb 2017 07:17:04 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752100AbdBTURE (ORCPT ); Mon, 20 Feb 2017 15:17:04 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54734 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752091AbdBTURE (ORCPT ); Mon, 20 Feb 2017 15:17:04 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E2B1081253; Mon, 20 Feb 2017 20:17:04 +0000 (UTC) Received: from shalem.localdomain.com (ovpn-117-9.ams2.redhat.com [10.36.117.9]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1KKGx6l014649; Mon, 20 Feb 2017 15:17:03 -0500 From: Hans de Goede To: Thierry Reding Cc: Hans de Goede , linux-pwm@vger.kernel.org, Andy Shevchenko Subject: [PATCH 3/3] pwm: lpss: Add get_state callback Date: Mon, 20 Feb 2017 21:16:57 +0100 Message-Id: <20170220201657.24801-4-hdegoede@redhat.com> In-Reply-To: <20170220201657.24801-1-hdegoede@redhat.com> References: <20170220201657.24801-1-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 20 Feb 2017 20:17:04 +0000 (UTC) Sender: linux-pwm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pwm@vger.kernel.org Add a get_state callback so that the initial state correctly reflects the actual hardware state. Cc: Andy Shevchenko Signed-off-by: Hans de Goede Acked-by: Jani Nikula --- Changes in v2: -Rebase on top of linux-pwm/for-next --- drivers/pwm/pwm-lpss.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/pwm/pwm-lpss.c b/drivers/pwm/pwm-lpss.c index 0b549dc..5e7e9ac 100644 --- a/drivers/pwm/pwm-lpss.c +++ b/drivers/pwm/pwm-lpss.c @@ -154,8 +154,36 @@ static int pwm_lpss_apply(struct pwm_chip *chip, struct pwm_device *pwm, return ret; } +static void pwm_lpss_get_state(struct pwm_chip *chip, struct pwm_device *pwm, + struct pwm_state *state) +{ + struct pwm_lpss_chip *lpwm = to_lpwm(chip); + unsigned long base_unit_range, freq; + unsigned long long base_unit, on_time_div; + u32 ctrl; + + base_unit_range = BIT(lpwm->info->base_unit_bits); + + ctrl = pwm_lpss_read(pwm); + on_time_div = ctrl & PWM_ON_TIME_DIV_MASK; + base_unit = (ctrl >> PWM_BASE_UNIT_SHIFT) & (base_unit_range - 1); + + freq = base_unit * lpwm->info->clk_rate / base_unit_range; + if (freq == 0) + freq = 1; + + state->period = NSEC_PER_SEC / freq; + state->duty_cycle = state->period * on_time_div / 255ULL; + state->polarity = PWM_POLARITY_NORMAL; + state->enabled = (ctrl & PWM_ENABLE) ? true : false; + + if (state->enabled) + pm_runtime_get_sync(chip->dev); +} + static const struct pwm_ops pwm_lpss_ops = { .apply = pwm_lpss_apply, + .get_state = pwm_lpss_get_state, .owner = THIS_MODULE, };