Lines Matching +full:vref +full:- +full:p
1 // SPDX-License-Identifier: GPL-2.0-only
22 #include <linux/hwmon-sysfs.h>
26 /* Internal reference voltage (VREF, x 1000 */
30 static int vref = SMM665_VREF_ADC_X1000; variable
31 module_param(vref, int, 0);
32 MODULE_PARM_DESC(vref, "Reference voltage in mV");
111 * vref = Reference voltage on VREF_ADC pin (module parameter)
115 /* Voltage A-F and VDD */
116 #define SMM665_VMON_ADC_TO_VOLTS(adc) ((adc) * vref / 256)
119 #define SMM665_12VIN_ADC_TO_VOLTS(adc) ((adc) * vref * 3 / 256)
122 #define SMM665_AIN_ADC_TO_VOLTS(adc) ((adc) * vref / 512)
127 (((int)(adc) - 0x400) * 1000 / 4))
179 struct i2c_client *client = data->cmdreg; in smm665_read_adc()
188 * {[S][addr][R][Ack]} {[datahi][Ack]} {[datalo][Ack][P]} in smm665_read_adc()
194 * Then do a two-byte read transaction. in smm665_read_adc()
197 if (rv != -ENXIO) { in smm665_read_adc()
200 * (per Documentation/i2c/fault-codes.rst). in smm665_read_adc()
203 dev_dbg(&client->dev, in smm665_read_adc()
205 return (rv < 0) ? rv : -EIO; in smm665_read_adc()
208 udelay(data->conversion_time); in smm665_read_adc()
221 dev_dbg(&client->dev, "Failed to read ADC value: error %d", rv); in smm665_read_adc()
229 dev_dbg(&client->dev, "Unexpected RADC: Expected %d got %d", in smm665_read_adc()
231 return -EIO; in smm665_read_adc()
240 struct i2c_client *client = data->client; in smm665_update_device()
243 mutex_lock(&data->update_lock); in smm665_update_device()
245 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { in smm665_update_device()
256 data->faults = val; in smm665_update_device()
265 data->adc[i] = val; in smm665_update_device()
267 data->last_updated = jiffies; in smm665_update_device()
268 data->valid = 1; in smm665_update_device()
271 mutex_unlock(&data->update_lock); in smm665_update_device()
317 return data->alarm_min_limit[index]; in smm665_get_min()
324 return data->alarm_max_limit[index]; in smm665_get_max()
331 return data->critical_min_limit[index]; in smm665_get_lcrit()
338 return data->critical_max_limit[index]; in smm665_get_crit()
351 if (data->faults & (1 << attr->index)) in smm665_show_crit_alarm()
362 int adc = attr->index; in smm665_show_input()
368 val = smm665_convert(data->adc[adc], adc); in smm665_show_input()
377 const int val = smm665_get_##what(dev, attr->index); \
569 struct i2c_adapter *adapter = client->adapter; in smm665_probe()
576 return -ENODEV; in smm665_probe()
579 return -ENODEV; in smm665_probe()
581 data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); in smm665_probe()
583 return -ENOMEM; in smm665_probe()
586 mutex_init(&data->update_lock); in smm665_probe()
588 data->client = client; in smm665_probe()
589 data->type = i2c_match_id(smm665_id, client)->driver_data; in smm665_probe()
590 data->cmdreg = i2c_new_dummy_device(adapter, (client->addr & ~SMM665_REGMASK) in smm665_probe()
592 if (IS_ERR(data->cmdreg)) in smm665_probe()
593 return PTR_ERR(data->cmdreg); in smm665_probe()
595 switch (data->type) { in smm665_probe()
598 data->conversion_time = SMM665_ADC_WAIT_SMM665; in smm665_probe()
603 data->conversion_time = SMM665_ADC_WAIT_SMM766; in smm665_probe()
607 ret = -ENODEV; in smm665_probe()
608 if (i2c_smbus_read_byte_data(data->cmdreg, SMM665_MISC8_CMD_STS) < 0) in smm665_probe()
628 * configured as critical or non-critical. in smm665_probe()
636 data->critical_min_limit[i] = data->alarm_min_limit[i] in smm665_probe()
642 data->critical_min_limit[i] = smm665_convert(val, i); in smm665_probe()
644 data->alarm_min_limit[i] = smm665_convert(val, i); in smm665_probe()
648 data->critical_max_limit[i] = data->alarm_max_limit[i] in smm665_probe()
654 data->critical_max_limit[i] = smm665_convert(val, i); in smm665_probe()
656 data->alarm_max_limit[i] = smm665_convert(val, i); in smm665_probe()
659 hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev, in smm665_probe()
660 client->name, data, in smm665_probe()
670 i2c_unregister_device(data->cmdreg); in smm665_probe()
678 i2c_unregister_device(data->cmdreg); in smm665_remove()