Chinaunix首页 | 论坛 | 博客
  • 博客访问: 970188
  • 博文数量: 214
  • 博客积分: 10173
  • 博客等级: 上将
  • 技术积分: 1867
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-18 13:48
文章分类

全部博文(214)

文章存档

2012年(1)

2010年(13)

2009年(5)

2008年(98)

2007年(97)

分类: LINUX

2007-12-05 23:02:34

 

S3C2410  RTC  Driver  Frame:(From Linux Kernel 2.6.20)
主要讲解在Linux Kernel 中的S3C2410 RTC 内核驱动整体框架结构的思路:


1.设计常规驱动程序中的platform_driver{}:
以下面为框架,主要实现模块的最基本的功能:probe,remove,suspend,resume,以platform_driver{}为核心数据结构,主要面向module_init()和module_exit().

static int s3c_rtc_remove(struct platform_device *dev)
{
 ...............
}

static int s3c_rtc_probe(struct platform_device *pdev)
{
 ...............
}

#ifdef CONFIG_PM

static int s3c_rtc_suspend(struct platform_device *pdev, pm_message_t state)
{
 .................
}

static int s3c_rtc_resume(struct platform_device *pdev)
{
 ...................
}
#else
#define s3c_rtc_suspend NULL
#define s3c_rtc_resume  NULL
#endif

static struct platform_driver s3c2410_rtcdrv = {
 .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_rtcdrv);
}

static void __exit s3c_rtc_exit(void)
{
 platform_driver_unregister(&s3c2410_rtcdrv);
}

module_init(s3c_rtc_init);
module_exit(s3c_rtc_exit);

MODULE_DESCRIPTION("Samsung S3C RTC Driver");
MODULE_AUTHOR("YX <>");
MODULE_LICENSE("GPL");

=====================================================
2.然后依据RTC这块相应芯片的主要功能设计其核心功能模块,以其芯片的主要功能为考虑中心。

在Linux Kernel中,对各类常用的芯片驱动,已经为同一类的芯片驱动设计了驱动程序的框架结构,只需要了解这一类的驱动程序框架结构,再在这个基础上开发具体的驱动程序。

S3C2410 的RTC其主要功能驱动的开发:
1。以rtc_class_ops{}为核心考虑依据:
struct rtc_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);
};

驱动框架结构:
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,
 .proc         = s3c_rtc_proc,
};

然后再一一实现这些函数代码:
static int s3c_rtc_open(struct device *dev)
{
 
}

static void s3c_rtc_release(struct device *dev)
{
 
}

static int s3c_rtc_ioctl(struct device *dev,
    unsigned int cmd, unsigned long arg)
{
 
}

static int s3c_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm)
{
 
}

static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm)
{
 
}

static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm)
{
 
}

static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
{
 
}

======================================================
所以再调整一下相应的该驱动文件的布局,得到主要函数框架:

------------------------------------------------
其他拆分出的辅助性的函数代码 设计如此。

------------------------------------------------
static int s3c_rtc_open(struct device *dev)
{
 
}

static void s3c_rtc_release(struct device *dev)
{
 
}

static int s3c_rtc_ioctl(struct device *dev,
    unsigned int cmd, unsigned long arg)
{
 
}

static int s3c_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm)
{
 
}

static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm)
{
 
}

static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm)
{
 
}

static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
{
 
}

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,
 .proc         = s3c_rtc_proc,
};

------------------------------------------------
static int s3c_rtc_remove(struct platform_device *dev)
{
 ...............
}

static int s3c_rtc_probe(struct platform_device *pdev)
{
 ...............
}

#ifdef CONFIG_PM

static int s3c_rtc_suspend(struct platform_device *pdev, pm_message_t state)
{
 .................
}

static int s3c_rtc_resume(struct platform_device *pdev)
{
 ...................
}
#else
#define s3c_rtc_suspend NULL
#define s3c_rtc_resume  NULL
#endif

static struct platform_driver s3c2410_rtcdrv = {
 .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_rtcdrv);
}

static void __exit s3c_rtc_exit(void)
{
 platform_driver_unregister(&s3c2410_rtcdrv);
}

module_init(s3c_rtc_init);
module_exit(s3c_rtc_exit);

MODULE_DESCRIPTION("Samsung S3C RTC Driver");
MODULE_AUTHOR("YX <>");
MODULE_LICENSE("GPL");

================================================
3。Makefile的结构如下: 
Debug Config====必须的Config(这类驱动核心程序)====各类开发板及相应芯片的驱动配置

#
# Makefile for RTC class/drivers.
#

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

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

obj-$(CONFIG_RTC_DRV_DS1307) += rtc-ds1307.o
obj-$(CONFIG_RTC_DRV_DS1672) += rtc-ds1672.o
obj-$(CONFIG_RTC_DRV_DS1742) += rtc-ds1742.o
obj-$(CONFIG_RTC_DRV_OMAP)  += rtc-omap.o
obj-$(CONFIG_RTC_DRV_PCF8563) += rtc-pcf8563.o
obj-$(CONFIG_RTC_DRV_PCF8583) += rtc-pcf8583.o
obj-$(CONFIG_RTC_DRV_S3C)  += rtc-s3c.o
=================================================
Kconfig:
menu "Real Time Clock"

config RTC_LIB
 tristate

config RTC_CLASS
 tristate "RTC class"
 depends on EXPERIMENTAL
 default n
 select RTC_LIB
 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 or more of the interfaces below.

   This driver can also be built as a module. If so, the module
   will be called rtc-class.

config RTC_HCTOSYS
 bool "Set system time from RTC on startup"
 depends on RTC_CLASS = y
 default y
 help
   If you say yes here, the system time will be set using
   the value read from the specified RTC device. This is useful
   in order to avoid unnecessary fsck runs.

config RTC_HCTOSYS_DEVICE
 string "The RTC to read the time from"
 depends on RTC_HCTOSYS = y
 default "rtc0"
 help
   The RTC device that will be used as the source for
   the system time, usually rtc0.

config RTC_DEBUG
 bool "RTC debug support"
 depends on RTC_CLASS = y
 help
   Say yes here to enable debugging support in the RTC framework
   and individual RTC drivers.

comment "RTC interfaces"
 depends on RTC_CLASS

config RTC_INTF_SYSFS
 tristate "sysfs"
 depends on RTC_CLASS && SYSFS
 default RTC_CLASS
 help
   Say yes here if you want to use your RTCs using sysfs interfaces,
   /sys/class/rtc/rtc0 through /sys/.../rtcN.

   This driver can also be built as a module. If so, the module
   will be called rtc-sysfs.

config RTC_INTF_PROC
 tristate "proc"
 depends on RTC_CLASS && PROC_FS
 default RTC_CLASS
 help
   Say yes here if you want to use your first RTC through the proc
   interface, /proc/driver/rtc.  Other RTCs will not be available
   through that API.

   This driver can also be built as a module. If so, the module
   will be called rtc-proc.

config RTC_INTF_DEV
 tristate "dev"
 depends on RTC_CLASS
 default RTC_CLASS
 help
   Say yes here if you want to use your RTCs using the /dev
   interfaces, which "udev" sets up as /dev/rtc0 through
   /dev/rtcN.  You may want to set up a symbolic link so one
   of these can be accessed as /dev/rtc, which is a name
   expected by "hwclock" and some other programs.

   This driver can also be built as a module. If so, the module
   will be called rtc-dev.

config RTC_INTF_DEV_UIE_EMUL
 bool "RTC UIE emulation on dev interface"
 depends on RTC_INTF_DEV
 help
   Provides an emulation for RTC_UIE if the underlaying rtc chip
   driver does not expose RTC_UIE ioctls.  Those requests generate
   once-per-second update interrupts, used for synchronization.

comment "RTC drivers"
 depends on RTC_CLASS

config RTC_DRV_DS1672
 tristate "Dallas/Maxim DS1672"
 depends on RTC_CLASS && I2C
 help
   If you say yes here you get support for the
   Dallas/Maxim DS1672 timekeeping chip.

   This driver can also be built as a module. If so, the module
   will be called rtc-ds1672.

config RTC_DRV_DS1742
 tristate "Dallas DS1742/1743"
 depends on RTC_CLASS
 help
   If you say yes here you get support for the
   Dallas DS1742/1743 timekeeping chip.

   This driver can also be built as a module. If so, the module
   will be called rtc-ds1742.

config RTC_DRV_OMAP
 tristate "TI OMAP1"
 depends on RTC_CLASS && ( \
  ARCH_OMAP15XX || ARCH_OMAP16XX || ARCH_OMAP730 )
 help
   Say "yes" here to support the real time clock on TI OMAP1 chips.
   This driver can also be built as a module called rtc-omap.

config RTC_DRV_PCF8563
 tristate "Philips PCF8563/Epson RTC8564"
 depends on RTC_CLASS && I2C
 help
   If you say yes here you get support for the
   Philips PCF8563 RTC chip. The Epson RTC8564
   should work as well.

   This driver can also be built as a module. If so, the module
   will be called rtc-pcf8563.

config RTC_DRV_PCF8583
 tristate "Philips PCF8583"
 depends on RTC_CLASS && I2C
 help
   If you say yes here you get support for the
   Philips PCF8583 RTC chip.

   This driver can also be built as a module. If so, the module
   will be called rtc-pcf8583.

config RTC_DRV_S3C
 tristate "Samsung S3C series SoC RTC"
 depends on RTC_CLASS && ARCH_S3C2410
 help
   RTC (Realtime Clock) driver for the clock inbuilt into the
   Samsung S3C24XX series of SoCs. This can provide periodic
   interrupt rates from 1Hz to 64Hz for user programs, and
   wakeup from Alarm.

   The driver currently supports the common features on all the
   S3C24XX range, such as the S3C2410, S3C2412, S3C2413, S3C2440
   and S3C2442.

   This driver can also be build as a module. If so, the module
   will be called rtc-s3c.
===================================================
===================================================
===================================================
===================================================
===================================================
===================================================
===================================================
===================================================
===================================================
===================================================
===================================================
===================================================
===================================================
===================================================
===================================================

    核心框架结构已完


===================================================
===================================================
===================================================
===================================================
===================================================
===================================================
===================================================
===================================================
核心框架结构已完,下面是具体的功能实现代码一些指导提示:

1。Ioctl:
   Documentation:
   ioctl-number.txt,ioctl-decoding.txt
   ioctl.h

2.Documetation:  Rtc.txt

3.rtc.h

4.rtc-s3c.c

 

阅读(1577) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~