sta2x11_vip.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * This is the driver for the STA2x11 Video Input Port.
  4. *
  5. * Copyright (C) 2012 ST Microelectronics
  6. * author: Federico Vaga <[email protected]>
  7. * Copyright (C) 2010 WindRiver Systems, Inc.
  8. * authors: Andreas Kies <[email protected]>
  9. * Vlad Lungu <[email protected]>
  10. */
  11. #include <linux/types.h>
  12. #include <linux/kernel.h>
  13. #include <linux/module.h>
  14. #include <linux/init.h>
  15. #include <linux/videodev2.h>
  16. #include <linux/kmod.h>
  17. #include <linux/pci.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/io.h>
  20. #include <linux/gpio.h>
  21. #include <linux/i2c.h>
  22. #include <linux/delay.h>
  23. #include <media/v4l2-common.h>
  24. #include <media/v4l2-device.h>
  25. #include <media/v4l2-ctrls.h>
  26. #include <media/v4l2-ioctl.h>
  27. #include <media/v4l2-fh.h>
  28. #include <media/v4l2-event.h>
  29. #include <media/videobuf2-dma-contig.h>
  30. #include "sta2x11_vip.h"
  31. #define DRV_VERSION "1.3"
  32. #ifndef PCI_DEVICE_ID_STMICRO_VIP
  33. #define PCI_DEVICE_ID_STMICRO_VIP 0xCC0D
  34. #endif
  35. #define MAX_FRAMES 4
  36. /*Register offsets*/
  37. #define DVP_CTL 0x00
  38. #define DVP_TFO 0x04
  39. #define DVP_TFS 0x08
  40. #define DVP_BFO 0x0C
  41. #define DVP_BFS 0x10
  42. #define DVP_VTP 0x14
  43. #define DVP_VBP 0x18
  44. #define DVP_VMP 0x1C
  45. #define DVP_ITM 0x98
  46. #define DVP_ITS 0x9C
  47. #define DVP_STA 0xA0
  48. #define DVP_HLFLN 0xA8
  49. #define DVP_RGB 0xC0
  50. #define DVP_PKZ 0xF0
  51. /*Register fields*/
  52. #define DVP_CTL_ENA 0x00000001
  53. #define DVP_CTL_RST 0x80000000
  54. #define DVP_CTL_DIS (~0x00040001)
  55. #define DVP_IT_VSB 0x00000008
  56. #define DVP_IT_VST 0x00000010
  57. #define DVP_IT_FIFO 0x00000020
  58. #define DVP_HLFLN_SD 0x00000001
  59. #define SAVE_COUNT 8
  60. #define AUX_COUNT 3
  61. #define IRQ_COUNT 1
  62. struct vip_buffer {
  63. struct vb2_v4l2_buffer vb;
  64. struct list_head list;
  65. dma_addr_t dma;
  66. };
  67. static inline struct vip_buffer *to_vip_buffer(struct vb2_v4l2_buffer *vb2)
  68. {
  69. return container_of(vb2, struct vip_buffer, vb);
  70. }
  71. /**
  72. * struct sta2x11_vip - All internal data for one instance of device
  73. * @v4l2_dev: device registered in v4l layer
  74. * @video_dev: properties of our device
  75. * @pdev: PCI device
  76. * @adapter: contains I2C adapter information
  77. * @register_save_area: All relevant register are saved here during suspend
  78. * @decoder: contains information about video DAC
  79. * @ctrl_hdl: handler for control framework
  80. * @format: pixel format, fixed UYVY
  81. * @std: video standard (e.g. PAL/NTSC)
  82. * @input: input line for video signal ( 0 or 1 )
  83. * @disabled: Device is in power down state
  84. * @slock: for excluse access of registers
  85. * @vb_vidq: queue maintained by videobuf2 layer
  86. * @buffer_list: list of buffer in use
  87. * @sequence: sequence number of acquired buffer
  88. * @active: current active buffer
  89. * @lock: used in videobuf2 callback
  90. * @v4l_lock: serialize its video4linux ioctls
  91. * @tcount: Number of top frames
  92. * @bcount: Number of bottom frames
  93. * @overflow: Number of FIFO overflows
  94. * @iomem: hardware base address
  95. * @config: I2C and gpio config from platform
  96. *
  97. * All non-local data is accessed via this structure.
  98. */
  99. struct sta2x11_vip {
  100. struct v4l2_device v4l2_dev;
  101. struct video_device video_dev;
  102. struct pci_dev *pdev;
  103. struct i2c_adapter *adapter;
  104. unsigned int register_save_area[IRQ_COUNT + SAVE_COUNT + AUX_COUNT];
  105. struct v4l2_subdev *decoder;
  106. struct v4l2_ctrl_handler ctrl_hdl;
  107. struct v4l2_pix_format format;
  108. v4l2_std_id std;
  109. unsigned int input;
  110. int disabled;
  111. spinlock_t slock;
  112. struct vb2_queue vb_vidq;
  113. struct list_head buffer_list;
  114. unsigned int sequence;
  115. struct vip_buffer *active; /* current active buffer */
  116. spinlock_t lock; /* Used in videobuf2 callback */
  117. struct mutex v4l_lock;
  118. /* Interrupt counters */
  119. int tcount, bcount;
  120. int overflow;
  121. void __iomem *iomem; /* I/O Memory */
  122. struct vip_config *config;
  123. };
  124. static const unsigned int registers_to_save[AUX_COUNT] = {
  125. DVP_HLFLN, DVP_RGB, DVP_PKZ
  126. };
  127. static struct v4l2_pix_format formats_50[] = {
  128. { /*PAL interlaced */
  129. .width = 720,
  130. .height = 576,
  131. .pixelformat = V4L2_PIX_FMT_UYVY,
  132. .field = V4L2_FIELD_INTERLACED,
  133. .bytesperline = 720 * 2,
  134. .sizeimage = 720 * 2 * 576,
  135. .colorspace = V4L2_COLORSPACE_SMPTE170M},
  136. { /*PAL top */
  137. .width = 720,
  138. .height = 288,
  139. .pixelformat = V4L2_PIX_FMT_UYVY,
  140. .field = V4L2_FIELD_TOP,
  141. .bytesperline = 720 * 2,
  142. .sizeimage = 720 * 2 * 288,
  143. .colorspace = V4L2_COLORSPACE_SMPTE170M},
  144. { /*PAL bottom */
  145. .width = 720,
  146. .height = 288,
  147. .pixelformat = V4L2_PIX_FMT_UYVY,
  148. .field = V4L2_FIELD_BOTTOM,
  149. .bytesperline = 720 * 2,
  150. .sizeimage = 720 * 2 * 288,
  151. .colorspace = V4L2_COLORSPACE_SMPTE170M},
  152. };
  153. static struct v4l2_pix_format formats_60[] = {
  154. { /*NTSC interlaced */
  155. .width = 720,
  156. .height = 480,
  157. .pixelformat = V4L2_PIX_FMT_UYVY,
  158. .field = V4L2_FIELD_INTERLACED,
  159. .bytesperline = 720 * 2,
  160. .sizeimage = 720 * 2 * 480,
  161. .colorspace = V4L2_COLORSPACE_SMPTE170M},
  162. { /*NTSC top */
  163. .width = 720,
  164. .height = 240,
  165. .pixelformat = V4L2_PIX_FMT_UYVY,
  166. .field = V4L2_FIELD_TOP,
  167. .bytesperline = 720 * 2,
  168. .sizeimage = 720 * 2 * 240,
  169. .colorspace = V4L2_COLORSPACE_SMPTE170M},
  170. { /*NTSC bottom */
  171. .width = 720,
  172. .height = 240,
  173. .pixelformat = V4L2_PIX_FMT_UYVY,
  174. .field = V4L2_FIELD_BOTTOM,
  175. .bytesperline = 720 * 2,
  176. .sizeimage = 720 * 2 * 240,
  177. .colorspace = V4L2_COLORSPACE_SMPTE170M},
  178. };
  179. /* Write VIP register */
  180. static inline void reg_write(struct sta2x11_vip *vip, unsigned int reg, u32 val)
  181. {
  182. iowrite32((val), (vip->iomem)+(reg));
  183. }
  184. /* Read VIP register */
  185. static inline u32 reg_read(struct sta2x11_vip *vip, unsigned int reg)
  186. {
  187. return ioread32((vip->iomem)+(reg));
  188. }
  189. /* Start DMA acquisition */
  190. static void start_dma(struct sta2x11_vip *vip, struct vip_buffer *vip_buf)
  191. {
  192. unsigned long offset = 0;
  193. if (vip->format.field == V4L2_FIELD_INTERLACED)
  194. offset = vip->format.width * 2;
  195. spin_lock_irq(&vip->slock);
  196. /* Enable acquisition */
  197. reg_write(vip, DVP_CTL, reg_read(vip, DVP_CTL) | DVP_CTL_ENA);
  198. /* Set Top and Bottom Field memory address */
  199. reg_write(vip, DVP_VTP, (u32)vip_buf->dma);
  200. reg_write(vip, DVP_VBP, (u32)vip_buf->dma + offset);
  201. spin_unlock_irq(&vip->slock);
  202. }
  203. /* Fetch the next buffer to activate */
  204. static void vip_active_buf_next(struct sta2x11_vip *vip)
  205. {
  206. /* Get the next buffer */
  207. spin_lock(&vip->lock);
  208. if (list_empty(&vip->buffer_list)) {/* No available buffer */
  209. spin_unlock(&vip->lock);
  210. return;
  211. }
  212. vip->active = list_first_entry(&vip->buffer_list,
  213. struct vip_buffer,
  214. list);
  215. /* Reset Top and Bottom counter */
  216. vip->tcount = 0;
  217. vip->bcount = 0;
  218. spin_unlock(&vip->lock);
  219. if (vb2_is_streaming(&vip->vb_vidq)) { /* streaming is on */
  220. start_dma(vip, vip->active); /* start dma capture */
  221. }
  222. }
  223. /* Videobuf2 Operations */
  224. static int queue_setup(struct vb2_queue *vq,
  225. unsigned int *nbuffers, unsigned int *nplanes,
  226. unsigned int sizes[], struct device *alloc_devs[])
  227. {
  228. struct sta2x11_vip *vip = vb2_get_drv_priv(vq);
  229. if (!(*nbuffers) || *nbuffers < MAX_FRAMES)
  230. *nbuffers = MAX_FRAMES;
  231. *nplanes = 1;
  232. sizes[0] = vip->format.sizeimage;
  233. vip->sequence = 0;
  234. vip->active = NULL;
  235. vip->tcount = 0;
  236. vip->bcount = 0;
  237. return 0;
  238. };
  239. static int buffer_init(struct vb2_buffer *vb)
  240. {
  241. struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
  242. struct vip_buffer *vip_buf = to_vip_buffer(vbuf);
  243. vip_buf->dma = vb2_dma_contig_plane_dma_addr(vb, 0);
  244. INIT_LIST_HEAD(&vip_buf->list);
  245. return 0;
  246. }
  247. static int buffer_prepare(struct vb2_buffer *vb)
  248. {
  249. struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
  250. struct sta2x11_vip *vip = vb2_get_drv_priv(vb->vb2_queue);
  251. struct vip_buffer *vip_buf = to_vip_buffer(vbuf);
  252. unsigned long size;
  253. size = vip->format.sizeimage;
  254. if (vb2_plane_size(vb, 0) < size) {
  255. v4l2_err(&vip->v4l2_dev, "buffer too small (%lu < %lu)\n",
  256. vb2_plane_size(vb, 0), size);
  257. return -EINVAL;
  258. }
  259. vb2_set_plane_payload(&vip_buf->vb.vb2_buf, 0, size);
  260. return 0;
  261. }
  262. static void buffer_queue(struct vb2_buffer *vb)
  263. {
  264. struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
  265. struct sta2x11_vip *vip = vb2_get_drv_priv(vb->vb2_queue);
  266. struct vip_buffer *vip_buf = to_vip_buffer(vbuf);
  267. spin_lock(&vip->lock);
  268. list_add_tail(&vip_buf->list, &vip->buffer_list);
  269. if (!vip->active) { /* No active buffer, active the first one */
  270. vip->active = list_first_entry(&vip->buffer_list,
  271. struct vip_buffer,
  272. list);
  273. if (vb2_is_streaming(&vip->vb_vidq)) /* streaming is on */
  274. start_dma(vip, vip_buf); /* start dma capture */
  275. }
  276. spin_unlock(&vip->lock);
  277. }
  278. static void buffer_finish(struct vb2_buffer *vb)
  279. {
  280. struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
  281. struct sta2x11_vip *vip = vb2_get_drv_priv(vb->vb2_queue);
  282. struct vip_buffer *vip_buf = to_vip_buffer(vbuf);
  283. /* Buffer handled, remove it from the list */
  284. spin_lock(&vip->lock);
  285. list_del_init(&vip_buf->list);
  286. spin_unlock(&vip->lock);
  287. if (vb2_is_streaming(vb->vb2_queue))
  288. vip_active_buf_next(vip);
  289. }
  290. static int start_streaming(struct vb2_queue *vq, unsigned int count)
  291. {
  292. struct sta2x11_vip *vip = vb2_get_drv_priv(vq);
  293. spin_lock_irq(&vip->slock);
  294. /* Enable interrupt VSYNC Top and Bottom*/
  295. reg_write(vip, DVP_ITM, DVP_IT_VSB | DVP_IT_VST);
  296. spin_unlock_irq(&vip->slock);
  297. if (count)
  298. start_dma(vip, vip->active);
  299. return 0;
  300. }
  301. /* abort streaming and wait for last buffer */
  302. static void stop_streaming(struct vb2_queue *vq)
  303. {
  304. struct sta2x11_vip *vip = vb2_get_drv_priv(vq);
  305. struct vip_buffer *vip_buf, *node;
  306. /* Disable acquisition */
  307. reg_write(vip, DVP_CTL, reg_read(vip, DVP_CTL) & ~DVP_CTL_ENA);
  308. /* Disable all interrupts */
  309. reg_write(vip, DVP_ITM, 0);
  310. /* Release all active buffers */
  311. spin_lock(&vip->lock);
  312. list_for_each_entry_safe(vip_buf, node, &vip->buffer_list, list) {
  313. vb2_buffer_done(&vip_buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
  314. list_del(&vip_buf->list);
  315. }
  316. spin_unlock(&vip->lock);
  317. }
  318. static const struct vb2_ops vip_video_qops = {
  319. .queue_setup = queue_setup,
  320. .buf_init = buffer_init,
  321. .buf_prepare = buffer_prepare,
  322. .buf_finish = buffer_finish,
  323. .buf_queue = buffer_queue,
  324. .start_streaming = start_streaming,
  325. .stop_streaming = stop_streaming,
  326. .wait_prepare = vb2_ops_wait_prepare,
  327. .wait_finish = vb2_ops_wait_finish,
  328. };
  329. /* File Operations */
  330. static const struct v4l2_file_operations vip_fops = {
  331. .owner = THIS_MODULE,
  332. .open = v4l2_fh_open,
  333. .release = vb2_fop_release,
  334. .unlocked_ioctl = video_ioctl2,
  335. .read = vb2_fop_read,
  336. .mmap = vb2_fop_mmap,
  337. .poll = vb2_fop_poll
  338. };
  339. /**
  340. * vidioc_querycap - return capabilities of device
  341. * @file: descriptor of device
  342. * @cap: contains return values
  343. * @priv: unused
  344. *
  345. * the capabilities of the device are returned
  346. *
  347. * return value: 0, no error.
  348. */
  349. static int vidioc_querycap(struct file *file, void *priv,
  350. struct v4l2_capability *cap)
  351. {
  352. strscpy(cap->driver, KBUILD_MODNAME, sizeof(cap->driver));
  353. strscpy(cap->card, KBUILD_MODNAME, sizeof(cap->card));
  354. return 0;
  355. }
  356. /**
  357. * vidioc_s_std - set video standard
  358. * @file: descriptor of device
  359. * @std: contains standard to be set
  360. * @priv: unused
  361. *
  362. * the video standard is set
  363. *
  364. * return value: 0, no error.
  365. *
  366. * -EIO, no input signal detected
  367. *
  368. * other, returned from video DAC.
  369. */
  370. static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id std)
  371. {
  372. struct sta2x11_vip *vip = video_drvdata(file);
  373. /*
  374. * This is here for backwards compatibility only.
  375. * The use of V4L2_STD_ALL to trigger a querystd is non-standard.
  376. */
  377. if (std == V4L2_STD_ALL) {
  378. v4l2_subdev_call(vip->decoder, video, querystd, &std);
  379. if (std == V4L2_STD_UNKNOWN)
  380. return -EIO;
  381. }
  382. if (vip->std != std) {
  383. vip->std = std;
  384. if (V4L2_STD_525_60 & std)
  385. vip->format = formats_60[0];
  386. else
  387. vip->format = formats_50[0];
  388. }
  389. return v4l2_subdev_call(vip->decoder, video, s_std, std);
  390. }
  391. /**
  392. * vidioc_g_std - get video standard
  393. * @file: descriptor of device
  394. * @priv: unused
  395. * @std: contains return values
  396. *
  397. * the current video standard is returned
  398. *
  399. * return value: 0, no error.
  400. */
  401. static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *std)
  402. {
  403. struct sta2x11_vip *vip = video_drvdata(file);
  404. *std = vip->std;
  405. return 0;
  406. }
  407. /**
  408. * vidioc_querystd - get possible video standards
  409. * @file: descriptor of device
  410. * @priv: unused
  411. * @std: contains return values
  412. *
  413. * all possible video standards are returned
  414. *
  415. * return value: delivered by video DAC routine.
  416. */
  417. static int vidioc_querystd(struct file *file, void *priv, v4l2_std_id *std)
  418. {
  419. struct sta2x11_vip *vip = video_drvdata(file);
  420. return v4l2_subdev_call(vip->decoder, video, querystd, std);
  421. }
  422. static int vidioc_enum_input(struct file *file, void *priv,
  423. struct v4l2_input *inp)
  424. {
  425. if (inp->index > 1)
  426. return -EINVAL;
  427. inp->type = V4L2_INPUT_TYPE_CAMERA;
  428. inp->std = V4L2_STD_ALL;
  429. sprintf(inp->name, "Camera %u", inp->index);
  430. return 0;
  431. }
  432. /**
  433. * vidioc_s_input - set input line
  434. * @file: descriptor of device
  435. * @priv: unused
  436. * @i: new input line number
  437. *
  438. * the current active input line is set
  439. *
  440. * return value: 0, no error.
  441. *
  442. * -EINVAL, line number out of range
  443. */
  444. static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
  445. {
  446. struct sta2x11_vip *vip = video_drvdata(file);
  447. int ret;
  448. if (i > 1)
  449. return -EINVAL;
  450. ret = v4l2_subdev_call(vip->decoder, video, s_routing, i, 0, 0);
  451. if (!ret)
  452. vip->input = i;
  453. return 0;
  454. }
  455. /**
  456. * vidioc_g_input - return input line
  457. * @file: descriptor of device
  458. * @priv: unused
  459. * @i: returned input line number
  460. *
  461. * the current active input line is returned
  462. *
  463. * return value: always 0.
  464. */
  465. static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
  466. {
  467. struct sta2x11_vip *vip = video_drvdata(file);
  468. *i = vip->input;
  469. return 0;
  470. }
  471. /**
  472. * vidioc_enum_fmt_vid_cap - return video capture format
  473. * @file: descriptor of device
  474. * @priv: unused
  475. * @f: returned format information
  476. *
  477. * returns name and format of video capture
  478. * Only UYVY is supported by hardware.
  479. *
  480. * return value: always 0.
  481. */
  482. static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
  483. struct v4l2_fmtdesc *f)
  484. {
  485. if (f->index != 0)
  486. return -EINVAL;
  487. f->pixelformat = V4L2_PIX_FMT_UYVY;
  488. return 0;
  489. }
  490. /**
  491. * vidioc_try_fmt_vid_cap - set video capture format
  492. * @file: descriptor of device
  493. * @priv: unused
  494. * @f: new format
  495. *
  496. * new video format is set which includes width and
  497. * field type. width is fixed to 720, no scaling.
  498. * Only UYVY is supported by this hardware.
  499. * the minimum height is 200, the maximum is 576 (PAL)
  500. *
  501. * return value: 0, no error
  502. *
  503. * -EINVAL, pixel or field format not supported
  504. *
  505. */
  506. static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
  507. struct v4l2_format *f)
  508. {
  509. struct sta2x11_vip *vip = video_drvdata(file);
  510. int interlace_lim;
  511. if (V4L2_PIX_FMT_UYVY != f->fmt.pix.pixelformat) {
  512. v4l2_warn(&vip->v4l2_dev, "Invalid format, only UYVY supported\n");
  513. return -EINVAL;
  514. }
  515. if (V4L2_STD_525_60 & vip->std)
  516. interlace_lim = 240;
  517. else
  518. interlace_lim = 288;
  519. switch (f->fmt.pix.field) {
  520. default:
  521. case V4L2_FIELD_ANY:
  522. if (interlace_lim < f->fmt.pix.height)
  523. f->fmt.pix.field = V4L2_FIELD_INTERLACED;
  524. else
  525. f->fmt.pix.field = V4L2_FIELD_BOTTOM;
  526. break;
  527. case V4L2_FIELD_TOP:
  528. case V4L2_FIELD_BOTTOM:
  529. if (interlace_lim < f->fmt.pix.height)
  530. f->fmt.pix.height = interlace_lim;
  531. break;
  532. case V4L2_FIELD_INTERLACED:
  533. break;
  534. }
  535. /* It is the only supported format */
  536. f->fmt.pix.pixelformat = V4L2_PIX_FMT_UYVY;
  537. f->fmt.pix.height &= ~1;
  538. if (2 * interlace_lim < f->fmt.pix.height)
  539. f->fmt.pix.height = 2 * interlace_lim;
  540. if (200 > f->fmt.pix.height)
  541. f->fmt.pix.height = 200;
  542. f->fmt.pix.width = 720;
  543. f->fmt.pix.bytesperline = f->fmt.pix.width * 2;
  544. f->fmt.pix.sizeimage = f->fmt.pix.width * 2 * f->fmt.pix.height;
  545. f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
  546. return 0;
  547. }
  548. /**
  549. * vidioc_s_fmt_vid_cap - set current video format parameters
  550. * @file: descriptor of device
  551. * @priv: unused
  552. * @f: returned format information
  553. *
  554. * set new capture format
  555. * return value: 0, no error
  556. *
  557. * other, delivered by video DAC routine.
  558. */
  559. static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
  560. struct v4l2_format *f)
  561. {
  562. struct sta2x11_vip *vip = video_drvdata(file);
  563. unsigned int t_stop, b_stop, pitch;
  564. int ret;
  565. ret = vidioc_try_fmt_vid_cap(file, priv, f);
  566. if (ret)
  567. return ret;
  568. if (vb2_is_busy(&vip->vb_vidq)) {
  569. /* Can't change format during acquisition */
  570. v4l2_err(&vip->v4l2_dev, "device busy\n");
  571. return -EBUSY;
  572. }
  573. vip->format = f->fmt.pix;
  574. switch (vip->format.field) {
  575. case V4L2_FIELD_INTERLACED:
  576. t_stop = ((vip->format.height / 2 - 1) << 16) |
  577. (2 * vip->format.width - 1);
  578. b_stop = t_stop;
  579. pitch = 4 * vip->format.width;
  580. break;
  581. case V4L2_FIELD_TOP:
  582. t_stop = ((vip->format.height - 1) << 16) |
  583. (2 * vip->format.width - 1);
  584. b_stop = (0 << 16) | (2 * vip->format.width - 1);
  585. pitch = 2 * vip->format.width;
  586. break;
  587. case V4L2_FIELD_BOTTOM:
  588. t_stop = (0 << 16) | (2 * vip->format.width - 1);
  589. b_stop = (vip->format.height << 16) |
  590. (2 * vip->format.width - 1);
  591. pitch = 2 * vip->format.width;
  592. break;
  593. default:
  594. v4l2_err(&vip->v4l2_dev, "unknown field format\n");
  595. return -EINVAL;
  596. }
  597. spin_lock_irq(&vip->slock);
  598. /* Y-X Top Field Offset */
  599. reg_write(vip, DVP_TFO, 0);
  600. /* Y-X Bottom Field Offset */
  601. reg_write(vip, DVP_BFO, 0);
  602. /* Y-X Top Field Stop*/
  603. reg_write(vip, DVP_TFS, t_stop);
  604. /* Y-X Bottom Field Stop */
  605. reg_write(vip, DVP_BFS, b_stop);
  606. /* Video Memory Pitch */
  607. reg_write(vip, DVP_VMP, pitch);
  608. spin_unlock_irq(&vip->slock);
  609. return 0;
  610. }
  611. /**
  612. * vidioc_g_fmt_vid_cap - get current video format parameters
  613. * @file: descriptor of device
  614. * @priv: unused
  615. * @f: contains format information
  616. *
  617. * returns current video format parameters
  618. *
  619. * return value: 0, always successful
  620. */
  621. static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
  622. struct v4l2_format *f)
  623. {
  624. struct sta2x11_vip *vip = video_drvdata(file);
  625. f->fmt.pix = vip->format;
  626. return 0;
  627. }
  628. static const struct v4l2_ioctl_ops vip_ioctl_ops = {
  629. .vidioc_querycap = vidioc_querycap,
  630. /* FMT handling */
  631. .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
  632. .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
  633. .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
  634. .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
  635. /* Buffer handlers */
  636. .vidioc_create_bufs = vb2_ioctl_create_bufs,
  637. .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
  638. .vidioc_reqbufs = vb2_ioctl_reqbufs,
  639. .vidioc_querybuf = vb2_ioctl_querybuf,
  640. .vidioc_qbuf = vb2_ioctl_qbuf,
  641. .vidioc_dqbuf = vb2_ioctl_dqbuf,
  642. /* Stream on/off */
  643. .vidioc_streamon = vb2_ioctl_streamon,
  644. .vidioc_streamoff = vb2_ioctl_streamoff,
  645. /* Standard handling */
  646. .vidioc_g_std = vidioc_g_std,
  647. .vidioc_s_std = vidioc_s_std,
  648. .vidioc_querystd = vidioc_querystd,
  649. /* Input handling */
  650. .vidioc_enum_input = vidioc_enum_input,
  651. .vidioc_g_input = vidioc_g_input,
  652. .vidioc_s_input = vidioc_s_input,
  653. /* Log status ioctl */
  654. .vidioc_log_status = v4l2_ctrl_log_status,
  655. /* Event handling */
  656. .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
  657. .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
  658. };
  659. static const struct video_device video_dev_template = {
  660. .name = KBUILD_MODNAME,
  661. .release = video_device_release_empty,
  662. .fops = &vip_fops,
  663. .ioctl_ops = &vip_ioctl_ops,
  664. .tvnorms = V4L2_STD_ALL,
  665. .device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE |
  666. V4L2_CAP_STREAMING,
  667. };
  668. /**
  669. * vip_irq - interrupt routine
  670. * @irq: Number of interrupt ( not used, correct number is assumed )
  671. * @vip: local data structure containing all information
  672. *
  673. * check for both frame interrupts set ( top and bottom ).
  674. * check FIFO overflow, but limit number of log messages after open.
  675. * signal a complete buffer if done
  676. *
  677. * return value: IRQ_NONE, interrupt was not generated by VIP
  678. *
  679. * IRQ_HANDLED, interrupt done.
  680. */
  681. static irqreturn_t vip_irq(int irq, struct sta2x11_vip *vip)
  682. {
  683. unsigned int status;
  684. status = reg_read(vip, DVP_ITS);
  685. if (!status) /* No interrupt to handle */
  686. return IRQ_NONE;
  687. if (status & DVP_IT_FIFO)
  688. if (vip->overflow++ > 5)
  689. pr_info("VIP: fifo overflow\n");
  690. if ((status & DVP_IT_VST) && (status & DVP_IT_VSB)) {
  691. /* this is bad, we are too slow, hope the condition is gone
  692. * on the next frame */
  693. return IRQ_HANDLED;
  694. }
  695. if (status & DVP_IT_VST)
  696. if ((++vip->tcount) < 2)
  697. return IRQ_HANDLED;
  698. if (status & DVP_IT_VSB) {
  699. vip->bcount++;
  700. return IRQ_HANDLED;
  701. }
  702. if (vip->active) { /* Acquisition is over on this buffer */
  703. /* Disable acquisition */
  704. reg_write(vip, DVP_CTL, reg_read(vip, DVP_CTL) & ~DVP_CTL_ENA);
  705. /* Remove the active buffer from the list */
  706. vip->active->vb.vb2_buf.timestamp = ktime_get_ns();
  707. vip->active->vb.sequence = vip->sequence++;
  708. vb2_buffer_done(&vip->active->vb.vb2_buf, VB2_BUF_STATE_DONE);
  709. }
  710. return IRQ_HANDLED;
  711. }
  712. static void sta2x11_vip_init_register(struct sta2x11_vip *vip)
  713. {
  714. /* Register initialization */
  715. spin_lock_irq(&vip->slock);
  716. /* Clean interrupt */
  717. reg_read(vip, DVP_ITS);
  718. /* Enable Half Line per vertical */
  719. reg_write(vip, DVP_HLFLN, DVP_HLFLN_SD);
  720. /* Reset VIP control */
  721. reg_write(vip, DVP_CTL, DVP_CTL_RST);
  722. /* Clear VIP control */
  723. reg_write(vip, DVP_CTL, 0);
  724. spin_unlock_irq(&vip->slock);
  725. }
  726. static void sta2x11_vip_clear_register(struct sta2x11_vip *vip)
  727. {
  728. spin_lock_irq(&vip->slock);
  729. /* Disable interrupt */
  730. reg_write(vip, DVP_ITM, 0);
  731. /* Reset VIP Control */
  732. reg_write(vip, DVP_CTL, DVP_CTL_RST);
  733. /* Clear VIP Control */
  734. reg_write(vip, DVP_CTL, 0);
  735. /* Clean VIP Interrupt */
  736. reg_read(vip, DVP_ITS);
  737. spin_unlock_irq(&vip->slock);
  738. }
  739. static int sta2x11_vip_init_buffer(struct sta2x11_vip *vip)
  740. {
  741. int err;
  742. err = dma_set_coherent_mask(&vip->pdev->dev, DMA_BIT_MASK(29));
  743. if (err) {
  744. v4l2_err(&vip->v4l2_dev, "Cannot configure coherent mask");
  745. return err;
  746. }
  747. memset(&vip->vb_vidq, 0, sizeof(struct vb2_queue));
  748. vip->vb_vidq.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  749. vip->vb_vidq.io_modes = VB2_MMAP | VB2_READ;
  750. vip->vb_vidq.drv_priv = vip;
  751. vip->vb_vidq.buf_struct_size = sizeof(struct vip_buffer);
  752. vip->vb_vidq.ops = &vip_video_qops;
  753. vip->vb_vidq.mem_ops = &vb2_dma_contig_memops;
  754. vip->vb_vidq.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
  755. vip->vb_vidq.dev = &vip->pdev->dev;
  756. vip->vb_vidq.lock = &vip->v4l_lock;
  757. err = vb2_queue_init(&vip->vb_vidq);
  758. if (err)
  759. return err;
  760. INIT_LIST_HEAD(&vip->buffer_list);
  761. spin_lock_init(&vip->lock);
  762. return 0;
  763. }
  764. static int sta2x11_vip_init_controls(struct sta2x11_vip *vip)
  765. {
  766. /*
  767. * Inititialize an empty control so VIP can inerithing controls
  768. * from ADV7180
  769. */
  770. v4l2_ctrl_handler_init(&vip->ctrl_hdl, 0);
  771. vip->v4l2_dev.ctrl_handler = &vip->ctrl_hdl;
  772. if (vip->ctrl_hdl.error) {
  773. int err = vip->ctrl_hdl.error;
  774. v4l2_ctrl_handler_free(&vip->ctrl_hdl);
  775. return err;
  776. }
  777. return 0;
  778. }
  779. /**
  780. * vip_gpio_reserve - reserve gpio pin
  781. * @dev: device
  782. * @pin: GPIO pin number
  783. * @dir: direction, input or output
  784. * @name: GPIO pin name
  785. *
  786. */
  787. static int vip_gpio_reserve(struct device *dev, int pin, int dir,
  788. const char *name)
  789. {
  790. int ret = -ENODEV;
  791. if (!gpio_is_valid(pin))
  792. return ret;
  793. ret = gpio_request(pin, name);
  794. if (ret) {
  795. dev_err(dev, "Failed to allocate pin %d (%s)\n", pin, name);
  796. return ret;
  797. }
  798. ret = gpio_direction_output(pin, dir);
  799. if (ret) {
  800. dev_err(dev, "Failed to set direction for pin %d (%s)\n",
  801. pin, name);
  802. gpio_free(pin);
  803. return ret;
  804. }
  805. ret = gpio_export(pin, false);
  806. if (ret) {
  807. dev_err(dev, "Failed to export pin %d (%s)\n", pin, name);
  808. gpio_free(pin);
  809. return ret;
  810. }
  811. return 0;
  812. }
  813. /**
  814. * vip_gpio_release - release gpio pin
  815. * @dev: device
  816. * @pin: GPIO pin number
  817. * @name: GPIO pin name
  818. *
  819. */
  820. static void vip_gpio_release(struct device *dev, int pin, const char *name)
  821. {
  822. if (gpio_is_valid(pin)) {
  823. dev_dbg(dev, "releasing pin %d (%s)\n", pin, name);
  824. gpio_unexport(pin);
  825. gpio_free(pin);
  826. }
  827. }
  828. /**
  829. * sta2x11_vip_init_one - init one instance of video device
  830. * @pdev: PCI device
  831. * @ent: (not used)
  832. *
  833. * allocate reset pins for DAC.
  834. * Reset video DAC, this is done via reset line.
  835. * allocate memory for managing device
  836. * request interrupt
  837. * map IO region
  838. * register device
  839. * find and initialize video DAC
  840. *
  841. * return value: 0, no error
  842. *
  843. * -ENOMEM, no memory
  844. *
  845. * -ENODEV, device could not be detected or registered
  846. */
  847. static int sta2x11_vip_init_one(struct pci_dev *pdev,
  848. const struct pci_device_id *ent)
  849. {
  850. int ret;
  851. struct sta2x11_vip *vip;
  852. struct vip_config *config;
  853. /* Check if hardware support 26-bit DMA */
  854. if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(26))) {
  855. dev_err(&pdev->dev, "26-bit DMA addressing not available\n");
  856. return -EINVAL;
  857. }
  858. /* Enable PCI */
  859. ret = pci_enable_device(pdev);
  860. if (ret)
  861. return ret;
  862. /* Get VIP platform data */
  863. config = dev_get_platdata(&pdev->dev);
  864. if (!config) {
  865. dev_info(&pdev->dev, "VIP slot disabled\n");
  866. ret = -EINVAL;
  867. goto disable;
  868. }
  869. /* Power configuration */
  870. ret = vip_gpio_reserve(&pdev->dev, config->pwr_pin, 0,
  871. config->pwr_name);
  872. if (ret)
  873. goto disable;
  874. ret = vip_gpio_reserve(&pdev->dev, config->reset_pin, 0,
  875. config->reset_name);
  876. if (ret) {
  877. vip_gpio_release(&pdev->dev, config->pwr_pin,
  878. config->pwr_name);
  879. goto disable;
  880. }
  881. if (gpio_is_valid(config->pwr_pin)) {
  882. /* Datasheet says 5ms between PWR and RST */
  883. usleep_range(5000, 25000);
  884. gpio_direction_output(config->pwr_pin, 1);
  885. }
  886. if (gpio_is_valid(config->reset_pin)) {
  887. /* Datasheet says 5ms between PWR and RST */
  888. usleep_range(5000, 25000);
  889. gpio_direction_output(config->reset_pin, 1);
  890. }
  891. usleep_range(5000, 25000);
  892. /* Allocate a new VIP instance */
  893. vip = kzalloc(sizeof(struct sta2x11_vip), GFP_KERNEL);
  894. if (!vip) {
  895. ret = -ENOMEM;
  896. goto release_gpios;
  897. }
  898. vip->pdev = pdev;
  899. vip->std = V4L2_STD_PAL;
  900. vip->format = formats_50[0];
  901. vip->config = config;
  902. mutex_init(&vip->v4l_lock);
  903. ret = sta2x11_vip_init_controls(vip);
  904. if (ret)
  905. goto free_mem;
  906. ret = v4l2_device_register(&pdev->dev, &vip->v4l2_dev);
  907. if (ret)
  908. goto free_mem;
  909. dev_dbg(&pdev->dev, "BAR #0 at 0x%lx 0x%lx irq %d\n",
  910. (unsigned long)pci_resource_start(pdev, 0),
  911. (unsigned long)pci_resource_len(pdev, 0), pdev->irq);
  912. pci_set_master(pdev);
  913. ret = pci_request_regions(pdev, KBUILD_MODNAME);
  914. if (ret)
  915. goto unreg;
  916. vip->iomem = pci_iomap(pdev, 0, 0x100);
  917. if (!vip->iomem) {
  918. ret = -ENOMEM;
  919. goto release;
  920. }
  921. pci_enable_msi(pdev);
  922. /* Initialize buffer */
  923. ret = sta2x11_vip_init_buffer(vip);
  924. if (ret)
  925. goto unmap;
  926. spin_lock_init(&vip->slock);
  927. ret = request_irq(pdev->irq,
  928. (irq_handler_t) vip_irq,
  929. IRQF_SHARED, KBUILD_MODNAME, vip);
  930. if (ret) {
  931. dev_err(&pdev->dev, "request_irq failed\n");
  932. ret = -ENODEV;
  933. goto release_buf;
  934. }
  935. /* Initialize and register video device */
  936. vip->video_dev = video_dev_template;
  937. vip->video_dev.v4l2_dev = &vip->v4l2_dev;
  938. vip->video_dev.queue = &vip->vb_vidq;
  939. vip->video_dev.lock = &vip->v4l_lock;
  940. video_set_drvdata(&vip->video_dev, vip);
  941. ret = video_register_device(&vip->video_dev, VFL_TYPE_VIDEO, -1);
  942. if (ret)
  943. goto vrelease;
  944. /* Get ADV7180 subdevice */
  945. vip->adapter = i2c_get_adapter(vip->config->i2c_id);
  946. if (!vip->adapter) {
  947. ret = -ENODEV;
  948. dev_err(&pdev->dev, "no I2C adapter found\n");
  949. goto vunreg;
  950. }
  951. vip->decoder = v4l2_i2c_new_subdev(&vip->v4l2_dev, vip->adapter,
  952. "adv7180", vip->config->i2c_addr,
  953. NULL);
  954. if (!vip->decoder) {
  955. ret = -ENODEV;
  956. dev_err(&pdev->dev, "no decoder found\n");
  957. goto vunreg;
  958. }
  959. i2c_put_adapter(vip->adapter);
  960. v4l2_subdev_call(vip->decoder, core, init, 0);
  961. sta2x11_vip_init_register(vip);
  962. dev_info(&pdev->dev, "STA2X11 Video Input Port (VIP) loaded\n");
  963. return 0;
  964. vunreg:
  965. video_set_drvdata(&vip->video_dev, NULL);
  966. vrelease:
  967. vb2_video_unregister_device(&vip->video_dev);
  968. free_irq(pdev->irq, vip);
  969. release_buf:
  970. pci_disable_msi(pdev);
  971. unmap:
  972. pci_iounmap(pdev, vip->iomem);
  973. release:
  974. pci_release_regions(pdev);
  975. unreg:
  976. v4l2_device_unregister(&vip->v4l2_dev);
  977. free_mem:
  978. kfree(vip);
  979. release_gpios:
  980. vip_gpio_release(&pdev->dev, config->reset_pin, config->reset_name);
  981. vip_gpio_release(&pdev->dev, config->pwr_pin, config->pwr_name);
  982. disable:
  983. /*
  984. * do not call pci_disable_device on sta2x11 because it break all
  985. * other Bus masters on this EP
  986. */
  987. return ret;
  988. }
  989. /**
  990. * sta2x11_vip_remove_one - release device
  991. * @pdev: PCI device
  992. *
  993. * Undo everything done in .._init_one
  994. *
  995. * unregister video device
  996. * free interrupt
  997. * unmap ioadresses
  998. * free memory
  999. * free GPIO pins
  1000. */
  1001. static void sta2x11_vip_remove_one(struct pci_dev *pdev)
  1002. {
  1003. struct v4l2_device *v4l2_dev = pci_get_drvdata(pdev);
  1004. struct sta2x11_vip *vip =
  1005. container_of(v4l2_dev, struct sta2x11_vip, v4l2_dev);
  1006. sta2x11_vip_clear_register(vip);
  1007. video_set_drvdata(&vip->video_dev, NULL);
  1008. vb2_video_unregister_device(&vip->video_dev);
  1009. free_irq(pdev->irq, vip);
  1010. pci_disable_msi(pdev);
  1011. pci_iounmap(pdev, vip->iomem);
  1012. pci_release_regions(pdev);
  1013. v4l2_device_unregister(&vip->v4l2_dev);
  1014. vip_gpio_release(&pdev->dev, vip->config->pwr_pin,
  1015. vip->config->pwr_name);
  1016. vip_gpio_release(&pdev->dev, vip->config->reset_pin,
  1017. vip->config->reset_name);
  1018. kfree(vip);
  1019. /*
  1020. * do not call pci_disable_device on sta2x11 because it break all
  1021. * other Bus masters on this EP
  1022. */
  1023. }
  1024. /**
  1025. * sta2x11_vip_suspend - set device into power save mode
  1026. * @dev_d: PCI device
  1027. *
  1028. * all relevant registers are saved and an attempt to set a new state is made.
  1029. *
  1030. * return value: 0 always indicate success,
  1031. * even if device could not be disabled. (workaround for hardware problem)
  1032. */
  1033. static int __maybe_unused sta2x11_vip_suspend(struct device *dev_d)
  1034. {
  1035. struct v4l2_device *v4l2_dev = dev_get_drvdata(dev_d);
  1036. struct sta2x11_vip *vip =
  1037. container_of(v4l2_dev, struct sta2x11_vip, v4l2_dev);
  1038. unsigned long flags;
  1039. int i;
  1040. spin_lock_irqsave(&vip->slock, flags);
  1041. vip->register_save_area[0] = reg_read(vip, DVP_CTL);
  1042. reg_write(vip, DVP_CTL, vip->register_save_area[0] & DVP_CTL_DIS);
  1043. vip->register_save_area[SAVE_COUNT] = reg_read(vip, DVP_ITM);
  1044. reg_write(vip, DVP_ITM, 0);
  1045. for (i = 1; i < SAVE_COUNT; i++)
  1046. vip->register_save_area[i] = reg_read(vip, 4 * i);
  1047. for (i = 0; i < AUX_COUNT; i++)
  1048. vip->register_save_area[SAVE_COUNT + IRQ_COUNT + i] =
  1049. reg_read(vip, registers_to_save[i]);
  1050. spin_unlock_irqrestore(&vip->slock, flags);
  1051. vip->disabled = 1;
  1052. pr_info("VIP: suspend\n");
  1053. return 0;
  1054. }
  1055. /**
  1056. * sta2x11_vip_resume - resume device operation
  1057. * @dev_d : PCI device
  1058. *
  1059. * return value: 0, no error.
  1060. *
  1061. * other, could not set device to power on state.
  1062. */
  1063. static int __maybe_unused sta2x11_vip_resume(struct device *dev_d)
  1064. {
  1065. struct v4l2_device *v4l2_dev = dev_get_drvdata(dev_d);
  1066. struct sta2x11_vip *vip =
  1067. container_of(v4l2_dev, struct sta2x11_vip, v4l2_dev);
  1068. unsigned long flags;
  1069. int i;
  1070. pr_info("VIP: resume\n");
  1071. vip->disabled = 0;
  1072. spin_lock_irqsave(&vip->slock, flags);
  1073. for (i = 1; i < SAVE_COUNT; i++)
  1074. reg_write(vip, 4 * i, vip->register_save_area[i]);
  1075. for (i = 0; i < AUX_COUNT; i++)
  1076. reg_write(vip, registers_to_save[i],
  1077. vip->register_save_area[SAVE_COUNT + IRQ_COUNT + i]);
  1078. reg_write(vip, DVP_CTL, vip->register_save_area[0]);
  1079. reg_write(vip, DVP_ITM, vip->register_save_area[SAVE_COUNT]);
  1080. spin_unlock_irqrestore(&vip->slock, flags);
  1081. return 0;
  1082. }
  1083. static const struct pci_device_id sta2x11_vip_pci_tbl[] = {
  1084. {PCI_DEVICE(PCI_VENDOR_ID_STMICRO, PCI_DEVICE_ID_STMICRO_VIP)},
  1085. {0,}
  1086. };
  1087. static SIMPLE_DEV_PM_OPS(sta2x11_vip_pm_ops,
  1088. sta2x11_vip_suspend,
  1089. sta2x11_vip_resume);
  1090. static struct pci_driver sta2x11_vip_driver = {
  1091. .name = KBUILD_MODNAME,
  1092. .probe = sta2x11_vip_init_one,
  1093. .remove = sta2x11_vip_remove_one,
  1094. .id_table = sta2x11_vip_pci_tbl,
  1095. .driver.pm = &sta2x11_vip_pm_ops,
  1096. };
  1097. static int __init sta2x11_vip_init_module(void)
  1098. {
  1099. return pci_register_driver(&sta2x11_vip_driver);
  1100. }
  1101. static void __exit sta2x11_vip_exit_module(void)
  1102. {
  1103. pci_unregister_driver(&sta2x11_vip_driver);
  1104. }
  1105. #ifdef MODULE
  1106. module_init(sta2x11_vip_init_module);
  1107. module_exit(sta2x11_vip_exit_module);
  1108. #else
  1109. late_initcall_sync(sta2x11_vip_init_module);
  1110. #endif
  1111. MODULE_DESCRIPTION("STA2X11 Video Input Port driver");
  1112. MODULE_AUTHOR("Wind River");
  1113. MODULE_LICENSE("GPL v2");
  1114. MODULE_VERSION(DRV_VERSION);
  1115. MODULE_DEVICE_TABLE(pci, sta2x11_vip_pci_tbl);