Linux Audio

Check our new training course

Loading...
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 * sound/soc/codecs/wm8782.c
  4 * simple, strap-pin configured 24bit 2ch ADC
  5 *
  6 * Copyright: 2011 Raumfeld GmbH
  7 * Author: Johannes Stezenbach <js@sig21.net>
  8 *
  9 * based on ad73311.c
 10 * Copyright:	Analog Devices Inc.
 11 * Author:	Cliff Cai <cliff.cai@analog.com>
 
 
 
 
 
 12 */
 13
 14#include <linux/init.h>
 15#include <linux/slab.h>
 16#include <linux/module.h>
 17#include <linux/kernel.h>
 18#include <linux/device.h>
 19#include <linux/regulator/consumer.h>
 20#include <sound/core.h>
 21#include <sound/pcm.h>
 22#include <sound/ac97_codec.h>
 23#include <sound/initval.h>
 24#include <sound/soc.h>
 25
 26/* regulator power supply names */
 27static const char *supply_names[] = {
 28	"Vdda", /* analog supply, 2.7V - 3.6V */
 29	"Vdd",  /* digital supply, 2.7V - 5.5V */
 30};
 31
 32struct wm8782_priv {
 33	struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)];
 34	int max_rate;
 35};
 36
 37static int wm8782_dai_startup(struct snd_pcm_substream *sub, struct snd_soc_dai *dai)
 38{
 39	struct snd_pcm_runtime *runtime = sub->runtime;
 40	struct wm8782_priv *priv =
 41		snd_soc_component_get_drvdata(dai->component);
 42
 43	return snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_RATE,
 44					   8000, priv->max_rate);
 45}
 46
 47static const struct snd_soc_dapm_widget wm8782_dapm_widgets[] = {
 48SND_SOC_DAPM_INPUT("AINL"),
 49SND_SOC_DAPM_INPUT("AINR"),
 50};
 51
 52static const struct snd_soc_dapm_route wm8782_dapm_routes[] = {
 53	{ "Capture", NULL, "AINL" },
 54	{ "Capture", NULL, "AINR" },
 55};
 56
 57static const struct snd_soc_dai_ops wm8782_dai_ops = {
 58	.startup = &wm8782_dai_startup,
 59};
 60
 61static struct snd_soc_dai_driver wm8782_dai = {
 62	.name = "wm8782",
 63	.capture = {
 64		.stream_name = "Capture",
 65		.channels_min = 2,
 66		.channels_max = 2,
 67		.rates = SNDRV_PCM_RATE_8000_192000,
 
 68		.formats = SNDRV_PCM_FMTBIT_S16_LE |
 69			   SNDRV_PCM_FMTBIT_S20_3LE |
 70			   SNDRV_PCM_FMTBIT_S24_LE,
 71	},
 72	.ops = &wm8782_dai_ops,
 73};
 74
 75static int wm8782_soc_probe(struct snd_soc_component *component)
 76{
 77	struct wm8782_priv *priv = snd_soc_component_get_drvdata(component);
 78	return regulator_bulk_enable(ARRAY_SIZE(priv->supplies), priv->supplies);
 79}
 
 
 
 80
 81static void wm8782_soc_remove(struct snd_soc_component *component)
 82{
 83	struct wm8782_priv *priv = snd_soc_component_get_drvdata(component);
 84	regulator_bulk_disable(ARRAY_SIZE(priv->supplies), priv->supplies);
 85}
 86
 87#ifdef CONFIG_PM
 88static int wm8782_soc_suspend(struct snd_soc_component *component)
 89{
 90	struct wm8782_priv *priv = snd_soc_component_get_drvdata(component);
 91	regulator_bulk_disable(ARRAY_SIZE(priv->supplies), priv->supplies);
 92	return 0;
 93}
 94
 95static int wm8782_soc_resume(struct snd_soc_component *component)
 96{
 97	struct wm8782_priv *priv = snd_soc_component_get_drvdata(component);
 98	return regulator_bulk_enable(ARRAY_SIZE(priv->supplies), priv->supplies);
 99}
100#else
101#define wm8782_soc_suspend      NULL
102#define wm8782_soc_resume       NULL
103#endif /* CONFIG_PM */
104
105static const struct snd_soc_component_driver soc_component_dev_wm8782 = {
106	.probe			= wm8782_soc_probe,
107	.remove			= wm8782_soc_remove,
108	.suspend		= wm8782_soc_suspend,
109	.resume			= wm8782_soc_resume,
110	.dapm_widgets		= wm8782_dapm_widgets,
111	.num_dapm_widgets	= ARRAY_SIZE(wm8782_dapm_widgets),
112	.dapm_routes		= wm8782_dapm_routes,
113	.num_dapm_routes	= ARRAY_SIZE(wm8782_dapm_routes),
114	.idle_bias_on		= 1,
115	.use_pmdown_time	= 1,
116	.endianness		= 1,
117};
118
119static int wm8782_probe(struct platform_device *pdev)
120{
121	struct device *dev = &pdev->dev;
122	struct device_node *np = dev->of_node;
123	struct wm8782_priv *priv;
124	int ret, i, fsampen;
125
126	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
127	if (!priv)
128		return -ENOMEM;
129
130	dev_set_drvdata(dev, priv);
131
132	for (i = 0; i < ARRAY_SIZE(supply_names); i++)
133		priv->supplies[i].supply = supply_names[i];
134
135	ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(priv->supplies),
136				      priv->supplies);
137	if (ret < 0)
138		return ret;
139
140	// Assume lowest value by default to avoid inadvertent overclocking
141	fsampen = 0;
142
143	if (np)
144		of_property_read_u32(np, "wlf,fsampen", &fsampen);
145
146	switch (fsampen) {
147	case 0:
148		priv->max_rate = 48000;
149		break;
150	case 1:
151		priv->max_rate = 96000;
152		break;
153	case 2:
154		priv->max_rate = 192000;
155		break;
156	default:
157		dev_err(dev, "Invalid wlf,fsampen value");
158		return -EINVAL;
159	}
160
161	return devm_snd_soc_register_component(&pdev->dev,
162			&soc_component_dev_wm8782, &wm8782_dai, 1);
163}
164
165#ifdef CONFIG_OF
166static const struct of_device_id wm8782_of_match[] = {
167	{ .compatible = "wlf,wm8782", },
168	{ }
169};
170MODULE_DEVICE_TABLE(of, wm8782_of_match);
171#endif
172
173static struct platform_driver wm8782_codec_driver = {
174	.driver = {
175		.name = "wm8782",
176		.of_match_table = of_match_ptr(wm8782_of_match),
177	},
178	.probe = wm8782_probe,
 
179};
180
181module_platform_driver(wm8782_codec_driver);
182
183MODULE_DESCRIPTION("ASoC WM8782 driver");
184MODULE_AUTHOR("Johannes Stezenbach <js@sig21.net>");
185MODULE_LICENSE("GPL");
v4.10.11
 
 1/*
 2 * sound/soc/codecs/wm8782.c
 3 * simple, strap-pin configured 24bit 2ch ADC
 4 *
 5 * Copyright: 2011 Raumfeld GmbH
 6 * Author: Johannes Stezenbach <js@sig21.net>
 7 *
 8 * based on ad73311.c
 9 * Copyright:	Analog Device Inc.
10 * Author:	Cliff Cai <cliff.cai@analog.com>
11 *
12 * This program is free software; you can redistribute  it and/or modify it
13 * under  the terms of  the GNU General  Public License as published by the
14 * Free Software Foundation;  either version 2 of the  License, or (at your
15 * option) any later version.
16 */
17
18#include <linux/init.h>
19#include <linux/slab.h>
20#include <linux/module.h>
21#include <linux/kernel.h>
22#include <linux/device.h>
 
23#include <sound/core.h>
24#include <sound/pcm.h>
25#include <sound/ac97_codec.h>
26#include <sound/initval.h>
27#include <sound/soc.h>
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29static const struct snd_soc_dapm_widget wm8782_dapm_widgets[] = {
30SND_SOC_DAPM_INPUT("AINL"),
31SND_SOC_DAPM_INPUT("AINR"),
32};
33
34static const struct snd_soc_dapm_route wm8782_dapm_routes[] = {
35	{ "Capture", NULL, "AINL" },
36	{ "Capture", NULL, "AINR" },
37};
38
 
 
 
 
39static struct snd_soc_dai_driver wm8782_dai = {
40	.name = "wm8782",
41	.capture = {
42		.stream_name = "Capture",
43		.channels_min = 2,
44		.channels_max = 2,
45		/* For configurations with FSAMPEN=0 */
46		.rates = SNDRV_PCM_RATE_8000_48000,
47		.formats = SNDRV_PCM_FMTBIT_S16_LE |
48			   SNDRV_PCM_FMTBIT_S20_3LE |
49			   SNDRV_PCM_FMTBIT_S24_LE,
50	},
 
51};
52
53static const struct snd_soc_codec_driver soc_codec_dev_wm8782 = {
54	.component_driver = {
55		.dapm_widgets		= wm8782_dapm_widgets,
56		.num_dapm_widgets	= ARRAY_SIZE(wm8782_dapm_widgets),
57		.dapm_routes		= wm8782_dapm_routes,
58		.num_dapm_routes	= ARRAY_SIZE(wm8782_dapm_routes),
59	},
60};
61
62static int wm8782_probe(struct platform_device *pdev)
63{
64	return snd_soc_register_codec(&pdev->dev,
65			&soc_codec_dev_wm8782, &wm8782_dai, 1);
66}
67
68static int wm8782_remove(struct platform_device *pdev)
 
69{
70	snd_soc_unregister_codec(&pdev->dev);
 
71	return 0;
72}
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74static struct platform_driver wm8782_codec_driver = {
75	.driver = {
76		.name = "wm8782",
 
77	},
78	.probe = wm8782_probe,
79	.remove = wm8782_remove,
80};
81
82module_platform_driver(wm8782_codec_driver);
83
84MODULE_DESCRIPTION("ASoC WM8782 driver");
85MODULE_AUTHOR("Johannes Stezenbach <js@sig21.net>");
86MODULE_LICENSE("GPL");