15 #include <linux/module.h>
16 #include <linux/slab.h>
17 #include <linux/bitops.h>
23 #include <mach/hardware.h>
39 if (drvdata->
slots > 1) {
57 "%s: Multichannel enabled. Slots: %d, TX: %u, RX: %u\n",
70 switch (drvdata->
slots) {
95 "%s: Error: Unsupported sample-rate (freq = %d)!\n",
114 "%s: Error: Unsupported slot-count (slots = %d)!\n",
115 __func__, drvdata->
slots);
122 dev_dbg(dai->
dev,
"%s: Clocks per frame: %u\n",
129 static int setup_pcm_framing(
struct snd_soc_dai *dai,
unsigned int rate,
137 switch (drvdata->
slots) {
155 "%s: Error: Unsupported slot-count (slots = %d)!\n",
156 __func__, drvdata->
slots);
170 return setup_frameper(dai, rate, prot_desc);
189 "%s: Error: Unsopported inversion (fmt = 0x%x)!\n",
197 dev_dbg(dai->
dev,
"%s: Codec is master.\n", __func__);
209 dev_dbg(dai->
dev,
"%s: Codec is slave.\n", __func__);
220 dev_err(dai->
dev,
"%s: Error: Unsopported master (fmt = 0x%x)!\n",
229 static int setup_pcm_protdesc(
struct snd_soc_dai *dai,
267 static int setup_i2s_protdesc(
struct msp_protdesc *prot_desc)
309 unsigned int fmt = drvdata->
fmt;
312 memset(msp_config, 0,
sizeof(*msp_config));
324 dev_dbg(dai->
dev,
"%s: f_inputclk = %u, frame_freq = %u.\n",
329 dev_dbg(dai->
dev,
"%s: rate: %u, channels: %d.\n", __func__,
334 dev_dbg(dai->
dev,
"%s: SND_SOC_DAIFMT_I2S.\n", __func__);
341 dev_dbg(dai->
dev,
"%s: SND_SOC_DAIFMT_I2S.\n", __func__);
346 ret = setup_i2s_protdesc(prot_desc);
356 dev_dbg(dai->
dev,
"%s: PCM format.\n", __func__);
361 ret = setup_pcm_protdesc(dai, fmt, prot_desc);
365 ret = setup_pcm_multichan(dai, msp_config);
369 ret = setup_pcm_framing(dai, runtime->
rate, prot_desc);
376 dev_err(dai->
dev,
"%s: Error: Unsopported format (%d)!\n",
381 return setup_clocking(dai, fmt, msp_config);
390 dev_dbg(dai->
dev,
"%s: MSP %d (%s): Enter.\n", __func__, dai->
id,
391 snd_pcm_stream_str(substream));
397 "%s: Failed to enable regulator!\n", __func__);
402 dev_dbg(dai->
dev,
"%s: Enabling MSP-clock.\n", __func__);
415 dev_dbg(dai->
dev,
"%s: MSP %d (%s): Enter.\n", __func__, dai->
id,
416 snd_pcm_stream_str(substream));
420 "ux500_msp_i2s", 50);
427 "%s: Error: MSP %d (%s): Unable to close i2s.\n",
428 __func__, dai->
id, snd_pcm_stream_str(substream));
438 "%s: ERROR: Failed to disable regulator (%d)!\n",
450 dev_dbg(dai->
dev,
"%s: MSP %d (%s): Enter (rate = %d).\n", __func__,
451 dai->
id, snd_pcm_stream_str(substream), runtime->
rate);
453 setup_msp_config(substream, dai, &msp_config);
457 dev_err(dai->
dev,
"%s: Error: msp_setup failed (ret = %d)!\n",
464 (drvdata->
msp->f_bitclk > 19200000)) {
468 "ux500-msp-i2s", 100);
472 "ux500-msp-i2s", 50);
483 unsigned int mask, slots_active;
487 dev_dbg(dai->
dev,
"%s: MSP %d (%s): Enter.\n",
488 __func__, dai->
id, snd_pcm_stream_str(substream));
504 dev_dbg(dai->
dev,
"TDM-slots active: %d", slots_active);
508 slots_active, slots_active);
513 "%s: Error: Unsupported protocol (fmt = 0x%x)!\n",
514 __func__, drvdata->
fmt);
521 static int ux500_msp_dai_set_dai_fmt(
struct snd_soc_dai *dai,
526 dev_dbg(dai->
dev,
"%s: MSP %d: Enter.\n", __func__, dai->
id);
540 "%s: Error: Unsupported protocol/master (fmt = 0x%x)!\n",
541 __func__, drvdata->
fmt);
545 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
553 "%s: Error: Unsupported inversion (fmt = 0x%x)!\n",
554 __func__, drvdata->
fmt);
562 static int ux500_msp_dai_set_tdm_slot(
struct snd_soc_dai *dai,
584 dev_err(dai->
dev,
"%s: Error: Unsupported slot-count (%d)!\n",
590 if (!(slot_width == 16)) {
591 dev_err(dai->
dev,
"%s: Error: Unsupported slot-width (%d)!\n",
592 __func__, slot_width);
603 static int ux500_msp_dai_set_dai_sysclk(
struct snd_soc_dai *dai,
604 int clk_id,
unsigned int freq,
int dir)
608 dev_dbg(dai->
dev,
"%s: MSP %d: Enter. clk-id: %d, freq: %u.\n",
609 __func__, dai->
id, clk_id, freq);
617 dev_err(dai->
dev,
"%s: MSP %d: Invalid clk-id (%d)!\n",
618 __func__, dai->
id, clk_id);
631 dev_dbg(dai->
dev,
"%s: MSP %d (%s): Enter (msp->id = %d, cmd = %d).\n",
632 __func__, dai->
id, snd_pcm_stream_str(substream),
633 (
int)drvdata->
msp->id, cmd);
640 static int ux500_msp_dai_probe(
struct snd_soc_dai *dai)
658 .set_sysclk = ux500_msp_dai_set_dai_sysclk,
659 .set_fmt = ux500_msp_dai_set_dai_fmt,
660 .set_tdm_slot = ux500_msp_dai_set_tdm_slot,
661 .startup = ux500_msp_dai_startup,
662 .shutdown = ux500_msp_dai_shutdown,
663 .prepare = ux500_msp_dai_prepare,
664 .trigger = ux500_msp_dai_trigger,
665 .hw_params = ux500_msp_dai_hw_params,
671 .name =
"ux500-msp-i2s.0",
672 .probe = ux500_msp_dai_probe,
688 .ops = ux500_msp_dai_ops,
691 .name =
"ux500-msp-i2s.1",
692 .probe = ux500_msp_dai_probe,
708 .ops = ux500_msp_dai_ops,
711 .name =
"ux500-msp-i2s.2",
713 .probe = ux500_msp_dai_probe,
728 .ops = ux500_msp_dai_ops,
731 .name =
"ux500-msp-i2s.3",
732 .probe = ux500_msp_dai_probe,
748 .ops = ux500_msp_dai_ops,
757 dev_dbg(&pdev->
dev,
"%s: Enter (pdev->name = %s).\n", __func__,
777 "%s: ERROR: Failed to get Vape supply (%d)!\n",
784 if (IS_ERR(drvdata->
clk)) {
785 ret = (
int)PTR_ERR(drvdata->
clk);
786 dev_err(&pdev->
dev,
"%s: ERROR: clk_get failed (%d)!\n",
792 pdev->
dev.platform_data);
795 "%s: ERROR: Failed to init MSP-struct (%d)!",
802 &ux500_msp_dai_drv[drvdata->
msp->id]);
804 dev_err(&pdev->
dev,
"Error: %s: Failed to register MSP%d!\n",
805 __func__, drvdata->
msp->id);
836 static const struct of_device_id ux500_msp_i2s_match[] = {
837 { .compatible =
"stericsson,ux500-msp-i2s", },
843 .name =
"ux500-msp-i2s",
845 .of_match_table = ux500_msp_i2s_match,
847 .probe = ux500_msp_drv_probe,
848 .remove = ux500_msp_drv_remove,