Lines Matching +full:pclk +full:- +full:sample

1 // SPDX-License-Identifier: (GPL-2.0 OR MIT)
12 #include <sound/soc-dai.h>
53 #define PDM_CHAN_CTRL_POINTER_MAX ((1 << PDM_CHAN_CTRL_POINTER_WIDTH) - 1)
96 struct clk *pclk; member
134 axg_pdm_enable(priv->map); in axg_pdm_trigger()
140 axg_pdm_disable(priv->map); in axg_pdm_trigger()
144 return -EINVAL; in axg_pdm_trigger()
150 const struct axg_pdm_filters *filters = priv->cfg->filters; in axg_pdm_get_os()
151 unsigned int os = filters->hcic.ds; in axg_pdm_get_os()
160 os *= filters->lpf[i].ds; in axg_pdm_get_os()
172 * the requested sample rate. In this case, the sample pointer in axg_pdm_set_sysclk()
175 if (sys_rate < priv->cfg->sys_rate) in axg_pdm_set_sysclk()
176 return clk_set_rate(priv->sysclk, sys_rate); in axg_pdm_set_sysclk()
178 return clk_set_rate(priv->sysclk, priv->cfg->sys_rate); in axg_pdm_set_sysclk()
186 /* Max sample counter value per half period of dclk */ in axg_pdm_set_sample_pointer()
187 spmax = DIV_ROUND_UP_ULL((u64)clk_get_rate(priv->sysclk), in axg_pdm_set_sample_pointer()
188 clk_get_rate(priv->dclk) * 2); in axg_pdm_set_sample_pointer()
190 /* Check if sysclk is not too fast - should not happen */ in axg_pdm_set_sample_pointer()
192 return -EINVAL; in axg_pdm_set_sample_pointer()
200 regmap_write(priv->map, PDM_CHAN_CTRL, val); in axg_pdm_set_sample_pointer()
201 regmap_write(priv->map, PDM_CHAN_CTRL1, val); in axg_pdm_set_sample_pointer()
209 unsigned int mask = GENMASK(channels - 1, 0); in axg_pdm_set_channel_mask()
212 regmap_update_bits(priv->map, PDM_CTRL, in axg_pdm_set_channel_mask()
216 regmap_update_bits(priv->map, PDM_CTRL, in axg_pdm_set_channel_mask()
241 dev_err(dai->dev, "unsupported sample width\n"); in axg_pdm_hw_params()
242 return -EINVAL; in axg_pdm_hw_params()
245 regmap_update_bits(priv->map, PDM_CTRL, PDM_CTRL_OUT_MODE, val); in axg_pdm_hw_params()
249 dev_err(dai->dev, "failed to set system clock\n"); in axg_pdm_hw_params()
253 ret = clk_set_rate(priv->dclk, rate * os); in axg_pdm_hw_params()
255 dev_err(dai->dev, "failed to set dclk\n"); in axg_pdm_hw_params()
261 dev_err(dai->dev, "invalid clock setting\n"); in axg_pdm_hw_params()
276 ret = clk_prepare_enable(priv->dclk); in axg_pdm_startup()
278 dev_err(dai->dev, "enabling dclk failed\n"); in axg_pdm_startup()
283 axg_pdm_filters_enable(priv->map, true); in axg_pdm_startup()
293 axg_pdm_filters_enable(priv->map, false); in axg_pdm_shutdown()
294 clk_disable_unprepare(priv->dclk); in axg_pdm_shutdown()
299 const struct axg_pdm_hcic *hcic = &priv->cfg->filters->hcic; in axg_pdm_set_hcic_ctrl()
302 val = PDM_HCIC_CTRL1_STAGE_NUM(hcic->steps); in axg_pdm_set_hcic_ctrl()
303 val |= PDM_HCIC_CTRL1_DSR(hcic->ds); in axg_pdm_set_hcic_ctrl()
304 val |= PDM_HCIC_CTRL1_GAIN_MULT(hcic->mult); in axg_pdm_set_hcic_ctrl()
305 val |= PDM_HCIC_CTRL1_GAIN_SFT(hcic->shift); in axg_pdm_set_hcic_ctrl()
307 regmap_update_bits(priv->map, PDM_HCIC_CTRL1, in axg_pdm_set_hcic_ctrl()
317 const struct axg_pdm_lpf *lpf = &priv->cfg->filters->lpf[index]; in axg_pdm_set_lpf_ctrl()
318 unsigned int offset = index * regmap_get_reg_stride(priv->map) in axg_pdm_set_lpf_ctrl()
322 val = PDM_LPF_STAGE_NUM(lpf->tap_num); in axg_pdm_set_lpf_ctrl()
323 val |= PDM_LPF_DSR(lpf->ds); in axg_pdm_set_lpf_ctrl()
324 val |= PDM_LPF_ROUND_MODE(lpf->round_mode); in axg_pdm_set_lpf_ctrl()
326 regmap_update_bits(priv->map, offset, in axg_pdm_set_lpf_ctrl()
335 const struct axg_pdm_hpf *hpf = &priv->cfg->filters->hpf; in axg_pdm_set_hpf_ctrl()
338 val = PDM_HPF_OUT_FACTOR(hpf->out_factor); in axg_pdm_set_hpf_ctrl()
339 val |= PDM_HPF_SFT_STEPS(hpf->steps); in axg_pdm_set_hpf_ctrl()
341 regmap_update_bits(priv->map, PDM_HPF_CTRL, in axg_pdm_set_hpf_ctrl()
349 const struct axg_pdm_lpf *lpf = priv->cfg->filters->lpf; in axg_pdm_set_lpf_filters()
358 return -EINVAL; in axg_pdm_set_lpf_filters()
361 regmap_write(priv->map, PDM_COEFF_ADDR, 0); in axg_pdm_set_lpf_filters()
368 regmap_write(priv->map, PDM_COEFF_DATA, lpf[i].tap[j]); in axg_pdm_set_lpf_filters()
379 ret = clk_prepare_enable(priv->pclk); in axg_pdm_dai_probe()
381 dev_err(dai->dev, "enabling pclk failed\n"); in axg_pdm_dai_probe()
389 ret = clk_set_rate(priv->sysclk, priv->cfg->sys_rate); in axg_pdm_dai_probe()
391 dev_err(dai->dev, "setting sysclk failed\n"); in axg_pdm_dai_probe()
395 ret = clk_prepare_enable(priv->sysclk); in axg_pdm_dai_probe()
397 dev_err(dai->dev, "enabling sysclk failed\n"); in axg_pdm_dai_probe()
402 axg_pdm_disable(priv->map); in axg_pdm_dai_probe()
405 regmap_update_bits(priv->map, PDM_CTRL, PDM_CTRL_BYPASS_MODE, 0); in axg_pdm_dai_probe()
413 dev_err(dai->dev, "invalid filter configuration\n"); in axg_pdm_dai_probe()
420 clk_disable_unprepare(priv->sysclk); in axg_pdm_dai_probe()
422 clk_disable_unprepare(priv->pclk); in axg_pdm_dai_probe()
430 clk_disable_unprepare(priv->sysclk); in axg_pdm_dai_remove()
431 clk_disable_unprepare(priv->pclk); in axg_pdm_dai_remove()
531 * - OS = 64
532 * - Latency = 38700 (?)
580 .compatible = "amlogic,axg-pdm",
588 struct device *dev = &pdev->dev; in axg_pdm_probe()
594 return -ENOMEM; in axg_pdm_probe()
597 priv->cfg = of_device_get_match_data(dev); in axg_pdm_probe()
598 if (!priv->cfg) { in axg_pdm_probe()
600 return -ENODEV; in axg_pdm_probe()
607 priv->map = devm_regmap_init_mmio(dev, regs, &axg_pdm_regmap_cfg); in axg_pdm_probe()
608 if (IS_ERR(priv->map)) { in axg_pdm_probe()
610 PTR_ERR(priv->map)); in axg_pdm_probe()
611 return PTR_ERR(priv->map); in axg_pdm_probe()
614 priv->pclk = devm_clk_get(dev, "pclk"); in axg_pdm_probe()
615 if (IS_ERR(priv->pclk)) in axg_pdm_probe()
616 return dev_err_probe(dev, PTR_ERR(priv->pclk), "failed to get pclk\n"); in axg_pdm_probe()
618 priv->dclk = devm_clk_get(dev, "dclk"); in axg_pdm_probe()
619 if (IS_ERR(priv->dclk)) in axg_pdm_probe()
620 return dev_err_probe(dev, PTR_ERR(priv->dclk), "failed to get dclk\n"); in axg_pdm_probe()
622 priv->sysclk = devm_clk_get(dev, "sysclk"); in axg_pdm_probe()
623 if (IS_ERR(priv->sysclk)) in axg_pdm_probe()
624 return dev_err_probe(dev, PTR_ERR(priv->sysclk), "failed to get dclk\n"); in axg_pdm_probe()
633 .name = "axg-pdm",