blob: 9ab034a1b4c1ff059cdd5388760751d76261bd03 [file] [log] [blame]
Riku Voipio84f1e442007-08-24 13:03:09 +03001/*
Björn Gerhartf58c44e2011-12-13 13:19:58 -05002 * f75375s.c - driver for the Fintek F75375/SP, F75373 and
3 * F75387SG/RG hardware monitoring features
Riku Voipiob26e0ed2009-03-03 21:37:17 +02004 * Copyright (C) 2006-2007 Riku Voipio
Riku Voipio84f1e442007-08-24 13:03:09 +03005 *
6 * Datasheets available at:
7 *
8 * f75375:
Guenter Roeck4fd826e2011-12-08 09:54:18 -08009 * http://www.fintek.com.tw/files/productfiles/F75375_V026P.pdf
Riku Voipio84f1e442007-08-24 13:03:09 +030010 *
11 * f75373:
Justin P. Mattock631dd1a2010-10-18 11:03:14 +020012 * http://www.fintek.com.tw/files/productfiles/F75373_V025P.pdf
Riku Voipio84f1e442007-08-24 13:03:09 +030013 *
Björn Gerhartf58c44e2011-12-13 13:19:58 -050014 * f75387:
15 * http://www.fintek.com.tw/files/productfiles/F75387_V027P.pdf
16 *
Riku Voipio84f1e442007-08-24 13:03:09 +030017 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 *
31 */
32
33#include <linux/module.h>
34#include <linux/jiffies.h>
35#include <linux/hwmon.h>
36#include <linux/hwmon-sysfs.h>
37#include <linux/i2c.h>
38#include <linux/err.h>
39#include <linux/mutex.h>
Riku Voipioff312d02007-09-26 13:14:40 +030040#include <linux/f75375s.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090041#include <linux/slab.h>
Riku Voipio84f1e442007-08-24 13:03:09 +030042
43/* Addresses to scan */
Mark M. Hoffman25e9c862008-02-17 22:28:03 -050044static const unsigned short normal_i2c[] = { 0x2d, 0x2e, I2C_CLIENT_END };
Riku Voipio84f1e442007-08-24 13:03:09 +030045
Björn Gerhartf58c44e2011-12-13 13:19:58 -050046enum chips { f75373, f75375, f75387 };
Riku Voipio84f1e442007-08-24 13:03:09 +030047
48/* Fintek F75375 registers */
49#define F75375_REG_CONFIG0 0x0
50#define F75375_REG_CONFIG1 0x1
51#define F75375_REG_CONFIG2 0x2
52#define F75375_REG_CONFIG3 0x3
53#define F75375_REG_ADDR 0x4
54#define F75375_REG_INTR 0x31
55#define F75375_CHIP_ID 0x5A
56#define F75375_REG_VERSION 0x5C
57#define F75375_REG_VENDOR 0x5D
58#define F75375_REG_FAN_TIMER 0x60
59
60#define F75375_REG_VOLT(nr) (0x10 + (nr))
61#define F75375_REG_VOLT_HIGH(nr) (0x20 + (nr) * 2)
62#define F75375_REG_VOLT_LOW(nr) (0x21 + (nr) * 2)
63
64#define F75375_REG_TEMP(nr) (0x14 + (nr))
Björn Gerhartf58c44e2011-12-13 13:19:58 -050065#define F75387_REG_TEMP11_LSB(nr) (0x1a + (nr))
Riku Voipio84f1e442007-08-24 13:03:09 +030066#define F75375_REG_TEMP_HIGH(nr) (0x28 + (nr) * 2)
67#define F75375_REG_TEMP_HYST(nr) (0x29 + (nr) * 2)
68
69#define F75375_REG_FAN(nr) (0x16 + (nr) * 2)
70#define F75375_REG_FAN_MIN(nr) (0x2C + (nr) * 2)
71#define F75375_REG_FAN_FULL(nr) (0x70 + (nr) * 0x10)
72#define F75375_REG_FAN_PWM_DUTY(nr) (0x76 + (nr) * 0x10)
73#define F75375_REG_FAN_PWM_CLOCK(nr) (0x7D + (nr) * 0x10)
74
75#define F75375_REG_FAN_EXP(nr) (0x74 + (nr) * 0x10)
76#define F75375_REG_FAN_B_TEMP(nr, step) ((0xA0 + (nr) * 0x10) + (step))
77#define F75375_REG_FAN_B_SPEED(nr, step) \
78 ((0xA5 + (nr) * 0x10) + (step) * 2)
79
80#define F75375_REG_PWM1_RAISE_DUTY 0x69
81#define F75375_REG_PWM2_RAISE_DUTY 0x6A
82#define F75375_REG_PWM1_DROP_DUTY 0x6B
83#define F75375_REG_PWM2_DROP_DUTY 0x6C
84
Björn Gerhartf58c44e2011-12-13 13:19:58 -050085#define F75375_FAN_CTRL_LINEAR(nr) (4 + nr)
86#define F75387_FAN_CTRL_LINEAR(nr) (1 + ((nr) * 4))
Guillem Jover96f36402010-09-17 17:24:11 +020087#define FAN_CTRL_MODE(nr) (4 + ((nr) * 2))
Björn Gerhartf58c44e2011-12-13 13:19:58 -050088#define F75387_FAN_DUTY_MODE(nr) (2 + ((nr) * 4))
89#define F75387_FAN_MANU_MODE(nr) ((nr) * 4)
Riku Voipio84f1e442007-08-24 13:03:09 +030090
91/*
92 * Data structures and manipulation thereof
93 */
94
95struct f75375_data {
96 unsigned short addr;
Tony Jones1beeffe2007-08-20 13:46:20 -070097 struct device *hwmon_dev;
Riku Voipio84f1e442007-08-24 13:03:09 +030098
99 const char *name;
100 int kind;
101 struct mutex update_lock; /* protect register access */
102 char valid;
103 unsigned long last_updated; /* In jiffies */
104 unsigned long last_limits; /* In jiffies */
105
106 /* Register values */
107 u8 in[4];
108 u8 in_max[4];
109 u8 in_min[4];
110 u16 fan[2];
111 u16 fan_min[2];
Guenter Roeck740f6be32011-12-08 09:59:25 -0800112 u16 fan_max[2];
113 u16 fan_target[2];
Riku Voipio84f1e442007-08-24 13:03:09 +0300114 u8 fan_timer;
115 u8 pwm[2];
116 u8 pwm_mode[2];
117 u8 pwm_enable[2];
Björn Gerhartf58c44e2011-12-13 13:19:58 -0500118 /*
119 * f75387: For remote temperature reading, it uses signed 11-bit
120 * values with LSB = 0.125 degree Celsius, left-justified in 16-bit
121 * registers. For original 8-bit temp readings, the LSB just is 0.
122 */
123 s16 temp11[2];
Riku Voipio84f1e442007-08-24 13:03:09 +0300124 s8 temp_high[2];
125 s8 temp_max_hyst[2];
126};
127
Jean Delvare310ec792009-12-14 21:17:23 +0100128static int f75375_detect(struct i2c_client *client,
Jean Delvare935ada82008-07-16 19:30:11 +0200129 struct i2c_board_info *info);
Jean Delvared2653e92008-04-29 23:11:39 +0200130static int f75375_probe(struct i2c_client *client,
131 const struct i2c_device_id *id);
Riku Voipio620c1422007-10-16 12:46:49 +0300132static int f75375_remove(struct i2c_client *client);
133
Jean Delvare3760f732008-04-29 23:11:40 +0200134static const struct i2c_device_id f75375_id[] = {
135 { "f75373", f75373 },
136 { "f75375", f75375 },
Björn Gerhartf58c44e2011-12-13 13:19:58 -0500137 { "f75387", f75387 },
Jean Delvare3760f732008-04-29 23:11:40 +0200138 { }
139};
140MODULE_DEVICE_TABLE(i2c, f75375_id);
141
Riku Voipio84f1e442007-08-24 13:03:09 +0300142static struct i2c_driver f75375_driver = {
Jean Delvare935ada82008-07-16 19:30:11 +0200143 .class = I2C_CLASS_HWMON,
Riku Voipio84f1e442007-08-24 13:03:09 +0300144 .driver = {
145 .name = "f75375",
146 },
Riku Voipio620c1422007-10-16 12:46:49 +0300147 .probe = f75375_probe,
148 .remove = f75375_remove,
Jean Delvare3760f732008-04-29 23:11:40 +0200149 .id_table = f75375_id,
Jean Delvare935ada82008-07-16 19:30:11 +0200150 .detect = f75375_detect,
Jean Delvarec3813d62009-12-14 21:17:25 +0100151 .address_list = normal_i2c,
Riku Voipio84f1e442007-08-24 13:03:09 +0300152};
153
154static inline int f75375_read8(struct i2c_client *client, u8 reg)
155{
156 return i2c_smbus_read_byte_data(client, reg);
157}
158
159/* in most cases, should be called while holding update_lock */
160static inline u16 f75375_read16(struct i2c_client *client, u8 reg)
161{
Guenter Roeck4fd826e2011-12-08 09:54:18 -0800162 return (i2c_smbus_read_byte_data(client, reg) << 8)
163 | i2c_smbus_read_byte_data(client, reg + 1);
Riku Voipio84f1e442007-08-24 13:03:09 +0300164}
165
166static inline void f75375_write8(struct i2c_client *client, u8 reg,
167 u8 value)
168{
169 i2c_smbus_write_byte_data(client, reg, value);
170}
171
172static inline void f75375_write16(struct i2c_client *client, u8 reg,
173 u16 value)
174{
Nikolaus Schulzeb2f2552012-02-08 18:56:10 +0100175 int err = i2c_smbus_write_byte_data(client, reg, (value >> 8));
Riku Voipio84f1e442007-08-24 13:03:09 +0300176 if (err)
177 return;
178 i2c_smbus_write_byte_data(client, reg + 1, (value & 0xFF));
179}
180
Nikolaus Schulz331255d2012-02-28 22:15:51 +0100181static void f75375_write_pwm(struct i2c_client *client, int nr)
182{
183 struct f75375_data *data = i2c_get_clientdata(client);
184 if (data->kind == f75387)
185 f75375_write16(client, F75375_REG_FAN_EXP(nr), data->pwm[nr]);
186 else
187 f75375_write8(client, F75375_REG_FAN_PWM_DUTY(nr),
188 data->pwm[nr]);
189}
190
Riku Voipio84f1e442007-08-24 13:03:09 +0300191static struct f75375_data *f75375_update_device(struct device *dev)
192{
193 struct i2c_client *client = to_i2c_client(dev);
194 struct f75375_data *data = i2c_get_clientdata(client);
195 int nr;
196
197 mutex_lock(&data->update_lock);
198
199 /* Limit registers cache is refreshed after 60 seconds */
200 if (time_after(jiffies, data->last_limits + 60 * HZ)
201 || !data->valid) {
202 for (nr = 0; nr < 2; nr++) {
203 data->temp_high[nr] =
204 f75375_read8(client, F75375_REG_TEMP_HIGH(nr));
205 data->temp_max_hyst[nr] =
206 f75375_read8(client, F75375_REG_TEMP_HYST(nr));
Guenter Roeck740f6be32011-12-08 09:59:25 -0800207 data->fan_max[nr] =
Riku Voipio84f1e442007-08-24 13:03:09 +0300208 f75375_read16(client, F75375_REG_FAN_FULL(nr));
209 data->fan_min[nr] =
210 f75375_read16(client, F75375_REG_FAN_MIN(nr));
Guenter Roeck740f6be32011-12-08 09:59:25 -0800211 data->fan_target[nr] =
Riku Voipio84f1e442007-08-24 13:03:09 +0300212 f75375_read16(client, F75375_REG_FAN_EXP(nr));
Riku Voipio84f1e442007-08-24 13:03:09 +0300213 }
214 for (nr = 0; nr < 4; nr++) {
215 data->in_max[nr] =
216 f75375_read8(client, F75375_REG_VOLT_HIGH(nr));
217 data->in_min[nr] =
218 f75375_read8(client, F75375_REG_VOLT_LOW(nr));
219 }
220 data->fan_timer = f75375_read8(client, F75375_REG_FAN_TIMER);
221 data->last_limits = jiffies;
222 }
223
224 /* Measurement registers cache is refreshed after 2 second */
225 if (time_after(jiffies, data->last_updated + 2 * HZ)
226 || !data->valid) {
227 for (nr = 0; nr < 2; nr++) {
Nikolaus Schulza1c1baf2012-02-08 18:56:11 +0100228 data->pwm[nr] = f75375_read8(client,
229 F75375_REG_FAN_PWM_DUTY(nr));
Björn Gerhartf58c44e2011-12-13 13:19:58 -0500230 /* assign MSB, therefore shift it by 8 bits */
231 data->temp11[nr] =
232 f75375_read8(client, F75375_REG_TEMP(nr)) << 8;
233 if (data->kind == f75387)
234 /* merge F75387's temperature LSB (11-bit) */
235 data->temp11[nr] |=
236 f75375_read8(client,
237 F75387_REG_TEMP11_LSB(nr));
Riku Voipio84f1e442007-08-24 13:03:09 +0300238 data->fan[nr] =
239 f75375_read16(client, F75375_REG_FAN(nr));
240 }
241 for (nr = 0; nr < 4; nr++)
242 data->in[nr] =
243 f75375_read8(client, F75375_REG_VOLT(nr));
244
245 data->last_updated = jiffies;
246 data->valid = 1;
247 }
248
249 mutex_unlock(&data->update_lock);
250 return data;
251}
252
253static inline u16 rpm_from_reg(u16 reg)
254{
255 if (reg == 0 || reg == 0xffff)
256 return 0;
Guenter Roeck4fd826e2011-12-08 09:54:18 -0800257 return 1500000 / reg;
Riku Voipio84f1e442007-08-24 13:03:09 +0300258}
259
260static inline u16 rpm_to_reg(int rpm)
261{
262 if (rpm < 367 || rpm > 0xffff)
263 return 0xffff;
Guenter Roeck4fd826e2011-12-08 09:54:18 -0800264 return 1500000 / rpm;
Riku Voipio84f1e442007-08-24 13:03:09 +0300265}
266
Nikolaus Schulzb17d6562012-02-28 16:15:53 -0500267static bool duty_mode_enabled(u8 pwm_enable)
268{
269 switch (pwm_enable) {
270 case 0: /* Manual, duty mode (full speed) */
271 case 1: /* Manual, duty mode */
272 case 4: /* Auto, duty mode */
273 return true;
274 case 2: /* Auto, speed mode */
275 case 3: /* Manual, speed mode */
276 return false;
277 default:
278 BUG();
279 }
280}
281
Riku Voipio84f1e442007-08-24 13:03:09 +0300282static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
283 const char *buf, size_t count)
284{
285 int nr = to_sensor_dev_attr(attr)->index;
286 struct i2c_client *client = to_i2c_client(dev);
287 struct f75375_data *data = i2c_get_clientdata(client);
Guenter Roeck4fd826e2011-12-08 09:54:18 -0800288 unsigned long val;
289 int err;
290
291 err = kstrtoul(buf, 10, &val);
292 if (err < 0)
293 return err;
Riku Voipio84f1e442007-08-24 13:03:09 +0300294
295 mutex_lock(&data->update_lock);
296 data->fan_min[nr] = rpm_to_reg(val);
297 f75375_write16(client, F75375_REG_FAN_MIN(nr), data->fan_min[nr]);
298 mutex_unlock(&data->update_lock);
299 return count;
300}
301
Guenter Roeck740f6be32011-12-08 09:59:25 -0800302static ssize_t set_fan_target(struct device *dev, struct device_attribute *attr,
Riku Voipio84f1e442007-08-24 13:03:09 +0300303 const char *buf, size_t count)
304{
305 int nr = to_sensor_dev_attr(attr)->index;
306 struct i2c_client *client = to_i2c_client(dev);
307 struct f75375_data *data = i2c_get_clientdata(client);
Guenter Roeck4fd826e2011-12-08 09:54:18 -0800308 unsigned long val;
309 int err;
310
311 err = kstrtoul(buf, 10, &val);
312 if (err < 0)
313 return err;
Riku Voipio84f1e442007-08-24 13:03:09 +0300314
315 mutex_lock(&data->update_lock);
Guenter Roeck740f6be32011-12-08 09:59:25 -0800316 data->fan_target[nr] = rpm_to_reg(val);
317 f75375_write16(client, F75375_REG_FAN_EXP(nr), data->fan_target[nr]);
Riku Voipio84f1e442007-08-24 13:03:09 +0300318 mutex_unlock(&data->update_lock);
319 return count;
320}
321
322static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
323 const char *buf, size_t count)
324{
325 int nr = to_sensor_dev_attr(attr)->index;
326 struct i2c_client *client = to_i2c_client(dev);
327 struct f75375_data *data = i2c_get_clientdata(client);
Guenter Roeck4fd826e2011-12-08 09:54:18 -0800328 unsigned long val;
329 int err;
330
331 err = kstrtoul(buf, 10, &val);
332 if (err < 0)
333 return err;
Riku Voipio84f1e442007-08-24 13:03:09 +0300334
335 mutex_lock(&data->update_lock);
336 data->pwm[nr] = SENSORS_LIMIT(val, 0, 255);
Nikolaus Schulz331255d2012-02-28 22:15:51 +0100337 f75375_write_pwm(client, nr);
Riku Voipio84f1e442007-08-24 13:03:09 +0300338 mutex_unlock(&data->update_lock);
339 return count;
340}
341
342static ssize_t show_pwm_enable(struct device *dev, struct device_attribute
343 *attr, char *buf)
344{
345 int nr = to_sensor_dev_attr(attr)->index;
346 struct f75375_data *data = f75375_update_device(dev);
347 return sprintf(buf, "%d\n", data->pwm_enable[nr]);
348}
349
Riku Voipioff312d02007-09-26 13:14:40 +0300350static int set_pwm_enable_direct(struct i2c_client *client, int nr, int val)
Riku Voipio84f1e442007-08-24 13:03:09 +0300351{
Riku Voipio84f1e442007-08-24 13:03:09 +0300352 struct f75375_data *data = i2c_get_clientdata(client);
Riku Voipio84f1e442007-08-24 13:03:09 +0300353 u8 fanmode;
354
Nikolaus Schulzb17d6562012-02-28 16:15:53 -0500355 if (val < 0 || val > 4)
Riku Voipio84f1e442007-08-24 13:03:09 +0300356 return -EINVAL;
357
Riku Voipio84f1e442007-08-24 13:03:09 +0300358 fanmode = f75375_read8(client, F75375_REG_FAN_TIMER);
Björn Gerhartf58c44e2011-12-13 13:19:58 -0500359 if (data->kind == f75387) {
Nikolaus Schulzb17d6562012-02-28 16:15:53 -0500360 /* For now, deny dangerous toggling of duty mode */
361 if (duty_mode_enabled(data->pwm_enable[nr]) !=
362 duty_mode_enabled(val))
363 return -EOPNOTSUPP;
Björn Gerhartf58c44e2011-12-13 13:19:58 -0500364 /* clear each fanX_mode bit before setting them properly */
365 fanmode &= ~(1 << F75387_FAN_DUTY_MODE(nr));
366 fanmode &= ~(1 << F75387_FAN_MANU_MODE(nr));
367 switch (val) {
368 case 0: /* full speed */
369 fanmode |= (1 << F75387_FAN_MANU_MODE(nr));
370 fanmode |= (1 << F75387_FAN_DUTY_MODE(nr));
371 data->pwm[nr] = 255;
Björn Gerhartf58c44e2011-12-13 13:19:58 -0500372 break;
373 case 1: /* PWM */
374 fanmode |= (1 << F75387_FAN_MANU_MODE(nr));
375 fanmode |= (1 << F75387_FAN_DUTY_MODE(nr));
376 break;
Nikolaus Schulzb17d6562012-02-28 16:15:53 -0500377 case 2: /* Automatic, speed mode */
Björn Gerhartf58c44e2011-12-13 13:19:58 -0500378 break;
379 case 3: /* fan speed */
380 fanmode |= (1 << F75387_FAN_MANU_MODE(nr));
381 break;
Nikolaus Schulzb17d6562012-02-28 16:15:53 -0500382 case 4: /* Automatic, pwm */
383 fanmode |= (1 << F75387_FAN_DUTY_MODE(nr));
384 break;
Björn Gerhartf58c44e2011-12-13 13:19:58 -0500385 }
386 } else {
387 /* clear each fanX_mode bit before setting them properly */
388 fanmode &= ~(3 << FAN_CTRL_MODE(nr));
389 switch (val) {
390 case 0: /* full speed */
391 fanmode |= (3 << FAN_CTRL_MODE(nr));
392 data->pwm[nr] = 255;
Björn Gerhartf58c44e2011-12-13 13:19:58 -0500393 break;
394 case 1: /* PWM */
395 fanmode |= (3 << FAN_CTRL_MODE(nr));
396 break;
397 case 2: /* AUTOMATIC*/
Nikolaus Schulz09e87e52012-02-08 18:56:08 +0100398 fanmode |= (1 << FAN_CTRL_MODE(nr));
Björn Gerhartf58c44e2011-12-13 13:19:58 -0500399 break;
400 case 3: /* fan speed */
401 break;
Nikolaus Schulzb17d6562012-02-28 16:15:53 -0500402 case 4: /* Automatic pwm */
403 return -EINVAL;
Björn Gerhartf58c44e2011-12-13 13:19:58 -0500404 }
Riku Voipio84f1e442007-08-24 13:03:09 +0300405 }
Björn Gerhartf58c44e2011-12-13 13:19:58 -0500406
Riku Voipio84f1e442007-08-24 13:03:09 +0300407 f75375_write8(client, F75375_REG_FAN_TIMER, fanmode);
408 data->pwm_enable[nr] = val;
Nikolaus Schulzc1c1a3d2012-02-22 23:18:44 +0100409 if (val == 0)
Nikolaus Schulz331255d2012-02-28 22:15:51 +0100410 f75375_write_pwm(client, nr);
Riku Voipioff312d02007-09-26 13:14:40 +0300411 return 0;
412}
413
414static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr,
415 const char *buf, size_t count)
416{
417 int nr = to_sensor_dev_attr(attr)->index;
418 struct i2c_client *client = to_i2c_client(dev);
419 struct f75375_data *data = i2c_get_clientdata(client);
Guenter Roeck4fd826e2011-12-08 09:54:18 -0800420 unsigned long val;
421 int err;
422
423 err = kstrtoul(buf, 10, &val);
424 if (err < 0)
425 return err;
Riku Voipioff312d02007-09-26 13:14:40 +0300426
427 mutex_lock(&data->update_lock);
428 err = set_pwm_enable_direct(client, nr, val);
Riku Voipio84f1e442007-08-24 13:03:09 +0300429 mutex_unlock(&data->update_lock);
Riku Voipioff312d02007-09-26 13:14:40 +0300430 return err ? err : count;
Riku Voipio84f1e442007-08-24 13:03:09 +0300431}
432
433static ssize_t set_pwm_mode(struct device *dev, struct device_attribute *attr,
434 const char *buf, size_t count)
435{
436 int nr = to_sensor_dev_attr(attr)->index;
437 struct i2c_client *client = to_i2c_client(dev);
438 struct f75375_data *data = i2c_get_clientdata(client);
Guenter Roeck4fd826e2011-12-08 09:54:18 -0800439 unsigned long val;
440 int err;
441 u8 conf;
Björn Gerhartf58c44e2011-12-13 13:19:58 -0500442 char reg, ctrl;
Guenter Roeck4fd826e2011-12-08 09:54:18 -0800443
444 err = kstrtoul(buf, 10, &val);
445 if (err < 0)
446 return err;
Riku Voipio84f1e442007-08-24 13:03:09 +0300447
Riku Voipio76e83be2007-10-26 14:14:23 +0300448 if (!(val == 0 || val == 1))
Riku Voipio84f1e442007-08-24 13:03:09 +0300449 return -EINVAL;
450
Guenter Roeck5cd32222011-12-08 10:55:16 -0800451 /* F75373 does not support DC (linear voltage) fan control mode */
452 if (data->kind == f75373 && val == 0)
453 return -EINVAL;
454
Björn Gerhartf58c44e2011-12-13 13:19:58 -0500455 /* take care for different registers */
456 if (data->kind == f75387) {
457 reg = F75375_REG_FAN_TIMER;
458 ctrl = F75387_FAN_CTRL_LINEAR(nr);
459 } else {
460 reg = F75375_REG_CONFIG1;
461 ctrl = F75375_FAN_CTRL_LINEAR(nr);
462 }
463
Riku Voipio84f1e442007-08-24 13:03:09 +0300464 mutex_lock(&data->update_lock);
Björn Gerhartf58c44e2011-12-13 13:19:58 -0500465 conf = f75375_read8(client, reg);
466 conf &= ~(1 << ctrl);
Riku Voipio84f1e442007-08-24 13:03:09 +0300467
468 if (val == 0)
Björn Gerhartf58c44e2011-12-13 13:19:58 -0500469 conf |= (1 << ctrl);
Riku Voipio84f1e442007-08-24 13:03:09 +0300470
Björn Gerhartf58c44e2011-12-13 13:19:58 -0500471 f75375_write8(client, reg, conf);
Riku Voipio84f1e442007-08-24 13:03:09 +0300472 data->pwm_mode[nr] = val;
473 mutex_unlock(&data->update_lock);
474 return count;
475}
476
477static ssize_t show_pwm(struct device *dev, struct device_attribute
478 *attr, char *buf)
479{
480 int nr = to_sensor_dev_attr(attr)->index;
481 struct f75375_data *data = f75375_update_device(dev);
482 return sprintf(buf, "%d\n", data->pwm[nr]);
483}
484
485static ssize_t show_pwm_mode(struct device *dev, struct device_attribute
486 *attr, char *buf)
487{
488 int nr = to_sensor_dev_attr(attr)->index;
489 struct f75375_data *data = f75375_update_device(dev);
490 return sprintf(buf, "%d\n", data->pwm_mode[nr]);
491}
492
493#define VOLT_FROM_REG(val) ((val) * 8)
494#define VOLT_TO_REG(val) ((val) / 8)
495
496static ssize_t show_in(struct device *dev, struct device_attribute *attr,
497 char *buf)
498{
499 int nr = to_sensor_dev_attr(attr)->index;
500 struct f75375_data *data = f75375_update_device(dev);
501 return sprintf(buf, "%d\n", VOLT_FROM_REG(data->in[nr]));
502}
503
504static ssize_t show_in_max(struct device *dev, struct device_attribute *attr,
505 char *buf)
506{
507 int nr = to_sensor_dev_attr(attr)->index;
508 struct f75375_data *data = f75375_update_device(dev);
509 return sprintf(buf, "%d\n", VOLT_FROM_REG(data->in_max[nr]));
510}
511
512static ssize_t show_in_min(struct device *dev, struct device_attribute *attr,
513 char *buf)
514{
515 int nr = to_sensor_dev_attr(attr)->index;
516 struct f75375_data *data = f75375_update_device(dev);
517 return sprintf(buf, "%d\n", VOLT_FROM_REG(data->in_min[nr]));
518}
519
520static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
521 const char *buf, size_t count)
522{
523 int nr = to_sensor_dev_attr(attr)->index;
524 struct i2c_client *client = to_i2c_client(dev);
525 struct f75375_data *data = i2c_get_clientdata(client);
Guenter Roeck4fd826e2011-12-08 09:54:18 -0800526 unsigned long val;
527 int err;
528
529 err = kstrtoul(buf, 10, &val);
530 if (err < 0)
531 return err;
532
Riku Voipio84f1e442007-08-24 13:03:09 +0300533 val = SENSORS_LIMIT(VOLT_TO_REG(val), 0, 0xff);
534 mutex_lock(&data->update_lock);
535 data->in_max[nr] = val;
536 f75375_write8(client, F75375_REG_VOLT_HIGH(nr), data->in_max[nr]);
537 mutex_unlock(&data->update_lock);
538 return count;
539}
540
541static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
542 const char *buf, size_t count)
543{
544 int nr = to_sensor_dev_attr(attr)->index;
545 struct i2c_client *client = to_i2c_client(dev);
546 struct f75375_data *data = i2c_get_clientdata(client);
Guenter Roeck4fd826e2011-12-08 09:54:18 -0800547 unsigned long val;
548 int err;
549
550 err = kstrtoul(buf, 10, &val);
551 if (err < 0)
552 return err;
553
Riku Voipio84f1e442007-08-24 13:03:09 +0300554 val = SENSORS_LIMIT(VOLT_TO_REG(val), 0, 0xff);
555 mutex_lock(&data->update_lock);
556 data->in_min[nr] = val;
557 f75375_write8(client, F75375_REG_VOLT_LOW(nr), data->in_min[nr]);
558 mutex_unlock(&data->update_lock);
559 return count;
560}
561#define TEMP_FROM_REG(val) ((val) * 1000)
562#define TEMP_TO_REG(val) ((val) / 1000)
Björn Gerhartf58c44e2011-12-13 13:19:58 -0500563#define TEMP11_FROM_REG(reg) ((reg) / 32 * 125)
Riku Voipio84f1e442007-08-24 13:03:09 +0300564
Björn Gerhartf58c44e2011-12-13 13:19:58 -0500565static ssize_t show_temp11(struct device *dev, struct device_attribute *attr,
Riku Voipio84f1e442007-08-24 13:03:09 +0300566 char *buf)
567{
568 int nr = to_sensor_dev_attr(attr)->index;
569 struct f75375_data *data = f75375_update_device(dev);
Björn Gerhartf58c44e2011-12-13 13:19:58 -0500570 return sprintf(buf, "%d\n", TEMP11_FROM_REG(data->temp11[nr]));
Riku Voipio84f1e442007-08-24 13:03:09 +0300571}
572
573static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr,
574 char *buf)
575{
576 int nr = to_sensor_dev_attr(attr)->index;
577 struct f75375_data *data = f75375_update_device(dev);
578 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_high[nr]));
579}
580
581static ssize_t show_temp_max_hyst(struct device *dev,
582 struct device_attribute *attr, char *buf)
583{
584 int nr = to_sensor_dev_attr(attr)->index;
585 struct f75375_data *data = f75375_update_device(dev);
586 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max_hyst[nr]));
587}
588
589static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
590 const char *buf, size_t count)
591{
592 int nr = to_sensor_dev_attr(attr)->index;
593 struct i2c_client *client = to_i2c_client(dev);
594 struct f75375_data *data = i2c_get_clientdata(client);
Guenter Roeck4fd826e2011-12-08 09:54:18 -0800595 unsigned long val;
596 int err;
597
598 err = kstrtoul(buf, 10, &val);
599 if (err < 0)
600 return err;
601
Riku Voipio84f1e442007-08-24 13:03:09 +0300602 val = SENSORS_LIMIT(TEMP_TO_REG(val), 0, 127);
603 mutex_lock(&data->update_lock);
604 data->temp_high[nr] = val;
605 f75375_write8(client, F75375_REG_TEMP_HIGH(nr), data->temp_high[nr]);
606 mutex_unlock(&data->update_lock);
607 return count;
608}
609
610static ssize_t set_temp_max_hyst(struct device *dev,
611 struct device_attribute *attr, const char *buf, size_t count)
612{
613 int nr = to_sensor_dev_attr(attr)->index;
614 struct i2c_client *client = to_i2c_client(dev);
615 struct f75375_data *data = i2c_get_clientdata(client);
Guenter Roeck4fd826e2011-12-08 09:54:18 -0800616 unsigned long val;
617 int err;
618
619 err = kstrtoul(buf, 10, &val);
620 if (err < 0)
621 return err;
622
Riku Voipio84f1e442007-08-24 13:03:09 +0300623 val = SENSORS_LIMIT(TEMP_TO_REG(val), 0, 127);
624 mutex_lock(&data->update_lock);
625 data->temp_max_hyst[nr] = val;
626 f75375_write8(client, F75375_REG_TEMP_HYST(nr),
627 data->temp_max_hyst[nr]);
628 mutex_unlock(&data->update_lock);
629 return count;
630}
631
632#define show_fan(thing) \
633static ssize_t show_##thing(struct device *dev, struct device_attribute *attr, \
634 char *buf)\
635{\
636 int nr = to_sensor_dev_attr(attr)->index;\
637 struct f75375_data *data = f75375_update_device(dev); \
638 return sprintf(buf, "%d\n", rpm_from_reg(data->thing[nr])); \
639}
640
641show_fan(fan);
642show_fan(fan_min);
Guenter Roeck740f6be32011-12-08 09:59:25 -0800643show_fan(fan_max);
644show_fan(fan_target);
Riku Voipio84f1e442007-08-24 13:03:09 +0300645
646static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, show_in, NULL, 0);
647static SENSOR_DEVICE_ATTR(in0_max, S_IRUGO|S_IWUSR,
648 show_in_max, set_in_max, 0);
649static SENSOR_DEVICE_ATTR(in0_min, S_IRUGO|S_IWUSR,
650 show_in_min, set_in_min, 0);
651static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_in, NULL, 1);
652static SENSOR_DEVICE_ATTR(in1_max, S_IRUGO|S_IWUSR,
653 show_in_max, set_in_max, 1);
654static SENSOR_DEVICE_ATTR(in1_min, S_IRUGO|S_IWUSR,
655 show_in_min, set_in_min, 1);
656static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_in, NULL, 2);
657static SENSOR_DEVICE_ATTR(in2_max, S_IRUGO|S_IWUSR,
658 show_in_max, set_in_max, 2);
659static SENSOR_DEVICE_ATTR(in2_min, S_IRUGO|S_IWUSR,
660 show_in_min, set_in_min, 2);
661static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_in, NULL, 3);
662static SENSOR_DEVICE_ATTR(in3_max, S_IRUGO|S_IWUSR,
663 show_in_max, set_in_max, 3);
664static SENSOR_DEVICE_ATTR(in3_min, S_IRUGO|S_IWUSR,
665 show_in_min, set_in_min, 3);
Björn Gerhartf58c44e2011-12-13 13:19:58 -0500666static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp11, NULL, 0);
Riku Voipio84f1e442007-08-24 13:03:09 +0300667static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IRUGO|S_IWUSR,
668 show_temp_max_hyst, set_temp_max_hyst, 0);
669static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO|S_IWUSR,
670 show_temp_max, set_temp_max, 0);
Björn Gerhartf58c44e2011-12-13 13:19:58 -0500671static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp11, NULL, 1);
Riku Voipio84f1e442007-08-24 13:03:09 +0300672static SENSOR_DEVICE_ATTR(temp2_max_hyst, S_IRUGO|S_IWUSR,
673 show_temp_max_hyst, set_temp_max_hyst, 1);
674static SENSOR_DEVICE_ATTR(temp2_max, S_IRUGO|S_IWUSR,
675 show_temp_max, set_temp_max, 1);
676static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0);
Guenter Roeck740f6be32011-12-08 09:59:25 -0800677static SENSOR_DEVICE_ATTR(fan1_max, S_IRUGO, show_fan_max, NULL, 0);
Riku Voipio84f1e442007-08-24 13:03:09 +0300678static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO|S_IWUSR,
679 show_fan_min, set_fan_min, 0);
Guenter Roeck740f6be32011-12-08 09:59:25 -0800680static SENSOR_DEVICE_ATTR(fan1_target, S_IRUGO|S_IWUSR,
681 show_fan_target, set_fan_target, 0);
Riku Voipio84f1e442007-08-24 13:03:09 +0300682static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1);
Guenter Roeck740f6be32011-12-08 09:59:25 -0800683static SENSOR_DEVICE_ATTR(fan2_max, S_IRUGO, show_fan_max, NULL, 1);
Riku Voipio84f1e442007-08-24 13:03:09 +0300684static SENSOR_DEVICE_ATTR(fan2_min, S_IRUGO|S_IWUSR,
685 show_fan_min, set_fan_min, 1);
Guenter Roeck740f6be32011-12-08 09:59:25 -0800686static SENSOR_DEVICE_ATTR(fan2_target, S_IRUGO|S_IWUSR,
687 show_fan_target, set_fan_target, 1);
Riku Voipio84f1e442007-08-24 13:03:09 +0300688static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO|S_IWUSR,
689 show_pwm, set_pwm, 0);
690static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO|S_IWUSR,
691 show_pwm_enable, set_pwm_enable, 0);
Riku Voipio76e83be2007-10-26 14:14:23 +0300692static SENSOR_DEVICE_ATTR(pwm1_mode, S_IRUGO,
Riku Voipio84f1e442007-08-24 13:03:09 +0300693 show_pwm_mode, set_pwm_mode, 0);
694static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR,
695 show_pwm, set_pwm, 1);
696static SENSOR_DEVICE_ATTR(pwm2_enable, S_IRUGO|S_IWUSR,
697 show_pwm_enable, set_pwm_enable, 1);
Riku Voipio76e83be2007-10-26 14:14:23 +0300698static SENSOR_DEVICE_ATTR(pwm2_mode, S_IRUGO,
Riku Voipio84f1e442007-08-24 13:03:09 +0300699 show_pwm_mode, set_pwm_mode, 1);
700
701static struct attribute *f75375_attributes[] = {
702 &sensor_dev_attr_temp1_input.dev_attr.attr,
703 &sensor_dev_attr_temp1_max.dev_attr.attr,
704 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
705 &sensor_dev_attr_temp2_input.dev_attr.attr,
706 &sensor_dev_attr_temp2_max.dev_attr.attr,
707 &sensor_dev_attr_temp2_max_hyst.dev_attr.attr,
708 &sensor_dev_attr_fan1_input.dev_attr.attr,
Guenter Roeck740f6be32011-12-08 09:59:25 -0800709 &sensor_dev_attr_fan1_max.dev_attr.attr,
Riku Voipio84f1e442007-08-24 13:03:09 +0300710 &sensor_dev_attr_fan1_min.dev_attr.attr,
Guenter Roeck740f6be32011-12-08 09:59:25 -0800711 &sensor_dev_attr_fan1_target.dev_attr.attr,
Riku Voipio84f1e442007-08-24 13:03:09 +0300712 &sensor_dev_attr_fan2_input.dev_attr.attr,
Guenter Roeck740f6be32011-12-08 09:59:25 -0800713 &sensor_dev_attr_fan2_max.dev_attr.attr,
Riku Voipio84f1e442007-08-24 13:03:09 +0300714 &sensor_dev_attr_fan2_min.dev_attr.attr,
Guenter Roeck740f6be32011-12-08 09:59:25 -0800715 &sensor_dev_attr_fan2_target.dev_attr.attr,
Riku Voipio84f1e442007-08-24 13:03:09 +0300716 &sensor_dev_attr_pwm1.dev_attr.attr,
717 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
718 &sensor_dev_attr_pwm1_mode.dev_attr.attr,
719 &sensor_dev_attr_pwm2.dev_attr.attr,
720 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
721 &sensor_dev_attr_pwm2_mode.dev_attr.attr,
722 &sensor_dev_attr_in0_input.dev_attr.attr,
723 &sensor_dev_attr_in0_max.dev_attr.attr,
724 &sensor_dev_attr_in0_min.dev_attr.attr,
725 &sensor_dev_attr_in1_input.dev_attr.attr,
726 &sensor_dev_attr_in1_max.dev_attr.attr,
727 &sensor_dev_attr_in1_min.dev_attr.attr,
728 &sensor_dev_attr_in2_input.dev_attr.attr,
729 &sensor_dev_attr_in2_max.dev_attr.attr,
730 &sensor_dev_attr_in2_min.dev_attr.attr,
731 &sensor_dev_attr_in3_input.dev_attr.attr,
732 &sensor_dev_attr_in3_max.dev_attr.attr,
733 &sensor_dev_attr_in3_min.dev_attr.attr,
734 NULL
735};
736
737static const struct attribute_group f75375_group = {
738 .attrs = f75375_attributes,
739};
740
Riku Voipioff312d02007-09-26 13:14:40 +0300741static void f75375_init(struct i2c_client *client, struct f75375_data *data,
742 struct f75375s_platform_data *f75375s_pdata)
743{
744 int nr;
Guenter Roeckb1b561a2011-12-08 10:15:51 -0800745
746 if (!f75375s_pdata) {
747 u8 conf, mode;
748 int nr;
749
750 conf = f75375_read8(client, F75375_REG_CONFIG1);
751 mode = f75375_read8(client, F75375_REG_FAN_TIMER);
752 for (nr = 0; nr < 2; nr++) {
Björn Gerhartf58c44e2011-12-13 13:19:58 -0500753 if (data->kind == f75387) {
754 bool manu, duty;
755
Nikolaus Schulza367a1e2012-02-08 18:56:09 +0100756 if (!(mode & (1 << F75387_FAN_CTRL_LINEAR(nr))))
Björn Gerhartf58c44e2011-12-13 13:19:58 -0500757 data->pwm_mode[nr] = 1;
758
759 manu = ((mode >> F75387_FAN_MANU_MODE(nr)) & 1);
760 duty = ((mode >> F75387_FAN_DUTY_MODE(nr)) & 1);
Nikolaus Schulzb17d6562012-02-28 16:15:53 -0500761 if (!manu && duty)
762 /* auto, pwm */
763 data->pwm_enable[nr] = 4;
764 else if (manu && !duty)
765 /* manual, speed */
Björn Gerhartf58c44e2011-12-13 13:19:58 -0500766 data->pwm_enable[nr] = 3;
Nikolaus Schulzb17d6562012-02-28 16:15:53 -0500767 else if (!manu && !duty)
768 /* automatic, speed */
Björn Gerhartf58c44e2011-12-13 13:19:58 -0500769 data->pwm_enable[nr] = 2;
770 else
Nikolaus Schulzb17d6562012-02-28 16:15:53 -0500771 /* manual, pwm */
Björn Gerhartf58c44e2011-12-13 13:19:58 -0500772 data->pwm_enable[nr] = 1;
773 } else {
774 if (!(conf & (1 << F75375_FAN_CTRL_LINEAR(nr))))
775 data->pwm_mode[nr] = 1;
776
777 switch ((mode >> FAN_CTRL_MODE(nr)) & 3) {
778 case 0: /* speed */
779 data->pwm_enable[nr] = 3;
780 break;
781 case 1: /* automatic */
782 data->pwm_enable[nr] = 2;
783 break;
784 default: /* manual */
785 data->pwm_enable[nr] = 1;
786 break;
787 }
Guenter Roeckb1b561a2011-12-08 10:15:51 -0800788 }
789 }
790 return;
791 }
792
Riku Voipioff312d02007-09-26 13:14:40 +0300793 set_pwm_enable_direct(client, 0, f75375s_pdata->pwm_enable[0]);
794 set_pwm_enable_direct(client, 1, f75375s_pdata->pwm_enable[1]);
795 for (nr = 0; nr < 2; nr++) {
796 data->pwm[nr] = SENSORS_LIMIT(f75375s_pdata->pwm[nr], 0, 255);
Nikolaus Schulz331255d2012-02-28 22:15:51 +0100797 f75375_write_pwm(client, nr);
Riku Voipioff312d02007-09-26 13:14:40 +0300798 }
799
800}
801
Jean Delvared2653e92008-04-29 23:11:39 +0200802static int f75375_probe(struct i2c_client *client,
803 const struct i2c_device_id *id)
Riku Voipio620c1422007-10-16 12:46:49 +0300804{
Andrew Klossner51b3e272009-03-12 13:36:39 +0100805 struct f75375_data *data;
Riku Voipioff312d02007-09-26 13:14:40 +0300806 struct f75375s_platform_data *f75375s_pdata = client->dev.platform_data;
Riku Voipio620c1422007-10-16 12:46:49 +0300807 int err;
808
809 if (!i2c_check_functionality(client->adapter,
810 I2C_FUNC_SMBUS_BYTE_DATA))
811 return -EIO;
Guenter Roeck4fd826e2011-12-08 09:54:18 -0800812 data = kzalloc(sizeof(struct f75375_data), GFP_KERNEL);
813 if (!data)
Riku Voipio620c1422007-10-16 12:46:49 +0300814 return -ENOMEM;
815
816 i2c_set_clientdata(client, data);
Riku Voipio620c1422007-10-16 12:46:49 +0300817 mutex_init(&data->update_lock);
Jean Delvare3760f732008-04-29 23:11:40 +0200818 data->kind = id->driver_data;
Riku Voipio620c1422007-10-16 12:46:49 +0300819
Guenter Roeck4fd826e2011-12-08 09:54:18 -0800820 err = sysfs_create_group(&client->dev.kobj, &f75375_group);
821 if (err)
Riku Voipio620c1422007-10-16 12:46:49 +0300822 goto exit_free;
823
Nikolaus Schulzedeea102012-02-28 22:15:52 +0100824 if (data->kind != f75373) {
Riku Voipio76e83be2007-10-26 14:14:23 +0300825 err = sysfs_chmod_file(&client->dev.kobj,
826 &sensor_dev_attr_pwm1_mode.dev_attr.attr,
827 S_IRUGO | S_IWUSR);
828 if (err)
829 goto exit_remove;
830 err = sysfs_chmod_file(&client->dev.kobj,
831 &sensor_dev_attr_pwm2_mode.dev_attr.attr,
832 S_IRUGO | S_IWUSR);
833 if (err)
834 goto exit_remove;
835 }
836
Riku Voipio620c1422007-10-16 12:46:49 +0300837 data->hwmon_dev = hwmon_device_register(&client->dev);
838 if (IS_ERR(data->hwmon_dev)) {
839 err = PTR_ERR(data->hwmon_dev);
840 goto exit_remove;
841 }
842
Guenter Roeckb1b561a2011-12-08 10:15:51 -0800843 f75375_init(client, data, f75375s_pdata);
Riku Voipioff312d02007-09-26 13:14:40 +0300844
Riku Voipio620c1422007-10-16 12:46:49 +0300845 return 0;
846
847exit_remove:
848 sysfs_remove_group(&client->dev.kobj, &f75375_group);
849exit_free:
Riku Voipio84f1e442007-08-24 13:03:09 +0300850 kfree(data);
Riku Voipio620c1422007-10-16 12:46:49 +0300851 return err;
852}
853
854static int f75375_remove(struct i2c_client *client)
855{
856 struct f75375_data *data = i2c_get_clientdata(client);
857 hwmon_device_unregister(data->hwmon_dev);
858 sysfs_remove_group(&client->dev.kobj, &f75375_group);
859 kfree(data);
Riku Voipio84f1e442007-08-24 13:03:09 +0300860 return 0;
861}
862
Jean Delvare935ada82008-07-16 19:30:11 +0200863/* Return 0 if detection is successful, -ENODEV otherwise */
Jean Delvare310ec792009-12-14 21:17:23 +0100864static int f75375_detect(struct i2c_client *client,
Jean Delvare935ada82008-07-16 19:30:11 +0200865 struct i2c_board_info *info)
Riku Voipio84f1e442007-08-24 13:03:09 +0300866{
Jean Delvare935ada82008-07-16 19:30:11 +0200867 struct i2c_adapter *adapter = client->adapter;
Jean Delvare52df6442009-12-09 20:35:57 +0100868 u16 vendid, chipid;
869 u8 version;
870 const char *name;
Riku Voipio84f1e442007-08-24 13:03:09 +0300871
Jean Delvare52df6442009-12-09 20:35:57 +0100872 vendid = f75375_read16(client, F75375_REG_VENDOR);
873 chipid = f75375_read16(client, F75375_CHIP_ID);
Björn Gerhartf58c44e2011-12-13 13:19:58 -0500874 if (vendid != 0x1934)
875 return -ENODEV;
876
877 if (chipid == 0x0306)
Riku Voipio84f1e442007-08-24 13:03:09 +0300878 name = "f75375";
Björn Gerhartf58c44e2011-12-13 13:19:58 -0500879 else if (chipid == 0x0204)
Riku Voipio84f1e442007-08-24 13:03:09 +0300880 name = "f75373";
Björn Gerhartf58c44e2011-12-13 13:19:58 -0500881 else if (chipid == 0x0410)
882 name = "f75387";
Jean Delvare52df6442009-12-09 20:35:57 +0100883 else
884 return -ENODEV;
885
886 version = f75375_read8(client, F75375_REG_VERSION);
Riku Voipio84f1e442007-08-24 13:03:09 +0300887 dev_info(&adapter->dev, "found %s version: %02X\n", name, version);
Jean Delvare935ada82008-07-16 19:30:11 +0200888 strlcpy(info->type, name, I2C_NAME_SIZE);
Riku Voipio84f1e442007-08-24 13:03:09 +0300889
Riku Voipio84f1e442007-08-24 13:03:09 +0300890 return 0;
Riku Voipio84f1e442007-08-24 13:03:09 +0300891}
892
893static int __init sensors_f75375_init(void)
894{
Jean Delvare935ada82008-07-16 19:30:11 +0200895 return i2c_add_driver(&f75375_driver);
Riku Voipio84f1e442007-08-24 13:03:09 +0300896}
897
898static void __exit sensors_f75375_exit(void)
899{
Riku Voipio84f1e442007-08-24 13:03:09 +0300900 i2c_del_driver(&f75375_driver);
901}
902
Riku Voipiob26e0ed2009-03-03 21:37:17 +0200903MODULE_AUTHOR("Riku Voipio");
Riku Voipio84f1e442007-08-24 13:03:09 +0300904MODULE_LICENSE("GPL");
Björn Gerhartf58c44e2011-12-13 13:19:58 -0500905MODULE_DESCRIPTION("F75373/F75375/F75387 hardware monitoring driver");
Riku Voipio84f1e442007-08-24 13:03:09 +0300906
907module_init(sensors_f75375_init);
908module_exit(sensors_f75375_exit);