rtc-nct3018y.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (c) 2022 Nuvoton Technology Corporation
  3. #include <linux/bcd.h>
  4. #include <linux/clk-provider.h>
  5. #include <linux/err.h>
  6. #include <linux/i2c.h>
  7. #include <linux/module.h>
  8. #include <linux/of.h>
  9. #include <linux/rtc.h>
  10. #include <linux/slab.h>
  11. #define NCT3018Y_REG_SC 0x00 /* seconds */
  12. #define NCT3018Y_REG_SCA 0x01 /* alarm */
  13. #define NCT3018Y_REG_MN 0x02
  14. #define NCT3018Y_REG_MNA 0x03 /* alarm */
  15. #define NCT3018Y_REG_HR 0x04
  16. #define NCT3018Y_REG_HRA 0x05 /* alarm */
  17. #define NCT3018Y_REG_DW 0x06
  18. #define NCT3018Y_REG_DM 0x07
  19. #define NCT3018Y_REG_MO 0x08
  20. #define NCT3018Y_REG_YR 0x09
  21. #define NCT3018Y_REG_CTRL 0x0A /* timer control */
  22. #define NCT3018Y_REG_ST 0x0B /* status */
  23. #define NCT3018Y_REG_CLKO 0x0C /* clock out */
  24. #define NCT3018Y_REG_PART 0x21 /* part info */
  25. #define NCT3018Y_BIT_AF BIT(7)
  26. #define NCT3018Y_BIT_ST BIT(7)
  27. #define NCT3018Y_BIT_DM BIT(6)
  28. #define NCT3018Y_BIT_HF BIT(5)
  29. #define NCT3018Y_BIT_DSM BIT(4)
  30. #define NCT3018Y_BIT_AIE BIT(3)
  31. #define NCT3018Y_BIT_OFIE BIT(2)
  32. #define NCT3018Y_BIT_CIE BIT(1)
  33. #define NCT3018Y_BIT_TWO BIT(0)
  34. #define NCT3018Y_REG_BAT_MASK 0x07
  35. #define NCT3018Y_REG_CLKO_F_MASK 0x03 /* frequenc mask */
  36. #define NCT3018Y_REG_CLKO_CKE 0x80 /* clock out enabled */
  37. #define NCT3018Y_REG_PART_NCT3018Y 0x02
  38. struct nct3018y {
  39. struct rtc_device *rtc;
  40. struct i2c_client *client;
  41. int part_num;
  42. #ifdef CONFIG_COMMON_CLK
  43. struct clk_hw clkout_hw;
  44. #endif
  45. };
  46. static int nct3018y_set_alarm_mode(struct i2c_client *client, bool on)
  47. {
  48. int err, flags;
  49. dev_dbg(&client->dev, "%s:on:%d\n", __func__, on);
  50. flags = i2c_smbus_read_byte_data(client, NCT3018Y_REG_CTRL);
  51. if (flags < 0) {
  52. dev_dbg(&client->dev,
  53. "Failed to read NCT3018Y_REG_CTRL\n");
  54. return flags;
  55. }
  56. if (on)
  57. flags |= NCT3018Y_BIT_AIE;
  58. else
  59. flags &= ~NCT3018Y_BIT_AIE;
  60. flags |= NCT3018Y_BIT_CIE;
  61. err = i2c_smbus_write_byte_data(client, NCT3018Y_REG_CTRL, flags);
  62. if (err < 0) {
  63. dev_dbg(&client->dev, "Unable to write NCT3018Y_REG_CTRL\n");
  64. return err;
  65. }
  66. flags = i2c_smbus_read_byte_data(client, NCT3018Y_REG_ST);
  67. if (flags < 0) {
  68. dev_dbg(&client->dev,
  69. "Failed to read NCT3018Y_REG_ST\n");
  70. return flags;
  71. }
  72. flags &= ~(NCT3018Y_BIT_AF);
  73. err = i2c_smbus_write_byte_data(client, NCT3018Y_REG_ST, flags);
  74. if (err < 0) {
  75. dev_dbg(&client->dev, "Unable to write NCT3018Y_REG_ST\n");
  76. return err;
  77. }
  78. return 0;
  79. }
  80. static int nct3018y_get_alarm_mode(struct i2c_client *client, unsigned char *alarm_enable,
  81. unsigned char *alarm_flag)
  82. {
  83. int flags;
  84. if (alarm_enable) {
  85. dev_dbg(&client->dev, "%s:NCT3018Y_REG_CTRL\n", __func__);
  86. flags = i2c_smbus_read_byte_data(client, NCT3018Y_REG_CTRL);
  87. if (flags < 0)
  88. return flags;
  89. *alarm_enable = flags & NCT3018Y_BIT_AIE;
  90. dev_dbg(&client->dev, "%s:alarm_enable:%x\n", __func__, *alarm_enable);
  91. }
  92. if (alarm_flag) {
  93. dev_dbg(&client->dev, "%s:NCT3018Y_REG_ST\n", __func__);
  94. flags = i2c_smbus_read_byte_data(client, NCT3018Y_REG_ST);
  95. if (flags < 0)
  96. return flags;
  97. *alarm_flag = flags & NCT3018Y_BIT_AF;
  98. dev_dbg(&client->dev, "%s:alarm_flag:%x\n", __func__, *alarm_flag);
  99. }
  100. return 0;
  101. }
  102. static irqreturn_t nct3018y_irq(int irq, void *dev_id)
  103. {
  104. struct nct3018y *nct3018y = i2c_get_clientdata(dev_id);
  105. struct i2c_client *client = nct3018y->client;
  106. int err;
  107. unsigned char alarm_flag;
  108. unsigned char alarm_enable;
  109. dev_dbg(&client->dev, "%s:irq:%d\n", __func__, irq);
  110. err = nct3018y_get_alarm_mode(nct3018y->client, &alarm_enable, &alarm_flag);
  111. if (err)
  112. return IRQ_NONE;
  113. if (alarm_flag) {
  114. dev_dbg(&client->dev, "%s:alarm flag:%x\n",
  115. __func__, alarm_flag);
  116. rtc_update_irq(nct3018y->rtc, 1, RTC_IRQF | RTC_AF);
  117. nct3018y_set_alarm_mode(nct3018y->client, 0);
  118. dev_dbg(&client->dev, "%s:IRQ_HANDLED\n", __func__);
  119. return IRQ_HANDLED;
  120. }
  121. return IRQ_NONE;
  122. }
  123. /*
  124. * In the routines that deal directly with the nct3018y hardware, we use
  125. * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch.
  126. */
  127. static int nct3018y_rtc_read_time(struct device *dev, struct rtc_time *tm)
  128. {
  129. struct i2c_client *client = to_i2c_client(dev);
  130. unsigned char buf[10];
  131. int err;
  132. err = i2c_smbus_read_i2c_block_data(client, NCT3018Y_REG_ST, 1, buf);
  133. if (err < 0)
  134. return err;
  135. if (!buf[0]) {
  136. dev_dbg(&client->dev, " voltage <=1.7, date/time is not reliable.\n");
  137. return -EINVAL;
  138. }
  139. err = i2c_smbus_read_i2c_block_data(client, NCT3018Y_REG_SC, sizeof(buf), buf);
  140. if (err < 0)
  141. return err;
  142. tm->tm_sec = bcd2bin(buf[0] & 0x7F);
  143. tm->tm_min = bcd2bin(buf[2] & 0x7F);
  144. tm->tm_hour = bcd2bin(buf[4] & 0x3F);
  145. tm->tm_wday = buf[6] & 0x07;
  146. tm->tm_mday = bcd2bin(buf[7] & 0x3F);
  147. tm->tm_mon = bcd2bin(buf[8] & 0x1F) - 1;
  148. tm->tm_year = bcd2bin(buf[9]) + 100;
  149. return 0;
  150. }
  151. static int nct3018y_rtc_set_time(struct device *dev, struct rtc_time *tm)
  152. {
  153. struct i2c_client *client = to_i2c_client(dev);
  154. struct nct3018y *nct3018y = dev_get_drvdata(dev);
  155. unsigned char buf[4] = {0};
  156. int err, flags;
  157. int restore_flags = 0;
  158. flags = i2c_smbus_read_byte_data(client, NCT3018Y_REG_CTRL);
  159. if (flags < 0) {
  160. dev_dbg(&client->dev, "Failed to read NCT3018Y_REG_CTRL.\n");
  161. return flags;
  162. }
  163. /* Check and set TWO bit */
  164. if (nct3018y->part_num == NCT3018Y_REG_PART_NCT3018Y && !(flags & NCT3018Y_BIT_TWO)) {
  165. restore_flags = 1;
  166. flags |= NCT3018Y_BIT_TWO;
  167. err = i2c_smbus_write_byte_data(client, NCT3018Y_REG_CTRL, flags);
  168. if (err < 0) {
  169. dev_dbg(&client->dev, "Unable to write NCT3018Y_REG_CTRL.\n");
  170. return err;
  171. }
  172. }
  173. buf[0] = bin2bcd(tm->tm_sec);
  174. err = i2c_smbus_write_byte_data(client, NCT3018Y_REG_SC, buf[0]);
  175. if (err < 0) {
  176. dev_dbg(&client->dev, "Unable to write NCT3018Y_REG_SC\n");
  177. return err;
  178. }
  179. buf[0] = bin2bcd(tm->tm_min);
  180. err = i2c_smbus_write_byte_data(client, NCT3018Y_REG_MN, buf[0]);
  181. if (err < 0) {
  182. dev_dbg(&client->dev, "Unable to write NCT3018Y_REG_MN\n");
  183. return err;
  184. }
  185. buf[0] = bin2bcd(tm->tm_hour);
  186. err = i2c_smbus_write_byte_data(client, NCT3018Y_REG_HR, buf[0]);
  187. if (err < 0) {
  188. dev_dbg(&client->dev, "Unable to write NCT3018Y_REG_HR\n");
  189. return err;
  190. }
  191. buf[0] = tm->tm_wday & 0x07;
  192. buf[1] = bin2bcd(tm->tm_mday);
  193. buf[2] = bin2bcd(tm->tm_mon + 1);
  194. buf[3] = bin2bcd(tm->tm_year - 100);
  195. err = i2c_smbus_write_i2c_block_data(client, NCT3018Y_REG_DW,
  196. sizeof(buf), buf);
  197. if (err < 0) {
  198. dev_dbg(&client->dev, "Unable to write for day and mon and year\n");
  199. return -EIO;
  200. }
  201. /* Restore TWO bit */
  202. if (restore_flags) {
  203. if (nct3018y->part_num == NCT3018Y_REG_PART_NCT3018Y)
  204. flags &= ~NCT3018Y_BIT_TWO;
  205. err = i2c_smbus_write_byte_data(client, NCT3018Y_REG_CTRL, flags);
  206. if (err < 0) {
  207. dev_dbg(&client->dev, "Unable to write NCT3018Y_REG_CTRL.\n");
  208. return err;
  209. }
  210. }
  211. return err;
  212. }
  213. static int nct3018y_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *tm)
  214. {
  215. struct i2c_client *client = to_i2c_client(dev);
  216. unsigned char buf[5];
  217. int err;
  218. err = i2c_smbus_read_i2c_block_data(client, NCT3018Y_REG_SCA,
  219. sizeof(buf), buf);
  220. if (err < 0) {
  221. dev_dbg(&client->dev, "Unable to read date\n");
  222. return -EIO;
  223. }
  224. dev_dbg(&client->dev, "%s: raw data is sec=%02x, min=%02x hr=%02x\n",
  225. __func__, buf[0], buf[2], buf[4]);
  226. tm->time.tm_sec = bcd2bin(buf[0] & 0x7F);
  227. tm->time.tm_min = bcd2bin(buf[2] & 0x7F);
  228. tm->time.tm_hour = bcd2bin(buf[4] & 0x3F);
  229. err = nct3018y_get_alarm_mode(client, &tm->enabled, &tm->pending);
  230. if (err < 0)
  231. return err;
  232. dev_dbg(&client->dev, "%s:s=%d m=%d, hr=%d, enabled=%d, pending=%d\n",
  233. __func__, tm->time.tm_sec, tm->time.tm_min,
  234. tm->time.tm_hour, tm->enabled, tm->pending);
  235. return 0;
  236. }
  237. static int nct3018y_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *tm)
  238. {
  239. struct i2c_client *client = to_i2c_client(dev);
  240. int err;
  241. dev_dbg(dev, "%s, sec=%d, min=%d hour=%d tm->enabled:%d\n",
  242. __func__, tm->time.tm_sec, tm->time.tm_min, tm->time.tm_hour,
  243. tm->enabled);
  244. err = i2c_smbus_write_byte_data(client, NCT3018Y_REG_SCA, bin2bcd(tm->time.tm_sec));
  245. if (err < 0) {
  246. dev_dbg(&client->dev, "Unable to write NCT3018Y_REG_SCA\n");
  247. return err;
  248. }
  249. err = i2c_smbus_write_byte_data(client, NCT3018Y_REG_MNA, bin2bcd(tm->time.tm_min));
  250. if (err < 0) {
  251. dev_dbg(&client->dev, "Unable to write NCT3018Y_REG_MNA\n");
  252. return err;
  253. }
  254. err = i2c_smbus_write_byte_data(client, NCT3018Y_REG_HRA, bin2bcd(tm->time.tm_hour));
  255. if (err < 0) {
  256. dev_dbg(&client->dev, "Unable to write NCT3018Y_REG_HRA\n");
  257. return err;
  258. }
  259. return nct3018y_set_alarm_mode(client, tm->enabled);
  260. }
  261. static int nct3018y_irq_enable(struct device *dev, unsigned int enabled)
  262. {
  263. dev_dbg(dev, "%s: alarm enable=%d\n", __func__, enabled);
  264. return nct3018y_set_alarm_mode(to_i2c_client(dev), enabled);
  265. }
  266. static int nct3018y_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
  267. {
  268. struct i2c_client *client = to_i2c_client(dev);
  269. int status, flags = 0;
  270. switch (cmd) {
  271. case RTC_VL_READ:
  272. status = i2c_smbus_read_byte_data(client, NCT3018Y_REG_ST);
  273. if (status < 0)
  274. return status;
  275. if (!(status & NCT3018Y_REG_BAT_MASK))
  276. flags |= RTC_VL_DATA_INVALID;
  277. return put_user(flags, (unsigned int __user *)arg);
  278. default:
  279. return -ENOIOCTLCMD;
  280. }
  281. }
  282. #ifdef CONFIG_COMMON_CLK
  283. /*
  284. * Handling of the clkout
  285. */
  286. #define clkout_hw_to_nct3018y(_hw) container_of(_hw, struct nct3018y, clkout_hw)
  287. static const int clkout_rates[] = {
  288. 32768,
  289. 1024,
  290. 32,
  291. 1,
  292. };
  293. static unsigned long nct3018y_clkout_recalc_rate(struct clk_hw *hw,
  294. unsigned long parent_rate)
  295. {
  296. struct nct3018y *nct3018y = clkout_hw_to_nct3018y(hw);
  297. struct i2c_client *client = nct3018y->client;
  298. int flags;
  299. flags = i2c_smbus_read_byte_data(client, NCT3018Y_REG_CLKO);
  300. if (flags < 0)
  301. return 0;
  302. flags &= NCT3018Y_REG_CLKO_F_MASK;
  303. return clkout_rates[flags];
  304. }
  305. static long nct3018y_clkout_round_rate(struct clk_hw *hw, unsigned long rate,
  306. unsigned long *prate)
  307. {
  308. int i;
  309. for (i = 0; i < ARRAY_SIZE(clkout_rates); i++)
  310. if (clkout_rates[i] <= rate)
  311. return clkout_rates[i];
  312. return 0;
  313. }
  314. static int nct3018y_clkout_set_rate(struct clk_hw *hw, unsigned long rate,
  315. unsigned long parent_rate)
  316. {
  317. struct nct3018y *nct3018y = clkout_hw_to_nct3018y(hw);
  318. struct i2c_client *client = nct3018y->client;
  319. int i, flags;
  320. flags = i2c_smbus_read_byte_data(client, NCT3018Y_REG_CLKO);
  321. if (flags < 0)
  322. return flags;
  323. for (i = 0; i < ARRAY_SIZE(clkout_rates); i++)
  324. if (clkout_rates[i] == rate) {
  325. flags &= ~NCT3018Y_REG_CLKO_F_MASK;
  326. flags |= i;
  327. return i2c_smbus_write_byte_data(client, NCT3018Y_REG_CLKO, flags);
  328. }
  329. return -EINVAL;
  330. }
  331. static int nct3018y_clkout_control(struct clk_hw *hw, bool enable)
  332. {
  333. struct nct3018y *nct3018y = clkout_hw_to_nct3018y(hw);
  334. struct i2c_client *client = nct3018y->client;
  335. int flags;
  336. flags = i2c_smbus_read_byte_data(client, NCT3018Y_REG_CLKO);
  337. if (flags < 0)
  338. return flags;
  339. if (enable)
  340. flags |= NCT3018Y_REG_CLKO_CKE;
  341. else
  342. flags &= ~NCT3018Y_REG_CLKO_CKE;
  343. return i2c_smbus_write_byte_data(client, NCT3018Y_REG_CLKO, flags);
  344. }
  345. static int nct3018y_clkout_prepare(struct clk_hw *hw)
  346. {
  347. return nct3018y_clkout_control(hw, 1);
  348. }
  349. static void nct3018y_clkout_unprepare(struct clk_hw *hw)
  350. {
  351. nct3018y_clkout_control(hw, 0);
  352. }
  353. static int nct3018y_clkout_is_prepared(struct clk_hw *hw)
  354. {
  355. struct nct3018y *nct3018y = clkout_hw_to_nct3018y(hw);
  356. struct i2c_client *client = nct3018y->client;
  357. int flags;
  358. flags = i2c_smbus_read_byte_data(client, NCT3018Y_REG_CLKO);
  359. if (flags < 0)
  360. return flags;
  361. return flags & NCT3018Y_REG_CLKO_CKE;
  362. }
  363. static const struct clk_ops nct3018y_clkout_ops = {
  364. .prepare = nct3018y_clkout_prepare,
  365. .unprepare = nct3018y_clkout_unprepare,
  366. .is_prepared = nct3018y_clkout_is_prepared,
  367. .recalc_rate = nct3018y_clkout_recalc_rate,
  368. .round_rate = nct3018y_clkout_round_rate,
  369. .set_rate = nct3018y_clkout_set_rate,
  370. };
  371. static struct clk *nct3018y_clkout_register_clk(struct nct3018y *nct3018y)
  372. {
  373. struct i2c_client *client = nct3018y->client;
  374. struct device_node *node = client->dev.of_node;
  375. struct clk *clk;
  376. struct clk_init_data init;
  377. init.name = "nct3018y-clkout";
  378. init.ops = &nct3018y_clkout_ops;
  379. init.flags = 0;
  380. init.parent_names = NULL;
  381. init.num_parents = 0;
  382. nct3018y->clkout_hw.init = &init;
  383. /* optional override of the clockname */
  384. of_property_read_string(node, "clock-output-names", &init.name);
  385. /* register the clock */
  386. clk = devm_clk_register(&client->dev, &nct3018y->clkout_hw);
  387. if (!IS_ERR(clk))
  388. of_clk_add_provider(node, of_clk_src_simple_get, clk);
  389. return clk;
  390. }
  391. #endif
  392. static const struct rtc_class_ops nct3018y_rtc_ops = {
  393. .read_time = nct3018y_rtc_read_time,
  394. .set_time = nct3018y_rtc_set_time,
  395. .read_alarm = nct3018y_rtc_read_alarm,
  396. .set_alarm = nct3018y_rtc_set_alarm,
  397. .alarm_irq_enable = nct3018y_irq_enable,
  398. .ioctl = nct3018y_ioctl,
  399. };
  400. static int nct3018y_probe(struct i2c_client *client)
  401. {
  402. struct nct3018y *nct3018y;
  403. int err, flags;
  404. if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C |
  405. I2C_FUNC_SMBUS_BYTE |
  406. I2C_FUNC_SMBUS_BLOCK_DATA))
  407. return -ENODEV;
  408. nct3018y = devm_kzalloc(&client->dev, sizeof(struct nct3018y),
  409. GFP_KERNEL);
  410. if (!nct3018y)
  411. return -ENOMEM;
  412. i2c_set_clientdata(client, nct3018y);
  413. nct3018y->client = client;
  414. device_set_wakeup_capable(&client->dev, 1);
  415. flags = i2c_smbus_read_byte_data(client, NCT3018Y_REG_CTRL);
  416. if (flags < 0) {
  417. dev_dbg(&client->dev, "%s: read error\n", __func__);
  418. return flags;
  419. } else if (flags & NCT3018Y_BIT_TWO) {
  420. dev_dbg(&client->dev, "%s: NCT3018Y_BIT_TWO is set\n", __func__);
  421. }
  422. nct3018y->part_num = i2c_smbus_read_byte_data(client, NCT3018Y_REG_PART);
  423. if (nct3018y->part_num < 0) {
  424. dev_dbg(&client->dev, "Failed to read NCT3018Y_REG_PART.\n");
  425. return nct3018y->part_num;
  426. } else {
  427. nct3018y->part_num &= 0x03; /* Part number is corresponding to bit 0 and 1 */
  428. if (nct3018y->part_num == NCT3018Y_REG_PART_NCT3018Y) {
  429. flags = NCT3018Y_BIT_HF;
  430. err = i2c_smbus_write_byte_data(client, NCT3018Y_REG_CTRL, flags);
  431. if (err < 0) {
  432. dev_dbg(&client->dev, "Unable to write NCT3018Y_REG_CTRL.\n");
  433. return err;
  434. }
  435. }
  436. }
  437. flags = 0;
  438. err = i2c_smbus_write_byte_data(client, NCT3018Y_REG_ST, flags);
  439. if (err < 0) {
  440. dev_dbg(&client->dev, "%s: write error\n", __func__);
  441. return err;
  442. }
  443. nct3018y->rtc = devm_rtc_allocate_device(&client->dev);
  444. if (IS_ERR(nct3018y->rtc))
  445. return PTR_ERR(nct3018y->rtc);
  446. nct3018y->rtc->ops = &nct3018y_rtc_ops;
  447. nct3018y->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
  448. nct3018y->rtc->range_max = RTC_TIMESTAMP_END_2099;
  449. if (client->irq > 0) {
  450. err = devm_request_threaded_irq(&client->dev, client->irq,
  451. NULL, nct3018y_irq,
  452. IRQF_ONESHOT | IRQF_TRIGGER_FALLING,
  453. "nct3018y", client);
  454. if (err) {
  455. dev_dbg(&client->dev, "unable to request IRQ %d\n", client->irq);
  456. return err;
  457. }
  458. } else {
  459. clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, nct3018y->rtc->features);
  460. clear_bit(RTC_FEATURE_ALARM, nct3018y->rtc->features);
  461. }
  462. #ifdef CONFIG_COMMON_CLK
  463. /* register clk in common clk framework */
  464. nct3018y_clkout_register_clk(nct3018y);
  465. #endif
  466. return devm_rtc_register_device(nct3018y->rtc);
  467. }
  468. static const struct i2c_device_id nct3018y_id[] = {
  469. { "nct3018y" },
  470. { }
  471. };
  472. MODULE_DEVICE_TABLE(i2c, nct3018y_id);
  473. static const struct of_device_id nct3018y_of_match[] = {
  474. { .compatible = "nuvoton,nct3018y" },
  475. {}
  476. };
  477. MODULE_DEVICE_TABLE(of, nct3018y_of_match);
  478. static struct i2c_driver nct3018y_driver = {
  479. .driver = {
  480. .name = "rtc-nct3018y",
  481. .of_match_table = nct3018y_of_match,
  482. },
  483. .probe = nct3018y_probe,
  484. .id_table = nct3018y_id,
  485. };
  486. module_i2c_driver(nct3018y_driver);
  487. MODULE_AUTHOR("Medad CChien <ctcchien@nuvoton.com>");
  488. MODULE_AUTHOR("Mia Lin <mimi05633@gmail.com>");
  489. MODULE_DESCRIPTION("Nuvoton NCT3018Y RTC driver");
  490. MODULE_LICENSE("GPL");