From patchwork Wed Jul 18 12:54:13 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: avinash philip X-Patchwork-Id: 1210911 Return-Path: X-Original-To: patchwork-linux-omap@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 84A5D3FCFC for ; Wed, 18 Jul 2012 13:09:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754492Ab2GRNIu (ORCPT ); Wed, 18 Jul 2012 09:08:50 -0400 Received: from devils.ext.ti.com ([198.47.26.153]:59669 "EHLO devils.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753648Ab2GRNIt (ORCPT ); Wed, 18 Jul 2012 09:08:49 -0400 Received: from dbdp20.itg.ti.com ([172.24.170.38]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id q6ID8kpI025393; Wed, 18 Jul 2012 08:08:46 -0500 Received: from DBDE71.ent.ti.com (localhost [127.0.0.1]) by dbdp20.itg.ti.com (8.13.8/8.13.8) with ESMTP id q6ID8iX6021707; Wed, 18 Jul 2012 18:38:45 +0530 (IST) Received: from dbdp32.itg.ti.com (172.24.170.251) by DBDE71.ent.ti.com (172.24.170.149) with Microsoft SMTP Server id 14.1.323.3; Wed, 18 Jul 2012 18:38:44 +0530 Received: from ucmsshproxy.india.ext.ti.com (dbdp20.itg.ti.com [172.24.170.38]) by dbdp32.itg.ti.com (8.13.8/8.13.8) with SMTP id q6ID8gMN006394; Wed, 18 Jul 2012 18:38:43 +0530 Received: from symphony.india.ext.ti.com (unknown [192.168.247.13]) by ucmsshproxy.india.ext.ti.com (Postfix) with ESMTP id B8D86158002; Wed, 18 Jul 2012 18:38:42 +0530 (IST) Received: from linux-psp-server.india.ext.ti.com (linux-psp-server [192.168.247.76]) by symphony.india.ext.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id q6ID8fI28841; Wed, 18 Jul 2012 18:38:41 +0530 (IST) From: "Philip, Avinash" To: , , CC: , , Subject: [PATCH] PWM: Add support for configuring polarity of PWM Date: Wed, 18 Jul 2012 18:24:13 +0530 Message-ID: <1342616053-7793-1-git-send-email-avinashphilip@ti.com> X-Mailer: git-send-email 1.7.1 MIME-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org Duty cycle inversion of PWM wave should achieved through PWM polarity inversion. Also polarity of PWM wave should configurable from slave drivers, Configure polarity 1. PWM_POLARITY_NORMAL -> duty ns defines ON period of PWM wave 2. PWM_POLARITY_INVERSE -> duty ns defines OFF period of PWM wave. This patch adds support for configuring PWM polarity in PWM frame work. Signed-off-by: Philip, Avinash --- Configuring polarity to be done with PWM device disabled, if not failure reported. If PWM device is enabled while configuring polarity, disabling and re_enabling make it complex. Whoever uses this API has to taken care of the basic rules. Discussions related to this can found at http://www.spinics.net/lists/kernel/msg1372110.html :100644 100644 ecb7690... 24d5495... M drivers/pwm/core.c :100644 100644 21d076c... 2e4e960... M include/linux/pwm.h drivers/pwm/core.c | 32 ++++++++++++++++++++++++++++++++ include/linux/pwm.h | 15 +++++++++++++++ 2 files changed, 47 insertions(+), 0 deletions(-) diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index ecb7690..24d5495 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -379,6 +379,38 @@ int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns) EXPORT_SYMBOL_GPL(pwm_config); /** + * pwm_set_polarity() - change PWM device Polarity + * @pwm: PWM device + * @polarity: Configure polarity of PWM + * + * Polarity to be configured with PWM device disabled. + */ +int pwm_set_polarity(struct pwm_device *pwm, int polarity) +{ + int pwm_flags = PWM_POLARITY_NORMAL; + + if (!pwm || !pwm->chip->ops->set_polarity) + return -EINVAL; + + if (test_bit(PWMF_ENABLED, &pwm->flags)) { + dev_err(pwm->chip->dev, + "Polarity configuration Failed!, PWM device enabled\n"); + return -EBUSY; + } + + if (polarity == PWM_POLARITY_INVERSE) + pwm_flags = PWM_POLARITY_INVERSE; + + if (!pwm_flags) + clear_bit(PWMF_POLARITY_INVERSE, &pwm->flags); + else + set_bit(PWMF_POLARITY_INVERSE, &pwm->flags); + + return pwm->chip->ops->set_polarity(pwm->chip, pwm, polarity); +} +EXPORT_SYMBOL_GPL(pwm_set_polarity); + +/** * pwm_enable() - start a PWM output toggling * @pwm: PWM device */ diff --git a/include/linux/pwm.h b/include/linux/pwm.h index 21d076c..2e4e960 100644 --- a/include/linux/pwm.h +++ b/include/linux/pwm.h @@ -21,6 +21,16 @@ void pwm_free(struct pwm_device *pwm); */ int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns); +enum { + PWM_POLARITY_NORMAL, /* ON period depends on duty_ns */ + PWM_POLARITY_INVERSE, /* OFF period depends on duty_ns */ +}; + +/* + * pwm_set_polarity - set polarity of PWM device + */ +int pwm_set_polarity(struct pwm_device *pwm, int polarity); + /* * pwm_enable - start a PWM output toggling */ @@ -37,6 +47,7 @@ struct pwm_chip; enum { PWMF_REQUESTED = 1 << 0, PWMF_ENABLED = 1 << 1, + PWMF_POLARITY_INVERSE = 1 << 2, }; struct pwm_device { @@ -66,6 +77,7 @@ static inline unsigned int pwm_get_period(struct pwm_device *pwm) * @request: optional hook for requesting a PWM * @free: optional hook for freeing a PWM * @config: configure duty cycles and period length for this PWM + * @set_polarity: configure polarity of PWM * @enable: enable PWM output toggling * @disable: disable PWM output toggling * @dbg_show: optional routine to show contents in debugfs @@ -79,6 +91,9 @@ struct pwm_ops { int (*config)(struct pwm_chip *chip, struct pwm_device *pwm, int duty_ns, int period_ns); + int (*set_polarity)(struct pwm_chip *chip, + struct pwm_device *pwm, + int polarity); int (*enable)(struct pwm_chip *chip, struct pwm_device *pwm); void (*disable)(struct pwm_chip *chip,