Lines Matching full:i2s

3 // tegra210_i2s.c - Tegra210 I2S driver
31 * is required to select i2s4b for it to be functional for I2S
50 struct tegra210_i2s *i2s = dev_get_drvdata(dev); in tegra210_i2s_set_clock_rate() local
54 regmap_read(i2s->regmap, TEGRA210_I2S_CTRL, &val); in tegra210_i2s_set_clock_rate()
56 /* No need to set rates if I2S is being operated in slave */ in tegra210_i2s_set_clock_rate()
60 err = clk_set_rate(i2s->clk_i2s, clock_rate); in tegra210_i2s_set_clock_rate()
62 dev_err(dev, "can't set I2S bit clock rate %u, err: %d\n", in tegra210_i2s_set_clock_rate()
67 if (!IS_ERR(i2s->clk_sync_input)) { in tegra210_i2s_set_clock_rate()
69 * Other I/O modules in AHUB can use i2s bclk as reference in tegra210_i2s_set_clock_rate()
73 err = clk_set_rate(i2s->clk_sync_input, clock_rate); in tegra210_i2s_set_clock_rate()
76 "can't set I2S sync input rate %u, err = %d\n", in tegra210_i2s_set_clock_rate()
89 struct tegra210_i2s *i2s = dev_get_drvdata(dev); in tegra210_i2s_sw_reset() local
106 /* Store CIF and I2S control values */ in tegra210_i2s_sw_reset()
107 regmap_read(i2s->regmap, cif_reg, &cif_ctrl); in tegra210_i2s_sw_reset()
108 regmap_read(i2s->regmap, stream_reg, &stream_ctrl); in tegra210_i2s_sw_reset()
109 regmap_read(i2s->regmap, TEGRA210_I2S_CTRL, &i2s_ctrl); in tegra210_i2s_sw_reset()
112 regmap_update_bits(i2s->regmap, reset_reg, reset_mask, reset_en); in tegra210_i2s_sw_reset()
114 err = regmap_read_poll_timeout(i2s->regmap, reset_reg, val, in tegra210_i2s_sw_reset()
118 dev_err(dev, "timeout: failed to reset I2S for %s\n", in tegra210_i2s_sw_reset()
123 /* Restore CIF and I2S control values */ in tegra210_i2s_sw_reset()
124 regmap_write(i2s->regmap, cif_reg, cif_ctrl); in tegra210_i2s_sw_reset()
125 regmap_write(i2s->regmap, stream_reg, stream_ctrl); in tegra210_i2s_sw_reset()
126 regmap_write(i2s->regmap, TEGRA210_I2S_CTRL, i2s_ctrl); in tegra210_i2s_sw_reset()
136 struct tegra210_i2s *i2s = dev_get_drvdata(dev); in tegra210_i2s_init() local
154 /* Ensure I2S is in disabled state before new session */ in tegra210_i2s_init()
155 err = regmap_read_poll_timeout(i2s->regmap, status_reg, val, in tegra210_i2s_init()
159 dev_err(dev, "timeout: previous I2S %s is still active\n", in tegra210_i2s_init()
169 struct tegra210_i2s *i2s = dev_get_drvdata(dev); in tegra210_i2s_runtime_suspend() local
171 regcache_cache_only(i2s->regmap, true); in tegra210_i2s_runtime_suspend()
172 regcache_mark_dirty(i2s->regmap); in tegra210_i2s_runtime_suspend()
174 clk_disable_unprepare(i2s->clk_i2s); in tegra210_i2s_runtime_suspend()
181 struct tegra210_i2s *i2s = dev_get_drvdata(dev); in tegra210_i2s_runtime_resume() local
184 err = clk_prepare_enable(i2s->clk_i2s); in tegra210_i2s_runtime_resume()
186 dev_err(dev, "failed to enable I2S bit clock, err: %d\n", err); in tegra210_i2s_runtime_resume()
190 regcache_cache_only(i2s->regmap, false); in tegra210_i2s_runtime_resume()
191 regcache_sync(i2s->regmap); in tegra210_i2s_runtime_resume()
196 static void tegra210_i2s_set_data_offset(struct tegra210_i2s *i2s, in tegra210_i2s_set_data_offset() argument
200 regmap_update_bits(i2s->regmap, TEGRA210_I2S_TX_CTRL, in tegra210_i2s_set_data_offset()
205 regmap_update_bits(i2s->regmap, TEGRA210_I2S_RX_CTRL, in tegra210_i2s_set_data_offset()
213 struct tegra210_i2s *i2s = snd_soc_dai_get_drvdata(dai); in tegra210_i2s_set_fmt() local
233 tegra210_i2s_set_data_offset(i2s, 1); in tegra210_i2s_set_fmt()
238 tegra210_i2s_set_data_offset(i2s, 0); in tegra210_i2s_set_fmt()
240 /* I2S mode has data offset of 1 */ in tegra210_i2s_set_fmt()
244 tegra210_i2s_set_data_offset(i2s, 1); in tegra210_i2s_set_fmt()
257 tegra210_i2s_set_data_offset(i2s, 0); in tegra210_i2s_set_fmt()
283 regmap_update_bits(i2s->regmap, TEGRA210_I2S_CTRL, mask, val); in tegra210_i2s_set_fmt()
285 i2s->dai_fmt = fmt & SND_SOC_DAIFMT_FORMAT_MASK; in tegra210_i2s_set_fmt()
294 struct tegra210_i2s *i2s = snd_soc_dai_get_drvdata(dai); in tegra210_i2s_set_tdm_slot() local
297 i2s->tx_mask = (tx_mask > DEFAULT_I2S_SLOT_MASK) ? in tegra210_i2s_set_tdm_slot()
299 i2s->rx_mask = (rx_mask > DEFAULT_I2S_SLOT_MASK) ? in tegra210_i2s_set_tdm_slot()
308 struct tegra210_i2s *i2s = snd_soc_dai_get_drvdata(dai); in tegra210_i2s_set_dai_bclk_ratio() local
310 i2s->bclk_ratio = ratio; in tegra210_i2s_set_dai_bclk_ratio()
319 struct tegra210_i2s *i2s = snd_soc_component_get_drvdata(compnt); in tegra210_i2s_get_control() local
323 *uctl_val = i2s->loopback; in tegra210_i2s_get_control()
325 *uctl_val = i2s->fsync_width; in tegra210_i2s_get_control()
327 *uctl_val = i2s->stereo_to_mono[I2S_TX_PATH]; in tegra210_i2s_get_control()
329 *uctl_val = i2s->mono_to_stereo[I2S_TX_PATH]; in tegra210_i2s_get_control()
331 *uctl_val = i2s->stereo_to_mono[I2S_RX_PATH]; in tegra210_i2s_get_control()
333 *uctl_val = i2s->mono_to_stereo[I2S_RX_PATH]; in tegra210_i2s_get_control()
335 *uctl_val = i2s->rx_fifo_th; in tegra210_i2s_get_control()
337 *uctl_val = i2s->bclk_ratio; in tegra210_i2s_get_control()
346 struct tegra210_i2s *i2s = snd_soc_component_get_drvdata(compnt); in tegra210_i2s_put_control() local
350 i2s->loopback = value; in tegra210_i2s_put_control()
352 regmap_update_bits(i2s->regmap, TEGRA210_I2S_CTRL, in tegra210_i2s_put_control()
354 i2s->loopback << I2S_CTRL_LPBK_SHIFT); in tegra210_i2s_put_control()
365 i2s->fsync_width = value; in tegra210_i2s_put_control()
367 regmap_update_bits(i2s->regmap, TEGRA210_I2S_CTRL, in tegra210_i2s_put_control()
369 i2s->fsync_width << I2S_FSYNC_WIDTH_SHIFT); in tegra210_i2s_put_control()
372 i2s->stereo_to_mono[I2S_TX_PATH] = value; in tegra210_i2s_put_control()
374 i2s->mono_to_stereo[I2S_TX_PATH] = value; in tegra210_i2s_put_control()
376 i2s->stereo_to_mono[I2S_RX_PATH] = value; in tegra210_i2s_put_control()
378 i2s->mono_to_stereo[I2S_RX_PATH] = value; in tegra210_i2s_put_control()
380 i2s->rx_fifo_th = value; in tegra210_i2s_put_control()
382 i2s->bclk_ratio = value; in tegra210_i2s_put_control()
393 struct tegra210_i2s *i2s = dev_get_drvdata(dev); in tegra210_i2s_set_timing_params() local
397 if (i2s->bclk_ratio) in tegra210_i2s_set_timing_params()
398 num_bclk *= i2s->bclk_ratio; in tegra210_i2s_set_timing_params()
400 if (i2s->dai_fmt == SND_SOC_DAIFMT_RIGHT_J) in tegra210_i2s_set_timing_params()
401 tegra210_i2s_set_data_offset(i2s, num_bclk - sample_size); in tegra210_i2s_set_timing_params()
403 /* I2S bit clock rate */ in tegra210_i2s_set_timing_params()
408 dev_err(dev, "can't set I2S bit clock rate %u, err: %d\n", in tegra210_i2s_set_timing_params()
413 regmap_read(i2s->regmap, TEGRA210_I2S_CTRL, &val); in tegra210_i2s_set_timing_params()
429 tegra210_i2s_set_slot_ctrl(i2s->regmap, channels, in tegra210_i2s_set_timing_params()
430 i2s->tx_mask, i2s->rx_mask); in tegra210_i2s_set_timing_params()
433 dev_err(dev, "invalid I2S frame format\n"); in tegra210_i2s_set_timing_params()
438 dev_err(dev, "invalid I2S channel bit count %u\n", bit_count); in tegra210_i2s_set_timing_params()
442 regmap_write(i2s->regmap, TEGRA210_I2S_TIMING, in tegra210_i2s_set_timing_params()
453 struct tegra210_i2s *i2s = snd_soc_dai_get_drvdata(dai); in tegra210_i2s_hw_params() local
461 dev_err(dev, "invalid I2S %d channel configuration\n", in tegra210_i2s_hw_params()
494 regmap_update_bits(i2s->regmap, TEGRA210_I2S_CTRL, in tegra210_i2s_hw_params()
499 /* For playback I2S RX-CIF and for capture TX-CIF is used */ in tegra210_i2s_hw_params()
511 if (i2s->rx_fifo_th > max_th) in tegra210_i2s_hw_params()
512 i2s->rx_fifo_th = max_th; in tegra210_i2s_hw_params()
514 cif_conf.threshold = i2s->rx_fifo_th; in tegra210_i2s_hw_params()
521 cif_conf.mono_conv = i2s->mono_to_stereo[path]; in tegra210_i2s_hw_params()
522 cif_conf.stereo_conv = i2s->stereo_to_mono[path]; in tegra210_i2s_hw_params()
524 tegra_set_cif(i2s->regmap, reg, &cif_conf); in tegra210_i2s_hw_params()
539 .name = "I2S-CIF",
560 .name = "I2S-DAP",
723 struct tegra210_i2s *i2s; in tegra210_i2s_probe() local
727 i2s = devm_kzalloc(dev, sizeof(*i2s), GFP_KERNEL); in tegra210_i2s_probe()
728 if (!i2s) in tegra210_i2s_probe()
731 i2s->rx_fifo_th = DEFAULT_I2S_RX_FIFO_THRESHOLD; in tegra210_i2s_probe()
732 i2s->tx_mask = DEFAULT_I2S_SLOT_MASK; in tegra210_i2s_probe()
733 i2s->rx_mask = DEFAULT_I2S_SLOT_MASK; in tegra210_i2s_probe()
734 i2s->loopback = false; in tegra210_i2s_probe()
736 dev_set_drvdata(dev, i2s); in tegra210_i2s_probe()
738 i2s->clk_i2s = devm_clk_get(dev, "i2s"); in tegra210_i2s_probe()
739 if (IS_ERR(i2s->clk_i2s)) { in tegra210_i2s_probe()
740 dev_err(dev, "can't retrieve I2S bit clock\n"); in tegra210_i2s_probe()
741 return PTR_ERR(i2s->clk_i2s); in tegra210_i2s_probe()
746 * requires input clock from current I2S instance, which is in tegra210_i2s_probe()
749 i2s->clk_sync_input = devm_clk_get(dev, "sync_input"); in tegra210_i2s_probe()
750 if (IS_ERR(i2s->clk_sync_input)) in tegra210_i2s_probe()
751 dev_dbg(dev, "can't retrieve I2S sync input clock\n"); in tegra210_i2s_probe()
757 i2s->regmap = devm_regmap_init_mmio(dev, regs, in tegra210_i2s_probe()
759 if (IS_ERR(i2s->regmap)) { in tegra210_i2s_probe()
761 return PTR_ERR(i2s->regmap); in tegra210_i2s_probe()
764 regcache_cache_only(i2s->regmap, true); in tegra210_i2s_probe()
770 dev_err(dev, "can't register I2S component, err: %d\n", err); in tegra210_i2s_probe()
794 { .compatible = "nvidia,tegra210-i2s" },
801 .name = "tegra210-i2s",
811 MODULE_DESCRIPTION("Tegra210 ASoC I2S driver");