]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - sound/soc/bcm/fe-pi-audio.c
Add support for Fe-Pi audio sound card. (#1867)
[mirror_ubuntu-artful-kernel.git] / sound / soc / bcm / fe-pi-audio.c
1 /*
2 * ASoC Driver for Fe-Pi Audio Sound Card
3 *
4 * Author: Henry Kupis <kuupaz@gmail.com>
5 * Copyright 2016
6 * based on code by Florian Meier <florian.meier@koalo.de>
7 * based on code by Shawn Guo <shawn.guo@linaro.org>
8 *
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.
12 *
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.
17 */
18
19 #include <linux/module.h>
20 #include <linux/platform_device.h>
21 #include <linux/io.h>
22
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>
28
29 #include "../codecs/sgtl5000.h"
30
31 static int snd_fe_pi_audio_init(struct snd_soc_pcm_runtime *rtd)
32 {
33 struct snd_soc_card *card = rtd->card;
34 struct snd_soc_codec *codec = rtd->codec;
35
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);
42
43 return 0;
44 }
45
46 static int snd_fe_pi_audio_hw_params(struct snd_pcm_substream *substream,
47 struct snd_pcm_hw_params *params)
48 {
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;
52
53 int ret;
54
55 /* Set SGTL5000's SYSCLK */
56 ret = snd_soc_dai_set_sysclk(codec_dai, SGTL5000_SYSCLK, 12288000, SND_SOC_CLOCK_IN);
57 if (ret) {
58 dev_err(dev, "could not set codec driver clock params\n");
59 return ret;
60 }
61
62 return 0;
63 }
64
65
66 static struct snd_soc_ops snd_fe_pi_audio_ops = {
67 .hw_params = snd_fe_pi_audio_hw_params,
68 };
69
70 static struct snd_soc_dai_link snd_fe_pi_audio_dai[] = {
71 {
72 .name = "FE-PI",
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,
82 },
83 };
84
85 static const struct snd_soc_dapm_route fe_pi_audio_dapm_routes[] = {
86 {"ADC", NULL, "Mic Bias"},
87 };
88
89
90 static struct snd_soc_card fe_pi_audio = {
91 .name = "Fe-Pi Audio",
92 .owner = THIS_MODULE,
93 .dai_link = snd_fe_pi_audio_dai,
94 .num_links = ARRAY_SIZE(snd_fe_pi_audio_dai),
95
96 .dapm_routes = fe_pi_audio_dapm_routes,
97 .num_dapm_routes = ARRAY_SIZE(fe_pi_audio_dapm_routes),
98 };
99
100 static int snd_fe_pi_audio_probe(struct platform_device *pdev)
101 {
102 int ret = 0;
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];
107
108 fe_pi_audio.dev = &pdev->dev;
109
110 i2s_node = of_parse_phandle(np, "i2s-controller", 0);
111 if (!i2s_node) {
112 dev_err(&pdev->dev, "i2s_node phandle missing or invalid\n");
113 return -EINVAL;
114 }
115
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;
120
121 of_node_put(i2s_node);
122
123 card->dev = &pdev->dev;
124 platform_set_drvdata(pdev, card);
125
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);
129
130 return ret;
131 }
132
133 static int snd_fe_pi_audio_remove(struct platform_device *pdev)
134 {
135 return snd_soc_unregister_card(&fe_pi_audio);
136 }
137
138 static const struct of_device_id snd_fe_pi_audio_of_match[] = {
139 { .compatible = "fe-pi,fe-pi-audio", },
140 {},
141 };
142 MODULE_DEVICE_TABLE(of, snd_fe_pi_audio_of_match);
143
144 static struct platform_driver snd_fe_pi_audio_driver = {
145 .driver = {
146 .name = "snd-fe-pi-audio",
147 .owner = THIS_MODULE,
148 .of_match_table = snd_fe_pi_audio_of_match,
149 },
150 .probe = snd_fe_pi_audio_probe,
151 .remove = snd_fe_pi_audio_remove,
152 };
153
154 module_platform_driver(snd_fe_pi_audio_driver);
155
156 MODULE_AUTHOR("Henry Kupis <fe-pi@cox.net>");
157 MODULE_DESCRIPTION("ASoC Driver for Fe-Pi Audio");
158 MODULE_LICENSE("GPL v2");