Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 22 | #include <linux/slab.h> |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 23 | #include <sound/core.h> |
| 24 | #include <sound/pcm.h> |
| 25 | #include <sound/initval.h> |
| 26 | #include <sound/soc.h> |
| 27 | |
| 28 | #include "pcm3008.h" |
| 29 | |
| 30 | #define PCM3008_VERSION "0.2" |
| 31 | |
| 32 | #define PCM3008_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \ |
| 33 | SNDRV_PCM_RATE_48000) |
| 34 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 35 | static struct snd_soc_dai_driver pcm3008_dai = { |
| 36 | .name = "pcm3008-hifi", |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 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 | }; |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 52 | |
| 53 | static void pcm3008_gpio_free(struct pcm3008_setup_data *setup) |
| 54 | { |
| 55 | gpio_free(setup->dem0_pin); |
| 56 | gpio_free(setup->dem1_pin); |
| 57 | gpio_free(setup->pdad_pin); |
| 58 | gpio_free(setup->pdda_pin); |
| 59 | } |
| 60 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 61 | static int pcm3008_soc_probe(struct snd_soc_codec *codec) |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 62 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 63 | struct pcm3008_setup_data *setup = codec->dev->platform_data; |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 64 | int ret = 0; |
| 65 | |
| 66 | printk(KERN_INFO "PCM3008 SoC Audio Codec %s\n", PCM3008_VERSION); |
| 67 | |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 68 | /* DEM1 DEM0 DE-EMPHASIS_MODE |
| 69 | * Low Low De-emphasis 44.1 kHz ON |
| 70 | * Low High De-emphasis OFF |
| 71 | * High Low De-emphasis 48 kHz ON |
| 72 | * High High De-emphasis 32 kHz ON |
| 73 | */ |
| 74 | |
| 75 | /* Configure DEM0 GPIO (turning OFF DAC De-emphasis). */ |
| 76 | ret = gpio_request(setup->dem0_pin, "codec_dem0"); |
| 77 | if (ret == 0) |
| 78 | ret = gpio_direction_output(setup->dem0_pin, 1); |
| 79 | if (ret != 0) |
| 80 | goto gpio_err; |
| 81 | |
| 82 | /* Configure DEM1 GPIO (turning OFF DAC De-emphasis). */ |
| 83 | ret = gpio_request(setup->dem1_pin, "codec_dem1"); |
| 84 | if (ret == 0) |
| 85 | ret = gpio_direction_output(setup->dem1_pin, 0); |
| 86 | if (ret != 0) |
| 87 | goto gpio_err; |
| 88 | |
| 89 | /* Configure PDAD GPIO. */ |
| 90 | ret = gpio_request(setup->pdad_pin, "codec_pdad"); |
| 91 | if (ret == 0) |
| 92 | ret = gpio_direction_output(setup->pdad_pin, 1); |
| 93 | if (ret != 0) |
| 94 | goto gpio_err; |
| 95 | |
| 96 | /* Configure PDDA GPIO. */ |
| 97 | ret = gpio_request(setup->pdda_pin, "codec_pdda"); |
| 98 | if (ret == 0) |
| 99 | ret = gpio_direction_output(setup->pdda_pin, 1); |
| 100 | if (ret != 0) |
| 101 | goto gpio_err; |
| 102 | |
| 103 | return ret; |
| 104 | |
| 105 | gpio_err: |
| 106 | pcm3008_gpio_free(setup); |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 107 | |
| 108 | return ret; |
| 109 | } |
| 110 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 111 | static int pcm3008_soc_remove(struct snd_soc_codec *codec) |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 112 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 113 | struct pcm3008_setup_data *setup = codec->dev->platform_data; |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 114 | |
| 115 | pcm3008_gpio_free(setup); |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | #ifdef CONFIG_PM |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 120 | static int pcm3008_soc_suspend(struct snd_soc_codec *codec, pm_message_t msg) |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 121 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 122 | struct pcm3008_setup_data *setup = codec->dev->platform_data; |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 123 | |
| 124 | gpio_set_value(setup->pdad_pin, 0); |
| 125 | gpio_set_value(setup->pdda_pin, 0); |
| 126 | |
| 127 | return 0; |
| 128 | } |
| 129 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 130 | static int pcm3008_soc_resume(struct snd_soc_codec *codec) |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 131 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 132 | struct pcm3008_setup_data *setup = codec->dev->platform_data; |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 133 | |
| 134 | gpio_set_value(setup->pdad_pin, 1); |
| 135 | gpio_set_value(setup->pdda_pin, 1); |
| 136 | |
| 137 | return 0; |
| 138 | } |
| 139 | #else |
| 140 | #define pcm3008_soc_suspend NULL |
| 141 | #define pcm3008_soc_resume NULL |
| 142 | #endif |
| 143 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 144 | static struct snd_soc_codec_driver soc_codec_dev_pcm3008 = { |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 145 | .probe = pcm3008_soc_probe, |
| 146 | .remove = pcm3008_soc_remove, |
| 147 | .suspend = pcm3008_soc_suspend, |
| 148 | .resume = pcm3008_soc_resume, |
| 149 | }; |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 150 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 151 | static int __devinit pcm3008_codec_probe(struct platform_device *pdev) |
Mark Brown | 64089b8 | 2008-12-08 19:17:58 +0000 | [diff] [blame] | 152 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 153 | return snd_soc_register_codec(&pdev->dev, |
| 154 | &soc_codec_dev_pcm3008, &pcm3008_dai, 1); |
Mark Brown | 64089b8 | 2008-12-08 19:17:58 +0000 | [diff] [blame] | 155 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 156 | |
| 157 | static int __devexit pcm3008_codec_remove(struct platform_device *pdev) |
| 158 | { |
| 159 | snd_soc_unregister_codec(&pdev->dev); |
| 160 | return 0; |
| 161 | } |
| 162 | |
| 163 | MODULE_ALIAS("platform:pcm3008-codec"); |
| 164 | |
| 165 | static struct platform_driver pcm3008_codec_driver = { |
| 166 | .probe = pcm3008_codec_probe, |
| 167 | .remove = __devexit_p(pcm3008_codec_remove), |
| 168 | .driver = { |
| 169 | .name = "pcm3008-codec", |
| 170 | .owner = THIS_MODULE, |
| 171 | }, |
| 172 | }; |
| 173 | |
| 174 | static int __init pcm3008_modinit(void) |
| 175 | { |
| 176 | return platform_driver_register(&pcm3008_codec_driver); |
| 177 | } |
| 178 | module_init(pcm3008_modinit); |
Mark Brown | 64089b8 | 2008-12-08 19:17:58 +0000 | [diff] [blame] | 179 | |
| 180 | static void __exit pcm3008_exit(void) |
| 181 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 182 | platform_driver_unregister(&pcm3008_codec_driver); |
Mark Brown | 64089b8 | 2008-12-08 19:17:58 +0000 | [diff] [blame] | 183 | } |
| 184 | module_exit(pcm3008_exit); |
| 185 | |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 186 | MODULE_DESCRIPTION("Soc PCM3008 driver"); |
| 187 | MODULE_AUTHOR("Hugo Villeneuve"); |
| 188 | MODULE_LICENSE("GPL"); |