Linux Audio

Check our new training course

Loading...
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  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 *
 
 
 
 
 
 11 * 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>
 18#include <linux/slab.h>
 19#include <linux/module.h>
 20#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
 27static int pcm3008_dac_ev(struct snd_soc_dapm_widget *w,
 28			  struct snd_kcontrol *kcontrol,
 29			  int event)
 30{
 31	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
 32	struct pcm3008_setup_data *setup = component->dev->platform_data;
 33
 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{
 44	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
 45	struct pcm3008_setup_data *setup = component->dev->platform_data;
 46
 47	gpio_set_value_cansleep(setup->pdad_pin,
 48				SND_SOC_DAPM_EVENT_ON(event));
 49
 50	return 0;
 51}
 52
 53static const struct snd_soc_dapm_widget pcm3008_dapm_widgets[] = {
 54SND_SOC_DAPM_INPUT("VINL"),
 55SND_SOC_DAPM_INPUT("VINR"),
 56
 57SND_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
 62SND_SOC_DAPM_OUTPUT("VOUTL"),
 63SND_SOC_DAPM_OUTPUT("VOUTR"),
 64};
 65
 66static const struct snd_soc_dapm_route pcm3008_dapm_routes[] = {
 67	{ "PCM3008 Capture", NULL, "ADC" },
 68	{ "ADC", NULL, "VINL" },
 69	{ "ADC", NULL, "VINR" },
 70
 71	{ "DAC", NULL, "PCM3008 Playback" },
 72	{ "VOUTL", NULL, "DAC" },
 73	{ "VOUTR", NULL, "DAC" },
 74};
 75
 76#define PCM3008_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |	\
 77		       SNDRV_PCM_RATE_48000)
 78
 79static struct snd_soc_dai_driver pcm3008_dai = {
 80	.name = "pcm3008-hifi",
 81	.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};
 96
 97static 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};
106
107static int pcm3008_codec_probe(struct platform_device *pdev)
108{
109	struct pcm3008_setup_data *setup = pdev->dev.platform_data;
110	int ret;
111
112	if (!setup)
113		return -EINVAL;
114
115	/* DEM1  DEM0  DE-EMPHASIS_MODE
116	 * Low   Low   De-emphasis 44.1 kHz ON
117	 * Low   High  De-emphasis OFF
118	 * High  Low   De-emphasis 48 kHz ON
119	 * High  High  De-emphasis 32 kHz ON
120	 */
121
122	/* Configure DEM0 GPIO (turning OFF DAC De-emphasis). */
123	ret = devm_gpio_request_one(&pdev->dev, setup->dem0_pin,
124				    GPIOF_OUT_INIT_HIGH, "codec_dem0");
125	if (ret != 0)
126		return ret;
127
128	/* Configure DEM1 GPIO (turning OFF DAC De-emphasis). */
129	ret = devm_gpio_request_one(&pdev->dev, setup->dem1_pin,
130				    GPIOF_OUT_INIT_LOW, "codec_dem1");
131	if (ret != 0)
132		return ret;
133
134	/* Configure PDAD GPIO. */
135	ret = devm_gpio_request_one(&pdev->dev, setup->pdad_pin,
136				    GPIOF_OUT_INIT_LOW, "codec_pdad");
137	if (ret != 0)
138		return ret;
139
140	/* Configure PDDA GPIO. */
141	ret = devm_gpio_request_one(&pdev->dev, setup->pdda_pin,
142				    GPIOF_OUT_INIT_LOW, "codec_pdda");
143	if (ret != 0)
144		return ret;
145
146	return devm_snd_soc_register_component(&pdev->dev,
147			&soc_component_dev_pcm3008, &pcm3008_dai, 1);
 
 
 
 
 
 
 
148}
149
150MODULE_ALIAS("platform:pcm3008-codec");
151
152static struct platform_driver pcm3008_codec_driver = {
153	.probe		= pcm3008_codec_probe,
 
154	.driver		= {
155		.name	= "pcm3008-codec",
156	},
157};
158
159module_platform_driver(pcm3008_codec_driver);
160
161MODULE_DESCRIPTION("Soc PCM3008 driver");
162MODULE_AUTHOR("Hugo Villeneuve");
163MODULE_LICENSE("GPL");
v4.10.11
 
  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 <linux/slab.h>
 23#include <linux/module.h>
 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
 31static int pcm3008_dac_ev(struct snd_soc_dapm_widget *w,
 32			  struct snd_kcontrol *kcontrol,
 33			  int event)
 34{
 35	struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
 36	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{
 48	struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
 49	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
 57static const struct snd_soc_dapm_widget pcm3008_dapm_widgets[] = {
 58SND_SOC_DAPM_INPUT("VINL"),
 59SND_SOC_DAPM_INPUT("VINR"),
 60
 61SND_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
 66SND_SOC_DAPM_OUTPUT("VOUTL"),
 67SND_SOC_DAPM_OUTPUT("VOUTR"),
 68};
 69
 70static const struct snd_soc_dapm_route pcm3008_dapm_routes[] = {
 71	{ "PCM3008 Capture", NULL, "ADC" },
 72	{ "ADC", NULL, "VINL" },
 73	{ "ADC", NULL, "VINR" },
 74
 75	{ "DAC", NULL, "PCM3008 Playback" },
 76	{ "VOUTL", NULL, "DAC" },
 77	{ "VOUTR", NULL, "DAC" },
 78};
 79
 80#define PCM3008_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |	\
 81		       SNDRV_PCM_RATE_48000)
 82
 83static struct snd_soc_dai_driver pcm3008_dai = {
 84	.name = "pcm3008-hifi",
 85	.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};
100
101static struct snd_soc_codec_driver soc_codec_dev_pcm3008 = {
102	.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	},
 
108};
109
110static int pcm3008_codec_probe(struct platform_device *pdev)
111{
112	struct pcm3008_setup_data *setup = pdev->dev.platform_data;
113	int ret;
114
115	if (!setup)
116		return -EINVAL;
117
118	/* 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). */
126	ret = devm_gpio_request_one(&pdev->dev, setup->dem0_pin,
127				    GPIOF_OUT_INIT_HIGH, "codec_dem0");
128	if (ret != 0)
129		return ret;
130
131	/* Configure DEM1 GPIO (turning OFF DAC De-emphasis). */
132	ret = devm_gpio_request_one(&pdev->dev, setup->dem1_pin,
133				    GPIOF_OUT_INIT_LOW, "codec_dem1");
134	if (ret != 0)
135		return ret;
136
137	/* Configure PDAD GPIO. */
138	ret = devm_gpio_request_one(&pdev->dev, setup->pdad_pin,
139				    GPIOF_OUT_INIT_LOW, "codec_pdad");
140	if (ret != 0)
141		return ret;
142
143	/* Configure PDDA GPIO. */
144	ret = devm_gpio_request_one(&pdev->dev, setup->pdda_pin,
145				    GPIOF_OUT_INIT_LOW, "codec_pdda");
146	if (ret != 0)
147		return ret;
148
149	return snd_soc_register_codec(&pdev->dev,
150			&soc_codec_dev_pcm3008, &pcm3008_dai, 1);
151}
152
153static int pcm3008_codec_remove(struct platform_device *pdev)
154{
155	snd_soc_unregister_codec(&pdev->dev);
156
157	return 0;
158}
159
160MODULE_ALIAS("platform:pcm3008-codec");
161
162static struct platform_driver pcm3008_codec_driver = {
163	.probe		= pcm3008_codec_probe,
164	.remove		= pcm3008_codec_remove,
165	.driver		= {
166		.name	= "pcm3008-codec",
167	},
168};
169
170module_platform_driver(pcm3008_codec_driver);
171
172MODULE_DESCRIPTION("Soc PCM3008 driver");
173MODULE_AUTHOR("Hugo Villeneuve");
174MODULE_LICENSE("GPL");