pxa3xx-gcu.c 17 KB

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