diff mbox

i2c: davinci: raw read and write endian fix

Message ID 1384971824-7707-1-git-send-email-taras.kondratiuk@linaro.org (mailing list archive)
State New, archived
Headers show

Commit Message

Taras Kondratiuk Nov. 20, 2013, 6:23 p.m. UTC
I2C IP block expect LE data, but CPU may operate in BE mode.
Need to use endian neutral functions to read/write h/w registers.
I.e instead of __raw_read[lw] and __raw_write[lw] functions code
need to use read[lw]_relaxed and write[lw]_relaxed functions.
If the first simply reads/writes register, the second will byteswap
it if host operates in BE mode.

Changes are trivial sed like replacement of __raw_xxx functions
with xxx_relaxed variant.

Signed-off-by: Taras Kondratiuk <taras.kondratiuk@linaro.org>
---
Based on Linus' master tip (b4789b8).
Tested on Keystone2 EVM.

 drivers/i2c/busses/i2c-davinci.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Grygorii Strashko Nov. 21, 2013, 5:05 p.m. UTC | #1
On 11/20/2013 08:23 PM, Taras Kondratiuk wrote:
> I2C IP block expect LE data, but CPU may operate in BE mode.
> Need to use endian neutral functions to read/write h/w registers.
> I.e instead of __raw_read[lw] and __raw_write[lw] functions code
> need to use read[lw]_relaxed and write[lw]_relaxed functions.
> If the first simply reads/writes register, the second will byteswap
> it if host operates in BE mode.
>
> Changes are trivial sed like replacement of __raw_xxx functions
> with xxx_relaxed variant.

Reviewed-by: Grygorii Strashko <grygorii.strashko@ti.com>

>
> Signed-off-by: Taras Kondratiuk <taras.kondratiuk@linaro.org>
> ---
> Based on Linus' master tip (b4789b8).
> Tested on Keystone2 EVM.
>
>   drivers/i2c/busses/i2c-davinci.c |    4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c
> index 132369f..a629447 100644
> --- a/drivers/i2c/busses/i2c-davinci.c
> +++ b/drivers/i2c/busses/i2c-davinci.c
> @@ -125,12 +125,12 @@ static struct davinci_i2c_platform_data davinci_i2c_platform_data_default = {
>   static inline void davinci_i2c_write_reg(struct davinci_i2c_dev *i2c_dev,
>   					 int reg, u16 val)
>   {
> -	__raw_writew(val, i2c_dev->base + reg);
> +	writew_relaxed(val, i2c_dev->base + reg);
>   }
>
>   static inline u16 davinci_i2c_read_reg(struct davinci_i2c_dev *i2c_dev, int reg)
>   {
> -	return __raw_readw(i2c_dev->base + reg);
> +	return readw_relaxed(i2c_dev->base + reg);
>   }
>
>   /* Generate a pulse on the i2c clock pin. */
>
Wolfram Sang Nov. 26, 2013, 12:39 p.m. UTC | #2
On Wed, Nov 20, 2013 at 08:23:44PM +0200, Taras Kondratiuk wrote:
> I2C IP block expect LE data, but CPU may operate in BE mode.
> Need to use endian neutral functions to read/write h/w registers.
> I.e instead of __raw_read[lw] and __raw_write[lw] functions code
> need to use read[lw]_relaxed and write[lw]_relaxed functions.
> If the first simply reads/writes register, the second will byteswap
> it if host operates in BE mode.
> 
> Changes are trivial sed like replacement of __raw_xxx functions
> with xxx_relaxed variant.
> 
> Signed-off-by: Taras Kondratiuk <taras.kondratiuk@linaro.org>

Applied to for-current, thanks!
Wolfram Sang Nov. 27, 2013, 6:29 p.m. UTC | #3
On Wed, Nov 20, 2013 at 08:23:44PM +0200, Taras Kondratiuk wrote:
> I2C IP block expect LE data, but CPU may operate in BE mode.
> Need to use endian neutral functions to read/write h/w registers.
> I.e instead of __raw_read[lw] and __raw_write[lw] functions code
> need to use read[lw]_relaxed and write[lw]_relaxed functions.
> If the first simply reads/writes register, the second will byteswap
> it if host operates in BE mode.
> 
> Changes are trivial sed like replacement of __raw_xxx functions
> with xxx_relaxed variant.
> 
> Signed-off-by: Taras Kondratiuk <taras.kondratiuk@linaro.org>

Applied to for-current, thanks!
diff mbox

Patch

diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c
index 132369f..a629447 100644
--- a/drivers/i2c/busses/i2c-davinci.c
+++ b/drivers/i2c/busses/i2c-davinci.c
@@ -125,12 +125,12 @@  static struct davinci_i2c_platform_data davinci_i2c_platform_data_default = {
 static inline void davinci_i2c_write_reg(struct davinci_i2c_dev *i2c_dev,
 					 int reg, u16 val)
 {
-	__raw_writew(val, i2c_dev->base + reg);
+	writew_relaxed(val, i2c_dev->base + reg);
 }
 
 static inline u16 davinci_i2c_read_reg(struct davinci_i2c_dev *i2c_dev, int reg)
 {
-	return __raw_readw(i2c_dev->base + reg);
+	return readw_relaxed(i2c_dev->base + reg);
 }
 
 /* Generate a pulse on the i2c clock pin. */