/** * module_i2c_driver() - Helper macro for registering a modular I2C driver * @__i2c_driver: i2c_driver struct * * Helper macro for I2C drivers which do not do anything special in module * init/exit. This eliminates a lot of boilerplate. Each module may only * use this macro once, and calling it replaces module_init() and module_exit() */ #define module_i2c_driver(__i2c_driver) \ module_driver(__i2c_driver, i2c_add_driver, \ i2c_del_driver)
/** * module_driver() - Helper macro for drivers that don't do anything * special in module init/exit. This eliminates a lot of boilerplate. * Each module may only use this macro once, and calling it replaces * module_init() and module_exit(). * * @__driver: driver name * @__register: register function for this driver type * @__unregister: unregister function for this driver type * @...: Additional arguments to be passed to __register and __unregister. * * Use this macro to construct bus specific macros for registering * drivers, and do not use it on its own. */ #define module_driver(__driver, __register, __unregister, ...) \ static int __init __driver##_init(void) \ { \ return __register(&(__driver) , ##__VA_ARGS__); \ } \ module_init(__driver##_init); \ static void __exit __driver##_exit(void) \ { \ __unregister(&(__driver) , ##__VA_ARGS__); \ } \ module_exit(__driver##_exit);
int irq_freq;// 中断频率 int max_user_freq;// 用户空间允许的最大中断频率
structtimerqueue_headtimerqueue;// 定时器队列,用于管理定时器事件 structrtc_timeraie_timer;// 闹钟中断定时器 structrtc_timeruie_rtctimer;// 更新中断定时器 structhrtimerpie_timer;/* sub second exp, so needs hrtimer */// 高精度定时器,用于处理亚秒级的中断 int pie_enabled;// 高精度定时器是否启用 structwork_structirqwork;// 中断处理的工作队列 /* Some hardware can't support UIE mode */ int uie_unsupported;// 硬件是否不支持更新中断模式
/* Number of nsec it takes to set the RTC clock. This influences when * the set ops are called. An offset: * - of 0.5 s will call RTC set for wall clock time 10.0 s at 9.5 s * - of 1.5 s will call RTC set for wall clock time 10.0 s at 8.5 s * - of -0.5 s will call RTC set for wall clock time 10.0 s at 10.5 s */ long set_offset_nsec;/* 设置 RTC 时钟时的偏移时间(纳秒) */
bool registered;// 设备是否已注册
/* Old ABI support */ bool nvram_old_abi;// 是否使用旧的 NVRAM ABI structbin_attribute *nvram;// NVRAM 的二进制属性
/** * devm_rtc_device_register - resource managed rtc_device_register() * @dev: the device to register * @name: the name of the device (unused) * @ops: the rtc operations structure * @owner: the module owner * * @return a struct rtc on success, or an ERR_PTR on error * * Managed rtc_device_register(). The rtc_device returned from this function * are automatically freed on driver detach. * This function is deprecated, use devm_rtc_allocate_device and * rtc_register_device instead */ struct rtc_device *devm_rtc_device_register(struct device *dev, constchar *name, conststruct rtc_class_ops *ops, struct module *owner) { structrtc_device *rtc; int err; // 分配设备资源管理器的内存,用于存储 RTC 设备指针 rtc = devm_rtc_allocate_device(dev); if (IS_ERR(rtc)) return rtc;// 如果分配失败,返回错误指针(内存不足)
/* Check to see if there is an ALARM already set in hw */ // 检查硬件中是否已经设置了报警 err = __rtc_read_alarm(rtc, &alrm);// 尝试读取硬件中的报警信息 if (!err && !rtc_valid_tm(&alrm.time))// 如果读取成功且时间有效 rtc_initialize_alarm(rtc, &alrm);// 初始化报警
#ifdef CONFIG_RTC_HCTOSYS_DEVICE /* Result of the last RTC to system clock attempt. */ int rtc_hctosys_ret = -ENODEV;
/* IMPORTANT: the RTC only stores whole seconds. It is arbitrary * whether it stores the most close value or the value with partial * seconds truncated. However, it is important that we use it to store * the truncated value. This is because otherwise it is necessary, * in an rtc sync function, to read both xtime.tv_sec and * xtime.tv_nsec. On some processors (i.e. ARM), an atomic read * of >32bits is not possible. So storing the most close value would * slow down the sync API. So here we have the truncated value and * the best guess is to add 0.5s. */