Merge git://git.kvack.org/~bcrl/aio-next
[deliverable/linux.git] / sound / soc / intel / byt-rt5640.c
CommitLineData
a4b12990
MB
1/*
2 * Intel Baytrail SST RT5640 machine driver
3 * Copyright (c) 2014, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/init.h>
16#include <linux/module.h>
17#include <linux/platform_device.h>
18#include <linux/acpi.h>
19#include <linux/device.h>
20#include <linux/slab.h>
21#include <sound/pcm.h>
22#include <sound/pcm_params.h>
23#include <sound/soc.h>
24#include <sound/jack.h>
25#include "../codecs/rt5640.h"
26
27#include "sst-dsp.h"
28
29static const struct snd_soc_dapm_widget byt_rt5640_widgets[] = {
30 SND_SOC_DAPM_HP("Headphone", NULL),
31 SND_SOC_DAPM_MIC("Headset Mic", NULL),
32 SND_SOC_DAPM_MIC("Internal Mic", NULL),
33 SND_SOC_DAPM_SPK("Speaker", NULL),
34};
35
36static const struct snd_soc_dapm_route byt_rt5640_audio_map[] = {
c9a8e3bd 37 {"Headset Mic", NULL, "MICBIAS1"},
a4b12990
MB
38 {"IN2P", NULL, "Headset Mic"},
39 {"IN2N", NULL, "Headset Mic"},
40 {"DMIC1", NULL, "Internal Mic"},
41 {"Headphone", NULL, "HPOL"},
42 {"Headphone", NULL, "HPOR"},
43 {"Speaker", NULL, "SPOLP"},
44 {"Speaker", NULL, "SPOLN"},
45 {"Speaker", NULL, "SPORP"},
46 {"Speaker", NULL, "SPORN"},
47};
48
49static const struct snd_kcontrol_new byt_rt5640_controls[] = {
50 SOC_DAPM_PIN_SWITCH("Headphone"),
51 SOC_DAPM_PIN_SWITCH("Headset Mic"),
52 SOC_DAPM_PIN_SWITCH("Internal Mic"),
53 SOC_DAPM_PIN_SWITCH("Speaker"),
54};
55
56static int byt_rt5640_hw_params(struct snd_pcm_substream *substream,
57 struct snd_pcm_hw_params *params)
58{
59 struct snd_soc_pcm_runtime *rtd = substream->private_data;
60 struct snd_soc_dai *codec_dai = rtd->codec_dai;
61 int ret;
62
63 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1,
64 params_rate(params) * 256,
65 SND_SOC_CLOCK_IN);
66 if (ret < 0) {
67 dev_err(codec_dai->dev, "can't set codec clock %d\n", ret);
68 return ret;
69 }
70 ret = snd_soc_dai_set_pll(codec_dai, 0, RT5640_PLL1_S_BCLK1,
71 params_rate(params) * 64,
72 params_rate(params) * 256);
73 if (ret < 0) {
74 dev_err(codec_dai->dev, "can't set codec pll: %d\n", ret);
75 return ret;
76 }
77 return 0;
78}
79
80static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)
81{
82 int ret;
83 struct snd_soc_codec *codec = runtime->codec;
84 struct snd_soc_dapm_context *dapm = &codec->dapm;
85 struct snd_soc_card *card = runtime->card;
86
87 card->dapm.idle_bias_off = true;
88
89 ret = snd_soc_add_card_controls(card, byt_rt5640_controls,
90 ARRAY_SIZE(byt_rt5640_controls));
91 if (ret) {
92 dev_err(card->dev, "unable to add card controls\n");
93 return ret;
94 }
95
96 snd_soc_dapm_ignore_suspend(dapm, "HPOL");
97 snd_soc_dapm_ignore_suspend(dapm, "HPOR");
98
99 snd_soc_dapm_ignore_suspend(dapm, "SPOLP");
100 snd_soc_dapm_ignore_suspend(dapm, "SPOLN");
101 snd_soc_dapm_ignore_suspend(dapm, "SPORP");
102 snd_soc_dapm_ignore_suspend(dapm, "SPORN");
103
a4b12990
MB
104 return ret;
105}
106
107static struct snd_soc_ops byt_rt5640_ops = {
108 .hw_params = byt_rt5640_hw_params,
109};
110
111static struct snd_soc_dai_link byt_rt5640_dais[] = {
112 {
113 .name = "Baytrail Audio",
114 .stream_name = "Audio",
49fee178 115 .cpu_dai_name = "baytrail-pcm-audio",
a4b12990
MB
116 .codec_dai_name = "rt5640-aif1",
117 .codec_name = "i2c-10EC5640:00",
118 .platform_name = "baytrail-pcm-audio",
119 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
120 SND_SOC_DAIFMT_CBS_CFS,
121 .init = byt_rt5640_init,
a4b12990
MB
122 .ops = &byt_rt5640_ops,
123 },
124};
125
126static struct snd_soc_card byt_rt5640_card = {
127 .name = "byt-rt5640",
128 .dai_link = byt_rt5640_dais,
129 .num_links = ARRAY_SIZE(byt_rt5640_dais),
130 .dapm_widgets = byt_rt5640_widgets,
131 .num_dapm_widgets = ARRAY_SIZE(byt_rt5640_widgets),
132 .dapm_routes = byt_rt5640_audio_map,
133 .num_dapm_routes = ARRAY_SIZE(byt_rt5640_audio_map),
134};
135
136static int byt_rt5640_probe(struct platform_device *pdev)
137{
138 struct snd_soc_card *card = &byt_rt5640_card;
a4b12990
MB
139
140 card->dev = &pdev->dev;
8eb776ab 141 return devm_snd_soc_register_card(&pdev->dev, card);
a4b12990
MB
142}
143
144static struct platform_driver byt_rt5640_audio = {
145 .probe = byt_rt5640_probe,
a4b12990
MB
146 .driver = {
147 .name = "byt-rt5640",
148 .owner = THIS_MODULE,
4af72f4e 149 .pm = &snd_soc_pm_ops,
a4b12990
MB
150 },
151};
152module_platform_driver(byt_rt5640_audio)
153
154MODULE_DESCRIPTION("ASoC Intel(R) Baytrail Machine driver");
155MODULE_AUTHOR("Omair Md Abdullah, Jarkko Nikula");
156MODULE_LICENSE("GPL v2");
157MODULE_ALIAS("platform:byt-rt5640");
This page took 0.117247 seconds and 5 git commands to generate.