]>
Commit | Line | Data |
---|---|---|
1c0090c2 HV |
1 | /* |
2 | * ALSA Soc PCM3008 codec support | |
3 | * | |
4 | * Author: Hugo Villeneuve | |
5 | * Copyright (C) 2008 Lyrtech inc | |
6 | * | |
7 | * Based on AC97 Soc codec, original copyright follow: | |
8 | * Copyright 2005 Wolfson Microelectronics PLC. | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or modify it | |
11 | * under the terms of the GNU General Public License as published by the | |
12 | * Free Software Foundation; either version 2 of the License, or (at your | |
13 | * option) any later version. | |
14 | * | |
15 | * Generic PCM3008 support. | |
16 | */ | |
17 | ||
18 | #include <linux/init.h> | |
19 | #include <linux/kernel.h> | |
20 | #include <linux/device.h> | |
21 | #include <linux/gpio.h> | |
5a0e3ad6 | 22 | #include <linux/slab.h> |
da155d5b | 23 | #include <linux/module.h> |
1c0090c2 HV |
24 | #include <sound/core.h> |
25 | #include <sound/pcm.h> | |
26 | #include <sound/initval.h> | |
27 | #include <sound/soc.h> | |
28 | ||
29 | #include "pcm3008.h" | |
30 | ||
4fc932c6 MB |
31 | static int pcm3008_dac_ev(struct snd_soc_dapm_widget *w, |
32 | struct snd_kcontrol *kcontrol, | |
33 | int event) | |
34 | { | |
0d76091c | 35 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
4fc932c6 MB |
36 | struct pcm3008_setup_data *setup = codec->dev->platform_data; |
37 | ||
38 | gpio_set_value_cansleep(setup->pdda_pin, | |
39 | SND_SOC_DAPM_EVENT_ON(event)); | |
40 | ||
41 | return 0; | |
42 | } | |
43 | ||
44 | static int pcm3008_adc_ev(struct snd_soc_dapm_widget *w, | |
45 | struct snd_kcontrol *kcontrol, | |
46 | int event) | |
47 | { | |
0d76091c | 48 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
4fc932c6 MB |
49 | struct pcm3008_setup_data *setup = codec->dev->platform_data; |
50 | ||
51 | gpio_set_value_cansleep(setup->pdad_pin, | |
52 | SND_SOC_DAPM_EVENT_ON(event)); | |
53 | ||
54 | return 0; | |
55 | } | |
56 | ||
faaf36f2 MB |
57 | static const struct snd_soc_dapm_widget pcm3008_dapm_widgets[] = { |
58 | SND_SOC_DAPM_INPUT("VINL"), | |
59 | SND_SOC_DAPM_INPUT("VINR"), | |
60 | ||
4fc932c6 MB |
61 | SND_SOC_DAPM_DAC_E("DAC", NULL, SND_SOC_NOPM, 0, 0, pcm3008_dac_ev, |
62 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), | |
63 | SND_SOC_DAPM_ADC_E("ADC", NULL, SND_SOC_NOPM, 0, 0, pcm3008_adc_ev, | |
64 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), | |
65 | ||
faaf36f2 MB |
66 | SND_SOC_DAPM_OUTPUT("VOUTL"), |
67 | SND_SOC_DAPM_OUTPUT("VOUTR"), | |
68 | }; | |
69 | ||
70 | static const struct snd_soc_dapm_route pcm3008_dapm_routes[] = { | |
4fc932c6 MB |
71 | { "PCM3008 Capture", NULL, "ADC" }, |
72 | { "ADC", NULL, "VINL" }, | |
73 | { "ADC", NULL, "VINR" }, | |
faaf36f2 | 74 | |
4fc932c6 MB |
75 | { "DAC", NULL, "PCM3008 Playback" }, |
76 | { "VOUTL", NULL, "DAC" }, | |
77 | { "VOUTR", NULL, "DAC" }, | |
faaf36f2 MB |
78 | }; |
79 | ||
1c0090c2 HV |
80 | #define PCM3008_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \ |
81 | SNDRV_PCM_RATE_48000) | |
82 | ||
f0fba2ad LG |
83 | static struct snd_soc_dai_driver pcm3008_dai = { |
84 | .name = "pcm3008-hifi", | |
1c0090c2 HV |
85 | .playback = { |
86 | .stream_name = "PCM3008 Playback", | |
87 | .channels_min = 1, | |
88 | .channels_max = 2, | |
89 | .rates = PCM3008_RATES, | |
90 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | |
91 | }, | |
92 | .capture = { | |
93 | .stream_name = "PCM3008 Capture", | |
94 | .channels_min = 1, | |
95 | .channels_max = 2, | |
96 | .rates = PCM3008_RATES, | |
97 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | |
98 | }, | |
99 | }; | |
1c0090c2 | 100 | |
d7f18495 | 101 | static struct snd_soc_codec_driver soc_codec_dev_pcm3008 = { |
4cd747df KM |
102 | .component_driver = { |
103 | .dapm_widgets = pcm3008_dapm_widgets, | |
104 | .num_dapm_widgets = ARRAY_SIZE(pcm3008_dapm_widgets), | |
105 | .dapm_routes = pcm3008_dapm_routes, | |
106 | .num_dapm_routes = ARRAY_SIZE(pcm3008_dapm_routes), | |
107 | }, | |
d7f18495 MB |
108 | }; |
109 | ||
110 | static int pcm3008_codec_probe(struct platform_device *pdev) | |
111 | { | |
112 | struct pcm3008_setup_data *setup = pdev->dev.platform_data; | |
113 | int ret; | |
1c0090c2 | 114 | |
33319a2f MB |
115 | if (!setup) |
116 | return -EINVAL; | |
117 | ||
1c0090c2 HV |
118 | /* DEM1 DEM0 DE-EMPHASIS_MODE |
119 | * Low Low De-emphasis 44.1 kHz ON | |
120 | * Low High De-emphasis OFF | |
121 | * High Low De-emphasis 48 kHz ON | |
122 | * High High De-emphasis 32 kHz ON | |
123 | */ | |
124 | ||
125 | /* Configure DEM0 GPIO (turning OFF DAC De-emphasis). */ | |
d57a79ac MB |
126 | ret = devm_gpio_request_one(&pdev->dev, setup->dem0_pin, |
127 | GPIOF_OUT_INIT_HIGH, "codec_dem0"); | |
1c0090c2 | 128 | if (ret != 0) |
d57a79ac | 129 | return ret; |
1c0090c2 HV |
130 | |
131 | /* Configure DEM1 GPIO (turning OFF DAC De-emphasis). */ | |
d57a79ac MB |
132 | ret = devm_gpio_request_one(&pdev->dev, setup->dem1_pin, |
133 | GPIOF_OUT_INIT_LOW, "codec_dem1"); | |
1c0090c2 | 134 | if (ret != 0) |
d57a79ac | 135 | return ret; |
1c0090c2 HV |
136 | |
137 | /* Configure PDAD GPIO. */ | |
d57a79ac | 138 | ret = devm_gpio_request_one(&pdev->dev, setup->pdad_pin, |
4fc932c6 | 139 | GPIOF_OUT_INIT_LOW, "codec_pdad"); |
1c0090c2 | 140 | if (ret != 0) |
d57a79ac | 141 | return ret; |
1c0090c2 HV |
142 | |
143 | /* Configure PDDA GPIO. */ | |
d57a79ac | 144 | ret = devm_gpio_request_one(&pdev->dev, setup->pdda_pin, |
4fc932c6 | 145 | GPIOF_OUT_INIT_LOW, "codec_pdda"); |
1c0090c2 | 146 | if (ret != 0) |
d57a79ac | 147 | return ret; |
1c0090c2 | 148 | |
d7f18495 MB |
149 | return snd_soc_register_codec(&pdev->dev, |
150 | &soc_codec_dev_pcm3008, &pcm3008_dai, 1); | |
1c0090c2 HV |
151 | } |
152 | ||
d7f18495 | 153 | static int pcm3008_codec_remove(struct platform_device *pdev) |
1c0090c2 | 154 | { |
d7f18495 | 155 | snd_soc_unregister_codec(&pdev->dev); |
1c0090c2 | 156 | |
f0fba2ad LG |
157 | return 0; |
158 | } | |
159 | ||
160 | MODULE_ALIAS("platform:pcm3008-codec"); | |
161 | ||
162 | static struct platform_driver pcm3008_codec_driver = { | |
163 | .probe = pcm3008_codec_probe, | |
7a79e94e | 164 | .remove = pcm3008_codec_remove, |
f0fba2ad LG |
165 | .driver = { |
166 | .name = "pcm3008-codec", | |
f0fba2ad LG |
167 | }, |
168 | }; | |
169 | ||
5bbcc3c0 | 170 | module_platform_driver(pcm3008_codec_driver); |
64089b84 | 171 | |
1c0090c2 HV |
172 | MODULE_DESCRIPTION("Soc PCM3008 driver"); |
173 | MODULE_AUTHOR("Hugo Villeneuve"); | |
174 | MODULE_LICENSE("GPL"); |