From patchwork Tue Aug 5 15:12:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelio Colosimo X-Patchwork-Id: 376731 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id A18FB1400E4 for ; Wed, 6 Aug 2014 01:13:29 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755859AbaHEPM5 (ORCPT ); Tue, 5 Aug 2014 11:12:57 -0400 Received: from mail-wi0-f174.google.com ([209.85.212.174]:54980 "EHLO mail-wi0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755846AbaHEPMy (ORCPT ); Tue, 5 Aug 2014 11:12:54 -0400 Received: by mail-wi0-f174.google.com with SMTP id d1so7127417wiv.7 for ; Tue, 05 Aug 2014 08:12:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=i+EbX+Z5jT5m3qdiA9ZV7QEbotsX7MPOkovLJJG3iV8=; b=bYCB4EXGLO/AR/hIfmkAbLiTpjp7Mk4mVyVr5ng4kAuKrsAU3JWNvTo3wfv8bup30W 3x3b7QU2rThLI3pT3O66/tbCRzL28OeOqvuiNQVBhafFlqf7vjSEqjh+291IGD5BMTKb Nzl84CutdWXYjfR+LUnc0NrAdW12iLeKbdw9jFK1dkqTy/LeqY2zAAyEDJWE+kQWBWoD LwEq3Qc44wwUO3s7i+s7XOPa3uDjEL7CkXd0XlIqlkgUQ86WhVAGjCacqH0MV4D9si2O 0hqcCi70Nf3PhvcwUH6Itubo+SkPZkjPFTWUAvlnQLDD+oMxoJGsKMJGs7jOcrU23Kz+ 4uMA== X-Received: by 10.194.89.168 with SMTP id bp8mr6749438wjb.73.1407251571875; Tue, 05 Aug 2014 08:12:51 -0700 (PDT) Received: from localhost.localdomain (93-34-56-158.ip48.fastwebnet.it. [93.34.56.158]) by mx.google.com with ESMTPSA id l7sm4840137wjx.7.2014.08.05.08.12.50 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 05 Aug 2014 08:12:51 -0700 (PDT) From: Aurelio Colosimo X-Google-Original-From: Aurelio Colosimo To: Thierry Reding , Randy Dunlap Cc: linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Aurelio Colosimo Subject: [PATCH 2/2] pwm: new fields, max and resolution, added to sysfs Date: Tue, 5 Aug 2014 17:12:18 +0200 Message-Id: <1407251538-17566-3-git-send-email-aurelio@aureliocolosimo.it> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1407251538-17566-1-git-send-email-aurelio@aureliocolosimo.it> References: <1407251538-17566-1-git-send-email-aurelio@aureliocolosimo.it> Sender: linux-pwm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pwm@vger.kernel.org max is the maximum number of nanoseconds accepted as duty or period by a certain device. resolution is the minimum step actually handled by the hardware output. This couple of attributes permit users: 1) to know the capabilities of the pwm output; 2) to set a really supported value (by using of resolution, a precise computation is possible); 3) to avoid them setting invalid (too big) periods. A default value of resolution=1 and max=MAX_INT is provided in this patch, but driver maintainers are encouraged to properly fill the new fields in struct pwm_device. Signed-off-by: Aurelio Colosimo --- Documentation/pwm.txt | 7 +++++++ drivers/pwm/core.c | 2 ++ drivers/pwm/sysfs.c | 22 ++++++++++++++++++++++ include/linux/pwm.h | 2 ++ 4 files changed, 33 insertions(+) diff --git a/Documentation/pwm.txt b/Documentation/pwm.txt index ca895fd..dbb1a16 100644 --- a/Documentation/pwm.txt +++ b/Documentation/pwm.txt @@ -74,6 +74,13 @@ period - The total period of the PWM signal (read/write). duty_cycle - The active time of the PWM signal (read/write). Value is in nanoseconds and must be less than the period. +resolution - The resolution of duty_cycle and period. + Value is in nanoseconds and is the min step period and duty can + change. + +max - The max value for period. + Value is in nanoseconds. + polarity - Changes the polarity of the PWM signal (read/write). Writes to this property only work if the PWM chip supports changing the polarity. The polarity can only be changed if the PWM is not diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index 4b66bf0..d973ed7 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -259,6 +259,8 @@ int pwmchip_add(struct pwm_chip *chip) pwm->chip = chip; pwm->pwm = chip->base + i; pwm->hwpwm = i; + pwm->resolution = 1; + pwm->max = UINT_MAX; radix_tree_insert(&pwm_tree, pwm->pwm, pwm); } diff --git a/drivers/pwm/sysfs.c b/drivers/pwm/sysfs.c index c1d6064..1bb77e2 100644 --- a/drivers/pwm/sysfs.c +++ b/drivers/pwm/sysfs.c @@ -157,16 +157,38 @@ static ssize_t pwm_polarity_store(struct device *child, return ret ? : size; } +static ssize_t pwm_resolution_show(struct device *child, + struct device_attribute *attr, + char *buf) +{ + const struct pwm_device *pwm = child_to_pwm_device(child); + + return sprintf(buf, "%u\n", pwm->resolution); +} + +static ssize_t pwm_max_show(struct device *child, + struct device_attribute *attr, + char *buf) +{ + const struct pwm_device *pwm = child_to_pwm_device(child); + + return sprintf(buf, "%u\n", pwm->max); +} + static DEVICE_ATTR(period, 0644, pwm_period_show, pwm_period_store); static DEVICE_ATTR(duty_cycle, 0644, pwm_duty_cycle_show, pwm_duty_cycle_store); static DEVICE_ATTR(enable, 0644, pwm_enable_show, pwm_enable_store); static DEVICE_ATTR(polarity, 0644, pwm_polarity_show, pwm_polarity_store); +static DEVICE_ATTR(resolution, 0444, pwm_resolution_show, NULL); +static DEVICE_ATTR(max, 0444, pwm_max_show, NULL); static struct attribute *pwm_attrs[] = { &dev_attr_period.attr, &dev_attr_duty_cycle.attr, &dev_attr_enable.attr, &dev_attr_polarity.attr, + &dev_attr_resolution.attr, + &dev_attr_max.attr, NULL }; ATTRIBUTE_GROUPS(pwm); diff --git a/include/linux/pwm.h b/include/linux/pwm.h index 9bacf35..c4cc794 100644 --- a/include/linux/pwm.h +++ b/include/linux/pwm.h @@ -90,6 +90,8 @@ struct pwm_device { unsigned int period; /* in nanoseconds */ unsigned int duty_cycle; /* in nanoseconds */ + unsigned int resolution; /* in nanoseconds */ + unsigned int max; /* in nanoseconds */ enum pwm_polarity polarity; };