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