Lines Matching +full:keep +full:- +full:vref +full:- +full:on

1 // SPDX-License-Identifier: GPL-2.0-or-later
17 #include <linux/hwmon-sysfs.h>
61 int vref; /* Reference voltage in mV */ member
81 struct i2c_client *client = data->client; in adc128_update_device()
85 mutex_lock(&data->update_lock); in adc128_update_device()
87 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { in adc128_update_device()
88 for (i = 0; i < num_inputs[data->mode]; i++) { in adc128_update_device()
93 data->in[0][i] = rv >> 4; in adc128_update_device()
99 data->in[1][i] = rv << 4; in adc128_update_device()
105 data->in[2][i] = rv << 4; in adc128_update_device()
108 if (data->mode != 1) { in adc128_update_device()
113 data->temp[0] = rv >> 7; in adc128_update_device()
119 data->temp[1] = rv << 1; in adc128_update_device()
125 data->temp[2] = rv << 1; in adc128_update_device()
131 data->alarms |= rv; in adc128_update_device()
133 data->last_updated = jiffies; in adc128_update_device()
134 data->valid = true; in adc128_update_device()
140 data->valid = false; in adc128_update_device()
142 mutex_unlock(&data->update_lock); in adc128_update_device()
150 int index = to_sensor_dev_attr_2(attr)->index; in adc128_in_show()
151 int nr = to_sensor_dev_attr_2(attr)->nr; in adc128_in_show()
157 val = DIV_ROUND_CLOSEST(data->in[index][nr] * data->vref, 4095); in adc128_in_show()
166 int index = to_sensor_dev_attr_2(attr)->index; in adc128_in_store()
167 int nr = to_sensor_dev_attr_2(attr)->nr; in adc128_in_store()
176 mutex_lock(&data->update_lock); in adc128_in_store()
177 /* 10 mV LSB on limit registers */ in adc128_in_store()
179 data->in[index][nr] = regval << 4; in adc128_in_store()
181 i2c_smbus_write_byte_data(data->client, reg, regval); in adc128_in_store()
182 mutex_unlock(&data->update_lock); in adc128_in_store()
191 int index = to_sensor_dev_attr(attr)->index; in adc128_temp_show()
197 temp = sign_extend32(data->temp[index], 8); in adc128_temp_show()
206 int index = to_sensor_dev_attr(attr)->index; in adc128_temp_store()
215 mutex_lock(&data->update_lock); in adc128_temp_store()
216 regval = DIV_ROUND_CLOSEST(clamp_val(val, -128000, 127000), 1000); in adc128_temp_store()
217 data->temp[index] = regval << 1; in adc128_temp_store()
218 i2c_smbus_write_byte_data(data->client, in adc128_temp_store()
222 mutex_unlock(&data->update_lock); in adc128_temp_store()
231 int mask = 1 << to_sensor_dev_attr(attr)->index; in adc128_alarm_show()
241 alarms = data->alarms; in adc128_alarm_show()
242 data->alarms &= ~mask; in adc128_alarm_show()
255 if (index >= num_inputs[data->mode] * 4) in adc128_is_visible()
259 if (data->mode == 1) in adc128_is_visible()
263 return attr->mode; in adc128_is_visible()
362 if (!i2c_check_functionality(client->adapter, in adc128_detect()
365 return -ENODEV; in adc128_detect()
370 return -ENODEV; in adc128_detect()
374 return -ENODEV; in adc128_detect()
376 return -ENODEV; in adc128_detect()
378 return -ENODEV; in adc128_detect()
380 return -ENODEV; in adc128_detect()
382 return -ENODEV; in adc128_detect()
384 return -ENODEV; in adc128_detect()
386 strscpy(info->type, "adc128d818", I2C_NAME_SIZE); in adc128_detect()
393 struct i2c_client *client = data->client; in adc128_init_client()
405 /* Set operation mode, if non-default */ in adc128_init_client()
406 if (data->mode != 0) in adc128_init_client()
407 regval |= data->mode << 1; in adc128_init_client()
409 /* If external vref is selected, configure the chip to use it */ in adc128_init_client()
431 struct device *dev = &client->dev; in adc128_probe()
435 int err, vref; in adc128_probe() local
439 return -ENOMEM; in adc128_probe()
441 /* vref is optional. If specified, is used as chip reference voltage */ in adc128_probe()
442 vref = devm_regulator_get_enable_read_voltage(dev, "vref"); in adc128_probe()
443 if (vref == -ENODEV) { in adc128_probe()
445 data->vref = 2560; /* 2.56V, in mV */ in adc128_probe()
446 } else if (vref < 0) { in adc128_probe()
447 return vref; in adc128_probe()
450 data->vref = DIV_ROUND_CLOSEST(vref, 1000); in adc128_probe()
453 /* Operation mode is optional. If unspecified, keep current mode */ in adc128_probe()
454 if (of_property_read_u8(dev->of_node, "ti,mode", &data->mode) == 0) { in adc128_probe()
455 if (data->mode > 3) { in adc128_probe()
457 data->mode); in adc128_probe()
458 return -EINVAL; in adc128_probe()
464 data->mode = (err >> 1) & ADC128_REG_MASK; in adc128_probe()
467 data->client = client; in adc128_probe()
469 mutex_init(&data->update_lock); in adc128_probe()
476 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, in adc128_probe()