--- accelerometer.c-0.1.orig 2005-07-03 12:28:28.000000000 -0700 +++ accelerometer.c 2005-07-03 12:33:39.000000000 -0700 @@ -158,45 +158,49 @@ } /* initialize the accelerometer, wait up to `timeout' seconds for success */ -int accelerometer_init(unsigned int timeout) +int accelerometer_init(unsigned int timeout_secs) { - unsigned long wait_until = jiffies + timeout * HZ; + unsigned long total_wait_msecs = timeout_secs * 1000; + unsinged msec_per_wait = 10; + unsigned long msecs_waited = 0; + int ret = -EIO; outb(0x13, 0x1610); outb(0x01, 0x161f); if (!wait_latch(0x00, 0x161f)) - return -EIO; + return ret; if (!wait_latch(0x03, 0x1611)) - return -EIO; + return ret; outb(0x17, 0x1610); outb(0x81, 0x1611); outb(0x01, 0x161f); if (!wait_latch(0x00, 0x161f)) - return -EIO; + return ret; if (!wait_latch(0x00, 0x1611)) - return -EIO; + return ret; if (!wait_latch(0x60, 0x1612)) - return -EIO; + return ret; if (!wait_latch(0x00, 0x1613)) - return -EIO; + return ret; outb(0x14, 0x1610); outb(0x01, 0x1611); outb(0x01, 0x161f); if (!wait_latch(0x00, 0x161f)) - return -EIO; + return ret; outb(0x10, 0x1610); outb(0xc8, 0x1611); outb(0x00, 0x1612); outb(0x02, 0x1613); outb(0x01, 0x161f); if (!wait_latch(0x00, 0x161f)) - return -EIO; + return ret; if (!request_refresh(REFRESH_SYNC)) - return -EIO; + return ret; if (!wait_latch(0x00, 0x1611)) - return -EIO; + return ret; - while (1) { + ret = -ENXIO; + while (msecs_waited <= total_wait_msecs) { if (wait_latch(0x02, 0x1611)) { struct hdaps_accel_data data; /* @@ -204,15 +208,13 @@ * return success. */ accelerometer_read(&data); - return 0; - } else if (time_before(jiffies, wait_until)) { - set_current_state(TASK_INTERRUPTIBLE); - schedule_timeout(HZ); - } else { - /* we timed out, return failure */ - return -ENXIO; + ret = 0; + break; } + msleep(msecs_per_wait); + msecs_waited += msecs_per_wait; } + return ret; } static int ibm_hdaps_init(void)