2006-06-26 23:58:46 +00:00
/*
*
*
* Copyright ( C ) 2005 Mike Isely < isely @ pobox . com >
* Copyright ( C ) 2004 Aurelien Alleaume < slts @ free . fr >
*
* 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 ; either version 2 of the License
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
*/
# include <linux/device.h> // for linux/firmware.h
# include <linux/firmware.h>
# include "pvrusb2-util.h"
# include "pvrusb2-encoder.h"
# include "pvrusb2-hdw-internal.h"
# include "pvrusb2-debug.h"
2007-01-22 05:17:55 +00:00
# include "pvrusb2-fx2-cmd.h"
2006-06-26 23:58:46 +00:00
/* Firmware mailbox flags - definitions found from ivtv */
# define IVTV_MBOX_FIRMWARE_DONE 0x00000004
# define IVTV_MBOX_DRIVER_DONE 0x00000002
# define IVTV_MBOX_DRIVER_BUSY 0x00000001
2007-01-28 18:41:12 +00:00
# define MBOX_BASE 0x44
2006-06-26 23:58:46 +00:00
2006-06-25 23:04:06 +00:00
static int pvr2_encoder_write_words ( struct pvr2_hdw * hdw ,
2007-01-28 18:41:12 +00:00
unsigned int offs ,
2006-06-26 23:58:46 +00:00
const u32 * data , unsigned int dlen )
{
2007-01-28 18:41:12 +00:00
unsigned int idx , addr ;
unsigned int bAddr ;
2006-06-26 23:58:46 +00:00
int ret ;
unsigned int chunkCnt ;
/*
Format : First byte must be 0x01 . Remaining 32 bit words are
2007-01-28 18:41:12 +00:00
spread out into chunks of 7 bytes each , with the first 4 bytes
being the data word ( little endian ) , and the next 3 bytes
being the address where that data word is to be written ( big
endian ) . Repeat request for additional words , with offset
adjusted accordingly .
2006-06-26 23:58:46 +00:00
*/
while ( dlen ) {
chunkCnt = 8 ;
if ( chunkCnt > dlen ) chunkCnt = dlen ;
memset ( hdw - > cmd_buffer , 0 , sizeof ( hdw - > cmd_buffer ) ) ;
2007-01-28 18:41:12 +00:00
bAddr = 0 ;
hdw - > cmd_buffer [ bAddr + + ] = FX2CMD_MEM_WRITE_DWORD ;
2006-06-26 23:58:46 +00:00
for ( idx = 0 ; idx < chunkCnt ; idx + + ) {
2007-01-28 18:41:12 +00:00
addr = idx + offs ;
hdw - > cmd_buffer [ bAddr + 6 ] = ( addr & 0xffu ) ;
hdw - > cmd_buffer [ bAddr + 5 ] = ( ( addr > > 8 ) & 0xffu ) ;
hdw - > cmd_buffer [ bAddr + 4 ] = ( ( addr > > 16 ) & 0xffu ) ;
PVR2_DECOMPOSE_LE ( hdw - > cmd_buffer , bAddr , data [ idx ] ) ;
bAddr + = 7 ;
2006-06-26 23:58:46 +00:00
}
ret = pvr2_send_request ( hdw ,
hdw - > cmd_buffer , 1 + ( chunkCnt * 7 ) ,
2006-06-30 14:35:28 +00:00
NULL , 0 ) ;
2006-06-26 23:58:46 +00:00
if ( ret ) return ret ;
data + = chunkCnt ;
dlen - = chunkCnt ;
offs + = chunkCnt ;
}
return 0 ;
}
2007-01-28 18:41:12 +00:00
static int pvr2_encoder_read_words ( struct pvr2_hdw * hdw ,
unsigned int offs ,
2006-06-26 23:58:46 +00:00
u32 * data , unsigned int dlen )
{
unsigned int idx ;
int ret ;
unsigned int chunkCnt ;
/*
Format : First byte must be 0x02 ( status check ) or 0x28 ( read
back block of 32 bit words ) . Next 6 bytes must be zero ,
2007-01-28 18:41:12 +00:00
followed by a single byte of MBOX_BASE + offset for portion to
be read . Returned data is packed set of 32 bits words that
were read .
2006-06-26 23:58:46 +00:00
*/
while ( dlen ) {
chunkCnt = 16 ;
if ( chunkCnt > dlen ) chunkCnt = dlen ;
2007-01-28 18:41:12 +00:00
if ( chunkCnt < 16 ) chunkCnt = 1 ;
2007-01-22 05:17:55 +00:00
hdw - > cmd_buffer [ 0 ] =
2007-01-28 18:41:12 +00:00
( ( chunkCnt = = 1 ) ?
FX2CMD_MEM_READ_DWORD : FX2CMD_MEM_READ_64BYTES ) ;
hdw - > cmd_buffer [ 1 ] = 0 ;
hdw - > cmd_buffer [ 2 ] = 0 ;
hdw - > cmd_buffer [ 3 ] = 0 ;
hdw - > cmd_buffer [ 4 ] = 0 ;
hdw - > cmd_buffer [ 5 ] = ( ( offs > > 16 ) & 0xffu ) ;
hdw - > cmd_buffer [ 6 ] = ( ( offs > > 8 ) & 0xffu ) ;
hdw - > cmd_buffer [ 7 ] = ( offs & 0xffu ) ;
2006-06-26 23:58:46 +00:00
ret = pvr2_send_request ( hdw ,
hdw - > cmd_buffer , 8 ,
2007-01-28 18:41:12 +00:00
hdw - > cmd_buffer ,
( chunkCnt = = 1 ? 4 : 16 * 4 ) ) ;
2006-06-26 23:58:46 +00:00
if ( ret ) return ret ;
for ( idx = 0 ; idx < chunkCnt ; idx + + ) {
data [ idx ] = PVR2_COMPOSE_LE ( hdw - > cmd_buffer , idx * 4 ) ;
}
data + = chunkCnt ;
dlen - = chunkCnt ;
offs + = chunkCnt ;
}
return 0 ;
}
2006-06-25 23:04:06 +00:00
/* This prototype is set up to be compatible with the
cx2341x_mbox_func prototype in cx2341x . h , which should be in
kernels 2.6 .18 or later . We do this so that we can enable
cx2341x . ko to write to our encoder ( by handing it a pointer to this
function ) . For earlier kernels this doesn ' t really matter . */
static int pvr2_encoder_cmd ( void * ctxt ,
2007-12-12 10:04:58 +00:00
u32 cmd ,
2006-06-25 23:04:06 +00:00
int arg_cnt_send ,
int arg_cnt_recv ,
u32 * argp )
2006-06-26 23:58:46 +00:00
{
unsigned int poll_count ;
2007-01-28 18:41:12 +00:00
unsigned int try_count = 0 ;
int retry_flag ;
2006-06-26 23:58:46 +00:00
int ret = 0 ;
unsigned int idx ;
2006-06-25 23:04:06 +00:00
/* These sizes look to be limited by the FX2 firmware implementation */
2006-06-26 23:58:46 +00:00
u32 wrData [ 16 ] ;
2006-06-25 23:04:06 +00:00
u32 rdData [ 16 ] ;
struct pvr2_hdw * hdw = ( struct pvr2_hdw * ) ctxt ;
2006-06-26 23:58:46 +00:00
2006-06-25 23:04:25 +00:00
2006-06-26 23:58:46 +00:00
/*
The encoder seems to speak entirely using blocks 32 bit words .
2007-01-28 18:41:12 +00:00
In ivtv driver terms , this is a mailbox at MBOX_BASE which we
populate with data and watch what the hardware does with it .
The first word is a set of flags used to control the
transaction , the second word is the command to execute , the
third byte is zero ( ivtv driver suggests that this is some
kind of return value ) , and the fourth byte is a specified
timeout ( windows driver always uses 0x00060000 except for one
case when it is zero ) . All successive words are the argument
words for the command .
2006-06-26 23:58:46 +00:00
First , write out the entire set of words , with the first word
being zero .
Next , write out just the first word again , but set it to
IVTV_MBOX_DRIVER_DONE | IVTV_DRIVER_BUSY this time ( which
probably means " go " ) .
2007-01-28 18:41:12 +00:00
Next , read back the return count words . Check the first word ,
2006-06-26 23:58:46 +00:00
which should have IVTV_MBOX_FIRMWARE_DONE set . If however
that bit is not set , then the command isn ' t done so repeat the
2007-01-28 18:41:12 +00:00
read until it is set .
2006-06-26 23:58:46 +00:00
Finally , write out just the first word again , but set it to
0x0 this time ( which probably means " idle " ) .
*/
2007-01-20 03:35:03 +00:00
if ( arg_cnt_send > ( ARRAY_SIZE ( wrData ) - 4 ) ) {
2006-06-25 23:04:06 +00:00
pvr2_trace (
PVR2_TRACE_ERROR_LEGS ,
[media] pvrusb2: 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-18 19:44:18 +00:00
" Failed to write cx23416 command - too many input arguments (was given %u limit %lu) " ,
2007-01-22 01:02:35 +00:00
arg_cnt_send , ( long unsigned ) ARRAY_SIZE ( wrData ) - 4 ) ;
2006-06-25 23:04:06 +00:00
return - EINVAL ;
}
2007-01-20 03:35:03 +00:00
if ( arg_cnt_recv > ( ARRAY_SIZE ( rdData ) - 4 ) ) {
2006-06-25 23:04:06 +00:00
pvr2_trace (
PVR2_TRACE_ERROR_LEGS ,
[media] pvrusb2: 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-18 19:44:18 +00:00
" Failed to write cx23416 command - too many return arguments (was given %u limit %lu) " ,
2007-01-22 01:02:35 +00:00
arg_cnt_recv , ( long unsigned ) ARRAY_SIZE ( rdData ) - 4 ) ;
2006-06-25 23:04:06 +00:00
return - EINVAL ;
}
2006-06-26 23:58:46 +00:00
LOCK_TAKE ( hdw - > ctl_lock ) ; do {
2007-11-26 04:48:52 +00:00
if ( ! hdw - > state_encoder_ok ) {
2007-10-14 21:18:12 +00:00
ret = - EIO ;
break ;
}
2007-01-28 18:41:12 +00:00
retry_flag = 0 ;
try_count + + ;
ret = 0 ;
2006-06-26 23:58:46 +00:00
wrData [ 0 ] = 0 ;
wrData [ 1 ] = cmd ;
wrData [ 2 ] = 0 ;
wrData [ 3 ] = 0x00060000 ;
2006-06-25 23:04:06 +00:00
for ( idx = 0 ; idx < arg_cnt_send ; idx + + ) {
wrData [ idx + 4 ] = argp [ idx ] ;
2006-06-26 23:58:46 +00:00
}
2007-01-20 03:35:03 +00:00
for ( ; idx < ARRAY_SIZE ( wrData ) - 4 ; idx + + ) {
2006-06-25 23:04:06 +00:00
wrData [ idx + 4 ] = 0 ;
2006-06-26 23:58:46 +00:00
}
2007-01-28 18:41:12 +00:00
ret = pvr2_encoder_write_words ( hdw , MBOX_BASE , wrData , idx ) ;
2006-06-26 23:58:46 +00:00
if ( ret ) break ;
wrData [ 0 ] = IVTV_MBOX_DRIVER_DONE | IVTV_MBOX_DRIVER_BUSY ;
2007-01-28 18:41:12 +00:00
ret = pvr2_encoder_write_words ( hdw , MBOX_BASE , wrData , 1 ) ;
2006-06-26 23:58:46 +00:00
if ( ret ) break ;
poll_count = 0 ;
while ( 1 ) {
2007-01-28 18:41:12 +00:00
poll_count + + ;
ret = pvr2_encoder_read_words ( hdw , MBOX_BASE , rdData ,
arg_cnt_recv + 4 ) ;
if ( ret ) {
break ;
}
2006-06-26 23:58:46 +00:00
if ( rdData [ 0 ] & IVTV_MBOX_FIRMWARE_DONE ) {
break ;
}
2007-01-28 18:41:12 +00:00
if ( rdData [ 0 ] & & ( poll_count < 1000 ) ) continue ;
if ( ! rdData [ 0 ] ) {
retry_flag = ! 0 ;
pvr2_trace (
PVR2_TRACE_ERROR_LEGS ,
[media] pvrusb2: 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-18 19:44:18 +00:00
" Encoder timed out waiting for us; arranging to retry " ) ;
2007-01-28 18:41:12 +00:00
} else {
2006-06-26 23:58:46 +00:00
pvr2_trace (
PVR2_TRACE_ERROR_LEGS ,
[media] pvrusb2: 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-18 19:44:18 +00:00
" ***WARNING*** device's encoder appears to be stuck (status=0x%08x) " ,
rdData [ 0 ] ) ;
2007-01-28 18:41:12 +00:00
}
pvr2_trace (
PVR2_TRACE_ERROR_LEGS ,
" Encoder command: 0x%02x " , cmd ) ;
for ( idx = 4 ; idx < arg_cnt_send ; idx + + ) {
2006-06-26 23:58:46 +00:00
pvr2_trace (
PVR2_TRACE_ERROR_LEGS ,
2007-01-28 18:41:12 +00:00
" Encoder arg%d: 0x%08x " ,
idx - 3 , wrData [ idx ] ) ;
2006-06-26 23:58:46 +00:00
}
2007-01-28 18:41:12 +00:00
ret = - EBUSY ;
break ;
}
if ( retry_flag ) {
if ( try_count < 20 ) continue ;
pvr2_trace (
PVR2_TRACE_ERROR_LEGS ,
" Too many retries... " ) ;
ret = - EBUSY ;
}
if ( ret ) {
2008-04-06 07:04:35 +00:00
del_timer_sync ( & hdw - > encoder_run_timer ) ;
2007-11-26 04:48:52 +00:00
hdw - > state_encoder_ok = 0 ;
pvr2_trace ( PVR2_TRACE_STBITS ,
" State bit %s <-- %s " ,
" state_encoder_ok " ,
( hdw - > state_encoder_ok ? " true " : " false " ) ) ;
2008-04-06 07:04:35 +00:00
if ( hdw - > state_encoder_runok ) {
hdw - > state_encoder_runok = 0 ;
pvr2_trace ( PVR2_TRACE_STBITS ,
" State bit %s <-- %s " ,
" state_encoder_runok " ,
( hdw - > state_encoder_runok ?
" true " : " false " ) ) ;
}
2007-01-28 18:41:12 +00:00
pvr2_trace (
PVR2_TRACE_ERROR_LEGS ,
[media] pvrusb2: 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-18 19:44:18 +00:00
" Giving up on command. This is normally recovered via a firmware reload and re-initialization; concern is only warranted if this happens repeatedly and rapidly. " ) ;
2007-01-28 18:41:12 +00:00
break ;
2006-06-26 23:58:46 +00:00
}
wrData [ 0 ] = 0x7 ;
2006-06-25 23:04:06 +00:00
for ( idx = 0 ; idx < arg_cnt_recv ; idx + + ) {
argp [ idx ] = rdData [ idx + 4 ] ;
2006-06-26 23:58:46 +00:00
}
wrData [ 0 ] = 0x0 ;
2007-01-28 18:41:12 +00:00
ret = pvr2_encoder_write_words ( hdw , MBOX_BASE , wrData , 1 ) ;
2006-06-26 23:58:46 +00:00
if ( ret ) break ;
} while ( 0 ) ; LOCK_GIVE ( hdw - > ctl_lock ) ;
return ret ;
}
2006-06-25 23:04:06 +00:00
static int pvr2_encoder_vcmd ( struct pvr2_hdw * hdw , int cmd ,
int args , . . . )
{
va_list vl ;
unsigned int idx ;
u32 data [ 12 ] ;
2007-01-20 03:35:03 +00:00
if ( args > ARRAY_SIZE ( data ) ) {
2006-06-25 23:04:06 +00:00
pvr2_trace (
PVR2_TRACE_ERROR_LEGS ,
[media] pvrusb2: 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-18 19:44:18 +00:00
" Failed to write cx23416 command - too many arguments (was given %u limit %lu) " ,
2007-01-22 01:02:35 +00:00
args , ( long unsigned ) ARRAY_SIZE ( data ) ) ;
2006-06-25 23:04:06 +00:00
return - EINVAL ;
}
va_start ( vl , args ) ;
for ( idx = 0 ; idx < args ; idx + + ) {
data [ idx ] = va_arg ( vl , u32 ) ;
}
va_end ( vl ) ;
return pvr2_encoder_cmd ( hdw , cmd , args , 0 , data ) ;
}
2007-01-28 18:42:56 +00:00
/* This implements some extra setup for the encoder that seems to be
specific to the PVR USB2 hardware . */
2007-04-27 15:31:05 +00:00
static int pvr2_encoder_prep_config ( struct pvr2_hdw * hdw )
2007-01-28 18:42:56 +00:00
{
int ret = 0 ;
int encMisc3Arg = 0 ;
#if 0
2009-03-19 22:00:35 +00:00
/* This inexplicable bit happens in the Hauppauge windows
2007-01-28 18:42:56 +00:00
driver ( for both 24 xxx and 29 xxx devices ) . However I
currently see no difference in behavior with or without
this stuff . Leave this here as a note of its existence ,
but don ' t use it . */
LOCK_TAKE ( hdw - > ctl_lock ) ; do {
u32 dat [ 1 ] ;
dat [ 0 ] = 0x80000640 ;
pvr2_encoder_write_words ( hdw , 0x01fe , dat , 1 ) ;
pvr2_encoder_write_words ( hdw , 0x023e , dat , 1 ) ;
} while ( 0 ) ; LOCK_GIVE ( hdw - > ctl_lock ) ;
# endif
/* Mike Isely <isely@pobox.com> 26-Jan-2006 The windows driver
sends the following list of ENC_MISC commands ( for both
24 xxx and 29 xxx devices ) . Meanings are not entirely clear ,
however without the ENC_MISC ( 3 , 1 ) command then we risk
random perpetual video corruption whenever the video input
breaks up for a moment ( like when switching channels ) . */
#if 0
/* This ENC_MISC(5,0) command seems to hurt 29xxx sync
performance on channel changes , but is not a problem on
24 xxx devices . */
ret | = pvr2_encoder_vcmd ( hdw , CX2341X_ENC_MISC , 4 , 5 , 0 , 0 , 0 ) ;
# endif
/* This ENC_MISC(3,encMisc3Arg) command is critical - without
it there will eventually be video corruption . Also , the
2007-11-26 04:53:12 +00:00
saa7115 case is strange - the Windows driver is passing 1
regardless of device type but if we have 1 for saa7115
devices the video turns sluggish . */
if ( hdw - > hdw_desc - > flag_has_cx25840 ) {
encMisc3Arg = 1 ;
} else {
encMisc3Arg = 0 ;
2007-01-28 18:42:56 +00:00
}
ret | = pvr2_encoder_vcmd ( hdw , CX2341X_ENC_MISC , 4 , 3 ,
encMisc3Arg , 0 , 0 ) ;
ret | = pvr2_encoder_vcmd ( hdw , CX2341X_ENC_MISC , 4 , 8 , 0 , 0 , 0 ) ;
#if 0
/* This ENC_MISC(4,1) command is poisonous, so it is commented
out . But I ' m leaving it here anyway to document its
existence in the Windows driver . The effect of this
command is that apps displaying the stream become sluggish
with stuttering video . */
ret | = pvr2_encoder_vcmd ( hdw , CX2341X_ENC_MISC , 4 , 4 , 1 , 0 , 0 ) ;
# endif
ret | = pvr2_encoder_vcmd ( hdw , CX2341X_ENC_MISC , 4 , 0 , 3 , 0 , 0 ) ;
ret | = pvr2_encoder_vcmd ( hdw , CX2341X_ENC_MISC , 4 , 15 , 0 , 0 , 0 ) ;
2008-10-19 20:00:30 +00:00
/* prevent the PTSs from slowly drifting away in the generated
MPEG stream */
ret | = pvr2_encoder_vcmd ( hdw , CX2341X_ENC_MISC , 2 , 4 , 1 ) ;
2007-01-28 18:42:56 +00:00
return ret ;
}
2007-11-26 04:48:52 +00:00
int pvr2_encoder_adjust ( struct pvr2_hdw * hdw )
{
int ret ;
ret = cx2341x_update ( hdw , pvr2_encoder_cmd ,
( hdw - > enc_cur_valid ? & hdw - > enc_cur_state : NULL ) ,
& hdw - > enc_ctl_state ) ;
if ( ret ) {
pvr2_trace ( PVR2_TRACE_ERROR_LEGS ,
" Error from cx2341x module code=%d " , ret ) ;
} else {
2012-10-23 18:57:09 +00:00
hdw - > enc_cur_state = hdw - > enc_ctl_state ;
2007-11-26 04:48:52 +00:00
hdw - > enc_cur_valid = ! 0 ;
}
return ret ;
}
2006-06-26 23:58:46 +00:00
int pvr2_encoder_configure ( struct pvr2_hdw * hdw )
{
2006-06-25 23:05:01 +00:00
int ret ;
2007-04-28 23:08:33 +00:00
int val ;
[media] pvrusb2: 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-18 19:44:18 +00:00
pvr2_trace ( PVR2_TRACE_ENCODER , " pvr2_encoder_configure (cx2341x module) " ) ;
2006-06-25 23:05:01 +00:00
hdw - > enc_ctl_state . port = CX2341X_PORT_STREAMING ;
hdw - > enc_ctl_state . width = hdw - > res_hor_val ;
hdw - > enc_ctl_state . height = hdw - > res_ver_val ;
2007-04-28 23:08:33 +00:00
hdw - > enc_ctl_state . is_50hz = ( ( hdw - > std_mask_cur & V4L2_STD_525_60 ) ?
2006-06-25 23:05:01 +00:00
0 : 1 ) ;
2006-06-26 23:58:46 +00:00
2006-06-25 23:05:01 +00:00
ret = 0 ;
2007-01-28 18:42:56 +00:00
ret | = pvr2_encoder_prep_config ( hdw ) ;
2007-04-28 23:08:33 +00:00
/* saa7115: 0xf0 */
val = 0xf0 ;
2007-11-26 04:53:12 +00:00
if ( hdw - > hdw_desc - > flag_has_cx25840 ) {
2007-04-28 23:08:33 +00:00
/* ivtv cx25840: 0x140 */
val = 0x140 ;
}
2006-06-25 23:05:01 +00:00
if ( ! ret ) ret = pvr2_encoder_vcmd (
hdw , CX2341X_ENC_SET_NUM_VSYNC_LINES , 2 ,
2007-04-28 23:08:33 +00:00
val , val ) ;
2006-06-26 23:58:46 +00:00
/* setup firmware to notify us about some events (don't know why...) */
2006-06-25 23:05:01 +00:00
if ( ! ret ) ret = pvr2_encoder_vcmd (
hdw , CX2341X_ENC_SET_EVENT_NOTIFICATION , 4 ,
0 , 0 , 0x10000000 , 0xffffffff ) ;
if ( ! ret ) ret = pvr2_encoder_vcmd (
hdw , CX2341X_ENC_SET_VBI_LINE , 5 ,
0xffffffff , 0 , 0 , 0 , 0 ) ;
if ( ret ) {
pvr2_trace ( PVR2_TRACE_ERROR_LEGS ,
2006-08-30 08:44:31 +00:00
" Failed to configure cx23416 " ) ;
2006-06-25 23:05:01 +00:00
return ret ;
}
2006-06-26 23:58:46 +00:00
2007-11-26 04:48:52 +00:00
ret = pvr2_encoder_adjust ( hdw ) ;
if ( ret ) return ret ;
2006-06-26 23:58:46 +00:00
2007-11-26 04:48:52 +00:00
ret = pvr2_encoder_vcmd (
2006-06-25 23:05:01 +00:00
hdw , CX2341X_ENC_INITIALIZE_INPUT , 0 ) ;
2006-06-26 23:58:46 +00:00
2006-06-25 23:05:01 +00:00
if ( ret ) {
pvr2_trace ( PVR2_TRACE_ERROR_LEGS ,
2006-08-30 08:44:31 +00:00
" Failed to initialize cx23416 video input " ) ;
2006-06-25 23:05:01 +00:00
return ret ;
2006-06-26 23:58:46 +00:00
}
2006-06-25 23:05:01 +00:00
return 0 ;
2006-06-26 23:58:46 +00:00
}
2006-06-25 23:05:01 +00:00
2006-06-26 23:58:46 +00:00
int pvr2_encoder_start ( struct pvr2_hdw * hdw )
{
int status ;
/* unmask some interrupts */
pvr2_write_register ( hdw , 0x0048 , 0xbfffffff ) ;
2006-12-28 02:05:19 +00:00
pvr2_encoder_vcmd ( hdw , CX2341X_ENC_MUTE_VIDEO , 1 ,
hdw - > input_val = = PVR2_CVAL_INPUT_RADIO ? 1 : 0 ) ;
2007-11-26 04:48:52 +00:00
switch ( hdw - > active_stream_type ) {
2006-12-30 21:27:32 +00:00
case pvr2_config_vbi :
2006-06-25 23:04:06 +00:00
status = pvr2_encoder_vcmd ( hdw , CX2341X_ENC_START_CAPTURE , 2 ,
0x01 , 0x14 ) ;
2006-12-30 21:27:32 +00:00
break ;
case pvr2_config_mpeg :
2006-06-25 23:04:06 +00:00
status = pvr2_encoder_vcmd ( hdw , CX2341X_ENC_START_CAPTURE , 2 ,
0 , 0x13 ) ;
2006-12-30 21:27:32 +00:00
break ;
default : /* Unhandled cases for now */
2006-06-25 23:04:06 +00:00
status = pvr2_encoder_vcmd ( hdw , CX2341X_ENC_START_CAPTURE , 2 ,
0 , 0x13 ) ;
2006-12-30 21:27:32 +00:00
break ;
2006-06-26 23:58:46 +00:00
}
return status ;
}
int pvr2_encoder_stop ( struct pvr2_hdw * hdw )
{
int status ;
/* mask all interrupts */
pvr2_write_register ( hdw , 0x0048 , 0xffffffff ) ;
2007-11-26 04:48:52 +00:00
switch ( hdw - > active_stream_type ) {
2006-12-30 21:27:32 +00:00
case pvr2_config_vbi :
2006-06-25 23:04:06 +00:00
status = pvr2_encoder_vcmd ( hdw , CX2341X_ENC_STOP_CAPTURE , 3 ,
0x01 , 0x01 , 0x14 ) ;
2006-12-30 21:27:32 +00:00
break ;
case pvr2_config_mpeg :
2006-06-25 23:04:06 +00:00
status = pvr2_encoder_vcmd ( hdw , CX2341X_ENC_STOP_CAPTURE , 3 ,
0x01 , 0 , 0x13 ) ;
2006-12-30 21:27:32 +00:00
break ;
default : /* Unhandled cases for now */
2006-06-25 23:04:06 +00:00
status = pvr2_encoder_vcmd ( hdw , CX2341X_ENC_STOP_CAPTURE , 3 ,
0x01 , 0 , 0x13 ) ;
2006-12-30 21:27:32 +00:00
break ;
2006-06-26 23:58:46 +00:00
}
return status ;
}