2 * Driver for the 1250-EV1 audio I/O module
4 * Copyright 2011 Wolfson Microelectronics plc
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.
13 #include <linux/init.h>
14 #include <linux/module.h>
15 #include <linux/slab.h>
16 #include <linux/i2c.h>
17 #include <linux/gpio.h>
19 #include <sound/soc.h>
20 #include <sound/soc-dapm.h>
21 #include <sound/wm1250-ev1.h>
23 static const char *wm1250_gpio_names[WM1250_EV1_NUM_GPIOS] = {
32 struct gpio gpios[WM1250_EV1_NUM_GPIOS];
35 static int wm1250_ev1_set_bias_level(struct snd_soc_codec *codec,
36 enum snd_soc_bias_level level)
38 struct wm1250_priv *wm1250 = dev_get_drvdata(codec->dev);
42 ena = wm1250->gpios[WM1250_EV1_GPIO_CLK_ENA].gpio;
50 case SND_SOC_BIAS_PREPARE:
53 case SND_SOC_BIAS_STANDBY:
55 gpio_set_value_cansleep(ena, 1);
58 case SND_SOC_BIAS_OFF:
60 gpio_set_value_cansleep(ena, 0);
64 codec->dapm.bias_level = level;
69 static const struct snd_soc_dapm_widget wm1250_ev1_dapm_widgets[] = {
70 SND_SOC_DAPM_ADC("ADC", "wm1250-ev1 Capture", SND_SOC_NOPM, 0, 0),
71 SND_SOC_DAPM_DAC("DAC", "wm1250-ev1 Playback", SND_SOC_NOPM, 0, 0),
73 SND_SOC_DAPM_INPUT("WM1250 Input"),
74 SND_SOC_DAPM_OUTPUT("WM1250 Output"),
77 static const struct snd_soc_dapm_route wm1250_ev1_dapm_routes[] = {
78 { "ADC", NULL, "WM1250 Input" },
79 { "WM1250 Output", NULL, "DAC" },
82 static struct snd_soc_dai_driver wm1250_ev1_dai = {
85 .stream_name = "Playback",
88 .rates = SNDRV_PCM_RATE_8000,
89 .formats = SNDRV_PCM_FMTBIT_S16_LE,
92 .stream_name = "Capture",
95 .rates = SNDRV_PCM_RATE_8000,
96 .formats = SNDRV_PCM_FMTBIT_S16_LE,
100 static struct snd_soc_codec_driver soc_codec_dev_wm1250_ev1 = {
101 .dapm_widgets = wm1250_ev1_dapm_widgets,
102 .num_dapm_widgets = ARRAY_SIZE(wm1250_ev1_dapm_widgets),
103 .dapm_routes = wm1250_ev1_dapm_routes,
104 .num_dapm_routes = ARRAY_SIZE(wm1250_ev1_dapm_routes),
106 .set_bias_level = wm1250_ev1_set_bias_level,
107 .idle_bias_off = true,
110 static int __devinit wm1250_ev1_pdata(struct i2c_client *i2c)
112 struct wm1250_ev1_pdata *pdata = dev_get_platdata(&i2c->dev);
113 struct wm1250_priv *wm1250;
119 wm1250 = kzalloc(sizeof(*wm1250), GFP_KERNEL);
121 dev_err(&i2c->dev, "Unable to allocate private data\n");
126 for (i = 0; i < ARRAY_SIZE(wm1250->gpios); i++) {
127 wm1250->gpios[i].gpio = pdata->gpios[i];
128 wm1250->gpios[i].label = wm1250_gpio_names[i];
129 wm1250->gpios[i].flags = GPIOF_OUT_INIT_LOW;
131 wm1250->gpios[WM1250_EV1_GPIO_CLK_SEL0].flags = GPIOF_OUT_INIT_HIGH;
132 wm1250->gpios[WM1250_EV1_GPIO_CLK_SEL1].flags = GPIOF_OUT_INIT_HIGH;
134 ret = gpio_request_array(wm1250->gpios, ARRAY_SIZE(wm1250->gpios));
136 dev_err(&i2c->dev, "Failed to get GPIOs: %d\n", ret);
140 dev_set_drvdata(&i2c->dev, wm1250);
150 static void wm1250_ev1_free(struct i2c_client *i2c)
152 struct wm1250_priv *wm1250 = dev_get_drvdata(&i2c->dev);
155 gpio_free_array(wm1250->gpios, ARRAY_SIZE(wm1250->gpios));
160 static int __devinit wm1250_ev1_probe(struct i2c_client *i2c,
161 const struct i2c_device_id *i2c_id)
163 int id, board, rev, ret;
165 dev_set_drvdata(&i2c->dev, NULL);
167 board = i2c_smbus_read_byte_data(i2c, 0);
169 dev_err(&i2c->dev, "Failed to read ID: %d\n", board);
173 id = (board & 0xfe) >> 2;
177 dev_err(&i2c->dev, "Unknown board ID %d\n", id);
181 dev_info(&i2c->dev, "revision %d\n", rev + 1);
183 ret = wm1250_ev1_pdata(i2c);
187 ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_wm1250_ev1,
190 dev_err(&i2c->dev, "Failed to register CODEC: %d\n", ret);
191 wm1250_ev1_free(i2c);
198 static int __devexit wm1250_ev1_remove(struct i2c_client *i2c)
200 snd_soc_unregister_codec(&i2c->dev);
201 wm1250_ev1_free(i2c);
206 static const struct i2c_device_id wm1250_ev1_i2c_id[] = {
210 MODULE_DEVICE_TABLE(i2c, wm1250_ev1_i2c_id);
212 static struct i2c_driver wm1250_ev1_i2c_driver = {
214 .name = "wm1250-ev1",
215 .owner = THIS_MODULE,
217 .probe = wm1250_ev1_probe,
218 .remove = __devexit_p(wm1250_ev1_remove),
219 .id_table = wm1250_ev1_i2c_id,
222 static int __init wm1250_ev1_modinit(void)
226 ret = i2c_add_driver(&wm1250_ev1_i2c_driver);
228 pr_err("Failed to register WM1250-EV1 I2C driver: %d\n", ret);
232 module_init(wm1250_ev1_modinit);
234 static void __exit wm1250_ev1_exit(void)
236 i2c_del_driver(&wm1250_ev1_i2c_driver);
238 module_exit(wm1250_ev1_exit);
240 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
241 MODULE_DESCRIPTION("WM1250-EV1 audio I/O module driver");
242 MODULE_LICENSE("GPL");