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> |
| 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", |
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 | }; |
| 51 | EXPORT_SYMBOL_GPL(pcm3008_dai); |
| 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 | |
| 61 | static int pcm3008_soc_probe(struct platform_device *pdev) |
| 62 | { |
| 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; |
| 66 | int ret = 0; |
| 67 | |
| 68 | printk(KERN_INFO "PCM3008 SoC Audio Codec %s\n", PCM3008_VERSION); |
| 69 | |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 70 | socdev->card->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); |
| 71 | if (!socdev->card->codec) |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 72 | return -ENOMEM; |
| 73 | |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 74 | codec = socdev->card->codec; |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 75 | mutex_init(&codec->mutex); |
| 76 | |
| 77 | codec->name = "PCM3008"; |
| 78 | codec->owner = THIS_MODULE; |
| 79 | codec->dai = &pcm3008_dai; |
| 80 | codec->num_dai = 1; |
| 81 | codec->write = NULL; |
| 82 | codec->read = NULL; |
| 83 | INIT_LIST_HEAD(&codec->dapm_widgets); |
| 84 | INIT_LIST_HEAD(&codec->dapm_paths); |
| 85 | |
| 86 | /* Register PCMs. */ |
| 87 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); |
| 88 | if (ret < 0) { |
| 89 | printk(KERN_ERR "pcm3008: failed to create pcms\n"); |
| 90 | goto pcm_err; |
| 91 | } |
| 92 | |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 93 | /* DEM1 DEM0 DE-EMPHASIS_MODE |
| 94 | * Low Low De-emphasis 44.1 kHz ON |
| 95 | * Low High De-emphasis OFF |
| 96 | * High Low De-emphasis 48 kHz ON |
| 97 | * High High De-emphasis 32 kHz ON |
| 98 | */ |
| 99 | |
| 100 | /* Configure DEM0 GPIO (turning OFF DAC De-emphasis). */ |
| 101 | ret = gpio_request(setup->dem0_pin, "codec_dem0"); |
| 102 | if (ret == 0) |
| 103 | ret = gpio_direction_output(setup->dem0_pin, 1); |
| 104 | if (ret != 0) |
| 105 | goto gpio_err; |
| 106 | |
| 107 | /* Configure DEM1 GPIO (turning OFF DAC De-emphasis). */ |
| 108 | ret = gpio_request(setup->dem1_pin, "codec_dem1"); |
| 109 | if (ret == 0) |
| 110 | ret = gpio_direction_output(setup->dem1_pin, 0); |
| 111 | if (ret != 0) |
| 112 | goto gpio_err; |
| 113 | |
| 114 | /* Configure PDAD GPIO. */ |
| 115 | ret = gpio_request(setup->pdad_pin, "codec_pdad"); |
| 116 | if (ret == 0) |
| 117 | ret = gpio_direction_output(setup->pdad_pin, 1); |
| 118 | if (ret != 0) |
| 119 | goto gpio_err; |
| 120 | |
| 121 | /* Configure PDDA GPIO. */ |
| 122 | ret = gpio_request(setup->pdda_pin, "codec_pdda"); |
| 123 | if (ret == 0) |
| 124 | ret = gpio_direction_output(setup->pdda_pin, 1); |
| 125 | if (ret != 0) |
| 126 | goto gpio_err; |
| 127 | |
| 128 | return ret; |
| 129 | |
| 130 | gpio_err: |
| 131 | pcm3008_gpio_free(setup); |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 132 | pcm_err: |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 133 | kfree(socdev->card->codec); |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 134 | |
| 135 | return ret; |
| 136 | } |
| 137 | |
| 138 | static int pcm3008_soc_remove(struct platform_device *pdev) |
| 139 | { |
| 140 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 141 | struct snd_soc_codec *codec = socdev->card->codec; |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 142 | struct pcm3008_setup_data *setup = socdev->codec_data; |
| 143 | |
| 144 | if (!codec) |
| 145 | return 0; |
| 146 | |
| 147 | pcm3008_gpio_free(setup); |
| 148 | snd_soc_free_pcms(socdev); |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 149 | kfree(socdev->card->codec); |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 150 | |
| 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | #ifdef CONFIG_PM |
| 155 | static int pcm3008_soc_suspend(struct platform_device *pdev, pm_message_t msg) |
| 156 | { |
| 157 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
| 158 | struct pcm3008_setup_data *setup = socdev->codec_data; |
| 159 | |
| 160 | gpio_set_value(setup->pdad_pin, 0); |
| 161 | gpio_set_value(setup->pdda_pin, 0); |
| 162 | |
| 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | static int pcm3008_soc_resume(struct platform_device *pdev) |
| 167 | { |
| 168 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
| 169 | struct pcm3008_setup_data *setup = socdev->codec_data; |
| 170 | |
| 171 | gpio_set_value(setup->pdad_pin, 1); |
| 172 | gpio_set_value(setup->pdda_pin, 1); |
| 173 | |
| 174 | return 0; |
| 175 | } |
| 176 | #else |
| 177 | #define pcm3008_soc_suspend NULL |
| 178 | #define pcm3008_soc_resume NULL |
| 179 | #endif |
| 180 | |
| 181 | struct snd_soc_codec_device soc_codec_dev_pcm3008 = { |
| 182 | .probe = pcm3008_soc_probe, |
| 183 | .remove = pcm3008_soc_remove, |
| 184 | .suspend = pcm3008_soc_suspend, |
| 185 | .resume = pcm3008_soc_resume, |
| 186 | }; |
| 187 | EXPORT_SYMBOL_GPL(soc_codec_dev_pcm3008); |
| 188 | |
Takashi Iwai | c9b3a40 | 2008-12-10 07:47:22 +0100 | [diff] [blame] | 189 | static int __init pcm3008_init(void) |
Mark Brown | 64089b8 | 2008-12-08 19:17:58 +0000 | [diff] [blame] | 190 | { |
| 191 | return snd_soc_register_dai(&pcm3008_dai); |
| 192 | } |
| 193 | module_init(pcm3008_init); |
| 194 | |
| 195 | static void __exit pcm3008_exit(void) |
| 196 | { |
| 197 | snd_soc_unregister_dai(&pcm3008_dai); |
| 198 | } |
| 199 | module_exit(pcm3008_exit); |
| 200 | |
Hugo Villeneuve | 1c0090c | 2008-11-19 01:37:31 -0500 | [diff] [blame] | 201 | MODULE_DESCRIPTION("Soc PCM3008 driver"); |
| 202 | MODULE_AUTHOR("Hugo Villeneuve"); |
| 203 | MODULE_LICENSE("GPL"); |