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()
75 mutex_unlock(&dac->lock); in stm32_dac_set_enable_state()
80 ret = regmap_update_bits(dac->common->regmap, STM32_DAC_CR, msk, en); in stm32_dac_set_enable_state()
81 mutex_unlock(&dac->lock); in stm32_dac_set_enable_state()
83 dev_err(&indio_dev->dev, "%s failed\n", en ? in stm32_dac_set_enable_state()
93 if (en && dac->common->hfsel) in stm32_dac_set_enable_state()
112 static int stm32_dac_get_value(struct stm32_dac *dac, int channel, int *val) in stm32_dac_get_value() argument
117 ret = regmap_read(dac->common->regmap, STM32_DAC_DOR1, val); in stm32_dac_get_value()
119 ret = regmap_read(dac->common->regmap, STM32_DAC_DOR2, val); in stm32_dac_get_value()
124 static int stm32_dac_set_value(struct stm32_dac *dac, int channel, int val) in stm32_dac_set_value() argument
129 ret = regmap_write(dac->common->regmap, STM32_DAC_DHR12R1, val); in stm32_dac_set_value()
131 ret = regmap_write(dac->common->regmap, STM32_DAC_DHR12R2, val); in stm32_dac_set_value()
140 struct stm32_dac *dac = iio_priv(indio_dev); in stm32_dac_read_raw() local
144 return stm32_dac_get_value(dac, chan->channel, val); in stm32_dac_read_raw()
146 *val = dac->common->vref_mv; in stm32_dac_read_raw()
147 *val2 = chan->scan_type.realbits; in stm32_dac_read_raw()
150 return -EINVAL; in stm32_dac_read_raw()
158 struct stm32_dac *dac = iio_priv(indio_dev); in stm32_dac_write_raw() local
162 return stm32_dac_set_value(dac, chan->channel, val); in stm32_dac_write_raw()
164 return -EINVAL; in stm32_dac_write_raw()
172 struct stm32_dac *dac = iio_priv(indio_dev); in stm32_dac_debugfs_reg_access() local
175 return regmap_write(dac->common->regmap, reg, writeval); in stm32_dac_debugfs_reg_access()
177 return regmap_read(dac->common->regmap, reg, readval); in stm32_dac_debugfs_reg_access()
208 int ret = stm32_dac_is_enabled(indio_dev, chan->channel); in stm32_dac_read_powerdown()
228 ret = stm32_dac_set_enable_state(indio_dev, chan->channel, !powerdown); in stm32_dac_write_powerdown()
279 struct device_node *np = indio_dev->dev.of_node; in stm32_dac_chan_of_init()
286 dev_err(&indio_dev->dev, "Failed to read reg property\n"); in stm32_dac_chan_of_init()
295 dev_err(&indio_dev->dev, "Invalid reg property\n"); in stm32_dac_chan_of_init()
296 return -EINVAL; in stm32_dac_chan_of_init()
299 indio_dev->channels = &stm32_dac_channels[i]; in stm32_dac_chan_of_init()
305 indio_dev->num_channels = 1; in stm32_dac_chan_of_init()
312 struct device_node *np = pdev->dev.of_node; in stm32_dac_probe()
313 struct device *dev = &pdev->dev; in stm32_dac_probe()
315 struct stm32_dac *dac; in stm32_dac_probe() local
319 return -ENODEV; in stm32_dac_probe()
321 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*dac)); in stm32_dac_probe()
323 return -ENOMEM; in stm32_dac_probe()
326 dac = iio_priv(indio_dev); in stm32_dac_probe()
327 dac->common = dev_get_drvdata(pdev->dev.parent); in stm32_dac_probe()
328 indio_dev->name = dev_name(&pdev->dev); in stm32_dac_probe()
329 indio_dev->dev.of_node = pdev->dev.of_node; in stm32_dac_probe()
330 indio_dev->info = &stm32_dac_iio_info; in stm32_dac_probe()
331 indio_dev->modes = INDIO_DIRECT_MODE; in stm32_dac_probe()
333 mutex_init(&dac->lock); in stm32_dac_probe()
339 /* Get stm32-dac-core PM online */ in stm32_dac_probe()
367 pm_runtime_get_sync(&pdev->dev); in stm32_dac_remove()
369 pm_runtime_disable(&pdev->dev); in stm32_dac_remove()
370 pm_runtime_set_suspended(&pdev->dev); in stm32_dac_remove()
371 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()
395 { .compatible = "st,stm32-dac", },
404 .name = "stm32-dac",
411 MODULE_ALIAS("platform:stm32-dac");
413 MODULE_DESCRIPTION("STMicroelectronics STM32 DAC driver");