sh_cmt.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. /*
  2. * SuperH Timer Support - CMT
  3. *
  4. * Copyright (C) 2008 Magnus Damm
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include <linux/init.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/spinlock.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/ioport.h>
  24. #include <linux/io.h>
  25. #include <linux/clk.h>
  26. #include <linux/irq.h>
  27. #include <linux/err.h>
  28. #include <linux/clocksource.h>
  29. #include <linux/clockchips.h>
  30. #include <linux/sh_timer.h>
  31. struct sh_cmt_priv {
  32. void __iomem *mapbase;
  33. struct clk *clk;
  34. unsigned long width; /* 16 or 32 bit version of hardware block */
  35. unsigned long overflow_bit;
  36. unsigned long clear_bits;
  37. struct irqaction irqaction;
  38. struct platform_device *pdev;
  39. unsigned long flags;
  40. unsigned long match_value;
  41. unsigned long next_match_value;
  42. unsigned long max_match_value;
  43. unsigned long rate;
  44. spinlock_t lock;
  45. struct clock_event_device ced;
  46. struct clocksource cs;
  47. unsigned long total_cycles;
  48. };
  49. static DEFINE_SPINLOCK(sh_cmt_lock);
  50. #define CMSTR -1 /* shared register */
  51. #define CMCSR 0 /* channel register */
  52. #define CMCNT 1 /* channel register */
  53. #define CMCOR 2 /* channel register */
  54. static inline unsigned long sh_cmt_read(struct sh_cmt_priv *p, int reg_nr)
  55. {
  56. struct sh_timer_config *cfg = p->pdev->dev.platform_data;
  57. void __iomem *base = p->mapbase;
  58. unsigned long offs;
  59. if (reg_nr == CMSTR) {
  60. offs = 0;
  61. base -= cfg->channel_offset;
  62. } else
  63. offs = reg_nr;
  64. if (p->width == 16)
  65. offs <<= 1;
  66. else {
  67. offs <<= 2;
  68. if ((reg_nr == CMCNT) || (reg_nr == CMCOR))
  69. return ioread32(base + offs);
  70. }
  71. return ioread16(base + offs);
  72. }
  73. static inline void sh_cmt_write(struct sh_cmt_priv *p, int reg_nr,
  74. unsigned long value)
  75. {
  76. struct sh_timer_config *cfg = p->pdev->dev.platform_data;
  77. void __iomem *base = p->mapbase;
  78. unsigned long offs;
  79. if (reg_nr == CMSTR) {
  80. offs = 0;
  81. base -= cfg->channel_offset;
  82. } else
  83. offs = reg_nr;
  84. if (p->width == 16)
  85. offs <<= 1;
  86. else {
  87. offs <<= 2;
  88. if ((reg_nr == CMCNT) || (reg_nr == CMCOR)) {
  89. iowrite32(value, base + offs);
  90. return;
  91. }
  92. }
  93. iowrite16(value, base + offs);
  94. }
  95. static unsigned long sh_cmt_get_counter(struct sh_cmt_priv *p,
  96. int *has_wrapped)
  97. {
  98. unsigned long v1, v2, v3;
  99. int o1, o2;
  100. o1 = sh_cmt_read(p, CMCSR) & p->overflow_bit;
  101. /* Make sure the timer value is stable. Stolen from acpi_pm.c */
  102. do {
  103. o2 = o1;
  104. v1 = sh_cmt_read(p, CMCNT);
  105. v2 = sh_cmt_read(p, CMCNT);
  106. v3 = sh_cmt_read(p, CMCNT);
  107. o1 = sh_cmt_read(p, CMCSR) & p->overflow_bit;
  108. } while (unlikely((o1 != o2) || (v1 > v2 && v1 < v3)
  109. || (v2 > v3 && v2 < v1) || (v3 > v1 && v3 < v2)));
  110. *has_wrapped = o1;
  111. return v2;
  112. }
  113. static void sh_cmt_start_stop_ch(struct sh_cmt_priv *p, int start)
  114. {
  115. struct sh_timer_config *cfg = p->pdev->dev.platform_data;
  116. unsigned long flags, value;
  117. /* start stop register shared by multiple timer channels */
  118. spin_lock_irqsave(&sh_cmt_lock, flags);
  119. value = sh_cmt_read(p, CMSTR);
  120. if (start)
  121. value |= 1 << cfg->timer_bit;
  122. else
  123. value &= ~(1 << cfg->timer_bit);
  124. sh_cmt_write(p, CMSTR, value);
  125. spin_unlock_irqrestore(&sh_cmt_lock, flags);
  126. }
  127. static int sh_cmt_enable(struct sh_cmt_priv *p, unsigned long *rate)
  128. {
  129. struct sh_timer_config *cfg = p->pdev->dev.platform_data;
  130. int ret;
  131. /* enable clock */
  132. ret = clk_enable(p->clk);
  133. if (ret) {
  134. pr_err("sh_cmt: cannot enable clock \"%s\"\n", cfg->clk);
  135. return ret;
  136. }
  137. /* make sure channel is disabled */
  138. sh_cmt_start_stop_ch(p, 0);
  139. /* configure channel, periodic mode and maximum timeout */
  140. if (p->width == 16) {
  141. *rate = clk_get_rate(p->clk) / 512;
  142. sh_cmt_write(p, CMCSR, 0x43);
  143. } else {
  144. *rate = clk_get_rate(p->clk) / 8;
  145. sh_cmt_write(p, CMCSR, 0x01a4);
  146. }
  147. sh_cmt_write(p, CMCOR, 0xffffffff);
  148. sh_cmt_write(p, CMCNT, 0);
  149. /* enable channel */
  150. sh_cmt_start_stop_ch(p, 1);
  151. return 0;
  152. }
  153. static void sh_cmt_disable(struct sh_cmt_priv *p)
  154. {
  155. /* disable channel */
  156. sh_cmt_start_stop_ch(p, 0);
  157. /* disable interrupts in CMT block */
  158. sh_cmt_write(p, CMCSR, 0);
  159. /* stop clock */
  160. clk_disable(p->clk);
  161. }
  162. /* private flags */
  163. #define FLAG_CLOCKEVENT (1 << 0)
  164. #define FLAG_CLOCKSOURCE (1 << 1)
  165. #define FLAG_REPROGRAM (1 << 2)
  166. #define FLAG_SKIPEVENT (1 << 3)
  167. #define FLAG_IRQCONTEXT (1 << 4)
  168. static void sh_cmt_clock_event_program_verify(struct sh_cmt_priv *p,
  169. int absolute)
  170. {
  171. unsigned long new_match;
  172. unsigned long value = p->next_match_value;
  173. unsigned long delay = 0;
  174. unsigned long now = 0;
  175. int has_wrapped;
  176. now = sh_cmt_get_counter(p, &has_wrapped);
  177. p->flags |= FLAG_REPROGRAM; /* force reprogram */
  178. if (has_wrapped) {
  179. /* we're competing with the interrupt handler.
  180. * -> let the interrupt handler reprogram the timer.
  181. * -> interrupt number two handles the event.
  182. */
  183. p->flags |= FLAG_SKIPEVENT;
  184. return;
  185. }
  186. if (absolute)
  187. now = 0;
  188. do {
  189. /* reprogram the timer hardware,
  190. * but don't save the new match value yet.
  191. */
  192. new_match = now + value + delay;
  193. if (new_match > p->max_match_value)
  194. new_match = p->max_match_value;
  195. sh_cmt_write(p, CMCOR, new_match);
  196. now = sh_cmt_get_counter(p, &has_wrapped);
  197. if (has_wrapped && (new_match > p->match_value)) {
  198. /* we are changing to a greater match value,
  199. * so this wrap must be caused by the counter
  200. * matching the old value.
  201. * -> first interrupt reprograms the timer.
  202. * -> interrupt number two handles the event.
  203. */
  204. p->flags |= FLAG_SKIPEVENT;
  205. break;
  206. }
  207. if (has_wrapped) {
  208. /* we are changing to a smaller match value,
  209. * so the wrap must be caused by the counter
  210. * matching the new value.
  211. * -> save programmed match value.
  212. * -> let isr handle the event.
  213. */
  214. p->match_value = new_match;
  215. break;
  216. }
  217. /* be safe: verify hardware settings */
  218. if (now < new_match) {
  219. /* timer value is below match value, all good.
  220. * this makes sure we won't miss any match events.
  221. * -> save programmed match value.
  222. * -> let isr handle the event.
  223. */
  224. p->match_value = new_match;
  225. break;
  226. }
  227. /* the counter has reached a value greater
  228. * than our new match value. and since the
  229. * has_wrapped flag isn't set we must have
  230. * programmed a too close event.
  231. * -> increase delay and retry.
  232. */
  233. if (delay)
  234. delay <<= 1;
  235. else
  236. delay = 1;
  237. if (!delay)
  238. pr_warning("sh_cmt: too long delay\n");
  239. } while (delay);
  240. }
  241. static void sh_cmt_set_next(struct sh_cmt_priv *p, unsigned long delta)
  242. {
  243. unsigned long flags;
  244. if (delta > p->max_match_value)
  245. pr_warning("sh_cmt: delta out of range\n");
  246. spin_lock_irqsave(&p->lock, flags);
  247. p->next_match_value = delta;
  248. sh_cmt_clock_event_program_verify(p, 0);
  249. spin_unlock_irqrestore(&p->lock, flags);
  250. }
  251. static irqreturn_t sh_cmt_interrupt(int irq, void *dev_id)
  252. {
  253. struct sh_cmt_priv *p = dev_id;
  254. /* clear flags */
  255. sh_cmt_write(p, CMCSR, sh_cmt_read(p, CMCSR) & p->clear_bits);
  256. /* update clock source counter to begin with if enabled
  257. * the wrap flag should be cleared by the timer specific
  258. * isr before we end up here.
  259. */
  260. if (p->flags & FLAG_CLOCKSOURCE)
  261. p->total_cycles += p->match_value;
  262. if (!(p->flags & FLAG_REPROGRAM))
  263. p->next_match_value = p->max_match_value;
  264. p->flags |= FLAG_IRQCONTEXT;
  265. if (p->flags & FLAG_CLOCKEVENT) {
  266. if (!(p->flags & FLAG_SKIPEVENT)) {
  267. if (p->ced.mode == CLOCK_EVT_MODE_ONESHOT) {
  268. p->next_match_value = p->max_match_value;
  269. p->flags |= FLAG_REPROGRAM;
  270. }
  271. p->ced.event_handler(&p->ced);
  272. }
  273. }
  274. p->flags &= ~FLAG_SKIPEVENT;
  275. if (p->flags & FLAG_REPROGRAM) {
  276. p->flags &= ~FLAG_REPROGRAM;
  277. sh_cmt_clock_event_program_verify(p, 1);
  278. if (p->flags & FLAG_CLOCKEVENT)
  279. if ((p->ced.mode == CLOCK_EVT_MODE_SHUTDOWN)
  280. || (p->match_value == p->next_match_value))
  281. p->flags &= ~FLAG_REPROGRAM;
  282. }
  283. p->flags &= ~FLAG_IRQCONTEXT;
  284. return IRQ_HANDLED;
  285. }
  286. static int sh_cmt_start(struct sh_cmt_priv *p, unsigned long flag)
  287. {
  288. int ret = 0;
  289. unsigned long flags;
  290. spin_lock_irqsave(&p->lock, flags);
  291. if (!(p->flags & (FLAG_CLOCKEVENT | FLAG_CLOCKSOURCE)))
  292. ret = sh_cmt_enable(p, &p->rate);
  293. if (ret)
  294. goto out;
  295. p->flags |= flag;
  296. /* setup timeout if no clockevent */
  297. if ((flag == FLAG_CLOCKSOURCE) && (!(p->flags & FLAG_CLOCKEVENT)))
  298. sh_cmt_set_next(p, p->max_match_value);
  299. out:
  300. spin_unlock_irqrestore(&p->lock, flags);
  301. return ret;
  302. }
  303. static void sh_cmt_stop(struct sh_cmt_priv *p, unsigned long flag)
  304. {
  305. unsigned long flags;
  306. unsigned long f;
  307. spin_lock_irqsave(&p->lock, flags);
  308. f = p->flags & (FLAG_CLOCKEVENT | FLAG_CLOCKSOURCE);
  309. p->flags &= ~flag;
  310. if (f && !(p->flags & (FLAG_CLOCKEVENT | FLAG_CLOCKSOURCE)))
  311. sh_cmt_disable(p);
  312. /* adjust the timeout to maximum if only clocksource left */
  313. if ((flag == FLAG_CLOCKEVENT) && (p->flags & FLAG_CLOCKSOURCE))
  314. sh_cmt_set_next(p, p->max_match_value);
  315. spin_unlock_irqrestore(&p->lock, flags);
  316. }
  317. static struct sh_cmt_priv *cs_to_sh_cmt(struct clocksource *cs)
  318. {
  319. return container_of(cs, struct sh_cmt_priv, cs);
  320. }
  321. static cycle_t sh_cmt_clocksource_read(struct clocksource *cs)
  322. {
  323. struct sh_cmt_priv *p = cs_to_sh_cmt(cs);
  324. unsigned long flags, raw;
  325. unsigned long value;
  326. int has_wrapped;
  327. spin_lock_irqsave(&p->lock, flags);
  328. value = p->total_cycles;
  329. raw = sh_cmt_get_counter(p, &has_wrapped);
  330. if (unlikely(has_wrapped))
  331. raw += p->match_value;
  332. spin_unlock_irqrestore(&p->lock, flags);
  333. return value + raw;
  334. }
  335. static int sh_cmt_clocksource_enable(struct clocksource *cs)
  336. {
  337. struct sh_cmt_priv *p = cs_to_sh_cmt(cs);
  338. int ret;
  339. p->total_cycles = 0;
  340. ret = sh_cmt_start(p, FLAG_CLOCKSOURCE);
  341. if (ret)
  342. return ret;
  343. /* TODO: calculate good shift from rate and counter bit width */
  344. cs->shift = 0;
  345. cs->mult = clocksource_hz2mult(p->rate, cs->shift);
  346. return 0;
  347. }
  348. static void sh_cmt_clocksource_disable(struct clocksource *cs)
  349. {
  350. sh_cmt_stop(cs_to_sh_cmt(cs), FLAG_CLOCKSOURCE);
  351. }
  352. static int sh_cmt_register_clocksource(struct sh_cmt_priv *p,
  353. char *name, unsigned long rating)
  354. {
  355. struct clocksource *cs = &p->cs;
  356. cs->name = name;
  357. cs->rating = rating;
  358. cs->read = sh_cmt_clocksource_read;
  359. cs->enable = sh_cmt_clocksource_enable;
  360. cs->disable = sh_cmt_clocksource_disable;
  361. cs->mask = CLOCKSOURCE_MASK(sizeof(unsigned long) * 8);
  362. cs->flags = CLOCK_SOURCE_IS_CONTINUOUS;
  363. pr_info("sh_cmt: %s used as clock source\n", cs->name);
  364. clocksource_register(cs);
  365. return 0;
  366. }
  367. static struct sh_cmt_priv *ced_to_sh_cmt(struct clock_event_device *ced)
  368. {
  369. return container_of(ced, struct sh_cmt_priv, ced);
  370. }
  371. static void sh_cmt_clock_event_start(struct sh_cmt_priv *p, int periodic)
  372. {
  373. struct clock_event_device *ced = &p->ced;
  374. sh_cmt_start(p, FLAG_CLOCKEVENT);
  375. /* TODO: calculate good shift from rate and counter bit width */
  376. ced->shift = 32;
  377. ced->mult = div_sc(p->rate, NSEC_PER_SEC, ced->shift);
  378. ced->max_delta_ns = clockevent_delta2ns(p->max_match_value, ced);
  379. ced->min_delta_ns = clockevent_delta2ns(0x1f, ced);
  380. if (periodic)
  381. sh_cmt_set_next(p, (p->rate + HZ/2) / HZ);
  382. else
  383. sh_cmt_set_next(p, p->max_match_value);
  384. }
  385. static void sh_cmt_clock_event_mode(enum clock_event_mode mode,
  386. struct clock_event_device *ced)
  387. {
  388. struct sh_cmt_priv *p = ced_to_sh_cmt(ced);
  389. /* deal with old setting first */
  390. switch (ced->mode) {
  391. case CLOCK_EVT_MODE_PERIODIC:
  392. case CLOCK_EVT_MODE_ONESHOT:
  393. sh_cmt_stop(p, FLAG_CLOCKEVENT);
  394. break;
  395. default:
  396. break;
  397. }
  398. switch (mode) {
  399. case CLOCK_EVT_MODE_PERIODIC:
  400. pr_info("sh_cmt: %s used for periodic clock events\n",
  401. ced->name);
  402. sh_cmt_clock_event_start(p, 1);
  403. break;
  404. case CLOCK_EVT_MODE_ONESHOT:
  405. pr_info("sh_cmt: %s used for oneshot clock events\n",
  406. ced->name);
  407. sh_cmt_clock_event_start(p, 0);
  408. break;
  409. case CLOCK_EVT_MODE_SHUTDOWN:
  410. case CLOCK_EVT_MODE_UNUSED:
  411. sh_cmt_stop(p, FLAG_CLOCKEVENT);
  412. break;
  413. default:
  414. break;
  415. }
  416. }
  417. static int sh_cmt_clock_event_next(unsigned long delta,
  418. struct clock_event_device *ced)
  419. {
  420. struct sh_cmt_priv *p = ced_to_sh_cmt(ced);
  421. BUG_ON(ced->mode != CLOCK_EVT_MODE_ONESHOT);
  422. if (likely(p->flags & FLAG_IRQCONTEXT))
  423. p->next_match_value = delta;
  424. else
  425. sh_cmt_set_next(p, delta);
  426. return 0;
  427. }
  428. static void sh_cmt_register_clockevent(struct sh_cmt_priv *p,
  429. char *name, unsigned long rating)
  430. {
  431. struct clock_event_device *ced = &p->ced;
  432. memset(ced, 0, sizeof(*ced));
  433. ced->name = name;
  434. ced->features = CLOCK_EVT_FEAT_PERIODIC;
  435. ced->features |= CLOCK_EVT_FEAT_ONESHOT;
  436. ced->rating = rating;
  437. ced->cpumask = cpumask_of(0);
  438. ced->set_next_event = sh_cmt_clock_event_next;
  439. ced->set_mode = sh_cmt_clock_event_mode;
  440. pr_info("sh_cmt: %s used for clock events\n", ced->name);
  441. clockevents_register_device(ced);
  442. }
  443. static int sh_cmt_register(struct sh_cmt_priv *p, char *name,
  444. unsigned long clockevent_rating,
  445. unsigned long clocksource_rating)
  446. {
  447. if (p->width == (sizeof(p->max_match_value) * 8))
  448. p->max_match_value = ~0;
  449. else
  450. p->max_match_value = (1 << p->width) - 1;
  451. p->match_value = p->max_match_value;
  452. spin_lock_init(&p->lock);
  453. if (clockevent_rating)
  454. sh_cmt_register_clockevent(p, name, clockevent_rating);
  455. if (clocksource_rating)
  456. sh_cmt_register_clocksource(p, name, clocksource_rating);
  457. return 0;
  458. }
  459. static int sh_cmt_setup(struct sh_cmt_priv *p, struct platform_device *pdev)
  460. {
  461. struct sh_timer_config *cfg = pdev->dev.platform_data;
  462. struct resource *res;
  463. int irq, ret;
  464. ret = -ENXIO;
  465. memset(p, 0, sizeof(*p));
  466. p->pdev = pdev;
  467. if (!cfg) {
  468. dev_err(&p->pdev->dev, "missing platform data\n");
  469. goto err0;
  470. }
  471. platform_set_drvdata(pdev, p);
  472. res = platform_get_resource(p->pdev, IORESOURCE_MEM, 0);
  473. if (!res) {
  474. dev_err(&p->pdev->dev, "failed to get I/O memory\n");
  475. goto err0;
  476. }
  477. irq = platform_get_irq(p->pdev, 0);
  478. if (irq < 0) {
  479. dev_err(&p->pdev->dev, "failed to get irq\n");
  480. goto err0;
  481. }
  482. /* map memory, let mapbase point to our channel */
  483. p->mapbase = ioremap_nocache(res->start, resource_size(res));
  484. if (p->mapbase == NULL) {
  485. pr_err("sh_cmt: failed to remap I/O memory\n");
  486. goto err0;
  487. }
  488. /* request irq using setup_irq() (too early for request_irq()) */
  489. p->irqaction.name = cfg->name;
  490. p->irqaction.handler = sh_cmt_interrupt;
  491. p->irqaction.dev_id = p;
  492. p->irqaction.flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL;
  493. ret = setup_irq(irq, &p->irqaction);
  494. if (ret) {
  495. pr_err("sh_cmt: failed to request irq %d\n", irq);
  496. goto err1;
  497. }
  498. /* get hold of clock */
  499. p->clk = clk_get(&p->pdev->dev, cfg->clk);
  500. if (IS_ERR(p->clk)) {
  501. pr_err("sh_cmt: cannot get clock \"%s\"\n", cfg->clk);
  502. ret = PTR_ERR(p->clk);
  503. goto err2;
  504. }
  505. if (resource_size(res) == 6) {
  506. p->width = 16;
  507. p->overflow_bit = 0x80;
  508. p->clear_bits = ~0x80;
  509. } else {
  510. p->width = 32;
  511. p->overflow_bit = 0x8000;
  512. p->clear_bits = ~0xc000;
  513. }
  514. return sh_cmt_register(p, cfg->name,
  515. cfg->clockevent_rating,
  516. cfg->clocksource_rating);
  517. err2:
  518. remove_irq(irq, &p->irqaction);
  519. err1:
  520. iounmap(p->mapbase);
  521. err0:
  522. return ret;
  523. }
  524. static int __devinit sh_cmt_probe(struct platform_device *pdev)
  525. {
  526. struct sh_cmt_priv *p = platform_get_drvdata(pdev);
  527. struct sh_timer_config *cfg = pdev->dev.platform_data;
  528. int ret;
  529. if (p) {
  530. pr_info("sh_cmt: %s kept as earlytimer\n", cfg->name);
  531. return 0;
  532. }
  533. p = kmalloc(sizeof(*p), GFP_KERNEL);
  534. if (p == NULL) {
  535. dev_err(&pdev->dev, "failed to allocate driver data\n");
  536. return -ENOMEM;
  537. }
  538. ret = sh_cmt_setup(p, pdev);
  539. if (ret) {
  540. kfree(p);
  541. platform_set_drvdata(pdev, NULL);
  542. }
  543. return ret;
  544. }
  545. static int __devexit sh_cmt_remove(struct platform_device *pdev)
  546. {
  547. return -EBUSY; /* cannot unregister clockevent and clocksource */
  548. }
  549. static struct platform_driver sh_cmt_device_driver = {
  550. .probe = sh_cmt_probe,
  551. .remove = __devexit_p(sh_cmt_remove),
  552. .driver = {
  553. .name = "sh_cmt",
  554. }
  555. };
  556. static int __init sh_cmt_init(void)
  557. {
  558. return platform_driver_register(&sh_cmt_device_driver);
  559. }
  560. static void __exit sh_cmt_exit(void)
  561. {
  562. platform_driver_unregister(&sh_cmt_device_driver);
  563. }
  564. early_platform_init("earlytimer", &sh_cmt_device_driver);
  565. module_init(sh_cmt_init);
  566. module_exit(sh_cmt_exit);
  567. MODULE_AUTHOR("Magnus Damm");
  568. MODULE_DESCRIPTION("SuperH CMT Timer Driver");
  569. MODULE_LICENSE("GPL v2");