设为首页 加入收藏

TOP

S3C6410的RTC在Linux中的驱动(二)
2014-11-24 12:51:45 来源: 作者: 【 】 浏览:2
Tags:S3C6410 RTC Linux 驱动
c_dev_fops = {
.owner = THIS_MODULE,
.llseek = no_llseek,
.read = rtc_dev_read,
.poll = rtc_dev_poll,
.unlocked_ioctl= rtc_dev_ioctl,
.open = rtc_dev_open,
.release = rtc_dev_release,
.fasync = rtc_dev_fasync,
};此结构体用于字符设备注册是使用。

(3)、/drivers/rtc/interface.c 这个文件主要提供了用户程序与RTC驱动的接口函数,用户程序一般通过ioctl与RTC驱动交互,这里定义了每个ioctl命令需要调用的函数。看函数名,也能猜出大概:


EXPORT_SYMBOL_GPL(rtc_set_time);


EXPORT_SYMBOL_GPL(rtc_read_alarm);



(4)、/drivers/rtc/rtc-sysfs.c 看名字就很清楚,与sysfs有关,看注释:


/*
* RTC subsystem, sysfs interface
*/
(5)、/drivers/rtc/rtc-proc.c 与proc文件系统有关,同样:


/*
* RTC subsystem, proc interface
*/


6)、/drivers/rtc/rtc-lib.c 主要和时间转化有关,列出一个函数,看函数名就能看出大概,


int rtc_year_days(unsigned int day, unsigned int month, unsigned int year)
{
return rtc_ydays[LEAP_YEAR(year)][month] + day-1;
}


(7)、/drivers/rtc/hctosys.c 和系统时钟有关,就一个函数,


/*
* RTC subsystem, initialize system time on startup
*/


static int __init rtc_hctosys(void)



(8)、/include/linux/rtc.h 定义了与RTC有关的数据结构,如下所示:


structrtc_class_ops { 用于具体设备的驱动接口
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);
int (*irq_set_state)(struct device *, int enabled);
int (*irq_set_freq)(struct device *, int freq);
int (*read_callback)(struct device *, int data);
};
struct rtc_device
{
struct device dev;
struct module *owner;


int id;
char name[RTC_DEVICE_NAME_SIZE];


const struct rtc_class_ops *ops;
struct mutex ops_lock;


struct cdev char_dev;
unsigned long flags;


unsigned long irq_data;
spinlock_t irq_lock;
wait_queue_head_t irq_queue;
struct fasync_struct *async_queue;


struct rtc_task *irq_task;
spinlock_t irq_task_lock;
int irq_freq;
int max_user_freq;
#ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL
struct work_struct uie_task;
struct timer_list uie_timer;
/* Those fields are protected by rtc->irq_lock */
unsigned int oldsecs;
unsigned int irq_active:1;
unsigned int stop_uie_polling:1;
unsigned int uie_task_active:1;
unsigned int uie_timer_active:1;
#endif
};


4、因为主要关心的是三星架构的s3c6410的RTC,与之有关的文件是Rtc-s3c.c (linux2.6.28\drivers\rtc)。这个文件实现了具体rtc设备的驱动。同样rtc设备在系统中也作为平台设备存在,所以这个文件中也包含了平台设备相关的内容。如下所示:


提供给上层的驱动函数。


static const struct rtc_class_ops s3c_rtcops = {
.open = s3c_rtc_open,
.release = s3c_rtc_release,
.ioctl = s3c_rtc_ioctl,
.read_time = s3c_rtc_gettime,
.set_time = s3c_rtc_settime,
.read_alarm = s3c_rtc_getalarm,
.set_alarm = s3c_rtc_setalarm,
.irq_set_freq = s3c_rtc_setfreq,
.irq_set_state= s3c_rtc_setpie,
.proc = s3c_rtc_proc,
};


平台相关:


static struct platform_driver s3c2410_rtc_driver = {
.probe = s3c_rtc_probe,
.remove = s3c_rtc_remove,
.suspend = s3c_rtc_suspend,
.resume = s3c_rtc_resume,
.driver = {
.name = "s3c2410-rtc",
.owner = THIS_MODULE,
},
};
static char __initdata banner[] = "S3C24XX RTC, (c) 2004,2006 Simtec Electronics\n";
static int __init s3c_rtc_init(void)
{
printk(banner);
return platform_driver_register(&s3c2410_rtc_driver);
}
static void __exit s3c_rtc_exit(void)
{
platform_driver_unregister(&s3c2410_rtc_driver);
}
module_init(s3c_rtc_init);
mo

首页 上一页 1 2 3 下一页 尾页 2/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Android教程:开机自启动C程序 下一篇S3C6410硬件RTC(实时时钟)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·如何利用Python做数 (2025-12-24 23:48:36)
·如何使用python进行 (2025-12-24 23:48:34)
·python 爬虫入门该怎 (2025-12-24 23:48:31)
·Java 实现多个大文件 (2025-12-24 23:22:00)
·Java多线程编程在工 (2025-12-24 23:21:56)