-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
staging: iio: new ADT7316/7/8 and ADT7516/7/9 driver
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
Showing
8 changed files
with
2,819 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Oops, something went wrong.