xref: /openbmc/linux/drivers/hwmon/adt7410.c (revision 4b5e536b)
1983b97beSHartmut Knaack /*
251c2a487SLars-Peter Clausen  * ADT7410/ADT7420 digital temperature sensor driver
3983b97beSHartmut Knaack  *
451c2a487SLars-Peter Clausen  * Copyright 2012-2013 Analog Devices Inc.
551c2a487SLars-Peter Clausen  *   Author: Lars-Peter Clausen <lars@metafoo.de>
6983b97beSHartmut Knaack  *
751c2a487SLars-Peter Clausen  * Licensed under the GPL-2 or later.
8983b97beSHartmut Knaack  */
9983b97beSHartmut Knaack 
10983b97beSHartmut Knaack #include <linux/module.h>
11983b97beSHartmut Knaack #include <linux/init.h>
12983b97beSHartmut Knaack #include <linux/i2c.h>
13983b97beSHartmut Knaack 
1451c2a487SLars-Peter Clausen #include "adt7x10.h"
15983b97beSHartmut Knaack 
1651c2a487SLars-Peter Clausen static int adt7410_i2c_read_word(struct device *dev, u8 reg)
1751c2a487SLars-Peter Clausen {
1851c2a487SLars-Peter Clausen 	return i2c_smbus_read_word_swapped(to_i2c_client(dev), reg);
1951c2a487SLars-Peter Clausen }
20983b97beSHartmut Knaack 
2151c2a487SLars-Peter Clausen static int adt7410_i2c_write_word(struct device *dev, u8 reg, u16 data)
2251c2a487SLars-Peter Clausen {
2351c2a487SLars-Peter Clausen 	return i2c_smbus_write_word_swapped(to_i2c_client(dev), reg, data);
2451c2a487SLars-Peter Clausen }
25983b97beSHartmut Knaack 
2651c2a487SLars-Peter Clausen static int adt7410_i2c_read_byte(struct device *dev, u8 reg)
2751c2a487SLars-Peter Clausen {
2851c2a487SLars-Peter Clausen 	return i2c_smbus_read_byte_data(to_i2c_client(dev), reg);
2951c2a487SLars-Peter Clausen }
30983b97beSHartmut Knaack 
3151c2a487SLars-Peter Clausen static int adt7410_i2c_write_byte(struct device *dev, u8 reg, u8 data)
3251c2a487SLars-Peter Clausen {
3351c2a487SLars-Peter Clausen 	return i2c_smbus_write_byte_data(to_i2c_client(dev), reg, data);
3451c2a487SLars-Peter Clausen }
35983b97beSHartmut Knaack 
3651c2a487SLars-Peter Clausen static const struct adt7x10_ops adt7410_i2c_ops = {
3751c2a487SLars-Peter Clausen 	.read_word = adt7410_i2c_read_word,
3851c2a487SLars-Peter Clausen 	.write_word = adt7410_i2c_write_word,
3951c2a487SLars-Peter Clausen 	.read_byte = adt7410_i2c_read_byte,
4051c2a487SLars-Peter Clausen 	.write_byte = adt7410_i2c_write_byte,
41983b97beSHartmut Knaack };
42983b97beSHartmut Knaack 
4351c2a487SLars-Peter Clausen static int adt7410_i2c_probe(struct i2c_client *client,
44983b97beSHartmut Knaack 	const struct i2c_device_id *id)
45983b97beSHartmut Knaack {
46983b97beSHartmut Knaack 	if (!i2c_check_functionality(client->adapter,
47983b97beSHartmut Knaack 			I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA))
48983b97beSHartmut Knaack 		return -ENODEV;
49983b97beSHartmut Knaack 
504b5e536bSLars-Peter Clausen 	return adt7x10_probe(&client->dev, NULL, client->irq, &adt7410_i2c_ops);
51983b97beSHartmut Knaack }
52983b97beSHartmut Knaack 
5351c2a487SLars-Peter Clausen static int adt7410_i2c_remove(struct i2c_client *client)
54983b97beSHartmut Knaack {
554b5e536bSLars-Peter Clausen 	return adt7x10_remove(&client->dev, client->irq);
56983b97beSHartmut Knaack }
57983b97beSHartmut Knaack 
58983b97beSHartmut Knaack static const struct i2c_device_id adt7410_ids[] = {
5951c2a487SLars-Peter Clausen 	{ "adt7410", 0 },
6051c2a487SLars-Peter Clausen 	{ "adt7420", 0 },
6151c2a487SLars-Peter Clausen 	{}
62983b97beSHartmut Knaack };
63983b97beSHartmut Knaack MODULE_DEVICE_TABLE(i2c, adt7410_ids);
64983b97beSHartmut Knaack 
65983b97beSHartmut Knaack static struct i2c_driver adt7410_driver = {
66983b97beSHartmut Knaack 	.class		= I2C_CLASS_HWMON,
67983b97beSHartmut Knaack 	.driver = {
68983b97beSHartmut Knaack 		.name	= "adt7410",
6951c2a487SLars-Peter Clausen 		.pm	= ADT7X10_DEV_PM_OPS,
70983b97beSHartmut Knaack 	},
7151c2a487SLars-Peter Clausen 	.probe		= adt7410_i2c_probe,
7251c2a487SLars-Peter Clausen 	.remove		= adt7410_i2c_remove,
73983b97beSHartmut Knaack 	.id_table	= adt7410_ids,
7454be068dSLars-Peter Clausen 	.address_list	= I2C_ADDRS(0x48, 0x49, 0x4a, 0x4b),
75983b97beSHartmut Knaack };
76983b97beSHartmut Knaack module_i2c_driver(adt7410_driver);
77983b97beSHartmut Knaack 
7851c2a487SLars-Peter Clausen MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
7951c2a487SLars-Peter Clausen MODULE_DESCRIPTION("ADT7410/AD7420 driver");
80983b97beSHartmut Knaack MODULE_LICENSE("GPL");
81