Lines Matching +full:stm32 +full:- +full:dac
1 // SPDX-License-Identifier: GPL-2.0
3 * This file is part of STM32 DAC driver
5 * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
22 #include "stm32-dac-core.h"
31 * struct stm32_dac - private data of DAC driver
32 * @common: reference to DAC common data
43 struct stm32_dac *dac = iio_priv(indio_dev); in stm32_dac_is_enabled() local
47 ret = regmap_read(dac->common->regmap, STM32_DAC_CR, &val); in stm32_dac_is_enabled()
61 struct stm32_dac *dac = iio_priv(indio_dev); in stm32_dac_set_enable_state() local
62 struct device *dev = indio_dev->dev.parent; in stm32_dac_set_enable_state()
68 mutex_lock(&dac->lock); in stm32_dac_set_enable_state()
71 mutex_unlock(&dac->lock); in stm32_dac_set_enable_state()
78 mutex_unlock(&dac->lock); in stm32_dac_set_enable_state()
83 ret = regmap_update_bits(dac->common->regmap, STM32_DAC_CR, msk, en); in stm32_dac_set_enable_state()
84 mutex_unlock(&dac->lock); in stm32_dac_set_enable_state()
86 dev_err(&indio_dev->dev, "%s failed\n", str_enable_disable(en)); in stm32_dac_set_enable_state()
95 if (en && dac->common->hfsel) in stm32_dac_set_enable_state()
114 static int stm32_dac_get_value(struct stm32_dac *dac, int channel, int *val) in stm32_dac_get_value() argument
119 ret = regmap_read(dac->common->regmap, STM32_DAC_DOR1, val); in stm32_dac_get_value()
121 ret = regmap_read(dac->common->regmap, STM32_DAC_DOR2, val); in stm32_dac_get_value()
126 static int stm32_dac_set_value(struct stm32_dac *dac, int channel, int val) in stm32_dac_set_value() argument
131 ret = regmap_write(dac->common->regmap, STM32_DAC_DHR12R1, val); in stm32_dac_set_value()
133 ret = regmap_write(dac->common->regmap, STM32_DAC_DHR12R2, val); in stm32_dac_set_value()
142 struct stm32_dac *dac = iio_priv(indio_dev); in stm32_dac_read_raw() local
146 return stm32_dac_get_value(dac, chan->channel, val); in stm32_dac_read_raw()
148 *val = dac->common->vref_mv; in stm32_dac_read_raw()
149 *val2 = chan->scan_type.realbits; in stm32_dac_read_raw()
152 return -EINVAL; in stm32_dac_read_raw()
160 struct stm32_dac *dac = iio_priv(indio_dev); in stm32_dac_write_raw() local
164 return stm32_dac_set_value(dac, chan->channel, val); in stm32_dac_write_raw()
166 return -EINVAL; in stm32_dac_write_raw()
174 struct stm32_dac *dac = iio_priv(indio_dev); in stm32_dac_debugfs_reg_access() local
177 return regmap_write(dac->common->regmap, reg, writeval); in stm32_dac_debugfs_reg_access()
179 return regmap_read(dac->common->regmap, reg, readval); in stm32_dac_debugfs_reg_access()
210 int ret = stm32_dac_is_enabled(indio_dev, chan->channel); in stm32_dac_read_powerdown()
230 ret = stm32_dac_set_enable_state(indio_dev, chan->channel, !powerdown); in stm32_dac_write_powerdown()
281 struct device_node *np = indio_dev->dev.of_node; in stm32_dac_chan_of_init()
288 dev_err(&indio_dev->dev, "Failed to read reg property\n"); in stm32_dac_chan_of_init()
297 dev_err(&indio_dev->dev, "Invalid reg property\n"); in stm32_dac_chan_of_init()
298 return -EINVAL; in stm32_dac_chan_of_init()
301 indio_dev->channels = &stm32_dac_channels[i]; in stm32_dac_chan_of_init()
307 indio_dev->num_channels = 1; in stm32_dac_chan_of_init()
314 struct device_node *np = pdev->dev.of_node; in stm32_dac_probe()
315 struct device *dev = &pdev->dev; in stm32_dac_probe()
317 struct stm32_dac *dac; in stm32_dac_probe() local
321 return -ENODEV; in stm32_dac_probe()
323 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*dac)); in stm32_dac_probe()
325 return -ENOMEM; in stm32_dac_probe()
328 dac = iio_priv(indio_dev); in stm32_dac_probe()
329 dac->common = dev_get_drvdata(pdev->dev.parent); in stm32_dac_probe()
330 indio_dev->name = dev_name(&pdev->dev); in stm32_dac_probe()
331 indio_dev->dev.of_node = pdev->dev.of_node; in stm32_dac_probe()
332 indio_dev->info = &stm32_dac_iio_info; in stm32_dac_probe()
333 indio_dev->modes = INDIO_DIRECT_MODE; in stm32_dac_probe()
335 mutex_init(&dac->lock); in stm32_dac_probe()
341 /* Get stm32-dac-core PM online */ in stm32_dac_probe()
369 pm_runtime_get_sync(&pdev->dev); in stm32_dac_remove()
371 pm_runtime_disable(&pdev->dev); in stm32_dac_remove()
372 pm_runtime_set_suspended(&pdev->dev); in stm32_dac_remove()
373 pm_runtime_put_noidle(&pdev->dev); in stm32_dac_remove()
379 int channel = indio_dev->channels[0].channel; in stm32_dac_suspend()
382 /* Ensure DAC is disabled before suspend */ in stm32_dac_suspend()
385 return ret < 0 ? ret : -EBUSY; in stm32_dac_suspend()
394 { .compatible = "st,stm32-dac", },
403 .name = "stm32-dac",
410 MODULE_ALIAS("platform:stm32-dac");
412 MODULE_DESCRIPTION("STMicroelectronics STM32 DAC driver");