From: Dave Hansen <dave@sr71.net>
To: Jesper Juhl <jesper.juhl@gmail.com>
Cc: Alejandro Bonilla <abonilla@linuxwireless.org>,
Vojtech Pavlik <vojtech@suse.cz>, Pavel Machek <pavel@suse.cz>,
Paul Sladen <thinkpad@paul.sladen.org>,
linux-thinkpad@linux-thinkpad.org,
Eric Piel <Eric.Piel@tremplin-utc.net>,
borislav@users.sourceforge.net,
Yani Ioannou <yani.ioannou@gmail.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
hdaps-devel@lists.sourceforge.net
Subject: Re: [Hdaps-devel] Re: [ltp] IBM HDAPS Someone interested? (Accelerometer)
Date: Sun, 03 Jul 2005 12:21:54 -0700 [thread overview]
Message-ID: <1120418514.4351.6.camel@localhost> (raw)
In-Reply-To: <42C82BBB.9090008@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1106 bytes --]
On Sun, 2005-07-03 at 20:17 +0200, Jesper Juhl wrote:
> Ok, just to show you people what I've done so far.
> This doesn't work yet, but it should be resonably close (at least it
> builds ;)
On top of what you sent at first this morning (not the most recent one)
I did some stuff (in the attached patch). It implements the last bit of
initialization that your earlier one didn't do, but I see you've done in
the most recent one.
Anyway, I get 10 reads out of it, 1 second apart, and it appears to be
getting real data:
10 seconds while tilting my thinkpad around:
x_accel: 372
y_accel: 339
x_accel: 475
y_accel: 396
x_accel: 429
y_accel: 414
x_accel: 441
y_accel: 519
x_accel: 431
y_accel: 525
x_accel: 387
y_accel: 311
x_accel: 389
y_accel: 246
x_accel: 385
y_accel: 266
10 seconds of stationary reads:
x_accel: 368
y_accel: 390
x_accel: 368
y_accel: 391
x_accel: 368
y_accel: 390
x_accel: 369
y_accel: 390
x_accel: 369
y_accel: 391
x_accel: 369
y_accel: 390
x_accel: 370
y_accel: 390
x_accel: 369
y_accel: 392
x_accel: 369
y_accel: 392
x_accel: 368
y_accel: 390
x_accel: 368
y_accel: 391
-- Dave
[-- Attachment #2: accel-0.diff --]
[-- Type: text/x-patch, Size: 4931 bytes --]
--- accelerometer.c.orig 2005-07-03 11:37:07.000000000 -0700
+++ accelerometer.c 2005-07-03 12:16:50.000000000 -0700
@@ -53,17 +53,17 @@
static inline int latch_wait(unsigned char value, unsigned short port)
{
- printk(KERN_DEBUG DRV_NAME ": latch_wait(0x%x, 0x%x)\n", value, port);
-
int status = 0;
int i;
- for (i = 0; i < 10; i++) {
+ printk(KERN_DEBUG DRV_NAME ": latch_wait(0x%x, 0x%x)\n", value, port);
+
+ for (i = 0; i < 100; i++) {
if (latch_check(value, port)) {
status = 1;
break;
}
- udelay(5);
+ udelay(10);
}
return status;
@@ -78,9 +78,9 @@
static inline int refresh(int synchronous)
{
- printk(KERN_DEBUG DRV_NAME ": refresh(%d)\n", synchronous);
-
int status = 0;
+
+ printk(KERN_DEBUG DRV_NAME ": refresh(%d)\n", synchronous);
if (refresh_check()) {
status = 1;
@@ -103,29 +103,54 @@
inb(0x1604);
}
-static int read(void)
-{
- printk(KERN_DEBUG DRV_NAME ": read()\n");
+struct accelerometer_data {
+ unsigned char state;
+ unsigned short x_accel;
+ unsigned short y_accel;
+ unsigned char temperature_a;
+ unsigned short x_variation;
+ unsigned short y_variation;
+ unsigned char temperature_b;
+ unsigned char unknown;
+ unsigned char mk_use;
+} __attribute__ ((packed));
+static int read(int print)
+{
+ int i;
int status = 0;
+ struct accelerometer_data d;
+
+ printk(KERN_DEBUG DRV_NAME ": read()\n");
if (refresh(ACCELEROMETER_SYNC)) {
+ for (i=0; i< sizeof(struct accelerometer_data); i++) {
+ ((unsigned char *)(&d))[i] = inb(0x1611 + i);
+ }
+
/* FIXME: read data from 0x1611 through 0x161E */
read_done();
refresh(ACCELEROMETER_ASYNC);
status = 1;
}
+ if (print) {
+ //for (i=0; i< sizeof(struct accelerometer_data); i++)
+ // printk("data[%2d]: %02x\n", i, ((unsigned char *)(&d))[i]);
+ printk("x_accel: %d\n", d.x_accel);
+ printk("y_accel: %d\n", d.y_accel);
+ }
return status;
}
static int initialize(void)
{
+ int ret = -EIO;
outb(0x13, 0x1610);
outb(0x01, 0x161f);
if (! latch_wait(0x0, 0x161f))
- return -EIO;
+ return ret;
if (! latch_wait(0x3, 0x1611))
return -EIO;
@@ -140,6 +165,7 @@
return -EIO;
if (! latch_wait(0x0, 0x1613))
return -EIO;
+ printk("%s() 5\n", __func__);
outb(0x14, 0x1610);
outb(0x01, 0x1611);
@@ -159,9 +185,57 @@
if (! latch_wait(0x0, 0x1611))
return -EIO;
- /* FIXME: finish init sequence */
+/*
+ * I issue an outb at port 0x1610 of value 0x13,
+ * followed by an outb at port 0x161f of value 0x01.
+ * I then waits for latch 0x161f for value 0x0,
+ * and then wait for latch 0x1611 for value 0x3.
+ *
+ * Three more outbs at ports 0x1610, 0x1611, and 0x161f of values 0x17, 0x81, and 0x01, respectively follow.
+ *
+ * Four more waits for latches 0x161f, 0x1611, 0x1612, and 0x1613 for values 0x0, 0x0, 0x60, and 0x0 respectively.
+ * Then three more outbs at ports 0x1610, 0x1611, and 0x161f of values 0x14, 0x01, and 0x01.
+ *
+ * Then I wait for latch 0x161f for value 0x0.
+ * Then five outbs at ports 0x1610, 0x1611, 0x1612, 0x1613, and 0x161f of values 0x10, 0xc8, 0x00, 0x02, and 0x01
+ *
+ * I then wait for latch 0x161f for value 0x0 again.
+ *
+ * I then issues a synchronous refresh of the accelerometer data, and wait for latch 0x1611 to become 0x0.
+ */
+
+ /*----------------------------------------------
+ * The next part is a little bit tricky because it can take a long time for the accelerometer to complete.
+ * I loop forever until latch 0x1611 becomes 0x02.
+ * Inside this loop, I check the timeout value against the "time waited so far" variable.
+ * If the function has taken too long,
+ * return failure.
+ * else, I call the function which reads the accelerometer data
+ * and I throw away the (probably garbage) data
+ * (this read somehow seems to kick the accelerometer into being initialized).
+ * I set_current_state to TASK_INTERRUPTIBLE, and schedule_timeout for HZ.
+ * I then increment our "seconds waited so far" variable and continue the loop.
+ * If the loop ever exits successfully, the function returns success.
+ * A good value to pass for the initialize timeout value is 10 seconds.
+ *
+ */
+ /* I loop forever until latch 0x1611 becomes 0x02. */ {
+ unsigned long msecs_to_sleep = 10000;
+ unsigned long msecs_per_sleep = 100;
+ unsigned long msecs_slept = 0;
+ while (msecs_slept <= msecs_to_sleep) {
+ if (latch_check(0x2, 0x1611)) {
+ printk("good latch check\n");
+ ret = 0;
+ break;
+ }
+
+ read(0);
+ msleep_interruptible(msecs_per_sleep);
+ msecs_slept += msecs_per_sleep;
+ }}
- return 0;
+ return ret;
}
static int __init accelerometer_init(void)
@@ -180,6 +254,17 @@
}
ret = initialize();
+ printk("initialize() ret: %d\n", ret);
+ if (ret)
+ return ret;
+ read(1);
+ {
+ int i;
+ for (i=0; i<10;i++) {
+ msleep_interruptible(1000);
+ read(1);
+ }
+ }
if (ret != 0) {
printk(KERN_ERR DRV_NAME ": initialization failed\n");
next prev parent reply other threads:[~2005-07-03 19:23 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <42B6F6F6.2040704@zipman.it>
2005-06-20 17:28 ` [ltp] Re: IBM HDAPS Someone interested? Alejandro Bonilla
2005-06-20 19:51 ` Yani Ioannou
2005-06-20 20:11 ` Yani Ioannou
2005-06-20 20:25 ` Alejandro Bonilla
2005-06-20 20:34 ` Yani Ioannou
2005-06-20 20:48 ` Alejandro Bonilla
2005-06-20 21:35 ` Lee Revell
2005-06-20 21:57 ` Alejandro Bonilla
2005-06-20 23:35 ` Lee Revell
2005-06-22 10:49 ` Pavel Machek
2005-06-22 12:50 ` Alejandro Bonilla
2005-06-23 7:13 ` Vojtech Pavlik
2005-06-23 10:06 ` Eric Piel
2005-06-23 12:53 ` Alejandro Bonilla
2005-06-23 13:18 ` Vojtech Pavlik
2005-06-23 20:22 ` Eric Piel
2005-06-23 20:42 ` Lee Revell
2005-06-25 6:17 ` [ltp] IBM HDAPS Someone interested? (Accelerometer) Paul Sladen
2005-06-25 11:31 ` Vojtech Pavlik
2005-06-25 14:47 ` Pavel Machek
2005-06-25 15:00 ` Vojtech Pavlik
2005-06-25 18:14 ` Alejandro Bonilla
2005-06-25 20:14 ` Vojtech Pavlik
2005-06-27 12:33 ` Lenz Grimmer
2005-06-27 13:10 ` Alejandro Bonilla
2005-06-27 21:02 ` Lee Revell
2005-06-28 3:22 ` Alejandro Bonilla
2005-06-28 5:40 ` Lee Revell
2005-06-28 15:40 ` Vojtech Pavlik
2005-06-25 18:13 ` Alejandro Bonilla
2005-06-25 20:09 ` Vojtech Pavlik
2005-06-25 22:41 ` Alejandro Bonilla
2005-06-27 3:35 ` [Hdaps-devel] " Shawn Starr
2005-07-03 8:37 ` Alejandro Bonilla
2005-07-03 10:16 ` Vojtech Pavlik
2005-07-03 11:07 ` Jesper Juhl
2005-07-03 18:17 ` Jesper Juhl
2005-07-03 19:21 ` Dave Hansen [this message]
2005-07-03 18:29 ` [Hdaps-devel] " Alejandro Bonilla
2005-07-03 19:37 ` Dave Hansen
2005-07-03 19:42 ` Jesper Juhl
2005-07-03 18:52 ` Alejandro Bonilla
2005-07-03 19:42 ` Henrik Brix Andersen
2005-07-03 20:03 ` Jesper Juhl
2005-07-03 20:53 ` Tomasz Torcz
2005-07-03 19:41 ` Dave Hansen
2005-07-11 9:42 ` [ltp] IBM HDAPS Someone interested? (Userspace accelerometer viewer) Paul Sladen
2005-07-11 14:26 ` Alan Cox
2005-07-11 16:53 ` [Hdaps-devel] " Dave Hansen
2005-07-11 17:31 ` Paul RIVIER
2005-07-11 20:09 ` [Hdaps-devel] " Daniel Willmann
2005-07-12 15:55 ` Dave Hansen
2005-07-11 15:13 ` Pavel Machek
2005-07-12 9:41 ` Matthew Garrett
2005-07-11 16:21 ` [Hdaps-devel] " Dave Hansen
2005-07-13 16:27 ` Alejandro Bonilla
2005-06-25 17:42 ` [ltp] IBM HDAPS Someone interested? (Accelerometer) Alejandro Bonilla
2005-06-27 10:36 ` P
2005-06-23 15:33 ` [ltp] Re: IBM HDAPS Someone interested? Jan Knutar
2005-06-23 17:08 ` Lee Revell
2005-06-23 20:47 ` Andrew Haninger
2005-06-24 9:16 ` P
2005-06-24 12:56 ` Alejandro Bonilla
2005-06-24 17:20 ` Alejandro Bonilla
2005-06-20 20:53 ` Vojtech Pavlik
[not found] ` <005b01c575bd_724fac60_600cc60a@amer.sykes.com>
2005-06-20 20:25 ` Pavel Machek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1120418514.4351.6.camel@localhost \
--to=dave@sr71.net \
--cc=Eric.Piel@tremplin-utc.net \
--cc=abonilla@linuxwireless.org \
--cc=borislav@users.sourceforge.net \
--cc=hdaps-devel@lists.sourceforge.net \
--cc=jesper.juhl@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-thinkpad@linux-thinkpad.org \
--cc=pavel@suse.cz \
--cc=thinkpad@paul.sladen.org \
--cc=vojtech@suse.cz \
--cc=yani.ioannou@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.