blob: 0dc066a939b4d25f94a573aa13dda54b43cc5fff [file] [log] [blame]
Hartmut Knaack983b97b2012-08-12 18:15:49 +02001/*
Lars-Peter Clausen51c2a482013-03-12 11:38:46 +01002 * ADT7410/ADT7420 digital temperature sensor driver
Hartmut Knaack983b97b2012-08-12 18:15:49 +02003 *
Lars-Peter Clausen51c2a482013-03-12 11:38:46 +01004 * Copyright 2012-2013 Analog Devices Inc.
5 * Author: Lars-Peter Clausen <lars@metafoo.de>
Hartmut Knaack983b97b2012-08-12 18:15:49 +02006 *
Lars-Peter Clausen51c2a482013-03-12 11:38:46 +01007 * Licensed under the GPL-2 or later.
Hartmut Knaack983b97b2012-08-12 18:15:49 +02008 */
9
10#include <linux/module.h>
11#include <linux/init.h>
Hartmut Knaack983b97b2012-08-12 18:15:49 +020012#include <linux/i2c.h>
Hartmut Knaack983b97b2012-08-12 18:15:49 +020013
Lars-Peter Clausen51c2a482013-03-12 11:38:46 +010014#include "adt7x10.h"
Hartmut Knaack983b97b2012-08-12 18:15:49 +020015
Lars-Peter Clausen51c2a482013-03-12 11:38:46 +010016static int adt7410_i2c_read_word(struct device *dev, u8 reg)
17{
18 return i2c_smbus_read_word_swapped(to_i2c_client(dev), reg);
19}
Hartmut Knaack983b97b2012-08-12 18:15:49 +020020
Lars-Peter Clausen51c2a482013-03-12 11:38:46 +010021static int adt7410_i2c_write_word(struct device *dev, u8 reg, u16 data)
22{
23 return i2c_smbus_write_word_swapped(to_i2c_client(dev), reg, data);
24}
Hartmut Knaack983b97b2012-08-12 18:15:49 +020025
Lars-Peter Clausen51c2a482013-03-12 11:38:46 +010026static int adt7410_i2c_read_byte(struct device *dev, u8 reg)
27{
28 return i2c_smbus_read_byte_data(to_i2c_client(dev), reg);
29}
Hartmut Knaack983b97b2012-08-12 18:15:49 +020030
Lars-Peter Clausen51c2a482013-03-12 11:38:46 +010031static int adt7410_i2c_write_byte(struct device *dev, u8 reg, u8 data)
32{
33 return i2c_smbus_write_byte_data(to_i2c_client(dev), reg, data);
34}
Hartmut Knaack983b97b2012-08-12 18:15:49 +020035
Lars-Peter Clausen51c2a482013-03-12 11:38:46 +010036static const struct adt7x10_ops adt7410_i2c_ops = {
37 .read_word = adt7410_i2c_read_word,
38 .write_word = adt7410_i2c_write_word,
39 .read_byte = adt7410_i2c_read_byte,
40 .write_byte = adt7410_i2c_write_byte,
Hartmut Knaack983b97b2012-08-12 18:15:49 +020041};
42
Lars-Peter Clausen51c2a482013-03-12 11:38:46 +010043static int adt7410_i2c_probe(struct i2c_client *client,
44 const struct i2c_device_id *id)
Hartmut Knaack983b97b2012-08-12 18:15:49 +020045{
Hartmut Knaack983b97b2012-08-12 18:15:49 +020046 if (!i2c_check_functionality(client->adapter,
47 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA))
48 return -ENODEV;
49
Lars-Peter Clausen4b5e5362013-03-12 11:38:47 +010050 return adt7x10_probe(&client->dev, NULL, client->irq, &adt7410_i2c_ops);
Hartmut Knaack983b97b2012-08-12 18:15:49 +020051}
52
Lars-Peter Clausen51c2a482013-03-12 11:38:46 +010053static int adt7410_i2c_remove(struct i2c_client *client)
Hartmut Knaack983b97b2012-08-12 18:15:49 +020054{
Lars-Peter Clausen4b5e5362013-03-12 11:38:47 +010055 return adt7x10_remove(&client->dev, client->irq);
Hartmut Knaack983b97b2012-08-12 18:15:49 +020056}
57
58static const struct i2c_device_id adt7410_ids[] = {
Lars-Peter Clausen51c2a482013-03-12 11:38:46 +010059 { "adt7410", 0 },
60 { "adt7420", 0 },
61 {}
Hartmut Knaack983b97b2012-08-12 18:15:49 +020062};
63MODULE_DEVICE_TABLE(i2c, adt7410_ids);
64
Hartmut Knaack983b97b2012-08-12 18:15:49 +020065static struct i2c_driver adt7410_driver = {
66 .class = I2C_CLASS_HWMON,
67 .driver = {
68 .name = "adt7410",
Lars-Peter Clausen51c2a482013-03-12 11:38:46 +010069 .pm = ADT7X10_DEV_PM_OPS,
Hartmut Knaack983b97b2012-08-12 18:15:49 +020070 },
Lars-Peter Clausen51c2a482013-03-12 11:38:46 +010071 .probe = adt7410_i2c_probe,
72 .remove = adt7410_i2c_remove,
Hartmut Knaack983b97b2012-08-12 18:15:49 +020073 .id_table = adt7410_ids,
Lars-Peter Clausen54be0682013-02-15 17:57:13 +010074 .address_list = I2C_ADDRS(0x48, 0x49, 0x4a, 0x4b),
Hartmut Knaack983b97b2012-08-12 18:15:49 +020075};
Hartmut Knaack983b97b2012-08-12 18:15:49 +020076module_i2c_driver(adt7410_driver);
77
Lars-Peter Clausen51c2a482013-03-12 11:38:46 +010078MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
79MODULE_DESCRIPTION("ADT7410/AD7420 driver");
Hartmut Knaack983b97b2012-08-12 18:15:49 +020080MODULE_LICENSE("GPL");