Chris Kennedy <[EMAIL PROTECTED]> wrote:
> Ah, interesting, for now I'm just using the separate one, but looks like
> that's the best way to go eventually, just no write one to go with that
> read and make things consistent (also to plug into the ioctl for the
> external access it's more compatible to the saa7115 this way, sort of,
> now to specify from userspace which subregisters is another problem).
Good point.
Here's a patch with a matching write. Also I named the functions a
more sensible cx25840_(read|write) to match what you have.
--
Tyler Trafford
--- ivtv-0.3.2s/driver/cx25840-driver.c.orig 2005-04-05 14:38:07.000000000 -0400
+++ ivtv-0.3.2s/driver/cx25840-driver.c 2005-04-05 14:55:49.000000000 -0400
@@ -224,24 +224,18 @@
return retval;
}
-static inline int read_reg_byte(struct i2c_client *client, u16 addr)
+static inline int cx25840_write(struct i2c_client *client, u16 addr, u8 value)
{
- u8 buff[2] = { addr >> 8, addr & 0xff };
- int ret;
-
- ret = i2c_master_send(client, buff, 2);
- if (ret != 2) {
- ERR("I2C write failed, length %d, ret %d", 1, ret);
- return -1;
- }
-
- ret = i2c_master_recv(client, buff, 1);
- if (ret != 1) {
- ERR("I2C sequence recv failed, length %d, ret %d", 1, ret);
- return -1;
- }
+ u8 buffer[3] = { addr >> 8, addr & 0xff, value };
+ return i2c_master_send(client, buffer, 3);
+}
- return buff[0];
+static inline u8 cx25840_read(struct i2c_client *client, u16 addr)
+{
+ u8 buffer[2] = { addr >> 8, addr & 0xff };
+ i2c_master_send(client, buffer, 2);
+ i2c_master_recv(client, buffer, 1);
+ return buffer[0];
}
static void update_setting(struct i2c_client *client, u16 setting,
@@ -250,15 +244,15 @@
u16 addr = CX25840_REGISTER_ADDRESS(CX25840_SETTING_REGISTER_INDEX(setting));
int s = CX25840_SETTING_START_BIT(setting);
int l = CX25840_SETTING_BIT_LENGTH(setting);
+ u8 byte, mask;
while (l > 0) {
- u8 buffer[3] = { addr >> 8, addr & 0xff, 0x00 };
- u8 mask = (0xff >> (8 - (l > 8 ? 8 : l))) << s;
+ mask = (0xff >> (8 - (l > 8 ? 8 : l))) << s;
- buffer[2] = read_reg_byte(client, addr++) & ~mask;
- buffer[2] |= (mask & (value << s));
+ byte = cx25840_read(client, addr) & ~mask;
+ byte |= (mask & (value << s));
- i2c_master_send(client, buffer, 3);
+ cx25840_write(client, addr++, byte);
l -= 8 - s;
value >>= (8 - s);
@@ -276,7 +270,7 @@
u32 value = 0;
int i = 0;
while (rl-- > 0)
- value |= read_reg_byte(client, addr++) << (i++ * 8);
+ value |= cx25840_read(client, addr++) << (i++ * 8);
return (value >> s) & (0xffffffff >> (32 - l));
}
@@ -729,7 +723,7 @@
if (CX25840_SETTING_TYPE(i) == RW) {
b = state->reg_cache[ri];
} else {
- b = read_reg_byte(client, addr);
+ b = cx25840_read(client, addr);
}
if (b < 0) {