rtc-ds1307.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2023-09-23 GuEe-GUI first version
  9. */
  10. #include "rtc_dm.h"
  11. #define DBG_TAG "rtc.ds1307"
  12. #define DBG_LVL DBG_INFO
  13. #include <rtdbg.h>
  14. #define RTC_SEC_REG_ADDR 0x00
  15. #define RTC_MIN_REG_ADDR 0x01
  16. #define RTC_HR_REG_ADDR 0x02
  17. #define RTC_DAY_REG_ADDR 0x03
  18. #define RTC_DATE_REG_ADDR 0x04
  19. #define RTC_MON_REG_ADDR 0x05
  20. #define RTC_YR_REG_ADDR 0x06
  21. #define RTC_CTL_REG_ADDR 0x07
  22. #define DS1337_CTL_REG_ADDR 0x0e
  23. #define DS1337_STAT_REG_ADDR 0x0f
  24. #define DS1340_STAT_REG_ADDR 0x09
  25. #define RTC_STAT_BIT_A1I 0x01
  26. #define RTC_STAT_BIT_A2I 0x02
  27. #define RTC_STAT_BIT_OSF 0x80
  28. #define RTC_SEC_BIT_CH 0x80 /* Clock Halt (in Register 0) */
  29. /* DS1307-specific bits */
  30. #define RTC_CTL_BIT_RS0 0x01 /* Rate select 0 */
  31. #define RTC_CTL_BIT_RS1 0x02 /* Rate select 1 */
  32. #define RTC_CTL_BIT_SQWE 0x10 /* Square Wave Enable */
  33. #define RTC_CTL_BIT_OUT 0x80 /* Output Control */
  34. /* DS1337-specific bits */
  35. #define DS1337_CTL_BIT_A1IE 0x01
  36. #define DS1337_CTL_BIT_A2IE 0x02
  37. #define DS1337_CTL_BIT_RS1 0x08 /* Rate select 1 */
  38. #define DS1337_CTL_BIT_RS2 0x10 /* Rate select 2 */
  39. #define DS1337_CTL_BIT_EOSC 0x80 /* Enable Oscillator */
  40. /* DS1339-specific bits */
  41. #define DS1339_ALARM1_REG_SECS 0x07
  42. /* DS1340-specific bits */
  43. #define DS1340_SEC_BIT_EOSC 0x80 /* Enable Oscillator */
  44. #define DS1340_CTL_BIT_OUT 0x80 /* Output Control */
  45. /* MCP7941X-specific bits */
  46. #define MCP794XX_ALARM0_REG_ADDR 0x0d
  47. #define MCP794XX_BIT_ALMX_IF RT_BIT(3)
  48. #define MCP794XX_BIT_ALMX_C0 RT_BIT(4)
  49. #define MCP794XX_BIT_ALMX_C1 RT_BIT(5)
  50. #define MCP794XX_BIT_ALMX_C2 RT_BIT(6)
  51. #define MCP794XX_BIT_ALMX_POL RT_BIT(7)
  52. #define MCP794XX_MSK_ALMX_MATCH (MCP794XX_BIT_ALMX_C0 | MCP794XX_BIT_ALMX_C1 | MCP794XX_BIT_ALMX_C2)
  53. #define MCP794XX_BIT_ALM0_EN 0x10
  54. #define MCP7941X_BIT_ST 0x80
  55. #define MCP7941X_BIT_VBATEN 0x08
  56. enum ds_type
  57. {
  58. ds1307,
  59. ds1337,
  60. ds1338,
  61. ds1339,
  62. ds1340,
  63. m41t11,
  64. mcp794xx,
  65. };
  66. struct ds1307_rtc
  67. {
  68. struct rt_device parent;
  69. int irq;
  70. enum ds_type type;
  71. struct rt_i2c_client *client;
  72. struct rt_thread *irq_thread;
  73. struct rt_rtc_wkalarm wkalarm;
  74. };
  75. #define raw_to_ds1307_rtc(raw) rt_container_of(raw, struct ds1307_rtc, parent)
  76. static rt_int32_t i2c_read_byte(struct rt_i2c_client *client,
  77. rt_uint8_t command)
  78. {
  79. rt_int32_t res;
  80. rt_uint8_t ret = 0;
  81. struct rt_i2c_msg msg[2];
  82. msg[0].buf = &command;
  83. msg[0].addr = client->client_addr;
  84. msg[0].len = 1;
  85. msg[0].flags = RT_I2C_WR;
  86. msg[1].buf = &ret;
  87. msg[1].addr = client->client_addr;
  88. msg[1].len = 1;
  89. msg[1].flags = RT_I2C_RD;
  90. res = rt_i2c_transfer(client->bus, msg, 2);
  91. return res == 2 ? ret : res;
  92. }
  93. static rt_int32_t i2c_write_byte(struct rt_i2c_client *client,
  94. rt_uint8_t command, rt_uint8_t value)
  95. {
  96. rt_int32_t res;
  97. struct rt_i2c_msg msg[1];
  98. rt_uint8_t data[2] = { command, value };
  99. msg[0].buf = data;
  100. msg[0].addr = client->client_addr;
  101. msg[0].len = 2;
  102. msg[0].flags = RT_I2C_WR;
  103. res = rt_i2c_transfer(client->bus, msg, 1);
  104. return res == 1 ? 0 : res;
  105. }
  106. static rt_int32_t i2c_update_byte_bits(struct rt_i2c_client *client,
  107. rt_uint8_t command, rt_uint8_t mask, rt_uint8_t value)
  108. {
  109. rt_int32_t res = i2c_read_byte(client, command);
  110. if (res < 0)
  111. {
  112. return res;
  113. }
  114. res &= ~mask;
  115. res |= value;
  116. return i2c_write_byte(client, command, res);
  117. }
  118. /* Returns the number of read bytes */
  119. static rt_int32_t i2c_read_block(struct rt_i2c_client *client,
  120. rt_uint8_t command, rt_uint8_t length, rt_uint8_t *values)
  121. {
  122. struct rt_i2c_msg msg[2];
  123. msg[0].buf = &command;
  124. msg[0].addr = client->client_addr;
  125. msg[0].len = 1;
  126. msg[0].flags = RT_I2C_WR;
  127. msg[1].buf = values;
  128. msg[1].addr = client->client_addr;
  129. msg[1].len = length;
  130. msg[1].flags = RT_I2C_RD;
  131. return rt_i2c_transfer(client->bus, msg, 2);
  132. }
  133. static rt_int32_t i2c_write_block(struct rt_i2c_client *client,
  134. rt_uint8_t command, rt_uint8_t length, const rt_uint8_t *values)
  135. {
  136. rt_uint8_t data[32];
  137. struct rt_i2c_msg msg[1];
  138. length = rt_min_t(rt_uint8_t, length, RT_ARRAY_SIZE(data) - 1);
  139. data[0] = command;
  140. rt_memcpy(&data[1], values, length);
  141. msg[0].buf = data;
  142. msg[0].addr = client->client_addr;
  143. msg[0].len = length + 1;
  144. msg[0].flags = RT_I2C_WR;
  145. return rt_i2c_transfer(client->bus, msg, 1);
  146. }
  147. static void ds1307_rtc_read_time(struct ds1307_rtc *ds1307, time_t *sec)
  148. {
  149. rt_uint8_t data[7];
  150. struct tm tm;
  151. struct rt_i2c_client *client = ds1307->client;
  152. if (i2c_read_block(client, 0, sizeof(data), data) > 0)
  153. {
  154. int reg = -1;
  155. if (ds1307->type == ds1337)
  156. {
  157. reg = DS1337_STAT_REG_ADDR;
  158. }
  159. if (ds1307->type == ds1340)
  160. {
  161. reg = DS1340_STAT_REG_ADDR;
  162. }
  163. if (reg >= 0)
  164. {
  165. rt_int32_t status = i2c_read_byte(client, reg);
  166. if (status >= 0 && (status & RTC_STAT_BIT_OSF))
  167. {
  168. status &= ~RTC_STAT_BIT_OSF;
  169. i2c_write_byte(client, reg, status);
  170. }
  171. }
  172. tm.tm_sec = rt_bcd2bin(data[RTC_SEC_REG_ADDR] & 0x7f);
  173. tm.tm_min = rt_bcd2bin(data[RTC_MIN_REG_ADDR] & 0x7f);
  174. tm.tm_hour = rt_bcd2bin(data[RTC_HR_REG_ADDR] & 0x3f);
  175. tm.tm_mday = rt_bcd2bin(data[RTC_DATE_REG_ADDR] & 0x3f);
  176. tm.tm_mon = rt_bcd2bin(data[RTC_MON_REG_ADDR] & 0x1f) - 1;
  177. tm.tm_year = rt_bcd2bin(data[RTC_YR_REG_ADDR]) + 100;
  178. tm.tm_wday = rt_bcd2bin(data[RTC_DAY_REG_ADDR] & 0x07) - 1;
  179. tm.tm_yday = 0;
  180. tm.tm_isdst = 0;
  181. *sec = timegm(&tm);
  182. }
  183. }
  184. static void ds1307_rtc_set_time(struct ds1307_rtc *ds1307, time_t *sec)
  185. {
  186. rt_uint8_t buf[7];
  187. struct tm *tm;
  188. struct rt_i2c_client *client = ds1307->client;
  189. tm = localtime(sec);
  190. buf[RTC_YR_REG_ADDR] = rt_bin2bcd(tm->tm_year - 100);
  191. buf[RTC_MON_REG_ADDR] = rt_bin2bcd(tm->tm_mon + 1);
  192. buf[RTC_DAY_REG_ADDR] = rt_bin2bcd(tm->tm_wday + 1);
  193. buf[RTC_DATE_REG_ADDR] = rt_bin2bcd(tm->tm_mday);
  194. buf[RTC_HR_REG_ADDR] = rt_bin2bcd(tm->tm_hour);
  195. buf[RTC_MIN_REG_ADDR] = rt_bin2bcd(tm->tm_min);
  196. buf[RTC_SEC_REG_ADDR] = rt_bin2bcd(tm->tm_sec);
  197. if (ds1307->type == mcp794xx)
  198. {
  199. buf[RTC_DAY_REG_ADDR] |= MCP7941X_BIT_VBATEN;
  200. buf[RTC_SEC_REG_ADDR] |= MCP7941X_BIT_ST;
  201. }
  202. if (i2c_write_block(client, 0, sizeof(buf), buf) >= 0)
  203. {
  204. if (ds1307->type == ds1337)
  205. {
  206. i2c_write_byte(client, DS1337_CTL_REG_ADDR, 0);
  207. }
  208. }
  209. }
  210. static int ds1307_rtc_alarm_irq_enable(struct ds1307_rtc *ds1307, rt_bool_t enabled)
  211. {
  212. struct rt_i2c_client *client = ds1307->client;
  213. if (ds1307->type == mcp794xx)
  214. {
  215. return i2c_update_byte_bits(client, RTC_CTL_REG_ADDR,
  216. MCP794XX_BIT_ALM0_EN, enabled ? MCP794XX_BIT_ALM0_EN : 0);
  217. }
  218. return i2c_update_byte_bits(client, DS1337_CTL_REG_ADDR,
  219. DS1337_CTL_BIT_A1IE, enabled ? DS1337_CTL_BIT_A1IE : 0);
  220. }
  221. static int ds1307_rtc_read_alarm(struct ds1307_rtc *ds1307,
  222. struct rt_rtc_wkalarm *alarm)
  223. {
  224. int res;
  225. struct rt_i2c_client *client = ds1307->client;
  226. if (ds1307->type == mcp794xx)
  227. {
  228. rt_uint8_t regs[10];
  229. res = i2c_read_block(client, RTC_CTL_REG_ADDR, sizeof(regs), regs);
  230. if (res < 0)
  231. {
  232. return res;
  233. }
  234. alarm->enable = !!(regs[0] & MCP794XX_BIT_ALM0_EN);
  235. /* Report alarm 0 time assuming 24-hour and day-of-month modes. */
  236. alarm->tm_sec = rt_bcd2bin(regs[3] & 0x7f);
  237. alarm->tm_min = rt_bcd2bin(regs[4] & 0x7f);
  238. alarm->tm_hour = rt_bcd2bin(regs[5] & 0x3f);
  239. /* alarm->tm_wday = rt_bcd2bin(regs[6] & 0x7) - 1; */
  240. alarm->tm_mday = rt_bcd2bin(regs[7] & 0x3f);
  241. alarm->tm_mon = rt_bcd2bin(regs[8] & 0x1f) - 1;
  242. alarm->tm_year = -1;
  243. }
  244. else
  245. {
  246. rt_uint8_t regs[9];
  247. res = i2c_read_block(client, DS1339_ALARM1_REG_SECS, sizeof(regs), regs);
  248. if (res < 0)
  249. {
  250. return res;
  251. }
  252. alarm->tm_sec = rt_bcd2bin(regs[0] & 0x7f);
  253. alarm->tm_min = rt_bcd2bin(regs[1] & 0x7f);
  254. alarm->tm_hour = rt_bcd2bin(regs[2] & 0x3f);
  255. alarm->tm_mday = rt_bcd2bin(regs[3] & 0x3f);
  256. alarm->enable = !!(regs[7] & DS1337_CTL_BIT_A1IE);
  257. }
  258. return RT_EOK;
  259. }
  260. static int ds1307_rtc_set_alarm(struct ds1307_rtc *ds1307,
  261. struct rt_rtc_wkalarm *alarm)
  262. {
  263. int res;
  264. struct rt_i2c_client *client = ds1307->client;
  265. struct rt_rtc_wkalarm *wkalarm = &ds1307->wkalarm;
  266. if (ds1307->type == mcp794xx)
  267. {
  268. rt_uint8_t regs[7];
  269. res = i2c_read_block(client, RTC_CTL_REG_ADDR, sizeof(regs), regs);
  270. if (res < 0)
  271. {
  272. return res;
  273. }
  274. /* Set alarm 0, using 24-hour and day-of-month modes. */
  275. regs[3] = rt_bin2bcd(alarm->tm_sec);
  276. regs[4] = rt_bin2bcd(alarm->tm_min);
  277. regs[5] = rt_bin2bcd(alarm->tm_hour);
  278. regs[6] = MCP7941X_BIT_VBATEN;
  279. regs[7] = rt_bin2bcd(alarm->tm_mday);
  280. regs[8] = rt_bin2bcd(alarm->tm_mon + 1);
  281. /* Clear the alarm 0 interrupt flag. */
  282. regs[6] &= ~MCP794XX_BIT_ALMX_IF;
  283. /* Set alarm match: second, minute, hour, day, date, month. */
  284. regs[6] |= MCP794XX_MSK_ALMX_MATCH;
  285. /* Disable interrupt. We will not enable until completely programmed */
  286. regs[0] &= ~MCP794XX_BIT_ALM0_EN;
  287. res = i2c_write_block(client, RTC_CTL_REG_ADDR, sizeof(regs), regs);
  288. if (res < 0)
  289. {
  290. return res;
  291. }
  292. }
  293. else
  294. {
  295. rt_uint8_t regs[9], control, status;
  296. res = i2c_read_block(client, DS1339_ALARM1_REG_SECS, sizeof(regs), regs);
  297. if (res < 0)
  298. {
  299. return res;
  300. }
  301. control = regs[7];
  302. status = regs[8];
  303. /* Set ALARM1, using 24 hour and day-of-month modes */
  304. regs[0] = rt_bin2bcd(alarm->tm_sec);
  305. regs[1] = rt_bin2bcd(alarm->tm_min);
  306. regs[2] = rt_bin2bcd(alarm->tm_hour);
  307. regs[3] = rt_bin2bcd(alarm->tm_mday);
  308. /* Set ALARM2 to non-garbage */
  309. regs[4] = 0;
  310. regs[5] = 0;
  311. regs[6] = 0;
  312. /* Disable alarms */
  313. regs[7] = control & ~(DS1337_CTL_BIT_A1IE | DS1337_CTL_BIT_A2IE);
  314. regs[8] = status & ~(RTC_STAT_BIT_A1I | RTC_STAT_BIT_A2I);
  315. res = i2c_write_block(client, DS1339_ALARM1_REG_SECS, sizeof(regs), regs);
  316. if (res < 0)
  317. {
  318. return res;
  319. }
  320. }
  321. res = ds1307_rtc_alarm_irq_enable(ds1307, wkalarm->enable);
  322. if (!(res < 0))
  323. {
  324. wkalarm->enable = alarm->enable;
  325. wkalarm->tm_hour = alarm->tm_hour;
  326. wkalarm->tm_min = alarm->tm_min;
  327. wkalarm->tm_sec = alarm->tm_sec;
  328. }
  329. return res;
  330. }
  331. static rt_err_t ds1307_rtc_control(rt_device_t dev, int cmd, void *args)
  332. {
  333. rt_err_t err = RT_EOK;
  334. struct ds1307_rtc *ds1307 = raw_to_ds1307_rtc(dev);
  335. if (!args)
  336. {
  337. return -RT_EINVAL;
  338. }
  339. switch (cmd)
  340. {
  341. case RT_DEVICE_CTRL_RTC_GET_TIME:
  342. ds1307_rtc_read_time(ds1307, args);
  343. break;
  344. case RT_DEVICE_CTRL_RTC_SET_TIME:
  345. ds1307_rtc_set_time(ds1307, args);
  346. break;
  347. case RT_DEVICE_CTRL_RTC_GET_TIMEVAL:
  348. ds1307_rtc_read_time(ds1307, (time_t *)&((struct timeval *)args)->tv_sec);
  349. break;
  350. case RT_DEVICE_CTRL_RTC_SET_TIMEVAL:
  351. ds1307_rtc_set_time(ds1307, (time_t *)&((struct timeval *)args)->tv_sec);
  352. break;
  353. case RT_DEVICE_CTRL_RTC_GET_ALARM:
  354. err = ds1307_rtc_read_alarm(ds1307, args);
  355. break;
  356. case RT_DEVICE_CTRL_RTC_SET_ALARM:
  357. err = ds1307_rtc_set_alarm(ds1307, args);
  358. break;
  359. default:
  360. err = -RT_EINVAL;
  361. break;
  362. }
  363. return err;
  364. }
  365. #ifdef RT_USING_DEVICE_OPS
  366. const static struct rt_device_ops ds1307_rtc_ops =
  367. {
  368. .control = ds1307_rtc_control,
  369. };
  370. #endif
  371. static void ds1307_rtc_thread_isr(void *param)
  372. {
  373. struct ds1307_rtc *ds1307 = param;
  374. struct rt_i2c_client *client = ds1307->client;
  375. while (RT_TRUE)
  376. {
  377. rt_thread_suspend(ds1307->irq_thread);
  378. rt_schedule();
  379. if (ds1307->type == mcp794xx)
  380. {
  381. rt_int32_t reg = i2c_read_byte(client, MCP794XX_ALARM0_REG_ADDR);
  382. if (reg < 0 || !(reg & MCP794XX_BIT_ALMX_IF))
  383. {
  384. continue;
  385. }
  386. reg &= ~MCP794XX_BIT_ALMX_IF;
  387. if (i2c_write_byte(client, MCP794XX_ALARM0_REG_ADDR, reg) < 0)
  388. {
  389. continue;
  390. }
  391. if (i2c_update_byte_bits(client, RTC_CTL_REG_ADDR, MCP794XX_BIT_ALM0_EN, 0) < 0)
  392. {
  393. continue;
  394. }
  395. }
  396. else
  397. {
  398. rt_int32_t reg = i2c_read_byte(client, DS1337_STAT_REG_ADDR);
  399. if (reg < 0 || !(reg & RTC_STAT_BIT_A1I))
  400. {
  401. continue;
  402. }
  403. reg &= ~RTC_STAT_BIT_A1I;
  404. i2c_write_byte(client, DS1337_STAT_REG_ADDR, reg);
  405. if (i2c_update_byte_bits(client, DS1337_CTL_REG_ADDR, DS1337_CTL_BIT_A1IE, 0) < 0)
  406. {
  407. continue;
  408. }
  409. }
  410. rt_alarm_update(&ds1307->parent, 1);
  411. }
  412. }
  413. static void ds1307_rtc_isr(int irqno, void *param)
  414. {
  415. struct ds1307_rtc *ds1307 = param;
  416. rt_thread_resume(ds1307->irq_thread);
  417. }
  418. static rt_err_t ds1307_rtc_probe(struct rt_i2c_client *client)
  419. {
  420. rt_err_t err;
  421. const char *dev_name;
  422. struct rt_device *dev = &client->parent;
  423. struct ds1307_rtc *ds1307 = rt_calloc(1, sizeof(*ds1307));
  424. if (!ds1307)
  425. {
  426. return -RT_ENOMEM;
  427. }
  428. ds1307->type = (rt_ubase_t)rt_i2c_client_id_data(client);
  429. ds1307->irq = rt_dm_dev_get_irq(dev, 0);
  430. ds1307->client = client;
  431. if (ds1307->irq >= 0)
  432. {
  433. ds1307->irq_thread = rt_thread_create("rtc-ds1307", &ds1307_rtc_thread_isr,
  434. ds1307, DM_THREAD_STACK_SIZE, RT_THREAD_PRIORITY_MAX / 2, 10);
  435. if (!ds1307->irq_thread)
  436. {
  437. err = -RT_ERROR;
  438. LOG_E("Create RTC IRQ thread fail");
  439. goto _fail;
  440. }
  441. rt_thread_startup(ds1307->irq_thread);
  442. rt_hw_interrupt_install(ds1307->irq, ds1307_rtc_isr, ds1307, "rtc-ds1307");
  443. rt_hw_interrupt_umask(ds1307->irq);
  444. }
  445. dev->user_data = ds1307;
  446. ds1307->parent.type = RT_Device_Class_RTC;
  447. #ifdef RT_USING_DEVICE_OPS
  448. ds1307->parent.ops = &ds1307_rtc_ops;
  449. #else
  450. ds1307->parent.control = ds1307_rtc_control;
  451. #endif
  452. rtc_dev_set_name(&ds1307->parent);
  453. dev_name = rt_dm_dev_get_name(&ds1307->parent);
  454. rt_device_register(&ds1307->parent, dev_name, RT_DEVICE_FLAG_RDWR);
  455. return RT_EOK;
  456. _fail:
  457. if (ds1307->irq_thread)
  458. {
  459. rt_thread_delete(ds1307->irq_thread);
  460. }
  461. rt_free(ds1307);
  462. return err;
  463. }
  464. static rt_err_t ds1307_rtc_remove(struct rt_i2c_client *client)
  465. {
  466. struct ds1307_rtc *ds1307 = client->parent.user_data;
  467. if (ds1307->irq >= 0)
  468. {
  469. if (ds1307->wkalarm.enable)
  470. {
  471. ds1307_rtc_alarm_irq_enable(ds1307, RT_FALSE);
  472. }
  473. rt_hw_interrupt_mask(ds1307->irq);
  474. rt_pic_detach_irq(ds1307->irq, ds1307);
  475. rt_thread_delete(ds1307->irq_thread);
  476. }
  477. rt_device_unregister(&ds1307->parent);
  478. rt_free(ds1307);
  479. return RT_EOK;
  480. }
  481. static const struct rt_i2c_device_id ds1307_rtc_ids[] =
  482. {
  483. { .name = "ds1307", .data = (void *)ds1307 },
  484. { .name = "ds1337", .data = (void *)ds1337 },
  485. { .name = "ds1338", .data = (void *)ds1338 },
  486. { .name = "ds1339", .data = (void *)ds1339 },
  487. { .name = "ds1340", .data = (void *)ds1340 },
  488. { .name = "m41t11", .data = (void *)m41t11 },
  489. { .name = "mcp7940x", .data = (void *)mcp794xx },
  490. { .name = "mcp7941x", .data = (void *)mcp794xx },
  491. { /* sentinel */ },
  492. };
  493. static const struct rt_ofw_node_id ds1307_rtc_ofw_ids[] =
  494. {
  495. { .compatible = "dallas,ds1307", .data = (void *)ds1307 },
  496. { .compatible = "dallas,ds1337", .data = (void *)ds1337 },
  497. { .compatible = "dallas,ds1338", .data = (void *)ds1338 },
  498. { .compatible = "dallas,ds1339", .data = (void *)ds1339 },
  499. { .compatible = "dallas,ds1340", .data = (void *)ds1340 },
  500. { .compatible = "microchip,mcp7940x", .data = (void *)mcp794xx },
  501. { .compatible = "microchip,mcp7941x", .data = (void *)mcp794xx },
  502. { .compatible = "st,m41t11", .data = (void *)m41t11 },
  503. { /* sentinel */ },
  504. };
  505. static struct rt_i2c_driver ds1307_rtc_driver =
  506. {
  507. .ids = ds1307_rtc_ids,
  508. .ofw_ids = ds1307_rtc_ofw_ids,
  509. .probe = ds1307_rtc_probe,
  510. .remove = ds1307_rtc_remove,
  511. };
  512. RT_I2C_DRIVER_EXPORT(ds1307_rtc_driver);