blob: bbcf9ec34759edba6629c64cc1f6e35885a2cab3 [file] [log] [blame]
Mark Brown4bb3f432011-04-08 16:49:42 +09001/*
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"),
Axel Lin979f4862011-05-26 10:54:12 +080025SND_SOC_DAPM_OUTPUT("WM1250 Output"),
Mark Brown4bb3f432011-04-08 16:49:42 +090026};
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,
Mark Browneaefb382011-07-29 16:27:18 +010059 const struct i2c_device_id *i2c_id)
Mark Brown4bb3f432011-04-08 16:49:42 +090060{
Mark Browneaefb382011-07-29 16:27:18 +010061 int ret, id, board, rev;
62
63 board = i2c_smbus_read_byte_data(i2c, 0);
64 if (board < 0) {
65 dev_err(&i2c->dev, "Failed to read ID: %d\n", ret);
66 return ret;
67 }
68
69 id = (board & 0xfe) >> 2;
70 rev = board & 0x3;
71
72 if (id != 1) {
73 dev_err(&i2c->dev, "Unknown board ID %d\n", id);
74 return -ENODEV;
75 }
76
77 dev_info(&i2c->dev, "revision %d\n", rev);
78
Mark Brown4bb3f432011-04-08 16:49:42 +090079 return snd_soc_register_codec(&i2c->dev, &soc_codec_dev_wm1250_ev1,
80 &wm1250_ev1_dai, 1);
81}
82
83static int __devexit wm1250_ev1_remove(struct i2c_client *i2c)
84{
85 snd_soc_unregister_codec(&i2c->dev);
86
87 return 0;
88}
89
90static const struct i2c_device_id wm1250_ev1_i2c_id[] = {
91 { "wm1250-ev1", 0 },
92 { }
93};
Mark Brown420dd712011-04-11 21:40:29 -070094MODULE_DEVICE_TABLE(i2c, wm1250_ev1_i2c_id);
Mark Brown4bb3f432011-04-08 16:49:42 +090095
96static struct i2c_driver wm1250_ev1_i2c_driver = {
97 .driver = {
98 .name = "wm1250-ev1",
99 .owner = THIS_MODULE,
100 },
101 .probe = wm1250_ev1_probe,
102 .remove = __devexit_p(wm1250_ev1_remove),
103 .id_table = wm1250_ev1_i2c_id,
104};
105
106static int __init wm1250_ev1_modinit(void)
107{
108 int ret = 0;
109
110 ret = i2c_add_driver(&wm1250_ev1_i2c_driver);
111 if (ret != 0)
112 pr_err("Failed to register WM1250-EV1 I2C driver: %d\n", ret);
113
114 return ret;
115}
116module_init(wm1250_ev1_modinit);
117
118static void __exit wm1250_ev1_exit(void)
119{
120 i2c_del_driver(&wm1250_ev1_i2c_driver);
121}
122module_exit(wm1250_ev1_exit);
123
124MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
125MODULE_DESCRIPTION("WM1250-EV1 audio I/O module driver");
126MODULE_LICENSE("GPL");