rtc-x1205.c 16 KB

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