1126b移植SE8025T
设备树i2c4 { pinctrl-0 i2c4m3_pins; clock-frequency 400000; status okay; se8025tc: rtc32 { compatible seiko,se8025tc; reg 0x32; #clock-cells 0; status okay; }; };内核配置config添加.mk添加makefile需要同样添加上自己的代码如下#include linux/module.h #include linux/i2c.h #include linux/rtc.h #include linux/bcd.h #include linux/delay.h #include linux/of.h /* -------------------------- 核心修改SE8025TC 寄存器定义 -------------------------- */ // 替换原 RX8025 的寄存器地址适配 SE8025TC 手册 #define SE8025TC_REG_SEC 0x00 // 秒 (BCD) #define SE8025TC_REG_MIN 0x01 // 分 (BCD) #define SE8025TC_REG_HOUR 0x02 // 时 (BCD) #define SE8025TC_REG_WEEK 0x03 // 星期 (独热码0x01周一, 0x02周二...0x40周日) #define SE8025TC_REG_DAY 0x04 // 日 (BCD) #define SE8025TC_REG_MONTH 0x05 // 月 (BCD) #define SE8025TC_REG_YEAR 0x06 // 年 (BCD, 00-99 对应 2000-2099) #define SE8025TC_REG_ALM_MIN 0x07 // 闹钟分 (BCD) #define SE8025TC_REG_ALM_HOUR 0x08 // 闹钟时 (BCD) #define SE8025TC_REG_ALM_WDAY 0x09 // 闹钟周/日 (由 WADA 位选择) #define SE8025TC_REG_ALM_DAY 0x0A // 闹钟日扩展 (保留) #define SE8025TC_REG_TIMER0 0x0B // 定时计数器0 (SE8025TC专属) #define SE8025TC_REG_TIMER1 0x0C // 定时计数器1 (SE8025TC专属) #define SE8025TC_REG_EXT 0x0D // 扩展寄存器 (FOUT/定时中断配置) #define SE8025TC_REG_FLAG 0x0E // 标志寄存器 (中断/电压检测) #define SE8025TC_REG_CTRL 0x0F // 控制寄存器 (中断使能/温度补偿) /* -------------------------- SE8025TC 寄存器位定义 -------------------------- */ // 标志寄存器 (0x0E) #define SE8025TC_FLAG_VLF BIT(1) // 电压低标志 (掉电后置1需软件清零) #define SE8025TC_FLAG_UF BIT(5) // 秒更新中断标志 #define SE8025TC_FLAG_TF BIT(4) // 定时中断标志 #define SE8025TC_FLAG_AF BIT(3) // 闹钟中断标志 // 控制寄存器 (0x0F) #define SE8025TC_CTRL_UIE BIT(5) // 秒更新中断使能 #define SE8025TC_CTRL_TIE BIT(4) // 定时中断使能 #define SE8025TC_CTRL_AIE BIT(3) // 闹钟中断使能 #define SE8025TC_CTRL_CSEL0 BIT(1) // 温度补偿间隔选择0 #define SE8025TC_CTRL_CSEL1 BIT(2) // 温度补偿间隔选择1 // 扩展寄存器 (0x0D) #define SE8025TC_EXT_WADA BIT(0) // 闹钟类型选择: 0周闹钟, 1日闹钟 #define SE8025TC_EXT_USEL BIT(1) // 秒更新中断模式: 0秒, 1分 #define SE8025TC_EXT_TSEL0 BIT(2) // 定时中断时钟源选择0 #define SE8025TC_EXT_TSEL1 BIT(3) // 定时中断时钟源选择1 #define SE8025TC_EXT_FSEL0 BIT(4) // FOUT频率选择0 #define SE8025TC_EXT_FSEL1 BIT(5) // FOUT频率选择1 #define SE8025TC_EXT_TE BIT(6) // 定时中断使能 #define SE8025TC_EXT_FOE BIT(7) // FOUT输出使能 // SE8025TC 设备私有数据 struct se8025tc_data { struct i2c_client *client; struct rtc_device *rtc; bool vlf_detected; // 电压低标志 }; /* -------------------------- 核心修改星期独热码 - 数字 转换 -------------------------- */ // SE8025TC 星期寄存器是独热码: 0x01周一, 0x02周二, ..., 0x40周日 static u8 se8025tc_week_heat2num(u8 heat) { switch (heat) { case 0x01: return 1; // 周一 case 0x02: return 2; // 周二 case 0x04: return 3; // 周三 case 0x08: return 4; // 周四 case 0x10: return 5; // 周五 case 0x20: return 6; // 周六 case 0x40: return 7; // 周日 default: return 1; // 默认周一 } } static u8 se8025tc_week_num2heat(u8 num) { switch (num) { case 1: return 0x01; // 周一 case 2: return 0x02; // 周二 case 3: return 0x04; // 周三 case 4: return 0x08; // 周四 case 5: return 0x10; // 周五 case 6: return 0x20; // 周六 case 7: return 0x40; // 周日 default: return 0x01; // 默认周一 } } /* -------------------------- RTC 时间读取 -------------------------- */ static int se8025tc_read_time(struct device *dev, struct rtc_time *tm) { struct se8025tc_data *data dev_get_drvdata(dev); struct i2c_client *client >扫描总线4上的所有可能地址0x03-0x77i2cdetect -y -r 4发现32地址下有设备尝试读取寄存器0通常是秒/状态寄存器i2cget -y 4 0x32 0x00连续读取多个寄存器查看数据模式i2cdump -y 4 0x32如果驱动加载了的话执行上述i2c检测的指令会提示busy加载了的话首先通过dmesg | grep 8025查看驱动加载是否成功。加载成功的话通过hwclock看一下目前系统时间之后通过date 031609042026.00更改一下系统时间然后使用 hwclock -w -f /dev/rtc0 将系统时间同步到rtc此处可以不加-f默认就是rtc0再使用hwclock打印一下是否修改成功还需要调试reboot后是否能保持时间