pxa3xx-gcu.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  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 <linux/of.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. wait_queue_head_t wait_idle;
  93. wait_queue_head_t wait_free;
  94. spinlock_t spinlock;
  95. struct timespec64 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 timespec64 ts; \
  114. struct pxa3xx_gcu_shared *shared = priv->shared; \
  115. u32 base = gc_readl(priv, REG_GCRBBR); \
  116. \
  117. ktime_get_ts64(&ts); \
  118. ts = timespec64_sub(ts, priv->base_time); \
  119. \
  120. printk(level "%lld.%03ld.%03ld - %-17s: %-21s (%s, " \
  121. "STATUS " \
  122. "0x%02lx, B 0x%08lx [%ld], E %5ld, H %5ld, " \
  123. "T %5ld)\n", \
  124. (s64)(ts.tv_sec), \
  125. ts.tv_nsec / NSEC_PER_MSEC, \
  126. (ts.tv_nsec % NSEC_PER_MSEC) / USEC_PER_MSEC, \
  127. __func__, msg, \
  128. shared->hw_running ? "running" : " idle", \
  129. gc_readl(priv, REG_GCISCR), \
  130. gc_readl(priv, REG_GCRBBR), \
  131. gc_readl(priv, REG_GCRBLR), \
  132. (gc_readl(priv, REG_GCRBEXHR) - base) / 4, \
  133. (gc_readl(priv, REG_GCRBHR) - base) / 4, \
  134. (gc_readl(priv, REG_GCRBTR) - base) / 4); \
  135. } while (0)
  136. static void
  137. pxa3xx_gcu_reset(struct pxa3xx_gcu_priv *priv)
  138. {
  139. QDUMP("RESET");
  140. /* disable interrupts */
  141. gc_writel(priv, REG_GCIECR, 0);
  142. /* reset hardware */
  143. gc_writel(priv, REG_GCCR, GCCR_ABORT);
  144. gc_writel(priv, REG_GCCR, 0);
  145. memset(priv->shared, 0, SHARED_SIZE);
  146. priv->shared->buffer_phys = priv->shared_phys;
  147. priv->shared->magic = PXA3XX_GCU_SHARED_MAGIC;
  148. ktime_get_ts64(&priv->base_time);
  149. /* set up the ring buffer pointers */
  150. gc_writel(priv, REG_GCRBLR, 0);
  151. gc_writel(priv, REG_GCRBBR, priv->shared_phys);
  152. gc_writel(priv, REG_GCRBTR, priv->shared_phys);
  153. /* enable all IRQs except EOB */
  154. gc_writel(priv, REG_GCIECR, IE_ALL & ~IE_EOB);
  155. }
  156. static void
  157. dump_whole_state(struct pxa3xx_gcu_priv *priv)
  158. {
  159. struct pxa3xx_gcu_shared *sh = priv->shared;
  160. u32 base = gc_readl(priv, REG_GCRBBR);
  161. QDUMP("DUMP");
  162. printk(KERN_DEBUG "== PXA3XX-GCU DUMP ==\n"
  163. "%s, STATUS 0x%02lx, B 0x%08lx [%ld], E %5ld, H %5ld, T %5ld\n",
  164. sh->hw_running ? "running" : "idle ",
  165. gc_readl(priv, REG_GCISCR),
  166. gc_readl(priv, REG_GCRBBR),
  167. gc_readl(priv, REG_GCRBLR),
  168. (gc_readl(priv, REG_GCRBEXHR) - base) / 4,
  169. (gc_readl(priv, REG_GCRBHR) - base) / 4,
  170. (gc_readl(priv, REG_GCRBTR) - base) / 4);
  171. }
  172. static void
  173. flush_running(struct pxa3xx_gcu_priv *priv)
  174. {
  175. struct pxa3xx_gcu_batch *running = priv->running;
  176. struct pxa3xx_gcu_batch *next;
  177. while (running) {
  178. next = running->next;
  179. running->next = priv->free;
  180. priv->free = running;
  181. running = next;
  182. }
  183. priv->running = NULL;
  184. }
  185. static void
  186. run_ready(struct pxa3xx_gcu_priv *priv)
  187. {
  188. unsigned int num = 0;
  189. struct pxa3xx_gcu_shared *shared = priv->shared;
  190. struct pxa3xx_gcu_batch *ready = priv->ready;
  191. QDUMP("Start");
  192. BUG_ON(!ready);
  193. shared->buffer[num++] = 0x05000000;
  194. while (ready) {
  195. shared->buffer[num++] = 0x00000001;
  196. shared->buffer[num++] = ready->phys;
  197. ready = ready->next;
  198. }
  199. shared->buffer[num++] = 0x05000000;
  200. priv->running = priv->ready;
  201. priv->ready = priv->ready_last = NULL;
  202. gc_writel(priv, REG_GCRBLR, 0);
  203. shared->hw_running = 1;
  204. /* ring base address */
  205. gc_writel(priv, REG_GCRBBR, shared->buffer_phys);
  206. /* ring tail address */
  207. gc_writel(priv, REG_GCRBTR, shared->buffer_phys + num * 4);
  208. /* ring length */
  209. gc_writel(priv, REG_GCRBLR, ((num + 63) & ~63) * 4);
  210. }
  211. static irqreturn_t
  212. pxa3xx_gcu_handle_irq(int irq, void *ctx)
  213. {
  214. struct pxa3xx_gcu_priv *priv = ctx;
  215. struct pxa3xx_gcu_shared *shared = priv->shared;
  216. u32 status = gc_readl(priv, REG_GCISCR) & IE_ALL;
  217. QDUMP("-Interrupt");
  218. if (!status)
  219. return IRQ_NONE;
  220. spin_lock(&priv->spinlock);
  221. shared->num_interrupts++;
  222. if (status & IE_EEOB) {
  223. QDUMP(" [EEOB]");
  224. flush_running(priv);
  225. wake_up_all(&priv->wait_free);
  226. if (priv->ready) {
  227. run_ready(priv);
  228. } else {
  229. /* There is no more data prepared by the userspace.
  230. * Set hw_running = 0 and wait for the next userspace
  231. * kick-off */
  232. shared->num_idle++;
  233. shared->hw_running = 0;
  234. QDUMP(" '-> Idle.");
  235. /* set ring buffer length to zero */
  236. gc_writel(priv, REG_GCRBLR, 0);
  237. wake_up_all(&priv->wait_idle);
  238. }
  239. shared->num_done++;
  240. } else {
  241. QERROR(" [???]");
  242. dump_whole_state(priv);
  243. }
  244. /* Clear the interrupt */
  245. gc_writel(priv, REG_GCISCR, status);
  246. spin_unlock(&priv->spinlock);
  247. return IRQ_HANDLED;
  248. }
  249. static int
  250. pxa3xx_gcu_wait_idle(struct pxa3xx_gcu_priv *priv)
  251. {
  252. int ret = 0;
  253. QDUMP("Waiting for idle...");
  254. /* Does not need to be atomic. There's a lock in user space,
  255. * but anyhow, this is just for statistics. */
  256. priv->shared->num_wait_idle++;
  257. while (priv->shared->hw_running) {
  258. int num = priv->shared->num_interrupts;
  259. u32 rbexhr = gc_readl(priv, REG_GCRBEXHR);
  260. ret = wait_event_interruptible_timeout(priv->wait_idle,
  261. !priv->shared->hw_running, HZ*4);
  262. if (ret != 0)
  263. break;
  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 inline struct pxa3xx_gcu_priv *to_pxa3xx_gcu_priv(struct file *file)
  301. {
  302. struct miscdevice *dev = file->private_data;
  303. return container_of(dev, struct pxa3xx_gcu_priv, misc_dev);
  304. }
  305. /*
  306. * provide an empty .open callback, so the core sets file->private_data
  307. * for us.
  308. */
  309. static int pxa3xx_gcu_open(struct inode *inode, struct file *file)
  310. {
  311. return 0;
  312. }
  313. static ssize_t
  314. pxa3xx_gcu_write(struct file *file, const char *buff,
  315. size_t count, loff_t *offp)
  316. {
  317. int ret;
  318. unsigned long flags;
  319. struct pxa3xx_gcu_batch *buffer;
  320. struct pxa3xx_gcu_priv *priv = to_pxa3xx_gcu_priv(file);
  321. int words = count / 4;
  322. /* Does not need to be atomic. There's a lock in user space,
  323. * but anyhow, this is just for statistics. */
  324. priv->shared->num_writes++;
  325. priv->shared->num_words += words;
  326. /* Last word reserved for batch buffer end command */
  327. if (words >= PXA3XX_GCU_BATCH_WORDS)
  328. return -E2BIG;
  329. /* Wait for a free buffer */
  330. if (!priv->free) {
  331. ret = pxa3xx_gcu_wait_free(priv);
  332. if (ret < 0)
  333. return ret;
  334. }
  335. /*
  336. * Get buffer from free list
  337. */
  338. spin_lock_irqsave(&priv->spinlock, flags);
  339. buffer = priv->free;
  340. priv->free = buffer->next;
  341. spin_unlock_irqrestore(&priv->spinlock, flags);
  342. /* Copy data from user into buffer */
  343. ret = copy_from_user(buffer->ptr, buff, words * 4);
  344. if (ret) {
  345. spin_lock_irqsave(&priv->spinlock, flags);
  346. buffer->next = priv->free;
  347. priv->free = buffer;
  348. spin_unlock_irqrestore(&priv->spinlock, flags);
  349. return -EFAULT;
  350. }
  351. buffer->length = words;
  352. /* Append batch buffer end command */
  353. buffer->ptr[words] = 0x01000000;
  354. /*
  355. * Add buffer to ready list
  356. */
  357. spin_lock_irqsave(&priv->spinlock, flags);
  358. buffer->next = NULL;
  359. if (priv->ready) {
  360. BUG_ON(priv->ready_last == NULL);
  361. priv->ready_last->next = buffer;
  362. } else
  363. priv->ready = buffer;
  364. priv->ready_last = buffer;
  365. if (!priv->shared->hw_running)
  366. run_ready(priv);
  367. spin_unlock_irqrestore(&priv->spinlock, flags);
  368. return words * 4;
  369. }
  370. static long
  371. pxa3xx_gcu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  372. {
  373. unsigned long flags;
  374. struct pxa3xx_gcu_priv *priv = to_pxa3xx_gcu_priv(file);
  375. switch (cmd) {
  376. case PXA3XX_GCU_IOCTL_RESET:
  377. spin_lock_irqsave(&priv->spinlock, flags);
  378. pxa3xx_gcu_reset(priv);
  379. spin_unlock_irqrestore(&priv->spinlock, flags);
  380. return 0;
  381. case PXA3XX_GCU_IOCTL_WAIT_IDLE:
  382. return pxa3xx_gcu_wait_idle(priv);
  383. }
  384. return -ENOSYS;
  385. }
  386. static int
  387. pxa3xx_gcu_mmap(struct file *file, struct vm_area_struct *vma)
  388. {
  389. unsigned int size = vma->vm_end - vma->vm_start;
  390. struct pxa3xx_gcu_priv *priv = to_pxa3xx_gcu_priv(file);
  391. switch (vma->vm_pgoff) {
  392. case 0:
  393. /* hand out the shared data area */
  394. if (size != SHARED_SIZE)
  395. return -EINVAL;
  396. return dma_mmap_coherent(NULL, vma,
  397. priv->shared, priv->shared_phys, size);
  398. case SHARED_SIZE >> PAGE_SHIFT:
  399. /* hand out the MMIO base for direct register access
  400. * from userspace */
  401. if (size != resource_size(priv->resource_mem))
  402. return -EINVAL;
  403. vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  404. return io_remap_pfn_range(vma, vma->vm_start,
  405. priv->resource_mem->start >> PAGE_SHIFT,
  406. size, vma->vm_page_prot);
  407. }
  408. return -EINVAL;
  409. }
  410. #ifdef PXA3XX_GCU_DEBUG_TIMER
  411. static struct timer_list pxa3xx_gcu_debug_timer;
  412. static struct pxa3xx_gcu_priv *debug_timer_priv;
  413. static void pxa3xx_gcu_debug_timedout(struct timer_list *unused)
  414. {
  415. struct pxa3xx_gcu_priv *priv = debug_timer_priv;
  416. QERROR("Timer DUMP");
  417. mod_timer(&pxa3xx_gcu_debug_timer, jiffies + 5 * HZ);
  418. }
  419. static void pxa3xx_gcu_init_debug_timer(struct pxa3xx_gcu_priv *priv)
  420. {
  421. /* init the timer structure */
  422. debug_timer_priv = priv;
  423. timer_setup(&pxa3xx_gcu_debug_timer, pxa3xx_gcu_debug_timedout, 0);
  424. pxa3xx_gcu_debug_timedout(NULL);
  425. }
  426. #else
  427. static inline void pxa3xx_gcu_init_debug_timer(struct pxa3xx_gcu_priv *priv) {}
  428. #endif
  429. static int
  430. pxa3xx_gcu_add_buffer(struct device *dev,
  431. struct pxa3xx_gcu_priv *priv)
  432. {
  433. struct pxa3xx_gcu_batch *buffer;
  434. buffer = kzalloc(sizeof(struct pxa3xx_gcu_batch), GFP_KERNEL);
  435. if (!buffer)
  436. return -ENOMEM;
  437. buffer->ptr = dma_alloc_coherent(dev, PXA3XX_GCU_BATCH_WORDS * 4,
  438. &buffer->phys, GFP_KERNEL);
  439. if (!buffer->ptr) {
  440. kfree(buffer);
  441. return -ENOMEM;
  442. }
  443. buffer->next = priv->free;
  444. priv->free = buffer;
  445. return 0;
  446. }
  447. static void
  448. pxa3xx_gcu_free_buffers(struct device *dev,
  449. struct pxa3xx_gcu_priv *priv)
  450. {
  451. struct pxa3xx_gcu_batch *next, *buffer = priv->free;
  452. while (buffer) {
  453. next = buffer->next;
  454. dma_free_coherent(dev, PXA3XX_GCU_BATCH_WORDS * 4,
  455. buffer->ptr, buffer->phys);
  456. kfree(buffer);
  457. buffer = next;
  458. }
  459. priv->free = NULL;
  460. }
  461. static const struct file_operations pxa3xx_gcu_miscdev_fops = {
  462. .owner = THIS_MODULE,
  463. .open = pxa3xx_gcu_open,
  464. .write = pxa3xx_gcu_write,
  465. .unlocked_ioctl = pxa3xx_gcu_ioctl,
  466. .mmap = pxa3xx_gcu_mmap,
  467. };
  468. static int pxa3xx_gcu_probe(struct platform_device *pdev)
  469. {
  470. int i, ret, irq;
  471. struct resource *r;
  472. struct pxa3xx_gcu_priv *priv;
  473. struct device *dev = &pdev->dev;
  474. priv = devm_kzalloc(dev, sizeof(struct pxa3xx_gcu_priv), GFP_KERNEL);
  475. if (!priv)
  476. return -ENOMEM;
  477. init_waitqueue_head(&priv->wait_idle);
  478. init_waitqueue_head(&priv->wait_free);
  479. spin_lock_init(&priv->spinlock);
  480. /* we allocate the misc device structure as part of our own allocation,
  481. * so we can get a pointer to our priv structure later on with
  482. * container_of(). This isn't really necessary as we have a fixed minor
  483. * number anyway, but this is to avoid statics. */
  484. priv->misc_dev.minor = MISCDEV_MINOR,
  485. priv->misc_dev.name = DRV_NAME,
  486. priv->misc_dev.fops = &pxa3xx_gcu_miscdev_fops;
  487. /* handle IO resources */
  488. r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  489. priv->mmio_base = devm_ioremap_resource(dev, r);
  490. if (IS_ERR(priv->mmio_base))
  491. return PTR_ERR(priv->mmio_base);
  492. /* enable the clock */
  493. priv->clk = devm_clk_get(dev, NULL);
  494. if (IS_ERR(priv->clk)) {
  495. dev_err(dev, "failed to get clock\n");
  496. return PTR_ERR(priv->clk);
  497. }
  498. /* request the IRQ */
  499. irq = platform_get_irq(pdev, 0);
  500. if (irq < 0) {
  501. dev_err(dev, "no IRQ defined: %d\n", irq);
  502. return irq;
  503. }
  504. ret = devm_request_irq(dev, irq, pxa3xx_gcu_handle_irq,
  505. 0, DRV_NAME, priv);
  506. if (ret < 0) {
  507. dev_err(dev, "request_irq failed\n");
  508. return ret;
  509. }
  510. /* allocate dma memory */
  511. priv->shared = dma_alloc_coherent(dev, SHARED_SIZE,
  512. &priv->shared_phys, GFP_KERNEL);
  513. if (!priv->shared) {
  514. dev_err(dev, "failed to allocate DMA memory\n");
  515. return -ENOMEM;
  516. }
  517. /* register misc device */
  518. ret = misc_register(&priv->misc_dev);
  519. if (ret < 0) {
  520. dev_err(dev, "misc_register() for minor %d failed\n",
  521. MISCDEV_MINOR);
  522. goto err_free_dma;
  523. }
  524. ret = clk_prepare_enable(priv->clk);
  525. if (ret < 0) {
  526. dev_err(dev, "failed to enable clock\n");
  527. goto err_misc_deregister;
  528. }
  529. for (i = 0; i < 8; i++) {
  530. ret = pxa3xx_gcu_add_buffer(dev, priv);
  531. if (ret) {
  532. dev_err(dev, "failed to allocate DMA memory\n");
  533. goto err_disable_clk;
  534. }
  535. }
  536. platform_set_drvdata(pdev, priv);
  537. priv->resource_mem = r;
  538. pxa3xx_gcu_reset(priv);
  539. pxa3xx_gcu_init_debug_timer(priv);
  540. dev_info(dev, "registered @0x%p, DMA 0x%p (%d bytes), IRQ %d\n",
  541. (void *) r->start, (void *) priv->shared_phys,
  542. SHARED_SIZE, irq);
  543. return 0;
  544. err_free_dma:
  545. dma_free_coherent(dev, SHARED_SIZE,
  546. priv->shared, priv->shared_phys);
  547. err_misc_deregister:
  548. misc_deregister(&priv->misc_dev);
  549. err_disable_clk:
  550. clk_disable_unprepare(priv->clk);
  551. return ret;
  552. }
  553. static int pxa3xx_gcu_remove(struct platform_device *pdev)
  554. {
  555. struct pxa3xx_gcu_priv *priv = platform_get_drvdata(pdev);
  556. struct device *dev = &pdev->dev;
  557. pxa3xx_gcu_wait_idle(priv);
  558. misc_deregister(&priv->misc_dev);
  559. dma_free_coherent(dev, SHARED_SIZE, priv->shared, priv->shared_phys);
  560. pxa3xx_gcu_free_buffers(dev, priv);
  561. return 0;
  562. }
  563. #ifdef CONFIG_OF
  564. static const struct of_device_id pxa3xx_gcu_of_match[] = {
  565. { .compatible = "marvell,pxa300-gcu", },
  566. { }
  567. };
  568. MODULE_DEVICE_TABLE(of, pxa3xx_gcu_of_match);
  569. #endif
  570. static struct platform_driver pxa3xx_gcu_driver = {
  571. .probe = pxa3xx_gcu_probe,
  572. .remove = pxa3xx_gcu_remove,
  573. .driver = {
  574. .name = DRV_NAME,
  575. .of_match_table = of_match_ptr(pxa3xx_gcu_of_match),
  576. },
  577. };
  578. module_platform_driver(pxa3xx_gcu_driver);
  579. MODULE_DESCRIPTION("PXA3xx graphics controller unit driver");
  580. MODULE_LICENSE("GPL");
  581. MODULE_ALIAS_MISCDEV(MISCDEV_MINOR);
  582. MODULE_AUTHOR("Janine Kropp <nin@directfb.org>, "
  583. "Denis Oliver Kropp <dok@directfb.org>, "
  584. "Daniel Mack <daniel@caiaq.de>");