pxa3xx-gcu.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * pxa3xx-gcu.c - Linux kernel module for PXA3xx graphics controllers
  4. *
  5. * This driver needs a DirectFB counterpart in user space, communication
  6. * is handled via mmap()ed memory areas and an ioctl.
  7. *
  8. * Copyright (c) 2009 Daniel Mack <[email protected]>
  9. * Copyright (c) 2009 Janine Kropp <[email protected]>
  10. * Copyright (c) 2009 Denis Oliver Kropp <[email protected]>
  11. */
  12. /*
  13. * WARNING: This controller is attached to System Bus 2 of the PXA which
  14. * needs its arbiter to be enabled explicitly (CKENB & 1<<9).
  15. * There is currently no way to do this from Linux, so you need to teach
  16. * your bootloader for now.
  17. */
  18. #include <linux/module.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/dma-mapping.h>
  21. #include <linux/miscdevice.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/spinlock.h>
  24. #include <linux/uaccess.h>
  25. #include <linux/ioctl.h>
  26. #include <linux/delay.h>
  27. #include <linux/sched.h>
  28. #include <linux/slab.h>
  29. #include <linux/clk.h>
  30. #include <linux/fs.h>
  31. #include <linux/io.h>
  32. #include <linux/of.h>
  33. #include "pxa3xx-gcu.h"
  34. #define DRV_NAME "pxa3xx-gcu"
  35. #define REG_GCCR 0x00
  36. #define GCCR_SYNC_CLR (1 << 9)
  37. #define GCCR_BP_RST (1 << 8)
  38. #define GCCR_ABORT (1 << 6)
  39. #define GCCR_STOP (1 << 4)
  40. #define REG_GCISCR 0x04
  41. #define REG_GCIECR 0x08
  42. #define REG_GCRBBR 0x20
  43. #define REG_GCRBLR 0x24
  44. #define REG_GCRBHR 0x28
  45. #define REG_GCRBTR 0x2C
  46. #define REG_GCRBEXHR 0x30
  47. #define IE_EOB (1 << 0)
  48. #define IE_EEOB (1 << 5)
  49. #define IE_ALL 0xff
  50. #define SHARED_SIZE PAGE_ALIGN(sizeof(struct pxa3xx_gcu_shared))
  51. /* #define PXA3XX_GCU_DEBUG */
  52. /* #define PXA3XX_GCU_DEBUG_TIMER */
  53. #ifdef PXA3XX_GCU_DEBUG
  54. #define QDUMP(msg) \
  55. do { \
  56. QPRINT(priv, KERN_DEBUG, msg); \
  57. } while (0)
  58. #else
  59. #define QDUMP(msg) do {} while (0)
  60. #endif
  61. #define QERROR(msg) \
  62. do { \
  63. QPRINT(priv, KERN_ERR, msg); \
  64. } while (0)
  65. struct pxa3xx_gcu_batch {
  66. struct pxa3xx_gcu_batch *next;
  67. u32 *ptr;
  68. dma_addr_t phys;
  69. unsigned long length;
  70. };
  71. struct pxa3xx_gcu_priv {
  72. struct device *dev;
  73. void __iomem *mmio_base;
  74. struct clk *clk;
  75. struct pxa3xx_gcu_shared *shared;
  76. dma_addr_t shared_phys;
  77. struct resource *resource_mem;
  78. struct miscdevice misc_dev;
  79. wait_queue_head_t wait_idle;
  80. wait_queue_head_t wait_free;
  81. spinlock_t spinlock;
  82. struct timespec64 base_time;
  83. struct pxa3xx_gcu_batch *free;
  84. struct pxa3xx_gcu_batch *ready;
  85. struct pxa3xx_gcu_batch *ready_last;
  86. struct pxa3xx_gcu_batch *running;
  87. };
  88. static inline unsigned long
  89. gc_readl(struct pxa3xx_gcu_priv *priv, unsigned int off)
  90. {
  91. return __raw_readl(priv->mmio_base + off);
  92. }
  93. static inline void
  94. gc_writel(struct pxa3xx_gcu_priv *priv, unsigned int off, unsigned long val)
  95. {
  96. __raw_writel(val, priv->mmio_base + off);
  97. }
  98. #define QPRINT(priv, level, msg) \
  99. do { \
  100. struct timespec64 ts; \
  101. struct pxa3xx_gcu_shared *shared = priv->shared; \
  102. u32 base = gc_readl(priv, REG_GCRBBR); \
  103. \
  104. ktime_get_ts64(&ts); \
  105. ts = timespec64_sub(ts, priv->base_time); \
  106. \
  107. printk(level "%lld.%03ld.%03ld - %-17s: %-21s (%s, " \
  108. "STATUS " \
  109. "0x%02lx, B 0x%08lx [%ld], E %5ld, H %5ld, " \
  110. "T %5ld)\n", \
  111. (s64)(ts.tv_sec), \
  112. ts.tv_nsec / NSEC_PER_MSEC, \
  113. (ts.tv_nsec % NSEC_PER_MSEC) / USEC_PER_MSEC, \
  114. __func__, msg, \
  115. shared->hw_running ? "running" : " idle", \
  116. gc_readl(priv, REG_GCISCR), \
  117. gc_readl(priv, REG_GCRBBR), \
  118. gc_readl(priv, REG_GCRBLR), \
  119. (gc_readl(priv, REG_GCRBEXHR) - base) / 4, \
  120. (gc_readl(priv, REG_GCRBHR) - base) / 4, \
  121. (gc_readl(priv, REG_GCRBTR) - base) / 4); \
  122. } while (0)
  123. static void
  124. pxa3xx_gcu_reset(struct pxa3xx_gcu_priv *priv)
  125. {
  126. QDUMP("RESET");
  127. /* disable interrupts */
  128. gc_writel(priv, REG_GCIECR, 0);
  129. /* reset hardware */
  130. gc_writel(priv, REG_GCCR, GCCR_ABORT);
  131. gc_writel(priv, REG_GCCR, 0);
  132. memset(priv->shared, 0, SHARED_SIZE);
  133. priv->shared->buffer_phys = priv->shared_phys;
  134. priv->shared->magic = PXA3XX_GCU_SHARED_MAGIC;
  135. ktime_get_ts64(&priv->base_time);
  136. /* set up the ring buffer pointers */
  137. gc_writel(priv, REG_GCRBLR, 0);
  138. gc_writel(priv, REG_GCRBBR, priv->shared_phys);
  139. gc_writel(priv, REG_GCRBTR, priv->shared_phys);
  140. /* enable all IRQs except EOB */
  141. gc_writel(priv, REG_GCIECR, IE_ALL & ~IE_EOB);
  142. }
  143. static void
  144. dump_whole_state(struct pxa3xx_gcu_priv *priv)
  145. {
  146. struct pxa3xx_gcu_shared *sh = priv->shared;
  147. u32 base = gc_readl(priv, REG_GCRBBR);
  148. QDUMP("DUMP");
  149. printk(KERN_DEBUG "== PXA3XX-GCU DUMP ==\n"
  150. "%s, STATUS 0x%02lx, B 0x%08lx [%ld], E %5ld, H %5ld, T %5ld\n",
  151. sh->hw_running ? "running" : "idle ",
  152. gc_readl(priv, REG_GCISCR),
  153. gc_readl(priv, REG_GCRBBR),
  154. gc_readl(priv, REG_GCRBLR),
  155. (gc_readl(priv, REG_GCRBEXHR) - base) / 4,
  156. (gc_readl(priv, REG_GCRBHR) - base) / 4,
  157. (gc_readl(priv, REG_GCRBTR) - base) / 4);
  158. }
  159. static void
  160. flush_running(struct pxa3xx_gcu_priv *priv)
  161. {
  162. struct pxa3xx_gcu_batch *running = priv->running;
  163. struct pxa3xx_gcu_batch *next;
  164. while (running) {
  165. next = running->next;
  166. running->next = priv->free;
  167. priv->free = running;
  168. running = next;
  169. }
  170. priv->running = NULL;
  171. }
  172. static void
  173. run_ready(struct pxa3xx_gcu_priv *priv)
  174. {
  175. unsigned int num = 0;
  176. struct pxa3xx_gcu_shared *shared = priv->shared;
  177. struct pxa3xx_gcu_batch *ready = priv->ready;
  178. QDUMP("Start");
  179. BUG_ON(!ready);
  180. shared->buffer[num++] = 0x05000000;
  181. while (ready) {
  182. shared->buffer[num++] = 0x00000001;
  183. shared->buffer[num++] = ready->phys;
  184. ready = ready->next;
  185. }
  186. shared->buffer[num++] = 0x05000000;
  187. priv->running = priv->ready;
  188. priv->ready = priv->ready_last = NULL;
  189. gc_writel(priv, REG_GCRBLR, 0);
  190. shared->hw_running = 1;
  191. /* ring base address */
  192. gc_writel(priv, REG_GCRBBR, shared->buffer_phys);
  193. /* ring tail address */
  194. gc_writel(priv, REG_GCRBTR, shared->buffer_phys + num * 4);
  195. /* ring length */
  196. gc_writel(priv, REG_GCRBLR, ((num + 63) & ~63) * 4);
  197. }
  198. static irqreturn_t
  199. pxa3xx_gcu_handle_irq(int irq, void *ctx)
  200. {
  201. struct pxa3xx_gcu_priv *priv = ctx;
  202. struct pxa3xx_gcu_shared *shared = priv->shared;
  203. u32 status = gc_readl(priv, REG_GCISCR) & IE_ALL;
  204. QDUMP("-Interrupt");
  205. if (!status)
  206. return IRQ_NONE;
  207. spin_lock(&priv->spinlock);
  208. shared->num_interrupts++;
  209. if (status & IE_EEOB) {
  210. QDUMP(" [EEOB]");
  211. flush_running(priv);
  212. wake_up_all(&priv->wait_free);
  213. if (priv->ready) {
  214. run_ready(priv);
  215. } else {
  216. /* There is no more data prepared by the userspace.
  217. * Set hw_running = 0 and wait for the next userspace
  218. * kick-off */
  219. shared->num_idle++;
  220. shared->hw_running = 0;
  221. QDUMP(" '-> Idle.");
  222. /* set ring buffer length to zero */
  223. gc_writel(priv, REG_GCRBLR, 0);
  224. wake_up_all(&priv->wait_idle);
  225. }
  226. shared->num_done++;
  227. } else {
  228. QERROR(" [???]");
  229. dump_whole_state(priv);
  230. }
  231. /* Clear the interrupt */
  232. gc_writel(priv, REG_GCISCR, status);
  233. spin_unlock(&priv->spinlock);
  234. return IRQ_HANDLED;
  235. }
  236. static int
  237. pxa3xx_gcu_wait_idle(struct pxa3xx_gcu_priv *priv)
  238. {
  239. int ret = 0;
  240. QDUMP("Waiting for idle...");
  241. /* Does not need to be atomic. There's a lock in user space,
  242. * but anyhow, this is just for statistics. */
  243. priv->shared->num_wait_idle++;
  244. while (priv->shared->hw_running) {
  245. int num = priv->shared->num_interrupts;
  246. u32 rbexhr = gc_readl(priv, REG_GCRBEXHR);
  247. ret = wait_event_interruptible_timeout(priv->wait_idle,
  248. !priv->shared->hw_running, HZ*4);
  249. if (ret != 0)
  250. break;
  251. if (gc_readl(priv, REG_GCRBEXHR) == rbexhr &&
  252. priv->shared->num_interrupts == num) {
  253. QERROR("TIMEOUT");
  254. ret = -ETIMEDOUT;
  255. break;
  256. }
  257. }
  258. QDUMP("done");
  259. return ret;
  260. }
  261. static int
  262. pxa3xx_gcu_wait_free(struct pxa3xx_gcu_priv *priv)
  263. {
  264. int ret = 0;
  265. QDUMP("Waiting for free...");
  266. /* Does not need to be atomic. There's a lock in user space,
  267. * but anyhow, this is just for statistics. */
  268. priv->shared->num_wait_free++;
  269. while (!priv->free) {
  270. u32 rbexhr = gc_readl(priv, REG_GCRBEXHR);
  271. ret = wait_event_interruptible_timeout(priv->wait_free,
  272. priv->free, HZ*4);
  273. if (ret < 0)
  274. break;
  275. if (ret > 0)
  276. continue;
  277. if (gc_readl(priv, REG_GCRBEXHR) == rbexhr) {
  278. QERROR("TIMEOUT");
  279. ret = -ETIMEDOUT;
  280. break;
  281. }
  282. }
  283. QDUMP("done");
  284. return ret;
  285. }
  286. /* Misc device layer */
  287. static inline struct pxa3xx_gcu_priv *to_pxa3xx_gcu_priv(struct file *file)
  288. {
  289. struct miscdevice *dev = file->private_data;
  290. return container_of(dev, struct pxa3xx_gcu_priv, misc_dev);
  291. }
  292. /*
  293. * provide an empty .open callback, so the core sets file->private_data
  294. * for us.
  295. */
  296. static int pxa3xx_gcu_open(struct inode *inode, struct file *file)
  297. {
  298. return 0;
  299. }
  300. static ssize_t
  301. pxa3xx_gcu_write(struct file *file, const char *buff,
  302. size_t count, loff_t *offp)
  303. {
  304. int ret;
  305. unsigned long flags;
  306. struct pxa3xx_gcu_batch *buffer;
  307. struct pxa3xx_gcu_priv *priv = to_pxa3xx_gcu_priv(file);
  308. size_t words = count / 4;
  309. /* Does not need to be atomic. There's a lock in user space,
  310. * but anyhow, this is just for statistics. */
  311. priv->shared->num_writes++;
  312. priv->shared->num_words += words;
  313. /* Last word reserved for batch buffer end command */
  314. if (words >= PXA3XX_GCU_BATCH_WORDS)
  315. return -E2BIG;
  316. /* Wait for a free buffer */
  317. if (!priv->free) {
  318. ret = pxa3xx_gcu_wait_free(priv);
  319. if (ret < 0)
  320. return ret;
  321. }
  322. /*
  323. * Get buffer from free list
  324. */
  325. spin_lock_irqsave(&priv->spinlock, flags);
  326. buffer = priv->free;
  327. priv->free = buffer->next;
  328. spin_unlock_irqrestore(&priv->spinlock, flags);
  329. /* Copy data from user into buffer */
  330. ret = copy_from_user(buffer->ptr, buff, words * 4);
  331. if (ret) {
  332. spin_lock_irqsave(&priv->spinlock, flags);
  333. buffer->next = priv->free;
  334. priv->free = buffer;
  335. spin_unlock_irqrestore(&priv->spinlock, flags);
  336. return -EFAULT;
  337. }
  338. buffer->length = words;
  339. /* Append batch buffer end command */
  340. buffer->ptr[words] = 0x01000000;
  341. /*
  342. * Add buffer to ready list
  343. */
  344. spin_lock_irqsave(&priv->spinlock, flags);
  345. buffer->next = NULL;
  346. if (priv->ready) {
  347. BUG_ON(priv->ready_last == NULL);
  348. priv->ready_last->next = buffer;
  349. } else
  350. priv->ready = buffer;
  351. priv->ready_last = buffer;
  352. if (!priv->shared->hw_running)
  353. run_ready(priv);
  354. spin_unlock_irqrestore(&priv->spinlock, flags);
  355. return words * 4;
  356. }
  357. static long
  358. pxa3xx_gcu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  359. {
  360. unsigned long flags;
  361. struct pxa3xx_gcu_priv *priv = to_pxa3xx_gcu_priv(file);
  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_mmap(struct file *file, struct vm_area_struct *vma)
  375. {
  376. unsigned int size = vma->vm_end - vma->vm_start;
  377. struct pxa3xx_gcu_priv *priv = to_pxa3xx_gcu_priv(file);
  378. switch (vma->vm_pgoff) {
  379. case 0:
  380. /* hand out the shared data area */
  381. if (size != SHARED_SIZE)
  382. return -EINVAL;
  383. return dma_mmap_coherent(priv->dev, vma,
  384. priv->shared, priv->shared_phys, size);
  385. case SHARED_SIZE >> PAGE_SHIFT:
  386. /* hand out the MMIO base for direct register access
  387. * from userspace */
  388. if (size != resource_size(priv->resource_mem))
  389. return -EINVAL;
  390. vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  391. return io_remap_pfn_range(vma, vma->vm_start,
  392. priv->resource_mem->start >> PAGE_SHIFT,
  393. size, vma->vm_page_prot);
  394. }
  395. return -EINVAL;
  396. }
  397. #ifdef PXA3XX_GCU_DEBUG_TIMER
  398. static struct timer_list pxa3xx_gcu_debug_timer;
  399. static struct pxa3xx_gcu_priv *debug_timer_priv;
  400. static void pxa3xx_gcu_debug_timedout(struct timer_list *unused)
  401. {
  402. struct pxa3xx_gcu_priv *priv = debug_timer_priv;
  403. QERROR("Timer DUMP");
  404. mod_timer(&pxa3xx_gcu_debug_timer, jiffies + 5 * HZ);
  405. }
  406. static void pxa3xx_gcu_init_debug_timer(struct pxa3xx_gcu_priv *priv)
  407. {
  408. /* init the timer structure */
  409. debug_timer_priv = priv;
  410. timer_setup(&pxa3xx_gcu_debug_timer, pxa3xx_gcu_debug_timedout, 0);
  411. pxa3xx_gcu_debug_timedout(NULL);
  412. }
  413. #else
  414. static inline void pxa3xx_gcu_init_debug_timer(struct pxa3xx_gcu_priv *priv) {}
  415. #endif
  416. static int
  417. pxa3xx_gcu_add_buffer(struct device *dev,
  418. struct pxa3xx_gcu_priv *priv)
  419. {
  420. struct pxa3xx_gcu_batch *buffer;
  421. buffer = kzalloc(sizeof(struct pxa3xx_gcu_batch), GFP_KERNEL);
  422. if (!buffer)
  423. return -ENOMEM;
  424. buffer->ptr = dma_alloc_coherent(dev, PXA3XX_GCU_BATCH_WORDS * 4,
  425. &buffer->phys, GFP_KERNEL);
  426. if (!buffer->ptr) {
  427. kfree(buffer);
  428. return -ENOMEM;
  429. }
  430. buffer->next = priv->free;
  431. priv->free = buffer;
  432. return 0;
  433. }
  434. static void
  435. pxa3xx_gcu_free_buffers(struct device *dev,
  436. struct pxa3xx_gcu_priv *priv)
  437. {
  438. struct pxa3xx_gcu_batch *next, *buffer = priv->free;
  439. while (buffer) {
  440. next = buffer->next;
  441. dma_free_coherent(dev, PXA3XX_GCU_BATCH_WORDS * 4,
  442. buffer->ptr, buffer->phys);
  443. kfree(buffer);
  444. buffer = next;
  445. }
  446. priv->free = NULL;
  447. }
  448. static const struct file_operations pxa3xx_gcu_miscdev_fops = {
  449. .owner = THIS_MODULE,
  450. .open = pxa3xx_gcu_open,
  451. .write = pxa3xx_gcu_write,
  452. .unlocked_ioctl = pxa3xx_gcu_ioctl,
  453. .mmap = pxa3xx_gcu_mmap,
  454. };
  455. static int pxa3xx_gcu_probe(struct platform_device *pdev)
  456. {
  457. int i, ret, irq;
  458. struct resource *r;
  459. struct pxa3xx_gcu_priv *priv;
  460. struct device *dev = &pdev->dev;
  461. priv = devm_kzalloc(dev, sizeof(struct pxa3xx_gcu_priv), GFP_KERNEL);
  462. if (!priv)
  463. return -ENOMEM;
  464. init_waitqueue_head(&priv->wait_idle);
  465. init_waitqueue_head(&priv->wait_free);
  466. spin_lock_init(&priv->spinlock);
  467. /* we allocate the misc device structure as part of our own allocation,
  468. * so we can get a pointer to our priv structure later on with
  469. * container_of(). This isn't really necessary as we have a fixed minor
  470. * number anyway, but this is to avoid statics. */
  471. priv->misc_dev.minor = PXA3XX_GCU_MINOR,
  472. priv->misc_dev.name = DRV_NAME,
  473. priv->misc_dev.fops = &pxa3xx_gcu_miscdev_fops;
  474. /* handle IO resources */
  475. r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  476. priv->mmio_base = devm_ioremap_resource(dev, r);
  477. if (IS_ERR(priv->mmio_base))
  478. return PTR_ERR(priv->mmio_base);
  479. /* enable the clock */
  480. priv->clk = devm_clk_get(dev, NULL);
  481. if (IS_ERR(priv->clk))
  482. return dev_err_probe(dev, PTR_ERR(priv->clk), "failed to get clock\n");
  483. /* request the IRQ */
  484. irq = platform_get_irq(pdev, 0);
  485. if (irq < 0)
  486. return irq;
  487. ret = devm_request_irq(dev, irq, pxa3xx_gcu_handle_irq,
  488. 0, DRV_NAME, priv);
  489. if (ret < 0) {
  490. dev_err(dev, "request_irq failed\n");
  491. return ret;
  492. }
  493. /* allocate dma memory */
  494. priv->shared = dma_alloc_coherent(dev, SHARED_SIZE,
  495. &priv->shared_phys, GFP_KERNEL);
  496. if (!priv->shared) {
  497. dev_err(dev, "failed to allocate DMA memory\n");
  498. return -ENOMEM;
  499. }
  500. /* register misc device */
  501. ret = misc_register(&priv->misc_dev);
  502. if (ret < 0) {
  503. dev_err(dev, "misc_register() for minor %d failed\n",
  504. PXA3XX_GCU_MINOR);
  505. goto err_free_dma;
  506. }
  507. ret = clk_prepare_enable(priv->clk);
  508. if (ret < 0) {
  509. dev_err(dev, "failed to enable clock\n");
  510. goto err_misc_deregister;
  511. }
  512. for (i = 0; i < 8; i++) {
  513. ret = pxa3xx_gcu_add_buffer(dev, priv);
  514. if (ret) {
  515. pxa3xx_gcu_free_buffers(dev, priv);
  516. dev_err(dev, "failed to allocate DMA memory\n");
  517. goto err_disable_clk;
  518. }
  519. }
  520. platform_set_drvdata(pdev, priv);
  521. priv->resource_mem = r;
  522. priv->dev = dev;
  523. pxa3xx_gcu_reset(priv);
  524. pxa3xx_gcu_init_debug_timer(priv);
  525. dev_info(dev, "registered @0x%p, DMA 0x%p (%d bytes), IRQ %d\n",
  526. (void *) r->start, (void *) priv->shared_phys,
  527. SHARED_SIZE, irq);
  528. return 0;
  529. err_disable_clk:
  530. clk_disable_unprepare(priv->clk);
  531. err_misc_deregister:
  532. misc_deregister(&priv->misc_dev);
  533. err_free_dma:
  534. dma_free_coherent(dev, SHARED_SIZE,
  535. priv->shared, priv->shared_phys);
  536. return ret;
  537. }
  538. static int pxa3xx_gcu_remove(struct platform_device *pdev)
  539. {
  540. struct pxa3xx_gcu_priv *priv = platform_get_drvdata(pdev);
  541. struct device *dev = &pdev->dev;
  542. pxa3xx_gcu_wait_idle(priv);
  543. misc_deregister(&priv->misc_dev);
  544. dma_free_coherent(dev, SHARED_SIZE, priv->shared, priv->shared_phys);
  545. clk_disable_unprepare(priv->clk);
  546. pxa3xx_gcu_free_buffers(dev, priv);
  547. return 0;
  548. }
  549. #ifdef CONFIG_OF
  550. static const struct of_device_id pxa3xx_gcu_of_match[] = {
  551. { .compatible = "marvell,pxa300-gcu", },
  552. { }
  553. };
  554. MODULE_DEVICE_TABLE(of, pxa3xx_gcu_of_match);
  555. #endif
  556. static struct platform_driver pxa3xx_gcu_driver = {
  557. .probe = pxa3xx_gcu_probe,
  558. .remove = pxa3xx_gcu_remove,
  559. .driver = {
  560. .name = DRV_NAME,
  561. .of_match_table = of_match_ptr(pxa3xx_gcu_of_match),
  562. },
  563. };
  564. module_platform_driver(pxa3xx_gcu_driver);
  565. MODULE_DESCRIPTION("PXA3xx graphics controller unit driver");
  566. MODULE_LICENSE("GPL");
  567. MODULE_ALIAS_MISCDEV(PXA3XX_GCU_MINOR);
  568. MODULE_AUTHOR("Janine Kropp <[email protected]>, "
  569. "Denis Oliver Kropp <[email protected]>, "
  570. "Daniel Mack <[email protected]>");