Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 1 | /* tmp401.c |
| 2 | * |
| 3 | * Copyright (C) 2007,2008 Hans de Goede <hdegoede@redhat.com> |
Andre Prendel | fce0758 | 2009-06-15 18:39:47 +0200 | [diff] [blame] | 4 | * Preliminary tmp411 support by: |
| 5 | * Gabriel Konat, Sander Leget, Wouter Willems |
| 6 | * Copyright (C) 2009 Andre Prendel <andre.prendel@gmx.de> |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 21 | */ |
| 22 | |
| 23 | /* |
| 24 | * Driver for the Texas Instruments TMP401 SMBUS temperature sensor IC. |
| 25 | * |
| 26 | * Note this IC is in some aspect similar to the LM90, but it has quite a |
| 27 | * few differences too, for example the local temp has a higher resolution |
| 28 | * and thus has 16 bits registers for its value and limit instead of 8 bits. |
| 29 | */ |
| 30 | |
| 31 | #include <linux/module.h> |
| 32 | #include <linux/init.h> |
Guenter Roeck | 947e927 | 2013-03-27 08:48:03 -0700 | [diff] [blame] | 33 | #include <linux/bitops.h> |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 34 | #include <linux/slab.h> |
| 35 | #include <linux/jiffies.h> |
| 36 | #include <linux/i2c.h> |
| 37 | #include <linux/hwmon.h> |
| 38 | #include <linux/hwmon-sysfs.h> |
| 39 | #include <linux/err.h> |
| 40 | #include <linux/mutex.h> |
| 41 | #include <linux/sysfs.h> |
| 42 | |
| 43 | /* Addresses to scan */ |
Guenter Roeck | a1fac92 | 2013-03-15 12:55:08 -0700 | [diff] [blame] | 44 | static const unsigned short normal_i2c[] = { 0x4c, 0x4d, 0x4e, I2C_CLIENT_END }; |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 45 | |
Guenter Roeck | a1fac92 | 2013-03-15 12:55:08 -0700 | [diff] [blame] | 46 | enum chips { tmp401, tmp411, tmp431 }; |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 47 | |
| 48 | /* |
| 49 | * The TMP401 registers, note some registers have different addresses for |
| 50 | * reading and writing |
| 51 | */ |
| 52 | #define TMP401_STATUS 0x02 |
| 53 | #define TMP401_CONFIG_READ 0x03 |
| 54 | #define TMP401_CONFIG_WRITE 0x09 |
| 55 | #define TMP401_CONVERSION_RATE_READ 0x04 |
| 56 | #define TMP401_CONVERSION_RATE_WRITE 0x0A |
| 57 | #define TMP401_TEMP_CRIT_HYST 0x21 |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 58 | #define TMP401_MANUFACTURER_ID_REG 0xFE |
| 59 | #define TMP401_DEVICE_ID_REG 0xFF |
| 60 | |
Guenter Roeck | 14f2a66 | 2013-03-27 21:23:10 -0700 | [diff] [blame] | 61 | static const u8 TMP401_TEMP_MSB_READ[6][2] = { |
| 62 | { 0x00, 0x01 }, /* temp */ |
| 63 | { 0x06, 0x08 }, /* low limit */ |
| 64 | { 0x05, 0x07 }, /* high limit */ |
| 65 | { 0x20, 0x19 }, /* therm (crit) limit */ |
| 66 | { 0x30, 0x34 }, /* lowest */ |
| 67 | { 0x32, 0x36 }, /* highest */ |
| 68 | }; |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 69 | |
Guenter Roeck | 14f2a66 | 2013-03-27 21:23:10 -0700 | [diff] [blame] | 70 | static const u8 TMP401_TEMP_MSB_WRITE[6][2] = { |
| 71 | { 0, 0 }, /* temp (unused) */ |
| 72 | { 0x0C, 0x0E }, /* low limit */ |
| 73 | { 0x0B, 0x0D }, /* high limit */ |
| 74 | { 0x20, 0x19 }, /* therm (crit) limit */ |
| 75 | { 0x30, 0x34 }, /* lowest */ |
| 76 | { 0x32, 0x36 }, /* highest */ |
| 77 | }; |
| 78 | |
| 79 | static const u8 TMP401_TEMP_LSB[6][2] = { |
| 80 | { 0x15, 0x10 }, /* temp */ |
| 81 | { 0x17, 0x14 }, /* low limit */ |
| 82 | { 0x16, 0x13 }, /* high limit */ |
| 83 | { 0, 0 }, /* therm (crit) limit (unused) */ |
| 84 | { 0x31, 0x35 }, /* lowest */ |
| 85 | { 0x33, 0x37 }, /* highest */ |
| 86 | }; |
Andre Prendel | fce0758 | 2009-06-15 18:39:47 +0200 | [diff] [blame] | 87 | |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 88 | /* Flags */ |
Guenter Roeck | 947e927 | 2013-03-27 08:48:03 -0700 | [diff] [blame] | 89 | #define TMP401_CONFIG_RANGE BIT(2) |
| 90 | #define TMP401_CONFIG_SHUTDOWN BIT(6) |
| 91 | #define TMP401_STATUS_LOCAL_CRIT BIT(0) |
| 92 | #define TMP401_STATUS_REMOTE_CRIT BIT(1) |
| 93 | #define TMP401_STATUS_REMOTE_OPEN BIT(2) |
| 94 | #define TMP401_STATUS_REMOTE_LOW BIT(3) |
| 95 | #define TMP401_STATUS_REMOTE_HIGH BIT(4) |
| 96 | #define TMP401_STATUS_LOCAL_LOW BIT(5) |
| 97 | #define TMP401_STATUS_LOCAL_HIGH BIT(6) |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 98 | |
| 99 | /* Manufacturer / Device ID's */ |
| 100 | #define TMP401_MANUFACTURER_ID 0x55 |
| 101 | #define TMP401_DEVICE_ID 0x11 |
Guenter Roeck | 4ce5b1f | 2013-03-29 17:56:07 -0700 | [diff] [blame] | 102 | #define TMP411A_DEVICE_ID 0x12 |
| 103 | #define TMP411B_DEVICE_ID 0x13 |
| 104 | #define TMP411C_DEVICE_ID 0x10 |
Guenter Roeck | a1fac92 | 2013-03-15 12:55:08 -0700 | [diff] [blame] | 105 | #define TMP431_DEVICE_ID 0x31 |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 106 | |
| 107 | /* |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 108 | * Driver data (common to all clients) |
| 109 | */ |
| 110 | |
| 111 | static const struct i2c_device_id tmp401_id[] = { |
| 112 | { "tmp401", tmp401 }, |
Andre Prendel | fce0758 | 2009-06-15 18:39:47 +0200 | [diff] [blame] | 113 | { "tmp411", tmp411 }, |
Guenter Roeck | a1fac92 | 2013-03-15 12:55:08 -0700 | [diff] [blame] | 114 | { "tmp431", tmp431 }, |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 115 | { } |
| 116 | }; |
| 117 | MODULE_DEVICE_TABLE(i2c, tmp401_id); |
| 118 | |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 119 | /* |
| 120 | * Client data (each client gets its own) |
| 121 | */ |
| 122 | |
| 123 | struct tmp401_data { |
| 124 | struct device *hwmon_dev; |
| 125 | struct mutex update_lock; |
| 126 | char valid; /* zero until following fields are valid */ |
| 127 | unsigned long last_updated; /* in jiffies */ |
Jean Delvare | dc71afe | 2010-03-05 22:17:26 +0100 | [diff] [blame] | 128 | enum chips kind; |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 129 | |
Guenter Roeck | 0846e30 | 2013-03-28 02:03:10 -0700 | [diff] [blame^] | 130 | unsigned int update_interval; /* in milliseconds */ |
| 131 | |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 132 | /* register values */ |
| 133 | u8 status; |
| 134 | u8 config; |
Guenter Roeck | 14f2a66 | 2013-03-27 21:23:10 -0700 | [diff] [blame] | 135 | u16 temp[6][2]; |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 136 | u8 temp_crit_hyst; |
| 137 | }; |
| 138 | |
| 139 | /* |
| 140 | * Sysfs attr show / store functions |
| 141 | */ |
| 142 | |
| 143 | static int tmp401_register_to_temp(u16 reg, u8 config) |
| 144 | { |
| 145 | int temp = reg; |
| 146 | |
| 147 | if (config & TMP401_CONFIG_RANGE) |
| 148 | temp -= 64 * 256; |
| 149 | |
Guenter Roeck | 14f2a66 | 2013-03-27 21:23:10 -0700 | [diff] [blame] | 150 | return DIV_ROUND_CLOSEST(temp * 125, 32); |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 151 | } |
| 152 | |
Guenter Roeck | 14f2a66 | 2013-03-27 21:23:10 -0700 | [diff] [blame] | 153 | static u16 tmp401_temp_to_register(long temp, u8 config, int zbits) |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 154 | { |
| 155 | if (config & TMP401_CONFIG_RANGE) { |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 156 | temp = clamp_val(temp, -64000, 191000); |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 157 | temp += 64000; |
| 158 | } else |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 159 | temp = clamp_val(temp, 0, 127000); |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 160 | |
Guenter Roeck | 14f2a66 | 2013-03-27 21:23:10 -0700 | [diff] [blame] | 161 | return DIV_ROUND_CLOSEST(temp * (1 << (8 - zbits)), 1000) << zbits; |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 162 | } |
| 163 | |
Guenter Roeck | 14f2a66 | 2013-03-27 21:23:10 -0700 | [diff] [blame] | 164 | static int tmp401_update_device_reg16(struct i2c_client *client, |
| 165 | struct tmp401_data *data) |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 166 | { |
Guenter Roeck | 14f2a66 | 2013-03-27 21:23:10 -0700 | [diff] [blame] | 167 | int i, j, val; |
| 168 | int num_regs = data->kind == tmp411 ? 6 : 4; |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 169 | |
Guenter Roeck | 14f2a66 | 2013-03-27 21:23:10 -0700 | [diff] [blame] | 170 | for (i = 0; i < 2; i++) { /* local / rem1 */ |
| 171 | for (j = 0; j < num_regs; j++) { /* temp / low / ... */ |
| 172 | /* |
| 173 | * High byte must be read first immediately followed |
| 174 | * by the low byte |
| 175 | */ |
| 176 | val = i2c_smbus_read_byte_data(client, |
| 177 | TMP401_TEMP_MSB_READ[j][i]); |
| 178 | if (val < 0) |
| 179 | return val; |
| 180 | data->temp[j][i] = val << 8; |
| 181 | if (j == 3) /* crit is msb only */ |
| 182 | continue; |
| 183 | val = i2c_smbus_read_byte_data(client, |
| 184 | TMP401_TEMP_LSB[j][i]); |
| 185 | if (val < 0) |
| 186 | return val; |
| 187 | data->temp[j][i] |= val; |
Andre Prendel | ea63c2b | 2010-05-27 19:58:49 +0200 | [diff] [blame] | 188 | } |
| 189 | } |
Guenter Roeck | 14f2a66 | 2013-03-27 21:23:10 -0700 | [diff] [blame] | 190 | return 0; |
Andre Prendel | ea63c2b | 2010-05-27 19:58:49 +0200 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | static struct tmp401_data *tmp401_update_device(struct device *dev) |
| 194 | { |
| 195 | struct i2c_client *client = to_i2c_client(dev); |
| 196 | struct tmp401_data *data = i2c_get_clientdata(client); |
Guenter Roeck | 14f2a66 | 2013-03-27 21:23:10 -0700 | [diff] [blame] | 197 | struct tmp401_data *ret = data; |
| 198 | int val; |
Guenter Roeck | 0846e30 | 2013-03-28 02:03:10 -0700 | [diff] [blame^] | 199 | unsigned long next_update; |
Andre Prendel | ea63c2b | 2010-05-27 19:58:49 +0200 | [diff] [blame] | 200 | |
| 201 | mutex_lock(&data->update_lock); |
| 202 | |
Guenter Roeck | 0846e30 | 2013-03-28 02:03:10 -0700 | [diff] [blame^] | 203 | next_update = data->last_updated + |
| 204 | msecs_to_jiffies(data->update_interval) + 1; |
| 205 | if (time_after(jiffies, next_update) || !data->valid) { |
Guenter Roeck | 14f2a66 | 2013-03-27 21:23:10 -0700 | [diff] [blame] | 206 | val = i2c_smbus_read_byte_data(client, TMP401_STATUS); |
| 207 | if (val < 0) { |
| 208 | ret = ERR_PTR(val); |
| 209 | goto abort; |
| 210 | } |
| 211 | data->status = val; |
| 212 | val = i2c_smbus_read_byte_data(client, TMP401_CONFIG_READ); |
| 213 | if (val < 0) { |
| 214 | ret = ERR_PTR(val); |
| 215 | goto abort; |
| 216 | } |
| 217 | data->config = val; |
| 218 | val = tmp401_update_device_reg16(client, data); |
| 219 | if (val < 0) { |
| 220 | ret = ERR_PTR(val); |
| 221 | goto abort; |
| 222 | } |
| 223 | val = i2c_smbus_read_byte_data(client, TMP401_TEMP_CRIT_HYST); |
| 224 | if (val < 0) { |
| 225 | ret = ERR_PTR(val); |
| 226 | goto abort; |
| 227 | } |
| 228 | data->temp_crit_hyst = val; |
Andre Prendel | ea63c2b | 2010-05-27 19:58:49 +0200 | [diff] [blame] | 229 | |
| 230 | data->last_updated = jiffies; |
| 231 | data->valid = 1; |
| 232 | } |
| 233 | |
Guenter Roeck | 14f2a66 | 2013-03-27 21:23:10 -0700 | [diff] [blame] | 234 | abort: |
Andre Prendel | ea63c2b | 2010-05-27 19:58:49 +0200 | [diff] [blame] | 235 | mutex_unlock(&data->update_lock); |
Guenter Roeck | 14f2a66 | 2013-03-27 21:23:10 -0700 | [diff] [blame] | 236 | return ret; |
Andre Prendel | ea63c2b | 2010-05-27 19:58:49 +0200 | [diff] [blame] | 237 | } |
| 238 | |
Guenter Roeck | 14f2a66 | 2013-03-27 21:23:10 -0700 | [diff] [blame] | 239 | static ssize_t show_temp(struct device *dev, |
| 240 | struct device_attribute *devattr, char *buf) |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 241 | { |
Guenter Roeck | 14f2a66 | 2013-03-27 21:23:10 -0700 | [diff] [blame] | 242 | int nr = to_sensor_dev_attr_2(devattr)->nr; |
| 243 | int index = to_sensor_dev_attr_2(devattr)->index; |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 244 | struct tmp401_data *data = tmp401_update_device(dev); |
| 245 | |
Guenter Roeck | 14f2a66 | 2013-03-27 21:23:10 -0700 | [diff] [blame] | 246 | if (IS_ERR(data)) |
| 247 | return PTR_ERR(data); |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 248 | |
| 249 | return sprintf(buf, "%d\n", |
Guenter Roeck | 14f2a66 | 2013-03-27 21:23:10 -0700 | [diff] [blame] | 250 | tmp401_register_to_temp(data->temp[nr][index], data->config)); |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | static ssize_t show_temp_crit_hyst(struct device *dev, |
| 254 | struct device_attribute *devattr, char *buf) |
| 255 | { |
| 256 | int temp, index = to_sensor_dev_attr(devattr)->index; |
| 257 | struct tmp401_data *data = tmp401_update_device(dev); |
| 258 | |
Guenter Roeck | 14f2a66 | 2013-03-27 21:23:10 -0700 | [diff] [blame] | 259 | if (IS_ERR(data)) |
| 260 | return PTR_ERR(data); |
| 261 | |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 262 | mutex_lock(&data->update_lock); |
Guenter Roeck | 14f2a66 | 2013-03-27 21:23:10 -0700 | [diff] [blame] | 263 | temp = tmp401_register_to_temp(data->temp[3][index], data->config); |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 264 | temp -= data->temp_crit_hyst * 1000; |
| 265 | mutex_unlock(&data->update_lock); |
| 266 | |
| 267 | return sprintf(buf, "%d\n", temp); |
| 268 | } |
| 269 | |
| 270 | static ssize_t show_status(struct device *dev, |
| 271 | struct device_attribute *devattr, char *buf) |
| 272 | { |
| 273 | int mask = to_sensor_dev_attr(devattr)->index; |
| 274 | struct tmp401_data *data = tmp401_update_device(dev); |
| 275 | |
Guenter Roeck | 14f2a66 | 2013-03-27 21:23:10 -0700 | [diff] [blame] | 276 | if (IS_ERR(data)) |
| 277 | return PTR_ERR(data); |
| 278 | |
| 279 | return sprintf(buf, "%d\n", !!(data->status & mask)); |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 280 | } |
| 281 | |
Guenter Roeck | 14f2a66 | 2013-03-27 21:23:10 -0700 | [diff] [blame] | 282 | static ssize_t store_temp(struct device *dev, struct device_attribute *devattr, |
| 283 | const char *buf, size_t count) |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 284 | { |
Guenter Roeck | 14f2a66 | 2013-03-27 21:23:10 -0700 | [diff] [blame] | 285 | int nr = to_sensor_dev_attr_2(devattr)->nr; |
| 286 | int index = to_sensor_dev_attr_2(devattr)->index; |
| 287 | struct i2c_client *client = to_i2c_client(dev); |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 288 | struct tmp401_data *data = tmp401_update_device(dev); |
| 289 | long val; |
| 290 | u16 reg; |
| 291 | |
Guenter Roeck | 14f2a66 | 2013-03-27 21:23:10 -0700 | [diff] [blame] | 292 | if (IS_ERR(data)) |
| 293 | return PTR_ERR(data); |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 294 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 295 | if (kstrtol(buf, 10, &val)) |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 296 | return -EINVAL; |
| 297 | |
Guenter Roeck | 14f2a66 | 2013-03-27 21:23:10 -0700 | [diff] [blame] | 298 | reg = tmp401_temp_to_register(val, data->config, nr == 3 ? 8 : 4); |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 299 | |
| 300 | mutex_lock(&data->update_lock); |
| 301 | |
Guenter Roeck | 14f2a66 | 2013-03-27 21:23:10 -0700 | [diff] [blame] | 302 | i2c_smbus_write_byte_data(client, |
| 303 | TMP401_TEMP_MSB_WRITE[nr][index], |
| 304 | reg >> 8); |
| 305 | if (nr != 3) { |
| 306 | i2c_smbus_write_byte_data(client, |
| 307 | TMP401_TEMP_LSB[nr][index], |
| 308 | reg & 0xFF); |
| 309 | } |
| 310 | data->temp[nr][index] = reg; |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 311 | |
| 312 | mutex_unlock(&data->update_lock); |
| 313 | |
| 314 | return count; |
| 315 | } |
| 316 | |
| 317 | static ssize_t store_temp_crit_hyst(struct device *dev, struct device_attribute |
| 318 | *devattr, const char *buf, size_t count) |
| 319 | { |
| 320 | int temp, index = to_sensor_dev_attr(devattr)->index; |
| 321 | struct tmp401_data *data = tmp401_update_device(dev); |
| 322 | long val; |
| 323 | u8 reg; |
| 324 | |
Guenter Roeck | 14f2a66 | 2013-03-27 21:23:10 -0700 | [diff] [blame] | 325 | if (IS_ERR(data)) |
| 326 | return PTR_ERR(data); |
| 327 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 328 | if (kstrtol(buf, 10, &val)) |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 329 | return -EINVAL; |
| 330 | |
| 331 | if (data->config & TMP401_CONFIG_RANGE) |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 332 | val = clamp_val(val, -64000, 191000); |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 333 | else |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 334 | val = clamp_val(val, 0, 127000); |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 335 | |
| 336 | mutex_lock(&data->update_lock); |
Guenter Roeck | 14f2a66 | 2013-03-27 21:23:10 -0700 | [diff] [blame] | 337 | temp = tmp401_register_to_temp(data->temp[3][index], data->config); |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 338 | val = clamp_val(val, temp - 255000, temp); |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 339 | reg = ((temp - val) + 500) / 1000; |
| 340 | |
Guenter Roeck | 14f2a66 | 2013-03-27 21:23:10 -0700 | [diff] [blame] | 341 | i2c_smbus_write_byte_data(to_i2c_client(dev), TMP401_TEMP_CRIT_HYST, |
| 342 | reg); |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 343 | |
| 344 | data->temp_crit_hyst = reg; |
| 345 | |
| 346 | mutex_unlock(&data->update_lock); |
| 347 | |
| 348 | return count; |
| 349 | } |
| 350 | |
Andre Prendel | fce0758 | 2009-06-15 18:39:47 +0200 | [diff] [blame] | 351 | /* |
| 352 | * Resets the historical measurements of minimum and maximum temperatures. |
| 353 | * This is done by writing any value to any of the minimum/maximum registers |
| 354 | * (0x30-0x37). |
| 355 | */ |
| 356 | static ssize_t reset_temp_history(struct device *dev, |
| 357 | struct device_attribute *devattr, const char *buf, size_t count) |
| 358 | { |
Guenter Roeck | 8eb6d90 | 2013-04-14 04:39:46 -0700 | [diff] [blame] | 359 | struct i2c_client *client = to_i2c_client(dev); |
| 360 | struct tmp401_data *data = i2c_get_clientdata(client); |
Andre Prendel | fce0758 | 2009-06-15 18:39:47 +0200 | [diff] [blame] | 361 | long val; |
| 362 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 363 | if (kstrtol(buf, 10, &val)) |
Andre Prendel | fce0758 | 2009-06-15 18:39:47 +0200 | [diff] [blame] | 364 | return -EINVAL; |
| 365 | |
| 366 | if (val != 1) { |
Guenter Roeck | b55f375 | 2013-01-10 10:01:24 -0800 | [diff] [blame] | 367 | dev_err(dev, |
| 368 | "temp_reset_history value %ld not supported. Use 1 to reset the history!\n", |
| 369 | val); |
Andre Prendel | fce0758 | 2009-06-15 18:39:47 +0200 | [diff] [blame] | 370 | return -EINVAL; |
| 371 | } |
Guenter Roeck | 8eb6d90 | 2013-04-14 04:39:46 -0700 | [diff] [blame] | 372 | mutex_lock(&data->update_lock); |
| 373 | i2c_smbus_write_byte_data(client, TMP401_TEMP_MSB_WRITE[5][0], val); |
| 374 | data->valid = 0; |
| 375 | mutex_unlock(&data->update_lock); |
Andre Prendel | fce0758 | 2009-06-15 18:39:47 +0200 | [diff] [blame] | 376 | |
| 377 | return count; |
| 378 | } |
| 379 | |
Guenter Roeck | 0846e30 | 2013-03-28 02:03:10 -0700 | [diff] [blame^] | 380 | static ssize_t show_update_interval(struct device *dev, |
| 381 | struct device_attribute *attr, char *buf) |
| 382 | { |
| 383 | struct i2c_client *client = to_i2c_client(dev); |
| 384 | struct tmp401_data *data = i2c_get_clientdata(client); |
| 385 | |
| 386 | return sprintf(buf, "%u\n", data->update_interval); |
| 387 | } |
| 388 | |
| 389 | static ssize_t set_update_interval(struct device *dev, |
| 390 | struct device_attribute *attr, |
| 391 | const char *buf, size_t count) |
| 392 | { |
| 393 | struct i2c_client *client = to_i2c_client(dev); |
| 394 | struct tmp401_data *data = i2c_get_clientdata(client); |
| 395 | unsigned long val; |
| 396 | int err, rate; |
| 397 | |
| 398 | err = kstrtoul(buf, 10, &val); |
| 399 | if (err) |
| 400 | return err; |
| 401 | |
| 402 | /* |
| 403 | * For valid rates, interval can be calculated as |
| 404 | * interval = (1 << (7 - rate)) * 125; |
| 405 | * Rounded rate is therefore |
| 406 | * rate = 7 - __fls(interval * 4 / (125 * 3)); |
| 407 | * Use clamp_val() to avoid overflows, and to ensure valid input |
| 408 | * for __fls. |
| 409 | */ |
| 410 | val = clamp_val(val, 125, 16000); |
| 411 | rate = 7 - __fls(val * 4 / (125 * 3)); |
| 412 | mutex_lock(&data->update_lock); |
| 413 | i2c_smbus_write_byte_data(client, TMP401_CONVERSION_RATE_WRITE, rate); |
| 414 | data->update_interval = (1 << (7 - rate)) * 125; |
| 415 | mutex_unlock(&data->update_lock); |
| 416 | |
| 417 | return count; |
| 418 | } |
| 419 | |
Guenter Roeck | 14f2a66 | 2013-03-27 21:23:10 -0700 | [diff] [blame] | 420 | static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0); |
| 421 | static SENSOR_DEVICE_ATTR_2(temp1_min, S_IWUSR | S_IRUGO, show_temp, |
| 422 | store_temp, 1, 0); |
| 423 | static SENSOR_DEVICE_ATTR_2(temp1_max, S_IWUSR | S_IRUGO, show_temp, |
| 424 | store_temp, 2, 0); |
| 425 | static SENSOR_DEVICE_ATTR_2(temp1_crit, S_IWUSR | S_IRUGO, show_temp, |
| 426 | store_temp, 3, 0); |
Guenter Roeck | b4e665c | 2013-03-27 08:58:46 -0700 | [diff] [blame] | 427 | static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, |
| 428 | show_temp_crit_hyst, store_temp_crit_hyst, 0); |
| 429 | static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_status, NULL, |
| 430 | TMP401_STATUS_LOCAL_LOW); |
| 431 | static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_status, NULL, |
| 432 | TMP401_STATUS_LOCAL_HIGH); |
| 433 | static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_status, NULL, |
| 434 | TMP401_STATUS_LOCAL_CRIT); |
Guenter Roeck | 14f2a66 | 2013-03-27 21:23:10 -0700 | [diff] [blame] | 435 | static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 1); |
| 436 | static SENSOR_DEVICE_ATTR_2(temp2_min, S_IWUSR | S_IRUGO, show_temp, |
| 437 | store_temp, 1, 1); |
| 438 | static SENSOR_DEVICE_ATTR_2(temp2_max, S_IWUSR | S_IRUGO, show_temp, |
| 439 | store_temp, 2, 1); |
| 440 | static SENSOR_DEVICE_ATTR_2(temp2_crit, S_IWUSR | S_IRUGO, show_temp, |
| 441 | store_temp, 3, 1); |
Guenter Roeck | b4e665c | 2013-03-27 08:58:46 -0700 | [diff] [blame] | 442 | static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temp_crit_hyst, |
| 443 | NULL, 1); |
| 444 | static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_status, NULL, |
| 445 | TMP401_STATUS_REMOTE_OPEN); |
| 446 | static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_status, NULL, |
| 447 | TMP401_STATUS_REMOTE_LOW); |
| 448 | static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_status, NULL, |
| 449 | TMP401_STATUS_REMOTE_HIGH); |
| 450 | static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_status, NULL, |
| 451 | TMP401_STATUS_REMOTE_CRIT); |
| 452 | |
Guenter Roeck | 0846e30 | 2013-03-28 02:03:10 -0700 | [diff] [blame^] | 453 | static DEVICE_ATTR(update_interval, S_IRUGO | S_IWUSR, show_update_interval, |
| 454 | set_update_interval); |
| 455 | |
Guenter Roeck | b4e665c | 2013-03-27 08:58:46 -0700 | [diff] [blame] | 456 | static struct attribute *tmp401_attributes[] = { |
| 457 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
| 458 | &sensor_dev_attr_temp1_min.dev_attr.attr, |
| 459 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
| 460 | &sensor_dev_attr_temp1_crit.dev_attr.attr, |
| 461 | &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr, |
| 462 | &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, |
| 463 | &sensor_dev_attr_temp1_min_alarm.dev_attr.attr, |
| 464 | &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr, |
| 465 | |
| 466 | &sensor_dev_attr_temp2_input.dev_attr.attr, |
| 467 | &sensor_dev_attr_temp2_min.dev_attr.attr, |
| 468 | &sensor_dev_attr_temp2_max.dev_attr.attr, |
| 469 | &sensor_dev_attr_temp2_crit.dev_attr.attr, |
| 470 | &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr, |
| 471 | &sensor_dev_attr_temp2_fault.dev_attr.attr, |
| 472 | &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, |
| 473 | &sensor_dev_attr_temp2_min_alarm.dev_attr.attr, |
| 474 | &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, |
| 475 | |
Guenter Roeck | 0846e30 | 2013-03-28 02:03:10 -0700 | [diff] [blame^] | 476 | &dev_attr_update_interval.attr, |
| 477 | |
Guenter Roeck | b4e665c | 2013-03-27 08:58:46 -0700 | [diff] [blame] | 478 | NULL |
| 479 | }; |
| 480 | |
| 481 | static const struct attribute_group tmp401_group = { |
| 482 | .attrs = tmp401_attributes, |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 483 | }; |
| 484 | |
| 485 | /* |
Andre Prendel | fce0758 | 2009-06-15 18:39:47 +0200 | [diff] [blame] | 486 | * Additional features of the TMP411 chip. |
| 487 | * The TMP411 stores the minimum and maximum |
| 488 | * temperature measured since power-on, chip-reset, or |
| 489 | * minimum and maximum register reset for both the local |
| 490 | * and remote channels. |
| 491 | */ |
Guenter Roeck | 14f2a66 | 2013-03-27 21:23:10 -0700 | [diff] [blame] | 492 | static SENSOR_DEVICE_ATTR_2(temp1_lowest, S_IRUGO, show_temp, NULL, 4, 0); |
| 493 | static SENSOR_DEVICE_ATTR_2(temp1_highest, S_IRUGO, show_temp, NULL, 5, 0); |
| 494 | static SENSOR_DEVICE_ATTR_2(temp2_lowest, S_IRUGO, show_temp, NULL, 4, 1); |
| 495 | static SENSOR_DEVICE_ATTR_2(temp2_highest, S_IRUGO, show_temp, NULL, 5, 1); |
Guenter Roeck | b4e665c | 2013-03-27 08:58:46 -0700 | [diff] [blame] | 496 | static SENSOR_DEVICE_ATTR(temp_reset_history, S_IWUSR, NULL, reset_temp_history, |
| 497 | 0); |
| 498 | |
| 499 | static struct attribute *tmp411_attributes[] = { |
| 500 | &sensor_dev_attr_temp1_highest.dev_attr.attr, |
| 501 | &sensor_dev_attr_temp1_lowest.dev_attr.attr, |
| 502 | &sensor_dev_attr_temp2_highest.dev_attr.attr, |
| 503 | &sensor_dev_attr_temp2_lowest.dev_attr.attr, |
| 504 | &sensor_dev_attr_temp_reset_history.dev_attr.attr, |
| 505 | NULL |
| 506 | }; |
| 507 | |
| 508 | static const struct attribute_group tmp411_group = { |
| 509 | .attrs = tmp411_attributes, |
Andre Prendel | fce0758 | 2009-06-15 18:39:47 +0200 | [diff] [blame] | 510 | }; |
| 511 | |
| 512 | /* |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 513 | * Begin non sysfs callback code (aka Real code) |
| 514 | */ |
| 515 | |
| 516 | static void tmp401_init_client(struct i2c_client *client) |
| 517 | { |
| 518 | int config, config_orig; |
Guenter Roeck | 0846e30 | 2013-03-28 02:03:10 -0700 | [diff] [blame^] | 519 | struct tmp401_data *data = i2c_get_clientdata(client); |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 520 | |
| 521 | /* Set the conversion rate to 2 Hz */ |
| 522 | i2c_smbus_write_byte_data(client, TMP401_CONVERSION_RATE_WRITE, 5); |
Guenter Roeck | 0846e30 | 2013-03-28 02:03:10 -0700 | [diff] [blame^] | 523 | data->update_interval = 500; |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 524 | |
| 525 | /* Start conversions (disable shutdown if necessary) */ |
| 526 | config = i2c_smbus_read_byte_data(client, TMP401_CONFIG_READ); |
| 527 | if (config < 0) { |
| 528 | dev_warn(&client->dev, "Initialization failed!\n"); |
| 529 | return; |
| 530 | } |
| 531 | |
| 532 | config_orig = config; |
| 533 | config &= ~TMP401_CONFIG_SHUTDOWN; |
| 534 | |
| 535 | if (config != config_orig) |
| 536 | i2c_smbus_write_byte_data(client, TMP401_CONFIG_WRITE, config); |
| 537 | } |
| 538 | |
Jean Delvare | 310ec79 | 2009-12-14 21:17:23 +0100 | [diff] [blame] | 539 | static int tmp401_detect(struct i2c_client *client, |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 540 | struct i2c_board_info *info) |
| 541 | { |
Jean Delvare | dbe73c8 | 2009-12-09 20:35:54 +0100 | [diff] [blame] | 542 | enum chips kind; |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 543 | struct i2c_adapter *adapter = client->adapter; |
Jean Delvare | dbe73c8 | 2009-12-09 20:35:54 +0100 | [diff] [blame] | 544 | u8 reg; |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 545 | |
| 546 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
| 547 | return -ENODEV; |
| 548 | |
| 549 | /* Detect and identify the chip */ |
Jean Delvare | dbe73c8 | 2009-12-09 20:35:54 +0100 | [diff] [blame] | 550 | reg = i2c_smbus_read_byte_data(client, TMP401_MANUFACTURER_ID_REG); |
| 551 | if (reg != TMP401_MANUFACTURER_ID) |
| 552 | return -ENODEV; |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 553 | |
Jean Delvare | dbe73c8 | 2009-12-09 20:35:54 +0100 | [diff] [blame] | 554 | reg = i2c_smbus_read_byte_data(client, TMP401_DEVICE_ID_REG); |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 555 | |
Jean Delvare | dbe73c8 | 2009-12-09 20:35:54 +0100 | [diff] [blame] | 556 | switch (reg) { |
| 557 | case TMP401_DEVICE_ID: |
Guenter Roeck | a1fac92 | 2013-03-15 12:55:08 -0700 | [diff] [blame] | 558 | if (client->addr != 0x4c) |
| 559 | return -ENODEV; |
Jean Delvare | dbe73c8 | 2009-12-09 20:35:54 +0100 | [diff] [blame] | 560 | kind = tmp401; |
| 561 | break; |
Guenter Roeck | 4ce5b1f | 2013-03-29 17:56:07 -0700 | [diff] [blame] | 562 | case TMP411A_DEVICE_ID: |
| 563 | if (client->addr != 0x4c) |
| 564 | return -ENODEV; |
| 565 | kind = tmp411; |
| 566 | break; |
| 567 | case TMP411B_DEVICE_ID: |
| 568 | if (client->addr != 0x4d) |
| 569 | return -ENODEV; |
| 570 | kind = tmp411; |
| 571 | break; |
| 572 | case TMP411C_DEVICE_ID: |
| 573 | if (client->addr != 0x4e) |
| 574 | return -ENODEV; |
Jean Delvare | dbe73c8 | 2009-12-09 20:35:54 +0100 | [diff] [blame] | 575 | kind = tmp411; |
| 576 | break; |
Guenter Roeck | a1fac92 | 2013-03-15 12:55:08 -0700 | [diff] [blame] | 577 | case TMP431_DEVICE_ID: |
| 578 | if (client->addr == 0x4e) |
| 579 | return -ENODEV; |
| 580 | kind = tmp431; |
| 581 | break; |
Jean Delvare | dbe73c8 | 2009-12-09 20:35:54 +0100 | [diff] [blame] | 582 | default: |
| 583 | return -ENODEV; |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 584 | } |
Jean Delvare | dbe73c8 | 2009-12-09 20:35:54 +0100 | [diff] [blame] | 585 | |
| 586 | reg = i2c_smbus_read_byte_data(client, TMP401_CONFIG_READ); |
| 587 | if (reg & 0x1b) |
| 588 | return -ENODEV; |
| 589 | |
| 590 | reg = i2c_smbus_read_byte_data(client, TMP401_CONVERSION_RATE_READ); |
| 591 | /* Datasheet says: 0x1-0x6 */ |
| 592 | if (reg > 15) |
| 593 | return -ENODEV; |
| 594 | |
Jean Delvare | dc71afe | 2010-03-05 22:17:26 +0100 | [diff] [blame] | 595 | strlcpy(info->type, tmp401_id[kind].name, I2C_NAME_SIZE); |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 596 | |
| 597 | return 0; |
| 598 | } |
| 599 | |
Andre Prendel | ea63c2b | 2010-05-27 19:58:49 +0200 | [diff] [blame] | 600 | static int tmp401_remove(struct i2c_client *client) |
| 601 | { |
Guenter Roeck | b4e665c | 2013-03-27 08:58:46 -0700 | [diff] [blame] | 602 | struct device *dev = &client->dev; |
Andre Prendel | ea63c2b | 2010-05-27 19:58:49 +0200 | [diff] [blame] | 603 | struct tmp401_data *data = i2c_get_clientdata(client); |
Andre Prendel | ea63c2b | 2010-05-27 19:58:49 +0200 | [diff] [blame] | 604 | |
| 605 | if (data->hwmon_dev) |
| 606 | hwmon_device_unregister(data->hwmon_dev); |
| 607 | |
Guenter Roeck | b4e665c | 2013-03-27 08:58:46 -0700 | [diff] [blame] | 608 | sysfs_remove_group(&dev->kobj, &tmp401_group); |
Andre Prendel | ea63c2b | 2010-05-27 19:58:49 +0200 | [diff] [blame] | 609 | |
Guenter Roeck | b4e665c | 2013-03-27 08:58:46 -0700 | [diff] [blame] | 610 | if (data->kind == tmp411) |
| 611 | sysfs_remove_group(&dev->kobj, &tmp411_group); |
Andre Prendel | ea63c2b | 2010-05-27 19:58:49 +0200 | [diff] [blame] | 612 | |
Andre Prendel | ea63c2b | 2010-05-27 19:58:49 +0200 | [diff] [blame] | 613 | return 0; |
| 614 | } |
| 615 | |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 616 | static int tmp401_probe(struct i2c_client *client, |
| 617 | const struct i2c_device_id *id) |
| 618 | { |
Guenter Roeck | b4e665c | 2013-03-27 08:58:46 -0700 | [diff] [blame] | 619 | struct device *dev = &client->dev; |
| 620 | int err; |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 621 | struct tmp401_data *data; |
Guenter Roeck | a1fac92 | 2013-03-15 12:55:08 -0700 | [diff] [blame] | 622 | const char *names[] = { "TMP401", "TMP411", "TMP431" }; |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 623 | |
Guenter Roeck | b4e665c | 2013-03-27 08:58:46 -0700 | [diff] [blame] | 624 | data = devm_kzalloc(dev, sizeof(struct tmp401_data), GFP_KERNEL); |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 625 | if (!data) |
| 626 | return -ENOMEM; |
| 627 | |
| 628 | i2c_set_clientdata(client, data); |
| 629 | mutex_init(&data->update_lock); |
Andre Prendel | fce0758 | 2009-06-15 18:39:47 +0200 | [diff] [blame] | 630 | data->kind = id->driver_data; |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 631 | |
| 632 | /* Initialize the TMP401 chip */ |
| 633 | tmp401_init_client(client); |
| 634 | |
| 635 | /* Register sysfs hooks */ |
Guenter Roeck | b4e665c | 2013-03-27 08:58:46 -0700 | [diff] [blame] | 636 | err = sysfs_create_group(&dev->kobj, &tmp401_group); |
| 637 | if (err) |
| 638 | return err; |
| 639 | |
| 640 | /* Register additional tmp411 sysfs hooks */ |
| 641 | if (data->kind == tmp411) { |
| 642 | err = sysfs_create_group(&dev->kobj, &tmp411_group); |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 643 | if (err) |
| 644 | goto exit_remove; |
| 645 | } |
| 646 | |
Guenter Roeck | b4e665c | 2013-03-27 08:58:46 -0700 | [diff] [blame] | 647 | data->hwmon_dev = hwmon_device_register(dev); |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 648 | if (IS_ERR(data->hwmon_dev)) { |
| 649 | err = PTR_ERR(data->hwmon_dev); |
| 650 | data->hwmon_dev = NULL; |
| 651 | goto exit_remove; |
| 652 | } |
| 653 | |
Guenter Roeck | b4e665c | 2013-03-27 08:58:46 -0700 | [diff] [blame] | 654 | dev_info(dev, "Detected TI %s chip\n", names[data->kind]); |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 655 | |
| 656 | return 0; |
| 657 | |
| 658 | exit_remove: |
Guenter Roeck | 0df9fc7 | 2012-06-02 11:35:53 -0700 | [diff] [blame] | 659 | tmp401_remove(client); |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 660 | return err; |
| 661 | } |
| 662 | |
Andre Prendel | ea63c2b | 2010-05-27 19:58:49 +0200 | [diff] [blame] | 663 | static struct i2c_driver tmp401_driver = { |
| 664 | .class = I2C_CLASS_HWMON, |
| 665 | .driver = { |
| 666 | .name = "tmp401", |
| 667 | }, |
| 668 | .probe = tmp401_probe, |
| 669 | .remove = tmp401_remove, |
| 670 | .id_table = tmp401_id, |
| 671 | .detect = tmp401_detect, |
| 672 | .address_list = normal_i2c, |
| 673 | }; |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 674 | |
Axel Lin | f0967ee | 2012-01-20 15:38:18 +0800 | [diff] [blame] | 675 | module_i2c_driver(tmp401_driver); |
Hans de Goede | ab2b79d | 2009-06-15 18:39:46 +0200 | [diff] [blame] | 676 | |
| 677 | MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>"); |
| 678 | MODULE_DESCRIPTION("Texas Instruments TMP401 temperature sensor driver"); |
| 679 | MODULE_LICENSE("GPL"); |