v4l: use i2c_smbus_read_word_swapped
Laurent Pinchart
Acked-byHi Jonathan,
Thanks for the patch.
Quoted 7 lines · On Friday 21 October 2011 15:30:25 Jonathan Cameron wrote:
Function ensures that error codes don't get mangled. Dependant on:
i2c: boilerplate function for byte swapped smbus_write/read_word_data which is working it's way through the i2c tree.Signed-off-by Jonathan Cameron <[email protected]>Acked-by Jean Delvare <[email protected]>
For the mt9v032 driver,
The mt9t001 and mt9p031 drivers should be fixed similarly. I'll send a patch.
Quoted 142 lines
---
V2: Stray line removed as per Jean's comment. Thanks Jean.
Dependency due to go upstream during next merge window.
drivers/media/video/mt9m001.c | 5 ++--- drivers/media/video/mt9m111.c | 7 +++---- drivers/media/video/mt9t031.c | 5 ++--- drivers/media/video/mt9v022.c | 5 ++--- drivers/media/video/mt9v032.c | 8 ++++---- 5 files changed, 13 insertions(+), 17 deletions(-)drivers/media/video/mt9m001.c +2
-3@@ -102,14 +102,13 @@ static struct mt9m001 *to_mt9m001(const struct i2c_client *client)static int reg_read (struct i2c_client *client,const u8 reg) { -s32 data =i2c_smbus_read_word_data (client, reg); -return data <0 ? data :swab16 (data); +return i2c_smbus_read_word_swapped (client, reg); }static int reg_write (struct i2c_client *client,const u8 reg,const u16 data) { -return i2c_smbus_write_word_data (client, reg,swab16 (data)); +return i2c_smbus_write_word_swapped (client, reg, data); }static int reg_set(struct
i2c_client*client, const u8 reg,drivers/media/video/mt9m111.c +2
-2@@ -210,7 +210,7 @@ static int reg_page_map_set(struct i2c_client *client, const u16 reg) if (page > 2)return -EINVAL ; - ret =i2c_smbus_write_word_data (client,MT9M111_PAGE_MAP ,swab16 (page)); + ret =i2c_smbus_write_word_swapped (client,MT9M111_PAGE_MAP , page);if (!ret) lastpage = page;return ret;@@ -222,7 +222,7 @@ static int mt9m111_reg_read(struct i2c_client *client, const u16 reg) ret =reg_page_map_set (client, reg);if (!ret) - ret =swab16 (i2c_smbus_read_word_data (client, reg &0xff )); + ret =i2c_smbus_read_word_swapped (client, reg &0xff );dev_dbg (&client->dev,"read reg.%03x -> %04x\n" , reg, ret);drivers/media/video/mt9m111.c +1
-2return ret;@@ -235,8 +235,7 @@ static int mt9m111_reg_write(struct i2c_client *client,const u16 reg, ret =reg_page_map_set (client, reg);if (!ret) - ret =i2c_smbus_write_word_data (client, reg &0xff , -swab16 (data)); + ret =i2c_smbus_write_word_swapped (client, reg &0xff , data);dev_dbg (&client->dev,"write reg.%03x = %04x -> %d\n" , reg, data, ret);return ret;}
drivers/media/video/mt9t031.c +2
-3@@ -81,14 +81,13 @@ static struct mt9t031 *to_mt9t031(const struct i2c_client *client)static int reg_read (struct i2c_client *client,const u8 reg) { -s32 data =i2c_smbus_read_word_data (client, reg); -return data <0 ? data :swab16 (data); +return i2c_smbus_read_word_swapped (client, reg); }static int reg_write (struct i2c_client *client,const u8 reg,const u16 data) { -return i2c_smbus_write_word_data (client, reg,swab16 (data)); +return i2c_smbus_write_word_swapped (client, reg, data); }static int reg_set(struct
i2c_client*client, const u8 reg,drivers/media/video/mt9v022.c +2
-3@@ -116,14 +116,13 @@ static struct mt9v022 *to_mt9v022(const struct i2c_client *client)static int reg_read (struct i2c_client *client,const u8 reg) { -s32 data =i2c_smbus_read_word_data (client, reg); -return data <0 ? data :swab16 (data); +return i2c_smbus_read_word_swapped (client, reg); }static int reg_write (struct i2c_client *client,const u8 reg,const u16 data) { -return i2c_smbus_write_word_data (client, reg,swab16 (data)); +return i2c_smbus_write_word_swapped (client, reg, data); }static int reg_set(struct
i2c_client*client, const u8 reg,drivers/media/video/mt9v032.c +3
-3@@ -138,10 +138,10 @@ static struct mt9v032 *to_mt9v032(struct v4l2_subdev *sd)static int mt9v032_read (struct i2c_client *client,const u8 reg) { -s32 data =i2c_smbus_read_word_data (client, reg); +s32 data =i2c_smbus_read_word_swapped (client, reg);dev_dbg (&client->dev,"%s: read 0x%04x from 0x%02x\n" , __func__, -swab16 (data), reg); -return data <0 ? data :swab16 (data); + data, reg); +return data; }static int mt9v032_write(struct
i2c_client*client, const u8 reg,drivers/media/video/mt9v032.c +1
-1@@ -149,7 +149,7 @@ static int mt9v032_write(struct i2c_client *client, const u8 reg, {dev_dbg (&client->dev,"%s: writing 0x%04x to 0x%02x\n" , __func__, data, reg); -return i2c_smbus_write_word_data (client, reg,swab16 (data)); +return i2c_smbus_write_word_swapped (client, reg, data); } static int mt9v032_set_chip_control(struct mt9v032 *mt9v032, u16 clear,u16 set)
Signature · 3 lines
Regards, Laurent Pinchart
PATCH 1/1 v4l: mt9p031/mt9t001: Use i2c_smbus_{read|write}_word_swapped()
In reply to a message not in the archiveThe MT9P031 and MT9T001 sensors transfer 16-bit data on the I2C bus in swapped order. Let the I2C core handle byte order by using the i2c_smbus_{read|write}_word_swapped() functions.
--- drivers/media/video/mt9p031.c | 5 ++--- drivers/media/video/mt9t001.c | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-)
drivers/media/video/mt9p031.c +2 -3
@@ -131,13 +131,12 @@ static struct mt9p031 *to_mt9p031(struct v4l2_subdev *sd)static int mt9p031_read (struct i2c_client *client,u8 reg) { -s32 data =i2c_smbus_read_word_data (client, reg); -return data <0 ? data :be16_to_cpu (data); +return i2c_smbus_read_word_swapped (client, reg); }static int mt9p031_write (struct i2c_client *client,u8 reg,u16 data) { -return i2c_smbus_write_word_data (client, reg,cpu_to_be16 (data)); +return i2c_smbus_write_word_swapped (client, reg, data); } static int mt9p031_set_output_control(struct mt9p031 *mt9p031, u16 clear,
drivers/media/video/mt9t001.c +2 -3
@@ -132,13 +132,12 @@ static inline struct mt9t001 *to_mt9t001(struct v4l2_subdev *sd)static int mt9t001_read (struct i2c_client *client,u8 reg) { -s32 data =i2c_smbus_read_word_data (client, reg); -return data <0 ? data :be16_to_cpu (data); +return i2c_smbus_read_word_swapped (client, reg); }static int mt9t001_write (struct i2c_client *client,u8 reg,u16 data) { -return i2c_smbus_write_word_data (client, reg,cpu_to_be16 (data)); +return i2c_smbus_write_word_swapped (client, reg, data); } static int mt9t001_set_output_control(struct mt9t001 *mt9t001, u16 clear,
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH] v4l: mt9p031/mt9t001: Use i2c_smbus_{read|write}_word_swapped()
Quoted 5 lines · Laurent Pinchart
The MT9P031 and MT9T001 sensors transfer 16-bit data on the I2C bus in swapped order. Let the I2C core handle byte order by using the i2c_smbus_{read|write}_word_swapped() functions.
Signed-off-by Laurent Pinchart <[email protected]>
Quoted 45 lines
--- drivers/media/video/mt9p031.c | 5 ++--- drivers/media/video/mt9t001.c | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-)drivers/media/video/mt9p031.c +2
-3@@ -131,13 +131,12 @@ static struct mt9p031 *to_mt9p031(struct v4l2_subdev *sd)static int mt9p031_read (struct i2c_client *client,u8 reg) { -s32 data =i2c_smbus_read_word_data (client, reg); -return data <0 ? data :be16_to_cpu (data); +return i2c_smbus_read_word_swapped (client, reg); }static int mt9p031_write (struct i2c_client *client,u8 reg,u16 data) { -return i2c_smbus_write_word_data (client, reg,cpu_to_be16 (data)); +return i2c_smbus_write_word_swapped (client, reg, data); } static int mt9p031_set_output_control(struct mt9p031 *mt9p031, u16 clear,drivers/media/video/mt9t001.c +2
-3@@ -132,13 +132,12 @@ static inline struct mt9t001 *to_mt9t001(struct v4l2_subdev *sd)static int mt9t001_read (struct i2c_client *client,u8 reg) { -s32 data =i2c_smbus_read_word_data (client, reg); -return data <0 ? data :be16_to_cpu (data); +return i2c_smbus_read_word_swapped (client, reg); }static int mt9t001_write (struct i2c_client *client,u8 reg,u16 data) { -return i2c_smbus_write_word_data (client, reg,cpu_to_be16 (data)); +return i2c_smbus_write_word_swapped (client, reg, data); } static int mt9t001_set_output_control(struct mt9t001 *mt9t001, u16 clear,
Re: [PATCH] v4l: mt9p031/mt9t001: Use i2c_smbus_{read|write}_word_swapped()
In reply to Laurent PinchartQuoted 5 lines · Laurent Pinchart
The MT9P031 and MT9T001 sensors transfer 16-bit data on the I2C bus in swapped order. Let the I2C core handle byte order by using the i2c_smbus_{read|write}_word_swapped() functions.
Signed-off-by Laurent Pinchart <[email protected]>
As far as I can tell, this fixes a bug too, the original code would not work on big-endian machines.
Quoted 45 lines
--- drivers/media/video/mt9p031.c | 5 ++--- drivers/media/video/mt9t001.c | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-)drivers/media/video/mt9p031.c +2
-3@@ -131,13 +131,12 @@ static struct mt9p031 *to_mt9p031(struct v4l2_subdev *sd)static int mt9p031_read (struct i2c_client *client,u8 reg) { -s32 data =i2c_smbus_read_word_data (client, reg); -return data <0 ? data :be16_to_cpu (data); +return i2c_smbus_read_word_swapped (client, reg); }static int mt9p031_write (struct i2c_client *client,u8 reg,u16 data) { -return i2c_smbus_write_word_data (client, reg,cpu_to_be16 (data)); +return i2c_smbus_write_word_swapped (client, reg, data); } static int mt9p031_set_output_control(struct mt9p031 *mt9p031, u16 clear,drivers/media/video/mt9t001.c +2
-3@@ -132,13 +132,12 @@ static inline struct mt9t001 *to_mt9t001(struct v4l2_subdev *sd)static int mt9t001_read (struct i2c_client *client,u8 reg) { -s32 data =i2c_smbus_read_word_data (client, reg); -return data <0 ? data :be16_to_cpu (data); +return i2c_smbus_read_word_swapped (client, reg); }static int mt9t001_write (struct i2c_client *client,u8 reg,u16 data) { -return i2c_smbus_write_word_data (client, reg,cpu_to_be16 (data)); +return i2c_smbus_write_word_swapped (client, reg, data); } static int mt9t001_set_output_control(struct mt9t001 *mt9t001, u16 clear,
Signature · 1 line
Jean Delvare