sh_cmt.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  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. /* stop clock */
  158. clk_disable(p->clk);
  159. }
  160. /* private flags */
  161. #define FLAG_CLOCKEVENT (1 << 0)
  162. #define FLAG_CLOCKSOURCE (1 << 1)
  163. #define FLAG_REPROGRAM (1 << 2)
  164. #define FLAG_SKIPEVENT (1 << 3)
  165. #define FLAG_IRQCONTEXT (1 << 4)
  166. static void sh_cmt_clock_event_program_verify(struct sh_cmt_priv *p,
  167. int absolute)
  168. {
  169. unsigned long new_match;
  170. unsigned long value = p->next_match_value;
  171. unsigned long delay = 0;
  172. unsigned long now = 0;
  173. int has_wrapped;
  174. now = sh_cmt_get_counter(p, &has_wrapped);
  175. p->flags |= FLAG_REPROGRAM; /* force reprogram */
  176. if (has_wrapped) {
  177. /* we're competing with the interrupt handler.
  178. * -> let the interrupt handler reprogram the timer.
  179. * -> interrupt number two handles the event.
  180. */
  181. p->flags |= FLAG_SKIPEVENT;
  182. return;
  183. }
  184. if (absolute)
  185. now = 0;
  186. do {
  187. /* reprogram the timer hardware,
  188. * but don't save the new match value yet.
  189. */
  190. new_match = now + value + delay;
  191. if (new_match > p->max_match_value)
  192. new_match = p->max_match_value;
  193. sh_cmt_write(p, CMCOR, new_match);
  194. now = sh_cmt_get_counter(p, &has_wrapped);
  195. if (has_wrapped && (new_match > p->match_value)) {
  196. /* we are changing to a greater match value,
  197. * so this wrap must be caused by the counter
  198. * matching the old value.
  199. * -> first interrupt reprograms the timer.
  200. * -> interrupt number two handles the event.
  201. */
  202. p->flags |= FLAG_SKIPEVENT;
  203. break;
  204. }
  205. if (has_wrapped) {
  206. /* we are changing to a smaller match value,
  207. * so the wrap must be caused by the counter
  208. * matching the new value.
  209. * -> save programmed match value.
  210. * -> let isr handle the event.
  211. */
  212. p->match_value = new_match;
  213. break;
  214. }
  215. /* be safe: verify hardware settings */
  216. if (now < new_match) {
  217. /* timer value is below match value, all good.
  218. * this makes sure we won't miss any match events.
  219. * -> save programmed match value.
  220. * -> let isr handle the event.
  221. */
  222. p->match_value = new_match;
  223. break;
  224. }
  225. /* the counter has reached a value greater
  226. * than our new match value. and since the
  227. * has_wrapped flag isn't set we must have
  228. * programmed a too close event.
  229. * -> increase delay and retry.
  230. */
  231. if (delay)
  232. delay <<= 1;
  233. else
  234. delay = 1;
  235. if (!delay)
  236. pr_warning("sh_cmt: too long delay\n");
  237. } while (delay);
  238. }
  239. static void sh_cmt_set_next(struct sh_cmt_priv *p, unsigned long delta)
  240. {
  241. unsigned long flags;
  242. if (delta > p->max_match_value)
  243. pr_warning("sh_cmt: delta out of range\n");
  244. spin_lock_irqsave(&p->lock, flags);
  245. p->next_match_value = delta;
  246. sh_cmt_clock_event_program_verify(p, 0);
  247. spin_unlock_irqrestore(&p->lock, flags);
  248. }
  249. static irqreturn_t sh_cmt_interrupt(int irq, void *dev_id)
  250. {
  251. struct sh_cmt_priv *p = dev_id;
  252. /* clear flags */
  253. sh_cmt_write(p, CMCSR, sh_cmt_read(p, CMCSR) & p->clear_bits);
  254. /* update clock source counter to begin with if enabled
  255. * the wrap flag should be cleared by the timer specific
  256. * isr before we end up here.
  257. */
  258. if (p->flags & FLAG_CLOCKSOURCE)
  259. p->total_cycles += p->match_value;
  260. if (!(p->flags & FLAG_REPROGRAM))
  261. p->next_match_value = p->max_match_value;
  262. p->flags |= FLAG_IRQCONTEXT;
  263. if (p->flags & FLAG_CLOCKEVENT) {
  264. if (!(p->flags & FLAG_SKIPEVENT)) {
  265. if (p->ced.mode == CLOCK_EVT_MODE_ONESHOT) {
  266. p->next_match_value = p->max_match_value;
  267. p->flags |= FLAG_REPROGRAM;
  268. }
  269. p->ced.event_handler(&p->ced);
  270. }
  271. }
  272. p->flags &= ~FLAG_SKIPEVENT;
  273. if (p->flags & FLAG_REPROGRAM) {
  274. p->flags &= ~FLAG_REPROGRAM;
  275. sh_cmt_clock_event_program_verify(p, 1);
  276. if (p->flags & FLAG_CLOCKEVENT)
  277. if ((p->ced.mode == CLOCK_EVT_MODE_SHUTDOWN)
  278. || (p->match_value == p->next_match_value))
  279. p->flags &= ~FLAG_REPROGRAM;
  280. }
  281. p->flags &= ~FLAG_IRQCONTEXT;
  282. return IRQ_HANDLED;
  283. }
  284. static int sh_cmt_start(struct sh_cmt_priv *p, unsigned long flag)
  285. {
  286. int ret = 0;
  287. unsigned long flags;
  288. spin_lock_irqsave(&p->lock, flags);
  289. if (!(p->flags & (FLAG_CLOCKEVENT | FLAG_CLOCKSOURCE)))
  290. ret = sh_cmt_enable(p, &p->rate);
  291. if (ret)
  292. goto out;
  293. p->flags |= flag;
  294. /* setup timeout if no clockevent */
  295. if ((flag == FLAG_CLOCKSOURCE) && (!(p->flags & FLAG_CLOCKEVENT)))
  296. sh_cmt_set_next(p, p->max_match_value);
  297. out:
  298. spin_unlock_irqrestore(&p->lock, flags);
  299. return ret;
  300. }
  301. static void sh_cmt_stop(struct sh_cmt_priv *p, unsigned long flag)
  302. {
  303. unsigned long flags;
  304. unsigned long f;
  305. spin_lock_irqsave(&p->lock, flags);
  306. f = p->flags & (FLAG_CLOCKEVENT | FLAG_CLOCKSOURCE);
  307. p->flags &= ~flag;
  308. if (f && !(p->flags & (FLAG_CLOCKEVENT | FLAG_CLOCKSOURCE)))
  309. sh_cmt_disable(p);
  310. /* adjust the timeout to maximum if only clocksource left */
  311. if ((flag == FLAG_CLOCKEVENT) && (p->flags & FLAG_CLOCKSOURCE))
  312. sh_cmt_set_next(p, p->max_match_value);
  313. spin_unlock_irqrestore(&p->lock, flags);
  314. }
  315. static struct sh_cmt_priv *cs_to_sh_cmt(struct clocksource *cs)
  316. {
  317. return container_of(cs, struct sh_cmt_priv, cs);
  318. }
  319. static cycle_t sh_cmt_clocksource_read(struct clocksource *cs)
  320. {
  321. struct sh_cmt_priv *p = cs_to_sh_cmt(cs);
  322. unsigned long flags, raw;
  323. unsigned long value;
  324. int has_wrapped;
  325. spin_lock_irqsave(&p->lock, flags);
  326. value = p->total_cycles;
  327. raw = sh_cmt_get_counter(p, &has_wrapped);
  328. if (unlikely(has_wrapped))
  329. raw += p->match_value;
  330. spin_unlock_irqrestore(&p->lock, flags);
  331. return value + raw;
  332. }
  333. static int sh_cmt_clocksource_enable(struct clocksource *cs)
  334. {
  335. struct sh_cmt_priv *p = cs_to_sh_cmt(cs);
  336. int ret;
  337. p->total_cycles = 0;
  338. ret = sh_cmt_start(p, FLAG_CLOCKSOURCE);
  339. if (ret)
  340. return ret;
  341. /* TODO: calculate good shift from rate and counter bit width */
  342. cs->shift = 0;
  343. cs->mult = clocksource_hz2mult(p->rate, cs->shift);
  344. return 0;
  345. }
  346. static void sh_cmt_clocksource_disable(struct clocksource *cs)
  347. {
  348. sh_cmt_stop(cs_to_sh_cmt(cs), FLAG_CLOCKSOURCE);
  349. }
  350. static int sh_cmt_register_clocksource(struct sh_cmt_priv *p,
  351. char *name, unsigned long rating)
  352. {
  353. struct clocksource *cs = &p->cs;
  354. cs->name = name;
  355. cs->rating = rating;
  356. cs->read = sh_cmt_clocksource_read;
  357. cs->enable = sh_cmt_clocksource_enable;
  358. cs->disable = sh_cmt_clocksource_disable;
  359. cs->mask = CLOCKSOURCE_MASK(sizeof(unsigned long) * 8);
  360. cs->flags = CLOCK_SOURCE_IS_CONTINUOUS;
  361. pr_info("sh_cmt: %s used as clock source\n", cs->name);
  362. clocksource_register(cs);
  363. return 0;
  364. }
  365. static struct sh_cmt_priv *ced_to_sh_cmt(struct clock_event_device *ced)
  366. {
  367. return container_of(ced, struct sh_cmt_priv, ced);
  368. }
  369. static void sh_cmt_clock_event_start(struct sh_cmt_priv *p, int periodic)
  370. {
  371. struct clock_event_device *ced = &p->ced;
  372. sh_cmt_start(p, FLAG_CLOCKEVENT);
  373. /* TODO: calculate good shift from rate and counter bit width */
  374. ced->shift = 32;
  375. ced->mult = div_sc(p->rate, NSEC_PER_SEC, ced->shift);
  376. ced->max_delta_ns = clockevent_delta2ns(p->max_match_value, ced);
  377. ced->min_delta_ns = clockevent_delta2ns(0x1f, ced);
  378. if (periodic)
  379. sh_cmt_set_next(p, (p->rate + HZ/2) / HZ);
  380. else
  381. sh_cmt_set_next(p, p->max_match_value);
  382. }
  383. static void sh_cmt_clock_event_mode(enum clock_event_mode mode,
  384. struct clock_event_device *ced)
  385. {
  386. struct sh_cmt_priv *p = ced_to_sh_cmt(ced);
  387. /* deal with old setting first */
  388. switch (ced->mode) {
  389. case CLOCK_EVT_MODE_PERIODIC:
  390. case CLOCK_EVT_MODE_ONESHOT:
  391. sh_cmt_stop(p, FLAG_CLOCKEVENT);
  392. break;
  393. default:
  394. break;
  395. }
  396. switch (mode) {
  397. case CLOCK_EVT_MODE_PERIODIC:
  398. pr_info("sh_cmt: %s used for periodic clock events\n",
  399. ced->name);
  400. sh_cmt_clock_event_start(p, 1);
  401. break;
  402. case CLOCK_EVT_MODE_ONESHOT:
  403. pr_info("sh_cmt: %s used for oneshot clock events\n",
  404. ced->name);
  405. sh_cmt_clock_event_start(p, 0);
  406. break;
  407. case CLOCK_EVT_MODE_SHUTDOWN:
  408. case CLOCK_EVT_MODE_UNUSED:
  409. sh_cmt_stop(p, FLAG_CLOCKEVENT);
  410. break;
  411. default:
  412. break;
  413. }
  414. }
  415. static int sh_cmt_clock_event_next(unsigned long delta,
  416. struct clock_event_device *ced)
  417. {
  418. struct sh_cmt_priv *p = ced_to_sh_cmt(ced);
  419. BUG_ON(ced->mode != CLOCK_EVT_MODE_ONESHOT);
  420. if (likely(p->flags & FLAG_IRQCONTEXT))
  421. p->next_match_value = delta;
  422. else
  423. sh_cmt_set_next(p, delta);
  424. return 0;
  425. }
  426. static void sh_cmt_register_clockevent(struct sh_cmt_priv *p,
  427. char *name, unsigned long rating)
  428. {
  429. struct clock_event_device *ced = &p->ced;
  430. memset(ced, 0, sizeof(*ced));
  431. ced->name = name;
  432. ced->features = CLOCK_EVT_FEAT_PERIODIC;
  433. ced->features |= CLOCK_EVT_FEAT_ONESHOT;
  434. ced->rating = rating;
  435. ced->cpumask = cpumask_of(0);
  436. ced->set_next_event = sh_cmt_clock_event_next;
  437. ced->set_mode = sh_cmt_clock_event_mode;
  438. pr_info("sh_cmt: %s used for clock events\n", ced->name);
  439. clockevents_register_device(ced);
  440. }
  441. static int sh_cmt_register(struct sh_cmt_priv *p, char *name,
  442. unsigned long clockevent_rating,
  443. unsigned long clocksource_rating)
  444. {
  445. if (p->width == (sizeof(p->max_match_value) * 8))
  446. p->max_match_value = ~0;
  447. else
  448. p->max_match_value = (1 << p->width) - 1;
  449. p->match_value = p->max_match_value;
  450. spin_lock_init(&p->lock);
  451. if (clockevent_rating)
  452. sh_cmt_register_clockevent(p, name, clockevent_rating);
  453. if (clocksource_rating)
  454. sh_cmt_register_clocksource(p, name, clocksource_rating);
  455. return 0;
  456. }
  457. static int sh_cmt_setup(struct sh_cmt_priv *p, struct platform_device *pdev)
  458. {
  459. struct sh_timer_config *cfg = pdev->dev.platform_data;
  460. struct resource *res;
  461. int irq, ret;
  462. ret = -ENXIO;
  463. memset(p, 0, sizeof(*p));
  464. p->pdev = pdev;
  465. if (!cfg) {
  466. dev_err(&p->pdev->dev, "missing platform data\n");
  467. goto err0;
  468. }
  469. platform_set_drvdata(pdev, p);
  470. res = platform_get_resource(p->pdev, IORESOURCE_MEM, 0);
  471. if (!res) {
  472. dev_err(&p->pdev->dev, "failed to get I/O memory\n");
  473. goto err0;
  474. }
  475. irq = platform_get_irq(p->pdev, 0);
  476. if (irq < 0) {
  477. dev_err(&p->pdev->dev, "failed to get irq\n");
  478. goto err0;
  479. }
  480. /* map memory, let mapbase point to our channel */
  481. p->mapbase = ioremap_nocache(res->start, resource_size(res));
  482. if (p->mapbase == NULL) {
  483. pr_err("sh_cmt: failed to remap I/O memory\n");
  484. goto err0;
  485. }
  486. /* request irq using setup_irq() (too early for request_irq()) */
  487. p->irqaction.name = cfg->name;
  488. p->irqaction.handler = sh_cmt_interrupt;
  489. p->irqaction.dev_id = p;
  490. p->irqaction.flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL;
  491. p->irqaction.mask = CPU_MASK_NONE;
  492. ret = setup_irq(irq, &p->irqaction);
  493. if (ret) {
  494. pr_err("sh_cmt: failed to request irq %d\n", irq);
  495. goto err1;
  496. }
  497. /* get hold of clock */
  498. p->clk = clk_get(&p->pdev->dev, cfg->clk);
  499. if (IS_ERR(p->clk)) {
  500. pr_err("sh_cmt: cannot get clock \"%s\"\n", cfg->clk);
  501. ret = PTR_ERR(p->clk);
  502. goto err2;
  503. }
  504. if (resource_size(res) == 6) {
  505. p->width = 16;
  506. p->overflow_bit = 0x80;
  507. p->clear_bits = ~0x80;
  508. } else {
  509. p->width = 32;
  510. p->overflow_bit = 0x8000;
  511. p->clear_bits = ~0xc000;
  512. }
  513. return sh_cmt_register(p, cfg->name,
  514. cfg->clockevent_rating,
  515. cfg->clocksource_rating);
  516. err2:
  517. remove_irq(irq, &p->irqaction);
  518. err1:
  519. iounmap(p->mapbase);
  520. err0:
  521. return ret;
  522. }
  523. static int __devinit sh_cmt_probe(struct platform_device *pdev)
  524. {
  525. struct sh_cmt_priv *p = platform_get_drvdata(pdev);
  526. struct sh_timer_config *cfg = pdev->dev.platform_data;
  527. int ret;
  528. if (p) {
  529. pr_info("sh_cmt: %s kept as earlytimer\n", cfg->name);
  530. return 0;
  531. }
  532. p = kmalloc(sizeof(*p), GFP_KERNEL);
  533. if (p == NULL) {
  534. dev_err(&pdev->dev, "failed to allocate driver data\n");
  535. return -ENOMEM;
  536. }
  537. ret = sh_cmt_setup(p, pdev);
  538. if (ret) {
  539. kfree(p);
  540. platform_set_drvdata(pdev, NULL);
  541. }
  542. return ret;
  543. }
  544. static int __devexit sh_cmt_remove(struct platform_device *pdev)
  545. {
  546. return -EBUSY; /* cannot unregister clockevent and clocksource */
  547. }
  548. static struct platform_driver sh_cmt_device_driver = {
  549. .probe = sh_cmt_probe,
  550. .remove = __devexit_p(sh_cmt_remove),
  551. .driver = {
  552. .name = "sh_cmt",
  553. }
  554. };
  555. static int __init sh_cmt_init(void)
  556. {
  557. return platform_driver_register(&sh_cmt_device_driver);
  558. }
  559. static void __exit sh_cmt_exit(void)
  560. {
  561. platform_driver_unregister(&sh_cmt_device_driver);
  562. }
  563. early_platform_init("earlytimer", &sh_cmt_device_driver);
  564. module_init(sh_cmt_init);
  565. module_exit(sh_cmt_exit);
  566. MODULE_AUTHOR("Magnus Damm");
  567. MODULE_DESCRIPTION("SuperH CMT Timer Driver");
  568. MODULE_LICENSE("GPL v2");