pxa_camera.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216
  1. /*
  2. * V4L2 Driver for PXA camera host
  3. *
  4. * Copyright (C) 2006, Sascha Hauer, Pengutronix
  5. * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. */
  12. #include <linux/init.h>
  13. #include <linux/module.h>
  14. #include <linux/io.h>
  15. #include <linux/delay.h>
  16. #include <linux/dma-mapping.h>
  17. #include <linux/errno.h>
  18. #include <linux/fs.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/kernel.h>
  21. #include <linux/mm.h>
  22. #include <linux/moduleparam.h>
  23. #include <linux/time.h>
  24. #include <linux/version.h>
  25. #include <linux/device.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/mutex.h>
  28. #include <linux/clk.h>
  29. #include <media/v4l2-common.h>
  30. #include <media/v4l2-dev.h>
  31. #include <media/videobuf-dma-sg.h>
  32. #include <media/soc_camera.h>
  33. #include <linux/videodev2.h>
  34. #include <asm/dma.h>
  35. #include <asm/arch/pxa-regs.h>
  36. #include <asm/arch/camera.h>
  37. #define PXA_CAM_VERSION_CODE KERNEL_VERSION(0, 0, 5)
  38. #define PXA_CAM_DRV_NAME "pxa27x-camera"
  39. #define CICR0_SIM_MP (0 << 24)
  40. #define CICR0_SIM_SP (1 << 24)
  41. #define CICR0_SIM_MS (2 << 24)
  42. #define CICR0_SIM_EP (3 << 24)
  43. #define CICR0_SIM_ES (4 << 24)
  44. #define CICR1_DW_VAL(x) ((x) & CICR1_DW) /* Data bus width */
  45. #define CICR1_PPL_VAL(x) (((x) << 15) & CICR1_PPL) /* Pixels per line */
  46. #define CICR1_COLOR_SP_VAL(x) (((x) << 3) & CICR1_COLOR_SP) /* color space */
  47. #define CICR1_RGB_BPP_VAL(x) (((x) << 7) & CICR1_RGB_BPP) /* bpp for rgb */
  48. #define CICR1_RGBT_CONV_VAL(x) (((x) << 29) & CICR1_RGBT_CONV) /* rgbt conv */
  49. #define CICR2_BLW_VAL(x) (((x) << 24) & CICR2_BLW) /* Beginning-of-line pixel clock wait count */
  50. #define CICR2_ELW_VAL(x) (((x) << 16) & CICR2_ELW) /* End-of-line pixel clock wait count */
  51. #define CICR2_HSW_VAL(x) (((x) << 10) & CICR2_HSW) /* Horizontal sync pulse width */
  52. #define CICR2_BFPW_VAL(x) (((x) << 3) & CICR2_BFPW) /* Beginning-of-frame pixel clock wait count */
  53. #define CICR2_FSW_VAL(x) (((x) << 0) & CICR2_FSW) /* Frame stabilization wait count */
  54. #define CICR3_BFW_VAL(x) (((x) << 24) & CICR3_BFW) /* Beginning-of-frame line clock wait count */
  55. #define CICR3_EFW_VAL(x) (((x) << 16) & CICR3_EFW) /* End-of-frame line clock wait count */
  56. #define CICR3_VSW_VAL(x) (((x) << 11) & CICR3_VSW) /* Vertical sync pulse width */
  57. #define CICR3_LPF_VAL(x) (((x) << 0) & CICR3_LPF) /* Lines per frame */
  58. #define CICR0_IRQ_MASK (CICR0_TOM | CICR0_RDAVM | CICR0_FEM | CICR0_EOLM | \
  59. CICR0_PERRM | CICR0_QDM | CICR0_CDM | CICR0_SOFM | \
  60. CICR0_EOFM | CICR0_FOM)
  61. static DEFINE_MUTEX(camera_lock);
  62. /*
  63. * Structures
  64. */
  65. enum pxa_camera_active_dma {
  66. DMA_Y = 0x1,
  67. DMA_U = 0x2,
  68. DMA_V = 0x4,
  69. };
  70. /* descriptor needed for the PXA DMA engine */
  71. struct pxa_cam_dma {
  72. dma_addr_t sg_dma;
  73. struct pxa_dma_desc *sg_cpu;
  74. size_t sg_size;
  75. int sglen;
  76. };
  77. /* buffer for one video frame */
  78. struct pxa_buffer {
  79. /* common v4l buffer stuff -- must be first */
  80. struct videobuf_buffer vb;
  81. const struct soc_camera_data_format *fmt;
  82. /* our descriptor lists for Y, U and V channels */
  83. struct pxa_cam_dma dmas[3];
  84. int inwork;
  85. enum pxa_camera_active_dma active_dma;
  86. };
  87. struct pxa_camera_dev {
  88. struct device *dev;
  89. /* PXA27x is only supposed to handle one camera on its Quick Capture
  90. * interface. If anyone ever builds hardware to enable more than
  91. * one camera, they will have to modify this driver too */
  92. struct soc_camera_device *icd;
  93. struct clk *clk;
  94. unsigned int irq;
  95. void __iomem *base;
  96. int channels;
  97. unsigned int dma_chans[3];
  98. struct pxacamera_platform_data *pdata;
  99. struct resource *res;
  100. unsigned long platform_flags;
  101. unsigned long platform_mclk_10khz;
  102. struct list_head capture;
  103. spinlock_t lock;
  104. struct pxa_buffer *active;
  105. struct pxa_dma_desc *sg_tail[3];
  106. };
  107. static const char *pxa_cam_driver_description = "PXA_Camera";
  108. static unsigned int vid_limit = 16; /* Video memory limit, in Mb */
  109. /*
  110. * Videobuf operations
  111. */
  112. static int pxa_videobuf_setup(struct videobuf_queue *vq, unsigned int *count,
  113. unsigned int *size)
  114. {
  115. struct soc_camera_device *icd = vq->priv_data;
  116. struct soc_camera_host *ici =
  117. to_soc_camera_host(icd->dev.parent);
  118. struct pxa_camera_dev *pcdev = ici->priv;
  119. dev_dbg(&icd->dev, "count=%d, size=%d\n", *count, *size);
  120. /* planar capture requires Y, U and V buffers to be page aligned */
  121. if (pcdev->channels == 3) {
  122. *size = PAGE_ALIGN(icd->width * icd->height); /* Y pages */
  123. *size += PAGE_ALIGN(icd->width * icd->height / 2); /* U pages */
  124. *size += PAGE_ALIGN(icd->width * icd->height / 2); /* V pages */
  125. } else {
  126. *size = icd->width * icd->height *
  127. ((icd->current_fmt->depth + 7) >> 3);
  128. }
  129. if (0 == *count)
  130. *count = 32;
  131. while (*size * *count > vid_limit * 1024 * 1024)
  132. (*count)--;
  133. return 0;
  134. }
  135. static void free_buffer(struct videobuf_queue *vq, struct pxa_buffer *buf)
  136. {
  137. struct soc_camera_device *icd = vq->priv_data;
  138. struct soc_camera_host *ici =
  139. to_soc_camera_host(icd->dev.parent);
  140. struct pxa_camera_dev *pcdev = ici->priv;
  141. struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb);
  142. int i;
  143. BUG_ON(in_interrupt());
  144. dev_dbg(&icd->dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
  145. &buf->vb, buf->vb.baddr, buf->vb.bsize);
  146. /* This waits until this buffer is out of danger, i.e., until it is no
  147. * longer in STATE_QUEUED or STATE_ACTIVE */
  148. videobuf_waiton(&buf->vb, 0, 0);
  149. videobuf_dma_unmap(vq, dma);
  150. videobuf_dma_free(dma);
  151. for (i = 0; i < ARRAY_SIZE(buf->dmas); i++) {
  152. if (buf->dmas[i].sg_cpu)
  153. dma_free_coherent(pcdev->dev, buf->dmas[i].sg_size,
  154. buf->dmas[i].sg_cpu,
  155. buf->dmas[i].sg_dma);
  156. buf->dmas[i].sg_cpu = NULL;
  157. }
  158. buf->vb.state = VIDEOBUF_NEEDS_INIT;
  159. }
  160. static int pxa_init_dma_channel(struct pxa_camera_dev *pcdev,
  161. struct pxa_buffer *buf,
  162. struct videobuf_dmabuf *dma, int channel,
  163. int sglen, int sg_start, int cibr,
  164. unsigned int size)
  165. {
  166. struct pxa_cam_dma *pxa_dma = &buf->dmas[channel];
  167. int i;
  168. if (pxa_dma->sg_cpu)
  169. dma_free_coherent(pcdev->dev, pxa_dma->sg_size,
  170. pxa_dma->sg_cpu, pxa_dma->sg_dma);
  171. pxa_dma->sg_size = (sglen + 1) * sizeof(struct pxa_dma_desc);
  172. pxa_dma->sg_cpu = dma_alloc_coherent(pcdev->dev, pxa_dma->sg_size,
  173. &pxa_dma->sg_dma, GFP_KERNEL);
  174. if (!pxa_dma->sg_cpu)
  175. return -ENOMEM;
  176. pxa_dma->sglen = sglen;
  177. for (i = 0; i < sglen; i++) {
  178. int sg_i = sg_start + i;
  179. struct scatterlist *sg = dma->sglist;
  180. unsigned int dma_len = sg_dma_len(&sg[sg_i]), xfer_len;
  181. pxa_dma->sg_cpu[i].dsadr = pcdev->res->start + cibr;
  182. pxa_dma->sg_cpu[i].dtadr = sg_dma_address(&sg[sg_i]);
  183. /* PXA27x Developer's Manual 27.4.4.1: round up to 8 bytes */
  184. xfer_len = (min(dma_len, size) + 7) & ~7;
  185. pxa_dma->sg_cpu[i].dcmd =
  186. DCMD_FLOWSRC | DCMD_BURST8 | DCMD_INCTRGADDR | xfer_len;
  187. size -= dma_len;
  188. pxa_dma->sg_cpu[i].ddadr =
  189. pxa_dma->sg_dma + (i + 1) * sizeof(struct pxa_dma_desc);
  190. }
  191. pxa_dma->sg_cpu[sglen - 1].ddadr = DDADR_STOP;
  192. pxa_dma->sg_cpu[sglen - 1].dcmd |= DCMD_ENDIRQEN;
  193. return 0;
  194. }
  195. static int pxa_videobuf_prepare(struct videobuf_queue *vq,
  196. struct videobuf_buffer *vb, enum v4l2_field field)
  197. {
  198. struct soc_camera_device *icd = vq->priv_data;
  199. struct soc_camera_host *ici =
  200. to_soc_camera_host(icd->dev.parent);
  201. struct pxa_camera_dev *pcdev = ici->priv;
  202. struct pxa_buffer *buf = container_of(vb, struct pxa_buffer, vb);
  203. int ret;
  204. int sglen_y, sglen_yu = 0, sglen_u = 0, sglen_v = 0;
  205. int size_y, size_u = 0, size_v = 0;
  206. dev_dbg(&icd->dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
  207. vb, vb->baddr, vb->bsize);
  208. /* Added list head initialization on alloc */
  209. WARN_ON(!list_empty(&vb->queue));
  210. #ifdef DEBUG
  211. /* This can be useful if you want to see if we actually fill
  212. * the buffer with something */
  213. memset((void *)vb->baddr, 0xaa, vb->bsize);
  214. #endif
  215. BUG_ON(NULL == icd->current_fmt);
  216. /* I think, in buf_prepare you only have to protect global data,
  217. * the actual buffer is yours */
  218. buf->inwork = 1;
  219. if (buf->fmt != icd->current_fmt ||
  220. vb->width != icd->width ||
  221. vb->height != icd->height ||
  222. vb->field != field) {
  223. buf->fmt = icd->current_fmt;
  224. vb->width = icd->width;
  225. vb->height = icd->height;
  226. vb->field = field;
  227. vb->state = VIDEOBUF_NEEDS_INIT;
  228. }
  229. vb->size = vb->width * vb->height * ((buf->fmt->depth + 7) >> 3);
  230. if (0 != vb->baddr && vb->bsize < vb->size) {
  231. ret = -EINVAL;
  232. goto out;
  233. }
  234. if (vb->state == VIDEOBUF_NEEDS_INIT) {
  235. unsigned int size = vb->size;
  236. struct videobuf_dmabuf *dma = videobuf_to_dma(vb);
  237. ret = videobuf_iolock(vq, vb, NULL);
  238. if (ret)
  239. goto fail;
  240. if (pcdev->channels == 3) {
  241. /* FIXME the calculations should be more precise */
  242. sglen_y = dma->sglen / 2;
  243. sglen_u = sglen_v = dma->sglen / 4 + 1;
  244. sglen_yu = sglen_y + sglen_u;
  245. size_y = size / 2;
  246. size_u = size_v = size / 4;
  247. } else {
  248. sglen_y = dma->sglen;
  249. size_y = size;
  250. }
  251. /* init DMA for Y channel */
  252. ret = pxa_init_dma_channel(pcdev, buf, dma, 0, sglen_y,
  253. 0, 0x28, size_y);
  254. if (ret) {
  255. dev_err(pcdev->dev,
  256. "DMA initialization for Y/RGB failed\n");
  257. goto fail;
  258. }
  259. if (pcdev->channels == 3) {
  260. /* init DMA for U channel */
  261. ret = pxa_init_dma_channel(pcdev, buf, dma, 1, sglen_u,
  262. sglen_y, 0x30, size_u);
  263. if (ret) {
  264. dev_err(pcdev->dev,
  265. "DMA initialization for U failed\n");
  266. goto fail_u;
  267. }
  268. /* init DMA for V channel */
  269. ret = pxa_init_dma_channel(pcdev, buf, dma, 2, sglen_v,
  270. sglen_yu, 0x38, size_v);
  271. if (ret) {
  272. dev_err(pcdev->dev,
  273. "DMA initialization for V failed\n");
  274. goto fail_v;
  275. }
  276. }
  277. vb->state = VIDEOBUF_PREPARED;
  278. }
  279. buf->inwork = 0;
  280. buf->active_dma = DMA_Y;
  281. if (pcdev->channels == 3)
  282. buf->active_dma |= DMA_U | DMA_V;
  283. return 0;
  284. fail_v:
  285. dma_free_coherent(pcdev->dev, buf->dmas[1].sg_size,
  286. buf->dmas[1].sg_cpu, buf->dmas[1].sg_dma);
  287. fail_u:
  288. dma_free_coherent(pcdev->dev, buf->dmas[0].sg_size,
  289. buf->dmas[0].sg_cpu, buf->dmas[0].sg_dma);
  290. fail:
  291. free_buffer(vq, buf);
  292. out:
  293. buf->inwork = 0;
  294. return ret;
  295. }
  296. static void pxa_videobuf_queue(struct videobuf_queue *vq,
  297. struct videobuf_buffer *vb)
  298. {
  299. struct soc_camera_device *icd = vq->priv_data;
  300. struct soc_camera_host *ici =
  301. to_soc_camera_host(icd->dev.parent);
  302. struct pxa_camera_dev *pcdev = ici->priv;
  303. struct pxa_buffer *buf = container_of(vb, struct pxa_buffer, vb);
  304. struct pxa_buffer *active;
  305. unsigned long flags;
  306. int i;
  307. dev_dbg(&icd->dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
  308. vb, vb->baddr, vb->bsize);
  309. spin_lock_irqsave(&pcdev->lock, flags);
  310. list_add_tail(&vb->queue, &pcdev->capture);
  311. vb->state = VIDEOBUF_ACTIVE;
  312. active = pcdev->active;
  313. if (!active) {
  314. CIFR |= CIFR_RESET_F;
  315. for (i = 0; i < pcdev->channels; i++) {
  316. DDADR(pcdev->dma_chans[i]) = buf->dmas[i].sg_dma;
  317. DCSR(pcdev->dma_chans[i]) = DCSR_RUN;
  318. pcdev->sg_tail[i] = buf->dmas[i].sg_cpu + buf->dmas[i].sglen - 1;
  319. }
  320. pcdev->active = buf;
  321. CICR0 |= CICR0_ENB;
  322. } else {
  323. struct pxa_cam_dma *buf_dma;
  324. struct pxa_cam_dma *act_dma;
  325. int nents;
  326. for (i = 0; i < pcdev->channels; i++) {
  327. buf_dma = &buf->dmas[i];
  328. act_dma = &active->dmas[i];
  329. nents = buf_dma->sglen;
  330. /* Stop DMA engine */
  331. DCSR(pcdev->dma_chans[i]) = 0;
  332. /* Add the descriptors we just initialized to
  333. the currently running chain */
  334. pcdev->sg_tail[i]->ddadr = buf_dma->sg_dma;
  335. pcdev->sg_tail[i] = buf_dma->sg_cpu + buf_dma->sglen - 1;
  336. /* Setup a dummy descriptor with the DMA engines current
  337. * state
  338. */
  339. buf_dma->sg_cpu[nents].dsadr =
  340. pcdev->res->start + 0x28 + i*8; /* CIBRx */
  341. buf_dma->sg_cpu[nents].dtadr =
  342. DTADR(pcdev->dma_chans[i]);
  343. buf_dma->sg_cpu[nents].dcmd =
  344. DCMD(pcdev->dma_chans[i]);
  345. if (DDADR(pcdev->dma_chans[i]) == DDADR_STOP) {
  346. /* The DMA engine is on the last
  347. descriptor, set the next descriptors
  348. address to the descriptors we just
  349. initialized */
  350. buf_dma->sg_cpu[nents].ddadr = buf_dma->sg_dma;
  351. } else {
  352. buf_dma->sg_cpu[nents].ddadr =
  353. DDADR(pcdev->dma_chans[i]);
  354. }
  355. /* The next descriptor is the dummy descriptor */
  356. DDADR(pcdev->dma_chans[i]) = buf_dma->sg_dma + nents *
  357. sizeof(struct pxa_dma_desc);
  358. DCSR(pcdev->dma_chans[i]) = DCSR_RUN;
  359. }
  360. }
  361. spin_unlock_irqrestore(&pcdev->lock, flags);
  362. }
  363. static void pxa_videobuf_release(struct videobuf_queue *vq,
  364. struct videobuf_buffer *vb)
  365. {
  366. struct pxa_buffer *buf = container_of(vb, struct pxa_buffer, vb);
  367. #ifdef DEBUG
  368. struct soc_camera_device *icd = vq->priv_data;
  369. dev_dbg(&icd->dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
  370. vb, vb->baddr, vb->bsize);
  371. switch (vb->state) {
  372. case VIDEOBUF_ACTIVE:
  373. dev_dbg(&icd->dev, "%s (active)\n", __func__);
  374. break;
  375. case VIDEOBUF_QUEUED:
  376. dev_dbg(&icd->dev, "%s (queued)\n", __func__);
  377. break;
  378. case VIDEOBUF_PREPARED:
  379. dev_dbg(&icd->dev, "%s (prepared)\n", __func__);
  380. break;
  381. default:
  382. dev_dbg(&icd->dev, "%s (unknown)\n", __func__);
  383. break;
  384. }
  385. #endif
  386. free_buffer(vq, buf);
  387. }
  388. static void pxa_camera_wakeup(struct pxa_camera_dev *pcdev,
  389. struct videobuf_buffer *vb,
  390. struct pxa_buffer *buf)
  391. {
  392. /* _init is used to debug races, see comment in pxa_camera_reqbufs() */
  393. list_del_init(&vb->queue);
  394. vb->state = VIDEOBUF_DONE;
  395. do_gettimeofday(&vb->ts);
  396. vb->field_count++;
  397. wake_up(&vb->done);
  398. if (list_empty(&pcdev->capture)) {
  399. pcdev->active = NULL;
  400. DCSR(pcdev->dma_chans[0]) = 0;
  401. DCSR(pcdev->dma_chans[1]) = 0;
  402. DCSR(pcdev->dma_chans[2]) = 0;
  403. CICR0 &= ~CICR0_ENB;
  404. return;
  405. }
  406. pcdev->active = list_entry(pcdev->capture.next,
  407. struct pxa_buffer, vb.queue);
  408. }
  409. static void pxa_camera_dma_irq(int channel, struct pxa_camera_dev *pcdev,
  410. enum pxa_camera_active_dma act_dma)
  411. {
  412. struct pxa_buffer *buf;
  413. unsigned long flags;
  414. u32 status, camera_status, overrun;
  415. struct videobuf_buffer *vb;
  416. spin_lock_irqsave(&pcdev->lock, flags);
  417. status = DCSR(channel);
  418. DCSR(channel) = status | DCSR_ENDINTR;
  419. if (status & DCSR_BUSERR) {
  420. dev_err(pcdev->dev, "DMA Bus Error IRQ!\n");
  421. goto out;
  422. }
  423. if (!(status & DCSR_ENDINTR)) {
  424. dev_err(pcdev->dev, "Unknown DMA IRQ source, "
  425. "status: 0x%08x\n", status);
  426. goto out;
  427. }
  428. if (!pcdev->active) {
  429. dev_err(pcdev->dev, "DMA End IRQ with no active buffer!\n");
  430. goto out;
  431. }
  432. camera_status = CISR;
  433. overrun = CISR_IFO_0;
  434. if (pcdev->channels == 3)
  435. overrun |= CISR_IFO_1 | CISR_IFO_2;
  436. if (camera_status & overrun) {
  437. dev_dbg(pcdev->dev, "FIFO overrun! CISR: %x\n", camera_status);
  438. /* Stop the Capture Interface */
  439. CICR0 &= ~CICR0_ENB;
  440. /* Stop DMA */
  441. DCSR(channel) = 0;
  442. /* Reset the FIFOs */
  443. CIFR |= CIFR_RESET_F;
  444. /* Enable End-Of-Frame Interrupt */
  445. CICR0 &= ~CICR0_EOFM;
  446. /* Restart the Capture Interface */
  447. CICR0 |= CICR0_ENB;
  448. goto out;
  449. }
  450. vb = &pcdev->active->vb;
  451. buf = container_of(vb, struct pxa_buffer, vb);
  452. WARN_ON(buf->inwork || list_empty(&vb->queue));
  453. dev_dbg(pcdev->dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
  454. vb, vb->baddr, vb->bsize);
  455. buf->active_dma &= ~act_dma;
  456. if (!buf->active_dma)
  457. pxa_camera_wakeup(pcdev, vb, buf);
  458. out:
  459. spin_unlock_irqrestore(&pcdev->lock, flags);
  460. }
  461. static void pxa_camera_dma_irq_y(int channel, void *data)
  462. {
  463. struct pxa_camera_dev *pcdev = data;
  464. pxa_camera_dma_irq(channel, pcdev, DMA_Y);
  465. }
  466. static void pxa_camera_dma_irq_u(int channel, void *data)
  467. {
  468. struct pxa_camera_dev *pcdev = data;
  469. pxa_camera_dma_irq(channel, pcdev, DMA_U);
  470. }
  471. static void pxa_camera_dma_irq_v(int channel, void *data)
  472. {
  473. struct pxa_camera_dev *pcdev = data;
  474. pxa_camera_dma_irq(channel, pcdev, DMA_V);
  475. }
  476. static struct videobuf_queue_ops pxa_videobuf_ops = {
  477. .buf_setup = pxa_videobuf_setup,
  478. .buf_prepare = pxa_videobuf_prepare,
  479. .buf_queue = pxa_videobuf_queue,
  480. .buf_release = pxa_videobuf_release,
  481. };
  482. static void pxa_camera_init_videobuf(struct videobuf_queue *q, spinlock_t *lock,
  483. struct soc_camera_device *icd)
  484. {
  485. /* We must pass NULL as dev pointer, then all pci_* dma operations
  486. * transform to normal dma_* ones. */
  487. videobuf_queue_sg_init(q, &pxa_videobuf_ops, NULL, lock,
  488. V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE,
  489. sizeof(struct pxa_buffer), icd);
  490. }
  491. static int mclk_get_divisor(struct pxa_camera_dev *pcdev)
  492. {
  493. unsigned int mclk_10khz = pcdev->platform_mclk_10khz;
  494. unsigned long div;
  495. unsigned long lcdclk;
  496. lcdclk = clk_get_rate(pcdev->clk) / 10000;
  497. /* We verify platform_mclk_10khz != 0, so if anyone breaks it, here
  498. * they get a nice Oops */
  499. div = (lcdclk + 2 * mclk_10khz - 1) / (2 * mclk_10khz) - 1;
  500. dev_dbg(pcdev->dev, "LCD clock %lukHz, target freq %dkHz, "
  501. "divisor %lu\n", lcdclk * 10, mclk_10khz * 10, div);
  502. return div;
  503. }
  504. static void pxa_camera_activate(struct pxa_camera_dev *pcdev)
  505. {
  506. struct pxacamera_platform_data *pdata = pcdev->pdata;
  507. u32 cicr4 = 0;
  508. dev_dbg(pcdev->dev, "Registered platform device at %p data %p\n",
  509. pcdev, pdata);
  510. if (pdata && pdata->init) {
  511. dev_dbg(pcdev->dev, "%s: Init gpios\n", __func__);
  512. pdata->init(pcdev->dev);
  513. }
  514. if (pdata && pdata->power) {
  515. dev_dbg(pcdev->dev, "%s: Power on camera\n", __func__);
  516. pdata->power(pcdev->dev, 1);
  517. }
  518. if (pdata && pdata->reset) {
  519. dev_dbg(pcdev->dev, "%s: Releasing camera reset\n",
  520. __func__);
  521. pdata->reset(pcdev->dev, 1);
  522. }
  523. CICR0 = 0x3FF; /* disable all interrupts */
  524. if (pcdev->platform_flags & PXA_CAMERA_PCLK_EN)
  525. cicr4 |= CICR4_PCLK_EN;
  526. if (pcdev->platform_flags & PXA_CAMERA_MCLK_EN)
  527. cicr4 |= CICR4_MCLK_EN;
  528. if (pcdev->platform_flags & PXA_CAMERA_PCP)
  529. cicr4 |= CICR4_PCP;
  530. if (pcdev->platform_flags & PXA_CAMERA_HSP)
  531. cicr4 |= CICR4_HSP;
  532. if (pcdev->platform_flags & PXA_CAMERA_VSP)
  533. cicr4 |= CICR4_VSP;
  534. CICR4 = mclk_get_divisor(pcdev) | cicr4;
  535. clk_enable(pcdev->clk);
  536. }
  537. static void pxa_camera_deactivate(struct pxa_camera_dev *pcdev)
  538. {
  539. struct pxacamera_platform_data *board = pcdev->pdata;
  540. clk_disable(pcdev->clk);
  541. if (board && board->reset) {
  542. dev_dbg(pcdev->dev, "%s: Asserting camera reset\n",
  543. __func__);
  544. board->reset(pcdev->dev, 0);
  545. }
  546. if (board && board->power) {
  547. dev_dbg(pcdev->dev, "%s: Power off camera\n", __func__);
  548. board->power(pcdev->dev, 0);
  549. }
  550. }
  551. static irqreturn_t pxa_camera_irq(int irq, void *data)
  552. {
  553. struct pxa_camera_dev *pcdev = data;
  554. unsigned int status = CISR;
  555. dev_dbg(pcdev->dev, "Camera interrupt status 0x%x\n", status);
  556. if (!status)
  557. return IRQ_NONE;
  558. CISR = status;
  559. if (status & CISR_EOF) {
  560. int i;
  561. for (i = 0; i < pcdev->channels; i++) {
  562. DDADR(pcdev->dma_chans[i]) =
  563. pcdev->active->dmas[i].sg_dma;
  564. DCSR(pcdev->dma_chans[i]) = DCSR_RUN;
  565. }
  566. CICR0 |= CICR0_EOFM;
  567. }
  568. return IRQ_HANDLED;
  569. }
  570. /* The following two functions absolutely depend on the fact, that
  571. * there can be only one camera on PXA quick capture interface */
  572. static int pxa_camera_add_device(struct soc_camera_device *icd)
  573. {
  574. struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
  575. struct pxa_camera_dev *pcdev = ici->priv;
  576. int ret;
  577. mutex_lock(&camera_lock);
  578. if (pcdev->icd) {
  579. ret = -EBUSY;
  580. goto ebusy;
  581. }
  582. dev_info(&icd->dev, "PXA Camera driver attached to camera %d\n",
  583. icd->devnum);
  584. pxa_camera_activate(pcdev);
  585. ret = icd->ops->init(icd);
  586. if (!ret)
  587. pcdev->icd = icd;
  588. ebusy:
  589. mutex_unlock(&camera_lock);
  590. return ret;
  591. }
  592. static void pxa_camera_remove_device(struct soc_camera_device *icd)
  593. {
  594. struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
  595. struct pxa_camera_dev *pcdev = ici->priv;
  596. BUG_ON(icd != pcdev->icd);
  597. dev_info(&icd->dev, "PXA Camera driver detached from camera %d\n",
  598. icd->devnum);
  599. /* disable capture, disable interrupts */
  600. CICR0 = 0x3ff;
  601. /* Stop DMA engine */
  602. DCSR(pcdev->dma_chans[0]) = 0;
  603. DCSR(pcdev->dma_chans[1]) = 0;
  604. DCSR(pcdev->dma_chans[2]) = 0;
  605. icd->ops->release(icd);
  606. pxa_camera_deactivate(pcdev);
  607. pcdev->icd = NULL;
  608. }
  609. static int test_platform_param(struct pxa_camera_dev *pcdev,
  610. unsigned char buswidth, unsigned long *flags)
  611. {
  612. /*
  613. * Platform specified synchronization and pixel clock polarities are
  614. * only a recommendation and are only used during probing. The PXA270
  615. * quick capture interface supports both.
  616. */
  617. *flags = (pcdev->platform_flags & PXA_CAMERA_MASTER ?
  618. SOCAM_MASTER : SOCAM_SLAVE) |
  619. SOCAM_HSYNC_ACTIVE_HIGH |
  620. SOCAM_HSYNC_ACTIVE_LOW |
  621. SOCAM_VSYNC_ACTIVE_HIGH |
  622. SOCAM_VSYNC_ACTIVE_LOW |
  623. SOCAM_PCLK_SAMPLE_RISING |
  624. SOCAM_PCLK_SAMPLE_FALLING;
  625. /* If requested data width is supported by the platform, use it */
  626. switch (buswidth) {
  627. case 10:
  628. if (!(pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_10))
  629. return -EINVAL;
  630. *flags |= SOCAM_DATAWIDTH_10;
  631. break;
  632. case 9:
  633. if (!(pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_9))
  634. return -EINVAL;
  635. *flags |= SOCAM_DATAWIDTH_9;
  636. break;
  637. case 8:
  638. if (!(pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_8))
  639. return -EINVAL;
  640. *flags |= SOCAM_DATAWIDTH_8;
  641. }
  642. return 0;
  643. }
  644. static int pxa_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt)
  645. {
  646. struct soc_camera_host *ici =
  647. to_soc_camera_host(icd->dev.parent);
  648. struct pxa_camera_dev *pcdev = ici->priv;
  649. unsigned long dw, bpp, bus_flags, camera_flags, common_flags;
  650. u32 cicr0, cicr1, cicr4 = 0;
  651. int ret = test_platform_param(pcdev, icd->buswidth, &bus_flags);
  652. if (ret < 0)
  653. return ret;
  654. camera_flags = icd->ops->query_bus_param(icd);
  655. common_flags = soc_camera_bus_param_compatible(camera_flags, bus_flags);
  656. if (!common_flags)
  657. return -EINVAL;
  658. pcdev->channels = 1;
  659. /* Make choises, based on platform preferences */
  660. if ((common_flags & SOCAM_HSYNC_ACTIVE_HIGH) &&
  661. (common_flags & SOCAM_HSYNC_ACTIVE_LOW)) {
  662. if (pcdev->platform_flags & PXA_CAMERA_HSP)
  663. common_flags &= ~SOCAM_HSYNC_ACTIVE_HIGH;
  664. else
  665. common_flags &= ~SOCAM_HSYNC_ACTIVE_LOW;
  666. }
  667. if ((common_flags & SOCAM_VSYNC_ACTIVE_HIGH) &&
  668. (common_flags & SOCAM_VSYNC_ACTIVE_LOW)) {
  669. if (pcdev->platform_flags & PXA_CAMERA_VSP)
  670. common_flags &= ~SOCAM_VSYNC_ACTIVE_HIGH;
  671. else
  672. common_flags &= ~SOCAM_VSYNC_ACTIVE_LOW;
  673. }
  674. if ((common_flags & SOCAM_PCLK_SAMPLE_RISING) &&
  675. (common_flags & SOCAM_PCLK_SAMPLE_FALLING)) {
  676. if (pcdev->platform_flags & PXA_CAMERA_PCP)
  677. common_flags &= ~SOCAM_PCLK_SAMPLE_RISING;
  678. else
  679. common_flags &= ~SOCAM_PCLK_SAMPLE_FALLING;
  680. }
  681. ret = icd->ops->set_bus_param(icd, common_flags);
  682. if (ret < 0)
  683. return ret;
  684. /* Datawidth is now guaranteed to be equal to one of the three values.
  685. * We fix bit-per-pixel equal to data-width... */
  686. switch (common_flags & SOCAM_DATAWIDTH_MASK) {
  687. case SOCAM_DATAWIDTH_10:
  688. icd->buswidth = 10;
  689. dw = 4;
  690. bpp = 0x40;
  691. break;
  692. case SOCAM_DATAWIDTH_9:
  693. icd->buswidth = 9;
  694. dw = 3;
  695. bpp = 0x20;
  696. break;
  697. default:
  698. /* Actually it can only be 8 now,
  699. * default is just to silence compiler warnings */
  700. case SOCAM_DATAWIDTH_8:
  701. icd->buswidth = 8;
  702. dw = 2;
  703. bpp = 0;
  704. }
  705. if (pcdev->platform_flags & PXA_CAMERA_PCLK_EN)
  706. cicr4 |= CICR4_PCLK_EN;
  707. if (pcdev->platform_flags & PXA_CAMERA_MCLK_EN)
  708. cicr4 |= CICR4_MCLK_EN;
  709. if (common_flags & SOCAM_PCLK_SAMPLE_FALLING)
  710. cicr4 |= CICR4_PCP;
  711. if (common_flags & SOCAM_HSYNC_ACTIVE_LOW)
  712. cicr4 |= CICR4_HSP;
  713. if (common_flags & SOCAM_VSYNC_ACTIVE_LOW)
  714. cicr4 |= CICR4_VSP;
  715. cicr0 = CICR0;
  716. if (cicr0 & CICR0_ENB)
  717. CICR0 = cicr0 & ~CICR0_ENB;
  718. cicr1 = CICR1_PPL_VAL(icd->width - 1) | bpp | dw;
  719. switch (pixfmt) {
  720. case V4L2_PIX_FMT_YUV422P:
  721. pcdev->channels = 3;
  722. cicr1 |= CICR1_YCBCR_F;
  723. case V4L2_PIX_FMT_YUYV:
  724. cicr1 |= CICR1_COLOR_SP_VAL(2);
  725. break;
  726. case V4L2_PIX_FMT_RGB555:
  727. cicr1 |= CICR1_RGB_BPP_VAL(1) | CICR1_RGBT_CONV_VAL(2) |
  728. CICR1_TBIT | CICR1_COLOR_SP_VAL(1);
  729. break;
  730. case V4L2_PIX_FMT_RGB565:
  731. cicr1 |= CICR1_COLOR_SP_VAL(1) | CICR1_RGB_BPP_VAL(2);
  732. break;
  733. }
  734. CICR1 = cicr1;
  735. CICR2 = 0;
  736. CICR3 = CICR3_LPF_VAL(icd->height - 1) |
  737. CICR3_BFW_VAL(min((unsigned short)255, icd->y_skip_top));
  738. CICR4 = mclk_get_divisor(pcdev) | cicr4;
  739. /* CIF interrupts are not used, only DMA */
  740. CICR0 = (pcdev->platform_flags & PXA_CAMERA_MASTER ?
  741. CICR0_SIM_MP : (CICR0_SL_CAP_EN | CICR0_SIM_SP)) |
  742. CICR0_DMAEN | CICR0_IRQ_MASK | (cicr0 & CICR0_ENB);
  743. return 0;
  744. }
  745. static int pxa_camera_try_bus_param(struct soc_camera_device *icd, __u32 pixfmt)
  746. {
  747. struct soc_camera_host *ici =
  748. to_soc_camera_host(icd->dev.parent);
  749. struct pxa_camera_dev *pcdev = ici->priv;
  750. unsigned long bus_flags, camera_flags;
  751. int ret = test_platform_param(pcdev, icd->buswidth, &bus_flags);
  752. if (ret < 0)
  753. return ret;
  754. camera_flags = icd->ops->query_bus_param(icd);
  755. return soc_camera_bus_param_compatible(camera_flags, bus_flags) ? 0 : -EINVAL;
  756. }
  757. static int pxa_camera_set_fmt_cap(struct soc_camera_device *icd,
  758. __u32 pixfmt, struct v4l2_rect *rect)
  759. {
  760. return icd->ops->set_fmt_cap(icd, pixfmt, rect);
  761. }
  762. static int pxa_camera_try_fmt_cap(struct soc_camera_device *icd,
  763. struct v4l2_format *f)
  764. {
  765. /* limit to pxa hardware capabilities */
  766. if (f->fmt.pix.height < 32)
  767. f->fmt.pix.height = 32;
  768. if (f->fmt.pix.height > 2048)
  769. f->fmt.pix.height = 2048;
  770. if (f->fmt.pix.width < 48)
  771. f->fmt.pix.width = 48;
  772. if (f->fmt.pix.width > 2048)
  773. f->fmt.pix.width = 2048;
  774. f->fmt.pix.width &= ~0x01;
  775. /* limit to sensor capabilities */
  776. return icd->ops->try_fmt_cap(icd, f);
  777. }
  778. static int pxa_camera_reqbufs(struct soc_camera_file *icf,
  779. struct v4l2_requestbuffers *p)
  780. {
  781. int i;
  782. /* This is for locking debugging only. I removed spinlocks and now I
  783. * check whether .prepare is ever called on a linked buffer, or whether
  784. * a dma IRQ can occur for an in-work or unlinked buffer. Until now
  785. * it hadn't triggered */
  786. for (i = 0; i < p->count; i++) {
  787. struct pxa_buffer *buf = container_of(icf->vb_vidq.bufs[i],
  788. struct pxa_buffer, vb);
  789. buf->inwork = 0;
  790. INIT_LIST_HEAD(&buf->vb.queue);
  791. }
  792. return 0;
  793. }
  794. static unsigned int pxa_camera_poll(struct file *file, poll_table *pt)
  795. {
  796. struct soc_camera_file *icf = file->private_data;
  797. struct pxa_buffer *buf;
  798. buf = list_entry(icf->vb_vidq.stream.next, struct pxa_buffer,
  799. vb.stream);
  800. poll_wait(file, &buf->vb.done, pt);
  801. if (buf->vb.state == VIDEOBUF_DONE ||
  802. buf->vb.state == VIDEOBUF_ERROR)
  803. return POLLIN|POLLRDNORM;
  804. return 0;
  805. }
  806. static int pxa_camera_querycap(struct soc_camera_host *ici,
  807. struct v4l2_capability *cap)
  808. {
  809. /* cap->name is set by the firendly caller:-> */
  810. strlcpy(cap->card, pxa_cam_driver_description, sizeof(cap->card));
  811. cap->version = PXA_CAM_VERSION_CODE;
  812. cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
  813. return 0;
  814. }
  815. static spinlock_t *pxa_camera_spinlock_alloc(struct soc_camera_file *icf)
  816. {
  817. struct soc_camera_host *ici =
  818. to_soc_camera_host(icf->icd->dev.parent);
  819. struct pxa_camera_dev *pcdev = ici->priv;
  820. return &pcdev->lock;
  821. }
  822. static struct soc_camera_host_ops pxa_soc_camera_host_ops = {
  823. .owner = THIS_MODULE,
  824. .add = pxa_camera_add_device,
  825. .remove = pxa_camera_remove_device,
  826. .set_fmt_cap = pxa_camera_set_fmt_cap,
  827. .try_fmt_cap = pxa_camera_try_fmt_cap,
  828. .init_videobuf = pxa_camera_init_videobuf,
  829. .reqbufs = pxa_camera_reqbufs,
  830. .poll = pxa_camera_poll,
  831. .querycap = pxa_camera_querycap,
  832. .try_bus_param = pxa_camera_try_bus_param,
  833. .set_bus_param = pxa_camera_set_bus_param,
  834. .spinlock_alloc = pxa_camera_spinlock_alloc,
  835. };
  836. /* Should be allocated dynamically too, but we have only one. */
  837. static struct soc_camera_host pxa_soc_camera_host = {
  838. .drv_name = PXA_CAM_DRV_NAME,
  839. .ops = &pxa_soc_camera_host_ops,
  840. };
  841. static int pxa_camera_probe(struct platform_device *pdev)
  842. {
  843. struct pxa_camera_dev *pcdev;
  844. struct resource *res;
  845. void __iomem *base;
  846. int irq;
  847. int err = 0;
  848. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  849. irq = platform_get_irq(pdev, 0);
  850. if (!res || irq < 0) {
  851. err = -ENODEV;
  852. goto exit;
  853. }
  854. pcdev = kzalloc(sizeof(*pcdev), GFP_KERNEL);
  855. if (!pcdev) {
  856. dev_err(&pdev->dev, "Could not allocate pcdev\n");
  857. err = -ENOMEM;
  858. goto exit;
  859. }
  860. pcdev->clk = clk_get(&pdev->dev, "CAMCLK");
  861. if (IS_ERR(pcdev->clk)) {
  862. err = PTR_ERR(pcdev->clk);
  863. goto exit_kfree;
  864. }
  865. dev_set_drvdata(&pdev->dev, pcdev);
  866. pcdev->res = res;
  867. pcdev->pdata = pdev->dev.platform_data;
  868. pcdev->platform_flags = pcdev->pdata->flags;
  869. if (!(pcdev->platform_flags & (PXA_CAMERA_DATAWIDTH_8 |
  870. PXA_CAMERA_DATAWIDTH_9 | PXA_CAMERA_DATAWIDTH_10))) {
  871. /* Platform hasn't set available data widths. This is bad.
  872. * Warn and use a default. */
  873. dev_warn(&pdev->dev, "WARNING! Platform hasn't set available "
  874. "data widths, using default 10 bit\n");
  875. pcdev->platform_flags |= PXA_CAMERA_DATAWIDTH_10;
  876. }
  877. pcdev->platform_mclk_10khz = pcdev->pdata->mclk_10khz;
  878. if (!pcdev->platform_mclk_10khz) {
  879. dev_warn(&pdev->dev,
  880. "mclk_10khz == 0! Please, fix your platform data. "
  881. "Using default 20MHz\n");
  882. pcdev->platform_mclk_10khz = 2000;
  883. }
  884. INIT_LIST_HEAD(&pcdev->capture);
  885. spin_lock_init(&pcdev->lock);
  886. /*
  887. * Request the regions.
  888. */
  889. if (!request_mem_region(res->start, res->end - res->start + 1,
  890. PXA_CAM_DRV_NAME)) {
  891. err = -EBUSY;
  892. goto exit_clk;
  893. }
  894. base = ioremap(res->start, res->end - res->start + 1);
  895. if (!base) {
  896. err = -ENOMEM;
  897. goto exit_release;
  898. }
  899. pcdev->irq = irq;
  900. pcdev->base = base;
  901. pcdev->dev = &pdev->dev;
  902. /* request dma */
  903. pcdev->dma_chans[0] = pxa_request_dma("CI_Y", DMA_PRIO_HIGH,
  904. pxa_camera_dma_irq_y, pcdev);
  905. if (pcdev->dma_chans[0] < 0) {
  906. dev_err(pcdev->dev, "Can't request DMA for Y\n");
  907. err = -ENOMEM;
  908. goto exit_iounmap;
  909. }
  910. dev_dbg(pcdev->dev, "got DMA channel %d\n", pcdev->dma_chans[0]);
  911. pcdev->dma_chans[1] = pxa_request_dma("CI_U", DMA_PRIO_HIGH,
  912. pxa_camera_dma_irq_u, pcdev);
  913. if (pcdev->dma_chans[1] < 0) {
  914. dev_err(pcdev->dev, "Can't request DMA for U\n");
  915. err = -ENOMEM;
  916. goto exit_free_dma_y;
  917. }
  918. dev_dbg(pcdev->dev, "got DMA channel (U) %d\n", pcdev->dma_chans[1]);
  919. pcdev->dma_chans[2] = pxa_request_dma("CI_V", DMA_PRIO_HIGH,
  920. pxa_camera_dma_irq_v, pcdev);
  921. if (pcdev->dma_chans[0] < 0) {
  922. dev_err(pcdev->dev, "Can't request DMA for V\n");
  923. err = -ENOMEM;
  924. goto exit_free_dma_u;
  925. }
  926. dev_dbg(pcdev->dev, "got DMA channel (V) %d\n", pcdev->dma_chans[2]);
  927. DRCMR68 = pcdev->dma_chans[0] | DRCMR_MAPVLD;
  928. DRCMR69 = pcdev->dma_chans[1] | DRCMR_MAPVLD;
  929. DRCMR70 = pcdev->dma_chans[2] | DRCMR_MAPVLD;
  930. /* request irq */
  931. err = request_irq(pcdev->irq, pxa_camera_irq, 0, PXA_CAM_DRV_NAME,
  932. pcdev);
  933. if (err) {
  934. dev_err(pcdev->dev, "Camera interrupt register failed \n");
  935. goto exit_free_dma;
  936. }
  937. pxa_soc_camera_host.priv = pcdev;
  938. pxa_soc_camera_host.dev.parent = &pdev->dev;
  939. pxa_soc_camera_host.nr = pdev->id;
  940. err = soc_camera_host_register(&pxa_soc_camera_host);
  941. if (err)
  942. goto exit_free_irq;
  943. return 0;
  944. exit_free_irq:
  945. free_irq(pcdev->irq, pcdev);
  946. exit_free_dma:
  947. pxa_free_dma(pcdev->dma_chans[2]);
  948. exit_free_dma_u:
  949. pxa_free_dma(pcdev->dma_chans[1]);
  950. exit_free_dma_y:
  951. pxa_free_dma(pcdev->dma_chans[0]);
  952. exit_iounmap:
  953. iounmap(base);
  954. exit_release:
  955. release_mem_region(res->start, res->end - res->start + 1);
  956. exit_clk:
  957. clk_put(pcdev->clk);
  958. exit_kfree:
  959. kfree(pcdev);
  960. exit:
  961. return err;
  962. }
  963. static int __devexit pxa_camera_remove(struct platform_device *pdev)
  964. {
  965. struct pxa_camera_dev *pcdev = platform_get_drvdata(pdev);
  966. struct resource *res;
  967. clk_put(pcdev->clk);
  968. pxa_free_dma(pcdev->dma_chans[0]);
  969. pxa_free_dma(pcdev->dma_chans[1]);
  970. pxa_free_dma(pcdev->dma_chans[2]);
  971. free_irq(pcdev->irq, pcdev);
  972. soc_camera_host_unregister(&pxa_soc_camera_host);
  973. iounmap(pcdev->base);
  974. res = pcdev->res;
  975. release_mem_region(res->start, res->end - res->start + 1);
  976. kfree(pcdev);
  977. dev_info(&pdev->dev, "PXA Camera driver unloaded\n");
  978. return 0;
  979. }
  980. static struct platform_driver pxa_camera_driver = {
  981. .driver = {
  982. .name = PXA_CAM_DRV_NAME,
  983. },
  984. .probe = pxa_camera_probe,
  985. .remove = __exit_p(pxa_camera_remove),
  986. };
  987. static int __devinit pxa_camera_init(void)
  988. {
  989. return platform_driver_register(&pxa_camera_driver);
  990. }
  991. static void __exit pxa_camera_exit(void)
  992. {
  993. return platform_driver_unregister(&pxa_camera_driver);
  994. }
  995. module_init(pxa_camera_init);
  996. module_exit(pxa_camera_exit);
  997. MODULE_DESCRIPTION("PXA27x SoC Camera Host driver");
  998. MODULE_AUTHOR("Guennadi Liakhovetski <kernel@pengutronix.de>");
  999. MODULE_LICENSE("GPL");