pxa3xx-gcu.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  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. wait_queue_head_t wait_idle;
  92. wait_queue_head_t wait_free;
  93. spinlock_t spinlock;
  94. struct timeval base_time;
  95. struct pxa3xx_gcu_batch *free;
  96. struct pxa3xx_gcu_batch *ready;
  97. struct pxa3xx_gcu_batch *ready_last;
  98. struct pxa3xx_gcu_batch *running;
  99. };
  100. static inline unsigned long
  101. gc_readl(struct pxa3xx_gcu_priv *priv, unsigned int off)
  102. {
  103. return __raw_readl(priv->mmio_base + off);
  104. }
  105. static inline void
  106. gc_writel(struct pxa3xx_gcu_priv *priv, unsigned int off, unsigned long val)
  107. {
  108. __raw_writel(val, priv->mmio_base + off);
  109. }
  110. #define QPRINT(priv, level, msg) \
  111. do { \
  112. struct timeval tv; \
  113. struct pxa3xx_gcu_shared *shared = priv->shared; \
  114. u32 base = gc_readl(priv, REG_GCRBBR); \
  115. \
  116. do_gettimeofday(&tv); \
  117. \
  118. printk(level "%ld.%03ld.%03ld - %-17s: %-21s (%s, " \
  119. "STATUS " \
  120. "0x%02lx, B 0x%08lx [%ld], E %5ld, H %5ld, " \
  121. "T %5ld)\n", \
  122. tv.tv_sec - priv->base_time.tv_sec, \
  123. tv.tv_usec / 1000, tv.tv_usec % 1000, \
  124. __func__, msg, \
  125. shared->hw_running ? "running" : " idle", \
  126. gc_readl(priv, REG_GCISCR), \
  127. gc_readl(priv, REG_GCRBBR), \
  128. gc_readl(priv, REG_GCRBLR), \
  129. (gc_readl(priv, REG_GCRBEXHR) - base) / 4, \
  130. (gc_readl(priv, REG_GCRBHR) - base) / 4, \
  131. (gc_readl(priv, REG_GCRBTR) - base) / 4); \
  132. } while (0)
  133. static void
  134. pxa3xx_gcu_reset(struct pxa3xx_gcu_priv *priv)
  135. {
  136. QDUMP("RESET");
  137. /* disable interrupts */
  138. gc_writel(priv, REG_GCIECR, 0);
  139. /* reset hardware */
  140. gc_writel(priv, REG_GCCR, GCCR_ABORT);
  141. gc_writel(priv, REG_GCCR, 0);
  142. memset(priv->shared, 0, SHARED_SIZE);
  143. priv->shared->buffer_phys = priv->shared_phys;
  144. priv->shared->magic = PXA3XX_GCU_SHARED_MAGIC;
  145. do_gettimeofday(&priv->base_time);
  146. /* set up the ring buffer pointers */
  147. gc_writel(priv, REG_GCRBLR, 0);
  148. gc_writel(priv, REG_GCRBBR, priv->shared_phys);
  149. gc_writel(priv, REG_GCRBTR, priv->shared_phys);
  150. /* enable all IRQs except EOB */
  151. gc_writel(priv, REG_GCIECR, IE_ALL & ~IE_EOB);
  152. }
  153. static void
  154. dump_whole_state(struct pxa3xx_gcu_priv *priv)
  155. {
  156. struct pxa3xx_gcu_shared *sh = priv->shared;
  157. u32 base = gc_readl(priv, REG_GCRBBR);
  158. QDUMP("DUMP");
  159. printk(KERN_DEBUG "== PXA3XX-GCU DUMP ==\n"
  160. "%s, STATUS 0x%02lx, B 0x%08lx [%ld], E %5ld, H %5ld, T %5ld\n",
  161. sh->hw_running ? "running" : "idle ",
  162. gc_readl(priv, REG_GCISCR),
  163. gc_readl(priv, REG_GCRBBR),
  164. gc_readl(priv, REG_GCRBLR),
  165. (gc_readl(priv, REG_GCRBEXHR) - base) / 4,
  166. (gc_readl(priv, REG_GCRBHR) - base) / 4,
  167. (gc_readl(priv, REG_GCRBTR) - base) / 4);
  168. }
  169. static void
  170. flush_running(struct pxa3xx_gcu_priv *priv)
  171. {
  172. struct pxa3xx_gcu_batch *running = priv->running;
  173. struct pxa3xx_gcu_batch *next;
  174. while (running) {
  175. next = running->next;
  176. running->next = priv->free;
  177. priv->free = running;
  178. running = next;
  179. }
  180. priv->running = NULL;
  181. }
  182. static void
  183. run_ready(struct pxa3xx_gcu_priv *priv)
  184. {
  185. unsigned int num = 0;
  186. struct pxa3xx_gcu_shared *shared = priv->shared;
  187. struct pxa3xx_gcu_batch *ready = priv->ready;
  188. QDUMP("Start");
  189. BUG_ON(!ready);
  190. shared->buffer[num++] = 0x05000000;
  191. while (ready) {
  192. shared->buffer[num++] = 0x00000001;
  193. shared->buffer[num++] = ready->phys;
  194. ready = ready->next;
  195. }
  196. shared->buffer[num++] = 0x05000000;
  197. priv->running = priv->ready;
  198. priv->ready = priv->ready_last = NULL;
  199. gc_writel(priv, REG_GCRBLR, 0);
  200. shared->hw_running = 1;
  201. /* ring base address */
  202. gc_writel(priv, REG_GCRBBR, shared->buffer_phys);
  203. /* ring tail address */
  204. gc_writel(priv, REG_GCRBTR, shared->buffer_phys + num * 4);
  205. /* ring length */
  206. gc_writel(priv, REG_GCRBLR, ((num + 63) & ~63) * 4);
  207. }
  208. static irqreturn_t
  209. pxa3xx_gcu_handle_irq(int irq, void *ctx)
  210. {
  211. struct pxa3xx_gcu_priv *priv = ctx;
  212. struct pxa3xx_gcu_shared *shared = priv->shared;
  213. u32 status = gc_readl(priv, REG_GCISCR) & IE_ALL;
  214. QDUMP("-Interrupt");
  215. if (!status)
  216. return IRQ_NONE;
  217. spin_lock(&priv->spinlock);
  218. shared->num_interrupts++;
  219. if (status & IE_EEOB) {
  220. QDUMP(" [EEOB]");
  221. flush_running(priv);
  222. wake_up_all(&priv->wait_free);
  223. if (priv->ready) {
  224. run_ready(priv);
  225. } else {
  226. /* There is no more data prepared by the userspace.
  227. * Set hw_running = 0 and wait for the next userspace
  228. * kick-off */
  229. shared->num_idle++;
  230. shared->hw_running = 0;
  231. QDUMP(" '-> Idle.");
  232. /* set ring buffer length to zero */
  233. gc_writel(priv, REG_GCRBLR, 0);
  234. wake_up_all(&priv->wait_idle);
  235. }
  236. shared->num_done++;
  237. } else {
  238. QERROR(" [???]");
  239. dump_whole_state(priv);
  240. }
  241. /* Clear the interrupt */
  242. gc_writel(priv, REG_GCISCR, status);
  243. spin_unlock(&priv->spinlock);
  244. return IRQ_HANDLED;
  245. }
  246. static int
  247. pxa3xx_gcu_wait_idle(struct pxa3xx_gcu_priv *priv)
  248. {
  249. int ret = 0;
  250. QDUMP("Waiting for idle...");
  251. /* Does not need to be atomic. There's a lock in user space,
  252. * but anyhow, this is just for statistics. */
  253. priv->shared->num_wait_idle++;
  254. while (priv->shared->hw_running) {
  255. int num = priv->shared->num_interrupts;
  256. u32 rbexhr = gc_readl(priv, REG_GCRBEXHR);
  257. ret = wait_event_interruptible_timeout(priv->wait_idle,
  258. !priv->shared->hw_running, HZ*4);
  259. if (ret != 0)
  260. break;
  261. if (gc_readl(priv, REG_GCRBEXHR) == rbexhr &&
  262. priv->shared->num_interrupts == num) {
  263. QERROR("TIMEOUT");
  264. ret = -ETIMEDOUT;
  265. break;
  266. }
  267. }
  268. QDUMP("done");
  269. return ret;
  270. }
  271. static int
  272. pxa3xx_gcu_wait_free(struct pxa3xx_gcu_priv *priv)
  273. {
  274. int ret = 0;
  275. QDUMP("Waiting for free...");
  276. /* Does not need to be atomic. There's a lock in user space,
  277. * but anyhow, this is just for statistics. */
  278. priv->shared->num_wait_free++;
  279. while (!priv->free) {
  280. u32 rbexhr = gc_readl(priv, REG_GCRBEXHR);
  281. ret = wait_event_interruptible_timeout(priv->wait_free,
  282. priv->free, HZ*4);
  283. if (ret < 0)
  284. break;
  285. if (ret > 0)
  286. continue;
  287. if (gc_readl(priv, REG_GCRBEXHR) == rbexhr) {
  288. QERROR("TIMEOUT");
  289. ret = -ETIMEDOUT;
  290. break;
  291. }
  292. }
  293. QDUMP("done");
  294. return ret;
  295. }
  296. /* Misc device layer */
  297. static inline struct pxa3xx_gcu_priv *file_dev(struct file *file)
  298. {
  299. struct miscdevice *dev = file->private_data;
  300. return container_of(dev, struct pxa3xx_gcu_priv, misc_dev);
  301. }
  302. static ssize_t
  303. pxa3xx_gcu_misc_write(struct file *file, const char *buff,
  304. size_t count, loff_t *offp)
  305. {
  306. int ret;
  307. unsigned long flags;
  308. struct pxa3xx_gcu_batch *buffer;
  309. struct pxa3xx_gcu_priv *priv = file_dev(file);
  310. int words = count / 4;
  311. /* Does not need to be atomic. There's a lock in user space,
  312. * but anyhow, this is just for statistics. */
  313. priv->shared->num_writes++;
  314. priv->shared->num_words += words;
  315. /* Last word reserved for batch buffer end command */
  316. if (words >= PXA3XX_GCU_BATCH_WORDS)
  317. return -E2BIG;
  318. /* Wait for a free buffer */
  319. if (!priv->free) {
  320. ret = pxa3xx_gcu_wait_free(priv);
  321. if (ret < 0)
  322. return ret;
  323. }
  324. /*
  325. * Get buffer from free list
  326. */
  327. spin_lock_irqsave(&priv->spinlock, flags);
  328. buffer = priv->free;
  329. priv->free = buffer->next;
  330. spin_unlock_irqrestore(&priv->spinlock, flags);
  331. /* Copy data from user into buffer */
  332. ret = copy_from_user(buffer->ptr, buff, words * 4);
  333. if (ret) {
  334. spin_lock_irqsave(&priv->spinlock, flags);
  335. buffer->next = priv->free;
  336. priv->free = buffer;
  337. spin_unlock_irqrestore(&priv->spinlock, flags);
  338. return -EFAULT;
  339. }
  340. buffer->length = words;
  341. /* Append batch buffer end command */
  342. buffer->ptr[words] = 0x01000000;
  343. /*
  344. * Add buffer to ready list
  345. */
  346. spin_lock_irqsave(&priv->spinlock, flags);
  347. buffer->next = NULL;
  348. if (priv->ready) {
  349. BUG_ON(priv->ready_last == NULL);
  350. priv->ready_last->next = buffer;
  351. } else
  352. priv->ready = buffer;
  353. priv->ready_last = buffer;
  354. if (!priv->shared->hw_running)
  355. run_ready(priv);
  356. spin_unlock_irqrestore(&priv->spinlock, flags);
  357. return words * 4;
  358. }
  359. static long
  360. pxa3xx_gcu_misc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  361. {
  362. unsigned long flags;
  363. struct pxa3xx_gcu_priv *priv = file_dev(file);
  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 *file, struct vm_area_struct *vma)
  377. {
  378. unsigned int size = vma->vm_end - vma->vm_start;
  379. struct pxa3xx_gcu_priv *priv = file_dev(file);
  380. switch (vma->vm_pgoff) {
  381. case 0:
  382. /* hand out the shared data area */
  383. if (size != SHARED_SIZE)
  384. return -EINVAL;
  385. return dma_mmap_coherent(NULL, vma,
  386. priv->shared, priv->shared_phys, size);
  387. case SHARED_SIZE >> PAGE_SHIFT:
  388. /* hand out the MMIO base for direct register access
  389. * from userspace */
  390. if (size != resource_size(priv->resource_mem))
  391. return -EINVAL;
  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 const struct file_operations misc_fops = {
  452. .owner = THIS_MODULE,
  453. .write = pxa3xx_gcu_misc_write,
  454. .unlocked_ioctl = pxa3xx_gcu_misc_ioctl,
  455. .mmap = pxa3xx_gcu_misc_mmap
  456. };
  457. static int pxa3xx_gcu_probe(struct platform_device *dev)
  458. {
  459. int i, ret, irq;
  460. struct resource *r;
  461. struct pxa3xx_gcu_priv *priv;
  462. priv = kzalloc(sizeof(struct pxa3xx_gcu_priv), GFP_KERNEL);
  463. if (!priv)
  464. return -ENOMEM;
  465. for (i = 0; i < 8; i++) {
  466. ret = add_buffer(dev, priv);
  467. if (ret) {
  468. dev_err(&dev->dev, "failed to allocate DMA memory\n");
  469. goto err_free_priv;
  470. }
  471. }
  472. init_waitqueue_head(&priv->wait_idle);
  473. init_waitqueue_head(&priv->wait_free);
  474. spin_lock_init(&priv->spinlock);
  475. /* we allocate the misc device structure as part of our own allocation,
  476. * so we can get a pointer to our priv structure later on with
  477. * container_of(). This isn't really necessary as we have a fixed minor
  478. * number anyway, but this is to avoid statics. */
  479. priv->misc_dev.minor = MISCDEV_MINOR,
  480. priv->misc_dev.name = DRV_NAME,
  481. priv->misc_dev.fops = &misc_fops,
  482. /* register misc device */
  483. ret = misc_register(&priv->misc_dev);
  484. if (ret < 0) {
  485. dev_err(&dev->dev, "misc_register() for minor %d failed\n",
  486. MISCDEV_MINOR);
  487. goto err_free_priv;
  488. }
  489. /* handle IO resources */
  490. r = platform_get_resource(dev, IORESOURCE_MEM, 0);
  491. if (r == NULL) {
  492. dev_err(&dev->dev, "no I/O memory resource defined\n");
  493. ret = -ENODEV;
  494. goto err_misc_deregister;
  495. }
  496. if (!request_mem_region(r->start, resource_size(r), dev->name)) {
  497. dev_err(&dev->dev, "failed to request I/O memory\n");
  498. ret = -EBUSY;
  499. goto err_misc_deregister;
  500. }
  501. priv->mmio_base = ioremap_nocache(r->start, resource_size(r));
  502. if (!priv->mmio_base) {
  503. dev_err(&dev->dev, "failed to map I/O memory\n");
  504. ret = -EBUSY;
  505. goto err_free_mem_region;
  506. }
  507. /* allocate dma memory */
  508. priv->shared = dma_alloc_coherent(&dev->dev, SHARED_SIZE,
  509. &priv->shared_phys, GFP_KERNEL);
  510. if (!priv->shared) {
  511. dev_err(&dev->dev, "failed to allocate DMA memory\n");
  512. ret = -ENOMEM;
  513. goto err_free_io;
  514. }
  515. /* enable the clock */
  516. priv->clk = clk_get(&dev->dev, NULL);
  517. if (IS_ERR(priv->clk)) {
  518. dev_err(&dev->dev, "failed to get clock\n");
  519. ret = -ENODEV;
  520. goto err_free_dma;
  521. }
  522. ret = clk_enable(priv->clk);
  523. if (ret < 0) {
  524. dev_err(&dev->dev, "failed to enable clock\n");
  525. goto err_put_clk;
  526. }
  527. /* request the IRQ */
  528. irq = platform_get_irq(dev, 0);
  529. if (irq < 0) {
  530. dev_err(&dev->dev, "no IRQ defined\n");
  531. ret = -ENODEV;
  532. goto err_put_clk;
  533. }
  534. ret = request_irq(irq, pxa3xx_gcu_handle_irq,
  535. 0, DRV_NAME, priv);
  536. if (ret) {
  537. dev_err(&dev->dev, "request_irq failed\n");
  538. ret = -EBUSY;
  539. goto err_put_clk;
  540. }
  541. platform_set_drvdata(dev, priv);
  542. priv->resource_mem = r;
  543. pxa3xx_gcu_reset(priv);
  544. pxa3xx_gcu_init_debug_timer();
  545. dev_info(&dev->dev, "registered @0x%p, DMA 0x%p (%d bytes), IRQ %d\n",
  546. (void *) r->start, (void *) priv->shared_phys,
  547. SHARED_SIZE, irq);
  548. return 0;
  549. err_put_clk:
  550. clk_disable(priv->clk);
  551. clk_put(priv->clk);
  552. err_free_dma:
  553. dma_free_coherent(&dev->dev, SHARED_SIZE,
  554. priv->shared, priv->shared_phys);
  555. err_free_io:
  556. iounmap(priv->mmio_base);
  557. err_free_mem_region:
  558. release_mem_region(r->start, resource_size(r));
  559. err_misc_deregister:
  560. misc_deregister(&priv->misc_dev);
  561. err_free_priv:
  562. free_buffers(dev, priv);
  563. kfree(priv);
  564. return ret;
  565. }
  566. static int pxa3xx_gcu_remove(struct platform_device *dev)
  567. {
  568. struct pxa3xx_gcu_priv *priv = platform_get_drvdata(dev);
  569. struct resource *r = priv->resource_mem;
  570. pxa3xx_gcu_wait_idle(priv);
  571. misc_deregister(&priv->misc_dev);
  572. dma_free_coherent(&dev->dev, SHARED_SIZE,
  573. priv->shared, priv->shared_phys);
  574. iounmap(priv->mmio_base);
  575. release_mem_region(r->start, resource_size(r));
  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>");