blob: 80f8a46733157e278aef85b8862ce9b168c42640 [file] [log] [blame]
Thomas Gleixner80503b22019-05-24 12:04:09 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Hartmut Knaack983b97b2012-08-12 18:15:49 +02002/*
Lars-Peter Clausen51c2a482013-03-12 11:38:46 +01003 * ADT7410/ADT7420 digital temperature sensor driver
Hartmut Knaack983b97b2012-08-12 18:15:49 +02004 *
Lars-Peter Clausen51c2a482013-03-12 11:38:46 +01005 * Copyright 2012-2013 Analog Devices Inc.
6 * Author: Lars-Peter Clausen <lars@metafoo.de>
Hartmut Knaack983b97b2012-08-12 18:15:49 +02007 */
8
9#include <linux/module.h>
10#include <linux/init.h>
Hartmut Knaack983b97b2012-08-12 18:15:49 +020011#include <linux/i2c.h>
Hartmut Knaack983b97b2012-08-12 18:15:49 +020012
Lars-Peter Clausen51c2a482013-03-12 11:38:46 +010013#include "adt7x10.h"
Hartmut Knaack983b97b2012-08-12 18:15:49 +020014
Lars-Peter Clausen51c2a482013-03-12 11:38:46 +010015static int adt7410_i2c_read_word(struct device *dev, u8 reg)
16{
17 return i2c_smbus_read_word_swapped(to_i2c_client(dev), reg);
18}
Hartmut Knaack983b97b2012-08-12 18:15:49 +020019
Lars-Peter Clausen51c2a482013-03-12 11:38:46 +010020static int adt7410_i2c_write_word(struct device *dev, u8 reg, u16 data)
21{
22 return i2c_smbus_write_word_swapped(to_i2c_client(dev), reg, data);
23}
Hartmut Knaack983b97b2012-08-12 18:15:49 +020024
Lars-Peter Clausen51c2a482013-03-12 11:38:46 +010025static int adt7410_i2c_read_byte(struct device *dev, u8 reg)
26{
27 return i2c_smbus_read_byte_data(to_i2c_client(dev), reg);
28}
Hartmut Knaack983b97b2012-08-12 18:15:49 +020029
Lars-Peter Clausen51c2a482013-03-12 11:38:46 +010030static int adt7410_i2c_write_byte(struct device *dev, u8 reg, u8 data)
31{
32 return i2c_smbus_write_byte_data(to_i2c_client(dev), reg, data);
33}
Hartmut Knaack983b97b2012-08-12 18:15:49 +020034
Lars-Peter Clausen51c2a482013-03-12 11:38:46 +010035static const struct adt7x10_ops adt7410_i2c_ops = {
36 .read_word = adt7410_i2c_read_word,
37 .write_word = adt7410_i2c_write_word,
38 .read_byte = adt7410_i2c_read_byte,
39 .write_byte = adt7410_i2c_write_byte,
Hartmut Knaack983b97b2012-08-12 18:15:49 +020040};
41
Lars-Peter Clausen51c2a482013-03-12 11:38:46 +010042static int adt7410_i2c_probe(struct i2c_client *client,
43 const struct i2c_device_id *id)
Hartmut Knaack983b97b2012-08-12 18:15:49 +020044{
Hartmut Knaack983b97b2012-08-12 18:15:49 +020045 if (!i2c_check_functionality(client->adapter,
46 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA))
47 return -ENODEV;
48
Lars-Peter Clausen4b5e5362013-03-12 11:38:47 +010049 return adt7x10_probe(&client->dev, NULL, client->irq, &adt7410_i2c_ops);
Hartmut Knaack983b97b2012-08-12 18:15:49 +020050}
51
Lars-Peter Clausen51c2a482013-03-12 11:38:46 +010052static int adt7410_i2c_remove(struct i2c_client *client)
Hartmut Knaack983b97b2012-08-12 18:15:49 +020053{
Lars-Peter Clausen4b5e5362013-03-12 11:38:47 +010054 return adt7x10_remove(&client->dev, client->irq);
Hartmut Knaack983b97b2012-08-12 18:15:49 +020055}
56
57static const struct i2c_device_id adt7410_ids[] = {
Lars-Peter Clausen51c2a482013-03-12 11:38:46 +010058 { "adt7410", 0 },
59 { "adt7420", 0 },
60 {}
Hartmut Knaack983b97b2012-08-12 18:15:49 +020061};
62MODULE_DEVICE_TABLE(i2c, adt7410_ids);
63
Hartmut Knaack983b97b2012-08-12 18:15:49 +020064static struct i2c_driver adt7410_driver = {
65 .class = I2C_CLASS_HWMON,
66 .driver = {
67 .name = "adt7410",
Lars-Peter Clausen51c2a482013-03-12 11:38:46 +010068 .pm = ADT7X10_DEV_PM_OPS,
Hartmut Knaack983b97b2012-08-12 18:15:49 +020069 },
Lars-Peter Clausen51c2a482013-03-12 11:38:46 +010070 .probe = adt7410_i2c_probe,
71 .remove = adt7410_i2c_remove,
Hartmut Knaack983b97b2012-08-12 18:15:49 +020072 .id_table = adt7410_ids,
Lars-Peter Clausen54be0682013-02-15 17:57:13 +010073 .address_list = I2C_ADDRS(0x48, 0x49, 0x4a, 0x4b),
Hartmut Knaack983b97b2012-08-12 18:15:49 +020074};
Hartmut Knaack983b97b2012-08-12 18:15:49 +020075module_i2c_driver(adt7410_driver);
76
Lars-Peter Clausen51c2a482013-03-12 11:38:46 +010077MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
78MODULE_DESCRIPTION("ADT7410/AD7420 driver");
Hartmut Knaack983b97b2012-08-12 18:15:49 +020079MODULE_LICENSE("GPL");