<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML dir=ltr><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1595" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT size=2>I've seen these problems too. Mark Anderson sent me the
following patch, which introduces delays as you mention.</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>This fixed my CAM access problems I had with
dvb_ca_en50221.c</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>---
drivers/media/dvb/dvb-core/dvb_ca_en50221.c.orig
2007-05-3121:45:21.700049473 +1000<BR>+++
drivers/media/dvb/dvb-core/dvb_ca_en50221.c 2007-06-0123:21:32.596707598
+1000<BR>@@ -721,29 +721,34 @@ static int
dvb_ca_en50221_write_data(str<BR> //
sanity check<BR> if (bytes_write >
ca->slot_info[slot].link_buf_size)<BR>
return
-EINVAL;<BR>-<BR>+msleep(1);<BR> /*
check if interface is actually waiting for us to read fromit, or if a read is in
progress */<BR> if ((status =
ca->pub->read_cam_control(ca->pub, slot,CTRLIF_STATUS)) <
0)<BR>
goto exitnowrite;<BR>+msleep(1);<BR>
if (status & (STATUSREG_DA | STATUSREG_RE))
{<BR>
status =
-EAGAIN;<BR>
goto exitnowrite;<BR>
}<BR>+msleep(1);</FONT></DIV>
<DIV> </DIV><FONT size=2>
<DIV><BR> /* OK, set HC bit
*/<BR> if ((status =
ca->pub->write_cam_control(ca->pub, slot,
CTRLIF_COMMAND,<BR>
IRQEN | CMDREG_HC)) !=
0)<BR>
goto exit;<BR>+msleep(1);</DIV>
<DIV> </DIV>
<DIV> /* check if interface is still
free */<BR> if ((status =
ca->pub->read_cam_control(ca->pub, slot,CTRLIF_STATUS)) <
0)<BR>
goto exit;<BR>+msleep(1);<BR> if
(!(status & STATUSREG_FR))
{<BR>
/* it wasn't free => try again later
*/<BR>
status =
-EAGAIN;<BR>
goto exit;<BR> }<BR>+msleep(1);</DIV>
<DIV> </DIV>
<DIV> /* send the amount of data
*/<BR> if ((status =
ca->pub->write_cam_control(ca->pub, slot,CTRLIF_SIZE_HIGH, bytes_write
>> 8)) != 0)<BR>@@ -752,21 +757,26 @@ static int
dvb_ca_en50221_write_data(str<BR>
bytes_write & 0xff)) !=
0)<BR>
goto exit;</DIV>
<DIV> </DIV>
<DIV>+msleep(1);<BR> /* send the
buffer */<BR> for (i = 0; i <
bytes_write; i++)
{<BR>
if ((status = ca->pub->write_cam_control(ca->pub,slot, CTRLIF_DATA,
buf[i])) !=
0)<BR>
goto exit;<BR> }</DIV>
<DIV> </DIV>
<DIV>+msleep(1);<BR> /* check for
write error (WE should now be 0)
*/<BR> if ((status =
ca->pub->read_cam_control(ca->pub, slot,CTRLIF_STATUS)) <
0)<BR>
goto exit;<BR>+msleep(1);<BR> if
(status & STATUSREG_WE)
{<BR>
ca->slot_info[slot].slot_state =
DVB_CA_SLOTSTATE_LINKINIT;<BR>
status =
-EIO;<BR>
goto exit;<BR>
}<BR>+msleep(1);<BR> status =
bytes_write;<BR>+msleep(1);</DIV>
<DIV> </DIV>
<DIV> dprintk("Wrote CA packet for
slot %i, connection id 0x%xlast_frag:%i size:0x%x\n",
slot,
buf[0], (buf[1] & 0x80) == 0, bytes_write);</DIV>
<DIV> </DIV>
<DIV>--- drivers/media/common/saa7146_i2c.c.orig
2007-05-31<BR>22:17:57.922566547 +1000<BR>+++
drivers/media/common/saa7146_i2c.c 2007-06-01 20:51:56.638799917
+1000<BR>@@ -179,6 +179,7 @@ static int saa7146_i2c_writeout(struct
s<BR> u32 status = 0, mc2 =
0;<BR> int trial =
0;<BR> unsigned long
timeout;<BR>+ int retry;</DIV>
<DIV> </DIV>
<DIV> /* write out i2c-command
*/<BR> DEB_I2C(("before: 0x%08x
(status: 0x%08x),%d\n",*dword,saa7146_read(dev, I2C_STATUS),
dev->i2c_op));<BR>@@ -194,6 +195,9 @@ static int saa7146_i2c_writeout(struct
s<BR>
saa7146_write(dev, MC2, (MASK_00 | MASK_16));</DIV>
<DIV> </DIV>
<DIV>
timeout = HZ/100 + 1; /* 10ms
*/<BR>+
retry =
1000;<BR>+
while (retry-- >
0)<BR>+
{<BR>
timeout = wait_event_interruptible_timeout(dev->i2c_wq, dev->i2c_op ==
0,timeout);<BR>
if (timeout == -ERESTARTSYS || dev->i2c_op)
{<BR>
SAA7146_IER_DISABLE(dev, MASK_16|MASK_17);<BR>@@ -203,10 +207,21 @@ static int
saa7146_i2c_writeout(struct
s<BR>
return -ERESTARTSYS;</DIV>
<DIV> </DIV>
<DIV>
printk(KERN_WARNING "saa7146_i2c_writeout:timed out waiting for end of
xfer\n");<BR>+
msleep(1);<BR>+
}<BR>+
else<BR>+
{<BR>+
break;<BR>+
}<BR>+
}<BR>+
if (retry <=
0)<BR>+
{<BR>
return
-EIO;<BR>
}<BR>
status = saa7146_read(dev, I2C_STATUS);<BR>-
} else {<BR>+
}<BR>+
else<BR>+
{<BR>
saa7146_write(dev, I2C_STATUS,
dev->i2c_bitrate);<BR>
saa7146_write(dev, I2C_TRANSFER,
*dword);<BR>
saa7146_write(dev, MC2, (MASK_00 | MASK_16));<BR>@@ -235,7 +250,7 @@ static int
saa7146_i2c_writeout(struct
s<BR>
/* this is normal when probing the
bus<BR>
* (no answer from nonexisistant
device...)<BR>
*/<BR>-
DEB_I2C(("saa7146_i2c_writeout: timedout waiting for end of
xfer\n"));<BR>+
DEB_I2C(("saa7146_i2c_writeout: timedout waiting for end of
xfer2\n"));<BR>
return
-EIO;<BR>
}<BR>
if (++trial < 50 && short_delay)<BR></DIV>
<DIV> </DIV>
<DIV> </DIV></FONT>
<BLOCKQUOTE
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=akivas@scopus.net href="mailto:akivas@scopus.net">Akiva Sadovski</A>
</DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=linux-dvb@linuxtv.org
href="mailto:linux-dvb@linuxtv.org">linux-dvb@linuxtv.org</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Friday, July 20, 2007 9:01 AM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> Re: [linux-dvb] Problem with
init some CAM blocks on TTBudget-S1500 + CI</DIV>
<DIV><BR></DIV>
<DIV><FONT face=Arial color=#000000 size=2>
<DIV><FONT face=Arial color=#000000 size=2>Evgen, all,</FONT></DIV>
<DIV><FONT face=Arial size=2> I'm only a stupid newbie
in the linuxtv world,</FONT></DIV>
<DIV><FONT face=Arial size=2>but from my experience with CAM cards it seems to
me that Eugen's observation is correct but not precious:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>IMHO, the sequence should be (from the DVB-CI
standard):</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2> 1) "<FONT face="Times New Roman"
size=2>host now tells the module to use this buffer size by writing a ‘1’ to
the SW bit in the Command Register"</FONT></FONT></DIV>
<DIV><FONT size=2> 2) "<FONT face="Times New Roman" size=2>waiting
until the FR bit is set"</FONT></FONT></DIV>
<DIV><FONT size=2> 3) "<FONT face="Times New Roman" size=2>writing
the size as 2 bytes of data, most significant byte
first..."</FONT></FONT></DIV>
<DIV><FONT size=2> 4) "<FONT face="Times New Roman" size=2>At the
end of the transfer the host sets the SW bit to '0'. "</FONT></FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>this is actually what is coded
in dvb_ca_en50221.c, but I GUESS - I HAVEN'T TESTED
IT!!</FONT></DIV>
<DIV><FONT size=2>that the problem is that one have to introduce some delay
between writing the buffer size</FONT></DIV>
<DIV><FONT size=2>and setting the SW bit to zero - since according to the
standard we have to wait until the transfer (and not</FONT></DIV>
<DIV><FONT size=2>simply the write operation) is finished</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2> if ((ret =
dvb_ca_en50221_write_data(ca, slot, buf, 2)) !=
2)<BR>
return -EIO;</FONT></DIV>
<DIV><FONT size=2>/*</FONT></DIV>
<DIV><FONT size=2> WE NEED DELAY HERE ... ?</FONT></DIV>
<DIV><FONT size=2>*/</FONT><BR><FONT
size=2> if ((ret =
ca->pub->write_cam_control(ca->pub, slot, <BR>CTRLIF_COMMAND,
IRQEN)) !=
0)<BR>
return ret;<BR>=======================<BR>Now my question:</FONT></DIV>
<DIV><FONT size=2> I'm writing the DVB-CI driver for customer made HW
developed by the firm I'm working for.</FONT></DIV>
<DIV><FONT size=2> I'm going to use the dvb-core
infrastructure.</FONT></DIV>
<DIV><FONT size=2> Is there any card which driver already uses the
dvb_ca part of the dvb-core ?</FONT></DIV>
<DIV><FONT size=2> </FONT></DIV>
<DIV><FONT size=2> I put an eye on Twinhan 1030 card, but it has the
vendor-specific driver which has nothing in common</FONT></DIV>
<DIV><FONT size=2>with dvb-core</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>Thanks in advance,</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>Akiva Sadovski</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>Scopus Video Networks</FONT></DIV></FONT></DIV>
<P>
<HR>
<P></P>_______________________________________________<BR>linux-dvb mailing
list<BR>linux-dvb@linuxtv.org<BR>http://www.linuxtv.org/cgi-bin/mailman/listinfo/linux-dvb</BLOCKQUOTE></BODY></HTML>