NUC972(五)RTC

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/JerryGou/article/details/86660459

RX8025驱动-STM+Linux程序下载 :https://download.csdn.net/download/jerrygou/10940406

Rx8025芯片手册+使用说明(英语+汉语):https://download.csdn.net/download/jerrygou/10940411

一、Rx-8025T IIC-BUS接口实时时钟

二、I2C寄存器

三、I2C-0驱动

3.1、I2C-0的platform_device平台设备注册

//i2c-0的总线配置
static struct nuc970_platform_i2c nuc970_i2c0_data = {
    .bus_num = 0,//这个参数很重要,决定i2c-0的总线为0,从设备通过0总线挂载到i2c-0适
        //配器上,下面会提到从设备通过i2c_register_board_info()注册设备信息,
        //其中该函数的第一个参数即为总线号,这样就将从设备与相应的i2c-0适配
        //器连接上,从设备就可以使用该适配器的资源,对外挂I2C硬件设备进行操作。
    .bus_freq = 100000,
};

//i2c-0的资源配置
static struct resource nuc970_i2c0_resource[] = {
    [0] = {
            .start = NUC970_PA_I2C0,
            .end   = NUC970_PA_I2C0 + NUC970_SZ_I2C0 - 1,
            .flags = IORESOURCE_MEM,
    },
    [1] = {
            .start = IRQ_I2C0,
            .end   = IRQ_I2C0,
            .flags = IORESOURCE_IRQ,
    }
};

//platform_device平台设备资源
struct platform_device nuc970_device_i2c0 = {
    .name		  = "nuc970-i2c0",
    .id		  = -1,
    .num_resources	  = ARRAY_SIZE(nuc970_i2c0_resource),
    .resource	  = nuc970_i2c0_resource,
    .dev = {
        .platform_data = &nuc970_i2c0_data,
    }
};	
    
static struct platform_device *nuc970_public_dev[] __initdata = {
    &nuc970_device_i2c0,
}

//注册platform_device设备
platform_add_devices(nuc970_public_dev, ARRAY_SIZE(nuc970_public_dev));

3.2、注册I2C从设备信息

//i2c-0下的从设备设备信息
static struct i2c_board_info __initdata nuc970_i2c_clients0[] =
{
	{I2C_BOARD_INFO("rx8025", 0x32),},
};

       由于I2C发送数据时,首现发送的第一个字节是对外围从设备进行寻址,我们知道首字节的高4bit(bit7~4)是外围设备的厂商编码,bit3~1是外围设备的地址(具体地址由该芯片的外围电路决定),而bit0是对表示当前'读/写'操作,这里的0x50没有包括bit0‘读写’操作,所以这里的0x32只有7个bit,适配器在进行操作时会左移一位,0x32=‭00110010‬b -> 向左偏移1bit=0110 010x,高bit7~4为6恰好是Rx8025的厂商编码,bit3~1为2恰好是外围器件地址。

//注册i2c从设备信息
i2c_register_board_info(0, nuc970_i2c_clients0, sizeof(nuc970_i2c_clients0)/sizeof(struct i2c_board_info));
//0就是1.1中提到的bus_num的总线,通过该总线就将从设备与nuc970-i2c0适配器进行了连接

3.3、I2C-0的platform-driver设备驱动注册

static struct platform_driver nuc970_i2c0_driver = {
	.probe      = nuc970_i2c0_probe,
	.remove     = nuc970_i2c0_remove,
	.driver     = {
		.name   = "nuc970-i2c0",
		.owner  = THIS_MODULE,
#if defined(CONFIG_OF)
		.of_match_table = of_match_ptr(nuc970_i2c0_of_match),
#endif
		.pm = NUC970_I2C0_PMOPS,
	},
};
module_platform_driver(nuc970_i2c0_driver);

四、RTC设备驱动

4.1、RTC设备驱动注册

static const struct i2c_device_id rx8025_id[] = {
	{ "rx8025", 0 },
	{ }
};
MODULE_DEVICE_TABLE(i2c, rx8025_id);

static struct i2c_driver rx8025_driver = {
	.driver = {
		.name = "rtc-rx8025",
		.owner = THIS_MODULE,
	},
	.probe		= rx8025_probe,
	.remove		= rx8025_remove,
	.id_table	= rx8025_id,
};

module_i2c_driver(rx8025_driver);

4.2、内核配置单配置

为了系统一上电就同步硬件RTC时钟,需修改配置单:
Device Drivers  --->
   <*> I2C support  --->
     --- I2C support                                                                
         [*]   Enable compatibility bits for old user-space                            
         < >   I2C device interface                                                     
         < >   I2C bus multiplexing support                                            
         [*]   Autoselect pertinent helper modules                                      
         I2C Hardware Bus support  --->
            <*> GPIO-based bitbanging I2C                                                 
            <*> NUC970/N9H30 I2C Driver for Port 0 	  
    [*] Real Time Clock  --->
            [*]   Set system time from RTC on startup and resume //系统一上电就同步硬件RTC时钟                         
        [*]   Set the RTC time based on NTP synchronization                            
        (rtc0)  RTC used to set the system time                                        
        [*]   RTC debug support                                                       
        *** RTC interfaces ***                                                     
        [*]   /sys/class/rtc/rtcN (sysfs)                                             
        [*]   /proc/driver/rtc (procfs for rtcN)                                       
        [*]   /dev/rtcN (character devices)                                           
        [ ]     RTC UIE emulation on dev interface  
            
        <*>   Epson RX-8025SA/NB
        < >   NUC970/N9H30 RTC driver

五、修正RTC驱动

六、测试

测试参考:kernel(十二)RTC

猜你喜欢

转载自blog.csdn.net/JerryGou/article/details/86660459
今日推荐