From patchwork Fri Mar 13 13:58:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kumar, Shobhit" X-Patchwork-Id: 6005261 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 1610E9F2A9 for ; Fri, 13 Mar 2015 13:59:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 215EB20274 for ; Fri, 13 Mar 2015 13:59:01 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id EAFA9200E6 for ; Fri, 13 Mar 2015 13:58:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 815A46EAC9; Fri, 13 Mar 2015 06:58:59 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTP id 8F8636EAC9 for ; Fri, 13 Mar 2015 06:58:58 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP; 13 Mar 2015 06:58:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.11,395,1422950400"; d="scan'208";a="698291016" Received: from skumar40-ivm.iind.intel.com ([10.223.179.147]) by orsmga002.jf.intel.com with ESMTP; 13 Mar 2015 06:58:08 -0700 From: Shobhit Kumar To: intel-gfx Date: Fri, 13 Mar 2015 19:28:02 +0530 Message-Id: <1426255082-25002-1-git-send-email-shobhit.kumar@intel.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1426177893-17945-5-git-send-email-shobhit.kumar@intel.com> References: <1426177893-17945-5-git-send-email-shobhit.kumar@intel.com> Cc: Alexandre Courbot , Samuel Ortiz , Jani Nikula , Shobhit Kumar , Linus Walleij , Thierry Reding , Daniel Vetter Subject: [Intel-gfx] [PATCH 4/9] drivers/pwm: Add helper to configure pwm using clock divisor and duty percent 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-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some chips instead of using period_ns and duty_ns can be configured using the clock divisor and duty percent. Adds an alternative configuration method for such chips v2: Corrected the chip validation for config_alternate in pwmchip_add CC: Samuel Ortiz Cc: Linus Walleij Cc: Alexandre Courbot Cc: Thierry Reding Signed-off-by: Shobhit Kumar --- drivers/pwm/core.c | 27 ++++++++++++++++++++++++++- include/linux/pwm.h | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index 810aef3..604e93d 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -235,7 +235,8 @@ int pwmchip_add(struct pwm_chip *chip) unsigned int i; int ret; - if (!chip || !chip->dev || !chip->ops || !chip->ops->config || + if (!chip || !chip->dev || !chip->ops || + !(chip->ops->config || chip->ops->config_alternate) || !chip->ops->enable || !chip->ops->disable || !chip->npwm) return -EINVAL; @@ -422,6 +423,30 @@ int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns) EXPORT_SYMBOL_GPL(pwm_config); /** + * pwm_config_alternate() - change a PWM device configuration + * @pwm: PWM device + * @clk_div: Clock divider to configure + * @duty_percentage: duty cycle in percentage + */ +int pwm_config_alternate(struct pwm_device *pwm, int clk_div, int duty_percent) +{ + int err; + + if (!pwm || clk_div < 0 || duty_percent < 0 || duty_percent > 100) + return -EINVAL; + + err = pwm->chip->ops->config_alternate(pwm->chip, pwm, clk_div, duty_percent); + if (err) + return err; + + pwm->clk_div = clk_div; + pwm->duty_percent = duty_percent; + + return 0; +} +EXPORT_SYMBOL_GPL(pwm_config_alternate); + +/** * pwm_set_polarity() - configure the polarity of a PWM signal * @pwm: PWM device * @polarity: new polarity of the PWM signal diff --git a/include/linux/pwm.h b/include/linux/pwm.h index e90628c..739cb2b 100644 --- a/include/linux/pwm.h +++ b/include/linux/pwm.h @@ -24,6 +24,12 @@ void pwm_free(struct pwm_device *pwm); int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns); /* + * pwm_config_alternate - change a PWM device configuration + * based on clk_dic and duty_percent + */ +int pwm_config_alternate(struct pwm_device *pwm, int clk_div, int duty_percent); + +/* * pwm_enable - start a PWM output toggling */ int pwm_enable(struct pwm_device *pwm); @@ -89,6 +95,8 @@ struct pwm_device { unsigned int period; /* in nanoseconds */ unsigned int duty_cycle; /* in nanoseconds */ + unsigned int clk_div; + unsigned int duty_percent; enum pwm_polarity polarity; }; @@ -114,6 +122,28 @@ static inline unsigned int pwm_get_duty_cycle(struct pwm_device *pwm) return pwm ? pwm->duty_cycle : 0; } +static inline void pwm_set_clk_div(struct pwm_device *pwm, unsigned int clk_div) +{ + if (pwm) + pwm->clk_div = clk_div; +} + +static inline unsigned int pwm_get_clk_div(struct pwm_device *pwm) +{ + return pwm ? pwm->clk_div : 0; +} + +static inline void pwm_set_duty_percent(struct pwm_device *pwm, unsigned int duty_percent) +{ + if (pwm) + pwm->duty_percent = duty_percent; +} + +static inline unsigned int pwm_get_duty_percent(struct pwm_device *pwm) +{ + return pwm ? pwm->duty_percent : 0; +} + /* * pwm_set_polarity - configure the polarity of a PWM signal */ @@ -138,6 +168,9 @@ struct pwm_ops { int (*config)(struct pwm_chip *chip, struct pwm_device *pwm, int duty_ns, int period_ns); + int (*config_alternate)(struct pwm_chip *chip, + struct pwm_device *pwm, + int clk_div, int duty_percent); int (*set_polarity)(struct pwm_chip *chip, struct pwm_device *pwm, enum pwm_polarity polarity);