예제 #1
0
static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
			  const char *buf, size_t count)
{
	struct i2c_client *client = to_i2c_client(dev);
	struct gl520_data *data = i2c_get_clientdata(client);
	int n = to_sensor_dev_attr(attr)->index;
	u8 r;
	long v;
	int err;

	err = kstrtol(buf, 10, &v);
	if (err)
		return err;

	mutex_lock(&data->update_lock);

	if (n == 0)
		r = VDD_TO_REG(v);
	else
		r = IN_TO_REG(v);

	data->in_min[n] = r;

	if (n < 4)
		gl520_write_value(client, GL520_REG_IN_MIN[n],
				  (gl520_read_value(client, GL520_REG_IN_MIN[n])
				   & ~0xff) | r);
	else
		gl520_write_value(client, GL520_REG_IN_MIN[n], r);

	mutex_unlock(&data->update_lock);
	return count;
}
예제 #2
0
static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
			  const char *buf, size_t count)
{
	struct i2c_client *client = to_i2c_client(dev);
	struct gl520_data *data = i2c_get_clientdata(client);
	int n = to_sensor_dev_attr(attr)->index;
	long v = simple_strtol(buf, NULL, 10);
	u8 r;

	if (n == 0)
		r = VDD_TO_REG(v);
	else
		r = IN_TO_REG(v);

	mutex_lock(&data->update_lock);

	data->in_max[n] = r;

	if (n < 4)
		gl520_write_value(client, GL520_REG_IN_MAX[n],
				  (gl520_read_value(client, GL520_REG_IN_MAX[n])
				   & ~0xff00) | (r << 8));
	else
		gl520_write_value(client, GL520_REG_IN_MAX[n], r);

	mutex_unlock(&data->update_lock);
	return count;
}
예제 #3
0
/* Called when we have found a new GL520SM. It should set limits, etc. */
void gl520_init_client(struct i2c_client *client)
{
	/* Power-on defaults (bit 7=1) */
	gl520_write_value(client, GL520_REG_CONF, 0x80);

	/* No noisy output (bit 2=1), Comparator mode (bit 3=0), two fans (bit4=0),
	   standby mode (bit6=0) */
	gl520_write_value(client, GL520_REG_CONF, 0x04);

	/* Never interrupts */
	gl520_write_value(client, GL520_REG_MASK, 0x00);

	gl520_write_value(client, GL520_REG_TEMP1_HYST,
			  TEMP_TO_REG(GL520_INIT_TEMP_HYST));
	gl520_write_value(client, GL520_REG_TEMP1_OVER,
			  TEMP_TO_REG(GL520_INIT_TEMP_OVER));

	/* We set Temp2, but not Vin4. */
	gl520_write_value(client, GL520_REG_TEMP2_HYST,
			  TEMP_TO_REG(GL520_INIT_TEMP_HYST));
	gl520_write_value(client, GL520_REG_TEMP2_OVER,
			  TEMP_TO_REG(GL520_INIT_TEMP_OVER));

	gl520_write_value(client, GL520_REG_MISC, (DIV_TO_REG(2) << 6) |
			  (DIV_TO_REG(2) << 4));
	gl520_write_value(client, GL520_REG_FAN_LIMIT,
			  (FAN_TO_REG(GL520_INIT_FAN_MIN_1, 2) << 8) |
			  FAN_TO_REG(GL520_INIT_FAN_MIN_2, 2));

	gl520_write_value(client, GL520_REG_VIN1_LIMIT,
			  (IN_TO_REG(GL520_INIT_VIN_MAX_1) << 8) |
			  IN_TO_REG(GL520_INIT_VIN_MIN_1));
	gl520_write_value(client, GL520_REG_VIN2_LIMIT,
			  (IN_TO_REG(GL520_INIT_VIN_MAX_2) << 8) |
			  IN_TO_REG(GL520_INIT_VIN_MIN_2));
	gl520_write_value(client, GL520_REG_VIN3_LIMIT,
			  (IN_TO_REG(GL520_INIT_VIN_MAX_3) << 8) |
			  IN_TO_REG(GL520_INIT_VIN_MIN_3));
	gl520_write_value(client, GL520_REG_VDD_LIMIT,
			  (VDD_TO_REG(GL520_INIT_VDD_MAX) << 8) |
			  VDD_TO_REG(GL520_INIT_VDD_MIN));

	/* Clear status register (bit 5=1), start (bit6=1) */
	gl520_write_value(client, GL520_REG_CONF, 0x24);
	gl520_write_value(client, GL520_REG_CONF, 0x44);
}