blob: aef40ec40aa16b640295454c98d3f4d2fc7d8ca5 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -05002/*
3 * ALSA Soc PCM3008 codec support
4 *
5 * Author: Hugo Villeneuve
6 * Copyright (C) 2008 Lyrtech inc
7 *
8 * Based on AC97 Soc codec, original copyright follow:
9 * Copyright 2005 Wolfson Microelectronics PLC.
10 *
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -050011 * Generic PCM3008 support.
12 */
13
14#include <linux/init.h>
15#include <linux/kernel.h>
16#include <linux/device.h>
17#include <linux/gpio.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090018#include <linux/slab.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040019#include <linux/module.h>
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -050020#include <sound/core.h>
21#include <sound/pcm.h>
22#include <sound/initval.h>
23#include <sound/soc.h>
24
25#include "pcm3008.h"
26
Mark Brown4fc932c2013-08-15 12:04:28 +010027static int pcm3008_dac_ev(struct snd_soc_dapm_widget *w,
28 struct snd_kcontrol *kcontrol,
29 int event)
30{
Kuninori Morimotod66827d2018-01-29 04:17:53 +000031 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
32 struct pcm3008_setup_data *setup = component->dev->platform_data;
Mark Brown4fc932c2013-08-15 12:04:28 +010033
34 gpio_set_value_cansleep(setup->pdda_pin,
35 SND_SOC_DAPM_EVENT_ON(event));
36
37 return 0;
38}
39
40static int pcm3008_adc_ev(struct snd_soc_dapm_widget *w,
41 struct snd_kcontrol *kcontrol,
42 int event)
43{
Kuninori Morimotod66827d2018-01-29 04:17:53 +000044 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
45 struct pcm3008_setup_data *setup = component->dev->platform_data;
Mark Brown4fc932c2013-08-15 12:04:28 +010046
47 gpio_set_value_cansleep(setup->pdad_pin,
48 SND_SOC_DAPM_EVENT_ON(event));
49
50 return 0;
51}
52
Mark Brownfaaf36f2013-08-15 12:01:40 +010053static const struct snd_soc_dapm_widget pcm3008_dapm_widgets[] = {
54SND_SOC_DAPM_INPUT("VINL"),
55SND_SOC_DAPM_INPUT("VINR"),
56
Mark Brown4fc932c2013-08-15 12:04:28 +010057SND_SOC_DAPM_DAC_E("DAC", NULL, SND_SOC_NOPM, 0, 0, pcm3008_dac_ev,
58 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
59SND_SOC_DAPM_ADC_E("ADC", NULL, SND_SOC_NOPM, 0, 0, pcm3008_adc_ev,
60 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
61
Mark Brownfaaf36f2013-08-15 12:01:40 +010062SND_SOC_DAPM_OUTPUT("VOUTL"),
63SND_SOC_DAPM_OUTPUT("VOUTR"),
64};
65
66static const struct snd_soc_dapm_route pcm3008_dapm_routes[] = {
Mark Brown4fc932c2013-08-15 12:04:28 +010067 { "PCM3008 Capture", NULL, "ADC" },
68 { "ADC", NULL, "VINL" },
69 { "ADC", NULL, "VINR" },
Mark Brownfaaf36f2013-08-15 12:01:40 +010070
Mark Brown4fc932c2013-08-15 12:04:28 +010071 { "DAC", NULL, "PCM3008 Playback" },
72 { "VOUTL", NULL, "DAC" },
73 { "VOUTR", NULL, "DAC" },
Mark Brownfaaf36f2013-08-15 12:01:40 +010074};
75
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -050076#define PCM3008_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
77 SNDRV_PCM_RATE_48000)
78
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000079static struct snd_soc_dai_driver pcm3008_dai = {
80 .name = "pcm3008-hifi",
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -050081 .playback = {
82 .stream_name = "PCM3008 Playback",
83 .channels_min = 1,
84 .channels_max = 2,
85 .rates = PCM3008_RATES,
86 .formats = SNDRV_PCM_FMTBIT_S16_LE,
87 },
88 .capture = {
89 .stream_name = "PCM3008 Capture",
90 .channels_min = 1,
91 .channels_max = 2,
92 .rates = PCM3008_RATES,
93 .formats = SNDRV_PCM_FMTBIT_S16_LE,
94 },
95};
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -050096
Kuninori Morimotod66827d2018-01-29 04:17:53 +000097static const struct snd_soc_component_driver soc_component_dev_pcm3008 = {
98 .dapm_widgets = pcm3008_dapm_widgets,
99 .num_dapm_widgets = ARRAY_SIZE(pcm3008_dapm_widgets),
100 .dapm_routes = pcm3008_dapm_routes,
101 .num_dapm_routes = ARRAY_SIZE(pcm3008_dapm_routes),
102 .idle_bias_on = 1,
103 .use_pmdown_time = 1,
104 .endianness = 1,
105 .non_legacy_dai_naming = 1,
Mark Brownd7f18492013-07-10 16:48:24 +0100106};
107
108static int pcm3008_codec_probe(struct platform_device *pdev)
109{
110 struct pcm3008_setup_data *setup = pdev->dev.platform_data;
111 int ret;
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -0500112
Mark Brown33319a22013-07-10 16:49:16 +0100113 if (!setup)
114 return -EINVAL;
115
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -0500116 /* DEM1 DEM0 DE-EMPHASIS_MODE
117 * Low Low De-emphasis 44.1 kHz ON
118 * Low High De-emphasis OFF
119 * High Low De-emphasis 48 kHz ON
120 * High High De-emphasis 32 kHz ON
121 */
122
123 /* Configure DEM0 GPIO (turning OFF DAC De-emphasis). */
Mark Brownd57a79a2013-07-10 16:53:55 +0100124 ret = devm_gpio_request_one(&pdev->dev, setup->dem0_pin,
125 GPIOF_OUT_INIT_HIGH, "codec_dem0");
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -0500126 if (ret != 0)
Mark Brownd57a79a2013-07-10 16:53:55 +0100127 return ret;
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -0500128
129 /* Configure DEM1 GPIO (turning OFF DAC De-emphasis). */
Mark Brownd57a79a2013-07-10 16:53:55 +0100130 ret = devm_gpio_request_one(&pdev->dev, setup->dem1_pin,
131 GPIOF_OUT_INIT_LOW, "codec_dem1");
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -0500132 if (ret != 0)
Mark Brownd57a79a2013-07-10 16:53:55 +0100133 return ret;
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -0500134
135 /* Configure PDAD GPIO. */
Mark Brownd57a79a2013-07-10 16:53:55 +0100136 ret = devm_gpio_request_one(&pdev->dev, setup->pdad_pin,
Mark Brown4fc932c2013-08-15 12:04:28 +0100137 GPIOF_OUT_INIT_LOW, "codec_pdad");
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -0500138 if (ret != 0)
Mark Brownd57a79a2013-07-10 16:53:55 +0100139 return ret;
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -0500140
141 /* Configure PDDA GPIO. */
Mark Brownd57a79a2013-07-10 16:53:55 +0100142 ret = devm_gpio_request_one(&pdev->dev, setup->pdda_pin,
Mark Brown4fc932c2013-08-15 12:04:28 +0100143 GPIOF_OUT_INIT_LOW, "codec_pdda");
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -0500144 if (ret != 0)
Mark Brownd57a79a2013-07-10 16:53:55 +0100145 return ret;
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -0500146
Kuninori Morimotod66827d2018-01-29 04:17:53 +0000147 return devm_snd_soc_register_component(&pdev->dev,
148 &soc_component_dev_pcm3008, &pcm3008_dai, 1);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000149}
150
151MODULE_ALIAS("platform:pcm3008-codec");
152
153static struct platform_driver pcm3008_codec_driver = {
154 .probe = pcm3008_codec_probe,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000155 .driver = {
156 .name = "pcm3008-codec",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000157 },
158};
159
Mark Brown5bbcc3c2011-11-23 22:52:08 +0000160module_platform_driver(pcm3008_codec_driver);
Mark Brown64089b82008-12-08 19:17:58 +0000161
Hugo Villeneuve1c0090c2008-11-19 01:37:31 -0500162MODULE_DESCRIPTION("Soc PCM3008 driver");
163MODULE_AUTHOR("Hugo Villeneuve");
164MODULE_LICENSE("GPL");