From patchwork Fri Apr 22 10:18:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 66421 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp631628qge; Fri, 22 Apr 2016 03:18:34 -0700 (PDT) X-Received: by 10.98.36.195 with SMTP id k64mr27259806pfk.88.1461320313442; Fri, 22 Apr 2016 03:18:33 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gc5si6951211pac.224.2016.04.22.03.18.33; Fri, 22 Apr 2016 03:18:33 -0700 (PDT) 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; dkim=pass header.i=@linaro.org; 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; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752517AbcDVKS1 (ORCPT + 29 others); Fri, 22 Apr 2016 06:18:27 -0400 Received: from mail-wm0-f53.google.com ([74.125.82.53]:38214 "EHLO mail-wm0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752377AbcDVKSY (ORCPT ); Fri, 22 Apr 2016 06:18:24 -0400 Received: by mail-wm0-f53.google.com with SMTP id u206so19367135wme.1 for ; Fri, 22 Apr 2016 03:18:23 -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=aqdIxXoy1E++5FtIJd0kwohJJQ6RS9EpdK+F+gHXG44=; b=KHgqPTwqIapOg/9Uw5h187b2XVIMAEfC1PAhzrlBZm/W2ACU0+r3l6u0fgGi3N5QH1 9dlFFxSPqCf4K9zJoq0YctH+d6zvTXTVuZdBnj1JzjXoVVDOXRtLcTq4G3hq5BkNkLaI dkRKX9i4VCU+JRdRFqbungWXytabEQQjrB9vM= 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=aqdIxXoy1E++5FtIJd0kwohJJQ6RS9EpdK+F+gHXG44=; b=WhmoK0iYI7SlAoV5jOPLUVfcWxHXRyUYAgNtdiCigNB9hXXGtNsdQxZHt2YAA2ReOe JlRgtGQVMEDpwunlba3RZg1wQchwVM/+L9VteVVa8oT+h3PlW4UsMDuWhWjdQVkCkhGu OvH47RwIBSK5JdJAdbL6JVatXXaGx1nLn5+Mcxw5g8oSNp1jjOzbrFtxkeSgXa9Uk4Ny ZOkd0kXIIrSOO0dznpGLj12pG4QRdBBopRAIDRh2GIC2EpgZdJfj/xidoP5JA93TQN3/ PZc/Lv92s+HJeYP75LZHf9Wwi3iNeatzlTCcJd4Ve5JgrVuHfk3pyhESFtzsZslJP/aY 2/UA== X-Gm-Message-State: AOPr4FVQuSSFRJtaEoRNEBV5DGIU6mGfgGokDoY0Yo8/n1nw2VGNWN47Oqfsv00420iRZZJl X-Received: by 10.28.63.148 with SMTP id m142mr2771827wma.85.1461320303255; Fri, 22 Apr 2016 03:18:23 -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.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Apr 2016 03:18:22 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: kernel@stlinux.com, maxime.coquelin@st.com, linux-pwm@vger.kernel.org, thierry.reding@gmail.com, ajitpal.singh@st.com, Lee Jones Subject: [[PATCH v2] 03/11] pwm: sysfs: Add PWM Capture support Date: Fri, 22 Apr 2016 11:18:07 +0100 Message-Id: <1461320295-20414-4-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> 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. To start a capture and read the result, simply read the file: $ cat $PWMCHIP/capture The output format is ":". Signed-off-by: Lee Jones --- drivers/pwm/sysfs.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) -- 2.8.0 diff --git a/drivers/pwm/sysfs.c b/drivers/pwm/sysfs.c index 9c90886..ca0d886 100644 --- a/drivers/pwm/sysfs.c +++ b/drivers/pwm/sysfs.c @@ -167,16 +167,33 @@ 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); + struct pwm_capture result; + int ret; + + ret = pwm_capture(pwm, &result, jiffies_to_msecs(HZ)); + if (ret) + return ret; + + return sprintf(buf, "%llu %llu\n", result.period, result.duty_cycle); +} + static DEVICE_ATTR_RW(period); static DEVICE_ATTR_RW(duty_cycle); static DEVICE_ATTR_RW(enable); static DEVICE_ATTR_RW(polarity); +static DEVICE_ATTR_RO(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);