pxa3xx-gcu.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. /*
  2. * pxa3xx-gcu.c - Linux kernel module for PXA3xx graphics controllers
  3. *
  4. * This driver needs a DirectFB counterpart in user space, communication
  5. * is handled via mmap()ed memory areas and an ioctl.
  6. *
  7. * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de>
  8. * Copyright (c) 2009 Janine Kropp <nin@directfb.org>
  9. * Copyright (c) 2009 Denis Oliver Kropp <dok@directfb.org>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. */
  25. /*
  26. * WARNING: This controller is attached to System Bus 2 of the PXA which
  27. * needs its arbiter to be enabled explicitly (CKENB & 1<<9).
  28. * There is currently no way to do this from Linux, so you need to teach
  29. * your bootloader for now.
  30. */
  31. #include <linux/module.h>
  32. #include <linux/platform_device.h>
  33. #include <linux/dma-mapping.h>
  34. #include <linux/miscdevice.h>
  35. #include <linux/interrupt.h>
  36. #include <linux/spinlock.h>
  37. #include <linux/uaccess.h>
  38. #include <linux/ioctl.h>
  39. #include <linux/delay.h>
  40. #include <linux/sched.h>
  41. #include <linux/slab.h>
  42. #include <linux/clk.h>
  43. #include <linux/fs.h>
  44. #include <linux/io.h>
  45. #include "pxa3xx-gcu.h"
  46. #define DRV_NAME "pxa3xx-gcu"
  47. #define MISCDEV_MINOR 197
  48. #define REG_GCCR 0x00
  49. #define GCCR_SYNC_CLR (1 << 9)
  50. #define GCCR_BP_RST (1 << 8)
  51. #define GCCR_ABORT (1 << 6)
  52. #define GCCR_STOP (1 << 4)
  53. #define REG_GCISCR 0x04
  54. #define REG_GCIECR 0x08
  55. #define REG_GCRBBR 0x20
  56. #define REG_GCRBLR 0x24
  57. #define REG_GCRBHR 0x28
  58. #define REG_GCRBTR 0x2C
  59. #define REG_GCRBEXHR 0x30
  60. #define IE_EOB (1 << 0)
  61. #define IE_EEOB (1 << 5)
  62. #define IE_ALL 0xff
  63. #define SHARED_SIZE PAGE_ALIGN(sizeof(struct pxa3xx_gcu_shared))
  64. /* #define PXA3XX_GCU_DEBUG */
  65. /* #define PXA3XX_GCU_DEBUG_TIMER */
  66. #ifdef PXA3XX_GCU_DEBUG
  67. #define QDUMP(msg) \
  68. do { \
  69. QPRINT(priv, KERN_DEBUG, msg); \
  70. } while (0)
  71. #else
  72. #define QDUMP(msg) do {} while (0)
  73. #endif
  74. #define QERROR(msg) \
  75. do { \
  76. QPRINT(priv, KERN_ERR, msg); \
  77. } while (0)
  78. struct pxa3xx_gcu_batch {
  79. struct pxa3xx_gcu_batch *next;
  80. u32 *ptr;
  81. dma_addr_t phys;
  82. unsigned long length;
  83. };
  84. struct pxa3xx_gcu_priv {
  85. void __iomem *mmio_base;
  86. struct clk *clk;
  87. struct pxa3xx_gcu_shared *shared;
  88. dma_addr_t shared_phys;
  89. struct resource *resource_mem;
  90. struct miscdevice misc_dev;
  91. struct file_operations misc_fops;
  92. wait_queue_head_t wait_idle;
  93. wait_queue_head_t wait_free;
  94. spinlock_t spinlock;
  95. struct timeval base_time;
  96. struct pxa3xx_gcu_batch *free;
  97. struct pxa3xx_gcu_batch *ready;
  98. struct pxa3xx_gcu_batch *ready_last;
  99. struct pxa3xx_gcu_batch *running;
  100. };
  101. static inline unsigned long
  102. gc_readl(struct pxa3xx_gcu_priv *priv, unsigned int off)
  103. {
  104. return __raw_readl(priv->mmio_base + off);
  105. }
  106. static inline void
  107. gc_writel(struct pxa3xx_gcu_priv *priv, unsigned int off, unsigned long val)
  108. {
  109. __raw_writel(val, priv->mmio_base + off);
  110. }
  111. #define QPRINT(priv, level, msg) \
  112. do { \
  113. struct timeval tv; \
  114. struct pxa3xx_gcu_shared *shared = priv->shared; \
  115. u32 base = gc_readl(priv, REG_GCRBBR); \
  116. \
  117. do_gettimeofday(&tv); \
  118. \
  119. printk(level "%ld.%03ld.%03ld - %-17s: %-21s (%s, " \
  120. "STATUS " \
  121. "0x%02lx, B 0x%08lx [%ld], E %5ld, H %5ld, " \
  122. "T %5ld)\n", \
  123. tv.tv_sec - priv->base_time.tv_sec, \
  124. tv.tv_usec / 1000, tv.tv_usec % 1000, \
  125. __func__, msg, \
  126. shared->hw_running ? "running" : " idle", \
  127. gc_readl(priv, REG_GCISCR), \
  128. gc_readl(priv, REG_GCRBBR), \
  129. gc_readl(priv, REG_GCRBLR), \
  130. (gc_readl(priv, REG_GCRBEXHR) - base) / 4, \
  131. (gc_readl(priv, REG_GCRBHR) - base) / 4, \
  132. (gc_readl(priv, REG_GCRBTR) - base) / 4); \
  133. } while (0)
  134. static void
  135. pxa3xx_gcu_reset(struct pxa3xx_gcu_priv *priv)
  136. {
  137. QDUMP("RESET");
  138. /* disable interrupts */
  139. gc_writel(priv, REG_GCIECR, 0);
  140. /* reset hardware */
  141. gc_writel(priv, REG_GCCR, GCCR_ABORT);
  142. gc_writel(priv, REG_GCCR, 0);
  143. memset(priv->shared, 0, SHARED_SIZE);
  144. priv->shared->buffer_phys = priv->shared_phys;
  145. priv->shared->magic = PXA3XX_GCU_SHARED_MAGIC;
  146. do_gettimeofday(&priv->base_time);
  147. /* set up the ring buffer pointers */
  148. gc_writel(priv, REG_GCRBLR, 0);
  149. gc_writel(priv, REG_GCRBBR, priv->shared_phys);
  150. gc_writel(priv, REG_GCRBTR, priv->shared_phys);
  151. /* enable all IRQs except EOB */
  152. gc_writel(priv, REG_GCIECR, IE_ALL & ~IE_EOB);
  153. }
  154. static void
  155. dump_whole_state(struct pxa3xx_gcu_priv *priv)
  156. {
  157. struct pxa3xx_gcu_shared *sh = priv->shared;
  158. u32 base = gc_readl(priv, REG_GCRBBR);
  159. QDUMP("DUMP");
  160. printk(KERN_DEBUG "== PXA3XX-GCU DUMP ==\n"
  161. "%s, STATUS 0x%02lx, B 0x%08lx [%ld], E %5ld, H %5ld, T %5ld\n",
  162. sh->hw_running ? "running" : "idle ",
  163. gc_readl(priv, REG_GCISCR),
  164. gc_readl(priv, REG_GCRBBR),
  165. gc_readl(priv, REG_GCRBLR),
  166. (gc_readl(priv, REG_GCRBEXHR) - base) / 4,
  167. (gc_readl(priv, REG_GCRBHR) - base) / 4,
  168. (gc_readl(priv, REG_GCRBTR) - base) / 4);
  169. }
  170. static void
  171. flush_running(struct pxa3xx_gcu_priv *priv)
  172. {
  173. struct pxa3xx_gcu_batch *running = priv->running;
  174. struct pxa3xx_gcu_batch *next;
  175. while (running) {
  176. next = running->next;
  177. running->next = priv->free;
  178. priv->free = running;
  179. running = next;
  180. }
  181. priv->running = NULL;
  182. }
  183. static void
  184. run_ready(struct pxa3xx_gcu_priv *priv)
  185. {
  186. unsigned int num = 0;
  187. struct pxa3xx_gcu_shared *shared = priv->shared;
  188. struct pxa3xx_gcu_batch *ready = priv->ready;
  189. QDUMP("Start");
  190. BUG_ON(!ready);
  191. shared->buffer[num++] = 0x05000000;
  192. while (ready) {
  193. shared->buffer[num++] = 0x00000001;
  194. shared->buffer[num++] = ready->phys;
  195. ready = ready->next;
  196. }
  197. shared->buffer[num++] = 0x05000000;
  198. priv->running = priv->ready;
  199. priv->ready = priv->ready_last = NULL;
  200. gc_writel(priv, REG_GCRBLR, 0);
  201. shared->hw_running = 1;
  202. /* ring base address */
  203. gc_writel(priv, REG_GCRBBR, shared->buffer_phys);
  204. /* ring tail address */
  205. gc_writel(priv, REG_GCRBTR, shared->buffer_phys + num * 4);
  206. /* ring length */
  207. gc_writel(priv, REG_GCRBLR, ((num + 63) & ~63) * 4);
  208. }
  209. static irqreturn_t
  210. pxa3xx_gcu_handle_irq(int irq, void *ctx)
  211. {
  212. struct pxa3xx_gcu_priv *priv = ctx;
  213. struct pxa3xx_gcu_shared *shared = priv->shared;
  214. u32 status = gc_readl(priv, REG_GCISCR) & IE_ALL;
  215. QDUMP("-Interrupt");
  216. if (!status)
  217. return IRQ_NONE;
  218. spin_lock(&priv->spinlock);
  219. shared->num_interrupts++;
  220. if (status & IE_EEOB) {
  221. QDUMP(" [EEOB]");
  222. flush_running(priv);
  223. wake_up_all(&priv->wait_free);
  224. if (priv->ready) {
  225. run_ready(priv);
  226. } else {
  227. /* There is no more data prepared by the userspace.
  228. * Set hw_running = 0 and wait for the next userspace
  229. * kick-off */
  230. shared->num_idle++;
  231. shared->hw_running = 0;
  232. QDUMP(" '-> Idle.");
  233. /* set ring buffer length to zero */
  234. gc_writel(priv, REG_GCRBLR, 0);
  235. wake_up_all(&priv->wait_idle);
  236. }
  237. shared->num_done++;
  238. } else {
  239. QERROR(" [???]");
  240. dump_whole_state(priv);
  241. }
  242. /* Clear the interrupt */
  243. gc_writel(priv, REG_GCISCR, status);
  244. spin_unlock(&priv->spinlock);
  245. return IRQ_HANDLED;
  246. }
  247. static int
  248. pxa3xx_gcu_wait_idle(struct pxa3xx_gcu_priv *priv)
  249. {
  250. int ret = 0;
  251. QDUMP("Waiting for idle...");
  252. /* Does not need to be atomic. There's a lock in user space,
  253. * but anyhow, this is just for statistics. */
  254. priv->shared->num_wait_idle++;
  255. while (priv->shared->hw_running) {
  256. int num = priv->shared->num_interrupts;
  257. u32 rbexhr = gc_readl(priv, REG_GCRBEXHR);
  258. ret = wait_event_interruptible_timeout(priv->wait_idle,
  259. !priv->shared->hw_running, HZ*4);
  260. if (ret < 0)
  261. break;
  262. if (ret > 0)
  263. continue;
  264. if (gc_readl(priv, REG_GCRBEXHR) == rbexhr &&
  265. priv->shared->num_interrupts == num) {
  266. QERROR("TIMEOUT");
  267. ret = -ETIMEDOUT;
  268. break;
  269. }
  270. }
  271. QDUMP("done");
  272. return ret;
  273. }
  274. static int
  275. pxa3xx_gcu_wait_free(struct pxa3xx_gcu_priv *priv)
  276. {
  277. int ret = 0;
  278. QDUMP("Waiting for free...");
  279. /* Does not need to be atomic. There's a lock in user space,
  280. * but anyhow, this is just for statistics. */
  281. priv->shared->num_wait_free++;
  282. while (!priv->free) {
  283. u32 rbexhr = gc_readl(priv, REG_GCRBEXHR);
  284. ret = wait_event_interruptible_timeout(priv->wait_free,
  285. priv->free, HZ*4);
  286. if (ret < 0)
  287. break;
  288. if (ret > 0)
  289. continue;
  290. if (gc_readl(priv, REG_GCRBEXHR) == rbexhr) {
  291. QERROR("TIMEOUT");
  292. ret = -ETIMEDOUT;
  293. break;
  294. }
  295. }
  296. QDUMP("done");
  297. return ret;
  298. }
  299. /* Misc device layer */
  300. static ssize_t
  301. pxa3xx_gcu_misc_write(struct file *filp, const char *buff,
  302. size_t count, loff_t *offp)
  303. {
  304. int ret;
  305. unsigned long flags;
  306. struct pxa3xx_gcu_batch *buffer;
  307. struct pxa3xx_gcu_priv *priv =
  308. container_of(filp->f_op, struct pxa3xx_gcu_priv, misc_fops);
  309. int words = count / 4;
  310. /* Does not need to be atomic. There's a lock in user space,
  311. * but anyhow, this is just for statistics. */
  312. priv->shared->num_writes++;
  313. priv->shared->num_words += words;
  314. /* Last word reserved for batch buffer end command */
  315. if (words >= PXA3XX_GCU_BATCH_WORDS)
  316. return -E2BIG;
  317. /* Wait for a free buffer */
  318. if (!priv->free) {
  319. ret = pxa3xx_gcu_wait_free(priv);
  320. if (ret < 0)
  321. return ret;
  322. }
  323. /*
  324. * Get buffer from free list
  325. */
  326. spin_lock_irqsave(&priv->spinlock, flags);
  327. buffer = priv->free;
  328. priv->free = buffer->next;
  329. spin_unlock_irqrestore(&priv->spinlock, flags);
  330. /* Copy data from user into buffer */
  331. ret = copy_from_user(buffer->ptr, buff, words * 4);
  332. if (ret) {
  333. spin_lock_irqsave(&priv->spinlock, flags);
  334. buffer->next = priv->free;
  335. priv->free = buffer;
  336. spin_unlock_irqrestore(&priv->spinlock, flags);
  337. return -EFAULT;
  338. }
  339. buffer->length = words;
  340. /* Append batch buffer end command */
  341. buffer->ptr[words] = 0x01000000;
  342. /*
  343. * Add buffer to ready list
  344. */
  345. spin_lock_irqsave(&priv->spinlock, flags);
  346. buffer->next = NULL;
  347. if (priv->ready) {
  348. BUG_ON(priv->ready_last == NULL);
  349. priv->ready_last->next = buffer;
  350. } else
  351. priv->ready = buffer;
  352. priv->ready_last = buffer;
  353. if (!priv->shared->hw_running)
  354. run_ready(priv);
  355. spin_unlock_irqrestore(&priv->spinlock, flags);
  356. return words * 4;
  357. }
  358. static long
  359. pxa3xx_gcu_misc_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  360. {
  361. unsigned long flags;
  362. struct pxa3xx_gcu_priv *priv =
  363. container_of(filp->f_op, struct pxa3xx_gcu_priv, misc_fops);
  364. switch (cmd) {
  365. case PXA3XX_GCU_IOCTL_RESET:
  366. spin_lock_irqsave(&priv->spinlock, flags);
  367. pxa3xx_gcu_reset(priv);
  368. spin_unlock_irqrestore(&priv->spinlock, flags);
  369. return 0;
  370. case PXA3XX_GCU_IOCTL_WAIT_IDLE:
  371. return pxa3xx_gcu_wait_idle(priv);
  372. }
  373. return -ENOSYS;
  374. }
  375. static int
  376. pxa3xx_gcu_misc_mmap(struct file *filp, struct vm_area_struct *vma)
  377. {
  378. unsigned int size = vma->vm_end - vma->vm_start;
  379. struct pxa3xx_gcu_priv *priv =
  380. container_of(filp->f_op, struct pxa3xx_gcu_priv, misc_fops);
  381. switch (vma->vm_pgoff) {
  382. case 0:
  383. /* hand out the shared data area */
  384. if (size != SHARED_SIZE)
  385. return -EINVAL;
  386. return dma_mmap_coherent(NULL, vma,
  387. priv->shared, priv->shared_phys, size);
  388. case SHARED_SIZE >> PAGE_SHIFT:
  389. /* hand out the MMIO base for direct register access
  390. * from userspace */
  391. if (size != resource_size(priv->resource_mem))
  392. return -EINVAL;
  393. vma->vm_flags |= VM_IO;
  394. vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  395. return io_remap_pfn_range(vma, vma->vm_start,
  396. priv->resource_mem->start >> PAGE_SHIFT,
  397. size, vma->vm_page_prot);
  398. }
  399. return -EINVAL;
  400. }
  401. #ifdef PXA3XX_GCU_DEBUG_TIMER
  402. static struct timer_list pxa3xx_gcu_debug_timer;
  403. static void pxa3xx_gcu_debug_timedout(unsigned long ptr)
  404. {
  405. struct pxa3xx_gcu_priv *priv = (struct pxa3xx_gcu_priv *) ptr;
  406. QERROR("Timer DUMP");
  407. /* init the timer structure */
  408. init_timer(&pxa3xx_gcu_debug_timer);
  409. pxa3xx_gcu_debug_timer.function = pxa3xx_gcu_debug_timedout;
  410. pxa3xx_gcu_debug_timer.data = ptr;
  411. pxa3xx_gcu_debug_timer.expires = jiffies + 5*HZ; /* one second */
  412. add_timer(&pxa3xx_gcu_debug_timer);
  413. }
  414. static void pxa3xx_gcu_init_debug_timer(void)
  415. {
  416. pxa3xx_gcu_debug_timedout((unsigned long) &pxa3xx_gcu_debug_timer);
  417. }
  418. #else
  419. static inline void pxa3xx_gcu_init_debug_timer(void) {}
  420. #endif
  421. static int
  422. add_buffer(struct platform_device *dev,
  423. struct pxa3xx_gcu_priv *priv)
  424. {
  425. struct pxa3xx_gcu_batch *buffer;
  426. buffer = kzalloc(sizeof(struct pxa3xx_gcu_batch), GFP_KERNEL);
  427. if (!buffer)
  428. return -ENOMEM;
  429. buffer->ptr = dma_alloc_coherent(&dev->dev, PXA3XX_GCU_BATCH_WORDS * 4,
  430. &buffer->phys, GFP_KERNEL);
  431. if (!buffer->ptr) {
  432. kfree(buffer);
  433. return -ENOMEM;
  434. }
  435. buffer->next = priv->free;
  436. priv->free = buffer;
  437. return 0;
  438. }
  439. static void
  440. free_buffers(struct platform_device *dev,
  441. struct pxa3xx_gcu_priv *priv)
  442. {
  443. struct pxa3xx_gcu_batch *next, *buffer = priv->free;
  444. while (buffer) {
  445. next = buffer->next;
  446. dma_free_coherent(&dev->dev, PXA3XX_GCU_BATCH_WORDS * 4,
  447. buffer->ptr, buffer->phys);
  448. kfree(buffer);
  449. buffer = next;
  450. }
  451. priv->free = NULL;
  452. }
  453. static int __devinit
  454. pxa3xx_gcu_probe(struct platform_device *dev)
  455. {
  456. int i, ret, irq;
  457. struct resource *r;
  458. struct pxa3xx_gcu_priv *priv;
  459. priv = kzalloc(sizeof(struct pxa3xx_gcu_priv), GFP_KERNEL);
  460. if (!priv)
  461. return -ENOMEM;
  462. for (i = 0; i < 8; i++) {
  463. ret = add_buffer(dev, priv);
  464. if (ret) {
  465. dev_err(&dev->dev, "failed to allocate DMA memory\n");
  466. goto err_free_priv;
  467. }
  468. }
  469. init_waitqueue_head(&priv->wait_idle);
  470. init_waitqueue_head(&priv->wait_free);
  471. spin_lock_init(&priv->spinlock);
  472. /* we allocate the misc device structure as part of our own allocation,
  473. * so we can get a pointer to our priv structure later on with
  474. * container_of(). This isn't really necessary as we have a fixed minor
  475. * number anyway, but this is to avoid statics. */
  476. priv->misc_fops.owner = THIS_MODULE;
  477. priv->misc_fops.write = pxa3xx_gcu_misc_write;
  478. priv->misc_fops.unlocked_ioctl = pxa3xx_gcu_misc_ioctl;
  479. priv->misc_fops.mmap = pxa3xx_gcu_misc_mmap;
  480. priv->misc_dev.minor = MISCDEV_MINOR,
  481. priv->misc_dev.name = DRV_NAME,
  482. priv->misc_dev.fops = &priv->misc_fops,
  483. /* register misc device */
  484. ret = misc_register(&priv->misc_dev);
  485. if (ret < 0) {
  486. dev_err(&dev->dev, "misc_register() for minor %d failed\n",
  487. MISCDEV_MINOR);
  488. goto err_free_priv;
  489. }
  490. /* handle IO resources */
  491. r = platform_get_resource(dev, IORESOURCE_MEM, 0);
  492. if (r == NULL) {
  493. dev_err(&dev->dev, "no I/O memory resource defined\n");
  494. ret = -ENODEV;
  495. goto err_misc_deregister;
  496. }
  497. if (!request_mem_region(r->start, resource_size(r), dev->name)) {
  498. dev_err(&dev->dev, "failed to request I/O memory\n");
  499. ret = -EBUSY;
  500. goto err_misc_deregister;
  501. }
  502. priv->mmio_base = ioremap_nocache(r->start, resource_size(r));
  503. if (!priv->mmio_base) {
  504. dev_err(&dev->dev, "failed to map I/O memory\n");
  505. ret = -EBUSY;
  506. goto err_free_mem_region;
  507. }
  508. /* allocate dma memory */
  509. priv->shared = dma_alloc_coherent(&dev->dev, SHARED_SIZE,
  510. &priv->shared_phys, GFP_KERNEL);
  511. if (!priv->shared) {
  512. dev_err(&dev->dev, "failed to allocate DMA memory\n");
  513. ret = -ENOMEM;
  514. goto err_free_io;
  515. }
  516. /* enable the clock */
  517. priv->clk = clk_get(&dev->dev, NULL);
  518. if (IS_ERR(priv->clk)) {
  519. dev_err(&dev->dev, "failed to get clock\n");
  520. ret = -ENODEV;
  521. goto err_free_dma;
  522. }
  523. ret = clk_enable(priv->clk);
  524. if (ret < 0) {
  525. dev_err(&dev->dev, "failed to enable clock\n");
  526. goto err_put_clk;
  527. }
  528. /* request the IRQ */
  529. irq = platform_get_irq(dev, 0);
  530. if (irq < 0) {
  531. dev_err(&dev->dev, "no IRQ defined\n");
  532. ret = -ENODEV;
  533. goto err_put_clk;
  534. }
  535. ret = request_irq(irq, pxa3xx_gcu_handle_irq,
  536. 0, DRV_NAME, priv);
  537. if (ret) {
  538. dev_err(&dev->dev, "request_irq failed\n");
  539. ret = -EBUSY;
  540. goto err_put_clk;
  541. }
  542. platform_set_drvdata(dev, priv);
  543. priv->resource_mem = r;
  544. pxa3xx_gcu_reset(priv);
  545. pxa3xx_gcu_init_debug_timer();
  546. dev_info(&dev->dev, "registered @0x%p, DMA 0x%p (%d bytes), IRQ %d\n",
  547. (void *) r->start, (void *) priv->shared_phys,
  548. SHARED_SIZE, irq);
  549. return 0;
  550. err_put_clk:
  551. clk_disable(priv->clk);
  552. clk_put(priv->clk);
  553. err_free_dma:
  554. dma_free_coherent(&dev->dev, SHARED_SIZE,
  555. priv->shared, priv->shared_phys);
  556. err_free_io:
  557. iounmap(priv->mmio_base);
  558. err_free_mem_region:
  559. release_mem_region(r->start, resource_size(r));
  560. err_misc_deregister:
  561. misc_deregister(&priv->misc_dev);
  562. err_free_priv:
  563. platform_set_drvdata(dev, NULL);
  564. free_buffers(dev, priv);
  565. kfree(priv);
  566. return ret;
  567. }
  568. static int __devexit
  569. pxa3xx_gcu_remove(struct platform_device *dev)
  570. {
  571. struct pxa3xx_gcu_priv *priv = platform_get_drvdata(dev);
  572. struct resource *r = priv->resource_mem;
  573. pxa3xx_gcu_wait_idle(priv);
  574. misc_deregister(&priv->misc_dev);
  575. dma_free_coherent(&dev->dev, SHARED_SIZE,
  576. priv->shared, priv->shared_phys);
  577. iounmap(priv->mmio_base);
  578. release_mem_region(r->start, resource_size(r));
  579. platform_set_drvdata(dev, NULL);
  580. clk_disable(priv->clk);
  581. free_buffers(dev, priv);
  582. kfree(priv);
  583. return 0;
  584. }
  585. static struct platform_driver pxa3xx_gcu_driver = {
  586. .probe = pxa3xx_gcu_probe,
  587. .remove = __devexit_p(pxa3xx_gcu_remove),
  588. .driver = {
  589. .owner = THIS_MODULE,
  590. .name = DRV_NAME,
  591. },
  592. };
  593. module_platform_driver(pxa3xx_gcu_driver);
  594. MODULE_DESCRIPTION("PXA3xx graphics controller unit driver");
  595. MODULE_LICENSE("GPL");
  596. MODULE_ALIAS_MISCDEV(MISCDEV_MINOR);
  597. MODULE_AUTHOR("Janine Kropp <nin@directfb.org>, "
  598. "Denis Oliver Kropp <dok@directfb.org>, "
  599. "Daniel Mack <daniel@caiaq.de>");