FILE
soc_sdw_rt_mf_sdca.c
File preview with syntax highlighting.
linux-6.19.14/sound/soc/sdw_utils/soc_sdw_rt_mf_sdca.c
1// SPDX-License-Identifier: GPL-2.0-only 2// This file incorporates work covered by the following copyright notice: 3// Copyright (c) 2024 Intel Corporation. 4 5/* 6 * soc_sdw_rt_mf_sdca 7 * - Helpers to handle RT Multifunction Codec from generic machine driver 8 */ 9 10#include <linux/device.h> 11#include <linux/errno.h> 12#include <linux/soundwire/sdw.h> 13#include <linux/soundwire/sdw_type.h> 14#include <sound/control.h> 15#include <sound/soc.h> 16#include <sound/soc-acpi.h> 17#include <sound/soc-dapm.h> 18#include <sound/soc_sdw_utils.h> 19 20#define CODEC_NAME_SIZE 6 21 22/* dapm routes for RT-SPK will be registered dynamically */ 23static const struct snd_soc_dapm_route rt712_spk_map[] = { 24 { "Speaker", NULL, "rt712 SPOL" }, 25 { "Speaker", NULL, "rt712 SPOR" }, 26}; 27 28static const struct snd_soc_dapm_route rt721_spk_map[] = { 29 { "Speaker", NULL, "rt721 SPK" }, 30}; 31 32static const struct snd_soc_dapm_route rt722_spk_map[] = { 33 { "Speaker", NULL, "rt722 SPK" }, 34}; 35 36/* Structure to map codec names to respective route arrays and sizes */ 37struct codec_route_map { 38 const char *codec_name; 39 const struct snd_soc_dapm_route *route_map; 40 size_t route_size; 41}; 42 43/* Codec route maps array */ 44static const struct codec_route_map codec_routes[] = { 45 { "rt712", rt712_spk_map, ARRAY_SIZE(rt712_spk_map) }, 46 { "rt721", rt721_spk_map, ARRAY_SIZE(rt721_spk_map) }, 47 { "rt722", rt722_spk_map, ARRAY_SIZE(rt722_spk_map) }, 48}; 49 50static const struct codec_route_map *get_codec_route_map(const char *codec_name) 51{ 52 for (size_t i = 0; i < ARRAY_SIZE(codec_routes); i++) { 53 if (strcmp(codec_routes[i].codec_name, codec_name) == 0) 54 return &codec_routes[i]; 55 } 56 return NULL; 57} 58 59int asoc_sdw_rt_mf_sdca_spk_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai) 60{ 61 struct snd_soc_card *card = rtd->card; 62 struct snd_soc_dapm_context *dapm = snd_soc_card_to_dapm(card); 63 char codec_name[CODEC_NAME_SIZE]; 64 int ret; 65 66 /* acquire codec name */ 67 snprintf(codec_name, CODEC_NAME_SIZE, "%s", dai->name); 68 69 /* acquire corresponding route map and size */ 70 const struct codec_route_map *route_map = get_codec_route_map(codec_name); 71 72 if (!route_map) { 73 dev_err(rtd->dev, "failed to get codec name and route map\n"); 74 return -EINVAL; 75 } 76 77 /* Add routes */ 78 ret = snd_soc_dapm_add_routes(dapm, route_map->route_map, route_map->route_size); 79 if (ret) 80 dev_err(rtd->dev, "failed to add rt sdca spk map: %d\n", ret); 81 82 return ret; 83} 84EXPORT_SYMBOL_NS(asoc_sdw_rt_mf_sdca_spk_rtd_init, "SND_SOC_SDW_UTILS");
~/
Read-only file preview.