Commit | Line | Data |
---|---|---|
80503b23 | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
983b97be | 2 | /* |
51c2a487 | 3 | * ADT7410/ADT7420 digital temperature sensor driver |
983b97be | 4 | * |
51c2a487 LPC |
5 | * Copyright 2012-2013 Analog Devices Inc. |
6 | * Author: Lars-Peter Clausen <lars@metafoo.de> | |
983b97be HK |
7 | */ |
8 | ||
9 | #include <linux/module.h> | |
10 | #include <linux/init.h> | |
983b97be | 11 | #include <linux/i2c.h> |
f5320701 | 12 | #include <linux/regmap.h> |
983b97be | 13 | |
51c2a487 | 14 | #include "adt7x10.h" |
983b97be | 15 | |
f5320701 | 16 | static bool adt7410_regmap_is_volatile(struct device *dev, unsigned int reg) |
983b97be | 17 | { |
f5320701 GR |
18 | switch (reg) { |
19 | case ADT7X10_TEMPERATURE: | |
20 | case ADT7X10_STATUS: | |
21 | return true; | |
22 | default: | |
23 | return false; | |
24 | } | |
983b97be HK |
25 | } |
26 | ||
f5320701 | 27 | static int adt7410_reg_read(void *context, unsigned int reg, unsigned int *val) |
983b97be | 28 | { |
f5320701 GR |
29 | struct i2c_client *client = context; |
30 | int regval; | |
983b97be | 31 | |
f5320701 GR |
32 | switch (reg) { |
33 | case ADT7X10_TEMPERATURE: | |
34 | case ADT7X10_T_ALARM_HIGH: | |
35 | case ADT7X10_T_ALARM_LOW: | |
36 | case ADT7X10_T_CRIT: | |
37 | regval = i2c_smbus_read_word_swapped(client, reg); | |
38 | break; | |
39 | default: | |
40 | regval = i2c_smbus_read_byte_data(client, reg); | |
41 | break; | |
42 | } | |
43 | if (regval < 0) | |
44 | return regval; | |
45 | *val = regval; | |
46 | return 0; | |
983b97be HK |
47 | } |
48 | ||
f5320701 | 49 | static int adt7410_reg_write(void *context, unsigned int reg, unsigned int val) |
983b97be | 50 | { |
f5320701 GR |
51 | struct i2c_client *client = context; |
52 | int ret; | |
53 | ||
54 | switch (reg) { | |
55 | case ADT7X10_TEMPERATURE: | |
56 | case ADT7X10_T_ALARM_HIGH: | |
57 | case ADT7X10_T_ALARM_LOW: | |
58 | case ADT7X10_T_CRIT: | |
59 | ret = i2c_smbus_write_word_swapped(client, reg, val); | |
60 | break; | |
61 | default: | |
62 | ret = i2c_smbus_write_byte_data(client, reg, val); | |
63 | break; | |
64 | } | |
65 | return ret; | |
983b97be HK |
66 | } |
67 | ||
f5320701 GR |
68 | static const struct regmap_config adt7410_regmap_config = { |
69 | .reg_bits = 8, | |
70 | .val_bits = 16, | |
71 | .max_register = ADT7X10_ID, | |
72 | .cache_type = REGCACHE_RBTREE, | |
73 | .volatile_reg = adt7410_regmap_is_volatile, | |
74 | .reg_read = adt7410_reg_read, | |
75 | .reg_write = adt7410_reg_write, | |
983b97be HK |
76 | }; |
77 | ||
67487038 | 78 | static int adt7410_i2c_probe(struct i2c_client *client) |
983b97be | 79 | { |
f5320701 GR |
80 | struct regmap *regmap; |
81 | ||
82 | regmap = devm_regmap_init(&client->dev, NULL, client, | |
83 | &adt7410_regmap_config); | |
84 | if (IS_ERR(regmap)) | |
85 | return PTR_ERR(regmap); | |
983b97be | 86 | |
a748d30c | 87 | return adt7x10_probe(&client->dev, client->name, client->irq, regmap); |
983b97be HK |
88 | } |
89 | ||
983b97be | 90 | static const struct i2c_device_id adt7410_ids[] = { |
51c2a487 LPC |
91 | { "adt7410", 0 }, |
92 | { "adt7420", 0 }, | |
93 | {} | |
983b97be HK |
94 | }; |
95 | MODULE_DEVICE_TABLE(i2c, adt7410_ids); | |
96 | ||
983b97be HK |
97 | static struct i2c_driver adt7410_driver = { |
98 | .class = I2C_CLASS_HWMON, | |
99 | .driver = { | |
100 | .name = "adt7410", | |
29805956 | 101 | .pm = pm_sleep_ptr(&adt7x10_dev_pm_ops), |
983b97be | 102 | }, |
67487038 | 103 | .probe_new = adt7410_i2c_probe, |
983b97be | 104 | .id_table = adt7410_ids, |
54be068d | 105 | .address_list = I2C_ADDRS(0x48, 0x49, 0x4a, 0x4b), |
983b97be | 106 | }; |
983b97be HK |
107 | module_i2c_driver(adt7410_driver); |
108 | ||
51c2a487 LPC |
109 | MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); |
110 | MODULE_DESCRIPTION("ADT7410/AD7420 driver"); | |
983b97be | 111 | MODULE_LICENSE("GPL"); |