Skip to contentSkip to conversation

RFC - PATCH for s3c2410 i2c missing support

PATCH Ben Dooks 2 participants 4 messages May 19, 2005

Subsystems (2)
lore
Share & tools
lore

Ben Dooks

author
#0 lore raw

This patch (as requested by J Delvare) adds the
following bits which have been missing from the
s3c2410-i2c.c bus driver, as well as a couple of
other minor changes:

1) add a .functionality field to our algo, and
report the facilities.

2) Add I2C_M_REV_DIR_ADDR handling for our start
code, to better support our reported value
from the .functionality probe (the use of
I2C_FUNC_PROTOCOL_MANGLING)

3) change the call to dev_err() to dev_dbg() in
the code that checks for an ack off the
start condition. This avoids the flood of
output when using i2cdetect

4) Add a .algo_control field which points to a
function returning zero.

5) Add an .owner = THIS_MODULE to the adapter

drivers/i2c/busses/i2c-s3c2410.c +19 -2
diff -urN -X ../dontdiff linux-2.6.12-rc1-mm3/drivers/i2c/busses/i2c-s3c2410.c linux-2.6.12-rc1-mm3-i2cf1/drivers/i2c/busses/i2c-s3c2410.c
@@ -1,6 +1,6 @@
 /* linux/drivers/i2c/busses/i2c-s3c2410.c
  *
- * Copyright (C) 2004 Simtec Electronics
+ * Copyright (C) 2004,2005 Simtec Electronics
  *	Ben Dooks <[email protected]>
  *
  * S3C2410 I2C Controller
@@ -188,6 +188,9 @@
 	} else
 		stat |= S3C2410_IICSTAT_MASTER_TX;
 
+	if (msg->flags & I2C_M_REV_DIR_ADDR)
+		addr ^= 1;
+
 	// todo - check for wether ack wanted or not
 	s3c24xx_i2c_enable_ack(i2c);
 
@@ -287,7 +290,7 @@
 		    !(i2c->msg->flags & I2C_M_IGNORE_NAK)) {
 			/* ack was not received... */
 
-			dev_err(i2c->dev, "ack was not received\n" );
+			dev_dbg(i2c->dev, "ack was not received\n" );
 			s3c24xx_i2c_stop(i2c, -EREMOTEIO);
 			goto out_ack;
 		}
@@ -555,11 +558,24 @@
 	return -EREMOTEIO;
 }
 
+static u32 s3c24xx_i2c_func(struct i2c_adapter *adap)
+{
+	return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_PROTOCOL_MANGLING;
+}
+
+static int s3c24xx_i2c_control(struct i2c_adapter *adapter, unsigned int cmd,
+			       unsigned long arg)
+{
+	return 0;
+}
+
 /* i2c bus registration info */
 
 static struct i2c_algorithm s3c24xx_i2c_algorithm = {
 	.name			= "S3C2410-I2C-Algorithm",
 	.master_xfer		= s3c24xx_i2c_xfer,
+	.functionality		= s3c24xx_i2c_func,
+	.algo_control		= s3c24xx_i2c_control,
 };
 
 static struct s3c24xx_i2c s3c24xx_i2c = {
@@ -567,6 +583,7 @@
 	.wait	= __WAIT_QUEUE_HEAD_INITIALIZER(s3c24xx_i2c.wait),
 	.adap	= {
 		.name			= "s3c2410-i2c",
+		.owner			= THIS_MODULE,
 		.algo			= &s3c24xx_i2c_algorithm,
 		.retries		= 2,
 		.class			= I2C_CLASS_HWMON,

-------------- next part --------------

drivers/i2c/busses/i2c-s3c2410.c +19 -2
diff -urN -X ../dontdiff linux-2.6.12-rc1-mm3/drivers/i2c/busses/i2c-s3c2410.c linux-2.6.12-rc1-mm3-i2cf1/drivers/i2c/busses/i2c-s3c2410.c
@@ -1,6 +1,6 @@
 /* linux/drivers/i2c/busses/i2c-s3c2410.c
  *
- * Copyright (C) 2004 Simtec Electronics
+ * Copyright (C) 2004,2005 Simtec Electronics
  *	Ben Dooks <[email protected]>
  *
  * S3C2410 I2C Controller
@@ -188,6 +188,9 @@
 	} else
 		stat |= S3C2410_IICSTAT_MASTER_TX;
 
+	if (msg->flags & I2C_M_REV_DIR_ADDR)
+		addr ^= 1;
+
 	// todo - check for wether ack wanted or not
 	s3c24xx_i2c_enable_ack(i2c);
 
@@ -287,7 +290,7 @@
 		    !(i2c->msg->flags & I2C_M_IGNORE_NAK)) {
 			/* ack was not received... */
 
-			dev_err(i2c->dev, "ack was not received\n" );
+			dev_dbg(i2c->dev, "ack was not received\n" );
 			s3c24xx_i2c_stop(i2c, -EREMOTEIO);
 			goto out_ack;
 		}
@@ -555,11 +558,24 @@
 	return -EREMOTEIO;
 }
 
+static u32 s3c24xx_i2c_func(struct i2c_adapter *adap)
+{
+	return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_PROTOCOL_MANGLING;
+}
+
+static int s3c24xx_i2c_control(struct i2c_adapter *adapter, unsigned int cmd,
+			       unsigned long arg)
+{
+	return 0;
+}
+
 /* i2c bus registration info */
 
 static struct i2c_algorithm s3c24xx_i2c_algorithm = {
 	.name			= "S3C2410-I2C-Algorithm",
 	.master_xfer		= s3c24xx_i2c_xfer,
+	.functionality		= s3c24xx_i2c_func,
+	.algo_control		= s3c24xx_i2c_control,
 };
 
 static struct s3c24xx_i2c s3c24xx_i2c = {
@@ -567,6 +583,7 @@
 	.wait	= __WAIT_QUEUE_HEAD_INITIALIZER(s3c24xx_i2c.wait),
 	.adap	= {
 		.name			= "s3c2410-i2c",
+		.owner			= THIS_MODULE,
 		.algo			= &s3c24xx_i2c_algorithm,
 		.retries		= 2,
 		.class			= I2C_CLASS_HWMON,
author
#1 lore raw
Quoted 19 lines · Jean Delvare

Hi Ben,

Quoted 7 lines

This patch (as requested by J Delvare) adds the
following bits which have been missing from the
s3c2410-i2c.c bus driver, as well as a couple of
other minor changes:

1) add a .functionality field to our algo, and
report the facilities.

Thanks, this will let me go on with core cleanups of the functionalities handling.

Quoted 4 lines

2) Add I2C_M_REV_DIR_ADDR handling for our start
code, to better support our reported value
from the .functionality probe (the use of
I2C_FUNC_PROTOCOL_MANGLING)

Quoted 6 lines

Hm, do you actually need mangling? Protocol mangling is something we added because it was needed in some weird cases, not because we liked it. It's not considered a wanted feature that i2c_adapters should implement whenever possible. It should really only be implemented when there is a concrete need. In my understanding, the need for mangling means that some chip is not properly conforming with the I2C standard.

I added it as the headers seem to suggest that I2C_FUNC_PROTOCOL_MANGLING is indicative of support for I2C_M_NOSTART. Addition of I2C_M_REV_DIR_ADDR was just to make this fuller.

Quoted 7 lines
Quoted 4 lines

3) change the call to dev_err() to dev_dbg() in
the code that checks for an ack off the
start condition. This avoids the flood of
output when using i2cdetect

Makes sense.

Quoted 7 lines
Quoted 2 lines

4) Add a .algo_control field which points to a
function returning zero.

Hmm, why? The i2c-core deals properly with NULL algo_control. Poiting to a function which returns 0 will be exactly the same than having no function defined at all, but eats a few bytes of memory and wastes time as well.

Ok, just noticed at least one other bus driver seems to implement it (i2c-iop3xx). I can remove this easily.

Quoted 3 lines
Quoted 1 line

5) Add an .owner = THIS_MODULE to the adapter

I had not noticed it was missing, you're absolutely right.

My home mailsystem is now fixed, so all messages to the list can be read again. Mail lost between 22nd and 24th.

Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
#2 lore raw
In reply to Ben Dooks

Hi Ben,

Quoted 7 lines

This patch (as requested by J Delvare) adds the
following bits which have been missing from the
s3c2410-i2c.c bus driver, as well as a couple of
other minor changes:

1) add a .functionality field to our algo, and
report the facilities.

Thanks, this will let me go on with core cleanups of the functionalities handling.

Quoted 4 lines

2) Add I2C_M_REV_DIR_ADDR handling for our start
code, to better support our reported value
from the .functionality probe (the use of
I2C_FUNC_PROTOCOL_MANGLING)

Hm, do you actually need mangling? Protocol mangling is something we added because it was needed in some weird cases, not because we liked it. It's not considered a wanted feature that i2c_adapters should implement whenever possible. It should really only be implemented when there is a concrete need. In my understanding, the need for mangling means that some chip is not properly conforming with the I2C standard.

Quoted 4 lines

3) change the call to dev_err() to dev_dbg() in
the code that checks for an ack off the
start condition. This avoids the flood of
output when using i2cdetect

Makes sense.

Quoted 2 lines

4) Add a .algo_control field which points to a
function returning zero.

Hmm, why? The i2c-core deals properly with NULL algo_control. Poiting to a function which returns 0 will be exactly the same than having no function defined at all, but eats a few bytes of memory and wastes time as well.

Quoted 1 line

5) Add an .owner = THIS_MODULE to the adapter

I had not noticed it was missing, you're absolutely right.

Thanks,
--
Jean Delvare

#3 lore raw
In reply to Ben Dooks

Hi Ben,

Quoted 11 lines
Quoted 6 lines

Hm, do you actually need mangling? Protocol mangling is something we added because it was needed in some weird cases, not because we liked it. It's not considered a wanted feature that i2c_adapters should implement whenever possible. It should really only be implemented when there is a concrete need. In my understanding, the need for mangling means that some chip is not properly conforming with the I2C standard.

I added it as the headers seem to suggest that I2C_FUNC_PROTOCOL_MANGLING is indicative of support for I2C_M_NOSTART. Addition of I2C_M_REV_DIR_ADDR was just to make this fuller.

OK. If you actually need I2C_M_NOSTART, then that was exactly the right thing to do.

Quoted 7 lines
Quoted 4 lines

Hmm, why? The i2c-core deals properly with NULL algo_control. Poiting to a function which returns 0 will be exactly the same than having no function defined at all, but eats a few bytes of memory and wastes time as well.

Ok, just noticed at least one other bus driver seems to implement it (i2c-iop3xx). I can remove this easily.

Please do.

I would welcome additional patches fixing the drivers which define it for no reason (i2c-algo-sibyte, saa7134-i2c, bttv-i2c, w9968cf).

Quoted 2 lines

My home mailsystem is now fixed, so all messages to the list can be read again. Mail lost between 22nd and 24th.

Ouch, sorry to learn that. You can consult the archives in case you think you missed something specific. If you want the originals of anything, just ask.

Thanks,
--
Jean Delvare