rtc-rx8025.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. /*
  2. * Driver for Epson's RTC module RX-8025 SA/NB
  3. *
  4. * Copyright (C) 2009 Wolfgang Grandegger <wg@grandegger.com>
  5. *
  6. * Copyright (C) 2005 by Digi International Inc.
  7. * All rights reserved.
  8. *
  9. * Modified by fengjh at rising.com.cn
  10. * <http://lists.lm-sensors.org/mailman/listinfo/lm-sensors>
  11. * 2006.11
  12. *
  13. * Code cleanup by Sergei Poselenov, <sposelenov@emcraft.com>
  14. * Converted to new style by Wolfgang Grandegger <wg@grandegger.com>
  15. * Alarm and periodic interrupt added by Dmitry Rakhchev <rda@emcraft.com>
  16. *
  17. * This program is free software; you can redistribute it and/or
  18. * modify it under the terms of the GNU General Public License
  19. * version 2 as published by the Free Software Foundation.
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include <linux/slab.h>
  24. #include <linux/init.h>
  25. #include <linux/bcd.h>
  26. #include <linux/i2c.h>
  27. #include <linux/list.h>
  28. #include <linux/rtc.h>
  29. /* Register definitions */
  30. #define RX8025_REG_SEC 0x00
  31. #define RX8025_REG_MIN 0x01
  32. #define RX8025_REG_HOUR 0x02
  33. #define RX8025_REG_WDAY 0x03
  34. #define RX8025_REG_MDAY 0x04
  35. #define RX8025_REG_MONTH 0x05
  36. #define RX8025_REG_YEAR 0x06
  37. #define RX8025_REG_DIGOFF 0x07
  38. #define RX8025_REG_ALWMIN 0x08
  39. #define RX8025_REG_ALWHOUR 0x09
  40. #define RX8025_REG_ALWWDAY 0x0a
  41. #define RX8025_REG_ALDMIN 0x0b
  42. #define RX8025_REG_ALDHOUR 0x0c
  43. /* 0x0d is reserved */
  44. #define RX8025_REG_CTRL1 0x0e
  45. #define RX8025_REG_CTRL2 0x0f
  46. #define RX8025_BIT_CTRL1_CT (7 << 0)
  47. /* 1 Hz periodic level irq */
  48. #define RX8025_BIT_CTRL1_CT_1HZ 4
  49. #define RX8025_BIT_CTRL1_TEST (1 << 3)
  50. #define RX8025_BIT_CTRL1_1224 (1 << 5)
  51. #define RX8025_BIT_CTRL1_DALE (1 << 6)
  52. #define RX8025_BIT_CTRL1_WALE (1 << 7)
  53. #define RX8025_BIT_CTRL2_DAFG (1 << 0)
  54. #define RX8025_BIT_CTRL2_WAFG (1 << 1)
  55. #define RX8025_BIT_CTRL2_CTFG (1 << 2)
  56. #define RX8025_BIT_CTRL2_PON (1 << 4)
  57. #define RX8025_BIT_CTRL2_XST (1 << 5)
  58. #define RX8025_BIT_CTRL2_VDET (1 << 6)
  59. /* Clock precision adjustment */
  60. #define RX8025_ADJ_RESOLUTION 3050 /* in ppb */
  61. #define RX8025_ADJ_DATA_MAX 62
  62. #define RX8025_ADJ_DATA_MIN -62
  63. static const struct i2c_device_id rx8025_id[] = {
  64. { "rx8025", 0 },
  65. { }
  66. };
  67. MODULE_DEVICE_TABLE(i2c, rx8025_id);
  68. struct rx8025_data {
  69. struct i2c_client *client;
  70. struct rtc_device *rtc;
  71. struct work_struct work;
  72. u8 ctrl1;
  73. unsigned exiting:1;
  74. };
  75. static int rx8025_read_reg(struct i2c_client *client, int number, u8 *value)
  76. {
  77. int ret = i2c_smbus_read_byte_data(client, (number << 4) | 0x08);
  78. if (ret < 0) {
  79. dev_err(&client->dev, "Unable to read register #%d\n", number);
  80. return ret;
  81. }
  82. *value = ret;
  83. return 0;
  84. }
  85. static int rx8025_read_regs(struct i2c_client *client,
  86. int number, u8 length, u8 *values)
  87. {
  88. int ret = i2c_smbus_read_i2c_block_data(client, (number << 4) | 0x08,
  89. length, values);
  90. if (ret != length) {
  91. dev_err(&client->dev, "Unable to read registers #%d..#%d\n",
  92. number, number + length - 1);
  93. return ret < 0 ? ret : -EIO;
  94. }
  95. return 0;
  96. }
  97. static int rx8025_write_reg(struct i2c_client *client, int number, u8 value)
  98. {
  99. int ret = i2c_smbus_write_byte_data(client, number << 4, value);
  100. if (ret)
  101. dev_err(&client->dev, "Unable to write register #%d\n",
  102. number);
  103. return ret;
  104. }
  105. static int rx8025_write_regs(struct i2c_client *client,
  106. int number, u8 length, u8 *values)
  107. {
  108. int ret = i2c_smbus_write_i2c_block_data(client, (number << 4) | 0x08,
  109. length, values);
  110. if (ret)
  111. dev_err(&client->dev, "Unable to write registers #%d..#%d\n",
  112. number, number + length - 1);
  113. return ret;
  114. }
  115. static irqreturn_t rx8025_irq(int irq, void *dev_id)
  116. {
  117. struct i2c_client *client = dev_id;
  118. struct rx8025_data *rx8025 = i2c_get_clientdata(client);
  119. disable_irq_nosync(irq);
  120. schedule_work(&rx8025->work);
  121. return IRQ_HANDLED;
  122. }
  123. static void rx8025_work(struct work_struct *work)
  124. {
  125. struct rx8025_data *rx8025 = container_of(work, struct rx8025_data,
  126. work);
  127. struct i2c_client *client = rx8025->client;
  128. struct mutex *lock = &rx8025->rtc->ops_lock;
  129. u8 status;
  130. mutex_lock(lock);
  131. if (rx8025_read_reg(client, RX8025_REG_CTRL2, &status))
  132. goto out;
  133. if (!(status & RX8025_BIT_CTRL2_XST))
  134. dev_warn(&client->dev, "Oscillation stop was detected,"
  135. "you may have to readjust the clock\n");
  136. if (status & RX8025_BIT_CTRL2_CTFG) {
  137. /* periodic */
  138. status &= ~RX8025_BIT_CTRL2_CTFG;
  139. local_irq_disable();
  140. rtc_update_irq(rx8025->rtc, 1, RTC_PF | RTC_IRQF);
  141. local_irq_enable();
  142. }
  143. if (status & RX8025_BIT_CTRL2_DAFG) {
  144. /* alarm */
  145. status &= RX8025_BIT_CTRL2_DAFG;
  146. if (rx8025_write_reg(client, RX8025_REG_CTRL1,
  147. rx8025->ctrl1 & ~RX8025_BIT_CTRL1_DALE))
  148. goto out;
  149. local_irq_disable();
  150. rtc_update_irq(rx8025->rtc, 1, RTC_AF | RTC_IRQF);
  151. local_irq_enable();
  152. }
  153. /* acknowledge IRQ */
  154. rx8025_write_reg(client, RX8025_REG_CTRL2,
  155. status | RX8025_BIT_CTRL2_XST);
  156. out:
  157. if (!rx8025->exiting)
  158. enable_irq(client->irq);
  159. mutex_unlock(lock);
  160. }
  161. static int rx8025_get_time(struct device *dev, struct rtc_time *dt)
  162. {
  163. struct rx8025_data *rx8025 = dev_get_drvdata(dev);
  164. u8 date[7];
  165. int err;
  166. err = rx8025_read_regs(rx8025->client, RX8025_REG_SEC, 7, date);
  167. if (err)
  168. return err;
  169. dev_dbg(dev, "%s: read 0x%02x 0x%02x "
  170. "0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n", __func__,
  171. date[0], date[1], date[2], date[3], date[4],
  172. date[5], date[6]);
  173. dt->tm_sec = bcd2bin(date[RX8025_REG_SEC] & 0x7f);
  174. dt->tm_min = bcd2bin(date[RX8025_REG_MIN] & 0x7f);
  175. if (rx8025->ctrl1 & RX8025_BIT_CTRL1_1224)
  176. dt->tm_hour = bcd2bin(date[RX8025_REG_HOUR] & 0x3f);
  177. else
  178. dt->tm_hour = bcd2bin(date[RX8025_REG_HOUR] & 0x1f) % 12
  179. + (date[RX8025_REG_HOUR] & 0x20 ? 12 : 0);
  180. dt->tm_mday = bcd2bin(date[RX8025_REG_MDAY] & 0x3f);
  181. dt->tm_mon = bcd2bin(date[RX8025_REG_MONTH] & 0x1f) - 1;
  182. dt->tm_year = bcd2bin(date[RX8025_REG_YEAR]);
  183. if (dt->tm_year < 70)
  184. dt->tm_year += 100;
  185. dev_dbg(dev, "%s: date %ds %dm %dh %dmd %dm %dy\n", __func__,
  186. dt->tm_sec, dt->tm_min, dt->tm_hour,
  187. dt->tm_mday, dt->tm_mon, dt->tm_year);
  188. return rtc_valid_tm(dt);
  189. }
  190. static int rx8025_set_time(struct device *dev, struct rtc_time *dt)
  191. {
  192. struct rx8025_data *rx8025 = dev_get_drvdata(dev);
  193. u8 date[7];
  194. /*
  195. * BUG: The HW assumes every year that is a multiple of 4 to be a leap
  196. * year. Next time this is wrong is 2100, which will not be a leap
  197. * year.
  198. */
  199. /*
  200. * Here the read-only bits are written as "0". I'm not sure if that
  201. * is sound.
  202. */
  203. date[RX8025_REG_SEC] = bin2bcd(dt->tm_sec);
  204. date[RX8025_REG_MIN] = bin2bcd(dt->tm_min);
  205. if (rx8025->ctrl1 & RX8025_BIT_CTRL1_1224)
  206. date[RX8025_REG_HOUR] = bin2bcd(dt->tm_hour);
  207. else
  208. date[RX8025_REG_HOUR] = (dt->tm_hour >= 12 ? 0x20 : 0)
  209. | bin2bcd((dt->tm_hour + 11) % 12 + 1);
  210. date[RX8025_REG_WDAY] = bin2bcd(dt->tm_wday);
  211. date[RX8025_REG_MDAY] = bin2bcd(dt->tm_mday);
  212. date[RX8025_REG_MONTH] = bin2bcd(dt->tm_mon + 1);
  213. date[RX8025_REG_YEAR] = bin2bcd(dt->tm_year % 100);
  214. dev_dbg(dev,
  215. "%s: write 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
  216. __func__,
  217. date[0], date[1], date[2], date[3], date[4], date[5], date[6]);
  218. return rx8025_write_regs(rx8025->client, RX8025_REG_SEC, 7, date);
  219. }
  220. static int rx8025_init_client(struct i2c_client *client, int *need_reset)
  221. {
  222. struct rx8025_data *rx8025 = i2c_get_clientdata(client);
  223. u8 ctrl[2], ctrl2;
  224. int need_clear = 0;
  225. int err;
  226. err = rx8025_read_regs(rx8025->client, RX8025_REG_CTRL1, 2, ctrl);
  227. if (err)
  228. goto out;
  229. /* Keep test bit zero ! */
  230. rx8025->ctrl1 = ctrl[0] & ~RX8025_BIT_CTRL1_TEST;
  231. if (ctrl[1] & RX8025_BIT_CTRL2_PON) {
  232. dev_warn(&client->dev, "power-on reset was detected, "
  233. "you may have to readjust the clock\n");
  234. *need_reset = 1;
  235. }
  236. if (ctrl[1] & RX8025_BIT_CTRL2_VDET) {
  237. dev_warn(&client->dev, "a power voltage drop was detected, "
  238. "you may have to readjust the clock\n");
  239. *need_reset = 1;
  240. }
  241. if (!(ctrl[1] & RX8025_BIT_CTRL2_XST)) {
  242. dev_warn(&client->dev, "Oscillation stop was detected,"
  243. "you may have to readjust the clock\n");
  244. *need_reset = 1;
  245. }
  246. if (ctrl[1] & (RX8025_BIT_CTRL2_DAFG | RX8025_BIT_CTRL2_WAFG)) {
  247. dev_warn(&client->dev, "Alarm was detected\n");
  248. need_clear = 1;
  249. }
  250. if (!(ctrl[1] & RX8025_BIT_CTRL2_CTFG))
  251. need_clear = 1;
  252. if (*need_reset || need_clear) {
  253. ctrl2 = ctrl[0];
  254. ctrl2 &= ~(RX8025_BIT_CTRL2_PON | RX8025_BIT_CTRL2_VDET |
  255. RX8025_BIT_CTRL2_CTFG | RX8025_BIT_CTRL2_WAFG |
  256. RX8025_BIT_CTRL2_DAFG);
  257. ctrl2 |= RX8025_BIT_CTRL2_XST;
  258. err = rx8025_write_reg(client, RX8025_REG_CTRL2, ctrl2);
  259. }
  260. out:
  261. return err;
  262. }
  263. /* Alarm support */
  264. static int rx8025_read_alarm(struct device *dev, struct rtc_wkalrm *t)
  265. {
  266. struct rx8025_data *rx8025 = dev_get_drvdata(dev);
  267. struct i2c_client *client = rx8025->client;
  268. u8 ctrl2, ald[2];
  269. int err;
  270. if (client->irq <= 0)
  271. return -EINVAL;
  272. err = rx8025_read_regs(client, RX8025_REG_ALDMIN, 2, ald);
  273. if (err)
  274. return err;
  275. err = rx8025_read_reg(client, RX8025_REG_CTRL2, &ctrl2);
  276. if (err)
  277. return err;
  278. dev_dbg(dev, "%s: read alarm 0x%02x 0x%02x ctrl2 %02x\n",
  279. __func__, ald[0], ald[1], ctrl2);
  280. /* Hardware alarms precision is 1 minute! */
  281. t->time.tm_sec = 0;
  282. t->time.tm_min = bcd2bin(ald[0] & 0x7f);
  283. if (rx8025->ctrl1 & RX8025_BIT_CTRL1_1224)
  284. t->time.tm_hour = bcd2bin(ald[1] & 0x3f);
  285. else
  286. t->time.tm_hour = bcd2bin(ald[1] & 0x1f) % 12
  287. + (ald[1] & 0x20 ? 12 : 0);
  288. t->time.tm_wday = -1;
  289. t->time.tm_mday = -1;
  290. t->time.tm_mon = -1;
  291. t->time.tm_year = -1;
  292. dev_dbg(dev, "%s: date: %ds %dm %dh %dmd %dm %dy\n",
  293. __func__,
  294. t->time.tm_sec, t->time.tm_min, t->time.tm_hour,
  295. t->time.tm_mday, t->time.tm_mon, t->time.tm_year);
  296. t->enabled = !!(rx8025->ctrl1 & RX8025_BIT_CTRL1_DALE);
  297. t->pending = (ctrl2 & RX8025_BIT_CTRL2_DAFG) && t->enabled;
  298. return err;
  299. }
  300. static int rx8025_set_alarm(struct device *dev, struct rtc_wkalrm *t)
  301. {
  302. struct i2c_client *client = to_i2c_client(dev);
  303. struct rx8025_data *rx8025 = dev_get_drvdata(dev);
  304. u8 ald[2];
  305. int err;
  306. if (client->irq <= 0)
  307. return -EINVAL;
  308. /* Hardware alarm precision is 1 minute! */
  309. ald[0] = bin2bcd(t->time.tm_min);
  310. if (rx8025->ctrl1 & RX8025_BIT_CTRL1_1224)
  311. ald[1] = bin2bcd(t->time.tm_hour);
  312. else
  313. ald[1] = (t->time.tm_hour >= 12 ? 0x20 : 0)
  314. | bin2bcd((t->time.tm_hour + 11) % 12 + 1);
  315. dev_dbg(dev, "%s: write 0x%02x 0x%02x\n", __func__, ald[0], ald[1]);
  316. if (rx8025->ctrl1 & RX8025_BIT_CTRL1_DALE) {
  317. rx8025->ctrl1 &= ~RX8025_BIT_CTRL1_DALE;
  318. err = rx8025_write_reg(rx8025->client, RX8025_REG_CTRL1,
  319. rx8025->ctrl1);
  320. if (err)
  321. return err;
  322. }
  323. err = rx8025_write_regs(rx8025->client, RX8025_REG_ALDMIN, 2, ald);
  324. if (err)
  325. return err;
  326. if (t->enabled) {
  327. rx8025->ctrl1 |= RX8025_BIT_CTRL1_DALE;
  328. err = rx8025_write_reg(rx8025->client, RX8025_REG_CTRL1,
  329. rx8025->ctrl1);
  330. if (err)
  331. return err;
  332. }
  333. return 0;
  334. }
  335. static int rx8025_alarm_irq_enable(struct device *dev, unsigned int enabled)
  336. {
  337. struct rx8025_data *rx8025 = dev_get_drvdata(dev);
  338. u8 ctrl1;
  339. int err;
  340. ctrl1 = rx8025->ctrl1;
  341. if (enabled)
  342. ctrl1 |= RX8025_BIT_CTRL1_DALE;
  343. else
  344. ctrl1 &= ~RX8025_BIT_CTRL1_DALE;
  345. if (ctrl1 != rx8025->ctrl1) {
  346. rx8025->ctrl1 = ctrl1;
  347. err = rx8025_write_reg(rx8025->client, RX8025_REG_CTRL1,
  348. rx8025->ctrl1);
  349. if (err)
  350. return err;
  351. }
  352. return 0;
  353. }
  354. static struct rtc_class_ops rx8025_rtc_ops = {
  355. .read_time = rx8025_get_time,
  356. .set_time = rx8025_set_time,
  357. .read_alarm = rx8025_read_alarm,
  358. .set_alarm = rx8025_set_alarm,
  359. .alarm_irq_enable = rx8025_alarm_irq_enable,
  360. };
  361. /*
  362. * Clock precision adjustment support
  363. *
  364. * According to the RX8025 SA/NB application manual the frequency and
  365. * temperature characteristics can be approximated using the following
  366. * equation:
  367. *
  368. * df = a * (ut - t)**2
  369. *
  370. * df: Frequency deviation in any temperature
  371. * a : Coefficient = (-35 +-5) * 10**-9
  372. * ut: Ultimate temperature in degree = +25 +-5 degree
  373. * t : Any temperature in degree
  374. *
  375. * Note that the clock adjustment in ppb must be entered (which is
  376. * the negative value of the deviation).
  377. */
  378. static int rx8025_get_clock_adjust(struct device *dev, int *adj)
  379. {
  380. struct i2c_client *client = to_i2c_client(dev);
  381. u8 digoff;
  382. int err;
  383. err = rx8025_read_reg(client, RX8025_REG_DIGOFF, &digoff);
  384. if (err)
  385. return err;
  386. *adj = digoff >= 64 ? digoff - 128 : digoff;
  387. if (*adj > 0)
  388. (*adj)--;
  389. *adj *= -RX8025_ADJ_RESOLUTION;
  390. return 0;
  391. }
  392. static int rx8025_set_clock_adjust(struct device *dev, int adj)
  393. {
  394. struct i2c_client *client = to_i2c_client(dev);
  395. u8 digoff;
  396. int err;
  397. adj /= -RX8025_ADJ_RESOLUTION;
  398. if (adj > RX8025_ADJ_DATA_MAX)
  399. adj = RX8025_ADJ_DATA_MAX;
  400. else if (adj < RX8025_ADJ_DATA_MIN)
  401. adj = RX8025_ADJ_DATA_MIN;
  402. else if (adj > 0)
  403. adj++;
  404. else if (adj < 0)
  405. adj += 128;
  406. digoff = adj;
  407. err = rx8025_write_reg(client, RX8025_REG_DIGOFF, digoff);
  408. if (err)
  409. return err;
  410. dev_dbg(dev, "%s: write 0x%02x\n", __func__, digoff);
  411. return 0;
  412. }
  413. static ssize_t rx8025_sysfs_show_clock_adjust(struct device *dev,
  414. struct device_attribute *attr,
  415. char *buf)
  416. {
  417. int err, adj;
  418. err = rx8025_get_clock_adjust(dev, &adj);
  419. if (err)
  420. return err;
  421. return sprintf(buf, "%d\n", adj);
  422. }
  423. static ssize_t rx8025_sysfs_store_clock_adjust(struct device *dev,
  424. struct device_attribute *attr,
  425. const char *buf, size_t count)
  426. {
  427. int adj, err;
  428. if (sscanf(buf, "%i", &adj) != 1)
  429. return -EINVAL;
  430. err = rx8025_set_clock_adjust(dev, adj);
  431. return err ? err : count;
  432. }
  433. static DEVICE_ATTR(clock_adjust_ppb, S_IRUGO | S_IWUSR,
  434. rx8025_sysfs_show_clock_adjust,
  435. rx8025_sysfs_store_clock_adjust);
  436. static int rx8025_sysfs_register(struct device *dev)
  437. {
  438. return device_create_file(dev, &dev_attr_clock_adjust_ppb);
  439. }
  440. static void rx8025_sysfs_unregister(struct device *dev)
  441. {
  442. device_remove_file(dev, &dev_attr_clock_adjust_ppb);
  443. }
  444. static int rx8025_probe(struct i2c_client *client,
  445. const struct i2c_device_id *id)
  446. {
  447. struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
  448. struct rx8025_data *rx8025;
  449. int err, need_reset = 0;
  450. if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA
  451. | I2C_FUNC_SMBUS_I2C_BLOCK)) {
  452. dev_err(&adapter->dev,
  453. "doesn't support required functionality\n");
  454. err = -EIO;
  455. goto errout;
  456. }
  457. rx8025 = devm_kzalloc(&client->dev, sizeof(*rx8025), GFP_KERNEL);
  458. if (!rx8025) {
  459. err = -ENOMEM;
  460. goto errout;
  461. }
  462. rx8025->client = client;
  463. i2c_set_clientdata(client, rx8025);
  464. INIT_WORK(&rx8025->work, rx8025_work);
  465. err = rx8025_init_client(client, &need_reset);
  466. if (err)
  467. goto errout;
  468. if (need_reset) {
  469. struct rtc_time tm;
  470. dev_info(&client->dev,
  471. "bad conditions detected, resetting date\n");
  472. rtc_time_to_tm(0, &tm); /* 1970/1/1 */
  473. rx8025_set_time(&client->dev, &tm);
  474. }
  475. rx8025->rtc = devm_rtc_device_register(&client->dev, client->name,
  476. &rx8025_rtc_ops, THIS_MODULE);
  477. if (IS_ERR(rx8025->rtc)) {
  478. err = PTR_ERR(rx8025->rtc);
  479. dev_err(&client->dev, "unable to register the class device\n");
  480. goto errout;
  481. }
  482. if (client->irq > 0) {
  483. dev_info(&client->dev, "IRQ %d supplied\n", client->irq);
  484. err = request_irq(client->irq, rx8025_irq,
  485. 0, "rx8025", client);
  486. if (err) {
  487. dev_err(&client->dev, "unable to request IRQ\n");
  488. goto errout;
  489. }
  490. }
  491. rx8025->rtc->irq_freq = 1;
  492. rx8025->rtc->max_user_freq = 1;
  493. err = rx8025_sysfs_register(&client->dev);
  494. if (err)
  495. goto errout_irq;
  496. return 0;
  497. errout_irq:
  498. if (client->irq > 0)
  499. free_irq(client->irq, client);
  500. errout:
  501. dev_err(&adapter->dev, "probing for rx8025 failed\n");
  502. return err;
  503. }
  504. static int rx8025_remove(struct i2c_client *client)
  505. {
  506. struct rx8025_data *rx8025 = i2c_get_clientdata(client);
  507. struct mutex *lock = &rx8025->rtc->ops_lock;
  508. if (client->irq > 0) {
  509. mutex_lock(lock);
  510. rx8025->exiting = 1;
  511. mutex_unlock(lock);
  512. free_irq(client->irq, client);
  513. cancel_work_sync(&rx8025->work);
  514. }
  515. rx8025_sysfs_unregister(&client->dev);
  516. return 0;
  517. }
  518. static struct i2c_driver rx8025_driver = {
  519. .driver = {
  520. .name = "rtc-rx8025",
  521. .owner = THIS_MODULE,
  522. },
  523. .probe = rx8025_probe,
  524. .remove = rx8025_remove,
  525. .id_table = rx8025_id,
  526. };
  527. module_i2c_driver(rx8025_driver);
  528. MODULE_AUTHOR("Wolfgang Grandegger <wg@grandegger.com>");
  529. MODULE_DESCRIPTION("RX-8025 SA/NB RTC driver");
  530. MODULE_LICENSE("GPL");