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