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