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