|
@@ -1,5 +1,5 @@
|
|
/*
|
|
/*
|
|
- * ADT7410 digital temperature sensor driver supporting ADT7410
|
|
|
|
|
|
+ * ADT7410 digital temperature sensor driver supporting ADT7310/ADT7410
|
|
*
|
|
*
|
|
* Copyright 2010 Analog Devices Inc.
|
|
* Copyright 2010 Analog Devices Inc.
|
|
*
|
|
*
|
|
@@ -13,6 +13,7 @@
|
|
#include <linux/sysfs.h>
|
|
#include <linux/sysfs.h>
|
|
#include <linux/list.h>
|
|
#include <linux/list.h>
|
|
#include <linux/i2c.h>
|
|
#include <linux/i2c.h>
|
|
|
|
+#include <linux/spi/spi.h>
|
|
#include <linux/module.h>
|
|
#include <linux/module.h>
|
|
|
|
|
|
#include <linux/iio/iio.h>
|
|
#include <linux/iio/iio.h>
|
|
@@ -33,6 +34,19 @@
|
|
#define ADT7410_ID 0xB
|
|
#define ADT7410_ID 0xB
|
|
#define ADT7410_RESET 0x2F
|
|
#define ADT7410_RESET 0x2F
|
|
|
|
|
|
|
|
+/*
|
|
|
|
+ * ADT7310 registers definition
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+#define ADT7310_STATUS 0
|
|
|
|
+#define ADT7310_CONFIG 1
|
|
|
|
+#define ADT7310_TEMPERATURE 2
|
|
|
|
+#define ADT7310_ID 3
|
|
|
|
+#define ADT7310_T_CRIT 4
|
|
|
|
+#define ADT7310_T_HYST 5
|
|
|
|
+#define ADT7310_T_ALARM_HIGH 6
|
|
|
|
+#define ADT7310_T_ALARM_LOW 7
|
|
|
|
+
|
|
/*
|
|
/*
|
|
* ADT7410 status
|
|
* ADT7410 status
|
|
*/
|
|
*/
|
|
@@ -69,75 +83,52 @@
|
|
#define ADT7410_MANUFACTORY_ID_MASK 0xF0
|
|
#define ADT7410_MANUFACTORY_ID_MASK 0xF0
|
|
#define ADT7410_MANUFACTORY_ID_OFFSET 4
|
|
#define ADT7410_MANUFACTORY_ID_OFFSET 4
|
|
|
|
|
|
|
|
+
|
|
|
|
+#define ADT7310_CMD_REG_MASK 0x28
|
|
|
|
+#define ADT7310_CMD_REG_OFFSET 3
|
|
|
|
+#define ADT7310_CMD_READ 0x40
|
|
|
|
+#define ADT7310_CMD_CON_READ 0x4
|
|
|
|
+
|
|
#define ADT7410_IRQS 2
|
|
#define ADT7410_IRQS 2
|
|
|
|
|
|
/*
|
|
/*
|
|
* struct adt7410_chip_info - chip specifc information
|
|
* struct adt7410_chip_info - chip specifc information
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
+struct adt7410_chip_info;
|
|
|
|
+
|
|
|
|
+struct adt7410_ops {
|
|
|
|
+ int (*read_word)(struct adt7410_chip_info *, u8 reg, u16 *data);
|
|
|
|
+ int (*write_word)(struct adt7410_chip_info *, u8 reg, u16 data);
|
|
|
|
+ int (*read_byte)(struct adt7410_chip_info *, u8 reg, u8 *data);
|
|
|
|
+ int (*write_byte)(struct adt7410_chip_info *, u8 reg, u8 data);
|
|
|
|
+};
|
|
|
|
+
|
|
struct adt7410_chip_info {
|
|
struct adt7410_chip_info {
|
|
- struct i2c_client *client;
|
|
|
|
|
|
+ struct device *dev;
|
|
u8 config;
|
|
u8 config;
|
|
-};
|
|
|
|
|
|
|
|
-/*
|
|
|
|
- * adt7410 register access by I2C
|
|
|
|
- */
|
|
|
|
|
|
+ const struct adt7410_ops *ops;
|
|
|
|
+};
|
|
|
|
|
|
-static int adt7410_i2c_read_word(struct adt7410_chip_info *chip, u8 reg, u16 *data)
|
|
|
|
|
|
+static int adt7410_read_word(struct adt7410_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;
|
|
|
|
|
|
+ return chip->ops->read_word(chip, reg, data);
|
|
}
|
|
}
|
|
|
|
|
|
-static int adt7410_i2c_write_word(struct adt7410_chip_info *chip, u8 reg, u16 data)
|
|
|
|
|
|
+static int adt7410_write_word(struct adt7410_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;
|
|
|
|
|
|
+ return chip->ops->write_word(chip, reg, data);
|
|
}
|
|
}
|
|
|
|
|
|
-static int adt7410_i2c_read_byte(struct adt7410_chip_info *chip, u8 reg, u8 *data)
|
|
|
|
|
|
+static int adt7410_read_byte(struct adt7410_chip_info *chip, u8 reg, u8 *data)
|
|
{
|
|
{
|
|
- struct i2c_client *client = chip->client;
|
|
|
|
- int ret = 0;
|
|
|
|
-
|
|
|
|
- ret = i2c_smbus_read_byte_data(client, reg);
|
|
|
|
- if (ret < 0) {
|
|
|
|
- dev_err(&client->dev, "I2C read error\n");
|
|
|
|
- return ret;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- *data = (u8)ret;
|
|
|
|
-
|
|
|
|
- return 0;
|
|
|
|
|
|
+ return chip->ops->read_byte(chip, reg, data);
|
|
}
|
|
}
|
|
|
|
|
|
-static int adt7410_i2c_write_byte(struct adt7410_chip_info *chip, u8 reg, u8 data)
|
|
|
|
|
|
+static int adt7410_write_byte(struct adt7410_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;
|
|
|
|
|
|
+ return chip->ops->write_byte(chip, reg, data);
|
|
}
|
|
}
|
|
|
|
|
|
static ssize_t adt7410_show_mode(struct device *dev,
|
|
static ssize_t adt7410_show_mode(struct device *dev,
|
|
@@ -172,7 +163,7 @@ static ssize_t adt7410_store_mode(struct device *dev,
|
|
u16 config;
|
|
u16 config;
|
|
int ret;
|
|
int ret;
|
|
|
|
|
|
- ret = adt7410_i2c_read_byte(chip, ADT7410_CONFIG, &chip->config);
|
|
|
|
|
|
+ ret = adt7410_read_byte(chip, ADT7410_CONFIG, &chip->config);
|
|
if (ret)
|
|
if (ret)
|
|
return -EIO;
|
|
return -EIO;
|
|
|
|
|
|
@@ -184,7 +175,7 @@ static ssize_t adt7410_store_mode(struct device *dev,
|
|
else if (strcmp(buf, "sps"))
|
|
else if (strcmp(buf, "sps"))
|
|
config |= ADT7410_SPS;
|
|
config |= ADT7410_SPS;
|
|
|
|
|
|
- ret = adt7410_i2c_write_byte(chip, ADT7410_CONFIG, config);
|
|
|
|
|
|
+ ret = adt7410_write_byte(chip, ADT7410_CONFIG, config);
|
|
if (ret)
|
|
if (ret)
|
|
return -EIO;
|
|
return -EIO;
|
|
|
|
|
|
@@ -216,7 +207,7 @@ static ssize_t adt7410_show_resolution(struct device *dev,
|
|
int ret;
|
|
int ret;
|
|
int bits;
|
|
int bits;
|
|
|
|
|
|
- ret = adt7410_i2c_read_byte(chip, ADT7410_CONFIG, &chip->config);
|
|
|
|
|
|
+ ret = adt7410_read_byte(chip, ADT7410_CONFIG, &chip->config);
|
|
if (ret)
|
|
if (ret)
|
|
return -EIO;
|
|
return -EIO;
|
|
|
|
|
|
@@ -243,7 +234,7 @@ static ssize_t adt7410_store_resolution(struct device *dev,
|
|
if (ret)
|
|
if (ret)
|
|
return -EINVAL;
|
|
return -EINVAL;
|
|
|
|
|
|
- ret = adt7410_i2c_read_byte(chip, ADT7410_CONFIG, &chip->config);
|
|
|
|
|
|
+ ret = adt7410_read_byte(chip, ADT7410_CONFIG, &chip->config);
|
|
if (ret)
|
|
if (ret)
|
|
return -EIO;
|
|
return -EIO;
|
|
|
|
|
|
@@ -251,7 +242,7 @@ static ssize_t adt7410_store_resolution(struct device *dev,
|
|
if (data)
|
|
if (data)
|
|
config |= ADT7410_RESOLUTION;
|
|
config |= ADT7410_RESOLUTION;
|
|
|
|
|
|
- ret = adt7410_i2c_write_byte(chip, ADT7410_CONFIG, config);
|
|
|
|
|
|
+ ret = adt7410_write_byte(chip, ADT7410_CONFIG, config);
|
|
if (ret)
|
|
if (ret)
|
|
return -EIO;
|
|
return -EIO;
|
|
|
|
|
|
@@ -274,7 +265,7 @@ static ssize_t adt7410_show_id(struct device *dev,
|
|
u8 id;
|
|
u8 id;
|
|
int ret;
|
|
int ret;
|
|
|
|
|
|
- ret = adt7410_i2c_read_byte(chip, ADT7410_ID, &id);
|
|
|
|
|
|
+ ret = adt7410_read_byte(chip, ADT7410_ID, &id);
|
|
if (ret)
|
|
if (ret)
|
|
return -EIO;
|
|
return -EIO;
|
|
|
|
|
|
@@ -317,7 +308,7 @@ static ssize_t adt7410_show_value(struct device *dev,
|
|
int ret, i = 0;
|
|
int ret, i = 0;
|
|
|
|
|
|
do {
|
|
do {
|
|
- ret = adt7410_i2c_read_byte(chip, ADT7410_STATUS, &status);
|
|
|
|
|
|
+ ret = adt7410_read_byte(chip, ADT7410_STATUS, &status);
|
|
if (ret)
|
|
if (ret)
|
|
return -EIO;
|
|
return -EIO;
|
|
i++;
|
|
i++;
|
|
@@ -325,7 +316,7 @@ static ssize_t adt7410_show_value(struct device *dev,
|
|
return -EIO;
|
|
return -EIO;
|
|
} while (status & ADT7410_STAT_NOT_RDY);
|
|
} while (status & ADT7410_STAT_NOT_RDY);
|
|
|
|
|
|
- ret = adt7410_i2c_read_word(chip, ADT7410_TEMPERATURE, &data);
|
|
|
|
|
|
+ ret = adt7410_read_word(chip, ADT7410_TEMPERATURE, &data);
|
|
if (ret)
|
|
if (ret)
|
|
return -EIO;
|
|
return -EIO;
|
|
|
|
|
|
@@ -354,7 +345,7 @@ static irqreturn_t adt7410_event_handler(int irq, void *private)
|
|
s64 timestamp = iio_get_time_ns();
|
|
s64 timestamp = iio_get_time_ns();
|
|
u8 status;
|
|
u8 status;
|
|
|
|
|
|
- if (adt7410_i2c_read_byte(chip, ADT7410_STATUS, &status))
|
|
|
|
|
|
+ if (adt7410_read_byte(chip, ADT7410_STATUS, &status))
|
|
return IRQ_HANDLED;
|
|
return IRQ_HANDLED;
|
|
|
|
|
|
if (status & ADT7410_STAT_T_HIGH)
|
|
if (status & ADT7410_STAT_T_HIGH)
|
|
@@ -387,7 +378,7 @@ static ssize_t adt7410_show_event_mode(struct device *dev,
|
|
struct adt7410_chip_info *chip = iio_priv(dev_info);
|
|
struct adt7410_chip_info *chip = iio_priv(dev_info);
|
|
int ret;
|
|
int ret;
|
|
|
|
|
|
- ret = adt7410_i2c_read_byte(chip, ADT7410_CONFIG, &chip->config);
|
|
|
|
|
|
+ ret = adt7410_read_byte(chip, ADT7410_CONFIG, &chip->config);
|
|
if (ret)
|
|
if (ret)
|
|
return -EIO;
|
|
return -EIO;
|
|
|
|
|
|
@@ -407,7 +398,7 @@ static ssize_t adt7410_set_event_mode(struct device *dev,
|
|
u16 config;
|
|
u16 config;
|
|
int ret;
|
|
int ret;
|
|
|
|
|
|
- ret = adt7410_i2c_read_byte(chip, ADT7410_CONFIG, &chip->config);
|
|
|
|
|
|
+ ret = adt7410_read_byte(chip, ADT7410_CONFIG, &chip->config);
|
|
if (ret)
|
|
if (ret)
|
|
return -EIO;
|
|
return -EIO;
|
|
|
|
|
|
@@ -415,7 +406,7 @@ static ssize_t adt7410_set_event_mode(struct device *dev,
|
|
if (strcmp(buf, "comparator") != 0)
|
|
if (strcmp(buf, "comparator") != 0)
|
|
config |= ADT7410_EVENT_MODE;
|
|
config |= ADT7410_EVENT_MODE;
|
|
|
|
|
|
- ret = adt7410_i2c_write_byte(chip, ADT7410_CONFIG, config);
|
|
|
|
|
|
+ ret = adt7410_write_byte(chip, ADT7410_CONFIG, config);
|
|
if (ret)
|
|
if (ret)
|
|
return -EIO;
|
|
return -EIO;
|
|
|
|
|
|
@@ -439,7 +430,7 @@ static ssize_t adt7410_show_fault_queue(struct device *dev,
|
|
struct adt7410_chip_info *chip = iio_priv(dev_info);
|
|
struct adt7410_chip_info *chip = iio_priv(dev_info);
|
|
int ret;
|
|
int ret;
|
|
|
|
|
|
- ret = adt7410_i2c_read_byte(chip, ADT7410_CONFIG, &chip->config);
|
|
|
|
|
|
+ ret = adt7410_read_byte(chip, ADT7410_CONFIG, &chip->config);
|
|
if (ret)
|
|
if (ret)
|
|
return -EIO;
|
|
return -EIO;
|
|
|
|
|
|
@@ -461,13 +452,13 @@ static ssize_t adt7410_set_fault_queue(struct device *dev,
|
|
if (ret || data > 3)
|
|
if (ret || data > 3)
|
|
return -EINVAL;
|
|
return -EINVAL;
|
|
|
|
|
|
- ret = adt7410_i2c_read_byte(chip, ADT7410_CONFIG, &chip->config);
|
|
|
|
|
|
+ ret = adt7410_read_byte(chip, ADT7410_CONFIG, &chip->config);
|
|
if (ret)
|
|
if (ret)
|
|
return -EIO;
|
|
return -EIO;
|
|
|
|
|
|
config = chip->config & ~ADT7410_FAULT_QUEUE_MASK;
|
|
config = chip->config & ~ADT7410_FAULT_QUEUE_MASK;
|
|
config |= data;
|
|
config |= data;
|
|
- ret = adt7410_i2c_write_byte(chip, ADT7410_CONFIG, config);
|
|
|
|
|
|
+ ret = adt7410_write_byte(chip, ADT7410_CONFIG, config);
|
|
if (ret)
|
|
if (ret)
|
|
return -EIO;
|
|
return -EIO;
|
|
|
|
|
|
@@ -486,7 +477,7 @@ static inline ssize_t adt7410_show_t_bound(struct device *dev,
|
|
u16 data;
|
|
u16 data;
|
|
int ret;
|
|
int ret;
|
|
|
|
|
|
- ret = adt7410_i2c_read_word(chip, bound_reg, &data);
|
|
|
|
|
|
+ ret = adt7410_read_word(chip, bound_reg, &data);
|
|
if (ret)
|
|
if (ret)
|
|
return -EIO;
|
|
return -EIO;
|
|
|
|
|
|
@@ -557,7 +548,7 @@ static inline ssize_t adt7410_set_t_bound(struct device *dev,
|
|
data <<= ADT7410_T13_VALUE_OFFSET;
|
|
data <<= ADT7410_T13_VALUE_OFFSET;
|
|
}
|
|
}
|
|
|
|
|
|
- ret = adt7410_i2c_write_word(chip, bound_reg, data);
|
|
|
|
|
|
+ ret = adt7410_write_word(chip, bound_reg, data);
|
|
if (ret)
|
|
if (ret)
|
|
return -EIO;
|
|
return -EIO;
|
|
|
|
|
|
@@ -624,7 +615,7 @@ static ssize_t adt7410_show_t_hyst(struct device *dev,
|
|
int ret;
|
|
int ret;
|
|
u8 t_hyst;
|
|
u8 t_hyst;
|
|
|
|
|
|
- ret = adt7410_i2c_read_byte(chip, ADT7410_T_HYST, &t_hyst);
|
|
|
|
|
|
+ ret = adt7410_read_byte(chip, ADT7410_T_HYST, &t_hyst);
|
|
if (ret)
|
|
if (ret)
|
|
return -EIO;
|
|
return -EIO;
|
|
|
|
|
|
@@ -649,7 +640,7 @@ static inline ssize_t adt7410_set_t_hyst(struct device *dev,
|
|
|
|
|
|
t_hyst = (u8)data;
|
|
t_hyst = (u8)data;
|
|
|
|
|
|
- ret = adt7410_i2c_write_byte(chip, ADT7410_T_HYST, t_hyst);
|
|
|
|
|
|
+ ret = adt7410_write_byte(chip, ADT7410_T_HYST, t_hyst);
|
|
if (ret)
|
|
if (ret)
|
|
return -EIO;
|
|
return -EIO;
|
|
|
|
|
|
@@ -704,14 +695,14 @@ static const struct iio_info adt7410_info = {
|
|
* device probe and remove
|
|
* device probe and remove
|
|
*/
|
|
*/
|
|
|
|
|
|
-static int __devinit adt7410_probe(struct i2c_client *client,
|
|
|
|
- const struct i2c_device_id *id)
|
|
|
|
|
|
+static int __devinit adt7410_probe(struct device *dev, int irq,
|
|
|
|
+ const char *name, const struct adt7410_ops *ops)
|
|
{
|
|
{
|
|
|
|
+ unsigned long *adt7410_platform_data = dev->platform_data;
|
|
|
|
+ unsigned long local_pdata[] = {0, 0};
|
|
struct adt7410_chip_info *chip;
|
|
struct adt7410_chip_info *chip;
|
|
struct iio_dev *indio_dev;
|
|
struct iio_dev *indio_dev;
|
|
int ret = 0;
|
|
int ret = 0;
|
|
- unsigned long *adt7410_platform_data = client->dev.platform_data;
|
|
|
|
- unsigned long local_pdata[] = {0, 0};
|
|
|
|
|
|
|
|
indio_dev = iio_device_alloc(sizeof(*chip));
|
|
indio_dev = iio_device_alloc(sizeof(*chip));
|
|
if (indio_dev == NULL) {
|
|
if (indio_dev == NULL) {
|
|
@@ -720,12 +711,13 @@ static int __devinit adt7410_probe(struct i2c_client *client,
|
|
}
|
|
}
|
|
chip = iio_priv(indio_dev);
|
|
chip = iio_priv(indio_dev);
|
|
/* this is only used for device removal purposes */
|
|
/* this is only used for device removal purposes */
|
|
- i2c_set_clientdata(client, indio_dev);
|
|
|
|
|
|
+ dev_set_drvdata(dev, indio_dev);
|
|
|
|
|
|
- chip->client = client;
|
|
|
|
|
|
+ chip->dev = dev;
|
|
|
|
+ chip->ops = ops;
|
|
|
|
|
|
- indio_dev->name = id->name;
|
|
|
|
- indio_dev->dev.parent = &client->dev;
|
|
|
|
|
|
+ indio_dev->name = name;
|
|
|
|
+ indio_dev->dev.parent = dev;
|
|
indio_dev->info = &adt7410_info;
|
|
indio_dev->info = &adt7410_info;
|
|
indio_dev->modes = INDIO_DIRECT_MODE;
|
|
indio_dev->modes = INDIO_DIRECT_MODE;
|
|
|
|
|
|
@@ -733,12 +725,12 @@ static int __devinit adt7410_probe(struct i2c_client *client,
|
|
adt7410_platform_data = local_pdata;
|
|
adt7410_platform_data = local_pdata;
|
|
|
|
|
|
/* CT critcal temperature event. line 0 */
|
|
/* CT critcal temperature event. line 0 */
|
|
- if (client->irq) {
|
|
|
|
- ret = request_threaded_irq(client->irq,
|
|
|
|
|
|
+ if (irq) {
|
|
|
|
+ ret = request_threaded_irq(irq,
|
|
NULL,
|
|
NULL,
|
|
&adt7410_event_handler,
|
|
&adt7410_event_handler,
|
|
IRQF_TRIGGER_LOW | IRQF_ONESHOT,
|
|
IRQF_TRIGGER_LOW | IRQF_ONESHOT,
|
|
- id->name,
|
|
|
|
|
|
+ name,
|
|
indio_dev);
|
|
indio_dev);
|
|
if (ret)
|
|
if (ret)
|
|
goto error_free_dev;
|
|
goto error_free_dev;
|
|
@@ -751,13 +743,13 @@ static int __devinit adt7410_probe(struct i2c_client *client,
|
|
&adt7410_event_handler,
|
|
&adt7410_event_handler,
|
|
adt7410_platform_data[1] |
|
|
adt7410_platform_data[1] |
|
|
IRQF_ONESHOT,
|
|
IRQF_ONESHOT,
|
|
- id->name,
|
|
|
|
|
|
+ name,
|
|
indio_dev);
|
|
indio_dev);
|
|
if (ret)
|
|
if (ret)
|
|
goto error_unreg_ct_irq;
|
|
goto error_unreg_ct_irq;
|
|
}
|
|
}
|
|
|
|
|
|
- ret = adt7410_i2c_read_byte(chip, ADT7410_CONFIG, &chip->config);
|
|
|
|
|
|
+ ret = adt7410_read_byte(chip, ADT7410_CONFIG, &chip->config);
|
|
if (ret) {
|
|
if (ret) {
|
|
ret = -EIO;
|
|
ret = -EIO;
|
|
goto error_unreg_int_irq;
|
|
goto error_unreg_int_irq;
|
|
@@ -765,7 +757,7 @@ static int __devinit adt7410_probe(struct i2c_client *client,
|
|
|
|
|
|
chip->config |= ADT7410_RESOLUTION;
|
|
chip->config |= ADT7410_RESOLUTION;
|
|
|
|
|
|
- if (client->irq && adt7410_platform_data[0]) {
|
|
|
|
|
|
+ if (irq && adt7410_platform_data[0]) {
|
|
|
|
|
|
/* set irq polarity low level */
|
|
/* set irq polarity low level */
|
|
chip->config &= ~ADT7410_CT_POLARITY;
|
|
chip->config &= ~ADT7410_CT_POLARITY;
|
|
@@ -776,7 +768,7 @@ static int __devinit adt7410_probe(struct i2c_client *client,
|
|
chip->config &= ~ADT7410_INT_POLARITY;
|
|
chip->config &= ~ADT7410_INT_POLARITY;
|
|
}
|
|
}
|
|
|
|
|
|
- ret = adt7410_i2c_write_byte(chip, ADT7410_CONFIG, chip->config);
|
|
|
|
|
|
+ ret = adt7410_write_byte(chip, ADT7410_CONFIG, chip->config);
|
|
if (ret) {
|
|
if (ret) {
|
|
ret = -EIO;
|
|
ret = -EIO;
|
|
goto error_unreg_int_irq;
|
|
goto error_unreg_int_irq;
|
|
@@ -785,36 +777,117 @@ static int __devinit adt7410_probe(struct i2c_client *client,
|
|
if (ret)
|
|
if (ret)
|
|
goto error_unreg_int_irq;
|
|
goto error_unreg_int_irq;
|
|
|
|
|
|
- dev_info(&client->dev, "%s temperature sensor registered.\n",
|
|
|
|
- id->name);
|
|
|
|
|
|
+ dev_info(dev, "%s temperature sensor registered.\n",
|
|
|
|
+ name);
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
|
|
|
|
error_unreg_int_irq:
|
|
error_unreg_int_irq:
|
|
free_irq(adt7410_platform_data[0], indio_dev);
|
|
free_irq(adt7410_platform_data[0], indio_dev);
|
|
error_unreg_ct_irq:
|
|
error_unreg_ct_irq:
|
|
- free_irq(client->irq, indio_dev);
|
|
|
|
|
|
+ free_irq(irq, indio_dev);
|
|
error_free_dev:
|
|
error_free_dev:
|
|
iio_device_free(indio_dev);
|
|
iio_device_free(indio_dev);
|
|
error_ret:
|
|
error_ret:
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
|
|
-static int __devexit adt7410_remove(struct i2c_client *client)
|
|
|
|
|
|
+static int __devexit adt7410_remove(struct device *dev, int irq)
|
|
{
|
|
{
|
|
- struct iio_dev *indio_dev = i2c_get_clientdata(client);
|
|
|
|
- unsigned long *adt7410_platform_data = client->dev.platform_data;
|
|
|
|
|
|
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
|
|
|
|
+ unsigned long *adt7410_platform_data = dev->platform_data;
|
|
|
|
|
|
iio_device_unregister(indio_dev);
|
|
iio_device_unregister(indio_dev);
|
|
if (adt7410_platform_data[0])
|
|
if (adt7410_platform_data[0])
|
|
free_irq(adt7410_platform_data[0], indio_dev);
|
|
free_irq(adt7410_platform_data[0], indio_dev);
|
|
- if (client->irq)
|
|
|
|
- free_irq(client->irq, indio_dev);
|
|
|
|
|
|
+ if (irq)
|
|
|
|
+ free_irq(irq, indio_dev);
|
|
iio_device_free(indio_dev);
|
|
iio_device_free(indio_dev);
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+#if IS_ENABLED(CONFIG_I2C)
|
|
|
|
+
|
|
|
|
+static int adt7410_i2c_read_word(struct adt7410_chip_info *chip, u8 reg,
|
|
|
|
+ u16 *data)
|
|
|
|
+{
|
|
|
|
+ struct i2c_client *client = to_i2c_client(chip->dev);
|
|
|
|
+ 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 adt7410_i2c_write_word(struct adt7410_chip_info *chip, u8 reg,
|
|
|
|
+ u16 data)
|
|
|
|
+{
|
|
|
|
+ struct i2c_client *client = to_i2c_client(chip->dev);
|
|
|
|
+ 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 adt7410_i2c_read_byte(struct adt7410_chip_info *chip, u8 reg,
|
|
|
|
+ u8 *data)
|
|
|
|
+{
|
|
|
|
+ struct i2c_client *client = to_i2c_client(chip->dev);
|
|
|
|
+ int ret = 0;
|
|
|
|
+
|
|
|
|
+ ret = i2c_smbus_read_byte_data(client, reg);
|
|
|
|
+ if (ret < 0) {
|
|
|
|
+ dev_err(&client->dev, "I2C read error\n");
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ *data = (u8)ret;
|
|
|
|
+
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static int adt7410_i2c_write_byte(struct adt7410_chip_info *chip, u8 reg,
|
|
|
|
+ u8 data)
|
|
|
|
+{
|
|
|
|
+ struct i2c_client *client = to_i2c_client(chip->dev);
|
|
|
|
+ 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 const struct adt7410_ops adt7410_i2c_ops = {
|
|
|
|
+ .read_word = adt7410_i2c_read_word,
|
|
|
|
+ .write_word = adt7410_i2c_write_word,
|
|
|
|
+ .read_byte = adt7410_i2c_read_byte,
|
|
|
|
+ .write_byte = adt7410_i2c_write_byte,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+static int __devinit adt7410_i2c_probe(struct i2c_client *client,
|
|
|
|
+ const struct i2c_device_id *id)
|
|
|
|
+{
|
|
|
|
+ return adt7410_probe(&client->dev, client->irq, id->name,
|
|
|
|
+ &adt7410_i2c_ops);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static int __devexit adt7410_i2c_remove(struct i2c_client *client)
|
|
|
|
+{
|
|
|
|
+ return adt7410_remove(&client->dev, client->irq);
|
|
|
|
+}
|
|
|
|
+
|
|
static const struct i2c_device_id adt7410_id[] = {
|
|
static const struct i2c_device_id adt7410_id[] = {
|
|
{ "adt7410", 0 },
|
|
{ "adt7410", 0 },
|
|
{}
|
|
{}
|
|
@@ -826,13 +899,204 @@ static struct i2c_driver adt7410_driver = {
|
|
.driver = {
|
|
.driver = {
|
|
.name = "adt7410",
|
|
.name = "adt7410",
|
|
},
|
|
},
|
|
- .probe = adt7410_probe,
|
|
|
|
- .remove = __devexit_p(adt7410_remove),
|
|
|
|
|
|
+ .probe = adt7410_i2c_probe,
|
|
|
|
+ .remove = __devexit_p(adt7410_i2c_remove),
|
|
.id_table = adt7410_id,
|
|
.id_table = adt7410_id,
|
|
};
|
|
};
|
|
-module_i2c_driver(adt7410_driver);
|
|
|
|
|
|
+
|
|
|
|
+static int __init adt7410_i2c_init(void)
|
|
|
|
+{
|
|
|
|
+ return i2c_add_driver(&adt7410_driver);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void __exit adt7410_i2c_exit(void)
|
|
|
|
+{
|
|
|
|
+ i2c_del_driver(&adt7410_driver);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+#else
|
|
|
|
+
|
|
|
|
+static int __init adt7410_i2c_init(void) { return 0; };
|
|
|
|
+static void __exit adt7410_i2c_exit(void) {};
|
|
|
|
+
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
+#if IS_ENABLED(CONFIG_SPI_MASTER)
|
|
|
|
+
|
|
|
|
+static const u8 adt7371_reg_table[] = {
|
|
|
|
+ [ADT7410_TEMPERATURE] = ADT7310_TEMPERATURE,
|
|
|
|
+ [ADT7410_STATUS] = ADT7310_STATUS,
|
|
|
|
+ [ADT7410_CONFIG] = ADT7310_CONFIG,
|
|
|
|
+ [ADT7410_T_ALARM_HIGH] = ADT7310_T_ALARM_HIGH,
|
|
|
|
+ [ADT7410_T_ALARM_LOW] = ADT7310_T_ALARM_LOW,
|
|
|
|
+ [ADT7410_T_CRIT] = ADT7310_T_CRIT,
|
|
|
|
+ [ADT7410_T_HYST] = ADT7310_T_HYST,
|
|
|
|
+ [ADT7410_ID] = ADT7310_ID,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+#define AD7310_COMMAND(reg) (adt7371_reg_table[(reg)] << ADT7310_CMD_REG_OFFSET)
|
|
|
|
+
|
|
|
|
+static int adt7310_spi_read_word(struct adt7410_chip_info *chip,
|
|
|
|
+ u8 reg, u16 *data)
|
|
|
|
+{
|
|
|
|
+ struct spi_device *spi = to_spi_device(chip->dev);
|
|
|
|
+ u8 command = AD7310_COMMAND(reg);
|
|
|
|
+ int ret = 0;
|
|
|
|
+
|
|
|
|
+ command |= ADT7310_CMD_READ;
|
|
|
|
+ ret = spi_write(spi, &command, sizeof(command));
|
|
|
|
+ if (ret < 0) {
|
|
|
|
+ dev_err(&spi->dev, "SPI write command error\n");
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ret = spi_read(spi, (u8 *)data, sizeof(*data));
|
|
|
|
+ if (ret < 0) {
|
|
|
|
+ dev_err(&spi->dev, "SPI read word error\n");
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ *data = be16_to_cpu(*data);
|
|
|
|
+
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static int adt7310_spi_write_word(struct adt7410_chip_info *chip, u8 reg,
|
|
|
|
+ u16 data)
|
|
|
|
+{
|
|
|
|
+ struct spi_device *spi = to_spi_device(chip->dev);
|
|
|
|
+ u8 buf[3];
|
|
|
|
+ int ret = 0;
|
|
|
|
+
|
|
|
|
+ buf[0] = AD7310_COMMAND(reg);
|
|
|
|
+ buf[1] = (u8)(data >> 8);
|
|
|
|
+ buf[2] = (u8)(data & 0xFF);
|
|
|
|
+
|
|
|
|
+ ret = spi_write(spi, buf, 3);
|
|
|
|
+ if (ret < 0) {
|
|
|
|
+ dev_err(&spi->dev, "SPI write word error\n");
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return ret;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static int adt7310_spi_read_byte(struct adt7410_chip_info *chip, u8 reg,
|
|
|
|
+ u8 *data)
|
|
|
|
+{
|
|
|
|
+ struct spi_device *spi = to_spi_device(chip->dev);
|
|
|
|
+ u8 command = AD7310_COMMAND(reg);
|
|
|
|
+ int ret = 0;
|
|
|
|
+
|
|
|
|
+ command |= ADT7310_CMD_READ;
|
|
|
|
+ ret = spi_write(spi, &command, sizeof(command));
|
|
|
|
+ if (ret < 0) {
|
|
|
|
+ dev_err(&spi->dev, "SPI write command error\n");
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ret = spi_read(spi, data, sizeof(*data));
|
|
|
|
+ if (ret < 0) {
|
|
|
|
+ dev_err(&spi->dev, "SPI read byte error\n");
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static int adt7310_spi_write_byte(struct adt7410_chip_info *chip, u8 reg,
|
|
|
|
+ u8 data)
|
|
|
|
+{
|
|
|
|
+ struct spi_device *spi = to_spi_device(chip->dev);
|
|
|
|
+ u8 buf[2];
|
|
|
|
+ int ret = 0;
|
|
|
|
+
|
|
|
|
+ buf[0] = AD7310_COMMAND(reg);
|
|
|
|
+ buf[1] = data;
|
|
|
|
+
|
|
|
|
+ ret = spi_write(spi, buf, 2);
|
|
|
|
+ if (ret < 0) {
|
|
|
|
+ dev_err(&spi->dev, "SPI write byte error\n");
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return ret;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static const struct adt7410_ops adt7310_spi_ops = {
|
|
|
|
+ .read_word = adt7310_spi_read_word,
|
|
|
|
+ .write_word = adt7310_spi_write_word,
|
|
|
|
+ .read_byte = adt7310_spi_read_byte,
|
|
|
|
+ .write_byte = adt7310_spi_write_byte,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+static int __devinit adt7310_spi_probe(struct spi_device *spi)
|
|
|
|
+{
|
|
|
|
+ return adt7410_probe(&spi->dev, spi->irq,
|
|
|
|
+ spi_get_device_id(spi)->name, &adt7310_spi_ops);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static int __devexit adt7310_spi_remove(struct spi_device *spi)
|
|
|
|
+{
|
|
|
|
+ return adt7410_remove(&spi->dev, spi->irq);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static const struct spi_device_id adt7310_id[] = {
|
|
|
|
+ { "adt7310", 0 },
|
|
|
|
+ {}
|
|
|
|
+};
|
|
|
|
+MODULE_DEVICE_TABLE(spi, adt7310_id);
|
|
|
|
+
|
|
|
|
+static struct spi_driver adt7310_driver = {
|
|
|
|
+ .driver = {
|
|
|
|
+ .name = "adt7310",
|
|
|
|
+ .owner = THIS_MODULE,
|
|
|
|
+ },
|
|
|
|
+ .probe = adt7310_spi_probe,
|
|
|
|
+ .remove = __devexit_p(adt7310_spi_remove),
|
|
|
|
+ .id_table = adt7310_id,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+static int __init adt7310_spi_init(void)
|
|
|
|
+{
|
|
|
|
+ return spi_register_driver(&adt7310_driver);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void adt7310_spi_exit(void)
|
|
|
|
+{
|
|
|
|
+ spi_unregister_driver(&adt7310_driver);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+#else
|
|
|
|
+
|
|
|
|
+static int __init adt7310_spi_init(void) { return 0; };
|
|
|
|
+static void adt7310_spi_exit(void) {};
|
|
|
|
+
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
+static int __init adt7410_init(void)
|
|
|
|
+{
|
|
|
|
+ int ret;
|
|
|
|
+
|
|
|
|
+ ret = adt7310_spi_init();
|
|
|
|
+ if (ret)
|
|
|
|
+ return ret;
|
|
|
|
+
|
|
|
|
+ ret = adt7410_i2c_init();
|
|
|
|
+ if (ret)
|
|
|
|
+ adt7310_spi_exit();
|
|
|
|
+
|
|
|
|
+ return ret;
|
|
|
|
+}
|
|
|
|
+module_init(adt7410_init);
|
|
|
|
+
|
|
|
|
+static void __exit adt7410_exit(void)
|
|
|
|
+{
|
|
|
|
+ adt7410_i2c_exit();
|
|
|
|
+ adt7310_spi_exit();
|
|
|
|
+}
|
|
|
|
+module_exit(adt7410_exit);
|
|
|
|
|
|
MODULE_AUTHOR("Sonic Zhang <sonic.zhang@analog.com>");
|
|
MODULE_AUTHOR("Sonic Zhang <sonic.zhang@analog.com>");
|
|
-MODULE_DESCRIPTION("Analog Devices ADT7410 digital"
|
|
|
|
- " temperature sensor driver");
|
|
|
|
|
|
+MODULE_DESCRIPTION("Analog Devices ADT7310/ADT7410 digital temperature sensor driver");
|
|
MODULE_LICENSE("GPL v2");
|
|
MODULE_LICENSE("GPL v2");
|