Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2008, Creative Technology Ltd. All Rights Reserved. |
| 3 | * |
| 4 | * This source file is released under GPL v2 license (no other versions). |
| 5 | * See the COPYING file included in the main directory of this source |
| 6 | * distribution for the license terms and conditions. |
| 7 | * |
| 8 | * @File ctatc.c |
| 9 | * |
| 10 | * @Brief |
| 11 | * This file contains the implementation of the device resource management |
| 12 | * object. |
| 13 | * |
| 14 | * @Author Liu Chun |
| 15 | * @Date Mar 28 2008 |
| 16 | */ |
| 17 | |
| 18 | #include "ctatc.h" |
| 19 | #include "ctpcm.h" |
| 20 | #include "ctmixer.h" |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 21 | #include "ctsrc.h" |
| 22 | #include "ctamixer.h" |
| 23 | #include "ctdaio.h" |
Takashi Iwai | b7bbf87 | 2009-06-05 16:11:07 +0200 | [diff] [blame] | 24 | #include "cttimer.h" |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 25 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/slab.h> |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 27 | #include <sound/pcm.h> |
| 28 | #include <sound/control.h> |
| 29 | #include <sound/asoundef.h> |
| 30 | |
| 31 | #define MONO_SUM_SCALE 0x19a8 /* 2^(-0.5) in 14-bit floating format */ |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 32 | #define MAX_MULTI_CHN 8 |
| 33 | |
| 34 | #define IEC958_DEFAULT_CON ((IEC958_AES0_NONAUDIO \ |
| 35 | | IEC958_AES0_CON_NOT_COPYRIGHT) \ |
| 36 | | ((IEC958_AES1_CON_MIXER \ |
| 37 | | IEC958_AES1_CON_ORIGINAL) << 8) \ |
| 38 | | (0x10 << 16) \ |
| 39 | | ((IEC958_AES3_CON_FS_48000) << 24)) |
| 40 | |
Takashi Iwai | 9470195 | 2009-06-08 18:10:32 +0200 | [diff] [blame] | 41 | static struct snd_pci_quirk __devinitdata subsys_20k1_list[] = { |
| 42 | SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE, 0x0022, "SB055x", CTSB055X), |
| 43 | SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE, 0x002f, "SB055x", CTSB055X), |
| 44 | SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE, 0x0029, "SB073x", CTSB073X), |
| 45 | SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE, 0x0031, "SB073x", CTSB073X), |
Takashi Iwai | 09521d2 | 2009-06-08 18:29:38 +0200 | [diff] [blame] | 46 | SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_CREATIVE, 0xf000, 0x6000, |
| 47 | "UAA", CTUAA), |
Takashi Iwai | 9470195 | 2009-06-08 18:10:32 +0200 | [diff] [blame] | 48 | { } /* terminator */ |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 49 | }; |
| 50 | |
Takashi Iwai | 9470195 | 2009-06-08 18:10:32 +0200 | [diff] [blame] | 51 | static struct snd_pci_quirk __devinitdata subsys_20k2_list[] = { |
| 52 | SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE, PCI_SUBDEVICE_ID_CREATIVE_SB0760, |
| 53 | "SB0760", CTSB0760), |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame] | 54 | SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE, PCI_SUBDEVICE_ID_CREATIVE_SB1270, |
| 55 | "SB1270", CTSB1270), |
Takashi Iwai | 9470195 | 2009-06-08 18:10:32 +0200 | [diff] [blame] | 56 | SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE, PCI_SUBDEVICE_ID_CREATIVE_SB08801, |
| 57 | "SB0880", CTSB0880), |
| 58 | SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE, PCI_SUBDEVICE_ID_CREATIVE_SB08802, |
| 59 | "SB0880", CTSB0880), |
| 60 | SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE, PCI_SUBDEVICE_ID_CREATIVE_SB08803, |
| 61 | "SB0880", CTSB0880), |
Takashi Iwai | 09521d2 | 2009-06-08 18:29:38 +0200 | [diff] [blame] | 62 | SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_CREATIVE, 0xf000, |
| 63 | PCI_SUBDEVICE_ID_CREATIVE_HENDRIX, "HENDRIX", |
| 64 | CTHENDRIX), |
Takashi Iwai | 9470195 | 2009-06-08 18:10:32 +0200 | [diff] [blame] | 65 | { } /* terminator */ |
| 66 | }; |
| 67 | |
| 68 | static const char *ct_subsys_name[NUM_CTCARDS] = { |
Takashi Iwai | a8f4310 | 2009-06-22 07:36:52 +0200 | [diff] [blame] | 69 | /* 20k1 models */ |
Takashi Iwai | 9470195 | 2009-06-08 18:10:32 +0200 | [diff] [blame] | 70 | [CTSB055X] = "SB055x", |
| 71 | [CTSB073X] = "SB073x", |
Takashi Iwai | 9470195 | 2009-06-08 18:10:32 +0200 | [diff] [blame] | 72 | [CTUAA] = "UAA", |
| 73 | [CT20K1_UNKNOWN] = "Unknown", |
Takashi Iwai | a8f4310 | 2009-06-22 07:36:52 +0200 | [diff] [blame] | 74 | /* 20k2 models */ |
| 75 | [CTSB0760] = "SB076x", |
Takashi Iwai | 9470195 | 2009-06-08 18:10:32 +0200 | [diff] [blame] | 76 | [CTHENDRIX] = "Hendrix", |
| 77 | [CTSB0880] = "SB0880", |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame] | 78 | [CTSB1270] = "SB1270", |
Takashi Iwai | a8f4310 | 2009-06-22 07:36:52 +0200 | [diff] [blame] | 79 | [CT20K2_UNKNOWN] = "Unknown", |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | static struct { |
| 83 | int (*create)(struct ct_atc *atc, |
| 84 | enum CTALSADEVS device, const char *device_name); |
| 85 | int (*destroy)(void *alsa_dev); |
| 86 | const char *public_name; |
| 87 | } alsa_dev_funcs[NUM_CTALSADEVS] = { |
| 88 | [FRONT] = { .create = ct_alsa_pcm_create, |
| 89 | .destroy = NULL, |
| 90 | .public_name = "Front/WaveIn"}, |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 91 | [SURROUND] = { .create = ct_alsa_pcm_create, |
| 92 | .destroy = NULL, |
| 93 | .public_name = "Surround"}, |
Takashi Iwai | 8372d498 | 2009-06-02 14:27:56 +0200 | [diff] [blame] | 94 | [CLFE] = { .create = ct_alsa_pcm_create, |
| 95 | .destroy = NULL, |
| 96 | .public_name = "Center/LFE"}, |
| 97 | [SIDE] = { .create = ct_alsa_pcm_create, |
| 98 | .destroy = NULL, |
| 99 | .public_name = "Side"}, |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 100 | [IEC958] = { .create = ct_alsa_pcm_create, |
| 101 | .destroy = NULL, |
| 102 | .public_name = "IEC958 Non-audio"}, |
| 103 | |
| 104 | [MIXER] = { .create = ct_alsa_mix_create, |
| 105 | .destroy = NULL, |
| 106 | .public_name = "Mixer"} |
| 107 | }; |
| 108 | |
| 109 | typedef int (*create_t)(void *, void **); |
| 110 | typedef int (*destroy_t)(void *); |
| 111 | |
| 112 | static struct { |
| 113 | int (*create)(void *hw, void **rmgr); |
| 114 | int (*destroy)(void *mgr); |
| 115 | } rsc_mgr_funcs[NUM_RSCTYP] = { |
| 116 | [SRC] = { .create = (create_t)src_mgr_create, |
| 117 | .destroy = (destroy_t)src_mgr_destroy }, |
| 118 | [SRCIMP] = { .create = (create_t)srcimp_mgr_create, |
| 119 | .destroy = (destroy_t)srcimp_mgr_destroy }, |
| 120 | [AMIXER] = { .create = (create_t)amixer_mgr_create, |
| 121 | .destroy = (destroy_t)amixer_mgr_destroy }, |
| 122 | [SUM] = { .create = (create_t)sum_mgr_create, |
| 123 | .destroy = (destroy_t)sum_mgr_destroy }, |
| 124 | [DAIO] = { .create = (create_t)daio_mgr_create, |
| 125 | .destroy = (destroy_t)daio_mgr_destroy } |
| 126 | }; |
| 127 | |
| 128 | static int |
| 129 | atc_pcm_release_resources(struct ct_atc *atc, struct ct_atc_pcm *apcm); |
| 130 | |
| 131 | /* * |
| 132 | * Only mono and interleaved modes are supported now. |
| 133 | * Always allocates a contiguous channel block. |
| 134 | * */ |
| 135 | |
| 136 | static int ct_map_audio_buffer(struct ct_atc *atc, struct ct_atc_pcm *apcm) |
| 137 | { |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 138 | struct snd_pcm_runtime *runtime; |
| 139 | struct ct_vm *vm; |
| 140 | |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 141 | if (!apcm->substream) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 142 | return 0; |
| 143 | |
| 144 | runtime = apcm->substream->runtime; |
| 145 | vm = atc->vm; |
| 146 | |
Takashi Iwai | c76157d | 2009-06-02 15:26:19 +0200 | [diff] [blame] | 147 | apcm->vm_block = vm->map(vm, apcm->substream, runtime->dma_bytes); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 148 | |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 149 | if (!apcm->vm_block) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 150 | return -ENOENT; |
| 151 | |
| 152 | return 0; |
| 153 | } |
| 154 | |
| 155 | static void ct_unmap_audio_buffer(struct ct_atc *atc, struct ct_atc_pcm *apcm) |
| 156 | { |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 157 | struct ct_vm *vm; |
| 158 | |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 159 | if (!apcm->vm_block) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 160 | return; |
| 161 | |
| 162 | vm = atc->vm; |
| 163 | |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 164 | vm->unmap(vm, apcm->vm_block); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 165 | |
| 166 | apcm->vm_block = NULL; |
| 167 | } |
| 168 | |
| 169 | static unsigned long atc_get_ptp_phys(struct ct_atc *atc, int index) |
| 170 | { |
Jaroslav Kysela | 21956b6 | 2010-02-02 19:58:25 +0100 | [diff] [blame] | 171 | return atc->vm->get_ptp_phys(atc->vm, index); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | static unsigned int convert_format(snd_pcm_format_t snd_format) |
| 175 | { |
| 176 | switch (snd_format) { |
| 177 | case SNDRV_PCM_FORMAT_U8: |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 178 | return SRC_SF_U8; |
| 179 | case SNDRV_PCM_FORMAT_S16_LE: |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 180 | return SRC_SF_S16; |
| 181 | case SNDRV_PCM_FORMAT_S24_3LE: |
| 182 | return SRC_SF_S24; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 183 | case SNDRV_PCM_FORMAT_S32_LE: |
| 184 | return SRC_SF_S32; |
Takashi Iwai | d2b9b96 | 2009-06-02 14:39:05 +0200 | [diff] [blame] | 185 | case SNDRV_PCM_FORMAT_FLOAT_LE: |
| 186 | return SRC_SF_F32; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 187 | default: |
Takashi Iwai | b3e0afe | 2009-05-14 15:19:30 +0200 | [diff] [blame] | 188 | printk(KERN_ERR "ctxfi: not recognized snd format is %d \n", |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 189 | snd_format); |
| 190 | return SRC_SF_S16; |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | static unsigned int |
| 195 | atc_get_pitch(unsigned int input_rate, unsigned int output_rate) |
| 196 | { |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 197 | unsigned int pitch; |
| 198 | int b; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 199 | |
| 200 | /* get pitch and convert to fixed-point 8.24 format. */ |
| 201 | pitch = (input_rate / output_rate) << 24; |
| 202 | input_rate %= output_rate; |
| 203 | input_rate /= 100; |
| 204 | output_rate /= 100; |
| 205 | for (b = 31; ((b >= 0) && !(input_rate >> b)); ) |
| 206 | b--; |
| 207 | |
| 208 | if (b >= 0) { |
| 209 | input_rate <<= (31 - b); |
| 210 | input_rate /= output_rate; |
| 211 | b = 24 - (31 - b); |
| 212 | if (b >= 0) |
| 213 | input_rate <<= b; |
| 214 | else |
| 215 | input_rate >>= -b; |
| 216 | |
| 217 | pitch |= input_rate; |
| 218 | } |
| 219 | |
| 220 | return pitch; |
| 221 | } |
| 222 | |
| 223 | static int select_rom(unsigned int pitch) |
| 224 | { |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 225 | if (pitch > 0x00428f5c && pitch < 0x01b851ec) { |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 226 | /* 0.26 <= pitch <= 1.72 */ |
| 227 | return 1; |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 228 | } else if (pitch == 0x01d66666 || pitch == 0x01d66667) { |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 229 | /* pitch == 1.8375 */ |
| 230 | return 2; |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 231 | } else if (pitch == 0x02000000) { |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 232 | /* pitch == 2 */ |
| 233 | return 3; |
Roel Kluin | 84ed1a1 | 2009-10-23 16:03:08 +0200 | [diff] [blame] | 234 | } else if (pitch <= 0x08000000) { |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 235 | /* 0 <= pitch <= 8 */ |
| 236 | return 0; |
| 237 | } else { |
| 238 | return -ENOENT; |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | static int atc_pcm_playback_prepare(struct ct_atc *atc, struct ct_atc_pcm *apcm) |
| 243 | { |
| 244 | struct src_mgr *src_mgr = atc->rsc_mgrs[SRC]; |
| 245 | struct amixer_mgr *amixer_mgr = atc->rsc_mgrs[AMIXER]; |
| 246 | struct src_desc desc = {0}; |
| 247 | struct amixer_desc mix_dsc = {0}; |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 248 | struct src *src; |
| 249 | struct amixer *amixer; |
| 250 | int err; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 251 | int n_amixer = apcm->substream->runtime->channels, i = 0; |
| 252 | int device = apcm->substream->pcm->device; |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 253 | unsigned int pitch; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 254 | |
Takashi Iwai | 822fa19 | 2009-06-02 14:12:17 +0200 | [diff] [blame] | 255 | /* first release old resources */ |
Wai Yew CHAY | 29959a0 | 2009-06-22 14:52:34 +0200 | [diff] [blame] | 256 | atc_pcm_release_resources(atc, apcm); |
Takashi Iwai | 822fa19 | 2009-06-02 14:12:17 +0200 | [diff] [blame] | 257 | |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 258 | /* Get SRC resource */ |
| 259 | desc.multi = apcm->substream->runtime->channels; |
| 260 | desc.msr = atc->msr; |
| 261 | desc.mode = MEMRD; |
| 262 | err = src_mgr->get_src(src_mgr, &desc, (struct src **)&apcm->src); |
| 263 | if (err) |
| 264 | goto error1; |
| 265 | |
| 266 | pitch = atc_get_pitch(apcm->substream->runtime->rate, |
| 267 | (atc->rsr * atc->msr)); |
| 268 | src = apcm->src; |
| 269 | src->ops->set_pitch(src, pitch); |
| 270 | src->ops->set_rom(src, select_rom(pitch)); |
| 271 | src->ops->set_sf(src, convert_format(apcm->substream->runtime->format)); |
| 272 | src->ops->set_pm(src, (src->ops->next_interleave(src) != NULL)); |
| 273 | |
| 274 | /* Get AMIXER resource */ |
| 275 | n_amixer = (n_amixer < 2) ? 2 : n_amixer; |
| 276 | apcm->amixers = kzalloc(sizeof(void *)*n_amixer, GFP_KERNEL); |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 277 | if (!apcm->amixers) { |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 278 | err = -ENOMEM; |
| 279 | goto error1; |
| 280 | } |
| 281 | mix_dsc.msr = atc->msr; |
| 282 | for (i = 0, apcm->n_amixer = 0; i < n_amixer; i++) { |
| 283 | err = amixer_mgr->get_amixer(amixer_mgr, &mix_dsc, |
| 284 | (struct amixer **)&apcm->amixers[i]); |
| 285 | if (err) |
| 286 | goto error1; |
| 287 | |
| 288 | apcm->n_amixer++; |
| 289 | } |
| 290 | |
| 291 | /* Set up device virtual mem map */ |
| 292 | err = ct_map_audio_buffer(atc, apcm); |
| 293 | if (err < 0) |
| 294 | goto error1; |
| 295 | |
| 296 | /* Connect resources */ |
| 297 | src = apcm->src; |
| 298 | for (i = 0; i < n_amixer; i++) { |
| 299 | amixer = apcm->amixers[i]; |
Takashi Iwai | 635c265 | 2009-06-13 10:12:59 +0200 | [diff] [blame] | 300 | mutex_lock(&atc->atc_mutex); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 301 | amixer->ops->setup(amixer, &src->rsc, |
| 302 | INIT_VOL, atc->pcm[i+device*2]); |
Takashi Iwai | 635c265 | 2009-06-13 10:12:59 +0200 | [diff] [blame] | 303 | mutex_unlock(&atc->atc_mutex); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 304 | src = src->ops->next_interleave(src); |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 305 | if (!src) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 306 | src = apcm->src; |
| 307 | } |
| 308 | |
Takashi Iwai | b7bbf87 | 2009-06-05 16:11:07 +0200 | [diff] [blame] | 309 | ct_timer_prepare(apcm->timer); |
| 310 | |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 311 | return 0; |
| 312 | |
| 313 | error1: |
| 314 | atc_pcm_release_resources(atc, apcm); |
| 315 | return err; |
| 316 | } |
| 317 | |
| 318 | static int |
| 319 | atc_pcm_release_resources(struct ct_atc *atc, struct ct_atc_pcm *apcm) |
| 320 | { |
| 321 | struct src_mgr *src_mgr = atc->rsc_mgrs[SRC]; |
| 322 | struct srcimp_mgr *srcimp_mgr = atc->rsc_mgrs[SRCIMP]; |
| 323 | struct amixer_mgr *amixer_mgr = atc->rsc_mgrs[AMIXER]; |
| 324 | struct sum_mgr *sum_mgr = atc->rsc_mgrs[SUM]; |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 325 | struct srcimp *srcimp; |
| 326 | int i; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 327 | |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 328 | if (apcm->srcimps) { |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 329 | for (i = 0; i < apcm->n_srcimp; i++) { |
| 330 | srcimp = apcm->srcimps[i]; |
| 331 | srcimp->ops->unmap(srcimp); |
| 332 | srcimp_mgr->put_srcimp(srcimp_mgr, srcimp); |
| 333 | apcm->srcimps[i] = NULL; |
| 334 | } |
| 335 | kfree(apcm->srcimps); |
| 336 | apcm->srcimps = NULL; |
| 337 | } |
| 338 | |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 339 | if (apcm->srccs) { |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 340 | for (i = 0; i < apcm->n_srcc; i++) { |
| 341 | src_mgr->put_src(src_mgr, apcm->srccs[i]); |
| 342 | apcm->srccs[i] = NULL; |
| 343 | } |
| 344 | kfree(apcm->srccs); |
| 345 | apcm->srccs = NULL; |
| 346 | } |
| 347 | |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 348 | if (apcm->amixers) { |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 349 | for (i = 0; i < apcm->n_amixer; i++) { |
| 350 | amixer_mgr->put_amixer(amixer_mgr, apcm->amixers[i]); |
| 351 | apcm->amixers[i] = NULL; |
| 352 | } |
| 353 | kfree(apcm->amixers); |
| 354 | apcm->amixers = NULL; |
| 355 | } |
| 356 | |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 357 | if (apcm->mono) { |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 358 | sum_mgr->put_sum(sum_mgr, apcm->mono); |
| 359 | apcm->mono = NULL; |
| 360 | } |
| 361 | |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 362 | if (apcm->src) { |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 363 | src_mgr->put_src(src_mgr, apcm->src); |
| 364 | apcm->src = NULL; |
| 365 | } |
| 366 | |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 367 | if (apcm->vm_block) { |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 368 | /* Undo device virtual mem map */ |
| 369 | ct_unmap_audio_buffer(atc, apcm); |
| 370 | apcm->vm_block = NULL; |
| 371 | } |
| 372 | |
| 373 | return 0; |
| 374 | } |
| 375 | |
| 376 | static int atc_pcm_playback_start(struct ct_atc *atc, struct ct_atc_pcm *apcm) |
| 377 | { |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 378 | unsigned int max_cisz; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 379 | struct src *src = apcm->src; |
| 380 | |
Takashi Iwai | c399f3b | 2009-06-09 08:16:20 +0200 | [diff] [blame] | 381 | if (apcm->started) |
| 382 | return 0; |
| 383 | apcm->started = 1; |
| 384 | |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 385 | max_cisz = src->multi * src->rsc.msr; |
| 386 | max_cisz = 0x80 * (max_cisz < 8 ? max_cisz : 8); |
| 387 | |
| 388 | src->ops->set_sa(src, apcm->vm_block->addr); |
| 389 | src->ops->set_la(src, apcm->vm_block->addr + apcm->vm_block->size); |
| 390 | src->ops->set_ca(src, apcm->vm_block->addr + max_cisz); |
| 391 | src->ops->set_cisz(src, max_cisz); |
| 392 | |
| 393 | src->ops->set_bm(src, 1); |
| 394 | src->ops->set_state(src, SRC_STATE_INIT); |
| 395 | src->ops->commit_write(src); |
| 396 | |
Takashi Iwai | b7bbf87 | 2009-06-05 16:11:07 +0200 | [diff] [blame] | 397 | ct_timer_start(apcm->timer); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 398 | return 0; |
| 399 | } |
| 400 | |
| 401 | static int atc_pcm_stop(struct ct_atc *atc, struct ct_atc_pcm *apcm) |
| 402 | { |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 403 | struct src *src; |
| 404 | int i; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 405 | |
Takashi Iwai | b7bbf87 | 2009-06-05 16:11:07 +0200 | [diff] [blame] | 406 | ct_timer_stop(apcm->timer); |
| 407 | |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 408 | src = apcm->src; |
| 409 | src->ops->set_bm(src, 0); |
| 410 | src->ops->set_state(src, SRC_STATE_OFF); |
| 411 | src->ops->commit_write(src); |
| 412 | |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 413 | if (apcm->srccs) { |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 414 | for (i = 0; i < apcm->n_srcc; i++) { |
| 415 | src = apcm->srccs[i]; |
| 416 | src->ops->set_bm(src, 0); |
| 417 | src->ops->set_state(src, SRC_STATE_OFF); |
| 418 | src->ops->commit_write(src); |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | apcm->started = 0; |
| 423 | |
| 424 | return 0; |
| 425 | } |
| 426 | |
| 427 | static int |
| 428 | atc_pcm_playback_position(struct ct_atc *atc, struct ct_atc_pcm *apcm) |
| 429 | { |
| 430 | struct src *src = apcm->src; |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 431 | u32 size, max_cisz; |
| 432 | int position; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 433 | |
Takashi Iwai | 5242bc7 | 2009-06-09 08:17:14 +0200 | [diff] [blame] | 434 | if (!src) |
| 435 | return 0; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 436 | position = src->ops->get_ca(src); |
| 437 | |
| 438 | size = apcm->vm_block->size; |
| 439 | max_cisz = src->multi * src->rsc.msr; |
| 440 | max_cisz = 128 * (max_cisz < 8 ? max_cisz : 8); |
| 441 | |
| 442 | return (position + size - max_cisz - apcm->vm_block->addr) % size; |
| 443 | } |
| 444 | |
| 445 | struct src_node_conf_t { |
| 446 | unsigned int pitch; |
| 447 | unsigned int msr:8; |
| 448 | unsigned int mix_msr:8; |
| 449 | unsigned int imp_msr:8; |
| 450 | unsigned int vo:1; |
| 451 | }; |
| 452 | |
| 453 | static void setup_src_node_conf(struct ct_atc *atc, struct ct_atc_pcm *apcm, |
| 454 | struct src_node_conf_t *conf, int *n_srcc) |
| 455 | { |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 456 | unsigned int pitch; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 457 | |
| 458 | /* get pitch and convert to fixed-point 8.24 format. */ |
| 459 | pitch = atc_get_pitch((atc->rsr * atc->msr), |
| 460 | apcm->substream->runtime->rate); |
| 461 | *n_srcc = 0; |
| 462 | |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame] | 463 | if (1 == atc->msr) { /* FIXME: do we really need SRC here if pitch==1 */ |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 464 | *n_srcc = apcm->substream->runtime->channels; |
| 465 | conf[0].pitch = pitch; |
| 466 | conf[0].mix_msr = conf[0].imp_msr = conf[0].msr = 1; |
| 467 | conf[0].vo = 1; |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame] | 468 | } else if (2 <= atc->msr) { |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 469 | if (0x8000000 < pitch) { |
| 470 | /* Need two-stage SRCs, SRCIMPs and |
| 471 | * AMIXERs for converting format */ |
| 472 | conf[0].pitch = (atc->msr << 24); |
| 473 | conf[0].msr = conf[0].mix_msr = 1; |
| 474 | conf[0].imp_msr = atc->msr; |
| 475 | conf[0].vo = 0; |
| 476 | conf[1].pitch = atc_get_pitch(atc->rsr, |
| 477 | apcm->substream->runtime->rate); |
| 478 | conf[1].msr = conf[1].mix_msr = conf[1].imp_msr = 1; |
| 479 | conf[1].vo = 1; |
| 480 | *n_srcc = apcm->substream->runtime->channels * 2; |
| 481 | } else if (0x1000000 < pitch) { |
| 482 | /* Need one-stage SRCs, SRCIMPs and |
| 483 | * AMIXERs for converting format */ |
| 484 | conf[0].pitch = pitch; |
| 485 | conf[0].msr = conf[0].mix_msr |
| 486 | = conf[0].imp_msr = atc->msr; |
| 487 | conf[0].vo = 1; |
| 488 | *n_srcc = apcm->substream->runtime->channels; |
| 489 | } |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | static int |
| 494 | atc_pcm_capture_get_resources(struct ct_atc *atc, struct ct_atc_pcm *apcm) |
| 495 | { |
| 496 | struct src_mgr *src_mgr = atc->rsc_mgrs[SRC]; |
| 497 | struct srcimp_mgr *srcimp_mgr = atc->rsc_mgrs[SRCIMP]; |
| 498 | struct amixer_mgr *amixer_mgr = atc->rsc_mgrs[AMIXER]; |
| 499 | struct sum_mgr *sum_mgr = atc->rsc_mgrs[SUM]; |
| 500 | struct src_desc src_dsc = {0}; |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 501 | struct src *src; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 502 | struct srcimp_desc srcimp_dsc = {0}; |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 503 | struct srcimp *srcimp; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 504 | struct amixer_desc mix_dsc = {0}; |
| 505 | struct sum_desc sum_dsc = {0}; |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 506 | unsigned int pitch; |
| 507 | int multi, err, i; |
| 508 | int n_srcimp, n_amixer, n_srcc, n_sum; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 509 | struct src_node_conf_t src_node_conf[2] = {{0} }; |
| 510 | |
Takashi Iwai | 822fa19 | 2009-06-02 14:12:17 +0200 | [diff] [blame] | 511 | /* first release old resources */ |
Takashi Iwai | a5990dc | 2009-06-09 08:19:02 +0200 | [diff] [blame] | 512 | atc_pcm_release_resources(atc, apcm); |
Takashi Iwai | 822fa19 | 2009-06-02 14:12:17 +0200 | [diff] [blame] | 513 | |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 514 | /* The numbers of converting SRCs and SRCIMPs should be determined |
| 515 | * by pitch value. */ |
| 516 | |
| 517 | multi = apcm->substream->runtime->channels; |
| 518 | |
| 519 | /* get pitch and convert to fixed-point 8.24 format. */ |
| 520 | pitch = atc_get_pitch((atc->rsr * atc->msr), |
| 521 | apcm->substream->runtime->rate); |
| 522 | |
| 523 | setup_src_node_conf(atc, apcm, src_node_conf, &n_srcc); |
| 524 | n_sum = (1 == multi) ? 1 : 0; |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 525 | n_amixer = n_sum * 2 + n_srcc; |
| 526 | n_srcimp = n_srcc; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 527 | if ((multi > 1) && (0x8000000 >= pitch)) { |
| 528 | /* Need extra AMIXERs and SRCIMPs for special treatment |
| 529 | * of interleaved recording of conjugate channels */ |
| 530 | n_amixer += multi * atc->msr; |
| 531 | n_srcimp += multi * atc->msr; |
| 532 | } else { |
| 533 | n_srcimp += multi; |
| 534 | } |
| 535 | |
| 536 | if (n_srcc) { |
| 537 | apcm->srccs = kzalloc(sizeof(void *)*n_srcc, GFP_KERNEL); |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 538 | if (!apcm->srccs) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 539 | return -ENOMEM; |
| 540 | } |
| 541 | if (n_amixer) { |
| 542 | apcm->amixers = kzalloc(sizeof(void *)*n_amixer, GFP_KERNEL); |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 543 | if (!apcm->amixers) { |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 544 | err = -ENOMEM; |
| 545 | goto error1; |
| 546 | } |
| 547 | } |
| 548 | apcm->srcimps = kzalloc(sizeof(void *)*n_srcimp, GFP_KERNEL); |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 549 | if (!apcm->srcimps) { |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 550 | err = -ENOMEM; |
| 551 | goto error1; |
| 552 | } |
| 553 | |
| 554 | /* Allocate SRCs for sample rate conversion if needed */ |
| 555 | src_dsc.multi = 1; |
| 556 | src_dsc.mode = ARCRW; |
| 557 | for (i = 0, apcm->n_srcc = 0; i < n_srcc; i++) { |
| 558 | src_dsc.msr = src_node_conf[i/multi].msr; |
| 559 | err = src_mgr->get_src(src_mgr, &src_dsc, |
| 560 | (struct src **)&apcm->srccs[i]); |
| 561 | if (err) |
| 562 | goto error1; |
| 563 | |
| 564 | src = apcm->srccs[i]; |
| 565 | pitch = src_node_conf[i/multi].pitch; |
| 566 | src->ops->set_pitch(src, pitch); |
| 567 | src->ops->set_rom(src, select_rom(pitch)); |
| 568 | src->ops->set_vo(src, src_node_conf[i/multi].vo); |
| 569 | |
| 570 | apcm->n_srcc++; |
| 571 | } |
| 572 | |
| 573 | /* Allocate AMIXERs for routing SRCs of conversion if needed */ |
| 574 | for (i = 0, apcm->n_amixer = 0; i < n_amixer; i++) { |
| 575 | if (i < (n_sum*2)) |
| 576 | mix_dsc.msr = atc->msr; |
| 577 | else if (i < (n_sum*2+n_srcc)) |
| 578 | mix_dsc.msr = src_node_conf[(i-n_sum*2)/multi].mix_msr; |
| 579 | else |
| 580 | mix_dsc.msr = 1; |
| 581 | |
| 582 | err = amixer_mgr->get_amixer(amixer_mgr, &mix_dsc, |
| 583 | (struct amixer **)&apcm->amixers[i]); |
| 584 | if (err) |
| 585 | goto error1; |
| 586 | |
| 587 | apcm->n_amixer++; |
| 588 | } |
| 589 | |
| 590 | /* Allocate a SUM resource to mix all input channels together */ |
| 591 | sum_dsc.msr = atc->msr; |
| 592 | err = sum_mgr->get_sum(sum_mgr, &sum_dsc, (struct sum **)&apcm->mono); |
| 593 | if (err) |
| 594 | goto error1; |
| 595 | |
| 596 | pitch = atc_get_pitch((atc->rsr * atc->msr), |
| 597 | apcm->substream->runtime->rate); |
| 598 | /* Allocate SRCIMP resources */ |
| 599 | for (i = 0, apcm->n_srcimp = 0; i < n_srcimp; i++) { |
| 600 | if (i < (n_srcc)) |
| 601 | srcimp_dsc.msr = src_node_conf[i/multi].imp_msr; |
| 602 | else if (1 == multi) |
| 603 | srcimp_dsc.msr = (pitch <= 0x8000000) ? atc->msr : 1; |
| 604 | else |
| 605 | srcimp_dsc.msr = 1; |
| 606 | |
| 607 | err = srcimp_mgr->get_srcimp(srcimp_mgr, &srcimp_dsc, &srcimp); |
| 608 | if (err) |
| 609 | goto error1; |
| 610 | |
| 611 | apcm->srcimps[i] = srcimp; |
| 612 | apcm->n_srcimp++; |
| 613 | } |
| 614 | |
| 615 | /* Allocate a SRC for writing data to host memory */ |
| 616 | src_dsc.multi = apcm->substream->runtime->channels; |
| 617 | src_dsc.msr = 1; |
| 618 | src_dsc.mode = MEMWR; |
| 619 | err = src_mgr->get_src(src_mgr, &src_dsc, (struct src **)&apcm->src); |
| 620 | if (err) |
| 621 | goto error1; |
| 622 | |
| 623 | src = apcm->src; |
| 624 | src->ops->set_pitch(src, pitch); |
| 625 | |
| 626 | /* Set up device virtual mem map */ |
| 627 | err = ct_map_audio_buffer(atc, apcm); |
| 628 | if (err < 0) |
| 629 | goto error1; |
| 630 | |
| 631 | return 0; |
| 632 | |
| 633 | error1: |
| 634 | atc_pcm_release_resources(atc, apcm); |
| 635 | return err; |
| 636 | } |
| 637 | |
| 638 | static int atc_pcm_capture_prepare(struct ct_atc *atc, struct ct_atc_pcm *apcm) |
| 639 | { |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 640 | struct src *src; |
| 641 | struct amixer *amixer; |
| 642 | struct srcimp *srcimp; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 643 | struct ct_mixer *mixer = atc->mixer; |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 644 | struct sum *mono; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 645 | struct rsc *out_ports[8] = {NULL}; |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 646 | int err, i, j, n_sum, multi; |
| 647 | unsigned int pitch; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 648 | int mix_base = 0, imp_base = 0; |
| 649 | |
Wai Yew CHAY | 29959a0 | 2009-06-22 14:52:34 +0200 | [diff] [blame] | 650 | atc_pcm_release_resources(atc, apcm); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 651 | |
| 652 | /* Get needed resources. */ |
| 653 | err = atc_pcm_capture_get_resources(atc, apcm); |
| 654 | if (err) |
| 655 | return err; |
| 656 | |
| 657 | /* Connect resources */ |
| 658 | mixer->get_output_ports(mixer, MIX_PCMO_FRONT, |
| 659 | &out_ports[0], &out_ports[1]); |
| 660 | |
| 661 | multi = apcm->substream->runtime->channels; |
| 662 | if (1 == multi) { |
| 663 | mono = apcm->mono; |
| 664 | for (i = 0; i < 2; i++) { |
| 665 | amixer = apcm->amixers[i]; |
| 666 | amixer->ops->setup(amixer, out_ports[i], |
| 667 | MONO_SUM_SCALE, mono); |
| 668 | } |
| 669 | out_ports[0] = &mono->rsc; |
| 670 | n_sum = 1; |
| 671 | mix_base = n_sum * 2; |
| 672 | } |
| 673 | |
| 674 | for (i = 0; i < apcm->n_srcc; i++) { |
| 675 | src = apcm->srccs[i]; |
| 676 | srcimp = apcm->srcimps[imp_base+i]; |
| 677 | amixer = apcm->amixers[mix_base+i]; |
| 678 | srcimp->ops->map(srcimp, src, out_ports[i%multi]); |
| 679 | amixer->ops->setup(amixer, &src->rsc, INIT_VOL, NULL); |
| 680 | out_ports[i%multi] = &amixer->rsc; |
| 681 | } |
| 682 | |
| 683 | pitch = atc_get_pitch((atc->rsr * atc->msr), |
| 684 | apcm->substream->runtime->rate); |
| 685 | |
| 686 | if ((multi > 1) && (pitch <= 0x8000000)) { |
| 687 | /* Special connection for interleaved |
| 688 | * recording with conjugate channels */ |
| 689 | for (i = 0; i < multi; i++) { |
| 690 | out_ports[i]->ops->master(out_ports[i]); |
| 691 | for (j = 0; j < atc->msr; j++) { |
| 692 | amixer = apcm->amixers[apcm->n_srcc+j*multi+i]; |
| 693 | amixer->ops->set_input(amixer, out_ports[i]); |
| 694 | amixer->ops->set_scale(amixer, INIT_VOL); |
| 695 | amixer->ops->set_sum(amixer, NULL); |
| 696 | amixer->ops->commit_raw_write(amixer); |
| 697 | out_ports[i]->ops->next_conj(out_ports[i]); |
| 698 | |
| 699 | srcimp = apcm->srcimps[apcm->n_srcc+j*multi+i]; |
| 700 | srcimp->ops->map(srcimp, apcm->src, |
| 701 | &amixer->rsc); |
| 702 | } |
| 703 | } |
| 704 | } else { |
| 705 | for (i = 0; i < multi; i++) { |
| 706 | srcimp = apcm->srcimps[apcm->n_srcc+i]; |
| 707 | srcimp->ops->map(srcimp, apcm->src, out_ports[i]); |
| 708 | } |
| 709 | } |
| 710 | |
Takashi Iwai | b7bbf87 | 2009-06-05 16:11:07 +0200 | [diff] [blame] | 711 | ct_timer_prepare(apcm->timer); |
| 712 | |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 713 | return 0; |
| 714 | } |
| 715 | |
| 716 | static int atc_pcm_capture_start(struct ct_atc *atc, struct ct_atc_pcm *apcm) |
| 717 | { |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 718 | struct src *src; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 719 | struct src_mgr *src_mgr = atc->rsc_mgrs[SRC]; |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 720 | int i, multi; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 721 | |
| 722 | if (apcm->started) |
| 723 | return 0; |
| 724 | |
| 725 | apcm->started = 1; |
| 726 | multi = apcm->substream->runtime->channels; |
| 727 | /* Set up converting SRCs */ |
| 728 | for (i = 0; i < apcm->n_srcc; i++) { |
| 729 | src = apcm->srccs[i]; |
| 730 | src->ops->set_pm(src, ((i%multi) != (multi-1))); |
| 731 | src_mgr->src_disable(src_mgr, src); |
| 732 | } |
| 733 | |
| 734 | /* Set up recording SRC */ |
| 735 | src = apcm->src; |
| 736 | src->ops->set_sf(src, convert_format(apcm->substream->runtime->format)); |
| 737 | src->ops->set_sa(src, apcm->vm_block->addr); |
| 738 | src->ops->set_la(src, apcm->vm_block->addr + apcm->vm_block->size); |
| 739 | src->ops->set_ca(src, apcm->vm_block->addr); |
| 740 | src_mgr->src_disable(src_mgr, src); |
| 741 | |
| 742 | /* Disable relevant SRCs firstly */ |
| 743 | src_mgr->commit_write(src_mgr); |
| 744 | |
| 745 | /* Enable SRCs respectively */ |
| 746 | for (i = 0; i < apcm->n_srcc; i++) { |
| 747 | src = apcm->srccs[i]; |
| 748 | src->ops->set_state(src, SRC_STATE_RUN); |
| 749 | src->ops->commit_write(src); |
| 750 | src_mgr->src_enable_s(src_mgr, src); |
| 751 | } |
| 752 | src = apcm->src; |
| 753 | src->ops->set_bm(src, 1); |
| 754 | src->ops->set_state(src, SRC_STATE_RUN); |
| 755 | src->ops->commit_write(src); |
| 756 | src_mgr->src_enable_s(src_mgr, src); |
| 757 | |
| 758 | /* Enable relevant SRCs synchronously */ |
| 759 | src_mgr->commit_write(src_mgr); |
| 760 | |
Takashi Iwai | b7bbf87 | 2009-06-05 16:11:07 +0200 | [diff] [blame] | 761 | ct_timer_start(apcm->timer); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 762 | return 0; |
| 763 | } |
| 764 | |
| 765 | static int |
| 766 | atc_pcm_capture_position(struct ct_atc *atc, struct ct_atc_pcm *apcm) |
| 767 | { |
| 768 | struct src *src = apcm->src; |
| 769 | |
Takashi Iwai | 5242bc7 | 2009-06-09 08:17:14 +0200 | [diff] [blame] | 770 | if (!src) |
| 771 | return 0; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 772 | return src->ops->get_ca(src) - apcm->vm_block->addr; |
| 773 | } |
| 774 | |
| 775 | static int spdif_passthru_playback_get_resources(struct ct_atc *atc, |
| 776 | struct ct_atc_pcm *apcm) |
| 777 | { |
| 778 | struct src_mgr *src_mgr = atc->rsc_mgrs[SRC]; |
| 779 | struct amixer_mgr *amixer_mgr = atc->rsc_mgrs[AMIXER]; |
| 780 | struct src_desc desc = {0}; |
| 781 | struct amixer_desc mix_dsc = {0}; |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 782 | struct src *src; |
| 783 | int err; |
| 784 | int n_amixer = apcm->substream->runtime->channels, i; |
| 785 | unsigned int pitch, rsr = atc->pll_rate; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 786 | |
Takashi Iwai | 822fa19 | 2009-06-02 14:12:17 +0200 | [diff] [blame] | 787 | /* first release old resources */ |
Takashi Iwai | a5990dc | 2009-06-09 08:19:02 +0200 | [diff] [blame] | 788 | atc_pcm_release_resources(atc, apcm); |
Takashi Iwai | 822fa19 | 2009-06-02 14:12:17 +0200 | [diff] [blame] | 789 | |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 790 | /* Get SRC resource */ |
| 791 | desc.multi = apcm->substream->runtime->channels; |
| 792 | desc.msr = 1; |
| 793 | while (apcm->substream->runtime->rate > (rsr * desc.msr)) |
| 794 | desc.msr <<= 1; |
| 795 | |
| 796 | desc.mode = MEMRD; |
| 797 | err = src_mgr->get_src(src_mgr, &desc, (struct src **)&apcm->src); |
| 798 | if (err) |
| 799 | goto error1; |
| 800 | |
| 801 | pitch = atc_get_pitch(apcm->substream->runtime->rate, (rsr * desc.msr)); |
| 802 | src = apcm->src; |
| 803 | src->ops->set_pitch(src, pitch); |
| 804 | src->ops->set_rom(src, select_rom(pitch)); |
| 805 | src->ops->set_sf(src, convert_format(apcm->substream->runtime->format)); |
| 806 | src->ops->set_pm(src, (src->ops->next_interleave(src) != NULL)); |
| 807 | src->ops->set_bp(src, 1); |
| 808 | |
| 809 | /* Get AMIXER resource */ |
| 810 | n_amixer = (n_amixer < 2) ? 2 : n_amixer; |
| 811 | apcm->amixers = kzalloc(sizeof(void *)*n_amixer, GFP_KERNEL); |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 812 | if (!apcm->amixers) { |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 813 | err = -ENOMEM; |
| 814 | goto error1; |
| 815 | } |
| 816 | mix_dsc.msr = desc.msr; |
| 817 | for (i = 0, apcm->n_amixer = 0; i < n_amixer; i++) { |
| 818 | err = amixer_mgr->get_amixer(amixer_mgr, &mix_dsc, |
| 819 | (struct amixer **)&apcm->amixers[i]); |
| 820 | if (err) |
| 821 | goto error1; |
| 822 | |
| 823 | apcm->n_amixer++; |
| 824 | } |
| 825 | |
| 826 | /* Set up device virtual mem map */ |
| 827 | err = ct_map_audio_buffer(atc, apcm); |
| 828 | if (err < 0) |
| 829 | goto error1; |
| 830 | |
| 831 | return 0; |
| 832 | |
| 833 | error1: |
| 834 | atc_pcm_release_resources(atc, apcm); |
| 835 | return err; |
| 836 | } |
| 837 | |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 838 | static int atc_pll_init(struct ct_atc *atc, int rate) |
| 839 | { |
| 840 | struct hw *hw = atc->hw; |
| 841 | int err; |
| 842 | err = hw->pll_init(hw, rate); |
| 843 | atc->pll_rate = err ? 0 : rate; |
| 844 | return err; |
| 845 | } |
| 846 | |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 847 | static int |
| 848 | spdif_passthru_playback_setup(struct ct_atc *atc, struct ct_atc_pcm *apcm) |
| 849 | { |
| 850 | struct dao *dao = container_of(atc->daios[SPDIFOO], struct dao, daio); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 851 | unsigned int rate = apcm->substream->runtime->rate; |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 852 | unsigned int status; |
Wai Yew CHAY | 29959a0 | 2009-06-22 14:52:34 +0200 | [diff] [blame] | 853 | int err = 0; |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 854 | unsigned char iec958_con_fs; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 855 | |
| 856 | switch (rate) { |
| 857 | case 48000: |
| 858 | iec958_con_fs = IEC958_AES3_CON_FS_48000; |
| 859 | break; |
| 860 | case 44100: |
| 861 | iec958_con_fs = IEC958_AES3_CON_FS_44100; |
| 862 | break; |
| 863 | case 32000: |
| 864 | iec958_con_fs = IEC958_AES3_CON_FS_32000; |
| 865 | break; |
| 866 | default: |
| 867 | return -ENOENT; |
| 868 | } |
| 869 | |
Takashi Iwai | 635c265 | 2009-06-13 10:12:59 +0200 | [diff] [blame] | 870 | mutex_lock(&atc->atc_mutex); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 871 | dao->ops->get_spos(dao, &status); |
| 872 | if (((status >> 24) & IEC958_AES3_CON_FS) != iec958_con_fs) { |
Przemyslaw Bruski | 4c1847e | 2011-03-13 16:18:56 +0100 | [diff] [blame] | 873 | status &= ~(IEC958_AES3_CON_FS << 24); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 874 | status |= (iec958_con_fs << 24); |
| 875 | dao->ops->set_spos(dao, status); |
| 876 | dao->ops->commit_write(dao); |
| 877 | } |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 878 | if ((rate != atc->pll_rate) && (32000 != rate)) |
| 879 | err = atc_pll_init(atc, rate); |
Takashi Iwai | 635c265 | 2009-06-13 10:12:59 +0200 | [diff] [blame] | 880 | mutex_unlock(&atc->atc_mutex); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 881 | |
| 882 | return err; |
| 883 | } |
| 884 | |
| 885 | static int |
| 886 | spdif_passthru_playback_prepare(struct ct_atc *atc, struct ct_atc_pcm *apcm) |
| 887 | { |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 888 | struct src *src; |
| 889 | struct amixer *amixer; |
| 890 | struct dao *dao; |
| 891 | int err; |
| 892 | int i; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 893 | |
Wai Yew CHAY | 29959a0 | 2009-06-22 14:52:34 +0200 | [diff] [blame] | 894 | atc_pcm_release_resources(atc, apcm); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 895 | |
| 896 | /* Configure SPDIFOO and PLL to passthrough mode; |
| 897 | * determine pll_rate. */ |
| 898 | err = spdif_passthru_playback_setup(atc, apcm); |
| 899 | if (err) |
| 900 | return err; |
| 901 | |
| 902 | /* Get needed resources. */ |
| 903 | err = spdif_passthru_playback_get_resources(atc, apcm); |
| 904 | if (err) |
| 905 | return err; |
| 906 | |
| 907 | /* Connect resources */ |
| 908 | src = apcm->src; |
| 909 | for (i = 0; i < apcm->n_amixer; i++) { |
| 910 | amixer = apcm->amixers[i]; |
| 911 | amixer->ops->setup(amixer, &src->rsc, INIT_VOL, NULL); |
| 912 | src = src->ops->next_interleave(src); |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 913 | if (!src) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 914 | src = apcm->src; |
| 915 | } |
| 916 | /* Connect to SPDIFOO */ |
Takashi Iwai | 635c265 | 2009-06-13 10:12:59 +0200 | [diff] [blame] | 917 | mutex_lock(&atc->atc_mutex); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 918 | dao = container_of(atc->daios[SPDIFOO], struct dao, daio); |
| 919 | amixer = apcm->amixers[0]; |
| 920 | dao->ops->set_left_input(dao, &amixer->rsc); |
| 921 | amixer = apcm->amixers[1]; |
| 922 | dao->ops->set_right_input(dao, &amixer->rsc); |
Takashi Iwai | 635c265 | 2009-06-13 10:12:59 +0200 | [diff] [blame] | 923 | mutex_unlock(&atc->atc_mutex); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 924 | |
Takashi Iwai | b7bbf87 | 2009-06-05 16:11:07 +0200 | [diff] [blame] | 925 | ct_timer_prepare(apcm->timer); |
| 926 | |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 927 | return 0; |
| 928 | } |
| 929 | |
| 930 | static int atc_select_line_in(struct ct_atc *atc) |
| 931 | { |
| 932 | struct hw *hw = atc->hw; |
| 933 | struct ct_mixer *mixer = atc->mixer; |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 934 | struct src *src; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 935 | |
| 936 | if (hw->is_adc_source_selected(hw, ADC_LINEIN)) |
| 937 | return 0; |
| 938 | |
| 939 | mixer->set_input_left(mixer, MIX_MIC_IN, NULL); |
| 940 | mixer->set_input_right(mixer, MIX_MIC_IN, NULL); |
| 941 | |
| 942 | hw->select_adc_source(hw, ADC_LINEIN); |
| 943 | |
| 944 | src = atc->srcs[2]; |
| 945 | mixer->set_input_left(mixer, MIX_LINE_IN, &src->rsc); |
| 946 | src = atc->srcs[3]; |
| 947 | mixer->set_input_right(mixer, MIX_LINE_IN, &src->rsc); |
| 948 | |
| 949 | return 0; |
| 950 | } |
| 951 | |
| 952 | static int atc_select_mic_in(struct ct_atc *atc) |
| 953 | { |
| 954 | struct hw *hw = atc->hw; |
| 955 | struct ct_mixer *mixer = atc->mixer; |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 956 | struct src *src; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 957 | |
| 958 | if (hw->is_adc_source_selected(hw, ADC_MICIN)) |
| 959 | return 0; |
| 960 | |
| 961 | mixer->set_input_left(mixer, MIX_LINE_IN, NULL); |
| 962 | mixer->set_input_right(mixer, MIX_LINE_IN, NULL); |
| 963 | |
| 964 | hw->select_adc_source(hw, ADC_MICIN); |
| 965 | |
| 966 | src = atc->srcs[2]; |
| 967 | mixer->set_input_left(mixer, MIX_MIC_IN, &src->rsc); |
| 968 | src = atc->srcs[3]; |
| 969 | mixer->set_input_right(mixer, MIX_MIC_IN, &src->rsc); |
| 970 | |
| 971 | return 0; |
| 972 | } |
| 973 | |
Harry Butterworth | b028b81 | 2011-06-11 17:41:13 +0800 | [diff] [blame] | 974 | static struct capabilities atc_capabilities(struct ct_atc *atc) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 975 | { |
| 976 | struct hw *hw = atc->hw; |
| 977 | |
Harry Butterworth | b028b81 | 2011-06-11 17:41:13 +0800 | [diff] [blame] | 978 | return hw->capabilities(hw); |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | static int atc_output_switch_get(struct ct_atc *atc) |
| 982 | { |
| 983 | struct hw *hw = atc->hw; |
| 984 | |
| 985 | return hw->output_switch_get(hw); |
| 986 | } |
| 987 | |
| 988 | static int atc_output_switch_put(struct ct_atc *atc, int position) |
| 989 | { |
| 990 | struct hw *hw = atc->hw; |
| 991 | |
| 992 | return hw->output_switch_put(hw, position); |
| 993 | } |
| 994 | |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame] | 995 | static int atc_mic_source_switch_get(struct ct_atc *atc) |
| 996 | { |
| 997 | struct hw *hw = atc->hw; |
| 998 | |
| 999 | return hw->mic_source_switch_get(hw); |
| 1000 | } |
| 1001 | |
| 1002 | static int atc_mic_source_switch_put(struct ct_atc *atc, int position) |
| 1003 | { |
| 1004 | struct hw *hw = atc->hw; |
| 1005 | |
| 1006 | return hw->mic_source_switch_put(hw, position); |
| 1007 | } |
| 1008 | |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1009 | static int atc_select_digit_io(struct ct_atc *atc) |
| 1010 | { |
| 1011 | struct hw *hw = atc->hw; |
| 1012 | |
| 1013 | if (hw->is_adc_source_selected(hw, ADC_NONE)) |
| 1014 | return 0; |
| 1015 | |
| 1016 | hw->select_adc_source(hw, ADC_NONE); |
| 1017 | |
| 1018 | return 0; |
| 1019 | } |
| 1020 | |
| 1021 | static int atc_daio_unmute(struct ct_atc *atc, unsigned char state, int type) |
| 1022 | { |
| 1023 | struct daio_mgr *daio_mgr = atc->rsc_mgrs[DAIO]; |
| 1024 | |
| 1025 | if (state) |
| 1026 | daio_mgr->daio_enable(daio_mgr, atc->daios[type]); |
| 1027 | else |
| 1028 | daio_mgr->daio_disable(daio_mgr, atc->daios[type]); |
| 1029 | |
| 1030 | daio_mgr->commit_write(daio_mgr); |
| 1031 | |
| 1032 | return 0; |
| 1033 | } |
| 1034 | |
| 1035 | static int |
| 1036 | atc_dao_get_status(struct ct_atc *atc, unsigned int *status, int type) |
| 1037 | { |
| 1038 | struct dao *dao = container_of(atc->daios[type], struct dao, daio); |
| 1039 | return dao->ops->get_spos(dao, status); |
| 1040 | } |
| 1041 | |
| 1042 | static int |
| 1043 | atc_dao_set_status(struct ct_atc *atc, unsigned int status, int type) |
| 1044 | { |
| 1045 | struct dao *dao = container_of(atc->daios[type], struct dao, daio); |
| 1046 | |
| 1047 | dao->ops->set_spos(dao, status); |
| 1048 | dao->ops->commit_write(dao); |
| 1049 | return 0; |
| 1050 | } |
| 1051 | |
| 1052 | static int atc_line_front_unmute(struct ct_atc *atc, unsigned char state) |
| 1053 | { |
| 1054 | return atc_daio_unmute(atc, state, LINEO1); |
| 1055 | } |
| 1056 | |
| 1057 | static int atc_line_surround_unmute(struct ct_atc *atc, unsigned char state) |
| 1058 | { |
Sven Eckelmann | 3b04691 | 2009-10-01 20:06:39 +0200 | [diff] [blame] | 1059 | return atc_daio_unmute(atc, state, LINEO2); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | static int atc_line_clfe_unmute(struct ct_atc *atc, unsigned char state) |
| 1063 | { |
| 1064 | return atc_daio_unmute(atc, state, LINEO3); |
| 1065 | } |
| 1066 | |
| 1067 | static int atc_line_rear_unmute(struct ct_atc *atc, unsigned char state) |
| 1068 | { |
Sven Eckelmann | 3b04691 | 2009-10-01 20:06:39 +0200 | [diff] [blame] | 1069 | return atc_daio_unmute(atc, state, LINEO4); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | static int atc_line_in_unmute(struct ct_atc *atc, unsigned char state) |
| 1073 | { |
| 1074 | return atc_daio_unmute(atc, state, LINEIM); |
| 1075 | } |
| 1076 | |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame] | 1077 | static int atc_mic_unmute(struct ct_atc *atc, unsigned char state) |
| 1078 | { |
| 1079 | return atc_daio_unmute(atc, state, MIC); |
| 1080 | } |
| 1081 | |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1082 | static int atc_spdif_out_unmute(struct ct_atc *atc, unsigned char state) |
| 1083 | { |
| 1084 | return atc_daio_unmute(atc, state, SPDIFOO); |
| 1085 | } |
| 1086 | |
| 1087 | static int atc_spdif_in_unmute(struct ct_atc *atc, unsigned char state) |
| 1088 | { |
| 1089 | return atc_daio_unmute(atc, state, SPDIFIO); |
| 1090 | } |
| 1091 | |
| 1092 | static int atc_spdif_out_get_status(struct ct_atc *atc, unsigned int *status) |
| 1093 | { |
| 1094 | return atc_dao_get_status(atc, status, SPDIFOO); |
| 1095 | } |
| 1096 | |
| 1097 | static int atc_spdif_out_set_status(struct ct_atc *atc, unsigned int status) |
| 1098 | { |
| 1099 | return atc_dao_set_status(atc, status, SPDIFOO); |
| 1100 | } |
| 1101 | |
| 1102 | static int atc_spdif_out_passthru(struct ct_atc *atc, unsigned char state) |
| 1103 | { |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1104 | struct dao_desc da_dsc = {0}; |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 1105 | struct dao *dao; |
| 1106 | int err; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1107 | struct ct_mixer *mixer = atc->mixer; |
| 1108 | struct rsc *rscs[2] = {NULL}; |
| 1109 | unsigned int spos = 0; |
| 1110 | |
Takashi Iwai | 635c265 | 2009-06-13 10:12:59 +0200 | [diff] [blame] | 1111 | mutex_lock(&atc->atc_mutex); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1112 | dao = container_of(atc->daios[SPDIFOO], struct dao, daio); |
| 1113 | da_dsc.msr = state ? 1 : atc->msr; |
| 1114 | da_dsc.passthru = state ? 1 : 0; |
| 1115 | err = dao->ops->reinit(dao, &da_dsc); |
| 1116 | if (state) { |
| 1117 | spos = IEC958_DEFAULT_CON; |
| 1118 | } else { |
| 1119 | mixer->get_output_ports(mixer, MIX_SPDIF_OUT, |
| 1120 | &rscs[0], &rscs[1]); |
| 1121 | dao->ops->set_left_input(dao, rscs[0]); |
| 1122 | dao->ops->set_right_input(dao, rscs[1]); |
| 1123 | /* Restore PLL to atc->rsr if needed. */ |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 1124 | if (atc->pll_rate != atc->rsr) |
| 1125 | err = atc_pll_init(atc, atc->rsr); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1126 | } |
| 1127 | dao->ops->set_spos(dao, spos); |
| 1128 | dao->ops->commit_write(dao); |
Takashi Iwai | 635c265 | 2009-06-13 10:12:59 +0200 | [diff] [blame] | 1129 | mutex_unlock(&atc->atc_mutex); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1130 | |
| 1131 | return err; |
| 1132 | } |
| 1133 | |
Wai Yew CHAY | 29959a0 | 2009-06-22 14:52:34 +0200 | [diff] [blame] | 1134 | static int atc_release_resources(struct ct_atc *atc) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1135 | { |
Wai Yew CHAY | 29959a0 | 2009-06-22 14:52:34 +0200 | [diff] [blame] | 1136 | int i; |
| 1137 | struct daio_mgr *daio_mgr = NULL; |
| 1138 | struct dao *dao = NULL; |
| 1139 | struct dai *dai = NULL; |
| 1140 | struct daio *daio = NULL; |
| 1141 | struct sum_mgr *sum_mgr = NULL; |
| 1142 | struct src_mgr *src_mgr = NULL; |
| 1143 | struct srcimp_mgr *srcimp_mgr = NULL; |
| 1144 | struct srcimp *srcimp = NULL; |
| 1145 | struct ct_mixer *mixer = NULL; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1146 | |
Wai Yew CHAY | 29959a0 | 2009-06-22 14:52:34 +0200 | [diff] [blame] | 1147 | /* disconnect internal mixer objects */ |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 1148 | if (atc->mixer) { |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1149 | mixer = atc->mixer; |
| 1150 | mixer->set_input_left(mixer, MIX_LINE_IN, NULL); |
| 1151 | mixer->set_input_right(mixer, MIX_LINE_IN, NULL); |
| 1152 | mixer->set_input_left(mixer, MIX_MIC_IN, NULL); |
| 1153 | mixer->set_input_right(mixer, MIX_MIC_IN, NULL); |
| 1154 | mixer->set_input_left(mixer, MIX_SPDIF_IN, NULL); |
| 1155 | mixer->set_input_right(mixer, MIX_SPDIF_IN, NULL); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1156 | } |
| 1157 | |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 1158 | if (atc->daios) { |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1159 | daio_mgr = (struct daio_mgr *)atc->rsc_mgrs[DAIO]; |
| 1160 | for (i = 0; i < atc->n_daio; i++) { |
| 1161 | daio = atc->daios[i]; |
| 1162 | if (daio->type < LINEIM) { |
| 1163 | dao = container_of(daio, struct dao, daio); |
| 1164 | dao->ops->clear_left_input(dao); |
| 1165 | dao->ops->clear_right_input(dao); |
| 1166 | } else { |
| 1167 | dai = container_of(daio, struct dai, daio); |
| 1168 | /* some thing to do for dai ... */ |
| 1169 | } |
| 1170 | daio_mgr->put_daio(daio_mgr, daio); |
| 1171 | } |
| 1172 | kfree(atc->daios); |
Wai Yew CHAY | 29959a0 | 2009-06-22 14:52:34 +0200 | [diff] [blame] | 1173 | atc->daios = NULL; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1174 | } |
| 1175 | |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 1176 | if (atc->pcm) { |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1177 | sum_mgr = atc->rsc_mgrs[SUM]; |
| 1178 | for (i = 0; i < atc->n_pcm; i++) |
| 1179 | sum_mgr->put_sum(sum_mgr, atc->pcm[i]); |
| 1180 | |
| 1181 | kfree(atc->pcm); |
Wai Yew CHAY | 29959a0 | 2009-06-22 14:52:34 +0200 | [diff] [blame] | 1182 | atc->pcm = NULL; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1183 | } |
| 1184 | |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 1185 | if (atc->srcs) { |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1186 | src_mgr = atc->rsc_mgrs[SRC]; |
| 1187 | for (i = 0; i < atc->n_src; i++) |
| 1188 | src_mgr->put_src(src_mgr, atc->srcs[i]); |
| 1189 | |
| 1190 | kfree(atc->srcs); |
Wai Yew CHAY | 29959a0 | 2009-06-22 14:52:34 +0200 | [diff] [blame] | 1191 | atc->srcs = NULL; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1192 | } |
| 1193 | |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 1194 | if (atc->srcimps) { |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1195 | srcimp_mgr = atc->rsc_mgrs[SRCIMP]; |
| 1196 | for (i = 0; i < atc->n_srcimp; i++) { |
| 1197 | srcimp = atc->srcimps[i]; |
| 1198 | srcimp->ops->unmap(srcimp); |
| 1199 | srcimp_mgr->put_srcimp(srcimp_mgr, atc->srcimps[i]); |
| 1200 | } |
| 1201 | kfree(atc->srcimps); |
Wai Yew CHAY | 29959a0 | 2009-06-22 14:52:34 +0200 | [diff] [blame] | 1202 | atc->srcimps = NULL; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1203 | } |
| 1204 | |
Wai Yew CHAY | 29959a0 | 2009-06-22 14:52:34 +0200 | [diff] [blame] | 1205 | return 0; |
| 1206 | } |
| 1207 | |
| 1208 | static int ct_atc_destroy(struct ct_atc *atc) |
| 1209 | { |
| 1210 | int i = 0; |
| 1211 | |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 1212 | if (!atc) |
Wai Yew CHAY | 29959a0 | 2009-06-22 14:52:34 +0200 | [diff] [blame] | 1213 | return 0; |
| 1214 | |
| 1215 | if (atc->timer) { |
| 1216 | ct_timer_free(atc->timer); |
| 1217 | atc->timer = NULL; |
| 1218 | } |
| 1219 | |
| 1220 | atc_release_resources(atc); |
| 1221 | |
| 1222 | /* Destroy internal mixer objects */ |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 1223 | if (atc->mixer) |
Wai Yew CHAY | 29959a0 | 2009-06-22 14:52:34 +0200 | [diff] [blame] | 1224 | ct_mixer_destroy(atc->mixer); |
| 1225 | |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1226 | for (i = 0; i < NUM_RSCTYP; i++) { |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 1227 | if (rsc_mgr_funcs[i].destroy && atc->rsc_mgrs[i]) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1228 | rsc_mgr_funcs[i].destroy(atc->rsc_mgrs[i]); |
| 1229 | |
| 1230 | } |
| 1231 | |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 1232 | if (atc->hw) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1233 | destroy_hw_obj((struct hw *)atc->hw); |
| 1234 | |
| 1235 | /* Destroy device virtual memory manager object */ |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 1236 | if (atc->vm) { |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1237 | ct_vm_destroy(atc->vm); |
| 1238 | atc->vm = NULL; |
| 1239 | } |
| 1240 | |
| 1241 | kfree(atc); |
| 1242 | |
| 1243 | return 0; |
| 1244 | } |
| 1245 | |
| 1246 | static int atc_dev_free(struct snd_device *dev) |
| 1247 | { |
| 1248 | struct ct_atc *atc = dev->device_data; |
| 1249 | return ct_atc_destroy(atc); |
| 1250 | } |
| 1251 | |
Takashi Iwai | 408bffd | 2010-01-14 09:19:46 +0100 | [diff] [blame] | 1252 | static int __devinit atc_identify_card(struct ct_atc *atc, unsigned int ssid) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1253 | { |
Takashi Iwai | 9470195 | 2009-06-08 18:10:32 +0200 | [diff] [blame] | 1254 | const struct snd_pci_quirk *p; |
| 1255 | const struct snd_pci_quirk *list; |
Takashi Iwai | 408bffd | 2010-01-14 09:19:46 +0100 | [diff] [blame] | 1256 | u16 vendor_id, device_id; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1257 | |
Takashi Iwai | 9470195 | 2009-06-08 18:10:32 +0200 | [diff] [blame] | 1258 | switch (atc->chip_type) { |
| 1259 | case ATC20K1: |
| 1260 | atc->chip_name = "20K1"; |
| 1261 | list = subsys_20k1_list; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1262 | break; |
Takashi Iwai | 9470195 | 2009-06-08 18:10:32 +0200 | [diff] [blame] | 1263 | case ATC20K2: |
| 1264 | atc->chip_name = "20K2"; |
| 1265 | list = subsys_20k2_list; |
| 1266 | break; |
| 1267 | default: |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1268 | return -ENOENT; |
Takashi Iwai | 9470195 | 2009-06-08 18:10:32 +0200 | [diff] [blame] | 1269 | } |
Takashi Iwai | 408bffd | 2010-01-14 09:19:46 +0100 | [diff] [blame] | 1270 | if (ssid) { |
| 1271 | vendor_id = ssid >> 16; |
| 1272 | device_id = ssid & 0xffff; |
| 1273 | } else { |
| 1274 | vendor_id = atc->pci->subsystem_vendor; |
| 1275 | device_id = atc->pci->subsystem_device; |
| 1276 | } |
| 1277 | p = snd_pci_quirk_lookup_id(vendor_id, device_id, list); |
Takashi Iwai | a8f4310 | 2009-06-22 07:36:52 +0200 | [diff] [blame] | 1278 | if (p) { |
| 1279 | if (p->value < 0) { |
| 1280 | printk(KERN_ERR "ctxfi: " |
| 1281 | "Device %04x:%04x is black-listed\n", |
Takashi Iwai | 408bffd | 2010-01-14 09:19:46 +0100 | [diff] [blame] | 1282 | vendor_id, device_id); |
Takashi Iwai | a8f4310 | 2009-06-22 07:36:52 +0200 | [diff] [blame] | 1283 | return -ENOENT; |
| 1284 | } |
| 1285 | atc->model = p->value; |
| 1286 | } else { |
| 1287 | if (atc->chip_type == ATC20K1) |
| 1288 | atc->model = CT20K1_UNKNOWN; |
| 1289 | else |
| 1290 | atc->model = CT20K2_UNKNOWN; |
| 1291 | } |
Takashi Iwai | 9470195 | 2009-06-08 18:10:32 +0200 | [diff] [blame] | 1292 | atc->model_name = ct_subsys_name[atc->model]; |
| 1293 | snd_printd("ctxfi: chip %s model %s (%04x:%04x) is found\n", |
| 1294 | atc->chip_name, atc->model_name, |
Takashi Iwai | 408bffd | 2010-01-14 09:19:46 +0100 | [diff] [blame] | 1295 | vendor_id, device_id); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1296 | return 0; |
| 1297 | } |
| 1298 | |
Takashi Iwai | 2a36f67 | 2009-06-05 16:34:10 +0200 | [diff] [blame] | 1299 | int __devinit ct_atc_create_alsa_devs(struct ct_atc *atc) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1300 | { |
| 1301 | enum CTALSADEVS i; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1302 | int err; |
| 1303 | |
Takashi Iwai | 9470195 | 2009-06-08 18:10:32 +0200 | [diff] [blame] | 1304 | alsa_dev_funcs[MIXER].public_name = atc->chip_name; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1305 | |
| 1306 | for (i = 0; i < NUM_CTALSADEVS; i++) { |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 1307 | if (!alsa_dev_funcs[i].create) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1308 | continue; |
| 1309 | |
| 1310 | err = alsa_dev_funcs[i].create(atc, i, |
| 1311 | alsa_dev_funcs[i].public_name); |
| 1312 | if (err) { |
Takashi Iwai | b3e0afe | 2009-05-14 15:19:30 +0200 | [diff] [blame] | 1313 | printk(KERN_ERR "ctxfi: " |
| 1314 | "Creating alsa device %d failed!\n", i); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1315 | return err; |
| 1316 | } |
| 1317 | } |
| 1318 | |
| 1319 | return 0; |
| 1320 | } |
| 1321 | |
Takashi Iwai | 2a36f67 | 2009-06-05 16:34:10 +0200 | [diff] [blame] | 1322 | static int __devinit atc_create_hw_devs(struct ct_atc *atc) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1323 | { |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 1324 | struct hw *hw; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1325 | struct card_conf info = {0}; |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 1326 | int i, err; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1327 | |
Takashi Iwai | 9470195 | 2009-06-08 18:10:32 +0200 | [diff] [blame] | 1328 | err = create_hw_obj(atc->pci, atc->chip_type, atc->model, &hw); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1329 | if (err) { |
| 1330 | printk(KERN_ERR "Failed to create hw obj!!!\n"); |
| 1331 | return err; |
| 1332 | } |
| 1333 | atc->hw = hw; |
| 1334 | |
| 1335 | /* Initialize card hardware. */ |
| 1336 | info.rsr = atc->rsr; |
| 1337 | info.msr = atc->msr; |
| 1338 | info.vm_pgt_phys = atc_get_ptp_phys(atc, 0); |
| 1339 | err = hw->card_init(hw, &info); |
| 1340 | if (err < 0) |
| 1341 | return err; |
| 1342 | |
| 1343 | for (i = 0; i < NUM_RSCTYP; i++) { |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 1344 | if (!rsc_mgr_funcs[i].create) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1345 | continue; |
| 1346 | |
| 1347 | err = rsc_mgr_funcs[i].create(atc->hw, &atc->rsc_mgrs[i]); |
| 1348 | if (err) { |
Takashi Iwai | b3e0afe | 2009-05-14 15:19:30 +0200 | [diff] [blame] | 1349 | printk(KERN_ERR "ctxfi: " |
| 1350 | "Failed to create rsc_mgr %d!!!\n", i); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1351 | return err; |
| 1352 | } |
| 1353 | } |
| 1354 | |
| 1355 | return 0; |
| 1356 | } |
| 1357 | |
Wai Yew CHAY | 29959a0 | 2009-06-22 14:52:34 +0200 | [diff] [blame] | 1358 | static int atc_get_resources(struct ct_atc *atc) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1359 | { |
| 1360 | struct daio_desc da_desc = {0}; |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 1361 | struct daio_mgr *daio_mgr; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1362 | struct src_desc src_dsc = {0}; |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 1363 | struct src_mgr *src_mgr; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1364 | struct srcimp_desc srcimp_dsc = {0}; |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 1365 | struct srcimp_mgr *srcimp_mgr; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1366 | struct sum_desc sum_dsc = {0}; |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 1367 | struct sum_mgr *sum_mgr; |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame] | 1368 | int err, i, num_srcs, num_daios; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1369 | |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame] | 1370 | num_daios = ((atc->model == CTSB1270) ? 8 : 7); |
| 1371 | num_srcs = ((atc->model == CTSB1270) ? 6 : 4); |
| 1372 | |
| 1373 | atc->daios = kzalloc(sizeof(void *)*num_daios, GFP_KERNEL); |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 1374 | if (!atc->daios) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1375 | return -ENOMEM; |
| 1376 | |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame] | 1377 | atc->srcs = kzalloc(sizeof(void *)*num_srcs, GFP_KERNEL); |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 1378 | if (!atc->srcs) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1379 | return -ENOMEM; |
| 1380 | |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame] | 1381 | atc->srcimps = kzalloc(sizeof(void *)*num_srcs, GFP_KERNEL); |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 1382 | if (!atc->srcimps) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1383 | return -ENOMEM; |
| 1384 | |
| 1385 | atc->pcm = kzalloc(sizeof(void *)*(2*4), GFP_KERNEL); |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 1386 | if (!atc->pcm) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1387 | return -ENOMEM; |
| 1388 | |
| 1389 | daio_mgr = (struct daio_mgr *)atc->rsc_mgrs[DAIO]; |
| 1390 | da_desc.msr = atc->msr; |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame] | 1391 | for (i = 0, atc->n_daio = 0; i < num_daios; i++) { |
| 1392 | da_desc.type = (atc->model != CTSB073X) ? i : |
| 1393 | ((i == SPDIFIO) ? SPDIFI1 : i); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1394 | err = daio_mgr->get_daio(daio_mgr, &da_desc, |
| 1395 | (struct daio **)&atc->daios[i]); |
| 1396 | if (err) { |
Takashi Iwai | b3e0afe | 2009-05-14 15:19:30 +0200 | [diff] [blame] | 1397 | printk(KERN_ERR "ctxfi: Failed to get DAIO " |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1398 | "resource %d!!!\n", i); |
| 1399 | return err; |
| 1400 | } |
| 1401 | atc->n_daio++; |
| 1402 | } |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1403 | |
| 1404 | src_mgr = atc->rsc_mgrs[SRC]; |
| 1405 | src_dsc.multi = 1; |
| 1406 | src_dsc.msr = atc->msr; |
| 1407 | src_dsc.mode = ARCRW; |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame] | 1408 | for (i = 0, atc->n_src = 0; i < num_srcs; i++) { |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1409 | err = src_mgr->get_src(src_mgr, &src_dsc, |
| 1410 | (struct src **)&atc->srcs[i]); |
| 1411 | if (err) |
| 1412 | return err; |
| 1413 | |
| 1414 | atc->n_src++; |
| 1415 | } |
| 1416 | |
| 1417 | srcimp_mgr = atc->rsc_mgrs[SRCIMP]; |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame] | 1418 | srcimp_dsc.msr = 8; |
| 1419 | for (i = 0, atc->n_srcimp = 0; i < num_srcs; i++) { |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1420 | err = srcimp_mgr->get_srcimp(srcimp_mgr, &srcimp_dsc, |
| 1421 | (struct srcimp **)&atc->srcimps[i]); |
| 1422 | if (err) |
| 1423 | return err; |
| 1424 | |
| 1425 | atc->n_srcimp++; |
| 1426 | } |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1427 | |
| 1428 | sum_mgr = atc->rsc_mgrs[SUM]; |
| 1429 | sum_dsc.msr = atc->msr; |
| 1430 | for (i = 0, atc->n_pcm = 0; i < (2*4); i++) { |
| 1431 | err = sum_mgr->get_sum(sum_mgr, &sum_dsc, |
| 1432 | (struct sum **)&atc->pcm[i]); |
| 1433 | if (err) |
| 1434 | return err; |
| 1435 | |
| 1436 | atc->n_pcm++; |
| 1437 | } |
| 1438 | |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1439 | return 0; |
| 1440 | } |
| 1441 | |
Wai Yew CHAY | 29959a0 | 2009-06-22 14:52:34 +0200 | [diff] [blame] | 1442 | static void |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1443 | atc_connect_dai(struct src_mgr *src_mgr, struct dai *dai, |
| 1444 | struct src **srcs, struct srcimp **srcimps) |
| 1445 | { |
| 1446 | struct rsc *rscs[2] = {NULL}; |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 1447 | struct src *src; |
| 1448 | struct srcimp *srcimp; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1449 | int i = 0; |
| 1450 | |
| 1451 | rscs[0] = &dai->daio.rscl; |
| 1452 | rscs[1] = &dai->daio.rscr; |
| 1453 | for (i = 0; i < 2; i++) { |
| 1454 | src = srcs[i]; |
| 1455 | srcimp = srcimps[i]; |
| 1456 | srcimp->ops->map(srcimp, src, rscs[i]); |
| 1457 | src_mgr->src_disable(src_mgr, src); |
| 1458 | } |
| 1459 | |
| 1460 | src_mgr->commit_write(src_mgr); /* Actually disable SRCs */ |
| 1461 | |
| 1462 | src = srcs[0]; |
| 1463 | src->ops->set_pm(src, 1); |
| 1464 | for (i = 0; i < 2; i++) { |
| 1465 | src = srcs[i]; |
| 1466 | src->ops->set_state(src, SRC_STATE_RUN); |
| 1467 | src->ops->commit_write(src); |
| 1468 | src_mgr->src_enable_s(src_mgr, src); |
| 1469 | } |
| 1470 | |
| 1471 | dai->ops->set_srt_srcl(dai, &(srcs[0]->rsc)); |
| 1472 | dai->ops->set_srt_srcr(dai, &(srcs[1]->rsc)); |
| 1473 | |
| 1474 | dai->ops->set_enb_src(dai, 1); |
| 1475 | dai->ops->set_enb_srt(dai, 1); |
| 1476 | dai->ops->commit_write(dai); |
| 1477 | |
| 1478 | src_mgr->commit_write(src_mgr); /* Synchronously enable SRCs */ |
| 1479 | } |
| 1480 | |
Wai Yew CHAY | 29959a0 | 2009-06-22 14:52:34 +0200 | [diff] [blame] | 1481 | static void atc_connect_resources(struct ct_atc *atc) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1482 | { |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 1483 | struct dai *dai; |
| 1484 | struct dao *dao; |
| 1485 | struct src *src; |
| 1486 | struct sum *sum; |
| 1487 | struct ct_mixer *mixer; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1488 | struct rsc *rscs[2] = {NULL}; |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 1489 | int i, j; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1490 | |
| 1491 | mixer = atc->mixer; |
| 1492 | |
| 1493 | for (i = MIX_WAVE_FRONT, j = LINEO1; i <= MIX_SPDIF_OUT; i++, j++) { |
| 1494 | mixer->get_output_ports(mixer, i, &rscs[0], &rscs[1]); |
| 1495 | dao = container_of(atc->daios[j], struct dao, daio); |
| 1496 | dao->ops->set_left_input(dao, rscs[0]); |
| 1497 | dao->ops->set_right_input(dao, rscs[1]); |
| 1498 | } |
| 1499 | |
| 1500 | dai = container_of(atc->daios[LINEIM], struct dai, daio); |
| 1501 | atc_connect_dai(atc->rsc_mgrs[SRC], dai, |
| 1502 | (struct src **)&atc->srcs[2], |
| 1503 | (struct srcimp **)&atc->srcimps[2]); |
| 1504 | src = atc->srcs[2]; |
| 1505 | mixer->set_input_left(mixer, MIX_LINE_IN, &src->rsc); |
| 1506 | src = atc->srcs[3]; |
| 1507 | mixer->set_input_right(mixer, MIX_LINE_IN, &src->rsc); |
| 1508 | |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame] | 1509 | if (atc->model == CTSB1270) { |
| 1510 | /* Titanium HD has a dedicated ADC for the Mic. */ |
| 1511 | dai = container_of(atc->daios[MIC], struct dai, daio); |
| 1512 | atc_connect_dai(atc->rsc_mgrs[SRC], dai, |
| 1513 | (struct src **)&atc->srcs[4], |
| 1514 | (struct srcimp **)&atc->srcimps[4]); |
| 1515 | src = atc->srcs[4]; |
| 1516 | mixer->set_input_left(mixer, MIX_MIC_IN, &src->rsc); |
| 1517 | src = atc->srcs[5]; |
| 1518 | mixer->set_input_right(mixer, MIX_MIC_IN, &src->rsc); |
| 1519 | } |
| 1520 | |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1521 | dai = container_of(atc->daios[SPDIFIO], struct dai, daio); |
| 1522 | atc_connect_dai(atc->rsc_mgrs[SRC], dai, |
| 1523 | (struct src **)&atc->srcs[0], |
| 1524 | (struct srcimp **)&atc->srcimps[0]); |
| 1525 | |
| 1526 | src = atc->srcs[0]; |
| 1527 | mixer->set_input_left(mixer, MIX_SPDIF_IN, &src->rsc); |
| 1528 | src = atc->srcs[1]; |
| 1529 | mixer->set_input_right(mixer, MIX_SPDIF_IN, &src->rsc); |
| 1530 | |
| 1531 | for (i = MIX_PCMI_FRONT, j = 0; i <= MIX_PCMI_SURROUND; i++, j += 2) { |
| 1532 | sum = atc->pcm[j]; |
| 1533 | mixer->set_input_left(mixer, i, &sum->rsc); |
| 1534 | sum = atc->pcm[j+1]; |
| 1535 | mixer->set_input_right(mixer, i, &sum->rsc); |
| 1536 | } |
| 1537 | } |
| 1538 | |
Wai Yew CHAY | 29959a0 | 2009-06-22 14:52:34 +0200 | [diff] [blame] | 1539 | #ifdef CONFIG_PM |
| 1540 | static int atc_suspend(struct ct_atc *atc, pm_message_t state) |
| 1541 | { |
| 1542 | int i; |
| 1543 | struct hw *hw = atc->hw; |
| 1544 | |
| 1545 | snd_power_change_state(atc->card, SNDRV_CTL_POWER_D3hot); |
| 1546 | |
| 1547 | for (i = FRONT; i < NUM_PCMS; i++) { |
| 1548 | if (!atc->pcms[i]) |
| 1549 | continue; |
| 1550 | |
| 1551 | snd_pcm_suspend_all(atc->pcms[i]); |
| 1552 | } |
| 1553 | |
| 1554 | atc_release_resources(atc); |
| 1555 | |
| 1556 | hw->suspend(hw, state); |
| 1557 | |
| 1558 | return 0; |
| 1559 | } |
| 1560 | |
| 1561 | static int atc_hw_resume(struct ct_atc *atc) |
| 1562 | { |
| 1563 | struct hw *hw = atc->hw; |
| 1564 | struct card_conf info = {0}; |
| 1565 | |
| 1566 | /* Re-initialize card hardware. */ |
| 1567 | info.rsr = atc->rsr; |
| 1568 | info.msr = atc->msr; |
| 1569 | info.vm_pgt_phys = atc_get_ptp_phys(atc, 0); |
| 1570 | return hw->resume(hw, &info); |
| 1571 | } |
| 1572 | |
| 1573 | static int atc_resources_resume(struct ct_atc *atc) |
| 1574 | { |
| 1575 | struct ct_mixer *mixer; |
| 1576 | int err = 0; |
| 1577 | |
| 1578 | /* Get resources */ |
| 1579 | err = atc_get_resources(atc); |
| 1580 | if (err < 0) { |
| 1581 | atc_release_resources(atc); |
| 1582 | return err; |
| 1583 | } |
| 1584 | |
| 1585 | /* Build topology */ |
| 1586 | atc_connect_resources(atc); |
| 1587 | |
| 1588 | mixer = atc->mixer; |
| 1589 | mixer->resume(mixer); |
| 1590 | |
| 1591 | return 0; |
| 1592 | } |
| 1593 | |
| 1594 | static int atc_resume(struct ct_atc *atc) |
| 1595 | { |
| 1596 | int err = 0; |
| 1597 | |
| 1598 | /* Do hardware resume. */ |
| 1599 | err = atc_hw_resume(atc); |
| 1600 | if (err < 0) { |
| 1601 | printk(KERN_ERR "ctxfi: pci_enable_device failed, " |
| 1602 | "disabling device\n"); |
| 1603 | snd_card_disconnect(atc->card); |
| 1604 | return err; |
| 1605 | } |
| 1606 | |
| 1607 | err = atc_resources_resume(atc); |
| 1608 | if (err < 0) |
| 1609 | return err; |
| 1610 | |
| 1611 | snd_power_change_state(atc->card, SNDRV_CTL_POWER_D0); |
| 1612 | |
| 1613 | return 0; |
| 1614 | } |
| 1615 | #endif |
| 1616 | |
Takashi Iwai | 2a36f67 | 2009-06-05 16:34:10 +0200 | [diff] [blame] | 1617 | static struct ct_atc atc_preset __devinitdata = { |
| 1618 | .map_audio_buffer = ct_map_audio_buffer, |
| 1619 | .unmap_audio_buffer = ct_unmap_audio_buffer, |
| 1620 | .pcm_playback_prepare = atc_pcm_playback_prepare, |
| 1621 | .pcm_release_resources = atc_pcm_release_resources, |
| 1622 | .pcm_playback_start = atc_pcm_playback_start, |
| 1623 | .pcm_playback_stop = atc_pcm_stop, |
| 1624 | .pcm_playback_position = atc_pcm_playback_position, |
| 1625 | .pcm_capture_prepare = atc_pcm_capture_prepare, |
| 1626 | .pcm_capture_start = atc_pcm_capture_start, |
| 1627 | .pcm_capture_stop = atc_pcm_stop, |
| 1628 | .pcm_capture_position = atc_pcm_capture_position, |
| 1629 | .spdif_passthru_playback_prepare = spdif_passthru_playback_prepare, |
| 1630 | .get_ptp_phys = atc_get_ptp_phys, |
| 1631 | .select_line_in = atc_select_line_in, |
| 1632 | .select_mic_in = atc_select_mic_in, |
| 1633 | .select_digit_io = atc_select_digit_io, |
| 1634 | .line_front_unmute = atc_line_front_unmute, |
| 1635 | .line_surround_unmute = atc_line_surround_unmute, |
| 1636 | .line_clfe_unmute = atc_line_clfe_unmute, |
| 1637 | .line_rear_unmute = atc_line_rear_unmute, |
| 1638 | .line_in_unmute = atc_line_in_unmute, |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame] | 1639 | .mic_unmute = atc_mic_unmute, |
Takashi Iwai | 2a36f67 | 2009-06-05 16:34:10 +0200 | [diff] [blame] | 1640 | .spdif_out_unmute = atc_spdif_out_unmute, |
| 1641 | .spdif_in_unmute = atc_spdif_in_unmute, |
| 1642 | .spdif_out_get_status = atc_spdif_out_get_status, |
| 1643 | .spdif_out_set_status = atc_spdif_out_set_status, |
| 1644 | .spdif_out_passthru = atc_spdif_out_passthru, |
Harry Butterworth | b028b81 | 2011-06-11 17:41:13 +0800 | [diff] [blame] | 1645 | .capabilities = atc_capabilities, |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame] | 1646 | .output_switch_get = atc_output_switch_get, |
| 1647 | .output_switch_put = atc_output_switch_put, |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame] | 1648 | .mic_source_switch_get = atc_mic_source_switch_get, |
| 1649 | .mic_source_switch_put = atc_mic_source_switch_put, |
Wai Yew CHAY | 29959a0 | 2009-06-22 14:52:34 +0200 | [diff] [blame] | 1650 | #ifdef CONFIG_PM |
| 1651 | .suspend = atc_suspend, |
| 1652 | .resume = atc_resume, |
| 1653 | #endif |
Takashi Iwai | 2a36f67 | 2009-06-05 16:34:10 +0200 | [diff] [blame] | 1654 | }; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1655 | |
| 1656 | /** |
| 1657 | * ct_atc_create - create and initialize a hardware manager |
| 1658 | * @card: corresponding alsa card object |
| 1659 | * @pci: corresponding kernel pci device object |
| 1660 | * @ratc: return created object address in it |
| 1661 | * |
| 1662 | * Creates and initializes a hardware manager. |
| 1663 | * |
| 1664 | * Creates kmallocated ct_atc structure. Initializes hardware. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1665 | * Returns 0 if succeeds, or negative error code if fails. |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1666 | */ |
| 1667 | |
Takashi Iwai | 2a36f67 | 2009-06-05 16:34:10 +0200 | [diff] [blame] | 1668 | int __devinit ct_atc_create(struct snd_card *card, struct pci_dev *pci, |
Takashi Iwai | 9470195 | 2009-06-08 18:10:32 +0200 | [diff] [blame] | 1669 | unsigned int rsr, unsigned int msr, |
Takashi Iwai | 408bffd | 2010-01-14 09:19:46 +0100 | [diff] [blame] | 1670 | int chip_type, unsigned int ssid, |
| 1671 | struct ct_atc **ratc) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1672 | { |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 1673 | struct ct_atc *atc; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1674 | static struct snd_device_ops ops = { |
| 1675 | .dev_free = atc_dev_free, |
| 1676 | }; |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 1677 | int err; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1678 | |
| 1679 | *ratc = NULL; |
| 1680 | |
| 1681 | atc = kzalloc(sizeof(*atc), GFP_KERNEL); |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 1682 | if (!atc) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1683 | return -ENOMEM; |
| 1684 | |
Takashi Iwai | 2a36f67 | 2009-06-05 16:34:10 +0200 | [diff] [blame] | 1685 | /* Set operations */ |
| 1686 | *atc = atc_preset; |
| 1687 | |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1688 | atc->card = card; |
| 1689 | atc->pci = pci; |
| 1690 | atc->rsr = rsr; |
| 1691 | atc->msr = msr; |
Takashi Iwai | 9470195 | 2009-06-08 18:10:32 +0200 | [diff] [blame] | 1692 | atc->chip_type = chip_type; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1693 | |
Takashi Iwai | 635c265 | 2009-06-13 10:12:59 +0200 | [diff] [blame] | 1694 | mutex_init(&atc->atc_mutex); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1695 | |
| 1696 | /* Find card model */ |
Takashi Iwai | 408bffd | 2010-01-14 09:19:46 +0100 | [diff] [blame] | 1697 | err = atc_identify_card(atc, ssid); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1698 | if (err < 0) { |
| 1699 | printk(KERN_ERR "ctatc: Card not recognised\n"); |
| 1700 | goto error1; |
| 1701 | } |
| 1702 | |
| 1703 | /* Set up device virtual memory management object */ |
Jaroslav Kysela | 21956b6 | 2010-02-02 19:58:25 +0100 | [diff] [blame] | 1704 | err = ct_vm_create(&atc->vm, pci); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1705 | if (err < 0) |
| 1706 | goto error1; |
| 1707 | |
| 1708 | /* Create all atc hw devices */ |
| 1709 | err = atc_create_hw_devs(atc); |
| 1710 | if (err < 0) |
| 1711 | goto error1; |
| 1712 | |
Wai Yew CHAY | 29959a0 | 2009-06-22 14:52:34 +0200 | [diff] [blame] | 1713 | err = ct_mixer_create(atc, (struct ct_mixer **)&atc->mixer); |
| 1714 | if (err) { |
| 1715 | printk(KERN_ERR "ctxfi: Failed to create mixer obj!!!\n"); |
| 1716 | goto error1; |
| 1717 | } |
| 1718 | |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1719 | /* Get resources */ |
| 1720 | err = atc_get_resources(atc); |
| 1721 | if (err < 0) |
| 1722 | goto error1; |
| 1723 | |
| 1724 | /* Build topology */ |
| 1725 | atc_connect_resources(atc); |
| 1726 | |
Takashi Iwai | b7bbf87 | 2009-06-05 16:11:07 +0200 | [diff] [blame] | 1727 | atc->timer = ct_timer_new(atc); |
| 1728 | if (!atc->timer) |
| 1729 | goto error1; |
| 1730 | |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1731 | err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, atc, &ops); |
| 1732 | if (err < 0) |
| 1733 | goto error1; |
| 1734 | |
| 1735 | snd_card_set_dev(card, &pci->dev); |
| 1736 | |
| 1737 | *ratc = atc; |
| 1738 | return 0; |
| 1739 | |
| 1740 | error1: |
| 1741 | ct_atc_destroy(atc); |
Takashi Iwai | b3e0afe | 2009-05-14 15:19:30 +0200 | [diff] [blame] | 1742 | printk(KERN_ERR "ctxfi: Something wrong!!!\n"); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1743 | return err; |
| 1744 | } |