All of lore.kernel.org
 help / color / mirror / Atom feed
From: Janne Kanniainen <janne.kanniainen@gmail.com>
To: johan@kernel.org
Cc: cooloney@gmail.com, jkosina@suse.cz, greg@kroah.com,
	bjorn@mork.no, linux-kernel@vger.kernel.org,
	linux-leds@vger.kernel.org, linux-usb@vger.kernel.org,
	linux-input@vger.kernel.org,
	Janne Kanniainen <janne.kanniainen@gmail.com>
Subject: [PATCH 2/2 v5] HID: leds: move led_mode attribute to led-class devices in MSI GT683R driver
Date: Wed,  2 Jul 2014 20:37:59 +0300	[thread overview]
Message-ID: <1404322679-19521-1-git-send-email-janne.kanniainen@gmail.com> (raw)
In-Reply-To: <20140701201627.GA30605@localhost>

Move led_mode attribute from HID device to led-class devices. This will also fix race condition by using attribute-groups.

Signed-off-by: Janne Kanniainen <janne.kanniainen@gmail.com>
---

Changes in v3:
	- Style fixes
	- Rename sysfs-class-hid-driver-gt683r to sysfs-class-leds-driver-gt683r

Changes in v4:
	- Rename sysfs-class-leds-driver-gt683r to sysfs-class-leds-gt683r
	- Change "What: " to /sys/class/leds/<led>/gt683r/mode
	- Change .name from gt683r_led to gt683r

Changes in v5:
	- Move mode attribute to gt683r/mode

 .../ABI/testing/sysfs-class-hid-driver-gt683r      | 14 ---------
 Documentation/ABI/testing/sysfs-class-leds-gt683r  | 16 ++++++++++
 drivers/hid/hid-gt683r.c                           | 36 ++++++++++++++--------
 3 files changed, 40 insertions(+), 26 deletions(-)
 delete mode 100644 Documentation/ABI/testing/sysfs-class-hid-driver-gt683r
 create mode 100644 Documentation/ABI/testing/sysfs-class-leds-gt683r

diff --git a/Documentation/ABI/testing/sysfs-class-hid-driver-gt683r b/Documentation/ABI/testing/sysfs-class-hid-driver-gt683r
deleted file mode 100644
index 317e9d5..0000000
--- a/Documentation/ABI/testing/sysfs-class-hid-driver-gt683r
+++ /dev/null
@@ -1,14 +0,0 @@
-What:		/sys/class/hidraw/<hidraw>/device/leds_mode
-Date:		Jun 2014
-KernelVersion:	3.17
-Contact:	Janne Kanniainen <janne.kanniainen@gmail.com>
-Description:
-		Set the mode of LEDs
-
-		0 - normal
-		1 - audio
-		2 - breathing
-
-		Normal: LEDs are fully on when enabled
-		Audio:  LEDs brightness depends on sound level
-		Breathing: LEDs brightness varies at human breathing rate
\ No newline at end of file
diff --git a/Documentation/ABI/testing/sysfs-class-leds-gt683r b/Documentation/ABI/testing/sysfs-class-leds-gt683r
new file mode 100644
index 0000000..e4fae60
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-class-leds-gt683r
@@ -0,0 +1,16 @@
+What:		/sys/class/leds/<led>/gt683r/mode
+Date:		Jun 2014
+KernelVersion:	3.17
+Contact:	Janne Kanniainen <janne.kanniainen@gmail.com>
+Description:
+		Set the mode of LEDs. You should notice that changing the mode
+		of one LED will update the mode of its two sibling devices as
+		well.
+
+		0 - normal
+		1 - audio
+		2 - breathing
+
+		Normal: LEDs are fully on when enabled
+		Audio:  LEDs brightness depends on sound level
+		Breathing: LEDs brightness varies at human breathing rate
\ No newline at end of file
diff --git a/drivers/hid/hid-gt683r.c b/drivers/hid/hid-gt683r.c
index 073bd80..0d6f135 100644
--- a/drivers/hid/hid-gt683r.c
+++ b/drivers/hid/hid-gt683r.c
@@ -84,12 +84,13 @@ static void gt683r_brightness_set(struct led_classdev *led_cdev,
 	}
 }
 
-static ssize_t leds_mode_show(struct device *dev,
+static ssize_t mode_show(struct device *dev,
 				struct device_attribute *attr,
 				char *buf)
 {
 	u8 sysfs_mode;
-	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
+	struct hid_device *hdev = container_of(dev->parent,
+					struct hid_device, dev);
 	struct gt683r_led *led = hid_get_drvdata(hdev);
 
 	if (led->mode == GT683R_LED_NORMAL)
@@ -102,12 +103,13 @@ static ssize_t leds_mode_show(struct device *dev,
 	return scnprintf(buf, PAGE_SIZE, "%u\n", sysfs_mode);
 }
 
-static ssize_t leds_mode_store(struct device *dev,
+static ssize_t mode_store(struct device *dev,
 				struct device_attribute *attr,
 				const char *buf, size_t count)
 {
 	u8 sysfs_mode;
-	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
+	struct hid_device *hdev = container_of(dev->parent,
+					struct hid_device, dev);
 	struct gt683r_led *led = hid_get_drvdata(hdev);
 
 
@@ -212,7 +214,22 @@ fail:
 	mutex_unlock(&led->lock);
 }
 
-static DEVICE_ATTR_RW(leds_mode);
+static DEVICE_ATTR_RW(mode);
+
+static struct attribute *gt683r_led_attrs[] = {
+	&dev_attr_mode.attr,
+	NULL
+};
+
+static const struct attribute_group gt683r_led_group = {
+	.name = "gt683r",
+	.attrs = gt683r_led_attrs,
+};
+
+static const struct attribute_group *gt683r_led_groups[] = {
+	&gt683r_led_group,
+	NULL
+};
 
 static int gt683r_led_probe(struct hid_device *hdev,
 			const struct hid_device_id *id)
@@ -261,6 +278,8 @@ static int gt683r_led_probe(struct hid_device *hdev,
 		led->led_devs[i].name = name;
 		led->led_devs[i].max_brightness = 1;
 		led->led_devs[i].brightness_set = gt683r_brightness_set;
+		led->led_devs[i].groups = gt683r_led_groups;
+
 		ret = led_classdev_register(&hdev->dev, &led->led_devs[i]);
 		if (ret) {
 			hid_err(hdev, "could not register led device\n");
@@ -268,12 +287,6 @@ static int gt683r_led_probe(struct hid_device *hdev,
 		}
 	}
 
-	ret = device_create_file(&led->hdev->dev, &dev_attr_leds_mode);
-	if (ret) {
-		hid_err(hdev, "could not make mode attribute file\n");
-		goto fail;
-	}
-
 	return 0;
 
 fail:
@@ -288,7 +301,6 @@ static void gt683r_led_remove(struct hid_device *hdev)
 	int i;
 	struct gt683r_led *led = hid_get_drvdata(hdev);
 
-	device_remove_file(&hdev->dev, &dev_attr_leds_mode);
 	for (i = 0; i < GT683R_LED_COUNT; i++)
 		led_classdev_unregister(&led->led_devs[i]);
 	flush_work(&led->work);
-- 
1.9.2

  reply	other threads:[~2014-07-02 17:38 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-05 21:29 [PATCH v2] leds: USB: Add support for MSI GT683R led panels Janne Kanniainen
2014-06-06  9:47 ` Johan Hovold
2014-06-07 10:12   ` Janne Kanniainen
2014-06-09 11:42     ` Johan Hovold
2014-06-10 21:10       ` Janne Kanniainen
2014-06-10 21:21         ` [PATCH v3] leds: USB: HID: " Janne Kanniainen
2014-06-11 11:25           ` Jiri Kosina
2014-06-11 14:06             ` Johan Hovold
     [not found]           ` <1402435299-16410-1-git-send-email-janne.kanniainen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-06-11 14:05             ` Johan Hovold
2014-06-11 14:05               ` Johan Hovold
2014-06-11 15:30               ` Johan Hovold
2014-06-11 17:34               ` Johan Hovold
2014-06-11 22:48                 ` [PATCH v4] " Janne Kanniainen
2014-06-12  9:06                   ` Johan Hovold
2014-06-12 20:34                     ` [PATCH v5] " Janne Kanniainen
2014-06-13  7:54                       ` Johan Hovold
2014-06-13 17:19                         ` Janne Kanniainen
2014-06-15 14:59                           ` Janne Kanniainen
2014-06-16  7:39                             ` Johan Hovold
2014-06-16 17:23                         ` [PATCH v6] " Janne Kanniainen
2014-06-16 22:01                           ` Janne Kanniainen
2014-06-17 13:46                             ` Johan Hovold
2014-06-17 16:41                               ` [PATCH v8] " Janne Kanniainen
     [not found]                                 ` <1403023304-7953-1-git-send-email-janne.kanniainen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-06-18  7:39                                   ` Johan Hovold
2014-06-18  7:39                                     ` Johan Hovold
2014-06-18 16:05                                     ` [PATCH v9] " Janne Kanniainen
     [not found]                                       ` <1403107502-14106-1-git-send-email-janne.kanniainen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-06-18 16:11                                         ` Johan Hovold
2014-06-18 16:11                                           ` Johan Hovold
2014-06-18 18:41                                           ` Janne Kanniainen
2014-06-18 18:46                                             ` Johan Hovold
2014-06-18 22:10                                           ` Jiri Kosina
2014-06-23 14:35                                       ` Oliver Neukum
2014-06-23 14:42                                         ` Johan Hovold
2014-06-23 16:17                                           ` Greg KH
2014-06-23 17:16                                             ` [PATCH v10] " Janne Kanniainen
2014-06-23 17:27                                               ` Johan Hovold
     [not found]                                               ` <1403543808-8228-1-git-send-email-janne.kanniainen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-06-23 18:23                                                 ` Greg KH
2014-06-23 18:23                                                   ` Greg KH
2014-06-23 18:24                                                   ` Greg KH
2014-06-23 19:31                                                     ` Johan Hovold
2014-06-23 19:40                                                       ` Greg KH
2014-06-23 19:52                                                         ` Johan Hovold
2014-06-23 20:24                                                           ` Greg KH
2014-06-23 20:44                                                             ` Johan Hovold
2014-06-24 13:10                                                               ` Bjørn Mork
2014-06-24 13:10                                                                 ` Bjørn Mork
2014-06-24 14:50                                                                 ` Johan Hovold
2014-06-24 19:38                                                                   ` [PATCH 1/2] HID: leds: fix race condition in MSI GT683R driver Janne Kanniainen
2014-06-24 19:38                                                                     ` [PATCH 2/2] HID: leds: move led_mode attribute to led-class devices " Janne Kanniainen
2014-06-24 19:56                                                                       ` Greg KH
2014-06-25 11:55                                                                         ` Johan Hovold
2014-06-25 15:59                                                                           ` [PATCH 2/2 v2] HID: leds: Use attribute-groups " Janne Kanniainen
2014-06-25 17:41                                                                             ` Johan Hovold
2014-06-25 18:13                                                                               ` [PATCH 2/2 v3] HID: leds: move led_mode attribute to led-class devices " Janne Kanniainen
2014-06-30 10:39                                                                                 ` Johan Hovold
2014-07-01 17:50                                                                                   ` [PATCH 2/2 v4] " Janne Kanniainen
2014-07-01 20:16                                                                                     ` Johan Hovold
2014-07-02 17:37                                                                                       ` Janne Kanniainen [this message]
2014-07-03  8:28                                                                                         ` [PATCH 2/2 v5] " Johan Hovold
2014-07-03 17:17                                                                                           ` [PATCH 1/2 v6] HID: gt683r: fix race condition Janne Kanniainen
2014-07-03 17:17                                                                                             ` [PATCH 2/2 v6] HID: gt683r: move mode attribute to led-class devices Janne Kanniainen
2014-07-03 17:40                                                                                               ` Johan Hovold
2014-07-03 17:40                                                                                                 ` Johan Hovold
2014-07-03 18:17                                                                                                 ` Bryan Wu
2014-07-03 18:28                                                                                                   ` Janne Kanniainen
2014-07-03 17:34                                                                                             ` [PATCH 1/2 v6] HID: gt683r: fix race condition Johan Hovold
2014-07-03 17:34                                                                                               ` Johan Hovold
2014-07-03 18:13                                                                                               ` Bryan Wu
2014-06-25 19:09                                                                               ` [PATCH 2/2 v2] HID: leds: Use attribute-groups in MSI GT683R driver Jiri Kosina
2014-06-25 22:55                                                                                 ` Bryan Wu
2014-06-30 10:47                                                                                   ` Johan Hovold
2014-06-30 11:33                                                                                     ` Jiri Kosina
2014-06-30 23:17                                                                                       ` Bryan Wu
2014-07-01  8:48                                                                                         ` Johan Hovold
2014-07-01 15:48                                                                                           ` Bryan Wu
2014-07-01 17:53                                                                                             ` Janne Kanniainen
2014-07-02  8:56                                                                                             ` Jiri Kosina
2014-06-23 16:20                                           ` [PATCH v9] leds: USB: HID: Add support for MSI GT683R led panels Janne Kanniainen
2014-06-14 22:42                       ` [PATCH v5] " Pavel Machek
2014-06-14 23:23                         ` Janne Kanniainen
2014-06-16  7:45                           ` Johan Hovold

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1404322679-19521-1-git-send-email-janne.kanniainen@gmail.com \
    --to=janne.kanniainen@gmail.com \
    --cc=bjorn@mork.no \
    --cc=cooloney@gmail.com \
    --cc=greg@kroah.com \
    --cc=jkosina@suse.cz \
    --cc=johan@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.