Daniel Glöckner | 2b7dbbe | 2009-03-28 19:47:02 +0100 | [diff] [blame] | 1 | /* |
| 2 | * ASoC driver for Stretch s6105 IP camera platform |
| 3 | * |
| 4 | * Author: Daniel Gloeckner, <dg@emlix.com> |
| 5 | * Copyright: (C) 2009 emlix GmbH <info@emlix.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/moduleparam.h> |
| 14 | #include <linux/timer.h> |
| 15 | #include <linux/interrupt.h> |
| 16 | #include <linux/platform_device.h> |
Ben Dooks | aa6b904 | 2009-08-20 22:50:42 +0100 | [diff] [blame] | 17 | #include <linux/i2c.h> |
Daniel Glöckner | 2b7dbbe | 2009-03-28 19:47:02 +0100 | [diff] [blame] | 18 | #include <sound/core.h> |
| 19 | #include <sound/pcm.h> |
| 20 | #include <sound/soc.h> |
Daniel Glöckner | 2b7dbbe | 2009-03-28 19:47:02 +0100 | [diff] [blame] | 21 | |
Daniel Glöckner | 2b7dbbe | 2009-03-28 19:47:02 +0100 | [diff] [blame] | 22 | #include "s6000-pcm.h" |
| 23 | #include "s6000-i2s.h" |
| 24 | |
| 25 | #define S6105_CAM_CODEC_CLOCK 12288000 |
| 26 | |
| 27 | static int s6105_hw_params(struct snd_pcm_substream *substream, |
| 28 | struct snd_pcm_hw_params *params) |
| 29 | { |
| 30 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 31 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 32 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Daniel Glöckner | 2b7dbbe | 2009-03-28 19:47:02 +0100 | [diff] [blame] | 33 | int ret = 0; |
| 34 | |
| 35 | /* set codec DAI configuration */ |
| 36 | ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S | |
| 37 | SND_SOC_DAIFMT_CBM_CFM); |
| 38 | if (ret < 0) |
| 39 | return ret; |
| 40 | |
| 41 | /* set cpu DAI configuration */ |
| 42 | ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_CBM_CFM | |
Daniel Glöckner | 80fbe6a | 2009-04-06 11:50:22 +0200 | [diff] [blame] | 43 | SND_SOC_DAIFMT_NB_NF); |
Daniel Glöckner | 2b7dbbe | 2009-03-28 19:47:02 +0100 | [diff] [blame] | 44 | if (ret < 0) |
| 45 | return ret; |
| 46 | |
| 47 | /* set the codec system clock */ |
| 48 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, S6105_CAM_CODEC_CLOCK, |
| 49 | SND_SOC_CLOCK_OUT); |
| 50 | if (ret < 0) |
| 51 | return ret; |
| 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | static struct snd_soc_ops s6105_ops = { |
| 57 | .hw_params = s6105_hw_params, |
| 58 | }; |
| 59 | |
| 60 | /* s6105 machine dapm widgets */ |
| 61 | static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = { |
| 62 | SND_SOC_DAPM_LINE("Audio Out Differential", NULL), |
| 63 | SND_SOC_DAPM_LINE("Audio Out Stereo", NULL), |
| 64 | SND_SOC_DAPM_LINE("Audio In", NULL), |
| 65 | }; |
| 66 | |
| 67 | /* s6105 machine audio_mapnections to the codec pins */ |
| 68 | static const struct snd_soc_dapm_route audio_map[] = { |
| 69 | /* Audio Out connected to HPLOUT, HPLCOM, HPROUT */ |
| 70 | {"Audio Out Differential", NULL, "HPLOUT"}, |
| 71 | {"Audio Out Differential", NULL, "HPLCOM"}, |
| 72 | {"Audio Out Stereo", NULL, "HPLOUT"}, |
| 73 | {"Audio Out Stereo", NULL, "HPROUT"}, |
| 74 | |
| 75 | /* Audio In connected to LINE1L, LINE1R */ |
| 76 | {"LINE1L", NULL, "Audio In"}, |
| 77 | {"LINE1R", NULL, "Audio In"}, |
| 78 | }; |
| 79 | |
| 80 | static int output_type_info(struct snd_kcontrol *kcontrol, |
| 81 | struct snd_ctl_elem_info *uinfo) |
| 82 | { |
| 83 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 84 | uinfo->count = 1; |
| 85 | uinfo->value.enumerated.items = 2; |
| 86 | if (uinfo->value.enumerated.item) { |
| 87 | uinfo->value.enumerated.item = 1; |
| 88 | strcpy(uinfo->value.enumerated.name, "HPLOUT/HPROUT"); |
| 89 | } else { |
| 90 | strcpy(uinfo->value.enumerated.name, "HPLOUT/HPLCOM"); |
| 91 | } |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | static int output_type_get(struct snd_kcontrol *kcontrol, |
| 96 | struct snd_ctl_elem_value *ucontrol) |
| 97 | { |
| 98 | ucontrol->value.enumerated.item[0] = kcontrol->private_value; |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | static int output_type_put(struct snd_kcontrol *kcontrol, |
| 103 | struct snd_ctl_elem_value *ucontrol) |
| 104 | { |
Lars-Peter Clausen | b92af2b | 2014-03-12 15:27:37 +0100 | [diff] [blame] | 105 | struct snd_soc_card *card = kcontrol->private_data; |
| 106 | struct snd_soc_dapm_context *dapm = &card->dapm; |
Daniel Glöckner | 2b7dbbe | 2009-03-28 19:47:02 +0100 | [diff] [blame] | 107 | unsigned int val = (ucontrol->value.enumerated.item[0] != 0); |
| 108 | char *differential = "Audio Out Differential"; |
| 109 | char *stereo = "Audio Out Stereo"; |
| 110 | |
| 111 | if (kcontrol->private_value == val) |
| 112 | return 0; |
| 113 | kcontrol->private_value = val; |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 114 | snd_soc_dapm_disable_pin(dapm, val ? differential : stereo); |
| 115 | snd_soc_dapm_sync(dapm); |
| 116 | snd_soc_dapm_enable_pin(dapm, val ? stereo : differential); |
| 117 | snd_soc_dapm_sync(dapm); |
Daniel Glöckner | 2b7dbbe | 2009-03-28 19:47:02 +0100 | [diff] [blame] | 118 | |
| 119 | return 1; |
| 120 | } |
| 121 | |
| 122 | static const struct snd_kcontrol_new audio_out_mux = { |
| 123 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 124 | .name = "Master Output Mux", |
| 125 | .index = 0, |
| 126 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, |
| 127 | .info = output_type_info, |
| 128 | .get = output_type_get, |
| 129 | .put = output_type_put, |
| 130 | .private_value = 1 /* default to stereo */ |
| 131 | }; |
| 132 | |
| 133 | /* Logic for a aic3x as connected on the s6105 ip camera ref design */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 134 | static int s6105_aic3x_init(struct snd_soc_pcm_runtime *rtd) |
Daniel Glöckner | 2b7dbbe | 2009-03-28 19:47:02 +0100 | [diff] [blame] | 135 | { |
Lars-Peter Clausen | b92af2b | 2014-03-12 15:27:37 +0100 | [diff] [blame] | 136 | struct snd_soc_card *card = rtd->card; |
Daniel Glöckner | 2b7dbbe | 2009-03-28 19:47:02 +0100 | [diff] [blame] | 137 | |
Daniel Glöckner | 2b7dbbe | 2009-03-28 19:47:02 +0100 | [diff] [blame] | 138 | /* must correspond to audio_out_mux.private_value initializer */ |
Lars-Peter Clausen | b92af2b | 2014-03-12 15:27:37 +0100 | [diff] [blame] | 139 | snd_soc_dapm_disable_pin(&card->dapm, "Audio Out Differential"); |
Daniel Glöckner | 2b7dbbe | 2009-03-28 19:47:02 +0100 | [diff] [blame] | 140 | |
Lars-Peter Clausen | b92af2b | 2014-03-12 15:27:37 +0100 | [diff] [blame] | 141 | snd_ctl_add(card->snd_card, snd_ctl_new1(&audio_out_mux, card)); |
Daniel Glöckner | 2b7dbbe | 2009-03-28 19:47:02 +0100 | [diff] [blame] | 142 | |
| 143 | return 0; |
| 144 | } |
| 145 | |
| 146 | /* s6105 digital audio interface glue - connects codec <--> CPU */ |
| 147 | static struct snd_soc_dai_link s6105_dai = { |
| 148 | .name = "TLV320AIC31", |
| 149 | .stream_name = "AIC31", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 150 | .cpu_dai_name = "s6000-i2s", |
| 151 | .codec_dai_name = "tlv320aic3x-hifi", |
| 152 | .platform_name = "s6000-pcm-audio", |
| 153 | .codec_name = "tlv320aic3x-codec.0-001a", |
Daniel Glöckner | 2b7dbbe | 2009-03-28 19:47:02 +0100 | [diff] [blame] | 154 | .init = s6105_aic3x_init, |
| 155 | .ops = &s6105_ops, |
| 156 | }; |
| 157 | |
| 158 | /* s6105 audio machine driver */ |
| 159 | static struct snd_soc_card snd_soc_card_s6105 = { |
| 160 | .name = "Stretch IP Camera", |
Axel Lin | 23bd1ce | 2011-12-23 14:52:22 +0800 | [diff] [blame] | 161 | .owner = THIS_MODULE, |
Daniel Glöckner | 2b7dbbe | 2009-03-28 19:47:02 +0100 | [diff] [blame] | 162 | .dai_link = &s6105_dai, |
| 163 | .num_links = 1, |
Lars-Peter Clausen | b92af2b | 2014-03-12 15:27:37 +0100 | [diff] [blame] | 164 | |
| 165 | .dapm_widgets = aic3x_dapm_widgets, |
| 166 | .num_dapm_widgets = ARRAY_SIZE(aic3x_dapm_widgets), |
| 167 | .dapm_routes = audio_map, |
| 168 | .num_dapm_routes = ARRAY_SIZE(audio_map), |
Lars-Peter Clausen | 13447cd | 2014-06-30 10:01:39 +0200 | [diff] [blame] | 169 | .fully_routed = true, |
Daniel Glöckner | 2b7dbbe | 2009-03-28 19:47:02 +0100 | [diff] [blame] | 170 | }; |
| 171 | |
Sachin Kamat | 74b4523 | 2013-08-08 16:52:18 +0530 | [diff] [blame] | 172 | static struct s6000_snd_platform_data s6105_snd_data __initdata = { |
Daniel Glöckner | 2b7dbbe | 2009-03-28 19:47:02 +0100 | [diff] [blame] | 173 | .wide = 0, |
| 174 | .channel_in = 0, |
| 175 | .channel_out = 1, |
| 176 | .lines_in = 1, |
| 177 | .lines_out = 1, |
| 178 | .same_rate = 1, |
| 179 | }; |
| 180 | |
| 181 | static struct platform_device *s6105_snd_device; |
| 182 | |
Ben Dooks | aa6b904 | 2009-08-20 22:50:42 +0100 | [diff] [blame] | 183 | /* temporary i2c device creation until this can be moved into the machine |
| 184 | * support file. |
| 185 | */ |
| 186 | static struct i2c_board_info i2c_device[] = { |
| 187 | { I2C_BOARD_INFO("tlv320aic33", 0x18), } |
| 188 | }; |
| 189 | |
Daniel Glöckner | 2b7dbbe | 2009-03-28 19:47:02 +0100 | [diff] [blame] | 190 | static int __init s6105_init(void) |
| 191 | { |
| 192 | int ret; |
| 193 | |
Ben Dooks | aa6b904 | 2009-08-20 22:50:42 +0100 | [diff] [blame] | 194 | i2c_register_board_info(0, i2c_device, ARRAY_SIZE(i2c_device)); |
| 195 | |
Daniel Glöckner | 2b7dbbe | 2009-03-28 19:47:02 +0100 | [diff] [blame] | 196 | s6105_snd_device = platform_device_alloc("soc-audio", -1); |
| 197 | if (!s6105_snd_device) |
| 198 | return -ENOMEM; |
| 199 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 200 | platform_set_drvdata(s6105_snd_device, &snd_soc_card_s6105); |
Daniel Glöckner | 2b7dbbe | 2009-03-28 19:47:02 +0100 | [diff] [blame] | 201 | platform_device_add_data(s6105_snd_device, &s6105_snd_data, |
| 202 | sizeof(s6105_snd_data)); |
| 203 | |
| 204 | ret = platform_device_add(s6105_snd_device); |
| 205 | if (ret) |
| 206 | platform_device_put(s6105_snd_device); |
| 207 | |
| 208 | return ret; |
| 209 | } |
| 210 | |
| 211 | static void __exit s6105_exit(void) |
| 212 | { |
| 213 | platform_device_unregister(s6105_snd_device); |
| 214 | } |
| 215 | |
| 216 | module_init(s6105_init); |
| 217 | module_exit(s6105_exit); |
| 218 | |
| 219 | MODULE_AUTHOR("Daniel Gloeckner"); |
| 220 | MODULE_DESCRIPTION("Stretch s6105 IP camera ASoC driver"); |
| 221 | MODULE_LICENSE("GPL"); |