Skip to contentSkip to conversation

More i2c driver changes for 2.5.70

PATCH New Greg KH 2 participants 8 messages Jun 11, 2003 – Jun 12, 2003 I2C

lore
Share & tools
lore

Greg KH

author
#0 lore raw

PATCH 1/1 More i2c driver changes for 2.5.70

Hi,

Here are some more i2c driver changes for 2.5.70. These consist of a new i2c client driver, a new i2c bus driver, some coding style fixes for the new bus driver, and a bunch of sparse warning removels.

Please pull from: bk://kernel.bkbits.net/gregkh/linux/i2c-2.5

thanks,

greg k-h

-----

 drivers/i2c/Kconfig        |    4 
 drivers/i2c/Makefile       |    1 
 drivers/i2c/chips/Kconfig  |   19 
 drivers/i2c/chips/Makefile |    1 
 drivers/i2c/chips/lm85.c   | 1223 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/i2c/i2c-core.c     |   36 -
 drivers/i2c/i2c-dev.c      |   10 
 drivers/i2c/i2c-iop3xx.c   |  868 +++++++++++++++++++++++++------
 drivers/i2c/i2c-iop3xx.h   |  238 ++++++--
 include/linux/i2c-dev.h    |    6 
 include/linux/i2c.h        |    4 
 11 files changed, 2150 insertions(+), 260 deletions(-)

-----

<margitsw:t-online.de>:
o I2C: add LM85 driver

<peterm:remware.demon.co.uk>:
o I2C: add New bus driver: XSCALE iop3xx

Greg Kroah-Hartman:
o I2C: fix up sparse warnings in the i2c-dev driver
o I2C: fix up sparse warnings in drivers/i2c/i2c-core.c
o I2C: fix some errors found by sparse in include/linux/i2c.h
o I2C: coding style updates for i2c-iop3xx driver

author
#1 lore raw

PATCH 1/1 More i2c driver changes for 2.5.70

ChangeSet 1.1419.1.3, 2003/06/11 11:42:47-07:00, [email protected]

[PATCH] I2C: add LM85 driver

Nothing extra in sysfs (yet) but I have left the way open in the driver to do this.
Provides vid, vrm, fan_input(1-4), fan_min(1-4), pwm(1-3), pwm_enable(1-3), in_input(0-4), in_min(0-4), in_max(0-4), temp_input(1-3), temp_min(1-3), temp_max(1-3), alarms.

 drivers/i2c/chips/Kconfig  |   19 
 drivers/i2c/chips/Makefile |    1 
 drivers/i2c/chips/lm85.c   | 1223 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1241 insertions(+), 2 deletions(-)
drivers/i2c/chips/Kconfig +17 -2
diff -Nru a/drivers/i2c/chips/Kconfig b/drivers/i2c/chips/Kconfig
@@ -47,6 +47,21 @@
 	  in the lm_sensors package, which you can download at 
 	  http://www.lm-sensors.nu
 	  
+config SENSORS_LM85
+	tristate "  National Semiconductors LM85 and compatibles"
+	depends on I2C && EXPERIMENTAL
+	help
+	  If you say yes here you get support for National Semiconductor LM85
+	  sensor chips and clones: ADT7463 and ADM1027.
+	  This can also be built as a module which can be inserted and
+	  removed while the kernel is running.
+
+	  The module will be called lm85.
+
+	  You will also need the latest user-space utilties: you can find them
+	  in the lm_sensors package, which you can download at 
+	  http://www.lm-sensors.nu
+	  
 config SENSORS_VIA686A
 	tristate "  VIA686A"
 	depends on I2C && EXPERIMENTAL
@@ -76,8 +91,8 @@
 
 config I2C_SENSOR
 	tristate
-	default y if SENSORS_ADM1021=y || SENSORS_IT87=y || SENSORS_LM75=y || SENSORS_VIA686A=y || SENSORS_W83781D=y
-	default m if SENSORS_ADM1021=m || SENSORS_IT87=m || SENSORS_LM75=m || SENSORS_VIA686A=m || SENSORS_W83781D=m
+	default y if SENSORS_ADM1021=y || SENSORS_IT87=y || SENSORS_LM75=y || SENSORS_VIA686A=y || SENSORS_W83781D=y || SENSORS_LM85=y
+	default m if SENSORS_ADM1021=m || SENSORS_IT87=m || SENSORS_LM75=m || SENSORS_VIA686A=m || SENSORS_W83781D=m || SENSORS_LM85=m
 	default n
 
 endmenu
drivers/i2c/chips/Makefile +1 -0
diff -Nru a/drivers/i2c/chips/Makefile b/drivers/i2c/chips/Makefile
@@ -5,5 +5,6 @@
 obj-$(CONFIG_SENSORS_ADM1021)	+= adm1021.o
 obj-$(CONFIG_SENSORS_IT87)	+= it87.o
 obj-$(CONFIG_SENSORS_LM75)	+= lm75.o
+obj-$(CONFIG_SENSORS_LM85)	+= lm85.o
 obj-$(CONFIG_SENSORS_VIA686A)	+= via686a.o
 obj-$(CONFIG_SENSORS_W83781D)	+= w83781d.o
drivers/i2c/chips/lm85.c new file +1223 -0

1,223 lines not on this page · raw message

author
#2 lore raw

ChangeSet 1.1419.1.4, 2003/06/11 11:43:02-07:00, [email protected]

[PATCH] I2C: add New bus driver: XSCALE iop3xx

 drivers/i2c/Kconfig      |    4 
 drivers/i2c/Makefile     |    1 
 drivers/i2c/i2c-iop3xx.c |  565 +++++++++++++++++++++++++++++++++++++++++++++++
 drivers/i2c/i2c-iop3xx.h |  120 +++++++++
 4 files changed, 690 insertions(+)
drivers/i2c/Kconfig +4 -0
diff -Nru a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig
@@ -193,6 +193,10 @@
 	tristate "IBM on-chip I2C Adapter"
 	depends on I2C_IBM_OCP_ALGO
 
+config I2C_IOP3XX
+	tristate "Intel XScale IOP3xx on-chip I2C interface"
+	depends on ARCH_IOP3XX && I2C
+
 config I2C_CHARDEV
 	tristate "I2C device interface"
 	depends on I2C
drivers/i2c/Makefile +1 -0
diff -Nru a/drivers/i2c/Makefile b/drivers/i2c/Makefile
@@ -16,4 +16,5 @@
 obj-$(CONFIG_SCx200_I2C)	+= scx200_i2c.o
 obj-$(CONFIG_SCx200_ACB)	+= scx200_acb.o
 obj-$(CONFIG_I2C_SENSOR)	+= i2c-sensor.o
+obj-$(CONFIG_I2C_IOP3XX)	+= i2c-iop3xx.o
 obj-y				+= busses/ chips/
drivers/i2c/i2c-iop3xx.c new file +565 -0

565 lines not on this page · raw message

drivers/i2c/i2c-iop3xx.h new file +120 -0

120 lines not on this page · raw message

author
#3 lore raw

ChangeSet 1.1419.1.5, 2003/06/11 12:07:27-07:00, [email protected]

[PATCH] I2C: coding style updates for i2c-iop3xx driver

 drivers/i2c/i2c-iop3xx.c |  303 +++++++++++++++++++++--------------------------
 drivers/i2c/i2c-iop3xx.h |  118 ++++++++----------
 2 files changed, 195 insertions(+), 226 deletions(-)
drivers/i2c/i2c-iop3xx.c +137 -166
diff -Nru a/drivers/i2c/i2c-iop3xx.c b/drivers/i2c/i2c-iop3xx.c
@@ -50,8 +50,8 @@
 
 /* ----- global defines ----------------------------------------------- */
 #define PASSERT(x) do { if (!(x) ) \
-                printk(KERN_CRIT "PASSERT %s in %s:%d\n", #x, __FILE__, __LINE__ );\
-        } while (0)
+		printk(KERN_CRIT "PASSERT %s in %s:%d\n", #x, __FILE__, __LINE__ );\
+	} while (0)
 
 
 /* ----- global variables ---------------------------------------------	*/
@@ -61,13 +61,13 @@
 {
 	unsigned char addr;
 
-	addr = ( msg->addr << 1 );
+	addr = (msg->addr << 1);
 
-	if (msg->flags & I2C_M_RD )
+	if (msg->flags & I2C_M_RD)
 		addr |= 1;
 
-/* PGM: what is M_REV_DIR_ADDR - do we need it ?? */
-	if (msg->flags & I2C_M_REV_DIR_ADDR )
+	/* PGM: what is M_REV_DIR_ADDR - do we need it ?? */
+	if (msg->flags & I2C_M_REV_DIR_ADDR)
 		addr ^= 1;
 
 	return addr;   
@@ -76,100 +76,93 @@
 
 static inline void iop3xx_adap_reset(struct i2c_algo_iop3xx_data *iop3xx_adap)
 {
-	// Follows devman 9.3
+	/* Follows devman 9.3 */
 	*iop3xx_adap->biu->CR = IOP321_ICR_UNIT_RESET;
 	*iop3xx_adap->biu->SR = IOP321_ISR_CLEARBITS;
 	*iop3xx_adap->biu->CR = 0;
 } 
 
-static inline void iop3xx_adap_set_slave_addr(
-	struct i2c_algo_iop3xx_data *iop3xx_adap )
+static inline void iop3xx_adap_set_slave_addr(struct i2c_algo_iop3xx_data *iop3xx_adap)
 {
 	*iop3xx_adap->biu->SAR = MYSAR;
 }
 
-static inline void iop3xx_adap_enable( 
-	struct i2c_algo_iop3xx_data *iop3xx_adap )
+static inline void iop3xx_adap_enable(struct i2c_algo_iop3xx_data *iop3xx_adap)
 {
 	u32 cr = IOP321_ICR_GCD|IOP321_ICR_SCLEN|IOP321_ICR_UE;
 
-/* NB SR bits not same position as CR IE bits :-( */
+	/* NB SR bits not same position as CR IE bits :-( */
 	iop3xx_adap->biu->SR_enabled = 
-		IOP321_ISR_ALD|IOP321_ISR_BERRD|
-		IOP321_ISR_RXFULL|IOP321_ISR_TXEMPTY;
+		IOP321_ISR_ALD | IOP321_ISR_BERRD |
+		IOP321_ISR_RXFULL | IOP321_ISR_TXEMPTY;
 
-	cr |= IOP321_ICR_ALDIE|IOP321_ICR_BERRIE|
-		IOP321_ICR_RXFULLIE|IOP321_ICR_TXEMPTYIE;
+	cr |= IOP321_ICR_ALDIE | IOP321_ICR_BERRIE |
+		IOP321_ICR_RXFULLIE | IOP321_ICR_TXEMPTYIE;
 
 	*iop3xx_adap->biu->CR = cr;
 }
 
-static void iop3xx_adap_transaction_cleanup( 
-	struct i2c_algo_iop3xx_data *iop3xx_adap )
+static void iop3xx_adap_transaction_cleanup(struct i2c_algo_iop3xx_data *iop3xx_adap)
 {
 	unsigned cr = *iop3xx_adap->biu->CR;
 	
 	cr &= ~(IOP321_ICR_MSTART | IOP321_ICR_TBYTE | 
-		IOP321_ICR_MSTOP | IOP321_ICR_SCLEN );
+		IOP321_ICR_MSTOP | IOP321_ICR_SCLEN);
 	*iop3xx_adap->biu->CR = cr;
 }
 
-static void iop3xx_adap_final_cleanup( 
-	struct i2c_algo_iop3xx_data *iop3xx_adap )
+static void iop3xx_adap_final_cleanup(struct i2c_algo_iop3xx_data *iop3xx_adap)
 {
 	unsigned cr = *iop3xx_adap->biu->CR;
 	
-	cr &= ~(IOP321_ICR_ALDIE|IOP321_ICR_BERRIE|
-		IOP321_ICR_RXFULLIE|IOP321_ICR_TXEMPTYIE);
+	cr &= ~(IOP321_ICR_ALDIE | IOP321_ICR_BERRIE |
+		IOP321_ICR_RXFULLIE | IOP321_ICR_TXEMPTYIE);
 	iop3xx_adap->biu->SR_enabled = 0;
 	*iop3xx_adap->biu->CR = cr;
 }
 
-
-
-static void iop3xx_i2c_handler( int this_irq, 
-				void *dev_id, 
-				struct pt_regs *regs) 
 /* 
  * NB: the handler has to clear the source of the interrupt! 
  * Then it passes the SR flags of interest to BH via adap data
  */
+static void iop3xx_i2c_handler(int this_irq, 
+				void *dev_id, 
+				struct pt_regs *regs) 
 {
 	struct i2c_algo_iop3xx_data *iop3xx_adap = dev_id;
 
 	u32 sr = *iop3xx_adap->biu->SR;
 
-	if ( (sr &= iop3xx_adap->biu->SR_enabled) ){
+	if ((sr &= iop3xx_adap->biu->SR_enabled)) {
 		*iop3xx_adap->biu->SR = sr;
 		iop3xx_adap->biu->SR_received |= sr;
 		wake_up_interruptible(&iop3xx_adap->waitq);
 	}
 }
 
-
-static int iop3xx_adap_error( u32 sr )
-// check all error conditions, clear them , report most important
+/* check all error conditions, clear them , report most important */
+static int iop3xx_adap_error(u32 sr)
 {
 	int rc = 0;
 
-	if ( (sr&IOP321_ISR_BERRD) ) {
+	if ((sr&IOP321_ISR_BERRD)) {
 		if ( !rc ) rc = -I2C_ERR_BERR;
 	}
-	if ( (sr&IOP321_ISR_ALD) ){
+	if ((sr&IOP321_ISR_ALD)) {
 		if ( !rc ) rc = -I2C_ERR_ALD;		
 	}
 	return rc;	
 }
 
-static inline u32 get_srstat( struct i2c_algo_iop3xx_data *iop3xx_adap  )
+static inline u32 get_srstat(struct i2c_algo_iop3xx_data *iop3xx_adap)
 {
 	unsigned long flags;
 	u32 sr;
 
-	spin_lock_irqsave( &iop3xx_adap->lock, flags );
+	spin_lock_irqsave(&iop3xx_adap->lock, flags);
 	sr = iop3xx_adap->biu->SR_received;
 	iop3xx_adap->biu->SR_received = 0;
-	spin_unlock_irqrestore( &iop3xx_adap->lock, flags );
+	spin_unlock_irqrestore(&iop3xx_adap->lock, flags);
 
 	return sr;
 }
@@ -178,12 +171,12 @@
  * sleep until interrupted, then recover and analyse the SR
  * saved by handler
  */
-typedef int (* CompareFunc)( unsigned test, unsigned mask );
+typedef int (* compare_func)(unsigned test, unsigned mask);
 /* returns 1 on correct comparison */
 
-static int iop3xx_adap_wait_event( struct i2c_algo_iop3xx_data *iop3xx_adap, 
-			    unsigned flags, unsigned* status,
-			    CompareFunc compare )
+static int iop3xx_adap_wait_event(struct i2c_algo_iop3xx_data *iop3xx_adap, 
+				  unsigned flags, unsigned* status,
+				  compare_func compare)
 {
 	unsigned sr = 0;
 	int interrupted;
@@ -196,100 +189,94 @@
 			(done = compare( sr = get_srstat(iop3xx_adap),flags )),
 			iop3xx_adap->timeout
 			);
-		if ( (rc = iop3xx_adap_error( sr )) < 0 ){
+		if ((rc = iop3xx_adap_error(sr)) < 0) {
 			*status = sr;
 			return rc;
-		}else if ( !interrupted ){
+		}else if (!interrupted) {
 			*status = sr;
 			return rc = -ETIMEDOUT;
 		}
-	} while( !done );
+	} while(!done);
 
 	*status = sr;
 
 	return rc = 0;
 }
 
-
-
-
 /*
- * Concrete CompareFuncs 
+ * Concrete compare_funcs 
  */
-static int all_bits_clear( unsigned test, unsigned mask ) {
-	return (test&mask) == 0;
+static int all_bits_clear(unsigned test, unsigned mask)
+{
+	return (test & mask) == 0;
 }
-static int any_bits_set( unsigned test, unsigned mask ) {
-	return (test&mask) != 0;
+static int any_bits_set(unsigned test, unsigned mask)
+{
+	return (test & mask) != 0;
 }
 
-
-static int iop3xx_adap_wait_tx_done(
-	struct i2c_algo_iop3xx_data *iop3xx_adap, int *status)
+static int iop3xx_adap_wait_tx_done(struct i2c_algo_iop3xx_data *iop3xx_adap, int *status)
 {
 	return iop3xx_adap_wait_event( 
 		iop3xx_adap, 
 	        IOP321_ISR_TXEMPTY|IOP321_ISR_ALD|IOP321_ISR_BERRD,
-		status, any_bits_set );
+		status, any_bits_set);
 }
 
-static int iop3xx_adap_wait_rx_done(
-	struct i2c_algo_iop3xx_data *iop3xx_adap, int *status)
+static int iop3xx_adap_wait_rx_done(struct i2c_algo_iop3xx_data *iop3xx_adap, int *status)
 {
 	return iop3xx_adap_wait_event( 
 		iop3xx_adap, 
 		IOP321_ISR_RXFULL|IOP321_ISR_ALD|IOP321_ISR_BERRD,
-		status,	any_bits_set );
+		status,	any_bits_set);
 }
 
-static int iop3xx_adap_wait_idle(
-	struct i2c_algo_iop3xx_data *iop3xx_adap, int *status)
+static int iop3xx_adap_wait_idle(struct i2c_algo_iop3xx_data *iop3xx_adap, int *status)
 {
 	return iop3xx_adap_wait_event( 
-		iop3xx_adap, IOP321_ISR_UNITBUSY, status, all_bits_clear );
+		iop3xx_adap, IOP321_ISR_UNITBUSY, status, all_bits_clear);
 }
 
-//
-// Description: This performs the IOP3xx initialization sequence
-// Valid for IOP321. Maybe valid for IOP310?.
-//
+/*
+ * Description: This performs the IOP3xx initialization sequence
+ * Valid for IOP321. Maybe valid for IOP310?.
+ */
 static int iop3xx_adap_init (struct i2c_algo_iop3xx_data *iop3xx_adap)
 {
-	*IOP321_GPOD &= ~(iop3xx_adap->channel==0?
+	*IOP321_GPOD &= ~(iop3xx_adap->channel==0 ?
 			  IOP321_GPOD_I2C0:
 			  IOP321_GPOD_I2C1);
 
-	iop3xx_adap_reset( iop3xx_adap );
-	iop3xx_adap_set_slave_addr( iop3xx_adap );
-	iop3xx_adap_enable( iop3xx_adap );
+	iop3xx_adap_reset(iop3xx_adap);
+	iop3xx_adap_set_slave_addr(iop3xx_adap);
+	iop3xx_adap_enable(iop3xx_adap);
 	
         return 0;
 }
 
-static int iop3xx_adap_send_target_slave_addr( 
-	struct i2c_algo_iop3xx_data *iop3xx_adap, struct i2c_msg* msg )
+static int iop3xx_adap_send_target_slave_addr(struct i2c_algo_iop3xx_data *iop3xx_adap,
+					      struct i2c_msg* msg)
 {
 	unsigned cr = *iop3xx_adap->biu->CR;
 	int status;
 	int rc;
 
-	*iop3xx_adap->biu->DBR = iic_cook_addr( msg );
+	*iop3xx_adap->biu->DBR = iic_cook_addr(msg);
 	
-	cr &= ~(IOP321_ICR_MSTOP|IOP321_ICR_NACK);
+	cr &= ~(IOP321_ICR_MSTOP | IOP321_ICR_NACK);
 	cr |= IOP321_ICR_MSTART | IOP321_ICR_TBYTE;
 
 	*iop3xx_adap->biu->CR = cr;
-	rc = iop3xx_adap_wait_tx_done( iop3xx_adap, &status );
-/* this assert fires every time, contrary to IOP manual	
-	PASSERT( (status&IOP321_ISR_UNITBUSY)!=0 );
-*/
-	PASSERT( (status&IOP321_ISR_RXREAD)==0 );
+	rc = iop3xx_adap_wait_tx_done(iop3xx_adap, &status);
+	/* this assert fires every time, contrary to IOP manual	
+	PASSERT((status&IOP321_ISR_UNITBUSY)!=0);
+	*/
+	PASSERT((status&IOP321_ISR_RXREAD)==0);
 	     
 	return rc;
 }
 
-static int iop3xx_adap_write_byte( 
-	struct i2c_algo_iop3xx_data *iop3xx_adap, char byte, int stop )
+static int iop3xx_adap_write_byte(struct i2c_algo_iop3xx_data *iop3xx_adap, char byte, int stop)
 {
 	unsigned cr = *iop3xx_adap->biu->CR;
 	int status;
@@ -297,19 +284,19 @@
 
 	*iop3xx_adap->biu->DBR = byte;
 	cr &= ~IOP321_ICR_MSTART;
-	if ( stop ){
+	if (stop) {
 		cr |= IOP321_ICR_MSTOP;
-	}else{
+	} else {
 		cr &= ~IOP321_ICR_MSTOP;
 	}
 	*iop3xx_adap->biu->CR = cr |= IOP321_ICR_TBYTE;
-	rc = iop3xx_adap_wait_tx_done( iop3xx_adap, &status );
+	rc = iop3xx_adap_wait_tx_done(iop3xx_adap, &status);
 
 	return rc;
 } 
 
-static int iop3xx_adap_read_byte(
-	struct i2c_algo_iop3xx_data *iop3xx_adap, char* byte, int stop )
+static int iop3xx_adap_read_byte(struct i2c_algo_iop3xx_data *iop3xx_adap,
+				 char* byte, int stop)
 {
 	unsigned cr = *iop3xx_adap->biu->CR;
 	int status;
@@ -317,49 +304,46 @@
 
 	cr &= ~IOP321_ICR_MSTART;
 
-	if ( stop ){
+	if (stop) {
 		cr |= IOP321_ICR_MSTOP|IOP321_ICR_NACK;
-	}else{
+	} else {
 		cr &= ~(IOP321_ICR_MSTOP|IOP321_ICR_NACK);
 	}
 	*iop3xx_adap->biu->CR = cr |= IOP321_ICR_TBYTE;
 
-	rc = iop3xx_adap_wait_rx_done( iop3xx_adap, &status );
+	rc = iop3xx_adap_wait_rx_done(iop3xx_adap, &status);
 
 	*byte = *iop3xx_adap->biu->DBR;
 
 	return rc;
 }
 
-
-static int iop3xx_i2c_writebytes( struct i2c_adapter *i2c_adap, 
-				  const char *buf, int count )
+static int iop3xx_i2c_writebytes(struct i2c_adapter *i2c_adap, 
+				 const char *buf, int count)
 {
 	struct i2c_algo_iop3xx_data *iop3xx_adap = i2c_adap->algo_data;
 	int ii;
 	int rc = 0;
 
-	for ( ii = 0; rc == 0 && ii != count; ++ii ){
+	for (ii = 0; rc == 0 && ii != count; ++ii) {
 		rc = iop3xx_adap_write_byte(iop3xx_adap, buf[ii], ii==count-1);
 	}
 	return rc;
 }
 
-
-static int iop3xx_i2c_readbytes( struct i2c_adapter *i2c_adap, 
-				 char *buf, int count )
+static int iop3xx_i2c_readbytes(struct i2c_adapter *i2c_adap, 
+				char *buf, int count)
 {
 	struct i2c_algo_iop3xx_data *iop3xx_adap = i2c_adap->algo_data;
 	int ii;
 	int rc = 0;
 
-	for ( ii = 0; rc == 0 && ii != count; ++ii ){
+	for (ii = 0; rc == 0 && ii != count; ++ii) {
 		rc = iop3xx_adap_read_byte(iop3xx_adap, &buf[ii], ii==count-1);
 	}
 	return rc;
 }
 
-
 /*
  * Description:  This function implements combined transactions.  Combined
  * transactions consist of combinations of reading and writing blocks of data.
@@ -367,63 +351,55 @@
  * Each transfer (i.e. a read or a write) is separated by a repeated start
  * condition.
  */
-
-static int iop3xx_handle_msg(
-	struct i2c_adapter *i2c_adap, struct i2c_msg* pmsg ) 
+static int iop3xx_handle_msg(struct i2c_adapter *i2c_adap, struct i2c_msg* pmsg) 
 {
 	struct i2c_algo_iop3xx_data *iop3xx_adap = i2c_adap->algo_data;
 	int rc;
 
-	rc = iop3xx_adap_send_target_slave_addr( iop3xx_adap, pmsg );
-	if ( rc < 0 ){
+	rc = iop3xx_adap_send_target_slave_addr(iop3xx_adap, pmsg);
+	if (rc < 0) {
 		return rc;
 	}
 
-	if ( (pmsg->flags&I2C_M_RD) ){
-		return iop3xx_i2c_readbytes( i2c_adap, pmsg->buf, pmsg->len );
-	}else{
-		return iop3xx_i2c_writebytes( i2c_adap, pmsg->buf, pmsg->len );
+	if ((pmsg->flags&I2C_M_RD)) {
+		return iop3xx_i2c_readbytes(i2c_adap, pmsg->buf, pmsg->len);
+	} else {
+		return iop3xx_i2c_writebytes(i2c_adap, pmsg->buf, pmsg->len);
 	}
 }
 
-
-
 /*
  * master_xfer() - main read/write entry
  */
-static int iop3xx_master_xfer(
-	struct i2c_adapter *i2c_adap, struct i2c_msg msgs[], int num )
+static int iop3xx_master_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msgs[], int num)
 {
 	struct i2c_algo_iop3xx_data *iop3xx_adap = i2c_adap->algo_data;
 	int im = 0;
 	int ret = 0;
 	int status;
 
-	iop3xx_adap_wait_idle( iop3xx_adap, &status );
-	iop3xx_adap_reset( iop3xx_adap );
-	iop3xx_adap_enable( iop3xx_adap );
+	iop3xx_adap_wait_idle(iop3xx_adap, &status);
+	iop3xx_adap_reset(iop3xx_adap);
+	iop3xx_adap_enable(iop3xx_adap);
 
-	for ( im = 0; ret == 0 && im != num; ++im ){
-		ret = iop3xx_handle_msg( i2c_adap, &msgs[im] );
+	for (im = 0; ret == 0 && im != num; ++im) {
+		ret = iop3xx_handle_msg(i2c_adap, &msgs[im]);
 	}
 
-	iop3xx_adap_transaction_cleanup( iop3xx_adap );
+	iop3xx_adap_transaction_cleanup(iop3xx_adap);
 
 	return ret;   
 }
 
-
-
-static int algo_control(struct i2c_adapter *adapter, 
-	unsigned int cmd, unsigned long arg)
+static int algo_control(struct i2c_adapter *adapter, unsigned int cmd,
+			unsigned long arg)
 {
 	return 0;
 }
 
-
 static u32 iic_func(struct i2c_adapter *adap)
 {
-	return I2C_FUNC_I2C|I2C_FUNC_SMBUS_EMUL;
+	return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
 }
 
 
@@ -440,74 +416,70 @@
 /* 
  * registering functions to load algorithms at runtime 
  */
-
-
 static int i2c_iop3xx_add_bus(struct i2c_adapter *iic_adap)
 {
 	struct i2c_algo_iop3xx_data *iop3xx_adap = iic_adap->algo_data;
 
-	if ( !request_region( REGION_START(iop3xx_adap), 
+	if (!request_region( REGION_START(iop3xx_adap), 
 			      REGION_LENGTH(iop3xx_adap),
-			      iic_adap->name ) ){
+			      iic_adap->name)) {
 		return -ENODEV;
 	}
-			      
-	init_waitqueue_head( &iop3xx_adap->waitq );
-	spin_lock_init( &iop3xx_adap->lock );
 
-	if ( request_irq( 
+	init_waitqueue_head(&iop3xx_adap->waitq);
+	spin_lock_init(&iop3xx_adap->lock);
+
+	if (request_irq( 
 		     iop3xx_adap->biu->irq,
 		     iop3xx_i2c_handler,
 		     /* SA_SAMPLE_RANDOM */ 0,
 		     iic_adap->name,
-		     iop3xx_adap )          ){
+		     iop3xx_adap)) {
 		return -ENODEV;
 	}			  
 
-/* register new iic_adapter to i2c module... */
-
+	/* register new iic_adapter to i2c module... */
 	iic_adap->id |= iic_algo.id;
 	iic_adap->algo = &iic_algo;
 
-	iic_adap->timeout = 100;	/* default values, should	*/
-	iic_adap->retries = 3;		/* be replaced by defines	*/
+	iic_adap->timeout = 100;	/* default values, should */
+	iic_adap->retries = 3;		/* be replaced by defines */
 
-	iop3xx_adap_init( iic_adap->algo_data );
+	iop3xx_adap_init(iic_adap->algo_data);
 	i2c_add_adapter(iic_adap);
 	return 0;
 }
 
-
 static int i2c_iop3xx_del_bus(struct i2c_adapter *iic_adap)
 {
 	struct i2c_algo_iop3xx_data *iop3xx_adap = iic_adap->algo_data;
 
-	iop3xx_adap_final_cleanup( iop3xx_adap );
-	free_irq( iop3xx_adap->biu->irq, iop3xx_adap );
+	iop3xx_adap_final_cleanup(iop3xx_adap);
+	free_irq(iop3xx_adap->biu->irq, iop3xx_adap);
 
-	release_region( REGION_START(iop3xx_adap), REGION_LENGTH(iop3xx_adap));
+	release_region(REGION_START(iop3xx_adap), REGION_LENGTH(iop3xx_adap));
 
-	return i2c_del_adapter( iic_adap );
+	return i2c_del_adapter(iic_adap);
 }
 
 #ifdef CONFIG_ARCH_IOP321
 
 static struct iop3xx_biu biu0 = {
-	.CR     = IOP321_ICR0,
-	.SR     = IOP321_ISR0,
-	.SAR    = IOP321_ISAR0,
-	.DBR    = IOP321_IDBR0,
-	.BMR    = IOP321_IBMR0,
-	.irq    = IRQ_IOP321_I2C_0
+	.CR	= IOP321_ICR0,
+	.SR	= IOP321_ISR0,
+	.SAR	= IOP321_ISAR0,
+	.DBR	= IOP321_IDBR0,
+	.BMR	= IOP321_IBMR0,
+	.irq	= IRQ_IOP321_I2C_0,
 };
 
 static struct iop3xx_biu biu1 = {
-	.CR     = IOP321_ICR1,
-	.SR     = IOP321_ISR1,
-	.SAR    = IOP321_ISAR1,
-	.DBR    = IOP321_IDBR1,
-	.BMR    = IOP321_IBMR1,
-	.irq    = IRQ_IOP321_I2C_1
+	.CR	= IOP321_ICR1,
+	.SR	= IOP321_ISR1,
+	.SAR	= IOP321_ISAR1,
+	.DBR	= IOP321_IDBR1,
+	.BMR	= IOP321_IBMR1,
+	.irq	= IRQ_IOP321_I2C_1,
 };
 
 #define ADAPTER_NAME_ROOT "IOP321 i2c biu adapter "
@@ -515,28 +487,28 @@
 #error Please define the BIU struct iop3xx_biu for your processor arch
 #endif
 
-static struct i2c_algo_iop3xx_data  algo_iop3xx_data0 = {
-	.channel                = 0,
-	.biu                    = &biu0,
-	.timeout                = 1*HZ
+static struct i2c_algo_iop3xx_data algo_iop3xx_data0 = {
+	.channel		= 0,
+	.biu			= &biu0,
+	.timeout		= 1*HZ,
 };
-static struct i2c_algo_iop3xx_data  algo_iop3xx_data1 = {
-        .channel                = 1,
-	.biu                    = &biu1,
-	.timeout                = 1*HZ
+static struct i2c_algo_iop3xx_data algo_iop3xx_data1 = {
+	.channel		= 1,
+	.biu			= &biu1,
+	.timeout		= 1*HZ,
 };
 
 static struct i2c_adapter iop3xx_ops0 = {
 	.owner			= THIS_MODULE,
 	.name			= ADAPTER_NAME_ROOT "0",
 	.id			= I2C_HW_IOP321,
-	.algo_data		= &algo_iop3xx_data0
+	.algo_data		= &algo_iop3xx_data0,
 };
 static struct i2c_adapter iop3xx_ops1 = {
 	.owner			= THIS_MODULE,
 	.name			= ADAPTER_NAME_ROOT "1",
 	.id			= I2C_HW_IOP321,
-	.algo_data		= &algo_iop3xx_data1
+	.algo_data		= &algo_iop3xx_data1,
 };
 
 static int __init i2c_iop3xx_init (void)
@@ -560,6 +532,5 @@
 
 MODULE_PARM(i2c_debug,"i");
 
-MODULE_PARM_DESC(i2c_debug,
-        "debug level - 0 off; 1 normal; 2,3 more verbose; 9 iic-protocol");
+MODULE_PARM_DESC(i2c_debug, "debug level - 0 off; 1 normal; 2,3 more verbose; 9 iic-protocol");
 
drivers/i2c/i2c-iop3xx.h +58 -60

144 lines not on this page · raw message

author
#4 lore raw

ChangeSet 1.1419.1.6, 2003/06/11 12:29:21-07:00, [email protected]

[PATCH] I2C: fix some errors found by sparse in include/linux/i2c.h

 include/linux/i2c.h |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
include/linux/i2c.h +2 -2
diff -Nru a/include/linux/i2c.h b/include/linux/i2c.h
@@ -176,7 +176,7 @@
 
 static inline void i2c_set_clientdata (struct i2c_client *dev, void *data)
 {
-	return dev_set_drvdata (&dev->dev, data);
+	dev_set_drvdata (&dev->dev, data);
 }
 
 #define I2C_DEVNAME(str)   .dev = { .name = str }
@@ -261,7 +261,7 @@
 
 static inline void i2c_set_adapdata (struct i2c_adapter *dev, void *data)
 {
-	return dev_set_drvdata (&dev->dev, data);
+	dev_set_drvdata (&dev->dev, data);
 }
 
 /*flags for the driver struct: */
author
#5 lore raw

ChangeSet 1.1419.1.7, 2003/06/11 12:29:31-07:00, [email protected]

[PATCH] I2C: fix up sparse warnings in drivers/i2c/i2c-core.c

 drivers/i2c/i2c-core.c |   36 ++++++++++++++----------------------
 1 files changed, 14 insertions(+), 22 deletions(-)
drivers/i2c/i2c-core.c +14 -22
diff -Nru a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
@@ -510,7 +510,7 @@
 		msg.addr   = client->addr;
 		msg.flags = client->flags & I2C_M_TEN;
 		msg.len = count;
-		(const char *)msg.buf = buf;
+		msg.buf = (char *)buf;
 	
 		DEB2(dev_dbg(&client->adapter->dev, "master_send: writing %d bytes.\n",
 				count));
@@ -861,13 +861,13 @@
 	return 0;	
 }
 
-extern s32 i2c_smbus_write_quick(struct i2c_client * client, u8 value)
+s32 i2c_smbus_write_quick(struct i2c_client *client, u8 value)
 {
 	return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
  	                      value,0,I2C_SMBUS_QUICK,NULL);
 }
 
-extern s32 i2c_smbus_read_byte(struct i2c_client * client)
+s32 i2c_smbus_read_byte(struct i2c_client *client)
 {
 	union i2c_smbus_data data;
 	if (i2c_smbus_xfer(client->adapter,client->addr,client->flags,
@@ -877,14 +877,14 @@
 		return 0x0FF & data.byte;
 }
 
-extern s32 i2c_smbus_write_byte(struct i2c_client * client, u8 value)
+s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value)
 {
 	union i2c_smbus_data data;	/* only for PEC */
 	return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
 	                      I2C_SMBUS_WRITE,value, I2C_SMBUS_BYTE,&data);
 }
 
-extern s32 i2c_smbus_read_byte_data(struct i2c_client * client, u8 command)
+s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command)
 {
 	union i2c_smbus_data data;
 	if (i2c_smbus_xfer(client->adapter,client->addr,client->flags,
@@ -894,8 +894,7 @@
 		return 0x0FF & data.byte;
 }
 
-extern s32 i2c_smbus_write_byte_data(struct i2c_client * client, u8 command,
-                                     u8 value)
+s32 i2c_smbus_write_byte_data(struct i2c_client *client, u8 command, u8 value)
 {
 	union i2c_smbus_data data;
 	data.byte = value;
@@ -904,7 +903,7 @@
 	                      I2C_SMBUS_BYTE_DATA,&data);
 }
 
-extern s32 i2c_smbus_read_word_data(struct i2c_client * client, u8 command)
+s32 i2c_smbus_read_word_data(struct i2c_client *client, u8 command)
 {
 	union i2c_smbus_data data;
 	if (i2c_smbus_xfer(client->adapter,client->addr,client->flags,
@@ -914,8 +913,7 @@
 		return 0x0FFFF & data.word;
 }
 
-extern s32 i2c_smbus_write_word_data(struct i2c_client * client,
-                                     u8 command, u16 value)
+s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value)
 {
 	union i2c_smbus_data data;
 	data.word = value;
@@ -924,8 +922,7 @@
 	                      I2C_SMBUS_WORD_DATA,&data);
 }
 
-extern s32 i2c_smbus_process_call(struct i2c_client * client,
-                                  u8 command, u16 value)
+s32 i2c_smbus_process_call(struct i2c_client *client, u8 command, u16 value)
 {
 	union i2c_smbus_data data;
 	data.word = value;
@@ -938,8 +935,7 @@
 }
 
 /* Returns the number of read bytes */
-extern s32 i2c_smbus_read_block_data(struct i2c_client * client,
-                                     u8 command, u8 *values)
+s32 i2c_smbus_read_block_data(struct i2c_client *client, u8 command, u8 *values)
 {
 	union i2c_smbus_data data;
 	int i;
@@ -954,8 +950,7 @@
 	}
 }
 
-extern s32 i2c_smbus_write_block_data(struct i2c_client * client,
-                                      u8 command, u8 length, u8 *values)
+s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command, u8 length, u8 *values)
 {
 	union i2c_smbus_data data;
 	int i;
@@ -970,8 +965,7 @@
 }
 
 /* Returns the number of read bytes */
-extern s32 i2c_smbus_block_process_call(struct i2c_client * client,
-                                        u8 command, u8 length, u8 *values)
+s32 i2c_smbus_block_process_call(struct i2c_client *client, u8 command, u8 length, u8 *values)
 {
 	union i2c_smbus_data data;
 	int i;
@@ -990,8 +984,7 @@
 }
 
 /* Returns the number of read bytes */
-extern s32 i2c_smbus_read_i2c_block_data(struct i2c_client * client,
-                                         u8 command, u8 *values)
+s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client, u8 command, u8 *values)
 {
 	union i2c_smbus_data data;
 	int i;
@@ -1006,8 +999,7 @@
 	}
 }
 
-extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client * client,
-                                          u8 command, u8 length, u8 *values)
+s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client, u8 command, u8 length, u8 *values)
 {
 	union i2c_smbus_data data;
 	int i;
author
#6 lore raw

ChangeSet 1.1419.1.8, 2003/06/11 12:29:42-07:00, [email protected]

[PATCH] I2C: fix up sparse warnings in the i2c-dev driver

 drivers/i2c/i2c-dev.c   |   10 +++++-----
 include/linux/i2c-dev.h |    6 +++---
 2 files changed, 8 insertions(+), 8 deletions(-)
drivers/i2c/i2c-dev.c +5 -5
diff -Nru a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
@@ -122,7 +122,7 @@
 }
 static CLASS_DEVICE_ATTR(dev, S_IRUGO, show_dev, NULL);
 
-static ssize_t i2cdev_read (struct file *file, char *buf, size_t count,
+static ssize_t i2cdev_read (struct file *file, char __user *buf, size_t count,
                             loff_t *offset)
 {
 	char *tmp;
@@ -147,7 +147,7 @@
 	return ret;
 }
 
-static ssize_t i2cdev_write (struct file *file, const char *buf, size_t count,
+static ssize_t i2cdev_write (struct file *file, const char __user *buf, size_t count,
                              loff_t *offset)
 {
 	int ret;
@@ -211,12 +211,12 @@
 		return 0;
 	case I2C_FUNCS:
 		funcs = i2c_get_functionality(client->adapter);
-		return (copy_to_user((unsigned long *)arg,&funcs,
+		return (copy_to_user((unsigned long __user *)arg, &funcs,
 		                     sizeof(unsigned long)))?-EFAULT:0;
 
         case I2C_RDWR:
 		if (copy_from_user(&rdwr_arg, 
-				   (struct i2c_rdwr_ioctl_data *)arg, 
+				   (struct i2c_rdwr_ioctl_data __user *)arg, 
 				   sizeof(rdwr_arg)))
 			return -EFAULT;
 
@@ -284,7 +284,7 @@
 
 	case I2C_SMBUS:
 		if (copy_from_user(&data_arg,
-		                   (struct i2c_smbus_ioctl_data *) arg,
+		                   (struct i2c_smbus_ioctl_data __user *) arg,
 		                   sizeof(struct i2c_smbus_ioctl_data)))
 			return -EFAULT;
 		if ((data_arg.size != I2C_SMBUS_BYTE) && 
include/linux/i2c-dev.h +3 -3
diff -Nru a/include/linux/i2c-dev.h b/include/linux/i2c-dev.h
@@ -34,13 +34,13 @@
 	__u8 read_write;
 	__u8 command;
 	__u32 size;
-	union i2c_smbus_data *data;
+	union i2c_smbus_data __user *data;
 };
 
 /* This is the structure as used in the I2C_RDWR ioctl call */
 struct i2c_rdwr_ioctl_data {
-	struct i2c_msg *msgs;	/* pointers to i2c_msgs */
-	__u32 nmsgs;		/* number of i2c_msgs */
+	struct i2c_msg __user *msgs;	/* pointers to i2c_msgs */
+	__u32 nmsgs;			/* number of i2c_msgs */
 };
 
 #endif /* _LINUX_I2C_DEV_H */
#7 lore raw
In reply to Greg KH

I think there is a race condition here in the "set" functions.

I had added a down()/up() semaphore pair to the write clauses of the functions in the pre-sysfs driver to prevent the xx_update_client() call from modifying the cached values at the same time that the set_xxx() function was trying to change them.

So for example:

Quoted 4 lines

static ssize_t set_temp_max(struct device *dev, const char *buf,

(quoted diff) +0 -0
 		size_t count, int nr)
 {
 	struct i2c_client *client = to_i2c_client(dev);

Review

Quoted 10 lines
(quoted diff) +2 -0
 	struct lm85_data *data = i2c_get_clientdata(client);
 
 	int val = simple_strtol(buf, NULL, 10);
+     down(&data->update_lock);
 	data->temp_max[nr] = TEMP_TO_REG(val);
 	lm85_write_value(client, LM85_REG_TEMP_MAX(nr),
                                    data->temp_max[nr]);
+     up(&data->update_lock);
 	return count;
 }

Isn't that still needed?

:v)

Quoted 41 lines · Greg KH

ChangeSet 1.1419.1.3, 2003/06/11 11:42:47-07:00, [email protected]

[PATCH] I2C: add LM85 driver

Nothing extra in sysfs (yet) but I have left the way open in the driver to do this.
Provides vid, vrm, fan_input(1-4), fan_min(1-4), pwm(1-3), pwm_enable(1-3), in_input(0-4), in_min(0-4), in_max(0-4), temp_input(1-3), temp_min(1-3), temp_max(1-3), alarms.

 drivers/i2c/chips/Kconfig  |   19 
 drivers/i2c/chips/Makefile |    1 
 drivers/i2c/chips/lm85.c   | 1223 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1241 insertions(+), 2 deletions(-)
drivers/i2c/chips/lm85.c new file +19 -0
+static ssize_t show_temp_max(struct device *dev, char *buf, int nr)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct lm85_data *data = i2c_get_clientdata(client);
+
+	lm85_update_client(client);
+	return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_max[nr]) );
+}
 
 
 
+static ssize_t set_temp_max(struct device *dev, const char *buf, 
+		size_t count, int nr)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct lm85_data *data = i2c_get_clientdata(client);
+
+	int val = simple_strtol(buf, NULL, 10);
+	data->temp_max[nr] = TEMP_TO_REG(val);
+	lm85_write_value(client, LM85_REG_TEMP_MAX(nr), data->temp_max[nr]);
+	return count;
+}
Signature · 4 lines
Philip Pokorny, Director of Engineering
Tel: 415-358-2635   Fax: 415-358-2646   Toll Free: 888-PENGUIN
PENGUIN COMPUTING, INC.
www.penguincomputing.com