asb100.c 29.8 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
/*
    asb100.c - Part of lm_sensors, Linux kernel modules for hardware
	        monitoring

    Copyright (C) 2004 Mark M. Hoffman <mhoffman@lightlink.com>

	(derived from w83781d.c)

    Copyright (C) 1998 - 2003  Frodo Looijaard <frodol@dds.nl>,
    Philip Edelbrock <phil@netroedge.com>, and
    Mark Studebaker <mdsxyz123@yahoo.com>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

/*
    This driver supports the hardware sensor chips: Asus ASB100 and
    ASB100-A "BACH".

    ASB100-A supports pwm1, while plain ASB100 does not.  There is no known
    way for the driver to tell which one is there.

    Chip	#vin	#fanin	#pwm	#temp	wchipid	vendid	i2c	ISA
    asb100	7	3	1	4	0x31	0x0694	yes	no
*/

#include <linux/module.h>
#include <linux/slab.h>
#include <linux/i2c.h>
42
#include <linux/hwmon.h>
43
#include <linux/hwmon-sysfs.h>
44
#include <linux/hwmon-vid.h>
45
#include <linux/err.h>
L
Linus Torvalds 已提交
46
#include <linux/init.h>
47
#include <linux/jiffies.h>
48
#include <linux/mutex.h>
L
Linus Torvalds 已提交
49 50 51 52 53 54
#include "lm75.h"

/* I2C addresses to scan */
static unsigned short normal_i2c[] = { 0x2d, I2C_CLIENT_END };

/* Insmod parameters */
55
I2C_CLIENT_INSMOD_1(asb100);
L
Linus Torvalds 已提交
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
I2C_CLIENT_MODULE_PARM(force_subclients, "List of subclient addresses: "
	"{bus, clientaddr, subclientaddr1, subclientaddr2}");

/* Voltage IN registers 0-6 */
#define ASB100_REG_IN(nr)	(0x20 + (nr))
#define ASB100_REG_IN_MAX(nr)	(0x2b + (nr * 2))
#define ASB100_REG_IN_MIN(nr)	(0x2c + (nr * 2))

/* FAN IN registers 1-3 */
#define ASB100_REG_FAN(nr)	(0x28 + (nr))
#define ASB100_REG_FAN_MIN(nr)	(0x3b + (nr))

/* TEMPERATURE registers 1-4 */
static const u16 asb100_reg_temp[]	= {0, 0x27, 0x150, 0x250, 0x17};
static const u16 asb100_reg_temp_max[]	= {0, 0x39, 0x155, 0x255, 0x18};
static const u16 asb100_reg_temp_hyst[]	= {0, 0x3a, 0x153, 0x253, 0x19};

#define ASB100_REG_TEMP(nr) (asb100_reg_temp[nr])
#define ASB100_REG_TEMP_MAX(nr) (asb100_reg_temp_max[nr])
#define ASB100_REG_TEMP_HYST(nr) (asb100_reg_temp_hyst[nr])

#define ASB100_REG_TEMP2_CONFIG	0x0152
#define ASB100_REG_TEMP3_CONFIG	0x0252


#define ASB100_REG_CONFIG	0x40
#define ASB100_REG_ALARM1	0x41
#define ASB100_REG_ALARM2	0x42
#define ASB100_REG_SMIM1	0x43
#define ASB100_REG_SMIM2	0x44
#define ASB100_REG_VID_FANDIV	0x47
#define ASB100_REG_I2C_ADDR	0x48
#define ASB100_REG_CHIPID	0x49
#define ASB100_REG_I2C_SUBADDR	0x4a
#define ASB100_REG_PIN		0x4b
#define ASB100_REG_IRQ		0x4c
#define ASB100_REG_BANK		0x4e
#define ASB100_REG_CHIPMAN	0x4f

#define ASB100_REG_WCHIPID	0x58

/* bit 7 -> enable, bits 0-3 -> duty cycle */
#define ASB100_REG_PWM1		0x59

/* CONVERSIONS
   Rounding and limit checking is only done on the TO_REG variants. */

/* These constants are a guess, consistent w/ w83781d */
#define ASB100_IN_MIN (   0)
#define ASB100_IN_MAX (4080)

/* IN: 1/1000 V (0V to 4.08V)
   REG: 16mV/bit */
static u8 IN_TO_REG(unsigned val)
{
	unsigned nval = SENSORS_LIMIT(val, ASB100_IN_MIN, ASB100_IN_MAX);
	return (nval + 8) / 16;
}

static unsigned IN_FROM_REG(u8 reg)
{
	return reg * 16;
}

static u8 FAN_TO_REG(long rpm, int div)
{
	if (rpm == -1)
		return 0;
	if (rpm == 0)
		return 255;
	rpm = SENSORS_LIMIT(rpm, 1, 1000000);
	return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
}

static int FAN_FROM_REG(u8 val, int div)
{
	return val==0 ? -1 : val==255 ? 0 : 1350000/(val*div);
}

/* These constants are a guess, consistent w/ w83781d */
#define ASB100_TEMP_MIN (-128000)
#define ASB100_TEMP_MAX ( 127000)

/* TEMP: 0.001C/bit (-128C to +127C)
   REG: 1C/bit, two's complement */
141
static u8 TEMP_TO_REG(long temp)
L
Linus Torvalds 已提交
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
{
	int ntemp = SENSORS_LIMIT(temp, ASB100_TEMP_MIN, ASB100_TEMP_MAX);
	ntemp += (ntemp<0 ? -500 : 500);
	return (u8)(ntemp / 1000);
}

static int TEMP_FROM_REG(u8 reg)
{
	return (s8)reg * 1000;
}

/* PWM: 0 - 255 per sensors documentation
   REG: (6.25% duty cycle per bit) */
static u8 ASB100_PWM_TO_REG(int pwm)
{
	pwm = SENSORS_LIMIT(pwm, 0, 255);
	return (u8)(pwm / 16);
}

static int ASB100_PWM_FROM_REG(u8 reg)
{
	return reg * 16;
}

#define DIV_FROM_REG(val) (1 << (val))

/* FAN DIV: 1, 2, 4, or 8 (defaults to 2)
   REG: 0, 1, 2, or 3 (respectively) (defaults to 1) */
static u8 DIV_TO_REG(long val)
{
	return val==8 ? 3 : val==4 ? 2 : val==1 ? 0 : 1;
}

/* For each registered client, we need to keep some data in memory. That
   data is pointed to by client->data. The structure itself is
   dynamically allocated, at the same time the client itself is allocated. */
struct asb100_data {
	struct i2c_client client;
180
	struct device *hwmon_dev;
181
	struct mutex lock;
L
Linus Torvalds 已提交
182 183
	enum chips type;

184
	struct mutex update_lock;
L
Linus Torvalds 已提交
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
	unsigned long last_updated;	/* In jiffies */

	/* array of 2 pointers to subclients */
	struct i2c_client *lm75[2];

	char valid;		/* !=0 if following fields are valid */
	u8 in[7];		/* Register value */
	u8 in_max[7];		/* Register value */
	u8 in_min[7];		/* Register value */
	u8 fan[3];		/* Register value */
	u8 fan_min[3];		/* Register value */
	u16 temp[4];		/* Register value (0 and 3 are u8 only) */
	u16 temp_max[4];	/* Register value (0 and 3 are u8 only) */
	u16 temp_hyst[4];	/* Register value (0 and 3 are u8 only) */
	u8 fan_div[3];		/* Register encoding, right justified */
	u8 pwm;			/* Register encoding */
	u8 vid;			/* Register encoding, combined */
	u32 alarms;		/* Register encoding, combined */
	u8 vrm;
};

static int asb100_read_value(struct i2c_client *client, u16 reg);
static void asb100_write_value(struct i2c_client *client, u16 reg, u16 val);

static int asb100_attach_adapter(struct i2c_adapter *adapter);
static int asb100_detect(struct i2c_adapter *adapter, int address, int kind);
static int asb100_detach_client(struct i2c_client *client);
static struct asb100_data *asb100_update_device(struct device *dev);
static void asb100_init_client(struct i2c_client *client);

static struct i2c_driver asb100_driver = {
216 217 218
	.driver = {
		.name	= "asb100",
	},
L
Linus Torvalds 已提交
219 220 221 222 223 224
	.attach_adapter	= asb100_attach_adapter,
	.detach_client	= asb100_detach_client,
};

/* 7 Voltages */
#define show_in_reg(reg) \
225 226
static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
		char *buf) \
L
Linus Torvalds 已提交
227
{ \
228
	int nr = to_sensor_dev_attr(attr)->index; \
L
Linus Torvalds 已提交
229 230 231 232 233 234 235 236 237
	struct asb100_data *data = asb100_update_device(dev); \
	return sprintf(buf, "%d\n", IN_FROM_REG(data->reg[nr])); \
}

show_in_reg(in)
show_in_reg(in_min)
show_in_reg(in_max)

#define set_in_reg(REG, reg) \
238 239
static ssize_t set_in_##reg(struct device *dev, struct device_attribute *attr, \
		const char *buf, size_t count) \
L
Linus Torvalds 已提交
240
{ \
241
	int nr = to_sensor_dev_attr(attr)->index; \
L
Linus Torvalds 已提交
242 243 244 245
	struct i2c_client *client = to_i2c_client(dev); \
	struct asb100_data *data = i2c_get_clientdata(client); \
	unsigned long val = simple_strtoul(buf, NULL, 10); \
 \
246
	mutex_lock(&data->update_lock); \
L
Linus Torvalds 已提交
247 248 249
	data->in_##reg[nr] = IN_TO_REG(val); \
	asb100_write_value(client, ASB100_REG_IN_##REG(nr), \
		data->in_##reg[nr]); \
250
	mutex_unlock(&data->update_lock); \
L
Linus Torvalds 已提交
251 252 253 254 255 256 257
	return count; \
}

set_in_reg(MIN, min)
set_in_reg(MAX, max)

#define sysfs_in(offset) \
258 259 260 261 262 263
static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
		show_in, NULL, offset); \
static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
		show_in_min, set_in_min, offset); \
static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
		show_in_max, set_in_max, offset)
L
Linus Torvalds 已提交
264 265 266 267 268 269 270 271 272 273

sysfs_in(0);
sysfs_in(1);
sysfs_in(2);
sysfs_in(3);
sysfs_in(4);
sysfs_in(5);
sysfs_in(6);

/* 3 Fans */
274 275
static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
		char *buf)
L
Linus Torvalds 已提交
276
{
277
	int nr = to_sensor_dev_attr(attr)->index;
L
Linus Torvalds 已提交
278 279 280 281 282
	struct asb100_data *data = asb100_update_device(dev);
	return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
		DIV_FROM_REG(data->fan_div[nr])));
}

283 284
static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
		char *buf)
L
Linus Torvalds 已提交
285
{
286
	int nr = to_sensor_dev_attr(attr)->index;
L
Linus Torvalds 已提交
287 288 289 290 291
	struct asb100_data *data = asb100_update_device(dev);
	return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr],
		DIV_FROM_REG(data->fan_div[nr])));
}

292 293
static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
		char *buf)
L
Linus Torvalds 已提交
294
{
295
	int nr = to_sensor_dev_attr(attr)->index;
L
Linus Torvalds 已提交
296 297 298 299
	struct asb100_data *data = asb100_update_device(dev);
	return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
}

300 301
static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
		const char *buf, size_t count)
L
Linus Torvalds 已提交
302
{
303
	int nr = to_sensor_dev_attr(attr)->index;
L
Linus Torvalds 已提交
304 305 306 307
	struct i2c_client *client = to_i2c_client(dev);
	struct asb100_data *data = i2c_get_clientdata(client);
	u32 val = simple_strtoul(buf, NULL, 10);

308
	mutex_lock(&data->update_lock);
L
Linus Torvalds 已提交
309 310
	data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
	asb100_write_value(client, ASB100_REG_FAN_MIN(nr), data->fan_min[nr]);
311
	mutex_unlock(&data->update_lock);
L
Linus Torvalds 已提交
312 313 314 315 316
	return count;
}

/* Note: we save and restore the fan minimum here, because its value is
   determined in part by the fan divisor.  This follows the principle of
A
Andreas Mohr 已提交
317
   least surprise; the user doesn't expect the fan minimum to change just
L
Linus Torvalds 已提交
318
   because the divisor changed. */
319 320
static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
		const char *buf, size_t count)
L
Linus Torvalds 已提交
321
{
322
	int nr = to_sensor_dev_attr(attr)->index;
L
Linus Torvalds 已提交
323 324 325 326 327
	struct i2c_client *client = to_i2c_client(dev);
	struct asb100_data *data = i2c_get_clientdata(client);
	unsigned long min;
	unsigned long val = simple_strtoul(buf, NULL, 10);
	int reg;
J
Jean Delvare 已提交
328

329
	mutex_lock(&data->update_lock);
L
Linus Torvalds 已提交
330 331 332 333 334

	min = FAN_FROM_REG(data->fan_min[nr],
			DIV_FROM_REG(data->fan_div[nr]));
	data->fan_div[nr] = DIV_TO_REG(val);

J
Jean Delvare 已提交
335
	switch (nr) {
L
Linus Torvalds 已提交
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
	case 0:	/* fan 1 */
		reg = asb100_read_value(client, ASB100_REG_VID_FANDIV);
		reg = (reg & 0xcf) | (data->fan_div[0] << 4);
		asb100_write_value(client, ASB100_REG_VID_FANDIV, reg);
		break;

	case 1:	/* fan 2 */
		reg = asb100_read_value(client, ASB100_REG_VID_FANDIV);
		reg = (reg & 0x3f) | (data->fan_div[1] << 6);
		asb100_write_value(client, ASB100_REG_VID_FANDIV, reg);
		break;

	case 2:	/* fan 3 */
		reg = asb100_read_value(client, ASB100_REG_PIN);
		reg = (reg & 0x3f) | (data->fan_div[2] << 6);
		asb100_write_value(client, ASB100_REG_PIN, reg);
		break;
	}

	data->fan_min[nr] =
		FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
	asb100_write_value(client, ASB100_REG_FAN_MIN(nr), data->fan_min[nr]);

359
	mutex_unlock(&data->update_lock);
L
Linus Torvalds 已提交
360 361 362 363 364

	return count;
}

#define sysfs_fan(offset) \
365 366 367 368 369 370
static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
		show_fan, NULL, offset - 1); \
static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
		show_fan_min, set_fan_min, offset - 1); \
static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
		show_fan_div, set_fan_div, offset - 1)
L
Linus Torvalds 已提交
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390

sysfs_fan(1);
sysfs_fan(2);
sysfs_fan(3);

/* 4 Temp. Sensors */
static int sprintf_temp_from_reg(u16 reg, char *buf, int nr)
{
	int ret = 0;

	switch (nr) {
	case 1: case 2:
		ret = sprintf(buf, "%d\n", LM75_TEMP_FROM_REG(reg));
		break;
	case 0: case 3: default:
		ret = sprintf(buf, "%d\n", TEMP_FROM_REG(reg));
		break;
	}
	return ret;
}
J
Jean Delvare 已提交
391

L
Linus Torvalds 已提交
392
#define show_temp_reg(reg) \
393 394
static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
		char *buf) \
L
Linus Torvalds 已提交
395
{ \
396
	int nr = to_sensor_dev_attr(attr)->index; \
L
Linus Torvalds 已提交
397 398 399 400 401 402 403 404 405
	struct asb100_data *data = asb100_update_device(dev); \
	return sprintf_temp_from_reg(data->reg[nr], buf, nr); \
}

show_temp_reg(temp);
show_temp_reg(temp_max);
show_temp_reg(temp_hyst);

#define set_temp_reg(REG, reg) \
406 407
static ssize_t set_##reg(struct device *dev, struct device_attribute *attr, \
		const char *buf, size_t count) \
L
Linus Torvalds 已提交
408
{ \
409
	int nr = to_sensor_dev_attr(attr)->index; \
L
Linus Torvalds 已提交
410 411
	struct i2c_client *client = to_i2c_client(dev); \
	struct asb100_data *data = i2c_get_clientdata(client); \
412
	long val = simple_strtol(buf, NULL, 10); \
L
Linus Torvalds 已提交
413
 \
414
	mutex_lock(&data->update_lock); \
L
Linus Torvalds 已提交
415 416 417 418 419 420 421 422 423 424
	switch (nr) { \
	case 1: case 2: \
		data->reg[nr] = LM75_TEMP_TO_REG(val); \
		break; \
	case 0: case 3: default: \
		data->reg[nr] = TEMP_TO_REG(val); \
		break; \
	} \
	asb100_write_value(client, ASB100_REG_TEMP_##REG(nr+1), \
			data->reg[nr]); \
425
	mutex_unlock(&data->update_lock); \
L
Linus Torvalds 已提交
426 427 428 429 430 431 432
	return count; \
}

set_temp_reg(MAX, temp_max);
set_temp_reg(HYST, temp_hyst);

#define sysfs_temp(num) \
433 434 435 436 437 438
static SENSOR_DEVICE_ATTR(temp##num##_input, S_IRUGO, \
		show_temp, NULL, num - 1); \
static SENSOR_DEVICE_ATTR(temp##num##_max, S_IRUGO | S_IWUSR, \
		show_temp_max, set_temp_max, num - 1); \
static SENSOR_DEVICE_ATTR(temp##num##_max_hyst, S_IRUGO | S_IWUSR, \
		show_temp_hyst, set_temp_hyst, num - 1)
L
Linus Torvalds 已提交
439 440 441 442 443 444 445

sysfs_temp(1);
sysfs_temp(2);
sysfs_temp(3);
sysfs_temp(4);

/* VID */
J
Jean Delvare 已提交
446 447
static ssize_t show_vid(struct device *dev, struct device_attribute *attr,
		char *buf)
L
Linus Torvalds 已提交
448 449 450 451 452 453 454 455
{
	struct asb100_data *data = asb100_update_device(dev);
	return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm));
}

static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);

/* VRM */
J
Jean Delvare 已提交
456 457
static ssize_t show_vrm(struct device *dev, struct device_attribute *attr,
		char *buf)
L
Linus Torvalds 已提交
458
{
459
	struct asb100_data *data = dev_get_drvdata(dev);
L
Linus Torvalds 已提交
460 461 462
	return sprintf(buf, "%d\n", data->vrm);
}

J
Jean Delvare 已提交
463 464
static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
		const char *buf, size_t count)
L
Linus Torvalds 已提交
465
{
466 467
	struct asb100_data *data = dev_get_drvdata(dev);
	data->vrm = simple_strtoul(buf, NULL, 10);
L
Linus Torvalds 已提交
468 469 470 471 472 473
	return count;
}

/* Alarms */
static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);

J
Jean Delvare 已提交
474 475
static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
		char *buf)
L
Linus Torvalds 已提交
476 477
{
	struct asb100_data *data = asb100_update_device(dev);
478
	return sprintf(buf, "%u\n", data->alarms);
L
Linus Torvalds 已提交
479 480 481 482
}

static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);

483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501
static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
		char *buf)
{
	int bitnr = to_sensor_dev_attr(attr)->index;
	struct asb100_data *data = asb100_update_device(dev);
	return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
}
static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8);
static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6);
static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7);
static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 11);
static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4);
static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5);
static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13);

L
Linus Torvalds 已提交
502
/* 1 PWM */
J
Jean Delvare 已提交
503 504
static ssize_t show_pwm1(struct device *dev, struct device_attribute *attr,
		char *buf)
L
Linus Torvalds 已提交
505 506 507 508 509
{
	struct asb100_data *data = asb100_update_device(dev);
	return sprintf(buf, "%d\n", ASB100_PWM_FROM_REG(data->pwm & 0x0f));
}

J
Jean Delvare 已提交
510 511
static ssize_t set_pwm1(struct device *dev, struct device_attribute *attr,
		const char *buf, size_t count)
L
Linus Torvalds 已提交
512 513 514 515 516
{
	struct i2c_client *client = to_i2c_client(dev);
	struct asb100_data *data = i2c_get_clientdata(client);
	unsigned long val = simple_strtoul(buf, NULL, 10);

517
	mutex_lock(&data->update_lock);
L
Linus Torvalds 已提交
518 519 520
	data->pwm &= 0x80; /* keep the enable bit */
	data->pwm |= (0x0f & ASB100_PWM_TO_REG(val));
	asb100_write_value(client, ASB100_REG_PWM1, data->pwm);
521
	mutex_unlock(&data->update_lock);
L
Linus Torvalds 已提交
522 523 524
	return count;
}

J
Jean Delvare 已提交
525 526
static ssize_t show_pwm_enable1(struct device *dev,
		struct device_attribute *attr, char *buf)
L
Linus Torvalds 已提交
527 528 529 530 531
{
	struct asb100_data *data = asb100_update_device(dev);
	return sprintf(buf, "%d\n", (data->pwm & 0x80) ? 1 : 0);
}

J
Jean Delvare 已提交
532 533
static ssize_t set_pwm_enable1(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t count)
L
Linus Torvalds 已提交
534 535 536 537 538
{
	struct i2c_client *client = to_i2c_client(dev);
	struct asb100_data *data = i2c_get_clientdata(client);
	unsigned long val = simple_strtoul(buf, NULL, 10);

539
	mutex_lock(&data->update_lock);
L
Linus Torvalds 已提交
540 541 542
	data->pwm &= 0x0f; /* keep the duty cycle bits */
	data->pwm |= (val ? 0x80 : 0x00);
	asb100_write_value(client, ASB100_REG_PWM1, data->pwm);
543
	mutex_unlock(&data->update_lock);
L
Linus Torvalds 已提交
544 545 546 547 548 549
	return count;
}

static DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm1, set_pwm1);
static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
		show_pwm_enable1, set_pwm_enable1);
550 551

static struct attribute *asb100_attributes[] = {
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595
	&sensor_dev_attr_in0_input.dev_attr.attr,
	&sensor_dev_attr_in0_min.dev_attr.attr,
	&sensor_dev_attr_in0_max.dev_attr.attr,
	&sensor_dev_attr_in1_input.dev_attr.attr,
	&sensor_dev_attr_in1_min.dev_attr.attr,
	&sensor_dev_attr_in1_max.dev_attr.attr,
	&sensor_dev_attr_in2_input.dev_attr.attr,
	&sensor_dev_attr_in2_min.dev_attr.attr,
	&sensor_dev_attr_in2_max.dev_attr.attr,
	&sensor_dev_attr_in3_input.dev_attr.attr,
	&sensor_dev_attr_in3_min.dev_attr.attr,
	&sensor_dev_attr_in3_max.dev_attr.attr,
	&sensor_dev_attr_in4_input.dev_attr.attr,
	&sensor_dev_attr_in4_min.dev_attr.attr,
	&sensor_dev_attr_in4_max.dev_attr.attr,
	&sensor_dev_attr_in5_input.dev_attr.attr,
	&sensor_dev_attr_in5_min.dev_attr.attr,
	&sensor_dev_attr_in5_max.dev_attr.attr,
	&sensor_dev_attr_in6_input.dev_attr.attr,
	&sensor_dev_attr_in6_min.dev_attr.attr,
	&sensor_dev_attr_in6_max.dev_attr.attr,

	&sensor_dev_attr_fan1_input.dev_attr.attr,
	&sensor_dev_attr_fan1_min.dev_attr.attr,
	&sensor_dev_attr_fan1_div.dev_attr.attr,
	&sensor_dev_attr_fan2_input.dev_attr.attr,
	&sensor_dev_attr_fan2_min.dev_attr.attr,
	&sensor_dev_attr_fan2_div.dev_attr.attr,
	&sensor_dev_attr_fan3_input.dev_attr.attr,
	&sensor_dev_attr_fan3_min.dev_attr.attr,
	&sensor_dev_attr_fan3_div.dev_attr.attr,

	&sensor_dev_attr_temp1_input.dev_attr.attr,
	&sensor_dev_attr_temp1_max.dev_attr.attr,
	&sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
	&sensor_dev_attr_temp2_input.dev_attr.attr,
	&sensor_dev_attr_temp2_max.dev_attr.attr,
	&sensor_dev_attr_temp2_max_hyst.dev_attr.attr,
	&sensor_dev_attr_temp3_input.dev_attr.attr,
	&sensor_dev_attr_temp3_max.dev_attr.attr,
	&sensor_dev_attr_temp3_max_hyst.dev_attr.attr,
	&sensor_dev_attr_temp4_input.dev_attr.attr,
	&sensor_dev_attr_temp4_max.dev_attr.attr,
	&sensor_dev_attr_temp4_max_hyst.dev_attr.attr,
596

597 598 599 600 601 602 603 604 605 606 607 608
	&sensor_dev_attr_in0_alarm.dev_attr.attr,
	&sensor_dev_attr_in1_alarm.dev_attr.attr,
	&sensor_dev_attr_in2_alarm.dev_attr.attr,
	&sensor_dev_attr_in3_alarm.dev_attr.attr,
	&sensor_dev_attr_in4_alarm.dev_attr.attr,
	&sensor_dev_attr_fan1_alarm.dev_attr.attr,
	&sensor_dev_attr_fan2_alarm.dev_attr.attr,
	&sensor_dev_attr_fan3_alarm.dev_attr.attr,
	&sensor_dev_attr_temp1_alarm.dev_attr.attr,
	&sensor_dev_attr_temp2_alarm.dev_attr.attr,
	&sensor_dev_attr_temp3_alarm.dev_attr.attr,

609 610 611 612 613 614 615 616 617 618 619 620
	&dev_attr_cpu0_vid.attr,
	&dev_attr_vrm.attr,
	&dev_attr_alarms.attr,
	&dev_attr_pwm1.attr,
	&dev_attr_pwm1_enable.attr,

	NULL
};

static const struct attribute_group asb100_group = {
	.attrs = asb100_attributes,
};
L
Linus Torvalds 已提交
621 622 623 624 625 626 627 628 629 630

/* This function is called when:
	asb100_driver is inserted (when this module is loaded), for each
		available adapter
	when a new adapter is inserted (and asb100_driver is still present)
 */
static int asb100_attach_adapter(struct i2c_adapter *adapter)
{
	if (!(adapter->class & I2C_CLASS_HWMON))
		return 0;
631
	return i2c_probe(adapter, &addr_data, asb100_detect);
L
Linus Torvalds 已提交
632 633 634
}

static int asb100_detect_subclients(struct i2c_adapter *adapter, int address,
J
Jean Delvare 已提交
635
		int kind, struct i2c_client *client)
L
Linus Torvalds 已提交
636 637
{
	int i, id, err;
J
Jean Delvare 已提交
638
	struct asb100_data *data = i2c_get_clientdata(client);
L
Linus Torvalds 已提交
639

D
Deepak Saxena 已提交
640
	data->lm75[0] = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
L
Linus Torvalds 已提交
641 642 643 644 645
	if (!(data->lm75[0])) {
		err = -ENOMEM;
		goto ERROR_SC_0;
	}

D
Deepak Saxena 已提交
646
	data->lm75[1] = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
L
Linus Torvalds 已提交
647 648 649 650 651 652 653 654 655 656 657
	if (!(data->lm75[1])) {
		err = -ENOMEM;
		goto ERROR_SC_1;
	}

	id = i2c_adapter_id(adapter);

	if (force_subclients[0] == id && force_subclients[1] == address) {
		for (i = 2; i <= 3; i++) {
			if (force_subclients[i] < 0x48 ||
			    force_subclients[i] > 0x4f) {
J
Jean Delvare 已提交
658
				dev_err(&client->dev, "invalid subclient "
L
Linus Torvalds 已提交
659 660 661 662 663 664
					"address %d; must be 0x48-0x4f\n",
					force_subclients[i]);
				err = -ENODEV;
				goto ERROR_SC_2;
			}
		}
J
Jean Delvare 已提交
665
		asb100_write_value(client, ASB100_REG_I2C_SUBADDR,
L
Linus Torvalds 已提交
666
					(force_subclients[2] & 0x07) |
J
Jean Delvare 已提交
667
					((force_subclients[3] & 0x07) << 4));
L
Linus Torvalds 已提交
668 669 670
		data->lm75[0]->addr = force_subclients[2];
		data->lm75[1]->addr = force_subclients[3];
	} else {
J
Jean Delvare 已提交
671
		int val = asb100_read_value(client, ASB100_REG_I2C_SUBADDR);
L
Linus Torvalds 已提交
672 673 674 675
		data->lm75[0]->addr = 0x48 + (val & 0x07);
		data->lm75[1]->addr = 0x48 + ((val >> 4) & 0x07);
	}

J
Jean Delvare 已提交
676 677
	if (data->lm75[0]->addr == data->lm75[1]->addr) {
		dev_err(&client->dev, "duplicate addresses 0x%x "
L
Linus Torvalds 已提交
678 679 680 681 682 683 684 685 686 687 688 689 690
				"for subclients\n", data->lm75[0]->addr);
		err = -ENODEV;
		goto ERROR_SC_2;
	}

	for (i = 0; i <= 1; i++) {
		i2c_set_clientdata(data->lm75[i], NULL);
		data->lm75[i]->adapter = adapter;
		data->lm75[i]->driver = &asb100_driver;
		strlcpy(data->lm75[i]->name, "asb100 subclient", I2C_NAME_SIZE);
	}

	if ((err = i2c_attach_client(data->lm75[0]))) {
J
Jean Delvare 已提交
691
		dev_err(&client->dev, "subclient %d registration "
L
Linus Torvalds 已提交
692 693 694 695 696
			"at address 0x%x failed.\n", i, data->lm75[0]->addr);
		goto ERROR_SC_2;
	}

	if ((err = i2c_attach_client(data->lm75[1]))) {
J
Jean Delvare 已提交
697
		dev_err(&client->dev, "subclient %d registration "
L
Linus Torvalds 已提交
698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717
			"at address 0x%x failed.\n", i, data->lm75[1]->addr);
		goto ERROR_SC_3;
	}

	return 0;

/* Undo inits in case of errors */
ERROR_SC_3:
	i2c_detach_client(data->lm75[0]);
ERROR_SC_2:
	kfree(data->lm75[1]);
ERROR_SC_1:
	kfree(data->lm75[0]);
ERROR_SC_0:
	return err;
}

static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
{
	int err;
J
Jean Delvare 已提交
718
	struct i2c_client *client;
L
Linus Torvalds 已提交
719 720 721 722 723 724 725 726 727 728 729 730 731
	struct asb100_data *data;

	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
		pr_debug("asb100.o: detect failed, "
				"smbus byte data not supported!\n");
		err = -ENODEV;
		goto ERROR0;
	}

	/* OK. For now, we presume we have a valid client. We now create the
	   client structure, even though we cannot fill it completely yet.
	   But it allows us to access asb100_{read,write}_value. */

D
Deepak Saxena 已提交
732 733
	if (!(data = kzalloc(sizeof(struct asb100_data), GFP_KERNEL))) {
		pr_debug("asb100.o: detect failed, kzalloc failed!\n");
L
Linus Torvalds 已提交
734 735 736 737
		err = -ENOMEM;
		goto ERROR0;
	}

J
Jean Delvare 已提交
738
	client = &data->client;
739
	mutex_init(&data->lock);
J
Jean Delvare 已提交
740 741 742 743
	i2c_set_clientdata(client, data);
	client->addr = address;
	client->adapter = adapter;
	client->driver = &asb100_driver;
L
Linus Torvalds 已提交
744 745 746 747 748 749 750 751 752

	/* Now, we do the remaining detection. */

	/* The chip may be stuck in some other bank than bank 0. This may
	   make reading other information impossible. Specify a force=... or
	   force_*=... parameter, and the chip will be reset to the right
	   bank. */
	if (kind < 0) {

J
Jean Delvare 已提交
753 754
		int val1 = asb100_read_value(client, ASB100_REG_BANK);
		int val2 = asb100_read_value(client, ASB100_REG_CHIPMAN);
L
Linus Torvalds 已提交
755 756

		/* If we're in bank 0 */
J
Jean Delvare 已提交
757
		if ((!(val1 & 0x07)) &&
L
Linus Torvalds 已提交
758
				/* Check for ASB100 ID (low byte) */
J
Jean Delvare 已提交
759
				(((!(val1 & 0x80)) && (val2 != 0x94)) ||
L
Linus Torvalds 已提交
760
				/* Check for ASB100 ID (high byte ) */
J
Jean Delvare 已提交
761
				((val1 & 0x80) && (val2 != 0x06)))) {
L
Linus Torvalds 已提交
762 763 764 765 766 767 768 769 770 771
			pr_debug("asb100.o: detect failed, "
					"bad chip id 0x%02x!\n", val2);
			err = -ENODEV;
			goto ERROR1;
		}

	} /* kind < 0 */

	/* We have either had a force parameter, or we have already detected
	   Winbond. Put it now into bank 0 and Vendor ID High Byte */
J
Jean Delvare 已提交
772 773
	asb100_write_value(client, ASB100_REG_BANK,
		(asb100_read_value(client, ASB100_REG_BANK) & 0x78) | 0x80);
L
Linus Torvalds 已提交
774 775 776

	/* Determine the chip type. */
	if (kind <= 0) {
J
Jean Delvare 已提交
777 778
		int val1 = asb100_read_value(client, ASB100_REG_WCHIPID);
		int val2 = asb100_read_value(client, ASB100_REG_CHIPMAN);
L
Linus Torvalds 已提交
779 780 781 782 783

		if ((val1 == 0x31) && (val2 == 0x06))
			kind = asb100;
		else {
			if (kind == 0)
J
Jean Delvare 已提交
784
				dev_warn(&client->dev, "ignoring "
L
Linus Torvalds 已提交
785 786 787 788 789 790 791 792 793
					"'force' parameter for unknown chip "
					"at adapter %d, address 0x%02x.\n",
					i2c_adapter_id(adapter), address);
			err = -ENODEV;
			goto ERROR1;
		}
	}

	/* Fill in remaining client fields and put it into the global list */
J
Jean Delvare 已提交
794
	strlcpy(client->name, "asb100", I2C_NAME_SIZE);
L
Linus Torvalds 已提交
795
	data->type = kind;
796
	mutex_init(&data->update_lock);
L
Linus Torvalds 已提交
797 798

	/* Tell the I2C layer a new client has arrived */
J
Jean Delvare 已提交
799
	if ((err = i2c_attach_client(client)))
L
Linus Torvalds 已提交
800 801 802 803
		goto ERROR1;

	/* Attach secondary lm75 clients */
	if ((err = asb100_detect_subclients(adapter, address, kind,
J
Jean Delvare 已提交
804
			client)))
L
Linus Torvalds 已提交
805 806 807
		goto ERROR2;

	/* Initialize the chip */
J
Jean Delvare 已提交
808
	asb100_init_client(client);
L
Linus Torvalds 已提交
809 810

	/* A few vars need to be filled upon startup */
J
Jean Delvare 已提交
811 812 813
	data->fan_min[0] = asb100_read_value(client, ASB100_REG_FAN_MIN(0));
	data->fan_min[1] = asb100_read_value(client, ASB100_REG_FAN_MIN(1));
	data->fan_min[2] = asb100_read_value(client, ASB100_REG_FAN_MIN(2));
L
Linus Torvalds 已提交
814 815

	/* Register sysfs hooks */
J
Jean Delvare 已提交
816
	if ((err = sysfs_create_group(&client->dev.kobj, &asb100_group)))
817 818
		goto ERROR3;

J
Jean Delvare 已提交
819
	data->hwmon_dev = hwmon_device_register(&client->dev);
820 821
	if (IS_ERR(data->hwmon_dev)) {
		err = PTR_ERR(data->hwmon_dev);
822
		goto ERROR4;
823 824
	}

L
Linus Torvalds 已提交
825 826
	return 0;

827
ERROR4:
J
Jean Delvare 已提交
828
	sysfs_remove_group(&client->dev.kobj, &asb100_group);
829 830 831 832 833
ERROR3:
	i2c_detach_client(data->lm75[1]);
	i2c_detach_client(data->lm75[0]);
	kfree(data->lm75[1]);
	kfree(data->lm75[0]);
L
Linus Torvalds 已提交
834
ERROR2:
J
Jean Delvare 已提交
835
	i2c_detach_client(client);
L
Linus Torvalds 已提交
836 837 838 839 840 841 842 843
ERROR1:
	kfree(data);
ERROR0:
	return err;
}

static int asb100_detach_client(struct i2c_client *client)
{
844
	struct asb100_data *data = i2c_get_clientdata(client);
L
Linus Torvalds 已提交
845 846
	int err;

847
	/* main client */
848
	if (data) {
849
		hwmon_device_unregister(data->hwmon_dev);
850 851
		sysfs_remove_group(&client->dev.kobj, &asb100_group);
	}
852

853
	if ((err = i2c_detach_client(client)))
L
Linus Torvalds 已提交
854 855
		return err;

856 857 858 859 860 861
	/* main client */
	if (data)
		kfree(data);

	/* subclient */
	else
L
Linus Torvalds 已提交
862 863 864 865 866 867 868 869 870 871 872 873 874
		kfree(client);

	return 0;
}

/* The SMBus locks itself, usually, but nothing may access the chip between
   bank switches. */
static int asb100_read_value(struct i2c_client *client, u16 reg)
{
	struct asb100_data *data = i2c_get_clientdata(client);
	struct i2c_client *cl;
	int res, bank;

875
	mutex_lock(&data->lock);
L
Linus Torvalds 已提交
876 877 878 879 880 881 882 883 884 885 886 887 888 889 890

	bank = (reg >> 8) & 0x0f;
	if (bank > 2)
		/* switch banks */
		i2c_smbus_write_byte_data(client, ASB100_REG_BANK, bank);

	if (bank == 0 || bank > 2) {
		res = i2c_smbus_read_byte_data(client, reg & 0xff);
	} else {
		/* switch to subclient */
		cl = data->lm75[bank - 1];

		/* convert from ISA to LM75 I2C addresses */
		switch (reg & 0xff) {
		case 0x50: /* TEMP */
J
Jean Delvare 已提交
891
			res = swab16(i2c_smbus_read_word_data(cl, 0));
L
Linus Torvalds 已提交
892 893 894 895 896
			break;
		case 0x52: /* CONFIG */
			res = i2c_smbus_read_byte_data(cl, 1);
			break;
		case 0x53: /* HYST */
J
Jean Delvare 已提交
897
			res = swab16(i2c_smbus_read_word_data(cl, 2));
L
Linus Torvalds 已提交
898 899 900
			break;
		case 0x55: /* MAX */
		default:
J
Jean Delvare 已提交
901
			res = swab16(i2c_smbus_read_word_data(cl, 3));
L
Linus Torvalds 已提交
902 903 904 905 906 907 908
			break;
		}
	}

	if (bank > 2)
		i2c_smbus_write_byte_data(client, ASB100_REG_BANK, 0);

909
	mutex_unlock(&data->lock);
L
Linus Torvalds 已提交
910 911 912 913 914 915 916 917 918 919

	return res;
}

static void asb100_write_value(struct i2c_client *client, u16 reg, u16 value)
{
	struct asb100_data *data = i2c_get_clientdata(client);
	struct i2c_client *cl;
	int bank;

920
	mutex_lock(&data->lock);
L
Linus Torvalds 已提交
921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949

	bank = (reg >> 8) & 0x0f;
	if (bank > 2)
		/* switch banks */
		i2c_smbus_write_byte_data(client, ASB100_REG_BANK, bank);

	if (bank == 0 || bank > 2) {
		i2c_smbus_write_byte_data(client, reg & 0xff, value & 0xff);
	} else {
		/* switch to subclient */
		cl = data->lm75[bank - 1];

		/* convert from ISA to LM75 I2C addresses */
		switch (reg & 0xff) {
		case 0x52: /* CONFIG */
			i2c_smbus_write_byte_data(cl, 1, value & 0xff);
			break;
		case 0x53: /* HYST */
			i2c_smbus_write_word_data(cl, 2, swab16(value));
			break;
		case 0x55: /* MAX */
			i2c_smbus_write_word_data(cl, 3, swab16(value));
			break;
		}
	}

	if (bank > 2)
		i2c_smbus_write_byte_data(client, ASB100_REG_BANK, 0);

950
	mutex_unlock(&data->lock);
L
Linus Torvalds 已提交
951 952 953 954 955 956 957 958 959
}

static void asb100_init_client(struct i2c_client *client)
{
	struct asb100_data *data = i2c_get_clientdata(client);
	int vid = 0;

	vid = asb100_read_value(client, ASB100_REG_VID_FANDIV) & 0x0f;
	vid |= (asb100_read_value(client, ASB100_REG_CHIPID) & 0x01) << 4;
960
	data->vrm = vid_which_vrm();
L
Linus Torvalds 已提交
961 962 963
	vid = vid_from_reg(vid, data->vrm);

	/* Start monitoring */
J
Jean Delvare 已提交
964
	asb100_write_value(client, ASB100_REG_CONFIG,
L
Linus Torvalds 已提交
965 966 967 968 969 970 971 972 973
		(asb100_read_value(client, ASB100_REG_CONFIG) & 0xf7) | 0x01);
}

static struct asb100_data *asb100_update_device(struct device *dev)
{
	struct i2c_client *client = to_i2c_client(dev);
	struct asb100_data *data = i2c_get_clientdata(client);
	int i;

974
	mutex_lock(&data->update_lock);
L
Linus Torvalds 已提交
975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031

	if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
		|| !data->valid) {

		dev_dbg(&client->dev, "starting device update...\n");

		/* 7 voltage inputs */
		for (i = 0; i < 7; i++) {
			data->in[i] = asb100_read_value(client,
				ASB100_REG_IN(i));
			data->in_min[i] = asb100_read_value(client,
				ASB100_REG_IN_MIN(i));
			data->in_max[i] = asb100_read_value(client,
				ASB100_REG_IN_MAX(i));
		}

		/* 3 fan inputs */
		for (i = 0; i < 3; i++) {
			data->fan[i] = asb100_read_value(client,
					ASB100_REG_FAN(i));
			data->fan_min[i] = asb100_read_value(client,
					ASB100_REG_FAN_MIN(i));
		}

		/* 4 temperature inputs */
		for (i = 1; i <= 4; i++) {
			data->temp[i-1] = asb100_read_value(client,
					ASB100_REG_TEMP(i));
			data->temp_max[i-1] = asb100_read_value(client,
					ASB100_REG_TEMP_MAX(i));
			data->temp_hyst[i-1] = asb100_read_value(client,
					ASB100_REG_TEMP_HYST(i));
		}

		/* VID and fan divisors */
		i = asb100_read_value(client, ASB100_REG_VID_FANDIV);
		data->vid = i & 0x0f;
		data->vid |= (asb100_read_value(client,
				ASB100_REG_CHIPID) & 0x01) << 4;
		data->fan_div[0] = (i >> 4) & 0x03;
		data->fan_div[1] = (i >> 6) & 0x03;
		data->fan_div[2] = (asb100_read_value(client,
				ASB100_REG_PIN) >> 6) & 0x03;

		/* PWM */
		data->pwm = asb100_read_value(client, ASB100_REG_PWM1);

		/* alarms */
		data->alarms = asb100_read_value(client, ASB100_REG_ALARM1) +
			(asb100_read_value(client, ASB100_REG_ALARM2) << 8);

		data->last_updated = jiffies;
		data->valid = 1;

		dev_dbg(&client->dev, "... device update complete\n");
	}

1032
	mutex_unlock(&data->update_lock);
L
Linus Torvalds 已提交
1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052

	return data;
}

static int __init asb100_init(void)
{
	return i2c_add_driver(&asb100_driver);
}

static void __exit asb100_exit(void)
{
	i2c_del_driver(&asb100_driver);
}

MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>");
MODULE_DESCRIPTION("ASB100 Bach driver");
MODULE_LICENSE("GPL");

module_init(asb100_init);
module_exit(asb100_exit);