staging: iio: adc: new driver for AD7152/3 devices
Subsystems (4)
PATCH 1/14 staging: iio: adc: new driver for AD7152/3 devices
From: Barry Song <[email protected]>
--- drivers/staging/iio/adc/Kconfig | 7 + drivers/staging/iio/adc/Makefile | 1 + drivers/staging/iio/adc/ad7152.c | 610 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 618 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/iio/adc/ad7152.c
drivers/staging/iio/adc/Kconfig +7 -0
@@ -33,3 +33,10 @@ config AD7150 help Say yes here to build support for Analog Devices capacitive sensors. (ad7150, ad7151, ad7156) Provides direct access via sysfs. + +config AD7152 + tristate "Analog Devices ad7152/3 capacitive sensor driver" + depends on I2C + help + Say yes here to build support for Analog Devices capacitive sensors. + (ad7152, ad7153) Provides direct access via sysfs.
drivers/staging/iio/adc/Makefile +1 -0
@@ -7,3 +7,4 @@ max1363-y += max1363_ring.o obj-$(CONFIG_MAX1363) += max1363.o obj-$(CONFIG_AD7150) += ad7150.o +obj-$(CONFIG_AD7152) += ad7152.o
drivers/staging/iio/adc/ad7152.c new file +610 -0
610 lines not on this page · raw message
Signature · 1 line
1.7.3.2
PATCH 2/14 staging: iio: adc: new driver for AD7291 devices
From: Sonic Zhang <[email protected]>
--- drivers/staging/iio/adc/Kconfig | 7 + drivers/staging/iio/adc/Makefile | 1 + drivers/staging/iio/adc/ad7291.c | 1039 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 1047 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/iio/adc/ad7291.c
drivers/staging/iio/adc/Kconfig +7 -0
@@ -40,3 +40,10 @@ config AD7152 help Say yes here to build support for Analog Devices capacitive sensors. (ad7152, ad7153) Provides direct access via sysfs. + +config AD7291 + tristate "Analog Devices AD7291 temperature sensor driver" + depends on I2C + help + Say yes here to build support for Analog Devices AD7291 + temperature sensors.
drivers/staging/iio/adc/Makefile +1 -0
@@ -8,3 +8,4 @@ max1363-y += max1363_ring.o obj-$(CONFIG_MAX1363) += max1363.o obj-$(CONFIG_AD7150) += ad7150.o obj-$(CONFIG_AD7152) += ad7152.o +obj-$(CONFIG_AD7291) += ad7291.o
drivers/staging/iio/adc/ad7291.c new file +1039 -0
1,039 lines not on this page · raw message
Signature · 1 line
1.7.3.2
Re: [PATCH 02/14] staging: iio: adc: new driver for AD7291 devices
Quoted 2 lines · Mike Frysinger
From: Sonic Zhang <[email protected]>
All sorts of abi fun and games. Where did v come from as a channel designation? The event code stuff has confused event registration with value setting. This may all make sense for these devices but it needs some documentation!
Checkpatch if time.
We have sysfs based scan modes in here. This almost always means that a buffer mode is really needed. We can add that later.
More documentation would have helped in this one. I've no idea what noise_delay is (and sorry, not time to datasheet dive)
Please check the uses of swab16.
Lots of new interfaces and bits that need cleaning up, but we are in staging, so send this one on as long as it builds.
Quoted 106 lines
Signed-off-by Sonic Zhang <[email protected]>Signed-off-by Mike Frysinger <[email protected]>--- drivers/staging/iio/adc/Kconfig | 7 + drivers/staging/iio/adc/Makefile | 1 + drivers/staging/iio/adc/ad7291.c | 1039 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 1047 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/iio/adc/ad7291.cdrivers/staging/iio/adc/Kconfig +7
-0@@ -40,3 +40,10 @@ config AD7152 help Say yes here to build support for Analog Devices capacitive sensors. (ad7152, ad7153) Provides direct access via sysfs. + +config AD7291 + tristate "Analog Devices AD7291 temperature sensor driver" + depends on I2C + help + Say yes here to build support for Analog Devices AD7291 + temperature sensors.drivers/staging/iio/adc/Makefile +1
-0@@ -8,3 +8,4 @@ max1363-y += max1363_ring.o obj-$(CONFIG_MAX1363) += max1363.o obj-$(CONFIG_AD7150) += ad7150.o obj-$(CONFIG_AD7152) += ad7152.o +obj-$(CONFIG_AD7291) += ad7291.odrivers/staging/iio/adc/ad7291.c new file +67
-0@@ -0,0 +1,1039 @@ +/* +* AD7291 digital temperature sensor driver supporting AD7291 +* +* Copyright 2010 Analog Devices Inc. +* +* Licensed under the GPL-2 or later. +*/ + +#include <linux/interrupt.h> +#include <linux/gpio.h> +#include <linux/workqueue.h> +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/sysfs.h> +#include <linux/list.h> +#include <linux/i2c.h> +#include <linux/rtc.h> + +#include "../iio.h" +#include "../sysfs.h" + +/* +* AD7291 registers definition +*/ +#define AD7291_COMMAND 0 +#define AD7291_VOLTAGE 1 +#define AD7291_T_SENSE 2 +#define AD7291_T_AVERAGE 3 +#define AD7291_VOLTAGE_LIMIT_BASE 4 +#define AD7291_VOLTAGE_LIMIT_COUNT 8 +#define AD7291_T_SENSE_HIGH 0x1c +#define AD7291_T_SENSE_LOW 0x1d +#define AD7291_T_SENSE_HYST 0x1e +#define AD7291_VOLTAGE_ALERT_STATUS 0x1f +#define AD7291_T_ALERT_STATUS 0x20 + +/* +* AD7291 command +*/ +#define AD7291_AUTOCYCLE 0x1 +#define AD7291_RESET 0x2 +#define AD7291_ALART_CLEAR 0x4 +#define AD7291_ALART_POLARITY 0x8 +#define AD7291_EXT_REF 0x10 +#define AD7291_NOISE_DELAY 0x20 +#define AD7291_T_SENSE_MASK 0x40 +#define AD7291_VOLTAGE_MASK 0xff00 +#define AD7291_VOLTAGE_OFFSET 0x8 + +/* +* AD7291 value masks +*/ +#define AD7291_CHANNEL_MASK 0xf000 +#define AD7291_VALUE_MASK 0xfff +#define AD7291_T_VALUE_SIGN 0x400 +#define AD7291_T_VALUE_FLOAT_OFFSET 2 +#define AD7291_T_VALUE_FLOAT_MASK 0x2 + +/* +* struct ad7291_chip_info - chip specifc information +*/ + +struct ad7291_chip_info { +const char *name; +struct i2c_client *client; +struct iio_dev *indio_dev;
drivers/staging/iio/adc/ad7291.c line 77
Quoted 10 lines
drivers/staging/iio/adc/ad7291.c new file +10
-0+struct work_struct thresh_work; +s64 last_timestamp; +u16 command; +u8 channels;/* Active voltage channels */ +}; + +/* +* struct ad7291_chip_info - chip specifc information +*/ +
I don't think this is used?
Quoted 20 lines
drivers/staging/iio/adc/ad7291.c new file +20
-0+struct ad7291_limit_regs { +u16 data_high; +u16 data_low; +u16 hysteresis; +}; + +/* +* ad7291 register access by I2C +*/ +static int ad7291_i2c_read (struct ad7291_chip_info *chip,u8 reg,u16 *data) +{ +struct i2c_client *client = chip->client; +int ret =0 ; + + ret =i2c_smbus_read_word_data (client, reg); +if (ret <0 ) { +dev_err (&client->dev,"I2C read error\n" ); +return ret; + } +
drivers/staging/iio/adc/ad7291.c line 107
Quoted 10 lines
drivers/staging/iio/adc/ad7291.c new file +10
-0+ *data =swab16 ((u16 )ret); + +return 0 ; +} + +static int ad7291_i2c_write (struct ad7291_chip_info *chip,u8 reg,u16 data) +{ +struct i2c_client *client = chip->client; +int ret =0 ; +
Is that swab a general thing? Looks like a cpu to smbus ordering conversion.
Quoted 22 lines
drivers/staging/iio/adc/ad7291.c new file +22
-0+ ret =i2c_smbus_write_word_data (client, reg,swab16 (data)); +if (ret <0 ) +dev_err (&client->dev,"I2C write error\n" ); + +return ret; +} + +/* Returns negative errno, or else the number of words read. */ +static int ad7291_i2c_read_data (struct ad7291_chip_info *chip,u8 reg,u16 *data) +{ +struct i2c_client *client = chip->client; +u8 commands[4 ]; +int ret =0 ; +int i, count; + +if (reg ==AD7291_T_SENSE || reg ==AD7291_T_AVERAGE ) + count =2 ; +else if (reg ==AD7291_VOLTAGE ) { +if (!chip->channels) { +dev_err (&client->dev,"No voltage channel is selected.\n" ); +return -EINVAL ; + }
drivers/staging/iio/adc/ad7291.c line 139
Quoted 10 lines
drivers/staging/iio/adc/ad7291.c new file +10
-0+ count =2 + chip->channels *2 ; + }else { +dev_err (&client->dev,"I2C wrong data register\n" ); +return -EINVAL ; + } + + commands[0 ] =0 ; + commands[1 ] = (chip->command >>8 ) &0xff ; + commands[2 ] = chip->command &0xff ; + commands[3 ] = reg;
Can this init move up to initial definition of commands? Cleaner code that way.
Quoted 56 lines
drivers/staging/iio/adc/ad7291.c new file +56
-0+ + ret =i2c_master_send (client, commands,4 ); +if (ret <0 ) { +dev_err (&client->dev,"I2C master send error\n" ); +return ret; + } + + ret =i2c_master_recv (client, (u8 *)data, count); +if (ret <0 ) { +dev_err (&client->dev,"I2C master receive error\n" ); +return ret; + } + ret >>=2 ; + +for (i =0 ; i < ret; i++) + data[i] =swab16 (data[i]); + +return ret; +} + +static ssize_t ad7291_show_mode (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7291_chip_info *chip = dev_info->dev_data; + +if (chip->command &AD7291_AUTOCYCLE ) +return sprintf (buf,"autocycle\n" ); +else +return sprintf (buf,"command\n" ); +} + +static ssize_t ad7291_store_mode (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7291_chip_info *chip = dev_info->dev_data; +u16 command; +int ret; + + command = chip->command & (~AD7291_AUTOCYCLE ); +if (strcmp (buf,"autocycle" )) + command |=AD7291_AUTOCYCLE ; + + ret =ad7291_i2c_write (chip,AD7291_COMMAND , command); +if (ret) +return -EIO ; + + chip->command = command; + +return ret; +} +
drivers/staging/iio/adc/ad7291.c line 205
Quoted 10 lines
drivers/staging/iio/adc/ad7291.c new file +10
-0+static IIO_DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, + ad7291_show_mode, + ad7291_store_mode, + 0); + +static ssize_t ad7291_show_available_modes (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return sprintf (buf,"command\nautocycle\n" );
Space separated rather than new line please.
Quoted 144 lines
drivers/staging/iio/adc/ad7291.c new file +144
-0+} + +static IIO_DEVICE_ATTR(available_modes, S_IRUGO, ad7291_show_available_modes, NULL, 0); + +static ssize_t ad7291_store_reset (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7291_chip_info *chip = dev_info->dev_data; +u16 command; +int ret; + + command = chip->command |AD7291_RESET ; + + ret =ad7291_i2c_write (chip,AD7291_COMMAND , command); +if (ret) +return -EIO ; + +return ret; +} + +static IIO_DEVICE_ATTR(reset, S_IWUSR, + NULL, + ad7291_store_reset, + 0); + +static ssize_t ad7291_show_ext_ref (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7291_chip_info *chip = dev_info->dev_data; + +return sprintf (buf,"%d\n" , !!(chip->command &AD7291_EXT_REF )); +} + +static ssize_t ad7291_store_ext_ref (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7291_chip_info *chip = dev_info->dev_data; +u16 command; +int ret; + + command = chip->command & (~AD7291_EXT_REF ); +if (strcmp (buf,"1" )) + command |=AD7291_EXT_REF ; + + ret =ad7291_i2c_write (chip,AD7291_COMMAND , command); +if (ret) +return -EIO ; + + chip->command = command; + +return ret; +} + +static IIO_DEVICE_ATTR(ext_ref, S_IRUGO | S_IWUSR, + ad7291_show_ext_ref, + ad7291_store_ext_ref, + 0); + +static ssize_t ad7291_show_noise_delay (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7291_chip_info *chip = dev_info->dev_data; + +return sprintf (buf,"%d\n" , !!(chip->command &AD7291_NOISE_DELAY )); +} + +static ssize_t ad7291_store_noise_delay (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7291_chip_info *chip = dev_info->dev_data; +u16 command; +int ret; + + command = chip->command & (~AD7291_NOISE_DELAY ); +if (strcmp (buf,"1" )) + command |=AD7291_NOISE_DELAY ; + + ret =ad7291_i2c_write (chip,AD7291_COMMAND , command); +if (ret) +return -EIO ; + + chip->command = command; + +return ret; +} + +static IIO_DEVICE_ATTR(noise_delay, S_IRUGO | S_IWUSR, + ad7291_show_noise_delay, + ad7291_store_noise_delay, + 0); + +static ssize_t ad7291_show_t_sense (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7291_chip_info *chip = dev_info->dev_data; +u16 data; +char sign =' ' ; +int ret; + + ret =ad7291_i2c_read_data (chip,AD7291_T_SENSE , &data); +if (ret) +return -EIO ; + +if (data &AD7291_T_VALUE_SIGN ) { +/* convert supplement to positive value */ + data = (AD7291_T_VALUE_SIGN <<1 ) - data; + sign ='-' ; + } + +return sprintf (buf,"%c%d.%.2d\n" , sign, + (data >>AD7291_T_VALUE_FLOAT_OFFSET ), + (data &AD7291_T_VALUE_FLOAT_MASK ) *25 ); +} + +static IIO_DEVICE_ATTR(t_sense, S_IRUGO, ad7291_show_t_sense, NULL, 0); + +static ssize_t ad7291_show_t_average (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7291_chip_info *chip = dev_info->dev_data; +u16 data; +char sign =' ' ; +int ret; + + ret =ad7291_i2c_read_data (chip,AD7291_T_AVERAGE , &data); +if (ret) +return -EIO ;
drivers/staging/iio/adc/ad7291.c line 359
Quoted 10 lines
drivers/staging/iio/adc/ad7291.c new file +10
-0+ +if (data &AD7291_T_VALUE_SIGN ) { +/* convert supplement to positive value */ + data = (AD7291_T_VALUE_SIGN <<1 ) - data; + sign ='-' ; + } + +return sprintf (buf,"%c%d.%.2d\n" , sign, + (data >>AD7291_T_VALUE_FLOAT_OFFSET ), + (data &AD7291_T_VALUE_FLOAT_MASK ) *25 );
This is where the offset scale pair of attributes are your friends. Allow the complexity to move into userspace.
Quoted 11 lines
drivers/staging/iio/adc/ad7291.c new file +11
-0+} + +static IIO_DEVICE_ATTR(t_average, S_IRUGO, ad7291_show_t_average, NULL, 0); + +static ssize_t ad7291_show_voltage (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7291_chip_info *chip = dev_info->dev_data; +u16 data[AD7291_VOLTAGE_LIMIT_COUNT ];
drivers/staging/iio/adc/ad7291.c line 380
Quoted 10 lines
drivers/staging/iio/adc/ad7291.c new file +10
-0+int i, size, ret; + + ret =ad7291_i2c_read_data (chip,AD7291_VOLTAGE , data); +if (ret) +return -EIO ; + +for (i =0 ; i <AD7291_VOLTAGE_LIMIT_COUNT ; i++) { +if (chip->command & (AD7291_T_SENSE_MASK << i)) { + ret =sprintf (buf,"channel[%d]=%d\n" , i, + data[i] &AD7291_VALUE_MASK );
If you want to do scan's please use the buffer interface. Doing it via sysfs just doesn't generalize well.
drivers/staging/iio/adc/ad7291.c line 392
Quoted 12 lines
drivers/staging/iio/adc/ad7291.c new file +12
-0+if (ret <0 ) +break ; + buf += ret; + size += ret; + } + } + +return size; +} + +static IIO_DEVICE_ATTR(voltage, S_IRUGO, ad7291_show_voltage, NULL, 0); +
Not a chance on this interface. We very carefully worked out how to handle these sort of 'scanning' devices. See max1363 or Michael's Analog adc drivers.
Quoted 29 lines
drivers/staging/iio/adc/ad7291.c new file +29
-0+static ssize_t ad7291_show_channel_mask (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7291_chip_info *chip = dev_info->dev_data; + +return sprintf (buf,"0x%x\n" , (chip->command &AD7291_VOLTAGE_MASK ) >> +AD7291_VOLTAGE_OFFSET ); +} + +static ssize_t ad7291_store_channel_mask (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7291_chip_info *chip = dev_info->dev_data; +u16 command; +unsigned long data; +int i, ret; + + ret =strict_strtoul (buf,16 , &data); +if (ret || data >0xff ) +return -EINVAL ; + + command = chip->command & (~AD7291_VOLTAGE_MASK ); + command |= data <<AD7291_VOLTAGE_OFFSET ; +
drivers/staging/iio/adc/ad7291.c line 431
Quoted 10 lines
drivers/staging/iio/adc/ad7291.c new file +10
-0+ ret =ad7291_i2c_write (chip,AD7291_COMMAND , command); +if (ret) +return -EIO ; + + chip->command = command; + +for (i =0 , chip->channels =0 ; i <AD7291_VOLTAGE_LIMIT_COUNT ; i++) { +if (chip->command & (AD7291_T_SENSE_MASK << i)) + chip->channels++; + }
spurious brackets.
Quoted 10 lines
drivers/staging/iio/adc/ad7291.c new file +10
-0+ +return ret; +} + +static IIO_DEVICE_ATTR(channel_mask, S_IRUGO | S_IWUSR, + ad7291_show_channel_mask, + ad7291_store_channel_mask, + 0); + +static ssize_t ad7291_show_name(struct device *dev,
drivers/staging/iio/adc/ad7291.c line 451
Quoted 10 lines
drivers/staging/iio/adc/ad7291.c new file +10
-0+struct device_attribute *attr, + char *buf) +{ + struct iio_dev *dev_info = dev_get_drvdata(dev); +struct ad7291_chip_info *chip = dev_info->dev_data; +return sprintf (buf,"%s\n" , chip->name); +} + +static IIO_DEVICE_ATTR(name, S_IRUGO, ad7291_show_name, NULL, 0); +
As ever, I'm fussy about the abi.
drivers/staging/iio/adc/ad7291.c line 452
Quoted 1 line
drivers/staging/iio/adc/ad7291.c new file +1
-0+static struct attribute *ad7291_attributes[] = {
Probably want to break mode up and pretty much hide it's existence. I don't even know what control is!
drivers/staging/iio/adc/ad7291.c line 455
Quoted 3 lines
drivers/staging/iio/adc/ad7291.c new file +3
-0+ &iio_dev_attr_available_modes.dev_attr.attr, + &iio_dev_attr_mode.dev_attr.attr, + &iio_dev_attr_reset.dev_attr.attr,
This one needs some explanation. Is it something that would be better handled as a regulator?
drivers/staging/iio/adc/ad7291.c line 457
Quoted 2 lines
drivers/staging/iio/adc/ad7291.c new file +2
-0+ &iio_dev_attr_ext_ref.dev_attr.attr, + &iio_dev_attr_noise_delay.dev_attr.attr,
no idea.
drivers/staging/iio/adc/ad7291.c line 458
Quoted 1 line
drivers/staging/iio/adc/ad7291.c new file +1
-0+ &iio_dev_attr_t_sense.dev_attr.attr,
Need documetation. I suspect I won't agree with the naming though.
drivers/staging/iio/adc/ad7291.c line 459
Quoted 1 line
drivers/staging/iio/adc/ad7291.c new file +1
-0+ &iio_dev_attr_t_average.dev_attr.attr,
This appears to be a multichannel read. Usually implies that the device really needs a buffer based interface.
drivers/staging/iio/adc/ad7291.c line 460
Quoted 1 line
drivers/staging/iio/adc/ad7291.c new file +1
-0+ &iio_dev_attr_voltage.dev_attr.attr,
Will get cleaned up in a move to a buffer based interface.
Quoted 8 lines
drivers/staging/iio/adc/ad7291.c new file +8
-0+ &iio_dev_attr_channel_mask.dev_attr.attr, + &iio_dev_attr_name.dev_attr.attr, + NULL, +}; + +static const struct attribute_group ad7291_attribute_group = { + .attrs = ad7291_attributes, +};
drivers/staging/iio/adc/ad7291.c line 478
Quoted 10 lines
drivers/staging/iio/adc/ad7291.c new file +10
-0+ +/* +* temperature bound events +*/ + +#define IIO_EVENT_CODE_AD7291_T_SENSE_HIGH (IIO_EVENT_CODE_DEVICE_SPECIFIC + 1) +#define IIO_EVENT_CODE_AD7291_T_SENSE_LOW (IIO_EVENT_CODE_DEVICE_SPECIFIC + 2) +#define IIO_EVENT_CODE_AD7291_T_AVG_HIGH (IIO_EVENT_CODE_DEVICE_SPECIFIC + 3) +#define IIO_EVENT_CODE_AD7291_T_AVG_LOW (IIO_EVENT_CODE_DEVICE_SPECIFIC + 4) +#define IIO_EVENT_CODE_AD7291_VOLTAGE_BASE (IIO_EVENT_CODE_DEVICE_SPECIFIC + 5)
We'll be wanting to move a lot of these to general values rather than device specific ones.
Quoted 129 lines
drivers/staging/iio/adc/ad7291.c new file +129
-0+ +static void ad7291_interrupt_bh (struct work_struct *work_s) +{ +struct ad7291_chip_info *chip = + container_of(work_s, struct ad7291_chip_info, thresh_work); +u16 t_status, v_status; +u16 command; +int i; + +if (ad7291_i2c_read (chip,AD7291_T_ALERT_STATUS , &t_status)) +return ; + +if (ad7291_i2c_read (chip,AD7291_VOLTAGE_ALERT_STATUS , &v_status)) +return ; + +if (!(t_status || v_status)) +return ; + + command = chip->command |AD7291_ALART_CLEAR ; +ad7291_i2c_write (chip,AD7291_COMMAND , command); + + command = chip->command & ~AD7291_ALART_CLEAR ; +ad7291_i2c_write (chip,AD7291_COMMAND , command); + +enable_irq (chip->client->irq); + +for (i =0 ; i <4 ; i++) { +if (t_status & (1 << i)) +iio_push_event (chip->indio_dev,0 , +IIO_EVENT_CODE_AD7291_T_SENSE_HIGH + i, + chip->last_timestamp); + } + +for (i =0 ; i <AD7291_VOLTAGE_LIMIT_COUNT *2 ; i++) { +if (v_status & (1 << i)) +iio_push_event (chip->indio_dev,0 , +IIO_EVENT_CODE_AD7291_VOLTAGE_BASE + i, + chip->last_timestamp); + } +} + +static int ad7291_interrupt (struct iio_dev *dev_info, +int index, +s64 timestamp, +int no_test) +{ +struct ad7291_chip_info *chip = dev_info->dev_data; + + chip->last_timestamp = timestamp; +schedule_work (&chip->thresh_work); + +return 0 ; +} + +IIO_EVENT_SH (ad7291, &ad7291_interrupt); + +static inline ssize_t ad7291_show_t_bound (struct device *dev, +struct device_attribute *attr, +u8 bound_reg, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7291_chip_info *chip = dev_info->dev_data; +u16 data; +char sign =' ' ; +int ret; + + ret =ad7291_i2c_read (chip, bound_reg, &data); +if (ret) +return -EIO ; + + data &=AD7291_VALUE_MASK ; +if (data &AD7291_T_VALUE_SIGN ) { +/* convert supplement to positive value */ + data = (AD7291_T_VALUE_SIGN <<1 ) - data; + sign ='-' ; + } + +return sprintf (buf,"%c%d.%.2d\n" , sign, + data >>AD7291_T_VALUE_FLOAT_OFFSET , + (data &AD7291_T_VALUE_FLOAT_MASK ) *25 ); +} + +static inline ssize_t ad7291_set_t_bound (struct device *dev, +struct device_attribute *attr, +u8 bound_reg, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7291_chip_info *chip = dev_info->dev_data; +long tmp1, tmp2; +u16 data; +char *pos; +int ret; + + pos =strchr (buf,'.' ); + + ret =strict_strtol (buf,10 , &tmp1); + +if (ret || tmp1 >127 || tmp1 <-128 ) +return -EINVAL ; + +if (pos) { + len =strlen (pos); +if (len >AD7291_T_VALUE_FLOAT_OFFSET ) + len =AD7291_T_VALUE_FLOAT_OFFSET ; + pos[len] =0 ; + ret =strict_strtol (pos,10 , &tmp2); + +if (!ret) + tmp2 = (tmp2 /25 ) *25 ; + } + +if (tmp1 <0 ) + data = (u16)(-tmp1); +else + data = (u16 )tmp1; + data = (data <<AD7291_T_VALUE_FLOAT_OFFSET ) | + (tmp2 &AD7291_T_VALUE_FLOAT_MASK ); +if (tmp1 <0 ) +/* convert positive value to supplyment */ + data = (AD7291_T_VALUE_SIGN <<1 ) - data; + + ret =ad7291_i2c_write (chip, bound_reg, data); +if (ret) +return -EIO ; + +return ret;
drivers/staging/iio/adc/ad7291.c line 617
Quoted 10 lines
drivers/staging/iio/adc/ad7291.c new file +10
-0+} + +static ssize_t ad7291_show_t_sense_high (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return ad7291_show_t_bound (dev, attr, +AD7291_T_SENSE_HIGH , buf); +} +
Use the dataelements of the attribute and these can be trivially combined (as far as I can see)
Quoted 101 lines
drivers/staging/iio/adc/ad7291.c new file +101
-0+static inline ssize_t ad7291_set_t_sense_high (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +return ad7291_set_t_bound (dev, attr, +AD7291_T_SENSE_HIGH , buf, len); +} + +static ssize_t ad7291_show_t_sense_low (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return ad7291_show_t_bound (dev, attr, +AD7291_T_SENSE_LOW , buf); +} + +static inline ssize_t ad7291_set_t_sense_low (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +return ad7291_set_t_bound (dev, attr, +AD7291_T_SENSE_LOW , buf, len); +} + +static ssize_t ad7291_show_t_sense_hyst (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return ad7291_show_t_bound (dev, attr, +AD7291_T_SENSE_HYST , buf); +} + +static inline ssize_t ad7291_set_t_sense_hyst (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +return ad7291_set_t_bound (dev, attr, +AD7291_T_SENSE_HYST , buf, len); +} + +static inline ssize_t ad7291_show_v_bound (struct device *dev, +struct device_attribute *attr, +u8 bound_reg, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7291_chip_info *chip = dev_info->dev_data; +u16 data; +int ret; + +if (bound_reg <AD7291_VOLTAGE_LIMIT_BASE || + bound_reg >=AD7291_VOLTAGE_LIMIT_BASE + +AD7291_VOLTAGE_LIMIT_COUNT ) +return -EINVAL ; + + ret =ad7291_i2c_read (chip, bound_reg, &data); +if (ret) +return -EIO ; + + data &=AD7291_VALUE_MASK ; + +return sprintf (buf,"%d\n" , data); +} + +static inline ssize_t ad7291_set_v_bound (struct device *dev, +struct device_attribute *attr, +u8 bound_reg, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7291_chip_info *chip = dev_info->dev_data; +unsigned long value; +u16 data; +int ret; + +if (bound_reg <AD7291_VOLTAGE_LIMIT_BASE || + bound_reg >=AD7291_VOLTAGE_LIMIT_BASE + +AD7291_VOLTAGE_LIMIT_COUNT ) +return -EINVAL ; + + ret =strict_strtoul (buf,10 , &value); + +if (ret || value >=4096 ) +return -EINVAL ; + + data = (u16 )value; + ret =ad7291_i2c_write (chip, bound_reg, data); +if (ret) +return -EIO ; + +return ret; +} + +static int ad7291_get_voltage_limit_regs (const char *channel) +{ +int index; +
drivers/staging/iio/adc/ad7291.c line 728
Quoted 10 lines
drivers/staging/iio/adc/ad7291.c new file +10
-0+if (strlen (channel) <3 && channel[0 ] !='v' ) +return -EINVAL ; + + index = channel[1 ] -'0' ; +if (index >=AD7291_VOLTAGE_LIMIT_COUNT ) +return -EINVAL ; + +return index; +} +
I think a lot of these functions could be easily combined into one...
Quoted 77 lines
drivers/staging/iio/adc/ad7291.c new file +77
-0+static ssize_t ad7291_show_voltage_high (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +int regs; + + regs =ad7291_get_voltage_limit_regs (attr->attr.name); + +if (regs <0 ) +return regs; + +return ad7291_show_t_bound (dev, attr, regs, buf); +} + +static inline ssize_t ad7291_set_voltage_high (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +int regs; + + regs =ad7291_get_voltage_limit_regs (attr->attr.name); + +if (regs <0 ) +return regs; + +return ad7291_set_t_bound (dev, attr, regs, buf, len); +} + +static ssize_t ad7291_show_voltage_low (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +int regs; + + regs =ad7291_get_voltage_limit_regs (attr->attr.name); + +if (regs <0 ) +return regs; + +return ad7291_show_t_bound (dev, attr, regs+1 , buf); +} + +static inline ssize_t ad7291_set_voltage_low (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +int regs; + + regs =ad7291_get_voltage_limit_regs (attr->attr.name); + +if (regs <0 ) +return regs; + +return ad7291_set_t_bound (dev, attr, regs+1 , buf, len); +} + +static ssize_t ad7291_show_voltage_hyst (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +int regs; + + regs =ad7291_get_voltage_limit_regs (attr->attr.name); + +if (regs <0 ) +return regs; + +return ad7291_show_t_bound (dev, attr, regs+2 , buf); +} + +static inline ssize_t ad7291_set_voltage_hyst (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{
drivers/staging/iio/adc/ad7291.c line 815
Quoted 10 lines
drivers/staging/iio/adc/ad7291.c new file +10
-0+int regs; + + regs =ad7291_get_voltage_limit_regs (attr->attr.name); + +if (regs <0 ) +return regs; + +return ad7291_set_t_bound (dev, attr, regs+2 , buf, len); +} +
Where did t come from? And what is sense about?
These need bashing into the standard forms (perhaps with additions).
Things have gotten confused. The intent is that these macros use files that simply turn the event on or off. The value is typically separate (gets confusing otherwise as many devices share a single value across multiple channels).
drivers/staging/iio/adc/ad7291.c line 822
Quoted 7 lines
drivers/staging/iio/adc/ad7291.c new file +7
-0+IIO_EVENT_ATTR_SH (t_sense_high, iio_event_ad7291, + ad7291_show_t_sense_high, ad7291_set_t_sense_high,0 ); +IIO_EVENT_ATTR_SH (t_sense_low, iio_event_ad7291, + ad7291_show_t_sense_low, ad7291_set_t_sense_low,0 ); +IIO_EVENT_ATTR_SH (t_sense_hyst, iio_event_ad7291, + ad7291_show_t_sense_hyst, ad7291_set_t_sense_hyst,0 ); +
Where did v come from?
Quoted 217 lines
drivers/staging/iio/adc/ad7291.c new file +217
-0+IIO_EVENT_ATTR_SH (v0_high, iio_event_ad7291, + ad7291_show_voltage_high, ad7291_set_voltage_high,0 ); +IIO_EVENT_ATTR_SH (v0_low, iio_event_ad7291, + ad7291_show_voltage_low, ad7291_set_voltage_low,0 ); +IIO_EVENT_ATTR_SH (v0_hyst, iio_event_ad7291, + ad7291_show_voltage_hyst, ad7291_set_voltage_hyst,0 ); +IIO_EVENT_ATTR_SH (v1_high, iio_event_ad7291, + ad7291_show_voltage_high, ad7291_set_voltage_high,0 ); +IIO_EVENT_ATTR_SH (v1_low, iio_event_ad7291, + ad7291_show_voltage_low, ad7291_set_voltage_low,0 ); +IIO_EVENT_ATTR_SH (v1_hyst, iio_event_ad7291, + ad7291_show_voltage_hyst, ad7291_set_voltage_hyst,0 ); +IIO_EVENT_ATTR_SH (v2_high, iio_event_ad7291, + ad7291_show_voltage_high, ad7291_set_voltage_high,0 ); +IIO_EVENT_ATTR_SH (v2_low, iio_event_ad7291, + ad7291_show_voltage_low, ad7291_set_voltage_low,0 ); +IIO_EVENT_ATTR_SH (v2_hyst, iio_event_ad7291, + ad7291_show_voltage_hyst, ad7291_set_voltage_hyst,0 ); +IIO_EVENT_ATTR_SH (v3_high, iio_event_ad7291, + ad7291_show_voltage_high, ad7291_set_voltage_high,0 ); +IIO_EVENT_ATTR_SH (v3_low, iio_event_ad7291, + ad7291_show_voltage_low, ad7291_set_voltage_low,0 ); +IIO_EVENT_ATTR_SH (v3_hyst, iio_event_ad7291, + ad7291_show_voltage_hyst, ad7291_set_voltage_hyst,0 ); +IIO_EVENT_ATTR_SH (v4_high, iio_event_ad7291, + ad7291_show_voltage_high, ad7291_set_voltage_high,0 ); +IIO_EVENT_ATTR_SH (v4_low, iio_event_ad7291, + ad7291_show_voltage_low, ad7291_set_voltage_low,0 ); +IIO_EVENT_ATTR_SH (v4_hyst, iio_event_ad7291, + ad7291_show_voltage_hyst, ad7291_set_voltage_hyst,0 ); +IIO_EVENT_ATTR_SH (v5_high, iio_event_ad7291, + ad7291_show_voltage_high, ad7291_set_voltage_high,0 ); +IIO_EVENT_ATTR_SH (v5_low, iio_event_ad7291, + ad7291_show_voltage_low, ad7291_set_voltage_low,0 ); +IIO_EVENT_ATTR_SH (v5_hyst, iio_event_ad7291, + ad7291_show_voltage_hyst, ad7291_set_voltage_hyst,0 ); +IIO_EVENT_ATTR_SH (v6_high, iio_event_ad7291, + ad7291_show_voltage_high, ad7291_set_voltage_high,0 ); +IIO_EVENT_ATTR_SH (v6_low, iio_event_ad7291, + ad7291_show_voltage_low, ad7291_set_voltage_low,0 ); +IIO_EVENT_ATTR_SH (v6_hyst, iio_event_ad7291, + ad7291_show_voltage_hyst, ad7291_set_voltage_hyst,0 ); +IIO_EVENT_ATTR_SH (v7_high, iio_event_ad7291, + ad7291_show_voltage_high, ad7291_set_voltage_high,0 ); +IIO_EVENT_ATTR_SH (v7_low, iio_event_ad7291, + ad7291_show_voltage_low, ad7291_set_voltage_low,0 ); +IIO_EVENT_ATTR_SH (v7_hyst, iio_event_ad7291, + ad7291_show_voltage_hyst, ad7291_set_voltage_hyst,0 ); + +static struct attribute *ad7291_event_attributes[] = { + &iio_event_attr_t_sense_high.dev_attr.attr, + &iio_event_attr_t_sense_low.dev_attr.attr, + &iio_event_attr_t_sense_hyst.dev_attr.attr, + &iio_event_attr_v0_high.dev_attr.attr, + &iio_event_attr_v0_low.dev_attr.attr, + &iio_event_attr_v0_hyst.dev_attr.attr, + &iio_event_attr_v1_high.dev_attr.attr, + &iio_event_attr_v1_low.dev_attr.attr, + &iio_event_attr_v1_hyst.dev_attr.attr, + &iio_event_attr_v2_high.dev_attr.attr, + &iio_event_attr_v2_low.dev_attr.attr, + &iio_event_attr_v2_hyst.dev_attr.attr, + &iio_event_attr_v3_high.dev_attr.attr, + &iio_event_attr_v3_low.dev_attr.attr, + &iio_event_attr_v3_hyst.dev_attr.attr, + &iio_event_attr_v4_high.dev_attr.attr, + &iio_event_attr_v4_low.dev_attr.attr, + &iio_event_attr_v4_hyst.dev_attr.attr, + &iio_event_attr_v5_high.dev_attr.attr, + &iio_event_attr_v5_low.dev_attr.attr, + &iio_event_attr_v5_hyst.dev_attr.attr, + &iio_event_attr_v6_high.dev_attr.attr, + &iio_event_attr_v6_low.dev_attr.attr, + &iio_event_attr_v6_hyst.dev_attr.attr, + &iio_event_attr_v7_high.dev_attr.attr, + &iio_event_attr_v7_low.dev_attr.attr, + &iio_event_attr_v7_hyst.dev_attr.attr, +NULL , +}; + +static struct attribute_group ad7291_event_attribute_group = { + .attrs = ad7291_event_attributes, +}; + +/* +* device probe and remove +*/ + +static int __devinit ad7291_probe (struct i2c_client *client, +const struct i2c_device_id *id) +{ +struct ad7291_chip_info *chip; +int ret =0 ; + + chip =kzalloc (sizeof (struct ad7291_chip_info ),GFP_KERNEL ); + +if (chip ==NULL ) +return -ENOMEM ; + +/* this is only used for device removal purposes */ +i2c_set_clientdata (client, chip); + + chip->client = client; + chip->name = id->name; + chip->command =AD7291_NOISE_DELAY |AD7291_T_SENSE_MASK ; + + chip->indio_dev =iio_allocate_device (); +if (chip->indio_dev ==NULL ) { + ret = -ENOMEM ; + goto error_free_chip; + } + + chip->indio_dev->dev.parent = &client->dev; + chip->indio_dev->attrs = &ad7291_attribute_group; + chip->indio_dev->event_attrs = &ad7291_event_attribute_group; + chip->indio_dev->dev_data = (void *)chip; + chip->indio_dev->driver_module =THIS_MODULE ; + chip->indio_dev->num_interrupt_lines =1 ; + chip->indio_dev->modes =INDIO_DIRECT_MODE ; + + ret =iio_device_register (chip->indio_dev); +if (ret) + goto error_free_dev; + +if (client->irq >0 ) { + ret =iio_register_interrupt_line (client->irq, + chip->indio_dev, +0 , + client->irq_flags, + chip->name); +if (ret) + goto error_unreg_dev; + +/* +* The event handler list element refer to iio_event_ad7291. +* All event attributes bind to the same event handler. +* So, only register event handler once. +*/ +iio_add_event_to_list (&iio_event_ad7291, + &chip->indio_dev->interrupts[0 ]->ev_list); + +INIT_WORK (&chip->thresh_work, ad7291_interrupt_bh); + +if (client->irq_flags &IRQF_TRIGGER_LOW ) + chip->command |=AD7291_ALART_POLARITY ; + } + + ret =ad7291_i2c_write (chip,AD7291_COMMAND , chip->command); +if (ret) { + ret = -EIO ; + goto error_unreg_irq; + } + +dev_info (&client->dev,"%s temperature sensor registered.\n" , + id->name); + +return 0 ; + +error_unreg_irq: +iio_unregister_interrupt_line (chip->indio_dev,0 ); +error_unreg_dev: +iio_device_unregister (chip->indio_dev); +error_free_dev: +iio_free_device (chip->indio_dev); +error_free_chip: +kfree (chip); + +return ret; +} + +static int __devexit ad7291_remove(struct i2c_client *client) +{ +struct ad7291_chip_info *chip =i2c_get_clientdata (client); +struct iio_dev *indio_dev = chip->indio_dev; + +if (client->irq) +iio_unregister_interrupt_line (indio_dev,0 ); +iio_device_unregister (indio_dev); +iio_free_device (chip->indio_dev); +kfree (chip); + +return 0 ; +} + +static const struct i2c_device_id ad7291_id[] = { + {"ad7291" ,0 }, + {} +}; + +MODULE_DEVICE_TABLE (i2c, ad7291_id); + +static struct i2c_driver ad7291_driver = { + .driver = { + .name ="ad7291" , + }, + .probe = ad7291_probe, + .remove =__devexit_p (ad7291_remove), + .id_table = ad7291_id, +}; + +static __init int ad7291_init (void ) +{ +return i2c_add_driver (&ad7291_driver); +} + +static __exit void ad7291_exit(void) +{ +i2c_del_driver (&ad7291_driver); +} + +MODULE_AUTHOR ("Sonic Zhang <[email protected]>" ); +MODULE_DESCRIPTION ("Analog Devices AD7291 digital" +" temperature sensor driver" ); +MODULE_LICENSE ("GPL v2" ); + +module_init (ad7291_init); +module_exit (ad7291_exit);
PATCH 3/14 staging: iio: adc: new driver for AD7298 devices
In reply to Mike FrysingerFrom: Sonic Zhang <[email protected]>
--- drivers/staging/iio/adc/Kconfig | 7 + drivers/staging/iio/adc/Makefile | 1 + drivers/staging/iio/adc/ad7298.c | 501 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 509 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/iio/adc/ad7298.c
drivers/staging/iio/adc/Kconfig +7 -0
@@ -47,3 +47,10 @@ config AD7291 help Say yes here to build support for Analog Devices AD7291 temperature sensors. + +config AD7298 + tristate "Analog Devices AD7298 temperature sensor and ADC driver" + depends on SPI + help + Say yes here to build support for Analog Devices AD7298 + temperature sensors and ADC.
drivers/staging/iio/adc/Makefile +1 -0
@@ -9,3 +9,4 @@ obj-$(CONFIG_MAX1363) += max1363.o obj-$(CONFIG_AD7150) += ad7150.o obj-$(CONFIG_AD7152) += ad7152.o obj-$(CONFIG_AD7291) += ad7291.o +obj-$(CONFIG_AD7298) += ad7298.o
drivers/staging/iio/adc/ad7298.c new file +501 -0
501 lines not on this page · raw message
Signature · 1 line
1.7.3.2
Re: [PATCH 03/14] staging: iio: adc: new driver for AD7298 devices
Quoted 2 lines · Mike Frysinger
From: Sonic Zhang <[email protected]>
For devices like this, the commit message should justify why they should go in iio rather than hwmon. Based on a quick google, I'm guessing the speed is the main reason. Not many 1MSps adc's in hwmon ;) Which one is most appopriate is down to what people are using the device for.
Just to avoid arguements, I'd change the comments to say it's an adc with a temperature sensor (which is afterall what the website calls it)
I'm getting lazy, so I'm not pointing out most generic stuff I've already commented on elsewhere.
The busy wait is a bad thing. msleep please or mdelay if the precision is needed. Or even a oneshot interrupt?
Some error eating that could do to be cleaned up.
I'd like to see the abi breakage fixed, but the driver looks fundamentally sound, so feel free to send onto Greg as long as it is build tested and someone has the kit and time to do testing on any cleanup (or to do it of course ;) I'm going to get cynical and move to reviewed by on the drivers that break current abi spec.
Jonathan
Quoted 2 lines
Signed-off-by Sonic Zhang <[email protected]>Signed-off-by Mike Frysinger <[email protected]>
Quoted 76 lines
--- drivers/staging/iio/adc/Kconfig | 7 + drivers/staging/iio/adc/Makefile | 1 + drivers/staging/iio/adc/ad7298.c | 501 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 509 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/iio/adc/ad7298.cdrivers/staging/iio/adc/Kconfig +7
-0@@ -47,3 +47,10 @@ config AD7291 help Say yes here to build support for Analog Devices AD7291 temperature sensors. + +config AD7298 + tristate "Analog Devices AD7298 temperature sensor and ADC driver" + depends on SPI + help + Say yes here to build support for Analog Devices AD7298 + temperature sensors and ADC.drivers/staging/iio/adc/Makefile +1
-0@@ -9,3 +9,4 @@ obj-$(CONFIG_MAX1363) += max1363.o obj-$(CONFIG_AD7150) += ad7150.o obj-$(CONFIG_AD7152) += ad7152.o obj-$(CONFIG_AD7291) += ad7291.o +obj-$(CONFIG_AD7298) += ad7298.odrivers/staging/iio/adc/ad7298.c new file +39
-0@@ -0,0 +1,501 @@ +/* +* AD7298 digital temperature sensor driver supporting AD7298 +* +* Copyright 2010 Analog Devices Inc. +* +* Licensed under the GPL-2 or later. +*/ + +#include <linux/interrupt.h> +#include <linux/gpio.h> +#include <linux/workqueue.h> +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/sysfs.h> +#include <linux/list.h> +#include <linux/spi/spi.h> +#include <linux/rtc.h> + +#include "../iio.h" +#include "../sysfs.h" + +/* +* AD7298 command +*/ +#define AD7298_PD 0x1 +#define AD7298_T_AVG_MASK 0x2 +#define AD7298_EXT_REF 0x4 +#define AD7298_T_SENSE_MASK 0x20 +#define AD7298_VOLTAGE_MASK 0x3fc0 +#define AD7298_VOLTAGE_OFFSET 0x6 +#define AD7298_VOLTAGE_LIMIT_COUNT 8 +#define AD7298_REPEAT 0x40 +#define AD7298_WRITE 0x80 + +/* +* AD7298 value masks +*/ +#define AD7298_CHANNEL_MASK 0xf000
drivers/staging/iio/adc/ad7298.c line 49
Quoted 10 lines
drivers/staging/iio/adc/ad7298.c new file +10
-0+#define AD7298_VALUE_MASK 0xfff +#define AD7298_T_VALUE_SIGN 0x400 +#define AD7298_T_VALUE_FLOAT_OFFSET 2 +#define AD7298_T_VALUE_FLOAT_MASK 0x2 + +/* +* struct ad7298_chip_info - chip specifc information +*/ + +struct ad7298_chip_info {
claims to only support one device, so why not hard code the name where it is needed?
Quoted 53 lines
drivers/staging/iio/adc/ad7298.c new file +53
-0+const char *name; +struct spi_device *spi_dev; +struct iio_dev *indio_dev; +u16 command; +u16 busy_pin; +u8 channels;/* Active voltage channels */ +}; + +/* +* ad7298 register access by SPI +*/ +static int ad7298_spi_write (struct ad7298_chip_info *chip,u16 data) +{ +struct spi_device *spi_dev = chip->spi_dev; +int ret =0 ; + + data |=AD7298_WRITE ; + data =cpu_to_be16 (data); + ret =spi_write (spi_dev, (u8 *)&data,sizeof (data)); +if (ret <0 ) +dev_err (&spi_dev->dev,"SPI write error\n" ); + +return ret; +} + +static int ad7298_spi_read (struct ad7298_chip_info *chip,u16 mask,u16 *data) +{ +struct spi_device *spi_dev = chip->spi_dev; +int ret =0 ; +u8 count = chip->channels; +u16 command; +int i; + +if (mask &AD7298_T_SENSE_MASK ) { + command = chip->command & ~(AD7298_T_AVG_MASK |AD7298_VOLTAGE_MASK ); + command |=AD7298_T_SENSE_MASK ; + count =1 ; + }else if (mask &AD7298_T_AVG_MASK ) { + command = chip->command & ~AD7298_VOLTAGE_MASK ; + command |=AD7298_T_SENSE_MASK |AD7298_T_AVG_MASK ; + count =2 ; + }else if (mask &AD7298_VOLTAGE_MASK ) { + command = chip->command & ~(AD7298_T_AVG_MASK |AD7298_T_SENSE_MASK ); + count = chip->channels; + } + + ret =ad7298_spi_write (chip, chip->command); +if (ret <0 ) { +dev_err (&spi_dev->dev,"SPI write command error\n" ); +return ret; + } + + ret =spi_read (spi_dev, (u8 *)&command,sizeof (command));
drivers/staging/iio/adc/ad7298.c line 112
Quoted 10 lines
drivers/staging/iio/adc/ad7298.c new file +10
-0+if (ret <0 ) { +dev_err (&spi_dev->dev,"SPI read error\n" ); +return ret; + } + + i =10000 ; +while (i &&gpio_get_value (chip->busy_pin)) { +cpu_relax (); + i--; + }
Please use msleep rather than this.
Quoted 7 lines
drivers/staging/iio/adc/ad7298.c new file +7
-0+if (!i) { +dev_err (&spi_dev->dev,"Always in busy convertion.\n" ); +return -EBUSY ; + } + +for (i =0 ; i < count; i++) { + ret =spi_read (spi_dev, (u8 *)&data[i],sizeof (data[i]));
drivers/staging/iio/adc/ad7298.c line 129
Quoted 10 lines
drivers/staging/iio/adc/ad7298.c new file +10
-0+if (ret <0 ) { +dev_err (&spi_dev->dev,"SPI read error\n" ); +return ret; + } + *data =be16_to_cpu (data[i]); + } + +return 0 ; +} +
Again, please don't expose this directly. Just have the driver set it as required for whatever is currently going on.
Quoted 12 lines
drivers/staging/iio/adc/ad7298.c new file +12
-0+static ssize_t ad7298_show_mode (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7298_chip_info *chip = dev_info->dev_data; + +if (chip->command &AD7298_REPEAT ) +return sprintf (buf,"repeat\n" ); +else +return sprintf (buf,"normal\n" ); +}
drivers/staging/iio/adc/ad7298.c line 151
Quoted 10 lines
drivers/staging/iio/adc/ad7298.c new file +10
-0+ +static ssize_t ad7298_store_mode (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7298_chip_info *chip = dev_info->dev_data; + +if (strcmp (buf,"repeat" ))
Please sanity check the other mode has actually been entered. Also, sysfs_strcmp is more reliable for this use (gets rid of whitespace etc).
Quoted 6 lines
drivers/staging/iio/adc/ad7298.c new file +6
-0+ chip->command |=AD7298_REPEAT ; + else + chip->command &= (~AD7298_REPEAT); + +return 1 ; +}
drivers/staging/iio/adc/ad7298.c line 167
Quoted 10 lines
drivers/staging/iio/adc/ad7298.c new file +10
-0+ +static IIO_DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, + ad7298_show_mode, + ad7298_store_mode, + 0); + +static ssize_t ad7298_show_available_modes (struct device *dev, +struct device_attribute *attr, +char *buf) +{
space separated.
Quoted 9 lines
drivers/staging/iio/adc/ad7298.c new file +9
-0+return sprintf (buf,"normal\nrepeat\n" ); +} + +static IIO_DEVICE_ATTR(available_modes, S_IRUGO, ad7298_show_available_modes, NULL, 0); + +static ssize_t ad7298_store_reset (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len)
drivers/staging/iio/adc/ad7298.c line 186
Quoted 10 lines
drivers/staging/iio/adc/ad7298.c new file +10
-0+{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7298_chip_info *chip = dev_info->dev_data; +u16 command; +int ret; + + command = chip->command & ~AD7298_PD ; + + ret =ad7298_spi_write (chip, command); +if (ret)
eating errors.
drivers/staging/iio/adc/ad7298.c line 192
Quoted 6 lines
drivers/staging/iio/adc/ad7298.c new file +6
-0+return -EIO ; + + command = chip->command |AD7298_PD ; + + ret =ad7298_spi_write (chip, command); +if (ret)
eating errors.
Quoted 9 lines
drivers/staging/iio/adc/ad7298.c new file +9
-0+return -EIO ; + +return len; +} + +static IIO_DEVICE_ATTR(reset, S_IWUSR, + NULL, + ad7298_store_reset, + 0);
drivers/staging/iio/adc/ad7298.c line 211
Quoted 10 lines
drivers/staging/iio/adc/ad7298.c new file +10
-0+ +static ssize_t ad7298_show_ext_ref (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7298_chip_info *chip = dev_info->dev_data; + +return sprintf (buf,"%d\n" , !!(chip->command &AD7298_EXT_REF )); +}
Regulator subsystem perhaps?
drivers/staging/iio/adc/ad7298.c line 224
Quoted 13 lines
drivers/staging/iio/adc/ad7298.c new file +13
-0+ +static ssize_t ad7298_store_ext_ref (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7298_chip_info *chip = dev_info->dev_data; +u16 command; +int ret; + + command = chip->command & (~AD7298_EXT_REF ); +if (strcmp (buf,"1" ))
sysfs_strcmp.
Quoted 74 lines
drivers/staging/iio/adc/ad7298.c new file +74
-0+ command |=AD7298_EXT_REF ; + + ret =ad7298_spi_write (chip, command); +if (ret) +return -EIO ; + + chip->command = command; + +return len; +} + +static IIO_DEVICE_ATTR(ext_ref, S_IRUGO | S_IWUSR, + ad7298_show_ext_ref, + ad7298_store_ext_ref, + 0); + +static ssize_t ad7298_show_t_sense (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7298_chip_info *chip = dev_info->dev_data; +u16 data; +char sign =' ' ; +int ret; + + ret =ad7298_spi_read (chip,AD7298_T_SENSE_MASK , &data); +if (ret) +return -EIO ; + +if (data &AD7298_T_VALUE_SIGN ) { +/* convert supplement to positive value */ + data = (AD7298_T_VALUE_SIGN <<1 ) - data; + sign ='-' ; + } + +return sprintf (buf,"%c%d.%.2d\n" , sign, + (data >>AD7298_T_VALUE_FLOAT_OFFSET ), + (data &AD7298_T_VALUE_FLOAT_MASK ) *25 ); +} + +static IIO_DEVICE_ATTR(t_sense, S_IRUGO, ad7298_show_t_sense, NULL, 0); + +static ssize_t ad7298_show_t_average (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7298_chip_info *chip = dev_info->dev_data; +u16 data[2 ]; +char sign =' ' ; +int ret; + + ret =ad7298_spi_read (chip,AD7298_T_AVG_MASK , data); +if (ret) +return -EIO ; + +if (data[1 ] &AD7298_T_VALUE_SIGN ) { +/* convert supplement to positive value */ + data[1 ] = (AD7298_T_VALUE_SIGN <<1 ) - data[1 ]; + sign ='-' ; + } + +return sprintf (buf,"%c%d.%.2d\n" , sign, + (data[1 ] >>AD7298_T_VALUE_FLOAT_OFFSET ), + (data[1 ] &AD7298_T_VALUE_FLOAT_MASK ) *25 ); +} + +static IIO_DEVICE_ATTR(t_average, S_IRUGO, ad7298_show_t_average, NULL, 0); + +static ssize_t ad7298_show_voltage (struct device *dev, +struct device_attribute *attr, +char *buf) +{
drivers/staging/iio/adc/ad7298.c line 308
Quoted 10 lines
drivers/staging/iio/adc/ad7298.c new file +10
-0+struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7298_chip_info *chip = dev_info->dev_data; +u16 data[AD7298_VOLTAGE_LIMIT_COUNT ]; +int i, size, ret; + + ret =ad7298_spi_read (chip,AD7298_VOLTAGE_MASK , data); +if (ret) +return -EIO ; + +for (i =0 ; i <AD7298_VOLTAGE_LIMIT_COUNT ; i++) {
spurious bracket.
drivers/staging/iio/adc/ad7298.c line 314
Quoted 6 lines
drivers/staging/iio/adc/ad7298.c new file +6
-0+if (chip->command & (AD7298_T_SENSE_MASK << i)) { + ret =sprintf (buf,"channel[%d]=%d\n" , i, + data[i] &AD7298_VALUE_MASK ); +if (ret <0 ) +break ; + buf += ret;
Any reason to not just use, buf + size in the sprintf? Cleaner code that way.
drivers/staging/iio/adc/ad7298.c line 323
Quoted 9 lines
drivers/staging/iio/adc/ad7298.c new file +9
-0+ size += ret; + } + } + +return size; +} + +static IIO_DEVICE_ATTR(voltage, S_IRUGO, ad7298_show_voltage, NULL, 0); +
Again, this pretty much implies the device ought to use the buffer interface.
Quoted 18 lines
drivers/staging/iio/adc/ad7298.c new file +18
-0+static ssize_t ad7298_show_channel_mask (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7298_chip_info *chip = dev_info->dev_data; + +return sprintf (buf,"0x%x\n" , (chip->command &AD7298_VOLTAGE_MASK ) >> +AD7298_VOLTAGE_OFFSET ); +} + +static ssize_t ad7298_store_channel_mask (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7298_chip_info *chip = dev_info->dev_data;
drivers/staging/iio/adc/ad7298.c line 351
Quoted 10 lines
drivers/staging/iio/adc/ad7298.c new file +10
-0+unsigned long data; +int i, ret; + + ret =strict_strtoul (buf,16 , &data); +if (ret || data >0xff ) +return -EINVAL ; + + chip->command &= (~AD7298_VOLTAGE_MASK ); + chip->command |= data <<AD7298_VOLTAGE_OFFSET ; +
spurious bracket.
Quoted 20 lines
drivers/staging/iio/adc/ad7298.c new file +20
-0+for (i =0 , chip->channels =0 ; i <AD7298_VOLTAGE_LIMIT_COUNT ; i++) { +if (chip->command & (AD7298_T_SENSE_MASK << i)) + chip->channels++; + } + +return ret; +} + +static IIO_DEVICE_ATTR(channel_mask, S_IRUGO | S_IWUSR, + ad7298_show_channel_mask, + ad7298_store_channel_mask, + 0); + +static ssize_t ad7298_show_name (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7298_chip_info *chip = dev_info->dev_data; +return sprintf (buf,"%s\n" , chip->name);
drivers/staging/iio/adc/ad7298.c line 381
Quoted 10 lines
drivers/staging/iio/adc/ad7298.c new file +10
-0+} + +static IIO_DEVICE_ATTR(name, S_IRUGO, ad7298_show_name, NULL, 0); + +static struct attribute *ad7298_attributes[] = { + &iio_dev_attr_available_modes.dev_attr.attr, + &iio_dev_attr_mode.dev_attr.attr, + &iio_dev_attr_reset.dev_attr.attr, + &iio_dev_attr_ext_ref.dev_attr.attr, + &iio_dev_attr_t_sense.dev_attr.attr,
temp0_input
drivers/staging/iio/adc/ad7298.c line 382
Quoted 1 line
drivers/staging/iio/adc/ad7298.c new file +1
-0+ &iio_dev_attr_t_average.dev_attr.attr,
temp0_mean_input
Quoted 119 lines
drivers/staging/iio/adc/ad7298.c new file +119
-0+ &iio_dev_attr_voltage.dev_attr.attr, + &iio_dev_attr_channel_mask.dev_attr.attr, + &iio_dev_attr_name.dev_attr.attr, + NULL, +}; + +static const struct attribute_group ad7298_attribute_group = { + .attrs = ad7298_attributes, +}; + +/* +* device probe and remove +*/ +static int __devinit ad7298_probe (struct spi_device *spi_dev) +{ +struct ad7298_chip_info *chip; +unsigned short *pins = spi_dev->dev.platform_data; +int ret =0 ; + + chip =kzalloc (sizeof (struct ad7298_chip_info ),GFP_KERNEL ); + +if (chip ==NULL ) +return -ENOMEM ; + +/* this is only used for device removal purposes */ +dev_set_drvdata (&spi_dev->dev, chip); + + chip->spi_dev = spi_dev; + chip->name = spi_dev->modalias; + chip->busy_pin = pins[0 ]; + + ret =gpio_request (chip->busy_pin, chip->name); +if (ret) { +dev_err (&spi_dev->dev,"Fail to request busy gpio PIN %d.\n" , + chip->busy_pin); + goto error_free_chip; + } +gpio_direction_input (chip->busy_pin); + + chip->indio_dev =iio_allocate_device (); +if (chip->indio_dev ==NULL ) { + ret = -ENOMEM ; + goto error_free_gpio; + } + + chip->indio_dev->dev.parent = &spi_dev->dev; + chip->indio_dev->attrs = &ad7298_attribute_group; + chip->indio_dev->dev_data = (void *)chip; + chip->indio_dev->driver_module =THIS_MODULE ; + chip->indio_dev->modes =INDIO_DIRECT_MODE ; + + ret =iio_device_register (chip->indio_dev); +if (ret) + goto error_free_dev; + +dev_info (&spi_dev->dev,"%s temperature sensor and ADC registered.\n" , + chip->name); + +return 0 ; + +error_free_dev: +iio_free_device (chip->indio_dev); +error_free_gpio: +gpio_free (chip->busy_pin); +error_free_chip: +kfree (chip); + +return ret; +} + +static int __devexit ad7298_remove(struct spi_device *spi_dev) +{ +struct ad7298_chip_info *chip =dev_get_drvdata (&spi_dev->dev); +struct iio_dev *indio_dev = chip->indio_dev; + +dev_set_drvdata (&spi_dev->dev,NULL ); +iio_device_unregister (indio_dev); +iio_free_device (chip->indio_dev); +gpio_free (chip->busy_pin); +kfree (chip); + +return 0 ; +} + +static const struct spi_device_id ad7298_id[] = { + {"ad7298" ,0 }, + {} +}; + +MODULE_DEVICE_TABLE (spi, ad7298_id); + +static struct spi_driver ad7298_driver = { + .driver = { + .name ="ad7298" , + .bus = &spi_bus_type, + .owner =THIS_MODULE , + }, + .probe = ad7298_probe, + .remove =__devexit_p (ad7298_remove), + .id_table = ad7298_id, +}; + +static __init int ad7298_init (void ) +{ +return spi_register_driver (&ad7298_driver); +} + +static __exit void ad7298_exit(void) +{ +spi_unregister_driver (&ad7298_driver); +} + +MODULE_AUTHOR ("Sonic Zhang <[email protected]>" ); +MODULE_DESCRIPTION ("Analog Devices AD7298 digital" +" temperature sensor and ADC driver" ); +MODULE_LICENSE ("GPL v2" ); + +module_init (ad7298_init); +module_exit (ad7298_exit);
PATCH 4/14 staging: iio: adc: new driver for AD7314 devices
In reply to Mike FrysingerFrom: Sonic Zhang <[email protected]>
--- drivers/staging/iio/adc/Kconfig | 7 + drivers/staging/iio/adc/Makefile | 1 + drivers/staging/iio/adc/ad7314.c | 308 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 316 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/iio/adc/ad7314.c
drivers/staging/iio/adc/Kconfig +7 -0
@@ -54,3 +54,10 @@ config AD7298 help Say yes here to build support for Analog Devices AD7298 temperature sensors and ADC. + +config AD7314 + tristate "Analog Devices AD7314 temperature sensor driver" + depends on SPI + help + Say yes here to build support for Analog Devices AD7314 + temperature sensors.
drivers/staging/iio/adc/Makefile +1 -0
@@ -10,3 +10,4 @@ obj-$(CONFIG_AD7150) += ad7150.o obj-$(CONFIG_AD7152) += ad7152.o obj-$(CONFIG_AD7291) += ad7291.o obj-$(CONFIG_AD7298) += ad7298.o +obj-$(CONFIG_AD7314) += ad7314.o
drivers/staging/iio/adc/ad7314.c new file +308 -0
308 lines not on this page · raw message
Signature · 1 line
1.7.3.2
Re: [PATCH 04/14] staging: iio: adc: new driver for AD7314 devices
Quoted 2 lines · Mike Frysinger
From: Sonic Zhang <[email protected]>
Why IIO? Do you have a use case that needs features off IIO and wouldn't be covered by hwmon?
Not using any here, so I'm doubtful about this (Sonic and I exchanged a few emails about this a while back).
Few comments inline and I guess iio then moving to hwmon is fine with me if you want to do it... (hwmon is simpler!).
Quoted 14 lines
Signed-off-by Sonic Zhang <[email protected]>Signed-off-by Mike Frysinger <[email protected]>--- drivers/staging/iio/adc/Kconfig | 7 + drivers/staging/iio/adc/Makefile | 1 + drivers/staging/iio/adc/ad7314.c | 308 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 316 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/iio/adc/ad7314.cdrivers/staging/iio/adc/Kconfig +0
-0
drivers/staging/iio/adc/Kconfig config AD7298 · line 60
Quoted 7 lines
drivers/staging/iio/adc/Kconfig +4
-0@@ -54,3 +54,10 @@ config AD7298 help Say yes here to build support for Analog Devices AD7298 temperature sensors and ADC. + +config AD7314 + tristate "Analog Devices AD7314 temperature sensor driver" + depends on SPI
Please list all parts supported (appear to be several others in the id table.)
Quoted 137 lines
drivers/staging/iio/adc/Kconfig +3
-0+ help + Say yes here to build support for Analog Devices AD7314 + temperature sensors.drivers/staging/iio/adc/Makefile +1
-0@@ -10,3 +10,4 @@ obj-$(CONFIG_AD7150) += ad7150.o obj-$(CONFIG_AD7152) += ad7152.o obj-$(CONFIG_AD7291) += ad7291.o obj-$(CONFIG_AD7298) += ad7298.o +obj-$(CONFIG_AD7314) += ad7314.odrivers/staging/iio/adc/ad7314.c new file +119
-0@@ -0,0 +1,308 @@ +/* +* AD7314 digital temperature sensor driver for AD7314, ADT7301 and ADT7302 +* +* Copyright 2010 Analog Devices Inc. +* +* Licensed under the GPL-2 or later. +*/ + +#include <linux/interrupt.h> +#include <linux/gpio.h> +#include <linux/workqueue.h> +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/sysfs.h> +#include <linux/list.h> +#include <linux/spi/spi.h> +#include <linux/rtc.h> + +#include "../iio.h" +#include "../sysfs.h" + +/* +* AD7314 power mode +*/ +#define AD7314_PD 0x2000 + +/* +* AD7314 temperature masks +*/ +#define AD7314_TEMP_SIGN 0x200 +#define AD7314_TEMP_MASK 0x7FE0 +#define AD7314_TEMP_OFFSET 5 +#define AD7314_TEMP_FLOAT_OFFSET 2 +#define AD7314_TEMP_FLOAT_MASK 0x3 + +/* +* ADT7301 and ADT7302 temperature masks +*/ +#define ADT7301_TEMP_SIGN 0x2000 +#define ADT7301_TEMP_MASK 0x2FFF +#define ADT7301_TEMP_FLOAT_OFFSET 5 +#define ADT7301_TEMP_FLOAT_MASK 0x1F + +/* +* struct ad7314_chip_info - chip specifc information +*/ + +struct ad7314_chip_info { +const char *name; +struct spi_device *spi_dev; +struct iio_dev *indio_dev; +s64 last_timestamp; +u8 mode; +}; + +/* +* ad7314 register access by SPI +*/ + +static int ad7314_spi_read (struct ad7314_chip_info *chip,u16 *data) +{ +struct spi_device *spi_dev = chip->spi_dev; +int ret =0 ; +u16 value; + + ret =spi_read (spi_dev, (u8 *)&value,sizeof (value)); +if (ret <0 ) { +dev_err (&spi_dev->dev,"SPI read error\n" ); +return ret; + } + + *data =be16_to_cpu ((u16 )value); + +return ret; +} + +static int ad7314_spi_write (struct ad7314_chip_info *chip,u16 data) +{ +struct spi_device *spi_dev = chip->spi_dev; +int ret =0 ; +u16 value =cpu_to_be16 (data); + + ret =spi_write (spi_dev, (u8 *)&value,sizeof (value)); +if (ret <0 ) +dev_err (&spi_dev->dev,"SPI write error\n" ); + +return ret; +} + +static ssize_t ad7314_show_mode (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7314_chip_info *chip = dev_info->dev_data; + +if (chip->mode) +return sprintf (buf,"power-save\n" ); +else +return sprintf (buf,"full\n" ); +} + +static ssize_t ad7314_store_mode (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7314_chip_info *chip = dev_info->dev_data; +u16 mode =0 ; +int ret; + +if (!strcmp (buf,"full" )) + mode =AD7314_PD ; + + ret =ad7314_spi_write (chip, mode); +if (ret) +return -EIO ;
drivers/staging/iio/adc/ad7314.c line 129
Quoted 10 lines
drivers/staging/iio/adc/ad7314.c new file +10
-0+ + chip->mode = mode; + +return len; +} + +static IIO_DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, + ad7314_show_mode, + ad7314_store_mode, + 0);
I'm still anti 'mode' attributes. They just don't generalize.
drivers/staging/iio/adc/ad7314.c line 135
Quoted 6 lines
drivers/staging/iio/adc/ad7314.c new file +6
-0+ +static ssize_t ad7314_show_available_modes (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return sprintf (buf,"full\npower-save\n" );
Do this via sampling_frequency (assuming that is what changes!)
drivers/staging/iio/adc/ad7314.c line 138
Quoted 3 lines
drivers/staging/iio/adc/ad7314.c new file +3
-0+} + +static IIO_DEVICE_ATTR(available_modes, S_IRUGO, ad7314_show_available_modes, NULL, 0);
mode_available please.
Quoted 5 lines
drivers/staging/iio/adc/ad7314.c new file +5
-0+ +static ssize_t ad7314_show_temperature (struct device *dev, +struct device_attribute *attr, +char *buf) +{
drivers/staging/iio/adc/ad7314.c line 153
Quoted 10 lines
drivers/staging/iio/adc/ad7314.c new file +10
-0+struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7314_chip_info *chip = dev_info->dev_data; +u16 data; +char sign =' ' ; +int ret; + +if (chip->mode) { + ret =ad7314_spi_write (chip,0 ); +if (ret) +return -EIO ;
Error eating.
Quoted 40 lines
drivers/staging/iio/adc/ad7314.c new file +40
-0+ } + + ret =ad7314_spi_read (chip, &data); +if (ret) +return -EIO ; + +if (chip->mode) +ad7314_spi_write (chip, chip->mode); + +if (strcmp (chip->name,"ad7314" )) { + data = (data &AD7314_TEMP_MASK ) >> +AD7314_TEMP_OFFSET ; +if (data &AD7314_TEMP_SIGN ) { + data = (AD7314_TEMP_SIGN <<1 ) - data; + sign ='-' ; + } + +return sprintf (buf,"%c%d.%.2d\n" , sign, + data >>AD7314_TEMP_FLOAT_OFFSET , + (data &AD7314_TEMP_FLOAT_MASK ) *25 ); + }else { + data &=ADT7301_TEMP_MASK ; +if (data &ADT7301_TEMP_SIGN ) { + data = (ADT7301_TEMP_SIGN <<1 ) - data; + sign ='-' ; + } + +return sprintf (buf,"%c%d.%.5d\n" , sign, + data >>ADT7301_TEMP_FLOAT_OFFSET , + (data &ADT7301_TEMP_FLOAT_MASK ) *3125 ); + } +} + +static IIO_DEVICE_ATTR(temperature, S_IRUGO, ad7314_show_temperature, NULL, 0); + +static ssize_t ad7314_show_name (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev);
drivers/staging/iio/adc/ad7314.c line 203
Quoted 10 lines
drivers/staging/iio/adc/ad7314.c new file +10
-0+struct ad7314_chip_info *chip = dev_info->dev_data; +return sprintf (buf,"%s\n" , chip->name); +} + +static IIO_DEVICE_ATTR(name, S_IRUGO, ad7314_show_name, NULL, 0); + +static struct attribute *ad7314_attributes[] = { + &iio_dev_attr_available_modes.dev_attr.attr, + &iio_dev_attr_mode.dev_attr.attr, + &iio_dev_attr_temperature.dev_attr.attr,
temp_input please (we match hwmon where possible).
Quoted 105 lines
drivers/staging/iio/adc/ad7314.c new file +105
-0+ &iio_dev_attr_name.dev_attr.attr, + NULL, +}; + +static const struct attribute_group ad7314_attribute_group = { + .attrs = ad7314_attributes, +}; + +/* +* device probe and remove +*/ + +static int __devinit ad7314_probe (struct spi_device *spi_dev) +{ +struct ad7314_chip_info *chip; +int ret =0 ; + + chip =kzalloc (sizeof (struct ad7314_chip_info ),GFP_KERNEL ); + +if (chip ==NULL ) +return -ENOMEM ; + +/* this is only used for device removal purposes */ +dev_set_drvdata (&spi_dev->dev, chip); + + chip->spi_dev = spi_dev; + chip->name = spi_dev->modalias; + + chip->indio_dev =iio_allocate_device (); +if (chip->indio_dev ==NULL ) { + ret = -ENOMEM ; + goto error_free_chip; + } + + chip->indio_dev->dev.parent = &spi_dev->dev; + chip->indio_dev->attrs = &ad7314_attribute_group; + chip->indio_dev->dev_data = (void *)chip; + chip->indio_dev->driver_module =THIS_MODULE ; + + ret =iio_device_register (chip->indio_dev); +if (ret) + goto error_free_dev; + +dev_info (&spi_dev->dev,"%s temperature sensor registered.\n" , + chip->name); + +return 0 ; +error_free_dev: +iio_free_device (chip->indio_dev); +error_free_chip: +kfree (chip); + +return ret; +} + +static int __devexit ad7314_remove(struct spi_device *spi_dev) +{ +struct ad7314_chip_info *chip =dev_get_drvdata (&spi_dev->dev); +struct iio_dev *indio_dev = chip->indio_dev; + +dev_set_drvdata (&spi_dev->dev,NULL ); +if (spi_dev->irq) +iio_unregister_interrupt_line (indio_dev,0 ); +iio_device_unregister (indio_dev); +iio_free_device (chip->indio_dev); +kfree (chip); + +return 0 ; +} + +static const struct spi_device_id ad7314_id[] = { + {"adt7301" ,0 }, + {"adt7302" ,0 }, + {"ad7314" ,0 }, + {} +}; + +static struct spi_driver ad7314_driver = { + .driver = { + .name ="ad7314" , + .bus = &spi_bus_type, + .owner =THIS_MODULE , + }, + .probe = ad7314_probe, + .remove =__devexit_p (ad7314_remove), + .id_table = ad7314_id, +}; + +static __init int ad7314_init (void ) +{ +return spi_register_driver (&ad7314_driver); +} + +static __exit void ad7314_exit(void) +{ +spi_unregister_driver (&ad7314_driver); +} + +MODULE_AUTHOR ("Sonic Zhang <[email protected]>" ); +MODULE_DESCRIPTION ("Analog Devices AD7314, ADT7301 and ADT7302 digital" +" temperature sensor driver" ); +MODULE_LICENSE ("GPL v2" ); + +module_init (ad7314_init); +module_exit (ad7314_exit);
RE: [PATCH 04/14] staging: iio: adc: new driver for AD7314 devices
Quoted 11 lines
-----Original Message-----
From: Jonathan Cameron [mailto:[email protected]]
Sent: Monday, October 25, 2010 5:57 AM
To: Mike Frysinger
Cc: [email protected]; [email protected]; Zhang, Sonic
Subject: Re: [PATCH 04/14] staging: iio: adc: new driver for AD7314 devices
Quoted 5 lines
Quoted 2 lines · Mike Frysinger
From: Sonic Zhang <[email protected]>
Why IIO? Do you have a use case that needs features off IIO and wouldn't be covered by hwmon?
You are right. AD7314 is not necessary to use IIO framework without interru= pt available.
We may move it to hwmon framework late.
Sonic
Quoted 370 lines
Not using any here, so I'm doubtful about this (Sonic and I exchanged a few emails about this a while back).
Few comments inline and I guess iio then moving to hwmon is fine with me if you want to do it... (hwmon is simpler!).
Quoted 15 lines
Signed-off-by Sonic Zhang <[email protected]>Signed-off-by Mike Frysinger <[email protected]>--- drivers/staging/iio/adc/Kconfig | 7 + drivers/staging/iio/adc/Makefile | 1 + drivers/staging/iio/adc/ad7314.c | 308 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 316 insertions(+), 0 deletions(-) create mode100644
drivers/staging/iio/adc/ad7314.c(quoted diff) +0
-0b/drivers/staging/iio/adc/Kconfig index 847f5f2..6d3b8bc 100644
drivers/staging/iio/adc/Kconfig config AD7298 · line 60
Quoted 7 lines
drivers/staging/iio/adc/Kconfig +4
-0@@ -54,3 +54,10 @@ config AD7298 help Say yes here to build support for Analog Devices AD7298 temperature sensors and ADC. + +config AD7314 + tristate "Analog Devices AD7314 temperature sensor driver" + depends on SPIPlease list all parts supported (appear to be several others in the id table.)
Quoted 70 lines
drivers/staging/iio/adc/Kconfig +3
-0+ help + Say yes here to build support for Analog Devices AD7314 + temperature sensors.drivers/staging/iio/adc/Makefile +1
-0@@ -10,3 +10,4 @@ obj-$(CONFIG_AD7150) +=3D ad7150.o obj-$(CONFIG_AD7152) +=3D ad7152.o obj-$(CONFIG_AD7291) +=3D ad7291.o obj-$(CONFIG_AD7298) +=3D ad7298.o +obj-$(CONFIG_AD7314) +=3D ad7314.odrivers/staging/iio/adc/ad7314.c new file +50
-0@@ -0,0 +1,308 @@ +/* +* AD7314 digital temperature sensor driver for AD7314, ADT7301 and +ADT7302 +* +* Copyright 2010 Analog Devices Inc. +* +* Licensed under the GPL-2 or later. +*/ + +#include <linux/interrupt.h> +#include <linux/gpio.h> +#include <linux/workqueue.h> +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/sysfs.h> +#include <linux/list.h> +#include <linux/spi/spi.h> +#include <linux/rtc.h> + +#include "../iio.h" +#include "../sysfs.h" + +/* +* AD7314 power mode +*/ +#define AD7314_PD 0x2000 + +/* +* AD7314 temperature masks +*/ +#define AD7314_TEMP_SIGN 0x200 +#define AD7314_TEMP_MASK 0x7FE0 +#define AD7314_TEMP_OFFSET 5 +#define AD7314_TEMP_FLOAT_OFFSET 2 +#define AD7314_TEMP_FLOAT_MASK 0x3 + +/* +* ADT7301 and ADT7302 temperature masks */ +#define ADT7301_TEMP_SIGN 0x2000 +#define ADT7301_TEMP_MASK 0x2FFF +#define ADT7301_TEMP_FLOAT_OFFSET 5 +#define ADT7301_TEMP_FLOAT_MASK 0x1F + +/* +* struct ad7314_chip_info - chip specifc information */ + +struct ad7314_chip_info { +const char *name; +struct spi_device *spi_dev;drivers/staging/iio/adc/ad7314.c line 60
Quoted 10 lines
drivers/staging/iio/adc/ad7314.c new file +10
-0+struct iio_dev *indio_dev; +s64 last_timestamp; +u8 mode; +}; + +/* +* ad7314 register access by SPI +*/ + +static int ad7314_spi_read(struct ad7314_chip_info *chip,u16 *data)
Quoted 7 lines
drivers/staging/iio/adc/ad7314.c new file +7
-0+{ + struct spi_device *spi_dev =3D chip->spi_dev; + int ret =3D 0; +u16 value; + + ret =3D spi_read(spi_dev, (u8 *)&value, sizeof(value)); +if (ret <0 ) {drivers/staging/iio/adc/ad7314.c
Quoted 10 lines
drivers/staging/iio/adc/ad7314.c new file +10
-0+dev_err (&spi_dev->dev,"SPI read error\n" ); +return ret; + } + + *data =3D be16_to_cpu((u16)value); + +return ret; +} + +static int ad7314_spi_write(struct ad7314_chip_info *chip,u16 data)
Quoted 41 lines
drivers/staging/iio/adc/ad7314.c new file +41
-0+{ + struct spi_device *spi_dev =3D chip->spi_dev; + int ret =3D 0; + u16 value =3D cpu_to_be16(data); + + ret =3D spi_write(spi_dev, (u8 *)&value, sizeof(value)); +if (ret <0 ) +dev_err (&spi_dev->dev,"SPI write error\n" ); + +return ret; +} + +static ssize_t ad7314_show_mode (struct device *dev, +struct device_attribute *attr, +char *buf) +{ + struct iio_dev *dev_info =3D dev_get_drvdata(dev); + struct ad7314_chip_info *chip =3D dev_info->dev_data; + +if (chip->mode) +return sprintf (buf,"power-save\n" ); +else +return sprintf (buf,"full\n" ); +} + +static ssize_t ad7314_store_mode (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ + struct iio_dev *dev_info =3D dev_get_drvdata(dev); + struct ad7314_chip_info *chip =3D dev_info->dev_data; + u16 mode =3D 0; +int ret; + +if (!strcmp (buf,"full" )) + mode =3D AD7314_PD; + + ret =3D ad7314_spi_write(chip, mode); +if (ret) +return -EIO ;drivers/staging/iio/adc/ad7314.c line 129
Quoted 10 lines
drivers/staging/iio/adc/ad7314.c new file +10
-0+ + chip->mode =3D mode; + +return len; +} + +static IIO_DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, + ad7314_show_mode, + ad7314_store_mode, + 0);I'm still anti 'mode' attributes. They just don't generalize.
drivers/staging/iio/adc/ad7314.c line 135
Quoted 6 lines
drivers/staging/iio/adc/ad7314.c new file +6
-0+ +static ssize_t ad7314_show_available_modes (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return sprintf (buf,"full\npower-save\n" );Do this via
sampling_frequency(assuming that is what changes!)drivers/staging/iio/adc/ad7314.c
Quoted 4 lines
drivers/staging/iio/adc/ad7314.c new file +4
-0+} + +static IIO_DEVICE_ATTR(available_modes, S_IRUGO, +ad7314_show_available_modes, NULL, 0);
mode_availableplease.Quoted 5 lines
drivers/staging/iio/adc/ad7314.c new file +5
-0+ +static ssize_t ad7314_show_temperature (struct device *dev, +struct device_attribute *attr, +char *buf) +{drivers/staging/iio/adc/ad7314.c line 153
Quoted 10 lines
drivers/staging/iio/adc/ad7314.c new file +10
-0+ struct iio_dev *dev_info =3D dev_get_drvdata(dev); + struct ad7314_chip_info *chip =3D dev_info->dev_data; +u16 data; + char sign =3D ' '; +int ret; + +if (chip->mode) { + ret =3D ad7314_spi_write(chip, 0); +if (ret) +return -EIO ;Error eating.
Quoted 20 lines
drivers/staging/iio/adc/ad7314.c new file +20
-0+ } + + ret =3D ad7314_spi_read(chip, &data); +if (ret) +return -EIO ; + +if (chip->mode) +ad7314_spi_write (chip, chip->mode); + +if (strcmp (chip->name,"ad7314" )) { + data =3D (data &AD7314_TEMP_MASK ) >> +AD7314_TEMP_OFFSET ; +if (data &AD7314_TEMP_SIGN ) { + data =3D (AD7314_TEMP_SIGN <<1 ) - data; + sign =3D '-'; + } + +return sprintf (buf,"%c%d.%.2d\n" , sign, + data >>AD7314_TEMP_FLOAT_OFFSET , + (data &AD7314_TEMP_FLOAT_MASK ) *25 );drivers/staging/iio/adc/ad7314.c
Quoted 10 lines
drivers/staging/iio/adc/ad7314.c new file +10
-0+ }else { + data &=3D ADT7301_TEMP_MASK; +if (data &ADT7301_TEMP_SIGN ) { + data =3D (ADT7301_TEMP_SIGN <<1 ) - data; + sign =3D '-'; + } + + return sprintf(buf, "%c%d.%.5d\n", sign, + data >> ADT7301_TEMP_FLOAT_OFFSET, + (data &
ADT7301_TEMP_FLOAT_MASK) * 3125);drivers/staging/iio/adc/ad7314.c
Quoted 4 lines
drivers/staging/iio/adc/ad7314.c new file +4
-0+ } +} + +static IIO_DEVICE_ATTR(temperature, S_IRUGO,
ad7314_show_temperature,Quoted 6 lines
drivers/staging/iio/adc/ad7314.c new file +6
-0+NULL, 0); + +static ssize_t ad7314_show_name (struct device *dev, +struct device_attribute *attr, +char *buf) +{drivers/staging/iio/adc/ad7314.c line 203
Quoted 10 lines
drivers/staging/iio/adc/ad7314.c new file +10
-0+ struct iio_dev *dev_info =3D dev_get_drvdata(dev); + struct ad7314_chip_info *chip =3D dev_info->dev_data; +return sprintf (buf,"%s\n" , chip->name); } + +static IIO_DEVICE_ATTR(name, S_IRUGO, ad7314_show_name, NULL, 0); + +static struct attribute *ad7314_attributes[] =3D { + &iio_dev_attr_available_modes.dev_attr.attr, + &iio_dev_attr_mode.dev_attr.attr, + &iio_dev_attr_temperature.dev_attr.attr,
temp_inputplease (we match hwmon where possible).Quoted 88 lines
drivers/staging/iio/adc/ad7314.c new file +88
-0+ &iio_dev_attr_name.dev_attr.attr, + NULL, +}; + +static const struct attribute_group ad7314_attribute_group =3D { + .attrs =3D ad7314_attributes, +}; + +/* +* device probe and remove +*/ + +static int __devinit ad7314_probe (struct spi_device *spi_dev) { +struct ad7314_chip_info *chip; + int ret =3D 0; + + chip =3D kzalloc(sizeof(struct ad7314_chip_info), GFP_KERNEL); + + if (chip =3D=3D NULL) +return -ENOMEM ; + +/* this is only used for device removal purposes */ +dev_set_drvdata (&spi_dev->dev, chip); + + chip->spi_dev =3D spi_dev; + chip->name =3D spi_dev->modalias; + + chip->indio_dev =3D iio_allocate_device(); + if (chip->indio_dev =3D=3D NULL) { + ret =3D -ENOMEM ; + goto error_free_chip; + } + + chip->indio_dev->dev.parent =3D &spi_dev->dev; + chip->indio_dev->attrs =3D &ad7314_attribute_group; + chip->indio_dev->dev_data =3D (void *)chip; + chip->indio_dev->driver_module =3D THIS_MODULE; + + ret =3D iio_device_register(chip->indio_dev); +if (ret) + goto error_free_dev; + +dev_info (&spi_dev->dev,"%s temperature sensor registered.\n" , + chip->name); + +return 0 ; +error_free_dev: +iio_free_device (chip->indio_dev); +error_free_chip: +kfree (chip); + +return ret; +} + +static int __devexit ad7314_remove(struct spi_device *spi_dev) { + struct ad7314_chip_info *chip =3D dev_get_drvdata(&spi_dev->dev); + struct iio_dev *indio_dev =3D chip->indio_dev; + +dev_set_drvdata (&spi_dev->dev,NULL ); +if (spi_dev->irq) +iio_unregister_interrupt_line (indio_dev,0 ); +iio_device_unregister (indio_dev); +iio_free_device (chip->indio_dev); +kfree (chip); + +return 0 ; +} + +static const struct spi_device_id ad7314_id[] =3D { + {"adt7301" ,0 }, + {"adt7302" ,0 }, + {"ad7314" ,0 }, + {} +}; + +static struct spi_driver ad7314_driver =3D { + .driver =3D { + .name =3D "ad7314", + .bus =3D &spi_bus_type, + .owner =3D THIS_MODULE, + }, + .probe =3D ad7314_probe, + .remove =3D __devexit_p(ad7314_remove), + .id_table =3D ad7314_id, +}; + +static __init int ad7314_init (void ) +{drivers/staging/iio/adc/ad7314.c
Quoted 10 lines
drivers/staging/iio/adc/ad7314.c new file +10
-0+return spi_register_driver (&ad7314_driver); +} + +static __exit void ad7314_exit(void) +{ +spi_unregister_driver (&ad7314_driver); +} + +MODULE_AUTHOR ("Sonic Zhang <[email protected]>" ); +MODULE_DESCRIPTION("Analog Devices AD7314, ADT7301 andADT7302 digital"
Quoted 5 lines
drivers/staging/iio/adc/ad7314.c new file +5
-0+ " temperature sensor driver"); +MODULE_LICENSE ("GPL v2" ); + +module_init (ad7314_init); +module_exit (ad7314_exit);
PATCH 5/14 staging: iio: adc: new driver for AD7414/5 devices
In reply to Mike FrysingerFrom: Sonic Zhang <[email protected]>
--- drivers/staging/iio/adc/Kconfig | 7 + drivers/staging/iio/adc/Makefile | 1 + drivers/staging/iio/adc/ad7414.c | 573 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 581 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/iio/adc/ad7414.c
drivers/staging/iio/adc/Kconfig +7 -0
@@ -61,3 +61,10 @@ config AD7314 help Say yes here to build support for Analog Devices AD7314 temperature sensors. + +config AD7414 + tristate "Analog Devices AD7414 and AD7415 temperature sensor driver" + depends on I2C + help + Say yes here to build support for Analog Devices AD7414 and AD7415 + temperature sensors.
drivers/staging/iio/adc/Makefile +1 -0
@@ -11,3 +11,4 @@ obj-$(CONFIG_AD7152) += ad7152.o obj-$(CONFIG_AD7291) += ad7291.o obj-$(CONFIG_AD7298) += ad7298.o obj-$(CONFIG_AD7314) += ad7314.o +obj-$(CONFIG_AD7414) += ad7414.o
drivers/staging/iio/adc/ad7414.c new file +573 -0
573 lines not on this page · raw message
Signature · 1 line
1.7.3.2
Re: [PATCH 05/14] staging: iio: adc: new driver for AD7414/5 devices
Quoted 2 lines · Mike Frysinger
From: Sonic Zhang <[email protected]>
Why IIO and not hwmon? Needs justification.
Guessing it's for the alarm elements?
Limited review follows.
Some abi breakage that needs fixing. This one falls entirely in areas we have covered. It's also not an adc, so should probably be in a different directory if it does go in iio
Quoted 2 lines
Signed-off-by Sonic Zhang <[email protected]>Signed-off-by Mike Frysinger <[email protected]>
Quoted 404 lines
--- drivers/staging/iio/adc/Kconfig | 7 + drivers/staging/iio/adc/Makefile | 1 + drivers/staging/iio/adc/ad7414.c | 573 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 581 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/iio/adc/ad7414.cdrivers/staging/iio/adc/Kconfig +7
-0@@ -61,3 +61,10 @@ config AD7314 help Say yes here to build support for Analog Devices AD7314 temperature sensors. + +config AD7414 + tristate "Analog Devices AD7414 and AD7415 temperature sensor driver" + depends on I2C + help + Say yes here to build support for Analog Devices AD7414 and AD7415 + temperature sensors.drivers/staging/iio/adc/Makefile +1
-0@@ -11,3 +11,4 @@ obj-$(CONFIG_AD7152) += ad7152.o obj-$(CONFIG_AD7291) += ad7291.o obj-$(CONFIG_AD7298) += ad7298.o obj-$(CONFIG_AD7314) += ad7314.o +obj-$(CONFIG_AD7414) += ad7414.odrivers/staging/iio/adc/ad7414.c new file +367
-0@@ -0,0 +1,573 @@ +/* +* AD7414 digital temperature sensor driver supporting AD7414 and AD7415 +* +* Copyright 2010 Analog Devices Inc. +* +* Licensed under the GPL-2 or later. +*/ + +#include <linux/interrupt.h> +#include <linux/gpio.h> +#include <linux/workqueue.h> +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/sysfs.h> +#include <linux/list.h> +#include <linux/i2c.h> +#include <linux/rtc.h> + +#include "../iio.h" +#include "../sysfs.h" + +/* +* AD7414 registers definition +*/ + +#define AD7414_TEMPERATURE 0 +#define AD7414_CONFIG 1 +#define AD7414_TEMPERATURE_HIGH 2 +#define AD7414_TEMPERATURE_LOW 3 + +/* +* AD7414 config bits +*/ +#define AD7414_TEST_MODE 0x3 +#define AD7414_ONE_SHOT 0x4 +#define AD7414_ALERT_RESET 0x8 +#define AD7414_ALERT_POLARITY 0x10 +#define AD7414_ALERT_EN 0x20 +#define AD7414_FLTR 0x40 +#define AD7414_PD 0x80 + +/* +* AD7414 masks +*/ +#define AD7414_TEMP_SIGN 0x200 +#define AD7414_TEMP_MASK 0xFFC0 +#define AD7414_TEMP_OFFSET 6 +#define AD7414_ALERT_FLAG 0x20 +#define AD7414_T_SIGN 0x80 +#define AD7414_T_HIGH_FLAG 0x10 +#define AD7414_T_LOW_FLAG 0x8 + + +/* +* struct ad7414_chip_info - chip specifc information +*/ + +struct ad7414_chip_info { +const char *name; +struct i2c_client *client; +struct iio_dev *indio_dev; +struct work_struct thresh_work; +s64 last_timestamp; +u8 mode; +}; + +/* +* ad7414 register access by I2C +*/ + +static int ad7414_i2c_read (struct ad7414_chip_info *chip,u8 reg,u8 *data) +{ +struct i2c_client *client = chip->client; +int ret =0 , len; + + ret =i2c_smbus_write_byte (client, reg); +if (ret <0 ) { +dev_err (&client->dev,"I2C read register address error\n" ); +return ret; + } + +if (reg ==AD7414_TEMPERATURE ) + len =2 ; +else + len =1 ; + + ret =i2c_master_recv (client, data, len); +if (ret <0 ) { +dev_err (&client->dev,"I2C read error\n" ); +return ret; + } + +return ret; +} + +static int ad7414_i2c_write (struct ad7414_chip_info *chip,u8 reg,u8 data) +{ +struct i2c_client *client = chip->client; +int ret =0 ; + + ret =i2c_smbus_write_byte_data (client, reg, data); +if (ret <0 ) +dev_err (&client->dev,"I2C write error\n" ); + +return ret; +} + +static ssize_t ad7414_show_mode (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7414_chip_info *chip = dev_info->dev_data; + +if (chip->mode) +return sprintf (buf,"power-save\n" ); +else +return sprintf (buf,"full\n" ); +} + +static ssize_t ad7414_store_mode (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7414_chip_info *chip = dev_info->dev_data; +u8 config; +int ret; + + ret =ad7414_i2c_read (chip,AD7414_CONFIG , &config); +if (ret) +return -EIO ; + +if (strcmp (buf,"full" )) { + chip->mode =0 ; + config &= ~AD7414_PD ; + }else { + chip->mode =1 ; + config |=AD7414_PD ; + } + + ret =ad7414_i2c_write (chip,AD7414_CONFIG , config); +if (ret) +return -EIO ; + +return ret; +} + +static IIO_DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, + ad7414_show_mode, + ad7414_store_mode, + 0); + +static ssize_t ad7414_show_available_modes (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return sprintf (buf,"full\npower-save\n" ); +} + +static IIO_DEVICE_ATTR(available_modes, S_IRUGO, ad7414_show_available_modes, NULL, 0); + +static ssize_t ad7414_show_temperature (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7414_chip_info *chip = dev_info->dev_data; +u8 config; +u16 data; +char sign =' ' ; +int ret; + +if (chip->mode) { + ret =ad7414_i2c_read (chip,AD7414_CONFIG , &config); +if (ret) +return -EIO ; + ret =ad7414_i2c_write (chip,AD7414_CONFIG , + config |AD7414_ONE_SHOT ); +if (ret) +return -EIO ; + } + + ret =ad7414_i2c_read (chip,AD7414_TEMPERATURE , (u8 *)&data); +if (ret) +return -EIO ; + + data =swab16 (data) >>AD7414_TEMP_OFFSET ; +if (data &AD7414_TEMP_SIGN ) { + data = (AD7414_TEMP_SIGN <<1 ) - data; + sign ='-' ; + } + +return sprintf (buf,"%c%d.%.2d\n" , sign, (data >>2 ), (data &3 ) *25 ); +} + +static IIO_DEVICE_ATTR(temperature, S_IRUGO, ad7414_show_temperature, NULL, 0); + +static ssize_t ad7414_show_name (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7414_chip_info *chip = dev_info->dev_data; +return sprintf (buf,"%s\n" , chip->name); +} + +static IIO_DEVICE_ATTR(name, S_IRUGO, ad7414_show_name, NULL, 0); + +static struct attribute *ad7414_attributes[] = { + &iio_dev_attr_available_modes.dev_attr.attr, + &iio_dev_attr_mode.dev_attr.attr, + &iio_dev_attr_temperature.dev_attr.attr, + &iio_dev_attr_name.dev_attr.attr, +NULL , +}; + +static const struct attribute_group ad7414_attribute_group = { + .attrs = ad7414_attributes, +}; + +/* +* temperature bound events +*/ + +#define IIO_EVENT_CODE_AD7414_T_HIGH (IIO_EVENT_CODE_DEVICE_SPECIFIC + 1) +#define IIO_EVENT_CODE_AD7414_T_LOW (IIO_EVENT_CODE_DEVICE_SPECIFIC + 2) + +static void ad7414_interrupt_bh (struct work_struct *work_s) +{ +struct ad7414_chip_info *chip = + container_of(work_s, struct ad7414_chip_info, thresh_work); +u16 status; +u8 config; +int ret; + +/* retrive ALART status */ + ret =ad7414_i2c_read (chip,AD7414_TEMPERATURE , (u8 *)&status); +if (ret) +return ; + status =swab16 (status); + +/* clear ALART pin in chip configuration register */ + ret =ad7414_i2c_read (chip,AD7414_CONFIG , &config); +if (ret) +return ; + ret =ad7414_i2c_write (chip,AD7414_CONFIG , + config |AD7414_ALERT_RESET ); +if (ret) +return ; + +enable_irq (chip->client->irq); + +if (status &AD7414_T_HIGH_FLAG ) +iio_push_event (chip->indio_dev,0 , +IIO_EVENT_CODE_AD7414_T_HIGH , + chip->last_timestamp); +else if (status &AD7414_T_LOW_FLAG ) +iio_push_event (chip->indio_dev,0 , +IIO_EVENT_CODE_AD7414_T_LOW , + chip->last_timestamp); +} + +static int ad7414_interrupt (struct iio_dev *dev_info, +int index, +s64 timestamp, +int no_test) +{ +struct ad7414_chip_info *chip = dev_info->dev_data; + + chip->last_timestamp = timestamp; +schedule_work (&chip->thresh_work); + +return 0 ; +} + +IIO_EVENT_SH (ad7414, &ad7414_interrupt); + +static ssize_t ad7414_show_enabled (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7414_chip_info *chip = dev_info->dev_data; +u8 config; +int ret; + +/* retrive ALART status */ + ret =ad7414_i2c_read (chip,AD7414_CONFIG , &config); +if (ret) +return -EIO ; + +return sprintf (buf,"%d\n" , !!(config &AD7414_ALERT_EN )); +} + +static ssize_t ad7414_set_enabled (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7414_chip_info *chip = dev_info->dev_data; +unsigned long data; +u8 config; +int ret; + + ret =strict_strtoul (buf,10 , &data); +if (ret) +return -EINVAL ; + +/* retrive ALART status */ + ret =ad7414_i2c_read (chip,AD7414_CONFIG , &config); +if (ret) +return -EIO ; + +if (data) + ret =ad7414_i2c_write (chip,AD7414_CONFIG , + config & ~AD7414_ALERT_EN ); +else + ret =ad7414_i2c_write (chip,AD7414_CONFIG , + config |AD7414_ALERT_EN ); +if (ret) +return -EIO ; + +return ret; +} + +static inline ssize_t ad7414_show_temperature_bound (struct device *dev, +struct device_attribute *attr, +u8 bound_reg, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7414_chip_info *chip = dev_info->dev_data; +s8 data; +int ret; + + ret =ad7414_i2c_read (chip, bound_reg, &data); +if (ret) +return -EIO ; + +if (data &AD7414_T_SIGN ) + data = (data&(~AD7414_T_SIGN )) -AD7414_T_SIGN ; + +return sprintf (buf,"%d\n" , data); +} + +static inline ssize_t ad7414_set_temperature_bound (struct device *dev, +struct device_attribute *attr, +u8 bound_reg, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7414_chip_info *chip = dev_info->dev_data; +long data; +s8 value; +int ret; + + ret =strict_strtol (buf,10 , &data); + +if (ret || data >127 || data <-128 ) +return -EINVAL ; + + value = (s8 )data;
drivers/staging/iio/adc/ad7414.c line 377
Quoted 10 lines
drivers/staging/iio/adc/ad7414.c new file +10
-0+if (value <0 ) + value = (AD7414_T_SIGN + value) |AD7414_T_SIGN ; + + ret =ad7414_i2c_write (chip, bound_reg, value); +if (ret) +return -EIO ; + +return ret; +} +
I think all these could be merged.
Quoted 26 lines
drivers/staging/iio/adc/ad7414.c new file +26
-0+static ssize_t ad7414_show_temperature_high (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return ad7414_show_temperature_bound (dev, attr, +AD7414_TEMPERATURE_HIGH , buf); +} + +static inline ssize_t ad7414_set_temperature_high (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +return ad7414_set_temperature_bound (dev, attr, +AD7414_TEMPERATURE_HIGH , buf, len); +} + +static ssize_t ad7414_show_temperature_low (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return ad7414_show_temperature_bound (dev, attr, +AD7414_TEMPERATURE_LOW , buf); +} + +static inline ssize_t ad7414_set_temperature_low(struct device *dev,
drivers/staging/iio/adc/ad7414.c line 413
Quoted 10 lines
drivers/staging/iio/adc/ad7414.c new file +10
-0+struct device_attribute *attr, + const char *buf, + size_t len) +{ + return ad7414_set_temperature_bound(dev, attr, +AD7414_TEMPERATURE_LOW ,buf ,len ); +} + +IIO_EVENT_ATTR_SH (t_bound_enabled, iio_event_ad7414, + ad7414_show_enabled, ad7414_set_enabled,0 );
Sorry, Sonic. Same issue here. Use normal device_attrs unless they are the enable / disable attributes.
drivers/staging/iio/adc/ad7414.c line 419
Quoted 6 lines
drivers/staging/iio/adc/ad7414.c new file +6
-0+IIO_EVENT_ATTR_SH (temperature_high, iio_event_ad7414, + ad7414_show_temperature_high, ad7414_set_temperature_high,0 ); +IIO_EVENT_ATTR_SH (temperature_low, iio_event_ad7414, + ad7414_show_temperature_low, ad7414_set_temperature_low,0 ); + +static struct attribute *ad7414_event_attributes[] = {
non abi compiant.
probably:
drivers/staging/iio/adc/ad7414.c line 420
Quoted 1 line
drivers/staging/iio/adc/ad7414.c new file +1
-0+ &iio_event_attr_t_bound_enabled.dev_attr.attr,
iio_event_attr_temp_thresh_en
drivers/staging/iio/adc/ad7414.c line 421
Quoted 1 line
drivers/staging/iio/adc/ad7414.c new file +1
-0+ &iio_event_attr_temperature_high.dev_attr.attr,
iio_device_attr_temp_thresh_rising_value
drivers/staging/iio/adc/ad7414.c line 422
Quoted 1 line
drivers/staging/iio/adc/ad7414.c new file +1
-0+ &iio_event_attr_temperature_low.dev_attr.attr,
iio_device_attr_temp_thresh_falling_value.
Quoted 151 lines
drivers/staging/iio/adc/ad7414.c new file +151
-0+ NULL, +}; + +static struct attribute_group ad7414_event_attribute_group = { + .attrs = ad7414_event_attributes, +}; + +/* +* device probe and remove +*/ + +static int __devinit ad7414_probe (struct i2c_client *client, +const struct i2c_device_id *id) +{ +struct ad7414_chip_info *chip; +int ret =0 ; +u8 config; + + chip =kzalloc (sizeof (struct ad7414_chip_info ),GFP_KERNEL ); + +if (chip ==NULL ) +return -ENOMEM ; + +/* this is only used for device removal purposes */ +i2c_set_clientdata (client, chip); + + chip->client = client; + chip->name = id->name; + + chip->indio_dev =iio_allocate_device (); +if (chip->indio_dev ==NULL ) { + ret = -ENOMEM ; + goto error_free_chip; + } + + chip->indio_dev->dev.parent = &client->dev; + chip->indio_dev->attrs = &ad7414_attribute_group; +if (strcmp (id->name,"ad7414" ) ==0 ) + chip->indio_dev->event_attrs = &ad7414_event_attribute_group; +else + client->irq =0 ; + chip->indio_dev->dev_data = (void *)chip; + chip->indio_dev->driver_module =THIS_MODULE ; + chip->indio_dev->num_interrupt_lines =1 ; + chip->indio_dev->modes =INDIO_DIRECT_MODE ; + + ret =iio_device_register (chip->indio_dev); +if (ret) + goto error_free_dev; + +if (client->irq) { + ret =iio_register_interrupt_line (client->irq, + chip->indio_dev, +0 , + client->irq_flags, + chip->name); +if (ret) + goto error_unreg_dev; + +/* +* The event handler list element refer to iio_event_ad7414. +* All event attributes bind to the same event handler. +* So, only register event handler once. +*/ +iio_add_event_to_list (&iio_event_ad7414, + &chip->indio_dev->interrupts[0 ]->ev_list); + +INIT_WORK (&chip->thresh_work, ad7414_interrupt_bh); + + ret =ad7414_i2c_read (chip,AD7414_CONFIG , &config); +if (ret) { + ret = -EIO ; + goto error_unreg_irq; + } + +if (client->irq_flags &IRQF_TRIGGER_HIGH ) + ret =ad7414_i2c_write (chip,AD7414_CONFIG , + config |AD7414_ALERT_POLARITY ); +else + ret =ad7414_i2c_write (chip,AD7414_CONFIG , + config & ~AD7414_ALERT_POLARITY ); +if (ret) { + ret = -EIO ; + goto error_unreg_irq; + } + } + +dev_info (&client->dev,"%s temperature sensor registered.\n" , + id->name); + +return 0 ; +error_unreg_irq: +iio_unregister_interrupt_line (chip->indio_dev,0 ); +error_unreg_dev: +iio_device_unregister (chip->indio_dev); +error_free_dev: +iio_free_device (chip->indio_dev); +error_free_chip: +kfree (chip); + +return ret; +} + +static int __devexit ad7414_remove(struct i2c_client *client) +{ +struct ad7414_chip_info *chip =i2c_get_clientdata (client); +struct iio_dev *indio_dev = chip->indio_dev; + +if (client->irq) +iio_unregister_interrupt_line (indio_dev,0 ); +iio_device_unregister (indio_dev); +iio_free_device (chip->indio_dev); +kfree (chip); + +return 0 ; +} + +static const struct i2c_device_id ad7414_id[] = { + {"ad7414" ,0 }, + {"ad7415" ,0 }, + {} +}; + +MODULE_DEVICE_TABLE (i2c, ad7414_id); + +static struct i2c_driver ad7414_driver = { + .driver = { + .name ="ad7414" , + }, + .probe = ad7414_probe, + .remove =__devexit_p (ad7414_remove), + .id_table = ad7414_id, +}; + +static __init int ad7414_init (void ) +{ +return i2c_add_driver (&ad7414_driver); +} + +static __exit void ad7414_exit(void) +{ +i2c_del_driver (&ad7414_driver); +} + +MODULE_AUTHOR ("Sonic Zhang <[email protected]>" ); +MODULE_DESCRIPTION ("Analog Devices AD7414 and AD7415 digital" +" temperature sensor driver" ); +MODULE_LICENSE ("GPL v2" ); + +module_init (ad7414_init); +module_exit (ad7414_exit);
PATCH 6/14 staging: iio: adc: new driver for AD7416/7/8 devices
In reply to Mike FrysingerFrom: Sonic Zhang <[email protected]>
--- drivers/staging/iio/adc/Kconfig | 7 + drivers/staging/iio/adc/Makefile | 1 + drivers/staging/iio/adc/ad7416.c | 777 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 785 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/iio/adc/ad7416.c
drivers/staging/iio/adc/Kconfig +7 -0
@@ -68,3 +68,10 @@ config AD7414 help Say yes here to build support for Analog Devices AD7414 and AD7415 temperature sensors. + +config AD7416 + tristate "Analog Devices AD7416/7/8 temperature sensor and ADC driver" + depends on I2C + help + Say yes here to build support for Analog Devices AD74167/8 + temperature sensors and ADC.
drivers/staging/iio/adc/Makefile +1 -0
@@ -12,3 +12,4 @@ obj-$(CONFIG_AD7291) += ad7291.o obj-$(CONFIG_AD7298) += ad7298.o obj-$(CONFIG_AD7314) += ad7314.o obj-$(CONFIG_AD7414) += ad7414.o +obj-$(CONFIG_AD7416) += ad7416.o
drivers/staging/iio/adc/ad7416.c new file +777 -0
777 lines not on this page · raw message
Signature · 1 line
1.7.3.2
Re: [PATCH 06/14] staging: iio: adc: new driver for AD7416/7/8 devices
Quoted 1 line · Mike Frysinger
From: Sonic Zhang <[email protected]>
Again, presence in IIO needs justifying comment.
(here for the events infrastructure I guess?)
Fair bit of abi breakage in this one. New elements too that will need discussion.
Quite a few nitpicks including some that correspond directly to the other drivers and might not be commented on here.
Don't abrieviate naming too far. Sometimes long attribute names are useful.
Lots to fix in here, but if it builds send it on to Greg.
Quoted 3 lines
Signed-off-by Sonic Zhang <[email protected]>Signed-off-by Mike Frysinger <[email protected]>
Quoted 12 lines
--- drivers/staging/iio/adc/Kconfig | 7 + drivers/staging/iio/adc/Makefile | 1 + drivers/staging/iio/adc/ad7416.c | 777 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 785 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/iio/adc/ad7416.cdrivers/staging/iio/adc/Kconfig +0
-0
drivers/staging/iio/adc/Kconfig config AD7414 · line 76
Quoted 9 lines
drivers/staging/iio/adc/Kconfig +6
-0@@ -68,3 +68,10 @@ config AD7414 help Say yes here to build support for Analog Devices AD7414 and AD7415 temperature sensors. + +config AD7416 + tristate "Analog Devices AD7416/7/8 temperature sensor and ADC driver" + depends on I2C + help + Say yes here to build support for Analog Devices AD74167/8
full names in the help text for easy grepping please.
Quoted 100 lines
drivers/staging/iio/adc/Kconfig +1
-0+ temperature sensors and ADC.drivers/staging/iio/adc/Makefile +1
-0@@ -12,3 +12,4 @@ obj-$(CONFIG_AD7291) += ad7291.o obj-$(CONFIG_AD7298) += ad7298.o obj-$(CONFIG_AD7314) += ad7314.o obj-$(CONFIG_AD7414) += ad7414.o +obj-$(CONFIG_AD7416) += ad7416.odrivers/staging/iio/adc/ad7416.c new file +84
-0@@ -0,0 +1,777 @@ +/* +* AD7416 digital temperature sensor driver supporting AD7416/7/8 +* +* Copyright 2010 Analog Devices Inc. +* +* Licensed under the GPL-2 or later. +*/ + +#include <linux/interrupt.h> +#include <linux/gpio.h> +#include <linux/workqueue.h> +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/sysfs.h> +#include <linux/list.h> +#include <linux/i2c.h> +#include <linux/rtc.h> + +#include "../iio.h" +#include "../sysfs.h" + +/* +* AD7416 registers definition +*/ +#define AD7416_TEMPERATURE 0 +#define AD7416_CONFIG 1 +#define AD7416_T_OTI 2 +#define AD7416_T_HYST 3 +#define AD7416_ADC_VALUE 4 +#define AD7416_CONFIG2 5 + +/* +* AD7416 config +*/ +#define AD7416_PD 0x1 +#define AD7416_OTI_INT 0x2 +#define AD7416_OTI_POLARITY 0x4 +#define AD7416_FAULT_QUEUE_MASK 0x18 +#define AD7416_FAULT_QUEUE_OFFSET 3 +#define AD7416_CS_MASK 0xE0 +#define AD7416_CS_OFFSET 5 + +/* +* AD7416 config +*/ +#define AD7416_CONVERT 0x80 + +/* +* AD7416 mode +*/ +#define AD7416_MODE_FULL 0 +#define AD7416_MODE_SHUTDOWN 1 +#define AD7416_MODE_CONVERT 2 + +/* +* AD7416/7/8 channel maks +*/ +#define AD7416_CHANNEL_MASK 0x1 +#define AD7417_CHANNEL_MASK 0x1F +#define AD7418_CHANNEL_MASK 0x11 + +/* +* AD7416 masks +*/ +#define AD7416_VALUE_SIGN 0x200 +#define AD7416_VALUE_OFFSET 6 +#define AD7416_BOUND_VALUE_SIGN 0x100 + + +/* +* struct ad7416_chip_info - chip specifc information +*/ + +struct ad7416_chip_info { +const char *name; +struct i2c_client *client; +struct iio_dev *indio_dev; +struct work_struct thresh_work; +s64 last_timestamp; +u16 convert_pin; +u8 mode; +u8 channel_id;/* 0 always be temperature */ +u8 channel_mask;
drivers/staging/iio/adc/ad7416.c line 94
Quoted 10 lines
drivers/staging/iio/adc/ad7416.c new file +10
-0+}; + +/* +* ad7416 register access by I2C +*/ + +static int ad7416_i2c_read (struct ad7416_chip_info *chip,u8 reg,u8 *data) +{ +struct i2c_client *client = chip->client; +int ret =0 , len;
no need to init ret;
Quoted 15 lines
drivers/staging/iio/adc/ad7416.c new file +15
-0+ + ret =i2c_smbus_write_byte (client, reg); +if (ret <0 ) { +dev_err (&client->dev,"I2C read register address error\n" ); +return ret; + } + +if (reg ==AD7416_CONFIG || reg ==AD7416_CONFIG2 ) + len =1 ; +else + len =2 ; + + ret =i2c_master_recv (client, data, len); +if (ret <0 ) { +dev_err (&client->dev,"I2C read error\n" );
drivers/staging/iio/adc/ad7416.c line 119
Quoted 10 lines
drivers/staging/iio/adc/ad7416.c new file +10
-0+return ret; + } + +return ret; +} + +static int ad7416_i2c_write (struct ad7416_chip_info *chip,u8 reg,u8 data) +{ +struct i2c_client *client = chip->client; +int ret =0 ;
no need to init ret.
drivers/staging/iio/adc/ad7416.c line 127
Quoted 8 lines
drivers/staging/iio/adc/ad7416.c new file +8
-0+ + ret =i2c_smbus_write_byte_data (client, reg, data); +if (ret <0 ) +dev_err (&client->dev,"I2C write error\n" ); + +return ret; +} +
Should be moved to an automated mode setting based on what the chip is currently doing.
Quoted 19 lines
drivers/staging/iio/adc/ad7416.c new file +19
-0+static ssize_t ad7416_show_mode (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7416_chip_info *chip = dev_info->dev_data; + +switch (chip->mode) { +case AD7416_MODE_SHUTDOWN : +return sprintf (buf,"power-save\n" ); +case AD7416_MODE_CONVERT : +return sprintf (buf,"convert\n" ); +default : +return sprintf (buf,"full\n" ); + } +} + +static ssize_t ad7416_store_mode(struct device *dev, + struct device_attribute *attr,
drivers/staging/iio/adc/ad7416.c line 156
Quoted 10 lines
drivers/staging/iio/adc/ad7416.c new file +10
-0+ const char *buf, + size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7416_chip_info *chip = dev_info->dev_data; +u8 config, config2; +int ret; + + ret =ad7416_i2c_read (chip,AD7416_CONFIG , &config); +if (ret)
error eating.
drivers/staging/iio/adc/ad7416.c line 163
Quoted 7 lines
drivers/staging/iio/adc/ad7416.c new file +7
-0+return -EIO ; + + ret =ad7416_i2c_read (chip,AD7416_CONFIG2 , &config2); +if (ret) +return -EIO ; + +if (strcmp (buf,"full" )) {
sysfs_strcmp
Quoted 5 lines
drivers/staging/iio/adc/ad7416.c new file +5
-0+ config2 &= ~AD7416_CONVERT ; + config &= ~AD7416_PD ; + + ret =ad7416_i2c_write (chip,AD7416_CONFIG , config); +if (ret)
drivers/staging/iio/adc/ad7416.c line 178
Quoted 10 lines
drivers/staging/iio/adc/ad7416.c new file +10
-0+return -EIO ; + +if (chip->mode ==AD7416_MODE_CONVERT ) { + ret =ad7416_i2c_write (chip,AD7416_CONFIG2 , config2); +if (ret) +return -EIO ; + } + + chip->mode =AD7416_MODE_FULL ; + }else if (chip->convert_pin &&strcmp (buf,"convert" )) {
sysfs_strcmp
Quoted 31 lines
drivers/staging/iio/adc/ad7416.c new file +31
-0+ config2 |=AD7416_CONVERT ; + + ret =ad7416_i2c_write (chip,AD7416_CONFIG2 , config2); +if (ret) +return -EIO ; + + chip->mode =AD7416_MODE_CONVERT ; + }else { + config |=AD7416_PD ; + config2 &= ~AD7416_CONVERT ; + + ret =ad7416_i2c_write (chip,AD7416_CONFIG , config); +if (ret) +return -EIO ; + +if (chip->mode ==AD7416_MODE_CONVERT ) { + ret =ad7416_i2c_write (chip,AD7416_CONFIG2 , config2); +if (ret) +return -EIO ; + } + + chip->mode =AD7416_MODE_SHUTDOWN ; + } + +return ret; +} + +static IIO_DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, + ad7416_show_mode, + ad7416_store_mode, + 0);
drivers/staging/iio/adc/ad7416.c line 219
Quoted 10 lines
drivers/staging/iio/adc/ad7416.c new file +10
-0+ +static ssize_t ad7416_show_available_modes (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7416_chip_info *chip = dev_info->dev_data; + +if (chip->convert_pin) +return sprintf (buf,"full\npower-save\nconvert\n" );
space separated please. Guessing convert is based on a trigger? Not entirely sure how we should handle that...
Quoted 43 lines
drivers/staging/iio/adc/ad7416.c new file +43
-0+else +return sprintf (buf,"full\npower-save\n" ); +} + +static IIO_DEVICE_ATTR(available_modes, S_IRUGO, ad7416_show_available_modes, NULL, 0); + +static ssize_t ad7416_show_channel (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7416_chip_info *chip = dev_info->dev_data; + +return sprintf (buf,"%d\n" , chip->channel_id); +} + +static ssize_t ad7416_store_channel (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7416_chip_info *chip = dev_info->dev_data; +unsigned long data; +u8 channel_mask; +u8 config; +int ret; + + ret =strict_strtoul (buf,10 , &data); +if (ret) +return -EINVAL ; + + channel_mask =1 << data; +if (!(channel_mask & chip->channel_mask)) { +dev_err (&chip->client->dev,"Invalid channel id %lu.\n" , data); +dev_err (&chip->client->dev,"Available channel mask 0x%x.\n" , + chip->channel_mask); +return -EINVAL ; + }else if (data == chip->channel_id) +return ret; + + ret =ad7416_i2c_read (chip,AD7416_CONFIG , &config); +if (ret)
drivers/staging/iio/adc/ad7416.c line 272
Quoted 10 lines
drivers/staging/iio/adc/ad7416.c new file +10
-0+return -EIO ; + + config |= ((data <<AD7416_CS_OFFSET ) &&AD7416_CS_MASK ); + ret =ad7416_i2c_write (chip,AD7416_CONFIG , config); +if (ret) +return -EIO ; + +return ret; +} +
Channels should be seperately handled or if a 'scan' is desired it should be done via the buffer interface.
Quoted 7 lines
drivers/staging/iio/adc/ad7416.c new file +7
-0+static IIO_DEVICE_ATTR(channel, S_IRUGO | S_IWUSR, + ad7416_show_channel, + ad7416_store_channel, + 0); + + +static ssize_t ad7416_show_value(struct device *dev,
drivers/staging/iio/adc/ad7416.c line 289
Quoted 10 lines
drivers/staging/iio/adc/ad7416.c new file +10
-0+struct device_attribute *attr, + char *buf) +{ + struct iio_dev *dev_info = dev_get_drvdata(dev); +struct ad7416_chip_info *chip = dev_info->dev_data; +u16 data; +char sign =' ' ; +int ret; + +if (chip->mode ==AD7416_MODE_SHUTDOWN ) {
probably wants to be runtime pm.
Quoted 26 lines
drivers/staging/iio/adc/ad7416.c new file +26
-0+/* write to active converter */ + ret =i2c_smbus_write_byte (chip->client,AD7416_TEMPERATURE ); +if (ret) +return -EIO ; + }else if (chip->mode ==AD7416_MODE_CONVERT ) { +gpio_set_value (chip->convert_pin,1 ); +gpio_set_value (chip->convert_pin,0 ); + } + +if (chip->channel_id ==0 ) { + ret =ad7416_i2c_read (chip,AD7416_TEMPERATURE , (u8 *)&data); +if (ret) +return -EIO ; + + data =swab16 (data); + data >>=AD7416_VALUE_OFFSET ; +if (data &AD7416_VALUE_SIGN ) { + data = (AD7416_VALUE_SIGN <<1 ) - data; + sign ='-' ; + } + +return sprintf (buf,"%c%d.%.2d\n" , sign, (data >>2 ), + (data &3 ) *25 ); + }else { + ret =ad7416_i2c_read (chip,AD7416_ADC_VALUE , (u8 *)&data); +if (ret)
drivers/staging/iio/adc/ad7416.c line 325
Quoted 10 lines
drivers/staging/iio/adc/ad7416.c new file +10
-0+return -EIO ; + + data =swab16 (data); + data >>=AD7416_VALUE_OFFSET ; + +return sprintf (buf,"%u\n" , data); + } +} + +static IIO_DEVICE_ATTR(value, S_IRUGO, ad7416_show_value, NULL, 0);
should be broken out set of attributes, one per channel.
Quoted 20 lines
drivers/staging/iio/adc/ad7416.c new file +20
-0+ +static ssize_t ad7416_show_name (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7416_chip_info *chip = dev_info->dev_data; +return sprintf (buf,"%s\n" , chip->name); +} + +static IIO_DEVICE_ATTR(name, S_IRUGO, ad7416_show_name, NULL, 0); + +static struct attribute *ad7416_attributes[] = { + &iio_dev_attr_available_modes.dev_attr.attr, + &iio_dev_attr_mode.dev_attr.attr, + &iio_dev_attr_channel.dev_attr.attr, + &iio_dev_attr_value.dev_attr.attr, + &iio_dev_attr_name.dev_attr.attr, +NULL , +};
drivers/staging/iio/adc/ad7416.c line 355
Quoted 10 lines
drivers/staging/iio/adc/ad7416.c new file +10
-0+ +static const struct attribute_group ad7416_attribute_group = { + .attrs = ad7416_attributes, +}; + +/* +* temperature bound events +*/ + +#define IIO_EVENT_CODE_AD7416_OTI (IIO_EVENT_CODE_DEVICE_SPECIFIC + 1)
Needs to be a general form. Not sure what it is here though!
Quoted 17 lines
drivers/staging/iio/adc/ad7416.c new file +17
-0+ +static void ad7416_interrupt_bh (struct work_struct *work_s) +{ +struct ad7416_chip_info *chip = + container_of(work_s, struct ad7416_chip_info, thresh_work); + +enable_irq (chip->client->irq); + +iio_push_event (chip->indio_dev,0 , +IIO_EVENT_CODE_AD7416_OTI , + chip->last_timestamp); +} + +static int ad7416_interrupt (struct iio_dev *dev_info, +int index, +s64 timestamp, +int no_test)
drivers/staging/iio/adc/ad7416.c line 382
Quoted 10 lines
drivers/staging/iio/adc/ad7416.c new file +10
-0+{ +struct ad7416_chip_info *chip = dev_info->dev_data; + + chip->last_timestamp = timestamp; +schedule_work (&chip->thresh_work); + +return 0 ; +} + +IIO_EVENT_SH (ad7416, &ad7416_interrupt);
There only seems to be one type of event, so it shouldn't need the shared form of this.
Quoted 6 lines
drivers/staging/iio/adc/ad7416.c new file +6
-0+ +static ssize_t ad7416_show_oti_mode (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev);
drivers/staging/iio/adc/ad7416.c line 398
Quoted 10 lines
drivers/staging/iio/adc/ad7416.c new file +10
-0+struct ad7416_chip_info *chip = dev_info->dev_data; +u8 config; +int ret; + +/* retrive ALART status */ + ret =ad7416_i2c_read (chip,AD7416_CONFIG , &config); +if (ret) +return -EIO ; + +if (config &AD7416_OTI_INT )
This looks 'interesting'... Please document this. I would imagine the interface will need discussion.
Quoted 6 lines
drivers/staging/iio/adc/ad7416.c new file +6
-0+return sprintf (buf,"interrupt\n" ); + else + return sprintf(buf, "comparator\n"); +} + +static ssize_t ad7416_set_oti_mode(struct device *dev,
drivers/staging/iio/adc/ad7416.c line 414
Quoted 10 lines
drivers/staging/iio/adc/ad7416.c new file +10
-0+struct device_attribute *attr, + const char *buf, + size_t len) +{ + struct iio_dev *dev_info = dev_get_drvdata(dev); +struct ad7416_chip_info *chip = dev_info->dev_data; +u8 config; +int ret; + +/* retrive ALART status */
alert.
drivers/staging/iio/adc/ad7416.c line 416
Quoted 2 lines
drivers/staging/iio/adc/ad7416.c new file +2
-0+ ret =ad7416_i2c_read (chip,AD7416_CONFIG , &config); +if (ret)
error eating.
Quoted 8 lines
drivers/staging/iio/adc/ad7416.c new file +8
-0+return -EIO ; + +if (strcmp (buf,"comparator" ) ==0 ) + ret =ad7416_i2c_write (chip,AD7416_CONFIG , + config & ~AD7416_OTI_INT ); +else + ret =ad7416_i2c_write (chip,AD7416_CONFIG , + config |AD7416_OTI_INT );
drivers/staging/iio/adc/ad7416.c line 434
Quoted 10 lines
drivers/staging/iio/adc/ad7416.c new file +10
-0+if (ret) +return -EIO ; + +return ret; +} + +static ssize_t ad7416_show_available_oti_modes (struct device *dev, +struct device_attribute *attr, +char *buf) +{
space separated please.
drivers/staging/iio/adc/ad7416.c line 447
Quoted 13 lines
drivers/staging/iio/adc/ad7416.c new file +13
-0+return sprintf (buf,"comparator\ninterrupt\n" ); +} + +static ssize_t ad7416_show_fault_queue (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7416_chip_info *chip = dev_info->dev_data; +u8 config; +int ret; + +/* retrive ALART status */
alert.
drivers/staging/iio/adc/ad7416.c line 455
Quoted 8 lines
drivers/staging/iio/adc/ad7416.c new file +8
-0+ ret =ad7416_i2c_read (chip,AD7416_CONFIG , &config); +if (ret) +return -EIO ; + +return sprintf (buf,"%d\n" , (config &AD7416_FAULT_QUEUE_MASK ) >> +AD7416_FAULT_QUEUE_OFFSET ); +} +
please document this one. Interface probably needs to be generally useful.
Quoted 14 lines
drivers/staging/iio/adc/ad7416.c new file +14
-0+static ssize_t ad7416_set_fault_queue (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7416_chip_info *chip = dev_info->dev_data; +unsigned long data; +u8 config; +int ret; + + ret =strict_strtoul (buf,10 , &data); +if (ret || data >3 ) +return -EINVAL ;
drivers/staging/iio/adc/ad7416.c line 479
Quoted 10 lines
drivers/staging/iio/adc/ad7416.c new file +10
-0+ +/* retrive ALART status */ + ret =ad7416_i2c_read (chip,AD7416_CONFIG , &config); +if (ret) +return -EIO ; + + config &= ~AD7416_FAULT_QUEUE_MASK ; + config |= (data <<AD7416_FAULT_QUEUE_OFFSET ); + ret =ad7416_i2c_write (chip,AD7416_CONFIG , config); +if (ret)
more error eating.
drivers/staging/iio/adc/ad7416.c line 204
Quoted 4 lines
drivers/staging/iio/adc/ad7416.c new file +4
-0+return -EIO ; + +return ret; +}
new line here please.
Quoted 60 lines
drivers/staging/iio/adc/ad7416.c new file +60
-0+static inline ssize_t ad7416_show_t_bound (struct device *dev, +struct device_attribute *attr, +u8 bound_reg, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7416_chip_info *chip = dev_info->dev_data; +u16 data; +s16 value; +int ret; + + ret =ad7416_i2c_read (chip, bound_reg, (u8 *)&data); +if (ret) +return -EIO ; + + data =swab16 (data); + data >>= (AD7416_VALUE_OFFSET +1 ); + +if (chip->channel_id ==0 ) { +if (data &AD7416_BOUND_VALUE_SIGN ) { + value = (s16)(data&(~AD7416_BOUND_VALUE_SIGN )); + value = value -AD7416_BOUND_VALUE_SIGN ; + }else + value = (s16 )data; + +return sprintf (buf,"%d\n" , value >>1 ); + }else +return sprintf (buf,"%u\n" , data); +} + +static inline ssize_t ad7416_set_t_bound (struct device *dev, +struct device_attribute *attr, +u8 bound_reg, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7416_chip_info *chip = dev_info->dev_data; +long value; +u16 data; +int ret; + +if (chip->channel_id ==0 ) { + ret =strict_strtol (buf,10 , &value); + +if (ret || value <-128 || value >127 ) +return -EINVAL ; +if (value <0 ) + value = (AD7416_BOUND_VALUE_SIGN + value) | +AD7416_BOUND_VALUE_SIGN ; + + data = (u16 )value <<1 ; + }else { + ret =strict_strtoul (buf,10 , &value); + +if (ret || value >511 || value <0 ) +return -EINVAL ; + + data = (u16 )value; + }
drivers/staging/iio/adc/ad7416.c line 553
Quoted 10 lines
drivers/staging/iio/adc/ad7416.c new file +10
-0+ + data <<= (AD7416_VALUE_OFFSET +1 ); + data =swab16 (data); + ret =ad7416_i2c_write (chip, bound_reg, (u8 )data); +if (ret) +return -EIO ; + +return ret; +} +
could probably use one function for all of these.
Quoted 24 lines
drivers/staging/iio/adc/ad7416.c new file +24
-0+static ssize_t ad7416_show_t_oti (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return ad7416_show_t_bound (dev, attr, +AD7416_T_OTI , buf); +} + +static inline ssize_t ad7416_set_t_oti (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +return ad7416_set_t_bound (dev, attr, +AD7416_T_OTI , buf, len); +} + +static ssize_t ad7416_show_t_hyst (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return ad7416_show_t_bound (dev, attr, +AD7416_T_HYST , buf); +}
drivers/staging/iio/adc/ad7416.c line 587
Quoted 10 lines
drivers/staging/iio/adc/ad7416.c new file +10
-0+ +static inline ssize_t ad7416_set_t_hyst (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +return ad7416_set_t_bound (dev, attr, +AD7416_T_HYST , buf, len); +} +
Usual point here. Only attributes that enable / disable should use the event macros.
drivers/staging/iio/adc/ad7416.c line 593
Quoted 6 lines
drivers/staging/iio/adc/ad7416.c new file +6
-0+IIO_EVENT_ATTR_SH (oti_mode, iio_event_ad7416, + ad7416_show_oti_mode, ad7416_set_oti_mode,0 ); +IIO_EVENT_ATTR_SH (available_oti_modes, iio_event_ad7416, + ad7416_show_available_oti_modes,NULL ,0 ); +IIO_EVENT_ATTR_SH (fault_queue, iio_event_ad7416, + ad7416_show_fault_queue, ad7416_set_fault_queue,0 );
Not sure what this is but that's not a standard abi...
Quoted 184 lines
drivers/staging/iio/adc/ad7416.c new file +184
-0+IIO_EVENT_ATTR_SH (t_oti, iio_event_ad7416, + ad7416_show_t_oti, ad7416_set_t_oti,0 ); +IIO_EVENT_ATTR_SH (t_hyst, iio_event_ad7416, + ad7416_show_t_hyst, ad7416_set_t_hyst,0 ); + +static struct attribute *ad7416_event_attributes[] = { + &iio_event_attr_oti_mode.dev_attr.attr, + &iio_event_attr_available_oti_modes.dev_attr.attr, + &iio_event_attr_fault_queue.dev_attr.attr, + &iio_event_attr_t_oti.dev_attr.attr, + &iio_event_attr_t_hyst.dev_attr.attr, +NULL , +}; + +static struct attribute_group ad7416_event_attribute_group = { + .attrs = ad7416_event_attributes, +}; + +/* +* device probe and remove +*/ + +static int __devinit ad7416_probe (struct i2c_client *client, +const struct i2c_device_id *id) +{ +struct ad7416_chip_info *chip; +unsigned long convert_pin = (unsigned long )client->dev.platform_data; +int ret =0 ; +u8 config; + + chip =kzalloc (sizeof (struct ad7416_chip_info ),GFP_KERNEL ); + +if (chip ==NULL ) +return -ENOMEM ; + +/* this is only used for device removal purposes */ +i2c_set_clientdata (client, chip); + + chip->client = client; + chip->name = id->name; +if (strcmp (chip->name,"ad7418" ) ==0 ) { + chip->channel_mask =AD7418_CHANNEL_MASK ; +if (convert_pin) { + ret =gpio_request (convert_pin, chip->name); +if (!ret) { + chip->convert_pin = (u16 )convert_pin; +gpio_set_value (chip->convert_pin,0 ); + } + } + }else if (strcmp (chip->name,"ad7417" ) ==0 ) { + chip->channel_mask =AD7417_CHANNEL_MASK ; +if (convert_pin) { + ret =gpio_request (convert_pin, chip->name); +if (!ret) { + chip->convert_pin = (u16 )convert_pin; +gpio_set_value (chip->convert_pin,0 ); + } + } + }else + chip->channel_mask =AD7416_CHANNEL_MASK ; + + chip->indio_dev =iio_allocate_device (); +if (chip->indio_dev ==NULL ) { + ret = -ENOMEM ; + goto error_free_chip; + } + + chip->indio_dev->dev.parent = &client->dev; + chip->indio_dev->attrs = &ad7416_attribute_group; + chip->indio_dev->event_attrs = &ad7416_event_attribute_group; + chip->indio_dev->dev_data = (void *)chip; + chip->indio_dev->driver_module =THIS_MODULE ; + chip->indio_dev->num_interrupt_lines =1 ; + chip->indio_dev->modes =INDIO_DIRECT_MODE ; + + ret =iio_device_register (chip->indio_dev); +if (ret) + goto error_free_dev; + +if (client->irq) { + ret =iio_register_interrupt_line (client->irq, + chip->indio_dev, +0 , + client->irq_flags, + chip->name); +if (ret) + goto error_unreg_dev; + +/* +* The event handler list element refer to iio_event_ad7416. +* All event attributes bind to the same event handler. +* So, only register event handler once. +*/ +iio_add_event_to_list (&iio_event_ad7416, + &chip->indio_dev->interrupts[0 ]->ev_list); + +INIT_WORK (&chip->thresh_work, ad7416_interrupt_bh); + + ret =ad7416_i2c_read (chip,AD7416_CONFIG , &config); +if (ret) { + ret = -EIO ; + goto error_unreg_irq; + } + +if (client->irq_flags &IRQF_TRIGGER_HIGH ) + ret =ad7416_i2c_write (chip,AD7416_CONFIG , + config |AD7416_OTI_POLARITY ); +else + ret =ad7416_i2c_write (chip,AD7416_CONFIG , + config & ~AD7416_OTI_POLARITY ); +if (ret) { + ret = -EIO ; + goto error_unreg_irq; + } + } + +dev_info (&client->dev,"%s temperature sensor and ADC registered.\n" , + id->name); + +return 0 ; + +error_unreg_irq: +iio_unregister_interrupt_line (chip->indio_dev,0 ); +error_unreg_dev: +iio_device_unregister (chip->indio_dev); +error_free_dev: +iio_free_device (chip->indio_dev); +error_free_chip: +kfree (chip); + +return ret; +} + +static int __devexit ad7416_remove(struct i2c_client *client) +{ +struct ad7416_chip_info *chip =i2c_get_clientdata (client); +struct iio_dev *indio_dev = chip->indio_dev; + +if (client->irq) +iio_unregister_interrupt_line (indio_dev,0 ); +iio_device_unregister (indio_dev); +iio_free_device (chip->indio_dev); +if (chip->convert_pin) +gpio_free (chip->convert_pin); +kfree (chip); + +return 0 ; +} + +static const struct i2c_device_id ad7416_id[] = { + {"ad7416" ,0 }, + {"ad7417" ,0 }, + {"ad7418" ,0 }, + {} +}; + +MODULE_DEVICE_TABLE (i2c, ad7416_id); + +static struct i2c_driver ad7416_driver = { + .driver = { + .name ="ad7416" , + }, + .probe = ad7416_probe, + .remove =__devexit_p (ad7416_remove), + .id_table = ad7416_id, +}; + +static __init int ad7416_init (void ) +{ +return i2c_add_driver (&ad7416_driver); +} + +static __exit void ad7416_exit(void) +{ +i2c_del_driver (&ad7416_driver); +} + +MODULE_AUTHOR ("Sonic Zhang <[email protected]>" ); +MODULE_DESCRIPTION ("Analog Devices AD7416/7/8 digital" +" temperature sensor driver" ); +MODULE_LICENSE ("GPL v2" ); + +module_init (ad7416_init); +module_exit (ad7416_exit);
PATCH 7/14 staging: iio: adc: new driver for AD7475/6/6A/7/7A/8/8A and AD7495 devices
In reply to Mike FrysingerFrom: Michael Hennerich <[email protected]>
--- drivers/staging/iio/adc/Kconfig | 11 ++ drivers/staging/iio/adc/Makefile | 4 + drivers/staging/iio/adc/ad7476.h | 66 +++++++++ drivers/staging/iio/adc/ad7476_core.c | 203 ++++++++++++++++++++++++++++ drivers/staging/iio/adc/ad7476_ring.c | 240 +++++++++++++++++++++++++++++++++ 5 files changed, 524 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/iio/adc/ad7476.h create mode 100644 drivers/staging/iio/adc/ad7476_core.c create mode 100644 drivers/staging/iio/adc/ad7476_ring.c
drivers/staging/iio/adc/Kconfig +11 -0
@@ -75,3 +75,14 @@ config AD7416 help Say yes here to build support for Analog Devices AD74167/8 temperature sensors and ADC. + +config AD7476 + tristate "Analog Devices AD7475/6/7/8 and AD7495 ADC driver" + depends on SPI + help + Say yes here to build support for Analog Devices AD7475/6/7/8, + AD7495 ADC driver. + If unsure, say N (but it's safe to say "Y"). + + To compile this driver as a module, choose M here: the + module will be called ad7476.
drivers/staging/iio/adc/Makefile +4 -0
@@ -5,6 +5,9 @@ max1363-y := max1363_core.o max1363-y += max1363_ring.o +ad7476-y := ad7476_core.o +ad7476-$(CONFIG_IIO_RING_BUFFER) += ad7476_ring.o + obj-$(CONFIG_MAX1363) += max1363.o obj-$(CONFIG_AD7150) += ad7150.o obj-$(CONFIG_AD7152) += ad7152.o
@@ -13,3 +16,4 @@ obj-$(CONFIG_AD7298) += ad7298.o obj-$(CONFIG_AD7314) += ad7314.o obj-$(CONFIG_AD7414) += ad7414.o obj-$(CONFIG_AD7416) += ad7416.o +obj-$(CONFIG_AD7476) += ad7476.o
drivers/staging/iio/adc/ad7476.h new file +66 -0
66 lines not on this page · raw message
drivers/staging/iio/adc/ad7476_core.c new file +203 -0
203 lines not on this page · raw message
drivers/staging/iio/adc/ad7476_ring.c new file +240 -0
240 lines not on this page · raw message
Signature · 1 line
1.7.3.2
Re: [Device-drivers-devel] [PATCH 07/14] staging: iio: adc: new driver for AD7475/6/6A/7/7A/8/8A and AD7495 devices
i guess this one is already merged into staging-next, so it can be ignored -mike
Re: [PATCH 07/14] staging: iio: adc: new driver for AD7475/6/6A/7/7A/8/8A and AD7495 devices
In reply to Mike FrysingerQuoted 2 lines · Mike Frysinger
From: Michael Hennerich <[email protected]>
This one looks familiar ;) It's already merged
Quoted 578 lines
Signed-off-by Michael Hennerich <[email protected]>Signed-off-by Mike Frysinger <[email protected]>--- drivers/staging/iio/adc/Kconfig | 11 ++ drivers/staging/iio/adc/Makefile | 4 + drivers/staging/iio/adc/ad7476.h | 66 +++++++++ drivers/staging/iio/adc/ad7476_core.c | 203 ++++++++++++++++++++++++++++ drivers/staging/iio/adc/ad7476_ring.c | 240 +++++++++++++++++++++++++++++++++ 5 files changed, 524 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/iio/adc/ad7476.h create mode 100644 drivers/staging/iio/adc/ad7476_core.c create mode 100644 drivers/staging/iio/adc/ad7476_ring.cdrivers/staging/iio/adc/Kconfig +11
-0@@ -75,3 +75,14 @@ config AD7416 help Say yes here to build support for Analog Devices AD74167/8 temperature sensors and ADC. + +config AD7476 + tristate "Analog Devices AD7475/6/7/8 and AD7495 ADC driver" + depends on SPI + help + Say yes here to build support for Analog Devices AD7475/6/7/8, + AD7495 ADC driver. + If unsure, say N (but it's safe to say "Y"). + + To compile this driver as a module, choose M here: the + module will be called ad7476.drivers/staging/iio/adc/Makefile +4
-0@@ -5,6 +5,9 @@ max1363-y := max1363_core.o max1363-y += max1363_ring.o +ad7476-y := ad7476_core.o +ad7476-$(CONFIG_IIO_RING_BUFFER) += ad7476_ring.o + obj-$(CONFIG_MAX1363) += max1363.o obj-$(CONFIG_AD7150) += ad7150.o obj-$(CONFIG_AD7152) += ad7152.o@@ -13,3 +16,4 @@ obj-$(CONFIG_AD7298) += ad7298.o obj-$(CONFIG_AD7314) += ad7314.o obj-$(CONFIG_AD7414) += ad7414.o obj-$(CONFIG_AD7416) += ad7416.o +obj-$(CONFIG_AD7476) += ad7476.odrivers/staging/iio/adc/ad7476.h new file +66
-0@@ -0,0 +1,66 @@ +#ifndef _AD7476_H_ +#define _AD7476_H_ + +struct ad7476_mode { +const char *name; +int numvals; +}; + +struct ad7476_state { +struct iio_dev *indio_dev; +struct spi_device *spi; +char setupbyte; +char configbyte; +const struct ad7476_chip_info *chip_info; +const struct ad7476_mode *current_mode; +struct work_struct poll_work; +atomic_t protect_ring; +struct iio_trigger *trig; +struct spi_transfer xfer; +struct spi_message msg; +unsigned char data[2 ]; +}; + +#define CHIP_NAME "AD7876/7/8" + +#ifdef CONFIG_IIO_RING_BUFFER + +ssize_t ad7476_scan_from_ring (struct device *dev, +struct device_attribute *attr, +char *buf); +int ad7476_register_ring_funcs_and_init (struct iio_dev *indio_dev); +void ad7476_ring_cleanup (struct iio_dev *indio_dev); + +int ad7476_initialize_ring (struct iio_ring_buffer *ring); +void ad7476_uninitialize_ring (struct iio_ring_buffer *ring); + +#else /* CONFIG_IIO_RING_BUFFER */ + +static inline void ad7476_uninitialize_ring (struct iio_ring_buffer *ring) +{ +} + +static inline int ad7476_initialize_ring (struct iio_ring_buffer *ring) +{ +return 0 ; +} + + +static inline ssize_t ad7476_scan_from_ring (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return 0 ; +} + +static inline int +ad7476_register_ring_funcs_and_init (struct iio_dev *indio_dev) +{ +return 0 ; +} + +static inline void ad7476_ring_cleanup (struct iio_dev *indio_dev) +{ +} +#endif /* CONFIG_IIO_RING_BUFFER */ +#endif /* _AD7476_H_ */ drivers/staging/iio/adc/ad7476_core.c new file +203
-0@@ -0,0 +1,203 @@ +/* +* AD7476/5/7/8 (A) SPI ADC driver +* +* Copyright 2010 Analog Devices Inc. +* +* Licensed under the GPL-2 or later. +*/ + +#include <linux/interrupt.h> +#include <linux/workqueue.h> +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/sysfs.h> +#include <linux/list.h> +#include <linux/spi/spi.h> + +#include "../iio.h" +#include "../sysfs.h" + +#include "ad7476.h" + +static const struct ad7476_mode ad7476_mode_table[] = { + { + .name ="s0" , + .numvals =1 , + }, +}; + +static ssize_t ad7476_scan_direct (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7476_state *st = dev_info->dev_data; +int ret; +struct spi_device *spi = st->spi; + + ret =spi_sync (spi, &st->msg); +if (ret) +return ret; + +return sprintf (buf,"%d\n" , (st->data[0 ] <<8 ) | st->data[1 ]); +} + +static ssize_t ad7476_scan (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +int ret; + +mutex_lock (&dev_info->mlock); +if (dev_info->currentmode ==INDIO_RING_TRIGGERED ) + ret =ad7476_scan_from_ring (dev, attr, buf); +else + ret =ad7476_scan_direct (dev, attr, buf); +mutex_unlock (&dev_info->mlock); + +return ret; +} + +/* Cannot query the device, so use local copy of state */ +static ssize_t ad7476_show_scan_mode (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7476_state *st = dev_info->dev_data; + +return sprintf (buf,"%s\n" , st->current_mode->name); +} + + +static IIO_DEV_ATTR_AVAIL_SCAN_MODES (ad7476_show_scan_mode); +static IIO_DEV_ATTR_SCAN_MODE(S_IRUGO | S_IWUSR, + ad7476_show_scan_mode, NULL); + +static IIO_DEV_ATTR_SCAN (ad7476_scan); + +static ssize_t ad7476_show_name (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return sprintf (buf,"%s\n" ,CHIP_NAME ); +} + +static IIO_DEVICE_ATTR(name, S_IRUGO, ad7476_show_name, NULL, 0); + +/*name export */ + +static struct attribute *ad7476_attributes[] = { + &iio_dev_attr_available_scan_modes.dev_attr.attr, + &iio_dev_attr_scan_mode.dev_attr.attr, + &iio_dev_attr_scan.dev_attr.attr, + &iio_dev_attr_name.dev_attr.attr, +NULL , +}; + +static const struct attribute_group ad7476_attribute_group = { + .attrs = ad7476_attributes, +}; + +static int __devinit ad7476_probe (struct spi_device *spi) +{ +int ret; +struct ad7476_state *st =kzalloc (sizeof (*st),GFP_KERNEL ); +if (st ==NULL ) { + ret = -ENOMEM ; + goto error_ret; + } + +spi_set_drvdata (spi, st); + +atomic_set (&st->protect_ring,0 ); + st->spi = spi; + + st->indio_dev =iio_allocate_device (); +if (st->indio_dev ==NULL ) { + ret = -ENOMEM ; + goto error_free_st; + } + +/* Estabilish that the iio_dev is a child of the i2c device */ + st->indio_dev->dev.parent = &spi->dev; + st->indio_dev->attrs = &ad7476_attribute_group; + st->indio_dev->dev_data = (void *)(st); + st->indio_dev->driver_module =THIS_MODULE ; + st->indio_dev->modes =INDIO_DIRECT_MODE ; + + st->current_mode = &ad7476_mode_table[0 ]; + +/* Setup default message */ + + st->xfer.rx_buf = &st->data; + st->xfer.len = st->current_mode->numvals *2 ; + +spi_message_init (&st->msg); +spi_message_add_tail (&st->xfer, &st->msg); + + ret =ad7476_register_ring_funcs_and_init (st->indio_dev); +if (ret) + goto error_free_device; + + ret =iio_device_register (st->indio_dev); +if (ret) + goto error_free_device; + + ret =ad7476_initialize_ring (st->indio_dev->ring); +if (ret) + goto error_cleanup_ring; +return 0 ; + +error_cleanup_ring: +ad7476_ring_cleanup (st->indio_dev); +iio_device_unregister (st->indio_dev); +error_free_device: +iio_free_device (st->indio_dev); +error_free_st: +kfree (st); +error_ret: +return ret; +} + +static int ad7476_remove (struct spi_device *spi) +{ +struct ad7476_state *st =spi_get_drvdata (spi); +struct iio_dev *indio_dev = st->indio_dev; +ad7476_uninitialize_ring (indio_dev->ring); +ad7476_ring_cleanup (indio_dev); +iio_device_unregister (indio_dev); +kfree (st); + +return 0 ; +} + + +static struct spi_driver ad7476_driver = { + .driver = { + .name ="ad7476" , + .bus = &spi_bus_type, + .owner =THIS_MODULE , + }, + .probe = ad7476_probe, + .remove =__devexit_p (ad7476_remove), +}; + +static int __init ad7476_init (void ) +{ +return spi_register_driver (&ad7476_driver); +} +module_init (ad7476_init); + +static void __exit ad7476_exit(void) +{ +spi_unregister_driver (&ad7476_driver); +} +module_exit (ad7476_exit); + +MODULE_AUTHOR ("Michael Hennerich <[email protected]>" ); +MODULE_DESCRIPTION ("Analog Devices AD7475/6/7/8(A) ADC" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_ALIAS ("spi:ad7476" );drivers/staging/iio/adc/ad7476_ring.c new file +240
-0@@ -0,0 +1,240 @@ +/* +* Copyright 2010 Analog Devices Inc. +* Copyright (C) 2008 Jonathan Cameron +* +* Licensed under the GPL-2 or later. +* +* ad7476_ring.c +*/ + +#include <linux/interrupt.h> +#include <linux/gpio.h> +#include <linux/workqueue.h> +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/sysfs.h> +#include <linux/list.h> +#include <linux/spi/spi.h> + +#include "../iio.h" +#include "../ring_generic.h" +#include "../ring_sw.h" +#include "../trigger.h" +#include "../sysfs.h" + +#include "ad7476.h" + +ssize_t ad7476_scan_from_ring (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7476_state *info = dev_info->dev_data; +int i, ret, len =0 ; +char *ring_data; + + ring_data =kmalloc (info->current_mode->numvals*2 ,GFP_KERNEL ); +if (ring_data ==NULL ) { + ret = -ENOMEM ; + goto error_ret; + } + ret = dev_info->ring->access.read_last (dev_info->ring, ring_data); +if (ret) + goto error_free_ring_data; + len +=sprintf (buf+len,"ring " ); +for (i =0 ; i < info->current_mode->numvals; i++) + len +=sprintf (buf + len,"%d " , + ((int )(ring_data[i*2 +0 ] &0xFF ) <<8 ) + + ((int )(ring_data[i*2 +1 ]))); + len +=sprintf (buf + len,"\n" ); +kfree (ring_data); + +return len; + +error_free_ring_data: +kfree (ring_data); +error_ret: +return ret; +} + +/** +* ad7476_ring_preenable() setup the parameters of the ring before enabling +* +* The complex nature of the setting of the nuber of bytes per datum is due +* to this driver currently ensuring that the timestamp is stored at an 8 +* byte boundary. +**/ +static int ad7476_ring_preenable (struct iio_dev *indio_dev) +{ +struct ad7476_state *st = indio_dev->dev_data; +size_t d_size; + +if (indio_dev->ring->access.set_bpd) { + d_size = st->current_mode->numvals*2 +sizeof (s64); +if (d_size %8 ) + d_size +=8 - (d_size %8 ); + indio_dev->ring->access.set_bpd (indio_dev->ring, d_size); + } + +return 0 ; +} + +/** +* ad7476_ring_postenable() typical ring post enable +* +* Only not moved into the core for the hardware ring buffer cases +* that are more sophisticated. +**/ +static int ad7476_ring_postenable (struct iio_dev *indio_dev) +{ +if (indio_dev->trig ==NULL ) +return 0 ; +return iio_trigger_attach_poll_func (indio_dev->trig, + indio_dev->pollfunc); +} + +/** +* ad7476_ring_predisable() runs just prior to ring buffer being disabled +* +* Typical predisable function which ensures that no trigger events can +* occur before we disable the ring buffer (and hence would have no idea +* what to do with them) +**/ +static int ad7476_ring_predisable (struct iio_dev *indio_dev) +{ +if (indio_dev->trig) +return iio_trigger_dettach_poll_func (indio_dev->trig, + indio_dev->pollfunc); +else +return 0 ; +} + +/** +* ad7476_poll_func_th() th of trigger launched polling to ring buffer +* +* As sampling only occurs on i2c comms occuring, leave timestamping until +* then. Some triggers will generate their own time stamp. Currently +* there is no way of notifying them when no one cares. +**/ +void ad7476_poll_func_th (struct iio_dev *indio_dev) +{ +struct ad7476_state *st = indio_dev->dev_data; + +schedule_work (&st->poll_work); + +return ; +} +/** +* ad7476_poll_bh_to_ring() bh of trigger launched polling to ring buffer +* @work_s: the work struct through which this was scheduled +* +* Currently there is no option in this driver to disable the saving of +* timestamps within the ring. +* I think the one copy of this at a time was to avoid problems if the +* trigger was set far too high and the reads then locked up the computer. +**/ +static void ad7476_poll_bh_to_ring (struct work_struct *work_s) +{ + struct ad7476_state *st = container_of(work_s, struct ad7476_state, + poll_work); +struct iio_dev *indio_dev = st->indio_dev; +struct iio_sw_ring_buffer *ring =iio_to_sw_ring (indio_dev->ring); +s64 time_ns; +__u8 *rxbuf; +int b_sent; +size_t d_size; + +/* Ensure the timestamp is 8 byte aligned */ + d_size = st->current_mode->numvals*2 +sizeof (s64); +if (d_size %sizeof (s64)) + d_size +=sizeof (s64) - (d_size %sizeof (s64)); + +/* Ensure only one copy of this function running at a time */ +if (atomic_inc_return (&st->protect_ring) >1 ) +return ; + +/* Monitor mode prevents reading. Whilst not currently implemented +* might as well have this test in here in the meantime as it does +* no harm. +*/ +if (st->current_mode->numvals ==0 ) +return ; + + rxbuf =kmalloc (d_size,GFP_KERNEL ); +if (rxbuf ==NULL ) +return ; + + b_sent =spi_read (st->spi, rxbuf, + st->current_mode->numvals *2 ); +if (b_sent <0 ) + goto done; + + time_ns =iio_get_time_ns (); + +memcpy (rxbuf + d_size -sizeof (s64), &time_ns,sizeof (time_ns)); + + indio_dev->ring->access.store_to (&ring->buf, rxbuf, time_ns); +done: +kfree (rxbuf); +atomic_dec (&st->protect_ring); +} + + +int ad7476_register_ring_funcs_and_init (struct iio_dev *indio_dev) +{ +struct ad7476_state *st = indio_dev->dev_data; +int ret =0 ; + + indio_dev->ring =iio_sw_rb_allocate (indio_dev); +if (!indio_dev->ring) { + ret = -ENOMEM ; + goto error_ret; + } +/* Effectively select the ring buffer implementation */ +iio_ring_sw_register_funcs (&st->indio_dev->ring->access); + indio_dev->pollfunc =kzalloc (sizeof (*indio_dev->pollfunc),GFP_KERNEL ); +if (indio_dev->pollfunc ==NULL ) { + ret = -ENOMEM ; + goto error_deallocate_sw_rb; + } +/* Configure the polling function called on trigger interrupts */ + indio_dev->pollfunc->poll_func_main = &ad7476_poll_func_th; + indio_dev->pollfunc->private_data = indio_dev; + +/* Ring buffer functions - here trigger setup related */ + indio_dev->ring->postenable = &ad7476_ring_postenable; + indio_dev->ring->preenable = &ad7476_ring_preenable; + indio_dev->ring->predisable = &ad7476_ring_predisable; +INIT_WORK (&st->poll_work, &ad7476_poll_bh_to_ring); + +/* Flag that polled ring buffering is possible */ + indio_dev->modes |=INDIO_RING_TRIGGERED ; +return 0 ; +error_deallocate_sw_rb: +iio_sw_rb_free (indio_dev->ring); +error_ret: +return ret; +} + +void ad7476_ring_cleanup (struct iio_dev *indio_dev) +{ +/* ensure that the trigger has been detached */ +if (indio_dev->trig) { +iio_put_trigger (indio_dev->trig); +iio_trigger_dettach_poll_func (indio_dev->trig, + indio_dev->pollfunc); + } +kfree (indio_dev->pollfunc); +iio_sw_rb_free (indio_dev->ring); +} + +void ad7476_uninitialize_ring (struct iio_ring_buffer *ring) +{ +iio_ring_buffer_unregister (ring); +} + +int ad7476_initialize_ring (struct iio_ring_buffer *ring) +{ +return iio_ring_buffer_register (ring,0 ); +}
PATCH 8/14 staging: iio: adc: new driver for AD7745/6/7 devices
In reply to Mike FrysingerFrom: Barry Song <[email protected]>
--- drivers/staging/iio/adc/Kconfig | 7 + drivers/staging/iio/adc/Makefile | 1 + drivers/staging/iio/adc/ad774x.c | 719 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 727 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/iio/adc/ad774x.c
drivers/staging/iio/adc/Kconfig +7 -0
@@ -86,3 +86,10 @@ config AD7476 To compile this driver as a module, choose M here: the module will be called ad7476. + +config AD774X + tristate "Analog Devices ad7745/6/7 capacitive sensor driver" + depends on I2C + help + Say yes here to build support for Analog Devices capacitive sensors. + (ad7745, ad7746, ad7747) Provides direct access via sysfs.
drivers/staging/iio/adc/Makefile +1 -0
@@ -17,3 +17,4 @@ obj-$(CONFIG_AD7314) += ad7314.o obj-$(CONFIG_AD7414) += ad7414.o obj-$(CONFIG_AD7416) += ad7416.o obj-$(CONFIG_AD7476) += ad7476.o +obj-$(CONFIG_AD774X) += ad774x.o
drivers/staging/iio/adc/ad774x.c new file +719 -0
719 lines not on this page · raw message
Signature · 1 line
1.7.3.2
Re: [PATCH 08/14] staging: iio: adc: new driver for AD7745/6/7 devices
Quoted 2 lines · Mike Frysinger
From: Barry Song <[email protected]>
This one is mostly clean. Needs some abi cleanup
and a few new abi elements need pinning down and documenting...
Quoted 2 lines
Signed-off-by Barry Song <[email protected]>Signed-off-by Mike Frysinger <[email protected]>
Quoted 4 lines
--- drivers/staging/iio/adc/Kconfig | 7 + drivers/staging/iio/adc/Makefile | 1 + drivers/staging/iio/adc/ad774x.c | 719 ++++++++++++++++++++++++++++++++++++++
No generic names please unless every part covered by the wild card is supported. Pick a device and name after that.
Quoted 100 lines
3 files changed, 727 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/iio/adc/ad774x.cdrivers/staging/iio/adc/Kconfig +7
-0@@ -86,3 +86,10 @@ config AD7476 To compile this driver as a module, choose M here: the module will be called ad7476. + +config AD774X + tristate "Analog Devices ad7745/6/7 capacitive sensor driver" + depends on I2C + help + Say yes here to build support for Analog Devices capacitive sensors. + (ad7745, ad7746, ad7747) Provides direct access via sysfs.drivers/staging/iio/adc/Makefile +1
-0@@ -17,3 +17,4 @@ obj-$(CONFIG_AD7314) += ad7314.o obj-$(CONFIG_AD7414) += ad7414.o obj-$(CONFIG_AD7416) += ad7416.o obj-$(CONFIG_AD7476) += ad7476.o +obj-$(CONFIG_AD774X) += ad774x.odrivers/staging/iio/adc/ad774x.c new file +67
-0@@ -0,0 +1,719 @@ +/* +* AD774X capacitive sensor driver supporting AD7745/6/7 +* +* Copyright 2010 Analog Devices Inc. +* +* Licensed under the GPL-2 or later. +*/ + +#include <linux/interrupt.h> +#include <linux/gpio.h> +#include <linux/workqueue.h> +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/sysfs.h> +#include <linux/list.h> +#include <linux/i2c.h> +#include <linux/rtc.h> + +#include "../iio.h" +#include "../sysfs.h" + +/* +* AD774X registers definition +*/ + +#define AD774X_STATUS 0 +#define AD774X_STATUS_RDY (1 << 2) +#define AD774X_STATUS_RDYVT (1 << 1) +#define AD774X_STATUS_RDYCAP (1 << 0) +#define AD774X_CAP_DATA_HIGH 1 +#define AD774X_CAP_DATA_MID 2 +#define AD774X_CAP_DATA_LOW 3 +#define AD774X_VT_DATA_HIGH 4 +#define AD774X_VT_DATA_MID 5 +#define AD774X_VT_DATA_LOW 6 +#define AD774X_CAP_SETUP 7 +#define AD774X_VT_SETUP 8 +#define AD774X_EXEC_SETUP 9 +#define AD774X_CFG 10 +#define AD774X_CAPDACA 11 +#define AD774X_CAPDACB 12 +#define AD774X_CAP_OFFH 13 +#define AD774X_CAP_OFFL 14 +#define AD774X_CAP_GAINH 15 +#define AD774X_CAP_GAINL 16 +#define AD774X_VOLT_GAINH 17 +#define AD774X_VOLT_GAINL 18 + +#define AD774X_MAX_CONV_MODE 6 + +/* +* struct ad774x_chip_info - chip specifc information +*/ + +struct ad774x_chip_info { +const char *name; +struct i2c_client *client; +struct iio_dev *indio_dev; +struct work_struct thresh_work; +bool inter; +s64 last_timestamp; +u16 cap_offs;/* Capacitive offset */ +u16 cap_gain;/* Capacitive gain calibration */ +u16 volt_gain;/* Voltage gain calibration */ +u8 cap_setup; +u8 vt_setup;
drivers/staging/iio/adc/ad774x.c line 77
Quoted 10 lines
drivers/staging/iio/adc/ad774x.c new file +10
-0+u8 exec_setup; + +char *conversion_mode; +}; + +struct ad774x_conversion_mode { +char *name; +u8 reg_cfg; +}; +
Same comments on these not being a good idea.
Quoted 7 lines
drivers/staging/iio/adc/ad774x.c new file +7
-0+struct ad774x_conversion_mode ad774x_conv_mode_table[AD774X_MAX_CONV_MODE ] = { + {"idle" ,0 }, + {"continuous-conversion" ,1 }, + {"single-conversion" ,2 }, + {"power-down" ,3 }, + {"offset-calibration" ,5 }, + {"gain-calibration" ,6 },
drivers/staging/iio/adc/ad774x.c line 94
Quoted 10 lines
drivers/staging/iio/adc/ad774x.c new file +10
-0+}; + +/* +* ad774x register access by I2C +*/ + +static int ad774x_i2c_read (struct ad774x_chip_info *chip,u8 reg,u8 *data,int len) +{ +struct i2c_client *client = chip->client; +int ret =0 ;
No need to init ret.
Quoted 10 lines
drivers/staging/iio/adc/ad774x.c new file +10
-0+ + ret =i2c_master_send (client, ®,1 ); +if (ret <0 ) { +dev_err (&client->dev,"I2C write error\n" ); +return ret; + } + + ret =i2c_master_recv (client, data, len); +if (ret <0 ) { +dev_err (&client->dev,"I2C read error\n" );
drivers/staging/iio/adc/ad774x.c line 114
Quoted 10 lines
drivers/staging/iio/adc/ad774x.c new file +10
-0+return ret; + } + +return ret; +} + +static int ad774x_i2c_write (struct ad774x_chip_info *chip,u8 reg,u8 data) +{ +struct i2c_client *client = chip->client; +int ret =0 ;
no need to init ret.
Quoted 13 lines
drivers/staging/iio/adc/ad774x.c new file +13
-0+ +u8 tx[2 ] = { + reg, + data, + }; + + ret =i2c_master_send (client, tx,2 ); +if (ret <0 ) +dev_err (&client->dev,"I2C write error\n" ); + +return ret; +} +
drivers/staging/iio/adc/ad774x.c line 137
Quoted 10 lines
drivers/staging/iio/adc/ad774x.c new file +10
-0+/* +* sysfs nodes +*/ + +#define IIO_DEV_ATTR_AVAIL_CONVERSION_MODES (_show) \ + IIO_DEVICE_ATTR(available_conversion_modes, S_IRUGO, _show, NULL, 0) +#define IIO_DEV_ATTR_CONVERSION_MODE (_mode, _show, _store) \ + IIO_DEVICE_ATTR(conversion_mode, _mode, _show, _store, 0) +#define IIO_DEV_ATTR_CAP_SETUP (_mode, _show, _store) \ + IIO_DEVICE_ATTR(cap_setup, _mode, _show, _store, 0)
I sense magic values.... Get rid of these.
drivers/staging/iio/adc/ad774x.c line 143
Quoted 6 lines
drivers/staging/iio/adc/ad774x.c new file +6
-0+#define IIO_DEV_ATTR_VT_SETUP (_mode, _show, _store) \ + IIO_DEVICE_ATTR(vt_setup, _mode, _show, _store, 0) +#define IIO_DEV_ATTR_EXEC_SETUP (_mode, _show, _store) \ + IIO_DEVICE_ATTR(exec_setup, _mode, _show, _store, 0) +#define IIO_DEV_ATTR_VOLT_GAIN (_mode, _show, _store) \ + IIO_DEVICE_ATTR(volt_gain, _mode, _show, _store, 0)
in_gain
drivers/staging/iio/adc/ad774x.c line 145
Quoted 2 lines
drivers/staging/iio/adc/ad774x.c new file +2
-0+#define IIO_DEV_ATTR_CAP_OFFS (_mode, _show, _store) \ + IIO_DEVICE_ATTR(cap_offs, _mode, _show, _store, 0)#
capacitance_offset (or if this is common in your drivers we could pick cap_...)
drivers/staging/iio/adc/ad774x.c line 147
Quoted 2 lines
drivers/staging/iio/adc/ad774x.c new file +2
-0+#define IIO_DEV_ATTR_CAP_GAIN (_mode, _show, _store) \ + IIO_DEVICE_ATTR(cap_gain, _mode, _show, _store, 0)
capacitance_scale (sorry this one got changed a while back).
drivers/staging/iio/adc/ad774x.c line 149
Quoted 2 lines
drivers/staging/iio/adc/ad774x.c new file +2
-0+#define IIO_DEV_ATTR_DACA_VALUE (_show) \ + IIO_DEVICE_ATTR(daca_value, S_IRUGO, _show, NULL, 0)
dac0_raw
drivers/staging/iio/adc/ad774x.c line 151
Quoted 2 lines
drivers/staging/iio/adc/ad774x.c new file +2
-0+#define IIO_DEV_ATTR_DACB_VALUE (_show) \ + IIO_DEVICE_ATTR(dacb_value, S_IRUGO, _show, NULL, 0)
dac1_raw
drivers/staging/iio/adc/ad774x.c line 155
Quoted 4 lines
drivers/staging/iio/adc/ad774x.c new file +4
-0+#define IIO_DEV_ATTR_CAP_DATA (_show) \ + IIO_DEVICE_ATTR(cap_data, S_IRUGO, _show, NULL, 0) +#define IIO_DEV_ATTR_VT_DATA (_show) \ + IIO_DEVICE_ATTR(vt_data, S_IRUGO, _show, NULL, 0)
probably break the various things this can be out and change mode as is needed.
Quoted 47 lines
drivers/staging/iio/adc/ad774x.c new file +47
-0+ +static ssize_t ad774x_show_conversion_modes (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +int i; +int len =0 ; + +for (i =0 ; i <AD774X_MAX_CONV_MODE ; i++) + len +=sprintf (buf + len,"%s\n" , ad774x_conv_mode_table[i].name); + +return len; +} + +static IIO_DEV_ATTR_AVAIL_CONVERSION_MODES (ad774x_show_conversion_modes); + +static ssize_t ad774x_show_conversion_mode (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad774x_chip_info *chip = dev_info->dev_data; + +return sprintf (buf,"%s\n" , chip->conversion_mode); +} + +static ssize_t ad774x_store_conversion_mode (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad774x_chip_info *chip = dev_info->dev_data; +u8 cfg; +int i; + +ad774x_i2c_read (chip,AD774X_CFG , &cfg,1 ); + +for (i =0 ; i <AD774X_MAX_CONV_MODE ; i++) { +if (strncmp (buf, ad774x_conv_mode_table[i].name, +strlen (ad774x_conv_mode_table[i].name) -1 ) ==0 ) { + chip->conversion_mode = ad774x_conv_mode_table[i].name; + cfg |=0x18 | ad774x_conv_mode_table[i].reg_cfg; +ad774x_i2c_write (chip,AD774X_CFG , cfg); +return len; + } + }
drivers/staging/iio/adc/ad774x.c line 212
Quoted 10 lines
drivers/staging/iio/adc/ad774x.c new file +10
-0+ +dev_err (dev,"not supported conversion mode\n" ); + +return -EINVAL ; +} + +static IIO_DEV_ATTR_CONVERSION_MODE(S_IRUGO | S_IWUSR, + ad774x_show_conversion_mode, + ad774x_store_conversion_mode); +
Would have thought the next two could be easily combined?
Quoted 162 lines
drivers/staging/iio/adc/ad774x.c new file +162
-0+static ssize_t ad774x_show_daca_value (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad774x_chip_info *chip = dev_info->dev_data; +u8 data; + +ad774x_i2c_read (chip,AD774X_CAPDACA , &data,1 ); + +return sprintf (buf,"%02x\n" , data); +} + +static IIO_DEV_ATTR_DACA_VALUE (ad774x_show_daca_value); + +static ssize_t ad774x_show_dacb_value (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad774x_chip_info *chip = dev_info->dev_data; +u8 data; + +ad774x_i2c_read (chip,AD774X_CAPDACB , &data,1 ); + +return sprintf (buf,"%02x\n" , data); +} + +static IIO_DEV_ATTR_DACB_VALUE (ad774x_show_dacb_value); + +static ssize_t ad774x_show_cap_setup (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad774x_chip_info *chip = dev_info->dev_data; + +return sprintf (buf,"0x%02x\n" , chip->cap_setup); +} + +static ssize_t ad774x_store_cap_setup (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad774x_chip_info *chip = dev_info->dev_data; +unsigned long data; +int ret; + + ret =strict_strtoul (buf,10 , &data); + +if ((!ret) && (data <0x100 )) { +ad774x_i2c_write (chip,AD774X_CAP_SETUP , data); + chip->cap_setup = data; +return len; + } + + +return -EINVAL ; +} + +static IIO_DEV_ATTR_CAP_SETUP(S_IRUGO | S_IWUSR, + ad774x_show_cap_setup, + ad774x_store_cap_setup); + +static ssize_t ad774x_show_vt_setup (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad774x_chip_info *chip = dev_info->dev_data; + +return sprintf (buf,"0x%02x\n" , chip->vt_setup); +} + +static ssize_t ad774x_store_vt_setup (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad774x_chip_info *chip = dev_info->dev_data; +unsigned long data; +int ret; + + ret =strict_strtoul (buf,10 , &data); + +if ((!ret) && (data <0x100 )) { +ad774x_i2c_write (chip,AD774X_VT_SETUP , data); + chip->vt_setup = data; +return len; + } + +return -EINVAL ; +} + +static IIO_DEV_ATTR_VT_SETUP(S_IRUGO | S_IWUSR, + ad774x_show_vt_setup, + ad774x_store_vt_setup); + +static ssize_t ad774x_show_exec_setup (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad774x_chip_info *chip = dev_info->dev_data; + +return sprintf (buf,"0x%02x\n" , chip->exec_setup); +} + +static ssize_t ad774x_store_exec_setup (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad774x_chip_info *chip = dev_info->dev_data; +unsigned long data; +int ret; + + ret =strict_strtoul (buf,10 , &data); + +if ((!ret) && (data <0x100 )) { +ad774x_i2c_write (chip,AD774X_EXEC_SETUP , data); + chip->exec_setup = data; +return len; + } + +return -EINVAL ; +} + +static IIO_DEV_ATTR_EXEC_SETUP(S_IRUGO | S_IWUSR, + ad774x_show_exec_setup, + ad774x_store_exec_setup); + +static ssize_t ad774x_show_volt_gain (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad774x_chip_info *chip = dev_info->dev_data; + +return sprintf (buf,"%d\n" , chip->volt_gain); +} + +static ssize_t ad774x_store_volt_gain (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad774x_chip_info *chip = dev_info->dev_data; +unsigned long data; +int ret; + + ret =strict_strtoul (buf,10 , &data); + +if ((!ret) && (data <0x10000 )) { +ad774x_i2c_write (chip,AD774X_VOLT_GAINH , data >>8 ); +ad774x_i2c_write (chip,AD774X_VOLT_GAINL , data); + chip->volt_gain = data;
drivers/staging/iio/adc/ad774x.c line 384
Quoted 10 lines
drivers/staging/iio/adc/ad774x.c new file +10
-0+return len; + } + +return -EINVAL ; +} + +static IIO_DEV_ATTR_VOLT_GAIN(S_IRUGO | S_IWUSR, + ad774x_show_volt_gain, + ad774x_store_volt_gain); +
The whole voltage thing was mysterious introduced in an early driver from Barry, I thought it was cleaned out of the blackfin tree, but I guess this one escaped. Always in0 etc (as per hwmon who got their first on naming these!)
Quoted 133 lines
drivers/staging/iio/adc/ad774x.c new file +133
-0+static ssize_t ad774x_show_cap_data (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad774x_chip_info *chip = dev_info->dev_data; +unsigned long data; +char tmp[3 ]; + +ad774x_i2c_read (chip,AD774X_CAP_DATA_HIGH , tmp,3 ); + data = ((int )tmp[0 ] <<16 ) | ((int )tmp[1 ] <<8 ) | (int )tmp[2 ]; + +return sprintf (buf,"%ld\n" , data); +} + +static IIO_DEV_ATTR_CAP_DATA (ad774x_show_cap_data); + +static ssize_t ad774x_show_vt_data (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad774x_chip_info *chip = dev_info->dev_data; +unsigned long data; +char tmp[3 ]; + +ad774x_i2c_read (chip,AD774X_VT_DATA_HIGH , tmp,3 ); + data = ((int )tmp[0 ] <<16 ) | ((int )tmp[1 ] <<8 ) | (int )tmp[2 ]; + +return sprintf (buf,"%ld\n" , data); +} + +static IIO_DEV_ATTR_VT_DATA (ad774x_show_vt_data); + +static ssize_t ad774x_show_cap_offs (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad774x_chip_info *chip = dev_info->dev_data; + +return sprintf (buf,"%d\n" , chip->cap_offs); +} + +static ssize_t ad774x_store_cap_offs (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad774x_chip_info *chip = dev_info->dev_data; +unsigned long data; +int ret; + + ret =strict_strtoul (buf,10 , &data); + +if ((!ret) && (data <0x10000 )) { +ad774x_i2c_write (chip,AD774X_CAP_OFFH , data >>8 ); +ad774x_i2c_write (chip,AD774X_CAP_OFFL , data); + chip->cap_offs = data; +return len; + } + +return -EINVAL ; +} + +static IIO_DEV_ATTR_CAP_OFFS(S_IRUGO | S_IWUSR, + ad774x_show_cap_offs, + ad774x_store_cap_offs); + +static ssize_t ad774x_show_cap_gain (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad774x_chip_info *chip = dev_info->dev_data; + +return sprintf (buf,"%d\n" , chip->cap_gain); +} + +static ssize_t ad774x_store_cap_gain (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad774x_chip_info *chip = dev_info->dev_data; +unsigned long data; +int ret; + + ret =strict_strtoul (buf,10 , &data); + +if ((!ret) && (data <0x10000 )) { +ad774x_i2c_write (chip,AD774X_CAP_GAINH , data >>8 ); +ad774x_i2c_write (chip,AD774X_CAP_GAINL , data); + chip->cap_gain = data; +return len; + } + +return -EINVAL ; +} + +static IIO_DEV_ATTR_CAP_GAIN(S_IRUGO | S_IWUSR, + ad774x_show_cap_gain, + ad774x_store_cap_gain); + +static ssize_t ad774x_show_name (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad774x_chip_info *chip = dev_info->dev_data; +return sprintf (buf,"%s\n" , chip->name); +} + +static IIO_DEVICE_ATTR(name, S_IRUGO, ad774x_show_name, NULL, 0); + +static struct attribute *ad774x_attributes[] = { + &iio_dev_attr_available_conversion_modes.dev_attr.attr, + &iio_dev_attr_conversion_mode.dev_attr.attr, + &iio_dev_attr_cap_setup.dev_attr.attr, + &iio_dev_attr_vt_setup.dev_attr.attr, + &iio_dev_attr_exec_setup.dev_attr.attr, + &iio_dev_attr_cap_offs.dev_attr.attr, + &iio_dev_attr_cap_gain.dev_attr.attr, + &iio_dev_attr_volt_gain.dev_attr.attr, + &iio_dev_attr_cap_data.dev_attr.attr, + &iio_dev_attr_daca_value.dev_attr.attr, + &iio_dev_attr_dacb_value.dev_attr.attr, + &iio_dev_attr_name.dev_attr.attr, +NULL , +}; +
drivers/staging/iio/adc/ad774x.c line 527
Quoted 10 lines
drivers/staging/iio/adc/ad774x.c new file +10
-0+static const struct attribute_group ad774x_attribute_group = { + .attrs = ad774x_attributes, +}; + +/* +* data ready events +*/ + +#define IIO_EVENT_CODE_CAP_RDY (IIO_EVENT_CODE_DEVICE_SPECIFIC + 1) +#define IIO_EVENT_CODE_VT_RDY (IIO_EVENT_CODE_DEVICE_SPECIFIC + 2)
Depending on speed these might want to be handled as triggers rather than generic events (moves acting on them into the kernel rather than userspace). Naming may require some thought. This is the first device to do seperate data ready signals for different channels. hohum... I'm open to suggestions...
Quoted 51 lines
drivers/staging/iio/adc/ad774x.c new file +51
-0+ +#define IIO_EVENT_ATTR_CAP_RDY_SH (_evlist, _show, _store, _mask) \ + IIO_EVENT_ATTR_SH(cap_rdy, _evlist, _show, _store, _mask) + +#define IIO_EVENT_ATTR_VT_RDY_SH (_evlist, _show, _store, _mask) \ + IIO_EVENT_ATTR_SH(vt_rdy, _evlist, _show, _store, _mask) + +static void ad774x_interrupt_handler_bh (struct work_struct *work_s) +{ +struct ad774x_chip_info *chip = + container_of(work_s, struct ad774x_chip_info, thresh_work); +u8 int_status; + +enable_irq (chip->client->irq); + +ad774x_i2c_read (chip,AD774X_STATUS , &int_status,1 ); + +if (int_status &AD774X_STATUS_RDYCAP ) +iio_push_event (chip->indio_dev,0 , +IIO_EVENT_CODE_CAP_RDY , + chip->last_timestamp); + +if (int_status &AD774X_STATUS_RDYVT ) +iio_push_event (chip->indio_dev,0 , +IIO_EVENT_CODE_VT_RDY , + chip->last_timestamp); +} + +static int ad774x_interrupt_handler_th (struct iio_dev *dev_info, +int index, +s64 timestamp, +int no_test) +{ +struct ad774x_chip_info *chip = dev_info->dev_data; + + chip->last_timestamp = timestamp; +schedule_work (&chip->thresh_work); + +return 0 ; +} + +IIO_EVENT_SH (data_rdy, &ad774x_interrupt_handler_th); + +static ssize_t ad774x_query_out_mode (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +/* +* AD774X provides one /RDY pin, which can be used as interrupt +* but the pin is not configurable +*/
drivers/staging/iio/adc/ad774x.c line 588
Quoted 10 lines
drivers/staging/iio/adc/ad774x.c new file +10
-0+return sprintf (buf,"1\n" ); +} + +static ssize_t ad774x_set_out_mode (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +return len; +}
Looks like we need to allow for devices that don't allow event's to be turned off. We can clean this up after this merges.
Quoted 31 lines
drivers/staging/iio/adc/ad774x.c new file +31
-0+ +IIO_EVENT_ATTR_CAP_RDY_SH (iio_event_data_rdy, ad774x_query_out_mode, ad774x_set_out_mode,0 ); +IIO_EVENT_ATTR_VT_RDY_SH (iio_event_data_rdy, ad774x_query_out_mode, ad774x_set_out_mode,0 ); + +static struct attribute *ad774x_event_attributes[] = { + &iio_event_attr_cap_rdy.dev_attr.attr, + &iio_event_attr_vt_rdy.dev_attr.attr, +NULL , +}; + +static struct attribute_group ad774x_event_attribute_group = { + .attrs = ad774x_event_attributes, +}; + +/* +* device probe and remove +*/ + +static int __devinit ad774x_probe (struct i2c_client *client, +const struct i2c_device_id *id) +{ +int ret =0 , regdone =0 ; +struct ad774x_chip_info *chip =kzalloc (sizeof (*chip),GFP_KERNEL ); +if (chip ==NULL ) { + ret = -ENOMEM ; + goto error_ret; + } + +/* this is only used for device removal purposes */ +i2c_set_clientdata (client, chip); +
drivers/staging/iio/adc/ad774x.c line 629
Quoted 10 lines
drivers/staging/iio/adc/ad774x.c new file +10
-0+ chip->client = client; + chip->name = id->name; + + chip->indio_dev =iio_allocate_device (); +if (chip->indio_dev ==NULL ) { + ret = -ENOMEM ; + goto error_free_chip; + } + +/* Echipabilish that the iio_dev is a child of the i2c device */
Establish.
Quoted 90 lines
drivers/staging/iio/adc/ad774x.c new file +90
-0+ chip->indio_dev->dev.parent = &client->dev; + chip->indio_dev->attrs = &ad774x_attribute_group; + chip->indio_dev->event_attrs = &ad774x_event_attribute_group; + chip->indio_dev->dev_data = (void *)(chip); + chip->indio_dev->driver_module =THIS_MODULE ; + chip->indio_dev->num_interrupt_lines =1 ; + chip->indio_dev->modes =INDIO_DIRECT_MODE ; + + ret =iio_device_register (chip->indio_dev); +if (ret) + goto error_free_dev; + regdone =1 ; + +if (client->irq &&gpio_is_valid (irq_to_gpio (client->irq)) >0 ) { + ret =iio_register_interrupt_line (client->irq, + chip->indio_dev, +0 , +IRQF_TRIGGER_FALLING , +"ad774x" ); +if (ret) + goto error_free_dev; + +iio_add_event_to_list (iio_event_attr_cap_rdy.listel, + &chip->indio_dev->interrupts[0 ]->ev_list); + +INIT_WORK (&chip->thresh_work, ad774x_interrupt_handler_bh); + } + +dev_err (&client->dev,"%s capacitive sensor registered, irq: %d\n" , id->name, client->irq); + +return 0 ; + +error_free_dev: +if (regdone) +iio_device_unregister (chip->indio_dev); +else +iio_free_device (chip->indio_dev); +error_free_chip: +kfree (chip); +error_ret: +return ret; +} + +static int __devexit ad774x_remove(struct i2c_client *client) +{ +struct ad774x_chip_info *chip =i2c_get_clientdata (client); +struct iio_dev *indio_dev = chip->indio_dev; + +if (client->irq &&gpio_is_valid (irq_to_gpio (client->irq)) >0 ) +iio_unregister_interrupt_line (indio_dev,0 ); +iio_device_unregister (indio_dev); +kfree (chip); + +return 0 ; +} + +static const struct i2c_device_id ad774x_id[] = { + {"ad7745" ,0 }, + {"ad7746" ,0 }, + {"ad7747" ,0 }, + {} +}; + +MODULE_DEVICE_TABLE (i2c, ad774x_id); + +static struct i2c_driver ad774x_driver = { + .driver = { + .name ="ad774x" , + }, + .probe = ad774x_probe, + .remove =__devexit_p (ad774x_remove), + .id_table = ad774x_id, +}; + +static __init int ad774x_init (void ) +{ +return i2c_add_driver (&ad774x_driver); +} + +static __exit void ad774x_exit(void) +{ +i2c_del_driver (&ad774x_driver); +} + +MODULE_AUTHOR ("Barry Song <[email protected]>" ); +MODULE_DESCRIPTION ("Analog Devices ad7745/6/7 capacitive sensor driver" ); +MODULE_LICENSE ("GPL v2" ); + +module_init (ad774x_init); +module_exit (ad774x_exit);
PATCH 9/14 staging: iio: adc: new driver for AD7816 devices
In reply to Mike FrysingerFrom: Sonic Zhang <[email protected]>
--- drivers/staging/iio/adc/Kconfig | 7 + drivers/staging/iio/adc/Makefile | 1 + drivers/staging/iio/adc/ad7816.c | 538 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 546 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/iio/adc/ad7816.c
drivers/staging/iio/adc/Kconfig +7 -0
@@ -93,3 +93,10 @@ config AD774X help Say yes here to build support for Analog Devices capacitive sensors. (ad7745, ad7746, ad7747) Provides direct access via sysfs. + +config AD7816 + tristate "Analog Devices AD7816/7/8 temperature sensor and ADC driver" + depends on SPI + help + Say yes here to build support for Analog Devices AD7816/7/8 + temperature sensors and ADC.
drivers/staging/iio/adc/Makefile +1 -0
@@ -18,3 +18,4 @@ obj-$(CONFIG_AD7414) += ad7414.o obj-$(CONFIG_AD7416) += ad7416.o obj-$(CONFIG_AD7476) += ad7476.o obj-$(CONFIG_AD774X) += ad774x.o +obj-$(CONFIG_AD7816) += ad7816.o
drivers/staging/iio/adc/ad7816.c new file +538 -0
538 lines not on this page · raw message
Signature · 1 line
1.7.3.2
PATCH 10/14 staging: iio: adc: new driver for ADT75 temperature sensors
In reply to Mike FrysingerFrom: Sonic Zhang <[email protected]>
--- drivers/staging/iio/adc/Kconfig | 7 + drivers/staging/iio/adc/Makefile | 1 + drivers/staging/iio/adc/adt75.c | 734 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 742 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/iio/adc/adt75.c
drivers/staging/iio/adc/Kconfig +7 -0
@@ -100,3 +100,10 @@ config AD7816 help Say yes here to build support for Analog Devices AD7816/7/8 temperature sensors and ADC. + +config ADT75 + tristate "Analog Devices ADT75 temperature sensor driver" + depends on I2C + help + Say yes here to build support for Analog Devices ADT75 + temperature sensors.
drivers/staging/iio/adc/Makefile +1 -0
@@ -19,3 +19,4 @@ obj-$(CONFIG_AD7416) += ad7416.o obj-$(CONFIG_AD7476) += ad7476.o obj-$(CONFIG_AD774X) += ad774x.o obj-$(CONFIG_AD7816) += ad7816.o +obj-$(CONFIG_ADT75) += adt75.o
drivers/staging/iio/adc/adt75.c new file +734 -0
734 lines not on this page · raw message
Signature · 1 line
1.7.3.2
PATCH 11/14 staging: iio: adc: new driver for ADT7310 temperature sensors
In reply to Mike FrysingerFrom: Sonic Zhang <[email protected]>
--- drivers/staging/iio/adc/Kconfig | 7 + drivers/staging/iio/adc/Makefile | 1 + drivers/staging/iio/adc/adt7310.c | 951 +++++++++++++++++++++++++++++++++++++ 3 files changed, 959 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/iio/adc/adt7310.c
drivers/staging/iio/adc/Kconfig +7 -0
@@ -107,3 +107,10 @@ config ADT75 help Say yes here to build support for Analog Devices ADT75 temperature sensors. + +config ADT7408 + tristate "Analog Devices ADT7408 temperature sensor driver" + depends on I2C + help + Say yes here to build support for Analog Devices ADT7408 + temperature sensors.
drivers/staging/iio/adc/Makefile +1 -0
@@ -20,3 +20,4 @@ obj-$(CONFIG_AD7476) += ad7476.o obj-$(CONFIG_AD774X) += ad774x.o obj-$(CONFIG_AD7816) += ad7816.o obj-$(CONFIG_ADT75) += adt75.o +obj-$(CONFIG_ADT7310) += adt7310.o
drivers/staging/iio/adc/adt7310.c new file +951 -0
951 lines not on this page · raw message
Signature · 1 line
1.7.3.2
PATCH 12/14 staging: iio: adc: new driver for ADT7408 temperature sensors
In reply to Mike FrysingerFrom: Sonic Zhang <[email protected]>
--- drivers/staging/iio/adc/Kconfig | 7 + drivers/staging/iio/adc/Makefile | 1 + drivers/staging/iio/adc/adt7408.c | 1006 +++++++++++++++++++++++++++++++++++++ 3 files changed, 1014 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/iio/adc/adt7408.c
drivers/staging/iio/adc/Kconfig +7 -0
@@ -114,3 +114,10 @@ config ADT7408 help Say yes here to build support for Analog Devices ADT7408 temperature sensors. + +config ADT7410 + tristate "Analog Devices ADT7410 temperature sensor driver" + depends on I2C + help + Say yes here to build support for Analog Devices ADT7410 + temperature sensors.
drivers/staging/iio/adc/Makefile +1 -0
@@ -21,3 +21,4 @@ obj-$(CONFIG_AD774X) += ad774x.o obj-$(CONFIG_AD7816) += ad7816.o obj-$(CONFIG_ADT75) += adt75.o obj-$(CONFIG_ADT7310) += adt7310.o +obj-$(CONFIG_ADT7408) += adt7408.o
drivers/staging/iio/adc/adt7408.c new file +1006 -0
1,006 lines not on this page · raw message
Signature · 1 line
1.7.3.2
Re: [PATCH 12/14] staging: iio: adc: new driver for ADT7408 temperature sensors
Quoted 1 line · Mike Frysinger
From: Sonic Zhang <[email protected]>
Here we enter new territory. This device is already supported in hwmon. Do we have a usecase that is not covered by that driver?
If this is only for hardware monitoring by Guenter (cc'd) can perhaps advise on how to support everything you have here...
I'm personally not against having drivers in IIO for devices supported elsewhere, but the requirements for justification are rather higher. Also care is needed to ensure no issues with platform data etc.
Guenter, for your information we have a set of temp drivers coming, as a small element of a larger set, from Analog's tree. Those I've reviewed so far have wanted to use IIO's event infrastructure (which is much more general than hwmon's handling of alarms) or have been suitably high performance devices with general adc's to satisfy me that they clearly have uses beyond hardware monitoring.
Quoted 1,046 lines
Signed-off-by Sonic Zhang <[email protected]>Signed-off-by Mike Frysinger <[email protected]>--- drivers/staging/iio/adc/Kconfig | 7 + drivers/staging/iio/adc/Makefile | 1 + drivers/staging/iio/adc/adt7408.c | 1006 +++++++++++++++++++++++++++++++++++++ 3 files changed, 1014 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/iio/adc/adt7408.cdrivers/staging/iio/adc/Kconfig +7
-0@@ -114,3 +114,10 @@ config ADT7408 help Say yes here to build support for Analog Devices ADT7408 temperature sensors. + +config ADT7410 + tristate "Analog Devices ADT7410 temperature sensor driver" + depends on I2C + help + Say yes here to build support for Analog Devices ADT7410 + temperature sensors.drivers/staging/iio/adc/Makefile +1
-0@@ -21,3 +21,4 @@ obj-$(CONFIG_AD774X) += ad774x.o obj-$(CONFIG_AD7816) += ad7816.o obj-$(CONFIG_ADT75) += adt75.o obj-$(CONFIG_ADT7310) += adt7310.o +obj-$(CONFIG_ADT7408) += adt7408.odrivers/staging/iio/adc/adt7408.c new file +1006
-0@@ -0,0 +1,1006 @@ +/* +* ADT7408 digital temperature sensor driver supporting ADT7408 +* +* Copyright 2010 Analog Devices Inc. +* +* Licensed under the GPL-2 or later. +*/ + +#include <linux/interrupt.h> +#include <linux/gpio.h> +#include <linux/workqueue.h> +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/sysfs.h> +#include <linux/list.h> +#include <linux/i2c.h> +#include <linux/rtc.h> + +#include "../iio.h" +#include "../sysfs.h" + +/* +* ADT7408 registers definition +*/ + +#define ADT7408_CAPABILITY 0 +#define ADT7408_CONFIG 1 +#define ADT7408_T_ALARM_HIGH 2 +#define ADT7408_T_ALARM_LOW 3 +#define ADT7408_T_CRIT 4 +#define ADT7408_TEMPERATURE 5 +#define ADT7408_MANUFACTURER_ID 6 +#define ADT7408_DEVICE_ID 7 + +/* +* ADT7408 capability +*/ +#define ADT7408_CAP_ALARM_CRIT_TRIPS 0x1 +#define ADT7408_CAP_HIGH_PRECISION 0x2 +#define ADT7408_CAP_WIDER_RANGE 0x4 +#define ADT7408_CAP_T_RESOLUTION_MASK 0x18 +#define ADT7408_CAP_T_RESOLUTION_HIGH 0x18 +#define ADT7408_CAP_T_RESOLUTION_LOW 0x8 + +/* +* ADT7408 config +*/ +#define ADT7408_EVENT_MODE 0x1 +#define ADT7408_EVENT_POLARITY 0x2 +#define ADT7408_EVENT_CRIT_ONLY 0x4 +#define ADT7408_EVENT_ENABLE 0x8 +#define ADT7408_EVENT_STATUS 0x10 +#define ADT7408_EVENT_CLEAR 0x20 +#define ADT7408_EVENT_ALARM_LOCK 0x40 +#define ADT7408_EVENT_CRIT_LOCK 0x80 +#define ADT7408_PD 0x100 +#define ADT7408_HISTERESIS_MASK 0x600 +#define ADT7408_HISTERESIS_1_5 0x200 +#define ADT7408_HISTERESIS_3 0x400 +#define ADT7408_HISTERESIS_6 0x600 + +/* +* ADT7408 masks +*/ +#define ADT7408_BOUND_VALUE_SIGN 0x400 +#define ADT7408_BOUND_VALUE_OFFSET 2 +#define ADT7408_BOUND_VALUE_FLOAT_OFFSET 2 +#define ADT7408_BOUND_VALUE_FLOAT_MASK 0x3 +#define ADT7408_T_VALUE_SIGN 0x1000 +#define ADT7408_T_VALUE_FLOAT_OFFSET 4 +#define ADT7408_T_VALUE_FLOAT_MASK 0xF + +/* +* ADT7408 event source +*/ +#define ADT7408_T_BELLOW_ALARM 0x2000 +#define ADT7408_T_ABOVE_ALARM 0x4000 +#define ADT7408_T_ABOVE_CRIT 0x8000 + + +/* +* struct adt7408_chip_info - chip specifc information +*/ + +struct adt7408_chip_info { +const char *name; +struct i2c_client *client; +struct iio_dev *indio_dev; +struct work_struct thresh_work; +s64 last_timestamp; +u16 config; +}; + +/* +* adt7408 register access by I2C +*/ + +static int adt7408_i2c_read (struct adt7408_chip_info *chip,u8 reg,u16 *data) +{ +struct i2c_client *client = chip->client; +int ret =0 ; + + ret =i2c_smbus_read_word_data (client, reg); +if (ret <0 ) { +dev_err (&client->dev,"I2C read error\n" ); +return ret; + } + + *data =swab16 ((u16 )ret); + +return 0 ; +} + +static int adt7408_i2c_write (struct adt7408_chip_info *chip,u8 reg,u16 data) +{ +struct i2c_client *client = chip->client; +int ret =0 ; + + ret =i2c_smbus_write_word_data (client, reg,swab16 (data)); +if (ret <0 ) +dev_err (&client->dev,"I2C write error\n" ); + +return ret; +} + +static int adt7408_is_event_locked (struct adt7408_chip_info *chip) +{ +return chip->config & (ADT7408_EVENT_ALARM_LOCK |ADT7408_EVENT_ALARM_LOCK ); +} + +static ssize_t adt7408_show_mode (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; + +if (chip->config &ADT7408_PD ) +return sprintf (buf,"power-save\n" ); +else +return sprintf (buf,"full\n" ); +} + +static ssize_t adt7408_store_mode (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +u16 config; +int ret; + +if (adt7408_is_event_locked (chip)) { +dev_err (dev,"Warning: Events are locked.\n" ); +return -EIO ; + } + + ret =adt7408_i2c_read (chip,ADT7408_CONFIG , &chip->config); +if (ret) +return -EIO ; + + config = chip->config & (~ADT7408_PD ); +if (!strcmp (buf,"full" )) + config |=ADT7408_PD ; + + ret =adt7408_i2c_write (chip,ADT7408_CONFIG , config); +if (ret) +return -EIO ; + + chip->config = config; + +return ret; +} + +static IIO_DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, + adt7408_show_mode, + adt7408_store_mode, + 0); + +static ssize_t adt7408_show_available_modes (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return sprintf (buf,"full\npower-down\n" ); +} + +static IIO_DEVICE_ATTR(available_modes, S_IRUGO, adt7408_show_available_modes, NULL, 0); + +static ssize_t adt7408_show_capability (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +u16 capability; +int ret; + + ret =adt7408_i2c_read (chip,ADT7408_CAPABILITY , &capability); +if (ret) +return -EIO ; + +return sprintf (buf,"0x%x\n" , capability); +} + +static IIO_DEVICE_ATTR(capability, S_IRUGO | S_IWUSR, + adt7408_show_capability, + NULL, + 0); + +static ssize_t adt7408_show_manufactory_id (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +u16 id; +int ret; + + ret =adt7408_i2c_read (chip,ADT7408_MANUFACTURER_ID , &id); +if (ret) +return -EIO ; + +return sprintf (buf,"0x%x\n" , id); +} + +static IIO_DEVICE_ATTR(manufactory_id, S_IRUGO | S_IWUSR, + adt7408_show_manufactory_id, + NULL, + 0); + +static ssize_t adt7408_show_device_id (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +u16 id; +int ret; + + ret =adt7408_i2c_read (chip,ADT7408_MANUFACTURER_ID , &id); +if (ret) +return -EIO ; + +return sprintf (buf,"0x%x\n" , id); +} + +static IIO_DEVICE_ATTR(device_id, S_IRUGO | S_IWUSR, + adt7408_show_device_id, + NULL, + 0); + +static ssize_t adt7408_show_value (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +u16 data; +char sign =' ' ; +int ret; + +if (chip->config &ADT7408_PD ) { +dev_err (dev,"Can't read value in power-down mode.\n" ); +return -EIO ; + } + + ret =adt7408_i2c_read (chip,ADT7408_TEMPERATURE , &data); +if (ret) +return -EIO ; + +if (data &ADT7408_T_VALUE_SIGN ) { +/* convert supplement to positive value */ + data = (ADT7408_T_VALUE_SIGN <<1 ) - data; + sign ='-' ; + } + +return sprintf (buf,"%c%d.%.4d\n" , sign, + (data >>ADT7408_T_VALUE_FLOAT_OFFSET ), + (data &ADT7408_T_VALUE_FLOAT_MASK ) *625 ); +} + +static IIO_DEVICE_ATTR(value, S_IRUGO, adt7408_show_value, NULL, 0); + +static ssize_t adt7408_show_name (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +return sprintf (buf,"%s\n" , chip->name); +} + +static IIO_DEVICE_ATTR(name, S_IRUGO, adt7408_show_name, NULL, 0); + +static struct attribute *adt7408_attributes[] = { + &iio_dev_attr_available_modes.dev_attr.attr, + &iio_dev_attr_mode.dev_attr.attr, + &iio_dev_attr_capability.dev_attr.attr, + &iio_dev_attr_device_id.dev_attr.attr, + &iio_dev_attr_manufactory_id.dev_attr.attr, + &iio_dev_attr_value.dev_attr.attr, + &iio_dev_attr_name.dev_attr.attr, +NULL , +}; + +static const struct attribute_group adt7408_attribute_group = { + .attrs = adt7408_attributes, +}; + +/* +* temperature bound events +*/ + +#define IIO_EVENT_CODE_ADT7408_ABOVE_ALARM (IIO_EVENT_CODE_DEVICE_SPECIFIC + 1) +#define IIO_EVENT_CODE_ADT7408_BELLOW_ALARM (IIO_EVENT_CODE_DEVICE_SPECIFIC + 2) +#define IIO_EVENT_CODE_ADT7408_ABOVE_CRIT (IIO_EVENT_CODE_DEVICE_SPECIFIC + 3) + +static void adt7408_interrupt_bh (struct work_struct *work_s) +{ +struct adt7408_chip_info *chip = + container_of(work_s, struct adt7408_chip_info, thresh_work); +u16 config; +u16 data; + +if (adt7408_i2c_read (chip,ADT7408_CONFIG , &chip->config)) +return ; + +if (!(chip->config &ADT7408_EVENT_STATUS )) +return ; + + config = chip->config & ~ADT7408_EVENT_CLEAR ; +if (data) + config |=ADT7408_EVENT_CLEAR ; + +adt7408_i2c_write (chip,ADT7408_CONFIG , config); + +if (adt7408_i2c_read (chip,ADT7408_TEMPERATURE , &data)) + goto exit; + +if (data &ADT7408_T_ABOVE_ALARM ) +iio_push_event (chip->indio_dev,0 , +IIO_EVENT_CODE_ADT7408_ABOVE_ALARM , + chip->last_timestamp); +if (data &ADT7408_T_BELLOW_ALARM ) +iio_push_event (chip->indio_dev,0 , +IIO_EVENT_CODE_ADT7408_BELLOW_ALARM , + chip->last_timestamp); +if (data &ADT7408_T_ABOVE_CRIT ) +iio_push_event (chip->indio_dev,0 , +IIO_EVENT_CODE_ADT7408_ABOVE_CRIT , + chip->last_timestamp); +exit: +enable_irq (chip->client->irq); +} + +static int adt7408_interrupt (struct iio_dev *dev_info, +int index, +s64 timestamp, +int no_test) +{ +struct adt7408_chip_info *chip = dev_info->dev_data; + + chip->last_timestamp = timestamp; +schedule_work (&chip->thresh_work); + +return 0 ; +} + +IIO_EVENT_SH (adt7408, &adt7408_interrupt); + +static ssize_t adt7408_show_event_mode (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +int ret; + + ret =adt7408_i2c_read (chip,ADT7408_CONFIG , &chip->config); +if (ret) +return -EIO ; + +if (chip->config &ADT7408_EVENT_MODE ) +return sprintf (buf,"interrupt\n" ); +else +return sprintf (buf,"comparator\n" ); +} + +static ssize_t adt7408_set_event_mode (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +u16 config; +int ret; + +if (adt7408_is_event_locked (chip)) { +dev_err (dev,"Warning: Events are locked.\n" ); +return -EIO ; + } + + ret =adt7408_i2c_read (chip,ADT7408_CONFIG , &chip->config); +if (ret) +return -EIO ; + + config = chip->config &= ~ADT7408_EVENT_MODE ; +if (strcmp (buf,"comparator" ) !=0 ) + config |=ADT7408_EVENT_MODE ; + + ret =adt7408_i2c_write (chip,ADT7408_CONFIG , config); +if (ret) +return -EIO ; + + chip->config = config; + +return ret; +} + +static ssize_t adt7408_show_available_event_modes (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return sprintf (buf,"comparator\ninterrupt\n" ); +} + +static ssize_t adt7408_show_event_crit_only (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +int ret; + + ret =adt7408_i2c_read (chip,ADT7408_CONFIG , &chip->config); +if (ret) +return -EIO ; + +return sprintf (buf,"%d\n" , !!(chip->config &ADT7408_EVENT_CRIT_ONLY )); +} + +static ssize_t adt7408_set_event_crit_only (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +unsigned long data =0 ; +u16 config; +int ret; + +if (adt7408_is_event_locked (chip)) { +dev_err (dev,"Warning: Events are locked.\n" ); +return -EIO ; + } + + ret =strict_strtoul (buf,10 , &data); +if (ret) +return -EINVAL ; + + ret =adt7408_i2c_read (chip,ADT7408_CONFIG , &chip->config); +if (ret) +return -EIO ; + + config = chip->config &= ~ADT7408_EVENT_CRIT_ONLY ; +if (data) + config |=ADT7408_EVENT_CRIT_ONLY ; + + ret =adt7408_i2c_write (chip,ADT7408_CONFIG , config); +if (ret) +return -EIO ; + + chip->config = config; + +return ret; +} + +static ssize_t adt7408_show_event_enable (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +int ret; + + ret =adt7408_i2c_read (chip,ADT7408_CONFIG , &chip->config); +if (ret) +return -EIO ; + +return sprintf (buf,"%d\n" , !!(chip->config &ADT7408_EVENT_ENABLE )); +} + +static ssize_t adt7408_set_event_enable (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +unsigned long data; +u16 config; +int ret; + +if (adt7408_is_event_locked (chip)) { +dev_err (dev,"Warning: Events are locked.\n" ); +return -EIO ; + } + + ret =strict_strtoul (buf,10 , &data); +if (ret) +return -EINVAL ; + + ret =adt7408_i2c_read (chip,ADT7408_CONFIG , &chip->config); +if (ret) +return -EIO ; + + config = chip->config & ~ADT7408_EVENT_ENABLE ; +if (data) + config |=ADT7408_EVENT_ENABLE ; + + ret =adt7408_i2c_write (chip,ADT7408_CONFIG , config); +if (ret) +return -EIO ; + + chip->config = config; + +return ret; +} + +static ssize_t adt7408_show_alarm_lock (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +int ret; + + ret =adt7408_i2c_read (chip,ADT7408_CONFIG , &chip->config); +if (ret) +return -EIO ; + +return sprintf (buf,"%d\n" , !!(chip->config &ADT7408_EVENT_ALARM_LOCK )); +} + +static ssize_t adt7408_set_alarm_lock (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +unsigned long data; +u16 config; +int ret; + + ret =strict_strtoul (buf,10 , &data); +if (ret) +return -EINVAL ; + + ret =adt7408_i2c_read (chip,ADT7408_CONFIG , &chip->config); +if (ret) +return -EIO ; + + config = chip->config & ~ADT7408_EVENT_ALARM_LOCK ; +if (data) + config |=ADT7408_EVENT_ALARM_LOCK ; + + ret =adt7408_i2c_write (chip,ADT7408_CONFIG , config); +if (ret) +return -EIO ; + + chip->config = config; + +return ret; +} + +static ssize_t adt7408_show_crit_lock (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +int ret; + + ret =adt7408_i2c_read (chip,ADT7408_CONFIG , &chip->config); +if (ret) +return -EIO ; + +return sprintf (buf,"%d\n" , !!(chip->config &ADT7408_EVENT_CRIT_LOCK )); +} + +static ssize_t adt7408_set_crit_lock (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +unsigned long data; +u16 config; +int ret; + + ret =strict_strtoul (buf,10 , &data); +if (ret) +return -EINVAL ; + + ret =adt7408_i2c_read (chip,ADT7408_CONFIG , &chip->config); +if (ret) +return -EIO ; + + config = chip->config & ~ADT7408_EVENT_CRIT_LOCK ; +if (data) + config |=ADT7408_EVENT_CRIT_LOCK ; + + ret =adt7408_i2c_write (chip,ADT7408_CONFIG , config); +if (ret) +return -EIO ; + + chip->config = config; + +return ret; +} + + +static inline ssize_t adt7408_show_t_bound (struct device *dev, +struct device_attribute *attr, +u8 bound_reg, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +u16 data; +char sign =' ' ; +int ret; + + ret =adt7408_i2c_read (chip, bound_reg, &data); +if (ret) +return -EIO ; + + data >>=ADT7408_BOUND_VALUE_OFFSET ; +if (data &ADT7408_BOUND_VALUE_SIGN ) { +/* convert supplement to positive value */ + data = (ADT7408_BOUND_VALUE_SIGN <<1 ) - data; + sign ='-' ; + } + +return sprintf (buf,"%c%d.%.2d\n" , sign, + data >>ADT7408_BOUND_VALUE_FLOAT_OFFSET , + (data &ADT7408_BOUND_VALUE_FLOAT_MASK ) *25 ); +} + +static inline ssize_t adt7408_set_t_bound (struct device *dev, +struct device_attribute *attr, +u8 bound_reg, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +long tmp1, tmp2; +u16 data; +char *pos; +int ret; + + pos =strchr (buf,'.' ); + + ret =strict_strtol (buf,10 , &tmp1); + +if (ret || tmp1 >127 || tmp1 <-128 ) +return -EINVAL ; + +if (pos) { + len =strlen (pos); +if (len >ADT7408_BOUND_VALUE_FLOAT_OFFSET ) + len =ADT7408_BOUND_VALUE_FLOAT_OFFSET ; + pos[len] =0 ; + ret =strict_strtol (pos,10 , &tmp2); + +if (!ret) + tmp2 = (tmp2 /25 ) *25 ; + } + +if (tmp1 <0 ) + data = (u16)(-tmp1); +else + data = (u16 )tmp1; + data = (data <<ADT7408_BOUND_VALUE_FLOAT_OFFSET ) | + (tmp2 &ADT7408_BOUND_VALUE_FLOAT_MASK ); +if (tmp1 <0 ) +/* convert positive value to supplyment */ + data = (ADT7408_BOUND_VALUE_SIGN <<1 ) - data; + data <<=ADT7408_BOUND_VALUE_OFFSET ; + + ret =adt7408_i2c_write (chip, bound_reg, data); +if (ret) +return -EIO ; + +return ret; +} + +static ssize_t adt7408_show_t_alarm_high (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return adt7408_show_t_bound (dev, attr, +ADT7408_T_ALARM_HIGH , buf); +} + +static inline ssize_t adt7408_set_t_alarm_high (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +return adt7408_set_t_bound (dev, attr, +ADT7408_T_ALARM_HIGH , buf, len); +} + +static ssize_t adt7408_show_t_alarm_low (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return adt7408_show_t_bound (dev, attr, +ADT7408_T_ALARM_LOW , buf); +} + +static inline ssize_t adt7408_set_t_alarm_low (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +return adt7408_set_t_bound (dev, attr, +ADT7408_T_ALARM_LOW , buf, len); +} + +static ssize_t adt7408_show_t_crit (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return adt7408_show_t_bound (dev, attr, +ADT7408_T_CRIT , buf); +} + +static inline ssize_t adt7408_set_t_crit (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +return adt7408_set_t_bound (dev, attr, +ADT7408_T_CRIT , buf, len); +} + +static ssize_t adt7408_show_t_hyst (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +int ret; + +/* retrive ALART status */ + ret =adt7408_i2c_read (chip,ADT7408_CONFIG , &chip->config); +if (ret) +return -EIO ; + +switch (chip->config &ADT7408_HISTERESIS_MASK ) { +case ADT7408_HISTERESIS_1_5 : +return sprintf (buf,"1.5\n" ); +case ADT7408_HISTERESIS_3 : +return sprintf (buf,"3\n" ); +case ADT7408_HISTERESIS_6 : +return sprintf (buf,"6\n" ); +default : +return sprintf (buf,"Disabled\n" ); + } +} + +static inline ssize_t adt7408_set_t_hyst (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +int ret; +u16 config =0 ; + +if (strcmp (buf,"disble" )) + config =ADT7408_HISTERESIS_MASK ; +else if (strcmp (buf,"1.5" )) + config =ADT7408_HISTERESIS_1_5 ; +else if (len >1 && buf[0 ] =='3' ) + config =ADT7408_HISTERESIS_6 ; +else if (len >1 && buf[0 ] =='6' ) + config =ADT7408_HISTERESIS_6 ; + +if (!config) +return -EINVAL ; + +/* retrive ALART status */ + ret =adt7408_i2c_read (chip,ADT7408_CONFIG , &chip->config); +if (ret) +return -EIO ; + + config |= chip->config & ~ADT7408_HISTERESIS_MASK ; + + ret =adt7408_i2c_write (chip,ADT7408_CONFIG , config); +if (ret) +return -EIO ; + + chip->config = config; +return ret; +} + +static ssize_t adt7408_show_available_t_hyst (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return sprintf (buf,"1.5\n3\n6\ndisable\n" ); +} + +IIO_EVENT_ATTR_SH (event_mode, iio_event_adt7408, + adt7408_show_event_mode, adt7408_set_event_mode,0 ); +IIO_EVENT_ATTR_SH (available_event_modes, iio_event_adt7408, + adt7408_show_available_event_modes,NULL ,0 ); +IIO_EVENT_ATTR_SH (event_crit_only, iio_event_adt7408, + adt7408_show_event_crit_only, adt7408_set_event_crit_only,0 ); +IIO_EVENT_ATTR_SH (event_enable, iio_event_adt7408, + adt7408_show_event_enable, adt7408_set_event_enable,0 ); +IIO_EVENT_ATTR_SH (alarm_lock, iio_event_adt7408, + adt7408_show_alarm_lock, adt7408_set_alarm_lock,0 ); +IIO_EVENT_ATTR_SH (crit_lock, iio_event_adt7408, + adt7408_show_crit_lock, adt7408_set_crit_lock,0 ); +IIO_EVENT_ATTR_SH (t_alarm_high, iio_event_adt7408, + adt7408_show_t_alarm_high, adt7408_set_t_alarm_high,0 ); +IIO_EVENT_ATTR_SH (t_alarm_low, iio_event_adt7408, + adt7408_show_t_alarm_low, adt7408_set_t_alarm_low,0 ); +IIO_EVENT_ATTR_SH (t_crit, iio_event_adt7408, + adt7408_show_t_crit, adt7408_set_t_crit,0 ); +IIO_EVENT_ATTR_SH (t_hyst, iio_event_adt7408, + adt7408_show_t_hyst, adt7408_set_t_hyst,0 ); +IIO_EVENT_ATTR_SH (available_t_hyst, iio_event_adt7408, + adt7408_show_available_t_hyst,NULL ,0 ); + +static struct attribute *adt7408_event_attributes[] = { + &iio_event_attr_event_mode.dev_attr.attr, + &iio_event_attr_available_event_modes.dev_attr.attr, + &iio_event_attr_event_crit_only.dev_attr.attr, + &iio_event_attr_event_enable.dev_attr.attr, + &iio_event_attr_alarm_lock.dev_attr.attr, + &iio_event_attr_crit_lock.dev_attr.attr, + &iio_event_attr_t_alarm_high.dev_attr.attr, + &iio_event_attr_t_alarm_low.dev_attr.attr, + &iio_event_attr_t_crit.dev_attr.attr, + &iio_event_attr_t_hyst.dev_attr.attr, + &iio_event_attr_available_t_hyst.dev_attr.attr, +NULL , +}; + +static struct attribute_group adt7408_event_attribute_group = { + .attrs = adt7408_event_attributes, +}; + +/* +* device probe and remove +*/ + +static int __devinit adt7408_probe (struct i2c_client *client, +const struct i2c_device_id *id) +{ +struct adt7408_chip_info *chip; +int ret =0 ; + + chip =kzalloc (sizeof (struct adt7408_chip_info ),GFP_KERNEL ); + +if (chip ==NULL ) +return -ENOMEM ; + +/* this is only used for device removal purposes */ +i2c_set_clientdata (client, chip); + + chip->client = client; + chip->name = id->name; + + chip->indio_dev =iio_allocate_device (); +if (chip->indio_dev ==NULL ) { + ret = -ENOMEM ; + goto error_free_chip; + } + + chip->indio_dev->dev.parent = &client->dev; + chip->indio_dev->attrs = &adt7408_attribute_group; + chip->indio_dev->event_attrs = &adt7408_event_attribute_group; + chip->indio_dev->dev_data = (void *)chip; + chip->indio_dev->driver_module =THIS_MODULE ; + chip->indio_dev->num_interrupt_lines =1 ; + chip->indio_dev->modes =INDIO_DIRECT_MODE ; + + ret =iio_device_register (chip->indio_dev); +if (ret) + goto error_free_dev; + +if (client->irq) { + ret =iio_register_interrupt_line (client->irq, + chip->indio_dev, +0 , + client->irq_flags, + chip->name); +if (ret) + goto error_unreg_dev; + +/* +* The event handler list element refer to iio_event_adt7408. +* All event attributes bind to the same event handler. +* So, only register event handler once. +*/ +iio_add_event_to_list (&iio_event_adt7408, + &chip->indio_dev->interrupts[0 ]->ev_list); + +INIT_WORK (&chip->thresh_work, adt7408_interrupt_bh); + + ret =adt7408_i2c_read (chip,ADT7408_CONFIG , &chip->config); +if (ret) { + ret = -EIO ; + goto error_unreg_irq; + } + +if (client->irq_flags &IRQF_TRIGGER_HIGH ) + chip->config |=ADT7408_EVENT_POLARITY ; +else + chip->config &= ~ADT7408_EVENT_POLARITY ; + + ret =adt7408_i2c_write (chip,ADT7408_CONFIG , chip->config); +if (ret) { + ret = -EIO ; + goto error_unreg_irq; + } + } + +dev_info (&client->dev,"%s temperature sensor registered.\n" , + id->name); + +return 0 ; + +error_unreg_irq: +iio_unregister_interrupt_line (chip->indio_dev,0 ); +error_unreg_dev: +iio_device_unregister (chip->indio_dev); +error_free_dev: +iio_free_device (chip->indio_dev); +error_free_chip: +kfree (chip); + +return ret; +} + +static int __devexit adt7408_remove(struct i2c_client *client) +{ +struct adt7408_chip_info *chip =i2c_get_clientdata (client); +struct iio_dev *indio_dev = chip->indio_dev; + +if (client->irq) +iio_unregister_interrupt_line (indio_dev,0 ); +iio_device_unregister (indio_dev); +iio_free_device (chip->indio_dev); +kfree (chip); + +return 0 ; +} + +static const struct i2c_device_id adt7408_id[] = { + {"adt7408" ,0 }, + {} +}; + +MODULE_DEVICE_TABLE (i2c, adt7408_id); + +static struct i2c_driver adt7408_driver = { + .driver = { + .name ="adt7408" , + }, + .probe = adt7408_probe, + .remove =__devexit_p (adt7408_remove), + .id_table = adt7408_id, +}; + +static __init int adt7408_init (void ) +{ +return i2c_add_driver (&adt7408_driver); +} + +static __exit void adt7408_exit(void) +{ +i2c_del_driver (&adt7408_driver); +} + +MODULE_AUTHOR ("Sonic Zhang <[email protected]>" ); +MODULE_DESCRIPTION ("Analog Devices ADT7408 digital" +" temperature sensor driver" ); +MODULE_LICENSE ("GPL v2" ); + +module_init (adt7408_init); +module_exit (adt7408_exit);
Re: [PATCH 12/14] staging: iio: adc: new driver for ADT7408 temperature sensors
Quoted 9 lines · Jonathan Cameron
Quoted 1 line · Mike Frysinger
From: Sonic Zhang <[email protected]>
Here we enter new territory. This device is already supported in hwmon. Do we have a usecase that is not covered by that driver?
If this is only for hardware monitoring by Guenter (cc'd) can perhaps advise on how to support everything you have here...
device_id and manufactory_id (shouldn't that be manufacturer_id ?) don't provide much value since they are (or could be) already part of the device name.
"capability" reflects a raw register value. I would be opposed to any attribute like that, since it does not mean anything beyond the driver for that specific chip. The data it provides might make sense in the driver documentation, but what is anyone supposed to do with the returned hex value ? That kind of ABI really does not make any sense. If the reported values are really valuable enough to be reported, a real abi (eg tempX_accuracy and tempX_resolution) would be much better.
For "power-save" (or "power-down" ?) and "full" mode I am not sure why suspend/resume isn't used instead. Is that some new upcoming ABI ?
Quoted 5 lines
I'm personally not against having drivers in IIO for devices supported elsewhere, but the requirements for justification are rather higher. Also care is needed to ensure no issues with platform data etc.
Quoted 8 lines
Guenter, for your information we have a set of temp drivers coming, as a small element of a larger set, from Analog's tree. Those I've reviewed so far have wanted to use IIO's event infrastructure (which is much more general than hwmon's handling of alarms) or have been suitably high performance devices with general adc's to satisfy me that they clearly have uses beyond hardware monitoring.
There should be a generic part and a specific part for such generic devices. The generic part can be in mfd or somewhere suitable (such as iio), but the hwmon part should reside in hwmon.
The worst thing to do would be to duplicate functionality as it is proposed here. That can only create chaos.
If the event mechanism in hwmon is deemed insufficient enough to cause drivers to move elsewhere, maybe event mechanism in hwmon should be improved instead. Or, even better, if there is a really need for a more detailed / improved event mechanism, there should be a single event subsystem that works for both iio and hwmon.
In short, if the hwmon ABI is deemed to be insufficient to support today's devices, for whaever reason, it needs to get fixed. Moving hwmon drivers elsewhere to avoid its perceived (or real) limitations should be an absolute no.
Guenter
Re: [PATCH 12/14] staging: iio: adc: new driver for ADT7408 temperature sensors
Quoted 7 lines · Guenter Roeck
Quoted 6 lines · Jonathan Cameron
Quoted 1 line · Mike Frysinger
From: Sonic Zhang <[email protected]>
Here we enter new territory. This device is already supported in hwmon. Do we have a usecase that is not covered by that driver?
Quoted 6 lines
Quoted 3 lines
If this is only for hardware monitoring by Guenter (cc'd) can perhaps advise on how to support everything you have here...
device_idandmanufactory_id(shouldn't that bemanufacturer_id?) don't provide much value since they are (or could be) already part of the device name.
Agreed, they'll get dropped whatever happens to this driver. It's far from clean as it currently stands.
Quoted 3 lines
"capability" reflects a raw register value. I would be opposed to any attribute like that, since it does not mean anything beyond the driver for that specific chip.
Agreed, that's certainly not staying there as is. The intent is to merge this series (36 drivers in all) into staging and clean up there. Analog have given commitments that they will put the man power on it.
Quoted 7 lines
The data it provides might make sense in the driver documentation, but what is anyone supposed to do with the returned hex value ? That kind of ABI really does not make any sense. If the reported values are really valuable enough to be reported, a real abi (eg
tempX_accuracyandtempX_resolution) would be much better.For "power-save" (or "power-down" ?) and "full" mode I am not sure why suspend/resume isn't used instead. Is that some new upcoming ABI ?
Nope, it's a dirty hack instead of using the runtime pm (which to be fair is still in relatively early days) It'll go in the clean up (as for that matter will any 'mode' type attributes as they never standardize well.).
Quoted 14 lines
Quoted 6 lines
I'm personally not against having drivers in IIO for devices supported elsewhere, but the requirements for justification are rather higher. Also care is needed to ensure no issues with platform data etc.
Quoted 8 lines
Guenter, for your information we have a set of temp drivers coming, as a small element of a larger set, from Analog's tree. Those I've reviewed so far have wanted to use IIO's event infrastructure (which is much more general than hwmon's handling of alarms) or have been suitably high performance devices with general adc's to satisfy me that they clearly have uses beyond hardware monitoring.
Quoted 3 lines
There should be a generic part and a specific part for such generic devices. The generic part can be in mfd or somewhere suitable (such as iio), but the hwmon part should reside in hwmon.
Tricky to agree on the divide. Note we do match your interfaces anyway (where they exist). The only exception to this is your alarm interfaces which are way too restrictive (as one would expect they only cover cases that make sense for hardware monitoring!)
We have numerous devices (including accelerometers, which you are quite rightly trying to get out of hwmon) that have a voltage supply monitor channel. It might seem obvious that we should add a hwmon element to this but the value is only of interest alongside the measurements from gyroscopes etc. Typically it will be captured and buffered at a couple of Khz which really doesn't make it fit into the scope of hwmon. Anyone who uses $400 of IMU as their voltage monitor gets to deal with the consequences.
Quoted 3 lines
The worst thing to do would be to duplicate functionality as it is proposed here. That can only create chaos.
It's an interesting boundary for what should go where and as per the discussions about accelerometers going into input, I think it has to be decided based on what people are using the device for.
Quoted 3 lines
If the event mechanism in hwmon is deemed insufficient enough to cause drivers to move elsewhere, maybe event mechanism in hwmon should be improved instead.
This comes back to the reason IIO started in the first place.
hwmon is for hardware monitoring and hence has a different set of requirements from generic sensing. Basically you want to do things slowly. There is no earthly point in monitoring at 1MHz. The problem lies in chips that sit on the edge. There are plenty of high end ADCs running at 1Hz or less to track some battery voltage or similar. If that's what they are used for then I agree they should be in hwmon. If you want to do high speed capture or fast event capture then it is a non starter. There is a reason IIO is a whole lot more complex than hwmon. Requirements demand it.
Quoted 3 lines
Or, even better, if there is a really need for a more detailed / improved event mechanism, there should be a single event subsystem that works for both iio and hwmon.
That's the equivalent of Linus' argument that all devices should use input's event subsystem. It's massive overkill unless you want sophisticated amalgamation and filtering of the incoming event stream. Also input are worried about bloat in their event structures so are very much against adding anything that isn't a true human input device. There may be some scope for sharing at some level but I don't think the whole event mechanism can realistically be shared. The requirements are simply too different. For reference the way we handle the conversion from IIO events (which are more specific and streamlined than input ones - their events include standard data, for reasons of overhead our data goes a different route) for the odd device that sits at the boundary of IIO and input is a userspace loopback tool via uinput (proof of concept only at this stage).
Quoted 4 lines
In short, if the hwmon ABI is deemed to be insufficient to support today's devices, for whaever reason, it needs to get fixed. Moving hwmon drivers elsewhere to avoid its perceived (or real) limitations should be an absolute no.
I agree. The issue here is where we draw the divide. I am very dubious about this particular driver going in IIO simply because it doesn't seem to need any of the stuff that we exist for. Others are far less clear.
Jonathan
Quoted 2 lines
Guenter
RE: [PATCH 12/14] staging: iio: adc: new driver for ADT7408 temperature sensors
In reply to Guenter RoeckQuoted 26 lines
-----Original Message-----
From: Guenter Roeck [mailto:[email protected]]
Sent: Monday, October 25, 2010 7:48 AM
To: Jonathan Cameron
Cc: Mike Frysinger; [email protected]; [email protected]; Zhang, Sonic
Subject: Re: [PATCH 12/14] staging: iio: adc: new driver for ADT7408 temperature sensorsQuoted 6 lines · Jonathan Cameron
Quoted 1 line · Mike Frysinger
From: Sonic Zhang <[email protected]>
Here we enter new territory. This device is already supported in hwmon. Do we have a usecase that is not covered by that driver?
If this is only for hardware monitoring by Guenter (cc'd)
can perhaps
Quoted 2 lines
advise on how to support everything you have here...
device_idandmanufactory_id(shouldn't that bemanufacturer_id?) don't provide much value since they are (or could be) already part of the device name.
Quoted 9 lines
"capability" reflects a raw register value. I would be opposed to any attribute like that, since it does not mean anything beyond the driver for that specific chip.
The data it provides might make sense in the driver documentation, but what is anyone supposed to do with the returned hex value ? That kind of ABI really does not make any sense. If the reported values are really valuable enough to be reported, a real abi (egtempX_accuracyandtempX_resolution) would be much better.
With the raw register value, the driver gives application develop full flex= ibility to control the device. Is it possible to define a unifiied ABI for = all different ADCs in IIO framework? May IIO should document a policy on AB= I difinition.
Quoted 5 lines
For "power-save" (or "power-down" ?) and "full" mode I am not sure why suspend/resume isn't used instead. Is that some new upcoming ABI ?
I think the user may want to disable specific AD sensors while still keepin= g system running.
Sonic
Re: [PATCH 12/14] staging: iio: adc: new driver for ADT7408 temperature sensors
On Tue, Oct 26, 2010 at 12:20:59AM -0400, Zhang, Sonic wrote:
[ ... ]
Quoted 3 lines
With the raw register value, the driver gives application develop full flexibility to control the device. Is it possible to define a unifiied ABI for all different ADCs in IIO framework? May IIO should document a policy on ABI difinition.
The whole point of an ABI (or API) is that it is well defined and unified, and can be used across multiple devices. Otherwise it is not an ABI.
Guenter
RE: [PATCH 12/14] staging: iio: adc: new driver for ADT7408 temperature sensors
Quoted 20 lines
-----Original Message-----
From: Guenter Roeck [mailto:[email protected]]
Sent: Tuesday, October 26, 2010 1:09 PM
To: Zhang, Sonic
Cc: Jonathan Cameron; Mike Frysinger; [email protected]; [email protected]
Subject: Re: [PATCH 12/14] staging: iio: adc: new driver for ADT7408 temperature sensorsOn Tue, Oct 26, 2010 at 12:20:59AM -0400, Zhang, Sonic wrote:
[ ... ]Quoted 2 lines
With the raw register value, the driver gives application
develop full flexibility to control the device. Is it possible to define a unifiied ABI for all different ADCs in IIO framework? May IIO should document a policy on ABI difinition.
Quoted 1 line
Quoted 6 lines
The whole point of an ABI (or API) is that it is well defined and unified, and can be used across multiple devices. Otherwise it is not an ABI.
Guenter
Yes, I don't think the attribute values exported by the IIO ADC drivers are=
ABI. Difference ADCs may differ.
Sonic
Re: [PATCH 12/14] staging: iio: adc: new driver for ADT7408 temperature sensors
In reply to Zhang, SonicQuoted 36 lines · Sonic
Quoted 26 lines
-----Original Message-----
From: Guenter Roeck [mailto:[email protected]]
Sent: Monday, October 25, 2010 7:48 AM
To: Jonathan Cameron
Cc: Mike Frysinger; [email protected]; [email protected]; Zhang, Sonic
Subject: Re: [PATCH 12/14] staging: iio: adc: new driver for ADT7408 temperature sensorsQuoted 6 lines · Jonathan Cameron
Quoted 1 line · Mike Frysinger
From: Sonic Zhang <[email protected]>
Here we enter new territory. This device is already supported in hwmon. Do we have a usecase that is not covered by that driver?
If this is only for hardware monitoring by Guenter (cc'd)
can perhaps
Quoted 2 lines
advise on how to support everything you have here...
device_idandmanufactory_id(shouldn't that bemanufacturer_id?) don't provide much value since they are (or could be) already part of the device name.Quoted 9 lines
"capability" reflects a raw register value. I would be opposed to any attribute like that, since it does not mean anything beyond the driver for that specific chip.
The data it provides might make sense in the driver documentation, but what is anyone supposed to do with the returned hex value ? That kind of ABI really does not make any sense. If the reported values are really valuable enough to be reported, a real abi (egtempX_accuracyandtempX_resolution) would be much better.
Quoted 4 lines
With the raw register value, the driver gives application develop full flexibility to control the device. Is it possible to define a unifiied ABI for all different ADCs in IIO framework? May IIO should document a policy on ABI difinition.
Yes. We have fairly comprehensive documentation (updated version was posted to linux-iio the other day, but the stuff in place isn't that different). drivers/staging/iio/Documentation/sysfs-bus-iio is a good starting point.
Take a look at how the other ADC drivers in tree handle similar functionality (though I'm not entirely sure what this functionality is). max1363 or Michael's recent drivers are good starting points.
If you want to extend the ABI, in common with every other kernel subsystem, you propose the additions on the relevant mailing lists as an RFC. Hardly seems necessary to document that policy.
Quoted 7 lines
Quoted 5 lines
For "power-save" (or "power-down" ?) and "full" mode I am not sure why suspend/resume isn't used instead. Is that some new upcoming ABI ?
I think the user may want to disable specific AD sensors while still keeping system running.
Indeed, but it should be done using the runtime pm framework because then they can also have the relevant spi / i2c controllers power down saving even more power.
There are some heuristics in various drivers (not in IIO) that handle auto power off. I'm not sure if manual controls are currently supported.
Quoted 4 lines
Sonic
Re: [PATCH 12/14] staging: iio: adc: new driver for ADT7408 temperature sensors
In reply to Jonathan CameronQuoted 14 lines · Jonathan Cameron
Quoted 1 line · Mike Frysinger
From: Sonic Zhang <[email protected]>
Here we enter new territory. This device is already supported in hwmon. Do we have a usecase that is not covered by that driver?
If this is only for hardware monitoring by Guenter (cc'd) can perhaps advise on how to support everything you have here...
I'm personally not against having drivers in IIO for devices supported elsewhere, but the requirements for justification are rather higher. Also care is needed to ensure no issues with platform data etc.
Quoted 8 lines
Guenter, for your information we have a set of temp drivers coming, as a small element of a larger set, from Analog's tree. Those I've reviewed so far have wanted to use IIO's event infrastructure (which is much more general than hwmon's handling of alarms) or have been suitably high performance devices with general adc's to satisfy me that they clearly have uses beyond hardware monitoring.
Browsing through the adt patch list, there are several other drivers which either already exist in hwmon, or should be there.
I'd love to see some reasoning why hardware monitoring drivers are moved to or directly written in iio.
Also, I seem to be missing your point re "high performance devices". Are you saying that hwmon is not suitable for high performance hardware monitoring devices ?
Thanks,
Guenter
Re: [PATCH 12/14] staging: iio: adc: new driver for ADT7408 temperature sensors
Quoted 26 lines · Guenter Roeck
Quoted 14 lines · Jonathan Cameron
Quoted 1 line · Mike Frysinger
From: Sonic Zhang <[email protected]>
Here we enter new territory. This device is already supported in hwmon. Do we have a usecase that is not covered by that driver?
If this is only for hardware monitoring by Guenter (cc'd) can perhaps advise on how to support everything you have here...
I'm personally not against having drivers in IIO for devices supported elsewhere, but the requirements for justification are rather higher. Also care is needed to ensure no issues with platform data etc.
Quoted 8 lines
Guenter, for your information we have a set of temp drivers coming, as a small element of a larger set, from Analog's tree. Those I've reviewed so far have wanted to use IIO's event infrastructure (which is much more general than hwmon's handling of alarms) or have been suitably high performance devices with general adc's to satisfy me that they clearly have uses beyond hardware monitoring.
Browsing through the adt patch list, there are several other drivers which either already exist in hwmon, or should be there.
Quoted 6 lines
I'd love to see some reasoning why hardware monitoring drivers are moved to or directly written in iio.
Also, I seem to be missing your point re "high performance devices". Are you saying that hwmon is not suitable for high performance hardware monitoring devices ?
Yes. Point me at someone doing 1MSps or higher via pretty printing through a sysfs interface. Admittedly none of the controversial drivers in this set do that currently either, but that's why I have asked Analog to confirm what they are using them for. The point is that these devices are only hardware monitoring to you because that is what you think they are for. Some of them (not the one I forwarded initially) are general purpose ADC's that have a temp sensor because the temperature can effect the calibration of the outputs.
We went through this in a lot of depth back when IIO first came about. There is a boundary. We just need to pin down where it is.
Quoted 5 lines
Thanks,
Guenter
Re: [PATCH 12/14] staging: iio: adc: new driver for ADT7408 temperature sensors
Quoted 9 lines · Jonathan Cameron
Quoted 7 lines
I'd love to see some reasoning why hardware monitoring drivers are moved to or directly written in iio.
Also, I seem to be missing your point re "high performance devices". Are you saying that hwmon is not suitable for high performance hardware monitoring devices ?
Yes. Point me at someone doing 1MSps or higher via pretty printing through a sysfs interface. Admittedly none of the controversial drivers in this
Ok.
Quoted 7 lines
set do that currently either, but that's why I have asked Analog to confirm what they are using them for. The point is that these devices are only hardware monitoring to you because that is what you think they are for. Some of them (not the one I forwarded initially) are general purpose ADC's that have a temp sensor because the temperature can effect the calibration of the outputs.
I did not refer to the chips with generic ADC sensors.
The chips I referred to are AD7414/15, ADT75, ADT7310, ADT7408, and ADT7410, though I may have missed some.
Quoted 2 lines
We went through this in a lot of depth back when IIO first came about. There is a boundary. We just need to pin down where it is.
For the ambient temperature sensors on the other chips - did you consider adding hwmon device entries for those ? There may of course be reasons against doing that, but it may be an option. There are other drivers outside the hwmon directory which call hwmon_device_register(), so it is not a new concept.
Thanks,
Guenter
Re: [PATCH 12/14] staging: iio: adc: new driver for ADT7408 temperature sensors
Quoted 20 lines · Guenter Roeck
Quoted 9 lines · Jonathan Cameron
Quoted 7 lines
I'd love to see some reasoning why hardware monitoring drivers are moved to or directly written in iio.
Also, I seem to be missing your point re "high performance devices". Are you saying that hwmon is not suitable for high performance hardware monitoring devices ?
Yes. Point me at someone doing 1MSps or higher via pretty printing through a sysfs interface. Admittedly none of the controversial drivers in this
Ok.
Quoted 7 lines
set do that currently either, but that's why I have asked Analog to confirm what they are using them for. The point is that these devices are only hardware monitoring to you because that is what you think they are for. Some of them (not the one I forwarded initially) are general purpose ADC's that have a temp sensor because the temperature can effect the calibration of the outputs.
Quoted 3 lines
I did not refer to the chips with generic ADC sensors.
The chips I referred to are AD7414/15, ADT75, ADT7310, ADT7408, and ADT7410, though I may have missed some.
You clearly got further through the set than I have so far! (I'd only come across the first 2 of those) Agreed, all of these appear to be temperature only and at a quick look they are typically slow and low resolution so that set definitely want to be in hwmon.
For those parts with actual hwmon drivers, ad7414/15 and adt7408 (based on a quick grep unless Guenter has others queued). Lets drop them for now from the merge.
For the others lets put a todo in place to convert them to hwmon. Nothing wrong with putting them in staging (under IIO or otherwise) in the meantime as far as I am concerned.
Quoted 8 lines
Quoted 3 lines
We went through this in a lot of depth back when IIO first came about. There is a boundary. We just need to pin down where it is.
For the ambient temperature sensors on the other chips - did you consider adding hwmon device entries for those ? There may of course be reasons against doing that, but it may be an option. There are other drivers outside the hwmon directory which call
hwmon_device_register(), so it is not a new concept.
It depends on whether they are generally useful for temperature monitoring. On the whole they are giving one the value on a particular bit of silicon in the chip (not the ambient temperature near by). They aren't reading it for monitoring purposes, but because it is needed to calibrate the other sensors in the package. We even have devices with multiple temperature sensors, one on each MEMs device. Also they often get read into a buffer with all the rest of the channels.
Lets leave the decision on this up to individual driver writers. If they are using the device to do hwmon stuff as well as whatever else it is for then we encourage them to register it with hwmon as you suggest.
Thanks for you quick response on this.
Jonathan
Re: [PATCH 12/14] staging: iio: adc: new driver for ADT7408 temperature sensors
On Mon, Oct 25, 2010 at 07:43:12AM -0400, Jonathan Cameron wrote:
[ ... ]
Quoted 11 lines
Quoted 3 lines
I did not refer to the chips with generic ADC sensors.
The chips I referred to are AD7414/15, ADT75, ADT7310, ADT7408, and ADT7410, though I may have missed some.You clearly got further through the set than I have so far! (I'd only come across the first 2 of those) Agreed, all of these appear to be temperature only and at a quick look they are typically slow and low resolution so that set definitely want to be in hwmon.
For those parts with actual hwmon drivers, ad7414/15 and adt7408 (based on a quick grep unless Guenter has others queued). Lets drop them for now from the merge.
Nothing queued here. Not that I would mind doing the driver conversions for ADT7310 and ADT7410 if needed, but I would need HW (eval boards) for testing.
Quoted 20 lines
For the others lets put a todo in place to convert them to hwmon. Nothing wrong with putting them in staging (under IIO or otherwise) in the meantime as far as I am concerned.
Quoted 8 lines
Quoted 3 lines
We went through this in a lot of depth back when IIO first came about. There is a boundary. We just need to pin down where it is.
For the ambient temperature sensors on the other chips - did you consider adding hwmon device entries for those ? There may of course be reasons against doing that, but it may be an option. There are other drivers outside the hwmon directory which call
hwmon_device_register(), so it is not a new concept.It depends on whether they are generally useful for temperature monitoring. On the whole they are giving one the value on a particular bit of silicon in the chip (not the ambient temperature near by). They aren't reading it for monitoring purposes, but because it is needed to calibrate the other sensors in the package. We even have devices with multiple temperature sensors, one on each MEMs device. Also they often get read into a buffer with all the rest of the channels.
Quoted 4 lines
Lets leave the decision on this up to individual driver writers. If they are using the device to do hwmon stuff as well as whatever else it is for then we encourage them to register it with hwmon as you suggest.
Ok, makes sense.
Thanks,
Guenter
Hennerich, Michael
maintainerRE: [PATCH 12/14] staging: iio: adc: new driver for ADT7408 temperature sensors
Guenter Roeck wrote on 2010-10-25:
Quoted 11 lines · Jonathan Cameron
[ ... ]
Quoted 8 lines
Quoted 3 lines
I did not refer to the chips with generic ADC sensors. The chips I referred to are AD7414/15, ADT75, ADT7310, ADT7408, and ADT7410, though I may have missed some.
You clearly got further through the set than I have so far! (I'd only come across the first 2 of those) Agreed, all of these appear to be temperature only and at a quick look they are typically slow and low resolution so that set definitely want to be in hwmon.
Quoted 8 lines
Quoted 4 lines
For those parts with actual hwmon drivers, ad7414/15 and adt7408 (based on a quick grep unless Guenter has others queued). Lets drop them for now from the merge.
Nothing queued here. Not that I would mind doing the driver conversions for ADT7310 and ADT7410 if needed, but I would need HW (eval boards) for testing.
I'm sure that I can get you the EVAL-ADT7X10EBZ board. Please send me your shipping address off list.
Greetings,
Michael
Analog Devices GmbH Wilhelm-Wagenfeld-Str. 6 80807 Muenchen
Sitz der Gesellschaft Muenchen, Registergericht Muenchen HRB 4036 Geschaeft= sfuehrer Thomas Wessel, William A. Martin, Margaret Seif
Hennerich, Michael
maintainerRE: [Device-drivers-devel] [PATCH 12/14] staging: iio: adc: new driver for ADT7408 temperature sensors
In reply to Guenter RoeckGuenter Roeck wrote on 2010-10-25:
Quoted 5 lines · Jonathan Cameron
Quoted 4 lines
Quoted 4 lines
I'd love to see some reasoning why hardware monitoring drivers are moved to or directly written in iio.
Quoted 11 lines
Quoted 6 lines
Quoted 3 lines
Also, I seem to be missing your point re "high performance devices". Are you saying that hwmon is not suitable for high performance hardware monitoring devices ?
Yes. Point me at someone doing 1MSps or higher via pretty printing through a sysfs interface. Admittedly none of the controversial drivers in this
Ok.
Quoted 2 lines
set do that currently either, but that's why I have asked Analog to confirm what they are using them for.
I don't remember why these drivers targeted IIO instead of HWMON, since I didn't write those in question.
For some (without looking at a particular one) I would say the ringbuffer a= nd
trigger capabilities in IIO were required.
Quoted 9 lines
Quoted 6 lines
The point is that these devices
are only hardware monitoring to you because that is what you think they are for. Some of them (not the one I forwarded initially) are general purpose ADC's that have a temp sensor because the temperature can effect the calibration of the outputs.I did not refer to the chips with generic ADC sensors. The chips I referred to are AD7414/15, ADT75, ADT7310, ADT7408, and ADT7410, though I may have missed some.
For the ones listed above -
Quoted 1 line
Quoted 1 line
From top of my head, and a quick glance at the driver source,
I also don't see a reason why these need to exist twice.
I asked the author to comment on, why these went into iio.
I think it's ok to drop the ones that already have suitable driver support = in hwmon,
while adding support for the ones that are currently missing in hwmon.
Quoted 9 lines
Quoted 2 lines
We went through this in a lot of depth back when IIO first came about. There is a boundary. We just need to pin down where it is.
For the ambient temperature sensors on the other chips - did you consider adding hwmon device entries for those ? There may of course be reasons against doing that, but it may be an option. There are other drivers outside the hwmon directory which call
hwmon_device_register(), so it is not a new concept.
Quoted 6 lines
Thanks,
Guenter_______________________________________________ Device-drivers-devel mailing list [email protected]
https://blackfin.uclinux.org/mailman/listinfo/device-drivers-devel
Greetings,
Michael
Analog Devices GmbH Wilhelm-Wagenfeld-Str. 6 80807 Muenchen
Sitz der Gesellschaft Muenchen, Registergericht Muenchen HRB 4036 Geschaeft= sfuehrer Thomas Wessel, William A. Martin, Margaret Seif
RE: [Device-drivers-devel] [PATCH 12/14] staging: iio: adc: new driver for ADT7408 temperature sensors
Quoted 27 lines
-----Original Message-----
From: Hennerich, Michael
Sent: Monday, October 25, 2010 7:48 PM
To: Guenter Roeck; Jonathan Cameron
Cc: [email protected]; Zhang, Sonic; Mike Frysinger; [email protected]
Subject: RE: [Device-drivers-devel] [PATCH 12/14] staging:
iio: adc: new driver for ADT7408 temperature sensorsGuenter Roeck wrote on 2010-10-25:
Quoted 6 lines · Jonathan Cameron
Quoted 5 lines
Quoted 5 lines
I'd love to see some reasoning why hardware monitoring drivers are moved to or directly written in iio.
Also, I seem to be missing your point re "high performance
devices".
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Are you saying that hwmon is not suitable for high performance hardware monitoring devices ?
Yes. Point me at someone doing 1MSps or higher via pretty printing through a sysfs interface. Admittedly none of the controversial drivers in this
Ok.
Quoted 9 lines
Quoted 2 lines
Quoted 2 lines
set do that currently either, but that's why I have asked Analog to confirm what they are using them for.
I don't remember why these drivers targeted IIO instead of HWMON, since I didn't write those in question.
For some (without looking at a particular one) I would say the ringbuffer and trigger capabilities in IIO were required.
One of the reason to target these driver in IIO is to enable the ringbuffer=
and trigger capability, such as AD7414, ADT75, ADT7310, ADT7408 and ADT741=
0 mentioned bellow.
The other reason is that some chips has additional AD units other than the = temperature one.
Quoted 11 lines
Quoted 4 lines
Quoted 4 lines
The point is that these devices
are only hardware monitoring to you because that is what you think they are for. Some of them (not the one I forwarded initially) are general purpose ADC's that have a temp sensor because thetemperature
Quoted 5 lines
Quoted 2 lines
can effect the calibration of the outputs.
I did not refer to the chips with generic ADC sensors. The chips I referred to are AD7414/15, ADT75, ADT7310, ADT7408, and ADT7410, though I may have missed some.
These IIO drivers were developed early this year, when there were no suppor= t in hwmon framework in kernel mainline.
Sonic
Quoted 34 lines
For the ones listed above -
Quoted 1 line
From top of my head, and a quick glance at the driver source,
I also don't see a reason why these need to exist twice. I asked the author to comment on, why these went into iio. I think it's ok to drop the ones that already have suitable driver support in hwmon, while adding support for the ones that are currently missing in hwmon.
Quoted 1 line
Quoted 1 line
We went through this in a lot of depth back when IIO first
came about.
Quoted 8 lines
Quoted 1 line
There is a boundary. We just need to pin down where it is.
For the ambient temperature sensors on the other chips - did you consider adding hwmon device entries for those ? There may of course be reasons against doing that, but it may be an option. There are other drivers outside the hwmon directory which call
hwmon_device_register(), so it is not a new concept.Quoted 6 lines
Thanks,
Guenter_______________________________________________ Device-drivers-devel mailing list [email protected]
https://blackfin.uclinux.org/mailman/listinfo/device-drivers-develGreetings,
MichaelAnalog Devices GmbH Wilhelm-Wagenfeld-Str. 6 80807 Muenchen
Sitz der Gesellschaft Muenchen, Registergericht Muenchen HRB 4036 Geschaeftsfuehrer Thomas Wessel, William A. Martin, Margaret Seif
RE: [PATCH 12/14] staging: iio: adc: new driver for ADT7408 temperature sensors
In reply to Jonathan CameronQuoted 11 lines
-----Original Message-----
From: Jonathan Cameron [mailto:[email protected]]
Sent: Monday, October 25, 2010 6:54 AM
To: Mike Frysinger
Cc: [email protected]; [email protected]; Zhang, Sonic; Guenter Roeck
Subject: Re: [PATCH 12/14] staging: iio: adc: new driver for ADT7408 temperature sensors
Quoted 5 lines
Quoted 1 line · Mike Frysinger
From: Sonic Zhang <[email protected]>
Here we enter new territory. This device is already supported in hwmon. Do we have a usecase that is not covered by that driver?
I don't find a way to get event notification other than poll in hwmon frame= work. So, I move all temperature devic with interrupt available to IIO fram= ework.
Sonic
Quoted 1,068 lines
If this is only for hardware monitoring by Guenter (cc'd) can perhaps advise on how to support everything you have here...
I'm personally not against having drivers in IIO for devices supported elsewhere, but the requirements for justification are rather higher. Also care is needed to ensure no issues with platform data etc.
Guenter, for your information we have a set of temp drivers coming, as a small element of a larger set, from Analog's tree. Those I've reviewed so far have wanted to use IIO's event infrastructure (which is much more general than hwmon's handling of alarms) or have been suitably high performance devices with general adc's to satisfy me that they clearly have uses beyond hardware monitoring.
Quoted 147 lines
Signed-off-by Sonic Zhang <[email protected]>Signed-off-by Mike Frysinger <[email protected]>--- drivers/staging/iio/adc/Kconfig | 7 + drivers/staging/iio/adc/Makefile | 1 + drivers/staging/iio/adc/adt7408.c | 1006 +++++++++++++++++++++++++++++++++++++ 3 files changed, 1014 insertions(+), 0 deletions(-) create mode100644
drivers/staging/iio/adc/adt7408.c(quoted diff) +0
-0b/drivers/staging/iio/adc/Kconfig index 5d13918..ea75700 100644
drivers/staging/iio/adc/Kconfig +7
-0@@ -114,3 +114,10 @@ config ADT7408 help Say yes here to build support for Analog Devices ADT7408 temperature sensors. + +config ADT7410 + tristate "Analog Devices ADT7410 temperature sensor driver" + depends on I2C + help + Say yes here to build support for Analog Devices ADT7410 + temperature sensors.drivers/staging/iio/adc/Makefile +1
-0@@ -21,3 +21,4 @@ obj-$(CONFIG_AD774X) +=3D ad774x.o obj-$(CONFIG_AD7816) +=3D ad7816.o obj-$(CONFIG_ADT75) +=3D adt75.o obj-$(CONFIG_ADT7310) +=3D adt7310.o +obj-$(CONFIG_ADT7408) +=3D adt7408.odrivers/staging/iio/adc/adt7408.c new file +104
-0@@ -0,0 +1,1006 @@ +/* +* ADT7408 digital temperature sensor driver supporting ADT7408 +* +* Copyright 2010 Analog Devices Inc. +* +* Licensed under the GPL-2 or later. +*/ + +#include <linux/interrupt.h> +#include <linux/gpio.h> +#include <linux/workqueue.h> +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/sysfs.h> +#include <linux/list.h> +#include <linux/i2c.h> +#include <linux/rtc.h> + +#include "../iio.h" +#include "../sysfs.h" + +/* +* ADT7408 registers definition +*/ + +#define ADT7408_CAPABILITY 0 +#define ADT7408_CONFIG 1 +#define ADT7408_T_ALARM_HIGH 2 +#define ADT7408_T_ALARM_LOW 3 +#define ADT7408_T_CRIT 4 +#define ADT7408_TEMPERATURE 5 +#define ADT7408_MANUFACTURER_ID 6 +#define ADT7408_DEVICE_ID 7 + +/* +* ADT7408 capability +*/ +#define ADT7408_CAP_ALARM_CRIT_TRIPS 0x1 +#define ADT7408_CAP_HIGH_PRECISION 0x2 +#define ADT7408_CAP_WIDER_RANGE 0x4 +#define ADT7408_CAP_T_RESOLUTION_MASK 0x18 +#define ADT7408_CAP_T_RESOLUTION_HIGH 0x18 +#define ADT7408_CAP_T_RESOLUTION_LOW 0x8 + +/* +* ADT7408 config +*/ +#define ADT7408_EVENT_MODE 0x1 +#define ADT7408_EVENT_POLARITY 0x2 +#define ADT7408_EVENT_CRIT_ONLY 0x4 +#define ADT7408_EVENT_ENABLE 0x8 +#define ADT7408_EVENT_STATUS 0x10 +#define ADT7408_EVENT_CLEAR 0x20 +#define ADT7408_EVENT_ALARM_LOCK 0x40 +#define ADT7408_EVENT_CRIT_LOCK 0x80 +#define ADT7408_PD 0x100 +#define ADT7408_HISTERESIS_MASK 0x600 +#define ADT7408_HISTERESIS_1_5 0x200 +#define ADT7408_HISTERESIS_3 0x400 +#define ADT7408_HISTERESIS_6 0x600 + +/* +* ADT7408 masks +*/ +#define ADT7408_BOUND_VALUE_SIGN 0x400 +#define ADT7408_BOUND_VALUE_OFFSET 2 +#define ADT7408_BOUND_VALUE_FLOAT_OFFSET 2 +#define ADT7408_BOUND_VALUE_FLOAT_MASK 0x3 +#define ADT7408_T_VALUE_SIGN 0x1000 +#define ADT7408_T_VALUE_FLOAT_OFFSET 4 +#define ADT7408_T_VALUE_FLOAT_MASK 0xF + +/* +* ADT7408 event source +*/ +#define ADT7408_T_BELLOW_ALARM 0x2000 +#define ADT7408_T_ABOVE_ALARM 0x4000 +#define ADT7408_T_ABOVE_CRIT 0x8000 + + +/* +* struct adt7408_chip_info - chip specifc information */ + +struct adt7408_chip_info { +const char *name; +struct i2c_client *client; +struct iio_dev *indio_dev; +struct work_struct thresh_work; +s64 last_timestamp; +u16 config; +}; + +/* +* adt7408 register access by I2C +*/ + +static int adt7408_i2c_read (struct adt7408_chip_info *chip,u8 reg, +u16 *data) { + struct i2c_client *client =3D chip->client; + int ret =3D 0; + + ret =3D i2c_smbus_read_word_data(client, reg); +if (ret <0 ) {drivers/staging/iio/adc/adt7408.c line 114
Quoted 10 lines
drivers/staging/iio/adc/adt7408.c new file +10
-0+dev_err (&client->dev,"I2C read error\n" ); +return ret; + } + + *data =3D swab16((u16)ret); + +return 0 ; +} + +static int adt7408_i2c_write(struct adt7408_chip_info*chip, u8 reg,
Quoted 187 lines
drivers/staging/iio/adc/adt7408.c new file +187
-0+u16 data) { + struct i2c_client *client =3D chip->client; + int ret =3D 0; + + ret =3D i2c_smbus_write_word_data(client, reg, swab16(data)); +if (ret <0 ) +dev_err (&client->dev,"I2C write error\n" ); + +return ret; +} + +static int adt7408_is_event_locked (struct adt7408_chip_info *chip) { +return chip->config & (ADT7408_EVENT_ALARM_LOCK | +ADT7408_EVENT_ALARM_LOCK ); } + +static ssize_t adt7408_show_mode (struct device *dev, +struct device_attribute *attr, +char *buf) +{ + struct iio_dev *dev_info =3D dev_get_drvdata(dev); + struct adt7408_chip_info *chip =3D dev_info->dev_data; + +if (chip->config &ADT7408_PD ) +return sprintf (buf,"power-save\n" ); +else +return sprintf (buf,"full\n" ); +} + +static ssize_t adt7408_store_mode (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ + struct iio_dev *dev_info =3D dev_get_drvdata(dev); + struct adt7408_chip_info *chip =3D dev_info->dev_data; +u16 config; +int ret; + +if (adt7408_is_event_locked (chip)) { +dev_err (dev,"Warning: Events are locked.\n" ); +return -EIO ; + } + + ret =3D adt7408_i2c_read(chip, ADT7408_CONFIG, &chip->config); +if (ret) +return -EIO ; + + config =3D chip->config & (~ADT7408_PD); +if (!strcmp (buf,"full" )) + config |=3D ADT7408_PD; + + ret =3D adt7408_i2c_write(chip, ADT7408_CONFIG, config); +if (ret) +return -EIO ; + + chip->config =3D config; + +return ret; +} + +static IIO_DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, + adt7408_show_mode, + adt7408_store_mode, + 0); + +static ssize_t adt7408_show_available_modes (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return sprintf (buf,"full\npower-down\n" ); } + +static IIO_DEVICE_ATTR(available_modes, S_IRUGO, +adt7408_show_available_modes, NULL, 0); + +static ssize_t adt7408_show_capability (struct device *dev, +struct device_attribute *attr, +char *buf) +{ + struct iio_dev *dev_info =3D dev_get_drvdata(dev); + struct adt7408_chip_info *chip =3D dev_info->dev_data; +u16 capability; +int ret; + + ret =3D adt7408_i2c_read(chip, ADT7408_CAPABILITY, &capability); +if (ret) +return -EIO ; + +return sprintf (buf,"0x%x\n" , capability); } + +static IIO_DEVICE_ATTR(capability, S_IRUGO | S_IWUSR, + adt7408_show_capability, + NULL, + 0); + +static ssize_t adt7408_show_manufactory_id (struct device *dev, +struct device_attribute *attr, +char *buf) +{ + struct iio_dev *dev_info =3D dev_get_drvdata(dev); + struct adt7408_chip_info *chip =3D dev_info->dev_data; +u16 id; +int ret; + + ret =3D adt7408_i2c_read(chip, ADT7408_MANUFACTURER_ID, &id); +if (ret) +return -EIO ; + +return sprintf (buf,"0x%x\n" , id); +} + +static IIO_DEVICE_ATTR(manufactory_id, S_IRUGO | S_IWUSR, + adt7408_show_manufactory_id, + NULL, + 0); + +static ssize_t adt7408_show_device_id (struct device *dev, +struct device_attribute *attr, +char *buf) +{ + struct iio_dev *dev_info =3D dev_get_drvdata(dev); + struct adt7408_chip_info *chip =3D dev_info->dev_data; +u16 id; +int ret; + + ret =3D adt7408_i2c_read(chip, ADT7408_MANUFACTURER_ID, &id); +if (ret) +return -EIO ; + +return sprintf (buf,"0x%x\n" , id); +} + +static IIO_DEVICE_ATTR(device_id, S_IRUGO | S_IWUSR, + adt7408_show_device_id, + NULL, + 0); + +static ssize_t adt7408_show_value (struct device *dev, +struct device_attribute *attr, +char *buf) +{ + struct iio_dev *dev_info =3D dev_get_drvdata(dev); + struct adt7408_chip_info *chip =3D dev_info->dev_data; +u16 data; + char sign =3D ' '; +int ret; + +if (chip->config &ADT7408_PD ) { +dev_err (dev,"Can't read value in power-down mode.\n" ); +return -EIO ; + } + + ret =3D adt7408_i2c_read(chip, ADT7408_TEMPERATURE, &data); +if (ret) +return -EIO ; + +if (data &ADT7408_T_VALUE_SIGN ) { +/* convert supplement to positive value */ + data =3D (ADT7408_T_VALUE_SIGN <<1 ) - data; + sign =3D '-'; + } + +return sprintf (buf,"%c%d.%.4d\n" , sign, + (data >>ADT7408_T_VALUE_FLOAT_OFFSET ), + (data &ADT7408_T_VALUE_FLOAT_MASK ) *625 ); } + +static IIO_DEVICE_ATTR(value, S_IRUGO, adt7408_show_value, NULL, 0); + +static ssize_t adt7408_show_name (struct device *dev, +struct device_attribute *attr, +char *buf) +{ + struct iio_dev *dev_info =3D dev_get_drvdata(dev); + struct adt7408_chip_info *chip =3D dev_info->dev_data; +return sprintf (buf,"%s\n" , chip->name); } + +static IIO_DEVICE_ATTR(name, S_IRUGO, adt7408_show_name, NULL, 0); + +static struct attribute *adt7408_attributes[] =3D { + &iio_dev_attr_available_modes.dev_attr.attr, + &iio_dev_attr_mode.dev_attr.attr, + &iio_dev_attr_capability.dev_attr.attr, + &iio_dev_attr_device_id.dev_attr.attr, + &iio_dev_attr_manufactory_id.dev_attr.attr, + &iio_dev_attr_value.dev_attr.attr, + &iio_dev_attr_name.dev_attr.attr, +NULL , +};drivers/staging/iio/adc/adt7408.c
Quoted 10 lines
drivers/staging/iio/adc/adt7408.c new file +10
-0+ +static const struct attribute_group adt7408_attribute_group =3D { + .attrs =3D adt7408_attributes, +}; + +/* +* temperature bound events +*/ + +#define IIO_EVENT_CODE_ADT7408_ABOVE_ALARM (
IIO_EVENT_CODE_DEVICE_SPECIFIC+ 1)drivers/staging/iio/adc/adt7408.c line 312
Quoted 1 line
drivers/staging/iio/adc/adt7408.c new file +1
-0+#define IIO_EVENT_CODE_ADT7408_BELLOW_ALARM (
IIO_EVENT_CODE_DEVICE_SPECIFIC+ 2)drivers/staging/iio/adc/adt7408.c line 313
Quoted 1 line
drivers/staging/iio/adc/adt7408.c new file +1
-0+#define IIO_EVENT_CODE_ADT7408_ABOVE_CRIT (
IIO_EVENT_CODE_DEVICE_SPECIFIC+ 3)drivers/staging/iio/adc/adt7408.c line 317
Quoted 4 lines
drivers/staging/iio/adc/adt7408.c new file +4
-0+ +static void adt7408_interrupt_bh (struct work_struct *work_s) { + struct adt7408_chip_info *chip =3D + container_of(work_s, struct adt7408_chip_info,
thresh_work);Quoted 89 lines
drivers/staging/iio/adc/adt7408.c new file +89
-0+u16 config; +u16 data; + +if (adt7408_i2c_read (chip,ADT7408_CONFIG , &chip->config)) +return ; + +if (!(chip->config &ADT7408_EVENT_STATUS )) +return ; + + config =3D chip->config & ~ADT7408_EVENT_CLEAR; +if (data) + config |=3D ADT7408_EVENT_CLEAR; + +adt7408_i2c_write (chip,ADT7408_CONFIG , config); + +if (adt7408_i2c_read (chip,ADT7408_TEMPERATURE , &data)) + goto exit; + +if (data &ADT7408_T_ABOVE_ALARM ) +iio_push_event (chip->indio_dev,0 , +IIO_EVENT_CODE_ADT7408_ABOVE_ALARM , + chip->last_timestamp); +if (data &ADT7408_T_BELLOW_ALARM ) +iio_push_event (chip->indio_dev,0 , +IIO_EVENT_CODE_ADT7408_BELLOW_ALARM , + chip->last_timestamp); +if (data &ADT7408_T_ABOVE_CRIT ) +iio_push_event (chip->indio_dev,0 , +IIO_EVENT_CODE_ADT7408_ABOVE_CRIT , + chip->last_timestamp); +exit: +enable_irq (chip->client->irq); +} + +static int adt7408_interrupt (struct iio_dev *dev_info, +int index, +s64 timestamp, +int no_test) +{ + struct adt7408_chip_info *chip =3D dev_info->dev_data; + + chip->last_timestamp =3D timestamp; +schedule_work (&chip->thresh_work); + +return 0 ; +} + +IIO_EVENT_SH (adt7408, &adt7408_interrupt); + +static ssize_t adt7408_show_event_mode (struct device *dev, +struct device_attribute *attr, +char *buf) +{ + struct iio_dev *dev_info =3D dev_get_drvdata(dev); + struct adt7408_chip_info *chip =3D dev_info->dev_data; +int ret; + + ret =3D adt7408_i2c_read(chip, ADT7408_CONFIG, &chip->config); +if (ret) +return -EIO ; + +if (chip->config &ADT7408_EVENT_MODE ) +return sprintf (buf,"interrupt\n" ); +else +return sprintf (buf,"comparator\n" ); } + +static ssize_t adt7408_set_event_mode (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ + struct iio_dev *dev_info =3D dev_get_drvdata(dev); + struct adt7408_chip_info *chip =3D dev_info->dev_data; +u16 config; +int ret; + +if (adt7408_is_event_locked (chip)) { +dev_err (dev,"Warning: Events are locked.\n" ); +return -EIO ; + } + + ret =3D adt7408_i2c_read(chip, ADT7408_CONFIG, &chip->config); +if (ret) +return -EIO ; + + config =3D chip->config &=3D ~ADT7408_EVENT_MODE; + if (strcmp(buf, "comparator") !=3D 0) + config |=3D ADT7408_EVENT_MODE; +drivers/staging/iio/adc/adt7408.c
Quoted 10 lines
drivers/staging/iio/adc/adt7408.c new file +10
-0+ ret =3D adt7408_i2c_write(chip, ADT7408_CONFIG, config); +if (ret) +return -EIO ; + + chip->config =3D config; + +return ret; +} + +static ssize_t adt7408_show_available_event_modes(structdevice *dev,
Quoted 394 lines
drivers/staging/iio/adc/adt7408.c new file +394
-0+struct device_attribute *attr, + char *buf) +{ + return sprintf(buf, "comparator\ninterrupt\n"); } + +static ssize_t adt7408_show_event_crit_only (struct device *dev, +struct device_attribute *attr, +char *buf) +{ + struct iio_dev *dev_info =3D dev_get_drvdata(dev); + struct adt7408_chip_info *chip =3D dev_info->dev_data; +int ret; + + ret =3D adt7408_i2c_read(chip, ADT7408_CONFIG, &chip->config); +if (ret) +return -EIO ; + +return sprintf (buf,"%d\n" , !!(chip->config & +ADT7408_EVENT_CRIT_ONLY )); } + +static ssize_t adt7408_set_event_crit_only (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ + struct iio_dev *dev_info =3D dev_get_drvdata(dev); + struct adt7408_chip_info *chip =3D dev_info->dev_data; + unsigned long data =3D 0; +u16 config; +int ret; + +if (adt7408_is_event_locked (chip)) { +dev_err (dev,"Warning: Events are locked.\n" ); +return -EIO ; + } + + ret =3D strict_strtoul(buf, 10, &data); +if (ret) +return -EINVAL ; + + ret =3D adt7408_i2c_read(chip, ADT7408_CONFIG, &chip->config); +if (ret) +return -EIO ; + + config =3D chip->config &=3D ~ADT7408_EVENT_CRIT_ONLY; +if (data) + config |=3D ADT7408_EVENT_CRIT_ONLY; + + ret =3D adt7408_i2c_write(chip, ADT7408_CONFIG, config); +if (ret) +return -EIO ; + + chip->config =3D config; + +return ret; +} + +static ssize_t adt7408_show_event_enable (struct device *dev, +struct device_attribute *attr, +char *buf) +{ + struct iio_dev *dev_info =3D dev_get_drvdata(dev); + struct adt7408_chip_info *chip =3D dev_info->dev_data; +int ret; + + ret =3D adt7408_i2c_read(chip, ADT7408_CONFIG, &chip->config); +if (ret) +return -EIO ; + +return sprintf (buf,"%d\n" , !!(chip->config & +ADT7408_EVENT_ENABLE )); } + +static ssize_t adt7408_set_event_enable (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ + struct iio_dev *dev_info =3D dev_get_drvdata(dev); + struct adt7408_chip_info *chip =3D dev_info->dev_data; +unsigned long data; +u16 config; +int ret; + +if (adt7408_is_event_locked (chip)) { +dev_err (dev,"Warning: Events are locked.\n" ); +return -EIO ; + } + + ret =3D strict_strtoul(buf, 10, &data); +if (ret) +return -EINVAL ; + + ret =3D adt7408_i2c_read(chip, ADT7408_CONFIG, &chip->config); +if (ret) +return -EIO ; + + config =3D chip->config & ~ADT7408_EVENT_ENABLE; +if (data) + config |=3D ADT7408_EVENT_ENABLE; + + ret =3D adt7408_i2c_write(chip, ADT7408_CONFIG, config); +if (ret) +return -EIO ; + + chip->config =3D config; + +return ret; +} + +static ssize_t adt7408_show_alarm_lock (struct device *dev, +struct device_attribute *attr, +char *buf) +{ + struct iio_dev *dev_info =3D dev_get_drvdata(dev); + struct adt7408_chip_info *chip =3D dev_info->dev_data; +int ret; + + ret =3D adt7408_i2c_read(chip, ADT7408_CONFIG, &chip->config); +if (ret) +return -EIO ; + +return sprintf (buf,"%d\n" , !!(chip->config & +ADT7408_EVENT_ALARM_LOCK )); } + +static ssize_t adt7408_set_alarm_lock (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ + struct iio_dev *dev_info =3D dev_get_drvdata(dev); + struct adt7408_chip_info *chip =3D dev_info->dev_data; +unsigned long data; +u16 config; +int ret; + + ret =3D strict_strtoul(buf, 10, &data); +if (ret) +return -EINVAL ; + + ret =3D adt7408_i2c_read(chip, ADT7408_CONFIG, &chip->config); +if (ret) +return -EIO ; + + config =3D chip->config & ~ADT7408_EVENT_ALARM_LOCK; +if (data) + config |=3D ADT7408_EVENT_ALARM_LOCK; + + ret =3D adt7408_i2c_write(chip, ADT7408_CONFIG, config); +if (ret) +return -EIO ; + + chip->config =3D config; + +return ret; +} + +static ssize_t adt7408_show_crit_lock (struct device *dev, +struct device_attribute *attr, +char *buf) +{ + struct iio_dev *dev_info =3D dev_get_drvdata(dev); + struct adt7408_chip_info *chip =3D dev_info->dev_data; +int ret; + + ret =3D adt7408_i2c_read(chip, ADT7408_CONFIG, &chip->config); +if (ret) +return -EIO ; + +return sprintf (buf,"%d\n" , !!(chip->config & +ADT7408_EVENT_CRIT_LOCK )); } + +static ssize_t adt7408_set_crit_lock (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ + struct iio_dev *dev_info =3D dev_get_drvdata(dev); + struct adt7408_chip_info *chip =3D dev_info->dev_data; +unsigned long data; +u16 config; +int ret; + + ret =3D strict_strtoul(buf, 10, &data); +if (ret) +return -EINVAL ; + + ret =3D adt7408_i2c_read(chip, ADT7408_CONFIG, &chip->config); +if (ret) +return -EIO ; + + config =3D chip->config & ~ADT7408_EVENT_CRIT_LOCK; +if (data) + config |=3D ADT7408_EVENT_CRIT_LOCK; + + ret =3D adt7408_i2c_write(chip, ADT7408_CONFIG, config); +if (ret) +return -EIO ; + + chip->config =3D config; + +return ret; +} + + +static inline ssize_t adt7408_show_t_bound (struct device *dev, +struct device_attribute *attr, +u8 bound_reg, +char *buf) +{ + struct iio_dev *dev_info =3D dev_get_drvdata(dev); + struct adt7408_chip_info *chip =3D dev_info->dev_data; +u16 data; + char sign =3D ' '; +int ret; + + ret =3D adt7408_i2c_read(chip, bound_reg, &data); +if (ret) +return -EIO ; + + data >>=3D ADT7408_BOUND_VALUE_OFFSET; +if (data &ADT7408_BOUND_VALUE_SIGN ) { +/* convert supplement to positive value */ + data =3D (ADT7408_BOUND_VALUE_SIGN <<1 ) - data; + sign =3D '-'; + } + +return sprintf (buf,"%c%d.%.2d\n" , sign, + data >>ADT7408_BOUND_VALUE_FLOAT_OFFSET , + (data &ADT7408_BOUND_VALUE_FLOAT_MASK ) *25 ); } + +static inline ssize_t adt7408_set_t_bound (struct device *dev, +struct device_attribute *attr, +u8 bound_reg, +const char *buf, +size_t len) +{ + struct iio_dev *dev_info =3D dev_get_drvdata(dev); + struct adt7408_chip_info *chip =3D dev_info->dev_data; +long tmp1, tmp2; +u16 data; +char *pos; +int ret; + + pos =3D strchr(buf, '.'); + + ret =3D strict_strtol(buf, 10, &tmp1); + +if (ret || tmp1 >127 || tmp1 <-128 ) +return -EINVAL ; + +if (pos) { + len =3D strlen(pos); +if (len >ADT7408_BOUND_VALUE_FLOAT_OFFSET ) + len =3D ADT7408_BOUND_VALUE_FLOAT_OFFSET; + pos[len] =3D 0; + ret =3D strict_strtol(pos, 10, &tmp2); + +if (!ret) + tmp2 =3D (tmp2 /25 ) *25 ; + } + +if (tmp1 <0 ) + data =3D (u16)(-tmp1); +else + data =3D (u16)tmp1; + data =3D (data <<ADT7408_BOUND_VALUE_FLOAT_OFFSET ) | + (tmp2 &ADT7408_BOUND_VALUE_FLOAT_MASK ); +if (tmp1 <0 ) +/* convert positive value to supplyment */ + data =3D (ADT7408_BOUND_VALUE_SIGN <<1 ) - data; + data <<=3D ADT7408_BOUND_VALUE_OFFSET; + + ret =3D adt7408_i2c_write(chip, bound_reg, data); +if (ret) +return -EIO ; + +return ret; +} + +static ssize_t adt7408_show_t_alarm_high (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return adt7408_show_t_bound (dev, attr, +ADT7408_T_ALARM_HIGH , buf); +} + +static inline ssize_t adt7408_set_t_alarm_high (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +return adt7408_set_t_bound (dev, attr, +ADT7408_T_ALARM_HIGH , buf, len); +} + +static ssize_t adt7408_show_t_alarm_low (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return adt7408_show_t_bound (dev, attr, +ADT7408_T_ALARM_LOW , buf); +} + +static inline ssize_t adt7408_set_t_alarm_low (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +return adt7408_set_t_bound (dev, attr, +ADT7408_T_ALARM_LOW , buf, len); +} + +static ssize_t adt7408_show_t_crit (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return adt7408_show_t_bound (dev, attr, +ADT7408_T_CRIT , buf); +} + +static inline ssize_t adt7408_set_t_crit (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +return adt7408_set_t_bound (dev, attr, +ADT7408_T_CRIT , buf, len); +} + +static ssize_t adt7408_show_t_hyst (struct device *dev, +struct device_attribute *attr, +char *buf) +{ + struct iio_dev *dev_info =3D dev_get_drvdata(dev); + struct adt7408_chip_info *chip =3D dev_info->dev_data; +int ret; + +/* retrive ALART status */ + ret =3D adt7408_i2c_read(chip, ADT7408_CONFIG, &chip->config); +if (ret) +return -EIO ; + +switch (chip->config &ADT7408_HISTERESIS_MASK ) { +case ADT7408_HISTERESIS_1_5 : +return sprintf (buf,"1.5\n" ); +case ADT7408_HISTERESIS_3 : +return sprintf (buf,"3\n" ); +case ADT7408_HISTERESIS_6 : +return sprintf (buf,"6\n" ); +default : +return sprintf (buf,"Disabled\n" ); + } +} + +static inline ssize_t adt7408_set_t_hyst (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ + struct iio_dev *dev_info =3D dev_get_drvdata(dev); + struct adt7408_chip_info *chip =3D dev_info->dev_data; +int ret; + u16 config =3D 0; + +if (strcmp (buf,"disble" )) + config =3D ADT7408_HISTERESIS_MASK; +else if (strcmp (buf,"1.5" )) + config =3D ADT7408_HISTERESIS_1_5; + else if (len > 1 && buf[0] =3D=3D '3') + config =3D ADT7408_HISTERESIS_6; + else if (len > 1 && buf[0] =3D=3D '6') + config =3D ADT7408_HISTERESIS_6; + +if (!config) +return -EINVAL ; + +/* retrive ALART status */ + ret =3D adt7408_i2c_read(chip, ADT7408_CONFIG, &chip->config); +if (ret) +return -EIO ; + + config |=3D chip->config & ~ADT7408_HISTERESIS_MASK; + + ret =3D adt7408_i2c_write(chip, ADT7408_CONFIG, config); +if (ret) +return -EIO ; + + chip->config =3D config; +return ret; +} + +static ssize_t adt7408_show_available_t_hyst(struct device *dev, + struct device_attribute *attr,drivers/staging/iio/adc/adt7408.c
Quoted 10 lines
drivers/staging/iio/adc/adt7408.c new file +10
-0+ char *buf) +{ +return sprintf (buf,"1.5\n3\n6\ndisable\n" ); } + +IIO_EVENT_ATTR_SH (event_mode, iio_event_adt7408, + adt7408_show_event_mode, adt7408_set_event_mode,0 ); +IIO_EVENT_ATTR_SH (available_event_modes, iio_event_adt7408, + adt7408_show_available_event_modes,NULL ,0 ); +IIO_EVENT_ATTR_SH(event_crit_only, iio_event_adt7408, + adt7408_show_event_crit_only,
adt7408_set_event_crit_only, 0);drivers/staging/iio/adc/adt7408.c line 822
Quoted 2 lines
drivers/staging/iio/adc/adt7408.c new file +2
-0+IIO_EVENT_ATTR_SH(event_enable, iio_event_adt7408, + adt7408_show_event_enable,
adt7408_set_event_enable, 0);drivers/staging/iio/adc/adt7408.c
Quoted 6 lines
drivers/staging/iio/adc/adt7408.c new file +6
-0+IIO_EVENT_ATTR_SH (alarm_lock, iio_event_adt7408, + adt7408_show_alarm_lock, adt7408_set_alarm_lock,0 ); +IIO_EVENT_ATTR_SH (crit_lock, iio_event_adt7408, + adt7408_show_crit_lock, adt7408_set_crit_lock,0 ); +IIO_EVENT_ATTR_SH(t_alarm_high, iio_event_adt7408, + adt7408_show_t_alarm_high,
adt7408_set_t_alarm_high, 0);Quoted 68 lines
drivers/staging/iio/adc/adt7408.c new file +68
-0+IIO_EVENT_ATTR_SH (t_alarm_low, iio_event_adt7408, + adt7408_show_t_alarm_low, adt7408_set_t_alarm_low,0 ); +IIO_EVENT_ATTR_SH (t_crit, iio_event_adt7408, + adt7408_show_t_crit, adt7408_set_t_crit,0 ); +IIO_EVENT_ATTR_SH (t_hyst, iio_event_adt7408, + adt7408_show_t_hyst, adt7408_set_t_hyst,0 ); +IIO_EVENT_ATTR_SH (available_t_hyst, iio_event_adt7408, + adt7408_show_available_t_hyst,NULL ,0 ); + +static struct attribute *adt7408_event_attributes[] =3D { + &iio_event_attr_event_mode.dev_attr.attr, + &iio_event_attr_available_event_modes.dev_attr.attr, + &iio_event_attr_event_crit_only.dev_attr.attr, + &iio_event_attr_event_enable.dev_attr.attr, + &iio_event_attr_alarm_lock.dev_attr.attr, + &iio_event_attr_crit_lock.dev_attr.attr, + &iio_event_attr_t_alarm_high.dev_attr.attr, + &iio_event_attr_t_alarm_low.dev_attr.attr, + &iio_event_attr_t_crit.dev_attr.attr, + &iio_event_attr_t_hyst.dev_attr.attr, + &iio_event_attr_available_t_hyst.dev_attr.attr, +NULL , +}; + +static struct attribute_group adt7408_event_attribute_group =3D { + .attrs =3D adt7408_event_attributes, +}; + +/* +* device probe and remove +*/ + +static int __devinit adt7408_probe (struct i2c_client *client, +const struct i2c_device_id *id) +{ +struct adt7408_chip_info *chip; + int ret =3D 0; + + chip =3D kzalloc(sizeof(struct adt7408_chip_info), GFP_KERNEL); + + if (chip =3D=3D NULL) +return -ENOMEM ; + +/* this is only used for device removal purposes */ +i2c_set_clientdata (client, chip); + + chip->client =3D client; + chip->name =3D id->name; + + chip->indio_dev =3D iio_allocate_device(); + if (chip->indio_dev =3D=3D NULL) { + ret =3D -ENOMEM ; + goto error_free_chip; + } + + chip->indio_dev->dev.parent =3D &client->dev; + chip->indio_dev->attrs =3D &adt7408_attribute_group; + chip->indio_dev->event_attrs =3D &adt7408_event_attribute_group; + chip->indio_dev->dev_data =3D (void *)chip; + chip->indio_dev->driver_module =3D THIS_MODULE; + chip->indio_dev->num_interrupt_lines =3D 1; + chip->indio_dev->modes =3D INDIO_DIRECT_MODE; + + ret =3D iio_device_register(chip->indio_dev); +if (ret) + goto error_free_dev; + +if (client->irq) {drivers/staging/iio/adc/adt7408.c
Quoted 10 lines
drivers/staging/iio/adc/adt7408.c new file +10
-0+ ret =3D iio_register_interrupt_line(client->irq, + chip->indio_dev, +0 , + client->irq_flags, + chip->name); +if (ret) + goto error_unreg_dev; + +/* +* The event handler list element refer to
iio_event_adt7408.drivers/staging/iio/adc/adt7408.c line 922
Quoted 5 lines
drivers/staging/iio/adc/adt7408.c new file +5
-0+* All event attributes bind to the same event handler. +* So, only register event handler once. +*/ + iio_add_event_to_list(&iio_event_adt7408, +&chip->indio_dev->interrupts[0]->ev_list);
drivers/staging/iio/adc/adt7408.c
Quoted 4 lines
drivers/staging/iio/adc/adt7408.c new file +4
-0+ +INIT_WORK (&chip->thresh_work, adt7408_interrupt_bh); + + ret =3D adt7408_i2c_read(chip, ADT7408_CONFIG,
&chip->config);drivers/staging/iio/adc/adt7408.c
Quoted 11 lines
drivers/staging/iio/adc/adt7408.c new file +11
-0+if (ret) { + ret =3D -EIO ; + goto error_unreg_irq; + } + +if (client->irq_flags &IRQF_TRIGGER_HIGH ) + chip->config |=3D ADT7408_EVENT_POLARITY; +else + chip->config &=3D ~ADT7408_EVENT_POLARITY; + + ret =3D adt7408_i2c_write(chip, ADT7408_CONFIG,
chip->config);Quoted 67 lines
drivers/staging/iio/adc/adt7408.c new file +67
-0+if (ret) { + ret =3D -EIO ; + goto error_unreg_irq; + } + } + +dev_info (&client->dev,"%s temperature sensor registered.\n" , + id->name); + +return 0 ; + +error_unreg_irq: +iio_unregister_interrupt_line (chip->indio_dev,0 ); +error_unreg_dev: +iio_device_unregister (chip->indio_dev); +error_free_dev: +iio_free_device (chip->indio_dev); +error_free_chip: +kfree (chip); + +return ret; +} + +static int __devexit adt7408_remove(struct i2c_client *client) { + struct adt7408_chip_info *chip =3D i2c_get_clientdata(client); + struct iio_dev *indio_dev =3D chip->indio_dev; + +if (client->irq) +iio_unregister_interrupt_line (indio_dev,0 ); +iio_device_unregister (indio_dev); +iio_free_device (chip->indio_dev); +kfree (chip); + +return 0 ; +} + +static const struct i2c_device_id adt7408_id[] =3D { + {"adt7408" ,0 }, + {} +}; + +MODULE_DEVICE_TABLE (i2c, adt7408_id); + +static struct i2c_driver adt7408_driver =3D { + .driver =3D { + .name =3D "adt7408", + }, + .probe =3D adt7408_probe, + .remove =3D __devexit_p(adt7408_remove), + .id_table =3D adt7408_id, +}; + +static __init int adt7408_init (void ) +{ +return i2c_add_driver (&adt7408_driver); } + +static __exit void adt7408_exit(void) { +i2c_del_driver (&adt7408_driver); +} + +MODULE_AUTHOR ("Sonic Zhang <[email protected]>" ); +MODULE_DESCRIPTION ("Analog Devices ADT7408 digital" +" temperature sensor driver" ); +MODULE_LICENSE ("GPL v2" ); + +module_init (adt7408_init); +module_exit (adt7408_exit);
Re: [PATCH 12/14] staging: iio: adc: new driver for ADT7408 temperature sensors
Quoted 11 lines · Sonic
Quoted 11 lines
-----Original Message-----
From: Jonathan Cameron [mailto:[email protected]]
Sent: Monday, October 25, 2010 6:54 AM
To: Mike Frysinger
Cc: [email protected]; [email protected]; Zhang, Sonic; Guenter Roeck
Subject: Re: [PATCH 12/14] staging: iio: adc: new driver for ADT7408 temperature sensors
Quoted 8 lines
Quoted 5 lines · Mike Frysinger
Quoted 1 line
From: Sonic Zhang <[email protected]>
Here we enter new territory. This device is already supported in hwmon. Do we have a usecase that is not covered by that driver?
I don't find a way to get event notification other than poll in hwmon framework. So, I move all temperature devic with interrupt available to IIO framework.
A much better approach, if such notifications are required and make sense, would be to add it to the hwmon framework. Rewriting drivers just to get notifications is not a solution.
Besides, did you consider using kobject_uevent() ? The generic gpio driver uses that mechanism to create udev notifications on alarms.
Guenter
Re: [PATCH 12/14] staging: iio: adc: new driver for ADT7408 temperature sensors
In reply to Zhang, SonicQuoted 12 lines · Sonic
Quoted 12 lines
-----Original Message-----
From: Jonathan Cameron [mailto:[email protected]]
Sent: Monday, October 25, 2010 6:54 AM
To: Mike Frysinger
Cc: [email protected]; [email protected]; Zhang, Sonic; Guenter Roeck
Subject: Re: [PATCH 12/14] staging: iio: adc: new driver for ADT7408 temperature sensorsOn 10/23/10 21:29, Mike Frysinger wrote:
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
From: Sonic Zhang <[email protected]>
Here we enter new territory. This device is already supported in hwmon. Do we have a usecase that is not covered by that driver?
I don't find a way to get event notification other than poll in hwmon framework. So, I move all temperature devic with interrupt available to IIO framework.
Whilst it isn't often done (and is a little clunky). It is possible to select on sysfs attributes much like any other file. I'm sure Guenter can tell us if any current hwmon devices are doing this?
Quoted 1,071 lines
Sonic
Quoted 1,068 lines
If this is only for hardware monitoring by Guenter (cc'd) can perhaps advise on how to support everything you have here...
I'm personally not against having drivers in IIO for devices supported elsewhere, but the requirements for justification are rather higher. Also care is needed to ensure no issues with platform data etc.
Guenter, for your information we have a set of temp drivers coming, as a small element of a larger set, from Analog's tree. Those I've reviewed so far have wanted to use IIO's event infrastructure (which is much more general than hwmon's handling of alarms) or have been suitably high performance devices with general adc's to satisfy me that they clearly have uses beyond hardware monitoring.
Quoted 147 lines
Signed-off-by Sonic Zhang <[email protected]>Signed-off-by Mike Frysinger <[email protected]>--- drivers/staging/iio/adc/Kconfig | 7 + drivers/staging/iio/adc/Makefile | 1 + drivers/staging/iio/adc/adt7408.c | 1006 +++++++++++++++++++++++++++++++++++++ 3 files changed, 1014 insertions(+), 0 deletions(-) create mode100644
drivers/staging/iio/adc/adt7408.c(quoted diff) +0
-0b/drivers/staging/iio/adc/Kconfig index 5d13918..ea75700 100644
drivers/staging/iio/adc/Kconfig +7
-0@@ -114,3 +114,10 @@ config ADT7408 help Say yes here to build support for Analog Devices ADT7408 temperature sensors. + +config ADT7410 + tristate "Analog Devices ADT7410 temperature sensor driver" + depends on I2C + help + Say yes here to build support for Analog Devices ADT7410 + temperature sensors.drivers/staging/iio/adc/Makefile +1
-0@@ -21,3 +21,4 @@ obj-$(CONFIG_AD774X) += ad774x.o obj-$(CONFIG_AD7816) += ad7816.o obj-$(CONFIG_ADT75) += adt75.o obj-$(CONFIG_ADT7310) += adt7310.o +obj-$(CONFIG_ADT7408) += adt7408.odrivers/staging/iio/adc/adt7408.c new file +104
-0@@ -0,0 +1,1006 @@ +/* +* ADT7408 digital temperature sensor driver supporting ADT7408 +* +* Copyright 2010 Analog Devices Inc. +* +* Licensed under the GPL-2 or later. +*/ + +#include <linux/interrupt.h> +#include <linux/gpio.h> +#include <linux/workqueue.h> +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/sysfs.h> +#include <linux/list.h> +#include <linux/i2c.h> +#include <linux/rtc.h> + +#include "../iio.h" +#include "../sysfs.h" + +/* +* ADT7408 registers definition +*/ + +#define ADT7408_CAPABILITY 0 +#define ADT7408_CONFIG 1 +#define ADT7408_T_ALARM_HIGH 2 +#define ADT7408_T_ALARM_LOW 3 +#define ADT7408_T_CRIT 4 +#define ADT7408_TEMPERATURE 5 +#define ADT7408_MANUFACTURER_ID 6 +#define ADT7408_DEVICE_ID 7 + +/* +* ADT7408 capability +*/ +#define ADT7408_CAP_ALARM_CRIT_TRIPS 0x1 +#define ADT7408_CAP_HIGH_PRECISION 0x2 +#define ADT7408_CAP_WIDER_RANGE 0x4 +#define ADT7408_CAP_T_RESOLUTION_MASK 0x18 +#define ADT7408_CAP_T_RESOLUTION_HIGH 0x18 +#define ADT7408_CAP_T_RESOLUTION_LOW 0x8 + +/* +* ADT7408 config +*/ +#define ADT7408_EVENT_MODE 0x1 +#define ADT7408_EVENT_POLARITY 0x2 +#define ADT7408_EVENT_CRIT_ONLY 0x4 +#define ADT7408_EVENT_ENABLE 0x8 +#define ADT7408_EVENT_STATUS 0x10 +#define ADT7408_EVENT_CLEAR 0x20 +#define ADT7408_EVENT_ALARM_LOCK 0x40 +#define ADT7408_EVENT_CRIT_LOCK 0x80 +#define ADT7408_PD 0x100 +#define ADT7408_HISTERESIS_MASK 0x600 +#define ADT7408_HISTERESIS_1_5 0x200 +#define ADT7408_HISTERESIS_3 0x400 +#define ADT7408_HISTERESIS_6 0x600 + +/* +* ADT7408 masks +*/ +#define ADT7408_BOUND_VALUE_SIGN 0x400 +#define ADT7408_BOUND_VALUE_OFFSET 2 +#define ADT7408_BOUND_VALUE_FLOAT_OFFSET 2 +#define ADT7408_BOUND_VALUE_FLOAT_MASK 0x3 +#define ADT7408_T_VALUE_SIGN 0x1000 +#define ADT7408_T_VALUE_FLOAT_OFFSET 4 +#define ADT7408_T_VALUE_FLOAT_MASK 0xF + +/* +* ADT7408 event source +*/ +#define ADT7408_T_BELLOW_ALARM 0x2000 +#define ADT7408_T_ABOVE_ALARM 0x4000 +#define ADT7408_T_ABOVE_CRIT 0x8000 + + +/* +* struct adt7408_chip_info - chip specifc information */ + +struct adt7408_chip_info { +const char *name; +struct i2c_client *client; +struct iio_dev *indio_dev; +struct work_struct thresh_work; +s64 last_timestamp; +u16 config; +}; + +/* +* adt7408 register access by I2C +*/ + +static int adt7408_i2c_read (struct adt7408_chip_info *chip,u8 reg, +u16 *data) { +struct i2c_client *client = chip->client; +int ret =0 ; + + ret =i2c_smbus_read_word_data (client, reg); +if (ret <0 ) {drivers/staging/iio/adc/adt7408.c line 114
Quoted 10 lines
drivers/staging/iio/adc/adt7408.c new file +10
-0+dev_err (&client->dev,"I2C read error\n" ); +return ret; + } + + *data =swab16 ((u16 )ret); + +return 0 ; +} + +static int adt7408_i2c_write(struct adt7408_chip_info*chip, u8 reg,
Quoted 187 lines
drivers/staging/iio/adc/adt7408.c new file +187
-0+u16 data) { +struct i2c_client *client = chip->client; +int ret =0 ; + + ret =i2c_smbus_write_word_data (client, reg,swab16 (data)); +if (ret <0 ) +dev_err (&client->dev,"I2C write error\n" ); + +return ret; +} + +static int adt7408_is_event_locked (struct adt7408_chip_info *chip) { +return chip->config & (ADT7408_EVENT_ALARM_LOCK | +ADT7408_EVENT_ALARM_LOCK ); } + +static ssize_t adt7408_show_mode (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; + +if (chip->config &ADT7408_PD ) +return sprintf (buf,"power-save\n" ); +else +return sprintf (buf,"full\n" ); +} + +static ssize_t adt7408_store_mode (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +u16 config; +int ret; + +if (adt7408_is_event_locked (chip)) { +dev_err (dev,"Warning: Events are locked.\n" ); +return -EIO ; + } + + ret =adt7408_i2c_read (chip,ADT7408_CONFIG , &chip->config); +if (ret) +return -EIO ; + + config = chip->config & (~ADT7408_PD ); +if (!strcmp (buf,"full" )) + config |=ADT7408_PD ; + + ret =adt7408_i2c_write (chip,ADT7408_CONFIG , config); +if (ret) +return -EIO ; + + chip->config = config; + +return ret; +} + +static IIO_DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, + adt7408_show_mode, + adt7408_store_mode, + 0); + +static ssize_t adt7408_show_available_modes (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return sprintf (buf,"full\npower-down\n" ); } + +static IIO_DEVICE_ATTR(available_modes, S_IRUGO, +adt7408_show_available_modes, NULL, 0); + +static ssize_t adt7408_show_capability (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +u16 capability; +int ret; + + ret =adt7408_i2c_read (chip,ADT7408_CAPABILITY , &capability); +if (ret) +return -EIO ; + +return sprintf (buf,"0x%x\n" , capability); } + +static IIO_DEVICE_ATTR(capability, S_IRUGO | S_IWUSR, + adt7408_show_capability, + NULL, + 0); + +static ssize_t adt7408_show_manufactory_id (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +u16 id; +int ret; + + ret =adt7408_i2c_read (chip,ADT7408_MANUFACTURER_ID , &id); +if (ret) +return -EIO ; + +return sprintf (buf,"0x%x\n" , id); +} + +static IIO_DEVICE_ATTR(manufactory_id, S_IRUGO | S_IWUSR, + adt7408_show_manufactory_id, + NULL, + 0); + +static ssize_t adt7408_show_device_id (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +u16 id; +int ret; + + ret =adt7408_i2c_read (chip,ADT7408_MANUFACTURER_ID , &id); +if (ret) +return -EIO ; + +return sprintf (buf,"0x%x\n" , id); +} + +static IIO_DEVICE_ATTR(device_id, S_IRUGO | S_IWUSR, + adt7408_show_device_id, + NULL, + 0); + +static ssize_t adt7408_show_value (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +u16 data; +char sign =' ' ; +int ret; + +if (chip->config &ADT7408_PD ) { +dev_err (dev,"Can't read value in power-down mode.\n" ); +return -EIO ; + } + + ret =adt7408_i2c_read (chip,ADT7408_TEMPERATURE , &data); +if (ret) +return -EIO ; + +if (data &ADT7408_T_VALUE_SIGN ) { +/* convert supplement to positive value */ + data = (ADT7408_T_VALUE_SIGN <<1 ) - data; + sign ='-' ; + } + +return sprintf (buf,"%c%d.%.4d\n" , sign, + (data >>ADT7408_T_VALUE_FLOAT_OFFSET ), + (data &ADT7408_T_VALUE_FLOAT_MASK ) *625 ); } + +static IIO_DEVICE_ATTR(value, S_IRUGO, adt7408_show_value, NULL, 0); + +static ssize_t adt7408_show_name (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +return sprintf (buf,"%s\n" , chip->name); } + +static IIO_DEVICE_ATTR(name, S_IRUGO, adt7408_show_name, NULL, 0); + +static struct attribute *adt7408_attributes[] = { + &iio_dev_attr_available_modes.dev_attr.attr, + &iio_dev_attr_mode.dev_attr.attr, + &iio_dev_attr_capability.dev_attr.attr, + &iio_dev_attr_device_id.dev_attr.attr, + &iio_dev_attr_manufactory_id.dev_attr.attr, + &iio_dev_attr_value.dev_attr.attr, + &iio_dev_attr_name.dev_attr.attr, +NULL , +};drivers/staging/iio/adc/adt7408.c
Quoted 10 lines
drivers/staging/iio/adc/adt7408.c new file +10
-0+ +static const struct attribute_group adt7408_attribute_group = { + .attrs = adt7408_attributes, +}; + +/* +* temperature bound events +*/ + +#define IIO_EVENT_CODE_ADT7408_ABOVE_ALARM (
IIO_EVENT_CODE_DEVICE_SPECIFIC+ 1)drivers/staging/iio/adc/adt7408.c line 312
Quoted 1 line
drivers/staging/iio/adc/adt7408.c new file +1
-0+#define IIO_EVENT_CODE_ADT7408_BELLOW_ALARM (
IIO_EVENT_CODE_DEVICE_SPECIFIC+ 2)drivers/staging/iio/adc/adt7408.c line 313
Quoted 1 line
drivers/staging/iio/adc/adt7408.c new file +1
-0+#define IIO_EVENT_CODE_ADT7408_ABOVE_CRIT (
IIO_EVENT_CODE_DEVICE_SPECIFIC+ 3)drivers/staging/iio/adc/adt7408.c
Quoted 4 lines
drivers/staging/iio/adc/adt7408.c new file +4
-0+ +static void adt7408_interrupt_bh (struct work_struct *work_s) { +struct adt7408_chip_info *chip = + container_of(work_s, struct adt7408_chip_info,
thresh_work);Quoted 89 lines
drivers/staging/iio/adc/adt7408.c new file +89
-0+u16 config; +u16 data; + +if (adt7408_i2c_read (chip,ADT7408_CONFIG , &chip->config)) +return ; + +if (!(chip->config &ADT7408_EVENT_STATUS )) +return ; + + config = chip->config & ~ADT7408_EVENT_CLEAR ; +if (data) + config |=ADT7408_EVENT_CLEAR ; + +adt7408_i2c_write (chip,ADT7408_CONFIG , config); + +if (adt7408_i2c_read (chip,ADT7408_TEMPERATURE , &data)) + goto exit; + +if (data &ADT7408_T_ABOVE_ALARM ) +iio_push_event (chip->indio_dev,0 , +IIO_EVENT_CODE_ADT7408_ABOVE_ALARM , + chip->last_timestamp); +if (data &ADT7408_T_BELLOW_ALARM ) +iio_push_event (chip->indio_dev,0 , +IIO_EVENT_CODE_ADT7408_BELLOW_ALARM , + chip->last_timestamp); +if (data &ADT7408_T_ABOVE_CRIT ) +iio_push_event (chip->indio_dev,0 , +IIO_EVENT_CODE_ADT7408_ABOVE_CRIT , + chip->last_timestamp); +exit: +enable_irq (chip->client->irq); +} + +static int adt7408_interrupt (struct iio_dev *dev_info, +int index, +s64 timestamp, +int no_test) +{ +struct adt7408_chip_info *chip = dev_info->dev_data; + + chip->last_timestamp = timestamp; +schedule_work (&chip->thresh_work); + +return 0 ; +} + +IIO_EVENT_SH (adt7408, &adt7408_interrupt); + +static ssize_t adt7408_show_event_mode (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +int ret; + + ret =adt7408_i2c_read (chip,ADT7408_CONFIG , &chip->config); +if (ret) +return -EIO ; + +if (chip->config &ADT7408_EVENT_MODE ) +return sprintf (buf,"interrupt\n" ); +else +return sprintf (buf,"comparator\n" ); } + +static ssize_t adt7408_set_event_mode (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +u16 config; +int ret; + +if (adt7408_is_event_locked (chip)) { +dev_err (dev,"Warning: Events are locked.\n" ); +return -EIO ; + } + + ret =adt7408_i2c_read (chip,ADT7408_CONFIG , &chip->config); +if (ret) +return -EIO ; + + config = chip->config &= ~ADT7408_EVENT_MODE ; +if (strcmp (buf,"comparator" ) !=0 ) + config |=ADT7408_EVENT_MODE ; +drivers/staging/iio/adc/adt7408.c
Quoted 10 lines
drivers/staging/iio/adc/adt7408.c new file +10
-0+ ret =adt7408_i2c_write (chip,ADT7408_CONFIG , config); +if (ret) +return -EIO ; + + chip->config = config; + +return ret; +} + +static ssize_t adt7408_show_available_event_modes(structdevice *dev,
Quoted 394 lines
drivers/staging/iio/adc/adt7408.c new file +394
-0+struct device_attribute *attr, + char *buf) +{ + return sprintf(buf, "comparator\ninterrupt\n"); } + +static ssize_t adt7408_show_event_crit_only (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +int ret; + + ret =adt7408_i2c_read (chip,ADT7408_CONFIG , &chip->config); +if (ret) +return -EIO ; + +return sprintf (buf,"%d\n" , !!(chip->config & +ADT7408_EVENT_CRIT_ONLY )); } + +static ssize_t adt7408_set_event_crit_only (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +unsigned long data =0 ; +u16 config; +int ret; + +if (adt7408_is_event_locked (chip)) { +dev_err (dev,"Warning: Events are locked.\n" ); +return -EIO ; + } + + ret =strict_strtoul (buf,10 , &data); +if (ret) +return -EINVAL ; + + ret =adt7408_i2c_read (chip,ADT7408_CONFIG , &chip->config); +if (ret) +return -EIO ; + + config = chip->config &= ~ADT7408_EVENT_CRIT_ONLY ; +if (data) + config |=ADT7408_EVENT_CRIT_ONLY ; + + ret =adt7408_i2c_write (chip,ADT7408_CONFIG , config); +if (ret) +return -EIO ; + + chip->config = config; + +return ret; +} + +static ssize_t adt7408_show_event_enable (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +int ret; + + ret =adt7408_i2c_read (chip,ADT7408_CONFIG , &chip->config); +if (ret) +return -EIO ; + +return sprintf (buf,"%d\n" , !!(chip->config & +ADT7408_EVENT_ENABLE )); } + +static ssize_t adt7408_set_event_enable (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +unsigned long data; +u16 config; +int ret; + +if (adt7408_is_event_locked (chip)) { +dev_err (dev,"Warning: Events are locked.\n" ); +return -EIO ; + } + + ret =strict_strtoul (buf,10 , &data); +if (ret) +return -EINVAL ; + + ret =adt7408_i2c_read (chip,ADT7408_CONFIG , &chip->config); +if (ret) +return -EIO ; + + config = chip->config & ~ADT7408_EVENT_ENABLE ; +if (data) + config |=ADT7408_EVENT_ENABLE ; + + ret =adt7408_i2c_write (chip,ADT7408_CONFIG , config); +if (ret) +return -EIO ; + + chip->config = config; + +return ret; +} + +static ssize_t adt7408_show_alarm_lock (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +int ret; + + ret =adt7408_i2c_read (chip,ADT7408_CONFIG , &chip->config); +if (ret) +return -EIO ; + +return sprintf (buf,"%d\n" , !!(chip->config & +ADT7408_EVENT_ALARM_LOCK )); } + +static ssize_t adt7408_set_alarm_lock (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +unsigned long data; +u16 config; +int ret; + + ret =strict_strtoul (buf,10 , &data); +if (ret) +return -EINVAL ; + + ret =adt7408_i2c_read (chip,ADT7408_CONFIG , &chip->config); +if (ret) +return -EIO ; + + config = chip->config & ~ADT7408_EVENT_ALARM_LOCK ; +if (data) + config |=ADT7408_EVENT_ALARM_LOCK ; + + ret =adt7408_i2c_write (chip,ADT7408_CONFIG , config); +if (ret) +return -EIO ; + + chip->config = config; + +return ret; +} + +static ssize_t adt7408_show_crit_lock (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +int ret; + + ret =adt7408_i2c_read (chip,ADT7408_CONFIG , &chip->config); +if (ret) +return -EIO ; + +return sprintf (buf,"%d\n" , !!(chip->config & +ADT7408_EVENT_CRIT_LOCK )); } + +static ssize_t adt7408_set_crit_lock (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +unsigned long data; +u16 config; +int ret; + + ret =strict_strtoul (buf,10 , &data); +if (ret) +return -EINVAL ; + + ret =adt7408_i2c_read (chip,ADT7408_CONFIG , &chip->config); +if (ret) +return -EIO ; + + config = chip->config & ~ADT7408_EVENT_CRIT_LOCK ; +if (data) + config |=ADT7408_EVENT_CRIT_LOCK ; + + ret =adt7408_i2c_write (chip,ADT7408_CONFIG , config); +if (ret) +return -EIO ; + + chip->config = config; + +return ret; +} + + +static inline ssize_t adt7408_show_t_bound (struct device *dev, +struct device_attribute *attr, +u8 bound_reg, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +u16 data; +char sign =' ' ; +int ret; + + ret =adt7408_i2c_read (chip, bound_reg, &data); +if (ret) +return -EIO ; + + data >>=ADT7408_BOUND_VALUE_OFFSET ; +if (data &ADT7408_BOUND_VALUE_SIGN ) { +/* convert supplement to positive value */ + data = (ADT7408_BOUND_VALUE_SIGN <<1 ) - data; + sign ='-' ; + } + +return sprintf (buf,"%c%d.%.2d\n" , sign, + data >>ADT7408_BOUND_VALUE_FLOAT_OFFSET , + (data &ADT7408_BOUND_VALUE_FLOAT_MASK ) *25 ); } + +static inline ssize_t adt7408_set_t_bound (struct device *dev, +struct device_attribute *attr, +u8 bound_reg, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +long tmp1, tmp2; +u16 data; +char *pos; +int ret; + + pos =strchr (buf,'.' ); + + ret =strict_strtol (buf,10 , &tmp1); + +if (ret || tmp1 >127 || tmp1 <-128 ) +return -EINVAL ; + +if (pos) { + len =strlen (pos); +if (len >ADT7408_BOUND_VALUE_FLOAT_OFFSET ) + len =ADT7408_BOUND_VALUE_FLOAT_OFFSET ; + pos[len] =0 ; + ret =strict_strtol (pos,10 , &tmp2); + +if (!ret) + tmp2 = (tmp2 /25 ) *25 ; + } + +if (tmp1 <0 ) + data = (u16)(-tmp1); +else + data = (u16 )tmp1; + data = (data <<ADT7408_BOUND_VALUE_FLOAT_OFFSET ) | + (tmp2 &ADT7408_BOUND_VALUE_FLOAT_MASK ); +if (tmp1 <0 ) +/* convert positive value to supplyment */ + data = (ADT7408_BOUND_VALUE_SIGN <<1 ) - data; + data <<=ADT7408_BOUND_VALUE_OFFSET ; + + ret =adt7408_i2c_write (chip, bound_reg, data); +if (ret) +return -EIO ; + +return ret; +} + +static ssize_t adt7408_show_t_alarm_high (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return adt7408_show_t_bound (dev, attr, +ADT7408_T_ALARM_HIGH , buf); +} + +static inline ssize_t adt7408_set_t_alarm_high (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +return adt7408_set_t_bound (dev, attr, +ADT7408_T_ALARM_HIGH , buf, len); +} + +static ssize_t adt7408_show_t_alarm_low (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return adt7408_show_t_bound (dev, attr, +ADT7408_T_ALARM_LOW , buf); +} + +static inline ssize_t adt7408_set_t_alarm_low (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +return adt7408_set_t_bound (dev, attr, +ADT7408_T_ALARM_LOW , buf, len); +} + +static ssize_t adt7408_show_t_crit (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return adt7408_show_t_bound (dev, attr, +ADT7408_T_CRIT , buf); +} + +static inline ssize_t adt7408_set_t_crit (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +return adt7408_set_t_bound (dev, attr, +ADT7408_T_CRIT , buf, len); +} + +static ssize_t adt7408_show_t_hyst (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +int ret; + +/* retrive ALART status */ + ret =adt7408_i2c_read (chip,ADT7408_CONFIG , &chip->config); +if (ret) +return -EIO ; + +switch (chip->config &ADT7408_HISTERESIS_MASK ) { +case ADT7408_HISTERESIS_1_5 : +return sprintf (buf,"1.5\n" ); +case ADT7408_HISTERESIS_3 : +return sprintf (buf,"3\n" ); +case ADT7408_HISTERESIS_6 : +return sprintf (buf,"6\n" ); +default : +return sprintf (buf,"Disabled\n" ); + } +} + +static inline ssize_t adt7408_set_t_hyst (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct adt7408_chip_info *chip = dev_info->dev_data; +int ret; +u16 config =0 ; + +if (strcmp (buf,"disble" )) + config =ADT7408_HISTERESIS_MASK ; +else if (strcmp (buf,"1.5" )) + config =ADT7408_HISTERESIS_1_5 ; +else if (len >1 && buf[0 ] =='3' ) + config =ADT7408_HISTERESIS_6 ; +else if (len >1 && buf[0 ] =='6' ) + config =ADT7408_HISTERESIS_6 ; + +if (!config) +return -EINVAL ; + +/* retrive ALART status */ + ret =adt7408_i2c_read (chip,ADT7408_CONFIG , &chip->config); +if (ret) +return -EIO ; + + config |= chip->config & ~ADT7408_HISTERESIS_MASK ; + + ret =adt7408_i2c_write (chip,ADT7408_CONFIG , config); +if (ret) +return -EIO ; + + chip->config = config; +return ret; +} + +static ssize_t adt7408_show_available_t_hyst(struct device *dev, + struct device_attribute *attr,drivers/staging/iio/adc/adt7408.c
Quoted 10 lines
drivers/staging/iio/adc/adt7408.c new file +10
-0+ char *buf) +{ +return sprintf (buf,"1.5\n3\n6\ndisable\n" ); } + +IIO_EVENT_ATTR_SH (event_mode, iio_event_adt7408, + adt7408_show_event_mode, adt7408_set_event_mode,0 ); +IIO_EVENT_ATTR_SH (available_event_modes, iio_event_adt7408, + adt7408_show_available_event_modes,NULL ,0 ); +IIO_EVENT_ATTR_SH(event_crit_only, iio_event_adt7408, + adt7408_show_event_crit_only,
adt7408_set_event_crit_only, 0);drivers/staging/iio/adc/adt7408.c line 822
Quoted 2 lines
drivers/staging/iio/adc/adt7408.c new file +2
-0+IIO_EVENT_ATTR_SH(event_enable, iio_event_adt7408, + adt7408_show_event_enable,
adt7408_set_event_enable, 0);drivers/staging/iio/adc/adt7408.c
Quoted 6 lines
drivers/staging/iio/adc/adt7408.c new file +6
-0+IIO_EVENT_ATTR_SH (alarm_lock, iio_event_adt7408, + adt7408_show_alarm_lock, adt7408_set_alarm_lock,0 ); +IIO_EVENT_ATTR_SH (crit_lock, iio_event_adt7408, + adt7408_show_crit_lock, adt7408_set_crit_lock,0 ); +IIO_EVENT_ATTR_SH(t_alarm_high, iio_event_adt7408, + adt7408_show_t_alarm_high,
adt7408_set_t_alarm_high, 0);Quoted 68 lines
drivers/staging/iio/adc/adt7408.c new file +68
-0+IIO_EVENT_ATTR_SH (t_alarm_low, iio_event_adt7408, + adt7408_show_t_alarm_low, adt7408_set_t_alarm_low,0 ); +IIO_EVENT_ATTR_SH (t_crit, iio_event_adt7408, + adt7408_show_t_crit, adt7408_set_t_crit,0 ); +IIO_EVENT_ATTR_SH (t_hyst, iio_event_adt7408, + adt7408_show_t_hyst, adt7408_set_t_hyst,0 ); +IIO_EVENT_ATTR_SH (available_t_hyst, iio_event_adt7408, + adt7408_show_available_t_hyst,NULL ,0 ); + +static struct attribute *adt7408_event_attributes[] = { + &iio_event_attr_event_mode.dev_attr.attr, + &iio_event_attr_available_event_modes.dev_attr.attr, + &iio_event_attr_event_crit_only.dev_attr.attr, + &iio_event_attr_event_enable.dev_attr.attr, + &iio_event_attr_alarm_lock.dev_attr.attr, + &iio_event_attr_crit_lock.dev_attr.attr, + &iio_event_attr_t_alarm_high.dev_attr.attr, + &iio_event_attr_t_alarm_low.dev_attr.attr, + &iio_event_attr_t_crit.dev_attr.attr, + &iio_event_attr_t_hyst.dev_attr.attr, + &iio_event_attr_available_t_hyst.dev_attr.attr, +NULL , +}; + +static struct attribute_group adt7408_event_attribute_group = { + .attrs = adt7408_event_attributes, +}; + +/* +* device probe and remove +*/ + +static int __devinit adt7408_probe (struct i2c_client *client, +const struct i2c_device_id *id) +{ +struct adt7408_chip_info *chip; +int ret =0 ; + + chip =kzalloc (sizeof (struct adt7408_chip_info ),GFP_KERNEL ); + +if (chip ==NULL ) +return -ENOMEM ; + +/* this is only used for device removal purposes */ +i2c_set_clientdata (client, chip); + + chip->client = client; + chip->name = id->name; + + chip->indio_dev =iio_allocate_device (); +if (chip->indio_dev ==NULL ) { + ret = -ENOMEM ; + goto error_free_chip; + } + + chip->indio_dev->dev.parent = &client->dev; + chip->indio_dev->attrs = &adt7408_attribute_group; + chip->indio_dev->event_attrs = &adt7408_event_attribute_group; + chip->indio_dev->dev_data = (void *)chip; + chip->indio_dev->driver_module =THIS_MODULE ; + chip->indio_dev->num_interrupt_lines =1 ; + chip->indio_dev->modes =INDIO_DIRECT_MODE ; + + ret =iio_device_register (chip->indio_dev); +if (ret) + goto error_free_dev; + +if (client->irq) {drivers/staging/iio/adc/adt7408.c
Quoted 10 lines
drivers/staging/iio/adc/adt7408.c new file +10
-0+ ret =iio_register_interrupt_line (client->irq, + chip->indio_dev, +0 , + client->irq_flags, + chip->name); +if (ret) + goto error_unreg_dev; + +/* +* The event handler list element refer to
iio_event_adt7408.drivers/staging/iio/adc/adt7408.c line 922
Quoted 5 lines
drivers/staging/iio/adc/adt7408.c new file +5
-0+* All event attributes bind to the same event handler. +* So, only register event handler once. +*/ + iio_add_event_to_list(&iio_event_adt7408, +&chip->indio_dev->interrupts[0]->ev_list);
drivers/staging/iio/adc/adt7408.c
Quoted 4 lines
drivers/staging/iio/adc/adt7408.c new file +4
-0+ +INIT_WORK (&chip->thresh_work, adt7408_interrupt_bh); + + ret = adt7408_i2c_read(chip, ADT7408_CONFIG,
&chip->config);drivers/staging/iio/adc/adt7408.c
Quoted 11 lines
drivers/staging/iio/adc/adt7408.c new file +11
-0+if (ret) { + ret = -EIO ; + goto error_unreg_irq; + } + +if (client->irq_flags &IRQF_TRIGGER_HIGH ) + chip->config |=ADT7408_EVENT_POLARITY ; +else + chip->config &= ~ADT7408_EVENT_POLARITY ; + + ret = adt7408_i2c_write(chip, ADT7408_CONFIG,
chip->config);Quoted 67 lines
drivers/staging/iio/adc/adt7408.c new file +67
-0+if (ret) { + ret = -EIO ; + goto error_unreg_irq; + } + } + +dev_info (&client->dev,"%s temperature sensor registered.\n" , + id->name); + +return 0 ; + +error_unreg_irq: +iio_unregister_interrupt_line (chip->indio_dev,0 ); +error_unreg_dev: +iio_device_unregister (chip->indio_dev); +error_free_dev: +iio_free_device (chip->indio_dev); +error_free_chip: +kfree (chip); + +return ret; +} + +static int __devexit adt7408_remove(struct i2c_client *client) { +struct adt7408_chip_info *chip =i2c_get_clientdata (client); +struct iio_dev *indio_dev = chip->indio_dev; + +if (client->irq) +iio_unregister_interrupt_line (indio_dev,0 ); +iio_device_unregister (indio_dev); +iio_free_device (chip->indio_dev); +kfree (chip); + +return 0 ; +} + +static const struct i2c_device_id adt7408_id[] = { + {"adt7408" ,0 }, + {} +}; + +MODULE_DEVICE_TABLE (i2c, adt7408_id); + +static struct i2c_driver adt7408_driver = { + .driver = { + .name ="adt7408" , + }, + .probe = adt7408_probe, + .remove =__devexit_p (adt7408_remove), + .id_table = adt7408_id, +}; + +static __init int adt7408_init (void ) +{ +return i2c_add_driver (&adt7408_driver); } + +static __exit void adt7408_exit(void) { +i2c_del_driver (&adt7408_driver); +} + +MODULE_AUTHOR ("Sonic Zhang <[email protected]>" ); +MODULE_DESCRIPTION ("Analog Devices ADT7408 digital" +" temperature sensor driver" ); +MODULE_LICENSE ("GPL v2" ); + +module_init (adt7408_init); +module_exit (adt7408_exit);
Re: [PATCH 12/14] staging: iio: adc: new driver for ADT7408 temperature sensors
Quoted 18 lines · Jonathan Cameron
Quoted 17 lines · Sonic
Quoted 16 lines
-----Original Message-----
From: Jonathan Cameron [mailto:[email protected]]
Sent: Monday, October 25, 2010 6:54 AM
To: Mike Frysinger
Cc: [email protected]; [email protected]; Zhang, Sonic; Guenter Roeck
Subject: Re: [PATCH 12/14] staging: iio: adc: new driver for ADT7408 temperature sensorsQuoted 1 line · Mike Frysinger
From: Sonic Zhang <[email protected]>
Here we enter new territory. This device is already supported in hwmon. Do we have a usecase that is not covered by that driver?
Quoted 7 lines
Quoted 3 lines
I don't find a way to get event notification other than poll in hwmon framework. So, I move all temperature devic with interrupt available to IIO framework.
Whilst it isn't often done (and is a little clunky). It is possible to select on sysfs attributes much like any other file. I'm sure Guenter can tell us if any current hwmon devices are doing this?
One can always use sysfs_notify(). Not sure I understand what is clunky about it. gpio-fan uses it, and I have used it as well in an internal driver. Works pretty well.
I thought that is what was meant with "poll" [ie poll (2)], and somehow considered to not be good enough. Would be nice to know the reasons, though, and how iio does better than that. Maybe I need to spend some time reading the iio documentation.
Guenter
Re: [PATCH 12/14] staging: iio: adc: new driver for ADT7408 temperature sensors
Quoted 27 lines · Guenter Roeck
Quoted 18 lines · Jonathan Cameron
Quoted 17 lines · Sonic
Quoted 16 lines
-----Original Message-----
From: Jonathan Cameron [mailto:[email protected]]
Sent: Monday, October 25, 2010 6:54 AM
To: Mike Frysinger
Cc: [email protected]; [email protected]; Zhang, Sonic; Guenter Roeck
Subject: Re: [PATCH 12/14] staging: iio: adc: new driver for ADT7408 temperature sensorsQuoted 1 line · Mike Frysinger
From: Sonic Zhang <[email protected]>
Here we enter new territory. This device is already supported in hwmon. Do we have a usecase that is not covered by that driver?
Quoted 7 lines
Quoted 3 lines
I don't find a way to get event notification other than poll in hwmon framework. So, I move all temperature devic with interrupt available to IIO framework.
Whilst it isn't often done (and is a little clunky). It is possible to select on sysfs attributes much like any other file. I'm sure Guenter can tell us if any current hwmon devices are doing this?
Quoted 6 lines
One can always use
sysfs_notify(). Not sure I understand what is clunky about it. gpio-fan uses it, and I have used it as well in an internal driver. Works pretty well.I thought that is what was meant with "poll" [ie poll (2)], and somehow considered to not be good enough. Would be nice to know the reasons, though, and how iio does better than that. Maybe I need to spend some time reading the iio documentation.
As a quick and dirty summary. IIO does it roughly the same way as input, be it heavily stripped down. Character device rather than sysfs for events.
This is from memory, but I think the main issue with sysfs_notify is that, whilst you can poll on any file, all of those in a given directory will wake up on a call of sysfs_notify. In devices with one or two alarms that is probably fine as you can just read them all, but we have devices with 10s of different alarms. Hence you don't want to be reading lots of files to find out what is going on. A single alarm file would be fine if only one could trigger simultaneously, but that's rarely the case. Any sort of 'what alarm has triggered' mask is clunky and difficult to generalize.
We try to use sysfs for what it is good at (low bandwidth direct reading from devices and configuration of those devices) and character devices for the high bandwidth stuff.
Jonathan
Re: [PATCH 12/14] staging: iio: adc: new driver for ADT7408 temperature sensors
Hi Jonathan,
Quoted 31 lines · Jonathan Cameron
Quoted 30 lines · Guenter Roeck
Quoted 18 lines · Jonathan Cameron
Quoted 17 lines · Sonic
Quoted 16 lines
-----Original Message-----
From: Jonathan Cameron [mailto:[email protected]]
Sent: Monday, October 25, 2010 6:54 AM
To: Mike Frysinger
Cc: [email protected]; [email protected]; Zhang, Sonic; Guenter Roeck
Subject: Re: [PATCH 12/14] staging: iio: adc: new driver for ADT7408 temperature sensorsQuoted 1 line · Mike Frysinger
From: Sonic Zhang <[email protected]>
Here we enter new territory. This device is already supported in hwmon. Do we have a usecase that is not covered by that driver?
Quoted 7 lines
Quoted 3 lines
I don't find a way to get event notification other than poll in hwmon framework. So, I move all temperature devic with interrupt available to IIO framework.
Whilst it isn't often done (and is a little clunky). It is possible to select on sysfs attributes much like any other file. I'm sure Guenter can tell us if any current hwmon devices are doing this?
One can always use
sysfs_notify(). Not sure I understand what is clunky about it. gpio-fan uses it, and I have used it as well in an internal driver. Works pretty well.
Quoted 10 lines
Quoted 3 lines
I thought that is what was meant with "poll" [ie poll (2)], and somehow considered to not be good enough. Would be nice to know the reasons, though, and how iio does better than that. Maybe I need to spend some time reading the iio documentation.
As a quick and dirty summary. IIO does it roughly the same way as input, be it heavily stripped down. Character device rather than sysfs for events.
This is from memory, but I think the main issue with
sysfs_notifyis that, whilst you can poll on any file, all of those in a given directory will wake up on a call ofsysfs_notify.Quoted 1 line
From looking at the code, I don't think that is true. It should only happen if the attribute
name is not specified in the call. From a logical perspective, it would not make much sense to have the attribute name as parameter if it is just ignored - and the call does not ignore it.
I'll do some testing to verify this. But even if it is true, I would assume it to be a bug that should be fixed, and not be used as argument to move drivers out of sysfs.
Quoted 6 lines
In devices with one or two alarms that is probably fine as you can just read them all, but we have devices with 10s of different alarms. Hence you don't want to be reading lots of files to find out what is going on. A single alarm file would be fine if only one could trigger simultaneously, but that's rarely the case. Any sort of 'what alarm has triggered' mask is clunky and difficult to generalize.
select() is clunky ?
Quoted 3 lines
We try to use sysfs for what it is good at (low bandwidth direct reading from devices and configuration of those devices) and character devices for the high bandwidth stuff.
Makes sense. But right now I am not entirely sure if some sysfs bashing got in there along the way.
Note that I would not be opposed to some thinking about the hwmon user interface and how to improve it, or even merge it with iio if that makes sense. I have a system which right now reports 301 (!) alarm files, and I am not even done with all drivers. That _is_ getting a bit large. But there should be a discussion about it. I don't think that providing parallel drivers in different subsystems is a solution. And writing hwmon drivers into iio with no driver in hwmon isn't a solution either.
Thanks,
Guenter
Re: [PATCH 12/14] staging: iio: adc: new driver for ADT7408 temperature sensors
Quoted 43 lines · Guenter Roeck
Hi Jonathan,
Quoted 39 lines · Jonathan Cameron
Quoted 27 lines · Guenter Roeck
Quoted 18 lines · Jonathan Cameron
Quoted 17 lines · Sonic
Quoted 16 lines
-----Original Message-----
From: Jonathan Cameron [mailto:[email protected]]
Sent: Monday, October 25, 2010 6:54 AM
To: Mike Frysinger
Cc: [email protected]; [email protected]; Zhang, Sonic; Guenter Roeck
Subject: Re: [PATCH 12/14] staging: iio: adc: new driver for ADT7408 temperature sensorsQuoted 1 line · Mike Frysinger
From: Sonic Zhang <[email protected]>
Here we enter new territory. This device is already supported in hwmon. Do we have a usecase that is not covered by that driver?
Quoted 7 lines
Quoted 3 lines
I don't find a way to get event notification other than poll in hwmon framework. So, I move all temperature devic with interrupt available to IIO framework.
Whilst it isn't often done (and is a little clunky). It is possible to select on sysfs attributes much like any other file. I'm sure Guenter can tell us if any current hwmon devices are doing this?
Quoted 6 lines
One can always use
sysfs_notify(). Not sure I understand what is clunky about it. gpio-fan uses it, and I have used it as well in an internal driver. Works pretty well.I thought that is what was meant with "poll" [ie poll (2)], and somehow considered to not be good enough. Would be nice to know the reasons, though, and how iio does better than that. Maybe I need to spend some time reading the iio documentation.
As a quick and dirty summary. IIO does it roughly the same way as input, be it heavily stripped down. Character device rather than sysfs for events.
This is from memory, but I think the main issue with
sysfs_notifyis that, whilst you can poll on any file, all of those in a given directory will wake up on a call ofsysfs_notify.
Quoted 6 lines
Quoted 1 line
Quoted 1 line
From looking at the code, I don't think that is true. It should only happen if the attribute
name is not specified in the call. From a logical perspective, it would not make much sense to have the attribute name as parameter if it is just ignored - and the call does not ignore it.
I'll do some testing to verify this. But even if it is true, I would assume it to be a bug that should be fixed, and not be used as argument to move drivers out of sysfs.
It's been a while since I looked at it, and it doesn't seem to be a terribly well documented bit of sysfs. I may well have just imagined the whole directory only thing... certainly looks to use the individual attributes.
So question is whether a big event system can be well covered by this. Next issue for us is timed events (which we care about, but I'm guessing hwmon does not). The only data we associate with an event at the moment (other than what it was) is the timestamp...
There is clearly a fair bit of overhead in the notify functions, but no idea how significant that will be. The sysfs_find_dirent calls all use a strcmp to match against the attribute name for starters.
Quoted 8 lines
Quoted 7 lines
In devices with one or two alarms that is probably fine as you can just read them all, but we have devices with 10s of different alarms. Hence you don't want to be reading lots of files to find out what is going on. A single alarm file would be fine if only one could trigger simultaneously, but that's rarely the case. Any sort of 'what alarm has triggered' mask is clunky and difficult to generalize.
select()is clunky ?
select is fine. My comment was based on the false assumption the notify was directory wide. Really no idea what made me think that in the first place....
Quoted 6 lines
Quoted 4 lines
We try to use sysfs for what it is good at (low bandwidth direct reading from devices and configuration of those devices) and character devices for the high bandwidth stuff.
Makes sense. But right now I am not entirely sure if some sysfs bashing got in there along the way.
Certainly possible!
Quoted 4 lines
Note that I would not be opposed to some thinking about the hwmon user interface and how to improve it, or even merge it with iio if that makes sense. I have a system which right now reports 301 (!) alarm files, and I am not even done with all drivers.
Ouch :)
Quoted 3 lines
That _is_ getting a bit large. But there should be a discussion about it. I don't think that providing parallel drivers in different subsystems is a solution. And writing hwmon drivers into iio with no driver in hwmon isn't a solution either.
Agreed, we need to work on this. To us, these devices are a fairly small corner, but one we would definitely like to handle sensibly and well. The tricky bit comes in doing this without causing problems for other types of device.
Jonathan
PATCH 13/14 staging: iio: adc: new driver for ADT7410 temperature sensors
In reply to Mike FrysingerFrom: Sonic Zhang <[email protected]>
--- drivers/staging/iio/adc/Kconfig | 7 + drivers/staging/iio/adc/Makefile | 1 + drivers/staging/iio/adc/adt7410.c | 917 +++++++++++++++++++++++++++++++++++++ 3 files changed, 925 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/iio/adc/adt7410.c
drivers/staging/iio/adc/Kconfig +7 -0
@@ -121,3 +121,10 @@ config ADT7410 help Say yes here to build support for Analog Devices ADT7410 temperature sensors. + +config ADT7310 + tristate "Analog Devices ADT7310 temperature sensor driver" + depends on SPI + help + Say yes here to build support for Analog Devices ADT7310 + temperature sensors.
drivers/staging/iio/adc/Makefile +1 -0
@@ -22,3 +22,4 @@ obj-$(CONFIG_AD7816) += ad7816.o obj-$(CONFIG_ADT75) += adt75.o obj-$(CONFIG_ADT7310) += adt7310.o obj-$(CONFIG_ADT7408) += adt7408.o +obj-$(CONFIG_ADT7410) += adt7410.o
drivers/staging/iio/adc/adt7410.c new file +917 -0
917 lines not on this page · raw message
Signature · 1 line
1.7.3.2
PATCH 14/14 staging: iio: adc: new ad799x driver
In reply to Mike FrysingerFrom: Michael Hennerich <[email protected]>
Driver for ad7991, ad7995, ad7999, ad7992, ad7993, ad7994, ad7997 and ad7998 multichannel ADC.
--- drivers/staging/iio/adc/Kconfig | 20 + drivers/staging/iio/adc/Makefile | 4 + drivers/staging/iio/adc/ad799x.h | 168 ++++++ drivers/staging/iio/adc/ad799x_core.c | 912 +++++++++++++++++++++++++++++++++ drivers/staging/iio/adc/ad799x_ring.c | 281 ++++++++++ 5 files changed, 1385 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/iio/adc/ad799x.h create mode 100644 drivers/staging/iio/adc/ad799x_core.c create mode 100644 drivers/staging/iio/adc/ad799x_ring.c
drivers/staging/iio/adc/Kconfig +20 -0
@@ -101,6 +101,26 @@ config AD7816 Say yes here to build support for Analog Devices AD7816/7/8 temperature sensors and ADC. +config AD799X + tristate "Analog Devices AD799x ADC driver" + depends on I2C + select IIO_TRIGGER if IIO_RING_BUFFER + select AD799X_RING_BUFFER + help + Say yes here to build support for Analog Devices: + ad7991, ad7995, ad7999, ad7992, ad7993, ad7994, ad7997, ad7998 + i2c analog to digital convertors (ADC). Provides direct access + via sysfs. + +config AD799X_RING_BUFFER + bool "Analog Devices AD799x: use ring buffer" + depends on AD799X + select IIO_RING_BUFFER + select IIO_SW_RING + help + Say yes here to include ring buffer support in the AD799X + ADC driver. + config ADT75 tristate "Analog Devices ADT75 temperature sensor driver" depends on I2C
drivers/staging/iio/adc/Makefile +4 -0
@@ -8,6 +8,9 @@ max1363-y += max1363_ring.o ad7476-y := ad7476_core.o ad7476-$(CONFIG_IIO_RING_BUFFER) += ad7476_ring.o +ad799x-y := ad799x_core.o +ad799x-$(CONFIG_AD799X_RING_BUFFER) += ad799x_ring.o + obj-$(CONFIG_MAX1363) += max1363.o obj-$(CONFIG_AD7150) += ad7150.o obj-$(CONFIG_AD7152) += ad7152.o
@@ -19,6 +22,7 @@ obj-$(CONFIG_AD7416) += ad7416.o obj-$(CONFIG_AD7476) += ad7476.o obj-$(CONFIG_AD774X) += ad774x.o obj-$(CONFIG_AD7816) += ad7816.o +obj-$(CONFIG_AD799X) += ad799x.o obj-$(CONFIG_ADT75) += adt75.o obj-$(CONFIG_ADT7310) += adt7310.o obj-$(CONFIG_ADT7408) += adt7408.o
drivers/staging/iio/adc/ad799x.h new file +168 -0
168 lines not on this page · raw message
drivers/staging/iio/adc/ad799x_core.c new file +912 -0
912 lines not on this page · raw message
drivers/staging/iio/adc/ad799x_ring.c new file +281 -0
281 lines not on this page · raw message
Signature · 1 line
1.7.3.2
Re: [Device-drivers-devel] [PATCH 14/14] staging: iio: adc: new ad799x driver
i guess this one is already merged into staging-next, so it can be ignored -mike
Re: [PATCH 14/14] staging: iio: adc: new ad799x driver
In reply to Mike FrysingerQuoted 4 lines · Mike Frysinger
From: Michael Hennerich <[email protected]>
Driver for ad7991, ad7995, ad7999, ad7992, ad7993, ad7994, ad7997 and ad7998 multichannel ADC.
Another one that has already merged.
Quoted 13 lines
Signed-off-by Michael Hennerich <[email protected]>Signed-off-by Mike Frysinger <[email protected]>--- drivers/staging/iio/adc/Kconfig | 20 + drivers/staging/iio/adc/Makefile | 4 + drivers/staging/iio/adc/ad799x.h | 168 ++++++ drivers/staging/iio/adc/ad799x_core.c | 912 +++++++++++++++++++++++++++++++++ drivers/staging/iio/adc/ad799x_ring.c | 281 ++++++++++ 5 files changed, 1385 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/iio/adc/ad799x.h create mode 100644 drivers/staging/iio/adc/ad799x_core.c create mode 100644 drivers/staging/iio/adc/ad799x_ring.c
...
Quoted 2 lines · Mike Frysinger
From: Barry Song <[email protected]>
For new device classes like this I'd prefer to see the abi posted on the mailing list at an early stage as we'd have changed a few things. As you said in your other email we can fix these at a later date as long as everyone is aware the abi isn't fixed as of yet!
Lots of new abi that we will want to standardize, document and pin down fully including some dreaded magic register writing :) Also some current abi breakage that needs fixing soonish.
Few nitpicks inline.
Looks like it would benefit from a quick checkpatch run.
There is stuff I'm not happy with but as you have said that can get fixed afterwards, so subject to the changes needed to make it build, send it on to Greg.
Quoted 2 lines
Signed-off-by Barry Song <[email protected]>Signed-off-by Mike Frysinger <[email protected]>
Quoted 92 lines
--- drivers/staging/iio/adc/Kconfig | 7 + drivers/staging/iio/adc/Makefile | 1 + drivers/staging/iio/adc/ad7152.c | 610 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 618 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/iio/adc/ad7152.cdrivers/staging/iio/adc/Kconfig +7
-0@@ -33,3 +33,10 @@ config AD7150 help Say yes here to build support for Analog Devices capacitive sensors. (ad7150, ad7151, ad7156) Provides direct access via sysfs. + +config AD7152 + tristate "Analog Devices ad7152/3 capacitive sensor driver" + depends on I2C + help + Say yes here to build support for Analog Devices capacitive sensors. + (ad7152, ad7153) Provides direct access via sysfs.drivers/staging/iio/adc/Makefile +1
-0@@ -7,3 +7,4 @@ max1363-y += max1363_ring.o obj-$(CONFIG_MAX1363) += max1363.o obj-$(CONFIG_AD7150) += ad7150.o +obj-$(CONFIG_AD7152) += ad7152.odrivers/staging/iio/adc/ad7152.c new file +55
-0@@ -0,0 +1,610 @@ +/* +* AD7152 capacitive sensor driver supporting AD7152/3 +* +* Copyright 2010 Analog Devices Inc. +* +* Licensed under the GPL-2 or later. +*/ + +#include <linux/interrupt.h> +#include <linux/gpio.h> +#include <linux/workqueue.h> +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/sysfs.h> +#include <linux/list.h> +#include <linux/i2c.h> +#include <linux/rtc.h> + +#include "../iio.h" +#include "../sysfs.h" + +/* +* AD7152 registers definition +*/ + +#define AD7152_STATUS 0 +#define AD7152_STATUS_RDY1 (1 << 0) +#define AD7152_STATUS_RDY2 (1 << 1) +#define AD7152_CH1_DATA_HIGH 1 +#define AD7152_CH1_DATA_LOW 2 +#define AD7152_CH2_DATA_HIGH 3 +#define AD7152_CH2_DATA_LOW 4 +#define AD7152_CH1_OFFS_HIGH 5 +#define AD7152_CH1_OFFS_LOW 6 +#define AD7152_CH2_OFFS_HIGH 7 +#define AD7152_CH2_OFFS_LOW 8 +#define AD7152_CH1_GAIN_HIGH 9 +#define AD7152_CH1_GAIN_LOW 10 +#define AD7152_CH1_SETUP 11 +#define AD7152_CH2_GAIN_HIGH 12 +#define AD7152_CH2_GAIN_LOW 13 +#define AD7152_CH2_SETUP 14 +#define AD7152_CFG 15 +#define AD7152_RESEVERD 16 +#define AD7152_CAPDAC_POS 17 +#define AD7152_CAPDAC_NEG 18 +#define AD7152_CFG2 26 + +#define AD7152_MAX_CONV_MODE 6 + +/* +* struct ad7152_chip_info - chip specifc information +*/ +
drivers/staging/iio/adc/ad7152.c line 65
Quoted 10 lines
drivers/staging/iio/adc/ad7152.c new file +10
-0+struct ad7152_chip_info { +const char *name; +struct i2c_client *client; +struct iio_dev *indio_dev; +u16 ch1_offset;/* Channel 1 offset calibration coefficient */ +u16 ch1_gain;/* Channel 1 gain coefficient */ +u8 ch1_setup; +u16 ch2_offset;/* Channel 2 offset calibration coefficient */ +u16 ch2_gain;/* Channel 1 gain coefficient */ +u8 ch2_setup;
Checkpatch overlong line.
drivers/staging/iio/adc/ad7152.c line 74
Quoted 9 lines
drivers/staging/iio/adc/ad7152.c new file +9
-0+u8 filter_rate_setup;/* Capacitive channel digital filter setup; conversion time/update rate setup per channel */ +char *conversion_mode; +}; + +struct ad7152_conversion_mode { +char *name; +u8 reg_cfg; +}; +
My usual comment on this sort of mode by string option is that it doesn't generalize. If we can possibly blugeon things into a form that does I will be much happier. This matters a lot to userspace code writers.
drivers/staging/iio/adc/ad7152.c line 76
Quoted 2 lines
drivers/staging/iio/adc/ad7152.c new file +2
-0+struct ad7152_conversion_mode ad7152_conv_mode_table[AD7152_MAX_CONV_MODE ] = { + {"idle" ,0 },
Guessing this means off? Should probably be handled internally. If the read doesn't care, then it shouldn't be enabled.
drivers/staging/iio/adc/ad7152.c line 77
Quoted 1 line
drivers/staging/iio/adc/ad7152.c new file +1
-0+ { "continuous-conversion", 1 },
Possibly only enable it event that needs it is turned on?
drivers/staging/iio/adc/ad7152.c line 78
Quoted 1 line
drivers/staging/iio/adc/ad7152.c new file +1
-0+ { "single-conversion", 2 },
Typical one shot mode. Should be written on demmand (by all means cache whether it is already in the right mode)
drivers/staging/iio/adc/ad7152.c line 79
Quoted 1 line
drivers/staging/iio/adc/ad7152.c new file +1
-0+ { "power-down", 3 },
Separate attr for power down.
drivers/staging/iio/adc/ad7152.c line 81
Quoted 2 lines
drivers/staging/iio/adc/ad7152.c new file +2
-0+ { "offset-calibration", 5 }, + { "gain-calibration", 6 },
These look fun. No idea how these should be described ;)
Quoted 10 lines
drivers/staging/iio/adc/ad7152.c new file +10
-0+}; + +/* +* ad7152 register access by I2C +*/ + +static int ad7152_i2c_read (struct ad7152_chip_info *chip,u8 reg,u8 *data,int len) +{ +struct i2c_client *client = chip->client; +int ret =0 ;
drivers/staging/iio/adc/ad7152.c line 101
Quoted 10 lines
drivers/staging/iio/adc/ad7152.c new file +10
-0+ + ret =i2c_master_send (client, ®,1 ); +if (ret <0 ) { +dev_err (&client->dev,"I2C write error\n" ); +return ret; + } + + ret =i2c_master_recv (client, data, len); +if (ret <0 ) { +dev_err (&client->dev,"I2C read error\n" );
pointless return ret
drivers/staging/iio/adc/ad7152.c line 111
Quoted 10 lines
drivers/staging/iio/adc/ad7152.c new file +10
-0+return ret; + } + +return ret; +} + +static int ad7152_i2c_write (struct ad7152_chip_info *chip,u8 reg,u8 data) +{ +struct i2c_client *client = chip->client; +int ret =0 ;
no need to initialize ret
Quoted 7 lines
drivers/staging/iio/adc/ad7152.c new file +7
-0+ +u8 tx[2 ] = { + reg, + data, + }; + + ret =i2c_master_send (client, tx,2 );
drivers/staging/iio/adc/ad7152.c line 128
Quoted 10 lines
drivers/staging/iio/adc/ad7152.c new file +10
-0+if (ret <0 ) +dev_err (&client->dev,"I2C write error\n" ); + +return ret; +} + +/* +* sysfs nodes +*/ +
Those of the following that generalize should move out into a generic header.
drivers/staging/iio/adc/ad7152.c line 130
Quoted 2 lines
drivers/staging/iio/adc/ad7152.c new file +2
-0+#define IIO_DEV_ATTR_AVAIL_CONVERSION_MODES (_show) \ + IIO_DEVICE_ATTR(available_conversion_modes, S_IRUGO, _show, NULL, 0)
standard form is conversion_mode_available (makes processing in userspace easy ;)
drivers/staging/iio/adc/ad7152.c line 132
Quoted 2 lines
drivers/staging/iio/adc/ad7152.c new file +2
-0+#define IIO_DEV_ATTR_CONVERSION_MODE (_mode, _show, _store) \ + IIO_DEVICE_ATTR(conversion_mode, _mode, _show, _store, 0)
I'm not keen on this for reasons stated above.
drivers/staging/iio/adc/ad7152.c line 134
Quoted 2 lines
drivers/staging/iio/adc/ad7152.c new file +2
-0+#define IIO_DEV_ATTR_CH1_OFFSET (_mode, _show, _store) \ + IIO_DEVICE_ATTR(ch1_offset, _mode, _show, _store, 0)
Lets define a 'type' for capcitance measurement. 'capacitance' seems like a sensible option for me. Base unit, Farads.
Hence this becomes capacitance0_offset (we index from 0, though don't really care on that as long as you are consistent - userspace should be able to cope as it's common for particular channels to be missing on some devices)
drivers/staging/iio/adc/ad7152.c line 138
Quoted 4 lines
drivers/staging/iio/adc/ad7152.c new file +4
-0+#define IIO_DEV_ATTR_CH2_OFFSET (_mode, _show, _store) \ + IIO_DEVICE_ATTR(ch2_offset, _mode, _show, _store, 0) +#define IIO_DEV_ATTR_CH1_GAIN (_mode, _show, _store) \ + IIO_DEVICE_ATTR(ch1_gain, _mode, _show, _store, 0)
capacitance0_scale if to be applied by userspace to end up in farads or capacitance0_calibscale if it is an internal gain setting applied on the device and that doesn't need to be applied by userspace to get to Farads.
drivers/staging/iio/adc/ad7152.c line 142
Quoted 4 lines
drivers/staging/iio/adc/ad7152.c new file +4
-0+#define IIO_DEV_ATTR_CH2_GAIN (_mode, _show, _store) \ + IIO_DEVICE_ATTR(ch2_gain, _mode, _show, _store, 0) +#define IIO_DEV_ATTR_CH1_VALUE (_show) \ + IIO_DEVICE_ATTR(ch1_value, S_IRUGO, _show, NULL, 0)
convention is <type>[m]_raw if it's not in si units (or _input if it is). capacitance0_raw
drivers/staging/iio/adc/ad7152.c line 144
Quoted 2 lines
drivers/staging/iio/adc/ad7152.c new file +2
-0+#define IIO_DEV_ATTR_CH2_VALUE (_show) \ + IIO_DEVICE_ATTR(ch2_value, S_IRUGO, _show, NULL, 0)
capacitance1_raw
drivers/staging/iio/adc/ad7152.c line 146
Quoted 2 lines
drivers/staging/iio/adc/ad7152.c new file +2
-0+#define IIO_DEV_ATTR_CH1_SETUP (_mode, _show, _store) \ + IIO_DEVICE_ATTR(ch1_setup, _mode, _show, _store, 0)
This smacks of magic value. Really needs to be on the todo list to clean this up to some 'standard' interface. Without the datasheet I have no idea what these magic values do.
drivers/staging/iio/adc/ad7152.c line 150
Quoted 4 lines
drivers/staging/iio/adc/ad7152.c new file +4
-0+#define IIO_DEV_ATTR_CH2_SETUP (_mode, _show, _store) \ + IIO_DEVICE_ATTR(ch2_setup, _mode, _show, _store, 0) +#define IIO_DEV_ATTR_FILTER_RATE_SETUP (_mode, _show, _store) \ + IIO_DEVICE_ATTR(filter_rate_setup, _mode, _show, _store, 0)
Filters are one area we realy don't have a clean abi for. This might actually be our first driver to support them (though quite a few devices we have drivers for do). Abi needs discussion at somepoint soon. May be rather fiddly to get right, so beware abi may not be stable for a while.
drivers/staging/iio/adc/ad7152.c line 160
Quoted 10 lines
drivers/staging/iio/adc/ad7152.c new file +10
-0+ +static ssize_t ad7152_show_conversion_modes (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +int i; +int len =0 ; + +for (i =0 ; i <AD7152_MAX_CONV_MODE ; i++) + len +=sprintf (buf + len,"%s\n" , ad7152_conv_mode_table[i].name);
space rather than newline please.
Quoted 47 lines
drivers/staging/iio/adc/ad7152.c new file +47
-0+ +return len; +} + +static IIO_DEV_ATTR_AVAIL_CONVERSION_MODES (ad7152_show_conversion_modes); + +static ssize_t ad7152_show_ch1_value (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7152_chip_info *chip = dev_info->dev_data; +u8 data[2 ]; + +ad7152_i2c_read (chip,AD7152_CH1_DATA_HIGH , data,2 ); +return sprintf (buf,"%d\n" , ((int )data[0 ] <<8 ) | data[1 ]); +} + +static IIO_DEV_ATTR_CH1_VALUE (ad7152_show_ch1_value); + +static ssize_t ad7152_show_ch2_value (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7152_chip_info *chip = dev_info->dev_data; +u8 data[2 ]; + +ad7152_i2c_read (chip,AD7152_CH2_DATA_HIGH , data,2 ); +return sprintf (buf,"%d\n" , ((int )data[0 ] <<8 ) | data[1 ]); +} + +static IIO_DEV_ATTR_CH2_VALUE (ad7152_show_ch2_value); + +static ssize_t ad7152_show_conversion_mode (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7152_chip_info *chip = dev_info->dev_data; + +return sprintf (buf,"%s\n" , chip->conversion_mode); +} + +static ssize_t ad7152_store_conversion_mode(struct device *dev, + struct device_attribute *attr, + const char *buf,
drivers/staging/iio/adc/ad7152.c line 217
Quoted 10 lines
drivers/staging/iio/adc/ad7152.c new file +10
-0+ size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7152_chip_info *chip = dev_info->dev_data; +u8 cfg; +int i; + +ad7152_i2c_read (chip,AD7152_CFG , &cfg,1 ); + +for (i =0 ; i <AD7152_MAX_CONV_MODE ; i++) {
superfluous brackets.
Quoted 53 lines
drivers/staging/iio/adc/ad7152.c new file +53
-0+if (strncmp (buf, ad7152_conv_mode_table[i].name, +strlen (ad7152_conv_mode_table[i].name) -1 ) ==0 ) { + chip->conversion_mode = ad7152_conv_mode_table[i].name; + cfg |=0x18 | ad7152_conv_mode_table[i].reg_cfg; +ad7152_i2c_write (chip,AD7152_CFG , cfg); +return len; + } + } + +dev_err (dev,"not supported conversion mode\n" ); + +return -EINVAL ; +} + +static IIO_DEV_ATTR_CONVERSION_MODE(S_IRUGO | S_IWUSR, + ad7152_show_conversion_mode, + ad7152_store_conversion_mode); + +static ssize_t ad7152_show_ch1_offset (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7152_chip_info *chip = dev_info->dev_data; + +return sprintf (buf,"%d\n" , chip->ch1_offset); +} + +static ssize_t ad7152_store_ch1_offset (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7152_chip_info *chip = dev_info->dev_data; +unsigned long data; +int ret; + + ret =strict_strtoul (buf,10 , &data); + +if ((!ret) && (data <0x10000 )) { +ad7152_i2c_write (chip,AD7152_CH1_OFFS_HIGH , data >>8 ); +ad7152_i2c_write (chip,AD7152_CH1_OFFS_LOW , data); + chip->ch1_offset = data; +return len; + } + +return -EINVAL ; +} + +static IIO_DEV_ATTR_CH1_OFFSET(S_IRUGO | S_IWUSR, + ad7152_show_ch1_offset, + ad7152_store_ch1_offset);
drivers/staging/iio/adc/ad7152.c line 280
Quoted 10 lines
drivers/staging/iio/adc/ad7152.c new file +10
-0+ +static ssize_t ad7152_show_ch2_offset (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7152_chip_info *chip = dev_info->dev_data; + +return sprintf (buf,"%d\n" , chip->ch2_offset); +}
Can probably save a few functions round here easily enough.
Quoted 89 lines
drivers/staging/iio/adc/ad7152.c new file +89
-0+ +static ssize_t ad7152_store_ch2_offset (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7152_chip_info *chip = dev_info->dev_data; +unsigned long data; +int ret; + + ret =strict_strtoul (buf,10 , &data); + +if ((!ret) && (data <0x10000 )) { +ad7152_i2c_write (chip,AD7152_CH2_OFFS_HIGH , data >>8 ); +ad7152_i2c_write (chip,AD7152_CH2_OFFS_LOW , data); + chip->ch2_offset = data; +return len; + } + +return -EINVAL ; +} + +static IIO_DEV_ATTR_CH2_OFFSET(S_IRUGO | S_IWUSR, + ad7152_show_ch2_offset, + ad7152_store_ch2_offset); + +static ssize_t ad7152_show_ch1_gain (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7152_chip_info *chip = dev_info->dev_data; + +return sprintf (buf,"%d\n" , chip->ch1_gain); +} + +static ssize_t ad7152_store_ch1_gain (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7152_chip_info *chip = dev_info->dev_data; +unsigned long data; +int ret; + + ret =strict_strtoul (buf,10 , &data); + +if ((!ret) && (data <0x10000 )) { +ad7152_i2c_write (chip,AD7152_CH1_GAIN_HIGH , data >>8 ); +ad7152_i2c_write (chip,AD7152_CH1_GAIN_LOW , data); + chip->ch1_gain = data; +return len; + } + +return -EINVAL ; +} + +static IIO_DEV_ATTR_CH1_GAIN(S_IRUGO | S_IWUSR, + ad7152_show_ch1_gain, + ad7152_store_ch1_gain); + +static ssize_t ad7152_show_ch2_gain (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7152_chip_info *chip = dev_info->dev_data; + +return sprintf (buf,"%d\n" , chip->ch2_gain); +} + +static ssize_t ad7152_store_ch2_gain (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7152_chip_info *chip = dev_info->dev_data; +unsigned long data; +int ret; + + ret =strict_strtoul (buf,10 , &data); + +if ((!ret) && (data <0x10000 )) { +ad7152_i2c_write (chip,AD7152_CH2_GAIN_HIGH , data >>8 ); +ad7152_i2c_write (chip,AD7152_CH2_GAIN_LOW , data); + chip->ch2_gain = data;
drivers/staging/iio/adc/ad7152.c line 379
Quoted 10 lines
drivers/staging/iio/adc/ad7152.c new file +10
-0+return len; + } + +return -EINVAL ; +} + +static IIO_DEV_ATTR_CH2_GAIN(S_IRUGO | S_IWUSR, + ad7152_show_ch2_gain, + ad7152_store_ch2_gain); +
Err, no to this as an interface. Fine for initial bashing, but we aren't going to keep something this 'magic' in here long term.
Quoted 60 lines
drivers/staging/iio/adc/ad7152.c new file +60
-0+static ssize_t ad7152_show_ch1_setup (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7152_chip_info *chip = dev_info->dev_data; + +return sprintf (buf,"0x%02x\n" , chip->ch1_setup); +} + +static ssize_t ad7152_store_ch1_setup (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7152_chip_info *chip = dev_info->dev_data; +unsigned long data; +int ret; + + ret =strict_strtoul (buf,10 , &data); + +if ((!ret) && (data <0x100 )) { +ad7152_i2c_write (chip,AD7152_CH1_SETUP , data); + chip->ch1_setup = data; +return len; + } + +return -EINVAL ; +} + +static IIO_DEV_ATTR_CH1_SETUP(S_IRUGO | S_IWUSR, + ad7152_show_ch1_setup, + ad7152_store_ch1_setup); + +static ssize_t ad7152_show_ch2_setup (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7152_chip_info *chip = dev_info->dev_data; + +return sprintf (buf,"0x%02x\n" , chip->ch2_setup); +} + +static ssize_t ad7152_store_ch2_setup (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7152_chip_info *chip = dev_info->dev_data; +unsigned long data; +int ret; + + ret =strict_strtoul (buf,10 , &data); + +if ((!ret) && (data <0x100 )) { +ad7152_i2c_write (chip,AD7152_CH2_SETUP , data); + chip->ch2_setup = data;
drivers/staging/iio/adc/ad7152.c line 449
Quoted 10 lines
drivers/staging/iio/adc/ad7152.c new file +10
-0+return len; + } + +return -EINVAL ; +} + +static IIO_DEV_ATTR_CH2_SETUP(S_IRUGO | S_IWUSR, + ad7152_show_ch2_setup, + ad7152_store_ch2_setup); +
Again, fine for initial bashing, but this ain't going to generalize unless all device use the same magic ;)
Quoted 36 lines
drivers/staging/iio/adc/ad7152.c new file +36
-0+static ssize_t ad7152_show_filter_rate_setup (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7152_chip_info *chip = dev_info->dev_data; + +return sprintf (buf,"0x%02x\n" , chip->filter_rate_setup); +} + +static ssize_t ad7152_store_filter_rate_setup (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t len) +{ +struct iio_dev *dev_info =dev_get_drvdata (dev); +struct ad7152_chip_info *chip = dev_info->dev_data; +unsigned long data; +int ret; + + ret =strict_strtoul (buf,10 , &data); + +if ((!ret) && (data <0x100 )) { +ad7152_i2c_write (chip,AD7152_CFG2 , data); + chip->filter_rate_setup = data; +return len; + } + +return -EINVAL ; +} + +static IIO_DEV_ATTR_FILTER_RATE_SETUP(S_IRUGO | S_IWUSR, + ad7152_show_filter_rate_setup, + ad7152_store_filter_rate_setup); + +static ssize_t ad7152_show_name(struct device *dev,
drivers/staging/iio/adc/ad7152.c line 495
Quoted 10 lines
drivers/staging/iio/adc/ad7152.c new file +10
-0+struct device_attribute *attr, + char *buf) +{ + struct iio_dev *dev_info = dev_get_drvdata(dev); +struct ad7152_chip_info *chip = dev_info->dev_data; +return sprintf (buf,"%s\n" , chip->name); +} + +static IIO_DEVICE_ATTR(name, S_IRUGO, ad7152_show_name, NULL, 0); +
comments on these are alongside the macros above.
Quoted 115 lines
drivers/staging/iio/adc/ad7152.c new file +115
-0+static struct attribute *ad7152_attributes[] = { + &iio_dev_attr_available_conversion_modes.dev_attr.attr, + &iio_dev_attr_conversion_mode.dev_attr.attr, + &iio_dev_attr_ch1_gain.dev_attr.attr, + &iio_dev_attr_ch2_gain.dev_attr.attr, + &iio_dev_attr_ch1_offset.dev_attr.attr, + &iio_dev_attr_ch2_offset.dev_attr.attr, + &iio_dev_attr_ch1_value.dev_attr.attr, + &iio_dev_attr_ch2_value.dev_attr.attr, + &iio_dev_attr_ch1_setup.dev_attr.attr, + &iio_dev_attr_ch2_setup.dev_attr.attr, + &iio_dev_attr_filter_rate_setup.dev_attr.attr, + &iio_dev_attr_name.dev_attr.attr, +NULL , +}; + +static const struct attribute_group ad7152_attribute_group = { + .attrs = ad7152_attributes, +}; + +/* +* device probe and remove +*/ + +static int __devinit ad7152_probe (struct i2c_client *client, +const struct i2c_device_id *id) +{ +int ret =0 ; +struct ad7152_chip_info *chip =kzalloc (sizeof (*chip),GFP_KERNEL ); +if (chip ==NULL ) { + ret = -ENOMEM ; + goto error_ret; + } + +/* this is only used for device removal purposes */ +i2c_set_clientdata (client, chip); + + chip->client = client; + chip->name = id->name; + + chip->indio_dev =iio_allocate_device (); +if (chip->indio_dev ==NULL ) { + ret = -ENOMEM ; + goto error_free_chip; + } + +/* Echipabilish that the iio_dev is a child of the i2c device */ + chip->indio_dev->dev.parent = &client->dev; + chip->indio_dev->attrs = &ad7152_attribute_group; + chip->indio_dev->dev_data = (void *)(chip); + chip->indio_dev->driver_module =THIS_MODULE ; + chip->indio_dev->modes =INDIO_DIRECT_MODE ; + + ret =iio_device_register (chip->indio_dev); +if (ret) + goto error_free_dev; + +dev_err (&client->dev,"%s capacitive sensor registered\n" , id->name); + +return 0 ; + +error_free_dev: +iio_free_device (chip->indio_dev); +error_free_chip: +kfree (chip); +error_ret: +return ret; +} + +static int __devexit ad7152_remove(struct i2c_client *client) +{ +struct ad7152_chip_info *chip =i2c_get_clientdata (client); +struct iio_dev *indio_dev = chip->indio_dev; + +if (client->irq &&gpio_is_valid (irq_to_gpio (client->irq)) >0 ) +iio_unregister_interrupt_line (indio_dev,0 ); +iio_device_unregister (indio_dev); +kfree (chip); + +return 0 ; +} + +static const struct i2c_device_id ad7152_id[] = { + {"ad7152" ,0 }, + {"ad7153" ,0 }, + {} +}; + +MODULE_DEVICE_TABLE (i2c, ad7152_id); + +static struct i2c_driver ad7152_driver = { + .driver = { + .name ="ad7152" , + }, + .probe = ad7152_probe, + .remove =__devexit_p (ad7152_remove), + .id_table = ad7152_id, +}; + +static __init int ad7152_init (void ) +{ +return i2c_add_driver (&ad7152_driver); +} + +static __exit void ad7152_exit(void) +{ +i2c_del_driver (&ad7152_driver); +} + +MODULE_AUTHOR ("Barry Song <[email protected]>" ); +MODULE_DESCRIPTION ("Analog Devices ad7152/3 capacitive sensor driver" ); +MODULE_LICENSE ("GPL v2" ); + +module_init (ad7152_init); +module_exit (ad7152_exit);