Re: [PATCH] i2c: boilerplate function for byte swapped smbus_write/read_word_data

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 8 Oct 2011 23:10:05 +0200, Jean Delvare wrote:
> On Thu, 22 Sep 2011 14:48:14 +0100, Jonathan Cameron wrote:
> > @@ -88,6 +89,23 @@ extern s32 i2c_smbus_read_word_data(const struct i2c_client *client,
> >  				    u8 command);
> >  extern s32 i2c_smbus_write_word_data(const struct i2c_client *client,
> >  				     u8 command, u16 value);
> > +
> > +static inline s32
> > +i2c_smbus_read_word_data_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_data_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 */
> >  extern s32 i2c_smbus_read_block_data(const struct i2c_client *client,
> >  				     u8 command, u8 *values);
> 
> It might make sense to change the _data_swapped suffix to just
> _swapped, for the sake of avoiding overly long function names (_data
> was never meaningful for the original functions anyway as there is no
> ambiguity.)
> 
> Other than these minor details, I like the patch very much, I tested if
> with 9 hwmon drivers and it indeed makes the drivers cleaner/smaller.
> I'll be happy to commit it when I am able to do this again.

Oh, and I think the new functions should be listed in
Documentation/i2c/smbus-protocol. Maybe not as separate entries, as
they are not new fundamental types, nor part of the SMBus protocol, but
at least as as notes in the SMBus Read Word and SMBus Write Word
sections.

-- 
Jean Delvare
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux GPIO]     [Linux SPI]     [Linux Hardward Monitoring]     [LM Sensors]     [Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux