diff options
Diffstat (limited to 'drivers/media/video/em28xx')
-rw-r--r-- | drivers/media/video/em28xx/Kconfig | 14 | ||||
-rw-r--r-- | drivers/media/video/em28xx/Makefile | 1 | ||||
-rw-r--r-- | drivers/media/video/em28xx/em28xx-audio.c | 2 | ||||
-rw-r--r-- | drivers/media/video/em28xx/em28xx-cards.c | 207 | ||||
-rw-r--r-- | drivers/media/video/em28xx/em28xx-core.c | 776 | ||||
-rw-r--r-- | drivers/media/video/em28xx/em28xx-dvb.c | 474 | ||||
-rw-r--r-- | drivers/media/video/em28xx/em28xx-i2c.c | 160 | ||||
-rw-r--r-- | drivers/media/video/em28xx/em28xx-input.c | 26 | ||||
-rw-r--r-- | drivers/media/video/em28xx/em28xx-reg.h | 88 | ||||
-rw-r--r-- | drivers/media/video/em28xx/em28xx-video.c | 1078 | ||||
-rw-r--r-- | drivers/media/video/em28xx/em28xx.h | 318 |
11 files changed, 1856 insertions, 1288 deletions
diff --git a/drivers/media/video/em28xx/Kconfig b/drivers/media/video/em28xx/Kconfig index 0f7a0bd86ff4..9caffed2b6b8 100644 --- a/drivers/media/video/em28xx/Kconfig +++ b/drivers/media/video/em28xx/Kconfig | |||
@@ -1,11 +1,13 @@ | |||
1 | config VIDEO_EM28XX | 1 | config VIDEO_EM28XX |
2 | tristate "Empia EM2800/2820/2840 USB video capture support" | 2 | tristate "Empia EM28xx USB video capture support" |
3 | depends on VIDEO_DEV && I2C && INPUT | 3 | depends on VIDEO_DEV && I2C && INPUT |
4 | select VIDEO_TUNER | 4 | select VIDEO_TUNER |
5 | select VIDEO_TVEEPROM | 5 | select VIDEO_TVEEPROM |
6 | select VIDEO_IR | 6 | select VIDEO_IR |
7 | select VIDEOBUF_VMALLOC | ||
7 | select VIDEO_SAA711X if VIDEO_HELPER_CHIPS_AUTO | 8 | select VIDEO_SAA711X if VIDEO_HELPER_CHIPS_AUTO |
8 | select VIDEO_TVP5150 if VIDEO_HELPER_CHIPS_AUTO | 9 | select VIDEO_TVP5150 if VIDEO_HELPER_CHIPS_AUTO |
10 | select VIDEO_MSP3400 if VIDEO_HELPER_CHIPS_AUTO | ||
9 | ---help--- | 11 | ---help--- |
10 | This is a video4linux driver for Empia 28xx based TV cards. | 12 | This is a video4linux driver for Empia 28xx based TV cards. |
11 | 13 | ||
@@ -27,3 +29,13 @@ config VIDEO_EM28XX_ALSA | |||
27 | To compile this driver as a module, choose M here: the | 29 | To compile this driver as a module, choose M here: the |
28 | module will be called em28xx-alsa | 30 | module will be called em28xx-alsa |
29 | 31 | ||
32 | config VIDEO_EM28XX_DVB | ||
33 | tristate "DVB/ATSC Support for em28xx based TV cards" | ||
34 | depends on VIDEO_EM28XX && DVB_CORE | ||
35 | select DVB_LGDT330X if !DVB_FE_CUSTOMISE | ||
36 | select DVB_ZL10353 if !DVB_FE_CUSTOMISE | ||
37 | select VIDEOBUF_DVB | ||
38 | select FW_LOADER | ||
39 | ---help--- | ||
40 | This adds support for DVB cards based on the | ||
41 | Empiatech em28xx chips. | ||
diff --git a/drivers/media/video/em28xx/Makefile b/drivers/media/video/em28xx/Makefile index 0924550992d0..3d1c3cc337fe 100644 --- a/drivers/media/video/em28xx/Makefile +++ b/drivers/media/video/em28xx/Makefile | |||
@@ -5,6 +5,7 @@ em28xx-alsa-objs := em28xx-audio.o | |||
5 | 5 | ||
6 | obj-$(CONFIG_VIDEO_EM28XX) += em28xx.o | 6 | obj-$(CONFIG_VIDEO_EM28XX) += em28xx.o |
7 | obj-$(CONFIG_VIDEO_EM28XX_ALSA) += em28xx-alsa.o | 7 | obj-$(CONFIG_VIDEO_EM28XX_ALSA) += em28xx-alsa.o |
8 | obj-$(CONFIG_VIDEO_EM28XX_DVB) += em28xx-dvb.o | ||
8 | 9 | ||
9 | EXTRA_CFLAGS += -Idrivers/media/video | 10 | EXTRA_CFLAGS += -Idrivers/media/video |
10 | EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core | 11 | EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core |
diff --git a/drivers/media/video/em28xx/em28xx-audio.c b/drivers/media/video/em28xx/em28xx-audio.c index 8c67f678266a..92b2a6db4fdc 100644 --- a/drivers/media/video/em28xx/em28xx-audio.c +++ b/drivers/media/video/em28xx/em28xx-audio.c | |||
@@ -51,7 +51,7 @@ MODULE_PARM_DESC(debug, "activates debug info"); | |||
51 | #define dprintk(fmt, arg...) do { \ | 51 | #define dprintk(fmt, arg...) do { \ |
52 | if (debug) \ | 52 | if (debug) \ |
53 | printk(KERN_INFO "em28xx-audio %s: " fmt, \ | 53 | printk(KERN_INFO "em28xx-audio %s: " fmt, \ |
54 | __FUNCTION__, ##arg); \ | 54 | __func__, ##arg); \ |
55 | } while (0) | 55 | } while (0) |
56 | 56 | ||
57 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; | 57 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; |
diff --git a/drivers/media/video/em28xx/em28xx-cards.c b/drivers/media/video/em28xx/em28xx-cards.c index aae7753fef11..50ccf3771204 100644 --- a/drivers/media/video/em28xx/em28xx-cards.c +++ b/drivers/media/video/em28xx/em28xx-cards.c | |||
@@ -36,7 +36,6 @@ | |||
36 | #include <media/v4l2-common.h> | 36 | #include <media/v4l2-common.h> |
37 | 37 | ||
38 | #include "em28xx.h" | 38 | #include "em28xx.h" |
39 | #include "tuner-xc2028.h" | ||
40 | 39 | ||
41 | static int tuner = -1; | 40 | static int tuner = -1; |
42 | module_param(tuner, int, 0444); | 41 | module_param(tuner, int, 0444); |
@@ -52,26 +51,6 @@ struct em28xx_hash_table { | |||
52 | unsigned int tuner; | 51 | unsigned int tuner; |
53 | }; | 52 | }; |
54 | 53 | ||
55 | /* Boards supported by driver */ | ||
56 | |||
57 | #define EM2800_BOARD_UNKNOWN 0 | ||
58 | #define EM2820_BOARD_UNKNOWN 1 | ||
59 | #define EM2820_BOARD_TERRATEC_CINERGY_250 2 | ||
60 | #define EM2820_BOARD_PINNACLE_USB_2 3 | ||
61 | #define EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 4 | ||
62 | #define EM2820_BOARD_MSI_VOX_USB_2 5 | ||
63 | #define EM2800_BOARD_TERRATEC_CINERGY_200 6 | ||
64 | #define EM2800_BOARD_LEADTEK_WINFAST_USBII 7 | ||
65 | #define EM2800_BOARD_KWORLD_USB2800 8 | ||
66 | #define EM2820_BOARD_PINNACLE_DVC_90 9 | ||
67 | #define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900 10 | ||
68 | #define EM2880_BOARD_TERRATEC_HYBRID_XS 11 | ||
69 | #define EM2820_BOARD_KWORLD_PVRTV2800RF 12 | ||
70 | #define EM2880_BOARD_TERRATEC_PRODIGY_XS 13 | ||
71 | #define EM2820_BOARD_PROLINK_PLAYTV_USB2 14 | ||
72 | #define EM2800_BOARD_VGEAR_POCKETTV 15 | ||
73 | #define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950 16 | ||
74 | |||
75 | struct em28xx_board em28xx_boards[] = { | 54 | struct em28xx_board em28xx_boards[] = { |
76 | [EM2800_BOARD_UNKNOWN] = { | 55 | [EM2800_BOARD_UNKNOWN] = { |
77 | .name = "Unknown EM2800 video grabber", | 56 | .name = "Unknown EM2800 video grabber", |
@@ -200,6 +179,7 @@ struct em28xx_board em28xx_boards[] = { | |||
200 | .tuner_type = TUNER_XC2028, | 179 | .tuner_type = TUNER_XC2028, |
201 | .mts_firmware = 1, | 180 | .mts_firmware = 1, |
202 | .has_12mhz_i2s = 1, | 181 | .has_12mhz_i2s = 1, |
182 | .has_dvb = 1, | ||
203 | .decoder = EM28XX_TVP5150, | 183 | .decoder = EM28XX_TVP5150, |
204 | .input = { { | 184 | .input = { { |
205 | .type = EM28XX_VMUX_TELEVISION, | 185 | .type = EM28XX_VMUX_TELEVISION, |
@@ -214,9 +194,6 @@ struct em28xx_board em28xx_boards[] = { | |||
214 | .vmux = TVP5150_SVIDEO, | 194 | .vmux = TVP5150_SVIDEO, |
215 | .amux = 1, | 195 | .amux = 1, |
216 | } }, | 196 | } }, |
217 | |||
218 | /* gpio's 4, 1, 0 */ | ||
219 | .analog_gpio = 0x003d2d, | ||
220 | }, | 197 | }, |
221 | [EM2880_BOARD_TERRATEC_HYBRID_XS] = { | 198 | [EM2880_BOARD_TERRATEC_HYBRID_XS] = { |
222 | .name = "Terratec Hybrid XS", | 199 | .name = "Terratec Hybrid XS", |
@@ -331,7 +308,7 @@ struct em28xx_board em28xx_boards[] = { | |||
331 | .name = "Kworld USB2800", | 308 | .name = "Kworld USB2800", |
332 | .is_em2800 = 1, | 309 | .is_em2800 = 1, |
333 | .vchannels = 3, | 310 | .vchannels = 3, |
334 | .tuner_type = TUNER_PHILIPS_ATSC, | 311 | .tuner_type = TUNER_PHILIPS_FCV1236D, |
335 | .tda9887_conf = TDA9887_PRESENT, | 312 | .tda9887_conf = TDA9887_PRESENT, |
336 | .decoder = EM28XX_SAA7113, | 313 | .decoder = EM28XX_SAA7113, |
337 | .input = { { | 314 | .input = { { |
@@ -453,7 +430,36 @@ struct usb_device_id em28xx_id_table [] = { | |||
453 | }; | 430 | }; |
454 | MODULE_DEVICE_TABLE(usb, em28xx_id_table); | 431 | MODULE_DEVICE_TABLE(usb, em28xx_id_table); |
455 | 432 | ||
456 | /* EEPROM hash table for devices with generic USB IDs */ | 433 | /* |
434 | * Reset sequences for analog/digital modes | ||
435 | */ | ||
436 | |||
437 | /* Board Hauppauge WinTV HVR 900 analog */ | ||
438 | static struct em28xx_reg_seq hauppauge_wintv_hvr_900_analog[] = { | ||
439 | {EM28XX_R08_GPIO, 0x2d, ~EM_GPIO_4, 10}, | ||
440 | {0x05, 0xff, 0x10, 10}, | ||
441 | { -1, -1, -1, -1}, | ||
442 | }; | ||
443 | |||
444 | /* Board Hauppauge WinTV HVR 900 digital */ | ||
445 | static struct em28xx_reg_seq hauppauge_wintv_hvr_900_digital[] = { | ||
446 | {EM28XX_R08_GPIO, 0x2e, ~EM_GPIO_4, 10}, | ||
447 | {EM2880_R04_GPO, 0x04, 0x0f, 10}, | ||
448 | {EM2880_R04_GPO, 0x0c, 0x0f, 10}, | ||
449 | { -1, -1, -1, -1}, | ||
450 | }; | ||
451 | |||
452 | /* Board Hauppauge WinTV HVR 900 tuner_callback */ | ||
453 | static struct em28xx_reg_seq hauppauge_wintv_hvr_900_tuner_callback[] = { | ||
454 | {EM28XX_R08_GPIO, EM_GPIO_4, EM_GPIO_4, 10}, | ||
455 | {EM28XX_R08_GPIO, 0, EM_GPIO_4, 10}, | ||
456 | {EM28XX_R08_GPIO, EM_GPIO_4, EM_GPIO_4, 10}, | ||
457 | { -1, -1, -1, -1}, | ||
458 | }; | ||
459 | |||
460 | /* | ||
461 | * EEPROM hash table for devices with generic USB IDs | ||
462 | */ | ||
457 | static struct em28xx_hash_table em28xx_eeprom_hash [] = { | 463 | static struct em28xx_hash_table em28xx_eeprom_hash [] = { |
458 | /* P/N: SA 60002070465 Tuner: TVF7533-MF */ | 464 | /* P/N: SA 60002070465 Tuner: TVF7533-MF */ |
459 | {0x6ce05a8f, EM2820_BOARD_PROLINK_PLAYTV_USB2, TUNER_YMEC_TVF_5533MF}, | 465 | {0x6ce05a8f, EM2820_BOARD_PROLINK_PLAYTV_USB2, TUNER_YMEC_TVF_5533MF}, |
@@ -465,79 +471,113 @@ static struct em28xx_hash_table em28xx_i2c_hash[] = { | |||
465 | {0xf51200e3, EM2800_BOARD_VGEAR_POCKETTV, TUNER_LG_PAL_NEW_TAPC}, | 471 | {0xf51200e3, EM2800_BOARD_VGEAR_POCKETTV, TUNER_LG_PAL_NEW_TAPC}, |
466 | }; | 472 | }; |
467 | 473 | ||
474 | int em28xx_tuner_callback(void *ptr, int command, int arg) | ||
475 | { | ||
476 | int rc = 0; | ||
477 | struct em28xx *dev = ptr; | ||
478 | |||
479 | if (dev->tuner_type != TUNER_XC2028) | ||
480 | return 0; | ||
481 | |||
482 | if (command != XC2028_TUNER_RESET) | ||
483 | return 0; | ||
484 | |||
485 | if (dev->mode == EM28XX_ANALOG_MODE) | ||
486 | rc = em28xx_gpio_set(dev, dev->tun_analog_gpio); | ||
487 | else | ||
488 | rc = em28xx_gpio_set(dev, dev->tun_digital_gpio); | ||
489 | |||
490 | return rc; | ||
491 | } | ||
492 | EXPORT_SYMBOL_GPL(em28xx_tuner_callback); | ||
493 | |||
494 | static void em28xx_set_model(struct em28xx *dev) | ||
495 | { | ||
496 | dev->is_em2800 = em28xx_boards[dev->model].is_em2800; | ||
497 | dev->has_msp34xx = em28xx_boards[dev->model].has_msp34xx; | ||
498 | dev->tda9887_conf = em28xx_boards[dev->model].tda9887_conf; | ||
499 | dev->decoder = em28xx_boards[dev->model].decoder; | ||
500 | dev->video_inputs = em28xx_boards[dev->model].vchannels; | ||
501 | dev->has_12mhz_i2s = em28xx_boards[dev->model].has_12mhz_i2s; | ||
502 | dev->max_range_640_480 = em28xx_boards[dev->model].max_range_640_480; | ||
503 | dev->has_dvb = em28xx_boards[dev->model].has_dvb; | ||
504 | } | ||
505 | |||
468 | /* Since em28xx_pre_card_setup() requires a proper dev->model, | 506 | /* Since em28xx_pre_card_setup() requires a proper dev->model, |
469 | * this won't work for boards with generic PCI IDs | 507 | * this won't work for boards with generic PCI IDs |
470 | */ | 508 | */ |
471 | void em28xx_pre_card_setup(struct em28xx *dev) | 509 | void em28xx_pre_card_setup(struct em28xx *dev) |
472 | { | 510 | { |
511 | int rc; | ||
512 | |||
513 | rc = em28xx_read_reg(dev, EM2880_R04_GPO); | ||
514 | if (rc >= 0) | ||
515 | dev->reg_gpo = rc; | ||
516 | |||
517 | dev->wait_after_write = 5; | ||
518 | rc = em28xx_read_reg(dev, EM28XX_R0A_CHIPID); | ||
519 | if (rc > 0) { | ||
520 | switch (rc) { | ||
521 | case CHIP_ID_EM2883: | ||
522 | em28xx_info("chip ID is em2882/em2883\n"); | ||
523 | dev->wait_after_write = 0; | ||
524 | break; | ||
525 | default: | ||
526 | em28xx_info("em28xx chip ID = %d\n", rc); | ||
527 | } | ||
528 | } | ||
529 | em28xx_set_model(dev); | ||
530 | |||
473 | /* request some modules */ | 531 | /* request some modules */ |
474 | switch (dev->model) { | 532 | switch (dev->model) { |
475 | case EM2880_BOARD_TERRATEC_PRODIGY_XS: | 533 | case EM2880_BOARD_TERRATEC_PRODIGY_XS: |
476 | case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900: | 534 | case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900: |
477 | case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950: | ||
478 | case EM2880_BOARD_TERRATEC_HYBRID_XS: | 535 | case EM2880_BOARD_TERRATEC_HYBRID_XS: |
479 | em28xx_write_regs(dev, XCLK_REG, "\x27", 1); | 536 | case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950: |
480 | em28xx_write_regs(dev, I2C_CLK_REG, "\x40", 1); | 537 | em28xx_write_regs(dev, EM28XX_R0F_XCLK, "\x27", 1); |
481 | em28xx_write_regs(dev, 0x08, "\xff", 1); | 538 | em28xx_write_regs(dev, EM28XX_R06_I2C_CLK, "\x40", 1); |
482 | em28xx_write_regs(dev, 0x04, "\x00", 1); | ||
483 | msleep(100); | ||
484 | em28xx_write_regs(dev, 0x04, "\x08", 1); | ||
485 | msleep(100); | ||
486 | em28xx_write_regs(dev, 0x08, "\xff", 1); | ||
487 | msleep(50); | ||
488 | em28xx_write_regs(dev, 0x08, "\x2d", 1); | ||
489 | msleep(50); | 539 | msleep(50); |
490 | em28xx_write_regs(dev, 0x08, "\x3d", 1); | 540 | |
541 | /* Sets GPO/GPIO sequences for this device */ | ||
542 | dev->analog_gpio = hauppauge_wintv_hvr_900_analog; | ||
543 | dev->digital_gpio = hauppauge_wintv_hvr_900_digital; | ||
544 | dev->tun_analog_gpio = hauppauge_wintv_hvr_900_tuner_callback; | ||
545 | dev->tun_digital_gpio = hauppauge_wintv_hvr_900_tuner_callback; | ||
546 | |||
491 | break; | 547 | break; |
492 | } | 548 | } |
549 | |||
550 | em28xx_gpio_set(dev, dev->tun_analog_gpio); | ||
551 | em28xx_set_mode(dev, EM28XX_ANALOG_MODE); | ||
552 | |||
553 | /* Unlock device */ | ||
554 | em28xx_set_mode(dev, EM28XX_MODE_UNDEFINED); | ||
493 | } | 555 | } |
494 | 556 | ||
495 | static int em28xx_tuner_callback(void *ptr, int command, int arg) | 557 | static void em28xx_setup_xc3028(struct em28xx *dev, struct xc2028_ctrl *ctl) |
496 | { | 558 | { |
497 | int rc = 0; | 559 | memset(ctl, 0, sizeof(*ctl)); |
498 | struct em28xx *dev = ptr; | ||
499 | 560 | ||
500 | if (dev->tuner_type != TUNER_XC2028) | 561 | ctl->fname = XC2028_DEFAULT_FIRMWARE; |
501 | return 0; | 562 | ctl->max_len = 64; |
502 | 563 | ctl->mts = em28xx_boards[dev->model].mts_firmware; | |
503 | switch (command) { | ||
504 | case XC2028_TUNER_RESET: | ||
505 | { | ||
506 | /* GPIO and initialization codes for analog TV and radio | ||
507 | This code should be complemented for DTV, since reset | ||
508 | codes are different. | ||
509 | */ | ||
510 | |||
511 | dev->em28xx_write_regs_req(dev, 0x00, 0x48, "\x00", 1); | ||
512 | dev->em28xx_write_regs_req(dev, 0x00, 0x12, "\x67", 1); | ||
513 | |||
514 | if (dev->analog_gpio) { | ||
515 | char gpio0 = dev->analog_gpio & 0xff; | ||
516 | char gpio1 = (dev->analog_gpio >> 8) & 0xff; | ||
517 | char gpio4 = dev->analog_gpio >> 24; | ||
518 | |||
519 | if (gpio4) { | ||
520 | dev->em28xx_write_regs(dev, 0x04, &gpio4, 1); | ||
521 | msleep(140); | ||
522 | } | ||
523 | |||
524 | msleep(6); | ||
525 | dev->em28xx_write_regs(dev, 0x08, &gpio0, 1); | ||
526 | msleep(10); | ||
527 | dev->em28xx_write_regs(dev, 0x08, &gpio1, 1); | ||
528 | msleep(5); | ||
529 | } | ||
530 | 564 | ||
565 | switch (dev->model) { | ||
566 | case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900: | ||
567 | ctl->demod = XC3028_FE_ZARLINK456; | ||
531 | break; | 568 | break; |
569 | case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950: | ||
570 | /* FIXME: Better to specify the needed IF */ | ||
571 | ctl->demod = XC3028_FE_DEFAULT; | ||
572 | break; | ||
573 | default: | ||
574 | ctl->demod = XC3028_FE_OREN538; | ||
532 | } | 575 | } |
533 | } | ||
534 | return rc; | ||
535 | } | 576 | } |
536 | 577 | ||
537 | static void em28xx_config_tuner(struct em28xx *dev) | 578 | static void em28xx_config_tuner(struct em28xx *dev) |
538 | { | 579 | { |
539 | struct v4l2_priv_tun_config xc2028_cfg; | 580 | struct v4l2_priv_tun_config xc2028_cfg; |
540 | struct xc2028_ctrl ctl; | ||
541 | struct tuner_setup tun_setup; | 581 | struct tuner_setup tun_setup; |
542 | struct v4l2_frequency f; | 582 | struct v4l2_frequency f; |
543 | 583 | ||
@@ -552,11 +592,9 @@ static void em28xx_config_tuner(struct em28xx *dev) | |||
552 | em28xx_i2c_call_clients(dev, TUNER_SET_TYPE_ADDR, &tun_setup); | 592 | em28xx_i2c_call_clients(dev, TUNER_SET_TYPE_ADDR, &tun_setup); |
553 | 593 | ||
554 | if (dev->tuner_type == TUNER_XC2028) { | 594 | if (dev->tuner_type == TUNER_XC2028) { |
555 | memset(&ctl, 0, sizeof(ctl)); | 595 | struct xc2028_ctrl ctl; |
556 | 596 | ||
557 | ctl.fname = XC2028_DEFAULT_FIRMWARE; | 597 | em28xx_setup_xc3028(dev, &ctl); |
558 | ctl.max_len = 64; | ||
559 | ctl.mts = em28xx_boards[dev->model].mts_firmware; | ||
560 | 598 | ||
561 | xc2028_cfg.tuner = TUNER_XC2028; | 599 | xc2028_cfg.tuner = TUNER_XC2028; |
562 | xc2028_cfg.priv = &ctl; | 600 | xc2028_cfg.priv = &ctl; |
@@ -654,19 +692,6 @@ static int em28xx_hint_board(struct em28xx *dev) | |||
654 | return -1; | 692 | return -1; |
655 | } | 693 | } |
656 | 694 | ||
657 | |||
658 | static void em28xx_set_model(struct em28xx *dev) | ||
659 | { | ||
660 | dev->is_em2800 = em28xx_boards[dev->model].is_em2800; | ||
661 | dev->has_msp34xx = em28xx_boards[dev->model].has_msp34xx; | ||
662 | dev->tda9887_conf = em28xx_boards[dev->model].tda9887_conf; | ||
663 | dev->decoder = em28xx_boards[dev->model].decoder; | ||
664 | dev->video_inputs = em28xx_boards[dev->model].vchannels; | ||
665 | dev->analog_gpio = em28xx_boards[dev->model].analog_gpio; | ||
666 | dev->has_12mhz_i2s = em28xx_boards[dev->model].has_12mhz_i2s; | ||
667 | dev->max_range_640_480 = em28xx_boards[dev->model].max_range_640_480; | ||
668 | } | ||
669 | |||
670 | /* ----------------------------------------------------------------------- */ | 695 | /* ----------------------------------------------------------------------- */ |
671 | void em28xx_set_ir(struct em28xx *dev, struct IR_i2c *ir) | 696 | void em28xx_set_ir(struct em28xx *dev, struct IR_i2c *ir) |
672 | { | 697 | { |
diff --git a/drivers/media/video/em28xx/em28xx-core.c b/drivers/media/video/em28xx/em28xx-core.c index c1caaa855b99..f8c41d8c74c4 100644 --- a/drivers/media/video/em28xx/em28xx-core.c +++ b/drivers/media/video/em28xx/em28xx-core.c | |||
@@ -31,104 +31,33 @@ | |||
31 | 31 | ||
32 | /* #define ENABLE_DEBUG_ISOC_FRAMES */ | 32 | /* #define ENABLE_DEBUG_ISOC_FRAMES */ |
33 | 33 | ||
34 | static unsigned int core_debug = 0; | 34 | static unsigned int core_debug; |
35 | module_param(core_debug,int,0644); | 35 | module_param(core_debug,int,0644); |
36 | MODULE_PARM_DESC(core_debug,"enable debug messages [core]"); | 36 | MODULE_PARM_DESC(core_debug,"enable debug messages [core]"); |
37 | 37 | ||
38 | #define em28xx_coredbg(fmt, arg...) do {\ | 38 | #define em28xx_coredbg(fmt, arg...) do {\ |
39 | if (core_debug) \ | 39 | if (core_debug) \ |
40 | printk(KERN_INFO "%s %s :"fmt, \ | 40 | printk(KERN_INFO "%s %s :"fmt, \ |
41 | dev->name, __FUNCTION__ , ##arg); } while (0) | 41 | dev->name, __func__ , ##arg); } while (0) |
42 | 42 | ||
43 | static unsigned int reg_debug = 0; | 43 | static unsigned int reg_debug; |
44 | module_param(reg_debug,int,0644); | 44 | module_param(reg_debug,int,0644); |
45 | MODULE_PARM_DESC(reg_debug,"enable debug messages [URB reg]"); | 45 | MODULE_PARM_DESC(reg_debug,"enable debug messages [URB reg]"); |
46 | 46 | ||
47 | #define em28xx_regdbg(fmt, arg...) do {\ | 47 | #define em28xx_regdbg(fmt, arg...) do {\ |
48 | if (reg_debug) \ | 48 | if (reg_debug) \ |
49 | printk(KERN_INFO "%s %s :"fmt, \ | 49 | printk(KERN_INFO "%s %s :"fmt, \ |
50 | dev->name, __FUNCTION__ , ##arg); } while (0) | 50 | dev->name, __func__ , ##arg); } while (0) |
51 | |||
52 | static unsigned int isoc_debug = 0; | ||
53 | module_param(isoc_debug,int,0644); | ||
54 | MODULE_PARM_DESC(isoc_debug,"enable debug messages [isoc transfers]"); | ||
55 | |||
56 | #define em28xx_isocdbg(fmt, arg...) do {\ | ||
57 | if (isoc_debug) \ | ||
58 | printk(KERN_INFO "%s %s :"fmt, \ | ||
59 | dev->name, __FUNCTION__ , ##arg); } while (0) | ||
60 | 51 | ||
61 | static int alt = EM28XX_PINOUT; | 52 | static int alt = EM28XX_PINOUT; |
62 | module_param(alt, int, 0644); | 53 | module_param(alt, int, 0644); |
63 | MODULE_PARM_DESC(alt, "alternate setting to use for video endpoint"); | 54 | MODULE_PARM_DESC(alt, "alternate setting to use for video endpoint"); |
64 | 55 | ||
65 | 56 | /* FIXME */ | |
66 | /* | 57 | #define em28xx_isocdbg(fmt, arg...) do {\ |
67 | * em28xx_request_buffers() | 58 | if (core_debug) \ |
68 | * allocate a number of buffers | 59 | printk(KERN_INFO "%s %s :"fmt, \ |
69 | */ | 60 | dev->name, __func__ , ##arg); } while (0) |
70 | u32 em28xx_request_buffers(struct em28xx *dev, u32 count) | ||
71 | { | ||
72 | const size_t imagesize = PAGE_ALIGN(dev->frame_size); /*needs to be page aligned cause the buffers can be mapped individually! */ | ||
73 | void *buff = NULL; | ||
74 | u32 i; | ||
75 | em28xx_coredbg("requested %i buffers with size %zi\n", | ||
76 | count, imagesize); | ||
77 | if (count > EM28XX_NUM_FRAMES) | ||
78 | count = EM28XX_NUM_FRAMES; | ||
79 | |||
80 | dev->num_frames = count; | ||
81 | while (dev->num_frames > 0) { | ||
82 | if ((buff = vmalloc_32(dev->num_frames * imagesize))) { | ||
83 | memset(buff, 0, dev->num_frames * imagesize); | ||
84 | break; | ||
85 | } | ||
86 | dev->num_frames--; | ||
87 | } | ||
88 | |||
89 | for (i = 0; i < dev->num_frames; i++) { | ||
90 | dev->frame[i].bufmem = buff + i * imagesize; | ||
91 | dev->frame[i].buf.index = i; | ||
92 | dev->frame[i].buf.m.offset = i * imagesize; | ||
93 | dev->frame[i].buf.length = dev->frame_size; | ||
94 | dev->frame[i].buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; | ||
95 | dev->frame[i].buf.sequence = 0; | ||
96 | dev->frame[i].buf.field = V4L2_FIELD_NONE; | ||
97 | dev->frame[i].buf.memory = V4L2_MEMORY_MMAP; | ||
98 | dev->frame[i].buf.flags = 0; | ||
99 | } | ||
100 | return dev->num_frames; | ||
101 | } | ||
102 | |||
103 | /* | ||
104 | * em28xx_queue_unusedframes() | ||
105 | * add all frames that are not currently in use to the inbuffer queue | ||
106 | */ | ||
107 | void em28xx_queue_unusedframes(struct em28xx *dev) | ||
108 | { | ||
109 | unsigned long lock_flags; | ||
110 | u32 i; | ||
111 | |||
112 | for (i = 0; i < dev->num_frames; i++) | ||
113 | if (dev->frame[i].state == F_UNUSED) { | ||
114 | dev->frame[i].state = F_QUEUED; | ||
115 | spin_lock_irqsave(&dev->queue_lock, lock_flags); | ||
116 | list_add_tail(&dev->frame[i].frame, &dev->inqueue); | ||
117 | spin_unlock_irqrestore(&dev->queue_lock, lock_flags); | ||
118 | } | ||
119 | } | ||
120 | |||
121 | /* | ||
122 | * em28xx_release_buffers() | ||
123 | * free frame buffers | ||
124 | */ | ||
125 | void em28xx_release_buffers(struct em28xx *dev) | ||
126 | { | ||
127 | if (dev->num_frames) { | ||
128 | vfree(dev->frame[0].bufmem); | ||
129 | dev->num_frames = 0; | ||
130 | } | ||
131 | } | ||
132 | 61 | ||
133 | /* | 62 | /* |
134 | * em28xx_read_reg_req() | 63 | * em28xx_read_reg_req() |
@@ -148,11 +77,11 @@ int em28xx_read_reg_req_len(struct em28xx *dev, u8 req, u16 reg, | |||
148 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | 77 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
149 | 0x0000, reg, buf, len, HZ); | 78 | 0x0000, reg, buf, len, HZ); |
150 | 79 | ||
151 | if (reg_debug){ | 80 | if (reg_debug) { |
152 | printk(ret < 0 ? " failed!\n" : "%02x values: ", ret); | 81 | printk(ret < 0 ? " failed!\n" : "%02x values: ", ret); |
153 | for (byte = 0; byte < len; byte++) { | 82 | for (byte = 0; byte < len; byte++) |
154 | printk(" %02x", (unsigned char)buf[byte]); | 83 | printk(" %02x", (unsigned char)buf[byte]); |
155 | } | 84 | |
156 | printk("\n"); | 85 | printk("\n"); |
157 | } | 86 | } |
158 | 87 | ||
@@ -205,7 +134,10 @@ int em28xx_write_regs_req(struct em28xx *dev, u8 req, u16 reg, char *buf, | |||
205 | unsigned char *bufs; | 134 | unsigned char *bufs; |
206 | 135 | ||
207 | if (dev->state & DEV_DISCONNECTED) | 136 | if (dev->state & DEV_DISCONNECTED) |
208 | return(-ENODEV); | 137 | return -ENODEV; |
138 | |||
139 | if (len < 1) | ||
140 | return -EINVAL; | ||
209 | 141 | ||
210 | bufs = kmalloc(len, GFP_KERNEL); | 142 | bufs = kmalloc(len, GFP_KERNEL); |
211 | 143 | ||
@@ -214,8 +146,8 @@ int em28xx_write_regs_req(struct em28xx *dev, u8 req, u16 reg, char *buf, | |||
214 | if (reg_debug) { | 146 | if (reg_debug) { |
215 | int i; | 147 | int i; |
216 | for (i = 0; i < len; ++i) | 148 | for (i = 0; i < len; ++i) |
217 | printk (" %02x", (unsigned char)buf[i]); | 149 | printk(" %02x", (unsigned char)buf[i]); |
218 | printk ("\n"); | 150 | printk("\n"); |
219 | } | 151 | } |
220 | 152 | ||
221 | if (!bufs) | 153 | if (!bufs) |
@@ -224,14 +156,32 @@ int em28xx_write_regs_req(struct em28xx *dev, u8 req, u16 reg, char *buf, | |||
224 | ret = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0), req, | 156 | ret = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0), req, |
225 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | 157 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
226 | 0x0000, reg, bufs, len, HZ); | 158 | 0x0000, reg, bufs, len, HZ); |
227 | msleep(5); /* FIXME: magic number */ | 159 | if (dev->wait_after_write) |
160 | msleep(dev->wait_after_write); | ||
161 | |||
228 | kfree(bufs); | 162 | kfree(bufs); |
229 | return ret; | 163 | return ret; |
230 | } | 164 | } |
231 | 165 | ||
232 | int em28xx_write_regs(struct em28xx *dev, u16 reg, char *buf, int len) | 166 | int em28xx_write_regs(struct em28xx *dev, u16 reg, char *buf, int len) |
233 | { | 167 | { |
234 | return em28xx_write_regs_req(dev, USB_REQ_GET_STATUS, reg, buf, len); | 168 | int rc; |
169 | |||
170 | rc = em28xx_write_regs_req(dev, USB_REQ_GET_STATUS, reg, buf, len); | ||
171 | |||
172 | /* Stores GPO/GPIO values at the cache, if changed | ||
173 | Only write values should be stored, since input on a GPIO | ||
174 | register will return the input bits. | ||
175 | Not sure what happens on reading GPO register. | ||
176 | */ | ||
177 | if (rc >= 0) { | ||
178 | if (reg == EM2880_R04_GPO) | ||
179 | dev->reg_gpo = buf[0]; | ||
180 | else if (reg == EM28XX_R08_GPIO) | ||
181 | dev->reg_gpio = buf[0]; | ||
182 | } | ||
183 | |||
184 | return rc; | ||
235 | } | 185 | } |
236 | 186 | ||
237 | /* | 187 | /* |
@@ -244,9 +194,20 @@ static int em28xx_write_reg_bits(struct em28xx *dev, u16 reg, u8 val, | |||
244 | { | 194 | { |
245 | int oldval; | 195 | int oldval; |
246 | u8 newval; | 196 | u8 newval; |
247 | if ((oldval = em28xx_read_reg(dev, reg)) < 0) | 197 | |
198 | /* Uses cache for gpo/gpio registers */ | ||
199 | if (reg == EM2880_R04_GPO) | ||
200 | oldval = dev->reg_gpo; | ||
201 | else if (reg == EM28XX_R08_GPIO) | ||
202 | oldval = dev->reg_gpio; | ||
203 | else | ||
204 | oldval = em28xx_read_reg(dev, reg); | ||
205 | |||
206 | if (oldval < 0) | ||
248 | return oldval; | 207 | return oldval; |
208 | |||
249 | newval = (((u8) oldval) & ~bitmask) | (val & bitmask); | 209 | newval = (((u8) oldval) & ~bitmask) | (val & bitmask); |
210 | |||
250 | return em28xx_write_regs(dev, reg, &newval, 1); | 211 | return em28xx_write_regs(dev, reg, &newval, 1); |
251 | } | 212 | } |
252 | 213 | ||
@@ -258,20 +219,26 @@ static int em28xx_write_ac97(struct em28xx *dev, u8 reg, u8 *val) | |||
258 | { | 219 | { |
259 | int ret, i; | 220 | int ret, i; |
260 | u8 addr = reg & 0x7f; | 221 | u8 addr = reg & 0x7f; |
261 | if ((ret = em28xx_write_regs(dev, AC97LSB_REG, val, 2)) < 0) | 222 | |
223 | ret = em28xx_write_regs(dev, EM28XX_R40_AC97LSB, val, 2); | ||
224 | if (ret < 0) | ||
262 | return ret; | 225 | return ret; |
263 | if ((ret = em28xx_write_regs(dev, AC97ADDR_REG, &addr, 1)) < 0) | 226 | |
227 | ret = em28xx_write_regs(dev, EM28XX_R42_AC97ADDR, &addr, 1); | ||
228 | if (ret < 0) | ||
264 | return ret; | 229 | return ret; |
265 | 230 | ||
266 | /* Wait up to 50 ms for AC97 command to complete */ | 231 | /* Wait up to 50 ms for AC97 command to complete */ |
267 | for (i = 0; i < 10; i++) { | 232 | for (i = 0; i < 10; i++) { |
268 | if ((ret = em28xx_read_reg(dev, AC97BUSY_REG)) < 0) | 233 | ret = em28xx_read_reg(dev, EM28XX_R43_AC97BUSY); |
234 | if (ret < 0) | ||
269 | return ret; | 235 | return ret; |
236 | |||
270 | if (!(ret & 0x01)) | 237 | if (!(ret & 0x01)) |
271 | return 0; | 238 | return 0; |
272 | msleep(5); | 239 | msleep(5); |
273 | } | 240 | } |
274 | em28xx_warn ("AC97 command still being executed: not handled properly!\n"); | 241 | em28xx_warn("AC97 command still being executed: not handled properly!\n"); |
275 | return 0; | 242 | return 0; |
276 | } | 243 | } |
277 | 244 | ||
@@ -289,7 +256,7 @@ static int em28xx_set_audio_source(struct em28xx *dev) | |||
289 | else | 256 | else |
290 | input = EM2800_AUDIO_SRC_TUNER; | 257 | input = EM2800_AUDIO_SRC_TUNER; |
291 | 258 | ||
292 | ret = em28xx_write_regs(dev, EM2800_AUDIOSRC_REG, &input, 1); | 259 | ret = em28xx_write_regs(dev, EM2800_R08_AUDIOSRC, &input, 1); |
293 | if (ret < 0) | 260 | if (ret < 0) |
294 | return ret; | 261 | return ret; |
295 | } | 262 | } |
@@ -315,7 +282,7 @@ static int em28xx_set_audio_source(struct em28xx *dev) | |||
315 | } | 282 | } |
316 | } | 283 | } |
317 | 284 | ||
318 | ret = em28xx_write_reg_bits(dev, AUDIOSRC_REG, input, 0xc0); | 285 | ret = em28xx_write_reg_bits(dev, EM28XX_R0E_AUDIOSRC, input, 0xc0); |
319 | if (ret < 0) | 286 | if (ret < 0) |
320 | return ret; | 287 | return ret; |
321 | msleep(5); | 288 | msleep(5); |
@@ -323,11 +290,11 @@ static int em28xx_set_audio_source(struct em28xx *dev) | |||
323 | /* Sets AC97 mixer registers | 290 | /* Sets AC97 mixer registers |
324 | This is seems to be needed, even for non-ac97 configs | 291 | This is seems to be needed, even for non-ac97 configs |
325 | */ | 292 | */ |
326 | ret = em28xx_write_ac97(dev, VIDEO_AC97, video); | 293 | ret = em28xx_write_ac97(dev, EM28XX_R14_VIDEO_AC97, video); |
327 | if (ret < 0) | 294 | if (ret < 0) |
328 | return ret; | 295 | return ret; |
329 | 296 | ||
330 | ret = em28xx_write_ac97(dev, LINE_IN_AC97, line); | 297 | ret = em28xx_write_ac97(dev, EM28XX_R10_LINE_IN_AC97, line); |
331 | 298 | ||
332 | return ret; | 299 | return ret; |
333 | } | 300 | } |
@@ -343,7 +310,7 @@ int em28xx_audio_analog_set(struct em28xx *dev) | |||
343 | 310 | ||
344 | /* Mute */ | 311 | /* Mute */ |
345 | s[1] |= 0x80; | 312 | s[1] |= 0x80; |
346 | ret = em28xx_write_ac97(dev, MASTER_AC97, s); | 313 | ret = em28xx_write_ac97(dev, EM28XX_R02_MASTER_AC97, s); |
347 | 314 | ||
348 | if (ret < 0) | 315 | if (ret < 0) |
349 | return ret; | 316 | return ret; |
@@ -354,7 +321,7 @@ int em28xx_audio_analog_set(struct em28xx *dev) | |||
354 | if (!dev->mute) | 321 | if (!dev->mute) |
355 | xclk |= 0x80; | 322 | xclk |= 0x80; |
356 | 323 | ||
357 | ret = em28xx_write_reg_bits(dev, XCLK_REG, xclk, 0xa7); | 324 | ret = em28xx_write_reg_bits(dev, EM28XX_R0F_XCLK, xclk, 0xa7); |
358 | if (ret < 0) | 325 | if (ret < 0) |
359 | return ret; | 326 | return ret; |
360 | msleep(10); | 327 | msleep(10); |
@@ -365,7 +332,7 @@ int em28xx_audio_analog_set(struct em28xx *dev) | |||
365 | /* Unmute device */ | 332 | /* Unmute device */ |
366 | if (!dev->mute) | 333 | if (!dev->mute) |
367 | s[1] &= ~0x80; | 334 | s[1] &= ~0x80; |
368 | ret = em28xx_write_ac97(dev, MASTER_AC97, s); | 335 | ret = em28xx_write_ac97(dev, EM28XX_R02_MASTER_AC97, s); |
369 | 336 | ||
370 | return ret; | 337 | return ret; |
371 | } | 338 | } |
@@ -373,50 +340,68 @@ EXPORT_SYMBOL_GPL(em28xx_audio_analog_set); | |||
373 | 340 | ||
374 | int em28xx_colorlevels_set_default(struct em28xx *dev) | 341 | int em28xx_colorlevels_set_default(struct em28xx *dev) |
375 | { | 342 | { |
376 | em28xx_write_regs(dev, YGAIN_REG, "\x10", 1); /* contrast */ | 343 | em28xx_write_regs(dev, EM28XX_R20_YGAIN, "\x10", 1); /* contrast */ |
377 | em28xx_write_regs(dev, YOFFSET_REG, "\x00", 1); /* brightness */ | 344 | em28xx_write_regs(dev, EM28XX_R21_YOFFSET, "\x00", 1); /* brightness */ |
378 | em28xx_write_regs(dev, UVGAIN_REG, "\x10", 1); /* saturation */ | 345 | em28xx_write_regs(dev, EM28XX_R22_UVGAIN, "\x10", 1); /* saturation */ |
379 | em28xx_write_regs(dev, UOFFSET_REG, "\x00", 1); | 346 | em28xx_write_regs(dev, EM28XX_R23_UOFFSET, "\x00", 1); |
380 | em28xx_write_regs(dev, VOFFSET_REG, "\x00", 1); | 347 | em28xx_write_regs(dev, EM28XX_R24_VOFFSET, "\x00", 1); |
381 | em28xx_write_regs(dev, SHARPNESS_REG, "\x00", 1); | 348 | em28xx_write_regs(dev, EM28XX_R25_SHARPNESS, "\x00", 1); |
382 | 349 | ||
383 | em28xx_write_regs(dev, GAMMA_REG, "\x20", 1); | 350 | em28xx_write_regs(dev, EM28XX_R14_GAMMA, "\x20", 1); |
384 | em28xx_write_regs(dev, RGAIN_REG, "\x20", 1); | 351 | em28xx_write_regs(dev, EM28XX_R15_RGAIN, "\x20", 1); |
385 | em28xx_write_regs(dev, GGAIN_REG, "\x20", 1); | 352 | em28xx_write_regs(dev, EM28XX_R16_GGAIN, "\x20", 1); |
386 | em28xx_write_regs(dev, BGAIN_REG, "\x20", 1); | 353 | em28xx_write_regs(dev, EM28XX_R17_BGAIN, "\x20", 1); |
387 | em28xx_write_regs(dev, ROFFSET_REG, "\x00", 1); | 354 | em28xx_write_regs(dev, EM28XX_R18_ROFFSET, "\x00", 1); |
388 | em28xx_write_regs(dev, GOFFSET_REG, "\x00", 1); | 355 | em28xx_write_regs(dev, EM28XX_R19_GOFFSET, "\x00", 1); |
389 | return em28xx_write_regs(dev, BOFFSET_REG, "\x00", 1); | 356 | return em28xx_write_regs(dev, EM28XX_R1A_BOFFSET, "\x00", 1); |
390 | } | 357 | } |
391 | 358 | ||
392 | int em28xx_capture_start(struct em28xx *dev, int start) | 359 | int em28xx_capture_start(struct em28xx *dev, int start) |
393 | { | 360 | { |
394 | int ret; | 361 | int rc; |
395 | /* FIXME: which is the best order? */ | 362 | /* FIXME: which is the best order? */ |
396 | /* video registers are sampled by VREF */ | 363 | /* video registers are sampled by VREF */ |
397 | if ((ret = em28xx_write_reg_bits(dev, USBSUSP_REG, start ? 0x10 : 0x00, | 364 | rc = em28xx_write_reg_bits(dev, EM28XX_R0C_USBSUSP, |
398 | 0x10)) < 0) | 365 | start ? 0x10 : 0x00, 0x10); |
399 | return ret; | 366 | if (rc < 0) |
367 | return rc; | ||
368 | |||
369 | if (!start) { | ||
370 | /* disable video capture */ | ||
371 | rc = em28xx_write_regs(dev, EM28XX_R12_VINENABLE, "\x27", 1); | ||
372 | return rc; | ||
373 | } | ||
374 | |||
400 | /* enable video capture */ | 375 | /* enable video capture */ |
401 | return em28xx_write_regs(dev, VINENABLE_REG, start ? "\x67" : "\x27", 1); | 376 | rc = em28xx_write_regs_req(dev, 0x00, 0x48, "\x00", 1); |
377 | |||
378 | if (dev->mode == EM28XX_ANALOG_MODE) | ||
379 | rc = em28xx_write_regs(dev, EM28XX_R12_VINENABLE, "\x67", 1); | ||
380 | else | ||
381 | rc = em28xx_write_regs(dev, EM28XX_R12_VINENABLE, "\x37", 1); | ||
382 | |||
383 | msleep(6); | ||
384 | |||
385 | return rc; | ||
402 | } | 386 | } |
403 | 387 | ||
404 | int em28xx_outfmt_set_yuv422(struct em28xx *dev) | 388 | int em28xx_outfmt_set_yuv422(struct em28xx *dev) |
405 | { | 389 | { |
406 | em28xx_write_regs(dev, OUTFMT_REG, "\x34", 1); | 390 | em28xx_write_regs(dev, EM28XX_R27_OUTFMT, "\x34", 1); |
407 | em28xx_write_regs(dev, VINMODE_REG, "\x10", 1); | 391 | em28xx_write_regs(dev, EM28XX_R10_VINMODE, "\x10", 1); |
408 | return em28xx_write_regs(dev, VINCTRL_REG, "\x11", 1); | 392 | return em28xx_write_regs(dev, EM28XX_R11_VINCTRL, "\x11", 1); |
409 | } | 393 | } |
410 | 394 | ||
411 | static int em28xx_accumulator_set(struct em28xx *dev, u8 xmin, u8 xmax, | 395 | static int em28xx_accumulator_set(struct em28xx *dev, u8 xmin, u8 xmax, |
412 | u8 ymin, u8 ymax) | 396 | u8 ymin, u8 ymax) |
413 | { | 397 | { |
414 | em28xx_coredbg("em28xx Scale: (%d,%d)-(%d,%d)\n", xmin, ymin, xmax, ymax); | 398 | em28xx_coredbg("em28xx Scale: (%d,%d)-(%d,%d)\n", |
399 | xmin, ymin, xmax, ymax); | ||
415 | 400 | ||
416 | em28xx_write_regs(dev, XMIN_REG, &xmin, 1); | 401 | em28xx_write_regs(dev, EM28XX_R28_XMIN, &xmin, 1); |
417 | em28xx_write_regs(dev, XMAX_REG, &xmax, 1); | 402 | em28xx_write_regs(dev, EM28XX_R29_XMAX, &xmax, 1); |
418 | em28xx_write_regs(dev, YMIN_REG, &ymin, 1); | 403 | em28xx_write_regs(dev, EM28XX_R2A_YMIN, &ymin, 1); |
419 | return em28xx_write_regs(dev, YMAX_REG, &ymax, 1); | 404 | return em28xx_write_regs(dev, EM28XX_R2B_YMAX, &ymax, 1); |
420 | } | 405 | } |
421 | 406 | ||
422 | static int em28xx_capture_area_set(struct em28xx *dev, u8 hstart, u8 vstart, | 407 | static int em28xx_capture_area_set(struct em28xx *dev, u8 hstart, u8 vstart, |
@@ -426,34 +411,36 @@ static int em28xx_capture_area_set(struct em28xx *dev, u8 hstart, u8 vstart, | |||
426 | u8 cheight = height; | 411 | u8 cheight = height; |
427 | u8 overflow = (height >> 7 & 0x02) | (width >> 8 & 0x01); | 412 | u8 overflow = (height >> 7 & 0x02) | (width >> 8 & 0x01); |
428 | 413 | ||
429 | em28xx_coredbg("em28xx Area Set: (%d,%d)\n", (width | (overflow & 2) << 7), | 414 | em28xx_coredbg("em28xx Area Set: (%d,%d)\n", |
415 | (width | (overflow & 2) << 7), | ||
430 | (height | (overflow & 1) << 8)); | 416 | (height | (overflow & 1) << 8)); |
431 | 417 | ||
432 | em28xx_write_regs(dev, HSTART_REG, &hstart, 1); | 418 | em28xx_write_regs(dev, EM28XX_R1C_HSTART, &hstart, 1); |
433 | em28xx_write_regs(dev, VSTART_REG, &vstart, 1); | 419 | em28xx_write_regs(dev, EM28XX_R1D_VSTART, &vstart, 1); |
434 | em28xx_write_regs(dev, CWIDTH_REG, &cwidth, 1); | 420 | em28xx_write_regs(dev, EM28XX_R1E_CWIDTH, &cwidth, 1); |
435 | em28xx_write_regs(dev, CHEIGHT_REG, &cheight, 1); | 421 | em28xx_write_regs(dev, EM28XX_R1F_CHEIGHT, &cheight, 1); |
436 | return em28xx_write_regs(dev, OFLOW_REG, &overflow, 1); | 422 | return em28xx_write_regs(dev, EM28XX_R1B_OFLOW, &overflow, 1); |
437 | } | 423 | } |
438 | 424 | ||
439 | static int em28xx_scaler_set(struct em28xx *dev, u16 h, u16 v) | 425 | static int em28xx_scaler_set(struct em28xx *dev, u16 h, u16 v) |
440 | { | 426 | { |
441 | u8 mode; | 427 | u8 mode; |
442 | /* the em2800 scaler only supports scaling down to 50% */ | 428 | /* the em2800 scaler only supports scaling down to 50% */ |
443 | if(dev->is_em2800) | 429 | if (dev->is_em2800) |
444 | mode = (v ? 0x20 : 0x00) | (h ? 0x10 : 0x00); | 430 | mode = (v ? 0x20 : 0x00) | (h ? 0x10 : 0x00); |
445 | else { | 431 | else { |
446 | u8 buf[2]; | 432 | u8 buf[2]; |
447 | buf[0] = h; | 433 | buf[0] = h; |
448 | buf[1] = h >> 8; | 434 | buf[1] = h >> 8; |
449 | em28xx_write_regs(dev, HSCALELOW_REG, (char *)buf, 2); | 435 | em28xx_write_regs(dev, EM28XX_R30_HSCALELOW, (char *)buf, 2); |
450 | buf[0] = v; | 436 | buf[0] = v; |
451 | buf[1] = v >> 8; | 437 | buf[1] = v >> 8; |
452 | em28xx_write_regs(dev, VSCALELOW_REG, (char *)buf, 2); | 438 | em28xx_write_regs(dev, EM28XX_R32_VSCALELOW, (char *)buf, 2); |
453 | /* it seems that both H and V scalers must be active to work correctly */ | 439 | /* it seems that both H and V scalers must be active |
440 | to work correctly */ | ||
454 | mode = (h || v)? 0x30: 0x00; | 441 | mode = (h || v)? 0x30: 0x00; |
455 | } | 442 | } |
456 | return em28xx_write_reg_bits(dev, COMPR_REG, mode, 0x30); | 443 | return em28xx_write_reg_bits(dev, EM28XX_R26_COMPR, mode, 0x30); |
457 | } | 444 | } |
458 | 445 | ||
459 | /* FIXME: this only function read values from dev */ | 446 | /* FIXME: this only function read values from dev */ |
@@ -469,376 +456,271 @@ int em28xx_resolution_set(struct em28xx *dev) | |||
469 | return em28xx_scaler_set(dev, dev->hscale, dev->vscale); | 456 | return em28xx_scaler_set(dev, dev->hscale, dev->vscale); |
470 | } | 457 | } |
471 | 458 | ||
472 | 459 | int em28xx_set_alternate(struct em28xx *dev) | |
473 | /******************* isoc transfer handling ****************************/ | ||
474 | |||
475 | #ifdef ENABLE_DEBUG_ISOC_FRAMES | ||
476 | static void em28xx_isoc_dump(struct urb *urb) | ||
477 | { | 460 | { |
478 | int len = 0; | 461 | int errCode, prev_alt = dev->alt; |
479 | int ntrans = 0; | ||
480 | int i; | 462 | int i; |
463 | unsigned int min_pkt_size = dev->width * 2 + 4; | ||
481 | 464 | ||
482 | printk(KERN_DEBUG "isocIrq: sf=%d np=%d ec=%x\n", | 465 | /* When image size is bigger than a certain value, |
483 | urb->start_frame, urb->number_of_packets, | 466 | the frame size should be increased, otherwise, only |
484 | urb->error_count); | 467 | green screen will be received. |
485 | for (i = 0; i < urb->number_of_packets; i++) { | 468 | */ |
486 | unsigned char *buf = | 469 | if (dev->width * 2 * dev->height > 720 * 240 * 2) |
487 | urb->transfer_buffer + | 470 | min_pkt_size *= 2; |
488 | urb->iso_frame_desc[i].offset; | 471 | |
489 | int alen = urb->iso_frame_desc[i].actual_length; | 472 | for (i = 0; i < dev->num_alt; i++) { |
490 | if (alen > 0) { | 473 | /* stop when the selected alt setting offers enough bandwidth */ |
491 | if (buf[0] == 0x88) { | 474 | if (dev->alt_max_pkt_size[i] >= min_pkt_size) { |
492 | ntrans++; | 475 | dev->alt = i; |
493 | len += alen; | 476 | break; |
494 | } else if (buf[0] == 0x22) { | 477 | /* otherwise make sure that we end up with the maximum bandwidth |
495 | printk(KERN_DEBUG | 478 | because the min_pkt_size equation might be wrong... |
496 | "= l=%d nt=%d bpp=%d\n", | 479 | */ |
497 | len - 4 * ntrans, ntrans, | 480 | } else if (dev->alt_max_pkt_size[i] > |
498 | ntrans == 0 ? 0 : len / ntrans); | 481 | dev->alt_max_pkt_size[dev->alt]) |
499 | ntrans = 1; | 482 | dev->alt = i; |
500 | len = alen; | 483 | } |
501 | } else | 484 | |
502 | printk(KERN_DEBUG "!\n"); | 485 | if (dev->alt != prev_alt) { |
486 | em28xx_coredbg("minimum isoc packet size: %u (alt=%d)\n", | ||
487 | min_pkt_size, dev->alt); | ||
488 | dev->max_pkt_size = dev->alt_max_pkt_size[dev->alt]; | ||
489 | em28xx_coredbg("setting alternate %d with wMaxPacketSize=%u\n", | ||
490 | dev->alt, dev->max_pkt_size); | ||
491 | errCode = usb_set_interface(dev->udev, 0, dev->alt); | ||
492 | if (errCode < 0) { | ||
493 | em28xx_errdev("cannot change alternate number to %d (error=%i)\n", | ||
494 | dev->alt, errCode); | ||
495 | return errCode; | ||
503 | } | 496 | } |
504 | printk(KERN_DEBUG " n=%d s=%d al=%d %x\n", i, | ||
505 | urb->iso_frame_desc[i].status, | ||
506 | urb->iso_frame_desc[i].actual_length, | ||
507 | (unsigned int) | ||
508 | *((unsigned char *)(urb->transfer_buffer + | ||
509 | urb->iso_frame_desc[i]. | ||
510 | offset))); | ||
511 | } | 497 | } |
498 | return 0; | ||
512 | } | 499 | } |
513 | #endif | ||
514 | 500 | ||
515 | static inline int em28xx_isoc_video(struct em28xx *dev,struct em28xx_frame_t **f, | 501 | int em28xx_gpio_set(struct em28xx *dev, struct em28xx_reg_seq *gpio) |
516 | unsigned long *lock_flags, unsigned char buf) | ||
517 | { | 502 | { |
518 | if (!(buf & 0x01)) { | 503 | int rc = 0; |
519 | if ((*f)->state == F_GRABBING) { | 504 | |
520 | /*previous frame is incomplete */ | 505 | if (!gpio) |
521 | if ((*f)->fieldbytesused < dev->field_size) { | 506 | return rc; |
522 | (*f)->state = F_ERROR; | 507 | |
523 | em28xx_isocdbg ("dropping incomplete bottom field (%i missing bytes)", | 508 | dev->em28xx_write_regs_req(dev, 0x00, 0x48, "\x00", 1); |
524 | dev->field_size-(*f)->fieldbytesused); | 509 | if (dev->mode == EM28XX_ANALOG_MODE) |
525 | } else { | 510 | dev->em28xx_write_regs_req(dev, 0x00, 0x12, "\x67", 1); |
526 | (*f)->state = F_DONE; | 511 | else |
527 | (*f)->buf.bytesused = dev->frame_size; | 512 | dev->em28xx_write_regs_req(dev, 0x00, 0x12, "\x37", 1); |
528 | } | 513 | msleep(6); |
529 | } | 514 | |
530 | if ((*f)->state == F_DONE || (*f)->state == F_ERROR) { | 515 | /* Send GPIO reset sequences specified at board entry */ |
531 | /* move current frame to outqueue and get next free buffer from inqueue */ | 516 | while (gpio->sleep >= 0) { |
532 | spin_lock_irqsave(&dev-> queue_lock, *lock_flags); | 517 | if (gpio->reg >= 0) { |
533 | list_move_tail(&(*f)->frame, &dev->outqueue); | 518 | rc = em28xx_write_reg_bits(dev, |
534 | if (!list_empty(&dev->inqueue)) | 519 | gpio->reg, |
535 | (*f) = list_entry(dev-> inqueue.next, | 520 | gpio->val, |
536 | struct em28xx_frame_t,frame); | 521 | gpio->mask); |
537 | else | 522 | if (rc < 0) |
538 | (*f) = NULL; | 523 | return rc; |
539 | spin_unlock_irqrestore(&dev->queue_lock,*lock_flags); | ||
540 | } | ||
541 | if (!(*f)) { | ||
542 | em28xx_isocdbg ("new frame but no buffer is free"); | ||
543 | return -1; | ||
544 | } | ||
545 | do_gettimeofday(&(*f)->buf.timestamp); | ||
546 | (*f)->buf.sequence = ++dev->frame_count; | ||
547 | (*f)->buf.field = V4L2_FIELD_INTERLACED; | ||
548 | (*f)->state = F_GRABBING; | ||
549 | (*f)->buf.bytesused = 0; | ||
550 | (*f)->top_field = 1; | ||
551 | (*f)->fieldbytesused = 0; | ||
552 | } else { | ||
553 | /* acquiring bottom field */ | ||
554 | if ((*f)->state == F_GRABBING) { | ||
555 | if (!(*f)->top_field) { | ||
556 | (*f)->state = F_ERROR; | ||
557 | em28xx_isocdbg ("unexpected begin of bottom field; discarding it"); | ||
558 | } else if ((*f)-> fieldbytesused < dev->field_size - 172) { | ||
559 | (*f)->state = F_ERROR; | ||
560 | em28xx_isocdbg ("dropping incomplete top field (%i missing bytes)", | ||
561 | dev->field_size-(*f)->fieldbytesused); | ||
562 | } else { | ||
563 | (*f)->top_field = 0; | ||
564 | (*f)->fieldbytesused = 0; | ||
565 | } | ||
566 | } | 524 | } |
525 | if (gpio->sleep > 0) | ||
526 | msleep(gpio->sleep); | ||
527 | |||
528 | gpio++; | ||
567 | } | 529 | } |
568 | return (0); | 530 | return rc; |
569 | } | 531 | } |
570 | 532 | ||
571 | static inline void em28xx_isoc_video_copy(struct em28xx *dev, | 533 | int em28xx_set_mode(struct em28xx *dev, enum em28xx_mode set_mode) |
572 | struct em28xx_frame_t **f, unsigned char *buf, int len) | ||
573 | { | 534 | { |
574 | void *fieldstart, *startwrite, *startread; | 535 | if (dev->mode == set_mode) |
575 | int linesdone, currlinedone, offset, lencopy,remain; | 536 | return 0; |
576 | 537 | ||
577 | if(dev->frame_size != (*f)->buf.length){ | 538 | if (set_mode == EM28XX_MODE_UNDEFINED) { |
578 | em28xx_err("frame_size %i and buf.length %i are different!!!\n",dev->frame_size,(*f)->buf.length); | 539 | dev->mode = set_mode; |
579 | return; | 540 | return 0; |
580 | } | 541 | } |
581 | 542 | ||
582 | if ((*f)->fieldbytesused + len > dev->field_size) | 543 | dev->mode = set_mode; |
583 | len =dev->field_size - (*f)->fieldbytesused; | ||
584 | |||
585 | if (buf[0] != 0x88 && buf[0] != 0x22) { | ||
586 | em28xx_isocdbg("frame is not complete\n"); | ||
587 | startread = buf; | ||
588 | len+=4; | ||
589 | } else | ||
590 | startread = buf + 4; | ||
591 | |||
592 | remain = len; | ||
593 | 544 | ||
594 | if ((*f)->top_field) | 545 | if (dev->mode == EM28XX_DIGITAL_MODE) |
595 | fieldstart = (*f)->bufmem; | 546 | return em28xx_gpio_set(dev, dev->digital_gpio); |
596 | else | 547 | else |
597 | fieldstart = (*f)->bufmem + dev->bytesperline; | 548 | return em28xx_gpio_set(dev, dev->analog_gpio); |
598 | |||
599 | linesdone = (*f)->fieldbytesused / dev->bytesperline; | ||
600 | currlinedone = (*f)->fieldbytesused % dev->bytesperline; | ||
601 | offset = linesdone * dev->bytesperline * 2 + currlinedone; | ||
602 | startwrite = fieldstart + offset; | ||
603 | lencopy = dev->bytesperline - currlinedone; | ||
604 | lencopy = lencopy > remain ? remain : lencopy; | ||
605 | |||
606 | memcpy(startwrite, startread, lencopy); | ||
607 | remain -= lencopy; | ||
608 | |||
609 | while (remain > 0) { | ||
610 | startwrite += lencopy + dev->bytesperline; | ||
611 | startread += lencopy; | ||
612 | if (dev->bytesperline > remain) | ||
613 | lencopy = remain; | ||
614 | else | ||
615 | lencopy = dev->bytesperline; | ||
616 | |||
617 | memcpy(startwrite, startread, lencopy); | ||
618 | remain -= lencopy; | ||
619 | } | ||
620 | |||
621 | (*f)->fieldbytesused += len; | ||
622 | } | 549 | } |
550 | EXPORT_SYMBOL_GPL(em28xx_set_mode); | ||
551 | |||
552 | /* ------------------------------------------------------------------ | ||
553 | URB control | ||
554 | ------------------------------------------------------------------*/ | ||
623 | 555 | ||
624 | /* | 556 | /* |
625 | * em28xx_isoIrq() | 557 | * IRQ callback, called by URB callback |
626 | * handles the incoming isoc urbs and fills the frames from our inqueue | ||
627 | */ | 558 | */ |
628 | static void em28xx_isocIrq(struct urb *urb) | 559 | static void em28xx_irq_callback(struct urb *urb) |
629 | { | 560 | { |
630 | struct em28xx *dev = urb->context; | 561 | struct em28xx_dmaqueue *dma_q = urb->context; |
631 | int i, status; | 562 | struct em28xx *dev = container_of(dma_q, struct em28xx, vidq); |
632 | struct em28xx_frame_t **f; | 563 | int rc, i; |
633 | unsigned long lock_flags; | ||
634 | |||
635 | if (!dev) | ||
636 | return; | ||
637 | #ifdef ENABLE_DEBUG_ISOC_FRAMES | ||
638 | if (isoc_debug>1) | ||
639 | em28xx_isoc_dump(urb); | ||
640 | #endif | ||
641 | |||
642 | if (urb->status == -ENOENT) | ||
643 | return; | ||
644 | |||
645 | f = &dev->frame_current; | ||
646 | |||
647 | if (dev->stream == STREAM_INTERRUPT) { | ||
648 | dev->stream = STREAM_OFF; | ||
649 | if ((*f)) | ||
650 | (*f)->state = F_QUEUED; | ||
651 | em28xx_isocdbg("stream interrupted"); | ||
652 | wake_up_interruptible(&dev->wait_stream); | ||
653 | } | ||
654 | |||
655 | if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED)) | ||
656 | return; | ||
657 | |||
658 | if (dev->stream == STREAM_ON && !list_empty(&dev->inqueue)) { | ||
659 | if (!(*f)) | ||
660 | (*f) = list_entry(dev->inqueue.next, | ||
661 | struct em28xx_frame_t, frame); | ||
662 | |||
663 | for (i = 0; i < urb->number_of_packets; i++) { | ||
664 | unsigned char *buf = urb->transfer_buffer + | ||
665 | urb->iso_frame_desc[i].offset; | ||
666 | int len = urb->iso_frame_desc[i].actual_length - 4; | ||
667 | |||
668 | if (urb->iso_frame_desc[i].status) { | ||
669 | em28xx_isocdbg("data error: [%d] len=%d, status=%d", i, | ||
670 | urb->iso_frame_desc[i].actual_length, | ||
671 | urb->iso_frame_desc[i].status); | ||
672 | if (urb->iso_frame_desc[i].status != -EPROTO) | ||
673 | continue; | ||
674 | } | ||
675 | if (urb->iso_frame_desc[i].actual_length <= 0) { | ||
676 | em28xx_isocdbg("packet %d is empty",i); | ||
677 | continue; | ||
678 | } | ||
679 | if (urb->iso_frame_desc[i].actual_length > | ||
680 | urb->iso_frame_desc[i].length) { | ||
681 | em28xx_isocdbg("packet bigger than packet size"); | ||
682 | continue; | ||
683 | } | ||
684 | /*new frame */ | ||
685 | if (buf[0] == 0x22 && buf[1] == 0x5a) { | ||
686 | em28xx_isocdbg("Video frame, length=%i!",len); | ||
687 | |||
688 | if (em28xx_isoc_video(dev,f,&lock_flags,buf[2])) | ||
689 | break; | ||
690 | } else if (buf[0]==0x33 && buf[1]==0x95 && buf[2]==0x00) { | ||
691 | em28xx_isocdbg("VBI HEADER!!!"); | ||
692 | } | ||
693 | 564 | ||
694 | /* actual copying */ | 565 | /* Copy data from URB */ |
695 | if ((*f)->state == F_GRABBING) { | 566 | spin_lock(&dev->slock); |
696 | em28xx_isoc_video_copy(dev,f,buf, len); | 567 | rc = dev->isoc_ctl.isoc_copy(dev, urb); |
697 | } | 568 | spin_unlock(&dev->slock); |
698 | } | ||
699 | } | ||
700 | 569 | ||
570 | /* Reset urb buffers */ | ||
701 | for (i = 0; i < urb->number_of_packets; i++) { | 571 | for (i = 0; i < urb->number_of_packets; i++) { |
702 | urb->iso_frame_desc[i].status = 0; | 572 | urb->iso_frame_desc[i].status = 0; |
703 | urb->iso_frame_desc[i].actual_length = 0; | 573 | urb->iso_frame_desc[i].actual_length = 0; |
704 | } | 574 | } |
705 | |||
706 | urb->status = 0; | 575 | urb->status = 0; |
707 | if ((status = usb_submit_urb(urb, GFP_ATOMIC))) { | 576 | |
708 | em28xx_errdev("resubmit of urb failed (error=%i)\n", status); | 577 | urb->status = usb_submit_urb(urb, GFP_ATOMIC); |
709 | dev->state |= DEV_MISCONFIGURED; | 578 | if (urb->status) { |
579 | em28xx_isocdbg("urb resubmit failed (error=%i)\n", | ||
580 | urb->status); | ||
710 | } | 581 | } |
711 | wake_up_interruptible(&dev->wait_frame); | ||
712 | return; | ||
713 | } | 582 | } |
714 | 583 | ||
715 | /* | 584 | /* |
716 | * em28xx_uninit_isoc() | 585 | * Stop and Deallocate URBs |
717 | * deallocates the buffers and urbs allocated during em28xx_init_iosc() | ||
718 | */ | 586 | */ |
719 | void em28xx_uninit_isoc(struct em28xx *dev) | 587 | void em28xx_uninit_isoc(struct em28xx *dev) |
720 | { | 588 | { |
589 | struct urb *urb; | ||
721 | int i; | 590 | int i; |
722 | 591 | ||
723 | for (i = 0; i < EM28XX_NUM_BUFS; i++) { | 592 | em28xx_isocdbg("em28xx: called em28xx_uninit_isoc\n"); |
724 | if (dev->urb[i]) { | 593 | |
725 | usb_kill_urb(dev->urb[i]); | 594 | dev->isoc_ctl.nfields = -1; |
726 | if (dev->transfer_buffer[i]) { | 595 | for (i = 0; i < dev->isoc_ctl.num_bufs; i++) { |
596 | urb = dev->isoc_ctl.urb[i]; | ||
597 | if (urb) { | ||
598 | usb_kill_urb(urb); | ||
599 | usb_unlink_urb(urb); | ||
600 | if (dev->isoc_ctl.transfer_buffer[i]) { | ||
727 | usb_buffer_free(dev->udev, | 601 | usb_buffer_free(dev->udev, |
728 | dev->urb[i]->transfer_buffer_length, | 602 | urb->transfer_buffer_length, |
729 | dev->transfer_buffer[i], | 603 | dev->isoc_ctl.transfer_buffer[i], |
730 | dev->urb[i]->transfer_dma); | 604 | urb->transfer_dma); |
731 | } | 605 | } |
732 | usb_free_urb(dev->urb[i]); | 606 | usb_free_urb(urb); |
607 | dev->isoc_ctl.urb[i] = NULL; | ||
733 | } | 608 | } |
734 | dev->urb[i] = NULL; | 609 | dev->isoc_ctl.transfer_buffer[i] = NULL; |
735 | dev->transfer_buffer[i] = NULL; | ||
736 | } | 610 | } |
611 | |||
612 | kfree(dev->isoc_ctl.urb); | ||
613 | kfree(dev->isoc_ctl.transfer_buffer); | ||
614 | |||
615 | dev->isoc_ctl.urb = NULL; | ||
616 | dev->isoc_ctl.transfer_buffer = NULL; | ||
617 | dev->isoc_ctl.num_bufs = 0; | ||
618 | |||
737 | em28xx_capture_start(dev, 0); | 619 | em28xx_capture_start(dev, 0); |
738 | } | 620 | } |
621 | EXPORT_SYMBOL_GPL(em28xx_uninit_isoc); | ||
739 | 622 | ||
740 | /* | 623 | /* |
741 | * em28xx_init_isoc() | 624 | * Allocate URBs and start IRQ |
742 | * allocates transfer buffers and submits the urbs for isoc transfer | ||
743 | */ | 625 | */ |
744 | int em28xx_init_isoc(struct em28xx *dev) | 626 | int em28xx_init_isoc(struct em28xx *dev, int max_packets, |
627 | int num_bufs, int max_pkt_size, | ||
628 | int (*isoc_copy) (struct em28xx *dev, struct urb *urb)) | ||
745 | { | 629 | { |
746 | /* change interface to 3 which allows the biggest packet sizes */ | 630 | struct em28xx_dmaqueue *dma_q = &dev->vidq; |
747 | int i, errCode; | 631 | int i; |
748 | int sb_size; | 632 | int sb_size, pipe; |
749 | 633 | struct urb *urb; | |
750 | em28xx_set_alternate(dev); | 634 | int j, k; |
751 | sb_size = EM28XX_NUM_PACKETS * dev->max_pkt_size; | 635 | int rc; |
752 | 636 | ||
753 | /* reset streaming vars */ | 637 | em28xx_isocdbg("em28xx: called em28xx_prepare_isoc\n"); |
754 | dev->frame_current = NULL; | 638 | |
755 | dev->frame_count = 0; | 639 | /* De-allocates all pending stuff */ |
756 | 640 | em28xx_uninit_isoc(dev); | |
757 | /* allocate urbs */ | 641 | |
758 | for (i = 0; i < EM28XX_NUM_BUFS; i++) { | 642 | dev->isoc_ctl.isoc_copy = isoc_copy; |
759 | struct urb *urb; | 643 | dev->isoc_ctl.num_bufs = num_bufs; |
760 | int j; | 644 | |
761 | /* allocate transfer buffer */ | 645 | dev->isoc_ctl.urb = kzalloc(sizeof(void *)*num_bufs, GFP_KERNEL); |
762 | urb = usb_alloc_urb(EM28XX_NUM_PACKETS, GFP_KERNEL); | 646 | if (!dev->isoc_ctl.urb) { |
763 | if (!urb){ | 647 | em28xx_errdev("cannot alloc memory for usb buffers\n"); |
764 | em28xx_errdev("cannot alloc urb %i\n", i); | 648 | return -ENOMEM; |
649 | } | ||
650 | |||
651 | dev->isoc_ctl.transfer_buffer = kzalloc(sizeof(void *)*num_bufs, | ||
652 | GFP_KERNEL); | ||
653 | if (!dev->isoc_ctl.urb) { | ||
654 | em28xx_errdev("cannot allocate memory for usbtransfer\n"); | ||
655 | kfree(dev->isoc_ctl.urb); | ||
656 | return -ENOMEM; | ||
657 | } | ||
658 | |||
659 | dev->isoc_ctl.max_pkt_size = max_pkt_size; | ||
660 | dev->isoc_ctl.buf = NULL; | ||
661 | |||
662 | sb_size = max_packets * dev->isoc_ctl.max_pkt_size; | ||
663 | |||
664 | /* allocate urbs and transfer buffers */ | ||
665 | for (i = 0; i < dev->isoc_ctl.num_bufs; i++) { | ||
666 | urb = usb_alloc_urb(max_packets, GFP_KERNEL); | ||
667 | if (!urb) { | ||
668 | em28xx_err("cannot alloc isoc_ctl.urb %i\n", i); | ||
765 | em28xx_uninit_isoc(dev); | 669 | em28xx_uninit_isoc(dev); |
766 | return -ENOMEM; | 670 | return -ENOMEM; |
767 | } | 671 | } |
768 | dev->transfer_buffer[i] = usb_buffer_alloc(dev->udev, sb_size, | 672 | dev->isoc_ctl.urb[i] = urb; |
769 | GFP_KERNEL, | 673 | |
770 | &urb->transfer_dma); | 674 | dev->isoc_ctl.transfer_buffer[i] = usb_buffer_alloc(dev->udev, |
771 | if (!dev->transfer_buffer[i]) { | 675 | sb_size, GFP_KERNEL, &urb->transfer_dma); |
772 | em28xx_errdev | 676 | if (!dev->isoc_ctl.transfer_buffer[i]) { |
773 | ("unable to allocate %i bytes for transfer buffer %i\n", | 677 | em28xx_err("unable to allocate %i bytes for transfer" |
774 | sb_size, i); | 678 | " buffer %i%s\n", |
679 | sb_size, i, | ||
680 | in_interrupt()?" while in int":""); | ||
775 | em28xx_uninit_isoc(dev); | 681 | em28xx_uninit_isoc(dev); |
776 | usb_free_urb(urb); | ||
777 | return -ENOMEM; | 682 | return -ENOMEM; |
778 | } | 683 | } |
779 | memset(dev->transfer_buffer[i], 0, sb_size); | 684 | memset(dev->isoc_ctl.transfer_buffer[i], 0, sb_size); |
780 | urb->dev = dev->udev; | 685 | |
781 | urb->context = dev; | 686 | /* FIXME: this is a hack - should be |
782 | urb->pipe = usb_rcvisocpipe(dev->udev, 0x82); | 687 | 'desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK' |
783 | urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; | 688 | should also be using 'desc.bInterval' |
784 | urb->interval = 1; | 689 | */ |
785 | urb->transfer_buffer = dev->transfer_buffer[i]; | 690 | pipe = usb_rcvisocpipe(dev->udev, |
786 | urb->complete = em28xx_isocIrq; | 691 | dev->mode == EM28XX_ANALOG_MODE ? 0x82 : 0x84); |
787 | urb->number_of_packets = EM28XX_NUM_PACKETS; | 692 | |
788 | urb->transfer_buffer_length = sb_size; | 693 | usb_fill_int_urb(urb, dev->udev, pipe, |
789 | for (j = 0; j < EM28XX_NUM_PACKETS; j++) { | 694 | dev->isoc_ctl.transfer_buffer[i], sb_size, |
790 | urb->iso_frame_desc[j].offset = j * dev->max_pkt_size; | 695 | em28xx_irq_callback, dma_q, 1); |
791 | urb->iso_frame_desc[j].length = dev->max_pkt_size; | 696 | |
697 | urb->number_of_packets = max_packets; | ||
698 | urb->transfer_flags = URB_ISO_ASAP; | ||
699 | |||
700 | k = 0; | ||
701 | for (j = 0; j < max_packets; j++) { | ||
702 | urb->iso_frame_desc[j].offset = k; | ||
703 | urb->iso_frame_desc[j].length = | ||
704 | dev->isoc_ctl.max_pkt_size; | ||
705 | k += dev->isoc_ctl.max_pkt_size; | ||
792 | } | 706 | } |
793 | dev->urb[i] = urb; | ||
794 | } | 707 | } |
795 | 708 | ||
796 | /* submit urbs */ | 709 | init_waitqueue_head(&dma_q->wq); |
797 | em28xx_coredbg("Submitting %d urbs of %d packets (%d each)\n", | ||
798 | EM28XX_NUM_BUFS, EM28XX_NUM_PACKETS, dev->max_pkt_size); | ||
799 | for (i = 0; i < EM28XX_NUM_BUFS; i++) { | ||
800 | errCode = usb_submit_urb(dev->urb[i], GFP_KERNEL); | ||
801 | if (errCode) { | ||
802 | em28xx_errdev("submit of urb %i failed (error=%i)\n", i, | ||
803 | errCode); | ||
804 | em28xx_uninit_isoc(dev); | ||
805 | return errCode; | ||
806 | } | ||
807 | } | ||
808 | |||
809 | return 0; | ||
810 | } | ||
811 | |||
812 | int em28xx_set_alternate(struct em28xx *dev) | ||
813 | { | ||
814 | int errCode, prev_alt = dev->alt; | ||
815 | int i; | ||
816 | unsigned int min_pkt_size = dev->bytesperline+4; | ||
817 | |||
818 | /* When image size is bigger than a ceirtain value, | ||
819 | the frame size should be increased, otherwise, only | ||
820 | green screen will be received. | ||
821 | */ | ||
822 | if (dev->frame_size > 720*240*2) | ||
823 | min_pkt_size *= 2; | ||
824 | 710 | ||
825 | for (i = 0; i < dev->num_alt; i++) | 711 | em28xx_capture_start(dev, 1); |
826 | if (dev->alt_max_pkt_size[i] >= min_pkt_size) | ||
827 | break; | ||
828 | dev->alt = i; | ||
829 | 712 | ||
830 | if (dev->alt != prev_alt) { | 713 | /* submit urbs and enables IRQ */ |
831 | em28xx_coredbg("minimum isoc packet size: %u (alt=%d)\n", | 714 | for (i = 0; i < dev->isoc_ctl.num_bufs; i++) { |
832 | min_pkt_size, dev->alt); | 715 | rc = usb_submit_urb(dev->isoc_ctl.urb[i], GFP_ATOMIC); |
833 | dev->max_pkt_size = dev->alt_max_pkt_size[dev->alt]; | 716 | if (rc) { |
834 | em28xx_coredbg("setting alternate %d with wMaxPacketSize=%u\n", | 717 | em28xx_err("submit of urb %i failed (error=%i)\n", i, |
835 | dev->alt, dev->max_pkt_size); | 718 | rc); |
836 | errCode = usb_set_interface(dev->udev, 0, dev->alt); | 719 | em28xx_uninit_isoc(dev); |
837 | if (errCode < 0) { | 720 | return rc; |
838 | em28xx_errdev ("cannot change alternate number to %d (error=%i)\n", | ||
839 | dev->alt, errCode); | ||
840 | return errCode; | ||
841 | } | 721 | } |
842 | } | 722 | } |
723 | |||
843 | return 0; | 724 | return 0; |
844 | } | 725 | } |
726 | EXPORT_SYMBOL_GPL(em28xx_init_isoc); | ||
diff --git a/drivers/media/video/em28xx/em28xx-dvb.c b/drivers/media/video/em28xx/em28xx-dvb.c new file mode 100644 index 000000000000..7df81575b7f2 --- /dev/null +++ b/drivers/media/video/em28xx/em28xx-dvb.c | |||
@@ -0,0 +1,474 @@ | |||
1 | /* | ||
2 | DVB device driver for em28xx | ||
3 | |||
4 | (c) 2008 Mauro Carvalho Chehab <mchehab@infradead.org> | ||
5 | |||
6 | (c) 2008 Devin Heitmueller <devin.heitmueller@gmail.com> | ||
7 | - Fixes for the driver to properly work with HVR-950 | ||
8 | |||
9 | (c) 2008 Aidan Thornton <makosoft@googlemail.com> | ||
10 | |||
11 | Based on cx88-dvb, saa7134-dvb and videobuf-dvb originally written by: | ||
12 | (c) 2004, 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au> | ||
13 | (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs] | ||
14 | |||
15 | This program is free software; you can redistribute it and/or modify | ||
16 | it under the terms of the GNU General Public License as published by | ||
17 | the Free Software Foundation; either version 2 of the License. | ||
18 | */ | ||
19 | |||
20 | #include <linux/kernel.h> | ||
21 | #include <linux/usb.h> | ||
22 | |||
23 | #include "em28xx.h" | ||
24 | #include <media/v4l2-common.h> | ||
25 | #include <media/videobuf-vmalloc.h> | ||
26 | |||
27 | #include "lgdt330x.h" | ||
28 | #include "zl10353.h" | ||
29 | |||
30 | MODULE_DESCRIPTION("driver for em28xx based DVB cards"); | ||
31 | MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>"); | ||
32 | MODULE_LICENSE("GPL"); | ||
33 | |||
34 | static unsigned int debug; | ||
35 | module_param(debug, int, 0644); | ||
36 | MODULE_PARM_DESC(debug, "enable debug messages [dvb]"); | ||
37 | |||
38 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); | ||
39 | |||
40 | #define dprintk(level, fmt, arg...) do { \ | ||
41 | if (debug >= level) \ | ||
42 | printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg); \ | ||
43 | } while (0) | ||
44 | |||
45 | #define EM28XX_DVB_NUM_BUFS 5 | ||
46 | #define EM28XX_DVB_MAX_PACKETSIZE 564 | ||
47 | #define EM28XX_DVB_MAX_PACKETS 64 | ||
48 | |||
49 | struct em28xx_dvb { | ||
50 | struct dvb_frontend *frontend; | ||
51 | |||
52 | /* feed count management */ | ||
53 | struct mutex lock; | ||
54 | int nfeeds; | ||
55 | |||
56 | /* general boilerplate stuff */ | ||
57 | struct dvb_adapter adapter; | ||
58 | struct dvb_demux demux; | ||
59 | struct dmxdev dmxdev; | ||
60 | struct dmx_frontend fe_hw; | ||
61 | struct dmx_frontend fe_mem; | ||
62 | struct dvb_net net; | ||
63 | }; | ||
64 | |||
65 | |||
66 | static inline void print_err_status(struct em28xx *dev, | ||
67 | int packet, int status) | ||
68 | { | ||
69 | char *errmsg = "Unknown"; | ||
70 | |||
71 | switch (status) { | ||
72 | case -ENOENT: | ||
73 | errmsg = "unlinked synchronuously"; | ||
74 | break; | ||
75 | case -ECONNRESET: | ||
76 | errmsg = "unlinked asynchronuously"; | ||
77 | break; | ||
78 | case -ENOSR: | ||
79 | errmsg = "Buffer error (overrun)"; | ||
80 | break; | ||
81 | case -EPIPE: | ||
82 | errmsg = "Stalled (device not responding)"; | ||
83 | break; | ||
84 | case -EOVERFLOW: | ||
85 | errmsg = "Babble (bad cable?)"; | ||
86 | break; | ||
87 | case -EPROTO: | ||
88 | errmsg = "Bit-stuff error (bad cable?)"; | ||
89 | break; | ||
90 | case -EILSEQ: | ||
91 | errmsg = "CRC/Timeout (could be anything)"; | ||
92 | break; | ||
93 | case -ETIME: | ||
94 | errmsg = "Device does not respond"; | ||
95 | break; | ||
96 | } | ||
97 | if (packet < 0) { | ||
98 | dprintk(1, "URB status %d [%s].\n", status, errmsg); | ||
99 | } else { | ||
100 | dprintk(1, "URB packet %d, status %d [%s].\n", | ||
101 | packet, status, errmsg); | ||
102 | } | ||
103 | } | ||
104 | |||
105 | static inline int dvb_isoc_copy(struct em28xx *dev, struct urb *urb) | ||
106 | { | ||
107 | int i; | ||
108 | |||
109 | if (!dev) | ||
110 | return 0; | ||
111 | |||
112 | if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED)) | ||
113 | return 0; | ||
114 | |||
115 | if (urb->status < 0) { | ||
116 | print_err_status(dev, -1, urb->status); | ||
117 | if (urb->status == -ENOENT) | ||
118 | return 0; | ||
119 | } | ||
120 | |||
121 | for (i = 0; i < urb->number_of_packets; i++) { | ||
122 | int status = urb->iso_frame_desc[i].status; | ||
123 | |||
124 | if (status < 0) { | ||
125 | print_err_status(dev, i, status); | ||
126 | if (urb->iso_frame_desc[i].status != -EPROTO) | ||
127 | continue; | ||
128 | } | ||
129 | |||
130 | dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer + | ||
131 | urb->iso_frame_desc[i].offset, | ||
132 | urb->iso_frame_desc[i].actual_length); | ||
133 | } | ||
134 | |||
135 | return 0; | ||
136 | } | ||
137 | |||
138 | static int start_streaming(struct em28xx_dvb *dvb) | ||
139 | { | ||
140 | int rc; | ||
141 | struct em28xx *dev = dvb->adapter.priv; | ||
142 | |||
143 | usb_set_interface(dev->udev, 0, 1); | ||
144 | rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE); | ||
145 | if (rc < 0) | ||
146 | return rc; | ||
147 | |||
148 | return em28xx_init_isoc(dev, EM28XX_DVB_MAX_PACKETS, | ||
149 | EM28XX_DVB_NUM_BUFS, EM28XX_DVB_MAX_PACKETSIZE, | ||
150 | dvb_isoc_copy); | ||
151 | } | ||
152 | |||
153 | static int stop_streaming(struct em28xx_dvb *dvb) | ||
154 | { | ||
155 | struct em28xx *dev = dvb->adapter.priv; | ||
156 | |||
157 | em28xx_uninit_isoc(dev); | ||
158 | |||
159 | em28xx_set_mode(dev, EM28XX_MODE_UNDEFINED); | ||
160 | |||
161 | return 0; | ||
162 | } | ||
163 | |||
164 | static int start_feed(struct dvb_demux_feed *feed) | ||
165 | { | ||
166 | struct dvb_demux *demux = feed->demux; | ||
167 | struct em28xx_dvb *dvb = demux->priv; | ||
168 | int rc, ret; | ||
169 | |||
170 | if (!demux->dmx.frontend) | ||
171 | return -EINVAL; | ||
172 | |||
173 | mutex_lock(&dvb->lock); | ||
174 | dvb->nfeeds++; | ||
175 | rc = dvb->nfeeds; | ||
176 | |||
177 | if (dvb->nfeeds == 1) { | ||
178 | ret = start_streaming(dvb); | ||
179 | if (ret < 0) | ||
180 | rc = ret; | ||
181 | } | ||
182 | |||
183 | mutex_unlock(&dvb->lock); | ||
184 | return rc; | ||
185 | } | ||
186 | |||
187 | static int stop_feed(struct dvb_demux_feed *feed) | ||
188 | { | ||
189 | struct dvb_demux *demux = feed->demux; | ||
190 | struct em28xx_dvb *dvb = demux->priv; | ||
191 | int err = 0; | ||
192 | |||
193 | mutex_lock(&dvb->lock); | ||
194 | dvb->nfeeds--; | ||
195 | |||
196 | if (0 == dvb->nfeeds) | ||
197 | err = stop_streaming(dvb); | ||
198 | |||
199 | mutex_unlock(&dvb->lock); | ||
200 | return err; | ||
201 | } | ||
202 | |||
203 | |||
204 | |||
205 | /* ------------------------------------------------------------------ */ | ||
206 | static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire) | ||
207 | { | ||
208 | struct em28xx *dev = fe->dvb->priv; | ||
209 | |||
210 | if (acquire) | ||
211 | return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE); | ||
212 | else | ||
213 | return em28xx_set_mode(dev, EM28XX_MODE_UNDEFINED); | ||
214 | } | ||
215 | |||
216 | /* ------------------------------------------------------------------ */ | ||
217 | |||
218 | static struct lgdt330x_config em2880_lgdt3303_dev = { | ||
219 | .demod_address = 0x0e, | ||
220 | .demod_chip = LGDT3303, | ||
221 | }; | ||
222 | |||
223 | static struct zl10353_config em28xx_zl10353_with_xc3028 = { | ||
224 | .demod_address = (0x1e >> 1), | ||
225 | .no_tuner = 1, | ||
226 | .parallel_ts = 1, | ||
227 | .if2 = 45600, | ||
228 | }; | ||
229 | |||
230 | /* ------------------------------------------------------------------ */ | ||
231 | |||
232 | static int attach_xc3028(u8 addr, struct em28xx *dev) | ||
233 | { | ||
234 | struct dvb_frontend *fe; | ||
235 | struct xc2028_config cfg; | ||
236 | |||
237 | memset(&cfg, 0, sizeof(cfg)); | ||
238 | cfg.i2c_adap = &dev->i2c_adap; | ||
239 | cfg.i2c_addr = addr; | ||
240 | cfg.callback = em28xx_tuner_callback; | ||
241 | |||
242 | if (!dev->dvb->frontend) { | ||
243 | printk(KERN_ERR "%s/2: dvb frontend not attached. " | ||
244 | "Can't attach xc3028\n", | ||
245 | dev->name); | ||
246 | return -EINVAL; | ||
247 | } | ||
248 | |||
249 | fe = dvb_attach(xc2028_attach, dev->dvb->frontend, &cfg); | ||
250 | if (!fe) { | ||
251 | printk(KERN_ERR "%s/2: xc3028 attach failed\n", | ||
252 | dev->name); | ||
253 | dvb_frontend_detach(dev->dvb->frontend); | ||
254 | dvb_unregister_frontend(dev->dvb->frontend); | ||
255 | dev->dvb->frontend = NULL; | ||
256 | return -EINVAL; | ||
257 | } | ||
258 | |||
259 | printk(KERN_INFO "%s/2: xc3028 attached\n", dev->name); | ||
260 | |||
261 | return 0; | ||
262 | } | ||
263 | |||
264 | /* ------------------------------------------------------------------ */ | ||
265 | |||
266 | int register_dvb(struct em28xx_dvb *dvb, | ||
267 | struct module *module, | ||
268 | struct em28xx *dev, | ||
269 | struct device *device) | ||
270 | { | ||
271 | int result; | ||
272 | |||
273 | mutex_init(&dvb->lock); | ||
274 | |||
275 | /* register adapter */ | ||
276 | result = dvb_register_adapter(&dvb->adapter, dev->name, module, device, | ||
277 | adapter_nr); | ||
278 | if (result < 0) { | ||
279 | printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n", | ||
280 | dev->name, result); | ||
281 | goto fail_adapter; | ||
282 | } | ||
283 | |||
284 | /* Ensure all frontends negotiate bus access */ | ||
285 | dvb->frontend->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl; | ||
286 | |||
287 | dvb->adapter.priv = dev; | ||
288 | |||
289 | /* register frontend */ | ||
290 | result = dvb_register_frontend(&dvb->adapter, dvb->frontend); | ||
291 | if (result < 0) { | ||
292 | printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n", | ||
293 | dev->name, result); | ||
294 | goto fail_frontend; | ||
295 | } | ||
296 | |||
297 | /* register demux stuff */ | ||
298 | dvb->demux.dmx.capabilities = | ||
299 | DMX_TS_FILTERING | DMX_SECTION_FILTERING | | ||
300 | DMX_MEMORY_BASED_FILTERING; | ||
301 | dvb->demux.priv = dvb; | ||
302 | dvb->demux.filternum = 256; | ||
303 | dvb->demux.feednum = 256; | ||
304 | dvb->demux.start_feed = start_feed; | ||
305 | dvb->demux.stop_feed = stop_feed; | ||
306 | |||
307 | result = dvb_dmx_init(&dvb->demux); | ||
308 | if (result < 0) { | ||
309 | printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n", | ||
310 | dev->name, result); | ||
311 | goto fail_dmx; | ||
312 | } | ||
313 | |||
314 | dvb->dmxdev.filternum = 256; | ||
315 | dvb->dmxdev.demux = &dvb->demux.dmx; | ||
316 | dvb->dmxdev.capabilities = 0; | ||
317 | result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter); | ||
318 | if (result < 0) { | ||
319 | printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n", | ||
320 | dev->name, result); | ||
321 | goto fail_dmxdev; | ||
322 | } | ||
323 | |||
324 | dvb->fe_hw.source = DMX_FRONTEND_0; | ||
325 | result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw); | ||
326 | if (result < 0) { | ||
327 | printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n", | ||
328 | dev->name, result); | ||
329 | goto fail_fe_hw; | ||
330 | } | ||
331 | |||
332 | dvb->fe_mem.source = DMX_MEMORY_FE; | ||
333 | result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem); | ||
334 | if (result < 0) { | ||
335 | printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n", | ||
336 | dev->name, result); | ||
337 | goto fail_fe_mem; | ||
338 | } | ||
339 | |||
340 | result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw); | ||
341 | if (result < 0) { | ||
342 | printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n", | ||
343 | dev->name, result); | ||
344 | goto fail_fe_conn; | ||
345 | } | ||
346 | |||
347 | /* register network adapter */ | ||
348 | dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx); | ||
349 | return 0; | ||
350 | |||
351 | fail_fe_conn: | ||
352 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); | ||
353 | fail_fe_mem: | ||
354 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); | ||
355 | fail_fe_hw: | ||
356 | dvb_dmxdev_release(&dvb->dmxdev); | ||
357 | fail_dmxdev: | ||
358 | dvb_dmx_release(&dvb->demux); | ||
359 | fail_dmx: | ||
360 | dvb_unregister_frontend(dvb->frontend); | ||
361 | fail_frontend: | ||
362 | dvb_frontend_detach(dvb->frontend); | ||
363 | dvb_unregister_adapter(&dvb->adapter); | ||
364 | fail_adapter: | ||
365 | return result; | ||
366 | } | ||
367 | |||
368 | static void unregister_dvb(struct em28xx_dvb *dvb) | ||
369 | { | ||
370 | dvb_net_release(&dvb->net); | ||
371 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); | ||
372 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); | ||
373 | dvb_dmxdev_release(&dvb->dmxdev); | ||
374 | dvb_dmx_release(&dvb->demux); | ||
375 | dvb_unregister_frontend(dvb->frontend); | ||
376 | dvb_frontend_detach(dvb->frontend); | ||
377 | dvb_unregister_adapter(&dvb->adapter); | ||
378 | } | ||
379 | |||
380 | |||
381 | static int dvb_init(struct em28xx *dev) | ||
382 | { | ||
383 | int result = 0; | ||
384 | struct em28xx_dvb *dvb; | ||
385 | |||
386 | dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL); | ||
387 | |||
388 | if (dvb == NULL) { | ||
389 | printk(KERN_INFO "em28xx_dvb: memory allocation failed\n"); | ||
390 | return -ENOMEM; | ||
391 | } | ||
392 | dev->dvb = dvb; | ||
393 | |||
394 | em28xx_set_mode(dev, EM28XX_DIGITAL_MODE); | ||
395 | /* init frontend */ | ||
396 | switch (dev->model) { | ||
397 | case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950: | ||
398 | dvb->frontend = dvb_attach(lgdt330x_attach, | ||
399 | &em2880_lgdt3303_dev, | ||
400 | &dev->i2c_adap); | ||
401 | if (attach_xc3028(0x61, dev) < 0) { | ||
402 | result = -EINVAL; | ||
403 | goto out_free; | ||
404 | } | ||
405 | break; | ||
406 | case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900: | ||
407 | dvb->frontend = dvb_attach(zl10353_attach, | ||
408 | &em28xx_zl10353_with_xc3028, | ||
409 | &dev->i2c_adap); | ||
410 | if (attach_xc3028(0x61, dev) < 0) { | ||
411 | result = -EINVAL; | ||
412 | goto out_free; | ||
413 | } | ||
414 | break; | ||
415 | default: | ||
416 | printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card" | ||
417 | " isn't supported yet\n", | ||
418 | dev->name); | ||
419 | break; | ||
420 | } | ||
421 | if (NULL == dvb->frontend) { | ||
422 | printk(KERN_ERR | ||
423 | "%s/2: frontend initialization failed\n", | ||
424 | dev->name); | ||
425 | result = -EINVAL; | ||
426 | goto out_free; | ||
427 | } | ||
428 | |||
429 | /* register everything */ | ||
430 | result = register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev); | ||
431 | |||
432 | if (result < 0) | ||
433 | goto out_free; | ||
434 | |||
435 | em28xx_set_mode(dev, EM28XX_MODE_UNDEFINED); | ||
436 | printk(KERN_INFO "Successfully loaded em28xx-dvb\n"); | ||
437 | return 0; | ||
438 | |||
439 | out_free: | ||
440 | em28xx_set_mode(dev, EM28XX_MODE_UNDEFINED); | ||
441 | kfree(dvb); | ||
442 | dev->dvb = NULL; | ||
443 | return result; | ||
444 | } | ||
445 | |||
446 | static int dvb_fini(struct em28xx *dev) | ||
447 | { | ||
448 | if (dev->dvb) { | ||
449 | unregister_dvb(dev->dvb); | ||
450 | dev->dvb = NULL; | ||
451 | } | ||
452 | |||
453 | return 0; | ||
454 | } | ||
455 | |||
456 | static struct em28xx_ops dvb_ops = { | ||
457 | .id = EM28XX_DVB, | ||
458 | .name = "Em28xx dvb Extension", | ||
459 | .init = dvb_init, | ||
460 | .fini = dvb_fini, | ||
461 | }; | ||
462 | |||
463 | static int __init em28xx_dvb_register(void) | ||
464 | { | ||
465 | return em28xx_register_extension(&dvb_ops); | ||
466 | } | ||
467 | |||
468 | static void __exit em28xx_dvb_unregister(void) | ||
469 | { | ||
470 | em28xx_unregister_extension(&dvb_ops); | ||
471 | } | ||
472 | |||
473 | module_init(em28xx_dvb_register); | ||
474 | module_exit(em28xx_dvb_unregister); | ||
diff --git a/drivers/media/video/em28xx/em28xx-i2c.c b/drivers/media/video/em28xx/em28xx-i2c.c index cacd04d46e99..6a78fd294cab 100644 --- a/drivers/media/video/em28xx/em28xx-i2c.c +++ b/drivers/media/video/em28xx/em28xx-i2c.c | |||
@@ -33,19 +33,29 @@ | |||
33 | 33 | ||
34 | /* ----------------------------------------------------------- */ | 34 | /* ----------------------------------------------------------- */ |
35 | 35 | ||
36 | static unsigned int i2c_scan = 0; | 36 | static unsigned int i2c_scan; |
37 | module_param(i2c_scan, int, 0444); | 37 | module_param(i2c_scan, int, 0444); |
38 | MODULE_PARM_DESC(i2c_scan, "scan i2c bus at insmod time"); | 38 | MODULE_PARM_DESC(i2c_scan, "scan i2c bus at insmod time"); |
39 | 39 | ||
40 | static unsigned int i2c_debug = 0; | 40 | static unsigned int i2c_debug; |
41 | module_param(i2c_debug, int, 0644); | 41 | module_param(i2c_debug, int, 0644); |
42 | MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]"); | 42 | MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]"); |
43 | 43 | ||
44 | #define dprintk1(lvl,fmt, args...) if (i2c_debug>=lvl) do {\ | 44 | |
45 | printk(fmt, ##args); } while (0) | 45 | #define dprintk1(lvl, fmt, args...) \ |
46 | #define dprintk2(lvl,fmt, args...) if (i2c_debug>=lvl) do{ \ | 46 | do { \ |
47 | printk(KERN_DEBUG "%s at %s: " fmt, \ | 47 | if (i2c_debug >= lvl) { \ |
48 | dev->name, __FUNCTION__ , ##args); } while (0) | 48 | printk(fmt, ##args); \ |
49 | } \ | ||
50 | } while (0) | ||
51 | |||
52 | #define dprintk2(lvl, fmt, args...) \ | ||
53 | do { \ | ||
54 | if (i2c_debug >= lvl) { \ | ||
55 | printk(KERN_DEBUG "%s at %s: " fmt, \ | ||
56 | dev->name, __func__ , ##args); \ | ||
57 | } \ | ||
58 | } while (0) | ||
49 | 59 | ||
50 | /* | 60 | /* |
51 | * em2800_i2c_send_max4() | 61 | * em2800_i2c_send_max4() |
@@ -235,16 +245,16 @@ static int em28xx_i2c_xfer(struct i2c_adapter *i2c_adap, | |||
235 | return 0; | 245 | return 0; |
236 | for (i = 0; i < num; i++) { | 246 | for (i = 0; i < num; i++) { |
237 | addr = msgs[i].addr << 1; | 247 | addr = msgs[i].addr << 1; |
238 | dprintk2(2,"%s %s addr=%x len=%d:", | 248 | dprintk2(2, "%s %s addr=%x len=%d:", |
239 | (msgs[i].flags & I2C_M_RD) ? "read" : "write", | 249 | (msgs[i].flags & I2C_M_RD) ? "read" : "write", |
240 | i == num - 1 ? "stop" : "nonstop", addr, msgs[i].len); | 250 | i == num - 1 ? "stop" : "nonstop", addr, msgs[i].len); |
241 | if (!msgs[i].len) { /* no len: check only for device presence */ | 251 | if (!msgs[i].len) { /* no len: check only for device presence */ |
242 | if (dev->is_em2800) | 252 | if (dev->is_em2800) |
243 | rc = em2800_i2c_check_for_device(dev, addr); | 253 | rc = em2800_i2c_check_for_device(dev, addr); |
244 | else | 254 | else |
245 | rc = em28xx_i2c_check_for_device(dev, addr); | 255 | rc = em28xx_i2c_check_for_device(dev, addr); |
246 | if (rc < 0) { | 256 | if (rc < 0) { |
247 | dprintk2(2," no device\n"); | 257 | dprintk2(2, " no device\n"); |
248 | return rc; | 258 | return rc; |
249 | } | 259 | } |
250 | 260 | ||
@@ -258,14 +268,13 @@ static int em28xx_i2c_xfer(struct i2c_adapter *i2c_adap, | |||
258 | rc = em28xx_i2c_recv_bytes(dev, addr, | 268 | rc = em28xx_i2c_recv_bytes(dev, addr, |
259 | msgs[i].buf, | 269 | msgs[i].buf, |
260 | msgs[i].len); | 270 | msgs[i].len); |
261 | if (i2c_debug>=2) { | 271 | if (i2c_debug >= 2) { |
262 | for (byte = 0; byte < msgs[i].len; byte++) { | 272 | for (byte = 0; byte < msgs[i].len; byte++) |
263 | printk(" %02x", msgs[i].buf[byte]); | 273 | printk(" %02x", msgs[i].buf[byte]); |
264 | } | ||
265 | } | 274 | } |
266 | } else { | 275 | } else { |
267 | /* write bytes */ | 276 | /* write bytes */ |
268 | if (i2c_debug>=2) { | 277 | if (i2c_debug >= 2) { |
269 | for (byte = 0; byte < msgs[i].len; byte++) | 278 | for (byte = 0; byte < msgs[i].len; byte++) |
270 | printk(" %02x", msgs[i].buf[byte]); | 279 | printk(" %02x", msgs[i].buf[byte]); |
271 | } | 280 | } |
@@ -281,13 +290,13 @@ static int em28xx_i2c_xfer(struct i2c_adapter *i2c_adap, | |||
281 | } | 290 | } |
282 | if (rc < 0) | 291 | if (rc < 0) |
283 | goto err; | 292 | goto err; |
284 | if (i2c_debug>=2) | 293 | if (i2c_debug >= 2) |
285 | printk("\n"); | 294 | printk("\n"); |
286 | } | 295 | } |
287 | 296 | ||
288 | return num; | 297 | return num; |
289 | err: | 298 | err: |
290 | dprintk2(2," ERROR: %i\n", rc); | 299 | dprintk2(2, " ERROR: %i\n", rc); |
291 | return rc; | 300 | return rc; |
292 | } | 301 | } |
293 | 302 | ||
@@ -330,7 +339,9 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len) | |||
330 | return -1; | 339 | return -1; |
331 | 340 | ||
332 | buf = 0; | 341 | buf = 0; |
333 | if (1 != (err = i2c_master_send(&dev->i2c_client, &buf, 1))) { | 342 | |
343 | err = i2c_master_send(&dev->i2c_client, &buf, 1); | ||
344 | if (err != 1) { | ||
334 | printk(KERN_INFO "%s: Huh, no eeprom present (err=%d)?\n", | 345 | printk(KERN_INFO "%s: Huh, no eeprom present (err=%d)?\n", |
335 | dev->name, err); | 346 | dev->name, err); |
336 | return -1; | 347 | return -1; |
@@ -403,8 +414,10 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len) | |||
403 | break; | 414 | break; |
404 | } | 415 | } |
405 | printk(KERN_INFO "Table at 0x%02x, strings=0x%04x, 0x%04x, 0x%04x\n", | 416 | printk(KERN_INFO "Table at 0x%02x, strings=0x%04x, 0x%04x, 0x%04x\n", |
406 | em_eeprom->string_idx_table,em_eeprom->string1, | 417 | em_eeprom->string_idx_table, |
407 | em_eeprom->string2,em_eeprom->string3); | 418 | em_eeprom->string1, |
419 | em_eeprom->string2, | ||
420 | em_eeprom->string3); | ||
408 | 421 | ||
409 | return 0; | 422 | return 0; |
410 | } | 423 | } |
@@ -430,58 +443,61 @@ static int attach_inform(struct i2c_client *client) | |||
430 | struct em28xx *dev = client->adapter->algo_data; | 443 | struct em28xx *dev = client->adapter->algo_data; |
431 | 444 | ||
432 | switch (client->addr << 1) { | 445 | switch (client->addr << 1) { |
433 | case 0x86: | 446 | case 0x86: |
434 | case 0x84: | 447 | case 0x84: |
435 | case 0x96: | 448 | case 0x96: |
436 | case 0x94: | 449 | case 0x94: |
437 | { | 450 | { |
438 | struct v4l2_priv_tun_config tda9887_cfg; | 451 | struct v4l2_priv_tun_config tda9887_cfg; |
439 | 452 | ||
440 | struct tuner_setup tun_setup; | 453 | struct tuner_setup tun_setup; |
441 | 454 | ||
442 | tun_setup.mode_mask = T_ANALOG_TV | T_RADIO; | 455 | tun_setup.mode_mask = T_ANALOG_TV | T_RADIO; |
443 | tun_setup.type = TUNER_TDA9887; | 456 | tun_setup.type = TUNER_TDA9887; |
444 | tun_setup.addr = client->addr; | 457 | tun_setup.addr = client->addr; |
445 | 458 | ||
446 | em28xx_i2c_call_clients(dev, TUNER_SET_TYPE_ADDR, &tun_setup); | 459 | em28xx_i2c_call_clients(dev, TUNER_SET_TYPE_ADDR, |
447 | 460 | &tun_setup); | |
448 | tda9887_cfg.tuner = TUNER_TDA9887; | 461 | |
449 | tda9887_cfg.priv = &dev->tda9887_conf; | 462 | tda9887_cfg.tuner = TUNER_TDA9887; |
450 | em28xx_i2c_call_clients(dev, TUNER_SET_CONFIG, | 463 | tda9887_cfg.priv = &dev->tda9887_conf; |
451 | &tda9887_cfg); | 464 | em28xx_i2c_call_clients(dev, TUNER_SET_CONFIG, |
452 | break; | 465 | &tda9887_cfg); |
453 | } | 466 | break; |
454 | case 0x42: | 467 | } |
455 | dprintk1(1,"attach_inform: saa7114 detected.\n"); | 468 | case 0x42: |
456 | break; | 469 | dprintk1(1, "attach_inform: saa7114 detected.\n"); |
457 | case 0x4a: | 470 | break; |
458 | dprintk1(1,"attach_inform: saa7113 detected.\n"); | 471 | case 0x4a: |
459 | break; | 472 | dprintk1(1, "attach_inform: saa7113 detected.\n"); |
460 | case 0xa0: | 473 | break; |
461 | dprintk1(1,"attach_inform: eeprom detected.\n"); | 474 | case 0xa0: |
462 | break; | 475 | dprintk1(1, "attach_inform: eeprom detected.\n"); |
463 | case 0x60: | 476 | break; |
464 | case 0x8e: | 477 | case 0x60: |
465 | { | 478 | case 0x8e: |
466 | struct IR_i2c *ir = i2c_get_clientdata(client); | 479 | { |
467 | dprintk1(1,"attach_inform: IR detected (%s).\n",ir->phys); | 480 | struct IR_i2c *ir = i2c_get_clientdata(client); |
468 | em28xx_set_ir(dev,ir); | 481 | dprintk1(1, "attach_inform: IR detected (%s).\n", |
469 | break; | 482 | ir->phys); |
470 | } | 483 | em28xx_set_ir(dev, ir); |
471 | case 0x80: | 484 | break; |
472 | case 0x88: | 485 | } |
473 | dprintk1(1,"attach_inform: msp34xx detected.\n"); | 486 | case 0x80: |
474 | break; | 487 | case 0x88: |
475 | case 0xb8: | 488 | dprintk1(1, "attach_inform: msp34xx detected.\n"); |
476 | case 0xba: | 489 | break; |
477 | dprintk1(1,"attach_inform: tvp5150 detected.\n"); | 490 | case 0xb8: |
478 | break; | 491 | case 0xba: |
479 | 492 | dprintk1(1, "attach_inform: tvp5150 detected.\n"); | |
480 | default: | 493 | break; |
481 | if (!dev->tuner_addr) | 494 | |
482 | dev->tuner_addr = client->addr; | 495 | default: |
483 | 496 | if (!dev->tuner_addr) | |
484 | dprintk1(1,"attach inform: detected I2C address %x\n", client->addr << 1); | 497 | dev->tuner_addr = client->addr; |
498 | |||
499 | dprintk1(1, "attach inform: detected I2C address %x\n", | ||
500 | client->addr << 1); | ||
485 | 501 | ||
486 | } | 502 | } |
487 | 503 | ||
diff --git a/drivers/media/video/em28xx/em28xx-input.c b/drivers/media/video/em28xx/em28xx-input.c index 10da2fd8d987..bb5807159b8d 100644 --- a/drivers/media/video/em28xx/em28xx-input.c +++ b/drivers/media/video/em28xx/em28xx-input.c | |||
@@ -32,10 +32,12 @@ | |||
32 | 32 | ||
33 | static unsigned int ir_debug; | 33 | static unsigned int ir_debug; |
34 | module_param(ir_debug, int, 0644); | 34 | module_param(ir_debug, int, 0644); |
35 | MODULE_PARM_DESC(ir_debug,"enable debug messages [IR]"); | 35 | MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]"); |
36 | 36 | ||
37 | #define dprintk(fmt, arg...) if (ir_debug) \ | 37 | #define dprintk(fmt, arg...) \ |
38 | printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg) | 38 | if (ir_debug) { \ |
39 | printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg); \ | ||
40 | } | ||
39 | 41 | ||
40 | /* ----------------------------------------------------------------------- */ | 42 | /* ----------------------------------------------------------------------- */ |
41 | 43 | ||
@@ -44,7 +46,7 @@ int em28xx_get_key_terratec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) | |||
44 | unsigned char b; | 46 | unsigned char b; |
45 | 47 | ||
46 | /* poll IR chip */ | 48 | /* poll IR chip */ |
47 | if (1 != i2c_master_recv(&ir->c,&b,1)) { | 49 | if (1 != i2c_master_recv(&ir->c, &b, 1)) { |
48 | dprintk("read error\n"); | 50 | dprintk("read error\n"); |
49 | return -EIO; | 51 | return -EIO; |
50 | } | 52 | } |
@@ -74,24 +76,25 @@ int em28xx_get_key_em_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) | |||
74 | unsigned char code; | 76 | unsigned char code; |
75 | 77 | ||
76 | /* poll IR chip */ | 78 | /* poll IR chip */ |
77 | if (2 != i2c_master_recv(&ir->c,buf,2)) | 79 | if (2 != i2c_master_recv(&ir->c, buf, 2)) |
78 | return -EIO; | 80 | return -EIO; |
79 | 81 | ||
80 | /* Does eliminate repeated parity code */ | 82 | /* Does eliminate repeated parity code */ |
81 | if (buf[1]==0xff) | 83 | if (buf[1] == 0xff) |
82 | return 0; | 84 | return 0; |
83 | 85 | ||
84 | ir->old=buf[1]; | 86 | ir->old = buf[1]; |
85 | 87 | ||
86 | /* Rearranges bits to the right order */ | 88 | /* Rearranges bits to the right order */ |
87 | code= ((buf[0]&0x01)<<5) | /* 0010 0000 */ | 89 | code = ((buf[0]&0x01)<<5) | /* 0010 0000 */ |
88 | ((buf[0]&0x02)<<3) | /* 0001 0000 */ | 90 | ((buf[0]&0x02)<<3) | /* 0001 0000 */ |
89 | ((buf[0]&0x04)<<1) | /* 0000 1000 */ | 91 | ((buf[0]&0x04)<<1) | /* 0000 1000 */ |
90 | ((buf[0]&0x08)>>1) | /* 0000 0100 */ | 92 | ((buf[0]&0x08)>>1) | /* 0000 0100 */ |
91 | ((buf[0]&0x10)>>3) | /* 0000 0010 */ | 93 | ((buf[0]&0x10)>>3) | /* 0000 0010 */ |
92 | ((buf[0]&0x20)>>5); /* 0000 0001 */ | 94 | ((buf[0]&0x20)>>5); /* 0000 0001 */ |
93 | 95 | ||
94 | dprintk("ir hauppauge (em2840): code=0x%02x (rcv=0x%02x)\n",code,buf[0]); | 96 | dprintk("ir hauppauge (em2840): code=0x%02x (rcv=0x%02x)\n", |
97 | code, buf[0]); | ||
95 | 98 | ||
96 | /* return key */ | 99 | /* return key */ |
97 | *ir_key = code; | 100 | *ir_key = code; |
@@ -106,15 +109,14 @@ int em28xx_get_key_pinnacle_usb_grey(struct IR_i2c *ir, u32 *ir_key, | |||
106 | 109 | ||
107 | /* poll IR chip */ | 110 | /* poll IR chip */ |
108 | 111 | ||
109 | if (3 != i2c_master_recv(&ir->c,buf,3)) { | 112 | if (3 != i2c_master_recv(&ir->c, buf, 3)) { |
110 | dprintk("read error\n"); | 113 | dprintk("read error\n"); |
111 | return -EIO; | 114 | return -EIO; |
112 | } | 115 | } |
113 | 116 | ||
114 | dprintk("key %02x\n", buf[2]&0x3f); | 117 | dprintk("key %02x\n", buf[2]&0x3f); |
115 | if (buf[0]!=0x00){ | 118 | if (buf[0] != 0x00) |
116 | return 0; | 119 | return 0; |
117 | } | ||
118 | 120 | ||
119 | *ir_key = buf[2]&0x3f; | 121 | *ir_key = buf[2]&0x3f; |
120 | *ir_raw = buf[2]&0x3f; | 122 | *ir_raw = buf[2]&0x3f; |
diff --git a/drivers/media/video/em28xx/em28xx-reg.h b/drivers/media/video/em28xx/em28xx-reg.h new file mode 100644 index 000000000000..9058bed07953 --- /dev/null +++ b/drivers/media/video/em28xx/em28xx-reg.h | |||
@@ -0,0 +1,88 @@ | |||
1 | #define EM_GPIO_0 (1 << 0) | ||
2 | #define EM_GPIO_1 (1 << 1) | ||
3 | #define EM_GPIO_2 (1 << 2) | ||
4 | #define EM_GPIO_3 (1 << 3) | ||
5 | #define EM_GPIO_4 (1 << 4) | ||
6 | #define EM_GPIO_5 (1 << 5) | ||
7 | #define EM_GPIO_6 (1 << 6) | ||
8 | #define EM_GPIO_7 (1 << 7) | ||
9 | |||
10 | #define EM_GPO_0 (1 << 0) | ||
11 | #define EM_GPO_1 (1 << 1) | ||
12 | #define EM_GPO_2 (1 << 2) | ||
13 | #define EM_GPO_3 (1 << 3) | ||
14 | |||
15 | /* em2800 registers */ | ||
16 | #define EM2800_R08_AUDIOSRC 0x08 | ||
17 | |||
18 | /* em28xx registers */ | ||
19 | |||
20 | /* GPIO/GPO registers */ | ||
21 | #define EM2880_R04_GPO 0x04 /* em2880-em2883 only */ | ||
22 | #define EM28XX_R08_GPIO 0x08 /* em2820 or upper */ | ||
23 | |||
24 | #define EM28XX_R06_I2C_CLK 0x06 | ||
25 | #define EM28XX_R0A_CHIPID 0x0a | ||
26 | #define EM28XX_R0C_USBSUSP 0x0c /* */ | ||
27 | |||
28 | #define EM28XX_R0E_AUDIOSRC 0x0e | ||
29 | #define EM28XX_R0F_XCLK 0x0f | ||
30 | |||
31 | #define EM28XX_R10_VINMODE 0x10 | ||
32 | #define EM28XX_R11_VINCTRL 0x11 | ||
33 | #define EM28XX_R12_VINENABLE 0x12 /* */ | ||
34 | |||
35 | #define EM28XX_R14_GAMMA 0x14 | ||
36 | #define EM28XX_R15_RGAIN 0x15 | ||
37 | #define EM28XX_R16_GGAIN 0x16 | ||
38 | #define EM28XX_R17_BGAIN 0x17 | ||
39 | #define EM28XX_R18_ROFFSET 0x18 | ||
40 | #define EM28XX_R19_GOFFSET 0x19 | ||
41 | #define EM28XX_R1A_BOFFSET 0x1a | ||
42 | |||
43 | #define EM28XX_R1B_OFLOW 0x1b | ||
44 | #define EM28XX_R1C_HSTART 0x1c | ||
45 | #define EM28XX_R1D_VSTART 0x1d | ||
46 | #define EM28XX_R1E_CWIDTH 0x1e | ||
47 | #define EM28XX_R1F_CHEIGHT 0x1f | ||
48 | |||
49 | #define EM28XX_R20_YGAIN 0x20 | ||
50 | #define EM28XX_R21_YOFFSET 0x21 | ||
51 | #define EM28XX_R22_UVGAIN 0x22 | ||
52 | #define EM28XX_R23_UOFFSET 0x23 | ||
53 | #define EM28XX_R24_VOFFSET 0x24 | ||
54 | #define EM28XX_R25_SHARPNESS 0x25 | ||
55 | |||
56 | #define EM28XX_R26_COMPR 0x26 | ||
57 | #define EM28XX_R27_OUTFMT 0x27 | ||
58 | |||
59 | #define EM28XX_R28_XMIN 0x28 | ||
60 | #define EM28XX_R29_XMAX 0x29 | ||
61 | #define EM28XX_R2A_YMIN 0x2a | ||
62 | #define EM28XX_R2B_YMAX 0x2b | ||
63 | |||
64 | #define EM28XX_R30_HSCALELOW 0x30 | ||
65 | #define EM28XX_R31_HSCALEHIGH 0x31 | ||
66 | #define EM28XX_R32_VSCALELOW 0x32 | ||
67 | #define EM28XX_R33_VSCALEHIGH 0x33 | ||
68 | |||
69 | #define EM28XX_R40_AC97LSB 0x40 | ||
70 | #define EM28XX_R41_AC97MSB 0x41 | ||
71 | #define EM28XX_R42_AC97ADDR 0x42 | ||
72 | #define EM28XX_R43_AC97BUSY 0x43 | ||
73 | |||
74 | /* em202 registers */ | ||
75 | #define EM28XX_R02_MASTER_AC97 0x02 | ||
76 | #define EM28XX_R10_LINE_IN_AC97 0x10 | ||
77 | #define EM28XX_R14_VIDEO_AC97 0x14 | ||
78 | |||
79 | /* register settings */ | ||
80 | #define EM2800_AUDIO_SRC_TUNER 0x0d | ||
81 | #define EM2800_AUDIO_SRC_LINE 0x0c | ||
82 | #define EM28XX_AUDIO_SRC_TUNER 0xc0 | ||
83 | #define EM28XX_AUDIO_SRC_LINE 0x80 | ||
84 | |||
85 | /* FIXME: Need to be populated with the other chip ID's */ | ||
86 | enum em28xx_chip_id { | ||
87 | CHIP_ID_EM2883 = 36, | ||
88 | }; | ||
diff --git a/drivers/media/video/em28xx/em28xx-video.c b/drivers/media/video/em28xx/em28xx-video.c index 4abe6701a770..8996175cc950 100644 --- a/drivers/media/video/em28xx/em28xx-video.c +++ b/drivers/media/video/em28xx/em28xx-video.c | |||
@@ -1,5 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | em28xx-video.c - driver for Empia EM2800/EM2820/2840 USB video capture devices | 2 | em28xx-video.c - driver for Empia EM2800/EM2820/2840 USB |
3 | video capture devices | ||
3 | 4 | ||
4 | Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it> | 5 | Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it> |
5 | Markus Rechberger <mrechberger@gmail.com> | 6 | Markus Rechberger <mrechberger@gmail.com> |
@@ -52,7 +53,19 @@ | |||
52 | #define em28xx_videodbg(fmt, arg...) do {\ | 53 | #define em28xx_videodbg(fmt, arg...) do {\ |
53 | if (video_debug) \ | 54 | if (video_debug) \ |
54 | printk(KERN_INFO "%s %s :"fmt, \ | 55 | printk(KERN_INFO "%s %s :"fmt, \ |
55 | dev->name, __FUNCTION__ , ##arg); } while (0) | 56 | dev->name, __func__ , ##arg); } while (0) |
57 | |||
58 | static unsigned int isoc_debug; | ||
59 | module_param(isoc_debug, int, 0644); | ||
60 | MODULE_PARM_DESC(isoc_debug, "enable debug messages [isoc transfers]"); | ||
61 | |||
62 | #define em28xx_isocdbg(fmt, arg...) \ | ||
63 | do {\ | ||
64 | if (isoc_debug) { \ | ||
65 | printk(KERN_INFO "%s %s :"fmt, \ | ||
66 | dev->name, __func__ , ##arg); \ | ||
67 | } \ | ||
68 | } while (0) | ||
56 | 69 | ||
57 | MODULE_AUTHOR(DRIVER_AUTHOR); | 70 | MODULE_AUTHOR(DRIVER_AUTHOR); |
58 | MODULE_DESCRIPTION(DRIVER_DESC); | 71 | MODULE_DESCRIPTION(DRIVER_DESC); |
@@ -74,9 +87,9 @@ MODULE_PARM_DESC(video_nr, "video device numbers"); | |||
74 | MODULE_PARM_DESC(vbi_nr, "vbi device numbers"); | 87 | MODULE_PARM_DESC(vbi_nr, "vbi device numbers"); |
75 | MODULE_PARM_DESC(radio_nr, "radio device numbers"); | 88 | MODULE_PARM_DESC(radio_nr, "radio device numbers"); |
76 | 89 | ||
77 | static unsigned int video_debug = 0; | 90 | static unsigned int video_debug; |
78 | module_param(video_debug,int,0644); | 91 | module_param(video_debug, int, 0644); |
79 | MODULE_PARM_DESC(video_debug,"enable debug messages [video]"); | 92 | MODULE_PARM_DESC(video_debug, "enable debug messages [video]"); |
80 | 93 | ||
81 | /* Bitmask marking allocated devices from 0 to EM28XX_MAXBOARDS */ | 94 | /* Bitmask marking allocated devices from 0 to EM28XX_MAXBOARDS */ |
82 | static unsigned long em28xx_devused; | 95 | static unsigned long em28xx_devused; |
@@ -93,7 +106,7 @@ static struct v4l2_queryctrl em28xx_qctrl[] = { | |||
93 | .step = 0x1, | 106 | .step = 0x1, |
94 | .default_value = 0x1f, | 107 | .default_value = 0x1f, |
95 | .flags = 0, | 108 | .flags = 0, |
96 | },{ | 109 | }, { |
97 | .id = V4L2_CID_AUDIO_MUTE, | 110 | .id = V4L2_CID_AUDIO_MUTE, |
98 | .type = V4L2_CTRL_TYPE_BOOLEAN, | 111 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
99 | .name = "Mute", | 112 | .name = "Mute", |
@@ -107,8 +120,391 @@ static struct v4l2_queryctrl em28xx_qctrl[] = { | |||
107 | 120 | ||
108 | static struct usb_driver em28xx_usb_driver; | 121 | static struct usb_driver em28xx_usb_driver; |
109 | 122 | ||
123 | /* ------------------------------------------------------------------ | ||
124 | DMA and thread functions | ||
125 | ------------------------------------------------------------------*/ | ||
126 | |||
127 | /* | ||
128 | * Announces that a buffer were filled and request the next | ||
129 | */ | ||
130 | static inline void buffer_filled(struct em28xx *dev, | ||
131 | struct em28xx_dmaqueue *dma_q, | ||
132 | struct em28xx_buffer *buf) | ||
133 | { | ||
134 | /* Advice that buffer was filled */ | ||
135 | em28xx_isocdbg("[%p/%d] wakeup\n", buf, buf->vb.i); | ||
136 | buf->vb.state = VIDEOBUF_DONE; | ||
137 | buf->vb.field_count++; | ||
138 | do_gettimeofday(&buf->vb.ts); | ||
110 | 139 | ||
111 | /********************* v4l2 interface ******************************************/ | 140 | dev->isoc_ctl.buf = NULL; |
141 | |||
142 | list_del(&buf->vb.queue); | ||
143 | wake_up(&buf->vb.done); | ||
144 | } | ||
145 | |||
146 | /* | ||
147 | * Identify the buffer header type and properly handles | ||
148 | */ | ||
149 | static void em28xx_copy_video(struct em28xx *dev, | ||
150 | struct em28xx_dmaqueue *dma_q, | ||
151 | struct em28xx_buffer *buf, | ||
152 | unsigned char *p, | ||
153 | unsigned char *outp, unsigned long len) | ||
154 | { | ||
155 | void *fieldstart, *startwrite, *startread; | ||
156 | int linesdone, currlinedone, offset, lencopy, remain; | ||
157 | int bytesperline = dev->width << 1; | ||
158 | |||
159 | if (dma_q->pos + len > buf->vb.size) | ||
160 | len = buf->vb.size - dma_q->pos; | ||
161 | |||
162 | if (p[0] != 0x88 && p[0] != 0x22) { | ||
163 | em28xx_isocdbg("frame is not complete\n"); | ||
164 | len += 4; | ||
165 | } else | ||
166 | p += 4; | ||
167 | |||
168 | startread = p; | ||
169 | remain = len; | ||
170 | |||
171 | /* Interlaces frame */ | ||
172 | if (buf->top_field) | ||
173 | fieldstart = outp; | ||
174 | else | ||
175 | fieldstart = outp + bytesperline; | ||
176 | |||
177 | linesdone = dma_q->pos / bytesperline; | ||
178 | currlinedone = dma_q->pos % bytesperline; | ||
179 | offset = linesdone * bytesperline * 2 + currlinedone; | ||
180 | startwrite = fieldstart + offset; | ||
181 | lencopy = bytesperline - currlinedone; | ||
182 | lencopy = lencopy > remain ? remain : lencopy; | ||
183 | |||
184 | if ((char *)startwrite + lencopy > (char *)outp + buf->vb.size) { | ||
185 | em28xx_isocdbg("Overflow of %zi bytes past buffer end (1)\n", | ||
186 | ((char *)startwrite + lencopy) - | ||
187 | ((char *)outp + buf->vb.size)); | ||
188 | lencopy = remain = (char *)outp + buf->vb.size - (char *)startwrite; | ||
189 | } | ||
190 | if (lencopy <= 0) | ||
191 | return; | ||
192 | memcpy(startwrite, startread, lencopy); | ||
193 | |||
194 | remain -= lencopy; | ||
195 | |||
196 | while (remain > 0) { | ||
197 | startwrite += lencopy + bytesperline; | ||
198 | startread += lencopy; | ||
199 | if (bytesperline > remain) | ||
200 | lencopy = remain; | ||
201 | else | ||
202 | lencopy = bytesperline; | ||
203 | |||
204 | if ((char *)startwrite + lencopy > (char *)outp + buf->vb.size) { | ||
205 | em28xx_isocdbg("Overflow of %zi bytes past buffer end (2)\n", | ||
206 | ((char *)startwrite + lencopy) - | ||
207 | ((char *)outp + buf->vb.size)); | ||
208 | lencopy = remain = (char *)outp + buf->vb.size - | ||
209 | (char *)startwrite; | ||
210 | } | ||
211 | if (lencopy <= 0) | ||
212 | break; | ||
213 | |||
214 | memcpy(startwrite, startread, lencopy); | ||
215 | |||
216 | remain -= lencopy; | ||
217 | } | ||
218 | |||
219 | dma_q->pos += len; | ||
220 | } | ||
221 | |||
222 | static inline void print_err_status(struct em28xx *dev, | ||
223 | int packet, int status) | ||
224 | { | ||
225 | char *errmsg = "Unknown"; | ||
226 | |||
227 | switch (status) { | ||
228 | case -ENOENT: | ||
229 | errmsg = "unlinked synchronuously"; | ||
230 | break; | ||
231 | case -ECONNRESET: | ||
232 | errmsg = "unlinked asynchronuously"; | ||
233 | break; | ||
234 | case -ENOSR: | ||
235 | errmsg = "Buffer error (overrun)"; | ||
236 | break; | ||
237 | case -EPIPE: | ||
238 | errmsg = "Stalled (device not responding)"; | ||
239 | break; | ||
240 | case -EOVERFLOW: | ||
241 | errmsg = "Babble (bad cable?)"; | ||
242 | break; | ||
243 | case -EPROTO: | ||
244 | errmsg = "Bit-stuff error (bad cable?)"; | ||
245 | break; | ||
246 | case -EILSEQ: | ||
247 | errmsg = "CRC/Timeout (could be anything)"; | ||
248 | break; | ||
249 | case -ETIME: | ||
250 | errmsg = "Device does not respond"; | ||
251 | break; | ||
252 | } | ||
253 | if (packet < 0) { | ||
254 | em28xx_isocdbg("URB status %d [%s].\n", status, errmsg); | ||
255 | } else { | ||
256 | em28xx_isocdbg("URB packet %d, status %d [%s].\n", | ||
257 | packet, status, errmsg); | ||
258 | } | ||
259 | } | ||
260 | |||
261 | /* | ||
262 | * video-buf generic routine to get the next available buffer | ||
263 | */ | ||
264 | static inline void get_next_buf(struct em28xx_dmaqueue *dma_q, | ||
265 | struct em28xx_buffer **buf) | ||
266 | { | ||
267 | struct em28xx *dev = container_of(dma_q, struct em28xx, vidq); | ||
268 | char *outp; | ||
269 | |||
270 | if (list_empty(&dma_q->active)) { | ||
271 | em28xx_isocdbg("No active queue to serve\n"); | ||
272 | dev->isoc_ctl.buf = NULL; | ||
273 | *buf = NULL; | ||
274 | return; | ||
275 | } | ||
276 | |||
277 | /* Get the next buffer */ | ||
278 | *buf = list_entry(dma_q->active.next, struct em28xx_buffer, vb.queue); | ||
279 | |||
280 | /* Cleans up buffer - Usefull for testing for frame/URB loss */ | ||
281 | outp = videobuf_to_vmalloc(&(*buf)->vb); | ||
282 | memset(outp, 0, (*buf)->vb.size); | ||
283 | |||
284 | dev->isoc_ctl.buf = *buf; | ||
285 | |||
286 | return; | ||
287 | } | ||
288 | |||
289 | /* | ||
290 | * Controls the isoc copy of each urb packet | ||
291 | */ | ||
292 | static inline int em28xx_isoc_copy(struct em28xx *dev, struct urb *urb) | ||
293 | { | ||
294 | struct em28xx_buffer *buf; | ||
295 | struct em28xx_dmaqueue *dma_q = urb->context; | ||
296 | unsigned char *outp = NULL; | ||
297 | int i, len = 0, rc = 1; | ||
298 | unsigned char *p; | ||
299 | |||
300 | if (!dev) | ||
301 | return 0; | ||
302 | |||
303 | if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED)) | ||
304 | return 0; | ||
305 | |||
306 | if (urb->status < 0) { | ||
307 | print_err_status(dev, -1, urb->status); | ||
308 | if (urb->status == -ENOENT) | ||
309 | return 0; | ||
310 | } | ||
311 | |||
312 | buf = dev->isoc_ctl.buf; | ||
313 | if (buf != NULL) | ||
314 | outp = videobuf_to_vmalloc(&buf->vb); | ||
315 | |||
316 | for (i = 0; i < urb->number_of_packets; i++) { | ||
317 | int status = urb->iso_frame_desc[i].status; | ||
318 | |||
319 | if (status < 0) { | ||
320 | print_err_status(dev, i, status); | ||
321 | if (urb->iso_frame_desc[i].status != -EPROTO) | ||
322 | continue; | ||
323 | } | ||
324 | |||
325 | len = urb->iso_frame_desc[i].actual_length - 4; | ||
326 | |||
327 | if (urb->iso_frame_desc[i].actual_length <= 0) { | ||
328 | /* em28xx_isocdbg("packet %d is empty",i); - spammy */ | ||
329 | continue; | ||
330 | } | ||
331 | if (urb->iso_frame_desc[i].actual_length > | ||
332 | dev->max_pkt_size) { | ||
333 | em28xx_isocdbg("packet bigger than packet size"); | ||
334 | continue; | ||
335 | } | ||
336 | |||
337 | p = urb->transfer_buffer + urb->iso_frame_desc[i].offset; | ||
338 | |||
339 | /* FIXME: incomplete buffer checks where removed to make | ||
340 | logic simpler. Impacts of those changes should be evaluated | ||
341 | */ | ||
342 | if (p[0] == 0x33 && p[1] == 0x95 && p[2] == 0x00) { | ||
343 | em28xx_isocdbg("VBI HEADER!!!\n"); | ||
344 | /* FIXME: Should add vbi copy */ | ||
345 | continue; | ||
346 | } | ||
347 | if (p[0] == 0x22 && p[1] == 0x5a) { | ||
348 | em28xx_isocdbg("Video frame %d, length=%i, %s\n", p[2], | ||
349 | len, (p[2] & 1)? "odd" : "even"); | ||
350 | |||
351 | if (!(p[2] & 1)) { | ||
352 | if (buf != NULL) | ||
353 | buffer_filled(dev, dma_q, buf); | ||
354 | get_next_buf(dma_q, &buf); | ||
355 | if (buf == NULL) | ||
356 | outp = NULL; | ||
357 | else | ||
358 | outp = videobuf_to_vmalloc(&buf->vb); | ||
359 | } | ||
360 | |||
361 | if (buf != NULL) { | ||
362 | if (p[2] & 1) | ||
363 | buf->top_field = 0; | ||
364 | else | ||
365 | buf->top_field = 1; | ||
366 | } | ||
367 | |||
368 | dma_q->pos = 0; | ||
369 | } | ||
370 | if (buf != NULL) | ||
371 | em28xx_copy_video(dev, dma_q, buf, p, outp, len); | ||
372 | } | ||
373 | return rc; | ||
374 | } | ||
375 | |||
376 | /* ------------------------------------------------------------------ | ||
377 | Videobuf operations | ||
378 | ------------------------------------------------------------------*/ | ||
379 | |||
380 | static int | ||
381 | buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size) | ||
382 | { | ||
383 | struct em28xx_fh *fh = vq->priv_data; | ||
384 | struct em28xx *dev = fh->dev; | ||
385 | struct v4l2_frequency f; | ||
386 | |||
387 | *size = 16 * fh->dev->width * fh->dev->height >> 3; | ||
388 | if (0 == *count) | ||
389 | *count = EM28XX_DEF_BUF; | ||
390 | |||
391 | if (*count < EM28XX_MIN_BUF) | ||
392 | *count = EM28XX_MIN_BUF; | ||
393 | |||
394 | /* Ask tuner to go to analog mode */ | ||
395 | memset(&f, 0, sizeof(f)); | ||
396 | f.frequency = dev->ctl_freq; | ||
397 | |||
398 | em28xx_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, &f); | ||
399 | |||
400 | return 0; | ||
401 | } | ||
402 | |||
403 | /* This is called *without* dev->slock held; please keep it that way */ | ||
404 | static void free_buffer(struct videobuf_queue *vq, struct em28xx_buffer *buf) | ||
405 | { | ||
406 | struct em28xx_fh *fh = vq->priv_data; | ||
407 | struct em28xx *dev = fh->dev; | ||
408 | unsigned long flags = 0; | ||
409 | if (in_interrupt()) | ||
410 | BUG(); | ||
411 | |||
412 | /* We used to wait for the buffer to finish here, but this didn't work | ||
413 | because, as we were keeping the state as VIDEOBUF_QUEUED, | ||
414 | videobuf_queue_cancel marked it as finished for us. | ||
415 | (Also, it could wedge forever if the hardware was misconfigured.) | ||
416 | |||
417 | This should be safe; by the time we get here, the buffer isn't | ||
418 | queued anymore. If we ever start marking the buffers as | ||
419 | VIDEOBUF_ACTIVE, it won't be, though. | ||
420 | */ | ||
421 | spin_lock_irqsave(&dev->slock, flags); | ||
422 | if (dev->isoc_ctl.buf == buf) | ||
423 | dev->isoc_ctl.buf = NULL; | ||
424 | spin_unlock_irqrestore(&dev->slock, flags); | ||
425 | |||
426 | videobuf_vmalloc_free(&buf->vb); | ||
427 | buf->vb.state = VIDEOBUF_NEEDS_INIT; | ||
428 | } | ||
429 | |||
430 | static int | ||
431 | buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb, | ||
432 | enum v4l2_field field) | ||
433 | { | ||
434 | struct em28xx_fh *fh = vq->priv_data; | ||
435 | struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb); | ||
436 | struct em28xx *dev = fh->dev; | ||
437 | int rc = 0, urb_init = 0; | ||
438 | |||
439 | /* FIXME: It assumes depth = 16 */ | ||
440 | /* The only currently supported format is 16 bits/pixel */ | ||
441 | buf->vb.size = 16 * dev->width * dev->height >> 3; | ||
442 | |||
443 | if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) | ||
444 | return -EINVAL; | ||
445 | |||
446 | buf->vb.width = dev->width; | ||
447 | buf->vb.height = dev->height; | ||
448 | buf->vb.field = field; | ||
449 | |||
450 | if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { | ||
451 | rc = videobuf_iolock(vq, &buf->vb, NULL); | ||
452 | if (rc < 0) | ||
453 | goto fail; | ||
454 | } | ||
455 | |||
456 | if (!dev->isoc_ctl.num_bufs) | ||
457 | urb_init = 1; | ||
458 | |||
459 | if (urb_init) { | ||
460 | rc = em28xx_init_isoc(dev, EM28XX_NUM_PACKETS, | ||
461 | EM28XX_NUM_BUFS, dev->max_pkt_size, | ||
462 | em28xx_isoc_copy); | ||
463 | if (rc < 0) | ||
464 | goto fail; | ||
465 | } | ||
466 | |||
467 | buf->vb.state = VIDEOBUF_PREPARED; | ||
468 | return 0; | ||
469 | |||
470 | fail: | ||
471 | free_buffer(vq, buf); | ||
472 | return rc; | ||
473 | } | ||
474 | |||
475 | static void | ||
476 | buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) | ||
477 | { | ||
478 | struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb); | ||
479 | struct em28xx_fh *fh = vq->priv_data; | ||
480 | struct em28xx *dev = fh->dev; | ||
481 | struct em28xx_dmaqueue *vidq = &dev->vidq; | ||
482 | |||
483 | buf->vb.state = VIDEOBUF_QUEUED; | ||
484 | list_add_tail(&buf->vb.queue, &vidq->active); | ||
485 | |||
486 | } | ||
487 | |||
488 | static void buffer_release(struct videobuf_queue *vq, | ||
489 | struct videobuf_buffer *vb) | ||
490 | { | ||
491 | struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb); | ||
492 | struct em28xx_fh *fh = vq->priv_data; | ||
493 | struct em28xx *dev = (struct em28xx *)fh->dev; | ||
494 | |||
495 | em28xx_isocdbg("em28xx: called buffer_release\n"); | ||
496 | |||
497 | free_buffer(vq, buf); | ||
498 | } | ||
499 | |||
500 | static struct videobuf_queue_ops em28xx_video_qops = { | ||
501 | .buf_setup = buffer_setup, | ||
502 | .buf_prepare = buffer_prepare, | ||
503 | .buf_queue = buffer_queue, | ||
504 | .buf_release = buffer_release, | ||
505 | }; | ||
506 | |||
507 | /********************* v4l2 interface **************************************/ | ||
112 | 508 | ||
113 | /* | 509 | /* |
114 | * em28xx_config() | 510 | * em28xx_config() |
@@ -123,9 +519,9 @@ static int em28xx_config(struct em28xx *dev) | |||
123 | 519 | ||
124 | /* enable vbi capturing */ | 520 | /* enable vbi capturing */ |
125 | 521 | ||
126 | /* em28xx_write_regs_req(dev,0x00,0x0e,"\xC0",1); audio register */ | 522 | /* em28xx_write_regs_req(dev, 0x00, 0x0e, "\xC0", 1); audio register */ |
127 | /* em28xx_write_regs_req(dev,0x00,0x0f,"\x80",1); clk register */ | 523 | /* em28xx_write_regs_req(dev, 0x00, 0x0f, "\x80", 1); clk register */ |
128 | em28xx_write_regs_req(dev,0x00,0x11,"\x51",1); | 524 | em28xx_write_regs_req(dev, 0x00, 0x11, "\x51", 1); |
129 | 525 | ||
130 | dev->mute = 1; /* maybe not the right place... */ | 526 | dev->mute = 1; /* maybe not the right place... */ |
131 | dev->volume = 0x1f; | 527 | dev->volume = 0x1f; |
@@ -152,23 +548,6 @@ static void em28xx_config_i2c(struct em28xx *dev) | |||
152 | em28xx_i2c_call_clients(dev, VIDIOC_STREAMON, NULL); | 548 | em28xx_i2c_call_clients(dev, VIDIOC_STREAMON, NULL); |
153 | } | 549 | } |
154 | 550 | ||
155 | /* | ||
156 | * em28xx_empty_framequeues() | ||
157 | * prepare queues for incoming and outgoing frames | ||
158 | */ | ||
159 | static void em28xx_empty_framequeues(struct em28xx *dev) | ||
160 | { | ||
161 | u32 i; | ||
162 | |||
163 | INIT_LIST_HEAD(&dev->inqueue); | ||
164 | INIT_LIST_HEAD(&dev->outqueue); | ||
165 | |||
166 | for (i = 0; i < EM28XX_NUM_FRAMES; i++) { | ||
167 | dev->frame[i].state = F_UNUSED; | ||
168 | dev->frame[i].buf.bytesused = 0; | ||
169 | } | ||
170 | } | ||
171 | |||
172 | static void video_mux(struct em28xx *dev, int index) | 551 | static void video_mux(struct em28xx *dev, int index) |
173 | { | 552 | { |
174 | struct v4l2_routing route; | 553 | struct v4l2_routing route; |
@@ -181,12 +560,15 @@ static void video_mux(struct em28xx *dev, int index) | |||
181 | em28xx_i2c_call_clients(dev, VIDIOC_INT_S_VIDEO_ROUTING, &route); | 560 | em28xx_i2c_call_clients(dev, VIDIOC_INT_S_VIDEO_ROUTING, &route); |
182 | 561 | ||
183 | if (dev->has_msp34xx) { | 562 | if (dev->has_msp34xx) { |
184 | if (dev->i2s_speed) | 563 | if (dev->i2s_speed) { |
185 | em28xx_i2c_call_clients(dev, VIDIOC_INT_I2S_CLOCK_FREQ, &dev->i2s_speed); | 564 | em28xx_i2c_call_clients(dev, VIDIOC_INT_I2S_CLOCK_FREQ, |
565 | &dev->i2s_speed); | ||
566 | } | ||
186 | route.input = dev->ctl_ainput; | 567 | route.input = dev->ctl_ainput; |
187 | route.output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1); | 568 | route.output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1); |
188 | /* Note: this is msp3400 specific */ | 569 | /* Note: this is msp3400 specific */ |
189 | em28xx_i2c_call_clients(dev, VIDIOC_INT_S_AUDIO_ROUTING, &route); | 570 | em28xx_i2c_call_clients(dev, VIDIOC_INT_S_AUDIO_ROUTING, |
571 | &route); | ||
190 | } | 572 | } |
191 | 573 | ||
192 | em28xx_audio_analog_set(dev); | 574 | em28xx_audio_analog_set(dev); |
@@ -202,15 +584,12 @@ static int res_get(struct em28xx_fh *fh) | |||
202 | if (fh->stream_on) | 584 | if (fh->stream_on) |
203 | return rc; | 585 | return rc; |
204 | 586 | ||
205 | mutex_lock(&dev->lock); | ||
206 | |||
207 | if (dev->stream_on) | 587 | if (dev->stream_on) |
208 | rc = -EINVAL; | 588 | return -EINVAL; |
209 | else { | ||
210 | dev->stream_on = 1; | ||
211 | fh->stream_on = 1; | ||
212 | } | ||
213 | 589 | ||
590 | mutex_lock(&dev->lock); | ||
591 | dev->stream_on = 1; | ||
592 | fh->stream_on = 1; | ||
214 | mutex_unlock(&dev->lock); | 593 | mutex_unlock(&dev->lock); |
215 | return rc; | 594 | return rc; |
216 | } | 595 | } |
@@ -231,33 +610,6 @@ static void res_free(struct em28xx_fh *fh) | |||
231 | } | 610 | } |
232 | 611 | ||
233 | /* | 612 | /* |
234 | * em28xx_vm_open() | ||
235 | */ | ||
236 | static void em28xx_vm_open(struct vm_area_struct *vma) | ||
237 | { | ||
238 | struct em28xx_frame_t *f = vma->vm_private_data; | ||
239 | f->vma_use_count++; | ||
240 | } | ||
241 | |||
242 | /* | ||
243 | * em28xx_vm_close() | ||
244 | */ | ||
245 | static void em28xx_vm_close(struct vm_area_struct *vma) | ||
246 | { | ||
247 | /* NOTE: buffers are not freed here */ | ||
248 | struct em28xx_frame_t *f = vma->vm_private_data; | ||
249 | |||
250 | if (f->vma_use_count) | ||
251 | f->vma_use_count--; | ||
252 | } | ||
253 | |||
254 | static struct vm_operations_struct em28xx_vm_ops = { | ||
255 | .open = em28xx_vm_open, | ||
256 | .close = em28xx_vm_close, | ||
257 | }; | ||
258 | |||
259 | |||
260 | /* | ||
261 | * em28xx_get_ctrl() | 613 | * em28xx_get_ctrl() |
262 | * return the current saturation, brightness or contrast, mute state | 614 | * return the current saturation, brightness or contrast, mute state |
263 | */ | 615 | */ |
@@ -296,34 +648,6 @@ static int em28xx_set_ctrl(struct em28xx *dev, const struct v4l2_control *ctrl) | |||
296 | } | 648 | } |
297 | } | 649 | } |
298 | 650 | ||
299 | /* | ||
300 | * em28xx_stream_interrupt() | ||
301 | * stops streaming | ||
302 | */ | ||
303 | static int em28xx_stream_interrupt(struct em28xx *dev) | ||
304 | { | ||
305 | int rc = 0; | ||
306 | |||
307 | /* stop reading from the device */ | ||
308 | |||
309 | dev->stream = STREAM_INTERRUPT; | ||
310 | rc = wait_event_timeout(dev->wait_stream, | ||
311 | (dev->stream == STREAM_OFF) || | ||
312 | (dev->state & DEV_DISCONNECTED), | ||
313 | EM28XX_URB_TIMEOUT); | ||
314 | |||
315 | if (rc) { | ||
316 | dev->state |= DEV_MISCONFIGURED; | ||
317 | em28xx_videodbg("device is misconfigured; close and " | ||
318 | "open /dev/video%d again\n", | ||
319 | dev->vdev->minor-MINOR_VFL_TYPE_GRABBER_MIN); | ||
320 | return rc; | ||
321 | } | ||
322 | |||
323 | return 0; | ||
324 | } | ||
325 | |||
326 | |||
327 | static int check_dev(struct em28xx *dev) | 651 | static int check_dev(struct em28xx *dev) |
328 | { | 652 | { |
329 | if (dev->state & DEV_DISCONNECTED) { | 653 | if (dev->state & DEV_DISCONNECTED) { |
@@ -370,8 +694,8 @@ static int vidioc_g_fmt_cap(struct file *file, void *priv, | |||
370 | f->fmt.pix.width = dev->width; | 694 | f->fmt.pix.width = dev->width; |
371 | f->fmt.pix.height = dev->height; | 695 | f->fmt.pix.height = dev->height; |
372 | f->fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV; | 696 | f->fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV; |
373 | f->fmt.pix.bytesperline = dev->bytesperline; | 697 | f->fmt.pix.bytesperline = dev->width * 2; |
374 | f->fmt.pix.sizeimage = dev->frame_size; | 698 | f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * dev->height; |
375 | f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; | 699 | f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
376 | 700 | ||
377 | /* FIXME: TOP? NONE? BOTTOM? ALTENATE? */ | 701 | /* FIXME: TOP? NONE? BOTTOM? ALTENATE? */ |
@@ -447,7 +771,7 @@ static int vidioc_s_fmt_cap(struct file *file, void *priv, | |||
447 | { | 771 | { |
448 | struct em28xx_fh *fh = priv; | 772 | struct em28xx_fh *fh = priv; |
449 | struct em28xx *dev = fh->dev; | 773 | struct em28xx *dev = fh->dev; |
450 | int rc, i; | 774 | int rc; |
451 | 775 | ||
452 | rc = check_dev(dev); | 776 | rc = check_dev(dev); |
453 | if (rc < 0) | 777 | if (rc < 0) |
@@ -457,49 +781,34 @@ static int vidioc_s_fmt_cap(struct file *file, void *priv, | |||
457 | 781 | ||
458 | mutex_lock(&dev->lock); | 782 | mutex_lock(&dev->lock); |
459 | 783 | ||
460 | for (i = 0; i < dev->num_frames; i++) | 784 | if (videobuf_queue_is_busy(&fh->vb_vidq)) { |
461 | if (dev->frame[i].vma_use_count) { | 785 | em28xx_errdev("%s queue busy\n", __func__); |
462 | em28xx_videodbg("VIDIOC_S_FMT failed. " | 786 | rc = -EBUSY; |
463 | "Unmap the buffers first.\n"); | 787 | goto out; |
464 | rc = -EINVAL; | ||
465 | goto err; | ||
466 | } | ||
467 | |||
468 | /* stop io in case it is already in progress */ | ||
469 | if (dev->stream == STREAM_ON) { | ||
470 | em28xx_videodbg("VIDIOC_SET_FMT: interrupting stream\n"); | ||
471 | rc = em28xx_stream_interrupt(dev); | ||
472 | if (rc < 0) | ||
473 | goto err; | ||
474 | } | 788 | } |
475 | 789 | ||
476 | em28xx_release_buffers(dev); | 790 | if (dev->stream_on && !fh->stream_on) { |
477 | dev->io = IO_NONE; | 791 | em28xx_errdev("%s device in use by another fh\n", __func__); |
792 | rc = -EBUSY; | ||
793 | goto out; | ||
794 | } | ||
478 | 795 | ||
479 | /* set new image size */ | 796 | /* set new image size */ |
480 | dev->width = f->fmt.pix.width; | 797 | dev->width = f->fmt.pix.width; |
481 | dev->height = f->fmt.pix.height; | 798 | dev->height = f->fmt.pix.height; |
482 | dev->frame_size = dev->width * dev->height * 2; | ||
483 | dev->field_size = dev->frame_size >> 1; | ||
484 | dev->bytesperline = dev->width * 2; | ||
485 | get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale); | 799 | get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale); |
486 | 800 | ||
487 | /* FIXME: This is really weird! Why capture is starting with | ||
488 | this ioctl ??? | ||
489 | */ | ||
490 | em28xx_uninit_isoc(dev); | ||
491 | em28xx_set_alternate(dev); | 801 | em28xx_set_alternate(dev); |
492 | em28xx_capture_start(dev, 1); | ||
493 | em28xx_resolution_set(dev); | 802 | em28xx_resolution_set(dev); |
494 | em28xx_init_isoc(dev); | 803 | |
495 | rc = 0; | 804 | rc = 0; |
496 | 805 | ||
497 | err: | 806 | out: |
498 | mutex_unlock(&dev->lock); | 807 | mutex_unlock(&dev->lock); |
499 | return rc; | 808 | return rc; |
500 | } | 809 | } |
501 | 810 | ||
502 | static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *norm) | 811 | static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id * norm) |
503 | { | 812 | { |
504 | struct em28xx_fh *fh = priv; | 813 | struct em28xx_fh *fh = priv; |
505 | struct em28xx *dev = fh->dev; | 814 | struct em28xx *dev = fh->dev; |
@@ -524,9 +833,6 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *norm) | |||
524 | /* set new image size */ | 833 | /* set new image size */ |
525 | dev->width = f.fmt.pix.width; | 834 | dev->width = f.fmt.pix.width; |
526 | dev->height = f.fmt.pix.height; | 835 | dev->height = f.fmt.pix.height; |
527 | dev->frame_size = dev->width * dev->height * 2; | ||
528 | dev->field_size = dev->frame_size >> 1; | ||
529 | dev->bytesperline = dev->width * 2; | ||
530 | get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale); | 836 | get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale); |
531 | 837 | ||
532 | em28xx_resolution_set(dev); | 838 | em28xx_resolution_set(dev); |
@@ -619,11 +925,11 @@ static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a) | |||
619 | 925 | ||
620 | index = dev->ctl_ainput; | 926 | index = dev->ctl_ainput; |
621 | 927 | ||
622 | if (index == 0) { | 928 | if (index == 0) |
623 | strcpy(a->name, "Television"); | 929 | strcpy(a->name, "Television"); |
624 | } else { | 930 | else |
625 | strcpy(a->name, "Line In"); | 931 | strcpy(a->name, "Line In"); |
626 | } | 932 | |
627 | a->capability = V4L2_AUDCAP_STEREO; | 933 | a->capability = V4L2_AUDCAP_STEREO; |
628 | a->index = index; | 934 | a->index = index; |
629 | 935 | ||
@@ -834,9 +1140,9 @@ static int vidioc_s_frequency(struct file *file, void *priv, | |||
834 | static int em28xx_reg_len(int reg) | 1140 | static int em28xx_reg_len(int reg) |
835 | { | 1141 | { |
836 | switch (reg) { | 1142 | switch (reg) { |
837 | case AC97LSB_REG: | 1143 | case EM28XX_R40_AC97LSB: |
838 | case HSCALELOW_REG: | 1144 | case EM28XX_R30_HSCALELOW: |
839 | case VSCALELOW_REG: | 1145 | case EM28XX_R32_VSCALELOW: |
840 | return 2; | 1146 | return 2; |
841 | default: | 1147 | default: |
842 | return 1; | 1148 | return 1; |
@@ -918,23 +1224,11 @@ static int vidioc_streamon(struct file *file, void *priv, | |||
918 | if (rc < 0) | 1224 | if (rc < 0) |
919 | return rc; | 1225 | return rc; |
920 | 1226 | ||
921 | if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE || dev->io != IO_MMAP) | ||
922 | return -EINVAL; | ||
923 | |||
924 | if (list_empty(&dev->inqueue)) | ||
925 | return -EINVAL; | ||
926 | |||
927 | mutex_lock(&dev->lock); | ||
928 | 1227 | ||
929 | if (unlikely(res_get(fh) < 0)) { | 1228 | if (unlikely(res_get(fh) < 0)) |
930 | mutex_unlock(&dev->lock); | ||
931 | return -EBUSY; | 1229 | return -EBUSY; |
932 | } | ||
933 | 1230 | ||
934 | dev->stream = STREAM_ON; /* FIXME: Start video capture here? */ | 1231 | return (videobuf_streamon(&fh->vb_vidq)); |
935 | |||
936 | mutex_unlock(&dev->lock); | ||
937 | return 0; | ||
938 | } | 1232 | } |
939 | 1233 | ||
940 | static int vidioc_streamoff(struct file *file, void *priv, | 1234 | static int vidioc_streamoff(struct file *file, void *priv, |
@@ -948,23 +1242,14 @@ static int vidioc_streamoff(struct file *file, void *priv, | |||
948 | if (rc < 0) | 1242 | if (rc < 0) |
949 | return rc; | 1243 | return rc; |
950 | 1244 | ||
951 | if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE || dev->io != IO_MMAP) | 1245 | if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
1246 | return -EINVAL; | ||
1247 | if (type != fh->type) | ||
952 | return -EINVAL; | 1248 | return -EINVAL; |
953 | 1249 | ||
954 | mutex_lock(&dev->lock); | 1250 | videobuf_streamoff(&fh->vb_vidq); |
955 | 1251 | res_free(fh); | |
956 | if (dev->stream == STREAM_ON) { | ||
957 | em28xx_videodbg("VIDIOC_STREAMOFF: interrupting stream\n"); | ||
958 | rc = em28xx_stream_interrupt(dev); | ||
959 | if (rc < 0) { | ||
960 | mutex_unlock(&dev->lock); | ||
961 | return rc; | ||
962 | } | ||
963 | } | ||
964 | |||
965 | em28xx_empty_framequeues(dev); | ||
966 | 1252 | ||
967 | mutex_unlock(&dev->lock); | ||
968 | return 0; | 1253 | return 0; |
969 | } | 1254 | } |
970 | 1255 | ||
@@ -1058,53 +1343,13 @@ static int vidioc_reqbufs(struct file *file, void *priv, | |||
1058 | { | 1343 | { |
1059 | struct em28xx_fh *fh = priv; | 1344 | struct em28xx_fh *fh = priv; |
1060 | struct em28xx *dev = fh->dev; | 1345 | struct em28xx *dev = fh->dev; |
1061 | u32 i; | ||
1062 | int rc; | 1346 | int rc; |
1063 | 1347 | ||
1064 | rc = check_dev(dev); | 1348 | rc = check_dev(dev); |
1065 | if (rc < 0) | 1349 | if (rc < 0) |
1066 | return rc; | 1350 | return rc; |
1067 | 1351 | ||
1068 | if (rb->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || | 1352 | return (videobuf_reqbufs(&fh->vb_vidq, rb)); |
1069 | rb->memory != V4L2_MEMORY_MMAP) | ||
1070 | return -EINVAL; | ||
1071 | |||
1072 | if (dev->io == IO_READ) { | ||
1073 | em28xx_videodbg("method is set to read;" | ||
1074 | " close and open the device again to" | ||
1075 | " choose the mmap I/O method\n"); | ||
1076 | return -EINVAL; | ||
1077 | } | ||
1078 | |||
1079 | for (i = 0; i < dev->num_frames; i++) | ||
1080 | if (dev->frame[i].vma_use_count) { | ||
1081 | em28xx_videodbg("VIDIOC_REQBUFS failed; " | ||
1082 | "previous buffers are still mapped\n"); | ||
1083 | return -EINVAL; | ||
1084 | } | ||
1085 | |||
1086 | mutex_lock(&dev->lock); | ||
1087 | |||
1088 | if (dev->stream == STREAM_ON) { | ||
1089 | em28xx_videodbg("VIDIOC_REQBUFS: interrupting stream\n"); | ||
1090 | rc = em28xx_stream_interrupt(dev); | ||
1091 | if (rc < 0) { | ||
1092 | mutex_unlock(&dev->lock); | ||
1093 | return rc; | ||
1094 | } | ||
1095 | } | ||
1096 | |||
1097 | em28xx_empty_framequeues(dev); | ||
1098 | |||
1099 | em28xx_release_buffers(dev); | ||
1100 | if (rb->count) | ||
1101 | rb->count = em28xx_request_buffers(dev, rb->count); | ||
1102 | |||
1103 | dev->frame_current = NULL; | ||
1104 | dev->io = rb->count ? IO_MMAP : IO_NONE; | ||
1105 | |||
1106 | mutex_unlock(&dev->lock); | ||
1107 | return 0; | ||
1108 | } | 1353 | } |
1109 | 1354 | ||
1110 | static int vidioc_querybuf(struct file *file, void *priv, | 1355 | static int vidioc_querybuf(struct file *file, void *priv, |
@@ -1118,52 +1363,20 @@ static int vidioc_querybuf(struct file *file, void *priv, | |||
1118 | if (rc < 0) | 1363 | if (rc < 0) |
1119 | return rc; | 1364 | return rc; |
1120 | 1365 | ||
1121 | if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || | 1366 | return (videobuf_querybuf(&fh->vb_vidq, b)); |
1122 | b->index >= dev->num_frames || dev->io != IO_MMAP) | ||
1123 | return -EINVAL; | ||
1124 | |||
1125 | mutex_lock(&dev->lock); | ||
1126 | |||
1127 | memcpy(b, &dev->frame[b->index].buf, sizeof(*b)); | ||
1128 | |||
1129 | if (dev->frame[b->index].vma_use_count) | ||
1130 | b->flags |= V4L2_BUF_FLAG_MAPPED; | ||
1131 | |||
1132 | if (dev->frame[b->index].state == F_DONE) | ||
1133 | b->flags |= V4L2_BUF_FLAG_DONE; | ||
1134 | else if (dev->frame[b->index].state != F_UNUSED) | ||
1135 | b->flags |= V4L2_BUF_FLAG_QUEUED; | ||
1136 | |||
1137 | mutex_unlock(&dev->lock); | ||
1138 | return 0; | ||
1139 | } | 1367 | } |
1140 | 1368 | ||
1141 | static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b) | 1369 | static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b) |
1142 | { | 1370 | { |
1143 | struct em28xx_fh *fh = priv; | 1371 | struct em28xx_fh *fh = priv; |
1144 | struct em28xx *dev = fh->dev; | 1372 | struct em28xx *dev = fh->dev; |
1145 | unsigned long lock_flags; | ||
1146 | int rc; | 1373 | int rc; |
1147 | 1374 | ||
1148 | rc = check_dev(dev); | 1375 | rc = check_dev(dev); |
1149 | if (rc < 0) | 1376 | if (rc < 0) |
1150 | return rc; | 1377 | return rc; |
1151 | 1378 | ||
1152 | if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || dev->io != IO_MMAP || | 1379 | return (videobuf_qbuf(&fh->vb_vidq, b)); |
1153 | b->index >= dev->num_frames) | ||
1154 | return -EINVAL; | ||
1155 | |||
1156 | if (dev->frame[b->index].state != F_UNUSED) | ||
1157 | return -EAGAIN; | ||
1158 | |||
1159 | dev->frame[b->index].state = F_QUEUED; | ||
1160 | |||
1161 | /* add frame to fifo */ | ||
1162 | spin_lock_irqsave(&dev->queue_lock, lock_flags); | ||
1163 | list_add_tail(&dev->frame[b->index].frame, &dev->inqueue); | ||
1164 | spin_unlock_irqrestore(&dev->queue_lock, lock_flags); | ||
1165 | |||
1166 | return 0; | ||
1167 | } | 1380 | } |
1168 | 1381 | ||
1169 | static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b) | 1382 | static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b) |
@@ -1171,46 +1384,24 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b) | |||
1171 | struct em28xx_fh *fh = priv; | 1384 | struct em28xx_fh *fh = priv; |
1172 | struct em28xx *dev = fh->dev; | 1385 | struct em28xx *dev = fh->dev; |
1173 | int rc; | 1386 | int rc; |
1174 | struct em28xx_frame_t *f; | ||
1175 | unsigned long lock_flags; | ||
1176 | 1387 | ||
1177 | rc = check_dev(dev); | 1388 | rc = check_dev(dev); |
1178 | if (rc < 0) | 1389 | if (rc < 0) |
1179 | return rc; | 1390 | return rc; |
1180 | 1391 | ||
1181 | if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || dev->io != IO_MMAP) | 1392 | return (videobuf_dqbuf(&fh->vb_vidq, b, |
1182 | return -EINVAL; | 1393 | file->f_flags & O_NONBLOCK)); |
1183 | 1394 | } | |
1184 | if (list_empty(&dev->outqueue)) { | ||
1185 | if (dev->stream == STREAM_OFF) | ||
1186 | return -EINVAL; | ||
1187 | |||
1188 | if (file->f_flags & O_NONBLOCK) | ||
1189 | return -EAGAIN; | ||
1190 | |||
1191 | rc = wait_event_interruptible(dev->wait_frame, | ||
1192 | (!list_empty(&dev->outqueue)) || | ||
1193 | (dev->state & DEV_DISCONNECTED)); | ||
1194 | if (rc) | ||
1195 | return rc; | ||
1196 | |||
1197 | if (dev->state & DEV_DISCONNECTED) | ||
1198 | return -ENODEV; | ||
1199 | } | ||
1200 | |||
1201 | spin_lock_irqsave(&dev->queue_lock, lock_flags); | ||
1202 | f = list_entry(dev->outqueue.next, struct em28xx_frame_t, frame); | ||
1203 | list_del(dev->outqueue.next); | ||
1204 | spin_unlock_irqrestore(&dev->queue_lock, lock_flags); | ||
1205 | |||
1206 | f->state = F_UNUSED; | ||
1207 | memcpy(b, &f->buf, sizeof(*b)); | ||
1208 | 1395 | ||
1209 | if (f->vma_use_count) | 1396 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
1210 | b->flags |= V4L2_BUF_FLAG_MAPPED; | 1397 | static int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf) |
1398 | { | ||
1399 | struct em28xx_fh *fh = priv; | ||
1211 | 1400 | ||
1212 | return 0; | 1401 | return videobuf_cgmbuf(&fh->vb_vidq, mbuf, 8); |
1213 | } | 1402 | } |
1403 | #endif | ||
1404 | |||
1214 | 1405 | ||
1215 | /* ----------------------------------------------------------- */ | 1406 | /* ----------------------------------------------------------- */ |
1216 | /* RADIO ESPECIFIC IOCTLS */ | 1407 | /* RADIO ESPECIFIC IOCTLS */ |
@@ -1316,17 +1507,18 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp) | |||
1316 | { | 1507 | { |
1317 | int minor = iminor(inode); | 1508 | int minor = iminor(inode); |
1318 | int errCode = 0, radio = 0; | 1509 | int errCode = 0, radio = 0; |
1319 | struct em28xx *h,*dev = NULL; | 1510 | struct em28xx *h, *dev = NULL; |
1320 | struct em28xx_fh *fh; | 1511 | struct em28xx_fh *fh; |
1512 | enum v4l2_buf_type fh_type = 0; | ||
1321 | 1513 | ||
1322 | list_for_each_entry(h, &em28xx_devlist, devlist) { | 1514 | list_for_each_entry(h, &em28xx_devlist, devlist) { |
1323 | if (h->vdev->minor == minor) { | 1515 | if (h->vdev->minor == minor) { |
1324 | dev = h; | 1516 | dev = h; |
1325 | dev->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; | 1517 | fh_type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
1326 | } | 1518 | } |
1327 | if (h->vbi_dev->minor == minor) { | 1519 | if (h->vbi_dev->minor == minor) { |
1328 | dev = h; | 1520 | dev = h; |
1329 | dev->type = V4L2_BUF_TYPE_VBI_CAPTURE; | 1521 | fh_type = V4L2_BUF_TYPE_VBI_CAPTURE; |
1330 | } | 1522 | } |
1331 | if (h->radio_dev && | 1523 | if (h->radio_dev && |
1332 | h->radio_dev->minor == minor) { | 1524 | h->radio_dev->minor == minor) { |
@@ -1338,10 +1530,10 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp) | |||
1338 | return -ENODEV; | 1530 | return -ENODEV; |
1339 | 1531 | ||
1340 | em28xx_videodbg("open minor=%d type=%s users=%d\n", | 1532 | em28xx_videodbg("open minor=%d type=%s users=%d\n", |
1341 | minor,v4l2_type_names[dev->type],dev->users); | 1533 | minor, v4l2_type_names[fh_type], dev->users); |
1342 | 1534 | ||
1343 | fh = kzalloc(sizeof(struct em28xx_fh), GFP_KERNEL); | ||
1344 | 1535 | ||
1536 | fh = kzalloc(sizeof(struct em28xx_fh), GFP_KERNEL); | ||
1345 | if (!fh) { | 1537 | if (!fh) { |
1346 | em28xx_errdev("em28xx-video.c: Out of memory?!\n"); | 1538 | em28xx_errdev("em28xx-video.c: Out of memory?!\n"); |
1347 | return -ENOMEM; | 1539 | return -ENOMEM; |
@@ -1349,28 +1541,24 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp) | |||
1349 | mutex_lock(&dev->lock); | 1541 | mutex_lock(&dev->lock); |
1350 | fh->dev = dev; | 1542 | fh->dev = dev; |
1351 | fh->radio = radio; | 1543 | fh->radio = radio; |
1544 | fh->type = fh_type; | ||
1352 | filp->private_data = fh; | 1545 | filp->private_data = fh; |
1353 | 1546 | ||
1354 | if (dev->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && dev->users == 0) { | 1547 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && dev->users == 0) { |
1355 | dev->width = norm_maxw(dev); | 1548 | dev->width = norm_maxw(dev); |
1356 | dev->height = norm_maxh(dev); | 1549 | dev->height = norm_maxh(dev); |
1357 | dev->frame_size = dev->width * dev->height * 2; | ||
1358 | dev->field_size = dev->frame_size >> 1; /*both_fileds ? dev->frame_size>>1 : dev->frame_size; */ | ||
1359 | dev->bytesperline = dev->width * 2; | ||
1360 | dev->hscale = 0; | 1550 | dev->hscale = 0; |
1361 | dev->vscale = 0; | 1551 | dev->vscale = 0; |
1362 | 1552 | ||
1553 | em28xx_set_mode(dev, EM28XX_ANALOG_MODE); | ||
1363 | em28xx_set_alternate(dev); | 1554 | em28xx_set_alternate(dev); |
1364 | em28xx_capture_start(dev, 1); | ||
1365 | em28xx_resolution_set(dev); | 1555 | em28xx_resolution_set(dev); |
1366 | 1556 | ||
1557 | /* Needed, since GPIO might have disabled power of | ||
1558 | some i2c device | ||
1559 | */ | ||
1560 | em28xx_config_i2c(dev); | ||
1367 | 1561 | ||
1368 | /* start the transfer */ | ||
1369 | errCode = em28xx_init_isoc(dev); | ||
1370 | if (errCode) | ||
1371 | goto err; | ||
1372 | |||
1373 | em28xx_empty_framequeues(dev); | ||
1374 | } | 1562 | } |
1375 | if (fh->radio) { | 1563 | if (fh->radio) { |
1376 | em28xx_videodbg("video_open: setting radio device\n"); | 1564 | em28xx_videodbg("video_open: setting radio device\n"); |
@@ -1379,8 +1567,12 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp) | |||
1379 | 1567 | ||
1380 | dev->users++; | 1568 | dev->users++; |
1381 | 1569 | ||
1382 | err: | 1570 | videobuf_queue_vmalloc_init(&fh->vb_vidq, &em28xx_video_qops, |
1571 | NULL, &dev->slock, fh->type, V4L2_FIELD_INTERLACED, | ||
1572 | sizeof(struct em28xx_buffer), fh); | ||
1573 | |||
1383 | mutex_unlock(&dev->lock); | 1574 | mutex_unlock(&dev->lock); |
1575 | |||
1384 | return errCode; | 1576 | return errCode; |
1385 | } | 1577 | } |
1386 | 1578 | ||
@@ -1423,12 +1615,13 @@ static void em28xx_release_resources(struct em28xx *dev) | |||
1423 | usb_put_dev(dev->udev); | 1615 | usb_put_dev(dev->udev); |
1424 | 1616 | ||
1425 | /* Mark device as unused */ | 1617 | /* Mark device as unused */ |
1426 | em28xx_devused&=~(1<<dev->devno); | 1618 | em28xx_devused &= ~(1<<dev->devno); |
1427 | } | 1619 | } |
1428 | 1620 | ||
1429 | /* | 1621 | /* |
1430 | * em28xx_v4l2_close() | 1622 | * em28xx_v4l2_close() |
1431 | * stops streaming and deallocates all resources allocated by the v4l2 calls and ioctls | 1623 | * stops streaming and deallocates all resources allocated by the v4l2 |
1624 | * calls and ioctls | ||
1432 | */ | 1625 | */ |
1433 | static int em28xx_v4l2_close(struct inode *inode, struct file *filp) | 1626 | static int em28xx_v4l2_close(struct inode *inode, struct file *filp) |
1434 | { | 1627 | { |
@@ -1445,9 +1638,8 @@ static int em28xx_v4l2_close(struct inode *inode, struct file *filp) | |||
1445 | mutex_lock(&dev->lock); | 1638 | mutex_lock(&dev->lock); |
1446 | 1639 | ||
1447 | if (dev->users == 1) { | 1640 | if (dev->users == 1) { |
1448 | em28xx_uninit_isoc(dev); | 1641 | videobuf_stop(&fh->vb_vidq); |
1449 | em28xx_release_buffers(dev); | 1642 | videobuf_mmap_free(&fh->vb_vidq); |
1450 | dev->io = IO_NONE; | ||
1451 | 1643 | ||
1452 | /* the device is already disconnect, | 1644 | /* the device is already disconnect, |
1453 | free the remaining resources */ | 1645 | free the remaining resources */ |
@@ -1458,6 +1650,10 @@ static int em28xx_v4l2_close(struct inode *inode, struct file *filp) | |||
1458 | return 0; | 1650 | return 0; |
1459 | } | 1651 | } |
1460 | 1652 | ||
1653 | /* do this before setting alternate! */ | ||
1654 | em28xx_uninit_isoc(dev); | ||
1655 | em28xx_set_mode(dev, EM28XX_MODE_UNDEFINED); | ||
1656 | |||
1461 | /* set alternate 0 */ | 1657 | /* set alternate 0 */ |
1462 | dev->alt = 0; | 1658 | dev->alt = 0; |
1463 | em28xx_videodbg("setting alternate 0\n"); | 1659 | em28xx_videodbg("setting alternate 0\n"); |
@@ -1479,135 +1675,29 @@ static int em28xx_v4l2_close(struct inode *inode, struct file *filp) | |||
1479 | * will allocate buffers when called for the first time | 1675 | * will allocate buffers when called for the first time |
1480 | */ | 1676 | */ |
1481 | static ssize_t | 1677 | static ssize_t |
1482 | em28xx_v4l2_read(struct file *filp, char __user * buf, size_t count, | 1678 | em28xx_v4l2_read(struct file *filp, char __user *buf, size_t count, |
1483 | loff_t * f_pos) | 1679 | loff_t *pos) |
1484 | { | 1680 | { |
1485 | struct em28xx_frame_t *f, *i; | ||
1486 | unsigned long lock_flags; | ||
1487 | int ret = 0; | ||
1488 | struct em28xx_fh *fh = filp->private_data; | 1681 | struct em28xx_fh *fh = filp->private_data; |
1489 | struct em28xx *dev = fh->dev; | 1682 | struct em28xx *dev = fh->dev; |
1683 | int rc; | ||
1684 | |||
1685 | rc = check_dev(dev); | ||
1686 | if (rc < 0) | ||
1687 | return rc; | ||
1490 | 1688 | ||
1491 | /* FIXME: read() is not prepared to allow changing the video | 1689 | /* FIXME: read() is not prepared to allow changing the video |
1492 | resolution while streaming. Seems a bug at em28xx_set_fmt | 1690 | resolution while streaming. Seems a bug at em28xx_set_fmt |
1493 | */ | 1691 | */ |
1494 | 1692 | ||
1495 | if (unlikely(res_get(fh) < 0)) | 1693 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { |
1496 | return -EBUSY; | 1694 | if (unlikely(res_get(fh))) |
1497 | 1695 | return -EBUSY; | |
1498 | mutex_lock(&dev->lock); | ||
1499 | |||
1500 | if (dev->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) | ||
1501 | em28xx_videodbg("V4l2_Buf_type_videocapture is set\n"); | ||
1502 | 1696 | ||
1503 | if (dev->type == V4L2_BUF_TYPE_VBI_CAPTURE) { | 1697 | return videobuf_read_stream(&fh->vb_vidq, buf, count, pos, 0, |
1504 | em28xx_videodbg("V4L2_BUF_TYPE_VBI_CAPTURE is set\n"); | 1698 | filp->f_flags & O_NONBLOCK); |
1505 | em28xx_videodbg("not supported yet! ...\n"); | ||
1506 | if (copy_to_user(buf, "", 1)) { | ||
1507 | mutex_unlock(&dev->lock); | ||
1508 | return -EFAULT; | ||
1509 | } | ||
1510 | mutex_unlock(&dev->lock); | ||
1511 | return (1); | ||
1512 | } | ||
1513 | if (dev->type == V4L2_BUF_TYPE_SLICED_VBI_CAPTURE) { | ||
1514 | em28xx_videodbg("V4L2_BUF_TYPE_SLICED_VBI_CAPTURE is set\n"); | ||
1515 | em28xx_videodbg("not supported yet! ...\n"); | ||
1516 | if (copy_to_user(buf, "", 1)) { | ||
1517 | mutex_unlock(&dev->lock); | ||
1518 | return -EFAULT; | ||
1519 | } | ||
1520 | mutex_unlock(&dev->lock); | ||
1521 | return (1); | ||
1522 | } | 1699 | } |
1523 | 1700 | return 0; | |
1524 | if (dev->state & DEV_DISCONNECTED) { | ||
1525 | em28xx_videodbg("device not present\n"); | ||
1526 | mutex_unlock(&dev->lock); | ||
1527 | return -ENODEV; | ||
1528 | } | ||
1529 | |||
1530 | if (dev->state & DEV_MISCONFIGURED) { | ||
1531 | em28xx_videodbg("device misconfigured; close and open it again\n"); | ||
1532 | mutex_unlock(&dev->lock); | ||
1533 | return -EIO; | ||
1534 | } | ||
1535 | |||
1536 | if (dev->io == IO_MMAP) { | ||
1537 | em28xx_videodbg ("IO method is set to mmap; close and open" | ||
1538 | " the device again to choose the read method\n"); | ||
1539 | mutex_unlock(&dev->lock); | ||
1540 | return -EINVAL; | ||
1541 | } | ||
1542 | |||
1543 | if (dev->io == IO_NONE) { | ||
1544 | if (!em28xx_request_buffers(dev, EM28XX_NUM_READ_FRAMES)) { | ||
1545 | em28xx_errdev("read failed, not enough memory\n"); | ||
1546 | mutex_unlock(&dev->lock); | ||
1547 | return -ENOMEM; | ||
1548 | } | ||
1549 | dev->io = IO_READ; | ||
1550 | dev->stream = STREAM_ON; | ||
1551 | em28xx_queue_unusedframes(dev); | ||
1552 | } | ||
1553 | |||
1554 | if (!count) { | ||
1555 | mutex_unlock(&dev->lock); | ||
1556 | return 0; | ||
1557 | } | ||
1558 | |||
1559 | if (list_empty(&dev->outqueue)) { | ||
1560 | if (filp->f_flags & O_NONBLOCK) { | ||
1561 | mutex_unlock(&dev->lock); | ||
1562 | return -EAGAIN; | ||
1563 | } | ||
1564 | ret = wait_event_interruptible | ||
1565 | (dev->wait_frame, | ||
1566 | (!list_empty(&dev->outqueue)) || | ||
1567 | (dev->state & DEV_DISCONNECTED)); | ||
1568 | if (ret) { | ||
1569 | mutex_unlock(&dev->lock); | ||
1570 | return ret; | ||
1571 | } | ||
1572 | if (dev->state & DEV_DISCONNECTED) { | ||
1573 | mutex_unlock(&dev->lock); | ||
1574 | return -ENODEV; | ||
1575 | } | ||
1576 | dev->video_bytesread = 0; | ||
1577 | } | ||
1578 | |||
1579 | f = list_entry(dev->outqueue.prev, struct em28xx_frame_t, frame); | ||
1580 | |||
1581 | em28xx_queue_unusedframes(dev); | ||
1582 | |||
1583 | if (count > f->buf.length) | ||
1584 | count = f->buf.length; | ||
1585 | |||
1586 | if ((dev->video_bytesread + count) > dev->frame_size) | ||
1587 | count = dev->frame_size - dev->video_bytesread; | ||
1588 | |||
1589 | if (copy_to_user(buf, f->bufmem+dev->video_bytesread, count)) { | ||
1590 | em28xx_err("Error while copying to user\n"); | ||
1591 | return -EFAULT; | ||
1592 | } | ||
1593 | dev->video_bytesread += count; | ||
1594 | |||
1595 | if (dev->video_bytesread == dev->frame_size) { | ||
1596 | spin_lock_irqsave(&dev->queue_lock, lock_flags); | ||
1597 | list_for_each_entry(i, &dev->outqueue, frame) | ||
1598 | i->state = F_UNUSED; | ||
1599 | INIT_LIST_HEAD(&dev->outqueue); | ||
1600 | spin_unlock_irqrestore(&dev->queue_lock, lock_flags); | ||
1601 | |||
1602 | em28xx_queue_unusedframes(dev); | ||
1603 | dev->video_bytesread = 0; | ||
1604 | } | ||
1605 | |||
1606 | *f_pos += count; | ||
1607 | |||
1608 | mutex_unlock(&dev->lock); | ||
1609 | |||
1610 | return count; | ||
1611 | } | 1701 | } |
1612 | 1702 | ||
1613 | /* | 1703 | /* |
@@ -1616,46 +1706,21 @@ em28xx_v4l2_read(struct file *filp, char __user * buf, size_t count, | |||
1616 | */ | 1706 | */ |
1617 | static unsigned int em28xx_v4l2_poll(struct file *filp, poll_table * wait) | 1707 | static unsigned int em28xx_v4l2_poll(struct file *filp, poll_table * wait) |
1618 | { | 1708 | { |
1619 | unsigned int mask = 0; | ||
1620 | struct em28xx_fh *fh = filp->private_data; | 1709 | struct em28xx_fh *fh = filp->private_data; |
1621 | struct em28xx *dev = fh->dev; | 1710 | struct em28xx *dev = fh->dev; |
1711 | int rc; | ||
1712 | |||
1713 | rc = check_dev(dev); | ||
1714 | if (rc < 0) | ||
1715 | return rc; | ||
1622 | 1716 | ||
1623 | if (unlikely(res_get(fh) < 0)) | 1717 | if (unlikely(res_get(fh) < 0)) |
1624 | return POLLERR; | 1718 | return POLLERR; |
1625 | 1719 | ||
1626 | mutex_lock(&dev->lock); | 1720 | if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type) |
1627 | 1721 | return POLLERR; | |
1628 | if (dev->state & DEV_DISCONNECTED) { | ||
1629 | em28xx_videodbg("device not present\n"); | ||
1630 | } else if (dev->state & DEV_MISCONFIGURED) { | ||
1631 | em28xx_videodbg("device is misconfigured; close and open it again\n"); | ||
1632 | } else { | ||
1633 | if (dev->io == IO_NONE) { | ||
1634 | if (!em28xx_request_buffers | ||
1635 | (dev, EM28XX_NUM_READ_FRAMES)) { | ||
1636 | em28xx_warn | ||
1637 | ("poll() failed, not enough memory\n"); | ||
1638 | } else { | ||
1639 | dev->io = IO_READ; | ||
1640 | dev->stream = STREAM_ON; | ||
1641 | } | ||
1642 | } | ||
1643 | |||
1644 | if (dev->io == IO_READ) { | ||
1645 | em28xx_queue_unusedframes(dev); | ||
1646 | poll_wait(filp, &dev->wait_frame, wait); | ||
1647 | |||
1648 | if (!list_empty(&dev->outqueue)) | ||
1649 | mask |= POLLIN | POLLRDNORM; | ||
1650 | |||
1651 | mutex_unlock(&dev->lock); | ||
1652 | |||
1653 | return mask; | ||
1654 | } | ||
1655 | } | ||
1656 | 1722 | ||
1657 | mutex_unlock(&dev->lock); | 1723 | return videobuf_poll_stream(filp, &fh->vb_vidq, wait); |
1658 | return POLLERR; | ||
1659 | } | 1724 | } |
1660 | 1725 | ||
1661 | /* | 1726 | /* |
@@ -1665,69 +1730,23 @@ static int em28xx_v4l2_mmap(struct file *filp, struct vm_area_struct *vma) | |||
1665 | { | 1730 | { |
1666 | struct em28xx_fh *fh = filp->private_data; | 1731 | struct em28xx_fh *fh = filp->private_data; |
1667 | struct em28xx *dev = fh->dev; | 1732 | struct em28xx *dev = fh->dev; |
1668 | unsigned long size = vma->vm_end - vma->vm_start; | 1733 | int rc; |
1669 | unsigned long start = vma->vm_start; | ||
1670 | void *pos; | ||
1671 | u32 i; | ||
1672 | 1734 | ||
1673 | if (unlikely(res_get(fh) < 0)) | 1735 | if (unlikely(res_get(fh) < 0)) |
1674 | return -EBUSY; | 1736 | return -EBUSY; |
1675 | 1737 | ||
1676 | mutex_lock(&dev->lock); | 1738 | rc = check_dev(dev); |
1677 | 1739 | if (rc < 0) | |
1678 | if (dev->state & DEV_DISCONNECTED) { | 1740 | return rc; |
1679 | em28xx_videodbg("mmap: device not present\n"); | ||
1680 | mutex_unlock(&dev->lock); | ||
1681 | return -ENODEV; | ||
1682 | } | ||
1683 | |||
1684 | if (dev->state & DEV_MISCONFIGURED) { | ||
1685 | em28xx_videodbg ("mmap: Device is misconfigured; close and " | ||
1686 | "open it again\n"); | ||
1687 | mutex_unlock(&dev->lock); | ||
1688 | return -EIO; | ||
1689 | } | ||
1690 | |||
1691 | if (dev->io != IO_MMAP || !(vma->vm_flags & VM_WRITE)) { | ||
1692 | mutex_unlock(&dev->lock); | ||
1693 | return -EINVAL; | ||
1694 | } | ||
1695 | |||
1696 | if (size > PAGE_ALIGN(dev->frame[0].buf.length)) | ||
1697 | size = PAGE_ALIGN(dev->frame[0].buf.length); | ||
1698 | |||
1699 | for (i = 0; i < dev->num_frames; i++) { | ||
1700 | if ((dev->frame[i].buf.m.offset >> PAGE_SHIFT) == vma->vm_pgoff) | ||
1701 | break; | ||
1702 | } | ||
1703 | if (i == dev->num_frames) { | ||
1704 | em28xx_videodbg("mmap: user supplied mapping address is out of range\n"); | ||
1705 | mutex_unlock(&dev->lock); | ||
1706 | return -EINVAL; | ||
1707 | } | ||
1708 | |||
1709 | /* VM_IO is eventually going to replace PageReserved altogether */ | ||
1710 | vma->vm_flags |= VM_IO; | ||
1711 | vma->vm_flags |= VM_RESERVED; /* avoid to swap out this VMA */ | ||
1712 | 1741 | ||
1713 | pos = dev->frame[i].bufmem; | 1742 | rc = videobuf_mmap_mapper(&fh->vb_vidq, vma); |
1714 | while (size > 0) { /* size is page-aligned */ | ||
1715 | if (vm_insert_page(vma, start, vmalloc_to_page(pos))) { | ||
1716 | em28xx_videodbg("mmap: vm_insert_page failed\n"); | ||
1717 | mutex_unlock(&dev->lock); | ||
1718 | return -EAGAIN; | ||
1719 | } | ||
1720 | start += PAGE_SIZE; | ||
1721 | pos += PAGE_SIZE; | ||
1722 | size -= PAGE_SIZE; | ||
1723 | } | ||
1724 | 1743 | ||
1725 | vma->vm_ops = &em28xx_vm_ops; | 1744 | em28xx_videodbg("vma start=0x%08lx, size=%ld, ret=%d\n", |
1726 | vma->vm_private_data = &dev->frame[i]; | 1745 | (unsigned long)vma->vm_start, |
1746 | (unsigned long)vma->vm_end-(unsigned long)vma->vm_start, | ||
1747 | rc); | ||
1727 | 1748 | ||
1728 | em28xx_vm_open(vma); | 1749 | return rc; |
1729 | mutex_unlock(&dev->lock); | ||
1730 | return 0; | ||
1731 | } | 1750 | } |
1732 | 1751 | ||
1733 | static const struct file_operations em28xx_v4l_fops = { | 1752 | static const struct file_operations em28xx_v4l_fops = { |
@@ -1790,6 +1809,9 @@ static const struct video_device em28xx_video_template = { | |||
1790 | .vidioc_g_register = vidioc_g_register, | 1809 | .vidioc_g_register = vidioc_g_register, |
1791 | .vidioc_s_register = vidioc_s_register, | 1810 | .vidioc_s_register = vidioc_s_register, |
1792 | #endif | 1811 | #endif |
1812 | #ifdef CONFIG_VIDEO_V4L1_COMPAT | ||
1813 | .vidiocgmbuf = vidiocgmbuf, | ||
1814 | #endif | ||
1793 | 1815 | ||
1794 | .tvnorms = V4L2_STD_ALL, | 1816 | .tvnorms = V4L2_STD_ALL, |
1795 | .current_norm = V4L2_STD_PAL, | 1817 | .current_norm = V4L2_STD_PAL, |
@@ -1818,7 +1840,7 @@ static struct video_device em28xx_radio_template = { | |||
1818 | #endif | 1840 | #endif |
1819 | }; | 1841 | }; |
1820 | 1842 | ||
1821 | /******************************** usb interface *****************************************/ | 1843 | /******************************** usb interface ******************************/ |
1822 | 1844 | ||
1823 | 1845 | ||
1824 | static LIST_HEAD(em28xx_extension_devlist); | 1846 | static LIST_HEAD(em28xx_extension_devlist); |
@@ -1875,6 +1897,7 @@ static struct video_device *em28xx_vdev_init(struct em28xx *dev, | |||
1875 | vfd->dev = &dev->udev->dev; | 1897 | vfd->dev = &dev->udev->dev; |
1876 | vfd->release = video_device_release; | 1898 | vfd->release = video_device_release; |
1877 | vfd->type = type; | 1899 | vfd->type = type; |
1900 | vfd->debug = video_debug; | ||
1878 | 1901 | ||
1879 | snprintf(vfd->name, sizeof(vfd->name), "%s %s", | 1902 | snprintf(vfd->name, sizeof(vfd->name), "%s %s", |
1880 | dev->name, type_name); | 1903 | dev->name, type_name); |
@@ -1898,7 +1921,7 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev, | |||
1898 | 1921 | ||
1899 | dev->udev = udev; | 1922 | dev->udev = udev; |
1900 | mutex_init(&dev->lock); | 1923 | mutex_init(&dev->lock); |
1901 | spin_lock_init(&dev->queue_lock); | 1924 | spin_lock_init(&dev->slock); |
1902 | init_waitqueue_head(&dev->open); | 1925 | init_waitqueue_head(&dev->open); |
1903 | init_waitqueue_head(&dev->wait_frame); | 1926 | init_waitqueue_head(&dev->wait_frame); |
1904 | init_waitqueue_head(&dev->wait_stream); | 1927 | init_waitqueue_head(&dev->wait_stream); |
@@ -1910,10 +1933,6 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev, | |||
1910 | dev->em28xx_read_reg_req = em28xx_read_reg_req; | 1933 | dev->em28xx_read_reg_req = em28xx_read_reg_req; |
1911 | dev->is_em2800 = em28xx_boards[dev->model].is_em2800; | 1934 | dev->is_em2800 = em28xx_boards[dev->model].is_em2800; |
1912 | 1935 | ||
1913 | errCode = em28xx_read_reg(dev, CHIPID_REG); | ||
1914 | if (errCode >= 0) | ||
1915 | em28xx_info("em28xx chip ID = %d\n", errCode); | ||
1916 | |||
1917 | em28xx_pre_card_setup(dev); | 1936 | em28xx_pre_card_setup(dev); |
1918 | 1937 | ||
1919 | errCode = em28xx_config(dev); | 1938 | errCode = em28xx_config(dev); |
@@ -1946,10 +1965,6 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev, | |||
1946 | dev->width = maxw; | 1965 | dev->width = maxw; |
1947 | dev->height = maxh; | 1966 | dev->height = maxh; |
1948 | dev->interlaced = EM28XX_INTERLACED_DEFAULT; | 1967 | dev->interlaced = EM28XX_INTERLACED_DEFAULT; |
1949 | dev->field_size = dev->width * dev->height; | ||
1950 | dev->frame_size = | ||
1951 | dev->interlaced ? dev->field_size << 1 : dev->field_size; | ||
1952 | dev->bytesperline = dev->width * 2; | ||
1953 | dev->hscale = 0; | 1968 | dev->hscale = 0; |
1954 | dev->vscale = 0; | 1969 | dev->vscale = 0; |
1955 | dev->ctl_input = 2; | 1970 | dev->ctl_input = 2; |
@@ -2005,6 +2020,10 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev, | |||
2005 | dev->radio_dev->minor & 0x1f); | 2020 | dev->radio_dev->minor & 0x1f); |
2006 | } | 2021 | } |
2007 | 2022 | ||
2023 | /* init video dma queues */ | ||
2024 | INIT_LIST_HEAD(&dev->vidq.active); | ||
2025 | INIT_LIST_HEAD(&dev->vidq.queued); | ||
2026 | |||
2008 | 2027 | ||
2009 | if (dev->has_msp34xx) { | 2028 | if (dev->has_msp34xx) { |
2010 | /* Send a reset to other chips via gpio */ | 2029 | /* Send a reset to other chips via gpio */ |
@@ -2048,6 +2067,9 @@ static void request_module_async(struct work_struct *work) | |||
2048 | request_module("snd-usb-audio"); | 2067 | request_module("snd-usb-audio"); |
2049 | else | 2068 | else |
2050 | request_module("em28xx-alsa"); | 2069 | request_module("em28xx-alsa"); |
2070 | |||
2071 | if (dev->has_dvb) | ||
2072 | request_module("em28xx-dvb"); | ||
2051 | } | 2073 | } |
2052 | 2074 | ||
2053 | static void request_modules(struct em28xx *dev) | 2075 | static void request_modules(struct em28xx *dev) |
@@ -2077,22 +2099,24 @@ static int em28xx_usb_probe(struct usb_interface *interface, | |||
2077 | ifnum = interface->altsetting[0].desc.bInterfaceNumber; | 2099 | ifnum = interface->altsetting[0].desc.bInterfaceNumber; |
2078 | 2100 | ||
2079 | /* Check to see next free device and mark as used */ | 2101 | /* Check to see next free device and mark as used */ |
2080 | nr=find_first_zero_bit(&em28xx_devused,EM28XX_MAXBOARDS); | 2102 | nr = find_first_zero_bit(&em28xx_devused, EM28XX_MAXBOARDS); |
2081 | em28xx_devused|=1<<nr; | 2103 | em28xx_devused |= 1<<nr; |
2082 | 2104 | ||
2083 | /* Don't register audio interfaces */ | 2105 | /* Don't register audio interfaces */ |
2084 | if (interface->altsetting[0].desc.bInterfaceClass == USB_CLASS_AUDIO) { | 2106 | if (interface->altsetting[0].desc.bInterfaceClass == USB_CLASS_AUDIO) { |
2085 | em28xx_err(DRIVER_NAME " audio device (%04x:%04x): interface %i, class %i\n", | 2107 | em28xx_err(DRIVER_NAME " audio device (%04x:%04x): interface %i, class %i\n", |
2086 | udev->descriptor.idVendor,udev->descriptor.idProduct, | 2108 | udev->descriptor.idVendor, |
2109 | udev->descriptor.idProduct, | ||
2087 | ifnum, | 2110 | ifnum, |
2088 | interface->altsetting[0].desc.bInterfaceClass); | 2111 | interface->altsetting[0].desc.bInterfaceClass); |
2089 | 2112 | ||
2090 | em28xx_devused&=~(1<<nr); | 2113 | em28xx_devused &= ~(1<<nr); |
2091 | return -ENODEV; | 2114 | return -ENODEV; |
2092 | } | 2115 | } |
2093 | 2116 | ||
2094 | em28xx_err(DRIVER_NAME " new video device (%04x:%04x): interface %i, class %i\n", | 2117 | em28xx_err(DRIVER_NAME " new video device (%04x:%04x): interface %i, class %i\n", |
2095 | udev->descriptor.idVendor,udev->descriptor.idProduct, | 2118 | udev->descriptor.idVendor, |
2119 | udev->descriptor.idProduct, | ||
2096 | ifnum, | 2120 | ifnum, |
2097 | interface->altsetting[0].desc.bInterfaceClass); | 2121 | interface->altsetting[0].desc.bInterfaceClass); |
2098 | 2122 | ||
@@ -2102,18 +2126,19 @@ static int em28xx_usb_probe(struct usb_interface *interface, | |||
2102 | if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != | 2126 | if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != |
2103 | USB_ENDPOINT_XFER_ISOC) { | 2127 | USB_ENDPOINT_XFER_ISOC) { |
2104 | em28xx_err(DRIVER_NAME " probing error: endpoint is non-ISO endpoint!\n"); | 2128 | em28xx_err(DRIVER_NAME " probing error: endpoint is non-ISO endpoint!\n"); |
2105 | em28xx_devused&=~(1<<nr); | 2129 | em28xx_devused &= ~(1<<nr); |
2106 | return -ENODEV; | 2130 | return -ENODEV; |
2107 | } | 2131 | } |
2108 | if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) { | 2132 | if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) { |
2109 | em28xx_err(DRIVER_NAME " probing error: endpoint is ISO OUT endpoint!\n"); | 2133 | em28xx_err(DRIVER_NAME " probing error: endpoint is ISO OUT endpoint!\n"); |
2110 | em28xx_devused&=~(1<<nr); | 2134 | em28xx_devused &= ~(1<<nr); |
2111 | return -ENODEV; | 2135 | return -ENODEV; |
2112 | } | 2136 | } |
2113 | 2137 | ||
2114 | if (nr >= EM28XX_MAXBOARDS) { | 2138 | if (nr >= EM28XX_MAXBOARDS) { |
2115 | printk (DRIVER_NAME ": Supports only %i em28xx boards.\n",EM28XX_MAXBOARDS); | 2139 | printk(DRIVER_NAME ": Supports only %i em28xx boards.\n", |
2116 | em28xx_devused&=~(1<<nr); | 2140 | EM28XX_MAXBOARDS); |
2141 | em28xx_devused &= ~(1<<nr); | ||
2117 | return -ENOMEM; | 2142 | return -ENOMEM; |
2118 | } | 2143 | } |
2119 | 2144 | ||
@@ -2121,7 +2146,7 @@ static int em28xx_usb_probe(struct usb_interface *interface, | |||
2121 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); | 2146 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
2122 | if (dev == NULL) { | 2147 | if (dev == NULL) { |
2123 | em28xx_err(DRIVER_NAME ": out of memory!\n"); | 2148 | em28xx_err(DRIVER_NAME ": out of memory!\n"); |
2124 | em28xx_devused&=~(1<<nr); | 2149 | em28xx_devused &= ~(1<<nr); |
2125 | return -ENOMEM; | 2150 | return -ENOMEM; |
2126 | } | 2151 | } |
2127 | 2152 | ||
@@ -2145,14 +2170,14 @@ static int em28xx_usb_probe(struct usb_interface *interface, | |||
2145 | /* compute alternate max packet sizes */ | 2170 | /* compute alternate max packet sizes */ |
2146 | uif = udev->actconfig->interface[0]; | 2171 | uif = udev->actconfig->interface[0]; |
2147 | 2172 | ||
2148 | dev->num_alt=uif->num_altsetting; | 2173 | dev->num_alt = uif->num_altsetting; |
2149 | em28xx_info("Alternate settings: %i\n",dev->num_alt); | 2174 | em28xx_info("Alternate settings: %i\n", dev->num_alt); |
2150 | // dev->alt_max_pkt_size = kmalloc(sizeof(*dev->alt_max_pkt_size)* | 2175 | /* dev->alt_max_pkt_size = kmalloc(sizeof(*dev->alt_max_pkt_size)* */ |
2151 | dev->alt_max_pkt_size = kmalloc(32* | 2176 | dev->alt_max_pkt_size = kmalloc(32 * dev->num_alt, GFP_KERNEL); |
2152 | dev->num_alt,GFP_KERNEL); | 2177 | |
2153 | if (dev->alt_max_pkt_size == NULL) { | 2178 | if (dev->alt_max_pkt_size == NULL) { |
2154 | em28xx_errdev("out of memory!\n"); | 2179 | em28xx_errdev("out of memory!\n"); |
2155 | em28xx_devused&=~(1<<nr); | 2180 | em28xx_devused &= ~(1<<nr); |
2156 | kfree(dev); | 2181 | kfree(dev); |
2157 | return -ENOMEM; | 2182 | return -ENOMEM; |
2158 | } | 2183 | } |
@@ -2162,11 +2187,11 @@ static int em28xx_usb_probe(struct usb_interface *interface, | |||
2162 | wMaxPacketSize); | 2187 | wMaxPacketSize); |
2163 | dev->alt_max_pkt_size[i] = | 2188 | dev->alt_max_pkt_size[i] = |
2164 | (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); | 2189 | (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); |
2165 | em28xx_info("Alternate setting %i, max size= %i\n",i, | 2190 | em28xx_info("Alternate setting %i, max size= %i\n", i, |
2166 | dev->alt_max_pkt_size[i]); | 2191 | dev->alt_max_pkt_size[i]); |
2167 | } | 2192 | } |
2168 | 2193 | ||
2169 | if ((card[nr]>=0)&&(card[nr]<em28xx_bcount)) | 2194 | if ((card[nr] >= 0) && (card[nr] < em28xx_bcount)) |
2170 | dev->model = card[nr]; | 2195 | dev->model = card[nr]; |
2171 | 2196 | ||
2172 | /* allocate device struct */ | 2197 | /* allocate device struct */ |
@@ -2202,7 +2227,8 @@ static void em28xx_usb_disconnect(struct usb_interface *interface) | |||
2202 | 2227 | ||
2203 | em28xx_info("disconnecting %s\n", dev->vdev->name); | 2228 | em28xx_info("disconnecting %s\n", dev->vdev->name); |
2204 | 2229 | ||
2205 | /* wait until all current v4l2 io is finished then deallocate resources */ | 2230 | /* wait until all current v4l2 io is finished then deallocate |
2231 | resources */ | ||
2206 | mutex_lock(&dev->lock); | 2232 | mutex_lock(&dev->lock); |
2207 | 2233 | ||
2208 | wake_up_interruptible_all(&dev->open); | 2234 | wake_up_interruptible_all(&dev->open); |
diff --git a/drivers/media/video/em28xx/em28xx.h b/drivers/media/video/em28xx/em28xx.h index 04e0e48ecabe..002f170b211a 100644 --- a/drivers/media/video/em28xx/em28xx.h +++ b/drivers/media/video/em28xx/em28xx.h | |||
@@ -26,11 +26,39 @@ | |||
26 | #define _EM28XX_H | 26 | #define _EM28XX_H |
27 | 27 | ||
28 | #include <linux/videodev2.h> | 28 | #include <linux/videodev2.h> |
29 | #include <media/videobuf-vmalloc.h> | ||
30 | |||
29 | #include <linux/i2c.h> | 31 | #include <linux/i2c.h> |
30 | #include <linux/mutex.h> | 32 | #include <linux/mutex.h> |
31 | #include <media/ir-kbd-i2c.h> | 33 | #include <media/ir-kbd-i2c.h> |
32 | 34 | #if defined(CONFIG_VIDEO_EM28XX_DVB) || defined(CONFIG_VIDEO_EM28XX_DVB_MODULE) | |
33 | #define UNSET -1 | 35 | #include <media/videobuf-dvb.h> |
36 | #endif | ||
37 | #include "tuner-xc2028.h" | ||
38 | #include "em28xx-reg.h" | ||
39 | |||
40 | /* Boards supported by driver */ | ||
41 | #define EM2800_BOARD_UNKNOWN 0 | ||
42 | #define EM2820_BOARD_UNKNOWN 1 | ||
43 | #define EM2820_BOARD_TERRATEC_CINERGY_250 2 | ||
44 | #define EM2820_BOARD_PINNACLE_USB_2 3 | ||
45 | #define EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 4 | ||
46 | #define EM2820_BOARD_MSI_VOX_USB_2 5 | ||
47 | #define EM2800_BOARD_TERRATEC_CINERGY_200 6 | ||
48 | #define EM2800_BOARD_LEADTEK_WINFAST_USBII 7 | ||
49 | #define EM2800_BOARD_KWORLD_USB2800 8 | ||
50 | #define EM2820_BOARD_PINNACLE_DVC_90 9 | ||
51 | #define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900 10 | ||
52 | #define EM2880_BOARD_TERRATEC_HYBRID_XS 11 | ||
53 | #define EM2820_BOARD_KWORLD_PVRTV2800RF 12 | ||
54 | #define EM2880_BOARD_TERRATEC_PRODIGY_XS 13 | ||
55 | #define EM2820_BOARD_PROLINK_PLAYTV_USB2 14 | ||
56 | #define EM2800_BOARD_VGEAR_POCKETTV 15 | ||
57 | #define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950 16 | ||
58 | |||
59 | /* Limits minimum and default number of buffers */ | ||
60 | #define EM28XX_MIN_BUF 4 | ||
61 | #define EM28XX_DEF_BUF 8 | ||
34 | 62 | ||
35 | /* maximum number of em28xx boards */ | 63 | /* maximum number of em28xx boards */ |
36 | #define EM28XX_MAXBOARDS 4 /*FIXME: should be bigger */ | 64 | #define EM28XX_MAXBOARDS 4 /*FIXME: should be bigger */ |
@@ -81,31 +109,78 @@ | |||
81 | /* time in msecs to wait for i2c writes to finish */ | 109 | /* time in msecs to wait for i2c writes to finish */ |
82 | #define EM2800_I2C_WRITE_TIMEOUT 20 | 110 | #define EM2800_I2C_WRITE_TIMEOUT 20 |
83 | 111 | ||
84 | /* the various frame states */ | 112 | enum em28xx_mode { |
85 | enum em28xx_frame_state { | 113 | EM28XX_MODE_UNDEFINED, |
86 | F_UNUSED = 0, | 114 | EM28XX_ANALOG_MODE, |
87 | F_QUEUED, | 115 | EM28XX_DIGITAL_MODE, |
88 | F_GRABBING, | ||
89 | F_DONE, | ||
90 | F_ERROR, | ||
91 | }; | 116 | }; |
92 | 117 | ||
93 | /* stream states */ | ||
94 | enum em28xx_stream_state { | 118 | enum em28xx_stream_state { |
95 | STREAM_OFF, | 119 | STREAM_OFF, |
96 | STREAM_INTERRUPT, | 120 | STREAM_INTERRUPT, |
97 | STREAM_ON, | 121 | STREAM_ON, |
98 | }; | 122 | }; |
99 | 123 | ||
100 | /* frames */ | 124 | struct em28xx; |
101 | struct em28xx_frame_t { | 125 | |
102 | void *bufmem; | 126 | struct em28xx_usb_isoc_ctl { |
103 | struct v4l2_buffer buf; | 127 | /* max packet size of isoc transaction */ |
104 | enum em28xx_frame_state state; | 128 | int max_pkt_size; |
129 | |||
130 | /* number of allocated urbs */ | ||
131 | int num_bufs; | ||
132 | |||
133 | /* urb for isoc transfers */ | ||
134 | struct urb **urb; | ||
135 | |||
136 | /* transfer buffers for isoc transfer */ | ||
137 | char **transfer_buffer; | ||
138 | |||
139 | /* Last buffer command and region */ | ||
140 | u8 cmd; | ||
141 | int pos, size, pktsize; | ||
142 | |||
143 | /* Last field: ODD or EVEN? */ | ||
144 | int field; | ||
145 | |||
146 | /* Stores incomplete commands */ | ||
147 | u32 tmp_buf; | ||
148 | int tmp_buf_len; | ||
149 | |||
150 | /* Stores already requested buffers */ | ||
151 | struct em28xx_buffer *buf; | ||
152 | |||
153 | /* Stores the number of received fields */ | ||
154 | int nfields; | ||
155 | |||
156 | /* isoc urb callback */ | ||
157 | int (*isoc_copy) (struct em28xx *dev, struct urb *urb); | ||
158 | |||
159 | }; | ||
160 | |||
161 | struct em28xx_fmt { | ||
162 | char *name; | ||
163 | u32 fourcc; /* v4l2 format id */ | ||
164 | }; | ||
165 | |||
166 | /* buffer for one video frame */ | ||
167 | struct em28xx_buffer { | ||
168 | /* common v4l buffer stuff -- must be first */ | ||
169 | struct videobuf_buffer vb; | ||
170 | |||
105 | struct list_head frame; | 171 | struct list_head frame; |
106 | unsigned long vma_use_count; | ||
107 | int top_field; | 172 | int top_field; |
108 | int fieldbytesused; | 173 | int receiving; |
174 | }; | ||
175 | |||
176 | struct em28xx_dmaqueue { | ||
177 | struct list_head active; | ||
178 | struct list_head queued; | ||
179 | |||
180 | wait_queue_head_t wq; | ||
181 | |||
182 | /* Counters to control buffer fill */ | ||
183 | int pos; | ||
109 | }; | 184 | }; |
110 | 185 | ||
111 | /* io methods */ | 186 | /* io methods */ |
@@ -152,6 +227,12 @@ enum em28xx_decoder { | |||
152 | EM28XX_SAA7114 | 227 | EM28XX_SAA7114 |
153 | }; | 228 | }; |
154 | 229 | ||
230 | struct em28xx_reg_seq { | ||
231 | int reg; | ||
232 | unsigned char val, mask; | ||
233 | int sleep; | ||
234 | }; | ||
235 | |||
155 | struct em28xx_board { | 236 | struct em28xx_board { |
156 | char *name; | 237 | char *name; |
157 | int vchannels; | 238 | int vchannels; |
@@ -165,8 +246,7 @@ struct em28xx_board { | |||
165 | unsigned int mts_firmware:1; | 246 | unsigned int mts_firmware:1; |
166 | unsigned int has_12mhz_i2s:1; | 247 | unsigned int has_12mhz_i2s:1; |
167 | unsigned int max_range_640_480:1; | 248 | unsigned int max_range_640_480:1; |
168 | 249 | unsigned int has_dvb:1; | |
169 | unsigned int analog_gpio; | ||
170 | 250 | ||
171 | enum em28xx_decoder decoder; | 251 | enum em28xx_decoder decoder; |
172 | 252 | ||
@@ -199,7 +279,10 @@ enum em28xx_dev_state { | |||
199 | #define EM28XX_NUM_AUDIO_PACKETS 64 | 279 | #define EM28XX_NUM_AUDIO_PACKETS 64 |
200 | #define EM28XX_AUDIO_MAX_PACKET_SIZE 196 /* static value */ | 280 | #define EM28XX_AUDIO_MAX_PACKET_SIZE 196 /* static value */ |
201 | #define EM28XX_CAPTURE_STREAM_EN 1 | 281 | #define EM28XX_CAPTURE_STREAM_EN 1 |
282 | |||
283 | /* em28xx extensions */ | ||
202 | #define EM28XX_AUDIO 0x10 | 284 | #define EM28XX_AUDIO 0x10 |
285 | #define EM28XX_DVB 0x20 | ||
203 | 286 | ||
204 | struct em28xx_audio { | 287 | struct em28xx_audio { |
205 | char name[50]; | 288 | char name[50]; |
@@ -217,13 +300,24 @@ struct em28xx_audio { | |||
217 | spinlock_t slock; | 300 | spinlock_t slock; |
218 | }; | 301 | }; |
219 | 302 | ||
303 | struct em28xx; | ||
304 | |||
305 | struct em28xx_fh { | ||
306 | struct em28xx *dev; | ||
307 | unsigned int stream_on:1; /* Locks streams */ | ||
308 | int radio; | ||
309 | |||
310 | struct videobuf_queue vb_vidq; | ||
311 | |||
312 | enum v4l2_buf_type type; | ||
313 | }; | ||
314 | |||
220 | /* main device struct */ | 315 | /* main device struct */ |
221 | struct em28xx { | 316 | struct em28xx { |
222 | /* generic device properties */ | 317 | /* generic device properties */ |
223 | char name[30]; /* name (including minor) of the device */ | 318 | char name[30]; /* name (including minor) of the device */ |
224 | int model; /* index in the device_data struct */ | 319 | int model; /* index in the device_data struct */ |
225 | int devno; /* marks the number of this device */ | 320 | int devno; /* marks the number of this device */ |
226 | unsigned int analog_gpio; | ||
227 | unsigned int is_em2800:1; | 321 | unsigned int is_em2800:1; |
228 | unsigned int has_msp34xx:1; | 322 | unsigned int has_msp34xx:1; |
229 | unsigned int has_tda9887:1; | 323 | unsigned int has_tda9887:1; |
@@ -231,6 +325,16 @@ struct em28xx { | |||
231 | unsigned int has_audio_class:1; | 325 | unsigned int has_audio_class:1; |
232 | unsigned int has_12mhz_i2s:1; | 326 | unsigned int has_12mhz_i2s:1; |
233 | unsigned int max_range_640_480:1; | 327 | unsigned int max_range_640_480:1; |
328 | unsigned int has_dvb:1; | ||
329 | |||
330 | /* Some older em28xx chips needs a waiting time after writing */ | ||
331 | unsigned int wait_after_write; | ||
332 | |||
333 | /* GPIO sequences for analog and digital mode */ | ||
334 | struct em28xx_reg_seq *analog_gpio, *digital_gpio; | ||
335 | |||
336 | /* GPIO sequences for tuner callbacks */ | ||
337 | struct em28xx_reg_seq *tun_analog_gpio, *tun_digital_gpio; | ||
234 | 338 | ||
235 | int video_inputs; /* number of video inputs */ | 339 | int video_inputs; /* number of video inputs */ |
236 | struct list_head devlist; | 340 | struct list_head devlist; |
@@ -255,36 +359,28 @@ struct em28xx { | |||
255 | int mute; | 359 | int mute; |
256 | int volume; | 360 | int volume; |
257 | /* frame properties */ | 361 | /* frame properties */ |
258 | struct em28xx_frame_t frame[EM28XX_NUM_FRAMES]; /* list of frames */ | ||
259 | int num_frames; /* number of frames currently in use */ | ||
260 | unsigned int frame_count; /* total number of transfered frames */ | ||
261 | struct em28xx_frame_t *frame_current; /* the frame that is being filled */ | ||
262 | int width; /* current frame width */ | 362 | int width; /* current frame width */ |
263 | int height; /* current frame height */ | 363 | int height; /* current frame height */ |
264 | int frame_size; /* current frame size */ | ||
265 | int field_size; /* current field size */ | ||
266 | int bytesperline; | ||
267 | int hscale; /* horizontal scale factor (see datasheet) */ | 364 | int hscale; /* horizontal scale factor (see datasheet) */ |
268 | int vscale; /* vertical scale factor (see datasheet) */ | 365 | int vscale; /* vertical scale factor (see datasheet) */ |
269 | int interlaced; /* 1=interlace fileds, 0=just top fileds */ | 366 | int interlaced; /* 1=interlace fileds, 0=just top fileds */ |
270 | int type; | ||
271 | unsigned int video_bytesread; /* Number of bytes read */ | 367 | unsigned int video_bytesread; /* Number of bytes read */ |
272 | 368 | ||
273 | unsigned long hash; /* eeprom hash - for boards with generic ID */ | 369 | unsigned long hash; /* eeprom hash - for boards with generic ID */ |
274 | unsigned long i2c_hash; /* i2c devicelist hash - for boards with generic ID */ | 370 | unsigned long i2c_hash; /* i2c devicelist hash - |
371 | for boards with generic ID */ | ||
275 | 372 | ||
276 | struct em28xx_audio *adev; | 373 | struct em28xx_audio *adev; |
277 | 374 | ||
278 | /* states */ | 375 | /* states */ |
279 | enum em28xx_dev_state state; | 376 | enum em28xx_dev_state state; |
280 | enum em28xx_stream_state stream; | ||
281 | enum em28xx_io_method io; | 377 | enum em28xx_io_method io; |
282 | 378 | ||
283 | struct work_struct request_module_wk; | 379 | struct work_struct request_module_wk; |
284 | 380 | ||
285 | /* locks */ | 381 | /* locks */ |
286 | struct mutex lock; | 382 | struct mutex lock; |
287 | spinlock_t queue_lock; | 383 | /* spinlock_t queue_lock; */ |
288 | struct list_head inqueue, outqueue; | 384 | struct list_head inqueue, outqueue; |
289 | wait_queue_head_t open, wait_frame, wait_stream; | 385 | wait_queue_head_t open, wait_frame, wait_stream; |
290 | struct video_device *vbi_dev; | 386 | struct video_device *vbi_dev; |
@@ -292,6 +388,11 @@ struct em28xx { | |||
292 | 388 | ||
293 | unsigned char eedata[256]; | 389 | unsigned char eedata[256]; |
294 | 390 | ||
391 | /* Isoc control struct */ | ||
392 | struct em28xx_dmaqueue vidq; | ||
393 | struct em28xx_usb_isoc_ctl isoc_ctl; | ||
394 | spinlock_t slock; | ||
395 | |||
295 | /* usb transfer */ | 396 | /* usb transfer */ |
296 | struct usb_device *udev; /* the usb device */ | 397 | struct usb_device *udev; /* the usb device */ |
297 | int alt; /* alternate */ | 398 | int alt; /* alternate */ |
@@ -301,20 +402,21 @@ struct em28xx { | |||
301 | struct urb *urb[EM28XX_NUM_BUFS]; /* urb for isoc transfers */ | 402 | struct urb *urb[EM28XX_NUM_BUFS]; /* urb for isoc transfers */ |
302 | char *transfer_buffer[EM28XX_NUM_BUFS]; /* transfer buffers for isoc transfer */ | 403 | char *transfer_buffer[EM28XX_NUM_BUFS]; /* transfer buffers for isoc transfer */ |
303 | /* helper funcs that call usb_control_msg */ | 404 | /* helper funcs that call usb_control_msg */ |
304 | int (*em28xx_write_regs) (struct em28xx * dev, u16 reg, char *buf, | 405 | int (*em28xx_write_regs) (struct em28xx *dev, u16 reg, |
305 | int len); | ||
306 | int (*em28xx_read_reg) (struct em28xx * dev, u16 reg); | ||
307 | int (*em28xx_read_reg_req_len) (struct em28xx * dev, u8 req, u16 reg, | ||
308 | char *buf, int len); | 406 | char *buf, int len); |
309 | int (*em28xx_write_regs_req) (struct em28xx * dev, u8 req, u16 reg, | 407 | int (*em28xx_read_reg) (struct em28xx *dev, u16 reg); |
408 | int (*em28xx_read_reg_req_len) (struct em28xx *dev, u8 req, u16 reg, | ||
409 | char *buf, int len); | ||
410 | int (*em28xx_write_regs_req) (struct em28xx *dev, u8 req, u16 reg, | ||
310 | char *buf, int len); | 411 | char *buf, int len); |
311 | int (*em28xx_read_reg_req) (struct em28xx * dev, u8 req, u16 reg); | 412 | int (*em28xx_read_reg_req) (struct em28xx *dev, u8 req, u16 reg); |
312 | }; | ||
313 | 413 | ||
314 | struct em28xx_fh { | 414 | enum em28xx_mode mode; |
315 | struct em28xx *dev; | 415 | |
316 | unsigned int stream_on:1; /* Locks streams */ | 416 | /* Caches GPO and GPIO registers */ |
317 | int radio; | 417 | unsigned char reg_gpo, reg_gpio; |
418 | |||
419 | struct em28xx_dvb *dvb; | ||
318 | }; | 420 | }; |
319 | 421 | ||
320 | struct em28xx_ops { | 422 | struct em28xx_ops { |
@@ -351,22 +453,27 @@ int em28xx_colorlevels_set_default(struct em28xx *dev); | |||
351 | int em28xx_capture_start(struct em28xx *dev, int start); | 453 | int em28xx_capture_start(struct em28xx *dev, int start); |
352 | int em28xx_outfmt_set_yuv422(struct em28xx *dev); | 454 | int em28xx_outfmt_set_yuv422(struct em28xx *dev); |
353 | int em28xx_resolution_set(struct em28xx *dev); | 455 | int em28xx_resolution_set(struct em28xx *dev); |
354 | int em28xx_init_isoc(struct em28xx *dev); | ||
355 | void em28xx_uninit_isoc(struct em28xx *dev); | ||
356 | int em28xx_set_alternate(struct em28xx *dev); | 456 | int em28xx_set_alternate(struct em28xx *dev); |
457 | int em28xx_init_isoc(struct em28xx *dev, int max_packets, | ||
458 | int num_bufs, int max_pkt_size, | ||
459 | int (*isoc_copy) (struct em28xx *dev, struct urb *urb)); | ||
460 | void em28xx_uninit_isoc(struct em28xx *dev); | ||
461 | int em28xx_set_mode(struct em28xx *dev, enum em28xx_mode set_mode); | ||
462 | int em28xx_gpio_set(struct em28xx *dev, struct em28xx_reg_seq *gpio); | ||
357 | 463 | ||
358 | /* Provided by em28xx-video.c */ | 464 | /* Provided by em28xx-video.c */ |
359 | int em28xx_register_extension(struct em28xx_ops *dev); | 465 | int em28xx_register_extension(struct em28xx_ops *dev); |
360 | void em28xx_unregister_extension(struct em28xx_ops *dev); | 466 | void em28xx_unregister_extension(struct em28xx_ops *dev); |
361 | 467 | ||
362 | /* Provided by em28xx-cards.c */ | 468 | /* Provided by em28xx-cards.c */ |
363 | extern int em2800_variant_detect(struct usb_device* udev,int model); | 469 | extern int em2800_variant_detect(struct usb_device *udev, int model); |
364 | extern void em28xx_pre_card_setup(struct em28xx *dev); | 470 | extern void em28xx_pre_card_setup(struct em28xx *dev); |
365 | extern void em28xx_card_setup(struct em28xx *dev); | 471 | extern void em28xx_card_setup(struct em28xx *dev); |
366 | extern struct em28xx_board em28xx_boards[]; | 472 | extern struct em28xx_board em28xx_boards[]; |
367 | extern struct usb_device_id em28xx_id_table[]; | 473 | extern struct usb_device_id em28xx_id_table[]; |
368 | extern const unsigned int em28xx_bcount; | 474 | extern const unsigned int em28xx_bcount; |
369 | void em28xx_set_ir(struct em28xx *dev, struct IR_i2c *ir); | 475 | void em28xx_set_ir(struct em28xx *dev, struct IR_i2c *ir); |
476 | int em28xx_tuner_callback(void *ptr, int command, int arg); | ||
370 | 477 | ||
371 | /* Provided by em28xx-input.c */ | 478 | /* Provided by em28xx-input.c */ |
372 | /* TODO: Check if the standard get_key handlers on ir-common can be used */ | 479 | /* TODO: Check if the standard get_key handlers on ir-common can be used */ |
@@ -375,71 +482,6 @@ int em28xx_get_key_em_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw); | |||
375 | int em28xx_get_key_pinnacle_usb_grey(struct IR_i2c *ir, u32 *ir_key, | 482 | int em28xx_get_key_pinnacle_usb_grey(struct IR_i2c *ir, u32 *ir_key, |
376 | u32 *ir_raw); | 483 | u32 *ir_raw); |
377 | 484 | ||
378 | /* em2800 registers */ | ||
379 | #define EM2800_AUDIOSRC_REG 0x08 | ||
380 | |||
381 | /* em28xx registers */ | ||
382 | #define I2C_CLK_REG 0x06 | ||
383 | #define CHIPID_REG 0x0a | ||
384 | #define USBSUSP_REG 0x0c /* */ | ||
385 | |||
386 | #define AUDIOSRC_REG 0x0e | ||
387 | #define XCLK_REG 0x0f | ||
388 | |||
389 | #define VINMODE_REG 0x10 | ||
390 | #define VINCTRL_REG 0x11 | ||
391 | #define VINENABLE_REG 0x12 /* */ | ||
392 | |||
393 | #define GAMMA_REG 0x14 | ||
394 | #define RGAIN_REG 0x15 | ||
395 | #define GGAIN_REG 0x16 | ||
396 | #define BGAIN_REG 0x17 | ||
397 | #define ROFFSET_REG 0x18 | ||
398 | #define GOFFSET_REG 0x19 | ||
399 | #define BOFFSET_REG 0x1a | ||
400 | |||
401 | #define OFLOW_REG 0x1b | ||
402 | #define HSTART_REG 0x1c | ||
403 | #define VSTART_REG 0x1d | ||
404 | #define CWIDTH_REG 0x1e | ||
405 | #define CHEIGHT_REG 0x1f | ||
406 | |||
407 | #define YGAIN_REG 0x20 | ||
408 | #define YOFFSET_REG 0x21 | ||
409 | #define UVGAIN_REG 0x22 | ||
410 | #define UOFFSET_REG 0x23 | ||
411 | #define VOFFSET_REG 0x24 | ||
412 | #define SHARPNESS_REG 0x25 | ||
413 | |||
414 | #define COMPR_REG 0x26 | ||
415 | #define OUTFMT_REG 0x27 | ||
416 | |||
417 | #define XMIN_REG 0x28 | ||
418 | #define XMAX_REG 0x29 | ||
419 | #define YMIN_REG 0x2a | ||
420 | #define YMAX_REG 0x2b | ||
421 | |||
422 | #define HSCALELOW_REG 0x30 | ||
423 | #define HSCALEHIGH_REG 0x31 | ||
424 | #define VSCALELOW_REG 0x32 | ||
425 | #define VSCALEHIGH_REG 0x33 | ||
426 | |||
427 | #define AC97LSB_REG 0x40 | ||
428 | #define AC97MSB_REG 0x41 | ||
429 | #define AC97ADDR_REG 0x42 | ||
430 | #define AC97BUSY_REG 0x43 | ||
431 | |||
432 | /* em202 registers */ | ||
433 | #define MASTER_AC97 0x02 | ||
434 | #define LINE_IN_AC97 0x10 | ||
435 | #define VIDEO_AC97 0x14 | ||
436 | |||
437 | /* register settings */ | ||
438 | #define EM2800_AUDIO_SRC_TUNER 0x0d | ||
439 | #define EM2800_AUDIO_SRC_LINE 0x0c | ||
440 | #define EM28XX_AUDIO_SRC_TUNER 0xc0 | ||
441 | #define EM28XX_AUDIO_SRC_LINE 0x80 | ||
442 | |||
443 | /* printk macros */ | 485 | /* printk macros */ |
444 | 486 | ||
445 | #define em28xx_err(fmt, arg...) do {\ | 487 | #define em28xx_err(fmt, arg...) do {\ |
@@ -456,80 +498,80 @@ int em28xx_get_key_pinnacle_usb_grey(struct IR_i2c *ir, u32 *ir_key, | |||
456 | printk(KERN_WARNING "%s: "fmt,\ | 498 | printk(KERN_WARNING "%s: "fmt,\ |
457 | dev->name , ##arg); } while (0) | 499 | dev->name , ##arg); } while (0) |
458 | 500 | ||
459 | inline static int em28xx_compression_disable(struct em28xx *dev) | 501 | static inline int em28xx_compression_disable(struct em28xx *dev) |
460 | { | 502 | { |
461 | /* side effect of disabling scaler and mixer */ | 503 | /* side effect of disabling scaler and mixer */ |
462 | return em28xx_write_regs(dev, COMPR_REG, "\x00", 1); | 504 | return em28xx_write_regs(dev, EM28XX_R26_COMPR, "\x00", 1); |
463 | } | 505 | } |
464 | 506 | ||
465 | inline static int em28xx_contrast_get(struct em28xx *dev) | 507 | static inline int em28xx_contrast_get(struct em28xx *dev) |
466 | { | 508 | { |
467 | return em28xx_read_reg(dev, YGAIN_REG) & 0x1f; | 509 | return em28xx_read_reg(dev, EM28XX_R20_YGAIN) & 0x1f; |
468 | } | 510 | } |
469 | 511 | ||
470 | inline static int em28xx_brightness_get(struct em28xx *dev) | 512 | static inline int em28xx_brightness_get(struct em28xx *dev) |
471 | { | 513 | { |
472 | return em28xx_read_reg(dev, YOFFSET_REG); | 514 | return em28xx_read_reg(dev, EM28XX_R21_YOFFSET); |
473 | } | 515 | } |
474 | 516 | ||
475 | inline static int em28xx_saturation_get(struct em28xx *dev) | 517 | static inline int em28xx_saturation_get(struct em28xx *dev) |
476 | { | 518 | { |
477 | return em28xx_read_reg(dev, UVGAIN_REG) & 0x1f; | 519 | return em28xx_read_reg(dev, EM28XX_R22_UVGAIN) & 0x1f; |
478 | } | 520 | } |
479 | 521 | ||
480 | inline static int em28xx_u_balance_get(struct em28xx *dev) | 522 | static inline int em28xx_u_balance_get(struct em28xx *dev) |
481 | { | 523 | { |
482 | return em28xx_read_reg(dev, UOFFSET_REG); | 524 | return em28xx_read_reg(dev, EM28XX_R23_UOFFSET); |
483 | } | 525 | } |
484 | 526 | ||
485 | inline static int em28xx_v_balance_get(struct em28xx *dev) | 527 | static inline int em28xx_v_balance_get(struct em28xx *dev) |
486 | { | 528 | { |
487 | return em28xx_read_reg(dev, VOFFSET_REG); | 529 | return em28xx_read_reg(dev, EM28XX_R24_VOFFSET); |
488 | } | 530 | } |
489 | 531 | ||
490 | inline static int em28xx_gamma_get(struct em28xx *dev) | 532 | static inline int em28xx_gamma_get(struct em28xx *dev) |
491 | { | 533 | { |
492 | return em28xx_read_reg(dev, GAMMA_REG) & 0x3f; | 534 | return em28xx_read_reg(dev, EM28XX_R14_GAMMA) & 0x3f; |
493 | } | 535 | } |
494 | 536 | ||
495 | inline static int em28xx_contrast_set(struct em28xx *dev, s32 val) | 537 | static inline int em28xx_contrast_set(struct em28xx *dev, s32 val) |
496 | { | 538 | { |
497 | u8 tmp = (u8) val; | 539 | u8 tmp = (u8) val; |
498 | return em28xx_write_regs(dev, YGAIN_REG, &tmp, 1); | 540 | return em28xx_write_regs(dev, EM28XX_R20_YGAIN, &tmp, 1); |
499 | } | 541 | } |
500 | 542 | ||
501 | inline static int em28xx_brightness_set(struct em28xx *dev, s32 val) | 543 | static inline int em28xx_brightness_set(struct em28xx *dev, s32 val) |
502 | { | 544 | { |
503 | u8 tmp = (u8) val; | 545 | u8 tmp = (u8) val; |
504 | return em28xx_write_regs(dev, YOFFSET_REG, &tmp, 1); | 546 | return em28xx_write_regs(dev, EM28XX_R21_YOFFSET, &tmp, 1); |
505 | } | 547 | } |
506 | 548 | ||
507 | inline static int em28xx_saturation_set(struct em28xx *dev, s32 val) | 549 | static inline int em28xx_saturation_set(struct em28xx *dev, s32 val) |
508 | { | 550 | { |
509 | u8 tmp = (u8) val; | 551 | u8 tmp = (u8) val; |
510 | return em28xx_write_regs(dev, UVGAIN_REG, &tmp, 1); | 552 | return em28xx_write_regs(dev, EM28XX_R22_UVGAIN, &tmp, 1); |
511 | } | 553 | } |
512 | 554 | ||
513 | inline static int em28xx_u_balance_set(struct em28xx *dev, s32 val) | 555 | static inline int em28xx_u_balance_set(struct em28xx *dev, s32 val) |
514 | { | 556 | { |
515 | u8 tmp = (u8) val; | 557 | u8 tmp = (u8) val; |
516 | return em28xx_write_regs(dev, UOFFSET_REG, &tmp, 1); | 558 | return em28xx_write_regs(dev, EM28XX_R23_UOFFSET, &tmp, 1); |
517 | } | 559 | } |
518 | 560 | ||
519 | inline static int em28xx_v_balance_set(struct em28xx *dev, s32 val) | 561 | static inline int em28xx_v_balance_set(struct em28xx *dev, s32 val) |
520 | { | 562 | { |
521 | u8 tmp = (u8) val; | 563 | u8 tmp = (u8) val; |
522 | return em28xx_write_regs(dev, VOFFSET_REG, &tmp, 1); | 564 | return em28xx_write_regs(dev, EM28XX_R24_VOFFSET, &tmp, 1); |
523 | } | 565 | } |
524 | 566 | ||
525 | inline static int em28xx_gamma_set(struct em28xx *dev, s32 val) | 567 | static inline int em28xx_gamma_set(struct em28xx *dev, s32 val) |
526 | { | 568 | { |
527 | u8 tmp = (u8) val; | 569 | u8 tmp = (u8) val; |
528 | return em28xx_write_regs(dev, GAMMA_REG, &tmp, 1); | 570 | return em28xx_write_regs(dev, EM28XX_R14_GAMMA, &tmp, 1); |
529 | } | 571 | } |
530 | 572 | ||
531 | /*FIXME: maxw should be dependent of alt mode */ | 573 | /*FIXME: maxw should be dependent of alt mode */ |
532 | inline static unsigned int norm_maxw(struct em28xx *dev) | 574 | static inline unsigned int norm_maxw(struct em28xx *dev) |
533 | { | 575 | { |
534 | if (dev->max_range_640_480) | 576 | if (dev->max_range_640_480) |
535 | return 640; | 577 | return 640; |
@@ -537,7 +579,7 @@ inline static unsigned int norm_maxw(struct em28xx *dev) | |||
537 | return 720; | 579 | return 720; |
538 | } | 580 | } |
539 | 581 | ||
540 | inline static unsigned int norm_maxh(struct em28xx *dev) | 582 | static inline unsigned int norm_maxh(struct em28xx *dev) |
541 | { | 583 | { |
542 | if (dev->max_range_640_480) | 584 | if (dev->max_range_640_480) |
543 | return 480; | 585 | return 480; |