Lines Matching +full:vref +full:- +full:mv
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * ads7828.c - driver for TI ADS7828 8-channel A/D converter and compatibles
17 #include <linux/hwmon-sysfs.h>
29 #define ADS7828_CMD_PD1 0x04 /* Internal vref OFF && A/D ON */
30 #define ADS7828_CMD_PD3 0x0C /* Internal vref ON && A/D ON */
31 #define ADS7828_INT_VREF_MV 2500 /* Internal vref is 2.5V, 2500mV */
32 #define ADS7828_EXT_VREF_MV_MIN 50 /* External vref min value 0.05V */
33 #define ADS7828_EXT_VREF_MV_MAX 5250 /* External vref max value 5.25V */
45 /* Command byte C2,C1,C0 - see datasheet */
57 u8 cmd = ads7828_cmd_byte(data->cmd_byte, attr->index); in ads7828_in_show()
61 err = regmap_read(data->regmap, cmd, ®val); in ads7828_in_show()
66 DIV_ROUND_CLOSEST(regval * data->lsb_resol, 1000)); in ads7828_in_show()
104 struct device *dev = &client->dev; in ads7828_probe()
118 return -ENOMEM; in ads7828_probe()
121 diff_input = pdata->diff_input; in ads7828_probe()
122 ext_vref = pdata->ext_vref; in ads7828_probe()
123 if (ext_vref && pdata->vref_mv) in ads7828_probe()
124 vref_mv = pdata->vref_mv; in ads7828_probe()
125 } else if (dev->of_node) { in ads7828_probe()
126 diff_input = of_property_read_bool(dev->of_node, in ads7828_probe()
127 "ti,differential-input"); in ads7828_probe()
128 reg = devm_regulator_get_optional(dev, "vref"); in ads7828_probe()
134 return -EINVAL; in ads7828_probe()
141 /* Bound Vref with min/max values */ in ads7828_probe()
145 /* ADS7828 uses 12-bit samples, while ADS7830 is 8-bit */ in ads7828_probe()
147 data->lsb_resol = DIV_ROUND_CLOSEST(vref_mv * 1000, 4096); in ads7828_probe()
148 data->regmap = devm_regmap_init_i2c(client, in ads7828_probe()
151 data->lsb_resol = DIV_ROUND_CLOSEST(vref_mv * 1000, 256); in ads7828_probe()
152 data->regmap = devm_regmap_init_i2c(client, in ads7828_probe()
156 if (IS_ERR(data->regmap)) in ads7828_probe()
157 return PTR_ERR(data->regmap); in ads7828_probe()
159 data->cmd_byte = ext_vref ? ADS7828_CMD_PD1 : ADS7828_CMD_PD3; in ads7828_probe()
161 data->cmd_byte |= ADS7828_CMD_SD_SE; in ads7828_probe()
170 regmap_read(data->regmap, data->cmd_byte, ®val); in ads7828_probe()
172 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, in ads7828_probe()