vpif_capture.c 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382
  1. /*
  2. * Copyright (C) 2009 Texas Instruments Inc
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. *
  18. * TODO : add support for VBI & HBI data service
  19. * add static buffer allocation
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/init.h>
  23. #include <linux/module.h>
  24. #include <linux/errno.h>
  25. #include <linux/fs.h>
  26. #include <linux/mm.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/workqueue.h>
  29. #include <linux/string.h>
  30. #include <linux/videodev2.h>
  31. #include <linux/wait.h>
  32. #include <linux/time.h>
  33. #include <linux/i2c.h>
  34. #include <linux/platform_device.h>
  35. #include <linux/io.h>
  36. #include <linux/slab.h>
  37. #include <media/v4l2-device.h>
  38. #include <media/v4l2-ioctl.h>
  39. #include <media/v4l2-chip-ident.h>
  40. #include "vpif_capture.h"
  41. #include "vpif.h"
  42. MODULE_DESCRIPTION("TI DaVinci VPIF Capture driver");
  43. MODULE_LICENSE("GPL");
  44. MODULE_VERSION(VPIF_CAPTURE_VERSION);
  45. #define vpif_err(fmt, arg...) v4l2_err(&vpif_obj.v4l2_dev, fmt, ## arg)
  46. #define vpif_dbg(level, debug, fmt, arg...) \
  47. v4l2_dbg(level, debug, &vpif_obj.v4l2_dev, fmt, ## arg)
  48. static int debug = 1;
  49. static u32 ch0_numbuffers = 3;
  50. static u32 ch1_numbuffers = 3;
  51. static u32 ch0_bufsize = 1920 * 1080 * 2;
  52. static u32 ch1_bufsize = 720 * 576 * 2;
  53. module_param(debug, int, 0644);
  54. module_param(ch0_numbuffers, uint, S_IRUGO);
  55. module_param(ch1_numbuffers, uint, S_IRUGO);
  56. module_param(ch0_bufsize, uint, S_IRUGO);
  57. module_param(ch1_bufsize, uint, S_IRUGO);
  58. MODULE_PARM_DESC(debug, "Debug level 0-1");
  59. MODULE_PARM_DESC(ch2_numbuffers, "Channel0 buffer count (default:3)");
  60. MODULE_PARM_DESC(ch3_numbuffers, "Channel1 buffer count (default:3)");
  61. MODULE_PARM_DESC(ch2_bufsize, "Channel0 buffer size (default:1920 x 1080 x 2)");
  62. MODULE_PARM_DESC(ch3_bufsize, "Channel1 buffer size (default:720 x 576 x 2)");
  63. static struct vpif_config_params config_params = {
  64. .min_numbuffers = 3,
  65. .numbuffers[0] = 3,
  66. .numbuffers[1] = 3,
  67. .min_bufsize[0] = 720 * 480 * 2,
  68. .min_bufsize[1] = 720 * 480 * 2,
  69. .channel_bufsize[0] = 1920 * 1080 * 2,
  70. .channel_bufsize[1] = 720 * 576 * 2,
  71. };
  72. /* global variables */
  73. static struct vpif_device vpif_obj = { {NULL} };
  74. static struct device *vpif_dev;
  75. static void vpif_calculate_offsets(struct channel_obj *ch);
  76. static void vpif_config_addr(struct channel_obj *ch, int muxmode);
  77. /**
  78. * buffer_prepare : callback function for buffer prepare
  79. * @vb: ptr to vb2_buffer
  80. *
  81. * This is the callback function for buffer prepare when vb2_qbuf()
  82. * function is called. The buffer is prepared and user space virtual address
  83. * or user address is converted into physical address
  84. */
  85. static int vpif_buffer_prepare(struct vb2_buffer *vb)
  86. {
  87. /* Get the file handle object and channel object */
  88. struct vpif_fh *fh = vb2_get_drv_priv(vb->vb2_queue);
  89. struct vb2_queue *q = vb->vb2_queue;
  90. struct channel_obj *ch = fh->channel;
  91. struct common_obj *common;
  92. unsigned long addr;
  93. vpif_dbg(2, debug, "vpif_buffer_prepare\n");
  94. common = &ch->common[VPIF_VIDEO_INDEX];
  95. if (vb->state != VB2_BUF_STATE_ACTIVE &&
  96. vb->state != VB2_BUF_STATE_PREPARED) {
  97. vb2_set_plane_payload(vb, 0, common->fmt.fmt.pix.sizeimage);
  98. if (vb2_plane_vaddr(vb, 0) &&
  99. vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0))
  100. goto exit;
  101. addr = vb2_dma_contig_plane_dma_addr(vb, 0);
  102. if (q->streaming) {
  103. if (!IS_ALIGNED((addr + common->ytop_off), 8) ||
  104. !IS_ALIGNED((addr + common->ybtm_off), 8) ||
  105. !IS_ALIGNED((addr + common->ctop_off), 8) ||
  106. !IS_ALIGNED((addr + common->cbtm_off), 8))
  107. goto exit;
  108. }
  109. }
  110. return 0;
  111. exit:
  112. vpif_dbg(1, debug, "buffer_prepare:offset is not aligned to 8 bytes\n");
  113. return -EINVAL;
  114. }
  115. /**
  116. * vpif_buffer_queue_setup : Callback function for buffer setup.
  117. * @vq: vb2_queue ptr
  118. * @fmt: v4l2 format
  119. * @nbuffers: ptr to number of buffers requested by application
  120. * @nplanes:: contains number of distinct video planes needed to hold a frame
  121. * @sizes[]: contains the size (in bytes) of each plane.
  122. * @alloc_ctxs: ptr to allocation context
  123. *
  124. * This callback function is called when reqbuf() is called to adjust
  125. * the buffer count and buffer size
  126. */
  127. static int vpif_buffer_queue_setup(struct vb2_queue *vq,
  128. const struct v4l2_format *fmt,
  129. unsigned int *nbuffers, unsigned int *nplanes,
  130. unsigned int sizes[], void *alloc_ctxs[])
  131. {
  132. /* Get the file handle object and channel object */
  133. struct vpif_fh *fh = vb2_get_drv_priv(vq);
  134. struct channel_obj *ch = fh->channel;
  135. struct common_obj *common;
  136. unsigned long size;
  137. common = &ch->common[VPIF_VIDEO_INDEX];
  138. vpif_dbg(2, debug, "vpif_buffer_setup\n");
  139. /* If memory type is not mmap, return */
  140. if (V4L2_MEMORY_MMAP == common->memory) {
  141. /* Calculate the size of the buffer */
  142. size = config_params.channel_bufsize[ch->channel_id];
  143. /*
  144. * Checking if the buffer size exceeds the available buffer
  145. * ycmux_mode = 0 means 1 channel mode HD and
  146. * ycmux_mode = 1 means 2 channels mode SD
  147. */
  148. if (ch->vpifparams.std_info.ycmux_mode == 0) {
  149. if (config_params.video_limit[ch->channel_id])
  150. while (size * *nbuffers >
  151. (config_params.video_limit[0]
  152. + config_params.video_limit[1]))
  153. (*nbuffers)--;
  154. } else {
  155. if (config_params.video_limit[ch->channel_id])
  156. while (size * *nbuffers >
  157. config_params.video_limit[ch->channel_id])
  158. (*nbuffers)--;
  159. }
  160. } else {
  161. size = common->fmt.fmt.pix.sizeimage;
  162. }
  163. if (*nbuffers < config_params.min_numbuffers)
  164. *nbuffers = config_params.min_numbuffers;
  165. *nplanes = 1;
  166. sizes[0] = size;
  167. alloc_ctxs[0] = common->alloc_ctx;
  168. return 0;
  169. }
  170. /**
  171. * vpif_buffer_queue : Callback function to add buffer to DMA queue
  172. * @vb: ptr to vb2_buffer
  173. */
  174. static void vpif_buffer_queue(struct vb2_buffer *vb)
  175. {
  176. /* Get the file handle object and channel object */
  177. struct vpif_fh *fh = vb2_get_drv_priv(vb->vb2_queue);
  178. struct channel_obj *ch = fh->channel;
  179. struct vpif_cap_buffer *buf = container_of(vb,
  180. struct vpif_cap_buffer, vb);
  181. struct common_obj *common;
  182. unsigned long flags;
  183. common = &ch->common[VPIF_VIDEO_INDEX];
  184. vpif_dbg(2, debug, "vpif_buffer_queue\n");
  185. spin_lock_irqsave(&common->irqlock, flags);
  186. /* add the buffer to the DMA queue */
  187. list_add_tail(&buf->list, &common->dma_queue);
  188. spin_unlock_irqrestore(&common->irqlock, flags);
  189. }
  190. /**
  191. * vpif_buf_cleanup : Callback function to free buffer
  192. * @vb: ptr to vb2_buffer
  193. *
  194. * This function is called from the videobuf2 layer to free memory
  195. * allocated to the buffers
  196. */
  197. static void vpif_buf_cleanup(struct vb2_buffer *vb)
  198. {
  199. /* Get the file handle object and channel object */
  200. struct vpif_fh *fh = vb2_get_drv_priv(vb->vb2_queue);
  201. struct vpif_cap_buffer *buf = container_of(vb,
  202. struct vpif_cap_buffer, vb);
  203. struct channel_obj *ch = fh->channel;
  204. struct common_obj *common;
  205. unsigned long flags;
  206. common = &ch->common[VPIF_VIDEO_INDEX];
  207. spin_lock_irqsave(&common->irqlock, flags);
  208. if (vb->state == VB2_BUF_STATE_ACTIVE)
  209. list_del_init(&buf->list);
  210. spin_unlock_irqrestore(&common->irqlock, flags);
  211. }
  212. static void vpif_wait_prepare(struct vb2_queue *vq)
  213. {
  214. struct vpif_fh *fh = vb2_get_drv_priv(vq);
  215. struct channel_obj *ch = fh->channel;
  216. struct common_obj *common;
  217. common = &ch->common[VPIF_VIDEO_INDEX];
  218. mutex_unlock(&common->lock);
  219. }
  220. static void vpif_wait_finish(struct vb2_queue *vq)
  221. {
  222. struct vpif_fh *fh = vb2_get_drv_priv(vq);
  223. struct channel_obj *ch = fh->channel;
  224. struct common_obj *common;
  225. common = &ch->common[VPIF_VIDEO_INDEX];
  226. mutex_lock(&common->lock);
  227. }
  228. static int vpif_buffer_init(struct vb2_buffer *vb)
  229. {
  230. struct vpif_cap_buffer *buf = container_of(vb,
  231. struct vpif_cap_buffer, vb);
  232. INIT_LIST_HEAD(&buf->list);
  233. return 0;
  234. }
  235. static u8 channel_first_int[VPIF_NUMBER_OF_OBJECTS][2] =
  236. { {1, 1} };
  237. static int vpif_start_streaming(struct vb2_queue *vq, unsigned int count)
  238. {
  239. struct vpif_capture_config *vpif_config_data =
  240. vpif_dev->platform_data;
  241. struct vpif_fh *fh = vb2_get_drv_priv(vq);
  242. struct channel_obj *ch = fh->channel;
  243. struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
  244. struct vpif_params *vpif = &ch->vpifparams;
  245. unsigned long addr = 0;
  246. unsigned long flags;
  247. int ret;
  248. /* If buffer queue is empty, return error */
  249. spin_lock_irqsave(&common->irqlock, flags);
  250. if (list_empty(&common->dma_queue)) {
  251. spin_unlock_irqrestore(&common->irqlock, flags);
  252. vpif_dbg(1, debug, "buffer queue is empty\n");
  253. return -EIO;
  254. }
  255. /* Get the next frame from the buffer queue */
  256. common->cur_frm = common->next_frm = list_entry(common->dma_queue.next,
  257. struct vpif_cap_buffer, list);
  258. /* Remove buffer from the buffer queue */
  259. list_del(&common->cur_frm->list);
  260. spin_unlock_irqrestore(&common->irqlock, flags);
  261. /* Mark state of the current frame to active */
  262. common->cur_frm->vb.state = VB2_BUF_STATE_ACTIVE;
  263. /* Initialize field_id and started member */
  264. ch->field_id = 0;
  265. common->started = 1;
  266. addr = vb2_dma_contig_plane_dma_addr(&common->cur_frm->vb, 0);
  267. /* Calculate the offset for Y and C data in the buffer */
  268. vpif_calculate_offsets(ch);
  269. if ((vpif->std_info.frm_fmt &&
  270. ((common->fmt.fmt.pix.field != V4L2_FIELD_NONE) &&
  271. (common->fmt.fmt.pix.field != V4L2_FIELD_ANY))) ||
  272. (!vpif->std_info.frm_fmt &&
  273. (common->fmt.fmt.pix.field == V4L2_FIELD_NONE))) {
  274. vpif_dbg(1, debug, "conflict in field format and std format\n");
  275. return -EINVAL;
  276. }
  277. /* configure 1 or 2 channel mode */
  278. if (vpif_config_data->setup_input_channel_mode) {
  279. ret = vpif_config_data->
  280. setup_input_channel_mode(vpif->std_info.ycmux_mode);
  281. if (ret < 0) {
  282. vpif_dbg(1, debug, "can't set vpif channel mode\n");
  283. return ret;
  284. }
  285. }
  286. /* Call vpif_set_params function to set the parameters and addresses */
  287. ret = vpif_set_video_params(vpif, ch->channel_id);
  288. if (ret < 0) {
  289. vpif_dbg(1, debug, "can't set video params\n");
  290. return ret;
  291. }
  292. common->started = ret;
  293. vpif_config_addr(ch, ret);
  294. common->set_addr(addr + common->ytop_off,
  295. addr + common->ybtm_off,
  296. addr + common->ctop_off,
  297. addr + common->cbtm_off);
  298. /**
  299. * Set interrupt for both the fields in VPIF Register enable channel in
  300. * VPIF register
  301. */
  302. channel_first_int[VPIF_VIDEO_INDEX][ch->channel_id] = 1;
  303. if ((VPIF_CHANNEL0_VIDEO == ch->channel_id)) {
  304. channel0_intr_assert();
  305. channel0_intr_enable(1);
  306. enable_channel0(1);
  307. }
  308. if ((VPIF_CHANNEL1_VIDEO == ch->channel_id) ||
  309. (common->started == 2)) {
  310. channel1_intr_assert();
  311. channel1_intr_enable(1);
  312. enable_channel1(1);
  313. }
  314. return 0;
  315. }
  316. /* abort streaming and wait for last buffer */
  317. static int vpif_stop_streaming(struct vb2_queue *vq)
  318. {
  319. struct vpif_fh *fh = vb2_get_drv_priv(vq);
  320. struct channel_obj *ch = fh->channel;
  321. struct common_obj *common;
  322. unsigned long flags;
  323. if (!vb2_is_streaming(vq))
  324. return 0;
  325. common = &ch->common[VPIF_VIDEO_INDEX];
  326. /* release all active buffers */
  327. spin_lock_irqsave(&common->irqlock, flags);
  328. while (!list_empty(&common->dma_queue)) {
  329. common->next_frm = list_entry(common->dma_queue.next,
  330. struct vpif_cap_buffer, list);
  331. list_del(&common->next_frm->list);
  332. vb2_buffer_done(&common->next_frm->vb, VB2_BUF_STATE_ERROR);
  333. }
  334. spin_unlock_irqrestore(&common->irqlock, flags);
  335. return 0;
  336. }
  337. static struct vb2_ops video_qops = {
  338. .queue_setup = vpif_buffer_queue_setup,
  339. .wait_prepare = vpif_wait_prepare,
  340. .wait_finish = vpif_wait_finish,
  341. .buf_init = vpif_buffer_init,
  342. .buf_prepare = vpif_buffer_prepare,
  343. .start_streaming = vpif_start_streaming,
  344. .stop_streaming = vpif_stop_streaming,
  345. .buf_cleanup = vpif_buf_cleanup,
  346. .buf_queue = vpif_buffer_queue,
  347. };
  348. /**
  349. * vpif_process_buffer_complete: process a completed buffer
  350. * @common: ptr to common channel object
  351. *
  352. * This function time stamp the buffer and mark it as DONE. It also
  353. * wake up any process waiting on the QUEUE and set the next buffer
  354. * as current
  355. */
  356. static void vpif_process_buffer_complete(struct common_obj *common)
  357. {
  358. v4l2_get_timestamp(&common->cur_frm->vb.v4l2_buf.timestamp);
  359. vb2_buffer_done(&common->cur_frm->vb,
  360. VB2_BUF_STATE_DONE);
  361. /* Make curFrm pointing to nextFrm */
  362. common->cur_frm = common->next_frm;
  363. }
  364. /**
  365. * vpif_schedule_next_buffer: set next buffer address for capture
  366. * @common : ptr to common channel object
  367. *
  368. * This function will get next buffer from the dma queue and
  369. * set the buffer address in the vpif register for capture.
  370. * the buffer is marked active
  371. */
  372. static void vpif_schedule_next_buffer(struct common_obj *common)
  373. {
  374. unsigned long addr = 0;
  375. spin_lock(&common->irqlock);
  376. common->next_frm = list_entry(common->dma_queue.next,
  377. struct vpif_cap_buffer, list);
  378. /* Remove that buffer from the buffer queue */
  379. list_del(&common->next_frm->list);
  380. spin_unlock(&common->irqlock);
  381. common->next_frm->vb.state = VB2_BUF_STATE_ACTIVE;
  382. addr = vb2_dma_contig_plane_dma_addr(&common->next_frm->vb, 0);
  383. /* Set top and bottom field addresses in VPIF registers */
  384. common->set_addr(addr + common->ytop_off,
  385. addr + common->ybtm_off,
  386. addr + common->ctop_off,
  387. addr + common->cbtm_off);
  388. }
  389. /**
  390. * vpif_channel_isr : ISR handler for vpif capture
  391. * @irq: irq number
  392. * @dev_id: dev_id ptr
  393. *
  394. * It changes status of the captured buffer, takes next buffer from the queue
  395. * and sets its address in VPIF registers
  396. */
  397. static irqreturn_t vpif_channel_isr(int irq, void *dev_id)
  398. {
  399. struct vpif_device *dev = &vpif_obj;
  400. struct common_obj *common;
  401. struct channel_obj *ch;
  402. enum v4l2_field field;
  403. int channel_id = 0;
  404. int fid = -1, i;
  405. channel_id = *(int *)(dev_id);
  406. if (!vpif_intr_status(channel_id))
  407. return IRQ_NONE;
  408. ch = dev->dev[channel_id];
  409. field = ch->common[VPIF_VIDEO_INDEX].fmt.fmt.pix.field;
  410. for (i = 0; i < VPIF_NUMBER_OF_OBJECTS; i++) {
  411. common = &ch->common[i];
  412. /* skip If streaming is not started in this channel */
  413. if (0 == common->started)
  414. continue;
  415. /* Check the field format */
  416. if (1 == ch->vpifparams.std_info.frm_fmt) {
  417. /* Progressive mode */
  418. spin_lock(&common->irqlock);
  419. if (list_empty(&common->dma_queue)) {
  420. spin_unlock(&common->irqlock);
  421. continue;
  422. }
  423. spin_unlock(&common->irqlock);
  424. if (!channel_first_int[i][channel_id])
  425. vpif_process_buffer_complete(common);
  426. channel_first_int[i][channel_id] = 0;
  427. vpif_schedule_next_buffer(common);
  428. channel_first_int[i][channel_id] = 0;
  429. } else {
  430. /**
  431. * Interlaced mode. If it is first interrupt, ignore
  432. * it
  433. */
  434. if (channel_first_int[i][channel_id]) {
  435. channel_first_int[i][channel_id] = 0;
  436. continue;
  437. }
  438. if (0 == i) {
  439. ch->field_id ^= 1;
  440. /* Get field id from VPIF registers */
  441. fid = vpif_channel_getfid(ch->channel_id);
  442. if (fid != ch->field_id) {
  443. /**
  444. * If field id does not match stored
  445. * field id, make them in sync
  446. */
  447. if (0 == fid)
  448. ch->field_id = fid;
  449. return IRQ_HANDLED;
  450. }
  451. }
  452. /* device field id and local field id are in sync */
  453. if (0 == fid) {
  454. /* this is even field */
  455. if (common->cur_frm == common->next_frm)
  456. continue;
  457. /* mark the current buffer as done */
  458. vpif_process_buffer_complete(common);
  459. } else if (1 == fid) {
  460. /* odd field */
  461. spin_lock(&common->irqlock);
  462. if (list_empty(&common->dma_queue) ||
  463. (common->cur_frm != common->next_frm)) {
  464. spin_unlock(&common->irqlock);
  465. continue;
  466. }
  467. spin_unlock(&common->irqlock);
  468. vpif_schedule_next_buffer(common);
  469. }
  470. }
  471. }
  472. return IRQ_HANDLED;
  473. }
  474. /**
  475. * vpif_update_std_info() - update standard related info
  476. * @ch: ptr to channel object
  477. *
  478. * For a given standard selected by application, update values
  479. * in the device data structures
  480. */
  481. static int vpif_update_std_info(struct channel_obj *ch)
  482. {
  483. struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
  484. struct vpif_params *vpifparams = &ch->vpifparams;
  485. const struct vpif_channel_config_params *config;
  486. struct vpif_channel_config_params *std_info = &vpifparams->std_info;
  487. struct video_obj *vid_ch = &ch->video;
  488. int index;
  489. vpif_dbg(2, debug, "vpif_update_std_info\n");
  490. for (index = 0; index < vpif_ch_params_count; index++) {
  491. config = &vpif_ch_params[index];
  492. if (config->hd_sd == 0) {
  493. vpif_dbg(2, debug, "SD format\n");
  494. if (config->stdid & vid_ch->stdid) {
  495. memcpy(std_info, config, sizeof(*config));
  496. break;
  497. }
  498. } else {
  499. vpif_dbg(2, debug, "HD format\n");
  500. if (!memcmp(&config->dv_timings, &vid_ch->dv_timings,
  501. sizeof(vid_ch->dv_timings))) {
  502. memcpy(std_info, config, sizeof(*config));
  503. break;
  504. }
  505. }
  506. }
  507. /* standard not found */
  508. if (index == vpif_ch_params_count)
  509. return -EINVAL;
  510. common->fmt.fmt.pix.width = std_info->width;
  511. common->width = std_info->width;
  512. common->fmt.fmt.pix.height = std_info->height;
  513. common->height = std_info->height;
  514. common->fmt.fmt.pix.bytesperline = std_info->width;
  515. vpifparams->video_params.hpitch = std_info->width;
  516. vpifparams->video_params.storage_mode = std_info->frm_fmt;
  517. return 0;
  518. }
  519. /**
  520. * vpif_calculate_offsets : This function calculates buffers offsets
  521. * @ch : ptr to channel object
  522. *
  523. * This function calculates buffer offsets for Y and C in the top and
  524. * bottom field
  525. */
  526. static void vpif_calculate_offsets(struct channel_obj *ch)
  527. {
  528. unsigned int hpitch, vpitch, sizeimage;
  529. struct video_obj *vid_ch = &(ch->video);
  530. struct vpif_params *vpifparams = &ch->vpifparams;
  531. struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
  532. enum v4l2_field field = common->fmt.fmt.pix.field;
  533. vpif_dbg(2, debug, "vpif_calculate_offsets\n");
  534. if (V4L2_FIELD_ANY == field) {
  535. if (vpifparams->std_info.frm_fmt)
  536. vid_ch->buf_field = V4L2_FIELD_NONE;
  537. else
  538. vid_ch->buf_field = V4L2_FIELD_INTERLACED;
  539. } else
  540. vid_ch->buf_field = common->fmt.fmt.pix.field;
  541. sizeimage = common->fmt.fmt.pix.sizeimage;
  542. hpitch = common->fmt.fmt.pix.bytesperline;
  543. vpitch = sizeimage / (hpitch * 2);
  544. if ((V4L2_FIELD_NONE == vid_ch->buf_field) ||
  545. (V4L2_FIELD_INTERLACED == vid_ch->buf_field)) {
  546. /* Calculate offsets for Y top, Y Bottom, C top and C Bottom */
  547. common->ytop_off = 0;
  548. common->ybtm_off = hpitch;
  549. common->ctop_off = sizeimage / 2;
  550. common->cbtm_off = sizeimage / 2 + hpitch;
  551. } else if (V4L2_FIELD_SEQ_TB == vid_ch->buf_field) {
  552. /* Calculate offsets for Y top, Y Bottom, C top and C Bottom */
  553. common->ytop_off = 0;
  554. common->ybtm_off = sizeimage / 4;
  555. common->ctop_off = sizeimage / 2;
  556. common->cbtm_off = common->ctop_off + sizeimage / 4;
  557. } else if (V4L2_FIELD_SEQ_BT == vid_ch->buf_field) {
  558. /* Calculate offsets for Y top, Y Bottom, C top and C Bottom */
  559. common->ybtm_off = 0;
  560. common->ytop_off = sizeimage / 4;
  561. common->cbtm_off = sizeimage / 2;
  562. common->ctop_off = common->cbtm_off + sizeimage / 4;
  563. }
  564. if ((V4L2_FIELD_NONE == vid_ch->buf_field) ||
  565. (V4L2_FIELD_INTERLACED == vid_ch->buf_field))
  566. vpifparams->video_params.storage_mode = 1;
  567. else
  568. vpifparams->video_params.storage_mode = 0;
  569. if (1 == vpifparams->std_info.frm_fmt)
  570. vpifparams->video_params.hpitch =
  571. common->fmt.fmt.pix.bytesperline;
  572. else {
  573. if ((field == V4L2_FIELD_ANY)
  574. || (field == V4L2_FIELD_INTERLACED))
  575. vpifparams->video_params.hpitch =
  576. common->fmt.fmt.pix.bytesperline * 2;
  577. else
  578. vpifparams->video_params.hpitch =
  579. common->fmt.fmt.pix.bytesperline;
  580. }
  581. ch->vpifparams.video_params.stdid = vpifparams->std_info.stdid;
  582. }
  583. /**
  584. * vpif_config_format: configure default frame format in the device
  585. * ch : ptr to channel object
  586. */
  587. static void vpif_config_format(struct channel_obj *ch)
  588. {
  589. struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
  590. vpif_dbg(2, debug, "vpif_config_format\n");
  591. common->fmt.fmt.pix.field = V4L2_FIELD_ANY;
  592. if (config_params.numbuffers[ch->channel_id] == 0)
  593. common->memory = V4L2_MEMORY_USERPTR;
  594. else
  595. common->memory = V4L2_MEMORY_MMAP;
  596. common->fmt.fmt.pix.sizeimage
  597. = config_params.channel_bufsize[ch->channel_id];
  598. if (ch->vpifparams.iface.if_type == VPIF_IF_RAW_BAYER)
  599. common->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_SBGGR8;
  600. else
  601. common->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV422P;
  602. common->fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  603. }
  604. /**
  605. * vpif_get_default_field() - Get default field type based on interface
  606. * @vpif_params - ptr to vpif params
  607. */
  608. static inline enum v4l2_field vpif_get_default_field(
  609. struct vpif_interface *iface)
  610. {
  611. return (iface->if_type == VPIF_IF_RAW_BAYER) ? V4L2_FIELD_NONE :
  612. V4L2_FIELD_INTERLACED;
  613. }
  614. /**
  615. * vpif_check_format() - check given pixel format for compatibility
  616. * @ch - channel ptr
  617. * @pixfmt - Given pixel format
  618. * @update - update the values as per hardware requirement
  619. *
  620. * Check the application pixel format for S_FMT and update the input
  621. * values as per hardware limits for TRY_FMT. The default pixel and
  622. * field format is selected based on interface type.
  623. */
  624. static int vpif_check_format(struct channel_obj *ch,
  625. struct v4l2_pix_format *pixfmt,
  626. int update)
  627. {
  628. struct common_obj *common = &(ch->common[VPIF_VIDEO_INDEX]);
  629. struct vpif_params *vpif_params = &ch->vpifparams;
  630. enum v4l2_field field = pixfmt->field;
  631. u32 sizeimage, hpitch, vpitch;
  632. int ret = -EINVAL;
  633. vpif_dbg(2, debug, "vpif_check_format\n");
  634. /**
  635. * first check for the pixel format. If if_type is Raw bayer,
  636. * only V4L2_PIX_FMT_SBGGR8 format is supported. Otherwise only
  637. * V4L2_PIX_FMT_YUV422P is supported
  638. */
  639. if (vpif_params->iface.if_type == VPIF_IF_RAW_BAYER) {
  640. if (pixfmt->pixelformat != V4L2_PIX_FMT_SBGGR8) {
  641. if (!update) {
  642. vpif_dbg(2, debug, "invalid pix format\n");
  643. goto exit;
  644. }
  645. pixfmt->pixelformat = V4L2_PIX_FMT_SBGGR8;
  646. }
  647. } else {
  648. if (pixfmt->pixelformat != V4L2_PIX_FMT_YUV422P) {
  649. if (!update) {
  650. vpif_dbg(2, debug, "invalid pixel format\n");
  651. goto exit;
  652. }
  653. pixfmt->pixelformat = V4L2_PIX_FMT_YUV422P;
  654. }
  655. }
  656. if (!(VPIF_VALID_FIELD(field))) {
  657. if (!update) {
  658. vpif_dbg(2, debug, "invalid field format\n");
  659. goto exit;
  660. }
  661. /**
  662. * By default use FIELD_NONE for RAW Bayer capture
  663. * and FIELD_INTERLACED for other interfaces
  664. */
  665. field = vpif_get_default_field(&vpif_params->iface);
  666. } else if (field == V4L2_FIELD_ANY)
  667. /* unsupported field. Use default */
  668. field = vpif_get_default_field(&vpif_params->iface);
  669. /* validate the hpitch */
  670. hpitch = pixfmt->bytesperline;
  671. if (hpitch < vpif_params->std_info.width) {
  672. if (!update) {
  673. vpif_dbg(2, debug, "invalid hpitch\n");
  674. goto exit;
  675. }
  676. hpitch = vpif_params->std_info.width;
  677. }
  678. sizeimage = pixfmt->sizeimage;
  679. vpitch = sizeimage / (hpitch * 2);
  680. /* validate the vpitch */
  681. if (vpitch < vpif_params->std_info.height) {
  682. if (!update) {
  683. vpif_dbg(2, debug, "Invalid vpitch\n");
  684. goto exit;
  685. }
  686. vpitch = vpif_params->std_info.height;
  687. }
  688. /* Check for 8 byte alignment */
  689. if (!ALIGN(hpitch, 8)) {
  690. if (!update) {
  691. vpif_dbg(2, debug, "invalid pitch alignment\n");
  692. goto exit;
  693. }
  694. /* adjust to next 8 byte boundary */
  695. hpitch = (((hpitch + 7) / 8) * 8);
  696. }
  697. /* if update is set, modify the bytesperline and sizeimage */
  698. if (update) {
  699. pixfmt->bytesperline = hpitch;
  700. pixfmt->sizeimage = hpitch * vpitch * 2;
  701. }
  702. /**
  703. * Image width and height is always based on current standard width and
  704. * height
  705. */
  706. pixfmt->width = common->fmt.fmt.pix.width;
  707. pixfmt->height = common->fmt.fmt.pix.height;
  708. return 0;
  709. exit:
  710. return ret;
  711. }
  712. /**
  713. * vpif_config_addr() - function to configure buffer address in vpif
  714. * @ch - channel ptr
  715. * @muxmode - channel mux mode
  716. */
  717. static void vpif_config_addr(struct channel_obj *ch, int muxmode)
  718. {
  719. struct common_obj *common;
  720. vpif_dbg(2, debug, "vpif_config_addr\n");
  721. common = &(ch->common[VPIF_VIDEO_INDEX]);
  722. if (VPIF_CHANNEL1_VIDEO == ch->channel_id)
  723. common->set_addr = ch1_set_videobuf_addr;
  724. else if (2 == muxmode)
  725. common->set_addr = ch0_set_videobuf_addr_yc_nmux;
  726. else
  727. common->set_addr = ch0_set_videobuf_addr;
  728. }
  729. /**
  730. * vpif_mmap : It is used to map kernel space buffers into user spaces
  731. * @filep: file pointer
  732. * @vma: ptr to vm_area_struct
  733. */
  734. static int vpif_mmap(struct file *filep, struct vm_area_struct *vma)
  735. {
  736. /* Get the channel object and file handle object */
  737. struct vpif_fh *fh = filep->private_data;
  738. struct channel_obj *ch = fh->channel;
  739. struct common_obj *common = &(ch->common[VPIF_VIDEO_INDEX]);
  740. int ret;
  741. vpif_dbg(2, debug, "vpif_mmap\n");
  742. if (mutex_lock_interruptible(&common->lock))
  743. return -ERESTARTSYS;
  744. ret = vb2_mmap(&common->buffer_queue, vma);
  745. mutex_unlock(&common->lock);
  746. return ret;
  747. }
  748. /**
  749. * vpif_poll: It is used for select/poll system call
  750. * @filep: file pointer
  751. * @wait: poll table to wait
  752. */
  753. static unsigned int vpif_poll(struct file *filep, poll_table * wait)
  754. {
  755. struct vpif_fh *fh = filep->private_data;
  756. struct channel_obj *channel = fh->channel;
  757. struct common_obj *common = &(channel->common[VPIF_VIDEO_INDEX]);
  758. unsigned int res = 0;
  759. vpif_dbg(2, debug, "vpif_poll\n");
  760. if (common->started) {
  761. mutex_lock(&common->lock);
  762. res = vb2_poll(&common->buffer_queue, filep, wait);
  763. mutex_unlock(&common->lock);
  764. }
  765. return res;
  766. }
  767. /**
  768. * vpif_open : vpif open handler
  769. * @filep: file ptr
  770. *
  771. * It creates object of file handle structure and stores it in private_data
  772. * member of filepointer
  773. */
  774. static int vpif_open(struct file *filep)
  775. {
  776. struct video_device *vdev = video_devdata(filep);
  777. struct common_obj *common;
  778. struct video_obj *vid_ch;
  779. struct channel_obj *ch;
  780. struct vpif_fh *fh;
  781. vpif_dbg(2, debug, "vpif_open\n");
  782. ch = video_get_drvdata(vdev);
  783. vid_ch = &ch->video;
  784. common = &ch->common[VPIF_VIDEO_INDEX];
  785. /* Allocate memory for the file handle object */
  786. fh = kzalloc(sizeof(struct vpif_fh), GFP_KERNEL);
  787. if (NULL == fh) {
  788. vpif_err("unable to allocate memory for file handle object\n");
  789. return -ENOMEM;
  790. }
  791. if (mutex_lock_interruptible(&common->lock)) {
  792. kfree(fh);
  793. return -ERESTARTSYS;
  794. }
  795. /* store pointer to fh in private_data member of filep */
  796. filep->private_data = fh;
  797. fh->channel = ch;
  798. fh->initialized = 0;
  799. /* If decoder is not initialized. initialize it */
  800. if (!ch->initialized) {
  801. fh->initialized = 1;
  802. ch->initialized = 1;
  803. memset(&(ch->vpifparams), 0, sizeof(struct vpif_params));
  804. }
  805. /* Increment channel usrs counter */
  806. ch->usrs++;
  807. /* Set io_allowed member to false */
  808. fh->io_allowed[VPIF_VIDEO_INDEX] = 0;
  809. /* Initialize priority of this instance to default priority */
  810. fh->prio = V4L2_PRIORITY_UNSET;
  811. v4l2_prio_open(&ch->prio, &fh->prio);
  812. mutex_unlock(&common->lock);
  813. return 0;
  814. }
  815. /**
  816. * vpif_release : function to clean up file close
  817. * @filep: file pointer
  818. *
  819. * This function deletes buffer queue, frees the buffers and the vpif file
  820. * handle
  821. */
  822. static int vpif_release(struct file *filep)
  823. {
  824. struct vpif_fh *fh = filep->private_data;
  825. struct channel_obj *ch = fh->channel;
  826. struct common_obj *common;
  827. vpif_dbg(2, debug, "vpif_release\n");
  828. common = &ch->common[VPIF_VIDEO_INDEX];
  829. mutex_lock(&common->lock);
  830. /* if this instance is doing IO */
  831. if (fh->io_allowed[VPIF_VIDEO_INDEX]) {
  832. /* Reset io_usrs member of channel object */
  833. common->io_usrs = 0;
  834. /* Disable channel as per its device type and channel id */
  835. if (VPIF_CHANNEL0_VIDEO == ch->channel_id) {
  836. enable_channel0(0);
  837. channel0_intr_enable(0);
  838. }
  839. if ((VPIF_CHANNEL1_VIDEO == ch->channel_id) ||
  840. (2 == common->started)) {
  841. enable_channel1(0);
  842. channel1_intr_enable(0);
  843. }
  844. common->started = 0;
  845. /* Free buffers allocated */
  846. vb2_queue_release(&common->buffer_queue);
  847. vb2_dma_contig_cleanup_ctx(common->alloc_ctx);
  848. }
  849. /* Decrement channel usrs counter */
  850. ch->usrs--;
  851. /* Close the priority */
  852. v4l2_prio_close(&ch->prio, fh->prio);
  853. if (fh->initialized)
  854. ch->initialized = 0;
  855. mutex_unlock(&common->lock);
  856. filep->private_data = NULL;
  857. kfree(fh);
  858. return 0;
  859. }
  860. /**
  861. * vpif_reqbufs() - request buffer handler
  862. * @file: file ptr
  863. * @priv: file handle
  864. * @reqbuf: request buffer structure ptr
  865. */
  866. static int vpif_reqbufs(struct file *file, void *priv,
  867. struct v4l2_requestbuffers *reqbuf)
  868. {
  869. struct vpif_fh *fh = priv;
  870. struct channel_obj *ch = fh->channel;
  871. struct common_obj *common;
  872. u8 index = 0;
  873. struct vb2_queue *q;
  874. int ret;
  875. vpif_dbg(2, debug, "vpif_reqbufs\n");
  876. /**
  877. * This file handle has not initialized the channel,
  878. * It is not allowed to do settings
  879. */
  880. if ((VPIF_CHANNEL0_VIDEO == ch->channel_id)
  881. || (VPIF_CHANNEL1_VIDEO == ch->channel_id)) {
  882. if (!fh->initialized) {
  883. vpif_dbg(1, debug, "Channel Busy\n");
  884. return -EBUSY;
  885. }
  886. }
  887. if (V4L2_BUF_TYPE_VIDEO_CAPTURE != reqbuf->type || !vpif_dev)
  888. return -EINVAL;
  889. index = VPIF_VIDEO_INDEX;
  890. common = &ch->common[index];
  891. if (0 != common->io_usrs)
  892. return -EBUSY;
  893. /* Initialize videobuf2 queue as per the buffer type */
  894. common->alloc_ctx = vb2_dma_contig_init_ctx(vpif_dev);
  895. if (IS_ERR(common->alloc_ctx)) {
  896. vpif_err("Failed to get the context\n");
  897. return PTR_ERR(common->alloc_ctx);
  898. }
  899. q = &common->buffer_queue;
  900. q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  901. q->io_modes = VB2_MMAP | VB2_USERPTR;
  902. q->drv_priv = fh;
  903. q->ops = &video_qops;
  904. q->mem_ops = &vb2_dma_contig_memops;
  905. q->buf_struct_size = sizeof(struct vpif_cap_buffer);
  906. q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
  907. ret = vb2_queue_init(q);
  908. if (ret) {
  909. vpif_err("vpif_capture: vb2_queue_init() failed\n");
  910. vb2_dma_contig_cleanup_ctx(common->alloc_ctx);
  911. return ret;
  912. }
  913. /* Set io allowed member of file handle to TRUE */
  914. fh->io_allowed[index] = 1;
  915. /* Increment io usrs member of channel object to 1 */
  916. common->io_usrs = 1;
  917. /* Store type of memory requested in channel object */
  918. common->memory = reqbuf->memory;
  919. INIT_LIST_HEAD(&common->dma_queue);
  920. /* Allocate buffers */
  921. return vb2_reqbufs(&common->buffer_queue, reqbuf);
  922. }
  923. /**
  924. * vpif_querybuf() - query buffer handler
  925. * @file: file ptr
  926. * @priv: file handle
  927. * @buf: v4l2 buffer structure ptr
  928. */
  929. static int vpif_querybuf(struct file *file, void *priv,
  930. struct v4l2_buffer *buf)
  931. {
  932. struct vpif_fh *fh = priv;
  933. struct channel_obj *ch = fh->channel;
  934. struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
  935. vpif_dbg(2, debug, "vpif_querybuf\n");
  936. if (common->fmt.type != buf->type)
  937. return -EINVAL;
  938. if (common->memory != V4L2_MEMORY_MMAP) {
  939. vpif_dbg(1, debug, "Invalid memory\n");
  940. return -EINVAL;
  941. }
  942. return vb2_querybuf(&common->buffer_queue, buf);
  943. }
  944. /**
  945. * vpif_qbuf() - query buffer handler
  946. * @file: file ptr
  947. * @priv: file handle
  948. * @buf: v4l2 buffer structure ptr
  949. */
  950. static int vpif_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
  951. {
  952. struct vpif_fh *fh = priv;
  953. struct channel_obj *ch = fh->channel;
  954. struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
  955. struct v4l2_buffer tbuf = *buf;
  956. vpif_dbg(2, debug, "vpif_qbuf\n");
  957. if (common->fmt.type != tbuf.type) {
  958. vpif_err("invalid buffer type\n");
  959. return -EINVAL;
  960. }
  961. if (!fh->io_allowed[VPIF_VIDEO_INDEX]) {
  962. vpif_err("fh io not allowed\n");
  963. return -EACCES;
  964. }
  965. return vb2_qbuf(&common->buffer_queue, buf);
  966. }
  967. /**
  968. * vpif_dqbuf() - query buffer handler
  969. * @file: file ptr
  970. * @priv: file handle
  971. * @buf: v4l2 buffer structure ptr
  972. */
  973. static int vpif_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
  974. {
  975. struct vpif_fh *fh = priv;
  976. struct channel_obj *ch = fh->channel;
  977. struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
  978. vpif_dbg(2, debug, "vpif_dqbuf\n");
  979. return vb2_dqbuf(&common->buffer_queue, buf,
  980. (file->f_flags & O_NONBLOCK));
  981. }
  982. /**
  983. * vpif_streamon() - streamon handler
  984. * @file: file ptr
  985. * @priv: file handle
  986. * @buftype: v4l2 buffer type
  987. */
  988. static int vpif_streamon(struct file *file, void *priv,
  989. enum v4l2_buf_type buftype)
  990. {
  991. struct vpif_fh *fh = priv;
  992. struct channel_obj *ch = fh->channel;
  993. struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
  994. struct channel_obj *oth_ch = vpif_obj.dev[!ch->channel_id];
  995. struct vpif_params *vpif;
  996. int ret = 0;
  997. vpif_dbg(2, debug, "vpif_streamon\n");
  998. vpif = &ch->vpifparams;
  999. if (buftype != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
  1000. vpif_dbg(1, debug, "buffer type not supported\n");
  1001. return -EINVAL;
  1002. }
  1003. /* If file handle is not allowed IO, return error */
  1004. if (!fh->io_allowed[VPIF_VIDEO_INDEX]) {
  1005. vpif_dbg(1, debug, "io not allowed\n");
  1006. return -EACCES;
  1007. }
  1008. /* If Streaming is already started, return error */
  1009. if (common->started) {
  1010. vpif_dbg(1, debug, "channel->started\n");
  1011. return -EBUSY;
  1012. }
  1013. if ((ch->channel_id == VPIF_CHANNEL0_VIDEO &&
  1014. oth_ch->common[VPIF_VIDEO_INDEX].started &&
  1015. vpif->std_info.ycmux_mode == 0) ||
  1016. ((ch->channel_id == VPIF_CHANNEL1_VIDEO) &&
  1017. (2 == oth_ch->common[VPIF_VIDEO_INDEX].started))) {
  1018. vpif_dbg(1, debug, "other channel is being used\n");
  1019. return -EBUSY;
  1020. }
  1021. ret = vpif_check_format(ch, &common->fmt.fmt.pix, 0);
  1022. if (ret)
  1023. return ret;
  1024. /* Enable streamon on the sub device */
  1025. ret = v4l2_subdev_call(ch->sd, video, s_stream, 1);
  1026. if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV) {
  1027. vpif_dbg(1, debug, "stream on failed in subdev\n");
  1028. return ret;
  1029. }
  1030. /* Call vb2_streamon to start streaming in videobuf2 */
  1031. ret = vb2_streamon(&common->buffer_queue, buftype);
  1032. if (ret) {
  1033. vpif_dbg(1, debug, "vb2_streamon\n");
  1034. return ret;
  1035. }
  1036. return ret;
  1037. }
  1038. /**
  1039. * vpif_streamoff() - streamoff handler
  1040. * @file: file ptr
  1041. * @priv: file handle
  1042. * @buftype: v4l2 buffer type
  1043. */
  1044. static int vpif_streamoff(struct file *file, void *priv,
  1045. enum v4l2_buf_type buftype)
  1046. {
  1047. struct vpif_fh *fh = priv;
  1048. struct channel_obj *ch = fh->channel;
  1049. struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
  1050. int ret;
  1051. vpif_dbg(2, debug, "vpif_streamoff\n");
  1052. if (buftype != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
  1053. vpif_dbg(1, debug, "buffer type not supported\n");
  1054. return -EINVAL;
  1055. }
  1056. /* If io is allowed for this file handle, return error */
  1057. if (!fh->io_allowed[VPIF_VIDEO_INDEX]) {
  1058. vpif_dbg(1, debug, "io not allowed\n");
  1059. return -EACCES;
  1060. }
  1061. /* If streaming is not started, return error */
  1062. if (!common->started) {
  1063. vpif_dbg(1, debug, "channel->started\n");
  1064. return -EINVAL;
  1065. }
  1066. /* disable channel */
  1067. if (VPIF_CHANNEL0_VIDEO == ch->channel_id) {
  1068. enable_channel0(0);
  1069. channel0_intr_enable(0);
  1070. } else {
  1071. enable_channel1(0);
  1072. channel1_intr_enable(0);
  1073. }
  1074. common->started = 0;
  1075. ret = v4l2_subdev_call(ch->sd, video, s_stream, 0);
  1076. if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV)
  1077. vpif_dbg(1, debug, "stream off failed in subdev\n");
  1078. return vb2_streamoff(&common->buffer_queue, buftype);
  1079. }
  1080. /**
  1081. * vpif_input_to_subdev() - Maps input to sub device
  1082. * @vpif_cfg - global config ptr
  1083. * @chan_cfg - channel config ptr
  1084. * @input_index - Given input index from application
  1085. *
  1086. * lookup the sub device information for a given input index.
  1087. * we report all the inputs to application. inputs table also
  1088. * has sub device name for the each input
  1089. */
  1090. static int vpif_input_to_subdev(
  1091. struct vpif_capture_config *vpif_cfg,
  1092. struct vpif_capture_chan_config *chan_cfg,
  1093. int input_index)
  1094. {
  1095. struct vpif_subdev_info *subdev_info;
  1096. const char *subdev_name;
  1097. int i;
  1098. vpif_dbg(2, debug, "vpif_input_to_subdev\n");
  1099. subdev_name = chan_cfg->inputs[input_index].subdev_name;
  1100. if (subdev_name == NULL)
  1101. return -1;
  1102. /* loop through the sub device list to get the sub device info */
  1103. for (i = 0; i < vpif_cfg->subdev_count; i++) {
  1104. subdev_info = &vpif_cfg->subdev_info[i];
  1105. if (!strcmp(subdev_info->name, subdev_name))
  1106. return i;
  1107. }
  1108. return -1;
  1109. }
  1110. /**
  1111. * vpif_set_input() - Select an input
  1112. * @vpif_cfg - global config ptr
  1113. * @ch - channel
  1114. * @_index - Given input index from application
  1115. *
  1116. * Select the given input.
  1117. */
  1118. static int vpif_set_input(
  1119. struct vpif_capture_config *vpif_cfg,
  1120. struct channel_obj *ch,
  1121. int index)
  1122. {
  1123. struct vpif_capture_chan_config *chan_cfg =
  1124. &vpif_cfg->chan_config[ch->channel_id];
  1125. struct vpif_subdev_info *subdev_info = NULL;
  1126. struct v4l2_subdev *sd = NULL;
  1127. u32 input = 0, output = 0;
  1128. int sd_index;
  1129. int ret;
  1130. sd_index = vpif_input_to_subdev(vpif_cfg, chan_cfg, index);
  1131. if (sd_index >= 0) {
  1132. sd = vpif_obj.sd[sd_index];
  1133. subdev_info = &vpif_cfg->subdev_info[sd_index];
  1134. }
  1135. /* first setup input path from sub device to vpif */
  1136. if (sd && vpif_cfg->setup_input_path) {
  1137. ret = vpif_cfg->setup_input_path(ch->channel_id,
  1138. subdev_info->name);
  1139. if (ret < 0) {
  1140. vpif_dbg(1, debug, "couldn't setup input path for the" \
  1141. " sub device %s, for input index %d\n",
  1142. subdev_info->name, index);
  1143. return ret;
  1144. }
  1145. }
  1146. if (sd) {
  1147. input = chan_cfg->inputs[index].input_route;
  1148. output = chan_cfg->inputs[index].output_route;
  1149. ret = v4l2_subdev_call(sd, video, s_routing,
  1150. input, output, 0);
  1151. if (ret < 0 && ret != -ENOIOCTLCMD) {
  1152. vpif_dbg(1, debug, "Failed to set input\n");
  1153. return ret;
  1154. }
  1155. }
  1156. ch->input_idx = index;
  1157. ch->sd = sd;
  1158. /* copy interface parameters to vpif */
  1159. ch->vpifparams.iface = chan_cfg->vpif_if;
  1160. /* update tvnorms from the sub device input info */
  1161. ch->video_dev->tvnorms = chan_cfg->inputs[index].input.std;
  1162. return 0;
  1163. }
  1164. /**
  1165. * vpif_querystd() - querystd handler
  1166. * @file: file ptr
  1167. * @priv: file handle
  1168. * @std_id: ptr to std id
  1169. *
  1170. * This function is called to detect standard at the selected input
  1171. */
  1172. static int vpif_querystd(struct file *file, void *priv, v4l2_std_id *std_id)
  1173. {
  1174. struct vpif_fh *fh = priv;
  1175. struct channel_obj *ch = fh->channel;
  1176. int ret = 0;
  1177. vpif_dbg(2, debug, "vpif_querystd\n");
  1178. /* Call querystd function of decoder device */
  1179. ret = v4l2_subdev_call(ch->sd, video, querystd, std_id);
  1180. if (ret == -ENOIOCTLCMD || ret == -ENODEV)
  1181. return -ENODATA;
  1182. if (ret) {
  1183. vpif_dbg(1, debug, "Failed to query standard for sub devices\n");
  1184. return ret;
  1185. }
  1186. return 0;
  1187. }
  1188. /**
  1189. * vpif_g_std() - get STD handler
  1190. * @file: file ptr
  1191. * @priv: file handle
  1192. * @std_id: ptr to std id
  1193. */
  1194. static int vpif_g_std(struct file *file, void *priv, v4l2_std_id *std)
  1195. {
  1196. struct vpif_fh *fh = priv;
  1197. struct channel_obj *ch = fh->channel;
  1198. vpif_dbg(2, debug, "vpif_g_std\n");
  1199. *std = ch->video.stdid;
  1200. return 0;
  1201. }
  1202. /**
  1203. * vpif_s_std() - set STD handler
  1204. * @file: file ptr
  1205. * @priv: file handle
  1206. * @std_id: ptr to std id
  1207. */
  1208. static int vpif_s_std(struct file *file, void *priv, v4l2_std_id std_id)
  1209. {
  1210. struct vpif_fh *fh = priv;
  1211. struct channel_obj *ch = fh->channel;
  1212. struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
  1213. int ret = 0;
  1214. vpif_dbg(2, debug, "vpif_s_std\n");
  1215. if (common->started) {
  1216. vpif_err("streaming in progress\n");
  1217. return -EBUSY;
  1218. }
  1219. if ((VPIF_CHANNEL0_VIDEO == ch->channel_id) ||
  1220. (VPIF_CHANNEL1_VIDEO == ch->channel_id)) {
  1221. if (!fh->initialized) {
  1222. vpif_dbg(1, debug, "Channel Busy\n");
  1223. return -EBUSY;
  1224. }
  1225. }
  1226. ret = v4l2_prio_check(&ch->prio, fh->prio);
  1227. if (0 != ret)
  1228. return ret;
  1229. fh->initialized = 1;
  1230. /* Call encoder subdevice function to set the standard */
  1231. ch->video.stdid = std_id;
  1232. memset(&ch->video.dv_timings, 0, sizeof(ch->video.dv_timings));
  1233. /* Get the information about the standard */
  1234. if (vpif_update_std_info(ch)) {
  1235. vpif_err("Error getting the standard info\n");
  1236. return -EINVAL;
  1237. }
  1238. /* Configure the default format information */
  1239. vpif_config_format(ch);
  1240. /* set standard in the sub device */
  1241. ret = v4l2_subdev_call(ch->sd, core, s_std, std_id);
  1242. if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV) {
  1243. vpif_dbg(1, debug, "Failed to set standard for sub devices\n");
  1244. return ret;
  1245. }
  1246. return 0;
  1247. }
  1248. /**
  1249. * vpif_enum_input() - ENUMINPUT handler
  1250. * @file: file ptr
  1251. * @priv: file handle
  1252. * @input: ptr to input structure
  1253. */
  1254. static int vpif_enum_input(struct file *file, void *priv,
  1255. struct v4l2_input *input)
  1256. {
  1257. struct vpif_capture_config *config = vpif_dev->platform_data;
  1258. struct vpif_capture_chan_config *chan_cfg;
  1259. struct vpif_fh *fh = priv;
  1260. struct channel_obj *ch = fh->channel;
  1261. chan_cfg = &config->chan_config[ch->channel_id];
  1262. if (input->index >= chan_cfg->input_count) {
  1263. vpif_dbg(1, debug, "Invalid input index\n");
  1264. return -EINVAL;
  1265. }
  1266. memcpy(input, &chan_cfg->inputs[input->index].input,
  1267. sizeof(*input));
  1268. return 0;
  1269. }
  1270. /**
  1271. * vpif_g_input() - Get INPUT handler
  1272. * @file: file ptr
  1273. * @priv: file handle
  1274. * @index: ptr to input index
  1275. */
  1276. static int vpif_g_input(struct file *file, void *priv, unsigned int *index)
  1277. {
  1278. struct vpif_fh *fh = priv;
  1279. struct channel_obj *ch = fh->channel;
  1280. *index = ch->input_idx;
  1281. return 0;
  1282. }
  1283. /**
  1284. * vpif_s_input() - Set INPUT handler
  1285. * @file: file ptr
  1286. * @priv: file handle
  1287. * @index: input index
  1288. */
  1289. static int vpif_s_input(struct file *file, void *priv, unsigned int index)
  1290. {
  1291. struct vpif_capture_config *config = vpif_dev->platform_data;
  1292. struct vpif_capture_chan_config *chan_cfg;
  1293. struct vpif_fh *fh = priv;
  1294. struct channel_obj *ch = fh->channel;
  1295. struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
  1296. int ret;
  1297. chan_cfg = &config->chan_config[ch->channel_id];
  1298. if (index >= chan_cfg->input_count)
  1299. return -EINVAL;
  1300. if (common->started) {
  1301. vpif_err("Streaming in progress\n");
  1302. return -EBUSY;
  1303. }
  1304. if ((VPIF_CHANNEL0_VIDEO == ch->channel_id) ||
  1305. (VPIF_CHANNEL1_VIDEO == ch->channel_id)) {
  1306. if (!fh->initialized) {
  1307. vpif_dbg(1, debug, "Channel Busy\n");
  1308. return -EBUSY;
  1309. }
  1310. }
  1311. ret = v4l2_prio_check(&ch->prio, fh->prio);
  1312. if (0 != ret)
  1313. return ret;
  1314. fh->initialized = 1;
  1315. return vpif_set_input(config, ch, index);
  1316. }
  1317. /**
  1318. * vpif_enum_fmt_vid_cap() - ENUM_FMT handler
  1319. * @file: file ptr
  1320. * @priv: file handle
  1321. * @index: input index
  1322. */
  1323. static int vpif_enum_fmt_vid_cap(struct file *file, void *priv,
  1324. struct v4l2_fmtdesc *fmt)
  1325. {
  1326. struct vpif_fh *fh = priv;
  1327. struct channel_obj *ch = fh->channel;
  1328. if (fmt->index != 0) {
  1329. vpif_dbg(1, debug, "Invalid format index\n");
  1330. return -EINVAL;
  1331. }
  1332. /* Fill in the information about format */
  1333. if (ch->vpifparams.iface.if_type == VPIF_IF_RAW_BAYER) {
  1334. fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  1335. strcpy(fmt->description, "Raw Mode -Bayer Pattern GrRBGb");
  1336. fmt->pixelformat = V4L2_PIX_FMT_SBGGR8;
  1337. } else {
  1338. fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  1339. strcpy(fmt->description, "YCbCr4:2:2 YC Planar");
  1340. fmt->pixelformat = V4L2_PIX_FMT_YUV422P;
  1341. }
  1342. return 0;
  1343. }
  1344. /**
  1345. * vpif_try_fmt_vid_cap() - TRY_FMT handler
  1346. * @file: file ptr
  1347. * @priv: file handle
  1348. * @fmt: ptr to v4l2 format structure
  1349. */
  1350. static int vpif_try_fmt_vid_cap(struct file *file, void *priv,
  1351. struct v4l2_format *fmt)
  1352. {
  1353. struct vpif_fh *fh = priv;
  1354. struct channel_obj *ch = fh->channel;
  1355. struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
  1356. return vpif_check_format(ch, pixfmt, 1);
  1357. }
  1358. /**
  1359. * vpif_g_fmt_vid_cap() - Set INPUT handler
  1360. * @file: file ptr
  1361. * @priv: file handle
  1362. * @fmt: ptr to v4l2 format structure
  1363. */
  1364. static int vpif_g_fmt_vid_cap(struct file *file, void *priv,
  1365. struct v4l2_format *fmt)
  1366. {
  1367. struct vpif_fh *fh = priv;
  1368. struct channel_obj *ch = fh->channel;
  1369. struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
  1370. /* Check the validity of the buffer type */
  1371. if (common->fmt.type != fmt->type)
  1372. return -EINVAL;
  1373. /* Fill in the information about format */
  1374. *fmt = common->fmt;
  1375. return 0;
  1376. }
  1377. /**
  1378. * vpif_s_fmt_vid_cap() - Set FMT handler
  1379. * @file: file ptr
  1380. * @priv: file handle
  1381. * @fmt: ptr to v4l2 format structure
  1382. */
  1383. static int vpif_s_fmt_vid_cap(struct file *file, void *priv,
  1384. struct v4l2_format *fmt)
  1385. {
  1386. struct vpif_fh *fh = priv;
  1387. struct channel_obj *ch = fh->channel;
  1388. struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
  1389. struct v4l2_pix_format *pixfmt;
  1390. int ret = 0;
  1391. vpif_dbg(2, debug, "%s\n", __func__);
  1392. /* If streaming is started, return error */
  1393. if (common->started) {
  1394. vpif_dbg(1, debug, "Streaming is started\n");
  1395. return -EBUSY;
  1396. }
  1397. if ((VPIF_CHANNEL0_VIDEO == ch->channel_id) ||
  1398. (VPIF_CHANNEL1_VIDEO == ch->channel_id)) {
  1399. if (!fh->initialized) {
  1400. vpif_dbg(1, debug, "Channel Busy\n");
  1401. return -EBUSY;
  1402. }
  1403. }
  1404. ret = v4l2_prio_check(&ch->prio, fh->prio);
  1405. if (0 != ret)
  1406. return ret;
  1407. fh->initialized = 1;
  1408. pixfmt = &fmt->fmt.pix;
  1409. /* Check for valid field format */
  1410. ret = vpif_check_format(ch, pixfmt, 0);
  1411. if (ret)
  1412. return ret;
  1413. /* store the format in the channel object */
  1414. common->fmt = *fmt;
  1415. return 0;
  1416. }
  1417. /**
  1418. * vpif_querycap() - QUERYCAP handler
  1419. * @file: file ptr
  1420. * @priv: file handle
  1421. * @cap: ptr to v4l2_capability structure
  1422. */
  1423. static int vpif_querycap(struct file *file, void *priv,
  1424. struct v4l2_capability *cap)
  1425. {
  1426. struct vpif_capture_config *config = vpif_dev->platform_data;
  1427. cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
  1428. cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
  1429. snprintf(cap->driver, sizeof(cap->driver), "%s", dev_name(vpif_dev));
  1430. snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
  1431. dev_name(vpif_dev));
  1432. strlcpy(cap->card, config->card_name, sizeof(cap->card));
  1433. return 0;
  1434. }
  1435. /**
  1436. * vpif_g_priority() - get priority handler
  1437. * @file: file ptr
  1438. * @priv: file handle
  1439. * @prio: ptr to v4l2_priority structure
  1440. */
  1441. static int vpif_g_priority(struct file *file, void *priv,
  1442. enum v4l2_priority *prio)
  1443. {
  1444. struct vpif_fh *fh = priv;
  1445. struct channel_obj *ch = fh->channel;
  1446. *prio = v4l2_prio_max(&ch->prio);
  1447. return 0;
  1448. }
  1449. /**
  1450. * vpif_s_priority() - set priority handler
  1451. * @file: file ptr
  1452. * @priv: file handle
  1453. * @prio: ptr to v4l2_priority structure
  1454. */
  1455. static int vpif_s_priority(struct file *file, void *priv, enum v4l2_priority p)
  1456. {
  1457. struct vpif_fh *fh = priv;
  1458. struct channel_obj *ch = fh->channel;
  1459. return v4l2_prio_change(&ch->prio, &fh->prio, p);
  1460. }
  1461. /**
  1462. * vpif_cropcap() - cropcap handler
  1463. * @file: file ptr
  1464. * @priv: file handle
  1465. * @crop: ptr to v4l2_cropcap structure
  1466. */
  1467. static int vpif_cropcap(struct file *file, void *priv,
  1468. struct v4l2_cropcap *crop)
  1469. {
  1470. struct vpif_fh *fh = priv;
  1471. struct channel_obj *ch = fh->channel;
  1472. struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
  1473. if (V4L2_BUF_TYPE_VIDEO_CAPTURE != crop->type)
  1474. return -EINVAL;
  1475. crop->bounds.left = 0;
  1476. crop->bounds.top = 0;
  1477. crop->bounds.height = common->height;
  1478. crop->bounds.width = common->width;
  1479. crop->defrect = crop->bounds;
  1480. return 0;
  1481. }
  1482. /**
  1483. * vpif_enum_dv_timings() - ENUM_DV_TIMINGS handler
  1484. * @file: file ptr
  1485. * @priv: file handle
  1486. * @timings: input timings
  1487. */
  1488. static int
  1489. vpif_enum_dv_timings(struct file *file, void *priv,
  1490. struct v4l2_enum_dv_timings *timings)
  1491. {
  1492. struct vpif_fh *fh = priv;
  1493. struct channel_obj *ch = fh->channel;
  1494. int ret;
  1495. ret = v4l2_subdev_call(ch->sd, video, enum_dv_timings, timings);
  1496. if (ret == -ENOIOCTLCMD || ret == -ENODEV)
  1497. return -EINVAL;
  1498. return ret;
  1499. }
  1500. /**
  1501. * vpif_query_dv_timings() - QUERY_DV_TIMINGS handler
  1502. * @file: file ptr
  1503. * @priv: file handle
  1504. * @timings: input timings
  1505. */
  1506. static int
  1507. vpif_query_dv_timings(struct file *file, void *priv,
  1508. struct v4l2_dv_timings *timings)
  1509. {
  1510. struct vpif_fh *fh = priv;
  1511. struct channel_obj *ch = fh->channel;
  1512. int ret;
  1513. ret = v4l2_subdev_call(ch->sd, video, query_dv_timings, timings);
  1514. if (ret == -ENOIOCTLCMD || ret == -ENODEV)
  1515. return -ENODATA;
  1516. return ret;
  1517. }
  1518. /**
  1519. * vpif_s_dv_timings() - S_DV_TIMINGS handler
  1520. * @file: file ptr
  1521. * @priv: file handle
  1522. * @timings: digital video timings
  1523. */
  1524. static int vpif_s_dv_timings(struct file *file, void *priv,
  1525. struct v4l2_dv_timings *timings)
  1526. {
  1527. struct vpif_fh *fh = priv;
  1528. struct channel_obj *ch = fh->channel;
  1529. struct vpif_params *vpifparams = &ch->vpifparams;
  1530. struct vpif_channel_config_params *std_info = &vpifparams->std_info;
  1531. struct video_obj *vid_ch = &ch->video;
  1532. struct v4l2_bt_timings *bt = &vid_ch->dv_timings.bt;
  1533. int ret;
  1534. if (timings->type != V4L2_DV_BT_656_1120) {
  1535. vpif_dbg(2, debug, "Timing type not defined\n");
  1536. return -EINVAL;
  1537. }
  1538. /* Configure subdevice timings, if any */
  1539. ret = v4l2_subdev_call(ch->sd, video, s_dv_timings, timings);
  1540. if (ret == -ENOIOCTLCMD || ret == -ENODEV)
  1541. ret = 0;
  1542. if (ret < 0) {
  1543. vpif_dbg(2, debug, "Error setting custom DV timings\n");
  1544. return ret;
  1545. }
  1546. if (!(timings->bt.width && timings->bt.height &&
  1547. (timings->bt.hbackporch ||
  1548. timings->bt.hfrontporch ||
  1549. timings->bt.hsync) &&
  1550. timings->bt.vfrontporch &&
  1551. (timings->bt.vbackporch ||
  1552. timings->bt.vsync))) {
  1553. vpif_dbg(2, debug, "Timings for width, height, "
  1554. "horizontal back porch, horizontal sync, "
  1555. "horizontal front porch, vertical back porch, "
  1556. "vertical sync and vertical back porch "
  1557. "must be defined\n");
  1558. return -EINVAL;
  1559. }
  1560. vid_ch->dv_timings = *timings;
  1561. /* Configure video port timings */
  1562. std_info->eav2sav = bt->hbackporch + bt->hfrontporch +
  1563. bt->hsync - 8;
  1564. std_info->sav2eav = bt->width;
  1565. std_info->l1 = 1;
  1566. std_info->l3 = bt->vsync + bt->vbackporch + 1;
  1567. if (bt->interlaced) {
  1568. if (bt->il_vbackporch || bt->il_vfrontporch || bt->il_vsync) {
  1569. std_info->vsize = bt->height * 2 +
  1570. bt->vfrontporch + bt->vsync + bt->vbackporch +
  1571. bt->il_vfrontporch + bt->il_vsync +
  1572. bt->il_vbackporch;
  1573. std_info->l5 = std_info->vsize/2 -
  1574. (bt->vfrontporch - 1);
  1575. std_info->l7 = std_info->vsize/2 + 1;
  1576. std_info->l9 = std_info->l7 + bt->il_vsync +
  1577. bt->il_vbackporch + 1;
  1578. std_info->l11 = std_info->vsize -
  1579. (bt->il_vfrontporch - 1);
  1580. } else {
  1581. vpif_dbg(2, debug, "Required timing values for "
  1582. "interlaced BT format missing\n");
  1583. return -EINVAL;
  1584. }
  1585. } else {
  1586. std_info->vsize = bt->height + bt->vfrontporch +
  1587. bt->vsync + bt->vbackporch;
  1588. std_info->l5 = std_info->vsize - (bt->vfrontporch - 1);
  1589. }
  1590. strncpy(std_info->name, "Custom timings BT656/1120", VPIF_MAX_NAME);
  1591. std_info->width = bt->width;
  1592. std_info->height = bt->height;
  1593. std_info->frm_fmt = bt->interlaced ? 0 : 1;
  1594. std_info->ycmux_mode = 0;
  1595. std_info->capture_format = 0;
  1596. std_info->vbi_supported = 0;
  1597. std_info->hd_sd = 1;
  1598. std_info->stdid = 0;
  1599. vid_ch->stdid = 0;
  1600. return 0;
  1601. }
  1602. /**
  1603. * vpif_g_dv_timings() - G_DV_TIMINGS handler
  1604. * @file: file ptr
  1605. * @priv: file handle
  1606. * @timings: digital video timings
  1607. */
  1608. static int vpif_g_dv_timings(struct file *file, void *priv,
  1609. struct v4l2_dv_timings *timings)
  1610. {
  1611. struct vpif_fh *fh = priv;
  1612. struct channel_obj *ch = fh->channel;
  1613. struct video_obj *vid_ch = &ch->video;
  1614. *timings = vid_ch->dv_timings;
  1615. return 0;
  1616. }
  1617. /*
  1618. * vpif_g_chip_ident() - Identify the chip
  1619. * @file: file ptr
  1620. * @priv: file handle
  1621. * @chip: chip identity
  1622. *
  1623. * Returns zero or -EINVAL if read operations fails.
  1624. */
  1625. static int vpif_g_chip_ident(struct file *file, void *priv,
  1626. struct v4l2_dbg_chip_ident *chip)
  1627. {
  1628. chip->ident = V4L2_IDENT_NONE;
  1629. chip->revision = 0;
  1630. if (chip->match.type != V4L2_CHIP_MATCH_I2C_DRIVER &&
  1631. chip->match.type != V4L2_CHIP_MATCH_I2C_ADDR) {
  1632. vpif_dbg(2, debug, "match_type is invalid.\n");
  1633. return -EINVAL;
  1634. }
  1635. return v4l2_device_call_until_err(&vpif_obj.v4l2_dev, 0, core,
  1636. g_chip_ident, chip);
  1637. }
  1638. #ifdef CONFIG_VIDEO_ADV_DEBUG
  1639. /*
  1640. * vpif_dbg_g_register() - Read register
  1641. * @file: file ptr
  1642. * @priv: file handle
  1643. * @reg: register to be read
  1644. *
  1645. * Debugging only
  1646. * Returns zero or -EINVAL if read operations fails.
  1647. */
  1648. static int vpif_dbg_g_register(struct file *file, void *priv,
  1649. struct v4l2_dbg_register *reg){
  1650. struct vpif_fh *fh = priv;
  1651. struct channel_obj *ch = fh->channel;
  1652. return v4l2_subdev_call(ch->sd, core, g_register, reg);
  1653. }
  1654. /*
  1655. * vpif_dbg_s_register() - Write to register
  1656. * @file: file ptr
  1657. * @priv: file handle
  1658. * @reg: register to be modified
  1659. *
  1660. * Debugging only
  1661. * Returns zero or -EINVAL if write operations fails.
  1662. */
  1663. static int vpif_dbg_s_register(struct file *file, void *priv,
  1664. const struct v4l2_dbg_register *reg)
  1665. {
  1666. struct vpif_fh *fh = priv;
  1667. struct channel_obj *ch = fh->channel;
  1668. return v4l2_subdev_call(ch->sd, core, s_register, reg);
  1669. }
  1670. #endif
  1671. /*
  1672. * vpif_log_status() - Status information
  1673. * @file: file ptr
  1674. * @priv: file handle
  1675. *
  1676. * Returns zero.
  1677. */
  1678. static int vpif_log_status(struct file *filep, void *priv)
  1679. {
  1680. /* status for sub devices */
  1681. v4l2_device_call_all(&vpif_obj.v4l2_dev, 0, core, log_status);
  1682. return 0;
  1683. }
  1684. /* vpif capture ioctl operations */
  1685. static const struct v4l2_ioctl_ops vpif_ioctl_ops = {
  1686. .vidioc_querycap = vpif_querycap,
  1687. .vidioc_g_priority = vpif_g_priority,
  1688. .vidioc_s_priority = vpif_s_priority,
  1689. .vidioc_enum_fmt_vid_cap = vpif_enum_fmt_vid_cap,
  1690. .vidioc_g_fmt_vid_cap = vpif_g_fmt_vid_cap,
  1691. .vidioc_s_fmt_vid_cap = vpif_s_fmt_vid_cap,
  1692. .vidioc_try_fmt_vid_cap = vpif_try_fmt_vid_cap,
  1693. .vidioc_enum_input = vpif_enum_input,
  1694. .vidioc_s_input = vpif_s_input,
  1695. .vidioc_g_input = vpif_g_input,
  1696. .vidioc_reqbufs = vpif_reqbufs,
  1697. .vidioc_querybuf = vpif_querybuf,
  1698. .vidioc_querystd = vpif_querystd,
  1699. .vidioc_s_std = vpif_s_std,
  1700. .vidioc_g_std = vpif_g_std,
  1701. .vidioc_qbuf = vpif_qbuf,
  1702. .vidioc_dqbuf = vpif_dqbuf,
  1703. .vidioc_streamon = vpif_streamon,
  1704. .vidioc_streamoff = vpif_streamoff,
  1705. .vidioc_cropcap = vpif_cropcap,
  1706. .vidioc_enum_dv_timings = vpif_enum_dv_timings,
  1707. .vidioc_query_dv_timings = vpif_query_dv_timings,
  1708. .vidioc_s_dv_timings = vpif_s_dv_timings,
  1709. .vidioc_g_dv_timings = vpif_g_dv_timings,
  1710. .vidioc_g_chip_ident = vpif_g_chip_ident,
  1711. #ifdef CONFIG_VIDEO_ADV_DEBUG
  1712. .vidioc_g_register = vpif_dbg_g_register,
  1713. .vidioc_s_register = vpif_dbg_s_register,
  1714. #endif
  1715. .vidioc_log_status = vpif_log_status,
  1716. };
  1717. /* vpif file operations */
  1718. static struct v4l2_file_operations vpif_fops = {
  1719. .owner = THIS_MODULE,
  1720. .open = vpif_open,
  1721. .release = vpif_release,
  1722. .unlocked_ioctl = video_ioctl2,
  1723. .mmap = vpif_mmap,
  1724. .poll = vpif_poll
  1725. };
  1726. /* vpif video template */
  1727. static struct video_device vpif_video_template = {
  1728. .name = "vpif",
  1729. .fops = &vpif_fops,
  1730. .minor = -1,
  1731. .ioctl_ops = &vpif_ioctl_ops,
  1732. };
  1733. /**
  1734. * initialize_vpif() - Initialize vpif data structures
  1735. *
  1736. * Allocate memory for data structures and initialize them
  1737. */
  1738. static int initialize_vpif(void)
  1739. {
  1740. int err = 0, i, j;
  1741. int free_channel_objects_index;
  1742. /* Default number of buffers should be 3 */
  1743. if ((ch0_numbuffers > 0) &&
  1744. (ch0_numbuffers < config_params.min_numbuffers))
  1745. ch0_numbuffers = config_params.min_numbuffers;
  1746. if ((ch1_numbuffers > 0) &&
  1747. (ch1_numbuffers < config_params.min_numbuffers))
  1748. ch1_numbuffers = config_params.min_numbuffers;
  1749. /* Set buffer size to min buffers size if it is invalid */
  1750. if (ch0_bufsize < config_params.min_bufsize[VPIF_CHANNEL0_VIDEO])
  1751. ch0_bufsize =
  1752. config_params.min_bufsize[VPIF_CHANNEL0_VIDEO];
  1753. if (ch1_bufsize < config_params.min_bufsize[VPIF_CHANNEL1_VIDEO])
  1754. ch1_bufsize =
  1755. config_params.min_bufsize[VPIF_CHANNEL1_VIDEO];
  1756. config_params.numbuffers[VPIF_CHANNEL0_VIDEO] = ch0_numbuffers;
  1757. config_params.numbuffers[VPIF_CHANNEL1_VIDEO] = ch1_numbuffers;
  1758. if (ch0_numbuffers) {
  1759. config_params.channel_bufsize[VPIF_CHANNEL0_VIDEO]
  1760. = ch0_bufsize;
  1761. }
  1762. if (ch1_numbuffers) {
  1763. config_params.channel_bufsize[VPIF_CHANNEL1_VIDEO]
  1764. = ch1_bufsize;
  1765. }
  1766. /* Allocate memory for six channel objects */
  1767. for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
  1768. vpif_obj.dev[i] =
  1769. kzalloc(sizeof(*vpif_obj.dev[i]), GFP_KERNEL);
  1770. /* If memory allocation fails, return error */
  1771. if (!vpif_obj.dev[i]) {
  1772. free_channel_objects_index = i;
  1773. err = -ENOMEM;
  1774. goto vpif_init_free_channel_objects;
  1775. }
  1776. }
  1777. return 0;
  1778. vpif_init_free_channel_objects:
  1779. for (j = 0; j < free_channel_objects_index; j++)
  1780. kfree(vpif_obj.dev[j]);
  1781. return err;
  1782. }
  1783. /**
  1784. * vpif_probe : This function probes the vpif capture driver
  1785. * @pdev: platform device pointer
  1786. *
  1787. * This creates device entries by register itself to the V4L2 driver and
  1788. * initializes fields of each channel objects
  1789. */
  1790. static __init int vpif_probe(struct platform_device *pdev)
  1791. {
  1792. struct vpif_subdev_info *subdevdata;
  1793. struct vpif_capture_config *config;
  1794. int i, j, k, err;
  1795. int res_idx = 0;
  1796. struct i2c_adapter *i2c_adap;
  1797. struct channel_obj *ch;
  1798. struct common_obj *common;
  1799. struct video_device *vfd;
  1800. struct resource *res;
  1801. int subdev_count;
  1802. size_t size;
  1803. vpif_dev = &pdev->dev;
  1804. err = initialize_vpif();
  1805. if (err) {
  1806. v4l2_err(vpif_dev->driver, "Error initializing vpif\n");
  1807. return err;
  1808. }
  1809. err = v4l2_device_register(vpif_dev, &vpif_obj.v4l2_dev);
  1810. if (err) {
  1811. v4l2_err(vpif_dev->driver, "Error registering v4l2 device\n");
  1812. return err;
  1813. }
  1814. while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) {
  1815. for (i = res->start; i <= res->end; i++) {
  1816. if (request_irq(i, vpif_channel_isr, IRQF_SHARED,
  1817. "VPIF_Capture", (void *)
  1818. (&vpif_obj.dev[res_idx]->channel_id))) {
  1819. err = -EBUSY;
  1820. for (j = 0; j < i; j++)
  1821. free_irq(j, (void *)
  1822. (&vpif_obj.dev[res_idx]->channel_id));
  1823. goto vpif_int_err;
  1824. }
  1825. }
  1826. res_idx++;
  1827. }
  1828. for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
  1829. /* Get the pointer to the channel object */
  1830. ch = vpif_obj.dev[i];
  1831. /* Allocate memory for video device */
  1832. vfd = video_device_alloc();
  1833. if (NULL == vfd) {
  1834. for (j = 0; j < i; j++) {
  1835. ch = vpif_obj.dev[j];
  1836. video_device_release(ch->video_dev);
  1837. }
  1838. err = -ENOMEM;
  1839. goto vpif_int_err;
  1840. }
  1841. /* Initialize field of video device */
  1842. *vfd = vpif_video_template;
  1843. vfd->v4l2_dev = &vpif_obj.v4l2_dev;
  1844. vfd->release = video_device_release;
  1845. snprintf(vfd->name, sizeof(vfd->name),
  1846. "VPIF_Capture_DRIVER_V%s",
  1847. VPIF_CAPTURE_VERSION);
  1848. /* Set video_dev to the video device */
  1849. ch->video_dev = vfd;
  1850. }
  1851. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1852. if (res) {
  1853. size = resource_size(res);
  1854. /* The resources are divided into two equal memory and when we
  1855. * have HD output we can add them together
  1856. */
  1857. for (j = 0; j < VPIF_CAPTURE_MAX_DEVICES; j++) {
  1858. ch = vpif_obj.dev[j];
  1859. ch->channel_id = j;
  1860. /* only enabled if second resource exists */
  1861. config_params.video_limit[ch->channel_id] = 0;
  1862. if (size)
  1863. config_params.video_limit[ch->channel_id] =
  1864. size/2;
  1865. }
  1866. }
  1867. i2c_adap = i2c_get_adapter(1);
  1868. config = pdev->dev.platform_data;
  1869. subdev_count = config->subdev_count;
  1870. vpif_obj.sd = kzalloc(sizeof(struct v4l2_subdev *) * subdev_count,
  1871. GFP_KERNEL);
  1872. if (vpif_obj.sd == NULL) {
  1873. vpif_err("unable to allocate memory for subdevice pointers\n");
  1874. err = -ENOMEM;
  1875. goto vpif_sd_error;
  1876. }
  1877. for (i = 0; i < subdev_count; i++) {
  1878. subdevdata = &config->subdev_info[i];
  1879. vpif_obj.sd[i] =
  1880. v4l2_i2c_new_subdev_board(&vpif_obj.v4l2_dev,
  1881. i2c_adap,
  1882. &subdevdata->board_info,
  1883. NULL);
  1884. if (!vpif_obj.sd[i]) {
  1885. vpif_err("Error registering v4l2 subdevice\n");
  1886. goto probe_subdev_out;
  1887. }
  1888. v4l2_info(&vpif_obj.v4l2_dev, "registered sub device %s\n",
  1889. subdevdata->name);
  1890. }
  1891. for (j = 0; j < VPIF_CAPTURE_MAX_DEVICES; j++) {
  1892. ch = vpif_obj.dev[j];
  1893. ch->channel_id = j;
  1894. common = &(ch->common[VPIF_VIDEO_INDEX]);
  1895. spin_lock_init(&common->irqlock);
  1896. mutex_init(&common->lock);
  1897. ch->video_dev->lock = &common->lock;
  1898. /* Initialize prio member of channel object */
  1899. v4l2_prio_init(&ch->prio);
  1900. video_set_drvdata(ch->video_dev, ch);
  1901. /* select input 0 */
  1902. err = vpif_set_input(config, ch, 0);
  1903. if (err)
  1904. goto probe_out;
  1905. err = video_register_device(ch->video_dev,
  1906. VFL_TYPE_GRABBER, (j ? 1 : 0));
  1907. if (err)
  1908. goto probe_out;
  1909. }
  1910. v4l2_info(&vpif_obj.v4l2_dev, "VPIF capture driver initialized\n");
  1911. return 0;
  1912. probe_out:
  1913. for (k = 0; k < j; k++) {
  1914. /* Get the pointer to the channel object */
  1915. ch = vpif_obj.dev[k];
  1916. /* Unregister video device */
  1917. video_unregister_device(ch->video_dev);
  1918. }
  1919. probe_subdev_out:
  1920. /* free sub devices memory */
  1921. kfree(vpif_obj.sd);
  1922. vpif_sd_error:
  1923. for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
  1924. ch = vpif_obj.dev[i];
  1925. /* Note: does nothing if ch->video_dev == NULL */
  1926. video_device_release(ch->video_dev);
  1927. }
  1928. vpif_int_err:
  1929. v4l2_device_unregister(&vpif_obj.v4l2_dev);
  1930. for (i = 0; i < res_idx; i++) {
  1931. res = platform_get_resource(pdev, IORESOURCE_IRQ, i);
  1932. for (j = res->start; j <= res->end; j++)
  1933. free_irq(j, (void *)(&vpif_obj.dev[i]->channel_id));
  1934. }
  1935. return err;
  1936. }
  1937. /**
  1938. * vpif_remove() - driver remove handler
  1939. * @device: ptr to platform device structure
  1940. *
  1941. * The vidoe device is unregistered
  1942. */
  1943. static int vpif_remove(struct platform_device *device)
  1944. {
  1945. int i;
  1946. struct channel_obj *ch;
  1947. v4l2_device_unregister(&vpif_obj.v4l2_dev);
  1948. /* un-register device */
  1949. for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
  1950. /* Get the pointer to the channel object */
  1951. ch = vpif_obj.dev[i];
  1952. /* Unregister video device */
  1953. video_unregister_device(ch->video_dev);
  1954. }
  1955. return 0;
  1956. }
  1957. #ifdef CONFIG_PM
  1958. /**
  1959. * vpif_suspend: vpif device suspend
  1960. */
  1961. static int vpif_suspend(struct device *dev)
  1962. {
  1963. struct common_obj *common;
  1964. struct channel_obj *ch;
  1965. int i;
  1966. for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
  1967. /* Get the pointer to the channel object */
  1968. ch = vpif_obj.dev[i];
  1969. common = &ch->common[VPIF_VIDEO_INDEX];
  1970. mutex_lock(&common->lock);
  1971. if (ch->usrs && common->io_usrs) {
  1972. /* Disable channel */
  1973. if (ch->channel_id == VPIF_CHANNEL0_VIDEO) {
  1974. enable_channel0(0);
  1975. channel0_intr_enable(0);
  1976. }
  1977. if (ch->channel_id == VPIF_CHANNEL1_VIDEO ||
  1978. common->started == 2) {
  1979. enable_channel1(0);
  1980. channel1_intr_enable(0);
  1981. }
  1982. }
  1983. mutex_unlock(&common->lock);
  1984. }
  1985. return 0;
  1986. }
  1987. /*
  1988. * vpif_resume: vpif device suspend
  1989. */
  1990. static int vpif_resume(struct device *dev)
  1991. {
  1992. struct common_obj *common;
  1993. struct channel_obj *ch;
  1994. int i;
  1995. for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
  1996. /* Get the pointer to the channel object */
  1997. ch = vpif_obj.dev[i];
  1998. common = &ch->common[VPIF_VIDEO_INDEX];
  1999. mutex_lock(&common->lock);
  2000. if (ch->usrs && common->io_usrs) {
  2001. /* Disable channel */
  2002. if (ch->channel_id == VPIF_CHANNEL0_VIDEO) {
  2003. enable_channel0(1);
  2004. channel0_intr_enable(1);
  2005. }
  2006. if (ch->channel_id == VPIF_CHANNEL1_VIDEO ||
  2007. common->started == 2) {
  2008. enable_channel1(1);
  2009. channel1_intr_enable(1);
  2010. }
  2011. }
  2012. mutex_unlock(&common->lock);
  2013. }
  2014. return 0;
  2015. }
  2016. static const struct dev_pm_ops vpif_dev_pm_ops = {
  2017. .suspend = vpif_suspend,
  2018. .resume = vpif_resume,
  2019. };
  2020. #define vpif_pm_ops (&vpif_dev_pm_ops)
  2021. #else
  2022. #define vpif_pm_ops NULL
  2023. #endif
  2024. static __refdata struct platform_driver vpif_driver = {
  2025. .driver = {
  2026. .name = "vpif_capture",
  2027. .owner = THIS_MODULE,
  2028. .pm = vpif_pm_ops,
  2029. },
  2030. .probe = vpif_probe,
  2031. .remove = vpif_remove,
  2032. };
  2033. /**
  2034. * vpif_init: initialize the vpif driver
  2035. *
  2036. * This function registers device and driver to the kernel, requests irq
  2037. * handler and allocates memory
  2038. * for channel objects
  2039. */
  2040. static __init int vpif_init(void)
  2041. {
  2042. return platform_driver_register(&vpif_driver);
  2043. }
  2044. /**
  2045. * vpif_cleanup : This function clean up the vpif capture resources
  2046. *
  2047. * This will un-registers device and driver to the kernel, frees
  2048. * requested irq handler and de-allocates memory allocated for channel
  2049. * objects.
  2050. */
  2051. static void vpif_cleanup(void)
  2052. {
  2053. struct platform_device *pdev;
  2054. struct resource *res;
  2055. int irq_num;
  2056. int i = 0;
  2057. pdev = container_of(vpif_dev, struct platform_device, dev);
  2058. while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, i))) {
  2059. for (irq_num = res->start; irq_num <= res->end; irq_num++)
  2060. free_irq(irq_num,
  2061. (void *)(&vpif_obj.dev[i]->channel_id));
  2062. i++;
  2063. }
  2064. platform_driver_unregister(&vpif_driver);
  2065. kfree(vpif_obj.sd);
  2066. for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++)
  2067. kfree(vpif_obj.dev[i]);
  2068. }
  2069. /* Function for module initialization and cleanup */
  2070. module_init(vpif_init);
  2071. module_exit(vpif_cleanup);