/* * The BD79703 uses 12-bit SPI commands. First four bits (high bits) define * channel(s) which are operated on, and also the mode. The mode can be to set * a DAC word only, or set DAC word and output. The data-sheet is not very * specific on how a previously set DAC word can be 'taken in to use'. Thus * this driver only uses the 'set DAC and output it' -mode. * * The BD79703 latches last 12-bits when the chip-select is toggled. Thus we * can use 16-bit transfers which should be widely supported. To simplify this * further, we treat the last 8 bits as a value, and first 8 bits as an * address. This allows us to separate channels/mode by address and treat the * 8-bit register value as DAC word. The highest 4 bits of address will be * discarded when the transfer is latched.
*/ staticconststruct regmap_config bd79703_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
.max_register = BD79703_MAX_REGISTER,
.cache_type = REGCACHE_MAPLE,
};
/* Dynamic driver private data */ struct bd79703_data { struct regmap *regmap; int vfs;
};
/* Static, IC type specific data for different variants */ struct bd7970x_chip_data { constchar *name; conststruct iio_chan_spec *channels; int num_channels; bool has_vfs;
};
staticint bd79703_read_raw(struct iio_dev *idev, struct iio_chan_spec const *chan, int *val, int *val2, long mask)
{ struct bd79703_data *data = iio_priv(idev);
/* * The BD79702 has 4 channels. They aren't mapped to BD79703 channels 0, 1, 2 * and 3, but to the channels 0, 1, 4, 5. So the addressing used with SPI * accesses is 1, 2, 5 and 6 for them. Thus, they're not constant offset to * the channel number as with other IC variants.
*/ staticconststruct iio_chan_spec bd79702_channels[] = {
BD79703_CHAN_ADDR(0, 1),
BD79703_CHAN_ADDR(1, 2),
BD79703_CHAN_ADDR(2, 5),
BD79703_CHAN_ADDR(3, 6),
};
cd = spi_get_device_match_data(spi); if (!cd) return -ENODEV;
idev = devm_iio_device_alloc(dev, sizeof(*data)); if (!idev) return -ENOMEM;
data = iio_priv(idev);
data->regmap = devm_regmap_init_spi(spi, &bd79703_regmap_config); if (IS_ERR(data->regmap)) return dev_err_probe(dev, PTR_ERR(data->regmap), "Failed to initialize Regmap\n");
/* * BD79703 has a separate VFS pin, whereas the BD79700 and BD79701 use * VCC for their full-scale output voltage.
*/ if (cd->has_vfs) {
ret = devm_regulator_get_enable(dev, "vcc"); if (ret) return dev_err_probe(dev, ret, "Failed to enable VCC\n");
ret = devm_regulator_get_enable_read_voltage(dev, "vfs"); if (ret < 0) return dev_err_probe(dev, ret, "Failed to get Vfs\n");
} else {
ret = devm_regulator_get_enable_read_voltage(dev, "vcc"); if (ret < 0) return dev_err_probe(dev, ret, "Failed to get VCC\n");
}
data->vfs = ret;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.