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