aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video')
-rw-r--r--drivers/media/video/Kconfig6
-rw-r--r--drivers/media/video/au0828/au0828-dvb.c2
-rw-r--r--drivers/media/video/au0828/au0828-i2c.c1
-rw-r--r--drivers/media/video/bt8xx/bttv-cards.c1
-rw-r--r--drivers/media/video/bt8xx/bttv-driver.c14
-rw-r--r--drivers/media/video/bt8xx/bttv-i2c.c2
-rw-r--r--drivers/media/video/bt8xx/bttv-input.c27
-rw-r--r--drivers/media/video/cafe_ccic.c1
-rw-r--r--drivers/media/video/cx18/cx18-cards.c8
-rw-r--r--drivers/media/video/cx18/cx18-cards.h18
-rw-r--r--drivers/media/video/cx18/cx18-driver.c41
-rw-r--r--drivers/media/video/cx18/cx18-fileops.c2
-rw-r--r--drivers/media/video/cx18/cx18-i2c.c59
-rw-r--r--drivers/media/video/cx18/cx18-ioctl.c2
-rw-r--r--drivers/media/video/cx231xx/cx231xx-conf-reg.h8
-rw-r--r--drivers/media/video/cx231xx/cx231xx-i2c.c1
-rw-r--r--drivers/media/video/cx231xx/cx231xx-video.c4
-rw-r--r--drivers/media/video/cx231xx/cx231xx.h2
-rw-r--r--drivers/media/video/cx23885/cimax2.c1
-rw-r--r--drivers/media/video/cx23885/cx23885-417.c57
-rw-r--r--drivers/media/video/cx23885/cx23885-cards.c77
-rw-r--r--drivers/media/video/cx23885/cx23885-core.c30
-rw-r--r--drivers/media/video/cx23885/cx23885-dvb.c54
-rw-r--r--drivers/media/video/cx23885/cx23885-i2c.c1
-rw-r--r--drivers/media/video/cx23885/cx23885.h14
-rw-r--r--drivers/media/video/cx25840/cx25840-core.c15
-rw-r--r--drivers/media/video/cx25840/cx25840-firmware.c48
-rw-r--r--drivers/media/video/cx88/cx88-cards.c56
-rw-r--r--drivers/media/video/cx88/cx88-dvb.c16
-rw-r--r--drivers/media/video/cx88/cx88-input.c78
-rw-r--r--drivers/media/video/cx88/cx88.h1
-rw-r--r--drivers/media/video/em28xx/em28xx-cards.c115
-rw-r--r--drivers/media/video/em28xx/em28xx-i2c.c1
-rw-r--r--drivers/media/video/em28xx/em28xx-video.c161
-rw-r--r--drivers/media/video/em28xx/em28xx.h8
-rw-r--r--drivers/media/video/gspca/Kconfig21
-rw-r--r--drivers/media/video/gspca/Makefile2
-rw-r--r--drivers/media/video/gspca/conex.c2
-rw-r--r--drivers/media/video/gspca/etoms.c4
-rw-r--r--drivers/media/video/gspca/gspca.c66
-rw-r--r--drivers/media/video/gspca/gspca.h5
-rw-r--r--drivers/media/video/gspca/jeilinj.c388
-rw-r--r--drivers/media/video/gspca/m5602/m5602_s5k83a.c4
-rw-r--r--drivers/media/video/gspca/mr97310a.c853
-rw-r--r--drivers/media/video/gspca/pac207.c37
-rw-r--r--drivers/media/video/gspca/pac7311.c2
-rw-r--r--drivers/media/video/gspca/sn9c20x.c235
-rw-r--r--drivers/media/video/gspca/sonixj.c40
-rw-r--r--drivers/media/video/gspca/spca501.c2
-rw-r--r--drivers/media/video/gspca/spca506.c2
-rw-r--r--drivers/media/video/gspca/spca508.c59
-rw-r--r--drivers/media/video/gspca/stv06xx/stv06xx.c4
-rw-r--r--drivers/media/video/gspca/sunplus.c386
-rw-r--r--drivers/media/video/gspca/t613.c210
-rw-r--r--drivers/media/video/gspca/tv8532.c2
-rw-r--r--drivers/media/video/gspca/vc032x.c1126
-rw-r--r--drivers/media/video/gspca/zc3xx.c2
-rw-r--r--drivers/media/video/hdpvr/hdpvr-control.c24
-rw-r--r--drivers/media/video/hdpvr/hdpvr-core.c12
-rw-r--r--drivers/media/video/hdpvr/hdpvr-i2c.c1
-rw-r--r--drivers/media/video/hdpvr/hdpvr-video.c6
-rw-r--r--drivers/media/video/ir-kbd-i2c.c64
-rw-r--r--drivers/media/video/ivtv/ivtv-cards.c70
-rw-r--r--drivers/media/video/ivtv/ivtv-cards.h3
-rw-r--r--drivers/media/video/ivtv/ivtv-driver.c3
-rw-r--r--drivers/media/video/ivtv/ivtv-gpio.c13
-rw-r--r--drivers/media/video/ivtv/ivtv-i2c.c2
-rw-r--r--drivers/media/video/meye.c3
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-audio.c5
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-i2c-core.c1
-rw-r--r--drivers/media/video/pwc/pwc-if.c78
-rw-r--r--drivers/media/video/pwc/pwc-v4l.c2
-rw-r--r--drivers/media/video/pwc/pwc.h7
-rw-r--r--drivers/media/video/saa6588.c60
-rw-r--r--drivers/media/video/saa7134/Kconfig1
-rw-r--r--drivers/media/video/saa7134/saa6752hs.c2
-rw-r--r--drivers/media/video/saa7134/saa7134-alsa.c242
-rw-r--r--drivers/media/video/saa7134/saa7134-cards.c213
-rw-r--r--drivers/media/video/saa7134/saa7134-core.c4
-rw-r--r--drivers/media/video/saa7134/saa7134-dvb.c17
-rw-r--r--drivers/media/video/saa7134/saa7134-input.c120
-rw-r--r--drivers/media/video/saa7134/saa7134-video.c5
-rw-r--r--drivers/media/video/saa7134/saa7134.h9
-rw-r--r--drivers/media/video/sn9c102/sn9c102_devtable.h2
-rw-r--r--drivers/media/video/stk-webcam.c1
-rw-r--r--drivers/media/video/stv680.c9
-rw-r--r--drivers/media/video/tuner-core.c4
-rw-r--r--drivers/media/video/tveeprom.c4
-rw-r--r--drivers/media/video/uvc/uvc_ctrl.c255
-rw-r--r--drivers/media/video/uvc/uvc_driver.c570
-rw-r--r--drivers/media/video/uvc/uvc_isight.c7
-rw-r--r--drivers/media/video/uvc/uvc_v4l2.c277
-rw-r--r--drivers/media/video/uvc/uvc_video.c434
-rw-r--r--drivers/media/video/uvc/uvcvideo.h278
-rw-r--r--drivers/media/video/v4l1-compat.c5
-rw-r--r--drivers/media/video/v4l2-common.c52
-rw-r--r--drivers/media/video/v4l2-compat-ioctl32.c67
-rw-r--r--drivers/media/video/v4l2-ioctl.c33
-rw-r--r--drivers/media/video/vino.c1
-rw-r--r--drivers/media/video/w9968cf.c1
-rw-r--r--drivers/media/video/zoran/zoran_card.c3
-rw-r--r--drivers/media/video/zr364xx.c1226
102 files changed, 5792 insertions, 2788 deletions
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index dcf9fa9264bb..1d758525d236 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -203,9 +203,9 @@ config VIDEO_CS53L32A
203 module will be called cs53l32a. 203 module will be called cs53l32a.
204 204
205config VIDEO_M52790 205config VIDEO_M52790
206 tristate "Mitsubishi M52790 A/V switch" 206 tristate "Mitsubishi M52790 A/V switch"
207 depends on VIDEO_V4L2 && I2C 207 depends on VIDEO_V4L2 && I2C
208 ---help--- 208 ---help---
209 Support for the Mitsubishi M52790 A/V switch. 209 Support for the Mitsubishi M52790 A/V switch.
210 210
211 To compile this driver as a module, choose M here: the 211 To compile this driver as a module, choose M here: the
diff --git a/drivers/media/video/au0828/au0828-dvb.c b/drivers/media/video/au0828/au0828-dvb.c
index 14baffc22192..b8a4b52e8d47 100644
--- a/drivers/media/video/au0828/au0828-dvb.c
+++ b/drivers/media/video/au0828/au0828-dvb.c
@@ -151,7 +151,7 @@ static int start_urb_transfer(struct au0828_dev *dev)
151 dprintk(2, "%s()\n", __func__); 151 dprintk(2, "%s()\n", __func__);
152 152
153 if (dev->urb_streaming) { 153 if (dev->urb_streaming) {
154 dprintk(2, "%s: iso xfer already running!\n", __func__); 154 dprintk(2, "%s: bulk xfer already running!\n", __func__);
155 return 0; 155 return 0;
156 } 156 }
157 157
diff --git a/drivers/media/video/au0828/au0828-i2c.c b/drivers/media/video/au0828/au0828-i2c.c
index 13e494365e70..cbdb65c34f21 100644
--- a/drivers/media/video/au0828/au0828-i2c.c
+++ b/drivers/media/video/au0828/au0828-i2c.c
@@ -320,7 +320,6 @@ static struct i2c_algorithm au0828_i2c_algo_template = {
320static struct i2c_adapter au0828_i2c_adap_template = { 320static struct i2c_adapter au0828_i2c_adap_template = {
321 .name = DRIVER_NAME, 321 .name = DRIVER_NAME,
322 .owner = THIS_MODULE, 322 .owner = THIS_MODULE,
323 .id = I2C_HW_B_AU0828,
324 .algo = &au0828_i2c_algo_template, 323 .algo = &au0828_i2c_algo_template,
325}; 324};
326 325
diff --git a/drivers/media/video/bt8xx/bttv-cards.c b/drivers/media/video/bt8xx/bttv-cards.c
index ca6558c394be..b42251fa96ba 100644
--- a/drivers/media/video/bt8xx/bttv-cards.c
+++ b/drivers/media/video/bt8xx/bttv-cards.c
@@ -1274,6 +1274,7 @@ struct tvcard bttv_tvcards[] = {
1274 .pll = PLL_28, 1274 .pll = PLL_28,
1275 .tuner_type = TUNER_TEMIC_PAL, 1275 .tuner_type = TUNER_TEMIC_PAL,
1276 .tuner_addr = ADDR_UNSET, 1276 .tuner_addr = ADDR_UNSET,
1277 .has_remote = 1,
1277 }, 1278 },
1278 1279
1279 /* ---- card 0x3c ---------------------------------- */ 1280 /* ---- card 0x3c ---------------------------------- */
diff --git a/drivers/media/video/bt8xx/bttv-driver.c b/drivers/media/video/bt8xx/bttv-driver.c
index 8cc6dd28d6a7..939d1e512974 100644
--- a/drivers/media/video/bt8xx/bttv-driver.c
+++ b/drivers/media/video/bt8xx/bttv-driver.c
@@ -2652,6 +2652,8 @@ static int bttv_querycap(struct file *file, void *priv,
2652 V4L2_CAP_VBI_CAPTURE | 2652 V4L2_CAP_VBI_CAPTURE |
2653 V4L2_CAP_READWRITE | 2653 V4L2_CAP_READWRITE |
2654 V4L2_CAP_STREAMING; 2654 V4L2_CAP_STREAMING;
2655 if (btv->has_saa6588)
2656 cap->capabilities |= V4L2_CAP_RDS_CAPTURE;
2655 if (no_overlay <= 0) 2657 if (no_overlay <= 0)
2656 cap->capabilities |= V4L2_CAP_VIDEO_OVERLAY; 2658 cap->capabilities |= V4L2_CAP_VIDEO_OVERLAY;
2657 2659
@@ -4593,14 +4595,10 @@ static int bttv_resume(struct pci_dev *pci_dev)
4593#endif 4595#endif
4594 4596
4595static struct pci_device_id bttv_pci_tbl[] = { 4597static struct pci_device_id bttv_pci_tbl[] = {
4596 {PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT848, 4598 {PCI_VDEVICE(BROOKTREE, PCI_DEVICE_ID_BT848), 0},
4597 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 4599 {PCI_VDEVICE(BROOKTREE, PCI_DEVICE_ID_BT849), 0},
4598 {PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT849, 4600 {PCI_VDEVICE(BROOKTREE, PCI_DEVICE_ID_BT878), 0},
4599 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 4601 {PCI_VDEVICE(BROOKTREE, PCI_DEVICE_ID_BT879), 0},
4600 {PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT878,
4601 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
4602 {PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT879,
4603 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
4604 {0,} 4602 {0,}
4605}; 4603};
4606 4604
diff --git a/drivers/media/video/bt8xx/bttv-i2c.c b/drivers/media/video/bt8xx/bttv-i2c.c
index ebd1ee9dc871..beda363418b0 100644
--- a/drivers/media/video/bt8xx/bttv-i2c.c
+++ b/drivers/media/video/bt8xx/bttv-i2c.c
@@ -352,7 +352,6 @@ int __devinit init_bttv_i2c(struct bttv *btv)
352 /* bt878 */ 352 /* bt878 */
353 strlcpy(btv->c.i2c_adap.name, "bt878", 353 strlcpy(btv->c.i2c_adap.name, "bt878",
354 sizeof(btv->c.i2c_adap.name)); 354 sizeof(btv->c.i2c_adap.name));
355 btv->c.i2c_adap.id = I2C_HW_B_BT848; /* FIXME */
356 btv->c.i2c_adap.algo = &bttv_algo; 355 btv->c.i2c_adap.algo = &bttv_algo;
357 } else { 356 } else {
358 /* bt848 */ 357 /* bt848 */
@@ -362,7 +361,6 @@ int __devinit init_bttv_i2c(struct bttv *btv)
362 361
363 strlcpy(btv->c.i2c_adap.name, "bttv", 362 strlcpy(btv->c.i2c_adap.name, "bttv",
364 sizeof(btv->c.i2c_adap.name)); 363 sizeof(btv->c.i2c_adap.name));
365 btv->c.i2c_adap.id = I2C_HW_B_BT848;
366 memcpy(&btv->i2c_algo, &bttv_i2c_algo_bit_template, 364 memcpy(&btv->i2c_algo, &bttv_i2c_algo_bit_template,
367 sizeof(bttv_i2c_algo_bit_template)); 365 sizeof(bttv_i2c_algo_bit_template));
368 btv->i2c_algo.udelay = i2c_udelay; 366 btv->i2c_algo.udelay = i2c_udelay;
diff --git a/drivers/media/video/bt8xx/bttv-input.c b/drivers/media/video/bt8xx/bttv-input.c
index 2f289d981fe6..ebd51afe8761 100644
--- a/drivers/media/video/bt8xx/bttv-input.c
+++ b/drivers/media/video/bt8xx/bttv-input.c
@@ -245,7 +245,7 @@ static void bttv_ir_stop(struct bttv *btv)
245int bttv_input_init(struct bttv *btv) 245int bttv_input_init(struct bttv *btv)
246{ 246{
247 struct card_ir *ir; 247 struct card_ir *ir;
248 IR_KEYTAB_TYPE *ir_codes = NULL; 248 struct ir_scancode_table *ir_codes = NULL;
249 struct input_dev *input_dev; 249 struct input_dev *input_dev;
250 int ir_type = IR_TYPE_OTHER; 250 int ir_type = IR_TYPE_OTHER;
251 int err = -ENOMEM; 251 int err = -ENOMEM;
@@ -263,7 +263,7 @@ int bttv_input_init(struct bttv *btv)
263 case BTTV_BOARD_AVERMEDIA: 263 case BTTV_BOARD_AVERMEDIA:
264 case BTTV_BOARD_AVPHONE98: 264 case BTTV_BOARD_AVPHONE98:
265 case BTTV_BOARD_AVERMEDIA98: 265 case BTTV_BOARD_AVERMEDIA98:
266 ir_codes = ir_codes_avermedia; 266 ir_codes = &ir_codes_avermedia_table;
267 ir->mask_keycode = 0xf88000; 267 ir->mask_keycode = 0xf88000;
268 ir->mask_keydown = 0x010000; 268 ir->mask_keydown = 0x010000;
269 ir->polling = 50; // ms 269 ir->polling = 50; // ms
@@ -271,14 +271,14 @@ int bttv_input_init(struct bttv *btv)
271 271
272 case BTTV_BOARD_AVDVBT_761: 272 case BTTV_BOARD_AVDVBT_761:
273 case BTTV_BOARD_AVDVBT_771: 273 case BTTV_BOARD_AVDVBT_771:
274 ir_codes = ir_codes_avermedia_dvbt; 274 ir_codes = &ir_codes_avermedia_dvbt_table;
275 ir->mask_keycode = 0x0f00c0; 275 ir->mask_keycode = 0x0f00c0;
276 ir->mask_keydown = 0x000020; 276 ir->mask_keydown = 0x000020;
277 ir->polling = 50; // ms 277 ir->polling = 50; // ms
278 break; 278 break;
279 279
280 case BTTV_BOARD_PXELVWPLTVPAK: 280 case BTTV_BOARD_PXELVWPLTVPAK:
281 ir_codes = ir_codes_pixelview; 281 ir_codes = &ir_codes_pixelview_table;
282 ir->mask_keycode = 0x003e00; 282 ir->mask_keycode = 0x003e00;
283 ir->mask_keyup = 0x010000; 283 ir->mask_keyup = 0x010000;
284 ir->polling = 50; // ms 284 ir->polling = 50; // ms
@@ -286,54 +286,55 @@ int bttv_input_init(struct bttv *btv)
286 case BTTV_BOARD_PV_M4900: 286 case BTTV_BOARD_PV_M4900:
287 case BTTV_BOARD_PV_BT878P_9B: 287 case BTTV_BOARD_PV_BT878P_9B:
288 case BTTV_BOARD_PV_BT878P_PLUS: 288 case BTTV_BOARD_PV_BT878P_PLUS:
289 ir_codes = ir_codes_pixelview; 289 ir_codes = &ir_codes_pixelview_table;
290 ir->mask_keycode = 0x001f00; 290 ir->mask_keycode = 0x001f00;
291 ir->mask_keyup = 0x008000; 291 ir->mask_keyup = 0x008000;
292 ir->polling = 50; // ms 292 ir->polling = 50; // ms
293 break; 293 break;
294 294
295 case BTTV_BOARD_WINFAST2000: 295 case BTTV_BOARD_WINFAST2000:
296 ir_codes = ir_codes_winfast; 296 ir_codes = &ir_codes_winfast_table;
297 ir->mask_keycode = 0x1f8; 297 ir->mask_keycode = 0x1f8;
298 break; 298 break;
299 case BTTV_BOARD_MAGICTVIEW061: 299 case BTTV_BOARD_MAGICTVIEW061:
300 case BTTV_BOARD_MAGICTVIEW063: 300 case BTTV_BOARD_MAGICTVIEW063:
301 ir_codes = ir_codes_winfast; 301 ir_codes = &ir_codes_winfast_table;
302 ir->mask_keycode = 0x0008e000; 302 ir->mask_keycode = 0x0008e000;
303 ir->mask_keydown = 0x00200000; 303 ir->mask_keydown = 0x00200000;
304 break; 304 break;
305 case BTTV_BOARD_APAC_VIEWCOMP: 305 case BTTV_BOARD_APAC_VIEWCOMP:
306 ir_codes = ir_codes_apac_viewcomp; 306 ir_codes = &ir_codes_apac_viewcomp_table;
307 ir->mask_keycode = 0x001f00; 307 ir->mask_keycode = 0x001f00;
308 ir->mask_keyup = 0x008000; 308 ir->mask_keyup = 0x008000;
309 ir->polling = 50; // ms 309 ir->polling = 50; // ms
310 break; 310 break;
311 case BTTV_BOARD_ASKEY_CPH03X:
311 case BTTV_BOARD_CONCEPTRONIC_CTVFMI2: 312 case BTTV_BOARD_CONCEPTRONIC_CTVFMI2:
312 case BTTV_BOARD_CONTVFMI: 313 case BTTV_BOARD_CONTVFMI:
313 ir_codes = ir_codes_pixelview; 314 ir_codes = &ir_codes_pixelview_table;
314 ir->mask_keycode = 0x001F00; 315 ir->mask_keycode = 0x001F00;
315 ir->mask_keyup = 0x006000; 316 ir->mask_keyup = 0x006000;
316 ir->polling = 50; // ms 317 ir->polling = 50; // ms
317 break; 318 break;
318 case BTTV_BOARD_NEBULA_DIGITV: 319 case BTTV_BOARD_NEBULA_DIGITV:
319 ir_codes = ir_codes_nebula; 320 ir_codes = &ir_codes_nebula_table;
320 btv->custom_irq = bttv_rc5_irq; 321 btv->custom_irq = bttv_rc5_irq;
321 ir->rc5_gpio = 1; 322 ir->rc5_gpio = 1;
322 break; 323 break;
323 case BTTV_BOARD_MACHTV_MAGICTV: 324 case BTTV_BOARD_MACHTV_MAGICTV:
324 ir_codes = ir_codes_apac_viewcomp; 325 ir_codes = &ir_codes_apac_viewcomp_table;
325 ir->mask_keycode = 0x001F00; 326 ir->mask_keycode = 0x001F00;
326 ir->mask_keyup = 0x004000; 327 ir->mask_keyup = 0x004000;
327 ir->polling = 50; /* ms */ 328 ir->polling = 50; /* ms */
328 break; 329 break;
329 case BTTV_BOARD_KOZUMI_KTV_01C: 330 case BTTV_BOARD_KOZUMI_KTV_01C:
330 ir_codes = ir_codes_pctv_sedna; 331 ir_codes = &ir_codes_pctv_sedna_table;
331 ir->mask_keycode = 0x001f00; 332 ir->mask_keycode = 0x001f00;
332 ir->mask_keyup = 0x006000; 333 ir->mask_keyup = 0x006000;
333 ir->polling = 50; /* ms */ 334 ir->polling = 50; /* ms */
334 break; 335 break;
335 case BTTV_BOARD_ENLTV_FM_2: 336 case BTTV_BOARD_ENLTV_FM_2:
336 ir_codes = ir_codes_encore_enltv2; 337 ir_codes = &ir_codes_encore_enltv2_table;
337 ir->mask_keycode = 0x00fd00; 338 ir->mask_keycode = 0x00fd00;
338 ir->mask_keyup = 0x000080; 339 ir->mask_keyup = 0x000080;
339 ir->polling = 1; /* ms */ 340 ir->polling = 1; /* ms */
diff --git a/drivers/media/video/cafe_ccic.c b/drivers/media/video/cafe_ccic.c
index c4d181dde1ca..9c149a781294 100644
--- a/drivers/media/video/cafe_ccic.c
+++ b/drivers/media/video/cafe_ccic.c
@@ -490,7 +490,6 @@ static int cafe_smbus_setup(struct cafe_camera *cam)
490 int ret; 490 int ret;
491 491
492 cafe_smbus_enable_irq(cam); 492 cafe_smbus_enable_irq(cam);
493 adap->id = I2C_HW_SMBUS_CAFE;
494 adap->owner = THIS_MODULE; 493 adap->owner = THIS_MODULE;
495 adap->algo = &cafe_smbus_algo; 494 adap->algo = &cafe_smbus_algo;
496 strcpy(adap->name, "cafe_ccic"); 495 strcpy(adap->name, "cafe_ccic");
diff --git a/drivers/media/video/cx18/cx18-cards.c b/drivers/media/video/cx18/cx18-cards.c
index 36f2d76006fd..f11e47a58286 100644
--- a/drivers/media/video/cx18/cx18-cards.c
+++ b/drivers/media/video/cx18/cx18-cards.c
@@ -56,7 +56,8 @@ static const struct cx18_card cx18_card_hvr1600_esmt = {
56 .hw_audio_ctrl = CX18_HW_418_AV, 56 .hw_audio_ctrl = CX18_HW_418_AV,
57 .hw_muxer = CX18_HW_CS5345, 57 .hw_muxer = CX18_HW_CS5345,
58 .hw_all = CX18_HW_TVEEPROM | CX18_HW_418_AV | CX18_HW_TUNER | 58 .hw_all = CX18_HW_TVEEPROM | CX18_HW_418_AV | CX18_HW_TUNER |
59 CX18_HW_CS5345 | CX18_HW_DVB | CX18_HW_GPIO_RESET_CTRL, 59 CX18_HW_CS5345 | CX18_HW_DVB | CX18_HW_GPIO_RESET_CTRL |
60 CX18_HW_Z8F0811_IR_HAUP,
60 .video_inputs = { 61 .video_inputs = {
61 { CX18_CARD_INPUT_VID_TUNER, 0, CX18_AV_COMPOSITE7 }, 62 { CX18_CARD_INPUT_VID_TUNER, 0, CX18_AV_COMPOSITE7 },
62 { CX18_CARD_INPUT_SVIDEO1, 1, CX18_AV_SVIDEO1 }, 63 { CX18_CARD_INPUT_SVIDEO1, 1, CX18_AV_SVIDEO1 },
@@ -102,7 +103,8 @@ static const struct cx18_card cx18_card_hvr1600_samsung = {
102 .hw_audio_ctrl = CX18_HW_418_AV, 103 .hw_audio_ctrl = CX18_HW_418_AV,
103 .hw_muxer = CX18_HW_CS5345, 104 .hw_muxer = CX18_HW_CS5345,
104 .hw_all = CX18_HW_TVEEPROM | CX18_HW_418_AV | CX18_HW_TUNER | 105 .hw_all = CX18_HW_TVEEPROM | CX18_HW_418_AV | CX18_HW_TUNER |
105 CX18_HW_CS5345 | CX18_HW_DVB | CX18_HW_GPIO_RESET_CTRL, 106 CX18_HW_CS5345 | CX18_HW_DVB | CX18_HW_GPIO_RESET_CTRL |
107 CX18_HW_Z8F0811_IR_HAUP,
106 .video_inputs = { 108 .video_inputs = {
107 { CX18_CARD_INPUT_VID_TUNER, 0, CX18_AV_COMPOSITE7 }, 109 { CX18_CARD_INPUT_VID_TUNER, 0, CX18_AV_COMPOSITE7 },
108 { CX18_CARD_INPUT_SVIDEO1, 1, CX18_AV_SVIDEO1 }, 110 { CX18_CARD_INPUT_SVIDEO1, 1, CX18_AV_SVIDEO1 },
@@ -204,7 +206,7 @@ static const struct cx18_card cx18_card_mpc718 = {
204 .v4l2_capabilities = CX18_CAP_ENCODER, 206 .v4l2_capabilities = CX18_CAP_ENCODER,
205 .hw_audio_ctrl = CX18_HW_418_AV, 207 .hw_audio_ctrl = CX18_HW_418_AV,
206 .hw_muxer = CX18_HW_GPIO_MUX, 208 .hw_muxer = CX18_HW_GPIO_MUX,
207 .hw_all = CX18_HW_418_AV | CX18_HW_TUNER | 209 .hw_all = CX18_HW_TVEEPROM | CX18_HW_418_AV | CX18_HW_TUNER |
208 CX18_HW_GPIO_MUX | CX18_HW_DVB | CX18_HW_GPIO_RESET_CTRL, 210 CX18_HW_GPIO_MUX | CX18_HW_DVB | CX18_HW_GPIO_RESET_CTRL,
209 .video_inputs = { 211 .video_inputs = {
210 { CX18_CARD_INPUT_VID_TUNER, 0, CX18_AV_COMPOSITE2 }, 212 { CX18_CARD_INPUT_VID_TUNER, 0, CX18_AV_COMPOSITE2 },
diff --git a/drivers/media/video/cx18/cx18-cards.h b/drivers/media/video/cx18/cx18-cards.h
index 3c552b6b7c4d..444e3c7c563e 100644
--- a/drivers/media/video/cx18/cx18-cards.h
+++ b/drivers/media/video/cx18/cx18-cards.h
@@ -22,13 +22,17 @@
22 */ 22 */
23 23
24/* hardware flags */ 24/* hardware flags */
25#define CX18_HW_TUNER (1 << 0) 25#define CX18_HW_TUNER (1 << 0)
26#define CX18_HW_TVEEPROM (1 << 1) 26#define CX18_HW_TVEEPROM (1 << 1)
27#define CX18_HW_CS5345 (1 << 2) 27#define CX18_HW_CS5345 (1 << 2)
28#define CX18_HW_DVB (1 << 3) 28#define CX18_HW_DVB (1 << 3)
29#define CX18_HW_418_AV (1 << 4) 29#define CX18_HW_418_AV (1 << 4)
30#define CX18_HW_GPIO_MUX (1 << 5) 30#define CX18_HW_GPIO_MUX (1 << 5)
31#define CX18_HW_GPIO_RESET_CTRL (1 << 6) 31#define CX18_HW_GPIO_RESET_CTRL (1 << 6)
32#define CX18_HW_Z8F0811_IR_TX_HAUP (1 << 7)
33#define CX18_HW_Z8F0811_IR_RX_HAUP (1 << 8)
34#define CX18_HW_Z8F0811_IR_HAUP (CX18_HW_Z8F0811_IR_RX_HAUP | \
35 CX18_HW_Z8F0811_IR_TX_HAUP)
32 36
33/* video inputs */ 37/* video inputs */
34#define CX18_CARD_INPUT_VID_TUNER 1 38#define CX18_CARD_INPUT_VID_TUNER 1
diff --git a/drivers/media/video/cx18/cx18-driver.c b/drivers/media/video/cx18/cx18-driver.c
index 92026e82e10e..dd0224f328ad 100644
--- a/drivers/media/video/cx18/cx18-driver.c
+++ b/drivers/media/video/cx18/cx18-driver.c
@@ -268,6 +268,20 @@ static void cx18_iounmap(struct cx18 *cx)
268 } 268 }
269} 269}
270 270
271static void cx18_eeprom_dump(struct cx18 *cx, unsigned char *eedata, int len)
272{
273 int i;
274
275 CX18_INFO("eeprom dump:\n");
276 for (i = 0; i < len; i++) {
277 if (0 == (i % 16))
278 CX18_INFO("eeprom %02x:", i);
279 printk(KERN_CONT " %02x", eedata[i]);
280 if (15 == (i % 16))
281 printk(KERN_CONT "\n");
282 }
283}
284
271/* Hauppauge card? get values from tveeprom */ 285/* Hauppauge card? get values from tveeprom */
272void cx18_read_eeprom(struct cx18 *cx, struct tveeprom *tv) 286void cx18_read_eeprom(struct cx18 *cx, struct tveeprom *tv)
273{ 287{
@@ -279,8 +293,26 @@ void cx18_read_eeprom(struct cx18 *cx, struct tveeprom *tv)
279 c.adapter = &cx->i2c_adap[0]; 293 c.adapter = &cx->i2c_adap[0];
280 c.addr = 0xA0 >> 1; 294 c.addr = 0xA0 >> 1;
281 295
282 tveeprom_read(&c, eedata, sizeof(eedata)); 296 memset(tv, 0, sizeof(*tv));
283 tveeprom_hauppauge_analog(&c, tv, eedata); 297 if (tveeprom_read(&c, eedata, sizeof(eedata)))
298 return;
299
300 switch (cx->card->type) {
301 case CX18_CARD_HVR_1600_ESMT:
302 case CX18_CARD_HVR_1600_SAMSUNG:
303 tveeprom_hauppauge_analog(&c, tv, eedata);
304 break;
305 case CX18_CARD_YUAN_MPC718:
306 tv->model = 0x718;
307 cx18_eeprom_dump(cx, eedata, sizeof(eedata));
308 CX18_INFO("eeprom PCI ID: %02x%02x:%02x%02x\n",
309 eedata[2], eedata[1], eedata[4], eedata[3]);
310 break;
311 default:
312 tv->model = 0xffffffff;
313 cx18_eeprom_dump(cx, eedata, sizeof(eedata));
314 break;
315 }
284} 316}
285 317
286static void cx18_process_eeprom(struct cx18 *cx) 318static void cx18_process_eeprom(struct cx18 *cx)
@@ -298,6 +330,11 @@ static void cx18_process_eeprom(struct cx18 *cx)
298 case 74000 ... 74999: 330 case 74000 ... 74999:
299 cx->card = cx18_get_card(CX18_CARD_HVR_1600_ESMT); 331 cx->card = cx18_get_card(CX18_CARD_HVR_1600_ESMT);
300 break; 332 break;
333 case 0x718:
334 return;
335 case 0xffffffff:
336 CX18_INFO("Unknown EEPROM encoding\n");
337 return;
301 case 0: 338 case 0:
302 CX18_ERR("Invalid EEPROM\n"); 339 CX18_ERR("Invalid EEPROM\n");
303 return; 340 return;
diff --git a/drivers/media/video/cx18/cx18-fileops.c b/drivers/media/video/cx18/cx18-fileops.c
index 29969c18949c..04d9c2508b86 100644
--- a/drivers/media/video/cx18/cx18-fileops.c
+++ b/drivers/media/video/cx18/cx18-fileops.c
@@ -690,7 +690,7 @@ int cx18_v4l2_open(struct file *filp)
690 int res; 690 int res;
691 struct video_device *video_dev = video_devdata(filp); 691 struct video_device *video_dev = video_devdata(filp);
692 struct cx18_stream *s = video_get_drvdata(video_dev); 692 struct cx18_stream *s = video_get_drvdata(video_dev);
693 struct cx18 *cx = s->cx;; 693 struct cx18 *cx = s->cx;
694 694
695 mutex_lock(&cx->serialize_lock); 695 mutex_lock(&cx->serialize_lock);
696 if (cx18_init_on_first_open(cx)) { 696 if (cx18_init_on_first_open(cx)) {
diff --git a/drivers/media/video/cx18/cx18-i2c.c b/drivers/media/video/cx18/cx18-i2c.c
index 8591e4fc359f..da395fef50df 100644
--- a/drivers/media/video/cx18/cx18-i2c.c
+++ b/drivers/media/video/cx18/cx18-i2c.c
@@ -28,6 +28,7 @@
28#include "cx18-gpio.h" 28#include "cx18-gpio.h"
29#include "cx18-i2c.h" 29#include "cx18-i2c.h"
30#include "cx18-irq.h" 30#include "cx18-irq.h"
31#include <media/ir-kbd-i2c.h>
31 32
32#define CX18_REG_I2C_1_WR 0xf15000 33#define CX18_REG_I2C_1_WR 0xf15000
33#define CX18_REG_I2C_1_RD 0xf15008 34#define CX18_REG_I2C_1_RD 0xf15008
@@ -40,16 +41,20 @@
40#define GETSDL_BIT 0x0008 41#define GETSDL_BIT 0x0008
41 42
42#define CX18_CS5345_I2C_ADDR 0x4c 43#define CX18_CS5345_I2C_ADDR 0x4c
44#define CX18_Z8F0811_IR_TX_I2C_ADDR 0x70
45#define CX18_Z8F0811_IR_RX_I2C_ADDR 0x71
43 46
44/* This array should match the CX18_HW_ defines */ 47/* This array should match the CX18_HW_ defines */
45static const u8 hw_addrs[] = { 48static const u8 hw_addrs[] = {
46 0, /* CX18_HW_TUNER */ 49 0, /* CX18_HW_TUNER */
47 0, /* CX18_HW_TVEEPROM */ 50 0, /* CX18_HW_TVEEPROM */
48 CX18_CS5345_I2C_ADDR, /* CX18_HW_CS5345 */ 51 CX18_CS5345_I2C_ADDR, /* CX18_HW_CS5345 */
49 0, /* CX18_HW_DVB */ 52 0, /* CX18_HW_DVB */
50 0, /* CX18_HW_418_AV */ 53 0, /* CX18_HW_418_AV */
51 0, /* CX18_HW_GPIO_MUX */ 54 0, /* CX18_HW_GPIO_MUX */
52 0, /* CX18_HW_GPIO_RESET_CTRL */ 55 0, /* CX18_HW_GPIO_RESET_CTRL */
56 CX18_Z8F0811_IR_TX_I2C_ADDR, /* CX18_HW_Z8F0811_IR_TX_HAUP */
57 CX18_Z8F0811_IR_RX_I2C_ADDR, /* CX18_HW_Z8F0811_IR_RX_HAUP */
53}; 58};
54 59
55/* This array should match the CX18_HW_ defines */ 60/* This array should match the CX18_HW_ defines */
@@ -62,6 +67,8 @@ static const u8 hw_bus[] = {
62 0, /* CX18_HW_418_AV */ 67 0, /* CX18_HW_418_AV */
63 0, /* CX18_HW_GPIO_MUX */ 68 0, /* CX18_HW_GPIO_MUX */
64 0, /* CX18_HW_GPIO_RESET_CTRL */ 69 0, /* CX18_HW_GPIO_RESET_CTRL */
70 0, /* CX18_HW_Z8F0811_IR_TX_HAUP */
71 0, /* CX18_HW_Z8F0811_IR_RX_HAUP */
65}; 72};
66 73
67/* This array should match the CX18_HW_ defines */ 74/* This array should match the CX18_HW_ defines */
@@ -73,6 +80,8 @@ static const char * const hw_modules[] = {
73 NULL, /* CX18_HW_418_AV */ 80 NULL, /* CX18_HW_418_AV */
74 NULL, /* CX18_HW_GPIO_MUX */ 81 NULL, /* CX18_HW_GPIO_MUX */
75 NULL, /* CX18_HW_GPIO_RESET_CTRL */ 82 NULL, /* CX18_HW_GPIO_RESET_CTRL */
83 NULL, /* CX18_HW_Z8F0811_IR_TX_HAUP */
84 NULL, /* CX18_HW_Z8F0811_IR_RX_HAUP */
76}; 85};
77 86
78/* This array should match the CX18_HW_ defines */ 87/* This array should match the CX18_HW_ defines */
@@ -84,8 +93,38 @@ static const char * const hw_devicenames[] = {
84 "cx23418_AV", 93 "cx23418_AV",
85 "gpio_mux", 94 "gpio_mux",
86 "gpio_reset_ctrl", 95 "gpio_reset_ctrl",
96 "ir_tx_z8f0811_haup",
97 "ir_rx_z8f0811_haup",
87}; 98};
88 99
100static const struct IR_i2c_init_data z8f0811_ir_init_data = {
101 .ir_codes = &ir_codes_hauppauge_new_table,
102 .internal_get_key_func = IR_KBD_GET_KEY_HAUP_XVR,
103 .type = IR_TYPE_RC5,
104 .name = "CX23418 Z8F0811 Hauppauge",
105};
106
107static int cx18_i2c_new_ir(struct i2c_adapter *adap, u32 hw, const char *type,
108 u8 addr)
109{
110 struct i2c_board_info info;
111 unsigned short addr_list[2] = { addr, I2C_CLIENT_END };
112
113 memset(&info, 0, sizeof(struct i2c_board_info));
114 strlcpy(info.type, type, I2C_NAME_SIZE);
115
116 /* Our default information for ir-kbd-i2c.c to use */
117 switch (hw) {
118 case CX18_HW_Z8F0811_IR_RX_HAUP:
119 info.platform_data = &z8f0811_ir_init_data;
120 break;
121 default:
122 break;
123 }
124
125 return i2c_new_probed_device(adap, &info, addr_list) == NULL ? -1 : 0;
126}
127
89int cx18_i2c_register(struct cx18 *cx, unsigned idx) 128int cx18_i2c_register(struct cx18 *cx, unsigned idx)
90{ 129{
91 struct v4l2_subdev *sd; 130 struct v4l2_subdev *sd;
@@ -115,11 +154,14 @@ int cx18_i2c_register(struct cx18 *cx, unsigned idx)
115 return sd != NULL ? 0 : -1; 154 return sd != NULL ? 0 : -1;
116 } 155 }
117 156
157 if (hw & CX18_HW_Z8F0811_IR_HAUP)
158 return cx18_i2c_new_ir(adap, hw, type, hw_addrs[idx]);
159
118 /* Is it not an I2C device or one we do not wish to register? */ 160 /* Is it not an I2C device or one we do not wish to register? */
119 if (!hw_addrs[idx]) 161 if (!hw_addrs[idx])
120 return -1; 162 return -1;
121 163
122 /* It's an I2C device other than an analog tuner */ 164 /* It's an I2C device other than an analog tuner or IR chip */
123 sd = v4l2_i2c_new_subdev(&cx->v4l2_dev, adap, mod, type, hw_addrs[idx]); 165 sd = v4l2_i2c_new_subdev(&cx->v4l2_dev, adap, mod, type, hw_addrs[idx]);
124 if (sd != NULL) 166 if (sd != NULL)
125 sd->grp_id = hw; 167 sd->grp_id = hw;
@@ -190,7 +232,6 @@ static int cx18_getsda(void *data)
190/* template for i2c-bit-algo */ 232/* template for i2c-bit-algo */
191static struct i2c_adapter cx18_i2c_adap_template = { 233static struct i2c_adapter cx18_i2c_adap_template = {
192 .name = "cx18 i2c driver", 234 .name = "cx18 i2c driver",
193 .id = I2C_HW_B_CX2341X,
194 .algo = NULL, /* set by i2c-algo-bit */ 235 .algo = NULL, /* set by i2c-algo-bit */
195 .algo_data = NULL, /* filled from template */ 236 .algo_data = NULL, /* filled from template */
196 .owner = THIS_MODULE, 237 .owner = THIS_MODULE,
diff --git a/drivers/media/video/cx18/cx18-ioctl.c b/drivers/media/video/cx18/cx18-ioctl.c
index d7b1921e6666..fc76e4d6ffa7 100644
--- a/drivers/media/video/cx18/cx18-ioctl.c
+++ b/drivers/media/video/cx18/cx18-ioctl.c
@@ -605,7 +605,7 @@ int cx18_s_input(struct file *file, void *fh, unsigned int inp)
605 if (ret) 605 if (ret)
606 return ret; 606 return ret;
607 607
608 if (inp < 0 || inp >= cx->nof_inputs) 608 if (inp >= cx->nof_inputs)
609 return -EINVAL; 609 return -EINVAL;
610 610
611 if (inp == cx->active_input) { 611 if (inp == cx->active_input) {
diff --git a/drivers/media/video/cx231xx/cx231xx-conf-reg.h b/drivers/media/video/cx231xx/cx231xx-conf-reg.h
index a6f398a175c5..31a8759f6e54 100644
--- a/drivers/media/video/cx231xx/cx231xx-conf-reg.h
+++ b/drivers/media/video/cx231xx/cx231xx-conf-reg.h
@@ -60,10 +60,10 @@
60#define PWR_RESETOUT_EN 0x100 /* bit8 */ 60#define PWR_RESETOUT_EN 0x100 /* bit8 */
61 61
62enum AV_MODE{ 62enum AV_MODE{
63 POLARIS_AVMODE_DEFAULT = 0, 63 POLARIS_AVMODE_DEFAULT = 0,
64 POLARIS_AVMODE_DIGITAL = 0x10, 64 POLARIS_AVMODE_DIGITAL = 0x10,
65 POLARIS_AVMODE_ANALOGT_TV = 0x20, 65 POLARIS_AVMODE_ANALOGT_TV = 0x20,
66 POLARIS_AVMODE_ENXTERNAL_AV = 0x30, 66 POLARIS_AVMODE_ENXTERNAL_AV = 0x30,
67 67
68}; 68};
69 69
diff --git a/drivers/media/video/cx231xx/cx231xx-i2c.c b/drivers/media/video/cx231xx/cx231xx-i2c.c
index 33219dc4d649..58d9cc0867b9 100644
--- a/drivers/media/video/cx231xx/cx231xx-i2c.c
+++ b/drivers/media/video/cx231xx/cx231xx-i2c.c
@@ -432,7 +432,6 @@ static struct i2c_algorithm cx231xx_algo = {
432static struct i2c_adapter cx231xx_adap_template = { 432static struct i2c_adapter cx231xx_adap_template = {
433 .owner = THIS_MODULE, 433 .owner = THIS_MODULE,
434 .name = "cx231xx", 434 .name = "cx231xx",
435 .id = I2C_HW_B_CX231XX,
436 .algo = &cx231xx_algo, 435 .algo = &cx231xx_algo,
437}; 436};
438 437
diff --git a/drivers/media/video/cx231xx/cx231xx-video.c b/drivers/media/video/cx231xx/cx231xx-video.c
index 609bae6098d3..36503725d973 100644
--- a/drivers/media/video/cx231xx/cx231xx-video.c
+++ b/drivers/media/video/cx231xx/cx231xx-video.c
@@ -923,8 +923,8 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
923 923
924 f->fmt.pix.width = dev->width; 924 f->fmt.pix.width = dev->width;
925 f->fmt.pix.height = dev->height; 925 f->fmt.pix.height = dev->height;
926 f->fmt.pix.pixelformat = dev->format->fourcc;; 926 f->fmt.pix.pixelformat = dev->format->fourcc;
927 f->fmt.pix.bytesperline = (dev->width * dev->format->depth + 7) >> 3;; 927 f->fmt.pix.bytesperline = (dev->width * dev->format->depth + 7) >> 3;
928 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * dev->height; 928 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * dev->height;
929 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; 929 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
930 930
diff --git a/drivers/media/video/cx231xx/cx231xx.h b/drivers/media/video/cx231xx/cx231xx.h
index a0f823ac6b8d..64e2ddd3c401 100644
--- a/drivers/media/video/cx231xx/cx231xx.h
+++ b/drivers/media/video/cx231xx/cx231xx.h
@@ -282,7 +282,7 @@ struct cx231xx_board {
282 282
283 struct cx231xx_input input[MAX_CX231XX_INPUT]; 283 struct cx231xx_input input[MAX_CX231XX_INPUT];
284 struct cx231xx_input radio; 284 struct cx231xx_input radio;
285 IR_KEYTAB_TYPE *ir_codes; 285 struct ir_scancode_table *ir_codes;
286}; 286};
287 287
288/* device states */ 288/* device states */
diff --git a/drivers/media/video/cx23885/cimax2.c b/drivers/media/video/cx23885/cimax2.c
index 08582e58bdbf..0316257b7345 100644
--- a/drivers/media/video/cx23885/cimax2.c
+++ b/drivers/media/video/cx23885/cimax2.c
@@ -443,6 +443,7 @@ int netup_ci_init(struct cx23885_tsport *port)
443 goto err; 443 goto err;
444 444
445 INIT_WORK(&state->work, netup_read_ci_status); 445 INIT_WORK(&state->work, netup_read_ci_status);
446 schedule_work(&state->work);
446 447
447 ci_dbg_print("%s: CI initialized!\n", __func__); 448 ci_dbg_print("%s: CI initialized!\n", __func__);
448 449
diff --git a/drivers/media/video/cx23885/cx23885-417.c b/drivers/media/video/cx23885/cx23885-417.c
index 1a1048b18f70..6c3b51ce3372 100644
--- a/drivers/media/video/cx23885/cx23885-417.c
+++ b/drivers/media/video/cx23885/cx23885-417.c
@@ -630,6 +630,39 @@ int mc417_memory_read(struct cx23885_dev *dev, u32 address, u32 *value)
630 return retval; 630 return retval;
631} 631}
632 632
633void mc417_gpio_set(struct cx23885_dev *dev, u32 mask)
634{
635 u32 val;
636
637 /* Set the gpio value */
638 mc417_register_read(dev, 0x900C, &val);
639 val |= (mask & 0x000ffff);
640 mc417_register_write(dev, 0x900C, val);
641}
642
643void mc417_gpio_clear(struct cx23885_dev *dev, u32 mask)
644{
645 u32 val;
646
647 /* Clear the gpio value */
648 mc417_register_read(dev, 0x900C, &val);
649 val &= ~(mask & 0x0000ffff);
650 mc417_register_write(dev, 0x900C, val);
651}
652
653void mc417_gpio_enable(struct cx23885_dev *dev, u32 mask, int asoutput)
654{
655 u32 val;
656
657 /* Enable GPIO direction bits */
658 mc417_register_read(dev, 0x9020, &val);
659 if (asoutput)
660 val |= (mask & 0x0000ffff);
661 else
662 val &= ~(mask & 0x0000ffff);
663
664 mc417_register_write(dev, 0x9020, val);
665}
633/* ------------------------------------------------------------------ */ 666/* ------------------------------------------------------------------ */
634 667
635/* MPEG encoder API */ 668/* MPEG encoder API */
@@ -955,25 +988,8 @@ static int cx23885_load_firmware(struct cx23885_dev *dev)
955 retval |= mc417_register_write(dev, IVTV_REG_HW_BLOCKS, 988 retval |= mc417_register_write(dev, IVTV_REG_HW_BLOCKS,
956 IVTV_CMD_HW_BLOCKS_RST); 989 IVTV_CMD_HW_BLOCKS_RST);
957 990
958 /* Restore GPIO settings, make sure EIO14 is enabled as an output. */ 991 /* F/W power up disturbs the GPIOs, restore state */
959 dprintk(2, "%s: GPIO output EIO 0-15 was = 0x%x\n", 992 retval |= mc417_register_write(dev, 0x9020, gpio_output);
960 __func__, gpio_output);
961 /* Power-up seems to have GPIOs AFU. This was causing digital side
962 * to fail at power-up. Seems GPIOs should be set to 0x10ff0411 at
963 * power-up.
964 * gpio_output |= (1<<14);
965 */
966 /* Note: GPIO14 is specific to the HVR1800 here */
967 gpio_output = 0x10ff0411 | (1<<14);
968 retval |= mc417_register_write(dev, 0x9020, gpio_output | (1<<14));
969 dprintk(2, "%s: GPIO output EIO 0-15 now = 0x%x\n",
970 __func__, gpio_output);
971
972 dprintk(1, "%s: GPIO value EIO 0-15 was = 0x%x\n",
973 __func__, value);
974 value |= (1<<14);
975 dprintk(1, "%s: GPIO value EIO 0-15 now = 0x%x\n",
976 __func__, value);
977 retval |= mc417_register_write(dev, 0x900C, value); 993 retval |= mc417_register_write(dev, 0x900C, value);
978 994
979 retval |= mc417_register_read(dev, IVTV_REG_VPU, &value); 995 retval |= mc417_register_read(dev, IVTV_REG_VPU, &value);
@@ -1788,9 +1804,6 @@ int cx23885_417_register(struct cx23885_dev *dev)
1788 return err; 1804 return err;
1789 } 1805 }
1790 1806
1791 /* Initialize MC417 registers */
1792 cx23885_mc417_init(dev);
1793
1794 printk(KERN_INFO "%s: registered device video%d [mpeg]\n", 1807 printk(KERN_INFO "%s: registered device video%d [mpeg]\n",
1795 dev->name, dev->v4l_device->num); 1808 dev->name, dev->v4l_device->num);
1796 1809
diff --git a/drivers/media/video/cx23885/cx23885-cards.c b/drivers/media/video/cx23885/cx23885-cards.c
index ce29b5e34a11..3143d85ef31d 100644
--- a/drivers/media/video/cx23885/cx23885-cards.c
+++ b/drivers/media/video/cx23885/cx23885-cards.c
@@ -201,6 +201,15 @@ struct cx23885_board cx23885_boards[] = {
201 .name = "Mygica X8506 DMB-TH", 201 .name = "Mygica X8506 DMB-TH",
202 .portb = CX23885_MPEG_DVB, 202 .portb = CX23885_MPEG_DVB,
203 }, 203 },
204 [CX23885_BOARD_MAGICPRO_PROHDTVE2] = {
205 .name = "Magic-Pro ProHDTV Extreme 2",
206 .portb = CX23885_MPEG_DVB,
207 },
208 [CX23885_BOARD_HAUPPAUGE_HVR1850] = {
209 .name = "Hauppauge WinTV-HVR1850",
210 .portb = CX23885_MPEG_ENCODER,
211 .portc = CX23885_MPEG_DVB,
212 },
204}; 213};
205const unsigned int cx23885_bcount = ARRAY_SIZE(cx23885_boards); 214const unsigned int cx23885_bcount = ARRAY_SIZE(cx23885_boards);
206 215
@@ -324,6 +333,14 @@ struct cx23885_subid cx23885_subids[] = {
324 .subvendor = 0x14f1, 333 .subvendor = 0x14f1,
325 .subdevice = 0x8651, 334 .subdevice = 0x8651,
326 .card = CX23885_BOARD_MYGICA_X8506, 335 .card = CX23885_BOARD_MYGICA_X8506,
336 }, {
337 .subvendor = 0x14f1,
338 .subdevice = 0x8657,
339 .card = CX23885_BOARD_MAGICPRO_PROHDTVE2,
340 }, {
341 .subvendor = 0x0070,
342 .subdevice = 0x8541,
343 .card = CX23885_BOARD_HAUPPAUGE_HVR1850,
327 }, 344 },
328}; 345};
329const unsigned int cx23885_idcount = ARRAY_SIZE(cx23885_subids); 346const unsigned int cx23885_idcount = ARRAY_SIZE(cx23885_subids);
@@ -483,8 +500,13 @@ static void hauppauge_eeprom(struct cx23885_dev *dev, u8 *eeprom_data)
483 /* WinTV-HVR1700 (PCIe, OEM, No IR, full height) 500 /* WinTV-HVR1700 (PCIe, OEM, No IR, full height)
484 * DVB-T and MPEG2 HW Encoder */ 501 * DVB-T and MPEG2 HW Encoder */
485 break; 502 break;
503 case 85021:
504 /* WinTV-HVR1850 (PCIe, OEM, RCA in, IR, FM,
505 Dual channel ATSC and MPEG2 HW Encoder */
506 break;
486 default: 507 default:
487 printk(KERN_WARNING "%s: warning: unknown hauppauge model #%d\n", 508 printk(KERN_WARNING "%s: warning: "
509 "unknown hauppauge model #%d\n",
488 dev->name, tv.model); 510 dev->name, tv.model);
489 break; 511 break;
490 } 512 }
@@ -574,13 +596,23 @@ void cx23885_gpio_setup(struct cx23885_dev *dev)
574 /* CX23417 GPIO's */ 596 /* CX23417 GPIO's */
575 /* EIO15 Zilog Reset */ 597 /* EIO15 Zilog Reset */
576 /* EIO14 S5H1409/CX24227 Reset */ 598 /* EIO14 S5H1409/CX24227 Reset */
599 mc417_gpio_enable(dev, GPIO_15 | GPIO_14, 1);
600
601 /* Put the demod into reset and protect the eeprom */
602 mc417_gpio_clear(dev, GPIO_15 | GPIO_14);
603 mdelay(100);
604
605 /* Bring the demod and blaster out of reset */
606 mc417_gpio_set(dev, GPIO_15 | GPIO_14);
607 mdelay(100);
577 608
578 /* Force the TDA8295A into reset and back */ 609 /* Force the TDA8295A into reset and back */
579 cx_set(GP0_IO, 0x00040004); 610 cx23885_gpio_enable(dev, GPIO_2, 1);
611 cx23885_gpio_set(dev, GPIO_2);
580 mdelay(20); 612 mdelay(20);
581 cx_clear(GP0_IO, 0x00000004); 613 cx23885_gpio_clear(dev, GPIO_2);
582 mdelay(20); 614 mdelay(20);
583 cx_set(GP0_IO, 0x00040004); 615 cx23885_gpio_set(dev, GPIO_2);
584 mdelay(20); 616 mdelay(20);
585 break; 617 break;
586 case CX23885_BOARD_HAUPPAUGE_HVR1200: 618 case CX23885_BOARD_HAUPPAUGE_HVR1200:
@@ -715,14 +747,45 @@ void cx23885_gpio_setup(struct cx23885_dev *dev)
715 cx23885_gpio_set(dev, GPIO_9); 747 cx23885_gpio_set(dev, GPIO_9);
716 break; 748 break;
717 case CX23885_BOARD_MYGICA_X8506: 749 case CX23885_BOARD_MYGICA_X8506:
750 case CX23885_BOARD_MAGICPRO_PROHDTVE2:
718 /* GPIO-1 reset XC5000 */ 751 /* GPIO-1 reset XC5000 */
719 /* GPIO-2 reset LGS8GL5 */ 752 /* GPIO-2 reset LGS8GL5 / LGS8G75 */
720 cx_set(GP0_IO, 0x00060000); 753 cx_set(GP0_IO, 0x00060000);
721 cx_clear(GP0_IO, 0x00000006); 754 cx_clear(GP0_IO, 0x00000006);
722 mdelay(100); 755 mdelay(100);
723 cx_set(GP0_IO, 0x00060006); 756 cx_set(GP0_IO, 0x00060006);
724 mdelay(100); 757 mdelay(100);
725 break; 758 break;
759 case CX23885_BOARD_HAUPPAUGE_HVR1850:
760 /* GPIO-0 656_CLK */
761 /* GPIO-1 656_D0 */
762 /* GPIO-2 Wake# */
763 /* GPIO-3-10 cx23417 data0-7 */
764 /* GPIO-11-14 cx23417 addr0-3 */
765 /* GPIO-15-18 cx23417 READY, CS, RD, WR */
766 /* GPIO-19 IR_RX */
767 /* GPIO-20 C_IR_TX */
768 /* GPIO-21 I2S DAT */
769 /* GPIO-22 I2S WCLK */
770 /* GPIO-23 I2S BCLK */
771 /* ALT GPIO: EXP GPIO LATCH */
772
773 /* CX23417 GPIO's */
774 /* GPIO-14 S5H1411/CX24228 Reset */
775 /* GPIO-13 EEPROM write protect */
776 mc417_gpio_enable(dev, GPIO_14 | GPIO_13, 1);
777
778 /* Put the demod into reset and protect the eeprom */
779 mc417_gpio_clear(dev, GPIO_14 | GPIO_13);
780 mdelay(100);
781
782 /* Bring the demod out of reset */
783 mc417_gpio_set(dev, GPIO_14);
784 mdelay(100);
785
786 /* CX24228 GPIO */
787 /* Connected to IF / Mux */
788 break;
726 } 789 }
727} 790}
728 791
@@ -739,6 +802,7 @@ int cx23885_ir_init(struct cx23885_dev *dev)
739 case CX23885_BOARD_HAUPPAUGE_HVR1275: 802 case CX23885_BOARD_HAUPPAUGE_HVR1275:
740 case CX23885_BOARD_HAUPPAUGE_HVR1255: 803 case CX23885_BOARD_HAUPPAUGE_HVR1255:
741 case CX23885_BOARD_HAUPPAUGE_HVR1210: 804 case CX23885_BOARD_HAUPPAUGE_HVR1210:
805 case CX23885_BOARD_HAUPPAUGE_HVR1850:
742 /* FIXME: Implement me */ 806 /* FIXME: Implement me */
743 break; 807 break;
744 case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP: 808 case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP:
@@ -778,6 +842,7 @@ void cx23885_card_setup(struct cx23885_dev *dev)
778 case CX23885_BOARD_HAUPPAUGE_HVR1275: 842 case CX23885_BOARD_HAUPPAUGE_HVR1275:
779 case CX23885_BOARD_HAUPPAUGE_HVR1255: 843 case CX23885_BOARD_HAUPPAUGE_HVR1255:
780 case CX23885_BOARD_HAUPPAUGE_HVR1210: 844 case CX23885_BOARD_HAUPPAUGE_HVR1210:
845 case CX23885_BOARD_HAUPPAUGE_HVR1850:
781 if (dev->i2c_bus[0].i2c_rc == 0) 846 if (dev->i2c_bus[0].i2c_rc == 0)
782 hauppauge_eeprom(dev, eeprom+0xc0); 847 hauppauge_eeprom(dev, eeprom+0xc0);
783 break; 848 break;
@@ -827,6 +892,7 @@ void cx23885_card_setup(struct cx23885_dev *dev)
827 ts2->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO; 892 ts2->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
828 break; 893 break;
829 case CX23885_BOARD_MYGICA_X8506: 894 case CX23885_BOARD_MYGICA_X8506:
895 case CX23885_BOARD_MAGICPRO_PROHDTVE2:
830 ts1->gen_ctrl_val = 0x5; /* Parallel */ 896 ts1->gen_ctrl_val = 0x5; /* Parallel */
831 ts1->ts_clk_en_val = 0x1; /* Enable TS_CLK */ 897 ts1->ts_clk_en_val = 0x1; /* Enable TS_CLK */
832 ts1->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO; 898 ts1->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
@@ -844,6 +910,7 @@ void cx23885_card_setup(struct cx23885_dev *dev)
844 case CX23885_BOARD_HAUPPAUGE_HVR1275: 910 case CX23885_BOARD_HAUPPAUGE_HVR1275:
845 case CX23885_BOARD_HAUPPAUGE_HVR1255: 911 case CX23885_BOARD_HAUPPAUGE_HVR1255:
846 case CX23885_BOARD_HAUPPAUGE_HVR1210: 912 case CX23885_BOARD_HAUPPAUGE_HVR1210:
913 case CX23885_BOARD_HAUPPAUGE_HVR1850:
847 default: 914 default:
848 ts2->gen_ctrl_val = 0xc; /* Serial bus + punctured clock */ 915 ts2->gen_ctrl_val = 0xc; /* Serial bus + punctured clock */
849 ts2->ts_clk_en_val = 0x1; /* Enable TS_CLK */ 916 ts2->ts_clk_en_val = 0x1; /* Enable TS_CLK */
diff --git a/drivers/media/video/cx23885/cx23885-core.c b/drivers/media/video/cx23885/cx23885-core.c
index bf7bb1c412fb..40d438d7234d 100644
--- a/drivers/media/video/cx23885/cx23885-core.c
+++ b/drivers/media/video/cx23885/cx23885-core.c
@@ -713,12 +713,26 @@ static void cx23885_dev_checkrevision(struct cx23885_dev *dev)
713 dev->hwrevision = 0xa1; 713 dev->hwrevision = 0xa1;
714 break; 714 break;
715 case 0x02: 715 case 0x02:
716 /* CX23885-13Z */ 716 /* CX23885-13Z/14Z */
717 dev->hwrevision = 0xb0; 717 dev->hwrevision = 0xb0;
718 break; 718 break;
719 case 0x03: 719 case 0x03:
720 /* CX23888-22Z */ 720 if (dev->pci->device == 0x8880) {
721 dev->hwrevision = 0xc0; 721 /* CX23888-21Z/22Z */
722 dev->hwrevision = 0xc0;
723 } else {
724 /* CX23885-14Z */
725 dev->hwrevision = 0xa4;
726 }
727 break;
728 case 0x04:
729 if (dev->pci->device == 0x8880) {
730 /* CX23888-31Z */
731 dev->hwrevision = 0xd0;
732 } else {
733 /* CX23885-15Z, CX23888-31Z */
734 dev->hwrevision = 0xa5;
735 }
722 break; 736 break;
723 case 0x0e: 737 case 0x0e:
724 /* CX23887-15Z */ 738 /* CX23887-15Z */
@@ -756,6 +770,7 @@ static int cx23885_dev_setup(struct cx23885_dev *dev)
756 770
757 /* Configure the internal memory */ 771 /* Configure the internal memory */
758 if (dev->pci->device == 0x8880) { 772 if (dev->pci->device == 0x8880) {
773 /* Could be 887 or 888, assume a default */
759 dev->bridge = CX23885_BRIDGE_887; 774 dev->bridge = CX23885_BRIDGE_887;
760 /* Apply a sensible clock frequency for the PCIe bridge */ 775 /* Apply a sensible clock frequency for the PCIe bridge */
761 dev->clk_freq = 25000000; 776 dev->clk_freq = 25000000;
@@ -868,6 +883,14 @@ static int cx23885_dev_setup(struct cx23885_dev *dev)
868 dprintk(1, "%s() radio_type = 0x%x radio_addr = 0x%x\n", 883 dprintk(1, "%s() radio_type = 0x%x radio_addr = 0x%x\n",
869 __func__, dev->radio_type, dev->radio_addr); 884 __func__, dev->radio_type, dev->radio_addr);
870 885
886 /* The cx23417 encoder has GPIO's that need to be initialised
887 * before DVB, so that demodulators and tuners are out of
888 * reset before DVB uses them.
889 */
890 if ((cx23885_boards[dev->board].portb == CX23885_MPEG_ENCODER) ||
891 (cx23885_boards[dev->board].portc == CX23885_MPEG_ENCODER))
892 cx23885_mc417_init(dev);
893
871 /* init hardware */ 894 /* init hardware */
872 cx23885_reset(dev); 895 cx23885_reset(dev);
873 896
@@ -1250,6 +1273,7 @@ static int cx23885_start_dma(struct cx23885_tsport *port,
1250 switch (dev->bridge) { 1273 switch (dev->bridge) {
1251 case CX23885_BRIDGE_885: 1274 case CX23885_BRIDGE_885:
1252 case CX23885_BRIDGE_887: 1275 case CX23885_BRIDGE_887:
1276 case CX23885_BRIDGE_888:
1253 /* enable irqs */ 1277 /* enable irqs */
1254 dprintk(1, "%s() enabling TS int's and DMA\n", __func__); 1278 dprintk(1, "%s() enabling TS int's and DMA\n", __func__);
1255 cx_set(port->reg_ts_int_msk, port->ts_int_msk_val); 1279 cx_set(port->reg_ts_int_msk, port->ts_int_msk_val);
diff --git a/drivers/media/video/cx23885/cx23885-dvb.c b/drivers/media/video/cx23885/cx23885-dvb.c
index 86ac529e62be..022fad798fc2 100644
--- a/drivers/media/video/cx23885/cx23885-dvb.c
+++ b/drivers/media/video/cx23885/cx23885-dvb.c
@@ -396,7 +396,7 @@ static struct stv0900_reg stv0900_ts_regs[] = {
396 396
397static struct stv0900_config netup_stv0900_config = { 397static struct stv0900_config netup_stv0900_config = {
398 .demod_address = 0x68, 398 .demod_address = 0x68,
399 .xtal = 27000000, 399 .xtal = 8000000,
400 .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */ 400 .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
401 .diseqc_mode = 2,/* 2/3 PWM */ 401 .diseqc_mode = 2,/* 2/3 PWM */
402 .ts_config_regs = stv0900_ts_regs, 402 .ts_config_regs = stv0900_ts_regs,
@@ -408,14 +408,14 @@ static struct stv0900_config netup_stv0900_config = {
408 408
409static struct stv6110_config netup_stv6110_tunerconfig_a = { 409static struct stv6110_config netup_stv6110_tunerconfig_a = {
410 .i2c_address = 0x60, 410 .i2c_address = 0x60,
411 .mclk = 27000000, 411 .mclk = 16000000,
412 .iq_wiring = 0, 412 .clk_div = 1,
413}; 413};
414 414
415static struct stv6110_config netup_stv6110_tunerconfig_b = { 415static struct stv6110_config netup_stv6110_tunerconfig_b = {
416 .i2c_address = 0x63, 416 .i2c_address = 0x63,
417 .mclk = 27000000, 417 .mclk = 16000000,
418 .iq_wiring = 1, 418 .clk_div = 1,
419}; 419};
420 420
421static int tbs_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) 421static int tbs_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
@@ -487,6 +487,26 @@ static int cx23885_dvb_set_frontend(struct dvb_frontend *fe,
487 port->set_frontend_save(fe, param) : -ENODEV; 487 port->set_frontend_save(fe, param) : -ENODEV;
488} 488}
489 489
490static struct lgs8gxx_config magicpro_prohdtve2_lgs8g75_config = {
491 .prod = LGS8GXX_PROD_LGS8G75,
492 .demod_address = 0x19,
493 .serial_ts = 0,
494 .ts_clk_pol = 1,
495 .ts_clk_gated = 1,
496 .if_clk_freq = 30400, /* 30.4 MHz */
497 .if_freq = 6500, /* 6.50 MHz */
498 .if_neg_center = 1,
499 .ext_adc = 0,
500 .adc_signed = 1,
501 .adc_vpp = 2, /* 1.6 Vpp */
502 .if_neg_edge = 1,
503};
504
505static struct xc5000_config magicpro_prohdtve2_xc5000_config = {
506 .i2c_address = 0x61,
507 .if_khz = 6500,
508};
509
490static int dvb_register(struct cx23885_tsport *port) 510static int dvb_register(struct cx23885_tsport *port)
491{ 511{
492 struct cx23885_dev *dev = port->dev; 512 struct cx23885_dev *dev = port->dev;
@@ -833,6 +853,30 @@ static int dvb_register(struct cx23885_tsport *port)
833 &mygica_x8506_xc5000_config); 853 &mygica_x8506_xc5000_config);
834 } 854 }
835 break; 855 break;
856 case CX23885_BOARD_MAGICPRO_PROHDTVE2:
857 i2c_bus = &dev->i2c_bus[0];
858 i2c_bus2 = &dev->i2c_bus[1];
859 fe0->dvb.frontend = dvb_attach(lgs8gxx_attach,
860 &magicpro_prohdtve2_lgs8g75_config,
861 &i2c_bus->i2c_adap);
862 if (fe0->dvb.frontend != NULL) {
863 dvb_attach(xc5000_attach,
864 fe0->dvb.frontend,
865 &i2c_bus2->i2c_adap,
866 &magicpro_prohdtve2_xc5000_config);
867 }
868 break;
869 case CX23885_BOARD_HAUPPAUGE_HVR1850:
870 i2c_bus = &dev->i2c_bus[0];
871 fe0->dvb.frontend = dvb_attach(s5h1411_attach,
872 &hcw_s5h1411_config,
873 &i2c_bus->i2c_adap);
874 if (fe0->dvb.frontend != NULL)
875 dvb_attach(tda18271_attach, fe0->dvb.frontend,
876 0x60, &dev->i2c_bus[0].i2c_adap,
877 &hauppauge_tda18271_config);
878 break;
879
836 default: 880 default:
837 printk(KERN_INFO "%s: The frontend of your DVB/ATSC card " 881 printk(KERN_INFO "%s: The frontend of your DVB/ATSC card "
838 " isn't supported yet\n", 882 " isn't supported yet\n",
diff --git a/drivers/media/video/cx23885/cx23885-i2c.c b/drivers/media/video/cx23885/cx23885-i2c.c
index 384dec34134f..4172cb387420 100644
--- a/drivers/media/video/cx23885/cx23885-i2c.c
+++ b/drivers/media/video/cx23885/cx23885-i2c.c
@@ -283,7 +283,6 @@ static struct i2c_algorithm cx23885_i2c_algo_template = {
283static struct i2c_adapter cx23885_i2c_adap_template = { 283static struct i2c_adapter cx23885_i2c_adap_template = {
284 .name = "cx23885", 284 .name = "cx23885",
285 .owner = THIS_MODULE, 285 .owner = THIS_MODULE,
286 .id = I2C_HW_B_CX23885,
287 .algo = &cx23885_i2c_algo_template, 286 .algo = &cx23885_i2c_algo_template,
288}; 287};
289 288
diff --git a/drivers/media/video/cx23885/cx23885.h b/drivers/media/video/cx23885/cx23885.h
index 214a55e943b7..86f26947bb78 100644
--- a/drivers/media/video/cx23885/cx23885.h
+++ b/drivers/media/video/cx23885/cx23885.h
@@ -76,6 +76,8 @@
76#define CX23885_BOARD_HAUPPAUGE_HVR1255 20 76#define CX23885_BOARD_HAUPPAUGE_HVR1255 20
77#define CX23885_BOARD_HAUPPAUGE_HVR1210 21 77#define CX23885_BOARD_HAUPPAUGE_HVR1210 21
78#define CX23885_BOARD_MYGICA_X8506 22 78#define CX23885_BOARD_MYGICA_X8506 22
79#define CX23885_BOARD_MAGICPRO_PROHDTVE2 23
80#define CX23885_BOARD_HAUPPAUGE_HVR1850 24
79 81
80#define GPIO_0 0x00000001 82#define GPIO_0 0x00000001
81#define GPIO_1 0x00000002 83#define GPIO_1 0x00000002
@@ -87,6 +89,12 @@
87#define GPIO_7 0x00000080 89#define GPIO_7 0x00000080
88#define GPIO_8 0x00000100 90#define GPIO_8 0x00000100
89#define GPIO_9 0x00000200 91#define GPIO_9 0x00000200
92#define GPIO_10 0x00000400
93#define GPIO_11 0x00000800
94#define GPIO_12 0x00001000
95#define GPIO_13 0x00002000
96#define GPIO_14 0x00004000
97#define GPIO_15 0x00008000
90 98
91/* Currently unsupported by the driver: PAL/H, NTSC/Kr, SECAM B/G/H/LC */ 99/* Currently unsupported by the driver: PAL/H, NTSC/Kr, SECAM B/G/H/LC */
92#define CX23885_NORMS (\ 100#define CX23885_NORMS (\
@@ -331,6 +339,7 @@ struct cx23885_dev {
331 CX23885_BRIDGE_UNDEFINED = 0, 339 CX23885_BRIDGE_UNDEFINED = 0,
332 CX23885_BRIDGE_885 = 885, 340 CX23885_BRIDGE_885 = 885,
333 CX23885_BRIDGE_887 = 887, 341 CX23885_BRIDGE_887 = 887,
342 CX23885_BRIDGE_888 = 888,
334 } bridge; 343 } bridge;
335 344
336 /* Analog video */ 345 /* Analog video */
@@ -395,7 +404,7 @@ struct sram_channel {
395 u32 cmds_start; 404 u32 cmds_start;
396 u32 ctrl_start; 405 u32 ctrl_start;
397 u32 cdt; 406 u32 cdt;
398 u32 fifo_start;; 407 u32 fifo_start;
399 u32 fifo_size; 408 u32 fifo_size;
400 u32 ptr1_reg; 409 u32 ptr1_reg;
401 u32 ptr2_reg; 410 u32 ptr2_reg;
@@ -504,6 +513,9 @@ extern void cx23885_417_check_encoder(struct cx23885_dev *dev);
504extern void cx23885_mc417_init(struct cx23885_dev *dev); 513extern void cx23885_mc417_init(struct cx23885_dev *dev);
505extern int mc417_memory_read(struct cx23885_dev *dev, u32 address, u32 *value); 514extern int mc417_memory_read(struct cx23885_dev *dev, u32 address, u32 *value);
506extern int mc417_memory_write(struct cx23885_dev *dev, u32 address, u32 value); 515extern int mc417_memory_write(struct cx23885_dev *dev, u32 address, u32 value);
516extern void mc417_gpio_set(struct cx23885_dev *dev, u32 mask);
517extern void mc417_gpio_clear(struct cx23885_dev *dev, u32 mask);
518extern void mc417_gpio_enable(struct cx23885_dev *dev, u32 mask, int asoutput);
507 519
508 520
509/* ----------------------------------------------------------- */ 521/* ----------------------------------------------------------- */
diff --git a/drivers/media/video/cx25840/cx25840-core.c b/drivers/media/video/cx25840/cx25840-core.c
index 0be51b65f098..1aeaf18a9bea 100644
--- a/drivers/media/video/cx25840/cx25840-core.c
+++ b/drivers/media/video/cx25840/cx25840-core.c
@@ -321,6 +321,15 @@ static void cx23885_initialize(struct i2c_client *client)
321 /* Select AFE clock pad output source */ 321 /* Select AFE clock pad output source */
322 cx25840_write(client, 0x144, 0x05); 322 cx25840_write(client, 0x144, 0x05);
323 323
324 /* Drive GPIO2 direction and values for HVR1700
325 * where an onboard mux selects the output of demodulator
326 * vs the 417. Failure to set this results in no DTV.
327 * It's safe to set this across all Hauppauge boards
328 * currently, regardless of the board type.
329 */
330 cx25840_write(client, 0x160, 0x1d);
331 cx25840_write(client, 0x164, 0x00);
332
324 /* Do the firmware load in a work handler to prevent. 333 /* Do the firmware load in a work handler to prevent.
325 Otherwise the kernel is blocked waiting for the 334 Otherwise the kernel is blocked waiting for the
326 bit-banging i2c interface to finish uploading the 335 bit-banging i2c interface to finish uploading the
@@ -1578,12 +1587,6 @@ static int cx25840_probe(struct i2c_client *client,
1578 state->id = id; 1587 state->id = id;
1579 state->rev = device_id; 1588 state->rev = device_id;
1580 1589
1581 if (state->is_cx23885) {
1582 /* Drive GPIO2 direction and values */
1583 cx25840_write(client, 0x160, 0x1d);
1584 cx25840_write(client, 0x164, 0x00);
1585 }
1586
1587 return 0; 1590 return 0;
1588} 1591}
1589 1592
diff --git a/drivers/media/video/cx25840/cx25840-firmware.c b/drivers/media/video/cx25840/cx25840-firmware.c
index 0df53b0d75d9..1f483c1d0dbe 100644
--- a/drivers/media/video/cx25840/cx25840-firmware.c
+++ b/drivers/media/video/cx25840/cx25840-firmware.c
@@ -23,10 +23,6 @@
23 23
24#include "cx25840-core.h" 24#include "cx25840-core.h"
25 25
26#define FWFILE "v4l-cx25840.fw"
27#define FWFILE_CX23885 "v4l-cx23885-avcore-01.fw"
28#define FWFILE_CX231XX "v4l-cx231xx-avcore-01.fw"
29
30/* 26/*
31 * Mike Isely <isely@pobox.com> - The FWSEND parameter controls the 27 * Mike Isely <isely@pobox.com> - The FWSEND parameter controls the
32 * size of the firmware chunks sent down the I2C bus to the chip. 28 * size of the firmware chunks sent down the I2C bus to the chip.
@@ -40,11 +36,11 @@
40 36
41#define FWDEV(x) &((x)->dev) 37#define FWDEV(x) &((x)->dev)
42 38
43static char *firmware = FWFILE; 39static char *firmware = "";
44 40
45module_param(firmware, charp, 0444); 41module_param(firmware, charp, 0444);
46 42
47MODULE_PARM_DESC(firmware, "Firmware image [default: " FWFILE "]"); 43MODULE_PARM_DESC(firmware, "Firmware image to load");
48 44
49static void start_fw_load(struct i2c_client *client) 45static void start_fw_load(struct i2c_client *client)
50{ 46{
@@ -65,6 +61,19 @@ static void end_fw_load(struct i2c_client *client)
65 cx25840_write(client, 0x803, 0x03); 61 cx25840_write(client, 0x803, 0x03);
66} 62}
67 63
64static const char *get_fw_name(struct i2c_client *client)
65{
66 struct cx25840_state *state = to_state(i2c_get_clientdata(client));
67
68 if (firmware[0])
69 return firmware;
70 if (state->is_cx23885)
71 return "v4l-cx23885-avcore-01.fw";
72 if (state->is_cx231xx)
73 return "v4l-cx231xx-avcore-01.fw";
74 return "v4l-cx25840.fw";
75}
76
68static int check_fw_load(struct i2c_client *client, int size) 77static int check_fw_load(struct i2c_client *client, int size)
69{ 78{
70 /* DL_ADDR_HB DL_ADDR_LB */ 79 /* DL_ADDR_HB DL_ADDR_LB */
@@ -72,11 +81,13 @@ static int check_fw_load(struct i2c_client *client, int size)
72 s |= cx25840_read(client, 0x800); 81 s |= cx25840_read(client, 0x800);
73 82
74 if (size != s) { 83 if (size != s) {
75 v4l_err(client, "firmware %s load failed\n", firmware); 84 v4l_err(client, "firmware %s load failed\n",
85 get_fw_name(client));
76 return -EINVAL; 86 return -EINVAL;
77 } 87 }
78 88
79 v4l_info(client, "loaded %s firmware (%d bytes)\n", firmware, size); 89 v4l_info(client, "loaded %s firmware (%d bytes)\n",
90 get_fw_name(client), size);
80 return 0; 91 return 0;
81} 92}
82 93
@@ -96,21 +107,24 @@ int cx25840_loadfw(struct i2c_client *client)
96 const struct firmware *fw = NULL; 107 const struct firmware *fw = NULL;
97 u8 buffer[FWSEND]; 108 u8 buffer[FWSEND];
98 const u8 *ptr; 109 const u8 *ptr;
110 const char *fwname = get_fw_name(client);
99 int size, retval; 111 int size, retval;
100 int MAX_BUF_SIZE = FWSEND; 112 int MAX_BUF_SIZE = FWSEND;
113 u32 gpio_oe = 0, gpio_da = 0;
101 114
102 if (state->is_cx23885) 115 if (state->is_cx23885) {
103 firmware = FWFILE_CX23885; 116 /* Preserve the GPIO OE and output bits */
104 else if (state->is_cx231xx) 117 gpio_oe = cx25840_read(client, 0x160);
105 firmware = FWFILE_CX231XX; 118 gpio_da = cx25840_read(client, 0x164);
119 }
106 120
107 if ((state->is_cx231xx) && MAX_BUF_SIZE > 16) { 121 if ((state->is_cx231xx) && MAX_BUF_SIZE > 16) {
108 v4l_err(client, " Firmware download size changed to 16 bytes max length\n"); 122 v4l_err(client, " Firmware download size changed to 16 bytes max length\n");
109 MAX_BUF_SIZE = 16; /* cx231xx cannot accept more than 16 bytes at a time */ 123 MAX_BUF_SIZE = 16; /* cx231xx cannot accept more than 16 bytes at a time */
110 } 124 }
111 125
112 if (request_firmware(&fw, firmware, FWDEV(client)) != 0) { 126 if (request_firmware(&fw, fwname, FWDEV(client)) != 0) {
113 v4l_err(client, "unable to open firmware %s\n", firmware); 127 v4l_err(client, "unable to open firmware %s\n", fwname);
114 return -EINVAL; 128 return -EINVAL;
115 } 129 }
116 130
@@ -142,5 +156,11 @@ int cx25840_loadfw(struct i2c_client *client)
142 size = fw->size; 156 size = fw->size;
143 release_firmware(fw); 157 release_firmware(fw);
144 158
159 if (state->is_cx23885) {
160 /* Restore GPIO configuration after f/w load */
161 cx25840_write(client, 0x160, gpio_oe);
162 cx25840_write(client, 0x164, gpio_da);
163 }
164
145 return check_fw_load(client, size); 165 return check_fw_load(client, size);
146} 166}
diff --git a/drivers/media/video/cx88/cx88-cards.c b/drivers/media/video/cx88/cx88-cards.c
index 39465301ec94..e5f07fbd5a35 100644
--- a/drivers/media/video/cx88/cx88-cards.c
+++ b/drivers/media/video/cx88/cx88-cards.c
@@ -1283,6 +1283,51 @@ static const struct cx88_board cx88_boards[] = {
1283 }, 1283 },
1284 .mpeg = CX88_MPEG_DVB, 1284 .mpeg = CX88_MPEG_DVB,
1285 }, 1285 },
1286 [CX88_BOARD_WINFAST_DTV2000H_J] = {
1287 .name = "WinFast DTV2000 H rev. J",
1288 .tuner_type = TUNER_PHILIPS_FMD1216ME_MK3,
1289 .radio_type = UNSET,
1290 .tuner_addr = ADDR_UNSET,
1291 .radio_addr = ADDR_UNSET,
1292 .tda9887_conf = TDA9887_PRESENT,
1293 .input = {{
1294 .type = CX88_VMUX_TELEVISION,
1295 .vmux = 0,
1296 .gpio0 = 0x00017300,
1297 .gpio1 = 0x00008207,
1298 .gpio2 = 0x00000000,
1299 .gpio3 = 0x02000000,
1300 },{
1301 .type = CX88_VMUX_TELEVISION,
1302 .vmux = 0,
1303 .gpio0 = 0x00018300,
1304 .gpio1 = 0x0000f207,
1305 .gpio2 = 0x00017304,
1306 .gpio3 = 0x02000000,
1307 },{
1308 .type = CX88_VMUX_COMPOSITE1,
1309 .vmux = 1,
1310 .gpio0 = 0x00018301,
1311 .gpio1 = 0x0000f207,
1312 .gpio2 = 0x00017304,
1313 .gpio3 = 0x02000000,
1314 },{
1315 .type = CX88_VMUX_SVIDEO,
1316 .vmux = 2,
1317 .gpio0 = 0x00018301,
1318 .gpio1 = 0x0000f207,
1319 .gpio2 = 0x00017304,
1320 .gpio3 = 0x02000000,
1321 }},
1322 .radio = {
1323 .type = CX88_RADIO,
1324 .gpio0 = 0x00015702,
1325 .gpio1 = 0x0000f207,
1326 .gpio2 = 0x00015702,
1327 .gpio3 = 0x02000000,
1328 },
1329 .mpeg = CX88_MPEG_DVB,
1330 },
1286 [CX88_BOARD_GENIATECH_DVBS] = { 1331 [CX88_BOARD_GENIATECH_DVBS] = {
1287 .name = "Geniatech DVB-S", 1332 .name = "Geniatech DVB-S",
1288 .tuner_type = TUNER_ABSENT, 1333 .tuner_type = TUNER_ABSENT,
@@ -1908,7 +1953,8 @@ static const struct cx88_board cx88_boards[] = {
1908 .radio_addr = ADDR_UNSET, 1953 .radio_addr = ADDR_UNSET,
1909 .input = {{ 1954 .input = {{
1910 .type = CX88_VMUX_DVB, 1955 .type = CX88_VMUX_DVB,
1911 .vmux = 1, 1956 .vmux = 0,
1957 .gpio0 = 0x8080,
1912 } }, 1958 } },
1913 .mpeg = CX88_MPEG_DVB, 1959 .mpeg = CX88_MPEG_DVB,
1914 }, 1960 },
@@ -2282,6 +2328,10 @@ static const struct cx88_subid cx88_subids[] = {
2282 .subdevice = 0x665e, 2328 .subdevice = 0x665e,
2283 .card = CX88_BOARD_WINFAST_DTV2000H, 2329 .card = CX88_BOARD_WINFAST_DTV2000H,
2284 },{ 2330 },{
2331 .subvendor = 0x107d,
2332 .subdevice = 0x6f2b,
2333 .card = CX88_BOARD_WINFAST_DTV2000H_J,
2334 },{
2285 .subvendor = 0x18ac, 2335 .subvendor = 0x18ac,
2286 .subdevice = 0xd800, /* FusionHDTV 3 Gold (original revision) */ 2336 .subdevice = 0xd800, /* FusionHDTV 3 Gold (original revision) */
2287 .card = CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q, 2337 .card = CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q,
@@ -3162,7 +3212,11 @@ static void cx88_card_setup(struct cx88_core *core)
3162 case CX88_BOARD_PROF_6200: 3212 case CX88_BOARD_PROF_6200:
3163 case CX88_BOARD_PROF_7300: 3213 case CX88_BOARD_PROF_7300:
3164 case CX88_BOARD_SATTRADE_ST4200: 3214 case CX88_BOARD_SATTRADE_ST4200:
3215 cx_write(MO_GP0_IO, 0x8000);
3216 msleep(100);
3165 cx_write(MO_SRST_IO, 0); 3217 cx_write(MO_SRST_IO, 0);
3218 msleep(10);
3219 cx_write(MO_GP0_IO, 0x8080);
3166 msleep(100); 3220 msleep(100);
3167 cx_write(MO_SRST_IO, 1); 3221 cx_write(MO_SRST_IO, 1);
3168 msleep(100); 3222 msleep(100);
diff --git a/drivers/media/video/cx88/cx88-dvb.c b/drivers/media/video/cx88/cx88-dvb.c
index e237b507659b..6e5d142b5b00 100644
--- a/drivers/media/video/cx88/cx88-dvb.c
+++ b/drivers/media/video/cx88/cx88-dvb.c
@@ -424,17 +424,16 @@ static int tevii_dvbs_set_voltage(struct dvb_frontend *fe,
424 struct cx8802_dev *dev= fe->dvb->priv; 424 struct cx8802_dev *dev= fe->dvb->priv;
425 struct cx88_core *core = dev->core; 425 struct cx88_core *core = dev->core;
426 426
427 cx_set(MO_GP0_IO, 0x6040);
427 switch (voltage) { 428 switch (voltage) {
428 case SEC_VOLTAGE_13: 429 case SEC_VOLTAGE_13:
429 printk("LNB Voltage SEC_VOLTAGE_13\n"); 430 cx_clear(MO_GP0_IO, 0x20);
430 cx_write(MO_GP0_IO, 0x00006040);
431 break; 431 break;
432 case SEC_VOLTAGE_18: 432 case SEC_VOLTAGE_18:
433 printk("LNB Voltage SEC_VOLTAGE_18\n"); 433 cx_set(MO_GP0_IO, 0x20);
434 cx_write(MO_GP0_IO, 0x00006060);
435 break; 434 break;
436 case SEC_VOLTAGE_OFF: 435 case SEC_VOLTAGE_OFF:
437 printk("LNB Voltage SEC_VOLTAGE_off\n"); 436 cx_clear(MO_GP0_IO, 0x20);
438 break; 437 break;
439 } 438 }
440 439
@@ -499,9 +498,9 @@ static struct zl10353_config cx88_pinnacle_hybrid_pctv = {
499}; 498};
500 499
501static struct zl10353_config cx88_geniatech_x8000_mt = { 500static struct zl10353_config cx88_geniatech_x8000_mt = {
502 .demod_address = (0x1e >> 1), 501 .demod_address = (0x1e >> 1),
503 .no_tuner = 1, 502 .no_tuner = 1,
504 .disable_i2c_gate_ctrl = 1, 503 .disable_i2c_gate_ctrl = 1,
505}; 504};
506 505
507static struct s5h1411_config dvico_fusionhdtv7_config = { 506static struct s5h1411_config dvico_fusionhdtv7_config = {
@@ -696,6 +695,7 @@ static int dvb_register(struct cx8802_dev *dev)
696 } 695 }
697 break; 696 break;
698 case CX88_BOARD_WINFAST_DTV2000H: 697 case CX88_BOARD_WINFAST_DTV2000H:
698 case CX88_BOARD_WINFAST_DTV2000H_J:
699 case CX88_BOARD_HAUPPAUGE_HVR1100: 699 case CX88_BOARD_HAUPPAUGE_HVR1100:
700 case CX88_BOARD_HAUPPAUGE_HVR1100LP: 700 case CX88_BOARD_HAUPPAUGE_HVR1100LP:
701 case CX88_BOARD_HAUPPAUGE_HVR1300: 701 case CX88_BOARD_HAUPPAUGE_HVR1300:
diff --git a/drivers/media/video/cx88/cx88-input.c b/drivers/media/video/cx88/cx88-input.c
index d91f5c51206d..78b3635178af 100644
--- a/drivers/media/video/cx88/cx88-input.c
+++ b/drivers/media/video/cx88/cx88-input.c
@@ -23,7 +23,7 @@
23 */ 23 */
24 24
25#include <linux/init.h> 25#include <linux/init.h>
26#include <linux/delay.h> 26#include <linux/hrtimer.h>
27#include <linux/input.h> 27#include <linux/input.h>
28#include <linux/pci.h> 28#include <linux/pci.h>
29#include <linux/module.h> 29#include <linux/module.h>
@@ -48,7 +48,7 @@ struct cx88_IR {
48 48
49 /* poll external decoder */ 49 /* poll external decoder */
50 int polling; 50 int polling;
51 struct delayed_work work; 51 struct hrtimer timer;
52 u32 gpio_addr; 52 u32 gpio_addr;
53 u32 last_gpio; 53 u32 last_gpio;
54 u32 mask_keycode; 54 u32 mask_keycode;
@@ -144,19 +144,28 @@ static void cx88_ir_handle_key(struct cx88_IR *ir)
144 } 144 }
145} 145}
146 146
147static void cx88_ir_work(struct work_struct *work) 147static enum hrtimer_restart cx88_ir_work(struct hrtimer *timer)
148{ 148{
149 struct cx88_IR *ir = container_of(work, struct cx88_IR, work.work); 149 unsigned long missed;
150 struct cx88_IR *ir = container_of(timer, struct cx88_IR, timer);
150 151
151 cx88_ir_handle_key(ir); 152 cx88_ir_handle_key(ir);
152 schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling)); 153 missed = hrtimer_forward_now(&ir->timer,
154 ktime_set(0, ir->polling * 1000000));
155 if (missed > 1)
156 ir_dprintk("Missed ticks %ld\n", missed - 1);
157
158 return HRTIMER_RESTART;
153} 159}
154 160
155void cx88_ir_start(struct cx88_core *core, struct cx88_IR *ir) 161void cx88_ir_start(struct cx88_core *core, struct cx88_IR *ir)
156{ 162{
157 if (ir->polling) { 163 if (ir->polling) {
158 INIT_DELAYED_WORK(&ir->work, cx88_ir_work); 164 hrtimer_init(&ir->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
159 schedule_delayed_work(&ir->work, 0); 165 ir->timer.function = cx88_ir_work;
166 hrtimer_start(&ir->timer,
167 ktime_set(0, ir->polling * 1000000),
168 HRTIMER_MODE_REL);
160 } 169 }
161 if (ir->sampling) { 170 if (ir->sampling) {
162 core->pci_irqmask |= PCI_INT_IR_SMPINT; 171 core->pci_irqmask |= PCI_INT_IR_SMPINT;
@@ -173,7 +182,7 @@ void cx88_ir_stop(struct cx88_core *core, struct cx88_IR *ir)
173 } 182 }
174 183
175 if (ir->polling) 184 if (ir->polling)
176 cancel_delayed_work_sync(&ir->work); 185 hrtimer_cancel(&ir->timer);
177} 186}
178 187
179/* ---------------------------------------------------------------------- */ 188/* ---------------------------------------------------------------------- */
@@ -182,7 +191,7 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
182{ 191{
183 struct cx88_IR *ir; 192 struct cx88_IR *ir;
184 struct input_dev *input_dev; 193 struct input_dev *input_dev;
185 IR_KEYTAB_TYPE *ir_codes = NULL; 194 struct ir_scancode_table *ir_codes = NULL;
186 int ir_type = IR_TYPE_OTHER; 195 int ir_type = IR_TYPE_OTHER;
187 int err = -ENOMEM; 196 int err = -ENOMEM;
188 197
@@ -198,14 +207,14 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
198 case CX88_BOARD_DNTV_LIVE_DVB_T: 207 case CX88_BOARD_DNTV_LIVE_DVB_T:
199 case CX88_BOARD_KWORLD_DVB_T: 208 case CX88_BOARD_KWORLD_DVB_T:
200 case CX88_BOARD_KWORLD_DVB_T_CX22702: 209 case CX88_BOARD_KWORLD_DVB_T_CX22702:
201 ir_codes = ir_codes_dntv_live_dvb_t; 210 ir_codes = &ir_codes_dntv_live_dvb_t_table;
202 ir->gpio_addr = MO_GP1_IO; 211 ir->gpio_addr = MO_GP1_IO;
203 ir->mask_keycode = 0x1f; 212 ir->mask_keycode = 0x1f;
204 ir->mask_keyup = 0x60; 213 ir->mask_keyup = 0x60;
205 ir->polling = 50; /* ms */ 214 ir->polling = 50; /* ms */
206 break; 215 break;
207 case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1: 216 case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1:
208 ir_codes = ir_codes_cinergy_1400; 217 ir_codes = &ir_codes_cinergy_1400_table;
209 ir_type = IR_TYPE_PD; 218 ir_type = IR_TYPE_PD;
210 ir->sampling = 0xeb04; /* address */ 219 ir->sampling = 0xeb04; /* address */
211 break; 220 break;
@@ -220,13 +229,14 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
220 case CX88_BOARD_PCHDTV_HD3000: 229 case CX88_BOARD_PCHDTV_HD3000:
221 case CX88_BOARD_PCHDTV_HD5500: 230 case CX88_BOARD_PCHDTV_HD5500:
222 case CX88_BOARD_HAUPPAUGE_IRONLY: 231 case CX88_BOARD_HAUPPAUGE_IRONLY:
223 ir_codes = ir_codes_hauppauge_new; 232 ir_codes = &ir_codes_hauppauge_new_table;
224 ir_type = IR_TYPE_RC5; 233 ir_type = IR_TYPE_RC5;
225 ir->sampling = 1; 234 ir->sampling = 1;
226 break; 235 break;
227 case CX88_BOARD_WINFAST_DTV2000H: 236 case CX88_BOARD_WINFAST_DTV2000H:
237 case CX88_BOARD_WINFAST_DTV2000H_J:
228 case CX88_BOARD_WINFAST_DTV1800H: 238 case CX88_BOARD_WINFAST_DTV1800H:
229 ir_codes = ir_codes_winfast; 239 ir_codes = &ir_codes_winfast_table;
230 ir->gpio_addr = MO_GP0_IO; 240 ir->gpio_addr = MO_GP0_IO;
231 ir->mask_keycode = 0x8f8; 241 ir->mask_keycode = 0x8f8;
232 ir->mask_keyup = 0x100; 242 ir->mask_keyup = 0x100;
@@ -235,14 +245,14 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
235 case CX88_BOARD_WINFAST2000XP_EXPERT: 245 case CX88_BOARD_WINFAST2000XP_EXPERT:
236 case CX88_BOARD_WINFAST_DTV1000: 246 case CX88_BOARD_WINFAST_DTV1000:
237 case CX88_BOARD_WINFAST_TV2000_XP_GLOBAL: 247 case CX88_BOARD_WINFAST_TV2000_XP_GLOBAL:
238 ir_codes = ir_codes_winfast; 248 ir_codes = &ir_codes_winfast_table;
239 ir->gpio_addr = MO_GP0_IO; 249 ir->gpio_addr = MO_GP0_IO;
240 ir->mask_keycode = 0x8f8; 250 ir->mask_keycode = 0x8f8;
241 ir->mask_keyup = 0x100; 251 ir->mask_keyup = 0x100;
242 ir->polling = 1; /* ms */ 252 ir->polling = 1; /* ms */
243 break; 253 break;
244 case CX88_BOARD_IODATA_GVBCTV7E: 254 case CX88_BOARD_IODATA_GVBCTV7E:
245 ir_codes = ir_codes_iodata_bctv7e; 255 ir_codes = &ir_codes_iodata_bctv7e_table;
246 ir->gpio_addr = MO_GP0_IO; 256 ir->gpio_addr = MO_GP0_IO;
247 ir->mask_keycode = 0xfd; 257 ir->mask_keycode = 0xfd;
248 ir->mask_keydown = 0x02; 258 ir->mask_keydown = 0x02;
@@ -250,7 +260,7 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
250 break; 260 break;
251 case CX88_BOARD_PROLINK_PLAYTVPVR: 261 case CX88_BOARD_PROLINK_PLAYTVPVR:
252 case CX88_BOARD_PIXELVIEW_PLAYTV_ULTRA_PRO: 262 case CX88_BOARD_PIXELVIEW_PLAYTV_ULTRA_PRO:
253 ir_codes = ir_codes_pixelview; 263 ir_codes = &ir_codes_pixelview_table;
254 ir->gpio_addr = MO_GP1_IO; 264 ir->gpio_addr = MO_GP1_IO;
255 ir->mask_keycode = 0x1f; 265 ir->mask_keycode = 0x1f;
256 ir->mask_keyup = 0x80; 266 ir->mask_keyup = 0x80;
@@ -258,28 +268,28 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
258 break; 268 break;
259 case CX88_BOARD_PROLINK_PV_8000GT: 269 case CX88_BOARD_PROLINK_PV_8000GT:
260 case CX88_BOARD_PROLINK_PV_GLOBAL_XTREME: 270 case CX88_BOARD_PROLINK_PV_GLOBAL_XTREME:
261 ir_codes = ir_codes_pixelview_new; 271 ir_codes = &ir_codes_pixelview_new_table;
262 ir->gpio_addr = MO_GP1_IO; 272 ir->gpio_addr = MO_GP1_IO;
263 ir->mask_keycode = 0x3f; 273 ir->mask_keycode = 0x3f;
264 ir->mask_keyup = 0x80; 274 ir->mask_keyup = 0x80;
265 ir->polling = 1; /* ms */ 275 ir->polling = 1; /* ms */
266 break; 276 break;
267 case CX88_BOARD_KWORLD_LTV883: 277 case CX88_BOARD_KWORLD_LTV883:
268 ir_codes = ir_codes_pixelview; 278 ir_codes = &ir_codes_pixelview_table;
269 ir->gpio_addr = MO_GP1_IO; 279 ir->gpio_addr = MO_GP1_IO;
270 ir->mask_keycode = 0x1f; 280 ir->mask_keycode = 0x1f;
271 ir->mask_keyup = 0x60; 281 ir->mask_keyup = 0x60;
272 ir->polling = 1; /* ms */ 282 ir->polling = 1; /* ms */
273 break; 283 break;
274 case CX88_BOARD_ADSTECH_DVB_T_PCI: 284 case CX88_BOARD_ADSTECH_DVB_T_PCI:
275 ir_codes = ir_codes_adstech_dvb_t_pci; 285 ir_codes = &ir_codes_adstech_dvb_t_pci_table;
276 ir->gpio_addr = MO_GP1_IO; 286 ir->gpio_addr = MO_GP1_IO;
277 ir->mask_keycode = 0xbf; 287 ir->mask_keycode = 0xbf;
278 ir->mask_keyup = 0x40; 288 ir->mask_keyup = 0x40;
279 ir->polling = 50; /* ms */ 289 ir->polling = 50; /* ms */
280 break; 290 break;
281 case CX88_BOARD_MSI_TVANYWHERE_MASTER: 291 case CX88_BOARD_MSI_TVANYWHERE_MASTER:
282 ir_codes = ir_codes_msi_tvanywhere; 292 ir_codes = &ir_codes_msi_tvanywhere_table;
283 ir->gpio_addr = MO_GP1_IO; 293 ir->gpio_addr = MO_GP1_IO;
284 ir->mask_keycode = 0x1f; 294 ir->mask_keycode = 0x1f;
285 ir->mask_keyup = 0x40; 295 ir->mask_keyup = 0x40;
@@ -287,40 +297,40 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
287 break; 297 break;
288 case CX88_BOARD_AVERTV_303: 298 case CX88_BOARD_AVERTV_303:
289 case CX88_BOARD_AVERTV_STUDIO_303: 299 case CX88_BOARD_AVERTV_STUDIO_303:
290 ir_codes = ir_codes_avertv_303; 300 ir_codes = &ir_codes_avertv_303_table;
291 ir->gpio_addr = MO_GP2_IO; 301 ir->gpio_addr = MO_GP2_IO;
292 ir->mask_keycode = 0xfb; 302 ir->mask_keycode = 0xfb;
293 ir->mask_keydown = 0x02; 303 ir->mask_keydown = 0x02;
294 ir->polling = 50; /* ms */ 304 ir->polling = 50; /* ms */
295 break; 305 break;
296 case CX88_BOARD_DNTV_LIVE_DVB_T_PRO: 306 case CX88_BOARD_DNTV_LIVE_DVB_T_PRO:
297 ir_codes = ir_codes_dntv_live_dvbt_pro; 307 ir_codes = &ir_codes_dntv_live_dvbt_pro_table;
298 ir_type = IR_TYPE_PD; 308 ir_type = IR_TYPE_PD;
299 ir->sampling = 0xff00; /* address */ 309 ir->sampling = 0xff00; /* address */
300 break; 310 break;
301 case CX88_BOARD_NORWOOD_MICRO: 311 case CX88_BOARD_NORWOOD_MICRO:
302 ir_codes = ir_codes_norwood; 312 ir_codes = &ir_codes_norwood_table;
303 ir->gpio_addr = MO_GP1_IO; 313 ir->gpio_addr = MO_GP1_IO;
304 ir->mask_keycode = 0x0e; 314 ir->mask_keycode = 0x0e;
305 ir->mask_keyup = 0x80; 315 ir->mask_keyup = 0x80;
306 ir->polling = 50; /* ms */ 316 ir->polling = 50; /* ms */
307 break; 317 break;
308 case CX88_BOARD_NPGTECH_REALTV_TOP10FM: 318 case CX88_BOARD_NPGTECH_REALTV_TOP10FM:
309 ir_codes = ir_codes_npgtech; 319 ir_codes = &ir_codes_npgtech_table;
310 ir->gpio_addr = MO_GP0_IO; 320 ir->gpio_addr = MO_GP0_IO;
311 ir->mask_keycode = 0xfa; 321 ir->mask_keycode = 0xfa;
312 ir->polling = 50; /* ms */ 322 ir->polling = 50; /* ms */
313 break; 323 break;
314 case CX88_BOARD_PINNACLE_PCTV_HD_800i: 324 case CX88_BOARD_PINNACLE_PCTV_HD_800i:
315 ir_codes = ir_codes_pinnacle_pctv_hd; 325 ir_codes = &ir_codes_pinnacle_pctv_hd_table;
316 ir_type = IR_TYPE_RC5; 326 ir_type = IR_TYPE_RC5;
317 ir->sampling = 1; 327 ir->sampling = 1;
318 break; 328 break;
319 case CX88_BOARD_POWERCOLOR_REAL_ANGEL: 329 case CX88_BOARD_POWERCOLOR_REAL_ANGEL:
320 ir_codes = ir_codes_powercolor_real_angel; 330 ir_codes = &ir_codes_powercolor_real_angel_table;
321 ir->gpio_addr = MO_GP2_IO; 331 ir->gpio_addr = MO_GP2_IO;
322 ir->mask_keycode = 0x7e; 332 ir->mask_keycode = 0x7e;
323 ir->polling = 100; /* ms */ 333 ir->polling = 100; /* ms */
324 break; 334 break;
325 } 335 }
326 336
diff --git a/drivers/media/video/cx88/cx88.h b/drivers/media/video/cx88/cx88.h
index 9d83762163f5..d5cea41f4207 100644
--- a/drivers/media/video/cx88/cx88.h
+++ b/drivers/media/video/cx88/cx88.h
@@ -237,6 +237,7 @@ extern struct sram_channel cx88_sram_channels[];
237#define CX88_BOARD_TERRATEC_CINERGY_HT_PCI_MKII 79 237#define CX88_BOARD_TERRATEC_CINERGY_HT_PCI_MKII 79
238#define CX88_BOARD_HAUPPAUGE_IRONLY 80 238#define CX88_BOARD_HAUPPAUGE_IRONLY 80
239#define CX88_BOARD_WINFAST_DTV1800H 81 239#define CX88_BOARD_WINFAST_DTV1800H 81
240#define CX88_BOARD_WINFAST_DTV2000H_J 82
240 241
241enum cx88_itype { 242enum cx88_itype {
242 CX88_VMUX_COMPOSITE1 = 1, 243 CX88_VMUX_COMPOSITE1 = 1,
diff --git a/drivers/media/video/em28xx/em28xx-cards.c b/drivers/media/video/em28xx/em28xx-cards.c
index 1c2e544eda73..7e3c78239fa9 100644
--- a/drivers/media/video/em28xx/em28xx-cards.c
+++ b/drivers/media/video/em28xx/em28xx-cards.c
@@ -299,6 +299,7 @@ struct em28xx_board em28xx_boards[] = {
299 [EM2820_BOARD_TERRATEC_CINERGY_250] = { 299 [EM2820_BOARD_TERRATEC_CINERGY_250] = {
300 .name = "Terratec Cinergy 250 USB", 300 .name = "Terratec Cinergy 250 USB",
301 .tuner_type = TUNER_LG_PAL_NEW_TAPC, 301 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
302 .has_ir_i2c = 1,
302 .tda9887_conf = TDA9887_PRESENT, 303 .tda9887_conf = TDA9887_PRESENT,
303 .decoder = EM28XX_SAA711X, 304 .decoder = EM28XX_SAA711X,
304 .input = { { 305 .input = { {
@@ -318,6 +319,7 @@ struct em28xx_board em28xx_boards[] = {
318 [EM2820_BOARD_PINNACLE_USB_2] = { 319 [EM2820_BOARD_PINNACLE_USB_2] = {
319 .name = "Pinnacle PCTV USB 2", 320 .name = "Pinnacle PCTV USB 2",
320 .tuner_type = TUNER_LG_PAL_NEW_TAPC, 321 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
322 .has_ir_i2c = 1,
321 .tda9887_conf = TDA9887_PRESENT, 323 .tda9887_conf = TDA9887_PRESENT,
322 .decoder = EM28XX_SAA711X, 324 .decoder = EM28XX_SAA711X,
323 .input = { { 325 .input = { {
@@ -342,6 +344,7 @@ struct em28xx_board em28xx_boards[] = {
342 TDA9887_PORT2_ACTIVE, 344 TDA9887_PORT2_ACTIVE,
343 .decoder = EM28XX_TVP5150, 345 .decoder = EM28XX_TVP5150,
344 .has_msp34xx = 1, 346 .has_msp34xx = 1,
347 .has_ir_i2c = 1,
345 .input = { { 348 .input = { {
346 .type = EM28XX_VMUX_TELEVISION, 349 .type = EM28XX_VMUX_TELEVISION,
347 .vmux = TVP5150_COMPOSITE0, 350 .vmux = TVP5150_COMPOSITE0,
@@ -558,6 +561,27 @@ struct em28xx_board em28xx_boards[] = {
558 .amux = EM28XX_AMUX_LINE_IN, 561 .amux = EM28XX_AMUX_LINE_IN,
559 } }, 562 } },
560 }, 563 },
564 [EM2861_BOARD_GADMEI_UTV330PLUS] = {
565 .name = "Gadmei UTV330+",
566 .tuner_type = TUNER_TNF_5335MF,
567 .tda9887_conf = TDA9887_PRESENT,
568 .ir_codes = &ir_codes_gadmei_rm008z_table,
569 .decoder = EM28XX_SAA711X,
570 .xclk = EM28XX_XCLK_FREQUENCY_12MHZ,
571 .input = { {
572 .type = EM28XX_VMUX_TELEVISION,
573 .vmux = SAA7115_COMPOSITE2,
574 .amux = EM28XX_AMUX_VIDEO,
575 }, {
576 .type = EM28XX_VMUX_COMPOSITE1,
577 .vmux = SAA7115_COMPOSITE0,
578 .amux = EM28XX_AMUX_LINE_IN,
579 }, {
580 .type = EM28XX_VMUX_SVIDEO,
581 .vmux = SAA7115_SVIDEO3,
582 .amux = EM28XX_AMUX_LINE_IN,
583 } },
584 },
561 [EM2860_BOARD_TERRATEC_HYBRID_XS] = { 585 [EM2860_BOARD_TERRATEC_HYBRID_XS] = {
562 .name = "Terratec Cinergy A Hybrid XS", 586 .name = "Terratec Cinergy A Hybrid XS",
563 .valid = EM28XX_BOARD_NOT_VALIDATED, 587 .valid = EM28XX_BOARD_NOT_VALIDATED,
@@ -715,7 +739,7 @@ struct em28xx_board em28xx_boards[] = {
715 .mts_firmware = 1, 739 .mts_firmware = 1,
716 .has_dvb = 1, 740 .has_dvb = 1,
717 .dvb_gpio = hauppauge_wintv_hvr_900_digital, 741 .dvb_gpio = hauppauge_wintv_hvr_900_digital,
718 .ir_codes = ir_codes_hauppauge_new, 742 .ir_codes = &ir_codes_hauppauge_new_table,
719 .decoder = EM28XX_TVP5150, 743 .decoder = EM28XX_TVP5150,
720 .input = { { 744 .input = { {
721 .type = EM28XX_VMUX_TELEVISION, 745 .type = EM28XX_VMUX_TELEVISION,
@@ -740,7 +764,7 @@ struct em28xx_board em28xx_boards[] = {
740 .tuner_type = TUNER_XC2028, 764 .tuner_type = TUNER_XC2028,
741 .tuner_gpio = default_tuner_gpio, 765 .tuner_gpio = default_tuner_gpio,
742 .mts_firmware = 1, 766 .mts_firmware = 1,
743 .ir_codes = ir_codes_hauppauge_new, 767 .ir_codes = &ir_codes_hauppauge_new_table,
744 .decoder = EM28XX_TVP5150, 768 .decoder = EM28XX_TVP5150,
745 .input = { { 769 .input = { {
746 .type = EM28XX_VMUX_TELEVISION, 770 .type = EM28XX_VMUX_TELEVISION,
@@ -766,7 +790,7 @@ struct em28xx_board em28xx_boards[] = {
766 .mts_firmware = 1, 790 .mts_firmware = 1,
767 .has_dvb = 1, 791 .has_dvb = 1,
768 .dvb_gpio = hauppauge_wintv_hvr_900_digital, 792 .dvb_gpio = hauppauge_wintv_hvr_900_digital,
769 .ir_codes = ir_codes_hauppauge_new, 793 .ir_codes = &ir_codes_hauppauge_new_table,
770 .decoder = EM28XX_TVP5150, 794 .decoder = EM28XX_TVP5150,
771 .input = { { 795 .input = { {
772 .type = EM28XX_VMUX_TELEVISION, 796 .type = EM28XX_VMUX_TELEVISION,
@@ -792,7 +816,7 @@ struct em28xx_board em28xx_boards[] = {
792 .mts_firmware = 1, 816 .mts_firmware = 1,
793 .has_dvb = 1, 817 .has_dvb = 1,
794 .dvb_gpio = hauppauge_wintv_hvr_900_digital, 818 .dvb_gpio = hauppauge_wintv_hvr_900_digital,
795 .ir_codes = ir_codes_hauppauge_new, 819 .ir_codes = &ir_codes_hauppauge_new_table,
796 .decoder = EM28XX_TVP5150, 820 .decoder = EM28XX_TVP5150,
797 .input = { { 821 .input = { {
798 .type = EM28XX_VMUX_TELEVISION, 822 .type = EM28XX_VMUX_TELEVISION,
@@ -818,7 +842,7 @@ struct em28xx_board em28xx_boards[] = {
818 .mts_firmware = 1, 842 .mts_firmware = 1,
819 .has_dvb = 1, 843 .has_dvb = 1,
820 .dvb_gpio = hauppauge_wintv_hvr_900_digital, 844 .dvb_gpio = hauppauge_wintv_hvr_900_digital,
821 .ir_codes = ir_codes_pinnacle_pctv_hd, 845 .ir_codes = &ir_codes_pinnacle_pctv_hd_table,
822 .decoder = EM28XX_TVP5150, 846 .decoder = EM28XX_TVP5150,
823 .input = { { 847 .input = { {
824 .type = EM28XX_VMUX_TELEVISION, 848 .type = EM28XX_VMUX_TELEVISION,
@@ -844,7 +868,7 @@ struct em28xx_board em28xx_boards[] = {
844 .mts_firmware = 1, 868 .mts_firmware = 1,
845 .has_dvb = 1, 869 .has_dvb = 1,
846 .dvb_gpio = hauppauge_wintv_hvr_900_digital, 870 .dvb_gpio = hauppauge_wintv_hvr_900_digital,
847 .ir_codes = ir_codes_ati_tv_wonder_hd_600, 871 .ir_codes = &ir_codes_ati_tv_wonder_hd_600_table,
848 .decoder = EM28XX_TVP5150, 872 .decoder = EM28XX_TVP5150,
849 .input = { { 873 .input = { {
850 .type = EM28XX_VMUX_TELEVISION, 874 .type = EM28XX_VMUX_TELEVISION,
@@ -870,6 +894,8 @@ struct em28xx_board em28xx_boards[] = {
870 .decoder = EM28XX_TVP5150, 894 .decoder = EM28XX_TVP5150,
871 .has_dvb = 1, 895 .has_dvb = 1,
872 .dvb_gpio = default_digital, 896 .dvb_gpio = default_digital,
897 .ir_codes = &ir_codes_terratec_cinergy_xs_table,
898 .xclk = EM28XX_XCLK_FREQUENCY_12MHZ, /* NEC IR */
873 .input = { { 899 .input = { {
874 .type = EM28XX_VMUX_TELEVISION, 900 .type = EM28XX_VMUX_TELEVISION,
875 .vmux = TVP5150_COMPOSITE0, 901 .vmux = TVP5150_COMPOSITE0,
@@ -937,6 +963,7 @@ struct em28xx_board em28xx_boards[] = {
937 [EM2800_BOARD_TERRATEC_CINERGY_200] = { 963 [EM2800_BOARD_TERRATEC_CINERGY_200] = {
938 .name = "Terratec Cinergy 200 USB", 964 .name = "Terratec Cinergy 200 USB",
939 .is_em2800 = 1, 965 .is_em2800 = 1,
966 .has_ir_i2c = 1,
940 .tuner_type = TUNER_LG_PAL_NEW_TAPC, 967 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
941 .tda9887_conf = TDA9887_PRESENT, 968 .tda9887_conf = TDA9887_PRESENT,
942 .decoder = EM28XX_SAA711X, 969 .decoder = EM28XX_SAA711X,
@@ -1010,7 +1037,8 @@ struct em28xx_board em28xx_boards[] = {
1010 } }, 1037 } },
1011 }, 1038 },
1012 [EM2820_BOARD_PINNACLE_DVC_90] = { 1039 [EM2820_BOARD_PINNACLE_DVC_90] = {
1013 .name = "Pinnacle Dazzle DVC 90/100/101/107 / Kaiser Baas Video to DVD maker", 1040 .name = "Pinnacle Dazzle DVC 90/100/101/107 / Kaiser Baas Video to DVD maker "
1041 "/ Kworld DVD Maker 2",
1014 .tuner_type = TUNER_ABSENT, /* capture only board */ 1042 .tuner_type = TUNER_ABSENT, /* capture only board */
1015 .decoder = EM28XX_SAA711X, 1043 .decoder = EM28XX_SAA711X,
1016 .input = { { 1044 .input = { {
@@ -1420,7 +1448,7 @@ struct em28xx_board em28xx_boards[] = {
1420 .mts_firmware = 1, 1448 .mts_firmware = 1,
1421 .decoder = EM28XX_TVP5150, 1449 .decoder = EM28XX_TVP5150,
1422 .tuner_gpio = default_tuner_gpio, 1450 .tuner_gpio = default_tuner_gpio,
1423 .ir_codes = ir_codes_kaiomy, 1451 .ir_codes = &ir_codes_kaiomy_table,
1424 .input = { { 1452 .input = { {
1425 .type = EM28XX_VMUX_TELEVISION, 1453 .type = EM28XX_VMUX_TELEVISION,
1426 .vmux = TVP5150_COMPOSITE0, 1454 .vmux = TVP5150_COMPOSITE0,
@@ -1520,7 +1548,7 @@ struct em28xx_board em28xx_boards[] = {
1520 .mts_firmware = 1, 1548 .mts_firmware = 1,
1521 .has_dvb = 1, 1549 .has_dvb = 1,
1522 .dvb_gpio = evga_indtube_digital, 1550 .dvb_gpio = evga_indtube_digital,
1523 .ir_codes = ir_codes_evga_indtube, 1551 .ir_codes = &ir_codes_evga_indtube_table,
1524 .input = { { 1552 .input = { {
1525 .type = EM28XX_VMUX_TELEVISION, 1553 .type = EM28XX_VMUX_TELEVISION,
1526 .vmux = TVP5150_COMPOSITE0, 1554 .vmux = TVP5150_COMPOSITE0,
@@ -1591,6 +1619,8 @@ struct usb_device_id em28xx_id_table[] = {
1591 .driver_info = EM2870_BOARD_KWORLD_355U }, 1619 .driver_info = EM2870_BOARD_KWORLD_355U },
1592 { USB_DEVICE(0x1b80, 0xe302), 1620 { USB_DEVICE(0x1b80, 0xe302),
1593 .driver_info = EM2820_BOARD_PINNACLE_DVC_90 }, /* Kaiser Baas Video to DVD maker */ 1621 .driver_info = EM2820_BOARD_PINNACLE_DVC_90 }, /* Kaiser Baas Video to DVD maker */
1622 { USB_DEVICE(0x1b80, 0xe304),
1623 .driver_info = EM2820_BOARD_PINNACLE_DVC_90 }, /* Kworld DVD Maker 2 */
1594 { USB_DEVICE(0x0ccd, 0x0036), 1624 { USB_DEVICE(0x0ccd, 0x0036),
1595 .driver_info = EM2820_BOARD_TERRATEC_CINERGY_250 }, 1625 .driver_info = EM2820_BOARD_TERRATEC_CINERGY_250 },
1596 { USB_DEVICE(0x0ccd, 0x004c), 1626 { USB_DEVICE(0x0ccd, 0x004c),
@@ -1649,6 +1679,8 @@ struct usb_device_id em28xx_id_table[] = {
1649 .driver_info = EM2861_BOARD_PLEXTOR_PX_TV100U }, 1679 .driver_info = EM2861_BOARD_PLEXTOR_PX_TV100U },
1650 { USB_DEVICE(0x04bb, 0x0515), 1680 { USB_DEVICE(0x04bb, 0x0515),
1651 .driver_info = EM2820_BOARD_IODATA_GVMVP_SZ }, 1681 .driver_info = EM2820_BOARD_IODATA_GVMVP_SZ },
1682 { USB_DEVICE(0xeb1a, 0x50a6),
1683 .driver_info = EM2860_BOARD_GADMEI_UTV330 },
1652 { }, 1684 { },
1653}; 1685};
1654MODULE_DEVICE_TABLE(usb, em28xx_id_table); 1686MODULE_DEVICE_TABLE(usb, em28xx_id_table);
@@ -1661,7 +1693,7 @@ static struct em28xx_hash_table em28xx_eeprom_hash[] = {
1661 {0x6ce05a8f, EM2820_BOARD_PROLINK_PLAYTV_USB2, TUNER_YMEC_TVF_5533MF}, 1693 {0x6ce05a8f, EM2820_BOARD_PROLINK_PLAYTV_USB2, TUNER_YMEC_TVF_5533MF},
1662 {0x72cc5a8b, EM2820_BOARD_PROLINK_PLAYTV_BOX4_USB2, TUNER_YMEC_TVF_5533MF}, 1694 {0x72cc5a8b, EM2820_BOARD_PROLINK_PLAYTV_BOX4_USB2, TUNER_YMEC_TVF_5533MF},
1663 {0x966a0441, EM2880_BOARD_KWORLD_DVB_310U, TUNER_XC2028}, 1695 {0x966a0441, EM2880_BOARD_KWORLD_DVB_310U, TUNER_XC2028},
1664 {0x9567eb1a, EM2880_BOARD_EMPIRE_DUAL_TV, TUNER_XC2028}, 1696 {0x166a0441, EM2880_BOARD_EMPIRE_DUAL_TV, TUNER_XC2028},
1665 {0xcee44a99, EM2882_BOARD_EVGA_INDTUBE, TUNER_XC2028}, 1697 {0xcee44a99, EM2882_BOARD_EVGA_INDTUBE, TUNER_XC2028},
1666 {0xb8846b20, EM2881_BOARD_PINNACLE_HYBRID_PRO, TUNER_XC2028}, 1698 {0xb8846b20, EM2881_BOARD_PINNACLE_HYBRID_PRO, TUNER_XC2028},
1667}; 1699};
@@ -1672,6 +1704,7 @@ static struct em28xx_hash_table em28xx_i2c_hash[] = {
1672 {0xf51200e3, EM2800_BOARD_VGEAR_POCKETTV, TUNER_LG_PAL_NEW_TAPC}, 1704 {0xf51200e3, EM2800_BOARD_VGEAR_POCKETTV, TUNER_LG_PAL_NEW_TAPC},
1673 {0x1ba50080, EM2860_BOARD_SAA711X_REFERENCE_DESIGN, TUNER_ABSENT}, 1705 {0x1ba50080, EM2860_BOARD_SAA711X_REFERENCE_DESIGN, TUNER_ABSENT},
1674 {0xc51200e3, EM2820_BOARD_GADMEI_TVR200, TUNER_LG_PAL_NEW_TAPC}, 1706 {0xc51200e3, EM2820_BOARD_GADMEI_TVR200, TUNER_LG_PAL_NEW_TAPC},
1707 {0x4ba50080, EM2861_BOARD_GADMEI_UTV330PLUS, TUNER_TNF_5335MF},
1675}; 1708};
1676 1709
1677/* I2C possible address to saa7115, tvp5150, msp3400, tvaudio */ 1710/* I2C possible address to saa7115, tvp5150, msp3400, tvaudio */
@@ -2170,8 +2203,6 @@ static int em28xx_hint_board(struct em28xx *dev)
2170/* ----------------------------------------------------------------------- */ 2203/* ----------------------------------------------------------------------- */
2171void em28xx_register_i2c_ir(struct em28xx *dev) 2204void em28xx_register_i2c_ir(struct em28xx *dev)
2172{ 2205{
2173 struct i2c_board_info info;
2174 struct IR_i2c_init_data init_data;
2175 const unsigned short addr_list[] = { 2206 const unsigned short addr_list[] = {
2176 0x30, 0x47, I2C_CLIENT_END 2207 0x30, 0x47, I2C_CLIENT_END
2177 }; 2208 };
@@ -2179,45 +2210,33 @@ void em28xx_register_i2c_ir(struct em28xx *dev)
2179 if (disable_ir) 2210 if (disable_ir)
2180 return; 2211 return;
2181 2212
2182 memset(&info, 0, sizeof(struct i2c_board_info)); 2213 memset(&dev->info, 0, sizeof(&dev->info));
2183 memset(&init_data, 0, sizeof(struct IR_i2c_init_data)); 2214 memset(&dev->init_data, 0, sizeof(dev->init_data));
2184 strlcpy(info.type, "ir_video", I2C_NAME_SIZE); 2215 strlcpy(dev->info.type, "ir_video", I2C_NAME_SIZE);
2185 2216
2186 /* detect & configure */ 2217 /* detect & configure */
2187 switch (dev->model) { 2218 switch (dev->model) {
2188 case (EM2800_BOARD_UNKNOWN): 2219 case EM2800_BOARD_TERRATEC_CINERGY_200:
2189 break; 2220 case EM2820_BOARD_TERRATEC_CINERGY_250:
2190 case (EM2820_BOARD_UNKNOWN): 2221 dev->init_data.ir_codes = &ir_codes_em_terratec_table;
2191 break; 2222 dev->init_data.get_key = em28xx_get_key_terratec;
2192 case (EM2800_BOARD_TERRATEC_CINERGY_200): 2223 dev->init_data.name = "i2c IR (EM28XX Terratec)";
2193 case (EM2820_BOARD_TERRATEC_CINERGY_250):
2194 init_data.ir_codes = ir_codes_em_terratec;
2195 init_data.get_key = em28xx_get_key_terratec;
2196 init_data.name = "i2c IR (EM28XX Terratec)";
2197 break;
2198 case (EM2820_BOARD_PINNACLE_USB_2):
2199 init_data.ir_codes = ir_codes_pinnacle_grey;
2200 init_data.get_key = em28xx_get_key_pinnacle_usb_grey;
2201 init_data.name = "i2c IR (EM28XX Pinnacle PCTV)";
2202 break;
2203 case (EM2820_BOARD_HAUPPAUGE_WINTV_USB_2):
2204 init_data.ir_codes = ir_codes_hauppauge_new;
2205 init_data.get_key = em28xx_get_key_em_haup;
2206 init_data.name = "i2c IR (EM2840 Hauppauge)";
2207 break; 2224 break;
2208 case (EM2820_BOARD_MSI_VOX_USB_2): 2225 case EM2820_BOARD_PINNACLE_USB_2:
2226 dev->init_data.ir_codes = &ir_codes_pinnacle_grey_table;
2227 dev->init_data.get_key = em28xx_get_key_pinnacle_usb_grey;
2228 dev->init_data.name = "i2c IR (EM28XX Pinnacle PCTV)";
2209 break; 2229 break;
2210 case (EM2800_BOARD_LEADTEK_WINFAST_USBII): 2230 case EM2820_BOARD_HAUPPAUGE_WINTV_USB_2:
2211 break; 2231 dev->init_data.ir_codes = &ir_codes_hauppauge_new_table;
2212 case (EM2800_BOARD_KWORLD_USB2800): 2232 dev->init_data.get_key = em28xx_get_key_em_haup;
2213 break; 2233 dev->init_data.name = "i2c IR (EM2840 Hauppauge)";
2214 case (EM2800_BOARD_GRABBEEX_USB2800):
2215 break; 2234 break;
2216 } 2235 }
2217 2236
2218 if (init_data.name) 2237 if (dev->init_data.name)
2219 info.platform_data = &init_data; 2238 dev->info.platform_data = &dev->init_data;
2220 i2c_new_probed_device(&dev->i2c_adap, &info, addr_list); 2239 i2c_new_probed_device(&dev->i2c_adap, &dev->info, addr_list);
2221} 2240}
2222 2241
2223void em28xx_card_setup(struct em28xx *dev) 2242void em28xx_card_setup(struct em28xx *dev)
@@ -2253,7 +2272,7 @@ void em28xx_card_setup(struct em28xx *dev)
2253 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950: 2272 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
2254 { 2273 {
2255 struct tveeprom tv; 2274 struct tveeprom tv;
2256#ifdef CONFIG_MODULES 2275#if defined(CONFIG_MODULES) && defined(MODULE)
2257 request_module("tveeprom"); 2276 request_module("tveeprom");
2258#endif 2277#endif
2259 /* Call first TVeeprom */ 2278 /* Call first TVeeprom */
@@ -2267,10 +2286,6 @@ void em28xx_card_setup(struct em28xx *dev)
2267 dev->i2s_speed = 2048000; 2286 dev->i2s_speed = 2048000;
2268 dev->board.has_msp34xx = 1; 2287 dev->board.has_msp34xx = 1;
2269 } 2288 }
2270#ifdef CONFIG_MODULES
2271 if (tv.has_ir)
2272 request_module("ir-kbd-i2c");
2273#endif
2274 break; 2289 break;
2275 } 2290 }
2276 case EM2882_BOARD_KWORLD_ATSC_315U: 2291 case EM2882_BOARD_KWORLD_ATSC_315U:
@@ -2311,6 +2326,10 @@ void em28xx_card_setup(struct em28xx *dev)
2311 break; 2326 break;
2312 } 2327 }
2313 2328
2329#if defined(CONFIG_MODULES) && defined(MODULE)
2330 if (dev->board.has_ir_i2c && !disable_ir)
2331 request_module("ir-kbd-i2c");
2332#endif
2314 if (dev->board.has_snapshot_button) 2333 if (dev->board.has_snapshot_button)
2315 em28xx_register_snapshot_button(dev); 2334 em28xx_register_snapshot_button(dev);
2316 2335
diff --git a/drivers/media/video/em28xx/em28xx-i2c.c b/drivers/media/video/em28xx/em28xx-i2c.c
index 27e33a287dfc..71474d31e155 100644
--- a/drivers/media/video/em28xx/em28xx-i2c.c
+++ b/drivers/media/video/em28xx/em28xx-i2c.c
@@ -459,7 +459,6 @@ static struct i2c_algorithm em28xx_algo = {
459static struct i2c_adapter em28xx_adap_template = { 459static struct i2c_adapter em28xx_adap_template = {
460 .owner = THIS_MODULE, 460 .owner = THIS_MODULE,
461 .name = "em28xx", 461 .name = "em28xx",
462 .id = I2C_HW_B_EM28XX,
463 .algo = &em28xx_algo, 462 .algo = &em28xx_algo,
464}; 463};
465 464
diff --git a/drivers/media/video/em28xx/em28xx-video.c b/drivers/media/video/em28xx/em28xx-video.c
index ab079d9256c4..a6bdbc21410e 100644
--- a/drivers/media/video/em28xx/em28xx-video.c
+++ b/drivers/media/video/em28xx/em28xx-video.c
@@ -124,7 +124,7 @@ static struct em28xx_fmt format[] = {
124 124
125/* supported controls */ 125/* supported controls */
126/* Common to all boards */ 126/* Common to all boards */
127static struct v4l2_queryctrl em28xx_qctrl[] = { 127static struct v4l2_queryctrl ac97_qctrl[] = {
128 { 128 {
129 .id = V4L2_CID_AUDIO_VOLUME, 129 .id = V4L2_CID_AUDIO_VOLUME,
130 .type = V4L2_CTRL_TYPE_INTEGER, 130 .type = V4L2_CTRL_TYPE_INTEGER,
@@ -133,7 +133,7 @@ static struct v4l2_queryctrl em28xx_qctrl[] = {
133 .maximum = 0x1f, 133 .maximum = 0x1f,
134 .step = 0x1, 134 .step = 0x1,
135 .default_value = 0x1f, 135 .default_value = 0x1f,
136 .flags = 0, 136 .flags = V4L2_CTRL_FLAG_SLIDER,
137 }, { 137 }, {
138 .id = V4L2_CID_AUDIO_MUTE, 138 .id = V4L2_CID_AUDIO_MUTE,
139 .type = V4L2_CTRL_TYPE_BOOLEAN, 139 .type = V4L2_CTRL_TYPE_BOOLEAN,
@@ -609,10 +609,29 @@ static void res_free(struct em28xx_fh *fh)
609} 609}
610 610
611/* 611/*
612 * em28xx_get_ctrl() 612 * ac97_queryctrl()
613 * return the current saturation, brightness or contrast, mute state 613 * return the ac97 supported controls
614 */ 614 */
615static int em28xx_get_ctrl(struct em28xx *dev, struct v4l2_control *ctrl) 615static int ac97_queryctrl(struct v4l2_queryctrl *qc)
616{
617 int i;
618
619 for (i = 0; i < ARRAY_SIZE(ac97_qctrl); i++) {
620 if (qc->id && qc->id == ac97_qctrl[i].id) {
621 memcpy(qc, &(ac97_qctrl[i]), sizeof(*qc));
622 return 0;
623 }
624 }
625
626 /* Control is not ac97 related */
627 return 1;
628}
629
630/*
631 * ac97_get_ctrl()
632 * return the current values for ac97 mute and volume
633 */
634static int ac97_get_ctrl(struct em28xx *dev, struct v4l2_control *ctrl)
616{ 635{
617 switch (ctrl->id) { 636 switch (ctrl->id) {
618 case V4L2_CID_AUDIO_MUTE: 637 case V4L2_CID_AUDIO_MUTE:
@@ -622,29 +641,41 @@ static int em28xx_get_ctrl(struct em28xx *dev, struct v4l2_control *ctrl)
622 ctrl->value = dev->volume; 641 ctrl->value = dev->volume;
623 return 0; 642 return 0;
624 default: 643 default:
625 return -EINVAL; 644 /* Control is not ac97 related */
645 return 1;
626 } 646 }
627} 647}
628 648
629/* 649/*
630 * em28xx_set_ctrl() 650 * ac97_set_ctrl()
631 * mute or set new saturation, brightness or contrast 651 * set values for ac97 mute and volume
632 */ 652 */
633static int em28xx_set_ctrl(struct em28xx *dev, const struct v4l2_control *ctrl) 653static int ac97_set_ctrl(struct em28xx *dev, const struct v4l2_control *ctrl)
634{ 654{
655 int i;
656
657 for (i = 0; i < ARRAY_SIZE(ac97_qctrl); i++)
658 if (ctrl->id == ac97_qctrl[i].id)
659 goto handle;
660
661 /* Announce that hasn't handle it */
662 return 1;
663
664handle:
665 if (ctrl->value < ac97_qctrl[i].minimum ||
666 ctrl->value > ac97_qctrl[i].maximum)
667 return -ERANGE;
668
635 switch (ctrl->id) { 669 switch (ctrl->id) {
636 case V4L2_CID_AUDIO_MUTE: 670 case V4L2_CID_AUDIO_MUTE:
637 if (ctrl->value != dev->mute) { 671 dev->mute = ctrl->value;
638 dev->mute = ctrl->value; 672 break;
639 return em28xx_audio_analog_set(dev);
640 }
641 return 0;
642 case V4L2_CID_AUDIO_VOLUME: 673 case V4L2_CID_AUDIO_VOLUME:
643 dev->volume = ctrl->value; 674 dev->volume = ctrl->value;
644 return em28xx_audio_analog_set(dev); 675 break;
645 default:
646 return -EINVAL;
647 } 676 }
677
678 return em28xx_audio_analog_set(dev);
648} 679}
649 680
650static int check_dev(struct em28xx *dev) 681static int check_dev(struct em28xx *dev)
@@ -974,6 +1005,9 @@ static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
974 struct em28xx_fh *fh = priv; 1005 struct em28xx_fh *fh = priv;
975 struct em28xx *dev = fh->dev; 1006 struct em28xx *dev = fh->dev;
976 1007
1008 if (!dev->audio_mode.has_audio)
1009 return -EINVAL;
1010
977 switch (a->index) { 1011 switch (a->index) {
978 case EM28XX_AMUX_VIDEO: 1012 case EM28XX_AMUX_VIDEO:
979 strcpy(a->name, "Television"); 1013 strcpy(a->name, "Television");
@@ -1015,6 +1049,9 @@ static int vidioc_s_audio(struct file *file, void *priv, struct v4l2_audio *a)
1015 struct em28xx *dev = fh->dev; 1049 struct em28xx *dev = fh->dev;
1016 1050
1017 1051
1052 if (!dev->audio_mode.has_audio)
1053 return -EINVAL;
1054
1018 if (a->index >= MAX_EM28XX_INPUT) 1055 if (a->index >= MAX_EM28XX_INPUT)
1019 return -EINVAL; 1056 return -EINVAL;
1020 if (0 == INPUT(a->index)->type) 1057 if (0 == INPUT(a->index)->type)
@@ -1038,7 +1075,6 @@ static int vidioc_queryctrl(struct file *file, void *priv,
1038 struct em28xx_fh *fh = priv; 1075 struct em28xx_fh *fh = priv;
1039 struct em28xx *dev = fh->dev; 1076 struct em28xx *dev = fh->dev;
1040 int id = qc->id; 1077 int id = qc->id;
1041 int i;
1042 int rc; 1078 int rc;
1043 1079
1044 rc = check_dev(dev); 1080 rc = check_dev(dev);
@@ -1049,15 +1085,14 @@ static int vidioc_queryctrl(struct file *file, void *priv,
1049 1085
1050 qc->id = id; 1086 qc->id = id;
1051 1087
1052 if (!dev->board.has_msp34xx) { 1088 /* enumberate AC97 controls */
1053 for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) { 1089 if (dev->audio_mode.ac97 != EM28XX_NO_AC97) {
1054 if (qc->id && qc->id == em28xx_qctrl[i].id) { 1090 rc = ac97_queryctrl(qc);
1055 memcpy(qc, &(em28xx_qctrl[i]), sizeof(*qc)); 1091 if (!rc)
1056 return 0; 1092 return 0;
1057 }
1058 }
1059 } 1093 }
1060 1094
1095 /* enumberate V4L2 device controls */
1061 mutex_lock(&dev->lock); 1096 mutex_lock(&dev->lock);
1062 v4l2_device_call_all(&dev->v4l2_dev, 0, core, queryctrl, qc); 1097 v4l2_device_call_all(&dev->v4l2_dev, 0, core, queryctrl, qc);
1063 mutex_unlock(&dev->lock); 1098 mutex_unlock(&dev->lock);
@@ -1082,14 +1117,16 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
1082 1117
1083 mutex_lock(&dev->lock); 1118 mutex_lock(&dev->lock);
1084 1119
1085 if (dev->board.has_msp34xx) 1120 /* Set an AC97 control */
1121 if (dev->audio_mode.ac97 != EM28XX_NO_AC97)
1122 rc = ac97_get_ctrl(dev, ctrl);
1123 else
1124 rc = 1;
1125
1126 /* It were not an AC97 control. Sends it to the v4l2 dev interface */
1127 if (rc == 1) {
1086 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_ctrl, ctrl); 1128 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_ctrl, ctrl);
1087 else { 1129 rc = 0;
1088 rc = em28xx_get_ctrl(dev, ctrl);
1089 if (rc < 0) {
1090 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_ctrl, ctrl);
1091 rc = 0;
1092 }
1093 } 1130 }
1094 1131
1095 mutex_unlock(&dev->lock); 1132 mutex_unlock(&dev->lock);
@@ -1101,7 +1138,6 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
1101{ 1138{
1102 struct em28xx_fh *fh = priv; 1139 struct em28xx_fh *fh = priv;
1103 struct em28xx *dev = fh->dev; 1140 struct em28xx *dev = fh->dev;
1104 u8 i;
1105 int rc; 1141 int rc;
1106 1142
1107 rc = check_dev(dev); 1143 rc = check_dev(dev);
@@ -1110,28 +1146,31 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
1110 1146
1111 mutex_lock(&dev->lock); 1147 mutex_lock(&dev->lock);
1112 1148
1113 if (dev->board.has_msp34xx) 1149 /* Set an AC97 control */
1114 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_ctrl, ctrl); 1150 if (dev->audio_mode.ac97 != EM28XX_NO_AC97)
1115 else { 1151 rc = ac97_set_ctrl(dev, ctrl);
1152 else
1116 rc = 1; 1153 rc = 1;
1117 for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) {
1118 if (ctrl->id == em28xx_qctrl[i].id) {
1119 if (ctrl->value < em28xx_qctrl[i].minimum ||
1120 ctrl->value > em28xx_qctrl[i].maximum) {
1121 rc = -ERANGE;
1122 break;
1123 }
1124
1125 rc = em28xx_set_ctrl(dev, ctrl);
1126 break;
1127 }
1128 }
1129 }
1130 1154
1131 /* Control not found - try to send it to the attached devices */ 1155 /* It isn't an AC97 control. Sends it to the v4l2 dev interface */
1132 if (rc == 1) { 1156 if (rc == 1) {
1133 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_ctrl, ctrl); 1157 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_ctrl, ctrl);
1134 rc = 0; 1158
1159 /*
1160 * In the case of non-AC97 volume controls, we still need
1161 * to do some setups at em28xx, in order to mute/unmute
1162 * and to adjust audio volume. However, the value ranges
1163 * should be checked by the corresponding V4L subdriver.
1164 */
1165 switch (ctrl->id) {
1166 case V4L2_CID_AUDIO_MUTE:
1167 dev->mute = ctrl->value;
1168 rc = em28xx_audio_analog_set(dev);
1169 break;
1170 case V4L2_CID_AUDIO_VOLUME:
1171 dev->volume = ctrl->value;
1172 rc = em28xx_audio_analog_set(dev);
1173 }
1135 } 1174 }
1136 1175
1137 mutex_unlock(&dev->lock); 1176 mutex_unlock(&dev->lock);
@@ -1275,8 +1314,9 @@ static int vidioc_g_register(struct file *file, void *priv,
1275 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_register, reg); 1314 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_register, reg);
1276 return 0; 1315 return 0;
1277 case V4L2_CHIP_MATCH_I2C_ADDR: 1316 case V4L2_CHIP_MATCH_I2C_ADDR:
1278 /* Not supported yet */ 1317 /* TODO: is this correct? */
1279 return -EINVAL; 1318 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_register, reg);
1319 return 0;
1280 default: 1320 default:
1281 if (!v4l2_chip_match_host(&reg->match)) 1321 if (!v4l2_chip_match_host(&reg->match))
1282 return -EINVAL; 1322 return -EINVAL;
@@ -1327,8 +1367,9 @@ static int vidioc_s_register(struct file *file, void *priv,
1327 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_register, reg); 1367 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_register, reg);
1328 return 0; 1368 return 0;
1329 case V4L2_CHIP_MATCH_I2C_ADDR: 1369 case V4L2_CHIP_MATCH_I2C_ADDR:
1330 /* Not supported yet */ 1370 /* TODO: is this correct? */
1331 return -EINVAL; 1371 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_register, reg);
1372 return 0;
1332 default: 1373 default:
1333 if (!v4l2_chip_match_host(&reg->match)) 1374 if (!v4l2_chip_match_host(&reg->match))
1334 return -EINVAL; 1375 return -EINVAL;
@@ -1431,9 +1472,11 @@ static int vidioc_querycap(struct file *file, void *priv,
1431 cap->capabilities = 1472 cap->capabilities =
1432 V4L2_CAP_SLICED_VBI_CAPTURE | 1473 V4L2_CAP_SLICED_VBI_CAPTURE |
1433 V4L2_CAP_VIDEO_CAPTURE | 1474 V4L2_CAP_VIDEO_CAPTURE |
1434 V4L2_CAP_AUDIO |
1435 V4L2_CAP_READWRITE | V4L2_CAP_STREAMING; 1475 V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
1436 1476
1477 if (dev->audio_mode.has_audio)
1478 cap->capabilities |= V4L2_CAP_AUDIO;
1479
1437 if (dev->tuner_type != TUNER_ABSENT) 1480 if (dev->tuner_type != TUNER_ABSENT)
1438 cap->capabilities |= V4L2_CAP_TUNER; 1481 cap->capabilities |= V4L2_CAP_TUNER;
1439 1482
@@ -1654,9 +1697,9 @@ static int radio_queryctrl(struct file *file, void *priv,
1654 qc->id >= V4L2_CID_LASTP1) 1697 qc->id >= V4L2_CID_LASTP1)
1655 return -EINVAL; 1698 return -EINVAL;
1656 1699
1657 for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) { 1700 for (i = 0; i < ARRAY_SIZE(ac97_qctrl); i++) {
1658 if (qc->id && qc->id == em28xx_qctrl[i].id) { 1701 if (qc->id && qc->id == ac97_qctrl[i].id) {
1659 memcpy(qc, &(em28xx_qctrl[i]), sizeof(*qc)); 1702 memcpy(qc, &(ac97_qctrl[i]), sizeof(*qc));
1660 return 0; 1703 return 0;
1661 } 1704 }
1662 } 1705 }
diff --git a/drivers/media/video/em28xx/em28xx.h b/drivers/media/video/em28xx/em28xx.h
index a2add61f7d59..0f2ba9a40d17 100644
--- a/drivers/media/video/em28xx/em28xx.h
+++ b/drivers/media/video/em28xx/em28xx.h
@@ -108,6 +108,7 @@
108#define EM2882_BOARD_KWORLD_ATSC_315U 69 108#define EM2882_BOARD_KWORLD_ATSC_315U 69
109#define EM2882_BOARD_EVGA_INDTUBE 70 109#define EM2882_BOARD_EVGA_INDTUBE 70
110#define EM2820_BOARD_SILVERCREST_WEBCAM 71 110#define EM2820_BOARD_SILVERCREST_WEBCAM 71
111#define EM2861_BOARD_GADMEI_UTV330PLUS 72
111 112
112/* Limits minimum and default number of buffers */ 113/* Limits minimum and default number of buffers */
113#define EM28XX_MIN_BUF 4 114#define EM28XX_MIN_BUF 4
@@ -398,6 +399,7 @@ struct em28xx_board {
398 unsigned int has_snapshot_button:1; 399 unsigned int has_snapshot_button:1;
399 unsigned int is_webcam:1; 400 unsigned int is_webcam:1;
400 unsigned int valid:1; 401 unsigned int valid:1;
402 unsigned int has_ir_i2c:1;
401 403
402 unsigned char xclk, i2c_speed; 404 unsigned char xclk, i2c_speed;
403 unsigned char radio_addr; 405 unsigned char radio_addr;
@@ -408,7 +410,7 @@ struct em28xx_board {
408 410
409 struct em28xx_input input[MAX_EM28XX_INPUT]; 411 struct em28xx_input input[MAX_EM28XX_INPUT];
410 struct em28xx_input radio; 412 struct em28xx_input radio;
411 IR_KEYTAB_TYPE *ir_codes; 413 struct ir_scancode_table *ir_codes;
412}; 414};
413 415
414struct em28xx_eeprom { 416struct em28xx_eeprom {
@@ -595,6 +597,10 @@ struct em28xx {
595 struct delayed_work sbutton_query_work; 597 struct delayed_work sbutton_query_work;
596 598
597 struct em28xx_dvb *dvb; 599 struct em28xx_dvb *dvb;
600
601 /* I2C keyboard data */
602 struct i2c_board_info info;
603 struct IR_i2c_init_data init_data;
598}; 604};
599 605
600struct em28xx_ops { 606struct em28xx_ops {
diff --git a/drivers/media/video/gspca/Kconfig b/drivers/media/video/gspca/Kconfig
index e994dcac43ff..8897283b0bb4 100644
--- a/drivers/media/video/gspca/Kconfig
+++ b/drivers/media/video/gspca/Kconfig
@@ -47,6 +47,15 @@ config USB_GSPCA_FINEPIX
47 To compile this driver as a module, choose M here: the 47 To compile this driver as a module, choose M here: the
48 module will be called gspca_finepix. 48 module will be called gspca_finepix.
49 49
50config USB_GSPCA_JEILINJ
51 tristate "Jeilin JPEG USB V4L2 driver"
52 depends on VIDEO_V4L2 && USB_GSPCA
53 help
54 Say Y here if you want support for cameras based on this Jeilin chip.
55
56 To compile this driver as a module, choose M here: the
57 module will be called gspca_jeilinj.
58
50config USB_GSPCA_MARS 59config USB_GSPCA_MARS
51 tristate "Mars USB Camera Driver" 60 tristate "Mars USB Camera Driver"
52 depends on VIDEO_V4L2 && USB_GSPCA 61 depends on VIDEO_V4L2 && USB_GSPCA
@@ -103,9 +112,9 @@ config USB_GSPCA_PAC7311
103 module will be called gspca_pac7311. 112 module will be called gspca_pac7311.
104 113
105config USB_GSPCA_SN9C20X 114config USB_GSPCA_SN9C20X
106 tristate "SN9C20X USB Camera Driver" 115 tristate "SN9C20X USB Camera Driver"
107 depends on VIDEO_V4L2 && USB_GSPCA 116 depends on VIDEO_V4L2 && USB_GSPCA
108 help 117 help
109 Say Y here if you want support for cameras based on the 118 Say Y here if you want support for cameras based on the
110 sn9c20x chips (SN9C201 and SN9C202). 119 sn9c20x chips (SN9C201 and SN9C202).
111 120
@@ -113,10 +122,10 @@ config USB_GSPCA_SN9C20X
113 module will be called gspca_sn9c20x. 122 module will be called gspca_sn9c20x.
114 123
115config USB_GSPCA_SN9C20X_EVDEV 124config USB_GSPCA_SN9C20X_EVDEV
116 bool "Enable evdev support" 125 bool "Enable evdev support"
117 depends on USB_GSPCA_SN9C20X && INPUT 126 depends on USB_GSPCA_SN9C20X && INPUT
118 ---help--- 127 ---help---
119 Say Y here in order to enable evdev support for sn9c20x webcam button. 128 Say Y here in order to enable evdev support for sn9c20x webcam button.
120 129
121config USB_GSPCA_SONIXB 130config USB_GSPCA_SONIXB
122 tristate "SONIX Bayer USB Camera Driver" 131 tristate "SONIX Bayer USB Camera Driver"
diff --git a/drivers/media/video/gspca/Makefile b/drivers/media/video/gspca/Makefile
index f6d3b86e9ad5..035616b5e867 100644
--- a/drivers/media/video/gspca/Makefile
+++ b/drivers/media/video/gspca/Makefile
@@ -2,6 +2,7 @@ obj-$(CONFIG_USB_GSPCA) += gspca_main.o
2obj-$(CONFIG_USB_GSPCA_CONEX) += gspca_conex.o 2obj-$(CONFIG_USB_GSPCA_CONEX) += gspca_conex.o
3obj-$(CONFIG_USB_GSPCA_ETOMS) += gspca_etoms.o 3obj-$(CONFIG_USB_GSPCA_ETOMS) += gspca_etoms.o
4obj-$(CONFIG_USB_GSPCA_FINEPIX) += gspca_finepix.o 4obj-$(CONFIG_USB_GSPCA_FINEPIX) += gspca_finepix.o
5obj-$(CONFIG_USB_GSPCA_JEILINJ) += gspca_jeilinj.o
5obj-$(CONFIG_USB_GSPCA_MARS) += gspca_mars.o 6obj-$(CONFIG_USB_GSPCA_MARS) += gspca_mars.o
6obj-$(CONFIG_USB_GSPCA_MR97310A) += gspca_mr97310a.o 7obj-$(CONFIG_USB_GSPCA_MR97310A) += gspca_mr97310a.o
7obj-$(CONFIG_USB_GSPCA_OV519) += gspca_ov519.o 8obj-$(CONFIG_USB_GSPCA_OV519) += gspca_ov519.o
@@ -30,6 +31,7 @@ gspca_main-objs := gspca.o
30gspca_conex-objs := conex.o 31gspca_conex-objs := conex.o
31gspca_etoms-objs := etoms.o 32gspca_etoms-objs := etoms.o
32gspca_finepix-objs := finepix.o 33gspca_finepix-objs := finepix.o
34gspca_jeilinj-objs := jeilinj.o
33gspca_mars-objs := mars.o 35gspca_mars-objs := mars.o
34gspca_mr97310a-objs := mr97310a.o 36gspca_mr97310a-objs := mr97310a.o
35gspca_ov519-objs := ov519.o 37gspca_ov519-objs := ov519.o
diff --git a/drivers/media/video/gspca/conex.c b/drivers/media/video/gspca/conex.c
index 8d48ea1742c2..eca003566ae3 100644
--- a/drivers/media/video/gspca/conex.c
+++ b/drivers/media/video/gspca/conex.c
@@ -820,7 +820,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
820 820
821 cam = &gspca_dev->cam; 821 cam = &gspca_dev->cam;
822 cam->cam_mode = vga_mode; 822 cam->cam_mode = vga_mode;
823 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0]; 823 cam->nmodes = ARRAY_SIZE(vga_mode);
824 824
825 sd->brightness = BRIGHTNESS_DEF; 825 sd->brightness = BRIGHTNESS_DEF;
826 sd->contrast = CONTRAST_DEF; 826 sd->contrast = CONTRAST_DEF;
diff --git a/drivers/media/video/gspca/etoms.c b/drivers/media/video/gspca/etoms.c
index 2c20d06a03e8..c1461e63647f 100644
--- a/drivers/media/video/gspca/etoms.c
+++ b/drivers/media/video/gspca/etoms.c
@@ -635,10 +635,10 @@ static int sd_config(struct gspca_dev *gspca_dev,
635 sd->sensor = id->driver_info; 635 sd->sensor = id->driver_info;
636 if (sd->sensor == SENSOR_PAS106) { 636 if (sd->sensor == SENSOR_PAS106) {
637 cam->cam_mode = sif_mode; 637 cam->cam_mode = sif_mode;
638 cam->nmodes = sizeof sif_mode / sizeof sif_mode[0]; 638 cam->nmodes = ARRAY_SIZE(sif_mode);
639 } else { 639 } else {
640 cam->cam_mode = vga_mode; 640 cam->cam_mode = vga_mode;
641 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0]; 641 cam->nmodes = ARRAY_SIZE(vga_mode);
642 gspca_dev->ctrl_dis = (1 << COLOR_IDX); 642 gspca_dev->ctrl_dis = (1 << COLOR_IDX);
643 } 643 }
644 sd->brightness = BRIGHTNESS_DEF; 644 sd->brightness = BRIGHTNESS_DEF;
diff --git a/drivers/media/video/gspca/gspca.c b/drivers/media/video/gspca/gspca.c
index b8561dfb6c8c..cf6540da1e42 100644
--- a/drivers/media/video/gspca/gspca.c
+++ b/drivers/media/video/gspca/gspca.c
@@ -47,7 +47,7 @@ MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>");
47MODULE_DESCRIPTION("GSPCA USB Camera Driver"); 47MODULE_DESCRIPTION("GSPCA USB Camera Driver");
48MODULE_LICENSE("GPL"); 48MODULE_LICENSE("GPL");
49 49
50#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 6, 0) 50#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 7, 0)
51 51
52#ifdef GSPCA_DEBUG 52#ifdef GSPCA_DEBUG
53int gspca_debug = D_ERR | D_PROBE; 53int gspca_debug = D_ERR | D_PROBE;
@@ -486,6 +486,7 @@ static struct usb_host_endpoint *get_ep(struct gspca_dev *gspca_dev)
486 } 486 }
487 PDEBUG(D_STREAM, "use alt %d ep 0x%02x", 487 PDEBUG(D_STREAM, "use alt %d ep 0x%02x",
488 i, ep->desc.bEndpointAddress); 488 i, ep->desc.bEndpointAddress);
489 gspca_dev->alt = i; /* memorize the current alt setting */
489 if (gspca_dev->nbalt > 1) { 490 if (gspca_dev->nbalt > 1) {
490 ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, i); 491 ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, i);
491 if (ret < 0) { 492 if (ret < 0) {
@@ -493,7 +494,6 @@ static struct usb_host_endpoint *get_ep(struct gspca_dev *gspca_dev)
493 return NULL; 494 return NULL;
494 } 495 }
495 } 496 }
496 gspca_dev->alt = i; /* memorize the current alt setting */
497 return ep; 497 return ep;
498} 498}
499 499
@@ -512,7 +512,10 @@ static int create_urbs(struct gspca_dev *gspca_dev,
512 if (!gspca_dev->cam.bulk) { /* isoc */ 512 if (!gspca_dev->cam.bulk) { /* isoc */
513 513
514 /* See paragraph 5.9 / table 5-11 of the usb 2.0 spec. */ 514 /* See paragraph 5.9 / table 5-11 of the usb 2.0 spec. */
515 psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3)); 515 if (gspca_dev->pkt_size == 0)
516 psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3));
517 else
518 psize = gspca_dev->pkt_size;
516 npkt = gspca_dev->cam.npkt; 519 npkt = gspca_dev->cam.npkt;
517 if (npkt == 0) 520 if (npkt == 0)
518 npkt = 32; /* default value */ 521 npkt = 32; /* default value */
@@ -597,13 +600,18 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev)
597 /* set the higher alternate setting and 600 /* set the higher alternate setting and
598 * loop until urb submit succeeds */ 601 * loop until urb submit succeeds */
599 gspca_dev->alt = gspca_dev->nbalt; 602 gspca_dev->alt = gspca_dev->nbalt;
603 if (gspca_dev->sd_desc->isoc_init) {
604 ret = gspca_dev->sd_desc->isoc_init(gspca_dev);
605 if (ret < 0)
606 goto out;
607 }
608 ep = get_ep(gspca_dev);
609 if (ep == NULL) {
610 ret = -EIO;
611 goto out;
612 }
600 for (;;) { 613 for (;;) {
601 PDEBUG(D_STREAM, "init transfer alt %d", gspca_dev->alt); 614 PDEBUG(D_STREAM, "init transfer alt %d", gspca_dev->alt);
602 ep = get_ep(gspca_dev);
603 if (ep == NULL) {
604 ret = -EIO;
605 goto out;
606 }
607 ret = create_urbs(gspca_dev, ep); 615 ret = create_urbs(gspca_dev, ep);
608 if (ret < 0) 616 if (ret < 0)
609 goto out; 617 goto out;
@@ -628,21 +636,32 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev)
628 /* submit the URBs */ 636 /* submit the URBs */
629 for (n = 0; n < gspca_dev->nurbs; n++) { 637 for (n = 0; n < gspca_dev->nurbs; n++) {
630 ret = usb_submit_urb(gspca_dev->urb[n], GFP_KERNEL); 638 ret = usb_submit_urb(gspca_dev->urb[n], GFP_KERNEL);
631 if (ret < 0) { 639 if (ret < 0)
632 PDEBUG(D_ERR|D_STREAM, 640 break;
633 "usb_submit_urb [%d] err %d", n, ret);
634 gspca_dev->streaming = 0;
635 destroy_urbs(gspca_dev);
636 if (ret == -ENOSPC) {
637 msleep(20); /* wait for kill
638 * complete */
639 break; /* try the previous alt */
640 }
641 goto out;
642 }
643 } 641 }
644 if (ret >= 0) 642 if (ret >= 0)
645 break; 643 break;
644 PDEBUG(D_ERR|D_STREAM,
645 "usb_submit_urb alt %d err %d", gspca_dev->alt, ret);
646 gspca_dev->streaming = 0;
647 destroy_urbs(gspca_dev);
648 if (ret != -ENOSPC)
649 goto out;
650
651 /* the bandwidth is not wide enough
652 * negociate or try a lower alternate setting */
653 msleep(20); /* wait for kill complete */
654 if (gspca_dev->sd_desc->isoc_nego) {
655 ret = gspca_dev->sd_desc->isoc_nego(gspca_dev);
656 if (ret < 0)
657 goto out;
658 } else {
659 ep = get_ep(gspca_dev);
660 if (ep == NULL) {
661 ret = -EIO;
662 goto out;
663 }
664 }
646 } 665 }
647out: 666out:
648 mutex_unlock(&gspca_dev->usb_lock); 667 mutex_unlock(&gspca_dev->usb_lock);
@@ -1473,12 +1492,6 @@ static int vidioc_s_parm(struct file *filp, void *priv,
1473 return 0; 1492 return 0;
1474} 1493}
1475 1494
1476static int vidioc_s_std(struct file *filp, void *priv,
1477 v4l2_std_id *parm)
1478{
1479 return 0;
1480}
1481
1482#ifdef CONFIG_VIDEO_V4L1_COMPAT 1495#ifdef CONFIG_VIDEO_V4L1_COMPAT
1483static int vidiocgmbuf(struct file *file, void *priv, 1496static int vidiocgmbuf(struct file *file, void *priv,
1484 struct video_mbuf *mbuf) 1497 struct video_mbuf *mbuf)
@@ -1949,7 +1962,6 @@ static const struct v4l2_ioctl_ops dev_ioctl_ops = {
1949 .vidioc_s_jpegcomp = vidioc_s_jpegcomp, 1962 .vidioc_s_jpegcomp = vidioc_s_jpegcomp,
1950 .vidioc_g_parm = vidioc_g_parm, 1963 .vidioc_g_parm = vidioc_g_parm,
1951 .vidioc_s_parm = vidioc_s_parm, 1964 .vidioc_s_parm = vidioc_s_parm,
1952 .vidioc_s_std = vidioc_s_std,
1953 .vidioc_enum_framesizes = vidioc_enum_framesizes, 1965 .vidioc_enum_framesizes = vidioc_enum_framesizes,
1954#ifdef CONFIG_VIDEO_ADV_DEBUG 1966#ifdef CONFIG_VIDEO_ADV_DEBUG
1955 .vidioc_g_register = vidioc_g_register, 1967 .vidioc_g_register = vidioc_g_register,
diff --git a/drivers/media/video/gspca/gspca.h b/drivers/media/video/gspca/gspca.h
index 46c4effdfcd5..70b1fd830876 100644
--- a/drivers/media/video/gspca/gspca.h
+++ b/drivers/media/video/gspca/gspca.h
@@ -98,9 +98,11 @@ struct sd_desc {
98/* mandatory operations */ 98/* mandatory operations */
99 cam_cf_op config; /* called on probe */ 99 cam_cf_op config; /* called on probe */
100 cam_op init; /* called on probe and resume */ 100 cam_op init; /* called on probe and resume */
101 cam_op start; /* called on stream on */ 101 cam_op start; /* called on stream on after URBs creation */
102 cam_pkt_op pkt_scan; 102 cam_pkt_op pkt_scan;
103/* optional operations */ 103/* optional operations */
104 cam_op isoc_init; /* called on stream on before getting the EP */
105 cam_op isoc_nego; /* called when URB submit failed with NOSPC */
104 cam_v_op stopN; /* called on stream off - main alt */ 106 cam_v_op stopN; /* called on stream off - main alt */
105 cam_v_op stop0; /* called on stream off & disconnect - alt 0 */ 107 cam_v_op stop0; /* called on stream off & disconnect - alt 0 */
106 cam_v_op dq_callback; /* called when a frame has been dequeued */ 108 cam_v_op dq_callback; /* called when a frame has been dequeued */
@@ -178,6 +180,7 @@ struct gspca_dev {
178 __u8 iface; /* USB interface number */ 180 __u8 iface; /* USB interface number */
179 __u8 alt; /* USB alternate setting */ 181 __u8 alt; /* USB alternate setting */
180 __u8 nbalt; /* number of USB alternate settings */ 182 __u8 nbalt; /* number of USB alternate settings */
183 u16 pkt_size; /* ISOC packet size */
181}; 184};
182 185
183int gspca_dev_probe(struct usb_interface *intf, 186int gspca_dev_probe(struct usb_interface *intf,
diff --git a/drivers/media/video/gspca/jeilinj.c b/drivers/media/video/gspca/jeilinj.c
new file mode 100644
index 000000000000..dbfa3ed6e8ef
--- /dev/null
+++ b/drivers/media/video/gspca/jeilinj.c
@@ -0,0 +1,388 @@
1/*
2 * Jeilinj subdriver
3 *
4 * Supports some Jeilin dual-mode cameras which use bulk transport and
5 * download raw JPEG data.
6 *
7 * Copyright (C) 2009 Theodore Kilgore
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24#define MODULE_NAME "jeilinj"
25
26#include <linux/workqueue.h>
27#include "gspca.h"
28#include "jpeg.h"
29
30MODULE_AUTHOR("Theodore Kilgore <kilgota@auburn.edu>");
31MODULE_DESCRIPTION("GSPCA/JEILINJ USB Camera Driver");
32MODULE_LICENSE("GPL");
33
34/* Default timeouts, in ms */
35#define JEILINJ_CMD_TIMEOUT 500
36#define JEILINJ_DATA_TIMEOUT 1000
37
38/* Maximum transfer size to use. */
39#define JEILINJ_MAX_TRANSFER 0x200
40
41#define FRAME_HEADER_LEN 0x10
42
43/* Structure to hold all of our device specific stuff */
44struct sd {
45 struct gspca_dev gspca_dev; /* !! must be the first item */
46 const struct v4l2_pix_format *cap_mode;
47 /* Driver stuff */
48 struct work_struct work_struct;
49 struct workqueue_struct *work_thread;
50 u8 quality; /* image quality */
51 u8 jpegqual; /* webcam quality */
52 u8 *jpeg_hdr;
53};
54
55 struct jlj_command {
56 unsigned char instruction[2];
57 unsigned char ack_wanted;
58 };
59
60/* AFAICT these cameras will only do 320x240. */
61static struct v4l2_pix_format jlj_mode[] = {
62 { 320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
63 .bytesperline = 320,
64 .sizeimage = 320 * 240,
65 .colorspace = V4L2_COLORSPACE_JPEG,
66 .priv = 0}
67};
68
69/*
70 * cam uses endpoint 0x03 to send commands, 0x84 for read commands,
71 * and 0x82 for bulk transfer.
72 */
73
74/* All commands are two bytes only */
75static int jlj_write2(struct gspca_dev *gspca_dev, unsigned char *command)
76{
77 int retval;
78
79 memcpy(gspca_dev->usb_buf, command, 2);
80 retval = usb_bulk_msg(gspca_dev->dev,
81 usb_sndbulkpipe(gspca_dev->dev, 3),
82 gspca_dev->usb_buf, 2, NULL, 500);
83 if (retval < 0)
84 PDEBUG(D_ERR, "command write [%02x] error %d",
85 gspca_dev->usb_buf[0], retval);
86 return retval;
87}
88
89/* Responses are one byte only */
90static int jlj_read1(struct gspca_dev *gspca_dev, unsigned char response)
91{
92 int retval;
93
94 retval = usb_bulk_msg(gspca_dev->dev,
95 usb_rcvbulkpipe(gspca_dev->dev, 0x84),
96 gspca_dev->usb_buf, 1, NULL, 500);
97 response = gspca_dev->usb_buf[0];
98 if (retval < 0)
99 PDEBUG(D_ERR, "read command [%02x] error %d",
100 gspca_dev->usb_buf[0], retval);
101 return retval;
102}
103
104static int jlj_start(struct gspca_dev *gspca_dev)
105{
106 int i;
107 int retval = -1;
108 u8 response = 0xff;
109 struct jlj_command start_commands[] = {
110 {{0x71, 0x81}, 0},
111 {{0x70, 0x05}, 0},
112 {{0x95, 0x70}, 1},
113 {{0x71, 0x81}, 0},
114 {{0x70, 0x04}, 0},
115 {{0x95, 0x70}, 1},
116 {{0x71, 0x00}, 0},
117 {{0x70, 0x08}, 0},
118 {{0x95, 0x70}, 1},
119 {{0x94, 0x02}, 0},
120 {{0xde, 0x24}, 0},
121 {{0x94, 0x02}, 0},
122 {{0xdd, 0xf0}, 0},
123 {{0x94, 0x02}, 0},
124 {{0xe3, 0x2c}, 0},
125 {{0x94, 0x02}, 0},
126 {{0xe4, 0x00}, 0},
127 {{0x94, 0x02}, 0},
128 {{0xe5, 0x00}, 0},
129 {{0x94, 0x02}, 0},
130 {{0xe6, 0x2c}, 0},
131 {{0x94, 0x03}, 0},
132 {{0xaa, 0x00}, 0},
133 {{0x71, 0x1e}, 0},
134 {{0x70, 0x06}, 0},
135 {{0x71, 0x80}, 0},
136 {{0x70, 0x07}, 0}
137 };
138 for (i = 0; i < ARRAY_SIZE(start_commands); i++) {
139 retval = jlj_write2(gspca_dev, start_commands[i].instruction);
140 if (retval < 0)
141 return retval;
142 if (start_commands[i].ack_wanted)
143 retval = jlj_read1(gspca_dev, response);
144 if (retval < 0)
145 return retval;
146 }
147 PDEBUG(D_ERR, "jlj_start retval is %d", retval);
148 return retval;
149}
150
151static int jlj_stop(struct gspca_dev *gspca_dev)
152{
153 int i;
154 int retval;
155 struct jlj_command stop_commands[] = {
156 {{0x71, 0x00}, 0},
157 {{0x70, 0x09}, 0},
158 {{0x71, 0x80}, 0},
159 {{0x70, 0x05}, 0}
160 };
161 for (i = 0; i < ARRAY_SIZE(stop_commands); i++) {
162 retval = jlj_write2(gspca_dev, stop_commands[i].instruction);
163 if (retval < 0)
164 return retval;
165 }
166 return retval;
167}
168
169/* This function is called as a workqueue function and runs whenever the camera
170 * is streaming data. Because it is a workqueue function it is allowed to sleep
171 * so we can use synchronous USB calls. To avoid possible collisions with other
172 * threads attempting to use the camera's USB interface the gspca usb_lock is
173 * used when performing the one USB control operation inside the workqueue,
174 * which tells the camera to close the stream. In practice the only thing
175 * which needs to be protected against is the usb_set_interface call that
176 * gspca makes during stream_off. Otherwise the camera doesn't provide any
177 * controls that the user could try to change.
178 */
179
180static void jlj_dostream(struct work_struct *work)
181{
182 struct sd *dev = container_of(work, struct sd, work_struct);
183 struct gspca_dev *gspca_dev = &dev->gspca_dev;
184 struct gspca_frame *frame;
185 int blocks_left; /* 0x200-sized blocks remaining in current frame. */
186 int size_in_blocks;
187 int act_len;
188 int discarding = 0; /* true if we failed to get space for frame. */
189 int packet_type;
190 int ret;
191 u8 *buffer;
192
193 buffer = kmalloc(JEILINJ_MAX_TRANSFER, GFP_KERNEL | GFP_DMA);
194 if (!buffer) {
195 PDEBUG(D_ERR, "Couldn't allocate USB buffer");
196 goto quit_stream;
197 }
198 while (gspca_dev->present && gspca_dev->streaming) {
199 if (!gspca_dev->present)
200 goto quit_stream;
201 /* Start a new frame, and add the JPEG header, first thing */
202 frame = gspca_get_i_frame(gspca_dev);
203 if (frame && !discarding)
204 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
205 dev->jpeg_hdr, JPEG_HDR_SZ);
206 else
207 discarding = 1;
208 /*
209 * Now request data block 0. Line 0 reports the size
210 * to download, in blocks of size 0x200, and also tells the
211 * "actual" data size, in bytes, which seems best to ignore.
212 */
213 ret = usb_bulk_msg(gspca_dev->dev,
214 usb_rcvbulkpipe(gspca_dev->dev, 0x82),
215 buffer, JEILINJ_MAX_TRANSFER, &act_len,
216 JEILINJ_DATA_TIMEOUT);
217 PDEBUG(D_STREAM,
218 "Got %d bytes out of %d for Block 0",
219 act_len, JEILINJ_MAX_TRANSFER);
220 if (ret < 0 || act_len < FRAME_HEADER_LEN)
221 goto quit_stream;
222 size_in_blocks = buffer[0x0a];
223 blocks_left = buffer[0x0a] - 1;
224 PDEBUG(D_STREAM, "blocks_left = 0x%x", blocks_left);
225 packet_type = INTER_PACKET;
226 if (frame && !discarding)
227 /* Toss line 0 of data block 0, keep the rest. */
228 gspca_frame_add(gspca_dev, packet_type,
229 frame, buffer + FRAME_HEADER_LEN,
230 JEILINJ_MAX_TRANSFER - FRAME_HEADER_LEN);
231 else
232 discarding = 1;
233 while (blocks_left > 0) {
234 if (!gspca_dev->present)
235 goto quit_stream;
236 ret = usb_bulk_msg(gspca_dev->dev,
237 usb_rcvbulkpipe(gspca_dev->dev, 0x82),
238 buffer, JEILINJ_MAX_TRANSFER, &act_len,
239 JEILINJ_DATA_TIMEOUT);
240 if (ret < 0 || act_len < JEILINJ_MAX_TRANSFER)
241 goto quit_stream;
242 PDEBUG(D_STREAM,
243 "%d blocks remaining for frame", blocks_left);
244 blocks_left -= 1;
245 if (blocks_left == 0)
246 packet_type = LAST_PACKET;
247 else
248 packet_type = INTER_PACKET;
249 if (frame && !discarding)
250 gspca_frame_add(gspca_dev, packet_type,
251 frame, buffer,
252 JEILINJ_MAX_TRANSFER);
253 else
254 discarding = 1;
255 }
256 }
257quit_stream:
258 mutex_lock(&gspca_dev->usb_lock);
259 if (gspca_dev->present)
260 jlj_stop(gspca_dev);
261 mutex_unlock(&gspca_dev->usb_lock);
262 kfree(buffer);
263}
264
265/* This function is called at probe time just before sd_init */
266static int sd_config(struct gspca_dev *gspca_dev,
267 const struct usb_device_id *id)
268{
269 struct cam *cam = &gspca_dev->cam;
270 struct sd *dev = (struct sd *) gspca_dev;
271
272 dev->quality = 85;
273 dev->jpegqual = 85;
274 PDEBUG(D_PROBE,
275 "JEILINJ camera detected"
276 " (vid/pid 0x%04X:0x%04X)", id->idVendor, id->idProduct);
277 cam->cam_mode = jlj_mode;
278 cam->nmodes = 1;
279 cam->bulk = 1;
280 /* We don't use the buffer gspca allocates so make it small. */
281 cam->bulk_size = 32;
282 INIT_WORK(&dev->work_struct, jlj_dostream);
283 return 0;
284}
285
286/* called on streamoff with alt==0 and on disconnect */
287/* the usb_lock is held at entry - restore on exit */
288static void sd_stop0(struct gspca_dev *gspca_dev)
289{
290 struct sd *dev = (struct sd *) gspca_dev;
291
292 /* wait for the work queue to terminate */
293 mutex_unlock(&gspca_dev->usb_lock);
294 /* This waits for jlj_dostream to finish */
295 destroy_workqueue(dev->work_thread);
296 dev->work_thread = NULL;
297 mutex_lock(&gspca_dev->usb_lock);
298 kfree(dev->jpeg_hdr);
299}
300
301/* this function is called at probe and resume time */
302static int sd_init(struct gspca_dev *gspca_dev)
303{
304 return 0;
305}
306
307/* Set up for getting frames. */
308static int sd_start(struct gspca_dev *gspca_dev)
309{
310 struct sd *dev = (struct sd *) gspca_dev;
311 int ret;
312
313 /* create the JPEG header */
314 dev->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
315 jpeg_define(dev->jpeg_hdr, gspca_dev->height, gspca_dev->width,
316 0x21); /* JPEG 422 */
317 jpeg_set_qual(dev->jpeg_hdr, dev->quality);
318 PDEBUG(D_STREAM, "Start streaming at 320x240");
319 ret = jlj_start(gspca_dev);
320 if (ret < 0) {
321 PDEBUG(D_ERR, "Start streaming command failed");
322 return ret;
323 }
324 /* Start the workqueue function to do the streaming */
325 dev->work_thread = create_singlethread_workqueue(MODULE_NAME);
326 queue_work(dev->work_thread, &dev->work_struct);
327
328 return 0;
329}
330
331/* Table of supported USB devices */
332static const __devinitdata struct usb_device_id device_table[] = {
333 {USB_DEVICE(0x0979, 0x0280)},
334 {}
335};
336
337MODULE_DEVICE_TABLE(usb, device_table);
338
339/* sub-driver description */
340static const struct sd_desc sd_desc = {
341 .name = MODULE_NAME,
342 .config = sd_config,
343 .init = sd_init,
344 .start = sd_start,
345 .stop0 = sd_stop0,
346};
347
348/* -- device connect -- */
349static int sd_probe(struct usb_interface *intf,
350 const struct usb_device_id *id)
351{
352 return gspca_dev_probe(intf, id,
353 &sd_desc,
354 sizeof(struct sd),
355 THIS_MODULE);
356}
357
358static struct usb_driver sd_driver = {
359 .name = MODULE_NAME,
360 .id_table = device_table,
361 .probe = sd_probe,
362 .disconnect = gspca_disconnect,
363#ifdef CONFIG_PM
364 .suspend = gspca_suspend,
365 .resume = gspca_resume,
366#endif
367};
368
369/* -- module insert / remove -- */
370static int __init sd_mod_init(void)
371{
372 int ret;
373
374 ret = usb_register(&sd_driver);
375 if (ret < 0)
376 return ret;
377 PDEBUG(D_PROBE, "registered");
378 return 0;
379}
380
381static void __exit sd_mod_exit(void)
382{
383 usb_deregister(&sd_driver);
384 PDEBUG(D_PROBE, "deregistered");
385}
386
387module_init(sd_mod_init);
388module_exit(sd_mod_exit);
diff --git a/drivers/media/video/gspca/m5602/m5602_s5k83a.c b/drivers/media/video/gspca/m5602/m5602_s5k83a.c
index 7127321ace8c..6b89f33a4ce0 100644
--- a/drivers/media/video/gspca/m5602/m5602_s5k83a.c
+++ b/drivers/media/video/gspca/m5602/m5602_s5k83a.c
@@ -178,8 +178,10 @@ sensor_found:
178 178
179 sens_priv->settings = 179 sens_priv->settings =
180 kmalloc(sizeof(s32)*ARRAY_SIZE(s5k83a_ctrls), GFP_KERNEL); 180 kmalloc(sizeof(s32)*ARRAY_SIZE(s5k83a_ctrls), GFP_KERNEL);
181 if (!sens_priv->settings) 181 if (!sens_priv->settings) {
182 kfree(sens_priv);
182 return -ENOMEM; 183 return -ENOMEM;
184 }
183 185
184 sd->gspca_dev.cam.cam_mode = s5k83a_modes; 186 sd->gspca_dev.cam.cam_mode = s5k83a_modes;
185 sd->gspca_dev.cam.nmodes = ARRAY_SIZE(s5k83a_modes); 187 sd->gspca_dev.cam.nmodes = ARRAY_SIZE(s5k83a_modes);
diff --git a/drivers/media/video/gspca/mr97310a.c b/drivers/media/video/gspca/mr97310a.c
index 30132513400c..140c8f320e47 100644
--- a/drivers/media/video/gspca/mr97310a.c
+++ b/drivers/media/video/gspca/mr97310a.c
@@ -3,6 +3,21 @@
3 * 3 *
4 * Copyright (C) 2009 Kyle Guinn <elyk03@gmail.com> 4 * Copyright (C) 2009 Kyle Guinn <elyk03@gmail.com>
5 * 5 *
6 * Support for the MR97310A cameras in addition to the Aiptek Pencam VGA+
7 * and for the routines for detecting and classifying these various cameras,
8 *
9 * Copyright (C) 2009 Theodore Kilgore <kilgota@auburn.edu>
10 *
11 * Acknowledgements:
12 *
13 * The MR97311A support in gspca/mars.c has been helpful in understanding some
14 * of the registers in these cameras.
15 *
16 * Hans de Goede <hdgoede@redhat.com> and
17 * Thomas Kaiser <thomas@kaiser-linux.li>
18 * have assisted with their experience. Each of them has also helped by
19 * testing a previously unsupported camera.
20 *
6 * This program is free software; you can redistribute it and/or modify 21 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 22 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or 23 * the Free Software Foundation; either version 2 of the License, or
@@ -22,18 +37,108 @@
22 37
23#include "gspca.h" 38#include "gspca.h"
24 39
25MODULE_AUTHOR("Kyle Guinn <elyk03@gmail.com>"); 40#define CAM_TYPE_CIF 0
41#define CAM_TYPE_VGA 1
42
43#define MR97310A_BRIGHTNESS_MIN -254
44#define MR97310A_BRIGHTNESS_MAX 255
45#define MR97310A_BRIGHTNESS_DEFAULT 0
46
47#define MR97310A_EXPOSURE_MIN 300
48#define MR97310A_EXPOSURE_MAX 4095
49#define MR97310A_EXPOSURE_DEFAULT 1000
50
51#define MR97310A_GAIN_MIN 0
52#define MR97310A_GAIN_MAX 31
53#define MR97310A_GAIN_DEFAULT 25
54
55MODULE_AUTHOR("Kyle Guinn <elyk03@gmail.com>,"
56 "Theodore Kilgore <kilgota@auburn.edu>");
26MODULE_DESCRIPTION("GSPCA/Mars-Semi MR97310A USB Camera Driver"); 57MODULE_DESCRIPTION("GSPCA/Mars-Semi MR97310A USB Camera Driver");
27MODULE_LICENSE("GPL"); 58MODULE_LICENSE("GPL");
28 59
60/* global parameters */
61int force_sensor_type = -1;
62module_param(force_sensor_type, int, 0644);
63MODULE_PARM_DESC(force_sensor_type, "Force sensor type (-1 (auto), 0 or 1)");
64
29/* specific webcam descriptor */ 65/* specific webcam descriptor */
30struct sd { 66struct sd {
31 struct gspca_dev gspca_dev; /* !! must be the first item */ 67 struct gspca_dev gspca_dev; /* !! must be the first item */
32 u8 sof_read; 68 u8 sof_read;
69 u8 cam_type; /* 0 is CIF and 1 is VGA */
70 u8 sensor_type; /* We use 0 and 1 here, too. */
71 u8 do_lcd_stop;
72
73 int brightness;
74 u16 exposure;
75 u8 gain;
76};
77
78struct sensor_w_data {
79 u8 reg;
80 u8 flags;
81 u8 data[16];
82 int len;
33}; 83};
34 84
85static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
86static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
87static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
88static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);
89static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
90static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
91static void setbrightness(struct gspca_dev *gspca_dev);
92static void setexposure(struct gspca_dev *gspca_dev);
93static void setgain(struct gspca_dev *gspca_dev);
94
35/* V4L2 controls supported by the driver */ 95/* V4L2 controls supported by the driver */
36static struct ctrl sd_ctrls[] = { 96static struct ctrl sd_ctrls[] = {
97 {
98#define BRIGHTNESS_IDX 0
99 {
100 .id = V4L2_CID_BRIGHTNESS,
101 .type = V4L2_CTRL_TYPE_INTEGER,
102 .name = "Brightness",
103 .minimum = MR97310A_BRIGHTNESS_MIN,
104 .maximum = MR97310A_BRIGHTNESS_MAX,
105 .step = 1,
106 .default_value = MR97310A_BRIGHTNESS_DEFAULT,
107 .flags = 0,
108 },
109 .set = sd_setbrightness,
110 .get = sd_getbrightness,
111 },
112 {
113#define EXPOSURE_IDX 1
114 {
115 .id = V4L2_CID_EXPOSURE,
116 .type = V4L2_CTRL_TYPE_INTEGER,
117 .name = "Exposure",
118 .minimum = MR97310A_EXPOSURE_MIN,
119 .maximum = MR97310A_EXPOSURE_MAX,
120 .step = 1,
121 .default_value = MR97310A_EXPOSURE_DEFAULT,
122 .flags = 0,
123 },
124 .set = sd_setexposure,
125 .get = sd_getexposure,
126 },
127 {
128#define GAIN_IDX 2
129 {
130 .id = V4L2_CID_GAIN,
131 .type = V4L2_CTRL_TYPE_INTEGER,
132 .name = "Gain",
133 .minimum = MR97310A_GAIN_MIN,
134 .maximum = MR97310A_GAIN_MAX,
135 .step = 1,
136 .default_value = MR97310A_GAIN_DEFAULT,
137 .flags = 0,
138 },
139 .set = sd_setgain,
140 .get = sd_getgain,
141 },
37}; 142};
38 143
39static const struct v4l2_pix_format vga_mode[] = { 144static const struct v4l2_pix_format vga_mode[] = {
@@ -65,7 +170,7 @@ static const struct v4l2_pix_format vga_mode[] = {
65}; 170};
66 171
67/* the bytes to write are in gspca_dev->usb_buf */ 172/* the bytes to write are in gspca_dev->usb_buf */
68static int reg_w(struct gspca_dev *gspca_dev, int len) 173static int mr_write(struct gspca_dev *gspca_dev, int len)
69{ 174{
70 int rc; 175 int rc;
71 176
@@ -78,15 +183,249 @@ static int reg_w(struct gspca_dev *gspca_dev, int len)
78 return rc; 183 return rc;
79} 184}
80 185
186/* the bytes are read into gspca_dev->usb_buf */
187static int mr_read(struct gspca_dev *gspca_dev, int len)
188{
189 int rc;
190
191 rc = usb_bulk_msg(gspca_dev->dev,
192 usb_rcvbulkpipe(gspca_dev->dev, 3),
193 gspca_dev->usb_buf, len, NULL, 500);
194 if (rc < 0)
195 PDEBUG(D_ERR, "reg read [%02x] error %d",
196 gspca_dev->usb_buf[0], rc);
197 return rc;
198}
199
200static int sensor_write_reg(struct gspca_dev *gspca_dev, u8 reg, u8 flags,
201 const u8 *data, int len)
202{
203 gspca_dev->usb_buf[0] = 0x1f;
204 gspca_dev->usb_buf[1] = flags;
205 gspca_dev->usb_buf[2] = reg;
206 memcpy(gspca_dev->usb_buf + 3, data, len);
207
208 return mr_write(gspca_dev, len + 3);
209}
210
211static int sensor_write_regs(struct gspca_dev *gspca_dev,
212 const struct sensor_w_data *data, int len)
213{
214 int i, rc;
215
216 for (i = 0; i < len; i++) {
217 rc = sensor_write_reg(gspca_dev, data[i].reg, data[i].flags,
218 data[i].data, data[i].len);
219 if (rc < 0)
220 return rc;
221 }
222
223 return 0;
224}
225
226static int sensor_write1(struct gspca_dev *gspca_dev, u8 reg, u8 data)
227{
228 struct sd *sd = (struct sd *) gspca_dev;
229 u8 buf, confirm_reg;
230 int rc;
231
232 buf = data;
233 rc = sensor_write_reg(gspca_dev, reg, 0x01, &buf, 1);
234 if (rc < 0)
235 return rc;
236
237 buf = 0x01;
238 confirm_reg = sd->sensor_type ? 0x13 : 0x11;
239 rc = sensor_write_reg(gspca_dev, confirm_reg, 0x00, &buf, 1);
240 if (rc < 0)
241 return rc;
242
243 return 0;
244}
245
246static int cam_get_response16(struct gspca_dev *gspca_dev)
247{
248 __u8 *data = gspca_dev->usb_buf;
249 int err_code;
250
251 data[0] = 0x21;
252 err_code = mr_write(gspca_dev, 1);
253 if (err_code < 0)
254 return err_code;
255
256 err_code = mr_read(gspca_dev, 16);
257 return err_code;
258}
259
260static int zero_the_pointer(struct gspca_dev *gspca_dev)
261{
262 __u8 *data = gspca_dev->usb_buf;
263 int err_code;
264 u8 status = 0;
265 int tries = 0;
266
267 err_code = cam_get_response16(gspca_dev);
268 if (err_code < 0)
269 return err_code;
270
271 err_code = mr_write(gspca_dev, 1);
272 data[0] = 0x19;
273 data[1] = 0x51;
274 err_code = mr_write(gspca_dev, 2);
275 if (err_code < 0)
276 return err_code;
277
278 err_code = cam_get_response16(gspca_dev);
279 if (err_code < 0)
280 return err_code;
281
282 data[0] = 0x19;
283 data[1] = 0xba;
284 err_code = mr_write(gspca_dev, 2);
285 if (err_code < 0)
286 return err_code;
287
288 err_code = cam_get_response16(gspca_dev);
289 if (err_code < 0)
290 return err_code;
291
292 data[0] = 0x19;
293 data[1] = 0x00;
294 err_code = mr_write(gspca_dev, 2);
295 if (err_code < 0)
296 return err_code;
297
298 err_code = cam_get_response16(gspca_dev);
299 if (err_code < 0)
300 return err_code;
301
302 data[0] = 0x19;
303 data[1] = 0x00;
304 err_code = mr_write(gspca_dev, 2);
305 if (err_code < 0)
306 return err_code;
307
308 while (status != 0x0a && tries < 256) {
309 err_code = cam_get_response16(gspca_dev);
310 status = data[0];
311 tries++;
312 if (err_code < 0)
313 return err_code;
314 }
315 if (status != 0x0a)
316 PDEBUG(D_ERR, "status is %02x", status);
317
318 tries = 0;
319 while (tries < 4) {
320 data[0] = 0x19;
321 data[1] = 0x00;
322 err_code = mr_write(gspca_dev, 2);
323 if (err_code < 0)
324 return err_code;
325
326 err_code = cam_get_response16(gspca_dev);
327 status = data[0];
328 tries++;
329 if (err_code < 0)
330 return err_code;
331 }
332
333 data[0] = 0x19;
334 err_code = mr_write(gspca_dev, 1);
335 if (err_code < 0)
336 return err_code;
337
338 err_code = mr_read(gspca_dev, 16);
339 if (err_code < 0)
340 return err_code;
341
342 return 0;
343}
344
345static u8 get_sensor_id(struct gspca_dev *gspca_dev)
346{
347 int err_code;
348
349 gspca_dev->usb_buf[0] = 0x1e;
350 err_code = mr_write(gspca_dev, 1);
351 if (err_code < 0)
352 return err_code;
353
354 err_code = mr_read(gspca_dev, 16);
355 if (err_code < 0)
356 return err_code;
357
358 PDEBUG(D_PROBE, "Byte zero reported is %01x", gspca_dev->usb_buf[0]);
359
360 return gspca_dev->usb_buf[0];
361}
362
81/* this function is called at probe time */ 363/* this function is called at probe time */
82static int sd_config(struct gspca_dev *gspca_dev, 364static int sd_config(struct gspca_dev *gspca_dev,
83 const struct usb_device_id *id) 365 const struct usb_device_id *id)
84{ 366{
367 struct sd *sd = (struct sd *) gspca_dev;
85 struct cam *cam; 368 struct cam *cam;
369 __u8 *data = gspca_dev->usb_buf;
370 int err_code;
86 371
87 cam = &gspca_dev->cam; 372 cam = &gspca_dev->cam;
88 cam->cam_mode = vga_mode; 373 cam->cam_mode = vga_mode;
89 cam->nmodes = ARRAY_SIZE(vga_mode); 374 cam->nmodes = ARRAY_SIZE(vga_mode);
375
376 if (id->idProduct == 0x010e) {
377 sd->cam_type = CAM_TYPE_CIF;
378 cam->nmodes--;
379
380 data[0] = 0x01;
381 data[1] = 0x01;
382 err_code = mr_write(gspca_dev, 2);
383 if (err_code < 0)
384 return err_code;
385
386 msleep(200);
387 data[0] = get_sensor_id(gspca_dev);
388 /*
389 * Known CIF cameras. If you have another to report, please do
390 *
391 * Name byte just read sd->sensor_type
392 * reported by
393 * Sakar Spy-shot 0x28 T. Kilgore 0
394 * Innovage 0xf5 (unstable) T. Kilgore 0
395 * Vivitar Mini 0x53 H. De Goede 0
396 * Vivitar Mini 0x04 / 0x24 E. Rodriguez 0
397 * Vivitar Mini 0x08 T. Kilgore 1
398 * Elta-Media 8212dc 0x23 T. Kaiser 1
399 * Philips dig. keych. 0x37 T. Kilgore 1
400 */
401 if ((data[0] & 0x78) == 8 ||
402 ((data[0] & 0x2) == 0x2 && data[0] != 0x53))
403 sd->sensor_type = 1;
404 else
405 sd->sensor_type = 0;
406
407 PDEBUG(D_PROBE, "MR97310A CIF camera detected, sensor: %d",
408 sd->sensor_type);
409
410 if (force_sensor_type != -1) {
411 sd->sensor_type = !! force_sensor_type;
412 PDEBUG(D_PROBE, "Forcing sensor type to: %d",
413 sd->sensor_type);
414 }
415
416 if (sd->sensor_type == 0)
417 gspca_dev->ctrl_dis = (1 << BRIGHTNESS_IDX);
418 } else {
419 sd->cam_type = CAM_TYPE_VGA;
420 PDEBUG(D_PROBE, "MR97310A VGA camera detected");
421 gspca_dev->ctrl_dis = (1 << BRIGHTNESS_IDX) |
422 (1 << EXPOSURE_IDX) | (1 << GAIN_IDX);
423 }
424
425 sd->brightness = MR97310A_BRIGHTNESS_DEFAULT;
426 sd->exposure = MR97310A_EXPOSURE_DEFAULT;
427 sd->gain = MR97310A_GAIN_DEFAULT;
428
90 return 0; 429 return 0;
91} 430}
92 431
@@ -96,183 +435,462 @@ static int sd_init(struct gspca_dev *gspca_dev)
96 return 0; 435 return 0;
97} 436}
98 437
99static int sd_start(struct gspca_dev *gspca_dev) 438static int start_cif_cam(struct gspca_dev *gspca_dev)
100{ 439{
101 struct sd *sd = (struct sd *) gspca_dev; 440 struct sd *sd = (struct sd *) gspca_dev;
102 __u8 *data = gspca_dev->usb_buf; 441 __u8 *data = gspca_dev->usb_buf;
103 int err_code; 442 int err_code;
104 443 const __u8 startup_string[] = {
105 sd->sof_read = 0; 444 0x00,
106 445 0x0d,
107 /* Note: register descriptions guessed from MR97113A driver */ 446 0x01,
108 447 0x00, /* Hsize/8 for 352 or 320 */
448 0x00, /* Vsize/4 for 288 or 240 */
449 0x13, /* or 0xbb, depends on sensor */
450 0x00, /* Hstart, depends on res. */
451 0x00, /* reserved ? */
452 0x00, /* Vstart, depends on res. and sensor */
453 0x50, /* 0x54 to get 176 or 160 */
454 0xc0
455 };
456
457 /* Note: Some of the above descriptions guessed from MR97113A driver */
109 data[0] = 0x01; 458 data[0] = 0x01;
110 data[1] = 0x01; 459 data[1] = 0x01;
111 err_code = reg_w(gspca_dev, 2); 460 err_code = mr_write(gspca_dev, 2);
112 if (err_code < 0) 461 if (err_code < 0)
113 return err_code; 462 return err_code;
114 463
115 data[0] = 0x00; 464 memcpy(data, startup_string, 11);
116 data[1] = 0x0d; 465 if (sd->sensor_type)
117 data[2] = 0x01; 466 data[5] = 0xbb;
118 data[5] = 0x2b;
119 data[7] = 0x00;
120 data[9] = 0x50; /* reg 8, no scale down */
121 data[10] = 0xc0;
122 467
123 switch (gspca_dev->width) { 468 switch (gspca_dev->width) {
124 case 160: 469 case 160:
125 data[9] |= 0x0c; /* reg 8, 4:1 scale down */ 470 data[9] |= 0x04; /* reg 8, 2:1 scale down from 320 */
126 /* fall thru */ 471 /* fall thru */
127 case 320: 472 case 320:
128 data[9] |= 0x04; /* reg 8, 2:1 scale down */
129 /* fall thru */
130 case 640:
131 default: 473 default:
132 data[3] = 0x50; /* reg 2, H size */ 474 data[3] = 0x28; /* reg 2, H size/8 */
133 data[4] = 0x78; /* reg 3, V size */ 475 data[4] = 0x3c; /* reg 3, V size/4 */
134 data[6] = 0x04; /* reg 5, H start */ 476 data[6] = 0x14; /* reg 5, H start */
135 data[8] = 0x03; /* reg 7, V start */ 477 data[8] = 0x1a + sd->sensor_type; /* reg 7, V start */
136 break; 478 break;
137
138 case 176: 479 case 176:
139 data[9] |= 0x04; /* reg 8, 2:1 scale down */ 480 data[9] |= 0x04; /* reg 8, 2:1 scale down from 352 */
140 /* fall thru */ 481 /* fall thru */
141 case 352: 482 case 352:
142 data[3] = 0x2c; /* reg 2, H size */ 483 data[3] = 0x2c; /* reg 2, H size/8 */
143 data[4] = 0x48; /* reg 3, V size */ 484 data[4] = 0x48; /* reg 3, V size/4 */
144 data[6] = 0x94; /* reg 5, H start */ 485 data[6] = 0x06; /* reg 5, H start */
145 data[8] = 0x63; /* reg 7, V start */ 486 data[8] = 0x06 + sd->sensor_type; /* reg 7, V start */
146 break; 487 break;
147 } 488 }
148 489 err_code = mr_write(gspca_dev, 11);
149 err_code = reg_w(gspca_dev, 11);
150 if (err_code < 0) 490 if (err_code < 0)
151 return err_code; 491 return err_code;
152 492
153 data[0] = 0x0a; 493 if (!sd->sensor_type) {
154 data[1] = 0x80; 494 const struct sensor_w_data cif_sensor0_init_data[] = {
155 err_code = reg_w(gspca_dev, 2); 495 {0x02, 0x00, {0x03, 0x5a, 0xb5, 0x01,
496 0x0f, 0x14, 0x0f, 0x10}, 8},
497 {0x0c, 0x00, {0x04, 0x01, 0x01, 0x00, 0x1f}, 5},
498 {0x12, 0x00, {0x07}, 1},
499 {0x1f, 0x00, {0x06}, 1},
500 {0x27, 0x00, {0x04}, 1},
501 {0x29, 0x00, {0x0c}, 1},
502 {0x40, 0x00, {0x40, 0x00, 0x04}, 3},
503 {0x50, 0x00, {0x60}, 1},
504 {0x60, 0x00, {0x06}, 1},
505 {0x6b, 0x00, {0x85, 0x85, 0xc8, 0xc8, 0xc8, 0xc8}, 6},
506 {0x72, 0x00, {0x1e, 0x56}, 2},
507 {0x75, 0x00, {0x58, 0x40, 0xa2, 0x02, 0x31, 0x02,
508 0x31, 0x80, 0x00}, 9},
509 {0x11, 0x00, {0x01}, 1},
510 {0, 0, {0}, 0}
511 };
512 err_code = sensor_write_regs(gspca_dev, cif_sensor0_init_data,
513 ARRAY_SIZE(cif_sensor0_init_data));
514 } else { /* sd->sensor_type = 1 */
515 const struct sensor_w_data cif_sensor1_init_data[] = {
516 /* Reg 3,4, 7,8 get set by the controls */
517 {0x02, 0x00, {0x10}, 1},
518 {0x05, 0x01, {0x22}, 1}, /* 5/6 also seen as 65h/32h */
519 {0x06, 0x01, {0x00}, 1},
520 {0x09, 0x02, {0x0e}, 1},
521 {0x0a, 0x02, {0x05}, 1},
522 {0x0b, 0x02, {0x05}, 1},
523 {0x0c, 0x02, {0x0f}, 1},
524 {0x0d, 0x02, {0x07}, 1},
525 {0x0e, 0x02, {0x0c}, 1},
526 {0x0f, 0x00, {0x00}, 1},
527 {0x10, 0x00, {0x06}, 1},
528 {0x11, 0x00, {0x07}, 1},
529 {0x12, 0x00, {0x00}, 1},
530 {0x13, 0x00, {0x01}, 1},
531 {0, 0, {0}, 0}
532 };
533 err_code = sensor_write_regs(gspca_dev, cif_sensor1_init_data,
534 ARRAY_SIZE(cif_sensor1_init_data));
535 }
156 if (err_code < 0) 536 if (err_code < 0)
157 return err_code; 537 return err_code;
158 538
159 data[0] = 0x14; 539 setbrightness(gspca_dev);
160 data[1] = 0x0a; 540 setexposure(gspca_dev);
161 err_code = reg_w(gspca_dev, 2); 541 setgain(gspca_dev);
162 if (err_code < 0)
163 return err_code;
164 542
165 data[0] = 0x1b; 543 msleep(200);
166 data[1] = 0x00;
167 err_code = reg_w(gspca_dev, 2);
168 if (err_code < 0)
169 return err_code;
170 544
171 data[0] = 0x15; 545 data[0] = 0x00;
172 data[1] = 0x16; 546 data[1] = 0x4d; /* ISOC transfering enable... */
173 err_code = reg_w(gspca_dev, 2); 547 err_code = mr_write(gspca_dev, 2);
174 if (err_code < 0) 548 if (err_code < 0)
175 return err_code; 549 return err_code;
176 550
177 data[0] = 0x16; 551 return 0;
178 data[1] = 0x10; 552}
179 err_code = reg_w(gspca_dev, 2);
180 if (err_code < 0)
181 return err_code;
182 553
183 data[0] = 0x17; 554static int start_vga_cam(struct gspca_dev *gspca_dev)
184 data[1] = 0x3a; 555{
185 err_code = reg_w(gspca_dev, 2); 556 struct sd *sd = (struct sd *) gspca_dev;
186 if (err_code < 0) 557 __u8 *data = gspca_dev->usb_buf;
187 return err_code; 558 int err_code;
559 const __u8 startup_string[] = {0x00, 0x0d, 0x01, 0x00, 0x00, 0x2b,
560 0x00, 0x00, 0x00, 0x50, 0xc0};
188 561
189 data[0] = 0x18; 562 /* What some of these mean is explained in start_cif_cam(), above */
190 data[1] = 0x68; 563 sd->sof_read = 0;
191 err_code = reg_w(gspca_dev, 2);
192 if (err_code < 0)
193 return err_code;
194 564
195 data[0] = 0x1f; 565 /*
196 data[1] = 0x00; 566 * We have to know which camera we have, because the register writes
197 data[2] = 0x02; 567 * depend upon the camera. This test, run before we actually enter
198 data[3] = 0x06; 568 * the initialization routine, distinguishes most of the cameras, If
199 data[4] = 0x59; 569 * needed, another routine is done later, too.
200 data[5] = 0x0c; 570 */
201 data[6] = 0x16; 571 memset(data, 0, 16);
202 data[7] = 0x00; 572 data[0] = 0x20;
203 data[8] = 0x07; 573 err_code = mr_write(gspca_dev, 1);
204 data[9] = 0x00;
205 data[10] = 0x01;
206 err_code = reg_w(gspca_dev, 11);
207 if (err_code < 0) 574 if (err_code < 0)
208 return err_code; 575 return err_code;
209 576
210 data[0] = 0x1f; 577 err_code = mr_read(gspca_dev, 16);
211 data[1] = 0x04;
212 data[2] = 0x11;
213 data[3] = 0x01;
214 err_code = reg_w(gspca_dev, 4);
215 if (err_code < 0) 578 if (err_code < 0)
216 return err_code; 579 return err_code;
217 580
218 data[0] = 0x1f; 581 PDEBUG(D_PROBE, "Byte reported is %02x", data[0]);
219 data[1] = 0x00; 582
220 data[2] = 0x0a; 583 msleep(200);
221 data[3] = 0x00; 584 /*
222 data[4] = 0x01; 585 * Known VGA cameras. If you have another to report, please do
223 data[5] = 0x00; 586 *
224 data[6] = 0x00; 587 * Name byte just read sd->sensor_type
225 data[7] = 0x01; 588 * sd->do_lcd_stop
226 data[8] = 0x00; 589 * Aiptek Pencam VGA+ 0x31 0 1
227 data[9] = 0x0a; 590 * ION digital 0x31 0 1
228 err_code = reg_w(gspca_dev, 10); 591 * Argus DC-1620 0x30 1 0
229 if (err_code < 0) 592 * Argus QuickClix 0x30 1 1 (not caught here)
230 return err_code; 593 */
594 sd->sensor_type = data[0] & 1;
595 sd->do_lcd_stop = (~data[0]) & 1;
596
597
231 598
232 data[0] = 0x1f; 599 /* Streaming setup begins here. */
233 data[1] = 0x04; 600
234 data[2] = 0x11; 601
235 data[3] = 0x01; 602 data[0] = 0x01;
236 err_code = reg_w(gspca_dev, 4); 603 data[1] = 0x01;
604 err_code = mr_write(gspca_dev, 2);
237 if (err_code < 0) 605 if (err_code < 0)
238 return err_code; 606 return err_code;
239 607
240 data[0] = 0x1f; 608 /*
241 data[1] = 0x00; 609 * A second test can now resolve any remaining ambiguity in the
242 data[2] = 0x12; 610 * identification of the camera type,
243 data[3] = 0x00; 611 */
244 data[4] = 0x63; 612 if (!sd->sensor_type) {
245 data[5] = 0x00; 613 data[0] = get_sensor_id(gspca_dev);
246 data[6] = 0x70; 614 if (data[0] == 0x7f) {
247 data[7] = 0x00; 615 sd->sensor_type = 1;
248 data[8] = 0x00; 616 PDEBUG(D_PROBE, "sensor_type corrected to 1");
249 err_code = reg_w(gspca_dev, 9); 617 }
618 msleep(200);
619 }
620
621 if (force_sensor_type != -1) {
622 sd->sensor_type = !! force_sensor_type;
623 PDEBUG(D_PROBE, "Forcing sensor type to: %d",
624 sd->sensor_type);
625 }
626
627 /*
628 * Known VGA cameras.
629 * This test is only run if the previous test returned 0x30, but
630 * here is the information for all others, too, just for reference.
631 *
632 * Name byte just read sd->sensor_type
633 *
634 * Aiptek Pencam VGA+ 0xfb (this test not run) 1
635 * ION digital 0xbd (this test not run) 1
636 * Argus DC-1620 0xe5 (no change) 0
637 * Argus QuickClix 0x7f (reclassified) 1
638 */
639 memcpy(data, startup_string, 11);
640 if (!sd->sensor_type) {
641 data[5] = 0x00;
642 data[10] = 0x91;
643 }
644
645 switch (gspca_dev->width) {
646 case 160:
647 data[9] |= 0x0c; /* reg 8, 4:1 scale down */
648 /* fall thru */
649 case 320:
650 data[9] |= 0x04; /* reg 8, 2:1 scale down */
651 /* fall thru */
652 case 640:
653 default:
654 data[3] = 0x50; /* reg 2, H size/8 */
655 data[4] = 0x78; /* reg 3, V size/4 */
656 data[6] = 0x04; /* reg 5, H start */
657 data[8] = 0x03; /* reg 7, V start */
658 if (sd->do_lcd_stop)
659 data[8] = 0x04; /* Bayer tile shifted */
660 break;
661
662 case 176:
663 data[9] |= 0x04; /* reg 8, 2:1 scale down */
664 /* fall thru */
665 case 352:
666 data[3] = 0x2c; /* reg 2, H size */
667 data[4] = 0x48; /* reg 3, V size */
668 data[6] = 0x94; /* reg 5, H start */
669 data[8] = 0x63; /* reg 7, V start */
670 if (sd->do_lcd_stop)
671 data[8] = 0x64; /* Bayer tile shifted */
672 break;
673 }
674
675 err_code = mr_write(gspca_dev, 11);
250 if (err_code < 0) 676 if (err_code < 0)
251 return err_code; 677 return err_code;
252 678
253 data[0] = 0x1f; 679 if (!sd->sensor_type) {
254 data[1] = 0x04; 680 /* The only known sensor_type 0 cam is the Argus DC-1620 */
255 data[2] = 0x11; 681 const struct sensor_w_data vga_sensor0_init_data[] = {
256 data[3] = 0x01; 682 {0x01, 0x00, {0x0c, 0x00, 0x04}, 3},
257 err_code = reg_w(gspca_dev, 4); 683 {0x14, 0x00, {0x01, 0xe4, 0x02, 0x84}, 4},
684 {0x20, 0x00, {0x00, 0x80, 0x00, 0x08}, 4},
685 {0x25, 0x00, {0x03, 0xa9, 0x80}, 3},
686 {0x30, 0x00, {0x30, 0x18, 0x10, 0x18}, 4},
687 {0, 0, {0}, 0}
688 };
689 err_code = sensor_write_regs(gspca_dev, vga_sensor0_init_data,
690 ARRAY_SIZE(vga_sensor0_init_data));
691 } else { /* sd->sensor_type = 1 */
692 const struct sensor_w_data vga_sensor1_init_data[] = {
693 {0x02, 0x00, {0x06, 0x59, 0x0c, 0x16, 0x00,
694 0x07, 0x00, 0x01}, 8},
695 {0x11, 0x04, {0x01}, 1},
696 /*{0x0a, 0x00, {0x00, 0x01, 0x00, 0x00, 0x01, */
697 {0x0a, 0x00, {0x01, 0x06, 0x00, 0x00, 0x01,
698 0x00, 0x0a}, 7},
699 {0x11, 0x04, {0x01}, 1},
700 {0x12, 0x00, {0x00, 0x63, 0x00, 0x70, 0x00, 0x00}, 6},
701 {0x11, 0x04, {0x01}, 1},
702 {0, 0, {0}, 0}
703 };
704 err_code = sensor_write_regs(gspca_dev, vga_sensor1_init_data,
705 ARRAY_SIZE(vga_sensor1_init_data));
706 }
258 if (err_code < 0) 707 if (err_code < 0)
259 return err_code; 708 return err_code;
260 709
710 msleep(200);
261 data[0] = 0x00; 711 data[0] = 0x00;
262 data[1] = 0x4d; /* ISOC transfering enable... */ 712 data[1] = 0x4d; /* ISOC transfering enable... */
263 err_code = reg_w(gspca_dev, 2); 713 err_code = mr_write(gspca_dev, 2);
714
715 return err_code;
716}
717
718static int sd_start(struct gspca_dev *gspca_dev)
719{
720 struct sd *sd = (struct sd *) gspca_dev;
721 int err_code;
722 struct cam *cam;
723
724 cam = &gspca_dev->cam;
725 sd->sof_read = 0;
726 /*
727 * Some of the supported cameras require the memory pointer to be
728 * set to 0, or else they will not stream.
729 */
730 zero_the_pointer(gspca_dev);
731 msleep(200);
732 if (sd->cam_type == CAM_TYPE_CIF) {
733 err_code = start_cif_cam(gspca_dev);
734 } else {
735 err_code = start_vga_cam(gspca_dev);
736 }
264 return err_code; 737 return err_code;
265} 738}
266 739
267static void sd_stopN(struct gspca_dev *gspca_dev) 740static void sd_stopN(struct gspca_dev *gspca_dev)
268{ 741{
742 struct sd *sd = (struct sd *) gspca_dev;
269 int result; 743 int result;
270 744
271 gspca_dev->usb_buf[0] = 1; 745 gspca_dev->usb_buf[0] = 1;
272 gspca_dev->usb_buf[1] = 0; 746 gspca_dev->usb_buf[1] = 0;
273 result = reg_w(gspca_dev, 2); 747 result = mr_write(gspca_dev, 2);
274 if (result < 0) 748 if (result < 0)
275 PDEBUG(D_ERR, "Camera Stop failed"); 749 PDEBUG(D_ERR, "Camera Stop failed");
750
751 /* Not all the cams need this, but even if not, probably a good idea */
752 zero_the_pointer(gspca_dev);
753 if (sd->do_lcd_stop) {
754 gspca_dev->usb_buf[0] = 0x19;
755 gspca_dev->usb_buf[1] = 0x54;
756 result = mr_write(gspca_dev, 2);
757 if (result < 0)
758 PDEBUG(D_ERR, "Camera Stop failed");
759 }
760}
761
762static void setbrightness(struct gspca_dev *gspca_dev)
763{
764 struct sd *sd = (struct sd *) gspca_dev;
765 u8 val;
766
767 if (gspca_dev->ctrl_dis & (1 << BRIGHTNESS_IDX))
768 return;
769
770 /* Note register 7 is also seen as 0x8x or 0xCx in dumps */
771 if (sd->brightness > 0) {
772 sensor_write1(gspca_dev, 7, 0x00);
773 val = sd->brightness;
774 } else {
775 sensor_write1(gspca_dev, 7, 0x01);
776 val = 257 - sd->brightness;
777 }
778 sensor_write1(gspca_dev, 8, val);
779}
780
781static void setexposure(struct gspca_dev *gspca_dev)
782{
783 struct sd *sd = (struct sd *) gspca_dev;
784 u8 val;
785
786 if (gspca_dev->ctrl_dis & (1 << EXPOSURE_IDX))
787 return;
788
789 if (sd->sensor_type) {
790 val = sd->exposure >> 4;
791 sensor_write1(gspca_dev, 3, val);
792 val = sd->exposure & 0xf;
793 sensor_write1(gspca_dev, 4, val);
794 } else {
795 u8 clockdiv;
796 int exposure;
797
798 /* We have both a clock divider and an exposure register.
799 We first calculate the clock divider, as that determines
800 the maximum exposure and then we calculayte the exposure
801 register setting (which goes from 0 - 511).
802
803 Note our 0 - 4095 exposure is mapped to 0 - 511
804 milliseconds exposure time */
805 clockdiv = (60 * sd->exposure + 7999) / 8000;
806
807 /* Limit framerate to not exceed usb bandwidth */
808 if (clockdiv < 3 && gspca_dev->width >= 320)
809 clockdiv = 3;
810 else if (clockdiv < 2)
811 clockdiv = 2;
812
813 /* Frame exposure time in ms = 1000 * clockdiv / 60 ->
814 exposure = (sd->exposure / 8) * 511 / (1000 * clockdiv / 60) */
815 exposure = (60 * 511 * sd->exposure) / (8000 * clockdiv);
816 if (exposure > 511)
817 exposure = 511;
818
819 /* exposure register value is reversed! */
820 exposure = 511 - exposure;
821
822 sensor_write1(gspca_dev, 0x02, clockdiv);
823 sensor_write1(gspca_dev, 0x0e, exposure & 0xff);
824 sensor_write1(gspca_dev, 0x0f, exposure >> 8);
825 }
826}
827
828static void setgain(struct gspca_dev *gspca_dev)
829{
830 struct sd *sd = (struct sd *) gspca_dev;
831
832 if (gspca_dev->ctrl_dis & (1 << GAIN_IDX))
833 return;
834
835 if (sd->sensor_type) {
836 sensor_write1(gspca_dev, 0x0e, sd->gain);
837 } else {
838 sensor_write1(gspca_dev, 0x10, sd->gain);
839 }
840}
841
842static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
843{
844 struct sd *sd = (struct sd *) gspca_dev;
845
846 sd->brightness = val;
847 if (gspca_dev->streaming)
848 setbrightness(gspca_dev);
849 return 0;
850}
851
852static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
853{
854 struct sd *sd = (struct sd *) gspca_dev;
855
856 *val = sd->brightness;
857 return 0;
858}
859
860static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
861{
862 struct sd *sd = (struct sd *) gspca_dev;
863
864 sd->exposure = val;
865 if (gspca_dev->streaming)
866 setexposure(gspca_dev);
867 return 0;
868}
869
870static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
871{
872 struct sd *sd = (struct sd *) gspca_dev;
873
874 *val = sd->exposure;
875 return 0;
876}
877
878static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
879{
880 struct sd *sd = (struct sd *) gspca_dev;
881
882 sd->gain = val;
883 if (gspca_dev->streaming)
884 setgain(gspca_dev);
885 return 0;
886}
887
888static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
889{
890 struct sd *sd = (struct sd *) gspca_dev;
891
892 *val = sd->gain;
893 return 0;
276} 894}
277 895
278/* Include pac common sof detection functions */ 896/* Include pac common sof detection functions */
@@ -320,8 +938,9 @@ static const struct sd_desc sd_desc = {
320 938
321/* -- module initialisation -- */ 939/* -- module initialisation -- */
322static const __devinitdata struct usb_device_id device_table[] = { 940static const __devinitdata struct usb_device_id device_table[] = {
323 {USB_DEVICE(0x08ca, 0x0111)}, 941 {USB_DEVICE(0x08ca, 0x0111)}, /* Aiptek Pencam VGA+ */
324 {USB_DEVICE(0x093a, 0x010f)}, 942 {USB_DEVICE(0x093a, 0x010f)}, /* All other known MR97310A VGA cams */
943 {USB_DEVICE(0x093a, 0x010e)}, /* All known MR97310A CIF cams */
325 {} 944 {}
326}; 945};
327MODULE_DEVICE_TABLE(usb, device_table); 946MODULE_DEVICE_TABLE(usb, device_table);
diff --git a/drivers/media/video/gspca/pac207.c b/drivers/media/video/gspca/pac207.c
index 95a97ab684cd..96659433d248 100644
--- a/drivers/media/video/gspca/pac207.c
+++ b/drivers/media/video/gspca/pac207.c
@@ -35,25 +35,17 @@ MODULE_LICENSE("GPL");
35 35
36#define PAC207_BRIGHTNESS_MIN 0 36#define PAC207_BRIGHTNESS_MIN 0
37#define PAC207_BRIGHTNESS_MAX 255 37#define PAC207_BRIGHTNESS_MAX 255
38#define PAC207_BRIGHTNESS_DEFAULT 4 /* power on default: 4 */ 38#define PAC207_BRIGHTNESS_DEFAULT 46
39 39
40/* An exposure value of 4 also works (3 does not) but then we need to lower 40#define PAC207_EXPOSURE_MIN 3
41 the compression balance setting when in 352x288 mode, otherwise the usb
42 bandwidth is not enough and packets get dropped resulting in corrupt
43 frames. The problem with this is that when the compression balance gets
44 lowered below 0x80, the pac207 starts using a different compression
45 algorithm for some lines, these lines get prefixed with a 0x2dd2 prefix
46 and currently we do not know how to decompress these lines, so for now
47 we use a minimum exposure value of 5 */
48#define PAC207_EXPOSURE_MIN 5
49#define PAC207_EXPOSURE_MAX 26 41#define PAC207_EXPOSURE_MAX 26
50#define PAC207_EXPOSURE_DEFAULT 5 /* power on default: 3 ?? */ 42#define PAC207_EXPOSURE_DEFAULT 5 /* power on default: 3 */
51#define PAC207_EXPOSURE_KNEE 11 /* 4 = 30 fps, 11 = 8, 15 = 6 */ 43#define PAC207_EXPOSURE_KNEE 8 /* 4 = 30 fps, 11 = 8, 15 = 6 */
52 44
53#define PAC207_GAIN_MIN 0 45#define PAC207_GAIN_MIN 0
54#define PAC207_GAIN_MAX 31 46#define PAC207_GAIN_MAX 31
55#define PAC207_GAIN_DEFAULT 9 /* power on default: 9 */ 47#define PAC207_GAIN_DEFAULT 9 /* power on default: 9 */
56#define PAC207_GAIN_KNEE 20 48#define PAC207_GAIN_KNEE 31
57 49
58#define PAC207_AUTOGAIN_DEADZONE 30 50#define PAC207_AUTOGAIN_DEADZONE 30
59 51
@@ -166,16 +158,12 @@ static const struct v4l2_pix_format sif_mode[] = {
166}; 158};
167 159
168static const __u8 pac207_sensor_init[][8] = { 160static const __u8 pac207_sensor_init[][8] = {
169 {0x10, 0x12, 0x0d, 0x12, 0x0c, 0x01, 0x29, 0xf0}, 161 {0x10, 0x12, 0x0d, 0x12, 0x0c, 0x01, 0x29, 0x84},
170 {0x00, 0x64, 0x64, 0x64, 0x04, 0x10, 0xf0, 0x30}, 162 {0x49, 0x64, 0x64, 0x64, 0x04, 0x10, 0xf0, 0x30},
171 {0x00, 0x00, 0x00, 0x70, 0xa0, 0xf8, 0x00, 0x00}, 163 {0x00, 0x00, 0x00, 0x70, 0xa0, 0xf8, 0x00, 0x00},
172 {0x00, 0x00, 0x32, 0x00, 0x96, 0x00, 0xa2, 0x02},
173 {0x32, 0x00, 0x96, 0x00, 0xA2, 0x02, 0xaf, 0x00}, 164 {0x32, 0x00, 0x96, 0x00, 0xA2, 0x02, 0xaf, 0x00},
174}; 165};
175 166
176 /* 48 reg_72 Rate Control end BalSize_4a =0x36 */
177static const __u8 PacReg72[] = { 0x00, 0x00, 0x36, 0x00 };
178
179static int pac207_write_regs(struct gspca_dev *gspca_dev, u16 index, 167static int pac207_write_regs(struct gspca_dev *gspca_dev, u16 index,
180 const u8 *buffer, u16 length) 168 const u8 *buffer, u16 length)
181{ 169{
@@ -274,7 +262,6 @@ static int sd_init(struct gspca_dev *gspca_dev)
274 * Bit_1=LED, 262 * Bit_1=LED,
275 * Bit_2=Compression test mode enable */ 263 * Bit_2=Compression test mode enable */
276 pac207_write_reg(gspca_dev, 0x0f, 0x00); /* Power Control */ 264 pac207_write_reg(gspca_dev, 0x0f, 0x00); /* Power Control */
277 pac207_write_reg(gspca_dev, 0x11, 0x30); /* Analog Bias */
278 265
279 return 0; 266 return 0;
280} 267}
@@ -289,15 +276,13 @@ static int sd_start(struct gspca_dev *gspca_dev)
289 pac207_write_regs(gspca_dev, 0x0002, pac207_sensor_init[0], 8); 276 pac207_write_regs(gspca_dev, 0x0002, pac207_sensor_init[0], 8);
290 pac207_write_regs(gspca_dev, 0x000a, pac207_sensor_init[1], 8); 277 pac207_write_regs(gspca_dev, 0x000a, pac207_sensor_init[1], 8);
291 pac207_write_regs(gspca_dev, 0x0012, pac207_sensor_init[2], 8); 278 pac207_write_regs(gspca_dev, 0x0012, pac207_sensor_init[2], 8);
292 pac207_write_regs(gspca_dev, 0x0040, pac207_sensor_init[3], 8); 279 pac207_write_regs(gspca_dev, 0x0042, pac207_sensor_init[3], 8);
293 pac207_write_regs(gspca_dev, 0x0042, pac207_sensor_init[4], 8);
294 pac207_write_regs(gspca_dev, 0x0048, PacReg72, 4);
295 280
296 /* Compression Balance */ 281 /* Compression Balance */
297 if (gspca_dev->width == 176) 282 if (gspca_dev->width == 176)
298 pac207_write_reg(gspca_dev, 0x4a, 0xff); 283 pac207_write_reg(gspca_dev, 0x4a, 0xff);
299 else 284 else
300 pac207_write_reg(gspca_dev, 0x4a, 0x88); 285 pac207_write_reg(gspca_dev, 0x4a, 0x30);
301 pac207_write_reg(gspca_dev, 0x4b, 0x00); /* Sram test value */ 286 pac207_write_reg(gspca_dev, 0x4b, 0x00); /* Sram test value */
302 pac207_write_reg(gspca_dev, 0x08, sd->brightness); 287 pac207_write_reg(gspca_dev, 0x08, sd->brightness);
303 288
@@ -346,7 +331,7 @@ static void pac207_do_auto_gain(struct gspca_dev *gspca_dev)
346 if (sd->autogain_ignore_frames > 0) 331 if (sd->autogain_ignore_frames > 0)
347 sd->autogain_ignore_frames--; 332 sd->autogain_ignore_frames--;
348 else if (gspca_auto_gain_n_exposure(gspca_dev, avg_lum, 333 else if (gspca_auto_gain_n_exposure(gspca_dev, avg_lum,
349 100 + sd->brightness / 2, PAC207_AUTOGAIN_DEADZONE, 334 100, PAC207_AUTOGAIN_DEADZONE,
350 PAC207_GAIN_KNEE, PAC207_EXPOSURE_KNEE)) 335 PAC207_GAIN_KNEE, PAC207_EXPOSURE_KNEE))
351 sd->autogain_ignore_frames = PAC_AUTOGAIN_IGNORE_FRAMES; 336 sd->autogain_ignore_frames = PAC_AUTOGAIN_IGNORE_FRAMES;
352} 337}
diff --git a/drivers/media/video/gspca/pac7311.c b/drivers/media/video/gspca/pac7311.c
index e1e3a3a50484..052714484e83 100644
--- a/drivers/media/video/gspca/pac7311.c
+++ b/drivers/media/video/gspca/pac7311.c
@@ -1057,6 +1057,7 @@ static struct sd_desc sd_desc = {
1057 1057
1058/* -- module initialisation -- */ 1058/* -- module initialisation -- */
1059static __devinitdata struct usb_device_id device_table[] = { 1059static __devinitdata struct usb_device_id device_table[] = {
1060 {USB_DEVICE(0x06f8, 0x3009), .driver_info = SENSOR_PAC7302},
1060 {USB_DEVICE(0x093a, 0x2600), .driver_info = SENSOR_PAC7311}, 1061 {USB_DEVICE(0x093a, 0x2600), .driver_info = SENSOR_PAC7311},
1061 {USB_DEVICE(0x093a, 0x2601), .driver_info = SENSOR_PAC7311}, 1062 {USB_DEVICE(0x093a, 0x2601), .driver_info = SENSOR_PAC7311},
1062 {USB_DEVICE(0x093a, 0x2603), .driver_info = SENSOR_PAC7311}, 1063 {USB_DEVICE(0x093a, 0x2603), .driver_info = SENSOR_PAC7311},
@@ -1068,6 +1069,7 @@ static __devinitdata struct usb_device_id device_table[] = {
1068 {USB_DEVICE(0x093a, 0x2622), .driver_info = SENSOR_PAC7302}, 1069 {USB_DEVICE(0x093a, 0x2622), .driver_info = SENSOR_PAC7302},
1069 {USB_DEVICE(0x093a, 0x2624), .driver_info = SENSOR_PAC7302}, 1070 {USB_DEVICE(0x093a, 0x2624), .driver_info = SENSOR_PAC7302},
1070 {USB_DEVICE(0x093a, 0x2626), .driver_info = SENSOR_PAC7302}, 1071 {USB_DEVICE(0x093a, 0x2626), .driver_info = SENSOR_PAC7302},
1072 {USB_DEVICE(0x093a, 0x2629), .driver_info = SENSOR_PAC7302},
1071 {USB_DEVICE(0x093a, 0x262a), .driver_info = SENSOR_PAC7302}, 1073 {USB_DEVICE(0x093a, 0x262a), .driver_info = SENSOR_PAC7302},
1072 {USB_DEVICE(0x093a, 0x262c), .driver_info = SENSOR_PAC7302}, 1074 {USB_DEVICE(0x093a, 0x262c), .driver_info = SENSOR_PAC7302},
1073 {} 1075 {}
diff --git a/drivers/media/video/gspca/sn9c20x.c b/drivers/media/video/gspca/sn9c20x.c
index fcfbbd329b4c..cdad3db33367 100644
--- a/drivers/media/video/gspca/sn9c20x.c
+++ b/drivers/media/video/gspca/sn9c20x.c
@@ -94,6 +94,16 @@ struct sd {
94#endif 94#endif
95}; 95};
96 96
97struct i2c_reg_u8 {
98 u8 reg;
99 u8 val;
100};
101
102struct i2c_reg_u16 {
103 u8 reg;
104 u16 val;
105};
106
97static int sd_setbrightness(struct gspca_dev *gspca_dev, s32 val); 107static int sd_setbrightness(struct gspca_dev *gspca_dev, s32 val);
98static int sd_getbrightness(struct gspca_dev *gspca_dev, s32 *val); 108static int sd_getbrightness(struct gspca_dev *gspca_dev, s32 *val);
99static int sd_setcontrast(struct gspca_dev *gspca_dev, s32 val); 109static int sd_setcontrast(struct gspca_dev *gspca_dev, s32 val);
@@ -403,7 +413,7 @@ static const struct v4l2_pix_format sxga_mode[] = {
403 .priv = 3 | MODE_RAW | MODE_SXGA}, 413 .priv = 3 | MODE_RAW | MODE_SXGA},
404}; 414};
405 415
406static const int hsv_red_x[] = { 416static const s16 hsv_red_x[] = {
407 41, 44, 46, 48, 50, 52, 54, 56, 417 41, 44, 46, 48, 50, 52, 54, 56,
408 58, 60, 62, 64, 66, 68, 70, 72, 418 58, 60, 62, 64, 66, 68, 70, 72,
409 74, 76, 78, 80, 81, 83, 85, 87, 419 74, 76, 78, 80, 81, 83, 85, 87,
@@ -451,7 +461,7 @@ static const int hsv_red_x[] = {
451 24, 26, 28, 30, 33, 35, 37, 39, 41 461 24, 26, 28, 30, 33, 35, 37, 39, 41
452}; 462};
453 463
454static const int hsv_red_y[] = { 464static const s16 hsv_red_y[] = {
455 82, 80, 78, 76, 74, 73, 71, 69, 465 82, 80, 78, 76, 74, 73, 71, 69,
456 67, 65, 63, 61, 58, 56, 54, 52, 466 67, 65, 63, 61, 58, 56, 54, 52,
457 50, 48, 46, 44, 41, 39, 37, 35, 467 50, 48, 46, 44, 41, 39, 37, 35,
@@ -499,7 +509,7 @@ static const int hsv_red_y[] = {
499 96, 94, 92, 91, 89, 87, 85, 84, 82 509 96, 94, 92, 91, 89, 87, 85, 84, 82
500}; 510};
501 511
502static const int hsv_green_x[] = { 512static const s16 hsv_green_x[] = {
503 -124, -124, -125, -125, -125, -125, -125, -125, 513 -124, -124, -125, -125, -125, -125, -125, -125,
504 -125, -126, -126, -125, -125, -125, -125, -125, 514 -125, -126, -126, -125, -125, -125, -125, -125,
505 -125, -124, -124, -124, -123, -123, -122, -122, 515 -125, -124, -124, -124, -123, -123, -122, -122,
@@ -547,7 +557,7 @@ static const int hsv_green_x[] = {
547 -120, -120, -121, -122, -122, -123, -123, -124, -124 557 -120, -120, -121, -122, -122, -123, -123, -124, -124
548}; 558};
549 559
550static const int hsv_green_y[] = { 560static const s16 hsv_green_y[] = {
551 -100, -99, -98, -97, -95, -94, -93, -91, 561 -100, -99, -98, -97, -95, -94, -93, -91,
552 -90, -89, -87, -86, -84, -83, -81, -80, 562 -90, -89, -87, -86, -84, -83, -81, -80,
553 -78, -76, -75, -73, -71, -70, -68, -66, 563 -78, -76, -75, -73, -71, -70, -68, -66,
@@ -595,7 +605,7 @@ static const int hsv_green_y[] = {
595 -109, -108, -107, -106, -105, -104, -103, -102, -100 605 -109, -108, -107, -106, -105, -104, -103, -102, -100
596}; 606};
597 607
598static const int hsv_blue_x[] = { 608static const s16 hsv_blue_x[] = {
599 112, 113, 114, 114, 115, 116, 117, 117, 609 112, 113, 114, 114, 115, 116, 117, 117,
600 118, 118, 119, 119, 120, 120, 120, 121, 610 118, 118, 119, 119, 120, 120, 120, 121,
601 121, 121, 122, 122, 122, 122, 122, 122, 611 121, 121, 122, 122, 122, 122, 122, 122,
@@ -643,7 +653,7 @@ static const int hsv_blue_x[] = {
643 104, 105, 106, 107, 108, 109, 110, 111, 112 653 104, 105, 106, 107, 108, 109, 110, 111, 112
644}; 654};
645 655
646static const int hsv_blue_y[] = { 656static const s16 hsv_blue_y[] = {
647 -11, -13, -15, -17, -19, -21, -23, -25, 657 -11, -13, -15, -17, -19, -21, -23, -25,
648 -27, -29, -31, -33, -35, -37, -39, -41, 658 -27, -29, -31, -33, -35, -37, -39, -41,
649 -43, -45, -46, -48, -50, -52, -54, -55, 659 -43, -45, -46, -48, -50, -52, -54, -55,
@@ -792,21 +802,21 @@ static u8 hv7131r_gain[] = {
792 0x78 /* 8x */ 802 0x78 /* 8x */
793}; 803};
794 804
795static u8 soi968_init[][2] = { 805static struct i2c_reg_u8 soi968_init[] = {
796 {0x12, 0x80}, {0x0c, 0x00}, {0x0f, 0x1f}, 806 {0x12, 0x80}, {0x0c, 0x00}, {0x0f, 0x1f},
797 {0x11, 0x80}, {0x38, 0x52}, {0x1e, 0x00}, 807 {0x11, 0x80}, {0x38, 0x52}, {0x1e, 0x00},
798 {0x33, 0x08}, {0x35, 0x8c}, {0x36, 0x0c}, 808 {0x33, 0x08}, {0x35, 0x8c}, {0x36, 0x0c},
799 {0x37, 0x04}, {0x45, 0x04}, {0x47, 0xff}, 809 {0x37, 0x04}, {0x45, 0x04}, {0x47, 0xff},
800 {0x3e, 0x00}, {0x3f, 0x00}, {0x3b, 0x20}, 810 {0x3e, 0x00}, {0x3f, 0x00}, {0x3b, 0x20},
801 {0x3a, 0x96}, {0x3d, 0x0a}, {0x14, 0x8e}, 811 {0x3a, 0x96}, {0x3d, 0x0a}, {0x14, 0x8e},
802 {0x13, 0x8a}, {0x12, 0x40}, {0x17, 0x13}, 812 {0x13, 0x8b}, {0x12, 0x40}, {0x17, 0x13},
803 {0x18, 0x63}, {0x19, 0x01}, {0x1a, 0x79}, 813 {0x18, 0x63}, {0x19, 0x01}, {0x1a, 0x79},
804 {0x32, 0x24}, {0x03, 0x00}, {0x11, 0x40}, 814 {0x32, 0x24}, {0x03, 0x00}, {0x11, 0x40},
805 {0x2a, 0x10}, {0x2b, 0xe0}, {0x10, 0x32}, 815 {0x2a, 0x10}, {0x2b, 0xe0}, {0x10, 0x32},
806 {0x00, 0x00}, {0x01, 0x80}, {0x02, 0x80}, 816 {0x00, 0x00}, {0x01, 0x80}, {0x02, 0x80},
807}; 817};
808 818
809static u8 ov7660_init[][2] = { 819static struct i2c_reg_u8 ov7660_init[] = {
810 {0x0e, 0x80}, {0x0d, 0x08}, {0x0f, 0xc3}, 820 {0x0e, 0x80}, {0x0d, 0x08}, {0x0f, 0xc3},
811 {0x04, 0xc3}, {0x10, 0x40}, {0x11, 0x40}, 821 {0x04, 0xc3}, {0x10, 0x40}, {0x11, 0x40},
812 {0x12, 0x05}, {0x13, 0xba}, {0x14, 0x2a}, 822 {0x12, 0x05}, {0x13, 0xba}, {0x14, 0x2a},
@@ -815,7 +825,7 @@ static u8 ov7660_init[][2] = {
815 {0x2e, 0x0b}, {0x01, 0x78}, {0x02, 0x50}, 825 {0x2e, 0x0b}, {0x01, 0x78}, {0x02, 0x50},
816}; 826};
817 827
818static u8 ov7670_init[][2] = { 828static struct i2c_reg_u8 ov7670_init[] = {
819 {0x12, 0x80}, {0x11, 0x80}, {0x3a, 0x04}, {0x12, 0x01}, 829 {0x12, 0x80}, {0x11, 0x80}, {0x3a, 0x04}, {0x12, 0x01},
820 {0x32, 0xb6}, {0x03, 0x0a}, {0x0c, 0x00}, {0x3e, 0x00}, 830 {0x32, 0xb6}, {0x03, 0x0a}, {0x0c, 0x00}, {0x3e, 0x00},
821 {0x70, 0x3a}, {0x71, 0x35}, {0x72, 0x11}, {0x73, 0xf0}, 831 {0x70, 0x3a}, {0x71, 0x35}, {0x72, 0x11}, {0x73, 0xf0},
@@ -872,7 +882,7 @@ static u8 ov7670_init[][2] = {
872 {0x93, 0x00}, 882 {0x93, 0x00},
873}; 883};
874 884
875static u8 ov9650_init[][2] = { 885static struct i2c_reg_u8 ov9650_init[] = {
876 {0x12, 0x80}, {0x00, 0x00}, {0x01, 0x78}, 886 {0x12, 0x80}, {0x00, 0x00}, {0x01, 0x78},
877 {0x02, 0x78}, {0x03, 0x36}, {0x04, 0x03}, 887 {0x02, 0x78}, {0x03, 0x36}, {0x04, 0x03},
878 {0x05, 0x00}, {0x06, 0x00}, {0x08, 0x00}, 888 {0x05, 0x00}, {0x06, 0x00}, {0x08, 0x00},
@@ -902,7 +912,7 @@ static u8 ov9650_init[][2] = {
902 {0xaa, 0x92}, {0xab, 0x0a}, 912 {0xaa, 0x92}, {0xab, 0x0a},
903}; 913};
904 914
905static u8 ov9655_init[][2] = { 915static struct i2c_reg_u8 ov9655_init[] = {
906 {0x12, 0x80}, {0x12, 0x01}, {0x0d, 0x00}, {0x0e, 0x61}, 916 {0x12, 0x80}, {0x12, 0x01}, {0x0d, 0x00}, {0x0e, 0x61},
907 {0x11, 0x80}, {0x13, 0xba}, {0x14, 0x2e}, {0x16, 0x24}, 917 {0x11, 0x80}, {0x13, 0xba}, {0x14, 0x2e}, {0x16, 0x24},
908 {0x1e, 0x04}, {0x1e, 0x04}, {0x1e, 0x04}, {0x27, 0x08}, 918 {0x1e, 0x04}, {0x1e, 0x04}, {0x1e, 0x04}, {0x27, 0x08},
@@ -939,7 +949,7 @@ static u8 ov9655_init[][2] = {
939 {0x00, 0x03}, {0x00, 0x0a}, {0x00, 0x10}, {0x00, 0x13}, 949 {0x00, 0x03}, {0x00, 0x0a}, {0x00, 0x10}, {0x00, 0x13},
940}; 950};
941 951
942static u16 mt9v112_init[][2] = { 952static struct i2c_reg_u16 mt9v112_init[] = {
943 {0xf0, 0x0000}, {0x0d, 0x0021}, {0x0d, 0x0020}, 953 {0xf0, 0x0000}, {0x0d, 0x0021}, {0x0d, 0x0020},
944 {0x34, 0xc019}, {0x0a, 0x0011}, {0x0b, 0x000b}, 954 {0x34, 0xc019}, {0x0a, 0x0011}, {0x0b, 0x000b},
945 {0x20, 0x0703}, {0x35, 0x2022}, {0xf0, 0x0001}, 955 {0x20, 0x0703}, {0x35, 0x2022}, {0xf0, 0x0001},
@@ -958,7 +968,7 @@ static u16 mt9v112_init[][2] = {
958 {0x2c, 0x00ae}, {0x2d, 0x00ae}, {0x2e, 0x00ae}, 968 {0x2c, 0x00ae}, {0x2d, 0x00ae}, {0x2e, 0x00ae},
959}; 969};
960 970
961static u16 mt9v111_init[][2] = { 971static struct i2c_reg_u16 mt9v111_init[] = {
962 {0x01, 0x0004}, {0x0d, 0x0001}, {0x0d, 0x0000}, 972 {0x01, 0x0004}, {0x0d, 0x0001}, {0x0d, 0x0000},
963 {0x01, 0x0001}, {0x02, 0x0016}, {0x03, 0x01e1}, 973 {0x01, 0x0001}, {0x02, 0x0016}, {0x03, 0x01e1},
964 {0x04, 0x0281}, {0x05, 0x0004}, {0x07, 0x3002}, 974 {0x04, 0x0281}, {0x05, 0x0004}, {0x07, 0x3002},
@@ -985,7 +995,7 @@ static u16 mt9v111_init[][2] = {
985 {0x0e, 0x0008}, {0x06, 0x002d}, {0x05, 0x0004}, 995 {0x0e, 0x0008}, {0x06, 0x002d}, {0x05, 0x0004},
986}; 996};
987 997
988static u16 mt9v011_init[][2] = { 998static struct i2c_reg_u16 mt9v011_init[] = {
989 {0x07, 0x0002}, {0x0d, 0x0001}, {0x0d, 0x0000}, 999 {0x07, 0x0002}, {0x0d, 0x0001}, {0x0d, 0x0000},
990 {0x01, 0x0008}, {0x02, 0x0016}, {0x03, 0x01e1}, 1000 {0x01, 0x0008}, {0x02, 0x0016}, {0x03, 0x01e1},
991 {0x04, 0x0281}, {0x05, 0x0083}, {0x06, 0x0006}, 1001 {0x04, 0x0281}, {0x05, 0x0083}, {0x06, 0x0006},
@@ -1012,7 +1022,7 @@ static u16 mt9v011_init[][2] = {
1012 {0x06, 0x0029}, {0x05, 0x0009}, 1022 {0x06, 0x0029}, {0x05, 0x0009},
1013}; 1023};
1014 1024
1015static u16 mt9m001_init[][2] = { 1025static struct i2c_reg_u16 mt9m001_init[] = {
1016 {0x0d, 0x0001}, {0x0d, 0x0000}, {0x01, 0x000e}, 1026 {0x0d, 0x0001}, {0x0d, 0x0000}, {0x01, 0x000e},
1017 {0x02, 0x0014}, {0x03, 0x03c1}, {0x04, 0x0501}, 1027 {0x02, 0x0014}, {0x03, 0x03c1}, {0x04, 0x0501},
1018 {0x05, 0x0083}, {0x06, 0x0006}, {0x0d, 0x0002}, 1028 {0x05, 0x0083}, {0x06, 0x0006}, {0x0d, 0x0002},
@@ -1025,14 +1035,14 @@ static u16 mt9m001_init[][2] = {
1025 {0x2e, 0x0029}, {0x07, 0x0002}, 1035 {0x2e, 0x0029}, {0x07, 0x0002},
1026}; 1036};
1027 1037
1028static u16 mt9m111_init[][2] = { 1038static struct i2c_reg_u16 mt9m111_init[] = {
1029 {0xf0, 0x0000}, {0x0d, 0x0008}, {0x0d, 0x0009}, 1039 {0xf0, 0x0000}, {0x0d, 0x0021}, {0x0d, 0x0008},
1030 {0x0d, 0x0008}, {0xf0, 0x0001}, {0x3a, 0x4300}, 1040 {0xf0, 0x0001}, {0x3a, 0x4300}, {0x9b, 0x4300},
1031 {0x9b, 0x4300}, {0xa1, 0x0280}, {0xa4, 0x0200}, 1041 {0x06, 0x708e}, {0xf0, 0x0002}, {0x2e, 0x0a1e},
1032 {0x06, 0x308e}, {0xf0, 0x0000}, 1042 {0xf0, 0x0000},
1033}; 1043};
1034 1044
1035static u8 hv7131r_init[][2] = { 1045static struct i2c_reg_u8 hv7131r_init[] = {
1036 {0x02, 0x08}, {0x02, 0x00}, {0x01, 0x08}, 1046 {0x02, 0x08}, {0x02, 0x00}, {0x01, 0x08},
1037 {0x02, 0x00}, {0x20, 0x00}, {0x21, 0xd0}, 1047 {0x02, 0x00}, {0x20, 0x00}, {0x21, 0xd0},
1038 {0x22, 0x00}, {0x23, 0x09}, {0x01, 0x08}, 1048 {0x22, 0x00}, {0x23, 0x09}, {0x01, 0x08},
@@ -1043,7 +1053,7 @@ static u8 hv7131r_init[][2] = {
1043 {0x23, 0x09}, {0x01, 0x08}, 1053 {0x23, 0x09}, {0x01, 0x08},
1044}; 1054};
1045 1055
1046int reg_r(struct gspca_dev *gspca_dev, u16 reg, u16 length) 1056static int reg_r(struct gspca_dev *gspca_dev, u16 reg, u16 length)
1047{ 1057{
1048 struct usb_device *dev = gspca_dev->dev; 1058 struct usb_device *dev = gspca_dev->dev;
1049 int result; 1059 int result;
@@ -1062,7 +1072,8 @@ int reg_r(struct gspca_dev *gspca_dev, u16 reg, u16 length)
1062 return 0; 1072 return 0;
1063} 1073}
1064 1074
1065int reg_w(struct gspca_dev *gspca_dev, u16 reg, const u8 *buffer, int length) 1075static int reg_w(struct gspca_dev *gspca_dev, u16 reg,
1076 const u8 *buffer, int length)
1066{ 1077{
1067 struct usb_device *dev = gspca_dev->dev; 1078 struct usb_device *dev = gspca_dev->dev;
1068 int result; 1079 int result;
@@ -1082,13 +1093,13 @@ int reg_w(struct gspca_dev *gspca_dev, u16 reg, const u8 *buffer, int length)
1082 return 0; 1093 return 0;
1083} 1094}
1084 1095
1085int reg_w1(struct gspca_dev *gspca_dev, u16 reg, const u8 value) 1096static int reg_w1(struct gspca_dev *gspca_dev, u16 reg, const u8 value)
1086{ 1097{
1087 u8 data[1] = {value}; 1098 u8 data[1] = {value};
1088 return reg_w(gspca_dev, reg, data, 1); 1099 return reg_w(gspca_dev, reg, data, 1);
1089} 1100}
1090 1101
1091int i2c_w(struct gspca_dev *gspca_dev, const u8 *buffer) 1102static int i2c_w(struct gspca_dev *gspca_dev, const u8 *buffer)
1092{ 1103{
1093 int i; 1104 int i;
1094 reg_w(gspca_dev, 0x10c0, buffer, 8); 1105 reg_w(gspca_dev, 0x10c0, buffer, 8);
@@ -1096,15 +1107,15 @@ int i2c_w(struct gspca_dev *gspca_dev, const u8 *buffer)
1096 reg_r(gspca_dev, 0x10c0, 1); 1107 reg_r(gspca_dev, 0x10c0, 1);
1097 if (gspca_dev->usb_buf[0] & 0x04) { 1108 if (gspca_dev->usb_buf[0] & 0x04) {
1098 if (gspca_dev->usb_buf[0] & 0x08) 1109 if (gspca_dev->usb_buf[0] & 0x08)
1099 return -1; 1110 return -EIO;
1100 return 0; 1111 return 0;
1101 } 1112 }
1102 msleep(1); 1113 msleep(1);
1103 } 1114 }
1104 return -1; 1115 return -EIO;
1105} 1116}
1106 1117
1107int i2c_w1(struct gspca_dev *gspca_dev, u8 reg, u8 val) 1118static int i2c_w1(struct gspca_dev *gspca_dev, u8 reg, u8 val)
1108{ 1119{
1109 struct sd *sd = (struct sd *) gspca_dev; 1120 struct sd *sd = (struct sd *) gspca_dev;
1110 1121
@@ -1126,7 +1137,7 @@ int i2c_w1(struct gspca_dev *gspca_dev, u8 reg, u8 val)
1126 return i2c_w(gspca_dev, row); 1137 return i2c_w(gspca_dev, row);
1127} 1138}
1128 1139
1129int i2c_w2(struct gspca_dev *gspca_dev, u8 reg, u16 val) 1140static int i2c_w2(struct gspca_dev *gspca_dev, u8 reg, u16 val)
1130{ 1141{
1131 struct sd *sd = (struct sd *) gspca_dev; 1142 struct sd *sd = (struct sd *) gspca_dev;
1132 u8 row[8]; 1143 u8 row[8];
@@ -1152,7 +1163,7 @@ int i2c_r1(struct gspca_dev *gspca_dev, u8 reg, u8 *val)
1152 struct sd *sd = (struct sd *) gspca_dev; 1163 struct sd *sd = (struct sd *) gspca_dev;
1153 u8 row[8]; 1164 u8 row[8];
1154 1165
1155 row[0] = 0x81 | 0x10; 1166 row[0] = 0x81 | (1 << 4);
1156 row[1] = sd->i2c_addr; 1167 row[1] = sd->i2c_addr;
1157 row[2] = reg; 1168 row[2] = reg;
1158 row[3] = 0; 1169 row[3] = 0;
@@ -1160,14 +1171,15 @@ int i2c_r1(struct gspca_dev *gspca_dev, u8 reg, u8 *val)
1160 row[5] = 0; 1171 row[5] = 0;
1161 row[6] = 0; 1172 row[6] = 0;
1162 row[7] = 0x10; 1173 row[7] = 0x10;
1163 reg_w(gspca_dev, 0x10c0, row, 8); 1174 if (i2c_w(gspca_dev, row) < 0)
1164 msleep(1); 1175 return -EIO;
1165 row[0] = 0x81 | (2 << 4) | 0x02; 1176 row[0] = 0x81 | (1 << 4) | 0x02;
1166 row[2] = 0; 1177 row[2] = 0;
1167 reg_w(gspca_dev, 0x10c0, row, 8); 1178 if (i2c_w(gspca_dev, row) < 0)
1168 msleep(1); 1179 return -EIO;
1169 reg_r(gspca_dev, 0x10c2, 5); 1180 if (reg_r(gspca_dev, 0x10c2, 5) < 0)
1170 *val = gspca_dev->usb_buf[3]; 1181 return -EIO;
1182 *val = gspca_dev->usb_buf[4];
1171 return 0; 1183 return 0;
1172} 1184}
1173 1185
@@ -1176,7 +1188,7 @@ int i2c_r2(struct gspca_dev *gspca_dev, u8 reg, u16 *val)
1176 struct sd *sd = (struct sd *) gspca_dev; 1188 struct sd *sd = (struct sd *) gspca_dev;
1177 u8 row[8]; 1189 u8 row[8];
1178 1190
1179 row[0] = 0x81 | 0x10; 1191 row[0] = 0x81 | (1 << 4);
1180 row[1] = sd->i2c_addr; 1192 row[1] = sd->i2c_addr;
1181 row[2] = reg; 1193 row[2] = reg;
1182 row[3] = 0; 1194 row[3] = 0;
@@ -1184,14 +1196,15 @@ int i2c_r2(struct gspca_dev *gspca_dev, u8 reg, u16 *val)
1184 row[5] = 0; 1196 row[5] = 0;
1185 row[6] = 0; 1197 row[6] = 0;
1186 row[7] = 0x10; 1198 row[7] = 0x10;
1187 reg_w(gspca_dev, 0x10c0, row, 8); 1199 if (i2c_w(gspca_dev, row) < 0)
1188 msleep(1); 1200 return -EIO;
1189 row[0] = 0x81 | (3 << 4) | 0x02; 1201 row[0] = 0x81 | (2 << 4) | 0x02;
1190 row[2] = 0; 1202 row[2] = 0;
1191 reg_w(gspca_dev, 0x10c0, row, 8); 1203 if (i2c_w(gspca_dev, row) < 0)
1192 msleep(1); 1204 return -EIO;
1193 reg_r(gspca_dev, 0x10c2, 5); 1205 if (reg_r(gspca_dev, 0x10c2, 5) < 0)
1194 *val = (gspca_dev->usb_buf[2] << 8) | gspca_dev->usb_buf[3]; 1206 return -EIO;
1207 *val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
1195 return 0; 1208 return 0;
1196} 1209}
1197 1210
@@ -1201,8 +1214,8 @@ static int ov9650_init_sensor(struct gspca_dev *gspca_dev)
1201 struct sd *sd = (struct sd *) gspca_dev; 1214 struct sd *sd = (struct sd *) gspca_dev;
1202 1215
1203 for (i = 0; i < ARRAY_SIZE(ov9650_init); i++) { 1216 for (i = 0; i < ARRAY_SIZE(ov9650_init); i++) {
1204 if (i2c_w1(gspca_dev, ov9650_init[i][0], 1217 if (i2c_w1(gspca_dev, ov9650_init[i].reg,
1205 ov9650_init[i][1]) < 0) { 1218 ov9650_init[i].val) < 0) {
1206 err("OV9650 sensor initialization failed"); 1219 err("OV9650 sensor initialization failed");
1207 return -ENODEV; 1220 return -ENODEV;
1208 } 1221 }
@@ -1218,8 +1231,8 @@ static int ov9655_init_sensor(struct gspca_dev *gspca_dev)
1218 struct sd *sd = (struct sd *) gspca_dev; 1231 struct sd *sd = (struct sd *) gspca_dev;
1219 1232
1220 for (i = 0; i < ARRAY_SIZE(ov9655_init); i++) { 1233 for (i = 0; i < ARRAY_SIZE(ov9655_init); i++) {
1221 if (i2c_w1(gspca_dev, ov9655_init[i][0], 1234 if (i2c_w1(gspca_dev, ov9655_init[i].reg,
1222 ov9655_init[i][1]) < 0) { 1235 ov9655_init[i].val) < 0) {
1223 err("OV9655 sensor initialization failed"); 1236 err("OV9655 sensor initialization failed");
1224 return -ENODEV; 1237 return -ENODEV;
1225 } 1238 }
@@ -1237,14 +1250,14 @@ static int soi968_init_sensor(struct gspca_dev *gspca_dev)
1237 struct sd *sd = (struct sd *) gspca_dev; 1250 struct sd *sd = (struct sd *) gspca_dev;
1238 1251
1239 for (i = 0; i < ARRAY_SIZE(soi968_init); i++) { 1252 for (i = 0; i < ARRAY_SIZE(soi968_init); i++) {
1240 if (i2c_w1(gspca_dev, soi968_init[i][0], 1253 if (i2c_w1(gspca_dev, soi968_init[i].reg,
1241 soi968_init[i][1]) < 0) { 1254 soi968_init[i].val) < 0) {
1242 err("SOI968 sensor initialization failed"); 1255 err("SOI968 sensor initialization failed");
1243 return -ENODEV; 1256 return -ENODEV;
1244 } 1257 }
1245 } 1258 }
1246 /* disable hflip and vflip */ 1259 /* disable hflip and vflip */
1247 gspca_dev->ctrl_dis = (1 << HFLIP_IDX) | (1 << VFLIP_IDX); 1260 gspca_dev->ctrl_dis = (1 << HFLIP_IDX) | (1 << VFLIP_IDX) | (1 << EXPOSURE_IDX);
1248 sd->hstart = 60; 1261 sd->hstart = 60;
1249 sd->vstart = 11; 1262 sd->vstart = 11;
1250 return 0; 1263 return 0;
@@ -1256,8 +1269,8 @@ static int ov7660_init_sensor(struct gspca_dev *gspca_dev)
1256 struct sd *sd = (struct sd *) gspca_dev; 1269 struct sd *sd = (struct sd *) gspca_dev;
1257 1270
1258 for (i = 0; i < ARRAY_SIZE(ov7660_init); i++) { 1271 for (i = 0; i < ARRAY_SIZE(ov7660_init); i++) {
1259 if (i2c_w1(gspca_dev, ov7660_init[i][0], 1272 if (i2c_w1(gspca_dev, ov7660_init[i].reg,
1260 ov7660_init[i][1]) < 0) { 1273 ov7660_init[i].val) < 0) {
1261 err("OV7660 sensor initialization failed"); 1274 err("OV7660 sensor initialization failed");
1262 return -ENODEV; 1275 return -ENODEV;
1263 } 1276 }
@@ -1275,8 +1288,8 @@ static int ov7670_init_sensor(struct gspca_dev *gspca_dev)
1275 struct sd *sd = (struct sd *) gspca_dev; 1288 struct sd *sd = (struct sd *) gspca_dev;
1276 1289
1277 for (i = 0; i < ARRAY_SIZE(ov7670_init); i++) { 1290 for (i = 0; i < ARRAY_SIZE(ov7670_init); i++) {
1278 if (i2c_w1(gspca_dev, ov7670_init[i][0], 1291 if (i2c_w1(gspca_dev, ov7670_init[i].reg,
1279 ov7670_init[i][1]) < 0) { 1292 ov7670_init[i].val) < 0) {
1280 err("OV7670 sensor initialization failed"); 1293 err("OV7670 sensor initialization failed");
1281 return -ENODEV; 1294 return -ENODEV;
1282 } 1295 }
@@ -1299,8 +1312,8 @@ static int mt9v_init_sensor(struct gspca_dev *gspca_dev)
1299 ret = i2c_r2(gspca_dev, 0xff, &value); 1312 ret = i2c_r2(gspca_dev, 0xff, &value);
1300 if ((ret == 0) && (value == 0x8243)) { 1313 if ((ret == 0) && (value == 0x8243)) {
1301 for (i = 0; i < ARRAY_SIZE(mt9v011_init); i++) { 1314 for (i = 0; i < ARRAY_SIZE(mt9v011_init); i++) {
1302 if (i2c_w2(gspca_dev, mt9v011_init[i][0], 1315 if (i2c_w2(gspca_dev, mt9v011_init[i].reg,
1303 mt9v011_init[i][1]) < 0) { 1316 mt9v011_init[i].val) < 0) {
1304 err("MT9V011 sensor initialization failed"); 1317 err("MT9V011 sensor initialization failed");
1305 return -ENODEV; 1318 return -ENODEV;
1306 } 1319 }
@@ -1317,8 +1330,8 @@ static int mt9v_init_sensor(struct gspca_dev *gspca_dev)
1317 ret = i2c_r2(gspca_dev, 0xff, &value); 1330 ret = i2c_r2(gspca_dev, 0xff, &value);
1318 if ((ret == 0) && (value == 0x823a)) { 1331 if ((ret == 0) && (value == 0x823a)) {
1319 for (i = 0; i < ARRAY_SIZE(mt9v111_init); i++) { 1332 for (i = 0; i < ARRAY_SIZE(mt9v111_init); i++) {
1320 if (i2c_w2(gspca_dev, mt9v111_init[i][0], 1333 if (i2c_w2(gspca_dev, mt9v111_init[i].reg,
1321 mt9v111_init[i][1]) < 0) { 1334 mt9v111_init[i].val) < 0) {
1322 err("MT9V111 sensor initialization failed"); 1335 err("MT9V111 sensor initialization failed");
1323 return -ENODEV; 1336 return -ENODEV;
1324 } 1337 }
@@ -1339,8 +1352,8 @@ static int mt9v_init_sensor(struct gspca_dev *gspca_dev)
1339 ret = i2c_r2(gspca_dev, 0x00, &value); 1352 ret = i2c_r2(gspca_dev, 0x00, &value);
1340 if ((ret == 0) && (value == 0x1229)) { 1353 if ((ret == 0) && (value == 0x1229)) {
1341 for (i = 0; i < ARRAY_SIZE(mt9v112_init); i++) { 1354 for (i = 0; i < ARRAY_SIZE(mt9v112_init); i++) {
1342 if (i2c_w2(gspca_dev, mt9v112_init[i][0], 1355 if (i2c_w2(gspca_dev, mt9v112_init[i].reg,
1343 mt9v112_init[i][1]) < 0) { 1356 mt9v112_init[i].val) < 0) {
1344 err("MT9V112 sensor initialization failed"); 1357 err("MT9V112 sensor initialization failed");
1345 return -ENODEV; 1358 return -ENODEV;
1346 } 1359 }
@@ -1360,12 +1373,13 @@ static int mt9m111_init_sensor(struct gspca_dev *gspca_dev)
1360 struct sd *sd = (struct sd *) gspca_dev; 1373 struct sd *sd = (struct sd *) gspca_dev;
1361 int i; 1374 int i;
1362 for (i = 0; i < ARRAY_SIZE(mt9m111_init); i++) { 1375 for (i = 0; i < ARRAY_SIZE(mt9m111_init); i++) {
1363 if (i2c_w2(gspca_dev, mt9m111_init[i][0], 1376 if (i2c_w2(gspca_dev, mt9m111_init[i].reg,
1364 mt9m111_init[i][1]) < 0) { 1377 mt9m111_init[i].val) < 0) {
1365 err("MT9M111 sensor initialization failed"); 1378 err("MT9M111 sensor initialization failed");
1366 return -ENODEV; 1379 return -ENODEV;
1367 } 1380 }
1368 } 1381 }
1382 gspca_dev->ctrl_dis = (1 << EXPOSURE_IDX) | (1 << AUTOGAIN_IDX) | (1 << GAIN_IDX);
1369 sd->hstart = 0; 1383 sd->hstart = 0;
1370 sd->vstart = 2; 1384 sd->vstart = 2;
1371 return 0; 1385 return 0;
@@ -1376,8 +1390,8 @@ static int mt9m001_init_sensor(struct gspca_dev *gspca_dev)
1376 struct sd *sd = (struct sd *) gspca_dev; 1390 struct sd *sd = (struct sd *) gspca_dev;
1377 int i; 1391 int i;
1378 for (i = 0; i < ARRAY_SIZE(mt9m001_init); i++) { 1392 for (i = 0; i < ARRAY_SIZE(mt9m001_init); i++) {
1379 if (i2c_w2(gspca_dev, mt9m001_init[i][0], 1393 if (i2c_w2(gspca_dev, mt9m001_init[i].reg,
1380 mt9m001_init[i][1]) < 0) { 1394 mt9m001_init[i].val) < 0) {
1381 err("MT9M001 sensor initialization failed"); 1395 err("MT9M001 sensor initialization failed");
1382 return -ENODEV; 1396 return -ENODEV;
1383 } 1397 }
@@ -1395,8 +1409,8 @@ static int hv7131r_init_sensor(struct gspca_dev *gspca_dev)
1395 struct sd *sd = (struct sd *) gspca_dev; 1409 struct sd *sd = (struct sd *) gspca_dev;
1396 1410
1397 for (i = 0; i < ARRAY_SIZE(hv7131r_init); i++) { 1411 for (i = 0; i < ARRAY_SIZE(hv7131r_init); i++) {
1398 if (i2c_w1(gspca_dev, hv7131r_init[i][0], 1412 if (i2c_w1(gspca_dev, hv7131r_init[i].reg,
1399 hv7131r_init[i][1]) < 0) { 1413 hv7131r_init[i].val) < 0) {
1400 err("HV7131R Sensor initialization failed"); 1414 err("HV7131R Sensor initialization failed");
1401 return -ENODEV; 1415 return -ENODEV;
1402 } 1416 }
@@ -1620,7 +1634,6 @@ static int set_exposure(struct gspca_dev *gspca_dev)
1620 switch (sd->sensor) { 1634 switch (sd->sensor) {
1621 case SENSOR_OV7660: 1635 case SENSOR_OV7660:
1622 case SENSOR_OV7670: 1636 case SENSOR_OV7670:
1623 case SENSOR_SOI968:
1624 case SENSOR_OV9655: 1637 case SENSOR_OV9655:
1625 case SENSOR_OV9650: 1638 case SENSOR_OV9650:
1626 exp[0] |= (3 << 4); 1639 exp[0] |= (3 << 4);
@@ -1629,7 +1642,6 @@ static int set_exposure(struct gspca_dev *gspca_dev)
1629 exp[4] = sd->exposure >> 8; 1642 exp[4] = sd->exposure >> 8;
1630 break; 1643 break;
1631 case SENSOR_MT9M001: 1644 case SENSOR_MT9M001:
1632 case SENSOR_MT9M111:
1633 case SENSOR_MT9V112: 1645 case SENSOR_MT9V112:
1634 case SENSOR_MT9V111: 1646 case SENSOR_MT9V111:
1635 case SENSOR_MT9V011: 1647 case SENSOR_MT9V011:
@@ -1645,6 +1657,8 @@ static int set_exposure(struct gspca_dev *gspca_dev)
1645 exp[4] = ((sd->exposure * 0xffffff) / 0xffff) >> 8; 1657 exp[4] = ((sd->exposure * 0xffffff) / 0xffff) >> 8;
1646 exp[5] = ((sd->exposure * 0xffffff) / 0xffff) & 0xff; 1658 exp[5] = ((sd->exposure * 0xffffff) / 0xffff) & 0xff;
1647 break; 1659 break;
1660 default:
1661 return 0;
1648 } 1662 }
1649 i2c_w(gspca_dev, exp); 1663 i2c_w(gspca_dev, exp);
1650 return 0; 1664 return 0;
@@ -1671,7 +1685,6 @@ static int set_gain(struct gspca_dev *gspca_dev)
1671 gain[4] = micron1_gain[sd->gain] & 0xff; 1685 gain[4] = micron1_gain[sd->gain] & 0xff;
1672 break; 1686 break;
1673 case SENSOR_MT9V112: 1687 case SENSOR_MT9V112:
1674 case SENSOR_MT9M111:
1675 gain[0] |= (3 << 4); 1688 gain[0] |= (3 << 4);
1676 gain[2] = 0x2f; 1689 gain[2] = 0x2f;
1677 gain[3] = micron1_gain[sd->gain] >> 8; 1690 gain[3] = micron1_gain[sd->gain] >> 8;
@@ -1688,6 +1701,8 @@ static int set_gain(struct gspca_dev *gspca_dev)
1688 gain[2] = 0x30; 1701 gain[2] = 0x30;
1689 gain[3] = hv7131r_gain[sd->gain]; 1702 gain[3] = hv7131r_gain[sd->gain];
1690 break; 1703 break;
1704 default:
1705 return 0;
1691 } 1706 }
1692 i2c_w(gspca_dev, gain); 1707 i2c_w(gspca_dev, gain);
1693 return 0; 1708 return 0;
@@ -1990,7 +2005,9 @@ static int sd_config(struct gspca_dev *gspca_dev,
1990 sd->i2c_addr = id->driver_info & 0xff; 2005 sd->i2c_addr = id->driver_info & 0xff;
1991 2006
1992 switch (sd->sensor) { 2007 switch (sd->sensor) {
2008 case SENSOR_MT9M111:
1993 case SENSOR_OV9650: 2009 case SENSOR_OV9650:
2010 case SENSOR_SOI968:
1994 cam->cam_mode = sxga_mode; 2011 cam->cam_mode = sxga_mode;
1995 cam->nmodes = ARRAY_SIZE(sxga_mode); 2012 cam->nmodes = ARRAY_SIZE(sxga_mode);
1996 break; 2013 break;
@@ -2106,6 +2123,25 @@ static void configure_sensor_output(struct gspca_dev *gspca_dev, int mode)
2106 struct sd *sd = (struct sd *) gspca_dev; 2123 struct sd *sd = (struct sd *) gspca_dev;
2107 u8 value; 2124 u8 value;
2108 switch (sd->sensor) { 2125 switch (sd->sensor) {
2126 case SENSOR_SOI968:
2127 if (mode & MODE_SXGA) {
2128 i2c_w1(gspca_dev, 0x17, 0x1d);
2129 i2c_w1(gspca_dev, 0x18, 0xbd);
2130 i2c_w1(gspca_dev, 0x19, 0x01);
2131 i2c_w1(gspca_dev, 0x1a, 0x81);
2132 i2c_w1(gspca_dev, 0x12, 0x00);
2133 sd->hstart = 140;
2134 sd->vstart = 19;
2135 } else {
2136 i2c_w1(gspca_dev, 0x17, 0x13);
2137 i2c_w1(gspca_dev, 0x18, 0x63);
2138 i2c_w1(gspca_dev, 0x19, 0x01);
2139 i2c_w1(gspca_dev, 0x1a, 0x79);
2140 i2c_w1(gspca_dev, 0x12, 0x40);
2141 sd->hstart = 60;
2142 sd->vstart = 11;
2143 }
2144 break;
2109 case SENSOR_OV9650: 2145 case SENSOR_OV9650:
2110 if (mode & MODE_SXGA) { 2146 if (mode & MODE_SXGA) {
2111 i2c_w1(gspca_dev, 0x17, 0x1b); 2147 i2c_w1(gspca_dev, 0x17, 0x1b);
@@ -2123,6 +2159,17 @@ static void configure_sensor_output(struct gspca_dev *gspca_dev, int mode)
2123 i2c_w1(gspca_dev, 0x12, (value & 0x7) | 0x40); 2159 i2c_w1(gspca_dev, 0x12, (value & 0x7) | 0x40);
2124 } 2160 }
2125 break; 2161 break;
2162 case SENSOR_MT9M111:
2163 if (mode & MODE_SXGA) {
2164 i2c_w2(gspca_dev, 0xf0, 0x0002);
2165 i2c_w2(gspca_dev, 0xc8, 0x970b);
2166 i2c_w2(gspca_dev, 0xf0, 0x0000);
2167 } else {
2168 i2c_w2(gspca_dev, 0xf0, 0x0002);
2169 i2c_w2(gspca_dev, 0xc8, 0x8000);
2170 i2c_w2(gspca_dev, 0xf0, 0x0000);
2171 }
2172 break;
2126 } 2173 }
2127} 2174}
2128 2175
@@ -2211,15 +2258,10 @@ static void sd_stop0(struct gspca_dev *gspca_dev)
2211 kfree(sd->jpeg_hdr); 2258 kfree(sd->jpeg_hdr);
2212} 2259}
2213 2260
2214static void do_autoexposure(struct gspca_dev *gspca_dev) 2261static void do_autoexposure(struct gspca_dev *gspca_dev, u16 avg_lum)
2215{ 2262{
2216 struct sd *sd = (struct sd *) gspca_dev; 2263 struct sd *sd = (struct sd *) gspca_dev;
2217 int avg_lum, new_exp; 2264 s16 new_exp;
2218
2219 if (!sd->auto_exposure)
2220 return;
2221
2222 avg_lum = atomic_read(&sd->avg_lum);
2223 2265
2224 /* 2266 /*
2225 * some hardcoded values are present 2267 * some hardcoded values are present
@@ -2266,6 +2308,39 @@ static void do_autoexposure(struct gspca_dev *gspca_dev)
2266 } 2308 }
2267} 2309}
2268 2310
2311static void do_autogain(struct gspca_dev *gspca_dev, u16 avg_lum)
2312{
2313 struct sd *sd = (struct sd *) gspca_dev;
2314
2315 if (avg_lum < MIN_AVG_LUM) {
2316 if (sd->gain + 1 <= 28) {
2317 sd->gain++;
2318 set_gain(gspca_dev);
2319 }
2320 }
2321 if (avg_lum > MAX_AVG_LUM) {
2322 if (sd->gain - 1 >= 0) {
2323 sd->gain--;
2324 set_gain(gspca_dev);
2325 }
2326 }
2327}
2328
2329static void sd_dqcallback(struct gspca_dev *gspca_dev)
2330{
2331 struct sd *sd = (struct sd *) gspca_dev;
2332 int avg_lum;
2333
2334 if (!sd->auto_exposure)
2335 return;
2336
2337 avg_lum = atomic_read(&sd->avg_lum);
2338 if (sd->sensor == SENSOR_SOI968)
2339 do_autogain(gspca_dev, avg_lum);
2340 else
2341 do_autoexposure(gspca_dev, avg_lum);
2342}
2343
2269static void sd_pkt_scan(struct gspca_dev *gspca_dev, 2344static void sd_pkt_scan(struct gspca_dev *gspca_dev,
2270 struct gspca_frame *frame, /* target */ 2345 struct gspca_frame *frame, /* target */
2271 u8 *data, /* isoc packet */ 2346 u8 *data, /* isoc packet */
@@ -2333,7 +2408,7 @@ static const struct sd_desc sd_desc = {
2333 .stopN = sd_stopN, 2408 .stopN = sd_stopN,
2334 .stop0 = sd_stop0, 2409 .stop0 = sd_stop0,
2335 .pkt_scan = sd_pkt_scan, 2410 .pkt_scan = sd_pkt_scan,
2336 .dq_callback = do_autoexposure, 2411 .dq_callback = sd_dqcallback,
2337#ifdef CONFIG_VIDEO_ADV_DEBUG 2412#ifdef CONFIG_VIDEO_ADV_DEBUG
2338 .set_register = sd_dbg_s_register, 2413 .set_register = sd_dbg_s_register,
2339 .get_register = sd_dbg_g_register, 2414 .get_register = sd_dbg_g_register,
diff --git a/drivers/media/video/gspca/sonixj.c b/drivers/media/video/gspca/sonixj.c
index d6332ab80669..33f4d0a1f6fd 100644
--- a/drivers/media/video/gspca/sonixj.c
+++ b/drivers/media/video/gspca/sonixj.c
@@ -727,7 +727,7 @@ static const u8 ov7660_sensor_init[][8] = {
727 {0xa1, 0x21, 0x12, 0x05, 0x00, 0x00, 0x00, 0x10}, 727 {0xa1, 0x21, 0x12, 0x05, 0x00, 0x00, 0x00, 0x10},
728 /* Outformat = rawRGB */ 728 /* Outformat = rawRGB */
729 {0xa1, 0x21, 0x13, 0xb8, 0x00, 0x00, 0x00, 0x10}, /* init COM8 */ 729 {0xa1, 0x21, 0x13, 0xb8, 0x00, 0x00, 0x00, 0x10}, /* init COM8 */
730 {0xd1, 0x21, 0x00, 0x01, 0x74, 0x74, 0x00, 0x10}, 730 {0xd1, 0x21, 0x00, 0x01, 0x74, 0x92, 0x00, 0x10},
731 /* GAIN BLUE RED VREF */ 731 /* GAIN BLUE RED VREF */
732 {0xd1, 0x21, 0x04, 0x00, 0x7d, 0x62, 0x00, 0x10}, 732 {0xd1, 0x21, 0x04, 0x00, 0x7d, 0x62, 0x00, 0x10},
733 /* COM 1 BAVE GEAVE AECHH */ 733 /* COM 1 BAVE GEAVE AECHH */
@@ -783,7 +783,7 @@ static const u8 ov7660_sensor_init[][8] = {
783 {0xc1, 0x21, 0x88, 0xaf, 0xc7, 0xdf, 0x00, 0x10}, /* gamma curve */ 783 {0xc1, 0x21, 0x88, 0xaf, 0xc7, 0xdf, 0x00, 0x10}, /* gamma curve */
784 {0xc1, 0x21, 0x8b, 0x99, 0x99, 0xcf, 0x00, 0x10}, /* reserved */ 784 {0xc1, 0x21, 0x8b, 0x99, 0x99, 0xcf, 0x00, 0x10}, /* reserved */
785 {0xb1, 0x21, 0x92, 0x00, 0x00, 0x00, 0x00, 0x10}, /* DM_LNL/H */ 785 {0xb1, 0x21, 0x92, 0x00, 0x00, 0x00, 0x00, 0x10}, /* DM_LNL/H */
786 {0xb1, 0x21, 0xa1, 0x00, 0x00, 0x00, 0x00, 0x10}, 786 {0xa1, 0x21, 0xa1, 0x00, 0x00, 0x00, 0x00, 0x10},
787/****** (some exchanges in the win trace) ******/ 787/****** (some exchanges in the win trace) ******/
788 {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10}, /* MVFP */ 788 {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10}, /* MVFP */
789 /* bits[3..0]reserved */ 789 /* bits[3..0]reserved */
@@ -1145,17 +1145,12 @@ static int configure_gpio(struct gspca_dev *gspca_dev,
1145 reg_w1(gspca_dev, 0x01, 0x42); 1145 reg_w1(gspca_dev, 0x01, 0x42);
1146 break; 1146 break;
1147 case SENSOR_OV7660: 1147 case SENSOR_OV7660:
1148 reg_w1(gspca_dev, 0x01, 0x61);
1149 reg_w1(gspca_dev, 0x17, 0x20);
1150 reg_w1(gspca_dev, 0x01, 0x60);
1151 reg_w1(gspca_dev, 0x01, 0x40);
1152 break;
1153 case SENSOR_SP80708: 1148 case SENSOR_SP80708:
1154 reg_w1(gspca_dev, 0x01, 0x63); 1149 reg_w1(gspca_dev, 0x01, 0x63);
1155 reg_w1(gspca_dev, 0x17, 0x20); 1150 reg_w1(gspca_dev, 0x17, 0x20);
1156 reg_w1(gspca_dev, 0x01, 0x62); 1151 reg_w1(gspca_dev, 0x01, 0x62);
1157 reg_w1(gspca_dev, 0x01, 0x42); 1152 reg_w1(gspca_dev, 0x01, 0x42);
1158 mdelay(100); 1153 msleep(100);
1159 reg_w1(gspca_dev, 0x02, 0x62); 1154 reg_w1(gspca_dev, 0x02, 0x62);
1160 break; 1155 break;
1161/* case SENSOR_HV7131R: */ 1156/* case SENSOR_HV7131R: */
@@ -1624,6 +1619,8 @@ static void setvflip(struct sd *sd)
1624 1619
1625static void setinfrared(struct sd *sd) 1620static void setinfrared(struct sd *sd)
1626{ 1621{
1622 if (sd->gspca_dev.ctrl_dis & (1 << INFRARED_IDX))
1623 return;
1627/*fixme: different sequence for StarCam Clip and StarCam 370i */ 1624/*fixme: different sequence for StarCam Clip and StarCam 370i */
1628/* Clip */ 1625/* Clip */
1629 i2c_w1(&sd->gspca_dev, 0x02, /* gpio */ 1626 i2c_w1(&sd->gspca_dev, 0x02, /* gpio */
@@ -1637,16 +1634,19 @@ static void setfreq(struct gspca_dev *gspca_dev)
1637 if (gspca_dev->ctrl_dis & (1 << FREQ_IDX)) 1634 if (gspca_dev->ctrl_dis & (1 << FREQ_IDX))
1638 return; 1635 return;
1639 if (sd->sensor == SENSOR_OV7660) { 1636 if (sd->sensor == SENSOR_OV7660) {
1637 u8 com8;
1638
1639 com8 = 0xdf; /* auto gain/wb/expo */
1640 switch (sd->freq) { 1640 switch (sd->freq) {
1641 case 0: /* Banding filter disabled */ 1641 case 0: /* Banding filter disabled */
1642 i2c_w1(gspca_dev, 0x13, 0xdf); 1642 i2c_w1(gspca_dev, 0x13, com8 | 0x20);
1643 break; 1643 break;
1644 case 1: /* 50 hz */ 1644 case 1: /* 50 hz */
1645 i2c_w1(gspca_dev, 0x13, 0xff); 1645 i2c_w1(gspca_dev, 0x13, com8);
1646 i2c_w1(gspca_dev, 0x3b, 0x0a); 1646 i2c_w1(gspca_dev, 0x3b, 0x0a);
1647 break; 1647 break;
1648 case 2: /* 60 hz */ 1648 case 2: /* 60 hz */
1649 i2c_w1(gspca_dev, 0x13, 0xff); 1649 i2c_w1(gspca_dev, 0x13, com8);
1650 i2c_w1(gspca_dev, 0x3b, 0x02); 1650 i2c_w1(gspca_dev, 0x3b, 0x02);
1651 break; 1651 break;
1652 } 1652 }
@@ -1796,12 +1796,6 @@ static int sd_start(struct gspca_dev *gspca_dev)
1796 reg_w1(gspca_dev, 0x99, 0x60); 1796 reg_w1(gspca_dev, 0x99, 0x60);
1797 break; 1797 break;
1798 case SENSOR_OV7660: 1798 case SENSOR_OV7660:
1799 reg_w1(gspca_dev, 0x9a, 0x05);
1800 if (sd->bridge == BRIDGE_SN9C105)
1801 reg_w1(gspca_dev, 0x99, 0xff);
1802 else
1803 reg_w1(gspca_dev, 0x99, 0x5b);
1804 break;
1805 case SENSOR_SP80708: 1799 case SENSOR_SP80708:
1806 reg_w1(gspca_dev, 0x9a, 0x05); 1800 reg_w1(gspca_dev, 0x9a, 0x05);
1807 reg_w1(gspca_dev, 0x99, 0x59); 1801 reg_w1(gspca_dev, 0x99, 0x59);
@@ -2325,18 +2319,19 @@ static const __devinitdata struct usb_device_id device_table[] = {
2325 {USB_DEVICE(0x0c45, 0x607c), BSI(SN9C102P, HV7131R, 0x11)}, 2319 {USB_DEVICE(0x0c45, 0x607c), BSI(SN9C102P, HV7131R, 0x11)},
2326/* {USB_DEVICE(0x0c45, 0x607e), BSI(SN9C102P, OV7630, 0x??)}, */ 2320/* {USB_DEVICE(0x0c45, 0x607e), BSI(SN9C102P, OV7630, 0x??)}, */
2327 {USB_DEVICE(0x0c45, 0x60c0), BSI(SN9C105, MI0360, 0x5d)}, 2321 {USB_DEVICE(0x0c45, 0x60c0), BSI(SN9C105, MI0360, 0x5d)},
2328/* {USB_DEVICE(0x0c45, 0x60c8), BSI(SN9C105, OM6801, 0x??)}, */ 2322/* {USB_DEVICE(0x0c45, 0x60c8), BSI(SN9C105, OM6802, 0x??)}, */
2329/* {USB_DEVICE(0x0c45, 0x60cc), BSI(SN9C105, HV7131GP, 0x??)}, */ 2323/* {USB_DEVICE(0x0c45, 0x60cc), BSI(SN9C105, HV7131GP, 0x??)}, */
2330 {USB_DEVICE(0x0c45, 0x60ec), BSI(SN9C105, MO4000, 0x21)}, 2324 {USB_DEVICE(0x0c45, 0x60ec), BSI(SN9C105, MO4000, 0x21)},
2331/* {USB_DEVICE(0x0c45, 0x60ef), BSI(SN9C105, ICM105C, 0x??)}, */ 2325/* {USB_DEVICE(0x0c45, 0x60ef), BSI(SN9C105, ICM105C, 0x??)}, */
2332/* {USB_DEVICE(0x0c45, 0x60fa), BSI(SN9C105, OV7648, 0x??)}, */ 2326/* {USB_DEVICE(0x0c45, 0x60fa), BSI(SN9C105, OV7648, 0x??)}, */
2333 {USB_DEVICE(0x0c45, 0x60fb), BSI(SN9C105, OV7660, 0x21)}, 2327 {USB_DEVICE(0x0c45, 0x60fb), BSI(SN9C105, OV7660, 0x21)},
2334 {USB_DEVICE(0x0c45, 0x60fc), BSI(SN9C105, HV7131R, 0x11)},
2335#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE 2328#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
2329 {USB_DEVICE(0x0c45, 0x60fc), BSI(SN9C105, HV7131R, 0x11)},
2336 {USB_DEVICE(0x0c45, 0x60fe), BSI(SN9C105, OV7630, 0x21)}, 2330 {USB_DEVICE(0x0c45, 0x60fe), BSI(SN9C105, OV7630, 0x21)},
2337#endif 2331#endif
2338 {USB_DEVICE(0x0c45, 0x6100), BSI(SN9C120, MI0360, 0x5d)}, /*sn9c128*/ 2332 {USB_DEVICE(0x0c45, 0x6100), BSI(SN9C120, MI0360, 0x5d)}, /*sn9c128*/
2339/* {USB_DEVICE(0x0c45, 0x6108), BSI(SN9C120, OM6801, 0x??)}, */ 2333/* {USB_DEVICE(0x0c45, 0x6102), BSI(SN9C120, PO2030N, ??)}, */
2334/* {USB_DEVICE(0x0c45, 0x6108), BSI(SN9C120, OM6802, 0x21)}, */
2340 {USB_DEVICE(0x0c45, 0x610a), BSI(SN9C120, OV7648, 0x21)}, /*sn9c128*/ 2335 {USB_DEVICE(0x0c45, 0x610a), BSI(SN9C120, OV7648, 0x21)}, /*sn9c128*/
2341 {USB_DEVICE(0x0c45, 0x610b), BSI(SN9C120, OV7660, 0x21)}, /*sn9c128*/ 2336 {USB_DEVICE(0x0c45, 0x610b), BSI(SN9C120, OV7660, 0x21)}, /*sn9c128*/
2342 {USB_DEVICE(0x0c45, 0x610c), BSI(SN9C120, HV7131R, 0x11)}, /*sn9c128*/ 2337 {USB_DEVICE(0x0c45, 0x610c), BSI(SN9C120, HV7131R, 0x11)}, /*sn9c128*/
@@ -2352,6 +2347,7 @@ static const __devinitdata struct usb_device_id device_table[] = {
2352#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE 2347#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
2353 {USB_DEVICE(0x0c45, 0x6130), BSI(SN9C120, MI0360, 0x5d)}, 2348 {USB_DEVICE(0x0c45, 0x6130), BSI(SN9C120, MI0360, 0x5d)},
2354#endif 2349#endif
2350/* {USB_DEVICE(0x0c45, 0x6132), BSI(SN9C120, OV7670, 0x21)}, */
2355 {USB_DEVICE(0x0c45, 0x6138), BSI(SN9C120, MO4000, 0x21)}, 2351 {USB_DEVICE(0x0c45, 0x6138), BSI(SN9C120, MO4000, 0x21)},
2356 {USB_DEVICE(0x0c45, 0x613a), BSI(SN9C120, OV7648, 0x21)}, 2352 {USB_DEVICE(0x0c45, 0x613a), BSI(SN9C120, OV7648, 0x21)},
2357#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE 2353#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
@@ -2359,7 +2355,9 @@ static const __devinitdata struct usb_device_id device_table[] = {
2359#endif 2355#endif
2360 {USB_DEVICE(0x0c45, 0x613c), BSI(SN9C120, HV7131R, 0x11)}, 2356 {USB_DEVICE(0x0c45, 0x613c), BSI(SN9C120, HV7131R, 0x11)},
2361 {USB_DEVICE(0x0c45, 0x613e), BSI(SN9C120, OV7630, 0x21)}, 2357 {USB_DEVICE(0x0c45, 0x613e), BSI(SN9C120, OV7630, 0x21)},
2362 {USB_DEVICE(0x0c45, 0x6143), BSI(SN9C120, SP80708, 0x18)}, 2358/* {USB_DEVICE(0x0c45, 0x6142), BSI(SN9C120, PO2030N, ??)}, *sn9c120b*/
2359 {USB_DEVICE(0x0c45, 0x6143), BSI(SN9C120, SP80708, 0x18)}, /*sn9c120b*/
2360 {USB_DEVICE(0x0c45, 0x6148), BSI(SN9C120, OM6802, 0x21)}, /*sn9c120b*/
2363 {} 2361 {}
2364}; 2362};
2365MODULE_DEVICE_TABLE(usb, device_table); 2363MODULE_DEVICE_TABLE(usb, device_table);
diff --git a/drivers/media/video/gspca/spca501.c b/drivers/media/video/gspca/spca501.c
index d48b27c648ca..b74a34218da0 100644
--- a/drivers/media/video/gspca/spca501.c
+++ b/drivers/media/video/gspca/spca501.c
@@ -1923,7 +1923,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
1923 1923
1924 cam = &gspca_dev->cam; 1924 cam = &gspca_dev->cam;
1925 cam->cam_mode = vga_mode; 1925 cam->cam_mode = vga_mode;
1926 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0]; 1926 cam->nmodes = ARRAY_SIZE(vga_mode);
1927 sd->subtype = id->driver_info; 1927 sd->subtype = id->driver_info;
1928 sd->brightness = sd_ctrls[MY_BRIGHTNESS].qctrl.default_value; 1928 sd->brightness = sd_ctrls[MY_BRIGHTNESS].qctrl.default_value;
1929 sd->contrast = sd_ctrls[MY_CONTRAST].qctrl.default_value; 1929 sd->contrast = sd_ctrls[MY_CONTRAST].qctrl.default_value;
diff --git a/drivers/media/video/gspca/spca506.c b/drivers/media/video/gspca/spca506.c
index 3a0c893f942d..a199298a6419 100644
--- a/drivers/media/video/gspca/spca506.c
+++ b/drivers/media/video/gspca/spca506.c
@@ -286,7 +286,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
286 286
287 cam = &gspca_dev->cam; 287 cam = &gspca_dev->cam;
288 cam->cam_mode = vga_mode; 288 cam->cam_mode = vga_mode;
289 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0]; 289 cam->nmodes = ARRAY_SIZE(vga_mode);
290 sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value; 290 sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value;
291 sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value; 291 sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value;
292 sd->colors = sd_ctrls[SD_COLOR].qctrl.default_value; 292 sd->colors = sd_ctrls[SD_COLOR].qctrl.default_value;
diff --git a/drivers/media/video/gspca/spca508.c b/drivers/media/video/gspca/spca508.c
index 2ed2669bac3e..9696c4caf5c9 100644
--- a/drivers/media/video/gspca/spca508.c
+++ b/drivers/media/video/gspca/spca508.c
@@ -1304,19 +1304,70 @@ static int reg_read(struct gspca_dev *gspca_dev,
1304 return gspca_dev->usb_buf[0]; 1304 return gspca_dev->usb_buf[0];
1305} 1305}
1306 1306
1307/* send 1 or 2 bytes to the sensor via the Synchronous Serial Interface */
1308static int ssi_w(struct gspca_dev *gspca_dev,
1309 u16 reg, u16 val)
1310{
1311 struct usb_device *dev = gspca_dev->dev;
1312 int ret, retry;
1313
1314 ret = reg_write(dev, 0x8802, reg >> 8);
1315 if (ret < 0)
1316 goto out;
1317 ret = reg_write(dev, 0x8801, reg & 0x00ff);
1318 if (ret < 0)
1319 goto out;
1320 if ((reg & 0xff00) == 0x1000) { /* if 2 bytes */
1321 ret = reg_write(dev, 0x8805, val & 0x00ff);
1322 if (ret < 0)
1323 goto out;
1324 val >>= 8;
1325 }
1326 ret = reg_write(dev, 0x8800, val);
1327 if (ret < 0)
1328 goto out;
1329
1330 /* poll until not busy */
1331 retry = 10;
1332 for (;;) {
1333 ret = reg_read(gspca_dev, 0x8803);
1334 if (ret < 0)
1335 break;
1336 if (gspca_dev->usb_buf[0] == 0)
1337 break;
1338 if (--retry <= 0) {
1339 PDEBUG(D_ERR, "ssi_w busy %02x",
1340 gspca_dev->usb_buf[0]);
1341 ret = -1;
1342 break;
1343 }
1344 msleep(8);
1345 }
1346
1347out:
1348 return ret;
1349}
1350
1307static int write_vector(struct gspca_dev *gspca_dev, 1351static int write_vector(struct gspca_dev *gspca_dev,
1308 const u16 (*data)[2]) 1352 const u16 (*data)[2])
1309{ 1353{
1310 struct usb_device *dev = gspca_dev->dev; 1354 struct usb_device *dev = gspca_dev->dev;
1311 int ret; 1355 int ret = 0;
1312 1356
1313 while ((*data)[1] != 0) { 1357 while ((*data)[1] != 0) {
1314 ret = reg_write(dev, (*data)[1], (*data)[0]); 1358 if ((*data)[1] & 0x8000) {
1359 if ((*data)[1] == 0xdd00) /* delay */
1360 msleep((*data)[0]);
1361 else
1362 ret = reg_write(dev, (*data)[1], (*data)[0]);
1363 } else {
1364 ret = ssi_w(gspca_dev, (*data)[1], (*data)[0]);
1365 }
1315 if (ret < 0) 1366 if (ret < 0)
1316 return ret; 1367 break;
1317 data++; 1368 data++;
1318 } 1369 }
1319 return 0; 1370 return ret;
1320} 1371}
1321 1372
1322/* this function is called at probe time */ 1373/* this function is called at probe time */
diff --git a/drivers/media/video/gspca/stv06xx/stv06xx.c b/drivers/media/video/gspca/stv06xx/stv06xx.c
index 0da8e0de0456..7af511b5e9c2 100644
--- a/drivers/media/video/gspca/stv06xx/stv06xx.c
+++ b/drivers/media/video/gspca/stv06xx/stv06xx.c
@@ -130,8 +130,8 @@ int stv06xx_write_sensor_bytes(struct sd *sd, const u8 *data, u8 len)
130 STV06XX_URB_MSG_TIMEOUT); 130 STV06XX_URB_MSG_TIMEOUT);
131 if (err < 0) 131 if (err < 0)
132 return err; 132 return err;
133 } 133 }
134 return stv06xx_write_sensor_finish(sd); 134 return stv06xx_write_sensor_finish(sd);
135} 135}
136 136
137int stv06xx_write_sensor_words(struct sd *sd, const u16 *data, u8 len) 137int stv06xx_write_sensor_words(struct sd *sd, const u16 *data, u8 len)
diff --git a/drivers/media/video/gspca/sunplus.c b/drivers/media/video/gspca/sunplus.c
index 5127bbf9dd26..aa8f995ce04e 100644
--- a/drivers/media/video/gspca/sunplus.c
+++ b/drivers/media/video/gspca/sunplus.c
@@ -32,26 +32,27 @@ MODULE_LICENSE("GPL");
32struct sd { 32struct sd {
33 struct gspca_dev gspca_dev; /* !! must be the first item */ 33 struct gspca_dev gspca_dev; /* !! must be the first item */
34 34
35 unsigned char brightness; 35 s8 brightness;
36 unsigned char contrast; 36 u8 contrast;
37 unsigned char colors; 37 u8 colors;
38 unsigned char autogain; 38 u8 autogain;
39 u8 quality; 39 u8 quality;
40#define QUALITY_MIN 70 40#define QUALITY_MIN 70
41#define QUALITY_MAX 95 41#define QUALITY_MAX 95
42#define QUALITY_DEF 85 42#define QUALITY_DEF 85
43 43
44 char bridge; 44 u8 bridge;
45#define BRIDGE_SPCA504 0 45#define BRIDGE_SPCA504 0
46#define BRIDGE_SPCA504B 1 46#define BRIDGE_SPCA504B 1
47#define BRIDGE_SPCA504C 2 47#define BRIDGE_SPCA504C 2
48#define BRIDGE_SPCA533 3 48#define BRIDGE_SPCA533 3
49#define BRIDGE_SPCA536 4 49#define BRIDGE_SPCA536 4
50 char subtype; 50 u8 subtype;
51#define AiptekMiniPenCam13 1 51#define AiptekMiniPenCam13 1
52#define LogitechClickSmart420 2 52#define LogitechClickSmart420 2
53#define LogitechClickSmart820 3 53#define LogitechClickSmart820 3
54#define MegapixV4 4 54#define MegapixV4 4
55#define MegaImageVI 5
55 56
56 u8 *jpeg_hdr; 57 u8 *jpeg_hdr;
57}; 58};
@@ -67,21 +68,20 @@ static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
67static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val); 68static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
68 69
69static struct ctrl sd_ctrls[] = { 70static struct ctrl sd_ctrls[] = {
70#define SD_BRIGHTNESS 0
71 { 71 {
72 { 72 {
73 .id = V4L2_CID_BRIGHTNESS, 73 .id = V4L2_CID_BRIGHTNESS,
74 .type = V4L2_CTRL_TYPE_INTEGER, 74 .type = V4L2_CTRL_TYPE_INTEGER,
75 .name = "Brightness", 75 .name = "Brightness",
76 .minimum = 0, 76 .minimum = -128,
77 .maximum = 0xff, 77 .maximum = 127,
78 .step = 1, 78 .step = 1,
79 .default_value = 0, 79#define BRIGHTNESS_DEF 0
80 .default_value = BRIGHTNESS_DEF,
80 }, 81 },
81 .set = sd_setbrightness, 82 .set = sd_setbrightness,
82 .get = sd_getbrightness, 83 .get = sd_getbrightness,
83 }, 84 },
84#define SD_CONTRAST 1
85 { 85 {
86 { 86 {
87 .id = V4L2_CID_CONTRAST, 87 .id = V4L2_CID_CONTRAST,
@@ -90,12 +90,12 @@ static struct ctrl sd_ctrls[] = {
90 .minimum = 0, 90 .minimum = 0,
91 .maximum = 0xff, 91 .maximum = 0xff,
92 .step = 1, 92 .step = 1,
93 .default_value = 0x20, 93#define CONTRAST_DEF 0x20
94 .default_value = CONTRAST_DEF,
94 }, 95 },
95 .set = sd_setcontrast, 96 .set = sd_setcontrast,
96 .get = sd_getcontrast, 97 .get = sd_getcontrast,
97 }, 98 },
98#define SD_COLOR 2
99 { 99 {
100 { 100 {
101 .id = V4L2_CID_SATURATION, 101 .id = V4L2_CID_SATURATION,
@@ -104,12 +104,12 @@ static struct ctrl sd_ctrls[] = {
104 .minimum = 0, 104 .minimum = 0,
105 .maximum = 0xff, 105 .maximum = 0xff,
106 .step = 1, 106 .step = 1,
107 .default_value = 0x1a, 107#define COLOR_DEF 0x1a
108 .default_value = COLOR_DEF,
108 }, 109 },
109 .set = sd_setcolors, 110 .set = sd_setcolors,
110 .get = sd_getcolors, 111 .get = sd_getcolors,
111 }, 112 },
112#define SD_AUTOGAIN 3
113 { 113 {
114 { 114 {
115 .id = V4L2_CID_AUTOGAIN, 115 .id = V4L2_CID_AUTOGAIN,
@@ -118,7 +118,8 @@ static struct ctrl sd_ctrls[] = {
118 .minimum = 0, 118 .minimum = 0,
119 .maximum = 1, 119 .maximum = 1,
120 .step = 1, 120 .step = 1,
121 .default_value = 1, 121#define AUTOGAIN_DEF 1
122 .default_value = AUTOGAIN_DEF,
122 }, 123 },
123 .set = sd_setautogain, 124 .set = sd_setautogain,
124 .get = sd_getautogain, 125 .get = sd_getautogain,
@@ -180,14 +181,20 @@ static const struct v4l2_pix_format vga_mode2[] = {
180#define SPCA504_PCCAM600_OFFSET_MODE 5 181#define SPCA504_PCCAM600_OFFSET_MODE 5
181#define SPCA504_PCCAM600_OFFSET_DATA 14 182#define SPCA504_PCCAM600_OFFSET_DATA 14
182 /* Frame packet header offsets for the spca533 */ 183 /* Frame packet header offsets for the spca533 */
183#define SPCA533_OFFSET_DATA 16 184#define SPCA533_OFFSET_DATA 16
184#define SPCA533_OFFSET_FRAMSEQ 15 185#define SPCA533_OFFSET_FRAMSEQ 15
185/* Frame packet header offsets for the spca536 */ 186/* Frame packet header offsets for the spca536 */
186#define SPCA536_OFFSET_DATA 4 187#define SPCA536_OFFSET_DATA 4
187#define SPCA536_OFFSET_FRAMSEQ 1 188#define SPCA536_OFFSET_FRAMSEQ 1
189
190struct cmd {
191 u8 req;
192 u16 val;
193 u16 idx;
194};
188 195
189/* Initialisation data for the Creative PC-CAM 600 */ 196/* Initialisation data for the Creative PC-CAM 600 */
190static const __u16 spca504_pccam600_init_data[][3] = { 197static const struct cmd spca504_pccam600_init_data[] = {
191/* {0xa0, 0x0000, 0x0503}, * capture mode */ 198/* {0xa0, 0x0000, 0x0503}, * capture mode */
192 {0x00, 0x0000, 0x2000}, 199 {0x00, 0x0000, 0x2000},
193 {0x00, 0x0013, 0x2301}, 200 {0x00, 0x0013, 0x2301},
@@ -211,22 +218,20 @@ static const __u16 spca504_pccam600_init_data[][3] = {
211 {0x00, 0x0003, 0x2000}, 218 {0x00, 0x0003, 0x2000},
212 {0x00, 0x0013, 0x2301}, 219 {0x00, 0x0013, 0x2301},
213 {0x00, 0x0003, 0x2000}, 220 {0x00, 0x0003, 0x2000},
214 {}
215}; 221};
216 222
217/* Creative PC-CAM 600 specific open data, sent before using the 223/* Creative PC-CAM 600 specific open data, sent before using the
218 * generic initialisation data from spca504_open_data. 224 * generic initialisation data from spca504_open_data.
219 */ 225 */
220static const __u16 spca504_pccam600_open_data[][3] = { 226static const struct cmd spca504_pccam600_open_data[] = {
221 {0x00, 0x0001, 0x2501}, 227 {0x00, 0x0001, 0x2501},
222 {0x20, 0x0500, 0x0001}, /* snapshot mode */ 228 {0x20, 0x0500, 0x0001}, /* snapshot mode */
223 {0x00, 0x0003, 0x2880}, 229 {0x00, 0x0003, 0x2880},
224 {0x00, 0x0001, 0x2881}, 230 {0x00, 0x0001, 0x2881},
225 {}
226}; 231};
227 232
228/* Initialisation data for the logitech clicksmart 420 */ 233/* Initialisation data for the logitech clicksmart 420 */
229static const __u16 spca504A_clicksmart420_init_data[][3] = { 234static const struct cmd spca504A_clicksmart420_init_data[] = {
230/* {0xa0, 0x0000, 0x0503}, * capture mode */ 235/* {0xa0, 0x0000, 0x0503}, * capture mode */
231 {0x00, 0x0000, 0x2000}, 236 {0x00, 0x0000, 0x2000},
232 {0x00, 0x0013, 0x2301}, 237 {0x00, 0x0013, 0x2301},
@@ -243,7 +248,7 @@ static const __u16 spca504A_clicksmart420_init_data[][3] = {
243 {0xb0, 0x0001, 0x0000}, 248 {0xb0, 0x0001, 0x0000},
244 249
245 250
246 {0x0a1, 0x0080, 0x0001}, 251 {0xa1, 0x0080, 0x0001},
247 {0x30, 0x0049, 0x0000}, 252 {0x30, 0x0049, 0x0000},
248 {0x30, 0x0060, 0x0005}, 253 {0x30, 0x0060, 0x0005},
249 {0x0c, 0x0004, 0x0000}, 254 {0x0c, 0x0004, 0x0000},
@@ -253,11 +258,10 @@ static const __u16 spca504A_clicksmart420_init_data[][3] = {
253 {0x00, 0x0003, 0x2000}, 258 {0x00, 0x0003, 0x2000},
254 {0x00, 0x0000, 0x2000}, 259 {0x00, 0x0000, 0x2000},
255 260
256 {}
257}; 261};
258 262
259/* clicksmart 420 open data ? */ 263/* clicksmart 420 open data ? */
260static const __u16 spca504A_clicksmart420_open_data[][3] = { 264static const struct cmd spca504A_clicksmart420_open_data[] = {
261 {0x00, 0x0001, 0x2501}, 265 {0x00, 0x0001, 0x2501},
262 {0x20, 0x0502, 0x0000}, 266 {0x20, 0x0502, 0x0000},
263 {0x06, 0x0000, 0x0000}, 267 {0x06, 0x0000, 0x0000},
@@ -401,10 +405,9 @@ static const __u16 spca504A_clicksmart420_open_data[][3] = {
401 {0x00, 0x0028, 0x287f}, 405 {0x00, 0x0028, 0x287f},
402 406
403 {0xa0, 0x0000, 0x0503}, 407 {0xa0, 0x0000, 0x0503},
404 {}
405}; 408};
406 409
407static const __u8 qtable_creative_pccam[2][64] = { 410static const u8 qtable_creative_pccam[2][64] = {
408 { /* Q-table Y-components */ 411 { /* Q-table Y-components */
409 0x05, 0x03, 0x03, 0x05, 0x07, 0x0c, 0x0f, 0x12, 412 0x05, 0x03, 0x03, 0x05, 0x07, 0x0c, 0x0f, 0x12,
410 0x04, 0x04, 0x04, 0x06, 0x08, 0x11, 0x12, 0x11, 413 0x04, 0x04, 0x04, 0x06, 0x08, 0x11, 0x12, 0x11,
@@ -429,7 +432,7 @@ static const __u8 qtable_creative_pccam[2][64] = {
429 * except for one byte. Possibly a typo? 432 * except for one byte. Possibly a typo?
430 * NWG: 18/05/2003. 433 * NWG: 18/05/2003.
431 */ 434 */
432static const __u8 qtable_spca504_default[2][64] = { 435static const u8 qtable_spca504_default[2][64] = {
433 { /* Q-table Y-components */ 436 { /* Q-table Y-components */
434 0x05, 0x03, 0x03, 0x05, 0x07, 0x0c, 0x0f, 0x12, 437 0x05, 0x03, 0x03, 0x05, 0x07, 0x0c, 0x0f, 0x12,
435 0x04, 0x04, 0x04, 0x06, 0x08, 0x11, 0x12, 0x11, 438 0x04, 0x04, 0x04, 0x06, 0x08, 0x11, 0x12, 0x11,
@@ -453,9 +456,9 @@ static const __u8 qtable_spca504_default[2][64] = {
453 456
454/* read <len> bytes to gspca_dev->usb_buf */ 457/* read <len> bytes to gspca_dev->usb_buf */
455static void reg_r(struct gspca_dev *gspca_dev, 458static void reg_r(struct gspca_dev *gspca_dev,
456 __u16 req, 459 u8 req,
457 __u16 index, 460 u16 index,
458 __u16 len) 461 u16 len)
459{ 462{
460#ifdef GSPCA_DEBUG 463#ifdef GSPCA_DEBUG
461 if (len > USB_BUF_SZ) { 464 if (len > USB_BUF_SZ) {
@@ -473,31 +476,26 @@ static void reg_r(struct gspca_dev *gspca_dev,
473 500); 476 500);
474} 477}
475 478
476/* write <len> bytes from gspca_dev->usb_buf */ 479/* write one byte */
477static void reg_w(struct gspca_dev *gspca_dev, 480static void reg_w_1(struct gspca_dev *gspca_dev,
478 __u16 req, 481 u8 req,
479 __u16 value, 482 u16 value,
480 __u16 index, 483 u16 index,
481 __u16 len) 484 u16 byte)
482{ 485{
483#ifdef GSPCA_DEBUG 486 gspca_dev->usb_buf[0] = byte;
484 if (len > USB_BUF_SZ) {
485 err("reg_w: buffer overflow");
486 return;
487 }
488#endif
489 usb_control_msg(gspca_dev->dev, 487 usb_control_msg(gspca_dev->dev,
490 usb_sndctrlpipe(gspca_dev->dev, 0), 488 usb_sndctrlpipe(gspca_dev->dev, 0),
491 req, 489 req,
492 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 490 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
493 value, index, 491 value, index,
494 len ? gspca_dev->usb_buf : NULL, len, 492 gspca_dev->usb_buf, 1,
495 500); 493 500);
496} 494}
497 495
498/* write req / index / value */ 496/* write req / index / value */
499static int reg_w_riv(struct usb_device *dev, 497static int reg_w_riv(struct usb_device *dev,
500 __u16 req, __u16 index, __u16 value) 498 u8 req, u16 index, u16 value)
501{ 499{
502 int ret; 500 int ret;
503 501
@@ -515,7 +513,7 @@ static int reg_w_riv(struct usb_device *dev,
515 513
516/* read 1 byte */ 514/* read 1 byte */
517static int reg_r_1(struct gspca_dev *gspca_dev, 515static int reg_r_1(struct gspca_dev *gspca_dev,
518 __u16 value) /* wValue */ 516 u16 value) /* wValue */
519{ 517{
520 int ret; 518 int ret;
521 519
@@ -536,9 +534,9 @@ static int reg_r_1(struct gspca_dev *gspca_dev,
536 534
537/* read 1 or 2 bytes - returns < 0 if error */ 535/* read 1 or 2 bytes - returns < 0 if error */
538static int reg_r_12(struct gspca_dev *gspca_dev, 536static int reg_r_12(struct gspca_dev *gspca_dev,
539 __u16 req, /* bRequest */ 537 u8 req, /* bRequest */
540 __u16 index, /* wIndex */ 538 u16 index, /* wIndex */
541 __u16 length) /* wLength (1 or 2 only) */ 539 u16 length) /* wLength (1 or 2 only) */
542{ 540{
543 int ret; 541 int ret;
544 542
@@ -559,43 +557,40 @@ static int reg_r_12(struct gspca_dev *gspca_dev,
559} 557}
560 558
561static int write_vector(struct gspca_dev *gspca_dev, 559static int write_vector(struct gspca_dev *gspca_dev,
562 const __u16 data[][3]) 560 const struct cmd *data, int ncmds)
563{ 561{
564 struct usb_device *dev = gspca_dev->dev; 562 struct usb_device *dev = gspca_dev->dev;
565 int ret, i = 0; 563 int ret;
566 564
567 while (data[i][0] != 0 || data[i][1] != 0 || data[i][2] != 0) { 565 while (--ncmds >= 0) {
568 ret = reg_w_riv(dev, data[i][0], data[i][2], data[i][1]); 566 ret = reg_w_riv(dev, data->req, data->idx, data->val);
569 if (ret < 0) { 567 if (ret < 0) {
570 PDEBUG(D_ERR, 568 PDEBUG(D_ERR,
571 "Register write failed for 0x%x,0x%x,0x%x", 569 "Register write failed for 0x%02x, 0x%04x, 0x%04x",
572 data[i][0], data[i][1], data[i][2]); 570 data->req, data->val, data->idx);
573 return ret; 571 return ret;
574 } 572 }
575 i++; 573 data++;
576 } 574 }
577 return 0; 575 return 0;
578} 576}
579 577
580static int spca50x_setup_qtable(struct gspca_dev *gspca_dev, 578static int spca50x_setup_qtable(struct gspca_dev *gspca_dev,
581 unsigned int request, 579 const u8 qtable[2][64])
582 unsigned int ybase,
583 unsigned int cbase,
584 const __u8 qtable[2][64])
585{ 580{
586 struct usb_device *dev = gspca_dev->dev; 581 struct usb_device *dev = gspca_dev->dev;
587 int i, err; 582 int i, err;
588 583
589 /* loop over y components */ 584 /* loop over y components */
590 for (i = 0; i < 64; i++) { 585 for (i = 0; i < 64; i++) {
591 err = reg_w_riv(dev, request, ybase + i, qtable[0][i]); 586 err = reg_w_riv(dev, 0x00, 0x2800 + i, qtable[0][i]);
592 if (err < 0) 587 if (err < 0)
593 return err; 588 return err;
594 } 589 }
595 590
596 /* loop over c components */ 591 /* loop over c components */
597 for (i = 0; i < 64; i++) { 592 for (i = 0; i < 64; i++) {
598 err = reg_w_riv(dev, request, cbase + i, qtable[1][i]); 593 err = reg_w_riv(dev, 0x00, 0x2840 + i, qtable[1][i]);
599 if (err < 0) 594 if (err < 0)
600 return err; 595 return err;
601 } 596 }
@@ -603,34 +598,34 @@ static int spca50x_setup_qtable(struct gspca_dev *gspca_dev,
603} 598}
604 599
605static void spca504_acknowledged_command(struct gspca_dev *gspca_dev, 600static void spca504_acknowledged_command(struct gspca_dev *gspca_dev,
606 __u16 req, __u16 idx, __u16 val) 601 u8 req, u16 idx, u16 val)
607{ 602{
608 struct usb_device *dev = gspca_dev->dev; 603 struct usb_device *dev = gspca_dev->dev;
609 __u8 notdone; 604 int notdone;
610 605
611 reg_w_riv(dev, req, idx, val); 606 reg_w_riv(dev, req, idx, val);
612 notdone = reg_r_12(gspca_dev, 0x01, 0x0001, 1); 607 notdone = reg_r_12(gspca_dev, 0x01, 0x0001, 1);
613 reg_w_riv(dev, req, idx, val); 608 reg_w_riv(dev, req, idx, val);
614 609
615 PDEBUG(D_FRAM, "before wait 0x%x", notdone); 610 PDEBUG(D_FRAM, "before wait 0x%04x", notdone);
616 611
617 msleep(200); 612 msleep(200);
618 notdone = reg_r_12(gspca_dev, 0x01, 0x0001, 1); 613 notdone = reg_r_12(gspca_dev, 0x01, 0x0001, 1);
619 PDEBUG(D_FRAM, "after wait 0x%x", notdone); 614 PDEBUG(D_FRAM, "after wait 0x%04x", notdone);
620} 615}
621 616
622static void spca504A_acknowledged_command(struct gspca_dev *gspca_dev, 617static void spca504A_acknowledged_command(struct gspca_dev *gspca_dev,
623 __u16 req, 618 u8 req,
624 __u16 idx, __u16 val, __u8 stat, __u8 count) 619 u16 idx, u16 val, u8 stat, u8 count)
625{ 620{
626 struct usb_device *dev = gspca_dev->dev; 621 struct usb_device *dev = gspca_dev->dev;
627 __u8 status; 622 int status;
628 __u8 endcode; 623 u8 endcode;
629 624
630 reg_w_riv(dev, req, idx, val); 625 reg_w_riv(dev, req, idx, val);
631 status = reg_r_12(gspca_dev, 0x01, 0x0001, 1); 626 status = reg_r_12(gspca_dev, 0x01, 0x0001, 1);
632 endcode = stat; 627 endcode = stat;
633 PDEBUG(D_FRAM, "Status 0x%x Need 0x%x", status, stat); 628 PDEBUG(D_FRAM, "Status 0x%x Need 0x%04x", status, stat);
634 if (!count) 629 if (!count)
635 return; 630 return;
636 count = 200; 631 count = 200;
@@ -640,7 +635,7 @@ static void spca504A_acknowledged_command(struct gspca_dev *gspca_dev,
640/* reg_w_riv(dev, req, idx, val); */ 635/* reg_w_riv(dev, req, idx, val); */
641 status = reg_r_12(gspca_dev, 0x01, 0x0001, 1); 636 status = reg_r_12(gspca_dev, 0x01, 0x0001, 1);
642 if (status == endcode) { 637 if (status == endcode) {
643 PDEBUG(D_FRAM, "status 0x%x after wait 0x%x", 638 PDEBUG(D_FRAM, "status 0x%04x after wait %d",
644 status, 200 - count); 639 status, 200 - count);
645 break; 640 break;
646 } 641 }
@@ -667,8 +662,7 @@ static void spca504B_WaitCmdStatus(struct gspca_dev *gspca_dev)
667 while (--count > 0) { 662 while (--count > 0) {
668 reg_r(gspca_dev, 0x21, 1, 1); 663 reg_r(gspca_dev, 0x21, 1, 1);
669 if (gspca_dev->usb_buf[0] != 0) { 664 if (gspca_dev->usb_buf[0] != 0) {
670 gspca_dev->usb_buf[0] = 0; 665 reg_w_1(gspca_dev, 0x21, 0, 1, 0);
671 reg_w(gspca_dev, 0x21, 0, 1, 1);
672 reg_r(gspca_dev, 0x21, 1, 1); 666 reg_r(gspca_dev, 0x21, 1, 1);
673 spca504B_PollingDataReady(gspca_dev); 667 spca504B_PollingDataReady(gspca_dev);
674 break; 668 break;
@@ -679,7 +673,7 @@ static void spca504B_WaitCmdStatus(struct gspca_dev *gspca_dev)
679 673
680static void spca50x_GetFirmware(struct gspca_dev *gspca_dev) 674static void spca50x_GetFirmware(struct gspca_dev *gspca_dev)
681{ 675{
682 __u8 *data; 676 u8 *data;
683 677
684 data = gspca_dev->usb_buf; 678 data = gspca_dev->usb_buf;
685 reg_r(gspca_dev, 0x20, 0, 5); 679 reg_r(gspca_dev, 0x20, 0, 5);
@@ -693,41 +687,34 @@ static void spca504B_SetSizeType(struct gspca_dev *gspca_dev)
693{ 687{
694 struct sd *sd = (struct sd *) gspca_dev; 688 struct sd *sd = (struct sd *) gspca_dev;
695 struct usb_device *dev = gspca_dev->dev; 689 struct usb_device *dev = gspca_dev->dev;
696 __u8 Size; 690 u8 Size;
697 __u8 Type;
698 int rc; 691 int rc;
699 692
700 Size = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv; 693 Size = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
701 Type = 0;
702 switch (sd->bridge) { 694 switch (sd->bridge) {
703 case BRIDGE_SPCA533: 695 case BRIDGE_SPCA533:
704 reg_w(gspca_dev, 0x31, 0, 0, 0); 696 reg_w_riv(dev, 0x31, 0, 0);
705 spca504B_WaitCmdStatus(gspca_dev); 697 spca504B_WaitCmdStatus(gspca_dev);
706 rc = spca504B_PollingDataReady(gspca_dev); 698 rc = spca504B_PollingDataReady(gspca_dev);
707 spca50x_GetFirmware(gspca_dev); 699 spca50x_GetFirmware(gspca_dev);
708 gspca_dev->usb_buf[0] = 2; /* type */ 700 reg_w_1(gspca_dev, 0x24, 0, 8, 2); /* type */
709 reg_w(gspca_dev, 0x24, 0, 8, 1);
710 reg_r(gspca_dev, 0x24, 8, 1); 701 reg_r(gspca_dev, 0x24, 8, 1);
711 702
712 gspca_dev->usb_buf[0] = Size; 703 reg_w_1(gspca_dev, 0x25, 0, 4, Size);
713 reg_w(gspca_dev, 0x25, 0, 4, 1);
714 reg_r(gspca_dev, 0x25, 4, 1); /* size */ 704 reg_r(gspca_dev, 0x25, 4, 1); /* size */
715 rc = spca504B_PollingDataReady(gspca_dev); 705 rc = spca504B_PollingDataReady(gspca_dev);
716 706
717 /* Init the cam width height with some values get on init ? */ 707 /* Init the cam width height with some values get on init ? */
718 reg_w(gspca_dev, 0x31, 0, 4, 0); 708 reg_w_riv(dev, 0x31, 0, 0x04);
719 spca504B_WaitCmdStatus(gspca_dev); 709 spca504B_WaitCmdStatus(gspca_dev);
720 rc = spca504B_PollingDataReady(gspca_dev); 710 rc = spca504B_PollingDataReady(gspca_dev);
721 break; 711 break;
722 default: 712 default:
723/* case BRIDGE_SPCA504B: */ 713/* case BRIDGE_SPCA504B: */
724/* case BRIDGE_SPCA536: */ 714/* case BRIDGE_SPCA536: */
725 gspca_dev->usb_buf[0] = Size; 715 reg_w_1(gspca_dev, 0x25, 0, 4, Size);
726 reg_w(gspca_dev, 0x25, 0, 4, 1);
727 reg_r(gspca_dev, 0x25, 4, 1); /* size */ 716 reg_r(gspca_dev, 0x25, 4, 1); /* size */
728 Type = 6; 717 reg_w_1(gspca_dev, 0x27, 0, 0, 6);
729 gspca_dev->usb_buf[0] = Type;
730 reg_w(gspca_dev, 0x27, 0, 0, 1);
731 reg_r(gspca_dev, 0x27, 0, 1); /* type */ 718 reg_r(gspca_dev, 0x27, 0, 1); /* type */
732 rc = spca504B_PollingDataReady(gspca_dev); 719 rc = spca504B_PollingDataReady(gspca_dev);
733 break; 720 break;
@@ -767,17 +754,51 @@ static void spca504_wait_status(struct gspca_dev *gspca_dev)
767 754
768static void spca504B_setQtable(struct gspca_dev *gspca_dev) 755static void spca504B_setQtable(struct gspca_dev *gspca_dev)
769{ 756{
770 gspca_dev->usb_buf[0] = 3; 757 reg_w_1(gspca_dev, 0x26, 0, 0, 3);
771 reg_w(gspca_dev, 0x26, 0, 0, 1);
772 reg_r(gspca_dev, 0x26, 0, 1); 758 reg_r(gspca_dev, 0x26, 0, 1);
773 spca504B_PollingDataReady(gspca_dev); 759 spca504B_PollingDataReady(gspca_dev);
774} 760}
775 761
776static void sp5xx_initContBrigHueRegisters(struct gspca_dev *gspca_dev) 762static void setbrightness(struct gspca_dev *gspca_dev)
763{
764 struct sd *sd = (struct sd *) gspca_dev;
765 struct usb_device *dev = gspca_dev->dev;
766 u16 reg;
767
768 reg = sd->bridge == BRIDGE_SPCA536 ? 0x20f0 : 0x21a7;
769 reg_w_riv(dev, 0x00, reg, sd->brightness);
770}
771
772static void setcontrast(struct gspca_dev *gspca_dev)
773{
774 struct sd *sd = (struct sd *) gspca_dev;
775 struct usb_device *dev = gspca_dev->dev;
776 u16 reg;
777
778 reg = sd->bridge == BRIDGE_SPCA536 ? 0x20f1 : 0x21a8;
779 reg_w_riv(dev, 0x00, reg, sd->contrast);
780}
781
782static void setcolors(struct gspca_dev *gspca_dev)
783{
784 struct sd *sd = (struct sd *) gspca_dev;
785 struct usb_device *dev = gspca_dev->dev;
786 u16 reg;
787
788 reg = sd->bridge == BRIDGE_SPCA536 ? 0x20f6 : 0x21ae;
789 reg_w_riv(dev, 0x00, reg, sd->colors);
790}
791
792static void init_ctl_reg(struct gspca_dev *gspca_dev)
777{ 793{
778 struct sd *sd = (struct sd *) gspca_dev; 794 struct sd *sd = (struct sd *) gspca_dev;
795 struct usb_device *dev = gspca_dev->dev;
779 int pollreg = 1; 796 int pollreg = 1;
780 797
798 setbrightness(gspca_dev);
799 setcontrast(gspca_dev);
800 setcolors(gspca_dev);
801
781 switch (sd->bridge) { 802 switch (sd->bridge) {
782 case BRIDGE_SPCA504: 803 case BRIDGE_SPCA504:
783 case BRIDGE_SPCA504C: 804 case BRIDGE_SPCA504C:
@@ -786,20 +807,14 @@ static void sp5xx_initContBrigHueRegisters(struct gspca_dev *gspca_dev)
786 default: 807 default:
787/* case BRIDGE_SPCA533: */ 808/* case BRIDGE_SPCA533: */
788/* case BRIDGE_SPCA504B: */ 809/* case BRIDGE_SPCA504B: */
789 reg_w(gspca_dev, 0, 0, 0x21a7, 0); /* brightness */ 810 reg_w_riv(dev, 0, 0x00, 0x21ad); /* hue */
790 reg_w(gspca_dev, 0, 0x20, 0x21a8, 0); /* contrast */ 811 reg_w_riv(dev, 0, 0x01, 0x21ac); /* sat/hue */
791 reg_w(gspca_dev, 0, 0, 0x21ad, 0); /* hue */ 812 reg_w_riv(dev, 0, 0x00, 0x21a3); /* gamma */
792 reg_w(gspca_dev, 0, 1, 0x21ac, 0); /* sat/hue */
793 reg_w(gspca_dev, 0, 0x20, 0x21ae, 0); /* saturation */
794 reg_w(gspca_dev, 0, 0, 0x21a3, 0); /* gamma */
795 break; 813 break;
796 case BRIDGE_SPCA536: 814 case BRIDGE_SPCA536:
797 reg_w(gspca_dev, 0, 0, 0x20f0, 0); 815 reg_w_riv(dev, 0, 0x40, 0x20f5);
798 reg_w(gspca_dev, 0, 0x21, 0x20f1, 0); 816 reg_w_riv(dev, 0, 0x01, 0x20f4);
799 reg_w(gspca_dev, 0, 0x40, 0x20f5, 0); 817 reg_w_riv(dev, 0, 0x00, 0x2089);
800 reg_w(gspca_dev, 0, 1, 0x20f4, 0);
801 reg_w(gspca_dev, 0, 0x40, 0x20f6, 0);
802 reg_w(gspca_dev, 0, 0, 0x2089, 0);
803 break; 818 break;
804 } 819 }
805 if (pollreg) 820 if (pollreg)
@@ -840,20 +855,24 @@ static int sd_config(struct gspca_dev *gspca_dev,
840/* case BRIDGE_SPCA504: */ 855/* case BRIDGE_SPCA504: */
841/* case BRIDGE_SPCA536: */ 856/* case BRIDGE_SPCA536: */
842 cam->cam_mode = vga_mode; 857 cam->cam_mode = vga_mode;
843 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0]; 858 cam->nmodes =ARRAY_SIZE(vga_mode);
844 break; 859 break;
845 case BRIDGE_SPCA533: 860 case BRIDGE_SPCA533:
846 cam->cam_mode = custom_mode; 861 cam->cam_mode = custom_mode;
847 cam->nmodes = sizeof custom_mode / sizeof custom_mode[0]; 862 if (sd->subtype == MegaImageVI) /* 320x240 only */
863 cam->nmodes = ARRAY_SIZE(custom_mode) - 1;
864 else
865 cam->nmodes = ARRAY_SIZE(custom_mode);
848 break; 866 break;
849 case BRIDGE_SPCA504C: 867 case BRIDGE_SPCA504C:
850 cam->cam_mode = vga_mode2; 868 cam->cam_mode = vga_mode2;
851 cam->nmodes = sizeof vga_mode2 / sizeof vga_mode2[0]; 869 cam->nmodes = ARRAY_SIZE(vga_mode2);
852 break; 870 break;
853 } 871 }
854 sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value; 872 sd->brightness = BRIGHTNESS_DEF;
855 sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value; 873 sd->contrast = CONTRAST_DEF;
856 sd->colors = sd_ctrls[SD_COLOR].qctrl.default_value; 874 sd->colors = COLOR_DEF;
875 sd->autogain = AUTOGAIN_DEF;
857 sd->quality = QUALITY_DEF; 876 sd->quality = QUALITY_DEF;
858 return 0; 877 return 0;
859} 878}
@@ -863,32 +882,29 @@ static int sd_init(struct gspca_dev *gspca_dev)
863{ 882{
864 struct sd *sd = (struct sd *) gspca_dev; 883 struct sd *sd = (struct sd *) gspca_dev;
865 struct usb_device *dev = gspca_dev->dev; 884 struct usb_device *dev = gspca_dev->dev;
866 int rc; 885 int i, err_code;
867 __u8 i; 886 u8 info[6];
868 __u8 info[6];
869 int err_code;
870 887
871 switch (sd->bridge) { 888 switch (sd->bridge) {
872 case BRIDGE_SPCA504B: 889 case BRIDGE_SPCA504B:
873 reg_w(gspca_dev, 0x1d, 0, 0, 0); 890 reg_w_riv(dev, 0x1d, 0x00, 0);
874 reg_w(gspca_dev, 0, 1, 0x2306, 0); 891 reg_w_riv(dev, 0, 0x01, 0x2306);
875 reg_w(gspca_dev, 0, 0, 0x0d04, 0); 892 reg_w_riv(dev, 0, 0x00, 0x0d04);
876 reg_w(gspca_dev, 0, 0, 0x2000, 0); 893 reg_w_riv(dev, 0, 0x00, 0x2000);
877 reg_w(gspca_dev, 0, 0x13, 0x2301, 0); 894 reg_w_riv(dev, 0, 0x13, 0x2301);
878 reg_w(gspca_dev, 0, 0, 0x2306, 0); 895 reg_w_riv(dev, 0, 0x00, 0x2306);
879 /* fall thru */ 896 /* fall thru */
880 case BRIDGE_SPCA533: 897 case BRIDGE_SPCA533:
881 rc = spca504B_PollingDataReady(gspca_dev); 898 spca504B_PollingDataReady(gspca_dev);
882 spca50x_GetFirmware(gspca_dev); 899 spca50x_GetFirmware(gspca_dev);
883 break; 900 break;
884 case BRIDGE_SPCA536: 901 case BRIDGE_SPCA536:
885 spca50x_GetFirmware(gspca_dev); 902 spca50x_GetFirmware(gspca_dev);
886 reg_r(gspca_dev, 0x00, 0x5002, 1); 903 reg_r(gspca_dev, 0x00, 0x5002, 1);
887 gspca_dev->usb_buf[0] = 0; 904 reg_w_1(gspca_dev, 0x24, 0, 0, 0);
888 reg_w(gspca_dev, 0x24, 0, 0, 1);
889 reg_r(gspca_dev, 0x24, 0, 1); 905 reg_r(gspca_dev, 0x24, 0, 1);
890 rc = spca504B_PollingDataReady(gspca_dev); 906 spca504B_PollingDataReady(gspca_dev);
891 reg_w(gspca_dev, 0x34, 0, 0, 0); 907 reg_w_riv(dev, 0x34, 0, 0);
892 spca504B_WaitCmdStatus(gspca_dev); 908 spca504B_WaitCmdStatus(gspca_dev);
893 break; 909 break;
894 case BRIDGE_SPCA504C: /* pccam600 */ 910 case BRIDGE_SPCA504C: /* pccam600 */
@@ -898,12 +914,13 @@ static int sd_init(struct gspca_dev *gspca_dev)
898 spca504_wait_status(gspca_dev); 914 spca504_wait_status(gspca_dev);
899 if (sd->subtype == LogitechClickSmart420) 915 if (sd->subtype == LogitechClickSmart420)
900 write_vector(gspca_dev, 916 write_vector(gspca_dev,
901 spca504A_clicksmart420_open_data); 917 spca504A_clicksmart420_open_data,
918 ARRAY_SIZE(spca504A_clicksmart420_open_data));
902 else 919 else
903 write_vector(gspca_dev, spca504_pccam600_open_data); 920 write_vector(gspca_dev, spca504_pccam600_open_data,
921 ARRAY_SIZE(spca504_pccam600_open_data));
904 err_code = spca50x_setup_qtable(gspca_dev, 922 err_code = spca50x_setup_qtable(gspca_dev,
905 0x00, 0x2800, 923 qtable_creative_pccam);
906 0x2840, qtable_creative_pccam);
907 if (err_code < 0) { 924 if (err_code < 0) {
908 PDEBUG(D_ERR|D_STREAM, "spca50x_setup_qtable failed"); 925 PDEBUG(D_ERR|D_STREAM, "spca50x_setup_qtable failed");
909 return err_code; 926 return err_code;
@@ -941,8 +958,8 @@ static int sd_init(struct gspca_dev *gspca_dev)
941 6, 0, 0x86, 1); */ 958 6, 0, 0x86, 1); */
942/* spca504A_acknowledged_command (gspca_dev, 0x24, 959/* spca504A_acknowledged_command (gspca_dev, 0x24,
943 0, 0, 0x9D, 1); */ 960 0, 0, 0x9D, 1); */
944 reg_w_riv(dev, 0x0, 0x270c, 0x05); /* L92 sno1t.txt */ 961 reg_w_riv(dev, 0x00, 0x270c, 0x05); /* L92 sno1t.txt */
945 reg_w_riv(dev, 0x0, 0x2310, 0x05); 962 reg_w_riv(dev, 0x00, 0x2310, 0x05);
946 spca504A_acknowledged_command(gspca_dev, 0x01, 963 spca504A_acknowledged_command(gspca_dev, 0x01,
947 0x0f, 0, 0xff, 0); 964 0x0f, 0, 0xff, 0);
948 } 965 }
@@ -950,8 +967,6 @@ static int sd_init(struct gspca_dev *gspca_dev)
950 reg_w_riv(dev, 0, 0x2000, 0); 967 reg_w_riv(dev, 0, 0x2000, 0);
951 reg_w_riv(dev, 0, 0x2883, 1); 968 reg_w_riv(dev, 0, 0x2883, 1);
952 err_code = spca50x_setup_qtable(gspca_dev, 969 err_code = spca50x_setup_qtable(gspca_dev,
953 0x00, 0x2800,
954 0x2840,
955 qtable_spca504_default); 970 qtable_spca504_default);
956 if (err_code < 0) { 971 if (err_code < 0) {
957 PDEBUG(D_ERR, "spca50x_setup_qtable failed"); 972 PDEBUG(D_ERR, "spca50x_setup_qtable failed");
@@ -966,10 +981,9 @@ static int sd_start(struct gspca_dev *gspca_dev)
966{ 981{
967 struct sd *sd = (struct sd *) gspca_dev; 982 struct sd *sd = (struct sd *) gspca_dev;
968 struct usb_device *dev = gspca_dev->dev; 983 struct usb_device *dev = gspca_dev->dev;
969 int rc;
970 int enable; 984 int enable;
971 __u8 i; 985 int i;
972 __u8 info[6]; 986 u8 info[6];
973 987
974 /* create the JPEG header */ 988 /* create the JPEG header */
975 sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL); 989 sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
@@ -987,16 +1001,20 @@ static int sd_start(struct gspca_dev *gspca_dev)
987/* case BRIDGE_SPCA504B: */ 1001/* case BRIDGE_SPCA504B: */
988/* case BRIDGE_SPCA533: */ 1002/* case BRIDGE_SPCA533: */
989/* case BRIDGE_SPCA536: */ 1003/* case BRIDGE_SPCA536: */
990 if (sd->subtype == MegapixV4 || 1004 switch (sd->subtype) {
991 sd->subtype == LogitechClickSmart820) { 1005 case MegapixV4:
992 reg_w(gspca_dev, 0xf0, 0, 0, 0); 1006 case LogitechClickSmart820:
1007 case MegaImageVI:
1008 reg_w_riv(dev, 0xf0, 0, 0);
993 spca504B_WaitCmdStatus(gspca_dev); 1009 spca504B_WaitCmdStatus(gspca_dev);
994 reg_r(gspca_dev, 0xf0, 4, 0); 1010 reg_r(gspca_dev, 0xf0, 4, 0);
995 spca504B_WaitCmdStatus(gspca_dev); 1011 spca504B_WaitCmdStatus(gspca_dev);
996 } else { 1012 break;
997 reg_w(gspca_dev, 0x31, 0, 4, 0); 1013 default:
1014 reg_w_riv(dev, 0x31, 0, 0x04);
998 spca504B_WaitCmdStatus(gspca_dev); 1015 spca504B_WaitCmdStatus(gspca_dev);
999 rc = spca504B_PollingDataReady(gspca_dev); 1016 spca504B_PollingDataReady(gspca_dev);
1017 break;
1000 } 1018 }
1001 break; 1019 break;
1002 case BRIDGE_SPCA504: 1020 case BRIDGE_SPCA504:
@@ -1030,15 +1048,17 @@ static int sd_start(struct gspca_dev *gspca_dev)
1030 spca504_acknowledged_command(gspca_dev, 0x24, 0, 0); 1048 spca504_acknowledged_command(gspca_dev, 0x24, 0, 0);
1031 } 1049 }
1032 spca504B_SetSizeType(gspca_dev); 1050 spca504B_SetSizeType(gspca_dev);
1033 reg_w_riv(dev, 0x0, 0x270c, 0x05); /* L92 sno1t.txt */ 1051 reg_w_riv(dev, 0x00, 0x270c, 0x05); /* L92 sno1t.txt */
1034 reg_w_riv(dev, 0x0, 0x2310, 0x05); 1052 reg_w_riv(dev, 0x00, 0x2310, 0x05);
1035 break; 1053 break;
1036 case BRIDGE_SPCA504C: 1054 case BRIDGE_SPCA504C:
1037 if (sd->subtype == LogitechClickSmart420) { 1055 if (sd->subtype == LogitechClickSmart420) {
1038 write_vector(gspca_dev, 1056 write_vector(gspca_dev,
1039 spca504A_clicksmart420_init_data); 1057 spca504A_clicksmart420_init_data,
1058 ARRAY_SIZE(spca504A_clicksmart420_init_data));
1040 } else { 1059 } else {
1041 write_vector(gspca_dev, spca504_pccam600_init_data); 1060 write_vector(gspca_dev, spca504_pccam600_init_data,
1061 ARRAY_SIZE(spca504_pccam600_init_data));
1042 } 1062 }
1043 enable = (sd->autogain ? 0x04 : 0x01); 1063 enable = (sd->autogain ? 0x04 : 0x01);
1044 reg_w_riv(dev, 0x0c, 0x0000, enable); /* auto exposure */ 1064 reg_w_riv(dev, 0x0c, 0x0000, enable); /* auto exposure */
@@ -1050,7 +1070,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
1050 spca504B_SetSizeType(gspca_dev); 1070 spca504B_SetSizeType(gspca_dev);
1051 break; 1071 break;
1052 } 1072 }
1053 sp5xx_initContBrigHueRegisters(gspca_dev); 1073 init_ctl_reg(gspca_dev);
1054 return 0; 1074 return 0;
1055} 1075}
1056 1076
@@ -1064,7 +1084,7 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
1064/* case BRIDGE_SPCA533: */ 1084/* case BRIDGE_SPCA533: */
1065/* case BRIDGE_SPCA536: */ 1085/* case BRIDGE_SPCA536: */
1066/* case BRIDGE_SPCA504B: */ 1086/* case BRIDGE_SPCA504B: */
1067 reg_w(gspca_dev, 0x31, 0, 0, 0); 1087 reg_w_riv(dev, 0x31, 0, 0);
1068 spca504B_WaitCmdStatus(gspca_dev); 1088 spca504B_WaitCmdStatus(gspca_dev);
1069 spca504B_PollingDataReady(gspca_dev); 1089 spca504B_PollingDataReady(gspca_dev);
1070 break; 1090 break;
@@ -1082,7 +1102,7 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
1082 0x0f, 0x00, 0xff, 1); 1102 0x0f, 0x00, 0xff, 1);
1083 } else { 1103 } else {
1084 spca504_acknowledged_command(gspca_dev, 0x24, 0, 0); 1104 spca504_acknowledged_command(gspca_dev, 0x24, 0, 0);
1085 reg_w_riv(dev, 0x01, 0x000f, 0x00); 1105 reg_w_riv(dev, 0x01, 0x000f, 0x0000);
1086 } 1106 }
1087 break; 1107 break;
1088 } 1108 }
@@ -1097,12 +1117,12 @@ static void sd_stop0(struct gspca_dev *gspca_dev)
1097 1117
1098static void sd_pkt_scan(struct gspca_dev *gspca_dev, 1118static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1099 struct gspca_frame *frame, /* target */ 1119 struct gspca_frame *frame, /* target */
1100 __u8 *data, /* isoc packet */ 1120 u8 *data, /* isoc packet */
1101 int len) /* iso packet length */ 1121 int len) /* iso packet length */
1102{ 1122{
1103 struct sd *sd = (struct sd *) gspca_dev; 1123 struct sd *sd = (struct sd *) gspca_dev;
1104 int i, sof = 0; 1124 int i, sof = 0;
1105 static unsigned char ffd9[] = {0xff, 0xd9}; 1125 static u8 ffd9[] = {0xff, 0xd9};
1106 1126
1107/* frames are jpeg 4.1.1 without 0xff escape */ 1127/* frames are jpeg 4.1.1 without 0xff escape */
1108 switch (sd->bridge) { 1128 switch (sd->bridge) {
@@ -1190,63 +1210,6 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1190 gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len); 1210 gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
1191} 1211}
1192 1212
1193static void setbrightness(struct gspca_dev *gspca_dev)
1194{
1195 struct sd *sd = (struct sd *) gspca_dev;
1196 struct usb_device *dev = gspca_dev->dev;
1197
1198 switch (sd->bridge) {
1199 default:
1200/* case BRIDGE_SPCA533: */
1201/* case BRIDGE_SPCA504B: */
1202/* case BRIDGE_SPCA504: */
1203/* case BRIDGE_SPCA504C: */
1204 reg_w_riv(dev, 0x0, 0x21a7, sd->brightness);
1205 break;
1206 case BRIDGE_SPCA536:
1207 reg_w_riv(dev, 0x0, 0x20f0, sd->brightness);
1208 break;
1209 }
1210}
1211
1212static void setcontrast(struct gspca_dev *gspca_dev)
1213{
1214 struct sd *sd = (struct sd *) gspca_dev;
1215 struct usb_device *dev = gspca_dev->dev;
1216
1217 switch (sd->bridge) {
1218 default:
1219/* case BRIDGE_SPCA533: */
1220/* case BRIDGE_SPCA504B: */
1221/* case BRIDGE_SPCA504: */
1222/* case BRIDGE_SPCA504C: */
1223 reg_w_riv(dev, 0x0, 0x21a8, sd->contrast);
1224 break;
1225 case BRIDGE_SPCA536:
1226 reg_w_riv(dev, 0x0, 0x20f1, sd->contrast);
1227 break;
1228 }
1229}
1230
1231static void setcolors(struct gspca_dev *gspca_dev)
1232{
1233 struct sd *sd = (struct sd *) gspca_dev;
1234 struct usb_device *dev = gspca_dev->dev;
1235
1236 switch (sd->bridge) {
1237 default:
1238/* case BRIDGE_SPCA533: */
1239/* case BRIDGE_SPCA504B: */
1240/* case BRIDGE_SPCA504: */
1241/* case BRIDGE_SPCA504C: */
1242 reg_w_riv(dev, 0x0, 0x21ae, sd->colors);
1243 break;
1244 case BRIDGE_SPCA536:
1245 reg_w_riv(dev, 0x0, 0x20f6, sd->colors);
1246 break;
1247 }
1248}
1249
1250static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) 1213static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
1251{ 1214{
1252 struct sd *sd = (struct sd *) gspca_dev; 1215 struct sd *sd = (struct sd *) gspca_dev;
@@ -1384,6 +1347,7 @@ static const __devinitdata struct usb_device_id device_table[] = {
1384 {USB_DEVICE(0x04fc, 0x5360), BS(SPCA536, 0)}, 1347 {USB_DEVICE(0x04fc, 0x5360), BS(SPCA536, 0)},
1385 {USB_DEVICE(0x04fc, 0xffff), BS(SPCA504B, 0)}, 1348 {USB_DEVICE(0x04fc, 0xffff), BS(SPCA504B, 0)},
1386 {USB_DEVICE(0x052b, 0x1513), BS(SPCA533, MegapixV4)}, 1349 {USB_DEVICE(0x052b, 0x1513), BS(SPCA533, MegapixV4)},
1350 {USB_DEVICE(0x052b, 0x1803), BS(SPCA533, MegaImageVI)},
1387 {USB_DEVICE(0x0546, 0x3155), BS(SPCA533, 0)}, 1351 {USB_DEVICE(0x0546, 0x3155), BS(SPCA533, 0)},
1388 {USB_DEVICE(0x0546, 0x3191), BS(SPCA504B, 0)}, 1352 {USB_DEVICE(0x0546, 0x3191), BS(SPCA504B, 0)},
1389 {USB_DEVICE(0x0546, 0x3273), BS(SPCA504B, 0)}, 1353 {USB_DEVICE(0x0546, 0x3273), BS(SPCA504B, 0)},
diff --git a/drivers/media/video/gspca/t613.c b/drivers/media/video/gspca/t613.c
index 404214b8cd2b..1d321c30d22f 100644
--- a/drivers/media/video/gspca/t613.c
+++ b/drivers/media/video/gspca/t613.c
@@ -264,6 +264,10 @@ static const struct v4l2_pix_format vga_mode_t16[] = {
264 264
265/* sensor specific data */ 265/* sensor specific data */
266struct additional_sensor_data { 266struct additional_sensor_data {
267 const u8 n3[6];
268 const u8 *n4, n4sz;
269 const u8 reg80, reg8e;
270 const u8 nset8[6];
267 const u8 data1[10]; 271 const u8 data1[10];
268 const u8 data2[9]; 272 const u8 data2[9];
269 const u8 data3[9]; 273 const u8 data3[9];
@@ -272,14 +276,55 @@ struct additional_sensor_data {
272 const u8 stream[4]; 276 const u8 stream[4];
273}; 277};
274 278
279static const u8 n4_om6802[] = {
280 0x09, 0x01, 0x12, 0x04, 0x66, 0x8a, 0x80, 0x3c,
281 0x81, 0x22, 0x84, 0x50, 0x8a, 0x78, 0x8b, 0x68,
282 0x8c, 0x88, 0x8e, 0x33, 0x8f, 0x24, 0xaa, 0xb1,
283 0xa2, 0x60, 0xa5, 0x30, 0xa6, 0x3a, 0xa8, 0xe8,
284 0xae, 0x05, 0xb1, 0x00, 0xbb, 0x04, 0xbc, 0x48,
285 0xbe, 0x36, 0xc6, 0x88, 0xe9, 0x00, 0xc5, 0xc0,
286 0x65, 0x0a, 0xbb, 0x86, 0xaf, 0x58, 0xb0, 0x68,
287 0x87, 0x40, 0x89, 0x2b, 0x8d, 0xff, 0x83, 0x40,
288 0xac, 0x84, 0xad, 0x86, 0xaf, 0x46
289};
290static const u8 n4_other[] = {
291 0x66, 0x00, 0x7f, 0x00, 0x80, 0xac, 0x81, 0x69,
292 0x84, 0x40, 0x85, 0x70, 0x86, 0x20, 0x8a, 0x68,
293 0x8b, 0x58, 0x8c, 0x88, 0x8d, 0xff, 0x8e, 0xb8,
294 0x8f, 0x28, 0xa2, 0x60, 0xa5, 0x40, 0xa8, 0xa8,
295 0xac, 0x84, 0xad, 0x84, 0xae, 0x24, 0xaf, 0x56,
296 0xb0, 0x68, 0xb1, 0x00, 0xb2, 0x88, 0xbb, 0xc5,
297 0xbc, 0x4a, 0xbe, 0x36, 0xc2, 0x88, 0xc5, 0xc0,
298 0xc6, 0xda, 0xe9, 0x26, 0xeb, 0x00
299};
300static const u8 n4_tas5130a[] = {
301 0x80, 0x3c, 0x81, 0x68, 0x83, 0xa0, 0x84, 0x20,
302 0x8a, 0x68, 0x8b, 0x58, 0x8c, 0x88, 0x8e, 0xb4,
303 0x8f, 0x24, 0xa1, 0xb1, 0xa2, 0x30, 0xa5, 0x10,
304 0xa6, 0x4a, 0xae, 0x03, 0xb1, 0x44, 0xb2, 0x08,
305 0xb7, 0x06, 0xb9, 0xe7, 0xbb, 0xc4, 0xbc, 0x4a,
306 0xbe, 0x36, 0xbf, 0xff, 0xc2, 0x88, 0xc5, 0xc8,
307 0xc6, 0xda
308};
309
275static const struct additional_sensor_data sensor_data[] = { 310static const struct additional_sensor_data sensor_data[] = {
276 { /* OM6802 */ 311 { /* 0: OM6802 */
312 .n3 =
313 {0x61, 0x68, 0x65, 0x0a, 0x60, 0x04},
314 .n4 = n4_om6802,
315 .n4sz = sizeof n4_om6802,
316 .reg80 = 0x3c,
317 .reg8e = 0x33,
318 .nset8 = {0xa8, 0xf0, 0xc6, 0x88, 0xc0, 0x00},
277 .data1 = 319 .data1 =
278 {0xc2, 0x28, 0x0f, 0x22, 0xcd, 0x27, 0x2c, 0x06, 320 {0xc2, 0x28, 0x0f, 0x22, 0xcd, 0x27, 0x2c, 0x06,
279 0xb3, 0xfc}, 321 0xb3, 0xfc},
280 .data2 = 322 .data2 =
281 {0x80, 0xff, 0xff, 0x80, 0xff, 0xff, 0x80, 0xff, 323 {0x80, 0xff, 0xff, 0x80, 0xff, 0xff, 0x80, 0xff,
282 0xff}, 324 0xff},
325 .data3 =
326 {0x80, 0xff, 0xff, 0x80, 0xff, 0xff, 0x80, 0xff,
327 0xff},
283 .data4 = /*Freq (50/60Hz). Splitted for test purpose */ 328 .data4 = /*Freq (50/60Hz). Splitted for test purpose */
284 {0x66, 0xca, 0xa8, 0xf0}, 329 {0x66, 0xca, 0xa8, 0xf0},
285 .data5 = /* this could be removed later */ 330 .data5 = /* this could be removed later */
@@ -287,13 +332,23 @@ static const struct additional_sensor_data sensor_data[] = {
287 .stream = 332 .stream =
288 {0x0b, 0x04, 0x0a, 0x78}, 333 {0x0b, 0x04, 0x0a, 0x78},
289 }, 334 },
290 { /* OTHER */ 335 { /* 1: OTHER */
336 .n3 =
337 {0x61, 0xc2, 0x65, 0x88, 0x60, 0x00},
338 .n4 = n4_other,
339 .n4sz = sizeof n4_other,
340 .reg80 = 0xac,
341 .reg8e = 0xb8,
342 .nset8 = {0xa8, 0xa8, 0xc6, 0xda, 0xc0, 0x00},
291 .data1 = 343 .data1 =
292 {0xc1, 0x48, 0x04, 0x1b, 0xca, 0x2e, 0x33, 0x3a, 344 {0xc1, 0x48, 0x04, 0x1b, 0xca, 0x2e, 0x33, 0x3a,
293 0xe8, 0xfc}, 345 0xe8, 0xfc},
294 .data2 = 346 .data2 =
295 {0x4e, 0x9c, 0xec, 0x40, 0x80, 0xc0, 0x48, 0x96, 347 {0x4e, 0x9c, 0xec, 0x40, 0x80, 0xc0, 0x48, 0x96,
296 0xd9}, 348 0xd9},
349 .data3 =
350 {0x4e, 0x9c, 0xec, 0x40, 0x80, 0xc0, 0x48, 0x96,
351 0xd9},
297 .data4 = 352 .data4 =
298 {0x66, 0x00, 0xa8, 0xa8}, 353 {0x66, 0x00, 0xa8, 0xa8},
299 .data5 = 354 .data5 =
@@ -301,13 +356,23 @@ static const struct additional_sensor_data sensor_data[] = {
301 .stream = 356 .stream =
302 {0x0b, 0x04, 0x0a, 0x00}, 357 {0x0b, 0x04, 0x0a, 0x00},
303 }, 358 },
304 { /* TAS5130A */ 359 { /* 2: TAS5130A */
360 .n3 =
361 {0x61, 0xc2, 0x65, 0x0d, 0x60, 0x08},
362 .n4 = n4_tas5130a,
363 .n4sz = sizeof n4_tas5130a,
364 .reg80 = 0x3c,
365 .reg8e = 0xb4,
366 .nset8 = {0xa8, 0xf0, 0xc6, 0xda, 0xc0, 0x00},
305 .data1 = 367 .data1 =
306 {0xbb, 0x28, 0x10, 0x10, 0xbb, 0x28, 0x1e, 0x27, 368 {0xbb, 0x28, 0x10, 0x10, 0xbb, 0x28, 0x1e, 0x27,
307 0xc8, 0xfc}, 369 0xc8, 0xfc},
308 .data2 = 370 .data2 =
309 {0x60, 0xa8, 0xe0, 0x60, 0xa8, 0xe0, 0x60, 0xa8, 371 {0x60, 0xa8, 0xe0, 0x60, 0xa8, 0xe0, 0x60, 0xa8,
310 0xe0}, 372 0xe0},
373 .data3 =
374 {0x60, 0xa8, 0xe0, 0x60, 0xa8, 0xe0, 0x60, 0xa8,
375 0xe0},
311 .data4 = /* Freq (50/60Hz). Splitted for test purpose */ 376 .data4 = /* Freq (50/60Hz). Splitted for test purpose */
312 {0x66, 0x00, 0xa8, 0xe8}, 377 {0x66, 0x00, 0xa8, 0xe8},
313 .data5 = 378 .data5 =
@@ -364,7 +429,7 @@ static const u8 gamma_table[GAMMA_MAX][17] = {
364 {0x00, 0x18, 0x2b, 0x44, 0x60, 0x70, 0x80, 0x8e, /* 10 */ 429 {0x00, 0x18, 0x2b, 0x44, 0x60, 0x70, 0x80, 0x8e, /* 10 */
365 0x9c, 0xaa, 0xb7, 0xc4, 0xd0, 0xd8, 0xe2, 0xf0, 430 0x9c, 0xaa, 0xb7, 0xc4, 0xd0, 0xd8, 0xe2, 0xf0,
366 0xff}, 431 0xff},
367 {0x00, 0x1a, 0x34, 0x52, 0x66, 0x7e, 0x8D, 0x9B, /* 11 */ 432 {0x00, 0x1a, 0x34, 0x52, 0x66, 0x7e, 0x8d, 0x9b, /* 11 */
368 0xa8, 0xb4, 0xc0, 0xcb, 0xd6, 0xe1, 0xeb, 0xf5, 433 0xa8, 0xb4, 0xc0, 0xcb, 0xd6, 0xe1, 0xeb, 0xf5,
369 0xff}, 434 0xff},
370 {0x00, 0x3f, 0x5a, 0x6e, 0x7f, 0x8e, 0x9c, 0xa8, /* 12 */ 435 {0x00, 0x3f, 0x5a, 0x6e, 0x7f, 0x8e, 0x9c, 0xa8, /* 12 */
@@ -385,8 +450,6 @@ static const u8 tas5130a_sensor_init[][8] = {
385 {0x62, 0x08, 0x63, 0x70, 0x64, 0x1d, 0x60, 0x09}, 450 {0x62, 0x08, 0x63, 0x70, 0x64, 0x1d, 0x60, 0x09},
386 {0x62, 0x20, 0x63, 0x01, 0x64, 0x02, 0x60, 0x09}, 451 {0x62, 0x20, 0x63, 0x01, 0x64, 0x02, 0x60, 0x09},
387 {0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09}, 452 {0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09},
388 {0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09},
389 {},
390}; 453};
391 454
392static u8 sensor_reset[] = {0x61, 0x68, 0x62, 0xff, 0x60, 0x07}; 455static u8 sensor_reset[] = {0x61, 0x68, 0x62, 0xff, 0x60, 0x07};
@@ -633,10 +696,10 @@ static int sd_init(struct gspca_dev *gspca_dev)
633 * but wont hurt anyway, and can help someone with similar webcam 696 * but wont hurt anyway, and can help someone with similar webcam
634 * to see the initial parameters.*/ 697 * to see the initial parameters.*/
635 struct sd *sd = (struct sd *) gspca_dev; 698 struct sd *sd = (struct sd *) gspca_dev;
699 const struct additional_sensor_data *sensor;
636 int i; 700 int i;
637 u16 sensor_id; 701 u16 sensor_id;
638 u8 test_byte = 0; 702 u8 test_byte = 0;
639 u16 reg80, reg8e;
640 703
641 static const u8 read_indexs[] = 704 static const u8 read_indexs[] =
642 { 0x0a, 0x0b, 0x66, 0x80, 0x81, 0x8e, 0x8f, 0xa5, 705 { 0x0a, 0x0b, 0x66, 0x80, 0x81, 0x8e, 0x8f, 0xa5,
@@ -645,37 +708,6 @@ static int sd_init(struct gspca_dev *gspca_dev)
645 {0x08, 0x03, 0x09, 0x03, 0x12, 0x04}; 708 {0x08, 0x03, 0x09, 0x03, 0x12, 0x04};
646 static const u8 n2[] = 709 static const u8 n2[] =
647 {0x08, 0x00}; 710 {0x08, 0x00};
648 static const u8 n3[6] =
649 {0x61, 0x68, 0x65, 0x0a, 0x60, 0x04};
650 static const u8 n3_other[6] =
651 {0x61, 0xc2, 0x65, 0x88, 0x60, 0x00};
652 static const u8 n4[] =
653 {0x09, 0x01, 0x12, 0x04, 0x66, 0x8a, 0x80, 0x3c,
654 0x81, 0x22, 0x84, 0x50, 0x8a, 0x78, 0x8b, 0x68,
655 0x8c, 0x88, 0x8e, 0x33, 0x8f, 0x24, 0xaa, 0xb1,
656 0xa2, 0x60, 0xa5, 0x30, 0xa6, 0x3a, 0xa8, 0xe8,
657 0xae, 0x05, 0xb1, 0x00, 0xbb, 0x04, 0xbc, 0x48,
658 0xbe, 0x36, 0xc6, 0x88, 0xe9, 0x00, 0xc5, 0xc0,
659 0x65, 0x0a, 0xbb, 0x86, 0xaf, 0x58, 0xb0, 0x68,
660 0x87, 0x40, 0x89, 0x2b, 0x8d, 0xff, 0x83, 0x40,
661 0xac, 0x84, 0xad, 0x86, 0xaf, 0x46};
662 static const u8 n4_other[] =
663 {0x66, 0x00, 0x7f, 0x00, 0x80, 0xac, 0x81, 0x69,
664 0x84, 0x40, 0x85, 0x70, 0x86, 0x20, 0x8a, 0x68,
665 0x8b, 0x58, 0x8c, 0x88, 0x8d, 0xff, 0x8e, 0xb8,
666 0x8f, 0x28, 0xa2, 0x60, 0xa5, 0x40, 0xa8, 0xa8,
667 0xac, 0x84, 0xad, 0x84, 0xae, 0x24, 0xaf, 0x56,
668 0xb0, 0x68, 0xb1, 0x00, 0xb2, 0x88, 0xbb, 0xc5,
669 0xbc, 0x4a, 0xbe, 0x36, 0xc2, 0x88, 0xc5, 0xc0,
670 0xc6, 0xda, 0xe9, 0x26, 0xeb, 0x00};
671 static const u8 nset8[6] =
672 { 0xa8, 0xf0, 0xc6, 0x88, 0xc0, 0x00 };
673 static const u8 nset8_other[6] =
674 { 0xa8, 0xa8, 0xc6, 0xda, 0xc0, 0x00 };
675 static const u8 nset9[4] =
676 { 0x0b, 0x04, 0x0a, 0x78 };
677 static const u8 nset9_other[4] =
678 { 0x0b, 0x04, 0x0a, 0x00 };
679 711
680 sensor_id = (reg_r(gspca_dev, 0x06) << 8) 712 sensor_id = (reg_r(gspca_dev, 0x06) << 8)
681 | reg_r(gspca_dev, 0x07); 713 | reg_r(gspca_dev, 0x07);
@@ -709,8 +741,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
709 } 741 }
710 if (i < 0) { 742 if (i < 0) {
711 err("Bad sensor reset %02x", test_byte); 743 err("Bad sensor reset %02x", test_byte);
712/* return -EIO; */ 744 return -EIO;
713/*fixme: test - continue */
714 } 745 }
715 reg_w_buf(gspca_dev, n2, sizeof n2); 746 reg_w_buf(gspca_dev, n2, sizeof n2);
716 } 747 }
@@ -723,31 +754,17 @@ static int sd_init(struct gspca_dev *gspca_dev)
723 i++; 754 i++;
724 } 755 }
725 756
726 if (sd->sensor != SENSOR_OTHER) { 757 sensor = &sensor_data[sd->sensor];
727 reg_w_buf(gspca_dev, n3, sizeof n3); 758 reg_w_buf(gspca_dev, sensor->n3, sizeof sensor->n3);
728 reg_w_buf(gspca_dev, n4, sizeof n4); 759 reg_w_buf(gspca_dev, sensor->n4, sensor->n4sz);
729 reg_r(gspca_dev, 0x0080);
730 reg_w(gspca_dev, 0x2c80);
731 reg80 = 0x3880;
732 reg8e = 0x338e;
733 } else {
734 reg_w_buf(gspca_dev, n3_other, sizeof n3_other);
735 reg_w_buf(gspca_dev, n4_other, sizeof n4_other);
736 sd->gamma = 5;
737 reg80 = 0xac80;
738 reg8e = 0xb88e;
739 }
740 760
741 reg_w_ixbuf(gspca_dev, 0xd0, sensor_data[sd->sensor].data1, 761 reg_w_ixbuf(gspca_dev, 0xd0, sensor->data1, sizeof sensor->data1);
742 sizeof sensor_data[sd->sensor].data1); 762 reg_w_ixbuf(gspca_dev, 0xc7, sensor->data2, sizeof sensor->data2);
743 reg_w_ixbuf(gspca_dev, 0xc7, sensor_data[sd->sensor].data2, 763 reg_w_ixbuf(gspca_dev, 0xe0, sensor->data3, sizeof sensor->data3);
744 sizeof sensor_data[sd->sensor].data2);
745 reg_w_ixbuf(gspca_dev, 0xe0, sensor_data[sd->sensor].data2,
746 sizeof sensor_data[sd->sensor].data2);
747 764
748 reg_w(gspca_dev, reg80); 765 reg_w(gspca_dev, (sensor->reg80 << 8) + 0x80);
749 reg_w(gspca_dev, reg80); 766 reg_w(gspca_dev, (sensor->reg80 << 8) + 0x80);
750 reg_w(gspca_dev, reg8e); 767 reg_w(gspca_dev, (sensor->reg8e << 8) + 0x8e);
751 768
752 setbrightness(gspca_dev); 769 setbrightness(gspca_dev);
753 setcontrast(gspca_dev); 770 setcontrast(gspca_dev);
@@ -760,25 +777,14 @@ static int sd_init(struct gspca_dev *gspca_dev)
760 reg_w(gspca_dev, 0x2088); 777 reg_w(gspca_dev, 0x2088);
761 reg_w(gspca_dev, 0x2089); 778 reg_w(gspca_dev, 0x2089);
762 779
763 reg_w_buf(gspca_dev, sensor_data[sd->sensor].data4, 780 reg_w_buf(gspca_dev, sensor->data4, sizeof sensor->data4);
764 sizeof sensor_data[sd->sensor].data4); 781 reg_w_buf(gspca_dev, sensor->data5, sizeof sensor->data5);
765 reg_w_buf(gspca_dev, sensor_data[sd->sensor].data5, 782 reg_w_buf(gspca_dev, sensor->nset8, sizeof sensor->nset8);
766 sizeof sensor_data[sd->sensor].data5); 783 reg_w_buf(gspca_dev, sensor->stream, sizeof sensor->stream);
767 if (sd->sensor != SENSOR_OTHER) {
768 reg_w_buf(gspca_dev, nset8, sizeof nset8);
769 reg_w_buf(gspca_dev, nset9, sizeof nset9);
770 reg_w(gspca_dev, 0x2880);
771 } else {
772 reg_w_buf(gspca_dev, nset8_other, sizeof nset8_other);
773 reg_w_buf(gspca_dev, nset9_other, sizeof nset9_other);
774 }
775 784
776 reg_w_ixbuf(gspca_dev, 0xd0, sensor_data[sd->sensor].data1, 785 reg_w_ixbuf(gspca_dev, 0xd0, sensor->data1, sizeof sensor->data1);
777 sizeof sensor_data[sd->sensor].data1); 786 reg_w_ixbuf(gspca_dev, 0xc7, sensor->data2, sizeof sensor->data2);
778 reg_w_ixbuf(gspca_dev, 0xc7, sensor_data[sd->sensor].data2, 787 reg_w_ixbuf(gspca_dev, 0xe0, sensor->data3, sizeof sensor->data3);
779 sizeof sensor_data[sd->sensor].data2);
780 reg_w_ixbuf(gspca_dev, 0xe0, sensor_data[sd->sensor].data2,
781 sizeof sensor_data[sd->sensor].data2);
782 788
783 return 0; 789 return 0;
784} 790}
@@ -828,7 +834,6 @@ static void setlightfreq(struct gspca_dev *gspca_dev)
828 * i added some module parameters for test with some users */ 834 * i added some module parameters for test with some users */
829static void poll_sensor(struct gspca_dev *gspca_dev) 835static void poll_sensor(struct gspca_dev *gspca_dev)
830{ 836{
831 struct sd *sd = (struct sd *) gspca_dev;
832 static const u8 poll1[] = 837 static const u8 poll1[] =
833 {0x67, 0x05, 0x68, 0x81, 0x69, 0x80, 0x6a, 0x82, 838 {0x67, 0x05, 0x68, 0x81, 0x69, 0x80, 0x6a, 0x82,
834 0x6b, 0x68, 0x6c, 0x69, 0x72, 0xd9, 0x73, 0x34, 839 0x6b, 0x68, 0x6c, 0x69, 0x72, 0xd9, 0x73, 0x34,
@@ -844,24 +849,23 @@ static void poll_sensor(struct gspca_dev *gspca_dev)
844 0xa1, 0xb1, 0xda, 0x6b, 0xdb, 0x98, 0xdf, 0x0c, 849 0xa1, 0xb1, 0xda, 0x6b, 0xdb, 0x98, 0xdf, 0x0c,
845 0xc2, 0x80, 0xc3, 0x10}; 850 0xc2, 0x80, 0xc3, 0x10};
846 851
847 if (sd->sensor == SENSOR_OM6802) { 852 PDEBUG(D_STREAM, "[Sensor requires polling]");
848 PDEBUG(D_STREAM, "[Sensor requires polling]"); 853 reg_w_buf(gspca_dev, poll1, sizeof poll1);
849 reg_w_buf(gspca_dev, poll1, sizeof poll1); 854 reg_w_buf(gspca_dev, poll2, sizeof poll2);
850 reg_w_buf(gspca_dev, poll2, sizeof poll2); 855 reg_w_buf(gspca_dev, poll3, sizeof poll3);
851 reg_w_buf(gspca_dev, poll3, sizeof poll3); 856 reg_w_buf(gspca_dev, poll4, sizeof poll4);
852 reg_w_buf(gspca_dev, poll4, sizeof poll4);
853 }
854} 857}
855 858
856static int sd_start(struct gspca_dev *gspca_dev) 859static int sd_start(struct gspca_dev *gspca_dev)
857{ 860{
858 struct sd *sd = (struct sd *) gspca_dev; 861 struct sd *sd = (struct sd *) gspca_dev;
862 const struct additional_sensor_data *sensor;
859 int i, mode; 863 int i, mode;
860 u8 t2[] = { 0x07, 0x00, 0x0d, 0x60, 0x0e, 0x80 }; 864 u8 t2[] = { 0x07, 0x00, 0x0d, 0x60, 0x0e, 0x80 };
861 static const u8 t3[] = 865 static const u8 t3[] =
862 { 0x07, 0x00, 0x88, 0x02, 0x06, 0x00, 0xe7, 0x01 }; 866 { 0x07, 0x00, 0x88, 0x02, 0x06, 0x00, 0xe7, 0x01 };
863 867
864 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode]. priv; 868 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
865 switch (mode) { 869 switch (mode) {
866 case 0: /* 640x480 (0x00) */ 870 case 0: /* 640x480 (0x00) */
867 break; 871 break;
@@ -889,34 +893,33 @@ static int sd_start(struct gspca_dev *gspca_dev)
889 default: 893 default:
890/* case SENSOR_TAS5130A: */ 894/* case SENSOR_TAS5130A: */
891 i = 0; 895 i = 0;
892 while (tas5130a_sensor_init[i][0] != 0) { 896 for (;;) {
893 reg_w_buf(gspca_dev, tas5130a_sensor_init[i], 897 reg_w_buf(gspca_dev, tas5130a_sensor_init[i],
894 sizeof tas5130a_sensor_init[0]); 898 sizeof tas5130a_sensor_init[0]);
899 if (i >= ARRAY_SIZE(tas5130a_sensor_init) - 1)
900 break;
895 i++; 901 i++;
896 } 902 }
897 reg_w(gspca_dev, 0x3c80); 903 reg_w(gspca_dev, 0x3c80);
898 /* just in case and to keep sync with logs (for mine) */ 904 /* just in case and to keep sync with logs (for mine) */
899 reg_w_buf(gspca_dev, tas5130a_sensor_init[3], 905 reg_w_buf(gspca_dev, tas5130a_sensor_init[i],
900 sizeof tas5130a_sensor_init[0]); 906 sizeof tas5130a_sensor_init[0]);
901 reg_w(gspca_dev, 0x3c80); 907 reg_w(gspca_dev, 0x3c80);
902 break; 908 break;
903 } 909 }
904 reg_w_buf(gspca_dev, sensor_data[sd->sensor].data4, 910 sensor = &sensor_data[sd->sensor];
905 sizeof sensor_data[sd->sensor].data4); 911 reg_w_buf(gspca_dev, sensor->data4, sizeof sensor->data4);
906 reg_r(gspca_dev, 0x0012); 912 reg_r(gspca_dev, 0x0012);
907 reg_w_buf(gspca_dev, t2, sizeof t2); 913 reg_w_buf(gspca_dev, t2, sizeof t2);
908 reg_w_ixbuf(gspca_dev, 0xb3, t3, sizeof t3); 914 reg_w_ixbuf(gspca_dev, 0xb3, t3, sizeof t3);
909 reg_w(gspca_dev, 0x0013); 915 reg_w(gspca_dev, 0x0013);
910 msleep(15); 916 msleep(15);
911 reg_w_buf(gspca_dev, sensor_data[sd->sensor].stream, 917 reg_w_buf(gspca_dev, sensor->stream, sizeof sensor->stream);
912 sizeof sensor_data[sd->sensor].stream); 918 reg_w_buf(gspca_dev, sensor->stream, sizeof sensor->stream);
913 poll_sensor(gspca_dev); 919
920 if (sd->sensor == SENSOR_OM6802)
921 poll_sensor(gspca_dev);
914 922
915 /* restart on each start, just in case, sometimes regs goes wrong
916 * when using controls from app */
917 setbrightness(gspca_dev);
918 setcontrast(gspca_dev);
919 setcolors(gspca_dev);
920 return 0; 923 return 0;
921} 924}
922 925
@@ -926,10 +929,9 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
926 929
927 reg_w_buf(gspca_dev, sensor_data[sd->sensor].stream, 930 reg_w_buf(gspca_dev, sensor_data[sd->sensor].stream,
928 sizeof sensor_data[sd->sensor].stream); 931 sizeof sensor_data[sd->sensor].stream);
929 msleep(20);
930 reg_w_buf(gspca_dev, sensor_data[sd->sensor].stream, 932 reg_w_buf(gspca_dev, sensor_data[sd->sensor].stream,
931 sizeof sensor_data[sd->sensor].stream); 933 sizeof sensor_data[sd->sensor].stream);
932 if (sd->sensor != SENSOR_OTHER) { 934 if (sd->sensor == SENSOR_OM6802) {
933 msleep(20); 935 msleep(20);
934 reg_w(gspca_dev, 0x0309); 936 reg_w(gspca_dev, 0x0309);
935 } 937 }
diff --git a/drivers/media/video/gspca/tv8532.c b/drivers/media/video/gspca/tv8532.c
index 9f243d7e3110..4b44dde9f8b8 100644
--- a/drivers/media/video/gspca/tv8532.c
+++ b/drivers/media/video/gspca/tv8532.c
@@ -426,7 +426,7 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
426 gspca_frame_add(gspca_dev, packet_type0, 426 gspca_frame_add(gspca_dev, packet_type0,
427 frame, data + 2, gspca_dev->width); 427 frame, data + 2, gspca_dev->width);
428 gspca_frame_add(gspca_dev, packet_type1, 428 gspca_frame_add(gspca_dev, packet_type1,
429 frame, data + gspca_dev->width + 6, gspca_dev->width); 429 frame, data + gspca_dev->width + 5, gspca_dev->width);
430} 430}
431 431
432static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) 432static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
diff --git a/drivers/media/video/gspca/vc032x.c b/drivers/media/video/gspca/vc032x.c
index 26dd155efcc3..619250e70718 100644
--- a/drivers/media/video/gspca/vc032x.c
+++ b/drivers/media/video/gspca/vc032x.c
@@ -32,14 +32,14 @@ MODULE_LICENSE("GPL");
32struct sd { 32struct sd {
33 struct gspca_dev gspca_dev; /* !! must be the first item */ 33 struct gspca_dev gspca_dev; /* !! must be the first item */
34 34
35 __u8 hflip; 35 u8 hflip;
36 __u8 vflip; 36 u8 vflip;
37 __u8 lightfreq; 37 u8 lightfreq;
38 __u8 sharpness; 38 u8 sharpness;
39 39
40 u8 image_offset; 40 u8 image_offset;
41 41
42 char bridge; 42 u8 bridge;
43#define BRIDGE_VC0321 0 43#define BRIDGE_VC0321 0
44#define BRIDGE_VC0323 1 44#define BRIDGE_VC0323 1
45 u8 sensor; 45 u8 sensor;
@@ -52,6 +52,10 @@ struct sd {
52#define SENSOR_OV7670 6 52#define SENSOR_OV7670 6
53#define SENSOR_PO1200 7 53#define SENSOR_PO1200 7
54#define SENSOR_PO3130NC 8 54#define SENSOR_PO3130NC 8
55 u8 flags;
56#define FL_SAMSUNG 0x01 /* SamsungQ1 (2 sensors) */
57#define FL_HFLIP 0x02 /* mirrored by default */
58#define FL_VFLIP 0x04 /* vertical flipped by default */
55}; 59};
56 60
57/* V4L2 controls supported by the driver */ 61/* V4L2 controls supported by the driver */
@@ -65,7 +69,7 @@ static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
65static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val); 69static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
66 70
67static struct ctrl sd_ctrls[] = { 71static struct ctrl sd_ctrls[] = {
68/* next 2 controls work with ov7660 and ov7670 only */ 72/* next 2 controls work with some sensors only */
69#define HFLIP_IDX 0 73#define HFLIP_IDX 0
70 { 74 {
71 { 75 {
@@ -152,9 +156,9 @@ static const struct v4l2_pix_format vc0323_mode[] = {
152 .sizeimage = 640 * 480 * 3 / 8 + 590, 156 .sizeimage = 640 * 480 * 3 / 8 + 590,
153 .colorspace = V4L2_COLORSPACE_JPEG, 157 .colorspace = V4L2_COLORSPACE_JPEG,
154 .priv = 0}, 158 .priv = 0},
155 {1280, 1024, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, /* mi13x0_soc only */ 159 {1280, 960, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, /* mi1310_soc only */
156 .bytesperline = 1280, 160 .bytesperline = 1280,
157 .sizeimage = 1280 * 1024 * 1 / 4 + 590, 161 .sizeimage = 1280 * 960 * 3 / 8 + 590,
158 .colorspace = V4L2_COLORSPACE_JPEG, 162 .colorspace = V4L2_COLORSPACE_JPEG,
159 .priv = 2}, 163 .priv = 2},
160}; 164};
@@ -188,11 +192,11 @@ static const struct v4l2_pix_format svga_mode[] = {
188#define OV7660_MVFP_MIRROR 0x20 192#define OV7660_MVFP_MIRROR 0x20
189#define OV7660_MVFP_VFLIP 0x10 193#define OV7660_MVFP_VFLIP 0x10
190 194
191static const __u8 mi0360_matrix[9] = { 195static const u8 mi0360_matrix[9] = {
192 0x50, 0xf8, 0xf8, 0xf5, 0x50, 0xfb, 0xff, 0xf1, 0x50 196 0x50, 0xf8, 0xf8, 0xf5, 0x50, 0xfb, 0xff, 0xf1, 0x50
193}; 197};
194 198
195static const __u8 mi0360_initVGA_JPG[][4] = { 199static const u8 mi0360_initVGA_JPG[][4] = {
196 {0xb0, 0x03, 0x19, 0xcc}, 200 {0xb0, 0x03, 0x19, 0xcc},
197 {0xb0, 0x04, 0x02, 0xcc}, 201 {0xb0, 0x04, 0x02, 0xcc},
198 {0xb3, 0x00, 0x24, 0xcc}, 202 {0xb3, 0x00, 0x24, 0xcc},
@@ -301,7 +305,7 @@ static const __u8 mi0360_initVGA_JPG[][4] = {
301 {0xb3, 0x5c, 0x01, 0xcc}, 305 {0xb3, 0x5c, 0x01, 0xcc},
302 {} 306 {}
303}; 307};
304static const __u8 mi0360_initQVGA_JPG[][4] = { 308static const u8 mi0360_initQVGA_JPG[][4] = {
305 {0xb0, 0x03, 0x19, 0xcc}, 309 {0xb0, 0x03, 0x19, 0xcc},
306 {0xb0, 0x04, 0x02, 0xcc}, 310 {0xb0, 0x04, 0x02, 0xcc},
307 {0xb3, 0x00, 0x24, 0xcc}, 311 {0xb3, 0x00, 0x24, 0xcc},
@@ -421,211 +425,95 @@ static const __u8 mi0360_initQVGA_JPG[][4] = {
421 {} 425 {}
422}; 426};
423 427
424static const __u8 mi1310_socinitVGA_JPG[][4] = { 428static const u8 mi1310_socinitVGA_JPG[][4] = {
425 {0xb0, 0x03, 0x19, 0xcc}, 429 {0xb0, 0x03, 0x19, 0xcc},
426 {0xb0, 0x04, 0x02, 0xcc}, 430 {0xb0, 0x04, 0x02, 0xcc},
427 {0xb3, 0x00, 0x24, 0xcc}, 431 {0xb3, 0x00, 0x64, 0xcc},
428 {0xb3, 0x00, 0x25, 0xcc}, 432 {0xb3, 0x00, 0x65, 0xcc},
429 {0xb3, 0x05, 0x01, 0xcc}, 433 {0xb3, 0x05, 0x00, 0xcc},
430 {0xb3, 0x06, 0x03, 0xcc}, 434 {0xb3, 0x06, 0x00, 0xcc},
431 {0xb3, 0x5c, 0x01, 0xcc},
432 {0xb3, 0x08, 0x01, 0xcc}, 435 {0xb3, 0x08, 0x01, 0xcc},
433 {0xb3, 0x09, 0x0c, 0xcc}, 436 {0xb3, 0x09, 0x0c, 0xcc},
434 {0xb3, 0x34, 0x02, 0xcc}, 437 {0xb3, 0x34, 0x02, 0xcc},
435 {0xb3, 0x35, 0xdd, 0xcc}, 438 {0xb3, 0x35, 0xdd, 0xcc},
439 {0xb3, 0x02, 0x00, 0xcc},
436 {0xb3, 0x03, 0x0a, 0xcc}, 440 {0xb3, 0x03, 0x0a, 0xcc},
437 {0xb3, 0x04, 0x0d, 0xcc}, 441 {0xb3, 0x04, 0x05, 0xcc},
438 {0xb3, 0x20, 0x00, 0xcc}, 442 {0xb3, 0x20, 0x00, 0xcc},
439 {0xb3, 0x21, 0x00, 0xcc}, 443 {0xb3, 0x21, 0x00, 0xcc},
440 {0xb3, 0x22, 0x01, 0xcc}, 444 {0xb3, 0x22, 0x03, 0xcc},
441 {0xb3, 0x23, 0xe0, 0xcc}, 445 {0xb3, 0x23, 0xc0, 0xcc},
442 {0xb3, 0x14, 0x00, 0xcc}, 446 {0xb3, 0x14, 0x00, 0xcc},
443 {0xb3, 0x15, 0x00, 0xcc}, 447 {0xb3, 0x15, 0x00, 0xcc},
444 {0xb3, 0x16, 0x02, 0xcc}, 448 {0xb3, 0x16, 0x04, 0xcc},
445 {0xb3, 0x17, 0x7f, 0xcc}, 449 {0xb3, 0x17, 0xff, 0xcc},
446 {0xb8, 0x01, 0x7d, 0xcc}, 450 {0xb3, 0x00, 0x65, 0xcc},
447 {0xb8, 0x81, 0x09, 0xcc}, 451 {0xb8, 0x00, 0x00, 0xcc},
448 {0xb8, 0x27, 0x20, 0xcc}, 452 {0xbc, 0x00, 0xd0, 0xcc},
449 {0xb8, 0x26, 0x80, 0xcc}, 453 {0xbc, 0x01, 0x01, 0xcc},
450 {0xb3, 0x00, 0x25, 0xcc}, 454 {0xf0, 0x00, 0x02, 0xbb},
451 {0xb8, 0x00, 0x13, 0xcc}, 455 {0xc8, 0x9f, 0x0b, 0xbb},
452 {0xbc, 0x00, 0x71, 0xcc}, 456 {0x5b, 0x00, 0x01, 0xbb},
453 {0xb8, 0x81, 0x01, 0xcc}, 457 {0x2f, 0xde, 0x20, 0xbb},
454 {0xb8, 0x2c, 0x5a, 0xcc},
455 {0xb8, 0x2d, 0xff, 0xcc},
456 {0xb8, 0x2e, 0xee, 0xcc},
457 {0xb8, 0x2f, 0xfb, 0xcc},
458 {0xb8, 0x30, 0x52, 0xcc},
459 {0xb8, 0x31, 0xf8, 0xcc},
460 {0xb8, 0x32, 0xf1, 0xcc},
461 {0xb8, 0x33, 0xff, 0xcc},
462 {0xb8, 0x34, 0x54, 0xcc},
463 {0xb8, 0x35, 0x00, 0xcc},
464 {0xb8, 0x36, 0x00, 0xcc},
465 {0xb8, 0x37, 0x00, 0xcc},
466 {0xf0, 0x00, 0x00, 0xbb}, 458 {0xf0, 0x00, 0x00, 0xbb},
467 {0x00, 0x01, 0x00, 0xdd}, 459 {0x20, 0x03, 0x02, 0xbb}, /* h/v flip */
468 {0x0d, 0x00, 0x09, 0xbb},
469 {0x0d, 0x00, 0x08, 0xbb},
470 {0xf0, 0x00, 0x01, 0xbb}, 460 {0xf0, 0x00, 0x01, 0xbb},
471 {0x00, 0x01, 0x00, 0xdd}, 461 {0x05, 0x00, 0x07, 0xbb},
472 {0x06, 0x00, 0x14, 0xbb}, 462 {0x34, 0x00, 0x00, 0xbb},
473 {0x3a, 0x10, 0x00, 0xbb}, 463 {0x35, 0xff, 0x00, 0xbb},
474 {0x00, 0x00, 0x10, 0xdd}, 464 {0xdc, 0x07, 0x02, 0xbb},
475 {0x9b, 0x10, 0x00, 0xbb}, 465 {0xdd, 0x3c, 0x18, 0xbb},
476 {0x00, 0x00, 0x10, 0xdd}, 466 {0xde, 0x92, 0x6d, 0xbb},
467 {0xdf, 0xcd, 0xb1, 0xbb},
468 {0xe0, 0xff, 0xe7, 0xbb},
469 {0x06, 0xf0, 0x0d, 0xbb},
470 {0x06, 0x70, 0x0e, 0xbb},
471 {0x4c, 0x00, 0x01, 0xbb},
472 {0x4d, 0x00, 0x01, 0xbb},
473 {0xf0, 0x00, 0x02, 0xbb},
474 {0x2e, 0x0c, 0x55, 0xbb},
475 {0x21, 0xb6, 0x6e, 0xbb},
476 {0x36, 0x30, 0x10, 0xbb},
477 {0x37, 0x00, 0xc1, 0xbb},
477 {0xf0, 0x00, 0x00, 0xbb}, 478 {0xf0, 0x00, 0x00, 0xbb},
478 {0x00, 0x01, 0x00, 0xdd}, 479 {0x07, 0x00, 0x84, 0xbb},
479 {0x2b, 0x00, 0x28, 0xbb}, 480 {0x08, 0x02, 0x4a, 0xbb},
480 {0x2c, 0x00, 0x30, 0xbb}, 481 {0x05, 0x01, 0x10, 0xbb},
481 {0x2d, 0x00, 0x30, 0xbb}, 482 {0x06, 0x00, 0x39, 0xbb},
482 {0x2e, 0x00, 0x28, 0xbb}, 483 {0xf0, 0x00, 0x02, 0xbb},
483 {0x41, 0x00, 0xd7, 0xbb}, 484 {0x58, 0x02, 0x67, 0xbb},
484 {0x09, 0x02, 0x3a, 0xbb}, 485 {0x57, 0x02, 0x00, 0xbb},
485 {0x0c, 0x00, 0x00, 0xbb}, 486 {0x5a, 0x02, 0x67, 0xbb},
486 {0x20, 0x00, 0x00, 0xbb}, 487 {0x59, 0x02, 0x00, 0xbb},
487 {0x05, 0x00, 0x8c, 0xbb}, 488 {0x5c, 0x12, 0x0d, 0xbb},
488 {0x06, 0x00, 0x32, 0xbb}, 489 {0x5d, 0x16, 0x11, 0xbb},
489 {0x07, 0x00, 0xc6, 0xbb}, 490 {0x39, 0x06, 0x18, 0xbb},
490 {0x08, 0x00, 0x19, 0xbb}, 491 {0x3a, 0x06, 0x18, 0xbb},
491 {0x24, 0x80, 0x6f, 0xbb}, 492 {0x3b, 0x06, 0x18, 0xbb},
492 {0xc8, 0x00, 0x0f, 0xbb}, 493 {0x3c, 0x06, 0x18, 0xbb},
493 {0x20, 0x00, 0x0f, 0xbb}, 494 {0x64, 0x7b, 0x5b, 0xbb},
495 {0xf0, 0x00, 0x02, 0xbb},
496 {0x36, 0x30, 0x10, 0xbb},
497 {0x37, 0x00, 0xc0, 0xbb},
498 {0xbc, 0x0e, 0x00, 0xcc},
499 {0xbc, 0x0f, 0x05, 0xcc},
500 {0xbc, 0x10, 0xc0, 0xcc},
501 {0xbc, 0x11, 0x03, 0xcc},
494 {0xb6, 0x00, 0x00, 0xcc}, 502 {0xb6, 0x00, 0x00, 0xcc},
495 {0xb6, 0x03, 0x02, 0xcc}, 503 {0xb6, 0x03, 0x02, 0xcc},
496 {0xb6, 0x02, 0x80, 0xcc}, 504 {0xb6, 0x02, 0x80, 0xcc},
497 {0xb6, 0x05, 0x01, 0xcc}, 505 {0xb6, 0x05, 0x01, 0xcc},
498 {0xb6, 0x04, 0xe0, 0xcc}, 506 {0xb6, 0x04, 0xe0, 0xcc},
499 {0xb6, 0x12, 0x78, 0xcc}, 507 {0xb6, 0x12, 0xf8, 0xcc},
508 {0xb6, 0x13, 0x25, 0xcc},
500 {0xb6, 0x18, 0x02, 0xcc}, 509 {0xb6, 0x18, 0x02, 0xcc},
501 {0xb6, 0x17, 0x58, 0xcc}, 510 {0xb6, 0x17, 0x58, 0xcc},
502 {0xb6, 0x16, 0x00, 0xcc}, 511 {0xb6, 0x16, 0x00, 0xcc},
503 {0xb6, 0x22, 0x12, 0xcc}, 512 {0xb6, 0x22, 0x12, 0xcc},
504 {0xb6, 0x23, 0x0b, 0xcc}, 513 {0xb6, 0x23, 0x0b, 0xcc},
505 {0xb3, 0x02, 0x02, 0xcc},
506 {0xbf, 0xc0, 0x39, 0xcc},
507 {0xbf, 0xc1, 0x04, 0xcc},
508 {0xbf, 0xcc, 0x10, 0xcc},
509 {0xb9, 0x12, 0x00, 0xcc},
510 {0xb9, 0x13, 0x0a, 0xcc},
511 {0xb9, 0x14, 0x0a, 0xcc},
512 {0xb9, 0x15, 0x0a, 0xcc},
513 {0xb9, 0x16, 0x0a, 0xcc},
514 {0xb9, 0x18, 0x00, 0xcc},
515 {0xb9, 0x19, 0x0f, 0xcc},
516 {0xb9, 0x1a, 0x0f, 0xcc},
517 {0xb9, 0x1b, 0x0f, 0xcc},
518 {0xb9, 0x1c, 0x0f, 0xcc},
519 {0xb8, 0x8e, 0x00, 0xcc},
520 {0xb8, 0x8f, 0xff, 0xcc},
521 {0xb3, 0x01, 0x41, 0xcc},
522 {0x03, 0x03, 0xc0, 0xbb},
523 {0x06, 0x00, 0x10, 0xbb},
524 {0xb6, 0x12, 0xf8, 0xcc},
525 {0xb8, 0x0c, 0x20, 0xcc},
526 {0xb8, 0x0d, 0x70, 0xcc},
527 {0xb6, 0x13, 0x13, 0xcc},
528 {0x2f, 0x00, 0xC0, 0xbb},
529 {0xb8, 0xa0, 0x12, 0xcc},
530 {},
531};
532static const __u8 mi1310_socinitQVGA_JPG[][4] = {
533 {0xb0, 0x03, 0x19, 0xcc},
534 {0xb0, 0x04, 0x02, 0xcc},
535 {0xb3, 0x00, 0x24, 0xcc},
536 {0xb3, 0x00, 0x25, 0xcc},
537 {0xb3, 0x05, 0x01, 0xcc},
538 {0xb3, 0x06, 0x03, 0xcc},
539 {0xb3, 0x5c, 0x01, 0xcc},
540 {0xb3, 0x08, 0x01, 0xcc},
541 {0xb3, 0x09, 0x0c, 0xcc},
542 {0xb3, 0x34, 0x02, 0xcc},
543 {0xb3, 0x35, 0xdd, 0xcc},
544 {0xb3, 0x03, 0x0a, 0xcc},
545 {0xb3, 0x04, 0x0d, 0xcc},
546 {0xb3, 0x20, 0x00, 0xcc},
547 {0xb3, 0x21, 0x00, 0xcc},
548 {0xb3, 0x22, 0x01, 0xcc},
549 {0xb3, 0x23, 0xe0, 0xcc},
550 {0xb3, 0x14, 0x00, 0xcc},
551 {0xb3, 0x15, 0x00, 0xcc},
552 {0xb3, 0x16, 0x02, 0xcc},
553 {0xb3, 0x17, 0x7f, 0xcc},
554 {0xb8, 0x01, 0x7d, 0xcc},
555 {0xb8, 0x81, 0x09, 0xcc},
556 {0xb8, 0x27, 0x20, 0xcc},
557 {0xb8, 0x26, 0x80, 0xcc},
558 {0xb3, 0x00, 0x25, 0xcc},
559 {0xb8, 0x00, 0x13, 0xcc},
560 {0xbc, 0x00, 0xd1, 0xcc},
561 {0xb8, 0x81, 0x01, 0xcc},
562 {0xb8, 0x2c, 0x5a, 0xcc},
563 {0xb8, 0x2d, 0xff, 0xcc},
564 {0xb8, 0x2e, 0xee, 0xcc},
565 {0xb8, 0x2f, 0xfb, 0xcc},
566 {0xb8, 0x30, 0x52, 0xcc},
567 {0xb8, 0x31, 0xf8, 0xcc},
568 {0xb8, 0x32, 0xf1, 0xcc},
569 {0xb8, 0x33, 0xff, 0xcc},
570 {0xb8, 0x34, 0x54, 0xcc},
571 {0xb8, 0x35, 0x00, 0xcc},
572 {0xb8, 0x36, 0x00, 0xcc},
573 {0xb8, 0x37, 0x00, 0xcc},
574 {0xf0, 0x00, 0x00, 0xbb},
575 {0x00, 0x01, 0x00, 0xdd},
576 {0x0d, 0x00, 0x09, 0xbb},
577 {0x0d, 0x00, 0x08, 0xbb},
578 {0xf0, 0x00, 0x01, 0xbb},
579 {0x00, 0x01, 0x00, 0xdd},
580 {0x06, 0x00, 0x14, 0xbb},
581 {0x3a, 0x10, 0x00, 0xbb},
582 {0x00, 0x00, 0x10, 0xdd},
583 {0x9b, 0x10, 0x00, 0xbb},
584 {0x00, 0x00, 0x10, 0xdd},
585 {0xf0, 0x00, 0x00, 0xbb},
586 {0x00, 0x01, 0x00, 0xdd},
587 {0x2b, 0x00, 0x28, 0xbb},
588 {0x2c, 0x00, 0x30, 0xbb},
589 {0x2d, 0x00, 0x30, 0xbb},
590 {0x2e, 0x00, 0x28, 0xbb},
591 {0x41, 0x00, 0xd7, 0xbb},
592 {0x09, 0x02, 0x3a, 0xbb},
593 {0x0c, 0x00, 0x00, 0xbb},
594 {0x20, 0x00, 0x00, 0xbb},
595 {0x05, 0x00, 0x8c, 0xbb},
596 {0x06, 0x00, 0x32, 0xbb},
597 {0x07, 0x00, 0xc6, 0xbb},
598 {0x08, 0x00, 0x19, 0xbb},
599 {0x24, 0x80, 0x6f, 0xbb},
600 {0xc8, 0x00, 0x0f, 0xbb},
601 {0x20, 0x00, 0x0f, 0xbb},
602 {0xb6, 0x00, 0x00, 0xcc},
603 {0xb6, 0x03, 0x01, 0xcc},
604 {0xb6, 0x02, 0x40, 0xcc},
605 {0xb6, 0x05, 0x00, 0xcc},
606 {0xb6, 0x04, 0xf0, 0xcc},
607 {0xb6, 0x12, 0x78, 0xcc},
608 {0xb6, 0x18, 0x00, 0xcc},
609 {0xb6, 0x17, 0x96, 0xcc},
610 {0xb6, 0x16, 0x00, 0xcc},
611 {0xb6, 0x22, 0x12, 0xcc},
612 {0xb6, 0x23, 0x0b, 0xcc},
613 {0xb3, 0x02, 0x02, 0xcc},
614 {0xbf, 0xc0, 0x39, 0xcc}, 514 {0xbf, 0xc0, 0x39, 0xcc},
615 {0xbf, 0xc1, 0x04, 0xcc}, 515 {0xbf, 0xc1, 0x04, 0xcc},
616 {0xbf, 0xcc, 0x10, 0xcc}, 516 {0xbf, 0xcc, 0x00, 0xcc},
617 {0xb9, 0x12, 0x00, 0xcc},
618 {0xb9, 0x13, 0x0a, 0xcc},
619 {0xb9, 0x14, 0x0a, 0xcc},
620 {0xb9, 0x15, 0x0a, 0xcc},
621 {0xb9, 0x16, 0x0a, 0xcc},
622 {0xb9, 0x18, 0x00, 0xcc},
623 {0xb9, 0x19, 0x0f, 0xcc},
624 {0xb9, 0x1a, 0x0f, 0xcc},
625 {0xb9, 0x1b, 0x0f, 0xcc},
626 {0xb9, 0x1c, 0x0f, 0xcc},
627 {0xb8, 0x8e, 0x00, 0xcc},
628 {0xb8, 0x8f, 0xff, 0xcc},
629 {0xbc, 0x02, 0x18, 0xcc}, 517 {0xbc, 0x02, 0x18, 0xcc},
630 {0xbc, 0x03, 0x50, 0xcc}, 518 {0xbc, 0x03, 0x50, 0xcc},
631 {0xbc, 0x04, 0x18, 0xcc}, 519 {0xbc, 0x04, 0x18, 0xcc},
@@ -636,133 +524,335 @@ static const __u8 mi1310_socinitQVGA_JPG[][4] = {
636 {0xbc, 0x0a, 0x10, 0xcc}, 524 {0xbc, 0x0a, 0x10, 0xcc},
637 {0xbc, 0x0b, 0x00, 0xcc}, 525 {0xbc, 0x0b, 0x00, 0xcc},
638 {0xbc, 0x0c, 0x00, 0xcc}, 526 {0xbc, 0x0c, 0x00, 0xcc},
527 {0xb3, 0x5c, 0x01, 0xcc},
528 {0xf0, 0x00, 0x01, 0xbb},
529 {0x80, 0x00, 0x03, 0xbb},
530 {0x81, 0xc7, 0x14, 0xbb},
531 {0x82, 0xeb, 0xe8, 0xbb},
532 {0x83, 0xfe, 0xf4, 0xbb},
533 {0x84, 0xcd, 0x10, 0xbb},
534 {0x85, 0xf3, 0xee, 0xbb},
535 {0x86, 0xff, 0xf1, 0xbb},
536 {0x87, 0xcd, 0x10, 0xbb},
537 {0x88, 0xf3, 0xee, 0xbb},
538 {0x89, 0x01, 0xf1, 0xbb},
539 {0x8a, 0xe5, 0x17, 0xbb},
540 {0x8b, 0xe8, 0xe2, 0xbb},
541 {0x8c, 0xf7, 0xed, 0xbb},
542 {0x8d, 0x00, 0xff, 0xbb},
543 {0x8e, 0xec, 0x10, 0xbb},
544 {0x8f, 0xf0, 0xed, 0xbb},
545 {0x90, 0xf9, 0xf2, 0xbb},
546 {0x91, 0x00, 0x00, 0xbb},
547 {0x92, 0xe9, 0x0d, 0xbb},
548 {0x93, 0xf4, 0xf2, 0xbb},
549 {0x94, 0xfb, 0xf5, 0xbb},
550 {0x95, 0x00, 0xff, 0xbb},
551 {0xb6, 0x0f, 0x08, 0xbb},
552 {0xb7, 0x3d, 0x16, 0xbb},
553 {0xb8, 0x0c, 0x04, 0xbb},
554 {0xb9, 0x1c, 0x07, 0xbb},
555 {0xba, 0x0a, 0x03, 0xbb},
556 {0xbb, 0x1b, 0x09, 0xbb},
557 {0xbc, 0x17, 0x0d, 0xbb},
558 {0xbd, 0x23, 0x1d, 0xbb},
559 {0xbe, 0x00, 0x28, 0xbb},
560 {0xbf, 0x11, 0x09, 0xbb},
561 {0xc0, 0x16, 0x15, 0xbb},
562 {0xc1, 0x00, 0x1b, 0xbb},
563 {0xc2, 0x0e, 0x07, 0xbb},
564 {0xc3, 0x14, 0x10, 0xbb},
565 {0xc4, 0x00, 0x17, 0xbb},
566 {0x06, 0x74, 0x8e, 0xbb},
567 {0xf0, 0x00, 0x01, 0xbb},
568 {0x06, 0xf4, 0x8e, 0xbb},
569 {0x00, 0x00, 0x50, 0xdd},
570 {0x06, 0x74, 0x8e, 0xbb},
571 {0xf0, 0x00, 0x02, 0xbb},
572 {0x24, 0x50, 0x20, 0xbb},
573 {0xf0, 0x00, 0x02, 0xbb},
574 {0x34, 0x0c, 0x50, 0xbb},
639 {0xb3, 0x01, 0x41, 0xcc}, 575 {0xb3, 0x01, 0x41, 0xcc},
576 {0xf0, 0x00, 0x00, 0xbb},
577 {0x03, 0x03, 0xc0, 0xbb},
578 {},
579};
580static const u8 mi1310_socinitQVGA_JPG[][4] = {
581 {0xb0, 0x03, 0x19, 0xcc}, {0xb0, 0x04, 0x02, 0xcc},
582 {0xb3, 0x00, 0x64, 0xcc}, {0xb3, 0x00, 0x65, 0xcc},
583 {0xb3, 0x05, 0x00, 0xcc}, {0xb3, 0x06, 0x00, 0xcc},
584 {0xb3, 0x08, 0x01, 0xcc}, {0xb3, 0x09, 0x0c, 0xcc},
585 {0xb3, 0x34, 0x02, 0xcc}, {0xb3, 0x35, 0xdd, 0xcc},
586 {0xb3, 0x02, 0x00, 0xcc}, {0xb3, 0x03, 0x0a, 0xcc},
587 {0xb3, 0x04, 0x05, 0xcc}, {0xb3, 0x20, 0x00, 0xcc},
588 {0xb3, 0x21, 0x00, 0xcc}, {0xb3, 0x22, 0x03, 0xcc},
589 {0xb3, 0x23, 0xc0, 0xcc}, {0xb3, 0x14, 0x00, 0xcc},
590 {0xb3, 0x15, 0x00, 0xcc}, {0xb3, 0x16, 0x04, 0xcc},
591 {0xb3, 0x17, 0xff, 0xcc}, {0xb3, 0x00, 0x65, 0xcc},
592 {0xb8, 0x00, 0x00, 0xcc}, {0xbc, 0x00, 0xf0, 0xcc},
593 {0xbc, 0x01, 0x01, 0xcc}, {0xf0, 0x00, 0x02, 0xbb},
594 {0xc8, 0x9f, 0x0b, 0xbb}, {0x5b, 0x00, 0x01, 0xbb},
595 {0x2f, 0xde, 0x20, 0xbb}, {0xf0, 0x00, 0x00, 0xbb},
596 {0x20, 0x03, 0x02, 0xbb}, /* h/v flip */
597 {0xf0, 0x00, 0x01, 0xbb},
598 {0x05, 0x00, 0x07, 0xbb}, {0x34, 0x00, 0x00, 0xbb},
599 {0x35, 0xff, 0x00, 0xbb}, {0xdc, 0x07, 0x02, 0xbb},
600 {0xdd, 0x3c, 0x18, 0xbb}, {0xde, 0x92, 0x6d, 0xbb},
601 {0xdf, 0xcd, 0xb1, 0xbb}, {0xe0, 0xff, 0xe7, 0xbb},
602 {0x06, 0xf0, 0x0d, 0xbb}, {0x06, 0x70, 0x0e, 0xbb},
603 {0x4c, 0x00, 0x01, 0xbb}, {0x4d, 0x00, 0x01, 0xbb},
604 {0xf0, 0x00, 0x02, 0xbb}, {0x2e, 0x0c, 0x55, 0xbb},
605 {0x21, 0xb6, 0x6e, 0xbb}, {0x36, 0x30, 0x10, 0xbb},
606 {0x37, 0x00, 0xc1, 0xbb}, {0xf0, 0x00, 0x00, 0xbb},
607 {0x07, 0x00, 0x84, 0xbb}, {0x08, 0x02, 0x4a, 0xbb},
608 {0x05, 0x01, 0x10, 0xbb}, {0x06, 0x00, 0x39, 0xbb},
609 {0xf0, 0x00, 0x02, 0xbb}, {0x58, 0x02, 0x67, 0xbb},
610 {0x57, 0x02, 0x00, 0xbb}, {0x5a, 0x02, 0x67, 0xbb},
611 {0x59, 0x02, 0x00, 0xbb}, {0x5c, 0x12, 0x0d, 0xbb},
612 {0x5d, 0x16, 0x11, 0xbb}, {0x39, 0x06, 0x18, 0xbb},
613 {0x3a, 0x06, 0x18, 0xbb}, {0x3b, 0x06, 0x18, 0xbb},
614 {0x3c, 0x06, 0x18, 0xbb}, {0x64, 0x7b, 0x5b, 0xbb},
615 {0xf0, 0x00, 0x02, 0xbb}, {0x36, 0x30, 0x10, 0xbb},
616 {0x37, 0x00, 0xc0, 0xbb}, {0xbc, 0x0e, 0x00, 0xcc},
617 {0xbc, 0x0f, 0x05, 0xcc}, {0xbc, 0x10, 0xc0, 0xcc},
618 {0xbc, 0x11, 0x03, 0xcc}, {0xb6, 0x00, 0x00, 0xcc},
619 {0xb6, 0x03, 0x01, 0xcc}, {0xb6, 0x02, 0x40, 0xcc},
620 {0xb6, 0x05, 0x00, 0xcc}, {0xb6, 0x04, 0xf0, 0xcc},
621 {0xb6, 0x12, 0xf8, 0xcc}, {0xb6, 0x13, 0x25, 0xcc},
622 {0xb6, 0x18, 0x00, 0xcc}, {0xb6, 0x17, 0x96, 0xcc},
623 {0xb6, 0x16, 0x00, 0xcc}, {0xb6, 0x22, 0x12, 0xcc},
624 {0xb6, 0x23, 0x0b, 0xcc}, {0xbf, 0xc0, 0x39, 0xcc},
625 {0xbf, 0xc1, 0x04, 0xcc}, {0xbf, 0xcc, 0x00, 0xcc},
626 {0xb3, 0x5c, 0x01, 0xcc}, {0xf0, 0x00, 0x01, 0xbb},
627 {0x80, 0x00, 0x03, 0xbb}, {0x81, 0xc7, 0x14, 0xbb},
628 {0x82, 0xeb, 0xe8, 0xbb}, {0x83, 0xfe, 0xf4, 0xbb},
629 {0x84, 0xcd, 0x10, 0xbb}, {0x85, 0xf3, 0xee, 0xbb},
630 {0x86, 0xff, 0xf1, 0xbb}, {0x87, 0xcd, 0x10, 0xbb},
631 {0x88, 0xf3, 0xee, 0xbb}, {0x89, 0x01, 0xf1, 0xbb},
632 {0x8a, 0xe5, 0x17, 0xbb}, {0x8b, 0xe8, 0xe2, 0xbb},
633 {0x8c, 0xf7, 0xed, 0xbb}, {0x8d, 0x00, 0xff, 0xbb},
634 {0x8e, 0xec, 0x10, 0xbb}, {0x8f, 0xf0, 0xed, 0xbb},
635 {0x90, 0xf9, 0xf2, 0xbb}, {0x91, 0x00, 0x00, 0xbb},
636 {0x92, 0xe9, 0x0d, 0xbb}, {0x93, 0xf4, 0xf2, 0xbb},
637 {0x94, 0xfb, 0xf5, 0xbb}, {0x95, 0x00, 0xff, 0xbb},
638 {0xb6, 0x0f, 0x08, 0xbb}, {0xb7, 0x3d, 0x16, 0xbb},
639 {0xb8, 0x0c, 0x04, 0xbb}, {0xb9, 0x1c, 0x07, 0xbb},
640 {0xba, 0x0a, 0x03, 0xbb}, {0xbb, 0x1b, 0x09, 0xbb},
641 {0xbc, 0x17, 0x0d, 0xbb}, {0xbd, 0x23, 0x1d, 0xbb},
642 {0xbe, 0x00, 0x28, 0xbb}, {0xbf, 0x11, 0x09, 0xbb},
643 {0xc0, 0x16, 0x15, 0xbb}, {0xc1, 0x00, 0x1b, 0xbb},
644 {0xc2, 0x0e, 0x07, 0xbb}, {0xc3, 0x14, 0x10, 0xbb},
645 {0xc4, 0x00, 0x17, 0xbb}, {0x06, 0x74, 0x8e, 0xbb},
646 {0xf0, 0x00, 0x01, 0xbb}, {0x06, 0xf4, 0x8e, 0xbb},
647 {0x00, 0x00, 0x50, 0xdd}, {0x06, 0x74, 0x8e, 0xbb},
648 {0xf0, 0x00, 0x02, 0xbb}, {0x24, 0x50, 0x20, 0xbb},
649 {0xf0, 0x00, 0x02, 0xbb}, {0x34, 0x0c, 0x50, 0xbb},
650 {0xb3, 0x01, 0x41, 0xcc}, {0xf0, 0x00, 0x00, 0xbb},
640 {0x03, 0x03, 0xc0, 0xbb}, 651 {0x03, 0x03, 0xc0, 0xbb},
641 {0x06, 0x00, 0x10, 0xbb},
642 {0xb6, 0x12, 0xf8, 0xcc},
643 {0xb8, 0x0c, 0x20, 0xcc},
644 {0xb8, 0x0d, 0x70, 0xcc},
645 {0xb6, 0x13, 0x13, 0xcc},
646 {0x2f, 0x00, 0xC0, 0xbb},
647 {0xb8, 0xa0, 0x12, 0xcc},
648 {}, 652 {},
649}; 653};
650static const u8 mi1310_soc_InitSXGA_JPG[][4] = { 654static const u8 mi1310_soc_InitSXGA_JPG[][4] = {
651 {0xb0, 0x03, 0x19, 0xcc}, 655 {0xb0, 0x03, 0x19, 0xcc},
652 {0xb0, 0x04, 0x02, 0xcc}, 656 {0xb0, 0x04, 0x02, 0xcc},
653 {0xb3, 0x00, 0x24, 0xcc}, 657 {0xb3, 0x00, 0x64, 0xcc},
654 {0xb3, 0x00, 0x25, 0xcc}, 658 {0xb3, 0x00, 0x65, 0xcc},
655 {0xb3, 0x05, 0x00, 0xcc}, 659 {0xb3, 0x05, 0x00, 0xcc},
656 {0xb3, 0x06, 0x01, 0xcc}, 660 {0xb3, 0x06, 0x00, 0xcc},
657 {0xb3, 0x5c, 0x01, 0xcc},
658 {0xb3, 0x08, 0x01, 0xcc}, 661 {0xb3, 0x08, 0x01, 0xcc},
659 {0xb3, 0x09, 0x0c, 0xcc}, 662 {0xb3, 0x09, 0x0c, 0xcc},
660 {0xb3, 0x34, 0x02, 0xcc}, 663 {0xb3, 0x34, 0x02, 0xcc},
661 {0xb3, 0x35, 0xdd, 0xcc}, 664 {0xb3, 0x35, 0xdd, 0xcc},
665 {0xb3, 0x02, 0x00, 0xcc},
662 {0xb3, 0x03, 0x0a, 0xcc}, 666 {0xb3, 0x03, 0x0a, 0xcc},
663 {0xb3, 0x04, 0x0d, 0xcc}, 667 {0xb3, 0x04, 0x0d, 0xcc},
664 {0xb3, 0x20, 0x00, 0xcc}, 668 {0xb3, 0x20, 0x00, 0xcc},
665 {0xb3, 0x21, 0x00, 0xcc}, 669 {0xb3, 0x21, 0x00, 0xcc},
666 {0xb3, 0x22, 0x04, 0xcc}, 670 {0xb3, 0x22, 0x03, 0xcc},
667 {0xb3, 0x23, 0x00, 0xcc}, 671 {0xb3, 0x23, 0xc0, 0xcc},
668 {0xb3, 0x14, 0x00, 0xcc}, 672 {0xb3, 0x14, 0x00, 0xcc},
669 {0xb3, 0x15, 0x00, 0xcc}, 673 {0xb3, 0x15, 0x00, 0xcc},
670 {0xb3, 0x16, 0x04, 0xcc}, 674 {0xb3, 0x16, 0x04, 0xcc},
671 {0xb3, 0x17, 0xff, 0xcc}, 675 {0xb3, 0x17, 0xff, 0xcc},
672 {0xb8, 0x01, 0x7d, 0xcc}, 676 {0xb3, 0x00, 0x65, 0xcc},
673 {0xb8, 0x81, 0x09, 0xcc}, 677 {0xb8, 0x00, 0x00, 0xcc},
674 {0xb8, 0x27, 0x20, 0xcc}, 678 {0xbc, 0x00, 0x70, 0xcc},
675 {0xb8, 0x26, 0x80, 0xcc}, 679 {0xbc, 0x01, 0x01, 0xcc},
676 {0xb8, 0x06, 0x00, 0xcc}, 680 {0xf0, 0x00, 0x02, 0xbb},
677 {0xb8, 0x07, 0x05, 0xcc}, 681 {0xc8, 0x9f, 0x0b, 0xbb},
678 {0xb8, 0x08, 0x00, 0xcc}, 682 {0x5b, 0x00, 0x01, 0xbb},
679 {0xb8, 0x09, 0x04, 0xcc},
680 {0xb3, 0x00, 0x25, 0xcc},
681 {0xb8, 0x00, 0x11, 0xcc},
682 {0xbc, 0x00, 0x71, 0xcc},
683 {0xb8, 0x81, 0x01, 0xcc},
684 {0xb8, 0x2c, 0x5a, 0xcc},
685 {0xb8, 0x2d, 0xff, 0xcc},
686 {0xb8, 0x2e, 0xee, 0xcc},
687 {0xb8, 0x2f, 0xfb, 0xcc},
688 {0xb8, 0x30, 0x52, 0xcc},
689 {0xb8, 0x31, 0xf8, 0xcc},
690 {0xb8, 0x32, 0xf1, 0xcc},
691 {0xb8, 0x33, 0xff, 0xcc},
692 {0xb8, 0x34, 0x54, 0xcc},
693 {0xf0, 0x00, 0x00, 0xbb}, 683 {0xf0, 0x00, 0x00, 0xbb},
694 {0x00, 0x01, 0x00, 0xdd}, 684 {0x20, 0x03, 0x02, 0xbb}, /* h/v flip */
695 {0x0d, 0x00, 0x09, 0xbb},
696 {0x0d, 0x00, 0x08, 0xbb},
697 {0xf0, 0x00, 0x01, 0xbb}, 685 {0xf0, 0x00, 0x01, 0xbb},
698 {0x00, 0x01, 0x00, 0xdd}, 686 {0x05, 0x00, 0x07, 0xbb},
699 {0x06, 0x00, 0x14, 0xbb}, 687 {0x34, 0x00, 0x00, 0xbb},
700 {0x3a, 0x10, 0x00, 0xbb}, 688 {0x35, 0xff, 0x00, 0xbb},
701 {0x00, 0x00, 0x10, 0xdd}, 689 {0xdc, 0x07, 0x02, 0xbb},
702 {0x9b, 0x10, 0x00, 0xbb}, 690 {0xdd, 0x3c, 0x18, 0xbb},
703 {0x00, 0x00, 0x10, 0xdd}, 691 {0xde, 0x92, 0x6d, 0xbb},
692 {0xdf, 0xcd, 0xb1, 0xbb},
693 {0xe0, 0xff, 0xe7, 0xbb},
694 {0x06, 0xf0, 0x0d, 0xbb},
695 {0x06, 0x70, 0x0e, 0xbb},
696 {0x4c, 0x00, 0x01, 0xbb},
697 {0x4d, 0x00, 0x01, 0xbb},
698 {0xf0, 0x00, 0x02, 0xbb},
699 {0x2e, 0x0c, 0x60, 0xbb},
700 {0x21, 0xb6, 0x6e, 0xbb},
701 {0x37, 0x01, 0x40, 0xbb},
704 {0xf0, 0x00, 0x00, 0xbb}, 702 {0xf0, 0x00, 0x00, 0xbb},
705 {0x00, 0x01, 0x00, 0xdd}, 703 {0x07, 0x00, 0x84, 0xbb},
706 {0x2b, 0x00, 0x28, 0xbb}, 704 {0x08, 0x02, 0x4a, 0xbb},
707 {0x2c, 0x00, 0x30, 0xbb}, 705 {0x05, 0x01, 0x10, 0xbb},
708 {0x2d, 0x00, 0x30, 0xbb}, 706 {0x06, 0x00, 0x39, 0xbb},
709 {0x2e, 0x00, 0x28, 0xbb}, 707 {0xf0, 0x00, 0x02, 0xbb},
710 {0x41, 0x00, 0xd7, 0xbb}, 708 {0x58, 0x02, 0x67, 0xbb},
711 {0x09, 0x02, 0x3a, 0xbb}, 709 {0x57, 0x02, 0x00, 0xbb},
712 {0x0c, 0x00, 0x00, 0xbb}, 710 {0x5a, 0x02, 0x67, 0xbb},
713 {0x20, 0x00, 0x00, 0xbb}, 711 {0x59, 0x02, 0x00, 0xbb},
714 {0x05, 0x00, 0x8c, 0xbb}, 712 {0x5c, 0x12, 0x0d, 0xbb},
715 {0x06, 0x00, 0x32, 0xbb}, 713 {0x5d, 0x16, 0x11, 0xbb},
716 {0x07, 0x00, 0xc6, 0xbb}, 714 {0x39, 0x06, 0x18, 0xbb},
717 {0x08, 0x00, 0x19, 0xbb}, 715 {0x3a, 0x06, 0x18, 0xbb},
718 {0x24, 0x80, 0x6f, 0xbb}, 716 {0x3b, 0x06, 0x18, 0xbb},
719 {0xc8, 0x00, 0x0f, 0xbb}, 717 {0x3c, 0x06, 0x18, 0xbb},
720 {0x20, 0x00, 0x03, 0xbb}, 718 {0x64, 0x7b, 0x5b, 0xbb},
721 {0xb6, 0x00, 0x00, 0xcc}, 719 {0xb6, 0x00, 0x00, 0xcc},
722 {0xb6, 0x03, 0x05, 0xcc}, 720 {0xb6, 0x03, 0x05, 0xcc},
723 {0xb6, 0x02, 0x00, 0xcc}, 721 {0xb6, 0x02, 0x00, 0xcc},
724 {0xb6, 0x05, 0x04, 0xcc}, 722 {0xb6, 0x05, 0x03, 0xcc},
725 {0xb6, 0x04, 0x00, 0xcc}, 723 {0xb6, 0x04, 0xc0, 0xcc},
726 {0xb6, 0x12, 0xf8, 0xcc}, 724 {0xb6, 0x12, 0xf8, 0xcc},
727 {0xb6, 0x18, 0x0a, 0xcc}, 725 {0xb6, 0x13, 0x29, 0xcc},
728 {0xb6, 0x17, 0x00, 0xcc}, 726 {0xb6, 0x18, 0x09, 0xcc},
727 {0xb6, 0x17, 0x60, 0xcc},
729 {0xb6, 0x16, 0x00, 0xcc}, 728 {0xb6, 0x16, 0x00, 0xcc},
730 {0xb6, 0x22, 0x12, 0xcc}, 729 {0xb6, 0x22, 0x12, 0xcc},
731 {0xb6, 0x23, 0x0b, 0xcc}, 730 {0xb6, 0x23, 0x0b, 0xcc},
732 {0xb3, 0x02, 0x02, 0xcc},
733 {0xbf, 0xc0, 0x39, 0xcc}, 731 {0xbf, 0xc0, 0x39, 0xcc},
734 {0xbf, 0xc1, 0x04, 0xcc}, 732 {0xbf, 0xc1, 0x04, 0xcc},
735 {0xbf, 0xcc, 0x10, 0xcc}, 733 {0xbf, 0xcc, 0x00, 0xcc},
736 {0xb9, 0x12, 0x00, 0xcc},
737 {0xb9, 0x13, 0x14, 0xcc},
738 {0xb9, 0x14, 0x14, 0xcc},
739 {0xb9, 0x15, 0x14, 0xcc},
740 {0xb9, 0x16, 0x14, 0xcc},
741 {0xb9, 0x18, 0x00, 0xcc},
742 {0xb9, 0x19, 0x1e, 0xcc},
743 {0xb9, 0x1a, 0x1e, 0xcc},
744 {0xb9, 0x1b, 0x1e, 0xcc},
745 {0xb9, 0x1c, 0x1e, 0xcc},
746 {0xb3, 0x01, 0x41, 0xcc}, 734 {0xb3, 0x01, 0x41, 0xcc},
747 {0xb8, 0x8e, 0x00, 0xcc}, 735 {0x00, 0x00, 0x80, 0xdd},
748 {0xb8, 0x8f, 0xff, 0xcc}, 736 {0xf0, 0x00, 0x02, 0xbb},
749 {0xb6, 0x12, 0xf8, 0xcc}, 737 {0x00, 0x00, 0x10, 0xdd},
750 {0xb8, 0x0c, 0x20, 0xcc}, 738 {0x22, 0xa0, 0x78, 0xbb},
751 {0xb8, 0x0d, 0x70, 0xcc}, 739 {0x23, 0xa0, 0x78, 0xbb},
752 {0xb6, 0x13, 0x13, 0xcc}, 740 {0x24, 0x7f, 0x00, 0xbb},
753 {0x2f, 0x00, 0xC0, 0xbb}, 741 {0x28, 0xea, 0x02, 0xbb},
754 {0xb8, 0xa0, 0x12, 0xcc}, 742 {0x29, 0x86, 0x7a, 0xbb},
743 {0x5e, 0x52, 0x4c, 0xbb},
744 {0x5f, 0x20, 0x24, 0xbb},
745 {0x60, 0x00, 0x02, 0xbb},
746 {0x02, 0x00, 0xee, 0xbb},
747 {0x03, 0x39, 0x23, 0xbb},
748 {0x04, 0x07, 0x24, 0xbb},
749 {0x09, 0x00, 0xc0, 0xbb},
750 {0x0a, 0x00, 0x79, 0xbb},
751 {0x0b, 0x00, 0x04, 0xbb},
752 {0x0c, 0x00, 0x5c, 0xbb},
753 {0x0d, 0x00, 0xd9, 0xbb},
754 {0x0e, 0x00, 0x53, 0xbb},
755 {0x0f, 0x00, 0x21, 0xbb},
756 {0x10, 0x00, 0xa4, 0xbb},
757 {0x11, 0x00, 0xe5, 0xbb},
758 {0x15, 0x00, 0x00, 0xbb},
759 {0x16, 0x00, 0x00, 0xbb},
760 {0x17, 0x00, 0x00, 0xbb},
761 {0x18, 0x00, 0x00, 0xbb},
762 {0x19, 0x00, 0x00, 0xbb},
763 {0x1a, 0x00, 0x00, 0xbb},
764 {0x1b, 0x00, 0x00, 0xbb},
765 {0x1c, 0x00, 0x00, 0xbb},
766 {0x1d, 0x00, 0x00, 0xbb},
767 {0x1e, 0x00, 0x00, 0xbb},
768 {0xf0, 0x00, 0x01, 0xbb},
769 {0x00, 0x00, 0x20, 0xdd},
770 {0x06, 0xf0, 0x8e, 0xbb},
771 {0x00, 0x00, 0x80, 0xdd},
772 {0x06, 0x70, 0x8e, 0xbb},
773 {0xf0, 0x00, 0x02, 0xbb},
774 {0x00, 0x00, 0x20, 0xdd},
775 {0x5e, 0x6a, 0x53, 0xbb},
776 {0x5f, 0x40, 0x2c, 0xbb},
777 {0xf0, 0x00, 0x01, 0xbb},
778 {0x00, 0x00, 0x20, 0xdd},
779 {0x58, 0x00, 0x00, 0xbb},
780 {0x53, 0x09, 0x03, 0xbb},
781 {0x54, 0x31, 0x18, 0xbb},
782 {0x55, 0x8b, 0x5f, 0xbb},
783 {0x56, 0xc0, 0xa9, 0xbb},
784 {0x57, 0xe0, 0xd2, 0xbb},
785 {0xe1, 0x00, 0x00, 0xbb},
786 {0xdc, 0x09, 0x03, 0xbb},
787 {0xdd, 0x31, 0x18, 0xbb},
788 {0xde, 0x8b, 0x5f, 0xbb},
789 {0xdf, 0xc0, 0xa9, 0xbb},
790 {0xe0, 0xe0, 0xd2, 0xbb},
791 {0xb3, 0x5c, 0x01, 0xcc},
792 {0xf0, 0x00, 0x01, 0xbb},
793 {0x06, 0xf0, 0x8e, 0xbb},
794 {0xf0, 0x00, 0x02, 0xbb},
795 {0x2f, 0xde, 0x20, 0xbb},
796 {0xf0, 0x00, 0x02, 0xbb},
797 {0x24, 0x50, 0x20, 0xbb},
798 {0xbc, 0x0e, 0x00, 0xcc},
799 {0xbc, 0x0f, 0x05, 0xcc},
800 {0xbc, 0x10, 0xc0, 0xcc},
801 {0xf0, 0x00, 0x02, 0xbb},
802 {0x34, 0x0c, 0x50, 0xbb},
803 {0xbc, 0x11, 0x03, 0xcc},
804 {0xf0, 0x00, 0x01, 0xbb},
805 {0x80, 0x00, 0x03, 0xbb},
806 {0x81, 0xc7, 0x14, 0xbb},
807 {0x82, 0xeb, 0xe8, 0xbb},
808 {0x83, 0xfe, 0xf4, 0xbb},
809 {0x84, 0xcd, 0x10, 0xbb},
810 {0x85, 0xf3, 0xee, 0xbb},
811 {0x86, 0xff, 0xf1, 0xbb},
812 {0x87, 0xcd, 0x10, 0xbb},
813 {0x88, 0xf3, 0xee, 0xbb},
814 {0x89, 0x01, 0xf1, 0xbb},
815 {0x8a, 0xe5, 0x17, 0xbb},
816 {0x8b, 0xe8, 0xe2, 0xbb},
817 {0x8c, 0xf7, 0xed, 0xbb},
818 {0x8d, 0x00, 0xff, 0xbb},
819 {0x8e, 0xec, 0x10, 0xbb},
820 {0x8f, 0xf0, 0xed, 0xbb},
821 {0x90, 0xf9, 0xf2, 0xbb},
822 {0x91, 0x00, 0x00, 0xbb},
823 {0x92, 0xe9, 0x0d, 0xbb},
824 {0x93, 0xf4, 0xf2, 0xbb},
825 {0x94, 0xfb, 0xf5, 0xbb},
826 {0x95, 0x00, 0xff, 0xbb},
827 {0xb6, 0x0f, 0x08, 0xbb},
828 {0xb7, 0x3d, 0x16, 0xbb},
829 {0xb8, 0x0c, 0x04, 0xbb},
830 {0xb9, 0x1c, 0x07, 0xbb},
831 {0xba, 0x0a, 0x03, 0xbb},
832 {0xbb, 0x1b, 0x09, 0xbb},
833 {0xbc, 0x17, 0x0d, 0xbb},
834 {0xbd, 0x23, 0x1d, 0xbb},
835 {0xbe, 0x00, 0x28, 0xbb},
836 {0xbf, 0x11, 0x09, 0xbb},
837 {0xc0, 0x16, 0x15, 0xbb},
838 {0xc1, 0x00, 0x1b, 0xbb},
839 {0xc2, 0x0e, 0x07, 0xbb},
840 {0xc3, 0x14, 0x10, 0xbb},
841 {0xc4, 0x00, 0x17, 0xbb},
842 {0x06, 0x74, 0x8e, 0xbb},
843 {0xf0, 0x00, 0x00, 0xbb},
844 {0x03, 0x03, 0xc0, 0xbb},
755 {} 845 {}
756}; 846};
757 847
758static const __u8 mi1320_gamma[17] = { 848static const u8 mi1320_gamma[17] = {
759 0x00, 0x13, 0x38, 0x59, 0x79, 0x92, 0xa7, 0xb9, 0xc8, 849 0x00, 0x13, 0x38, 0x59, 0x79, 0x92, 0xa7, 0xb9, 0xc8,
760 0xd4, 0xdf, 0xe7, 0xee, 0xf4, 0xf9, 0xfc, 0xff 850 0xd4, 0xdf, 0xe7, 0xee, 0xf4, 0xf9, 0xfc, 0xff
761}; 851};
762static const __u8 mi1320_matrix[9] = { 852static const u8 mi1320_matrix[9] = {
763 0x54, 0xda, 0x06, 0xf1, 0x50, 0xf4, 0xf7, 0xea, 0x52 853 0x54, 0xda, 0x06, 0xf1, 0x50, 0xf4, 0xf7, 0xea, 0x52
764}; 854};
765static const __u8 mi1320_initVGA_data[][4] = { 855static const u8 mi1320_initVGA_data[][4] = {
766 {0xb3, 0x01, 0x01, 0xcc}, {0x00, 0x00, 0x33, 0xdd}, 856 {0xb3, 0x01, 0x01, 0xcc}, {0x00, 0x00, 0x33, 0xdd},
767 {0xb0, 0x03, 0x19, 0xcc}, {0x00, 0x00, 0x33, 0xdd}, 857 {0xb0, 0x03, 0x19, 0xcc}, {0x00, 0x00, 0x33, 0xdd},
768 {0xb0, 0x04, 0x02, 0xcc}, {0x00, 0x00, 0x33, 0xdd}, 858 {0xb0, 0x04, 0x02, 0xcc}, {0x00, 0x00, 0x33, 0xdd},
@@ -841,7 +931,7 @@ static const __u8 mi1320_initVGA_data[][4] = {
841 {0xb3, 0x5c, 0x01, 0xcc}, {0xb3, 0x01, 0x41, 0xcc}, 931 {0xb3, 0x5c, 0x01, 0xcc}, {0xb3, 0x01, 0x41, 0xcc},
842 {} 932 {}
843}; 933};
844static const __u8 mi1320_initQVGA_data[][4] = { 934static const u8 mi1320_initQVGA_data[][4] = {
845 {0xb3, 0x01, 0x01, 0xcc}, {0x00, 0x00, 0x33, 0xdd}, 935 {0xb3, 0x01, 0x01, 0xcc}, {0x00, 0x00, 0x33, 0xdd},
846 {0xb0, 0x03, 0x19, 0xcc}, {0x00, 0x00, 0x33, 0xdd}, 936 {0xb0, 0x03, 0x19, 0xcc}, {0x00, 0x00, 0x33, 0xdd},
847 {0xb0, 0x04, 0x02, 0xcc}, {0x00, 0x00, 0x33, 0xdd}, 937 {0xb0, 0x04, 0x02, 0xcc}, {0x00, 0x00, 0x33, 0xdd},
@@ -948,7 +1038,7 @@ static const u8 mi1320_soc_InitVGA[][4] = {
948 {0x07, 0x00, 0xe0, 0xbb}, 1038 {0x07, 0x00, 0xe0, 0xbb},
949 {0x08, 0x00, 0x0b, 0xbb}, 1039 {0x08, 0x00, 0x0b, 0xbb},
950 {0x21, 0x00, 0x0c, 0xbb}, 1040 {0x21, 0x00, 0x0c, 0xbb},
951 {0x20, 0x01, 0x03, 0xbb}, 1041 {0x20, 0x01, 0x03, 0xbb}, /* h/v flip */
952 {0xbf, 0xc0, 0x26, 0xcc}, 1042 {0xbf, 0xc0, 0x26, 0xcc},
953 {0xbf, 0xc1, 0x02, 0xcc}, 1043 {0xbf, 0xc1, 0x02, 0xcc},
954 {0xbf, 0xcc, 0x04, 0xcc}, 1044 {0xbf, 0xcc, 0x04, 0xcc},
@@ -958,7 +1048,7 @@ static const u8 mi1320_soc_InitVGA[][4] = {
958 {0x06, 0x00, 0x11, 0xbb}, 1048 {0x06, 0x00, 0x11, 0xbb},
959 {0x07, 0x01, 0x42, 0xbb}, 1049 {0x07, 0x01, 0x42, 0xbb},
960 {0x08, 0x00, 0x11, 0xbb}, 1050 {0x08, 0x00, 0x11, 0xbb},
961 {0x20, 0x01, 0x03, 0xbb}, 1051 {0x20, 0x01, 0x03, 0xbb}, /* h/v flip */
962 {0x21, 0x80, 0x00, 0xbb}, 1052 {0x21, 0x80, 0x00, 0xbb},
963 {0x22, 0x0d, 0x0f, 0xbb}, 1053 {0x22, 0x0d, 0x0f, 0xbb},
964 {0x24, 0x80, 0x00, 0xbb}, 1054 {0x24, 0x80, 0x00, 0xbb},
@@ -1051,7 +1141,7 @@ static const u8 mi1320_soc_InitQVGA[][4] = {
1051 {0x07, 0x00, 0xe0, 0xbb}, 1141 {0x07, 0x00, 0xe0, 0xbb},
1052 {0x08, 0x00, 0x0b, 0xbb}, 1142 {0x08, 0x00, 0x0b, 0xbb},
1053 {0x21, 0x00, 0x0c, 0xbb}, 1143 {0x21, 0x00, 0x0c, 0xbb},
1054 {0x20, 0x01, 0x03, 0xbb}, 1144 {0x20, 0x01, 0x03, 0xbb}, /* h/v flip */
1055 {0xbf, 0xc0, 0x26, 0xcc}, 1145 {0xbf, 0xc0, 0x26, 0xcc},
1056 {0xbf, 0xc1, 0x02, 0xcc}, 1146 {0xbf, 0xc1, 0x02, 0xcc},
1057 {0xbf, 0xcc, 0x04, 0xcc}, 1147 {0xbf, 0xcc, 0x04, 0xcc},
@@ -1071,7 +1161,7 @@ static const u8 mi1320_soc_InitQVGA[][4] = {
1071 {0x06, 0x00, 0x11, 0xbb}, 1161 {0x06, 0x00, 0x11, 0xbb},
1072 {0x07, 0x01, 0x42, 0xbb}, 1162 {0x07, 0x01, 0x42, 0xbb},
1073 {0x08, 0x00, 0x11, 0xbb}, 1163 {0x08, 0x00, 0x11, 0xbb},
1074 {0x20, 0x01, 0x03, 0xbb}, 1164 {0x20, 0x01, 0x03, 0xbb}, /* h/v flip */
1075 {0x21, 0x80, 0x00, 0xbb}, 1165 {0x21, 0x80, 0x00, 0xbb},
1076 {0x22, 0x0d, 0x0f, 0xbb}, 1166 {0x22, 0x0d, 0x0f, 0xbb},
1077 {0x24, 0x80, 0x00, 0xbb}, 1167 {0x24, 0x80, 0x00, 0xbb},
@@ -1161,7 +1251,7 @@ static const u8 mi1320_soc_InitSXGA[][4] = {
1161 {0x00, 0x00, 0x20, 0xdd}, 1251 {0x00, 0x00, 0x20, 0xdd},
1162 {0xf0, 0x00, 0x00, 0xbb}, 1252 {0xf0, 0x00, 0x00, 0xbb},
1163 {0x00, 0x00, 0x30, 0xdd}, 1253 {0x00, 0x00, 0x30, 0xdd},
1164 {0x20, 0x01, 0x03, 0xbb}, 1254 {0x20, 0x01, 0x03, 0xbb}, /* h/v flip */
1165 {0x00, 0x00, 0x20, 0xdd}, 1255 {0x00, 0x00, 0x20, 0xdd},
1166 {0xbf, 0xc0, 0x26, 0xcc}, 1256 {0xbf, 0xc0, 0x26, 0xcc},
1167 {0xbf, 0xc1, 0x02, 0xcc}, 1257 {0xbf, 0xc1, 0x02, 0xcc},
@@ -1172,7 +1262,7 @@ static const u8 mi1320_soc_InitSXGA[][4] = {
1172 {0x06, 0x00, 0x11, 0xbb}, 1262 {0x06, 0x00, 0x11, 0xbb},
1173 {0x07, 0x01, 0x42, 0xbb}, 1263 {0x07, 0x01, 0x42, 0xbb},
1174 {0x08, 0x00, 0x11, 0xbb}, 1264 {0x08, 0x00, 0x11, 0xbb},
1175 {0x20, 0x01, 0x03, 0xbb}, 1265 {0x20, 0x01, 0x03, 0xbb}, /* h/v flip */
1176 {0x21, 0x80, 0x00, 0xbb}, 1266 {0x21, 0x80, 0x00, 0xbb},
1177 {0x22, 0x0d, 0x0f, 0xbb}, 1267 {0x22, 0x0d, 0x0f, 0xbb},
1178 {0x24, 0x80, 0x00, 0xbb}, 1268 {0x24, 0x80, 0x00, 0xbb},
@@ -1230,7 +1320,7 @@ static const u8 mi1320_soc_InitSXGA[][4] = {
1230 {0x06, 0x00, 0x11, 0xbb}, 1320 {0x06, 0x00, 0x11, 0xbb},
1231 {0x07, 0x00, 0x85, 0xbb}, 1321 {0x07, 0x00, 0x85, 0xbb},
1232 {0x08, 0x00, 0x27, 0xbb}, 1322 {0x08, 0x00, 0x27, 0xbb},
1233 {0x20, 0x01, 0x03, 0xbb}, 1323 {0x20, 0x01, 0x03, 0xbb}, /* h/v flip */
1234 {0x21, 0x80, 0x00, 0xbb}, 1324 {0x21, 0x80, 0x00, 0xbb},
1235 {0x22, 0x0d, 0x0f, 0xbb}, 1325 {0x22, 0x0d, 0x0f, 0xbb},
1236 {0x24, 0x80, 0x00, 0xbb}, 1326 {0x24, 0x80, 0x00, 0xbb},
@@ -1249,15 +1339,15 @@ static const u8 mi1320_soc_InitSXGA[][4] = {
1249 {0x64, 0x5e, 0x1c, 0xbb}, 1339 {0x64, 0x5e, 0x1c, 0xbb},
1250 {} 1340 {}
1251}; 1341};
1252static const __u8 po3130_gamma[17] = { 1342static const u8 po3130_gamma[17] = {
1253 0x00, 0x13, 0x38, 0x59, 0x79, 0x92, 0xa7, 0xb9, 0xc8, 1343 0x00, 0x13, 0x38, 0x59, 0x79, 0x92, 0xa7, 0xb9, 0xc8,
1254 0xd4, 0xdf, 0xe7, 0xee, 0xf4, 0xf9, 0xfc, 0xff 1344 0xd4, 0xdf, 0xe7, 0xee, 0xf4, 0xf9, 0xfc, 0xff
1255}; 1345};
1256static const __u8 po3130_matrix[9] = { 1346static const u8 po3130_matrix[9] = {
1257 0x5f, 0xec, 0xf5, 0xf1, 0x5a, 0xf5, 0xf1, 0xec, 0x63 1347 0x5f, 0xec, 0xf5, 0xf1, 0x5a, 0xf5, 0xf1, 0xec, 0x63
1258}; 1348};
1259 1349
1260static const __u8 po3130_initVGA_data[][4] = { 1350static const u8 po3130_initVGA_data[][4] = {
1261 {0xb0, 0x4d, 0x00, 0xcc}, {0xb3, 0x01, 0x01, 0xcc}, 1351 {0xb0, 0x4d, 0x00, 0xcc}, {0xb3, 0x01, 0x01, 0xcc},
1262 {0x00, 0x00, 0x50, 0xdd}, {0xb0, 0x03, 0x01, 0xcc}, 1352 {0x00, 0x00, 0x50, 0xdd}, {0xb0, 0x03, 0x01, 0xcc},
1263 {0xb3, 0x00, 0x04, 0xcc}, {0xb3, 0x00, 0x24, 0xcc}, 1353 {0xb3, 0x00, 0x04, 0xcc}, {0xb3, 0x00, 0x24, 0xcc},
@@ -1340,7 +1430,7 @@ static const __u8 po3130_initVGA_data[][4] = {
1340 {0xb3, 0x5c, 0x00, 0xcc}, {0xb3, 0x01, 0x41, 0xcc}, 1430 {0xb3, 0x5c, 0x00, 0xcc}, {0xb3, 0x01, 0x41, 0xcc},
1341 {} 1431 {}
1342}; 1432};
1343static const __u8 po3130_rundata[][4] = { 1433static const u8 po3130_rundata[][4] = {
1344 {0x00, 0x47, 0x45, 0xaa}, {0x00, 0x48, 0x9b, 0xaa}, 1434 {0x00, 0x47, 0x45, 0xaa}, {0x00, 0x48, 0x9b, 0xaa},
1345 {0x00, 0x49, 0x3a, 0xaa}, {0x00, 0x4a, 0x01, 0xaa}, 1435 {0x00, 0x49, 0x3a, 0xaa}, {0x00, 0x4a, 0x01, 0xaa},
1346 {0x00, 0x44, 0x40, 0xaa}, 1436 {0x00, 0x44, 0x40, 0xaa},
@@ -1355,7 +1445,7 @@ static const __u8 po3130_rundata[][4] = {
1355 {} 1445 {}
1356}; 1446};
1357 1447
1358static const __u8 po3130_initQVGA_data[][4] = { 1448static const u8 po3130_initQVGA_data[][4] = {
1359 {0xb0, 0x4d, 0x00, 0xcc}, {0xb3, 0x01, 0x01, 0xcc}, 1449 {0xb0, 0x4d, 0x00, 0xcc}, {0xb3, 0x01, 0x01, 0xcc},
1360 {0x00, 0x00, 0x50, 0xdd}, {0xb0, 0x03, 0x09, 0xcc}, 1450 {0x00, 0x00, 0x50, 0xdd}, {0xb0, 0x03, 0x09, 0xcc},
1361 {0xb3, 0x00, 0x04, 0xcc}, {0xb3, 0x00, 0x24, 0xcc}, 1451 {0xb3, 0x00, 0x04, 0xcc}, {0xb3, 0x00, 0x24, 0xcc},
@@ -1441,121 +1531,207 @@ static const __u8 po3130_initQVGA_data[][4] = {
1441 {} 1531 {}
1442}; 1532};
1443 1533
1444static const __u8 hv7131r_gamma[17] = { 1534static const u8 hv7131r_gamma[17] = {
1445/* 0x00, 0x13, 0x38, 0x59, 0x79, 0x92, 0xa7, 0xb9, 0xc8, 1535 0x00, 0x13, 0x38, 0x59, 0x79, 0x92, 0xa7, 0xb9, 0xc8,
1446 * 0xd4, 0xdf, 0xe7, 0xee, 0xf4, 0xf9, 0xfc, 0xff */ 1536 0xd4, 0xdf, 0xe7, 0xee, 0xf4, 0xf9, 0xfc, 0xff
1447 0x04, 0x1a, 0x36, 0x55, 0x6f, 0x87, 0x9d, 0xb0, 0xc1,
1448 0xcf, 0xda, 0xe4, 0xec, 0xf3, 0xf8, 0xfd, 0xff
1449}; 1537};
1450static const __u8 hv7131r_matrix[9] = { 1538static const u8 hv7131r_matrix[9] = {
1451 0x5f, 0xec, 0xf5, 0xf1, 0x5a, 0xf5, 0xf1, 0xec, 0x63 1539 0x5f, 0xec, 0xf5, 0xf1, 0x5a, 0xf5, 0xf1, 0xec, 0x63
1452}; 1540};
1453static const __u8 hv7131r_initVGA_data[][4] = { 1541static const u8 hv7131r_initVGA_data[][4] = {
1454 {0xb0, 0x4d, 0x00, 0xcc}, {0xb3, 0x01, 0x01, 0xcc}, 1542 {0xb3, 0x01, 0x01, 0xcc},
1455 {0x00, 0x00, 0x50, 0xdd}, {0xb0, 0x03, 0x01, 0xcc}, 1543 {0xb0, 0x03, 0x19, 0xcc},
1544 {0xb0, 0x04, 0x02, 0xcc},
1545 {0x00, 0x00, 0x20, 0xdd},
1456 {0xb3, 0x00, 0x24, 0xcc}, 1546 {0xb3, 0x00, 0x24, 0xcc},
1457 {0xb3, 0x00, 0x25, 0xcc}, {0xb3, 0x08, 0x01, 0xcc}, 1547 {0xb3, 0x00, 0x25, 0xcc},
1458 {0xb3, 0x09, 0x0c, 0xcc}, {0xb3, 0x05, 0x00, 0xcc}, 1548 {0xb3, 0x08, 0x01, 0xcc},
1459 {0xb3, 0x06, 0x01, 0xcc}, 1549 {0xb3, 0x09, 0x0c, 0xcc},
1460 {0xb3, 0x01, 0x45, 0xcc}, {0xb3, 0x03, 0x0b, 0xcc}, 1550 {0xb3, 0x05, 0x01, 0xcc},
1461 {0xb3, 0x04, 0x05, 0xcc}, {0xb3, 0x20, 0x00, 0xcc}, 1551 {0xb3, 0x06, 0x03, 0xcc},
1552 {0xb3, 0x01, 0x45, 0xcc},
1553 {0xb3, 0x03, 0x0b, 0xcc},
1554 {0xb3, 0x04, 0x05, 0xcc},
1555 {0xb3, 0x20, 0x00, 0xcc},
1462 {0xb3, 0x21, 0x00, 0xcc}, 1556 {0xb3, 0x21, 0x00, 0xcc},
1463 {0xb3, 0x22, 0x01, 0xcc}, {0xb3, 0x23, 0xe0, 0xcc}, 1557 {0xb3, 0x22, 0x01, 0xcc},
1464 {0xb3, 0x14, 0x00, 0xcc}, {0xb3, 0x15, 0x00, 0xcc}, 1558 {0xb3, 0x23, 0xe0, 0xcc},
1559 {0xb3, 0x14, 0x00, 0xcc},
1560 {0xb3, 0x15, 0x02, 0xcc},
1465 {0xb3, 0x16, 0x02, 0xcc}, 1561 {0xb3, 0x16, 0x02, 0xcc},
1466 {0xb3, 0x17, 0x7f, 0xcc}, {0xb3, 0x34, 0x01, 0xcc}, 1562 {0xb3, 0x17, 0x7f, 0xcc},
1467 {0xb3, 0x35, 0x91, 0xcc}, {0xb3, 0x00, 0x27, 0xcc}, 1563 {0xb3, 0x34, 0x01, 0xcc},
1564 {0xb3, 0x35, 0x91, 0xcc},
1565 {0xb3, 0x00, 0x27, 0xcc},
1468 {0xbc, 0x00, 0x73, 0xcc}, 1566 {0xbc, 0x00, 0x73, 0xcc},
1469 {0xb8, 0x00, 0x23, 0xcc}, {0x00, 0x01, 0x0c, 0xaa}, 1567 {0xb8, 0x00, 0x23, 0xcc},
1470 {0x00, 0x14, 0x01, 0xaa}, {0x00, 0x15, 0xe6, 0xaa}, 1568 {0xb8, 0x2c, 0x50, 0xcc},
1471 {0x00, 0x16, 0x02, 0xaa}, 1569 {0xb8, 0x2d, 0xf8, 0xcc},
1472 {0x00, 0x17, 0x86, 0xaa}, {0x00, 0x23, 0x00, 0xaa}, 1570 {0xb8, 0x2e, 0xf8, 0xcc},
1473 {0x00, 0x25, 0x09, 0xaa}, {0x00, 0x26, 0x27, 0xaa}, 1571 {0xb8, 0x2f, 0xf8, 0xcc},
1474 {0x00, 0x27, 0xc0, 0xaa},
1475 {0xb8, 0x2c, 0x60, 0xcc}, {0xb8, 0x2d, 0xf8, 0xcc},
1476 {0xb8, 0x2e, 0xf8, 0xcc}, {0xb8, 0x2f, 0xf8, 0xcc},
1477 {0xb8, 0x30, 0x50, 0xcc}, 1572 {0xb8, 0x30, 0x50, 0xcc},
1478 {0xb8, 0x31, 0xf8, 0xcc}, {0xb8, 0x32, 0xf8, 0xcc}, 1573 {0xb8, 0x31, 0xf8, 0xcc},
1479 {0xb8, 0x33, 0xf8, 0xcc}, {0xb8, 0x34, 0x65, 0xcc}, 1574 {0xb8, 0x32, 0xf8, 0xcc},
1575 {0xb8, 0x33, 0xf8, 0xcc},
1576 {0xb8, 0x34, 0x58, 0xcc},
1480 {0xb8, 0x35, 0x00, 0xcc}, 1577 {0xb8, 0x35, 0x00, 0xcc},
1481 {0xb8, 0x36, 0x00, 0xcc}, {0xb8, 0x37, 0x00, 0xcc}, 1578 {0xb8, 0x36, 0x00, 0xcc},
1482 {0xb8, 0x27, 0x20, 0xcc}, {0xb8, 0x01, 0x7d, 0xcc}, 1579 {0xb8, 0x37, 0x00, 0xcc},
1580 {0xb8, 0x27, 0x20, 0xcc},
1581 {0xb8, 0x01, 0x7d, 0xcc},
1483 {0xb8, 0x81, 0x09, 0xcc}, 1582 {0xb8, 0x81, 0x09, 0xcc},
1484 {0xb3, 0x01, 0x41, 0xcc}, {0xb8, 0xfe, 0x00, 0xcc}, 1583 {0xb3, 0x01, 0x41, 0xcc},
1485 {0xb8, 0xff, 0x28, 0xcc}, {0xb9, 0x00, 0x28, 0xcc}, 1584 {0xb8, 0x8e, 0x00, 0xcc},
1486 {0xb9, 0x01, 0x28, 0xcc}, 1585 {0xb8, 0x8f, 0xff, 0xcc},
1487 {0xb9, 0x02, 0x28, 0xcc}, {0xb9, 0x03, 0x00, 0xcc}, 1586 {0x00, 0x01, 0x0c, 0xaa},
1488 {0xb9, 0x04, 0x00, 0xcc}, {0xb9, 0x05, 0x3c, 0xcc}, 1587 {0x00, 0x14, 0x01, 0xaa},
1489 {0xb9, 0x06, 0x3c, 0xcc}, 1588 {0x00, 0x15, 0xe6, 0xaa},
1490 {0xb9, 0x07, 0x3c, 0xcc}, {0xb9, 0x08, 0x3c, 0xcc}, 1589 {0x00, 0x16, 0x02, 0xaa},
1491 {0xb8, 0x8e, 0x00, 0xcc}, {0xb8, 0x8f, 0xff, 0xcc}, 1590 {0x00, 0x17, 0x86, 0xaa},
1591 {0x00, 0x23, 0x00, 0xaa},
1592 {0x00, 0x25, 0x03, 0xaa},
1593 {0x00, 0x26, 0xa9, 0xaa},
1594 {0x00, 0x27, 0x80, 0xaa},
1492 {0x00, 0x30, 0x18, 0xaa}, 1595 {0x00, 0x30, 0x18, 0xaa},
1596 {0xb6, 0x00, 0x00, 0xcc},
1597 {0xb6, 0x03, 0x02, 0xcc},
1598 {0xb6, 0x02, 0x80, 0xcc},
1599 {0xb6, 0x05, 0x01, 0xcc},
1600 {0xb6, 0x04, 0xe0, 0xcc},
1601 {0xb6, 0x12, 0x78, 0xcc},
1602 {0xb6, 0x18, 0x02, 0xcc},
1603 {0xb6, 0x17, 0x58, 0xcc},
1604 {0xb6, 0x16, 0x00, 0xcc},
1605 {0xb6, 0x22, 0x12, 0xcc},
1606 {0xb6, 0x23, 0x0b, 0xcc},
1607 {0xb3, 0x02, 0x02, 0xcc},
1608 {0xbf, 0xc0, 0x39, 0xcc},
1609 {0xbf, 0xc1, 0x04, 0xcc},
1610 {0xbf, 0xcc, 0x10, 0xcc},
1611 {0xb6, 0x12, 0xf8, 0xcc},
1612 {0xb6, 0x13, 0x13, 0xcc},
1613 {0xb9, 0x12, 0x00, 0xcc},
1614 {0xb9, 0x13, 0x0a, 0xcc},
1615 {0xb9, 0x14, 0x0a, 0xcc},
1616 {0xb9, 0x15, 0x0a, 0xcc},
1617 {0xb9, 0x16, 0x0a, 0xcc},
1618 {0xb8, 0x0c, 0x20, 0xcc},
1619 {0xb8, 0x0d, 0x70, 0xcc},
1620 {0xb9, 0x18, 0x00, 0xcc},
1621 {0xb9, 0x19, 0x0f, 0xcc},
1622 {0xb9, 0x1a, 0x0f, 0xcc},
1623 {0xb9, 0x1b, 0x0f, 0xcc},
1624 {0xb9, 0x1c, 0x0f, 0xcc},
1625 {0xb3, 0x5c, 0x01, 0xcc},
1493 {} 1626 {}
1494}; 1627};
1495 1628
1496static const __u8 hv7131r_initQVGA_data[][4] = { 1629static const u8 hv7131r_initQVGA_data[][4] = {
1497 {0xb0, 0x4d, 0x00, 0xcc}, {0xb3, 0x01, 0x01, 0xcc}, 1630 {0xb3, 0x01, 0x01, 0xcc},
1498 {0x00, 0x00, 0x50, 0xdd}, {0xb0, 0x03, 0x01, 0xcc}, 1631 {0xb0, 0x03, 0x19, 0xcc},
1632 {0xb0, 0x04, 0x02, 0xcc},
1633 {0x00, 0x00, 0x20, 0xdd},
1499 {0xb3, 0x00, 0x24, 0xcc}, 1634 {0xb3, 0x00, 0x24, 0xcc},
1500 {0xb3, 0x00, 0x25, 0xcc}, {0xb3, 0x08, 0x01, 0xcc}, 1635 {0xb3, 0x00, 0x25, 0xcc},
1501 {0xb3, 0x09, 0x0c, 0xcc}, {0xb3, 0x05, 0x00, 0xcc}, 1636 {0xb3, 0x08, 0x01, 0xcc},
1502 {0xb3, 0x06, 0x01, 0xcc}, 1637 {0xb3, 0x09, 0x0c, 0xcc},
1503 {0xb3, 0x03, 0x0b, 0xcc}, {0xb3, 0x04, 0x05, 0xcc}, 1638 {0xb3, 0x05, 0x01, 0xcc},
1504 {0xb3, 0x20, 0x00, 0xcc}, {0xb3, 0x21, 0x00, 0xcc}, 1639 {0xb3, 0x06, 0x03, 0xcc},
1640 {0xb3, 0x01, 0x45, 0xcc},
1641 {0xb3, 0x03, 0x0b, 0xcc},
1642 {0xb3, 0x04, 0x05, 0xcc},
1643 {0xb3, 0x20, 0x00, 0xcc},
1644 {0xb3, 0x21, 0x00, 0xcc},
1505 {0xb3, 0x22, 0x01, 0xcc}, 1645 {0xb3, 0x22, 0x01, 0xcc},
1506 {0xb3, 0x23, 0xe0, 0xcc}, {0xb3, 0x14, 0x00, 0xcc}, 1646 {0xb3, 0x23, 0xe0, 0xcc},
1507 {0xb3, 0x15, 0x00, 0xcc}, {0xb3, 0x16, 0x02, 0xcc}, 1647 {0xb3, 0x14, 0x00, 0xcc},
1648 {0xb3, 0x15, 0x02, 0xcc},
1649 {0xb3, 0x16, 0x02, 0xcc},
1508 {0xb3, 0x17, 0x7f, 0xcc}, 1650 {0xb3, 0x17, 0x7f, 0xcc},
1509 {0xb3, 0x34, 0x01, 0xcc}, {0xb3, 0x35, 0x91, 0xcc}, 1651 {0xb3, 0x34, 0x01, 0xcc},
1510 {0xb3, 0x00, 0x27, 0xcc}, {0xbc, 0x00, 0xd1, 0xcc}, 1652 {0xb3, 0x35, 0x91, 0xcc},
1511 {0xb8, 0x00, 0x21, 0xcc}, 1653 {0xb3, 0x00, 0x27, 0xcc},
1512 {0x00, 0x01, 0x0c, 0xaa}, {0x00, 0x14, 0x01, 0xaa}, 1654 {0xbc, 0x00, 0xd3, 0xcc},
1513 {0x00, 0x15, 0xe6, 0xaa}, {0x00, 0x16, 0x02, 0xaa}, 1655 {0xb8, 0x00, 0x23, 0xcc},
1514 {0x00, 0x17, 0x86, 0xaa}, 1656 {0xb8, 0x2c, 0x50, 0xcc},
1515 {0x00, 0x23, 0x00, 0xaa}, {0x00, 0x25, 0x01, 0xaa}, 1657 {0xb8, 0x2d, 0xf8, 0xcc},
1516 {0x00, 0x26, 0xd4, 0xaa}, {0x00, 0x27, 0xc0, 0xaa}, 1658 {0xb8, 0x2e, 0xf8, 0xcc},
1517 {0xbc, 0x02, 0x08, 0xcc}, 1659 {0xb8, 0x2f, 0xf8, 0xcc},
1518 {0xbc, 0x03, 0x70, 0xcc}, {0xbc, 0x04, 0x08, 0xcc},
1519 {0xbc, 0x05, 0x00, 0xcc}, {0xbc, 0x06, 0x00, 0xcc},
1520 {0xbc, 0x08, 0x3c, 0xcc},
1521 {0xbc, 0x09, 0x40, 0xcc}, {0xbc, 0x0a, 0x04, 0xcc},
1522 {0xbc, 0x0b, 0x00, 0xcc}, {0xbc, 0x0c, 0x00, 0xcc},
1523 {0xb8, 0xfe, 0x02, 0xcc},
1524 {0xb8, 0xff, 0x07, 0xcc}, {0xb9, 0x00, 0x14, 0xcc},
1525 {0xb9, 0x01, 0x14, 0xcc}, {0xb9, 0x02, 0x14, 0xcc},
1526 {0xb9, 0x03, 0x00, 0xcc},
1527 {0xb9, 0x04, 0x02, 0xcc}, {0xb9, 0x05, 0x05, 0xcc},
1528 {0xb9, 0x06, 0x0f, 0xcc}, {0xb9, 0x07, 0x0f, 0xcc},
1529 {0xb9, 0x08, 0x0f, 0xcc},
1530 {0xb8, 0x2c, 0x60, 0xcc}, {0xb8, 0x2d, 0xf8, 0xcc},
1531 {0xb8, 0x2e, 0xf8, 0xcc}, {0xb8, 0x2f, 0xf8, 0xcc},
1532 {0xb8, 0x30, 0x50, 0xcc}, 1660 {0xb8, 0x30, 0x50, 0xcc},
1533 {0xb8, 0x31, 0xf8, 0xcc}, {0xb8, 0x32, 0xf8, 0xcc}, 1661 {0xb8, 0x31, 0xf8, 0xcc},
1662 {0xb8, 0x32, 0xf8, 0xcc},
1534 {0xb8, 0x33, 0xf8, 0xcc}, 1663 {0xb8, 0x33, 0xf8, 0xcc},
1535 {0xb8, 0x34, 0x65, 0xcc}, {0xb8, 0x35, 0x00, 0xcc}, 1664 {0xb8, 0x34, 0x58, 0xcc},
1536 {0xb8, 0x36, 0x00, 0xcc}, {0xb8, 0x37, 0x00, 0xcc}, 1665 {0xb8, 0x35, 0x00, 0xcc},
1666 {0xb8, 0x36, 0x00, 0xcc},
1667 {0xb8, 0x37, 0x00, 0xcc},
1537 {0xb8, 0x27, 0x20, 0xcc}, 1668 {0xb8, 0x27, 0x20, 0xcc},
1538 {0xb8, 0x01, 0x7d, 0xcc}, {0xb8, 0x81, 0x09, 0xcc}, 1669 {0xb8, 0x01, 0x7d, 0xcc},
1539 {0xb3, 0x01, 0x41, 0xcc}, {0xb8, 0xfe, 0x00, 0xcc}, 1670 {0xb8, 0x81, 0x09, 0xcc},
1540 {0xb8, 0xff, 0x28, 0xcc}, 1671 {0xb3, 0x01, 0x41, 0xcc},
1541 {0xb9, 0x00, 0x28, 0xcc}, {0xb9, 0x01, 0x28, 0xcc},
1542 {0xb9, 0x02, 0x28, 0xcc}, {0xb9, 0x03, 0x00, 0xcc},
1543 {0xb9, 0x04, 0x00, 0xcc},
1544 {0xb9, 0x05, 0x3c, 0xcc}, {0xb9, 0x06, 0x3c, 0xcc},
1545 {0xb9, 0x07, 0x3c, 0xcc}, {0xb9, 0x08, 0x3c, 0xcc},
1546 {0xb8, 0x8e, 0x00, 0xcc}, 1672 {0xb8, 0x8e, 0x00, 0xcc},
1547 {0xb8, 0x8f, 0xff, 0xcc}, {0x00, 0x30, 0x18, 0xaa}, 1673 {0xb8, 0x8f, 0xff, 0xcc},
1674 {0x00, 0x01, 0x0c, 0xaa},
1675 {0x00, 0x14, 0x01, 0xaa},
1676 {0x00, 0x15, 0xe6, 0xaa},
1677 {0x00, 0x16, 0x02, 0xaa},
1678 {0x00, 0x17, 0x86, 0xaa},
1679 {0x00, 0x23, 0x00, 0xaa},
1680 {0x00, 0x25, 0x03, 0xaa},
1681 {0x00, 0x26, 0xa9, 0xaa},
1682 {0x00, 0x27, 0x80, 0xaa},
1683 {0x00, 0x30, 0x18, 0xaa},
1684 {0xb6, 0x00, 0x00, 0xcc},
1685 {0xb6, 0x03, 0x01, 0xcc},
1686 {0xb6, 0x02, 0x40, 0xcc},
1687 {0xb6, 0x05, 0x00, 0xcc},
1688 {0xb6, 0x04, 0xf0, 0xcc},
1689 {0xb6, 0x12, 0x78, 0xcc},
1690 {0xb6, 0x18, 0x00, 0xcc},
1691 {0xb6, 0x17, 0x96, 0xcc},
1692 {0xb6, 0x16, 0x00, 0xcc},
1693 {0xb6, 0x22, 0x12, 0xcc},
1694 {0xb6, 0x23, 0x0b, 0xcc},
1695 {0xb3, 0x02, 0x02, 0xcc},
1696 {0xbf, 0xc0, 0x39, 0xcc},
1697 {0xbf, 0xc1, 0x04, 0xcc},
1698 {0xbf, 0xcc, 0x10, 0xcc},
1699 {0xbc, 0x02, 0x18, 0xcc},
1700 {0xbc, 0x03, 0x50, 0xcc},
1701 {0xbc, 0x04, 0x18, 0xcc},
1702 {0xbc, 0x05, 0x00, 0xcc},
1703 {0xbc, 0x06, 0x00, 0xcc},
1704 {0xbc, 0x08, 0x30, 0xcc},
1705 {0xbc, 0x09, 0x40, 0xcc},
1706 {0xbc, 0x0a, 0x10, 0xcc},
1707 {0xbc, 0x0b, 0x00, 0xcc},
1708 {0xbc, 0x0c, 0x00, 0xcc},
1709 {0xb9, 0x12, 0x00, 0xcc},
1710 {0xb9, 0x13, 0x0a, 0xcc},
1711 {0xb9, 0x14, 0x0a, 0xcc},
1712 {0xb9, 0x15, 0x0a, 0xcc},
1713 {0xb9, 0x16, 0x0a, 0xcc},
1714 {0xb9, 0x18, 0x00, 0xcc},
1715 {0xb9, 0x19, 0x0f, 0xcc},
1716 {0xb8, 0x0c, 0x20, 0xcc},
1717 {0xb8, 0x0d, 0x70, 0xcc},
1718 {0xb9, 0x1a, 0x0f, 0xcc},
1719 {0xb9, 0x1b, 0x0f, 0xcc},
1720 {0xb9, 0x1c, 0x0f, 0xcc},
1721 {0xb6, 0x12, 0xf8, 0xcc},
1722 {0xb6, 0x13, 0x13, 0xcc},
1723 {0xb3, 0x5c, 0x01, 0xcc},
1548 {} 1724 {}
1549}; 1725};
1550 1726
1551static const __u8 ov7660_gamma[17] = { 1727static const u8 ov7660_gamma[17] = {
1552 0x00, 0x13, 0x38, 0x59, 0x79, 0x92, 0xa7, 0xb9, 0xc8, 1728 0x00, 0x13, 0x38, 0x59, 0x79, 0x92, 0xa7, 0xb9, 0xc8,
1553 0xd4, 0xdf, 0xe7, 0xee, 0xf4, 0xf9, 0xfc, 0xff 1729 0xd4, 0xdf, 0xe7, 0xee, 0xf4, 0xf9, 0xfc, 0xff
1554}; 1730};
1555static const __u8 ov7660_matrix[9] = { 1731static const u8 ov7660_matrix[9] = {
1556 0x5a, 0xf0, 0xf6, 0xf3, 0x57, 0xf6, 0xf3, 0xef, 0x62 1732 0x5a, 0xf0, 0xf6, 0xf3, 0x57, 0xf6, 0xf3, 0xef, 0x62
1557}; 1733};
1558static const __u8 ov7660_initVGA_data[][4] = { 1734static const u8 ov7660_initVGA_data[][4] = {
1559 {0xb0, 0x4d, 0x00, 0xcc}, {0xb3, 0x01, 0x01, 0xcc}, 1735 {0xb0, 0x4d, 0x00, 0xcc}, {0xb3, 0x01, 0x01, 0xcc},
1560 {0x00, 0x00, 0x50, 0xdd}, 1736 {0x00, 0x00, 0x50, 0xdd},
1561 {0xb0, 0x03, 0x01, 0xcc}, 1737 {0xb0, 0x03, 0x01, 0xcc},
@@ -1613,7 +1789,7 @@ static const __u8 ov7660_initVGA_data[][4] = {
1613 {0x00, 0x29, 0x3c, 0xaa}, {0xb3, 0x01, 0x45, 0xcc}, 1789 {0x00, 0x29, 0x3c, 0xaa}, {0xb3, 0x01, 0x45, 0xcc},
1614 {} 1790 {}
1615}; 1791};
1616static const __u8 ov7660_initQVGA_data[][4] = { 1792static const u8 ov7660_initQVGA_data[][4] = {
1617 {0xb0, 0x4d, 0x00, 0xcc}, {0xb3, 0x01, 0x01, 0xcc}, 1793 {0xb0, 0x4d, 0x00, 0xcc}, {0xb3, 0x01, 0x01, 0xcc},
1618 {0x00, 0x00, 0x50, 0xdd}, {0xb0, 0x03, 0x01, 0xcc}, 1794 {0x00, 0x00, 0x50, 0xdd}, {0xb0, 0x03, 0x01, 0xcc},
1619 {0xb3, 0x00, 0x21, 0xcc}, {0xb3, 0x00, 0x26, 0xcc}, 1795 {0xb3, 0x00, 0x21, 0xcc}, {0xb3, 0x00, 0x26, 0xcc},
@@ -1682,26 +1858,26 @@ static const __u8 ov7660_initQVGA_data[][4] = {
1682 {} 1858 {}
1683}; 1859};
1684 1860
1685static const __u8 ov7660_50HZ[][4] = { 1861static const u8 ov7660_50HZ[][4] = {
1686 {0x00, 0x3b, 0x08, 0xaa}, 1862 {0x00, 0x3b, 0x08, 0xaa},
1687 {0x00, 0x9d, 0x40, 0xaa}, 1863 {0x00, 0x9d, 0x40, 0xaa},
1688 {0x00, 0x13, 0xa7, 0xaa}, 1864 {0x00, 0x13, 0xa7, 0xaa},
1689 {} 1865 {}
1690}; 1866};
1691 1867
1692static const __u8 ov7660_60HZ[][4] = { 1868static const u8 ov7660_60HZ[][4] = {
1693 {0x00, 0x3b, 0x00, 0xaa}, 1869 {0x00, 0x3b, 0x00, 0xaa},
1694 {0x00, 0x9e, 0x40, 0xaa}, 1870 {0x00, 0x9e, 0x40, 0xaa},
1695 {0x00, 0x13, 0xa7, 0xaa}, 1871 {0x00, 0x13, 0xa7, 0xaa},
1696 {} 1872 {}
1697}; 1873};
1698 1874
1699static const __u8 ov7660_NoFliker[][4] = { 1875static const u8 ov7660_NoFliker[][4] = {
1700 {0x00, 0x13, 0x87, 0xaa}, 1876 {0x00, 0x13, 0x87, 0xaa},
1701 {} 1877 {}
1702}; 1878};
1703 1879
1704static const __u8 ov7670_initVGA_JPG[][4] = { 1880static const u8 ov7670_initVGA_JPG[][4] = {
1705 {0xb3, 0x01, 0x05, 0xcc}, 1881 {0xb3, 0x01, 0x05, 0xcc},
1706 {0x00, 0x00, 0x30, 0xdd}, {0xb0, 0x03, 0x19, 0xcc}, 1882 {0x00, 0x00, 0x30, 0xdd}, {0xb0, 0x03, 0x19, 0xcc},
1707 {0x00, 0x00, 0x10, 0xdd}, 1883 {0x00, 0x00, 0x10, 0xdd},
@@ -1831,7 +2007,7 @@ static const __u8 ov7670_initVGA_JPG[][4] = {
1831 {}, 2007 {},
1832}; 2008};
1833 2009
1834static const __u8 ov7670_initQVGA_JPG[][4] = { 2010static const u8 ov7670_initQVGA_JPG[][4] = {
1835 {0xb3, 0x01, 0x05, 0xcc}, {0x00, 0x00, 0x30, 0xdd}, 2011 {0xb3, 0x01, 0x05, 0xcc}, {0x00, 0x00, 0x30, 0xdd},
1836 {0xb0, 0x03, 0x19, 0xcc}, {0x00, 0x00, 0x10, 0xdd}, 2012 {0xb0, 0x03, 0x19, 0xcc}, {0x00, 0x00, 0x10, 0xdd},
1837 {0xb0, 0x04, 0x02, 0xcc}, {0x00, 0x00, 0x10, 0xdd}, 2013 {0xb0, 0x04, 0x02, 0xcc}, {0x00, 0x00, 0x10, 0xdd},
@@ -1966,14 +2142,14 @@ static const __u8 ov7670_initQVGA_JPG[][4] = {
1966}; 2142};
1967 2143
1968/* PO1200 - values from usbvm326.inf and ms-win trace */ 2144/* PO1200 - values from usbvm326.inf and ms-win trace */
1969static const __u8 po1200_gamma[17] = { 2145static const u8 po1200_gamma[17] = {
1970 0x00, 0x13, 0x38, 0x59, 0x79, 0x92, 0xa7, 0xb9, 0xc8, 2146 0x00, 0x13, 0x38, 0x59, 0x79, 0x92, 0xa7, 0xb9, 0xc8,
1971 0xd4, 0xdf, 0xe7, 0xee, 0xf4, 0xf9, 0xfc, 0xff 2147 0xd4, 0xdf, 0xe7, 0xee, 0xf4, 0xf9, 0xfc, 0xff
1972}; 2148};
1973static const __u8 po1200_matrix[9] = { 2149static const u8 po1200_matrix[9] = {
1974 0x60, 0xf9, 0xe5, 0xe7, 0x50, 0x05, 0xf3, 0xe6, 0x5e 2150 0x60, 0xf9, 0xe5, 0xe7, 0x50, 0x05, 0xf3, 0xe6, 0x5e
1975}; 2151};
1976static const __u8 po1200_initVGA_data[][4] = { 2152static const u8 po1200_initVGA_data[][4] = {
1977 {0xb0, 0x03, 0x19, 0xcc}, /* reset? */ 2153 {0xb0, 0x03, 0x19, 0xcc}, /* reset? */
1978 {0xb0, 0x03, 0x19, 0xcc}, 2154 {0xb0, 0x03, 0x19, 0xcc},
1979/* {0x00, 0x00, 0x33, 0xdd}, */ 2155/* {0x00, 0x00, 0x33, 0xdd}, */
@@ -2276,9 +2452,9 @@ static const struct sensor_info sensor_info_data[] = {
2276 2452
2277/* read 'len' bytes in gspca_dev->usb_buf */ 2453/* read 'len' bytes in gspca_dev->usb_buf */
2278static void reg_r(struct gspca_dev *gspca_dev, 2454static void reg_r(struct gspca_dev *gspca_dev,
2279 __u16 req, 2455 u16 req,
2280 __u16 index, 2456 u16 index,
2281 __u16 len) 2457 u16 len)
2282{ 2458{
2283 usb_control_msg(gspca_dev->dev, 2459 usb_control_msg(gspca_dev->dev,
2284 usb_rcvctrlpipe(gspca_dev->dev, 0), 2460 usb_rcvctrlpipe(gspca_dev->dev, 0),
@@ -2290,9 +2466,9 @@ static void reg_r(struct gspca_dev *gspca_dev,
2290} 2466}
2291 2467
2292static void reg_w(struct usb_device *dev, 2468static void reg_w(struct usb_device *dev,
2293 __u16 req, 2469 u16 req,
2294 __u16 value, 2470 u16 value,
2295 __u16 index) 2471 u16 index)
2296{ 2472{
2297 usb_control_msg(dev, 2473 usb_control_msg(dev,
2298 usb_sndctrlpipe(dev, 0), 2474 usb_sndctrlpipe(dev, 0),
@@ -2342,11 +2518,18 @@ static u16 read_sensor_register(struct gspca_dev *gspca_dev,
2342 2518
2343static int vc032x_probe_sensor(struct gspca_dev *gspca_dev) 2519static int vc032x_probe_sensor(struct gspca_dev *gspca_dev)
2344{ 2520{
2521 struct sd *sd = (struct sd *) gspca_dev;
2345 struct usb_device *dev = gspca_dev->dev; 2522 struct usb_device *dev = gspca_dev->dev;
2346 int i; 2523 int i;
2347 u16 value; 2524 u16 value;
2348 const struct sensor_info *ptsensor_info; 2525 const struct sensor_info *ptsensor_info;
2349 2526
2527/*fixme: should also check the other sensor (back mi1320_soc, front mc501cb)*/
2528 if (sd->flags & FL_SAMSUNG) {
2529 reg_w(dev, 0xa0, 0x01, 0xb301);
2530 reg_w(dev, 0x89, 0xf0ff, 0xffff); /* select the back sensor */
2531 }
2532
2350 reg_r(gspca_dev, 0xa1, 0xbfcf, 1); 2533 reg_r(gspca_dev, 0xa1, 0xbfcf, 1);
2351 PDEBUG(D_PROBE, "check sensor header %02x", gspca_dev->usb_buf[0]); 2534 PDEBUG(D_PROBE, "check sensor header %02x", gspca_dev->usb_buf[0]);
2352 for (i = 0; i < ARRAY_SIZE(sensor_info_data); i++) { 2535 for (i = 0; i < ARRAY_SIZE(sensor_info_data); i++) {
@@ -2406,17 +2589,17 @@ static void i2c_write(struct gspca_dev *gspca_dev,
2406} 2589}
2407 2590
2408static void put_tab_to_reg(struct gspca_dev *gspca_dev, 2591static void put_tab_to_reg(struct gspca_dev *gspca_dev,
2409 const __u8 *tab, __u8 tabsize, __u16 addr) 2592 const u8 *tab, u8 tabsize, u16 addr)
2410{ 2593{
2411 int j; 2594 int j;
2412 __u16 ad = addr; 2595 u16 ad = addr;
2413 2596
2414 for (j = 0; j < tabsize; j++) 2597 for (j = 0; j < tabsize; j++)
2415 reg_w(gspca_dev->dev, 0xa0, tab[j], ad++); 2598 reg_w(gspca_dev->dev, 0xa0, tab[j], ad++);
2416} 2599}
2417 2600
2418static void usb_exchange(struct gspca_dev *gspca_dev, 2601static void usb_exchange(struct gspca_dev *gspca_dev,
2419 const __u8 data[][4]) 2602 const u8 data[][4])
2420{ 2603{
2421 struct usb_device *dev = gspca_dev->dev; 2604 struct usb_device *dev = gspca_dev->dev;
2422 int i = 0; 2605 int i = 0;
@@ -2466,7 +2649,8 @@ static int sd_config(struct gspca_dev *gspca_dev,
2466 }; 2649 };
2467 2650
2468 cam = &gspca_dev->cam; 2651 cam = &gspca_dev->cam;
2469 sd->bridge = id->driver_info; 2652 sd->bridge = id->driver_info >> 8;
2653 sd->flags = id->driver_info & 0xff;
2470 sensor = vc032x_probe_sensor(gspca_dev); 2654 sensor = vc032x_probe_sensor(gspca_dev);
2471 switch (sensor) { 2655 switch (sensor) {
2472 case -1: 2656 case -1:
@@ -2519,8 +2703,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
2519 case SENSOR_MI1320_SOC: 2703 case SENSOR_MI1320_SOC:
2520 cam->cam_mode = bi_mode; 2704 cam->cam_mode = bi_mode;
2521 cam->nmodes = ARRAY_SIZE(bi_mode); 2705 cam->nmodes = ARRAY_SIZE(bi_mode);
2522 cam->input_flags = V4L2_IN_ST_VFLIP |
2523 V4L2_IN_ST_HFLIP;
2524 break; 2706 break;
2525 default: 2707 default:
2526 cam->cam_mode = vc0323_mode; 2708 cam->cam_mode = vc0323_mode;
@@ -2532,14 +2714,14 @@ static int sd_config(struct gspca_dev *gspca_dev,
2532 2714
2533 sd->hflip = HFLIP_DEF; 2715 sd->hflip = HFLIP_DEF;
2534 sd->vflip = VFLIP_DEF; 2716 sd->vflip = VFLIP_DEF;
2535 if (sd->sensor == SENSOR_OV7670) { 2717 if (sd->sensor == SENSOR_OV7670)
2536 sd->hflip = 1; 2718 sd->flags |= FL_HFLIP | FL_VFLIP;
2537 sd->vflip = 1;
2538 }
2539 sd->lightfreq = FREQ_DEF; 2719 sd->lightfreq = FREQ_DEF;
2540 if (sd->sensor != SENSOR_OV7670) 2720 if (sd->sensor != SENSOR_OV7670)
2541 gspca_dev->ctrl_dis = (1 << LIGHTFREQ_IDX); 2721 gspca_dev->ctrl_dis = (1 << LIGHTFREQ_IDX);
2542 switch (sd->sensor) { 2722 switch (sd->sensor) {
2723 case SENSOR_MI1310_SOC:
2724 case SENSOR_MI1320_SOC:
2543 case SENSOR_OV7660: 2725 case SENSOR_OV7660:
2544 case SENSOR_OV7670: 2726 case SENSOR_OV7670:
2545 case SENSOR_PO1200: 2727 case SENSOR_PO1200:
@@ -2568,39 +2750,50 @@ static int sd_init(struct gspca_dev *gspca_dev)
2568 return 0; 2750 return 0;
2569} 2751}
2570 2752
2571/* for OV7660 and OV7670 only */ 2753/* some sensors only */
2572static void sethvflip(struct gspca_dev *gspca_dev) 2754static void sethvflip(struct gspca_dev *gspca_dev)
2573{ 2755{
2574 struct sd *sd = (struct sd *) gspca_dev; 2756 struct sd *sd = (struct sd *) gspca_dev;
2575 __u8 data; 2757 u8 data[2], hflip, vflip;
2576 2758
2759 hflip = sd->hflip;
2760 if (sd->flags & FL_HFLIP)
2761 hflip = !hflip;
2762 vflip = sd->vflip;
2763 if (sd->flags & FL_VFLIP)
2764 vflip = !vflip;
2577 switch (sd->sensor) { 2765 switch (sd->sensor) {
2578 case SENSOR_OV7660: 2766 case SENSOR_MI1310_SOC:
2579 data = 1; 2767 case SENSOR_MI1320_SOC:
2768 data[0] = data[1] = 0; /* select page 0 */
2769 i2c_write(gspca_dev, 0xf0, data, 2);
2770 data[0] = sd->sensor == SENSOR_MI1310_SOC ? 0x03 : 0x01;
2771 data[1] = 0x02 * hflip
2772 | 0x01 * vflip;
2773 i2c_write(gspca_dev, 0x20, data, 2);
2580 break; 2774 break;
2775 case SENSOR_OV7660:
2581 case SENSOR_OV7670: 2776 case SENSOR_OV7670:
2582 data = 7; 2777 data[0] = sd->sensor == SENSOR_OV7660 ? 0x01 : 0x07;
2778 data[0] |= OV7660_MVFP_MIRROR * hflip
2779 | OV7660_MVFP_VFLIP * vflip;
2780 i2c_write(gspca_dev, OV7660_REG_MVFP, data, 1);
2583 break; 2781 break;
2584 case SENSOR_PO1200: 2782 case SENSOR_PO1200:
2585 data = 0; 2783 data[0] = 0;
2586 i2c_write(gspca_dev, 0x03, &data, 1); 2784 i2c_write(gspca_dev, 0x03, data, 1);
2587 data = 0x80 * sd->hflip 2785 data[0] = 0x80 * hflip
2588 | 0x40 * sd->vflip 2786 | 0x40 * vflip
2589 | 0x06; 2787 | 0x06;
2590 i2c_write(gspca_dev, 0x1e, &data, 1); 2788 i2c_write(gspca_dev, 0x1e, data, 1);
2591 return; 2789 break;
2592 default:
2593 return;
2594 } 2790 }
2595 data |= OV7660_MVFP_MIRROR * sd->hflip
2596 | OV7660_MVFP_VFLIP * sd->vflip;
2597 i2c_write(gspca_dev, OV7660_REG_MVFP, &data, 1);
2598} 2791}
2599 2792
2600static void setlightfreq(struct gspca_dev *gspca_dev) 2793static void setlightfreq(struct gspca_dev *gspca_dev)
2601{ 2794{
2602 struct sd *sd = (struct sd *) gspca_dev; 2795 struct sd *sd = (struct sd *) gspca_dev;
2603 static const __u8 (*ov7660_freq_tb[3])[4] = 2796 static const u8 (*ov7660_freq_tb[3])[4] =
2604 {ov7660_NoFliker, ov7660_50HZ, ov7660_60HZ}; 2797 {ov7660_NoFliker, ov7660_50HZ, ov7660_60HZ};
2605 2798
2606 if (sd->sensor != SENSOR_OV7660) 2799 if (sd->sensor != SENSOR_OV7660)
@@ -2612,7 +2805,7 @@ static void setlightfreq(struct gspca_dev *gspca_dev)
2612static void setsharpness(struct gspca_dev *gspca_dev) 2805static void setsharpness(struct gspca_dev *gspca_dev)
2613{ 2806{
2614 struct sd *sd = (struct sd *) gspca_dev; 2807 struct sd *sd = (struct sd *) gspca_dev;
2615 __u8 data; 2808 u8 data;
2616 2809
2617 if (sd->sensor != SENSOR_PO1200) 2810 if (sd->sensor != SENSOR_PO1200)
2618 return; 2811 return;
@@ -2625,9 +2818,9 @@ static void setsharpness(struct gspca_dev *gspca_dev)
2625static int sd_start(struct gspca_dev *gspca_dev) 2818static int sd_start(struct gspca_dev *gspca_dev)
2626{ 2819{
2627 struct sd *sd = (struct sd *) gspca_dev; 2820 struct sd *sd = (struct sd *) gspca_dev;
2628 const __u8 (*init)[4]; 2821 const u8 (*init)[4];
2629 const __u8 *GammaT = NULL; 2822 const u8 *GammaT = NULL;
2630 const __u8 *MatrixT = NULL; 2823 const u8 *MatrixT = NULL;
2631 int mode; 2824 int mode;
2632 static const u8 (*mi1320_soc_init[])[4] = { 2825 static const u8 (*mi1320_soc_init[])[4] = {
2633 mi1320_soc_InitSXGA, 2826 mi1320_soc_InitSXGA,
@@ -2635,6 +2828,13 @@ static int sd_start(struct gspca_dev *gspca_dev)
2635 mi1320_soc_InitQVGA, 2828 mi1320_soc_InitQVGA,
2636 }; 2829 };
2637 2830
2831/*fixme: back sensor only*/
2832 if (sd->flags & FL_SAMSUNG) {
2833 reg_w(gspca_dev->dev, 0x89, 0xf0ff, 0xffff);
2834 reg_w(gspca_dev->dev, 0xa9, 0x8348, 0x000e);
2835 reg_w(gspca_dev->dev, 0xa9, 0x0000, 0x001a);
2836 }
2837
2638 /* Assume start use the good resolution from gspca_dev->mode */ 2838 /* Assume start use the good resolution from gspca_dev->mode */
2639 if (sd->bridge == BRIDGE_VC0321) { 2839 if (sd->bridge == BRIDGE_VC0321) {
2640 reg_w(gspca_dev->dev, 0xa0, 0xff, 0xbfec); 2840 reg_w(gspca_dev->dev, 0xa0, 0xff, 0xbfec);
@@ -2737,16 +2937,22 @@ static int sd_start(struct gspca_dev *gspca_dev)
2737 put_tab_to_reg(gspca_dev, MatrixT, 9, 0xb82c); 2937 put_tab_to_reg(gspca_dev, MatrixT, 9, 0xb82c);
2738 2938
2739 /* set the led on 0x0892 0x0896 */ 2939 /* set the led on 0x0892 0x0896 */
2740 if (sd->sensor != SENSOR_PO1200) { 2940 switch (sd->sensor) {
2741 reg_w(gspca_dev->dev, 0x89, 0xffff, 0xfdff); 2941 case SENSOR_PO1200:
2742 msleep(100); 2942 case SENSOR_HV7131R:
2743 sethvflip(gspca_dev);
2744 setlightfreq(gspca_dev);
2745 } else {
2746 setsharpness(gspca_dev);
2747 sethvflip(gspca_dev);
2748 reg_w(gspca_dev->dev, 0x89, 0x0400, 0x1415); 2943 reg_w(gspca_dev->dev, 0x89, 0x0400, 0x1415);
2944 break;
2945 case SENSOR_MI1310_SOC:
2946 reg_w(gspca_dev->dev, 0x89, 0x058c, 0x0000);
2947 break;
2948 default:
2949 reg_w(gspca_dev->dev, 0x89, 0xffff, 0xfdff);
2950 break;
2749 } 2951 }
2952 msleep(100);
2953 setsharpness(gspca_dev);
2954 sethvflip(gspca_dev);
2955 setlightfreq(gspca_dev);
2750 } 2956 }
2751 return 0; 2957 return 0;
2752} 2958}
@@ -2754,8 +2960,12 @@ static int sd_start(struct gspca_dev *gspca_dev)
2754static void sd_stopN(struct gspca_dev *gspca_dev) 2960static void sd_stopN(struct gspca_dev *gspca_dev)
2755{ 2961{
2756 struct usb_device *dev = gspca_dev->dev; 2962 struct usb_device *dev = gspca_dev->dev;
2963 struct sd *sd = (struct sd *) gspca_dev;
2757 2964
2758 reg_w(dev, 0x89, 0xffff, 0xffff); 2965 if (sd->sensor == SENSOR_MI1310_SOC)
2966 reg_w(dev, 0x89, 0x058c, 0x00ff);
2967 else
2968 reg_w(dev, 0x89, 0xffff, 0xffff);
2759 reg_w(dev, 0xa0, 0x01, 0xb301); 2969 reg_w(dev, 0xa0, 0x01, 0xb301);
2760 reg_w(dev, 0xa0, 0x09, 0xb003); 2970 reg_w(dev, 0xa0, 0x09, 0xb003);
2761} 2971}
@@ -2764,15 +2974,20 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
2764static void sd_stop0(struct gspca_dev *gspca_dev) 2974static void sd_stop0(struct gspca_dev *gspca_dev)
2765{ 2975{
2766 struct usb_device *dev = gspca_dev->dev; 2976 struct usb_device *dev = gspca_dev->dev;
2977 struct sd *sd = (struct sd *) gspca_dev;
2767 2978
2768 if (!gspca_dev->present) 2979 if (!gspca_dev->present)
2769 return; 2980 return;
2770 reg_w(dev, 0x89, 0xffff, 0xffff); 2981/*fixme: is this useful?*/
2982 if (sd->sensor == SENSOR_MI1310_SOC)
2983 reg_w(dev, 0x89, 0x058c, 0x00ff);
2984 else
2985 reg_w(dev, 0x89, 0xffff, 0xffff);
2771} 2986}
2772 2987
2773static void sd_pkt_scan(struct gspca_dev *gspca_dev, 2988static void sd_pkt_scan(struct gspca_dev *gspca_dev,
2774 struct gspca_frame *frame, /* target */ 2989 struct gspca_frame *frame, /* target */
2775 __u8 *data, /* isoc packet */ 2990 u8 *data, /* isoc packet */
2776 int len) /* iso pkt length */ 2991 int len) /* iso pkt length */
2777{ 2992{
2778 struct sd *sd = (struct sd *) gspca_dev; 2993 struct sd *sd = (struct sd *) gspca_dev;
@@ -2872,21 +3087,12 @@ static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
2872static int sd_querymenu(struct gspca_dev *gspca_dev, 3087static int sd_querymenu(struct gspca_dev *gspca_dev,
2873 struct v4l2_querymenu *menu) 3088 struct v4l2_querymenu *menu)
2874{ 3089{
3090 static const char *freq_nm[3] = {"NoFliker", "50 Hz", "60 Hz"};
3091
2875 switch (menu->id) { 3092 switch (menu->id) {
2876 case V4L2_CID_POWER_LINE_FREQUENCY: 3093 case V4L2_CID_POWER_LINE_FREQUENCY:
2877 switch (menu->index) { 3094 strcpy((char *) menu->name, freq_nm[menu->index]);
2878 case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */ 3095 return 0;
2879 strcpy((char *) menu->name, "NoFliker");
2880 return 0;
2881 case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
2882 strcpy((char *) menu->name, "50 Hz");
2883 return 0;
2884 default:
2885/* case 2: * V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
2886 strcpy((char *) menu->name, "60 Hz");
2887 return 0;
2888 }
2889 break;
2890 } 3096 }
2891 return -EINVAL; 3097 return -EINVAL;
2892} 3098}
@@ -2906,19 +3112,23 @@ static const struct sd_desc sd_desc = {
2906}; 3112};
2907 3113
2908/* -- module initialisation -- */ 3114/* -- module initialisation -- */
3115#define BF(bridge, flags) \
3116 .driver_info = (BRIDGE_ ## bridge << 8) \
3117 | (flags)
2909static const __devinitdata struct usb_device_id device_table[] = { 3118static const __devinitdata struct usb_device_id device_table[] = {
2910 {USB_DEVICE(0x041e, 0x405b), .driver_info = BRIDGE_VC0323}, 3119 {USB_DEVICE(0x041e, 0x405b), BF(VC0323, FL_VFLIP)},
2911 {USB_DEVICE(0x046d, 0x0892), .driver_info = BRIDGE_VC0321}, 3120 {USB_DEVICE(0x046d, 0x0892), BF(VC0321, 0)},
2912 {USB_DEVICE(0x046d, 0x0896), .driver_info = BRIDGE_VC0321}, 3121 {USB_DEVICE(0x046d, 0x0896), BF(VC0321, 0)},
2913 {USB_DEVICE(0x046d, 0x0897), .driver_info = BRIDGE_VC0321}, 3122 {USB_DEVICE(0x046d, 0x0897), BF(VC0321, 0)},
2914 {USB_DEVICE(0x0ac8, 0x0321), .driver_info = BRIDGE_VC0321}, 3123 {USB_DEVICE(0x0ac8, 0x0321), BF(VC0321, 0)},
2915 {USB_DEVICE(0x0ac8, 0x0323), .driver_info = BRIDGE_VC0323}, 3124 {USB_DEVICE(0x0ac8, 0x0323), BF(VC0323, 0)},
2916 {USB_DEVICE(0x0ac8, 0x0328), .driver_info = BRIDGE_VC0321}, 3125 {USB_DEVICE(0x0ac8, 0x0328), BF(VC0321, 0)},
2917 {USB_DEVICE(0x0ac8, 0xc001), .driver_info = BRIDGE_VC0321}, 3126 {USB_DEVICE(0x0ac8, 0xc001), BF(VC0321, 0)},
2918 {USB_DEVICE(0x0ac8, 0xc002), .driver_info = BRIDGE_VC0321}, 3127 {USB_DEVICE(0x0ac8, 0xc002), BF(VC0321, 0)},
2919 {USB_DEVICE(0x15b8, 0x6001), .driver_info = BRIDGE_VC0323}, 3128 {USB_DEVICE(0x0ac8, 0xc301), BF(VC0323, FL_SAMSUNG)},
2920 {USB_DEVICE(0x15b8, 0x6002), .driver_info = BRIDGE_VC0323}, 3129 {USB_DEVICE(0x15b8, 0x6001), BF(VC0323, 0)},
2921 {USB_DEVICE(0x17ef, 0x4802), .driver_info = BRIDGE_VC0323}, 3130 {USB_DEVICE(0x15b8, 0x6002), BF(VC0323, 0)},
3131 {USB_DEVICE(0x17ef, 0x4802), BF(VC0323, 0)},
2922 {} 3132 {}
2923}; 3133};
2924MODULE_DEVICE_TABLE(usb, device_table); 3134MODULE_DEVICE_TABLE(usb, device_table);
diff --git a/drivers/media/video/gspca/zc3xx.c b/drivers/media/video/gspca/zc3xx.c
index 3d2756f7874a..cdf3357b4c9f 100644
--- a/drivers/media/video/gspca/zc3xx.c
+++ b/drivers/media/video/gspca/zc3xx.c
@@ -7574,7 +7574,7 @@ static int sd_get_jcomp(struct gspca_dev *gspca_dev,
7574static const struct sd_desc sd_desc = { 7574static const struct sd_desc sd_desc = {
7575 .name = MODULE_NAME, 7575 .name = MODULE_NAME,
7576 .ctrls = sd_ctrls, 7576 .ctrls = sd_ctrls,
7577 .nctrls = sizeof sd_ctrls / sizeof sd_ctrls[0], 7577 .nctrls = ARRAY_SIZE(sd_ctrls),
7578 .config = sd_config, 7578 .config = sd_config,
7579 .init = sd_init, 7579 .init = sd_init,
7580 .start = sd_start, 7580 .start = sd_start,
diff --git a/drivers/media/video/hdpvr/hdpvr-control.c b/drivers/media/video/hdpvr/hdpvr-control.c
index 06791749d1a0..5a6b78b8d25d 100644
--- a/drivers/media/video/hdpvr/hdpvr-control.c
+++ b/drivers/media/video/hdpvr/hdpvr-control.c
@@ -178,24 +178,24 @@ error:
178 178
179int hdpvr_set_options(struct hdpvr_device *dev) 179int hdpvr_set_options(struct hdpvr_device *dev)
180{ 180{
181 hdpvr_config_call(dev, CTRL_VIDEO_STD_TYPE, dev->options.video_std); 181 hdpvr_config_call(dev, CTRL_VIDEO_STD_TYPE, dev->options.video_std);
182 182
183 hdpvr_config_call(dev, CTRL_VIDEO_INPUT_VALUE, 183 hdpvr_config_call(dev, CTRL_VIDEO_INPUT_VALUE,
184 dev->options.video_input+1); 184 dev->options.video_input+1);
185 185
186 hdpvr_set_audio(dev, dev->options.audio_input+1, 186 hdpvr_set_audio(dev, dev->options.audio_input+1,
187 dev->options.audio_codec); 187 dev->options.audio_codec);
188 188
189 hdpvr_set_bitrate(dev); 189 hdpvr_set_bitrate(dev);
190 hdpvr_config_call(dev, CTRL_BITRATE_MODE_VALUE, 190 hdpvr_config_call(dev, CTRL_BITRATE_MODE_VALUE,
191 dev->options.bitrate_mode); 191 dev->options.bitrate_mode);
192 hdpvr_config_call(dev, CTRL_GOP_MODE_VALUE, dev->options.gop_mode); 192 hdpvr_config_call(dev, CTRL_GOP_MODE_VALUE, dev->options.gop_mode);
193 193
194 hdpvr_config_call(dev, CTRL_BRIGHTNESS, dev->options.brightness); 194 hdpvr_config_call(dev, CTRL_BRIGHTNESS, dev->options.brightness);
195 hdpvr_config_call(dev, CTRL_CONTRAST, dev->options.contrast); 195 hdpvr_config_call(dev, CTRL_CONTRAST, dev->options.contrast);
196 hdpvr_config_call(dev, CTRL_HUE, dev->options.hue); 196 hdpvr_config_call(dev, CTRL_HUE, dev->options.hue);
197 hdpvr_config_call(dev, CTRL_SATURATION, dev->options.saturation); 197 hdpvr_config_call(dev, CTRL_SATURATION, dev->options.saturation);
198 hdpvr_config_call(dev, CTRL_SHARPNESS, dev->options.sharpness); 198 hdpvr_config_call(dev, CTRL_SHARPNESS, dev->options.sharpness);
199 199
200 return 0; 200 return 0;
201} 201}
diff --git a/drivers/media/video/hdpvr/hdpvr-core.c b/drivers/media/video/hdpvr/hdpvr-core.c
index 188bd5aea258..1c9bc94c905c 100644
--- a/drivers/media/video/hdpvr/hdpvr-core.c
+++ b/drivers/media/video/hdpvr/hdpvr-core.c
@@ -126,7 +126,7 @@ static int device_authorization(struct hdpvr_device *dev)
126 char *print_buf = kzalloc(5*buf_size+1, GFP_KERNEL); 126 char *print_buf = kzalloc(5*buf_size+1, GFP_KERNEL);
127 if (!print_buf) { 127 if (!print_buf) {
128 v4l2_err(&dev->v4l2_dev, "Out of memory\n"); 128 v4l2_err(&dev->v4l2_dev, "Out of memory\n");
129 goto error; 129 return retval;
130 } 130 }
131#endif 131#endif
132 132
@@ -140,7 +140,7 @@ static int device_authorization(struct hdpvr_device *dev)
140 if (ret != 46) { 140 if (ret != 46) {
141 v4l2_err(&dev->v4l2_dev, 141 v4l2_err(&dev->v4l2_dev,
142 "unexpected answer of status request, len %d\n", ret); 142 "unexpected answer of status request, len %d\n", ret);
143 goto error; 143 goto unlock;
144 } 144 }
145#ifdef HDPVR_DEBUG 145#ifdef HDPVR_DEBUG
146 else { 146 else {
@@ -163,7 +163,7 @@ static int device_authorization(struct hdpvr_device *dev)
163 v4l2_err(&dev->v4l2_dev, "unknown firmware version 0x%x\n", 163 v4l2_err(&dev->v4l2_dev, "unknown firmware version 0x%x\n",
164 dev->usbc_buf[1]); 164 dev->usbc_buf[1]);
165 ret = -EINVAL; 165 ret = -EINVAL;
166 goto error; 166 goto unlock;
167 } 167 }
168 168
169 response = dev->usbc_buf+38; 169 response = dev->usbc_buf+38;
@@ -188,10 +188,10 @@ static int device_authorization(struct hdpvr_device *dev)
188 10000); 188 10000);
189 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev, 189 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
190 "magic request returned %d\n", ret); 190 "magic request returned %d\n", ret);
191 mutex_unlock(&dev->usbc_mutex);
192 191
193 retval = ret != 8; 192 retval = ret != 8;
194error: 193unlock:
194 mutex_unlock(&dev->usbc_mutex);
195 return retval; 195 return retval;
196} 196}
197 197
@@ -350,6 +350,7 @@ static int hdpvr_probe(struct usb_interface *interface,
350 350
351 mutex_lock(&dev->io_mutex); 351 mutex_lock(&dev->io_mutex);
352 if (hdpvr_alloc_buffers(dev, NUM_BUFFERS)) { 352 if (hdpvr_alloc_buffers(dev, NUM_BUFFERS)) {
353 mutex_unlock(&dev->io_mutex);
353 v4l2_err(&dev->v4l2_dev, 354 v4l2_err(&dev->v4l2_dev,
354 "allocating transfer buffers failed\n"); 355 "allocating transfer buffers failed\n");
355 goto error; 356 goto error;
@@ -381,7 +382,6 @@ static int hdpvr_probe(struct usb_interface *interface,
381 382
382error: 383error:
383 if (dev) { 384 if (dev) {
384 mutex_unlock(&dev->io_mutex);
385 /* this frees allocated memory */ 385 /* this frees allocated memory */
386 hdpvr_delete(dev); 386 hdpvr_delete(dev);
387 } 387 }
diff --git a/drivers/media/video/hdpvr/hdpvr-i2c.c b/drivers/media/video/hdpvr/hdpvr-i2c.c
index c4b5d1515c10..296330a0e1e5 100644
--- a/drivers/media/video/hdpvr/hdpvr-i2c.c
+++ b/drivers/media/video/hdpvr/hdpvr-i2c.c
@@ -127,7 +127,6 @@ int hdpvr_register_i2c_adapter(struct hdpvr_device *dev)
127 sizeof(i2c_adap->name)); 127 sizeof(i2c_adap->name));
128 i2c_adap->algo = &hdpvr_algo; 128 i2c_adap->algo = &hdpvr_algo;
129 i2c_adap->class = I2C_CLASS_TV_ANALOG; 129 i2c_adap->class = I2C_CLASS_TV_ANALOG;
130 i2c_adap->id = I2C_HW_B_HDPVR;
131 i2c_adap->owner = THIS_MODULE; 130 i2c_adap->owner = THIS_MODULE;
132 i2c_adap->dev.parent = &dev->udev->dev; 131 i2c_adap->dev.parent = &dev->udev->dev;
133 132
diff --git a/drivers/media/video/hdpvr/hdpvr-video.c b/drivers/media/video/hdpvr/hdpvr-video.c
index d678765cbba2..2eb9dc2ebe59 100644
--- a/drivers/media/video/hdpvr/hdpvr-video.c
+++ b/drivers/media/video/hdpvr/hdpvr-video.c
@@ -375,6 +375,7 @@ static int hdpvr_open(struct file *file)
375 * in resumption */ 375 * in resumption */
376 mutex_lock(&dev->io_mutex); 376 mutex_lock(&dev->io_mutex);
377 dev->open_count++; 377 dev->open_count++;
378 mutex_unlock(&dev->io_mutex);
378 379
379 fh->dev = dev; 380 fh->dev = dev;
380 381
@@ -383,7 +384,6 @@ static int hdpvr_open(struct file *file)
383 384
384 retval = 0; 385 retval = 0;
385err: 386err:
386 mutex_unlock(&dev->io_mutex);
387 return retval; 387 return retval;
388} 388}
389 389
@@ -519,8 +519,10 @@ static unsigned int hdpvr_poll(struct file *filp, poll_table *wait)
519 519
520 mutex_lock(&dev->io_mutex); 520 mutex_lock(&dev->io_mutex);
521 521
522 if (video_is_unregistered(dev->video_dev)) 522 if (video_is_unregistered(dev->video_dev)) {
523 mutex_unlock(&dev->io_mutex);
523 return -EIO; 524 return -EIO;
525 }
524 526
525 if (dev->status == STATUS_IDLE) { 527 if (dev->status == STATUS_IDLE) {
526 if (hdpvr_start_streaming(dev)) { 528 if (hdpvr_start_streaming(dev)) {
diff --git a/drivers/media/video/ir-kbd-i2c.c b/drivers/media/video/ir-kbd-i2c.c
index 86f2fefe1edf..247d3115a9b7 100644
--- a/drivers/media/video/ir-kbd-i2c.c
+++ b/drivers/media/video/ir-kbd-i2c.c
@@ -122,12 +122,12 @@ static int get_key_haup_common(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw,
122 return 1; 122 return 1;
123} 123}
124 124
125static inline int get_key_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) 125static int get_key_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
126{ 126{
127 return get_key_haup_common (ir, ir_key, ir_raw, 3, 0); 127 return get_key_haup_common (ir, ir_key, ir_raw, 3, 0);
128} 128}
129 129
130static inline int get_key_haup_xvr(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) 130static int get_key_haup_xvr(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
131{ 131{
132 return get_key_haup_common (ir, ir_key, ir_raw, 6, 3); 132 return get_key_haup_common (ir, ir_key, ir_raw, 6, 3);
133} 133}
@@ -297,7 +297,7 @@ static void ir_work(struct work_struct *work)
297 297
298static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id) 298static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
299{ 299{
300 IR_KEYTAB_TYPE *ir_codes = NULL; 300 struct ir_scancode_table *ir_codes = NULL;
301 const char *name = NULL; 301 const char *name = NULL;
302 int ir_type; 302 int ir_type;
303 struct IR_i2c *ir; 303 struct IR_i2c *ir;
@@ -322,13 +322,13 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
322 name = "Pixelview"; 322 name = "Pixelview";
323 ir->get_key = get_key_pixelview; 323 ir->get_key = get_key_pixelview;
324 ir_type = IR_TYPE_OTHER; 324 ir_type = IR_TYPE_OTHER;
325 ir_codes = ir_codes_empty; 325 ir_codes = &ir_codes_empty_table;
326 break; 326 break;
327 case 0x4b: 327 case 0x4b:
328 name = "PV951"; 328 name = "PV951";
329 ir->get_key = get_key_pv951; 329 ir->get_key = get_key_pv951;
330 ir_type = IR_TYPE_OTHER; 330 ir_type = IR_TYPE_OTHER;
331 ir_codes = ir_codes_pv951; 331 ir_codes = &ir_codes_pv951_table;
332 break; 332 break;
333 case 0x18: 333 case 0x18:
334 case 0x1a: 334 case 0x1a:
@@ -336,36 +336,38 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
336 ir->get_key = get_key_haup; 336 ir->get_key = get_key_haup;
337 ir_type = IR_TYPE_RC5; 337 ir_type = IR_TYPE_RC5;
338 if (hauppauge == 1) { 338 if (hauppauge == 1) {
339 ir_codes = ir_codes_hauppauge_new; 339 ir_codes = &ir_codes_hauppauge_new_table;
340 } else { 340 } else {
341 ir_codes = ir_codes_rc5_tv; 341 ir_codes = &ir_codes_rc5_tv_table;
342 } 342 }
343 break; 343 break;
344 case 0x30: 344 case 0x30:
345 name = "KNC One"; 345 name = "KNC One";
346 ir->get_key = get_key_knc1; 346 ir->get_key = get_key_knc1;
347 ir_type = IR_TYPE_OTHER; 347 ir_type = IR_TYPE_OTHER;
348 ir_codes = ir_codes_empty; 348 ir_codes = &ir_codes_empty_table;
349 break; 349 break;
350 case 0x6b: 350 case 0x6b:
351 name = "FusionHDTV"; 351 name = "FusionHDTV";
352 ir->get_key = get_key_fusionhdtv; 352 ir->get_key = get_key_fusionhdtv;
353 ir_type = IR_TYPE_RC5; 353 ir_type = IR_TYPE_RC5;
354 ir_codes = ir_codes_fusionhdtv_mce; 354 ir_codes = &ir_codes_fusionhdtv_mce_table;
355 break; 355 break;
356 case 0x7a: 356 case 0x7a:
357 case 0x47: 357 case 0x47:
358 case 0x71: 358 case 0x71:
359 case 0x2d: 359 case 0x2d:
360 if (adap->id == I2C_HW_B_CX2388x) { 360 if (adap->id == I2C_HW_B_CX2388x ||
361 adap->id == I2C_HW_B_CX2341X) {
361 /* Handled by cx88-input */ 362 /* Handled by cx88-input */
362 name = "CX2388x remote"; 363 name = adap->id == I2C_HW_B_CX2341X ? "CX2341x remote"
364 : "CX2388x remote";
363 ir_type = IR_TYPE_RC5; 365 ir_type = IR_TYPE_RC5;
364 ir->get_key = get_key_haup_xvr; 366 ir->get_key = get_key_haup_xvr;
365 if (hauppauge == 1) { 367 if (hauppauge == 1) {
366 ir_codes = ir_codes_hauppauge_new; 368 ir_codes = &ir_codes_hauppauge_new_table;
367 } else { 369 } else {
368 ir_codes = ir_codes_rc5_tv; 370 ir_codes = &ir_codes_rc5_tv_table;
369 } 371 }
370 } else { 372 } else {
371 /* Handled by saa7134-input */ 373 /* Handled by saa7134-input */
@@ -377,7 +379,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
377 name = "AVerMedia Cardbus remote"; 379 name = "AVerMedia Cardbus remote";
378 ir->get_key = get_key_avermedia_cardbus; 380 ir->get_key = get_key_avermedia_cardbus;
379 ir_type = IR_TYPE_OTHER; 381 ir_type = IR_TYPE_OTHER;
380 ir_codes = ir_codes_avermedia_cardbus; 382 ir_codes = &ir_codes_avermedia_cardbus_table;
381 break; 383 break;
382 default: 384 default:
383 dprintk(1, DEVNAME ": Unsupported i2c address 0x%02x\n", addr); 385 dprintk(1, DEVNAME ": Unsupported i2c address 0x%02x\n", addr);
@@ -392,7 +394,36 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
392 394
393 ir_codes = init_data->ir_codes; 395 ir_codes = init_data->ir_codes;
394 name = init_data->name; 396 name = init_data->name;
395 ir->get_key = init_data->get_key; 397 if (init_data->type)
398 ir_type = init_data->type;
399
400 switch (init_data->internal_get_key_func) {
401 case IR_KBD_GET_KEY_CUSTOM:
402 /* The bridge driver provided us its own function */
403 ir->get_key = init_data->get_key;
404 break;
405 case IR_KBD_GET_KEY_PIXELVIEW:
406 ir->get_key = get_key_pixelview;
407 break;
408 case IR_KBD_GET_KEY_PV951:
409 ir->get_key = get_key_pv951;
410 break;
411 case IR_KBD_GET_KEY_HAUP:
412 ir->get_key = get_key_haup;
413 break;
414 case IR_KBD_GET_KEY_KNC1:
415 ir->get_key = get_key_knc1;
416 break;
417 case IR_KBD_GET_KEY_FUSIONHDTV:
418 ir->get_key = get_key_fusionhdtv;
419 break;
420 case IR_KBD_GET_KEY_HAUP_XVR:
421 ir->get_key = get_key_haup_xvr;
422 break;
423 case IR_KBD_GET_KEY_AVERMEDIA_CARDBUS:
424 ir->get_key = get_key_avermedia_cardbus;
425 break;
426 }
396 } 427 }
397 428
398 /* Make sure we are all setup before going on */ 429 /* Make sure we are all setup before going on */
@@ -454,7 +485,8 @@ static int ir_remove(struct i2c_client *client)
454static const struct i2c_device_id ir_kbd_id[] = { 485static const struct i2c_device_id ir_kbd_id[] = {
455 /* Generic entry for any IR receiver */ 486 /* Generic entry for any IR receiver */
456 { "ir_video", 0 }, 487 { "ir_video", 0 },
457 /* IR device specific entries could be added here */ 488 /* IR device specific entries should be added here */
489 { "ir_rx_z8f0811_haup", 0 },
458 { } 490 { }
459}; 491};
460 492
diff --git a/drivers/media/video/ivtv/ivtv-cards.c b/drivers/media/video/ivtv/ivtv-cards.c
index 2883c8780760..4873b6ca5801 100644
--- a/drivers/media/video/ivtv/ivtv-cards.c
+++ b/drivers/media/video/ivtv/ivtv-cards.c
@@ -977,26 +977,27 @@ static const struct ivtv_card ivtv_card_avertv_mce116 = {
977 977
978/* ------------------------------------------------------------------------- */ 978/* ------------------------------------------------------------------------- */
979 979
980/* AVerMedia PVR-150 Plus (M113) card */ 980/* AVerMedia PVR-150 Plus / AVerTV M113 cards with a Daewoo/Partsnic Tuner */
981 981
982static const struct ivtv_card_pci_info ivtv_pci_aver_pvr150[] = { 982static const struct ivtv_card_pci_info ivtv_pci_aver_pvr150[] = {
983 { PCI_DEVICE_ID_IVTV16, IVTV_PCI_ID_AVERMEDIA, 0xc035 }, 983 { PCI_DEVICE_ID_IVTV16, IVTV_PCI_ID_AVERMEDIA, 0xc034 }, /* NTSC */
984 { PCI_DEVICE_ID_IVTV16, IVTV_PCI_ID_AVERMEDIA, 0xc035 }, /* NTSC FM */
984 { 0, 0, 0 } 985 { 0, 0, 0 }
985}; 986};
986 987
987static const struct ivtv_card ivtv_card_aver_pvr150 = { 988static const struct ivtv_card ivtv_card_aver_pvr150 = {
988 .type = IVTV_CARD_AVER_PVR150PLUS, 989 .type = IVTV_CARD_AVER_PVR150PLUS,
989 .name = "AVerMedia PVR-150 Plus", 990 .name = "AVerMedia PVR-150 Plus / AVerTV M113 Partsnic (Daewoo) Tuner",
990 .v4l2_capabilities = IVTV_CAP_ENCODER, 991 .v4l2_capabilities = IVTV_CAP_ENCODER,
991 .hw_video = IVTV_HW_CX25840, 992 .hw_video = IVTV_HW_CX25840,
992 .hw_audio = IVTV_HW_CX25840, 993 .hw_audio = IVTV_HW_CX25840,
993 .hw_audio_ctrl = IVTV_HW_CX25840, 994 .hw_audio_ctrl = IVTV_HW_CX25840,
994 .hw_muxer = IVTV_HW_GPIO, 995 .hw_muxer = IVTV_HW_GPIO,
995 .hw_all = IVTV_HW_CX25840 | IVTV_HW_TUNER, 996 .hw_all = IVTV_HW_CX25840 | IVTV_HW_TUNER |
997 IVTV_HW_WM8739 | IVTV_HW_GPIO,
996 .video_inputs = { 998 .video_inputs = {
997 { IVTV_CARD_INPUT_VID_TUNER, 0, CX25840_COMPOSITE2 }, 999 { IVTV_CARD_INPUT_VID_TUNER, 0, CX25840_COMPOSITE2 },
998 { IVTV_CARD_INPUT_SVIDEO1, 1, 1000 { IVTV_CARD_INPUT_SVIDEO1, 1, CX25840_SVIDEO3 },
999 CX25840_SVIDEO_LUMA3 | CX25840_SVIDEO_CHROMA4 },
1000 { IVTV_CARD_INPUT_COMPOSITE1, 1, CX25840_COMPOSITE1 }, 1001 { IVTV_CARD_INPUT_COMPOSITE1, 1, CX25840_COMPOSITE1 },
1001 }, 1002 },
1002 .audio_inputs = { 1003 .audio_inputs = {
@@ -1004,18 +1005,66 @@ static const struct ivtv_card ivtv_card_aver_pvr150 = {
1004 { IVTV_CARD_INPUT_LINE_IN1, CX25840_AUDIO_SERIAL, 1 }, 1005 { IVTV_CARD_INPUT_LINE_IN1, CX25840_AUDIO_SERIAL, 1 },
1005 }, 1006 },
1006 .radio_input = { IVTV_CARD_INPUT_AUD_TUNER, CX25840_AUDIO_SERIAL, 2 }, 1007 .radio_input = { IVTV_CARD_INPUT_AUD_TUNER, CX25840_AUDIO_SERIAL, 2 },
1007 .gpio_init = { .direction = 0x0800, .initial_value = 0 }, 1008 /* The 74HC4052 Dual 4:1 multiplexer is controlled by 2 GPIO lines */
1008 .gpio_audio_input = { .mask = 0x0800, .tuner = 0, .linein = 0, .radio = 0x0800 }, 1009 .gpio_init = { .direction = 0xc000, .initial_value = 0 },
1010 .gpio_audio_input = { .mask = 0xc000,
1011 .tuner = 0x0000,
1012 .linein = 0x4000,
1013 .radio = 0x8000 },
1009 .tuners = { 1014 .tuners = {
1010 /* This card has a Partsnic PTI-5NF05 tuner */ 1015 /* Subsystem ID's 0xc03[45] have a Partsnic PTI-5NF05 tuner */
1011 { .std = V4L2_STD_MN, .tuner = TUNER_TCL_2002N }, 1016 { .std = V4L2_STD_MN, .tuner = TUNER_PARTSNIC_PTI_5NF05 },
1012 }, 1017 },
1013 .pci_list = ivtv_pci_aver_pvr150, 1018 .pci_list = ivtv_pci_aver_pvr150,
1019 /* Subsystem ID 0xc035 has a TEA5767(?) FM tuner, 0xc034 does not */
1014 .i2c = &ivtv_i2c_radio, 1020 .i2c = &ivtv_i2c_radio,
1015}; 1021};
1016 1022
1017/* ------------------------------------------------------------------------- */ 1023/* ------------------------------------------------------------------------- */
1018 1024
1025/* AVerMedia UltraTV 1500 MCE (newer non-cx88 version, M113 variant) card */
1026
1027static const struct ivtv_card_pci_info ivtv_pci_aver_ultra1500mce[] = {
1028 { PCI_DEVICE_ID_IVTV16, IVTV_PCI_ID_AVERMEDIA, 0xc019 },
1029 { 0, 0, 0 }
1030};
1031
1032static const struct ivtv_card ivtv_card_aver_ultra1500mce = {
1033 .type = IVTV_CARD_AVER_ULTRA1500MCE,
1034 .name = "AVerMedia UltraTV 1500 MCE / AVerTV M113 Philips Tuner",
1035 .v4l2_capabilities = IVTV_CAP_ENCODER,
1036 .hw_video = IVTV_HW_CX25840,
1037 .hw_audio = IVTV_HW_CX25840,
1038 .hw_audio_ctrl = IVTV_HW_CX25840,
1039 .hw_muxer = IVTV_HW_GPIO,
1040 .hw_all = IVTV_HW_CX25840 | IVTV_HW_TUNER |
1041 IVTV_HW_WM8739 | IVTV_HW_GPIO,
1042 .video_inputs = {
1043 { IVTV_CARD_INPUT_VID_TUNER, 0, CX25840_COMPOSITE2 },
1044 { IVTV_CARD_INPUT_SVIDEO1, 1, CX25840_SVIDEO3 },
1045 { IVTV_CARD_INPUT_COMPOSITE1, 1, CX25840_COMPOSITE1 },
1046 },
1047 .audio_inputs = {
1048 { IVTV_CARD_INPUT_AUD_TUNER, CX25840_AUDIO5, 0 },
1049 { IVTV_CARD_INPUT_LINE_IN1, CX25840_AUDIO_SERIAL, 1 },
1050 },
1051 .radio_input = { IVTV_CARD_INPUT_AUD_TUNER, CX25840_AUDIO_SERIAL, 2 },
1052 /* The 74HC4052 Dual 4:1 multiplexer is controlled by 2 GPIO lines */
1053 .gpio_init = { .direction = 0xc000, .initial_value = 0 },
1054 .gpio_audio_input = { .mask = 0xc000,
1055 .tuner = 0x0000,
1056 .linein = 0x4000,
1057 .radio = 0x8000 },
1058 .tuners = {
1059 /* The UltraTV 1500 MCE has a Philips FM1236 MK5 TV/FM tuner */
1060 { .std = V4L2_STD_MN, .tuner = TUNER_PHILIPS_FM1236_MK3 },
1061 },
1062 .pci_list = ivtv_pci_aver_ultra1500mce,
1063 .i2c = &ivtv_i2c_std,
1064};
1065
1066/* ------------------------------------------------------------------------- */
1067
1019/* AVerMedia EZMaker PCI Deluxe card */ 1068/* AVerMedia EZMaker PCI Deluxe card */
1020 1069
1021static const struct ivtv_card_pci_info ivtv_pci_aver_ezmaker[] = { 1070static const struct ivtv_card_pci_info ivtv_pci_aver_ezmaker[] = {
@@ -1180,6 +1229,7 @@ static const struct ivtv_card *ivtv_card_list[] = {
1180 &ivtv_card_aver_ezmaker, 1229 &ivtv_card_aver_ezmaker,
1181 &ivtv_card_aver_m104, 1230 &ivtv_card_aver_m104,
1182 &ivtv_card_buffalo, 1231 &ivtv_card_buffalo,
1232 &ivtv_card_aver_ultra1500mce,
1183 1233
1184 /* Variations of standard cards but with the same PCI IDs. 1234 /* Variations of standard cards but with the same PCI IDs.
1185 These cards must come last in this list. */ 1235 These cards must come last in this list. */
diff --git a/drivers/media/video/ivtv/ivtv-cards.h b/drivers/media/video/ivtv/ivtv-cards.h
index 0b8fe85fb697..e99a0a255578 100644
--- a/drivers/media/video/ivtv/ivtv-cards.h
+++ b/drivers/media/video/ivtv/ivtv-cards.h
@@ -50,7 +50,8 @@
50#define IVTV_CARD_AVER_EZMAKER 23 /* AVerMedia EZMaker PCI Deluxe */ 50#define IVTV_CARD_AVER_EZMAKER 23 /* AVerMedia EZMaker PCI Deluxe */
51#define IVTV_CARD_AVER_M104 24 /* AverMedia M104 miniPCI card */ 51#define IVTV_CARD_AVER_M104 24 /* AverMedia M104 miniPCI card */
52#define IVTV_CARD_BUFFALO_MV5L 25 /* Buffalo PC-MV5L/PCI card */ 52#define IVTV_CARD_BUFFALO_MV5L 25 /* Buffalo PC-MV5L/PCI card */
53#define IVTV_CARD_LAST 25 53#define IVTV_CARD_AVER_ULTRA1500MCE 26 /* AVerMedia UltraTV 1500 MCE */
54#define IVTV_CARD_LAST 26
54 55
55/* Variants of existing cards but with the same PCI IDs. The driver 56/* Variants of existing cards but with the same PCI IDs. The driver
56 detects these based on other device information. 57 detects these based on other device information.
diff --git a/drivers/media/video/ivtv/ivtv-driver.c b/drivers/media/video/ivtv/ivtv-driver.c
index 558f8a837ff4..63ea0fb66063 100644
--- a/drivers/media/video/ivtv/ivtv-driver.c
+++ b/drivers/media/video/ivtv/ivtv-driver.c
@@ -186,6 +186,7 @@ MODULE_PARM_DESC(cardtype,
186 "\t\t\t24 = AverMedia EZMaker PCI Deluxe\n" 186 "\t\t\t24 = AverMedia EZMaker PCI Deluxe\n"
187 "\t\t\t25 = AverMedia M104 (not yet working)\n" 187 "\t\t\t25 = AverMedia M104 (not yet working)\n"
188 "\t\t\t26 = Buffalo PC-MV5L/PCI\n" 188 "\t\t\t26 = Buffalo PC-MV5L/PCI\n"
189 "\t\t\t27 = AVerMedia UltraTV 1500 MCE\n"
189 "\t\t\t 0 = Autodetect (default)\n" 190 "\t\t\t 0 = Autodetect (default)\n"
190 "\t\t\t-1 = Ignore this card\n\t\t"); 191 "\t\t\t-1 = Ignore this card\n\t\t");
191MODULE_PARM_DESC(pal, "Set PAL standard: BGH, DK, I, M, N, Nc, 60"); 192MODULE_PARM_DESC(pal, "Set PAL standard: BGH, DK, I, M, N, Nc, 60");
@@ -218,7 +219,7 @@ MODULE_PARM_DESC(ivtv_yuv_mode,
218 "\t\t\tDefault: 0 (interlaced)"); 219 "\t\t\tDefault: 0 (interlaced)");
219MODULE_PARM_DESC(ivtv_yuv_threshold, 220MODULE_PARM_DESC(ivtv_yuv_threshold,
220 "If ivtv_yuv_mode is 2 (auto) then playback content as\n\t\tprogressive if src height <= ivtv_yuvthreshold\n" 221 "If ivtv_yuv_mode is 2 (auto) then playback content as\n\t\tprogressive if src height <= ivtv_yuvthreshold\n"
221 "\t\t\tDefault: 480");; 222 "\t\t\tDefault: 480");
222MODULE_PARM_DESC(enc_mpg_buffers, 223MODULE_PARM_DESC(enc_mpg_buffers,
223 "Encoder MPG Buffers (in MB)\n" 224 "Encoder MPG Buffers (in MB)\n"
224 "\t\t\tDefault: " __stringify(IVTV_DEFAULT_ENC_MPG_BUFFERS)); 225 "\t\t\tDefault: " __stringify(IVTV_DEFAULT_ENC_MPG_BUFFERS));
diff --git a/drivers/media/video/ivtv/ivtv-gpio.c b/drivers/media/video/ivtv/ivtv-gpio.c
index 85ac707228e7..aede061cae5d 100644
--- a/drivers/media/video/ivtv/ivtv-gpio.c
+++ b/drivers/media/video/ivtv/ivtv-gpio.c
@@ -236,18 +236,6 @@ static int subdev_s_radio(struct v4l2_subdev *sd)
236 return 0; 236 return 0;
237} 237}
238 238
239static int subdev_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
240{
241 struct ivtv *itv = sd_to_ivtv(sd);
242 u16 mask, data;
243
244 mask = itv->card->gpio_audio_input.mask;
245 data = itv->card->gpio_audio_input.tuner;
246 if (mask)
247 write_reg((read_reg(IVTV_REG_GPIO_OUT) & ~mask) | (data & mask), IVTV_REG_GPIO_OUT);
248 return 0;
249}
250
251static int subdev_s_audio_routing(struct v4l2_subdev *sd, 239static int subdev_s_audio_routing(struct v4l2_subdev *sd,
252 u32 input, u32 output, u32 config) 240 u32 input, u32 output, u32 config)
253{ 241{
@@ -344,7 +332,6 @@ static const struct v4l2_subdev_core_ops subdev_core_ops = {
344 .g_ctrl = subdev_g_ctrl, 332 .g_ctrl = subdev_g_ctrl,
345 .s_ctrl = subdev_s_ctrl, 333 .s_ctrl = subdev_s_ctrl,
346 .queryctrl = subdev_queryctrl, 334 .queryctrl = subdev_queryctrl,
347 .s_std = subdev_s_std,
348}; 335};
349 336
350static const struct v4l2_subdev_tuner_ops subdev_tuner_ops = { 337static const struct v4l2_subdev_tuner_ops subdev_tuner_ops = {
diff --git a/drivers/media/video/ivtv/ivtv-i2c.c b/drivers/media/video/ivtv/ivtv-i2c.c
index e52aa322b134..8f15a31d3f66 100644
--- a/drivers/media/video/ivtv/ivtv-i2c.c
+++ b/drivers/media/video/ivtv/ivtv-i2c.c
@@ -509,7 +509,6 @@ static struct i2c_algorithm ivtv_algo = {
509/* template for our-bit banger */ 509/* template for our-bit banger */
510static struct i2c_adapter ivtv_i2c_adap_hw_template = { 510static struct i2c_adapter ivtv_i2c_adap_hw_template = {
511 .name = "ivtv i2c driver", 511 .name = "ivtv i2c driver",
512 .id = I2C_HW_B_CX2341X,
513 .algo = &ivtv_algo, 512 .algo = &ivtv_algo,
514 .algo_data = NULL, /* filled from template */ 513 .algo_data = NULL, /* filled from template */
515 .owner = THIS_MODULE, 514 .owner = THIS_MODULE,
@@ -560,7 +559,6 @@ static int ivtv_getsda_old(void *data)
560/* template for i2c-bit-algo */ 559/* template for i2c-bit-algo */
561static struct i2c_adapter ivtv_i2c_adap_template = { 560static struct i2c_adapter ivtv_i2c_adap_template = {
562 .name = "ivtv i2c driver", 561 .name = "ivtv i2c driver",
563 .id = I2C_HW_B_CX2341X,
564 .algo = NULL, /* set by i2c-algo-bit */ 562 .algo = NULL, /* set by i2c-algo-bit */
565 .algo_data = NULL, /* filled from template */ 563 .algo_data = NULL, /* filled from template */
566 .owner = THIS_MODULE, 564 .owner = THIS_MODULE,
diff --git a/drivers/media/video/meye.c b/drivers/media/video/meye.c
index 1d66855a379a..d0765bed79c9 100644
--- a/drivers/media/video/meye.c
+++ b/drivers/media/video/meye.c
@@ -1915,8 +1915,7 @@ static void __devexit meye_remove(struct pci_dev *pcidev)
1915} 1915}
1916 1916
1917static struct pci_device_id meye_pci_tbl[] = { 1917static struct pci_device_id meye_pci_tbl[] = {
1918 { PCI_VENDOR_ID_KAWASAKI, PCI_DEVICE_ID_MCHIP_KL5A72002, 1918 { PCI_VDEVICE(KAWASAKI, PCI_DEVICE_ID_MCHIP_KL5A72002), 0 },
1919 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
1920 { } 1919 { }
1921}; 1920};
1922 1921
diff --git a/drivers/media/video/pvrusb2/pvrusb2-audio.c b/drivers/media/video/pvrusb2/pvrusb2-audio.c
index 416933ca607d..cc06d5e4adcc 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-audio.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-audio.c
@@ -65,9 +65,10 @@ void pvr2_msp3400_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd)
65 u32 input; 65 u32 input;
66 66
67 pvr2_trace(PVR2_TRACE_CHIPS, "subdev msp3400 v4l2 set_stereo"); 67 pvr2_trace(PVR2_TRACE_CHIPS, "subdev msp3400 v4l2 set_stereo");
68 sp = (sid < ARRAY_SIZE(routing_schemes)) ?
69 routing_schemes[sid] : NULL;
68 70
69 if ((sid < ARRAY_SIZE(routing_schemes)) && 71 if ((sp != NULL) &&
70 ((sp = routing_schemes[sid]) != NULL) &&
71 (hdw->input_val >= 0) && 72 (hdw->input_val >= 0) &&
72 (hdw->input_val < sp->cnt)) { 73 (hdw->input_val < sp->cnt)) {
73 input = sp->def[hdw->input_val]; 74 input = sp->def[hdw->input_val];
diff --git a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
index 610bd848df24..a334b1a966a2 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
@@ -540,7 +540,6 @@ static struct i2c_algorithm pvr2_i2c_algo_template = {
540static struct i2c_adapter pvr2_i2c_adap_template = { 540static struct i2c_adapter pvr2_i2c_adap_template = {
541 .owner = THIS_MODULE, 541 .owner = THIS_MODULE,
542 .class = 0, 542 .class = 0,
543 .id = I2C_HW_B_BT848,
544}; 543};
545 544
546 545
diff --git a/drivers/media/video/pwc/pwc-if.c b/drivers/media/video/pwc/pwc-if.c
index 8d17cf613306..f976df452a34 100644
--- a/drivers/media/video/pwc/pwc-if.c
+++ b/drivers/media/video/pwc/pwc-if.c
@@ -1057,7 +1057,8 @@ static int pwc_create_sysfs_files(struct video_device *vdev)
1057 goto err; 1057 goto err;
1058 if (pdev->features & FEATURE_MOTOR_PANTILT) { 1058 if (pdev->features & FEATURE_MOTOR_PANTILT) {
1059 rc = device_create_file(&vdev->dev, &dev_attr_pan_tilt); 1059 rc = device_create_file(&vdev->dev, &dev_attr_pan_tilt);
1060 if (rc) goto err_button; 1060 if (rc)
1061 goto err_button;
1061 } 1062 }
1062 1063
1063 return 0; 1064 return 0;
@@ -1072,6 +1073,7 @@ err:
1072static void pwc_remove_sysfs_files(struct video_device *vdev) 1073static void pwc_remove_sysfs_files(struct video_device *vdev)
1073{ 1074{
1074 struct pwc_device *pdev = video_get_drvdata(vdev); 1075 struct pwc_device *pdev = video_get_drvdata(vdev);
1076
1075 if (pdev->features & FEATURE_MOTOR_PANTILT) 1077 if (pdev->features & FEATURE_MOTOR_PANTILT)
1076 device_remove_file(&vdev->dev, &dev_attr_pan_tilt); 1078 device_remove_file(&vdev->dev, &dev_attr_pan_tilt);
1077 device_remove_file(&vdev->dev, &dev_attr_button); 1079 device_remove_file(&vdev->dev, &dev_attr_button);
@@ -1229,13 +1231,11 @@ static void pwc_cleanup(struct pwc_device *pdev)
1229 video_unregister_device(pdev->vdev); 1231 video_unregister_device(pdev->vdev);
1230 1232
1231#ifdef CONFIG_USB_PWC_INPUT_EVDEV 1233#ifdef CONFIG_USB_PWC_INPUT_EVDEV
1232 if (pdev->button_dev) { 1234 if (pdev->button_dev)
1233 input_unregister_device(pdev->button_dev); 1235 input_unregister_device(pdev->button_dev);
1234 input_free_device(pdev->button_dev);
1235 kfree(pdev->button_dev->phys);
1236 pdev->button_dev = NULL;
1237 }
1238#endif 1236#endif
1237
1238 kfree(pdev);
1239} 1239}
1240 1240
1241/* Note that all cleanup is done in the reverse order as in _open */ 1241/* Note that all cleanup is done in the reverse order as in _open */
@@ -1281,8 +1281,6 @@ static int pwc_video_close(struct file *file)
1281 PWC_DEBUG_OPEN("<< video_close() vopen=%d\n", pdev->vopen); 1281 PWC_DEBUG_OPEN("<< video_close() vopen=%d\n", pdev->vopen);
1282 } else { 1282 } else {
1283 pwc_cleanup(pdev); 1283 pwc_cleanup(pdev);
1284 /* Free memory (don't set pdev to 0 just yet) */
1285 kfree(pdev);
1286 /* search device_hint[] table if we occupy a slot, by any chance */ 1284 /* search device_hint[] table if we occupy a slot, by any chance */
1287 for (hint = 0; hint < MAX_DEV_HINTS; hint++) 1285 for (hint = 0; hint < MAX_DEV_HINTS; hint++)
1288 if (device_hint[hint].pdev == pdev) 1286 if (device_hint[hint].pdev == pdev)
@@ -1499,13 +1497,10 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id
1499 struct usb_device *udev = interface_to_usbdev(intf); 1497 struct usb_device *udev = interface_to_usbdev(intf);
1500 struct pwc_device *pdev = NULL; 1498 struct pwc_device *pdev = NULL;
1501 int vendor_id, product_id, type_id; 1499 int vendor_id, product_id, type_id;
1502 int i, hint, rc; 1500 int hint, rc;
1503 int features = 0; 1501 int features = 0;
1504 int video_nr = -1; /* default: use next available device */ 1502 int video_nr = -1; /* default: use next available device */
1505 char serial_number[30], *name; 1503 char serial_number[30], *name;
1506#ifdef CONFIG_USB_PWC_INPUT_EVDEV
1507 char *phys = NULL;
1508#endif
1509 1504
1510 vendor_id = le16_to_cpu(udev->descriptor.idVendor); 1505 vendor_id = le16_to_cpu(udev->descriptor.idVendor);
1511 product_id = le16_to_cpu(udev->descriptor.idProduct); 1506 product_id = le16_to_cpu(udev->descriptor.idProduct);
@@ -1757,8 +1752,7 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id
1757 pdev->vframes = default_fps; 1752 pdev->vframes = default_fps;
1758 strcpy(pdev->serial, serial_number); 1753 strcpy(pdev->serial, serial_number);
1759 pdev->features = features; 1754 pdev->features = features;
1760 if (vendor_id == 0x046D && product_id == 0x08B5) 1755 if (vendor_id == 0x046D && product_id == 0x08B5) {
1761 {
1762 /* Logitech QuickCam Orbit 1756 /* Logitech QuickCam Orbit
1763 The ranges have been determined experimentally; they may differ from cam to cam. 1757 The ranges have been determined experimentally; they may differ from cam to cam.
1764 Also, the exact ranges left-right and up-down are different for my cam 1758 Also, the exact ranges left-right and up-down are different for my cam
@@ -1780,8 +1774,8 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id
1780 pdev->vdev = video_device_alloc(); 1774 pdev->vdev = video_device_alloc();
1781 if (!pdev->vdev) { 1775 if (!pdev->vdev) {
1782 PWC_ERROR("Err, cannot allocate video_device struture. Failing probe."); 1776 PWC_ERROR("Err, cannot allocate video_device struture. Failing probe.");
1783 kfree(pdev); 1777 rc = -ENOMEM;
1784 return -ENOMEM; 1778 goto err_free_mem;
1785 } 1779 }
1786 memcpy(pdev->vdev, &pwc_template, sizeof(pwc_template)); 1780 memcpy(pdev->vdev, &pwc_template, sizeof(pwc_template));
1787 pdev->vdev->parent = &intf->dev; 1781 pdev->vdev->parent = &intf->dev;
@@ -1806,25 +1800,23 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id
1806 } 1800 }
1807 1801
1808 pdev->vdev->release = video_device_release; 1802 pdev->vdev->release = video_device_release;
1809 i = video_register_device(pdev->vdev, VFL_TYPE_GRABBER, video_nr); 1803 rc = video_register_device(pdev->vdev, VFL_TYPE_GRABBER, video_nr);
1810 if (i < 0) { 1804 if (rc < 0) {
1811 PWC_ERROR("Failed to register as video device (%d).\n", i); 1805 PWC_ERROR("Failed to register as video device (%d).\n", rc);
1812 rc = i; 1806 goto err_video_release;
1813 goto err;
1814 }
1815 else {
1816 PWC_INFO("Registered as /dev/video%d.\n", pdev->vdev->num);
1817 } 1807 }
1818 1808
1809 PWC_INFO("Registered as /dev/video%d.\n", pdev->vdev->num);
1810
1819 /* occupy slot */ 1811 /* occupy slot */
1820 if (hint < MAX_DEV_HINTS) 1812 if (hint < MAX_DEV_HINTS)
1821 device_hint[hint].pdev = pdev; 1813 device_hint[hint].pdev = pdev;
1822 1814
1823 PWC_DEBUG_PROBE("probe() function returning struct at 0x%p.\n", pdev); 1815 PWC_DEBUG_PROBE("probe() function returning struct at 0x%p.\n", pdev);
1824 usb_set_intfdata (intf, pdev); 1816 usb_set_intfdata(intf, pdev);
1825 rc = pwc_create_sysfs_files(pdev->vdev); 1817 rc = pwc_create_sysfs_files(pdev->vdev);
1826 if (rc) 1818 if (rc)
1827 goto err_unreg; 1819 goto err_video_unreg;
1828 1820
1829 /* Set the leds off */ 1821 /* Set the leds off */
1830 pwc_set_leds(pdev, 0, 0); 1822 pwc_set_leds(pdev, 0, 0);
@@ -1835,16 +1827,16 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id
1835 pdev->button_dev = input_allocate_device(); 1827 pdev->button_dev = input_allocate_device();
1836 if (!pdev->button_dev) { 1828 if (!pdev->button_dev) {
1837 PWC_ERROR("Err, insufficient memory for webcam snapshot button device."); 1829 PWC_ERROR("Err, insufficient memory for webcam snapshot button device.");
1838 return -ENOMEM; 1830 rc = -ENOMEM;
1831 pwc_remove_sysfs_files(pdev->vdev);
1832 goto err_video_unreg;
1839 } 1833 }
1840 1834
1835 usb_make_path(udev, pdev->button_phys, sizeof(pdev->button_phys));
1836 strlcat(pdev->button_phys, "/input0", sizeof(pdev->button_phys));
1837
1841 pdev->button_dev->name = "PWC snapshot button"; 1838 pdev->button_dev->name = "PWC snapshot button";
1842 phys = kasprintf(GFP_KERNEL,"usb-%s-%s", pdev->udev->bus->bus_name, pdev->udev->devpath); 1839 pdev->button_dev->phys = pdev->button_phys;
1843 if (!phys) {
1844 input_free_device(pdev->button_dev);
1845 return -ENOMEM;
1846 }
1847 pdev->button_dev->phys = phys;
1848 usb_to_input_id(pdev->udev, &pdev->button_dev->id); 1840 usb_to_input_id(pdev->udev, &pdev->button_dev->id);
1849 pdev->button_dev->dev.parent = &pdev->udev->dev; 1841 pdev->button_dev->dev.parent = &pdev->udev->dev;
1850 pdev->button_dev->evbit[0] = BIT_MASK(EV_KEY); 1842 pdev->button_dev->evbit[0] = BIT_MASK(EV_KEY);
@@ -1853,25 +1845,27 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id
1853 rc = input_register_device(pdev->button_dev); 1845 rc = input_register_device(pdev->button_dev);
1854 if (rc) { 1846 if (rc) {
1855 input_free_device(pdev->button_dev); 1847 input_free_device(pdev->button_dev);
1856 kfree(pdev->button_dev->phys);
1857 pdev->button_dev = NULL; 1848 pdev->button_dev = NULL;
1858 return rc; 1849 pwc_remove_sysfs_files(pdev->vdev);
1850 goto err_video_unreg;
1859 } 1851 }
1860#endif 1852#endif
1861 1853
1862 return 0; 1854 return 0;
1863 1855
1864err_unreg: 1856err_video_unreg:
1865 if (hint < MAX_DEV_HINTS) 1857 if (hint < MAX_DEV_HINTS)
1866 device_hint[hint].pdev = NULL; 1858 device_hint[hint].pdev = NULL;
1867 video_unregister_device(pdev->vdev); 1859 video_unregister_device(pdev->vdev);
1868err: 1860 pdev->vdev = NULL; /* So we don't try to release it below */
1869 video_device_release(pdev->vdev); /* Drip... drip... drip... */ 1861err_video_release:
1870 kfree(pdev); /* Oops, no memory leaks please */ 1862 video_device_release(pdev->vdev);
1863err_free_mem:
1864 kfree(pdev);
1871 return rc; 1865 return rc;
1872} 1866}
1873 1867
1874/* The user janked out the cable... */ 1868/* The user yanked out the cable... */
1875static void usb_pwc_disconnect(struct usb_interface *intf) 1869static void usb_pwc_disconnect(struct usb_interface *intf)
1876{ 1870{
1877 struct pwc_device *pdev; 1871 struct pwc_device *pdev;
@@ -1902,7 +1896,7 @@ static void usb_pwc_disconnect(struct usb_interface *intf)
1902 /* Alert waiting processes */ 1896 /* Alert waiting processes */
1903 wake_up_interruptible(&pdev->frameq); 1897 wake_up_interruptible(&pdev->frameq);
1904 /* Wait until device is closed */ 1898 /* Wait until device is closed */
1905 if(pdev->vopen) { 1899 if (pdev->vopen) {
1906 mutex_lock(&pdev->modlock); 1900 mutex_lock(&pdev->modlock);
1907 pdev->unplugged = 1; 1901 pdev->unplugged = 1;
1908 mutex_unlock(&pdev->modlock); 1902 mutex_unlock(&pdev->modlock);
@@ -1911,8 +1905,6 @@ static void usb_pwc_disconnect(struct usb_interface *intf)
1911 /* Device is closed, so we can safely unregister it */ 1905 /* Device is closed, so we can safely unregister it */
1912 PWC_DEBUG_PROBE("Unregistering video device in disconnect().\n"); 1906 PWC_DEBUG_PROBE("Unregistering video device in disconnect().\n");
1913 pwc_cleanup(pdev); 1907 pwc_cleanup(pdev);
1914 /* Free memory (don't set pdev to 0 just yet) */
1915 kfree(pdev);
1916 1908
1917disconnect_out: 1909disconnect_out:
1918 /* search device_hint[] table if we occupy a slot, by any chance */ 1910 /* search device_hint[] table if we occupy a slot, by any chance */
diff --git a/drivers/media/video/pwc/pwc-v4l.c b/drivers/media/video/pwc/pwc-v4l.c
index 2876ce084510..bdb4ced57496 100644
--- a/drivers/media/video/pwc/pwc-v4l.c
+++ b/drivers/media/video/pwc/pwc-v4l.c
@@ -1033,7 +1033,7 @@ long pwc_video_do_ioctl(struct file *file, unsigned int cmd, void *arg)
1033 if (std->index != 0) 1033 if (std->index != 0)
1034 return -EINVAL; 1034 return -EINVAL;
1035 std->id = V4L2_STD_UNKNOWN; 1035 std->id = V4L2_STD_UNKNOWN;
1036 strncpy(std->name, "webcam", sizeof(std->name)); 1036 strlcpy(std->name, "webcam", sizeof(std->name));
1037 return 0; 1037 return 0;
1038 } 1038 }
1039 1039
diff --git a/drivers/media/video/pwc/pwc.h b/drivers/media/video/pwc/pwc.h
index 0b658dee05a4..0902355dfa77 100644
--- a/drivers/media/video/pwc/pwc.h
+++ b/drivers/media/video/pwc/pwc.h
@@ -135,12 +135,6 @@
135#define DEVICE_USE_CODEC3(x) ((x)>=700) 135#define DEVICE_USE_CODEC3(x) ((x)>=700)
136#define DEVICE_USE_CODEC23(x) ((x)>=675) 136#define DEVICE_USE_CODEC23(x) ((x)>=675)
137 137
138
139#ifndef V4L2_PIX_FMT_PWC1
140#define V4L2_PIX_FMT_PWC1 v4l2_fourcc('P','W','C','1')
141#define V4L2_PIX_FMT_PWC2 v4l2_fourcc('P','W','C','2')
142#endif
143
144/* The following structures were based on cpia.h. Why reinvent the wheel? :-) */ 138/* The following structures were based on cpia.h. Why reinvent the wheel? :-) */
145struct pwc_iso_buf 139struct pwc_iso_buf
146{ 140{
@@ -259,6 +253,7 @@ struct pwc_device
259 int snapshot_button_status; /* set to 1 when the user push the button, reset to 0 when this value is read */ 253 int snapshot_button_status; /* set to 1 when the user push the button, reset to 0 when this value is read */
260#ifdef CONFIG_USB_PWC_INPUT_EVDEV 254#ifdef CONFIG_USB_PWC_INPUT_EVDEV
261 struct input_dev *button_dev; /* webcam snapshot button input */ 255 struct input_dev *button_dev; /* webcam snapshot button input */
256 char button_phys[64];
262#endif 257#endif
263 258
264 /*** Misc. data ***/ 259 /*** Misc. data ***/
diff --git a/drivers/media/video/saa6588.c b/drivers/media/video/saa6588.c
index c25e81af5ce0..c3e96f070973 100644
--- a/drivers/media/video/saa6588.c
+++ b/drivers/media/video/saa6588.c
@@ -40,7 +40,7 @@
40/* insmod options */ 40/* insmod options */
41static unsigned int debug; 41static unsigned int debug;
42static unsigned int xtal; 42static unsigned int xtal;
43static unsigned int rbds; 43static unsigned int mmbs;
44static unsigned int plvl; 44static unsigned int plvl;
45static unsigned int bufblocks = 100; 45static unsigned int bufblocks = 100;
46 46
@@ -48,8 +48,8 @@ module_param(debug, int, 0644);
48MODULE_PARM_DESC(debug, "enable debug messages"); 48MODULE_PARM_DESC(debug, "enable debug messages");
49module_param(xtal, int, 0); 49module_param(xtal, int, 0);
50MODULE_PARM_DESC(xtal, "select oscillator frequency (0..3), default 0"); 50MODULE_PARM_DESC(xtal, "select oscillator frequency (0..3), default 0");
51module_param(rbds, int, 0); 51module_param(mmbs, int, 0);
52MODULE_PARM_DESC(rbds, "select mode, 0=RDS, 1=RBDS, default 0"); 52MODULE_PARM_DESC(mmbs, "enable MMBS mode: 0=off (default), 1=on");
53module_param(plvl, int, 0); 53module_param(plvl, int, 0);
54MODULE_PARM_DESC(plvl, "select pause level (0..3), default 0"); 54MODULE_PARM_DESC(plvl, "select pause level (0..3), default 0");
55module_param(bufblocks, int, 0); 55module_param(bufblocks, int, 0);
@@ -78,6 +78,7 @@ struct saa6588 {
78 unsigned char last_blocknum; 78 unsigned char last_blocknum;
79 wait_queue_head_t read_queue; 79 wait_queue_head_t read_queue;
80 int data_available_for_read; 80 int data_available_for_read;
81 u8 sync;
81}; 82};
82 83
83static inline struct saa6588 *to_saa6588(struct v4l2_subdev *sd) 84static inline struct saa6588 *to_saa6588(struct v4l2_subdev *sd)
@@ -261,13 +262,16 @@ static void saa6588_i2c_poll(struct saa6588 *s)
261 unsigned char tmp; 262 unsigned char tmp;
262 263
263 /* Although we only need 3 bytes, we have to read at least 6. 264 /* Although we only need 3 bytes, we have to read at least 6.
264 SAA6588 returns garbage otherwise */ 265 SAA6588 returns garbage otherwise. */
265 if (6 != i2c_master_recv(client, &tmpbuf[0], 6)) { 266 if (6 != i2c_master_recv(client, &tmpbuf[0], 6)) {
266 if (debug > 1) 267 if (debug > 1)
267 dprintk(PREFIX "read error!\n"); 268 dprintk(PREFIX "read error!\n");
268 return; 269 return;
269 } 270 }
270 271
272 s->sync = tmpbuf[0] & 0x10;
273 if (!s->sync)
274 return;
271 blocknum = tmpbuf[0] >> 5; 275 blocknum = tmpbuf[0] >> 5;
272 if (blocknum == s->last_blocknum) { 276 if (blocknum == s->last_blocknum) {
273 if (debug > 3) 277 if (debug > 3)
@@ -286,9 +290,8 @@ static void saa6588_i2c_poll(struct saa6588 *s)
286 occurred during reception of this block. 290 occurred during reception of this block.
287 Bit 6: Corrected bit. Indicates that an error was 291 Bit 6: Corrected bit. Indicates that an error was
288 corrected for this data block. 292 corrected for this data block.
289 Bits 5-3: Received Offset. Indicates the offset received 293 Bits 5-3: Same as bits 0-2.
290 by the sync system. 294 Bits 2-0: Block number.
291 Bits 2-0: Offset Name. Indicates the offset applied to this data.
292 295
293 SAA6588 byte order is Status-MSB-LSB, so we have to swap the 296 SAA6588 byte order is Status-MSB-LSB, so we have to swap the
294 first and the last of the 3 bytes block. 297 first and the last of the 3 bytes block.
@@ -298,12 +301,21 @@ static void saa6588_i2c_poll(struct saa6588 *s)
298 tmpbuf[2] = tmpbuf[0]; 301 tmpbuf[2] = tmpbuf[0];
299 tmpbuf[0] = tmp; 302 tmpbuf[0] = tmp;
300 303
304 /* Map 'Invalid block E' to 'Invalid Block' */
305 if (blocknum == 6)
306 blocknum = V4L2_RDS_BLOCK_INVALID;
307 /* And if are not in mmbs mode, then 'Block E' is also mapped
308 to 'Invalid Block'. As far as I can tell MMBS is discontinued,
309 and if there is ever a need to support E blocks, then please
310 contact the linux-media mailinglist. */
311 else if (!mmbs && blocknum == 5)
312 blocknum = V4L2_RDS_BLOCK_INVALID;
301 tmp = blocknum; 313 tmp = blocknum;
302 tmp |= blocknum << 3; /* Received offset == Offset Name (OK ?) */ 314 tmp |= blocknum << 3; /* Received offset == Offset Name (OK ?) */
303 if ((tmpbuf[2] & 0x03) == 0x03) 315 if ((tmpbuf[2] & 0x03) == 0x03)
304 tmp |= 0x80; /* uncorrectable error */ 316 tmp |= V4L2_RDS_BLOCK_ERROR; /* uncorrectable error */
305 else if ((tmpbuf[2] & 0x03) != 0x00) 317 else if ((tmpbuf[2] & 0x03) != 0x00)
306 tmp |= 0x40; /* corrected error */ 318 tmp |= V4L2_RDS_BLOCK_CORRECTED; /* corrected error */
307 tmpbuf[2] = tmp; /* Is this enough ? Should we also check other bits ? */ 319 tmpbuf[2] = tmp; /* Is this enough ? Should we also check other bits ? */
308 320
309 spin_lock_irqsave(&s->lock, flags); 321 spin_lock_irqsave(&s->lock, flags);
@@ -321,14 +333,14 @@ static void saa6588_work(struct work_struct *work)
321 schedule_delayed_work(&s->work, msecs_to_jiffies(20)); 333 schedule_delayed_work(&s->work, msecs_to_jiffies(20));
322} 334}
323 335
324static int saa6588_configure(struct saa6588 *s) 336static void saa6588_configure(struct saa6588 *s)
325{ 337{
326 struct i2c_client *client = v4l2_get_subdevdata(&s->sd); 338 struct i2c_client *client = v4l2_get_subdevdata(&s->sd);
327 unsigned char buf[3]; 339 unsigned char buf[3];
328 int rc; 340 int rc;
329 341
330 buf[0] = cSyncRestart; 342 buf[0] = cSyncRestart;
331 if (rbds) 343 if (mmbs)
332 buf[0] |= cProcessingModeRBDS; 344 buf[0] |= cProcessingModeRBDS;
333 345
334 buf[1] = cFlywheelDefault; 346 buf[1] = cFlywheelDefault;
@@ -374,8 +386,6 @@ static int saa6588_configure(struct saa6588 *s)
374 rc = i2c_master_send(client, buf, 3); 386 rc = i2c_master_send(client, buf, 3);
375 if (rc != 3) 387 if (rc != 3)
376 printk(PREFIX "i2c i/o error: rc == %d (should be 3)\n", rc); 388 printk(PREFIX "i2c i/o error: rc == %d (should be 3)\n", rc);
377
378 return 0;
379} 389}
380 390
381/* ---------------------------------------------------------------------- */ 391/* ---------------------------------------------------------------------- */
@@ -416,6 +426,24 @@ static long saa6588_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
416 return 0; 426 return 0;
417} 427}
418 428
429static int saa6588_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
430{
431 struct saa6588 *s = to_saa6588(sd);
432
433 vt->capability |= V4L2_TUNER_CAP_RDS;
434 if (s->sync)
435 vt->rxsubchans |= V4L2_TUNER_SUB_RDS;
436 return 0;
437}
438
439static int saa6588_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
440{
441 struct saa6588 *s = to_saa6588(sd);
442
443 saa6588_configure(s);
444 return 0;
445}
446
419static int saa6588_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip) 447static int saa6588_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
420{ 448{
421 struct i2c_client *client = v4l2_get_subdevdata(sd); 449 struct i2c_client *client = v4l2_get_subdevdata(sd);
@@ -430,8 +458,14 @@ static const struct v4l2_subdev_core_ops saa6588_core_ops = {
430 .ioctl = saa6588_ioctl, 458 .ioctl = saa6588_ioctl,
431}; 459};
432 460
461static const struct v4l2_subdev_tuner_ops saa6588_tuner_ops = {
462 .g_tuner = saa6588_g_tuner,
463 .s_tuner = saa6588_s_tuner,
464};
465
433static const struct v4l2_subdev_ops saa6588_ops = { 466static const struct v4l2_subdev_ops saa6588_ops = {
434 .core = &saa6588_core_ops, 467 .core = &saa6588_core_ops,
468 .tuner = &saa6588_tuner_ops,
435}; 469};
436 470
437/* ---------------------------------------------------------------------- */ 471/* ---------------------------------------------------------------------- */
diff --git a/drivers/media/video/saa7134/Kconfig b/drivers/media/video/saa7134/Kconfig
index 5bcce092e804..22bfd62c9551 100644
--- a/drivers/media/video/saa7134/Kconfig
+++ b/drivers/media/video/saa7134/Kconfig
@@ -47,6 +47,7 @@ config VIDEO_SAA7134_DVB
47 select DVB_TDA10048 if !DVB_FE_CUSTOMISE 47 select DVB_TDA10048 if !DVB_FE_CUSTOMISE
48 select MEDIA_TUNER_TDA18271 if !MEDIA_TUNER_CUSTOMISE 48 select MEDIA_TUNER_TDA18271 if !MEDIA_TUNER_CUSTOMISE
49 select MEDIA_TUNER_TDA8290 if !MEDIA_TUNER_CUSTOMISE 49 select MEDIA_TUNER_TDA8290 if !MEDIA_TUNER_CUSTOMISE
50 select DVB_ZL10039 if !DVB_FE_CUSTOMISE
50 ---help--- 51 ---help---
51 This adds support for DVB cards based on the 52 This adds support for DVB cards based on the
52 Philips saa7134 chip. 53 Philips saa7134 chip.
diff --git a/drivers/media/video/saa7134/saa6752hs.c b/drivers/media/video/saa7134/saa6752hs.c
index 63c4b8f1f541..1eabff6b2456 100644
--- a/drivers/media/video/saa7134/saa6752hs.c
+++ b/drivers/media/video/saa7134/saa6752hs.c
@@ -468,7 +468,7 @@ static int handle_ctrl(int has_ac3, struct saa6752hs_mpeg_params *params,
468 if (set && new != V4L2_MPEG_AUDIO_ENCODING_LAYER_2 && 468 if (set && new != V4L2_MPEG_AUDIO_ENCODING_LAYER_2 &&
469 (!has_ac3 || new != V4L2_MPEG_AUDIO_ENCODING_AC3)) 469 (!has_ac3 || new != V4L2_MPEG_AUDIO_ENCODING_AC3))
470 return -ERANGE; 470 return -ERANGE;
471 new = old; 471 params->au_encoding = new;
472 break; 472 break;
473 case V4L2_CID_MPEG_AUDIO_L2_BITRATE: 473 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
474 old = params->au_l2_bitrate; 474 old = params->au_l2_bitrate;
diff --git a/drivers/media/video/saa7134/saa7134-alsa.c b/drivers/media/video/saa7134/saa7134-alsa.c
index 8b0b64a89874..d48c450ed77c 100644
--- a/drivers/media/video/saa7134/saa7134-alsa.c
+++ b/drivers/media/video/saa7134/saa7134-alsa.c
@@ -40,6 +40,7 @@ MODULE_PARM_DESC(debug,"enable debug messages [alsa]");
40 */ 40 */
41 41
42/* defaults */ 42/* defaults */
43#define MIXER_ADDR_UNSELECTED -1
43#define MIXER_ADDR_TVTUNER 0 44#define MIXER_ADDR_TVTUNER 0
44#define MIXER_ADDR_LINE1 1 45#define MIXER_ADDR_LINE1 1
45#define MIXER_ADDR_LINE2 2 46#define MIXER_ADDR_LINE2 2
@@ -68,7 +69,9 @@ typedef struct snd_card_saa7134 {
68 struct snd_card *card; 69 struct snd_card *card;
69 spinlock_t mixer_lock; 70 spinlock_t mixer_lock;
70 int mixer_volume[MIXER_ADDR_LAST+1][2]; 71 int mixer_volume[MIXER_ADDR_LAST+1][2];
71 int capture_source[MIXER_ADDR_LAST+1][2]; 72 int capture_source_addr;
73 int capture_source[2];
74 struct snd_kcontrol *capture_ctl[MIXER_ADDR_LAST+1];
72 struct pci_dev *pci; 75 struct pci_dev *pci;
73 struct saa7134_dev *dev; 76 struct saa7134_dev *dev;
74 77
@@ -314,6 +317,115 @@ static int dsp_buffer_free(struct saa7134_dev *dev)
314 return 0; 317 return 0;
315} 318}
316 319
320/*
321 * Setting the capture source and updating the ALSA controls
322 */
323static int snd_saa7134_capsrc_set(struct snd_kcontrol *kcontrol,
324 int left, int right, bool force_notify)
325{
326 snd_card_saa7134_t *chip = snd_kcontrol_chip(kcontrol);
327 int change = 0, addr = kcontrol->private_value;
328 int active, old_addr;
329 u32 anabar, xbarin;
330 int analog_io, rate;
331 struct saa7134_dev *dev;
332
333 dev = chip->dev;
334
335 spin_lock_irq(&chip->mixer_lock);
336
337 active = left != 0 || right != 0;
338 old_addr = chip->capture_source_addr;
339
340 /* The active capture source cannot be deactivated */
341 if (active) {
342 change = old_addr != addr ||
343 chip->capture_source[0] != left ||
344 chip->capture_source[1] != right;
345
346 chip->capture_source[0] = left;
347 chip->capture_source[1] = right;
348 chip->capture_source_addr = addr;
349 dev->dmasound.input = addr;
350 }
351 spin_unlock_irq(&chip->mixer_lock);
352
353 if (change) {
354 switch (dev->pci->device) {
355
356 case PCI_DEVICE_ID_PHILIPS_SAA7134:
357 switch (addr) {
358 case MIXER_ADDR_TVTUNER:
359 saa_andorb(SAA7134_AUDIO_FORMAT_CTRL,
360 0xc0, 0xc0);
361 saa_andorb(SAA7134_SIF_SAMPLE_FREQ,
362 0x03, 0x00);
363 break;
364 case MIXER_ADDR_LINE1:
365 case MIXER_ADDR_LINE2:
366 analog_io = (MIXER_ADDR_LINE1 == addr) ?
367 0x00 : 0x08;
368 rate = (32000 == dev->dmasound.rate) ?
369 0x01 : 0x03;
370 saa_andorb(SAA7134_ANALOG_IO_SELECT,
371 0x08, analog_io);
372 saa_andorb(SAA7134_AUDIO_FORMAT_CTRL,
373 0xc0, 0x80);
374 saa_andorb(SAA7134_SIF_SAMPLE_FREQ,
375 0x03, rate);
376 break;
377 }
378
379 break;
380 case PCI_DEVICE_ID_PHILIPS_SAA7133:
381 case PCI_DEVICE_ID_PHILIPS_SAA7135:
382 xbarin = 0x03; /* adc */
383 anabar = 0;
384 switch (addr) {
385 case MIXER_ADDR_TVTUNER:
386 xbarin = 0; /* Demodulator */
387 anabar = 2; /* DACs */
388 break;
389 case MIXER_ADDR_LINE1:
390 anabar = 0; /* aux1, aux1 */
391 break;
392 case MIXER_ADDR_LINE2:
393 anabar = 9; /* aux2, aux2 */
394 break;
395 }
396
397 /* output xbar always main channel */
398 saa_dsp_writel(dev, SAA7133_DIGITAL_OUTPUT_SEL1,
399 0xbbbb10);
400
401 if (left || right) {
402 /* We've got data, turn the input on */
403 saa_dsp_writel(dev, SAA7133_DIGITAL_INPUT_XBAR1,
404 xbarin);
405 saa_writel(SAA7133_ANALOG_IO_SELECT, anabar);
406 } else {
407 saa_dsp_writel(dev, SAA7133_DIGITAL_INPUT_XBAR1,
408 0);
409 saa_writel(SAA7133_ANALOG_IO_SELECT, 0);
410 }
411 break;
412 }
413 }
414
415 if (change) {
416 if (force_notify)
417 snd_ctl_notify(chip->card,
418 SNDRV_CTL_EVENT_MASK_VALUE,
419 &chip->capture_ctl[addr]->id);
420
421 if (old_addr != MIXER_ADDR_UNSELECTED && old_addr != addr)
422 snd_ctl_notify(chip->card,
423 SNDRV_CTL_EVENT_MASK_VALUE,
424 &chip->capture_ctl[old_addr]->id);
425 }
426
427 return change;
428}
317 429
318/* 430/*
319 * ALSA PCM preparation 431 * ALSA PCM preparation
@@ -401,6 +513,10 @@ static int snd_card_saa7134_capture_prepare(struct snd_pcm_substream * substream
401 513
402 dev->dmasound.rate = runtime->rate; 514 dev->dmasound.rate = runtime->rate;
403 515
516 /* Setup and update the card/ALSA controls */
517 snd_saa7134_capsrc_set(saa7134->capture_ctl[dev->dmasound.input], 1, 1,
518 true);
519
404 return 0; 520 return 0;
405 521
406} 522}
@@ -435,6 +551,16 @@ snd_card_saa7134_capture_pointer(struct snd_pcm_substream * substream)
435 551
436/* 552/*
437 * ALSA hardware capabilities definition 553 * ALSA hardware capabilities definition
554 *
555 * Report only 32kHz for ALSA:
556 *
557 * - SAA7133/35 uses DDEP (DemDec Easy Programming mode), which works in 32kHz
558 * only
559 * - SAA7134 for TV mode uses DemDec mode (32kHz)
560 * - Radio works in 32kHz only
561 * - When recording 48kHz from Line1/Line2, switching of capture source to TV
562 * means
563 * switching to 32kHz without any frequency translation
438 */ 564 */
439 565
440static struct snd_pcm_hardware snd_card_saa7134_capture = 566static struct snd_pcm_hardware snd_card_saa7134_capture =
@@ -448,9 +574,9 @@ static struct snd_pcm_hardware snd_card_saa7134_capture =
448 SNDRV_PCM_FMTBIT_U8 | \ 574 SNDRV_PCM_FMTBIT_U8 | \
449 SNDRV_PCM_FMTBIT_U16_LE | \ 575 SNDRV_PCM_FMTBIT_U16_LE | \
450 SNDRV_PCM_FMTBIT_U16_BE, 576 SNDRV_PCM_FMTBIT_U16_BE,
451 .rates = SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000, 577 .rates = SNDRV_PCM_RATE_32000,
452 .rate_min = 32000, 578 .rate_min = 32000,
453 .rate_max = 48000, 579 .rate_max = 32000,
454 .channels_min = 1, 580 .channels_min = 1,
455 .channels_max = 2, 581 .channels_max = 2,
456 .buffer_bytes_max = (256*1024), 582 .buffer_bytes_max = (256*1024),
@@ -836,8 +962,13 @@ static int snd_saa7134_capsrc_get(struct snd_kcontrol * kcontrol,
836 int addr = kcontrol->private_value; 962 int addr = kcontrol->private_value;
837 963
838 spin_lock_irq(&chip->mixer_lock); 964 spin_lock_irq(&chip->mixer_lock);
839 ucontrol->value.integer.value[0] = chip->capture_source[addr][0]; 965 if (chip->capture_source_addr == addr) {
840 ucontrol->value.integer.value[1] = chip->capture_source[addr][1]; 966 ucontrol->value.integer.value[0] = chip->capture_source[0];
967 ucontrol->value.integer.value[1] = chip->capture_source[1];
968 } else {
969 ucontrol->value.integer.value[0] = 0;
970 ucontrol->value.integer.value[1] = 0;
971 }
841 spin_unlock_irq(&chip->mixer_lock); 972 spin_unlock_irq(&chip->mixer_lock);
842 973
843 return 0; 974 return 0;
@@ -846,87 +977,22 @@ static int snd_saa7134_capsrc_get(struct snd_kcontrol * kcontrol,
846static int snd_saa7134_capsrc_put(struct snd_kcontrol * kcontrol, 977static int snd_saa7134_capsrc_put(struct snd_kcontrol * kcontrol,
847 struct snd_ctl_elem_value * ucontrol) 978 struct snd_ctl_elem_value * ucontrol)
848{ 979{
849 snd_card_saa7134_t *chip = snd_kcontrol_chip(kcontrol);
850 int change, addr = kcontrol->private_value;
851 int left, right; 980 int left, right;
852 u32 anabar, xbarin;
853 int analog_io, rate;
854 struct saa7134_dev *dev;
855
856 dev = chip->dev;
857
858 left = ucontrol->value.integer.value[0] & 1; 981 left = ucontrol->value.integer.value[0] & 1;
859 right = ucontrol->value.integer.value[1] & 1; 982 right = ucontrol->value.integer.value[1] & 1;
860 spin_lock_irq(&chip->mixer_lock);
861
862 change = chip->capture_source[addr][0] != left ||
863 chip->capture_source[addr][1] != right;
864 chip->capture_source[addr][0] = left;
865 chip->capture_source[addr][1] = right;
866 dev->dmasound.input=addr;
867 spin_unlock_irq(&chip->mixer_lock);
868
869
870 if (change) {
871 switch (dev->pci->device) {
872
873 case PCI_DEVICE_ID_PHILIPS_SAA7134:
874 switch (addr) {
875 case MIXER_ADDR_TVTUNER:
876 saa_andorb(SAA7134_AUDIO_FORMAT_CTRL, 0xc0, 0xc0);
877 saa_andorb(SAA7134_SIF_SAMPLE_FREQ, 0x03, 0x00);
878 break;
879 case MIXER_ADDR_LINE1:
880 case MIXER_ADDR_LINE2:
881 analog_io = (MIXER_ADDR_LINE1 == addr) ? 0x00 : 0x08;
882 rate = (32000 == dev->dmasound.rate) ? 0x01 : 0x03;
883 saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x08, analog_io);
884 saa_andorb(SAA7134_AUDIO_FORMAT_CTRL, 0xc0, 0x80);
885 saa_andorb(SAA7134_SIF_SAMPLE_FREQ, 0x03, rate);
886 break;
887 }
888
889 break;
890 case PCI_DEVICE_ID_PHILIPS_SAA7133:
891 case PCI_DEVICE_ID_PHILIPS_SAA7135:
892 xbarin = 0x03; // adc
893 anabar = 0;
894 switch (addr) {
895 case MIXER_ADDR_TVTUNER:
896 xbarin = 0; // Demodulator
897 anabar = 2; // DACs
898 break;
899 case MIXER_ADDR_LINE1:
900 anabar = 0; // aux1, aux1
901 break;
902 case MIXER_ADDR_LINE2:
903 anabar = 9; // aux2, aux2
904 break;
905 }
906
907 /* output xbar always main channel */
908 saa_dsp_writel(dev, SAA7133_DIGITAL_OUTPUT_SEL1, 0xbbbb10);
909 983
910 if (left || right) { // We've got data, turn the input on 984 return snd_saa7134_capsrc_set(kcontrol, left, right, false);
911 saa_dsp_writel(dev, SAA7133_DIGITAL_INPUT_XBAR1, xbarin);
912 saa_writel(SAA7133_ANALOG_IO_SELECT, anabar);
913 } else {
914 saa_dsp_writel(dev, SAA7133_DIGITAL_INPUT_XBAR1, 0);
915 saa_writel(SAA7133_ANALOG_IO_SELECT, 0);
916 }
917 break;
918 }
919 }
920
921 return change;
922} 985}
923 986
924static struct snd_kcontrol_new snd_saa7134_controls[] = { 987static struct snd_kcontrol_new snd_saa7134_volume_controls[] = {
925SAA713x_VOLUME("Video Volume", 0, MIXER_ADDR_TVTUNER), 988SAA713x_VOLUME("Video Volume", 0, MIXER_ADDR_TVTUNER),
926SAA713x_CAPSRC("Video Capture Switch", 0, MIXER_ADDR_TVTUNER),
927SAA713x_VOLUME("Line Volume", 1, MIXER_ADDR_LINE1), 989SAA713x_VOLUME("Line Volume", 1, MIXER_ADDR_LINE1),
928SAA713x_CAPSRC("Line Capture Switch", 1, MIXER_ADDR_LINE1),
929SAA713x_VOLUME("Line Volume", 2, MIXER_ADDR_LINE2), 990SAA713x_VOLUME("Line Volume", 2, MIXER_ADDR_LINE2),
991};
992
993static struct snd_kcontrol_new snd_saa7134_capture_controls[] = {
994SAA713x_CAPSRC("Video Capture Switch", 0, MIXER_ADDR_TVTUNER),
995SAA713x_CAPSRC("Line Capture Switch", 1, MIXER_ADDR_LINE1),
930SAA713x_CAPSRC("Line Capture Switch", 2, MIXER_ADDR_LINE2), 996SAA713x_CAPSRC("Line Capture Switch", 2, MIXER_ADDR_LINE2),
931}; 997};
932 998
@@ -941,17 +1007,33 @@ SAA713x_CAPSRC("Line Capture Switch", 2, MIXER_ADDR_LINE2),
941static int snd_card_saa7134_new_mixer(snd_card_saa7134_t * chip) 1007static int snd_card_saa7134_new_mixer(snd_card_saa7134_t * chip)
942{ 1008{
943 struct snd_card *card = chip->card; 1009 struct snd_card *card = chip->card;
1010 struct snd_kcontrol *kcontrol;
944 unsigned int idx; 1011 unsigned int idx;
945 int err; 1012 int err, addr;
946 1013
947 if (snd_BUG_ON(!chip)) 1014 if (snd_BUG_ON(!chip))
948 return -EINVAL; 1015 return -EINVAL;
949 strcpy(card->mixername, "SAA7134 Mixer"); 1016 strcpy(card->mixername, "SAA7134 Mixer");
950 1017
951 for (idx = 0; idx < ARRAY_SIZE(snd_saa7134_controls); idx++) { 1018 for (idx = 0; idx < ARRAY_SIZE(snd_saa7134_volume_controls); idx++) {
952 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_saa7134_controls[idx], chip))) < 0) 1019 kcontrol = snd_ctl_new1(&snd_saa7134_volume_controls[idx],
1020 chip);
1021 err = snd_ctl_add(card, kcontrol);
1022 if (err < 0)
953 return err; 1023 return err;
954 } 1024 }
1025
1026 for (idx = 0; idx < ARRAY_SIZE(snd_saa7134_capture_controls); idx++) {
1027 kcontrol = snd_ctl_new1(&snd_saa7134_capture_controls[idx],
1028 chip);
1029 addr = snd_saa7134_capture_controls[idx].private_value;
1030 chip->capture_ctl[addr] = kcontrol;
1031 err = snd_ctl_add(card, kcontrol);
1032 if (err < 0)
1033 return err;
1034 }
1035
1036 chip->capture_source_addr = MIXER_ADDR_UNSELECTED;
955 return 0; 1037 return 0;
956} 1038}
957 1039
diff --git a/drivers/media/video/saa7134/saa7134-cards.c b/drivers/media/video/saa7134/saa7134-cards.c
index 6eebe3ef97d3..1b29487fd254 100644
--- a/drivers/media/video/saa7134/saa7134-cards.c
+++ b/drivers/media/video/saa7134/saa7134-cards.c
@@ -32,6 +32,7 @@
32#include <media/tveeprom.h> 32#include <media/tveeprom.h>
33#include "tea5767.h" 33#include "tea5767.h"
34#include "tda18271.h" 34#include "tda18271.h"
35#include "xc5000.h"
35 36
36/* commly used strings */ 37/* commly used strings */
37static char name_mute[] = "mute"; 38static char name_mute[] = "mute";
@@ -265,6 +266,56 @@ struct saa7134_board saa7134_boards[] = {
265 .gpio = 0x10000, 266 .gpio = 0x10000,
266 }, 267 },
267 }, 268 },
269 [SAA7134_BOARD_ROVERMEDIA_LINK_PRO_FM] = {
270 /* RoverMedia TV Link Pro FM (LR138 REV:I) */
271 /* Eugene Yudin <Eugene.Yudin@gmail.com> */
272 .name = "RoverMedia TV Link Pro FM",
273 .audio_clock = 0x00200000,
274 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, /* TCL MFPE05 2 */
275 .radio_type = UNSET,
276 .tuner_addr = ADDR_UNSET,
277 .radio_addr = ADDR_UNSET,
278 .tda9887_conf = TDA9887_PRESENT,
279 .gpiomask = 0xe000,
280 .inputs = { {
281 .name = name_tv,
282 .vmux = 1,
283 .amux = TV,
284 .gpio = 0x8000,
285 .tv = 1,
286 }, {
287 .name = name_tv_mono,
288 .vmux = 1,
289 .amux = LINE2,
290 .gpio = 0x0000,
291 .tv = 1,
292 }, {
293 .name = name_comp1,
294 .vmux = 0,
295 .amux = LINE2,
296 .gpio = 0x4000,
297 }, {
298 .name = name_comp2,
299 .vmux = 3,
300 .amux = LINE2,
301 .gpio = 0x4000,
302 }, {
303 .name = name_svideo,
304 .vmux = 8,
305 .amux = LINE2,
306 .gpio = 0x4000,
307 } },
308 .radio = {
309 .name = name_radio,
310 .amux = LINE2,
311 .gpio = 0x2000,
312 },
313 .mute = {
314 .name = name_mute,
315 .amux = TV,
316 .gpio = 0x8000,
317 },
318 },
268 [SAA7134_BOARD_EMPRESS] = { 319 [SAA7134_BOARD_EMPRESS] = {
269 /* "Gert Vervoort" <gert.vervoort@philips.com> */ 320 /* "Gert Vervoort" <gert.vervoort@philips.com> */
270 .name = "EMPRESS", 321 .name = "EMPRESS",
@@ -1364,6 +1415,42 @@ struct saa7134_board saa7134_boards[] = {
1364 .amux = LINE1, 1415 .amux = LINE1,
1365 }, 1416 },
1366 }, 1417 },
1418 [SAA7134_BOARD_AVERMEDIA_STUDIO_505] = {
1419 /* Vasiliy Temnikov <vaka@newmail.ru> */
1420 .name = "AverMedia AverTV Studio 505",
1421 .audio_clock = 0x00187de7,
1422 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
1423 .radio_type = UNSET,
1424 .tuner_addr = ADDR_UNSET,
1425 .radio_addr = ADDR_UNSET,
1426 .tda9887_conf = TDA9887_PRESENT,
1427 .inputs = { {
1428 .name = name_tv,
1429 .vmux = 1,
1430 .amux = LINE2,
1431 .tv = 1,
1432 }, {
1433 .name = name_comp1,
1434 .vmux = 0,
1435 .amux = LINE2,
1436 }, {
1437 .name = name_comp2,
1438 .vmux = 3,
1439 .amux = LINE2,
1440 },{
1441 .name = name_svideo,
1442 .vmux = 8,
1443 .amux = LINE2,
1444 } },
1445 .radio = {
1446 .name = name_radio,
1447 .amux = LINE2,
1448 },
1449 .mute = {
1450 .name = name_mute,
1451 .amux = LINE1,
1452 },
1453 },
1367 [SAA7134_BOARD_UPMOST_PURPLE_TV] = { 1454 [SAA7134_BOARD_UPMOST_PURPLE_TV] = {
1368 .name = "UPMOST PURPLE TV", 1455 .name = "UPMOST PURPLE TV",
1369 .audio_clock = 0x00187de7, 1456 .audio_clock = 0x00187de7,
@@ -1633,7 +1720,7 @@ struct saa7134_board saa7134_boards[] = {
1633 }}, 1720 }},
1634 .radio = { 1721 .radio = {
1635 .name = name_radio, 1722 .name = name_radio,
1636 .amux = LINE1, 1723 .amux = TV,
1637 .gpio = 0x00300001, 1724 .gpio = 0x00300001,
1638 }, 1725 },
1639 .mute = { 1726 .mute = {
@@ -3663,8 +3750,8 @@ struct saa7134_board saa7134_boards[] = {
3663 .amux = TV, 3750 .amux = TV,
3664 .gpio = 0x0200000, 3751 .gpio = 0x0200000,
3665 }, 3752 },
3666 }, 3753 },
3667 [SAA7134_BOARD_ASUSTeK_P7131_ANALOG] = { 3754 [SAA7134_BOARD_ASUSTeK_P7131_ANALOG] = {
3668 .name = "ASUSTeK P7131 Analog", 3755 .name = "ASUSTeK P7131 Analog",
3669 .audio_clock = 0x00187de7, 3756 .audio_clock = 0x00187de7,
3670 .tuner_type = TUNER_PHILIPS_TDA8290, 3757 .tuner_type = TUNER_PHILIPS_TDA8290,
@@ -4081,6 +4168,7 @@ struct saa7134_board saa7134_boards[] = {
4081 .radio_type = UNSET, 4168 .radio_type = UNSET,
4082 .tuner_addr = ADDR_UNSET, 4169 .tuner_addr = ADDR_UNSET,
4083 .radio_addr = ADDR_UNSET, 4170 .radio_addr = ADDR_UNSET,
4171 .rds_addr = 0x10,
4084 .tda9887_conf = TDA9887_PRESENT, 4172 .tda9887_conf = TDA9887_PRESENT,
4085 .gpiomask = 0x00008000, 4173 .gpiomask = 0x00008000,
4086 .inputs = {{ 4174 .inputs = {{
@@ -4145,6 +4233,7 @@ struct saa7134_board saa7134_boards[] = {
4145 .radio_type = UNSET, 4233 .radio_type = UNSET,
4146 .tuner_addr = ADDR_UNSET, 4234 .tuner_addr = ADDR_UNSET,
4147 .radio_addr = ADDR_UNSET, 4235 .radio_addr = ADDR_UNSET,
4236 .rds_addr = 0x10,
4148 .tda9887_conf = TDA9887_PRESENT, 4237 .tda9887_conf = TDA9887_PRESENT,
4149 .gpiomask = 0x00008000, 4238 .gpiomask = 0x00008000,
4150 .inputs = {{ 4239 .inputs = {{
@@ -4175,6 +4264,7 @@ struct saa7134_board saa7134_boards[] = {
4175 .radio_type = UNSET, 4264 .radio_type = UNSET,
4176 .tuner_addr = ADDR_UNSET, 4265 .tuner_addr = ADDR_UNSET,
4177 .radio_addr = ADDR_UNSET, 4266 .radio_addr = ADDR_UNSET,
4267 .rds_addr = 0x10,
4178 .tda9887_conf = TDA9887_PRESENT, 4268 .tda9887_conf = TDA9887_PRESENT,
4179 .gpiomask = 0x00008000, 4269 .gpiomask = 0x00008000,
4180 .inputs = {{ 4270 .inputs = {{
@@ -4350,6 +4440,7 @@ struct saa7134_board saa7134_boards[] = {
4350 .radio_type = UNSET, 4440 .radio_type = UNSET,
4351 .tuner_addr = ADDR_UNSET, 4441 .tuner_addr = ADDR_UNSET,
4352 .radio_addr = ADDR_UNSET, 4442 .radio_addr = ADDR_UNSET,
4443 .rds_addr = 0x10,
4353 .tda9887_conf = TDA9887_PRESENT, 4444 .tda9887_conf = TDA9887_PRESENT,
4354 .inputs = {{ 4445 .inputs = {{
4355 .name = name_tv, 4446 .name = name_tv,
@@ -4378,6 +4469,7 @@ struct saa7134_board saa7134_boards[] = {
4378 .radio_type = UNSET, 4469 .radio_type = UNSET,
4379 .tuner_addr = ADDR_UNSET, 4470 .tuner_addr = ADDR_UNSET,
4380 .radio_addr = ADDR_UNSET, 4471 .radio_addr = ADDR_UNSET,
4472 .rds_addr = 0x10,
4381 .tda9887_conf = TDA9887_PRESENT, 4473 .tda9887_conf = TDA9887_PRESENT,
4382 .inputs = {{ 4474 .inputs = {{
4383 .name = name_tv, 4475 .name = name_tv,
@@ -4406,6 +4498,7 @@ struct saa7134_board saa7134_boards[] = {
4406 .radio_type = UNSET, 4498 .radio_type = UNSET,
4407 .tuner_addr = ADDR_UNSET, 4499 .tuner_addr = ADDR_UNSET,
4408 .radio_addr = ADDR_UNSET, 4500 .radio_addr = ADDR_UNSET,
4501 .rds_addr = 0x10,
4409 .tda9887_conf = TDA9887_PRESENT, 4502 .tda9887_conf = TDA9887_PRESENT,
4410 .inputs = {{ 4503 .inputs = {{
4411 .name = name_tv, 4504 .name = name_tv,
@@ -4434,6 +4527,7 @@ struct saa7134_board saa7134_boards[] = {
4434 .radio_type = UNSET, 4527 .radio_type = UNSET,
4435 .tuner_addr = ADDR_UNSET, 4528 .tuner_addr = ADDR_UNSET,
4436 .radio_addr = ADDR_UNSET, 4529 .radio_addr = ADDR_UNSET,
4530 .rds_addr = 0x10,
4437 .tda9887_conf = TDA9887_PRESENT, 4531 .tda9887_conf = TDA9887_PRESENT,
4438 .inputs = {{ 4532 .inputs = {{
4439 .name = name_tv, 4533 .name = name_tv,
@@ -4540,6 +4634,7 @@ struct saa7134_board saa7134_boards[] = {
4540 .radio_type = UNSET, 4634 .radio_type = UNSET,
4541 .tuner_addr = ADDR_UNSET, 4635 .tuner_addr = ADDR_UNSET,
4542 .radio_addr = ADDR_UNSET, 4636 .radio_addr = ADDR_UNSET,
4637 .rds_addr = 0x10,
4543 .empress_addr = 0x20, 4638 .empress_addr = 0x20,
4544 .tda9887_conf = TDA9887_PRESENT, 4639 .tda9887_conf = TDA9887_PRESENT,
4545 .inputs = { { 4640 .inputs = { {
@@ -4861,7 +4956,7 @@ struct saa7134_board saa7134_boards[] = {
4861 /* Igor Kuznetsov <igk@igk.ru> */ 4956 /* Igor Kuznetsov <igk@igk.ru> */
4862 .name = "Beholder BeholdTV H6", 4957 .name = "Beholder BeholdTV H6",
4863 .audio_clock = 0x00187de7, 4958 .audio_clock = 0x00187de7,
4864 .tuner_type = TUNER_PHILIPS_FMD1216ME_MK3, 4959 .tuner_type = TUNER_PHILIPS_FMD1216MEX_MK3,
4865 .radio_type = UNSET, 4960 .radio_type = UNSET,
4866 .tuner_addr = ADDR_UNSET, 4961 .tuner_addr = ADDR_UNSET,
4867 .radio_addr = ADDR_UNSET, 4962 .radio_addr = ADDR_UNSET,
@@ -5116,6 +5211,53 @@ struct saa7134_board saa7134_boards[] = {
5116 .gpio = 0x00, 5211 .gpio = 0x00,
5117 }, 5212 },
5118 }, 5213 },
5214 [SAA7134_BOARD_VIDEOMATE_S350] = {
5215 /* Jan D. Louw <jd.louw@mweb.co.za */
5216 .name = "Compro VideoMate S350/S300",
5217 .audio_clock = 0x00187de7,
5218 .tuner_type = TUNER_ABSENT,
5219 .radio_type = UNSET,
5220 .tuner_addr = ADDR_UNSET,
5221 .radio_addr = ADDR_UNSET,
5222 .mpeg = SAA7134_MPEG_DVB,
5223 .inputs = { {
5224 .name = name_comp1,
5225 .vmux = 0,
5226 .amux = LINE1,
5227 }, {
5228 .name = name_svideo,
5229 .vmux = 8, /* Not tested */
5230 .amux = LINE1
5231 } },
5232 },
5233 [SAA7134_BOARD_BEHOLD_X7] = {
5234 /* Beholder Intl. Ltd. Dmitry Belimov <d.belimov@gmail.com> */
5235 .name = "Beholder BeholdTV X7",
5236 .audio_clock = 0x00187de7,
5237 .tuner_type = TUNER_XC5000,
5238 .radio_type = UNSET,
5239 .tuner_addr = ADDR_UNSET,
5240 .radio_addr = ADDR_UNSET,
5241 .inputs = { {
5242 .name = name_tv,
5243 .vmux = 2,
5244 .amux = TV,
5245 .tv = 1,
5246 }, {
5247 .name = name_comp1,
5248 .vmux = 0,
5249 .amux = LINE1,
5250 }, {
5251 .name = name_svideo,
5252 .vmux = 9,
5253 .amux = LINE1,
5254 } },
5255 .radio = {
5256 .name = name_radio,
5257 .amux = TV,
5258 },
5259 },
5260
5119}; 5261};
5120 5262
5121const unsigned int saa7134_bcount = ARRAY_SIZE(saa7134_boards); 5263const unsigned int saa7134_bcount = ARRAY_SIZE(saa7134_boards);
@@ -5374,6 +5516,12 @@ struct pci_device_id saa7134_pci_tbl[] = {
5374 .vendor = PCI_VENDOR_ID_PHILIPS, 5516 .vendor = PCI_VENDOR_ID_PHILIPS,
5375 .device = PCI_DEVICE_ID_PHILIPS_SAA7130, 5517 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
5376 .subvendor = 0x1461, /* Avermedia Technologies Inc */ 5518 .subvendor = 0x1461, /* Avermedia Technologies Inc */
5519 .subdevice = 0xa115,
5520 .driver_data = SAA7134_BOARD_AVERMEDIA_STUDIO_505,
5521 }, {
5522 .vendor = PCI_VENDOR_ID_PHILIPS,
5523 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
5524 .subvendor = 0x1461, /* Avermedia Technologies Inc */
5377 .subdevice = 0x2108, 5525 .subdevice = 0x2108,
5378 .driver_data = SAA7134_BOARD_AVERMEDIA_305, 5526 .driver_data = SAA7134_BOARD_AVERMEDIA_305,
5379 },{ 5527 },{
@@ -6223,7 +6371,24 @@ struct pci_device_id saa7134_pci_tbl[] = {
6223 .subvendor = 0x1461, /* Avermedia Technologies Inc */ 6371 .subvendor = 0x1461, /* Avermedia Technologies Inc */
6224 .subdevice = 0xf31d, 6372 .subdevice = 0xf31d,
6225 .driver_data = SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS, 6373 .driver_data = SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS,
6226 6374 }, {
6375 .vendor = PCI_VENDOR_ID_PHILIPS,
6376 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
6377 .subvendor = 0x185b,
6378 .subdevice = 0xc900,
6379 .driver_data = SAA7134_BOARD_VIDEOMATE_S350,
6380 }, {
6381 .vendor = PCI_VENDOR_ID_PHILIPS,
6382 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
6383 .subvendor = 0x5ace, /* Beholder Intl. Ltd. */
6384 .subdevice = 0x7595,
6385 .driver_data = SAA7134_BOARD_BEHOLD_X7,
6386 }, {
6387 .vendor = PCI_VENDOR_ID_PHILIPS,
6388 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
6389 .subvendor = 0x19d1, /* RoverMedia */
6390 .subdevice = 0x0138, /* LifeView FlyTV Prime30 OEM */
6391 .driver_data = SAA7134_BOARD_ROVERMEDIA_LINK_PRO_FM,
6227 }, { 6392 }, {
6228 /* --- boards without eeprom + subsystem ID --- */ 6393 /* --- boards without eeprom + subsystem ID --- */
6229 .vendor = PCI_VENDOR_ID_PHILIPS, 6394 .vendor = PCI_VENDOR_ID_PHILIPS,
@@ -6310,6 +6475,32 @@ static int saa7134_xc2028_callback(struct saa7134_dev *dev,
6310 return -EINVAL; 6475 return -EINVAL;
6311} 6476}
6312 6477
6478static int saa7134_xc5000_callback(struct saa7134_dev *dev,
6479 int command, int arg)
6480{
6481 switch (dev->board) {
6482 case SAA7134_BOARD_BEHOLD_X7:
6483 if (command == XC5000_TUNER_RESET) {
6484 /* Down and UP pheripherial RESET pin for reset all chips */
6485 saa_writeb(SAA7134_SPECIAL_MODE, 0x00);
6486 msleep(10);
6487 saa_writeb(SAA7134_SPECIAL_MODE, 0x01);
6488 msleep(10);
6489 }
6490 break;
6491 default:
6492 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0x06e20000, 0x06e20000);
6493 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x06a20000, 0x06a20000);
6494 saa_andorl(SAA7133_ANALOG_IO_SELECT >> 2, 0x02, 0x02);
6495 saa_andorl(SAA7134_ANALOG_IN_CTRL1 >> 2, 0x81, 0x81);
6496 saa_andorl(SAA7134_AUDIO_CLOCK0 >> 2, 0x03187de7, 0x03187de7);
6497 saa_andorl(SAA7134_AUDIO_PLL_CTRL >> 2, 0x03, 0x03);
6498 saa_andorl(SAA7134_AUDIO_CLOCKS_PER_FIELD0 >> 2,
6499 0x0001e000, 0x0001e000);
6500 break;
6501 }
6502 return 0;
6503}
6313 6504
6314static int saa7134_tda8290_827x_callback(struct saa7134_dev *dev, 6505static int saa7134_tda8290_827x_callback(struct saa7134_dev *dev,
6315 int command, int arg) 6506 int command, int arg)
@@ -6406,6 +6597,8 @@ int saa7134_tuner_callback(void *priv, int component, int command, int arg)
6406 return saa7134_tda8290_callback(dev, command, arg); 6597 return saa7134_tda8290_callback(dev, command, arg);
6407 case TUNER_XC2028: 6598 case TUNER_XC2028:
6408 return saa7134_xc2028_callback(dev, command, arg); 6599 return saa7134_xc2028_callback(dev, command, arg);
6600 case TUNER_XC5000:
6601 return saa7134_xc5000_callback(dev, command, arg);
6409 } 6602 }
6410 } else { 6603 } else {
6411 printk(KERN_ERR "saa7134: Error - device struct undefined.\n"); 6604 printk(KERN_ERR "saa7134: Error - device struct undefined.\n");
@@ -6476,6 +6669,7 @@ int saa7134_board_init1(struct saa7134_dev *dev)
6476 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT: 6669 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT:
6477 case SAA7134_BOARD_KWORLD_XPERT: 6670 case SAA7134_BOARD_KWORLD_XPERT:
6478 case SAA7134_BOARD_AVERMEDIA_STUDIO_305: 6671 case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
6672 case SAA7134_BOARD_AVERMEDIA_STUDIO_505:
6479 case SAA7134_BOARD_AVERMEDIA_305: 6673 case SAA7134_BOARD_AVERMEDIA_305:
6480 case SAA7134_BOARD_AVERMEDIA_STUDIO_307: 6674 case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
6481 case SAA7134_BOARD_AVERMEDIA_307: 6675 case SAA7134_BOARD_AVERMEDIA_307:
@@ -6500,7 +6694,7 @@ int saa7134_board_init1(struct saa7134_dev *dev)
6500 case SAA7134_BOARD_FLYDVBT_LR301: 6694 case SAA7134_BOARD_FLYDVBT_LR301:
6501 case SAA7134_BOARD_ASUSTeK_P7131_DUAL: 6695 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
6502 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA: 6696 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
6503 case SAA7134_BOARD_ASUSTeK_P7131_ANALOG: 6697 case SAA7134_BOARD_ASUSTeK_P7131_ANALOG:
6504 case SAA7134_BOARD_FLYDVBTDUO: 6698 case SAA7134_BOARD_FLYDVBTDUO:
6505 case SAA7134_BOARD_PROTEUS_2309: 6699 case SAA7134_BOARD_PROTEUS_2309:
6506 case SAA7134_BOARD_AVERMEDIA_A16AR: 6700 case SAA7134_BOARD_AVERMEDIA_A16AR:
@@ -6525,6 +6719,7 @@ int saa7134_board_init1(struct saa7134_dev *dev)
6525 case SAA7134_BOARD_REAL_ANGEL_220: 6719 case SAA7134_BOARD_REAL_ANGEL_220:
6526 case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG: 6720 case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG:
6527 case SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS: 6721 case SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS:
6722 case SAA7134_BOARD_ROVERMEDIA_LINK_PRO_FM:
6528 dev->has_remote = SAA7134_REMOTE_GPIO; 6723 dev->has_remote = SAA7134_REMOTE_GPIO;
6529 break; 6724 break;
6530 case SAA7134_BOARD_FLYDVBS_LR300: 6725 case SAA7134_BOARD_FLYDVBS_LR300:
@@ -6653,6 +6848,7 @@ int saa7134_board_init1(struct saa7134_dev *dev)
6653 case SAA7134_BOARD_BEHOLD_M63: 6848 case SAA7134_BOARD_BEHOLD_M63:
6654 case SAA7134_BOARD_BEHOLD_M6_EXTRA: 6849 case SAA7134_BOARD_BEHOLD_M6_EXTRA:
6655 case SAA7134_BOARD_BEHOLD_H6: 6850 case SAA7134_BOARD_BEHOLD_H6:
6851 case SAA7134_BOARD_BEHOLD_X7:
6656 dev->has_remote = SAA7134_REMOTE_I2C; 6852 dev->has_remote = SAA7134_REMOTE_I2C;
6657 break; 6853 break;
6658 case SAA7134_BOARD_AVERMEDIA_A169_B: 6854 case SAA7134_BOARD_AVERMEDIA_A169_B:
@@ -6673,6 +6869,11 @@ int saa7134_board_init1(struct saa7134_dev *dev)
6673 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0x80040100, 0x80040100); 6869 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0x80040100, 0x80040100);
6674 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x80040100, 0x00040100); 6870 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x80040100, 0x00040100);
6675 break; 6871 break;
6872 case SAA7134_BOARD_VIDEOMATE_S350:
6873 dev->has_remote = SAA7134_REMOTE_GPIO;
6874 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0x00008000, 0x00008000);
6875 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x00008000, 0x00008000);
6876 break;
6676 } 6877 }
6677 return 0; 6878 return 0;
6678} 6879}
diff --git a/drivers/media/video/saa7134/saa7134-core.c b/drivers/media/video/saa7134/saa7134-core.c
index 94a023a14bbc..cb78c956d810 100644
--- a/drivers/media/video/saa7134/saa7134-core.c
+++ b/drivers/media/video/saa7134/saa7134-core.c
@@ -1012,8 +1012,10 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
1012 sd = v4l2_i2c_new_probed_subdev_addr(&dev->v4l2_dev, 1012 sd = v4l2_i2c_new_probed_subdev_addr(&dev->v4l2_dev,
1013 &dev->i2c_adap, "saa6588", "saa6588", 1013 &dev->i2c_adap, "saa6588", "saa6588",
1014 saa7134_boards[dev->board].rds_addr); 1014 saa7134_boards[dev->board].rds_addr);
1015 if (sd) 1015 if (sd) {
1016 printk(KERN_INFO "%s: found RDS decoder\n", dev->name); 1016 printk(KERN_INFO "%s: found RDS decoder\n", dev->name);
1017 dev->has_rds = 1;
1018 }
1017 } 1019 }
1018 1020
1019 request_submodules(dev); 1021 request_submodules(dev);
diff --git a/drivers/media/video/saa7134/saa7134-dvb.c b/drivers/media/video/saa7134/saa7134-dvb.c
index 98f3efd1e944..ebde21dba7e3 100644
--- a/drivers/media/video/saa7134/saa7134-dvb.c
+++ b/drivers/media/video/saa7134/saa7134-dvb.c
@@ -56,6 +56,7 @@
56#include "zl10353.h" 56#include "zl10353.h"
57 57
58#include "zl10036.h" 58#include "zl10036.h"
59#include "zl10039.h"
59#include "mt312.h" 60#include "mt312.h"
60 61
61MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]"); 62MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
@@ -968,6 +969,10 @@ static struct zl10036_config avertv_a700_tuner = {
968 .tuner_address = 0x60, 969 .tuner_address = 0x60,
969}; 970};
970 971
972static struct mt312_config zl10313_compro_s350_config = {
973 .demod_address = 0x0e,
974};
975
971static struct lgdt3305_config hcw_lgdt3305_config = { 976static struct lgdt3305_config hcw_lgdt3305_config = {
972 .i2c_addr = 0x0e, 977 .i2c_addr = 0x0e,
973 .mpeg_mode = LGDT3305_MPEG_SERIAL, 978 .mpeg_mode = LGDT3305_MPEG_SERIAL,
@@ -1457,7 +1462,7 @@ static int dvb_init(struct saa7134_dev *dev)
1457 if (fe0->dvb.frontend) { 1462 if (fe0->dvb.frontend) {
1458 dvb_attach(simple_tuner_attach, fe0->dvb.frontend, 1463 dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
1459 &dev->i2c_adap, 0x61, 1464 &dev->i2c_adap, 0x61,
1460 TUNER_PHILIPS_FMD1216ME_MK3); 1465 TUNER_PHILIPS_FMD1216MEX_MK3);
1461 } 1466 }
1462 break; 1467 break;
1463 case SAA7134_BOARD_AVERMEDIA_A700_PRO: 1468 case SAA7134_BOARD_AVERMEDIA_A700_PRO:
@@ -1473,6 +1478,16 @@ static int dvb_init(struct saa7134_dev *dev)
1473 } 1478 }
1474 } 1479 }
1475 break; 1480 break;
1481 case SAA7134_BOARD_VIDEOMATE_S350:
1482 fe0->dvb.frontend = dvb_attach(mt312_attach,
1483 &zl10313_compro_s350_config, &dev->i2c_adap);
1484 if (fe0->dvb.frontend)
1485 if (dvb_attach(zl10039_attach, fe0->dvb.frontend,
1486 0x60, &dev->i2c_adap) == NULL)
1487 wprintk("%s: No zl10039 found!\n",
1488 __func__);
1489
1490 break;
1476 default: 1491 default:
1477 wprintk("Huh? unknown DVB card?\n"); 1492 wprintk("Huh? unknown DVB card?\n");
1478 break; 1493 break;
diff --git a/drivers/media/video/saa7134/saa7134-input.c b/drivers/media/video/saa7134/saa7134-input.c
index 6e219c2db841..e1e83c7b966e 100644
--- a/drivers/media/video/saa7134/saa7134-input.c
+++ b/drivers/media/video/saa7134/saa7134-input.c
@@ -394,7 +394,7 @@ int saa7134_input_init1(struct saa7134_dev *dev)
394{ 394{
395 struct card_ir *ir; 395 struct card_ir *ir;
396 struct input_dev *input_dev; 396 struct input_dev *input_dev;
397 IR_KEYTAB_TYPE *ir_codes = NULL; 397 struct ir_scancode_table *ir_codes = NULL;
398 u32 mask_keycode = 0; 398 u32 mask_keycode = 0;
399 u32 mask_keydown = 0; 399 u32 mask_keydown = 0;
400 u32 mask_keyup = 0; 400 u32 mask_keyup = 0;
@@ -415,27 +415,28 @@ int saa7134_input_init1(struct saa7134_dev *dev)
415 case SAA7134_BOARD_FLYVIDEO3000: 415 case SAA7134_BOARD_FLYVIDEO3000:
416 case SAA7134_BOARD_FLYTVPLATINUM_FM: 416 case SAA7134_BOARD_FLYTVPLATINUM_FM:
417 case SAA7134_BOARD_FLYTVPLATINUM_MINI2: 417 case SAA7134_BOARD_FLYTVPLATINUM_MINI2:
418 ir_codes = ir_codes_flyvideo; 418 case SAA7134_BOARD_ROVERMEDIA_LINK_PRO_FM:
419 ir_codes = &ir_codes_flyvideo_table;
419 mask_keycode = 0xEC00000; 420 mask_keycode = 0xEC00000;
420 mask_keydown = 0x0040000; 421 mask_keydown = 0x0040000;
421 break; 422 break;
422 case SAA7134_BOARD_CINERGY400: 423 case SAA7134_BOARD_CINERGY400:
423 case SAA7134_BOARD_CINERGY600: 424 case SAA7134_BOARD_CINERGY600:
424 case SAA7134_BOARD_CINERGY600_MK3: 425 case SAA7134_BOARD_CINERGY600_MK3:
425 ir_codes = ir_codes_cinergy; 426 ir_codes = &ir_codes_cinergy_table;
426 mask_keycode = 0x00003f; 427 mask_keycode = 0x00003f;
427 mask_keyup = 0x040000; 428 mask_keyup = 0x040000;
428 break; 429 break;
429 case SAA7134_BOARD_ECS_TVP3XP: 430 case SAA7134_BOARD_ECS_TVP3XP:
430 case SAA7134_BOARD_ECS_TVP3XP_4CB5: 431 case SAA7134_BOARD_ECS_TVP3XP_4CB5:
431 ir_codes = ir_codes_eztv; 432 ir_codes = &ir_codes_eztv_table;
432 mask_keycode = 0x00017c; 433 mask_keycode = 0x00017c;
433 mask_keyup = 0x000002; 434 mask_keyup = 0x000002;
434 polling = 50; // ms 435 polling = 50; // ms
435 break; 436 break;
436 case SAA7134_BOARD_KWORLD_XPERT: 437 case SAA7134_BOARD_KWORLD_XPERT:
437 case SAA7134_BOARD_AVACSSMARTTV: 438 case SAA7134_BOARD_AVACSSMARTTV:
438 ir_codes = ir_codes_pixelview; 439 ir_codes = &ir_codes_pixelview_table;
439 mask_keycode = 0x00001F; 440 mask_keycode = 0x00001F;
440 mask_keyup = 0x000020; 441 mask_keyup = 0x000020;
441 polling = 50; // ms 442 polling = 50; // ms
@@ -445,13 +446,14 @@ int saa7134_input_init1(struct saa7134_dev *dev)
445 case SAA7134_BOARD_AVERMEDIA_305: 446 case SAA7134_BOARD_AVERMEDIA_305:
446 case SAA7134_BOARD_AVERMEDIA_307: 447 case SAA7134_BOARD_AVERMEDIA_307:
447 case SAA7134_BOARD_AVERMEDIA_STUDIO_305: 448 case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
449 case SAA7134_BOARD_AVERMEDIA_STUDIO_505:
448 case SAA7134_BOARD_AVERMEDIA_STUDIO_307: 450 case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
449 case SAA7134_BOARD_AVERMEDIA_STUDIO_507: 451 case SAA7134_BOARD_AVERMEDIA_STUDIO_507:
450 case SAA7134_BOARD_AVERMEDIA_STUDIO_507UA: 452 case SAA7134_BOARD_AVERMEDIA_STUDIO_507UA:
451 case SAA7134_BOARD_AVERMEDIA_GO_007_FM: 453 case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
452 case SAA7134_BOARD_AVERMEDIA_M102: 454 case SAA7134_BOARD_AVERMEDIA_M102:
453 case SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS: 455 case SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS:
454 ir_codes = ir_codes_avermedia; 456 ir_codes = &ir_codes_avermedia_table;
455 mask_keycode = 0x0007C8; 457 mask_keycode = 0x0007C8;
456 mask_keydown = 0x000010; 458 mask_keydown = 0x000010;
457 polling = 50; // ms 459 polling = 50; // ms
@@ -460,14 +462,14 @@ int saa7134_input_init1(struct saa7134_dev *dev)
460 saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4); 462 saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4);
461 break; 463 break;
462 case SAA7134_BOARD_AVERMEDIA_M135A: 464 case SAA7134_BOARD_AVERMEDIA_M135A:
463 ir_codes = ir_codes_avermedia_m135a; 465 ir_codes = &ir_codes_avermedia_m135a_table;
464 mask_keydown = 0x0040000; 466 mask_keydown = 0x0040000;
465 mask_keycode = 0x00013f; 467 mask_keycode = 0x00013f;
466 nec_gpio = 1; 468 nec_gpio = 1;
467 break; 469 break;
468 case SAA7134_BOARD_AVERMEDIA_777: 470 case SAA7134_BOARD_AVERMEDIA_777:
469 case SAA7134_BOARD_AVERMEDIA_A16AR: 471 case SAA7134_BOARD_AVERMEDIA_A16AR:
470 ir_codes = ir_codes_avermedia; 472 ir_codes = &ir_codes_avermedia_table;
471 mask_keycode = 0x02F200; 473 mask_keycode = 0x02F200;
472 mask_keydown = 0x000400; 474 mask_keydown = 0x000400;
473 polling = 50; // ms 475 polling = 50; // ms
@@ -476,7 +478,7 @@ int saa7134_input_init1(struct saa7134_dev *dev)
476 saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1); 478 saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
477 break; 479 break;
478 case SAA7134_BOARD_AVERMEDIA_A16D: 480 case SAA7134_BOARD_AVERMEDIA_A16D:
479 ir_codes = ir_codes_avermedia_a16d; 481 ir_codes = &ir_codes_avermedia_a16d_table;
480 mask_keycode = 0x02F200; 482 mask_keycode = 0x02F200;
481 mask_keydown = 0x000400; 483 mask_keydown = 0x000400;
482 polling = 50; /* ms */ 484 polling = 50; /* ms */
@@ -485,14 +487,14 @@ int saa7134_input_init1(struct saa7134_dev *dev)
485 saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1); 487 saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
486 break; 488 break;
487 case SAA7134_BOARD_KWORLD_TERMINATOR: 489 case SAA7134_BOARD_KWORLD_TERMINATOR:
488 ir_codes = ir_codes_pixelview; 490 ir_codes = &ir_codes_pixelview_table;
489 mask_keycode = 0x00001f; 491 mask_keycode = 0x00001f;
490 mask_keyup = 0x000060; 492 mask_keyup = 0x000060;
491 polling = 50; // ms 493 polling = 50; // ms
492 break; 494 break;
493 case SAA7134_BOARD_MANLI_MTV001: 495 case SAA7134_BOARD_MANLI_MTV001:
494 case SAA7134_BOARD_MANLI_MTV002: 496 case SAA7134_BOARD_MANLI_MTV002:
495 ir_codes = ir_codes_manli; 497 ir_codes = &ir_codes_manli_table;
496 mask_keycode = 0x001f00; 498 mask_keycode = 0x001f00;
497 mask_keyup = 0x004000; 499 mask_keyup = 0x004000;
498 polling = 50; /* ms */ 500 polling = 50; /* ms */
@@ -511,25 +513,25 @@ int saa7134_input_init1(struct saa7134_dev *dev)
511 case SAA7134_BOARD_BEHOLD_507_9FM: 513 case SAA7134_BOARD_BEHOLD_507_9FM:
512 case SAA7134_BOARD_BEHOLD_507RDS_MK3: 514 case SAA7134_BOARD_BEHOLD_507RDS_MK3:
513 case SAA7134_BOARD_BEHOLD_507RDS_MK5: 515 case SAA7134_BOARD_BEHOLD_507RDS_MK5:
514 ir_codes = ir_codes_manli; 516 ir_codes = &ir_codes_manli_table;
515 mask_keycode = 0x003f00; 517 mask_keycode = 0x003f00;
516 mask_keyup = 0x004000; 518 mask_keyup = 0x004000;
517 polling = 50; /* ms */ 519 polling = 50; /* ms */
518 break; 520 break;
519 case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM: 521 case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM:
520 ir_codes = ir_codes_behold_columbus; 522 ir_codes = &ir_codes_behold_columbus_table;
521 mask_keycode = 0x003f00; 523 mask_keycode = 0x003f00;
522 mask_keyup = 0x004000; 524 mask_keyup = 0x004000;
523 polling = 50; // ms 525 polling = 50; // ms
524 break; 526 break;
525 case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS: 527 case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS:
526 ir_codes = ir_codes_pctv_sedna; 528 ir_codes = &ir_codes_pctv_sedna_table;
527 mask_keycode = 0x001f00; 529 mask_keycode = 0x001f00;
528 mask_keyup = 0x004000; 530 mask_keyup = 0x004000;
529 polling = 50; // ms 531 polling = 50; // ms
530 break; 532 break;
531 case SAA7134_BOARD_GOTVIEW_7135: 533 case SAA7134_BOARD_GOTVIEW_7135:
532 ir_codes = ir_codes_gotview7135; 534 ir_codes = &ir_codes_gotview7135_table;
533 mask_keycode = 0x0003CC; 535 mask_keycode = 0x0003CC;
534 mask_keydown = 0x000010; 536 mask_keydown = 0x000010;
535 polling = 5; /* ms */ 537 polling = 5; /* ms */
@@ -538,73 +540,78 @@ int saa7134_input_init1(struct saa7134_dev *dev)
538 case SAA7134_BOARD_VIDEOMATE_TV_PVR: 540 case SAA7134_BOARD_VIDEOMATE_TV_PVR:
539 case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS: 541 case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS:
540 case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII: 542 case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII:
541 ir_codes = ir_codes_videomate_tv_pvr; 543 ir_codes = &ir_codes_videomate_tv_pvr_table;
542 mask_keycode = 0x00003F; 544 mask_keycode = 0x00003F;
543 mask_keyup = 0x400000; 545 mask_keyup = 0x400000;
544 polling = 50; // ms 546 polling = 50; // ms
545 break; 547 break;
546 case SAA7134_BOARD_PROTEUS_2309: 548 case SAA7134_BOARD_PROTEUS_2309:
547 ir_codes = ir_codes_proteus_2309; 549 ir_codes = &ir_codes_proteus_2309_table;
548 mask_keycode = 0x00007F; 550 mask_keycode = 0x00007F;
549 mask_keyup = 0x000080; 551 mask_keyup = 0x000080;
550 polling = 50; // ms 552 polling = 50; // ms
551 break; 553 break;
552 case SAA7134_BOARD_VIDEOMATE_DVBT_300: 554 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
553 case SAA7134_BOARD_VIDEOMATE_DVBT_200: 555 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
554 ir_codes = ir_codes_videomate_tv_pvr; 556 ir_codes = &ir_codes_videomate_tv_pvr_table;
555 mask_keycode = 0x003F00; 557 mask_keycode = 0x003F00;
556 mask_keyup = 0x040000; 558 mask_keyup = 0x040000;
557 break; 559 break;
558 case SAA7134_BOARD_FLYDVBS_LR300: 560 case SAA7134_BOARD_FLYDVBS_LR300:
559 case SAA7134_BOARD_FLYDVBT_LR301: 561 case SAA7134_BOARD_FLYDVBT_LR301:
560 case SAA7134_BOARD_FLYDVBTDUO: 562 case SAA7134_BOARD_FLYDVBTDUO:
561 ir_codes = ir_codes_flydvb; 563 ir_codes = &ir_codes_flydvb_table;
562 mask_keycode = 0x0001F00; 564 mask_keycode = 0x0001F00;
563 mask_keydown = 0x0040000; 565 mask_keydown = 0x0040000;
564 break; 566 break;
565 case SAA7134_BOARD_ASUSTeK_P7131_DUAL: 567 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
566 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA: 568 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
567 case SAA7134_BOARD_ASUSTeK_P7131_ANALOG: 569 case SAA7134_BOARD_ASUSTeK_P7131_ANALOG:
568 ir_codes = ir_codes_asus_pc39; 570 ir_codes = &ir_codes_asus_pc39_table;
569 mask_keydown = 0x0040000; 571 mask_keydown = 0x0040000;
570 rc5_gpio = 1; 572 rc5_gpio = 1;
571 break; 573 break;
572 case SAA7134_BOARD_ENCORE_ENLTV: 574 case SAA7134_BOARD_ENCORE_ENLTV:
573 case SAA7134_BOARD_ENCORE_ENLTV_FM: 575 case SAA7134_BOARD_ENCORE_ENLTV_FM:
574 ir_codes = ir_codes_encore_enltv; 576 ir_codes = &ir_codes_encore_enltv_table;
575 mask_keycode = 0x00007f; 577 mask_keycode = 0x00007f;
576 mask_keyup = 0x040000; 578 mask_keyup = 0x040000;
577 polling = 50; // ms 579 polling = 50; // ms
578 break; 580 break;
579 case SAA7134_BOARD_ENCORE_ENLTV_FM53: 581 case SAA7134_BOARD_ENCORE_ENLTV_FM53:
580 ir_codes = ir_codes_encore_enltv_fm53; 582 ir_codes = &ir_codes_encore_enltv_fm53_table;
581 mask_keydown = 0x0040000; 583 mask_keydown = 0x0040000;
582 mask_keycode = 0x00007f; 584 mask_keycode = 0x00007f;
583 nec_gpio = 1; 585 nec_gpio = 1;
584 break; 586 break;
585 case SAA7134_BOARD_10MOONSTVMASTER3: 587 case SAA7134_BOARD_10MOONSTVMASTER3:
586 ir_codes = ir_codes_encore_enltv; 588 ir_codes = &ir_codes_encore_enltv_table;
587 mask_keycode = 0x5f80000; 589 mask_keycode = 0x5f80000;
588 mask_keyup = 0x8000000; 590 mask_keyup = 0x8000000;
589 polling = 50; //ms 591 polling = 50; //ms
590 break; 592 break;
591 case SAA7134_BOARD_GENIUS_TVGO_A11MCE: 593 case SAA7134_BOARD_GENIUS_TVGO_A11MCE:
592 ir_codes = ir_codes_genius_tvgo_a11mce; 594 ir_codes = &ir_codes_genius_tvgo_a11mce_table;
593 mask_keycode = 0xff; 595 mask_keycode = 0xff;
594 mask_keydown = 0xf00000; 596 mask_keydown = 0xf00000;
595 polling = 50; /* ms */ 597 polling = 50; /* ms */
596 break; 598 break;
597 case SAA7134_BOARD_REAL_ANGEL_220: 599 case SAA7134_BOARD_REAL_ANGEL_220:
598 ir_codes = ir_codes_real_audio_220_32_keys; 600 ir_codes = &ir_codes_real_audio_220_32_keys_table;
599 mask_keycode = 0x3f00; 601 mask_keycode = 0x3f00;
600 mask_keyup = 0x4000; 602 mask_keyup = 0x4000;
601 polling = 50; /* ms */ 603 polling = 50; /* ms */
602 break; 604 break;
603 case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG: 605 case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG:
604 ir_codes = ir_codes_kworld_plus_tv_analog; 606 ir_codes = &ir_codes_kworld_plus_tv_analog_table;
605 mask_keycode = 0x7f; 607 mask_keycode = 0x7f;
606 polling = 40; /* ms */ 608 polling = 40; /* ms */
607 break; 609 break;
610 case SAA7134_BOARD_VIDEOMATE_S350:
611 ir_codes = &ir_codes_videomate_s350_table;
612 mask_keycode = 0x003f00;
613 mask_keydown = 0x040000;
614 break;
608 } 615 }
609 if (NULL == ir_codes) { 616 if (NULL == ir_codes) {
610 printk("%s: Oops: IR config error [card=%d]\n", 617 printk("%s: Oops: IR config error [card=%d]\n",
@@ -684,8 +691,6 @@ void saa7134_input_fini(struct saa7134_dev *dev)
684 691
685void saa7134_probe_i2c_ir(struct saa7134_dev *dev) 692void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
686{ 693{
687 struct i2c_board_info info;
688 struct IR_i2c_init_data init_data;
689 const unsigned short addr_list[] = { 694 const unsigned short addr_list[] = {
690 0x7a, 0x47, 0x71, 0x2d, 695 0x7a, 0x47, 0x71, 0x2d,
691 I2C_CLIENT_END 696 I2C_CLIENT_END
@@ -705,32 +710,34 @@ void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
705 return; 710 return;
706 } 711 }
707 712
708 memset(&info, 0, sizeof(struct i2c_board_info)); 713 memset(&dev->info, 0, sizeof(dev->info));
709 memset(&init_data, 0, sizeof(struct IR_i2c_init_data)); 714 memset(&dev->init_data, 0, sizeof(dev->init_data));
710 strlcpy(info.type, "ir_video", I2C_NAME_SIZE); 715 strlcpy(dev->info.type, "ir_video", I2C_NAME_SIZE);
711 716
712 switch (dev->board) { 717 switch (dev->board) {
713 case SAA7134_BOARD_PINNACLE_PCTV_110i: 718 case SAA7134_BOARD_PINNACLE_PCTV_110i:
714 case SAA7134_BOARD_PINNACLE_PCTV_310i: 719 case SAA7134_BOARD_PINNACLE_PCTV_310i:
715 init_data.name = "Pinnacle PCTV"; 720 dev->init_data.name = "Pinnacle PCTV";
716 if (pinnacle_remote == 0) { 721 if (pinnacle_remote == 0) {
717 init_data.get_key = get_key_pinnacle_color; 722 dev->init_data.get_key = get_key_pinnacle_color;
718 init_data.ir_codes = ir_codes_pinnacle_color; 723 dev->init_data.ir_codes = &ir_codes_pinnacle_color_table;
724 dev->info.addr = 0x47;
719 } else { 725 } else {
720 init_data.get_key = get_key_pinnacle_grey; 726 dev->init_data.get_key = get_key_pinnacle_grey;
721 init_data.ir_codes = ir_codes_pinnacle_grey; 727 dev->init_data.ir_codes = &ir_codes_pinnacle_grey_table;
728 dev->info.addr = 0x47;
722 } 729 }
723 break; 730 break;
724 case SAA7134_BOARD_UPMOST_PURPLE_TV: 731 case SAA7134_BOARD_UPMOST_PURPLE_TV:
725 init_data.name = "Purple TV"; 732 dev->init_data.name = "Purple TV";
726 init_data.get_key = get_key_purpletv; 733 dev->init_data.get_key = get_key_purpletv;
727 init_data.ir_codes = ir_codes_purpletv; 734 dev->init_data.ir_codes = &ir_codes_purpletv_table;
728 break; 735 break;
729 case SAA7134_BOARD_MSI_TVATANYWHERE_PLUS: 736 case SAA7134_BOARD_MSI_TVATANYWHERE_PLUS:
730 init_data.name = "MSI TV@nywhere Plus"; 737 dev->init_data.name = "MSI TV@nywhere Plus";
731 init_data.get_key = get_key_msi_tvanywhere_plus; 738 dev->init_data.get_key = get_key_msi_tvanywhere_plus;
732 init_data.ir_codes = ir_codes_msi_tvanywhere_plus; 739 dev->init_data.ir_codes = &ir_codes_msi_tvanywhere_plus_table;
733 info.addr = 0x30; 740 dev->info.addr = 0x30;
734 /* MSI TV@nywhere Plus controller doesn't seem to 741 /* MSI TV@nywhere Plus controller doesn't seem to
735 respond to probes unless we read something from 742 respond to probes unless we read something from
736 an existing device. Weird... 743 an existing device. Weird...
@@ -741,9 +748,9 @@ void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
741 (1 == rc) ? "yes" : "no"); 748 (1 == rc) ? "yes" : "no");
742 break; 749 break;
743 case SAA7134_BOARD_HAUPPAUGE_HVR1110: 750 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
744 init_data.name = "HVR 1110"; 751 dev->init_data.name = "HVR 1110";
745 init_data.get_key = get_key_hvr1110; 752 dev->init_data.get_key = get_key_hvr1110;
746 init_data.ir_codes = ir_codes_hauppauge_new; 753 dev->init_data.ir_codes = &ir_codes_hauppauge_new_table;
747 break; 754 break;
748 case SAA7134_BOARD_BEHOLD_607FM_MK3: 755 case SAA7134_BOARD_BEHOLD_607FM_MK3:
749 case SAA7134_BOARD_BEHOLD_607FM_MK5: 756 case SAA7134_BOARD_BEHOLD_607FM_MK5:
@@ -757,26 +764,27 @@ void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
757 case SAA7134_BOARD_BEHOLD_M63: 764 case SAA7134_BOARD_BEHOLD_M63:
758 case SAA7134_BOARD_BEHOLD_M6_EXTRA: 765 case SAA7134_BOARD_BEHOLD_M6_EXTRA:
759 case SAA7134_BOARD_BEHOLD_H6: 766 case SAA7134_BOARD_BEHOLD_H6:
760 init_data.name = "BeholdTV"; 767 case SAA7134_BOARD_BEHOLD_X7:
761 init_data.get_key = get_key_beholdm6xx; 768 dev->init_data.name = "BeholdTV";
762 init_data.ir_codes = ir_codes_behold; 769 dev->init_data.get_key = get_key_beholdm6xx;
770 dev->init_data.ir_codes = &ir_codes_behold_table;
763 break; 771 break;
764 case SAA7134_BOARD_AVERMEDIA_CARDBUS_501: 772 case SAA7134_BOARD_AVERMEDIA_CARDBUS_501:
765 case SAA7134_BOARD_AVERMEDIA_CARDBUS_506: 773 case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
766 info.addr = 0x40; 774 dev->info.addr = 0x40;
767 break; 775 break;
768 } 776 }
769 777
770 if (init_data.name) 778 if (dev->init_data.name)
771 info.platform_data = &init_data; 779 dev->info.platform_data = &dev->init_data;
772 /* No need to probe if address is known */ 780 /* No need to probe if address is known */
773 if (info.addr) { 781 if (dev->info.addr) {
774 i2c_new_device(&dev->i2c_adap, &info); 782 i2c_new_device(&dev->i2c_adap, &dev->info);
775 return; 783 return;
776 } 784 }
777 785
778 /* Address not known, fallback to probing */ 786 /* Address not known, fallback to probing */
779 i2c_new_probed_device(&dev->i2c_adap, &info, addr_list); 787 i2c_new_probed_device(&dev->i2c_adap, &dev->info, addr_list);
780} 788}
781 789
782static int saa7134_rc5_irq(struct saa7134_dev *dev) 790static int saa7134_rc5_irq(struct saa7134_dev *dev)
diff --git a/drivers/media/video/saa7134/saa7134-video.c b/drivers/media/video/saa7134/saa7134-video.c
index ba87128542e0..da26f476a302 100644
--- a/drivers/media/video/saa7134/saa7134-video.c
+++ b/drivers/media/video/saa7134/saa7134-video.c
@@ -1444,7 +1444,6 @@ video_poll(struct file *file, struct poll_table_struct *wait)
1444 fh->cap.ops->buf_queue(&fh->cap,fh->cap.read_buf); 1444 fh->cap.ops->buf_queue(&fh->cap,fh->cap.read_buf);
1445 fh->cap.read_off = 0; 1445 fh->cap.read_off = 0;
1446 } 1446 }
1447 mutex_unlock(&fh->cap.vb_lock);
1448 buf = fh->cap.read_buf; 1447 buf = fh->cap.read_buf;
1449 } 1448 }
1450 1449
@@ -1790,7 +1789,7 @@ static int saa7134_s_input(struct file *file, void *priv, unsigned int i)
1790 if (0 != err) 1789 if (0 != err)
1791 return err; 1790 return err;
1792 1791
1793 if (i < 0 || i >= SAA7134_INPUT_MAX) 1792 if (i >= SAA7134_INPUT_MAX)
1794 return -EINVAL; 1793 return -EINVAL;
1795 if (NULL == card_in(dev, i).name) 1794 if (NULL == card_in(dev, i).name)
1796 return -EINVAL; 1795 return -EINVAL;
@@ -1819,6 +1818,8 @@ static int saa7134_querycap(struct file *file, void *priv,
1819 V4L2_CAP_READWRITE | 1818 V4L2_CAP_READWRITE |
1820 V4L2_CAP_STREAMING | 1819 V4L2_CAP_STREAMING |
1821 V4L2_CAP_TUNER; 1820 V4L2_CAP_TUNER;
1821 if (dev->has_rds)
1822 cap->capabilities |= V4L2_CAP_RDS_CAPTURE;
1822 if (saa7134_no_overlay <= 0) 1823 if (saa7134_no_overlay <= 0)
1823 cap->capabilities |= V4L2_CAP_VIDEO_OVERLAY; 1824 cap->capabilities |= V4L2_CAP_VIDEO_OVERLAY;
1824 1825
diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
index fb564f14887c..d18bb9643856 100644
--- a/drivers/media/video/saa7134/saa7134.h
+++ b/drivers/media/video/saa7134/saa7134.h
@@ -292,6 +292,10 @@ struct saa7134_format {
292#define SAA7134_BOARD_BEHOLD_607RDS_MK5 166 292#define SAA7134_BOARD_BEHOLD_607RDS_MK5 166
293#define SAA7134_BOARD_BEHOLD_609RDS_MK3 167 293#define SAA7134_BOARD_BEHOLD_609RDS_MK3 167
294#define SAA7134_BOARD_BEHOLD_609RDS_MK5 168 294#define SAA7134_BOARD_BEHOLD_609RDS_MK5 168
295#define SAA7134_BOARD_VIDEOMATE_S350 169
296#define SAA7134_BOARD_AVERMEDIA_STUDIO_505 170
297#define SAA7134_BOARD_BEHOLD_X7 171
298#define SAA7134_BOARD_ROVERMEDIA_LINK_PRO_FM 172
295 299
296#define SAA7134_MAXBOARDS 32 300#define SAA7134_MAXBOARDS 32
297#define SAA7134_INPUT_MAX 8 301#define SAA7134_INPUT_MAX 8
@@ -539,6 +543,7 @@ struct saa7134_dev {
539 struct i2c_adapter i2c_adap; 543 struct i2c_adapter i2c_adap;
540 struct i2c_client i2c_client; 544 struct i2c_client i2c_client;
541 unsigned char eedata[256]; 545 unsigned char eedata[256];
546 int has_rds;
542 547
543 /* video overlay */ 548 /* video overlay */
544 struct v4l2_framebuffer ovbuf; 549 struct v4l2_framebuffer ovbuf;
@@ -584,6 +589,10 @@ struct saa7134_dev {
584 int nosignal; 589 int nosignal;
585 unsigned int insuspend; 590 unsigned int insuspend;
586 591
592 /* I2C keyboard data */
593 struct i2c_board_info info;
594 struct IR_i2c_init_data init_data;
595
587 /* SAA7134_MPEG_* */ 596 /* SAA7134_MPEG_* */
588 struct saa7134_ts ts; 597 struct saa7134_ts ts;
589 struct saa7134_dmaqueue ts_q; 598 struct saa7134_dmaqueue ts_q;
diff --git a/drivers/media/video/sn9c102/sn9c102_devtable.h b/drivers/media/video/sn9c102/sn9c102_devtable.h
index 38a716020d7f..36ee43a9ee95 100644
--- a/drivers/media/video/sn9c102/sn9c102_devtable.h
+++ b/drivers/media/video/sn9c102/sn9c102_devtable.h
@@ -123,8 +123,8 @@ static const struct usb_device_id sn9c102_id_table[] = {
123 { SN9C102_USB_DEVICE(0x0c45, 0x613b, BRIDGE_SN9C120), }, 123 { SN9C102_USB_DEVICE(0x0c45, 0x613b, BRIDGE_SN9C120), },
124#if !defined CONFIG_USB_GSPCA && !defined CONFIG_USB_GSPCA_MODULE 124#if !defined CONFIG_USB_GSPCA && !defined CONFIG_USB_GSPCA_MODULE
125 { SN9C102_USB_DEVICE(0x0c45, 0x613c, BRIDGE_SN9C120), }, 125 { SN9C102_USB_DEVICE(0x0c45, 0x613c, BRIDGE_SN9C120), },
126#endif
127 { SN9C102_USB_DEVICE(0x0c45, 0x613e, BRIDGE_SN9C120), }, 126 { SN9C102_USB_DEVICE(0x0c45, 0x613e, BRIDGE_SN9C120), },
127#endif
128 { } 128 { }
129}; 129};
130 130
diff --git a/drivers/media/video/stk-webcam.c b/drivers/media/video/stk-webcam.c
index b154bd961e3b..0b996ea4134e 100644
--- a/drivers/media/video/stk-webcam.c
+++ b/drivers/media/video/stk-webcam.c
@@ -1400,7 +1400,6 @@ static int stk_camera_probe(struct usb_interface *interface,
1400 } 1400 }
1401 1401
1402 stk_create_sysfs_files(&dev->vdev); 1402 stk_create_sysfs_files(&dev->vdev);
1403 usb_autopm_enable(dev->interface);
1404 1403
1405 return 0; 1404 return 0;
1406 1405
diff --git a/drivers/media/video/stv680.c b/drivers/media/video/stv680.c
index 8b4e7dafce7b..6a91714125d2 100644
--- a/drivers/media/video/stv680.c
+++ b/drivers/media/video/stv680.c
@@ -734,10 +734,6 @@ static int stv680_start_stream (struct usb_stv *stv680)
734 return 0; 734 return 0;
735 735
736 nomem_err: 736 nomem_err:
737 for (i = 0; i < STV680_NUMSCRATCH; i++) {
738 kfree(stv680->scratch[i].data);
739 stv680->scratch[i].data = NULL;
740 }
741 for (i = 0; i < STV680_NUMSBUF; i++) { 737 for (i = 0; i < STV680_NUMSBUF; i++) {
742 usb_kill_urb(stv680->urb[i]); 738 usb_kill_urb(stv680->urb[i]);
743 usb_free_urb(stv680->urb[i]); 739 usb_free_urb(stv680->urb[i]);
@@ -745,6 +741,11 @@ static int stv680_start_stream (struct usb_stv *stv680)
745 kfree(stv680->sbuf[i].data); 741 kfree(stv680->sbuf[i].data);
746 stv680->sbuf[i].data = NULL; 742 stv680->sbuf[i].data = NULL;
747 } 743 }
744 /* used in irq, free only as all URBs are dead */
745 for (i = 0; i < STV680_NUMSCRATCH; i++) {
746 kfree(stv680->scratch[i].data);
747 stv680->scratch[i].data = NULL;
748 }
748 return -ENOMEM; 749 return -ENOMEM;
749 750
750} 751}
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index 537594211a90..2816f1839230 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -819,8 +819,8 @@ static int tuner_g_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f)
819 819
820 fe_tuner_ops->get_frequency(&t->fe, &abs_freq); 820 fe_tuner_ops->get_frequency(&t->fe, &abs_freq);
821 f->frequency = (V4L2_TUNER_RADIO == t->mode) ? 821 f->frequency = (V4L2_TUNER_RADIO == t->mode) ?
822 (abs_freq * 2 + 125/2) / 125 : 822 DIV_ROUND_CLOSEST(abs_freq * 2, 125) :
823 (abs_freq + 62500/2) / 62500; 823 DIV_ROUND_CLOSEST(abs_freq, 62500);
824 return 0; 824 return 0;
825 } 825 }
826 f->frequency = (V4L2_TUNER_RADIO == t->mode) ? 826 f->frequency = (V4L2_TUNER_RADIO == t->mode) ?
diff --git a/drivers/media/video/tveeprom.c b/drivers/media/video/tveeprom.c
index ac02808106c1..d533ea57e7b1 100644
--- a/drivers/media/video/tveeprom.c
+++ b/drivers/media/video/tveeprom.c
@@ -646,14 +646,14 @@ void tveeprom_hauppauge_analog(struct i2c_client *c, struct tveeprom *tvee,
646 tvee->has_radio = 1; 646 tvee->has_radio = 1;
647 } 647 }
648 648
649 if (tuner1 < sizeof(hauppauge_tuner)/sizeof(struct HAUPPAUGE_TUNER)) { 649 if (tuner1 < ARRAY_SIZE(hauppauge_tuner)) {
650 tvee->tuner_type = hauppauge_tuner[tuner1].id; 650 tvee->tuner_type = hauppauge_tuner[tuner1].id;
651 t_name1 = hauppauge_tuner[tuner1].name; 651 t_name1 = hauppauge_tuner[tuner1].name;
652 } else { 652 } else {
653 t_name1 = "unknown"; 653 t_name1 = "unknown";
654 } 654 }
655 655
656 if (tuner2 < sizeof(hauppauge_tuner)/sizeof(struct HAUPPAUGE_TUNER)) { 656 if (tuner2 < ARRAY_SIZE(hauppauge_tuner)) {
657 tvee->tuner2_type = hauppauge_tuner[tuner2].id; 657 tvee->tuner2_type = hauppauge_tuner[tuner2].id;
658 t_name2 = hauppauge_tuner[tuner2].name; 658 t_name2 = hauppauge_tuner[tuner2].name;
659 } else { 659 } else {
diff --git a/drivers/media/video/uvc/uvc_ctrl.c b/drivers/media/video/uvc/uvc_ctrl.c
index 36a6ba92df27..c3225a561748 100644
--- a/drivers/media/video/uvc/uvc_ctrl.c
+++ b/drivers/media/video/uvc/uvc_ctrl.c
@@ -34,7 +34,7 @@
34static struct uvc_control_info uvc_ctrls[] = { 34static struct uvc_control_info uvc_ctrls[] = {
35 { 35 {
36 .entity = UVC_GUID_UVC_PROCESSING, 36 .entity = UVC_GUID_UVC_PROCESSING,
37 .selector = PU_BRIGHTNESS_CONTROL, 37 .selector = UVC_PU_BRIGHTNESS_CONTROL,
38 .index = 0, 38 .index = 0,
39 .size = 2, 39 .size = 2,
40 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE 40 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
@@ -42,7 +42,7 @@ static struct uvc_control_info uvc_ctrls[] = {
42 }, 42 },
43 { 43 {
44 .entity = UVC_GUID_UVC_PROCESSING, 44 .entity = UVC_GUID_UVC_PROCESSING,
45 .selector = PU_CONTRAST_CONTROL, 45 .selector = UVC_PU_CONTRAST_CONTROL,
46 .index = 1, 46 .index = 1,
47 .size = 2, 47 .size = 2,
48 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE 48 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
@@ -50,7 +50,7 @@ static struct uvc_control_info uvc_ctrls[] = {
50 }, 50 },
51 { 51 {
52 .entity = UVC_GUID_UVC_PROCESSING, 52 .entity = UVC_GUID_UVC_PROCESSING,
53 .selector = PU_HUE_CONTROL, 53 .selector = UVC_PU_HUE_CONTROL,
54 .index = 2, 54 .index = 2,
55 .size = 2, 55 .size = 2,
56 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE 56 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
@@ -58,7 +58,7 @@ static struct uvc_control_info uvc_ctrls[] = {
58 }, 58 },
59 { 59 {
60 .entity = UVC_GUID_UVC_PROCESSING, 60 .entity = UVC_GUID_UVC_PROCESSING,
61 .selector = PU_SATURATION_CONTROL, 61 .selector = UVC_PU_SATURATION_CONTROL,
62 .index = 3, 62 .index = 3,
63 .size = 2, 63 .size = 2,
64 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE 64 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
@@ -66,7 +66,7 @@ static struct uvc_control_info uvc_ctrls[] = {
66 }, 66 },
67 { 67 {
68 .entity = UVC_GUID_UVC_PROCESSING, 68 .entity = UVC_GUID_UVC_PROCESSING,
69 .selector = PU_SHARPNESS_CONTROL, 69 .selector = UVC_PU_SHARPNESS_CONTROL,
70 .index = 4, 70 .index = 4,
71 .size = 2, 71 .size = 2,
72 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE 72 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
@@ -74,7 +74,7 @@ static struct uvc_control_info uvc_ctrls[] = {
74 }, 74 },
75 { 75 {
76 .entity = UVC_GUID_UVC_PROCESSING, 76 .entity = UVC_GUID_UVC_PROCESSING,
77 .selector = PU_GAMMA_CONTROL, 77 .selector = UVC_PU_GAMMA_CONTROL,
78 .index = 5, 78 .index = 5,
79 .size = 2, 79 .size = 2,
80 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE 80 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
@@ -82,7 +82,7 @@ static struct uvc_control_info uvc_ctrls[] = {
82 }, 82 },
83 { 83 {
84 .entity = UVC_GUID_UVC_PROCESSING, 84 .entity = UVC_GUID_UVC_PROCESSING,
85 .selector = PU_WHITE_BALANCE_TEMPERATURE_CONTROL, 85 .selector = UVC_PU_WHITE_BALANCE_TEMPERATURE_CONTROL,
86 .index = 6, 86 .index = 6,
87 .size = 2, 87 .size = 2,
88 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE 88 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
@@ -90,7 +90,7 @@ static struct uvc_control_info uvc_ctrls[] = {
90 }, 90 },
91 { 91 {
92 .entity = UVC_GUID_UVC_PROCESSING, 92 .entity = UVC_GUID_UVC_PROCESSING,
93 .selector = PU_WHITE_BALANCE_COMPONENT_CONTROL, 93 .selector = UVC_PU_WHITE_BALANCE_COMPONENT_CONTROL,
94 .index = 7, 94 .index = 7,
95 .size = 4, 95 .size = 4,
96 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE 96 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
@@ -98,7 +98,7 @@ static struct uvc_control_info uvc_ctrls[] = {
98 }, 98 },
99 { 99 {
100 .entity = UVC_GUID_UVC_PROCESSING, 100 .entity = UVC_GUID_UVC_PROCESSING,
101 .selector = PU_BACKLIGHT_COMPENSATION_CONTROL, 101 .selector = UVC_PU_BACKLIGHT_COMPENSATION_CONTROL,
102 .index = 8, 102 .index = 8,
103 .size = 2, 103 .size = 2,
104 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE 104 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
@@ -106,7 +106,7 @@ static struct uvc_control_info uvc_ctrls[] = {
106 }, 106 },
107 { 107 {
108 .entity = UVC_GUID_UVC_PROCESSING, 108 .entity = UVC_GUID_UVC_PROCESSING,
109 .selector = PU_GAIN_CONTROL, 109 .selector = UVC_PU_GAIN_CONTROL,
110 .index = 9, 110 .index = 9,
111 .size = 2, 111 .size = 2,
112 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE 112 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
@@ -114,7 +114,7 @@ static struct uvc_control_info uvc_ctrls[] = {
114 }, 114 },
115 { 115 {
116 .entity = UVC_GUID_UVC_PROCESSING, 116 .entity = UVC_GUID_UVC_PROCESSING,
117 .selector = PU_POWER_LINE_FREQUENCY_CONTROL, 117 .selector = UVC_PU_POWER_LINE_FREQUENCY_CONTROL,
118 .index = 10, 118 .index = 10,
119 .size = 1, 119 .size = 1,
120 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE 120 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
@@ -122,7 +122,7 @@ static struct uvc_control_info uvc_ctrls[] = {
122 }, 122 },
123 { 123 {
124 .entity = UVC_GUID_UVC_PROCESSING, 124 .entity = UVC_GUID_UVC_PROCESSING,
125 .selector = PU_HUE_AUTO_CONTROL, 125 .selector = UVC_PU_HUE_AUTO_CONTROL,
126 .index = 11, 126 .index = 11,
127 .size = 1, 127 .size = 1,
128 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR 128 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
@@ -130,7 +130,7 @@ static struct uvc_control_info uvc_ctrls[] = {
130 }, 130 },
131 { 131 {
132 .entity = UVC_GUID_UVC_PROCESSING, 132 .entity = UVC_GUID_UVC_PROCESSING,
133 .selector = PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL, 133 .selector = UVC_PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL,
134 .index = 12, 134 .index = 12,
135 .size = 1, 135 .size = 1,
136 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR 136 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
@@ -138,7 +138,7 @@ static struct uvc_control_info uvc_ctrls[] = {
138 }, 138 },
139 { 139 {
140 .entity = UVC_GUID_UVC_PROCESSING, 140 .entity = UVC_GUID_UVC_PROCESSING,
141 .selector = PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL, 141 .selector = UVC_PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL,
142 .index = 13, 142 .index = 13,
143 .size = 1, 143 .size = 1,
144 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR 144 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
@@ -146,7 +146,7 @@ static struct uvc_control_info uvc_ctrls[] = {
146 }, 146 },
147 { 147 {
148 .entity = UVC_GUID_UVC_PROCESSING, 148 .entity = UVC_GUID_UVC_PROCESSING,
149 .selector = PU_DIGITAL_MULTIPLIER_CONTROL, 149 .selector = UVC_PU_DIGITAL_MULTIPLIER_CONTROL,
150 .index = 14, 150 .index = 14,
151 .size = 2, 151 .size = 2,
152 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE 152 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
@@ -154,7 +154,7 @@ static struct uvc_control_info uvc_ctrls[] = {
154 }, 154 },
155 { 155 {
156 .entity = UVC_GUID_UVC_PROCESSING, 156 .entity = UVC_GUID_UVC_PROCESSING,
157 .selector = PU_DIGITAL_MULTIPLIER_LIMIT_CONTROL, 157 .selector = UVC_PU_DIGITAL_MULTIPLIER_LIMIT_CONTROL,
158 .index = 15, 158 .index = 15,
159 .size = 2, 159 .size = 2,
160 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE 160 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
@@ -162,21 +162,21 @@ static struct uvc_control_info uvc_ctrls[] = {
162 }, 162 },
163 { 163 {
164 .entity = UVC_GUID_UVC_PROCESSING, 164 .entity = UVC_GUID_UVC_PROCESSING,
165 .selector = PU_ANALOG_VIDEO_STANDARD_CONTROL, 165 .selector = UVC_PU_ANALOG_VIDEO_STANDARD_CONTROL,
166 .index = 16, 166 .index = 16,
167 .size = 1, 167 .size = 1,
168 .flags = UVC_CONTROL_GET_CUR, 168 .flags = UVC_CONTROL_GET_CUR,
169 }, 169 },
170 { 170 {
171 .entity = UVC_GUID_UVC_PROCESSING, 171 .entity = UVC_GUID_UVC_PROCESSING,
172 .selector = PU_ANALOG_LOCK_STATUS_CONTROL, 172 .selector = UVC_PU_ANALOG_LOCK_STATUS_CONTROL,
173 .index = 17, 173 .index = 17,
174 .size = 1, 174 .size = 1,
175 .flags = UVC_CONTROL_GET_CUR, 175 .flags = UVC_CONTROL_GET_CUR,
176 }, 176 },
177 { 177 {
178 .entity = UVC_GUID_UVC_CAMERA, 178 .entity = UVC_GUID_UVC_CAMERA,
179 .selector = CT_SCANNING_MODE_CONTROL, 179 .selector = UVC_CT_SCANNING_MODE_CONTROL,
180 .index = 0, 180 .index = 0,
181 .size = 1, 181 .size = 1,
182 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR 182 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
@@ -184,7 +184,7 @@ static struct uvc_control_info uvc_ctrls[] = {
184 }, 184 },
185 { 185 {
186 .entity = UVC_GUID_UVC_CAMERA, 186 .entity = UVC_GUID_UVC_CAMERA,
187 .selector = CT_AE_MODE_CONTROL, 187 .selector = UVC_CT_AE_MODE_CONTROL,
188 .index = 1, 188 .index = 1,
189 .size = 1, 189 .size = 1,
190 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR 190 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
@@ -193,7 +193,7 @@ static struct uvc_control_info uvc_ctrls[] = {
193 }, 193 },
194 { 194 {
195 .entity = UVC_GUID_UVC_CAMERA, 195 .entity = UVC_GUID_UVC_CAMERA,
196 .selector = CT_AE_PRIORITY_CONTROL, 196 .selector = UVC_CT_AE_PRIORITY_CONTROL,
197 .index = 2, 197 .index = 2,
198 .size = 1, 198 .size = 1,
199 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR 199 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
@@ -201,7 +201,7 @@ static struct uvc_control_info uvc_ctrls[] = {
201 }, 201 },
202 { 202 {
203 .entity = UVC_GUID_UVC_CAMERA, 203 .entity = UVC_GUID_UVC_CAMERA,
204 .selector = CT_EXPOSURE_TIME_ABSOLUTE_CONTROL, 204 .selector = UVC_CT_EXPOSURE_TIME_ABSOLUTE_CONTROL,
205 .index = 3, 205 .index = 3,
206 .size = 4, 206 .size = 4,
207 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE 207 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
@@ -209,7 +209,7 @@ static struct uvc_control_info uvc_ctrls[] = {
209 }, 209 },
210 { 210 {
211 .entity = UVC_GUID_UVC_CAMERA, 211 .entity = UVC_GUID_UVC_CAMERA,
212 .selector = CT_EXPOSURE_TIME_RELATIVE_CONTROL, 212 .selector = UVC_CT_EXPOSURE_TIME_RELATIVE_CONTROL,
213 .index = 4, 213 .index = 4,
214 .size = 1, 214 .size = 1,
215 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR 215 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
@@ -217,7 +217,7 @@ static struct uvc_control_info uvc_ctrls[] = {
217 }, 217 },
218 { 218 {
219 .entity = UVC_GUID_UVC_CAMERA, 219 .entity = UVC_GUID_UVC_CAMERA,
220 .selector = CT_FOCUS_ABSOLUTE_CONTROL, 220 .selector = UVC_CT_FOCUS_ABSOLUTE_CONTROL,
221 .index = 5, 221 .index = 5,
222 .size = 2, 222 .size = 2,
223 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE 223 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
@@ -225,7 +225,7 @@ static struct uvc_control_info uvc_ctrls[] = {
225 }, 225 },
226 { 226 {
227 .entity = UVC_GUID_UVC_CAMERA, 227 .entity = UVC_GUID_UVC_CAMERA,
228 .selector = CT_FOCUS_RELATIVE_CONTROL, 228 .selector = UVC_CT_FOCUS_RELATIVE_CONTROL,
229 .index = 6, 229 .index = 6,
230 .size = 2, 230 .size = 2,
231 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE 231 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
@@ -233,7 +233,7 @@ static struct uvc_control_info uvc_ctrls[] = {
233 }, 233 },
234 { 234 {
235 .entity = UVC_GUID_UVC_CAMERA, 235 .entity = UVC_GUID_UVC_CAMERA,
236 .selector = CT_IRIS_ABSOLUTE_CONTROL, 236 .selector = UVC_CT_IRIS_ABSOLUTE_CONTROL,
237 .index = 7, 237 .index = 7,
238 .size = 2, 238 .size = 2,
239 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE 239 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
@@ -241,7 +241,7 @@ static struct uvc_control_info uvc_ctrls[] = {
241 }, 241 },
242 { 242 {
243 .entity = UVC_GUID_UVC_CAMERA, 243 .entity = UVC_GUID_UVC_CAMERA,
244 .selector = CT_IRIS_RELATIVE_CONTROL, 244 .selector = UVC_CT_IRIS_RELATIVE_CONTROL,
245 .index = 8, 245 .index = 8,
246 .size = 1, 246 .size = 1,
247 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR 247 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
@@ -249,7 +249,7 @@ static struct uvc_control_info uvc_ctrls[] = {
249 }, 249 },
250 { 250 {
251 .entity = UVC_GUID_UVC_CAMERA, 251 .entity = UVC_GUID_UVC_CAMERA,
252 .selector = CT_ZOOM_ABSOLUTE_CONTROL, 252 .selector = UVC_CT_ZOOM_ABSOLUTE_CONTROL,
253 .index = 9, 253 .index = 9,
254 .size = 2, 254 .size = 2,
255 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE 255 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
@@ -257,7 +257,7 @@ static struct uvc_control_info uvc_ctrls[] = {
257 }, 257 },
258 { 258 {
259 .entity = UVC_GUID_UVC_CAMERA, 259 .entity = UVC_GUID_UVC_CAMERA,
260 .selector = CT_ZOOM_RELATIVE_CONTROL, 260 .selector = UVC_CT_ZOOM_RELATIVE_CONTROL,
261 .index = 10, 261 .index = 10,
262 .size = 3, 262 .size = 3,
263 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE 263 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
@@ -265,7 +265,7 @@ static struct uvc_control_info uvc_ctrls[] = {
265 }, 265 },
266 { 266 {
267 .entity = UVC_GUID_UVC_CAMERA, 267 .entity = UVC_GUID_UVC_CAMERA,
268 .selector = CT_PANTILT_ABSOLUTE_CONTROL, 268 .selector = UVC_CT_PANTILT_ABSOLUTE_CONTROL,
269 .index = 11, 269 .index = 11,
270 .size = 8, 270 .size = 8,
271 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE 271 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
@@ -273,7 +273,7 @@ static struct uvc_control_info uvc_ctrls[] = {
273 }, 273 },
274 { 274 {
275 .entity = UVC_GUID_UVC_CAMERA, 275 .entity = UVC_GUID_UVC_CAMERA,
276 .selector = CT_PANTILT_RELATIVE_CONTROL, 276 .selector = UVC_CT_PANTILT_RELATIVE_CONTROL,
277 .index = 12, 277 .index = 12,
278 .size = 4, 278 .size = 4,
279 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE 279 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
@@ -281,7 +281,7 @@ static struct uvc_control_info uvc_ctrls[] = {
281 }, 281 },
282 { 282 {
283 .entity = UVC_GUID_UVC_CAMERA, 283 .entity = UVC_GUID_UVC_CAMERA,
284 .selector = CT_ROLL_ABSOLUTE_CONTROL, 284 .selector = UVC_CT_ROLL_ABSOLUTE_CONTROL,
285 .index = 13, 285 .index = 13,
286 .size = 2, 286 .size = 2,
287 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE 287 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
@@ -289,7 +289,7 @@ static struct uvc_control_info uvc_ctrls[] = {
289 }, 289 },
290 { 290 {
291 .entity = UVC_GUID_UVC_CAMERA, 291 .entity = UVC_GUID_UVC_CAMERA,
292 .selector = CT_ROLL_RELATIVE_CONTROL, 292 .selector = UVC_CT_ROLL_RELATIVE_CONTROL,
293 .index = 14, 293 .index = 14,
294 .size = 2, 294 .size = 2,
295 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE 295 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
@@ -297,7 +297,7 @@ static struct uvc_control_info uvc_ctrls[] = {
297 }, 297 },
298 { 298 {
299 .entity = UVC_GUID_UVC_CAMERA, 299 .entity = UVC_GUID_UVC_CAMERA,
300 .selector = CT_FOCUS_AUTO_CONTROL, 300 .selector = UVC_CT_FOCUS_AUTO_CONTROL,
301 .index = 17, 301 .index = 17,
302 .size = 1, 302 .size = 1,
303 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR 303 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
@@ -305,7 +305,7 @@ static struct uvc_control_info uvc_ctrls[] = {
305 }, 305 },
306 { 306 {
307 .entity = UVC_GUID_UVC_CAMERA, 307 .entity = UVC_GUID_UVC_CAMERA,
308 .selector = CT_PRIVACY_CONTROL, 308 .selector = UVC_CT_PRIVACY_CONTROL,
309 .index = 18, 309 .index = 18,
310 .size = 1, 310 .size = 1,
311 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR 311 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
@@ -332,13 +332,13 @@ static __s32 uvc_ctrl_get_zoom(struct uvc_control_mapping *mapping,
332 __s8 zoom = (__s8)data[0]; 332 __s8 zoom = (__s8)data[0];
333 333
334 switch (query) { 334 switch (query) {
335 case GET_CUR: 335 case UVC_GET_CUR:
336 return (zoom == 0) ? 0 : (zoom > 0 ? data[2] : -data[2]); 336 return (zoom == 0) ? 0 : (zoom > 0 ? data[2] : -data[2]);
337 337
338 case GET_MIN: 338 case UVC_GET_MIN:
339 case GET_MAX: 339 case UVC_GET_MAX:
340 case GET_RES: 340 case UVC_GET_RES:
341 case GET_DEF: 341 case UVC_GET_DEF:
342 default: 342 default:
343 return data[2]; 343 return data[2];
344 } 344 }
@@ -356,7 +356,7 @@ static struct uvc_control_mapping uvc_ctrl_mappings[] = {
356 .id = V4L2_CID_BRIGHTNESS, 356 .id = V4L2_CID_BRIGHTNESS,
357 .name = "Brightness", 357 .name = "Brightness",
358 .entity = UVC_GUID_UVC_PROCESSING, 358 .entity = UVC_GUID_UVC_PROCESSING,
359 .selector = PU_BRIGHTNESS_CONTROL, 359 .selector = UVC_PU_BRIGHTNESS_CONTROL,
360 .size = 16, 360 .size = 16,
361 .offset = 0, 361 .offset = 0,
362 .v4l2_type = V4L2_CTRL_TYPE_INTEGER, 362 .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
@@ -366,7 +366,7 @@ static struct uvc_control_mapping uvc_ctrl_mappings[] = {
366 .id = V4L2_CID_CONTRAST, 366 .id = V4L2_CID_CONTRAST,
367 .name = "Contrast", 367 .name = "Contrast",
368 .entity = UVC_GUID_UVC_PROCESSING, 368 .entity = UVC_GUID_UVC_PROCESSING,
369 .selector = PU_CONTRAST_CONTROL, 369 .selector = UVC_PU_CONTRAST_CONTROL,
370 .size = 16, 370 .size = 16,
371 .offset = 0, 371 .offset = 0,
372 .v4l2_type = V4L2_CTRL_TYPE_INTEGER, 372 .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
@@ -376,7 +376,7 @@ static struct uvc_control_mapping uvc_ctrl_mappings[] = {
376 .id = V4L2_CID_HUE, 376 .id = V4L2_CID_HUE,
377 .name = "Hue", 377 .name = "Hue",
378 .entity = UVC_GUID_UVC_PROCESSING, 378 .entity = UVC_GUID_UVC_PROCESSING,
379 .selector = PU_HUE_CONTROL, 379 .selector = UVC_PU_HUE_CONTROL,
380 .size = 16, 380 .size = 16,
381 .offset = 0, 381 .offset = 0,
382 .v4l2_type = V4L2_CTRL_TYPE_INTEGER, 382 .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
@@ -386,7 +386,7 @@ static struct uvc_control_mapping uvc_ctrl_mappings[] = {
386 .id = V4L2_CID_SATURATION, 386 .id = V4L2_CID_SATURATION,
387 .name = "Saturation", 387 .name = "Saturation",
388 .entity = UVC_GUID_UVC_PROCESSING, 388 .entity = UVC_GUID_UVC_PROCESSING,
389 .selector = PU_SATURATION_CONTROL, 389 .selector = UVC_PU_SATURATION_CONTROL,
390 .size = 16, 390 .size = 16,
391 .offset = 0, 391 .offset = 0,
392 .v4l2_type = V4L2_CTRL_TYPE_INTEGER, 392 .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
@@ -396,7 +396,7 @@ static struct uvc_control_mapping uvc_ctrl_mappings[] = {
396 .id = V4L2_CID_SHARPNESS, 396 .id = V4L2_CID_SHARPNESS,
397 .name = "Sharpness", 397 .name = "Sharpness",
398 .entity = UVC_GUID_UVC_PROCESSING, 398 .entity = UVC_GUID_UVC_PROCESSING,
399 .selector = PU_SHARPNESS_CONTROL, 399 .selector = UVC_PU_SHARPNESS_CONTROL,
400 .size = 16, 400 .size = 16,
401 .offset = 0, 401 .offset = 0,
402 .v4l2_type = V4L2_CTRL_TYPE_INTEGER, 402 .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
@@ -406,7 +406,7 @@ static struct uvc_control_mapping uvc_ctrl_mappings[] = {
406 .id = V4L2_CID_GAMMA, 406 .id = V4L2_CID_GAMMA,
407 .name = "Gamma", 407 .name = "Gamma",
408 .entity = UVC_GUID_UVC_PROCESSING, 408 .entity = UVC_GUID_UVC_PROCESSING,
409 .selector = PU_GAMMA_CONTROL, 409 .selector = UVC_PU_GAMMA_CONTROL,
410 .size = 16, 410 .size = 16,
411 .offset = 0, 411 .offset = 0,
412 .v4l2_type = V4L2_CTRL_TYPE_INTEGER, 412 .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
@@ -416,7 +416,7 @@ static struct uvc_control_mapping uvc_ctrl_mappings[] = {
416 .id = V4L2_CID_BACKLIGHT_COMPENSATION, 416 .id = V4L2_CID_BACKLIGHT_COMPENSATION,
417 .name = "Backlight Compensation", 417 .name = "Backlight Compensation",
418 .entity = UVC_GUID_UVC_PROCESSING, 418 .entity = UVC_GUID_UVC_PROCESSING,
419 .selector = PU_BACKLIGHT_COMPENSATION_CONTROL, 419 .selector = UVC_PU_BACKLIGHT_COMPENSATION_CONTROL,
420 .size = 16, 420 .size = 16,
421 .offset = 0, 421 .offset = 0,
422 .v4l2_type = V4L2_CTRL_TYPE_INTEGER, 422 .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
@@ -426,7 +426,7 @@ static struct uvc_control_mapping uvc_ctrl_mappings[] = {
426 .id = V4L2_CID_GAIN, 426 .id = V4L2_CID_GAIN,
427 .name = "Gain", 427 .name = "Gain",
428 .entity = UVC_GUID_UVC_PROCESSING, 428 .entity = UVC_GUID_UVC_PROCESSING,
429 .selector = PU_GAIN_CONTROL, 429 .selector = UVC_PU_GAIN_CONTROL,
430 .size = 16, 430 .size = 16,
431 .offset = 0, 431 .offset = 0,
432 .v4l2_type = V4L2_CTRL_TYPE_INTEGER, 432 .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
@@ -436,7 +436,7 @@ static struct uvc_control_mapping uvc_ctrl_mappings[] = {
436 .id = V4L2_CID_POWER_LINE_FREQUENCY, 436 .id = V4L2_CID_POWER_LINE_FREQUENCY,
437 .name = "Power Line Frequency", 437 .name = "Power Line Frequency",
438 .entity = UVC_GUID_UVC_PROCESSING, 438 .entity = UVC_GUID_UVC_PROCESSING,
439 .selector = PU_POWER_LINE_FREQUENCY_CONTROL, 439 .selector = UVC_PU_POWER_LINE_FREQUENCY_CONTROL,
440 .size = 2, 440 .size = 2,
441 .offset = 0, 441 .offset = 0,
442 .v4l2_type = V4L2_CTRL_TYPE_MENU, 442 .v4l2_type = V4L2_CTRL_TYPE_MENU,
@@ -448,7 +448,7 @@ static struct uvc_control_mapping uvc_ctrl_mappings[] = {
448 .id = V4L2_CID_HUE_AUTO, 448 .id = V4L2_CID_HUE_AUTO,
449 .name = "Hue, Auto", 449 .name = "Hue, Auto",
450 .entity = UVC_GUID_UVC_PROCESSING, 450 .entity = UVC_GUID_UVC_PROCESSING,
451 .selector = PU_HUE_AUTO_CONTROL, 451 .selector = UVC_PU_HUE_AUTO_CONTROL,
452 .size = 1, 452 .size = 1,
453 .offset = 0, 453 .offset = 0,
454 .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN, 454 .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN,
@@ -458,7 +458,7 @@ static struct uvc_control_mapping uvc_ctrl_mappings[] = {
458 .id = V4L2_CID_EXPOSURE_AUTO, 458 .id = V4L2_CID_EXPOSURE_AUTO,
459 .name = "Exposure, Auto", 459 .name = "Exposure, Auto",
460 .entity = UVC_GUID_UVC_CAMERA, 460 .entity = UVC_GUID_UVC_CAMERA,
461 .selector = CT_AE_MODE_CONTROL, 461 .selector = UVC_CT_AE_MODE_CONTROL,
462 .size = 4, 462 .size = 4,
463 .offset = 0, 463 .offset = 0,
464 .v4l2_type = V4L2_CTRL_TYPE_MENU, 464 .v4l2_type = V4L2_CTRL_TYPE_MENU,
@@ -470,7 +470,7 @@ static struct uvc_control_mapping uvc_ctrl_mappings[] = {
470 .id = V4L2_CID_EXPOSURE_AUTO_PRIORITY, 470 .id = V4L2_CID_EXPOSURE_AUTO_PRIORITY,
471 .name = "Exposure, Auto Priority", 471 .name = "Exposure, Auto Priority",
472 .entity = UVC_GUID_UVC_CAMERA, 472 .entity = UVC_GUID_UVC_CAMERA,
473 .selector = CT_AE_PRIORITY_CONTROL, 473 .selector = UVC_CT_AE_PRIORITY_CONTROL,
474 .size = 1, 474 .size = 1,
475 .offset = 0, 475 .offset = 0,
476 .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN, 476 .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN,
@@ -480,7 +480,7 @@ static struct uvc_control_mapping uvc_ctrl_mappings[] = {
480 .id = V4L2_CID_EXPOSURE_ABSOLUTE, 480 .id = V4L2_CID_EXPOSURE_ABSOLUTE,
481 .name = "Exposure (Absolute)", 481 .name = "Exposure (Absolute)",
482 .entity = UVC_GUID_UVC_CAMERA, 482 .entity = UVC_GUID_UVC_CAMERA,
483 .selector = CT_EXPOSURE_TIME_ABSOLUTE_CONTROL, 483 .selector = UVC_CT_EXPOSURE_TIME_ABSOLUTE_CONTROL,
484 .size = 32, 484 .size = 32,
485 .offset = 0, 485 .offset = 0,
486 .v4l2_type = V4L2_CTRL_TYPE_INTEGER, 486 .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
@@ -490,7 +490,7 @@ static struct uvc_control_mapping uvc_ctrl_mappings[] = {
490 .id = V4L2_CID_AUTO_WHITE_BALANCE, 490 .id = V4L2_CID_AUTO_WHITE_BALANCE,
491 .name = "White Balance Temperature, Auto", 491 .name = "White Balance Temperature, Auto",
492 .entity = UVC_GUID_UVC_PROCESSING, 492 .entity = UVC_GUID_UVC_PROCESSING,
493 .selector = PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL, 493 .selector = UVC_PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL,
494 .size = 1, 494 .size = 1,
495 .offset = 0, 495 .offset = 0,
496 .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN, 496 .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN,
@@ -500,7 +500,7 @@ static struct uvc_control_mapping uvc_ctrl_mappings[] = {
500 .id = V4L2_CID_WHITE_BALANCE_TEMPERATURE, 500 .id = V4L2_CID_WHITE_BALANCE_TEMPERATURE,
501 .name = "White Balance Temperature", 501 .name = "White Balance Temperature",
502 .entity = UVC_GUID_UVC_PROCESSING, 502 .entity = UVC_GUID_UVC_PROCESSING,
503 .selector = PU_WHITE_BALANCE_TEMPERATURE_CONTROL, 503 .selector = UVC_PU_WHITE_BALANCE_TEMPERATURE_CONTROL,
504 .size = 16, 504 .size = 16,
505 .offset = 0, 505 .offset = 0,
506 .v4l2_type = V4L2_CTRL_TYPE_INTEGER, 506 .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
@@ -510,7 +510,7 @@ static struct uvc_control_mapping uvc_ctrl_mappings[] = {
510 .id = V4L2_CID_AUTO_WHITE_BALANCE, 510 .id = V4L2_CID_AUTO_WHITE_BALANCE,
511 .name = "White Balance Component, Auto", 511 .name = "White Balance Component, Auto",
512 .entity = UVC_GUID_UVC_PROCESSING, 512 .entity = UVC_GUID_UVC_PROCESSING,
513 .selector = PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL, 513 .selector = UVC_PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL,
514 .size = 1, 514 .size = 1,
515 .offset = 0, 515 .offset = 0,
516 .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN, 516 .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN,
@@ -520,7 +520,7 @@ static struct uvc_control_mapping uvc_ctrl_mappings[] = {
520 .id = V4L2_CID_BLUE_BALANCE, 520 .id = V4L2_CID_BLUE_BALANCE,
521 .name = "White Balance Blue Component", 521 .name = "White Balance Blue Component",
522 .entity = UVC_GUID_UVC_PROCESSING, 522 .entity = UVC_GUID_UVC_PROCESSING,
523 .selector = PU_WHITE_BALANCE_COMPONENT_CONTROL, 523 .selector = UVC_PU_WHITE_BALANCE_COMPONENT_CONTROL,
524 .size = 16, 524 .size = 16,
525 .offset = 0, 525 .offset = 0,
526 .v4l2_type = V4L2_CTRL_TYPE_INTEGER, 526 .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
@@ -530,7 +530,7 @@ static struct uvc_control_mapping uvc_ctrl_mappings[] = {
530 .id = V4L2_CID_RED_BALANCE, 530 .id = V4L2_CID_RED_BALANCE,
531 .name = "White Balance Red Component", 531 .name = "White Balance Red Component",
532 .entity = UVC_GUID_UVC_PROCESSING, 532 .entity = UVC_GUID_UVC_PROCESSING,
533 .selector = PU_WHITE_BALANCE_COMPONENT_CONTROL, 533 .selector = UVC_PU_WHITE_BALANCE_COMPONENT_CONTROL,
534 .size = 16, 534 .size = 16,
535 .offset = 16, 535 .offset = 16,
536 .v4l2_type = V4L2_CTRL_TYPE_INTEGER, 536 .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
@@ -540,7 +540,7 @@ static struct uvc_control_mapping uvc_ctrl_mappings[] = {
540 .id = V4L2_CID_FOCUS_ABSOLUTE, 540 .id = V4L2_CID_FOCUS_ABSOLUTE,
541 .name = "Focus (absolute)", 541 .name = "Focus (absolute)",
542 .entity = UVC_GUID_UVC_CAMERA, 542 .entity = UVC_GUID_UVC_CAMERA,
543 .selector = CT_FOCUS_ABSOLUTE_CONTROL, 543 .selector = UVC_CT_FOCUS_ABSOLUTE_CONTROL,
544 .size = 16, 544 .size = 16,
545 .offset = 0, 545 .offset = 0,
546 .v4l2_type = V4L2_CTRL_TYPE_INTEGER, 546 .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
@@ -550,7 +550,7 @@ static struct uvc_control_mapping uvc_ctrl_mappings[] = {
550 .id = V4L2_CID_FOCUS_AUTO, 550 .id = V4L2_CID_FOCUS_AUTO,
551 .name = "Focus, Auto", 551 .name = "Focus, Auto",
552 .entity = UVC_GUID_UVC_CAMERA, 552 .entity = UVC_GUID_UVC_CAMERA,
553 .selector = CT_FOCUS_AUTO_CONTROL, 553 .selector = UVC_CT_FOCUS_AUTO_CONTROL,
554 .size = 1, 554 .size = 1,
555 .offset = 0, 555 .offset = 0,
556 .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN, 556 .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN,
@@ -560,7 +560,7 @@ static struct uvc_control_mapping uvc_ctrl_mappings[] = {
560 .id = V4L2_CID_ZOOM_ABSOLUTE, 560 .id = V4L2_CID_ZOOM_ABSOLUTE,
561 .name = "Zoom, Absolute", 561 .name = "Zoom, Absolute",
562 .entity = UVC_GUID_UVC_CAMERA, 562 .entity = UVC_GUID_UVC_CAMERA,
563 .selector = CT_ZOOM_ABSOLUTE_CONTROL, 563 .selector = UVC_CT_ZOOM_ABSOLUTE_CONTROL,
564 .size = 16, 564 .size = 16,
565 .offset = 0, 565 .offset = 0,
566 .v4l2_type = V4L2_CTRL_TYPE_INTEGER, 566 .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
@@ -570,7 +570,7 @@ static struct uvc_control_mapping uvc_ctrl_mappings[] = {
570 .id = V4L2_CID_ZOOM_CONTINUOUS, 570 .id = V4L2_CID_ZOOM_CONTINUOUS,
571 .name = "Zoom, Continuous", 571 .name = "Zoom, Continuous",
572 .entity = UVC_GUID_UVC_CAMERA, 572 .entity = UVC_GUID_UVC_CAMERA,
573 .selector = CT_ZOOM_RELATIVE_CONTROL, 573 .selector = UVC_CT_ZOOM_RELATIVE_CONTROL,
574 .size = 0, 574 .size = 0,
575 .offset = 0, 575 .offset = 0,
576 .v4l2_type = V4L2_CTRL_TYPE_INTEGER, 576 .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
@@ -582,7 +582,7 @@ static struct uvc_control_mapping uvc_ctrl_mappings[] = {
582 .id = V4L2_CID_PRIVACY, 582 .id = V4L2_CID_PRIVACY,
583 .name = "Privacy", 583 .name = "Privacy",
584 .entity = UVC_GUID_UVC_CAMERA, 584 .entity = UVC_GUID_UVC_CAMERA,
585 .selector = CT_PRIVACY_CONTROL, 585 .selector = UVC_CT_PRIVACY_CONTROL,
586 .size = 1, 586 .size = 1,
587 .offset = 0, 587 .offset = 0,
588 .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN, 588 .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN,
@@ -675,16 +675,16 @@ static const __u8 uvc_media_transport_input_guid[16] =
675static int uvc_entity_match_guid(struct uvc_entity *entity, __u8 guid[16]) 675static int uvc_entity_match_guid(struct uvc_entity *entity, __u8 guid[16])
676{ 676{
677 switch (UVC_ENTITY_TYPE(entity)) { 677 switch (UVC_ENTITY_TYPE(entity)) {
678 case ITT_CAMERA: 678 case UVC_ITT_CAMERA:
679 return memcmp(uvc_camera_guid, guid, 16) == 0; 679 return memcmp(uvc_camera_guid, guid, 16) == 0;
680 680
681 case ITT_MEDIA_TRANSPORT_INPUT: 681 case UVC_ITT_MEDIA_TRANSPORT_INPUT:
682 return memcmp(uvc_media_transport_input_guid, guid, 16) == 0; 682 return memcmp(uvc_media_transport_input_guid, guid, 16) == 0;
683 683
684 case VC_PROCESSING_UNIT: 684 case UVC_VC_PROCESSING_UNIT:
685 return memcmp(uvc_processing_guid, guid, 16) == 0; 685 return memcmp(uvc_processing_guid, guid, 16) == 0;
686 686
687 case VC_EXTENSION_UNIT: 687 case UVC_VC_EXTENSION_UNIT:
688 return memcmp(entity->extension.guidExtensionCode, 688 return memcmp(entity->extension.guidExtensionCode,
689 guid, 16) == 0; 689 guid, 16) == 0;
690 690
@@ -729,7 +729,7 @@ static void __uvc_find_control(struct uvc_entity *entity, __u32 v4l2_id,
729 } 729 }
730} 730}
731 731
732struct uvc_control *uvc_find_control(struct uvc_video_device *video, 732struct uvc_control *uvc_find_control(struct uvc_video_chain *chain,
733 __u32 v4l2_id, struct uvc_control_mapping **mapping) 733 __u32 v4l2_id, struct uvc_control_mapping **mapping)
734{ 734{
735 struct uvc_control *ctrl = NULL; 735 struct uvc_control *ctrl = NULL;
@@ -742,17 +742,17 @@ struct uvc_control *uvc_find_control(struct uvc_video_device *video,
742 v4l2_id &= V4L2_CTRL_ID_MASK; 742 v4l2_id &= V4L2_CTRL_ID_MASK;
743 743
744 /* Find the control. */ 744 /* Find the control. */
745 __uvc_find_control(video->processing, v4l2_id, mapping, &ctrl, next); 745 __uvc_find_control(chain->processing, v4l2_id, mapping, &ctrl, next);
746 if (ctrl && !next) 746 if (ctrl && !next)
747 return ctrl; 747 return ctrl;
748 748
749 list_for_each_entry(entity, &video->iterms, chain) { 749 list_for_each_entry(entity, &chain->iterms, chain) {
750 __uvc_find_control(entity, v4l2_id, mapping, &ctrl, next); 750 __uvc_find_control(entity, v4l2_id, mapping, &ctrl, next);
751 if (ctrl && !next) 751 if (ctrl && !next)
752 return ctrl; 752 return ctrl;
753 } 753 }
754 754
755 list_for_each_entry(entity, &video->extensions, chain) { 755 list_for_each_entry(entity, &chain->extensions, chain) {
756 __uvc_find_control(entity, v4l2_id, mapping, &ctrl, next); 756 __uvc_find_control(entity, v4l2_id, mapping, &ctrl, next);
757 if (ctrl && !next) 757 if (ctrl && !next)
758 return ctrl; 758 return ctrl;
@@ -765,7 +765,7 @@ struct uvc_control *uvc_find_control(struct uvc_video_device *video,
765 return ctrl; 765 return ctrl;
766} 766}
767 767
768int uvc_query_v4l2_ctrl(struct uvc_video_device *video, 768int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
769 struct v4l2_queryctrl *v4l2_ctrl) 769 struct v4l2_queryctrl *v4l2_ctrl)
770{ 770{
771 struct uvc_control *ctrl; 771 struct uvc_control *ctrl;
@@ -775,7 +775,7 @@ int uvc_query_v4l2_ctrl(struct uvc_video_device *video,
775 __u8 *data; 775 __u8 *data;
776 int ret; 776 int ret;
777 777
778 ctrl = uvc_find_control(video, v4l2_ctrl->id, &mapping); 778 ctrl = uvc_find_control(chain, v4l2_ctrl->id, &mapping);
779 if (ctrl == NULL) 779 if (ctrl == NULL)
780 return -EINVAL; 780 return -EINVAL;
781 781
@@ -793,11 +793,13 @@ int uvc_query_v4l2_ctrl(struct uvc_video_device *video,
793 v4l2_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; 793 v4l2_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
794 794
795 if (ctrl->info->flags & UVC_CONTROL_GET_DEF) { 795 if (ctrl->info->flags & UVC_CONTROL_GET_DEF) {
796 if ((ret = uvc_query_ctrl(video->dev, GET_DEF, ctrl->entity->id, 796 ret = uvc_query_ctrl(chain->dev, UVC_GET_DEF, ctrl->entity->id,
797 video->dev->intfnum, ctrl->info->selector, 797 chain->dev->intfnum, ctrl->info->selector,
798 data, ctrl->info->size)) < 0) 798 data, ctrl->info->size);
799 if (ret < 0)
799 goto out; 800 goto out;
800 v4l2_ctrl->default_value = mapping->get(mapping, GET_DEF, data); 801 v4l2_ctrl->default_value =
802 mapping->get(mapping, UVC_GET_DEF, data);
801 } 803 }
802 804
803 switch (mapping->v4l2_type) { 805 switch (mapping->v4l2_type) {
@@ -829,25 +831,28 @@ int uvc_query_v4l2_ctrl(struct uvc_video_device *video,
829 } 831 }
830 832
831 if (ctrl->info->flags & UVC_CONTROL_GET_MIN) { 833 if (ctrl->info->flags & UVC_CONTROL_GET_MIN) {
832 if ((ret = uvc_query_ctrl(video->dev, GET_MIN, ctrl->entity->id, 834 ret = uvc_query_ctrl(chain->dev, UVC_GET_MIN, ctrl->entity->id,
833 video->dev->intfnum, ctrl->info->selector, 835 chain->dev->intfnum, ctrl->info->selector,
834 data, ctrl->info->size)) < 0) 836 data, ctrl->info->size);
837 if (ret < 0)
835 goto out; 838 goto out;
836 v4l2_ctrl->minimum = mapping->get(mapping, GET_MIN, data); 839 v4l2_ctrl->minimum = mapping->get(mapping, UVC_GET_MIN, data);
837 } 840 }
838 if (ctrl->info->flags & UVC_CONTROL_GET_MAX) { 841 if (ctrl->info->flags & UVC_CONTROL_GET_MAX) {
839 if ((ret = uvc_query_ctrl(video->dev, GET_MAX, ctrl->entity->id, 842 ret = uvc_query_ctrl(chain->dev, UVC_GET_MAX, ctrl->entity->id,
840 video->dev->intfnum, ctrl->info->selector, 843 chain->dev->intfnum, ctrl->info->selector,
841 data, ctrl->info->size)) < 0) 844 data, ctrl->info->size);
845 if (ret < 0)
842 goto out; 846 goto out;
843 v4l2_ctrl->maximum = mapping->get(mapping, GET_MAX, data); 847 v4l2_ctrl->maximum = mapping->get(mapping, UVC_GET_MAX, data);
844 } 848 }
845 if (ctrl->info->flags & UVC_CONTROL_GET_RES) { 849 if (ctrl->info->flags & UVC_CONTROL_GET_RES) {
846 if ((ret = uvc_query_ctrl(video->dev, GET_RES, ctrl->entity->id, 850 ret = uvc_query_ctrl(chain->dev, UVC_GET_RES, ctrl->entity->id,
847 video->dev->intfnum, ctrl->info->selector, 851 chain->dev->intfnum, ctrl->info->selector,
848 data, ctrl->info->size)) < 0) 852 data, ctrl->info->size);
853 if (ret < 0)
849 goto out; 854 goto out;
850 v4l2_ctrl->step = mapping->get(mapping, GET_RES, data); 855 v4l2_ctrl->step = mapping->get(mapping, UVC_GET_RES, data);
851 } 856 }
852 857
853 ret = 0; 858 ret = 0;
@@ -881,9 +886,9 @@ out:
881 * (UVC_CTRL_DATA_BACKUP) for all dirty controls. Both functions release the 886 * (UVC_CTRL_DATA_BACKUP) for all dirty controls. Both functions release the
882 * control lock. 887 * control lock.
883 */ 888 */
884int uvc_ctrl_begin(struct uvc_video_device *video) 889int uvc_ctrl_begin(struct uvc_video_chain *chain)
885{ 890{
886 return mutex_lock_interruptible(&video->ctrl_mutex) ? -ERESTARTSYS : 0; 891 return mutex_lock_interruptible(&chain->ctrl_mutex) ? -ERESTARTSYS : 0;
887} 892}
888 893
889static int uvc_ctrl_commit_entity(struct uvc_device *dev, 894static int uvc_ctrl_commit_entity(struct uvc_device *dev,
@@ -912,7 +917,7 @@ static int uvc_ctrl_commit_entity(struct uvc_device *dev,
912 continue; 917 continue;
913 918
914 if (!rollback) 919 if (!rollback)
915 ret = uvc_query_ctrl(dev, SET_CUR, ctrl->entity->id, 920 ret = uvc_query_ctrl(dev, UVC_SET_CUR, ctrl->entity->id,
916 dev->intfnum, ctrl->info->selector, 921 dev->intfnum, ctrl->info->selector,
917 uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), 922 uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
918 ctrl->info->size); 923 ctrl->info->size);
@@ -933,34 +938,34 @@ static int uvc_ctrl_commit_entity(struct uvc_device *dev,
933 return 0; 938 return 0;
934} 939}
935 940
936int __uvc_ctrl_commit(struct uvc_video_device *video, int rollback) 941int __uvc_ctrl_commit(struct uvc_video_chain *chain, int rollback)
937{ 942{
938 struct uvc_entity *entity; 943 struct uvc_entity *entity;
939 int ret = 0; 944 int ret = 0;
940 945
941 /* Find the control. */ 946 /* Find the control. */
942 ret = uvc_ctrl_commit_entity(video->dev, video->processing, rollback); 947 ret = uvc_ctrl_commit_entity(chain->dev, chain->processing, rollback);
943 if (ret < 0) 948 if (ret < 0)
944 goto done; 949 goto done;
945 950
946 list_for_each_entry(entity, &video->iterms, chain) { 951 list_for_each_entry(entity, &chain->iterms, chain) {
947 ret = uvc_ctrl_commit_entity(video->dev, entity, rollback); 952 ret = uvc_ctrl_commit_entity(chain->dev, entity, rollback);
948 if (ret < 0) 953 if (ret < 0)
949 goto done; 954 goto done;
950 } 955 }
951 956
952 list_for_each_entry(entity, &video->extensions, chain) { 957 list_for_each_entry(entity, &chain->extensions, chain) {
953 ret = uvc_ctrl_commit_entity(video->dev, entity, rollback); 958 ret = uvc_ctrl_commit_entity(chain->dev, entity, rollback);
954 if (ret < 0) 959 if (ret < 0)
955 goto done; 960 goto done;
956 } 961 }
957 962
958done: 963done:
959 mutex_unlock(&video->ctrl_mutex); 964 mutex_unlock(&chain->ctrl_mutex);
960 return ret; 965 return ret;
961} 966}
962 967
963int uvc_ctrl_get(struct uvc_video_device *video, 968int uvc_ctrl_get(struct uvc_video_chain *chain,
964 struct v4l2_ext_control *xctrl) 969 struct v4l2_ext_control *xctrl)
965{ 970{
966 struct uvc_control *ctrl; 971 struct uvc_control *ctrl;
@@ -969,13 +974,13 @@ int uvc_ctrl_get(struct uvc_video_device *video,
969 unsigned int i; 974 unsigned int i;
970 int ret; 975 int ret;
971 976
972 ctrl = uvc_find_control(video, xctrl->id, &mapping); 977 ctrl = uvc_find_control(chain, xctrl->id, &mapping);
973 if (ctrl == NULL || (ctrl->info->flags & UVC_CONTROL_GET_CUR) == 0) 978 if (ctrl == NULL || (ctrl->info->flags & UVC_CONTROL_GET_CUR) == 0)
974 return -EINVAL; 979 return -EINVAL;
975 980
976 if (!ctrl->loaded) { 981 if (!ctrl->loaded) {
977 ret = uvc_query_ctrl(video->dev, GET_CUR, ctrl->entity->id, 982 ret = uvc_query_ctrl(chain->dev, UVC_GET_CUR, ctrl->entity->id,
978 video->dev->intfnum, ctrl->info->selector, 983 chain->dev->intfnum, ctrl->info->selector,
979 uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), 984 uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
980 ctrl->info->size); 985 ctrl->info->size);
981 if (ret < 0) 986 if (ret < 0)
@@ -984,7 +989,7 @@ int uvc_ctrl_get(struct uvc_video_device *video,
984 ctrl->loaded = 1; 989 ctrl->loaded = 1;
985 } 990 }
986 991
987 xctrl->value = mapping->get(mapping, GET_CUR, 992 xctrl->value = mapping->get(mapping, UVC_GET_CUR,
988 uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT)); 993 uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT));
989 994
990 if (mapping->v4l2_type == V4L2_CTRL_TYPE_MENU) { 995 if (mapping->v4l2_type == V4L2_CTRL_TYPE_MENU) {
@@ -1000,7 +1005,7 @@ int uvc_ctrl_get(struct uvc_video_device *video,
1000 return 0; 1005 return 0;
1001} 1006}
1002 1007
1003int uvc_ctrl_set(struct uvc_video_device *video, 1008int uvc_ctrl_set(struct uvc_video_chain *chain,
1004 struct v4l2_ext_control *xctrl) 1009 struct v4l2_ext_control *xctrl)
1005{ 1010{
1006 struct uvc_control *ctrl; 1011 struct uvc_control *ctrl;
@@ -1008,7 +1013,7 @@ int uvc_ctrl_set(struct uvc_video_device *video,
1008 s32 value = xctrl->value; 1013 s32 value = xctrl->value;
1009 int ret; 1014 int ret;
1010 1015
1011 ctrl = uvc_find_control(video, xctrl->id, &mapping); 1016 ctrl = uvc_find_control(chain, xctrl->id, &mapping);
1012 if (ctrl == NULL || (ctrl->info->flags & UVC_CONTROL_SET_CUR) == 0) 1017 if (ctrl == NULL || (ctrl->info->flags & UVC_CONTROL_SET_CUR) == 0)
1013 return -EINVAL; 1018 return -EINVAL;
1014 1019
@@ -1023,8 +1028,8 @@ int uvc_ctrl_set(struct uvc_video_device *video,
1023 memset(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), 1028 memset(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
1024 0, ctrl->info->size); 1029 0, ctrl->info->size);
1025 } else { 1030 } else {
1026 ret = uvc_query_ctrl(video->dev, GET_CUR, 1031 ret = uvc_query_ctrl(chain->dev, UVC_GET_CUR,
1027 ctrl->entity->id, video->dev->intfnum, 1032 ctrl->entity->id, chain->dev->intfnum,
1028 ctrl->info->selector, 1033 ctrl->info->selector,
1029 uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), 1034 uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
1030 ctrl->info->size); 1035 ctrl->info->size);
@@ -1053,7 +1058,7 @@ int uvc_ctrl_set(struct uvc_video_device *video,
1053 * Dynamic controls 1058 * Dynamic controls
1054 */ 1059 */
1055 1060
1056int uvc_xu_ctrl_query(struct uvc_video_device *video, 1061int uvc_xu_ctrl_query(struct uvc_video_chain *chain,
1057 struct uvc_xu_control *xctrl, int set) 1062 struct uvc_xu_control *xctrl, int set)
1058{ 1063{
1059 struct uvc_entity *entity; 1064 struct uvc_entity *entity;
@@ -1063,7 +1068,7 @@ int uvc_xu_ctrl_query(struct uvc_video_device *video,
1063 int ret; 1068 int ret;
1064 1069
1065 /* Find the extension unit. */ 1070 /* Find the extension unit. */
1066 list_for_each_entry(entity, &video->extensions, chain) { 1071 list_for_each_entry(entity, &chain->extensions, chain) {
1067 if (entity->id == xctrl->unit) 1072 if (entity->id == xctrl->unit)
1068 break; 1073 break;
1069 } 1074 }
@@ -1102,7 +1107,7 @@ int uvc_xu_ctrl_query(struct uvc_video_device *video,
1102 (!set && !(ctrl->info->flags & UVC_CONTROL_GET_CUR))) 1107 (!set && !(ctrl->info->flags & UVC_CONTROL_GET_CUR)))
1103 return -EINVAL; 1108 return -EINVAL;
1104 1109
1105 if (mutex_lock_interruptible(&video->ctrl_mutex)) 1110 if (mutex_lock_interruptible(&chain->ctrl_mutex))
1106 return -ERESTARTSYS; 1111 return -ERESTARTSYS;
1107 1112
1108 memcpy(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_BACKUP), 1113 memcpy(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_BACKUP),
@@ -1115,9 +1120,9 @@ int uvc_xu_ctrl_query(struct uvc_video_device *video,
1115 goto out; 1120 goto out;
1116 } 1121 }
1117 1122
1118 ret = uvc_query_ctrl(video->dev, set ? SET_CUR : GET_CUR, xctrl->unit, 1123 ret = uvc_query_ctrl(chain->dev, set ? UVC_SET_CUR : UVC_GET_CUR,
1119 video->dev->intfnum, xctrl->selector, data, 1124 xctrl->unit, chain->dev->intfnum, xctrl->selector,
1120 xctrl->size); 1125 data, xctrl->size);
1121 if (ret < 0) 1126 if (ret < 0)
1122 goto out; 1127 goto out;
1123 1128
@@ -1132,7 +1137,7 @@ out:
1132 uvc_ctrl_data(ctrl, UVC_CTRL_DATA_BACKUP), 1137 uvc_ctrl_data(ctrl, UVC_CTRL_DATA_BACKUP),
1133 xctrl->size); 1138 xctrl->size);
1134 1139
1135 mutex_unlock(&video->ctrl_mutex); 1140 mutex_unlock(&chain->ctrl_mutex);
1136 return ret; 1141 return ret;
1137} 1142}
1138 1143
@@ -1211,7 +1216,7 @@ static void uvc_ctrl_add_ctrl(struct uvc_device *dev,
1211 if (!found) 1216 if (!found)
1212 return; 1217 return;
1213 1218
1214 if (UVC_ENTITY_TYPE(entity) == VC_EXTENSION_UNIT) { 1219 if (UVC_ENTITY_TYPE(entity) == UVC_VC_EXTENSION_UNIT) {
1215 /* Check if the device control information and length match 1220 /* Check if the device control information and length match
1216 * the user supplied information. 1221 * the user supplied information.
1217 */ 1222 */
@@ -1219,8 +1224,9 @@ static void uvc_ctrl_add_ctrl(struct uvc_device *dev,
1219 __le16 size; 1224 __le16 size;
1220 __u8 inf; 1225 __u8 inf;
1221 1226
1222 if ((ret = uvc_query_ctrl(dev, GET_LEN, ctrl->entity->id, 1227 ret = uvc_query_ctrl(dev, UVC_GET_LEN, ctrl->entity->id,
1223 dev->intfnum, info->selector, (__u8 *)&size, 2)) < 0) { 1228 dev->intfnum, info->selector, (__u8 *)&size, 2);
1229 if (ret < 0) {
1224 uvc_trace(UVC_TRACE_CONTROL, "GET_LEN failed on " 1230 uvc_trace(UVC_TRACE_CONTROL, "GET_LEN failed on "
1225 "control " UVC_GUID_FORMAT "/%u (%d).\n", 1231 "control " UVC_GUID_FORMAT "/%u (%d).\n",
1226 UVC_GUID_ARGS(info->entity), info->selector, 1232 UVC_GUID_ARGS(info->entity), info->selector,
@@ -1236,8 +1242,9 @@ static void uvc_ctrl_add_ctrl(struct uvc_device *dev,
1236 return; 1242 return;
1237 } 1243 }
1238 1244
1239 if ((ret = uvc_query_ctrl(dev, GET_INFO, ctrl->entity->id, 1245 ret = uvc_query_ctrl(dev, UVC_GET_INFO, ctrl->entity->id,
1240 dev->intfnum, info->selector, &inf, 1)) < 0) { 1246 dev->intfnum, info->selector, &inf, 1);
1247 if (ret < 0) {
1241 uvc_trace(UVC_TRACE_CONTROL, "GET_INFO failed on " 1248 uvc_trace(UVC_TRACE_CONTROL, "GET_INFO failed on "
1242 "control " UVC_GUID_FORMAT "/%u (%d).\n", 1249 "control " UVC_GUID_FORMAT "/%u (%d).\n",
1243 UVC_GUID_ARGS(info->entity), info->selector, 1250 UVC_GUID_ARGS(info->entity), info->selector,
@@ -1391,7 +1398,7 @@ uvc_ctrl_prune_entity(struct uvc_device *dev, struct uvc_entity *entity)
1391 unsigned int size; 1398 unsigned int size;
1392 unsigned int i; 1399 unsigned int i;
1393 1400
1394 if (UVC_ENTITY_TYPE(entity) != VC_PROCESSING_UNIT) 1401 if (UVC_ENTITY_TYPE(entity) != UVC_VC_PROCESSING_UNIT)
1395 return; 1402 return;
1396 1403
1397 controls = entity->processing.bmControls; 1404 controls = entity->processing.bmControls;
@@ -1427,13 +1434,13 @@ int uvc_ctrl_init_device(struct uvc_device *dev)
1427 unsigned int bControlSize = 0, ncontrols = 0; 1434 unsigned int bControlSize = 0, ncontrols = 0;
1428 __u8 *bmControls = NULL; 1435 __u8 *bmControls = NULL;
1429 1436
1430 if (UVC_ENTITY_TYPE(entity) == VC_EXTENSION_UNIT) { 1437 if (UVC_ENTITY_TYPE(entity) == UVC_VC_EXTENSION_UNIT) {
1431 bmControls = entity->extension.bmControls; 1438 bmControls = entity->extension.bmControls;
1432 bControlSize = entity->extension.bControlSize; 1439 bControlSize = entity->extension.bControlSize;
1433 } else if (UVC_ENTITY_TYPE(entity) == VC_PROCESSING_UNIT) { 1440 } else if (UVC_ENTITY_TYPE(entity) == UVC_VC_PROCESSING_UNIT) {
1434 bmControls = entity->processing.bmControls; 1441 bmControls = entity->processing.bmControls;
1435 bControlSize = entity->processing.bControlSize; 1442 bControlSize = entity->processing.bControlSize;
1436 } else if (UVC_ENTITY_TYPE(entity) == ITT_CAMERA) { 1443 } else if (UVC_ENTITY_TYPE(entity) == UVC_ITT_CAMERA) {
1437 bmControls = entity->camera.bmControls; 1444 bmControls = entity->camera.bmControls;
1438 bControlSize = entity->camera.bControlSize; 1445 bControlSize = entity->camera.bControlSize;
1439 } 1446 }
diff --git a/drivers/media/video/uvc/uvc_driver.c b/drivers/media/video/uvc/uvc_driver.c
index 04b47832fa0a..8756be569154 100644
--- a/drivers/media/video/uvc/uvc_driver.c
+++ b/drivers/media/video/uvc/uvc_driver.c
@@ -249,23 +249,23 @@ static struct uvc_entity *uvc_entity_by_reference(struct uvc_device *dev,
249 249
250 list_for_each_entry_continue(entity, &dev->entities, list) { 250 list_for_each_entry_continue(entity, &dev->entities, list) {
251 switch (UVC_ENTITY_TYPE(entity)) { 251 switch (UVC_ENTITY_TYPE(entity)) {
252 case TT_STREAMING: 252 case UVC_TT_STREAMING:
253 if (entity->output.bSourceID == id) 253 if (entity->output.bSourceID == id)
254 return entity; 254 return entity;
255 break; 255 break;
256 256
257 case VC_PROCESSING_UNIT: 257 case UVC_VC_PROCESSING_UNIT:
258 if (entity->processing.bSourceID == id) 258 if (entity->processing.bSourceID == id)
259 return entity; 259 return entity;
260 break; 260 break;
261 261
262 case VC_SELECTOR_UNIT: 262 case UVC_VC_SELECTOR_UNIT:
263 for (i = 0; i < entity->selector.bNrInPins; ++i) 263 for (i = 0; i < entity->selector.bNrInPins; ++i)
264 if (entity->selector.baSourceID[i] == id) 264 if (entity->selector.baSourceID[i] == id)
265 return entity; 265 return entity;
266 break; 266 break;
267 267
268 case VC_EXTENSION_UNIT: 268 case UVC_VC_EXTENSION_UNIT:
269 for (i = 0; i < entity->extension.bNrInPins; ++i) 269 for (i = 0; i < entity->extension.bNrInPins; ++i)
270 if (entity->extension.baSourceID[i] == id) 270 if (entity->extension.baSourceID[i] == id)
271 return entity; 271 return entity;
@@ -276,8 +276,20 @@ static struct uvc_entity *uvc_entity_by_reference(struct uvc_device *dev,
276 return NULL; 276 return NULL;
277} 277}
278 278
279static struct uvc_streaming *uvc_stream_by_id(struct uvc_device *dev, int id)
280{
281 struct uvc_streaming *stream;
282
283 list_for_each_entry(stream, &dev->streams, list) {
284 if (stream->header.bTerminalLink == id)
285 return stream;
286 }
287
288 return NULL;
289}
290
279/* ------------------------------------------------------------------------ 291/* ------------------------------------------------------------------------
280 * Descriptors handling 292 * Descriptors parsing
281 */ 293 */
282 294
283static int uvc_parse_format(struct uvc_device *dev, 295static int uvc_parse_format(struct uvc_device *dev,
@@ -297,9 +309,9 @@ static int uvc_parse_format(struct uvc_device *dev,
297 format->index = buffer[3]; 309 format->index = buffer[3];
298 310
299 switch (buffer[2]) { 311 switch (buffer[2]) {
300 case VS_FORMAT_UNCOMPRESSED: 312 case UVC_VS_FORMAT_UNCOMPRESSED:
301 case VS_FORMAT_FRAME_BASED: 313 case UVC_VS_FORMAT_FRAME_BASED:
302 n = buffer[2] == VS_FORMAT_UNCOMPRESSED ? 27 : 28; 314 n = buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED ? 27 : 28;
303 if (buflen < n) { 315 if (buflen < n) {
304 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming " 316 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
305 "interface %d FORMAT error\n", 317 "interface %d FORMAT error\n",
@@ -325,16 +337,16 @@ static int uvc_parse_format(struct uvc_device *dev,
325 } 337 }
326 338
327 format->bpp = buffer[21]; 339 format->bpp = buffer[21];
328 if (buffer[2] == VS_FORMAT_UNCOMPRESSED) { 340 if (buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED) {
329 ftype = VS_FRAME_UNCOMPRESSED; 341 ftype = UVC_VS_FRAME_UNCOMPRESSED;
330 } else { 342 } else {
331 ftype = VS_FRAME_FRAME_BASED; 343 ftype = UVC_VS_FRAME_FRAME_BASED;
332 if (buffer[27]) 344 if (buffer[27])
333 format->flags = UVC_FMT_FLAG_COMPRESSED; 345 format->flags = UVC_FMT_FLAG_COMPRESSED;
334 } 346 }
335 break; 347 break;
336 348
337 case VS_FORMAT_MJPEG: 349 case UVC_VS_FORMAT_MJPEG:
338 if (buflen < 11) { 350 if (buflen < 11) {
339 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming " 351 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
340 "interface %d FORMAT error\n", 352 "interface %d FORMAT error\n",
@@ -347,10 +359,10 @@ static int uvc_parse_format(struct uvc_device *dev,
347 format->fcc = V4L2_PIX_FMT_MJPEG; 359 format->fcc = V4L2_PIX_FMT_MJPEG;
348 format->flags = UVC_FMT_FLAG_COMPRESSED; 360 format->flags = UVC_FMT_FLAG_COMPRESSED;
349 format->bpp = 0; 361 format->bpp = 0;
350 ftype = VS_FRAME_MJPEG; 362 ftype = UVC_VS_FRAME_MJPEG;
351 break; 363 break;
352 364
353 case VS_FORMAT_DV: 365 case UVC_VS_FORMAT_DV:
354 if (buflen < 9) { 366 if (buflen < 9) {
355 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming " 367 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
356 "interface %d FORMAT error\n", 368 "interface %d FORMAT error\n",
@@ -395,8 +407,8 @@ static int uvc_parse_format(struct uvc_device *dev,
395 format->nframes = 1; 407 format->nframes = 1;
396 break; 408 break;
397 409
398 case VS_FORMAT_MPEG2TS: 410 case UVC_VS_FORMAT_MPEG2TS:
399 case VS_FORMAT_STREAM_BASED: 411 case UVC_VS_FORMAT_STREAM_BASED:
400 /* Not supported yet. */ 412 /* Not supported yet. */
401 default: 413 default:
402 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming " 414 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
@@ -416,7 +428,7 @@ static int uvc_parse_format(struct uvc_device *dev,
416 */ 428 */
417 while (buflen > 2 && buffer[2] == ftype) { 429 while (buflen > 2 && buffer[2] == ftype) {
418 frame = &format->frame[format->nframes]; 430 frame = &format->frame[format->nframes];
419 if (ftype != VS_FRAME_FRAME_BASED) 431 if (ftype != UVC_VS_FRAME_FRAME_BASED)
420 n = buflen > 25 ? buffer[25] : 0; 432 n = buflen > 25 ? buffer[25] : 0;
421 else 433 else
422 n = buflen > 21 ? buffer[21] : 0; 434 n = buflen > 21 ? buffer[21] : 0;
@@ -436,7 +448,7 @@ static int uvc_parse_format(struct uvc_device *dev,
436 frame->wHeight = get_unaligned_le16(&buffer[7]); 448 frame->wHeight = get_unaligned_le16(&buffer[7]);
437 frame->dwMinBitRate = get_unaligned_le32(&buffer[9]); 449 frame->dwMinBitRate = get_unaligned_le32(&buffer[9]);
438 frame->dwMaxBitRate = get_unaligned_le32(&buffer[13]); 450 frame->dwMaxBitRate = get_unaligned_le32(&buffer[13]);
439 if (ftype != VS_FRAME_FRAME_BASED) { 451 if (ftype != UVC_VS_FRAME_FRAME_BASED) {
440 frame->dwMaxVideoFrameBufferSize = 452 frame->dwMaxVideoFrameBufferSize =
441 get_unaligned_le32(&buffer[17]); 453 get_unaligned_le32(&buffer[17]);
442 frame->dwDefaultFrameInterval = 454 frame->dwDefaultFrameInterval =
@@ -491,12 +503,12 @@ static int uvc_parse_format(struct uvc_device *dev,
491 buffer += buffer[0]; 503 buffer += buffer[0];
492 } 504 }
493 505
494 if (buflen > 2 && buffer[2] == VS_STILL_IMAGE_FRAME) { 506 if (buflen > 2 && buffer[2] == UVC_VS_STILL_IMAGE_FRAME) {
495 buflen -= buffer[0]; 507 buflen -= buffer[0];
496 buffer += buffer[0]; 508 buffer += buffer[0];
497 } 509 }
498 510
499 if (buflen > 2 && buffer[2] == VS_COLORFORMAT) { 511 if (buflen > 2 && buffer[2] == UVC_VS_COLORFORMAT) {
500 if (buflen < 6) { 512 if (buflen < 6) {
501 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming " 513 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
502 "interface %d COLORFORMAT error\n", 514 "interface %d COLORFORMAT error\n",
@@ -530,7 +542,7 @@ static int uvc_parse_streaming(struct uvc_device *dev,
530 int ret = -EINVAL; 542 int ret = -EINVAL;
531 543
532 if (intf->cur_altsetting->desc.bInterfaceSubClass 544 if (intf->cur_altsetting->desc.bInterfaceSubClass
533 != SC_VIDEOSTREAMING) { 545 != UVC_SC_VIDEOSTREAMING) {
534 uvc_trace(UVC_TRACE_DESCR, "device %d interface %d isn't a " 546 uvc_trace(UVC_TRACE_DESCR, "device %d interface %d isn't a "
535 "video streaming interface\n", dev->udev->devnum, 547 "video streaming interface\n", dev->udev->devnum,
536 intf->altsetting[0].desc.bInterfaceNumber); 548 intf->altsetting[0].desc.bInterfaceNumber);
@@ -551,6 +563,7 @@ static int uvc_parse_streaming(struct uvc_device *dev,
551 } 563 }
552 564
553 mutex_init(&streaming->mutex); 565 mutex_init(&streaming->mutex);
566 streaming->dev = dev;
554 streaming->intf = usb_get_intf(intf); 567 streaming->intf = usb_get_intf(intf);
555 streaming->intfnum = intf->cur_altsetting->desc.bInterfaceNumber; 568 streaming->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
556 569
@@ -589,12 +602,12 @@ static int uvc_parse_streaming(struct uvc_device *dev,
589 602
590 /* Parse the header descriptor. */ 603 /* Parse the header descriptor. */
591 switch (buffer[2]) { 604 switch (buffer[2]) {
592 case VS_OUTPUT_HEADER: 605 case UVC_VS_OUTPUT_HEADER:
593 streaming->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; 606 streaming->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
594 size = 9; 607 size = 9;
595 break; 608 break;
596 609
597 case VS_INPUT_HEADER: 610 case UVC_VS_INPUT_HEADER:
598 streaming->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 611 streaming->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
599 size = 13; 612 size = 13;
600 break; 613 break;
@@ -618,7 +631,7 @@ static int uvc_parse_streaming(struct uvc_device *dev,
618 631
619 streaming->header.bNumFormats = p; 632 streaming->header.bNumFormats = p;
620 streaming->header.bEndpointAddress = buffer[6]; 633 streaming->header.bEndpointAddress = buffer[6];
621 if (buffer[2] == VS_INPUT_HEADER) { 634 if (buffer[2] == UVC_VS_INPUT_HEADER) {
622 streaming->header.bmInfo = buffer[7]; 635 streaming->header.bmInfo = buffer[7];
623 streaming->header.bTerminalLink = buffer[8]; 636 streaming->header.bTerminalLink = buffer[8];
624 streaming->header.bStillCaptureMethod = buffer[9]; 637 streaming->header.bStillCaptureMethod = buffer[9];
@@ -644,15 +657,15 @@ static int uvc_parse_streaming(struct uvc_device *dev,
644 _buflen = buflen; 657 _buflen = buflen;
645 658
646 /* Count the format and frame descriptors. */ 659 /* Count the format and frame descriptors. */
647 while (_buflen > 2 && _buffer[1] == CS_INTERFACE) { 660 while (_buflen > 2 && _buffer[1] == USB_DT_CS_INTERFACE) {
648 switch (_buffer[2]) { 661 switch (_buffer[2]) {
649 case VS_FORMAT_UNCOMPRESSED: 662 case UVC_VS_FORMAT_UNCOMPRESSED:
650 case VS_FORMAT_MJPEG: 663 case UVC_VS_FORMAT_MJPEG:
651 case VS_FORMAT_FRAME_BASED: 664 case UVC_VS_FORMAT_FRAME_BASED:
652 nformats++; 665 nformats++;
653 break; 666 break;
654 667
655 case VS_FORMAT_DV: 668 case UVC_VS_FORMAT_DV:
656 /* DV format has no frame descriptor. We will create a 669 /* DV format has no frame descriptor. We will create a
657 * dummy frame descriptor with a dummy frame interval. 670 * dummy frame descriptor with a dummy frame interval.
658 */ 671 */
@@ -661,22 +674,22 @@ static int uvc_parse_streaming(struct uvc_device *dev,
661 nintervals++; 674 nintervals++;
662 break; 675 break;
663 676
664 case VS_FORMAT_MPEG2TS: 677 case UVC_VS_FORMAT_MPEG2TS:
665 case VS_FORMAT_STREAM_BASED: 678 case UVC_VS_FORMAT_STREAM_BASED:
666 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming " 679 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
667 "interface %d FORMAT %u is not supported.\n", 680 "interface %d FORMAT %u is not supported.\n",
668 dev->udev->devnum, 681 dev->udev->devnum,
669 alts->desc.bInterfaceNumber, _buffer[2]); 682 alts->desc.bInterfaceNumber, _buffer[2]);
670 break; 683 break;
671 684
672 case VS_FRAME_UNCOMPRESSED: 685 case UVC_VS_FRAME_UNCOMPRESSED:
673 case VS_FRAME_MJPEG: 686 case UVC_VS_FRAME_MJPEG:
674 nframes++; 687 nframes++;
675 if (_buflen > 25) 688 if (_buflen > 25)
676 nintervals += _buffer[25] ? _buffer[25] : 3; 689 nintervals += _buffer[25] ? _buffer[25] : 3;
677 break; 690 break;
678 691
679 case VS_FRAME_FRAME_BASED: 692 case UVC_VS_FRAME_FRAME_BASED:
680 nframes++; 693 nframes++;
681 if (_buflen > 21) 694 if (_buflen > 21)
682 nintervals += _buffer[21] ? _buffer[21] : 3; 695 nintervals += _buffer[21] ? _buffer[21] : 3;
@@ -709,12 +722,12 @@ static int uvc_parse_streaming(struct uvc_device *dev,
709 streaming->nformats = nformats; 722 streaming->nformats = nformats;
710 723
711 /* Parse the format descriptors. */ 724 /* Parse the format descriptors. */
712 while (buflen > 2 && buffer[1] == CS_INTERFACE) { 725 while (buflen > 2 && buffer[1] == USB_DT_CS_INTERFACE) {
713 switch (buffer[2]) { 726 switch (buffer[2]) {
714 case VS_FORMAT_UNCOMPRESSED: 727 case UVC_VS_FORMAT_UNCOMPRESSED:
715 case VS_FORMAT_MJPEG: 728 case UVC_VS_FORMAT_MJPEG:
716 case VS_FORMAT_DV: 729 case UVC_VS_FORMAT_DV:
717 case VS_FORMAT_FRAME_BASED: 730 case UVC_VS_FORMAT_FRAME_BASED:
718 format->frame = frame; 731 format->frame = frame;
719 ret = uvc_parse_format(dev, streaming, format, 732 ret = uvc_parse_format(dev, streaming, format,
720 &interval, buffer, buflen); 733 &interval, buffer, buflen);
@@ -751,7 +764,7 @@ static int uvc_parse_streaming(struct uvc_device *dev,
751 streaming->maxpsize = psize; 764 streaming->maxpsize = psize;
752 } 765 }
753 766
754 list_add_tail(&streaming->list, &dev->streaming); 767 list_add_tail(&streaming->list, &dev->streams);
755 return 0; 768 return 0;
756 769
757error: 770error:
@@ -819,7 +832,7 @@ static int uvc_parse_vendor_control(struct uvc_device *dev,
819 return -ENOMEM; 832 return -ENOMEM;
820 833
821 unit->id = buffer[3]; 834 unit->id = buffer[3];
822 unit->type = VC_EXTENSION_UNIT; 835 unit->type = UVC_VC_EXTENSION_UNIT;
823 memcpy(unit->extension.guidExtensionCode, &buffer[4], 16); 836 memcpy(unit->extension.guidExtensionCode, &buffer[4], 16);
824 unit->extension.bNumControls = buffer[20]; 837 unit->extension.bNumControls = buffer[20];
825 unit->extension.bNrInPins = get_unaligned_le16(&buffer[21]); 838 unit->extension.bNrInPins = get_unaligned_le16(&buffer[21]);
@@ -856,7 +869,7 @@ static int uvc_parse_standard_control(struct uvc_device *dev,
856 __u16 type; 869 __u16 type;
857 870
858 switch (buffer[2]) { 871 switch (buffer[2]) {
859 case VC_HEADER: 872 case UVC_VC_HEADER:
860 n = buflen >= 12 ? buffer[11] : 0; 873 n = buflen >= 12 ? buffer[11] : 0;
861 874
862 if (buflen < 12 || buflen < 12 + n) { 875 if (buflen < 12 || buflen < 12 + n) {
@@ -883,7 +896,7 @@ static int uvc_parse_standard_control(struct uvc_device *dev,
883 } 896 }
884 break; 897 break;
885 898
886 case VC_INPUT_TERMINAL: 899 case UVC_VC_INPUT_TERMINAL:
887 if (buflen < 8) { 900 if (buflen < 8) {
888 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol " 901 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
889 "interface %d INPUT_TERMINAL error\n", 902 "interface %d INPUT_TERMINAL error\n",
@@ -908,11 +921,11 @@ static int uvc_parse_standard_control(struct uvc_device *dev,
908 p = 0; 921 p = 0;
909 len = 8; 922 len = 8;
910 923
911 if (type == ITT_CAMERA) { 924 if (type == UVC_ITT_CAMERA) {
912 n = buflen >= 15 ? buffer[14] : 0; 925 n = buflen >= 15 ? buffer[14] : 0;
913 len = 15; 926 len = 15;
914 927
915 } else if (type == ITT_MEDIA_TRANSPORT_INPUT) { 928 } else if (type == UVC_ITT_MEDIA_TRANSPORT_INPUT) {
916 n = buflen >= 9 ? buffer[8] : 0; 929 n = buflen >= 9 ? buffer[8] : 0;
917 p = buflen >= 10 + n ? buffer[9+n] : 0; 930 p = buflen >= 10 + n ? buffer[9+n] : 0;
918 len = 10; 931 len = 10;
@@ -932,7 +945,7 @@ static int uvc_parse_standard_control(struct uvc_device *dev,
932 term->id = buffer[3]; 945 term->id = buffer[3];
933 term->type = type | UVC_TERM_INPUT; 946 term->type = type | UVC_TERM_INPUT;
934 947
935 if (UVC_ENTITY_TYPE(term) == ITT_CAMERA) { 948 if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA) {
936 term->camera.bControlSize = n; 949 term->camera.bControlSize = n;
937 term->camera.bmControls = (__u8 *)term + sizeof *term; 950 term->camera.bmControls = (__u8 *)term + sizeof *term;
938 term->camera.wObjectiveFocalLengthMin = 951 term->camera.wObjectiveFocalLengthMin =
@@ -942,7 +955,8 @@ static int uvc_parse_standard_control(struct uvc_device *dev,
942 term->camera.wOcularFocalLength = 955 term->camera.wOcularFocalLength =
943 get_unaligned_le16(&buffer[12]); 956 get_unaligned_le16(&buffer[12]);
944 memcpy(term->camera.bmControls, &buffer[15], n); 957 memcpy(term->camera.bmControls, &buffer[15], n);
945 } else if (UVC_ENTITY_TYPE(term) == ITT_MEDIA_TRANSPORT_INPUT) { 958 } else if (UVC_ENTITY_TYPE(term) ==
959 UVC_ITT_MEDIA_TRANSPORT_INPUT) {
946 term->media.bControlSize = n; 960 term->media.bControlSize = n;
947 term->media.bmControls = (__u8 *)term + sizeof *term; 961 term->media.bmControls = (__u8 *)term + sizeof *term;
948 term->media.bTransportModeSize = p; 962 term->media.bTransportModeSize = p;
@@ -955,9 +969,9 @@ static int uvc_parse_standard_control(struct uvc_device *dev,
955 if (buffer[7] != 0) 969 if (buffer[7] != 0)
956 usb_string(udev, buffer[7], term->name, 970 usb_string(udev, buffer[7], term->name,
957 sizeof term->name); 971 sizeof term->name);
958 else if (UVC_ENTITY_TYPE(term) == ITT_CAMERA) 972 else if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA)
959 sprintf(term->name, "Camera %u", buffer[3]); 973 sprintf(term->name, "Camera %u", buffer[3]);
960 else if (UVC_ENTITY_TYPE(term) == ITT_MEDIA_TRANSPORT_INPUT) 974 else if (UVC_ENTITY_TYPE(term) == UVC_ITT_MEDIA_TRANSPORT_INPUT)
961 sprintf(term->name, "Media %u", buffer[3]); 975 sprintf(term->name, "Media %u", buffer[3]);
962 else 976 else
963 sprintf(term->name, "Input %u", buffer[3]); 977 sprintf(term->name, "Input %u", buffer[3]);
@@ -965,7 +979,7 @@ static int uvc_parse_standard_control(struct uvc_device *dev,
965 list_add_tail(&term->list, &dev->entities); 979 list_add_tail(&term->list, &dev->entities);
966 break; 980 break;
967 981
968 case VC_OUTPUT_TERMINAL: 982 case UVC_VC_OUTPUT_TERMINAL:
969 if (buflen < 9) { 983 if (buflen < 9) {
970 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol " 984 uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
971 "interface %d OUTPUT_TERMINAL error\n", 985 "interface %d OUTPUT_TERMINAL error\n",
@@ -1002,7 +1016,7 @@ static int uvc_parse_standard_control(struct uvc_device *dev,
1002 list_add_tail(&term->list, &dev->entities); 1016 list_add_tail(&term->list, &dev->entities);
1003 break; 1017 break;
1004 1018
1005 case VC_SELECTOR_UNIT: 1019 case UVC_VC_SELECTOR_UNIT:
1006 p = buflen >= 5 ? buffer[4] : 0; 1020 p = buflen >= 5 ? buffer[4] : 0;
1007 1021
1008 if (buflen < 5 || buflen < 6 + p) { 1022 if (buflen < 5 || buflen < 6 + p) {
@@ -1031,7 +1045,7 @@ static int uvc_parse_standard_control(struct uvc_device *dev,
1031 list_add_tail(&unit->list, &dev->entities); 1045 list_add_tail(&unit->list, &dev->entities);
1032 break; 1046 break;
1033 1047
1034 case VC_PROCESSING_UNIT: 1048 case UVC_VC_PROCESSING_UNIT:
1035 n = buflen >= 8 ? buffer[7] : 0; 1049 n = buflen >= 8 ? buffer[7] : 0;
1036 p = dev->uvc_version >= 0x0110 ? 10 : 9; 1050 p = dev->uvc_version >= 0x0110 ? 10 : 9;
1037 1051
@@ -1066,7 +1080,7 @@ static int uvc_parse_standard_control(struct uvc_device *dev,
1066 list_add_tail(&unit->list, &dev->entities); 1080 list_add_tail(&unit->list, &dev->entities);
1067 break; 1081 break;
1068 1082
1069 case VC_EXTENSION_UNIT: 1083 case UVC_VC_EXTENSION_UNIT:
1070 p = buflen >= 22 ? buffer[21] : 0; 1084 p = buflen >= 22 ? buffer[21] : 0;
1071 n = buflen >= 24 + p ? buffer[22+p] : 0; 1085 n = buflen >= 24 + p ? buffer[22+p] : 0;
1072 1086
@@ -1158,43 +1172,40 @@ next_descriptor:
1158} 1172}
1159 1173
1160/* ------------------------------------------------------------------------ 1174/* ------------------------------------------------------------------------
1161 * USB probe and disconnect 1175 * UVC device scan
1162 */ 1176 */
1163 1177
1164/* 1178/*
1165 * Unregister the video devices.
1166 */
1167static void uvc_unregister_video(struct uvc_device *dev)
1168{
1169 if (dev->video.vdev) {
1170 if (dev->video.vdev->minor == -1)
1171 video_device_release(dev->video.vdev);
1172 else
1173 video_unregister_device(dev->video.vdev);
1174 dev->video.vdev = NULL;
1175 }
1176}
1177
1178/*
1179 * Scan the UVC descriptors to locate a chain starting at an Output Terminal 1179 * Scan the UVC descriptors to locate a chain starting at an Output Terminal
1180 * and containing the following units: 1180 * and containing the following units:
1181 * 1181 *
1182 * - one Output Terminal (USB Streaming or Display) 1182 * - one or more Output Terminals (USB Streaming or Display)
1183 * - zero or one Processing Unit 1183 * - zero or one Processing Unit
1184 * - zero, one or mode single-input Selector Units 1184 * - zero, one or more single-input Selector Units
1185 * - zero or one multiple-input Selector Units, provided all inputs are 1185 * - zero or one multiple-input Selector Units, provided all inputs are
1186 * connected to input terminals 1186 * connected to input terminals
1187 * - zero, one or mode single-input Extension Units 1187 * - zero, one or mode single-input Extension Units
1188 * - one or more Input Terminals (Camera, External or USB Streaming) 1188 * - one or more Input Terminals (Camera, External or USB Streaming)
1189 * 1189 *
1190 * A side forward scan is made on each detected entity to check for additional 1190 * The terminal and units must match on of the following structures:
1191 * extension units. 1191 *
1192 * ITT_*(0) -> +---------+ +---------+ +---------+ -> TT_STREAMING(0)
1193 * ... | SU{0,1} | -> | PU{0,1} | -> | XU{0,n} | ...
1194 * ITT_*(n) -> +---------+ +---------+ +---------+ -> TT_STREAMING(n)
1195 *
1196 * +---------+ +---------+ -> OTT_*(0)
1197 * TT_STREAMING -> | PU{0,1} | -> | XU{0,n} | ...
1198 * +---------+ +---------+ -> OTT_*(n)
1199 *
1200 * The Processing Unit and Extension Units can be in any order. Additional
1201 * Extension Units connected to the main chain as single-unit branches are
1202 * also supported. Single-input Selector Units are ignored.
1192 */ 1203 */
1193static int uvc_scan_chain_entity(struct uvc_video_device *video, 1204static int uvc_scan_chain_entity(struct uvc_video_chain *chain,
1194 struct uvc_entity *entity) 1205 struct uvc_entity *entity)
1195{ 1206{
1196 switch (UVC_ENTITY_TYPE(entity)) { 1207 switch (UVC_ENTITY_TYPE(entity)) {
1197 case VC_EXTENSION_UNIT: 1208 case UVC_VC_EXTENSION_UNIT:
1198 if (uvc_trace_param & UVC_TRACE_PROBE) 1209 if (uvc_trace_param & UVC_TRACE_PROBE)
1199 printk(" <- XU %d", entity->id); 1210 printk(" <- XU %d", entity->id);
1200 1211
@@ -1204,23 +1215,23 @@ static int uvc_scan_chain_entity(struct uvc_video_device *video,
1204 return -1; 1215 return -1;
1205 } 1216 }
1206 1217
1207 list_add_tail(&entity->chain, &video->extensions); 1218 list_add_tail(&entity->chain, &chain->extensions);
1208 break; 1219 break;
1209 1220
1210 case VC_PROCESSING_UNIT: 1221 case UVC_VC_PROCESSING_UNIT:
1211 if (uvc_trace_param & UVC_TRACE_PROBE) 1222 if (uvc_trace_param & UVC_TRACE_PROBE)
1212 printk(" <- PU %d", entity->id); 1223 printk(" <- PU %d", entity->id);
1213 1224
1214 if (video->processing != NULL) { 1225 if (chain->processing != NULL) {
1215 uvc_trace(UVC_TRACE_DESCR, "Found multiple " 1226 uvc_trace(UVC_TRACE_DESCR, "Found multiple "
1216 "Processing Units in chain.\n"); 1227 "Processing Units in chain.\n");
1217 return -1; 1228 return -1;
1218 } 1229 }
1219 1230
1220 video->processing = entity; 1231 chain->processing = entity;
1221 break; 1232 break;
1222 1233
1223 case VC_SELECTOR_UNIT: 1234 case UVC_VC_SELECTOR_UNIT:
1224 if (uvc_trace_param & UVC_TRACE_PROBE) 1235 if (uvc_trace_param & UVC_TRACE_PROBE)
1225 printk(" <- SU %d", entity->id); 1236 printk(" <- SU %d", entity->id);
1226 1237
@@ -1228,25 +1239,25 @@ static int uvc_scan_chain_entity(struct uvc_video_device *video,
1228 if (entity->selector.bNrInPins == 1) 1239 if (entity->selector.bNrInPins == 1)
1229 break; 1240 break;
1230 1241
1231 if (video->selector != NULL) { 1242 if (chain->selector != NULL) {
1232 uvc_trace(UVC_TRACE_DESCR, "Found multiple Selector " 1243 uvc_trace(UVC_TRACE_DESCR, "Found multiple Selector "
1233 "Units in chain.\n"); 1244 "Units in chain.\n");
1234 return -1; 1245 return -1;
1235 } 1246 }
1236 1247
1237 video->selector = entity; 1248 chain->selector = entity;
1238 break; 1249 break;
1239 1250
1240 case ITT_VENDOR_SPECIFIC: 1251 case UVC_ITT_VENDOR_SPECIFIC:
1241 case ITT_CAMERA: 1252 case UVC_ITT_CAMERA:
1242 case ITT_MEDIA_TRANSPORT_INPUT: 1253 case UVC_ITT_MEDIA_TRANSPORT_INPUT:
1243 if (uvc_trace_param & UVC_TRACE_PROBE) 1254 if (uvc_trace_param & UVC_TRACE_PROBE)
1244 printk(" <- IT %d\n", entity->id); 1255 printk(" <- IT %d\n", entity->id);
1245 1256
1246 list_add_tail(&entity->chain, &video->iterms); 1257 list_add_tail(&entity->chain, &chain->iterms);
1247 break; 1258 break;
1248 1259
1249 case TT_STREAMING: 1260 case UVC_TT_STREAMING:
1250 if (uvc_trace_param & UVC_TRACE_PROBE) 1261 if (uvc_trace_param & UVC_TRACE_PROBE)
1251 printk(" <- IT %d\n", entity->id); 1262 printk(" <- IT %d\n", entity->id);
1252 1263
@@ -1256,14 +1267,7 @@ static int uvc_scan_chain_entity(struct uvc_video_device *video,
1256 return -1; 1267 return -1;
1257 } 1268 }
1258 1269
1259 if (video->sterm != NULL) { 1270 list_add_tail(&entity->chain, &chain->iterms);
1260 uvc_trace(UVC_TRACE_DESCR, "Found multiple streaming "
1261 "entities in chain.\n");
1262 return -1;
1263 }
1264
1265 list_add_tail(&entity->chain, &video->iterms);
1266 video->sterm = entity;
1267 break; 1271 break;
1268 1272
1269 default: 1273 default:
@@ -1275,7 +1279,7 @@ static int uvc_scan_chain_entity(struct uvc_video_device *video,
1275 return 0; 1279 return 0;
1276} 1280}
1277 1281
1278static int uvc_scan_chain_forward(struct uvc_video_device *video, 1282static int uvc_scan_chain_forward(struct uvc_video_chain *chain,
1279 struct uvc_entity *entity, struct uvc_entity *prev) 1283 struct uvc_entity *entity, struct uvc_entity *prev)
1280{ 1284{
1281 struct uvc_entity *forward; 1285 struct uvc_entity *forward;
@@ -1286,28 +1290,51 @@ static int uvc_scan_chain_forward(struct uvc_video_device *video,
1286 found = 0; 1290 found = 0;
1287 1291
1288 while (1) { 1292 while (1) {
1289 forward = uvc_entity_by_reference(video->dev, entity->id, 1293 forward = uvc_entity_by_reference(chain->dev, entity->id,
1290 forward); 1294 forward);
1291 if (forward == NULL) 1295 if (forward == NULL)
1292 break; 1296 break;
1293 1297 if (forward == prev)
1294 if (UVC_ENTITY_TYPE(forward) != VC_EXTENSION_UNIT ||
1295 forward == prev)
1296 continue; 1298 continue;
1297 1299
1298 if (forward->extension.bNrInPins != 1) { 1300 switch (UVC_ENTITY_TYPE(forward)) {
1299 uvc_trace(UVC_TRACE_DESCR, "Extension unit %d has " 1301 case UVC_VC_EXTENSION_UNIT:
1300 "more than 1 input pin.\n", entity->id); 1302 if (forward->extension.bNrInPins != 1) {
1301 return -1; 1303 uvc_trace(UVC_TRACE_DESCR, "Extension unit %d "
1302 } 1304 "has more than 1 input pin.\n",
1305 entity->id);
1306 return -EINVAL;
1307 }
1308
1309 list_add_tail(&forward->chain, &chain->extensions);
1310 if (uvc_trace_param & UVC_TRACE_PROBE) {
1311 if (!found)
1312 printk(" (->");
1303 1313
1304 list_add_tail(&forward->chain, &video->extensions); 1314 printk(" XU %d", forward->id);
1305 if (uvc_trace_param & UVC_TRACE_PROBE) { 1315 found = 1;
1306 if (!found) 1316 }
1307 printk(" (-> XU"); 1317 break;
1318
1319 case UVC_OTT_VENDOR_SPECIFIC:
1320 case UVC_OTT_DISPLAY:
1321 case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
1322 case UVC_TT_STREAMING:
1323 if (UVC_ENTITY_IS_ITERM(forward)) {
1324 uvc_trace(UVC_TRACE_DESCR, "Unsupported input "
1325 "terminal %u.\n", forward->id);
1326 return -EINVAL;
1327 }
1308 1328
1309 printk(" %d", forward->id); 1329 list_add_tail(&forward->chain, &chain->oterms);
1310 found = 1; 1330 if (uvc_trace_param & UVC_TRACE_PROBE) {
1331 if (!found)
1332 printk(" (->");
1333
1334 printk(" OT %d", forward->id);
1335 found = 1;
1336 }
1337 break;
1311 } 1338 }
1312 } 1339 }
1313 if (found) 1340 if (found)
@@ -1316,22 +1343,22 @@ static int uvc_scan_chain_forward(struct uvc_video_device *video,
1316 return 0; 1343 return 0;
1317} 1344}
1318 1345
1319static int uvc_scan_chain_backward(struct uvc_video_device *video, 1346static int uvc_scan_chain_backward(struct uvc_video_chain *chain,
1320 struct uvc_entity *entity) 1347 struct uvc_entity *entity)
1321{ 1348{
1322 struct uvc_entity *term; 1349 struct uvc_entity *term;
1323 int id = -1, i; 1350 int id = -1, i;
1324 1351
1325 switch (UVC_ENTITY_TYPE(entity)) { 1352 switch (UVC_ENTITY_TYPE(entity)) {
1326 case VC_EXTENSION_UNIT: 1353 case UVC_VC_EXTENSION_UNIT:
1327 id = entity->extension.baSourceID[0]; 1354 id = entity->extension.baSourceID[0];
1328 break; 1355 break;
1329 1356
1330 case VC_PROCESSING_UNIT: 1357 case UVC_VC_PROCESSING_UNIT:
1331 id = entity->processing.bSourceID; 1358 id = entity->processing.bSourceID;
1332 break; 1359 break;
1333 1360
1334 case VC_SELECTOR_UNIT: 1361 case UVC_VC_SELECTOR_UNIT:
1335 /* Single-input selector units are ignored. */ 1362 /* Single-input selector units are ignored. */
1336 if (entity->selector.bNrInPins == 1) { 1363 if (entity->selector.bNrInPins == 1) {
1337 id = entity->selector.baSourceID[0]; 1364 id = entity->selector.baSourceID[0];
@@ -1341,10 +1368,10 @@ static int uvc_scan_chain_backward(struct uvc_video_device *video,
1341 if (uvc_trace_param & UVC_TRACE_PROBE) 1368 if (uvc_trace_param & UVC_TRACE_PROBE)
1342 printk(" <- IT"); 1369 printk(" <- IT");
1343 1370
1344 video->selector = entity; 1371 chain->selector = entity;
1345 for (i = 0; i < entity->selector.bNrInPins; ++i) { 1372 for (i = 0; i < entity->selector.bNrInPins; ++i) {
1346 id = entity->selector.baSourceID[i]; 1373 id = entity->selector.baSourceID[i];
1347 term = uvc_entity_by_id(video->dev, id); 1374 term = uvc_entity_by_id(chain->dev, id);
1348 if (term == NULL || !UVC_ENTITY_IS_ITERM(term)) { 1375 if (term == NULL || !UVC_ENTITY_IS_ITERM(term)) {
1349 uvc_trace(UVC_TRACE_DESCR, "Selector unit %d " 1376 uvc_trace(UVC_TRACE_DESCR, "Selector unit %d "
1350 "input %d isn't connected to an " 1377 "input %d isn't connected to an "
@@ -1355,8 +1382,8 @@ static int uvc_scan_chain_backward(struct uvc_video_device *video,
1355 if (uvc_trace_param & UVC_TRACE_PROBE) 1382 if (uvc_trace_param & UVC_TRACE_PROBE)
1356 printk(" %d", term->id); 1383 printk(" %d", term->id);
1357 1384
1358 list_add_tail(&term->chain, &video->iterms); 1385 list_add_tail(&term->chain, &chain->iterms);
1359 uvc_scan_chain_forward(video, term, entity); 1386 uvc_scan_chain_forward(chain, term, entity);
1360 } 1387 }
1361 1388
1362 if (uvc_trace_param & UVC_TRACE_PROBE) 1389 if (uvc_trace_param & UVC_TRACE_PROBE)
@@ -1369,125 +1396,170 @@ static int uvc_scan_chain_backward(struct uvc_video_device *video,
1369 return id; 1396 return id;
1370} 1397}
1371 1398
1372static int uvc_scan_chain(struct uvc_video_device *video) 1399static int uvc_scan_chain(struct uvc_video_chain *chain,
1400 struct uvc_entity *oterm)
1373{ 1401{
1374 struct uvc_entity *entity, *prev; 1402 struct uvc_entity *entity, *prev;
1375 int id; 1403 int id;
1376 1404
1377 entity = video->oterm; 1405 entity = oterm;
1406 list_add_tail(&entity->chain, &chain->oterms);
1378 uvc_trace(UVC_TRACE_PROBE, "Scanning UVC chain: OT %d", entity->id); 1407 uvc_trace(UVC_TRACE_PROBE, "Scanning UVC chain: OT %d", entity->id);
1379 1408
1380 if (UVC_ENTITY_TYPE(entity) == TT_STREAMING)
1381 video->sterm = entity;
1382
1383 id = entity->output.bSourceID; 1409 id = entity->output.bSourceID;
1384 while (id != 0) { 1410 while (id != 0) {
1385 prev = entity; 1411 prev = entity;
1386 entity = uvc_entity_by_id(video->dev, id); 1412 entity = uvc_entity_by_id(chain->dev, id);
1387 if (entity == NULL) { 1413 if (entity == NULL) {
1388 uvc_trace(UVC_TRACE_DESCR, "Found reference to " 1414 uvc_trace(UVC_TRACE_DESCR, "Found reference to "
1389 "unknown entity %d.\n", id); 1415 "unknown entity %d.\n", id);
1390 return -1; 1416 return -EINVAL;
1417 }
1418
1419 if (entity->chain.next || entity->chain.prev) {
1420 uvc_trace(UVC_TRACE_DESCR, "Found reference to "
1421 "entity %d already in chain.\n", id);
1422 return -EINVAL;
1391 } 1423 }
1392 1424
1393 /* Process entity */ 1425 /* Process entity */
1394 if (uvc_scan_chain_entity(video, entity) < 0) 1426 if (uvc_scan_chain_entity(chain, entity) < 0)
1395 return -1; 1427 return -EINVAL;
1396 1428
1397 /* Forward scan */ 1429 /* Forward scan */
1398 if (uvc_scan_chain_forward(video, entity, prev) < 0) 1430 if (uvc_scan_chain_forward(chain, entity, prev) < 0)
1399 return -1; 1431 return -EINVAL;
1400 1432
1401 /* Stop when a terminal is found. */ 1433 /* Stop when a terminal is found. */
1402 if (!UVC_ENTITY_IS_UNIT(entity)) 1434 if (UVC_ENTITY_IS_TERM(entity))
1403 break; 1435 break;
1404 1436
1405 /* Backward scan */ 1437 /* Backward scan */
1406 id = uvc_scan_chain_backward(video, entity); 1438 id = uvc_scan_chain_backward(chain, entity);
1407 if (id < 0) 1439 if (id < 0)
1408 return id; 1440 return id;
1409 } 1441 }
1410 1442
1411 if (video->sterm == NULL) { 1443 return 0;
1412 uvc_trace(UVC_TRACE_DESCR, "No streaming entity found in " 1444}
1413 "chain.\n"); 1445
1414 return -1; 1446static unsigned int uvc_print_terms(struct list_head *terms, char *buffer)
1447{
1448 struct uvc_entity *term;
1449 unsigned int nterms = 0;
1450 char *p = buffer;
1451
1452 list_for_each_entry(term, terms, chain) {
1453 p += sprintf(p, "%u", term->id);
1454 if (term->chain.next != terms) {
1455 p += sprintf(p, ",");
1456 if (++nterms >= 4) {
1457 p += sprintf(p, "...");
1458 break;
1459 }
1460 }
1415 } 1461 }
1416 1462
1417 return 0; 1463 return p - buffer;
1464}
1465
1466static const char *uvc_print_chain(struct uvc_video_chain *chain)
1467{
1468 static char buffer[43];
1469 char *p = buffer;
1470
1471 p += uvc_print_terms(&chain->iterms, p);
1472 p += sprintf(p, " -> ");
1473 uvc_print_terms(&chain->oterms, p);
1474
1475 return buffer;
1418} 1476}
1419 1477
1420/* 1478/*
1421 * Register the video devices. 1479 * Scan the device for video chains and register video devices.
1422 *
1423 * The driver currently supports a single video device per control interface
1424 * only. The terminal and units must match the following structure:
1425 * 1480 *
1426 * ITT_* -> VC_PROCESSING_UNIT -> VC_EXTENSION_UNIT{0,n} -> TT_STREAMING 1481 * Chains are scanned starting at their output terminals and walked backwards.
1427 * TT_STREAMING -> VC_PROCESSING_UNIT -> VC_EXTENSION_UNIT{0,n} -> OTT_*
1428 *
1429 * The Extension Units, if present, must have a single input pin. The
1430 * Processing Unit and Extension Units can be in any order. Additional
1431 * Extension Units connected to the main chain as single-unit branches are
1432 * also supported.
1433 */ 1482 */
1434static int uvc_register_video(struct uvc_device *dev) 1483static int uvc_scan_device(struct uvc_device *dev)
1435{ 1484{
1436 struct video_device *vdev; 1485 struct uvc_video_chain *chain;
1437 struct uvc_entity *term; 1486 struct uvc_entity *term;
1438 int found = 0, ret;
1439 1487
1440 /* Check if the control interface matches the structure we expect. */
1441 list_for_each_entry(term, &dev->entities, list) { 1488 list_for_each_entry(term, &dev->entities, list) {
1442 struct uvc_streaming *streaming; 1489 if (!UVC_ENTITY_IS_OTERM(term))
1443
1444 if (!UVC_ENTITY_IS_TERM(term) || !UVC_ENTITY_IS_OTERM(term))
1445 continue; 1490 continue;
1446 1491
1447 memset(&dev->video, 0, sizeof dev->video); 1492 /* If the terminal is already included in a chain, skip it.
1448 mutex_init(&dev->video.ctrl_mutex); 1493 * This can happen for chains that have multiple output
1449 INIT_LIST_HEAD(&dev->video.iterms); 1494 * terminals, where all output terminals beside the first one
1450 INIT_LIST_HEAD(&dev->video.extensions); 1495 * will be inserted in the chain in forward scans.
1451 dev->video.oterm = term; 1496 */
1452 dev->video.dev = dev; 1497 if (term->chain.next || term->chain.prev)
1453 if (uvc_scan_chain(&dev->video) < 0)
1454 continue; 1498 continue;
1455 1499
1456 list_for_each_entry(streaming, &dev->streaming, list) { 1500 chain = kzalloc(sizeof(*chain), GFP_KERNEL);
1457 if (streaming->header.bTerminalLink == 1501 if (chain == NULL)
1458 dev->video.sterm->id) { 1502 return -ENOMEM;
1459 dev->video.streaming = streaming; 1503
1460 found = 1; 1504 INIT_LIST_HEAD(&chain->iterms);
1461 break; 1505 INIT_LIST_HEAD(&chain->oterms);
1462 } 1506 INIT_LIST_HEAD(&chain->extensions);
1507 mutex_init(&chain->ctrl_mutex);
1508 chain->dev = dev;
1509
1510 if (uvc_scan_chain(chain, term) < 0) {
1511 kfree(chain);
1512 continue;
1463 } 1513 }
1464 1514
1465 if (found) 1515 uvc_trace(UVC_TRACE_PROBE, "Found a valid video chain (%s).\n",
1466 break; 1516 uvc_print_chain(chain));
1517
1518 list_add_tail(&chain->list, &dev->chains);
1467 } 1519 }
1468 1520
1469 if (!found) { 1521 if (list_empty(&dev->chains)) {
1470 uvc_printk(KERN_INFO, "No valid video chain found.\n"); 1522 uvc_printk(KERN_INFO, "No valid video chain found.\n");
1471 return -1; 1523 return -1;
1472 } 1524 }
1473 1525
1474 if (uvc_trace_param & UVC_TRACE_PROBE) { 1526 return 0;
1475 uvc_printk(KERN_INFO, "Found a valid video chain ("); 1527}
1476 list_for_each_entry(term, &dev->video.iterms, chain) { 1528
1477 printk("%d", term->id); 1529/* ------------------------------------------------------------------------
1478 if (term->chain.next != &dev->video.iterms) 1530 * Video device registration and unregistration
1479 printk(","); 1531 */
1480 } 1532
1481 printk(" -> %d).\n", dev->video.oterm->id); 1533/*
1534 * Unregister the video devices.
1535 */
1536static void uvc_unregister_video(struct uvc_device *dev)
1537{
1538 struct uvc_streaming *stream;
1539
1540 list_for_each_entry(stream, &dev->streams, list) {
1541 if (stream->vdev == NULL)
1542 continue;
1543
1544 if (stream->vdev->minor == -1)
1545 video_device_release(stream->vdev);
1546 else
1547 video_unregister_device(stream->vdev);
1548 stream->vdev = NULL;
1482 } 1549 }
1550}
1483 1551
1484 /* Initialize the video buffers queue. */ 1552static int uvc_register_video(struct uvc_device *dev,
1485 uvc_queue_init(&dev->video.queue, dev->video.streaming->type); 1553 struct uvc_streaming *stream)
1554{
1555 struct video_device *vdev;
1556 int ret;
1486 1557
1487 /* Initialize the streaming interface with default streaming 1558 /* Initialize the streaming interface with default streaming
1488 * parameters. 1559 * parameters.
1489 */ 1560 */
1490 if ((ret = uvc_video_init(&dev->video)) < 0) { 1561 ret = uvc_video_init(stream);
1562 if (ret < 0) {
1491 uvc_printk(KERN_ERR, "Failed to initialize the device " 1563 uvc_printk(KERN_ERR, "Failed to initialize the device "
1492 "(%d).\n", ret); 1564 "(%d).\n", ret);
1493 return ret; 1565 return ret;
@@ -1495,8 +1567,11 @@ static int uvc_register_video(struct uvc_device *dev)
1495 1567
1496 /* Register the device with V4L. */ 1568 /* Register the device with V4L. */
1497 vdev = video_device_alloc(); 1569 vdev = video_device_alloc();
1498 if (vdev == NULL) 1570 if (vdev == NULL) {
1499 return -1; 1571 uvc_printk(KERN_ERR, "Failed to allocate video device (%d).\n",
1572 ret);
1573 return -ENOMEM;
1574 }
1500 1575
1501 /* We already hold a reference to dev->udev. The video device will be 1576 /* We already hold a reference to dev->udev. The video device will be
1502 * unregistered before the reference is released, so we don't need to 1577 * unregistered before the reference is released, so we don't need to
@@ -1511,19 +1586,74 @@ static int uvc_register_video(struct uvc_device *dev)
1511 /* Set the driver data before calling video_register_device, otherwise 1586 /* Set the driver data before calling video_register_device, otherwise
1512 * uvc_v4l2_open might race us. 1587 * uvc_v4l2_open might race us.
1513 */ 1588 */
1514 dev->video.vdev = vdev; 1589 stream->vdev = vdev;
1515 video_set_drvdata(vdev, &dev->video); 1590 video_set_drvdata(vdev, stream);
1516 1591
1517 if (video_register_device(vdev, VFL_TYPE_GRABBER, -1) < 0) { 1592 ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
1518 dev->video.vdev = NULL; 1593 if (ret < 0) {
1594 uvc_printk(KERN_ERR, "Failed to register video device (%d).\n",
1595 ret);
1596 stream->vdev = NULL;
1519 video_device_release(vdev); 1597 video_device_release(vdev);
1520 return -1; 1598 return ret;
1521 } 1599 }
1522 1600
1523 return 0; 1601 return 0;
1524} 1602}
1525 1603
1526/* 1604/*
1605 * Register all video devices in all chains.
1606 */
1607static int uvc_register_terms(struct uvc_device *dev,
1608 struct uvc_video_chain *chain, struct list_head *terms)
1609{
1610 struct uvc_streaming *stream;
1611 struct uvc_entity *term;
1612 int ret;
1613
1614 list_for_each_entry(term, terms, chain) {
1615 if (UVC_ENTITY_TYPE(term) != UVC_TT_STREAMING)
1616 continue;
1617
1618 stream = uvc_stream_by_id(dev, term->id);
1619 if (stream == NULL) {
1620 uvc_printk(KERN_INFO, "No streaming interface found "
1621 "for terminal %u.", term->id);
1622 continue;
1623 }
1624
1625 stream->chain = chain;
1626 ret = uvc_register_video(dev, stream);
1627 if (ret < 0)
1628 return ret;
1629 }
1630
1631 return 0;
1632}
1633
1634static int uvc_register_chains(struct uvc_device *dev)
1635{
1636 struct uvc_video_chain *chain;
1637 int ret;
1638
1639 list_for_each_entry(chain, &dev->chains, list) {
1640 ret = uvc_register_terms(dev, chain, &chain->iterms);
1641 if (ret < 0)
1642 return ret;
1643
1644 ret = uvc_register_terms(dev, chain, &chain->oterms);
1645 if (ret < 0)
1646 return ret;
1647 }
1648
1649 return 0;
1650}
1651
1652/* ------------------------------------------------------------------------
1653 * USB probe, disconnect, suspend and resume
1654 */
1655
1656/*
1527 * Delete the UVC device. 1657 * Delete the UVC device.
1528 * 1658 *
1529 * Called by the kernel when the last reference to the uvc_device structure 1659 * Called by the kernel when the last reference to the uvc_device structure
@@ -1544,7 +1674,7 @@ void uvc_delete(struct kref *kref)
1544 struct uvc_device *dev = container_of(kref, struct uvc_device, kref); 1674 struct uvc_device *dev = container_of(kref, struct uvc_device, kref);
1545 struct list_head *p, *n; 1675 struct list_head *p, *n;
1546 1676
1547 /* Unregister the video device. */ 1677 /* Unregister the video devices. */
1548 uvc_unregister_video(dev); 1678 uvc_unregister_video(dev);
1549 usb_put_intf(dev->intf); 1679 usb_put_intf(dev->intf);
1550 usb_put_dev(dev->udev); 1680 usb_put_dev(dev->udev);
@@ -1552,13 +1682,19 @@ void uvc_delete(struct kref *kref)
1552 uvc_status_cleanup(dev); 1682 uvc_status_cleanup(dev);
1553 uvc_ctrl_cleanup_device(dev); 1683 uvc_ctrl_cleanup_device(dev);
1554 1684
1685 list_for_each_safe(p, n, &dev->chains) {
1686 struct uvc_video_chain *chain;
1687 chain = list_entry(p, struct uvc_video_chain, list);
1688 kfree(chain);
1689 }
1690
1555 list_for_each_safe(p, n, &dev->entities) { 1691 list_for_each_safe(p, n, &dev->entities) {
1556 struct uvc_entity *entity; 1692 struct uvc_entity *entity;
1557 entity = list_entry(p, struct uvc_entity, list); 1693 entity = list_entry(p, struct uvc_entity, list);
1558 kfree(entity); 1694 kfree(entity);
1559 } 1695 }
1560 1696
1561 list_for_each_safe(p, n, &dev->streaming) { 1697 list_for_each_safe(p, n, &dev->streams) {
1562 struct uvc_streaming *streaming; 1698 struct uvc_streaming *streaming;
1563 streaming = list_entry(p, struct uvc_streaming, list); 1699 streaming = list_entry(p, struct uvc_streaming, list);
1564 usb_driver_release_interface(&uvc_driver.driver, 1700 usb_driver_release_interface(&uvc_driver.driver,
@@ -1592,7 +1728,8 @@ static int uvc_probe(struct usb_interface *intf,
1592 return -ENOMEM; 1728 return -ENOMEM;
1593 1729
1594 INIT_LIST_HEAD(&dev->entities); 1730 INIT_LIST_HEAD(&dev->entities);
1595 INIT_LIST_HEAD(&dev->streaming); 1731 INIT_LIST_HEAD(&dev->chains);
1732 INIT_LIST_HEAD(&dev->streams);
1596 kref_init(&dev->kref); 1733 kref_init(&dev->kref);
1597 atomic_set(&dev->users, 0); 1734 atomic_set(&dev->users, 0);
1598 1735
@@ -1633,8 +1770,12 @@ static int uvc_probe(struct usb_interface *intf,
1633 if (uvc_ctrl_init_device(dev) < 0) 1770 if (uvc_ctrl_init_device(dev) < 0)
1634 goto error; 1771 goto error;
1635 1772
1636 /* Register the video devices. */ 1773 /* Scan the device for video chains. */
1637 if (uvc_register_video(dev) < 0) 1774 if (uvc_scan_device(dev) < 0)
1775 goto error;
1776
1777 /* Register video devices. */
1778 if (uvc_register_chains(dev) < 0)
1638 goto error; 1779 goto error;
1639 1780
1640 /* Save our data pointer in the interface data. */ 1781 /* Save our data pointer in the interface data. */
@@ -1664,7 +1805,8 @@ static void uvc_disconnect(struct usb_interface *intf)
1664 */ 1805 */
1665 usb_set_intfdata(intf, NULL); 1806 usb_set_intfdata(intf, NULL);
1666 1807
1667 if (intf->cur_altsetting->desc.bInterfaceSubClass == SC_VIDEOSTREAMING) 1808 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
1809 UVC_SC_VIDEOSTREAMING)
1668 return; 1810 return;
1669 1811
1670 /* uvc_v4l2_open() might race uvc_disconnect(). A static driver-wide 1812 /* uvc_v4l2_open() might race uvc_disconnect(). A static driver-wide
@@ -1687,31 +1829,36 @@ static void uvc_disconnect(struct usb_interface *intf)
1687static int uvc_suspend(struct usb_interface *intf, pm_message_t message) 1829static int uvc_suspend(struct usb_interface *intf, pm_message_t message)
1688{ 1830{
1689 struct uvc_device *dev = usb_get_intfdata(intf); 1831 struct uvc_device *dev = usb_get_intfdata(intf);
1832 struct uvc_streaming *stream;
1690 1833
1691 uvc_trace(UVC_TRACE_SUSPEND, "Suspending interface %u\n", 1834 uvc_trace(UVC_TRACE_SUSPEND, "Suspending interface %u\n",
1692 intf->cur_altsetting->desc.bInterfaceNumber); 1835 intf->cur_altsetting->desc.bInterfaceNumber);
1693 1836
1694 /* Controls are cached on the fly so they don't need to be saved. */ 1837 /* Controls are cached on the fly so they don't need to be saved. */
1695 if (intf->cur_altsetting->desc.bInterfaceSubClass == SC_VIDEOCONTROL) 1838 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
1839 UVC_SC_VIDEOCONTROL)
1696 return uvc_status_suspend(dev); 1840 return uvc_status_suspend(dev);
1697 1841
1698 if (dev->video.streaming->intf != intf) { 1842 list_for_each_entry(stream, &dev->streams, list) {
1699 uvc_trace(UVC_TRACE_SUSPEND, "Suspend: video streaming USB " 1843 if (stream->intf == intf)
1700 "interface mismatch.\n"); 1844 return uvc_video_suspend(stream);
1701 return -EINVAL;
1702 } 1845 }
1703 1846
1704 return uvc_video_suspend(&dev->video); 1847 uvc_trace(UVC_TRACE_SUSPEND, "Suspend: video streaming USB interface "
1848 "mismatch.\n");
1849 return -EINVAL;
1705} 1850}
1706 1851
1707static int __uvc_resume(struct usb_interface *intf, int reset) 1852static int __uvc_resume(struct usb_interface *intf, int reset)
1708{ 1853{
1709 struct uvc_device *dev = usb_get_intfdata(intf); 1854 struct uvc_device *dev = usb_get_intfdata(intf);
1855 struct uvc_streaming *stream;
1710 1856
1711 uvc_trace(UVC_TRACE_SUSPEND, "Resuming interface %u\n", 1857 uvc_trace(UVC_TRACE_SUSPEND, "Resuming interface %u\n",
1712 intf->cur_altsetting->desc.bInterfaceNumber); 1858 intf->cur_altsetting->desc.bInterfaceNumber);
1713 1859
1714 if (intf->cur_altsetting->desc.bInterfaceSubClass == SC_VIDEOCONTROL) { 1860 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
1861 UVC_SC_VIDEOCONTROL) {
1715 if (reset) { 1862 if (reset) {
1716 int ret = uvc_ctrl_resume_device(dev); 1863 int ret = uvc_ctrl_resume_device(dev);
1717 1864
@@ -1722,13 +1869,14 @@ static int __uvc_resume(struct usb_interface *intf, int reset)
1722 return uvc_status_resume(dev); 1869 return uvc_status_resume(dev);
1723 } 1870 }
1724 1871
1725 if (dev->video.streaming->intf != intf) { 1872 list_for_each_entry(stream, &dev->streams, list) {
1726 uvc_trace(UVC_TRACE_SUSPEND, "Resume: video streaming USB " 1873 if (stream->intf == intf)
1727 "interface mismatch.\n"); 1874 return uvc_video_resume(stream);
1728 return -EINVAL;
1729 } 1875 }
1730 1876
1731 return uvc_video_resume(&dev->video); 1877 uvc_trace(UVC_TRACE_SUSPEND, "Resume: video streaming USB interface "
1878 "mismatch.\n");
1879 return -EINVAL;
1732} 1880}
1733 1881
1734static int uvc_resume(struct usb_interface *intf) 1882static int uvc_resume(struct usb_interface *intf)
@@ -1880,7 +2028,8 @@ static struct usb_device_id uvc_ids[] = {
1880 .bInterfaceClass = USB_CLASS_VIDEO, 2028 .bInterfaceClass = USB_CLASS_VIDEO,
1881 .bInterfaceSubClass = 1, 2029 .bInterfaceSubClass = 1,
1882 .bInterfaceProtocol = 0, 2030 .bInterfaceProtocol = 0,
1883 .driver_info = UVC_QUIRK_PROBE_MINMAX }, 2031 .driver_info = UVC_QUIRK_PROBE_MINMAX
2032 | UVC_QUIRK_PROBE_DEF },
1884 /* Syntek (HP Spartan) */ 2033 /* Syntek (HP Spartan) */
1885 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 2034 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
1886 | USB_DEVICE_ID_MATCH_INT_INFO, 2035 | USB_DEVICE_ID_MATCH_INT_INFO,
@@ -1943,7 +2092,8 @@ static struct usb_device_id uvc_ids[] = {
1943 .bInterfaceClass = USB_CLASS_VIDEO, 2092 .bInterfaceClass = USB_CLASS_VIDEO,
1944 .bInterfaceSubClass = 1, 2093 .bInterfaceSubClass = 1,
1945 .bInterfaceProtocol = 0, 2094 .bInterfaceProtocol = 0,
1946 .driver_info = UVC_QUIRK_PROBE_EXTRAFIELDS }, 2095 .driver_info = UVC_QUIRK_PROBE_MINMAX
2096 | UVC_QUIRK_PROBE_EXTRAFIELDS },
1947 /* Ecamm Pico iMage */ 2097 /* Ecamm Pico iMage */
1948 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 2098 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
1949 | USB_DEVICE_ID_MATCH_INT_INFO, 2099 | USB_DEVICE_ID_MATCH_INT_INFO,
diff --git a/drivers/media/video/uvc/uvc_isight.c b/drivers/media/video/uvc/uvc_isight.c
index 436f462685a0..a9285b570dbe 100644
--- a/drivers/media/video/uvc/uvc_isight.c
+++ b/drivers/media/video/uvc/uvc_isight.c
@@ -99,7 +99,7 @@ static int isight_decode(struct uvc_video_queue *queue, struct uvc_buffer *buf,
99 return 0; 99 return 0;
100} 100}
101 101
102void uvc_video_decode_isight(struct urb *urb, struct uvc_video_device *video, 102void uvc_video_decode_isight(struct urb *urb, struct uvc_streaming *stream,
103 struct uvc_buffer *buf) 103 struct uvc_buffer *buf)
104{ 104{
105 int ret, i; 105 int ret, i;
@@ -120,7 +120,7 @@ void uvc_video_decode_isight(struct urb *urb, struct uvc_video_device *video,
120 * processes the data of the first payload of the new frame. 120 * processes the data of the first payload of the new frame.
121 */ 121 */
122 do { 122 do {
123 ret = isight_decode(&video->queue, buf, 123 ret = isight_decode(&stream->queue, buf,
124 urb->transfer_buffer + 124 urb->transfer_buffer +
125 urb->iso_frame_desc[i].offset, 125 urb->iso_frame_desc[i].offset,
126 urb->iso_frame_desc[i].actual_length); 126 urb->iso_frame_desc[i].actual_length);
@@ -130,7 +130,8 @@ void uvc_video_decode_isight(struct urb *urb, struct uvc_video_device *video,
130 130
131 if (buf->state == UVC_BUF_STATE_DONE || 131 if (buf->state == UVC_BUF_STATE_DONE ||
132 buf->state == UVC_BUF_STATE_ERROR) 132 buf->state == UVC_BUF_STATE_ERROR)
133 buf = uvc_queue_next_buffer(&video->queue, buf); 133 buf = uvc_queue_next_buffer(&stream->queue,
134 buf);
134 } while (ret == -EAGAIN); 135 } while (ret == -EAGAIN);
135 } 136 }
136} 137}
diff --git a/drivers/media/video/uvc/uvc_v4l2.c b/drivers/media/video/uvc/uvc_v4l2.c
index 5e77cad29690..9e7351569b5d 100644
--- a/drivers/media/video/uvc/uvc_v4l2.c
+++ b/drivers/media/video/uvc/uvc_v4l2.c
@@ -40,7 +40,7 @@
40 * table for the controls that can be mapped directly, and handle the others 40 * table for the controls that can be mapped directly, and handle the others
41 * manually. 41 * manually.
42 */ 42 */
43static int uvc_v4l2_query_menu(struct uvc_video_device *video, 43static int uvc_v4l2_query_menu(struct uvc_video_chain *chain,
44 struct v4l2_querymenu *query_menu) 44 struct v4l2_querymenu *query_menu)
45{ 45{
46 struct uvc_menu_info *menu_info; 46 struct uvc_menu_info *menu_info;
@@ -49,7 +49,7 @@ static int uvc_v4l2_query_menu(struct uvc_video_device *video,
49 u32 index = query_menu->index; 49 u32 index = query_menu->index;
50 u32 id = query_menu->id; 50 u32 id = query_menu->id;
51 51
52 ctrl = uvc_find_control(video, query_menu->id, &mapping); 52 ctrl = uvc_find_control(chain, query_menu->id, &mapping);
53 if (ctrl == NULL || mapping->v4l2_type != V4L2_CTRL_TYPE_MENU) 53 if (ctrl == NULL || mapping->v4l2_type != V4L2_CTRL_TYPE_MENU)
54 return -EINVAL; 54 return -EINVAL;
55 55
@@ -103,7 +103,7 @@ static __u32 uvc_try_frame_interval(struct uvc_frame *frame, __u32 interval)
103 return interval; 103 return interval;
104} 104}
105 105
106static int uvc_v4l2_try_format(struct uvc_video_device *video, 106static int uvc_v4l2_try_format(struct uvc_streaming *stream,
107 struct v4l2_format *fmt, struct uvc_streaming_control *probe, 107 struct v4l2_format *fmt, struct uvc_streaming_control *probe,
108 struct uvc_format **uvc_format, struct uvc_frame **uvc_frame) 108 struct uvc_format **uvc_format, struct uvc_frame **uvc_frame)
109{ 109{
@@ -116,7 +116,7 @@ static int uvc_v4l2_try_format(struct uvc_video_device *video,
116 int ret = 0; 116 int ret = 0;
117 __u8 *fcc; 117 __u8 *fcc;
118 118
119 if (fmt->type != video->streaming->type) 119 if (fmt->type != stream->type)
120 return -EINVAL; 120 return -EINVAL;
121 121
122 fcc = (__u8 *)&fmt->fmt.pix.pixelformat; 122 fcc = (__u8 *)&fmt->fmt.pix.pixelformat;
@@ -126,8 +126,8 @@ static int uvc_v4l2_try_format(struct uvc_video_device *video,
126 fmt->fmt.pix.width, fmt->fmt.pix.height); 126 fmt->fmt.pix.width, fmt->fmt.pix.height);
127 127
128 /* Check if the hardware supports the requested format. */ 128 /* Check if the hardware supports the requested format. */
129 for (i = 0; i < video->streaming->nformats; ++i) { 129 for (i = 0; i < stream->nformats; ++i) {
130 format = &video->streaming->format[i]; 130 format = &stream->format[i];
131 if (format->fcc == fmt->fmt.pix.pixelformat) 131 if (format->fcc == fmt->fmt.pix.pixelformat)
132 break; 132 break;
133 } 133 }
@@ -191,12 +191,13 @@ static int uvc_v4l2_try_format(struct uvc_video_device *video,
191 * developers test their webcams with the Linux driver as well as with 191 * developers test their webcams with the Linux driver as well as with
192 * the Windows driver). 192 * the Windows driver).
193 */ 193 */
194 if (video->dev->quirks & UVC_QUIRK_PROBE_EXTRAFIELDS) 194 if (stream->dev->quirks & UVC_QUIRK_PROBE_EXTRAFIELDS)
195 probe->dwMaxVideoFrameSize = 195 probe->dwMaxVideoFrameSize =
196 video->streaming->ctrl.dwMaxVideoFrameSize; 196 stream->ctrl.dwMaxVideoFrameSize;
197 197
198 /* Probe the device. */ 198 /* Probe the device. */
199 if ((ret = uvc_probe_video(video, probe)) < 0) 199 ret = uvc_probe_video(stream, probe);
200 if (ret < 0)
200 goto done; 201 goto done;
201 202
202 fmt->fmt.pix.width = frame->wWidth; 203 fmt->fmt.pix.width = frame->wWidth;
@@ -216,13 +217,13 @@ done:
216 return ret; 217 return ret;
217} 218}
218 219
219static int uvc_v4l2_get_format(struct uvc_video_device *video, 220static int uvc_v4l2_get_format(struct uvc_streaming *stream,
220 struct v4l2_format *fmt) 221 struct v4l2_format *fmt)
221{ 222{
222 struct uvc_format *format = video->streaming->cur_format; 223 struct uvc_format *format = stream->cur_format;
223 struct uvc_frame *frame = video->streaming->cur_frame; 224 struct uvc_frame *frame = stream->cur_frame;
224 225
225 if (fmt->type != video->streaming->type) 226 if (fmt->type != stream->type)
226 return -EINVAL; 227 return -EINVAL;
227 228
228 if (format == NULL || frame == NULL) 229 if (format == NULL || frame == NULL)
@@ -233,14 +234,14 @@ static int uvc_v4l2_get_format(struct uvc_video_device *video,
233 fmt->fmt.pix.height = frame->wHeight; 234 fmt->fmt.pix.height = frame->wHeight;
234 fmt->fmt.pix.field = V4L2_FIELD_NONE; 235 fmt->fmt.pix.field = V4L2_FIELD_NONE;
235 fmt->fmt.pix.bytesperline = format->bpp * frame->wWidth / 8; 236 fmt->fmt.pix.bytesperline = format->bpp * frame->wWidth / 8;
236 fmt->fmt.pix.sizeimage = video->streaming->ctrl.dwMaxVideoFrameSize; 237 fmt->fmt.pix.sizeimage = stream->ctrl.dwMaxVideoFrameSize;
237 fmt->fmt.pix.colorspace = format->colorspace; 238 fmt->fmt.pix.colorspace = format->colorspace;
238 fmt->fmt.pix.priv = 0; 239 fmt->fmt.pix.priv = 0;
239 240
240 return 0; 241 return 0;
241} 242}
242 243
243static int uvc_v4l2_set_format(struct uvc_video_device *video, 244static int uvc_v4l2_set_format(struct uvc_streaming *stream,
244 struct v4l2_format *fmt) 245 struct v4l2_format *fmt)
245{ 246{
246 struct uvc_streaming_control probe; 247 struct uvc_streaming_control probe;
@@ -248,39 +249,39 @@ static int uvc_v4l2_set_format(struct uvc_video_device *video,
248 struct uvc_frame *frame; 249 struct uvc_frame *frame;
249 int ret; 250 int ret;
250 251
251 if (fmt->type != video->streaming->type) 252 if (fmt->type != stream->type)
252 return -EINVAL; 253 return -EINVAL;
253 254
254 if (uvc_queue_allocated(&video->queue)) 255 if (uvc_queue_allocated(&stream->queue))
255 return -EBUSY; 256 return -EBUSY;
256 257
257 ret = uvc_v4l2_try_format(video, fmt, &probe, &format, &frame); 258 ret = uvc_v4l2_try_format(stream, fmt, &probe, &format, &frame);
258 if (ret < 0) 259 if (ret < 0)
259 return ret; 260 return ret;
260 261
261 memcpy(&video->streaming->ctrl, &probe, sizeof probe); 262 memcpy(&stream->ctrl, &probe, sizeof probe);
262 video->streaming->cur_format = format; 263 stream->cur_format = format;
263 video->streaming->cur_frame = frame; 264 stream->cur_frame = frame;
264 265
265 return 0; 266 return 0;
266} 267}
267 268
268static int uvc_v4l2_get_streamparm(struct uvc_video_device *video, 269static int uvc_v4l2_get_streamparm(struct uvc_streaming *stream,
269 struct v4l2_streamparm *parm) 270 struct v4l2_streamparm *parm)
270{ 271{
271 uint32_t numerator, denominator; 272 uint32_t numerator, denominator;
272 273
273 if (parm->type != video->streaming->type) 274 if (parm->type != stream->type)
274 return -EINVAL; 275 return -EINVAL;
275 276
276 numerator = video->streaming->ctrl.dwFrameInterval; 277 numerator = stream->ctrl.dwFrameInterval;
277 denominator = 10000000; 278 denominator = 10000000;
278 uvc_simplify_fraction(&numerator, &denominator, 8, 333); 279 uvc_simplify_fraction(&numerator, &denominator, 8, 333);
279 280
280 memset(parm, 0, sizeof *parm); 281 memset(parm, 0, sizeof *parm);
281 parm->type = video->streaming->type; 282 parm->type = stream->type;
282 283
283 if (video->streaming->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { 284 if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
284 parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; 285 parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
285 parm->parm.capture.capturemode = 0; 286 parm->parm.capture.capturemode = 0;
286 parm->parm.capture.timeperframe.numerator = numerator; 287 parm->parm.capture.timeperframe.numerator = numerator;
@@ -297,19 +298,19 @@ static int uvc_v4l2_get_streamparm(struct uvc_video_device *video,
297 return 0; 298 return 0;
298} 299}
299 300
300static int uvc_v4l2_set_streamparm(struct uvc_video_device *video, 301static int uvc_v4l2_set_streamparm(struct uvc_streaming *stream,
301 struct v4l2_streamparm *parm) 302 struct v4l2_streamparm *parm)
302{ 303{
303 struct uvc_frame *frame = video->streaming->cur_frame; 304 struct uvc_frame *frame = stream->cur_frame;
304 struct uvc_streaming_control probe; 305 struct uvc_streaming_control probe;
305 struct v4l2_fract timeperframe; 306 struct v4l2_fract timeperframe;
306 uint32_t interval; 307 uint32_t interval;
307 int ret; 308 int ret;
308 309
309 if (parm->type != video->streaming->type) 310 if (parm->type != stream->type)
310 return -EINVAL; 311 return -EINVAL;
311 312
312 if (uvc_queue_streaming(&video->queue)) 313 if (uvc_queue_streaming(&stream->queue))
313 return -EBUSY; 314 return -EBUSY;
314 315
315 if (parm->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) 316 if (parm->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
@@ -317,7 +318,7 @@ static int uvc_v4l2_set_streamparm(struct uvc_video_device *video,
317 else 318 else
318 timeperframe = parm->parm.output.timeperframe; 319 timeperframe = parm->parm.output.timeperframe;
319 320
320 memcpy(&probe, &video->streaming->ctrl, sizeof probe); 321 memcpy(&probe, &stream->ctrl, sizeof probe);
321 interval = uvc_fraction_to_interval(timeperframe.numerator, 322 interval = uvc_fraction_to_interval(timeperframe.numerator,
322 timeperframe.denominator); 323 timeperframe.denominator);
323 324
@@ -326,10 +327,11 @@ static int uvc_v4l2_set_streamparm(struct uvc_video_device *video,
326 probe.dwFrameInterval = uvc_try_frame_interval(frame, interval); 327 probe.dwFrameInterval = uvc_try_frame_interval(frame, interval);
327 328
328 /* Probe the device with the new settings. */ 329 /* Probe the device with the new settings. */
329 if ((ret = uvc_probe_video(video, &probe)) < 0) 330 ret = uvc_probe_video(stream, &probe);
331 if (ret < 0)
330 return ret; 332 return ret;
331 333
332 memcpy(&video->streaming->ctrl, &probe, sizeof probe); 334 memcpy(&stream->ctrl, &probe, sizeof probe);
333 335
334 /* Return the actual frame period. */ 336 /* Return the actual frame period. */
335 timeperframe.numerator = probe.dwFrameInterval; 337 timeperframe.numerator = probe.dwFrameInterval;
@@ -382,8 +384,8 @@ static int uvc_acquire_privileges(struct uvc_fh *handle)
382 384
383 /* Check if the device already has a privileged handle. */ 385 /* Check if the device already has a privileged handle. */
384 mutex_lock(&uvc_driver.open_mutex); 386 mutex_lock(&uvc_driver.open_mutex);
385 if (atomic_inc_return(&handle->device->active) != 1) { 387 if (atomic_inc_return(&handle->stream->active) != 1) {
386 atomic_dec(&handle->device->active); 388 atomic_dec(&handle->stream->active);
387 ret = -EBUSY; 389 ret = -EBUSY;
388 goto done; 390 goto done;
389 } 391 }
@@ -398,7 +400,7 @@ done:
398static void uvc_dismiss_privileges(struct uvc_fh *handle) 400static void uvc_dismiss_privileges(struct uvc_fh *handle)
399{ 401{
400 if (handle->state == UVC_HANDLE_ACTIVE) 402 if (handle->state == UVC_HANDLE_ACTIVE)
401 atomic_dec(&handle->device->active); 403 atomic_dec(&handle->stream->active);
402 404
403 handle->state = UVC_HANDLE_PASSIVE; 405 handle->state = UVC_HANDLE_PASSIVE;
404} 406}
@@ -414,45 +416,47 @@ static int uvc_has_privileges(struct uvc_fh *handle)
414 416
415static int uvc_v4l2_open(struct file *file) 417static int uvc_v4l2_open(struct file *file)
416{ 418{
417 struct uvc_video_device *video; 419 struct uvc_streaming *stream;
418 struct uvc_fh *handle; 420 struct uvc_fh *handle;
419 int ret = 0; 421 int ret = 0;
420 422
421 uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_open\n"); 423 uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_open\n");
422 mutex_lock(&uvc_driver.open_mutex); 424 mutex_lock(&uvc_driver.open_mutex);
423 video = video_drvdata(file); 425 stream = video_drvdata(file);
424 426
425 if (video->dev->state & UVC_DEV_DISCONNECTED) { 427 if (stream->dev->state & UVC_DEV_DISCONNECTED) {
426 ret = -ENODEV; 428 ret = -ENODEV;
427 goto done; 429 goto done;
428 } 430 }
429 431
430 ret = usb_autopm_get_interface(video->dev->intf); 432 ret = usb_autopm_get_interface(stream->dev->intf);
431 if (ret < 0) 433 if (ret < 0)
432 goto done; 434 goto done;
433 435
434 /* Create the device handle. */ 436 /* Create the device handle. */
435 handle = kzalloc(sizeof *handle, GFP_KERNEL); 437 handle = kzalloc(sizeof *handle, GFP_KERNEL);
436 if (handle == NULL) { 438 if (handle == NULL) {
437 usb_autopm_put_interface(video->dev->intf); 439 usb_autopm_put_interface(stream->dev->intf);
438 ret = -ENOMEM; 440 ret = -ENOMEM;
439 goto done; 441 goto done;
440 } 442 }
441 443
442 if (atomic_inc_return(&video->dev->users) == 1) { 444 if (atomic_inc_return(&stream->dev->users) == 1) {
443 if ((ret = uvc_status_start(video->dev)) < 0) { 445 ret = uvc_status_start(stream->dev);
444 usb_autopm_put_interface(video->dev->intf); 446 if (ret < 0) {
445 atomic_dec(&video->dev->users); 447 usb_autopm_put_interface(stream->dev->intf);
448 atomic_dec(&stream->dev->users);
446 kfree(handle); 449 kfree(handle);
447 goto done; 450 goto done;
448 } 451 }
449 } 452 }
450 453
451 handle->device = video; 454 handle->chain = stream->chain;
455 handle->stream = stream;
452 handle->state = UVC_HANDLE_PASSIVE; 456 handle->state = UVC_HANDLE_PASSIVE;
453 file->private_data = handle; 457 file->private_data = handle;
454 458
455 kref_get(&video->dev->kref); 459 kref_get(&stream->dev->kref);
456 460
457done: 461done:
458 mutex_unlock(&uvc_driver.open_mutex); 462 mutex_unlock(&uvc_driver.open_mutex);
@@ -461,20 +465,20 @@ done:
461 465
462static int uvc_v4l2_release(struct file *file) 466static int uvc_v4l2_release(struct file *file)
463{ 467{
464 struct uvc_video_device *video = video_drvdata(file);
465 struct uvc_fh *handle = (struct uvc_fh *)file->private_data; 468 struct uvc_fh *handle = (struct uvc_fh *)file->private_data;
469 struct uvc_streaming *stream = handle->stream;
466 470
467 uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_release\n"); 471 uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_release\n");
468 472
469 /* Only free resources if this is a privileged handle. */ 473 /* Only free resources if this is a privileged handle. */
470 if (uvc_has_privileges(handle)) { 474 if (uvc_has_privileges(handle)) {
471 uvc_video_enable(video, 0); 475 uvc_video_enable(stream, 0);
472 476
473 mutex_lock(&video->queue.mutex); 477 mutex_lock(&stream->queue.mutex);
474 if (uvc_free_buffers(&video->queue) < 0) 478 if (uvc_free_buffers(&stream->queue) < 0)
475 uvc_printk(KERN_ERR, "uvc_v4l2_release: Unable to " 479 uvc_printk(KERN_ERR, "uvc_v4l2_release: Unable to "
476 "free buffers.\n"); 480 "free buffers.\n");
477 mutex_unlock(&video->queue.mutex); 481 mutex_unlock(&stream->queue.mutex);
478 } 482 }
479 483
480 /* Release the file handle. */ 484 /* Release the file handle. */
@@ -482,19 +486,20 @@ static int uvc_v4l2_release(struct file *file)
482 kfree(handle); 486 kfree(handle);
483 file->private_data = NULL; 487 file->private_data = NULL;
484 488
485 if (atomic_dec_return(&video->dev->users) == 0) 489 if (atomic_dec_return(&stream->dev->users) == 0)
486 uvc_status_stop(video->dev); 490 uvc_status_stop(stream->dev);
487 491
488 usb_autopm_put_interface(video->dev->intf); 492 usb_autopm_put_interface(stream->dev->intf);
489 kref_put(&video->dev->kref, uvc_delete); 493 kref_put(&stream->dev->kref, uvc_delete);
490 return 0; 494 return 0;
491} 495}
492 496
493static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) 497static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
494{ 498{
495 struct video_device *vdev = video_devdata(file); 499 struct video_device *vdev = video_devdata(file);
496 struct uvc_video_device *video = video_get_drvdata(vdev);
497 struct uvc_fh *handle = (struct uvc_fh *)file->private_data; 500 struct uvc_fh *handle = (struct uvc_fh *)file->private_data;
501 struct uvc_video_chain *chain = handle->chain;
502 struct uvc_streaming *stream = handle->stream;
498 long ret = 0; 503 long ret = 0;
499 504
500 switch (cmd) { 505 switch (cmd) {
@@ -506,10 +511,10 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
506 memset(cap, 0, sizeof *cap); 511 memset(cap, 0, sizeof *cap);
507 strlcpy(cap->driver, "uvcvideo", sizeof cap->driver); 512 strlcpy(cap->driver, "uvcvideo", sizeof cap->driver);
508 strlcpy(cap->card, vdev->name, sizeof cap->card); 513 strlcpy(cap->card, vdev->name, sizeof cap->card);
509 usb_make_path(video->dev->udev, 514 usb_make_path(stream->dev->udev,
510 cap->bus_info, sizeof(cap->bus_info)); 515 cap->bus_info, sizeof(cap->bus_info));
511 cap->version = DRIVER_VERSION_NUMBER; 516 cap->version = DRIVER_VERSION_NUMBER;
512 if (video->streaming->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) 517 if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
513 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE 518 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE
514 | V4L2_CAP_STREAMING; 519 | V4L2_CAP_STREAMING;
515 else 520 else
@@ -520,7 +525,7 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
520 525
521 /* Get, Set & Query control */ 526 /* Get, Set & Query control */
522 case VIDIOC_QUERYCTRL: 527 case VIDIOC_QUERYCTRL:
523 return uvc_query_v4l2_ctrl(video, arg); 528 return uvc_query_v4l2_ctrl(chain, arg);
524 529
525 case VIDIOC_G_CTRL: 530 case VIDIOC_G_CTRL:
526 { 531 {
@@ -530,12 +535,12 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
530 memset(&xctrl, 0, sizeof xctrl); 535 memset(&xctrl, 0, sizeof xctrl);
531 xctrl.id = ctrl->id; 536 xctrl.id = ctrl->id;
532 537
533 ret = uvc_ctrl_begin(video); 538 ret = uvc_ctrl_begin(chain);
534 if (ret < 0) 539 if (ret < 0)
535 return ret; 540 return ret;
536 541
537 ret = uvc_ctrl_get(video, &xctrl); 542 ret = uvc_ctrl_get(chain, &xctrl);
538 uvc_ctrl_rollback(video); 543 uvc_ctrl_rollback(chain);
539 if (ret >= 0) 544 if (ret >= 0)
540 ctrl->value = xctrl.value; 545 ctrl->value = xctrl.value;
541 break; 546 break;
@@ -550,21 +555,21 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
550 xctrl.id = ctrl->id; 555 xctrl.id = ctrl->id;
551 xctrl.value = ctrl->value; 556 xctrl.value = ctrl->value;
552 557
553 ret = uvc_ctrl_begin(video); 558 uvc_ctrl_begin(chain);
554 if (ret < 0) 559 if (ret < 0)
555 return ret; 560 return ret;
556 561
557 ret = uvc_ctrl_set(video, &xctrl); 562 ret = uvc_ctrl_set(chain, &xctrl);
558 if (ret < 0) { 563 if (ret < 0) {
559 uvc_ctrl_rollback(video); 564 uvc_ctrl_rollback(chain);
560 return ret; 565 return ret;
561 } 566 }
562 ret = uvc_ctrl_commit(video); 567 ret = uvc_ctrl_commit(chain);
563 break; 568 break;
564 } 569 }
565 570
566 case VIDIOC_QUERYMENU: 571 case VIDIOC_QUERYMENU:
567 return uvc_v4l2_query_menu(video, arg); 572 return uvc_v4l2_query_menu(chain, arg);
568 573
569 case VIDIOC_G_EXT_CTRLS: 574 case VIDIOC_G_EXT_CTRLS:
570 { 575 {
@@ -572,20 +577,20 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
572 struct v4l2_ext_control *ctrl = ctrls->controls; 577 struct v4l2_ext_control *ctrl = ctrls->controls;
573 unsigned int i; 578 unsigned int i;
574 579
575 ret = uvc_ctrl_begin(video); 580 ret = uvc_ctrl_begin(chain);
576 if (ret < 0) 581 if (ret < 0)
577 return ret; 582 return ret;
578 583
579 for (i = 0; i < ctrls->count; ++ctrl, ++i) { 584 for (i = 0; i < ctrls->count; ++ctrl, ++i) {
580 ret = uvc_ctrl_get(video, ctrl); 585 ret = uvc_ctrl_get(chain, ctrl);
581 if (ret < 0) { 586 if (ret < 0) {
582 uvc_ctrl_rollback(video); 587 uvc_ctrl_rollback(chain);
583 ctrls->error_idx = i; 588 ctrls->error_idx = i;
584 return ret; 589 return ret;
585 } 590 }
586 } 591 }
587 ctrls->error_idx = 0; 592 ctrls->error_idx = 0;
588 ret = uvc_ctrl_rollback(video); 593 ret = uvc_ctrl_rollback(chain);
589 break; 594 break;
590 } 595 }
591 596
@@ -596,14 +601,14 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
596 struct v4l2_ext_control *ctrl = ctrls->controls; 601 struct v4l2_ext_control *ctrl = ctrls->controls;
597 unsigned int i; 602 unsigned int i;
598 603
599 ret = uvc_ctrl_begin(video); 604 ret = uvc_ctrl_begin(chain);
600 if (ret < 0) 605 if (ret < 0)
601 return ret; 606 return ret;
602 607
603 for (i = 0; i < ctrls->count; ++ctrl, ++i) { 608 for (i = 0; i < ctrls->count; ++ctrl, ++i) {
604 ret = uvc_ctrl_set(video, ctrl); 609 ret = uvc_ctrl_set(chain, ctrl);
605 if (ret < 0) { 610 if (ret < 0) {
606 uvc_ctrl_rollback(video); 611 uvc_ctrl_rollback(chain);
607 ctrls->error_idx = i; 612 ctrls->error_idx = i;
608 return ret; 613 return ret;
609 } 614 }
@@ -612,31 +617,31 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
612 ctrls->error_idx = 0; 617 ctrls->error_idx = 0;
613 618
614 if (cmd == VIDIOC_S_EXT_CTRLS) 619 if (cmd == VIDIOC_S_EXT_CTRLS)
615 ret = uvc_ctrl_commit(video); 620 ret = uvc_ctrl_commit(chain);
616 else 621 else
617 ret = uvc_ctrl_rollback(video); 622 ret = uvc_ctrl_rollback(chain);
618 break; 623 break;
619 } 624 }
620 625
621 /* Get, Set & Enum input */ 626 /* Get, Set & Enum input */
622 case VIDIOC_ENUMINPUT: 627 case VIDIOC_ENUMINPUT:
623 { 628 {
624 const struct uvc_entity *selector = video->selector; 629 const struct uvc_entity *selector = chain->selector;
625 struct v4l2_input *input = arg; 630 struct v4l2_input *input = arg;
626 struct uvc_entity *iterm = NULL; 631 struct uvc_entity *iterm = NULL;
627 u32 index = input->index; 632 u32 index = input->index;
628 int pin = 0; 633 int pin = 0;
629 634
630 if (selector == NULL || 635 if (selector == NULL ||
631 (video->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) { 636 (chain->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) {
632 if (index != 0) 637 if (index != 0)
633 return -EINVAL; 638 return -EINVAL;
634 iterm = list_first_entry(&video->iterms, 639 iterm = list_first_entry(&chain->iterms,
635 struct uvc_entity, chain); 640 struct uvc_entity, chain);
636 pin = iterm->id; 641 pin = iterm->id;
637 } else if (pin < selector->selector.bNrInPins) { 642 } else if (pin < selector->selector.bNrInPins) {
638 pin = selector->selector.baSourceID[index]; 643 pin = selector->selector.baSourceID[index];
639 list_for_each_entry(iterm, video->iterms.next, chain) { 644 list_for_each_entry(iterm, chain->iterms.next, chain) {
640 if (iterm->id == pin) 645 if (iterm->id == pin)
641 break; 646 break;
642 } 647 }
@@ -648,7 +653,7 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
648 memset(input, 0, sizeof *input); 653 memset(input, 0, sizeof *input);
649 input->index = index; 654 input->index = index;
650 strlcpy(input->name, iterm->name, sizeof input->name); 655 strlcpy(input->name, iterm->name, sizeof input->name);
651 if (UVC_ENTITY_TYPE(iterm) == ITT_CAMERA) 656 if (UVC_ENTITY_TYPE(iterm) == UVC_ITT_CAMERA)
652 input->type = V4L2_INPUT_TYPE_CAMERA; 657 input->type = V4L2_INPUT_TYPE_CAMERA;
653 break; 658 break;
654 } 659 }
@@ -657,15 +662,15 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
657 { 662 {
658 u8 input; 663 u8 input;
659 664
660 if (video->selector == NULL || 665 if (chain->selector == NULL ||
661 (video->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) { 666 (chain->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) {
662 *(int *)arg = 0; 667 *(int *)arg = 0;
663 break; 668 break;
664 } 669 }
665 670
666 ret = uvc_query_ctrl(video->dev, GET_CUR, video->selector->id, 671 ret = uvc_query_ctrl(chain->dev, UVC_GET_CUR,
667 video->dev->intfnum, SU_INPUT_SELECT_CONTROL, 672 chain->selector->id, chain->dev->intfnum,
668 &input, 1); 673 UVC_SU_INPUT_SELECT_CONTROL, &input, 1);
669 if (ret < 0) 674 if (ret < 0)
670 return ret; 675 return ret;
671 676
@@ -680,19 +685,19 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
680 if ((ret = uvc_acquire_privileges(handle)) < 0) 685 if ((ret = uvc_acquire_privileges(handle)) < 0)
681 return ret; 686 return ret;
682 687
683 if (video->selector == NULL || 688 if (chain->selector == NULL ||
684 (video->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) { 689 (chain->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) {
685 if (input != 1) 690 if (input != 1)
686 return -EINVAL; 691 return -EINVAL;
687 break; 692 break;
688 } 693 }
689 694
690 if (input == 0 || input > video->selector->selector.bNrInPins) 695 if (input == 0 || input > chain->selector->selector.bNrInPins)
691 return -EINVAL; 696 return -EINVAL;
692 697
693 return uvc_query_ctrl(video->dev, SET_CUR, video->selector->id, 698 return uvc_query_ctrl(chain->dev, UVC_SET_CUR,
694 video->dev->intfnum, SU_INPUT_SELECT_CONTROL, 699 chain->selector->id, chain->dev->intfnum,
695 &input, 1); 700 UVC_SU_INPUT_SELECT_CONTROL, &input, 1);
696 } 701 }
697 702
698 /* Try, Get, Set & Enum format */ 703 /* Try, Get, Set & Enum format */
@@ -703,15 +708,15 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
703 enum v4l2_buf_type type = fmt->type; 708 enum v4l2_buf_type type = fmt->type;
704 __u32 index = fmt->index; 709 __u32 index = fmt->index;
705 710
706 if (fmt->type != video->streaming->type || 711 if (fmt->type != stream->type ||
707 fmt->index >= video->streaming->nformats) 712 fmt->index >= stream->nformats)
708 return -EINVAL; 713 return -EINVAL;
709 714
710 memset(fmt, 0, sizeof(*fmt)); 715 memset(fmt, 0, sizeof(*fmt));
711 fmt->index = index; 716 fmt->index = index;
712 fmt->type = type; 717 fmt->type = type;
713 718
714 format = &video->streaming->format[fmt->index]; 719 format = &stream->format[fmt->index];
715 fmt->flags = 0; 720 fmt->flags = 0;
716 if (format->flags & UVC_FMT_FLAG_COMPRESSED) 721 if (format->flags & UVC_FMT_FLAG_COMPRESSED)
717 fmt->flags |= V4L2_FMT_FLAG_COMPRESSED; 722 fmt->flags |= V4L2_FMT_FLAG_COMPRESSED;
@@ -729,17 +734,17 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
729 if ((ret = uvc_acquire_privileges(handle)) < 0) 734 if ((ret = uvc_acquire_privileges(handle)) < 0)
730 return ret; 735 return ret;
731 736
732 return uvc_v4l2_try_format(video, arg, &probe, NULL, NULL); 737 return uvc_v4l2_try_format(stream, arg, &probe, NULL, NULL);
733 } 738 }
734 739
735 case VIDIOC_S_FMT: 740 case VIDIOC_S_FMT:
736 if ((ret = uvc_acquire_privileges(handle)) < 0) 741 if ((ret = uvc_acquire_privileges(handle)) < 0)
737 return ret; 742 return ret;
738 743
739 return uvc_v4l2_set_format(video, arg); 744 return uvc_v4l2_set_format(stream, arg);
740 745
741 case VIDIOC_G_FMT: 746 case VIDIOC_G_FMT:
742 return uvc_v4l2_get_format(video, arg); 747 return uvc_v4l2_get_format(stream, arg);
743 748
744 /* Frame size enumeration */ 749 /* Frame size enumeration */
745 case VIDIOC_ENUM_FRAMESIZES: 750 case VIDIOC_ENUM_FRAMESIZES:
@@ -750,10 +755,10 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
750 int i; 755 int i;
751 756
752 /* Look for the given pixel format */ 757 /* Look for the given pixel format */
753 for (i = 0; i < video->streaming->nformats; i++) { 758 for (i = 0; i < stream->nformats; i++) {
754 if (video->streaming->format[i].fcc == 759 if (stream->format[i].fcc ==
755 fsize->pixel_format) { 760 fsize->pixel_format) {
756 format = &video->streaming->format[i]; 761 format = &stream->format[i];
757 break; 762 break;
758 } 763 }
759 } 764 }
@@ -779,10 +784,10 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
779 int i; 784 int i;
780 785
781 /* Look for the given pixel format and frame size */ 786 /* Look for the given pixel format and frame size */
782 for (i = 0; i < video->streaming->nformats; i++) { 787 for (i = 0; i < stream->nformats; i++) {
783 if (video->streaming->format[i].fcc == 788 if (stream->format[i].fcc ==
784 fival->pixel_format) { 789 fival->pixel_format) {
785 format = &video->streaming->format[i]; 790 format = &stream->format[i];
786 break; 791 break;
787 } 792 }
788 } 793 }
@@ -832,21 +837,21 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
832 837
833 /* Get & Set streaming parameters */ 838 /* Get & Set streaming parameters */
834 case VIDIOC_G_PARM: 839 case VIDIOC_G_PARM:
835 return uvc_v4l2_get_streamparm(video, arg); 840 return uvc_v4l2_get_streamparm(stream, arg);
836 841
837 case VIDIOC_S_PARM: 842 case VIDIOC_S_PARM:
838 if ((ret = uvc_acquire_privileges(handle)) < 0) 843 if ((ret = uvc_acquire_privileges(handle)) < 0)
839 return ret; 844 return ret;
840 845
841 return uvc_v4l2_set_streamparm(video, arg); 846 return uvc_v4l2_set_streamparm(stream, arg);
842 847
843 /* Cropping and scaling */ 848 /* Cropping and scaling */
844 case VIDIOC_CROPCAP: 849 case VIDIOC_CROPCAP:
845 { 850 {
846 struct v4l2_cropcap *ccap = arg; 851 struct v4l2_cropcap *ccap = arg;
847 struct uvc_frame *frame = video->streaming->cur_frame; 852 struct uvc_frame *frame = stream->cur_frame;
848 853
849 if (ccap->type != video->streaming->type) 854 if (ccap->type != stream->type)
850 return -EINVAL; 855 return -EINVAL;
851 856
852 ccap->bounds.left = 0; 857 ccap->bounds.left = 0;
@@ -870,16 +875,16 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
870 { 875 {
871 struct v4l2_requestbuffers *rb = arg; 876 struct v4l2_requestbuffers *rb = arg;
872 unsigned int bufsize = 877 unsigned int bufsize =
873 video->streaming->ctrl.dwMaxVideoFrameSize; 878 stream->ctrl.dwMaxVideoFrameSize;
874 879
875 if (rb->type != video->streaming->type || 880 if (rb->type != stream->type ||
876 rb->memory != V4L2_MEMORY_MMAP) 881 rb->memory != V4L2_MEMORY_MMAP)
877 return -EINVAL; 882 return -EINVAL;
878 883
879 if ((ret = uvc_acquire_privileges(handle)) < 0) 884 if ((ret = uvc_acquire_privileges(handle)) < 0)
880 return ret; 885 return ret;
881 886
882 ret = uvc_alloc_buffers(&video->queue, rb->count, bufsize); 887 ret = uvc_alloc_buffers(&stream->queue, rb->count, bufsize);
883 if (ret < 0) 888 if (ret < 0)
884 return ret; 889 return ret;
885 890
@@ -892,39 +897,40 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
892 { 897 {
893 struct v4l2_buffer *buf = arg; 898 struct v4l2_buffer *buf = arg;
894 899
895 if (buf->type != video->streaming->type) 900 if (buf->type != stream->type)
896 return -EINVAL; 901 return -EINVAL;
897 902
898 if (!uvc_has_privileges(handle)) 903 if (!uvc_has_privileges(handle))
899 return -EBUSY; 904 return -EBUSY;
900 905
901 return uvc_query_buffer(&video->queue, buf); 906 return uvc_query_buffer(&stream->queue, buf);
902 } 907 }
903 908
904 case VIDIOC_QBUF: 909 case VIDIOC_QBUF:
905 if (!uvc_has_privileges(handle)) 910 if (!uvc_has_privileges(handle))
906 return -EBUSY; 911 return -EBUSY;
907 912
908 return uvc_queue_buffer(&video->queue, arg); 913 return uvc_queue_buffer(&stream->queue, arg);
909 914
910 case VIDIOC_DQBUF: 915 case VIDIOC_DQBUF:
911 if (!uvc_has_privileges(handle)) 916 if (!uvc_has_privileges(handle))
912 return -EBUSY; 917 return -EBUSY;
913 918
914 return uvc_dequeue_buffer(&video->queue, arg, 919 return uvc_dequeue_buffer(&stream->queue, arg,
915 file->f_flags & O_NONBLOCK); 920 file->f_flags & O_NONBLOCK);
916 921
917 case VIDIOC_STREAMON: 922 case VIDIOC_STREAMON:
918 { 923 {
919 int *type = arg; 924 int *type = arg;
920 925
921 if (*type != video->streaming->type) 926 if (*type != stream->type)
922 return -EINVAL; 927 return -EINVAL;
923 928
924 if (!uvc_has_privileges(handle)) 929 if (!uvc_has_privileges(handle))
925 return -EBUSY; 930 return -EBUSY;
926 931
927 if ((ret = uvc_video_enable(video, 1)) < 0) 932 ret = uvc_video_enable(stream, 1);
933 if (ret < 0)
928 return ret; 934 return ret;
929 break; 935 break;
930 } 936 }
@@ -933,13 +939,13 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
933 { 939 {
934 int *type = arg; 940 int *type = arg;
935 941
936 if (*type != video->streaming->type) 942 if (*type != stream->type)
937 return -EINVAL; 943 return -EINVAL;
938 944
939 if (!uvc_has_privileges(handle)) 945 if (!uvc_has_privileges(handle))
940 return -EBUSY; 946 return -EBUSY;
941 947
942 return uvc_video_enable(video, 0); 948 return uvc_video_enable(stream, 0);
943 } 949 }
944 950
945 /* Analog video standards make no sense for digital cameras. */ 951 /* Analog video standards make no sense for digital cameras. */
@@ -1013,10 +1019,10 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
1013 } 1019 }
1014 1020
1015 case UVCIOC_CTRL_GET: 1021 case UVCIOC_CTRL_GET:
1016 return uvc_xu_ctrl_query(video, arg, 0); 1022 return uvc_xu_ctrl_query(chain, arg, 0);
1017 1023
1018 case UVCIOC_CTRL_SET: 1024 case UVCIOC_CTRL_SET:
1019 return uvc_xu_ctrl_query(video, arg, 1); 1025 return uvc_xu_ctrl_query(chain, arg, 1);
1020 1026
1021 default: 1027 default:
1022 if ((ret = v4l_compat_translate_ioctl(file, cmd, arg, 1028 if ((ret = v4l_compat_translate_ioctl(file, cmd, arg,
@@ -1070,7 +1076,9 @@ static struct vm_operations_struct uvc_vm_ops = {
1070 1076
1071static int uvc_v4l2_mmap(struct file *file, struct vm_area_struct *vma) 1077static int uvc_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
1072{ 1078{
1073 struct uvc_video_device *video = video_drvdata(file); 1079 struct uvc_fh *handle = (struct uvc_fh *)file->private_data;
1080 struct uvc_streaming *stream = handle->stream;
1081 struct uvc_video_queue *queue = &stream->queue;
1074 struct uvc_buffer *uninitialized_var(buffer); 1082 struct uvc_buffer *uninitialized_var(buffer);
1075 struct page *page; 1083 struct page *page;
1076 unsigned long addr, start, size; 1084 unsigned long addr, start, size;
@@ -1082,15 +1090,15 @@ static int uvc_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
1082 start = vma->vm_start; 1090 start = vma->vm_start;
1083 size = vma->vm_end - vma->vm_start; 1091 size = vma->vm_end - vma->vm_start;
1084 1092
1085 mutex_lock(&video->queue.mutex); 1093 mutex_lock(&queue->mutex);
1086 1094
1087 for (i = 0; i < video->queue.count; ++i) { 1095 for (i = 0; i < queue->count; ++i) {
1088 buffer = &video->queue.buffer[i]; 1096 buffer = &queue->buffer[i];
1089 if ((buffer->buf.m.offset >> PAGE_SHIFT) == vma->vm_pgoff) 1097 if ((buffer->buf.m.offset >> PAGE_SHIFT) == vma->vm_pgoff)
1090 break; 1098 break;
1091 } 1099 }
1092 1100
1093 if (i == video->queue.count || size != video->queue.buf_size) { 1101 if (i == queue->count || size != queue->buf_size) {
1094 ret = -EINVAL; 1102 ret = -EINVAL;
1095 goto done; 1103 goto done;
1096 } 1104 }
@@ -1101,7 +1109,7 @@ static int uvc_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
1101 */ 1109 */
1102 vma->vm_flags |= VM_IO; 1110 vma->vm_flags |= VM_IO;
1103 1111
1104 addr = (unsigned long)video->queue.mem + buffer->buf.m.offset; 1112 addr = (unsigned long)queue->mem + buffer->buf.m.offset;
1105 while (size > 0) { 1113 while (size > 0) {
1106 page = vmalloc_to_page((void *)addr); 1114 page = vmalloc_to_page((void *)addr);
1107 if ((ret = vm_insert_page(vma, start, page)) < 0) 1115 if ((ret = vm_insert_page(vma, start, page)) < 0)
@@ -1117,17 +1125,18 @@ static int uvc_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
1117 uvc_vm_open(vma); 1125 uvc_vm_open(vma);
1118 1126
1119done: 1127done:
1120 mutex_unlock(&video->queue.mutex); 1128 mutex_unlock(&queue->mutex);
1121 return ret; 1129 return ret;
1122} 1130}
1123 1131
1124static unsigned int uvc_v4l2_poll(struct file *file, poll_table *wait) 1132static unsigned int uvc_v4l2_poll(struct file *file, poll_table *wait)
1125{ 1133{
1126 struct uvc_video_device *video = video_drvdata(file); 1134 struct uvc_fh *handle = (struct uvc_fh *)file->private_data;
1135 struct uvc_streaming *stream = handle->stream;
1127 1136
1128 uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_poll\n"); 1137 uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_poll\n");
1129 1138
1130 return uvc_queue_poll(&video->queue, file, wait); 1139 return uvc_queue_poll(&stream->queue, file, wait);
1131} 1140}
1132 1141
1133const struct v4l2_file_operations uvc_fops = { 1142const struct v4l2_file_operations uvc_fops = {
diff --git a/drivers/media/video/uvc/uvc_video.c b/drivers/media/video/uvc/uvc_video.c
index 01b633c73480..5b757f32d997 100644
--- a/drivers/media/video/uvc/uvc_video.c
+++ b/drivers/media/video/uvc/uvc_video.c
@@ -61,7 +61,7 @@ int uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit,
61 return 0; 61 return 0;
62} 62}
63 63
64static void uvc_fixup_video_ctrl(struct uvc_video_device *video, 64static void uvc_fixup_video_ctrl(struct uvc_streaming *stream,
65 struct uvc_streaming_control *ctrl) 65 struct uvc_streaming_control *ctrl)
66{ 66{
67 struct uvc_format *format; 67 struct uvc_format *format;
@@ -69,10 +69,10 @@ static void uvc_fixup_video_ctrl(struct uvc_video_device *video,
69 unsigned int i; 69 unsigned int i;
70 70
71 if (ctrl->bFormatIndex <= 0 || 71 if (ctrl->bFormatIndex <= 0 ||
72 ctrl->bFormatIndex > video->streaming->nformats) 72 ctrl->bFormatIndex > stream->nformats)
73 return; 73 return;
74 74
75 format = &video->streaming->format[ctrl->bFormatIndex - 1]; 75 format = &stream->format[ctrl->bFormatIndex - 1];
76 76
77 for (i = 0; i < format->nframes; ++i) { 77 for (i = 0; i < format->nframes; ++i) {
78 if (format->frame[i].bFrameIndex == ctrl->bFrameIndex) { 78 if (format->frame[i].bFrameIndex == ctrl->bFrameIndex) {
@@ -86,12 +86,12 @@ static void uvc_fixup_video_ctrl(struct uvc_video_device *video,
86 86
87 if (!(format->flags & UVC_FMT_FLAG_COMPRESSED) || 87 if (!(format->flags & UVC_FMT_FLAG_COMPRESSED) ||
88 (ctrl->dwMaxVideoFrameSize == 0 && 88 (ctrl->dwMaxVideoFrameSize == 0 &&
89 video->dev->uvc_version < 0x0110)) 89 stream->dev->uvc_version < 0x0110))
90 ctrl->dwMaxVideoFrameSize = 90 ctrl->dwMaxVideoFrameSize =
91 frame->dwMaxVideoFrameBufferSize; 91 frame->dwMaxVideoFrameBufferSize;
92 92
93 if (video->dev->quirks & UVC_QUIRK_FIX_BANDWIDTH && 93 if (stream->dev->quirks & UVC_QUIRK_FIX_BANDWIDTH &&
94 video->streaming->intf->num_altsetting > 1) { 94 stream->intf->num_altsetting > 1) {
95 u32 interval; 95 u32 interval;
96 u32 bandwidth; 96 u32 bandwidth;
97 97
@@ -108,7 +108,7 @@ static void uvc_fixup_video_ctrl(struct uvc_video_device *video,
108 bandwidth = frame->wWidth * frame->wHeight / 8 * format->bpp; 108 bandwidth = frame->wWidth * frame->wHeight / 8 * format->bpp;
109 bandwidth *= 10000000 / interval + 1; 109 bandwidth *= 10000000 / interval + 1;
110 bandwidth /= 1000; 110 bandwidth /= 1000;
111 if (video->dev->udev->speed == USB_SPEED_HIGH) 111 if (stream->dev->udev->speed == USB_SPEED_HIGH)
112 bandwidth /= 8; 112 bandwidth /= 8;
113 bandwidth += 12; 113 bandwidth += 12;
114 114
@@ -116,40 +116,43 @@ static void uvc_fixup_video_ctrl(struct uvc_video_device *video,
116 } 116 }
117} 117}
118 118
119static int uvc_get_video_ctrl(struct uvc_video_device *video, 119static int uvc_get_video_ctrl(struct uvc_streaming *stream,
120 struct uvc_streaming_control *ctrl, int probe, __u8 query) 120 struct uvc_streaming_control *ctrl, int probe, __u8 query)
121{ 121{
122 __u8 *data; 122 __u8 *data;
123 __u16 size; 123 __u16 size;
124 int ret; 124 int ret;
125 125
126 size = video->dev->uvc_version >= 0x0110 ? 34 : 26; 126 size = stream->dev->uvc_version >= 0x0110 ? 34 : 26;
127 data = kmalloc(size, GFP_KERNEL); 127 data = kmalloc(size, GFP_KERNEL);
128 if (data == NULL) 128 if (data == NULL)
129 return -ENOMEM; 129 return -ENOMEM;
130 130
131 ret = __uvc_query_ctrl(video->dev, query, 0, video->streaming->intfnum, 131 if ((stream->dev->quirks & UVC_QUIRK_PROBE_DEF) && query == UVC_GET_DEF)
132 probe ? VS_PROBE_CONTROL : VS_COMMIT_CONTROL, data, size, 132 return -EIO;
133 UVC_CTRL_STREAMING_TIMEOUT); 133
134 ret = __uvc_query_ctrl(stream->dev, query, 0, stream->intfnum,
135 probe ? UVC_VS_PROBE_CONTROL : UVC_VS_COMMIT_CONTROL, data,
136 size, UVC_CTRL_STREAMING_TIMEOUT);
134 137
135 if ((query == GET_MIN || query == GET_MAX) && ret == 2) { 138 if ((query == UVC_GET_MIN || query == UVC_GET_MAX) && ret == 2) {
136 /* Some cameras, mostly based on Bison Electronics chipsets, 139 /* Some cameras, mostly based on Bison Electronics chipsets,
137 * answer a GET_MIN or GET_MAX request with the wCompQuality 140 * answer a GET_MIN or GET_MAX request with the wCompQuality
138 * field only. 141 * field only.
139 */ 142 */
140 uvc_warn_once(video->dev, UVC_WARN_MINMAX, "UVC non " 143 uvc_warn_once(stream->dev, UVC_WARN_MINMAX, "UVC non "
141 "compliance - GET_MIN/MAX(PROBE) incorrectly " 144 "compliance - GET_MIN/MAX(PROBE) incorrectly "
142 "supported. Enabling workaround.\n"); 145 "supported. Enabling workaround.\n");
143 memset(ctrl, 0, sizeof ctrl); 146 memset(ctrl, 0, sizeof ctrl);
144 ctrl->wCompQuality = le16_to_cpup((__le16 *)data); 147 ctrl->wCompQuality = le16_to_cpup((__le16 *)data);
145 ret = 0; 148 ret = 0;
146 goto out; 149 goto out;
147 } else if (query == GET_DEF && probe == 1 && ret != size) { 150 } else if (query == UVC_GET_DEF && probe == 1 && ret != size) {
148 /* Many cameras don't support the GET_DEF request on their 151 /* Many cameras don't support the GET_DEF request on their
149 * video probe control. Warn once and return, the caller will 152 * video probe control. Warn once and return, the caller will
150 * fall back to GET_CUR. 153 * fall back to GET_CUR.
151 */ 154 */
152 uvc_warn_once(video->dev, UVC_WARN_PROBE_DEF, "UVC non " 155 uvc_warn_once(stream->dev, UVC_WARN_PROBE_DEF, "UVC non "
153 "compliance - GET_DEF(PROBE) not supported. " 156 "compliance - GET_DEF(PROBE) not supported. "
154 "Enabling workaround.\n"); 157 "Enabling workaround.\n");
155 ret = -EIO; 158 ret = -EIO;
@@ -181,7 +184,7 @@ static int uvc_get_video_ctrl(struct uvc_video_device *video,
181 ctrl->bMinVersion = data[32]; 184 ctrl->bMinVersion = data[32];
182 ctrl->bMaxVersion = data[33]; 185 ctrl->bMaxVersion = data[33];
183 } else { 186 } else {
184 ctrl->dwClockFrequency = video->dev->clock_frequency; 187 ctrl->dwClockFrequency = stream->dev->clock_frequency;
185 ctrl->bmFramingInfo = 0; 188 ctrl->bmFramingInfo = 0;
186 ctrl->bPreferedVersion = 0; 189 ctrl->bPreferedVersion = 0;
187 ctrl->bMinVersion = 0; 190 ctrl->bMinVersion = 0;
@@ -192,7 +195,7 @@ static int uvc_get_video_ctrl(struct uvc_video_device *video,
192 * dwMaxPayloadTransferSize fields. Try to get the value from the 195 * dwMaxPayloadTransferSize fields. Try to get the value from the
193 * format and frame descriptors. 196 * format and frame descriptors.
194 */ 197 */
195 uvc_fixup_video_ctrl(video, ctrl); 198 uvc_fixup_video_ctrl(stream, ctrl);
196 ret = 0; 199 ret = 0;
197 200
198out: 201out:
@@ -200,14 +203,14 @@ out:
200 return ret; 203 return ret;
201} 204}
202 205
203static int uvc_set_video_ctrl(struct uvc_video_device *video, 206static int uvc_set_video_ctrl(struct uvc_streaming *stream,
204 struct uvc_streaming_control *ctrl, int probe) 207 struct uvc_streaming_control *ctrl, int probe)
205{ 208{
206 __u8 *data; 209 __u8 *data;
207 __u16 size; 210 __u16 size;
208 int ret; 211 int ret;
209 212
210 size = video->dev->uvc_version >= 0x0110 ? 34 : 26; 213 size = stream->dev->uvc_version >= 0x0110 ? 34 : 26;
211 data = kzalloc(size, GFP_KERNEL); 214 data = kzalloc(size, GFP_KERNEL);
212 if (data == NULL) 215 if (data == NULL)
213 return -ENOMEM; 216 return -ENOMEM;
@@ -232,10 +235,9 @@ static int uvc_set_video_ctrl(struct uvc_video_device *video,
232 data[33] = ctrl->bMaxVersion; 235 data[33] = ctrl->bMaxVersion;
233 } 236 }
234 237
235 ret = __uvc_query_ctrl(video->dev, SET_CUR, 0, 238 ret = __uvc_query_ctrl(stream->dev, UVC_SET_CUR, 0, stream->intfnum,
236 video->streaming->intfnum, 239 probe ? UVC_VS_PROBE_CONTROL : UVC_VS_COMMIT_CONTROL, data,
237 probe ? VS_PROBE_CONTROL : VS_COMMIT_CONTROL, data, size, 240 size, UVC_CTRL_STREAMING_TIMEOUT);
238 UVC_CTRL_STREAMING_TIMEOUT);
239 if (ret != size) { 241 if (ret != size) {
240 uvc_printk(KERN_ERR, "Failed to set UVC %s control : " 242 uvc_printk(KERN_ERR, "Failed to set UVC %s control : "
241 "%d (exp. %u).\n", probe ? "probe" : "commit", 243 "%d (exp. %u).\n", probe ? "probe" : "commit",
@@ -247,7 +249,7 @@ static int uvc_set_video_ctrl(struct uvc_video_device *video,
247 return ret; 249 return ret;
248} 250}
249 251
250int uvc_probe_video(struct uvc_video_device *video, 252int uvc_probe_video(struct uvc_streaming *stream,
251 struct uvc_streaming_control *probe) 253 struct uvc_streaming_control *probe)
252{ 254{
253 struct uvc_streaming_control probe_min, probe_max; 255 struct uvc_streaming_control probe_min, probe_max;
@@ -255,7 +257,7 @@ int uvc_probe_video(struct uvc_video_device *video,
255 unsigned int i; 257 unsigned int i;
256 int ret; 258 int ret;
257 259
258 mutex_lock(&video->streaming->mutex); 260 mutex_lock(&stream->mutex);
259 261
260 /* Perform probing. The device should adjust the requested values 262 /* Perform probing. The device should adjust the requested values
261 * according to its capabilities. However, some devices, namely the 263 * according to its capabilities. However, some devices, namely the
@@ -264,15 +266,16 @@ int uvc_probe_video(struct uvc_video_device *video,
264 * that reason, if the needed bandwidth exceeds the maximum available 266 * that reason, if the needed bandwidth exceeds the maximum available
265 * bandwidth, try to lower the quality. 267 * bandwidth, try to lower the quality.
266 */ 268 */
267 if ((ret = uvc_set_video_ctrl(video, probe, 1)) < 0) 269 ret = uvc_set_video_ctrl(stream, probe, 1);
270 if (ret < 0)
268 goto done; 271 goto done;
269 272
270 /* Get the minimum and maximum values for compression settings. */ 273 /* Get the minimum and maximum values for compression settings. */
271 if (!(video->dev->quirks & UVC_QUIRK_PROBE_MINMAX)) { 274 if (!(stream->dev->quirks & UVC_QUIRK_PROBE_MINMAX)) {
272 ret = uvc_get_video_ctrl(video, &probe_min, 1, GET_MIN); 275 ret = uvc_get_video_ctrl(stream, &probe_min, 1, UVC_GET_MIN);
273 if (ret < 0) 276 if (ret < 0)
274 goto done; 277 goto done;
275 ret = uvc_get_video_ctrl(video, &probe_max, 1, GET_MAX); 278 ret = uvc_get_video_ctrl(stream, &probe_max, 1, UVC_GET_MAX);
276 if (ret < 0) 279 if (ret < 0)
277 goto done; 280 goto done;
278 281
@@ -280,18 +283,21 @@ int uvc_probe_video(struct uvc_video_device *video,
280 } 283 }
281 284
282 for (i = 0; i < 2; ++i) { 285 for (i = 0; i < 2; ++i) {
283 if ((ret = uvc_set_video_ctrl(video, probe, 1)) < 0 || 286 ret = uvc_set_video_ctrl(stream, probe, 1);
284 (ret = uvc_get_video_ctrl(video, probe, 1, GET_CUR)) < 0) 287 if (ret < 0)
288 goto done;
289 ret = uvc_get_video_ctrl(stream, probe, 1, UVC_GET_CUR);
290 if (ret < 0)
285 goto done; 291 goto done;
286 292
287 if (video->streaming->intf->num_altsetting == 1) 293 if (stream->intf->num_altsetting == 1)
288 break; 294 break;
289 295
290 bandwidth = probe->dwMaxPayloadTransferSize; 296 bandwidth = probe->dwMaxPayloadTransferSize;
291 if (bandwidth <= video->streaming->maxpsize) 297 if (bandwidth <= stream->maxpsize)
292 break; 298 break;
293 299
294 if (video->dev->quirks & UVC_QUIRK_PROBE_MINMAX) { 300 if (stream->dev->quirks & UVC_QUIRK_PROBE_MINMAX) {
295 ret = -ENOSPC; 301 ret = -ENOSPC;
296 goto done; 302 goto done;
297 } 303 }
@@ -304,14 +310,14 @@ int uvc_probe_video(struct uvc_video_device *video,
304 } 310 }
305 311
306done: 312done:
307 mutex_unlock(&video->streaming->mutex); 313 mutex_unlock(&stream->mutex);
308 return ret; 314 return ret;
309} 315}
310 316
311int uvc_commit_video(struct uvc_video_device *video, 317int uvc_commit_video(struct uvc_streaming *stream,
312 struct uvc_streaming_control *probe) 318 struct uvc_streaming_control *probe)
313{ 319{
314 return uvc_set_video_ctrl(video, probe, 0); 320 return uvc_set_video_ctrl(stream, probe, 0);
315} 321}
316 322
317/* ------------------------------------------------------------------------ 323/* ------------------------------------------------------------------------
@@ -363,7 +369,7 @@ int uvc_commit_video(struct uvc_video_device *video,
363 * to be called with a NULL buf parameter. uvc_video_decode_data and 369 * to be called with a NULL buf parameter. uvc_video_decode_data and
364 * uvc_video_decode_end will never be called with a NULL buffer. 370 * uvc_video_decode_end will never be called with a NULL buffer.
365 */ 371 */
366static int uvc_video_decode_start(struct uvc_video_device *video, 372static int uvc_video_decode_start(struct uvc_streaming *stream,
367 struct uvc_buffer *buf, const __u8 *data, int len) 373 struct uvc_buffer *buf, const __u8 *data, int len)
368{ 374{
369 __u8 fid; 375 __u8 fid;
@@ -389,25 +395,25 @@ static int uvc_video_decode_start(struct uvc_video_device *video,
389 * NULL. 395 * NULL.
390 */ 396 */
391 if (buf == NULL) { 397 if (buf == NULL) {
392 video->last_fid = fid; 398 stream->last_fid = fid;
393 return -ENODATA; 399 return -ENODATA;
394 } 400 }
395 401
396 /* Synchronize to the input stream by waiting for the FID bit to be 402 /* Synchronize to the input stream by waiting for the FID bit to be
397 * toggled when the the buffer state is not UVC_BUF_STATE_ACTIVE. 403 * toggled when the the buffer state is not UVC_BUF_STATE_ACTIVE.
398 * video->last_fid is initialized to -1, so the first isochronous 404 * stream->last_fid is initialized to -1, so the first isochronous
399 * frame will always be in sync. 405 * frame will always be in sync.
400 * 406 *
401 * If the device doesn't toggle the FID bit, invert video->last_fid 407 * If the device doesn't toggle the FID bit, invert stream->last_fid
402 * when the EOF bit is set to force synchronisation on the next packet. 408 * when the EOF bit is set to force synchronisation on the next packet.
403 */ 409 */
404 if (buf->state != UVC_BUF_STATE_ACTIVE) { 410 if (buf->state != UVC_BUF_STATE_ACTIVE) {
405 if (fid == video->last_fid) { 411 if (fid == stream->last_fid) {
406 uvc_trace(UVC_TRACE_FRAME, "Dropping payload (out of " 412 uvc_trace(UVC_TRACE_FRAME, "Dropping payload (out of "
407 "sync).\n"); 413 "sync).\n");
408 if ((video->dev->quirks & UVC_QUIRK_STREAM_NO_FID) && 414 if ((stream->dev->quirks & UVC_QUIRK_STREAM_NO_FID) &&
409 (data[1] & UVC_STREAM_EOF)) 415 (data[1] & UVC_STREAM_EOF))
410 video->last_fid ^= UVC_STREAM_FID; 416 stream->last_fid ^= UVC_STREAM_FID;
411 return -ENODATA; 417 return -ENODATA;
412 } 418 }
413 419
@@ -422,7 +428,7 @@ static int uvc_video_decode_start(struct uvc_video_device *video,
422 * last payload can be lost anyway). We thus must check if the FID has 428 * last payload can be lost anyway). We thus must check if the FID has
423 * been toggled. 429 * been toggled.
424 * 430 *
425 * video->last_fid is initialized to -1, so the first isochronous 431 * stream->last_fid is initialized to -1, so the first isochronous
426 * frame will never trigger an end of frame detection. 432 * frame will never trigger an end of frame detection.
427 * 433 *
428 * Empty buffers (bytesused == 0) don't trigger end of frame detection 434 * Empty buffers (bytesused == 0) don't trigger end of frame detection
@@ -430,22 +436,22 @@ static int uvc_video_decode_start(struct uvc_video_device *video,
430 * avoids detecting end of frame conditions at FID toggling if the 436 * avoids detecting end of frame conditions at FID toggling if the
431 * previous payload had the EOF bit set. 437 * previous payload had the EOF bit set.
432 */ 438 */
433 if (fid != video->last_fid && buf->buf.bytesused != 0) { 439 if (fid != stream->last_fid && buf->buf.bytesused != 0) {
434 uvc_trace(UVC_TRACE_FRAME, "Frame complete (FID bit " 440 uvc_trace(UVC_TRACE_FRAME, "Frame complete (FID bit "
435 "toggled).\n"); 441 "toggled).\n");
436 buf->state = UVC_BUF_STATE_DONE; 442 buf->state = UVC_BUF_STATE_DONE;
437 return -EAGAIN; 443 return -EAGAIN;
438 } 444 }
439 445
440 video->last_fid = fid; 446 stream->last_fid = fid;
441 447
442 return data[0]; 448 return data[0];
443} 449}
444 450
445static void uvc_video_decode_data(struct uvc_video_device *video, 451static void uvc_video_decode_data(struct uvc_streaming *stream,
446 struct uvc_buffer *buf, const __u8 *data, int len) 452 struct uvc_buffer *buf, const __u8 *data, int len)
447{ 453{
448 struct uvc_video_queue *queue = &video->queue; 454 struct uvc_video_queue *queue = &stream->queue;
449 unsigned int maxlen, nbytes; 455 unsigned int maxlen, nbytes;
450 void *mem; 456 void *mem;
451 457
@@ -466,7 +472,7 @@ static void uvc_video_decode_data(struct uvc_video_device *video,
466 } 472 }
467} 473}
468 474
469static void uvc_video_decode_end(struct uvc_video_device *video, 475static void uvc_video_decode_end(struct uvc_streaming *stream,
470 struct uvc_buffer *buf, const __u8 *data, int len) 476 struct uvc_buffer *buf, const __u8 *data, int len)
471{ 477{
472 /* Mark the buffer as done if the EOF marker is set. */ 478 /* Mark the buffer as done if the EOF marker is set. */
@@ -475,8 +481,8 @@ static void uvc_video_decode_end(struct uvc_video_device *video,
475 if (data[0] == len) 481 if (data[0] == len)
476 uvc_trace(UVC_TRACE_FRAME, "EOF in empty payload.\n"); 482 uvc_trace(UVC_TRACE_FRAME, "EOF in empty payload.\n");
477 buf->state = UVC_BUF_STATE_DONE; 483 buf->state = UVC_BUF_STATE_DONE;
478 if (video->dev->quirks & UVC_QUIRK_STREAM_NO_FID) 484 if (stream->dev->quirks & UVC_QUIRK_STREAM_NO_FID)
479 video->last_fid ^= UVC_STREAM_FID; 485 stream->last_fid ^= UVC_STREAM_FID;
480 } 486 }
481} 487}
482 488
@@ -491,26 +497,26 @@ static void uvc_video_decode_end(struct uvc_video_device *video,
491 * uvc_video_encode_data is called for every URB and copies the data from the 497 * uvc_video_encode_data is called for every URB and copies the data from the
492 * video buffer to the transfer buffer. 498 * video buffer to the transfer buffer.
493 */ 499 */
494static int uvc_video_encode_header(struct uvc_video_device *video, 500static int uvc_video_encode_header(struct uvc_streaming *stream,
495 struct uvc_buffer *buf, __u8 *data, int len) 501 struct uvc_buffer *buf, __u8 *data, int len)
496{ 502{
497 data[0] = 2; /* Header length */ 503 data[0] = 2; /* Header length */
498 data[1] = UVC_STREAM_EOH | UVC_STREAM_EOF 504 data[1] = UVC_STREAM_EOH | UVC_STREAM_EOF
499 | (video->last_fid & UVC_STREAM_FID); 505 | (stream->last_fid & UVC_STREAM_FID);
500 return 2; 506 return 2;
501} 507}
502 508
503static int uvc_video_encode_data(struct uvc_video_device *video, 509static int uvc_video_encode_data(struct uvc_streaming *stream,
504 struct uvc_buffer *buf, __u8 *data, int len) 510 struct uvc_buffer *buf, __u8 *data, int len)
505{ 511{
506 struct uvc_video_queue *queue = &video->queue; 512 struct uvc_video_queue *queue = &stream->queue;
507 unsigned int nbytes; 513 unsigned int nbytes;
508 void *mem; 514 void *mem;
509 515
510 /* Copy video data to the URB buffer. */ 516 /* Copy video data to the URB buffer. */
511 mem = queue->mem + buf->buf.m.offset + queue->buf_used; 517 mem = queue->mem + buf->buf.m.offset + queue->buf_used;
512 nbytes = min((unsigned int)len, buf->buf.bytesused - queue->buf_used); 518 nbytes = min((unsigned int)len, buf->buf.bytesused - queue->buf_used);
513 nbytes = min(video->bulk.max_payload_size - video->bulk.payload_size, 519 nbytes = min(stream->bulk.max_payload_size - stream->bulk.payload_size,
514 nbytes); 520 nbytes);
515 memcpy(data, mem, nbytes); 521 memcpy(data, mem, nbytes);
516 522
@@ -526,8 +532,8 @@ static int uvc_video_encode_data(struct uvc_video_device *video,
526/* 532/*
527 * Completion handler for video URBs. 533 * Completion handler for video URBs.
528 */ 534 */
529static void uvc_video_decode_isoc(struct urb *urb, 535static void uvc_video_decode_isoc(struct urb *urb, struct uvc_streaming *stream,
530 struct uvc_video_device *video, struct uvc_buffer *buf) 536 struct uvc_buffer *buf)
531{ 537{
532 u8 *mem; 538 u8 *mem;
533 int ret, i; 539 int ret, i;
@@ -542,31 +548,32 @@ static void uvc_video_decode_isoc(struct urb *urb,
542 /* Decode the payload header. */ 548 /* Decode the payload header. */
543 mem = urb->transfer_buffer + urb->iso_frame_desc[i].offset; 549 mem = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
544 do { 550 do {
545 ret = uvc_video_decode_start(video, buf, mem, 551 ret = uvc_video_decode_start(stream, buf, mem,
546 urb->iso_frame_desc[i].actual_length); 552 urb->iso_frame_desc[i].actual_length);
547 if (ret == -EAGAIN) 553 if (ret == -EAGAIN)
548 buf = uvc_queue_next_buffer(&video->queue, buf); 554 buf = uvc_queue_next_buffer(&stream->queue,
555 buf);
549 } while (ret == -EAGAIN); 556 } while (ret == -EAGAIN);
550 557
551 if (ret < 0) 558 if (ret < 0)
552 continue; 559 continue;
553 560
554 /* Decode the payload data. */ 561 /* Decode the payload data. */
555 uvc_video_decode_data(video, buf, mem + ret, 562 uvc_video_decode_data(stream, buf, mem + ret,
556 urb->iso_frame_desc[i].actual_length - ret); 563 urb->iso_frame_desc[i].actual_length - ret);
557 564
558 /* Process the header again. */ 565 /* Process the header again. */
559 uvc_video_decode_end(video, buf, mem, 566 uvc_video_decode_end(stream, buf, mem,
560 urb->iso_frame_desc[i].actual_length); 567 urb->iso_frame_desc[i].actual_length);
561 568
562 if (buf->state == UVC_BUF_STATE_DONE || 569 if (buf->state == UVC_BUF_STATE_DONE ||
563 buf->state == UVC_BUF_STATE_ERROR) 570 buf->state == UVC_BUF_STATE_ERROR)
564 buf = uvc_queue_next_buffer(&video->queue, buf); 571 buf = uvc_queue_next_buffer(&stream->queue, buf);
565 } 572 }
566} 573}
567 574
568static void uvc_video_decode_bulk(struct urb *urb, 575static void uvc_video_decode_bulk(struct urb *urb, struct uvc_streaming *stream,
569 struct uvc_video_device *video, struct uvc_buffer *buf) 576 struct uvc_buffer *buf)
570{ 577{
571 u8 *mem; 578 u8 *mem;
572 int len, ret; 579 int len, ret;
@@ -576,24 +583,25 @@ static void uvc_video_decode_bulk(struct urb *urb,
576 583
577 mem = urb->transfer_buffer; 584 mem = urb->transfer_buffer;
578 len = urb->actual_length; 585 len = urb->actual_length;
579 video->bulk.payload_size += len; 586 stream->bulk.payload_size += len;
580 587
581 /* If the URB is the first of its payload, decode and save the 588 /* If the URB is the first of its payload, decode and save the
582 * header. 589 * header.
583 */ 590 */
584 if (video->bulk.header_size == 0 && !video->bulk.skip_payload) { 591 if (stream->bulk.header_size == 0 && !stream->bulk.skip_payload) {
585 do { 592 do {
586 ret = uvc_video_decode_start(video, buf, mem, len); 593 ret = uvc_video_decode_start(stream, buf, mem, len);
587 if (ret == -EAGAIN) 594 if (ret == -EAGAIN)
588 buf = uvc_queue_next_buffer(&video->queue, buf); 595 buf = uvc_queue_next_buffer(&stream->queue,
596 buf);
589 } while (ret == -EAGAIN); 597 } while (ret == -EAGAIN);
590 598
591 /* If an error occured skip the rest of the payload. */ 599 /* If an error occured skip the rest of the payload. */
592 if (ret < 0 || buf == NULL) { 600 if (ret < 0 || buf == NULL) {
593 video->bulk.skip_payload = 1; 601 stream->bulk.skip_payload = 1;
594 } else { 602 } else {
595 memcpy(video->bulk.header, mem, ret); 603 memcpy(stream->bulk.header, mem, ret);
596 video->bulk.header_size = ret; 604 stream->bulk.header_size = ret;
597 605
598 mem += ret; 606 mem += ret;
599 len -= ret; 607 len -= ret;
@@ -606,33 +614,34 @@ static void uvc_video_decode_bulk(struct urb *urb,
606 */ 614 */
607 615
608 /* Process video data. */ 616 /* Process video data. */
609 if (!video->bulk.skip_payload && buf != NULL) 617 if (!stream->bulk.skip_payload && buf != NULL)
610 uvc_video_decode_data(video, buf, mem, len); 618 uvc_video_decode_data(stream, buf, mem, len);
611 619
612 /* Detect the payload end by a URB smaller than the maximum size (or 620 /* Detect the payload end by a URB smaller than the maximum size (or
613 * a payload size equal to the maximum) and process the header again. 621 * a payload size equal to the maximum) and process the header again.
614 */ 622 */
615 if (urb->actual_length < urb->transfer_buffer_length || 623 if (urb->actual_length < urb->transfer_buffer_length ||
616 video->bulk.payload_size >= video->bulk.max_payload_size) { 624 stream->bulk.payload_size >= stream->bulk.max_payload_size) {
617 if (!video->bulk.skip_payload && buf != NULL) { 625 if (!stream->bulk.skip_payload && buf != NULL) {
618 uvc_video_decode_end(video, buf, video->bulk.header, 626 uvc_video_decode_end(stream, buf, stream->bulk.header,
619 video->bulk.payload_size); 627 stream->bulk.payload_size);
620 if (buf->state == UVC_BUF_STATE_DONE || 628 if (buf->state == UVC_BUF_STATE_DONE ||
621 buf->state == UVC_BUF_STATE_ERROR) 629 buf->state == UVC_BUF_STATE_ERROR)
622 buf = uvc_queue_next_buffer(&video->queue, buf); 630 buf = uvc_queue_next_buffer(&stream->queue,
631 buf);
623 } 632 }
624 633
625 video->bulk.header_size = 0; 634 stream->bulk.header_size = 0;
626 video->bulk.skip_payload = 0; 635 stream->bulk.skip_payload = 0;
627 video->bulk.payload_size = 0; 636 stream->bulk.payload_size = 0;
628 } 637 }
629} 638}
630 639
631static void uvc_video_encode_bulk(struct urb *urb, 640static void uvc_video_encode_bulk(struct urb *urb, struct uvc_streaming *stream,
632 struct uvc_video_device *video, struct uvc_buffer *buf) 641 struct uvc_buffer *buf)
633{ 642{
634 u8 *mem = urb->transfer_buffer; 643 u8 *mem = urb->transfer_buffer;
635 int len = video->urb_size, ret; 644 int len = stream->urb_size, ret;
636 645
637 if (buf == NULL) { 646 if (buf == NULL) {
638 urb->transfer_buffer_length = 0; 647 urb->transfer_buffer_length = 0;
@@ -640,40 +649,40 @@ static void uvc_video_encode_bulk(struct urb *urb,
640 } 649 }
641 650
642 /* If the URB is the first of its payload, add the header. */ 651 /* If the URB is the first of its payload, add the header. */
643 if (video->bulk.header_size == 0) { 652 if (stream->bulk.header_size == 0) {
644 ret = uvc_video_encode_header(video, buf, mem, len); 653 ret = uvc_video_encode_header(stream, buf, mem, len);
645 video->bulk.header_size = ret; 654 stream->bulk.header_size = ret;
646 video->bulk.payload_size += ret; 655 stream->bulk.payload_size += ret;
647 mem += ret; 656 mem += ret;
648 len -= ret; 657 len -= ret;
649 } 658 }
650 659
651 /* Process video data. */ 660 /* Process video data. */
652 ret = uvc_video_encode_data(video, buf, mem, len); 661 ret = uvc_video_encode_data(stream, buf, mem, len);
653 662
654 video->bulk.payload_size += ret; 663 stream->bulk.payload_size += ret;
655 len -= ret; 664 len -= ret;
656 665
657 if (buf->buf.bytesused == video->queue.buf_used || 666 if (buf->buf.bytesused == stream->queue.buf_used ||
658 video->bulk.payload_size == video->bulk.max_payload_size) { 667 stream->bulk.payload_size == stream->bulk.max_payload_size) {
659 if (buf->buf.bytesused == video->queue.buf_used) { 668 if (buf->buf.bytesused == stream->queue.buf_used) {
660 video->queue.buf_used = 0; 669 stream->queue.buf_used = 0;
661 buf->state = UVC_BUF_STATE_DONE; 670 buf->state = UVC_BUF_STATE_DONE;
662 uvc_queue_next_buffer(&video->queue, buf); 671 uvc_queue_next_buffer(&stream->queue, buf);
663 video->last_fid ^= UVC_STREAM_FID; 672 stream->last_fid ^= UVC_STREAM_FID;
664 } 673 }
665 674
666 video->bulk.header_size = 0; 675 stream->bulk.header_size = 0;
667 video->bulk.payload_size = 0; 676 stream->bulk.payload_size = 0;
668 } 677 }
669 678
670 urb->transfer_buffer_length = video->urb_size - len; 679 urb->transfer_buffer_length = stream->urb_size - len;
671} 680}
672 681
673static void uvc_video_complete(struct urb *urb) 682static void uvc_video_complete(struct urb *urb)
674{ 683{
675 struct uvc_video_device *video = urb->context; 684 struct uvc_streaming *stream = urb->context;
676 struct uvc_video_queue *queue = &video->queue; 685 struct uvc_video_queue *queue = &stream->queue;
677 struct uvc_buffer *buf = NULL; 686 struct uvc_buffer *buf = NULL;
678 unsigned long flags; 687 unsigned long flags;
679 int ret; 688 int ret;
@@ -687,7 +696,7 @@ static void uvc_video_complete(struct urb *urb)
687 "completion handler.\n", urb->status); 696 "completion handler.\n", urb->status);
688 697
689 case -ENOENT: /* usb_kill_urb() called. */ 698 case -ENOENT: /* usb_kill_urb() called. */
690 if (video->frozen) 699 if (stream->frozen)
691 return; 700 return;
692 701
693 case -ECONNRESET: /* usb_unlink_urb() called. */ 702 case -ECONNRESET: /* usb_unlink_urb() called. */
@@ -702,7 +711,7 @@ static void uvc_video_complete(struct urb *urb)
702 queue); 711 queue);
703 spin_unlock_irqrestore(&queue->irqlock, flags); 712 spin_unlock_irqrestore(&queue->irqlock, flags);
704 713
705 video->decode(urb, video, buf); 714 stream->decode(urb, stream, buf);
706 715
707 if ((ret = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { 716 if ((ret = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
708 uvc_printk(KERN_ERR, "Failed to resubmit video URB (%d).\n", 717 uvc_printk(KERN_ERR, "Failed to resubmit video URB (%d).\n",
@@ -713,19 +722,19 @@ static void uvc_video_complete(struct urb *urb)
713/* 722/*
714 * Free transfer buffers. 723 * Free transfer buffers.
715 */ 724 */
716static void uvc_free_urb_buffers(struct uvc_video_device *video) 725static void uvc_free_urb_buffers(struct uvc_streaming *stream)
717{ 726{
718 unsigned int i; 727 unsigned int i;
719 728
720 for (i = 0; i < UVC_URBS; ++i) { 729 for (i = 0; i < UVC_URBS; ++i) {
721 if (video->urb_buffer[i]) { 730 if (stream->urb_buffer[i]) {
722 usb_buffer_free(video->dev->udev, video->urb_size, 731 usb_buffer_free(stream->dev->udev, stream->urb_size,
723 video->urb_buffer[i], video->urb_dma[i]); 732 stream->urb_buffer[i], stream->urb_dma[i]);
724 video->urb_buffer[i] = NULL; 733 stream->urb_buffer[i] = NULL;
725 } 734 }
726 } 735 }
727 736
728 video->urb_size = 0; 737 stream->urb_size = 0;
729} 738}
730 739
731/* 740/*
@@ -739,15 +748,15 @@ static void uvc_free_urb_buffers(struct uvc_video_device *video)
739 * 748 *
740 * Return the number of allocated packets on success or 0 when out of memory. 749 * Return the number of allocated packets on success or 0 when out of memory.
741 */ 750 */
742static int uvc_alloc_urb_buffers(struct uvc_video_device *video, 751static int uvc_alloc_urb_buffers(struct uvc_streaming *stream,
743 unsigned int size, unsigned int psize, gfp_t gfp_flags) 752 unsigned int size, unsigned int psize, gfp_t gfp_flags)
744{ 753{
745 unsigned int npackets; 754 unsigned int npackets;
746 unsigned int i; 755 unsigned int i;
747 756
748 /* Buffers are already allocated, bail out. */ 757 /* Buffers are already allocated, bail out. */
749 if (video->urb_size) 758 if (stream->urb_size)
750 return video->urb_size / psize; 759 return stream->urb_size / psize;
751 760
752 /* Compute the number of packets. Bulk endpoints might transfer UVC 761 /* Compute the number of packets. Bulk endpoints might transfer UVC
753 * payloads accross multiple URBs. 762 * payloads accross multiple URBs.
@@ -759,17 +768,17 @@ static int uvc_alloc_urb_buffers(struct uvc_video_device *video,
759 /* Retry allocations until one succeed. */ 768 /* Retry allocations until one succeed. */
760 for (; npackets > 1; npackets /= 2) { 769 for (; npackets > 1; npackets /= 2) {
761 for (i = 0; i < UVC_URBS; ++i) { 770 for (i = 0; i < UVC_URBS; ++i) {
762 video->urb_buffer[i] = usb_buffer_alloc( 771 stream->urb_buffer[i] = usb_buffer_alloc(
763 video->dev->udev, psize * npackets, 772 stream->dev->udev, psize * npackets,
764 gfp_flags | __GFP_NOWARN, &video->urb_dma[i]); 773 gfp_flags | __GFP_NOWARN, &stream->urb_dma[i]);
765 if (!video->urb_buffer[i]) { 774 if (!stream->urb_buffer[i]) {
766 uvc_free_urb_buffers(video); 775 uvc_free_urb_buffers(stream);
767 break; 776 break;
768 } 777 }
769 } 778 }
770 779
771 if (i == UVC_URBS) { 780 if (i == UVC_URBS) {
772 video->urb_size = psize * npackets; 781 stream->urb_size = psize * npackets;
773 return npackets; 782 return npackets;
774 } 783 }
775 } 784 }
@@ -780,29 +789,30 @@ static int uvc_alloc_urb_buffers(struct uvc_video_device *video,
780/* 789/*
781 * Uninitialize isochronous/bulk URBs and free transfer buffers. 790 * Uninitialize isochronous/bulk URBs and free transfer buffers.
782 */ 791 */
783static void uvc_uninit_video(struct uvc_video_device *video, int free_buffers) 792static void uvc_uninit_video(struct uvc_streaming *stream, int free_buffers)
784{ 793{
785 struct urb *urb; 794 struct urb *urb;
786 unsigned int i; 795 unsigned int i;
787 796
788 for (i = 0; i < UVC_URBS; ++i) { 797 for (i = 0; i < UVC_URBS; ++i) {
789 if ((urb = video->urb[i]) == NULL) 798 urb = stream->urb[i];
799 if (urb == NULL)
790 continue; 800 continue;
791 801
792 usb_kill_urb(urb); 802 usb_kill_urb(urb);
793 usb_free_urb(urb); 803 usb_free_urb(urb);
794 video->urb[i] = NULL; 804 stream->urb[i] = NULL;
795 } 805 }
796 806
797 if (free_buffers) 807 if (free_buffers)
798 uvc_free_urb_buffers(video); 808 uvc_free_urb_buffers(stream);
799} 809}
800 810
801/* 811/*
802 * Initialize isochronous URBs and allocate transfer buffers. The packet size 812 * Initialize isochronous URBs and allocate transfer buffers. The packet size
803 * is given by the endpoint. 813 * is given by the endpoint.
804 */ 814 */
805static int uvc_init_video_isoc(struct uvc_video_device *video, 815static int uvc_init_video_isoc(struct uvc_streaming *stream,
806 struct usb_host_endpoint *ep, gfp_t gfp_flags) 816 struct usb_host_endpoint *ep, gfp_t gfp_flags)
807{ 817{
808 struct urb *urb; 818 struct urb *urb;
@@ -812,9 +822,9 @@ static int uvc_init_video_isoc(struct uvc_video_device *video,
812 822
813 psize = le16_to_cpu(ep->desc.wMaxPacketSize); 823 psize = le16_to_cpu(ep->desc.wMaxPacketSize);
814 psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3)); 824 psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3));
815 size = video->streaming->ctrl.dwMaxVideoFrameSize; 825 size = stream->ctrl.dwMaxVideoFrameSize;
816 826
817 npackets = uvc_alloc_urb_buffers(video, size, psize, gfp_flags); 827 npackets = uvc_alloc_urb_buffers(stream, size, psize, gfp_flags);
818 if (npackets == 0) 828 if (npackets == 0)
819 return -ENOMEM; 829 return -ENOMEM;
820 830
@@ -823,18 +833,18 @@ static int uvc_init_video_isoc(struct uvc_video_device *video,
823 for (i = 0; i < UVC_URBS; ++i) { 833 for (i = 0; i < UVC_URBS; ++i) {
824 urb = usb_alloc_urb(npackets, gfp_flags); 834 urb = usb_alloc_urb(npackets, gfp_flags);
825 if (urb == NULL) { 835 if (urb == NULL) {
826 uvc_uninit_video(video, 1); 836 uvc_uninit_video(stream, 1);
827 return -ENOMEM; 837 return -ENOMEM;
828 } 838 }
829 839
830 urb->dev = video->dev->udev; 840 urb->dev = stream->dev->udev;
831 urb->context = video; 841 urb->context = stream;
832 urb->pipe = usb_rcvisocpipe(video->dev->udev, 842 urb->pipe = usb_rcvisocpipe(stream->dev->udev,
833 ep->desc.bEndpointAddress); 843 ep->desc.bEndpointAddress);
834 urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; 844 urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
835 urb->interval = ep->desc.bInterval; 845 urb->interval = ep->desc.bInterval;
836 urb->transfer_buffer = video->urb_buffer[i]; 846 urb->transfer_buffer = stream->urb_buffer[i];
837 urb->transfer_dma = video->urb_dma[i]; 847 urb->transfer_dma = stream->urb_dma[i];
838 urb->complete = uvc_video_complete; 848 urb->complete = uvc_video_complete;
839 urb->number_of_packets = npackets; 849 urb->number_of_packets = npackets;
840 urb->transfer_buffer_length = size; 850 urb->transfer_buffer_length = size;
@@ -844,7 +854,7 @@ static int uvc_init_video_isoc(struct uvc_video_device *video,
844 urb->iso_frame_desc[j].length = psize; 854 urb->iso_frame_desc[j].length = psize;
845 } 855 }
846 856
847 video->urb[i] = urb; 857 stream->urb[i] = urb;
848 } 858 }
849 859
850 return 0; 860 return 0;
@@ -854,7 +864,7 @@ static int uvc_init_video_isoc(struct uvc_video_device *video,
854 * Initialize bulk URBs and allocate transfer buffers. The packet size is 864 * Initialize bulk URBs and allocate transfer buffers. The packet size is
855 * given by the endpoint. 865 * given by the endpoint.
856 */ 866 */
857static int uvc_init_video_bulk(struct uvc_video_device *video, 867static int uvc_init_video_bulk(struct uvc_streaming *stream,
858 struct usb_host_endpoint *ep, gfp_t gfp_flags) 868 struct usb_host_endpoint *ep, gfp_t gfp_flags)
859{ 869{
860 struct urb *urb; 870 struct urb *urb;
@@ -863,39 +873,39 @@ static int uvc_init_video_bulk(struct uvc_video_device *video,
863 u32 size; 873 u32 size;
864 874
865 psize = le16_to_cpu(ep->desc.wMaxPacketSize) & 0x07ff; 875 psize = le16_to_cpu(ep->desc.wMaxPacketSize) & 0x07ff;
866 size = video->streaming->ctrl.dwMaxPayloadTransferSize; 876 size = stream->ctrl.dwMaxPayloadTransferSize;
867 video->bulk.max_payload_size = size; 877 stream->bulk.max_payload_size = size;
868 878
869 npackets = uvc_alloc_urb_buffers(video, size, psize, gfp_flags); 879 npackets = uvc_alloc_urb_buffers(stream, size, psize, gfp_flags);
870 if (npackets == 0) 880 if (npackets == 0)
871 return -ENOMEM; 881 return -ENOMEM;
872 882
873 size = npackets * psize; 883 size = npackets * psize;
874 884
875 if (usb_endpoint_dir_in(&ep->desc)) 885 if (usb_endpoint_dir_in(&ep->desc))
876 pipe = usb_rcvbulkpipe(video->dev->udev, 886 pipe = usb_rcvbulkpipe(stream->dev->udev,
877 ep->desc.bEndpointAddress); 887 ep->desc.bEndpointAddress);
878 else 888 else
879 pipe = usb_sndbulkpipe(video->dev->udev, 889 pipe = usb_sndbulkpipe(stream->dev->udev,
880 ep->desc.bEndpointAddress); 890 ep->desc.bEndpointAddress);
881 891
882 if (video->streaming->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) 892 if (stream->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
883 size = 0; 893 size = 0;
884 894
885 for (i = 0; i < UVC_URBS; ++i) { 895 for (i = 0; i < UVC_URBS; ++i) {
886 urb = usb_alloc_urb(0, gfp_flags); 896 urb = usb_alloc_urb(0, gfp_flags);
887 if (urb == NULL) { 897 if (urb == NULL) {
888 uvc_uninit_video(video, 1); 898 uvc_uninit_video(stream, 1);
889 return -ENOMEM; 899 return -ENOMEM;
890 } 900 }
891 901
892 usb_fill_bulk_urb(urb, video->dev->udev, pipe, 902 usb_fill_bulk_urb(urb, stream->dev->udev, pipe,
893 video->urb_buffer[i], size, uvc_video_complete, 903 stream->urb_buffer[i], size, uvc_video_complete,
894 video); 904 stream);
895 urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP; 905 urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
896 urb->transfer_dma = video->urb_dma[i]; 906 urb->transfer_dma = stream->urb_dma[i];
897 907
898 video->urb[i] = urb; 908 stream->urb[i] = urb;
899 } 909 }
900 910
901 return 0; 911 return 0;
@@ -904,35 +914,35 @@ static int uvc_init_video_bulk(struct uvc_video_device *video,
904/* 914/*
905 * Initialize isochronous/bulk URBs and allocate transfer buffers. 915 * Initialize isochronous/bulk URBs and allocate transfer buffers.
906 */ 916 */
907static int uvc_init_video(struct uvc_video_device *video, gfp_t gfp_flags) 917static int uvc_init_video(struct uvc_streaming *stream, gfp_t gfp_flags)
908{ 918{
909 struct usb_interface *intf = video->streaming->intf; 919 struct usb_interface *intf = stream->intf;
910 struct usb_host_interface *alts; 920 struct usb_host_interface *alts;
911 struct usb_host_endpoint *ep = NULL; 921 struct usb_host_endpoint *ep = NULL;
912 int intfnum = video->streaming->intfnum; 922 int intfnum = stream->intfnum;
913 unsigned int bandwidth, psize, i; 923 unsigned int bandwidth, psize, i;
914 int ret; 924 int ret;
915 925
916 video->last_fid = -1; 926 stream->last_fid = -1;
917 video->bulk.header_size = 0; 927 stream->bulk.header_size = 0;
918 video->bulk.skip_payload = 0; 928 stream->bulk.skip_payload = 0;
919 video->bulk.payload_size = 0; 929 stream->bulk.payload_size = 0;
920 930
921 if (intf->num_altsetting > 1) { 931 if (intf->num_altsetting > 1) {
922 /* Isochronous endpoint, select the alternate setting. */ 932 /* Isochronous endpoint, select the alternate setting. */
923 bandwidth = video->streaming->ctrl.dwMaxPayloadTransferSize; 933 bandwidth = stream->ctrl.dwMaxPayloadTransferSize;
924 934
925 if (bandwidth == 0) { 935 if (bandwidth == 0) {
926 uvc_printk(KERN_WARNING, "device %s requested null " 936 uvc_printk(KERN_WARNING, "device %s requested null "
927 "bandwidth, defaulting to lowest.\n", 937 "bandwidth, defaulting to lowest.\n",
928 video->vdev->name); 938 stream->dev->name);
929 bandwidth = 1; 939 bandwidth = 1;
930 } 940 }
931 941
932 for (i = 0; i < intf->num_altsetting; ++i) { 942 for (i = 0; i < intf->num_altsetting; ++i) {
933 alts = &intf->altsetting[i]; 943 alts = &intf->altsetting[i];
934 ep = uvc_find_endpoint(alts, 944 ep = uvc_find_endpoint(alts,
935 video->streaming->header.bEndpointAddress); 945 stream->header.bEndpointAddress);
936 if (ep == NULL) 946 if (ep == NULL)
937 continue; 947 continue;
938 948
@@ -946,18 +956,19 @@ static int uvc_init_video(struct uvc_video_device *video, gfp_t gfp_flags)
946 if (i >= intf->num_altsetting) 956 if (i >= intf->num_altsetting)
947 return -EIO; 957 return -EIO;
948 958
949 if ((ret = usb_set_interface(video->dev->udev, intfnum, i)) < 0) 959 ret = usb_set_interface(stream->dev->udev, intfnum, i);
960 if (ret < 0)
950 return ret; 961 return ret;
951 962
952 ret = uvc_init_video_isoc(video, ep, gfp_flags); 963 ret = uvc_init_video_isoc(stream, ep, gfp_flags);
953 } else { 964 } else {
954 /* Bulk endpoint, proceed to URB initialization. */ 965 /* Bulk endpoint, proceed to URB initialization. */
955 ep = uvc_find_endpoint(&intf->altsetting[0], 966 ep = uvc_find_endpoint(&intf->altsetting[0],
956 video->streaming->header.bEndpointAddress); 967 stream->header.bEndpointAddress);
957 if (ep == NULL) 968 if (ep == NULL)
958 return -EIO; 969 return -EIO;
959 970
960 ret = uvc_init_video_bulk(video, ep, gfp_flags); 971 ret = uvc_init_video_bulk(stream, ep, gfp_flags);
961 } 972 }
962 973
963 if (ret < 0) 974 if (ret < 0)
@@ -965,10 +976,11 @@ static int uvc_init_video(struct uvc_video_device *video, gfp_t gfp_flags)
965 976
966 /* Submit the URBs. */ 977 /* Submit the URBs. */
967 for (i = 0; i < UVC_URBS; ++i) { 978 for (i = 0; i < UVC_URBS; ++i) {
968 if ((ret = usb_submit_urb(video->urb[i], gfp_flags)) < 0) { 979 ret = usb_submit_urb(stream->urb[i], gfp_flags);
980 if (ret < 0) {
969 uvc_printk(KERN_ERR, "Failed to submit URB %u " 981 uvc_printk(KERN_ERR, "Failed to submit URB %u "
970 "(%d).\n", i, ret); 982 "(%d).\n", i, ret);
971 uvc_uninit_video(video, 1); 983 uvc_uninit_video(stream, 1);
972 return ret; 984 return ret;
973 } 985 }
974 } 986 }
@@ -987,14 +999,14 @@ static int uvc_init_video(struct uvc_video_device *video, gfp_t gfp_flags)
987 * video buffers in any way. We mark the device as frozen to make sure the URB 999 * video buffers in any way. We mark the device as frozen to make sure the URB
988 * completion handler won't try to cancel the queue when we kill the URBs. 1000 * completion handler won't try to cancel the queue when we kill the URBs.
989 */ 1001 */
990int uvc_video_suspend(struct uvc_video_device *video) 1002int uvc_video_suspend(struct uvc_streaming *stream)
991{ 1003{
992 if (!uvc_queue_streaming(&video->queue)) 1004 if (!uvc_queue_streaming(&stream->queue))
993 return 0; 1005 return 0;
994 1006
995 video->frozen = 1; 1007 stream->frozen = 1;
996 uvc_uninit_video(video, 0); 1008 uvc_uninit_video(stream, 0);
997 usb_set_interface(video->dev->udev, video->streaming->intfnum, 0); 1009 usb_set_interface(stream->dev->udev, stream->intfnum, 0);
998 return 0; 1010 return 0;
999} 1011}
1000 1012
@@ -1006,22 +1018,24 @@ int uvc_video_suspend(struct uvc_video_device *video)
1006 * buffers, making sure userspace applications are notified of the problem 1018 * buffers, making sure userspace applications are notified of the problem
1007 * instead of waiting forever. 1019 * instead of waiting forever.
1008 */ 1020 */
1009int uvc_video_resume(struct uvc_video_device *video) 1021int uvc_video_resume(struct uvc_streaming *stream)
1010{ 1022{
1011 int ret; 1023 int ret;
1012 1024
1013 video->frozen = 0; 1025 stream->frozen = 0;
1014 1026
1015 if ((ret = uvc_commit_video(video, &video->streaming->ctrl)) < 0) { 1027 ret = uvc_commit_video(stream, &stream->ctrl);
1016 uvc_queue_enable(&video->queue, 0); 1028 if (ret < 0) {
1029 uvc_queue_enable(&stream->queue, 0);
1017 return ret; 1030 return ret;
1018 } 1031 }
1019 1032
1020 if (!uvc_queue_streaming(&video->queue)) 1033 if (!uvc_queue_streaming(&stream->queue))
1021 return 0; 1034 return 0;
1022 1035
1023 if ((ret = uvc_init_video(video, GFP_NOIO)) < 0) 1036 ret = uvc_init_video(stream, GFP_NOIO);
1024 uvc_queue_enable(&video->queue, 0); 1037 if (ret < 0)
1038 uvc_queue_enable(&stream->queue, 0);
1025 1039
1026 return ret; 1040 return ret;
1027} 1041}
@@ -1040,47 +1054,53 @@ int uvc_video_resume(struct uvc_video_device *video)
1040 * 1054 *
1041 * This function is called before registering the device with V4L. 1055 * This function is called before registering the device with V4L.
1042 */ 1056 */
1043int uvc_video_init(struct uvc_video_device *video) 1057int uvc_video_init(struct uvc_streaming *stream)
1044{ 1058{
1045 struct uvc_streaming_control *probe = &video->streaming->ctrl; 1059 struct uvc_streaming_control *probe = &stream->ctrl;
1046 struct uvc_format *format = NULL; 1060 struct uvc_format *format = NULL;
1047 struct uvc_frame *frame = NULL; 1061 struct uvc_frame *frame = NULL;
1048 unsigned int i; 1062 unsigned int i;
1049 int ret; 1063 int ret;
1050 1064
1051 if (video->streaming->nformats == 0) { 1065 if (stream->nformats == 0) {
1052 uvc_printk(KERN_INFO, "No supported video formats found.\n"); 1066 uvc_printk(KERN_INFO, "No supported video formats found.\n");
1053 return -EINVAL; 1067 return -EINVAL;
1054 } 1068 }
1055 1069
1070 atomic_set(&stream->active, 0);
1071
1072 /* Initialize the video buffers queue. */
1073 uvc_queue_init(&stream->queue, stream->type);
1074
1056 /* Alternate setting 0 should be the default, yet the XBox Live Vision 1075 /* Alternate setting 0 should be the default, yet the XBox Live Vision
1057 * Cam (and possibly other devices) crash or otherwise misbehave if 1076 * Cam (and possibly other devices) crash or otherwise misbehave if
1058 * they don't receive a SET_INTERFACE request before any other video 1077 * they don't receive a SET_INTERFACE request before any other video
1059 * control request. 1078 * control request.
1060 */ 1079 */
1061 usb_set_interface(video->dev->udev, video->streaming->intfnum, 0); 1080 usb_set_interface(stream->dev->udev, stream->intfnum, 0);
1062 1081
1063 /* Set the streaming probe control with default streaming parameters 1082 /* Set the streaming probe control with default streaming parameters
1064 * retrieved from the device. Webcams that don't suport GET_DEF 1083 * retrieved from the device. Webcams that don't suport GET_DEF
1065 * requests on the probe control will just keep their current streaming 1084 * requests on the probe control will just keep their current streaming
1066 * parameters. 1085 * parameters.
1067 */ 1086 */
1068 if (uvc_get_video_ctrl(video, probe, 1, GET_DEF) == 0) 1087 if (uvc_get_video_ctrl(stream, probe, 1, UVC_GET_DEF) == 0)
1069 uvc_set_video_ctrl(video, probe, 1); 1088 uvc_set_video_ctrl(stream, probe, 1);
1070 1089
1071 /* Initialize the streaming parameters with the probe control current 1090 /* Initialize the streaming parameters with the probe control current
1072 * value. This makes sure SET_CUR requests on the streaming commit 1091 * value. This makes sure SET_CUR requests on the streaming commit
1073 * control will always use values retrieved from a successful GET_CUR 1092 * control will always use values retrieved from a successful GET_CUR
1074 * request on the probe control, as required by the UVC specification. 1093 * request on the probe control, as required by the UVC specification.
1075 */ 1094 */
1076 if ((ret = uvc_get_video_ctrl(video, probe, 1, GET_CUR)) < 0) 1095 ret = uvc_get_video_ctrl(stream, probe, 1, UVC_GET_CUR);
1096 if (ret < 0)
1077 return ret; 1097 return ret;
1078 1098
1079 /* Check if the default format descriptor exists. Use the first 1099 /* Check if the default format descriptor exists. Use the first
1080 * available format otherwise. 1100 * available format otherwise.
1081 */ 1101 */
1082 for (i = video->streaming->nformats; i > 0; --i) { 1102 for (i = stream->nformats; i > 0; --i) {
1083 format = &video->streaming->format[i-1]; 1103 format = &stream->format[i-1];
1084 if (format->index == probe->bFormatIndex) 1104 if (format->index == probe->bFormatIndex)
1085 break; 1105 break;
1086 } 1106 }
@@ -1105,21 +1125,20 @@ int uvc_video_init(struct uvc_video_device *video)
1105 probe->bFormatIndex = format->index; 1125 probe->bFormatIndex = format->index;
1106 probe->bFrameIndex = frame->bFrameIndex; 1126 probe->bFrameIndex = frame->bFrameIndex;
1107 1127
1108 video->streaming->cur_format = format; 1128 stream->cur_format = format;
1109 video->streaming->cur_frame = frame; 1129 stream->cur_frame = frame;
1110 atomic_set(&video->active, 0);
1111 1130
1112 /* Select the video decoding function */ 1131 /* Select the video decoding function */
1113 if (video->streaming->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { 1132 if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1114 if (video->dev->quirks & UVC_QUIRK_BUILTIN_ISIGHT) 1133 if (stream->dev->quirks & UVC_QUIRK_BUILTIN_ISIGHT)
1115 video->decode = uvc_video_decode_isight; 1134 stream->decode = uvc_video_decode_isight;
1116 else if (video->streaming->intf->num_altsetting > 1) 1135 else if (stream->intf->num_altsetting > 1)
1117 video->decode = uvc_video_decode_isoc; 1136 stream->decode = uvc_video_decode_isoc;
1118 else 1137 else
1119 video->decode = uvc_video_decode_bulk; 1138 stream->decode = uvc_video_decode_bulk;
1120 } else { 1139 } else {
1121 if (video->streaming->intf->num_altsetting == 1) 1140 if (stream->intf->num_altsetting == 1)
1122 video->decode = uvc_video_encode_bulk; 1141 stream->decode = uvc_video_encode_bulk;
1123 else { 1142 else {
1124 uvc_printk(KERN_INFO, "Isochronous endpoints are not " 1143 uvc_printk(KERN_INFO, "Isochronous endpoints are not "
1125 "supported for video output devices.\n"); 1144 "supported for video output devices.\n");
@@ -1133,31 +1152,32 @@ int uvc_video_init(struct uvc_video_device *video)
1133/* 1152/*
1134 * Enable or disable the video stream. 1153 * Enable or disable the video stream.
1135 */ 1154 */
1136int uvc_video_enable(struct uvc_video_device *video, int enable) 1155int uvc_video_enable(struct uvc_streaming *stream, int enable)
1137{ 1156{
1138 int ret; 1157 int ret;
1139 1158
1140 if (!enable) { 1159 if (!enable) {
1141 uvc_uninit_video(video, 1); 1160 uvc_uninit_video(stream, 1);
1142 usb_set_interface(video->dev->udev, 1161 usb_set_interface(stream->dev->udev, stream->intfnum, 0);
1143 video->streaming->intfnum, 0); 1162 uvc_queue_enable(&stream->queue, 0);
1144 uvc_queue_enable(&video->queue, 0);
1145 return 0; 1163 return 0;
1146 } 1164 }
1147 1165
1148 if ((video->streaming->cur_format->flags & UVC_FMT_FLAG_COMPRESSED) || 1166 if ((stream->cur_format->flags & UVC_FMT_FLAG_COMPRESSED) ||
1149 uvc_no_drop_param) 1167 uvc_no_drop_param)
1150 video->queue.flags &= ~UVC_QUEUE_DROP_INCOMPLETE; 1168 stream->queue.flags &= ~UVC_QUEUE_DROP_INCOMPLETE;
1151 else 1169 else
1152 video->queue.flags |= UVC_QUEUE_DROP_INCOMPLETE; 1170 stream->queue.flags |= UVC_QUEUE_DROP_INCOMPLETE;
1153 1171
1154 if ((ret = uvc_queue_enable(&video->queue, 1)) < 0) 1172 ret = uvc_queue_enable(&stream->queue, 1);
1173 if (ret < 0)
1155 return ret; 1174 return ret;
1156 1175
1157 /* Commit the streaming parameters. */ 1176 /* Commit the streaming parameters. */
1158 if ((ret = uvc_commit_video(video, &video->streaming->ctrl)) < 0) 1177 ret = uvc_commit_video(stream, &stream->ctrl);
1178 if (ret < 0)
1159 return ret; 1179 return ret;
1160 1180
1161 return uvc_init_video(video, GFP_KERNEL); 1181 return uvc_init_video(stream, GFP_KERNEL);
1162} 1182}
1163 1183
diff --git a/drivers/media/video/uvc/uvcvideo.h b/drivers/media/video/uvc/uvcvideo.h
index 3c78d3c1e4c0..e7958aa454ce 100644
--- a/drivers/media/video/uvc/uvcvideo.h
+++ b/drivers/media/video/uvc/uvcvideo.h
@@ -67,155 +67,12 @@ struct uvc_xu_control {
67#ifdef __KERNEL__ 67#ifdef __KERNEL__
68 68
69#include <linux/poll.h> 69#include <linux/poll.h>
70#include <linux/usb/video.h>
70 71
71/* -------------------------------------------------------------------------- 72/* --------------------------------------------------------------------------
72 * UVC constants 73 * UVC constants
73 */ 74 */
74 75
75#define SC_UNDEFINED 0x00
76#define SC_VIDEOCONTROL 0x01
77#define SC_VIDEOSTREAMING 0x02
78#define SC_VIDEO_INTERFACE_COLLECTION 0x03
79
80#define PC_PROTOCOL_UNDEFINED 0x00
81
82#define CS_UNDEFINED 0x20
83#define CS_DEVICE 0x21
84#define CS_CONFIGURATION 0x22
85#define CS_STRING 0x23
86#define CS_INTERFACE 0x24
87#define CS_ENDPOINT 0x25
88
89/* VideoControl class specific interface descriptor */
90#define VC_DESCRIPTOR_UNDEFINED 0x00
91#define VC_HEADER 0x01
92#define VC_INPUT_TERMINAL 0x02
93#define VC_OUTPUT_TERMINAL 0x03
94#define VC_SELECTOR_UNIT 0x04
95#define VC_PROCESSING_UNIT 0x05
96#define VC_EXTENSION_UNIT 0x06
97
98/* VideoStreaming class specific interface descriptor */
99#define VS_UNDEFINED 0x00
100#define VS_INPUT_HEADER 0x01
101#define VS_OUTPUT_HEADER 0x02
102#define VS_STILL_IMAGE_FRAME 0x03
103#define VS_FORMAT_UNCOMPRESSED 0x04
104#define VS_FRAME_UNCOMPRESSED 0x05
105#define VS_FORMAT_MJPEG 0x06
106#define VS_FRAME_MJPEG 0x07
107#define VS_FORMAT_MPEG2TS 0x0a
108#define VS_FORMAT_DV 0x0c
109#define VS_COLORFORMAT 0x0d
110#define VS_FORMAT_FRAME_BASED 0x10
111#define VS_FRAME_FRAME_BASED 0x11
112#define VS_FORMAT_STREAM_BASED 0x12
113
114/* Endpoint type */
115#define EP_UNDEFINED 0x00
116#define EP_GENERAL 0x01
117#define EP_ENDPOINT 0x02
118#define EP_INTERRUPT 0x03
119
120/* Request codes */
121#define RC_UNDEFINED 0x00
122#define SET_CUR 0x01
123#define GET_CUR 0x81
124#define GET_MIN 0x82
125#define GET_MAX 0x83
126#define GET_RES 0x84
127#define GET_LEN 0x85
128#define GET_INFO 0x86
129#define GET_DEF 0x87
130
131/* VideoControl interface controls */
132#define VC_CONTROL_UNDEFINED 0x00
133#define VC_VIDEO_POWER_MODE_CONTROL 0x01
134#define VC_REQUEST_ERROR_CODE_CONTROL 0x02
135
136/* Terminal controls */
137#define TE_CONTROL_UNDEFINED 0x00
138
139/* Selector Unit controls */
140#define SU_CONTROL_UNDEFINED 0x00
141#define SU_INPUT_SELECT_CONTROL 0x01
142
143/* Camera Terminal controls */
144#define CT_CONTROL_UNDEFINED 0x00
145#define CT_SCANNING_MODE_CONTROL 0x01
146#define CT_AE_MODE_CONTROL 0x02
147#define CT_AE_PRIORITY_CONTROL 0x03
148#define CT_EXPOSURE_TIME_ABSOLUTE_CONTROL 0x04
149#define CT_EXPOSURE_TIME_RELATIVE_CONTROL 0x05
150#define CT_FOCUS_ABSOLUTE_CONTROL 0x06
151#define CT_FOCUS_RELATIVE_CONTROL 0x07
152#define CT_FOCUS_AUTO_CONTROL 0x08
153#define CT_IRIS_ABSOLUTE_CONTROL 0x09
154#define CT_IRIS_RELATIVE_CONTROL 0x0a
155#define CT_ZOOM_ABSOLUTE_CONTROL 0x0b
156#define CT_ZOOM_RELATIVE_CONTROL 0x0c
157#define CT_PANTILT_ABSOLUTE_CONTROL 0x0d
158#define CT_PANTILT_RELATIVE_CONTROL 0x0e
159#define CT_ROLL_ABSOLUTE_CONTROL 0x0f
160#define CT_ROLL_RELATIVE_CONTROL 0x10
161#define CT_PRIVACY_CONTROL 0x11
162
163/* Processing Unit controls */
164#define PU_CONTROL_UNDEFINED 0x00
165#define PU_BACKLIGHT_COMPENSATION_CONTROL 0x01
166#define PU_BRIGHTNESS_CONTROL 0x02
167#define PU_CONTRAST_CONTROL 0x03
168#define PU_GAIN_CONTROL 0x04
169#define PU_POWER_LINE_FREQUENCY_CONTROL 0x05
170#define PU_HUE_CONTROL 0x06
171#define PU_SATURATION_CONTROL 0x07
172#define PU_SHARPNESS_CONTROL 0x08
173#define PU_GAMMA_CONTROL 0x09
174#define PU_WHITE_BALANCE_TEMPERATURE_CONTROL 0x0a
175#define PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL 0x0b
176#define PU_WHITE_BALANCE_COMPONENT_CONTROL 0x0c
177#define PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL 0x0d
178#define PU_DIGITAL_MULTIPLIER_CONTROL 0x0e
179#define PU_DIGITAL_MULTIPLIER_LIMIT_CONTROL 0x0f
180#define PU_HUE_AUTO_CONTROL 0x10
181#define PU_ANALOG_VIDEO_STANDARD_CONTROL 0x11
182#define PU_ANALOG_LOCK_STATUS_CONTROL 0x12
183
184#define LXU_MOTOR_PANTILT_RELATIVE_CONTROL 0x01
185#define LXU_MOTOR_PANTILT_RESET_CONTROL 0x02
186#define LXU_MOTOR_FOCUS_MOTOR_CONTROL 0x03
187
188/* VideoStreaming interface controls */
189#define VS_CONTROL_UNDEFINED 0x00
190#define VS_PROBE_CONTROL 0x01
191#define VS_COMMIT_CONTROL 0x02
192#define VS_STILL_PROBE_CONTROL 0x03
193#define VS_STILL_COMMIT_CONTROL 0x04
194#define VS_STILL_IMAGE_TRIGGER_CONTROL 0x05
195#define VS_STREAM_ERROR_CODE_CONTROL 0x06
196#define VS_GENERATE_KEY_FRAME_CONTROL 0x07
197#define VS_UPDATE_FRAME_SEGMENT_CONTROL 0x08
198#define VS_SYNC_DELAY_CONTROL 0x09
199
200#define TT_VENDOR_SPECIFIC 0x0100
201#define TT_STREAMING 0x0101
202
203/* Input Terminal types */
204#define ITT_VENDOR_SPECIFIC 0x0200
205#define ITT_CAMERA 0x0201
206#define ITT_MEDIA_TRANSPORT_INPUT 0x0202
207
208/* Output Terminal types */
209#define OTT_VENDOR_SPECIFIC 0x0300
210#define OTT_DISPLAY 0x0301
211#define OTT_MEDIA_TRANSPORT_OUTPUT 0x0302
212
213/* External Terminal types */
214#define EXTERNAL_VENDOR_SPECIFIC 0x0400
215#define COMPOSITE_CONNECTOR 0x0401
216#define SVIDEO_CONNECTOR 0x0402
217#define COMPONENT_CONNECTOR 0x0403
218
219#define UVC_TERM_INPUT 0x0000 76#define UVC_TERM_INPUT 0x0000
220#define UVC_TERM_OUTPUT 0x8000 77#define UVC_TERM_OUTPUT 0x8000
221 78
@@ -223,12 +80,12 @@ struct uvc_xu_control {
223#define UVC_ENTITY_IS_UNIT(entity) (((entity)->type & 0xff00) == 0) 80#define UVC_ENTITY_IS_UNIT(entity) (((entity)->type & 0xff00) == 0)
224#define UVC_ENTITY_IS_TERM(entity) (((entity)->type & 0xff00) != 0) 81#define UVC_ENTITY_IS_TERM(entity) (((entity)->type & 0xff00) != 0)
225#define UVC_ENTITY_IS_ITERM(entity) \ 82#define UVC_ENTITY_IS_ITERM(entity) \
226 (((entity)->type & 0x8000) == UVC_TERM_INPUT) 83 (UVC_ENTITY_IS_TERM(entity) && \
84 ((entity)->type & 0x8000) == UVC_TERM_INPUT)
227#define UVC_ENTITY_IS_OTERM(entity) \ 85#define UVC_ENTITY_IS_OTERM(entity) \
228 (((entity)->type & 0x8000) == UVC_TERM_OUTPUT) 86 (UVC_ENTITY_IS_TERM(entity) && \
87 ((entity)->type & 0x8000) == UVC_TERM_OUTPUT)
229 88
230#define UVC_STATUS_TYPE_CONTROL 1
231#define UVC_STATUS_TYPE_STREAMING 2
232 89
233/* ------------------------------------------------------------------------ 90/* ------------------------------------------------------------------------
234 * GUIDs 91 * GUIDs
@@ -249,19 +106,6 @@ struct uvc_xu_control {
249 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 106 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
250 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02} 107 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02}
251 108
252#define UVC_GUID_LOGITECH_DEV_INFO \
253 {0x82, 0x06, 0x61, 0x63, 0x70, 0x50, 0xab, 0x49, \
254 0xb8, 0xcc, 0xb3, 0x85, 0x5e, 0x8d, 0x22, 0x1e}
255#define UVC_GUID_LOGITECH_USER_HW \
256 {0x82, 0x06, 0x61, 0x63, 0x70, 0x50, 0xab, 0x49, \
257 0xb8, 0xcc, 0xb3, 0x85, 0x5e, 0x8d, 0x22, 0x1f}
258#define UVC_GUID_LOGITECH_VIDEO \
259 {0x82, 0x06, 0x61, 0x63, 0x70, 0x50, 0xab, 0x49, \
260 0xb8, 0xcc, 0xb3, 0x85, 0x5e, 0x8d, 0x22, 0x50}
261#define UVC_GUID_LOGITECH_MOTOR \
262 {0x82, 0x06, 0x61, 0x63, 0x70, 0x50, 0xab, 0x49, \
263 0xb8, 0xcc, 0xb3, 0x85, 0x5e, 0x8d, 0x22, 0x56}
264
265#define UVC_GUID_FORMAT_MJPEG \ 109#define UVC_GUID_FORMAT_MJPEG \
266 { 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \ 110 { 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \
267 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 111 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
@@ -314,6 +158,7 @@ struct uvc_xu_control {
314#define UVC_QUIRK_STREAM_NO_FID 0x00000010 158#define UVC_QUIRK_STREAM_NO_FID 0x00000010
315#define UVC_QUIRK_IGNORE_SELECTOR_UNIT 0x00000020 159#define UVC_QUIRK_IGNORE_SELECTOR_UNIT 0x00000020
316#define UVC_QUIRK_FIX_BANDWIDTH 0x00000080 160#define UVC_QUIRK_FIX_BANDWIDTH 0x00000080
161#define UVC_QUIRK_PROBE_DEF 0x00000100
317 162
318/* Format flags */ 163/* Format flags */
319#define UVC_FMT_FLAG_COMPRESSED 0x00000001 164#define UVC_FMT_FLAG_COMPRESSED 0x00000001
@@ -518,26 +363,6 @@ struct uvc_streaming_header {
518 __u8 bTriggerUsage; 363 __u8 bTriggerUsage;
519}; 364};
520 365
521struct uvc_streaming {
522 struct list_head list;
523
524 struct usb_interface *intf;
525 int intfnum;
526 __u16 maxpsize;
527
528 struct uvc_streaming_header header;
529 enum v4l2_buf_type type;
530
531 unsigned int nformats;
532 struct uvc_format *format;
533
534 struct uvc_streaming_control ctrl;
535 struct uvc_format *cur_format;
536 struct uvc_frame *cur_frame;
537
538 struct mutex mutex;
539};
540
541enum uvc_buffer_state { 366enum uvc_buffer_state {
542 UVC_BUF_STATE_IDLE = 0, 367 UVC_BUF_STATE_IDLE = 0,
543 UVC_BUF_STATE_QUEUED = 1, 368 UVC_BUF_STATE_QUEUED = 1,
@@ -579,26 +404,45 @@ struct uvc_video_queue {
579 struct list_head irqqueue; 404 struct list_head irqqueue;
580}; 405};
581 406
582struct uvc_video_device { 407struct uvc_video_chain {
583 struct uvc_device *dev; 408 struct uvc_device *dev;
584 struct video_device *vdev; 409 struct list_head list;
585 atomic_t active;
586 unsigned int frozen : 1;
587 410
588 struct list_head iterms; /* Input terminals */ 411 struct list_head iterms; /* Input terminals */
589 struct uvc_entity *oterm; /* Output terminal */ 412 struct list_head oterms; /* Output terminals */
590 struct uvc_entity *sterm; /* USB streaming terminal */ 413 struct uvc_entity *processing; /* Processing unit */
591 struct uvc_entity *processing; 414 struct uvc_entity *selector; /* Selector unit */
592 struct uvc_entity *selector; 415 struct list_head extensions; /* Extension units */
593 struct list_head extensions; 416
594 struct mutex ctrl_mutex; 417 struct mutex ctrl_mutex;
418};
595 419
596 struct uvc_video_queue queue; 420struct uvc_streaming {
421 struct list_head list;
422 struct uvc_device *dev;
423 struct video_device *vdev;
424 struct uvc_video_chain *chain;
425 atomic_t active;
597 426
598 /* Video streaming object, must always be non-NULL. */ 427 struct usb_interface *intf;
599 struct uvc_streaming *streaming; 428 int intfnum;
429 __u16 maxpsize;
600 430
601 void (*decode) (struct urb *urb, struct uvc_video_device *video, 431 struct uvc_streaming_header header;
432 enum v4l2_buf_type type;
433
434 unsigned int nformats;
435 struct uvc_format *format;
436
437 struct uvc_streaming_control ctrl;
438 struct uvc_format *cur_format;
439 struct uvc_frame *cur_frame;
440
441 struct mutex mutex;
442
443 unsigned int frozen : 1;
444 struct uvc_video_queue queue;
445 void (*decode) (struct urb *urb, struct uvc_streaming *video,
602 struct uvc_buffer *buf); 446 struct uvc_buffer *buf);
603 447
604 /* Context data used by the bulk completion handler. */ 448 /* Context data used by the bulk completion handler. */
@@ -640,8 +484,10 @@ struct uvc_device {
640 __u32 clock_frequency; 484 __u32 clock_frequency;
641 485
642 struct list_head entities; 486 struct list_head entities;
487 struct list_head chains;
643 488
644 struct uvc_video_device video; 489 /* Video Streaming interfaces */
490 struct list_head streams;
645 491
646 /* Status Interrupt Endpoint */ 492 /* Status Interrupt Endpoint */
647 struct usb_host_endpoint *int_ep; 493 struct usb_host_endpoint *int_ep;
@@ -649,9 +495,6 @@ struct uvc_device {
649 __u8 *status; 495 __u8 *status;
650 struct input_dev *input; 496 struct input_dev *input;
651 char input_phys[64]; 497 char input_phys[64];
652
653 /* Video Streaming interfaces */
654 struct list_head streaming;
655}; 498};
656 499
657enum uvc_handle_state { 500enum uvc_handle_state {
@@ -660,7 +503,8 @@ enum uvc_handle_state {
660}; 503};
661 504
662struct uvc_fh { 505struct uvc_fh {
663 struct uvc_video_device *device; 506 struct uvc_video_chain *chain;
507 struct uvc_streaming *stream;
664 enum uvc_handle_state state; 508 enum uvc_handle_state state;
665}; 509};
666 510
@@ -757,13 +601,13 @@ static inline int uvc_queue_streaming(struct uvc_video_queue *queue)
757extern const struct v4l2_file_operations uvc_fops; 601extern const struct v4l2_file_operations uvc_fops;
758 602
759/* Video */ 603/* Video */
760extern int uvc_video_init(struct uvc_video_device *video); 604extern int uvc_video_init(struct uvc_streaming *stream);
761extern int uvc_video_suspend(struct uvc_video_device *video); 605extern int uvc_video_suspend(struct uvc_streaming *stream);
762extern int uvc_video_resume(struct uvc_video_device *video); 606extern int uvc_video_resume(struct uvc_streaming *stream);
763extern int uvc_video_enable(struct uvc_video_device *video, int enable); 607extern int uvc_video_enable(struct uvc_streaming *stream, int enable);
764extern int uvc_probe_video(struct uvc_video_device *video, 608extern int uvc_probe_video(struct uvc_streaming *stream,
765 struct uvc_streaming_control *probe); 609 struct uvc_streaming_control *probe);
766extern int uvc_commit_video(struct uvc_video_device *video, 610extern int uvc_commit_video(struct uvc_streaming *stream,
767 struct uvc_streaming_control *ctrl); 611 struct uvc_streaming_control *ctrl);
768extern int uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit, 612extern int uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit,
769 __u8 intfnum, __u8 cs, void *data, __u16 size); 613 __u8 intfnum, __u8 cs, void *data, __u16 size);
@@ -777,9 +621,9 @@ extern int uvc_status_suspend(struct uvc_device *dev);
777extern int uvc_status_resume(struct uvc_device *dev); 621extern int uvc_status_resume(struct uvc_device *dev);
778 622
779/* Controls */ 623/* Controls */
780extern struct uvc_control *uvc_find_control(struct uvc_video_device *video, 624extern struct uvc_control *uvc_find_control(struct uvc_video_chain *chain,
781 __u32 v4l2_id, struct uvc_control_mapping **mapping); 625 __u32 v4l2_id, struct uvc_control_mapping **mapping);
782extern int uvc_query_v4l2_ctrl(struct uvc_video_device *video, 626extern int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
783 struct v4l2_queryctrl *v4l2_ctrl); 627 struct v4l2_queryctrl *v4l2_ctrl);
784 628
785extern int uvc_ctrl_add_info(struct uvc_control_info *info); 629extern int uvc_ctrl_add_info(struct uvc_control_info *info);
@@ -789,23 +633,23 @@ extern void uvc_ctrl_cleanup_device(struct uvc_device *dev);
789extern int uvc_ctrl_resume_device(struct uvc_device *dev); 633extern int uvc_ctrl_resume_device(struct uvc_device *dev);
790extern void uvc_ctrl_init(void); 634extern void uvc_ctrl_init(void);
791 635
792extern int uvc_ctrl_begin(struct uvc_video_device *video); 636extern int uvc_ctrl_begin(struct uvc_video_chain *chain);
793extern int __uvc_ctrl_commit(struct uvc_video_device *video, int rollback); 637extern int __uvc_ctrl_commit(struct uvc_video_chain *chain, int rollback);
794static inline int uvc_ctrl_commit(struct uvc_video_device *video) 638static inline int uvc_ctrl_commit(struct uvc_video_chain *chain)
795{ 639{
796 return __uvc_ctrl_commit(video, 0); 640 return __uvc_ctrl_commit(chain, 0);
797} 641}
798static inline int uvc_ctrl_rollback(struct uvc_video_device *video) 642static inline int uvc_ctrl_rollback(struct uvc_video_chain *chain)
799{ 643{
800 return __uvc_ctrl_commit(video, 1); 644 return __uvc_ctrl_commit(chain, 1);
801} 645}
802 646
803extern int uvc_ctrl_get(struct uvc_video_device *video, 647extern int uvc_ctrl_get(struct uvc_video_chain *chain,
804 struct v4l2_ext_control *xctrl); 648 struct v4l2_ext_control *xctrl);
805extern int uvc_ctrl_set(struct uvc_video_device *video, 649extern int uvc_ctrl_set(struct uvc_video_chain *chain,
806 struct v4l2_ext_control *xctrl); 650 struct v4l2_ext_control *xctrl);
807 651
808extern int uvc_xu_ctrl_query(struct uvc_video_device *video, 652extern int uvc_xu_ctrl_query(struct uvc_video_chain *chain,
809 struct uvc_xu_control *ctrl, int set); 653 struct uvc_xu_control *ctrl, int set);
810 654
811/* Utility functions */ 655/* Utility functions */
@@ -817,7 +661,7 @@ extern struct usb_host_endpoint *uvc_find_endpoint(
817 struct usb_host_interface *alts, __u8 epaddr); 661 struct usb_host_interface *alts, __u8 epaddr);
818 662
819/* Quirks support */ 663/* Quirks support */
820void uvc_video_decode_isight(struct urb *urb, struct uvc_video_device *video, 664void uvc_video_decode_isight(struct urb *urb, struct uvc_streaming *stream,
821 struct uvc_buffer *buf); 665 struct uvc_buffer *buf);
822 666
823#endif /* __KERNEL__ */ 667#endif /* __KERNEL__ */
diff --git a/drivers/media/video/v4l1-compat.c b/drivers/media/video/v4l1-compat.c
index 02f2a6d18b45..761fbd64db58 100644
--- a/drivers/media/video/v4l1-compat.c
+++ b/drivers/media/video/v4l1-compat.c
@@ -76,9 +76,8 @@ get_v4l_control(struct file *file,
76 dprintk("VIDIOC_G_CTRL: %d\n", err); 76 dprintk("VIDIOC_G_CTRL: %d\n", err);
77 return 0; 77 return 0;
78 } 78 }
79 return ((ctrl2.value - qctrl2.minimum) * 65535 79 return DIV_ROUND_CLOSEST((ctrl2.value-qctrl2.minimum) * 65535,
80 + (qctrl2.maximum - qctrl2.minimum) / 2) 80 qctrl2.maximum - qctrl2.minimum);
81 / (qctrl2.maximum - qctrl2.minimum);
82 } 81 }
83 return 0; 82 return 0;
84} 83}
diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c
index b91d66a767d7..3a0c64935b0e 100644
--- a/drivers/media/video/v4l2-common.c
+++ b/drivers/media/video/v4l2-common.c
@@ -156,6 +156,8 @@ int v4l2_ctrl_check(struct v4l2_ext_control *ctrl, struct v4l2_queryctrl *qctrl,
156 return -EINVAL; 156 return -EINVAL;
157 if (qctrl->flags & V4L2_CTRL_FLAG_GRABBED) 157 if (qctrl->flags & V4L2_CTRL_FLAG_GRABBED)
158 return -EBUSY; 158 return -EBUSY;
159 if (qctrl->type == V4L2_CTRL_TYPE_STRING)
160 return 0;
159 if (qctrl->type == V4L2_CTRL_TYPE_BUTTON || 161 if (qctrl->type == V4L2_CTRL_TYPE_BUTTON ||
160 qctrl->type == V4L2_CTRL_TYPE_INTEGER64 || 162 qctrl->type == V4L2_CTRL_TYPE_INTEGER64 ||
161 qctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS) 163 qctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS)
@@ -340,6 +342,12 @@ const char **v4l2_ctrl_get_menu(u32 id)
340 "Sepia", 342 "Sepia",
341 NULL 343 NULL
342 }; 344 };
345 static const char *tune_preemphasis[] = {
346 "No preemphasis",
347 "50 useconds",
348 "75 useconds",
349 NULL,
350 };
343 351
344 switch (id) { 352 switch (id) {
345 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: 353 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
@@ -378,6 +386,8 @@ const char **v4l2_ctrl_get_menu(u32 id)
378 return camera_exposure_auto; 386 return camera_exposure_auto;
379 case V4L2_CID_COLORFX: 387 case V4L2_CID_COLORFX:
380 return colorfx; 388 return colorfx;
389 case V4L2_CID_TUNE_PREEMPHASIS:
390 return tune_preemphasis;
381 default: 391 default:
382 return NULL; 392 return NULL;
383 } 393 }
@@ -476,6 +486,28 @@ const char *v4l2_ctrl_get_name(u32 id)
476 case V4L2_CID_ZOOM_CONTINUOUS: return "Zoom, Continuous"; 486 case V4L2_CID_ZOOM_CONTINUOUS: return "Zoom, Continuous";
477 case V4L2_CID_PRIVACY: return "Privacy"; 487 case V4L2_CID_PRIVACY: return "Privacy";
478 488
489 /* FM Radio Modulator control */
490 case V4L2_CID_FM_TX_CLASS: return "FM Radio Modulator Controls";
491 case V4L2_CID_RDS_TX_DEVIATION: return "RDS Signal Deviation";
492 case V4L2_CID_RDS_TX_PI: return "RDS Program ID";
493 case V4L2_CID_RDS_TX_PTY: return "RDS Program Type";
494 case V4L2_CID_RDS_TX_PS_NAME: return "RDS PS Name";
495 case V4L2_CID_RDS_TX_RADIO_TEXT: return "RDS Radio Text";
496 case V4L2_CID_AUDIO_LIMITER_ENABLED: return "Audio Limiter Feature Enabled";
497 case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME: return "Audio Limiter Release Time";
498 case V4L2_CID_AUDIO_LIMITER_DEVIATION: return "Audio Limiter Deviation";
499 case V4L2_CID_AUDIO_COMPRESSION_ENABLED: return "Audio Compression Feature Enabled";
500 case V4L2_CID_AUDIO_COMPRESSION_GAIN: return "Audio Compression Gain";
501 case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD: return "Audio Compression Threshold";
502 case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME: return "Audio Compression Attack Time";
503 case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME: return "Audio Compression Release Time";
504 case V4L2_CID_PILOT_TONE_ENABLED: return "Pilot Tone Feature Enabled";
505 case V4L2_CID_PILOT_TONE_DEVIATION: return "Pilot Tone Deviation";
506 case V4L2_CID_PILOT_TONE_FREQUENCY: return "Pilot Tone Frequency";
507 case V4L2_CID_TUNE_PREEMPHASIS: return "Pre-emphasis settings";
508 case V4L2_CID_TUNE_POWER_LEVEL: return "Tune Power Level";
509 case V4L2_CID_TUNE_ANTENNA_CAPACITOR: return "Tune Antenna Capacitor";
510
479 default: 511 default:
480 return NULL; 512 return NULL;
481 } 513 }
@@ -508,6 +540,9 @@ int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 ste
508 case V4L2_CID_EXPOSURE_AUTO_PRIORITY: 540 case V4L2_CID_EXPOSURE_AUTO_PRIORITY:
509 case V4L2_CID_FOCUS_AUTO: 541 case V4L2_CID_FOCUS_AUTO:
510 case V4L2_CID_PRIVACY: 542 case V4L2_CID_PRIVACY:
543 case V4L2_CID_AUDIO_LIMITER_ENABLED:
544 case V4L2_CID_AUDIO_COMPRESSION_ENABLED:
545 case V4L2_CID_PILOT_TONE_ENABLED:
511 qctrl->type = V4L2_CTRL_TYPE_BOOLEAN; 546 qctrl->type = V4L2_CTRL_TYPE_BOOLEAN;
512 min = 0; 547 min = 0;
513 max = step = 1; 548 max = step = 1;
@@ -536,12 +571,18 @@ int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 ste
536 case V4L2_CID_MPEG_STREAM_VBI_FMT: 571 case V4L2_CID_MPEG_STREAM_VBI_FMT:
537 case V4L2_CID_EXPOSURE_AUTO: 572 case V4L2_CID_EXPOSURE_AUTO:
538 case V4L2_CID_COLORFX: 573 case V4L2_CID_COLORFX:
574 case V4L2_CID_TUNE_PREEMPHASIS:
539 qctrl->type = V4L2_CTRL_TYPE_MENU; 575 qctrl->type = V4L2_CTRL_TYPE_MENU;
540 step = 1; 576 step = 1;
541 break; 577 break;
578 case V4L2_CID_RDS_TX_PS_NAME:
579 case V4L2_CID_RDS_TX_RADIO_TEXT:
580 qctrl->type = V4L2_CTRL_TYPE_STRING;
581 break;
542 case V4L2_CID_USER_CLASS: 582 case V4L2_CID_USER_CLASS:
543 case V4L2_CID_CAMERA_CLASS: 583 case V4L2_CID_CAMERA_CLASS:
544 case V4L2_CID_MPEG_CLASS: 584 case V4L2_CID_MPEG_CLASS:
585 case V4L2_CID_FM_TX_CLASS:
545 qctrl->type = V4L2_CTRL_TYPE_CTRL_CLASS; 586 qctrl->type = V4L2_CTRL_TYPE_CTRL_CLASS;
546 qctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; 587 qctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
547 min = max = step = def = 0; 588 min = max = step = def = 0;
@@ -570,6 +611,17 @@ int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 ste
570 case V4L2_CID_BLUE_BALANCE: 611 case V4L2_CID_BLUE_BALANCE:
571 case V4L2_CID_GAMMA: 612 case V4L2_CID_GAMMA:
572 case V4L2_CID_SHARPNESS: 613 case V4L2_CID_SHARPNESS:
614 case V4L2_CID_RDS_TX_DEVIATION:
615 case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME:
616 case V4L2_CID_AUDIO_LIMITER_DEVIATION:
617 case V4L2_CID_AUDIO_COMPRESSION_GAIN:
618 case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD:
619 case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME:
620 case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME:
621 case V4L2_CID_PILOT_TONE_DEVIATION:
622 case V4L2_CID_PILOT_TONE_FREQUENCY:
623 case V4L2_CID_TUNE_POWER_LEVEL:
624 case V4L2_CID_TUNE_ANTENNA_CAPACITOR:
573 qctrl->flags |= V4L2_CTRL_FLAG_SLIDER; 625 qctrl->flags |= V4L2_CTRL_FLAG_SLIDER;
574 break; 626 break;
575 case V4L2_CID_PAN_RELATIVE: 627 case V4L2_CID_PAN_RELATIVE:
diff --git a/drivers/media/video/v4l2-compat-ioctl32.c b/drivers/media/video/v4l2-compat-ioctl32.c
index 0056b115b42e..997975d5e024 100644
--- a/drivers/media/video/v4l2-compat-ioctl32.c
+++ b/drivers/media/video/v4l2-compat-ioctl32.c
@@ -600,9 +600,37 @@ struct v4l2_ext_controls32 {
600 compat_caddr_t controls; /* actually struct v4l2_ext_control32 * */ 600 compat_caddr_t controls; /* actually struct v4l2_ext_control32 * */
601}; 601};
602 602
603struct v4l2_ext_control32 {
604 __u32 id;
605 __u32 size;
606 __u32 reserved2[1];
607 union {
608 __s32 value;
609 __s64 value64;
610 compat_caddr_t string; /* actually char * */
611 };
612} __attribute__ ((packed));
613
614/* The following function really belong in v4l2-common, but that causes
615 a circular dependency between modules. We need to think about this, but
616 for now this will do. */
617
618/* Return non-zero if this control is a pointer type. Currently only
619 type STRING is a pointer type. */
620static inline int ctrl_is_pointer(u32 id)
621{
622 switch (id) {
623 case V4L2_CID_RDS_TX_PS_NAME:
624 case V4L2_CID_RDS_TX_RADIO_TEXT:
625 return 1;
626 default:
627 return 0;
628 }
629}
630
603static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up) 631static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
604{ 632{
605 struct v4l2_ext_control __user *ucontrols; 633 struct v4l2_ext_control32 __user *ucontrols;
606 struct v4l2_ext_control __user *kcontrols; 634 struct v4l2_ext_control __user *kcontrols;
607 int n; 635 int n;
608 compat_caddr_t p; 636 compat_caddr_t p;
@@ -626,15 +654,17 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
626 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control)); 654 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
627 kp->controls = kcontrols; 655 kp->controls = kcontrols;
628 while (--n >= 0) { 656 while (--n >= 0) {
629 if (copy_in_user(&kcontrols->id, &ucontrols->id, sizeof(__u32))) 657 if (copy_in_user(kcontrols, ucontrols, sizeof(*kcontrols)))
630 return -EFAULT;
631 if (copy_in_user(&kcontrols->reserved2, &ucontrols->reserved2, sizeof(ucontrols->reserved2)))
632 return -EFAULT;
633 /* Note: if the void * part of the union ever becomes relevant
634 then we need to know the type of the control in order to do
635 the right thing here. Luckily, that is not yet an issue. */
636 if (copy_in_user(&kcontrols->value, &ucontrols->value, sizeof(ucontrols->value)))
637 return -EFAULT; 658 return -EFAULT;
659 if (ctrl_is_pointer(kcontrols->id)) {
660 void __user *s;
661
662 if (get_user(p, &ucontrols->string))
663 return -EFAULT;
664 s = compat_ptr(p);
665 if (put_user(s, &kcontrols->string))
666 return -EFAULT;
667 }
638 ucontrols++; 668 ucontrols++;
639 kcontrols++; 669 kcontrols++;
640 } 670 }
@@ -643,7 +673,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
643 673
644static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up) 674static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
645{ 675{
646 struct v4l2_ext_control __user *ucontrols; 676 struct v4l2_ext_control32 __user *ucontrols;
647 struct v4l2_ext_control __user *kcontrols = kp->controls; 677 struct v4l2_ext_control __user *kcontrols = kp->controls;
648 int n = kp->count; 678 int n = kp->count;
649 compat_caddr_t p; 679 compat_caddr_t p;
@@ -664,15 +694,14 @@ static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
664 return -EFAULT; 694 return -EFAULT;
665 695
666 while (--n >= 0) { 696 while (--n >= 0) {
667 if (copy_in_user(&ucontrols->id, &kcontrols->id, sizeof(__u32))) 697 unsigned size = sizeof(*ucontrols);
668 return -EFAULT; 698
669 if (copy_in_user(&ucontrols->reserved2, &kcontrols->reserved2, 699 /* Do not modify the pointer when copying a pointer control.
670 sizeof(ucontrols->reserved2))) 700 The contents of the pointer was changed, not the pointer
671 return -EFAULT; 701 itself. */
672 /* Note: if the void * part of the union ever becomes relevant 702 if (ctrl_is_pointer(kcontrols->id))
673 then we need to know the type of the control in order to do 703 size -= sizeof(ucontrols->value64);
674 the right thing here. Luckily, that is not yet an issue. */ 704 if (copy_in_user(ucontrols, kcontrols, size))
675 if (copy_in_user(&ucontrols->value, &kcontrols->value, sizeof(ucontrols->value)))
676 return -EFAULT; 705 return -EFAULT;
677 ucontrols++; 706 ucontrols++;
678 kcontrols++; 707 kcontrols++;
diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
index f2afc4e08379..30cc3347ae52 100644
--- a/drivers/media/video/v4l2-ioctl.c
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -42,6 +42,12 @@
42 printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\ 42 printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\
43 } while (0) 43 } while (0)
44 44
45#define dbgarg3(fmt, arg...) \
46 do { \
47 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
48 printk(KERN_CONT "%s: " fmt, vfd->name, ## arg);\
49 } while (0)
50
45/* Zero out the end of the struct pointed to by p. Everthing after, but 51/* Zero out the end of the struct pointed to by p. Everthing after, but
46 * not including, the specified field is cleared. */ 52 * not including, the specified field is cleared. */
47#define CLEAR_AFTER_FIELD(p, field) \ 53#define CLEAR_AFTER_FIELD(p, field) \
@@ -507,11 +513,12 @@ static inline void v4l_print_ext_ctrls(unsigned int cmd,
507 dbgarg(cmd, ""); 513 dbgarg(cmd, "");
508 printk(KERN_CONT "class=0x%x", c->ctrl_class); 514 printk(KERN_CONT "class=0x%x", c->ctrl_class);
509 for (i = 0; i < c->count; i++) { 515 for (i = 0; i < c->count; i++) {
510 if (show_vals) 516 if (show_vals && !c->controls[i].size)
511 printk(KERN_CONT " id/val=0x%x/0x%x", 517 printk(KERN_CONT " id/val=0x%x/0x%x",
512 c->controls[i].id, c->controls[i].value); 518 c->controls[i].id, c->controls[i].value);
513 else 519 else
514 printk(KERN_CONT " id=0x%x", c->controls[i].id); 520 printk(KERN_CONT " id=0x%x,size=%u",
521 c->controls[i].id, c->controls[i].size);
515 } 522 }
516 printk(KERN_CONT "\n"); 523 printk(KERN_CONT "\n");
517}; 524};
@@ -522,10 +529,9 @@ static inline int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
522 529
523 /* zero the reserved fields */ 530 /* zero the reserved fields */
524 c->reserved[0] = c->reserved[1] = 0; 531 c->reserved[0] = c->reserved[1] = 0;
525 for (i = 0; i < c->count; i++) { 532 for (i = 0; i < c->count; i++)
526 c->controls[i].reserved2[0] = 0; 533 c->controls[i].reserved2[0] = 0;
527 c->controls[i].reserved2[1] = 0; 534
528 }
529 /* V4L2_CID_PRIVATE_BASE cannot be used as control class 535 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
530 when using extended controls. 536 when using extended controls.
531 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL 537 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
@@ -1726,24 +1732,29 @@ static long __video_do_ioctl(struct file *file,
1726 1732
1727 ret = ops->vidioc_enum_framesizes(file, fh, p); 1733 ret = ops->vidioc_enum_framesizes(file, fh, p);
1728 dbgarg(cmd, 1734 dbgarg(cmd,
1729 "index=%d, pixelformat=%d, type=%d ", 1735 "index=%d, pixelformat=%c%c%c%c, type=%d ",
1730 p->index, p->pixel_format, p->type); 1736 p->index,
1737 (p->pixel_format & 0xff),
1738 (p->pixel_format >> 8) & 0xff,
1739 (p->pixel_format >> 16) & 0xff,
1740 (p->pixel_format >> 24) & 0xff,
1741 p->type);
1731 switch (p->type) { 1742 switch (p->type) {
1732 case V4L2_FRMSIZE_TYPE_DISCRETE: 1743 case V4L2_FRMSIZE_TYPE_DISCRETE:
1733 dbgarg2("width = %d, height=%d\n", 1744 dbgarg3("width = %d, height=%d\n",
1734 p->discrete.width, p->discrete.height); 1745 p->discrete.width, p->discrete.height);
1735 break; 1746 break;
1736 case V4L2_FRMSIZE_TYPE_STEPWISE: 1747 case V4L2_FRMSIZE_TYPE_STEPWISE:
1737 dbgarg2("min %dx%d, max %dx%d, step %dx%d\n", 1748 dbgarg3("min %dx%d, max %dx%d, step %dx%d\n",
1738 p->stepwise.min_width, p->stepwise.min_height, 1749 p->stepwise.min_width, p->stepwise.min_height,
1739 p->stepwise.step_width, p->stepwise.step_height, 1750 p->stepwise.step_width, p->stepwise.step_height,
1740 p->stepwise.max_width, p->stepwise.max_height); 1751 p->stepwise.max_width, p->stepwise.max_height);
1741 break; 1752 break;
1742 case V4L2_FRMSIZE_TYPE_CONTINUOUS: 1753 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
1743 dbgarg2("continuous\n"); 1754 dbgarg3("continuous\n");
1744 break; 1755 break;
1745 default: 1756 default:
1746 dbgarg2("- Unknown type!\n"); 1757 dbgarg3("- Unknown type!\n");
1747 } 1758 }
1748 1759
1749 break; 1760 break;
diff --git a/drivers/media/video/vino.c b/drivers/media/video/vino.c
index 97b082fe4473..f3b6e15d91f2 100644
--- a/drivers/media/video/vino.c
+++ b/drivers/media/video/vino.c
@@ -1776,7 +1776,6 @@ static struct i2c_algo_sgi_data i2c_sgi_vino_data = {
1776 1776
1777static struct i2c_adapter vino_i2c_adapter = { 1777static struct i2c_adapter vino_i2c_adapter = {
1778 .name = "VINO I2C bus", 1778 .name = "VINO I2C bus",
1779 .id = I2C_HW_SGI_VINO,
1780 .algo = &sgi_algo, 1779 .algo = &sgi_algo,
1781 .algo_data = &i2c_sgi_vino_data, 1780 .algo_data = &i2c_sgi_vino_data,
1782 .owner = THIS_MODULE, 1781 .owner = THIS_MODULE,
diff --git a/drivers/media/video/w9968cf.c b/drivers/media/video/w9968cf.c
index 6c3f23e31b5c..602484dd3da9 100644
--- a/drivers/media/video/w9968cf.c
+++ b/drivers/media/video/w9968cf.c
@@ -1497,7 +1497,6 @@ static int w9968cf_i2c_init(struct w9968cf_device* cam)
1497 }; 1497 };
1498 1498
1499 static struct i2c_adapter adap = { 1499 static struct i2c_adapter adap = {
1500 .id = I2C_HW_SMBUS_W9968CF,
1501 .owner = THIS_MODULE, 1500 .owner = THIS_MODULE,
1502 .algo = &algo, 1501 .algo = &algo,
1503 }; 1502 };
diff --git a/drivers/media/video/zoran/zoran_card.c b/drivers/media/video/zoran/zoran_card.c
index 03dc2f3cf84a..0c4d9b1f8e6f 100644
--- a/drivers/media/video/zoran/zoran_card.c
+++ b/drivers/media/video/zoran/zoran_card.c
@@ -732,7 +732,6 @@ zoran_register_i2c (struct zoran *zr)
732 memcpy(&zr->i2c_algo, &zoran_i2c_bit_data_template, 732 memcpy(&zr->i2c_algo, &zoran_i2c_bit_data_template,
733 sizeof(struct i2c_algo_bit_data)); 733 sizeof(struct i2c_algo_bit_data));
734 zr->i2c_algo.data = zr; 734 zr->i2c_algo.data = zr;
735 zr->i2c_adapter.id = I2C_HW_B_ZR36067;
736 strlcpy(zr->i2c_adapter.name, ZR_DEVNAME(zr), 735 strlcpy(zr->i2c_adapter.name, ZR_DEVNAME(zr),
737 sizeof(zr->i2c_adapter.name)); 736 sizeof(zr->i2c_adapter.name));
738 i2c_set_adapdata(&zr->i2c_adapter, &zr->v4l2_dev); 737 i2c_set_adapdata(&zr->i2c_adapter, &zr->v4l2_dev);
@@ -1169,7 +1168,7 @@ zoran_setup_videocodec (struct zoran *zr,
1169 m->type = 0; 1168 m->type = 0;
1170 1169
1171 m->flags = CODEC_FLAG_ENCODER | CODEC_FLAG_DECODER; 1170 m->flags = CODEC_FLAG_ENCODER | CODEC_FLAG_DECODER;
1172 strncpy(m->name, ZR_DEVNAME(zr), sizeof(m->name)); 1171 strlcpy(m->name, ZR_DEVNAME(zr), sizeof(m->name));
1173 m->data = zr; 1172 m->data = zr;
1174 1173
1175 switch (type) 1174 switch (type)
diff --git a/drivers/media/video/zr364xx.c b/drivers/media/video/zr364xx.c
index 2622a6e63da1..9aae011d92ab 100644
--- a/drivers/media/video/zr364xx.c
+++ b/drivers/media/video/zr364xx.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Zoran 364xx based USB webcam module version 0.72 2 * Zoran 364xx based USB webcam module version 0.73
3 * 3 *
4 * Allows you to use your USB webcam with V4L2 applications 4 * Allows you to use your USB webcam with V4L2 applications
5 * This is still in heavy developpement ! 5 * This is still in heavy developpement !
@@ -10,6 +10,8 @@
10 * Heavily inspired by usb-skeleton.c, vicam.c, cpia.c and spca50x.c drivers 10 * Heavily inspired by usb-skeleton.c, vicam.c, cpia.c and spca50x.c drivers
11 * V4L2 version inspired by meye.c driver 11 * V4L2 version inspired by meye.c driver
12 * 12 *
13 * Some video buffer code by Lamarque based on s2255drv.c and vivi.c drivers.
14 *
13 * This program is free software; you can redistribute it and/or modify 15 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by 16 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or 17 * the Free Software Foundation; either version 2 of the License, or
@@ -27,6 +29,7 @@
27 29
28 30
29#include <linux/module.h> 31#include <linux/module.h>
32#include <linux/version.h>
30#include <linux/init.h> 33#include <linux/init.h>
31#include <linux/usb.h> 34#include <linux/usb.h>
32#include <linux/vmalloc.h> 35#include <linux/vmalloc.h>
@@ -35,24 +38,40 @@
35#include <linux/highmem.h> 38#include <linux/highmem.h>
36#include <media/v4l2-common.h> 39#include <media/v4l2-common.h>
37#include <media/v4l2-ioctl.h> 40#include <media/v4l2-ioctl.h>
41#include <media/videobuf-vmalloc.h>
38 42
39 43
40/* Version Information */ 44/* Version Information */
41#define DRIVER_VERSION "v0.72" 45#define DRIVER_VERSION "v0.73"
46#define ZR364XX_VERSION_CODE KERNEL_VERSION(0, 7, 3)
42#define DRIVER_AUTHOR "Antoine Jacquet, http://royale.zerezo.com/" 47#define DRIVER_AUTHOR "Antoine Jacquet, http://royale.zerezo.com/"
43#define DRIVER_DESC "Zoran 364xx" 48#define DRIVER_DESC "Zoran 364xx"
44 49
45 50
46/* Camera */ 51/* Camera */
47#define FRAMES 2 52#define FRAMES 1
48#define MAX_FRAME_SIZE 100000 53#define MAX_FRAME_SIZE 200000
49#define BUFFER_SIZE 0x1000 54#define BUFFER_SIZE 0x1000
50#define CTRL_TIMEOUT 500 55#define CTRL_TIMEOUT 500
51 56
57#define ZR364XX_DEF_BUFS 4
58#define ZR364XX_READ_IDLE 0
59#define ZR364XX_READ_FRAME 1
52 60
53/* Debug macro */ 61/* Debug macro */
54#define DBG(x...) if (debug) printk(KERN_INFO KBUILD_MODNAME x) 62#define DBG(fmt, args...) \
55 63 do { \
64 if (debug) { \
65 printk(KERN_INFO KBUILD_MODNAME " " fmt, ##args); \
66 } \
67 } while (0)
68
69/*#define FULL_DEBUG 1*/
70#ifdef FULL_DEBUG
71#define _DBG DBG
72#else
73#define _DBG(fmt, args...)
74#endif
56 75
57/* Init methods, need to find nicer names for these 76/* Init methods, need to find nicer names for these
58 * the exact names of the chipsets would be the best if someone finds it */ 77 * the exact names of the chipsets would be the best if someone finds it */
@@ -101,24 +120,93 @@ static struct usb_device_id device_table[] = {
101 120
102MODULE_DEVICE_TABLE(usb, device_table); 121MODULE_DEVICE_TABLE(usb, device_table);
103 122
123struct zr364xx_mode {
124 u32 color; /* output video color format */
125 u32 brightness; /* brightness */
126};
127
128/* frame structure */
129struct zr364xx_framei {
130 unsigned long ulState; /* ulState:ZR364XX_READ_IDLE,
131 ZR364XX_READ_FRAME */
132 void *lpvbits; /* image data */
133 unsigned long cur_size; /* current data copied to it */
134};
135
136/* image buffer structure */
137struct zr364xx_bufferi {
138 unsigned long dwFrames; /* number of frames in buffer */
139 struct zr364xx_framei frame[FRAMES]; /* array of FRAME structures */
140};
141
142struct zr364xx_dmaqueue {
143 struct list_head active;
144 struct zr364xx_camera *cam;
145};
146
147struct zr364xx_pipeinfo {
148 u32 transfer_size;
149 u8 *transfer_buffer;
150 u32 state;
151 void *stream_urb;
152 void *cam; /* back pointer to zr364xx_camera struct */
153 u32 err_count;
154 u32 idx;
155};
156
157struct zr364xx_fmt {
158 char *name;
159 u32 fourcc;
160 int depth;
161};
162
163/* image formats. */
164static const struct zr364xx_fmt formats[] = {
165 {
166 .name = "JPG",
167 .fourcc = V4L2_PIX_FMT_JPEG,
168 .depth = 24
169 }
170};
104 171
105/* Camera stuff */ 172/* Camera stuff */
106struct zr364xx_camera { 173struct zr364xx_camera {
107 struct usb_device *udev; /* save off the usb device pointer */ 174 struct usb_device *udev; /* save off the usb device pointer */
108 struct usb_interface *interface;/* the interface for this device */ 175 struct usb_interface *interface;/* the interface for this device */
109 struct video_device *vdev; /* v4l video device */ 176 struct video_device *vdev; /* v4l video device */
110 u8 *framebuf;
111 int nb; 177 int nb;
112 unsigned char *buffer; 178 struct zr364xx_bufferi buffer;
113 int skip; 179 int skip;
114 int brightness;
115 int width; 180 int width;
116 int height; 181 int height;
117 int method; 182 int method;
118 struct mutex lock; 183 struct mutex lock;
184 struct mutex open_lock;
119 int users; 185 int users;
186
187 spinlock_t slock;
188 struct zr364xx_dmaqueue vidq;
189 int resources;
190 int last_frame;
191 int cur_frame;
192 unsigned long frame_count;
193 int b_acquire;
194 struct zr364xx_pipeinfo pipe[1];
195
196 u8 read_endpoint;
197
198 const struct zr364xx_fmt *fmt;
199 struct videobuf_queue vb_vidq;
200 enum v4l2_buf_type type;
201 struct zr364xx_mode mode;
120}; 202};
121 203
204/* buffer for one video frame */
205struct zr364xx_buffer {
206 /* common v4l buffer stuff -- must be first */
207 struct videobuf_buffer vb;
208 const struct zr364xx_fmt *fmt;
209};
122 210
123/* function used to send initialisation commands to the camera */ 211/* function used to send initialisation commands to the camera */
124static int send_control_msg(struct usb_device *udev, u8 request, u16 value, 212static int send_control_msg(struct usb_device *udev, u8 request, u16 value,
@@ -272,139 +360,116 @@ static unsigned char header2[] = {
272}; 360};
273static unsigned char header3; 361static unsigned char header3;
274 362
363/* ------------------------------------------------------------------
364 Videobuf operations
365 ------------------------------------------------------------------*/
275 366
367static int buffer_setup(struct videobuf_queue *vq, unsigned int *count,
368 unsigned int *size)
369{
370 struct zr364xx_camera *cam = vq->priv_data;
276 371
277/********************/ 372 *size = cam->width * cam->height * (cam->fmt->depth >> 3);
278/* V4L2 integration */
279/********************/
280 373
281/* this function reads a full JPEG picture synchronously 374 if (*count == 0)
282 * TODO: do it asynchronously... */ 375 *count = ZR364XX_DEF_BUFS;
283static int read_frame(struct zr364xx_camera *cam, int framenum)
284{
285 int i, n, temp, head, size, actual_length;
286 unsigned char *ptr = NULL, *jpeg;
287
288 redo:
289 /* hardware brightness */
290 n = send_control_msg(cam->udev, 1, 0x2001, 0, NULL, 0);
291 temp = (0x60 << 8) + 127 - cam->brightness;
292 n = send_control_msg(cam->udev, 1, temp, 0, NULL, 0);
293
294 /* during the first loop we are going to insert JPEG header */
295 head = 0;
296 /* this is the place in memory where we are going to build
297 * the JPEG image */
298 jpeg = cam->framebuf + framenum * MAX_FRAME_SIZE;
299 /* read data... */
300 do {
301 n = usb_bulk_msg(cam->udev,
302 usb_rcvbulkpipe(cam->udev, 0x81),
303 cam->buffer, BUFFER_SIZE, &actual_length,
304 CTRL_TIMEOUT);
305 DBG("buffer : %d %d", cam->buffer[0], cam->buffer[1]);
306 DBG("bulk : n=%d size=%d", n, actual_length);
307 if (n < 0) {
308 dev_err(&cam->udev->dev, "error reading bulk msg\n");
309 return 0;
310 }
311 if (actual_length < 0 || actual_length > BUFFER_SIZE) {
312 dev_err(&cam->udev->dev, "wrong number of bytes\n");
313 return 0;
314 }
315 376
316 /* swap bytes if camera needs it */ 377 while (*size * (*count) > ZR364XX_DEF_BUFS * 1024 * 1024)
317 if (cam->method == METHOD0) { 378 (*count)--;
318 u16 *buf = (u16*)cam->buffer;
319 for (i = 0; i < BUFFER_SIZE/2; i++)
320 swab16s(buf + i);
321 }
322 379
323 /* write the JPEG header */ 380 return 0;
324 if (!head) { 381}
325 DBG("jpeg header");
326 ptr = jpeg;
327 memcpy(ptr, header1, sizeof(header1));
328 ptr += sizeof(header1);
329 header3 = 0;
330 memcpy(ptr, &header3, 1);
331 ptr++;
332 memcpy(ptr, cam->buffer, 64);
333 ptr += 64;
334 header3 = 1;
335 memcpy(ptr, &header3, 1);
336 ptr++;
337 memcpy(ptr, cam->buffer + 64, 64);
338 ptr += 64;
339 memcpy(ptr, header2, sizeof(header2));
340 ptr += sizeof(header2);
341 memcpy(ptr, cam->buffer + 128,
342 actual_length - 128);
343 ptr += actual_length - 128;
344 head = 1;
345 DBG("header : %d %d %d %d %d %d %d %d %d",
346 cam->buffer[0], cam->buffer[1], cam->buffer[2],
347 cam->buffer[3], cam->buffer[4], cam->buffer[5],
348 cam->buffer[6], cam->buffer[7], cam->buffer[8]);
349 } else {
350 memcpy(ptr, cam->buffer, actual_length);
351 ptr += actual_length;
352 }
353 }
354 /* ... until there is no more */
355 while (actual_length == BUFFER_SIZE);
356 382
357 /* we skip the 2 first frames which are usually buggy */ 383static void free_buffer(struct videobuf_queue *vq, struct zr364xx_buffer *buf)
358 if (cam->skip) { 384{
359 cam->skip--; 385 _DBG("%s\n", __func__);
360 goto redo;
361 }
362 386
363 /* go back to find the JPEG EOI marker */ 387 if (in_interrupt())
364 size = ptr - jpeg; 388 BUG();
365 ptr -= 2;
366 while (ptr > jpeg) {
367 if (*ptr == 0xFF && *(ptr + 1) == 0xD9
368 && *(ptr + 2) == 0xFF)
369 break;
370 ptr--;
371 }
372 if (ptr == jpeg)
373 DBG("No EOI marker");
374 389
375 /* Sometimes there is junk data in the middle of the picture, 390 videobuf_vmalloc_free(&buf->vb);
376 * we want to skip this bogus frames */ 391 buf->vb.state = VIDEOBUF_NEEDS_INIT;
377 while (ptr > jpeg) { 392}
378 if (*ptr == 0xFF && *(ptr + 1) == 0xFF 393
379 && *(ptr + 2) == 0xFF) 394static int buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
380 break; 395 enum v4l2_field field)
381 ptr--; 396{
397 struct zr364xx_camera *cam = vq->priv_data;
398 struct zr364xx_buffer *buf = container_of(vb, struct zr364xx_buffer,
399 vb);
400 int rc;
401
402 DBG("%s, field=%d, fmt name = %s\n", __func__, field, cam->fmt != NULL ?
403 cam->fmt->name : "");
404 if (cam->fmt == NULL)
405 return -EINVAL;
406
407 buf->vb.size = cam->width * cam->height * (cam->fmt->depth >> 3);
408
409 if (buf->vb.baddr != 0 && buf->vb.bsize < buf->vb.size) {
410 DBG("invalid buffer prepare\n");
411 return -EINVAL;
382 } 412 }
383 if (ptr != jpeg) { 413
384 DBG("Bogus frame ? %d", cam->nb); 414 buf->fmt = cam->fmt;
385 goto redo; 415 buf->vb.width = cam->width;
416 buf->vb.height = cam->height;
417 buf->vb.field = field;
418
419 if (buf->vb.state == VIDEOBUF_NEEDS_INIT) {
420 rc = videobuf_iolock(vq, &buf->vb, NULL);
421 if (rc < 0)
422 goto fail;
386 } 423 }
387 424
388 DBG("jpeg : %d %d %d %d %d %d %d %d", 425 buf->vb.state = VIDEOBUF_PREPARED;
389 jpeg[0], jpeg[1], jpeg[2], jpeg[3], 426 return 0;
390 jpeg[4], jpeg[5], jpeg[6], jpeg[7]); 427fail:
428 free_buffer(vq, buf);
429 return rc;
430}
431
432static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
433{
434 struct zr364xx_buffer *buf = container_of(vb, struct zr364xx_buffer,
435 vb);
436 struct zr364xx_camera *cam = vq->priv_data;
437
438 _DBG("%s\n", __func__);
439
440 buf->vb.state = VIDEOBUF_QUEUED;
441 list_add_tail(&buf->vb.queue, &cam->vidq.active);
442}
443
444static void buffer_release(struct videobuf_queue *vq,
445 struct videobuf_buffer *vb)
446{
447 struct zr364xx_buffer *buf = container_of(vb, struct zr364xx_buffer,
448 vb);
391 449
392 return size; 450 _DBG("%s\n", __func__);
451 free_buffer(vq, buf);
393} 452}
394 453
454static struct videobuf_queue_ops zr364xx_video_qops = {
455 .buf_setup = buffer_setup,
456 .buf_prepare = buffer_prepare,
457 .buf_queue = buffer_queue,
458 .buf_release = buffer_release,
459};
460
461/********************/
462/* V4L2 integration */
463/********************/
464static int zr364xx_vidioc_streamon(struct file *file, void *priv,
465 enum v4l2_buf_type type);
395 466
396static ssize_t zr364xx_read(struct file *file, char __user *buf, size_t cnt, 467static ssize_t zr364xx_read(struct file *file, char __user *buf, size_t count,
397 loff_t * ppos) 468 loff_t * ppos)
398{ 469{
399 unsigned long count = cnt; 470 struct zr364xx_camera *cam = video_drvdata(file);
400 struct video_device *vdev = video_devdata(file);
401 struct zr364xx_camera *cam;
402 471
403 DBG("zr364xx_read: read %d bytes.", (int) count); 472 _DBG("%s\n", __func__);
404
405 if (vdev == NULL)
406 return -ENODEV;
407 cam = video_get_drvdata(vdev);
408 473
409 if (!buf) 474 if (!buf)
410 return -EINVAL; 475 return -EINVAL;
@@ -412,21 +477,276 @@ static ssize_t zr364xx_read(struct file *file, char __user *buf, size_t cnt,
412 if (!count) 477 if (!count)
413 return -EINVAL; 478 return -EINVAL;
414 479
415 /* NoMan Sux ! */ 480 if (cam->type == V4L2_BUF_TYPE_VIDEO_CAPTURE &&
416 count = read_frame(cam, 0); 481 zr364xx_vidioc_streamon(file, cam, cam->type) == 0) {
482 DBG("%s: reading %d bytes at pos %d.\n", __func__, (int) count,
483 (int) *ppos);
484
485 /* NoMan Sux ! */
486 return videobuf_read_one(&cam->vb_vidq, buf, count, ppos,
487 file->f_flags & O_NONBLOCK);
488 }
489
490 return 0;
491}
492
493/* video buffer vmalloc implementation based partly on VIVI driver which is
494 * Copyright (c) 2006 by
495 * Mauro Carvalho Chehab <mchehab--a.t--infradead.org>
496 * Ted Walther <ted--a.t--enumera.com>
497 * John Sokol <sokol--a.t--videotechnology.com>
498 * http://v4l.videotechnology.com/
499 *
500 */
501static void zr364xx_fillbuff(struct zr364xx_camera *cam,
502 struct zr364xx_buffer *buf,
503 int jpgsize)
504{
505 int pos = 0;
506 struct timeval ts;
507 const char *tmpbuf;
508 char *vbuf = videobuf_to_vmalloc(&buf->vb);
509 unsigned long last_frame;
510 struct zr364xx_framei *frm;
511
512 if (!vbuf)
513 return;
514
515 last_frame = cam->last_frame;
516 if (last_frame != -1) {
517 frm = &cam->buffer.frame[last_frame];
518 tmpbuf = (const char *)cam->buffer.frame[last_frame].lpvbits;
519 switch (buf->fmt->fourcc) {
520 case V4L2_PIX_FMT_JPEG:
521 buf->vb.size = jpgsize;
522 memcpy(vbuf, tmpbuf, buf->vb.size);
523 break;
524 default:
525 printk(KERN_DEBUG KBUILD_MODNAME ": unknown format?\n");
526 }
527 cam->last_frame = -1;
528 } else {
529 printk(KERN_ERR KBUILD_MODNAME ": =======no frame\n");
530 return;
531 }
532 DBG("%s: Buffer 0x%08lx size= %d\n", __func__,
533 (unsigned long)vbuf, pos);
534 /* tell v4l buffer was filled */
535
536 buf->vb.field_count = cam->frame_count * 2;
537 do_gettimeofday(&ts);
538 buf->vb.ts = ts;
539 buf->vb.state = VIDEOBUF_DONE;
540}
541
542static int zr364xx_got_frame(struct zr364xx_camera *cam, int jpgsize)
543{
544 struct zr364xx_dmaqueue *dma_q = &cam->vidq;
545 struct zr364xx_buffer *buf;
546 unsigned long flags = 0;
547 int rc = 0;
548
549 DBG("wakeup: %p\n", &dma_q);
550 spin_lock_irqsave(&cam->slock, flags);
551
552 if (list_empty(&dma_q->active)) {
553 DBG("No active queue to serve\n");
554 rc = -1;
555 goto unlock;
556 }
557 buf = list_entry(dma_q->active.next,
558 struct zr364xx_buffer, vb.queue);
559
560 if (!waitqueue_active(&buf->vb.done)) {
561 /* no one active */
562 rc = -1;
563 goto unlock;
564 }
565 list_del(&buf->vb.queue);
566 do_gettimeofday(&buf->vb.ts);
567 DBG("[%p/%d] wakeup\n", buf, buf->vb.i);
568 zr364xx_fillbuff(cam, buf, jpgsize);
569 wake_up(&buf->vb.done);
570 DBG("wakeup [buf/i] [%p/%d]\n", buf, buf->vb.i);
571unlock:
572 spin_unlock_irqrestore(&cam->slock, flags);
573 return 0;
574}
575
576/* this function moves the usb stream read pipe data
577 * into the system buffers.
578 * returns 0 on success, EAGAIN if more data to process (call this
579 * function again).
580 */
581static int zr364xx_read_video_callback(struct zr364xx_camera *cam,
582 struct zr364xx_pipeinfo *pipe_info,
583 struct urb *purb)
584{
585 unsigned char *pdest;
586 unsigned char *psrc;
587 s32 idx = -1;
588 struct zr364xx_framei *frm;
589 int i = 0;
590 unsigned char *ptr = NULL;
591
592 _DBG("buffer to user\n");
593 idx = cam->cur_frame;
594 frm = &cam->buffer.frame[idx];
595
596 /* swap bytes if camera needs it */
597 if (cam->method == METHOD0) {
598 u16 *buf = (u16 *)pipe_info->transfer_buffer;
599 for (i = 0; i < purb->actual_length/2; i++)
600 swab16s(buf + i);
601 }
602
603 /* search done. now find out if should be acquiring */
604 if (!cam->b_acquire) {
605 /* we found a frame, but this channel is turned off */
606 frm->ulState = ZR364XX_READ_IDLE;
607 return -EINVAL;
608 }
609
610 psrc = (u8 *)pipe_info->transfer_buffer;
611 ptr = pdest = frm->lpvbits;
612
613 if (frm->ulState == ZR364XX_READ_IDLE) {
614 frm->ulState = ZR364XX_READ_FRAME;
615 frm->cur_size = 0;
616
617 _DBG("jpeg header, ");
618 memcpy(ptr, header1, sizeof(header1));
619 ptr += sizeof(header1);
620 header3 = 0;
621 memcpy(ptr, &header3, 1);
622 ptr++;
623 memcpy(ptr, psrc, 64);
624 ptr += 64;
625 header3 = 1;
626 memcpy(ptr, &header3, 1);
627 ptr++;
628 memcpy(ptr, psrc + 64, 64);
629 ptr += 64;
630 memcpy(ptr, header2, sizeof(header2));
631 ptr += sizeof(header2);
632 memcpy(ptr, psrc + 128,
633 purb->actual_length - 128);
634 ptr += purb->actual_length - 128;
635 _DBG("header : %d %d %d %d %d %d %d %d %d\n",
636 psrc[0], psrc[1], psrc[2],
637 psrc[3], psrc[4], psrc[5],
638 psrc[6], psrc[7], psrc[8]);
639 frm->cur_size = ptr - pdest;
640 } else {
641 if (frm->cur_size + purb->actual_length > MAX_FRAME_SIZE) {
642 dev_info(&cam->udev->dev,
643 "%s: buffer (%d bytes) too small to hold "
644 "frame data. Discarding frame data.\n",
645 __func__, MAX_FRAME_SIZE);
646 } else {
647 pdest += frm->cur_size;
648 memcpy(pdest, psrc, purb->actual_length);
649 frm->cur_size += purb->actual_length;
650 }
651 }
652 /*_DBG("cur_size %lu urb size %d\n", frm->cur_size,
653 purb->actual_length);*/
654
655 if (purb->actual_length < pipe_info->transfer_size) {
656 _DBG("****************Buffer[%d]full*************\n", idx);
657 cam->last_frame = cam->cur_frame;
658 cam->cur_frame++;
659 /* end of system frame ring buffer, start at zero */
660 if (cam->cur_frame == cam->buffer.dwFrames)
661 cam->cur_frame = 0;
662
663 /* frame ready */
664 /* go back to find the JPEG EOI marker */
665 ptr = pdest = frm->lpvbits;
666 ptr += frm->cur_size - 2;
667 while (ptr > pdest) {
668 if (*ptr == 0xFF && *(ptr + 1) == 0xD9
669 && *(ptr + 2) == 0xFF)
670 break;
671 ptr--;
672 }
673 if (ptr == pdest)
674 DBG("No EOI marker\n");
675
676 /* Sometimes there is junk data in the middle of the picture,
677 * we want to skip this bogus frames */
678 while (ptr > pdest) {
679 if (*ptr == 0xFF && *(ptr + 1) == 0xFF
680 && *(ptr + 2) == 0xFF)
681 break;
682 ptr--;
683 }
684 if (ptr != pdest) {
685 DBG("Bogus frame ? %d\n", ++(cam->nb));
686 } else if (cam->b_acquire) {
687 /* we skip the 2 first frames which are usually buggy */
688 if (cam->skip)
689 cam->skip--;
690 else {
691 _DBG("jpeg(%lu): %d %d %d %d %d %d %d %d\n",
692 frm->cur_size,
693 pdest[0], pdest[1], pdest[2], pdest[3],
694 pdest[4], pdest[5], pdest[6], pdest[7]);
695
696 zr364xx_got_frame(cam, frm->cur_size);
697 }
698 }
699 cam->frame_count++;
700 frm->ulState = ZR364XX_READ_IDLE;
701 frm->cur_size = 0;
702 }
703 /* done successfully */
704 return 0;
705}
417 706
418 if (copy_to_user(buf, cam->framebuf, count)) 707static int res_get(struct zr364xx_camera *cam)
419 return -EFAULT; 708{
709 /* is it free? */
710 mutex_lock(&cam->lock);
711 if (cam->resources) {
712 /* no, someone else uses it */
713 mutex_unlock(&cam->lock);
714 return 0;
715 }
716 /* it's free, grab it */
717 cam->resources = 1;
718 _DBG("res: get\n");
719 mutex_unlock(&cam->lock);
720 return 1;
721}
420 722
421 return count; 723static inline int res_check(struct zr364xx_camera *cam)
724{
725 return cam->resources;
422} 726}
423 727
728static void res_free(struct zr364xx_camera *cam)
729{
730 mutex_lock(&cam->lock);
731 cam->resources = 0;
732 mutex_unlock(&cam->lock);
733 _DBG("res: put\n");
734}
424 735
425static int zr364xx_vidioc_querycap(struct file *file, void *priv, 736static int zr364xx_vidioc_querycap(struct file *file, void *priv,
426 struct v4l2_capability *cap) 737 struct v4l2_capability *cap)
427{ 738{
428 strcpy(cap->driver, DRIVER_DESC); 739 struct zr364xx_camera *cam = video_drvdata(file);
429 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE; 740
741 strlcpy(cap->driver, DRIVER_DESC, sizeof(cap->driver));
742 strlcpy(cap->card, cam->udev->product, sizeof(cap->card));
743 strlcpy(cap->bus_info, dev_name(&cam->udev->dev),
744 sizeof(cap->bus_info));
745 cap->version = ZR364XX_VERSION_CODE;
746 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE |
747 V4L2_CAP_READWRITE |
748 V4L2_CAP_STREAMING;
749
430 return 0; 750 return 0;
431} 751}
432 752
@@ -458,12 +778,11 @@ static int zr364xx_vidioc_s_input(struct file *file, void *priv,
458static int zr364xx_vidioc_queryctrl(struct file *file, void *priv, 778static int zr364xx_vidioc_queryctrl(struct file *file, void *priv,
459 struct v4l2_queryctrl *c) 779 struct v4l2_queryctrl *c)
460{ 780{
461 struct video_device *vdev = video_devdata(file);
462 struct zr364xx_camera *cam; 781 struct zr364xx_camera *cam;
463 782
464 if (vdev == NULL) 783 if (file == NULL)
465 return -ENODEV; 784 return -ENODEV;
466 cam = video_get_drvdata(vdev); 785 cam = video_drvdata(file);
467 786
468 switch (c->id) { 787 switch (c->id) {
469 case V4L2_CID_BRIGHTNESS: 788 case V4L2_CID_BRIGHTNESS:
@@ -472,7 +791,7 @@ static int zr364xx_vidioc_queryctrl(struct file *file, void *priv,
472 c->minimum = 0; 791 c->minimum = 0;
473 c->maximum = 127; 792 c->maximum = 127;
474 c->step = 1; 793 c->step = 1;
475 c->default_value = cam->brightness; 794 c->default_value = cam->mode.brightness;
476 c->flags = 0; 795 c->flags = 0;
477 break; 796 break;
478 default: 797 default:
@@ -484,36 +803,42 @@ static int zr364xx_vidioc_queryctrl(struct file *file, void *priv,
484static int zr364xx_vidioc_s_ctrl(struct file *file, void *priv, 803static int zr364xx_vidioc_s_ctrl(struct file *file, void *priv,
485 struct v4l2_control *c) 804 struct v4l2_control *c)
486{ 805{
487 struct video_device *vdev = video_devdata(file);
488 struct zr364xx_camera *cam; 806 struct zr364xx_camera *cam;
807 int temp;
489 808
490 if (vdev == NULL) 809 if (file == NULL)
491 return -ENODEV; 810 return -ENODEV;
492 cam = video_get_drvdata(vdev); 811 cam = video_drvdata(file);
493 812
494 switch (c->id) { 813 switch (c->id) {
495 case V4L2_CID_BRIGHTNESS: 814 case V4L2_CID_BRIGHTNESS:
496 cam->brightness = c->value; 815 cam->mode.brightness = c->value;
816 /* hardware brightness */
817 mutex_lock(&cam->lock);
818 send_control_msg(cam->udev, 1, 0x2001, 0, NULL, 0);
819 temp = (0x60 << 8) + 127 - cam->mode.brightness;
820 send_control_msg(cam->udev, 1, temp, 0, NULL, 0);
821 mutex_unlock(&cam->lock);
497 break; 822 break;
498 default: 823 default:
499 return -EINVAL; 824 return -EINVAL;
500 } 825 }
826
501 return 0; 827 return 0;
502} 828}
503 829
504static int zr364xx_vidioc_g_ctrl(struct file *file, void *priv, 830static int zr364xx_vidioc_g_ctrl(struct file *file, void *priv,
505 struct v4l2_control *c) 831 struct v4l2_control *c)
506{ 832{
507 struct video_device *vdev = video_devdata(file);
508 struct zr364xx_camera *cam; 833 struct zr364xx_camera *cam;
509 834
510 if (vdev == NULL) 835 if (file == NULL)
511 return -ENODEV; 836 return -ENODEV;
512 cam = video_get_drvdata(vdev); 837 cam = video_drvdata(file);
513 838
514 switch (c->id) { 839 switch (c->id) {
515 case V4L2_CID_BRIGHTNESS: 840 case V4L2_CID_BRIGHTNESS:
516 c->value = cam->brightness; 841 c->value = cam->mode.brightness;
517 break; 842 break;
518 default: 843 default:
519 return -EINVAL; 844 return -EINVAL;
@@ -527,47 +852,63 @@ static int zr364xx_vidioc_enum_fmt_vid_cap(struct file *file,
527 if (f->index > 0) 852 if (f->index > 0)
528 return -EINVAL; 853 return -EINVAL;
529 f->flags = V4L2_FMT_FLAG_COMPRESSED; 854 f->flags = V4L2_FMT_FLAG_COMPRESSED;
530 strcpy(f->description, "JPEG"); 855 strcpy(f->description, formats[0].name);
531 f->pixelformat = V4L2_PIX_FMT_JPEG; 856 f->pixelformat = formats[0].fourcc;
532 return 0; 857 return 0;
533} 858}
534 859
860static char *decode_fourcc(__u32 pixelformat, char *buf)
861{
862 buf[0] = pixelformat & 0xff;
863 buf[1] = (pixelformat >> 8) & 0xff;
864 buf[2] = (pixelformat >> 16) & 0xff;
865 buf[3] = (pixelformat >> 24) & 0xff;
866 buf[4] = '\0';
867 return buf;
868}
869
535static int zr364xx_vidioc_try_fmt_vid_cap(struct file *file, void *priv, 870static int zr364xx_vidioc_try_fmt_vid_cap(struct file *file, void *priv,
536 struct v4l2_format *f) 871 struct v4l2_format *f)
537{ 872{
538 struct video_device *vdev = video_devdata(file); 873 struct zr364xx_camera *cam = video_drvdata(file);
539 struct zr364xx_camera *cam; 874 char pixelformat_name[5];
540 875
541 if (vdev == NULL) 876 if (cam == NULL)
542 return -ENODEV; 877 return -ENODEV;
543 cam = video_get_drvdata(vdev);
544 878
545 if (f->fmt.pix.pixelformat != V4L2_PIX_FMT_JPEG) 879 if (f->fmt.pix.pixelformat != V4L2_PIX_FMT_JPEG) {
546 return -EINVAL; 880 DBG("%s: unsupported pixelformat V4L2_PIX_FMT_%s\n", __func__,
547 if (f->fmt.pix.field != V4L2_FIELD_ANY && 881 decode_fourcc(f->fmt.pix.pixelformat, pixelformat_name));
548 f->fmt.pix.field != V4L2_FIELD_NONE)
549 return -EINVAL; 882 return -EINVAL;
883 }
884
885 if (!(f->fmt.pix.width == 160 && f->fmt.pix.height == 120) &&
886 !(f->fmt.pix.width == 640 && f->fmt.pix.height == 480)) {
887 f->fmt.pix.width = 320;
888 f->fmt.pix.height = 240;
889 }
890
550 f->fmt.pix.field = V4L2_FIELD_NONE; 891 f->fmt.pix.field = V4L2_FIELD_NONE;
551 f->fmt.pix.width = cam->width;
552 f->fmt.pix.height = cam->height;
553 f->fmt.pix.bytesperline = f->fmt.pix.width * 2; 892 f->fmt.pix.bytesperline = f->fmt.pix.width * 2;
554 f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; 893 f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
555 f->fmt.pix.colorspace = 0; 894 f->fmt.pix.colorspace = 0;
556 f->fmt.pix.priv = 0; 895 f->fmt.pix.priv = 0;
896 DBG("%s: V4L2_PIX_FMT_%s (%d) ok!\n", __func__,
897 decode_fourcc(f->fmt.pix.pixelformat, pixelformat_name),
898 f->fmt.pix.field);
557 return 0; 899 return 0;
558} 900}
559 901
560static int zr364xx_vidioc_g_fmt_vid_cap(struct file *file, void *priv, 902static int zr364xx_vidioc_g_fmt_vid_cap(struct file *file, void *priv,
561 struct v4l2_format *f) 903 struct v4l2_format *f)
562{ 904{
563 struct video_device *vdev = video_devdata(file);
564 struct zr364xx_camera *cam; 905 struct zr364xx_camera *cam;
565 906
566 if (vdev == NULL) 907 if (file == NULL)
567 return -ENODEV; 908 return -ENODEV;
568 cam = video_get_drvdata(vdev); 909 cam = video_drvdata(file);
569 910
570 f->fmt.pix.pixelformat = V4L2_PIX_FMT_JPEG; 911 f->fmt.pix.pixelformat = formats[0].fourcc;
571 f->fmt.pix.field = V4L2_FIELD_NONE; 912 f->fmt.pix.field = V4L2_FIELD_NONE;
572 f->fmt.pix.width = cam->width; 913 f->fmt.pix.width = cam->width;
573 f->fmt.pix.height = cam->height; 914 f->fmt.pix.height = cam->height;
@@ -581,38 +922,327 @@ static int zr364xx_vidioc_g_fmt_vid_cap(struct file *file, void *priv,
581static int zr364xx_vidioc_s_fmt_vid_cap(struct file *file, void *priv, 922static int zr364xx_vidioc_s_fmt_vid_cap(struct file *file, void *priv,
582 struct v4l2_format *f) 923 struct v4l2_format *f)
583{ 924{
584 struct video_device *vdev = video_devdata(file); 925 struct zr364xx_camera *cam = video_drvdata(file);
585 struct zr364xx_camera *cam; 926 struct videobuf_queue *q = &cam->vb_vidq;
927 char pixelformat_name[5];
928 int ret = zr364xx_vidioc_try_fmt_vid_cap(file, cam, f);
929 int i;
586 930
587 if (vdev == NULL) 931 if (ret < 0)
588 return -ENODEV; 932 return ret;
589 cam = video_get_drvdata(vdev);
590 933
591 if (f->fmt.pix.pixelformat != V4L2_PIX_FMT_JPEG) 934 mutex_lock(&q->vb_lock);
592 return -EINVAL; 935
593 if (f->fmt.pix.field != V4L2_FIELD_ANY && 936 if (videobuf_queue_is_busy(&cam->vb_vidq)) {
594 f->fmt.pix.field != V4L2_FIELD_NONE) 937 DBG("%s queue busy\n", __func__);
595 return -EINVAL; 938 ret = -EBUSY;
596 f->fmt.pix.field = V4L2_FIELD_NONE; 939 goto out;
597 f->fmt.pix.width = cam->width; 940 }
598 f->fmt.pix.height = cam->height; 941
942 if (res_check(cam)) {
943 DBG("%s can't change format after started\n", __func__);
944 ret = -EBUSY;
945 goto out;
946 }
947
948 cam->width = f->fmt.pix.width;
949 cam->height = f->fmt.pix.height;
950 dev_info(&cam->udev->dev, "%s: %dx%d mode selected\n", __func__,
951 cam->width, cam->height);
599 f->fmt.pix.bytesperline = f->fmt.pix.width * 2; 952 f->fmt.pix.bytesperline = f->fmt.pix.width * 2;
600 f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; 953 f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
601 f->fmt.pix.colorspace = 0; 954 f->fmt.pix.colorspace = 0;
602 f->fmt.pix.priv = 0; 955 f->fmt.pix.priv = 0;
603 DBG("ok!"); 956 cam->vb_vidq.field = f->fmt.pix.field;
957 cam->mode.color = V4L2_PIX_FMT_JPEG;
958
959 if (f->fmt.pix.width == 160 && f->fmt.pix.height == 120)
960 mode = 1;
961 else if (f->fmt.pix.width == 640 && f->fmt.pix.height == 480)
962 mode = 2;
963 else
964 mode = 0;
965
966 m0d1[0] = mode;
967 m1[2].value = 0xf000 + mode;
968 m2[1].value = 0xf000 + mode;
969 header2[437] = cam->height / 256;
970 header2[438] = cam->height % 256;
971 header2[439] = cam->width / 256;
972 header2[440] = cam->width % 256;
973
974 for (i = 0; init[cam->method][i].size != -1; i++) {
975 ret =
976 send_control_msg(cam->udev, 1, init[cam->method][i].value,
977 0, init[cam->method][i].bytes,
978 init[cam->method][i].size);
979 if (ret < 0) {
980 dev_err(&cam->udev->dev,
981 "error during resolution change sequence: %d\n", i);
982 goto out;
983 }
984 }
985
986 /* Added some delay here, since opening/closing the camera quickly,
987 * like Ekiga does during its startup, can crash the webcam
988 */
989 mdelay(100);
990 cam->skip = 2;
991 ret = 0;
992
993out:
994 mutex_unlock(&q->vb_lock);
995
996 DBG("%s: V4L2_PIX_FMT_%s (%d) ok!\n", __func__,
997 decode_fourcc(f->fmt.pix.pixelformat, pixelformat_name),
998 f->fmt.pix.field);
999 return ret;
1000}
1001
1002static int zr364xx_vidioc_reqbufs(struct file *file, void *priv,
1003 struct v4l2_requestbuffers *p)
1004{
1005 int rc;
1006 struct zr364xx_camera *cam = video_drvdata(file);
1007 rc = videobuf_reqbufs(&cam->vb_vidq, p);
1008 return rc;
1009}
1010
1011static int zr364xx_vidioc_querybuf(struct file *file,
1012 void *priv,
1013 struct v4l2_buffer *p)
1014{
1015 int rc;
1016 struct zr364xx_camera *cam = video_drvdata(file);
1017 rc = videobuf_querybuf(&cam->vb_vidq, p);
1018 return rc;
1019}
1020
1021static int zr364xx_vidioc_qbuf(struct file *file,
1022 void *priv,
1023 struct v4l2_buffer *p)
1024{
1025 int rc;
1026 struct zr364xx_camera *cam = video_drvdata(file);
1027 _DBG("%s\n", __func__);
1028 rc = videobuf_qbuf(&cam->vb_vidq, p);
1029 return rc;
1030}
1031
1032static int zr364xx_vidioc_dqbuf(struct file *file,
1033 void *priv,
1034 struct v4l2_buffer *p)
1035{
1036 int rc;
1037 struct zr364xx_camera *cam = video_drvdata(file);
1038 _DBG("%s\n", __func__);
1039 rc = videobuf_dqbuf(&cam->vb_vidq, p, file->f_flags & O_NONBLOCK);
1040 return rc;
1041}
1042
1043static void read_pipe_completion(struct urb *purb)
1044{
1045 struct zr364xx_pipeinfo *pipe_info;
1046 struct zr364xx_camera *cam;
1047 int pipe;
1048
1049 pipe_info = purb->context;
1050 _DBG("%s %p, status %d\n", __func__, purb, purb->status);
1051 if (pipe_info == NULL) {
1052 printk(KERN_ERR KBUILD_MODNAME ": no context!\n");
1053 return;
1054 }
1055
1056 cam = pipe_info->cam;
1057 if (cam == NULL) {
1058 printk(KERN_ERR KBUILD_MODNAME ": no context!\n");
1059 return;
1060 }
1061
1062 /* if shutting down, do not resubmit, exit immediately */
1063 if (purb->status == -ESHUTDOWN) {
1064 DBG("%s, err shutdown\n", __func__);
1065 pipe_info->err_count++;
1066 return;
1067 }
1068
1069 if (pipe_info->state == 0) {
1070 DBG("exiting USB pipe\n");
1071 return;
1072 }
1073
1074 if (purb->actual_length < 0 ||
1075 purb->actual_length > pipe_info->transfer_size) {
1076 dev_err(&cam->udev->dev, "wrong number of bytes\n");
1077 return;
1078 }
1079
1080 if (purb->status == 0)
1081 zr364xx_read_video_callback(cam, pipe_info, purb);
1082 else {
1083 pipe_info->err_count++;
1084 DBG("%s: failed URB %d\n", __func__, purb->status);
1085 }
1086
1087 pipe = usb_rcvbulkpipe(cam->udev, cam->read_endpoint);
1088
1089 /* reuse urb */
1090 usb_fill_bulk_urb(pipe_info->stream_urb, cam->udev,
1091 pipe,
1092 pipe_info->transfer_buffer,
1093 pipe_info->transfer_size,
1094 read_pipe_completion, pipe_info);
1095
1096 if (pipe_info->state != 0) {
1097 purb->status = usb_submit_urb(pipe_info->stream_urb,
1098 GFP_ATOMIC);
1099
1100 if (purb->status)
1101 dev_err(&cam->udev->dev,
1102 "error submitting urb (error=%i)\n",
1103 purb->status);
1104 } else
1105 DBG("read pipe complete state 0\n");
1106}
1107
1108static int zr364xx_start_readpipe(struct zr364xx_camera *cam)
1109{
1110 int pipe;
1111 int retval;
1112 struct zr364xx_pipeinfo *pipe_info = cam->pipe;
1113 pipe = usb_rcvbulkpipe(cam->udev, cam->read_endpoint);
1114 DBG("%s: start pipe IN x%x\n", __func__, cam->read_endpoint);
1115
1116 pipe_info->state = 1;
1117 pipe_info->err_count = 0;
1118 pipe_info->stream_urb = usb_alloc_urb(0, GFP_KERNEL);
1119 if (!pipe_info->stream_urb) {
1120 dev_err(&cam->udev->dev, "ReadStream: Unable to alloc URB\n");
1121 return -ENOMEM;
1122 }
1123 /* transfer buffer allocated in board_init */
1124 usb_fill_bulk_urb(pipe_info->stream_urb, cam->udev,
1125 pipe,
1126 pipe_info->transfer_buffer,
1127 pipe_info->transfer_size,
1128 read_pipe_completion, pipe_info);
1129
1130 DBG("submitting URB %p\n", pipe_info->stream_urb);
1131 retval = usb_submit_urb(pipe_info->stream_urb, GFP_KERNEL);
1132 if (retval) {
1133 printk(KERN_ERR KBUILD_MODNAME ": start read pipe failed\n");
1134 return retval;
1135 }
1136
1137 return 0;
1138}
1139
1140static void zr364xx_stop_readpipe(struct zr364xx_camera *cam)
1141{
1142 struct zr364xx_pipeinfo *pipe_info;
1143
1144 if (cam == NULL) {
1145 printk(KERN_ERR KBUILD_MODNAME ": invalid device\n");
1146 return;
1147 }
1148 DBG("stop read pipe\n");
1149 pipe_info = cam->pipe;
1150 if (pipe_info) {
1151 if (pipe_info->state != 0)
1152 pipe_info->state = 0;
1153
1154 if (pipe_info->stream_urb) {
1155 /* cancel urb */
1156 usb_kill_urb(pipe_info->stream_urb);
1157 usb_free_urb(pipe_info->stream_urb);
1158 pipe_info->stream_urb = NULL;
1159 }
1160 }
1161 return;
1162}
1163
1164/* starts acquisition process */
1165static int zr364xx_start_acquire(struct zr364xx_camera *cam)
1166{
1167 int j;
1168
1169 DBG("start acquire\n");
1170
1171 cam->last_frame = -1;
1172 cam->cur_frame = 0;
1173 for (j = 0; j < FRAMES; j++) {
1174 cam->buffer.frame[j].ulState = ZR364XX_READ_IDLE;
1175 cam->buffer.frame[j].cur_size = 0;
1176 }
1177 cam->b_acquire = 1;
1178 return 0;
1179}
1180
1181static inline int zr364xx_stop_acquire(struct zr364xx_camera *cam)
1182{
1183 cam->b_acquire = 0;
604 return 0; 1184 return 0;
605} 1185}
606 1186
607static int zr364xx_vidioc_streamon(struct file *file, void *priv, 1187static int zr364xx_vidioc_streamon(struct file *file, void *priv,
608 enum v4l2_buf_type type) 1188 enum v4l2_buf_type type)
609{ 1189{
610 return 0; 1190 struct zr364xx_camera *cam = video_drvdata(file);
1191 int j;
1192 int res;
1193
1194 DBG("%s\n", __func__);
1195
1196 if (cam->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1197 dev_err(&cam->udev->dev, "invalid fh type0\n");
1198 return -EINVAL;
1199 }
1200 if (cam->type != type) {
1201 dev_err(&cam->udev->dev, "invalid fh type1\n");
1202 return -EINVAL;
1203 }
1204
1205 if (!res_get(cam)) {
1206 dev_err(&cam->udev->dev, "stream busy\n");
1207 return -EBUSY;
1208 }
1209
1210 cam->last_frame = -1;
1211 cam->cur_frame = 0;
1212 cam->frame_count = 0;
1213 for (j = 0; j < FRAMES; j++) {
1214 cam->buffer.frame[j].ulState = ZR364XX_READ_IDLE;
1215 cam->buffer.frame[j].cur_size = 0;
1216 }
1217 res = videobuf_streamon(&cam->vb_vidq);
1218 if (res == 0) {
1219 zr364xx_start_acquire(cam);
1220 } else {
1221 res_free(cam);
1222 }
1223 return res;
611} 1224}
612 1225
613static int zr364xx_vidioc_streamoff(struct file *file, void *priv, 1226static int zr364xx_vidioc_streamoff(struct file *file, void *priv,
614 enum v4l2_buf_type type) 1227 enum v4l2_buf_type type)
615{ 1228{
1229 int res;
1230 struct zr364xx_camera *cam = video_drvdata(file);
1231
1232 DBG("%s\n", __func__);
1233 if (cam->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1234 dev_err(&cam->udev->dev, "invalid fh type0\n");
1235 return -EINVAL;
1236 }
1237 if (cam->type != type) {
1238 dev_err(&cam->udev->dev, "invalid fh type1\n");
1239 return -EINVAL;
1240 }
1241 zr364xx_stop_acquire(cam);
1242 res = videobuf_streamoff(&cam->vb_vidq);
1243 if (res < 0)
1244 return res;
1245 res_free(cam);
616 return 0; 1246 return 0;
617} 1247}
618 1248
@@ -621,28 +1251,19 @@ static int zr364xx_vidioc_streamoff(struct file *file, void *priv,
621static int zr364xx_open(struct file *file) 1251static int zr364xx_open(struct file *file)
622{ 1252{
623 struct video_device *vdev = video_devdata(file); 1253 struct video_device *vdev = video_devdata(file);
624 struct zr364xx_camera *cam = video_get_drvdata(vdev); 1254 struct zr364xx_camera *cam = video_drvdata(file);
625 struct usb_device *udev = cam->udev; 1255 struct usb_device *udev = cam->udev;
626 int i, err; 1256 int i, err;
627 1257
628 DBG("zr364xx_open"); 1258 DBG("%s\n", __func__);
629 1259
630 mutex_lock(&cam->lock); 1260 mutex_lock(&cam->open_lock);
631 1261
632 if (cam->users) { 1262 if (cam->users) {
633 err = -EBUSY; 1263 err = -EBUSY;
634 goto out; 1264 goto out;
635 } 1265 }
636 1266
637 if (!cam->framebuf) {
638 cam->framebuf = vmalloc_32(MAX_FRAME_SIZE * FRAMES);
639 if (!cam->framebuf) {
640 dev_err(&cam->udev->dev, "vmalloc_32 failed!\n");
641 err = -ENOMEM;
642 goto out;
643 }
644 }
645
646 for (i = 0; init[cam->method][i].size != -1; i++) { 1267 for (i = 0; init[cam->method][i].size != -1; i++) {
647 err = 1268 err =
648 send_control_msg(udev, 1, init[cam->method][i].value, 1269 send_control_msg(udev, 1, init[cam->method][i].value,
@@ -658,6 +1279,14 @@ static int zr364xx_open(struct file *file)
658 cam->skip = 2; 1279 cam->skip = 2;
659 cam->users++; 1280 cam->users++;
660 file->private_data = vdev; 1281 file->private_data = vdev;
1282 cam->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1283 cam->fmt = formats;
1284
1285 videobuf_queue_vmalloc_init(&cam->vb_vidq, &zr364xx_video_qops,
1286 NULL, &cam->slock,
1287 cam->type,
1288 V4L2_FIELD_NONE,
1289 sizeof(struct zr364xx_buffer), cam);
661 1290
662 /* Added some delay here, since opening/closing the camera quickly, 1291 /* Added some delay here, since opening/closing the camera quickly,
663 * like Ekiga does during its startup, can crash the webcam 1292 * like Ekiga does during its startup, can crash the webcam
@@ -666,28 +1295,70 @@ static int zr364xx_open(struct file *file)
666 err = 0; 1295 err = 0;
667 1296
668out: 1297out:
669 mutex_unlock(&cam->lock); 1298 mutex_unlock(&cam->open_lock);
1299 DBG("%s: %d\n", __func__, err);
670 return err; 1300 return err;
671} 1301}
672 1302
1303static void zr364xx_destroy(struct zr364xx_camera *cam)
1304{
1305 unsigned long i;
1306
1307 if (!cam) {
1308 printk(KERN_ERR KBUILD_MODNAME ", %s: no device\n", __func__);
1309 return;
1310 }
1311 mutex_lock(&cam->open_lock);
1312 if (cam->vdev)
1313 video_unregister_device(cam->vdev);
1314 cam->vdev = NULL;
1315
1316 /* stops the read pipe if it is running */
1317 if (cam->b_acquire)
1318 zr364xx_stop_acquire(cam);
1319
1320 zr364xx_stop_readpipe(cam);
1321
1322 /* release sys buffers */
1323 for (i = 0; i < FRAMES; i++) {
1324 if (cam->buffer.frame[i].lpvbits) {
1325 DBG("vfree %p\n", cam->buffer.frame[i].lpvbits);
1326 vfree(cam->buffer.frame[i].lpvbits);
1327 }
1328 cam->buffer.frame[i].lpvbits = NULL;
1329 }
1330
1331 /* release transfer buffer */
1332 kfree(cam->pipe->transfer_buffer);
1333 cam->pipe->transfer_buffer = NULL;
1334 mutex_unlock(&cam->open_lock);
1335 kfree(cam);
1336 cam = NULL;
1337}
673 1338
674/* release the camera */ 1339/* release the camera */
675static int zr364xx_release(struct file *file) 1340static int zr364xx_release(struct file *file)
676{ 1341{
677 struct video_device *vdev = video_devdata(file);
678 struct zr364xx_camera *cam; 1342 struct zr364xx_camera *cam;
679 struct usb_device *udev; 1343 struct usb_device *udev;
680 int i, err; 1344 int i, err;
681 1345
682 DBG("zr364xx_release"); 1346 DBG("%s\n", __func__);
1347 cam = video_drvdata(file);
683 1348
684 if (vdev == NULL) 1349 if (!cam)
685 return -ENODEV; 1350 return -ENODEV;
686 cam = video_get_drvdata(vdev);
687 1351
1352 mutex_lock(&cam->open_lock);
688 udev = cam->udev; 1353 udev = cam->udev;
689 1354
690 mutex_lock(&cam->lock); 1355 /* turn off stream */
1356 if (res_check(cam)) {
1357 if (cam->b_acquire)
1358 zr364xx_stop_acquire(cam);
1359 videobuf_streamoff(&cam->vb_vidq);
1360 res_free(cam);
1361 }
691 1362
692 cam->users--; 1363 cam->users--;
693 file->private_data = NULL; 1364 file->private_data = NULL;
@@ -710,40 +1381,43 @@ static int zr364xx_release(struct file *file)
710 err = 0; 1381 err = 0;
711 1382
712out: 1383out:
713 mutex_unlock(&cam->lock); 1384 mutex_unlock(&cam->open_lock);
1385
714 return err; 1386 return err;
715} 1387}
716 1388
717 1389
718static int zr364xx_mmap(struct file *file, struct vm_area_struct *vma) 1390static int zr364xx_mmap(struct file *file, struct vm_area_struct *vma)
719{ 1391{
720 void *pos; 1392 struct zr364xx_camera *cam = video_drvdata(file);
721 unsigned long start = vma->vm_start; 1393 int ret;
722 unsigned long size = vma->vm_end - vma->vm_start;
723 struct video_device *vdev = video_devdata(file);
724 struct zr364xx_camera *cam;
725
726 DBG("zr364xx_mmap: %ld\n", size);
727 1394
728 if (vdev == NULL) 1395 if (cam == NULL) {
1396 DBG("%s: cam == NULL\n", __func__);
729 return -ENODEV; 1397 return -ENODEV;
730 cam = video_get_drvdata(vdev);
731
732 pos = cam->framebuf;
733 while (size > 0) {
734 if (vm_insert_page(vma, start, vmalloc_to_page(pos)))
735 return -EAGAIN;
736 start += PAGE_SIZE;
737 pos += PAGE_SIZE;
738 if (size > PAGE_SIZE)
739 size -= PAGE_SIZE;
740 else
741 size = 0;
742 } 1398 }
1399 DBG("mmap called, vma=0x%08lx\n", (unsigned long)vma);
743 1400
744 return 0; 1401 ret = videobuf_mmap_mapper(&cam->vb_vidq, vma);
1402
1403 DBG("vma start=0x%08lx, size=%ld, ret=%d\n",
1404 (unsigned long)vma->vm_start,
1405 (unsigned long)vma->vm_end - (unsigned long)vma->vm_start, ret);
1406 return ret;
745} 1407}
746 1408
1409static unsigned int zr364xx_poll(struct file *file,
1410 struct poll_table_struct *wait)
1411{
1412 struct zr364xx_camera *cam = video_drvdata(file);
1413 struct videobuf_queue *q = &cam->vb_vidq;
1414 _DBG("%s\n", __func__);
1415
1416 if (cam->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1417 return POLLERR;
1418
1419 return videobuf_poll_stream(file, q, wait);
1420}
747 1421
748static const struct v4l2_file_operations zr364xx_fops = { 1422static const struct v4l2_file_operations zr364xx_fops = {
749 .owner = THIS_MODULE, 1423 .owner = THIS_MODULE,
@@ -752,6 +1426,7 @@ static const struct v4l2_file_operations zr364xx_fops = {
752 .read = zr364xx_read, 1426 .read = zr364xx_read,
753 .mmap = zr364xx_mmap, 1427 .mmap = zr364xx_mmap,
754 .ioctl = video_ioctl2, 1428 .ioctl = video_ioctl2,
1429 .poll = zr364xx_poll,
755}; 1430};
756 1431
757static const struct v4l2_ioctl_ops zr364xx_ioctl_ops = { 1432static const struct v4l2_ioctl_ops zr364xx_ioctl_ops = {
@@ -768,6 +1443,10 @@ static const struct v4l2_ioctl_ops zr364xx_ioctl_ops = {
768 .vidioc_queryctrl = zr364xx_vidioc_queryctrl, 1443 .vidioc_queryctrl = zr364xx_vidioc_queryctrl,
769 .vidioc_g_ctrl = zr364xx_vidioc_g_ctrl, 1444 .vidioc_g_ctrl = zr364xx_vidioc_g_ctrl,
770 .vidioc_s_ctrl = zr364xx_vidioc_s_ctrl, 1445 .vidioc_s_ctrl = zr364xx_vidioc_s_ctrl,
1446 .vidioc_reqbufs = zr364xx_vidioc_reqbufs,
1447 .vidioc_querybuf = zr364xx_vidioc_querybuf,
1448 .vidioc_qbuf = zr364xx_vidioc_qbuf,
1449 .vidioc_dqbuf = zr364xx_vidioc_dqbuf,
771}; 1450};
772 1451
773static struct video_device zr364xx_template = { 1452static struct video_device zr364xx_template = {
@@ -783,15 +1462,76 @@ static struct video_device zr364xx_template = {
783/*******************/ 1462/*******************/
784/* USB integration */ 1463/* USB integration */
785/*******************/ 1464/*******************/
1465static int zr364xx_board_init(struct zr364xx_camera *cam)
1466{
1467 struct zr364xx_pipeinfo *pipe = cam->pipe;
1468 unsigned long i;
1469
1470 DBG("board init: %p\n", cam);
1471 memset(pipe, 0, sizeof(*pipe));
1472 pipe->cam = cam;
1473 pipe->transfer_size = BUFFER_SIZE;
1474
1475 pipe->transfer_buffer = kzalloc(pipe->transfer_size,
1476 GFP_KERNEL);
1477 if (pipe->transfer_buffer == NULL) {
1478 DBG("out of memory!\n");
1479 return -ENOMEM;
1480 }
1481
1482 cam->b_acquire = 0;
1483 cam->frame_count = 0;
1484
1485 /*** start create system buffers ***/
1486 for (i = 0; i < FRAMES; i++) {
1487 /* always allocate maximum size for system buffers */
1488 cam->buffer.frame[i].lpvbits = vmalloc(MAX_FRAME_SIZE);
1489
1490 DBG("valloc %p, idx %lu, pdata %p\n",
1491 &cam->buffer.frame[i], i,
1492 cam->buffer.frame[i].lpvbits);
1493 if (cam->buffer.frame[i].lpvbits == NULL) {
1494 printk(KERN_INFO KBUILD_MODNAME ": out of memory. "
1495 "Using less frames\n");
1496 break;
1497 }
1498 }
1499
1500 if (i == 0) {
1501 printk(KERN_INFO KBUILD_MODNAME ": out of memory. Aborting\n");
1502 kfree(cam->pipe->transfer_buffer);
1503 cam->pipe->transfer_buffer = NULL;
1504 return -ENOMEM;
1505 } else
1506 cam->buffer.dwFrames = i;
1507
1508 /* make sure internal states are set */
1509 for (i = 0; i < FRAMES; i++) {
1510 cam->buffer.frame[i].ulState = ZR364XX_READ_IDLE;
1511 cam->buffer.frame[i].cur_size = 0;
1512 }
1513
1514 cam->cur_frame = 0;
1515 cam->last_frame = -1;
1516 /*** end create system buffers ***/
1517
1518 /* start read pipe */
1519 zr364xx_start_readpipe(cam);
1520 DBG(": board initialized\n");
1521 return 0;
1522}
786 1523
787static int zr364xx_probe(struct usb_interface *intf, 1524static int zr364xx_probe(struct usb_interface *intf,
788 const struct usb_device_id *id) 1525 const struct usb_device_id *id)
789{ 1526{
790 struct usb_device *udev = interface_to_usbdev(intf); 1527 struct usb_device *udev = interface_to_usbdev(intf);
791 struct zr364xx_camera *cam = NULL; 1528 struct zr364xx_camera *cam = NULL;
1529 struct usb_host_interface *iface_desc;
1530 struct usb_endpoint_descriptor *endpoint;
792 int err; 1531 int err;
1532 int i;
793 1533
794 DBG("probing..."); 1534 DBG("probing...\n");
795 1535
796 dev_info(&intf->dev, DRIVER_DESC " compatible webcam plugged\n"); 1536 dev_info(&intf->dev, DRIVER_DESC " compatible webcam plugged\n");
797 dev_info(&intf->dev, "model %04x:%04x detected\n", 1537 dev_info(&intf->dev, "model %04x:%04x detected\n",
@@ -810,22 +1550,17 @@ static int zr364xx_probe(struct usb_interface *intf,
810 if (cam->vdev == NULL) { 1550 if (cam->vdev == NULL) {
811 dev_err(&udev->dev, "cam->vdev: out of memory !\n"); 1551 dev_err(&udev->dev, "cam->vdev: out of memory !\n");
812 kfree(cam); 1552 kfree(cam);
1553 cam = NULL;
813 return -ENOMEM; 1554 return -ENOMEM;
814 } 1555 }
815 memcpy(cam->vdev, &zr364xx_template, sizeof(zr364xx_template)); 1556 memcpy(cam->vdev, &zr364xx_template, sizeof(zr364xx_template));
1557 cam->vdev->parent = &intf->dev;
816 video_set_drvdata(cam->vdev, cam); 1558 video_set_drvdata(cam->vdev, cam);
817 if (debug) 1559 if (debug)
818 cam->vdev->debug = V4L2_DEBUG_IOCTL | V4L2_DEBUG_IOCTL_ARG; 1560 cam->vdev->debug = V4L2_DEBUG_IOCTL | V4L2_DEBUG_IOCTL_ARG;
819 1561
820 cam->udev = udev; 1562 cam->udev = udev;
821 1563
822 if ((cam->buffer = kmalloc(BUFFER_SIZE, GFP_KERNEL)) == NULL) {
823 dev_info(&udev->dev, "cam->buffer: out of memory !\n");
824 video_device_release(cam->vdev);
825 kfree(cam);
826 return -ENODEV;
827 }
828
829 switch (mode) { 1564 switch (mode) {
830 case 1: 1565 case 1:
831 dev_info(&udev->dev, "160x120 mode selected\n"); 1566 dev_info(&udev->dev, "160x120 mode selected\n");
@@ -852,21 +1587,53 @@ static int zr364xx_probe(struct usb_interface *intf,
852 header2[439] = cam->width / 256; 1587 header2[439] = cam->width / 256;
853 header2[440] = cam->width % 256; 1588 header2[440] = cam->width % 256;
854 1589
1590 cam->users = 0;
855 cam->nb = 0; 1591 cam->nb = 0;
856 cam->brightness = 64; 1592 cam->mode.brightness = 64;
857 mutex_init(&cam->lock); 1593 mutex_init(&cam->lock);
1594 mutex_init(&cam->open_lock);
1595
1596 DBG("dev: %p, udev %p interface %p\n", cam, cam->udev, intf);
1597
1598 /* set up the endpoint information */
1599 iface_desc = intf->cur_altsetting;
1600 DBG("num endpoints %d\n", iface_desc->desc.bNumEndpoints);
1601 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
1602 endpoint = &iface_desc->endpoint[i].desc;
1603 if (!cam->read_endpoint && usb_endpoint_is_bulk_in(endpoint)) {
1604 /* we found the bulk in endpoint */
1605 cam->read_endpoint = endpoint->bEndpointAddress;
1606 }
1607 }
1608
1609 if (!cam->read_endpoint) {
1610 dev_err(&intf->dev, "Could not find bulk-in endpoint\n");
1611 return -ENOMEM;
1612 }
858 1613
1614 /* v4l */
1615 INIT_LIST_HEAD(&cam->vidq.active);
1616 cam->vidq.cam = cam;
859 err = video_register_device(cam->vdev, VFL_TYPE_GRABBER, -1); 1617 err = video_register_device(cam->vdev, VFL_TYPE_GRABBER, -1);
860 if (err) { 1618 if (err) {
861 dev_err(&udev->dev, "video_register_device failed\n"); 1619 dev_err(&udev->dev, "video_register_device failed\n");
862 video_device_release(cam->vdev); 1620 video_device_release(cam->vdev);
863 kfree(cam->buffer);
864 kfree(cam); 1621 kfree(cam);
1622 cam = NULL;
865 return err; 1623 return err;
866 } 1624 }
867 1625
868 usb_set_intfdata(intf, cam); 1626 usb_set_intfdata(intf, cam);
869 1627
1628 /* load zr364xx board specific */
1629 err = zr364xx_board_init(cam);
1630 if (err) {
1631 spin_lock_init(&cam->slock);
1632 return err;
1633 }
1634
1635 spin_lock_init(&cam->slock);
1636
870 dev_info(&udev->dev, DRIVER_DESC " controlling video device %d\n", 1637 dev_info(&udev->dev, DRIVER_DESC " controlling video device %d\n",
871 cam->vdev->num); 1638 cam->vdev->num);
872 return 0; 1639 return 0;
@@ -876,17 +1643,10 @@ static int zr364xx_probe(struct usb_interface *intf,
876static void zr364xx_disconnect(struct usb_interface *intf) 1643static void zr364xx_disconnect(struct usb_interface *intf)
877{ 1644{
878 struct zr364xx_camera *cam = usb_get_intfdata(intf); 1645 struct zr364xx_camera *cam = usb_get_intfdata(intf);
1646 videobuf_mmap_free(&cam->vb_vidq);
879 usb_set_intfdata(intf, NULL); 1647 usb_set_intfdata(intf, NULL);
880 dev_info(&intf->dev, DRIVER_DESC " webcam unplugged\n"); 1648 dev_info(&intf->dev, DRIVER_DESC " webcam unplugged\n");
881 if (cam->vdev) 1649 zr364xx_destroy(cam);
882 video_unregister_device(cam->vdev);
883 cam->vdev = NULL;
884 kfree(cam->buffer);
885 cam->buffer = NULL;
886 vfree(cam->framebuf);
887 cam->framebuf = NULL;
888 kfree(cam);
889 cam = NULL;
890} 1650}
891 1651
892 1652