Commit 84d2d7f2 authored by Henrik Rydberg's avatar Henrik Rydberg Committed by Linus Torvalds

hwmon: applesmc: fix the 'wait status failed: c != 8' problem

On many Macbooks since mid 2007, the Pro, C2D and Air models, applesmc
fails to read some or all SMC ports.  This problem has various effects,
such as flooded logfiles, malfunctioning temperature sensors,
accelerometers failing to initialize, and difficulties getting backlight
functionality to work properly.

The root of the problem seems to be the command protocol.  The current
code sends out a command byte, then repeatedly polls for an ack before
continuing to send or recieve data.  From experiments leading to this
patch, it seems the command protocol never quite worked or changed so that
one now sends a command byte, waits a little bit, polls for an ack, and if
it fails, repeats the whole thing by sending the command byte again.

This patch implements a send_command function according to the new
interpretation of the protocol, and should work also for earlier models.
Signed-off-by: default avatarHenrik Rydberg <rydberg@euromail.se>
Cc: Nicolas Boichat <nicolas@boichat.ch>
Cc: Riki Oktarianto <rkoktarianto@gmail.com>
Cc: Mark M. Hoffman <mhoffman@lightlink.com>
Cc: Jean Delvare <khali@linux-fr.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 05224091
...@@ -190,6 +190,26 @@ static int __wait_status(u8 val) ...@@ -190,6 +190,26 @@ static int __wait_status(u8 val)
return -EIO; return -EIO;
} }
/*
* special treatment of command port - on newer macbooks, it seems necessary
* to resend the command byte before polling the status again. Callers must
* hold applesmc_lock.
*/
static int send_command(u8 cmd)
{
int i;
for (i = 0; i < 1000; i++) {
outb(cmd, APPLESMC_CMD_PORT);
udelay(5);
if ((inb(APPLESMC_CMD_PORT) & APPLESMC_STATUS_MASK) == 0x0c)
return 0;
udelay(5);
}
printk(KERN_WARNING "applesmc: command failed: %x -> %x\n",
cmd, inb(APPLESMC_CMD_PORT));
return -EIO;
}
/* /*
* applesmc_read_key - reads len bytes from a given key, and put them in buffer. * applesmc_read_key - reads len bytes from a given key, and put them in buffer.
* Returns zero on success or a negative error on failure. Callers must * Returns zero on success or a negative error on failure. Callers must
...@@ -205,8 +225,7 @@ static int applesmc_read_key(const char* key, u8* buffer, u8 len) ...@@ -205,8 +225,7 @@ static int applesmc_read_key(const char* key, u8* buffer, u8 len)
return -EINVAL; return -EINVAL;
} }
outb(APPLESMC_READ_CMD, APPLESMC_CMD_PORT); if (send_command(APPLESMC_READ_CMD))
if (__wait_status(0x0c))
return -EIO; return -EIO;
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
...@@ -249,8 +268,7 @@ static int applesmc_write_key(const char* key, u8* buffer, u8 len) ...@@ -249,8 +268,7 @@ static int applesmc_write_key(const char* key, u8* buffer, u8 len)
return -EINVAL; return -EINVAL;
} }
outb(APPLESMC_WRITE_CMD, APPLESMC_CMD_PORT); if (send_command(APPLESMC_WRITE_CMD))
if (__wait_status(0x0c))
return -EIO; return -EIO;
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
...@@ -284,8 +302,7 @@ static int applesmc_get_key_at_index(int index, char* key) ...@@ -284,8 +302,7 @@ static int applesmc_get_key_at_index(int index, char* key)
readkey[2] = index >> 8; readkey[2] = index >> 8;
readkey[3] = index; readkey[3] = index;
outb(APPLESMC_GET_KEY_BY_INDEX_CMD, APPLESMC_CMD_PORT); if (send_command(APPLESMC_GET_KEY_BY_INDEX_CMD))
if (__wait_status(0x0c))
return -EIO; return -EIO;
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
...@@ -315,8 +332,7 @@ static int applesmc_get_key_type(char* key, char* type) ...@@ -315,8 +332,7 @@ static int applesmc_get_key_type(char* key, char* type)
{ {
int i; int i;
outb(APPLESMC_GET_KEY_TYPE_CMD, APPLESMC_CMD_PORT); if (send_command(APPLESMC_GET_KEY_TYPE_CMD))
if (__wait_status(0x0c))
return -EIO; return -EIO;
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment