memset(data, 0, sizeof(struct w83781d_data)); 
w83781d_detect(struct i2c_adapter *adapter, int address, int kind){	int i = 0, val1 = 0, val2;	struct i2c_client *new_client;	struct w83781d_data *data;	int err;	const char *client_name = "";	int is_isa = i2c_is_isa_adapter(adapter);	enum vendor { winbond, asus } vendid;	if (!is_isa	    && !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {		err = -EINVAL;		goto ERROR0;	}	/* Prevent users from forcing a kind for a bus it isn't supposed	   to possibly be on */	if (is_isa && (kind == as99127f || kind == w83783s)) {		dev_err(&adapter->dev,			"Cannot force I2C-only chip for ISA address 0x%02x.\n",			address);		err = -EINVAL;		goto ERROR0;	}		if (is_isa)		if (!request_region(address, W83781D_EXTENT,				    w83781d_isa_driver.name)) {			dev_dbg(&adapter->dev, "Request of region "				"0x%x-0x%x for w83781d failed\n", address,				address + W83781D_EXTENT - 1);			err = -EBUSY;			goto ERROR0;		}	/* Probe whether there is anything available on this address. Already	   done for SMBus clients */	if (kind < 0) {		if (is_isa) {#define REALLY_SLOW_IO			/* We need the timeouts for at least some LM78-like			   chips. But only if we read 'undefined' registers. */			i = inb_p(address + 1);			if (inb_p(address + 2) != i			 || inb_p(address + 3) != i			 || inb_p(address + 7) != i) {				dev_dbg(&adapter->dev, "Detection of w83781d "					"chip failed at step 1\n");				err = -ENODEV;				goto ERROR1;			}#undef REALLY_SLOW_IO			/* Let's just hope nothing breaks here */			i = inb_p(address + 5) & 0x7f;			outb_p(~i & 0x7f, address + 5);			val2 = inb_p(address + 5) & 0x7f;			if (val2 != (~i & 0x7f)) {				outb_p(i, address + 5);				dev_dbg(&adapter->dev, "Detection of w83781d "					"chip failed at step 2 (0x%x != "					"0x%x at 0x%x)\n", val2, ~i & 0x7f,					address + 5);				err = -ENODEV;				goto ERROR1;			}		}	}	/* 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 w83781d_{read,write}_value. */	if (!(data = kmalloc(sizeof(struct w83781d_data), GFP_KERNEL))) {		err = -ENOMEM;		goto ERROR1;	}	memset(data, 0, sizeof(struct w83781d_data));	new_client = &data->client;	i2c_set_clientdata(new_client, data);	new_client->addr = address;	init_MUTEX(&data->lock);	new_client->adapter = adapter;	new_client->driver = is_isa ? &w83781d_isa_driver : &w83781d_driver;	new_client->flags = 0;	/* Now, we do the remaining detection. */	/* The w8378?d 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 Winbond will be reset to the right	   bank. */	if (kind < 0) {		if (w83781d_read_value(new_client, W83781D_REG_CONFIG) & 0x80) {			dev_dbg(&new_client->dev, "Detection failed at step "				"3\n");			err = -ENODEV;			goto ERROR2;		}		val1 = w83781d_read_value(new_client, W83781D_REG_BANK);		val2 = w83781d_read_value(new_client, W83781D_REG_CHIPMAN);		/* Check for Winbond or Asus ID if in bank 0 */		if ((!(val1 & 0x07)) &&		    (((!(val1 & 0x80)) && (val2 != 0xa3) && (val2 != 0xc3))		     || ((val1 & 0x80) && (val2 != 0x5c) && (val2 != 0x12)))) {			dev_dbg(&new_client->dev, "Detection failed at step "				"4\n");			err = -ENODEV;			goto ERROR2;		}		/* If Winbond SMBus, check address at 0x48.		   Asus doesn't support, except for as99127f rev.2 */		if ((!is_isa) && (((!(val1 & 0x80)) && (val2 == 0xa3)) ||				  ((val1 & 0x80) && (val2 == 0x5c)))) {			if (w83781d_read_value			    (new_client, W83781D_REG_I2C_ADDR) != address) {				dev_dbg(&new_client->dev, "Detection failed "					"at step 5\n");				err = -ENODEV;				goto ERROR2;			}		}	}	/* We have either had a force parameter, or we have already detected the	   Winbond. Put it now into bank 0 and Vendor ID High Byte */	w83781d_write_value(new_client, W83781D_REG_BANK,			    (w83781d_read_value(new_client,						W83781D_REG_BANK) & 0x78) |			    0x80);	/* Determine the chip type. */	if (kind <= 0) {		/* get vendor ID */		val2 = w83781d_read_value(new_client, W83781D_REG_CHIPMAN);		if (val2 == 0x5c)			vendid = winbond;		else if (val2 == 0x12)			vendid = asus;		else {			dev_dbg(&new_client->dev, "Chip was made by neither "				"Winbond nor Asus?\n");			err = -ENODEV;			goto ERROR2;		}		val1 = w83781d_read_value(new_client, W83781D_REG_WCHIPID);		if ((val1 == 0x10 || val1 == 0x11) && vendid == winbond)			kind = w83781d;		else if (val1 == 0x30 && vendid == winbond)			kind = w83782d;		else if (val1 == 0x40 && vendid == winbond && !is_isa				&& address == 0x2d)			kind = w83783s;		else if (val1 == 0x21 && vendid == winbond)			kind = w83627hf;		else if (val1 == 0x31 && !is_isa && address >= 0x28)			kind = as99127f;		else {			if (kind == 0)				dev_warn(&new_client->dev, "Ignoring 'force' "					 "parameter for unknown chip at "					 "adapter %d, address 0x%02x\n",					 i2c_adapter_id(adapter), address);			err = -EINVAL;			goto ERROR2;		}	}	if (kind == w83781d) {		client_name = "w83781d";	} else if (kind == w83782d) {		client_name = "w83782d";	} else if (kind == w83783s) {		client_name = "w83783s";	} else if (kind == w83627hf) {		client_name = "w83627hf";	} else if (kind == as99127f) {		client_name = "as99127f";	}	/* Fill in the remaining client fields and put into the global list */	strlcpy(new_client->name, client_name, I2C_NAME_SIZE);	data->type = kind;	data->valid = 0;	init_MUTEX(&data->update_lock);	/* Tell the I2C layer a new client has arrived */	if ((err = i2c_attach_client(new_client)))		goto ERROR2;	/* attach secondary i2c lm75-like clients */	if (!is_isa) {		if ((err = w83781d_detect_subclients(adapter, address,				kind, new_client)))			goto ERROR3;	} else {		data->lm75[0] = NULL;		data->lm75[1] = NULL;	}	/* Initialize the chip */	w83781d_init_client(new_client);	/* A few vars need to be filled upon startup */	for (i = 1; i <= 3; i++) {		data->fan_min[i - 1] = w83781d_read_value(new_client,					W83781D_REG_FAN_MIN(i));	}	if (kind != w83781d && kind != as99127f)		for (i = 0; i < 4; i++)			data->pwmenable[i] = 1;	/* Register sysfs hooks */	data->class_dev = hwmon_device_register(&new_client->dev);	if (IS_ERR(data->class_dev)) {		err = PTR_ERR(data->class_dev);		goto ERROR4;	}	device_create_file_in(new_client, 0);	if (kind != w83783s)		device_create_file_in(new_client, 1);	device_create_file_in(new_client, 2);	device_create_file_in(new_client, 3);	device_create_file_in(new_client, 4);	device_create_file_in(new_client, 5);	device_create_file_in(new_client, 6);	if (kind != as99127f && kind != w83781d && kind != w83783s) {		device_create_file_in(new_client, 7);		device_create_file_in(new_client, 8);	}	device_create_file_fan(new_client, 1);	device_create_file_fan(new_client, 2);	device_create_file_fan(new_client, 3);	device_create_file_temp(new_client, 1);	device_create_file_temp(new_client, 2);	if (kind != w83783s)		device_create_file_temp(new_client, 3);	device_create_file_vid(new_client);	device_create_file_vrm(new_client);	device_create_file_fan_div(new_client, 1);	device_create_file_fan_div(new_client, 2);	device_create_file_fan_div(new_client, 3);	device_create_file_alarms(new_client);	device_create_file_beep(new_client);	if (kind != w83781d && kind != as99127f) {		device_create_file_pwm(new_client, 1);		device_create_file_pwm(new_client, 2);		device_create_file_pwmenable(new_client, 2);	}	if (kind == w83782d && !is_isa) {		device_create_file_pwm(new_client, 3);		device_create_file_pwm(new_client, 4);	}	if (kind != as99127f && kind != w83781d) {		device_create_file_sensor(new_client, 1);		device_create_file_sensor(new_client, 2);		if (kind != w83783s)			device_create_file_sensor(new_client, 3);	}	return 0;ERROR4:	if (data->lm75[1]) {		i2c_detach_client(data->lm75[1]);		kfree(data->lm75[1]);	}	if (data->lm75[0]) {		i2c_detach_client(data->lm75[0]);		kfree(data->lm75[0]);	}ERROR3:	i2c_detach_client(new_client);ERROR2:	kfree(data);ERROR1:	if (is_isa)		release_region(address, W83781D_EXTENT);ERROR0:	return err;}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/ba9c2e8d15da029ea3051c95e446b2d638ef02e2/w83781d.c/clean/drivers/hwmon/w83781d.c