| 1 |
// SPDX-License-Identifier: GPL-2.0-only |
| 2 |
// Based on sof_sdw_rt5682.c |
| 3 |
// This file incorporates work covered by the following copyright notice: |
| 4 |
// Copyright (c) 2023 Intel Corporation |
| 5 |
// Copyright (c) 2024 Advanced Micro Devices, Inc. |
| 6 |
|
| 7 |
/* |
| 8 |
* soc_sdw_cs42l45 - Helpers to handle CS42L45 from generic machine driver |
| 9 |
*/ |
| 10 |
#include <linux/device.h> |
| 11 |
#include <linux/errno.h> |
| 12 |
#include <sound/jack.h> |
| 13 |
#include <sound/soc.h> |
| 14 |
#include <sound/soc-card.h> |
| 15 |
#include <sound/soc-component.h> |
| 16 |
#include <sound/soc-dai.h> |
| 17 |
#include <sound/soc_sdw_utils.h> |
| 18 |
|
| 19 |
static struct snd_soc_jack_pin soc_jack_pins[] = { |
| 20 |
{ |
| 21 |
.pin = "cs42l45 OT 43 Headphone", |
| 22 |
.mask = SND_JACK_HEADPHONE, |
| 23 |
}, |
| 24 |
{ |
| 25 |
.pin = "cs42l45 OT 45 Headset", |
| 26 |
.mask = SND_JACK_HEADPHONE, |
| 27 |
}, |
| 28 |
{ |
| 29 |
.pin = "cs42l45 IT 31 Microphone", |
| 30 |
.mask = SND_JACK_MICROPHONE, |
| 31 |
}, |
| 32 |
{ |
| 33 |
.pin = "cs42l45 IT 33 Headset", |
| 34 |
.mask = SND_JACK_MICROPHONE, |
| 35 |
}, |
| 36 |
}; |
| 37 |
|
| 38 |
int asoc_sdw_cs42l45_hs_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai) |
| 39 |
{ |
| 40 |
struct snd_soc_card *card = rtd->card; |
| 41 |
struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component; |
| 42 |
struct asoc_sdw_mc_private *ctx = snd_soc_card_get_drvdata(card); |
| 43 |
struct snd_soc_jack *jack = &ctx->sdw_headset; |
| 44 |
int ret; |
| 45 |
|
| 46 |
card->components = devm_kasprintf(card->dev, GFP_KERNEL, "%s hs:cs42l45", |
| 47 |
card->components); |
| 48 |
if (!card->components) |
| 49 |
return -ENOMEM; |
| 50 |
|
| 51 |
ret = snd_soc_card_jack_new_pins(card, "Jack", SND_JACK_MECHANICAL | |
| 52 |
SND_JACK_HEADSET | SND_JACK_LINEOUT, jack, |
| 53 |
soc_jack_pins, ARRAY_SIZE(soc_jack_pins)); |
| 54 |
if (ret) { |
| 55 |
dev_err(card->dev, "Failed to create jack: %d\n", ret); |
| 56 |
return ret; |
| 57 |
} |
| 58 |
|
| 59 |
ret = snd_soc_component_set_jack(component, jack, NULL); |
| 60 |
if (ret) { |
| 61 |
dev_err(card->dev, "Failed to register jack: %d\n", ret); |
| 62 |
return ret; |
| 63 |
} |
| 64 |
|
| 65 |
return 0; |
| 66 |
} |
| 67 |
EXPORT_SYMBOL_NS(asoc_sdw_cs42l45_hs_rtd_init, "SND_SOC_SDW_UTILS"); |
| 68 |
|
| 69 |
int asoc_sdw_cs42l45_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai) |
| 70 |
{ |
| 71 |
struct snd_soc_card *card = rtd->card; |
| 72 |
|
| 73 |
card->components = devm_kasprintf(card->dev, GFP_KERNEL, "%s mic:cs42l45-dmic", |
| 74 |
card->components); |
| 75 |
if (!card->components) |
| 76 |
return -ENOMEM; |
| 77 |
|
| 78 |
return 0; |
| 79 |
} |
| 80 |
EXPORT_SYMBOL_NS(asoc_sdw_cs42l45_dmic_rtd_init, "SND_SOC_SDW_UTILS"); |