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
21 #include "stm32-dac-core.h"
30 * struct stm32_dac - private data of DAC driver
31 * @common: reference to DAC common data
42 struct stm32_dac *dac = iio_priv(indio_dev); in stm32_dac_is_enabled() local
46 ret = regmap_read(dac->common->regmap, STM32_DAC_CR, &val); in stm32_dac_is_enabled()
60 struct stm32_dac *dac = iio_priv(indio_dev); in stm32_dac_set_enable_state() local
61 struct device *dev = indio_dev->dev.parent; in stm32_dac_set_enable_state()
67 mutex_lock(&dac->lock); in stm32_dac_set_enable_state()
70 mutex_unlock(&dac->lock); in stm32_dac_set_enable_state()
77 mutex_unlock(&dac->lock); in stm32_dac_set_enable_state()
82 ret = regmap_update_bits(dac->common->regmap, STM32_DAC_CR, msk, en); in stm32_dac_set_enable_state()
83 mutex_unlock(&dac->lock); in stm32_dac_set_enable_state()
85 dev_err(&indio_dev->dev, "%s failed\n", str_enable_disable(en)); in stm32_dac_set_enable_state()
94 if (en && dac->common->hfsel) in stm32_dac_set_enable_state()
113 static int stm32_dac_get_value(struct stm32_dac *dac, int channel, int *val) in stm32_dac_get_value() argument
118 ret = regmap_read(dac->common->regmap, STM32_DAC_DOR1, val); in stm32_dac_get_value()
120 ret = regmap_read(dac->common->regmap, STM32_DAC_DOR2, val); in stm32_dac_get_value()
125 static int stm32_dac_set_value(struct stm32_dac *dac, int channel, int val) in stm32_dac_set_value() argument
130 ret = regmap_write(dac->common->regmap, STM32_DAC_DHR12R1, val); in stm32_dac_set_value()
132 ret = regmap_write(dac->common->regmap, STM32_DAC_DHR12R2, val); in stm32_dac_set_value()
141 struct stm32_dac *dac = iio_priv(indio_dev); in stm32_dac_read_raw() local
145 return stm32_dac_get_value(dac, chan->channel, val); in stm32_dac_read_raw()
147 *val = dac->common->vref_mv; in stm32_dac_read_raw()
148 *val2 = chan->scan_type.realbits; in stm32_dac_read_raw()
151 return -EINVAL; in stm32_dac_read_raw()
159 struct stm32_dac *dac = iio_priv(indio_dev); in stm32_dac_write_raw() local
163 return stm32_dac_set_value(dac, chan->channel, val); in stm32_dac_write_raw()
165 return -EINVAL; in stm32_dac_write_raw()
173 struct stm32_dac *dac = iio_priv(indio_dev); in stm32_dac_debugfs_reg_access() local
176 return regmap_write(dac->common->regmap, reg, writeval); in stm32_dac_debugfs_reg_access()
178 return regmap_read(dac->common->regmap, reg, readval); in stm32_dac_debugfs_reg_access()
209 int ret = stm32_dac_is_enabled(indio_dev, chan->channel); in stm32_dac_read_powerdown()
229 ret = stm32_dac_set_enable_state(indio_dev, chan->channel, !powerdown); in stm32_dac_write_powerdown()
280 struct device_node *np = indio_dev->dev.of_node; in stm32_dac_chan_of_init()
287 dev_err(&indio_dev->dev, "Failed to read reg property\n"); in stm32_dac_chan_of_init()
296 dev_err(&indio_dev->dev, "Invalid reg property\n"); in stm32_dac_chan_of_init()
297 return -EINVAL; in stm32_dac_chan_of_init()
300 indio_dev->channels = &stm32_dac_channels[i]; in stm32_dac_chan_of_init()
306 indio_dev->num_channels = 1; in stm32_dac_chan_of_init()
313 struct device_node *np = pdev->dev.of_node; in stm32_dac_probe()
314 struct device *dev = &pdev->dev; in stm32_dac_probe()
316 struct stm32_dac *dac; in stm32_dac_probe() local
320 return -ENODEV; in stm32_dac_probe()
322 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*dac)); in stm32_dac_probe()
324 return -ENOMEM; in stm32_dac_probe()
327 dac = iio_priv(indio_dev); in stm32_dac_probe()
328 dac->common = dev_get_drvdata(pdev->dev.parent); in stm32_dac_probe()
329 indio_dev->name = dev_name(&pdev->dev); in stm32_dac_probe()
330 indio_dev->dev.of_node = pdev->dev.of_node; in stm32_dac_probe()
331 indio_dev->info = &stm32_dac_iio_info; in stm32_dac_probe()
332 indio_dev->modes = INDIO_DIRECT_MODE; in stm32_dac_probe()
334 mutex_init(&dac->lock); in stm32_dac_probe()
340 /* Get stm32-dac-core PM online */ in stm32_dac_probe()
368 pm_runtime_get_sync(&pdev->dev); in stm32_dac_remove()
370 pm_runtime_disable(&pdev->dev); in stm32_dac_remove()
371 pm_runtime_set_suspended(&pdev->dev); in stm32_dac_remove()
372 pm_runtime_put_noidle(&pdev->dev); in stm32_dac_remove()
380 int channel = indio_dev->channels[0].channel; in stm32_dac_suspend()
383 /* Ensure DAC is disabled before suspend */ in stm32_dac_suspend()
386 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");