sh_mobile_ceu_camera.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. /*
  2. * V4L2 Driver for SuperH Mobile CEU interface
  3. *
  4. * Copyright (C) 2008 Magnus Damm
  5. *
  6. * Based on V4L2 Driver for PXA camera host - "pxa_camera.c",
  7. *
  8. * Copyright (C) 2006, Sascha Hauer, Pengutronix
  9. * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
  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. #include <linux/init.h>
  17. #include <linux/module.h>
  18. #include <linux/io.h>
  19. #include <linux/delay.h>
  20. #include <linux/dma-mapping.h>
  21. #include <linux/errno.h>
  22. #include <linux/fs.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/kernel.h>
  25. #include <linux/mm.h>
  26. #include <linux/moduleparam.h>
  27. #include <linux/time.h>
  28. #include <linux/version.h>
  29. #include <linux/device.h>
  30. #include <linux/platform_device.h>
  31. #include <linux/mutex.h>
  32. #include <linux/videodev2.h>
  33. #include <media/v4l2-common.h>
  34. #include <media/v4l2-dev.h>
  35. #include <media/soc_camera.h>
  36. #include <media/sh_mobile_ceu.h>
  37. #include <media/videobuf-dma-contig.h>
  38. /* register offsets for sh7722 / sh7723 */
  39. #define CAPSR 0x00
  40. #define CAPCR 0x04
  41. #define CAMCR 0x08
  42. #define CMCYR 0x0c
  43. #define CAMOR 0x10
  44. #define CAPWR 0x14
  45. #define CAIFR 0x18
  46. #define CSTCR 0x20 /* not on sh7723 */
  47. #define CSECR 0x24 /* not on sh7723 */
  48. #define CRCNTR 0x28
  49. #define CRCMPR 0x2c
  50. #define CFLCR 0x30
  51. #define CFSZR 0x34
  52. #define CDWDR 0x38
  53. #define CDAYR 0x3c
  54. #define CDACR 0x40
  55. #define CDBYR 0x44
  56. #define CDBCR 0x48
  57. #define CBDSR 0x4c
  58. #define CFWCR 0x5c
  59. #define CLFCR 0x60
  60. #define CDOCR 0x64
  61. #define CDDCR 0x68
  62. #define CDDAR 0x6c
  63. #define CEIER 0x70
  64. #define CETCR 0x74
  65. #define CSTSR 0x7c
  66. #define CSRTR 0x80
  67. #define CDSSR 0x84
  68. #define CDAYR2 0x90
  69. #define CDACR2 0x94
  70. #define CDBYR2 0x98
  71. #define CDBCR2 0x9c
  72. static DEFINE_MUTEX(camera_lock);
  73. /* per video frame buffer */
  74. struct sh_mobile_ceu_buffer {
  75. struct videobuf_buffer vb; /* v4l buffer must be first */
  76. const struct soc_camera_data_format *fmt;
  77. };
  78. struct sh_mobile_ceu_dev {
  79. struct device *dev;
  80. struct soc_camera_host ici;
  81. struct soc_camera_device *icd;
  82. unsigned int irq;
  83. void __iomem *base;
  84. unsigned long video_limit;
  85. /* lock used to protect videobuf */
  86. spinlock_t lock;
  87. struct list_head capture;
  88. struct videobuf_buffer *active;
  89. struct sh_mobile_ceu_info *pdata;
  90. };
  91. static void ceu_write(struct sh_mobile_ceu_dev *priv,
  92. unsigned long reg_offs, unsigned long data)
  93. {
  94. iowrite32(data, priv->base + reg_offs);
  95. }
  96. static unsigned long ceu_read(struct sh_mobile_ceu_dev *priv,
  97. unsigned long reg_offs)
  98. {
  99. return ioread32(priv->base + reg_offs);
  100. }
  101. /*
  102. * Videobuf operations
  103. */
  104. static int sh_mobile_ceu_videobuf_setup(struct videobuf_queue *vq,
  105. unsigned int *count,
  106. unsigned int *size)
  107. {
  108. struct soc_camera_device *icd = vq->priv_data;
  109. struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
  110. struct sh_mobile_ceu_dev *pcdev = ici->priv;
  111. int bytes_per_pixel = (icd->current_fmt->depth + 7) >> 3;
  112. *size = PAGE_ALIGN(icd->width * icd->height * bytes_per_pixel);
  113. if (0 == *count)
  114. *count = 2;
  115. if (pcdev->video_limit) {
  116. while (*size * *count > pcdev->video_limit)
  117. (*count)--;
  118. }
  119. dev_dbg(&icd->dev, "count=%d, size=%d\n", *count, *size);
  120. return 0;
  121. }
  122. static void free_buffer(struct videobuf_queue *vq,
  123. struct sh_mobile_ceu_buffer *buf)
  124. {
  125. struct soc_camera_device *icd = vq->priv_data;
  126. dev_dbg(&icd->dev, "%s (vb=0x%p) 0x%08lx %zd\n", __func__,
  127. &buf->vb, buf->vb.baddr, buf->vb.bsize);
  128. if (in_interrupt())
  129. BUG();
  130. videobuf_dma_contig_free(vq, &buf->vb);
  131. dev_dbg(&icd->dev, "%s freed\n", __func__);
  132. buf->vb.state = VIDEOBUF_NEEDS_INIT;
  133. }
  134. static void sh_mobile_ceu_capture(struct sh_mobile_ceu_dev *pcdev)
  135. {
  136. ceu_write(pcdev, CEIER, ceu_read(pcdev, CEIER) & ~1);
  137. ceu_write(pcdev, CETCR, ~ceu_read(pcdev, CETCR) & 0x0317f313);
  138. ceu_write(pcdev, CEIER, ceu_read(pcdev, CEIER) | 1);
  139. ceu_write(pcdev, CAPCR, ceu_read(pcdev, CAPCR) & ~0x10000);
  140. ceu_write(pcdev, CETCR, 0x0317f313 ^ 0x10);
  141. if (pcdev->active) {
  142. ceu_write(pcdev, CDAYR, videobuf_to_dma_contig(pcdev->active));
  143. ceu_write(pcdev, CAPSR, 0x1); /* start capture */
  144. }
  145. }
  146. static int sh_mobile_ceu_videobuf_prepare(struct videobuf_queue *vq,
  147. struct videobuf_buffer *vb,
  148. enum v4l2_field field)
  149. {
  150. struct soc_camera_device *icd = vq->priv_data;
  151. struct sh_mobile_ceu_buffer *buf;
  152. int ret;
  153. buf = container_of(vb, struct sh_mobile_ceu_buffer, vb);
  154. dev_dbg(&icd->dev, "%s (vb=0x%p) 0x%08lx %zd\n", __func__,
  155. vb, vb->baddr, vb->bsize);
  156. /* Added list head initialization on alloc */
  157. WARN_ON(!list_empty(&vb->queue));
  158. #ifdef DEBUG
  159. /* This can be useful if you want to see if we actually fill
  160. * the buffer with something */
  161. memset((void *)vb->baddr, 0xaa, vb->bsize);
  162. #endif
  163. BUG_ON(NULL == icd->current_fmt);
  164. if (buf->fmt != icd->current_fmt ||
  165. vb->width != icd->width ||
  166. vb->height != icd->height ||
  167. vb->field != field) {
  168. buf->fmt = icd->current_fmt;
  169. vb->width = icd->width;
  170. vb->height = icd->height;
  171. vb->field = field;
  172. vb->state = VIDEOBUF_NEEDS_INIT;
  173. }
  174. vb->size = vb->width * vb->height * ((buf->fmt->depth + 7) >> 3);
  175. if (0 != vb->baddr && vb->bsize < vb->size) {
  176. ret = -EINVAL;
  177. goto out;
  178. }
  179. if (vb->state == VIDEOBUF_NEEDS_INIT) {
  180. ret = videobuf_iolock(vq, vb, NULL);
  181. if (ret)
  182. goto fail;
  183. vb->state = VIDEOBUF_PREPARED;
  184. }
  185. return 0;
  186. fail:
  187. free_buffer(vq, buf);
  188. out:
  189. return ret;
  190. }
  191. static void sh_mobile_ceu_videobuf_queue(struct videobuf_queue *vq,
  192. struct videobuf_buffer *vb)
  193. {
  194. struct soc_camera_device *icd = vq->priv_data;
  195. struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
  196. struct sh_mobile_ceu_dev *pcdev = ici->priv;
  197. unsigned long flags;
  198. dev_dbg(&icd->dev, "%s (vb=0x%p) 0x%08lx %zd\n", __func__,
  199. vb, vb->baddr, vb->bsize);
  200. vb->state = VIDEOBUF_ACTIVE;
  201. spin_lock_irqsave(&pcdev->lock, flags);
  202. list_add_tail(&vb->queue, &pcdev->capture);
  203. if (!pcdev->active) {
  204. pcdev->active = vb;
  205. sh_mobile_ceu_capture(pcdev);
  206. }
  207. spin_unlock_irqrestore(&pcdev->lock, flags);
  208. }
  209. static void sh_mobile_ceu_videobuf_release(struct videobuf_queue *vq,
  210. struct videobuf_buffer *vb)
  211. {
  212. free_buffer(vq, container_of(vb, struct sh_mobile_ceu_buffer, vb));
  213. }
  214. static struct videobuf_queue_ops sh_mobile_ceu_videobuf_ops = {
  215. .buf_setup = sh_mobile_ceu_videobuf_setup,
  216. .buf_prepare = sh_mobile_ceu_videobuf_prepare,
  217. .buf_queue = sh_mobile_ceu_videobuf_queue,
  218. .buf_release = sh_mobile_ceu_videobuf_release,
  219. };
  220. static irqreturn_t sh_mobile_ceu_irq(int irq, void *data)
  221. {
  222. struct sh_mobile_ceu_dev *pcdev = data;
  223. struct videobuf_buffer *vb;
  224. unsigned long flags;
  225. spin_lock_irqsave(&pcdev->lock, flags);
  226. vb = pcdev->active;
  227. list_del_init(&vb->queue);
  228. if (!list_empty(&pcdev->capture))
  229. pcdev->active = list_entry(pcdev->capture.next,
  230. struct videobuf_buffer, queue);
  231. else
  232. pcdev->active = NULL;
  233. sh_mobile_ceu_capture(pcdev);
  234. vb->state = VIDEOBUF_DONE;
  235. do_gettimeofday(&vb->ts);
  236. vb->field_count++;
  237. wake_up(&vb->done);
  238. spin_unlock_irqrestore(&pcdev->lock, flags);
  239. return IRQ_HANDLED;
  240. }
  241. static int sh_mobile_ceu_add_device(struct soc_camera_device *icd)
  242. {
  243. struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
  244. struct sh_mobile_ceu_dev *pcdev = ici->priv;
  245. int ret = -EBUSY;
  246. mutex_lock(&camera_lock);
  247. if (pcdev->icd)
  248. goto err;
  249. dev_info(&icd->dev,
  250. "SuperH Mobile CEU driver attached to camera %d\n",
  251. icd->devnum);
  252. ret = icd->ops->init(icd);
  253. if (ret)
  254. goto err;
  255. ceu_write(pcdev, CAPSR, 1 << 16); /* reset */
  256. while (ceu_read(pcdev, CSTSR) & 1)
  257. msleep(1);
  258. pcdev->icd = icd;
  259. err:
  260. mutex_unlock(&camera_lock);
  261. return ret;
  262. }
  263. static void sh_mobile_ceu_remove_device(struct soc_camera_device *icd)
  264. {
  265. struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
  266. struct sh_mobile_ceu_dev *pcdev = ici->priv;
  267. BUG_ON(icd != pcdev->icd);
  268. /* disable capture, disable interrupts */
  269. ceu_write(pcdev, CEIER, 0);
  270. ceu_write(pcdev, CAPSR, 1 << 16); /* reset */
  271. icd->ops->release(icd);
  272. dev_info(&icd->dev,
  273. "SuperH Mobile CEU driver detached from camera %d\n",
  274. icd->devnum);
  275. pcdev->icd = NULL;
  276. }
  277. static int sh_mobile_ceu_set_bus_param(struct soc_camera_device *icd,
  278. __u32 pixfmt)
  279. {
  280. struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
  281. struct sh_mobile_ceu_dev *pcdev = ici->priv;
  282. int ret, buswidth, width, cfszr_width, cdwdr_width;
  283. unsigned long camera_flags, common_flags, value;
  284. camera_flags = icd->ops->query_bus_param(icd);
  285. common_flags = soc_camera_bus_param_compatible(camera_flags,
  286. pcdev->pdata->flags);
  287. if (!common_flags)
  288. return -EINVAL;
  289. ret = icd->ops->set_bus_param(icd, common_flags);
  290. if (ret < 0)
  291. return ret;
  292. switch (common_flags & SOCAM_DATAWIDTH_MASK) {
  293. case SOCAM_DATAWIDTH_8:
  294. buswidth = 8;
  295. break;
  296. case SOCAM_DATAWIDTH_16:
  297. buswidth = 16;
  298. break;
  299. default:
  300. return -EINVAL;
  301. }
  302. ceu_write(pcdev, CRCNTR, 0);
  303. ceu_write(pcdev, CRCMPR, 0);
  304. value = 0x00000010;
  305. value |= (common_flags & SOCAM_VSYNC_ACTIVE_LOW) ? (1 << 1) : 0;
  306. value |= (common_flags & SOCAM_HSYNC_ACTIVE_LOW) ? (1 << 0) : 0;
  307. value |= (buswidth == 16) ? (1 << 12) : 0;
  308. ceu_write(pcdev, CAMCR, value);
  309. ceu_write(pcdev, CAPCR, 0x00300000);
  310. ceu_write(pcdev, CAIFR, 0);
  311. mdelay(1);
  312. width = icd->width * (icd->current_fmt->depth / 8);
  313. width = (buswidth == 16) ? width / 2 : width;
  314. cfszr_width = (buswidth == 8) ? width / 2 : width;
  315. cdwdr_width = (buswidth == 16) ? width * 2 : width;
  316. ceu_write(pcdev, CAMOR, 0);
  317. ceu_write(pcdev, CAPWR, (icd->height << 16) | width);
  318. ceu_write(pcdev, CFLCR, 0); /* data fetch mode - no scaling */
  319. ceu_write(pcdev, CFSZR, (icd->height << 16) | cfszr_width);
  320. ceu_write(pcdev, CLFCR, 0); /* data fetch mode - no lowpass filter */
  321. ceu_write(pcdev, CDOCR, 0x00000016);
  322. ceu_write(pcdev, CDWDR, cdwdr_width);
  323. ceu_write(pcdev, CFWCR, 0); /* keep "datafetch firewall" disabled */
  324. /* not in bundle mode: skip CBDSR, CDAYR2, CDACR2, CDBYR2, CDBCR2 */
  325. /* in data fetch mode: no need for CDACR, CDBYR, CDBCR */
  326. return 0;
  327. }
  328. static int sh_mobile_ceu_try_bus_param(struct soc_camera_device *icd,
  329. __u32 pixfmt)
  330. {
  331. struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
  332. struct sh_mobile_ceu_dev *pcdev = ici->priv;
  333. unsigned long camera_flags, common_flags;
  334. camera_flags = icd->ops->query_bus_param(icd);
  335. common_flags = soc_camera_bus_param_compatible(camera_flags,
  336. pcdev->pdata->flags);
  337. if (!common_flags)
  338. return -EINVAL;
  339. return 0;
  340. }
  341. static int sh_mobile_ceu_set_fmt_cap(struct soc_camera_device *icd,
  342. __u32 pixfmt, struct v4l2_rect *rect)
  343. {
  344. return icd->ops->set_fmt_cap(icd, pixfmt, rect);
  345. }
  346. static int sh_mobile_ceu_try_fmt_cap(struct soc_camera_device *icd,
  347. struct v4l2_format *f)
  348. {
  349. /* FIXME: calculate using depth and bus width */
  350. if (f->fmt.pix.height < 4)
  351. f->fmt.pix.height = 4;
  352. if (f->fmt.pix.height > 1920)
  353. f->fmt.pix.height = 1920;
  354. if (f->fmt.pix.width < 2)
  355. f->fmt.pix.width = 2;
  356. if (f->fmt.pix.width > 2560)
  357. f->fmt.pix.width = 2560;
  358. f->fmt.pix.width &= ~0x01;
  359. f->fmt.pix.height &= ~0x03;
  360. /* limit to sensor capabilities */
  361. return icd->ops->try_fmt_cap(icd, f);
  362. }
  363. static int sh_mobile_ceu_reqbufs(struct soc_camera_file *icf,
  364. struct v4l2_requestbuffers *p)
  365. {
  366. int i;
  367. /* This is for locking debugging only. I removed spinlocks and now I
  368. * check whether .prepare is ever called on a linked buffer, or whether
  369. * a dma IRQ can occur for an in-work or unlinked buffer. Until now
  370. * it hadn't triggered */
  371. for (i = 0; i < p->count; i++) {
  372. struct sh_mobile_ceu_buffer *buf;
  373. buf = container_of(icf->vb_vidq.bufs[i],
  374. struct sh_mobile_ceu_buffer, vb);
  375. INIT_LIST_HEAD(&buf->vb.queue);
  376. }
  377. return 0;
  378. }
  379. static unsigned int sh_mobile_ceu_poll(struct file *file, poll_table *pt)
  380. {
  381. struct soc_camera_file *icf = file->private_data;
  382. struct sh_mobile_ceu_buffer *buf;
  383. buf = list_entry(icf->vb_vidq.stream.next,
  384. struct sh_mobile_ceu_buffer, vb.stream);
  385. poll_wait(file, &buf->vb.done, pt);
  386. if (buf->vb.state == VIDEOBUF_DONE ||
  387. buf->vb.state == VIDEOBUF_ERROR)
  388. return POLLIN|POLLRDNORM;
  389. return 0;
  390. }
  391. static int sh_mobile_ceu_querycap(struct soc_camera_host *ici,
  392. struct v4l2_capability *cap)
  393. {
  394. strlcpy(cap->card, "SuperH_Mobile_CEU", sizeof(cap->card));
  395. cap->version = KERNEL_VERSION(0, 0, 5);
  396. cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
  397. return 0;
  398. }
  399. static void sh_mobile_ceu_init_videobuf(struct videobuf_queue *q,
  400. struct soc_camera_device *icd)
  401. {
  402. struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
  403. struct sh_mobile_ceu_dev *pcdev = ici->priv;
  404. videobuf_queue_dma_contig_init(q,
  405. &sh_mobile_ceu_videobuf_ops,
  406. &ici->dev, &pcdev->lock,
  407. V4L2_BUF_TYPE_VIDEO_CAPTURE,
  408. V4L2_FIELD_NONE,
  409. sizeof(struct sh_mobile_ceu_buffer),
  410. icd);
  411. }
  412. static struct soc_camera_host_ops sh_mobile_ceu_host_ops = {
  413. .owner = THIS_MODULE,
  414. .add = sh_mobile_ceu_add_device,
  415. .remove = sh_mobile_ceu_remove_device,
  416. .set_fmt_cap = sh_mobile_ceu_set_fmt_cap,
  417. .try_fmt_cap = sh_mobile_ceu_try_fmt_cap,
  418. .reqbufs = sh_mobile_ceu_reqbufs,
  419. .poll = sh_mobile_ceu_poll,
  420. .querycap = sh_mobile_ceu_querycap,
  421. .try_bus_param = sh_mobile_ceu_try_bus_param,
  422. .set_bus_param = sh_mobile_ceu_set_bus_param,
  423. .init_videobuf = sh_mobile_ceu_init_videobuf,
  424. };
  425. static int sh_mobile_ceu_probe(struct platform_device *pdev)
  426. {
  427. struct sh_mobile_ceu_dev *pcdev;
  428. struct resource *res;
  429. void __iomem *base;
  430. unsigned int irq;
  431. int err = 0;
  432. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  433. irq = platform_get_irq(pdev, 0);
  434. if (!res || !irq) {
  435. dev_err(&pdev->dev, "Not enough CEU platform resources.\n");
  436. err = -ENODEV;
  437. goto exit;
  438. }
  439. pcdev = kzalloc(sizeof(*pcdev), GFP_KERNEL);
  440. if (!pcdev) {
  441. dev_err(&pdev->dev, "Could not allocate pcdev\n");
  442. err = -ENOMEM;
  443. goto exit;
  444. }
  445. platform_set_drvdata(pdev, pcdev);
  446. INIT_LIST_HEAD(&pcdev->capture);
  447. spin_lock_init(&pcdev->lock);
  448. pcdev->pdata = pdev->dev.platform_data;
  449. if (!pcdev->pdata) {
  450. err = -EINVAL;
  451. dev_err(&pdev->dev, "CEU platform data not set.\n");
  452. goto exit_kfree;
  453. }
  454. base = ioremap_nocache(res->start, res->end - res->start + 1);
  455. if (!base) {
  456. err = -ENXIO;
  457. dev_err(&pdev->dev, "Unable to ioremap CEU registers.\n");
  458. goto exit_kfree;
  459. }
  460. pcdev->irq = irq;
  461. pcdev->base = base;
  462. pcdev->video_limit = 0; /* only enabled if second resource exists */
  463. pcdev->dev = &pdev->dev;
  464. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  465. if (res) {
  466. err = dma_declare_coherent_memory(&pdev->dev, res->start,
  467. res->start,
  468. (res->end - res->start) + 1,
  469. DMA_MEMORY_MAP |
  470. DMA_MEMORY_EXCLUSIVE);
  471. if (!err) {
  472. dev_err(&pdev->dev, "Unable to declare CEU memory.\n");
  473. err = -ENXIO;
  474. goto exit_iounmap;
  475. }
  476. pcdev->video_limit = (res->end - res->start) + 1;
  477. }
  478. /* request irq */
  479. err = request_irq(pcdev->irq, sh_mobile_ceu_irq, IRQF_DISABLED,
  480. pdev->dev.bus_id, pcdev);
  481. if (err) {
  482. dev_err(&pdev->dev, "Unable to register CEU interrupt.\n");
  483. goto exit_release_mem;
  484. }
  485. pcdev->ici.priv = pcdev;
  486. pcdev->ici.dev.parent = &pdev->dev;
  487. pcdev->ici.nr = pdev->id;
  488. pcdev->ici.drv_name = pdev->dev.bus_id,
  489. pcdev->ici.ops = &sh_mobile_ceu_host_ops,
  490. err = soc_camera_host_register(&pcdev->ici);
  491. if (err)
  492. goto exit_free_irq;
  493. return 0;
  494. exit_free_irq:
  495. free_irq(pcdev->irq, pcdev);
  496. exit_release_mem:
  497. if (platform_get_resource(pdev, IORESOURCE_MEM, 1))
  498. dma_release_declared_memory(&pdev->dev);
  499. exit_iounmap:
  500. iounmap(base);
  501. exit_kfree:
  502. kfree(pcdev);
  503. exit:
  504. return err;
  505. }
  506. static int sh_mobile_ceu_remove(struct platform_device *pdev)
  507. {
  508. struct sh_mobile_ceu_dev *pcdev = platform_get_drvdata(pdev);
  509. soc_camera_host_unregister(&pcdev->ici);
  510. free_irq(pcdev->irq, pcdev);
  511. if (platform_get_resource(pdev, IORESOURCE_MEM, 1))
  512. dma_release_declared_memory(&pdev->dev);
  513. iounmap(pcdev->base);
  514. kfree(pcdev);
  515. return 0;
  516. }
  517. static struct platform_driver sh_mobile_ceu_driver = {
  518. .driver = {
  519. .name = "sh_mobile_ceu",
  520. },
  521. .probe = sh_mobile_ceu_probe,
  522. .remove = sh_mobile_ceu_remove,
  523. };
  524. static int __init sh_mobile_ceu_init(void)
  525. {
  526. return platform_driver_register(&sh_mobile_ceu_driver);
  527. }
  528. static void __exit sh_mobile_ceu_exit(void)
  529. {
  530. platform_driver_unregister(&sh_mobile_ceu_driver);
  531. }
  532. module_init(sh_mobile_ceu_init);
  533. module_exit(sh_mobile_ceu_exit);
  534. MODULE_DESCRIPTION("SuperH Mobile CEU driver");
  535. MODULE_AUTHOR("Magnus Damm");
  536. MODULE_LICENSE("GPL");