diff options
author | Jean Delvare <khali@linux-fr.org> | 2007-07-12 08:12:29 -0400 |
---|---|---|
committer | Jean Delvare <khali@hyperion.delvare> | 2007-07-12 08:12:29 -0400 |
commit | 4b2643d7d9bdcd776749e17f73c168ddf02e93cb (patch) | |
tree | 1642900ea1c196cc27d120f0af4de44fff30633e /drivers/macintosh | |
parent | ba7fbb723f50ab2607989a282af655fb0fab0492 (diff) |
i2c: Fix the i2c_smbus_read_i2c_block_data() prototype
Let the drivers specify how many bytes they want to read with
i2c_smbus_read_i2c_block_data(). So far, the block count was
hard-coded to I2C_SMBUS_BLOCK_MAX (32), which did not make much sense.
Many driver authors complained about this before, and I believe it's
about time to fix it. Right now, authors have to do technically stupid
things, such as individual byte reads or full-fledged I2C messaging,
to work around the problem. We do not want to encourage that.
I even found that some bus drivers (e.g. i2c-amd8111) already
implemented I2C block read the "right" way, that is, they didn't
follow the old, broken standard. The fact that it was never noticed
before just shows how little i2c_smbus_read_i2c_block_data() was used,
which isn't that surprising given how broken its prototype was so far.
There are some obvious compatiblity considerations:
* This changes the i2c_smbus_read_i2c_block_data() prototype. Users
outside the kernel tree will notice at compilation time, and will
have to update their code.
* User-space has access to i2c_smbus_xfer() directly using i2c-dev, so
the changed expectations would affect tools such as i2cdump. In order
to preserve binary compatibility, we give I2C_SMBUS_I2C_BLOCK_DATA
a new numeric value, and define I2C_SMBUS_I2C_BLOCK_BROKEN with the
old numeric value. When i2c-dev receives a transaction with the
old value, it can convert it to the new format on the fly.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/macintosh')
-rw-r--r-- | drivers/macintosh/windfarm_smu_sat.c | 28 |
1 files changed, 4 insertions, 24 deletions
diff --git a/drivers/macintosh/windfarm_smu_sat.c b/drivers/macintosh/windfarm_smu_sat.c index 1043b39aa123..351982bcec1b 100644 --- a/drivers/macintosh/windfarm_smu_sat.c +++ b/drivers/macintosh/windfarm_smu_sat.c | |||
@@ -67,26 +67,6 @@ static struct i2c_driver wf_sat_driver = { | |||
67 | .detach_client = wf_sat_detach, | 67 | .detach_client = wf_sat_detach, |
68 | }; | 68 | }; |
69 | 69 | ||
70 | /* | ||
71 | * XXX i2c_smbus_read_i2c_block_data doesn't pass the requested | ||
72 | * length down to the low-level driver, so we use this, which | ||
73 | * works well enough with the SMU i2c driver code... | ||
74 | */ | ||
75 | static int sat_read_block(struct i2c_client *client, u8 command, | ||
76 | u8 *values, int len) | ||
77 | { | ||
78 | union i2c_smbus_data data; | ||
79 | int err; | ||
80 | |||
81 | data.block[0] = len; | ||
82 | err = i2c_smbus_xfer(client->adapter, client->addr, client->flags, | ||
83 | I2C_SMBUS_READ, command, I2C_SMBUS_I2C_BLOCK_DATA, | ||
84 | &data); | ||
85 | if (!err) | ||
86 | memcpy(values, data.block, len); | ||
87 | return err; | ||
88 | } | ||
89 | |||
90 | struct smu_sdbp_header *smu_sat_get_sdb_partition(unsigned int sat_id, int id, | 70 | struct smu_sdbp_header *smu_sat_get_sdb_partition(unsigned int sat_id, int id, |
91 | unsigned int *size) | 71 | unsigned int *size) |
92 | { | 72 | { |
@@ -124,8 +104,8 @@ struct smu_sdbp_header *smu_sat_get_sdb_partition(unsigned int sat_id, int id, | |||
124 | return NULL; | 104 | return NULL; |
125 | 105 | ||
126 | for (i = 0; i < len; i += 4) { | 106 | for (i = 0; i < len; i += 4) { |
127 | err = sat_read_block(&sat->i2c, 0xa, data, 4); | 107 | err = i2c_smbus_read_i2c_block_data(&sat->i2c, 0xa, 4, data); |
128 | if (err) { | 108 | if (err < 0) { |
129 | printk(KERN_ERR "smu_sat_get_sdb_part rd err %d\n", | 109 | printk(KERN_ERR "smu_sat_get_sdb_part rd err %d\n", |
130 | err); | 110 | err); |
131 | goto fail; | 111 | goto fail; |
@@ -157,8 +137,8 @@ static int wf_sat_read_cache(struct wf_sat *sat) | |||
157 | { | 137 | { |
158 | int err; | 138 | int err; |
159 | 139 | ||
160 | err = sat_read_block(&sat->i2c, 0x3f, sat->cache, 16); | 140 | err = i2c_smbus_read_i2c_block_data(&sat->i2c, 0x3f, 16, sat->cache); |
161 | if (err) | 141 | if (err < 0) |
162 | return err; | 142 | return err; |
163 | sat->last_read = jiffies; | 143 | sat->last_read = jiffies; |
164 | #ifdef LOTSA_DEBUG | 144 | #ifdef LOTSA_DEBUG |