RTC 也就是实时时钟,用于记录当前系统时间,对于 Linux 系统而言时间是非常重要的
RTC 设备驱动是一个标准的字符设备驱动
Linux 内核将 RTC 设备抽象为 rtc_device 结构体 rtc_device 注册到 Linux 内核里面,这样 Linux 内核就有一个 RTC 设备的
rtc_device 注册到 Linux 内核里面,这样 Linux 内核就有一个 RTC 设备的。
71 struct rtc_class_ops {
72 int (*open)(struct device *);
73 void (*release)(struct device *);
74 int (*ioctl)(struct device *, unsigned int, unsigned long);
75 int (*read_time)(struct device *, struct rtc_time *);
76 int (*set_time)(struct device *, struct rtc_time *);
77 int (*read_alarm)(struct device *, struct rtc_wkalrm *);
78 int (*set_alarm)(struct device *, struct rtc_wkalrm *);
79 int (*proc)(struct device *, struct seq_file *);
80 int (*set_mmss64)(struct device *, time64_t secs);
81 int (*set_mmss)(struct device *, unsigned long secs);
82 int (*read_callback)(struct device *, int data);
83 int (*alarm_irq_enable)(struct device *, unsigned int enabled);
84 };
struct rtc_device
105 {
106 struct device dev; /* 设备 */
107 struct module *owner;
108
109 int id; /* ID */
110 char name[RTC_DEVICE_NAME_SIZE]; /* 名字 */
111
112 const struct rtc_class_ops *ops; /* RTC 设备底层操作函数 */
113 struct mutex ops_lock;
114
115 struct cdev char_dev; /* 字符设备 */
116 unsigned long flags;
117
118 unsigned long irq_data;
119 spinlock_t irq_lock;
120 wait_queue_head_t irq_queue;
121 struct fasync_struct *async_queue;
122
123 struct rtc_task *irq_task;
124 spinlock_t irq_task_lock;
125 int irq_freq;
126 int max_user_freq;
127
128 struct timerqueue_head timerqueue;
129 struct rtc_timer aie_timer;
130 struct rtc_timer uie_rtctimer;
131 struct hrtimer pie_timer; /* sub second exp, so needs hrtimer */
132 int pie_enabled;
133 struct work_struct irqwork;
134 /* Some hardware can't support UIE mode */
135 int uie_unsupported;
先直接告诉大家,I.MX6U 的 RTC 驱动我们不用自己编写,因为 NXP 已经写好了。其实对
于大多数的 SOC 来讲,内部 RTC 驱动都不需要我们去编写,半导体厂商会编写好。