rtc-pcf8563.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  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. * 2022-11-26 GuEe-GUI first version
  9. */
  10. #include <rtthread.h>
  11. #include <rtdevice.h>
  12. #define DBG_TAG "rtc.pcf8563"
  13. #define DBG_LVL DBG_INFO
  14. #include <rtdbg.h>
  15. #include "rtc_dm.h"
  16. #define PCF8563_REG_ST1 0x00 /* status */
  17. #define PCF8563_REG_ST2 0x01
  18. #define PCF8563_BIT_AIE RT_BIT(1)
  19. #define PCF8563_BIT_AF RT_BIT(3)
  20. #define PCF8563_BITS_ST2_N (7 << 5)
  21. #define PCF8563_REG_SC 0x02 /* datetime */
  22. #define PCF8563_REG_MN 0x03
  23. #define PCF8563_REG_HR 0x04
  24. #define PCF8563_REG_DM 0x05
  25. #define PCF8563_REG_DW 0x06
  26. #define PCF8563_REG_MO 0x07
  27. #define PCF8563_REG_YR 0x08
  28. #define PCF8563_REG_AMN 0x09 /* alarm */
  29. #define PCF8563_REG_CLKO 0x0d /* clock out */
  30. #define PCF8563_REG_CLKO_FE 0x80 /* clock out enabled */
  31. #define PCF8563_REG_CLKO_F_MASK 0x03 /* frequenc mask */
  32. #define PCF8563_REG_CLKO_F_32768H 0x00
  33. #define PCF8563_REG_CLKO_F_1024HZ 0x01
  34. #define PCF8563_REG_CLKO_F_32HZ 0x02
  35. #define PCF8563_REG_CLKO_F_1HZ 0x03
  36. #define PCF8563_REG_TMRC 0x0e /* timer control */
  37. #define PCF8563_TMRC_ENABLE RT_BIT(7)
  38. #define PCF8563_TMRC_4096 0
  39. #define PCF8563_TMRC_64 1
  40. #define PCF8563_TMRC_1 2
  41. #define PCF8563_TMRC_1_60 3
  42. #define PCF8563_TMRC_MASK 3
  43. #define PCF8563_REG_TMR 0x0f /* timer */
  44. #define PCF8563_SC_LV 0x80 /* low voltage */
  45. #define PCF8563_MO_C 0x80 /* century */
  46. struct pcf8563_rtc
  47. {
  48. struct rt_device parent;
  49. struct rt_clk_node clkout_hw;
  50. struct rt_clk_cell cell;
  51. struct rt_clk_cell *cells[1];
  52. int irq;
  53. int c_polarity;
  54. struct rt_i2c_client *client;
  55. struct rt_thread *irq_thread;
  56. struct rt_rtc_wkalarm wkalarm;
  57. };
  58. #define raw_to_pcf8563_rtc(raw) rt_container_of(raw, struct pcf8563_rtc, parent)
  59. #define raw_to_pcf8563_clkout(raw) rt_container_of(raw, struct pcf8563_rtc, clkout_hw)
  60. static rt_err_t pcf8563_read_block_data(struct pcf8563_rtc *pcf8563,
  61. rt_uint8_t reg, rt_uint8_t length, rt_uint8_t *buf)
  62. {
  63. rt_int32_t res;
  64. struct rt_i2c_msg msg[2];
  65. struct rt_i2c_client *client = pcf8563->client;
  66. msg[0].buf = &reg;
  67. msg[0].addr = client->client_addr;
  68. msg[0].len = 1;
  69. msg[0].flags = RT_I2C_WR;
  70. msg[1].buf = buf;
  71. msg[1].addr = client->client_addr;
  72. msg[1].len = length;
  73. msg[1].flags = RT_I2C_RD;
  74. res = rt_i2c_transfer(client->bus, msg, 2);
  75. return res > 0 ? RT_EOK : res;
  76. }
  77. static rt_err_t pcf8563_write_block_data(struct pcf8563_rtc *pcf8563,
  78. rt_uint8_t reg, rt_uint8_t length, rt_uint8_t *buf)
  79. {
  80. rt_int32_t res;
  81. struct rt_i2c_client *client = pcf8563->client;
  82. for (int i = 0; i < length; i++)
  83. {
  84. rt_uint8_t data[2] = { reg + i, buf[i] };
  85. res = rt_i2c_master_send(client->bus, client->client_addr,
  86. RT_I2C_WR, data, sizeof(data));
  87. if (res != sizeof(data))
  88. {
  89. return -RT_EIO;
  90. }
  91. }
  92. return RT_EOK;
  93. }
  94. static rt_err_t pcf8563_set_alarm_mode(struct pcf8563_rtc *pcf8563, rt_bool_t on)
  95. {
  96. rt_err_t err;
  97. rt_uint8_t buf;
  98. err = pcf8563_read_block_data(pcf8563, PCF8563_REG_ST2, 1, &buf);
  99. if (err)
  100. {
  101. return err;
  102. }
  103. if (on)
  104. {
  105. buf |= PCF8563_BIT_AIE;
  106. }
  107. else
  108. {
  109. buf &= ~PCF8563_BIT_AIE;
  110. }
  111. buf &= ~(PCF8563_BIT_AF | PCF8563_BITS_ST2_N);
  112. err = pcf8563_write_block_data(pcf8563, PCF8563_REG_ST2, 1, &buf);
  113. if (err)
  114. {
  115. LOG_E("Write %s error", "PCF8563_REG_ST2");
  116. return -RT_EIO;
  117. }
  118. return RT_EOK;
  119. }
  120. static rt_err_t pcf8563_get_alarm_mode(struct pcf8563_rtc *pcf8563,
  121. rt_uint8_t *en, rt_uint8_t *pen)
  122. {
  123. rt_err_t err;
  124. rt_uint8_t buf;
  125. err = pcf8563_read_block_data(pcf8563, PCF8563_REG_ST2, 1, &buf);
  126. if (err)
  127. {
  128. return err;
  129. }
  130. if (en)
  131. {
  132. *en = !!(buf & PCF8563_BIT_AIE);
  133. }
  134. if (pen)
  135. {
  136. *pen = !!(buf & PCF8563_BIT_AF);
  137. }
  138. return RT_EOK;
  139. }
  140. static int pcf8563_rtc_read_time(struct pcf8563_rtc *pcf8563, time_t *sec)
  141. {
  142. rt_err_t err;
  143. struct tm tm;
  144. rt_uint8_t buf[9];
  145. err = pcf8563_read_block_data(pcf8563, PCF8563_REG_ST1, 9, buf);
  146. if (err)
  147. {
  148. return err;
  149. }
  150. if (buf[PCF8563_REG_SC] & PCF8563_SC_LV)
  151. {
  152. LOG_E("Low voltage detected, date/time is not reliable");
  153. return -RT_EINVAL;
  154. }
  155. tm.tm_sec = rt_bcd2bin(buf[PCF8563_REG_SC] & 0x7f);
  156. tm.tm_min = rt_bcd2bin(buf[PCF8563_REG_MN] & 0x7f);
  157. tm.tm_hour = rt_bcd2bin(buf[PCF8563_REG_HR] & 0x3f); /* rtc hr 0-23 */
  158. tm.tm_mday = rt_bcd2bin(buf[PCF8563_REG_DM] & 0x3f);
  159. tm.tm_wday = buf[PCF8563_REG_DW] & 0x07;
  160. tm.tm_mon = rt_bcd2bin(buf[PCF8563_REG_MO] & 0x1f) - 1; /* rtc mn 1-12 */
  161. tm.tm_year = rt_bcd2bin(buf[PCF8563_REG_YR]) + 100;
  162. /* detect the polarity heuristically. see note above. */
  163. pcf8563->c_polarity = (buf[PCF8563_REG_MO] & PCF8563_MO_C) ?
  164. (tm.tm_year >= 100) : (tm.tm_year < 100);
  165. *sec = timegm(&tm);
  166. return RT_EOK;
  167. }
  168. static int pcf8563_rtc_set_time(struct pcf8563_rtc *pcf8563, time_t *sec)
  169. {
  170. struct tm *tm;
  171. rt_uint8_t buf[9];
  172. tm = localtime(sec);
  173. /* hours, minutes and seconds */
  174. buf[PCF8563_REG_SC] = rt_bin2bcd(tm->tm_sec);
  175. buf[PCF8563_REG_MN] = rt_bin2bcd(tm->tm_min);
  176. buf[PCF8563_REG_HR] = rt_bin2bcd(tm->tm_hour);
  177. buf[PCF8563_REG_DM] = rt_bin2bcd(tm->tm_mday);
  178. /* month, 1 - 12 */
  179. buf[PCF8563_REG_MO] = rt_bin2bcd(tm->tm_mon + 1);
  180. /* year and century */
  181. buf[PCF8563_REG_YR] = rt_bin2bcd(tm->tm_year - 100);
  182. if (pcf8563->c_polarity ? (tm->tm_year >= 100) : (tm->tm_year < 100))
  183. {
  184. buf[PCF8563_REG_MO] |= PCF8563_MO_C;
  185. }
  186. buf[PCF8563_REG_DW] = tm->tm_wday & 0x07;
  187. return pcf8563_write_block_data(pcf8563, PCF8563_REG_SC,
  188. 9 - PCF8563_REG_SC, buf + PCF8563_REG_SC);
  189. }
  190. static int pcf8563_rtc_read_alarm(struct pcf8563_rtc *pcf8563,
  191. struct rt_rtc_wkalarm *alarm)
  192. {
  193. rt_err_t err;
  194. rt_uint8_t pending, buf[4];
  195. err = pcf8563_read_block_data(pcf8563, PCF8563_REG_AMN, 4, buf);
  196. if (err)
  197. {
  198. return err;
  199. }
  200. alarm->tm_sec = 0;
  201. alarm->tm_min = rt_bcd2bin(buf[0] & 0x7f);
  202. alarm->tm_hour = rt_bcd2bin(buf[1] & 0x3f);
  203. alarm->tm_mday = rt_bcd2bin(buf[2] & 0x3f);
  204. /* alarm->tm_wday = rt_bcd2bin(buf[3] & 0x7); */
  205. return pcf8563_get_alarm_mode(pcf8563, (rt_uint8_t *)&alarm->enable, &pending);
  206. }
  207. static int pcf8563_rtc_set_alarm(struct pcf8563_rtc *pcf8563,
  208. struct rt_rtc_wkalarm *alarm)
  209. {
  210. rt_err_t err;
  211. rt_uint8_t buf[4];
  212. struct rt_rtc_wkalarm *wkalarm = &pcf8563->wkalarm;
  213. buf[0] = rt_bin2bcd(alarm->tm_min);
  214. buf[1] = rt_bin2bcd(alarm->tm_hour);
  215. buf[2] = rt_bin2bcd(alarm->tm_mday);
  216. buf[3] = 0 & 0x07; /* alarm->tm_wday */
  217. err = pcf8563_write_block_data(pcf8563, PCF8563_REG_AMN, 4, buf);
  218. if (err)
  219. {
  220. return err;
  221. }
  222. err = pcf8563_set_alarm_mode(pcf8563, alarm->enable);
  223. if (!err)
  224. {
  225. wkalarm->enable = alarm->enable;
  226. wkalarm->tm_hour = alarm->tm_hour;
  227. wkalarm->tm_min = alarm->tm_min;
  228. wkalarm->tm_sec = alarm->tm_sec;
  229. }
  230. return err;
  231. }
  232. static rt_err_t pcf8563_rtc_control(rt_device_t dev, int cmd, void *args)
  233. {
  234. rt_err_t err = RT_EOK;
  235. struct pcf8563_rtc *pcf8563 = raw_to_pcf8563_rtc(dev);
  236. if (!args)
  237. {
  238. return -RT_EINVAL;
  239. }
  240. switch (cmd)
  241. {
  242. case RT_DEVICE_CTRL_RTC_GET_TIME:
  243. err = pcf8563_rtc_read_time(pcf8563, args);
  244. break;
  245. case RT_DEVICE_CTRL_RTC_SET_TIME:
  246. err = pcf8563_rtc_set_time(pcf8563, args);
  247. break;
  248. case RT_DEVICE_CTRL_RTC_GET_TIMEVAL:
  249. err = pcf8563_rtc_read_time(pcf8563, (time_t *)&((struct timeval *)args)->tv_sec);
  250. break;
  251. case RT_DEVICE_CTRL_RTC_SET_TIMEVAL:
  252. err = pcf8563_rtc_set_time(pcf8563, (time_t *)&((struct timeval *)args)->tv_sec);
  253. break;
  254. case RT_DEVICE_CTRL_RTC_GET_ALARM:
  255. err = pcf8563_rtc_read_alarm(pcf8563, args);
  256. break;
  257. case RT_DEVICE_CTRL_RTC_SET_ALARM:
  258. err = pcf8563_rtc_set_alarm(pcf8563, args);
  259. break;
  260. default:
  261. err = -RT_EINVAL;
  262. break;
  263. }
  264. return err;
  265. }
  266. #ifdef RT_USING_DEVICE_OPS
  267. const static struct rt_device_ops pcf8563_rtc_ops =
  268. {
  269. .control = pcf8563_rtc_control,
  270. };
  271. #endif
  272. static void pcf8563_rtc_thread_isr(void *param)
  273. {
  274. rt_err_t err;
  275. rt_uint8_t pending;
  276. struct pcf8563_rtc *pcf8563 = param;
  277. while (RT_TRUE)
  278. {
  279. rt_thread_suspend(pcf8563->irq_thread);
  280. rt_schedule();
  281. err = pcf8563_get_alarm_mode(pcf8563, NULL, &pending);
  282. if (err)
  283. {
  284. continue;
  285. }
  286. if (pending)
  287. {
  288. rt_alarm_update(&pcf8563->parent, 1);
  289. pcf8563_set_alarm_mode(pcf8563, 1);
  290. }
  291. }
  292. }
  293. static void pcf8563_rtc_isr(int irqno, void *param)
  294. {
  295. struct pcf8563_rtc *pcf8563 = param;
  296. rt_thread_resume(pcf8563->irq_thread);
  297. }
  298. static const int clkout_rates[] =
  299. {
  300. 32768, 1024, 32, 1,
  301. };
  302. static rt_err_t pcf8563_clkout_control(struct pcf8563_rtc *pcf8563, rt_bool_t enable)
  303. {
  304. rt_err_t err;
  305. rt_uint8_t buf;
  306. if ((err = pcf8563_read_block_data(pcf8563, PCF8563_REG_CLKO, 1, &buf)))
  307. {
  308. return err;
  309. }
  310. if (enable)
  311. {
  312. buf |= PCF8563_REG_CLKO_FE;
  313. }
  314. else
  315. {
  316. buf &= ~PCF8563_REG_CLKO_FE;
  317. }
  318. return pcf8563_write_block_data(pcf8563, PCF8563_REG_CLKO, 1, &buf);
  319. }
  320. static rt_err_t pcf8563_clkout_prepare(struct rt_clk_cell *cell)
  321. {
  322. struct pcf8563_rtc *pcf8563 = raw_to_pcf8563_clkout(cell->clk_np);
  323. return pcf8563_clkout_control(pcf8563, RT_TRUE);
  324. }
  325. static void pcf8563_clkout_unprepare(struct rt_clk_cell *cell)
  326. {
  327. struct pcf8563_rtc *pcf8563 = raw_to_pcf8563_clkout(cell->clk_np);
  328. pcf8563_clkout_control(pcf8563, RT_FALSE);
  329. }
  330. static rt_bool_t pcf8563_clkout_is_prepared(struct rt_clk_cell *cell)
  331. {
  332. rt_uint8_t buf;
  333. struct pcf8563_rtc *pcf8563 = raw_to_pcf8563_clkout(cell->clk_np);
  334. if (pcf8563_read_block_data(pcf8563, PCF8563_REG_CLKO, 1, &buf))
  335. {
  336. return RT_FALSE;
  337. }
  338. return !!(buf & PCF8563_REG_CLKO_FE);
  339. }
  340. static rt_ubase_t pcf8563_clkout_recalc_rate(struct rt_clk_cell *cell, rt_ubase_t parent_rate)
  341. {
  342. rt_err_t err;
  343. rt_uint8_t buf;
  344. struct pcf8563_rtc *pcf8563 = raw_to_pcf8563_clkout(cell->clk_np);
  345. err = pcf8563_read_block_data(pcf8563, PCF8563_REG_CLKO, 1, &buf);
  346. if (err)
  347. {
  348. return err;
  349. }
  350. buf &= PCF8563_REG_CLKO_F_MASK;
  351. return clkout_rates[buf];
  352. }
  353. static rt_base_t pcf8563_clkout_round_rate(struct rt_clk_cell *cell, rt_ubase_t drate,
  354. rt_ubase_t *prate)
  355. {
  356. for (int i = 0; i < RT_ARRAY_SIZE(clkout_rates); ++i)
  357. {
  358. if (clkout_rates[i] <= drate)
  359. {
  360. return clkout_rates[i];
  361. }
  362. }
  363. return 0;
  364. }
  365. static rt_err_t pcf8563_clkout_set_rate(struct rt_clk_cell *cell, rt_ubase_t rate,
  366. rt_ubase_t parent_rate)
  367. {
  368. rt_err_t err;
  369. rt_uint8_t buf;
  370. struct pcf8563_rtc *pcf8563 = raw_to_pcf8563_clkout(cell->clk_np);
  371. err = pcf8563_read_block_data(pcf8563, PCF8563_REG_CLKO, 1, &buf);
  372. if (err)
  373. {
  374. return err;
  375. }
  376. for (int i = 0; i < RT_ARRAY_SIZE(clkout_rates); ++i)
  377. {
  378. if (clkout_rates[i] == rate)
  379. {
  380. buf &= ~PCF8563_REG_CLKO_F_MASK;
  381. buf |= i;
  382. return pcf8563_write_block_data(pcf8563, PCF8563_REG_CLKO, 1, &buf);
  383. }
  384. }
  385. return -RT_EINVAL;
  386. }
  387. static const struct rt_clk_ops pcf8563_clkout_ops =
  388. {
  389. .prepare = pcf8563_clkout_prepare,
  390. .unprepare = pcf8563_clkout_unprepare,
  391. .is_prepared = pcf8563_clkout_is_prepared,
  392. .recalc_rate = pcf8563_clkout_recalc_rate,
  393. .round_rate = pcf8563_clkout_round_rate,
  394. .set_rate = pcf8563_clkout_set_rate,
  395. };
  396. static void pcf8563_clkout_register_clk(struct pcf8563_rtc *pcf8563, struct rt_device *dev)
  397. {
  398. rt_uint8_t buf = 0;
  399. /* Disable the clkout output */
  400. if (pcf8563_write_block_data(pcf8563, PCF8563_REG_CLKO, 1, &buf))
  401. {
  402. return;
  403. }
  404. pcf8563->cells[0] = &pcf8563->cell;
  405. pcf8563->cell.name = "pcf8563-clkout";
  406. pcf8563->cell.ops = &pcf8563_clkout_ops;
  407. rt_dm_dev_prop_read_string(dev, "clock-output-names", &pcf8563->cell.name);
  408. pcf8563->clkout_hw.dev = dev;
  409. pcf8563->clkout_hw.cells_nr = 1;
  410. pcf8563->clkout_hw.cells = pcf8563->cells;
  411. if (rt_clk_register(&pcf8563->clkout_hw))
  412. {
  413. return;
  414. }
  415. }
  416. static rt_err_t pcf8563_rtc_probe(struct rt_i2c_client *client)
  417. {
  418. rt_err_t err;
  419. rt_uint8_t buf;
  420. const char *dev_name;
  421. struct rt_device *dev = &client->parent;
  422. struct pcf8563_rtc *pcf8563 = rt_calloc(1, sizeof(*pcf8563));
  423. if (!pcf8563)
  424. {
  425. return -RT_ENOMEM;
  426. }
  427. pcf8563->irq = rt_dm_dev_get_irq(dev, 0);
  428. pcf8563->client = client;
  429. /* Set timer to lowest frequency to save power (ref Haoyu datasheet) */
  430. buf = PCF8563_TMRC_1_60;
  431. if ((err = pcf8563_write_block_data(pcf8563, PCF8563_REG_TMRC, 1, &buf)))
  432. {
  433. LOG_E("Write %s error", "PCF8563_REG_TMRC");
  434. goto _fail;
  435. }
  436. /* Clear flags and disable interrupts */
  437. buf = 0;
  438. if ((err = pcf8563_write_block_data(pcf8563, PCF8563_REG_ST2, 1, &buf)))
  439. {
  440. LOG_E("Write %s error", "PCF8563_REG_ST2");
  441. goto _fail;
  442. }
  443. if (pcf8563->irq >= 0)
  444. {
  445. pcf8563->irq_thread = rt_thread_create("rtc-pcf8563", &pcf8563_rtc_thread_isr,
  446. pcf8563, DM_THREAD_STACK_SIZE, RT_THREAD_PRIORITY_MAX / 2, 10);
  447. if (!pcf8563->irq_thread)
  448. {
  449. err = -RT_ERROR;
  450. LOG_E("Create RTC IRQ thread fail");
  451. goto _fail;
  452. }
  453. rt_thread_startup(pcf8563->irq_thread);
  454. rt_hw_interrupt_install(pcf8563->irq, pcf8563_rtc_isr, pcf8563, "rtc-pcf8563");
  455. rt_hw_interrupt_umask(pcf8563->irq);
  456. }
  457. dev->user_data = pcf8563;
  458. pcf8563->parent.type = RT_Device_Class_RTC;
  459. #ifdef RT_USING_DEVICE_OPS
  460. pcf8563->parent.ops = &pcf8563_rtc_ops;
  461. #else
  462. pcf8563->parent.control = pcf8563_rtc_control;
  463. #endif
  464. rtc_dev_set_name(&pcf8563->parent);
  465. dev_name = rt_dm_dev_get_name(&pcf8563->parent);
  466. rt_device_register(&pcf8563->parent, dev_name, RT_DEVICE_FLAG_RDWR);
  467. pcf8563_clkout_register_clk(pcf8563, dev);
  468. return RT_EOK;
  469. _fail:
  470. if (pcf8563->irq_thread)
  471. {
  472. rt_thread_delete(pcf8563->irq_thread);
  473. }
  474. rt_free(pcf8563);
  475. return err;
  476. }
  477. static rt_err_t pcf8563_rtc_remove(struct rt_i2c_client *client)
  478. {
  479. struct pcf8563_rtc *pcf8563 = client->parent.user_data;
  480. rt_dm_dev_unbind_fwdata(&client->parent, RT_NULL);
  481. if (pcf8563->irq >= 0)
  482. {
  483. if (pcf8563->wkalarm.enable)
  484. {
  485. pcf8563_set_alarm_mode(pcf8563, RT_FALSE);
  486. }
  487. rt_hw_interrupt_mask(pcf8563->irq);
  488. rt_pic_detach_irq(pcf8563->irq, pcf8563);
  489. rt_thread_delete(pcf8563->irq_thread);
  490. }
  491. if (pcf8563->cells[0])
  492. {
  493. rt_clk_unregister(&pcf8563->clkout_hw);
  494. }
  495. rt_device_unregister(&pcf8563->parent);
  496. rt_free(pcf8563);
  497. return RT_EOK;
  498. }
  499. static const struct rt_i2c_device_id pcf8563_rtc_ids[] =
  500. {
  501. { .name = "pcf8563" },
  502. { .name = "rtc8564" },
  503. { .name = "pca8565" },
  504. { /* sentinel */ },
  505. };
  506. static const struct rt_ofw_node_id pcf8563_rtc_ofw_ids[] =
  507. {
  508. { .compatible = "nxp,pcf8563" },
  509. { .compatible = "epson,rtc8564" },
  510. { .compatible = "microcrystal,rv8564" },
  511. { .compatible = "nxp,pca8565" },
  512. { /* sentinel */ },
  513. };
  514. static struct rt_i2c_driver pcf8563_rtc_driver =
  515. {
  516. .ids = pcf8563_rtc_ids,
  517. .ofw_ids = pcf8563_rtc_ofw_ids,
  518. .probe = pcf8563_rtc_probe,
  519. .remove = pcf8563_rtc_remove,
  520. };
  521. RT_I2C_DRIVER_EXPORT(pcf8563_rtc_driver);