4242#include "dib0070.h"
4343#include "lgs8gxx.h"
4444#include "atbm8830.h"
45+ #include "si2168.h"
46+ #include "si2157.h"
4547
4648/* Max transfer size done by I2C transfer functions */
4749#define MAX_XFER_SIZE 64
@@ -144,6 +146,22 @@ static int cxusb_d680_dmb_gpio_tuner(struct dvb_usb_device *d,
144146 }
145147}
146148
149+ static int cxusb_tt_ct2_4400_gpio_tuner (struct dvb_usb_device * d , int onoff )
150+ {
151+ u8 o [2 ], i ;
152+ int rc ;
153+
154+ o [0 ] = 0x83 ;
155+ o [1 ] = onoff ;
156+ rc = cxusb_ctrl_msg (d , CMD_GPIO_WRITE , o , 2 , & i , 1 );
157+
158+ if (rc ) {
159+ deb_info ("gpio_write failed.\n" );
160+ return - EIO ;
161+ }
162+ return 0 ;
163+ }
164+
147165/* I2C */
148166static int cxusb_i2c_xfer (struct i2c_adapter * adap , struct i2c_msg msg [],
149167 int num )
@@ -505,6 +523,30 @@ static int cxusb_d680_dmb_rc_query(struct dvb_usb_device *d, u32 *event,
505523 return 0 ;
506524}
507525
526+ static int cxusb_tt_ct2_4400_rc_query (struct dvb_usb_device * d )
527+ {
528+ u8 i [2 ];
529+ int ret ;
530+ u32 cmd , keycode ;
531+ u8 rc5_cmd , rc5_addr , rc5_toggle ;
532+
533+ ret = cxusb_ctrl_msg (d , 0x10 , NULL , 0 , i , 2 );
534+ if (ret )
535+ return ret ;
536+
537+ cmd = (i [0 ] << 8 ) | i [1 ];
538+
539+ if (cmd != 0xffff ) {
540+ rc5_cmd = cmd & 0x3F ; /* bits 1-6 for command */
541+ rc5_addr = (cmd & 0x07C0 ) >> 6 ; /* bits 7-11 for address */
542+ rc5_toggle = (cmd & 0x0800 ) >> 11 ; /* bit 12 for toggle */
543+ keycode = (rc5_addr << 8 ) | rc5_cmd ;
544+ rc_keydown (d -> rc_dev , keycode , rc5_toggle );
545+ }
546+
547+ return 0 ;
548+ }
549+
508550static struct rc_map_table rc_map_dvico_mce_table [] = {
509551 { 0xfe02 , KEY_TV },
510552 { 0xfe0e , KEY_MP3 },
@@ -1301,6 +1343,73 @@ static int cxusb_mygica_d689_frontend_attach(struct dvb_usb_adapter *adap)
13011343 return 0 ;
13021344}
13031345
1346+ static int cxusb_tt_ct2_4400_attach (struct dvb_usb_adapter * adap )
1347+ {
1348+ struct dvb_usb_device * d = adap -> dev ;
1349+ struct cxusb_state * st = d -> priv ;
1350+ struct i2c_adapter * adapter ;
1351+ struct i2c_client * client_demod ;
1352+ struct i2c_client * client_tuner ;
1353+ struct i2c_board_info info ;
1354+ struct si2168_config si2168_config ;
1355+ struct si2157_config si2157_config ;
1356+
1357+ /* reset the tuner */
1358+ if (cxusb_tt_ct2_4400_gpio_tuner (d , 0 ) < 0 ) {
1359+ err ("clear tuner gpio failed" );
1360+ return - EIO ;
1361+ }
1362+ msleep (100 );
1363+ if (cxusb_tt_ct2_4400_gpio_tuner (d , 1 ) < 0 ) {
1364+ err ("set tuner gpio failed" );
1365+ return - EIO ;
1366+ }
1367+ msleep (100 );
1368+
1369+ /* attach frontend */
1370+ si2168_config .i2c_adapter = & adapter ;
1371+ si2168_config .fe = & adap -> fe_adap [0 ].fe ;
1372+ memset (& info , 0 , sizeof (struct i2c_board_info ));
1373+ strlcpy (info .type , "si2168" , I2C_NAME_SIZE );
1374+ info .addr = 0x64 ;
1375+ info .platform_data = & si2168_config ;
1376+ request_module (info .type );
1377+ client_demod = i2c_new_device (& d -> i2c_adap , & info );
1378+ if (client_demod == NULL || client_demod -> dev .driver == NULL )
1379+ return - ENODEV ;
1380+
1381+ if (!try_module_get (client_demod -> dev .driver -> owner )) {
1382+ i2c_unregister_device (client_demod );
1383+ return - ENODEV ;
1384+ }
1385+
1386+ st -> i2c_client_demod = client_demod ;
1387+
1388+ /* attach tuner */
1389+ si2157_config .fe = adap -> fe_adap [0 ].fe ;
1390+ memset (& info , 0 , sizeof (struct i2c_board_info ));
1391+ strlcpy (info .type , "si2157" , I2C_NAME_SIZE );
1392+ info .addr = 0x60 ;
1393+ info .platform_data = & si2157_config ;
1394+ request_module (info .type );
1395+ client_tuner = i2c_new_device (adapter , & info );
1396+ if (client_tuner == NULL || client_tuner -> dev .driver == NULL ) {
1397+ module_put (client_demod -> dev .driver -> owner );
1398+ i2c_unregister_device (client_demod );
1399+ return - ENODEV ;
1400+ }
1401+ if (!try_module_get (client_tuner -> dev .driver -> owner )) {
1402+ i2c_unregister_device (client_tuner );
1403+ module_put (client_demod -> dev .driver -> owner );
1404+ i2c_unregister_device (client_demod );
1405+ return - ENODEV ;
1406+ }
1407+
1408+ st -> i2c_client_tuner = client_tuner ;
1409+
1410+ return 0 ;
1411+ }
1412+
13041413/*
13051414 * DViCO has shipped two devices with the same USB ID, but only one of them
13061415 * needs a firmware download. Check the device class details to see if they
@@ -1382,6 +1491,7 @@ static struct dvb_usb_device_properties cxusb_bluebird_nano2_needsfirmware_prope
13821491static struct dvb_usb_device_properties cxusb_aver_a868r_properties ;
13831492static struct dvb_usb_device_properties cxusb_d680_dmb_properties ;
13841493static struct dvb_usb_device_properties cxusb_mygica_d689_properties ;
1494+ static struct dvb_usb_device_properties cxusb_tt_ct2_4400_properties ;
13851495
13861496static int cxusb_probe (struct usb_interface * intf ,
13871497 const struct usb_device_id * id )
@@ -1412,12 +1522,37 @@ static int cxusb_probe(struct usb_interface *intf,
14121522 THIS_MODULE , NULL , adapter_nr ) ||
14131523 0 == dvb_usb_device_init (intf , & cxusb_mygica_d689_properties ,
14141524 THIS_MODULE , NULL , adapter_nr ) ||
1525+ 0 == dvb_usb_device_init (intf , & cxusb_tt_ct2_4400_properties ,
1526+ THIS_MODULE , NULL , adapter_nr ) ||
14151527 0 )
14161528 return 0 ;
14171529
14181530 return - EINVAL ;
14191531}
14201532
1533+ static void cxusb_disconnect (struct usb_interface * intf )
1534+ {
1535+ struct dvb_usb_device * d = usb_get_intfdata (intf );
1536+ struct cxusb_state * st = d -> priv ;
1537+ struct i2c_client * client ;
1538+
1539+ /* remove I2C client for tuner */
1540+ client = st -> i2c_client_tuner ;
1541+ if (client ) {
1542+ module_put (client -> dev .driver -> owner );
1543+ i2c_unregister_device (client );
1544+ }
1545+
1546+ /* remove I2C client for demodulator */
1547+ client = st -> i2c_client_demod ;
1548+ if (client ) {
1549+ module_put (client -> dev .driver -> owner );
1550+ i2c_unregister_device (client );
1551+ }
1552+
1553+ dvb_usb_device_exit (intf );
1554+ }
1555+
14211556static struct usb_device_id cxusb_table [] = {
14221557 { USB_DEVICE (USB_VID_MEDION , USB_PID_MEDION_MD95700 ) },
14231558 { USB_DEVICE (USB_VID_DVICO , USB_PID_DVICO_BLUEBIRD_LG064F_COLD ) },
@@ -1439,6 +1574,7 @@ static struct usb_device_id cxusb_table [] = {
14391574 { USB_DEVICE (USB_VID_DVICO , USB_PID_DVICO_BLUEBIRD_DUAL_4_REV_2 ) },
14401575 { USB_DEVICE (USB_VID_CONEXANT , USB_PID_CONEXANT_D680_DMB ) },
14411576 { USB_DEVICE (USB_VID_CONEXANT , USB_PID_MYGICA_D689 ) },
1577+ { USB_DEVICE (USB_VID_TECHNOTREND , USB_PID_TECHNOTREND_TVSTICK_CT2_4400 ) },
14421578 {} /* Terminating entry */
14431579};
14441580MODULE_DEVICE_TABLE (usb , cxusb_table );
@@ -2085,10 +2221,63 @@ static struct dvb_usb_device_properties cxusb_mygica_d689_properties = {
20852221 }
20862222};
20872223
2224+ static struct dvb_usb_device_properties cxusb_tt_ct2_4400_properties = {
2225+ .caps = DVB_USB_IS_AN_I2C_ADAPTER ,
2226+
2227+ .usb_ctrl = CYPRESS_FX2 ,
2228+
2229+ .size_of_priv = sizeof (struct cxusb_state ),
2230+
2231+ .num_adapters = 1 ,
2232+ .adapter = {
2233+ {
2234+ .num_frontends = 1 ,
2235+ .fe = {{
2236+ .streaming_ctrl = cxusb_streaming_ctrl ,
2237+ /* both frontend and tuner attached in the
2238+ same function */
2239+ .frontend_attach = cxusb_tt_ct2_4400_attach ,
2240+
2241+ /* parameter for the MPEG2-data transfer */
2242+ .stream = {
2243+ .type = USB_BULK ,
2244+ .count = 8 ,
2245+ .endpoint = 0x82 ,
2246+ .u = {
2247+ .bulk = {
2248+ .buffersize = 4096 ,
2249+ }
2250+ }
2251+ },
2252+ } },
2253+ },
2254+ },
2255+
2256+ .i2c_algo = & cxusb_i2c_algo ,
2257+ .generic_bulk_ctrl_endpoint = 0x01 ,
2258+ .generic_bulk_ctrl_endpoint_response = 0x81 ,
2259+
2260+ .rc .core = {
2261+ .rc_codes = RC_MAP_TT_1500 ,
2262+ .allowed_protos = RC_BIT_RC5 ,
2263+ .rc_query = cxusb_tt_ct2_4400_rc_query ,
2264+ .rc_interval = 150 ,
2265+ },
2266+
2267+ .num_device_descs = 1 ,
2268+ .devices = {
2269+ {
2270+ "TechnoTrend TVStick CT2-4400" ,
2271+ { NULL },
2272+ { & cxusb_table [20 ], NULL },
2273+ },
2274+ }
2275+ };
2276+
20882277static struct usb_driver cxusb_driver = {
20892278 .name = "dvb_usb_cxusb" ,
20902279 .probe = cxusb_probe ,
2091- .disconnect = dvb_usb_device_exit ,
2280+ .disconnect = cxusb_disconnect ,
20922281 .id_table = cxusb_table ,
20932282};
20942283
0 commit comments