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> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 23 | #include <linux/module.h> |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 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 | |
| 31 | #define PCM3008_VERSION "0.2" |
| 32 | |
| 33 | #define PCM3008_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \ |
| 34 | SNDRV_PCM_RATE_48000) |
| 35 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 36 | static struct snd_soc_dai_driver pcm3008_dai = { |
| 37 | .name = "pcm3008-hifi", |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 38 | .playback = { |
| 39 | .stream_name = "PCM3008 Playback", |
| 40 | .channels_min = 1, |
| 41 | .channels_max = 2, |
| 42 | .rates = PCM3008_RATES, |
| 43 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 44 | }, |
| 45 | .capture = { |
| 46 | .stream_name = "PCM3008 Capture", |
| 47 | .channels_min = 1, |
| 48 | .channels_max = 2, |
| 49 | .rates = PCM3008_RATES, |
| 50 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 51 | }, |
| 52 | }; |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 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 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 62 | static int pcm3008_soc_probe(struct snd_soc_codec *codec) |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 63 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 64 | struct pcm3008_setup_data *setup = codec->dev->platform_data; |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 65 | int ret = 0; |
| 66 | |
| 67 | printk(KERN_INFO "PCM3008 SoC Audio Codec %s\n", PCM3008_VERSION); |
| 68 | |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 69 | /* DEM1 DEM0 DE-EMPHASIS_MODE |
| 70 | * Low Low De-emphasis 44.1 kHz ON |
| 71 | * Low High De-emphasis OFF |
| 72 | * High Low De-emphasis 48 kHz ON |
| 73 | * High High De-emphasis 32 kHz ON |
| 74 | */ |
| 75 | |
| 76 | /* Configure DEM0 GPIO (turning OFF DAC De-emphasis). */ |
| 77 | ret = gpio_request(setup->dem0_pin, "codec_dem0"); |
| 78 | if (ret == 0) |
| 79 | ret = gpio_direction_output(setup->dem0_pin, 1); |
| 80 | if (ret != 0) |
| 81 | goto gpio_err; |
| 82 | |
| 83 | /* Configure DEM1 GPIO (turning OFF DAC De-emphasis). */ |
| 84 | ret = gpio_request(setup->dem1_pin, "codec_dem1"); |
| 85 | if (ret == 0) |
| 86 | ret = gpio_direction_output(setup->dem1_pin, 0); |
| 87 | if (ret != 0) |
| 88 | goto gpio_err; |
| 89 | |
| 90 | /* Configure PDAD GPIO. */ |
| 91 | ret = gpio_request(setup->pdad_pin, "codec_pdad"); |
| 92 | if (ret == 0) |
| 93 | ret = gpio_direction_output(setup->pdad_pin, 1); |
| 94 | if (ret != 0) |
| 95 | goto gpio_err; |
| 96 | |
| 97 | /* Configure PDDA GPIO. */ |
| 98 | ret = gpio_request(setup->pdda_pin, "codec_pdda"); |
| 99 | if (ret == 0) |
| 100 | ret = gpio_direction_output(setup->pdda_pin, 1); |
| 101 | if (ret != 0) |
| 102 | goto gpio_err; |
| 103 | |
| 104 | return ret; |
| 105 | |
| 106 | gpio_err: |
| 107 | pcm3008_gpio_free(setup); |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 108 | |
| 109 | return ret; |
| 110 | } |
| 111 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 112 | static int pcm3008_soc_remove(struct snd_soc_codec *codec) |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 113 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 114 | struct pcm3008_setup_data *setup = codec->dev->platform_data; |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 115 | |
| 116 | pcm3008_gpio_free(setup); |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | #ifdef CONFIG_PM |
Lars-Peter Clausen | 84b315e | 2011-12-02 10:18:28 +0100 | [diff] [blame] | 121 | static int pcm3008_soc_suspend(struct snd_soc_codec *codec) |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 122 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 123 | struct pcm3008_setup_data *setup = codec->dev->platform_data; |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 124 | |
| 125 | gpio_set_value(setup->pdad_pin, 0); |
| 126 | gpio_set_value(setup->pdda_pin, 0); |
| 127 | |
| 128 | return 0; |
| 129 | } |
| 130 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 131 | static int pcm3008_soc_resume(struct snd_soc_codec *codec) |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 132 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 133 | struct pcm3008_setup_data *setup = codec->dev->platform_data; |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 134 | |
| 135 | gpio_set_value(setup->pdad_pin, 1); |
| 136 | gpio_set_value(setup->pdda_pin, 1); |
| 137 | |
| 138 | return 0; |
| 139 | } |
| 140 | #else |
| 141 | #define pcm3008_soc_suspend NULL |
| 142 | #define pcm3008_soc_resume NULL |
| 143 | #endif |
| 144 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 145 | static struct snd_soc_codec_driver soc_codec_dev_pcm3008 = { |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 146 | .probe = pcm3008_soc_probe, |
| 147 | .remove = pcm3008_soc_remove, |
| 148 | .suspend = pcm3008_soc_suspend, |
| 149 | .resume = pcm3008_soc_resume, |
| 150 | }; |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 151 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 152 | static int __devinit pcm3008_codec_probe(struct platform_device *pdev) |
Mark Brown | 64089b8 | 2008-12-08 19:17:58 +0000 | [diff] [blame] | 153 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 154 | return snd_soc_register_codec(&pdev->dev, |
| 155 | &soc_codec_dev_pcm3008, &pcm3008_dai, 1); |
Mark Brown | 64089b8 | 2008-12-08 19:17:58 +0000 | [diff] [blame] | 156 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 157 | |
| 158 | static int __devexit pcm3008_codec_remove(struct platform_device *pdev) |
| 159 | { |
| 160 | snd_soc_unregister_codec(&pdev->dev); |
| 161 | return 0; |
| 162 | } |
| 163 | |
| 164 | MODULE_ALIAS("platform:pcm3008-codec"); |
| 165 | |
| 166 | static struct platform_driver pcm3008_codec_driver = { |
| 167 | .probe = pcm3008_codec_probe, |
| 168 | .remove = __devexit_p(pcm3008_codec_remove), |
| 169 | .driver = { |
| 170 | .name = "pcm3008-codec", |
| 171 | .owner = THIS_MODULE, |
| 172 | }, |
| 173 | }; |
| 174 | |
Mark Brown | 5bbcc3c | 2011-11-23 22:52:08 +0000 | [diff] [blame] | 175 | module_platform_driver(pcm3008_codec_driver); |
Mark Brown | 64089b8 | 2008-12-08 19:17:58 +0000 | [diff] [blame] | 176 | |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 177 | MODULE_DESCRIPTION("Soc PCM3008 driver"); |
| 178 | MODULE_AUTHOR("Hugo Villeneuve"); |
| 179 | MODULE_LICENSE("GPL"); |