linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i2c-isch: Add module parameter for backbone clock rate if divider is unset
@ 2013-01-23 10:34 Alexander Stein
       [not found] ` <1358937274-14908-1-git-send-email-alexander.stein-93q1YBGzJSMe9JSWTWOYM3xStJ4P+DSV@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Alexander Stein @ 2013-01-23 10:34 UTC (permalink / raw)
  To: Jean Delvare, Wolfram Sang, Ben Dooks (embedded platforms)
  Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA, Alexander Stein

It was observed the Host Clock Divider was not written by the driver. It
was still set to (default) 0, if not already set by BIOS, which caused
garbage on SMBus.
This driver adds a parameters which is used to calculate the divider
appropriately for a default bitrate of 100 KHz. This new divider is only
applied if the clock divider is still default 0.

Signed-off-by: Alexander Stein <alexander.stein-93q1YBGzJSMe9JSWTWOYM3xStJ4P+DSV@public.gmane.org>
---
This patch supersedes the older patch
 i2c-isch: Add module parameter which actually set the clock divider
from 2012. It now has only one parameter to set the backbone clock rate which
is guessed to 33 MHz which is the maximum for both device the lpc_sch driver
is for. It registers a single i2c_smbus platform device.
To my knowledge we can't determine if we have 33 or 25 MHz clock for SMBus,
so expect 33 MHz and calculate a bus clock of 100 kHz. If we actually run
at 25 MHz the bus will be run ~75 kHz instead which should do no harm.

 drivers/i2c/busses/i2c-isch.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/i2c/busses/i2c-isch.c b/drivers/i2c/busses/i2c-isch.c
index 4099f79..495d28f 100644
--- a/drivers/i2c/busses/i2c-isch.c
+++ b/drivers/i2c/busses/i2c-isch.c
@@ -40,6 +40,7 @@
 /* SCH SMBus address offsets */
 #define SMBHSTCNT	(0 + sch_smba)
 #define SMBHSTSTS	(1 + sch_smba)
+#define SMBHSTCLK	(2 + sch_smba)
 #define SMBHSTADD	(4 + sch_smba) /* TSA */
 #define SMBHSTCMD	(5 + sch_smba)
 #define SMBHSTDAT0	(6 + sch_smba)
@@ -58,6 +59,7 @@
 
 static unsigned short sch_smba;
 static struct i2c_adapter sch_adapter;
+static int backbone_speed = 33000; /* backbone speed in KHz */
 
 /*
  * Start the i2c transaction -- the i2c_access will prepare the transaction
@@ -156,6 +158,14 @@ static s32 sch_access(struct i2c_adapter *adap, u16 addr,
 		dev_dbg(&sch_adapter.dev, "SMBus busy (%02x)\n", temp);
 		return -EAGAIN;
 	}
+	temp = inw(SMBHSTCLK);
+	if (!temp) {
+		int smbus_speed = 100;
+		dev_notice(&sch_adapter.dev, "clock divider unitialized. Setting module defaults\n");
+		dev_dbg(&sch_adapter.dev, "access speed: %d KHz\n", smbus_speed);
+		outw((backbone_speed / 4) / smbus_speed, SMBHSTCLK);
+	}
+
 	dev_dbg(&sch_adapter.dev, "access size: %d %s\n", size,
 		(read_write)?"READ":"WRITE");
 	switch (size) {
@@ -312,3 +322,4 @@ MODULE_AUTHOR("Jacob Pan <jacob.jun.pan-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>");
 MODULE_DESCRIPTION("Intel SCH SMBus driver");
 MODULE_LICENSE("GPL");
 MODULE_ALIAS("platform:isch_smbus");
+module_param(backbone_speed, int, (S_IRUSR | S_IWUSR));
-- 
1.8.1.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] i2c-isch: Add module parameter for backbone clock rate if divider is unset
       [not found] ` <1358937274-14908-1-git-send-email-alexander.stein-93q1YBGzJSMe9JSWTWOYM3xStJ4P+DSV@public.gmane.org>
@ 2013-01-25  9:32   ` Wolfram Sang
  2013-01-25  9:59   ` Jean Delvare
  1 sibling, 0 replies; 3+ messages in thread
From: Wolfram Sang @ 2013-01-25  9:32 UTC (permalink / raw)
  To: Alexander Stein
  Cc: Jean Delvare, Ben Dooks (embedded platforms),
	linux-i2c-u79uwXL29TY76Z2rM5mHXA

[-- Attachment #1: Type: text/plain, Size: 3231 bytes --]

On Wed, Jan 23, 2013 at 11:34:34AM +0100, Alexander Stein wrote:
> It was observed the Host Clock Divider was not written by the driver. It
> was still set to (default) 0, if not already set by BIOS, which caused
> garbage on SMBus.
> This driver adds a parameters which is used to calculate the divider
> appropriately for a default bitrate of 100 KHz. This new divider is only
> applied if the clock divider is still default 0.
> 
> Signed-off-by: Alexander Stein <alexander.stein-93q1YBGzJSMe9JSWTWOYM3xStJ4P+DSV@public.gmane.org>

Maybe Jean has something to add, but my remarks are...

> ---
> This patch supersedes the older patch
>  i2c-isch: Add module parameter which actually set the clock divider
> from 2012. It now has only one parameter to set the backbone clock rate which
> is guessed to 33 MHz which is the maximum for both device the lpc_sch driver
> is for. It registers a single i2c_smbus platform device.
> To my knowledge we can't determine if we have 33 or 25 MHz clock for SMBus,
> so expect 33 MHz and calculate a bus clock of 100 kHz. If we actually run
> at 25 MHz the bus will be run ~75 kHz instead which should do no harm.

This last paragraph should be a comment at the place you set the default
value.

> 
>  drivers/i2c/busses/i2c-isch.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/drivers/i2c/busses/i2c-isch.c b/drivers/i2c/busses/i2c-isch.c
> index 4099f79..495d28f 100644
> --- a/drivers/i2c/busses/i2c-isch.c
> +++ b/drivers/i2c/busses/i2c-isch.c
> @@ -40,6 +40,7 @@
>  /* SCH SMBus address offsets */
>  #define SMBHSTCNT	(0 + sch_smba)
>  #define SMBHSTSTS	(1 + sch_smba)
> +#define SMBHSTCLK	(2 + sch_smba)
>  #define SMBHSTADD	(4 + sch_smba) /* TSA */
>  #define SMBHSTCMD	(5 + sch_smba)
>  #define SMBHSTDAT0	(6 + sch_smba)
> @@ -58,6 +59,7 @@
>  
>  static unsigned short sch_smba;
>  static struct i2c_adapter sch_adapter;
> +static int backbone_speed = 33000; /* backbone speed in KHz */
>  
>  /*
>   * Start the i2c transaction -- the i2c_access will prepare the transaction
> @@ -156,6 +158,14 @@ static s32 sch_access(struct i2c_adapter *adap, u16 addr,
>  		dev_dbg(&sch_adapter.dev, "SMBus busy (%02x)\n", temp);
>  		return -EAGAIN;
>  	}
> +	temp = inw(SMBHSTCLK);
> +	if (!temp) {
> +		int smbus_speed = 100;
> +		dev_notice(&sch_adapter.dev, "clock divider unitialized. Setting module defaults\n");
> +		dev_dbg(&sch_adapter.dev, "access speed: %d KHz\n", smbus_speed);

That debug can go since this is a constant value anyhow.

> +		outw((backbone_speed / 4) / smbus_speed, SMBHSTCLK);
> +	}
> +
>  	dev_dbg(&sch_adapter.dev, "access size: %d %s\n", size,
>  		(read_write)?"READ":"WRITE");
>  	switch (size) {
> @@ -312,3 +322,4 @@ MODULE_AUTHOR("Jacob Pan <jacob.jun.pan-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>");
>  MODULE_DESCRIPTION("Intel SCH SMBus driver");
>  MODULE_LICENSE("GPL");
>  MODULE_ALIAS("platform:isch_smbus");
> +module_param(backbone_speed, int, (S_IRUSR | S_IWUSR));

Thanks,

   Wolfram

-- 
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] i2c-isch: Add module parameter for backbone clock rate if divider is unset
       [not found] ` <1358937274-14908-1-git-send-email-alexander.stein-93q1YBGzJSMe9JSWTWOYM3xStJ4P+DSV@public.gmane.org>
  2013-01-25  9:32   ` Wolfram Sang
@ 2013-01-25  9:59   ` Jean Delvare
  1 sibling, 0 replies; 3+ messages in thread
From: Jean Delvare @ 2013-01-25  9:59 UTC (permalink / raw)
  To: Alexander Stein
  Cc: Wolfram Sang, Ben Dooks (embedded platforms),
	linux-i2c-u79uwXL29TY76Z2rM5mHXA

Hi Alexander,

On Wed, 23 Jan 2013 11:34:34 +0100, Alexander Stein wrote:
> It was observed the Host Clock Divider was not written by the driver. It
> was still set to (default) 0, if not already set by BIOS, which caused
> garbage on SMBus.
> This driver adds a parameters which is used to calculate the divider
> appropriately for a default bitrate of 100 KHz. This new divider is only
> applied if the clock divider is still default 0.
> 
> Signed-off-by: Alexander Stein <alexander.stein-93q1YBGzJSMe9JSWTWOYM3xStJ4P+DSV@public.gmane.org>
> ---
> This patch supersedes the older patch
>  i2c-isch: Add module parameter which actually set the clock divider
> from 2012. It now has only one parameter to set the backbone clock rate which
> is guessed to 33 MHz which is the maximum for both device the lpc_sch driver
> is for. It registers a single i2c_smbus platform device.
> To my knowledge we can't determine if we have 33 or 25 MHz clock for SMBus,
> so expect 33 MHz and calculate a bus clock of 100 kHz. If we actually run
> at 25 MHz the bus will be run ~75 kHz instead which should do no harm.
> 
>  drivers/i2c/busses/i2c-isch.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/drivers/i2c/busses/i2c-isch.c b/drivers/i2c/busses/i2c-isch.c
> index 4099f79..495d28f 100644
> --- a/drivers/i2c/busses/i2c-isch.c
> +++ b/drivers/i2c/busses/i2c-isch.c
> @@ -40,6 +40,7 @@
>  /* SCH SMBus address offsets */
>  #define SMBHSTCNT	(0 + sch_smba)
>  #define SMBHSTSTS	(1 + sch_smba)
> +#define SMBHSTCLK	(2 + sch_smba)
>  #define SMBHSTADD	(4 + sch_smba) /* TSA */
>  #define SMBHSTCMD	(5 + sch_smba)
>  #define SMBHSTDAT0	(6 + sch_smba)
> @@ -58,6 +59,7 @@
>  
>  static unsigned short sch_smba;
>  static struct i2c_adapter sch_adapter;
> +static int backbone_speed = 33000; /* backbone speed in KHz */

Although I know it is a very common mistake, the proper casing is kHz.

>  
>  /*
>   * Start the i2c transaction -- the i2c_access will prepare the transaction
> @@ -156,6 +158,14 @@ static s32 sch_access(struct i2c_adapter *adap, u16 addr,
>  		dev_dbg(&sch_adapter.dev, "SMBus busy (%02x)\n", temp);
>  		return -EAGAIN;
>  	}
> +	temp = inw(SMBHSTCLK);
> +	if (!temp) {
> +		int smbus_speed = 100;
> +		dev_notice(&sch_adapter.dev, "clock divider unitialized. Setting module defaults\n");

Start the log message with a capital. Move the string to the next line
to limit line length. "Setting module defaults" is not useful
information for the user, not to mention that it is incorrect (the
module default is uninitialized, that's exactly the problem.)

> +		dev_dbg(&sch_adapter.dev, "access speed: %d KHz\n", smbus_speed);
> +		outw((backbone_speed / 4) / smbus_speed, SMBHSTCLK);

Useless debug statement. Just hardcode smbus_speed to 100 in the
formula. BTW I suspect that backbone_speed / (4 * 100) would be more
efficient.

> +	}
> +
>  	dev_dbg(&sch_adapter.dev, "access size: %d %s\n", size,
>  		(read_write)?"READ":"WRITE");
>  	switch (size) {
> @@ -312,3 +322,4 @@ MODULE_AUTHOR("Jacob Pan <jacob.jun.pan-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>");
>  MODULE_DESCRIPTION("Intel SCH SMBus driver");
>  MODULE_LICENSE("GPL");
>  MODULE_ALIAS("platform:isch_smbus");
> +module_param(backbone_speed, int, (S_IRUSR | S_IWUSR));

Please group the variable declaration and the module parameter
declaration. The parentheses around S_IRUSR | S_IWUSR aren't needed.
Please add a module parameter description, including the unit and
default value.

-- 
Jean Delvare

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-01-25  9:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-23 10:34 [PATCH] i2c-isch: Add module parameter for backbone clock rate if divider is unset Alexander Stein
     [not found] ` <1358937274-14908-1-git-send-email-alexander.stein-93q1YBGzJSMe9JSWTWOYM3xStJ4P+DSV@public.gmane.org>
2013-01-25  9:32   ` Wolfram Sang
2013-01-25  9:59   ` Jean Delvare

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).