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
18 #include "stm32-dac-core.h"
27 * struct stm32_dac - private data of DAC driver
28 * @common: reference to DAC common data
39 struct stm32_dac *dac = iio_priv(indio_dev); in stm32_dac_is_enabled() local
43 ret = regmap_read(dac->common->regmap, STM32_DAC_CR, &val); in stm32_dac_is_enabled()
57 struct stm32_dac *dac = iio_priv(indio_dev); in stm32_dac_set_enable_state() local
58 struct device *dev = indio_dev->dev.parent; in stm32_dac_set_enable_state()
64 mutex_lock(&dac->lock); in stm32_dac_set_enable_state()
67 mutex_unlock(&dac->lock); in stm32_dac_set_enable_state()
74 mutex_unlock(&dac->lock); in stm32_dac_set_enable_state()
79 ret = regmap_update_bits(dac->common->regmap, STM32_DAC_CR, msk, en); in stm32_dac_set_enable_state()
80 mutex_unlock(&dac->lock); in stm32_dac_set_enable_state()
82 dev_err(&indio_dev->dev, "%s failed\n", en ? in stm32_dac_set_enable_state()
92 if (en && dac->common->hfsel) in stm32_dac_set_enable_state()
111 static int stm32_dac_get_value(struct stm32_dac *dac, int channel, int *val) in stm32_dac_get_value() argument
116 ret = regmap_read(dac->common->regmap, STM32_DAC_DOR1, val); in stm32_dac_get_value()
118 ret = regmap_read(dac->common->regmap, STM32_DAC_DOR2, val); in stm32_dac_get_value()
123 static int stm32_dac_set_value(struct stm32_dac *dac, int channel, int val) in stm32_dac_set_value() argument
128 ret = regmap_write(dac->common->regmap, STM32_DAC_DHR12R1, val); in stm32_dac_set_value()
130 ret = regmap_write(dac->common->regmap, STM32_DAC_DHR12R2, val); in stm32_dac_set_value()
139 struct stm32_dac *dac = iio_priv(indio_dev); in stm32_dac_read_raw() local
143 return stm32_dac_get_value(dac, chan->channel, val); in stm32_dac_read_raw()
145 *val = dac->common->vref_mv; in stm32_dac_read_raw()
146 *val2 = chan->scan_type.realbits; in stm32_dac_read_raw()
149 return -EINVAL; in stm32_dac_read_raw()
157 struct stm32_dac *dac = iio_priv(indio_dev); in stm32_dac_write_raw() local
161 return stm32_dac_set_value(dac, chan->channel, val); in stm32_dac_write_raw()
163 return -EINVAL; in stm32_dac_write_raw()
171 struct stm32_dac *dac = iio_priv(indio_dev); in stm32_dac_debugfs_reg_access() local
174 return regmap_write(dac->common->regmap, reg, writeval); in stm32_dac_debugfs_reg_access()
176 return regmap_read(dac->common->regmap, reg, readval); in stm32_dac_debugfs_reg_access()
207 int ret = stm32_dac_is_enabled(indio_dev, chan->channel); in stm32_dac_read_powerdown()
227 ret = stm32_dac_set_enable_state(indio_dev, chan->channel, !powerdown); in stm32_dac_write_powerdown()
278 struct device_node *np = indio_dev->dev.of_node; in stm32_dac_chan_of_init()
285 dev_err(&indio_dev->dev, "Failed to read reg property\n"); in stm32_dac_chan_of_init()
294 dev_err(&indio_dev->dev, "Invalid reg property\n"); in stm32_dac_chan_of_init()
295 return -EINVAL; in stm32_dac_chan_of_init()
298 indio_dev->channels = &stm32_dac_channels[i]; in stm32_dac_chan_of_init()
304 indio_dev->num_channels = 1; in stm32_dac_chan_of_init()
311 struct device_node *np = pdev->dev.of_node; in stm32_dac_probe()
312 struct device *dev = &pdev->dev; in stm32_dac_probe()
314 struct stm32_dac *dac; in stm32_dac_probe() local
318 return -ENODEV; in stm32_dac_probe()
320 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*dac)); in stm32_dac_probe()
322 return -ENOMEM; in stm32_dac_probe()
325 dac = iio_priv(indio_dev); in stm32_dac_probe()
326 dac->common = dev_get_drvdata(pdev->dev.parent); in stm32_dac_probe()
327 indio_dev->name = dev_name(&pdev->dev); in stm32_dac_probe()
328 indio_dev->dev.of_node = pdev->dev.of_node; in stm32_dac_probe()
329 indio_dev->info = &stm32_dac_iio_info; in stm32_dac_probe()
330 indio_dev->modes = INDIO_DIRECT_MODE; in stm32_dac_probe()
332 mutex_init(&dac->lock); in stm32_dac_probe()
338 /* Get stm32-dac-core PM online */ in stm32_dac_probe()
366 pm_runtime_get_sync(&pdev->dev); in stm32_dac_remove()
368 pm_runtime_disable(&pdev->dev); in stm32_dac_remove()
369 pm_runtime_set_suspended(&pdev->dev); in stm32_dac_remove()
370 pm_runtime_put_noidle(&pdev->dev); in stm32_dac_remove()
378 int channel = indio_dev->channels[0].channel; in stm32_dac_suspend()
381 /* Ensure DAC is disabled before suspend */ in stm32_dac_suspend()
384 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");