Merge branch 'samsung/board' into next/boards
[~shefty/rdma-dev.git] / arch / arm / mach-s3c64xx / mach-crag6410-module.c
1 /* Speyside modules for Cragganmore - board data probing
2  *
3  * Copyright 2011 Wolfson Microelectronics plc
4  *      Mark Brown <broonie@opensource.wolfsonmicro.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  */
10
11 #include <linux/export.h>
12 #include <linux/interrupt.h>
13 #include <linux/i2c.h>
14
15 #include <linux/mfd/wm831x/irq.h>
16 #include <linux/mfd/wm831x/gpio.h>
17 #include <linux/mfd/wm8994/pdata.h>
18
19 #include <sound/wm5100.h>
20 #include <sound/wm8996.h>
21 #include <sound/wm8962.h>
22 #include <sound/wm9081.h>
23
24 #include <mach/crag6410.h>
25
26 static struct wm5100_pdata wm5100_pdata = {
27         .ldo_ena = S3C64XX_GPN(7),
28         .irq_flags = IRQF_TRIGGER_HIGH,
29         .gpio_base = CODEC_GPIO_BASE,
30
31         .in_mode = {
32                 WM5100_IN_DIFF,
33                 WM5100_IN_DIFF,
34                 WM5100_IN_DIFF,
35                 WM5100_IN_SE,
36         },
37
38         .hp_pol = CODEC_GPIO_BASE + 3,
39         .jack_modes = {
40                 { WM5100_MICDET_MICBIAS3, 0, 0 },
41                 { WM5100_MICDET_MICBIAS2, 1, 1 },
42         },
43
44         .gpio_defaults = {
45                 0,
46                 0,
47                 0,
48                 0,
49                 0x2, /* IRQ: CMOS output */
50                 0x3, /* CLKOUT: CMOS output */
51         },
52 };
53
54 static struct wm8996_retune_mobile_config wm8996_retune[] = {
55         {
56                 .name = "Sub LPF",
57                 .rate = 48000,
58                 .regs = {
59                         0x6318, 0x6300, 0x1000, 0x0000, 0x0004, 0x2000, 0xF000,
60                         0x0000, 0x0004, 0x2000, 0xF000, 0x0000, 0x0004, 0x2000,
61                         0xF000, 0x0000, 0x0004, 0x1000, 0x0800, 0x4000
62                 },
63         },
64         {
65                 .name = "Sub HPF",
66                 .rate = 48000,
67                 .regs = {
68                         0x000A, 0x6300, 0x1000, 0x0000, 0x0004, 0x2000, 0xF000,
69                         0x0000, 0x0004, 0x2000, 0xF000, 0x0000, 0x0004, 0x2000,
70                         0xF000, 0x0000, 0x0004, 0x1000, 0x0800, 0x4000
71                 },
72         },
73 };
74
75 static struct wm8996_pdata wm8996_pdata __initdata = {
76         .ldo_ena = S3C64XX_GPN(7),
77         .gpio_base = CODEC_GPIO_BASE,
78         .micdet_def = 1,
79         .inl_mode = WM8996_DIFFERRENTIAL_1,
80         .inr_mode = WM8996_DIFFERRENTIAL_1,
81
82         .irq_flags = IRQF_TRIGGER_RISING,
83
84         .gpio_default = {
85                 0x8001, /* GPIO1 == ADCLRCLK1 */
86                 0x8001, /* GPIO2 == ADCLRCLK2, input due to CPU */
87                 0x0141, /* GPIO3 == HP_SEL */
88                 0x0002, /* GPIO4 == IRQ */
89                 0x020e, /* GPIO5 == CLKOUT */
90         },
91
92         .retune_mobile_cfgs = wm8996_retune,
93         .num_retune_mobile_cfgs = ARRAY_SIZE(wm8996_retune),
94 };
95
96 static struct wm8962_pdata wm8962_pdata __initdata = {
97         .gpio_init = {
98                 0,
99                 WM8962_GPIO_FN_OPCLK,
100                 WM8962_GPIO_FN_DMICCLK,
101                 0,
102                 0x8000 | WM8962_GPIO_FN_DMICDAT,
103                 WM8962_GPIO_FN_IRQ,    /* Open drain mode */
104         },
105 };
106
107 static struct wm9081_pdata wm9081_pdata __initdata = {
108         .irq_high = false,
109         .irq_cmos = false,
110 };
111
112 static const struct i2c_board_info wm1254_devs[] = {
113         { I2C_BOARD_INFO("wm8996", 0x1a),
114           .platform_data = &wm8996_pdata,
115           .irq = GLENFARCLAS_PMIC_IRQ_BASE + WM831X_IRQ_GPIO_2,
116         },
117         { I2C_BOARD_INFO("wm9081", 0x6c),
118           .platform_data = &wm9081_pdata, },
119 };
120
121 static const struct i2c_board_info wm1255_devs[] = {
122         { I2C_BOARD_INFO("wm5100", 0x1a),
123           .platform_data = &wm5100_pdata,
124           .irq = GLENFARCLAS_PMIC_IRQ_BASE + WM831X_IRQ_GPIO_2,
125         },
126         { I2C_BOARD_INFO("wm9081", 0x6c),
127           .platform_data = &wm9081_pdata, },
128 };
129
130 static const struct i2c_board_info wm1259_devs[] = {
131         { I2C_BOARD_INFO("wm8962", 0x1a),
132           .platform_data = &wm8962_pdata,
133           .irq = GLENFARCLAS_PMIC_IRQ_BASE + WM831X_IRQ_GPIO_2,
134         },
135 };
136
137 static struct wm8994_pdata wm8994_pdata = {
138         .gpio_base = CODEC_GPIO_BASE,
139         .gpio_defaults = {
140                 0x3,          /* IRQ out, active high, CMOS */
141         },
142         .irq_base = CODEC_IRQ_BASE,
143         .ldo = {
144                 { .supply = "WALLVDD" },
145                 { .supply = "WALLVDD" },
146         },
147 };
148
149 static const struct i2c_board_info wm1277_devs[] = {
150         { I2C_BOARD_INFO("wm8958", 0x1a),  /* WM8958 is the superset */
151           .platform_data = &wm8994_pdata,
152           .irq = GLENFARCLAS_PMIC_IRQ_BASE + WM831X_IRQ_GPIO_2,
153         },
154 };
155
156 static __devinitdata const struct {
157         u8 id;
158         const char *name;
159         const struct i2c_board_info *i2c_devs;
160         int num_i2c_devs;
161 } gf_mods[] = {
162         { .id = 0x01, .name = "1250-EV1 Springbank" },
163         { .id = 0x02, .name = "1251-EV1 Jura" },
164         { .id = 0x03, .name = "1252-EV1 Glenlivet" },
165         { .id = 0x11, .name = "6249-EV2 Glenfarclas", },
166         { .id = 0x21, .name = "1275-EV1 Mortlach" },
167         { .id = 0x25, .name = "1274-EV1 Glencadam" },
168         { .id = 0x31, .name = "1253-EV1 Tomatin", },
169         { .id = 0x39, .name = "1254-EV1 Dallas Dhu",
170           .i2c_devs = wm1254_devs, .num_i2c_devs = ARRAY_SIZE(wm1254_devs) },
171         { .id = 0x3a, .name = "1259-EV1 Tobermory",
172           .i2c_devs = wm1259_devs, .num_i2c_devs = ARRAY_SIZE(wm1259_devs) },
173         { .id = 0x3b, .name = "1255-EV1 Kilchoman",
174           .i2c_devs = wm1255_devs, .num_i2c_devs = ARRAY_SIZE(wm1255_devs) },
175         { .id = 0x3c, .name = "1273-EV1 Longmorn" },
176         { .id = 0x3d, .name = "1277-EV1 Littlemill",
177           .i2c_devs = wm1277_devs, .num_i2c_devs = ARRAY_SIZE(wm1277_devs) },
178 };
179
180 static __devinit int wlf_gf_module_probe(struct i2c_client *i2c,
181                                          const struct i2c_device_id *i2c_id)
182 {
183         int ret, i, j, id, rev;
184
185         ret = i2c_smbus_read_byte_data(i2c, 0);
186         if (ret < 0) {
187                 dev_err(&i2c->dev, "Failed to read ID: %d\n", ret);
188                 return ret;
189         }
190
191         id = (ret & 0xfe) >> 2;
192         rev = ret & 0x3;
193         for (i = 0; i < ARRAY_SIZE(gf_mods); i++)
194                 if (id == gf_mods[i].id)
195                         break;
196
197         if (i < ARRAY_SIZE(gf_mods)) {
198                 dev_info(&i2c->dev, "%s revision %d\n",
199                          gf_mods[i].name, rev + 1);
200                 for (j = 0; j < gf_mods[i].num_i2c_devs; j++) {
201                         if (!i2c_new_device(i2c->adapter,
202                                             &(gf_mods[i].i2c_devs[j])))
203                                 dev_err(&i2c->dev,
204                                         "Failed to register dev: %d\n", ret);
205                 }
206         } else {
207                 dev_warn(&i2c->dev, "Unknown module ID 0x%x revision %d\n",
208                          id, rev + 1);
209         }
210
211         return 0;
212 }
213
214 static const struct i2c_device_id wlf_gf_module_id[] = {
215         { "wlf-gf-module", 0 },
216         { }
217 };
218
219 static struct i2c_driver wlf_gf_module_driver = {
220         .driver = {
221                 .name = "wlf-gf-module",
222                 .owner = THIS_MODULE,
223         },
224         .probe = wlf_gf_module_probe,
225         .id_table = wlf_gf_module_id,
226 };
227
228 static int __init wlf_gf_module_register(void)
229 {
230         return i2c_add_driver(&wlf_gf_module_driver);
231 }
232 module_init(wlf_gf_module_register);