rtc-x1205.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. /*
  2. * An i2c driver for the Xicor/Intersil X1205 RTC
  3. * Copyright 2004 Karen Spearel
  4. * Copyright 2005 Alessandro Zummo
  5. *
  6. * please send all reports to:
  7. * Karen Spearel <kas111 at gmail dot com>
  8. * Alessandro Zummo <a.zummo@towertech.it>
  9. *
  10. * based on a lot of other RTC drivers.
  11. *
  12. * Information and datasheet:
  13. * http://www.intersil.com/cda/deviceinfo/0,1477,X1205,00.html
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License version 2 as
  17. * published by the Free Software Foundation.
  18. */
  19. #include <linux/i2c.h>
  20. #include <linux/bcd.h>
  21. #include <linux/rtc.h>
  22. #include <linux/delay.h>
  23. #include <linux/module.h>
  24. #include <linux/bitops.h>
  25. /* offsets into CCR area */
  26. #define CCR_SEC 0
  27. #define CCR_MIN 1
  28. #define CCR_HOUR 2
  29. #define CCR_MDAY 3
  30. #define CCR_MONTH 4
  31. #define CCR_YEAR 5
  32. #define CCR_WDAY 6
  33. #define CCR_Y2K 7
  34. #define X1205_REG_SR 0x3F /* status register */
  35. #define X1205_REG_Y2K 0x37
  36. #define X1205_REG_DW 0x36
  37. #define X1205_REG_YR 0x35
  38. #define X1205_REG_MO 0x34
  39. #define X1205_REG_DT 0x33
  40. #define X1205_REG_HR 0x32
  41. #define X1205_REG_MN 0x31
  42. #define X1205_REG_SC 0x30
  43. #define X1205_REG_DTR 0x13
  44. #define X1205_REG_ATR 0x12
  45. #define X1205_REG_INT 0x11
  46. #define X1205_REG_0 0x10
  47. #define X1205_REG_Y2K1 0x0F
  48. #define X1205_REG_DWA1 0x0E
  49. #define X1205_REG_YRA1 0x0D
  50. #define X1205_REG_MOA1 0x0C
  51. #define X1205_REG_DTA1 0x0B
  52. #define X1205_REG_HRA1 0x0A
  53. #define X1205_REG_MNA1 0x09
  54. #define X1205_REG_SCA1 0x08
  55. #define X1205_REG_Y2K0 0x07
  56. #define X1205_REG_DWA0 0x06
  57. #define X1205_REG_YRA0 0x05
  58. #define X1205_REG_MOA0 0x04
  59. #define X1205_REG_DTA0 0x03
  60. #define X1205_REG_HRA0 0x02
  61. #define X1205_REG_MNA0 0x01
  62. #define X1205_REG_SCA0 0x00
  63. #define X1205_CCR_BASE 0x30 /* Base address of CCR */
  64. #define X1205_ALM0_BASE 0x00 /* Base address of ALARM0 */
  65. #define X1205_SR_RTCF 0x01 /* Clock failure */
  66. #define X1205_SR_WEL 0x02 /* Write Enable Latch */
  67. #define X1205_SR_RWEL 0x04 /* Register Write Enable */
  68. #define X1205_SR_AL0 0x20 /* Alarm 0 match */
  69. #define X1205_DTR_DTR0 0x01
  70. #define X1205_DTR_DTR1 0x02
  71. #define X1205_DTR_DTR2 0x04
  72. #define X1205_HR_MIL 0x80 /* Set in ccr.hour for 24 hr mode */
  73. #define X1205_INT_AL0E 0x20 /* Alarm 0 enable */
  74. static struct i2c_driver x1205_driver;
  75. /*
  76. * In the routines that deal directly with the x1205 hardware, we use
  77. * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch
  78. * Epoch is initialized as 2000. Time is set to UTC.
  79. */
  80. static int x1205_get_datetime(struct i2c_client *client, struct rtc_time *tm,
  81. unsigned char reg_base)
  82. {
  83. unsigned char dt_addr[2] = { 0, reg_base };
  84. unsigned char buf[8];
  85. int i;
  86. struct i2c_msg msgs[] = {
  87. {/* setup read ptr */
  88. .addr = client->addr,
  89. .len = 2,
  90. .buf = dt_addr
  91. },
  92. {/* read date */
  93. .addr = client->addr,
  94. .flags = I2C_M_RD,
  95. .len = 8,
  96. .buf = buf
  97. },
  98. };
  99. /* read date registers */
  100. if (i2c_transfer(client->adapter, &msgs[0], 2) != 2) {
  101. dev_err(&client->dev, "%s: read error\n", __func__);
  102. return -EIO;
  103. }
  104. dev_dbg(&client->dev,
  105. "%s: raw read data - sec=%02x, min=%02x, hr=%02x, "
  106. "mday=%02x, mon=%02x, year=%02x, wday=%02x, y2k=%02x\n",
  107. __func__,
  108. buf[0], buf[1], buf[2], buf[3],
  109. buf[4], buf[5], buf[6], buf[7]);
  110. /* Mask out the enable bits if these are alarm registers */
  111. if (reg_base < X1205_CCR_BASE)
  112. for (i = 0; i <= 4; i++)
  113. buf[i] &= 0x7F;
  114. tm->tm_sec = bcd2bin(buf[CCR_SEC]);
  115. tm->tm_min = bcd2bin(buf[CCR_MIN]);
  116. tm->tm_hour = bcd2bin(buf[CCR_HOUR] & 0x3F); /* hr is 0-23 */
  117. tm->tm_mday = bcd2bin(buf[CCR_MDAY]);
  118. tm->tm_mon = bcd2bin(buf[CCR_MONTH]) - 1; /* mon is 0-11 */
  119. tm->tm_year = bcd2bin(buf[CCR_YEAR])
  120. + (bcd2bin(buf[CCR_Y2K]) * 100) - 1900;
  121. tm->tm_wday = buf[CCR_WDAY];
  122. dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
  123. "mday=%d, mon=%d, year=%d, wday=%d\n",
  124. __func__,
  125. tm->tm_sec, tm->tm_min, tm->tm_hour,
  126. tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
  127. return 0;
  128. }
  129. static int x1205_get_status(struct i2c_client *client, unsigned char *sr)
  130. {
  131. static unsigned char sr_addr[2] = { 0, X1205_REG_SR };
  132. struct i2c_msg msgs[] = {
  133. { /* setup read ptr */
  134. .addr = client->addr,
  135. .len = 2,
  136. .buf = sr_addr
  137. },
  138. { /* read status */
  139. .addr = client->addr,
  140. .flags = I2C_M_RD,
  141. .len = 1,
  142. .buf = sr
  143. },
  144. };
  145. /* read status register */
  146. if (i2c_transfer(client->adapter, &msgs[0], 2) != 2) {
  147. dev_err(&client->dev, "%s: read error\n", __func__);
  148. return -EIO;
  149. }
  150. return 0;
  151. }
  152. static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm,
  153. u8 reg_base, unsigned char alm_enable)
  154. {
  155. int i, xfer;
  156. unsigned char rdata[10] = { 0, reg_base };
  157. unsigned char *buf = rdata + 2;
  158. static const unsigned char wel[3] = { 0, X1205_REG_SR,
  159. X1205_SR_WEL };
  160. static const unsigned char rwel[3] = { 0, X1205_REG_SR,
  161. X1205_SR_WEL | X1205_SR_RWEL };
  162. static const unsigned char diswe[3] = { 0, X1205_REG_SR, 0 };
  163. dev_dbg(&client->dev,
  164. "%s: sec=%d min=%d hour=%d mday=%d mon=%d year=%d wday=%d\n",
  165. __func__, tm->tm_sec, tm->tm_min, tm->tm_hour, tm->tm_mday,
  166. tm->tm_mon, tm->tm_year, tm->tm_wday);
  167. buf[CCR_SEC] = bin2bcd(tm->tm_sec);
  168. buf[CCR_MIN] = bin2bcd(tm->tm_min);
  169. /* set hour and 24hr bit */
  170. buf[CCR_HOUR] = bin2bcd(tm->tm_hour) | X1205_HR_MIL;
  171. buf[CCR_MDAY] = bin2bcd(tm->tm_mday);
  172. /* month, 1 - 12 */
  173. buf[CCR_MONTH] = bin2bcd(tm->tm_mon + 1);
  174. /* year, since the rtc epoch*/
  175. buf[CCR_YEAR] = bin2bcd(tm->tm_year % 100);
  176. buf[CCR_WDAY] = tm->tm_wday & 0x07;
  177. buf[CCR_Y2K] = bin2bcd((tm->tm_year + 1900) / 100);
  178. /* If writing alarm registers, set compare bits on registers 0-4 */
  179. if (reg_base < X1205_CCR_BASE)
  180. for (i = 0; i <= 4; i++)
  181. buf[i] |= 0x80;
  182. /* this sequence is required to unlock the chip */
  183. xfer = i2c_master_send(client, wel, 3);
  184. if (xfer != 3) {
  185. dev_err(&client->dev, "%s: wel - %d\n", __func__, xfer);
  186. return -EIO;
  187. }
  188. xfer = i2c_master_send(client, rwel, 3);
  189. if (xfer != 3) {
  190. dev_err(&client->dev, "%s: rwel - %d\n", __func__, xfer);
  191. return -EIO;
  192. }
  193. xfer = i2c_master_send(client, rdata, sizeof(rdata));
  194. if (xfer != sizeof(rdata)) {
  195. dev_err(&client->dev,
  196. "%s: result=%d addr=%02x, data=%02x\n",
  197. __func__,
  198. xfer, rdata[1], rdata[2]);
  199. return -EIO;
  200. }
  201. /* If we wrote to the nonvolatile region, wait 10msec for write cycle*/
  202. if (reg_base < X1205_CCR_BASE) {
  203. unsigned char al0e[3] = { 0, X1205_REG_INT, 0 };
  204. msleep(10);
  205. /* ...and set or clear the AL0E bit in the INT register */
  206. /* Need to set RWEL again as the write has cleared it */
  207. xfer = i2c_master_send(client, rwel, 3);
  208. if (xfer != 3) {
  209. dev_err(&client->dev,
  210. "%s: aloe rwel - %d\n",
  211. __func__,
  212. xfer);
  213. return -EIO;
  214. }
  215. if (alm_enable)
  216. al0e[2] = X1205_INT_AL0E;
  217. xfer = i2c_master_send(client, al0e, 3);
  218. if (xfer != 3) {
  219. dev_err(&client->dev,
  220. "%s: al0e - %d\n",
  221. __func__,
  222. xfer);
  223. return -EIO;
  224. }
  225. /* and wait 10msec again for this write to complete */
  226. msleep(10);
  227. }
  228. /* disable further writes */
  229. xfer = i2c_master_send(client, diswe, 3);
  230. if (xfer != 3) {
  231. dev_err(&client->dev, "%s: diswe - %d\n", __func__, xfer);
  232. return -EIO;
  233. }
  234. return 0;
  235. }
  236. static int x1205_fix_osc(struct i2c_client *client)
  237. {
  238. int err;
  239. struct rtc_time tm;
  240. memset(&tm, 0, sizeof(tm));
  241. err = x1205_set_datetime(client, &tm, X1205_CCR_BASE, 0);
  242. if (err < 0)
  243. dev_err(&client->dev, "unable to restart the oscillator\n");
  244. return err;
  245. }
  246. static int x1205_get_dtrim(struct i2c_client *client, int *trim)
  247. {
  248. unsigned char dtr;
  249. static unsigned char dtr_addr[2] = { 0, X1205_REG_DTR };
  250. struct i2c_msg msgs[] = {
  251. { /* setup read ptr */
  252. .addr = client->addr,
  253. .len = 2,
  254. .buf = dtr_addr
  255. },
  256. { /* read dtr */
  257. .addr = client->addr,
  258. .flags = I2C_M_RD,
  259. .len = 1,
  260. .buf = &dtr
  261. },
  262. };
  263. /* read dtr register */
  264. if (i2c_transfer(client->adapter, &msgs[0], 2) != 2) {
  265. dev_err(&client->dev, "%s: read error\n", __func__);
  266. return -EIO;
  267. }
  268. dev_dbg(&client->dev, "%s: raw dtr=%x\n", __func__, dtr);
  269. *trim = 0;
  270. if (dtr & X1205_DTR_DTR0)
  271. *trim += 20;
  272. if (dtr & X1205_DTR_DTR1)
  273. *trim += 10;
  274. if (dtr & X1205_DTR_DTR2)
  275. *trim = -*trim;
  276. return 0;
  277. }
  278. static int x1205_get_atrim(struct i2c_client *client, int *trim)
  279. {
  280. s8 atr;
  281. static unsigned char atr_addr[2] = { 0, X1205_REG_ATR };
  282. struct i2c_msg msgs[] = {
  283. {/* setup read ptr */
  284. .addr = client->addr,
  285. .len = 2,
  286. .buf = atr_addr
  287. },
  288. {/* read atr */
  289. .addr = client->addr,
  290. .flags = I2C_M_RD,
  291. .len = 1,
  292. .buf = &atr
  293. },
  294. };
  295. /* read atr register */
  296. if (i2c_transfer(client->adapter, &msgs[0], 2) != 2) {
  297. dev_err(&client->dev, "%s: read error\n", __func__);
  298. return -EIO;
  299. }
  300. dev_dbg(&client->dev, "%s: raw atr=%x\n", __func__, atr);
  301. /* atr is a two's complement value on 6 bits,
  302. * perform sign extension. The formula is
  303. * Catr = (atr * 0.25pF) + 11.00pF.
  304. */
  305. atr = sign_extend32(atr, 5);
  306. dev_dbg(&client->dev, "%s: raw atr=%x (%d)\n", __func__, atr, atr);
  307. *trim = (atr * 250) + 11000;
  308. dev_dbg(&client->dev, "%s: real=%d\n", __func__, *trim);
  309. return 0;
  310. }
  311. struct x1205_limit {
  312. unsigned char reg, mask, min, max;
  313. };
  314. static int x1205_validate_client(struct i2c_client *client)
  315. {
  316. int i, xfer;
  317. /* Probe array. We will read the register at the specified
  318. * address and check if the given bits are zero.
  319. */
  320. static const unsigned char probe_zero_pattern[] = {
  321. /* register, mask */
  322. X1205_REG_SR, 0x18,
  323. X1205_REG_DTR, 0xF8,
  324. X1205_REG_ATR, 0xC0,
  325. X1205_REG_INT, 0x18,
  326. X1205_REG_0, 0xFF,
  327. };
  328. static const struct x1205_limit probe_limits_pattern[] = {
  329. /* register, mask, min, max */
  330. { X1205_REG_Y2K, 0xFF, 19, 20 },
  331. { X1205_REG_DW, 0xFF, 0, 6 },
  332. { X1205_REG_YR, 0xFF, 0, 99 },
  333. { X1205_REG_MO, 0xFF, 0, 12 },
  334. { X1205_REG_DT, 0xFF, 0, 31 },
  335. { X1205_REG_HR, 0x7F, 0, 23 },
  336. { X1205_REG_MN, 0xFF, 0, 59 },
  337. { X1205_REG_SC, 0xFF, 0, 59 },
  338. { X1205_REG_Y2K1, 0xFF, 19, 20 },
  339. { X1205_REG_Y2K0, 0xFF, 19, 20 },
  340. };
  341. /* check that registers have bits a 0 where expected */
  342. for (i = 0; i < ARRAY_SIZE(probe_zero_pattern); i += 2) {
  343. unsigned char buf;
  344. unsigned char addr[2] = { 0, probe_zero_pattern[i] };
  345. struct i2c_msg msgs[2] = {
  346. {
  347. .addr = client->addr,
  348. .len = 2,
  349. .buf = addr
  350. },
  351. {
  352. .addr = client->addr,
  353. .flags = I2C_M_RD,
  354. .len = 1,
  355. .buf = &buf
  356. },
  357. };
  358. xfer = i2c_transfer(client->adapter, msgs, 2);
  359. if (xfer != 2) {
  360. dev_err(&client->dev,
  361. "%s: could not read register %x\n",
  362. __func__, probe_zero_pattern[i]);
  363. return -EIO;
  364. }
  365. if ((buf & probe_zero_pattern[i+1]) != 0) {
  366. dev_err(&client->dev,
  367. "%s: register=%02x, zero pattern=%d, value=%x\n",
  368. __func__, probe_zero_pattern[i], i, buf);
  369. return -ENODEV;
  370. }
  371. }
  372. /* check limits (only registers with bcd values) */
  373. for (i = 0; i < ARRAY_SIZE(probe_limits_pattern); i++) {
  374. unsigned char reg, value;
  375. unsigned char addr[2] = { 0, probe_limits_pattern[i].reg };
  376. struct i2c_msg msgs[2] = {
  377. {
  378. .addr = client->addr,
  379. .len = 2,
  380. .buf = addr
  381. },
  382. {
  383. .addr = client->addr,
  384. .flags = I2C_M_RD,
  385. .len = 1,
  386. .buf = &reg
  387. },
  388. };
  389. xfer = i2c_transfer(client->adapter, msgs, 2);
  390. if (xfer != 2) {
  391. dev_err(&client->dev,
  392. "%s: could not read register %x\n",
  393. __func__, probe_limits_pattern[i].reg);
  394. return -EIO;
  395. }
  396. value = bcd2bin(reg & probe_limits_pattern[i].mask);
  397. if (value > probe_limits_pattern[i].max ||
  398. value < probe_limits_pattern[i].min) {
  399. dev_dbg(&client->dev,
  400. "%s: register=%x, lim pattern=%d, value=%d\n",
  401. __func__, probe_limits_pattern[i].reg,
  402. i, value);
  403. return -ENODEV;
  404. }
  405. }
  406. return 0;
  407. }
  408. static int x1205_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
  409. {
  410. int err;
  411. unsigned char intreg, status;
  412. static unsigned char int_addr[2] = { 0, X1205_REG_INT };
  413. struct i2c_client *client = to_i2c_client(dev);
  414. struct i2c_msg msgs[] = {
  415. { /* setup read ptr */
  416. .addr = client->addr,
  417. .len = 2,
  418. .buf = int_addr
  419. },
  420. {/* read INT register */
  421. .addr = client->addr,
  422. .flags = I2C_M_RD,
  423. .len = 1,
  424. .buf = &intreg
  425. },
  426. };
  427. /* read interrupt register and status register */
  428. if (i2c_transfer(client->adapter, &msgs[0], 2) != 2) {
  429. dev_err(&client->dev, "%s: read error\n", __func__);
  430. return -EIO;
  431. }
  432. err = x1205_get_status(client, &status);
  433. if (err == 0) {
  434. alrm->pending = (status & X1205_SR_AL0) ? 1 : 0;
  435. alrm->enabled = (intreg & X1205_INT_AL0E) ? 1 : 0;
  436. err = x1205_get_datetime(client, &alrm->time, X1205_ALM0_BASE);
  437. }
  438. return err;
  439. }
  440. static int x1205_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
  441. {
  442. return x1205_set_datetime(to_i2c_client(dev),
  443. &alrm->time, X1205_ALM0_BASE, alrm->enabled);
  444. }
  445. static int x1205_rtc_read_time(struct device *dev, struct rtc_time *tm)
  446. {
  447. return x1205_get_datetime(to_i2c_client(dev),
  448. tm, X1205_CCR_BASE);
  449. }
  450. static int x1205_rtc_set_time(struct device *dev, struct rtc_time *tm)
  451. {
  452. return x1205_set_datetime(to_i2c_client(dev),
  453. tm, X1205_CCR_BASE, 0);
  454. }
  455. static int x1205_rtc_proc(struct device *dev, struct seq_file *seq)
  456. {
  457. int err, dtrim, atrim;
  458. err = x1205_get_dtrim(to_i2c_client(dev), &dtrim);
  459. if (!err)
  460. seq_printf(seq, "digital_trim\t: %d ppm\n", dtrim);
  461. err = x1205_get_atrim(to_i2c_client(dev), &atrim);
  462. if (!err)
  463. seq_printf(seq, "analog_trim\t: %d.%02d pF\n",
  464. atrim / 1000, atrim % 1000);
  465. return 0;
  466. }
  467. static const struct rtc_class_ops x1205_rtc_ops = {
  468. .proc = x1205_rtc_proc,
  469. .read_time = x1205_rtc_read_time,
  470. .set_time = x1205_rtc_set_time,
  471. .read_alarm = x1205_rtc_read_alarm,
  472. .set_alarm = x1205_rtc_set_alarm,
  473. };
  474. static ssize_t x1205_sysfs_show_atrim(struct device *dev,
  475. struct device_attribute *attr, char *buf)
  476. {
  477. int err, atrim;
  478. err = x1205_get_atrim(to_i2c_client(dev), &atrim);
  479. if (err)
  480. return err;
  481. return sprintf(buf, "%d.%02d pF\n", atrim / 1000, atrim % 1000);
  482. }
  483. static DEVICE_ATTR(atrim, S_IRUGO, x1205_sysfs_show_atrim, NULL);
  484. static ssize_t x1205_sysfs_show_dtrim(struct device *dev,
  485. struct device_attribute *attr, char *buf)
  486. {
  487. int err, dtrim;
  488. err = x1205_get_dtrim(to_i2c_client(dev), &dtrim);
  489. if (err)
  490. return err;
  491. return sprintf(buf, "%d ppm\n", dtrim);
  492. }
  493. static DEVICE_ATTR(dtrim, S_IRUGO, x1205_sysfs_show_dtrim, NULL);
  494. static int x1205_sysfs_register(struct device *dev)
  495. {
  496. int err;
  497. err = device_create_file(dev, &dev_attr_atrim);
  498. if (err)
  499. return err;
  500. err = device_create_file(dev, &dev_attr_dtrim);
  501. if (err)
  502. device_remove_file(dev, &dev_attr_atrim);
  503. return err;
  504. }
  505. static void x1205_sysfs_unregister(struct device *dev)
  506. {
  507. device_remove_file(dev, &dev_attr_atrim);
  508. device_remove_file(dev, &dev_attr_dtrim);
  509. }
  510. static int x1205_probe(struct i2c_client *client,
  511. const struct i2c_device_id *id)
  512. {
  513. int err = 0;
  514. unsigned char sr;
  515. struct rtc_device *rtc;
  516. dev_dbg(&client->dev, "%s\n", __func__);
  517. if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
  518. return -ENODEV;
  519. if (x1205_validate_client(client) < 0)
  520. return -ENODEV;
  521. rtc = devm_rtc_device_register(&client->dev, x1205_driver.driver.name,
  522. &x1205_rtc_ops, THIS_MODULE);
  523. if (IS_ERR(rtc))
  524. return PTR_ERR(rtc);
  525. i2c_set_clientdata(client, rtc);
  526. /* Check for power failures and eventually enable the osc */
  527. err = x1205_get_status(client, &sr);
  528. if (!err) {
  529. if (sr & X1205_SR_RTCF) {
  530. dev_err(&client->dev,
  531. "power failure detected, "
  532. "please set the clock\n");
  533. udelay(50);
  534. x1205_fix_osc(client);
  535. }
  536. } else {
  537. dev_err(&client->dev, "couldn't read status\n");
  538. }
  539. err = x1205_sysfs_register(&client->dev);
  540. if (err)
  541. dev_err(&client->dev, "Unable to create sysfs entries\n");
  542. return 0;
  543. }
  544. static int x1205_remove(struct i2c_client *client)
  545. {
  546. x1205_sysfs_unregister(&client->dev);
  547. return 0;
  548. }
  549. static const struct i2c_device_id x1205_id[] = {
  550. { "x1205", 0 },
  551. { }
  552. };
  553. MODULE_DEVICE_TABLE(i2c, x1205_id);
  554. static struct i2c_driver x1205_driver = {
  555. .driver = {
  556. .name = "rtc-x1205",
  557. },
  558. .probe = x1205_probe,
  559. .remove = x1205_remove,
  560. .id_table = x1205_id,
  561. };
  562. module_i2c_driver(x1205_driver);
  563. MODULE_AUTHOR(
  564. "Karen Spearel <kas111 at gmail dot com>, "
  565. "Alessandro Zummo <a.zummo@towertech.it>");
  566. MODULE_DESCRIPTION("Xicor/Intersil X1205 RTC driver");
  567. MODULE_LICENSE("GPL");