mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	i2c: Functions for byte-swapped smbus_write/read_word_data
Reimplemented at least 17 times discounting error mangling cases where it could be used. Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk> Signed-off-by: Jean Delvare <khali@linux-fr.org>
This commit is contained in:
		
							parent
							
								
									4403988afc
								
							
						
					
					
						commit
						06a67848c6
					
				
					 2 changed files with 25 additions and 0 deletions
				
			
		| 
						 | 
					@ -88,6 +88,10 @@ byte. But this time, the data is a complete word (16 bits).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
S Addr Wr [A] Comm [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P
 | 
					S Addr Wr [A] Comm [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Note the convenience function i2c_smbus_read_word_swapped is
 | 
				
			||||||
 | 
					available for reads where the two data bytes are the other way
 | 
				
			||||||
 | 
					around (not SMBus compliant, but very popular.)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SMBus Write Byte:  i2c_smbus_write_byte_data()
 | 
					SMBus Write Byte:  i2c_smbus_write_byte_data()
 | 
				
			||||||
==============================================
 | 
					==============================================
 | 
				
			||||||
| 
						 | 
					@ -108,6 +112,10 @@ specified through the Comm byte.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] P
 | 
					S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] P
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Note the convenience function i2c_smbus_write_word_swapped is
 | 
				
			||||||
 | 
					available for writes where the two data bytes are the other way
 | 
				
			||||||
 | 
					around (not SMBus compliant, but very popular.)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SMBus Process Call:  i2c_smbus_process_call()
 | 
					SMBus Process Call:  i2c_smbus_process_call()
 | 
				
			||||||
=============================================
 | 
					=============================================
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -34,6 +34,7 @@
 | 
				
			||||||
#include <linux/sched.h>	/* for completion */
 | 
					#include <linux/sched.h>	/* for completion */
 | 
				
			||||||
#include <linux/mutex.h>
 | 
					#include <linux/mutex.h>
 | 
				
			||||||
#include <linux/of.h>		/* for struct device_node */
 | 
					#include <linux/of.h>		/* for struct device_node */
 | 
				
			||||||
 | 
					#include <linux/swab.h>		/* for swab16 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern struct bus_type i2c_bus_type;
 | 
					extern struct bus_type i2c_bus_type;
 | 
				
			||||||
extern struct device_type i2c_adapter_type;
 | 
					extern struct device_type i2c_adapter_type;
 | 
				
			||||||
| 
						 | 
					@ -88,6 +89,22 @@ extern s32 i2c_smbus_read_word_data(const struct i2c_client *client,
 | 
				
			||||||
				    u8 command);
 | 
									    u8 command);
 | 
				
			||||||
extern s32 i2c_smbus_write_word_data(const struct i2c_client *client,
 | 
					extern s32 i2c_smbus_write_word_data(const struct i2c_client *client,
 | 
				
			||||||
				     u8 command, u16 value);
 | 
									     u8 command, u16 value);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline s32
 | 
				
			||||||
 | 
					i2c_smbus_read_word_swapped(const struct i2c_client *client, u8 command)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						s32 value = i2c_smbus_read_word_data(client, command);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return (value < 0) ? value : swab16(value);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline s32
 | 
				
			||||||
 | 
					i2c_smbus_write_word_swapped(const struct i2c_client *client,
 | 
				
			||||||
 | 
								     u8 command, u16 value)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return i2c_smbus_write_word_data(client, command, swab16(value));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Returns the number of read bytes */
 | 
					/* Returns the number of read bytes */
 | 
				
			||||||
extern s32 i2c_smbus_read_block_data(const struct i2c_client *client,
 | 
					extern s32 i2c_smbus_read_block_data(const struct i2c_client *client,
 | 
				
			||||||
				     u8 command, u8 *values);
 | 
									     u8 command, u8 *values);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue