pxa3xx-gcu.c 18 KB

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