pxa_camera.c 31 KB

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