1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * ADT7410/ADT7420 digital temperature sensor driver
5 * Copyright 2012-2013 Analog Devices Inc.
6 * Author: Lars-Peter Clausen <lars@metafoo.de>
9 #include <linux/module.h>
10 #include <linux/init.h>
11 #include <linux/i2c.h>
12 #include <linux/regmap.h>
16 static bool adt7410_regmap_is_volatile(struct device
*dev
, unsigned int reg
)
19 case ADT7X10_TEMPERATURE
:
27 static int adt7410_reg_read(void *context
, unsigned int reg
, unsigned int *val
)
29 struct i2c_client
*client
= context
;
33 case ADT7X10_TEMPERATURE
:
34 case ADT7X10_T_ALARM_HIGH
:
35 case ADT7X10_T_ALARM_LOW
:
37 regval
= i2c_smbus_read_word_swapped(client
, reg
);
40 regval
= i2c_smbus_read_byte_data(client
, reg
);
49 static int adt7410_reg_write(void *context
, unsigned int reg
, unsigned int val
)
51 struct i2c_client
*client
= context
;
55 case ADT7X10_TEMPERATURE
:
56 case ADT7X10_T_ALARM_HIGH
:
57 case ADT7X10_T_ALARM_LOW
:
59 ret
= i2c_smbus_write_word_swapped(client
, reg
, val
);
62 ret
= i2c_smbus_write_byte_data(client
, reg
, val
);
68 static const struct regmap_config adt7410_regmap_config
= {
71 .max_register
= ADT7X10_ID
,
72 .cache_type
= REGCACHE_MAPLE
,
73 .volatile_reg
= adt7410_regmap_is_volatile
,
74 .reg_read
= adt7410_reg_read
,
75 .reg_write
= adt7410_reg_write
,
78 static int adt7410_i2c_probe(struct i2c_client
*client
)
80 struct regmap
*regmap
;
82 regmap
= devm_regmap_init(&client
->dev
, NULL
, client
,
83 &adt7410_regmap_config
);
85 return PTR_ERR(regmap
);
87 return adt7x10_probe(&client
->dev
, client
->name
, client
->irq
, regmap
);
90 static const struct i2c_device_id adt7410_ids
[] = {
95 MODULE_DEVICE_TABLE(i2c
, adt7410_ids
);
97 static struct i2c_driver adt7410_driver
= {
100 .pm
= pm_sleep_ptr(&adt7x10_dev_pm_ops
),
102 .probe
= adt7410_i2c_probe
,
103 .id_table
= adt7410_ids
,
105 module_i2c_driver(adt7410_driver
);
107 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
108 MODULE_DESCRIPTION("ADT7410/AD7420 driver");
109 MODULE_LICENSE("GPL");