2 * ALSA Soc PCM3008 codec support
4 * Author: Hugo Villeneuve
5 * Copyright (C) 2008 Lyrtech inc
7 * Based on AC97 Soc codec, original copyright follow:
8 * Copyright 2005 Wolfson Microelectronics PLC.
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.
15 * Generic PCM3008 support.
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>
29 #define PCM3008_VERSION "0.2"
31 #define PCM3008_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
34 struct snd_soc_dai pcm3008_dai = {
35 .name = "PCM3008 HiFi",
37 .stream_name = "PCM3008 Playback",
40 .rates = PCM3008_RATES,
41 .formats = SNDRV_PCM_FMTBIT_S16_LE,
44 .stream_name = "PCM3008 Capture",
47 .rates = PCM3008_RATES,
48 .formats = SNDRV_PCM_FMTBIT_S16_LE,
51 EXPORT_SYMBOL_GPL(pcm3008_dai);
53 static void pcm3008_gpio_free(struct pcm3008_setup_data *setup)
55 gpio_free(setup->dem0_pin);
56 gpio_free(setup->dem1_pin);
57 gpio_free(setup->pdad_pin);
58 gpio_free(setup->pdda_pin);
61 static int pcm3008_soc_probe(struct platform_device *pdev)
63 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
64 struct snd_soc_codec *codec;
65 struct pcm3008_setup_data *setup = socdev->codec_data;
68 printk(KERN_INFO "PCM3008 SoC Audio Codec %s\n", PCM3008_VERSION);
70 socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
74 codec = socdev->codec;
75 mutex_init(&codec->mutex);
77 codec->name = "PCM3008";
78 codec->owner = THIS_MODULE;
79 codec->dai = &pcm3008_dai;
83 INIT_LIST_HEAD(&codec->dapm_widgets);
84 INIT_LIST_HEAD(&codec->dapm_paths);
87 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
89 printk(KERN_ERR "pcm3008: failed to create pcms\n");
94 ret = snd_soc_init_card(socdev);
96 printk(KERN_ERR "pcm3008: failed to register card\n");
100 /* DEM1 DEM0 DE-EMPHASIS_MODE
101 * Low Low De-emphasis 44.1 kHz ON
102 * Low High De-emphasis OFF
103 * High Low De-emphasis 48 kHz ON
104 * High High De-emphasis 32 kHz ON
107 /* Configure DEM0 GPIO (turning OFF DAC De-emphasis). */
108 ret = gpio_request(setup->dem0_pin, "codec_dem0");
110 ret = gpio_direction_output(setup->dem0_pin, 1);
114 /* Configure DEM1 GPIO (turning OFF DAC De-emphasis). */
115 ret = gpio_request(setup->dem1_pin, "codec_dem1");
117 ret = gpio_direction_output(setup->dem1_pin, 0);
121 /* Configure PDAD GPIO. */
122 ret = gpio_request(setup->pdad_pin, "codec_pdad");
124 ret = gpio_direction_output(setup->pdad_pin, 1);
128 /* Configure PDDA GPIO. */
129 ret = gpio_request(setup->pdda_pin, "codec_pdda");
131 ret = gpio_direction_output(setup->pdda_pin, 1);
138 pcm3008_gpio_free(setup);
140 snd_soc_free_pcms(socdev);
142 kfree(socdev->codec);
147 static int pcm3008_soc_remove(struct platform_device *pdev)
149 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
150 struct snd_soc_codec *codec = socdev->codec;
151 struct pcm3008_setup_data *setup = socdev->codec_data;
156 pcm3008_gpio_free(setup);
157 snd_soc_free_pcms(socdev);
158 kfree(socdev->codec);
164 static int pcm3008_soc_suspend(struct platform_device *pdev, pm_message_t msg)
166 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
167 struct pcm3008_setup_data *setup = socdev->codec_data;
169 gpio_set_value(setup->pdad_pin, 0);
170 gpio_set_value(setup->pdda_pin, 0);
175 static int pcm3008_soc_resume(struct platform_device *pdev)
177 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
178 struct pcm3008_setup_data *setup = socdev->codec_data;
180 gpio_set_value(setup->pdad_pin, 1);
181 gpio_set_value(setup->pdda_pin, 1);
186 #define pcm3008_soc_suspend NULL
187 #define pcm3008_soc_resume NULL
190 struct snd_soc_codec_device soc_codec_dev_pcm3008 = {
191 .probe = pcm3008_soc_probe,
192 .remove = pcm3008_soc_remove,
193 .suspend = pcm3008_soc_suspend,
194 .resume = pcm3008_soc_resume,
196 EXPORT_SYMBOL_GPL(soc_codec_dev_pcm3008);
198 static int __init pcm3008_init(void)
200 return snd_soc_register_dai(&pcm3008_dai);
202 module_init(pcm3008_init);
204 static void __exit pcm3008_exit(void)
206 snd_soc_unregister_dai(&pcm3008_dai);
208 module_exit(pcm3008_exit);
210 MODULE_DESCRIPTION("Soc PCM3008 driver");
211 MODULE_AUTHOR("Hugo Villeneuve");
212 MODULE_LICENSE("GPL");