Commit 51c2a487 authored by Lars-Peter Clausen's avatar Lars-Peter Clausen Committed by Guenter Roeck

hwmon: (adt7410) Add support for the adt7310/adt7320

The adt7310/adt7320 is the SPI version of the adt7410/adt7420. The register map
layout is a bit different, i.e. the register addresses differ between the two
variants, but the bit layouts of the individual registers are identical. So both
chip variants can easily be supported by the same driver. The issue of non
matching register address layouts is solved by a simple look-up table which
translates the I2C addresses to the SPI addresses.

The patch moves the bulk of the adt7410 driver to a common module that will be
shared by the adt7410 and adt7310 drivers. This common module implements the
driver logic and uses a set of virtual functions to perform IO access. The
adt7410 and adt7310 driver modules provide proper implementations of these IO
accessor functions for I2C respective SPI.
Signed-off-by: default avatarLars-Peter Clausen <lars@metafoo.de>
Reviewed-by: default avatarHartmut Knaack <knaack.h@gmx.de>
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent c55dc91e
......@@ -12,29 +12,42 @@ Supported chips:
Addresses scanned: None
Datasheet: Publicly available at the Analog Devices website
http://www.analog.com/static/imported-files/data_sheets/ADT7420.pdf
* Analog Devices ADT7310
Prefix: 'adt7310'
Addresses scanned: None
Datasheet: Publicly available at the Analog Devices website
http://www.analog.com/static/imported-files/data_sheets/ADT7310.pdf
* Analog Devices ADT7320
Prefix: 'adt7320'
Addresses scanned: None
Datasheet: Publicly available at the Analog Devices website
http://www.analog.com/static/imported-files/data_sheets/ADT7320.pdf
Author: Hartmut Knaack <knaack.h@gmx.de>
Description
-----------
The ADT7410 is a temperature sensor with rated temperature range of -55°C to
+150°C. It has a high accuracy of +/-0.5°C and can be operated at a resolution
of 13 bits (0.0625°C) or 16 bits (0.0078°C). The sensor provides an INT pin to
indicate that a minimum or maximum temperature set point has been exceeded, as
well as a critical temperature (CT) pin to indicate that the critical
temperature set point has been exceeded. Both pins can be set up with a common
hysteresis of 0°C - 15°C and a fault queue, ranging from 1 to 4 events. Both
pins can individually set to be active-low or active-high, while the whole
device can either run in comparator mode or interrupt mode. The ADT7410
supports continous temperature sampling, as well as sampling one temperature
value per second or even justget one sample on demand for power saving.
Besides, it can completely power down its ADC, if power management is
required.
The ADT7420 is register compatible, the only differences being the package,
a slightly narrower operating temperature range (-40°C to +150°C), and a
better accuracy (0.25°C instead of 0.50°C.)
The ADT7310/ADT7410 is a temperature sensor with rated temperature range of
-55°C to +150°C. It has a high accuracy of +/-0.5°C and can be operated at a
resolution of 13 bits (0.0625°C) or 16 bits (0.0078°C). The sensor provides an
INT pin to indicate that a minimum or maximum temperature set point has been
exceeded, as well as a critical temperature (CT) pin to indicate that the
critical temperature set point has been exceeded. Both pins can be set up with a
common hysteresis of 0°C - 15°C and a fault queue, ranging from 1 to 4 events.
Both pins can individually set to be active-low or active-high, while the whole
device can either run in comparator mode or interrupt mode. The ADT7410 supports
continuous temperature sampling, as well as sampling one temperature value per
second or even just get one sample on demand for power saving. Besides, it can
completely power down its ADC, if power management is required.
The ADT7320/ADT7420 is register compatible, the only differences being the
package, a slightly narrower operating temperature range (-40°C to +150°C), and
a better accuracy (0.25°C instead of 0.50°C.)
The difference between the ADT7310/ADT7320 and ADT7410/ADT7420 is the control
interface, the ADT7310 and ADT7320 use SPI while the ADT7410 and ADT7420 use
I2C.
Configuration Notes
-------------------
......
......@@ -179,9 +179,29 @@ config SENSORS_ADM9240
This driver can also be built as a module. If so, the module
will be called adm9240.
config SENSORS_ADT7X10
tristate
help
This module contains common code shared by the ADT7310/ADT7320 and
ADT7410/ADT7420 temperature monitoring chip drivers.
If build as a module, the module will be called adt7x10.
config SENSORS_ADT7310
tristate "Analog Devices ADT7310/ADT7320"
depends on SPI_MASTER
select SENSORS_ADT7X10
help
If you say yes here you get support for the Analog Devices
ADT7310 and ADT7320 temperature monitoring chips.
This driver can also be built as a module. If so, the module
will be called adt7310.
config SENSORS_ADT7410
tristate "Analog Devices ADT7410/ADT7420"
depends on I2C
select SENSORS_ADT7X10
help
If you say yes here you get support for the Analog Devices
ADT7410 and ADT7420 temperature monitoring chips.
......
......@@ -34,6 +34,8 @@ obj-$(CONFIG_SENSORS_ADM9240) += adm9240.o
obj-$(CONFIG_SENSORS_ADS1015) += ads1015.o
obj-$(CONFIG_SENSORS_ADS7828) += ads7828.o
obj-$(CONFIG_SENSORS_ADS7871) += ads7871.o
obj-$(CONFIG_SENSORS_ADT7X10) += adt7x10.o
obj-$(CONFIG_SENSORS_ADT7310) += adt7310.o
obj-$(CONFIG_SENSORS_ADT7410) += adt7410.o
obj-$(CONFIG_SENSORS_ADT7411) += adt7411.o
obj-$(CONFIG_SENSORS_ADT7462) += adt7462.o
......
/*
* ADT7310/ADT7310 digital temperature sensor driver
*
* Copyright 2012-2013 Analog Devices Inc.
* Author: Lars-Peter Clausen <lars@metafoo.de>
*
* Licensed under the GPL-2 or later.
*/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/spi/spi.h>
#include <asm/unaligned.h>
#include "adt7x10.h"
#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
static const u8 adt7310_reg_table[] = {
[ADT7X10_TEMPERATURE] = ADT7310_TEMPERATURE,
[ADT7X10_STATUS] = ADT7310_STATUS,
[ADT7X10_CONFIG] = ADT7310_CONFIG,
[ADT7X10_T_ALARM_HIGH] = ADT7310_T_ALARM_HIGH,
[ADT7X10_T_ALARM_LOW] = ADT7310_T_ALARM_LOW,
[ADT7X10_T_CRIT] = ADT7310_T_CRIT,
[ADT7X10_T_HYST] = ADT7310_T_HYST,
[ADT7X10_ID] = ADT7310_ID,
};
#define ADT7310_CMD_REG_OFFSET 3
#define ADT7310_CMD_READ 0x40
#define AD7310_COMMAND(reg) (adt7310_reg_table[(reg)] << ADT7310_CMD_REG_OFFSET)
static int adt7310_spi_read_word(struct device *dev, u8 reg)
{
struct spi_device *spi = to_spi_device(dev);
int ret;
ret = spi_w8r16(spi, AD7310_COMMAND(reg) | ADT7310_CMD_READ);
if (ret < 0)
return ret;
return be16_to_cpu(ret);
}
static int adt7310_spi_write_word(struct device *dev, u8 reg, u16 data)
{
struct spi_device *spi = to_spi_device(dev);
u8 buf[3];
buf[0] = AD7310_COMMAND(reg);
put_unaligned_be16(data, &buf[1]);
return spi_write(spi, buf, sizeof(buf));
}
static int adt7310_spi_read_byte(struct device *dev, u8 reg)
{
struct spi_device *spi = to_spi_device(dev);
return spi_w8r8(spi, AD7310_COMMAND(reg) | ADT7310_CMD_READ);
}
static int adt7310_spi_write_byte(struct device *dev, u8 reg,
u8 data)
{
struct spi_device *spi = to_spi_device(dev);
u8 buf[2];
buf[0] = AD7310_COMMAND(reg);
buf[1] = data;
return spi_write(spi, buf, sizeof(buf));
}
static const struct adt7x10_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 adt7310_spi_probe(struct spi_device *spi)
{
return adt7x10_probe(&spi->dev, spi_get_device_id(spi)->name,
&adt7310_spi_ops);
}
static int adt7310_spi_remove(struct spi_device *spi)
{
return adt7x10_remove(&spi->dev);
}
static const struct spi_device_id adt7310_id[] = {
{ "adt7310", 0 },
{ "adt7320", 0 },
{}
};
MODULE_DEVICE_TABLE(spi, adt7310_id);
static struct spi_driver adt7310_driver = {
.driver = {
.name = "adt7310",
.owner = THIS_MODULE,
.pm = ADT7X10_DEV_PM_OPS,
},
.probe = adt7310_spi_probe,
.remove = adt7310_spi_remove,
.id_table = adt7310_id,
};
module_spi_driver(adt7310_driver);
MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
MODULE_DESCRIPTION("ADT7310/ADT7320 driver");
MODULE_LICENSE("GPL");
This diff is collapsed.
This diff is collapsed.
#ifndef __HWMON_ADT7X10_H__
#define __HWMON_ADT7X10_H__
#include <linux/types.h>
#include <linux/pm.h>
/* ADT7410 registers definition */
#define ADT7X10_TEMPERATURE 0
#define ADT7X10_STATUS 2
#define ADT7X10_CONFIG 3
#define ADT7X10_T_ALARM_HIGH 4
#define ADT7X10_T_ALARM_LOW 6
#define ADT7X10_T_CRIT 8
#define ADT7X10_T_HYST 0xA
#define ADT7X10_ID 0xB
struct device;
struct adt7x10_ops {
int (*read_byte)(struct device *, u8 reg);
int (*write_byte)(struct device *, u8 reg, u8 data);
int (*read_word)(struct device *, u8 reg);
int (*write_word)(struct device *, u8 reg, u16 data);
};
int adt7x10_probe(struct device *dev, const char *name,
const struct adt7x10_ops *ops);
int adt7x10_remove(struct device *dev);
#ifdef CONFIG_PM_SLEEP
extern const struct dev_pm_ops adt7x10_dev_pm_ops;
#define ADT7X10_DEV_PM_OPS (&adt7x10_dev_pm_ops)
#else
#define ADT7X10_DEV_PM_OPS NULL
#endif
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment