Mailing List archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[linux-dvb] [PATCH] [dvb] various delay fixes; ddelay() removal
This was inspired by the recent dvb-kernel changes containing broken
delay code -- it tries to clean things up a bit.
Removes several (incompatible) ddelay() implementations and
provides a common dvb_delay() helper instead.
Ensures a minimal timeout of one jiffy (previously a "ddelay(9)"
would mean basically a "schedule_timeout(0)")
Compiled, up and running as of right now (2.4.20-rc1,SMP,HZ==1024).
I hope the delays will work out OK on a HZ==100 box, but haven't
tested it on one...
artur
diff -urNp DVB/driver/av7110/av7110.c DVB-ns/driver/av7110/av7110.c
--- DVB/driver/av7110/av7110.c 2003-04-29 17:50:11.000000000 +0000
+++ DVB-ns/driver/av7110/av7110.c 2003-04-30 20:11:57.000000000 +0000
@@ -76,6 +76,7 @@
#include "dvb_i2c.h"
#include "dvb_frontend.h"
+#include "dvb_functions.h"
#include "compat.h"
#include "av7110.h"
@@ -115,12 +116,6 @@ static int hw_sections = 1;
* General helper functions
****************************************************************************/
-static inline void ddelay(int i)
-{
- current->state=TASK_INTERRUPTIBLE;
- schedule_timeout((HZ*i)/100);
-}
-
static inline int
msp_writereg(av7110_t *av7110, u8 dev, u16 reg, u16 val)
{
@@ -348,7 +343,7 @@ recover_arm(av7110_t *av7110)
printk("OOPS, no current->files\n");
reset_arm(av7110);
}
- ddelay(10);
+ dvb_delay(100);
restart_feeds(av7110);
outcom(av7110, COMTYPE_PIDFILTER, SetIR, 1, av7110->ir_config);
}
@@ -1422,7 +1417,7 @@ static int OutCommand(av7110_t *av7110,
start = jiffies;
while ( rdebi(av7110, DEBINOSWAP, COMMAND, 0, 2 ) )
{
- ddelay(1);
+ dvb_delay(1);
if ((jiffies - start) > ARM_WAIT_FREE) {
printk(KERN_ERR "%s: timeout waiting for COMMAND idle\n", __FUNCTION__);
return -1;
@@ -1433,7 +1428,7 @@ static int OutCommand(av7110_t *av7110,
start = jiffies;
while ( rdebi(av7110, DEBINOSWAP, HANDSHAKE_REG, 0, 2 ) )
{
- ddelay(1);
+ dvb_delay(1);
if ((jiffies - start) > ARM_WAIT_SHAKE) {
printk(KERN_ERR "%s: timeout waiting for HANDSHAKE_REG\n", __FUNCTION__);
return -1;
@@ -1444,7 +1439,7 @@ static int OutCommand(av7110_t *av7110,
start = jiffies;
while ( rdebi(av7110, DEBINOSWAP, MSGSTATE, 0, 2) & OSDQFull )
{
- ddelay(1);
+ dvb_delay(1);
if ((jiffies - start) > ARM_WAIT_OSD)
{
printk(KERN_ERR "%s: timeout waiting for !OSDQFull\n", __FUNCTION__);
@@ -1465,7 +1460,7 @@ static int OutCommand(av7110_t *av7110,
start = jiffies;
while ( rdebi(av7110, DEBINOSWAP, COMMAND, 0, 2 ) )
{
- ddelay(1);
+ dvb_delay(1);
if ((jiffies - start) > ARM_WAIT_FREE) {
printk(KERN_ERR "%s: timeout waiting for COMMAND to complete\n", __FUNCTION__);
return -1;
@@ -1574,7 +1569,7 @@ static int CommandRequest(av7110_t *av71
while ( rdebi(av7110, DEBINOSWAP, COMMAND, 0, 2) )
{
#ifdef _NOHANDSHAKE
- ddelay(1);
+ dvb_delay(1);
#endif
if ((jiffies - start) > ARM_WAIT_FREE) {
printk("%s: timeout waiting for COMMAND to complete\n", __FUNCTION__);
@@ -1586,7 +1581,7 @@ static int CommandRequest(av7110_t *av71
#ifndef _NOHANDSHAKE
start = jiffies;
while ( rdebi(av7110, DEBINOSWAP, HANDSHAKE_REG, 0, 2 ) ) {
- ddelay(1);
+ dvb_delay(1);
if ((jiffies - start) > ARM_WAIT_SHAKE) {
printk(KERN_ERR "%s: timeout waiting for HANDSHAKE_REG\n", __FUNCTION__);
up(&av7110->dcomlock);
@@ -1739,7 +1734,7 @@ static int FlushText(av7110_t *av7110)
return -ERESTARTSYS;
start = jiffies;
while ( rdebi(av7110, DEBINOSWAP, BUFF1_BASE, 0, 2 ) ) {
- ddelay(1);
+ dvb_delay(1);
if ((jiffies - start) > ARM_WAIT_OSD) {
printk(KERN_ERR "%s: timeout waiting for BUFF1_BASE == 0\n", __FUNCTION__);
up(&av7110->dcomlock);
@@ -1762,7 +1757,7 @@ static int WriteText(av7110_t *av7110, u
start = jiffies;
while ( rdebi(av7110, DEBINOSWAP, BUFF1_BASE, 0, 2 ) ) {
- ddelay(1);
+ dvb_delay(1);
if ((jiffies - start) > ARM_WAIT_OSD) {
printk(KERN_ERR "%s: timeout waiting for BUFF1_BASE == 0\n", __FUNCTION__);
up(&av7110->dcomlock);
@@ -1772,7 +1767,7 @@ static int WriteText(av7110_t *av7110, u
#ifndef _NOHANDSHAKE
start = jiffies;
while ( rdebi(av7110, DEBINOSWAP, HANDSHAKE_REG, 0, 2 ) ) {
- ddelay(1);
+ dvb_delay(1);
if ((jiffies - start) > ARM_WAIT_SHAKE) {
printk(KERN_ERR "%s: timeout waiting for HANDSHAKE_REG\n", __FUNCTION__);
up(&av7110->dcomlock);
@@ -2301,8 +2296,7 @@ bootarm(av7110_t *av7110)
wait_for_debi_done(av7110);
setgpio(av7110, RESET_LINE, GPIO_OUTHI);
- current->state=TASK_INTERRUPTIBLE;
- schedule_timeout(HZ);
+ dvb_delay(1000);
dprintk("bootarm: load dram code\n");
@@ -2501,7 +2495,7 @@ SendDiSEqCMsg(av7110_t *av7110, int len,
setgpio(av7110, 3, GPIO_OUTLO);
}
- ddelay(2);
+ dvb_delay(2);
}
break;
@@ -4968,7 +4962,7 @@ int av7110_attach (struct saa7146 *saa,
printk("av7110: DVB-C analog module detected, "
"initializing MSP3400\n");
av7110->adac_type = DVB_ADAC_MSP;
- ddelay(10);
+ dvb_delay(100);
msp_writereg(av7110, 0x12, 0x0013, 0x0c00);
msp_writereg(av7110, 0x12, 0x0000, 0x7f00); // loudspeaker + headphone
msp_writereg(av7110, 0x12, 0x0008, 0x0220); // loudspeaker source
@@ -5007,7 +5001,7 @@ int av7110_detach (struct saa7146 *saa,
wake_up_interruptible(&av7110->arm_wait);
while (av7110->arm_thread)
- ddelay(1);
+ dvb_delay(1);
dvb_unregister(av7110);
Binary files DVB/driver/av7110/fdump and DVB-ns/driver/av7110/fdump differ
diff -urNp DVB/driver/dvb_frontend.c DVB-ns/driver/dvb_frontend.c
--- DVB/driver/dvb_frontend.c 2003-02-20 19:21:09.000000000 +0000
+++ DVB-ns/driver/dvb_frontend.c 2003-04-30 20:13:50.000000000 +0000
@@ -33,6 +33,7 @@
#include "compat.h"
#include "dvb_frontend.h"
#include "dvbdev.h"
+#include "dvb_functions.h"
static int dvb_frontend_debug = 0;
@@ -100,14 +101,6 @@ static DECLARE_MUTEX(frontend_mutex);
static
-inline void ddelay (int ms)
-{
- current->state=TASK_INTERRUPTIBLE;
- schedule_timeout((HZ*ms)/1000);
-}
-
-
-static
int dvb_frontend_internal_ioctl (struct dvb_frontend *frontend,
unsigned int cmd, void *arg)
{
@@ -200,7 +193,7 @@ void dvb_call_frontend_notifiers (struct
fe->lost_sync_jiffies = jiffies;
if (((s ^ fe->status) & FE_HAS_LOCK) && (s & FE_HAS_LOCK))
- ddelay (fe->info->notifier_delay);
+ dvb_delay (fe->info->notifier_delay);
fe->status = s;
@@ -509,8 +502,7 @@ void dvb_frontend_stop (struct dvb_front
while (fe->thread) {
fe->exit = 1;
wake_up_interruptible (&fe->wait_queue);
- current->state = TASK_INTERRUPTIBLE;
- schedule_timeout (5);
+ dvb_delay(50);
};
}
diff -urNp DVB/driver/dvb_functions.h DVB-ns/driver/dvb_functions.h
--- DVB/driver/dvb_functions.h 1970-01-01 00:00:00.000000000 +0000
+++ DVB-ns/driver/dvb_functions.h 2003-04-30 21:50:10.000000000 +0000
@@ -0,0 +1,25 @@
+#ifndef __DVB_FUNCTIONS_H__
+#define __DVB_FUNCTIONS_H__
+
+/*
+ * a sleeping delay function, waits ms milliseconds.
+ *
+ * Note: the minimal delay is one jiffy (usually at most 10ms);
+ * if you really need shorter delays this function could be
+ * extended, but this needs careful consideration.
+ */
+
+static inline void dvb_delay(int ms)
+{
+ long timeout = (HZ*ms)/1000;
+
+ if (timeout==0)
+ timeout = 1;
+ do {
+ set_task_state(current,TASK_INTERRUPTIBLE);
+ timeout = schedule_timeout(timeout);
+ }
+ while (timeout!=0);
+}
+
+#endif
diff -urNp DVB/driver/frontends/alps_tdmb7.c DVB-ns/driver/frontends/alps_tdmb7.c
--- DVB/driver/frontends/alps_tdmb7.c 2002-11-19 01:52:25.000000000 +0000
+++ DVB-ns/driver/frontends/alps_tdmb7.c 2003-04-30 20:18:41.000000000 +0000
@@ -25,6 +25,7 @@
#include "compat.h"
#include "dvb_frontend.h"
+#include "dvb_functions.h"
static int debug = 0;
@@ -53,14 +54,6 @@ struct dvb_frontend_info tdmb7_info = {
static
-inline void ddelay (int timeout)
-{
- current->state=TASK_INTERRUPTIBLE;
- schedule_timeout(timeout);
-}
-
-
-static
u8 init_tab [] = {
0x04, 0x10,
0x05, 0x09,
@@ -171,7 +164,7 @@ int cx22700_init (struct dvb_i2c_bus *i2
cx22700_writereg (i2c, 0x00, 0x02); /* soft reset */
cx22700_writereg (i2c, 0x00, 0x00);
- ddelay (HZ/100);
+ dvb_delay (10);
for (i=0; i<sizeof(init_tab); i+=2)
cx22700_writereg (i2c, init_tab[i], init_tab[i+1]);
diff -urNp DVB/driver/frontends/grundig_29504-491.c DVB-ns/driver/frontends/grundig_29504-491.c
--- DVB/driver/frontends/grundig_29504-491.c 2002-11-19 01:52:29.000000000 +0000
+++ DVB-ns/driver/frontends/grundig_29504-491.c 2003-04-30 20:24:33.000000000 +0000
@@ -246,7 +246,7 @@ void tda8083_wait_diseqc_fifo (struct dv
!(tda8083_readreg(i2c, 0x02) & 0x80))
{
current->state = TASK_INTERRUPTIBLE;
- schedule_timeout (5);
+ schedule_timeout (HZ/20);
};
}
diff -urNp DVB/driver/frontends/stv0299.c DVB-ns/driver/frontends/stv0299.c
--- DVB/driver/frontends/stv0299.c 2003-04-25 18:36:17.000000000 +0000
+++ DVB-ns/driver/frontends/stv0299.c 2003-04-30 20:20:22.000000000 +0000
@@ -42,20 +42,13 @@
#include <linux/string.h>
#include "dvb_frontend.h"
+#include "dvb_functions.h"
#include "compat.h"
static int debug = 0;
#define dprintk if (debug) printk
-static
-inline void ddelay(int i)
-{
- current->state=TASK_INTERRUPTIBLE;
- schedule_timeout((HZ*i)/1000);
-}
-
-
/* frontend types */
#define UNKNOWN_FRONTEND -1
#define PHILIPS_SU1278SH 0
@@ -442,7 +435,7 @@ int stv0299_wait_diseqc_fifo (struct dvb
dprintk ("%s: timeout!!\n", __FUNCTION__);
return -ETIMEDOUT;
}
- ddelay(10);
+ dvb_delay(10);
};
return 0;
@@ -461,7 +454,7 @@ int stv0299_wait_diseqc_idle (struct dvb
dprintk ("%s: timeout!!\n", __FUNCTION__);
return -ETIMEDOUT;
}
- ddelay(10);
+ dvb_delay(10);
};
return 0;
diff -urNp DVB/driver/frontends/ves1820.c DVB-ns/driver/frontends/ves1820.c
--- DVB/driver/frontends/ves1820.c 2003-03-12 17:54:36.000000000 +0000
+++ DVB-ns/driver/frontends/ves1820.c 2003-04-30 20:16:38.000000000 +0000
@@ -25,6 +25,7 @@
#include "compat.h"
#include "dvb_frontend.h"
+#include "dvb_functions.h"
#if 0
@@ -65,14 +66,6 @@
#define GET_DEMOD_ADDR(data) ((u8) (((int) data >> 24) & 0xff))
-static inline
-void ddelay (int ms)
-{
- current->state=TASK_INTERRUPTIBLE;
- schedule_timeout((HZ*ms)/1000);
-}
-
-
static
struct dvb_frontend_info ves1820_info = {
.name = "VES1820 based DVB-C frontend",
@@ -210,7 +203,7 @@ int ves1820_setup_reg0 (struct dvb_front
* check lock and toggle inversion bit if required...
*/
if (!(ves1820_readreg (fe, 0x11) & 0x08)) {
- ddelay(1);
+ dvb_delay(1);
if (!(ves1820_readreg (fe, 0x11) & 0x08)) {
reg0 ^= 0x20;
ves1820_writereg (fe, 0x00, reg0 & 0xfe);
Home |
Main Index |
Thread Index