emc6w201.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. /*
  2. * emc6w201.c - Hardware monitoring driver for the SMSC EMC6W201
  3. * Copyright (C) 2011 Jean Delvare <jdelvare@suse.de>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19. #include <linux/module.h>
  20. #include <linux/init.h>
  21. #include <linux/slab.h>
  22. #include <linux/jiffies.h>
  23. #include <linux/i2c.h>
  24. #include <linux/hwmon.h>
  25. #include <linux/hwmon-sysfs.h>
  26. #include <linux/err.h>
  27. #include <linux/mutex.h>
  28. /*
  29. * Addresses to scan
  30. */
  31. static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
  32. /*
  33. * The EMC6W201 registers
  34. */
  35. #define EMC6W201_REG_IN(nr) (0x20 + (nr))
  36. #define EMC6W201_REG_TEMP(nr) (0x26 + (nr))
  37. #define EMC6W201_REG_FAN(nr) (0x2C + (nr) * 2)
  38. #define EMC6W201_REG_COMPANY 0x3E
  39. #define EMC6W201_REG_VERSTEP 0x3F
  40. #define EMC6W201_REG_CONFIG 0x40
  41. #define EMC6W201_REG_IN_LOW(nr) (0x4A + (nr) * 2)
  42. #define EMC6W201_REG_IN_HIGH(nr) (0x4B + (nr) * 2)
  43. #define EMC6W201_REG_TEMP_LOW(nr) (0x56 + (nr) * 2)
  44. #define EMC6W201_REG_TEMP_HIGH(nr) (0x57 + (nr) * 2)
  45. #define EMC6W201_REG_FAN_MIN(nr) (0x62 + (nr) * 2)
  46. enum subfeature { input, min, max };
  47. /*
  48. * Per-device data
  49. */
  50. struct emc6w201_data {
  51. struct i2c_client *client;
  52. struct mutex update_lock;
  53. char valid; /* zero until following fields are valid */
  54. unsigned long last_updated; /* in jiffies */
  55. /* registers values */
  56. u8 in[3][6];
  57. s8 temp[3][6];
  58. u16 fan[2][5];
  59. };
  60. /*
  61. * Combine LSB and MSB registers in a single value
  62. * Locking: must be called with data->update_lock held
  63. */
  64. static u16 emc6w201_read16(struct i2c_client *client, u8 reg)
  65. {
  66. int lsb, msb;
  67. lsb = i2c_smbus_read_byte_data(client, reg);
  68. msb = i2c_smbus_read_byte_data(client, reg + 1);
  69. if (unlikely(lsb < 0 || msb < 0)) {
  70. dev_err(&client->dev, "%d-bit %s failed at 0x%02x\n",
  71. 16, "read", reg);
  72. return 0xFFFF; /* Arbitrary value */
  73. }
  74. return (msb << 8) | lsb;
  75. }
  76. /*
  77. * Write 16-bit value to LSB and MSB registers
  78. * Locking: must be called with data->update_lock held
  79. */
  80. static int emc6w201_write16(struct i2c_client *client, u8 reg, u16 val)
  81. {
  82. int err;
  83. err = i2c_smbus_write_byte_data(client, reg, val & 0xff);
  84. if (likely(!err))
  85. err = i2c_smbus_write_byte_data(client, reg + 1, val >> 8);
  86. if (unlikely(err < 0))
  87. dev_err(&client->dev, "%d-bit %s failed at 0x%02x\n",
  88. 16, "write", reg);
  89. return err;
  90. }
  91. /* Read 8-bit value from register */
  92. static u8 emc6w201_read8(struct i2c_client *client, u8 reg)
  93. {
  94. int val;
  95. val = i2c_smbus_read_byte_data(client, reg);
  96. if (unlikely(val < 0)) {
  97. dev_err(&client->dev, "%d-bit %s failed at 0x%02x\n",
  98. 8, "read", reg);
  99. return 0x00; /* Arbitrary value */
  100. }
  101. return val;
  102. }
  103. /* Write 8-bit value to register */
  104. static int emc6w201_write8(struct i2c_client *client, u8 reg, u8 val)
  105. {
  106. int err;
  107. err = i2c_smbus_write_byte_data(client, reg, val);
  108. if (unlikely(err < 0))
  109. dev_err(&client->dev, "%d-bit %s failed at 0x%02x\n",
  110. 8, "write", reg);
  111. return err;
  112. }
  113. static struct emc6w201_data *emc6w201_update_device(struct device *dev)
  114. {
  115. struct emc6w201_data *data = dev_get_drvdata(dev);
  116. struct i2c_client *client = data->client;
  117. int nr;
  118. mutex_lock(&data->update_lock);
  119. if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
  120. for (nr = 0; nr < 6; nr++) {
  121. data->in[input][nr] =
  122. emc6w201_read8(client,
  123. EMC6W201_REG_IN(nr));
  124. data->in[min][nr] =
  125. emc6w201_read8(client,
  126. EMC6W201_REG_IN_LOW(nr));
  127. data->in[max][nr] =
  128. emc6w201_read8(client,
  129. EMC6W201_REG_IN_HIGH(nr));
  130. }
  131. for (nr = 0; nr < 6; nr++) {
  132. data->temp[input][nr] =
  133. emc6w201_read8(client,
  134. EMC6W201_REG_TEMP(nr));
  135. data->temp[min][nr] =
  136. emc6w201_read8(client,
  137. EMC6W201_REG_TEMP_LOW(nr));
  138. data->temp[max][nr] =
  139. emc6w201_read8(client,
  140. EMC6W201_REG_TEMP_HIGH(nr));
  141. }
  142. for (nr = 0; nr < 5; nr++) {
  143. data->fan[input][nr] =
  144. emc6w201_read16(client,
  145. EMC6W201_REG_FAN(nr));
  146. data->fan[min][nr] =
  147. emc6w201_read16(client,
  148. EMC6W201_REG_FAN_MIN(nr));
  149. }
  150. data->last_updated = jiffies;
  151. data->valid = 1;
  152. }
  153. mutex_unlock(&data->update_lock);
  154. return data;
  155. }
  156. /*
  157. * Sysfs callback functions
  158. */
  159. static const s16 nominal_mv[6] = { 2500, 1500, 3300, 5000, 1500, 1500 };
  160. static ssize_t show_in(struct device *dev, struct device_attribute *devattr,
  161. char *buf)
  162. {
  163. struct emc6w201_data *data = emc6w201_update_device(dev);
  164. int sf = to_sensor_dev_attr_2(devattr)->index;
  165. int nr = to_sensor_dev_attr_2(devattr)->nr;
  166. return sprintf(buf, "%u\n",
  167. (unsigned)data->in[sf][nr] * nominal_mv[nr] / 0xC0);
  168. }
  169. static ssize_t set_in(struct device *dev, struct device_attribute *devattr,
  170. const char *buf, size_t count)
  171. {
  172. struct emc6w201_data *data = dev_get_drvdata(dev);
  173. struct i2c_client *client = data->client;
  174. int sf = to_sensor_dev_attr_2(devattr)->index;
  175. int nr = to_sensor_dev_attr_2(devattr)->nr;
  176. int err;
  177. long val;
  178. u8 reg;
  179. err = kstrtol(buf, 10, &val);
  180. if (err < 0)
  181. return err;
  182. val = DIV_ROUND_CLOSEST(val * 0xC0, nominal_mv[nr]);
  183. reg = (sf == min) ? EMC6W201_REG_IN_LOW(nr)
  184. : EMC6W201_REG_IN_HIGH(nr);
  185. mutex_lock(&data->update_lock);
  186. data->in[sf][nr] = clamp_val(val, 0, 255);
  187. err = emc6w201_write8(client, reg, data->in[sf][nr]);
  188. mutex_unlock(&data->update_lock);
  189. return err < 0 ? err : count;
  190. }
  191. static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
  192. char *buf)
  193. {
  194. struct emc6w201_data *data = emc6w201_update_device(dev);
  195. int sf = to_sensor_dev_attr_2(devattr)->index;
  196. int nr = to_sensor_dev_attr_2(devattr)->nr;
  197. return sprintf(buf, "%d\n", (int)data->temp[sf][nr] * 1000);
  198. }
  199. static ssize_t set_temp(struct device *dev, struct device_attribute *devattr,
  200. const char *buf, size_t count)
  201. {
  202. struct emc6w201_data *data = dev_get_drvdata(dev);
  203. struct i2c_client *client = data->client;
  204. int sf = to_sensor_dev_attr_2(devattr)->index;
  205. int nr = to_sensor_dev_attr_2(devattr)->nr;
  206. int err;
  207. long val;
  208. u8 reg;
  209. err = kstrtol(buf, 10, &val);
  210. if (err < 0)
  211. return err;
  212. val = DIV_ROUND_CLOSEST(val, 1000);
  213. reg = (sf == min) ? EMC6W201_REG_TEMP_LOW(nr)
  214. : EMC6W201_REG_TEMP_HIGH(nr);
  215. mutex_lock(&data->update_lock);
  216. data->temp[sf][nr] = clamp_val(val, -127, 127);
  217. err = emc6w201_write8(client, reg, data->temp[sf][nr]);
  218. mutex_unlock(&data->update_lock);
  219. return err < 0 ? err : count;
  220. }
  221. static ssize_t show_fan(struct device *dev, struct device_attribute *devattr,
  222. char *buf)
  223. {
  224. struct emc6w201_data *data = emc6w201_update_device(dev);
  225. int sf = to_sensor_dev_attr_2(devattr)->index;
  226. int nr = to_sensor_dev_attr_2(devattr)->nr;
  227. unsigned rpm;
  228. if (data->fan[sf][nr] == 0 || data->fan[sf][nr] == 0xFFFF)
  229. rpm = 0;
  230. else
  231. rpm = 5400000U / data->fan[sf][nr];
  232. return sprintf(buf, "%u\n", rpm);
  233. }
  234. static ssize_t set_fan(struct device *dev, struct device_attribute *devattr,
  235. const char *buf, size_t count)
  236. {
  237. struct emc6w201_data *data = dev_get_drvdata(dev);
  238. struct i2c_client *client = data->client;
  239. int sf = to_sensor_dev_attr_2(devattr)->index;
  240. int nr = to_sensor_dev_attr_2(devattr)->nr;
  241. int err;
  242. unsigned long val;
  243. err = kstrtoul(buf, 10, &val);
  244. if (err < 0)
  245. return err;
  246. if (val == 0) {
  247. val = 0xFFFF;
  248. } else {
  249. val = DIV_ROUND_CLOSEST(5400000U, val);
  250. val = clamp_val(val, 0, 0xFFFE);
  251. }
  252. mutex_lock(&data->update_lock);
  253. data->fan[sf][nr] = val;
  254. err = emc6w201_write16(client, EMC6W201_REG_FAN_MIN(nr),
  255. data->fan[sf][nr]);
  256. mutex_unlock(&data->update_lock);
  257. return err < 0 ? err : count;
  258. }
  259. static SENSOR_DEVICE_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, input);
  260. static SENSOR_DEVICE_ATTR_2(in0_min, S_IRUGO | S_IWUSR, show_in, set_in,
  261. 0, min);
  262. static SENSOR_DEVICE_ATTR_2(in0_max, S_IRUGO | S_IWUSR, show_in, set_in,
  263. 0, max);
  264. static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 1, input);
  265. static SENSOR_DEVICE_ATTR_2(in1_min, S_IRUGO | S_IWUSR, show_in, set_in,
  266. 1, min);
  267. static SENSOR_DEVICE_ATTR_2(in1_max, S_IRUGO | S_IWUSR, show_in, set_in,
  268. 1, max);
  269. static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 2, input);
  270. static SENSOR_DEVICE_ATTR_2(in2_min, S_IRUGO | S_IWUSR, show_in, set_in,
  271. 2, min);
  272. static SENSOR_DEVICE_ATTR_2(in2_max, S_IRUGO | S_IWUSR, show_in, set_in,
  273. 2, max);
  274. static SENSOR_DEVICE_ATTR_2(in3_input, S_IRUGO, show_in, NULL, 3, input);
  275. static SENSOR_DEVICE_ATTR_2(in3_min, S_IRUGO | S_IWUSR, show_in, set_in,
  276. 3, min);
  277. static SENSOR_DEVICE_ATTR_2(in3_max, S_IRUGO | S_IWUSR, show_in, set_in,
  278. 3, max);
  279. static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO, show_in, NULL, 4, input);
  280. static SENSOR_DEVICE_ATTR_2(in4_min, S_IRUGO | S_IWUSR, show_in, set_in,
  281. 4, min);
  282. static SENSOR_DEVICE_ATTR_2(in4_max, S_IRUGO | S_IWUSR, show_in, set_in,
  283. 4, max);
  284. static SENSOR_DEVICE_ATTR_2(in5_input, S_IRUGO, show_in, NULL, 5, input);
  285. static SENSOR_DEVICE_ATTR_2(in5_min, S_IRUGO | S_IWUSR, show_in, set_in,
  286. 5, min);
  287. static SENSOR_DEVICE_ATTR_2(in5_max, S_IRUGO | S_IWUSR, show_in, set_in,
  288. 5, max);
  289. static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, input);
  290. static SENSOR_DEVICE_ATTR_2(temp1_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
  291. 0, min);
  292. static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
  293. 0, max);
  294. static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 1, input);
  295. static SENSOR_DEVICE_ATTR_2(temp2_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
  296. 1, min);
  297. static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
  298. 1, max);
  299. static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 2, input);
  300. static SENSOR_DEVICE_ATTR_2(temp3_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
  301. 2, min);
  302. static SENSOR_DEVICE_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
  303. 2, max);
  304. static SENSOR_DEVICE_ATTR_2(temp4_input, S_IRUGO, show_temp, NULL, 3, input);
  305. static SENSOR_DEVICE_ATTR_2(temp4_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
  306. 3, min);
  307. static SENSOR_DEVICE_ATTR_2(temp4_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
  308. 3, max);
  309. static SENSOR_DEVICE_ATTR_2(temp5_input, S_IRUGO, show_temp, NULL, 4, input);
  310. static SENSOR_DEVICE_ATTR_2(temp5_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
  311. 4, min);
  312. static SENSOR_DEVICE_ATTR_2(temp5_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
  313. 4, max);
  314. static SENSOR_DEVICE_ATTR_2(temp6_input, S_IRUGO, show_temp, NULL, 5, input);
  315. static SENSOR_DEVICE_ATTR_2(temp6_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
  316. 5, min);
  317. static SENSOR_DEVICE_ATTR_2(temp6_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
  318. 5, max);
  319. static SENSOR_DEVICE_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, 0, input);
  320. static SENSOR_DEVICE_ATTR_2(fan1_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
  321. 0, min);
  322. static SENSOR_DEVICE_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, 1, input);
  323. static SENSOR_DEVICE_ATTR_2(fan2_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
  324. 1, min);
  325. static SENSOR_DEVICE_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 2, input);
  326. static SENSOR_DEVICE_ATTR_2(fan3_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
  327. 2, min);
  328. static SENSOR_DEVICE_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 3, input);
  329. static SENSOR_DEVICE_ATTR_2(fan4_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
  330. 3, min);
  331. static SENSOR_DEVICE_ATTR_2(fan5_input, S_IRUGO, show_fan, NULL, 4, input);
  332. static SENSOR_DEVICE_ATTR_2(fan5_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
  333. 4, min);
  334. static struct attribute *emc6w201_attrs[] = {
  335. &sensor_dev_attr_in0_input.dev_attr.attr,
  336. &sensor_dev_attr_in0_min.dev_attr.attr,
  337. &sensor_dev_attr_in0_max.dev_attr.attr,
  338. &sensor_dev_attr_in1_input.dev_attr.attr,
  339. &sensor_dev_attr_in1_min.dev_attr.attr,
  340. &sensor_dev_attr_in1_max.dev_attr.attr,
  341. &sensor_dev_attr_in2_input.dev_attr.attr,
  342. &sensor_dev_attr_in2_min.dev_attr.attr,
  343. &sensor_dev_attr_in2_max.dev_attr.attr,
  344. &sensor_dev_attr_in3_input.dev_attr.attr,
  345. &sensor_dev_attr_in3_min.dev_attr.attr,
  346. &sensor_dev_attr_in3_max.dev_attr.attr,
  347. &sensor_dev_attr_in4_input.dev_attr.attr,
  348. &sensor_dev_attr_in4_min.dev_attr.attr,
  349. &sensor_dev_attr_in4_max.dev_attr.attr,
  350. &sensor_dev_attr_in5_input.dev_attr.attr,
  351. &sensor_dev_attr_in5_min.dev_attr.attr,
  352. &sensor_dev_attr_in5_max.dev_attr.attr,
  353. &sensor_dev_attr_temp1_input.dev_attr.attr,
  354. &sensor_dev_attr_temp1_min.dev_attr.attr,
  355. &sensor_dev_attr_temp1_max.dev_attr.attr,
  356. &sensor_dev_attr_temp2_input.dev_attr.attr,
  357. &sensor_dev_attr_temp2_min.dev_attr.attr,
  358. &sensor_dev_attr_temp2_max.dev_attr.attr,
  359. &sensor_dev_attr_temp3_input.dev_attr.attr,
  360. &sensor_dev_attr_temp3_min.dev_attr.attr,
  361. &sensor_dev_attr_temp3_max.dev_attr.attr,
  362. &sensor_dev_attr_temp4_input.dev_attr.attr,
  363. &sensor_dev_attr_temp4_min.dev_attr.attr,
  364. &sensor_dev_attr_temp4_max.dev_attr.attr,
  365. &sensor_dev_attr_temp5_input.dev_attr.attr,
  366. &sensor_dev_attr_temp5_min.dev_attr.attr,
  367. &sensor_dev_attr_temp5_max.dev_attr.attr,
  368. &sensor_dev_attr_temp6_input.dev_attr.attr,
  369. &sensor_dev_attr_temp6_min.dev_attr.attr,
  370. &sensor_dev_attr_temp6_max.dev_attr.attr,
  371. &sensor_dev_attr_fan1_input.dev_attr.attr,
  372. &sensor_dev_attr_fan1_min.dev_attr.attr,
  373. &sensor_dev_attr_fan2_input.dev_attr.attr,
  374. &sensor_dev_attr_fan2_min.dev_attr.attr,
  375. &sensor_dev_attr_fan3_input.dev_attr.attr,
  376. &sensor_dev_attr_fan3_min.dev_attr.attr,
  377. &sensor_dev_attr_fan4_input.dev_attr.attr,
  378. &sensor_dev_attr_fan4_min.dev_attr.attr,
  379. &sensor_dev_attr_fan5_input.dev_attr.attr,
  380. &sensor_dev_attr_fan5_min.dev_attr.attr,
  381. NULL
  382. };
  383. ATTRIBUTE_GROUPS(emc6w201);
  384. /*
  385. * Driver interface
  386. */
  387. /* Return 0 if detection is successful, -ENODEV otherwise */
  388. static int emc6w201_detect(struct i2c_client *client,
  389. struct i2c_board_info *info)
  390. {
  391. struct i2c_adapter *adapter = client->adapter;
  392. int company, verstep, config;
  393. if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
  394. return -ENODEV;
  395. /* Identification */
  396. company = i2c_smbus_read_byte_data(client, EMC6W201_REG_COMPANY);
  397. if (company != 0x5C)
  398. return -ENODEV;
  399. verstep = i2c_smbus_read_byte_data(client, EMC6W201_REG_VERSTEP);
  400. if (verstep < 0 || (verstep & 0xF0) != 0xB0)
  401. return -ENODEV;
  402. if ((verstep & 0x0F) > 2) {
  403. dev_dbg(&client->dev, "Unknown EMC6W201 stepping %d\n",
  404. verstep & 0x0F);
  405. return -ENODEV;
  406. }
  407. /* Check configuration */
  408. config = i2c_smbus_read_byte_data(client, EMC6W201_REG_CONFIG);
  409. if (config < 0 || (config & 0xF4) != 0x04)
  410. return -ENODEV;
  411. if (!(config & 0x01)) {
  412. dev_err(&client->dev, "Monitoring not enabled\n");
  413. return -ENODEV;
  414. }
  415. strlcpy(info->type, "emc6w201", I2C_NAME_SIZE);
  416. return 0;
  417. }
  418. static int emc6w201_probe(struct i2c_client *client,
  419. const struct i2c_device_id *id)
  420. {
  421. struct device *dev = &client->dev;
  422. struct emc6w201_data *data;
  423. struct device *hwmon_dev;
  424. data = devm_kzalloc(dev, sizeof(struct emc6w201_data), GFP_KERNEL);
  425. if (!data)
  426. return -ENOMEM;
  427. data->client = client;
  428. mutex_init(&data->update_lock);
  429. hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
  430. data,
  431. emc6w201_groups);
  432. return PTR_ERR_OR_ZERO(hwmon_dev);
  433. }
  434. static const struct i2c_device_id emc6w201_id[] = {
  435. { "emc6w201", 0 },
  436. { }
  437. };
  438. MODULE_DEVICE_TABLE(i2c, emc6w201_id);
  439. static struct i2c_driver emc6w201_driver = {
  440. .class = I2C_CLASS_HWMON,
  441. .driver = {
  442. .name = "emc6w201",
  443. },
  444. .probe = emc6w201_probe,
  445. .id_table = emc6w201_id,
  446. .detect = emc6w201_detect,
  447. .address_list = normal_i2c,
  448. };
  449. module_i2c_driver(emc6w201_driver);
  450. MODULE_AUTHOR("Jean Delvare <jdelvare@suse.de>");
  451. MODULE_DESCRIPTION("SMSC EMC6W201 hardware monitoring driver");
  452. MODULE_LICENSE("GPL");