[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210819025053.222710-14-arequipeno@gmail.com>
Date: Wed, 18 Aug 2021 21:50:48 -0500
From: Ian Pilcher <arequipeno@...il.com>
To: linux-block@...r.kernel.org, linux-leds@...r.kernel.org
Cc: axboe@...nel.dk, pavel@....cz, kabel@...nel.org,
linux-kernel@...r.kernel.org, kernelnewbies@...nelnewbies.org
Subject: [RFC PATCH v3 13/18] ledtrig-blkdev: Add blink_time & interval sysfs attributes
/sys/class/leds/<led>/blink_time controls - per-LED blink duration
/sys/class/leds/<led>/interval - global frequency with which devices
are checked for activity and LEDs are blinked
Enforce 25 millisecond minimum for both attributes
Signed-off-by: Ian Pilcher <arequipeno@...il.com>
---
drivers/leds/trigger/ledtrig-blkdev.c | 63 +++++++++++++++++++++++++++
1 file changed, 63 insertions(+)
diff --git a/drivers/leds/trigger/ledtrig-blkdev.c b/drivers/leds/trigger/ledtrig-blkdev.c
index 15b15aefdfd8..481b2d142db2 100644
--- a/drivers/leds/trigger/ledtrig-blkdev.c
+++ b/drivers/leds/trigger/ledtrig-blkdev.c
@@ -528,3 +528,66 @@ static ssize_t blkdev_add_or_del(struct device *const dev,
*/
return blkdev_skip_space(endp) - buf;
}
+
+
+/*
+ *
+ * blink_time & interval device attributes
+ *
+ */
+
+static ssize_t blkdev_time_show(struct device *const dev,
+ struct device_attribute *const attr,
+ char *const buf);
+
+static ssize_t blkdev_time_store(struct device *const dev,
+ struct device_attribute *const attr,
+ const char *const buf, const size_t count);
+
+static struct device_attribute ledtrig_blkdev_attr_blink_time =
+ __ATTR(blink_time, 0644, blkdev_time_show, blkdev_time_store);
+
+static struct device_attribute ledtrig_blkdev_attr_interval =
+ __ATTR(interval, 0644, blkdev_time_show, blkdev_time_store);
+
+static ssize_t blkdev_time_show(struct device *const dev,
+ struct device_attribute *const attr,
+ char *const buf)
+{
+ const struct ledtrig_blkdev_led *const led =
+ led_trigger_get_drvdata(dev);
+ unsigned int value;
+
+ if (attr == &ledtrig_blkdev_attr_blink_time)
+ value = READ_ONCE(led->blink_msec);
+ else // attr == &ledtrig_blkdev_attr_interval
+ value = jiffies_to_msecs(READ_ONCE(ledtrig_blkdev_interval));
+
+ return sprintf(buf, "%u\n", value);
+}
+
+static ssize_t blkdev_time_store(struct device *const dev,
+ struct device_attribute *const attr,
+ const char *const buf, const size_t count)
+{
+ struct ledtrig_blkdev_led *const led = led_trigger_get_drvdata(dev);
+ unsigned int value;
+ int ret;
+
+ ret = kstrtouint(buf, 0, &value);
+ if (ret != 0)
+ return ret;
+
+ if (value < LEDTRIG_BLKDEV_MIN_TIME) {
+ pr_info("blkdev LED: attempt to set time < %s milliseconds\n",
+ __stringify(LEDTRIG_BLKDEV_MIN_TIME));
+ return -ERANGE;
+ }
+
+ if (attr == &ledtrig_blkdev_attr_blink_time)
+ WRITE_ONCE(led->blink_msec, value);
+ else // attr == &ledtrig_blkdev_attr_interval
+ WRITE_ONCE(ledtrig_blkdev_interval, msecs_to_jiffies(value));
+
+ return count;
+}
--
2.31.1
Powered by blists - more mailing lists