drivers/iio/dac/stm32-dac.c
Source file repositories/reference/linux-study-clean/drivers/iio/dac/stm32-dac.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/dac/stm32-dac.c- Extension
.c- Size
- 9991 bytes
- Lines
- 405
- Domain
- Driver Families
- Bucket
- drivers/iio
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitfield.hlinux/delay.hlinux/iio/iio.hlinux/kernel.hlinux/kstrtox.hlinux/module.hlinux/mod_devicetable.hlinux/of.hlinux/platform_device.hlinux/pm_runtime.hlinux/string_choices.hstm32-dac-core.h
Detected Declarations
struct stm32_dacfunction stm32_dac_is_enabledfunction stm32_dac_set_enable_statefunction stm32_dac_get_valuefunction stm32_dac_set_valuefunction stm32_dac_read_rawfunction stm32_dac_write_rawfunction stm32_dac_debugfs_reg_accessfunction stm32_dac_get_powerdown_modefunction stm32_dac_set_powerdown_modefunction stm32_dac_read_powerdownfunction stm32_dac_write_powerdownfunction stm32_dac_chan_of_initfunction stm32_dac_probefunction stm32_dac_removefunction stm32_dac_suspend
Annotated Snippet
struct stm32_dac {
struct stm32_dac_common *common;
struct mutex lock;
};
static int 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);
return !!en;
}
static int stm32_dac_set_enable_state(struct iio_dev *indio_dev, int ch,
bool enable)
{
struct stm32_dac *dac = iio_priv(indio_dev);
struct device *dev = indio_dev->dev.parent;
u32 msk = STM32_DAC_IS_CHAN_1(ch) ? STM32_DAC_CR_EN1 : STM32_DAC_CR_EN2;
u32 en = enable ? msk : 0;
int ret;
/* 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) {
dev_err(&indio_dev->dev, "%s failed\n", str_enable_disable(en));
if (enable)
pm_runtime_put_autosuspend(dev);
return ret;
}
/*
* 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_put_autosuspend(dev);
return 0;
}
static int 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;
}
static int 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);
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/delay.h`, `linux/iio/iio.h`, `linux/kernel.h`, `linux/kstrtox.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/of.h`.
- Detected declarations: `struct stm32_dac`, `function stm32_dac_is_enabled`, `function stm32_dac_set_enable_state`, `function stm32_dac_get_value`, `function stm32_dac_set_value`, `function stm32_dac_read_raw`, `function stm32_dac_write_raw`, `function stm32_dac_debugfs_reg_access`, `function stm32_dac_get_powerdown_mode`, `function stm32_dac_set_powerdown_mode`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.