2006-09-19 23:51:37 +08:00
/* Linux driver for devices based on the DiBcom DiB0700 USB bridge
*
* This program is free software ; you can redistribute it and / or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation , version 2.
*
* Copyright ( C ) 2005 - 6 DiBcom , SA
*/
# include "dib0700.h"
/* debug */
int dvb_usb_dib0700_debug ;
module_param_named ( debug , dvb_usb_dib0700_debug , int , 0644 ) ;
MODULE_PARM_DESC ( debug , " set debugging level (1=info,2=fw,4=fwdata,8=data (or-able)). " DVB_USB_DEBUG_STATUS ) ;
2009-12-07 19:22:53 +08:00
static int nb_packet_buffer_size = 21 ;
module_param ( nb_packet_buffer_size , int , 0644 ) ;
MODULE_PARM_DESC ( nb_packet_buffer_size ,
[media] dvb-usb: don't break long lines
Due to the 80-cols restrictions, and latter due to checkpatch
warnings, several strings were broken into multiple lines. This
is not considered a good practice anymore, as it makes harder
to grep for strings at the source code.
As we're right now fixing other drivers due to KERN_CONT, we need
to be able to identify what printk strings don't end with a "\n".
It is a way easier to detect those if we don't break long lines.
So, join those continuation lines.
The patch was generated via the script below, and manually
adjusted if needed.
</script>
use Text::Tabs;
while (<>) {
if ($next ne "") {
$c=$_;
if ($c =~ /^\s+\"(.*)/) {
$c2=$1;
$next =~ s/\"\n$//;
$n = expand($next);
$funpos = index($n, '(');
$pos = index($c2, '",');
if ($funpos && $pos > 0) {
$s1 = substr $c2, 0, $pos + 2;
$s2 = ' ' x ($funpos + 1) . substr $c2, $pos + 2;
$s2 =~ s/^\s+//;
$s2 = ' ' x ($funpos + 1) . $s2 if ($s2 ne "");
print unexpand("$next$s1\n");
print unexpand("$s2\n") if ($s2 ne "");
} else {
print "$next$c2\n";
}
$next="";
next;
} else {
print $next;
}
$next="";
} else {
if (m/\"$/) {
if (!m/\\n\"$/) {
$next=$_;
next;
}
}
}
print $_;
}
</script>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2016-10-19 03:44:15 +08:00
" Set the dib0700 driver data buffer size. This parameter corresponds to the number of TS packets. The actual size of the data buffer corresponds to this parameter multiplied by 188 (default: 21) " ) ;
2009-12-07 19:22:53 +08:00
2008-04-10 06:13:13 +08:00
DVB_DEFINE_MOD_OPT_ADAPTER_NR ( adapter_nr ) ;
2008-11-15 18:13:07 +08:00
int dib0700_get_version ( struct dvb_usb_device * d , u32 * hwversion ,
u32 * romversion , u32 * ramversion , u32 * fwtype )
{
2011-03-24 20:32:26 +08:00
struct dib0700_state * st = d - > priv ;
int ret ;
2011-08-01 23:45:58 +08:00
if ( mutex_lock_interruptible ( & d - > usb_mutex ) < 0 ) {
2011-08-05 00:10:03 +08:00
err ( " could not acquire lock " ) ;
2012-03-19 18:27:37 +08:00
return - EINTR ;
2011-08-01 23:45:58 +08:00
}
2011-03-24 20:32:26 +08:00
ret = usb_control_msg ( d - > udev , usb_rcvctrlpipe ( d - > udev , 0 ) ,
2008-11-15 18:13:07 +08:00
REQUEST_GET_VERSION ,
USB_TYPE_VENDOR | USB_DIR_IN , 0 , 0 ,
2011-03-24 20:32:26 +08:00
st - > buf , 16 , USB_CTRL_GET_TIMEOUT ) ;
2009-12-07 19:22:53 +08:00
if ( hwversion ! = NULL )
2011-03-24 20:32:26 +08:00
* hwversion = ( st - > buf [ 0 ] < < 24 ) | ( st - > buf [ 1 ] < < 16 ) |
( st - > buf [ 2 ] < < 8 ) | st - > buf [ 3 ] ;
2009-12-07 19:22:53 +08:00
if ( romversion ! = NULL )
2011-03-24 20:32:26 +08:00
* romversion = ( st - > buf [ 4 ] < < 24 ) | ( st - > buf [ 5 ] < < 16 ) |
( st - > buf [ 6 ] < < 8 ) | st - > buf [ 7 ] ;
2009-12-07 19:22:53 +08:00
if ( ramversion ! = NULL )
2011-03-24 20:32:26 +08:00
* ramversion = ( st - > buf [ 8 ] < < 24 ) | ( st - > buf [ 9 ] < < 16 ) |
( st - > buf [ 10 ] < < 8 ) | st - > buf [ 11 ] ;
2009-12-07 19:22:53 +08:00
if ( fwtype ! = NULL )
2011-03-24 20:32:26 +08:00
* fwtype = ( st - > buf [ 12 ] < < 24 ) | ( st - > buf [ 13 ] < < 16 ) |
( st - > buf [ 14 ] < < 8 ) | st - > buf [ 15 ] ;
2011-08-01 23:45:58 +08:00
mutex_unlock ( & d - > usb_mutex ) ;
2008-11-15 18:13:07 +08:00
return ret ;
}
2006-09-19 23:51:37 +08:00
/* expecting rx buffer: request data[0] data[1] ... data[2] */
static int dib0700_ctrl_wr ( struct dvb_usb_device * d , u8 * tx , u8 txlen )
{
int status ;
deb_data ( " >>> " ) ;
2010-07-01 12:19:31 +08:00
debug_dump ( tx , txlen , deb_data ) ;
2006-09-19 23:51:37 +08:00
status = usb_control_msg ( d - > udev , usb_sndctrlpipe ( d - > udev , 0 ) ,
tx [ 0 ] , USB_TYPE_VENDOR | USB_DIR_OUT , 0 , 0 , tx , txlen ,
USB_CTRL_GET_TIMEOUT ) ;
if ( status ! = txlen )
2006-09-19 23:51:40 +08:00
deb_data ( " ep 0 write error (status = %d, len: %d) \n " , status , txlen ) ;
2006-09-19 23:51:37 +08:00
return status < 0 ? status : 0 ;
}
/* expecting tx buffer: request data[0] ... data[n] (n <= 4) */
2007-07-26 01:42:54 +08:00
int dib0700_ctrl_rd ( struct dvb_usb_device * d , u8 * tx , u8 txlen , u8 * rx , u8 rxlen )
2006-09-19 23:51:37 +08:00
{
u16 index , value ;
int status ;
if ( txlen < 2 ) {
err ( " tx buffer length is smaller than 2. Makes no sense. " ) ;
return - EINVAL ;
}
if ( txlen > 4 ) {
err ( " tx buffer length is larger than 4. Not supported. " ) ;
return - EINVAL ;
}
deb_data ( " >>> " ) ;
debug_dump ( tx , txlen , deb_data ) ;
value = ( ( txlen - 2 ) < < 8 ) | tx [ 1 ] ;
index = 0 ;
if ( txlen > 2 )
index | = ( tx [ 2 ] < < 8 ) ;
if ( txlen > 3 )
index | = tx [ 3 ] ;
status = usb_control_msg ( d - > udev , usb_rcvctrlpipe ( d - > udev , 0 ) , tx [ 0 ] ,
USB_TYPE_VENDOR | USB_DIR_IN , value , index , rx , rxlen ,
USB_CTRL_GET_TIMEOUT ) ;
if ( status < 0 )
2006-09-19 23:51:40 +08:00
deb_info ( " ep 0 read error (status = %d) \n " , status ) ;
2006-09-19 23:51:37 +08:00
deb_data ( " <<< " ) ;
2010-07-01 12:19:31 +08:00
debug_dump ( rx , rxlen , deb_data ) ;
2006-09-19 23:51:37 +08:00
return status ; /* length in case of success */
}
int dib0700_set_gpio ( struct dvb_usb_device * d , enum dib07x0_gpios gpio , u8 gpio_dir , u8 gpio_val )
{
2011-03-24 20:32:26 +08:00
struct dib0700_state * st = d - > priv ;
2011-08-01 23:45:58 +08:00
int ret ;
if ( mutex_lock_interruptible ( & d - > usb_mutex ) < 0 ) {
2011-08-05 00:10:03 +08:00
err ( " could not acquire lock " ) ;
2012-03-19 18:27:37 +08:00
return - EINTR ;
2011-08-01 23:45:58 +08:00
}
2011-03-24 20:32:26 +08:00
st - > buf [ 0 ] = REQUEST_SET_GPIO ;
st - > buf [ 1 ] = gpio ;
st - > buf [ 2 ] = ( ( gpio_dir & 0x01 ) < < 7 ) | ( ( gpio_val & 0x01 ) < < 6 ) ;
ret = dib0700_ctrl_wr ( d , st - > buf , 3 ) ;
2011-08-01 23:45:58 +08:00
mutex_unlock ( & d - > usb_mutex ) ;
2011-03-24 20:32:26 +08:00
return ret ;
2006-09-19 23:51:37 +08:00
}
2009-12-07 19:22:53 +08:00
static int dib0700_set_usb_xfer_len ( struct dvb_usb_device * d , u16 nb_ts_packets )
{
2010-07-01 12:19:31 +08:00
struct dib0700_state * st = d - > priv ;
int ret ;
if ( st - > fw_version > = 0x10201 ) {
2011-08-01 23:45:58 +08:00
if ( mutex_lock_interruptible ( & d - > usb_mutex ) < 0 ) {
2011-08-05 00:10:03 +08:00
err ( " could not acquire lock " ) ;
2012-03-19 18:27:37 +08:00
return - EINTR ;
2011-08-01 23:45:58 +08:00
}
2011-03-24 20:32:26 +08:00
st - > buf [ 0 ] = REQUEST_SET_USB_XFER_LEN ;
st - > buf [ 1 ] = ( nb_ts_packets > > 8 ) & 0xff ;
st - > buf [ 2 ] = nb_ts_packets & 0xff ;
2010-07-01 12:19:31 +08:00
deb_info ( " set the USB xfer len to %i Ts packet \n " , nb_ts_packets ) ;
2011-03-24 20:32:26 +08:00
ret = dib0700_ctrl_wr ( d , st - > buf , 3 ) ;
2011-08-01 23:45:58 +08:00
mutex_unlock ( & d - > usb_mutex ) ;
2010-07-01 12:19:31 +08:00
} else {
deb_info ( " this firmware does not allow to change the USB xfer len \n " ) ;
ret = - EIO ;
}
return ret ;
2009-12-07 19:22:53 +08:00
}
2006-09-19 23:51:37 +08:00
/*
2008-09-07 00:45:27 +08:00
* I2C master xfer function ( supported in 1.20 firmware )
2006-09-19 23:51:37 +08:00
*/
2008-09-07 00:45:27 +08:00
static int dib0700_i2c_xfer_new ( struct i2c_adapter * adap , struct i2c_msg * msg ,
int num )
{
/* The new i2c firmware messages are more reliable and in particular
properly support i2c read calls not preceded by a write */
struct dvb_usb_device * d = i2c_get_adapdata ( adap ) ;
2011-03-24 20:32:26 +08:00
struct dib0700_state * st = d - > priv ;
2008-09-07 00:45:27 +08:00
uint8_t bus_mode = 1 ; /* 0=eeprom bus, 1=frontend bus */
uint8_t gen_mode = 0 ; /* 0=master i2c, 1=gpio i2c */
uint8_t en_start = 0 ;
uint8_t en_stop = 0 ;
int result , i ;
/* Ensure nobody else hits the i2c bus while we're sending our
sequence of messages , ( such as the remote control thread ) */
if ( mutex_lock_interruptible ( & d - > i2c_mutex ) < 0 )
2012-03-19 18:27:37 +08:00
return - EINTR ;
2008-09-07 00:45:27 +08:00
for ( i = 0 ; i < num ; i + + ) {
if ( i = = 0 ) {
/* First message in the transaction */
en_start = 1 ;
} else if ( ! ( msg [ i ] . flags & I2C_M_NOSTART ) ) {
/* Device supports repeated-start */
en_start = 1 ;
} else {
/* Not the first packet and device doesn't support
repeated start */
en_start = 0 ;
}
if ( i = = ( num - 1 ) ) {
/* Last message in the transaction */
en_stop = 1 ;
}
if ( msg [ i ] . flags & I2C_M_RD ) {
/* Read request */
u16 index , value ;
uint8_t i2c_dest ;
i2c_dest = ( msg [ i ] . addr < < 1 ) ;
value = ( ( en_start < < 7 ) | ( en_stop < < 6 ) |
( msg [ i ] . len & 0x3F ) ) < < 8 | i2c_dest ;
/* I2C ctrl + FE bus; */
2010-07-01 12:19:31 +08:00
index = ( ( gen_mode < < 6 ) & 0xC0 ) |
( ( bus_mode < < 4 ) & 0x30 ) ;
2008-09-07 00:45:27 +08:00
result = usb_control_msg ( d - > udev ,
usb_rcvctrlpipe ( d - > udev , 0 ) ,
REQUEST_NEW_I2C_READ ,
USB_TYPE_VENDOR | USB_DIR_IN ,
2016-10-07 17:53:51 +08:00
value , index , st - > buf ,
2008-09-07 00:45:27 +08:00
msg [ i ] . len ,
USB_CTRL_GET_TIMEOUT ) ;
if ( result < 0 ) {
2011-01-04 16:42:19 +08:00
deb_info ( " i2c read error (status = %d) \n " , result ) ;
2017-04-28 20:52:07 +08:00
goto unlock ;
2008-09-07 00:45:27 +08:00
}
2009-01-30 11:24:01 +08:00
2016-10-07 17:53:51 +08:00
if ( msg [ i ] . len > sizeof ( st - > buf ) ) {
deb_info ( " buffer too small to fit %d bytes \n " ,
msg [ i ] . len ) ;
2017-04-28 20:52:07 +08:00
result = - EIO ;
goto unlock ;
2016-10-07 17:53:51 +08:00
}
memcpy ( msg [ i ] . buf , st - > buf , msg [ i ] . len ) ;
2009-01-30 11:24:01 +08:00
deb_data ( " <<< " ) ;
debug_dump ( msg [ i ] . buf , msg [ i ] . len , deb_data ) ;
2008-09-07 00:45:27 +08:00
} else {
/* Write request */
2011-08-01 23:45:58 +08:00
if ( mutex_lock_interruptible ( & d - > usb_mutex ) < 0 ) {
2011-08-05 00:10:03 +08:00
err ( " could not acquire lock " ) ;
2017-04-28 20:52:07 +08:00
result = - EINTR ;
goto unlock ;
2011-08-01 23:45:58 +08:00
}
2011-03-24 20:32:26 +08:00
st - > buf [ 0 ] = REQUEST_NEW_I2C_WRITE ;
st - > buf [ 1 ] = msg [ i ] . addr < < 1 ;
st - > buf [ 2 ] = ( en_start < < 7 ) | ( en_stop < < 6 ) |
2008-09-07 00:45:27 +08:00
( msg [ i ] . len & 0x3F ) ;
/* I2C ctrl + FE bus; */
2011-03-24 20:32:26 +08:00
st - > buf [ 3 ] = ( ( gen_mode < < 6 ) & 0xC0 ) |
2010-07-01 12:19:31 +08:00
( ( bus_mode < < 4 ) & 0x30 ) ;
2016-10-07 17:53:51 +08:00
if ( msg [ i ] . len > sizeof ( st - > buf ) - 4 ) {
deb_info ( " i2c message to big: %d \n " ,
msg [ i ] . len ) ;
2017-04-28 20:52:07 +08:00
mutex_unlock ( & d - > usb_mutex ) ;
result = - EIO ;
goto unlock ;
2016-10-07 17:53:51 +08:00
}
2008-09-07 00:45:27 +08:00
/* The Actual i2c payload */
2011-03-24 20:32:26 +08:00
memcpy ( & st - > buf [ 4 ] , msg [ i ] . buf , msg [ i ] . len ) ;
2008-09-07 00:45:27 +08:00
2009-01-30 11:24:01 +08:00
deb_data ( " >>> " ) ;
2011-03-24 20:32:26 +08:00
debug_dump ( st - > buf , msg [ i ] . len + 4 , deb_data ) ;
2009-01-30 11:24:01 +08:00
2008-09-07 00:45:27 +08:00
result = usb_control_msg ( d - > udev ,
usb_sndctrlpipe ( d - > udev , 0 ) ,
REQUEST_NEW_I2C_WRITE ,
USB_TYPE_VENDOR | USB_DIR_OUT ,
2011-03-24 20:32:26 +08:00
0 , 0 , st - > buf , msg [ i ] . len + 4 ,
2008-09-07 00:45:27 +08:00
USB_CTRL_GET_TIMEOUT ) ;
2011-08-01 23:45:58 +08:00
mutex_unlock ( & d - > usb_mutex ) ;
2008-09-07 00:45:27 +08:00
if ( result < 0 ) {
2011-01-04 16:42:19 +08:00
deb_info ( " i2c write error (status = %d) \n " , result ) ;
2008-09-07 00:45:27 +08:00
break ;
}
}
}
2017-04-28 20:52:07 +08:00
result = i ;
unlock :
2008-09-07 00:45:27 +08:00
mutex_unlock ( & d - > i2c_mutex ) ;
2017-04-28 20:52:07 +08:00
return result ;
2008-09-07 00:45:27 +08:00
}
/*
* I2C master xfer function ( pre - 1.20 firmware )
*/
static int dib0700_i2c_xfer_legacy ( struct i2c_adapter * adap ,
struct i2c_msg * msg , int num )
2006-09-19 23:51:37 +08:00
{
struct dvb_usb_device * d = i2c_get_adapdata ( adap ) ;
2011-03-24 20:32:26 +08:00
struct dib0700_state * st = d - > priv ;
2006-09-19 23:51:37 +08:00
int i , len ;
if ( mutex_lock_interruptible ( & d - > i2c_mutex ) < 0 )
2012-03-19 18:27:37 +08:00
return - EINTR ;
2011-08-01 23:45:58 +08:00
if ( mutex_lock_interruptible ( & d - > usb_mutex ) < 0 ) {
2011-08-05 00:10:03 +08:00
err ( " could not acquire lock " ) ;
2012-03-19 18:27:37 +08:00
mutex_unlock ( & d - > i2c_mutex ) ;
return - EINTR ;
2011-08-01 23:45:58 +08:00
}
2006-09-19 23:51:37 +08:00
for ( i = 0 ; i < num ; i + + ) {
/* fill in the address */
2011-03-24 20:32:26 +08:00
st - > buf [ 1 ] = msg [ i ] . addr < < 1 ;
2006-09-19 23:51:37 +08:00
/* fill the buffer */
2016-10-07 17:53:51 +08:00
if ( msg [ i ] . len > sizeof ( st - > buf ) - 2 ) {
deb_info ( " i2c xfer to big: %d \n " ,
msg [ i ] . len ) ;
return - EIO ;
}
2011-03-24 20:32:26 +08:00
memcpy ( & st - > buf [ 2 ] , msg [ i ] . buf , msg [ i ] . len ) ;
2006-09-19 23:51:37 +08:00
/* write/read request */
if ( i + 1 < num & & ( msg [ i + 1 ] . flags & I2C_M_RD ) ) {
2011-03-24 20:32:26 +08:00
st - > buf [ 0 ] = REQUEST_I2C_READ ;
st - > buf [ 1 ] | = 1 ;
2006-09-19 23:51:37 +08:00
/* special thing in the current firmware: when length is zero the read-failed */
2011-03-24 20:32:26 +08:00
len = dib0700_ctrl_rd ( d , st - > buf , msg [ i ] . len + 2 ,
2016-10-07 17:40:24 +08:00
st - > buf , msg [ i + 1 ] . len ) ;
2011-03-24 20:32:26 +08:00
if ( len < = 0 ) {
2009-01-21 12:40:04 +08:00
deb_info ( " I2C read failed on address 0x%02x \n " ,
2011-03-24 20:32:26 +08:00
msg [ i ] . addr ) ;
2006-09-19 23:51:37 +08:00
break ;
2006-09-19 23:51:56 +08:00
}
2006-09-19 23:51:37 +08:00
2016-10-07 17:53:51 +08:00
if ( msg [ i + 1 ] . len > sizeof ( st - > buf ) ) {
deb_info ( " i2c xfer buffer to small for %d \n " ,
msg [ i ] . len ) ;
return - EIO ;
}
2016-10-07 17:40:24 +08:00
memcpy ( msg [ i + 1 ] . buf , st - > buf , msg [ i + 1 ] . len ) ;
2006-09-19 23:51:37 +08:00
msg [ i + 1 ] . len = len ;
i + + ;
} else {
2011-03-24 20:32:26 +08:00
st - > buf [ 0 ] = REQUEST_I2C_WRITE ;
if ( dib0700_ctrl_wr ( d , st - > buf , msg [ i ] . len + 2 ) < 0 )
2006-09-19 23:51:37 +08:00
break ;
}
}
2011-08-01 23:45:58 +08:00
mutex_unlock ( & d - > usb_mutex ) ;
2006-09-19 23:51:37 +08:00
mutex_unlock ( & d - > i2c_mutex ) ;
2011-03-24 20:32:26 +08:00
2006-09-19 23:51:37 +08:00
return i ;
}
2008-09-07 00:45:27 +08:00
static int dib0700_i2c_xfer ( struct i2c_adapter * adap , struct i2c_msg * msg ,
int num )
{
struct dvb_usb_device * d = i2c_get_adapdata ( adap ) ;
struct dib0700_state * st = d - > priv ;
if ( st - > fw_use_new_i2c_api = = 1 ) {
/* User running at least fw 1.20 */
return dib0700_i2c_xfer_new ( adap , msg , num ) ;
} else {
/* Use legacy calls */
return dib0700_i2c_xfer_legacy ( adap , msg , num ) ;
}
}
2006-09-19 23:51:37 +08:00
static u32 dib0700_i2c_func ( struct i2c_adapter * adapter )
{
return I2C_FUNC_I2C ;
}
struct i2c_algorithm dib0700_i2c_algo = {
. master_xfer = dib0700_i2c_xfer ,
. functionality = dib0700_i2c_func ,
} ;
2006-09-19 23:51:40 +08:00
int dib0700_identify_state ( struct usb_device * udev , struct dvb_usb_device_properties * props ,
struct dvb_usb_device_description * * desc , int * cold )
{
2011-03-24 20:32:26 +08:00
s16 ret ;
u8 * b ;
b = kmalloc ( 16 , GFP_KERNEL ) ;
if ( ! b )
return - ENOMEM ;
ret = usb_control_msg ( udev , usb_rcvctrlpipe ( udev , 0 ) ,
2006-10-18 19:34:16 +08:00
REQUEST_GET_VERSION , USB_TYPE_VENDOR | USB_DIR_IN , 0 , 0 , b , 16 , USB_CTRL_GET_TIMEOUT ) ;
deb_info ( " FW GET_VERSION length: %d \n " , ret ) ;
* cold = ret < = 0 ;
2006-09-19 23:51:40 +08:00
deb_info ( " cold: %d \n " , * cold ) ;
2011-03-24 20:32:26 +08:00
kfree ( b ) ;
2006-09-19 23:51:40 +08:00
return 0 ;
}
2006-10-18 19:34:16 +08:00
static int dib0700_set_clock ( struct dvb_usb_device * d , u8 en_pll ,
u8 pll_src , u8 pll_range , u8 clock_gpio3 , u16 pll_prediv ,
u16 pll_loopdiv , u16 free_div , u16 dsuScaler )
{
2011-03-24 20:32:26 +08:00
struct dib0700_state * st = d - > priv ;
2011-08-01 23:45:58 +08:00
int ret ;
if ( mutex_lock_interruptible ( & d - > usb_mutex ) < 0 ) {
2011-08-05 00:10:03 +08:00
err ( " could not acquire lock " ) ;
2012-03-19 18:27:37 +08:00
return - EINTR ;
2011-08-01 23:45:58 +08:00
}
2011-03-24 20:32:26 +08:00
st - > buf [ 0 ] = REQUEST_SET_CLOCK ;
st - > buf [ 1 ] = ( en_pll < < 7 ) | ( pll_src < < 6 ) |
( pll_range < < 5 ) | ( clock_gpio3 < < 4 ) ;
st - > buf [ 2 ] = ( pll_prediv > > 8 ) & 0xff ; /* MSB */
st - > buf [ 3 ] = pll_prediv & 0xff ; /* LSB */
st - > buf [ 4 ] = ( pll_loopdiv > > 8 ) & 0xff ; /* MSB */
st - > buf [ 5 ] = pll_loopdiv & 0xff ; /* LSB */
st - > buf [ 6 ] = ( free_div > > 8 ) & 0xff ; /* MSB */
st - > buf [ 7 ] = free_div & 0xff ; /* LSB */
st - > buf [ 8 ] = ( dsuScaler > > 8 ) & 0xff ; /* MSB */
st - > buf [ 9 ] = dsuScaler & 0xff ; /* LSB */
ret = dib0700_ctrl_wr ( d , st - > buf , 10 ) ;
2011-08-01 23:45:58 +08:00
mutex_unlock ( & d - > usb_mutex ) ;
2011-03-24 20:32:26 +08:00
return ret ;
2006-10-18 19:34:16 +08:00
}
2011-01-04 02:30:14 +08:00
int dib0700_set_i2c_speed ( struct dvb_usb_device * d , u16 scl_kHz )
{
2011-03-24 20:32:26 +08:00
struct dib0700_state * st = d - > priv ;
2011-01-04 02:30:14 +08:00
u16 divider ;
2011-08-01 23:45:58 +08:00
int ret ;
2011-01-04 02:30:14 +08:00
if ( scl_kHz = = 0 )
return - EINVAL ;
2011-08-01 23:45:58 +08:00
if ( mutex_lock_interruptible ( & d - > usb_mutex ) < 0 ) {
2011-08-05 00:10:03 +08:00
err ( " could not acquire lock " ) ;
2012-03-19 18:27:37 +08:00
return - EINTR ;
2011-08-01 23:45:58 +08:00
}
2011-03-24 20:32:26 +08:00
st - > buf [ 0 ] = REQUEST_SET_I2C_PARAM ;
2011-01-04 02:30:14 +08:00
divider = ( u16 ) ( 30000 / scl_kHz ) ;
2011-03-24 20:32:26 +08:00
st - > buf [ 1 ] = 0 ;
st - > buf [ 2 ] = ( u8 ) ( divider > > 8 ) ;
st - > buf [ 3 ] = ( u8 ) ( divider & 0xff ) ;
2011-01-04 02:30:14 +08:00
divider = ( u16 ) ( 72000 / scl_kHz ) ;
2011-03-24 20:32:26 +08:00
st - > buf [ 4 ] = ( u8 ) ( divider > > 8 ) ;
st - > buf [ 5 ] = ( u8 ) ( divider & 0xff ) ;
2011-01-04 02:30:14 +08:00
divider = ( u16 ) ( 72000 / scl_kHz ) ; /* clock: 72MHz */
2011-03-24 20:32:26 +08:00
st - > buf [ 6 ] = ( u8 ) ( divider > > 8 ) ;
st - > buf [ 7 ] = ( u8 ) ( divider & 0xff ) ;
2011-01-04 02:30:14 +08:00
2011-01-05 00:08:14 +08:00
deb_info ( " setting I2C speed: %04x %04x %04x (%d kHz). " ,
2011-03-24 20:32:26 +08:00
( st - > buf [ 2 ] < < 8 ) | ( st - > buf [ 3 ] ) , ( st - > buf [ 4 ] < < 8 ) |
st - > buf [ 5 ] , ( st - > buf [ 6 ] < < 8 ) | st - > buf [ 7 ] , scl_kHz ) ;
2011-08-01 23:45:58 +08:00
ret = dib0700_ctrl_wr ( d , st - > buf , 8 ) ;
mutex_unlock ( & d - > usb_mutex ) ;
return ret ;
2011-01-04 02:30:14 +08:00
}
2006-10-18 19:34:16 +08:00
int dib0700_ctrl_clock ( struct dvb_usb_device * d , u32 clk_MHz , u8 clock_out_gp3 )
{
switch ( clk_MHz ) {
case 72 : dib0700_set_clock ( d , 1 , 0 , 1 , clock_out_gp3 , 2 , 24 , 0 , 0x4c ) ; break ;
default : return - EINVAL ;
}
return 0 ;
}
2006-09-19 23:51:37 +08:00
static int dib0700_jumpram ( struct usb_device * udev , u32 address )
{
2011-03-24 20:32:26 +08:00
int ret = 0 , actlen ;
u8 * buf ;
buf = kmalloc ( 8 , GFP_KERNEL ) ;
if ( ! buf )
return - ENOMEM ;
buf [ 0 ] = REQUEST_JUMPRAM ;
buf [ 1 ] = 0 ;
buf [ 2 ] = 0 ;
buf [ 3 ] = 0 ;
buf [ 4 ] = ( address > > 24 ) & 0xff ;
buf [ 5 ] = ( address > > 16 ) & 0xff ;
buf [ 6 ] = ( address > > 8 ) & 0xff ;
buf [ 7 ] = address & 0xff ;
2006-09-19 23:51:37 +08:00
if ( ( ret = usb_bulk_msg ( udev , usb_sndbulkpipe ( udev , 0x01 ) , buf , 8 , & actlen , 1000 ) ) < 0 ) {
deb_fw ( " jumpram to 0x%x failed \n " , address ) ;
2011-03-24 20:32:26 +08:00
goto out ;
2006-09-19 23:51:37 +08:00
}
if ( actlen ! = 8 ) {
deb_fw ( " jumpram to 0x%x failed \n " , address ) ;
2011-03-24 20:32:26 +08:00
ret = - EIO ;
goto out ;
2006-09-19 23:51:37 +08:00
}
2011-03-24 20:32:26 +08:00
out :
kfree ( buf ) ;
return ret ;
2006-09-19 23:51:37 +08:00
}
int dib0700_download_firmware ( struct usb_device * udev , const struct firmware * fw )
{
struct hexline hx ;
2009-12-07 19:22:53 +08:00
int pos = 0 , ret , act_len , i , adap_num ;
2011-03-24 20:32:26 +08:00
u8 * buf ;
2009-12-07 19:22:53 +08:00
u32 fw_version ;
2006-09-19 23:51:37 +08:00
2011-03-24 20:32:26 +08:00
buf = kmalloc ( 260 , GFP_KERNEL ) ;
if ( ! buf )
return - ENOMEM ;
2006-09-19 23:51:37 +08:00
while ( ( ret = dvb_usb_get_hexline ( fw , & hx , & pos ) ) > 0 ) {
2010-07-01 12:19:31 +08:00
deb_fwdata ( " writing to address 0x%08x (buffer: 0x%02x %02x) \n " ,
hx . addr , hx . len , hx . chk ) ;
2006-09-19 23:51:37 +08:00
buf [ 0 ] = hx . len ;
2006-09-19 23:51:46 +08:00
buf [ 1 ] = ( hx . addr > > 8 ) & 0xff ;
buf [ 2 ] = hx . addr & 0xff ;
2006-09-19 23:51:37 +08:00
buf [ 3 ] = hx . type ;
memcpy ( & buf [ 4 ] , hx . data , hx . len ) ;
buf [ 4 + hx . len ] = hx . chk ;
ret = usb_bulk_msg ( udev ,
usb_sndbulkpipe ( udev , 0x01 ) ,
buf ,
hx . len + 5 ,
& act_len ,
1000 ) ;
if ( ret < 0 ) {
err ( " firmware download failed at %d with %d " , pos , ret ) ;
2011-03-24 20:32:26 +08:00
goto out ;
2006-09-19 23:51:37 +08:00
}
}
if ( ret = = 0 ) {
/* start the firmware */
2006-09-19 23:51:40 +08:00
if ( ( ret = dib0700_jumpram ( udev , 0x70000000 ) ) = = 0 ) {
2006-09-19 23:51:37 +08:00
info ( " firmware started successfully. " ) ;
2006-10-18 19:34:16 +08:00
msleep ( 500 ) ;
2006-09-19 23:51:40 +08:00
}
2006-09-19 23:51:37 +08:00
} else
ret = - EIO ;
2009-12-07 19:22:53 +08:00
/* the number of ts packet has to be at least 1 */
if ( nb_packet_buffer_size < 1 )
nb_packet_buffer_size = 1 ;
2016-05-20 08:09:14 +08:00
/* get the firmware version */
2009-12-07 19:22:53 +08:00
usb_control_msg ( udev , usb_rcvctrlpipe ( udev , 0 ) ,
REQUEST_GET_VERSION ,
USB_TYPE_VENDOR | USB_DIR_IN , 0 , 0 ,
2011-03-24 20:32:26 +08:00
buf , 16 , USB_CTRL_GET_TIMEOUT ) ;
fw_version = ( buf [ 8 ] < < 24 ) | ( buf [ 9 ] < < 16 ) | ( buf [ 10 ] < < 8 ) | buf [ 11 ] ;
2009-12-07 19:22:53 +08:00
/* set the buffer size - DVB-USB is allocating URB buffers
* only after the firwmare download was successful */
for ( i = 0 ; i < dib0700_device_count ; i + + ) {
for ( adap_num = 0 ; adap_num < dib0700_devices [ i ] . num_adapters ;
adap_num + + ) {
2010-07-01 12:19:31 +08:00
if ( fw_version > = 0x10201 ) {
2011-09-06 20:31:57 +08:00
dib0700_devices [ i ] . adapter [ adap_num ] . fe [ 0 ] . stream . u . bulk . buffersize = 188 * nb_packet_buffer_size ;
2010-07-01 12:19:31 +08:00
} else {
2009-12-07 19:22:53 +08:00
/* for fw version older than 1.20.1,
* the buffersize has to be n times 512 */
2011-09-06 20:31:57 +08:00
dib0700_devices [ i ] . adapter [ adap_num ] . fe [ 0 ] . stream . u . bulk . buffersize = ( ( 188 * nb_packet_buffer_size + 188 / 2 ) / 512 ) * 512 ;
if ( dib0700_devices [ i ] . adapter [ adap_num ] . fe [ 0 ] . stream . u . bulk . buffersize < 512 )
dib0700_devices [ i ] . adapter [ adap_num ] . fe [ 0 ] . stream . u . bulk . buffersize = 512 ;
2009-12-07 19:22:53 +08:00
}
}
}
2011-03-24 20:32:26 +08:00
out :
kfree ( buf ) ;
2006-09-19 23:51:37 +08:00
return ret ;
}
int dib0700_streaming_ctrl ( struct dvb_usb_adapter * adap , int onoff )
{
struct dib0700_state * st = adap - > dev - > priv ;
2009-12-07 19:22:53 +08:00
int ret ;
if ( ( onoff ! = 0 ) & & ( st - > fw_version > = 0x10201 ) ) {
/* for firmware later than 1.20.1,
* the USB xfer length can be set */
ret = dib0700_set_usb_xfer_len ( adap - > dev ,
st - > nb_packet_buffer_size ) ;
if ( ret < 0 ) {
deb_info ( " can not set the USB xfer len \n " ) ;
return ret ;
}
}
2006-09-19 23:51:37 +08:00
2013-01-03 23:53:53 +08:00
mutex_lock ( & adap - > dev - > usb_mutex ) ;
2011-08-01 23:45:58 +08:00
2011-03-24 20:32:26 +08:00
st - > buf [ 0 ] = REQUEST_ENABLE_VIDEO ;
/* this bit gives a kind of command,
* rather than enabling something or not */
st - > buf [ 1 ] = ( onoff < < 4 ) | 0x00 ;
2008-09-08 16:42:42 +08:00
if ( st - > disable_streaming_master_mode = = 1 )
2011-03-24 20:32:26 +08:00
st - > buf [ 2 ] = 0x00 ;
2008-09-08 16:42:42 +08:00
else
2011-03-24 20:32:26 +08:00
st - > buf [ 2 ] = 0x01 < < 4 ; /* Master mode */
2008-09-08 16:42:42 +08:00
2011-03-24 20:32:26 +08:00
st - > buf [ 3 ] = 0x00 ;
2006-09-19 23:51:37 +08:00
deb_info ( " modifying (%d) streaming state for %d \n " , onoff , adap - > id ) ;
2011-01-04 02:30:14 +08:00
st - > channel_state & = ~ 0x3 ;
2011-09-06 20:31:57 +08:00
if ( ( adap - > fe_adap [ 0 ] . stream . props . endpoint ! = 2 )
& & ( adap - > fe_adap [ 0 ] . stream . props . endpoint ! = 3 ) ) {
deb_info ( " the endpoint number (%i) is not correct, use the adapter id instead " , adap - > fe_adap [ 0 ] . stream . props . endpoint ) ;
2011-01-04 02:30:14 +08:00
if ( onoff )
st - > channel_state | = 1 < < ( adap - > id ) ;
else
2013-02-06 18:29:39 +08:00
st - > channel_state | = 1 < < ~ ( adap - > id ) ;
2011-01-05 00:08:14 +08:00
} else {
2011-01-04 02:30:14 +08:00
if ( onoff )
2011-09-06 20:31:57 +08:00
st - > channel_state | = 1 < < ( adap - > fe_adap [ 0 ] . stream . props . endpoint - 2 ) ;
2011-01-04 02:30:14 +08:00
else
2011-09-06 20:31:57 +08:00
st - > channel_state | = 1 < < ( 3 - adap - > fe_adap [ 0 ] . stream . props . endpoint ) ;
2011-01-04 02:30:14 +08:00
}
2006-09-19 23:51:37 +08:00
2011-03-24 20:32:26 +08:00
st - > buf [ 2 ] | = st - > channel_state ;
2006-09-19 23:51:37 +08:00
2011-03-24 20:32:26 +08:00
deb_info ( " data for streaming: %x %x \n " , st - > buf [ 1 ] , st - > buf [ 2 ] ) ;
2006-09-19 23:51:37 +08:00
2011-08-01 23:45:58 +08:00
ret = dib0700_ctrl_wr ( adap - > dev , st - > buf , 4 ) ;
mutex_unlock ( & adap - > dev - > usb_mutex ) ;
return ret ;
2006-09-19 23:51:37 +08:00
}
2012-10-12 06:11:54 +08:00
int dib0700_change_protocol ( struct rc_dev * rc , u64 * rc_type )
2010-08-01 20:37:23 +08:00
{
2010-10-30 03:08:23 +08:00
struct dvb_usb_device * d = rc - > priv ;
2010-08-01 20:37:23 +08:00
struct dib0700_state * st = d - > priv ;
int new_proto , ret ;
2011-08-01 23:45:58 +08:00
if ( mutex_lock_interruptible ( & d - > usb_mutex ) < 0 ) {
2011-08-05 00:10:03 +08:00
err ( " could not acquire lock " ) ;
2012-03-19 18:27:37 +08:00
return - EINTR ;
2011-08-01 23:45:58 +08:00
}
2011-03-24 20:32:26 +08:00
st - > buf [ 0 ] = REQUEST_SET_RC ;
st - > buf [ 1 ] = 0 ;
st - > buf [ 2 ] = 0 ;
2010-08-01 20:37:23 +08:00
/* Set the IR mode */
2012-10-12 06:11:54 +08:00
if ( * rc_type & RC_BIT_RC5 ) {
2010-08-01 20:37:23 +08:00
new_proto = 1 ;
2012-10-12 06:11:54 +08:00
* rc_type = RC_BIT_RC5 ;
} else if ( * rc_type & RC_BIT_NEC ) {
2010-08-01 20:37:23 +08:00
new_proto = 0 ;
2012-10-12 06:11:54 +08:00
* rc_type = RC_BIT_NEC ;
} else if ( * rc_type & RC_BIT_RC6_MCE ) {
2011-08-01 23:45:58 +08:00
if ( st - > fw_version < 0x10200 ) {
ret = - EINVAL ;
goto out ;
}
2010-08-01 20:37:23 +08:00
new_proto = 2 ;
2012-10-12 06:11:54 +08:00
* rc_type = RC_BIT_RC6_MCE ;
2011-08-01 23:45:58 +08:00
} else {
ret = - EINVAL ;
goto out ;
}
2010-08-01 20:37:23 +08:00
2011-03-24 20:32:26 +08:00
st - > buf [ 1 ] = new_proto ;
2010-08-01 20:37:23 +08:00
2011-03-24 20:32:26 +08:00
ret = dib0700_ctrl_wr ( d , st - > buf , 3 ) ;
2010-08-01 20:37:23 +08:00
if ( ret < 0 ) {
err ( " ir protocol setup failed " ) ;
2011-08-01 23:45:58 +08:00
goto out ;
2010-08-01 20:37:23 +08:00
}
2012-10-12 06:11:54 +08:00
d - > props . rc . core . protocol = * rc_type ;
2010-08-01 20:37:23 +08:00
2011-08-01 23:45:58 +08:00
out :
mutex_unlock ( & d - > usb_mutex ) ;
2010-08-01 20:37:23 +08:00
return ret ;
}
2010-01-04 13:43:19 +08:00
/* This is the structure of the RC response packet starting in firmware 1.20 */
struct dib0700_rc_response {
u8 report_id ;
u8 data_state ;
2015-03-31 04:51:01 +08:00
union {
struct {
u8 system ;
u8 not_system ;
u8 data ;
u8 not_data ;
} nec ;
struct {
u8 not_used ;
u8 system ;
u8 data ;
u8 not_data ;
} rc5 ;
} ;
2010-01-04 13:43:19 +08:00
} ;
# define RC_MSG_SIZE_V1_20 6
static void dib0700_rc_urb_completion ( struct urb * purb )
{
struct dvb_usb_device * d = purb - > context ;
2010-08-01 21:35:49 +08:00
struct dib0700_rc_response * poll_reply ;
2014-04-04 07:31:30 +08:00
enum rc_type protocol ;
2016-11-11 00:44:49 +08:00
u32 keycode ;
2010-08-01 09:56:00 +08:00
u8 toggle ;
2010-01-04 13:43:19 +08:00
deb_info ( " %s() \n " , __func__ ) ;
2010-10-30 03:08:23 +08:00
if ( d - > rc_dev = = NULL ) {
2010-01-04 13:43:19 +08:00
/* This will occur if disable_rc_polling=1 */
2012-03-14 00:52:50 +08:00
kfree ( purb - > transfer_buffer ) ;
2010-01-04 13:43:19 +08:00
usb_free_urb ( purb ) ;
return ;
}
2010-08-01 21:35:49 +08:00
poll_reply = purb - > transfer_buffer ;
2010-01-04 13:43:19 +08:00
if ( purb - > status < 0 ) {
deb_info ( " discontinuing polling \n " ) ;
2012-03-14 00:52:50 +08:00
kfree ( purb - > transfer_buffer ) ;
2010-01-04 13:43:19 +08:00
usb_free_urb ( purb ) ;
return ;
}
if ( purb - > actual_length ! = RC_MSG_SIZE_V1_20 ) {
deb_info ( " malformed rc msg size=%d \n " , purb - > actual_length ) ;
goto resubmit ;
}
2010-08-01 21:35:49 +08:00
deb_data ( " IR ID = %02X state = %02X System = %02X %02X Cmd = %02X %02X (len %d) \n " ,
poll_reply - > report_id , poll_reply - > data_state ,
2015-03-31 04:51:01 +08:00
poll_reply - > nec . system , poll_reply - > nec . not_system ,
poll_reply - > nec . data , poll_reply - > nec . not_data ,
2010-08-01 21:35:49 +08:00
purb - > actual_length ) ;
2010-01-04 13:43:19 +08:00
2010-08-01 20:37:23 +08:00
switch ( d - > props . rc . core . protocol ) {
2012-10-12 06:11:54 +08:00
case RC_BIT_NEC :
2010-08-01 09:56:00 +08:00
toggle = 0 ;
2010-01-04 13:43:19 +08:00
/* NEC protocol sends repeat code as 0 0 0 FF */
2015-03-31 04:51:01 +08:00
if ( poll_reply - > nec . system = = 0x00 & &
poll_reply - > nec . not_system = = 0x00 & &
poll_reply - > nec . data = = 0x00 & &
poll_reply - > nec . not_data = = 0xff ) {
2010-08-01 21:35:49 +08:00
poll_reply - > data_state = 2 ;
2016-11-11 00:44:49 +08:00
rc_repeat ( d - > rc_dev ) ;
goto resubmit ;
2010-01-04 13:43:19 +08:00
}
2010-08-01 09:56:00 +08:00
2015-03-31 04:51:01 +08:00
if ( ( poll_reply - > nec . data ^ poll_reply - > nec . not_data ) ! = 0xff ) {
2014-04-04 07:31:51 +08:00
deb_data ( " NEC32 protocol \n " ) ;
2015-03-31 04:51:01 +08:00
keycode = RC_SCANCODE_NEC32 ( poll_reply - > nec . system < < 24 |
poll_reply - > nec . not_system < < 16 |
poll_reply - > nec . data < < 8 |
poll_reply - > nec . not_data ) ;
2016-09-21 17:54:19 +08:00
protocol = RC_TYPE_NEC32 ;
2015-03-31 04:51:01 +08:00
} else if ( ( poll_reply - > nec . system ^ poll_reply - > nec . not_system ) ! = 0xff ) {
2010-08-01 21:35:49 +08:00
deb_data ( " NEC extended protocol \n " ) ;
2015-03-31 04:51:01 +08:00
keycode = RC_SCANCODE_NECX ( poll_reply - > nec . system < < 8 |
poll_reply - > nec . not_system ,
poll_reply - > nec . data ) ;
2014-04-04 07:31:30 +08:00
2016-09-21 17:54:19 +08:00
protocol = RC_TYPE_NECX ;
2010-08-01 21:35:49 +08:00
} else {
deb_data ( " NEC normal protocol \n " ) ;
2015-03-31 04:51:01 +08:00
keycode = RC_SCANCODE_NEC ( poll_reply - > nec . system ,
poll_reply - > nec . data ) ;
2016-09-21 17:54:19 +08:00
protocol = RC_TYPE_NEC ;
2010-08-01 21:35:49 +08:00
}
2010-01-04 13:43:19 +08:00
break ;
default :
2010-08-01 21:35:49 +08:00
deb_data ( " RC5 protocol \n " ) ;
2014-04-04 07:31:30 +08:00
protocol = RC_TYPE_RC5 ;
2010-08-01 21:35:49 +08:00
toggle = poll_reply - > report_id ;
2015-03-31 04:51:01 +08:00
keycode = RC_SCANCODE_RC5 ( poll_reply - > rc5 . system , poll_reply - > rc5 . data ) ;
if ( ( poll_reply - > rc5 . data ^ poll_reply - > rc5 . not_data ) ! = 0xff ) {
/* Key failed integrity check */
err ( " key failed integrity check: %02x %02x %02x %02x " ,
poll_reply - > rc5 . not_used , poll_reply - > rc5 . system ,
poll_reply - > rc5 . data , poll_reply - > rc5 . not_data ) ;
goto resubmit ;
}
2010-08-01 09:56:00 +08:00
2010-01-04 13:43:19 +08:00
break ;
}
2014-04-04 07:31:30 +08:00
rc_keydown ( d - > rc_dev , protocol , keycode , toggle ) ;
2010-01-04 13:43:19 +08:00
resubmit :
/* Clean the buffer before we requeue */
memset ( purb - > transfer_buffer , 0 , RC_MSG_SIZE_V1_20 ) ;
/* Requeue URB */
usb_submit_urb ( purb , GFP_ATOMIC ) ;
}
2014-05-22 04:40:25 +08:00
int dib0700_rc_setup ( struct dvb_usb_device * d , struct usb_interface * intf )
2007-08-01 06:45:13 +08:00
{
2010-01-04 13:43:19 +08:00
struct dib0700_state * st = d - > priv ;
struct urb * purb ;
2014-05-22 04:40:25 +08:00
const struct usb_endpoint_descriptor * e ;
int ret , rc_ep = 1 ;
unsigned int pipe = 0 ;
2010-01-04 13:43:19 +08:00
2010-08-01 20:37:23 +08:00
/* Poll-based. Don't initialize bulk mode */
2014-05-22 04:40:25 +08:00
if ( st - > fw_version < 0x10200 | | ! intf )
2010-01-04 13:43:19 +08:00
return 0 ;
/* Starting in firmware 1.20, the RC info is provided on a bulk pipe */
2014-05-22 04:40:25 +08:00
2017-03-13 20:53:54 +08:00
if ( intf - > altsetting [ 0 ] . desc . bNumEndpoints < rc_ep + 1 )
return - ENODEV ;
2010-01-04 13:43:19 +08:00
purb = usb_alloc_urb ( 0 , GFP_KERNEL ) ;
2016-08-12 05:03:48 +08:00
if ( purb = = NULL )
2010-07-01 12:08:58 +08:00
return - ENOMEM ;
2010-01-04 13:43:19 +08:00
purb - > transfer_buffer = kzalloc ( RC_MSG_SIZE_V1_20 , GFP_KERNEL ) ;
if ( purb - > transfer_buffer = = NULL ) {
2012-07-31 01:03:16 +08:00
err ( " rc kzalloc failed " ) ;
2010-01-04 13:43:19 +08:00
usb_free_urb ( purb ) ;
2010-07-01 12:08:58 +08:00
return - ENOMEM ;
2010-01-04 13:43:19 +08:00
}
purb - > status = - EINPROGRESS ;
2014-05-22 04:40:25 +08:00
/*
* Some devices like the Hauppauge NovaTD model 52009 use an interrupt
* endpoint , while others use a bulk one .
*/
e = & intf - > altsetting [ 0 ] . endpoint [ rc_ep ] . desc ;
if ( usb_endpoint_dir_in ( e ) ) {
if ( usb_endpoint_xfer_bulk ( e ) ) {
pipe = usb_rcvbulkpipe ( d - > udev , rc_ep ) ;
usb_fill_bulk_urb ( purb , d - > udev , pipe ,
purb - > transfer_buffer ,
RC_MSG_SIZE_V1_20 ,
dib0700_rc_urb_completion , d ) ;
} else if ( usb_endpoint_xfer_int ( e ) ) {
pipe = usb_rcvintpipe ( d - > udev , rc_ep ) ;
usb_fill_int_urb ( purb , d - > udev , pipe ,
purb - > transfer_buffer ,
RC_MSG_SIZE_V1_20 ,
dib0700_rc_urb_completion , d , 1 ) ;
}
}
if ( ! pipe ) {
err ( " There's no endpoint for remote controller " ) ;
kfree ( purb - > transfer_buffer ) ;
usb_free_urb ( purb ) ;
return 0 ;
}
2010-01-04 13:43:19 +08:00
ret = usb_submit_urb ( purb , GFP_ATOMIC ) ;
2012-03-14 00:52:50 +08:00
if ( ret ) {
2012-07-31 01:03:16 +08:00
err ( " rc submit urb failed " ) ;
2012-03-14 00:52:50 +08:00
kfree ( purb - > transfer_buffer ) ;
usb_free_urb ( purb ) ;
}
2010-01-04 13:43:19 +08:00
2010-07-01 12:08:58 +08:00
return ret ;
2007-08-01 06:45:13 +08:00
}
2006-09-19 23:51:37 +08:00
static int dib0700_probe ( struct usb_interface * intf ,
const struct usb_device_id * id )
{
int i ;
2007-08-01 06:45:13 +08:00
struct dvb_usb_device * dev ;
2006-09-19 23:51:37 +08:00
for ( i = 0 ; i < dib0700_device_count ; i + + )
2008-04-10 06:13:13 +08:00
if ( dvb_usb_device_init ( intf , & dib0700_devices [ i ] , THIS_MODULE ,
2009-12-07 19:22:53 +08:00
& dev , adapter_nr ) = = 0 ) {
struct dib0700_state * st = dev - > priv ;
u32 hwversion , romversion , fw_version , fwtype ;
dib0700_get_version ( dev , & hwversion , & romversion ,
& fw_version , & fwtype ) ;
deb_info ( " Firmware version: %x, %d, 0x%x, %d \n " ,
hwversion , romversion , fw_version , fwtype ) ;
st - > fw_version = fw_version ;
st - > nb_packet_buffer_size = ( u32 ) nb_packet_buffer_size ;
2010-08-01 09:56:00 +08:00
/* Disable polling mode on newer firmwares */
if ( st - > fw_version > = 0x10200 )
dev - > props . rc . core . bulk_mode = true ;
else
dev - > props . rc . core . bulk_mode = false ;
2014-05-22 04:40:25 +08:00
dib0700_rc_setup ( dev , intf ) ;
2009-12-07 19:22:53 +08:00
2006-09-19 23:51:37 +08:00
return 0 ;
2007-08-01 06:45:13 +08:00
}
2006-09-19 23:51:37 +08:00
return - ENODEV ;
}
static struct usb_driver dib0700_driver = {
. name = " dvb_usb_dib0700 " ,
. probe = dib0700_probe ,
. disconnect = dvb_usb_device_exit ,
. id_table = dib0700_usb_id_table ,
} ;
2011-11-19 01:46:12 +08:00
module_usb_driver ( dib0700_driver ) ;
2006-09-19 23:51:37 +08:00
2012-01-17 19:41:20 +08:00
MODULE_FIRMWARE ( " dvb-usb-dib0700-1.20.fw " ) ;
2016-01-24 22:56:58 +08:00
MODULE_AUTHOR ( " Patrick Boettcher <patrick.boettcher@posteo.de> " ) ;
2006-09-19 23:51:37 +08:00
MODULE_DESCRIPTION ( " Driver for devices based on DiBcom DiB0700 - USB bridge " ) ;
MODULE_VERSION ( " 1.0 " ) ;
MODULE_LICENSE ( " GPL " ) ;