^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) 2020 Intel Corporation. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) // Author: Cezary Rojewski <cezary.rojewski@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/pm_runtime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <sound/soc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <sound/pcm_params.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <uapi/sound/tlv.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "core.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "messages.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) struct catpt_stream_template {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) enum catpt_path_id path_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) enum catpt_stream_type type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) u32 persistent_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) u8 num_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct catpt_module_entry entries[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) static struct catpt_stream_template system_pb = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) .path_id = CATPT_PATH_SSP0_OUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) .type = CATPT_STRM_TYPE_SYSTEM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) .num_entries = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) .entries = {{ CATPT_MODID_PCM_SYSTEM, 0 }},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static struct catpt_stream_template system_cp = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) .path_id = CATPT_PATH_SSP0_IN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) .type = CATPT_STRM_TYPE_CAPTURE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) .num_entries = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) .entries = {{ CATPT_MODID_PCM_CAPTURE, 0 }},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) static struct catpt_stream_template offload_pb = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) .path_id = CATPT_PATH_SSP0_OUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) .type = CATPT_STRM_TYPE_RENDER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) .num_entries = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) .entries = {{ CATPT_MODID_PCM, 0 }},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static struct catpt_stream_template loopback_cp = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) .path_id = CATPT_PATH_SSP0_OUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) .type = CATPT_STRM_TYPE_LOOPBACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) .num_entries = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) .entries = {{ CATPT_MODID_PCM_REFERENCE, 0 }},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static struct catpt_stream_template bluetooth_pb = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) .path_id = CATPT_PATH_SSP1_OUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) .type = CATPT_STRM_TYPE_BLUETOOTH_RENDER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) .num_entries = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) .entries = {{ CATPT_MODID_BLUETOOTH_RENDER, 0 }},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) static struct catpt_stream_template bluetooth_cp = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) .path_id = CATPT_PATH_SSP1_IN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) .type = CATPT_STRM_TYPE_BLUETOOTH_CAPTURE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) .num_entries = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) .entries = {{ CATPT_MODID_BLUETOOTH_CAPTURE, 0 }},
^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 struct catpt_stream_template *catpt_topology[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) [CATPT_STRM_TYPE_RENDER] = &offload_pb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) [CATPT_STRM_TYPE_SYSTEM] = &system_pb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) [CATPT_STRM_TYPE_CAPTURE] = &system_cp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) [CATPT_STRM_TYPE_LOOPBACK] = &loopback_cp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) [CATPT_STRM_TYPE_BLUETOOTH_RENDER] = &bluetooth_pb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) [CATPT_STRM_TYPE_BLUETOOTH_CAPTURE] = &bluetooth_cp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static struct catpt_stream_template *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) catpt_get_stream_template(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct snd_soc_pcm_runtime *rtm = substream->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtm, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) enum catpt_stream_type type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) type = cpu_dai->driver->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /* account for capture in bidirectional dais */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) case CATPT_STRM_TYPE_SYSTEM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) type = CATPT_STRM_TYPE_CAPTURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) case CATPT_STRM_TYPE_BLUETOOTH_RENDER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) type = CATPT_STRM_TYPE_BLUETOOTH_CAPTURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) return catpt_topology[type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) struct catpt_stream_runtime *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) catpt_stream_find(struct catpt_dev *cdev, u8 stream_hw_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) struct catpt_stream_runtime *pos, *result = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) spin_lock(&cdev->list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) list_for_each_entry(pos, &cdev->stream_list, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (pos->info.stream_hw_id == stream_hw_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) result = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) spin_unlock(&cdev->list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static u32 catpt_stream_read_position(struct catpt_dev *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct catpt_stream_runtime *stream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) u32 pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) memcpy_fromio(&pos, cdev->lpe_ba + stream->info.read_pos_regaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) sizeof(pos));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static u32 catpt_stream_volume(struct catpt_dev *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct catpt_stream_runtime *stream, u32 channel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) u32 volume, offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if (channel >= CATPT_CHANNELS_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) channel = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) offset = stream->info.volume_regaddr[channel];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) memcpy_fromio(&volume, cdev->lpe_ba + offset, sizeof(volume));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) return volume;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static u32 catpt_mixer_volume(struct catpt_dev *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) struct catpt_mixer_stream_info *info, u32 channel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) u32 volume, offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) if (channel >= CATPT_CHANNELS_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) channel = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) offset = info->volume_regaddr[channel];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) memcpy_fromio(&volume, cdev->lpe_ba + offset, sizeof(volume));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) return volume;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static void catpt_arrange_page_table(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) struct snd_dma_buffer *pgtbl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) struct snd_pcm_runtime *rtm = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) struct snd_dma_buffer *databuf = snd_pcm_get_dma_buf(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) int i, pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) pages = snd_sgbuf_aligned_pages(rtm->dma_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) for (i = 0; i < pages; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) u32 pfn, offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) u32 *page_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) pfn = PFN_DOWN(snd_sgbuf_get_addr(databuf, i * PAGE_SIZE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) /* incrementing by 2 on even and 3 on odd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) offset = ((i << 2) + i) >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) page_table = (u32 *)(pgtbl->area + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) if (i & 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) *page_table |= (pfn << 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) *page_table |= pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static u32 catpt_get_channel_map(enum catpt_channel_config config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) switch (config) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) case CATPT_CHANNEL_CONFIG_MONO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return GENMASK(31, 4) | CATPT_CHANNEL_CENTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) case CATPT_CHANNEL_CONFIG_STEREO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) return GENMASK(31, 8) | CATPT_CHANNEL_LEFT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) | (CATPT_CHANNEL_RIGHT << 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) case CATPT_CHANNEL_CONFIG_2_POINT_1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) return GENMASK(31, 12) | CATPT_CHANNEL_LEFT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) | (CATPT_CHANNEL_RIGHT << 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) | (CATPT_CHANNEL_LFE << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) case CATPT_CHANNEL_CONFIG_3_POINT_0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) return GENMASK(31, 12) | CATPT_CHANNEL_LEFT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) | (CATPT_CHANNEL_CENTER << 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) | (CATPT_CHANNEL_RIGHT << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) case CATPT_CHANNEL_CONFIG_3_POINT_1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return GENMASK(31, 16) | CATPT_CHANNEL_LEFT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) | (CATPT_CHANNEL_CENTER << 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) | (CATPT_CHANNEL_RIGHT << 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) | (CATPT_CHANNEL_LFE << 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) case CATPT_CHANNEL_CONFIG_QUATRO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) return GENMASK(31, 16) | CATPT_CHANNEL_LEFT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) | (CATPT_CHANNEL_RIGHT << 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) | (CATPT_CHANNEL_LEFT_SURROUND << 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) | (CATPT_CHANNEL_RIGHT_SURROUND << 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) case CATPT_CHANNEL_CONFIG_4_POINT_0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) return GENMASK(31, 16) | CATPT_CHANNEL_LEFT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) | (CATPT_CHANNEL_CENTER << 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) | (CATPT_CHANNEL_RIGHT << 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) | (CATPT_CHANNEL_CENTER_SURROUND << 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) case CATPT_CHANNEL_CONFIG_5_POINT_0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) return GENMASK(31, 20) | CATPT_CHANNEL_LEFT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) | (CATPT_CHANNEL_CENTER << 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) | (CATPT_CHANNEL_RIGHT << 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) | (CATPT_CHANNEL_LEFT_SURROUND << 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) | (CATPT_CHANNEL_RIGHT_SURROUND << 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) case CATPT_CHANNEL_CONFIG_5_POINT_1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) return GENMASK(31, 24) | CATPT_CHANNEL_CENTER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) | (CATPT_CHANNEL_LEFT << 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) | (CATPT_CHANNEL_RIGHT << 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) | (CATPT_CHANNEL_LEFT_SURROUND << 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) | (CATPT_CHANNEL_RIGHT_SURROUND << 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) | (CATPT_CHANNEL_LFE << 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) case CATPT_CHANNEL_CONFIG_DUAL_MONO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) return GENMASK(31, 8) | CATPT_CHANNEL_LEFT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) | (CATPT_CHANNEL_LEFT << 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) return U32_MAX;
^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 enum catpt_channel_config catpt_get_channel_config(u32 num_channels)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) switch (num_channels) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) case 6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) return CATPT_CHANNEL_CONFIG_5_POINT_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) case 5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) return CATPT_CHANNEL_CONFIG_5_POINT_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) return CATPT_CHANNEL_CONFIG_QUATRO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) return CATPT_CHANNEL_CONFIG_2_POINT_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) return CATPT_CHANNEL_CONFIG_MONO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) return CATPT_CHANNEL_CONFIG_STEREO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static int catpt_dai_startup(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) struct snd_soc_dai *dai)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) struct catpt_dev *cdev = dev_get_drvdata(dai->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) struct catpt_stream_template *template;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) struct catpt_stream_runtime *stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) struct resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) template = catpt_get_stream_template(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) stream = kzalloc(sizeof(*stream), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) if (!stream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, cdev->dev, PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) &stream->pgtbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) goto err_pgtbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) res = catpt_request_region(&cdev->dram, template->persistent_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) if (!res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) ret = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) goto err_request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) catpt_dsp_update_srampge(cdev, &cdev->dram, cdev->spec->dram_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) stream->template = template;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) stream->persistent = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) stream->substream = substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) INIT_LIST_HEAD(&stream->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) snd_soc_dai_set_dma_data(dai, substream, stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) spin_lock(&cdev->list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) list_add_tail(&stream->node, &cdev->stream_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) spin_unlock(&cdev->list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) err_request:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) snd_dma_free_pages(&stream->pgtbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) err_pgtbl:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) kfree(stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) static void catpt_dai_shutdown(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) struct snd_soc_dai *dai)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) struct catpt_dev *cdev = dev_get_drvdata(dai->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) struct catpt_stream_runtime *stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) stream = snd_soc_dai_get_dma_data(dai, substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) spin_lock(&cdev->list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) list_del(&stream->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) spin_unlock(&cdev->list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) release_resource(stream->persistent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) kfree(stream->persistent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) catpt_dsp_update_srampge(cdev, &cdev->dram, cdev->spec->dram_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) snd_dma_free_pages(&stream->pgtbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) kfree(stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) snd_soc_dai_set_dma_data(dai, substream, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) static int catpt_dai_hw_params(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) struct snd_pcm_hw_params *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) struct snd_soc_dai *dai)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) struct catpt_dev *cdev = dev_get_drvdata(dai->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) struct catpt_stream_runtime *stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) struct catpt_audio_format afmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) struct catpt_ring_info rinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) struct snd_pcm_runtime *rtm = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) struct snd_dma_buffer *dmab;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) stream = snd_soc_dai_get_dma_data(dai, substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) if (stream->allocated)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) memset(&afmt, 0, sizeof(afmt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) afmt.sample_rate = params_rate(params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) afmt.bit_depth = params_physical_width(params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) afmt.valid_bit_depth = params_width(params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) afmt.num_channels = params_channels(params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) afmt.channel_config = catpt_get_channel_config(afmt.num_channels);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) afmt.channel_map = catpt_get_channel_map(afmt.channel_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) afmt.interleaving = CATPT_INTERLEAVING_PER_CHANNEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) dmab = snd_pcm_get_dma_buf(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) catpt_arrange_page_table(substream, &stream->pgtbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) memset(&rinfo, 0, sizeof(rinfo));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) rinfo.page_table_addr = stream->pgtbl.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) rinfo.num_pages = DIV_ROUND_UP(rtm->dma_bytes, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) rinfo.size = rtm->dma_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) rinfo.offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) rinfo.ring_first_page_pfn = PFN_DOWN(snd_sgbuf_get_addr(dmab, 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) ret = catpt_ipc_alloc_stream(cdev, stream->template->path_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) stream->template->type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) &afmt, &rinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) stream->template->num_entries,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) stream->template->entries,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) stream->persistent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) cdev->scratch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) &stream->info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) return CATPT_IPC_ERROR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) stream->allocated = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) static int catpt_dai_hw_free(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) struct snd_soc_dai *dai)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) struct catpt_dev *cdev = dev_get_drvdata(dai->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) struct catpt_stream_runtime *stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) stream = snd_soc_dai_get_dma_data(dai, substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) if (!stream->allocated)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) catpt_ipc_reset_stream(cdev, stream->info.stream_hw_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) catpt_ipc_free_stream(cdev, stream->info.stream_hw_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) stream->allocated = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) static int catpt_set_dspvol(struct catpt_dev *cdev, u8 stream_id, long *ctlvol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) static int catpt_dai_apply_usettings(struct snd_soc_dai *dai,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) struct catpt_stream_runtime *stream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) struct catpt_dev *cdev = dev_get_drvdata(dai->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) struct snd_soc_component *component = dai->component;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) struct snd_kcontrol *pos, *kctl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) u32 id = stream->info.stream_hw_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) /* only selected streams have individual controls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) switch (id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) case CATPT_PIN_ID_OFFLOAD1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) name = "Media0 Playback Volume";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) case CATPT_PIN_ID_OFFLOAD2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) name = "Media1 Playback Volume";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) case CATPT_PIN_ID_CAPTURE1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) name = "Mic Capture Volume";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) case CATPT_PIN_ID_REFERENCE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) name = "Loopback Mute";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) list_for_each_entry(pos, &component->card->snd_card->controls, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) if (pos->private_data == component &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) !strncmp(name, pos->id.name, sizeof(pos->id.name))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) kctl = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) if (!kctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) if (stream->template->type != CATPT_STRM_TYPE_LOOPBACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) return catpt_set_dspvol(cdev, id, (long *)kctl->private_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) ret = catpt_ipc_mute_loopback(cdev, id, *(bool *)kctl->private_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) return CATPT_IPC_ERROR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) static int catpt_dai_prepare(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) struct snd_soc_dai *dai)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) struct catpt_dev *cdev = dev_get_drvdata(dai->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) struct catpt_stream_runtime *stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) stream = snd_soc_dai_get_dma_data(dai, substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) if (stream->prepared)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) ret = catpt_ipc_reset_stream(cdev, stream->info.stream_hw_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) return CATPT_IPC_ERROR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) ret = catpt_ipc_pause_stream(cdev, stream->info.stream_hw_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) return CATPT_IPC_ERROR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) ret = catpt_dai_apply_usettings(dai, stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) stream->prepared = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) static int catpt_dai_trigger(struct snd_pcm_substream *substream, int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) struct snd_soc_dai *dai)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) struct catpt_dev *cdev = dev_get_drvdata(dai->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) struct catpt_stream_runtime *stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) snd_pcm_uframes_t pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) stream = snd_soc_dai_get_dma_data(dai, substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) case SNDRV_PCM_TRIGGER_START:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) /* only offload is set_write_pos driven */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) if (stream->template->type != CATPT_STRM_TYPE_RENDER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) goto resume_stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) pos = frames_to_bytes(runtime, runtime->start_threshold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) * Dsp operates on buffer halves, thus max 2x set_write_pos
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) * (entire buffer filled) prior to stream start.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) ret = catpt_ipc_set_write_pos(cdev, stream->info.stream_hw_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) pos, false, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) return CATPT_IPC_ERROR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) case SNDRV_PCM_TRIGGER_RESUME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) resume_stream:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) catpt_dsp_update_lpclock(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) ret = catpt_ipc_resume_stream(cdev, stream->info.stream_hw_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) return CATPT_IPC_ERROR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) case SNDRV_PCM_TRIGGER_STOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) stream->prepared = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) case SNDRV_PCM_TRIGGER_SUSPEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) ret = catpt_ipc_pause_stream(cdev, stream->info.stream_hw_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) catpt_dsp_update_lpclock(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) return CATPT_IPC_ERROR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) void catpt_stream_update_position(struct catpt_dev *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) struct catpt_stream_runtime *stream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) struct catpt_notify_position *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) struct snd_pcm_substream *substream = stream->substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) struct snd_pcm_runtime *r = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) snd_pcm_uframes_t dsppos, newpos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) dsppos = bytes_to_frames(r, pos->stream_position);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) if (!stream->prepared)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) /* only offload is set_write_pos driven */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) if (stream->template->type != CATPT_STRM_TYPE_RENDER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) if (dsppos >= r->buffer_size / 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) newpos = r->buffer_size / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) newpos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) * Dsp operates on buffer halves, thus on every notify position
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) * (buffer half consumed) update wp to allow stream progression.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) ret = catpt_ipc_set_write_pos(cdev, stream->info.stream_hw_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) frames_to_bytes(r, newpos),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) false, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) dev_err(cdev->dev, "update position for stream %d failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) stream->info.stream_hw_id, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) snd_pcm_period_elapsed(substream);
^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) /* 200 ms for 2 32-bit channels at 48kHz (native format) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) #define CATPT_BUFFER_MAX_SIZE 76800
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) #define CATPT_PCM_PERIODS_MAX 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) #define CATPT_PCM_PERIODS_MIN 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) static const struct snd_pcm_hardware catpt_pcm_hardware = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) .info = SNDRV_PCM_INFO_MMAP |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) SNDRV_PCM_INFO_MMAP_VALID |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) SNDRV_PCM_INFO_INTERLEAVED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) SNDRV_PCM_INFO_PAUSE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) SNDRV_PCM_INFO_RESUME |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) SNDRV_PCM_INFO_NO_PERIOD_WAKEUP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) .formats = SNDRV_PCM_FMTBIT_S16_LE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) SNDRV_PCM_FMTBIT_S24_LE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) SNDRV_PCM_FMTBIT_S32_LE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) .period_bytes_min = PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) .period_bytes_max = CATPT_BUFFER_MAX_SIZE / CATPT_PCM_PERIODS_MIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) .periods_min = CATPT_PCM_PERIODS_MIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) .periods_max = CATPT_PCM_PERIODS_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) .buffer_bytes_max = CATPT_BUFFER_MAX_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) static int catpt_component_pcm_construct(struct snd_soc_component *component,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) struct snd_soc_pcm_runtime *rtm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) struct catpt_dev *cdev = dev_get_drvdata(component->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) snd_pcm_set_managed_buffer_all(rtm->pcm, SNDRV_DMA_TYPE_DEV_SG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) cdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) catpt_pcm_hardware.buffer_bytes_max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) catpt_pcm_hardware.buffer_bytes_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) static int catpt_component_open(struct snd_soc_component *component,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) struct snd_soc_pcm_runtime *rtm = substream->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) if (rtm->dai_link->no_pcm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) snd_soc_set_runtime_hwparams(substream, &catpt_pcm_hardware);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) static snd_pcm_uframes_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) catpt_component_pointer(struct snd_soc_component *component,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) struct catpt_dev *cdev = dev_get_drvdata(component->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) struct catpt_stream_runtime *stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) struct snd_soc_pcm_runtime *rtm = substream->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtm, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) u32 pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) if (rtm->dai_link->no_pcm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) stream = snd_soc_dai_get_dma_data(cpu_dai, substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) pos = catpt_stream_read_position(cdev, stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) return bytes_to_frames(substream->runtime, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) static const struct snd_soc_dai_ops catpt_fe_dai_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) .startup = catpt_dai_startup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) .shutdown = catpt_dai_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) .hw_params = catpt_dai_hw_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) .hw_free = catpt_dai_hw_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) .prepare = catpt_dai_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) .trigger = catpt_dai_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) static int catpt_dai_pcm_new(struct snd_soc_pcm_runtime *rtm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) struct snd_soc_dai *dai)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtm, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) struct catpt_dev *cdev = dev_get_drvdata(dai->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) struct catpt_ssp_device_format devfmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) devfmt.iface = dai->driver->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) devfmt.channels = codec_dai->driver->capture.channels_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) switch (devfmt.iface) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) case CATPT_SSP_IFACE_0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) devfmt.mclk = CATPT_MCLK_FREQ_24_MHZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) switch (devfmt.channels) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) devfmt.mode = CATPT_SSP_MODE_TDM_PROVIDER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) devfmt.clock_divider = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) devfmt.mode = CATPT_SSP_MODE_I2S_PROVIDER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) devfmt.clock_divider = 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) case CATPT_SSP_IFACE_1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) devfmt.mclk = CATPT_MCLK_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) devfmt.mode = CATPT_SSP_MODE_I2S_CONSUMER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) devfmt.clock_divider = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) /* see if this is a new configuration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) if (!memcmp(&cdev->devfmt[devfmt.iface], &devfmt, sizeof(devfmt)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) pm_runtime_get_sync(cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) ret = catpt_ipc_set_device_format(cdev, &devfmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) pm_runtime_mark_last_busy(cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) pm_runtime_put_autosuspend(cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) return CATPT_IPC_ERROR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) /* store device format set for given SSP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) memcpy(&cdev->devfmt[devfmt.iface], &devfmt, sizeof(devfmt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) static struct snd_soc_dai_driver dai_drivers[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) /* FE DAIs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) .name = "System Pin",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) .id = CATPT_STRM_TYPE_SYSTEM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) .ops = &catpt_fe_dai_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) .playback = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) .stream_name = "System Playback",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) .channels_min = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) .channels_max = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) .rates = SNDRV_PCM_RATE_48000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) .capture = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) .stream_name = "Analog Capture",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) .channels_min = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) .channels_max = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) .rates = SNDRV_PCM_RATE_48000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) },
^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) .name = "Offload0 Pin",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) .id = CATPT_STRM_TYPE_RENDER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) .ops = &catpt_fe_dai_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) .playback = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) .stream_name = "Offload0 Playback",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) .channels_min = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) .channels_max = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) .rates = SNDRV_PCM_RATE_8000_192000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) },
^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) .name = "Offload1 Pin",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) .id = CATPT_STRM_TYPE_RENDER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) .ops = &catpt_fe_dai_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) .playback = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) .stream_name = "Offload1 Playback",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) .channels_min = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) .channels_max = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) .rates = SNDRV_PCM_RATE_8000_192000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) .name = "Loopback Pin",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) .id = CATPT_STRM_TYPE_LOOPBACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) .ops = &catpt_fe_dai_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) .capture = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) .stream_name = "Loopback Capture",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) .channels_min = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) .channels_max = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) .rates = SNDRV_PCM_RATE_48000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) .name = "Bluetooth Pin",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) .id = CATPT_STRM_TYPE_BLUETOOTH_RENDER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) .ops = &catpt_fe_dai_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) .playback = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) .stream_name = "Bluetooth Playback",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) .channels_min = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) .channels_max = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) .rates = SNDRV_PCM_RATE_8000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) .formats = SNDRV_PCM_FMTBIT_S16_LE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) .capture = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) .stream_name = "Bluetooth Capture",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) .channels_min = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) .channels_max = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) .rates = SNDRV_PCM_RATE_8000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) .formats = SNDRV_PCM_FMTBIT_S16_LE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) /* BE DAIs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) .name = "ssp0-port",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) .id = CATPT_SSP_IFACE_0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) .pcm_new = catpt_dai_pcm_new,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) .playback = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) .channels_min = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) .channels_max = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) .capture = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) .channels_min = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) .channels_max = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) .name = "ssp1-port",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) .id = CATPT_SSP_IFACE_1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) .pcm_new = catpt_dai_pcm_new,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) .playback = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) .channels_min = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) .channels_max = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) .capture = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) .channels_min = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) .channels_max = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) #define DSP_VOLUME_MAX S32_MAX /* 0db */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) #define DSP_VOLUME_STEP_MAX 30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) static u32 ctlvol_to_dspvol(u32 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) if (value > DSP_VOLUME_STEP_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) value = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) return DSP_VOLUME_MAX >> (DSP_VOLUME_STEP_MAX - value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) static u32 dspvol_to_ctlvol(u32 volume)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) if (volume > DSP_VOLUME_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) return DSP_VOLUME_STEP_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) return volume ? __fls(volume) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) static int catpt_set_dspvol(struct catpt_dev *cdev, u8 stream_id, long *ctlvol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) u32 dspvol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) for (i = 1; i < CATPT_CHANNELS_MAX; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) if (ctlvol[i] != ctlvol[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) if (i == CATPT_CHANNELS_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) dspvol = ctlvol_to_dspvol(ctlvol[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) ret = catpt_ipc_set_volume(cdev, stream_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) CATPT_ALL_CHANNELS_MASK, dspvol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) 0, CATPT_AUDIO_CURVE_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) for (i = 0; i < CATPT_CHANNELS_MAX; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) dspvol = ctlvol_to_dspvol(ctlvol[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) ret = catpt_ipc_set_volume(cdev, stream_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) i, dspvol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) 0, CATPT_AUDIO_CURVE_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) return CATPT_IPC_ERROR(ret);
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) static int catpt_volume_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) uinfo->count = CATPT_CHANNELS_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) uinfo->value.integer.min = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) uinfo->value.integer.max = DSP_VOLUME_STEP_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) static int catpt_mixer_volume_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) struct snd_soc_component *component =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) snd_soc_kcontrol_component(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) struct catpt_dev *cdev = dev_get_drvdata(component->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) u32 dspvol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) pm_runtime_get_sync(cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) for (i = 0; i < CATPT_CHANNELS_MAX; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) dspvol = catpt_mixer_volume(cdev, &cdev->mixer, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) ucontrol->value.integer.value[i] = dspvol_to_ctlvol(dspvol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) pm_runtime_mark_last_busy(cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) pm_runtime_put_autosuspend(cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) static int catpt_mixer_volume_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) struct snd_soc_component *component =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) snd_soc_kcontrol_component(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) struct catpt_dev *cdev = dev_get_drvdata(component->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) pm_runtime_get_sync(cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) ret = catpt_set_dspvol(cdev, cdev->mixer.mixer_hw_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) ucontrol->value.integer.value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) pm_runtime_mark_last_busy(cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) pm_runtime_put_autosuspend(cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) return ret;
^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 catpt_stream_volume_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) struct snd_ctl_elem_value *ucontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) enum catpt_pin_id pin_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) struct snd_soc_component *component =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) snd_soc_kcontrol_component(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) struct catpt_dev *cdev = dev_get_drvdata(component->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) struct catpt_stream_runtime *stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) long *ctlvol = (long *)kcontrol->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) u32 dspvol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) stream = catpt_stream_find(cdev, pin_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) if (!stream) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) for (i = 0; i < CATPT_CHANNELS_MAX; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) ucontrol->value.integer.value[i] = ctlvol[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) pm_runtime_get_sync(cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) for (i = 0; i < CATPT_CHANNELS_MAX; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) dspvol = catpt_stream_volume(cdev, stream, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) ucontrol->value.integer.value[i] = dspvol_to_ctlvol(dspvol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) pm_runtime_mark_last_busy(cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) pm_runtime_put_autosuspend(cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) static int catpt_stream_volume_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) struct snd_ctl_elem_value *ucontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) enum catpt_pin_id pin_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) struct snd_soc_component *component =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) snd_soc_kcontrol_component(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) struct catpt_dev *cdev = dev_get_drvdata(component->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) struct catpt_stream_runtime *stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) long *ctlvol = (long *)kcontrol->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) stream = catpt_stream_find(cdev, pin_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) if (!stream) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) for (i = 0; i < CATPT_CHANNELS_MAX; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) ctlvol[i] = ucontrol->value.integer.value[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) pm_runtime_get_sync(cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) ret = catpt_set_dspvol(cdev, stream->info.stream_hw_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) ucontrol->value.integer.value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) pm_runtime_mark_last_busy(cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) pm_runtime_put_autosuspend(cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) for (i = 0; i < CATPT_CHANNELS_MAX; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) ctlvol[i] = ucontrol->value.integer.value[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) static int catpt_offload1_volume_get(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) struct snd_ctl_elem_value *uctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) return catpt_stream_volume_get(kctl, uctl, CATPT_PIN_ID_OFFLOAD1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) static int catpt_offload1_volume_put(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) struct snd_ctl_elem_value *uctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) return catpt_stream_volume_put(kctl, uctl, CATPT_PIN_ID_OFFLOAD1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) static int catpt_offload2_volume_get(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) struct snd_ctl_elem_value *uctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) return catpt_stream_volume_get(kctl, uctl, CATPT_PIN_ID_OFFLOAD2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) static int catpt_offload2_volume_put(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) struct snd_ctl_elem_value *uctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) return catpt_stream_volume_put(kctl, uctl, CATPT_PIN_ID_OFFLOAD2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) static int catpt_capture_volume_get(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) struct snd_ctl_elem_value *uctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) return catpt_stream_volume_get(kctl, uctl, CATPT_PIN_ID_CAPTURE1);
^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 catpt_capture_volume_put(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) struct snd_ctl_elem_value *uctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) return catpt_stream_volume_put(kctl, uctl, CATPT_PIN_ID_CAPTURE1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) static int catpt_loopback_switch_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) ucontrol->value.integer.value[0] = *(bool *)kcontrol->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) static int catpt_loopback_switch_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) struct snd_soc_component *component =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) snd_soc_kcontrol_component(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) struct catpt_dev *cdev = dev_get_drvdata(component->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) struct catpt_stream_runtime *stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) bool mute;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) mute = (bool)ucontrol->value.integer.value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) stream = catpt_stream_find(cdev, CATPT_PIN_ID_REFERENCE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) if (!stream) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) *(bool *)kcontrol->private_value = mute;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) pm_runtime_get_sync(cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) ret = catpt_ipc_mute_loopback(cdev, stream->info.stream_hw_id, mute);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) pm_runtime_mark_last_busy(cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) pm_runtime_put_autosuspend(cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) return CATPT_IPC_ERROR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) *(bool *)kcontrol->private_value = mute;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) static int catpt_waves_switch_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) static int catpt_waves_switch_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) static int catpt_waves_param_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) unsigned int __user *bytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) unsigned int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) static int catpt_waves_param_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) const unsigned int __user *bytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) unsigned int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(catpt_volume_tlv, -9000, 300, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) #define CATPT_VOLUME_CTL(kname, sname) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) .name = (kname), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) SNDRV_CTL_ELEM_ACCESS_READWRITE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) .info = catpt_volume_info, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) .get = catpt_##sname##_volume_get, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) .put = catpt_##sname##_volume_put, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) .tlv.p = catpt_volume_tlv, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) .private_value = (unsigned long) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) &(long[CATPT_CHANNELS_MAX]) {0} }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) static const struct snd_kcontrol_new component_kcontrols[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) /* Master volume (mixer stream) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) CATPT_VOLUME_CTL("Master Playback Volume", mixer),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) /* Individual volume controls for offload and capture */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) CATPT_VOLUME_CTL("Media0 Playback Volume", offload1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) CATPT_VOLUME_CTL("Media1 Playback Volume", offload2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) CATPT_VOLUME_CTL("Mic Capture Volume", capture),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) SOC_SINGLE_BOOL_EXT("Loopback Mute", (unsigned long)&(bool[1]) {0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) catpt_loopback_switch_get, catpt_loopback_switch_put),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) /* Enable or disable WAVES module */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) SOC_SINGLE_BOOL_EXT("Waves Switch", 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) catpt_waves_switch_get, catpt_waves_switch_put),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) /* WAVES module parameter control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) SND_SOC_BYTES_TLV("Waves Set Param", 128,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) catpt_waves_param_get, catpt_waves_param_put),
^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 const struct snd_soc_dapm_widget component_widgets[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) SND_SOC_DAPM_AIF_IN("SSP0 CODEC IN", NULL, 0, SND_SOC_NOPM, 0, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) SND_SOC_DAPM_AIF_OUT("SSP0 CODEC OUT", NULL, 0, SND_SOC_NOPM, 0, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) SND_SOC_DAPM_AIF_IN("SSP1 BT IN", NULL, 0, SND_SOC_NOPM, 0, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) SND_SOC_DAPM_AIF_OUT("SSP1 BT OUT", NULL, 0, SND_SOC_NOPM, 0, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) SND_SOC_DAPM_MIXER("Playback VMixer", SND_SOC_NOPM, 0, 0, NULL, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) static const struct snd_soc_dapm_route component_routes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) {"Playback VMixer", NULL, "System Playback"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) {"Playback VMixer", NULL, "Offload0 Playback"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) {"Playback VMixer", NULL, "Offload1 Playback"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) {"SSP0 CODEC OUT", NULL, "Playback VMixer"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) {"Analog Capture", NULL, "SSP0 CODEC IN"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) {"Loopback Capture", NULL, "SSP0 CODEC IN"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) {"SSP1 BT OUT", NULL, "Bluetooth Playback"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) {"Bluetooth Capture", NULL, "SSP1 BT IN"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) static const struct snd_soc_component_driver catpt_comp_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) .name = "catpt-platform",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) .pcm_construct = catpt_component_pcm_construct,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) .open = catpt_component_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) .pointer = catpt_component_pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) .controls = component_kcontrols,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) .num_controls = ARRAY_SIZE(component_kcontrols),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) .dapm_widgets = component_widgets,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) .num_dapm_widgets = ARRAY_SIZE(component_widgets),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) .dapm_routes = component_routes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) .num_dapm_routes = ARRAY_SIZE(component_routes),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) int catpt_arm_stream_templates(struct catpt_dev *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) struct resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) u32 scratch_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) for (i = 0; i < ARRAY_SIZE(catpt_topology); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) struct catpt_stream_template *template;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) struct catpt_module_entry *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) struct catpt_module_type *type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) template = catpt_topology[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) template->persistent_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) for (j = 0; j < template->num_entries; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) entry = &template->entries[j];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) type = &cdev->modules[entry->module_id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) if (!type->loaded)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) entry->entry_point = type->entry_point;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) template->persistent_size += type->persistent_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) if (type->scratch_size > scratch_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) scratch_size = type->scratch_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) if (scratch_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) /* allocate single scratch area for all modules */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) res = catpt_request_region(&cdev->dram, scratch_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) if (!res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) cdev->scratch = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) int catpt_register_plat_component(struct catpt_dev *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) struct snd_soc_component *component;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) component = devm_kzalloc(cdev->dev, sizeof(*component), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) if (!component)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) ret = snd_soc_component_initialize(component, &catpt_comp_driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) component->name = catpt_comp_driver.name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) return snd_soc_add_component(component, dai_drivers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) ARRAY_SIZE(dai_drivers));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) }