コード例 #1
0
ファイル: atxp1.c プロジェクト: 020gzh/linux
static int atxp1_probe(struct i2c_client *client,
		       const struct i2c_device_id *id)
{
	struct device *dev = &client->dev;
	struct atxp1_data *data;
	struct device *hwmon_dev;

	data = devm_kzalloc(dev, sizeof(struct atxp1_data), GFP_KERNEL);
	if (!data)
		return -ENOMEM;

	/* Get VRM */
	data->vrm = vid_which_vrm();
	if (data->vrm != 90 && data->vrm != 91) {
		dev_err(dev, "atxp1: Not supporting VRM %d.%d\n",
			data->vrm / 10, data->vrm % 10);
		return -ENODEV;
	}

	data->client = client;
	mutex_init(&data->update_lock);

	hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
							   data,
							   atxp1_groups);
	if (IS_ERR(hwmon_dev))
		return PTR_ERR(hwmon_dev);

	dev_info(dev, "Using VRM: %d.%d\n", data->vrm / 10, data->vrm % 10);

	return 0;
};
コード例 #2
0
ファイル: smsc47m192.c プロジェクト: forgivemyheart/linux
static int smsc47m192_probe(struct i2c_client *client,
			    const struct i2c_device_id *id)
{
	struct device *dev = &client->dev;
	struct device *hwmon_dev;
	struct smsc47m192_data *data;
	int config;

	data = devm_kzalloc(dev, sizeof(struct smsc47m192_data), GFP_KERNEL);
	if (!data)
		return -ENOMEM;

	data->client = client;
	data->vrm = vid_which_vrm();
	mutex_init(&data->update_lock);

	/* Initialize the SMSC47M192 chip */
	smsc47m192_init_client(client);

	/* sysfs hooks */
	data->groups[0] = &smsc47m192_group;
	/* Pin 110 is either in4 (+12V) or VID4 */
	config = i2c_smbus_read_byte_data(client, SMSC47M192_REG_CONFIG);
	if (!(config & 0x20))
		data->groups[1] = &smsc47m192_group_in4;

	hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
							   data, data->groups);
	return PTR_ERR_OR_ZERO(hwmon_dev);
}
コード例 #3
0
static int atxp1_probe(struct i2c_client *new_client,
		       const struct i2c_device_id *id)
{
	struct atxp1_data *data;
	int err;

	data = kzalloc(sizeof(struct atxp1_data), GFP_KERNEL);
	if (!data) {
		err = -ENOMEM;
		goto exit;
	}

	/* Get VRM */
	data->vrm = vid_which_vrm();

	i2c_set_clientdata(new_client, data);
	data->valid = 0;

	mutex_init(&data->update_lock);

	/* Register sysfs hooks */
	if ((err = sysfs_create_group(&new_client->dev.kobj, &atxp1_group)))
		goto exit_free;

	data->hwmon_dev = hwmon_device_register(&new_client->dev);
	if (IS_ERR(data->hwmon_dev)) {
		err = PTR_ERR(data->hwmon_dev);
		goto exit_remove_files;
	}

	dev_info(&new_client->dev, "Using VRM: %d.%d\n",
			 data->vrm / 10, data->vrm % 10);

	return 0;

exit_remove_files:
	sysfs_remove_group(&new_client->dev.kobj, &atxp1_group);
exit_free:
	kfree(data);
exit:
	return err;
};
コード例 #4
0
ファイル: adm1025.c プロジェクト: MohdVara/linux
static void adm1025_init_client(struct i2c_client *client)
{
	u8 reg;
	struct adm1025_data *data = i2c_get_clientdata(client);
	int i;

	data->vrm = vid_which_vrm();

	/*
	 * Set high limits
	 * Usually we avoid setting limits on driver init, but it happens
	 * that the ADM1025 comes with stupid default limits (all registers
	 * set to 0). In case the chip has not gone through any limit
	 * setting yet, we better set the high limits to the max so that
	 * no alarm triggers.
	 */
	for (i = 0; i < 6; i++) {
		reg = i2c_smbus_read_byte_data(client,
					       ADM1025_REG_IN_MAX(i));
		if (reg == 0)
			i2c_smbus_write_byte_data(client,
						  ADM1025_REG_IN_MAX(i),
						  0xFF);
	}
	for (i = 0; i < 2; i++) {
		reg = i2c_smbus_read_byte_data(client,
					       ADM1025_REG_TEMP_HIGH(i));
		if (reg == 0)
			i2c_smbus_write_byte_data(client,
						  ADM1025_REG_TEMP_HIGH(i),
						  0x7F);
	}

	/*
	 * Start the conversions
	 */
	reg = i2c_smbus_read_byte_data(client, ADM1025_REG_CONFIG);
	if (!(reg & 0x01))
		i2c_smbus_write_byte_data(client, ADM1025_REG_CONFIG,
					  (reg&0x7E)|0x01);
}
コード例 #5
0
static void adm1025_init_client(struct i2c_client *client)
{
	u8 reg;
	struct adm1025_data *data = i2c_get_clientdata(client);
	int i;

	data->vrm = vid_which_vrm();

	/*
                   
                                                                  
                                                                    
                                                              
                                                                 
                      
  */
	for (i = 0; i < 6; i++) {
		reg = i2c_smbus_read_byte_data(client,
					       ADM1025_REG_IN_MAX(i));
		if (reg == 0)
			i2c_smbus_write_byte_data(client,
						  ADM1025_REG_IN_MAX(i),
						  0xFF);
	}
	for (i = 0; i < 2; i++) {
		reg = i2c_smbus_read_byte_data(client,
					       ADM1025_REG_TEMP_HIGH(i));
		if (reg == 0)
			i2c_smbus_write_byte_data(client,
						  ADM1025_REG_TEMP_HIGH(i),
						  0x7F);
	}

	/*
                         
  */
	reg = i2c_smbus_read_byte_data(client, ADM1025_REG_CONFIG);
	if (!(reg & 0x01))
		i2c_smbus_write_byte_data(client, ADM1025_REG_CONFIG,
					  (reg&0x7E)|0x01);
}
コード例 #6
0
ファイル: atxp1.c プロジェクト: MaxChina/linux
/* Return 0 if detection is successful, -ENODEV otherwise */
static int atxp1_detect(struct i2c_client *new_client,
			struct i2c_board_info *info)
{
	struct i2c_adapter *adapter = new_client->adapter;

	u8 temp;

	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
		return -ENODEV;

	/* Detect ATXP1, checking if vendor ID registers are all zero */
	if (!((i2c_smbus_read_byte_data(new_client, 0x3e) == 0) &&
	     (i2c_smbus_read_byte_data(new_client, 0x3f) == 0) &&
	     (i2c_smbus_read_byte_data(new_client, 0xfe) == 0) &&
	     (i2c_smbus_read_byte_data(new_client, 0xff) == 0)))
		return -ENODEV;

	/*
	 * No vendor ID, now checking if registers 0x10,0x11 (non-existent)
	 * showing the same as register 0x00
	 */
	temp = i2c_smbus_read_byte_data(new_client, 0x00);

	if (!((i2c_smbus_read_byte_data(new_client, 0x10) == temp) &&
	      (i2c_smbus_read_byte_data(new_client, 0x11) == temp)))
		return -ENODEV;

	/* Get VRM */
	temp = vid_which_vrm();

	if ((temp != 90) && (temp != 91)) {
		dev_err(&adapter->dev, "atxp1: Not supporting VRM %d.%d\n",
				temp / 10, temp % 10);
		return -ENODEV;
	}

	strlcpy(info->type, "atxp1", I2C_NAME_SIZE);

	return 0;
}
コード例 #7
0
/* Called when we have found a new GL520SM. */
static void gl520_init_client(struct i2c_client *client)
{
	struct gl520_data *data = i2c_get_clientdata(client);
	u8 oldconf, conf;

	conf = oldconf = gl520_read_value(client, GL520_REG_CONF);

	data->alarm_mask = 0xff;
	data->vrm = vid_which_vrm();

	if (extra_sensor_type == 1)
		conf &= ~0x10;
	else if (extra_sensor_type == 2)
		conf |= 0x10;
	data->two_temps = !(conf & 0x10);

	/* If IRQ# is disabled, we can safely force comparator mode */
	if (!(conf & 0x20))
		conf &= 0xf7;

	/* Enable monitoring if needed */
	conf |= 0x40;

	if (conf != oldconf)
		gl520_write_value(client, GL520_REG_CONF, conf);

	gl520_update_device(&(client->dev));

	if (data->fan_min[0] == 0)
		data->alarm_mask &= ~0x20;
	if (data->fan_min[1] == 0)
		data->alarm_mask &= ~0x40;

	data->beep_mask &= data->alarm_mask;
	gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask);
}
コード例 #8
0
ファイル: lm87.c プロジェクト: arnetheduck/openonload
int efx_lm87_probe(struct i2c_client *new_client,
		   const struct i2c_device_id *id)
#endif
{
	struct lm87_data *data;
	int err;

	data = kzalloc(sizeof(struct lm87_data), GFP_KERNEL);
	if (!data) {
		err = -ENOMEM;
		goto exit;
	}

	i2c_set_clientdata(new_client, data);
	data->valid = 0;
	mutex_init(&data->update_lock);

	/* Initialize the LM87 chip */
	lm87_init_client(new_client);

	data->in_scale[0] = 2500;
	data->in_scale[1] = 2700;
	data->in_scale[2] = (data->channel & CHAN_VCC_5V) ? 5000 : 3300;
	data->in_scale[3] = 5000;
	data->in_scale[4] = 12000;
	data->in_scale[5] = 2700;
	data->in_scale[6] = 1875;
	data->in_scale[7] = 1875;

	/* Register sysfs hooks */
	if ((err = sysfs_create_group(&new_client->dev.kobj, &lm87_group)))
		goto exit_free;

	if (data->channel & CHAN_NO_FAN(0)) {
		if ((err = device_create_file(&new_client->dev,
					&dev_attr_in6_input))
		 || (err = device_create_file(&new_client->dev,
					&dev_attr_in6_min))
		 || (err = device_create_file(&new_client->dev,
					&dev_attr_in6_max))
		 || (err = device_create_file(&new_client->dev,
					&sensor_dev_attr_in6_alarm.dev_attr)))
			goto exit_remove;
	} else {
		if ((err = device_create_file(&new_client->dev,
					&dev_attr_fan1_input))
		 || (err = device_create_file(&new_client->dev,
					&dev_attr_fan1_min))
		 || (err = device_create_file(&new_client->dev,
					&dev_attr_fan1_div))
		 || (err = device_create_file(&new_client->dev,
					&sensor_dev_attr_fan1_alarm.dev_attr)))
			goto exit_remove;
	}

	if (data->channel & CHAN_NO_FAN(1)) {
		if ((err = device_create_file(&new_client->dev,
					&dev_attr_in7_input))
		 || (err = device_create_file(&new_client->dev,
					&dev_attr_in7_min))
		 || (err = device_create_file(&new_client->dev,
					&dev_attr_in7_max))
		 || (err = device_create_file(&new_client->dev,
					&sensor_dev_attr_in7_alarm.dev_attr)))
			goto exit_remove;
	} else {
		if ((err = device_create_file(&new_client->dev,
					&dev_attr_fan2_input))
		 || (err = device_create_file(&new_client->dev,
					&dev_attr_fan2_min))
		 || (err = device_create_file(&new_client->dev,
					&dev_attr_fan2_div))
		 || (err = device_create_file(&new_client->dev,
					&sensor_dev_attr_fan2_alarm.dev_attr)))
			goto exit_remove;
	}

	if (data->channel & CHAN_TEMP3) {
		if ((err = device_create_file(&new_client->dev,
					&dev_attr_temp3_input))
		 || (err = device_create_file(&new_client->dev,
					&dev_attr_temp3_max))
		 || (err = device_create_file(&new_client->dev,
					&dev_attr_temp3_min))
		 || (err = device_create_file(&new_client->dev,
					&dev_attr_temp3_crit))
		 || (err = device_create_file(&new_client->dev,
					&sensor_dev_attr_temp3_alarm.dev_attr))
		 || (err = device_create_file(&new_client->dev,
					&sensor_dev_attr_temp3_fault.dev_attr)))
			goto exit_remove;
	} else {
		if ((err = device_create_file(&new_client->dev,
					&dev_attr_in0_input))
		 || (err = device_create_file(&new_client->dev,
					&dev_attr_in0_min))
		 || (err = device_create_file(&new_client->dev,
					&dev_attr_in0_max))
		 || (err = device_create_file(&new_client->dev,
					&sensor_dev_attr_in0_alarm.dev_attr))
		 || (err = device_create_file(&new_client->dev,
					&dev_attr_in5_input))
		 || (err = device_create_file(&new_client->dev,
					&dev_attr_in5_min))
		 || (err = device_create_file(&new_client->dev,
					&dev_attr_in5_max))
		 || (err = device_create_file(&new_client->dev,
					&sensor_dev_attr_in5_alarm.dev_attr)))
			goto exit_remove;
	}

	if (!(data->channel & CHAN_NO_VID)) {
		data->vrm = vid_which_vrm();
		if ((err = device_create_file(&new_client->dev,
					&dev_attr_cpu0_vid))
		 || (err = device_create_file(&new_client->dev,
					&dev_attr_vrm)))
			goto exit_remove;
	}

	data->hwmon_dev = hwmon_device_register(&new_client->dev);
	if (IS_ERR(data->hwmon_dev)) {
		err = PTR_ERR(data->hwmon_dev);
		goto exit_remove;
	}

	return 0;

exit_remove:
	sysfs_remove_group(&new_client->dev.kobj, &lm87_group);
	sysfs_remove_group(&new_client->dev.kobj, &lm87_group_opt);
exit_free:
	lm87_write_value(new_client, LM87_REG_CONFIG, data->config);
	kfree(data);
exit:
	return err;
}