From patchwork Wed Feb 10 13:02:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 61647 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp2629923lbl; Wed, 10 Feb 2016 05:04:46 -0800 (PST) X-Received: by 10.98.16.12 with SMTP id y12mr58488351pfi.6.1455109486628; Wed, 10 Feb 2016 05:04:46 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id wg9si4953949pab.242.2016.02.10.05.04.46; Wed, 10 Feb 2016 05:04:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dkim=pass header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751422AbcBJNEl (ORCPT + 30 others); Wed, 10 Feb 2016 08:04:41 -0500 Received: from mail-wm0-f53.google.com ([74.125.82.53]:35952 "EHLO mail-wm0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751308AbcBJNEi (ORCPT ); Wed, 10 Feb 2016 08:04:38 -0500 Received: by mail-wm0-f53.google.com with SMTP id p63so27517973wmp.1 for ; Wed, 10 Feb 2016 05:04:37 -0800 (PST) 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=cyI57F19pIhwZcq5ccrYrB+HUgtxU3ItyRp6MeQ2xbE=; b=TXSlhkkNlz6N3vEM8dPhgN4LYP+ufFZuYySy/1lqmaiP5XY9C5yT44jTtO6n9P2y9q mUWhlOX////gA2lbTTIt68JykKD7s/55jCGFbEUtHUmXNRQ/zHfY0j123livJV4isqgM emmt/x9tk9WQfvYSJkWwEMMGrgaq13zmUDKhQ= 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=cyI57F19pIhwZcq5ccrYrB+HUgtxU3ItyRp6MeQ2xbE=; b=ACR7IlRHUUIbTvScsrLq/Wk1AMC9wpUna8XqFZbOy9G0TqR/y2Q7W15HAsykNQoIX2 MeH0nxA/kZHojpdd1i0yZH2sZ2G2VDbtfLADdUrVlEYVGFzRzy8y6K0s6zxjjk+7Axru kxsHZ52oOS9EKjrN9zjBNfl/MZ6eaThZP+UqgkWVJL3RIwqjivhnh3dAZfmOOJDoKltl nFA80kH1qloDeWwLx5qqmGS2YMItRQICUGuBaGy+i+OBEDG0fmXD112WjQ18geoeMUU3 SksjdtpP1SKp0TdTrz2qk7x0kixLnD0CNicxaPu3gXHlCnn5fIrdPKocBiKaxyc92Oxe 9aow== X-Gm-Message-State: AG10YOSuaWoz+mv4sK4Aw6UwJIYaNaTnEGazhWm3MKfuQRBcq9epUQkPUCke0swau/8PkAqn X-Received: by 10.194.110.230 with SMTP id id6mr37869079wjb.67.1455109477021; Wed, 10 Feb 2016 05:04:37 -0800 (PST) Received: from localhost.localdomain (host81-129-170-149.range81-129.btcentralplus.com. [81.129.170.149]) by smtp.gmail.com with ESMTPSA id q75sm22429319wmd.6.2016.02.10.05.04.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 10 Feb 2016 05:04:36 -0800 (PST) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, thierry.reding@gmail.com, linux-pwm@vger.kernel.org, ajitpal.singh@st.com Cc: kernel@stlinux.com, maxime.coquelin@st.com, Lee Jones Subject: [PATCH 02/11] pwm: sysfs: Add PWM Capture support Date: Wed, 10 Feb 2016 13:02:19 +0000 Message-Id: <1455109348-32767-3-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1455109348-32767-1-git-send-email-lee.jones@linaro.org> References: <1455109348-32767-1-git-send-email-lee.jones@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Allow a user to read PWM Capture results from /sysfs. First, the user must tell PWM Capture which channel they wish to read from: $ echo 2 > $PWMCHIP/capture To start a capture and read the result, simply read the file: $ cat $PWMCHIP/capture The output format is left to the device. Signed-off-by: Lee Jones --- drivers/pwm/sysfs.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) -- 1.9.1 diff --git a/drivers/pwm/sysfs.c b/drivers/pwm/sysfs.c index 9c90886..3572ef4 100644 --- a/drivers/pwm/sysfs.c +++ b/drivers/pwm/sysfs.c @@ -23,6 +23,8 @@ #include #include +static int capture_channel; + struct pwm_export { struct device child; struct pwm_device *pwm; @@ -167,16 +169,42 @@ static ssize_t polarity_store(struct device *child, return ret ? : size; } +static ssize_t capture_show(struct device *child, + struct device_attribute *attr, + char *buf) +{ + struct pwm_device *pwm = child_to_pwm_device(child); + + return pwm_capture(pwm, capture_channel, buf); +} + +static ssize_t capture_store(struct device *child, + struct device_attribute *attr, + const char *buf, size_t size) +{ + int val, ret; + + ret = kstrtoint(buf, 0, &val); + if (ret) + return ret; + + capture_channel = val; + + return size; +} + static DEVICE_ATTR_RW(period); static DEVICE_ATTR_RW(duty_cycle); static DEVICE_ATTR_RW(enable); static DEVICE_ATTR_RW(polarity); +static DEVICE_ATTR_RW(capture); static struct attribute *pwm_attrs[] = { &dev_attr_period.attr, &dev_attr_duty_cycle.attr, &dev_attr_enable.attr, &dev_attr_polarity.attr, + &dev_attr_capture.attr, NULL }; ATTRIBUTE_GROUPS(pwm);