/** * struct stm32_dac - private data of DAC driver * @common: reference to DAC common data * @lock: lock to protect against potential races when reading * and update CR, to keep it in sync with pm_runtime
*/ struct stm32_dac { struct stm32_dac_common *common; struct mutex lock;
};
staticint stm32_dac_is_enabled(struct iio_dev *indio_dev, int channel)
{ struct stm32_dac *dac = iio_priv(indio_dev);
u32 en, val; int ret;
ret = regmap_read(dac->common->regmap, STM32_DAC_CR, &val); if (ret < 0) return ret; if (STM32_DAC_IS_CHAN_1(channel))
en = FIELD_GET(STM32_DAC_CR_EN1, val); else
en = FIELD_GET(STM32_DAC_CR_EN2, val);
/* already enabled / disabled ? */
mutex_lock(&dac->lock);
ret = stm32_dac_is_enabled(indio_dev, ch); if (ret < 0 || enable == !!ret) {
mutex_unlock(&dac->lock); return ret < 0 ? ret : 0;
}
if (enable) {
ret = pm_runtime_resume_and_get(dev); if (ret < 0) {
mutex_unlock(&dac->lock); return ret;
}
}
ret = regmap_update_bits(dac->common->regmap, STM32_DAC_CR, msk, en);
mutex_unlock(&dac->lock); if (ret < 0) {
dev_err(&indio_dev->dev, "%s failed\n", str_enable_disable(en)); goto err_put_pm;
}
/* * When HFSEL is set, it is not allowed to write the DHRx register * during 8 clock cycles after the ENx bit is set. It is not allowed * to make software/hardware trigger during this period either.
*/ if (en && dac->common->hfsel)
udelay(1);
if (!enable) {
pm_runtime_mark_last_busy(dev);
pm_runtime_put_autosuspend(dev);
}
return 0;
err_put_pm: if (enable) {
pm_runtime_mark_last_busy(dev);
pm_runtime_put_autosuspend(dev);
}
return ret;
}
staticint stm32_dac_get_value(struct stm32_dac *dac, int channel, int *val)
{ int ret;
if (STM32_DAC_IS_CHAN_1(channel))
ret = regmap_read(dac->common->regmap, STM32_DAC_DOR1, val); else
ret = regmap_read(dac->common->regmap, STM32_DAC_DOR2, val);
return ret ? ret : IIO_VAL_INT;
}
staticint stm32_dac_set_value(struct stm32_dac *dac, int channel, int val)
{ int ret;
if (STM32_DAC_IS_CHAN_1(channel))
ret = regmap_write(dac->common->regmap, STM32_DAC_DHR12R1, val); else
ret = regmap_write(dac->common->regmap, STM32_DAC_DHR12R2, val);
return ret;
}
staticint stm32_dac_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask)
{ struct stm32_dac *dac = iio_priv(indio_dev);
ret = of_property_read_u32(np, "reg", &channel); if (ret) {
dev_err(&indio_dev->dev, "Failed to read reg property\n"); return ret;
}
for (i = 0; i < ARRAY_SIZE(stm32_dac_channels); i++) { if (stm32_dac_channels[i].channel == channel) break;
} if (i >= ARRAY_SIZE(stm32_dac_channels)) {
dev_err(&indio_dev->dev, "Invalid reg property\n"); return -EINVAL;
}
indio_dev->channels = &stm32_dac_channels[i]; /* * Expose only one channel here, as they can be used independently, * with separate trigger. Then separate IIO devices are instantiated * to manage this.
*/
indio_dev->num_channels = 1;
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.