Hartmut Knaack | 983b97b | 2012-08-12 18:15:49 +0200 | [diff] [blame] | 1 | /* |
Lars-Peter Clausen | 51c2a48 | 2013-03-12 11:38:46 +0100 | [diff] [blame] | 2 | * ADT7410/ADT7420 digital temperature sensor driver |
Hartmut Knaack | 983b97b | 2012-08-12 18:15:49 +0200 | [diff] [blame] | 3 | * |
Lars-Peter Clausen | 51c2a48 | 2013-03-12 11:38:46 +0100 | [diff] [blame] | 4 | * Copyright 2012-2013 Analog Devices Inc. |
| 5 | * Author: Lars-Peter Clausen <lars@metafoo.de> |
Hartmut Knaack | 983b97b | 2012-08-12 18:15:49 +0200 | [diff] [blame] | 6 | * |
Lars-Peter Clausen | 51c2a48 | 2013-03-12 11:38:46 +0100 | [diff] [blame] | 7 | * Licensed under the GPL-2 or later. |
Hartmut Knaack | 983b97b | 2012-08-12 18:15:49 +0200 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/init.h> |
Hartmut Knaack | 983b97b | 2012-08-12 18:15:49 +0200 | [diff] [blame] | 12 | #include <linux/i2c.h> |
Hartmut Knaack | 983b97b | 2012-08-12 18:15:49 +0200 | [diff] [blame] | 13 | |
Lars-Peter Clausen | 51c2a48 | 2013-03-12 11:38:46 +0100 | [diff] [blame] | 14 | #include "adt7x10.h" |
Hartmut Knaack | 983b97b | 2012-08-12 18:15:49 +0200 | [diff] [blame] | 15 | |
Lars-Peter Clausen | 51c2a48 | 2013-03-12 11:38:46 +0100 | [diff] [blame] | 16 | static 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 Knaack | 983b97b | 2012-08-12 18:15:49 +0200 | [diff] [blame] | 20 | |
Lars-Peter Clausen | 51c2a48 | 2013-03-12 11:38:46 +0100 | [diff] [blame] | 21 | static 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 Knaack | 983b97b | 2012-08-12 18:15:49 +0200 | [diff] [blame] | 25 | |
Lars-Peter Clausen | 51c2a48 | 2013-03-12 11:38:46 +0100 | [diff] [blame] | 26 | static 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 Knaack | 983b97b | 2012-08-12 18:15:49 +0200 | [diff] [blame] | 30 | |
Lars-Peter Clausen | 51c2a48 | 2013-03-12 11:38:46 +0100 | [diff] [blame] | 31 | static 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 Knaack | 983b97b | 2012-08-12 18:15:49 +0200 | [diff] [blame] | 35 | |
Lars-Peter Clausen | 51c2a48 | 2013-03-12 11:38:46 +0100 | [diff] [blame] | 36 | static 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 Knaack | 983b97b | 2012-08-12 18:15:49 +0200 | [diff] [blame] | 41 | }; |
| 42 | |
Lars-Peter Clausen | 51c2a48 | 2013-03-12 11:38:46 +0100 | [diff] [blame] | 43 | static int adt7410_i2c_probe(struct i2c_client *client, |
| 44 | const struct i2c_device_id *id) |
Hartmut Knaack | 983b97b | 2012-08-12 18:15:49 +0200 | [diff] [blame] | 45 | { |
Hartmut Knaack | 983b97b | 2012-08-12 18:15:49 +0200 | [diff] [blame] | 46 | if (!i2c_check_functionality(client->adapter, |
| 47 | I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA)) |
| 48 | return -ENODEV; |
| 49 | |
Lars-Peter Clausen | 4b5e536 | 2013-03-12 11:38:47 +0100 | [diff] [blame] | 50 | return adt7x10_probe(&client->dev, NULL, client->irq, &adt7410_i2c_ops); |
Hartmut Knaack | 983b97b | 2012-08-12 18:15:49 +0200 | [diff] [blame] | 51 | } |
| 52 | |
Lars-Peter Clausen | 51c2a48 | 2013-03-12 11:38:46 +0100 | [diff] [blame] | 53 | static int adt7410_i2c_remove(struct i2c_client *client) |
Hartmut Knaack | 983b97b | 2012-08-12 18:15:49 +0200 | [diff] [blame] | 54 | { |
Lars-Peter Clausen | 4b5e536 | 2013-03-12 11:38:47 +0100 | [diff] [blame] | 55 | return adt7x10_remove(&client->dev, client->irq); |
Hartmut Knaack | 983b97b | 2012-08-12 18:15:49 +0200 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | static const struct i2c_device_id adt7410_ids[] = { |
Lars-Peter Clausen | 51c2a48 | 2013-03-12 11:38:46 +0100 | [diff] [blame] | 59 | { "adt7410", 0 }, |
| 60 | { "adt7420", 0 }, |
| 61 | {} |
Hartmut Knaack | 983b97b | 2012-08-12 18:15:49 +0200 | [diff] [blame] | 62 | }; |
| 63 | MODULE_DEVICE_TABLE(i2c, adt7410_ids); |
| 64 | |
Hartmut Knaack | 983b97b | 2012-08-12 18:15:49 +0200 | [diff] [blame] | 65 | static struct i2c_driver adt7410_driver = { |
| 66 | .class = I2C_CLASS_HWMON, |
| 67 | .driver = { |
| 68 | .name = "adt7410", |
Lars-Peter Clausen | 51c2a48 | 2013-03-12 11:38:46 +0100 | [diff] [blame] | 69 | .pm = ADT7X10_DEV_PM_OPS, |
Hartmut Knaack | 983b97b | 2012-08-12 18:15:49 +0200 | [diff] [blame] | 70 | }, |
Lars-Peter Clausen | 51c2a48 | 2013-03-12 11:38:46 +0100 | [diff] [blame] | 71 | .probe = adt7410_i2c_probe, |
| 72 | .remove = adt7410_i2c_remove, |
Hartmut Knaack | 983b97b | 2012-08-12 18:15:49 +0200 | [diff] [blame] | 73 | .id_table = adt7410_ids, |
Lars-Peter Clausen | 54be068 | 2013-02-15 17:57:13 +0100 | [diff] [blame] | 74 | .address_list = I2C_ADDRS(0x48, 0x49, 0x4a, 0x4b), |
Hartmut Knaack | 983b97b | 2012-08-12 18:15:49 +0200 | [diff] [blame] | 75 | }; |
Hartmut Knaack | 983b97b | 2012-08-12 18:15:49 +0200 | [diff] [blame] | 76 | module_i2c_driver(adt7410_driver); |
| 77 | |
Lars-Peter Clausen | 51c2a48 | 2013-03-12 11:38:46 +0100 | [diff] [blame] | 78 | MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); |
| 79 | MODULE_DESCRIPTION("ADT7410/AD7420 driver"); |
Hartmut Knaack | 983b97b | 2012-08-12 18:15:49 +0200 | [diff] [blame] | 80 | MODULE_LICENSE("GPL"); |