• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * SiRF audio card driver
3  *
4  * Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company.
5  *
6  * Licensed under GPLv2 or later.
7  */
8 
9 #include <linux/platform_device.h>
10 #include <linux/module.h>
11 #include <linux/of.h>
12 #include <linux/gpio.h>
13 #include <linux/of_gpio.h>
14 #include <sound/core.h>
15 #include <sound/pcm.h>
16 #include <sound/soc.h>
17 
18 struct sirf_audio_card {
19 	unsigned int            gpio_hp_pa;
20 	unsigned int            gpio_spk_pa;
21 };
22 
sirf_audio_hp_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * ctrl,int event)23 static int sirf_audio_hp_event(struct snd_soc_dapm_widget *w,
24 				struct snd_kcontrol *ctrl, int event)
25 {
26 	struct snd_soc_dapm_context *dapm = w->dapm;
27 	struct snd_soc_card *card = dapm->card;
28 	struct sirf_audio_card *sirf_audio_card = snd_soc_card_get_drvdata(card);
29 	int on = !SND_SOC_DAPM_EVENT_OFF(event);
30 
31 	if (gpio_is_valid(sirf_audio_card->gpio_hp_pa))
32 		gpio_set_value(sirf_audio_card->gpio_hp_pa, on);
33 	return 0;
34 }
35 
sirf_audio_spk_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * ctrl,int event)36 static int sirf_audio_spk_event(struct snd_soc_dapm_widget *w,
37 				struct snd_kcontrol *ctrl, int event)
38 {
39 	struct snd_soc_dapm_context *dapm = w->dapm;
40 	struct snd_soc_card *card = dapm->card;
41 	struct sirf_audio_card *sirf_audio_card = snd_soc_card_get_drvdata(card);
42 	int on = !SND_SOC_DAPM_EVENT_OFF(event);
43 
44 	if (gpio_is_valid(sirf_audio_card->gpio_spk_pa))
45 		gpio_set_value(sirf_audio_card->gpio_spk_pa, on);
46 
47 	return 0;
48 }
49 static const struct snd_soc_dapm_widget sirf_audio_dapm_widgets[] = {
50 	SND_SOC_DAPM_HP("Hp", sirf_audio_hp_event),
51 	SND_SOC_DAPM_SPK("Ext Spk", sirf_audio_spk_event),
52 	SND_SOC_DAPM_MIC("Ext Mic", NULL),
53 };
54 
55 static const struct snd_soc_dapm_route intercon[] = {
56 	{"Hp", NULL, "HPOUTL"},
57 	{"Hp", NULL, "HPOUTR"},
58 	{"Ext Spk", NULL, "SPKOUT"},
59 	{"MICIN1", NULL, "Mic Bias"},
60 	{"Mic Bias", NULL, "Ext Mic"},
61 };
62 
63 /* Digital audio interface glue - connects codec <--> CPU */
64 static struct snd_soc_dai_link sirf_audio_dai_link[] = {
65 	{
66 		.name = "SiRF audio card",
67 		.stream_name = "SiRF audio HiFi",
68 		.codec_dai_name = "sirf-audio-codec",
69 	},
70 };
71 
72 /* Audio machine driver */
73 static struct snd_soc_card snd_soc_sirf_audio_card = {
74 	.name = "SiRF audio card",
75 	.owner = THIS_MODULE,
76 	.dai_link = sirf_audio_dai_link,
77 	.num_links = ARRAY_SIZE(sirf_audio_dai_link),
78 	.dapm_widgets = sirf_audio_dapm_widgets,
79 	.num_dapm_widgets = ARRAY_SIZE(sirf_audio_dapm_widgets),
80 	.dapm_routes = intercon,
81 	.num_dapm_routes = ARRAY_SIZE(intercon),
82 };
83 
sirf_audio_probe(struct platform_device * pdev)84 static int sirf_audio_probe(struct platform_device *pdev)
85 {
86 	struct snd_soc_card *card = &snd_soc_sirf_audio_card;
87 	struct sirf_audio_card *sirf_audio_card;
88 	int ret;
89 
90 	sirf_audio_card = devm_kzalloc(&pdev->dev, sizeof(struct sirf_audio_card),
91 			GFP_KERNEL);
92 	if (sirf_audio_card == NULL)
93 		return -ENOMEM;
94 
95 	sirf_audio_dai_link[0].cpu_of_node =
96 		of_parse_phandle(pdev->dev.of_node, "sirf,audio-platform", 0);
97 	sirf_audio_dai_link[0].platform_of_node =
98 		of_parse_phandle(pdev->dev.of_node, "sirf,audio-platform", 0);
99 	sirf_audio_dai_link[0].codec_of_node =
100 		of_parse_phandle(pdev->dev.of_node, "sirf,audio-codec", 0);
101 	sirf_audio_card->gpio_spk_pa = of_get_named_gpio(pdev->dev.of_node,
102 			"spk-pa-gpios", 0);
103 	sirf_audio_card->gpio_hp_pa =  of_get_named_gpio(pdev->dev.of_node,
104 			"hp-pa-gpios", 0);
105 	if (gpio_is_valid(sirf_audio_card->gpio_spk_pa)) {
106 		ret = devm_gpio_request_one(&pdev->dev,
107 				sirf_audio_card->gpio_spk_pa,
108 				GPIOF_OUT_INIT_LOW, "SPA_PA_SD");
109 		if (ret) {
110 			dev_err(&pdev->dev,
111 				"Failed to request GPIO_%d for reset: %d\n",
112 				sirf_audio_card->gpio_spk_pa, ret);
113 			return ret;
114 		}
115 	}
116 	if (gpio_is_valid(sirf_audio_card->gpio_hp_pa)) {
117 		ret = devm_gpio_request_one(&pdev->dev,
118 				sirf_audio_card->gpio_hp_pa,
119 				GPIOF_OUT_INIT_LOW, "HP_PA_SD");
120 		if (ret) {
121 			dev_err(&pdev->dev,
122 				"Failed to request GPIO_%d for reset: %d\n",
123 				sirf_audio_card->gpio_hp_pa, ret);
124 			return ret;
125 		}
126 	}
127 
128 	card->dev = &pdev->dev;
129 	snd_soc_card_set_drvdata(card, sirf_audio_card);
130 
131 	ret = devm_snd_soc_register_card(&pdev->dev, card);
132 	if (ret)
133 		dev_err(&pdev->dev, "snd_soc_register_card() failed:%d\n", ret);
134 
135 	return ret;
136 }
137 
138 static const struct of_device_id sirf_audio_of_match[] = {
139 	{.compatible = "sirf,sirf-audio-card", },
140 	{ },
141 };
142 MODULE_DEVICE_TABLE(of, sirf_audio_of_match);
143 
144 static struct platform_driver sirf_audio_driver = {
145 	.driver = {
146 		.name = "sirf-audio-card",
147 		.pm = &snd_soc_pm_ops,
148 		.of_match_table = sirf_audio_of_match,
149 	},
150 	.probe = sirf_audio_probe,
151 };
152 module_platform_driver(sirf_audio_driver);
153 
154 MODULE_AUTHOR("RongJun Ying <RongJun.Ying@csr.com>");
155 MODULE_DESCRIPTION("ALSA SoC SIRF audio card driver");
156 MODULE_LICENSE("GPL v2");
157