RTC subsystem, class
RFC PATCH 1/7 RTC subsystem, class
This patch adds the basic RTC subsytem infrastructure to the kernel.
rtc/class.c - registration facilities for RTC drivers rtc/interface.c - kernel/rtc interface functions rtc/utils.c - misc rtc-related utility functions
Signed-off-by Alessandro Zummo <[email protected]>
--
drivers/Kconfig | 2 drivers/Makefile | 1 drivers/rtc/Kconfig | 25 +++++++++ drivers/rtc/Makefile | 8 +++ drivers/rtc/class.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++ drivers/rtc/interface.c | 78 +++++++++++++++++++++++++++++ drivers/rtc/utils.c | 96 ++++++++++++++++++++++++++++++++++++ include/linux/rtc.h | 66 ++++++++++++++++++++++++ 8 files changed, 403 insertions(+)
include/linux/rtc.h +66 -0
@@ -91,8 +91,74 @@#define RTC_PLL_GET _IOR('p', 0x11, struct rtc_pll_info)/* Get PLL correction */ #define RTC_PLL_SET _IOW('p', 0x12, struct rtc_pll_info)/* Set PLL correction */ +/* interrupt flags */ +#define RTC_IRQF 0x80/* any of the following is active */ +#define RTC_PF 0x40 +#define RTC_AF 0x20 +#define RTC_UF 0x10 + #ifdef __KERNEL__ +#include <linux/device.h> +#include <linux/seq_file.h> +#include <linux/cdev.h> +#include <linux/poll.h> + +struct rtc_class_ops { + struct module *owner; + int (*open)(struct device *); + void (*release)(struct device *); + int (*ioctl)(struct device *, unsigned int, unsigned long); + int (*read_time)(struct device *, struct rtc_time *); + int (*set_time)(struct device *, struct rtc_time *); + int (*read_alarm)(struct device *, struct rtc_wkalrm *); + int (*set_alarm)(struct device *, struct rtc_wkalrm *); + int (*proc)(struct device *, struct seq_file *); + int (*set_mmss)(struct device *, unsigned long secs); +}; + +struct rtc_device +{ + int id; + struct class_device class_dev; + struct rtc_class_ops *ops; + + struct cdev char_dev; + struct semaphore char_sem; + + unsigned long irq_data; + struct semaphore irq_lock; + wait_queue_head_t irq_queue; + struct fasync_struct *async_queue; +}; +#define to_rtc_device(d) container_of(d, struct rtc_device, class_dev) + +static inline struct rtc_class_ops *rtc_get_ops(struct class_device *class_dev) +{ + struct rtc_device *rtc = to_rtc_device(class_dev); + return rtc->ops; +} + +extern int rtc_interface_register(struct class_interface *intf); +extern struct rtc_device *rtc_device_register(struct device *dev, + struct rtc_class_ops *ops); +extern void rtc_device_unregister(struct rtc_device *rdev); + + +extern int rtc_month_days(unsigned int month, unsigned int year); +extern int rtc_valid_tm(struct rtc_time *tm); +extern void rtc_tm_to_time(struct rtc_time *tm, unsigned long *time); +extern void rtc_time_to_tm(unsigned long time, struct rtc_time *tm); + +extern int rtc_read_time(struct class_device *class_dev, struct rtc_time *tm); +extern int rtc_set_time(struct class_device *class_dev, struct rtc_time *tm); +extern int rtc_read_alarm(struct class_device *class_dev, + struct rtc_wkalrm *alrm); +extern int rtc_set_alarm(struct class_device *class_dev, + struct rtc_wkalrm *alrm); +extern void rtc_update_irq(struct class_device *class_dev, + unsigned long num, unsigned long events); + typedef struct rtc_task { void (*func)(void *private_data); void *private_data;
drivers/Kconfig +2 -0
@@ -66,4 +66,6 @@ source "drivers/sn/Kconfig" +source "drivers/rtc/Kconfig" + endmenu
drivers/Makefile +1 -0
@@ -54,6 +54,7 @@ obj-$(CONFIG_GAMEPORT) += input/gameport/ obj-$(CONFIG_INPUT) += input/ obj-$(CONFIG_I2O) += message/ +obj-y += rtc/ obj-$(CONFIG_I2C) += i2c/ obj-$(CONFIG_W1) += w1/ obj-$(CONFIG_HWMON) += hwmon/
drivers/rtc/class.c new file +127 -0
127 lines not on this page · raw message
drivers/rtc/Kconfig new file +25 -0
@@ -0,0 +1,25 @@ +# +# RTC class/drivers configuration +# + +menu "Real Time Clock" + +config RTC_CLASS + tristate "RTC class" + depends on EXPERIMENTAL + default y + help + Generic RTC class support. If you say yes here, you will + be allowed to plug one or more RTCs to your system. You will + probably want to enable one of more of the interfaces below. + + This driver can also be built as a module. If so, the module + will be called rtc-class. + +comment "RTC interfaces" + depends on RTC_CLASS + +comment "RTC drivers" + depends on RTC_CLASS + +endmenu
drivers/rtc/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +# +# Makefile for RTC class/drivers. +# + +obj-y += utils.o +obj-$(CONFIG_RTC_CLASS) += rtc-core.o +rtc-core-y := class.o interface.o +
drivers/rtc/interface.c new file +78 -0
78 lines not on this page · raw message
drivers/rtc/utils.c new file +96 -0
96 lines not on this page · raw message