blob: 4e3fe57674c8b2cc1b93599fbef6c9563db211c6 [file] [log] [blame]
Mark Brownd0f0b432011-08-19 22:40:07 +09001/* 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
Kukjin Kima69e4c22011-11-17 01:14:38 +090011#include <linux/export.h>
Mark Brownd0f0b432011-08-19 22:40:07 +090012#include <linux/interrupt.h>
13#include <linux/i2c.h>
Mark Browncda23492012-01-12 11:04:56 +090014#include <linux/spi/spi.h>
Mark Brownd0f0b432011-08-19 22:40:07 +090015
16#include <linux/mfd/wm831x/irq.h>
17#include <linux/mfd/wm831x/gpio.h>
Mark Brownc5c32c92011-12-02 14:32:32 +090018#include <linux/mfd/wm8994/pdata.h>
Mark Brown853b1eb2012-08-10 13:03:16 +090019#include <linux/mfd/arizona/pdata.h>
Mark Brownd0f0b432011-08-19 22:40:07 +090020
Mark Brown719a4242012-03-16 19:36:29 +010021#include <linux/regulator/machine.h>
22
Mark Brown3d19f1c2011-12-02 14:29:08 +090023#include <sound/wm5100.h>
Mark Brownd0f0b432011-08-19 22:40:07 +090024#include <sound/wm8996.h>
25#include <sound/wm8962.h>
26#include <sound/wm9081.h>
27
Arnd Bergmann436d42c2012-08-24 15:22:12 +020028#include <linux/platform_data/spi-s3c64xx.h>
Mark Browncda23492012-01-12 11:04:56 +090029
Mark Brownd0f0b432011-08-19 22:40:07 +090030#include <mach/crag6410.h>
31
Mark Browncda23492012-01-12 11:04:56 +090032static struct s3c64xx_spi_csinfo wm0010_spi_csinfo = {
Mark Browncda23492012-01-12 11:04:56 +090033 .line = S3C64XX_GPC(3),
34};
35
36static struct spi_board_info wm1253_devs[] = {
37 [0] = {
38 .modalias = "wm0010",
39 .bus_num = 0,
40 .chip_select = 0,
41 .mode = SPI_MODE_0,
Dimitris Papastamos15211092012-06-21 03:43:57 +090042 .irq = S3C_EINT(5),
Mark Browncda23492012-01-12 11:04:56 +090043 .controller_data = &wm0010_spi_csinfo,
44 },
45};
46
Mark Brown3d19f1c2011-12-02 14:29:08 +090047static struct wm5100_pdata wm5100_pdata = {
48 .ldo_ena = S3C64XX_GPN(7),
49 .irq_flags = IRQF_TRIGGER_HIGH,
50 .gpio_base = CODEC_GPIO_BASE,
51
52 .in_mode = {
53 WM5100_IN_DIFF,
54 WM5100_IN_DIFF,
55 WM5100_IN_DIFF,
56 WM5100_IN_SE,
57 },
58
59 .hp_pol = CODEC_GPIO_BASE + 3,
60 .jack_modes = {
61 { WM5100_MICDET_MICBIAS3, 0, 0 },
62 { WM5100_MICDET_MICBIAS2, 1, 1 },
63 },
64
65 .gpio_defaults = {
66 0,
67 0,
68 0,
69 0,
70 0x2, /* IRQ: CMOS output */
71 0x3, /* CLKOUT: CMOS output */
72 },
73};
74
Mark Brownd0f0b432011-08-19 22:40:07 +090075static struct wm8996_retune_mobile_config wm8996_retune[] = {
76 {
77 .name = "Sub LPF",
78 .rate = 48000,
79 .regs = {
80 0x6318, 0x6300, 0x1000, 0x0000, 0x0004, 0x2000, 0xF000,
81 0x0000, 0x0004, 0x2000, 0xF000, 0x0000, 0x0004, 0x2000,
82 0xF000, 0x0000, 0x0004, 0x1000, 0x0800, 0x4000
83 },
84 },
85 {
86 .name = "Sub HPF",
87 .rate = 48000,
88 .regs = {
89 0x000A, 0x6300, 0x1000, 0x0000, 0x0004, 0x2000, 0xF000,
90 0x0000, 0x0004, 0x2000, 0xF000, 0x0000, 0x0004, 0x2000,
91 0xF000, 0x0000, 0x0004, 0x1000, 0x0800, 0x4000
92 },
93 },
94};
95
96static struct wm8996_pdata wm8996_pdata __initdata = {
97 .ldo_ena = S3C64XX_GPN(7),
98 .gpio_base = CODEC_GPIO_BASE,
99 .micdet_def = 1,
100 .inl_mode = WM8996_DIFFERRENTIAL_1,
101 .inr_mode = WM8996_DIFFERRENTIAL_1,
102
103 .irq_flags = IRQF_TRIGGER_RISING,
104
105 .gpio_default = {
106 0x8001, /* GPIO1 == ADCLRCLK1 */
107 0x8001, /* GPIO2 == ADCLRCLK2, input due to CPU */
108 0x0141, /* GPIO3 == HP_SEL */
109 0x0002, /* GPIO4 == IRQ */
110 0x020e, /* GPIO5 == CLKOUT */
111 },
112
113 .retune_mobile_cfgs = wm8996_retune,
114 .num_retune_mobile_cfgs = ARRAY_SIZE(wm8996_retune),
115};
116
117static struct wm8962_pdata wm8962_pdata __initdata = {
118 .gpio_init = {
119 0,
120 WM8962_GPIO_FN_OPCLK,
121 WM8962_GPIO_FN_DMICCLK,
122 0,
123 0x8000 | WM8962_GPIO_FN_DMICDAT,
124 WM8962_GPIO_FN_IRQ, /* Open drain mode */
125 },
Mark Brown4b9c85f2012-01-24 21:09:15 +0000126 .in4_dc_measure = true,
Mark Brownd0f0b432011-08-19 22:40:07 +0900127};
128
129static struct wm9081_pdata wm9081_pdata __initdata = {
130 .irq_high = false,
131 .irq_cmos = false,
132};
133
134static const struct i2c_board_info wm1254_devs[] = {
135 { I2C_BOARD_INFO("wm8996", 0x1a),
136 .platform_data = &wm8996_pdata,
137 .irq = GLENFARCLAS_PMIC_IRQ_BASE + WM831X_IRQ_GPIO_2,
138 },
139 { I2C_BOARD_INFO("wm9081", 0x6c),
140 .platform_data = &wm9081_pdata, },
141};
142
Mark Brown3aa77792011-09-05 14:48:39 +0900143static const struct i2c_board_info wm1255_devs[] = {
144 { I2C_BOARD_INFO("wm5100", 0x1a),
Mark Brown3d19f1c2011-12-02 14:29:08 +0900145 .platform_data = &wm5100_pdata,
Mark Brown3aa77792011-09-05 14:48:39 +0900146 .irq = GLENFARCLAS_PMIC_IRQ_BASE + WM831X_IRQ_GPIO_2,
147 },
148 { I2C_BOARD_INFO("wm9081", 0x6c),
149 .platform_data = &wm9081_pdata, },
150};
151
Mark Brownd0f0b432011-08-19 22:40:07 +0900152static const struct i2c_board_info wm1259_devs[] = {
153 { I2C_BOARD_INFO("wm8962", 0x1a),
154 .platform_data = &wm8962_pdata,
155 .irq = GLENFARCLAS_PMIC_IRQ_BASE + WM831X_IRQ_GPIO_2,
156 },
157};
158
Mark Brownbd155d22012-03-08 11:55:07 +0000159static struct regulator_init_data wm8994_ldo1 = {
160 .supply_regulator = "WALLVDD",
161};
162
163static struct regulator_init_data wm8994_ldo2 = {
164 .supply_regulator = "WALLVDD",
165};
166
Mark Brownc5c32c92011-12-02 14:32:32 +0900167static struct wm8994_pdata wm8994_pdata = {
168 .gpio_base = CODEC_GPIO_BASE,
169 .gpio_defaults = {
170 0x3, /* IRQ out, active high, CMOS */
171 },
Mark Brownc5c32c92011-12-02 14:32:32 +0900172 .ldo = {
Mark Brownbd155d22012-03-08 11:55:07 +0000173 { .init_data = &wm8994_ldo1, },
174 { .init_data = &wm8994_ldo2, },
Mark Brownc5c32c92011-12-02 14:32:32 +0900175 },
176};
177
178static const struct i2c_board_info wm1277_devs[] = {
179 { I2C_BOARD_INFO("wm8958", 0x1a), /* WM8958 is the superset */
180 .platform_data = &wm8994_pdata,
181 .irq = GLENFARCLAS_PMIC_IRQ_BASE + WM831X_IRQ_GPIO_2,
182 },
183};
Mark Brownd0f0b432011-08-19 22:40:07 +0900184
Mark Brown853b1eb2012-08-10 13:03:16 +0900185static struct arizona_pdata wm5102_pdata = {
186 .ldoena = S3C64XX_GPN(7),
187 .gpio_base = CODEC_GPIO_BASE,
188 .irq_active_high = true,
189 .micd_pol_gpio = CODEC_GPIO_BASE + 4,
190 .gpio_defaults = {
191 [2] = 0x10000, /* AIF3TXLRCLK */
192 [3] = 0x4, /* OPCLK */
193 },
194};
195
196static struct s3c64xx_spi_csinfo wm5102_spi_csinfo = {
197 .line = S3C64XX_GPN(5),
198};
199
200static struct spi_board_info wm5102_spi_devs[] = {
201 [0] = {
202 .modalias = "wm5102",
203 .max_speed_hz = 10 * 1000 * 1000,
204 .bus_num = 0,
205 .chip_select = 0,
206 .mode = SPI_MODE_0,
207 .irq = GLENFARCLAS_PMIC_IRQ_BASE +
208 WM831X_IRQ_GPIO_2,
209 .controller_data = &wm5102_spi_csinfo,
210 .platform_data = &wm5102_pdata,
211 },
Mark Brown9b6e1b02012-06-20 08:16:25 +0900212};
213
Mark Brown98dcf902012-05-16 07:00:03 +0900214static const struct i2c_board_info wm6230_i2c_devs[] = {
215 { I2C_BOARD_INFO("wm9081", 0x6c),
216 .platform_data = &wm9081_pdata, },
217};
218
Mark Brownd0f0b432011-08-19 22:40:07 +0900219static __devinitdata const struct {
220 u8 id;
221 const char *name;
222 const struct i2c_board_info *i2c_devs;
223 int num_i2c_devs;
Mark Browncda23492012-01-12 11:04:56 +0900224 const struct spi_board_info *spi_devs;
225 int num_spi_devs;
Mark Brownd0f0b432011-08-19 22:40:07 +0900226} gf_mods[] = {
227 { .id = 0x01, .name = "1250-EV1 Springbank" },
228 { .id = 0x02, .name = "1251-EV1 Jura" },
229 { .id = 0x03, .name = "1252-EV1 Glenlivet" },
230 { .id = 0x11, .name = "6249-EV2 Glenfarclas", },
Mark Brownf73dc3d2012-03-07 04:13:20 -0800231 { .id = 0x14, .name = "6271-EV1 Lochnagar" },
Mark Brown98dcf902012-05-16 07:00:03 +0900232 { .id = 0x15, .name = "6320-EV1 Bells",
233 .i2c_devs = wm6230_i2c_devs,
234 .num_i2c_devs = ARRAY_SIZE(wm6230_i2c_devs) },
Mark Brownd0f0b432011-08-19 22:40:07 +0900235 { .id = 0x21, .name = "1275-EV1 Mortlach" },
236 { .id = 0x25, .name = "1274-EV1 Glencadam" },
Mark Browncda23492012-01-12 11:04:56 +0900237 { .id = 0x31, .name = "1253-EV1 Tomatin",
238 .spi_devs = wm1253_devs, .num_spi_devs = ARRAY_SIZE(wm1253_devs) },
Mark Brownf73dc3d2012-03-07 04:13:20 -0800239 { .id = 0x32, .name = "XXXX-EV1 Caol Illa" },
240 { .id = 0x33, .name = "XXXX-EV1 Oban" },
Mark Brown58f8c052012-06-20 08:16:19 +0900241 { .id = 0x34, .name = "WM0010-6320-CS42 Balblair" },
Mark Brownd0f0b432011-08-19 22:40:07 +0900242 { .id = 0x39, .name = "1254-EV1 Dallas Dhu",
243 .i2c_devs = wm1254_devs, .num_i2c_devs = ARRAY_SIZE(wm1254_devs) },
244 { .id = 0x3a, .name = "1259-EV1 Tobermory",
245 .i2c_devs = wm1259_devs, .num_i2c_devs = ARRAY_SIZE(wm1259_devs) },
Mark Brown3aa77792011-09-05 14:48:39 +0900246 { .id = 0x3b, .name = "1255-EV1 Kilchoman",
247 .i2c_devs = wm1255_devs, .num_i2c_devs = ARRAY_SIZE(wm1255_devs) },
Mark Brownd0f0b432011-08-19 22:40:07 +0900248 { .id = 0x3c, .name = "1273-EV1 Longmorn" },
Mark Brownc5c32c92011-12-02 14:32:32 +0900249 { .id = 0x3d, .name = "1277-EV1 Littlemill",
250 .i2c_devs = wm1277_devs, .num_i2c_devs = ARRAY_SIZE(wm1277_devs) },
Mark Brown853b1eb2012-08-10 13:03:16 +0900251 { .id = 0x3e, .name = "WM5102-6271-EV1-CS127 Amrut",
252 .spi_devs = wm5102_spi_devs,
253 .num_spi_devs = ARRAY_SIZE(wm5102_spi_devs) },
Mark Brownd0f0b432011-08-19 22:40:07 +0900254};
255
256static __devinit int wlf_gf_module_probe(struct i2c_client *i2c,
257 const struct i2c_device_id *i2c_id)
258{
259 int ret, i, j, id, rev;
260
261 ret = i2c_smbus_read_byte_data(i2c, 0);
262 if (ret < 0) {
263 dev_err(&i2c->dev, "Failed to read ID: %d\n", ret);
264 return ret;
265 }
266
267 id = (ret & 0xfe) >> 2;
268 rev = ret & 0x3;
269 for (i = 0; i < ARRAY_SIZE(gf_mods); i++)
270 if (id == gf_mods[i].id)
271 break;
272
273 if (i < ARRAY_SIZE(gf_mods)) {
274 dev_info(&i2c->dev, "%s revision %d\n",
275 gf_mods[i].name, rev + 1);
Mark Browncda23492012-01-12 11:04:56 +0900276
Mark Brownd0f0b432011-08-19 22:40:07 +0900277 for (j = 0; j < gf_mods[i].num_i2c_devs; j++) {
278 if (!i2c_new_device(i2c->adapter,
279 &(gf_mods[i].i2c_devs[j])))
280 dev_err(&i2c->dev,
281 "Failed to register dev: %d\n", ret);
282 }
Mark Browncda23492012-01-12 11:04:56 +0900283
284 spi_register_board_info(gf_mods[i].spi_devs,
285 gf_mods[i].num_spi_devs);
Mark Brownd0f0b432011-08-19 22:40:07 +0900286 } else {
Mark Brownfc716892011-12-02 14:29:08 +0900287 dev_warn(&i2c->dev, "Unknown module ID 0x%x revision %d\n",
288 id, rev + 1);
Mark Brownd0f0b432011-08-19 22:40:07 +0900289 }
290
291 return 0;
292}
293
294static const struct i2c_device_id wlf_gf_module_id[] = {
295 { "wlf-gf-module", 0 },
296 { }
297};
298
299static struct i2c_driver wlf_gf_module_driver = {
300 .driver = {
301 .name = "wlf-gf-module",
302 .owner = THIS_MODULE,
303 },
304 .probe = wlf_gf_module_probe,
305 .id_table = wlf_gf_module_id,
306};
307
308static int __init wlf_gf_module_register(void)
309{
310 return i2c_add_driver(&wlf_gf_module_driver);
311}
312module_init(wlf_gf_module_register);