From patchwork Mon Jul 18 22:14:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hsu X-Patchwork-Id: 649784 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 3rtct951WSz9s5J for ; Tue, 19 Jul 2016 08:14:57 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b=A11aPvWj; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751451AbcGRWO4 (ORCPT ); Mon, 18 Jul 2016 18:14:56 -0400 Received: from mail-pa0-f45.google.com ([209.85.220.45]:34675 "EHLO mail-pa0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751041AbcGRWOz (ORCPT ); Mon, 18 Jul 2016 18:14:55 -0400 Received: by mail-pa0-f45.google.com with SMTP id fi15so146079pac.1 for ; Mon, 18 Jul 2016 15:14:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=98QO/oK6gCnmr9RJgPMDheROhCnnLfbuXyczAwqjqSs=; b=A11aPvWjgXgKmWwDTDRP8BnMhep8VG0sAkfywLfaStmqed+XITa0bn/qyavvk1G9Vu OhVd59XUFTsy4uFEcKZX1gUzPv4HLxn4Z6IkzSTCtqigl3SS73Mpmr/klC1QGywbPTMi M1dwnzp3np/iXek6pyes5uKrQp1fVmpa1OsuZEoK2ET0JZ+GaCGGvCctpFVufslo9+aL lNGIeTPjwN5SNHawTYHXVqan2qDDPduSvQwUhyTsBFOQRnTUGszqLJAHgnH8X8Oc514p zkobHHe45JHt2qZ6t6Iq2C3zGdH+KZRDk+JM1M5nScXpME/1vUC/Hx0AmiSd/jGlXdyM b3NA== 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; bh=98QO/oK6gCnmr9RJgPMDheROhCnnLfbuXyczAwqjqSs=; b=IulWH7tXM5vW60wCV0pO3yOC/ODpejIvrd3Ja10OZQ3Ln3DO97NG7R4fhwEOPDPKUI h2yRhn9TjE46Iommf8G6jGpSJXUm8ZkbDr93zeuoTQ/BsjVRUcFqLMgrqIxv32k7GANM Zh9ioHACq0m4zvAeFgSY+3MMAzZznMxbtZKCkhtdEuEM49FvqAXtt+3ziIvjbmsvCW8r BrjKgM9We472nBviw8HmD8f2CGyf2qoHwVF781TL7qrnTX2TKj1dZQ/ZsLcVIl8sjZvi JV6nLAaV2HG6A2p/SSAQPGh726rQK2g5TwJ7WmwN95cpaEi2Y7nqlVyf/gH1/tlyAAMY +kkw== X-Gm-Message-State: ALyK8tKROvGWUCCPCX63p5KC12fwTTi4qKUbONm0P/G7a7vMjM/DaO4PKHG6jvz/+RMVNPE2 X-Received: by 10.66.254.39 with SMTP id af7mr59217599pad.37.1468880094870; Mon, 18 Jul 2016 15:14:54 -0700 (PDT) Received: from localhost ([2620:0:1000:6509:dc78:5625:b83e:91ae]) by smtp.gmail.com with ESMTPSA id c64sm7250500pfg.35.2016.07.18.15.14.54 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 18 Jul 2016 15:14:54 -0700 (PDT) From: David Hsu To: thierry.reding@gmail.com Cc: gregkh@linuxfoundation.org, sspatil@google.com, linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, davidhsu@google.com Subject: [PATCH v2] pwm: Create device class for pwm channels Date: Mon, 18 Jul 2016 15:14:50 -0700 Message-Id: <1468880090-46076-1-git-send-email-davidhsu@google.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 Sender: linux-pwm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pwm@vger.kernel.org Pwm channels don't send uevents when exported, this change adds the channels to a pwm class and set their device type to pwm_channel so uevents are sent. To do this properly, the device names need to change to uniquely identify a channel. This change is from pwmN to pwmchipM:N Signed-off-by: David Hsu --- v2: Use parent name instead of chip->base for channel naming. Documentation/pwm.txt | 6 ++++-- drivers/pwm/sysfs.c | 18 +++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Documentation/pwm.txt b/Documentation/pwm.txt index 789b27c..8453435 100644 --- a/Documentation/pwm.txt +++ b/Documentation/pwm.txt @@ -80,9 +80,11 @@ unexport - Unexports a PWM channel from sysfs (write-only). The PWM channels are numbered using a per-chip index from 0 to npwm-1. -When a PWM channel is exported a pwmX directory will be created in the +When a PWM channel is exported a pwmchipN:X directory will be created in the pwmchipN directory it is associated with, where X is the number of the -channel that was exported. The following properties will then be available: +channel that was exported. It will also be exposed at /sys/class/pwm/ and +can be identified by the pwm_channel device type. +The following properties will then be available: period - The total period of the PWM signal (read/write). Value is in nanoseconds and is the sum of the active and inactive diff --git a/drivers/pwm/sysfs.c b/drivers/pwm/sysfs.c index 01695d4..cb2b376 100644 --- a/drivers/pwm/sysfs.c +++ b/drivers/pwm/sysfs.c @@ -23,6 +23,8 @@ #include #include +static struct class pwm_class; + struct pwm_export { struct device child; struct pwm_device *pwm; @@ -222,6 +224,10 @@ static struct attribute *pwm_attrs[] = { }; ATTRIBUTE_GROUPS(pwm); +static const struct device_type pwm_channel_type = { + .name = "pwm_channel", +}; + static void pwm_export_release(struct device *child) { struct pwm_export *export = child_to_pwm_export(child); @@ -248,9 +254,11 @@ static int pwm_export_child(struct device *parent, struct pwm_device *pwm) export->child.release = pwm_export_release; export->child.parent = parent; + export->child.type = &pwm_channel_type; export->child.devt = MKDEV(0, 0); + export->child.class = &pwm_class; export->child.groups = pwm_groups; - dev_set_name(&export->child, "pwm%u", pwm->hwpwm); + dev_set_name(&export->child, "%s:%u", dev_name(parent), pwm->hwpwm); ret = device_register(&export->child); if (ret) { @@ -355,7 +363,6 @@ ATTRIBUTE_GROUPS(pwm_chip); static struct class pwm_class = { .name = "pwm", .owner = THIS_MODULE, - .dev_groups = pwm_chip_groups, }; static int pwmchip_sysfs_match(struct device *parent, const void *data) @@ -368,14 +375,15 @@ void pwmchip_sysfs_export(struct pwm_chip *chip) struct device *parent; /* - * If device_create() fails the pwm_chip is still usable by + * If device_create_with_groups() fails the pwm_chip is still usable by * the kernel its just not exported. */ - parent = device_create(&pwm_class, chip->dev, MKDEV(0, 0), chip, + parent = device_create_with_groups(&pwm_class, chip->dev, MKDEV(0, 0), + chip, pwm_chip_groups, "pwmchip%d", chip->base); if (IS_ERR(parent)) { dev_warn(chip->dev, - "device_create failed for pwm_chip sysfs export\n"); + "device_create_with_groups failed for pwm_chip sysfs export\n"); } }