20 #include <linux/module.h>
22 #include <linux/slab.h>
23 #include <linux/i2c.h>
28 #include <linux/device.h>
31 #define DRIVER_NAME "tmp102"
33 #define TMP102_TEMP_REG 0x00
34 #define TMP102_CONF_REG 0x01
36 #define TMP102_CONF_SD 0x0100
37 #define TMP102_CONF_TM 0x0200
38 #define TMP102_CONF_POL 0x0400
39 #define TMP102_CONF_F0 0x0800
40 #define TMP102_CONF_F1 0x1000
41 #define TMP102_CONF_R0 0x2000
42 #define TMP102_CONF_R1 0x4000
43 #define TMP102_CONF_OS 0x8000
44 #define TMP102_CONF_EM 0x0010
45 #define TMP102_CONF_AL 0x0020
46 #define TMP102_CONF_CR0 0x0040
47 #define TMP102_CONF_CR1 0x0080
48 #define TMP102_TLOW_REG 0x02
49 #define TMP102_THIGH_REG 0x03
60 static inline int tmp102_reg_to_mC(
s16 val)
62 return ((val & ~0x01) * 1000) / 128;
66 static inline u16 tmp102_mC_to_reg(
int val)
68 return (val * 128) / 1000;
71 static const u8 tmp102_reg[] = {
85 int status = i2c_smbus_read_word_swapped(client,
88 tmp102->
temp[
i] = tmp102_reg_to_mC(status);
101 struct tmp102 *tmp102 = tmp102_update_device(
to_i2c_client(dev));
108 const char *buf,
size_t count)
112 struct tmp102 *tmp102 = i2c_get_clientdata(client);
116 if (kstrtol(buf, 10, &val) < 0)
118 val = SENSORS_LIMIT(val, -256000, 255000);
122 status = i2c_smbus_write_word_swapped(client, tmp102_reg[sda->
index],
123 tmp102_mC_to_reg(val));
125 return status ? :
count;
136 static struct attribute *tmp102_attributes[] = {
137 &sensor_dev_attr_temp1_input.dev_attr.attr,
138 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
139 &sensor_dev_attr_temp1_max.dev_attr.attr,
144 .attrs = tmp102_attributes,
147 #define TMP102_CONFIG (TMP102_CONF_TM | TMP102_CONF_EM | TMP102_CONF_CR1)
148 #define TMP102_CONFIG_RD_ONLY (TMP102_CONF_R0 | TMP102_CONF_R1 | TMP102_CONF_AL)
153 struct tmp102 *tmp102;
156 if (!i2c_check_functionality(client->
adapter,
158 dev_err(&client->
dev,
"adapter doesn't support SMBus word "
167 i2c_set_clientdata(client, tmp102);
171 dev_err(&client->
dev,
"error reading config register\n");
178 dev_err(&client->
dev,
"error writing config register\n");
179 goto fail_restore_config;
183 dev_err(&client->
dev,
"error reading config register\n");
184 goto fail_restore_config;
188 dev_err(&client->
dev,
"config settings did not stick\n");
190 goto fail_restore_config;
197 dev_dbg(&client->
dev,
"could not create sysfs files\n");
198 goto fail_restore_config;
202 dev_dbg(&client->
dev,
"unable to register hwmon device\n");
204 goto fail_remove_sysfs;
221 struct tmp102 *tmp102 = i2c_get_clientdata(client);
240 static int tmp102_suspend(
struct device *dev)
253 static int tmp102_resume(
struct device *dev)
266 static const struct dev_pm_ops tmp102_dev_pm_ops = {
268 .resume = tmp102_resume,
271 #define TMP102_DEV_PM_OPS (&tmp102_dev_pm_ops)
273 #define TMP102_DEV_PM_OPS NULL
285 .probe = tmp102_probe,
287 .id_table = tmp102_id,