sh_mobile_ceu_camera.c 16 KB

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