sh_mobile_ceu_camera.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  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. if (pcdev->pdata->enable_camera)
  253. pcdev->pdata->enable_camera();
  254. ret = icd->ops->init(icd);
  255. if (ret)
  256. goto err;
  257. ceu_write(pcdev, CAPSR, 1 << 16); /* reset */
  258. while (ceu_read(pcdev, CSTSR) & 1)
  259. msleep(1);
  260. pcdev->icd = icd;
  261. err:
  262. mutex_unlock(&camera_lock);
  263. return ret;
  264. }
  265. static void sh_mobile_ceu_remove_device(struct soc_camera_device *icd)
  266. {
  267. struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
  268. struct sh_mobile_ceu_dev *pcdev = ici->priv;
  269. BUG_ON(icd != pcdev->icd);
  270. /* disable capture, disable interrupts */
  271. ceu_write(pcdev, CEIER, 0);
  272. ceu_write(pcdev, CAPSR, 1 << 16); /* reset */
  273. icd->ops->release(icd);
  274. if (pcdev->pdata->disable_camera)
  275. pcdev->pdata->disable_camera();
  276. dev_info(&icd->dev,
  277. "SuperH Mobile CEU driver detached from camera %d\n",
  278. icd->devnum);
  279. pcdev->icd = NULL;
  280. }
  281. static int sh_mobile_ceu_set_bus_param(struct soc_camera_device *icd,
  282. __u32 pixfmt)
  283. {
  284. struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
  285. struct sh_mobile_ceu_dev *pcdev = ici->priv;
  286. int ret, buswidth, width, cfszr_width, cdwdr_width;
  287. unsigned long camera_flags, common_flags, value;
  288. camera_flags = icd->ops->query_bus_param(icd);
  289. common_flags = soc_camera_bus_param_compatible(camera_flags,
  290. pcdev->pdata->flags);
  291. if (!common_flags)
  292. return -EINVAL;
  293. ret = icd->ops->set_bus_param(icd, common_flags);
  294. if (ret < 0)
  295. return ret;
  296. switch (common_flags & SOCAM_DATAWIDTH_MASK) {
  297. case SOCAM_DATAWIDTH_8:
  298. buswidth = 8;
  299. break;
  300. case SOCAM_DATAWIDTH_16:
  301. buswidth = 16;
  302. break;
  303. default:
  304. return -EINVAL;
  305. }
  306. ceu_write(pcdev, CRCNTR, 0);
  307. ceu_write(pcdev, CRCMPR, 0);
  308. value = 0x00000010;
  309. value |= (common_flags & SOCAM_VSYNC_ACTIVE_LOW) ? (1 << 1) : 0;
  310. value |= (common_flags & SOCAM_HSYNC_ACTIVE_LOW) ? (1 << 0) : 0;
  311. value |= (buswidth == 16) ? (1 << 12) : 0;
  312. ceu_write(pcdev, CAMCR, value);
  313. ceu_write(pcdev, CAPCR, 0x00300000);
  314. ceu_write(pcdev, CAIFR, 0);
  315. mdelay(1);
  316. width = icd->width * (icd->current_fmt->depth / 8);
  317. width = (buswidth == 16) ? width / 2 : width;
  318. cfszr_width = (buswidth == 8) ? width / 2 : width;
  319. cdwdr_width = (buswidth == 16) ? width * 2 : width;
  320. ceu_write(pcdev, CAMOR, 0);
  321. ceu_write(pcdev, CAPWR, (icd->height << 16) | width);
  322. ceu_write(pcdev, CFLCR, 0); /* data fetch mode - no scaling */
  323. ceu_write(pcdev, CFSZR, (icd->height << 16) | cfszr_width);
  324. ceu_write(pcdev, CLFCR, 0); /* data fetch mode - no lowpass filter */
  325. ceu_write(pcdev, CDOCR, 0x00000016);
  326. ceu_write(pcdev, CDWDR, cdwdr_width);
  327. ceu_write(pcdev, CFWCR, 0); /* keep "datafetch firewall" disabled */
  328. /* not in bundle mode: skip CBDSR, CDAYR2, CDACR2, CDBYR2, CDBCR2 */
  329. /* in data fetch mode: no need for CDACR, CDBYR, CDBCR */
  330. return 0;
  331. }
  332. static int sh_mobile_ceu_try_bus_param(struct soc_camera_device *icd,
  333. __u32 pixfmt)
  334. {
  335. struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
  336. struct sh_mobile_ceu_dev *pcdev = ici->priv;
  337. unsigned long camera_flags, common_flags;
  338. camera_flags = icd->ops->query_bus_param(icd);
  339. common_flags = soc_camera_bus_param_compatible(camera_flags,
  340. pcdev->pdata->flags);
  341. if (!common_flags)
  342. return -EINVAL;
  343. return 0;
  344. }
  345. static int sh_mobile_ceu_set_fmt_cap(struct soc_camera_device *icd,
  346. __u32 pixfmt, struct v4l2_rect *rect)
  347. {
  348. return icd->ops->set_fmt_cap(icd, pixfmt, rect);
  349. }
  350. static int sh_mobile_ceu_try_fmt_cap(struct soc_camera_device *icd,
  351. struct v4l2_format *f)
  352. {
  353. /* FIXME: calculate using depth and bus width */
  354. if (f->fmt.pix.height < 4)
  355. f->fmt.pix.height = 4;
  356. if (f->fmt.pix.height > 1920)
  357. f->fmt.pix.height = 1920;
  358. if (f->fmt.pix.width < 2)
  359. f->fmt.pix.width = 2;
  360. if (f->fmt.pix.width > 2560)
  361. f->fmt.pix.width = 2560;
  362. f->fmt.pix.width &= ~0x01;
  363. f->fmt.pix.height &= ~0x03;
  364. /* limit to sensor capabilities */
  365. return icd->ops->try_fmt_cap(icd, f);
  366. }
  367. static int sh_mobile_ceu_reqbufs(struct soc_camera_file *icf,
  368. struct v4l2_requestbuffers *p)
  369. {
  370. int i;
  371. /* This is for locking debugging only. I removed spinlocks and now I
  372. * check whether .prepare is ever called on a linked buffer, or whether
  373. * a dma IRQ can occur for an in-work or unlinked buffer. Until now
  374. * it hadn't triggered */
  375. for (i = 0; i < p->count; i++) {
  376. struct sh_mobile_ceu_buffer *buf;
  377. buf = container_of(icf->vb_vidq.bufs[i],
  378. struct sh_mobile_ceu_buffer, vb);
  379. INIT_LIST_HEAD(&buf->vb.queue);
  380. }
  381. return 0;
  382. }
  383. static unsigned int sh_mobile_ceu_poll(struct file *file, poll_table *pt)
  384. {
  385. struct soc_camera_file *icf = file->private_data;
  386. struct sh_mobile_ceu_buffer *buf;
  387. buf = list_entry(icf->vb_vidq.stream.next,
  388. struct sh_mobile_ceu_buffer, vb.stream);
  389. poll_wait(file, &buf->vb.done, pt);
  390. if (buf->vb.state == VIDEOBUF_DONE ||
  391. buf->vb.state == VIDEOBUF_ERROR)
  392. return POLLIN|POLLRDNORM;
  393. return 0;
  394. }
  395. static int sh_mobile_ceu_querycap(struct soc_camera_host *ici,
  396. struct v4l2_capability *cap)
  397. {
  398. strlcpy(cap->card, "SuperH_Mobile_CEU", sizeof(cap->card));
  399. cap->version = KERNEL_VERSION(0, 0, 5);
  400. cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
  401. return 0;
  402. }
  403. static void sh_mobile_ceu_init_videobuf(struct videobuf_queue *q,
  404. struct soc_camera_device *icd)
  405. {
  406. struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
  407. struct sh_mobile_ceu_dev *pcdev = ici->priv;
  408. videobuf_queue_dma_contig_init(q,
  409. &sh_mobile_ceu_videobuf_ops,
  410. &ici->dev, &pcdev->lock,
  411. V4L2_BUF_TYPE_VIDEO_CAPTURE,
  412. V4L2_FIELD_NONE,
  413. sizeof(struct sh_mobile_ceu_buffer),
  414. icd);
  415. }
  416. static struct soc_camera_host_ops sh_mobile_ceu_host_ops = {
  417. .owner = THIS_MODULE,
  418. .add = sh_mobile_ceu_add_device,
  419. .remove = sh_mobile_ceu_remove_device,
  420. .set_fmt_cap = sh_mobile_ceu_set_fmt_cap,
  421. .try_fmt_cap = sh_mobile_ceu_try_fmt_cap,
  422. .reqbufs = sh_mobile_ceu_reqbufs,
  423. .poll = sh_mobile_ceu_poll,
  424. .querycap = sh_mobile_ceu_querycap,
  425. .try_bus_param = sh_mobile_ceu_try_bus_param,
  426. .set_bus_param = sh_mobile_ceu_set_bus_param,
  427. .init_videobuf = sh_mobile_ceu_init_videobuf,
  428. };
  429. static int sh_mobile_ceu_probe(struct platform_device *pdev)
  430. {
  431. struct sh_mobile_ceu_dev *pcdev;
  432. struct resource *res;
  433. void __iomem *base;
  434. unsigned int irq;
  435. int err = 0;
  436. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  437. irq = platform_get_irq(pdev, 0);
  438. if (!res || !irq) {
  439. dev_err(&pdev->dev, "Not enough CEU platform resources.\n");
  440. err = -ENODEV;
  441. goto exit;
  442. }
  443. pcdev = kzalloc(sizeof(*pcdev), GFP_KERNEL);
  444. if (!pcdev) {
  445. dev_err(&pdev->dev, "Could not allocate pcdev\n");
  446. err = -ENOMEM;
  447. goto exit;
  448. }
  449. platform_set_drvdata(pdev, pcdev);
  450. INIT_LIST_HEAD(&pcdev->capture);
  451. spin_lock_init(&pcdev->lock);
  452. pcdev->pdata = pdev->dev.platform_data;
  453. if (!pcdev->pdata) {
  454. err = -EINVAL;
  455. dev_err(&pdev->dev, "CEU platform data not set.\n");
  456. goto exit_kfree;
  457. }
  458. base = ioremap_nocache(res->start, res->end - res->start + 1);
  459. if (!base) {
  460. err = -ENXIO;
  461. dev_err(&pdev->dev, "Unable to ioremap CEU registers.\n");
  462. goto exit_kfree;
  463. }
  464. pcdev->irq = irq;
  465. pcdev->base = base;
  466. pcdev->video_limit = 0; /* only enabled if second resource exists */
  467. pcdev->dev = &pdev->dev;
  468. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  469. if (res) {
  470. err = dma_declare_coherent_memory(&pdev->dev, res->start,
  471. res->start,
  472. (res->end - res->start) + 1,
  473. DMA_MEMORY_MAP |
  474. DMA_MEMORY_EXCLUSIVE);
  475. if (!err) {
  476. dev_err(&pdev->dev, "Unable to declare CEU memory.\n");
  477. err = -ENXIO;
  478. goto exit_iounmap;
  479. }
  480. pcdev->video_limit = (res->end - res->start) + 1;
  481. }
  482. /* request irq */
  483. err = request_irq(pcdev->irq, sh_mobile_ceu_irq, IRQF_DISABLED,
  484. pdev->dev.bus_id, pcdev);
  485. if (err) {
  486. dev_err(&pdev->dev, "Unable to register CEU interrupt.\n");
  487. goto exit_release_mem;
  488. }
  489. pcdev->ici.priv = pcdev;
  490. pcdev->ici.dev.parent = &pdev->dev;
  491. pcdev->ici.nr = pdev->id;
  492. pcdev->ici.drv_name = pdev->dev.bus_id,
  493. pcdev->ici.ops = &sh_mobile_ceu_host_ops,
  494. err = soc_camera_host_register(&pcdev->ici);
  495. if (err)
  496. goto exit_free_irq;
  497. return 0;
  498. exit_free_irq:
  499. free_irq(pcdev->irq, pcdev);
  500. exit_release_mem:
  501. if (platform_get_resource(pdev, IORESOURCE_MEM, 1))
  502. dma_release_declared_memory(&pdev->dev);
  503. exit_iounmap:
  504. iounmap(base);
  505. exit_kfree:
  506. kfree(pcdev);
  507. exit:
  508. return err;
  509. }
  510. static int sh_mobile_ceu_remove(struct platform_device *pdev)
  511. {
  512. struct sh_mobile_ceu_dev *pcdev = platform_get_drvdata(pdev);
  513. soc_camera_host_unregister(&pcdev->ici);
  514. free_irq(pcdev->irq, pcdev);
  515. if (platform_get_resource(pdev, IORESOURCE_MEM, 1))
  516. dma_release_declared_memory(&pdev->dev);
  517. iounmap(pcdev->base);
  518. kfree(pcdev);
  519. return 0;
  520. }
  521. static struct platform_driver sh_mobile_ceu_driver = {
  522. .driver = {
  523. .name = "sh_mobile_ceu",
  524. },
  525. .probe = sh_mobile_ceu_probe,
  526. .remove = sh_mobile_ceu_remove,
  527. };
  528. static int __init sh_mobile_ceu_init(void)
  529. {
  530. return platform_driver_register(&sh_mobile_ceu_driver);
  531. }
  532. static void __exit sh_mobile_ceu_exit(void)
  533. {
  534. return platform_driver_unregister(&sh_mobile_ceu_driver);
  535. }
  536. module_init(sh_mobile_ceu_init);
  537. module_exit(sh_mobile_ceu_exit);
  538. MODULE_DESCRIPTION("SuperH Mobile CEU driver");
  539. MODULE_AUTHOR("Magnus Damm");
  540. MODULE_LICENSE("GPL");