interface.c 16 KB

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