Lines Matching +full:stm32h7 +full:- +full:sai
1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
23 #include "stm32-dfsdm.h"
26 * struct stm32_dfsdm_dev_data - DFSDM compatible configuration data
30 * @regmap_cfg: SAI register map configuration pointer
113 ret = clk_prepare_enable(priv->clk); in stm32_dfsdm_clk_prepare_enable()
114 if (ret || !priv->aclk) in stm32_dfsdm_clk_prepare_enable()
117 ret = clk_prepare_enable(priv->aclk); in stm32_dfsdm_clk_prepare_enable()
119 clk_disable_unprepare(priv->clk); in stm32_dfsdm_clk_prepare_enable()
128 clk_disable_unprepare(priv->aclk); in stm32_dfsdm_clk_disable_unprepare()
129 clk_disable_unprepare(priv->clk); in stm32_dfsdm_clk_disable_unprepare()
133 * stm32_dfsdm_start_dfsdm - start global dfsdm interface.
141 struct device *dev = &priv->pdev->dev; in stm32_dfsdm_start_dfsdm()
142 unsigned int clk_div = priv->spi_clk_out_div, clk_src; in stm32_dfsdm_start_dfsdm()
145 if (atomic_inc_return(&priv->n_active_ch) == 1) { in stm32_dfsdm_start_dfsdm()
151 clk_src = priv->aclk ? 1 : 0; in stm32_dfsdm_start_dfsdm()
152 ret = regmap_update_bits(dfsdm->regmap, DFSDM_CHCFGR1(0), in stm32_dfsdm_start_dfsdm()
159 ret = regmap_update_bits(dfsdm->regmap, DFSDM_CHCFGR1(0), in stm32_dfsdm_start_dfsdm()
166 ret = regmap_update_bits(dfsdm->regmap, DFSDM_CHCFGR1(0), in stm32_dfsdm_start_dfsdm()
174 atomic_read(&priv->n_active_ch)); in stm32_dfsdm_start_dfsdm()
181 atomic_dec(&priv->n_active_ch); in stm32_dfsdm_start_dfsdm()
188 * stm32_dfsdm_stop_dfsdm - stop global DFSDM interface.
198 if (atomic_dec_and_test(&priv->n_active_ch)) { in stm32_dfsdm_stop_dfsdm()
200 ret = regmap_update_bits(dfsdm->regmap, DFSDM_CHCFGR1(0), in stm32_dfsdm_stop_dfsdm()
207 ret = regmap_update_bits(dfsdm->regmap, DFSDM_CHCFGR1(0), in stm32_dfsdm_stop_dfsdm()
213 pm_runtime_put_sync(&priv->pdev->dev); in stm32_dfsdm_stop_dfsdm()
215 dev_dbg(&priv->pdev->dev, "%s: n_active_ch %d\n", __func__, in stm32_dfsdm_stop_dfsdm()
216 atomic_read(&priv->n_active_ch)); in stm32_dfsdm_stop_dfsdm()
225 struct device_node *node = pdev->dev.of_node; in stm32_dfsdm_parse_of()
232 return -EINVAL; in stm32_dfsdm_parse_of()
234 priv->dfsdm.base = devm_platform_get_and_ioremap_resource(pdev, 0, in stm32_dfsdm_parse_of()
236 if (IS_ERR(priv->dfsdm.base)) in stm32_dfsdm_parse_of()
237 return PTR_ERR(priv->dfsdm.base); in stm32_dfsdm_parse_of()
239 priv->dfsdm.phys_base = res->start; in stm32_dfsdm_parse_of()
247 priv->clk = devm_clk_get(&pdev->dev, "dfsdm"); in stm32_dfsdm_parse_of()
248 if (IS_ERR(priv->clk)) in stm32_dfsdm_parse_of()
249 return dev_err_probe(&pdev->dev, PTR_ERR(priv->clk), in stm32_dfsdm_parse_of()
252 priv->aclk = devm_clk_get(&pdev->dev, "audio"); in stm32_dfsdm_parse_of()
253 if (IS_ERR(priv->aclk)) in stm32_dfsdm_parse_of()
254 priv->aclk = NULL; in stm32_dfsdm_parse_of()
256 if (priv->aclk) in stm32_dfsdm_parse_of()
257 clk_freq = clk_get_rate(priv->aclk); in stm32_dfsdm_parse_of()
259 clk_freq = clk_get_rate(priv->clk); in stm32_dfsdm_parse_of()
262 ret = of_property_read_u32(pdev->dev.of_node, "spi-max-frequency", in stm32_dfsdm_parse_of()
276 dev_err(&pdev->dev, "spi-max-frequency not achievable\n"); in stm32_dfsdm_parse_of()
277 return -EINVAL; in stm32_dfsdm_parse_of()
281 priv->spi_clk_out_div = divider - 1; in stm32_dfsdm_parse_of()
282 priv->dfsdm.spi_master_freq = clk_freq / (priv->spi_clk_out_div + 1); in stm32_dfsdm_parse_of()
285 dev_warn(&pdev->dev, "SPI clock not accurate\n"); in stm32_dfsdm_parse_of()
286 dev_warn(&pdev->dev, "%ld = %d * %d + %d\n", in stm32_dfsdm_parse_of()
287 clk_freq, spi_freq, priv->spi_clk_out_div + 1, rem); in stm32_dfsdm_parse_of()
295 .compatible = "st,stm32h7-dfsdm",
299 .compatible = "st,stm32mp1-dfsdm",
310 struct device_node *np = pdev->dev.of_node; in stm32_dfsdm_probe_identification()
312 struct stm32_dfsdm *dfsdm = &priv->dfsdm; in stm32_dfsdm_probe_identification()
317 if (!dev_data->ipid) { in stm32_dfsdm_probe_identification()
318 dfsdm->num_fls = dev_data->num_filters; in stm32_dfsdm_probe_identification()
319 dfsdm->num_chs = dev_data->num_channels; in stm32_dfsdm_probe_identification()
323 ret = regmap_read(dfsdm->regmap, DFSDM_IPIDR, &id); in stm32_dfsdm_probe_identification()
327 if (id != dev_data->ipid) { in stm32_dfsdm_probe_identification()
328 dev_err(&pdev->dev, "Unexpected IP version: 0x%x", id); in stm32_dfsdm_probe_identification()
329 return -EINVAL; in stm32_dfsdm_probe_identification()
341 ret = regmap_read(dfsdm->regmap, DFSDM_HWCFGR, &val); in stm32_dfsdm_probe_identification()
345 dfsdm->num_fls = FIELD_GET(DFSDM_HWCFGR_NBF_MASK, val); in stm32_dfsdm_probe_identification()
346 dfsdm->num_chs = FIELD_GET(DFSDM_HWCFGR_NBT_MASK, val); in stm32_dfsdm_probe_identification()
348 if (count > dfsdm->num_fls) { in stm32_dfsdm_probe_identification()
349 dev_err(&pdev->dev, "Unexpected child number: %d", count); in stm32_dfsdm_probe_identification()
350 return -EINVAL; in stm32_dfsdm_probe_identification()
353 ret = regmap_read(dfsdm->regmap, DFSDM_VERR, &val); in stm32_dfsdm_probe_identification()
357 dev_dbg(&pdev->dev, "DFSDM version: %lu.%lu. %d channels/%d filters\n", in stm32_dfsdm_probe_identification()
360 dfsdm->num_chs, dfsdm->num_fls); in stm32_dfsdm_probe_identification()
372 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); in stm32_dfsdm_probe()
374 return -ENOMEM; in stm32_dfsdm_probe()
376 priv->pdev = pdev; in stm32_dfsdm_probe()
378 dev_data = of_device_get_match_data(&pdev->dev); in stm32_dfsdm_probe()
380 dfsdm = &priv->dfsdm; in stm32_dfsdm_probe()
386 dfsdm->regmap = devm_regmap_init_mmio_clk(&pdev->dev, "dfsdm", in stm32_dfsdm_probe()
387 dfsdm->base, in stm32_dfsdm_probe()
388 dev_data->regmap_cfg); in stm32_dfsdm_probe()
389 if (IS_ERR(dfsdm->regmap)) { in stm32_dfsdm_probe()
390 ret = PTR_ERR(dfsdm->regmap); in stm32_dfsdm_probe()
391 dev_err(&pdev->dev, "%s: Failed to allocate regmap: %d\n", in stm32_dfsdm_probe()
400 dfsdm->fl_list = devm_kcalloc(&pdev->dev, dfsdm->num_fls, in stm32_dfsdm_probe()
401 sizeof(*dfsdm->fl_list), GFP_KERNEL); in stm32_dfsdm_probe()
402 if (!dfsdm->fl_list) in stm32_dfsdm_probe()
403 return -ENOMEM; in stm32_dfsdm_probe()
405 dfsdm->ch_list = devm_kcalloc(&pdev->dev, dfsdm->num_chs, in stm32_dfsdm_probe()
406 sizeof(*dfsdm->ch_list), GFP_KERNEL); in stm32_dfsdm_probe()
407 if (!dfsdm->ch_list) in stm32_dfsdm_probe()
408 return -ENOMEM; in stm32_dfsdm_probe()
414 dev_err(&pdev->dev, "Failed to start clock\n"); in stm32_dfsdm_probe()
418 pm_runtime_get_noresume(&pdev->dev); in stm32_dfsdm_probe()
419 pm_runtime_set_active(&pdev->dev); in stm32_dfsdm_probe()
420 pm_runtime_enable(&pdev->dev); in stm32_dfsdm_probe()
422 ret = of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev); in stm32_dfsdm_probe()
426 pm_runtime_put(&pdev->dev); in stm32_dfsdm_probe()
431 pm_runtime_disable(&pdev->dev); in stm32_dfsdm_probe()
432 pm_runtime_set_suspended(&pdev->dev); in stm32_dfsdm_probe()
433 pm_runtime_put_noidle(&pdev->dev); in stm32_dfsdm_probe()
443 pm_runtime_get_sync(&pdev->dev); in stm32_dfsdm_core_remove()
444 of_platform_depopulate(&pdev->dev); in stm32_dfsdm_core_remove()
445 pm_runtime_disable(&pdev->dev); in stm32_dfsdm_core_remove()
446 pm_runtime_set_suspended(&pdev->dev); in stm32_dfsdm_core_remove()
447 pm_runtime_put_noidle(&pdev->dev); in stm32_dfsdm_core_remove()
462 clk_unprepare(priv->clk); in stm32_dfsdm_core_suspend()
477 ret = clk_prepare(priv->clk); in stm32_dfsdm_core_resume()
511 .name = "stm32-dfsdm",