aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFederico Vaga <federico.vaga@gmail.com>2013-02-05 12:34:37 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2013-02-06 11:17:17 -0500
commit8dc97ea20c2bdf406348640abbd35eb89c843957 (patch)
tree4c5b297803aae10a604996e09d422f1f38d0b2bf
parent5815d0c4d55a80310138698c9dc516c759b6be87 (diff)
[media] sta2x11_vip: convert to videobuf2, control framework, file handler
This patch re-write the driver and use the videobuf2 interface instead of the old videobuf. Moreover, it uses also the control framework which allows the driver to inherit controls from its subdevice (ADV7180). Finally the driver does not implement custom file operation but it uses the generic ones from videobuf2 and v4l2_fh Signed-off-by: Federico Vaga <federico.vaga@gmail.com> Acked-by: Giancarlo Asnaghi <giancarlo.asnaghi@st.com> Acked-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r--drivers/media/pci/sta2x11/Kconfig2
-rw-r--r--drivers/media/pci/sta2x11/sta2x11_vip.c1073
2 files changed, 434 insertions, 641 deletions
diff --git a/drivers/media/pci/sta2x11/Kconfig b/drivers/media/pci/sta2x11/Kconfig
index 6749f67cab8a..a94ccad02066 100644
--- a/drivers/media/pci/sta2x11/Kconfig
+++ b/drivers/media/pci/sta2x11/Kconfig
@@ -2,7 +2,7 @@ config STA2X11_VIP
2 tristate "STA2X11 VIP Video For Linux" 2 tristate "STA2X11 VIP Video For Linux"
3 depends on STA2X11 3 depends on STA2X11
4 select VIDEO_ADV7180 if MEDIA_SUBDRV_AUTOSELECT 4 select VIDEO_ADV7180 if MEDIA_SUBDRV_AUTOSELECT
5 select VIDEOBUF_DMA_CONTIG 5 select VIDEOBUF2_DMA_CONTIG
6 depends on PCI && VIDEO_V4L2 && VIRT_TO_BUS 6 depends on PCI && VIDEO_V4L2 && VIRT_TO_BUS
7 help 7 help
8 Say Y for support for STA2X11 VIP (Video Input Port) capture 8 Say Y for support for STA2X11 VIP (Video Input Port) capture
diff --git a/drivers/media/pci/sta2x11/sta2x11_vip.c b/drivers/media/pci/sta2x11/sta2x11_vip.c
index 1352e50e457b..4b703fe8c953 100644
--- a/drivers/media/pci/sta2x11/sta2x11_vip.c
+++ b/drivers/media/pci/sta2x11/sta2x11_vip.c
@@ -1,7 +1,11 @@
1/* 1/*
2 * This is the driver for the STA2x11 Video Input Port. 2 * This is the driver for the STA2x11 Video Input Port.
3 * 3 *
4 * Copyright (C) 2012 ST Microelectronics
5 * author: Federico Vaga <federico.vaga@gmail.com>
4 * Copyright (C) 2010 WindRiver Systems, Inc. 6 * Copyright (C) 2010 WindRiver Systems, Inc.
7 * authors: Andreas Kies <andreas.kies@windriver.com>
8 * Vlad Lungu <vlad.lungu@windriver.com>
5 * 9 *
6 * This program is free software; you can redistribute it and/or modify it 10 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License, 11 * under the terms and conditions of the GNU General Public License,
@@ -19,36 +23,30 @@
19 * The full GNU General Public License is included in this distribution in 23 * The full GNU General Public License is included in this distribution in
20 * the file called "COPYING". 24 * the file called "COPYING".
21 * 25 *
22 * Author: Andreas Kies <andreas.kies@windriver.com>
23 * Vlad Lungu <vlad.lungu@windriver.com>
24 *
25 */ 26 */
26 27
27#include <linux/types.h> 28#include <linux/types.h>
28#include <linux/kernel.h> 29#include <linux/kernel.h>
29#include <linux/module.h> 30#include <linux/module.h>
30#include <linux/init.h> 31#include <linux/init.h>
31#include <linux/vmalloc.h>
32
33#include <linux/videodev2.h> 32#include <linux/videodev2.h>
34
35#include <linux/kmod.h> 33#include <linux/kmod.h>
36
37#include <linux/pci.h> 34#include <linux/pci.h>
38#include <linux/interrupt.h> 35#include <linux/interrupt.h>
39#include <linux/mutex.h>
40#include <linux/io.h> 36#include <linux/io.h>
41#include <linux/gpio.h> 37#include <linux/gpio.h>
42#include <linux/i2c.h> 38#include <linux/i2c.h>
43#include <linux/delay.h> 39#include <linux/delay.h>
44#include <media/v4l2-common.h> 40#include <media/v4l2-common.h>
45#include <media/v4l2-device.h> 41#include <media/v4l2-device.h>
42#include <media/v4l2-ctrls.h>
46#include <media/v4l2-ioctl.h> 43#include <media/v4l2-ioctl.h>
47#include <media/videobuf-dma-contig.h> 44#include <media/v4l2-fh.h>
45#include <media/v4l2-event.h>
46#include <media/videobuf2-dma-contig.h>
48 47
49#include "sta2x11_vip.h" 48#include "sta2x11_vip.h"
50 49
51#define DRV_NAME "sta2x11_vip"
52#define DRV_VERSION "1.3" 50#define DRV_VERSION "1.3"
53 51
54#ifndef PCI_DEVICE_ID_STMICRO_VIP 52#ifndef PCI_DEVICE_ID_STMICRO_VIP
@@ -63,8 +61,8 @@
63#define DVP_TFS 0x08 61#define DVP_TFS 0x08
64#define DVP_BFO 0x0C 62#define DVP_BFO 0x0C
65#define DVP_BFS 0x10 63#define DVP_BFS 0x10
66#define DVP_VTP 0x14 64#define DVP_VTP 0x14
67#define DVP_VBP 0x18 65#define DVP_VBP 0x18
68#define DVP_VMP 0x1C 66#define DVP_VMP 0x1C
69#define DVP_ITM 0x98 67#define DVP_ITM 0x98
70#define DVP_ITS 0x9C 68#define DVP_ITS 0x9C
@@ -84,13 +82,21 @@
84 82
85#define DVP_HLFLN_SD 0x00000001 83#define DVP_HLFLN_SD 0x00000001
86 84
87#define REG_WRITE(vip, reg, value) iowrite32((value), (vip->iomem)+(reg))
88#define REG_READ(vip, reg) ioread32((vip->iomem)+(reg))
89
90#define SAVE_COUNT 8 85#define SAVE_COUNT 8
91#define AUX_COUNT 3 86#define AUX_COUNT 3
92#define IRQ_COUNT 1 87#define IRQ_COUNT 1
93 88
89
90struct vip_buffer {
91 struct vb2_buffer vb;
92 struct list_head list;
93 dma_addr_t dma;
94};
95static inline struct vip_buffer *to_vip_buffer(struct vb2_buffer *vb2)
96{
97 return container_of(vb2, struct vip_buffer, vb);
98}
99
94/** 100/**
95 * struct sta2x11_vip - All internal data for one instance of device 101 * struct sta2x11_vip - All internal data for one instance of device
96 * @v4l2_dev: device registered in v4l layer 102 * @v4l2_dev: device registered in v4l layer
@@ -99,29 +105,26 @@
99 * @adapter: contains I2C adapter information 105 * @adapter: contains I2C adapter information
100 * @register_save_area: All relevant register are saved here during suspend 106 * @register_save_area: All relevant register are saved here during suspend
101 * @decoder: contains information about video DAC 107 * @decoder: contains information about video DAC
108 * @ctrl_hdl: handler for control framework
102 * @format: pixel format, fixed UYVY 109 * @format: pixel format, fixed UYVY
103 * @std: video standard (e.g. PAL/NTSC) 110 * @std: video standard (e.g. PAL/NTSC)
104 * @input: input line for video signal ( 0 or 1 ) 111 * @input: input line for video signal ( 0 or 1 )
105 * @users: Number of open of device ( max. 1 )
106 * @disabled: Device is in power down state 112 * @disabled: Device is in power down state
107 * @mutex: ensures exclusive opening of device
108 * @slock: for excluse acces of registers 113 * @slock: for excluse acces of registers
109 * @vb_vidq: queue maintained by videobuf layer 114 * @alloc_ctx: context for videobuf2
110 * @capture: linked list of capture buffer 115 * @vb_vidq: queue maintained by videobuf2 layer
111 * @active: struct videobuf_buffer currently beingg filled 116 * @buffer_list: list of buffer in use
112 * @started: device is ready to capture frame 117 * @sequence: sequence number of acquired buffer
113 * @closing: device will be shut down 118 * @active: current active buffer
119 * @lock: used in videobuf2 callback
114 * @tcount: Number of top frames 120 * @tcount: Number of top frames
115 * @bcount: Number of bottom frames 121 * @bcount: Number of bottom frames
116 * @overflow: Number of FIFO overflows 122 * @overflow: Number of FIFO overflows
117 * @mem_spare: small buffer of unused frame
118 * @dma_spare: dma addres of mem_spare
119 * @iomem: hardware base address 123 * @iomem: hardware base address
120 * @config: I2C and gpio config from platform 124 * @config: I2C and gpio config from platform
121 * 125 *
122 * All non-local data is accessed via this structure. 126 * All non-local data is accessed via this structure.
123 */ 127 */
124
125struct sta2x11_vip { 128struct sta2x11_vip {
126 struct v4l2_device v4l2_dev; 129 struct v4l2_device v4l2_dev;
127 struct video_device *video_dev; 130 struct video_device *video_dev;
@@ -129,21 +132,27 @@ struct sta2x11_vip {
129 struct i2c_adapter *adapter; 132 struct i2c_adapter *adapter;
130 unsigned int register_save_area[IRQ_COUNT + SAVE_COUNT + AUX_COUNT]; 133 unsigned int register_save_area[IRQ_COUNT + SAVE_COUNT + AUX_COUNT];
131 struct v4l2_subdev *decoder; 134 struct v4l2_subdev *decoder;
135 struct v4l2_ctrl_handler ctrl_hdl;
136
137
132 struct v4l2_pix_format format; 138 struct v4l2_pix_format format;
133 v4l2_std_id std; 139 v4l2_std_id std;
134 unsigned int input; 140 unsigned int input;
135 int users;
136 int disabled; 141 int disabled;
137 struct mutex mutex; /* exclusive access during open */ 142 spinlock_t slock;
138 spinlock_t slock; /* spin lock for hardware and queue access */ 143
139 struct videobuf_queue vb_vidq; 144 struct vb2_alloc_ctx *alloc_ctx;
140 struct list_head capture; 145 struct vb2_queue vb_vidq;
141 struct videobuf_buffer *active; 146 struct list_head buffer_list;
142 int started, closing, tcount, bcount; 147 unsigned int sequence;
148 struct vip_buffer *active; /* current active buffer */
149 spinlock_t lock; /* Used in videobuf2 callback */
150
151 /* Interrupt counters */
152 int tcount, bcount;
143 int overflow; 153 int overflow;
144 void *mem_spare; 154
145 dma_addr_t dma_spare; 155 void *iomem; /* I/O Memory */
146 void *iomem;
147 struct vip_config *config; 156 struct vip_config *config;
148}; 157};
149 158
@@ -206,318 +215,195 @@ static struct v4l2_pix_format formats_60[] = {
206 .colorspace = V4L2_COLORSPACE_SMPTE170M}, 215 .colorspace = V4L2_COLORSPACE_SMPTE170M},
207}; 216};
208 217
209/** 218/* Write VIP register */
210 * buf_setup - Get size and number of video buffer 219static inline void reg_write(struct sta2x11_vip *vip, unsigned int reg, u32 val)
211 * @vq: queue in videobuf
212 * @count: Number of buffers (1..MAX_FRAMES).
213 * 0 use default value.
214 * @size: size of buffer in bytes
215 *
216 * returns size and number of buffers
217 * a preset value of 0 returns the default number.
218 * return value: 0, always succesfull.
219 */
220static int buf_setup(struct videobuf_queue *vq, unsigned int *count,
221 unsigned int *size)
222{ 220{
223 struct sta2x11_vip *vip = vq->priv_data; 221 iowrite32((val), (vip->iomem)+(reg));
224 222}
225 *size = vip->format.width * vip->format.height * 2; 223/* Read VIP register */
226 if (0 == *count || MAX_FRAMES < *count) 224static inline u32 reg_read(struct sta2x11_vip *vip, unsigned int reg)
227 *count = MAX_FRAMES;
228 return 0;
229};
230
231/**
232 * buf_prepare - prepare buffer for usage
233 * @vq: queue in videobuf layer
234 * @vb: buffer to be prepared
235 * @field: type of video data (interlaced/non-interlaced)
236 *
237 * Allocate or realloc buffer
238 * return value: 0, successful.
239 *
240 * -EINVAL, supplied buffer is too small.
241 *
242 * other, buffer could not be locked.
243 */
244static int buf_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
245 enum v4l2_field field)
246{ 225{
247 struct sta2x11_vip *vip = vq->priv_data; 226 return ioread32((vip->iomem)+(reg));
248 int ret;
249
250 vb->size = vip->format.width * vip->format.height * 2;
251 if ((0 != vb->baddr) && (vb->bsize < vb->size))
252 return -EINVAL;
253 vb->width = vip->format.width;
254 vb->height = vip->format.height;
255 vb->field = field;
256
257 if (VIDEOBUF_NEEDS_INIT == vb->state) {
258 ret = videobuf_iolock(vq, vb, NULL);
259 if (ret)
260 goto fail;
261 }
262 vb->state = VIDEOBUF_PREPARED;
263 return 0;
264fail:
265 videobuf_dma_contig_free(vq, vb);
266 vb->state = VIDEOBUF_NEEDS_INIT;
267 return ret;
268} 227}
269 228/* Start DMA acquisition */
270/** 229static void start_dma(struct sta2x11_vip *vip, struct vip_buffer *vip_buf)
271 * buf_queu - queue buffer for filling
272 * @vq: queue in videobuf layer
273 * @vb: buffer to be queued
274 *
275 * if capturing is already running, the buffer will be queued. Otherwise
276 * capture is started and the buffer is used directly.
277 */
278static void buf_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
279{ 230{
280 struct sta2x11_vip *vip = vq->priv_data; 231 unsigned long offset = 0;
281 u32 dma; 232
233 if (vip->format.field == V4L2_FIELD_INTERLACED)
234 offset = vip->format.width * 2;
282 235
283 vb->state = VIDEOBUF_QUEUED; 236 spin_lock_irq(&vip->slock);
237 /* Enable acquisition */
238 reg_write(vip, DVP_CTL, reg_read(vip, DVP_CTL) | DVP_CTL_ENA);
239 /* Set Top and Bottom Field memory address */
240 reg_write(vip, DVP_VTP, (u32)vip_buf->dma);
241 reg_write(vip, DVP_VBP, (u32)vip_buf->dma + offset);
242 spin_unlock_irq(&vip->slock);
243}
284 244
285 if (vip->active) { 245/* Fetch the next buffer to activate */
286 list_add_tail(&vb->queue, &vip->capture); 246static void vip_active_buf_next(struct sta2x11_vip *vip)
247{
248 /* Get the next buffer */
249 spin_lock(&vip->lock);
250 if (list_empty(&vip->buffer_list)) {/* No available buffer */
251 spin_unlock(&vip->lock);
287 return; 252 return;
288 } 253 }
289 254 vip->active = list_first_entry(&vip->buffer_list,
290 vip->started = 1; 255 struct vip_buffer,
256 list);
257 /* Reset Top and Bottom counter */
291 vip->tcount = 0; 258 vip->tcount = 0;
292 vip->bcount = 0; 259 vip->bcount = 0;
293 vip->active = vb; 260 spin_unlock(&vip->lock);
294 vb->state = VIDEOBUF_ACTIVE; 261 if (vb2_is_streaming(&vip->vb_vidq)) { /* streaming is on */
262 start_dma(vip, vip->active); /* start dma capture */
263 }
264}
295 265
296 dma = videobuf_to_dma_contig(vb);
297 266
298 REG_WRITE(vip, DVP_TFO, (0 << 16) | (0)); 267/* Videobuf2 Operations */
299 /* despite of interlace mode, upper and lower frames start at zero */ 268static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
300 REG_WRITE(vip, DVP_BFO, (0 << 16) | (0)); 269 unsigned int *nbuffers, unsigned int *nplanes,
270 unsigned int sizes[], void *alloc_ctxs[])
271{
272 struct sta2x11_vip *vip = vb2_get_drv_priv(vq);
301 273
302 switch (vip->format.field) { 274 if (!(*nbuffers) || *nbuffers < MAX_FRAMES)
303 case V4L2_FIELD_INTERLACED: 275 *nbuffers = MAX_FRAMES;
304 REG_WRITE(vip, DVP_TFS,
305 ((vip->format.height / 2 - 1) << 16) |
306 (2 * vip->format.width - 1));
307 REG_WRITE(vip, DVP_BFS, ((vip->format.height / 2 - 1) << 16) |
308 (2 * vip->format.width - 1));
309 REG_WRITE(vip, DVP_VTP, dma);
310 REG_WRITE(vip, DVP_VBP, dma + vip->format.width * 2);
311 REG_WRITE(vip, DVP_VMP, 4 * vip->format.width);
312 break;
313 case V4L2_FIELD_TOP:
314 REG_WRITE(vip, DVP_TFS,
315 ((vip->format.height - 1) << 16) |
316 (2 * vip->format.width - 1));
317 REG_WRITE(vip, DVP_BFS, ((0) << 16) |
318 (2 * vip->format.width - 1));
319 REG_WRITE(vip, DVP_VTP, dma);
320 REG_WRITE(vip, DVP_VBP, dma);
321 REG_WRITE(vip, DVP_VMP, 2 * vip->format.width);
322 break;
323 case V4L2_FIELD_BOTTOM:
324 REG_WRITE(vip, DVP_TFS, ((0) << 16) |
325 (2 * vip->format.width - 1));
326 REG_WRITE(vip, DVP_BFS,
327 ((vip->format.height) << 16) |
328 (2 * vip->format.width - 1));
329 REG_WRITE(vip, DVP_VTP, dma);
330 REG_WRITE(vip, DVP_VBP, dma);
331 REG_WRITE(vip, DVP_VMP, 2 * vip->format.width);
332 break;
333 276
334 default: 277 *nplanes = 1;
335 pr_warning("VIP: unknown field format\n"); 278 sizes[0] = vip->format.sizeimage;
336 return; 279 alloc_ctxs[0] = vip->alloc_ctx;
337 }
338 280
339 REG_WRITE(vip, DVP_CTL, DVP_CTL_ENA); 281 vip->sequence = 0;
340} 282 vip->active = NULL;
283 vip->tcount = 0;
284 vip->bcount = 0;
341 285
342/** 286 return 0;
343 * buff_release - release buffer 287};
344 * @vq: queue in videobuf layer 288static int buffer_init(struct vb2_buffer *vb)
345 * @vb: buffer to be released
346 *
347 * release buffer in videobuf layer
348 */
349static void buf_release(struct videobuf_queue *vq, struct videobuf_buffer *vb)
350{ 289{
290 struct vip_buffer *vip_buf = to_vip_buffer(vb);
351 291
352 videobuf_dma_contig_free(vq, vb); 292 vip_buf->dma = vb2_dma_contig_plane_dma_addr(vb, 0);
353 vb->state = VIDEOBUF_NEEDS_INIT; 293 INIT_LIST_HEAD(&vip_buf->list);
294 return 0;
354} 295}
355 296
356static struct videobuf_queue_ops vip_qops = { 297static int buffer_prepare(struct vb2_buffer *vb)
357 .buf_setup = buf_setup,
358 .buf_prepare = buf_prepare,
359 .buf_queue = buf_queue,
360 .buf_release = buf_release,
361};
362
363/**
364 * vip_open - open video device
365 * @file: descriptor of device
366 *
367 * open device, make sure it is only opened once.
368 * return value: 0, no error.
369 *
370 * -EBUSY, device is already opened
371 *
372 * -ENOMEM, no memory for auxiliary DMA buffer
373 */
374static int vip_open(struct file *file)
375{ 298{
376 struct video_device *dev = video_devdata(file); 299 struct sta2x11_vip *vip = vb2_get_drv_priv(vb->vb2_queue);
377 struct sta2x11_vip *vip = video_get_drvdata(dev); 300 struct vip_buffer *vip_buf = to_vip_buffer(vb);
301 unsigned long size;
302
303 size = vip->format.sizeimage;
304 if (vb2_plane_size(vb, 0) < size) {
305 v4l2_err(&vip->v4l2_dev, "buffer too small (%lu < %lu)\n",
306 vb2_plane_size(vb, 0), size);
307 return -EINVAL;
308 }
378 309
379 mutex_lock(&vip->mutex); 310 vb2_set_plane_payload(&vip_buf->vb, 0, size);
380 vip->users++;
381 311
382 if (vip->users > 1) { 312 return 0;
383 vip->users--; 313}
384 mutex_unlock(&vip->mutex); 314static void buffer_queue(struct vb2_buffer *vb)
385 return -EBUSY; 315{
316 struct sta2x11_vip *vip = vb2_get_drv_priv(vb->vb2_queue);
317 struct vip_buffer *vip_buf = to_vip_buffer(vb);
318
319 spin_lock(&vip->lock);
320 list_add_tail(&vip_buf->list, &vip->buffer_list);
321 if (!vip->active) { /* No active buffer, active the first one */
322 vip->active = list_first_entry(&vip->buffer_list,
323 struct vip_buffer,
324 list);
325 if (vb2_is_streaming(&vip->vb_vidq)) /* streaming is on */
326 start_dma(vip, vip_buf); /* start dma capture */
386 } 327 }
328 spin_unlock(&vip->lock);
329}
330static int buffer_finish(struct vb2_buffer *vb)
331{
332 struct sta2x11_vip *vip = vb2_get_drv_priv(vb->vb2_queue);
333 struct vip_buffer *vip_buf = to_vip_buffer(vb);
387 334
388 file->private_data = dev; 335 /* Buffer handled, remove it from the list */
389 vip->overflow = 0; 336 spin_lock(&vip->lock);
390 vip->started = 0; 337 list_del_init(&vip_buf->list);
391 vip->closing = 0; 338 spin_unlock(&vip->lock);
392 vip->active = NULL;
393 339
394 INIT_LIST_HEAD(&vip->capture); 340 vip_active_buf_next(vip);
395 vip->mem_spare = dma_alloc_coherent(&vip->pdev->dev, 64,
396 &vip->dma_spare, GFP_KERNEL);
397 if (!vip->mem_spare) {
398 vip->users--;
399 mutex_unlock(&vip->mutex);
400 return -ENOMEM;
401 }
402 341
403 mutex_unlock(&vip->mutex);
404 videobuf_queue_dma_contig_init_cached(&vip->vb_vidq,
405 &vip_qops,
406 &vip->pdev->dev,
407 &vip->slock,
408 V4L2_BUF_TYPE_VIDEO_CAPTURE,
409 V4L2_FIELD_INTERLACED,
410 sizeof(struct videobuf_buffer),
411 vip, NULL);
412 REG_READ(vip, DVP_ITS);
413 REG_WRITE(vip, DVP_HLFLN, DVP_HLFLN_SD);
414 REG_WRITE(vip, DVP_ITM, DVP_IT_VSB | DVP_IT_VST);
415 REG_WRITE(vip, DVP_CTL, DVP_CTL_RST);
416 REG_WRITE(vip, DVP_CTL, 0);
417 REG_READ(vip, DVP_ITS);
418 return 0; 342 return 0;
419} 343}
420 344
421/** 345static int start_streaming(struct vb2_queue *vq, unsigned int count)
422 * vip_close - close video device
423 * @file: descriptor of device
424 *
425 * close video device, wait until all pending operations are finished
426 * ( maximum FRAME_MAX buffers pending )
427 * Turn off interrupts.
428 *
429 * return value: 0, always succesful.
430 */
431static int vip_close(struct file *file)
432{ 346{
433 struct video_device *dev = video_devdata(file); 347 struct sta2x11_vip *vip = vb2_get_drv_priv(vq);
434 struct sta2x11_vip *vip = video_get_drvdata(dev);
435 348
436 vip->closing = 1;
437 if (vip->active)
438 videobuf_waiton(&vip->vb_vidq, vip->active, 0, 0);
439 spin_lock_irq(&vip->slock); 349 spin_lock_irq(&vip->slock);
440 350 /* Enable interrupt VSYNC Top and Bottom*/
441 REG_WRITE(vip, DVP_ITM, 0); 351 reg_write(vip, DVP_ITM, DVP_IT_VSB | DVP_IT_VST);
442 REG_WRITE(vip, DVP_CTL, DVP_CTL_RST);
443 REG_WRITE(vip, DVP_CTL, 0);
444 REG_READ(vip, DVP_ITS);
445
446 vip->started = 0;
447 vip->active = NULL;
448
449 spin_unlock_irq(&vip->slock); 352 spin_unlock_irq(&vip->slock);
450 353
451 videobuf_stop(&vip->vb_vidq); 354 if (count)
452 videobuf_mmap_free(&vip->vb_vidq); 355 start_dma(vip, vip->active);
453 356
454 dma_free_coherent(&vip->pdev->dev, 64, vip->mem_spare, vip->dma_spare);
455 file->private_data = NULL;
456 mutex_lock(&vip->mutex);
457 vip->users--;
458 mutex_unlock(&vip->mutex);
459 return 0; 357 return 0;
460} 358}
461 359
462/** 360/* abort streaming and wait for last buffer */
463 * vip_read - read from video input 361static int stop_streaming(struct vb2_queue *vq)
464 * @file: descriptor of device
465 * @data: user buffer
466 * @count: number of bytes to be read
467 * @ppos: position within stream
468 *
469 * read video data from video device.
470 * handling is done in generic videobuf layer
471 * return value: provided by videobuf layer
472 */
473static ssize_t vip_read(struct file *file, char __user *data,
474 size_t count, loff_t *ppos)
475{ 362{
476 struct video_device *dev = file->private_data; 363 struct sta2x11_vip *vip = vb2_get_drv_priv(vq);
477 struct sta2x11_vip *vip = video_get_drvdata(dev); 364 struct vip_buffer *vip_buf, *node;
478 365
479 return videobuf_read_stream(&vip->vb_vidq, data, count, ppos, 0, 366 /* Disable acquisition */
480 file->f_flags & O_NONBLOCK); 367 reg_write(vip, DVP_CTL, reg_read(vip, DVP_CTL) & ~DVP_CTL_ENA);
368 /* Disable all interrupts */
369 reg_write(vip, DVP_ITM, 0);
370
371 /* Release all active buffers */
372 spin_lock(&vip->lock);
373 list_for_each_entry_safe(vip_buf, node, &vip->buffer_list, list) {
374 vb2_buffer_done(&vip_buf->vb, VB2_BUF_STATE_ERROR);
375 list_del(&vip_buf->list);
376 }
377 spin_unlock(&vip->lock);
378 return 0;
481} 379}
482 380
483/** 381static struct vb2_ops vip_video_qops = {
484 * vip_mmap - map user buffer 382 .queue_setup = queue_setup,
485 * @file: descriptor of device 383 .buf_init = buffer_init,
486 * @vma: user buffer 384 .buf_prepare = buffer_prepare,
487 * 385 .buf_finish = buffer_finish,
488 * map user space buffer into kernel mode, including DMA address. 386 .buf_queue = buffer_queue,
489 * handling is done in generic videobuf layer. 387 .start_streaming = start_streaming,
490 * return value: provided by videobuf layer 388 .stop_streaming = stop_streaming,
491 */ 389};
492static int vip_mmap(struct file *file, struct vm_area_struct *vma)
493{
494 struct video_device *dev = file->private_data;
495 struct sta2x11_vip *vip = video_get_drvdata(dev);
496 390
497 return videobuf_mmap_mapper(&vip->vb_vidq, vma);
498}
499 391
500/** 392/* File Operations */
501 * vip_poll - poll for event 393static const struct v4l2_file_operations vip_fops = {
502 * @file: descriptor of device 394 .owner = THIS_MODULE,
503 * @wait: contains events to be waited for 395 .open = v4l2_fh_open,
504 * 396 .release = vb2_fop_release,
505 * wait for event related to video device. 397 .unlocked_ioctl = video_ioctl2,
506 * handling is done in generic videobuf layer. 398 .read = vb2_fop_read,
507 * return value: provided by videobuf layer 399 .mmap = vb2_fop_mmap,
508 */ 400 .poll = vb2_fop_poll
509static unsigned int vip_poll(struct file *file, struct poll_table_struct *wait) 401};
510{
511 struct video_device *dev = file->private_data;
512 struct sta2x11_vip *vip = video_get_drvdata(dev);
513 402
514 return videobuf_poll_stream(file, &vip->vb_vidq, wait);
515}
516 403
517/** 404/**
518 * vidioc_querycap - return capabilities of device 405 * vidioc_querycap - return capabilities of device
519 * @file: descriptor of device (not used) 406 * @file: descriptor of device
520 * @priv: points to current videodevice
521 * @cap: contains return values 407 * @cap: contains return values
522 * 408 *
523 * the capabilities of the device are returned 409 * the capabilities of the device are returned
@@ -527,25 +413,22 @@ static unsigned int vip_poll(struct file *file, struct poll_table_struct *wait)
527static int vidioc_querycap(struct file *file, void *priv, 413static int vidioc_querycap(struct file *file, void *priv,
528 struct v4l2_capability *cap) 414 struct v4l2_capability *cap)
529{ 415{
530 struct video_device *dev = priv; 416 struct sta2x11_vip *vip = video_drvdata(file);
531 struct sta2x11_vip *vip = video_get_drvdata(dev);
532 417
533 memset(cap, 0, sizeof(struct v4l2_capability)); 418 strcpy(cap->driver, KBUILD_MODNAME);
534 strcpy(cap->driver, DRV_NAME); 419 strcpy(cap->card, KBUILD_MODNAME);
535 strcpy(cap->card, DRV_NAME);
536 cap->version = 0;
537 snprintf(cap->bus_info, sizeof(cap->bus_info), "PCI:%s", 420 snprintf(cap->bus_info, sizeof(cap->bus_info), "PCI:%s",
538 pci_name(vip->pdev)); 421 pci_name(vip->pdev));
539 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE | 422 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE |
540 V4L2_CAP_STREAMING; 423 V4L2_CAP_STREAMING;
424 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
541 425
542 return 0; 426 return 0;
543} 427}
544 428
545/** 429/**
546 * vidioc_s_std - set video standard 430 * vidioc_s_std - set video standard
547 * @file: descriptor of device (not used) 431 * @file: descriptor of device
548 * @priv: points to current videodevice
549 * @std: contains standard to be set 432 * @std: contains standard to be set
550 * 433 *
551 * the video standard is set 434 * the video standard is set
@@ -558,8 +441,7 @@ static int vidioc_querycap(struct file *file, void *priv,
558 */ 441 */
559static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *std) 442static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *std)
560{ 443{
561 struct video_device *dev = priv; 444 struct sta2x11_vip *vip = video_drvdata(file);
562 struct sta2x11_vip *vip = video_get_drvdata(dev);
563 v4l2_std_id oldstd = vip->std, newstd; 445 v4l2_std_id oldstd = vip->std, newstd;
564 int status; 446 int status;
565 447
@@ -592,8 +474,7 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *std)
592 474
593/** 475/**
594 * vidioc_g_std - get video standard 476 * vidioc_g_std - get video standard
595 * @file: descriptor of device (not used) 477 * @file: descriptor of device
596 * @priv: points to current videodevice
597 * @std: contains return values 478 * @std: contains return values
598 * 479 *
599 * the current video standard is returned 480 * the current video standard is returned
@@ -602,8 +483,7 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *std)
602 */ 483 */
603static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *std) 484static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *std)
604{ 485{
605 struct video_device *dev = priv; 486 struct sta2x11_vip *vip = video_drvdata(file);
606 struct sta2x11_vip *vip = video_get_drvdata(dev);
607 487
608 *std = vip->std; 488 *std = vip->std;
609 return 0; 489 return 0;
@@ -611,8 +491,7 @@ static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *std)
611 491
612/** 492/**
613 * vidioc_querystd - get possible video standards 493 * vidioc_querystd - get possible video standards
614 * @file: descriptor of device (not used) 494 * @file: descriptor of device
615 * @priv: points to current videodevice
616 * @std: contains return values 495 * @std: contains return values
617 * 496 *
618 * all possible video standards are returned 497 * all possible video standards are returned
@@ -621,79 +500,11 @@ static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *std)
621 */ 500 */
622static int vidioc_querystd(struct file *file, void *priv, v4l2_std_id *std) 501static int vidioc_querystd(struct file *file, void *priv, v4l2_std_id *std)
623{ 502{
624 struct video_device *dev = priv; 503 struct sta2x11_vip *vip = video_drvdata(file);
625 struct sta2x11_vip *vip = video_get_drvdata(dev);
626 504
627 return v4l2_subdev_call(vip->decoder, video, querystd, std); 505 return v4l2_subdev_call(vip->decoder, video, querystd, std);
628
629} 506}
630 507
631/**
632 * vidioc_queryctl - get possible control settings
633 * @file: descriptor of device (not used)
634 * @priv: points to current videodevice
635 * @ctrl: contains return values
636 *
637 * return possible values for a control
638 * return value: delivered by video DAC routine.
639 */
640static int vidioc_queryctrl(struct file *file, void *priv,
641 struct v4l2_queryctrl *ctrl)
642{
643 struct video_device *dev = priv;
644 struct sta2x11_vip *vip = video_get_drvdata(dev);
645
646 return v4l2_subdev_call(vip->decoder, core, queryctrl, ctrl);
647}
648
649/**
650 * vidioc_g_ctl - get control value
651 * @file: descriptor of device (not used)
652 * @priv: points to current videodevice
653 * @ctrl: contains return values
654 *
655 * return setting for a control value
656 * return value: delivered by video DAC routine.
657 */
658static int vidioc_g_ctrl(struct file *file, void *priv,
659 struct v4l2_control *ctrl)
660{
661 struct video_device *dev = priv;
662 struct sta2x11_vip *vip = video_get_drvdata(dev);
663
664 return v4l2_subdev_call(vip->decoder, core, g_ctrl, ctrl);
665}
666
667/**
668 * vidioc_s_ctl - set control value
669 * @file: descriptor of device (not used)
670 * @priv: points to current videodevice
671 * @ctrl: contains value to be set
672 *
673 * set value for a specific control
674 * return value: delivered by video DAC routine.
675 */
676static int vidioc_s_ctrl(struct file *file, void *priv,
677 struct v4l2_control *ctrl)
678{
679 struct video_device *dev = priv;
680 struct sta2x11_vip *vip = video_get_drvdata(dev);
681
682 return v4l2_subdev_call(vip->decoder, core, s_ctrl, ctrl);
683}
684
685/**
686 * vidioc_enum_input - return name of input line
687 * @file: descriptor of device (not used)
688 * @priv: points to current videodevice
689 * @inp: contains return values
690 *
691 * the user friendly name of the input line is returned
692 *
693 * return value: 0, no error.
694 *
695 * -EINVAL, input line number out of range
696 */
697static int vidioc_enum_input(struct file *file, void *priv, 508static int vidioc_enum_input(struct file *file, void *priv,
698 struct v4l2_input *inp) 509 struct v4l2_input *inp)
699{ 510{
@@ -709,8 +520,7 @@ static int vidioc_enum_input(struct file *file, void *priv,
709 520
710/** 521/**
711 * vidioc_s_input - set input line 522 * vidioc_s_input - set input line
712 * @file: descriptor of device ( not used) 523 * @file: descriptor of device
713 * @priv: points to current videodevice
714 * @i: new input line number 524 * @i: new input line number
715 * 525 *
716 * the current active input line is set 526 * the current active input line is set
@@ -721,8 +531,7 @@ static int vidioc_enum_input(struct file *file, void *priv,
721 */ 531 */
722static int vidioc_s_input(struct file *file, void *priv, unsigned int i) 532static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
723{ 533{
724 struct video_device *dev = priv; 534 struct sta2x11_vip *vip = video_drvdata(file);
725 struct sta2x11_vip *vip = video_get_drvdata(dev);
726 int ret; 535 int ret;
727 536
728 if (i > 1) 537 if (i > 1)
@@ -737,8 +546,7 @@ static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
737 546
738/** 547/**
739 * vidioc_g_input - return input line 548 * vidioc_g_input - return input line
740 * @file: descriptor of device ( not used) 549 * @file: descriptor of device
741 * @priv: points to current videodevice
742 * @i: returned input line number 550 * @i: returned input line number
743 * 551 *
744 * the current active input line is returned 552 * the current active input line is returned
@@ -747,8 +555,7 @@ static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
747 */ 555 */
748static int vidioc_g_input(struct file *file, void *priv, unsigned int *i) 556static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
749{ 557{
750 struct video_device *dev = priv; 558 struct sta2x11_vip *vip = video_drvdata(file);
751 struct sta2x11_vip *vip = video_get_drvdata(dev);
752 559
753 *i = vip->input; 560 *i = vip->input;
754 return 0; 561 return 0;
@@ -756,8 +563,6 @@ static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
756 563
757/** 564/**
758 * vidioc_enum_fmt_vid_cap - return video capture format 565 * vidioc_enum_fmt_vid_cap - return video capture format
759 * @file: descriptor of device ( not used)
760 * @priv: points to current videodevice
761 * @f: returned format information 566 * @f: returned format information
762 * 567 *
763 * returns name and format of video capture 568 * returns name and format of video capture
@@ -780,8 +585,7 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
780 585
781/** 586/**
782 * vidioc_try_fmt_vid_cap - set video capture format 587 * vidioc_try_fmt_vid_cap - set video capture format
783 * @file: descriptor of device ( not used) 588 * @file: descriptor of device
784 * @priv: points to current videodevice
785 * @f: new format 589 * @f: new format
786 * 590 *
787 * new video format is set which includes width and 591 * new video format is set which includes width and
@@ -797,12 +601,13 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
797static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, 601static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
798 struct v4l2_format *f) 602 struct v4l2_format *f)
799{ 603{
800 struct video_device *dev = priv; 604 struct sta2x11_vip *vip = video_drvdata(file);
801 struct sta2x11_vip *vip = video_get_drvdata(dev);
802 int interlace_lim; 605 int interlace_lim;
803 606
804 if (V4L2_PIX_FMT_UYVY != f->fmt.pix.pixelformat) 607 if (V4L2_PIX_FMT_UYVY != f->fmt.pix.pixelformat) {
608 v4l2_warn(&vip->v4l2_dev, "Invalid format, only UYVY supported\n");
805 return -EINVAL; 609 return -EINVAL;
610 }
806 611
807 if (V4L2_STD_525_60 & vip->std) 612 if (V4L2_STD_525_60 & vip->std)
808 interlace_lim = 240; 613 interlace_lim = 240;
@@ -810,6 +615,7 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
810 interlace_lim = 288; 615 interlace_lim = 288;
811 616
812 switch (f->fmt.pix.field) { 617 switch (f->fmt.pix.field) {
618 default:
813 case V4L2_FIELD_ANY: 619 case V4L2_FIELD_ANY:
814 if (interlace_lim < f->fmt.pix.height) 620 if (interlace_lim < f->fmt.pix.height)
815 f->fmt.pix.field = V4L2_FIELD_INTERLACED; 621 f->fmt.pix.field = V4L2_FIELD_INTERLACED;
@@ -823,10 +629,10 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
823 break; 629 break;
824 case V4L2_FIELD_INTERLACED: 630 case V4L2_FIELD_INTERLACED:
825 break; 631 break;
826 default:
827 return -EINVAL;
828 } 632 }
829 633
634 /* It is the only supported format */
635 f->fmt.pix.pixelformat = V4L2_PIX_FMT_UYVY;
830 f->fmt.pix.height &= ~1; 636 f->fmt.pix.height &= ~1;
831 if (2 * interlace_lim < f->fmt.pix.height) 637 if (2 * interlace_lim < f->fmt.pix.height)
832 f->fmt.pix.height = 2 * interlace_lim; 638 f->fmt.pix.height = 2 * interlace_lim;
@@ -842,8 +648,7 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
842 648
843/** 649/**
844 * vidioc_s_fmt_vid_cap - set current video format parameters 650 * vidioc_s_fmt_vid_cap - set current video format parameters
845 * @file: descriptor of device ( not used) 651 * @file: descriptor of device
846 * @priv: points to current videodevice
847 * @f: returned format information 652 * @f: returned format information
848 * 653 *
849 * set new capture format 654 * set new capture format
@@ -854,22 +659,63 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
854static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, 659static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
855 struct v4l2_format *f) 660 struct v4l2_format *f)
856{ 661{
857 struct video_device *dev = priv; 662 struct sta2x11_vip *vip = video_drvdata(file);
858 struct sta2x11_vip *vip = video_get_drvdata(dev); 663 unsigned int t_stop, b_stop, pitch;
859 int ret; 664 int ret;
860 665
861 ret = vidioc_try_fmt_vid_cap(file, priv, f); 666 ret = vidioc_try_fmt_vid_cap(file, priv, f);
862 if (ret) 667 if (ret)
863 return ret; 668 return ret;
864 669
865 memcpy(&vip->format, &f->fmt.pix, sizeof(struct v4l2_pix_format)); 670 if (vb2_is_busy(&vip->vb_vidq)) {
671 /* Can't change format during acquisition */
672 v4l2_err(&vip->v4l2_dev, "device busy\n");
673 return -EBUSY;
674 }
675 vip->format = f->fmt.pix;
676 switch (vip->format.field) {
677 case V4L2_FIELD_INTERLACED:
678 t_stop = ((vip->format.height / 2 - 1) << 16) |
679 (2 * vip->format.width - 1);
680 b_stop = t_stop;
681 pitch = 4 * vip->format.width;
682 break;
683 case V4L2_FIELD_TOP:
684 t_stop = ((vip->format.height - 1) << 16) |
685 (2 * vip->format.width - 1);
686 b_stop = (0 << 16) | (2 * vip->format.width - 1);
687 pitch = 2 * vip->format.width;
688 break;
689 case V4L2_FIELD_BOTTOM:
690 t_stop = (0 << 16) | (2 * vip->format.width - 1);
691 b_stop = (vip->format.height << 16) |
692 (2 * vip->format.width - 1);
693 pitch = 2 * vip->format.width;
694 break;
695 default:
696 v4l2_err(&vip->v4l2_dev, "unknown field format\n");
697 return -EINVAL;
698 }
699
700 spin_lock_irq(&vip->slock);
701 /* Y-X Top Field Offset */
702 reg_write(vip, DVP_TFO, 0);
703 /* Y-X Bottom Field Offset */
704 reg_write(vip, DVP_BFO, 0);
705 /* Y-X Top Field Stop*/
706 reg_write(vip, DVP_TFS, t_stop);
707 /* Y-X Bottom Field Stop */
708 reg_write(vip, DVP_BFS, b_stop);
709 /* Video Memory Pitch */
710 reg_write(vip, DVP_VMP, pitch);
711 spin_unlock_irq(&vip->slock);
712
866 return 0; 713 return 0;
867} 714}
868 715
869/** 716/**
870 * vidioc_g_fmt_vid_cap - get current video format parameters 717 * vidioc_g_fmt_vid_cap - get current video format parameters
871 * @file: descriptor of device ( not used) 718 * @file: descriptor of device
872 * @priv: points to current videodevice
873 * @f: contains format information 719 * @f: contains format information
874 * 720 *
875 * returns current video format parameters 721 * returns current video format parameters
@@ -879,150 +725,47 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
879static int vidioc_g_fmt_vid_cap(struct file *file, void *priv, 725static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
880 struct v4l2_format *f) 726 struct v4l2_format *f)
881{ 727{
882 struct video_device *dev = priv; 728 struct sta2x11_vip *vip = video_drvdata(file);
883 struct sta2x11_vip *vip = video_get_drvdata(dev);
884
885 memcpy(&f->fmt.pix, &vip->format, sizeof(struct v4l2_pix_format));
886 return 0;
887}
888
889/**
890 * vidioc_reqfs - request buffer
891 * @file: descriptor of device ( not used)
892 * @priv: points to current videodevice
893 * @p: video buffer
894 *
895 * Handling is done in generic videobuf layer.
896 */
897static int vidioc_reqbufs(struct file *file, void *priv,
898 struct v4l2_requestbuffers *p)
899{
900 struct video_device *dev = priv;
901 struct sta2x11_vip *vip = video_get_drvdata(dev);
902
903 return videobuf_reqbufs(&vip->vb_vidq, p);
904}
905
906/**
907 * vidioc_querybuf - query buffer
908 * @file: descriptor of device ( not used)
909 * @priv: points to current videodevice
910 * @p: video buffer
911 *
912 * query buffer state.
913 * Handling is done in generic videobuf layer.
914 */
915static int vidioc_querybuf(struct file *file, void *priv, struct v4l2_buffer *p)
916{
917 struct video_device *dev = priv;
918 struct sta2x11_vip *vip = video_get_drvdata(dev);
919 729
920 return videobuf_querybuf(&vip->vb_vidq, p); 730 f->fmt.pix = vip->format;
921}
922 731
923/** 732 return 0;
924 * vidioc_qbuf - queue a buffer
925 * @file: descriptor of device ( not used)
926 * @priv: points to current videodevice
927 * @p: video buffer
928 *
929 * Handling is done in generic videobuf layer.
930 */
931static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *p)
932{
933 struct video_device *dev = priv;
934 struct sta2x11_vip *vip = video_get_drvdata(dev);
935
936 return videobuf_qbuf(&vip->vb_vidq, p);
937}
938
939/**
940 * vidioc_dqbuf - dequeue a buffer
941 * @file: descriptor of device ( not used)
942 * @priv: points to current videodevice
943 * @p: video buffer
944 *
945 * Handling is done in generic videobuf layer.
946 */
947static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
948{
949 struct video_device *dev = priv;
950 struct sta2x11_vip *vip = video_get_drvdata(dev);
951
952 return videobuf_dqbuf(&vip->vb_vidq, p, file->f_flags & O_NONBLOCK);
953}
954
955/**
956 * vidioc_streamon - turn on streaming
957 * @file: descriptor of device ( not used)
958 * @priv: points to current videodevice
959 * @type: type of capture
960 *
961 * turn on streaming.
962 * Handling is done in generic videobuf layer.
963 */
964static int vidioc_streamon(struct file *file, void *priv,
965 enum v4l2_buf_type type)
966{
967 struct video_device *dev = priv;
968 struct sta2x11_vip *vip = video_get_drvdata(dev);
969
970 return videobuf_streamon(&vip->vb_vidq);
971}
972
973/**
974 * vidioc_streamoff - turn off streaming
975 * @file: descriptor of device ( not used)
976 * @priv: points to current videodevice
977 * @type: type of capture
978 *
979 * turn off streaming.
980 * Handling is done in generic videobuf layer.
981 */
982static int vidioc_streamoff(struct file *file, void *priv,
983 enum v4l2_buf_type type)
984{
985 struct video_device *dev = priv;
986 struct sta2x11_vip *vip = video_get_drvdata(dev);
987
988 return videobuf_streamoff(&vip->vb_vidq);
989} 733}
990 734
991static const struct v4l2_file_operations vip_fops = {
992 .owner = THIS_MODULE,
993 .open = vip_open,
994 .release = vip_close,
995 .ioctl = video_ioctl2,
996 .read = vip_read,
997 .mmap = vip_mmap,
998 .poll = vip_poll
999};
1000
1001static const struct v4l2_ioctl_ops vip_ioctl_ops = { 735static const struct v4l2_ioctl_ops vip_ioctl_ops = {
1002 .vidioc_querycap = vidioc_querycap, 736 .vidioc_querycap = vidioc_querycap,
1003 .vidioc_s_std = vidioc_s_std, 737 /* FMT handling */
738 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
739 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
740 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
741 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
742 /* Buffer handlers */
743 .vidioc_create_bufs = vb2_ioctl_create_bufs,
744 .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
745 .vidioc_reqbufs = vb2_ioctl_reqbufs,
746 .vidioc_querybuf = vb2_ioctl_querybuf,
747 .vidioc_qbuf = vb2_ioctl_qbuf,
748 .vidioc_dqbuf = vb2_ioctl_dqbuf,
749 /* Stream on/off */
750 .vidioc_streamon = vb2_ioctl_streamon,
751 .vidioc_streamoff = vb2_ioctl_streamoff,
752 /* Standard handling */
1004 .vidioc_g_std = vidioc_g_std, 753 .vidioc_g_std = vidioc_g_std,
754 .vidioc_s_std = vidioc_s_std,
1005 .vidioc_querystd = vidioc_querystd, 755 .vidioc_querystd = vidioc_querystd,
1006 .vidioc_queryctrl = vidioc_queryctrl, 756 /* Input handling */
1007 .vidioc_g_ctrl = vidioc_g_ctrl,
1008 .vidioc_s_ctrl = vidioc_s_ctrl,
1009 .vidioc_enum_input = vidioc_enum_input, 757 .vidioc_enum_input = vidioc_enum_input,
1010 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
1011 .vidioc_s_input = vidioc_s_input,
1012 .vidioc_g_input = vidioc_g_input, 758 .vidioc_g_input = vidioc_g_input,
1013 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, 759 .vidioc_s_input = vidioc_s_input,
1014 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, 760 /* Log status ioctl */
1015 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, 761 .vidioc_log_status = v4l2_ctrl_log_status,
1016 .vidioc_reqbufs = vidioc_reqbufs, 762 /* Event handling */
1017 .vidioc_querybuf = vidioc_querybuf, 763 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1018 .vidioc_qbuf = vidioc_qbuf, 764 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1019 .vidioc_dqbuf = vidioc_dqbuf,
1020 .vidioc_streamon = vidioc_streamon,
1021 .vidioc_streamoff = vidioc_streamoff,
1022}; 765};
1023 766
1024static struct video_device video_dev_template = { 767static struct video_device video_dev_template = {
1025 .name = DRV_NAME, 768 .name = KBUILD_MODNAME,
1026 .release = video_device_release, 769 .release = video_device_release,
1027 .fops = &vip_fops, 770 .fops = &vip_fops,
1028 .ioctl_ops = &vip_ioctl_ops, 771 .ioctl_ops = &vip_ioctl_ops,
@@ -1036,9 +779,7 @@ static struct video_device video_dev_template = {
1036 * 779 *
1037 * check for both frame interrupts set ( top and bottom ). 780 * check for both frame interrupts set ( top and bottom ).
1038 * check FIFO overflow, but limit number of log messages after open. 781 * check FIFO overflow, but limit number of log messages after open.
1039 * signal a complete buffer if done. 782 * signal a complete buffer if done
1040 * dequeue a new buffer if available.
1041 * disable VIP if no buffer available.
1042 * 783 *
1043 * return value: IRQ_NONE, interrupt was not generated by VIP 784 * return value: IRQ_NONE, interrupt was not generated by VIP
1044 * 785 *
@@ -1046,88 +787,122 @@ static struct video_device video_dev_template = {
1046 */ 787 */
1047static irqreturn_t vip_irq(int irq, struct sta2x11_vip *vip) 788static irqreturn_t vip_irq(int irq, struct sta2x11_vip *vip)
1048{ 789{
1049 u32 status, dma; 790 unsigned int status;
1050 unsigned long flags;
1051 struct videobuf_buffer *vb;
1052 791
1053 status = REG_READ(vip, DVP_ITS); 792 status = reg_read(vip, DVP_ITS);
1054 793
1055 if (!status) { 794 if (!status) /* No interrupt to handle */
1056 pr_debug("VIP: irq ignored\n");
1057 return IRQ_NONE; 795 return IRQ_NONE;
1058 }
1059
1060 if (!vip->started)
1061 return IRQ_HANDLED;
1062 796
1063 if (status & DVP_IT_VSB) 797 if (status & DVP_IT_FIFO)
1064 vip->bcount++; 798 if (vip->overflow++ > 5)
1065 799 pr_info("VIP: fifo overflow\n");
1066 if (status & DVP_IT_VST)
1067 vip->tcount++;
1068 800
1069 if ((DVP_IT_VSB | DVP_IT_VST) == (status & (DVP_IT_VST | DVP_IT_VSB))) { 801 if ((status & DVP_IT_VST) && (status & DVP_IT_VSB)) {
1070 /* this is bad, we are too slow, hope the condition is gone 802 /* this is bad, we are too slow, hope the condition is gone
1071 * on the next frame */ 803 * on the next frame */
1072 pr_info("VIP: both irqs\n");
1073 return IRQ_HANDLED; 804 return IRQ_HANDLED;
1074 } 805 }
1075 806
1076 if (status & DVP_IT_FIFO) { 807 if (status & DVP_IT_VST)
1077 if (5 > vip->overflow++) 808 if ((++vip->tcount) < 2)
1078 pr_info("VIP: fifo overflow\n"); 809 return IRQ_HANDLED;
810 if (status & DVP_IT_VSB) {
811 vip->bcount++;
812 return IRQ_HANDLED;
1079 } 813 }
1080 814
1081 if (2 > vip->tcount) 815 if (vip->active) { /* Acquisition is over on this buffer */
1082 return IRQ_HANDLED; 816 /* Disable acquisition */
817 reg_write(vip, DVP_CTL, reg_read(vip, DVP_CTL) & ~DVP_CTL_ENA);
818 /* Remove the active buffer from the list */
819 do_gettimeofday(&vip->active->vb.v4l2_buf.timestamp);
820 vip->active->vb.v4l2_buf.sequence = vip->sequence++;
821 vb2_buffer_done(&vip->active->vb, VB2_BUF_STATE_DONE);
822 }
1083 823
1084 if (status & DVP_IT_VSB) 824 return IRQ_HANDLED;
1085 return IRQ_HANDLED; 825}
1086 826
1087 spin_lock_irqsave(&vip->slock, flags); 827static void sta2x11_vip_init_register(struct sta2x11_vip *vip)
828{
829 /* Register initialization */
830 spin_lock_irq(&vip->slock);
831 /* Clean interrupt */
832 reg_read(vip, DVP_ITS);
833 /* Enable Half Line per vertical */
834 reg_write(vip, DVP_HLFLN, DVP_HLFLN_SD);
835 /* Reset VIP control */
836 reg_write(vip, DVP_CTL, DVP_CTL_RST);
837 /* Clear VIP control */
838 reg_write(vip, DVP_CTL, 0);
839 spin_unlock_irq(&vip->slock);
840}
841static void sta2x11_vip_clear_register(struct sta2x11_vip *vip)
842{
843 spin_lock_irq(&vip->slock);
844 /* Disable interrupt */
845 reg_write(vip, DVP_ITM, 0);
846 /* Reset VIP Control */
847 reg_write(vip, DVP_CTL, DVP_CTL_RST);
848 /* Clear VIP Control */
849 reg_write(vip, DVP_CTL, 0);
850 /* Clean VIP Interrupt */
851 reg_read(vip, DVP_ITS);
852 spin_unlock_irq(&vip->slock);
853}
854static int sta2x11_vip_init_buffer(struct sta2x11_vip *vip)
855{
856 int err;
1088 857
1089 REG_WRITE(vip, DVP_CTL, REG_READ(vip, DVP_CTL) & ~DVP_CTL_ENA); 858 err = dma_set_coherent_mask(&vip->pdev->dev, DMA_BIT_MASK(29));
1090 if (vip->active) { 859 if (err) {
1091 v4l2_get_timestamp(&vip->active->ts); 860 v4l2_err(&vip->v4l2_dev, "Cannot configure coherent mask");
1092 vip->active->field_count++; 861 return err;
1093 vip->active->state = VIDEOBUF_DONE;
1094 wake_up(&vip->active->done);
1095 vip->active = NULL;
1096 } 862 }
1097 if (!vip->closing) { 863 memset(&vip->vb_vidq, 0, sizeof(struct vb2_queue));
1098 if (list_empty(&vip->capture)) 864 vip->vb_vidq.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1099 goto done; 865 vip->vb_vidq.io_modes = VB2_MMAP | VB2_READ;
1100 866 vip->vb_vidq.drv_priv = vip;
1101 vb = list_first_entry(&vip->capture, struct videobuf_buffer, 867 vip->vb_vidq.buf_struct_size = sizeof(struct vip_buffer);
1102 queue); 868 vip->vb_vidq.ops = &vip_video_qops;
1103 if (NULL == vb) { 869 vip->vb_vidq.mem_ops = &vb2_dma_contig_memops;
1104 pr_info("VIP: no buffer\n"); 870 err = vb2_queue_init(&vip->vb_vidq);
1105 goto done; 871 if (err)
1106 } 872 return err;
1107 vb->state = VIDEOBUF_ACTIVE; 873 INIT_LIST_HEAD(&vip->buffer_list);
1108 list_del(&vb->queue); 874 spin_lock_init(&vip->lock);
1109 vip->active = vb; 875
1110 dma = videobuf_to_dma_contig(vb); 876
1111 switch (vip->format.field) { 877 vip->alloc_ctx = vb2_dma_contig_init_ctx(&vip->pdev->dev);
1112 case V4L2_FIELD_INTERLACED: 878 if (IS_ERR(vip->alloc_ctx)) {
1113 REG_WRITE(vip, DVP_VTP, dma); 879 v4l2_err(&vip->v4l2_dev, "Can't allocate buffer context");
1114 REG_WRITE(vip, DVP_VBP, dma + vip->format.width * 2); 880 return PTR_ERR(vip->alloc_ctx);
1115 break;
1116 case V4L2_FIELD_TOP:
1117 case V4L2_FIELD_BOTTOM:
1118 REG_WRITE(vip, DVP_VTP, dma);
1119 REG_WRITE(vip, DVP_VBP, dma);
1120 break;
1121 default:
1122 pr_warning("VIP: unknown field format\n");
1123 goto done;
1124 break;
1125 }
1126 REG_WRITE(vip, DVP_CTL, REG_READ(vip, DVP_CTL) | DVP_CTL_ENA);
1127 } 881 }
1128done: 882
1129 spin_unlock_irqrestore(&vip->slock, flags); 883 return 0;
1130 return IRQ_HANDLED; 884}
885static void sta2x11_vip_release_buffer(struct sta2x11_vip *vip)
886{
887 vb2_dma_contig_cleanup_ctx(vip->alloc_ctx);
888}
889static int sta2x11_vip_init_controls(struct sta2x11_vip *vip)
890{
891 /*
892 * Inititialize an empty control so VIP can inerithing controls
893 * from ADV7180
894 */
895 v4l2_ctrl_handler_init(&vip->ctrl_hdl, 0);
896
897 vip->v4l2_dev.ctrl_handler = &vip->ctrl_hdl;
898 if (vip->ctrl_hdl.error) {
899 int err = vip->ctrl_hdl.error;
900
901 v4l2_ctrl_handler_free(&vip->ctrl_hdl);
902 return err;
903 }
904
905 return 0;
1131} 906}
1132 907
1133/** 908/**
@@ -1212,10 +987,17 @@ static int sta2x11_vip_init_one(struct pci_dev *pdev,
1212 struct sta2x11_vip *vip; 987 struct sta2x11_vip *vip;
1213 struct vip_config *config; 988 struct vip_config *config;
1214 989
990 /* Check if hardware support 26-bit DMA */
991 if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(26))) {
992 dev_err(&pdev->dev, "26-bit DMA addressing not available\n");
993 return -EINVAL;
994 }
995 /* Enable PCI */
1215 ret = pci_enable_device(pdev); 996 ret = pci_enable_device(pdev);
1216 if (ret) 997 if (ret)
1217 return ret; 998 return ret;
1218 999
1000 /* Get VIP platform data */
1219 config = dev_get_platdata(&pdev->dev); 1001 config = dev_get_platdata(&pdev->dev);
1220 if (!config) { 1002 if (!config) {
1221 dev_info(&pdev->dev, "VIP slot disabled\n"); 1003 dev_info(&pdev->dev, "VIP slot disabled\n");
@@ -1223,6 +1005,7 @@ static int sta2x11_vip_init_one(struct pci_dev *pdev,
1223 goto disable; 1005 goto disable;
1224 } 1006 }
1225 1007
1008 /* Power configuration */
1226 ret = vip_gpio_reserve(&pdev->dev, config->pwr_pin, 0, 1009 ret = vip_gpio_reserve(&pdev->dev, config->pwr_pin, 0,
1227 config->pwr_name); 1010 config->pwr_name);
1228 if (ret) 1011 if (ret)
@@ -1237,7 +1020,6 @@ static int sta2x11_vip_init_one(struct pci_dev *pdev,
1237 goto disable; 1020 goto disable;
1238 } 1021 }
1239 } 1022 }
1240
1241 if (config->pwr_pin != -1) { 1023 if (config->pwr_pin != -1) {
1242 /* Datasheet says 5ms between PWR and RST */ 1024 /* Datasheet says 5ms between PWR and RST */
1243 usleep_range(5000, 25000); 1025 usleep_range(5000, 25000);
@@ -1251,17 +1033,20 @@ static int sta2x11_vip_init_one(struct pci_dev *pdev,
1251 } 1033 }
1252 usleep_range(5000, 25000); 1034 usleep_range(5000, 25000);
1253 1035
1036 /* Allocate a new VIP instance */
1254 vip = kzalloc(sizeof(struct sta2x11_vip), GFP_KERNEL); 1037 vip = kzalloc(sizeof(struct sta2x11_vip), GFP_KERNEL);
1255 if (!vip) { 1038 if (!vip) {
1256 ret = -ENOMEM; 1039 ret = -ENOMEM;
1257 goto release_gpios; 1040 goto release_gpios;
1258 } 1041 }
1259
1260 vip->pdev = pdev; 1042 vip->pdev = pdev;
1261 vip->std = V4L2_STD_PAL; 1043 vip->std = V4L2_STD_PAL;
1262 vip->format = formats_50[0]; 1044 vip->format = formats_50[0];
1263 vip->config = config; 1045 vip->config = config;
1264 1046
1047 ret = sta2x11_vip_init_controls(vip);
1048 if (ret)
1049 goto free_mem;
1265 if (v4l2_device_register(&pdev->dev, &vip->v4l2_dev)) 1050 if (v4l2_device_register(&pdev->dev, &vip->v4l2_dev))
1266 goto free_mem; 1051 goto free_mem;
1267 1052
@@ -1271,46 +1056,52 @@ static int sta2x11_vip_init_one(struct pci_dev *pdev,
1271 1056
1272 pci_set_master(pdev); 1057 pci_set_master(pdev);
1273 1058
1274 ret = pci_request_regions(pdev, DRV_NAME); 1059 ret = pci_request_regions(pdev, KBUILD_MODNAME);
1275 if (ret) 1060 if (ret)
1276 goto unreg; 1061 goto unreg;
1277 1062
1278 vip->iomem = pci_iomap(pdev, 0, 0x100); 1063 vip->iomem = pci_iomap(pdev, 0, 0x100);
1279 if (!vip->iomem) { 1064 if (!vip->iomem) {
1280 ret = -ENOMEM; /* FIXME */ 1065 ret = -ENOMEM;
1281 goto release; 1066 goto release;
1282 } 1067 }
1283 1068
1284 pci_enable_msi(pdev); 1069 pci_enable_msi(pdev);
1285 1070
1286 INIT_LIST_HEAD(&vip->capture); 1071 /* Initialize buffer */
1072 ret = sta2x11_vip_init_buffer(vip);
1073 if (ret)
1074 goto unmap;
1075
1287 spin_lock_init(&vip->slock); 1076 spin_lock_init(&vip->slock);
1288 mutex_init(&vip->mutex);
1289 vip->started = 0;
1290 vip->disabled = 0;
1291 1077
1292 ret = request_irq(pdev->irq, 1078 ret = request_irq(pdev->irq,
1293 (irq_handler_t) vip_irq, 1079 (irq_handler_t) vip_irq,
1294 IRQF_SHARED, DRV_NAME, vip); 1080 IRQF_SHARED, KBUILD_MODNAME, vip);
1295 if (ret) { 1081 if (ret) {
1296 dev_err(&pdev->dev, "request_irq failed\n"); 1082 dev_err(&pdev->dev, "request_irq failed\n");
1297 ret = -ENODEV; 1083 ret = -ENODEV;
1298 goto unmap; 1084 goto release_buf;
1299 } 1085 }
1300 1086
1087 /* Alloc, initialize and register video device */
1301 vip->video_dev = video_device_alloc(); 1088 vip->video_dev = video_device_alloc();
1302 if (!vip->video_dev) { 1089 if (!vip->video_dev) {
1303 ret = -ENOMEM; 1090 ret = -ENOMEM;
1304 goto release_irq; 1091 goto release_irq;
1305 } 1092 }
1306 1093
1307 *(vip->video_dev) = video_dev_template; 1094 vip->video_dev = &video_dev_template;
1095 vip->video_dev->v4l2_dev = &vip->v4l2_dev;
1096 vip->video_dev->queue = &vip->vb_vidq;
1097 set_bit(V4L2_FL_USE_FH_PRIO, &vip->video_dev->flags);
1308 video_set_drvdata(vip->video_dev, vip); 1098 video_set_drvdata(vip->video_dev, vip);
1309 1099
1310 ret = video_register_device(vip->video_dev, VFL_TYPE_GRABBER, -1); 1100 ret = video_register_device(vip->video_dev, VFL_TYPE_GRABBER, -1);
1311 if (ret) 1101 if (ret)
1312 goto vrelease; 1102 goto vrelease;
1313 1103
1104 /* Get ADV7180 subdevice */
1314 vip->adapter = i2c_get_adapter(vip->config->i2c_id); 1105 vip->adapter = i2c_get_adapter(vip->config->i2c_id);
1315 if (!vip->adapter) { 1106 if (!vip->adapter) {
1316 ret = -ENODEV; 1107 ret = -ENODEV;
@@ -1328,10 +1119,11 @@ static int sta2x11_vip_init_one(struct pci_dev *pdev,
1328 } 1119 }
1329 1120
1330 i2c_put_adapter(vip->adapter); 1121 i2c_put_adapter(vip->adapter);
1331
1332 v4l2_subdev_call(vip->decoder, core, init, 0); 1122 v4l2_subdev_call(vip->decoder, core, init, 0);
1333 1123
1334 pr_info("STA2X11 Video Input Port (VIP) loaded\n"); 1124 sta2x11_vip_init_register(vip);
1125
1126 dev_info(&pdev->dev, "STA2X11 Video Input Port (VIP) loaded\n");
1335 return 0; 1127 return 0;
1336 1128
1337vunreg: 1129vunreg:
@@ -1343,10 +1135,12 @@ vrelease:
1343 video_device_release(vip->video_dev); 1135 video_device_release(vip->video_dev);
1344release_irq: 1136release_irq:
1345 free_irq(pdev->irq, vip); 1137 free_irq(pdev->irq, vip);
1138release_buf:
1139 sta2x11_vip_release_buffer(vip);
1346 pci_disable_msi(pdev); 1140 pci_disable_msi(pdev);
1347unmap: 1141unmap:
1142 vb2_queue_release(&vip->vb_vidq);
1348 pci_iounmap(pdev, vip->iomem); 1143 pci_iounmap(pdev, vip->iomem);
1349 mutex_destroy(&vip->mutex);
1350release: 1144release:
1351 pci_release_regions(pdev); 1145 pci_release_regions(pdev);
1352unreg: 1146unreg:
@@ -1382,16 +1176,18 @@ static void sta2x11_vip_remove_one(struct pci_dev *pdev)
1382 struct sta2x11_vip *vip = 1176 struct sta2x11_vip *vip =
1383 container_of(v4l2_dev, struct sta2x11_vip, v4l2_dev); 1177 container_of(v4l2_dev, struct sta2x11_vip, v4l2_dev);
1384 1178
1179 sta2x11_vip_clear_register(vip);
1180
1385 video_set_drvdata(vip->video_dev, NULL); 1181 video_set_drvdata(vip->video_dev, NULL);
1386 video_unregister_device(vip->video_dev); 1182 video_unregister_device(vip->video_dev);
1387 /*do not call video_device_release() here, is already done */ 1183 /*do not call video_device_release() here, is already done */
1388 free_irq(pdev->irq, vip); 1184 free_irq(pdev->irq, vip);
1389 pci_disable_msi(pdev); 1185 pci_disable_msi(pdev);
1186 vb2_queue_release(&vip->vb_vidq);
1390 pci_iounmap(pdev, vip->iomem); 1187 pci_iounmap(pdev, vip->iomem);
1391 pci_release_regions(pdev); 1188 pci_release_regions(pdev);
1392 1189
1393 v4l2_device_unregister(&vip->v4l2_dev); 1190 v4l2_device_unregister(&vip->v4l2_dev);
1394 mutex_destroy(&vip->mutex);
1395 1191
1396 vip_gpio_release(&pdev->dev, vip->config->pwr_pin, 1192 vip_gpio_release(&pdev->dev, vip->config->pwr_pin,
1397 vip->config->pwr_name); 1193 vip->config->pwr_name);
@@ -1416,9 +1212,6 @@ static void sta2x11_vip_remove_one(struct pci_dev *pdev)
1416 * 1212 *
1417 * return value: 0 always indicate success, 1213 * return value: 0 always indicate success,
1418 * even if device could not be disabled. (workaround for hardware problem) 1214 * even if device could not be disabled. (workaround for hardware problem)
1419 *
1420 * reurn value : 0, always succesful, even if hardware does not not support
1421 * power down mode.
1422 */ 1215 */
1423static int sta2x11_vip_suspend(struct pci_dev *pdev, pm_message_t state) 1216static int sta2x11_vip_suspend(struct pci_dev *pdev, pm_message_t state)
1424{ 1217{
@@ -1429,15 +1222,15 @@ static int sta2x11_vip_suspend(struct pci_dev *pdev, pm_message_t state)
1429 int i; 1222 int i;
1430 1223
1431 spin_lock_irqsave(&vip->slock, flags); 1224 spin_lock_irqsave(&vip->slock, flags);
1432 vip->register_save_area[0] = REG_READ(vip, DVP_CTL); 1225 vip->register_save_area[0] = reg_read(vip, DVP_CTL);
1433 REG_WRITE(vip, DVP_CTL, vip->register_save_area[0] & DVP_CTL_DIS); 1226 reg_write(vip, DVP_CTL, vip->register_save_area[0] & DVP_CTL_DIS);
1434 vip->register_save_area[SAVE_COUNT] = REG_READ(vip, DVP_ITM); 1227 vip->register_save_area[SAVE_COUNT] = reg_read(vip, DVP_ITM);
1435 REG_WRITE(vip, DVP_ITM, 0); 1228 reg_write(vip, DVP_ITM, 0);
1436 for (i = 1; i < SAVE_COUNT; i++) 1229 for (i = 1; i < SAVE_COUNT; i++)
1437 vip->register_save_area[i] = REG_READ(vip, 4 * i); 1230 vip->register_save_area[i] = reg_read(vip, 4 * i);
1438 for (i = 0; i < AUX_COUNT; i++) 1231 for (i = 0; i < AUX_COUNT; i++)
1439 vip->register_save_area[SAVE_COUNT + IRQ_COUNT + i] = 1232 vip->register_save_area[SAVE_COUNT + IRQ_COUNT + i] =
1440 REG_READ(vip, registers_to_save[i]); 1233 reg_read(vip, registers_to_save[i]);
1441 spin_unlock_irqrestore(&vip->slock, flags); 1234 spin_unlock_irqrestore(&vip->slock, flags);
1442 /* save pci state */ 1235 /* save pci state */
1443 pci_save_state(pdev); 1236 pci_save_state(pdev);
@@ -1477,7 +1270,7 @@ static int sta2x11_vip_resume(struct pci_dev *pdev)
1477 if (vip->disabled) { 1270 if (vip->disabled) {
1478 ret = pci_enable_device(pdev); 1271 ret = pci_enable_device(pdev);
1479 if (ret) { 1272 if (ret) {
1480 pr_warning("VIP: Can't enable device.\n"); 1273 pr_warn("VIP: Can't enable device.\n");
1481 return ret; 1274 return ret;
1482 } 1275 }
1483 vip->disabled = 0; 1276 vip->disabled = 0;
@@ -1488,7 +1281,7 @@ static int sta2x11_vip_resume(struct pci_dev *pdev)
1488 * do not call pci_disable_device on sta2x11 because it 1281 * do not call pci_disable_device on sta2x11 because it
1489 * break all other Bus masters on this EP 1282 * break all other Bus masters on this EP
1490 */ 1283 */
1491 pr_warning("VIP: Can't enable device.\n"); 1284 pr_warn("VIP: Can't enable device.\n");
1492 vip->disabled = 1; 1285 vip->disabled = 1;
1493 return ret; 1286 return ret;
1494 } 1287 }
@@ -1497,12 +1290,12 @@ static int sta2x11_vip_resume(struct pci_dev *pdev)
1497 1290
1498 spin_lock_irqsave(&vip->slock, flags); 1291 spin_lock_irqsave(&vip->slock, flags);
1499 for (i = 1; i < SAVE_COUNT; i++) 1292 for (i = 1; i < SAVE_COUNT; i++)
1500 REG_WRITE(vip, 4 * i, vip->register_save_area[i]); 1293 reg_write(vip, 4 * i, vip->register_save_area[i]);
1501 for (i = 0; i < AUX_COUNT; i++) 1294 for (i = 0; i < AUX_COUNT; i++)
1502 REG_WRITE(vip, registers_to_save[i], 1295 reg_write(vip, registers_to_save[i],
1503 vip->register_save_area[SAVE_COUNT + IRQ_COUNT + i]); 1296 vip->register_save_area[SAVE_COUNT + IRQ_COUNT + i]);
1504 REG_WRITE(vip, DVP_CTL, vip->register_save_area[0]); 1297 reg_write(vip, DVP_CTL, vip->register_save_area[0]);
1505 REG_WRITE(vip, DVP_ITM, vip->register_save_area[SAVE_COUNT]); 1298 reg_write(vip, DVP_ITM, vip->register_save_area[SAVE_COUNT]);
1506 spin_unlock_irqrestore(&vip->slock, flags); 1299 spin_unlock_irqrestore(&vip->slock, flags);
1507 return 0; 1300 return 0;
1508} 1301}
@@ -1515,7 +1308,7 @@ static DEFINE_PCI_DEVICE_TABLE(sta2x11_vip_pci_tbl) = {
1515}; 1308};
1516 1309
1517static struct pci_driver sta2x11_vip_driver = { 1310static struct pci_driver sta2x11_vip_driver = {
1518 .name = DRV_NAME, 1311 .name = KBUILD_MODNAME,
1519 .probe = sta2x11_vip_init_one, 1312 .probe = sta2x11_vip_init_one,
1520 .remove = sta2x11_vip_remove_one, 1313 .remove = sta2x11_vip_remove_one,
1521 .id_table = sta2x11_vip_pci_tbl, 1314 .id_table = sta2x11_vip_pci_tbl,