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: 8908821 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 057269F1D3 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 068E32024F 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 35BF6201EF 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 1atYB2-0000Y0-Jl; Fri, 22 Apr 2016 10:19:08 +0000 Received: from mail-wm0-x22f.google.com ([2a00:1450:400c:c09::22f]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1atYAe-00007b-TU for linux-arm-kernel@lists.infradead.org; Fri, 22 Apr 2016 10:18:45 +0000 Received: by mail-wm0-x22f.google.com with SMTP id n3so19450852wmn.0 for ; Fri, 22 Apr 2016 03:18:24 -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=MZW+06E4b2gUHmLlJl3nT9eFjdP90MgpynKiKdCnAukpynShgg16H+d6kUPuPuSWIE /d7JSPd9dlpmh9CYzY+fOEr5yjvzpQdwz95sn8cLNKtM6o6b/HS4utqo08fN1ik/qCjl 8MI1d4LZndq/mLnDagfdiw5fMlWrb12QC2cMjAMijMkhu8noPHb2c9kVSodxHgMEpSYp yB/Eafdt+cyIOR/JGBBIfFyw21cKkFCaY28mZhIz0xHSPA7i5qCLk+8oTlMGbyG1JdIn HMNIF7bLSwh17IzQ6ZsC6ehM980Jx2rBYyPZZCHDiq7/wCC1BzrnxGF+6H6mIBPXgZUa 6mjg== X-Gm-Message-State: AOPr4FU2IQb/s9KMitg3jPhH1PJ8SHyuPEba9MI9FKFhd5PjGfjd1ZAJNGedlBETxtYzFXTA 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160422_031845_154121_CC1ABF07 X-CRM114-Status: GOOD ( 10.26 ) 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 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(+) 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);