Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/device.h> |
| 17 | #include <linux/delay.h> |
| 18 | #include <linux/clk.h> |
| 19 | #include <linux/platform_device.h> |
| 20 | #include <sound/core.h> |
| 21 | #include <sound/pcm.h> |
| 22 | #include <sound/initval.h> |
| 23 | #include <sound/soc.h> |
| 24 | #include <sound/dai.h> |
| 25 | |
| 26 | static int msm_cpu_dai_startup(struct snd_pcm_substream *substream, |
| 27 | struct snd_soc_dai *dai) |
| 28 | { |
| 29 | uint32_t dma_ch = dai->id; |
| 30 | int ret = 0; |
| 31 | |
| 32 | pr_debug("%s\n", __func__); |
| 33 | ret = dai_open(dma_ch); |
| 34 | return ret; |
| 35 | |
| 36 | } |
| 37 | |
| 38 | static void msm_cpu_dai_shutdown(struct snd_pcm_substream *substream, |
| 39 | struct snd_soc_dai *dai) |
| 40 | { |
| 41 | uint32_t dma_ch = dai->id; |
| 42 | |
| 43 | pr_debug("%s\n", __func__); |
| 44 | dai_close(dma_ch); |
| 45 | } |
| 46 | |
| 47 | static int msm_cpu_dai_trigger(struct snd_pcm_substream *substream, int cmd, |
| 48 | struct snd_soc_dai *dai) |
| 49 | { |
| 50 | pr_debug("%s\n", __func__); |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | static int msm_cpu_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) |
| 55 | { |
| 56 | uint32_t dma_ch = dai->id; |
| 57 | |
| 58 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 59 | case SND_SOC_DAIFMT_CBS_CFS: |
| 60 | dai_set_master_mode(dma_ch, 1); /* CPU is master */ |
| 61 | break; |
| 62 | case SND_SOC_DAIFMT_CBM_CFM: |
| 63 | dai_set_master_mode(dma_ch, 0); /* CPU is slave */ |
| 64 | break; |
| 65 | default: |
| 66 | return -EINVAL; |
| 67 | } |
| 68 | |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | static struct snd_soc_dai_ops msm_cpu_dai_ops = { |
| 73 | .startup = msm_cpu_dai_startup, |
| 74 | .shutdown = msm_cpu_dai_shutdown, |
| 75 | .trigger = msm_cpu_dai_trigger, |
| 76 | .set_fmt = msm_cpu_dai_fmt, |
| 77 | |
| 78 | }; |
| 79 | |
| 80 | |
| 81 | #define MSM_DAI_SPEAKER_BUILDER(link_id) \ |
| 82 | { \ |
| 83 | .name = "msm-speaker-dai-"#link_id, \ |
| 84 | .id = (link_id), \ |
| 85 | .playback = { \ |
| 86 | .rates = SNDRV_PCM_RATE_8000_96000, \ |
| 87 | .formats = SNDRV_PCM_FMTBIT_S16_LE, \ |
| 88 | .channels_min = 1, \ |
| 89 | .channels_max = 2, \ |
| 90 | .rate_max = 96000, \ |
| 91 | .rate_min = 8000, \ |
| 92 | }, \ |
| 93 | .ops = &msm_cpu_dai_ops, \ |
| 94 | } |
| 95 | |
| 96 | |
| 97 | #define MSM_DAI_MIC_BUILDER(link_id) \ |
| 98 | { \ |
| 99 | .name = "msm-mic-dai-"#link_id, \ |
| 100 | .id = (link_id), \ |
| 101 | .capture = { \ |
| 102 | .rates = SNDRV_PCM_RATE_8000_96000, \ |
| 103 | .formats = SNDRV_PCM_FMTBIT_S16_LE, \ |
| 104 | .rate_min = 8000, \ |
| 105 | .rate_max = 96000, \ |
| 106 | .channels_min = 1, \ |
| 107 | .channels_max = 2, \ |
| 108 | }, \ |
| 109 | .ops = &msm_cpu_dai_ops, \ |
| 110 | } |
| 111 | |
| 112 | |
| 113 | struct snd_soc_dai msm_cpu_dai[] = { |
| 114 | MSM_DAI_SPEAKER_BUILDER(0), |
| 115 | MSM_DAI_SPEAKER_BUILDER(1), |
| 116 | MSM_DAI_SPEAKER_BUILDER(2), |
| 117 | MSM_DAI_SPEAKER_BUILDER(3), |
| 118 | MSM_DAI_SPEAKER_BUILDER(4), |
| 119 | MSM_DAI_MIC_BUILDER(5), |
| 120 | MSM_DAI_MIC_BUILDER(6), |
| 121 | MSM_DAI_MIC_BUILDER(7), |
| 122 | }; |
| 123 | EXPORT_SYMBOL_GPL(msm_cpu_dai); |
| 124 | |
| 125 | static int __init msm_cpu_dai_init(void) |
| 126 | { |
| 127 | return snd_soc_register_dais(msm_cpu_dai, ARRAY_SIZE(msm_cpu_dai)); |
| 128 | } |
| 129 | module_init(msm_cpu_dai_init); |
| 130 | |
| 131 | static void __exit msm_cpu_dai_exit(void) |
| 132 | { |
| 133 | snd_soc_unregister_dais(msm_cpu_dai, ARRAY_SIZE(msm_cpu_dai)); |
| 134 | } |
| 135 | module_exit(msm_cpu_dai_exit); |
| 136 | |
| 137 | /* Module information */ |
| 138 | MODULE_DESCRIPTION("MSM CPU DAI driver"); |
| 139 | MODULE_LICENSE("GPL v2"); |