1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * SiRF audio card driver
5 * Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company.
8 #include <linux/platform_device.h>
9 #include <linux/module.h>
11 #include <linux/gpio.h>
12 #include <linux/of_gpio.h>
13 #include <sound/core.h>
14 #include <sound/pcm.h>
15 #include <sound/soc.h>
17 struct sirf_audio_card
{
18 unsigned int gpio_hp_pa
;
19 unsigned int gpio_spk_pa
;
22 static int sirf_audio_hp_event(struct snd_soc_dapm_widget
*w
,
23 struct snd_kcontrol
*ctrl
, int event
)
25 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
26 struct snd_soc_card
*card
= dapm
->card
;
27 struct sirf_audio_card
*sirf_audio_card
= snd_soc_card_get_drvdata(card
);
28 int on
= !SND_SOC_DAPM_EVENT_OFF(event
);
30 if (gpio_is_valid(sirf_audio_card
->gpio_hp_pa
))
31 gpio_set_value(sirf_audio_card
->gpio_hp_pa
, on
);
35 static int sirf_audio_spk_event(struct snd_soc_dapm_widget
*w
,
36 struct snd_kcontrol
*ctrl
, int event
)
38 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
39 struct snd_soc_card
*card
= dapm
->card
;
40 struct sirf_audio_card
*sirf_audio_card
= snd_soc_card_get_drvdata(card
);
41 int on
= !SND_SOC_DAPM_EVENT_OFF(event
);
43 if (gpio_is_valid(sirf_audio_card
->gpio_spk_pa
))
44 gpio_set_value(sirf_audio_card
->gpio_spk_pa
, on
);
48 static const struct snd_soc_dapm_widget sirf_audio_dapm_widgets
[] = {
49 SND_SOC_DAPM_HP("Hp", sirf_audio_hp_event
),
50 SND_SOC_DAPM_SPK("Ext Spk", sirf_audio_spk_event
),
51 SND_SOC_DAPM_MIC("Ext Mic", NULL
),
54 static const struct snd_soc_dapm_route intercon
[] = {
55 {"Hp", NULL
, "HPOUTL"},
56 {"Hp", NULL
, "HPOUTR"},
57 {"Ext Spk", NULL
, "SPKOUT"},
58 {"MICIN1", NULL
, "Mic Bias"},
59 {"Mic Bias", NULL
, "Ext Mic"},
62 /* Digital audio interface glue - connects codec <--> CPU */
63 SND_SOC_DAILINK_DEFS(sirf
,
64 DAILINK_COMP_ARRAY(COMP_EMPTY()),
65 DAILINK_COMP_ARRAY(COMP_CODEC(NULL
, "sirf-audio-codec")),
66 DAILINK_COMP_ARRAY(COMP_EMPTY()));
68 static struct snd_soc_dai_link sirf_audio_dai_link
[] = {
70 .name
= "SiRF audio card",
71 .stream_name
= "SiRF audio HiFi",
72 SND_SOC_DAILINK_REG(sirf
),
76 /* Audio machine driver */
77 static struct snd_soc_card snd_soc_sirf_audio_card
= {
78 .name
= "SiRF audio card",
80 .dai_link
= sirf_audio_dai_link
,
81 .num_links
= ARRAY_SIZE(sirf_audio_dai_link
),
82 .dapm_widgets
= sirf_audio_dapm_widgets
,
83 .num_dapm_widgets
= ARRAY_SIZE(sirf_audio_dapm_widgets
),
84 .dapm_routes
= intercon
,
85 .num_dapm_routes
= ARRAY_SIZE(intercon
),
88 static int sirf_audio_probe(struct platform_device
*pdev
)
90 struct snd_soc_card
*card
= &snd_soc_sirf_audio_card
;
91 struct sirf_audio_card
*sirf_audio_card
;
94 sirf_audio_card
= devm_kzalloc(&pdev
->dev
, sizeof(struct sirf_audio_card
),
96 if (sirf_audio_card
== NULL
)
99 sirf_audio_dai_link
[0].cpus
->of_node
=
100 of_parse_phandle(pdev
->dev
.of_node
, "sirf,audio-platform", 0);
101 sirf_audio_dai_link
[0].platforms
->of_node
=
102 of_parse_phandle(pdev
->dev
.of_node
, "sirf,audio-platform", 0);
103 sirf_audio_dai_link
[0].codecs
->of_node
=
104 of_parse_phandle(pdev
->dev
.of_node
, "sirf,audio-codec", 0);
105 sirf_audio_card
->gpio_spk_pa
= of_get_named_gpio(pdev
->dev
.of_node
,
107 sirf_audio_card
->gpio_hp_pa
= of_get_named_gpio(pdev
->dev
.of_node
,
109 if (gpio_is_valid(sirf_audio_card
->gpio_spk_pa
)) {
110 ret
= devm_gpio_request_one(&pdev
->dev
,
111 sirf_audio_card
->gpio_spk_pa
,
112 GPIOF_OUT_INIT_LOW
, "SPA_PA_SD");
115 "Failed to request GPIO_%d for reset: %d\n",
116 sirf_audio_card
->gpio_spk_pa
, ret
);
120 if (gpio_is_valid(sirf_audio_card
->gpio_hp_pa
)) {
121 ret
= devm_gpio_request_one(&pdev
->dev
,
122 sirf_audio_card
->gpio_hp_pa
,
123 GPIOF_OUT_INIT_LOW
, "HP_PA_SD");
126 "Failed to request GPIO_%d for reset: %d\n",
127 sirf_audio_card
->gpio_hp_pa
, ret
);
132 card
->dev
= &pdev
->dev
;
133 snd_soc_card_set_drvdata(card
, sirf_audio_card
);
135 ret
= devm_snd_soc_register_card(&pdev
->dev
, card
);
137 dev_err(&pdev
->dev
, "snd_soc_register_card() failed:%d\n", ret
);
142 static const struct of_device_id sirf_audio_of_match
[] = {
143 {.compatible
= "sirf,sirf-audio-card", },
146 MODULE_DEVICE_TABLE(of
, sirf_audio_of_match
);
148 static struct platform_driver sirf_audio_driver
= {
150 .name
= "sirf-audio-card",
151 .pm
= &snd_soc_pm_ops
,
152 .of_match_table
= sirf_audio_of_match
,
154 .probe
= sirf_audio_probe
,
156 module_platform_driver(sirf_audio_driver
);
158 MODULE_AUTHOR("RongJun Ying <RongJun.Ying@csr.com>");
159 MODULE_DESCRIPTION("ALSA SoC SIRF audio card driver");
160 MODULE_LICENSE("GPL v2");