Lines Matching +full:clkout +full:- +full:disable
1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
20 #include "stm32-dfsdm.h"
88 unsigned int spi_clk_out_div; /* SPI clkout divider value */
105 ret = clk_prepare_enable(priv->clk); in stm32_dfsdm_clk_prepare_enable()
106 if (ret || !priv->aclk) in stm32_dfsdm_clk_prepare_enable()
109 ret = clk_prepare_enable(priv->aclk); in stm32_dfsdm_clk_prepare_enable()
111 clk_disable_unprepare(priv->clk); in stm32_dfsdm_clk_prepare_enable()
120 clk_disable_unprepare(priv->aclk); in stm32_dfsdm_clk_disable_unprepare()
121 clk_disable_unprepare(priv->clk); in stm32_dfsdm_clk_disable_unprepare()
125 * stm32_dfsdm_start_dfsdm - start global dfsdm interface.
133 struct device *dev = &priv->pdev->dev; in stm32_dfsdm_start_dfsdm()
134 unsigned int clk_div = priv->spi_clk_out_div, clk_src; in stm32_dfsdm_start_dfsdm()
137 if (atomic_inc_return(&priv->n_active_ch) == 1) { in stm32_dfsdm_start_dfsdm()
143 clk_src = priv->aclk ? 1 : 0; in stm32_dfsdm_start_dfsdm()
144 ret = regmap_update_bits(dfsdm->regmap, DFSDM_CHCFGR1(0), in stm32_dfsdm_start_dfsdm()
150 /* Output the SPI CLKOUT (if clk_div == 0 clock if OFF) */ in stm32_dfsdm_start_dfsdm()
151 ret = regmap_update_bits(dfsdm->regmap, DFSDM_CHCFGR1(0), in stm32_dfsdm_start_dfsdm()
158 ret = regmap_update_bits(dfsdm->regmap, DFSDM_CHCFGR1(0), in stm32_dfsdm_start_dfsdm()
166 atomic_read(&priv->n_active_ch)); in stm32_dfsdm_start_dfsdm()
173 atomic_dec(&priv->n_active_ch); in stm32_dfsdm_start_dfsdm()
180 * stm32_dfsdm_stop_dfsdm - stop global DFSDM interface.
182 * Disable interface if n_active_ch is null
190 if (atomic_dec_and_test(&priv->n_active_ch)) { in stm32_dfsdm_stop_dfsdm()
191 /* Global disable of DFSDM interface */ in stm32_dfsdm_stop_dfsdm()
192 ret = regmap_update_bits(dfsdm->regmap, DFSDM_CHCFGR1(0), in stm32_dfsdm_stop_dfsdm()
198 /* Stop SPI CLKOUT */ in stm32_dfsdm_stop_dfsdm()
199 ret = regmap_update_bits(dfsdm->regmap, DFSDM_CHCFGR1(0), in stm32_dfsdm_stop_dfsdm()
205 pm_runtime_put_sync(&priv->pdev->dev); in stm32_dfsdm_stop_dfsdm()
207 dev_dbg(&priv->pdev->dev, "%s: n_active_ch %d\n", __func__, in stm32_dfsdm_stop_dfsdm()
208 atomic_read(&priv->n_active_ch)); in stm32_dfsdm_stop_dfsdm()
217 struct device_node *node = pdev->dev.of_node; in stm32_dfsdm_parse_of()
224 return -EINVAL; in stm32_dfsdm_parse_of()
226 priv->dfsdm.base = devm_platform_get_and_ioremap_resource(pdev, 0, in stm32_dfsdm_parse_of()
228 if (IS_ERR(priv->dfsdm.base)) in stm32_dfsdm_parse_of()
229 return PTR_ERR(priv->dfsdm.base); in stm32_dfsdm_parse_of()
231 priv->dfsdm.phys_base = res->start; in stm32_dfsdm_parse_of()
239 priv->clk = devm_clk_get(&pdev->dev, "dfsdm"); in stm32_dfsdm_parse_of()
240 if (IS_ERR(priv->clk)) in stm32_dfsdm_parse_of()
241 return dev_err_probe(&pdev->dev, PTR_ERR(priv->clk), in stm32_dfsdm_parse_of()
244 priv->aclk = devm_clk_get(&pdev->dev, "audio"); in stm32_dfsdm_parse_of()
245 if (IS_ERR(priv->aclk)) in stm32_dfsdm_parse_of()
246 priv->aclk = NULL; in stm32_dfsdm_parse_of()
248 if (priv->aclk) in stm32_dfsdm_parse_of()
249 clk_freq = clk_get_rate(priv->aclk); in stm32_dfsdm_parse_of()
251 clk_freq = clk_get_rate(priv->clk); in stm32_dfsdm_parse_of()
254 ret = of_property_read_u32(pdev->dev.of_node, "spi-max-frequency", in stm32_dfsdm_parse_of()
268 dev_err(&pdev->dev, "spi-max-frequency not achievable\n"); in stm32_dfsdm_parse_of()
269 return -EINVAL; in stm32_dfsdm_parse_of()
273 priv->spi_clk_out_div = divider - 1; in stm32_dfsdm_parse_of()
274 priv->dfsdm.spi_master_freq = clk_freq / (priv->spi_clk_out_div + 1); in stm32_dfsdm_parse_of()
277 dev_warn(&pdev->dev, "SPI clock not accurate\n"); in stm32_dfsdm_parse_of()
278 dev_warn(&pdev->dev, "%ld = %d * %d + %d\n", in stm32_dfsdm_parse_of()
279 clk_freq, spi_freq, priv->spi_clk_out_div + 1, rem); in stm32_dfsdm_parse_of()
287 .compatible = "st,stm32h7-dfsdm",
291 .compatible = "st,stm32mp1-dfsdm",
305 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); in stm32_dfsdm_probe()
307 return -ENOMEM; in stm32_dfsdm_probe()
309 priv->pdev = pdev; in stm32_dfsdm_probe()
311 dev_data = of_device_get_match_data(&pdev->dev); in stm32_dfsdm_probe()
313 dfsdm = &priv->dfsdm; in stm32_dfsdm_probe()
314 dfsdm->fl_list = devm_kcalloc(&pdev->dev, dev_data->num_filters, in stm32_dfsdm_probe()
315 sizeof(*dfsdm->fl_list), GFP_KERNEL); in stm32_dfsdm_probe()
316 if (!dfsdm->fl_list) in stm32_dfsdm_probe()
317 return -ENOMEM; in stm32_dfsdm_probe()
319 dfsdm->num_fls = dev_data->num_filters; in stm32_dfsdm_probe()
320 dfsdm->ch_list = devm_kcalloc(&pdev->dev, dev_data->num_channels, in stm32_dfsdm_probe()
321 sizeof(*dfsdm->ch_list), in stm32_dfsdm_probe()
323 if (!dfsdm->ch_list) in stm32_dfsdm_probe()
324 return -ENOMEM; in stm32_dfsdm_probe()
325 dfsdm->num_chs = dev_data->num_channels; in stm32_dfsdm_probe()
331 dfsdm->regmap = devm_regmap_init_mmio_clk(&pdev->dev, "dfsdm", in stm32_dfsdm_probe()
332 dfsdm->base, in stm32_dfsdm_probe()
333 dev_data->regmap_cfg); in stm32_dfsdm_probe()
334 if (IS_ERR(dfsdm->regmap)) { in stm32_dfsdm_probe()
335 ret = PTR_ERR(dfsdm->regmap); in stm32_dfsdm_probe()
336 dev_err(&pdev->dev, "%s: Failed to allocate regmap: %d\n", in stm32_dfsdm_probe()
345 dev_err(&pdev->dev, "Failed to start clock\n"); in stm32_dfsdm_probe()
349 pm_runtime_get_noresume(&pdev->dev); in stm32_dfsdm_probe()
350 pm_runtime_set_active(&pdev->dev); in stm32_dfsdm_probe()
351 pm_runtime_enable(&pdev->dev); in stm32_dfsdm_probe()
353 ret = of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev); in stm32_dfsdm_probe()
357 pm_runtime_put(&pdev->dev); in stm32_dfsdm_probe()
362 pm_runtime_disable(&pdev->dev); in stm32_dfsdm_probe()
363 pm_runtime_set_suspended(&pdev->dev); in stm32_dfsdm_probe()
364 pm_runtime_put_noidle(&pdev->dev); in stm32_dfsdm_probe()
374 pm_runtime_get_sync(&pdev->dev); in stm32_dfsdm_core_remove()
375 of_platform_depopulate(&pdev->dev); in stm32_dfsdm_core_remove()
376 pm_runtime_disable(&pdev->dev); in stm32_dfsdm_core_remove()
377 pm_runtime_set_suspended(&pdev->dev); in stm32_dfsdm_core_remove()
378 pm_runtime_put_noidle(&pdev->dev); in stm32_dfsdm_core_remove()
395 clk_unprepare(priv->clk); in stm32_dfsdm_core_suspend()
410 ret = clk_prepare(priv->clk); in stm32_dfsdm_core_resume()
444 .name = "stm32-dfsdm",