vpif_capture.c 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809
  1. /*
  2. * Copyright (C) 2009 Texas Instruments Inc
  3. * Copyright (C) 2014 Lad, Prabhakar <prabhakar.csengg@gmail.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. *
  19. * TODO : add support for VBI & HBI data service
  20. * add static buffer allocation
  21. */
  22. #include <linux/module.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/slab.h>
  26. #include <media/v4l2-ioctl.h>
  27. #include "vpif.h"
  28. #include "vpif_capture.h"
  29. MODULE_DESCRIPTION("TI DaVinci VPIF Capture driver");
  30. MODULE_LICENSE("GPL");
  31. MODULE_VERSION(VPIF_CAPTURE_VERSION);
  32. #define vpif_err(fmt, arg...) v4l2_err(&vpif_obj.v4l2_dev, fmt, ## arg)
  33. #define vpif_dbg(level, debug, fmt, arg...) \
  34. v4l2_dbg(level, debug, &vpif_obj.v4l2_dev, fmt, ## arg)
  35. static int debug = 1;
  36. static u32 ch0_numbuffers = 3;
  37. static u32 ch1_numbuffers = 3;
  38. static u32 ch0_bufsize = 1920 * 1080 * 2;
  39. static u32 ch1_bufsize = 720 * 576 * 2;
  40. module_param(debug, int, 0644);
  41. module_param(ch0_numbuffers, uint, S_IRUGO);
  42. module_param(ch1_numbuffers, uint, S_IRUGO);
  43. module_param(ch0_bufsize, uint, S_IRUGO);
  44. module_param(ch1_bufsize, uint, S_IRUGO);
  45. MODULE_PARM_DESC(debug, "Debug level 0-1");
  46. MODULE_PARM_DESC(ch2_numbuffers, "Channel0 buffer count (default:3)");
  47. MODULE_PARM_DESC(ch3_numbuffers, "Channel1 buffer count (default:3)");
  48. MODULE_PARM_DESC(ch2_bufsize, "Channel0 buffer size (default:1920 x 1080 x 2)");
  49. MODULE_PARM_DESC(ch3_bufsize, "Channel1 buffer size (default:720 x 576 x 2)");
  50. static struct vpif_config_params config_params = {
  51. .min_numbuffers = 3,
  52. .numbuffers[0] = 3,
  53. .numbuffers[1] = 3,
  54. .min_bufsize[0] = 720 * 480 * 2,
  55. .min_bufsize[1] = 720 * 480 * 2,
  56. .channel_bufsize[0] = 1920 * 1080 * 2,
  57. .channel_bufsize[1] = 720 * 576 * 2,
  58. };
  59. #define VPIF_DRIVER_NAME "vpif_capture"
  60. /* global variables */
  61. static struct vpif_device vpif_obj = { {NULL} };
  62. static struct device *vpif_dev;
  63. static void vpif_calculate_offsets(struct channel_obj *ch);
  64. static void vpif_config_addr(struct channel_obj *ch, int muxmode);
  65. static u8 channel_first_int[VPIF_NUMBER_OF_OBJECTS][2] = { {1, 1} };
  66. /* Is set to 1 in case of SDTV formats, 2 in case of HDTV formats. */
  67. static int ycmux_mode;
  68. static inline struct vpif_cap_buffer *to_vpif_buffer(struct vb2_buffer *vb)
  69. {
  70. return container_of(vb, struct vpif_cap_buffer, vb);
  71. }
  72. /**
  73. * vpif_buffer_prepare : callback function for buffer prepare
  74. * @vb: ptr to vb2_buffer
  75. *
  76. * This is the callback function for buffer prepare when vb2_qbuf()
  77. * function is called. The buffer is prepared and user space virtual address
  78. * or user address is converted into physical address
  79. */
  80. static int vpif_buffer_prepare(struct vb2_buffer *vb)
  81. {
  82. struct vb2_queue *q = vb->vb2_queue;
  83. struct channel_obj *ch = vb2_get_drv_priv(q);
  84. struct common_obj *common;
  85. unsigned long addr;
  86. vpif_dbg(2, debug, "vpif_buffer_prepare\n");
  87. common = &ch->common[VPIF_VIDEO_INDEX];
  88. vb2_set_plane_payload(vb, 0, common->fmt.fmt.pix.sizeimage);
  89. if (vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0))
  90. return -EINVAL;
  91. vb->v4l2_buf.field = common->fmt.fmt.pix.field;
  92. addr = vb2_dma_contig_plane_dma_addr(vb, 0);
  93. if (!IS_ALIGNED((addr + common->ytop_off), 8) ||
  94. !IS_ALIGNED((addr + common->ybtm_off), 8) ||
  95. !IS_ALIGNED((addr + common->ctop_off), 8) ||
  96. !IS_ALIGNED((addr + common->cbtm_off), 8)) {
  97. vpif_dbg(1, debug, "offset is not aligned\n");
  98. return -EINVAL;
  99. }
  100. return 0;
  101. }
  102. /**
  103. * vpif_buffer_queue_setup : Callback function for buffer setup.
  104. * @vq: vb2_queue ptr
  105. * @fmt: v4l2 format
  106. * @nbuffers: ptr to number of buffers requested by application
  107. * @nplanes:: contains number of distinct video planes needed to hold a frame
  108. * @sizes[]: contains the size (in bytes) of each plane.
  109. * @alloc_ctxs: ptr to allocation context
  110. *
  111. * This callback function is called when reqbuf() is called to adjust
  112. * the buffer count and buffer size
  113. */
  114. static int vpif_buffer_queue_setup(struct vb2_queue *vq,
  115. const struct v4l2_format *fmt,
  116. unsigned int *nbuffers, unsigned int *nplanes,
  117. unsigned int sizes[], void *alloc_ctxs[])
  118. {
  119. struct channel_obj *ch = vb2_get_drv_priv(vq);
  120. struct common_obj *common;
  121. common = &ch->common[VPIF_VIDEO_INDEX];
  122. vpif_dbg(2, debug, "vpif_buffer_setup\n");
  123. if (fmt && fmt->fmt.pix.sizeimage < common->fmt.fmt.pix.sizeimage)
  124. return -EINVAL;
  125. if (vq->num_buffers + *nbuffers < 3)
  126. *nbuffers = 3 - vq->num_buffers;
  127. *nplanes = 1;
  128. sizes[0] = fmt ? fmt->fmt.pix.sizeimage : common->fmt.fmt.pix.sizeimage;
  129. alloc_ctxs[0] = common->alloc_ctx;
  130. /* Calculate the offset for Y and C data in the buffer */
  131. vpif_calculate_offsets(ch);
  132. return 0;
  133. }
  134. /**
  135. * vpif_buffer_queue : Callback function to add buffer to DMA queue
  136. * @vb: ptr to vb2_buffer
  137. */
  138. static void vpif_buffer_queue(struct vb2_buffer *vb)
  139. {
  140. struct channel_obj *ch = vb2_get_drv_priv(vb->vb2_queue);
  141. struct vpif_cap_buffer *buf = to_vpif_buffer(vb);
  142. struct common_obj *common;
  143. unsigned long flags;
  144. common = &ch->common[VPIF_VIDEO_INDEX];
  145. vpif_dbg(2, debug, "vpif_buffer_queue\n");
  146. spin_lock_irqsave(&common->irqlock, flags);
  147. /* add the buffer to the DMA queue */
  148. list_add_tail(&buf->list, &common->dma_queue);
  149. spin_unlock_irqrestore(&common->irqlock, flags);
  150. }
  151. /**
  152. * vpif_start_streaming : Starts the DMA engine for streaming
  153. * @vb: ptr to vb2_buffer
  154. * @count: number of buffers
  155. */
  156. static int vpif_start_streaming(struct vb2_queue *vq, unsigned int count)
  157. {
  158. struct vpif_capture_config *vpif_config_data =
  159. vpif_dev->platform_data;
  160. struct channel_obj *ch = vb2_get_drv_priv(vq);
  161. struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
  162. struct vpif_params *vpif = &ch->vpifparams;
  163. struct vpif_cap_buffer *buf, *tmp;
  164. unsigned long addr, flags;
  165. int ret;
  166. spin_lock_irqsave(&common->irqlock, flags);
  167. /* Initialize field_id */
  168. ch->field_id = 0;
  169. /* configure 1 or 2 channel mode */
  170. if (vpif_config_data->setup_input_channel_mode) {
  171. ret = vpif_config_data->
  172. setup_input_channel_mode(vpif->std_info.ycmux_mode);
  173. if (ret < 0) {
  174. vpif_dbg(1, debug, "can't set vpif channel mode\n");
  175. goto err;
  176. }
  177. }
  178. ret = v4l2_subdev_call(ch->sd, video, s_stream, 1);
  179. if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV) {
  180. vpif_dbg(1, debug, "stream on failed in subdev\n");
  181. goto err;
  182. }
  183. /* Call vpif_set_params function to set the parameters and addresses */
  184. ret = vpif_set_video_params(vpif, ch->channel_id);
  185. if (ret < 0) {
  186. vpif_dbg(1, debug, "can't set video params\n");
  187. goto err;
  188. }
  189. ycmux_mode = ret;
  190. vpif_config_addr(ch, ret);
  191. /* Get the next frame from the buffer queue */
  192. common->cur_frm = common->next_frm = list_entry(common->dma_queue.next,
  193. struct vpif_cap_buffer, list);
  194. /* Remove buffer from the buffer queue */
  195. list_del(&common->cur_frm->list);
  196. spin_unlock_irqrestore(&common->irqlock, flags);
  197. /* Mark state of the current frame to active */
  198. common->cur_frm->vb.state = VB2_BUF_STATE_ACTIVE;
  199. addr = vb2_dma_contig_plane_dma_addr(&common->cur_frm->vb, 0);
  200. common->set_addr(addr + common->ytop_off,
  201. addr + common->ybtm_off,
  202. addr + common->ctop_off,
  203. addr + common->cbtm_off);
  204. /**
  205. * Set interrupt for both the fields in VPIF Register enable channel in
  206. * VPIF register
  207. */
  208. channel_first_int[VPIF_VIDEO_INDEX][ch->channel_id] = 1;
  209. if (VPIF_CHANNEL0_VIDEO == ch->channel_id) {
  210. channel0_intr_assert();
  211. channel0_intr_enable(1);
  212. enable_channel0(1);
  213. }
  214. if (VPIF_CHANNEL1_VIDEO == ch->channel_id ||
  215. ycmux_mode == 2) {
  216. channel1_intr_assert();
  217. channel1_intr_enable(1);
  218. enable_channel1(1);
  219. }
  220. return 0;
  221. err:
  222. list_for_each_entry_safe(buf, tmp, &common->dma_queue, list) {
  223. list_del(&buf->list);
  224. vb2_buffer_done(&buf->vb, VB2_BUF_STATE_QUEUED);
  225. }
  226. spin_unlock_irqrestore(&common->irqlock, flags);
  227. return ret;
  228. }
  229. /**
  230. * vpif_stop_streaming : Stop the DMA engine
  231. * @vq: ptr to vb2_queue
  232. *
  233. * This callback stops the DMA engine and any remaining buffers
  234. * in the DMA queue are released.
  235. */
  236. static void vpif_stop_streaming(struct vb2_queue *vq)
  237. {
  238. struct channel_obj *ch = vb2_get_drv_priv(vq);
  239. struct common_obj *common;
  240. unsigned long flags;
  241. int ret;
  242. common = &ch->common[VPIF_VIDEO_INDEX];
  243. /* Disable channel as per its device type and channel id */
  244. if (VPIF_CHANNEL0_VIDEO == ch->channel_id) {
  245. enable_channel0(0);
  246. channel0_intr_enable(0);
  247. }
  248. if (VPIF_CHANNEL1_VIDEO == ch->channel_id ||
  249. ycmux_mode == 2) {
  250. enable_channel1(0);
  251. channel1_intr_enable(0);
  252. }
  253. ycmux_mode = 0;
  254. ret = v4l2_subdev_call(ch->sd, video, s_stream, 0);
  255. if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV)
  256. vpif_dbg(1, debug, "stream off failed in subdev\n");
  257. /* release all active buffers */
  258. spin_lock_irqsave(&common->irqlock, flags);
  259. if (common->cur_frm == common->next_frm) {
  260. vb2_buffer_done(&common->cur_frm->vb, VB2_BUF_STATE_ERROR);
  261. } else {
  262. if (common->cur_frm != NULL)
  263. vb2_buffer_done(&common->cur_frm->vb,
  264. VB2_BUF_STATE_ERROR);
  265. if (common->next_frm != NULL)
  266. vb2_buffer_done(&common->next_frm->vb,
  267. VB2_BUF_STATE_ERROR);
  268. }
  269. while (!list_empty(&common->dma_queue)) {
  270. common->next_frm = list_entry(common->dma_queue.next,
  271. struct vpif_cap_buffer, list);
  272. list_del(&common->next_frm->list);
  273. vb2_buffer_done(&common->next_frm->vb, VB2_BUF_STATE_ERROR);
  274. }
  275. spin_unlock_irqrestore(&common->irqlock, flags);
  276. }
  277. static struct vb2_ops video_qops = {
  278. .queue_setup = vpif_buffer_queue_setup,
  279. .buf_prepare = vpif_buffer_prepare,
  280. .start_streaming = vpif_start_streaming,
  281. .stop_streaming = vpif_stop_streaming,
  282. .buf_queue = vpif_buffer_queue,
  283. };
  284. /**
  285. * vpif_process_buffer_complete: process a completed buffer
  286. * @common: ptr to common channel object
  287. *
  288. * This function time stamp the buffer and mark it as DONE. It also
  289. * wake up any process waiting on the QUEUE and set the next buffer
  290. * as current
  291. */
  292. static void vpif_process_buffer_complete(struct common_obj *common)
  293. {
  294. v4l2_get_timestamp(&common->cur_frm->vb.v4l2_buf.timestamp);
  295. vb2_buffer_done(&common->cur_frm->vb,
  296. VB2_BUF_STATE_DONE);
  297. /* Make curFrm pointing to nextFrm */
  298. common->cur_frm = common->next_frm;
  299. }
  300. /**
  301. * vpif_schedule_next_buffer: set next buffer address for capture
  302. * @common : ptr to common channel object
  303. *
  304. * This function will get next buffer from the dma queue and
  305. * set the buffer address in the vpif register for capture.
  306. * the buffer is marked active
  307. */
  308. static void vpif_schedule_next_buffer(struct common_obj *common)
  309. {
  310. unsigned long addr = 0;
  311. spin_lock(&common->irqlock);
  312. common->next_frm = list_entry(common->dma_queue.next,
  313. struct vpif_cap_buffer, list);
  314. /* Remove that buffer from the buffer queue */
  315. list_del(&common->next_frm->list);
  316. spin_unlock(&common->irqlock);
  317. common->next_frm->vb.state = VB2_BUF_STATE_ACTIVE;
  318. addr = vb2_dma_contig_plane_dma_addr(&common->next_frm->vb, 0);
  319. /* Set top and bottom field addresses in VPIF registers */
  320. common->set_addr(addr + common->ytop_off,
  321. addr + common->ybtm_off,
  322. addr + common->ctop_off,
  323. addr + common->cbtm_off);
  324. }
  325. /**
  326. * vpif_channel_isr : ISR handler for vpif capture
  327. * @irq: irq number
  328. * @dev_id: dev_id ptr
  329. *
  330. * It changes status of the captured buffer, takes next buffer from the queue
  331. * and sets its address in VPIF registers
  332. */
  333. static irqreturn_t vpif_channel_isr(int irq, void *dev_id)
  334. {
  335. struct vpif_device *dev = &vpif_obj;
  336. struct common_obj *common;
  337. struct channel_obj *ch;
  338. enum v4l2_field field;
  339. int channel_id = 0;
  340. int fid = -1, i;
  341. channel_id = *(int *)(dev_id);
  342. if (!vpif_intr_status(channel_id))
  343. return IRQ_NONE;
  344. ch = dev->dev[channel_id];
  345. field = ch->common[VPIF_VIDEO_INDEX].fmt.fmt.pix.field;
  346. for (i = 0; i < VPIF_NUMBER_OF_OBJECTS; i++) {
  347. common = &ch->common[i];
  348. /* skip If streaming is not started in this channel */
  349. /* Check the field format */
  350. if (1 == ch->vpifparams.std_info.frm_fmt) {
  351. /* Progressive mode */
  352. spin_lock(&common->irqlock);
  353. if (list_empty(&common->dma_queue)) {
  354. spin_unlock(&common->irqlock);
  355. continue;
  356. }
  357. spin_unlock(&common->irqlock);
  358. if (!channel_first_int[i][channel_id])
  359. vpif_process_buffer_complete(common);
  360. channel_first_int[i][channel_id] = 0;
  361. vpif_schedule_next_buffer(common);
  362. channel_first_int[i][channel_id] = 0;
  363. } else {
  364. /**
  365. * Interlaced mode. If it is first interrupt, ignore
  366. * it
  367. */
  368. if (channel_first_int[i][channel_id]) {
  369. channel_first_int[i][channel_id] = 0;
  370. continue;
  371. }
  372. if (0 == i) {
  373. ch->field_id ^= 1;
  374. /* Get field id from VPIF registers */
  375. fid = vpif_channel_getfid(ch->channel_id);
  376. if (fid != ch->field_id) {
  377. /**
  378. * If field id does not match stored
  379. * field id, make them in sync
  380. */
  381. if (0 == fid)
  382. ch->field_id = fid;
  383. return IRQ_HANDLED;
  384. }
  385. }
  386. /* device field id and local field id are in sync */
  387. if (0 == fid) {
  388. /* this is even field */
  389. if (common->cur_frm == common->next_frm)
  390. continue;
  391. /* mark the current buffer as done */
  392. vpif_process_buffer_complete(common);
  393. } else if (1 == fid) {
  394. /* odd field */
  395. spin_lock(&common->irqlock);
  396. if (list_empty(&common->dma_queue) ||
  397. (common->cur_frm != common->next_frm)) {
  398. spin_unlock(&common->irqlock);
  399. continue;
  400. }
  401. spin_unlock(&common->irqlock);
  402. vpif_schedule_next_buffer(common);
  403. }
  404. }
  405. }
  406. return IRQ_HANDLED;
  407. }
  408. /**
  409. * vpif_update_std_info() - update standard related info
  410. * @ch: ptr to channel object
  411. *
  412. * For a given standard selected by application, update values
  413. * in the device data structures
  414. */
  415. static int vpif_update_std_info(struct channel_obj *ch)
  416. {
  417. struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
  418. struct vpif_params *vpifparams = &ch->vpifparams;
  419. const struct vpif_channel_config_params *config;
  420. struct vpif_channel_config_params *std_info = &vpifparams->std_info;
  421. struct video_obj *vid_ch = &ch->video;
  422. int index;
  423. vpif_dbg(2, debug, "vpif_update_std_info\n");
  424. for (index = 0; index < vpif_ch_params_count; index++) {
  425. config = &vpif_ch_params[index];
  426. if (config->hd_sd == 0) {
  427. vpif_dbg(2, debug, "SD format\n");
  428. if (config->stdid & vid_ch->stdid) {
  429. memcpy(std_info, config, sizeof(*config));
  430. break;
  431. }
  432. } else {
  433. vpif_dbg(2, debug, "HD format\n");
  434. if (!memcmp(&config->dv_timings, &vid_ch->dv_timings,
  435. sizeof(vid_ch->dv_timings))) {
  436. memcpy(std_info, config, sizeof(*config));
  437. break;
  438. }
  439. }
  440. }
  441. /* standard not found */
  442. if (index == vpif_ch_params_count)
  443. return -EINVAL;
  444. common->fmt.fmt.pix.width = std_info->width;
  445. common->width = std_info->width;
  446. common->fmt.fmt.pix.height = std_info->height;
  447. common->height = std_info->height;
  448. common->fmt.fmt.pix.bytesperline = std_info->width;
  449. vpifparams->video_params.hpitch = std_info->width;
  450. vpifparams->video_params.storage_mode = std_info->frm_fmt;
  451. return 0;
  452. }
  453. /**
  454. * vpif_calculate_offsets : This function calculates buffers offsets
  455. * @ch : ptr to channel object
  456. *
  457. * This function calculates buffer offsets for Y and C in the top and
  458. * bottom field
  459. */
  460. static void vpif_calculate_offsets(struct channel_obj *ch)
  461. {
  462. unsigned int hpitch, vpitch, sizeimage;
  463. struct video_obj *vid_ch = &(ch->video);
  464. struct vpif_params *vpifparams = &ch->vpifparams;
  465. struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
  466. enum v4l2_field field = common->fmt.fmt.pix.field;
  467. vpif_dbg(2, debug, "vpif_calculate_offsets\n");
  468. if (V4L2_FIELD_ANY == field) {
  469. if (vpifparams->std_info.frm_fmt)
  470. vid_ch->buf_field = V4L2_FIELD_NONE;
  471. else
  472. vid_ch->buf_field = V4L2_FIELD_INTERLACED;
  473. } else
  474. vid_ch->buf_field = common->fmt.fmt.pix.field;
  475. sizeimage = common->fmt.fmt.pix.sizeimage;
  476. hpitch = common->fmt.fmt.pix.bytesperline;
  477. vpitch = sizeimage / (hpitch * 2);
  478. if ((V4L2_FIELD_NONE == vid_ch->buf_field) ||
  479. (V4L2_FIELD_INTERLACED == vid_ch->buf_field)) {
  480. /* Calculate offsets for Y top, Y Bottom, C top and C Bottom */
  481. common->ytop_off = 0;
  482. common->ybtm_off = hpitch;
  483. common->ctop_off = sizeimage / 2;
  484. common->cbtm_off = sizeimage / 2 + hpitch;
  485. } else if (V4L2_FIELD_SEQ_TB == vid_ch->buf_field) {
  486. /* Calculate offsets for Y top, Y Bottom, C top and C Bottom */
  487. common->ytop_off = 0;
  488. common->ybtm_off = sizeimage / 4;
  489. common->ctop_off = sizeimage / 2;
  490. common->cbtm_off = common->ctop_off + sizeimage / 4;
  491. } else if (V4L2_FIELD_SEQ_BT == vid_ch->buf_field) {
  492. /* Calculate offsets for Y top, Y Bottom, C top and C Bottom */
  493. common->ybtm_off = 0;
  494. common->ytop_off = sizeimage / 4;
  495. common->cbtm_off = sizeimage / 2;
  496. common->ctop_off = common->cbtm_off + sizeimage / 4;
  497. }
  498. if ((V4L2_FIELD_NONE == vid_ch->buf_field) ||
  499. (V4L2_FIELD_INTERLACED == vid_ch->buf_field))
  500. vpifparams->video_params.storage_mode = 1;
  501. else
  502. vpifparams->video_params.storage_mode = 0;
  503. if (1 == vpifparams->std_info.frm_fmt)
  504. vpifparams->video_params.hpitch =
  505. common->fmt.fmt.pix.bytesperline;
  506. else {
  507. if ((field == V4L2_FIELD_ANY)
  508. || (field == V4L2_FIELD_INTERLACED))
  509. vpifparams->video_params.hpitch =
  510. common->fmt.fmt.pix.bytesperline * 2;
  511. else
  512. vpifparams->video_params.hpitch =
  513. common->fmt.fmt.pix.bytesperline;
  514. }
  515. ch->vpifparams.video_params.stdid = vpifparams->std_info.stdid;
  516. }
  517. /**
  518. * vpif_config_format: configure default frame format in the device
  519. * ch : ptr to channel object
  520. */
  521. static void vpif_config_format(struct channel_obj *ch)
  522. {
  523. struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
  524. vpif_dbg(2, debug, "vpif_config_format\n");
  525. common->fmt.fmt.pix.field = V4L2_FIELD_ANY;
  526. common->fmt.fmt.pix.sizeimage
  527. = config_params.channel_bufsize[ch->channel_id];
  528. if (ch->vpifparams.iface.if_type == VPIF_IF_RAW_BAYER)
  529. common->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_SBGGR8;
  530. else
  531. common->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV422P;
  532. common->fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  533. }
  534. /**
  535. * vpif_get_default_field() - Get default field type based on interface
  536. * @vpif_params - ptr to vpif params
  537. */
  538. static inline enum v4l2_field vpif_get_default_field(
  539. struct vpif_interface *iface)
  540. {
  541. return (iface->if_type == VPIF_IF_RAW_BAYER) ? V4L2_FIELD_NONE :
  542. V4L2_FIELD_INTERLACED;
  543. }
  544. /**
  545. * vpif_check_format() - check given pixel format for compatibility
  546. * @ch - channel ptr
  547. * @pixfmt - Given pixel format
  548. * @update - update the values as per hardware requirement
  549. *
  550. * Check the application pixel format for S_FMT and update the input
  551. * values as per hardware limits for TRY_FMT. The default pixel and
  552. * field format is selected based on interface type.
  553. */
  554. static int vpif_check_format(struct channel_obj *ch,
  555. struct v4l2_pix_format *pixfmt,
  556. int update)
  557. {
  558. struct common_obj *common = &(ch->common[VPIF_VIDEO_INDEX]);
  559. struct vpif_params *vpif_params = &ch->vpifparams;
  560. enum v4l2_field field = pixfmt->field;
  561. u32 sizeimage, hpitch, vpitch;
  562. int ret = -EINVAL;
  563. vpif_dbg(2, debug, "vpif_check_format\n");
  564. /**
  565. * first check for the pixel format. If if_type is Raw bayer,
  566. * only V4L2_PIX_FMT_SBGGR8 format is supported. Otherwise only
  567. * V4L2_PIX_FMT_YUV422P is supported
  568. */
  569. if (vpif_params->iface.if_type == VPIF_IF_RAW_BAYER) {
  570. if (pixfmt->pixelformat != V4L2_PIX_FMT_SBGGR8) {
  571. if (!update) {
  572. vpif_dbg(2, debug, "invalid pix format\n");
  573. goto exit;
  574. }
  575. pixfmt->pixelformat = V4L2_PIX_FMT_SBGGR8;
  576. }
  577. } else {
  578. if (pixfmt->pixelformat != V4L2_PIX_FMT_YUV422P) {
  579. if (!update) {
  580. vpif_dbg(2, debug, "invalid pixel format\n");
  581. goto exit;
  582. }
  583. pixfmt->pixelformat = V4L2_PIX_FMT_YUV422P;
  584. }
  585. }
  586. if (!(VPIF_VALID_FIELD(field))) {
  587. if (!update) {
  588. vpif_dbg(2, debug, "invalid field format\n");
  589. goto exit;
  590. }
  591. /**
  592. * By default use FIELD_NONE for RAW Bayer capture
  593. * and FIELD_INTERLACED for other interfaces
  594. */
  595. field = vpif_get_default_field(&vpif_params->iface);
  596. } else if (field == V4L2_FIELD_ANY)
  597. /* unsupported field. Use default */
  598. field = vpif_get_default_field(&vpif_params->iface);
  599. /* validate the hpitch */
  600. hpitch = pixfmt->bytesperline;
  601. if (hpitch < vpif_params->std_info.width) {
  602. if (!update) {
  603. vpif_dbg(2, debug, "invalid hpitch\n");
  604. goto exit;
  605. }
  606. hpitch = vpif_params->std_info.width;
  607. }
  608. sizeimage = pixfmt->sizeimage;
  609. vpitch = sizeimage / (hpitch * 2);
  610. /* validate the vpitch */
  611. if (vpitch < vpif_params->std_info.height) {
  612. if (!update) {
  613. vpif_dbg(2, debug, "Invalid vpitch\n");
  614. goto exit;
  615. }
  616. vpitch = vpif_params->std_info.height;
  617. }
  618. /* Check for 8 byte alignment */
  619. if (!ALIGN(hpitch, 8)) {
  620. if (!update) {
  621. vpif_dbg(2, debug, "invalid pitch alignment\n");
  622. goto exit;
  623. }
  624. /* adjust to next 8 byte boundary */
  625. hpitch = (((hpitch + 7) / 8) * 8);
  626. }
  627. /* if update is set, modify the bytesperline and sizeimage */
  628. if (update) {
  629. pixfmt->bytesperline = hpitch;
  630. pixfmt->sizeimage = hpitch * vpitch * 2;
  631. }
  632. /**
  633. * Image width and height is always based on current standard width and
  634. * height
  635. */
  636. pixfmt->width = common->fmt.fmt.pix.width;
  637. pixfmt->height = common->fmt.fmt.pix.height;
  638. return 0;
  639. exit:
  640. return ret;
  641. }
  642. /**
  643. * vpif_config_addr() - function to configure buffer address in vpif
  644. * @ch - channel ptr
  645. * @muxmode - channel mux mode
  646. */
  647. static void vpif_config_addr(struct channel_obj *ch, int muxmode)
  648. {
  649. struct common_obj *common;
  650. vpif_dbg(2, debug, "vpif_config_addr\n");
  651. common = &(ch->common[VPIF_VIDEO_INDEX]);
  652. if (VPIF_CHANNEL1_VIDEO == ch->channel_id)
  653. common->set_addr = ch1_set_videobuf_addr;
  654. else if (2 == muxmode)
  655. common->set_addr = ch0_set_videobuf_addr_yc_nmux;
  656. else
  657. common->set_addr = ch0_set_videobuf_addr;
  658. }
  659. /**
  660. * vpif_input_to_subdev() - Maps input to sub device
  661. * @vpif_cfg - global config ptr
  662. * @chan_cfg - channel config ptr
  663. * @input_index - Given input index from application
  664. *
  665. * lookup the sub device information for a given input index.
  666. * we report all the inputs to application. inputs table also
  667. * has sub device name for the each input
  668. */
  669. static int vpif_input_to_subdev(
  670. struct vpif_capture_config *vpif_cfg,
  671. struct vpif_capture_chan_config *chan_cfg,
  672. int input_index)
  673. {
  674. struct vpif_subdev_info *subdev_info;
  675. const char *subdev_name;
  676. int i;
  677. vpif_dbg(2, debug, "vpif_input_to_subdev\n");
  678. subdev_name = chan_cfg->inputs[input_index].subdev_name;
  679. if (subdev_name == NULL)
  680. return -1;
  681. /* loop through the sub device list to get the sub device info */
  682. for (i = 0; i < vpif_cfg->subdev_count; i++) {
  683. subdev_info = &vpif_cfg->subdev_info[i];
  684. if (!strcmp(subdev_info->name, subdev_name))
  685. return i;
  686. }
  687. return -1;
  688. }
  689. /**
  690. * vpif_set_input() - Select an input
  691. * @vpif_cfg - global config ptr
  692. * @ch - channel
  693. * @_index - Given input index from application
  694. *
  695. * Select the given input.
  696. */
  697. static int vpif_set_input(
  698. struct vpif_capture_config *vpif_cfg,
  699. struct channel_obj *ch,
  700. int index)
  701. {
  702. struct vpif_capture_chan_config *chan_cfg =
  703. &vpif_cfg->chan_config[ch->channel_id];
  704. struct vpif_subdev_info *subdev_info = NULL;
  705. struct v4l2_subdev *sd = NULL;
  706. u32 input = 0, output = 0;
  707. int sd_index;
  708. int ret;
  709. sd_index = vpif_input_to_subdev(vpif_cfg, chan_cfg, index);
  710. if (sd_index >= 0) {
  711. sd = vpif_obj.sd[sd_index];
  712. subdev_info = &vpif_cfg->subdev_info[sd_index];
  713. }
  714. /* first setup input path from sub device to vpif */
  715. if (sd && vpif_cfg->setup_input_path) {
  716. ret = vpif_cfg->setup_input_path(ch->channel_id,
  717. subdev_info->name);
  718. if (ret < 0) {
  719. vpif_dbg(1, debug, "couldn't setup input path for the" \
  720. " sub device %s, for input index %d\n",
  721. subdev_info->name, index);
  722. return ret;
  723. }
  724. }
  725. if (sd) {
  726. input = chan_cfg->inputs[index].input_route;
  727. output = chan_cfg->inputs[index].output_route;
  728. ret = v4l2_subdev_call(sd, video, s_routing,
  729. input, output, 0);
  730. if (ret < 0 && ret != -ENOIOCTLCMD) {
  731. vpif_dbg(1, debug, "Failed to set input\n");
  732. return ret;
  733. }
  734. }
  735. ch->input_idx = index;
  736. ch->sd = sd;
  737. /* copy interface parameters to vpif */
  738. ch->vpifparams.iface = chan_cfg->vpif_if;
  739. /* update tvnorms from the sub device input info */
  740. ch->video_dev->tvnorms = chan_cfg->inputs[index].input.std;
  741. return 0;
  742. }
  743. /**
  744. * vpif_querystd() - querystd handler
  745. * @file: file ptr
  746. * @priv: file handle
  747. * @std_id: ptr to std id
  748. *
  749. * This function is called to detect standard at the selected input
  750. */
  751. static int vpif_querystd(struct file *file, void *priv, v4l2_std_id *std_id)
  752. {
  753. struct video_device *vdev = video_devdata(file);
  754. struct channel_obj *ch = video_get_drvdata(vdev);
  755. int ret = 0;
  756. vpif_dbg(2, debug, "vpif_querystd\n");
  757. /* Call querystd function of decoder device */
  758. ret = v4l2_subdev_call(ch->sd, video, querystd, std_id);
  759. if (ret == -ENOIOCTLCMD || ret == -ENODEV)
  760. return -ENODATA;
  761. if (ret) {
  762. vpif_dbg(1, debug, "Failed to query standard for sub devices\n");
  763. return ret;
  764. }
  765. return 0;
  766. }
  767. /**
  768. * vpif_g_std() - get STD handler
  769. * @file: file ptr
  770. * @priv: file handle
  771. * @std_id: ptr to std id
  772. */
  773. static int vpif_g_std(struct file *file, void *priv, v4l2_std_id *std)
  774. {
  775. struct vpif_capture_config *config = vpif_dev->platform_data;
  776. struct video_device *vdev = video_devdata(file);
  777. struct channel_obj *ch = video_get_drvdata(vdev);
  778. struct vpif_capture_chan_config *chan_cfg;
  779. struct v4l2_input input;
  780. vpif_dbg(2, debug, "vpif_g_std\n");
  781. if (config->chan_config[ch->channel_id].inputs == NULL)
  782. return -ENODATA;
  783. chan_cfg = &config->chan_config[ch->channel_id];
  784. input = chan_cfg->inputs[ch->input_idx].input;
  785. if (input.capabilities != V4L2_IN_CAP_STD)
  786. return -ENODATA;
  787. *std = ch->video.stdid;
  788. return 0;
  789. }
  790. /**
  791. * vpif_s_std() - set STD handler
  792. * @file: file ptr
  793. * @priv: file handle
  794. * @std_id: ptr to std id
  795. */
  796. static int vpif_s_std(struct file *file, void *priv, v4l2_std_id std_id)
  797. {
  798. struct vpif_capture_config *config = vpif_dev->platform_data;
  799. struct video_device *vdev = video_devdata(file);
  800. struct channel_obj *ch = video_get_drvdata(vdev);
  801. struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
  802. struct vpif_capture_chan_config *chan_cfg;
  803. struct v4l2_input input;
  804. int ret;
  805. vpif_dbg(2, debug, "vpif_s_std\n");
  806. if (config->chan_config[ch->channel_id].inputs == NULL)
  807. return -ENODATA;
  808. chan_cfg = &config->chan_config[ch->channel_id];
  809. input = chan_cfg->inputs[ch->input_idx].input;
  810. if (input.capabilities != V4L2_IN_CAP_STD)
  811. return -ENODATA;
  812. if (vb2_is_busy(&common->buffer_queue))
  813. return -EBUSY;
  814. /* Call encoder subdevice function to set the standard */
  815. ch->video.stdid = std_id;
  816. memset(&ch->video.dv_timings, 0, sizeof(ch->video.dv_timings));
  817. /* Get the information about the standard */
  818. if (vpif_update_std_info(ch)) {
  819. vpif_err("Error getting the standard info\n");
  820. return -EINVAL;
  821. }
  822. /* Configure the default format information */
  823. vpif_config_format(ch);
  824. /* set standard in the sub device */
  825. ret = v4l2_subdev_call(ch->sd, video, s_std, std_id);
  826. if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV) {
  827. vpif_dbg(1, debug, "Failed to set standard for sub devices\n");
  828. return ret;
  829. }
  830. return 0;
  831. }
  832. /**
  833. * vpif_enum_input() - ENUMINPUT handler
  834. * @file: file ptr
  835. * @priv: file handle
  836. * @input: ptr to input structure
  837. */
  838. static int vpif_enum_input(struct file *file, void *priv,
  839. struct v4l2_input *input)
  840. {
  841. struct vpif_capture_config *config = vpif_dev->platform_data;
  842. struct video_device *vdev = video_devdata(file);
  843. struct channel_obj *ch = video_get_drvdata(vdev);
  844. struct vpif_capture_chan_config *chan_cfg;
  845. chan_cfg = &config->chan_config[ch->channel_id];
  846. if (input->index >= chan_cfg->input_count) {
  847. vpif_dbg(1, debug, "Invalid input index\n");
  848. return -EINVAL;
  849. }
  850. memcpy(input, &chan_cfg->inputs[input->index].input,
  851. sizeof(*input));
  852. return 0;
  853. }
  854. /**
  855. * vpif_g_input() - Get INPUT handler
  856. * @file: file ptr
  857. * @priv: file handle
  858. * @index: ptr to input index
  859. */
  860. static int vpif_g_input(struct file *file, void *priv, unsigned int *index)
  861. {
  862. struct video_device *vdev = video_devdata(file);
  863. struct channel_obj *ch = video_get_drvdata(vdev);
  864. *index = ch->input_idx;
  865. return 0;
  866. }
  867. /**
  868. * vpif_s_input() - Set INPUT handler
  869. * @file: file ptr
  870. * @priv: file handle
  871. * @index: input index
  872. */
  873. static int vpif_s_input(struct file *file, void *priv, unsigned int index)
  874. {
  875. struct vpif_capture_config *config = vpif_dev->platform_data;
  876. struct video_device *vdev = video_devdata(file);
  877. struct channel_obj *ch = video_get_drvdata(vdev);
  878. struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
  879. struct vpif_capture_chan_config *chan_cfg;
  880. chan_cfg = &config->chan_config[ch->channel_id];
  881. if (index >= chan_cfg->input_count)
  882. return -EINVAL;
  883. if (vb2_is_busy(&common->buffer_queue))
  884. return -EBUSY;
  885. return vpif_set_input(config, ch, index);
  886. }
  887. /**
  888. * vpif_enum_fmt_vid_cap() - ENUM_FMT handler
  889. * @file: file ptr
  890. * @priv: file handle
  891. * @index: input index
  892. */
  893. static int vpif_enum_fmt_vid_cap(struct file *file, void *priv,
  894. struct v4l2_fmtdesc *fmt)
  895. {
  896. struct video_device *vdev = video_devdata(file);
  897. struct channel_obj *ch = video_get_drvdata(vdev);
  898. if (fmt->index != 0) {
  899. vpif_dbg(1, debug, "Invalid format index\n");
  900. return -EINVAL;
  901. }
  902. /* Fill in the information about format */
  903. if (ch->vpifparams.iface.if_type == VPIF_IF_RAW_BAYER) {
  904. fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  905. strcpy(fmt->description, "Raw Mode -Bayer Pattern GrRBGb");
  906. fmt->pixelformat = V4L2_PIX_FMT_SBGGR8;
  907. } else {
  908. fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  909. strcpy(fmt->description, "YCbCr4:2:2 YC Planar");
  910. fmt->pixelformat = V4L2_PIX_FMT_YUV422P;
  911. }
  912. return 0;
  913. }
  914. /**
  915. * vpif_try_fmt_vid_cap() - TRY_FMT handler
  916. * @file: file ptr
  917. * @priv: file handle
  918. * @fmt: ptr to v4l2 format structure
  919. */
  920. static int vpif_try_fmt_vid_cap(struct file *file, void *priv,
  921. struct v4l2_format *fmt)
  922. {
  923. struct video_device *vdev = video_devdata(file);
  924. struct channel_obj *ch = video_get_drvdata(vdev);
  925. struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
  926. return vpif_check_format(ch, pixfmt, 1);
  927. }
  928. /**
  929. * vpif_g_fmt_vid_cap() - Set INPUT handler
  930. * @file: file ptr
  931. * @priv: file handle
  932. * @fmt: ptr to v4l2 format structure
  933. */
  934. static int vpif_g_fmt_vid_cap(struct file *file, void *priv,
  935. struct v4l2_format *fmt)
  936. {
  937. struct video_device *vdev = video_devdata(file);
  938. struct channel_obj *ch = video_get_drvdata(vdev);
  939. struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
  940. /* Check the validity of the buffer type */
  941. if (common->fmt.type != fmt->type)
  942. return -EINVAL;
  943. /* Fill in the information about format */
  944. *fmt = common->fmt;
  945. return 0;
  946. }
  947. /**
  948. * vpif_s_fmt_vid_cap() - Set FMT handler
  949. * @file: file ptr
  950. * @priv: file handle
  951. * @fmt: ptr to v4l2 format structure
  952. */
  953. static int vpif_s_fmt_vid_cap(struct file *file, void *priv,
  954. struct v4l2_format *fmt)
  955. {
  956. struct video_device *vdev = video_devdata(file);
  957. struct channel_obj *ch = video_get_drvdata(vdev);
  958. struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
  959. struct v4l2_pix_format *pixfmt;
  960. int ret = 0;
  961. vpif_dbg(2, debug, "%s\n", __func__);
  962. if (vb2_is_busy(&common->buffer_queue))
  963. return -EBUSY;
  964. pixfmt = &fmt->fmt.pix;
  965. /* Check for valid field format */
  966. ret = vpif_check_format(ch, pixfmt, 0);
  967. if (ret)
  968. return ret;
  969. /* store the format in the channel object */
  970. common->fmt = *fmt;
  971. return 0;
  972. }
  973. /**
  974. * vpif_querycap() - QUERYCAP handler
  975. * @file: file ptr
  976. * @priv: file handle
  977. * @cap: ptr to v4l2_capability structure
  978. */
  979. static int vpif_querycap(struct file *file, void *priv,
  980. struct v4l2_capability *cap)
  981. {
  982. struct vpif_capture_config *config = vpif_dev->platform_data;
  983. cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
  984. cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
  985. strlcpy(cap->driver, VPIF_DRIVER_NAME, sizeof(cap->driver));
  986. snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
  987. dev_name(vpif_dev));
  988. strlcpy(cap->card, config->card_name, sizeof(cap->card));
  989. return 0;
  990. }
  991. /**
  992. * vpif_enum_dv_timings() - ENUM_DV_TIMINGS handler
  993. * @file: file ptr
  994. * @priv: file handle
  995. * @timings: input timings
  996. */
  997. static int
  998. vpif_enum_dv_timings(struct file *file, void *priv,
  999. struct v4l2_enum_dv_timings *timings)
  1000. {
  1001. struct vpif_capture_config *config = vpif_dev->platform_data;
  1002. struct video_device *vdev = video_devdata(file);
  1003. struct channel_obj *ch = video_get_drvdata(vdev);
  1004. struct vpif_capture_chan_config *chan_cfg;
  1005. struct v4l2_input input;
  1006. int ret;
  1007. if (config->chan_config[ch->channel_id].inputs == NULL)
  1008. return -ENODATA;
  1009. chan_cfg = &config->chan_config[ch->channel_id];
  1010. input = chan_cfg->inputs[ch->input_idx].input;
  1011. if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS)
  1012. return -ENODATA;
  1013. timings->pad = 0;
  1014. ret = v4l2_subdev_call(ch->sd, pad, enum_dv_timings, timings);
  1015. if (ret == -ENOIOCTLCMD || ret == -ENODEV)
  1016. return -EINVAL;
  1017. return ret;
  1018. }
  1019. /**
  1020. * vpif_query_dv_timings() - QUERY_DV_TIMINGS handler
  1021. * @file: file ptr
  1022. * @priv: file handle
  1023. * @timings: input timings
  1024. */
  1025. static int
  1026. vpif_query_dv_timings(struct file *file, void *priv,
  1027. struct v4l2_dv_timings *timings)
  1028. {
  1029. struct vpif_capture_config *config = vpif_dev->platform_data;
  1030. struct video_device *vdev = video_devdata(file);
  1031. struct channel_obj *ch = video_get_drvdata(vdev);
  1032. struct vpif_capture_chan_config *chan_cfg;
  1033. struct v4l2_input input;
  1034. int ret;
  1035. if (config->chan_config[ch->channel_id].inputs == NULL)
  1036. return -ENODATA;
  1037. chan_cfg = &config->chan_config[ch->channel_id];
  1038. input = chan_cfg->inputs[ch->input_idx].input;
  1039. if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS)
  1040. return -ENODATA;
  1041. ret = v4l2_subdev_call(ch->sd, video, query_dv_timings, timings);
  1042. if (ret == -ENOIOCTLCMD || ret == -ENODEV)
  1043. return -ENODATA;
  1044. return ret;
  1045. }
  1046. /**
  1047. * vpif_s_dv_timings() - S_DV_TIMINGS handler
  1048. * @file: file ptr
  1049. * @priv: file handle
  1050. * @timings: digital video timings
  1051. */
  1052. static int vpif_s_dv_timings(struct file *file, void *priv,
  1053. struct v4l2_dv_timings *timings)
  1054. {
  1055. struct vpif_capture_config *config = vpif_dev->platform_data;
  1056. struct video_device *vdev = video_devdata(file);
  1057. struct channel_obj *ch = video_get_drvdata(vdev);
  1058. struct vpif_params *vpifparams = &ch->vpifparams;
  1059. struct vpif_channel_config_params *std_info = &vpifparams->std_info;
  1060. struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
  1061. struct video_obj *vid_ch = &ch->video;
  1062. struct v4l2_bt_timings *bt = &vid_ch->dv_timings.bt;
  1063. struct vpif_capture_chan_config *chan_cfg;
  1064. struct v4l2_input input;
  1065. int ret;
  1066. if (config->chan_config[ch->channel_id].inputs == NULL)
  1067. return -ENODATA;
  1068. chan_cfg = &config->chan_config[ch->channel_id];
  1069. input = chan_cfg->inputs[ch->input_idx].input;
  1070. if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS)
  1071. return -ENODATA;
  1072. if (timings->type != V4L2_DV_BT_656_1120) {
  1073. vpif_dbg(2, debug, "Timing type not defined\n");
  1074. return -EINVAL;
  1075. }
  1076. if (vb2_is_busy(&common->buffer_queue))
  1077. return -EBUSY;
  1078. /* Configure subdevice timings, if any */
  1079. ret = v4l2_subdev_call(ch->sd, video, s_dv_timings, timings);
  1080. if (ret == -ENOIOCTLCMD || ret == -ENODEV)
  1081. ret = 0;
  1082. if (ret < 0) {
  1083. vpif_dbg(2, debug, "Error setting custom DV timings\n");
  1084. return ret;
  1085. }
  1086. if (!(timings->bt.width && timings->bt.height &&
  1087. (timings->bt.hbackporch ||
  1088. timings->bt.hfrontporch ||
  1089. timings->bt.hsync) &&
  1090. timings->bt.vfrontporch &&
  1091. (timings->bt.vbackporch ||
  1092. timings->bt.vsync))) {
  1093. vpif_dbg(2, debug, "Timings for width, height, "
  1094. "horizontal back porch, horizontal sync, "
  1095. "horizontal front porch, vertical back porch, "
  1096. "vertical sync and vertical back porch "
  1097. "must be defined\n");
  1098. return -EINVAL;
  1099. }
  1100. vid_ch->dv_timings = *timings;
  1101. /* Configure video port timings */
  1102. std_info->eav2sav = V4L2_DV_BT_BLANKING_WIDTH(bt) - 8;
  1103. std_info->sav2eav = bt->width;
  1104. std_info->l1 = 1;
  1105. std_info->l3 = bt->vsync + bt->vbackporch + 1;
  1106. std_info->vsize = V4L2_DV_BT_FRAME_HEIGHT(bt);
  1107. if (bt->interlaced) {
  1108. if (bt->il_vbackporch || bt->il_vfrontporch || bt->il_vsync) {
  1109. std_info->l5 = std_info->vsize/2 -
  1110. (bt->vfrontporch - 1);
  1111. std_info->l7 = std_info->vsize/2 + 1;
  1112. std_info->l9 = std_info->l7 + bt->il_vsync +
  1113. bt->il_vbackporch + 1;
  1114. std_info->l11 = std_info->vsize -
  1115. (bt->il_vfrontporch - 1);
  1116. } else {
  1117. vpif_dbg(2, debug, "Required timing values for "
  1118. "interlaced BT format missing\n");
  1119. return -EINVAL;
  1120. }
  1121. } else {
  1122. std_info->l5 = std_info->vsize - (bt->vfrontporch - 1);
  1123. }
  1124. strncpy(std_info->name, "Custom timings BT656/1120", VPIF_MAX_NAME);
  1125. std_info->width = bt->width;
  1126. std_info->height = bt->height;
  1127. std_info->frm_fmt = bt->interlaced ? 0 : 1;
  1128. std_info->ycmux_mode = 0;
  1129. std_info->capture_format = 0;
  1130. std_info->vbi_supported = 0;
  1131. std_info->hd_sd = 1;
  1132. std_info->stdid = 0;
  1133. vid_ch->stdid = 0;
  1134. return 0;
  1135. }
  1136. /**
  1137. * vpif_g_dv_timings() - G_DV_TIMINGS handler
  1138. * @file: file ptr
  1139. * @priv: file handle
  1140. * @timings: digital video timings
  1141. */
  1142. static int vpif_g_dv_timings(struct file *file, void *priv,
  1143. struct v4l2_dv_timings *timings)
  1144. {
  1145. struct vpif_capture_config *config = vpif_dev->platform_data;
  1146. struct video_device *vdev = video_devdata(file);
  1147. struct channel_obj *ch = video_get_drvdata(vdev);
  1148. struct video_obj *vid_ch = &ch->video;
  1149. struct vpif_capture_chan_config *chan_cfg;
  1150. struct v4l2_input input;
  1151. if (config->chan_config[ch->channel_id].inputs == NULL)
  1152. return -ENODATA;
  1153. chan_cfg = &config->chan_config[ch->channel_id];
  1154. input = chan_cfg->inputs[ch->input_idx].input;
  1155. if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS)
  1156. return -ENODATA;
  1157. *timings = vid_ch->dv_timings;
  1158. return 0;
  1159. }
  1160. /*
  1161. * vpif_log_status() - Status information
  1162. * @file: file ptr
  1163. * @priv: file handle
  1164. *
  1165. * Returns zero.
  1166. */
  1167. static int vpif_log_status(struct file *filep, void *priv)
  1168. {
  1169. /* status for sub devices */
  1170. v4l2_device_call_all(&vpif_obj.v4l2_dev, 0, core, log_status);
  1171. return 0;
  1172. }
  1173. /* vpif capture ioctl operations */
  1174. static const struct v4l2_ioctl_ops vpif_ioctl_ops = {
  1175. .vidioc_querycap = vpif_querycap,
  1176. .vidioc_enum_fmt_vid_cap = vpif_enum_fmt_vid_cap,
  1177. .vidioc_g_fmt_vid_cap = vpif_g_fmt_vid_cap,
  1178. .vidioc_s_fmt_vid_cap = vpif_s_fmt_vid_cap,
  1179. .vidioc_try_fmt_vid_cap = vpif_try_fmt_vid_cap,
  1180. .vidioc_enum_input = vpif_enum_input,
  1181. .vidioc_s_input = vpif_s_input,
  1182. .vidioc_g_input = vpif_g_input,
  1183. .vidioc_reqbufs = vb2_ioctl_reqbufs,
  1184. .vidioc_create_bufs = vb2_ioctl_create_bufs,
  1185. .vidioc_querybuf = vb2_ioctl_querybuf,
  1186. .vidioc_qbuf = vb2_ioctl_qbuf,
  1187. .vidioc_dqbuf = vb2_ioctl_dqbuf,
  1188. .vidioc_expbuf = vb2_ioctl_expbuf,
  1189. .vidioc_streamon = vb2_ioctl_streamon,
  1190. .vidioc_streamoff = vb2_ioctl_streamoff,
  1191. .vidioc_querystd = vpif_querystd,
  1192. .vidioc_s_std = vpif_s_std,
  1193. .vidioc_g_std = vpif_g_std,
  1194. .vidioc_enum_dv_timings = vpif_enum_dv_timings,
  1195. .vidioc_query_dv_timings = vpif_query_dv_timings,
  1196. .vidioc_s_dv_timings = vpif_s_dv_timings,
  1197. .vidioc_g_dv_timings = vpif_g_dv_timings,
  1198. .vidioc_log_status = vpif_log_status,
  1199. };
  1200. /* vpif file operations */
  1201. static struct v4l2_file_operations vpif_fops = {
  1202. .owner = THIS_MODULE,
  1203. .open = v4l2_fh_open,
  1204. .release = vb2_fop_release,
  1205. .unlocked_ioctl = video_ioctl2,
  1206. .mmap = vb2_fop_mmap,
  1207. .poll = vb2_fop_poll
  1208. };
  1209. /**
  1210. * initialize_vpif() - Initialize vpif data structures
  1211. *
  1212. * Allocate memory for data structures and initialize them
  1213. */
  1214. static int initialize_vpif(void)
  1215. {
  1216. int err = 0, i, j;
  1217. int free_channel_objects_index;
  1218. /* Default number of buffers should be 3 */
  1219. if ((ch0_numbuffers > 0) &&
  1220. (ch0_numbuffers < config_params.min_numbuffers))
  1221. ch0_numbuffers = config_params.min_numbuffers;
  1222. if ((ch1_numbuffers > 0) &&
  1223. (ch1_numbuffers < config_params.min_numbuffers))
  1224. ch1_numbuffers = config_params.min_numbuffers;
  1225. /* Set buffer size to min buffers size if it is invalid */
  1226. if (ch0_bufsize < config_params.min_bufsize[VPIF_CHANNEL0_VIDEO])
  1227. ch0_bufsize =
  1228. config_params.min_bufsize[VPIF_CHANNEL0_VIDEO];
  1229. if (ch1_bufsize < config_params.min_bufsize[VPIF_CHANNEL1_VIDEO])
  1230. ch1_bufsize =
  1231. config_params.min_bufsize[VPIF_CHANNEL1_VIDEO];
  1232. config_params.numbuffers[VPIF_CHANNEL0_VIDEO] = ch0_numbuffers;
  1233. config_params.numbuffers[VPIF_CHANNEL1_VIDEO] = ch1_numbuffers;
  1234. if (ch0_numbuffers) {
  1235. config_params.channel_bufsize[VPIF_CHANNEL0_VIDEO]
  1236. = ch0_bufsize;
  1237. }
  1238. if (ch1_numbuffers) {
  1239. config_params.channel_bufsize[VPIF_CHANNEL1_VIDEO]
  1240. = ch1_bufsize;
  1241. }
  1242. /* Allocate memory for six channel objects */
  1243. for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
  1244. vpif_obj.dev[i] =
  1245. kzalloc(sizeof(*vpif_obj.dev[i]), GFP_KERNEL);
  1246. /* If memory allocation fails, return error */
  1247. if (!vpif_obj.dev[i]) {
  1248. free_channel_objects_index = i;
  1249. err = -ENOMEM;
  1250. goto vpif_init_free_channel_objects;
  1251. }
  1252. }
  1253. return 0;
  1254. vpif_init_free_channel_objects:
  1255. for (j = 0; j < free_channel_objects_index; j++)
  1256. kfree(vpif_obj.dev[j]);
  1257. return err;
  1258. }
  1259. static int vpif_async_bound(struct v4l2_async_notifier *notifier,
  1260. struct v4l2_subdev *subdev,
  1261. struct v4l2_async_subdev *asd)
  1262. {
  1263. int i;
  1264. for (i = 0; i < vpif_obj.config->subdev_count; i++)
  1265. if (!strcmp(vpif_obj.config->subdev_info[i].name,
  1266. subdev->name)) {
  1267. vpif_obj.sd[i] = subdev;
  1268. return 0;
  1269. }
  1270. return -EINVAL;
  1271. }
  1272. static int vpif_probe_complete(void)
  1273. {
  1274. struct common_obj *common;
  1275. struct video_device *vdev;
  1276. struct channel_obj *ch;
  1277. struct vb2_queue *q;
  1278. int i, j, err, k;
  1279. for (j = 0; j < VPIF_CAPTURE_MAX_DEVICES; j++) {
  1280. ch = vpif_obj.dev[j];
  1281. ch->channel_id = j;
  1282. common = &(ch->common[VPIF_VIDEO_INDEX]);
  1283. spin_lock_init(&common->irqlock);
  1284. mutex_init(&common->lock);
  1285. /* select input 0 */
  1286. err = vpif_set_input(vpif_obj.config, ch, 0);
  1287. if (err)
  1288. goto probe_out;
  1289. /* Initialize vb2 queue */
  1290. q = &common->buffer_queue;
  1291. q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  1292. q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
  1293. q->drv_priv = ch;
  1294. q->ops = &video_qops;
  1295. q->mem_ops = &vb2_dma_contig_memops;
  1296. q->buf_struct_size = sizeof(struct vpif_cap_buffer);
  1297. q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
  1298. q->min_buffers_needed = 1;
  1299. q->lock = &common->lock;
  1300. err = vb2_queue_init(q);
  1301. if (err) {
  1302. vpif_err("vpif_capture: vb2_queue_init() failed\n");
  1303. goto probe_out;
  1304. }
  1305. common->alloc_ctx = vb2_dma_contig_init_ctx(vpif_dev);
  1306. if (IS_ERR(common->alloc_ctx)) {
  1307. vpif_err("Failed to get the context\n");
  1308. err = PTR_ERR(common->alloc_ctx);
  1309. goto probe_out;
  1310. }
  1311. INIT_LIST_HEAD(&common->dma_queue);
  1312. /* Initialize the video_device structure */
  1313. vdev = ch->video_dev;
  1314. strlcpy(vdev->name, VPIF_DRIVER_NAME, sizeof(vdev->name));
  1315. vdev->release = video_device_release;
  1316. vdev->fops = &vpif_fops;
  1317. vdev->ioctl_ops = &vpif_ioctl_ops;
  1318. vdev->v4l2_dev = &vpif_obj.v4l2_dev;
  1319. vdev->vfl_dir = VFL_DIR_RX;
  1320. vdev->queue = q;
  1321. vdev->lock = &common->lock;
  1322. set_bit(V4L2_FL_USE_FH_PRIO, &vdev->flags);
  1323. video_set_drvdata(ch->video_dev, ch);
  1324. err = video_register_device(vdev,
  1325. VFL_TYPE_GRABBER, (j ? 1 : 0));
  1326. if (err)
  1327. goto probe_out;
  1328. }
  1329. v4l2_info(&vpif_obj.v4l2_dev, "VPIF capture driver initialized\n");
  1330. return 0;
  1331. probe_out:
  1332. for (k = 0; k < j; k++) {
  1333. /* Get the pointer to the channel object */
  1334. ch = vpif_obj.dev[k];
  1335. common = &ch->common[k];
  1336. vb2_dma_contig_cleanup_ctx(common->alloc_ctx);
  1337. /* Unregister video device */
  1338. video_unregister_device(ch->video_dev);
  1339. }
  1340. kfree(vpif_obj.sd);
  1341. for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
  1342. ch = vpif_obj.dev[i];
  1343. /* Note: does nothing if ch->video_dev == NULL */
  1344. video_device_release(ch->video_dev);
  1345. }
  1346. v4l2_device_unregister(&vpif_obj.v4l2_dev);
  1347. return err;
  1348. }
  1349. static int vpif_async_complete(struct v4l2_async_notifier *notifier)
  1350. {
  1351. return vpif_probe_complete();
  1352. }
  1353. /**
  1354. * vpif_probe : This function probes the vpif capture driver
  1355. * @pdev: platform device pointer
  1356. *
  1357. * This creates device entries by register itself to the V4L2 driver and
  1358. * initializes fields of each channel objects
  1359. */
  1360. static __init int vpif_probe(struct platform_device *pdev)
  1361. {
  1362. struct vpif_subdev_info *subdevdata;
  1363. int i, j, err;
  1364. int res_idx = 0;
  1365. struct i2c_adapter *i2c_adap;
  1366. struct channel_obj *ch;
  1367. struct video_device *vfd;
  1368. struct resource *res;
  1369. int subdev_count;
  1370. vpif_dev = &pdev->dev;
  1371. err = initialize_vpif();
  1372. if (err) {
  1373. v4l2_err(vpif_dev->driver, "Error initializing vpif\n");
  1374. return err;
  1375. }
  1376. err = v4l2_device_register(vpif_dev, &vpif_obj.v4l2_dev);
  1377. if (err) {
  1378. v4l2_err(vpif_dev->driver, "Error registering v4l2 device\n");
  1379. return err;
  1380. }
  1381. while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) {
  1382. err = devm_request_irq(&pdev->dev, res->start, vpif_channel_isr,
  1383. IRQF_SHARED, VPIF_DRIVER_NAME,
  1384. (void *)(&vpif_obj.dev[res_idx]->
  1385. channel_id));
  1386. if (err) {
  1387. err = -EINVAL;
  1388. goto vpif_unregister;
  1389. }
  1390. res_idx++;
  1391. }
  1392. for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
  1393. /* Get the pointer to the channel object */
  1394. ch = vpif_obj.dev[i];
  1395. /* Allocate memory for video device */
  1396. vfd = video_device_alloc();
  1397. if (NULL == vfd) {
  1398. for (j = 0; j < i; j++) {
  1399. ch = vpif_obj.dev[j];
  1400. video_device_release(ch->video_dev);
  1401. }
  1402. err = -ENOMEM;
  1403. goto vpif_unregister;
  1404. }
  1405. /* Set video_dev to the video device */
  1406. ch->video_dev = vfd;
  1407. }
  1408. vpif_obj.config = pdev->dev.platform_data;
  1409. subdev_count = vpif_obj.config->subdev_count;
  1410. vpif_obj.sd = kzalloc(sizeof(struct v4l2_subdev *) * subdev_count,
  1411. GFP_KERNEL);
  1412. if (vpif_obj.sd == NULL) {
  1413. vpif_err("unable to allocate memory for subdevice pointers\n");
  1414. err = -ENOMEM;
  1415. goto vpif_sd_error;
  1416. }
  1417. if (!vpif_obj.config->asd_sizes) {
  1418. i2c_adap = i2c_get_adapter(1);
  1419. for (i = 0; i < subdev_count; i++) {
  1420. subdevdata = &vpif_obj.config->subdev_info[i];
  1421. vpif_obj.sd[i] =
  1422. v4l2_i2c_new_subdev_board(&vpif_obj.v4l2_dev,
  1423. i2c_adap,
  1424. &subdevdata->
  1425. board_info,
  1426. NULL);
  1427. if (!vpif_obj.sd[i]) {
  1428. vpif_err("Error registering v4l2 subdevice\n");
  1429. err = -ENODEV;
  1430. goto probe_subdev_out;
  1431. }
  1432. v4l2_info(&vpif_obj.v4l2_dev,
  1433. "registered sub device %s\n",
  1434. subdevdata->name);
  1435. }
  1436. vpif_probe_complete();
  1437. } else {
  1438. vpif_obj.notifier.subdevs = vpif_obj.config->asd;
  1439. vpif_obj.notifier.num_subdevs = vpif_obj.config->asd_sizes[0];
  1440. vpif_obj.notifier.bound = vpif_async_bound;
  1441. vpif_obj.notifier.complete = vpif_async_complete;
  1442. err = v4l2_async_notifier_register(&vpif_obj.v4l2_dev,
  1443. &vpif_obj.notifier);
  1444. if (err) {
  1445. vpif_err("Error registering async notifier\n");
  1446. err = -EINVAL;
  1447. goto probe_subdev_out;
  1448. }
  1449. }
  1450. return 0;
  1451. probe_subdev_out:
  1452. /* free sub devices memory */
  1453. kfree(vpif_obj.sd);
  1454. vpif_sd_error:
  1455. for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
  1456. ch = vpif_obj.dev[i];
  1457. /* Note: does nothing if ch->video_dev == NULL */
  1458. video_device_release(ch->video_dev);
  1459. }
  1460. vpif_unregister:
  1461. v4l2_device_unregister(&vpif_obj.v4l2_dev);
  1462. return err;
  1463. }
  1464. /**
  1465. * vpif_remove() - driver remove handler
  1466. * @device: ptr to platform device structure
  1467. *
  1468. * The vidoe device is unregistered
  1469. */
  1470. static int vpif_remove(struct platform_device *device)
  1471. {
  1472. struct common_obj *common;
  1473. struct channel_obj *ch;
  1474. int i;
  1475. v4l2_device_unregister(&vpif_obj.v4l2_dev);
  1476. kfree(vpif_obj.sd);
  1477. /* un-register device */
  1478. for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
  1479. /* Get the pointer to the channel object */
  1480. ch = vpif_obj.dev[i];
  1481. common = &ch->common[i];
  1482. vb2_dma_contig_cleanup_ctx(common->alloc_ctx);
  1483. /* Unregister video device */
  1484. video_unregister_device(ch->video_dev);
  1485. kfree(vpif_obj.dev[i]);
  1486. }
  1487. return 0;
  1488. }
  1489. #ifdef CONFIG_PM_SLEEP
  1490. /**
  1491. * vpif_suspend: vpif device suspend
  1492. */
  1493. static int vpif_suspend(struct device *dev)
  1494. {
  1495. struct common_obj *common;
  1496. struct channel_obj *ch;
  1497. int i;
  1498. for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
  1499. /* Get the pointer to the channel object */
  1500. ch = vpif_obj.dev[i];
  1501. common = &ch->common[VPIF_VIDEO_INDEX];
  1502. if (!vb2_is_streaming(&common->buffer_queue))
  1503. continue;
  1504. mutex_lock(&common->lock);
  1505. /* Disable channel */
  1506. if (ch->channel_id == VPIF_CHANNEL0_VIDEO) {
  1507. enable_channel0(0);
  1508. channel0_intr_enable(0);
  1509. }
  1510. if (ch->channel_id == VPIF_CHANNEL1_VIDEO ||
  1511. ycmux_mode == 2) {
  1512. enable_channel1(0);
  1513. channel1_intr_enable(0);
  1514. }
  1515. mutex_unlock(&common->lock);
  1516. }
  1517. return 0;
  1518. }
  1519. /*
  1520. * vpif_resume: vpif device suspend
  1521. */
  1522. static int vpif_resume(struct device *dev)
  1523. {
  1524. struct common_obj *common;
  1525. struct channel_obj *ch;
  1526. int i;
  1527. for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
  1528. /* Get the pointer to the channel object */
  1529. ch = vpif_obj.dev[i];
  1530. common = &ch->common[VPIF_VIDEO_INDEX];
  1531. if (!vb2_is_streaming(&common->buffer_queue))
  1532. continue;
  1533. mutex_lock(&common->lock);
  1534. /* Enable channel */
  1535. if (ch->channel_id == VPIF_CHANNEL0_VIDEO) {
  1536. enable_channel0(1);
  1537. channel0_intr_enable(1);
  1538. }
  1539. if (ch->channel_id == VPIF_CHANNEL1_VIDEO ||
  1540. ycmux_mode == 2) {
  1541. enable_channel1(1);
  1542. channel1_intr_enable(1);
  1543. }
  1544. mutex_unlock(&common->lock);
  1545. }
  1546. return 0;
  1547. }
  1548. #endif
  1549. static SIMPLE_DEV_PM_OPS(vpif_pm_ops, vpif_suspend, vpif_resume);
  1550. static __refdata struct platform_driver vpif_driver = {
  1551. .driver = {
  1552. .name = VPIF_DRIVER_NAME,
  1553. .owner = THIS_MODULE,
  1554. .pm = &vpif_pm_ops,
  1555. },
  1556. .probe = vpif_probe,
  1557. .remove = vpif_remove,
  1558. };
  1559. module_platform_driver(vpif_driver);