Commit e5840c78f3c9e3d950363e4305b65183f2998a73
Committed by
Guenter Roeck
1 parent
31ab1ad70b
Exists in
smarc-imx_3.14.28_1.0.0_ga
and in
1 other branch
hwmon: (max6642 fix coccinelle warnings
drivers/hwmon/max6642.c:299:1-3: WARNING: PTR_RET can be used Use PTR_ERR_OR_ZERO rather than if(IS_ERR(...)) + PTR_ERR Generated by: coccinelle/api/ptr_ret.cocci CC: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Fengguang Wu <fengguang.wu@intel.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Showing 1 changed file with 1 additions and 4 deletions Inline Diff
drivers/hwmon/max6642.c
1 | /* | 1 | /* |
2 | * Driver for +/-1 degree C, SMBus-Compatible Remote/Local Temperature Sensor | 2 | * Driver for +/-1 degree C, SMBus-Compatible Remote/Local Temperature Sensor |
3 | * with Overtemperature Alarm | 3 | * with Overtemperature Alarm |
4 | * | 4 | * |
5 | * Copyright (C) 2011 AppearTV AS | 5 | * Copyright (C) 2011 AppearTV AS |
6 | * | 6 | * |
7 | * Derived from: | 7 | * Derived from: |
8 | * | 8 | * |
9 | * Based on the max1619 driver. | 9 | * Based on the max1619 driver. |
10 | * Copyright (C) 2003-2004 Oleksij Rempel <bug-track@fisher-privat.net> | 10 | * Copyright (C) 2003-2004 Oleksij Rempel <bug-track@fisher-privat.net> |
11 | * Jean Delvare <khali@linux-fr.org> | 11 | * Jean Delvare <khali@linux-fr.org> |
12 | * | 12 | * |
13 | * The MAX6642 is a sensor chip made by Maxim. | 13 | * The MAX6642 is a sensor chip made by Maxim. |
14 | * It reports up to two temperatures (its own plus up to | 14 | * It reports up to two temperatures (its own plus up to |
15 | * one external one). Complete datasheet can be | 15 | * one external one). Complete datasheet can be |
16 | * obtained from Maxim's website at: | 16 | * obtained from Maxim's website at: |
17 | * http://datasheets.maxim-ic.com/en/ds/MAX6642.pdf | 17 | * http://datasheets.maxim-ic.com/en/ds/MAX6642.pdf |
18 | * | 18 | * |
19 | * This program is free software; you can redistribute it and/or modify | 19 | * This program is free software; you can redistribute it and/or modify |
20 | * it under the terms of the GNU General Public License as published by | 20 | * it under the terms of the GNU General Public License as published by |
21 | * the Free Software Foundation; either version 2 of the License, or | 21 | * the Free Software Foundation; either version 2 of the License, or |
22 | * (at your option) any later version. | 22 | * (at your option) any later version. |
23 | * | 23 | * |
24 | * This program is distributed in the hope that it will be useful, | 24 | * This program is distributed in the hope that it will be useful, |
25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
27 | * GNU General Public License for more details. | 27 | * GNU General Public License for more details. |
28 | * | 28 | * |
29 | * You should have received a copy of the GNU General Public License | 29 | * You should have received a copy of the GNU General Public License |
30 | * along with this program; if not, write to the Free Software | 30 | * along with this program; if not, write to the Free Software |
31 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 31 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
32 | */ | 32 | */ |
33 | 33 | ||
34 | 34 | ||
35 | #include <linux/module.h> | 35 | #include <linux/module.h> |
36 | #include <linux/init.h> | 36 | #include <linux/init.h> |
37 | #include <linux/slab.h> | 37 | #include <linux/slab.h> |
38 | #include <linux/jiffies.h> | 38 | #include <linux/jiffies.h> |
39 | #include <linux/i2c.h> | 39 | #include <linux/i2c.h> |
40 | #include <linux/hwmon.h> | 40 | #include <linux/hwmon.h> |
41 | #include <linux/hwmon-sysfs.h> | 41 | #include <linux/hwmon-sysfs.h> |
42 | #include <linux/err.h> | 42 | #include <linux/err.h> |
43 | #include <linux/mutex.h> | 43 | #include <linux/mutex.h> |
44 | #include <linux/sysfs.h> | 44 | #include <linux/sysfs.h> |
45 | 45 | ||
46 | static const unsigned short normal_i2c[] = { | 46 | static const unsigned short normal_i2c[] = { |
47 | 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, I2C_CLIENT_END }; | 47 | 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, I2C_CLIENT_END }; |
48 | 48 | ||
49 | /* | 49 | /* |
50 | * The MAX6642 registers | 50 | * The MAX6642 registers |
51 | */ | 51 | */ |
52 | 52 | ||
53 | #define MAX6642_REG_R_MAN_ID 0xFE | 53 | #define MAX6642_REG_R_MAN_ID 0xFE |
54 | #define MAX6642_REG_R_CONFIG 0x03 | 54 | #define MAX6642_REG_R_CONFIG 0x03 |
55 | #define MAX6642_REG_W_CONFIG 0x09 | 55 | #define MAX6642_REG_W_CONFIG 0x09 |
56 | #define MAX6642_REG_R_STATUS 0x02 | 56 | #define MAX6642_REG_R_STATUS 0x02 |
57 | #define MAX6642_REG_R_LOCAL_TEMP 0x00 | 57 | #define MAX6642_REG_R_LOCAL_TEMP 0x00 |
58 | #define MAX6642_REG_R_LOCAL_TEMPL 0x11 | 58 | #define MAX6642_REG_R_LOCAL_TEMPL 0x11 |
59 | #define MAX6642_REG_R_LOCAL_HIGH 0x05 | 59 | #define MAX6642_REG_R_LOCAL_HIGH 0x05 |
60 | #define MAX6642_REG_W_LOCAL_HIGH 0x0B | 60 | #define MAX6642_REG_W_LOCAL_HIGH 0x0B |
61 | #define MAX6642_REG_R_REMOTE_TEMP 0x01 | 61 | #define MAX6642_REG_R_REMOTE_TEMP 0x01 |
62 | #define MAX6642_REG_R_REMOTE_TEMPL 0x10 | 62 | #define MAX6642_REG_R_REMOTE_TEMPL 0x10 |
63 | #define MAX6642_REG_R_REMOTE_HIGH 0x07 | 63 | #define MAX6642_REG_R_REMOTE_HIGH 0x07 |
64 | #define MAX6642_REG_W_REMOTE_HIGH 0x0D | 64 | #define MAX6642_REG_W_REMOTE_HIGH 0x0D |
65 | 65 | ||
66 | /* | 66 | /* |
67 | * Conversions | 67 | * Conversions |
68 | */ | 68 | */ |
69 | 69 | ||
70 | static int temp_from_reg10(int val) | 70 | static int temp_from_reg10(int val) |
71 | { | 71 | { |
72 | return val * 250; | 72 | return val * 250; |
73 | } | 73 | } |
74 | 74 | ||
75 | static int temp_from_reg(int val) | 75 | static int temp_from_reg(int val) |
76 | { | 76 | { |
77 | return val * 1000; | 77 | return val * 1000; |
78 | } | 78 | } |
79 | 79 | ||
80 | static int temp_to_reg(int val) | 80 | static int temp_to_reg(int val) |
81 | { | 81 | { |
82 | return val / 1000; | 82 | return val / 1000; |
83 | } | 83 | } |
84 | 84 | ||
85 | /* | 85 | /* |
86 | * Client data (each client gets its own) | 86 | * Client data (each client gets its own) |
87 | */ | 87 | */ |
88 | 88 | ||
89 | struct max6642_data { | 89 | struct max6642_data { |
90 | struct i2c_client *client; | 90 | struct i2c_client *client; |
91 | struct mutex update_lock; | 91 | struct mutex update_lock; |
92 | bool valid; /* zero until following fields are valid */ | 92 | bool valid; /* zero until following fields are valid */ |
93 | unsigned long last_updated; /* in jiffies */ | 93 | unsigned long last_updated; /* in jiffies */ |
94 | 94 | ||
95 | /* registers values */ | 95 | /* registers values */ |
96 | u16 temp_input[2]; /* local/remote */ | 96 | u16 temp_input[2]; /* local/remote */ |
97 | u16 temp_high[2]; /* local/remote */ | 97 | u16 temp_high[2]; /* local/remote */ |
98 | u8 alarms; | 98 | u8 alarms; |
99 | }; | 99 | }; |
100 | 100 | ||
101 | /* | 101 | /* |
102 | * Real code | 102 | * Real code |
103 | */ | 103 | */ |
104 | 104 | ||
105 | static void max6642_init_client(struct max6642_data *data, | 105 | static void max6642_init_client(struct max6642_data *data, |
106 | struct i2c_client *client) | 106 | struct i2c_client *client) |
107 | { | 107 | { |
108 | u8 config; | 108 | u8 config; |
109 | 109 | ||
110 | /* | 110 | /* |
111 | * Start the conversions. | 111 | * Start the conversions. |
112 | */ | 112 | */ |
113 | config = i2c_smbus_read_byte_data(client, MAX6642_REG_R_CONFIG); | 113 | config = i2c_smbus_read_byte_data(client, MAX6642_REG_R_CONFIG); |
114 | if (config & 0x40) | 114 | if (config & 0x40) |
115 | i2c_smbus_write_byte_data(client, MAX6642_REG_W_CONFIG, | 115 | i2c_smbus_write_byte_data(client, MAX6642_REG_W_CONFIG, |
116 | config & 0xBF); /* run */ | 116 | config & 0xBF); /* run */ |
117 | 117 | ||
118 | data->temp_high[0] = i2c_smbus_read_byte_data(client, | 118 | data->temp_high[0] = i2c_smbus_read_byte_data(client, |
119 | MAX6642_REG_R_LOCAL_HIGH); | 119 | MAX6642_REG_R_LOCAL_HIGH); |
120 | data->temp_high[1] = i2c_smbus_read_byte_data(client, | 120 | data->temp_high[1] = i2c_smbus_read_byte_data(client, |
121 | MAX6642_REG_R_REMOTE_HIGH); | 121 | MAX6642_REG_R_REMOTE_HIGH); |
122 | } | 122 | } |
123 | 123 | ||
124 | /* Return 0 if detection is successful, -ENODEV otherwise */ | 124 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
125 | static int max6642_detect(struct i2c_client *client, | 125 | static int max6642_detect(struct i2c_client *client, |
126 | struct i2c_board_info *info) | 126 | struct i2c_board_info *info) |
127 | { | 127 | { |
128 | struct i2c_adapter *adapter = client->adapter; | 128 | struct i2c_adapter *adapter = client->adapter; |
129 | u8 reg_config, reg_status, man_id; | 129 | u8 reg_config, reg_status, man_id; |
130 | 130 | ||
131 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 131 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
132 | return -ENODEV; | 132 | return -ENODEV; |
133 | 133 | ||
134 | /* identification */ | 134 | /* identification */ |
135 | man_id = i2c_smbus_read_byte_data(client, MAX6642_REG_R_MAN_ID); | 135 | man_id = i2c_smbus_read_byte_data(client, MAX6642_REG_R_MAN_ID); |
136 | if (man_id != 0x4D) | 136 | if (man_id != 0x4D) |
137 | return -ENODEV; | 137 | return -ENODEV; |
138 | 138 | ||
139 | /* sanity check */ | 139 | /* sanity check */ |
140 | if (i2c_smbus_read_byte_data(client, 0x04) != 0x4D | 140 | if (i2c_smbus_read_byte_data(client, 0x04) != 0x4D |
141 | || i2c_smbus_read_byte_data(client, 0x06) != 0x4D | 141 | || i2c_smbus_read_byte_data(client, 0x06) != 0x4D |
142 | || i2c_smbus_read_byte_data(client, 0xff) != 0x4D) | 142 | || i2c_smbus_read_byte_data(client, 0xff) != 0x4D) |
143 | return -ENODEV; | 143 | return -ENODEV; |
144 | 144 | ||
145 | /* | 145 | /* |
146 | * We read the config and status register, the 4 lower bits in the | 146 | * We read the config and status register, the 4 lower bits in the |
147 | * config register should be zero and bit 5, 3, 1 and 0 should be | 147 | * config register should be zero and bit 5, 3, 1 and 0 should be |
148 | * zero in the status register. | 148 | * zero in the status register. |
149 | */ | 149 | */ |
150 | reg_config = i2c_smbus_read_byte_data(client, MAX6642_REG_R_CONFIG); | 150 | reg_config = i2c_smbus_read_byte_data(client, MAX6642_REG_R_CONFIG); |
151 | if ((reg_config & 0x0f) != 0x00) | 151 | if ((reg_config & 0x0f) != 0x00) |
152 | return -ENODEV; | 152 | return -ENODEV; |
153 | 153 | ||
154 | /* in between, another round of sanity checks */ | 154 | /* in between, another round of sanity checks */ |
155 | if (i2c_smbus_read_byte_data(client, 0x04) != reg_config | 155 | if (i2c_smbus_read_byte_data(client, 0x04) != reg_config |
156 | || i2c_smbus_read_byte_data(client, 0x06) != reg_config | 156 | || i2c_smbus_read_byte_data(client, 0x06) != reg_config |
157 | || i2c_smbus_read_byte_data(client, 0xff) != reg_config) | 157 | || i2c_smbus_read_byte_data(client, 0xff) != reg_config) |
158 | return -ENODEV; | 158 | return -ENODEV; |
159 | 159 | ||
160 | reg_status = i2c_smbus_read_byte_data(client, MAX6642_REG_R_STATUS); | 160 | reg_status = i2c_smbus_read_byte_data(client, MAX6642_REG_R_STATUS); |
161 | if ((reg_status & 0x2b) != 0x00) | 161 | if ((reg_status & 0x2b) != 0x00) |
162 | return -ENODEV; | 162 | return -ENODEV; |
163 | 163 | ||
164 | strlcpy(info->type, "max6642", I2C_NAME_SIZE); | 164 | strlcpy(info->type, "max6642", I2C_NAME_SIZE); |
165 | 165 | ||
166 | return 0; | 166 | return 0; |
167 | } | 167 | } |
168 | 168 | ||
169 | static struct max6642_data *max6642_update_device(struct device *dev) | 169 | static struct max6642_data *max6642_update_device(struct device *dev) |
170 | { | 170 | { |
171 | struct max6642_data *data = dev_get_drvdata(dev); | 171 | struct max6642_data *data = dev_get_drvdata(dev); |
172 | struct i2c_client *client = data->client; | 172 | struct i2c_client *client = data->client; |
173 | u16 val, tmp; | 173 | u16 val, tmp; |
174 | 174 | ||
175 | mutex_lock(&data->update_lock); | 175 | mutex_lock(&data->update_lock); |
176 | 176 | ||
177 | if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { | 177 | if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { |
178 | dev_dbg(dev, "Updating max6642 data.\n"); | 178 | dev_dbg(dev, "Updating max6642 data.\n"); |
179 | val = i2c_smbus_read_byte_data(client, | 179 | val = i2c_smbus_read_byte_data(client, |
180 | MAX6642_REG_R_LOCAL_TEMPL); | 180 | MAX6642_REG_R_LOCAL_TEMPL); |
181 | tmp = (val >> 6) & 3; | 181 | tmp = (val >> 6) & 3; |
182 | val = i2c_smbus_read_byte_data(client, | 182 | val = i2c_smbus_read_byte_data(client, |
183 | MAX6642_REG_R_LOCAL_TEMP); | 183 | MAX6642_REG_R_LOCAL_TEMP); |
184 | val = (val << 2) | tmp; | 184 | val = (val << 2) | tmp; |
185 | data->temp_input[0] = val; | 185 | data->temp_input[0] = val; |
186 | val = i2c_smbus_read_byte_data(client, | 186 | val = i2c_smbus_read_byte_data(client, |
187 | MAX6642_REG_R_REMOTE_TEMPL); | 187 | MAX6642_REG_R_REMOTE_TEMPL); |
188 | tmp = (val >> 6) & 3; | 188 | tmp = (val >> 6) & 3; |
189 | val = i2c_smbus_read_byte_data(client, | 189 | val = i2c_smbus_read_byte_data(client, |
190 | MAX6642_REG_R_REMOTE_TEMP); | 190 | MAX6642_REG_R_REMOTE_TEMP); |
191 | val = (val << 2) | tmp; | 191 | val = (val << 2) | tmp; |
192 | data->temp_input[1] = val; | 192 | data->temp_input[1] = val; |
193 | data->alarms = i2c_smbus_read_byte_data(client, | 193 | data->alarms = i2c_smbus_read_byte_data(client, |
194 | MAX6642_REG_R_STATUS); | 194 | MAX6642_REG_R_STATUS); |
195 | 195 | ||
196 | data->last_updated = jiffies; | 196 | data->last_updated = jiffies; |
197 | data->valid = 1; | 197 | data->valid = 1; |
198 | } | 198 | } |
199 | 199 | ||
200 | mutex_unlock(&data->update_lock); | 200 | mutex_unlock(&data->update_lock); |
201 | 201 | ||
202 | return data; | 202 | return data; |
203 | } | 203 | } |
204 | 204 | ||
205 | /* | 205 | /* |
206 | * Sysfs stuff | 206 | * Sysfs stuff |
207 | */ | 207 | */ |
208 | 208 | ||
209 | static ssize_t show_temp_max10(struct device *dev, | 209 | static ssize_t show_temp_max10(struct device *dev, |
210 | struct device_attribute *dev_attr, char *buf) | 210 | struct device_attribute *dev_attr, char *buf) |
211 | { | 211 | { |
212 | struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); | 212 | struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); |
213 | struct max6642_data *data = max6642_update_device(dev); | 213 | struct max6642_data *data = max6642_update_device(dev); |
214 | 214 | ||
215 | return sprintf(buf, "%d\n", | 215 | return sprintf(buf, "%d\n", |
216 | temp_from_reg10(data->temp_input[attr->index])); | 216 | temp_from_reg10(data->temp_input[attr->index])); |
217 | } | 217 | } |
218 | 218 | ||
219 | static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr, | 219 | static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr, |
220 | char *buf) | 220 | char *buf) |
221 | { | 221 | { |
222 | struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(attr); | 222 | struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(attr); |
223 | struct max6642_data *data = max6642_update_device(dev); | 223 | struct max6642_data *data = max6642_update_device(dev); |
224 | 224 | ||
225 | return sprintf(buf, "%d\n", temp_from_reg(data->temp_high[attr2->nr])); | 225 | return sprintf(buf, "%d\n", temp_from_reg(data->temp_high[attr2->nr])); |
226 | } | 226 | } |
227 | 227 | ||
228 | static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | 228 | static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, |
229 | const char *buf, size_t count) | 229 | const char *buf, size_t count) |
230 | { | 230 | { |
231 | struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(attr); | 231 | struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(attr); |
232 | struct max6642_data *data = dev_get_drvdata(dev); | 232 | struct max6642_data *data = dev_get_drvdata(dev); |
233 | unsigned long val; | 233 | unsigned long val; |
234 | int err; | 234 | int err; |
235 | 235 | ||
236 | err = kstrtoul(buf, 10, &val); | 236 | err = kstrtoul(buf, 10, &val); |
237 | if (err < 0) | 237 | if (err < 0) |
238 | return err; | 238 | return err; |
239 | 239 | ||
240 | mutex_lock(&data->update_lock); | 240 | mutex_lock(&data->update_lock); |
241 | data->temp_high[attr2->nr] = clamp_val(temp_to_reg(val), 0, 255); | 241 | data->temp_high[attr2->nr] = clamp_val(temp_to_reg(val), 0, 255); |
242 | i2c_smbus_write_byte_data(data->client, attr2->index, | 242 | i2c_smbus_write_byte_data(data->client, attr2->index, |
243 | data->temp_high[attr2->nr]); | 243 | data->temp_high[attr2->nr]); |
244 | mutex_unlock(&data->update_lock); | 244 | mutex_unlock(&data->update_lock); |
245 | return count; | 245 | return count; |
246 | } | 246 | } |
247 | 247 | ||
248 | static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, | 248 | static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, |
249 | char *buf) | 249 | char *buf) |
250 | { | 250 | { |
251 | int bitnr = to_sensor_dev_attr(attr)->index; | 251 | int bitnr = to_sensor_dev_attr(attr)->index; |
252 | struct max6642_data *data = max6642_update_device(dev); | 252 | struct max6642_data *data = max6642_update_device(dev); |
253 | return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1); | 253 | return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1); |
254 | } | 254 | } |
255 | 255 | ||
256 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp_max10, NULL, 0); | 256 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp_max10, NULL, 0); |
257 | static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp_max10, NULL, 1); | 257 | static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp_max10, NULL, 1); |
258 | static SENSOR_DEVICE_ATTR_2(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, | 258 | static SENSOR_DEVICE_ATTR_2(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, |
259 | set_temp_max, 0, MAX6642_REG_W_LOCAL_HIGH); | 259 | set_temp_max, 0, MAX6642_REG_W_LOCAL_HIGH); |
260 | static SENSOR_DEVICE_ATTR_2(temp2_max, S_IWUSR | S_IRUGO, show_temp_max, | 260 | static SENSOR_DEVICE_ATTR_2(temp2_max, S_IWUSR | S_IRUGO, show_temp_max, |
261 | set_temp_max, 1, MAX6642_REG_W_REMOTE_HIGH); | 261 | set_temp_max, 1, MAX6642_REG_W_REMOTE_HIGH); |
262 | static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 2); | 262 | static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 2); |
263 | static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6); | 263 | static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6); |
264 | static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4); | 264 | static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4); |
265 | 265 | ||
266 | static struct attribute *max6642_attrs[] = { | 266 | static struct attribute *max6642_attrs[] = { |
267 | &sensor_dev_attr_temp1_input.dev_attr.attr, | 267 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
268 | &sensor_dev_attr_temp2_input.dev_attr.attr, | 268 | &sensor_dev_attr_temp2_input.dev_attr.attr, |
269 | &sensor_dev_attr_temp1_max.dev_attr.attr, | 269 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
270 | &sensor_dev_attr_temp2_max.dev_attr.attr, | 270 | &sensor_dev_attr_temp2_max.dev_attr.attr, |
271 | 271 | ||
272 | &sensor_dev_attr_temp2_fault.dev_attr.attr, | 272 | &sensor_dev_attr_temp2_fault.dev_attr.attr, |
273 | &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, | 273 | &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, |
274 | &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, | 274 | &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, |
275 | NULL | 275 | NULL |
276 | }; | 276 | }; |
277 | ATTRIBUTE_GROUPS(max6642); | 277 | ATTRIBUTE_GROUPS(max6642); |
278 | 278 | ||
279 | static int max6642_probe(struct i2c_client *client, | 279 | static int max6642_probe(struct i2c_client *client, |
280 | const struct i2c_device_id *id) | 280 | const struct i2c_device_id *id) |
281 | { | 281 | { |
282 | struct device *dev = &client->dev; | 282 | struct device *dev = &client->dev; |
283 | struct max6642_data *data; | 283 | struct max6642_data *data; |
284 | struct device *hwmon_dev; | 284 | struct device *hwmon_dev; |
285 | 285 | ||
286 | data = devm_kzalloc(dev, sizeof(struct max6642_data), GFP_KERNEL); | 286 | data = devm_kzalloc(dev, sizeof(struct max6642_data), GFP_KERNEL); |
287 | if (!data) | 287 | if (!data) |
288 | return -ENOMEM; | 288 | return -ENOMEM; |
289 | 289 | ||
290 | data->client = client; | 290 | data->client = client; |
291 | mutex_init(&data->update_lock); | 291 | mutex_init(&data->update_lock); |
292 | 292 | ||
293 | /* Initialize the MAX6642 chip */ | 293 | /* Initialize the MAX6642 chip */ |
294 | max6642_init_client(data, client); | 294 | max6642_init_client(data, client); |
295 | 295 | ||
296 | hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev, | 296 | hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev, |
297 | client->name, data, | 297 | client->name, data, |
298 | max6642_groups); | 298 | max6642_groups); |
299 | if (IS_ERR(hwmon_dev)) | 299 | return PTR_ERR_OR_ZERO(hwmon_dev); |
300 | return PTR_ERR(hwmon_dev); | ||
301 | |||
302 | return 0; | ||
303 | } | 300 | } |
304 | 301 | ||
305 | /* | 302 | /* |
306 | * Driver data (common to all clients) | 303 | * Driver data (common to all clients) |
307 | */ | 304 | */ |
308 | 305 | ||
309 | static const struct i2c_device_id max6642_id[] = { | 306 | static const struct i2c_device_id max6642_id[] = { |
310 | { "max6642", 0 }, | 307 | { "max6642", 0 }, |
311 | { } | 308 | { } |
312 | }; | 309 | }; |
313 | MODULE_DEVICE_TABLE(i2c, max6642_id); | 310 | MODULE_DEVICE_TABLE(i2c, max6642_id); |
314 | 311 | ||
315 | static struct i2c_driver max6642_driver = { | 312 | static struct i2c_driver max6642_driver = { |
316 | .class = I2C_CLASS_HWMON, | 313 | .class = I2C_CLASS_HWMON, |
317 | .driver = { | 314 | .driver = { |
318 | .name = "max6642", | 315 | .name = "max6642", |
319 | }, | 316 | }, |
320 | .probe = max6642_probe, | 317 | .probe = max6642_probe, |
321 | .id_table = max6642_id, | 318 | .id_table = max6642_id, |
322 | .detect = max6642_detect, | 319 | .detect = max6642_detect, |
323 | .address_list = normal_i2c, | 320 | .address_list = normal_i2c, |
324 | }; | 321 | }; |
325 | 322 | ||
326 | module_i2c_driver(max6642_driver); | 323 | module_i2c_driver(max6642_driver); |
327 | 324 | ||
328 | MODULE_AUTHOR("Per Dalen <per.dalen@appeartv.com>"); | 325 | MODULE_AUTHOR("Per Dalen <per.dalen@appeartv.com>"); |
329 | MODULE_DESCRIPTION("MAX6642 sensor driver"); | 326 | MODULE_DESCRIPTION("MAX6642 sensor driver"); |
330 | MODULE_LICENSE("GPL"); | 327 | MODULE_LICENSE("GPL"); |
331 | 328 |