Skip to contentSkip to conversation

ad525x_dpot: new driver for AD525x digital potentiometers

PATCH Superseded Mike Frysinger 3 participants 6 messages Sep 17, 2009 – Oct 2, 2009

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ad525x_dpot: new driver for AD525x digital potentiometers

From: Michael Hennerich <[email protected]>

This driver supports the non-volatile digital potentiometers via I2C:
AD5258, AD5259, AD5251, AD5252, AD5253, AD5254, and AD5255

It provides a sysfs interface to each device for reading/writing.

---
 drivers/misc/Kconfig       |   11 +
 drivers/misc/Makefile      |    1 +
 drivers/misc/ad525x_dpot.c |  666 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 678 insertions(+), 0 deletions(-)
 create mode 100644 drivers/misc/ad525x_dpot.c
drivers/misc/Kconfig +11 -0
index df1f86b..32c8978 100644
@@ -246,6 +246,17 @@ config EP93XX_PWM
 	  To compile this driver as a module, choose M here: the module will
 	  be called ep93xx_pwm.
 
+config AD525X_DPOT
+	tristate "Analog Devices AD525x Digital Potentiometers"
+	depends on I2C && SYSFS
+	help
+	  If you say yes here, you get support for the Analog Devices
+	  AD5258, AD5259, AD5251, AD5252, AD5253, AD5254 and AD5255
+	  digital potentiometer chips.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called ad525x_dpot.
+
 source "drivers/misc/c2port/Kconfig"
 source "drivers/misc/eeprom/Kconfig"
 source "drivers/misc/cb710/Kconfig"
drivers/misc/Makefile +1 -0
index f982d2e..6c67c00 100644
@@ -20,6 +20,7 @@ obj-$(CONFIG_SGI_GRU)		+= sgi-gru/
 obj-$(CONFIG_HP_ILO)		+= hpilo.o
 obj-$(CONFIG_ISL29003)		+= isl29003.o
 obj-$(CONFIG_EP93XX_PWM)	+= ep93xx_pwm.o
+obj-$(CONFIG_AD525X_DPOT)	+= ad525x_dpot.o
 obj-$(CONFIG_C2PORT)		+= c2port/
 obj-y				+= eeprom/
 obj-y				+= cb710/
drivers/misc/ad525x_dpot.c new file +666 -0

666 lines not on this page · raw message

Signature · 1 line
1.6.5.rc1
#1 lore raw
Quoted 4 lines · On Thu, 17 Sep 2009 00:22:37 -0400 Mike Frysinger <[email protected]> wrote:

This driver supports the non-volatile digital potentiometers via I2C:
AD5258, AD5259, AD5251, AD5252, AD5253, AD5254, and AD5255

It provides a sysfs interface to each device for reading/writing.

This sysfs interface is by far the most important aspect of this driver. For both its users and for its reviewers.

Yet you tell us nothing about it! Not in code comments, not in the changelog, not in supporting documentation.

So some poor idiot (ie: me) is left having to scratch his way through the implementation trying to work out what the propoed userspace interface is supposed to look like.

Then I come across something this:

+ if (reg & AD525X_REG_TOL)
+ return sprintf(buf, "0x%04x\n", value & 0xFFFF);
+ else
+ return sprintf(buf, "%u\n", value & data->rdac_mask);

which makes me suspect that the proposed userspace interface is quite poor.

Patch not applied! Not even close.

#2 lore raw
Quoted 9 lines · Andrew Morton
Quoted 4 lines · On Thu, 17 Sep 2009 00:22:37 -0400 Mike Frysinger wrote:

This driver supports the non-volatile digital potentiometers via I2C:
AD5258, AD5259, AD5251, AD5252, AD5253, AD5254, and AD5255

It provides a sysfs interface to each device for reading/writing.

This sysfs interface is by far the most important aspect of this driver.  For both its users and for its reviewers.

Quoted 6 lines

Yet you tell us nothing about it!  Not in code comments, not in the changelog, not in supporting documentation.

So some poor idiot (ie: me) is left having to scratch his way through the implementation trying to work out what the propoed userspace interface is supposed to look like.

i'll have to get a description from some people

Quoted 7 lines

+       if (reg & AD525X_REG_TOL)
+               return sprintf(buf, "0x%04x\n", value & 0xFFFF);
+       else
+               return sprintf(buf, "%u\n", value & data->rdac_mask);

which makes me suspect that the proposed userspace interface is quite poor.

not really. the proposed interface was discussed with a few different people (devs and end users) and reviewed for use across multiple parts rather than just slapping together a raw interface onto it. if you actually read the datasheet as indicated in the comment you snipped, you'll see that the value isnt formatted for trivial conversion. if the math can easily be done in the kernel, then that's one thing, but it doesnt look like it to me.

this field is a read-only percentage programmed into the part by the factory. it can be interpreted by:
MSB: 0 = +
Next 7 MSB: 001 1100 = 28
8 LSB: 0000 1111 = 15 * 2^-8 = 0.06
Tolerance = 28.06%
Rounded Tolerance = 28.1% and therefore
RAB_ACTUAL = 12.810 kΩ

seems to me that this requires floating point support -mike

#3 lore raw
Quoted 9 lines · On Tue, 29 Sep 2009 21:14:37 -0400 Mike Frysinger <[email protected]> wrote:
Quoted 7 lines

+ __ __ __ if (reg & AD525X_REG_TOL)
+ __ __ __ __ __ __ __ return sprintf(buf, "0x%04x\n", value & 0xFFFF);
+ __ __ __ else
+ __ __ __ __ __ __ __ return sprintf(buf, "%u\n", value & data->rdac_mask);

which makes me suspect that the proposed userspace interface is quite poor.

not really.

Think so. We have a sysfs file which under some circumstances will return a decimal number and which under others will return a hex number. So userspace is supposed to look for the leading 0x to work out how to interpret that number?

Or something. Whatever. Perhaps it all makes sense when one has seen the overall description.

#4 lore raw
Quoted 11 lines · Andrew Morton
Quoted 9 lines · On Tue, 29 Sep 2009 21:14:37 -0400 Mike Frysinger wrote:
Quoted 7 lines

+ __ __ __ if (reg & AD525X_REG_TOL)
+ __ __ __ __ __ __ __ return sprintf(buf, "0x%04x\n", value & 0xFFFF);
+ __ __ __ else
+ __ __ __ __ __ __ __ return sprintf(buf, "%u\n", value & data->rdac_mask);

which makes me suspect that the proposed userspace interface is quite poor.

not really.

Quoted 7 lines

Think so.  We have a sysfs file which under some circumstances will return a decimal number and which under others will return a hex number.  So userspace is supposed to look for the leading 0x to work out how to interpret that number?

Or something.  Whatever.  Perhaps it all makes sense when one has seen the overall description.

no, you're looking at one common function which is called by different sysfs files. no point in copying & pasting the same code over and over. all of the rdac files display as a hex file while all the non-rdac files display as a decimal.
-mike

#5 lore raw

PATCH v2 1/1 ad525x_dpot: new driver for AD525x digital potentiometers

In reply to Mike Frysinger

From: Michael Hennerich <[email protected]>

This driver supports the non-volatile digital potentiometers via I2C:
AD5258, AD5259, AD5251, AD5252, AD5253, AD5254, and AD5255

It provides a sysfs interface to each device for reading/writing which is documented in Documentation/misc-devices/ad525x_dpot.txt.

---
v2
- add some docs on sysfs interface
- sort kconfig/makefile list

 Documentation/misc-devices/ad525x_dpot.txt |   57 +++
 drivers/misc/Kconfig                       |   14 +
 drivers/misc/Makefile                      |    1 +
 drivers/misc/ad525x_dpot.c                 |  666 ++++++++++++++++++++++++++++
 4 files changed, 738 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/misc-devices/ad525x_dpot.txt
 create mode 100644 drivers/misc/ad525x_dpot.c
Documentation/misc-devices/ad525x_dpot.txt new file +57 -0
new file mode 100644
index 0000000..0c9413b
@@ -0,0 +1,57 @@
+---------------------------------
+  AD525x Digital Potentiometers
+---------------------------------
+
+The ad525x_dpot driver exports a simple sysfs interface.  This allows you to
+work with the immediate resistance settings as well as update the saved startup
+settings.  Access to the factory programmed tolerance is also provided, but
+interpretation of this settings is required by the end application according to
+the specific part in use.
+
+---------
+  Files
+---------
+
+Each dpot device will have a set of eeprom, rdac, and tolerance files.  How
+many depends on the actual part you have, as will the range of allowed values.
+
+The eeprom files are used to program the startup value of the device.
+
+The rdac files are used to program the immediate value of the device.
+
+The tolerance files are the read-only factory programmed tolerance settings
+and may vary greatly on a part-by-part basis.  For exact interpretation of
+this field, please consult the datasheet for your part.  This is presented
+as a hex file for easier parsing.
+
+-----------
+  Example
+-----------
+
+Locate the device in your sysfs tree.  This is probably easiest by going into
+the common i2c directory and locating the device by the i2c slave address.
+
+	# ls /sys/bus/i2c/devices/
+	0-0022  0-0027  0-002f
+
+So assuming the device in question is on the first i2c bus and has the slave
+address of 0x2f, we descend (unrelated sysfs entries have been trimmed).
+
+	# ls /sys/bus/i2c/devices/0-002f/
+	eeprom0 rdac0 tolerance0
+
+You can use simple reads/writes to access these files:
+
+	# cd /sys/bus/i2c/devices/0-002f/
+
+	# cat eeprom0
+	0
+	# echo 10 > eeprom0
+	# cat eeprom0
+	10
+
+	# cat rdac0
+	5
+	# echo 3 > rdac0
+	# cat rdac0
+	3
drivers/misc/Kconfig +14 -0
index df1f86b..3e039d3 100644
@@ -13,6 +13,20 @@ menuconfig MISC_DEVICES
 
 if MISC_DEVICES
 
+config AD525X_DPOT
+	tristate "Analog Devices AD525x Digital Potentiometers"
+	depends on I2C && SYSFS
+	help
+	  If you say yes here, you get support for the Analog Devices
+	  AD5258, AD5259, AD5251, AD5252, AD5253, AD5254 and AD5255
+	  digital potentiometer chips.
+
+	  See Documentation/misc-devices/ad525x_dpot.txt for the
+	  userspace interface.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called ad525x_dpot.
+
 config ATMEL_PWM
 	tristate "Atmel AT32/AT91 PWM support"
 	depends on AVR32 || ARCH_AT91SAM9263 || ARCH_AT91SAM9RL || ARCH_AT91CAP9
drivers/misc/Makefile +1 -0
index f982d2e..e0d4189 100644
@@ -4,6 +4,7 @@
 
 obj-$(CONFIG_IBM_ASM)		+= ibmasm/
 obj-$(CONFIG_HDPU_FEATURES)	+= hdpuftrs/
+obj-$(CONFIG_AD525X_DPOT)	+= ad525x_dpot.o
 obj-$(CONFIG_ATMEL_PWM)		+= atmel_pwm.o
 obj-$(CONFIG_ATMEL_SSC)		+= atmel-ssc.o
 obj-$(CONFIG_ATMEL_TCLIB)	+= atmel_tclib.o
drivers/misc/ad525x_dpot.c new file +666 -0

666 lines not on this page · raw message

Signature · 1 line
1.6.5.rc2