]>
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> | |
22 | #include <sound/core.h> | |
23 | #include <sound/pcm.h> | |
24 | #include <sound/initval.h> | |
25 | #include <sound/soc.h> | |
26 | ||
27 | #include "pcm3008.h" | |
28 | ||
29 | #define PCM3008_VERSION "0.2" | |
30 | ||
31 | #define PCM3008_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \ | |
32 | SNDRV_PCM_RATE_48000) | |
33 | ||
34 | struct snd_soc_dai pcm3008_dai = { | |
35 | .name = "PCM3008 HiFi", | |
36 | .type = SND_SOC_DAI_I2S, | |
37 | .playback = { | |
38 | .stream_name = "PCM3008 Playback", | |
39 | .channels_min = 1, | |
40 | .channels_max = 2, | |
41 | .rates = PCM3008_RATES, | |
42 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | |
43 | }, | |
44 | .capture = { | |
45 | .stream_name = "PCM3008 Capture", | |
46 | .channels_min = 1, | |
47 | .channels_max = 2, | |
48 | .rates = PCM3008_RATES, | |
49 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | |
50 | }, | |
51 | }; | |
52 | EXPORT_SYMBOL_GPL(pcm3008_dai); | |
53 | ||
54 | static void pcm3008_gpio_free(struct pcm3008_setup_data *setup) | |
55 | { | |
56 | gpio_free(setup->dem0_pin); | |
57 | gpio_free(setup->dem1_pin); | |
58 | gpio_free(setup->pdad_pin); | |
59 | gpio_free(setup->pdda_pin); | |
60 | } | |
61 | ||
62 | static int pcm3008_soc_probe(struct platform_device *pdev) | |
63 | { | |
64 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | |
65 | struct snd_soc_codec *codec; | |
66 | struct pcm3008_setup_data *setup = socdev->codec_data; | |
67 | int ret = 0; | |
68 | ||
69 | printk(KERN_INFO "PCM3008 SoC Audio Codec %s\n", PCM3008_VERSION); | |
70 | ||
71 | socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); | |
72 | if (!socdev->codec) | |
73 | return -ENOMEM; | |
74 | ||
75 | codec = socdev->codec; | |
76 | mutex_init(&codec->mutex); | |
77 | ||
78 | codec->name = "PCM3008"; | |
79 | codec->owner = THIS_MODULE; | |
80 | codec->dai = &pcm3008_dai; | |
81 | codec->num_dai = 1; | |
82 | codec->write = NULL; | |
83 | codec->read = NULL; | |
84 | INIT_LIST_HEAD(&codec->dapm_widgets); | |
85 | INIT_LIST_HEAD(&codec->dapm_paths); | |
86 | ||
87 | /* Register PCMs. */ | |
88 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); | |
89 | if (ret < 0) { | |
90 | printk(KERN_ERR "pcm3008: failed to create pcms\n"); | |
91 | goto pcm_err; | |
92 | } | |
93 | ||
94 | /* Register Card. */ | |
95 | ret = snd_soc_register_card(socdev); | |
96 | if (ret < 0) { | |
97 | printk(KERN_ERR "pcm3008: failed to register card\n"); | |
98 | goto card_err; | |
99 | } | |
100 | ||
101 | /* DEM1 DEM0 DE-EMPHASIS_MODE | |
102 | * Low Low De-emphasis 44.1 kHz ON | |
103 | * Low High De-emphasis OFF | |
104 | * High Low De-emphasis 48 kHz ON | |
105 | * High High De-emphasis 32 kHz ON | |
106 | */ | |
107 | ||
108 | /* Configure DEM0 GPIO (turning OFF DAC De-emphasis). */ | |
109 | ret = gpio_request(setup->dem0_pin, "codec_dem0"); | |
110 | if (ret == 0) | |
111 | ret = gpio_direction_output(setup->dem0_pin, 1); | |
112 | if (ret != 0) | |
113 | goto gpio_err; | |
114 | ||
115 | /* Configure DEM1 GPIO (turning OFF DAC De-emphasis). */ | |
116 | ret = gpio_request(setup->dem1_pin, "codec_dem1"); | |
117 | if (ret == 0) | |
118 | ret = gpio_direction_output(setup->dem1_pin, 0); | |
119 | if (ret != 0) | |
120 | goto gpio_err; | |
121 | ||
122 | /* Configure PDAD GPIO. */ | |
123 | ret = gpio_request(setup->pdad_pin, "codec_pdad"); | |
124 | if (ret == 0) | |
125 | ret = gpio_direction_output(setup->pdad_pin, 1); | |
126 | if (ret != 0) | |
127 | goto gpio_err; | |
128 | ||
129 | /* Configure PDDA GPIO. */ | |
130 | ret = gpio_request(setup->pdda_pin, "codec_pdda"); | |
131 | if (ret == 0) | |
132 | ret = gpio_direction_output(setup->pdda_pin, 1); | |
133 | if (ret != 0) | |
134 | goto gpio_err; | |
135 | ||
136 | return ret; | |
137 | ||
138 | gpio_err: | |
139 | pcm3008_gpio_free(setup); | |
140 | card_err: | |
141 | snd_soc_free_pcms(socdev); | |
142 | pcm_err: | |
143 | kfree(socdev->codec); | |
144 | ||
145 | return ret; | |
146 | } | |
147 | ||
148 | static int pcm3008_soc_remove(struct platform_device *pdev) | |
149 | { | |
150 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | |
151 | struct snd_soc_codec *codec = socdev->codec; | |
152 | struct pcm3008_setup_data *setup = socdev->codec_data; | |
153 | ||
154 | if (!codec) | |
155 | return 0; | |
156 | ||
157 | pcm3008_gpio_free(setup); | |
158 | snd_soc_free_pcms(socdev); | |
159 | kfree(socdev->codec); | |
160 | ||
161 | return 0; | |
162 | } | |
163 | ||
164 | #ifdef CONFIG_PM | |
165 | static int pcm3008_soc_suspend(struct platform_device *pdev, pm_message_t msg) | |
166 | { | |
167 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | |
168 | struct pcm3008_setup_data *setup = socdev->codec_data; | |
169 | ||
170 | gpio_set_value(setup->pdad_pin, 0); | |
171 | gpio_set_value(setup->pdda_pin, 0); | |
172 | ||
173 | return 0; | |
174 | } | |
175 | ||
176 | static int pcm3008_soc_resume(struct platform_device *pdev) | |
177 | { | |
178 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | |
179 | struct pcm3008_setup_data *setup = socdev->codec_data; | |
180 | ||
181 | gpio_set_value(setup->pdad_pin, 1); | |
182 | gpio_set_value(setup->pdda_pin, 1); | |
183 | ||
184 | return 0; | |
185 | } | |
186 | #else | |
187 | #define pcm3008_soc_suspend NULL | |
188 | #define pcm3008_soc_resume NULL | |
189 | #endif | |
190 | ||
191 | struct snd_soc_codec_device soc_codec_dev_pcm3008 = { | |
192 | .probe = pcm3008_soc_probe, | |
193 | .remove = pcm3008_soc_remove, | |
194 | .suspend = pcm3008_soc_suspend, | |
195 | .resume = pcm3008_soc_resume, | |
196 | }; | |
197 | EXPORT_SYMBOL_GPL(soc_codec_dev_pcm3008); | |
198 | ||
199 | MODULE_DESCRIPTION("Soc PCM3008 driver"); | |
200 | MODULE_AUTHOR("Hugo Villeneuve"); | |
201 | MODULE_LICENSE("GPL"); |