blob: 708af05486f634012da081f78421b676b21d1f7c [file] [log] [blame]
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -05001/*
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 Heo5a0e3ad2010-03-24 17:04:11 +090022#include <linux/slab.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040023#include <linux/module.h>
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -050024#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 Brown4fc932c2013-08-15 12:04:28 +010031static int pcm3008_dac_ev(struct snd_soc_dapm_widget *w,
32 struct snd_kcontrol *kcontrol,
33 int event)
34{
Lars-Peter Clausen0d760912015-01-15 12:52:02 +010035 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
Mark Brown4fc932c2013-08-15 12:04:28 +010036 struct pcm3008_setup_data *setup = codec->dev->platform_data;
37
38 gpio_set_value_cansleep(setup->pdda_pin,
39 SND_SOC_DAPM_EVENT_ON(event));
40
41 return 0;
42}
43
44static int pcm3008_adc_ev(struct snd_soc_dapm_widget *w,
45 struct snd_kcontrol *kcontrol,
46 int event)
47{
Lars-Peter Clausen0d760912015-01-15 12:52:02 +010048 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
Mark Brown4fc932c2013-08-15 12:04:28 +010049 struct pcm3008_setup_data *setup = codec->dev->platform_data;
50
51 gpio_set_value_cansleep(setup->pdad_pin,
52 SND_SOC_DAPM_EVENT_ON(event));
53
54 return 0;
55}
56
Mark Brownfaaf36f2013-08-15 12:01:40 +010057static const struct snd_soc_dapm_widget pcm3008_dapm_widgets[] = {
58SND_SOC_DAPM_INPUT("VINL"),
59SND_SOC_DAPM_INPUT("VINR"),
60
Mark Brown4fc932c2013-08-15 12:04:28 +010061SND_SOC_DAPM_DAC_E("DAC", NULL, SND_SOC_NOPM, 0, 0, pcm3008_dac_ev,
62 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
63SND_SOC_DAPM_ADC_E("ADC", NULL, SND_SOC_NOPM, 0, 0, pcm3008_adc_ev,
64 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
65
Mark Brownfaaf36f2013-08-15 12:01:40 +010066SND_SOC_DAPM_OUTPUT("VOUTL"),
67SND_SOC_DAPM_OUTPUT("VOUTR"),
68};
69
70static const struct snd_soc_dapm_route pcm3008_dapm_routes[] = {
Mark Brown4fc932c2013-08-15 12:04:28 +010071 { "PCM3008 Capture", NULL, "ADC" },
72 { "ADC", NULL, "VINL" },
73 { "ADC", NULL, "VINR" },
Mark Brownfaaf36f2013-08-15 12:01:40 +010074
Mark Brown4fc932c2013-08-15 12:04:28 +010075 { "DAC", NULL, "PCM3008 Playback" },
76 { "VOUTL", NULL, "DAC" },
77 { "VOUTR", NULL, "DAC" },
Mark Brownfaaf36f2013-08-15 12:01:40 +010078};
79
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -050080#define PCM3008_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
81 SNDRV_PCM_RATE_48000)
82
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000083static struct snd_soc_dai_driver pcm3008_dai = {
84 .name = "pcm3008-hifi",
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -050085 .playback = {
86 .stream_name = "PCM3008 Playback",
87 .channels_min = 1,
88 .channels_max = 2,
89 .rates = PCM3008_RATES,
90 .formats = SNDRV_PCM_FMTBIT_S16_LE,
91 },
92 .capture = {
93 .stream_name = "PCM3008 Capture",
94 .channels_min = 1,
95 .channels_max = 2,
96 .rates = PCM3008_RATES,
97 .formats = SNDRV_PCM_FMTBIT_S16_LE,
98 },
99};
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -0500100
Mark Brownd7f18492013-07-10 16:48:24 +0100101static struct snd_soc_codec_driver soc_codec_dev_pcm3008 = {
Kuninori Morimoto4cd747d2016-08-08 09:21:02 +0000102 .component_driver = {
103 .dapm_widgets = pcm3008_dapm_widgets,
104 .num_dapm_widgets = ARRAY_SIZE(pcm3008_dapm_widgets),
105 .dapm_routes = pcm3008_dapm_routes,
106 .num_dapm_routes = ARRAY_SIZE(pcm3008_dapm_routes),
107 },
Mark Brownd7f18492013-07-10 16:48:24 +0100108};
109
110static int pcm3008_codec_probe(struct platform_device *pdev)
111{
112 struct pcm3008_setup_data *setup = pdev->dev.platform_data;
113 int ret;
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -0500114
Mark Brown33319a22013-07-10 16:49:16 +0100115 if (!setup)
116 return -EINVAL;
117
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -0500118 /* DEM1 DEM0 DE-EMPHASIS_MODE
119 * Low Low De-emphasis 44.1 kHz ON
120 * Low High De-emphasis OFF
121 * High Low De-emphasis 48 kHz ON
122 * High High De-emphasis 32 kHz ON
123 */
124
125 /* Configure DEM0 GPIO (turning OFF DAC De-emphasis). */
Mark Brownd57a79a2013-07-10 16:53:55 +0100126 ret = devm_gpio_request_one(&pdev->dev, setup->dem0_pin,
127 GPIOF_OUT_INIT_HIGH, "codec_dem0");
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -0500128 if (ret != 0)
Mark Brownd57a79a2013-07-10 16:53:55 +0100129 return ret;
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -0500130
131 /* Configure DEM1 GPIO (turning OFF DAC De-emphasis). */
Mark Brownd57a79a2013-07-10 16:53:55 +0100132 ret = devm_gpio_request_one(&pdev->dev, setup->dem1_pin,
133 GPIOF_OUT_INIT_LOW, "codec_dem1");
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -0500134 if (ret != 0)
Mark Brownd57a79a2013-07-10 16:53:55 +0100135 return ret;
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -0500136
137 /* Configure PDAD GPIO. */
Mark Brownd57a79a2013-07-10 16:53:55 +0100138 ret = devm_gpio_request_one(&pdev->dev, setup->pdad_pin,
Mark Brown4fc932c2013-08-15 12:04:28 +0100139 GPIOF_OUT_INIT_LOW, "codec_pdad");
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -0500140 if (ret != 0)
Mark Brownd57a79a2013-07-10 16:53:55 +0100141 return ret;
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -0500142
143 /* Configure PDDA GPIO. */
Mark Brownd57a79a2013-07-10 16:53:55 +0100144 ret = devm_gpio_request_one(&pdev->dev, setup->pdda_pin,
Mark Brown4fc932c2013-08-15 12:04:28 +0100145 GPIOF_OUT_INIT_LOW, "codec_pdda");
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -0500146 if (ret != 0)
Mark Brownd57a79a2013-07-10 16:53:55 +0100147 return ret;
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -0500148
Mark Brownd7f18492013-07-10 16:48:24 +0100149 return snd_soc_register_codec(&pdev->dev,
150 &soc_codec_dev_pcm3008, &pcm3008_dai, 1);
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -0500151}
152
Bill Pemberton7a79e942012-12-07 09:26:37 -0500153static int pcm3008_codec_remove(struct platform_device *pdev)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000154{
155 snd_soc_unregister_codec(&pdev->dev);
Mark Brownd7f18492013-07-10 16:48:24 +0100156
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000157 return 0;
158}
159
160MODULE_ALIAS("platform:pcm3008-codec");
161
162static struct platform_driver pcm3008_codec_driver = {
163 .probe = pcm3008_codec_probe,
Bill Pemberton7a79e942012-12-07 09:26:37 -0500164 .remove = pcm3008_codec_remove,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000165 .driver = {
166 .name = "pcm3008-codec",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000167 },
168};
169
Mark Brown5bbcc3c2011-11-23 22:52:08 +0000170module_platform_driver(pcm3008_codec_driver);
Mark Brown64089b82008-12-08 19:17:58 +0000171
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -0500172MODULE_DESCRIPTION("Soc PCM3008 driver");
173MODULE_AUTHOR("Hugo Villeneuve");
174MODULE_LICENSE("GPL");