Commit | Line | Data |
---|---|---|
28a196fe KK |
1 | // SPDX-License-Identifier: GPL-2.0 |
2 | // | |
3 | // Speyside modules for Cragganmore - board data probing | |
4 | // | |
5 | // Copyright 2011 Wolfson Microelectronics plc | |
6 | // Mark Brown <broonie@opensource.wolfsonmicro.com> | |
d0f0b43f | 7 | |
a69e4c28 | 8 | #include <linux/export.h> |
d0f0b43f MB |
9 | #include <linux/interrupt.h> |
10 | #include <linux/i2c.h> | |
cda2349a | 11 | #include <linux/spi/spi.h> |
e1739e86 | 12 | #include <linux/gpio/machine.h> |
d0f0b43f MB |
13 | |
14 | #include <linux/mfd/wm831x/irq.h> | |
15 | #include <linux/mfd/wm831x/gpio.h> | |
c5c32c96 | 16 | #include <linux/mfd/wm8994/pdata.h> |
853b1eb8 | 17 | #include <linux/mfd/arizona/pdata.h> |
d0f0b43f | 18 | |
719a4240 MB |
19 | #include <linux/regulator/machine.h> |
20 | ||
c8968ad8 | 21 | #include <sound/wm0010.h> |
e6a194b7 | 22 | #include <sound/wm2200.h> |
3d19f1cd | 23 | #include <sound/wm5100.h> |
d0f0b43f MB |
24 | #include <sound/wm8996.h> |
25 | #include <sound/wm8962.h> | |
26 | #include <sound/wm9081.h> | |
27 | ||
436d42c6 | 28 | #include <linux/platform_data/spi-s3c64xx.h> |
cda2349a | 29 | |
c6ff132d | 30 | #include "cpu.h" |
c78a41fc | 31 | #include "irqs.h" |
ba279044 | 32 | |
e6235928 | 33 | #include "crag6410.h" |
d0f0b43f | 34 | |
c8968ad8 MB |
35 | static struct wm0010_pdata wm0010_pdata = { |
36 | .gpio_reset = S3C64XX_GPN(6), | |
37 | .reset_active_high = 1, /* Active high for Glenfarclas Rev 2 */ | |
38 | }; | |
39 | ||
cda2349a MB |
40 | static struct spi_board_info wm1253_devs[] = { |
41 | [0] = { | |
42 | .modalias = "wm0010", | |
c8968ad8 MB |
43 | .max_speed_hz = 26 * 1000 * 1000, |
44 | .bus_num = 0, | |
45 | .chip_select = 0, | |
46 | .mode = SPI_MODE_0, | |
b86dc0d8 | 47 | .irq = S3C_EINT(4), |
c8968ad8 MB |
48 | .platform_data = &wm0010_pdata, |
49 | }, | |
50 | }; | |
51 | ||
52 | static struct spi_board_info balblair_devs[] = { | |
53 | [0] = { | |
54 | .modalias = "wm0010", | |
55 | .max_speed_hz = 26 * 1000 * 1000, | |
cda2349a MB |
56 | .bus_num = 0, |
57 | .chip_select = 0, | |
58 | .mode = SPI_MODE_0, | |
f032b49e | 59 | .irq = S3C_EINT(4), |
c8968ad8 | 60 | .platform_data = &wm0010_pdata, |
cda2349a MB |
61 | }, |
62 | }; | |
63 | ||
3d19f1cd MB |
64 | static struct wm5100_pdata wm5100_pdata = { |
65 | .ldo_ena = S3C64XX_GPN(7), | |
66 | .irq_flags = IRQF_TRIGGER_HIGH, | |
67 | .gpio_base = CODEC_GPIO_BASE, | |
68 | ||
69 | .in_mode = { | |
70 | WM5100_IN_DIFF, | |
71 | WM5100_IN_DIFF, | |
72 | WM5100_IN_DIFF, | |
73 | WM5100_IN_SE, | |
74 | }, | |
75 | ||
76 | .hp_pol = CODEC_GPIO_BASE + 3, | |
77 | .jack_modes = { | |
78 | { WM5100_MICDET_MICBIAS3, 0, 0 }, | |
79 | { WM5100_MICDET_MICBIAS2, 1, 1 }, | |
80 | }, | |
81 | ||
82 | .gpio_defaults = { | |
83 | 0, | |
84 | 0, | |
85 | 0, | |
86 | 0, | |
87 | 0x2, /* IRQ: CMOS output */ | |
88 | 0x3, /* CLKOUT: CMOS output */ | |
89 | }, | |
90 | }; | |
91 | ||
d0f0b43f MB |
92 | static struct wm8996_retune_mobile_config wm8996_retune[] = { |
93 | { | |
94 | .name = "Sub LPF", | |
95 | .rate = 48000, | |
96 | .regs = { | |
97 | 0x6318, 0x6300, 0x1000, 0x0000, 0x0004, 0x2000, 0xF000, | |
98 | 0x0000, 0x0004, 0x2000, 0xF000, 0x0000, 0x0004, 0x2000, | |
99 | 0xF000, 0x0000, 0x0004, 0x1000, 0x0800, 0x4000 | |
100 | }, | |
101 | }, | |
102 | { | |
103 | .name = "Sub HPF", | |
104 | .rate = 48000, | |
105 | .regs = { | |
106 | 0x000A, 0x6300, 0x1000, 0x0000, 0x0004, 0x2000, 0xF000, | |
107 | 0x0000, 0x0004, 0x2000, 0xF000, 0x0000, 0x0004, 0x2000, | |
108 | 0xF000, 0x0000, 0x0004, 0x1000, 0x0800, 0x4000 | |
109 | }, | |
110 | }, | |
111 | }; | |
112 | ||
113 | static struct wm8996_pdata wm8996_pdata __initdata = { | |
114 | .ldo_ena = S3C64XX_GPN(7), | |
115 | .gpio_base = CODEC_GPIO_BASE, | |
116 | .micdet_def = 1, | |
117 | .inl_mode = WM8996_DIFFERRENTIAL_1, | |
118 | .inr_mode = WM8996_DIFFERRENTIAL_1, | |
119 | ||
120 | .irq_flags = IRQF_TRIGGER_RISING, | |
121 | ||
122 | .gpio_default = { | |
123 | 0x8001, /* GPIO1 == ADCLRCLK1 */ | |
124 | 0x8001, /* GPIO2 == ADCLRCLK2, input due to CPU */ | |
125 | 0x0141, /* GPIO3 == HP_SEL */ | |
126 | 0x0002, /* GPIO4 == IRQ */ | |
127 | 0x020e, /* GPIO5 == CLKOUT */ | |
128 | }, | |
129 | ||
130 | .retune_mobile_cfgs = wm8996_retune, | |
131 | .num_retune_mobile_cfgs = ARRAY_SIZE(wm8996_retune), | |
132 | }; | |
133 | ||
134 | static struct wm8962_pdata wm8962_pdata __initdata = { | |
135 | .gpio_init = { | |
136 | 0, | |
137 | WM8962_GPIO_FN_OPCLK, | |
138 | WM8962_GPIO_FN_DMICCLK, | |
139 | 0, | |
140 | 0x8000 | WM8962_GPIO_FN_DMICDAT, | |
141 | WM8962_GPIO_FN_IRQ, /* Open drain mode */ | |
142 | }, | |
4b9c85f9 | 143 | .in4_dc_measure = true, |
d0f0b43f MB |
144 | }; |
145 | ||
146 | static struct wm9081_pdata wm9081_pdata __initdata = { | |
147 | .irq_high = false, | |
148 | .irq_cmos = false, | |
149 | }; | |
150 | ||
151 | static const struct i2c_board_info wm1254_devs[] = { | |
152 | { I2C_BOARD_INFO("wm8996", 0x1a), | |
153 | .platform_data = &wm8996_pdata, | |
154 | .irq = GLENFARCLAS_PMIC_IRQ_BASE + WM831X_IRQ_GPIO_2, | |
155 | }, | |
156 | { I2C_BOARD_INFO("wm9081", 0x6c), | |
157 | .platform_data = &wm9081_pdata, }, | |
158 | }; | |
159 | ||
3aa7779c MB |
160 | static const struct i2c_board_info wm1255_devs[] = { |
161 | { I2C_BOARD_INFO("wm5100", 0x1a), | |
3d19f1cd | 162 | .platform_data = &wm5100_pdata, |
3aa7779c MB |
163 | .irq = GLENFARCLAS_PMIC_IRQ_BASE + WM831X_IRQ_GPIO_2, |
164 | }, | |
165 | { I2C_BOARD_INFO("wm9081", 0x6c), | |
166 | .platform_data = &wm9081_pdata, }, | |
167 | }; | |
168 | ||
d0f0b43f MB |
169 | static const struct i2c_board_info wm1259_devs[] = { |
170 | { I2C_BOARD_INFO("wm8962", 0x1a), | |
171 | .platform_data = &wm8962_pdata, | |
172 | .irq = GLENFARCLAS_PMIC_IRQ_BASE + WM831X_IRQ_GPIO_2, | |
173 | }, | |
174 | }; | |
175 | ||
bd155d2c MB |
176 | static struct regulator_init_data wm8994_ldo1 = { |
177 | .supply_regulator = "WALLVDD", | |
178 | }; | |
179 | ||
180 | static struct regulator_init_data wm8994_ldo2 = { | |
181 | .supply_regulator = "WALLVDD", | |
182 | }; | |
183 | ||
c5c32c96 MB |
184 | static struct wm8994_pdata wm8994_pdata = { |
185 | .gpio_base = CODEC_GPIO_BASE, | |
b23bc66c | 186 | .micb2_delay = 150, |
c5c32c96 MB |
187 | .gpio_defaults = { |
188 | 0x3, /* IRQ out, active high, CMOS */ | |
189 | }, | |
c5c32c96 | 190 | .ldo = { |
1d2f4681 LW |
191 | { .init_data = &wm8994_ldo1, }, |
192 | { .init_data = &wm8994_ldo2, }, | |
c5c32c96 MB |
193 | }, |
194 | }; | |
195 | ||
196 | static const struct i2c_board_info wm1277_devs[] = { | |
197 | { I2C_BOARD_INFO("wm8958", 0x1a), /* WM8958 is the superset */ | |
198 | .platform_data = &wm8994_pdata, | |
199 | .irq = GLENFARCLAS_PMIC_IRQ_BASE + WM831X_IRQ_GPIO_2, | |
1d2f4681 LW |
200 | .dev_name = "wm8958", |
201 | }, | |
202 | }; | |
203 | ||
204 | static struct gpiod_lookup_table wm8994_gpiod_table = { | |
205 | .dev_id = "i2c-wm8958", /* I2C device name */ | |
206 | .table = { | |
207 | GPIO_LOOKUP("GPION", 6, | |
208 | "wlf,ldo1ena", GPIO_ACTIVE_HIGH), | |
209 | GPIO_LOOKUP("GPION", 4, | |
210 | "wlf,ldo2ena", GPIO_ACTIVE_HIGH), | |
211 | { }, | |
c5c32c96 MB |
212 | }, |
213 | }; | |
d0f0b43f | 214 | |
b23bc66c | 215 | static struct arizona_pdata wm5102_reva_pdata = { |
853b1eb8 | 216 | .gpio_base = CODEC_GPIO_BASE, |
f8a0941f | 217 | .irq_flags = IRQF_TRIGGER_HIGH, |
853b1eb8 | 218 | .micd_pol_gpio = CODEC_GPIO_BASE + 4, |
1fa86dcf | 219 | .micd_rate = 6, |
853b1eb8 MB |
220 | .gpio_defaults = { |
221 | [2] = 0x10000, /* AIF3TXLRCLK */ | |
222 | [3] = 0x4, /* OPCLK */ | |
223 | }, | |
224 | }; | |
225 | ||
b23bc66c MB |
226 | static struct spi_board_info wm5102_reva_spi_devs[] = { |
227 | [0] = { | |
228 | .modalias = "wm5102", | |
229 | .max_speed_hz = 10 * 1000 * 1000, | |
230 | .bus_num = 0, | |
231 | .chip_select = 1, | |
232 | .mode = SPI_MODE_0, | |
233 | .irq = GLENFARCLAS_PMIC_IRQ_BASE + | |
234 | WM831X_IRQ_GPIO_2, | |
b23bc66c MB |
235 | .platform_data = &wm5102_reva_pdata, |
236 | }, | |
237 | }; | |
238 | ||
e1739e86 LW |
239 | static struct gpiod_lookup_table wm5102_reva_gpiod_table = { |
240 | .dev_id = "spi0.1", /* SPI device name */ | |
241 | .table = { | |
242 | GPIO_LOOKUP("GPION", 7, | |
243 | "wlf,ldoena", GPIO_ACTIVE_HIGH), | |
244 | { }, | |
aaa84e6a | 245 | }, |
e1739e86 LW |
246 | }; |
247 | ||
248 | static struct arizona_pdata wm5102_pdata = { | |
b23bc66c | 249 | .gpio_base = CODEC_GPIO_BASE, |
f8a0941f | 250 | .irq_flags = IRQF_TRIGGER_HIGH, |
b23bc66c MB |
251 | .micd_pol_gpio = CODEC_GPIO_BASE + 2, |
252 | .gpio_defaults = { | |
253 | [2] = 0x10000, /* AIF3TXLRCLK */ | |
254 | [3] = 0x4, /* OPCLK */ | |
255 | }, | |
256 | }; | |
257 | ||
853b1eb8 MB |
258 | static struct spi_board_info wm5102_spi_devs[] = { |
259 | [0] = { | |
260 | .modalias = "wm5102", | |
261 | .max_speed_hz = 10 * 1000 * 1000, | |
262 | .bus_num = 0, | |
479535ed | 263 | .chip_select = 1, |
853b1eb8 MB |
264 | .mode = SPI_MODE_0, |
265 | .irq = GLENFARCLAS_PMIC_IRQ_BASE + | |
266 | WM831X_IRQ_GPIO_2, | |
853b1eb8 MB |
267 | .platform_data = &wm5102_pdata, |
268 | }, | |
9b6e1b0e MB |
269 | }; |
270 | ||
e1739e86 LW |
271 | static struct gpiod_lookup_table wm5102_gpiod_table = { |
272 | .dev_id = "spi0.1", /* SPI device name */ | |
273 | .table = { | |
274 | GPIO_LOOKUP("GPION", 7, | |
275 | "wlf,ldo1ena", GPIO_ACTIVE_HIGH), | |
276 | { }, | |
277 | }, | |
278 | }; | |
279 | ||
41830ee0 MB |
280 | static struct spi_board_info wm5110_spi_devs[] = { |
281 | [0] = { | |
282 | .modalias = "wm5110", | |
283 | .max_speed_hz = 10 * 1000 * 1000, | |
284 | .bus_num = 0, | |
285 | .chip_select = 1, | |
286 | .mode = SPI_MODE_0, | |
287 | .irq = GLENFARCLAS_PMIC_IRQ_BASE + | |
288 | WM831X_IRQ_GPIO_2, | |
41830ee0 MB |
289 | .platform_data = &wm5102_reva_pdata, |
290 | }, | |
291 | }; | |
292 | ||
98dcf905 MB |
293 | static const struct i2c_board_info wm6230_i2c_devs[] = { |
294 | { I2C_BOARD_INFO("wm9081", 0x6c), | |
295 | .platform_data = &wm9081_pdata, }, | |
296 | }; | |
297 | ||
e6a194b7 MB |
298 | static struct wm2200_pdata wm2200_pdata = { |
299 | .ldo_ena = S3C64XX_GPN(7), | |
300 | .gpio_defaults = { | |
301 | [2] = 0x0005, /* GPIO3 24.576MHz output clock */ | |
302 | }, | |
303 | }; | |
304 | ||
305 | static const struct i2c_board_info wm2200_i2c[] = { | |
306 | { I2C_BOARD_INFO("wm2200", 0x3a), | |
307 | .platform_data = &wm2200_pdata, }, | |
308 | }; | |
309 | ||
351a102d | 310 | static const struct { |
d0f0b43f | 311 | u8 id; |
64aecb4a | 312 | u8 rev; |
d0f0b43f MB |
313 | const char *name; |
314 | const struct i2c_board_info *i2c_devs; | |
315 | int num_i2c_devs; | |
cda2349a MB |
316 | const struct spi_board_info *spi_devs; |
317 | int num_spi_devs; | |
7676e667 CK |
318 | |
319 | struct gpiod_lookup_table *gpiod_table; | |
d0f0b43f | 320 | } gf_mods[] = { |
64aecb4a MB |
321 | { .id = 0x01, .rev = 0xff, .name = "1250-EV1 Springbank" }, |
322 | { .id = 0x02, .rev = 0xff, .name = "1251-EV1 Jura" }, | |
323 | { .id = 0x03, .rev = 0xff, .name = "1252-EV1 Glenlivet" }, | |
324 | { .id = 0x06, .rev = 0xff, .name = "WM8997-6721-CS96-EV1 Lapraoig" }, | |
41830ee0 MB |
325 | { .id = 0x07, .rev = 0xff, .name = "WM5110-6271 Deanston", |
326 | .spi_devs = wm5110_spi_devs, | |
327 | .num_spi_devs = ARRAY_SIZE(wm5110_spi_devs) }, | |
64aecb4a MB |
328 | { .id = 0x08, .rev = 0xff, .name = "WM8903-6102 Tamdhu" }, |
329 | { .id = 0x09, .rev = 0xff, .name = "WM1811A-6305 Adelphi" }, | |
330 | { .id = 0x0a, .rev = 0xff, .name = "WM8996-6272 Blackadder" }, | |
331 | { .id = 0x0b, .rev = 0xff, .name = "WM8994-6235 Benromach" }, | |
332 | { .id = 0x11, .rev = 0xff, .name = "6249-EV2 Glenfarclas", }, | |
333 | { .id = 0x14, .rev = 0xff, .name = "6271-EV1 Lochnagar" }, | |
334 | { .id = 0x15, .rev = 0xff, .name = "6320-EV1 Bells", | |
98dcf905 MB |
335 | .i2c_devs = wm6230_i2c_devs, |
336 | .num_i2c_devs = ARRAY_SIZE(wm6230_i2c_devs) }, | |
64aecb4a MB |
337 | { .id = 0x21, .rev = 0xff, .name = "1275-EV1 Mortlach" }, |
338 | { .id = 0x25, .rev = 0xff, .name = "1274-EV1 Glencadam" }, | |
339 | { .id = 0x31, .rev = 0xff, .name = "1253-EV1 Tomatin", | |
cda2349a | 340 | .spi_devs = wm1253_devs, .num_spi_devs = ARRAY_SIZE(wm1253_devs) }, |
64aecb4a MB |
341 | { .id = 0x32, .rev = 0xff, .name = "XXXX-EV1 Caol Illa" }, |
342 | { .id = 0x33, .rev = 0xff, .name = "XXXX-EV1 Oban" }, | |
343 | { .id = 0x34, .rev = 0xff, .name = "WM0010-6320-CS42 Balblair", | |
c8968ad8 MB |
344 | .spi_devs = balblair_devs, |
345 | .num_spi_devs = ARRAY_SIZE(balblair_devs) }, | |
64aecb4a | 346 | { .id = 0x39, .rev = 0xff, .name = "1254-EV1 Dallas Dhu", |
d0f0b43f | 347 | .i2c_devs = wm1254_devs, .num_i2c_devs = ARRAY_SIZE(wm1254_devs) }, |
64aecb4a | 348 | { .id = 0x3a, .rev = 0xff, .name = "1259-EV1 Tobermory", |
d0f0b43f | 349 | .i2c_devs = wm1259_devs, .num_i2c_devs = ARRAY_SIZE(wm1259_devs) }, |
64aecb4a | 350 | { .id = 0x3b, .rev = 0xff, .name = "1255-EV1 Kilchoman", |
3aa7779c | 351 | .i2c_devs = wm1255_devs, .num_i2c_devs = ARRAY_SIZE(wm1255_devs) }, |
64aecb4a MB |
352 | { .id = 0x3c, .rev = 0xff, .name = "1273-EV1 Longmorn" }, |
353 | { .id = 0x3d, .rev = 0xff, .name = "1277-EV1 Littlemill", | |
7676e667 CK |
354 | .i2c_devs = wm1277_devs, .num_i2c_devs = ARRAY_SIZE(wm1277_devs), |
355 | .gpiod_table = &wm8994_gpiod_table }, | |
b23bc66c MB |
356 | { .id = 0x3e, .rev = 0, .name = "WM5102-6271-EV1-CS127 Amrut", |
357 | .spi_devs = wm5102_reva_spi_devs, | |
7676e667 CK |
358 | .num_spi_devs = ARRAY_SIZE(wm5102_reva_spi_devs), |
359 | .gpiod_table = &wm5102_reva_gpiod_table }, | |
64aecb4a | 360 | { .id = 0x3e, .rev = -1, .name = "WM5102-6271-EV1-CS127 Amrut", |
853b1eb8 | 361 | .spi_devs = wm5102_spi_devs, |
7676e667 CK |
362 | .num_spi_devs = ARRAY_SIZE(wm5102_spi_devs), |
363 | .gpiod_table = &wm5102_gpiod_table }, | |
e6a194b7 MB |
364 | { .id = 0x3f, .rev = -1, .name = "WM2200-6271-CS90-M-REV1", |
365 | .i2c_devs = wm2200_i2c, .num_i2c_devs = ARRAY_SIZE(wm2200_i2c) }, | |
d0f0b43f MB |
366 | }; |
367 | ||
bb82067a | 368 | static int wlf_gf_module_probe(struct i2c_client *i2c) |
d0f0b43f MB |
369 | { |
370 | int ret, i, j, id, rev; | |
371 | ||
372 | ret = i2c_smbus_read_byte_data(i2c, 0); | |
373 | if (ret < 0) { | |
374 | dev_err(&i2c->dev, "Failed to read ID: %d\n", ret); | |
375 | return ret; | |
376 | } | |
377 | ||
378 | id = (ret & 0xfe) >> 2; | |
379 | rev = ret & 0x3; | |
380 | for (i = 0; i < ARRAY_SIZE(gf_mods); i++) | |
64aecb4a MB |
381 | if (id == gf_mods[i].id && (gf_mods[i].rev == 0xff || |
382 | rev == gf_mods[i].rev)) | |
d0f0b43f MB |
383 | break; |
384 | ||
e1739e86 LW |
385 | gpiod_add_lookup_table(&wm5102_reva_gpiod_table); |
386 | gpiod_add_lookup_table(&wm5102_gpiod_table); | |
1d2f4681 | 387 | gpiod_add_lookup_table(&wm8994_gpiod_table); |
e1739e86 | 388 | |
d0f0b43f MB |
389 | if (i < ARRAY_SIZE(gf_mods)) { |
390 | dev_info(&i2c->dev, "%s revision %d\n", | |
391 | gf_mods[i].name, rev + 1); | |
cda2349a | 392 | |
d0f0b43f | 393 | for (j = 0; j < gf_mods[i].num_i2c_devs; j++) { |
778627c7 WS |
394 | if (IS_ERR(i2c_new_client_device(i2c->adapter, |
395 | &(gf_mods[i].i2c_devs[j])))) | |
396 | dev_err(&i2c->dev, "Failed to register\n"); | |
d0f0b43f | 397 | } |
cda2349a MB |
398 | |
399 | spi_register_board_info(gf_mods[i].spi_devs, | |
400 | gf_mods[i].num_spi_devs); | |
7676e667 CK |
401 | |
402 | if (gf_mods[i].gpiod_table) | |
403 | gpiod_add_lookup_table(gf_mods[i].gpiod_table); | |
d0f0b43f | 404 | } else { |
fc716894 MB |
405 | dev_warn(&i2c->dev, "Unknown module ID 0x%x revision %d\n", |
406 | id, rev + 1); | |
d0f0b43f MB |
407 | } |
408 | ||
409 | return 0; | |
410 | } | |
411 | ||
412 | static const struct i2c_device_id wlf_gf_module_id[] = { | |
413 | { "wlf-gf-module", 0 }, | |
414 | { } | |
415 | }; | |
416 | ||
417 | static struct i2c_driver wlf_gf_module_driver = { | |
418 | .driver = { | |
21c66101 | 419 | .name = "wlf-gf-module" |
d0f0b43f | 420 | }, |
bb82067a | 421 | .probe_new = wlf_gf_module_probe, |
d0f0b43f MB |
422 | .id_table = wlf_gf_module_id, |
423 | }; | |
424 | ||
425 | static int __init wlf_gf_module_register(void) | |
426 | { | |
a0e157af AB |
427 | if (!soc_is_s3c64xx()) |
428 | return 0; | |
429 | ||
d0f0b43f MB |
430 | return i2c_add_driver(&wlf_gf_module_driver); |
431 | } | |
baf64abc | 432 | device_initcall(wlf_gf_module_register); |