From patchwork Fri Dec 2 10:17:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 9458117 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 2676A60585 for ; Fri, 2 Dec 2016 10:17:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C5012852C for ; Fri, 2 Dec 2016 10:17:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0148628540; Fri, 2 Dec 2016 10:17:54 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C5D2D2852C for ; Fri, 2 Dec 2016 10:17:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 07A066E93E; Fri, 2 Dec 2016 10:17:45 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by gabe.freedesktop.org (Postfix) with ESMTPS id BEB316E93A; Fri, 2 Dec 2016 10:17:41 +0000 (UTC) Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 564AA3F723; Fri, 2 Dec 2016 10:17:41 +0000 (UTC) Received: from shalem.localdomain.com (vpn1-7-92.ams2.redhat.com [10.36.7.92]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uB2AHbvb013630; Fri, 2 Dec 2016 05:17:39 -0500 From: Hans de Goede To: Thierry Reding , Daniel Vetter , Jani Nikula , =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= Date: Fri, 2 Dec 2016 11:17:36 +0100 Message-Id: <20161202101736.12236-2-hdegoede@redhat.com> In-Reply-To: <20161202101736.12236-1-hdegoede@redhat.com> References: <20161202101736.12236-1-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 02 Dec 2016 10:17:41 +0000 (UTC) Cc: linux-pwm@vger.kernel.org, intel-gfx , dri-devel@lists.freedesktop.org, Hans de Goede Subject: [Intel-gfx] [PATCH 2/2] pwm: lpss: Add get_state callback X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP Add a get_state callback so that the initial state correctly reflects the actual hardware state. Signed-off-by: Hans de Goede --- 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 b4d8835..f5603c0 100644 --- a/drivers/pwm/pwm-lpss.c +++ b/drivers/pwm/pwm-lpss.c @@ -135,6 +135,33 @@ static int pwm_lpss_config(struct pwm_chip *chip, struct pwm_device *pwm, return 0; } +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 int pwm_lpss_enable(struct pwm_chip *chip, struct pwm_device *pwm) { pm_runtime_get_sync(chip->dev); @@ -156,6 +183,7 @@ static void pwm_lpss_disable(struct pwm_chip *chip, struct pwm_device *pwm) static const struct pwm_ops pwm_lpss_ops = { .config = pwm_lpss_config, + .get_state = pwm_lpss_get_state, .enable = pwm_lpss_enable, .disable = pwm_lpss_disable, .owner = THIS_MODULE,