设为首页 加入收藏

TOP

S3C6410的RTC在Linux中的驱动(一)
2014-11-24 12:51:45 来源: 作者: 【 】 浏览:0
Tags:S3C6410 RTC Linux 驱动



1、先从整体上做些分析,大致看了下linux2.6.28\drivers\rtc文件中的kconfig和Makefile文件,在Makefile文件中有如下内容:


ifeq ($(CONFIG_RTC_DEBUG),y)
EXTRA_CFLAGS += -DDEBUG
endif


obj-$(CONFIG_RTC_LIB) += rtc-lib.o
obj-$(CONFIG_RTC_HCTOSYS) += hctosys.o
obj-$(CONFIG_RTC_CLASS) += rtc-core.o
rtc-core-y := class.o interface.o


rtc-core-$(CONFIG_RTC_INTF_DEV) += rtc-dev.o
rtc-core-$(CONFIG_RTC_INTF_PROC) += rtc-proc.o
rtc-core-$(CONFIG_RTC_INTF_SYSFS) += rtc-sysfs.o


下面这些是对应的具体的实现,根据自己的情况进行选择。


obj-$(CONFIG_RTC_DRV_RX8581)+= rtc-rx8581.o
obj-$(CONFIG_RTC_DRV_S35390A) += rtc-s35390a.o
obj-$(CONFIG_RTC_DRV_S3C) += rtc-s3c.o
obj-$(CONFIG_RTC_DRV_SA1100) += rtc-sa1100.o


应该能从中看出,rtc的驱动大致和那些文件有关,再看对应的kconfig文件,可以看出对应文件的用途,我们就不列出对应的kconfig文件了,因为内容太多了。


2、现在的RTC驱动架构,当然看一下Rtc.txt (linux2.6.28\documentation)文件,对我们理解此架构是很有帮助的,列出部分:



New portable "RTC Class" drivers: /dev/rtcN
--------------------------------------------

Because Linux supports many non-ACPI and non-PC platforms, some of which have more than one RTC style clock, it needed a more portable solution than expecting a single battery-backed MC146818 clone on every system. Accordingly, a new "RTC Class" framework has been defined.讲述了新架构建立的原因。


It offers three different userspace interfaces:讲述了与用户空间的三种接口
* /dev/rtcN ... much the same as the older /dev/rtc interface
* /sys/class/rtc/rtcN ... sysfs attributes support readonly access to some RTC attributes.
* /proc/driver/rtc ... the first RTC (rtc0) may expose itself using a procfs interface. More information is (currently) shown here than through sysfs.



The RTC Class framework supports a wide variety of RTCs, ranging from those integrated into embeddable system-on-chip (SOC) processors to discrete chips using I2C, SPI, or some other bus to communicate with the host CPU. There's even support for PC-style RTCs ... including the features exposed on newer PCs through ACPI.


这种分类的架构,支持更广阔的RTC设备。
The new framework also removes the "one RTC per system" restriction. For example, maybe the low-power battery-backed RTC is a discrete I2C chip, but a high functionality RTC is integrated into the SOC. That system might read the system clock from the discrete RTC, but use the integrated one for all other tasks, because of its greater functionality.
The ioctl() calls supported by /dev/rtc are also supported by the RTC class framework. However, because the chips and systems are not standardized, some PC/AT functionality might not be provided. And in the same way, some newer features -- including those enabled by ACPI -- are exposed by the RTC class framework, but can't be supported by the older driver.




3、有关文件的作用


与RTC核心有关的文件有:



(1)、/drivers/rtc/class.c 这个文件向linux设备驱动模型核心注册了一个RTC类,然后向具体的驱动程序提供了rtc_device_register用于注册和rtc_device_unregister用于注销设备。还实现的rtc类设备的注册。


列出部分源码:


static int __init rtc_init(void)
{
rtc_class = class_create(THIS_MODULE, "rtc");
if (IS_ERR(rtc_class)) {
printk(KERN_ERR "%s: couldn't create class\n", __FILE__);
return PTR_ERR(rtc_class);
}
rtc_class->suspend = rtc_suspend;
rtc_class->resume = rtc_resume;
rtc_dev_init();
rtc_sysfs_init(rtc_class);
return 0;
}
static void __exit rtc_exit(void)
{
rtc_dev_exit();
class_destroy(rtc_class);
}

subsys_initcall(rtc_init);
module_exit(rtc_exit);

(2)、/drivers/rtc/rtc-dev.c 这个文件定义了顶层基本的字符设备文件操作函数,如:open,read等,有个结构体,如下所示:


static const struct file_operations rt

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

评论

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

·C语言中如何将结构体 (2025-12-24 22:20:09)
·纯C语言结构体成员变 (2025-12-24 22:20:06)
·C语言中,指针函数和 (2025-12-24 22:20:03)
·哈希表 - 菜鸟教程 (2025-12-24 20:18:55)
·MySQL存储引擎InnoDB (2025-12-24 20:18:53)