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_component *component = asoc_rtd_to_codec(rtd, 0)->component;
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_component_update_bits(component, 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 = asoc_rtd_to_codec(rtd, 0);
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 SND_SOC_DAILINK_DEFS(fe_pi,
71 DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
72 DAILINK_COMP_ARRAY(COMP_CODEC("sgtl5000.1-000a", "sgtl5000")),
73 DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
75 static struct snd_soc_dai_link snd_fe_pi_audio_dai[] = {
78 .stream_name = "Fe-Pi HiFi",
79 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
80 SND_SOC_DAIFMT_CBM_CFM,
81 .ops = &snd_fe_pi_audio_ops,
82 .init = snd_fe_pi_audio_init,
83 SND_SOC_DAILINK_REG(fe_pi),
87 static const struct snd_soc_dapm_route fe_pi_audio_dapm_routes[] = {
88 {"ADC", NULL, "Mic Bias"},
92 static struct snd_soc_card fe_pi_audio = {
93 .name = "Fe-Pi Audio",
95 .dai_link = snd_fe_pi_audio_dai,
96 .num_links = ARRAY_SIZE(snd_fe_pi_audio_dai),
98 .dapm_routes = fe_pi_audio_dapm_routes,
99 .num_dapm_routes = ARRAY_SIZE(fe_pi_audio_dapm_routes),
102 static int snd_fe_pi_audio_probe(struct platform_device *pdev)
105 struct snd_soc_card *card = &fe_pi_audio;
106 struct device_node *np = pdev->dev.of_node;
107 struct device_node *i2s_node;
108 struct snd_soc_dai_link *dai = &snd_fe_pi_audio_dai[0];
110 fe_pi_audio.dev = &pdev->dev;
112 i2s_node = of_parse_phandle(np, "i2s-controller", 0);
114 dev_err(&pdev->dev, "i2s_node phandle missing or invalid\n");
118 dai->cpus->dai_name = NULL;
119 dai->cpus->of_node = i2s_node;
120 dai->platforms->name = NULL;
121 dai->platforms->of_node = i2s_node;
123 of_node_put(i2s_node);
125 card->dev = &pdev->dev;
126 platform_set_drvdata(pdev, card);
128 ret = devm_snd_soc_register_card(&pdev->dev, card);
129 if (ret && ret != -EPROBE_DEFER)
130 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
135 static const struct of_device_id snd_fe_pi_audio_of_match[] = {
136 { .compatible = "fe-pi,fe-pi-audio", },
139 MODULE_DEVICE_TABLE(of, snd_fe_pi_audio_of_match);
141 static struct platform_driver snd_fe_pi_audio_driver = {
143 .name = "snd-fe-pi-audio",
144 .owner = THIS_MODULE,
145 .of_match_table = snd_fe_pi_audio_of_match,
147 .probe = snd_fe_pi_audio_probe,
150 module_platform_driver(snd_fe_pi_audio_driver);
152 MODULE_AUTHOR("Henry Kupis <fe-pi@cox.net>");
153 MODULE_DESCRIPTION("ASoC Driver for Fe-Pi Audio");
154 MODULE_LICENSE("GPL v2");