diff --git a/kernel/chips/asb100.c b/kernel/chips/asb100.c index 8d3b7ff8..e5eba276 100644 --- a/kernel/chips/asb100.c +++ b/kernel/chips/asb100.c @@ -587,11 +587,6 @@ static int asb100_detach_client(struct i2c_client *client) return 0; } -static u16 swap_bytes(u16 val) -{ - return (val >> 8) | (val << 8); -} - /* The SMBus locks itself, usually, but nothing may access the Winbond between bank switches. ISA access must always be locked explicitly! We ignore the W83781D BUSY flag at this moment - it could lead to deadlocks, @@ -620,17 +615,17 @@ static int asb100_read_value(struct i2c_client *client, u16 reg) /* convert from ISA to LM75 I2C addresses */ switch (reg & 0xff) { case 0x50: /* TEMP */ - res = swap_bytes(i2c_smbus_read_word_data (cl, 0)); + res = swab16(i2c_smbus_read_word_data (cl, 0)); break; case 0x52: /* CONFIG */ res = i2c_smbus_read_byte_data(cl, 1); break; case 0x53: /* HYST */ - res = swap_bytes(i2c_smbus_read_word_data (cl, 2)); + res = swab16(i2c_smbus_read_word_data (cl, 2)); break; case 0x55: /* MAX */ default: - res = swap_bytes(i2c_smbus_read_word_data (cl, 3)); + res = swab16(i2c_smbus_read_word_data (cl, 3)); break; } } @@ -668,10 +663,10 @@ static void asb100_write_value(struct i2c_client *client, u16 reg, u16 value) i2c_smbus_write_byte_data(cl, 1, value & 0xff); break; case 0x53: /* HYST */ - i2c_smbus_write_word_data(cl, 2, swap_bytes(value)); + i2c_smbus_write_word_data(cl, 2, swab16(value)); break; case 0x55: /* MAX */ - i2c_smbus_write_word_data(cl, 3, swap_bytes(value)); + i2c_smbus_write_word_data(cl, 3, swab16(value)); break; } } diff --git a/kernel/chips/ds1621.c b/kernel/chips/ds1621.c index b69cd968..3e86c379 100644 --- a/kernel/chips/ds1621.c +++ b/kernel/chips/ds1621.c @@ -99,7 +99,6 @@ static int ds1621_detect(struct i2c_adapter *adapter, int address, static void ds1621_init_client(struct i2c_client *client); static int ds1621_detach_client(struct i2c_client *client); -static u16 swap_bytes(u16 val); static int ds1621_read_value(struct i2c_client *client, u8 reg); static int ds1621_write_value(struct i2c_client *client, u8 reg, u16 value); static void ds1621_temp(struct i2c_client *client, int operation, @@ -281,11 +280,6 @@ static int ds1621_detach_client(struct i2c_client *client) } -static u16 swap_bytes(u16 val) -{ - return (val >> 8) | (val << 8); -} - /* All registers are word-sized, except for the configuration register. DS1621 uses a high-byte first convention, which is exactly opposite to the usual practice. */ @@ -295,7 +289,7 @@ static int ds1621_read_value(struct i2c_client *client, u8 reg) || (reg == DS1621_REG_TEMP_SLOPE)) return i2c_smbus_read_byte_data(client, reg); else - return swap_bytes(i2c_smbus_read_word_data(client, reg)); + return swab16(i2c_smbus_read_word_data(client, reg)); } /* All registers are word-sized, except for the configuration register. @@ -310,8 +304,7 @@ static int ds1621_write_value(struct i2c_client *client, u8 reg, u16 value) || (reg == DS1621_REG_TEMP_SLOPE)) return i2c_smbus_write_byte_data(client, reg, value); else - return i2c_smbus_write_word_data(client, reg, - swap_bytes(value)); + return i2c_smbus_write_word_data(client, reg, swab16(value)); } static void ds1621_init_client(struct i2c_client *client) diff --git a/kernel/chips/gl518sm.c b/kernel/chips/gl518sm.c index c6f973e8..b0489fc5 100644 --- a/kernel/chips/gl518sm.c +++ b/kernel/chips/gl518sm.c @@ -147,7 +147,6 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, static void gl518_init_client(struct i2c_client *client); static int gl518_detach_client(struct i2c_client *client); -static u16 swap_bytes(u16 val); static int gl518_read_value(struct i2c_client *client, u8 reg); static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value); static void gl518_update_client(struct i2c_client *client); @@ -447,18 +446,13 @@ static int gl518_detach_client(struct i2c_client *client) } -static u16 swap_bytes(u16 val) -{ - return (val >> 8) | (val << 8); -} - /* Registers 0x07 to 0x0c are word-sized, others are byte-sized GL518 uses a high-byte first convention, which is exactly opposite to the usual practice. */ static int gl518_read_value(struct i2c_client *client, u8 reg) { if ((reg >= 0x07) && (reg <= 0x0c)) - return swap_bytes(i2c_smbus_read_word_data(client, reg)); + return swab16(i2c_smbus_read_word_data(client, reg)); else return i2c_smbus_read_byte_data(client, reg); } @@ -469,8 +463,7 @@ static int gl518_read_value(struct i2c_client *client, u8 reg) static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value) { if ((reg >= 0x07) && (reg <= 0x0c)) - return i2c_smbus_write_word_data(client, reg, - swap_bytes(value)); + return i2c_smbus_write_word_data(client, reg, swab16(value)); else return i2c_smbus_write_byte_data(client, reg, value); } diff --git a/kernel/chips/gl520sm.c b/kernel/chips/gl520sm.c index 40914d53..b24b11df 100644 --- a/kernel/chips/gl520sm.c +++ b/kernel/chips/gl520sm.c @@ -146,7 +146,6 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, static void gl520_init_client(struct i2c_client *client); static int gl520_detach_client(struct i2c_client *client); -static u16 swap_bytes(u16 val); static int gl520_read_value(struct i2c_client *client, u8 reg); static int gl520_write_value(struct i2c_client *client, u8 reg, u16 value); static void gl520_update_client(struct i2c_client *client); @@ -398,18 +397,13 @@ static int gl520_detach_client(struct i2c_client *client) } -static u16 swap_bytes(u16 val) -{ - return (val >> 8) | (val << 8); -} - /* Registers 0x07 to 0x0c are word-sized, others are byte-sized GL520 uses a high-byte first convention, which is exactly opposite to the usual practice. */ static int gl520_read_value(struct i2c_client *client, u8 reg) { if ((reg >= 0x07) && (reg <= 0x0c)) - return swap_bytes(i2c_smbus_read_word_data(client, reg)); + return swab16(i2c_smbus_read_word_data(client, reg)); else return i2c_smbus_read_byte_data(client, reg); } @@ -420,8 +414,7 @@ static int gl520_read_value(struct i2c_client *client, u8 reg) static int gl520_write_value(struct i2c_client *client, u8 reg, u16 value) { if ((reg >= 0x07) && (reg <= 0x0c)) - return i2c_smbus_write_word_data(client, reg, - swap_bytes(value)); + return i2c_smbus_write_word_data(client, reg, swab16(value)); else return i2c_smbus_write_byte_data(client, reg, value); } diff --git a/kernel/chips/lm75.c b/kernel/chips/lm75.c index 2a7a75cd..f441a6df 100644 --- a/kernel/chips/lm75.c +++ b/kernel/chips/lm75.c @@ -60,7 +60,6 @@ static int lm75_detect(struct i2c_adapter *adapter, int address, static void lm75_init_client(struct i2c_client *client); static int lm75_detach_client(struct i2c_client *client); -static u16 swap_bytes(u16 val); static int lm75_read_value(struct i2c_client *client, u8 reg); static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value); static void lm75_temp(struct i2c_client *client, int operation, @@ -218,11 +217,6 @@ static int lm75_detach_client(struct i2c_client *client) return 0; } -static u16 swap_bytes(u16 val) -{ - return (val >> 8) | (val << 8); -} - /* All registers are word-sized, except for the configuration register. LM75 uses a high-byte first convention, which is exactly opposite to the usual practice. */ @@ -231,7 +225,7 @@ static int lm75_read_value(struct i2c_client *client, u8 reg) if (reg == LM75_REG_CONF) return i2c_smbus_read_byte_data(client, reg); else - return swap_bytes(i2c_smbus_read_word_data(client, reg)); + return swab16(i2c_smbus_read_word_data(client, reg)); } /* All registers are word-sized, except for the configuration register. @@ -242,8 +236,7 @@ static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value) if (reg == LM75_REG_CONF) return i2c_smbus_write_byte_data(client, reg, value); else - return i2c_smbus_write_word_data(client, reg, - swap_bytes(value)); + return i2c_smbus_write_word_data(client, reg, swab16(value)); } static void lm75_init_client(struct i2c_client *client) diff --git a/kernel/chips/lm92.c b/kernel/chips/lm92.c index 02ec98b9..77f492a5 100644 --- a/kernel/chips/lm92.c +++ b/kernel/chips/lm92.c @@ -126,7 +126,7 @@ static inline int lm92_read16 (struct i2c_client *client,u8 reg,u16 *value) if (tmp < 0) return (-EIO); /* convert the data to little endian format */ - *value = ((u16) tmp >> 8) | (u16) ((u16) tmp << 8); + *value = swab16((u16) tmp); return (0); } @@ -134,8 +134,10 @@ static inline int lm92_read16 (struct i2c_client *client,u8 reg,u16 *value) static inline int lm92_write16 (struct i2c_client *client,u8 reg,u16 value) { /* convert the data to big endian format */ - u16 be = (value >> 8) | (u16) (value << 8); - return (i2c_smbus_write_word_data (client,reg,be) < 0 ? -EIO : 0); + if (i2c_smbus_write_word_data(client, reg, swab16(value)) < 0) + return -EIO; + + return 0; } static int lm92_read (struct i2c_client *client) diff --git a/kernel/chips/smartbatt.c b/kernel/chips/smartbatt.c index 0b415ffd..b0e56b2d 100644 --- a/kernel/chips/smartbatt.c +++ b/kernel/chips/smartbatt.c @@ -102,7 +102,6 @@ static int smartbatt_detach_client(struct i2c_client *client); static int smartbatt_read(struct i2c_client *client, u8 reg); #if 0 -static u16 swap_bytes(u16 val); static int smartbatt_write_value(struct i2c_client *client, u8 reg, u16 value); #endif static void smartbatt_temp(struct i2c_client *client, int operation, @@ -321,14 +320,6 @@ static int smartbatt_detach_client(struct i2c_client *client) return 0; } -#if 0 -/* Why swap bytes? */ -static u16 swap_bytes(u16 val) -{ - return (val >> 8) | (val << 8); -} -#endif - static int smartbatt_read(struct i2c_client *client, u8 reg) { int n = COMM_TIMEOUT; @@ -342,7 +333,8 @@ static int smartbatt_read(struct i2c_client *client, u8 reg) #if 0 static int smartbatt_write_value(struct i2c_client *client, u8 reg, u16 value) { - return i2c_smbus_write_word_data(client, reg, swap_bytes(value)); + /* Why swap bytes? */ + return i2c_smbus_write_word_data(client, reg, swab16(value)); } #endif diff --git a/kernel/chips/w83781d.c b/kernel/chips/w83781d.c index 1d1cb571..d176d5e7 100644 --- a/kernel/chips/w83781d.c +++ b/kernel/chips/w83781d.c @@ -327,7 +327,6 @@ static void w83781d_sens(struct i2c_client *client, int operation, static void w83781d_rt(struct i2c_client *client, int operation, int ctl_name, int *nrels_mag, long *results); #endif -static u16 swap_bytes(u16 val); static int w83781d_id = 0; @@ -1127,11 +1126,6 @@ static int w83781d_detach_client(struct i2c_client *client) return 0; } -static inline u16 swap_bytes(u16 val) -{ - return (val >> 8) | (val << 8); -} - /* The SMBus locks itself, usually, but nothing may access the Winbond between bank switches. ISA access must always be locked explicitly! We ignore the W83781D BUSY flag at this moment - it could lead to deadlocks, @@ -1186,23 +1180,17 @@ static int w83781d_read_value(struct i2c_client *client, u16 reg) /* convert from ISA to LM75 I2C addresses */ switch (reg & 0xff) { case 0x50: /* TEMP */ - res = - swap_bytes(i2c_smbus_read_word_data - (cl, 0)); + res = swab16(i2c_smbus_read_word_data(cl, 0)); break; case 0x52: /* CONFIG */ res = i2c_smbus_read_byte_data(cl, 1); break; case 0x53: /* HYST */ - res = - swap_bytes(i2c_smbus_read_word_data - (cl, 2)); + res = swab16(i2c_smbus_read_word_data(cl, 2)); break; case 0x55: /* OVER */ default: - res = - swap_bytes(i2c_smbus_read_word_data - (cl, 3)); + res = swab16(i2c_smbus_read_word_data(cl, 3)); break; } } @@ -1261,16 +1249,13 @@ static int w83781d_write_value(struct i2c_client *client, u16 reg, u16 value) /* convert from ISA to LM75 I2C addresses */ switch (reg & 0xff) { case 0x52: /* CONFIG */ - i2c_smbus_write_byte_data(cl, 1, - value & 0xff); + i2c_smbus_write_byte_data(cl, 1, value & 0xff); break; case 0x53: /* HYST */ - i2c_smbus_write_word_data(cl, 2, - swap_bytes(value)); + i2c_smbus_write_word_data(cl, 2, swab16(value)); break; case 0x55: /* OVER */ - i2c_smbus_write_word_data(cl, 3, - swap_bytes(value)); + i2c_smbus_write_word_data(cl, 3, swab16(value)); break; } }