sh_cmt.c 16 KB

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