From patchwork Wed Jun 8 09:21:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 69625 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp2391231qgf; Wed, 8 Jun 2016 02:25:58 -0700 (PDT) X-Received: by 10.36.111.76 with SMTP id x73mr10604195itb.59.1465377958466; Wed, 08 Jun 2016 02:25:58 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id i20si441813pfd.165.2016.06.08.02.25.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Jun 2016 02:25:58 -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 1bAZiz-0001iO-F1; Wed, 08 Jun 2016 09:24:33 +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 1bAZgO-0007E2-I1 for linux-arm-kernel@lists.infradead.org; Wed, 08 Jun 2016 09:21:54 +0000 Received: by mail-wm0-x235.google.com with SMTP id v199so54375329wmv.0 for ; Wed, 08 Jun 2016 02:21:34 -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=cD5Xr8K+QDVbOKyXOkOzjZoNJUwnRZm8bLd0xDWyBwk=; b=Gyae0iG32Es4zMd309V7AGfxCm9EuBeRS4imcFz1uwwzDn6GDB6DTgoTU+kwz6Wo0d 09XNUtbpsQefvxGYpGd/unUcP0qlXfx88VkNcCB2CEDDhcY36JLJ4W3TlxMJ0UIjtDIw 5izR+hAD2PV4nYqeRnXO8O9S7fiAzfDoOL/yM= 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=cD5Xr8K+QDVbOKyXOkOzjZoNJUwnRZm8bLd0xDWyBwk=; b=Q5z0EgB0rSnuMOBYdQwW8AdmJcW0lOGd+f9lIc3wqu0dWRy1yVrQfy3tn2XxStOzVT qugGfeY/hWLyU4jABqO7IK7rs98dzSraEe+JuhDvzhQG/bBgRzkhVEYz5jHg5L8s0nWI 5xkQxK8WvvLf1oNohQEnLBS6drQS/V08uiRBvunf7C/PNSc/G6se/TrNtzuN/KVnohmI g4+xckQD64IrDIbET9OwqzyBBanrsL4CgSHdJk4zkEMb6qr8NZujjxZ1KFqcSfsG0QOo qpTb3Xc6rt2zTH2p3aGUuEH6NkbaAHFQlpS6RbyVwSDogPzygFLPG1eZTdRgioLHEHYP P1Vg== X-Gm-Message-State: ALyK8tJkLPpwwYsRwpnKGh/QD+6IQVTJqyeBDUwR97b9AmswzEtWAYaZtMVyfnUgdi+GTveH X-Received: by 10.28.168.71 with SMTP id r68mr6588948wme.44.1465377692998; Wed, 08 Jun 2016 02:21:32 -0700 (PDT) Received: from localhost.localdomain (host81-129-171-215.range81-129.btcentralplus.com. [81.129.171.215]) by smtp.gmail.com with ESMTPSA id g192sm23694494wme.15.2016.06.08.02.21.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Jun 2016 02:21:32 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 08/20] pwm: Add PWM Capture support Date: Wed, 8 Jun 2016 10:21:23 +0100 Message-Id: <20160608092135.21184-9-lee.jones@linaro.org> X-Mailer: git-send-email 2.8.3 In-Reply-To: <20160608092135.21184-1-lee.jones@linaro.org> References: <20160608092135.21184-1-lee.jones@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160608_022152_864329_4A644837 X-CRM114-Status: GOOD ( 16.06 ) 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_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 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 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, devicetree@vger.kernel.org, patrice.chotard@st.com, robh+dt@kernel.org, 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 | 25 +++++++++++++++++++++++++ 2 files changed, 52 insertions(+) -- 2.8.3 _______________________________________________ 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 dba3843..4678de6 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -525,6 +525,33 @@ int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state) EXPORT_SYMBOL_GPL(pwm_apply_state); /** + * 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_adjust_config() - adjust the current PWM config to the PWM arguments * @pwm: PWM device * diff --git a/include/linux/pwm.h b/include/linux/pwm.h index 17018f3..13cac27 100644 --- a/include/linux/pwm.h +++ b/include/linux/pwm.h @@ -5,7 +5,9 @@ #include #include +struct pwm_capture; struct seq_file; + struct pwm_chip; /** @@ -153,6 +155,7 @@ static inline void pwm_get_args(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 * @apply: atomically apply a new PWM config. The state argument @@ -172,6 +175,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); int (*apply)(struct pwm_chip *chip, struct pwm_device *pwm, @@ -212,6 +217,16 @@ struct pwm_chip { bool can_sleep; }; +/** + * 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; +}; + #if IS_ENABLED(CONFIG_PWM) /* PWM user APIs */ struct pwm_device *pwm_request(int pwm_id, const char *label); @@ -322,6 +337,9 @@ static inline void pwm_disable(struct pwm_device *pwm) /* PWM provider APIs */ +int pwm_capture(struct pwm_device *pwm, + struct pwm_capture *result, + unsigned int timeout_ms); int pwm_set_chip_data(struct pwm_device *pwm, void *data); void *pwm_get_chip_data(struct pwm_device *pwm); @@ -373,6 +391,13 @@ static inline int pwm_config(struct pwm_device *pwm, int duty_ns, return -EINVAL; } +static inline int pwm_capture(struct pwm_device *pwm, + struct pwm_capture *result, + unsigned int timeout_ms) +{ + return -EINVAL; +} + static inline int pwm_set_polarity(struct pwm_device *pwm, enum pwm_polarity polarity) {