Skip to content

Commit

Permalink
staging: iio: new ADT7316/7/8 and ADT7516/7/9 driver
Browse files Browse the repository at this point in the history
IIO driver for temperature sensor, ADC and DAC devices over SPI and I2C.

Signed-off-by: Sonic Zhang <sonic.zhang@analog.com>
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Acked-by: Jonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Sonic Zhang authored and Greg Kroah-Hartman committed Nov 9, 2010
1 parent bb6f19e commit 35f6b6b
Show file tree
Hide file tree
Showing 8 changed files with 2,819 additions and 0 deletions.
1 change: 1 addition & 0 deletions drivers/staging/iio/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ config IIO_TRIGGER

source "drivers/staging/iio/accel/Kconfig"
source "drivers/staging/iio/adc/Kconfig"
source "drivers/staging/iio/addac/Kconfig"
source "drivers/staging/iio/gyro/Kconfig"
source "drivers/staging/iio/imu/Kconfig"
source "drivers/staging/iio/light/Kconfig"
Expand Down
1 change: 1 addition & 0 deletions drivers/staging/iio/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ obj-$(CONFIG_IIO_SW_RING) += ring_sw.o

obj-y += accel/
obj-y += adc/
obj-y += addac/
obj-y += gyro/
obj-y += imu/
obj-y += light/
Expand Down
25 changes: 25 additions & 0 deletions drivers/staging/iio/addac/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
# ADDAC drivers
#
comment "Analog digital bi-direction convertors"

config ADT7316
tristate "Analog Devices ADT7316/7/8 ADT7516/7/9 temperature sensor, ADC and DAC driver"
help
Say yes here to build support for Analog Devices ADT7316, ADT7317, ADT7318
and ADT7516, ADT7517, ADT7519 temperature sensors, ADC and DAC.

config ADT7316_SPI
tristate "support SPI bus connection"
depends on SPI && ADT7316
default y
help
Say yes here to build SPI bus support for Analog Devices ADT7316/7/8
and ADT7516/7/9.

config ADT7316_I2C
tristate "support I2C bus connection"
depends on I2C && ADT7316
help
Say yes here to build I2C bus support for Analog Devices ADT7316/7/8
and ADT7516/7/9.
7 changes: 7 additions & 0 deletions drivers/staging/iio/addac/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#
# Makefile for industrial I/O ADDAC drivers
#

obj-$(CONFIG_ADT7316) += adt7316.o
obj-$(CONFIG_ADT7316_SPI) += adt7316-spi.o
obj-$(CONFIG_ADT7316_I2C) += adt7316-i2c.o
170 changes: 170 additions & 0 deletions drivers/staging/iio/addac/adt7316-i2c.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
/*
* I2C bus driver for ADT7316/7/8 ADT7516/7/9 digital temperature
* sensor, ADC and DAC
*
* Copyright 2010 Analog Devices Inc.
*
* Licensed under the GPL-2 or later.
*/

#include <linux/device.h>
#include <linux/kernel.h>
#include <linux/i2c.h>
#include <linux/interrupt.h>

#include "adt7316.h"

/*
* adt7316 register access by I2C
*/
static int adt7316_i2c_read(void *client, u8 reg, u8 *data)
{
struct i2c_client *cl = client;
int ret = 0;

ret = i2c_smbus_write_byte(cl, reg);
if (ret < 0) {
dev_err(&cl->dev, "I2C fail to select reg\n");
return ret;
}

ret = i2c_smbus_read_byte(client);
if (ret < 0) {
dev_err(&cl->dev, "I2C read error\n");
return ret;
}

return 0;
}

static int adt7316_i2c_write(void *client, u8 reg, u8 data)
{
struct i2c_client *cl = client;
int ret = 0;

ret = i2c_smbus_write_byte_data(cl, reg, data);
if (ret < 0)
dev_err(&cl->dev, "I2C write error\n");

return ret;
}

static int adt7316_i2c_multi_read(void *client, u8 reg, u8 count, u8 *data)
{
struct i2c_client *cl = client;
int i, ret = 0;

if (count > ADT7316_REG_MAX_ADDR)
count = ADT7316_REG_MAX_ADDR;

for (i = 0; i < count; i++) {
ret = adt7316_i2c_read(cl, reg, &data[i]);
if (ret < 0) {
dev_err(&cl->dev, "I2C multi read error\n");
return ret;
}
}

return 0;
}

static int adt7316_i2c_multi_write(void *client, u8 reg, u8 count, u8 *data)
{
struct i2c_client *cl = client;
int i, ret = 0;

if (count > ADT7316_REG_MAX_ADDR)
count = ADT7316_REG_MAX_ADDR;

for (i = 0; i < count; i++) {
ret = adt7316_i2c_write(cl, reg, data[i]);
if (ret < 0) {
dev_err(&cl->dev, "I2C multi write error\n");
return ret;
}
}

return 0;
}

/*
* device probe and remove
*/

static int __devinit adt7316_i2c_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
struct adt7316_bus bus = {
.client = client,
.irq = client->irq,
.irq_flags = IRQF_TRIGGER_LOW,
.read = adt7316_i2c_read,
.write = adt7316_i2c_write,
.multi_read = adt7316_i2c_multi_read,
.multi_write = adt7316_i2c_multi_write,
};

return adt7316_probe(&client->dev, &bus, id->name);
}

static int __devexit adt7316_i2c_remove(struct i2c_client *client)
{
return adt7316_remove(&client->dev);;
}

static const struct i2c_device_id adt7316_i2c_id[] = {
{ "adt7316", 0 },
{ "adt7317", 0 },
{ "adt7318", 0 },
{ "adt7516", 0 },
{ "adt7517", 0 },
{ "adt7519", 0 },
{ }
};

MODULE_DEVICE_TABLE(i2c, adt7316_i2c_id);

#ifdef CONFIG_PM
static int adt7316_i2c_suspend(struct i2c_client *client, pm_message_t message)
{
return adt7316_disable(&client->dev);
}

static int adt7316_i2c_resume(struct i2c_client *client)
{
return adt7316_enable(&client->dev);
}
#else
# define adt7316_i2c_suspend NULL
# define adt7316_i2c_resume NULL
#endif

static struct i2c_driver adt7316_driver = {
.driver = {
.name = "adt7316",
.owner = THIS_MODULE,
},
.probe = adt7316_i2c_probe,
.remove = __devexit_p(adt7316_i2c_remove),
.suspend = adt7316_i2c_suspend,
.resume = adt7316_i2c_resume,
.id_table = adt7316_i2c_id,
};

static __init int adt7316_i2c_init(void)
{
return i2c_add_driver(&adt7316_driver);
}

static __exit void adt7316_i2c_exit(void)
{
i2c_del_driver(&adt7316_driver);
}

MODULE_AUTHOR("Sonic Zhang <sonic.zhang@analog.com>");
MODULE_DESCRIPTION("I2C bus driver for Analog Devices ADT7316/7/9 and"
"ADT7516/7/8 digital temperature sensor, ADC and DAC");
MODULE_LICENSE("GPL v2");

module_init(adt7316_i2c_init);
module_exit(adt7316_i2c_exit);
Loading

0 comments on commit 35f6b6b

Please sign in to comment.