pxa3xx-gcu.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  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 (gc_readl(priv, REG_GCRBEXHR) == rbexhr &&
  263. priv->shared->num_interrupts == num) {
  264. QERROR("TIMEOUT");
  265. ret = -ETIMEDOUT;
  266. break;
  267. }
  268. }
  269. QDUMP("done");
  270. return ret;
  271. }
  272. static int
  273. pxa3xx_gcu_wait_free(struct pxa3xx_gcu_priv *priv)
  274. {
  275. int ret = 0;
  276. QDUMP("Waiting for free...");
  277. /* Does not need to be atomic. There's a lock in user space,
  278. * but anyhow, this is just for statistics. */
  279. priv->shared->num_wait_free++;
  280. while (!priv->free) {
  281. u32 rbexhr = gc_readl(priv, REG_GCRBEXHR);
  282. ret = wait_event_interruptible_timeout(priv->wait_free,
  283. priv->free, HZ*4);
  284. if (ret < 0)
  285. break;
  286. if (ret > 0)
  287. continue;
  288. if (gc_readl(priv, REG_GCRBEXHR) == rbexhr) {
  289. QERROR("TIMEOUT");
  290. ret = -ETIMEDOUT;
  291. break;
  292. }
  293. }
  294. QDUMP("done");
  295. return ret;
  296. }
  297. /* Misc device layer */
  298. static ssize_t
  299. pxa3xx_gcu_misc_write(struct file *filp, const char *buff,
  300. size_t count, loff_t *offp)
  301. {
  302. int ret;
  303. unsigned long flags;
  304. struct pxa3xx_gcu_batch *buffer;
  305. struct pxa3xx_gcu_priv *priv =
  306. container_of(filp->f_op, struct pxa3xx_gcu_priv, misc_fops);
  307. int words = count / 4;
  308. /* Does not need to be atomic. There's a lock in user space,
  309. * but anyhow, this is just for statistics. */
  310. priv->shared->num_writes++;
  311. priv->shared->num_words += words;
  312. /* Last word reserved for batch buffer end command */
  313. if (words >= PXA3XX_GCU_BATCH_WORDS)
  314. return -E2BIG;
  315. /* Wait for a free buffer */
  316. if (!priv->free) {
  317. ret = pxa3xx_gcu_wait_free(priv);
  318. if (ret < 0)
  319. return ret;
  320. }
  321. /*
  322. * Get buffer from free list
  323. */
  324. spin_lock_irqsave(&priv->spinlock, flags);
  325. buffer = priv->free;
  326. priv->free = buffer->next;
  327. spin_unlock_irqrestore(&priv->spinlock, flags);
  328. /* Copy data from user into buffer */
  329. ret = copy_from_user(buffer->ptr, buff, words * 4);
  330. if (ret) {
  331. spin_lock_irqsave(&priv->spinlock, flags);
  332. buffer->next = priv->free;
  333. priv->free = buffer;
  334. spin_unlock_irqrestore(&priv->spinlock, flags);
  335. return -EFAULT;
  336. }
  337. buffer->length = words;
  338. /* Append batch buffer end command */
  339. buffer->ptr[words] = 0x01000000;
  340. /*
  341. * Add buffer to ready list
  342. */
  343. spin_lock_irqsave(&priv->spinlock, flags);
  344. buffer->next = NULL;
  345. if (priv->ready) {
  346. BUG_ON(priv->ready_last == NULL);
  347. priv->ready_last->next = buffer;
  348. } else
  349. priv->ready = buffer;
  350. priv->ready_last = buffer;
  351. if (!priv->shared->hw_running)
  352. run_ready(priv);
  353. spin_unlock_irqrestore(&priv->spinlock, flags);
  354. return words * 4;
  355. }
  356. static long
  357. pxa3xx_gcu_misc_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  358. {
  359. unsigned long flags;
  360. struct pxa3xx_gcu_priv *priv =
  361. container_of(filp->f_op, struct pxa3xx_gcu_priv, misc_fops);
  362. switch (cmd) {
  363. case PXA3XX_GCU_IOCTL_RESET:
  364. spin_lock_irqsave(&priv->spinlock, flags);
  365. pxa3xx_gcu_reset(priv);
  366. spin_unlock_irqrestore(&priv->spinlock, flags);
  367. return 0;
  368. case PXA3XX_GCU_IOCTL_WAIT_IDLE:
  369. return pxa3xx_gcu_wait_idle(priv);
  370. }
  371. return -ENOSYS;
  372. }
  373. static int
  374. pxa3xx_gcu_misc_mmap(struct file *filp, struct vm_area_struct *vma)
  375. {
  376. unsigned int size = vma->vm_end - vma->vm_start;
  377. struct pxa3xx_gcu_priv *priv =
  378. container_of(filp->f_op, struct pxa3xx_gcu_priv, misc_fops);
  379. switch (vma->vm_pgoff) {
  380. case 0:
  381. /* hand out the shared data area */
  382. if (size != SHARED_SIZE)
  383. return -EINVAL;
  384. return dma_mmap_coherent(NULL, vma,
  385. priv->shared, priv->shared_phys, size);
  386. case SHARED_SIZE >> PAGE_SHIFT:
  387. /* hand out the MMIO base for direct register access
  388. * from userspace */
  389. if (size != resource_size(priv->resource_mem))
  390. return -EINVAL;
  391. vma->vm_flags |= VM_IO;
  392. vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  393. return io_remap_pfn_range(vma, vma->vm_start,
  394. priv->resource_mem->start >> PAGE_SHIFT,
  395. size, vma->vm_page_prot);
  396. }
  397. return -EINVAL;
  398. }
  399. #ifdef PXA3XX_GCU_DEBUG_TIMER
  400. static struct timer_list pxa3xx_gcu_debug_timer;
  401. static void pxa3xx_gcu_debug_timedout(unsigned long ptr)
  402. {
  403. struct pxa3xx_gcu_priv *priv = (struct pxa3xx_gcu_priv *) ptr;
  404. QERROR("Timer DUMP");
  405. /* init the timer structure */
  406. init_timer(&pxa3xx_gcu_debug_timer);
  407. pxa3xx_gcu_debug_timer.function = pxa3xx_gcu_debug_timedout;
  408. pxa3xx_gcu_debug_timer.data = ptr;
  409. pxa3xx_gcu_debug_timer.expires = jiffies + 5*HZ; /* one second */
  410. add_timer(&pxa3xx_gcu_debug_timer);
  411. }
  412. static void pxa3xx_gcu_init_debug_timer(void)
  413. {
  414. pxa3xx_gcu_debug_timedout((unsigned long) &pxa3xx_gcu_debug_timer);
  415. }
  416. #else
  417. static inline void pxa3xx_gcu_init_debug_timer(void) {}
  418. #endif
  419. static int
  420. add_buffer(struct platform_device *dev,
  421. struct pxa3xx_gcu_priv *priv)
  422. {
  423. struct pxa3xx_gcu_batch *buffer;
  424. buffer = kzalloc(sizeof(struct pxa3xx_gcu_batch), GFP_KERNEL);
  425. if (!buffer)
  426. return -ENOMEM;
  427. buffer->ptr = dma_alloc_coherent(&dev->dev, PXA3XX_GCU_BATCH_WORDS * 4,
  428. &buffer->phys, GFP_KERNEL);
  429. if (!buffer->ptr) {
  430. kfree(buffer);
  431. return -ENOMEM;
  432. }
  433. buffer->next = priv->free;
  434. priv->free = buffer;
  435. return 0;
  436. }
  437. static void
  438. free_buffers(struct platform_device *dev,
  439. struct pxa3xx_gcu_priv *priv)
  440. {
  441. struct pxa3xx_gcu_batch *next, *buffer = priv->free;
  442. while (buffer) {
  443. next = buffer->next;
  444. dma_free_coherent(&dev->dev, PXA3XX_GCU_BATCH_WORDS * 4,
  445. buffer->ptr, buffer->phys);
  446. kfree(buffer);
  447. buffer = next;
  448. }
  449. priv->free = NULL;
  450. }
  451. static int pxa3xx_gcu_probe(struct platform_device *dev)
  452. {
  453. int i, ret, irq;
  454. struct resource *r;
  455. struct pxa3xx_gcu_priv *priv;
  456. priv = kzalloc(sizeof(struct pxa3xx_gcu_priv), GFP_KERNEL);
  457. if (!priv)
  458. return -ENOMEM;
  459. for (i = 0; i < 8; i++) {
  460. ret = add_buffer(dev, priv);
  461. if (ret) {
  462. dev_err(&dev->dev, "failed to allocate DMA memory\n");
  463. goto err_free_priv;
  464. }
  465. }
  466. init_waitqueue_head(&priv->wait_idle);
  467. init_waitqueue_head(&priv->wait_free);
  468. spin_lock_init(&priv->spinlock);
  469. /* we allocate the misc device structure as part of our own allocation,
  470. * so we can get a pointer to our priv structure later on with
  471. * container_of(). This isn't really necessary as we have a fixed minor
  472. * number anyway, but this is to avoid statics. */
  473. priv->misc_fops.owner = THIS_MODULE;
  474. priv->misc_fops.write = pxa3xx_gcu_misc_write;
  475. priv->misc_fops.unlocked_ioctl = pxa3xx_gcu_misc_ioctl;
  476. priv->misc_fops.mmap = pxa3xx_gcu_misc_mmap;
  477. priv->misc_dev.minor = MISCDEV_MINOR,
  478. priv->misc_dev.name = DRV_NAME,
  479. priv->misc_dev.fops = &priv->misc_fops,
  480. /* register misc device */
  481. ret = misc_register(&priv->misc_dev);
  482. if (ret < 0) {
  483. dev_err(&dev->dev, "misc_register() for minor %d failed\n",
  484. MISCDEV_MINOR);
  485. goto err_free_priv;
  486. }
  487. /* handle IO resources */
  488. r = platform_get_resource(dev, IORESOURCE_MEM, 0);
  489. if (r == NULL) {
  490. dev_err(&dev->dev, "no I/O memory resource defined\n");
  491. ret = -ENODEV;
  492. goto err_misc_deregister;
  493. }
  494. if (!request_mem_region(r->start, resource_size(r), dev->name)) {
  495. dev_err(&dev->dev, "failed to request I/O memory\n");
  496. ret = -EBUSY;
  497. goto err_misc_deregister;
  498. }
  499. priv->mmio_base = ioremap_nocache(r->start, resource_size(r));
  500. if (!priv->mmio_base) {
  501. dev_err(&dev->dev, "failed to map I/O memory\n");
  502. ret = -EBUSY;
  503. goto err_free_mem_region;
  504. }
  505. /* allocate dma memory */
  506. priv->shared = dma_alloc_coherent(&dev->dev, SHARED_SIZE,
  507. &priv->shared_phys, GFP_KERNEL);
  508. if (!priv->shared) {
  509. dev_err(&dev->dev, "failed to allocate DMA memory\n");
  510. ret = -ENOMEM;
  511. goto err_free_io;
  512. }
  513. /* enable the clock */
  514. priv->clk = clk_get(&dev->dev, NULL);
  515. if (IS_ERR(priv->clk)) {
  516. dev_err(&dev->dev, "failed to get clock\n");
  517. ret = -ENODEV;
  518. goto err_free_dma;
  519. }
  520. ret = clk_enable(priv->clk);
  521. if (ret < 0) {
  522. dev_err(&dev->dev, "failed to enable clock\n");
  523. goto err_put_clk;
  524. }
  525. /* request the IRQ */
  526. irq = platform_get_irq(dev, 0);
  527. if (irq < 0) {
  528. dev_err(&dev->dev, "no IRQ defined\n");
  529. ret = -ENODEV;
  530. goto err_put_clk;
  531. }
  532. ret = request_irq(irq, pxa3xx_gcu_handle_irq,
  533. 0, DRV_NAME, priv);
  534. if (ret) {
  535. dev_err(&dev->dev, "request_irq failed\n");
  536. ret = -EBUSY;
  537. goto err_put_clk;
  538. }
  539. platform_set_drvdata(dev, priv);
  540. priv->resource_mem = r;
  541. pxa3xx_gcu_reset(priv);
  542. pxa3xx_gcu_init_debug_timer();
  543. dev_info(&dev->dev, "registered @0x%p, DMA 0x%p (%d bytes), IRQ %d\n",
  544. (void *) r->start, (void *) priv->shared_phys,
  545. SHARED_SIZE, irq);
  546. return 0;
  547. err_put_clk:
  548. clk_disable(priv->clk);
  549. clk_put(priv->clk);
  550. err_free_dma:
  551. dma_free_coherent(&dev->dev, SHARED_SIZE,
  552. priv->shared, priv->shared_phys);
  553. err_free_io:
  554. iounmap(priv->mmio_base);
  555. err_free_mem_region:
  556. release_mem_region(r->start, resource_size(r));
  557. err_misc_deregister:
  558. misc_deregister(&priv->misc_dev);
  559. err_free_priv:
  560. platform_set_drvdata(dev, NULL);
  561. free_buffers(dev, priv);
  562. kfree(priv);
  563. return ret;
  564. }
  565. static int pxa3xx_gcu_remove(struct platform_device *dev)
  566. {
  567. struct pxa3xx_gcu_priv *priv = platform_get_drvdata(dev);
  568. struct resource *r = priv->resource_mem;
  569. pxa3xx_gcu_wait_idle(priv);
  570. misc_deregister(&priv->misc_dev);
  571. dma_free_coherent(&dev->dev, SHARED_SIZE,
  572. priv->shared, priv->shared_phys);
  573. iounmap(priv->mmio_base);
  574. release_mem_region(r->start, resource_size(r));
  575. platform_set_drvdata(dev, NULL);
  576. clk_disable(priv->clk);
  577. free_buffers(dev, priv);
  578. kfree(priv);
  579. return 0;
  580. }
  581. static struct platform_driver pxa3xx_gcu_driver = {
  582. .probe = pxa3xx_gcu_probe,
  583. .remove = pxa3xx_gcu_remove,
  584. .driver = {
  585. .owner = THIS_MODULE,
  586. .name = DRV_NAME,
  587. },
  588. };
  589. module_platform_driver(pxa3xx_gcu_driver);
  590. MODULE_DESCRIPTION("PXA3xx graphics controller unit driver");
  591. MODULE_LICENSE("GPL");
  592. MODULE_ALIAS_MISCDEV(MISCDEV_MINOR);
  593. MODULE_AUTHOR("Janine Kropp <nin@directfb.org>, "
  594. "Denis Oliver Kropp <dok@directfb.org>, "
  595. "Daniel Mack <daniel@caiaq.de>");