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: 66430 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp632260qge; Fri, 22 Apr 2016 03:20:05 -0700 (PDT) X-Received: by 10.98.109.193 with SMTP id i184mr26668084pfc.81.1461320403109; Fri, 22 Apr 2016 03:20:03 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id qd3si6971083pab.208.2016.04.22.03.20.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Apr 2016 03:20:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org 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-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:400c:c09:0:0:0:235 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 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+patch=linaro.org@lists.infradead.org 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(+) -- 2.8.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel 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