omap1_camera.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738
  1. /*
  2. * V4L2 SoC Camera driver for OMAP1 Camera Interface
  3. *
  4. * Copyright (C) 2010, Janusz Krzysztofik <jkrzyszt@tis.icnet.pl>
  5. *
  6. * Based on V4L2 Driver for i.MXL/i.MXL camera (CSI) host
  7. * Copyright (C) 2008, Paulius Zaleckas <paulius.zaleckas@teltonika.lt>
  8. * Copyright (C) 2009, Darius Augulis <augulis.darius@gmail.com>
  9. *
  10. * Based on PXA SoC camera driver
  11. * Copyright (C) 2006, Sascha Hauer, Pengutronix
  12. * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
  13. *
  14. * Hardware specific bits initialy based on former work by Matt Callow
  15. * drivers/media/platform/omap/omap1510cam.c
  16. * Copyright (C) 2006 Matt Callow
  17. *
  18. * This program is free software; you can redistribute it and/or modify
  19. * it under the terms of the GNU General Public License version 2 as
  20. * published by the Free Software Foundation.
  21. */
  22. #include <linux/clk.h>
  23. #include <linux/dma-mapping.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/module.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/slab.h>
  28. #include <media/omap1_camera.h>
  29. #include <media/soc_camera.h>
  30. #include <media/soc_mediabus.h>
  31. #include <media/videobuf-dma-contig.h>
  32. #include <media/videobuf-dma-sg.h>
  33. #include <linux/omap-dma.h>
  34. #define DRIVER_NAME "omap1-camera"
  35. #define DRIVER_VERSION "0.0.2"
  36. #define OMAP_DMA_CAMERA_IF_RX 20
  37. /*
  38. * ---------------------------------------------------------------------------
  39. * OMAP1 Camera Interface registers
  40. * ---------------------------------------------------------------------------
  41. */
  42. #define REG_CTRLCLOCK 0x00
  43. #define REG_IT_STATUS 0x04
  44. #define REG_MODE 0x08
  45. #define REG_STATUS 0x0C
  46. #define REG_CAMDATA 0x10
  47. #define REG_GPIO 0x14
  48. #define REG_PEAK_COUNTER 0x18
  49. /* CTRLCLOCK bit shifts */
  50. #define LCLK_EN BIT(7)
  51. #define DPLL_EN BIT(6)
  52. #define MCLK_EN BIT(5)
  53. #define CAMEXCLK_EN BIT(4)
  54. #define POLCLK BIT(3)
  55. #define FOSCMOD_SHIFT 0
  56. #define FOSCMOD_MASK (0x7 << FOSCMOD_SHIFT)
  57. #define FOSCMOD_12MHz 0x0
  58. #define FOSCMOD_6MHz 0x2
  59. #define FOSCMOD_9_6MHz 0x4
  60. #define FOSCMOD_24MHz 0x5
  61. #define FOSCMOD_8MHz 0x6
  62. /* IT_STATUS bit shifts */
  63. #define DATA_TRANSFER BIT(5)
  64. #define FIFO_FULL BIT(4)
  65. #define H_DOWN BIT(3)
  66. #define H_UP BIT(2)
  67. #define V_DOWN BIT(1)
  68. #define V_UP BIT(0)
  69. /* MODE bit shifts */
  70. #define RAZ_FIFO BIT(18)
  71. #define EN_FIFO_FULL BIT(17)
  72. #define EN_NIRQ BIT(16)
  73. #define THRESHOLD_SHIFT 9
  74. #define THRESHOLD_MASK (0x7f << THRESHOLD_SHIFT)
  75. #define DMA BIT(8)
  76. #define EN_H_DOWN BIT(7)
  77. #define EN_H_UP BIT(6)
  78. #define EN_V_DOWN BIT(5)
  79. #define EN_V_UP BIT(4)
  80. #define ORDERCAMD BIT(3)
  81. #define IRQ_MASK (EN_V_UP | EN_V_DOWN | EN_H_UP | EN_H_DOWN | \
  82. EN_NIRQ | EN_FIFO_FULL)
  83. /* STATUS bit shifts */
  84. #define HSTATUS BIT(1)
  85. #define VSTATUS BIT(0)
  86. /* GPIO bit shifts */
  87. #define CAM_RST BIT(0)
  88. /* end of OMAP1 Camera Interface registers */
  89. #define SOCAM_BUS_FLAGS (V4L2_MBUS_MASTER | \
  90. V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_HIGH | \
  91. V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING | \
  92. V4L2_MBUS_DATA_ACTIVE_HIGH)
  93. #define FIFO_SIZE ((THRESHOLD_MASK >> THRESHOLD_SHIFT) + 1)
  94. #define FIFO_SHIFT __fls(FIFO_SIZE)
  95. #define DMA_BURST_SHIFT (1 + OMAP_DMA_DATA_BURST_4)
  96. #define DMA_BURST_SIZE (1 << DMA_BURST_SHIFT)
  97. #define DMA_ELEMENT_SHIFT OMAP_DMA_DATA_TYPE_S32
  98. #define DMA_ELEMENT_SIZE (1 << DMA_ELEMENT_SHIFT)
  99. #define DMA_FRAME_SHIFT_CONTIG (FIFO_SHIFT - 1)
  100. #define DMA_FRAME_SHIFT_SG DMA_BURST_SHIFT
  101. #define DMA_FRAME_SHIFT(x) ((x) == OMAP1_CAM_DMA_CONTIG ? \
  102. DMA_FRAME_SHIFT_CONTIG : \
  103. DMA_FRAME_SHIFT_SG)
  104. #define DMA_FRAME_SIZE(x) (1 << DMA_FRAME_SHIFT(x))
  105. #define DMA_SYNC OMAP_DMA_SYNC_FRAME
  106. #define THRESHOLD_LEVEL DMA_FRAME_SIZE
  107. #define MAX_VIDEO_MEM 4 /* arbitrary video memory limit in MB */
  108. /*
  109. * Structures
  110. */
  111. /* buffer for one video frame */
  112. struct omap1_cam_buf {
  113. struct videobuf_buffer vb;
  114. u32 code;
  115. int inwork;
  116. struct scatterlist *sgbuf;
  117. int sgcount;
  118. int bytes_left;
  119. enum videobuf_state result;
  120. };
  121. struct omap1_cam_dev {
  122. struct soc_camera_host soc_host;
  123. struct clk *clk;
  124. unsigned int irq;
  125. void __iomem *base;
  126. int dma_ch;
  127. struct omap1_cam_platform_data *pdata;
  128. struct resource *res;
  129. unsigned long pflags;
  130. unsigned long camexclk;
  131. struct list_head capture;
  132. /* lock used to protect videobuf */
  133. spinlock_t lock;
  134. /* Pointers to DMA buffers */
  135. struct omap1_cam_buf *active;
  136. struct omap1_cam_buf *ready;
  137. enum omap1_cam_vb_mode vb_mode;
  138. int (*mmap_mapper)(struct videobuf_queue *q,
  139. struct videobuf_buffer *buf,
  140. struct vm_area_struct *vma);
  141. u32 reg_cache[0];
  142. };
  143. static void cam_write(struct omap1_cam_dev *pcdev, u16 reg, u32 val)
  144. {
  145. pcdev->reg_cache[reg / sizeof(u32)] = val;
  146. __raw_writel(val, pcdev->base + reg);
  147. }
  148. static u32 cam_read(struct omap1_cam_dev *pcdev, u16 reg, bool from_cache)
  149. {
  150. return !from_cache ? __raw_readl(pcdev->base + reg) :
  151. pcdev->reg_cache[reg / sizeof(u32)];
  152. }
  153. #define CAM_READ(pcdev, reg) \
  154. cam_read(pcdev, REG_##reg, false)
  155. #define CAM_WRITE(pcdev, reg, val) \
  156. cam_write(pcdev, REG_##reg, val)
  157. #define CAM_READ_CACHE(pcdev, reg) \
  158. cam_read(pcdev, REG_##reg, true)
  159. /*
  160. * Videobuf operations
  161. */
  162. static int omap1_videobuf_setup(struct videobuf_queue *vq, unsigned int *count,
  163. unsigned int *size)
  164. {
  165. struct soc_camera_device *icd = vq->priv_data;
  166. struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
  167. struct omap1_cam_dev *pcdev = ici->priv;
  168. *size = icd->sizeimage;
  169. if (!*count || *count < OMAP1_CAMERA_MIN_BUF_COUNT(pcdev->vb_mode))
  170. *count = OMAP1_CAMERA_MIN_BUF_COUNT(pcdev->vb_mode);
  171. if (*size * *count > MAX_VIDEO_MEM * 1024 * 1024)
  172. *count = (MAX_VIDEO_MEM * 1024 * 1024) / *size;
  173. dev_dbg(icd->parent,
  174. "%s: count=%d, size=%d\n", __func__, *count, *size);
  175. return 0;
  176. }
  177. static void free_buffer(struct videobuf_queue *vq, struct omap1_cam_buf *buf,
  178. enum omap1_cam_vb_mode vb_mode)
  179. {
  180. struct videobuf_buffer *vb = &buf->vb;
  181. BUG_ON(in_interrupt());
  182. videobuf_waiton(vq, vb, 0, 0);
  183. if (vb_mode == OMAP1_CAM_DMA_CONTIG) {
  184. videobuf_dma_contig_free(vq, vb);
  185. } else {
  186. struct soc_camera_device *icd = vq->priv_data;
  187. struct device *dev = icd->parent;
  188. struct videobuf_dmabuf *dma = videobuf_to_dma(vb);
  189. videobuf_dma_unmap(dev, dma);
  190. videobuf_dma_free(dma);
  191. }
  192. vb->state = VIDEOBUF_NEEDS_INIT;
  193. }
  194. static int omap1_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 omap1_cam_buf *buf = container_of(vb, struct omap1_cam_buf, vb);
  199. struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
  200. struct omap1_cam_dev *pcdev = ici->priv;
  201. int ret;
  202. WARN_ON(!list_empty(&vb->queue));
  203. BUG_ON(NULL == icd->current_fmt);
  204. buf->inwork = 1;
  205. if (buf->code != icd->current_fmt->code || vb->field != field ||
  206. vb->width != icd->user_width ||
  207. vb->height != icd->user_height) {
  208. buf->code = icd->current_fmt->code;
  209. vb->width = icd->user_width;
  210. vb->height = icd->user_height;
  211. vb->field = field;
  212. vb->state = VIDEOBUF_NEEDS_INIT;
  213. }
  214. vb->size = icd->sizeimage;
  215. if (vb->baddr && vb->bsize < vb->size) {
  216. ret = -EINVAL;
  217. goto out;
  218. }
  219. if (vb->state == VIDEOBUF_NEEDS_INIT) {
  220. ret = videobuf_iolock(vq, vb, NULL);
  221. if (ret)
  222. goto fail;
  223. vb->state = VIDEOBUF_PREPARED;
  224. }
  225. buf->inwork = 0;
  226. return 0;
  227. fail:
  228. free_buffer(vq, buf, pcdev->vb_mode);
  229. out:
  230. buf->inwork = 0;
  231. return ret;
  232. }
  233. static void set_dma_dest_params(int dma_ch, struct omap1_cam_buf *buf,
  234. enum omap1_cam_vb_mode vb_mode)
  235. {
  236. dma_addr_t dma_addr;
  237. unsigned int block_size;
  238. if (vb_mode == OMAP1_CAM_DMA_CONTIG) {
  239. dma_addr = videobuf_to_dma_contig(&buf->vb);
  240. block_size = buf->vb.size;
  241. } else {
  242. if (WARN_ON(!buf->sgbuf)) {
  243. buf->result = VIDEOBUF_ERROR;
  244. return;
  245. }
  246. dma_addr = sg_dma_address(buf->sgbuf);
  247. if (WARN_ON(!dma_addr)) {
  248. buf->sgbuf = NULL;
  249. buf->result = VIDEOBUF_ERROR;
  250. return;
  251. }
  252. block_size = sg_dma_len(buf->sgbuf);
  253. if (WARN_ON(!block_size)) {
  254. buf->sgbuf = NULL;
  255. buf->result = VIDEOBUF_ERROR;
  256. return;
  257. }
  258. if (unlikely(buf->bytes_left < block_size))
  259. block_size = buf->bytes_left;
  260. if (WARN_ON(dma_addr & (DMA_FRAME_SIZE(vb_mode) *
  261. DMA_ELEMENT_SIZE - 1))) {
  262. dma_addr = ALIGN(dma_addr, DMA_FRAME_SIZE(vb_mode) *
  263. DMA_ELEMENT_SIZE);
  264. block_size &= ~(DMA_FRAME_SIZE(vb_mode) *
  265. DMA_ELEMENT_SIZE - 1);
  266. }
  267. buf->bytes_left -= block_size;
  268. buf->sgcount++;
  269. }
  270. omap_set_dma_dest_params(dma_ch,
  271. OMAP_DMA_PORT_EMIFF, OMAP_DMA_AMODE_POST_INC, dma_addr, 0, 0);
  272. omap_set_dma_transfer_params(dma_ch,
  273. OMAP_DMA_DATA_TYPE_S32, DMA_FRAME_SIZE(vb_mode),
  274. block_size >> (DMA_FRAME_SHIFT(vb_mode) + DMA_ELEMENT_SHIFT),
  275. DMA_SYNC, 0, 0);
  276. }
  277. static struct omap1_cam_buf *prepare_next_vb(struct omap1_cam_dev *pcdev)
  278. {
  279. struct omap1_cam_buf *buf;
  280. /*
  281. * If there is already a buffer pointed out by the pcdev->ready,
  282. * (re)use it, otherwise try to fetch and configure a new one.
  283. */
  284. buf = pcdev->ready;
  285. if (!buf) {
  286. if (list_empty(&pcdev->capture))
  287. return buf;
  288. buf = list_entry(pcdev->capture.next,
  289. struct omap1_cam_buf, vb.queue);
  290. buf->vb.state = VIDEOBUF_ACTIVE;
  291. pcdev->ready = buf;
  292. list_del_init(&buf->vb.queue);
  293. }
  294. if (pcdev->vb_mode == OMAP1_CAM_DMA_CONTIG) {
  295. /*
  296. * In CONTIG mode, we can safely enter next buffer parameters
  297. * into the DMA programming register set after the DMA
  298. * has already been activated on the previous buffer
  299. */
  300. set_dma_dest_params(pcdev->dma_ch, buf, pcdev->vb_mode);
  301. } else {
  302. /*
  303. * In SG mode, the above is not safe since there are probably
  304. * a bunch of sgbufs from previous sglist still pending.
  305. * Instead, mark the sglist fresh for the upcoming
  306. * try_next_sgbuf().
  307. */
  308. buf->sgbuf = NULL;
  309. }
  310. return buf;
  311. }
  312. static struct scatterlist *try_next_sgbuf(int dma_ch, struct omap1_cam_buf *buf)
  313. {
  314. struct scatterlist *sgbuf;
  315. if (likely(buf->sgbuf)) {
  316. /* current sglist is active */
  317. if (unlikely(!buf->bytes_left)) {
  318. /* indicate sglist complete */
  319. sgbuf = NULL;
  320. } else {
  321. /* process next sgbuf */
  322. sgbuf = sg_next(buf->sgbuf);
  323. if (WARN_ON(!sgbuf)) {
  324. buf->result = VIDEOBUF_ERROR;
  325. } else if (WARN_ON(!sg_dma_len(sgbuf))) {
  326. sgbuf = NULL;
  327. buf->result = VIDEOBUF_ERROR;
  328. }
  329. }
  330. buf->sgbuf = sgbuf;
  331. } else {
  332. /* sglist is fresh, initialize it before using */
  333. struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb);
  334. sgbuf = dma->sglist;
  335. if (!(WARN_ON(!sgbuf))) {
  336. buf->sgbuf = sgbuf;
  337. buf->sgcount = 0;
  338. buf->bytes_left = buf->vb.size;
  339. buf->result = VIDEOBUF_DONE;
  340. }
  341. }
  342. if (sgbuf)
  343. /*
  344. * Put our next sgbuf parameters (address, size)
  345. * into the DMA programming register set.
  346. */
  347. set_dma_dest_params(dma_ch, buf, OMAP1_CAM_DMA_SG);
  348. return sgbuf;
  349. }
  350. static void start_capture(struct omap1_cam_dev *pcdev)
  351. {
  352. struct omap1_cam_buf *buf = pcdev->active;
  353. u32 ctrlclock = CAM_READ_CACHE(pcdev, CTRLCLOCK);
  354. u32 mode = CAM_READ_CACHE(pcdev, MODE) & ~EN_V_DOWN;
  355. if (WARN_ON(!buf))
  356. return;
  357. /*
  358. * Enable start of frame interrupt, which we will use for activating
  359. * our end of frame watchdog when capture actually starts.
  360. */
  361. mode |= EN_V_UP;
  362. if (unlikely(ctrlclock & LCLK_EN))
  363. /* stop pixel clock before FIFO reset */
  364. CAM_WRITE(pcdev, CTRLCLOCK, ctrlclock & ~LCLK_EN);
  365. /* reset FIFO */
  366. CAM_WRITE(pcdev, MODE, mode | RAZ_FIFO);
  367. omap_start_dma(pcdev->dma_ch);
  368. if (pcdev->vb_mode == OMAP1_CAM_DMA_SG) {
  369. /*
  370. * In SG mode, it's a good moment for fetching next sgbuf
  371. * from the current sglist and, if available, already putting
  372. * its parameters into the DMA programming register set.
  373. */
  374. try_next_sgbuf(pcdev->dma_ch, buf);
  375. }
  376. /* (re)enable pixel clock */
  377. CAM_WRITE(pcdev, CTRLCLOCK, ctrlclock | LCLK_EN);
  378. /* release FIFO reset */
  379. CAM_WRITE(pcdev, MODE, mode);
  380. }
  381. static void suspend_capture(struct omap1_cam_dev *pcdev)
  382. {
  383. u32 ctrlclock = CAM_READ_CACHE(pcdev, CTRLCLOCK);
  384. CAM_WRITE(pcdev, CTRLCLOCK, ctrlclock & ~LCLK_EN);
  385. omap_stop_dma(pcdev->dma_ch);
  386. }
  387. static void disable_capture(struct omap1_cam_dev *pcdev)
  388. {
  389. u32 mode = CAM_READ_CACHE(pcdev, MODE);
  390. CAM_WRITE(pcdev, MODE, mode & ~(IRQ_MASK | DMA));
  391. }
  392. static void omap1_videobuf_queue(struct videobuf_queue *vq,
  393. struct videobuf_buffer *vb)
  394. {
  395. struct soc_camera_device *icd = vq->priv_data;
  396. struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
  397. struct omap1_cam_dev *pcdev = ici->priv;
  398. struct omap1_cam_buf *buf;
  399. u32 mode;
  400. list_add_tail(&vb->queue, &pcdev->capture);
  401. vb->state = VIDEOBUF_QUEUED;
  402. if (pcdev->active) {
  403. /*
  404. * Capture in progress, so don't touch pcdev->ready even if
  405. * empty. Since the transfer of the DMA programming register set
  406. * content to the DMA working register set is done automatically
  407. * by the DMA hardware, this can pretty well happen while we
  408. * are keeping the lock here. Leave fetching it from the queue
  409. * to be done when a next DMA interrupt occures instead.
  410. */
  411. return;
  412. }
  413. WARN_ON(pcdev->ready);
  414. buf = prepare_next_vb(pcdev);
  415. if (WARN_ON(!buf))
  416. return;
  417. pcdev->active = buf;
  418. pcdev->ready = NULL;
  419. dev_dbg(icd->parent,
  420. "%s: capture not active, setup FIFO, start DMA\n", __func__);
  421. mode = CAM_READ_CACHE(pcdev, MODE) & ~THRESHOLD_MASK;
  422. mode |= THRESHOLD_LEVEL(pcdev->vb_mode) << THRESHOLD_SHIFT;
  423. CAM_WRITE(pcdev, MODE, mode | EN_FIFO_FULL | DMA);
  424. if (pcdev->vb_mode == OMAP1_CAM_DMA_SG) {
  425. /*
  426. * In SG mode, the above prepare_next_vb() didn't actually
  427. * put anything into the DMA programming register set,
  428. * so we have to do it now, before activating DMA.
  429. */
  430. try_next_sgbuf(pcdev->dma_ch, buf);
  431. }
  432. start_capture(pcdev);
  433. }
  434. static void omap1_videobuf_release(struct videobuf_queue *vq,
  435. struct videobuf_buffer *vb)
  436. {
  437. struct omap1_cam_buf *buf =
  438. container_of(vb, struct omap1_cam_buf, vb);
  439. struct soc_camera_device *icd = vq->priv_data;
  440. struct device *dev = icd->parent;
  441. struct soc_camera_host *ici = to_soc_camera_host(dev);
  442. struct omap1_cam_dev *pcdev = ici->priv;
  443. switch (vb->state) {
  444. case VIDEOBUF_DONE:
  445. dev_dbg(dev, "%s (done)\n", __func__);
  446. break;
  447. case VIDEOBUF_ACTIVE:
  448. dev_dbg(dev, "%s (active)\n", __func__);
  449. break;
  450. case VIDEOBUF_QUEUED:
  451. dev_dbg(dev, "%s (queued)\n", __func__);
  452. break;
  453. case VIDEOBUF_PREPARED:
  454. dev_dbg(dev, "%s (prepared)\n", __func__);
  455. break;
  456. default:
  457. dev_dbg(dev, "%s (unknown %d)\n", __func__, vb->state);
  458. break;
  459. }
  460. free_buffer(vq, buf, pcdev->vb_mode);
  461. }
  462. static void videobuf_done(struct omap1_cam_dev *pcdev,
  463. enum videobuf_state result)
  464. {
  465. struct omap1_cam_buf *buf = pcdev->active;
  466. struct videobuf_buffer *vb;
  467. struct device *dev = pcdev->soc_host.icd->parent;
  468. if (WARN_ON(!buf)) {
  469. suspend_capture(pcdev);
  470. disable_capture(pcdev);
  471. return;
  472. }
  473. if (result == VIDEOBUF_ERROR)
  474. suspend_capture(pcdev);
  475. vb = &buf->vb;
  476. if (waitqueue_active(&vb->done)) {
  477. if (!pcdev->ready && result != VIDEOBUF_ERROR) {
  478. /*
  479. * No next buffer has been entered into the DMA
  480. * programming register set on time (could be done only
  481. * while the previous DMA interurpt was processed, not
  482. * later), so the last DMA block, be it a whole buffer
  483. * if in CONTIG or its last sgbuf if in SG mode, is
  484. * about to be reused by the just autoreinitialized DMA
  485. * engine, and overwritten with next frame data. Best we
  486. * can do is stopping the capture as soon as possible,
  487. * hopefully before the next frame start.
  488. */
  489. suspend_capture(pcdev);
  490. }
  491. vb->state = result;
  492. v4l2_get_timestamp(&vb->ts);
  493. if (result != VIDEOBUF_ERROR)
  494. vb->field_count++;
  495. wake_up(&vb->done);
  496. /* shift in next buffer */
  497. buf = pcdev->ready;
  498. pcdev->active = buf;
  499. pcdev->ready = NULL;
  500. if (!buf) {
  501. /*
  502. * No next buffer was ready on time (see above), so
  503. * indicate error condition to force capture restart or
  504. * stop, depending on next buffer already queued or not.
  505. */
  506. result = VIDEOBUF_ERROR;
  507. prepare_next_vb(pcdev);
  508. buf = pcdev->ready;
  509. pcdev->active = buf;
  510. pcdev->ready = NULL;
  511. }
  512. } else if (pcdev->ready) {
  513. /*
  514. * In both CONTIG and SG mode, the DMA engine has possibly
  515. * been already autoreinitialized with the preprogrammed
  516. * pcdev->ready buffer. We can either accept this fact
  517. * and just swap the buffers, or provoke an error condition
  518. * and restart capture. The former seems less intrusive.
  519. */
  520. dev_dbg(dev, "%s: nobody waiting on videobuf, swap with next\n",
  521. __func__);
  522. pcdev->active = pcdev->ready;
  523. if (pcdev->vb_mode == OMAP1_CAM_DMA_SG) {
  524. /*
  525. * In SG mode, we have to make sure that the buffer we
  526. * are putting back into the pcdev->ready is marked
  527. * fresh.
  528. */
  529. buf->sgbuf = NULL;
  530. }
  531. pcdev->ready = buf;
  532. buf = pcdev->active;
  533. } else {
  534. /*
  535. * No next buffer has been entered into
  536. * the DMA programming register set on time.
  537. */
  538. if (pcdev->vb_mode == OMAP1_CAM_DMA_CONTIG) {
  539. /*
  540. * In CONTIG mode, the DMA engine has already been
  541. * reinitialized with the current buffer. Best we can do
  542. * is not touching it.
  543. */
  544. dev_dbg(dev,
  545. "%s: nobody waiting on videobuf, reuse it\n",
  546. __func__);
  547. } else {
  548. /*
  549. * In SG mode, the DMA engine has just been
  550. * autoreinitialized with the last sgbuf from the
  551. * current list. Restart capture in order to transfer
  552. * next frame start into the first sgbuf, not the last
  553. * one.
  554. */
  555. if (result != VIDEOBUF_ERROR) {
  556. suspend_capture(pcdev);
  557. result = VIDEOBUF_ERROR;
  558. }
  559. }
  560. }
  561. if (!buf) {
  562. dev_dbg(dev, "%s: no more videobufs, stop capture\n", __func__);
  563. disable_capture(pcdev);
  564. return;
  565. }
  566. if (pcdev->vb_mode == OMAP1_CAM_DMA_CONTIG) {
  567. /*
  568. * In CONTIG mode, the current buffer parameters had already
  569. * been entered into the DMA programming register set while the
  570. * buffer was fetched with prepare_next_vb(), they may have also
  571. * been transferred into the runtime set and already active if
  572. * the DMA still running.
  573. */
  574. } else {
  575. /* In SG mode, extra steps are required */
  576. if (result == VIDEOBUF_ERROR)
  577. /* make sure we (re)use sglist from start on error */
  578. buf->sgbuf = NULL;
  579. /*
  580. * In any case, enter the next sgbuf parameters into the DMA
  581. * programming register set. They will be used either during
  582. * nearest DMA autoreinitialization or, in case of an error,
  583. * on DMA startup below.
  584. */
  585. try_next_sgbuf(pcdev->dma_ch, buf);
  586. }
  587. if (result == VIDEOBUF_ERROR) {
  588. dev_dbg(dev, "%s: videobuf error; reset FIFO, restart DMA\n",
  589. __func__);
  590. start_capture(pcdev);
  591. /*
  592. * In SG mode, the above also resulted in the next sgbuf
  593. * parameters being entered into the DMA programming register
  594. * set, making them ready for next DMA autoreinitialization.
  595. */
  596. }
  597. /*
  598. * Finally, try fetching next buffer.
  599. * In CONTIG mode, it will also enter it into the DMA programming
  600. * register set, making it ready for next DMA autoreinitialization.
  601. */
  602. prepare_next_vb(pcdev);
  603. }
  604. static void dma_isr(int channel, unsigned short status, void *data)
  605. {
  606. struct omap1_cam_dev *pcdev = data;
  607. struct omap1_cam_buf *buf = pcdev->active;
  608. unsigned long flags;
  609. spin_lock_irqsave(&pcdev->lock, flags);
  610. if (WARN_ON(!buf)) {
  611. suspend_capture(pcdev);
  612. disable_capture(pcdev);
  613. goto out;
  614. }
  615. if (pcdev->vb_mode == OMAP1_CAM_DMA_CONTIG) {
  616. /*
  617. * In CONTIG mode, assume we have just managed to collect the
  618. * whole frame, hopefully before our end of frame watchdog is
  619. * triggered. Then, all we have to do is disabling the watchdog
  620. * for this frame, and calling videobuf_done() with success
  621. * indicated.
  622. */
  623. CAM_WRITE(pcdev, MODE,
  624. CAM_READ_CACHE(pcdev, MODE) & ~EN_V_DOWN);
  625. videobuf_done(pcdev, VIDEOBUF_DONE);
  626. } else {
  627. /*
  628. * In SG mode, we have to process every sgbuf from the current
  629. * sglist, one after another.
  630. */
  631. if (buf->sgbuf) {
  632. /*
  633. * Current sglist not completed yet, try fetching next
  634. * sgbuf, hopefully putting it into the DMA programming
  635. * register set, making it ready for next DMA
  636. * autoreinitialization.
  637. */
  638. try_next_sgbuf(pcdev->dma_ch, buf);
  639. if (buf->sgbuf)
  640. goto out;
  641. /*
  642. * No more sgbufs left in the current sglist. This
  643. * doesn't mean that the whole videobuffer is already
  644. * complete, but only that the last sgbuf from the
  645. * current sglist is about to be filled. It will be
  646. * ready on next DMA interrupt, signalled with the
  647. * buf->sgbuf set back to NULL.
  648. */
  649. if (buf->result != VIDEOBUF_ERROR) {
  650. /*
  651. * Video frame collected without errors so far,
  652. * we can prepare for collecting a next one
  653. * as soon as DMA gets autoreinitialized
  654. * after the current (last) sgbuf is completed.
  655. */
  656. buf = prepare_next_vb(pcdev);
  657. if (!buf)
  658. goto out;
  659. try_next_sgbuf(pcdev->dma_ch, buf);
  660. goto out;
  661. }
  662. }
  663. /* end of videobuf */
  664. videobuf_done(pcdev, buf->result);
  665. }
  666. out:
  667. spin_unlock_irqrestore(&pcdev->lock, flags);
  668. }
  669. static irqreturn_t cam_isr(int irq, void *data)
  670. {
  671. struct omap1_cam_dev *pcdev = data;
  672. struct device *dev = pcdev->soc_host.icd->parent;
  673. struct omap1_cam_buf *buf = pcdev->active;
  674. u32 it_status;
  675. unsigned long flags;
  676. it_status = CAM_READ(pcdev, IT_STATUS);
  677. if (!it_status)
  678. return IRQ_NONE;
  679. spin_lock_irqsave(&pcdev->lock, flags);
  680. if (WARN_ON(!buf)) {
  681. dev_warn(dev, "%s: unhandled camera interrupt, status == %#x\n",
  682. __func__, it_status);
  683. suspend_capture(pcdev);
  684. disable_capture(pcdev);
  685. goto out;
  686. }
  687. if (unlikely(it_status & FIFO_FULL)) {
  688. dev_warn(dev, "%s: FIFO overflow\n", __func__);
  689. } else if (it_status & V_DOWN) {
  690. /* end of video frame watchdog */
  691. if (pcdev->vb_mode == OMAP1_CAM_DMA_CONTIG) {
  692. /*
  693. * In CONTIG mode, the watchdog is disabled with
  694. * successful DMA end of block interrupt, and reenabled
  695. * on next frame start. If we get here, there is nothing
  696. * to check, we must be out of sync.
  697. */
  698. } else {
  699. if (buf->sgcount == 2) {
  700. /*
  701. * If exactly 2 sgbufs from the next sglist have
  702. * been programmed into the DMA engine (the
  703. * first one already transferred into the DMA
  704. * runtime register set, the second one still
  705. * in the programming set), then we are in sync.
  706. */
  707. goto out;
  708. }
  709. }
  710. dev_notice(dev, "%s: unexpected end of video frame\n",
  711. __func__);
  712. } else if (it_status & V_UP) {
  713. u32 mode;
  714. if (pcdev->vb_mode == OMAP1_CAM_DMA_CONTIG) {
  715. /*
  716. * In CONTIG mode, we need this interrupt every frame
  717. * in oredr to reenable our end of frame watchdog.
  718. */
  719. mode = CAM_READ_CACHE(pcdev, MODE);
  720. } else {
  721. /*
  722. * In SG mode, the below enabled end of frame watchdog
  723. * is kept on permanently, so we can turn this one shot
  724. * setup off.
  725. */
  726. mode = CAM_READ_CACHE(pcdev, MODE) & ~EN_V_UP;
  727. }
  728. if (!(mode & EN_V_DOWN)) {
  729. /* (re)enable end of frame watchdog interrupt */
  730. mode |= EN_V_DOWN;
  731. }
  732. CAM_WRITE(pcdev, MODE, mode);
  733. goto out;
  734. } else {
  735. dev_warn(dev, "%s: unhandled camera interrupt, status == %#x\n",
  736. __func__, it_status);
  737. goto out;
  738. }
  739. videobuf_done(pcdev, VIDEOBUF_ERROR);
  740. out:
  741. spin_unlock_irqrestore(&pcdev->lock, flags);
  742. return IRQ_HANDLED;
  743. }
  744. static struct videobuf_queue_ops omap1_videobuf_ops = {
  745. .buf_setup = omap1_videobuf_setup,
  746. .buf_prepare = omap1_videobuf_prepare,
  747. .buf_queue = omap1_videobuf_queue,
  748. .buf_release = omap1_videobuf_release,
  749. };
  750. /*
  751. * SOC Camera host operations
  752. */
  753. static void sensor_reset(struct omap1_cam_dev *pcdev, bool reset)
  754. {
  755. /* apply/release camera sensor reset if requested by platform data */
  756. if (pcdev->pflags & OMAP1_CAMERA_RST_HIGH)
  757. CAM_WRITE(pcdev, GPIO, reset);
  758. else if (pcdev->pflags & OMAP1_CAMERA_RST_LOW)
  759. CAM_WRITE(pcdev, GPIO, !reset);
  760. }
  761. static int omap1_cam_add_device(struct soc_camera_device *icd)
  762. {
  763. dev_dbg(icd->parent, "OMAP1 Camera driver attached to camera %d\n",
  764. icd->devnum);
  765. return 0;
  766. }
  767. static void omap1_cam_remove_device(struct soc_camera_device *icd)
  768. {
  769. dev_dbg(icd->parent,
  770. "OMAP1 Camera driver detached from camera %d\n", icd->devnum);
  771. }
  772. /*
  773. * The following two functions absolutely depend on the fact, that
  774. * there can be only one camera on OMAP1 camera sensor interface
  775. */
  776. static int omap1_cam_clock_start(struct soc_camera_host *ici)
  777. {
  778. struct omap1_cam_dev *pcdev = ici->priv;
  779. u32 ctrlclock;
  780. clk_enable(pcdev->clk);
  781. /* setup sensor clock */
  782. ctrlclock = CAM_READ(pcdev, CTRLCLOCK);
  783. ctrlclock &= ~(CAMEXCLK_EN | MCLK_EN | DPLL_EN);
  784. CAM_WRITE(pcdev, CTRLCLOCK, ctrlclock);
  785. ctrlclock &= ~FOSCMOD_MASK;
  786. switch (pcdev->camexclk) {
  787. case 6000000:
  788. ctrlclock |= CAMEXCLK_EN | FOSCMOD_6MHz;
  789. break;
  790. case 8000000:
  791. ctrlclock |= CAMEXCLK_EN | FOSCMOD_8MHz | DPLL_EN;
  792. break;
  793. case 9600000:
  794. ctrlclock |= CAMEXCLK_EN | FOSCMOD_9_6MHz | DPLL_EN;
  795. break;
  796. case 12000000:
  797. ctrlclock |= CAMEXCLK_EN | FOSCMOD_12MHz;
  798. break;
  799. case 24000000:
  800. ctrlclock |= CAMEXCLK_EN | FOSCMOD_24MHz | DPLL_EN;
  801. default:
  802. break;
  803. }
  804. CAM_WRITE(pcdev, CTRLCLOCK, ctrlclock & ~DPLL_EN);
  805. /* enable internal clock */
  806. ctrlclock |= MCLK_EN;
  807. CAM_WRITE(pcdev, CTRLCLOCK, ctrlclock);
  808. sensor_reset(pcdev, false);
  809. return 0;
  810. }
  811. static void omap1_cam_clock_stop(struct soc_camera_host *ici)
  812. {
  813. struct omap1_cam_dev *pcdev = ici->priv;
  814. u32 ctrlclock;
  815. suspend_capture(pcdev);
  816. disable_capture(pcdev);
  817. sensor_reset(pcdev, true);
  818. /* disable and release system clocks */
  819. ctrlclock = CAM_READ_CACHE(pcdev, CTRLCLOCK);
  820. ctrlclock &= ~(MCLK_EN | DPLL_EN | CAMEXCLK_EN);
  821. CAM_WRITE(pcdev, CTRLCLOCK, ctrlclock);
  822. ctrlclock = (ctrlclock & ~FOSCMOD_MASK) | FOSCMOD_12MHz;
  823. CAM_WRITE(pcdev, CTRLCLOCK, ctrlclock);
  824. CAM_WRITE(pcdev, CTRLCLOCK, ctrlclock | MCLK_EN);
  825. CAM_WRITE(pcdev, CTRLCLOCK, ctrlclock & ~MCLK_EN);
  826. clk_disable(pcdev->clk);
  827. }
  828. /* Duplicate standard formats based on host capability of byte swapping */
  829. static const struct soc_mbus_lookup omap1_cam_formats[] = {
  830. {
  831. .code = MEDIA_BUS_FMT_UYVY8_2X8,
  832. .fmt = {
  833. .fourcc = V4L2_PIX_FMT_YUYV,
  834. .name = "YUYV",
  835. .bits_per_sample = 8,
  836. .packing = SOC_MBUS_PACKING_2X8_PADHI,
  837. .order = SOC_MBUS_ORDER_BE,
  838. .layout = SOC_MBUS_LAYOUT_PACKED,
  839. },
  840. }, {
  841. .code = MEDIA_BUS_FMT_VYUY8_2X8,
  842. .fmt = {
  843. .fourcc = V4L2_PIX_FMT_YVYU,
  844. .name = "YVYU",
  845. .bits_per_sample = 8,
  846. .packing = SOC_MBUS_PACKING_2X8_PADHI,
  847. .order = SOC_MBUS_ORDER_BE,
  848. .layout = SOC_MBUS_LAYOUT_PACKED,
  849. },
  850. }, {
  851. .code = MEDIA_BUS_FMT_YUYV8_2X8,
  852. .fmt = {
  853. .fourcc = V4L2_PIX_FMT_UYVY,
  854. .name = "UYVY",
  855. .bits_per_sample = 8,
  856. .packing = SOC_MBUS_PACKING_2X8_PADHI,
  857. .order = SOC_MBUS_ORDER_BE,
  858. .layout = SOC_MBUS_LAYOUT_PACKED,
  859. },
  860. }, {
  861. .code = MEDIA_BUS_FMT_YVYU8_2X8,
  862. .fmt = {
  863. .fourcc = V4L2_PIX_FMT_VYUY,
  864. .name = "VYUY",
  865. .bits_per_sample = 8,
  866. .packing = SOC_MBUS_PACKING_2X8_PADHI,
  867. .order = SOC_MBUS_ORDER_BE,
  868. .layout = SOC_MBUS_LAYOUT_PACKED,
  869. },
  870. }, {
  871. .code = MEDIA_BUS_FMT_RGB555_2X8_PADHI_BE,
  872. .fmt = {
  873. .fourcc = V4L2_PIX_FMT_RGB555,
  874. .name = "RGB555",
  875. .bits_per_sample = 8,
  876. .packing = SOC_MBUS_PACKING_2X8_PADHI,
  877. .order = SOC_MBUS_ORDER_BE,
  878. .layout = SOC_MBUS_LAYOUT_PACKED,
  879. },
  880. }, {
  881. .code = MEDIA_BUS_FMT_RGB555_2X8_PADHI_LE,
  882. .fmt = {
  883. .fourcc = V4L2_PIX_FMT_RGB555X,
  884. .name = "RGB555X",
  885. .bits_per_sample = 8,
  886. .packing = SOC_MBUS_PACKING_2X8_PADHI,
  887. .order = SOC_MBUS_ORDER_BE,
  888. .layout = SOC_MBUS_LAYOUT_PACKED,
  889. },
  890. }, {
  891. .code = MEDIA_BUS_FMT_RGB565_2X8_BE,
  892. .fmt = {
  893. .fourcc = V4L2_PIX_FMT_RGB565,
  894. .name = "RGB565",
  895. .bits_per_sample = 8,
  896. .packing = SOC_MBUS_PACKING_2X8_PADHI,
  897. .order = SOC_MBUS_ORDER_BE,
  898. .layout = SOC_MBUS_LAYOUT_PACKED,
  899. },
  900. }, {
  901. .code = MEDIA_BUS_FMT_RGB565_2X8_LE,
  902. .fmt = {
  903. .fourcc = V4L2_PIX_FMT_RGB565X,
  904. .name = "RGB565X",
  905. .bits_per_sample = 8,
  906. .packing = SOC_MBUS_PACKING_2X8_PADHI,
  907. .order = SOC_MBUS_ORDER_BE,
  908. .layout = SOC_MBUS_LAYOUT_PACKED,
  909. },
  910. },
  911. };
  912. static int omap1_cam_get_formats(struct soc_camera_device *icd,
  913. unsigned int idx, struct soc_camera_format_xlate *xlate)
  914. {
  915. struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
  916. struct device *dev = icd->parent;
  917. int formats = 0, ret;
  918. struct v4l2_subdev_mbus_code_enum code = {
  919. .which = V4L2_SUBDEV_FORMAT_ACTIVE,
  920. .index = idx,
  921. };
  922. const struct soc_mbus_pixelfmt *fmt;
  923. ret = v4l2_subdev_call(sd, pad, enum_mbus_code, NULL, &code);
  924. if (ret < 0)
  925. /* No more formats */
  926. return 0;
  927. fmt = soc_mbus_get_fmtdesc(code.code);
  928. if (!fmt) {
  929. dev_warn(dev, "%s: unsupported format code #%d: %d\n", __func__,
  930. idx, code.code);
  931. return 0;
  932. }
  933. /* Check support for the requested bits-per-sample */
  934. if (fmt->bits_per_sample != 8)
  935. return 0;
  936. switch (code.code) {
  937. case MEDIA_BUS_FMT_YUYV8_2X8:
  938. case MEDIA_BUS_FMT_YVYU8_2X8:
  939. case MEDIA_BUS_FMT_UYVY8_2X8:
  940. case MEDIA_BUS_FMT_VYUY8_2X8:
  941. case MEDIA_BUS_FMT_RGB555_2X8_PADHI_BE:
  942. case MEDIA_BUS_FMT_RGB555_2X8_PADHI_LE:
  943. case MEDIA_BUS_FMT_RGB565_2X8_BE:
  944. case MEDIA_BUS_FMT_RGB565_2X8_LE:
  945. formats++;
  946. if (xlate) {
  947. xlate->host_fmt = soc_mbus_find_fmtdesc(code.code,
  948. omap1_cam_formats,
  949. ARRAY_SIZE(omap1_cam_formats));
  950. xlate->code = code.code;
  951. xlate++;
  952. dev_dbg(dev,
  953. "%s: providing format %s as byte swapped code #%d\n",
  954. __func__, xlate->host_fmt->name, code.code);
  955. }
  956. default:
  957. if (xlate)
  958. dev_dbg(dev,
  959. "%s: providing format %s in pass-through mode\n",
  960. __func__, fmt->name);
  961. }
  962. formats++;
  963. if (xlate) {
  964. xlate->host_fmt = fmt;
  965. xlate->code = code.code;
  966. xlate++;
  967. }
  968. return formats;
  969. }
  970. static bool is_dma_aligned(s32 bytes_per_line, unsigned int height,
  971. enum omap1_cam_vb_mode vb_mode)
  972. {
  973. int size = bytes_per_line * height;
  974. return IS_ALIGNED(bytes_per_line, DMA_ELEMENT_SIZE) &&
  975. IS_ALIGNED(size, DMA_FRAME_SIZE(vb_mode) * DMA_ELEMENT_SIZE);
  976. }
  977. static int dma_align(int *width, int *height,
  978. const struct soc_mbus_pixelfmt *fmt,
  979. enum omap1_cam_vb_mode vb_mode, bool enlarge)
  980. {
  981. s32 bytes_per_line = soc_mbus_bytes_per_line(*width, fmt);
  982. if (bytes_per_line < 0)
  983. return bytes_per_line;
  984. if (!is_dma_aligned(bytes_per_line, *height, vb_mode)) {
  985. unsigned int pxalign = __fls(bytes_per_line / *width);
  986. unsigned int salign = DMA_FRAME_SHIFT(vb_mode) +
  987. DMA_ELEMENT_SHIFT - pxalign;
  988. unsigned int incr = enlarge << salign;
  989. v4l_bound_align_image(width, 1, *width + incr, 0,
  990. height, 1, *height + incr, 0, salign);
  991. return 0;
  992. }
  993. return 1;
  994. }
  995. #define subdev_call_with_sense(pcdev, dev, icd, sd, op, function, args...) \
  996. ({ \
  997. struct soc_camera_sense sense = { \
  998. .master_clock = pcdev->camexclk, \
  999. .pixel_clock_max = 0, \
  1000. }; \
  1001. int __ret; \
  1002. \
  1003. if (pcdev->pdata) \
  1004. sense.pixel_clock_max = pcdev->pdata->lclk_khz_max * 1000; \
  1005. icd->sense = &sense; \
  1006. __ret = v4l2_subdev_call(sd, op, function, ##args); \
  1007. icd->sense = NULL; \
  1008. \
  1009. if (sense.flags & SOCAM_SENSE_PCLK_CHANGED) { \
  1010. if (sense.pixel_clock > sense.pixel_clock_max) { \
  1011. dev_err(dev, \
  1012. "%s: pixel clock %lu set by the camera too high!\n", \
  1013. __func__, sense.pixel_clock); \
  1014. __ret = -EINVAL; \
  1015. } \
  1016. } \
  1017. __ret; \
  1018. })
  1019. static int set_format(struct omap1_cam_dev *pcdev, struct device *dev,
  1020. struct soc_camera_device *icd, struct v4l2_subdev *sd,
  1021. struct v4l2_subdev_format *format,
  1022. const struct soc_camera_format_xlate *xlate)
  1023. {
  1024. s32 bytes_per_line;
  1025. struct v4l2_mbus_framefmt *mf = &format->format;
  1026. int ret = subdev_call_with_sense(pcdev, dev, icd, sd, pad, set_fmt, NULL, format);
  1027. if (ret < 0) {
  1028. dev_err(dev, "%s: set_fmt failed\n", __func__);
  1029. return ret;
  1030. }
  1031. if (mf->code != xlate->code) {
  1032. dev_err(dev, "%s: unexpected pixel code change\n", __func__);
  1033. return -EINVAL;
  1034. }
  1035. bytes_per_line = soc_mbus_bytes_per_line(mf->width, xlate->host_fmt);
  1036. if (bytes_per_line < 0) {
  1037. dev_err(dev, "%s: soc_mbus_bytes_per_line() failed\n",
  1038. __func__);
  1039. return bytes_per_line;
  1040. }
  1041. if (!is_dma_aligned(bytes_per_line, mf->height, pcdev->vb_mode)) {
  1042. dev_err(dev, "%s: resulting geometry %ux%u not DMA aligned\n",
  1043. __func__, mf->width, mf->height);
  1044. return -EINVAL;
  1045. }
  1046. return 0;
  1047. }
  1048. static int omap1_cam_set_crop(struct soc_camera_device *icd,
  1049. const struct v4l2_crop *crop)
  1050. {
  1051. const struct v4l2_rect *rect = &crop->c;
  1052. const struct soc_camera_format_xlate *xlate = icd->current_fmt;
  1053. struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
  1054. struct device *dev = icd->parent;
  1055. struct soc_camera_host *ici = to_soc_camera_host(dev);
  1056. struct omap1_cam_dev *pcdev = ici->priv;
  1057. struct v4l2_subdev_format fmt = {
  1058. .which = V4L2_SUBDEV_FORMAT_ACTIVE,
  1059. };
  1060. struct v4l2_mbus_framefmt *mf = &fmt.format;
  1061. int ret;
  1062. ret = subdev_call_with_sense(pcdev, dev, icd, sd, video, s_crop, crop);
  1063. if (ret < 0) {
  1064. dev_warn(dev, "%s: failed to crop to %ux%u@%u:%u\n", __func__,
  1065. rect->width, rect->height, rect->left, rect->top);
  1066. return ret;
  1067. }
  1068. ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &fmt);
  1069. if (ret < 0) {
  1070. dev_warn(dev, "%s: failed to fetch current format\n", __func__);
  1071. return ret;
  1072. }
  1073. ret = dma_align(&mf->width, &mf->height, xlate->host_fmt, pcdev->vb_mode,
  1074. false);
  1075. if (ret < 0) {
  1076. dev_err(dev, "%s: failed to align %ux%u %s with DMA\n",
  1077. __func__, mf->width, mf->height,
  1078. xlate->host_fmt->name);
  1079. return ret;
  1080. }
  1081. if (!ret) {
  1082. /* sensor returned geometry not DMA aligned, trying to fix */
  1083. ret = set_format(pcdev, dev, icd, sd, &fmt, xlate);
  1084. if (ret < 0) {
  1085. dev_err(dev, "%s: failed to set format\n", __func__);
  1086. return ret;
  1087. }
  1088. }
  1089. icd->user_width = mf->width;
  1090. icd->user_height = mf->height;
  1091. return 0;
  1092. }
  1093. static int omap1_cam_set_fmt(struct soc_camera_device *icd,
  1094. struct v4l2_format *f)
  1095. {
  1096. struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
  1097. const struct soc_camera_format_xlate *xlate;
  1098. struct device *dev = icd->parent;
  1099. struct soc_camera_host *ici = to_soc_camera_host(dev);
  1100. struct omap1_cam_dev *pcdev = ici->priv;
  1101. struct v4l2_pix_format *pix = &f->fmt.pix;
  1102. struct v4l2_subdev_format format = {
  1103. .which = V4L2_SUBDEV_FORMAT_ACTIVE,
  1104. };
  1105. struct v4l2_mbus_framefmt *mf = &format.format;
  1106. int ret;
  1107. xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat);
  1108. if (!xlate) {
  1109. dev_warn(dev, "%s: format %#x not found\n", __func__,
  1110. pix->pixelformat);
  1111. return -EINVAL;
  1112. }
  1113. mf->width = pix->width;
  1114. mf->height = pix->height;
  1115. mf->field = pix->field;
  1116. mf->colorspace = pix->colorspace;
  1117. mf->code = xlate->code;
  1118. ret = dma_align(&mf->width, &mf->height, xlate->host_fmt, pcdev->vb_mode,
  1119. true);
  1120. if (ret < 0) {
  1121. dev_err(dev, "%s: failed to align %ux%u %s with DMA\n",
  1122. __func__, pix->width, pix->height,
  1123. xlate->host_fmt->name);
  1124. return ret;
  1125. }
  1126. ret = set_format(pcdev, dev, icd, sd, &format, xlate);
  1127. if (ret < 0) {
  1128. dev_err(dev, "%s: failed to set format\n", __func__);
  1129. return ret;
  1130. }
  1131. pix->width = mf->width;
  1132. pix->height = mf->height;
  1133. pix->field = mf->field;
  1134. pix->colorspace = mf->colorspace;
  1135. icd->current_fmt = xlate;
  1136. return 0;
  1137. }
  1138. static int omap1_cam_try_fmt(struct soc_camera_device *icd,
  1139. struct v4l2_format *f)
  1140. {
  1141. struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
  1142. const struct soc_camera_format_xlate *xlate;
  1143. struct v4l2_pix_format *pix = &f->fmt.pix;
  1144. struct v4l2_subdev_pad_config pad_cfg;
  1145. struct v4l2_subdev_format format = {
  1146. .which = V4L2_SUBDEV_FORMAT_TRY,
  1147. };
  1148. struct v4l2_mbus_framefmt *mf = &format.format;
  1149. int ret;
  1150. /* TODO: limit to mx1 hardware capabilities */
  1151. xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat);
  1152. if (!xlate) {
  1153. dev_warn(icd->parent, "Format %#x not found\n",
  1154. pix->pixelformat);
  1155. return -EINVAL;
  1156. }
  1157. mf->width = pix->width;
  1158. mf->height = pix->height;
  1159. mf->field = pix->field;
  1160. mf->colorspace = pix->colorspace;
  1161. mf->code = xlate->code;
  1162. /* limit to sensor capabilities */
  1163. ret = v4l2_subdev_call(sd, pad, set_fmt, &pad_cfg, &format);
  1164. if (ret < 0)
  1165. return ret;
  1166. pix->width = mf->width;
  1167. pix->height = mf->height;
  1168. pix->field = mf->field;
  1169. pix->colorspace = mf->colorspace;
  1170. return 0;
  1171. }
  1172. static bool sg_mode;
  1173. /*
  1174. * Local mmap_mapper wrapper,
  1175. * used for detecting videobuf-dma-contig buffer allocation failures
  1176. * and switching to videobuf-dma-sg automatically for future attempts.
  1177. */
  1178. static int omap1_cam_mmap_mapper(struct videobuf_queue *q,
  1179. struct videobuf_buffer *buf,
  1180. struct vm_area_struct *vma)
  1181. {
  1182. struct soc_camera_device *icd = q->priv_data;
  1183. struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
  1184. struct omap1_cam_dev *pcdev = ici->priv;
  1185. int ret;
  1186. ret = pcdev->mmap_mapper(q, buf, vma);
  1187. if (ret == -ENOMEM)
  1188. sg_mode = true;
  1189. return ret;
  1190. }
  1191. static void omap1_cam_init_videobuf(struct videobuf_queue *q,
  1192. struct soc_camera_device *icd)
  1193. {
  1194. struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
  1195. struct omap1_cam_dev *pcdev = ici->priv;
  1196. if (!sg_mode)
  1197. videobuf_queue_dma_contig_init(q, &omap1_videobuf_ops,
  1198. icd->parent, &pcdev->lock,
  1199. V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE,
  1200. sizeof(struct omap1_cam_buf), icd, &ici->host_lock);
  1201. else
  1202. videobuf_queue_sg_init(q, &omap1_videobuf_ops,
  1203. icd->parent, &pcdev->lock,
  1204. V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE,
  1205. sizeof(struct omap1_cam_buf), icd, &ici->host_lock);
  1206. /* use videobuf mode (auto)selected with the module parameter */
  1207. pcdev->vb_mode = sg_mode ? OMAP1_CAM_DMA_SG : OMAP1_CAM_DMA_CONTIG;
  1208. /*
  1209. * Ensure we substitute the videobuf-dma-contig version of the
  1210. * mmap_mapper() callback with our own wrapper, used for switching
  1211. * automatically to videobuf-dma-sg on buffer allocation failure.
  1212. */
  1213. if (!sg_mode && q->int_ops->mmap_mapper != omap1_cam_mmap_mapper) {
  1214. pcdev->mmap_mapper = q->int_ops->mmap_mapper;
  1215. q->int_ops->mmap_mapper = omap1_cam_mmap_mapper;
  1216. }
  1217. }
  1218. static int omap1_cam_reqbufs(struct soc_camera_device *icd,
  1219. struct v4l2_requestbuffers *p)
  1220. {
  1221. int i;
  1222. /*
  1223. * This is for locking debugging only. I removed spinlocks and now I
  1224. * check whether .prepare is ever called on a linked buffer, or whether
  1225. * a dma IRQ can occur for an in-work or unlinked buffer. Until now
  1226. * it hadn't triggered
  1227. */
  1228. for (i = 0; i < p->count; i++) {
  1229. struct omap1_cam_buf *buf = container_of(icd->vb_vidq.bufs[i],
  1230. struct omap1_cam_buf, vb);
  1231. buf->inwork = 0;
  1232. INIT_LIST_HEAD(&buf->vb.queue);
  1233. }
  1234. return 0;
  1235. }
  1236. static int omap1_cam_querycap(struct soc_camera_host *ici,
  1237. struct v4l2_capability *cap)
  1238. {
  1239. /* cap->name is set by the friendly caller:-> */
  1240. strlcpy(cap->card, "OMAP1 Camera", sizeof(cap->card));
  1241. cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
  1242. cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
  1243. return 0;
  1244. }
  1245. static int omap1_cam_set_bus_param(struct soc_camera_device *icd)
  1246. {
  1247. struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
  1248. struct device *dev = icd->parent;
  1249. struct soc_camera_host *ici = to_soc_camera_host(dev);
  1250. struct omap1_cam_dev *pcdev = ici->priv;
  1251. u32 pixfmt = icd->current_fmt->host_fmt->fourcc;
  1252. const struct soc_camera_format_xlate *xlate;
  1253. const struct soc_mbus_pixelfmt *fmt;
  1254. struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,};
  1255. unsigned long common_flags;
  1256. u32 ctrlclock, mode;
  1257. int ret;
  1258. ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg);
  1259. if (!ret) {
  1260. common_flags = soc_mbus_config_compatible(&cfg, SOCAM_BUS_FLAGS);
  1261. if (!common_flags) {
  1262. dev_warn(dev,
  1263. "Flags incompatible: camera 0x%x, host 0x%x\n",
  1264. cfg.flags, SOCAM_BUS_FLAGS);
  1265. return -EINVAL;
  1266. }
  1267. } else if (ret != -ENOIOCTLCMD) {
  1268. return ret;
  1269. } else {
  1270. common_flags = SOCAM_BUS_FLAGS;
  1271. }
  1272. /* Make choices, possibly based on platform configuration */
  1273. if ((common_flags & V4L2_MBUS_PCLK_SAMPLE_RISING) &&
  1274. (common_flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)) {
  1275. if (!pcdev->pdata ||
  1276. pcdev->pdata->flags & OMAP1_CAMERA_LCLK_RISING)
  1277. common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_FALLING;
  1278. else
  1279. common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_RISING;
  1280. }
  1281. cfg.flags = common_flags;
  1282. ret = v4l2_subdev_call(sd, video, s_mbus_config, &cfg);
  1283. if (ret < 0 && ret != -ENOIOCTLCMD) {
  1284. dev_dbg(dev, "camera s_mbus_config(0x%lx) returned %d\n",
  1285. common_flags, ret);
  1286. return ret;
  1287. }
  1288. ctrlclock = CAM_READ_CACHE(pcdev, CTRLCLOCK);
  1289. if (ctrlclock & LCLK_EN)
  1290. CAM_WRITE(pcdev, CTRLCLOCK, ctrlclock & ~LCLK_EN);
  1291. if (common_flags & V4L2_MBUS_PCLK_SAMPLE_RISING) {
  1292. dev_dbg(dev, "CTRLCLOCK_REG |= POLCLK\n");
  1293. ctrlclock |= POLCLK;
  1294. } else {
  1295. dev_dbg(dev, "CTRLCLOCK_REG &= ~POLCLK\n");
  1296. ctrlclock &= ~POLCLK;
  1297. }
  1298. CAM_WRITE(pcdev, CTRLCLOCK, ctrlclock & ~LCLK_EN);
  1299. if (ctrlclock & LCLK_EN)
  1300. CAM_WRITE(pcdev, CTRLCLOCK, ctrlclock);
  1301. /* select bus endianness */
  1302. xlate = soc_camera_xlate_by_fourcc(icd, pixfmt);
  1303. fmt = xlate->host_fmt;
  1304. mode = CAM_READ(pcdev, MODE) & ~(RAZ_FIFO | IRQ_MASK | DMA);
  1305. if (fmt->order == SOC_MBUS_ORDER_LE) {
  1306. dev_dbg(dev, "MODE_REG &= ~ORDERCAMD\n");
  1307. CAM_WRITE(pcdev, MODE, mode & ~ORDERCAMD);
  1308. } else {
  1309. dev_dbg(dev, "MODE_REG |= ORDERCAMD\n");
  1310. CAM_WRITE(pcdev, MODE, mode | ORDERCAMD);
  1311. }
  1312. return 0;
  1313. }
  1314. static unsigned int omap1_cam_poll(struct file *file, poll_table *pt)
  1315. {
  1316. struct soc_camera_device *icd = file->private_data;
  1317. struct omap1_cam_buf *buf;
  1318. buf = list_entry(icd->vb_vidq.stream.next, struct omap1_cam_buf,
  1319. vb.stream);
  1320. poll_wait(file, &buf->vb.done, pt);
  1321. if (buf->vb.state == VIDEOBUF_DONE ||
  1322. buf->vb.state == VIDEOBUF_ERROR)
  1323. return POLLIN | POLLRDNORM;
  1324. return 0;
  1325. }
  1326. static struct soc_camera_host_ops omap1_host_ops = {
  1327. .owner = THIS_MODULE,
  1328. .add = omap1_cam_add_device,
  1329. .remove = omap1_cam_remove_device,
  1330. .clock_start = omap1_cam_clock_start,
  1331. .clock_stop = omap1_cam_clock_stop,
  1332. .get_formats = omap1_cam_get_formats,
  1333. .set_crop = omap1_cam_set_crop,
  1334. .set_fmt = omap1_cam_set_fmt,
  1335. .try_fmt = omap1_cam_try_fmt,
  1336. .init_videobuf = omap1_cam_init_videobuf,
  1337. .reqbufs = omap1_cam_reqbufs,
  1338. .querycap = omap1_cam_querycap,
  1339. .set_bus_param = omap1_cam_set_bus_param,
  1340. .poll = omap1_cam_poll,
  1341. };
  1342. static int omap1_cam_probe(struct platform_device *pdev)
  1343. {
  1344. struct omap1_cam_dev *pcdev;
  1345. struct resource *res;
  1346. struct clk *clk;
  1347. void __iomem *base;
  1348. unsigned int irq;
  1349. int err = 0;
  1350. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1351. irq = platform_get_irq(pdev, 0);
  1352. if (!res || (int)irq <= 0) {
  1353. err = -ENODEV;
  1354. goto exit;
  1355. }
  1356. clk = clk_get(&pdev->dev, "armper_ck");
  1357. if (IS_ERR(clk)) {
  1358. err = PTR_ERR(clk);
  1359. goto exit;
  1360. }
  1361. pcdev = kzalloc(sizeof(*pcdev) + resource_size(res), GFP_KERNEL);
  1362. if (!pcdev) {
  1363. dev_err(&pdev->dev, "Could not allocate pcdev\n");
  1364. err = -ENOMEM;
  1365. goto exit_put_clk;
  1366. }
  1367. pcdev->res = res;
  1368. pcdev->clk = clk;
  1369. pcdev->pdata = pdev->dev.platform_data;
  1370. if (pcdev->pdata) {
  1371. pcdev->pflags = pcdev->pdata->flags;
  1372. pcdev->camexclk = pcdev->pdata->camexclk_khz * 1000;
  1373. }
  1374. switch (pcdev->camexclk) {
  1375. case 6000000:
  1376. case 8000000:
  1377. case 9600000:
  1378. case 12000000:
  1379. case 24000000:
  1380. break;
  1381. default:
  1382. /* pcdev->camexclk != 0 => pcdev->pdata != NULL */
  1383. dev_warn(&pdev->dev,
  1384. "Incorrect sensor clock frequency %ld kHz, "
  1385. "should be one of 0, 6, 8, 9.6, 12 or 24 MHz, "
  1386. "please correct your platform data\n",
  1387. pcdev->pdata->camexclk_khz);
  1388. pcdev->camexclk = 0;
  1389. case 0:
  1390. dev_info(&pdev->dev, "Not providing sensor clock\n");
  1391. }
  1392. INIT_LIST_HEAD(&pcdev->capture);
  1393. spin_lock_init(&pcdev->lock);
  1394. /*
  1395. * Request the region.
  1396. */
  1397. if (!request_mem_region(res->start, resource_size(res), DRIVER_NAME)) {
  1398. err = -EBUSY;
  1399. goto exit_kfree;
  1400. }
  1401. base = ioremap(res->start, resource_size(res));
  1402. if (!base) {
  1403. err = -ENOMEM;
  1404. goto exit_release;
  1405. }
  1406. pcdev->irq = irq;
  1407. pcdev->base = base;
  1408. sensor_reset(pcdev, true);
  1409. err = omap_request_dma(OMAP_DMA_CAMERA_IF_RX, DRIVER_NAME,
  1410. dma_isr, (void *)pcdev, &pcdev->dma_ch);
  1411. if (err < 0) {
  1412. dev_err(&pdev->dev, "Can't request DMA for OMAP1 Camera\n");
  1413. err = -EBUSY;
  1414. goto exit_iounmap;
  1415. }
  1416. dev_dbg(&pdev->dev, "got DMA channel %d\n", pcdev->dma_ch);
  1417. /* preconfigure DMA */
  1418. omap_set_dma_src_params(pcdev->dma_ch, OMAP_DMA_PORT_TIPB,
  1419. OMAP_DMA_AMODE_CONSTANT, res->start + REG_CAMDATA,
  1420. 0, 0);
  1421. omap_set_dma_dest_burst_mode(pcdev->dma_ch, OMAP_DMA_DATA_BURST_4);
  1422. /* setup DMA autoinitialization */
  1423. omap_dma_link_lch(pcdev->dma_ch, pcdev->dma_ch);
  1424. err = request_irq(pcdev->irq, cam_isr, 0, DRIVER_NAME, pcdev);
  1425. if (err) {
  1426. dev_err(&pdev->dev, "Camera interrupt register failed\n");
  1427. goto exit_free_dma;
  1428. }
  1429. pcdev->soc_host.drv_name = DRIVER_NAME;
  1430. pcdev->soc_host.ops = &omap1_host_ops;
  1431. pcdev->soc_host.priv = pcdev;
  1432. pcdev->soc_host.v4l2_dev.dev = &pdev->dev;
  1433. pcdev->soc_host.nr = pdev->id;
  1434. err = soc_camera_host_register(&pcdev->soc_host);
  1435. if (err)
  1436. goto exit_free_irq;
  1437. dev_info(&pdev->dev, "OMAP1 Camera Interface driver loaded\n");
  1438. return 0;
  1439. exit_free_irq:
  1440. free_irq(pcdev->irq, pcdev);
  1441. exit_free_dma:
  1442. omap_free_dma(pcdev->dma_ch);
  1443. exit_iounmap:
  1444. iounmap(base);
  1445. exit_release:
  1446. release_mem_region(res->start, resource_size(res));
  1447. exit_kfree:
  1448. kfree(pcdev);
  1449. exit_put_clk:
  1450. clk_put(clk);
  1451. exit:
  1452. return err;
  1453. }
  1454. static int omap1_cam_remove(struct platform_device *pdev)
  1455. {
  1456. struct soc_camera_host *soc_host = to_soc_camera_host(&pdev->dev);
  1457. struct omap1_cam_dev *pcdev = container_of(soc_host,
  1458. struct omap1_cam_dev, soc_host);
  1459. struct resource *res;
  1460. free_irq(pcdev->irq, pcdev);
  1461. omap_free_dma(pcdev->dma_ch);
  1462. soc_camera_host_unregister(soc_host);
  1463. iounmap(pcdev->base);
  1464. res = pcdev->res;
  1465. release_mem_region(res->start, resource_size(res));
  1466. clk_put(pcdev->clk);
  1467. kfree(pcdev);
  1468. dev_info(&pdev->dev, "OMAP1 Camera Interface driver unloaded\n");
  1469. return 0;
  1470. }
  1471. static struct platform_driver omap1_cam_driver = {
  1472. .driver = {
  1473. .name = DRIVER_NAME,
  1474. },
  1475. .probe = omap1_cam_probe,
  1476. .remove = omap1_cam_remove,
  1477. };
  1478. module_platform_driver(omap1_cam_driver);
  1479. module_param(sg_mode, bool, 0644);
  1480. MODULE_PARM_DESC(sg_mode, "videobuf mode, 0: dma-contig (default), 1: dma-sg");
  1481. MODULE_DESCRIPTION("OMAP1 Camera Interface driver");
  1482. MODULE_AUTHOR("Janusz Krzysztofik <jkrzyszt@tis.icnet.pl>");
  1483. MODULE_LICENSE("GPL v2");
  1484. MODULE_VERSION(DRIVER_VERSION);
  1485. MODULE_ALIAS("platform:" DRIVER_NAME);