2 * ASoC Driver for Fe-Pi Audio Sound Card
4 * Author: Henry Kupis <kuupaz@gmail.com>
6 * based on code by Florian Meier <florian.meier@koalo.de>
7 * based on code by Shawn Guo <shawn.guo@linaro.org>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
19 #include <linux/module.h>
20 #include <linux/platform_device.h>
23 #include <sound/core.h>
24 #include <sound/pcm.h>
25 #include <sound/pcm_params.h>
26 #include <sound/soc.h>
27 #include <sound/jack.h>
29 #include "../codecs/sgtl5000.h"
31 static int snd_fe_pi_audio_init(struct snd_soc_pcm_runtime
*rtd
)
33 struct snd_soc_card
*card
= rtd
->card
;
34 struct snd_soc_codec
*codec
= rtd
->codec
;
36 snd_soc_dapm_force_enable_pin(&card
->dapm
, "LO");
37 snd_soc_dapm_force_enable_pin(&card
->dapm
, "ADC");
38 snd_soc_dapm_force_enable_pin(&card
->dapm
, "DAC");
39 snd_soc_dapm_force_enable_pin(&card
->dapm
, "HP");
40 snd_soc_update_bits(codec
, SGTL5000_CHIP_ANA_POWER
,
41 SGTL5000_VAG_POWERUP
, SGTL5000_VAG_POWERUP
);
46 static int snd_fe_pi_audio_hw_params(struct snd_pcm_substream
*substream
,
47 struct snd_pcm_hw_params
*params
)
49 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
50 struct device
*dev
= rtd
->card
->dev
;
51 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
55 /* Set SGTL5000's SYSCLK */
56 ret
= snd_soc_dai_set_sysclk(codec_dai
, SGTL5000_SYSCLK
, 12288000, SND_SOC_CLOCK_IN
);
58 dev_err(dev
, "could not set codec driver clock params\n");
66 static struct snd_soc_ops snd_fe_pi_audio_ops
= {
67 .hw_params
= snd_fe_pi_audio_hw_params
,
70 static struct snd_soc_dai_link snd_fe_pi_audio_dai
[] = {
73 .stream_name
= "Fe-Pi HiFi",
74 .cpu_dai_name
= "bcm2708-i2s.0",
75 .codec_dai_name
= "sgtl5000",
76 .platform_name
= "bcm2708-i2s.0",
77 .codec_name
= "sgtl5000.1-000a",
78 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
|
79 SND_SOC_DAIFMT_CBM_CFM
,
80 .ops
= &snd_fe_pi_audio_ops
,
81 .init
= snd_fe_pi_audio_init
,
85 static const struct snd_soc_dapm_route fe_pi_audio_dapm_routes
[] = {
86 {"ADC", NULL
, "Mic Bias"},
90 static struct snd_soc_card fe_pi_audio
= {
91 .name
= "Fe-Pi Audio",
93 .dai_link
= snd_fe_pi_audio_dai
,
94 .num_links
= ARRAY_SIZE(snd_fe_pi_audio_dai
),
96 .dapm_routes
= fe_pi_audio_dapm_routes
,
97 .num_dapm_routes
= ARRAY_SIZE(fe_pi_audio_dapm_routes
),
100 static int snd_fe_pi_audio_probe(struct platform_device
*pdev
)
103 struct snd_soc_card
*card
= &fe_pi_audio
;
104 struct device_node
*np
= pdev
->dev
.of_node
;
105 struct device_node
*i2s_node
;
106 struct snd_soc_dai_link
*dai
= &snd_fe_pi_audio_dai
[0];
108 fe_pi_audio
.dev
= &pdev
->dev
;
110 i2s_node
= of_parse_phandle(np
, "i2s-controller", 0);
112 dev_err(&pdev
->dev
, "i2s_node phandle missing or invalid\n");
116 dai
->cpu_dai_name
= NULL
;
117 dai
->cpu_of_node
= i2s_node
;
118 dai
->platform_name
= NULL
;
119 dai
->platform_of_node
= i2s_node
;
121 of_node_put(i2s_node
);
123 card
->dev
= &pdev
->dev
;
124 platform_set_drvdata(pdev
, card
);
126 ret
= snd_soc_register_card(card
);
127 if (ret
&& ret
!= -EPROBE_DEFER
)
128 dev_err(&pdev
->dev
, "snd_soc_register_card() failed: %d\n", ret
);
133 static int snd_fe_pi_audio_remove(struct platform_device
*pdev
)
135 return snd_soc_unregister_card(&fe_pi_audio
);
138 static const struct of_device_id snd_fe_pi_audio_of_match
[] = {
139 { .compatible
= "fe-pi,fe-pi-audio", },
142 MODULE_DEVICE_TABLE(of
, snd_fe_pi_audio_of_match
);
144 static struct platform_driver snd_fe_pi_audio_driver
= {
146 .name
= "snd-fe-pi-audio",
147 .owner
= THIS_MODULE
,
148 .of_match_table
= snd_fe_pi_audio_of_match
,
150 .probe
= snd_fe_pi_audio_probe
,
151 .remove
= snd_fe_pi_audio_remove
,
154 module_platform_driver(snd_fe_pi_audio_driver
);
156 MODULE_AUTHOR("Henry Kupis <fe-pi@cox.net>");
157 MODULE_DESCRIPTION("ASoC Driver for Fe-Pi Audio");
158 MODULE_LICENSE("GPL v2");