From patchwork Fri Apr 22 10:18:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 8908831 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id EFABABF29F for ; Fri, 22 Apr 2016 10:20:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F1EF920256 for ; Fri, 22 Apr 2016 10:20:38 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id A58CC20221 for ; Fri, 22 Apr 2016 10:20:37 +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 1atYAn-0000P1-EF; Fri, 22 Apr 2016 10:18:53 +0000 Received: from mail-wm0-x235.google.com ([2a00:1450:400c:c09::235]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1atYAc-00007T-T8 for linux-arm-kernel@lists.infradead.org; Fri, 22 Apr 2016 10:18:43 +0000 Received: by mail-wm0-x235.google.com with SMTP id u206so19365764wme.1 for ; Fri, 22 Apr 2016 03:18:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=X3kPKzG8T4i0o7bo5KtcxmDi9iPu+0EVauwJmYCvvHI=; b=LHZ0s+XHhi1/SlYBATSiR5ncwI6EdT+uy0rXHco8hHzYQOAh7ssRSo6uUcQZCcTFVQ e7wcyE9EwN4Pn15jS6svjEcC2YFMMNkHuYuPNM7T0kHpq9hEA892OChLk7Wckt6haRzQ bKpQEwE5CCX5TZU9kHLsWBI/ckoFB3c1dJZlI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=X3kPKzG8T4i0o7bo5KtcxmDi9iPu+0EVauwJmYCvvHI=; b=dXInncZWqDAw3GP4zviAuLlghSnDc/xayyeFB4v/lgocFs7EMhMrmsBAKNp5OOPhHQ A2kffvVC4Fg3iP572Wxnuqr/F9976Kedc9QaJZOReZupRCqRwyyg/eU2PSBCYyW2bms5 tbgFnkzpFJlepZBCH6fmjrE6MM13oLmwNSOjLlBLOvIZu50shktfEXDqxJlr5O/Dc4hw RuUWQ/Afz1+1ql9JgYIBbkT+69XscMAz6RAoStlkzzANPrv4ryeMGEQmH0EyXYRhG1SP 0cRkk2GWGEWyCtkB+HLLoEYV2usHFsPFCgaM5dE2KvPjjPfcqLb0S4bl6S/pNNmWXkwi UHbg== X-Gm-Message-State: AOPr4FVhZVCmMrtl+DbBh+KKdrHBPOD1RRzD02Yh8nEFaqI3tQGVlGdSwgbiB9wcwhvxqTN4 X-Received: by 10.28.54.69 with SMTP id d66mr3130787wma.94.1461320301112; Fri, 22 Apr 2016 03:18:21 -0700 (PDT) Received: from dell.localdomain (host81-129-172-5.range81-129.btcentralplus.com. [81.129.172.5]) by smtp.gmail.com with ESMTPSA id a1sm7316345wje.43.2016.04.22.03.18.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Apr 2016 03:18:20 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [[PATCH v2] 01/11] pwm: Add PWM Capture support Date: Fri, 22 Apr 2016 11:18:05 +0100 Message-Id: <1461320295-20414-2-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 2.8.0 In-Reply-To: <1461320295-20414-1-git-send-email-lee.jones@linaro.org> References: <1461320295-20414-1-git-send-email-lee.jones@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160422_031843_094295_8EEFDEC6 X-CRM114-Status: GOOD ( 13.61 ) X-Spam-Score: -2.7 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pwm@vger.kernel.org, kernel@stlinux.com, ajitpal.singh@st.com, thierry.reding@gmail.com, Lee Jones , maxime.coquelin@st.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,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 Supply a PWM Capture call-back Op in order to pass back information obtained by running analysis on PWM a signal. This would normally (at least during testing) be called from the Sysfs routines with a view to printing out PWM Capture data which has been encoded into a string. Signed-off-by: Lee Jones --- drivers/pwm/core.c | 27 +++++++++++++++++++++++++++ include/linux/pwm.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index 7831bc6..160784d 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -494,6 +494,33 @@ unlock: EXPORT_SYMBOL_GPL(pwm_set_polarity); /** + * pwm_capture() - capture and report a PWM signal + * @pwm: PWM device + * @result: struct to fill with capture result + * @timeout_ms: time to wait, in milliseconds, before giving up on capture + * + * Returns: 0 on success or a negative error code on failure. + */ +int pwm_capture(struct pwm_device *pwm, struct pwm_capture *result, + unsigned int timeout_ms) +{ + int err; + + if (!pwm || !pwm->chip->ops) + return -EINVAL; + + if (!pwm->chip->ops->capture) + return -ENOSYS; + + mutex_lock(&pwm->lock); + err = pwm->chip->ops->capture(pwm->chip, pwm, result, timeout_ms); + mutex_unlock(&pwm->lock); + + return err; +} +EXPORT_SYMBOL_GPL(pwm_capture); + +/** * pwm_enable() - start a PWM output toggling * @pwm: PWM device * diff --git a/include/linux/pwm.h b/include/linux/pwm.h index cfc3ed4..49f9648 100644 --- a/include/linux/pwm.h +++ b/include/linux/pwm.h @@ -6,6 +6,7 @@ #include struct pwm_device; +struct pwm_capture; struct seq_file; #if IS_ENABLED(CONFIG_PWM) @@ -33,6 +34,13 @@ int pwm_enable(struct pwm_device *pwm); * pwm_disable - stop a PWM output toggling */ void pwm_disable(struct pwm_device *pwm); + +/* + * pwm_capture - capture and report a PWM signal + */ +int pwm_capture(struct pwm_device *pwm, + struct pwm_capture *result, + unsigned int timeout_ms); #else static inline struct pwm_device *pwm_request(int pwm_id, const char *label) { @@ -56,6 +64,13 @@ static inline int pwm_enable(struct pwm_device *pwm) static inline void pwm_disable(struct pwm_device *pwm) { } + +static inline int pwm_capture(struct pwm_device *pwm, + struct pwm_capture *result, + unsigned int timeout_ms) +{ + return -EINVAL; +} #endif struct pwm_chip; @@ -107,6 +122,16 @@ struct pwm_device { enum pwm_polarity polarity; }; +/** + * struct pwm_capture - PWM capture data + * @period: period of the PWM signal (in nanoseconds) + * @duty_cycle: duty cycle of the PWM signal (in nanoseconds) + */ +struct pwm_capture { + unsigned long long period; + unsigned long long duty_cycle; +}; + static inline bool pwm_is_enabled(const struct pwm_device *pwm) { return test_bit(PWMF_ENABLED, &pwm->flags); @@ -150,6 +175,7 @@ static inline enum pwm_polarity pwm_get_polarity(const struct pwm_device *pwm) * @free: optional hook for freeing a PWM * @config: configure duty cycles and period length for this PWM * @set_polarity: configure the polarity of this PWM + * @capture: capture and report PWM signal * @enable: enable PWM output toggling * @disable: disable PWM output toggling * @dbg_show: optional routine to show contents in debugfs @@ -162,6 +188,8 @@ struct pwm_ops { int duty_ns, int period_ns); int (*set_polarity)(struct pwm_chip *chip, struct pwm_device *pwm, enum pwm_polarity polarity); + int (*capture)(struct pwm_chip *chip, struct pwm_device *pwm, + struct pwm_capture *result, unsigned int timeout_ms); int (*enable)(struct pwm_chip *chip, struct pwm_device *pwm); void (*disable)(struct pwm_chip *chip, struct pwm_device *pwm); #ifdef CONFIG_DEBUG_FS