vpbe_display.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825
  1. /*
  2. * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation version 2.
  7. *
  8. * This program is distributed WITHOUT ANY WARRANTY of any
  9. * kind, whether express or implied; without even the implied warranty
  10. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/module.h>
  16. #include <linux/errno.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/string.h>
  19. #include <linux/wait.h>
  20. #include <linux/time.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/irq.h>
  23. #include <linux/mm.h>
  24. #include <linux/mutex.h>
  25. #include <linux/videodev2.h>
  26. #include <linux/slab.h>
  27. #include <asm/pgtable.h>
  28. #include <mach/cputype.h>
  29. #include <media/v4l2-dev.h>
  30. #include <media/v4l2-common.h>
  31. #include <media/v4l2-ioctl.h>
  32. #include <media/v4l2-device.h>
  33. #include <media/davinci/vpbe_display.h>
  34. #include <media/davinci/vpbe_types.h>
  35. #include <media/davinci/vpbe.h>
  36. #include <media/davinci/vpbe_venc.h>
  37. #include <media/davinci/vpbe_osd.h>
  38. #include "vpbe_venc_regs.h"
  39. #define VPBE_DISPLAY_DRIVER "vpbe-v4l2"
  40. static int debug;
  41. #define VPBE_DEFAULT_NUM_BUFS 3
  42. module_param(debug, int, 0644);
  43. static int venc_is_second_field(struct vpbe_display *disp_dev)
  44. {
  45. struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
  46. int ret;
  47. int val;
  48. ret = v4l2_subdev_call(vpbe_dev->venc,
  49. core,
  50. ioctl,
  51. VENC_GET_FLD,
  52. &val);
  53. if (ret < 0) {
  54. v4l2_err(&vpbe_dev->v4l2_dev,
  55. "Error in getting Field ID 0\n");
  56. }
  57. return val;
  58. }
  59. static void vpbe_isr_even_field(struct vpbe_display *disp_obj,
  60. struct vpbe_layer *layer)
  61. {
  62. struct timespec timevalue;
  63. if (layer->cur_frm == layer->next_frm)
  64. return;
  65. ktime_get_ts(&timevalue);
  66. layer->cur_frm->ts.tv_sec = timevalue.tv_sec;
  67. layer->cur_frm->ts.tv_usec = timevalue.tv_nsec / NSEC_PER_USEC;
  68. layer->cur_frm->state = VIDEOBUF_DONE;
  69. wake_up_interruptible(&layer->cur_frm->done);
  70. /* Make cur_frm pointing to next_frm */
  71. layer->cur_frm = layer->next_frm;
  72. }
  73. static void vpbe_isr_odd_field(struct vpbe_display *disp_obj,
  74. struct vpbe_layer *layer)
  75. {
  76. struct osd_state *osd_device = disp_obj->osd_device;
  77. unsigned long addr;
  78. spin_lock(&disp_obj->dma_queue_lock);
  79. if (list_empty(&layer->dma_queue) ||
  80. (layer->cur_frm != layer->next_frm)) {
  81. spin_unlock(&disp_obj->dma_queue_lock);
  82. return;
  83. }
  84. /*
  85. * one field is displayed configure
  86. * the next frame if it is available
  87. * otherwise hold on current frame
  88. * Get next from the buffer queue
  89. */
  90. layer->next_frm = list_entry(
  91. layer->dma_queue.next,
  92. struct videobuf_buffer,
  93. queue);
  94. /* Remove that from the buffer queue */
  95. list_del(&layer->next_frm->queue);
  96. spin_unlock(&disp_obj->dma_queue_lock);
  97. /* Mark state of the frame to active */
  98. layer->next_frm->state = VIDEOBUF_ACTIVE;
  99. addr = videobuf_to_dma_contig(layer->next_frm);
  100. osd_device->ops.start_layer(osd_device,
  101. layer->layer_info.id,
  102. addr,
  103. disp_obj->cbcr_ofst);
  104. }
  105. /* interrupt service routine */
  106. static irqreturn_t venc_isr(int irq, void *arg)
  107. {
  108. struct vpbe_display *disp_dev = (struct vpbe_display *)arg;
  109. struct vpbe_layer *layer;
  110. static unsigned last_event;
  111. unsigned event = 0;
  112. int fid;
  113. int i;
  114. if ((NULL == arg) || (NULL == disp_dev->dev[0]))
  115. return IRQ_HANDLED;
  116. if (venc_is_second_field(disp_dev))
  117. event |= VENC_SECOND_FIELD;
  118. else
  119. event |= VENC_FIRST_FIELD;
  120. if (event == (last_event & ~VENC_END_OF_FRAME)) {
  121. /*
  122. * If the display is non-interlaced, then we need to flag the
  123. * end-of-frame event at every interrupt regardless of the
  124. * value of the FIDST bit. We can conclude that the display is
  125. * non-interlaced if the value of the FIDST bit is unchanged
  126. * from the previous interrupt.
  127. */
  128. event |= VENC_END_OF_FRAME;
  129. } else if (event == VENC_SECOND_FIELD) {
  130. /* end-of-frame for interlaced display */
  131. event |= VENC_END_OF_FRAME;
  132. }
  133. last_event = event;
  134. for (i = 0; i < VPBE_DISPLAY_MAX_DEVICES; i++) {
  135. layer = disp_dev->dev[i];
  136. /* If streaming is started in this layer */
  137. if (!layer->started)
  138. continue;
  139. if (layer->layer_first_int) {
  140. layer->layer_first_int = 0;
  141. continue;
  142. }
  143. /* Check the field format */
  144. if ((V4L2_FIELD_NONE == layer->pix_fmt.field) &&
  145. (event & VENC_END_OF_FRAME)) {
  146. /* Progressive mode */
  147. vpbe_isr_even_field(disp_dev, layer);
  148. vpbe_isr_odd_field(disp_dev, layer);
  149. } else {
  150. /* Interlaced mode */
  151. layer->field_id ^= 1;
  152. if (event & VENC_FIRST_FIELD)
  153. fid = 0;
  154. else
  155. fid = 1;
  156. /*
  157. * If field id does not match with store
  158. * field id
  159. */
  160. if (fid != layer->field_id) {
  161. /* Make them in sync */
  162. layer->field_id = fid;
  163. continue;
  164. }
  165. /*
  166. * device field id and local field id are
  167. * in sync. If this is even field
  168. */
  169. if (0 == fid)
  170. vpbe_isr_even_field(disp_dev, layer);
  171. else /* odd field */
  172. vpbe_isr_odd_field(disp_dev, layer);
  173. }
  174. }
  175. return IRQ_HANDLED;
  176. }
  177. /*
  178. * vpbe_buffer_prepare()
  179. * This is the callback function called from videobuf_qbuf() function
  180. * the buffer is prepared and user space virtual address is converted into
  181. * physical address
  182. */
  183. static int vpbe_buffer_prepare(struct videobuf_queue *q,
  184. struct videobuf_buffer *vb,
  185. enum v4l2_field field)
  186. {
  187. struct vpbe_fh *fh = q->priv_data;
  188. struct vpbe_layer *layer = fh->layer;
  189. struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
  190. unsigned long addr;
  191. int ret;
  192. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
  193. "vpbe_buffer_prepare\n");
  194. /* If buffer is not initialized, initialize it */
  195. if (VIDEOBUF_NEEDS_INIT == vb->state) {
  196. vb->width = layer->pix_fmt.width;
  197. vb->height = layer->pix_fmt.height;
  198. vb->size = layer->pix_fmt.sizeimage;
  199. vb->field = field;
  200. ret = videobuf_iolock(q, vb, NULL);
  201. if (ret < 0) {
  202. v4l2_err(&vpbe_dev->v4l2_dev, "Failed to map \
  203. user address\n");
  204. return -EINVAL;
  205. }
  206. addr = videobuf_to_dma_contig(vb);
  207. if (q->streaming) {
  208. if (!IS_ALIGNED(addr, 8)) {
  209. v4l2_err(&vpbe_dev->v4l2_dev,
  210. "buffer_prepare:offset is \
  211. not aligned to 32 bytes\n");
  212. return -EINVAL;
  213. }
  214. }
  215. vb->state = VIDEOBUF_PREPARED;
  216. }
  217. return 0;
  218. }
  219. /*
  220. * vpbe_buffer_setup()
  221. * This function allocates memory for the buffers
  222. */
  223. static int vpbe_buffer_setup(struct videobuf_queue *q,
  224. unsigned int *count,
  225. unsigned int *size)
  226. {
  227. /* Get the file handle object and layer object */
  228. struct vpbe_fh *fh = q->priv_data;
  229. struct vpbe_layer *layer = fh->layer;
  230. struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
  231. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_buffer_setup\n");
  232. *size = layer->pix_fmt.sizeimage;
  233. /* Store number of buffers allocated in numbuffer member */
  234. if (*count < VPBE_DEFAULT_NUM_BUFS)
  235. *count = layer->numbuffers = VPBE_DEFAULT_NUM_BUFS;
  236. return 0;
  237. }
  238. /*
  239. * vpbe_buffer_queue()
  240. * This function adds the buffer to DMA queue
  241. */
  242. static void vpbe_buffer_queue(struct videobuf_queue *q,
  243. struct videobuf_buffer *vb)
  244. {
  245. /* Get the file handle object and layer object */
  246. struct vpbe_fh *fh = q->priv_data;
  247. struct vpbe_layer *layer = fh->layer;
  248. struct vpbe_display *disp = fh->disp_dev;
  249. struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
  250. unsigned long flags;
  251. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
  252. "vpbe_buffer_queue\n");
  253. /* add the buffer to the DMA queue */
  254. spin_lock_irqsave(&disp->dma_queue_lock, flags);
  255. list_add_tail(&vb->queue, &layer->dma_queue);
  256. spin_unlock_irqrestore(&disp->dma_queue_lock, flags);
  257. /* Change state of the buffer */
  258. vb->state = VIDEOBUF_QUEUED;
  259. }
  260. /*
  261. * vpbe_buffer_release()
  262. * This function is called from the videobuf layer to free memory allocated to
  263. * the buffers
  264. */
  265. static void vpbe_buffer_release(struct videobuf_queue *q,
  266. struct videobuf_buffer *vb)
  267. {
  268. /* Get the file handle object and layer object */
  269. struct vpbe_fh *fh = q->priv_data;
  270. struct vpbe_layer *layer = fh->layer;
  271. struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
  272. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
  273. "vpbe_buffer_release\n");
  274. if (V4L2_MEMORY_USERPTR != layer->memory)
  275. videobuf_dma_contig_free(q, vb);
  276. vb->state = VIDEOBUF_NEEDS_INIT;
  277. }
  278. static struct videobuf_queue_ops video_qops = {
  279. .buf_setup = vpbe_buffer_setup,
  280. .buf_prepare = vpbe_buffer_prepare,
  281. .buf_queue = vpbe_buffer_queue,
  282. .buf_release = vpbe_buffer_release,
  283. };
  284. static
  285. struct vpbe_layer*
  286. _vpbe_display_get_other_win_layer(struct vpbe_display *disp_dev,
  287. struct vpbe_layer *layer)
  288. {
  289. enum vpbe_display_device_id thiswin, otherwin;
  290. thiswin = layer->device_id;
  291. otherwin = (thiswin == VPBE_DISPLAY_DEVICE_0) ?
  292. VPBE_DISPLAY_DEVICE_1 : VPBE_DISPLAY_DEVICE_0;
  293. return disp_dev->dev[otherwin];
  294. }
  295. static int vpbe_set_osd_display_params(struct vpbe_display *disp_dev,
  296. struct vpbe_layer *layer)
  297. {
  298. struct osd_layer_config *cfg = &layer->layer_info.config;
  299. struct osd_state *osd_device = disp_dev->osd_device;
  300. struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
  301. unsigned long addr;
  302. int ret;
  303. addr = videobuf_to_dma_contig(layer->cur_frm);
  304. /* Set address in the display registers */
  305. osd_device->ops.start_layer(osd_device,
  306. layer->layer_info.id,
  307. addr,
  308. disp_dev->cbcr_ofst);
  309. ret = osd_device->ops.enable_layer(osd_device,
  310. layer->layer_info.id, 0);
  311. if (ret < 0) {
  312. v4l2_err(&vpbe_dev->v4l2_dev,
  313. "Error in enabling osd window layer 0\n");
  314. return -1;
  315. }
  316. /* Enable the window */
  317. layer->layer_info.enable = 1;
  318. if (cfg->pixfmt == PIXFMT_NV12) {
  319. struct vpbe_layer *otherlayer =
  320. _vpbe_display_get_other_win_layer(disp_dev, layer);
  321. ret = osd_device->ops.enable_layer(osd_device,
  322. otherlayer->layer_info.id, 1);
  323. if (ret < 0) {
  324. v4l2_err(&vpbe_dev->v4l2_dev,
  325. "Error in enabling osd window layer 1\n");
  326. return -1;
  327. }
  328. otherlayer->layer_info.enable = 1;
  329. }
  330. return 0;
  331. }
  332. static void
  333. vpbe_disp_calculate_scale_factor(struct vpbe_display *disp_dev,
  334. struct vpbe_layer *layer,
  335. int expected_xsize, int expected_ysize)
  336. {
  337. struct display_layer_info *layer_info = &layer->layer_info;
  338. struct v4l2_pix_format *pixfmt = &layer->pix_fmt;
  339. struct osd_layer_config *cfg = &layer->layer_info.config;
  340. struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
  341. int calculated_xsize;
  342. int h_exp = 0;
  343. int v_exp = 0;
  344. int h_scale;
  345. int v_scale;
  346. v4l2_std_id standard_id = vpbe_dev->current_timings.timings.std_id;
  347. /*
  348. * Application initially set the image format. Current display
  349. * size is obtained from the vpbe display controller. expected_xsize
  350. * and expected_ysize are set through S_CROP ioctl. Based on this,
  351. * driver will calculate the scale factors for vertical and
  352. * horizontal direction so that the image is displayed scaled
  353. * and expanded. Application uses expansion to display the image
  354. * in a square pixel. Otherwise it is displayed using displays
  355. * pixel aspect ratio.It is expected that application chooses
  356. * the crop coordinates for cropped or scaled display. if crop
  357. * size is less than the image size, it is displayed cropped or
  358. * it is displayed scaled and/or expanded.
  359. *
  360. * to begin with, set the crop window same as expected. Later we
  361. * will override with scaled window size
  362. */
  363. cfg->xsize = pixfmt->width;
  364. cfg->ysize = pixfmt->height;
  365. layer_info->h_zoom = ZOOM_X1; /* no horizontal zoom */
  366. layer_info->v_zoom = ZOOM_X1; /* no horizontal zoom */
  367. layer_info->h_exp = H_EXP_OFF; /* no horizontal zoom */
  368. layer_info->v_exp = V_EXP_OFF; /* no horizontal zoom */
  369. if (pixfmt->width < expected_xsize) {
  370. h_scale = vpbe_dev->current_timings.xres / pixfmt->width;
  371. if (h_scale < 2)
  372. h_scale = 1;
  373. else if (h_scale >= 4)
  374. h_scale = 4;
  375. else
  376. h_scale = 2;
  377. cfg->xsize *= h_scale;
  378. if (cfg->xsize < expected_xsize) {
  379. if ((standard_id & V4L2_STD_525_60) ||
  380. (standard_id & V4L2_STD_625_50)) {
  381. calculated_xsize = (cfg->xsize *
  382. VPBE_DISPLAY_H_EXP_RATIO_N) /
  383. VPBE_DISPLAY_H_EXP_RATIO_D;
  384. if (calculated_xsize <= expected_xsize) {
  385. h_exp = 1;
  386. cfg->xsize = calculated_xsize;
  387. }
  388. }
  389. }
  390. if (h_scale == 2)
  391. layer_info->h_zoom = ZOOM_X2;
  392. else if (h_scale == 4)
  393. layer_info->h_zoom = ZOOM_X4;
  394. if (h_exp)
  395. layer_info->h_exp = H_EXP_9_OVER_8;
  396. } else {
  397. /* no scaling, only cropping. Set display area to crop area */
  398. cfg->xsize = expected_xsize;
  399. }
  400. if (pixfmt->height < expected_ysize) {
  401. v_scale = expected_ysize / pixfmt->height;
  402. if (v_scale < 2)
  403. v_scale = 1;
  404. else if (v_scale >= 4)
  405. v_scale = 4;
  406. else
  407. v_scale = 2;
  408. cfg->ysize *= v_scale;
  409. if (cfg->ysize < expected_ysize) {
  410. if ((standard_id & V4L2_STD_625_50)) {
  411. calculated_xsize = (cfg->ysize *
  412. VPBE_DISPLAY_V_EXP_RATIO_N) /
  413. VPBE_DISPLAY_V_EXP_RATIO_D;
  414. if (calculated_xsize <= expected_ysize) {
  415. v_exp = 1;
  416. cfg->ysize = calculated_xsize;
  417. }
  418. }
  419. }
  420. if (v_scale == 2)
  421. layer_info->v_zoom = ZOOM_X2;
  422. else if (v_scale == 4)
  423. layer_info->v_zoom = ZOOM_X4;
  424. if (v_exp)
  425. layer_info->h_exp = V_EXP_6_OVER_5;
  426. } else {
  427. /* no scaling, only cropping. Set display area to crop area */
  428. cfg->ysize = expected_ysize;
  429. }
  430. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
  431. "crop display xsize = %d, ysize = %d\n",
  432. cfg->xsize, cfg->ysize);
  433. }
  434. static void vpbe_disp_adj_position(struct vpbe_display *disp_dev,
  435. struct vpbe_layer *layer,
  436. int top, int left)
  437. {
  438. struct osd_layer_config *cfg = &layer->layer_info.config;
  439. struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
  440. cfg->xpos = min((unsigned int)left,
  441. vpbe_dev->current_timings.xres - cfg->xsize);
  442. cfg->ypos = min((unsigned int)top,
  443. vpbe_dev->current_timings.yres - cfg->ysize);
  444. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
  445. "new xpos = %d, ypos = %d\n",
  446. cfg->xpos, cfg->ypos);
  447. }
  448. static void vpbe_disp_check_window_params(struct vpbe_display *disp_dev,
  449. struct v4l2_rect *c)
  450. {
  451. struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
  452. if ((c->width == 0) ||
  453. ((c->width + c->left) > vpbe_dev->current_timings.xres))
  454. c->width = vpbe_dev->current_timings.xres - c->left;
  455. if ((c->height == 0) || ((c->height + c->top) >
  456. vpbe_dev->current_timings.yres))
  457. c->height = vpbe_dev->current_timings.yres - c->top;
  458. /* window height must be even for interlaced display */
  459. if (vpbe_dev->current_timings.interlaced)
  460. c->height &= (~0x01);
  461. }
  462. /**
  463. * vpbe_try_format()
  464. * If user application provides width and height, and have bytesperline set
  465. * to zero, driver calculates bytesperline and sizeimage based on hardware
  466. * limits.
  467. */
  468. static int vpbe_try_format(struct vpbe_display *disp_dev,
  469. struct v4l2_pix_format *pixfmt, int check)
  470. {
  471. struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
  472. int min_height = 1;
  473. int min_width = 32;
  474. int max_height;
  475. int max_width;
  476. int bpp;
  477. if ((pixfmt->pixelformat != V4L2_PIX_FMT_UYVY) &&
  478. (pixfmt->pixelformat != V4L2_PIX_FMT_NV12))
  479. /* choose default as V4L2_PIX_FMT_UYVY */
  480. pixfmt->pixelformat = V4L2_PIX_FMT_UYVY;
  481. /* Check the field format */
  482. if ((pixfmt->field != V4L2_FIELD_INTERLACED) &&
  483. (pixfmt->field != V4L2_FIELD_NONE)) {
  484. if (vpbe_dev->current_timings.interlaced)
  485. pixfmt->field = V4L2_FIELD_INTERLACED;
  486. else
  487. pixfmt->field = V4L2_FIELD_NONE;
  488. }
  489. if (pixfmt->field == V4L2_FIELD_INTERLACED)
  490. min_height = 2;
  491. if (pixfmt->pixelformat == V4L2_PIX_FMT_NV12)
  492. bpp = 1;
  493. else
  494. bpp = 2;
  495. max_width = vpbe_dev->current_timings.xres;
  496. max_height = vpbe_dev->current_timings.yres;
  497. min_width /= bpp;
  498. if (!pixfmt->width || (pixfmt->width < min_width) ||
  499. (pixfmt->width > max_width)) {
  500. pixfmt->width = vpbe_dev->current_timings.xres;
  501. }
  502. if (!pixfmt->height || (pixfmt->height < min_height) ||
  503. (pixfmt->height > max_height)) {
  504. pixfmt->height = vpbe_dev->current_timings.yres;
  505. }
  506. if (pixfmt->bytesperline < (pixfmt->width * bpp))
  507. pixfmt->bytesperline = pixfmt->width * bpp;
  508. /* Make the bytesperline 32 byte aligned */
  509. pixfmt->bytesperline = ((pixfmt->width * bpp + 31) & ~31);
  510. if (pixfmt->pixelformat == V4L2_PIX_FMT_NV12)
  511. pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height +
  512. (pixfmt->bytesperline * pixfmt->height >> 1);
  513. else
  514. pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height;
  515. return 0;
  516. }
  517. static int vpbe_display_g_priority(struct file *file, void *priv,
  518. enum v4l2_priority *p)
  519. {
  520. struct vpbe_fh *fh = file->private_data;
  521. struct vpbe_layer *layer = fh->layer;
  522. *p = v4l2_prio_max(&layer->prio);
  523. return 0;
  524. }
  525. static int vpbe_display_s_priority(struct file *file, void *priv,
  526. enum v4l2_priority p)
  527. {
  528. struct vpbe_fh *fh = file->private_data;
  529. struct vpbe_layer *layer = fh->layer;
  530. int ret;
  531. ret = v4l2_prio_change(&layer->prio, &fh->prio, p);
  532. return ret;
  533. }
  534. static int vpbe_display_querycap(struct file *file, void *priv,
  535. struct v4l2_capability *cap)
  536. {
  537. struct vpbe_fh *fh = file->private_data;
  538. struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
  539. cap->version = VPBE_DISPLAY_VERSION_CODE;
  540. cap->capabilities = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
  541. strlcpy(cap->driver, VPBE_DISPLAY_DRIVER, sizeof(cap->driver));
  542. strlcpy(cap->bus_info, "platform", sizeof(cap->bus_info));
  543. strlcpy(cap->card, vpbe_dev->cfg->module_name, sizeof(cap->card));
  544. return 0;
  545. }
  546. static int vpbe_display_s_crop(struct file *file, void *priv,
  547. struct v4l2_crop *crop)
  548. {
  549. struct vpbe_fh *fh = file->private_data;
  550. struct vpbe_layer *layer = fh->layer;
  551. struct vpbe_display *disp_dev = fh->disp_dev;
  552. struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
  553. struct osd_layer_config *cfg = &layer->layer_info.config;
  554. struct osd_state *osd_device = disp_dev->osd_device;
  555. struct v4l2_rect *rect = &crop->c;
  556. int ret;
  557. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
  558. "VIDIOC_S_CROP, layer id = %d\n", layer->device_id);
  559. if (crop->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) {
  560. v4l2_err(&vpbe_dev->v4l2_dev, "Invalid buf type\n");
  561. return -EINVAL;
  562. }
  563. if (rect->top < 0)
  564. rect->top = 0;
  565. if (rect->left < 0)
  566. rect->left = 0;
  567. vpbe_disp_check_window_params(disp_dev, rect);
  568. osd_device->ops.get_layer_config(osd_device,
  569. layer->layer_info.id, cfg);
  570. vpbe_disp_calculate_scale_factor(disp_dev, layer,
  571. rect->width,
  572. rect->height);
  573. vpbe_disp_adj_position(disp_dev, layer, rect->top,
  574. rect->left);
  575. ret = osd_device->ops.set_layer_config(osd_device,
  576. layer->layer_info.id, cfg);
  577. if (ret < 0) {
  578. v4l2_err(&vpbe_dev->v4l2_dev,
  579. "Error in set layer config:\n");
  580. return -EINVAL;
  581. }
  582. /* apply zooming and h or v expansion */
  583. osd_device->ops.set_zoom(osd_device,
  584. layer->layer_info.id,
  585. layer->layer_info.h_zoom,
  586. layer->layer_info.v_zoom);
  587. ret = osd_device->ops.set_vid_expansion(osd_device,
  588. layer->layer_info.h_exp,
  589. layer->layer_info.v_exp);
  590. if (ret < 0) {
  591. v4l2_err(&vpbe_dev->v4l2_dev,
  592. "Error in set vid expansion:\n");
  593. return -EINVAL;
  594. }
  595. if ((layer->layer_info.h_zoom != ZOOM_X1) ||
  596. (layer->layer_info.v_zoom != ZOOM_X1) ||
  597. (layer->layer_info.h_exp != H_EXP_OFF) ||
  598. (layer->layer_info.v_exp != V_EXP_OFF))
  599. /* Enable expansion filter */
  600. osd_device->ops.set_interpolation_filter(osd_device, 1);
  601. else
  602. osd_device->ops.set_interpolation_filter(osd_device, 0);
  603. return 0;
  604. }
  605. static int vpbe_display_g_crop(struct file *file, void *priv,
  606. struct v4l2_crop *crop)
  607. {
  608. struct vpbe_fh *fh = file->private_data;
  609. struct vpbe_layer *layer = fh->layer;
  610. struct osd_layer_config *cfg = &layer->layer_info.config;
  611. struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
  612. struct osd_state *osd_device = fh->disp_dev->osd_device;
  613. struct v4l2_rect *rect = &crop->c;
  614. int ret;
  615. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
  616. "VIDIOC_G_CROP, layer id = %d\n",
  617. layer->device_id);
  618. if (crop->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) {
  619. v4l2_err(&vpbe_dev->v4l2_dev, "Invalid buf type\n");
  620. ret = -EINVAL;
  621. }
  622. osd_device->ops.get_layer_config(osd_device,
  623. layer->layer_info.id, cfg);
  624. rect->top = cfg->ypos;
  625. rect->left = cfg->xpos;
  626. rect->width = cfg->xsize;
  627. rect->height = cfg->ysize;
  628. return 0;
  629. }
  630. static int vpbe_display_cropcap(struct file *file, void *priv,
  631. struct v4l2_cropcap *cropcap)
  632. {
  633. struct vpbe_fh *fh = file->private_data;
  634. struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
  635. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_CROPCAP ioctl\n");
  636. cropcap->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
  637. cropcap->bounds.left = 0;
  638. cropcap->bounds.top = 0;
  639. cropcap->bounds.width = vpbe_dev->current_timings.xres;
  640. cropcap->bounds.height = vpbe_dev->current_timings.yres;
  641. cropcap->pixelaspect = vpbe_dev->current_timings.aspect;
  642. cropcap->defrect = cropcap->bounds;
  643. return 0;
  644. }
  645. static int vpbe_display_g_fmt(struct file *file, void *priv,
  646. struct v4l2_format *fmt)
  647. {
  648. struct vpbe_fh *fh = file->private_data;
  649. struct vpbe_layer *layer = fh->layer;
  650. struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
  651. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
  652. "VIDIOC_G_FMT, layer id = %d\n",
  653. layer->device_id);
  654. /* If buffer type is video output */
  655. if (V4L2_BUF_TYPE_VIDEO_OUTPUT != fmt->type) {
  656. v4l2_err(&vpbe_dev->v4l2_dev, "invalid type\n");
  657. return -EINVAL;
  658. }
  659. /* Fill in the information about format */
  660. fmt->fmt.pix = layer->pix_fmt;
  661. return 0;
  662. }
  663. static int vpbe_display_enum_fmt(struct file *file, void *priv,
  664. struct v4l2_fmtdesc *fmt)
  665. {
  666. struct vpbe_fh *fh = file->private_data;
  667. struct vpbe_layer *layer = fh->layer;
  668. struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
  669. unsigned int index = 0;
  670. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
  671. "VIDIOC_ENUM_FMT, layer id = %d\n",
  672. layer->device_id);
  673. if (fmt->index > 1) {
  674. v4l2_err(&vpbe_dev->v4l2_dev, "Invalid format index\n");
  675. return -EINVAL;
  676. }
  677. /* Fill in the information about format */
  678. index = fmt->index;
  679. memset(fmt, 0, sizeof(*fmt));
  680. fmt->index = index;
  681. fmt->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
  682. if (index == 0) {
  683. strcpy(fmt->description, "YUV 4:2:2 - UYVY");
  684. fmt->pixelformat = V4L2_PIX_FMT_UYVY;
  685. } else {
  686. strcpy(fmt->description, "Y/CbCr 4:2:0");
  687. fmt->pixelformat = V4L2_PIX_FMT_NV12;
  688. }
  689. return 0;
  690. }
  691. static int vpbe_display_s_fmt(struct file *file, void *priv,
  692. struct v4l2_format *fmt)
  693. {
  694. struct vpbe_fh *fh = file->private_data;
  695. struct vpbe_layer *layer = fh->layer;
  696. struct vpbe_display *disp_dev = fh->disp_dev;
  697. struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
  698. struct osd_layer_config *cfg = &layer->layer_info.config;
  699. struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
  700. struct osd_state *osd_device = disp_dev->osd_device;
  701. int ret;
  702. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
  703. "VIDIOC_S_FMT, layer id = %d\n",
  704. layer->device_id);
  705. /* If streaming is started, return error */
  706. if (layer->started) {
  707. v4l2_err(&vpbe_dev->v4l2_dev, "Streaming is started\n");
  708. return -EBUSY;
  709. }
  710. if (V4L2_BUF_TYPE_VIDEO_OUTPUT != fmt->type) {
  711. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "invalid type\n");
  712. return -EINVAL;
  713. }
  714. /* Check for valid pixel format */
  715. ret = vpbe_try_format(disp_dev, pixfmt, 1);
  716. if (ret)
  717. return ret;
  718. /* YUV420 is requested, check availability of the
  719. other video window */
  720. layer->pix_fmt = *pixfmt;
  721. /* Get osd layer config */
  722. osd_device->ops.get_layer_config(osd_device,
  723. layer->layer_info.id, cfg);
  724. /* Store the pixel format in the layer object */
  725. cfg->xsize = pixfmt->width;
  726. cfg->ysize = pixfmt->height;
  727. cfg->line_length = pixfmt->bytesperline;
  728. cfg->ypos = 0;
  729. cfg->xpos = 0;
  730. cfg->interlaced = vpbe_dev->current_timings.interlaced;
  731. if (V4L2_PIX_FMT_UYVY == pixfmt->pixelformat)
  732. cfg->pixfmt = PIXFMT_YCbCrI;
  733. /* Change of the default pixel format for both video windows */
  734. if (V4L2_PIX_FMT_NV12 == pixfmt->pixelformat) {
  735. struct vpbe_layer *otherlayer;
  736. cfg->pixfmt = PIXFMT_NV12;
  737. otherlayer = _vpbe_display_get_other_win_layer(disp_dev,
  738. layer);
  739. otherlayer->layer_info.config.pixfmt = PIXFMT_NV12;
  740. }
  741. /* Set the layer config in the osd window */
  742. ret = osd_device->ops.set_layer_config(osd_device,
  743. layer->layer_info.id, cfg);
  744. if (ret < 0) {
  745. v4l2_err(&vpbe_dev->v4l2_dev,
  746. "Error in S_FMT params:\n");
  747. return -EINVAL;
  748. }
  749. /* Readback and fill the local copy of current pix format */
  750. osd_device->ops.get_layer_config(osd_device,
  751. layer->layer_info.id, cfg);
  752. return 0;
  753. }
  754. static int vpbe_display_try_fmt(struct file *file, void *priv,
  755. struct v4l2_format *fmt)
  756. {
  757. struct vpbe_fh *fh = file->private_data;
  758. struct vpbe_display *disp_dev = fh->disp_dev;
  759. struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
  760. struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
  761. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_TRY_FMT\n");
  762. if (V4L2_BUF_TYPE_VIDEO_OUTPUT != fmt->type) {
  763. v4l2_err(&vpbe_dev->v4l2_dev, "invalid type\n");
  764. return -EINVAL;
  765. }
  766. /* Check for valid field format */
  767. return vpbe_try_format(disp_dev, pixfmt, 0);
  768. }
  769. /**
  770. * vpbe_display_s_std - Set the given standard in the encoder
  771. *
  772. * Sets the standard if supported by the current encoder. Return the status.
  773. * 0 - success & -EINVAL on error
  774. */
  775. static int vpbe_display_s_std(struct file *file, void *priv,
  776. v4l2_std_id *std_id)
  777. {
  778. struct vpbe_fh *fh = priv;
  779. struct vpbe_layer *layer = fh->layer;
  780. struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
  781. int ret;
  782. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_S_STD\n");
  783. /* If streaming is started, return error */
  784. if (layer->started) {
  785. v4l2_err(&vpbe_dev->v4l2_dev, "Streaming is started\n");
  786. return -EBUSY;
  787. }
  788. if (NULL != vpbe_dev->ops.s_std) {
  789. ret = vpbe_dev->ops.s_std(vpbe_dev, std_id);
  790. if (ret) {
  791. v4l2_err(&vpbe_dev->v4l2_dev,
  792. "Failed to set standard for sub devices\n");
  793. return -EINVAL;
  794. }
  795. } else {
  796. return -EINVAL;
  797. }
  798. return 0;
  799. }
  800. /**
  801. * vpbe_display_g_std - Get the standard in the current encoder
  802. *
  803. * Get the standard in the current encoder. Return the status. 0 - success
  804. * -EINVAL on error
  805. */
  806. static int vpbe_display_g_std(struct file *file, void *priv,
  807. v4l2_std_id *std_id)
  808. {
  809. struct vpbe_fh *fh = priv;
  810. struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
  811. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_G_STD\n");
  812. /* Get the standard from the current encoder */
  813. if (vpbe_dev->current_timings.timings_type & VPBE_ENC_STD) {
  814. *std_id = vpbe_dev->current_timings.timings.std_id;
  815. return 0;
  816. }
  817. return -EINVAL;
  818. }
  819. /**
  820. * vpbe_display_enum_output - enumerate outputs
  821. *
  822. * Enumerates the outputs available at the vpbe display
  823. * returns the status, -EINVAL if end of output list
  824. */
  825. static int vpbe_display_enum_output(struct file *file, void *priv,
  826. struct v4l2_output *output)
  827. {
  828. struct vpbe_fh *fh = priv;
  829. struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
  830. int ret;
  831. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_ENUM_OUTPUT\n");
  832. /* Enumerate outputs */
  833. if (NULL == vpbe_dev->ops.enum_outputs)
  834. return -EINVAL;
  835. ret = vpbe_dev->ops.enum_outputs(vpbe_dev, output);
  836. if (ret) {
  837. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
  838. "Failed to enumerate outputs\n");
  839. return -EINVAL;
  840. }
  841. return 0;
  842. }
  843. /**
  844. * vpbe_display_s_output - Set output to
  845. * the output specified by the index
  846. */
  847. static int vpbe_display_s_output(struct file *file, void *priv,
  848. unsigned int i)
  849. {
  850. struct vpbe_fh *fh = priv;
  851. struct vpbe_layer *layer = fh->layer;
  852. struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
  853. int ret;
  854. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_S_OUTPUT\n");
  855. /* If streaming is started, return error */
  856. if (layer->started) {
  857. v4l2_err(&vpbe_dev->v4l2_dev, "Streaming is started\n");
  858. return -EBUSY;
  859. }
  860. if (NULL == vpbe_dev->ops.set_output)
  861. return -EINVAL;
  862. ret = vpbe_dev->ops.set_output(vpbe_dev, i);
  863. if (ret) {
  864. v4l2_err(&vpbe_dev->v4l2_dev,
  865. "Failed to set output for sub devices\n");
  866. return -EINVAL;
  867. }
  868. return 0;
  869. }
  870. /**
  871. * vpbe_display_g_output - Get output from subdevice
  872. * for a given by the index
  873. */
  874. static int vpbe_display_g_output(struct file *file, void *priv,
  875. unsigned int *i)
  876. {
  877. struct vpbe_fh *fh = priv;
  878. struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
  879. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_G_OUTPUT\n");
  880. /* Get the standard from the current encoder */
  881. *i = vpbe_dev->current_out_index;
  882. return 0;
  883. }
  884. /**
  885. * vpbe_display_enum_dv_presets - Enumerate the dv presets
  886. *
  887. * enum the preset in the current encoder. Return the status. 0 - success
  888. * -EINVAL on error
  889. */
  890. static int
  891. vpbe_display_enum_dv_presets(struct file *file, void *priv,
  892. struct v4l2_dv_enum_preset *preset)
  893. {
  894. struct vpbe_fh *fh = priv;
  895. struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
  896. int ret;
  897. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_ENUM_DV_PRESETS\n");
  898. /* Enumerate outputs */
  899. if (NULL == vpbe_dev->ops.enum_dv_presets)
  900. return -EINVAL;
  901. ret = vpbe_dev->ops.enum_dv_presets(vpbe_dev, preset);
  902. if (ret) {
  903. v4l2_err(&vpbe_dev->v4l2_dev,
  904. "Failed to enumerate dv presets info\n");
  905. return -EINVAL;
  906. }
  907. return 0;
  908. }
  909. /**
  910. * vpbe_display_s_dv_preset - Set the dv presets
  911. *
  912. * Set the preset in the current encoder. Return the status. 0 - success
  913. * -EINVAL on error
  914. */
  915. static int
  916. vpbe_display_s_dv_preset(struct file *file, void *priv,
  917. struct v4l2_dv_preset *preset)
  918. {
  919. struct vpbe_fh *fh = priv;
  920. struct vpbe_layer *layer = fh->layer;
  921. struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
  922. int ret;
  923. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_S_DV_PRESETS\n");
  924. /* If streaming is started, return error */
  925. if (layer->started) {
  926. v4l2_err(&vpbe_dev->v4l2_dev, "Streaming is started\n");
  927. return -EBUSY;
  928. }
  929. /* Set the given standard in the encoder */
  930. if (NULL != vpbe_dev->ops.s_dv_preset)
  931. return -EINVAL;
  932. ret = vpbe_dev->ops.s_dv_preset(vpbe_dev, preset);
  933. if (ret) {
  934. v4l2_err(&vpbe_dev->v4l2_dev,
  935. "Failed to set the dv presets info\n");
  936. return -EINVAL;
  937. }
  938. /* set the current norm to zero to be consistent. If STD is used
  939. * v4l2 layer will set the norm properly on successful s_std call
  940. */
  941. layer->video_dev.current_norm = 0;
  942. return 0;
  943. }
  944. /**
  945. * vpbe_display_g_dv_preset - Set the dv presets
  946. *
  947. * Get the preset in the current encoder. Return the status. 0 - success
  948. * -EINVAL on error
  949. */
  950. static int
  951. vpbe_display_g_dv_preset(struct file *file, void *priv,
  952. struct v4l2_dv_preset *dv_preset)
  953. {
  954. struct vpbe_fh *fh = priv;
  955. struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
  956. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_G_DV_PRESETS\n");
  957. /* Get the given standard in the encoder */
  958. if (vpbe_dev->current_timings.timings_type &
  959. VPBE_ENC_DV_PRESET) {
  960. dv_preset->preset =
  961. vpbe_dev->current_timings.timings.dv_preset;
  962. } else {
  963. return -EINVAL;
  964. }
  965. return 0;
  966. }
  967. static int vpbe_display_streamoff(struct file *file, void *priv,
  968. enum v4l2_buf_type buf_type)
  969. {
  970. struct vpbe_fh *fh = file->private_data;
  971. struct vpbe_layer *layer = fh->layer;
  972. struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
  973. struct osd_state *osd_device = fh->disp_dev->osd_device;
  974. int ret;
  975. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
  976. "VIDIOC_STREAMOFF,layer id = %d\n",
  977. layer->device_id);
  978. if (V4L2_BUF_TYPE_VIDEO_OUTPUT != buf_type) {
  979. v4l2_err(&vpbe_dev->v4l2_dev, "Invalid buffer type\n");
  980. return -EINVAL;
  981. }
  982. /* If io is allowed for this file handle, return error */
  983. if (!fh->io_allowed) {
  984. v4l2_err(&vpbe_dev->v4l2_dev, "No io_allowed\n");
  985. return -EACCES;
  986. }
  987. /* If streaming is not started, return error */
  988. if (!layer->started) {
  989. v4l2_err(&vpbe_dev->v4l2_dev, "streaming not started in layer"
  990. " id = %d\n", layer->device_id);
  991. return -EINVAL;
  992. }
  993. osd_device->ops.disable_layer(osd_device,
  994. layer->layer_info.id);
  995. layer->started = 0;
  996. ret = videobuf_streamoff(&layer->buffer_queue);
  997. return ret;
  998. }
  999. static int vpbe_display_streamon(struct file *file, void *priv,
  1000. enum v4l2_buf_type buf_type)
  1001. {
  1002. struct vpbe_fh *fh = file->private_data;
  1003. struct vpbe_layer *layer = fh->layer;
  1004. struct vpbe_display *disp_dev = fh->disp_dev;
  1005. struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
  1006. struct osd_state *osd_device = disp_dev->osd_device;
  1007. int ret;
  1008. osd_device->ops.disable_layer(osd_device,
  1009. layer->layer_info.id);
  1010. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_STREAMON, layerid=%d\n",
  1011. layer->device_id);
  1012. if (V4L2_BUF_TYPE_VIDEO_OUTPUT != buf_type) {
  1013. v4l2_err(&vpbe_dev->v4l2_dev, "Invalid buffer type\n");
  1014. return -EINVAL;
  1015. }
  1016. /* If file handle is not allowed IO, return error */
  1017. if (!fh->io_allowed) {
  1018. v4l2_err(&vpbe_dev->v4l2_dev, "No io_allowed\n");
  1019. return -EACCES;
  1020. }
  1021. /* If Streaming is already started, return error */
  1022. if (layer->started) {
  1023. v4l2_err(&vpbe_dev->v4l2_dev, "layer is already streaming\n");
  1024. return -EBUSY;
  1025. }
  1026. /*
  1027. * Call videobuf_streamon to start streaming
  1028. * in videobuf
  1029. */
  1030. ret = videobuf_streamon(&layer->buffer_queue);
  1031. if (ret) {
  1032. v4l2_err(&vpbe_dev->v4l2_dev,
  1033. "error in videobuf_streamon\n");
  1034. return ret;
  1035. }
  1036. /* If buffer queue is empty, return error */
  1037. if (list_empty(&layer->dma_queue)) {
  1038. v4l2_err(&vpbe_dev->v4l2_dev, "buffer queue is empty\n");
  1039. goto streamoff;
  1040. }
  1041. /* Get the next frame from the buffer queue */
  1042. layer->next_frm = layer->cur_frm = list_entry(layer->dma_queue.next,
  1043. struct videobuf_buffer, queue);
  1044. /* Remove buffer from the buffer queue */
  1045. list_del(&layer->cur_frm->queue);
  1046. /* Mark state of the current frame to active */
  1047. layer->cur_frm->state = VIDEOBUF_ACTIVE;
  1048. /* Initialize field_id and started member */
  1049. layer->field_id = 0;
  1050. /* Set parameters in OSD and VENC */
  1051. ret = vpbe_set_osd_display_params(disp_dev, layer);
  1052. if (ret < 0)
  1053. goto streamoff;
  1054. /*
  1055. * if request format is yuv420 semiplanar, need to
  1056. * enable both video windows
  1057. */
  1058. layer->started = 1;
  1059. layer->layer_first_int = 1;
  1060. return ret;
  1061. streamoff:
  1062. ret = videobuf_streamoff(&layer->buffer_queue);
  1063. return ret;
  1064. }
  1065. static int vpbe_display_dqbuf(struct file *file, void *priv,
  1066. struct v4l2_buffer *buf)
  1067. {
  1068. struct vpbe_fh *fh = file->private_data;
  1069. struct vpbe_layer *layer = fh->layer;
  1070. struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
  1071. int ret;
  1072. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
  1073. "VIDIOC_DQBUF, layer id = %d\n",
  1074. layer->device_id);
  1075. if (V4L2_BUF_TYPE_VIDEO_OUTPUT != buf->type) {
  1076. v4l2_err(&vpbe_dev->v4l2_dev, "Invalid buffer type\n");
  1077. return -EINVAL;
  1078. }
  1079. /* If this file handle is not allowed to do IO, return error */
  1080. if (!fh->io_allowed) {
  1081. v4l2_err(&vpbe_dev->v4l2_dev, "No io_allowed\n");
  1082. return -EACCES;
  1083. }
  1084. if (file->f_flags & O_NONBLOCK)
  1085. /* Call videobuf_dqbuf for non blocking mode */
  1086. ret = videobuf_dqbuf(&layer->buffer_queue, buf, 1);
  1087. else
  1088. /* Call videobuf_dqbuf for blocking mode */
  1089. ret = videobuf_dqbuf(&layer->buffer_queue, buf, 0);
  1090. return ret;
  1091. }
  1092. static int vpbe_display_qbuf(struct file *file, void *priv,
  1093. struct v4l2_buffer *p)
  1094. {
  1095. struct vpbe_fh *fh = file->private_data;
  1096. struct vpbe_layer *layer = fh->layer;
  1097. struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
  1098. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
  1099. "VIDIOC_QBUF, layer id = %d\n",
  1100. layer->device_id);
  1101. if (V4L2_BUF_TYPE_VIDEO_OUTPUT != p->type) {
  1102. v4l2_err(&vpbe_dev->v4l2_dev, "Invalid buffer type\n");
  1103. return -EINVAL;
  1104. }
  1105. /* If this file handle is not allowed to do IO, return error */
  1106. if (!fh->io_allowed) {
  1107. v4l2_err(&vpbe_dev->v4l2_dev, "No io_allowed\n");
  1108. return -EACCES;
  1109. }
  1110. return videobuf_qbuf(&layer->buffer_queue, p);
  1111. }
  1112. static int vpbe_display_querybuf(struct file *file, void *priv,
  1113. struct v4l2_buffer *buf)
  1114. {
  1115. struct vpbe_fh *fh = file->private_data;
  1116. struct vpbe_layer *layer = fh->layer;
  1117. struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
  1118. int ret;
  1119. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
  1120. "VIDIOC_QUERYBUF, layer id = %d\n",
  1121. layer->device_id);
  1122. if (V4L2_BUF_TYPE_VIDEO_OUTPUT != buf->type) {
  1123. v4l2_err(&vpbe_dev->v4l2_dev, "Invalid buffer type\n");
  1124. return -EINVAL;
  1125. }
  1126. /* Call videobuf_querybuf to get information */
  1127. ret = videobuf_querybuf(&layer->buffer_queue, buf);
  1128. return ret;
  1129. }
  1130. static int vpbe_display_reqbufs(struct file *file, void *priv,
  1131. struct v4l2_requestbuffers *req_buf)
  1132. {
  1133. struct vpbe_fh *fh = file->private_data;
  1134. struct vpbe_layer *layer = fh->layer;
  1135. struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
  1136. int ret;
  1137. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_display_reqbufs\n");
  1138. if (V4L2_BUF_TYPE_VIDEO_OUTPUT != req_buf->type) {
  1139. v4l2_err(&vpbe_dev->v4l2_dev, "Invalid buffer type\n");
  1140. return -EINVAL;
  1141. }
  1142. /* If io users of the layer is not zero, return error */
  1143. if (0 != layer->io_usrs) {
  1144. v4l2_err(&vpbe_dev->v4l2_dev, "not IO user\n");
  1145. return -EBUSY;
  1146. }
  1147. /* Initialize videobuf queue as per the buffer type */
  1148. videobuf_queue_dma_contig_init(&layer->buffer_queue,
  1149. &video_qops,
  1150. vpbe_dev->pdev,
  1151. &layer->irqlock,
  1152. V4L2_BUF_TYPE_VIDEO_OUTPUT,
  1153. layer->pix_fmt.field,
  1154. sizeof(struct videobuf_buffer),
  1155. fh, NULL);
  1156. /* Set io allowed member of file handle to TRUE */
  1157. fh->io_allowed = 1;
  1158. /* Increment io usrs member of layer object to 1 */
  1159. layer->io_usrs = 1;
  1160. /* Store type of memory requested in layer object */
  1161. layer->memory = req_buf->memory;
  1162. /* Initialize buffer queue */
  1163. INIT_LIST_HEAD(&layer->dma_queue);
  1164. /* Allocate buffers */
  1165. ret = videobuf_reqbufs(&layer->buffer_queue, req_buf);
  1166. return ret;
  1167. }
  1168. /*
  1169. * vpbe_display_mmap()
  1170. * It is used to map kernel space buffers into user spaces
  1171. */
  1172. static int vpbe_display_mmap(struct file *filep, struct vm_area_struct *vma)
  1173. {
  1174. /* Get the layer object and file handle object */
  1175. struct vpbe_fh *fh = filep->private_data;
  1176. struct vpbe_layer *layer = fh->layer;
  1177. struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
  1178. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_display_mmap\n");
  1179. return videobuf_mmap_mapper(&layer->buffer_queue, vma);
  1180. }
  1181. /* vpbe_display_poll(): It is used for select/poll system call
  1182. */
  1183. static unsigned int vpbe_display_poll(struct file *filep, poll_table *wait)
  1184. {
  1185. struct vpbe_fh *fh = filep->private_data;
  1186. struct vpbe_layer *layer = fh->layer;
  1187. struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
  1188. unsigned int err = 0;
  1189. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_display_poll\n");
  1190. if (layer->started)
  1191. err = videobuf_poll_stream(filep, &layer->buffer_queue, wait);
  1192. return err;
  1193. }
  1194. /*
  1195. * vpbe_display_open()
  1196. * It creates object of file handle structure and stores it in private_data
  1197. * member of filepointer
  1198. */
  1199. static int vpbe_display_open(struct file *file)
  1200. {
  1201. struct vpbe_fh *fh = NULL;
  1202. struct vpbe_layer *layer = video_drvdata(file);
  1203. struct vpbe_display *disp_dev = layer->disp_dev;
  1204. struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
  1205. struct osd_state *osd_device = disp_dev->osd_device;
  1206. int err;
  1207. /* Allocate memory for the file handle object */
  1208. fh = kmalloc(sizeof(struct vpbe_fh), GFP_KERNEL);
  1209. if (fh == NULL) {
  1210. v4l2_err(&vpbe_dev->v4l2_dev,
  1211. "unable to allocate memory for file handle object\n");
  1212. return -ENOMEM;
  1213. }
  1214. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
  1215. "vpbe display open plane = %d\n",
  1216. layer->device_id);
  1217. /* store pointer to fh in private_data member of filep */
  1218. file->private_data = fh;
  1219. fh->layer = layer;
  1220. fh->disp_dev = disp_dev;
  1221. if (!layer->usrs) {
  1222. /* First claim the layer for this device */
  1223. err = osd_device->ops.request_layer(osd_device,
  1224. layer->layer_info.id);
  1225. if (err < 0) {
  1226. /* Couldn't get layer */
  1227. v4l2_err(&vpbe_dev->v4l2_dev,
  1228. "Display Manager failed to allocate layer\n");
  1229. kfree(fh);
  1230. return -EINVAL;
  1231. }
  1232. }
  1233. /* Increment layer usrs counter */
  1234. layer->usrs++;
  1235. /* Set io_allowed member to false */
  1236. fh->io_allowed = 0;
  1237. /* Initialize priority of this instance to default priority */
  1238. fh->prio = V4L2_PRIORITY_UNSET;
  1239. v4l2_prio_open(&layer->prio, &fh->prio);
  1240. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
  1241. "vpbe display device opened successfully\n");
  1242. return 0;
  1243. }
  1244. /*
  1245. * vpbe_display_release()
  1246. * This function deletes buffer queue, frees the buffers and the davinci
  1247. * display file * handle
  1248. */
  1249. static int vpbe_display_release(struct file *file)
  1250. {
  1251. /* Get the layer object and file handle object */
  1252. struct vpbe_fh *fh = file->private_data;
  1253. struct vpbe_layer *layer = fh->layer;
  1254. struct osd_layer_config *cfg = &layer->layer_info.config;
  1255. struct vpbe_display *disp_dev = fh->disp_dev;
  1256. struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
  1257. struct osd_state *osd_device = disp_dev->osd_device;
  1258. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_display_release\n");
  1259. /* if this instance is doing IO */
  1260. if (fh->io_allowed) {
  1261. /* Reset io_usrs member of layer object */
  1262. layer->io_usrs = 0;
  1263. osd_device->ops.disable_layer(osd_device,
  1264. layer->layer_info.id);
  1265. layer->started = 0;
  1266. /* Free buffers allocated */
  1267. videobuf_queue_cancel(&layer->buffer_queue);
  1268. videobuf_mmap_free(&layer->buffer_queue);
  1269. }
  1270. /* Decrement layer usrs counter */
  1271. layer->usrs--;
  1272. /* If this file handle has initialize encoder device, reset it */
  1273. if (!layer->usrs) {
  1274. if (cfg->pixfmt == PIXFMT_NV12) {
  1275. struct vpbe_layer *otherlayer;
  1276. otherlayer =
  1277. _vpbe_display_get_other_win_layer(disp_dev, layer);
  1278. osd_device->ops.disable_layer(osd_device,
  1279. otherlayer->layer_info.id);
  1280. osd_device->ops.release_layer(osd_device,
  1281. otherlayer->layer_info.id);
  1282. }
  1283. osd_device->ops.disable_layer(osd_device,
  1284. layer->layer_info.id);
  1285. osd_device->ops.release_layer(osd_device,
  1286. layer->layer_info.id);
  1287. }
  1288. /* Close the priority */
  1289. v4l2_prio_close(&layer->prio, fh->prio);
  1290. file->private_data = NULL;
  1291. /* Free memory allocated to file handle object */
  1292. kfree(fh);
  1293. disp_dev->cbcr_ofst = 0;
  1294. return 0;
  1295. }
  1296. #ifdef CONFIG_VIDEO_ADV_DEBUG
  1297. static int vpbe_display_g_register(struct file *file, void *priv,
  1298. struct v4l2_dbg_register *reg)
  1299. {
  1300. struct v4l2_dbg_match *match = &reg->match;
  1301. if (match->type >= 2) {
  1302. v4l2_subdev_call(vpbe_dev->venc,
  1303. core,
  1304. g_register,
  1305. reg);
  1306. }
  1307. return 0;
  1308. }
  1309. static int vpbe_display_s_register(struct file *file, void *priv,
  1310. struct v4l2_dbg_register *reg)
  1311. {
  1312. return 0;
  1313. }
  1314. #endif
  1315. /* vpbe capture ioctl operations */
  1316. static const struct v4l2_ioctl_ops vpbe_ioctl_ops = {
  1317. .vidioc_querycap = vpbe_display_querycap,
  1318. .vidioc_g_fmt_vid_out = vpbe_display_g_fmt,
  1319. .vidioc_enum_fmt_vid_out = vpbe_display_enum_fmt,
  1320. .vidioc_s_fmt_vid_out = vpbe_display_s_fmt,
  1321. .vidioc_try_fmt_vid_out = vpbe_display_try_fmt,
  1322. .vidioc_reqbufs = vpbe_display_reqbufs,
  1323. .vidioc_querybuf = vpbe_display_querybuf,
  1324. .vidioc_qbuf = vpbe_display_qbuf,
  1325. .vidioc_dqbuf = vpbe_display_dqbuf,
  1326. .vidioc_streamon = vpbe_display_streamon,
  1327. .vidioc_streamoff = vpbe_display_streamoff,
  1328. .vidioc_cropcap = vpbe_display_cropcap,
  1329. .vidioc_g_crop = vpbe_display_g_crop,
  1330. .vidioc_s_crop = vpbe_display_s_crop,
  1331. .vidioc_g_priority = vpbe_display_g_priority,
  1332. .vidioc_s_priority = vpbe_display_s_priority,
  1333. .vidioc_s_std = vpbe_display_s_std,
  1334. .vidioc_g_std = vpbe_display_g_std,
  1335. .vidioc_enum_output = vpbe_display_enum_output,
  1336. .vidioc_s_output = vpbe_display_s_output,
  1337. .vidioc_g_output = vpbe_display_g_output,
  1338. .vidioc_s_dv_preset = vpbe_display_s_dv_preset,
  1339. .vidioc_g_dv_preset = vpbe_display_g_dv_preset,
  1340. .vidioc_enum_dv_presets = vpbe_display_enum_dv_presets,
  1341. #ifdef CONFIG_VIDEO_ADV_DEBUG
  1342. .vidioc_g_register = vpbe_display_g_register,
  1343. .vidioc_s_register = vpbe_display_s_register,
  1344. #endif
  1345. };
  1346. static struct v4l2_file_operations vpbe_fops = {
  1347. .owner = THIS_MODULE,
  1348. .open = vpbe_display_open,
  1349. .release = vpbe_display_release,
  1350. .unlocked_ioctl = video_ioctl2,
  1351. .mmap = vpbe_display_mmap,
  1352. .poll = vpbe_display_poll
  1353. };
  1354. static int vpbe_device_get(struct device *dev, void *data)
  1355. {
  1356. struct platform_device *pdev = to_platform_device(dev);
  1357. struct vpbe_display *vpbe_disp = data;
  1358. if (strcmp("vpbe_controller", pdev->name) == 0)
  1359. vpbe_disp->vpbe_dev = platform_get_drvdata(pdev);
  1360. if (strcmp("vpbe-osd", pdev->name) == 0)
  1361. vpbe_disp->osd_device = platform_get_drvdata(pdev);
  1362. return 0;
  1363. }
  1364. static __devinit int init_vpbe_layer(int i, struct vpbe_display *disp_dev,
  1365. struct platform_device *pdev)
  1366. {
  1367. struct vpbe_layer *vpbe_display_layer = NULL;
  1368. struct video_device *vbd = NULL;
  1369. /* Allocate memory for four plane display objects */
  1370. disp_dev->dev[i] =
  1371. kzalloc(sizeof(struct vpbe_layer), GFP_KERNEL);
  1372. /* If memory allocation fails, return error */
  1373. if (!disp_dev->dev[i]) {
  1374. printk(KERN_ERR "ran out of memory\n");
  1375. return -ENOMEM;
  1376. }
  1377. spin_lock_init(&disp_dev->dev[i]->irqlock);
  1378. mutex_init(&disp_dev->dev[i]->opslock);
  1379. /* Get the pointer to the layer object */
  1380. vpbe_display_layer = disp_dev->dev[i];
  1381. vbd = &vpbe_display_layer->video_dev;
  1382. /* Initialize field of video device */
  1383. vbd->release = video_device_release_empty;
  1384. vbd->fops = &vpbe_fops;
  1385. vbd->ioctl_ops = &vpbe_ioctl_ops;
  1386. vbd->minor = -1;
  1387. vbd->v4l2_dev = &disp_dev->vpbe_dev->v4l2_dev;
  1388. vbd->lock = &vpbe_display_layer->opslock;
  1389. if (disp_dev->vpbe_dev->current_timings.timings_type &
  1390. VPBE_ENC_STD) {
  1391. vbd->tvnorms = (V4L2_STD_525_60 | V4L2_STD_625_50);
  1392. vbd->current_norm =
  1393. disp_dev->vpbe_dev->
  1394. current_timings.timings.std_id;
  1395. } else
  1396. vbd->current_norm = 0;
  1397. snprintf(vbd->name, sizeof(vbd->name),
  1398. "DaVinci_VPBE Display_DRIVER_V%d.%d.%d",
  1399. (VPBE_DISPLAY_VERSION_CODE >> 16) & 0xff,
  1400. (VPBE_DISPLAY_VERSION_CODE >> 8) & 0xff,
  1401. (VPBE_DISPLAY_VERSION_CODE) & 0xff);
  1402. vpbe_display_layer->device_id = i;
  1403. vpbe_display_layer->layer_info.id =
  1404. ((i == VPBE_DISPLAY_DEVICE_0) ? WIN_VID0 : WIN_VID1);
  1405. /* Initialize prio member of layer object */
  1406. v4l2_prio_init(&vpbe_display_layer->prio);
  1407. return 0;
  1408. }
  1409. static __devinit int register_device(struct vpbe_layer *vpbe_display_layer,
  1410. struct vpbe_display *disp_dev,
  1411. struct platform_device *pdev) {
  1412. int err;
  1413. v4l2_info(&disp_dev->vpbe_dev->v4l2_dev,
  1414. "Trying to register VPBE display device.\n");
  1415. v4l2_info(&disp_dev->vpbe_dev->v4l2_dev,
  1416. "layer=%x,layer->video_dev=%x\n",
  1417. (int)vpbe_display_layer,
  1418. (int)&vpbe_display_layer->video_dev);
  1419. err = video_register_device(&vpbe_display_layer->video_dev,
  1420. VFL_TYPE_GRABBER,
  1421. -1);
  1422. if (err)
  1423. return -ENODEV;
  1424. vpbe_display_layer->disp_dev = disp_dev;
  1425. /* set the driver data in platform device */
  1426. platform_set_drvdata(pdev, disp_dev);
  1427. video_set_drvdata(&vpbe_display_layer->video_dev,
  1428. vpbe_display_layer);
  1429. return 0;
  1430. }
  1431. /*
  1432. * vpbe_display_probe()
  1433. * This function creates device entries by register itself to the V4L2 driver
  1434. * and initializes fields of each layer objects
  1435. */
  1436. static __devinit int vpbe_display_probe(struct platform_device *pdev)
  1437. {
  1438. struct vpbe_layer *vpbe_display_layer;
  1439. struct vpbe_display *disp_dev;
  1440. struct resource *res = NULL;
  1441. int k;
  1442. int i;
  1443. int err;
  1444. int irq;
  1445. printk(KERN_DEBUG "vpbe_display_probe\n");
  1446. /* Allocate memory for vpbe_display */
  1447. disp_dev = kzalloc(sizeof(struct vpbe_display), GFP_KERNEL);
  1448. if (!disp_dev) {
  1449. printk(KERN_ERR "ran out of memory\n");
  1450. return -ENOMEM;
  1451. }
  1452. spin_lock_init(&disp_dev->dma_queue_lock);
  1453. /*
  1454. * Scan all the platform devices to find the vpbe
  1455. * controller device and get the vpbe_dev object
  1456. */
  1457. err = bus_for_each_dev(&platform_bus_type, NULL, disp_dev,
  1458. vpbe_device_get);
  1459. if (err < 0)
  1460. return err;
  1461. /* Initialize the vpbe display controller */
  1462. if (NULL != disp_dev->vpbe_dev->ops.initialize) {
  1463. err = disp_dev->vpbe_dev->ops.initialize(&pdev->dev,
  1464. disp_dev->vpbe_dev);
  1465. if (err) {
  1466. v4l2_err(&disp_dev->vpbe_dev->v4l2_dev,
  1467. "Error initing vpbe\n");
  1468. err = -ENOMEM;
  1469. goto probe_out;
  1470. }
  1471. }
  1472. for (i = 0; i < VPBE_DISPLAY_MAX_DEVICES; i++) {
  1473. if (init_vpbe_layer(i, disp_dev, pdev)) {
  1474. err = -ENODEV;
  1475. goto probe_out;
  1476. }
  1477. }
  1478. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  1479. if (!res) {
  1480. v4l2_err(&disp_dev->vpbe_dev->v4l2_dev,
  1481. "Unable to get VENC interrupt resource\n");
  1482. err = -ENODEV;
  1483. goto probe_out;
  1484. }
  1485. irq = res->start;
  1486. if (request_irq(irq, venc_isr, IRQF_DISABLED, VPBE_DISPLAY_DRIVER,
  1487. disp_dev)) {
  1488. v4l2_err(&disp_dev->vpbe_dev->v4l2_dev,
  1489. "Unable to request interrupt\n");
  1490. err = -ENODEV;
  1491. goto probe_out;
  1492. }
  1493. for (i = 0; i < VPBE_DISPLAY_MAX_DEVICES; i++) {
  1494. if (register_device(disp_dev->dev[i], disp_dev, pdev)) {
  1495. err = -ENODEV;
  1496. goto probe_out_irq;
  1497. }
  1498. }
  1499. printk(KERN_DEBUG "Successfully completed the probing of vpbe v4l2 device\n");
  1500. return 0;
  1501. probe_out_irq:
  1502. free_irq(res->start, disp_dev);
  1503. probe_out:
  1504. for (k = 0; k < VPBE_DISPLAY_MAX_DEVICES; k++) {
  1505. /* Get the pointer to the layer object */
  1506. vpbe_display_layer = disp_dev->dev[k];
  1507. /* Unregister video device */
  1508. if (vpbe_display_layer) {
  1509. video_unregister_device(
  1510. &vpbe_display_layer->video_dev);
  1511. kfree(disp_dev->dev[k]);
  1512. }
  1513. }
  1514. kfree(disp_dev);
  1515. return err;
  1516. }
  1517. /*
  1518. * vpbe_display_remove()
  1519. * It un-register hardware layer from V4L2 driver
  1520. */
  1521. static int vpbe_display_remove(struct platform_device *pdev)
  1522. {
  1523. struct vpbe_layer *vpbe_display_layer;
  1524. struct vpbe_display *disp_dev = platform_get_drvdata(pdev);
  1525. struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
  1526. struct resource *res;
  1527. int i;
  1528. v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_display_remove\n");
  1529. /* unregister irq */
  1530. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  1531. free_irq(res->start, disp_dev);
  1532. /* deinitialize the vpbe display controller */
  1533. if (NULL != vpbe_dev->ops.deinitialize)
  1534. vpbe_dev->ops.deinitialize(&pdev->dev, vpbe_dev);
  1535. /* un-register device */
  1536. for (i = 0; i < VPBE_DISPLAY_MAX_DEVICES; i++) {
  1537. /* Get the pointer to the layer object */
  1538. vpbe_display_layer = disp_dev->dev[i];
  1539. /* Unregister video device */
  1540. video_unregister_device(&vpbe_display_layer->video_dev);
  1541. }
  1542. for (i = 0; i < VPBE_DISPLAY_MAX_DEVICES; i++) {
  1543. kfree(disp_dev->dev[i]);
  1544. disp_dev->dev[i] = NULL;
  1545. }
  1546. return 0;
  1547. }
  1548. static struct platform_driver vpbe_display_driver = {
  1549. .driver = {
  1550. .name = VPBE_DISPLAY_DRIVER,
  1551. .owner = THIS_MODULE,
  1552. .bus = &platform_bus_type,
  1553. },
  1554. .probe = vpbe_display_probe,
  1555. .remove = __devexit_p(vpbe_display_remove),
  1556. };
  1557. module_platform_driver(vpbe_display_driver);
  1558. MODULE_DESCRIPTION("TI DM644x/DM355/DM365 VPBE Display controller");
  1559. MODULE_LICENSE("GPL");
  1560. MODULE_AUTHOR("Texas Instruments");