Lines Matching +full:vref +full:- +full:internal
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()
106 struct device *dev = &client->dev; in ads7828_probe()
120 return -ENOMEM; in ads7828_probe()
123 diff_input = pdata->diff_input; in ads7828_probe()
124 ext_vref = pdata->ext_vref; in ads7828_probe()
125 if (ext_vref && pdata->vref_mv) in ads7828_probe()
126 vref_mv = pdata->vref_mv; in ads7828_probe()
127 } else if (dev->of_node) { in ads7828_probe()
128 diff_input = of_property_read_bool(dev->of_node, in ads7828_probe()
129 "ti,differential-input"); in ads7828_probe()
130 reg = devm_regulator_get_optional(dev, "vref"); in ads7828_probe()
136 return -EINVAL; in ads7828_probe()
141 if (client->dev.of_node) in ads7828_probe()
142 chip = (uintptr_t)of_device_get_match_data(&client->dev); in ads7828_probe()
144 chip = i2c_match_id(ads7828_device_ids, client)->driver_data; in ads7828_probe()
146 /* Bound Vref with min/max values */ in ads7828_probe()
150 /* ADS7828 uses 12-bit samples, while ADS7830 is 8-bit */ in ads7828_probe()
152 data->lsb_resol = DIV_ROUND_CLOSEST(vref_mv * 1000, 4096); in ads7828_probe()
153 data->regmap = devm_regmap_init_i2c(client, in ads7828_probe()
156 data->lsb_resol = DIV_ROUND_CLOSEST(vref_mv * 1000, 256); in ads7828_probe()
157 data->regmap = devm_regmap_init_i2c(client, in ads7828_probe()
161 if (IS_ERR(data->regmap)) in ads7828_probe()
162 return PTR_ERR(data->regmap); in ads7828_probe()
164 data->cmd_byte = ext_vref ? ADS7828_CMD_PD1 : ADS7828_CMD_PD3; in ads7828_probe()
166 data->cmd_byte |= ADS7828_CMD_SD_SE; in ads7828_probe()
169 * Datasheet specifies internal reference voltage is disabled by in ads7828_probe()
170 * default. The internal reference voltage needs to be enabled and in ads7828_probe()
172 * dummy read to enable the internal reference voltage. in ads7828_probe()
175 regmap_read(data->regmap, data->cmd_byte, ®val); in ads7828_probe()
177 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, in ads7828_probe()