Linux Audio

Check our new training course

Loading...
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 * Driver for the 1250-EV1 audio I/O module
  4 *
  5 * Copyright 2011 Wolfson Microelectronics plc
 
 
 
 
 
 
  6 */
  7
  8#include <linux/init.h>
  9#include <linux/module.h>
 10#include <linux/slab.h>
 11#include <linux/i2c.h>
 12#include <linux/gpio/consumer.h>
 13
 14#include <sound/soc.h>
 15#include <sound/soc-dapm.h>
 16
 17struct wm1250_priv {
 18	struct gpio_desc *clk_ena;
 19	struct gpio_desc *clk_sel0;
 20	struct gpio_desc *clk_sel1;
 21	struct gpio_desc *osr;
 22	struct gpio_desc *master;
 23};
 24
 25static int wm1250_ev1_set_bias_level(struct snd_soc_component *component,
 26				     enum snd_soc_bias_level level)
 27{
 28	struct wm1250_priv *wm1250 = dev_get_drvdata(component->dev);
 29
 30	switch (level) {
 31	case SND_SOC_BIAS_ON:
 32		break;
 33
 34	case SND_SOC_BIAS_PREPARE:
 35		break;
 36
 37	case SND_SOC_BIAS_STANDBY:
 38		gpiod_set_value_cansleep(wm1250->clk_ena, 1);
 39		break;
 40
 41	case SND_SOC_BIAS_OFF:
 42		gpiod_set_value_cansleep(wm1250->clk_ena, 0);
 43		break;
 44	}
 45
 46	return 0;
 47}
 48
 49static const struct snd_soc_dapm_widget wm1250_ev1_dapm_widgets[] = {
 50SND_SOC_DAPM_ADC("ADC", "wm1250-ev1 Capture", SND_SOC_NOPM, 0, 0),
 51SND_SOC_DAPM_DAC("DAC", "wm1250-ev1 Playback", SND_SOC_NOPM, 0, 0),
 52
 53SND_SOC_DAPM_INPUT("WM1250 Input"),
 54SND_SOC_DAPM_OUTPUT("WM1250 Output"),
 55};
 56
 57static const struct snd_soc_dapm_route wm1250_ev1_dapm_routes[] = {
 58	{ "ADC", NULL, "WM1250 Input" },
 59	{ "WM1250 Output", NULL, "DAC" },
 60};
 61
 62static int wm1250_ev1_hw_params(struct snd_pcm_substream *substream,
 63				struct snd_pcm_hw_params *params,
 64				struct snd_soc_dai *dai)
 65{
 66	struct wm1250_priv *wm1250 = snd_soc_component_get_drvdata(dai->component);
 67
 68	switch (params_rate(params)) {
 69	case 8000:
 70		gpiod_set_value(wm1250->clk_sel0, 1);
 71		gpiod_set_value(wm1250->clk_sel1, 1);
 72		break;
 73	case 16000:
 74		gpiod_set_value(wm1250->clk_sel0, 0);
 75		gpiod_set_value(wm1250->clk_sel1, 1);
 76		break;
 77	case 32000:
 78		gpiod_set_value(wm1250->clk_sel0, 1);
 79		gpiod_set_value(wm1250->clk_sel1, 0);
 80		break;
 81	case 64000:
 82		gpiod_set_value(wm1250->clk_sel0, 0);
 83		gpiod_set_value(wm1250->clk_sel1, 0);
 84		break;
 85	default:
 86		return -EINVAL;
 87	}
 88
 89	return 0;
 90}
 91
 92static const struct snd_soc_dai_ops wm1250_ev1_ops = {
 93	.hw_params = wm1250_ev1_hw_params,
 94};
 95
 96#define WM1250_EV1_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
 97			  SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_64000)
 98
 99static struct snd_soc_dai_driver wm1250_ev1_dai = {
100	.name = "wm1250-ev1",
101	.playback = {
102		.stream_name = "Playback",
103		.channels_min = 1,
104		.channels_max = 2,
105		.rates = WM1250_EV1_RATES,
106		.formats = SNDRV_PCM_FMTBIT_S16_LE,
107	},
108	.capture = {
109		.stream_name = "Capture",
110		.channels_min = 1,
111		.channels_max = 2,
112		.rates = WM1250_EV1_RATES,
113		.formats = SNDRV_PCM_FMTBIT_S16_LE,
114	},
115	.ops = &wm1250_ev1_ops,
116};
117
118static const struct snd_soc_component_driver soc_component_dev_wm1250_ev1 = {
119	.dapm_widgets		= wm1250_ev1_dapm_widgets,
120	.num_dapm_widgets	= ARRAY_SIZE(wm1250_ev1_dapm_widgets),
121	.dapm_routes		= wm1250_ev1_dapm_routes,
122	.num_dapm_routes	= ARRAY_SIZE(wm1250_ev1_dapm_routes),
123	.set_bias_level		= wm1250_ev1_set_bias_level,
124	.use_pmdown_time	= 1,
125	.endianness		= 1,
126};
127
128static int wm1250_ev1_pdata(struct i2c_client *i2c)
 
129{
130	struct wm1250_ev1_pdata *pdata = dev_get_platdata(&i2c->dev);
131	struct wm1250_priv *wm1250;
132
133	if (!pdata)
134		return 0;
135
136	wm1250 = devm_kzalloc(&i2c->dev, sizeof(*wm1250), GFP_KERNEL);
137	if (!wm1250)
138		return -ENOMEM;
139
140	wm1250->clk_ena = devm_gpiod_get(&i2c->dev, "clk-ena", GPIOD_OUT_LOW);
141	if (IS_ERR(wm1250->clk_ena))
142		return dev_err_probe(&i2c->dev, PTR_ERR(wm1250->clk_ena),
143				     "failed to get clock enable GPIO\n");
144
145	wm1250->clk_sel0 = devm_gpiod_get(&i2c->dev, "clk-sel0", GPIOD_OUT_HIGH);
146	if (IS_ERR(wm1250->clk_sel0))
147		return dev_err_probe(&i2c->dev, PTR_ERR(wm1250->clk_sel0),
148				     "failed to get clock sel0 GPIO\n");
149
150	wm1250->clk_sel1 = devm_gpiod_get(&i2c->dev, "clk-sel1", GPIOD_OUT_HIGH);
151	if (IS_ERR(wm1250->clk_sel1))
152		return dev_err_probe(&i2c->dev, PTR_ERR(wm1250->clk_sel1),
153				     "failed to get clock sel1 GPIO\n");
154
155	wm1250->osr = devm_gpiod_get(&i2c->dev, "osr", GPIOD_OUT_LOW);
156	if (IS_ERR(wm1250->osr))
157		return dev_err_probe(&i2c->dev, PTR_ERR(wm1250->osr),
158				     "failed to get OSR GPIO\n");
159
160	wm1250->master = devm_gpiod_get(&i2c->dev, "master", GPIOD_OUT_LOW);
161	if (IS_ERR(wm1250->master))
162		return dev_err_probe(&i2c->dev, PTR_ERR(wm1250->master),
163				     "failed to get MASTER GPIO\n");
164
165	dev_set_drvdata(&i2c->dev, wm1250);
166
167	return 0;
168}
169
170static int wm1250_ev1_probe(struct i2c_client *i2c)
171{
172	int id, board, rev, ret;
173
174	dev_set_drvdata(&i2c->dev, NULL);
175
176	board = i2c_smbus_read_byte_data(i2c, 0);
177	if (board < 0) {
178		dev_err(&i2c->dev, "Failed to read ID: %d\n", board);
179		return board;
180	}
181
182	id = (board & 0xfe) >> 2;
183	rev = board & 0x3;
184
185	if (id != 1) {
186		dev_err(&i2c->dev, "Unknown board ID %d\n", id);
187		return -ENODEV;
188	}
189
190	dev_info(&i2c->dev, "revision %d\n", rev + 1);
191
192	ret = wm1250_ev1_pdata(i2c);
193	if (ret != 0)
194		return ret;
195
196	ret = devm_snd_soc_register_component(&i2c->dev, &soc_component_dev_wm1250_ev1,
197				     &wm1250_ev1_dai, 1);
198	if (ret != 0) {
199		dev_err(&i2c->dev, "Failed to register CODEC: %d\n", ret);
200		return ret;
201	}
202
203	return 0;
204}
205
206static const struct i2c_device_id wm1250_ev1_i2c_id[] = {
207	{ "wm1250-ev1" },
208	{ }
209};
210MODULE_DEVICE_TABLE(i2c, wm1250_ev1_i2c_id);
211
212static struct i2c_driver wm1250_ev1_i2c_driver = {
213	.driver = {
214		.name = "wm1250-ev1",
 
215	},
216	.probe =    wm1250_ev1_probe,
 
217	.id_table = wm1250_ev1_i2c_id,
218};
219
220module_i2c_driver(wm1250_ev1_i2c_driver);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
221
222MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
223MODULE_DESCRIPTION("WM1250-EV1 audio I/O module driver");
224MODULE_LICENSE("GPL");
v3.1
 
  1/*
  2 * Driver for the 1250-EV1 audio I/O module
  3 *
  4 * Copyright 2011 Wolfson Microelectronics plc
  5 *
  6 *  This program is free software; you can redistribute  it and/or modify it
  7 *  under  the terms of  the GNU General  Public License as published by the
  8 *  Free Software Foundation;  either version 2 of the  License, or (at your
  9 *  option) any later version.
 10 *
 11 */
 12
 13#include <linux/init.h>
 14#include <linux/module.h>
 
 15#include <linux/i2c.h>
 
 16
 17#include <sound/soc.h>
 18#include <sound/soc-dapm.h>
 19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 20static const struct snd_soc_dapm_widget wm1250_ev1_dapm_widgets[] = {
 21SND_SOC_DAPM_ADC("ADC", "wm1250-ev1 Capture", SND_SOC_NOPM, 0, 0),
 22SND_SOC_DAPM_DAC("DAC", "wm1250-ev1 Playback", SND_SOC_NOPM, 0, 0),
 23
 24SND_SOC_DAPM_INPUT("WM1250 Input"),
 25SND_SOC_DAPM_OUTPUT("WM1250 Output"),
 26};
 27
 28static const struct snd_soc_dapm_route wm1250_ev1_dapm_routes[] = {
 29	{ "ADC", NULL, "WM1250 Input" },
 30	{ "WM1250 Output", NULL, "DAC" },
 31};
 32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 33static struct snd_soc_dai_driver wm1250_ev1_dai = {
 34	.name = "wm1250-ev1",
 35	.playback = {
 36		.stream_name = "Playback",
 37		.channels_min = 1,
 38		.channels_max = 1,
 39		.rates = SNDRV_PCM_RATE_8000,
 40		.formats = SNDRV_PCM_FMTBIT_S16_LE,
 41	},
 42	.capture = {
 43		.stream_name = "Capture",
 44		.channels_min = 1,
 45		.channels_max = 1,
 46		.rates = SNDRV_PCM_RATE_8000,
 47		.formats = SNDRV_PCM_FMTBIT_S16_LE,
 48	},
 
 49};
 50
 51static struct snd_soc_codec_driver soc_codec_dev_wm1250_ev1 = {
 52	.dapm_widgets = wm1250_ev1_dapm_widgets,
 53	.num_dapm_widgets = ARRAY_SIZE(wm1250_ev1_dapm_widgets),
 54	.dapm_routes = wm1250_ev1_dapm_routes,
 55	.num_dapm_routes = ARRAY_SIZE(wm1250_ev1_dapm_routes),
 
 
 
 56};
 57
 58static int __devinit wm1250_ev1_probe(struct i2c_client *i2c,
 59				      const struct i2c_device_id *id)
 60{
 61	return snd_soc_register_codec(&i2c->dev, &soc_codec_dev_wm1250_ev1,
 62				      &wm1250_ev1_dai, 1);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 63}
 64
 65static int __devexit wm1250_ev1_remove(struct i2c_client *i2c)
 66{
 67	snd_soc_unregister_codec(&i2c->dev);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 68
 69	return 0;
 70}
 71
 72static const struct i2c_device_id wm1250_ev1_i2c_id[] = {
 73	{ "wm1250-ev1", 0 },
 74	{ }
 75};
 76MODULE_DEVICE_TABLE(i2c, wm1250_ev1_i2c_id);
 77
 78static struct i2c_driver wm1250_ev1_i2c_driver = {
 79	.driver = {
 80		.name = "wm1250-ev1",
 81		.owner = THIS_MODULE,
 82	},
 83	.probe =    wm1250_ev1_probe,
 84	.remove =   __devexit_p(wm1250_ev1_remove),
 85	.id_table = wm1250_ev1_i2c_id,
 86};
 87
 88static int __init wm1250_ev1_modinit(void)
 89{
 90	int ret = 0;
 91
 92	ret = i2c_add_driver(&wm1250_ev1_i2c_driver);
 93	if (ret != 0)
 94		pr_err("Failed to register WM1250-EV1 I2C driver: %d\n", ret);
 95
 96	return ret;
 97}
 98module_init(wm1250_ev1_modinit);
 99
100static void __exit wm1250_ev1_exit(void)
101{
102	i2c_del_driver(&wm1250_ev1_i2c_driver);
103}
104module_exit(wm1250_ev1_exit);
105
106MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
107MODULE_DESCRIPTION("WM1250-EV1 audio I/O module driver");
108MODULE_LICENSE("GPL");