bfin_capture.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178
  1. /*
  2. * Analog Devices video capture driver
  3. *
  4. * Copyright (c) 2011 Analog Devices Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  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., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19. #include <linux/completion.h>
  20. #include <linux/delay.h>
  21. #include <linux/errno.h>
  22. #include <linux/fs.h>
  23. #include <linux/i2c.h>
  24. #include <linux/init.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/io.h>
  27. #include <linux/mm.h>
  28. #include <linux/module.h>
  29. #include <linux/platform_device.h>
  30. #include <linux/slab.h>
  31. #include <linux/time.h>
  32. #include <linux/types.h>
  33. #include <media/v4l2-chip-ident.h>
  34. #include <media/v4l2-common.h>
  35. #include <media/v4l2-ctrls.h>
  36. #include <media/v4l2-device.h>
  37. #include <media/v4l2-ioctl.h>
  38. #include <media/videobuf2-dma-contig.h>
  39. #include <asm/dma.h>
  40. #include <media/blackfin/bfin_capture.h>
  41. #include <media/blackfin/ppi.h>
  42. #define CAPTURE_DRV_NAME "bfin_capture"
  43. #define BCAP_MIN_NUM_BUF 2
  44. struct bcap_format {
  45. char *desc;
  46. u32 pixelformat;
  47. enum v4l2_mbus_pixelcode mbus_code;
  48. int bpp; /* bits per pixel */
  49. int dlen; /* data length for ppi in bits */
  50. };
  51. struct bcap_buffer {
  52. struct vb2_buffer vb;
  53. struct list_head list;
  54. };
  55. struct bcap_device {
  56. /* capture device instance */
  57. struct v4l2_device v4l2_dev;
  58. /* v4l2 control handler */
  59. struct v4l2_ctrl_handler ctrl_handler;
  60. /* device node data */
  61. struct video_device *video_dev;
  62. /* sub device instance */
  63. struct v4l2_subdev *sd;
  64. /* capture config */
  65. struct bfin_capture_config *cfg;
  66. /* ppi interface */
  67. struct ppi_if *ppi;
  68. /* current input */
  69. unsigned int cur_input;
  70. /* current selected standard */
  71. v4l2_std_id std;
  72. /* current selected dv_timings */
  73. struct v4l2_dv_timings dv_timings;
  74. /* used to store pixel format */
  75. struct v4l2_pix_format fmt;
  76. /* bits per pixel*/
  77. int bpp;
  78. /* data length for ppi in bits */
  79. int dlen;
  80. /* used to store sensor supported format */
  81. struct bcap_format *sensor_formats;
  82. /* number of sensor formats array */
  83. int num_sensor_formats;
  84. /* pointing to current video buffer */
  85. struct bcap_buffer *cur_frm;
  86. /* buffer queue used in videobuf2 */
  87. struct vb2_queue buffer_queue;
  88. /* allocator-specific contexts for each plane */
  89. struct vb2_alloc_ctx *alloc_ctx;
  90. /* queue of filled frames */
  91. struct list_head dma_queue;
  92. /* used in videobuf2 callback */
  93. spinlock_t lock;
  94. /* used to access capture device */
  95. struct mutex mutex;
  96. /* used to wait ppi to complete one transfer */
  97. struct completion comp;
  98. /* prepare to stop */
  99. bool stop;
  100. };
  101. struct bcap_fh {
  102. struct v4l2_fh fh;
  103. /* indicates whether this file handle is doing IO */
  104. bool io_allowed;
  105. };
  106. static const struct bcap_format bcap_formats[] = {
  107. {
  108. .desc = "YCbCr 4:2:2 Interleaved UYVY",
  109. .pixelformat = V4L2_PIX_FMT_UYVY,
  110. .mbus_code = V4L2_MBUS_FMT_UYVY8_2X8,
  111. .bpp = 16,
  112. .dlen = 8,
  113. },
  114. {
  115. .desc = "YCbCr 4:2:2 Interleaved YUYV",
  116. .pixelformat = V4L2_PIX_FMT_YUYV,
  117. .mbus_code = V4L2_MBUS_FMT_YUYV8_2X8,
  118. .bpp = 16,
  119. .dlen = 8,
  120. },
  121. {
  122. .desc = "YCbCr 4:2:2 Interleaved UYVY",
  123. .pixelformat = V4L2_PIX_FMT_UYVY,
  124. .mbus_code = V4L2_MBUS_FMT_UYVY8_1X16,
  125. .bpp = 16,
  126. .dlen = 16,
  127. },
  128. {
  129. .desc = "RGB 565",
  130. .pixelformat = V4L2_PIX_FMT_RGB565,
  131. .mbus_code = V4L2_MBUS_FMT_RGB565_2X8_LE,
  132. .bpp = 16,
  133. .dlen = 8,
  134. },
  135. {
  136. .desc = "RGB 444",
  137. .pixelformat = V4L2_PIX_FMT_RGB444,
  138. .mbus_code = V4L2_MBUS_FMT_RGB444_2X8_PADHI_LE,
  139. .bpp = 16,
  140. .dlen = 8,
  141. },
  142. };
  143. #define BCAP_MAX_FMTS ARRAY_SIZE(bcap_formats)
  144. static irqreturn_t bcap_isr(int irq, void *dev_id);
  145. static struct bcap_buffer *to_bcap_vb(struct vb2_buffer *vb)
  146. {
  147. return container_of(vb, struct bcap_buffer, vb);
  148. }
  149. static int bcap_init_sensor_formats(struct bcap_device *bcap_dev)
  150. {
  151. enum v4l2_mbus_pixelcode code;
  152. struct bcap_format *sf;
  153. unsigned int num_formats = 0;
  154. int i, j;
  155. while (!v4l2_subdev_call(bcap_dev->sd, video,
  156. enum_mbus_fmt, num_formats, &code))
  157. num_formats++;
  158. if (!num_formats)
  159. return -ENXIO;
  160. sf = kzalloc(num_formats * sizeof(*sf), GFP_KERNEL);
  161. if (!sf)
  162. return -ENOMEM;
  163. for (i = 0; i < num_formats; i++) {
  164. v4l2_subdev_call(bcap_dev->sd, video,
  165. enum_mbus_fmt, i, &code);
  166. for (j = 0; j < BCAP_MAX_FMTS; j++)
  167. if (code == bcap_formats[j].mbus_code)
  168. break;
  169. if (j == BCAP_MAX_FMTS) {
  170. /* we don't allow this sensor working with our bridge */
  171. kfree(sf);
  172. return -EINVAL;
  173. }
  174. sf[i] = bcap_formats[j];
  175. }
  176. bcap_dev->sensor_formats = sf;
  177. bcap_dev->num_sensor_formats = num_formats;
  178. return 0;
  179. }
  180. static void bcap_free_sensor_formats(struct bcap_device *bcap_dev)
  181. {
  182. bcap_dev->num_sensor_formats = 0;
  183. kfree(bcap_dev->sensor_formats);
  184. bcap_dev->sensor_formats = NULL;
  185. }
  186. static int bcap_open(struct file *file)
  187. {
  188. struct bcap_device *bcap_dev = video_drvdata(file);
  189. struct video_device *vfd = bcap_dev->video_dev;
  190. struct bcap_fh *bcap_fh;
  191. if (!bcap_dev->sd) {
  192. v4l2_err(&bcap_dev->v4l2_dev, "No sub device registered\n");
  193. return -ENODEV;
  194. }
  195. bcap_fh = kzalloc(sizeof(*bcap_fh), GFP_KERNEL);
  196. if (!bcap_fh) {
  197. v4l2_err(&bcap_dev->v4l2_dev,
  198. "unable to allocate memory for file handle object\n");
  199. return -ENOMEM;
  200. }
  201. v4l2_fh_init(&bcap_fh->fh, vfd);
  202. /* store pointer to v4l2_fh in private_data member of file */
  203. file->private_data = &bcap_fh->fh;
  204. v4l2_fh_add(&bcap_fh->fh);
  205. bcap_fh->io_allowed = false;
  206. return 0;
  207. }
  208. static int bcap_release(struct file *file)
  209. {
  210. struct bcap_device *bcap_dev = video_drvdata(file);
  211. struct v4l2_fh *fh = file->private_data;
  212. struct bcap_fh *bcap_fh = container_of(fh, struct bcap_fh, fh);
  213. /* if this instance is doing IO */
  214. if (bcap_fh->io_allowed)
  215. vb2_queue_release(&bcap_dev->buffer_queue);
  216. file->private_data = NULL;
  217. v4l2_fh_del(&bcap_fh->fh);
  218. v4l2_fh_exit(&bcap_fh->fh);
  219. kfree(bcap_fh);
  220. return 0;
  221. }
  222. static int bcap_mmap(struct file *file, struct vm_area_struct *vma)
  223. {
  224. struct bcap_device *bcap_dev = video_drvdata(file);
  225. int ret;
  226. if (mutex_lock_interruptible(&bcap_dev->mutex))
  227. return -ERESTARTSYS;
  228. ret = vb2_mmap(&bcap_dev->buffer_queue, vma);
  229. mutex_unlock(&bcap_dev->mutex);
  230. return ret;
  231. }
  232. #ifndef CONFIG_MMU
  233. static unsigned long bcap_get_unmapped_area(struct file *file,
  234. unsigned long addr,
  235. unsigned long len,
  236. unsigned long pgoff,
  237. unsigned long flags)
  238. {
  239. struct bcap_device *bcap_dev = video_drvdata(file);
  240. return vb2_get_unmapped_area(&bcap_dev->buffer_queue,
  241. addr,
  242. len,
  243. pgoff,
  244. flags);
  245. }
  246. #endif
  247. static unsigned int bcap_poll(struct file *file, poll_table *wait)
  248. {
  249. struct bcap_device *bcap_dev = video_drvdata(file);
  250. unsigned int res;
  251. mutex_lock(&bcap_dev->mutex);
  252. res = vb2_poll(&bcap_dev->buffer_queue, file, wait);
  253. mutex_unlock(&bcap_dev->mutex);
  254. return res;
  255. }
  256. static int bcap_queue_setup(struct vb2_queue *vq,
  257. const struct v4l2_format *fmt,
  258. unsigned int *nbuffers, unsigned int *nplanes,
  259. unsigned int sizes[], void *alloc_ctxs[])
  260. {
  261. struct bcap_device *bcap_dev = vb2_get_drv_priv(vq);
  262. if (*nbuffers < BCAP_MIN_NUM_BUF)
  263. *nbuffers = BCAP_MIN_NUM_BUF;
  264. *nplanes = 1;
  265. sizes[0] = bcap_dev->fmt.sizeimage;
  266. alloc_ctxs[0] = bcap_dev->alloc_ctx;
  267. return 0;
  268. }
  269. static int bcap_buffer_init(struct vb2_buffer *vb)
  270. {
  271. struct bcap_buffer *buf = to_bcap_vb(vb);
  272. INIT_LIST_HEAD(&buf->list);
  273. return 0;
  274. }
  275. static int bcap_buffer_prepare(struct vb2_buffer *vb)
  276. {
  277. struct bcap_device *bcap_dev = vb2_get_drv_priv(vb->vb2_queue);
  278. struct bcap_buffer *buf = to_bcap_vb(vb);
  279. unsigned long size;
  280. size = bcap_dev->fmt.sizeimage;
  281. if (vb2_plane_size(vb, 0) < size) {
  282. v4l2_err(&bcap_dev->v4l2_dev, "buffer too small (%lu < %lu)\n",
  283. vb2_plane_size(vb, 0), size);
  284. return -EINVAL;
  285. }
  286. vb2_set_plane_payload(&buf->vb, 0, size);
  287. return 0;
  288. }
  289. static void bcap_buffer_queue(struct vb2_buffer *vb)
  290. {
  291. struct bcap_device *bcap_dev = vb2_get_drv_priv(vb->vb2_queue);
  292. struct bcap_buffer *buf = to_bcap_vb(vb);
  293. unsigned long flags;
  294. spin_lock_irqsave(&bcap_dev->lock, flags);
  295. list_add_tail(&buf->list, &bcap_dev->dma_queue);
  296. spin_unlock_irqrestore(&bcap_dev->lock, flags);
  297. }
  298. static void bcap_buffer_cleanup(struct vb2_buffer *vb)
  299. {
  300. struct bcap_device *bcap_dev = vb2_get_drv_priv(vb->vb2_queue);
  301. struct bcap_buffer *buf = to_bcap_vb(vb);
  302. unsigned long flags;
  303. spin_lock_irqsave(&bcap_dev->lock, flags);
  304. list_del_init(&buf->list);
  305. spin_unlock_irqrestore(&bcap_dev->lock, flags);
  306. }
  307. static void bcap_lock(struct vb2_queue *vq)
  308. {
  309. struct bcap_device *bcap_dev = vb2_get_drv_priv(vq);
  310. mutex_lock(&bcap_dev->mutex);
  311. }
  312. static void bcap_unlock(struct vb2_queue *vq)
  313. {
  314. struct bcap_device *bcap_dev = vb2_get_drv_priv(vq);
  315. mutex_unlock(&bcap_dev->mutex);
  316. }
  317. static int bcap_start_streaming(struct vb2_queue *vq, unsigned int count)
  318. {
  319. struct bcap_device *bcap_dev = vb2_get_drv_priv(vq);
  320. struct ppi_if *ppi = bcap_dev->ppi;
  321. struct ppi_params params;
  322. int ret;
  323. /* enable streamon on the sub device */
  324. ret = v4l2_subdev_call(bcap_dev->sd, video, s_stream, 1);
  325. if (ret && (ret != -ENOIOCTLCMD)) {
  326. v4l2_err(&bcap_dev->v4l2_dev, "stream on failed in subdev\n");
  327. return ret;
  328. }
  329. /* set ppi params */
  330. params.width = bcap_dev->fmt.width;
  331. params.height = bcap_dev->fmt.height;
  332. params.bpp = bcap_dev->bpp;
  333. params.dlen = bcap_dev->dlen;
  334. params.ppi_control = bcap_dev->cfg->ppi_control;
  335. params.int_mask = bcap_dev->cfg->int_mask;
  336. if (bcap_dev->cfg->inputs[bcap_dev->cur_input].capabilities
  337. & V4L2_IN_CAP_CUSTOM_TIMINGS) {
  338. struct v4l2_bt_timings *bt = &bcap_dev->dv_timings.bt;
  339. params.hdelay = bt->hsync + bt->hbackporch;
  340. params.vdelay = bt->vsync + bt->vbackporch;
  341. params.line = bt->hfrontporch + bt->hsync
  342. + bt->hbackporch + bt->width;
  343. params.frame = bt->vfrontporch + bt->vsync
  344. + bt->vbackporch + bt->height;
  345. if (bt->interlaced)
  346. params.frame += bt->il_vfrontporch + bt->il_vsync
  347. + bt->il_vbackporch;
  348. } else if (bcap_dev->cfg->inputs[bcap_dev->cur_input].capabilities
  349. & V4L2_IN_CAP_STD) {
  350. params.hdelay = 0;
  351. params.vdelay = 0;
  352. if (bcap_dev->std & V4L2_STD_525_60) {
  353. params.line = 858;
  354. params.frame = 525;
  355. } else {
  356. params.line = 864;
  357. params.frame = 625;
  358. }
  359. } else {
  360. params.hdelay = 0;
  361. params.vdelay = 0;
  362. params.line = params.width + bcap_dev->cfg->blank_pixels;
  363. params.frame = params.height;
  364. }
  365. ret = ppi->ops->set_params(ppi, &params);
  366. if (ret < 0) {
  367. v4l2_err(&bcap_dev->v4l2_dev,
  368. "Error in setting ppi params\n");
  369. return ret;
  370. }
  371. /* attach ppi DMA irq handler */
  372. ret = ppi->ops->attach_irq(ppi, bcap_isr);
  373. if (ret < 0) {
  374. v4l2_err(&bcap_dev->v4l2_dev,
  375. "Error in attaching interrupt handler\n");
  376. return ret;
  377. }
  378. INIT_COMPLETION(bcap_dev->comp);
  379. bcap_dev->stop = false;
  380. return 0;
  381. }
  382. static int bcap_stop_streaming(struct vb2_queue *vq)
  383. {
  384. struct bcap_device *bcap_dev = vb2_get_drv_priv(vq);
  385. struct ppi_if *ppi = bcap_dev->ppi;
  386. int ret;
  387. if (!vb2_is_streaming(vq))
  388. return 0;
  389. bcap_dev->stop = true;
  390. wait_for_completion(&bcap_dev->comp);
  391. ppi->ops->stop(ppi);
  392. ppi->ops->detach_irq(ppi);
  393. ret = v4l2_subdev_call(bcap_dev->sd, video, s_stream, 0);
  394. if (ret && (ret != -ENOIOCTLCMD))
  395. v4l2_err(&bcap_dev->v4l2_dev,
  396. "stream off failed in subdev\n");
  397. /* release all active buffers */
  398. while (!list_empty(&bcap_dev->dma_queue)) {
  399. bcap_dev->cur_frm = list_entry(bcap_dev->dma_queue.next,
  400. struct bcap_buffer, list);
  401. list_del(&bcap_dev->cur_frm->list);
  402. vb2_buffer_done(&bcap_dev->cur_frm->vb, VB2_BUF_STATE_ERROR);
  403. }
  404. return 0;
  405. }
  406. static struct vb2_ops bcap_video_qops = {
  407. .queue_setup = bcap_queue_setup,
  408. .buf_init = bcap_buffer_init,
  409. .buf_prepare = bcap_buffer_prepare,
  410. .buf_cleanup = bcap_buffer_cleanup,
  411. .buf_queue = bcap_buffer_queue,
  412. .wait_prepare = bcap_unlock,
  413. .wait_finish = bcap_lock,
  414. .start_streaming = bcap_start_streaming,
  415. .stop_streaming = bcap_stop_streaming,
  416. };
  417. static int bcap_reqbufs(struct file *file, void *priv,
  418. struct v4l2_requestbuffers *req_buf)
  419. {
  420. struct bcap_device *bcap_dev = video_drvdata(file);
  421. struct vb2_queue *vq = &bcap_dev->buffer_queue;
  422. struct v4l2_fh *fh = file->private_data;
  423. struct bcap_fh *bcap_fh = container_of(fh, struct bcap_fh, fh);
  424. if (vb2_is_busy(vq))
  425. return -EBUSY;
  426. bcap_fh->io_allowed = true;
  427. return vb2_reqbufs(vq, req_buf);
  428. }
  429. static int bcap_querybuf(struct file *file, void *priv,
  430. struct v4l2_buffer *buf)
  431. {
  432. struct bcap_device *bcap_dev = video_drvdata(file);
  433. return vb2_querybuf(&bcap_dev->buffer_queue, buf);
  434. }
  435. static int bcap_qbuf(struct file *file, void *priv,
  436. struct v4l2_buffer *buf)
  437. {
  438. struct bcap_device *bcap_dev = video_drvdata(file);
  439. struct v4l2_fh *fh = file->private_data;
  440. struct bcap_fh *bcap_fh = container_of(fh, struct bcap_fh, fh);
  441. if (!bcap_fh->io_allowed)
  442. return -EBUSY;
  443. return vb2_qbuf(&bcap_dev->buffer_queue, buf);
  444. }
  445. static int bcap_dqbuf(struct file *file, void *priv,
  446. struct v4l2_buffer *buf)
  447. {
  448. struct bcap_device *bcap_dev = video_drvdata(file);
  449. struct v4l2_fh *fh = file->private_data;
  450. struct bcap_fh *bcap_fh = container_of(fh, struct bcap_fh, fh);
  451. if (!bcap_fh->io_allowed)
  452. return -EBUSY;
  453. return vb2_dqbuf(&bcap_dev->buffer_queue,
  454. buf, file->f_flags & O_NONBLOCK);
  455. }
  456. static irqreturn_t bcap_isr(int irq, void *dev_id)
  457. {
  458. struct ppi_if *ppi = dev_id;
  459. struct bcap_device *bcap_dev = ppi->priv;
  460. struct vb2_buffer *vb = &bcap_dev->cur_frm->vb;
  461. dma_addr_t addr;
  462. spin_lock(&bcap_dev->lock);
  463. if (!list_empty(&bcap_dev->dma_queue)) {
  464. v4l2_get_timestamp(&vb->v4l2_buf.timestamp);
  465. if (ppi->err) {
  466. vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
  467. ppi->err = false;
  468. } else {
  469. vb2_buffer_done(vb, VB2_BUF_STATE_DONE);
  470. }
  471. bcap_dev->cur_frm = list_entry(bcap_dev->dma_queue.next,
  472. struct bcap_buffer, list);
  473. list_del(&bcap_dev->cur_frm->list);
  474. } else {
  475. /* clear error flag, we will get a new frame */
  476. if (ppi->err)
  477. ppi->err = false;
  478. }
  479. ppi->ops->stop(ppi);
  480. if (bcap_dev->stop) {
  481. complete(&bcap_dev->comp);
  482. } else {
  483. addr = vb2_dma_contig_plane_dma_addr(&bcap_dev->cur_frm->vb, 0);
  484. ppi->ops->update_addr(ppi, (unsigned long)addr);
  485. ppi->ops->start(ppi);
  486. }
  487. spin_unlock(&bcap_dev->lock);
  488. return IRQ_HANDLED;
  489. }
  490. static int bcap_streamon(struct file *file, void *priv,
  491. enum v4l2_buf_type buf_type)
  492. {
  493. struct bcap_device *bcap_dev = video_drvdata(file);
  494. struct bcap_fh *fh = file->private_data;
  495. struct ppi_if *ppi = bcap_dev->ppi;
  496. dma_addr_t addr;
  497. int ret;
  498. if (!fh->io_allowed)
  499. return -EBUSY;
  500. /* call streamon to start streaming in videobuf */
  501. ret = vb2_streamon(&bcap_dev->buffer_queue, buf_type);
  502. if (ret)
  503. return ret;
  504. /* if dma queue is empty, return error */
  505. if (list_empty(&bcap_dev->dma_queue)) {
  506. v4l2_err(&bcap_dev->v4l2_dev, "dma queue is empty\n");
  507. ret = -EINVAL;
  508. goto err;
  509. }
  510. /* get the next frame from the dma queue */
  511. bcap_dev->cur_frm = list_entry(bcap_dev->dma_queue.next,
  512. struct bcap_buffer, list);
  513. /* remove buffer from the dma queue */
  514. list_del(&bcap_dev->cur_frm->list);
  515. addr = vb2_dma_contig_plane_dma_addr(&bcap_dev->cur_frm->vb, 0);
  516. /* update DMA address */
  517. ppi->ops->update_addr(ppi, (unsigned long)addr);
  518. /* enable ppi */
  519. ppi->ops->start(ppi);
  520. return 0;
  521. err:
  522. vb2_streamoff(&bcap_dev->buffer_queue, buf_type);
  523. return ret;
  524. }
  525. static int bcap_streamoff(struct file *file, void *priv,
  526. enum v4l2_buf_type buf_type)
  527. {
  528. struct bcap_device *bcap_dev = video_drvdata(file);
  529. struct bcap_fh *fh = file->private_data;
  530. if (!fh->io_allowed)
  531. return -EBUSY;
  532. return vb2_streamoff(&bcap_dev->buffer_queue, buf_type);
  533. }
  534. static int bcap_querystd(struct file *file, void *priv, v4l2_std_id *std)
  535. {
  536. struct bcap_device *bcap_dev = video_drvdata(file);
  537. return v4l2_subdev_call(bcap_dev->sd, video, querystd, std);
  538. }
  539. static int bcap_g_std(struct file *file, void *priv, v4l2_std_id *std)
  540. {
  541. struct bcap_device *bcap_dev = video_drvdata(file);
  542. *std = bcap_dev->std;
  543. return 0;
  544. }
  545. static int bcap_s_std(struct file *file, void *priv, v4l2_std_id *std)
  546. {
  547. struct bcap_device *bcap_dev = video_drvdata(file);
  548. int ret;
  549. if (vb2_is_busy(&bcap_dev->buffer_queue))
  550. return -EBUSY;
  551. ret = v4l2_subdev_call(bcap_dev->sd, core, s_std, *std);
  552. if (ret < 0)
  553. return ret;
  554. bcap_dev->std = *std;
  555. return 0;
  556. }
  557. static int bcap_g_dv_timings(struct file *file, void *priv,
  558. struct v4l2_dv_timings *timings)
  559. {
  560. struct bcap_device *bcap_dev = video_drvdata(file);
  561. int ret;
  562. ret = v4l2_subdev_call(bcap_dev->sd, video,
  563. g_dv_timings, timings);
  564. if (ret < 0)
  565. return ret;
  566. bcap_dev->dv_timings = *timings;
  567. return 0;
  568. }
  569. static int bcap_s_dv_timings(struct file *file, void *priv,
  570. struct v4l2_dv_timings *timings)
  571. {
  572. struct bcap_device *bcap_dev = video_drvdata(file);
  573. int ret;
  574. if (vb2_is_busy(&bcap_dev->buffer_queue))
  575. return -EBUSY;
  576. ret = v4l2_subdev_call(bcap_dev->sd, video, s_dv_timings, timings);
  577. if (ret < 0)
  578. return ret;
  579. bcap_dev->dv_timings = *timings;
  580. return 0;
  581. }
  582. static int bcap_enum_input(struct file *file, void *priv,
  583. struct v4l2_input *input)
  584. {
  585. struct bcap_device *bcap_dev = video_drvdata(file);
  586. struct bfin_capture_config *config = bcap_dev->cfg;
  587. int ret;
  588. u32 status;
  589. if (input->index >= config->num_inputs)
  590. return -EINVAL;
  591. *input = config->inputs[input->index];
  592. /* get input status */
  593. ret = v4l2_subdev_call(bcap_dev->sd, video, g_input_status, &status);
  594. if (!ret)
  595. input->status = status;
  596. return 0;
  597. }
  598. static int bcap_g_input(struct file *file, void *priv, unsigned int *index)
  599. {
  600. struct bcap_device *bcap_dev = video_drvdata(file);
  601. *index = bcap_dev->cur_input;
  602. return 0;
  603. }
  604. static int bcap_s_input(struct file *file, void *priv, unsigned int index)
  605. {
  606. struct bcap_device *bcap_dev = video_drvdata(file);
  607. struct bfin_capture_config *config = bcap_dev->cfg;
  608. struct bcap_route *route;
  609. int ret;
  610. if (vb2_is_busy(&bcap_dev->buffer_queue))
  611. return -EBUSY;
  612. if (index >= config->num_inputs)
  613. return -EINVAL;
  614. route = &config->routes[index];
  615. ret = v4l2_subdev_call(bcap_dev->sd, video, s_routing,
  616. route->input, route->output, 0);
  617. if ((ret < 0) && (ret != -ENOIOCTLCMD)) {
  618. v4l2_err(&bcap_dev->v4l2_dev, "Failed to set input\n");
  619. return ret;
  620. }
  621. bcap_dev->cur_input = index;
  622. /* if this route has specific config, update ppi control */
  623. if (route->ppi_control)
  624. config->ppi_control = route->ppi_control;
  625. return 0;
  626. }
  627. static int bcap_try_format(struct bcap_device *bcap,
  628. struct v4l2_pix_format *pixfmt,
  629. struct bcap_format *bcap_fmt)
  630. {
  631. struct bcap_format *sf = bcap->sensor_formats;
  632. struct bcap_format *fmt = NULL;
  633. struct v4l2_mbus_framefmt mbus_fmt;
  634. int ret, i;
  635. for (i = 0; i < bcap->num_sensor_formats; i++) {
  636. fmt = &sf[i];
  637. if (pixfmt->pixelformat == fmt->pixelformat)
  638. break;
  639. }
  640. if (i == bcap->num_sensor_formats)
  641. fmt = &sf[0];
  642. v4l2_fill_mbus_format(&mbus_fmt, pixfmt, fmt->mbus_code);
  643. ret = v4l2_subdev_call(bcap->sd, video,
  644. try_mbus_fmt, &mbus_fmt);
  645. if (ret < 0)
  646. return ret;
  647. v4l2_fill_pix_format(pixfmt, &mbus_fmt);
  648. if (bcap_fmt) {
  649. for (i = 0; i < bcap->num_sensor_formats; i++) {
  650. fmt = &sf[i];
  651. if (mbus_fmt.code == fmt->mbus_code)
  652. break;
  653. }
  654. *bcap_fmt = *fmt;
  655. }
  656. pixfmt->bytesperline = pixfmt->width * fmt->bpp / 8;
  657. pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height;
  658. return 0;
  659. }
  660. static int bcap_enum_fmt_vid_cap(struct file *file, void *priv,
  661. struct v4l2_fmtdesc *fmt)
  662. {
  663. struct bcap_device *bcap_dev = video_drvdata(file);
  664. struct bcap_format *sf = bcap_dev->sensor_formats;
  665. if (fmt->index >= bcap_dev->num_sensor_formats)
  666. return -EINVAL;
  667. fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  668. strlcpy(fmt->description,
  669. sf[fmt->index].desc,
  670. sizeof(fmt->description));
  671. fmt->pixelformat = sf[fmt->index].pixelformat;
  672. return 0;
  673. }
  674. static int bcap_try_fmt_vid_cap(struct file *file, void *priv,
  675. struct v4l2_format *fmt)
  676. {
  677. struct bcap_device *bcap_dev = video_drvdata(file);
  678. struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
  679. return bcap_try_format(bcap_dev, pixfmt, NULL);
  680. }
  681. static int bcap_g_fmt_vid_cap(struct file *file, void *priv,
  682. struct v4l2_format *fmt)
  683. {
  684. struct bcap_device *bcap_dev = video_drvdata(file);
  685. fmt->fmt.pix = bcap_dev->fmt;
  686. return 0;
  687. }
  688. static int bcap_s_fmt_vid_cap(struct file *file, void *priv,
  689. struct v4l2_format *fmt)
  690. {
  691. struct bcap_device *bcap_dev = video_drvdata(file);
  692. struct v4l2_mbus_framefmt mbus_fmt;
  693. struct bcap_format bcap_fmt;
  694. struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
  695. int ret;
  696. if (vb2_is_busy(&bcap_dev->buffer_queue))
  697. return -EBUSY;
  698. /* see if format works */
  699. ret = bcap_try_format(bcap_dev, pixfmt, &bcap_fmt);
  700. if (ret < 0)
  701. return ret;
  702. v4l2_fill_mbus_format(&mbus_fmt, pixfmt, bcap_fmt.mbus_code);
  703. ret = v4l2_subdev_call(bcap_dev->sd, video, s_mbus_fmt, &mbus_fmt);
  704. if (ret < 0)
  705. return ret;
  706. bcap_dev->fmt = *pixfmt;
  707. bcap_dev->bpp = bcap_fmt.bpp;
  708. bcap_dev->dlen = bcap_fmt.dlen;
  709. return 0;
  710. }
  711. static int bcap_querycap(struct file *file, void *priv,
  712. struct v4l2_capability *cap)
  713. {
  714. struct bcap_device *bcap_dev = video_drvdata(file);
  715. cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
  716. strlcpy(cap->driver, CAPTURE_DRV_NAME, sizeof(cap->driver));
  717. strlcpy(cap->bus_info, "Blackfin Platform", sizeof(cap->bus_info));
  718. strlcpy(cap->card, bcap_dev->cfg->card_name, sizeof(cap->card));
  719. return 0;
  720. }
  721. static int bcap_g_parm(struct file *file, void *fh,
  722. struct v4l2_streamparm *a)
  723. {
  724. struct bcap_device *bcap_dev = video_drvdata(file);
  725. if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  726. return -EINVAL;
  727. return v4l2_subdev_call(bcap_dev->sd, video, g_parm, a);
  728. }
  729. static int bcap_s_parm(struct file *file, void *fh,
  730. struct v4l2_streamparm *a)
  731. {
  732. struct bcap_device *bcap_dev = video_drvdata(file);
  733. if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  734. return -EINVAL;
  735. return v4l2_subdev_call(bcap_dev->sd, video, s_parm, a);
  736. }
  737. static int bcap_g_chip_ident(struct file *file, void *priv,
  738. struct v4l2_dbg_chip_ident *chip)
  739. {
  740. struct bcap_device *bcap_dev = video_drvdata(file);
  741. chip->ident = V4L2_IDENT_NONE;
  742. chip->revision = 0;
  743. if (chip->match.type != V4L2_CHIP_MATCH_I2C_DRIVER &&
  744. chip->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
  745. return -EINVAL;
  746. return v4l2_subdev_call(bcap_dev->sd, core,
  747. g_chip_ident, chip);
  748. }
  749. #ifdef CONFIG_VIDEO_ADV_DEBUG
  750. static int bcap_dbg_g_register(struct file *file, void *priv,
  751. struct v4l2_dbg_register *reg)
  752. {
  753. struct bcap_device *bcap_dev = video_drvdata(file);
  754. return v4l2_subdev_call(bcap_dev->sd, core,
  755. g_register, reg);
  756. }
  757. static int bcap_dbg_s_register(struct file *file, void *priv,
  758. struct v4l2_dbg_register *reg)
  759. {
  760. struct bcap_device *bcap_dev = video_drvdata(file);
  761. return v4l2_subdev_call(bcap_dev->sd, core,
  762. s_register, reg);
  763. }
  764. #endif
  765. static int bcap_log_status(struct file *file, void *priv)
  766. {
  767. struct bcap_device *bcap_dev = video_drvdata(file);
  768. /* status for sub devices */
  769. v4l2_device_call_all(&bcap_dev->v4l2_dev, 0, core, log_status);
  770. return 0;
  771. }
  772. static const struct v4l2_ioctl_ops bcap_ioctl_ops = {
  773. .vidioc_querycap = bcap_querycap,
  774. .vidioc_g_fmt_vid_cap = bcap_g_fmt_vid_cap,
  775. .vidioc_enum_fmt_vid_cap = bcap_enum_fmt_vid_cap,
  776. .vidioc_s_fmt_vid_cap = bcap_s_fmt_vid_cap,
  777. .vidioc_try_fmt_vid_cap = bcap_try_fmt_vid_cap,
  778. .vidioc_enum_input = bcap_enum_input,
  779. .vidioc_g_input = bcap_g_input,
  780. .vidioc_s_input = bcap_s_input,
  781. .vidioc_querystd = bcap_querystd,
  782. .vidioc_s_std = bcap_s_std,
  783. .vidioc_g_std = bcap_g_std,
  784. .vidioc_s_dv_timings = bcap_s_dv_timings,
  785. .vidioc_g_dv_timings = bcap_g_dv_timings,
  786. .vidioc_reqbufs = bcap_reqbufs,
  787. .vidioc_querybuf = bcap_querybuf,
  788. .vidioc_qbuf = bcap_qbuf,
  789. .vidioc_dqbuf = bcap_dqbuf,
  790. .vidioc_streamon = bcap_streamon,
  791. .vidioc_streamoff = bcap_streamoff,
  792. .vidioc_g_parm = bcap_g_parm,
  793. .vidioc_s_parm = bcap_s_parm,
  794. .vidioc_g_chip_ident = bcap_g_chip_ident,
  795. #ifdef CONFIG_VIDEO_ADV_DEBUG
  796. .vidioc_g_register = bcap_dbg_g_register,
  797. .vidioc_s_register = bcap_dbg_s_register,
  798. #endif
  799. .vidioc_log_status = bcap_log_status,
  800. };
  801. static struct v4l2_file_operations bcap_fops = {
  802. .owner = THIS_MODULE,
  803. .open = bcap_open,
  804. .release = bcap_release,
  805. .unlocked_ioctl = video_ioctl2,
  806. .mmap = bcap_mmap,
  807. #ifndef CONFIG_MMU
  808. .get_unmapped_area = bcap_get_unmapped_area,
  809. #endif
  810. .poll = bcap_poll
  811. };
  812. static int bcap_probe(struct platform_device *pdev)
  813. {
  814. struct bcap_device *bcap_dev;
  815. struct video_device *vfd;
  816. struct i2c_adapter *i2c_adap;
  817. struct bfin_capture_config *config;
  818. struct vb2_queue *q;
  819. struct bcap_route *route;
  820. int ret;
  821. config = pdev->dev.platform_data;
  822. if (!config) {
  823. v4l2_err(pdev->dev.driver, "Unable to get board config\n");
  824. return -ENODEV;
  825. }
  826. bcap_dev = kzalloc(sizeof(*bcap_dev), GFP_KERNEL);
  827. if (!bcap_dev) {
  828. v4l2_err(pdev->dev.driver, "Unable to alloc bcap_dev\n");
  829. return -ENOMEM;
  830. }
  831. bcap_dev->cfg = config;
  832. bcap_dev->ppi = ppi_create_instance(config->ppi_info);
  833. if (!bcap_dev->ppi) {
  834. v4l2_err(pdev->dev.driver, "Unable to create ppi\n");
  835. ret = -ENODEV;
  836. goto err_free_dev;
  837. }
  838. bcap_dev->ppi->priv = bcap_dev;
  839. bcap_dev->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev);
  840. if (IS_ERR(bcap_dev->alloc_ctx)) {
  841. ret = PTR_ERR(bcap_dev->alloc_ctx);
  842. goto err_free_ppi;
  843. }
  844. vfd = video_device_alloc();
  845. if (!vfd) {
  846. ret = -ENOMEM;
  847. v4l2_err(pdev->dev.driver, "Unable to alloc video device\n");
  848. goto err_cleanup_ctx;
  849. }
  850. /* initialize field of video device */
  851. vfd->release = video_device_release;
  852. vfd->fops = &bcap_fops;
  853. vfd->ioctl_ops = &bcap_ioctl_ops;
  854. vfd->tvnorms = 0;
  855. vfd->v4l2_dev = &bcap_dev->v4l2_dev;
  856. set_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
  857. strncpy(vfd->name, CAPTURE_DRV_NAME, sizeof(vfd->name));
  858. bcap_dev->video_dev = vfd;
  859. ret = v4l2_device_register(&pdev->dev, &bcap_dev->v4l2_dev);
  860. if (ret) {
  861. v4l2_err(pdev->dev.driver,
  862. "Unable to register v4l2 device\n");
  863. goto err_release_vdev;
  864. }
  865. v4l2_info(&bcap_dev->v4l2_dev, "v4l2 device registered\n");
  866. bcap_dev->v4l2_dev.ctrl_handler = &bcap_dev->ctrl_handler;
  867. ret = v4l2_ctrl_handler_init(&bcap_dev->ctrl_handler, 0);
  868. if (ret) {
  869. v4l2_err(&bcap_dev->v4l2_dev,
  870. "Unable to init control handler\n");
  871. goto err_unreg_v4l2;
  872. }
  873. spin_lock_init(&bcap_dev->lock);
  874. /* initialize queue */
  875. q = &bcap_dev->buffer_queue;
  876. q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  877. q->io_modes = VB2_MMAP;
  878. q->drv_priv = bcap_dev;
  879. q->buf_struct_size = sizeof(struct bcap_buffer);
  880. q->ops = &bcap_video_qops;
  881. q->mem_ops = &vb2_dma_contig_memops;
  882. vb2_queue_init(q);
  883. mutex_init(&bcap_dev->mutex);
  884. init_completion(&bcap_dev->comp);
  885. /* init video dma queues */
  886. INIT_LIST_HEAD(&bcap_dev->dma_queue);
  887. vfd->lock = &bcap_dev->mutex;
  888. /* register video device */
  889. ret = video_register_device(bcap_dev->video_dev, VFL_TYPE_GRABBER, -1);
  890. if (ret) {
  891. v4l2_err(&bcap_dev->v4l2_dev,
  892. "Unable to register video device\n");
  893. goto err_free_handler;
  894. }
  895. video_set_drvdata(bcap_dev->video_dev, bcap_dev);
  896. v4l2_info(&bcap_dev->v4l2_dev, "video device registered as: %s\n",
  897. video_device_node_name(vfd));
  898. /* load up the subdevice */
  899. i2c_adap = i2c_get_adapter(config->i2c_adapter_id);
  900. if (!i2c_adap) {
  901. v4l2_err(&bcap_dev->v4l2_dev,
  902. "Unable to find i2c adapter\n");
  903. ret = -ENODEV;
  904. goto err_unreg_vdev;
  905. }
  906. bcap_dev->sd = v4l2_i2c_new_subdev_board(&bcap_dev->v4l2_dev,
  907. i2c_adap,
  908. &config->board_info,
  909. NULL);
  910. if (bcap_dev->sd) {
  911. int i;
  912. if (!config->num_inputs) {
  913. v4l2_err(&bcap_dev->v4l2_dev,
  914. "Unable to work without input\n");
  915. goto err_unreg_vdev;
  916. }
  917. /* update tvnorms from the sub devices */
  918. for (i = 0; i < config->num_inputs; i++)
  919. vfd->tvnorms |= config->inputs[i].std;
  920. } else {
  921. v4l2_err(&bcap_dev->v4l2_dev,
  922. "Unable to register sub device\n");
  923. goto err_unreg_vdev;
  924. }
  925. v4l2_info(&bcap_dev->v4l2_dev, "v4l2 sub device registered\n");
  926. /*
  927. * explicitly set input, otherwise some boards
  928. * may not work at the state as we expected
  929. */
  930. route = &config->routes[0];
  931. ret = v4l2_subdev_call(bcap_dev->sd, video, s_routing,
  932. route->input, route->output, 0);
  933. if ((ret < 0) && (ret != -ENOIOCTLCMD)) {
  934. v4l2_err(&bcap_dev->v4l2_dev, "Failed to set input\n");
  935. goto err_unreg_vdev;
  936. }
  937. bcap_dev->cur_input = 0;
  938. /* if this route has specific config, update ppi control */
  939. if (route->ppi_control)
  940. config->ppi_control = route->ppi_control;
  941. /* now we can probe the default state */
  942. if (config->inputs[0].capabilities & V4L2_IN_CAP_STD) {
  943. v4l2_std_id std;
  944. ret = v4l2_subdev_call(bcap_dev->sd, core, g_std, &std);
  945. if (ret) {
  946. v4l2_err(&bcap_dev->v4l2_dev,
  947. "Unable to get std\n");
  948. goto err_unreg_vdev;
  949. }
  950. bcap_dev->std = std;
  951. }
  952. if (config->inputs[0].capabilities & V4L2_IN_CAP_CUSTOM_TIMINGS) {
  953. struct v4l2_dv_timings dv_timings;
  954. ret = v4l2_subdev_call(bcap_dev->sd, video,
  955. g_dv_timings, &dv_timings);
  956. if (ret) {
  957. v4l2_err(&bcap_dev->v4l2_dev,
  958. "Unable to get dv timings\n");
  959. goto err_unreg_vdev;
  960. }
  961. bcap_dev->dv_timings = dv_timings;
  962. }
  963. ret = bcap_init_sensor_formats(bcap_dev);
  964. if (ret) {
  965. v4l2_err(&bcap_dev->v4l2_dev,
  966. "Unable to create sensor formats table\n");
  967. goto err_unreg_vdev;
  968. }
  969. return 0;
  970. err_unreg_vdev:
  971. video_unregister_device(bcap_dev->video_dev);
  972. bcap_dev->video_dev = NULL;
  973. err_free_handler:
  974. v4l2_ctrl_handler_free(&bcap_dev->ctrl_handler);
  975. err_unreg_v4l2:
  976. v4l2_device_unregister(&bcap_dev->v4l2_dev);
  977. err_release_vdev:
  978. if (bcap_dev->video_dev)
  979. video_device_release(bcap_dev->video_dev);
  980. err_cleanup_ctx:
  981. vb2_dma_contig_cleanup_ctx(bcap_dev->alloc_ctx);
  982. err_free_ppi:
  983. ppi_delete_instance(bcap_dev->ppi);
  984. err_free_dev:
  985. kfree(bcap_dev);
  986. return ret;
  987. }
  988. static int bcap_remove(struct platform_device *pdev)
  989. {
  990. struct v4l2_device *v4l2_dev = platform_get_drvdata(pdev);
  991. struct bcap_device *bcap_dev = container_of(v4l2_dev,
  992. struct bcap_device, v4l2_dev);
  993. bcap_free_sensor_formats(bcap_dev);
  994. video_unregister_device(bcap_dev->video_dev);
  995. v4l2_ctrl_handler_free(&bcap_dev->ctrl_handler);
  996. v4l2_device_unregister(v4l2_dev);
  997. vb2_dma_contig_cleanup_ctx(bcap_dev->alloc_ctx);
  998. ppi_delete_instance(bcap_dev->ppi);
  999. kfree(bcap_dev);
  1000. return 0;
  1001. }
  1002. static struct platform_driver bcap_driver = {
  1003. .driver = {
  1004. .name = CAPTURE_DRV_NAME,
  1005. .owner = THIS_MODULE,
  1006. },
  1007. .probe = bcap_probe,
  1008. .remove = bcap_remove,
  1009. };
  1010. module_platform_driver(bcap_driver);
  1011. MODULE_DESCRIPTION("Analog Devices blackfin video capture driver");
  1012. MODULE_AUTHOR("Scott Jiang <Scott.Jiang.Linux@gmail.com>");
  1013. MODULE_LICENSE("GPL v2");