Add StarTech SVID2USB232 support
Subsystems (2)
RFC PATCH 1/1 Add StarTech SVID2USB232 support
This is a work-in-progress implementation of StarTech SVID2USB232, which uses a single EM28281 chip to capture and decode analog signal.
NOTE: this driver is NOT production ready!
Unlike other em28xx chips, EM28281 integrates its own TVP5150-like decoder. The TVP5150 communication happens at register 0x7Axx instead of I2C. The existing TVP5150 driver issues some commands that are incompatible with this chip. These are either skipped or overridden with data that the chip expects.
What works:
- Video capture with PAL via composite
- Audio capture
- Brightness, saturation, color balance, sharpness settings
- Limited or Full colour range setting
What does not work:
- Switch input to S-VIDEO
- Switch to NTSC, PAL-60 or SECAM
- HUE setting
What is untested:
- NTSC and SECAM (not sure if EM28281 supports signal auto-detection)
- S-VIDEO (I ordered a cable for testing)
The patch has a lot of compromises, with some room for better code. Unfortunately I lack understanding how to make it better, so please provide feedback.
Raw StarTech SVID2USB232 capture from a sane driver:
reg:0x7a00 val:0x32
reg:0x7a01 val:0x04
reg:0x7a02 val:0x4f
reg:0x7a03 val:0x09
reg:0x7a04 val:0xdc
reg:0x7a07 val:0x2f
reg:0x7a08 val:0x7a
reg:0x7a09 val:0x20
reg:0x7a0a val:0x8c
reg:0x7a0b val:0x00
reg:0x7a0c val:0x67
reg:0x7a0f val:0x1c
reg:0x7a17 val:0xc3
reg:0x7a18 val:0x28
reg:0x7a19 val:0x32
reg:0x7a1a val:0xb9
reg:0x7a1b val:0x86
reg:0x7a1c val:0x1e
reg:0x7a1d val:0x99
reg:0x7a1e val:0x99
reg:0x7a1f val:0x9a
reg:0x7a20 val:0x3d
reg:0x7a21 val:0x3e
reg:0x7a28 val:0x5e
reg:0x7a29 val:0x00
reg:0x7a2e val:0x88
reg:0x7a2f val:0x52
reg:0x7a30 val:0x2a
reg:0x7a31 val:0xc3
reg:0x7a3f val:0x00
reg:0x7a40 val:0x05
reg:0x7a51 val:0x00
reg:0x7a53 val:0xcc
reg:0x7a5d val:0x16
reg:0x7a5e val:0x50
reg:0x7a60 val:0xb4
reg:0x7a67 val:0x64
reg:0x7a80 val:0x03
reg:0x7a82 val:0x52
reg:0x7ac1 val:0x1b
reg:0x7ac8 val:0x00
---
This is my very first kernel patch. There are many unknowns I might not be aware of, so please provide feedback.
My objective is to add EM28281 driver support not only for my personal use, but for whoever wants to make use of this video capture device on Linux. I tried adjusting the code trying to strike a balance between having a functional device and "clean" code. I am very sure there is a much better way to submit a cleaner patch than this, hence why I am submitting the patch in this state.
My initial approach was a dummy i2c_bus->algo_type, while I was setting up all the 0x7AXX registers at em28xx_pre_card_setup. Then I started to slowly defer registry writes from the TVP5150 driver in drivers/media/i2c/tvp5150.c.
I left in the commit message a dump of the raw registry writes to keep history of how a sane driver is expected to send data.
drivers/media/usb/em28xx/em28xx-cards.c | 35 ++++++ drivers/media/usb/em28xx/em28xx-core.c | 7 ++ drivers/media/usb/em28xx/em28xx-i2c.c | 145 +++++++++++++++++++++++- drivers/media/usb/em28xx/em28xx-reg.h | 1 + drivers/media/usb/em28xx/em28xx.h | 5 + 5 files changed, 192 insertions(+), 1 deletion(-)
drivers/media/usb/em28xx/em28xx-cards.c +35 -0
@@ -1154,6 +1154,21 @@ const struct em28xx_board em28xx_boards[] = { .amux = EM28XX_AMUX_LINE_IN, } }, }, + [EM28281_BOARD_STARTECH_SVID2USB232] = { + .name = "StarTech SVID2USB232", + .tuner_type = TUNER_ABSENT, + .decoder = EM28XX_TVP5150, + .xclk = EM28XX_XCLK_FREQUENCY_12MHZ, + .input = { { + .type = EM28XX_VMUX_COMPOSITE, + .vmux = TVP5150_COMPOSITE0, + .amux = EM28XX_AMUX_LINE_IN, + }, { + .type = EM28XX_VMUX_SVIDEO, + .vmux = TVP5150_SVIDEO, + .amux = EM28XX_AMUX_LINE_IN, + } }, + }, [EM2861_BOARD_PLEXTOR_PX_TV100U] = { .name = "Plextor ConvertX PX-TV100U", .tuner_type = TUNER_TNF_5335MF,
@@ -2849,6 +2864,8 @@ struct usb_device_id em28xx_id_table[] = { .driver_info = EM28178_BOARD_PLEX_PX_BCUD }, { USB_DEVICE(0xeb1a, 0x5051), /* Ion Video 2 PC MKII / Startech svid2usb23 / Raygo R12-41373 */ .driver_info = EM2860_BOARD_TVP5150_REFERENCE_DESIGN }, + { USB_DEVICE(0xeb1a, 0x8286), /* StarTech SVID2USB232 */ + .driver_info = EM28281_BOARD_STARTECH_SVID2USB232 }, { USB_DEVICE(0x1b80, 0xe349), /* Magix USB Videowandler-2 */ .driver_info = EM2861_BOARD_MAGIX_VIDEOWANDLER2 }, { },
@@ -3093,6 +3110,14 @@ static void em28xx_pre_card_setup(struct em28xx *dev)*/ em28xx_wait_until_ac97_features_equals (dev,0x6a90 );break ; + +case EM28281_BOARD_STARTECH_SVID2USB232 : +em28xx_write_reg (dev,EM2874_R80_GPIO_P0_CTRL ,0xff ); +em28xx_write_reg (dev,0x0D ,0xff ); +msleep (70 ); +em28xx_write_reg (dev,0x7A31 ,0xc3 ); +em28xx_write_reg (dev,0x7A3F ,0x00 ); +break ; }em28xx_gpio_set (dev, dev->board.tuner_gpio);
@@ -3651,6 +3676,11 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev, dev->wait_after_write =0 ; dev->eeprom_addrwidth_16bit =1 ;break ; +case CHIP_ID_EM28281 : + chip_name ="em28281" ; + dev->wait_after_write =0 ; + dev->eeprom_addrwidth_16bit =1 ; +break ;case CHIP_ID_EM2883 : chip_name ="em2882/3" ; dev->wait_after_write =0 ;
@@ -3688,6 +3718,8 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev,/* register i2c bus 0 */ if (dev->board.is_em2800) retval =em28xx_i2c_register (dev,0 ,EM28XX_I2C_ALGO_EM2800 ); +else if (dev->chip_id ==CHIP_ID_EM28281 ) + retval =em28xx_i2c_register (dev,0 ,EM28XX_I2C_ALGO_EM28281_INTEGRATED );else retval =em28xx_i2c_register (dev,0 ,EM28XX_I2C_ALGO_EM28XX );if (retval <0 ) {
@@ -3702,6 +3734,9 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev,if (dev->is_em25xx) retval =em28xx_i2c_register (dev,1 ,EM28XX_I2C_ALGO_EM25XX_BUS_B ); +else if (dev->chip_id ==CHIP_ID_EM28281 ) + retval =em28xx_i2c_register (dev,1 , +EM28XX_I2C_ALGO_EM28281_INTEGRATED );else retval =em28xx_i2c_register (dev,1 ,EM28XX_I2C_ALGO_EM28XX );
drivers/media/usb/em28xx/em28xx-core.c +7 -0
@@ -506,6 +506,13 @@ int em28xx_audio_setup(struct em28xx *dev)return 0 ; } +if (dev->chip_id ==CHIP_ID_EM28281 ) { +/* Skip standard AC97 initialization which fails on this chip */ + dev->int_audio_type =EM28XX_INT_AUDIO_NONE ; + dev->audio_mode.ac97 =EM28XX_NO_AC97 ; +return 0 ; + } +/* See how this device is configured */ cfg =em28xx_read_reg (dev,EM28XX_R00_CHIPCFG );dev_info (&dev->intf->dev,"Config register raw data: 0x%02x\n" , cfg);
drivers/media/usb/em28xx/em28xx-i2c.c +144 -1
175 lines not on this page · raw message
drivers/media/usb/em28xx/em28xx-reg.h +1 -0
@@ -283,6 +283,7 @@ enum em28xx_chip_id {CHIP_ID_EM2884 =68 ,CHIP_ID_EM28174 =113 ,CHIP_ID_EM28178 =114 , + CHIP_ID_EM28281 = 145, };/*
drivers/media/usb/em28xx/em28xx.h +5 -0
@@ -144,6 +144,7 @@#define EM2860_BOARD_MYGICA_IGRABBER 105#define EM2874_BOARD_HAUPPAUGE_USB_QUADHD 106#define EM2860_BOARD_MYGICA_UTV3 107 +#define EM28281_BOARD_STARTECH_SVID2USB232 108/* Limits minimum and default number of buffers */ #define EM28XX_MIN_BUF 4
@@ -623,6 +624,7 @@ enum em28xx_i2c_algo_type {EM28XX_I2C_ALGO_EM28XX =0 ,EM28XX_I2C_ALGO_EM2800 ,EM28XX_I2C_ALGO_EM25XX_BUS_B , + EM28XX_I2C_ALGO_EM28281_INTEGRATED, }; struct em28xx_i2c_bus {
@@ -683,6 +685,9 @@ struct em28xx {unsigned int cur_i2c_bus;// Current I2C bus struct rt_mutex i2c_bus_lock; +/* EM28281 integrated decoder state */ +u8 em28281_last_reg;// Last register address for I2C reads +// video for linux unsigned int ctl_input;// selected input unsigned int ctl_ainput;// selected audio input
Signature · 1 line
2.52.0