rtc: add max_user_freq to sysfs
authorBryan Kadzban <bryan@kdzbn.homelinux.net>
Tue, 16 Oct 2007 08:28:22 +0000 (01:28 -0700)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Tue, 16 Oct 2007 16:43:13 +0000 (09:43 -0700)
drivers/char/rtc.c exposed a sysctl to change the maximum frequency at
which a non-root user could ask the RTC to generate interrupts (via the
RTC_IRQP_SET ioctl).  This value is no longer available under the new RTC
subsystem, so add it to sysfs for each RTC device.

Works for me on x86_64 (both reads and writes), using rtc-cmos.

Signed-off-by: Bryan Kadzban <bryan@kdzbn.homelinux.net>
Acked-by: Alessandro Zummo <a.zummo@towertech.it>
Cc: David Brownell <david-b@pacbell.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/rtc/rtc-sysfs.c

index 69df94b4484169d0a61b5c08f32f3e0e6133f716..6cad0841f3c4d8719ab56e322a2fb82eb6fb89c7 100644 (file)
@@ -73,11 +73,35 @@ rtc_sysfs_show_since_epoch(struct device *dev, struct device_attribute *attr,
        return retval;
 }
 
+static ssize_t
+rtc_sysfs_show_max_user_freq(struct device *dev, struct device_attribute *attr,
+               char *buf)
+{
+       return sprintf(buf, "%d\n", to_rtc_device(dev)->max_user_freq);
+}
+
+static ssize_t
+rtc_sysfs_set_max_user_freq(struct device *dev, struct device_attribute *attr,
+               const char *buf, size_t n)
+{
+       struct rtc_device *rtc = to_rtc_device(dev);
+       unsigned long val = simple_strtoul(buf, NULL, 0);
+
+       if (val >= 4096 || val == 0)
+               return -EINVAL;
+
+       rtc->max_user_freq = (int)val;
+
+       return n;
+}
+
 static struct device_attribute rtc_attrs[] = {
        __ATTR(name, S_IRUGO, rtc_sysfs_show_name, NULL),
        __ATTR(date, S_IRUGO, rtc_sysfs_show_date, NULL),
        __ATTR(time, S_IRUGO, rtc_sysfs_show_time, NULL),
        __ATTR(since_epoch, S_IRUGO, rtc_sysfs_show_since_epoch, NULL),
+       __ATTR(max_user_freq, S_IRUGO | S_IWUSR, rtc_sysfs_show_max_user_freq,
+                       rtc_sysfs_set_max_user_freq),
        { },
 };