Skip to contentSkip to conversation

i2c: designware: Add support for 16bit register access

PATCH Superseded Stefan Roese 4 participants 10 messages Mar 13, 2012 – Apr 17, 2012 6 messages not in the archive

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: designware: Add support for 16bit register access

The STM SPEAr platform can only access the i2c controller register via 16bit read/write functions. This patch adds support to automatically detect this 16bit access mode.

---
 drivers/i2c/busses/i2c-designware-core.c |   22 ++++++++++++++++++++--
 drivers/i2c/busses/i2c-designware-core.h |    1 +
 2 files changed, 21 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-designware-core.c +20 -2
index df87992..d1facbc 100644
@@ -164,7 +164,14 @@ static char *abort_sources[] = {
 
 u32 dw_readl(struct dw_i2c_dev *dev, int offset)
 {
-	u32 value = readl(dev->base + offset);
+	u32 value;
+
+	if (dev->access_16bit) {
+		value = readw(dev->base + offset) |
+			(readw(dev->base + offset + 2) << 16);
+	} else {
+		value = readl(dev->base + offset);
+	}
 
 	if (dev->swab)
 		return swab32(value);
@@ -177,7 +184,12 @@ void dw_writel(struct dw_i2c_dev *dev, u32 b, int offset)
 	if (dev->swab)
 		b = swab32(b);
 
-	writel(b, dev->base + offset);
+	if (dev->access_16bit) {
+		writew((u16)b, dev->base + offset);
+		writew((u16)(b >> 16), dev->base + offset + 2);
+	} else {
+		writel(b, dev->base + offset);
+	}
 }
 
 static u32
@@ -258,6 +270,12 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
 		reg = DW_IC_COMP_TYPE_VALUE;
 	}
 
+	/* Configure register access mode 16bit */
+	if (reg == (DW_IC_COMP_TYPE_VALUE & 0x0000ffff)) {
+		dev->access_16bit = 1;
+		reg = DW_IC_COMP_TYPE_VALUE;
+	}
+
 	if (reg != DW_IC_COMP_TYPE_VALUE) {
 		dev_err(dev->dev, "Unknown Synopsys component type: "
 			"0x%08x\n", reg);
drivers/i2c/busses/i2c-designware-core.h +1 -0
index 02d1a2d..f5af101 100644
@@ -83,6 +83,7 @@ struct dw_i2c_dev {
 	u32			abort_source;
 	int			irq;
 	int			swab;
+	int			access_16bit;
 	struct i2c_adapter	adapter;
 	u32			functionality;
 	u32			master_cfg;
Signature · 1 line
1.7.9.2
#2 lore raw
In reply to a message not in the archive

Hi Stefan,

Quoted 25 lines

-----Original Message-----
From: Stefan Roese [mailto:[email protected]]
Sent: Tuesday, March 13, 2012 9:24 PM
To: [email protected]
Cc: spear-devel; [email protected]
Subject: [PATCH] i2c: designware: Add support for 16bit register access

The STM SPEAr platform can only access the i2c controller register via 16bit read/write functions. This patch adds support to automatically detect this 16bit access mode.

---
 drivers/i2c/busses/i2c-designware-core.c |   22 ++++++++++++++++++++--
 drivers/i2c/busses/i2c-designware-core.h |    1 +
 2 files changed, 21 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-designware-core.c +0 -0
index df87992..d1facbc 100644
@@ -164,7 +164,14 @@ static char *abort_sources[] = {
 
 u32 dw_readl(struct dw_i2c_dev *dev, int offset)

drivers/i2c/busses/i2c-designware-core.c static char *abort_sources[] = { · line 174

Quoted 10 lines
drivers/i2c/busses/i2c-designware-core.c +8 -1
 {
-	u32 value = readl(dev->base + offset);
+	u32 value;
+
+	if (dev->access_16bit) {
+		value = readw(dev->base + offset) |
+			(readw(dev->base + offset + 2) << 16);
+	} else {
+		value = readl(dev->base + offset);
+	}

We can do away with '{' parenthesis as these are single line of code inside both the 'if-else' blocks.

Quoted 18 lines
drivers/i2c/busses/i2c-designware-core.c +6 -1
 	if (dev->swab)
 		return swab32(value);
@@ -177,7 +184,12 @@ void dw_writel(struct dw_i2c_dev *dev, u32 b, int
 offset)
 	if (dev->swab)
 		b = swab32(b);
 
-	writel(b, dev->base + offset);
+	if (dev->access_16bit) {
+		writew((u16)b, dev->base + offset);
+		writew((u16)(b >> 16), dev->base + offset + 2);
+	} else {
+		writel(b, dev->base + offset);
+	}
 }
 

static u32

drivers/i2c/busses/i2c-designware-core.c int i2c_dw_init(struct dw_i2c_dev *dev) · line 275

Quoted 6 lines
drivers/i2c/busses/i2c-designware-core.c +3 -0
@@ -258,6 +270,12 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
 		reg = DW_IC_COMP_TYPE_VALUE;
 	}
 
+	/* Configure register access mode 16bit */
+	if (reg == (DW_IC_COMP_TYPE_VALUE & 0x0000ffff)) {
+		dev->access_16bit = 1;

Can we use a suitable macro for 0x0000ffff? Also, if dev->access_16bit is bool we can simply set:

		dev->access_16bit = true;

more on that below...

Quoted 12 lines
drivers/i2c/busses/i2c-designware-core.c +3 -0
+		reg = DW_IC_COMP_TYPE_VALUE;
+	}
+
 	if (reg != DW_IC_COMP_TYPE_VALUE) {
 		dev_err(dev->dev, "Unknown Synopsys component type: "
 			"0x%08x\n", reg);
drivers/i2c/busses/i2c-designware-core.h +0 -0
index 02d1a2d..f5af101 100644

drivers/i2c/busses/i2c-designware-core.h struct dw_i2c_dev { · line 86

Quoted 4 lines
drivers/i2c/busses/i2c-designware-core.h +1 -0
@@ -83,6 +83,7 @@ struct dw_i2c_dev {
 	u32			abort_source;
 	int			irq;
 	int			swab;
+	int			access_16bit;

...
int?? Probably we are better off with making this as bool.

drivers/i2c/busses/i2c-designware-core.h struct dw_i2c_dev {

Quoted 4 lines
drivers/i2c/busses/i2c-designware-core.h +0 -1
 	struct i2c_adapter	adapter;
 	u32			functionality;
 	u32			master_cfg;
--

Regards,
Bhupesh

#4 lore raw
In reply to a message not in the archive

Hi Bhupesh,

Quoted 28 lines · On Wednesday 14 March 2012 04:29:23 Bhupesh SHARMA wrote:
Quoted 28 lines

-----Original Message-----
From: Stefan Roese [mailto:[email protected]]
Sent: Tuesday, March 13, 2012 9:24 PM
To: [email protected]
Cc: spear-devel; [email protected]
Subject: [PATCH] i2c: designware: Add support for 16bit register access

The STM SPEAr platform can only access the i2c controller register via 16bit read/write functions. This patch adds support to automatically detect this 16bit access mode.

---

 drivers/i2c/busses/i2c-designware-core.c |   22 ++++++++++++++++++++--
 drivers/i2c/busses/i2c-designware-core.h |    1 +
 2 files changed, 21 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-designware-core.c +0 -0
index df87992..d1facbc 100644
@@ -164,7 +164,14 @@ static char *abort_sources[] = {
 
 u32 dw_readl(struct dw_i2c_dev *dev, int offset)
 {
 
Quoted 12 lines

drivers/i2c/busses/i2c-designware-core.c static char *abort_sources[] = { · line 174

Quoted 9 lines
drivers/i2c/busses/i2c-designware-core.c +8 -1
-	u32 value = readl(dev->base + offset);
+	u32 value;
+
+	if (dev->access_16bit) {
+		value = readw(dev->base + offset) |
+			(readw(dev->base + offset + 2) << 16);
+	} else {
+		value = readl(dev->base + offset);
+	}

We can do away with '{' parenthesis as these are single line of code inside both the 'if-else' blocks.

It's not a single-line statement. The first block extends spans 2 lines. At least that how I interpret this CodingStyle recommendation.

Quoted 27 lines
Quoted 27 lines
drivers/i2c/busses/i2c-designware-core.c +0 -0
 	if (dev->swab)
 
drivers/i2c/busses/i2c-designware-core.c +6 -1
 		return swab32(value);
@@ -177,7 +184,12 @@ void dw_writel(struct dw_i2c_dev *dev, u32 b, int
 offset)
 
 	if (dev->swab)
 
 		b = swab32(b);
 
-	writel(b, dev->base + offset);
+	if (dev->access_16bit) {
+		writew((u16)b, dev->base + offset);
+		writew((u16)(b >> 16), dev->base + offset + 2);
+	} else {
+		writel(b, dev->base + offset);
+	}

}

static u32

drivers/i2c/busses/i2c-designware-core.c +0 -0
@@ -258,6 +270,12 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
 
 		reg = DW_IC_COMP_TYPE_VALUE;
 
Quoted 7 lines

drivers/i2c/busses/i2c-designware-core.c int i2c_dw_init(struct dw_i2c_dev *dev) · line 275

Quoted 5 lines
drivers/i2c/busses/i2c-designware-core.c +3 -0
 	}
 
+	/* Configure register access mode 16bit */
+	if (reg == (DW_IC_COMP_TYPE_VALUE & 0x0000ffff)) {
+		dev->access_16bit = 1;

Can we use a suitable macro for 0x0000ffff?

Hmmm. Wouldn't that make it more complex? 0x0000ffff is easy to understand. A marco would "hide" this value. I would prefer to keep the value.

Quoted 22 lines

Also, if dev->access_16bit is bool we can simply set:

		dev->access_16bit = true;

more on that below...

Quoted 17 lines
drivers/i2c/busses/i2c-designware-core.c +3 -0
+		reg = DW_IC_COMP_TYPE_VALUE;
+	}
+
 
drivers/i2c/busses/i2c-designware-core.c +0 -0
 	if (reg != DW_IC_COMP_TYPE_VALUE) {
 
 		dev_err(dev->dev, "Unknown Synopsys component type: "
 
 			"0x%08x\n", reg);
drivers/i2c/busses/i2c-designware-core.h +0 -0
index 02d1a2d..f5af101 100644
@@ -83,6 +83,7 @@ struct dw_i2c_dev {
 
Quoted 8 lines

drivers/i2c/busses/i2c-designware-core.h struct dw_i2c_dev { · line 86

Quoted 5 lines
drivers/i2c/busses/i2c-designware-core.h +1 -0
 	u32			abort_source;
 	int			irq;
 	int			swab;
 
+	int			access_16bit;

...
int?? Probably we are better off with making this as bool.

I'm not a big fan of bool's. But I have no strong preference here. My reasoning here was consistency. As we already have "int swab" for a similar issue.

So basically, I would prefer to not make the changes you suggested. But in the end its the decision of the maintainer(s).

Thanks,
Stefan

#6 lore raw
In reply to a message not in the archive

Hi Stefan,

Quoted 54 lines

-----Original Message-----
From: Stefan Roese [mailto:[email protected]]
Sent: Wednesday, March 14, 2012 1:28 PM
To: Bhupesh SHARMA
Cc: [email protected]; spear-devel; [email protected]
Subject: Re: [PATCH] i2c: designware: Add support for 16bit register
access

Hi Bhupesh,

Quoted 6 lines · On Wednesday 14 March 2012 04:29:23 Bhupesh SHARMA wrote:
Quoted 6 lines

-----Original Message-----
From: Stefan Roese [mailto:[email protected]]
Sent: Tuesday, March 13, 2012 9:24 PM
To: [email protected]
Cc: spear-devel; [email protected]
Subject: [PATCH] i2c: designware: Add support for 16bit register

access

Quoted 9 lines
Quoted 9 lines

The STM SPEAr platform can only access the i2c controller register via 16bit read/write functions. This patch adds support to automatically detect this 16bit access mode.

---

 drivers/i2c/busses/i2c-designware-core.c |   22

++++++++++++++++++++--

Quoted 13 lines
Quoted 13 lines
 drivers/i2c/busses/i2c-designware-core.h |    1 +
 2 files changed, 21 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-designware-core.c +0 -0
index df87992..d1facbc 100644
@@ -164,7 +164,14 @@ static char *abort_sources[] = {
 
 u32 dw_readl(struct dw_i2c_dev *dev, int offset)
 {
 
Quoted 12 lines

drivers/i2c/busses/i2c-designware-core.c static char *abort_sources[] = { · line 174

Quoted 9 lines
drivers/i2c/busses/i2c-designware-core.c +8 -1
-	u32 value = readl(dev->base + offset);
+	u32 value;
+
+	if (dev->access_16bit) {
+		value = readw(dev->base + offset) |
+			(readw(dev->base + offset + 2) << 16);
+	} else {
+		value = readl(dev->base + offset);
+	}

We can do away with '{' parenthesis as these are single line of code inside both the 'if-else' blocks.

Quoted 3 lines

It's not a single-line statement. The first block extends spans 2 lines. At
least that how I interpret this CodingStyle recommendation.

???
Breaking a single line of code into two for readability does not make them two separate executable statements.

As per CodingStyle recommendation:
Do not unnecessarily use braces where a single statement will do.

if (condition)

	action();

So, please modify your patch as braces here waste precious screen space and reduce readability.

Quoted 36 lines
Quoted 5 lines

drivers/i2c/busses/i2c-designware-core.c void dw_writel(struct dw_i2c_dev *dev, u32 b,

Quoted 5 lines
drivers/i2c/busses/i2c-designware-core.c +0 -0
 	if (dev->swab)
 
drivers/i2c/busses/i2c-designware-core.c +0 -0
 		return swab32(value);
@@ -177,7 +184,12 @@ void dw_writel(struct dw_i2c_dev *dev, u32 b,

int

Quoted 22 lines
Quoted 22 lines
drivers/i2c/busses/i2c-designware-core.c +6 -1
 offset)
 
 	if (dev->swab)
 
 		b = swab32(b);
 
-	writel(b, dev->base + offset);
+	if (dev->access_16bit) {
+		writew((u16)b, dev->base + offset);
+		writew((u16)(b >> 16), dev->base + offset + 2);
+	} else {
+		writel(b, dev->base + offset);
+	}

}

static u32

drivers/i2c/busses/i2c-designware-core.c +0 -0
@@ -258,6 +270,12 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
 
 		reg = DW_IC_COMP_TYPE_VALUE;
 
Quoted 7 lines

drivers/i2c/busses/i2c-designware-core.c int i2c_dw_init(struct dw_i2c_dev *dev) · line 275

Quoted 5 lines
drivers/i2c/busses/i2c-designware-core.c +3 -0
 	}
 
+	/* Configure register access mode 16bit */
+	if (reg == (DW_IC_COMP_TYPE_VALUE & 0x0000ffff)) {
+		dev->access_16bit = 1;

Can we use a suitable macro for 0x0000ffff?

Quoted 3 lines

Hmmm. Wouldn't that make it more complex? 0x0000ffff is easy to understand. A
marco would "hide" this value. I would prefer to keep the value.

Using a macro doesn't make things 'more complex', but more readable. Magic numbers must be avoided at all cost. A better
named MACRO is always better (for anyone else reading the code) than a magic number like 0x0000ffff.

Quoted 31 lines
Quoted 22 lines

Also, if dev->access_16bit is bool we can simply set:

		dev->access_16bit = true;

more on that below...

Quoted 17 lines
drivers/i2c/busses/i2c-designware-core.c +3 -0
+		reg = DW_IC_COMP_TYPE_VALUE;
+	}
+
 
drivers/i2c/busses/i2c-designware-core.c +0 -0
 	if (reg != DW_IC_COMP_TYPE_VALUE) {
 
 		dev_err(dev->dev, "Unknown Synopsys component type: "
 
 			"0x%08x\n", reg);
drivers/i2c/busses/i2c-designware-core.h +0 -0
index 02d1a2d..f5af101 100644
@@ -83,6 +83,7 @@ struct dw_i2c_dev {
 
Quoted 8 lines

drivers/i2c/busses/i2c-designware-core.h struct dw_i2c_dev { · line 86

Quoted 5 lines
drivers/i2c/busses/i2c-designware-core.h +1 -0
 	u32			abort_source;
 	int			irq;
 	int			swab;
 
+	int			access_16bit;

...
int?? Probably we are better off with making this as bool.

Quoted 4 lines

I'm not a big fan of bool's. But I have no strong preference here. My reasoning here was consistency. As we already have "int swab" for a similar
issue.

If we have not done it earlier, doesn't mean that we repeat the same mistake again. There is no reason to take access_16bit as an int when a bool will suffice.

This wastes storage and on some platforms (which have real crunch of memory), such saving is critical.

Quoted 4 lines

So basically, I would prefer to not make the changes you suggested. But in the
end its the decision of the maintainer(s).

Linux is a collaborative world and patches can be reviewed by literally anyone :)

I am sure the maintainer(s) will find my comments worth adding in your patch..

Regards,
Bhupesh

#8 lore raw
In reply to a message not in the archive
Quoted 28 lines · Bhupesh SHARMA
Quoted 28 lines

-----Original Message-----
From: Stefan Roese [mailto:[email protected]]
Sent: Wednesday, March 14, 2012 1:28 PM
To: Bhupesh SHARMA
Cc: [email protected]; spear-devel; [email protected]
Subject: Re: [PATCH] i2c: designware: Add support for 16bit register
access

Quoted 18 lines · On Wednesday 14 March 2012 04:29:23 Bhupesh SHARMA wrote:
Quoted 8 lines

-----Original Message-----
From: Stefan Roese [mailto:[email protected]]
Sent: Tuesday, March 13, 2012 9:24 PM
To: [email protected]
Cc: spear-devel; [email protected]
Subject: [PATCH] i2c: designware: Add support for 16bit register access (...)

Review int i2c_dw_init(struct dw_i2c_dev *dev) · line 277

Quoted 8 lines
(quoted diff) +3 -0
@@ -258,6 +270,12 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
 
 		reg = DW_IC_COMP_TYPE_VALUE;
 
 	}
 
+	/* Configure register access mode 16bit */
+	if (reg == (DW_IC_COMP_TYPE_VALUE & 0x0000ffff)) {
+		dev->access_16bit = 1;

Can we use a suitable macro for 0x0000ffff?

Quoted 8 lines
Quoted 3 lines

Hmmm. Wouldn't that make it more complex? 0x0000ffff is easy to understand. A
marco would "hide" this value. I would prefer to keep the value.

Using a macro doesn't make things 'more complex', but more readable. Magic numbers must be avoided at all cost. A better
named MACRO is always better (for anyone else reading the code) than a magic number like 0x0000ffff.

I beg to disagree. Quite strongly, even.

For one thing, "at all cost" never holds in the real world. You always have to make compromises.

For another, it only makes sense to define constants for values that have a specific meaning. For example bits in a bit vector, or bit masks. Here this is clearly not the case, so I fully agree with Stefan that a define would make the code _less_ readable.

Quoted 29 lines
Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
(quoted diff) +0 -0
(...)
drivers/i2c/busses/i2c-designware-core.h +0 -0
index 02d1a2d..f5af101 100644
@@ -83,6 +83,7 @@ struct dw_i2c_dev {
 
Quoted 8 lines

drivers/i2c/busses/i2c-designware-core.h struct dw_i2c_dev { · line 88

Quoted 5 lines
drivers/i2c/busses/i2c-designware-core.h +1 -0
 	u32			abort_source;
 	int			irq;
 	int			swab;
 
+	int			access_16bit;

...
int?? Probably we are better off with making this as bool.

Quoted 4 lines

I'm not a big fan of bool's. But I have no strong preference here. My reasoning here was consistency. As we already have "int swab" for a similar
issue.

If we have not done it earlier, doesn't mean that we repeat the same mistake again. There is no reason to take access_16bit as an int when a bool will suffice.

This wastes storage and on some platforms (which have real crunch of memory), such saving is critical.

Quoted 7 lines
Quoted 4 lines

So basically, I would prefer to not make the changes you suggested. But in the
end its the decision of the maintainer(s).

Linux is a collaborative world and patches can be reviewed by literally anyone :)

Likewise, everyone can send patches to address issues that bother them. Want these ints turned into bools? Stop yelling at Stefan, and do it yourself. If it is so critical, no doubt you'll find reviewers to ack your patch and maintainers to apply it. And you'll even get the fame.

Quoted 1 line

I am sure the maintainer(s) will find my comments worth adding in your patch..

I'm not in charge of this specific driver, so I can't speak for the maintainer. And you shouldn't either...

Thanks,

Signature · 1 line
Jean Delvare
#10 lore raw
In reply to a message not in the archive
Quoted 51 lines

-----Original Message-----
From: Jean Delvare [mailto:[email protected]]
Sent: Wednesday, March 14, 2012 2:14 PM
To: Bhupesh SHARMA
Cc: Stefan Roese; [email protected]; spear-devel; ben- [email protected]
Subject: Re: [PATCH] i2c: designware: Add support for 16bit register access

Quoted 6 lines · Bhupesh SHARMA
Quoted 6 lines

-----Original Message-----
From: Stefan Roese [mailto:[email protected]]
Sent: Wednesday, March 14, 2012 1:28 PM
To: Bhupesh SHARMA
Cc: [email protected]; spear-devel; [email protected]
Subject: Re: [PATCH] i2c: designware: Add support for 16bit

register

Quoted 9 lines
Quoted 9 lines

access

Quoted 6 lines · On Wednesday 14 March 2012 04:29:23 Bhupesh SHARMA wrote:
Quoted 6 lines

-----Original Message-----
From: Stefan Roese [mailto:[email protected]]
Sent: Tuesday, March 13, 2012 9:24 PM
To: [email protected]
Cc: spear-devel; [email protected]
Subject: [PATCH] i2c: designware: Add support for 16bit

register access

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines

Review int i2c_dw_init(struct dw_i2c_dev *dev) · line 277

Quoted 10 lines

(...)

(quoted diff) +3 -0
@@ -258,6 +270,12 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
 
 		reg = DW_IC_COMP_TYPE_VALUE;
 
 	}
 
+	/* Configure register access mode 16bit */
+	if (reg == (DW_IC_COMP_TYPE_VALUE & 0x0000ffff)) {
+		dev->access_16bit = 1;

Can we use a suitable macro for 0x0000ffff?

Quoted 8 lines
Quoted 3 lines

Hmmm. Wouldn't that make it more complex? 0x0000ffff is easy to understand. A
marco would "hide" this value. I would prefer to keep the value.

Using a macro doesn't make things 'more complex', but more readable. Magic numbers must be avoided at all cost. A better
named MACRO is always better (for anyone else reading the code) than a magic number like 0x0000ffff.

I beg to disagree. Quite strongly, even.

Quoted 7 lines

For one thing, "at all cost" never holds in the real world. You always have to make compromises.

For another, it only makes sense to define constants for values that have a specific meaning. For example bits in a bit vector, or bit masks. Here this is clearly not the case, so I fully agree with Stefan that a define would make the code _less_ readable.

Well you can have your opinion, let's wait for the maintainer's words..

Quoted 38 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
(quoted diff) +0 -0
(...)
drivers/i2c/busses/i2c-designware-core.h +0 -0
index 02d1a2d..f5af101 100644
@@ -83,6 +83,7 @@ struct dw_i2c_dev {
 
 	u32			abort_source;
 	int			irq;
 	int			swab;
 
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

drivers/i2c/busses/i2c-designware-core.h struct dw_i2c_dev { · line 88

Quoted 1 line
drivers/i2c/busses/i2c-designware-core.h +1 -0
+	int			access_16bit;

...
int?? Probably we are better off with making this as bool.

I'm not a big fan of bool's. But I have no strong preference here.

My

Quoted 6 lines
Quoted 3 lines

reasoning here was consistency. As we already have "int swab" for a similar
issue.

If we have not done it earlier, doesn't mean that we repeat the same mistake again. There is no reason to take access_16bit as an int when

a bool

Quoted 3 lines

will suffice.

This wastes storage and on some platforms (which have real crunch of

memory),

Quoted 3 lines

such saving is critical.

Quoted 1 line

So basically, I would prefer to not make the changes you suggested.

But

Quoted 4 lines
Quoted 3 lines

in the
end its the decision of the maintainer(s).

Quoted 7 lines
Quoted 2 lines

Linux is a collaborative world and patches can be reviewed by literally anyone :)

Likewise, everyone can send patches to address issues that bother them. Want these ints turned into bools? Stop yelling at Stefan, and do it yourself. If it is so critical, no doubt you'll find reviewers to ack your patch and maintainers to apply it. And you'll even get the fame.

You missed the point completely..

We have done a thing in 'X' way but later we realize that 'Y' is a better way of doing it and when we bring out something new we still use the 'X' way and claim that it was always done that way doesn't make sense. It's better to use 'Y' way for everything new and gradually shift older stuff too..

Quoted 6 lines
Quoted 1 line

I am sure the maintainer(s) will find my comments worth adding in

your patch..

I'm not in charge of this specific driver, so I can't speak for the maintainer. And you shouldn't either...

Yes of-course.
Let's wait for the maintainer(s) words.

Regards,
Bhupesh

#11 lore raw
In reply to a message not in the archive
Quoted 27 lines · On Wednesday 14 March 2012 09:19:22 Bhupesh SHARMA wrote:
Quoted 19 lines
Quoted 6 lines
Quoted 6 lines

+++ b/drivers/i2c/busses/i2c-designware-core.c

(quoted diff) +0 -0
@@ -164,7 +164,14 @@ static char *abort_sources[] = {
 
 u32 dw_readl(struct dw_i2c_dev *dev, int offset)
 {
 
Quoted 12 lines

Review static char *abort_sources[] = { · line 175

Quoted 9 lines
(quoted diff) +8 -1
-	u32 value = readl(dev->base + offset);
+	u32 value;
+
+	if (dev->access_16bit) {
+		value = readw(dev->base + offset) |
+			(readw(dev->base + offset + 2) << 16);
+	} else {
+		value = readl(dev->base + offset);
+	}

We can do away with '{' parenthesis as these are single line of code inside both the 'if-else' blocks.

Quoted 3 lines

It's not a single-line statement. The first block extends spans 2 lines. At
least that how I interpret this CodingStyle recommendation.

???
Breaking a single line of code into two for readability does not make them two separate executable statements.

Quoted 8 lines

As per CodingStyle recommendation:
Do not unnecessarily use braces where a single statement will do.

if (condition)

	action();

So, please modify your patch as braces here waste precious screen space and reduce readability.

I have no strong preferences here. I it helps getting this patch accepted, I'll remove those braces.

Quoted 38 lines
Quoted 38 lines
Quoted 5 lines

Review void dw_writel(struct dw_i2c_dev *dev, u32 b,

Quoted 5 lines
(quoted diff) +0 -0
 	if (dev->swab)
 
(quoted diff) +0 -0
 		return swab32(value);
@@ -177,7 +184,12 @@ void dw_writel(struct dw_i2c_dev *dev, u32 b,

int

Quoted 29 lines
Quoted 19 lines
(quoted diff) +6 -1
 offset)
 
 	if (dev->swab)
 
 		b = swab32(b);
 
-	writel(b, dev->base + offset);
+	if (dev->access_16bit) {
+		writew((u16)b, dev->base + offset);
+		writew((u16)(b >> 16), dev->base + offset + 2);
+	} else {
+		writel(b, dev->base + offset);
+	}

}

static u32

Review int i2c_dw_init(struct dw_i2c_dev *dev) · line 277

Quoted 8 lines
(quoted diff) +3 -0
@@ -258,6 +270,12 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
 
 		reg = DW_IC_COMP_TYPE_VALUE;
 
 	}
 
+	/* Configure register access mode 16bit */
+	if (reg == (DW_IC_COMP_TYPE_VALUE & 0x0000ffff)) {
+		dev->access_16bit = 1;

Can we use a suitable macro for 0x0000ffff?

Quoted 8 lines
Quoted 3 lines

Hmmm. Wouldn't that make it more complex? 0x0000ffff is easy to understand. A
marco would "hide" this value. I would prefer to keep the value.

Using a macro doesn't make things 'more complex', but more readable. Magic numbers must be avoided at all cost. A better
named MACRO is always better (for anyone else reading the code) than a magic number like 0x0000ffff.

I really don't share your point of view here. I feel that in this case, the number is much better readable than a macro.

Quoted 36 lines
Quoted 31 lines
Quoted 22 lines

Also, if dev->access_16bit is bool we can simply set:

		dev->access_16bit = true;

more on that below...

Quoted 17 lines
(quoted diff) +3 -0
+		reg = DW_IC_COMP_TYPE_VALUE;
+	}
+
 
(quoted diff) +0 -0
 	if (reg != DW_IC_COMP_TYPE_VALUE) {
 
 		dev_err(dev->dev, "Unknown Synopsys component type: "
 
 			"0x%08x\n", reg);
drivers/i2c/busses/i2c-designware-core.h +0 -0
index 02d1a2d..f5af101 100644
@@ -83,6 +83,7 @@ struct dw_i2c_dev {
 
Quoted 8 lines

drivers/i2c/busses/i2c-designware-core.h struct dw_i2c_dev { · line 88

Quoted 5 lines
drivers/i2c/busses/i2c-designware-core.h +1 -0
 	u32			abort_source;
 	int			irq;
 	int			swab;
 
+	int			access_16bit;

...
int?? Probably we are better off with making this as bool.

Quoted 4 lines

I'm not a big fan of bool's. But I have no strong preference here. My reasoning here was consistency. As we already have "int swab" for a similar
issue.

Quoted 6 lines

If we have not done it earlier, doesn't mean that we repeat the same mistake again. There is no reason to take access_16bit as an int when a bool will suffice.

This wastes storage and on some platforms (which have real crunch of memory), such saving is critical.

Again, I have no big problem changing this to bool.

Quoted 6 lines
Quoted 3 lines

So basically, I would prefer to not make the changes you suggested. But in the
end its the decision of the maintainer(s).

Linux is a collaborative world and patches can be reviewed by literally anyone :)

Sure.

Quoted 2 lines

I am sure the maintainer(s) will find my comments worth adding in your patch..

Might be. But who is the maintainer of this driver?

Thanks,
Stefan

#13 lore raw
In reply to a message not in the archive

Hi Ben,

Quoted 143 lines · On Wednesday 14 March 2012 10:05:40 Stefan Roese wrote:
Quoted 30 lines · On Wednesday 14 March 2012 09:19:22 Bhupesh SHARMA wrote:
Quoted 19 lines
Quoted 6 lines
Quoted 6 lines

+++ b/drivers/i2c/busses/i2c-designware-core.c

(quoted diff) +0 -0
@@ -164,7 +164,14 @@ static char *abort_sources[] = {
 
 u32 dw_readl(struct dw_i2c_dev *dev, int offset)
 {
 
Quoted 12 lines

Review static char *abort_sources[] = { · line 175

Quoted 9 lines
(quoted diff) +8 -1
-	u32 value = readl(dev->base + offset);
+	u32 value;
+
+	if (dev->access_16bit) {
+		value = readw(dev->base + offset) |
+			(readw(dev->base + offset + 2) << 16);
+	} else {
+		value = readl(dev->base + offset);
+	}

We can do away with '{' parenthesis as these are single line of code inside both the 'if-else' blocks.

Quoted 3 lines

It's not a single-line statement. The first block extends spans 2 lines. At
least that how I interpret this CodingStyle recommendation.

???
Breaking a single line of code into two for readability does not make them two separate executable statements.

As per CodingStyle recommendation:
Do not unnecessarily use braces where a single statement will do.

Quoted 6 lines

if (condition)

	action();

So, please modify your patch as braces here waste precious screen space and reduce readability.

I have no strong preferences here. I it helps getting this patch accepted, I'll remove those braces.

Quoted 38 lines
Quoted 38 lines
Quoted 5 lines

Review void dw_writel(struct dw_i2c_dev *dev, u32 b,

Quoted 5 lines
(quoted diff) +0 -0
 	if (dev->swab)
 
(quoted diff) +0 -0
 		return swab32(value);
@@ -177,7 +184,12 @@ void dw_writel(struct dw_i2c_dev *dev, u32 b,

int

Quoted 29 lines
Quoted 19 lines
(quoted diff) +6 -1
 offset)
 
 	if (dev->swab)
 
 		b = swab32(b);
 
-	writel(b, dev->base + offset);
+	if (dev->access_16bit) {
+		writew((u16)b, dev->base + offset);
+		writew((u16)(b >> 16), dev->base + offset + 2);
+	} else {
+		writel(b, dev->base + offset);
+	}

}

static u32

Review int i2c_dw_init(struct dw_i2c_dev *dev) · line 277

Quoted 8 lines
(quoted diff) +3 -0
@@ -258,6 +270,12 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
 
 		reg = DW_IC_COMP_TYPE_VALUE;
 
 	}
 
+	/* Configure register access mode 16bit */
+	if (reg == (DW_IC_COMP_TYPE_VALUE & 0x0000ffff)) {
+		dev->access_16bit = 1;

Can we use a suitable macro for 0x0000ffff?

Quoted 8 lines
Quoted 3 lines

Hmmm. Wouldn't that make it more complex? 0x0000ffff is easy to understand. A
marco would "hide" this value. I would prefer to keep the value.

Using a macro doesn't make things 'more complex', but more readable. Magic numbers must be avoided at all cost. A better
named MACRO is always better (for anyone else reading the code) than a magic number like 0x0000ffff.

I really don't share your point of view here. I feel that in this case, the number is much better readable than a macro.

Quoted 36 lines
Quoted 31 lines
Quoted 22 lines

Also, if dev->access_16bit is bool we can simply set:

		dev->access_16bit = true;

more on that below...

Quoted 17 lines
(quoted diff) +3 -0
+		reg = DW_IC_COMP_TYPE_VALUE;
+	}
+
 
(quoted diff) +0 -0
 	if (reg != DW_IC_COMP_TYPE_VALUE) {
 
 		dev_err(dev->dev, "Unknown Synopsys component type: "
 
 			"0x%08x\n", reg);
drivers/i2c/busses/i2c-designware-core.h +0 -0
index 02d1a2d..f5af101 100644
@@ -83,6 +83,7 @@ struct dw_i2c_dev {
 
Quoted 8 lines

drivers/i2c/busses/i2c-designware-core.h struct dw_i2c_dev { · line 88

Quoted 5 lines
drivers/i2c/busses/i2c-designware-core.h +1 -0
 	u32			abort_source;
 	int			irq;
 	int			swab;
 
+	int			access_16bit;

...
int?? Probably we are better off with making this as bool.

Quoted 4 lines

I'm not a big fan of bool's. But I have no strong preference here. My reasoning here was consistency. As we already have "int swab" for a similar
issue.

Quoted 6 lines

If we have not done it earlier, doesn't mean that we repeat the same mistake again. There is no reason to take access_16bit as an int when a bool will suffice.

This wastes storage and on some platforms (which have real crunch of memory), such saving is critical.

Again, I have no big problem changing this to bool.

Quoted 6 lines
Quoted 3 lines

So basically, I would prefer to not make the changes you suggested. But in the
end its the decision of the maintainer(s).

Linux is a collaborative world and patches can be reviewed by literally anyone :)

Quoted 6 lines

Sure.

Quoted 2 lines

I am sure the maintainer(s) will find my comments worth adding in your patch..

Might be. But who is the maintainer of this driver?

Ben, will you accept this patch as is, or should I make some of the suggested changes (braces, int->bool) and send a patch-v2 out?

Thanks,
Stefan

#14 lore raw
In reply to a message not in the archive

Hi,

my points to this discussion:

Quoted 17 lines · Stefan Roese

The STM SPEAr platform can only access the i2c controller register via 16bit read/write functions. This patch adds support to automatically detect this 16bit access mode.

---
  drivers/i2c/busses/i2c-designware-core.c |   22 ++++++++++++++++++++--
  drivers/i2c/busses/i2c-designware-core.h |    1 +
  2 files changed, 21 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-designware-core.c +0 -0
index df87992..d1facbc 100644
@@ -164,7 +164,14 @@ static char *abort_sources[] = {
 
  u32 dw_readl(struct dw_i2c_dev *dev, int offset)

drivers/i2c/busses/i2c-designware-core.c static char *abort_sources[] = { · line 174

Quoted 10 lines
drivers/i2c/busses/i2c-designware-core.c +8 -1
  {
-	u32 value = readl(dev->base + offset);
+	u32 value;
+
+	if (dev->access_16bit) {
+		value = readw(dev->base + offset) |
+			(readw(dev->base + offset + 2)<<  16);
+	} else {
+		value = readl(dev->base + offset);
+	}

Since both blocks just have one statement, please remove the braces.

Quoted 18 lines
drivers/i2c/busses/i2c-designware-core.c +6 -1
  	if (dev->swab)
  		return swab32(value);
@@ -177,7 +184,12 @@ void dw_writel(struct dw_i2c_dev *dev, u32 b, int offset)
  	if (dev->swab)
  		b = swab32(b);
 
-	writel(b, dev->base + offset);
+	if (dev->access_16bit) {
+		writew((u16)b, dev->base + offset);
+		writew((u16)(b>>  16), dev->base + offset + 2);
+	} else {
+		writel(b, dev->base + offset);
+	}
  }
 
  static u32

drivers/i2c/busses/i2c-designware-core.c int i2c_dw_init(struct dw_i2c_dev *dev) · line 274

Quoted 5 lines
drivers/i2c/busses/i2c-designware-core.c +2 -0
@@ -258,6 +270,12 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
  		reg = DW_IC_COMP_TYPE_VALUE;
  	}
 
+	/* Configure register access mode 16bit */
+	if (reg == (DW_IC_COMP_TYPE_VALUE&  0x0000ffff)) {

No need for a macro IMO. You are missing a space before &, though.

Quoted 12 lines
drivers/i2c/busses/i2c-designware-core.c +4 -0
+		dev->access_16bit = 1;
+		reg = DW_IC_COMP_TYPE_VALUE;
+	}
+
  	if (reg != DW_IC_COMP_TYPE_VALUE) {
  		dev_err(dev->dev, "Unknown Synopsys component type: "
  			"0x%08x\n", reg);
drivers/i2c/busses/i2c-designware-core.h +0 -0
index 02d1a2d..f5af101 100644

drivers/i2c/busses/i2c-designware-core.h struct dw_i2c_dev { · line 86

Quoted 4 lines
drivers/i2c/busses/i2c-designware-core.h +1 -0
@@ -83,6 +83,7 @@ struct dw_i2c_dev {
  	u32			abort_source;
  	int			irq;
  	int			swab;
+	int			access_16bit;

This struct is already quite large. My favourite would be convert swab and access_16bit to 'unsigend accessor_flags' and proper flags. A bitfield at the end of the struct should also do.

Quoted 3 lines
drivers/i2c/busses/i2c-designware-core.h +0 -0
  	struct i2c_adapter	adapter;
  	u32			functionality;
  	u32			master_cfg;
#15 lore raw
In reply to a message not in the archive

Hi,

second try, now with CC list. Forgive me the mangled lines.

My points to this discussion:

Quoted 17 lines · Stefan Roese

The STM SPEAr platform can only access the i2c controller register via 16bit read/write functions. This patch adds support to automatically detect this 16bit access mode.

---
  drivers/i2c/busses/i2c-designware-core.c |   22 ++++++++++++++++++++--
  drivers/i2c/busses/i2c-designware-core.h |    1 +
  2 files changed, 21 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-designware-core.c +0 -0
index df87992..d1facbc 100644
@@ -164,7 +164,14 @@ static char *abort_sources[] = {
 
  u32 dw_readl(struct dw_i2c_dev *dev, int offset)

drivers/i2c/busses/i2c-designware-core.c static char *abort_sources[] = { · line 174

Quoted 10 lines
drivers/i2c/busses/i2c-designware-core.c +8 -1
  {
-    u32 value = readl(dev->base + offset);
+    u32 value;
+
+    if (dev->access_16bit) {
+        value = readw(dev->base + offset) |
+            (readw(dev->base + offset + 2)<<  16);
+    } else {
+        value = readl(dev->base + offset);
+    }

Since both blocks just have one statement, please remove the braces.

Quoted 18 lines
drivers/i2c/busses/i2c-designware-core.c +6 -1
      if (dev->swab)
          return swab32(value);
@@ -177,7 +184,12 @@ void dw_writel(struct dw_i2c_dev *dev, u32 b, int offset)
      if (dev->swab)
          b = swab32(b);
 
-    writel(b, dev->base + offset);
+    if (dev->access_16bit) {
+        writew((u16)b, dev->base + offset);
+        writew((u16)(b>>  16), dev->base + offset + 2);
+    } else {
+        writel(b, dev->base + offset);
+    }
  }
 
  static u32

drivers/i2c/busses/i2c-designware-core.c int i2c_dw_init(struct dw_i2c_dev *dev) · line 274

Quoted 5 lines
drivers/i2c/busses/i2c-designware-core.c +2 -0
@@ -258,6 +270,12 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
          reg = DW_IC_COMP_TYPE_VALUE;
      }
 
+    /* Configure register access mode 16bit */
+    if (reg == (DW_IC_COMP_TYPE_VALUE&  0x0000ffff)) {

No need for a macro IMO. You are missing a space before &, though.

Quoted 12 lines
drivers/i2c/busses/i2c-designware-core.c +4 -0
+        dev->access_16bit = 1;
+        reg = DW_IC_COMP_TYPE_VALUE;
+    }
+
      if (reg != DW_IC_COMP_TYPE_VALUE) {
          dev_err(dev->dev, "Unknown Synopsys component type: "
              "0x%08x\n", reg);
drivers/i2c/busses/i2c-designware-core.h +0 -0
index 02d1a2d..f5af101 100644

drivers/i2c/busses/i2c-designware-core.h struct dw_i2c_dev { · line 86

Quoted 4 lines
drivers/i2c/busses/i2c-designware-core.h +1 -0
@@ -83,6 +83,7 @@ struct dw_i2c_dev {
      u32            abort_source;
      int            irq;
      int            swab;
+    int            access_16bit;

This struct is already quite large. My favourite would be convert swab and access_16bit to 'unsigend accessor_flags' and proper flags. A bitfield at the end of the struct should also do.

Quoted 3 lines
drivers/i2c/busses/i2c-designware-core.h +0 -0
      struct i2c_adapter    adapter;
      u32            functionality;
      u32            master_cfg;