interface.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. /*
  2. * RTC subsystem, interface functions
  3. *
  4. * Copyright (C) 2005 Tower Technologies
  5. * Author: Alessandro Zummo <a.zummo@towertech.it>
  6. *
  7. * based on arch/arm/common/rtctime.c
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/rtc.h>
  14. #include <linux/sched.h>
  15. #include <linux/log2.h>
  16. #include <linux/workqueue.h>
  17. static int rtc_timer_enqueue(struct rtc_device *rtc, struct rtc_timer *timer);
  18. static void rtc_timer_remove(struct rtc_device *rtc, struct rtc_timer *timer);
  19. static int __rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm)
  20. {
  21. int err;
  22. if (!rtc->ops)
  23. err = -ENODEV;
  24. else if (!rtc->ops->read_time)
  25. err = -EINVAL;
  26. else {
  27. memset(tm, 0, sizeof(struct rtc_time));
  28. err = rtc->ops->read_time(rtc->dev.parent, tm);
  29. }
  30. return err;
  31. }
  32. int rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm)
  33. {
  34. int err;
  35. err = mutex_lock_interruptible(&rtc->ops_lock);
  36. if (err)
  37. return err;
  38. err = __rtc_read_time(rtc, tm);
  39. mutex_unlock(&rtc->ops_lock);
  40. return err;
  41. }
  42. EXPORT_SYMBOL_GPL(rtc_read_time);
  43. int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm)
  44. {
  45. int err;
  46. err = rtc_valid_tm(tm);
  47. if (err != 0)
  48. return err;
  49. err = mutex_lock_interruptible(&rtc->ops_lock);
  50. if (err)
  51. return err;
  52. if (!rtc->ops)
  53. err = -ENODEV;
  54. else if (rtc->ops->set_time)
  55. err = rtc->ops->set_time(rtc->dev.parent, tm);
  56. else if (rtc->ops->set_mmss) {
  57. unsigned long secs;
  58. err = rtc_tm_to_time(tm, &secs);
  59. if (err == 0)
  60. err = rtc->ops->set_mmss(rtc->dev.parent, secs);
  61. } else
  62. err = -EINVAL;
  63. mutex_unlock(&rtc->ops_lock);
  64. return err;
  65. }
  66. EXPORT_SYMBOL_GPL(rtc_set_time);
  67. int rtc_set_mmss(struct rtc_device *rtc, unsigned long secs)
  68. {
  69. int err;
  70. err = mutex_lock_interruptible(&rtc->ops_lock);
  71. if (err)
  72. return err;
  73. if (!rtc->ops)
  74. err = -ENODEV;
  75. else if (rtc->ops->set_mmss)
  76. err = rtc->ops->set_mmss(rtc->dev.parent, secs);
  77. else if (rtc->ops->read_time && rtc->ops->set_time) {
  78. struct rtc_time new, old;
  79. err = rtc->ops->read_time(rtc->dev.parent, &old);
  80. if (err == 0) {
  81. rtc_time_to_tm(secs, &new);
  82. /*
  83. * avoid writing when we're going to change the day of
  84. * the month. We will retry in the next minute. This
  85. * basically means that if the RTC must not drift
  86. * by more than 1 minute in 11 minutes.
  87. */
  88. if (!((old.tm_hour == 23 && old.tm_min == 59) ||
  89. (new.tm_hour == 23 && new.tm_min == 59)))
  90. err = rtc->ops->set_time(rtc->dev.parent,
  91. &new);
  92. }
  93. }
  94. else
  95. err = -EINVAL;
  96. mutex_unlock(&rtc->ops_lock);
  97. return err;
  98. }
  99. EXPORT_SYMBOL_GPL(rtc_set_mmss);
  100. int rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
  101. {
  102. int err;
  103. err = mutex_lock_interruptible(&rtc->ops_lock);
  104. if (err)
  105. return err;
  106. if (rtc->ops == NULL)
  107. err = -ENODEV;
  108. else if (!rtc->ops->read_alarm)
  109. err = -EINVAL;
  110. else {
  111. memset(alarm, 0, sizeof(struct rtc_wkalrm));
  112. alarm->enabled = rtc->aie_timer.enabled;
  113. alarm->time = rtc_ktime_to_tm(rtc->aie_timer.node.expires);
  114. }
  115. mutex_unlock(&rtc->ops_lock);
  116. return err;
  117. }
  118. EXPORT_SYMBOL_GPL(rtc_read_alarm);
  119. int __rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
  120. {
  121. struct rtc_time tm;
  122. long now, scheduled;
  123. int err;
  124. err = rtc_valid_tm(&alarm->time);
  125. if (err)
  126. return err;
  127. rtc_tm_to_time(&alarm->time, &scheduled);
  128. /* Make sure we're not setting alarms in the past */
  129. err = __rtc_read_time(rtc, &tm);
  130. rtc_tm_to_time(&tm, &now);
  131. if (scheduled <= now)
  132. return -ETIME;
  133. /*
  134. * XXX - We just checked to make sure the alarm time is not
  135. * in the past, but there is still a race window where if
  136. * the is alarm set for the next second and the second ticks
  137. * over right here, before we set the alarm.
  138. */
  139. if (!rtc->ops)
  140. err = -ENODEV;
  141. else if (!rtc->ops->set_alarm)
  142. err = -EINVAL;
  143. else
  144. err = rtc->ops->set_alarm(rtc->dev.parent, alarm);
  145. return err;
  146. }
  147. int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
  148. {
  149. int err;
  150. err = rtc_valid_tm(&alarm->time);
  151. if (err != 0)
  152. return err;
  153. err = mutex_lock_interruptible(&rtc->ops_lock);
  154. if (err)
  155. return err;
  156. if (rtc->aie_timer.enabled) {
  157. rtc_timer_remove(rtc, &rtc->aie_timer);
  158. }
  159. rtc->aie_timer.node.expires = rtc_tm_to_ktime(alarm->time);
  160. rtc->aie_timer.period = ktime_set(0, 0);
  161. if (alarm->enabled) {
  162. err = rtc_timer_enqueue(rtc, &rtc->aie_timer);
  163. }
  164. mutex_unlock(&rtc->ops_lock);
  165. return err;
  166. }
  167. EXPORT_SYMBOL_GPL(rtc_set_alarm);
  168. int rtc_alarm_irq_enable(struct rtc_device *rtc, unsigned int enabled)
  169. {
  170. int err = mutex_lock_interruptible(&rtc->ops_lock);
  171. if (err)
  172. return err;
  173. if (rtc->aie_timer.enabled != enabled) {
  174. if (enabled)
  175. err = rtc_timer_enqueue(rtc, &rtc->aie_timer);
  176. else
  177. rtc_timer_remove(rtc, &rtc->aie_timer);
  178. }
  179. if (err)
  180. return err;
  181. if (!rtc->ops)
  182. err = -ENODEV;
  183. else if (!rtc->ops->alarm_irq_enable)
  184. err = -EINVAL;
  185. else
  186. err = rtc->ops->alarm_irq_enable(rtc->dev.parent, enabled);
  187. mutex_unlock(&rtc->ops_lock);
  188. return err;
  189. }
  190. EXPORT_SYMBOL_GPL(rtc_alarm_irq_enable);
  191. int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled)
  192. {
  193. int err = mutex_lock_interruptible(&rtc->ops_lock);
  194. if (err)
  195. return err;
  196. /* make sure we're changing state */
  197. if (rtc->uie_rtctimer.enabled == enabled)
  198. goto out;
  199. if (enabled) {
  200. struct rtc_time tm;
  201. ktime_t now, onesec;
  202. __rtc_read_time(rtc, &tm);
  203. onesec = ktime_set(1, 0);
  204. now = rtc_tm_to_ktime(tm);
  205. rtc->uie_rtctimer.node.expires = ktime_add(now, onesec);
  206. rtc->uie_rtctimer.period = ktime_set(1, 0);
  207. err = rtc_timer_enqueue(rtc, &rtc->uie_rtctimer);
  208. } else
  209. rtc_timer_remove(rtc, &rtc->uie_rtctimer);
  210. out:
  211. mutex_unlock(&rtc->ops_lock);
  212. return err;
  213. }
  214. EXPORT_SYMBOL_GPL(rtc_update_irq_enable);
  215. /**
  216. * rtc_handle_legacy_irq - AIE, UIE and PIE event hook
  217. * @rtc: pointer to the rtc device
  218. *
  219. * This function is called when an AIE, UIE or PIE mode interrupt
  220. * has occured (or been emulated).
  221. *
  222. * Triggers the registered irq_task function callback.
  223. */
  224. static void rtc_handle_legacy_irq(struct rtc_device *rtc, int num, int mode)
  225. {
  226. unsigned long flags;
  227. /* mark one irq of the appropriate mode */
  228. spin_lock_irqsave(&rtc->irq_lock, flags);
  229. rtc->irq_data = (rtc->irq_data + (num << 8)) | (RTC_IRQF|mode);
  230. spin_unlock_irqrestore(&rtc->irq_lock, flags);
  231. /* call the task func */
  232. spin_lock_irqsave(&rtc->irq_task_lock, flags);
  233. if (rtc->irq_task)
  234. rtc->irq_task->func(rtc->irq_task->private_data);
  235. spin_unlock_irqrestore(&rtc->irq_task_lock, flags);
  236. wake_up_interruptible(&rtc->irq_queue);
  237. kill_fasync(&rtc->async_queue, SIGIO, POLL_IN);
  238. }
  239. /**
  240. * rtc_aie_update_irq - AIE mode rtctimer hook
  241. * @private: pointer to the rtc_device
  242. *
  243. * This functions is called when the aie_timer expires.
  244. */
  245. void rtc_aie_update_irq(void *private)
  246. {
  247. struct rtc_device *rtc = (struct rtc_device *)private;
  248. rtc_handle_legacy_irq(rtc, 1, RTC_AF);
  249. }
  250. /**
  251. * rtc_uie_update_irq - UIE mode rtctimer hook
  252. * @private: pointer to the rtc_device
  253. *
  254. * This functions is called when the uie_timer expires.
  255. */
  256. void rtc_uie_update_irq(void *private)
  257. {
  258. struct rtc_device *rtc = (struct rtc_device *)private;
  259. rtc_handle_legacy_irq(rtc, 1, RTC_UF);
  260. }
  261. /**
  262. * rtc_pie_update_irq - PIE mode hrtimer hook
  263. * @timer: pointer to the pie mode hrtimer
  264. *
  265. * This function is used to emulate PIE mode interrupts
  266. * using an hrtimer. This function is called when the periodic
  267. * hrtimer expires.
  268. */
  269. enum hrtimer_restart rtc_pie_update_irq(struct hrtimer *timer)
  270. {
  271. struct rtc_device *rtc;
  272. ktime_t period;
  273. int count;
  274. rtc = container_of(timer, struct rtc_device, pie_timer);
  275. period = ktime_set(0, NSEC_PER_SEC/rtc->irq_freq);
  276. count = hrtimer_forward_now(timer, period);
  277. rtc_handle_legacy_irq(rtc, count, RTC_PF);
  278. return HRTIMER_RESTART;
  279. }
  280. /**
  281. * rtc_update_irq - Triggered when a RTC interrupt occurs.
  282. * @rtc: the rtc device
  283. * @num: how many irqs are being reported (usually one)
  284. * @events: mask of RTC_IRQF with one or more of RTC_PF, RTC_AF, RTC_UF
  285. * Context: any
  286. */
  287. void rtc_update_irq(struct rtc_device *rtc,
  288. unsigned long num, unsigned long events)
  289. {
  290. schedule_work(&rtc->irqwork);
  291. }
  292. EXPORT_SYMBOL_GPL(rtc_update_irq);
  293. static int __rtc_match(struct device *dev, void *data)
  294. {
  295. char *name = (char *)data;
  296. if (strcmp(dev_name(dev), name) == 0)
  297. return 1;
  298. return 0;
  299. }
  300. struct rtc_device *rtc_class_open(char *name)
  301. {
  302. struct device *dev;
  303. struct rtc_device *rtc = NULL;
  304. dev = class_find_device(rtc_class, NULL, name, __rtc_match);
  305. if (dev)
  306. rtc = to_rtc_device(dev);
  307. if (rtc) {
  308. if (!try_module_get(rtc->owner)) {
  309. put_device(dev);
  310. rtc = NULL;
  311. }
  312. }
  313. return rtc;
  314. }
  315. EXPORT_SYMBOL_GPL(rtc_class_open);
  316. void rtc_class_close(struct rtc_device *rtc)
  317. {
  318. module_put(rtc->owner);
  319. put_device(&rtc->dev);
  320. }
  321. EXPORT_SYMBOL_GPL(rtc_class_close);
  322. int rtc_irq_register(struct rtc_device *rtc, struct rtc_task *task)
  323. {
  324. int retval = -EBUSY;
  325. if (task == NULL || task->func == NULL)
  326. return -EINVAL;
  327. /* Cannot register while the char dev is in use */
  328. if (test_and_set_bit_lock(RTC_DEV_BUSY, &rtc->flags))
  329. return -EBUSY;
  330. spin_lock_irq(&rtc->irq_task_lock);
  331. if (rtc->irq_task == NULL) {
  332. rtc->irq_task = task;
  333. retval = 0;
  334. }
  335. spin_unlock_irq(&rtc->irq_task_lock);
  336. clear_bit_unlock(RTC_DEV_BUSY, &rtc->flags);
  337. return retval;
  338. }
  339. EXPORT_SYMBOL_GPL(rtc_irq_register);
  340. void rtc_irq_unregister(struct rtc_device *rtc, struct rtc_task *task)
  341. {
  342. spin_lock_irq(&rtc->irq_task_lock);
  343. if (rtc->irq_task == task)
  344. rtc->irq_task = NULL;
  345. spin_unlock_irq(&rtc->irq_task_lock);
  346. }
  347. EXPORT_SYMBOL_GPL(rtc_irq_unregister);
  348. /**
  349. * rtc_irq_set_state - enable/disable 2^N Hz periodic IRQs
  350. * @rtc: the rtc device
  351. * @task: currently registered with rtc_irq_register()
  352. * @enabled: true to enable periodic IRQs
  353. * Context: any
  354. *
  355. * Note that rtc_irq_set_freq() should previously have been used to
  356. * specify the desired frequency of periodic IRQ task->func() callbacks.
  357. */
  358. int rtc_irq_set_state(struct rtc_device *rtc, struct rtc_task *task, int enabled)
  359. {
  360. int err = 0;
  361. unsigned long flags;
  362. spin_lock_irqsave(&rtc->irq_task_lock, flags);
  363. if (rtc->irq_task != NULL && task == NULL)
  364. err = -EBUSY;
  365. if (rtc->irq_task != task)
  366. err = -EACCES;
  367. if (enabled) {
  368. ktime_t period = ktime_set(0, NSEC_PER_SEC/rtc->irq_freq);
  369. hrtimer_start(&rtc->pie_timer, period, HRTIMER_MODE_REL);
  370. } else {
  371. hrtimer_cancel(&rtc->pie_timer);
  372. }
  373. rtc->pie_enabled = enabled;
  374. spin_unlock_irqrestore(&rtc->irq_task_lock, flags);
  375. return err;
  376. }
  377. EXPORT_SYMBOL_GPL(rtc_irq_set_state);
  378. /**
  379. * rtc_irq_set_freq - set 2^N Hz periodic IRQ frequency for IRQ
  380. * @rtc: the rtc device
  381. * @task: currently registered with rtc_irq_register()
  382. * @freq: positive frequency with which task->func() will be called
  383. * Context: any
  384. *
  385. * Note that rtc_irq_set_state() is used to enable or disable the
  386. * periodic IRQs.
  387. */
  388. int rtc_irq_set_freq(struct rtc_device *rtc, struct rtc_task *task, int freq)
  389. {
  390. int err = 0;
  391. unsigned long flags;
  392. if (freq <= 0)
  393. return -EINVAL;
  394. spin_lock_irqsave(&rtc->irq_task_lock, flags);
  395. if (rtc->irq_task != NULL && task == NULL)
  396. err = -EBUSY;
  397. if (rtc->irq_task != task)
  398. err = -EACCES;
  399. if (err == 0) {
  400. rtc->irq_freq = freq;
  401. if (rtc->pie_enabled) {
  402. ktime_t period;
  403. hrtimer_cancel(&rtc->pie_timer);
  404. period = ktime_set(0, NSEC_PER_SEC/rtc->irq_freq);
  405. hrtimer_start(&rtc->pie_timer, period,
  406. HRTIMER_MODE_REL);
  407. }
  408. }
  409. spin_unlock_irqrestore(&rtc->irq_task_lock, flags);
  410. return err;
  411. }
  412. EXPORT_SYMBOL_GPL(rtc_irq_set_freq);
  413. /**
  414. * rtc_timer_enqueue - Adds a rtc_timer to the rtc_device timerqueue
  415. * @rtc rtc device
  416. * @timer timer being added.
  417. *
  418. * Enqueues a timer onto the rtc devices timerqueue and sets
  419. * the next alarm event appropriately.
  420. *
  421. * Sets the enabled bit on the added timer.
  422. *
  423. * Must hold ops_lock for proper serialization of timerqueue
  424. */
  425. static int rtc_timer_enqueue(struct rtc_device *rtc, struct rtc_timer *timer)
  426. {
  427. timer->enabled = 1;
  428. timerqueue_add(&rtc->timerqueue, &timer->node);
  429. if (&timer->node == timerqueue_getnext(&rtc->timerqueue)) {
  430. struct rtc_wkalrm alarm;
  431. int err;
  432. alarm.time = rtc_ktime_to_tm(timer->node.expires);
  433. alarm.enabled = 1;
  434. err = __rtc_set_alarm(rtc, &alarm);
  435. if (err == -ETIME)
  436. schedule_work(&rtc->irqwork);
  437. else if (err) {
  438. timerqueue_del(&rtc->timerqueue, &timer->node);
  439. timer->enabled = 0;
  440. return err;
  441. }
  442. }
  443. return 0;
  444. }
  445. /**
  446. * rtc_timer_remove - Removes a rtc_timer from the rtc_device timerqueue
  447. * @rtc rtc device
  448. * @timer timer being removed.
  449. *
  450. * Removes a timer onto the rtc devices timerqueue and sets
  451. * the next alarm event appropriately.
  452. *
  453. * Clears the enabled bit on the removed timer.
  454. *
  455. * Must hold ops_lock for proper serialization of timerqueue
  456. */
  457. static void rtc_timer_remove(struct rtc_device *rtc, struct rtc_timer *timer)
  458. {
  459. struct timerqueue_node *next = timerqueue_getnext(&rtc->timerqueue);
  460. timerqueue_del(&rtc->timerqueue, &timer->node);
  461. timer->enabled = 0;
  462. if (next == &timer->node) {
  463. struct rtc_wkalrm alarm;
  464. int err;
  465. next = timerqueue_getnext(&rtc->timerqueue);
  466. if (!next)
  467. return;
  468. alarm.time = rtc_ktime_to_tm(next->expires);
  469. alarm.enabled = 1;
  470. err = __rtc_set_alarm(rtc, &alarm);
  471. if (err == -ETIME)
  472. schedule_work(&rtc->irqwork);
  473. }
  474. }
  475. /**
  476. * rtc_timer_do_work - Expires rtc timers
  477. * @rtc rtc device
  478. * @timer timer being removed.
  479. *
  480. * Expires rtc timers. Reprograms next alarm event if needed.
  481. * Called via worktask.
  482. *
  483. * Serializes access to timerqueue via ops_lock mutex
  484. */
  485. void rtc_timer_do_work(struct work_struct *work)
  486. {
  487. struct rtc_timer *timer;
  488. struct timerqueue_node *next;
  489. ktime_t now;
  490. struct rtc_time tm;
  491. struct rtc_device *rtc =
  492. container_of(work, struct rtc_device, irqwork);
  493. mutex_lock(&rtc->ops_lock);
  494. again:
  495. __rtc_read_time(rtc, &tm);
  496. now = rtc_tm_to_ktime(tm);
  497. while ((next = timerqueue_getnext(&rtc->timerqueue))) {
  498. if (next->expires.tv64 > now.tv64)
  499. break;
  500. /* expire timer */
  501. timer = container_of(next, struct rtc_timer, node);
  502. timerqueue_del(&rtc->timerqueue, &timer->node);
  503. timer->enabled = 0;
  504. if (timer->task.func)
  505. timer->task.func(timer->task.private_data);
  506. /* Re-add/fwd periodic timers */
  507. if (ktime_to_ns(timer->period)) {
  508. timer->node.expires = ktime_add(timer->node.expires,
  509. timer->period);
  510. timer->enabled = 1;
  511. timerqueue_add(&rtc->timerqueue, &timer->node);
  512. }
  513. }
  514. /* Set next alarm */
  515. if (next) {
  516. struct rtc_wkalrm alarm;
  517. int err;
  518. alarm.time = rtc_ktime_to_tm(next->expires);
  519. alarm.enabled = 1;
  520. err = __rtc_set_alarm(rtc, &alarm);
  521. if (err == -ETIME)
  522. goto again;
  523. }
  524. mutex_unlock(&rtc->ops_lock);
  525. }
  526. /* rtc_timer_init - Initializes an rtc_timer
  527. * @timer: timer to be intiialized
  528. * @f: function pointer to be called when timer fires
  529. * @data: private data passed to function pointer
  530. *
  531. * Kernel interface to initializing an rtc_timer.
  532. */
  533. void rtc_timer_init(struct rtc_timer *timer, void (*f)(void* p), void* data)
  534. {
  535. timerqueue_init(&timer->node);
  536. timer->enabled = 0;
  537. timer->task.func = f;
  538. timer->task.private_data = data;
  539. }
  540. /* rtc_timer_start - Sets an rtc_timer to fire in the future
  541. * @ rtc: rtc device to be used
  542. * @ timer: timer being set
  543. * @ expires: time at which to expire the timer
  544. * @ period: period that the timer will recur
  545. *
  546. * Kernel interface to set an rtc_timer
  547. */
  548. int rtc_timer_start(struct rtc_device *rtc, struct rtc_timer* timer,
  549. ktime_t expires, ktime_t period)
  550. {
  551. int ret = 0;
  552. mutex_lock(&rtc->ops_lock);
  553. if (timer->enabled)
  554. rtc_timer_remove(rtc, timer);
  555. timer->node.expires = expires;
  556. timer->period = period;
  557. ret = rtc_timer_enqueue(rtc, timer);
  558. mutex_unlock(&rtc->ops_lock);
  559. return ret;
  560. }
  561. /* rtc_timer_cancel - Stops an rtc_timer
  562. * @ rtc: rtc device to be used
  563. * @ timer: timer being set
  564. *
  565. * Kernel interface to cancel an rtc_timer
  566. */
  567. int rtc_timer_cancel(struct rtc_device *rtc, struct rtc_timer* timer)
  568. {
  569. int ret = 0;
  570. mutex_lock(&rtc->ops_lock);
  571. if (timer->enabled)
  572. rtc_timer_remove(rtc, timer);
  573. mutex_unlock(&rtc->ops_lock);
  574. return ret;
  575. }