2 * Wolfson WM97xx -- Core device
4 * Copyright (C) 2017 Robert Jarzmik
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
12 * - an AC97 audio codec
13 * - a touchscreen driver
17 #include <linux/device.h>
18 #include <linux/mfd/core.h>
19 #include <linux/mfd/wm97xx.h>
20 #include <linux/module.h>
21 #include <linux/regmap.h>
22 #include <linux/slab.h>
23 #include <linux/wm97xx.h>
24 #include <sound/ac97/codec.h>
25 #include <sound/ac97/compat.h>
27 #define WM9705_VENDOR_ID 0x574d4c05
28 #define WM9712_VENDOR_ID 0x574d4c12
29 #define WM9713_VENDOR_ID 0x574d4c13
30 #define WM97xx_VENDOR_ID_MASK 0xffffffff
33 struct regmap
*regmap
;
34 struct snd_ac97
*ac97
;
36 struct wm97xx_platform_data codec_pdata
;
39 static bool wm97xx_readable_reg(struct device
*dev
, unsigned int reg
)
42 case AC97_RESET
... AC97_PCM_SURR_DAC_RATE
:
43 case AC97_PCM_LR_ADC_RATE
:
44 case AC97_CENTER_LFE_MASTER
:
45 case AC97_SPDIF
... AC97_LINE1_LEVEL
:
46 case AC97_GPIO_CFG
... 0x5c:
47 case AC97_CODEC_CLASS_REV
... AC97_PCI_SID
:
48 case 0x74 ... AC97_VENDOR_ID2
:
55 static bool wm97xx_writeable_reg(struct device
*dev
, unsigned int reg
)
62 return wm97xx_readable_reg(dev
, reg
);
66 static const struct reg_default wm9705_reg_defaults
[] = {
97 static const struct regmap_config wm9705_regmap_config
= {
101 .max_register
= 0x7e,
102 .cache_type
= REGCACHE_RBTREE
,
104 .reg_defaults
= wm9705_reg_defaults
,
105 .num_reg_defaults
= ARRAY_SIZE(wm9705_reg_defaults
),
106 .volatile_reg
= regmap_ac97_default_volatile
,
107 .readable_reg
= wm97xx_readable_reg
,
108 .writeable_reg
= wm97xx_writeable_reg
,
111 static struct mfd_cell wm9705_cells
[] = {
112 { .name
= "wm9705-codec", },
113 { .name
= "wm97xx-ts", },
116 static bool wm9712_volatile_reg(struct device
*dev
, unsigned int reg
)
122 return regmap_ac97_default_volatile(dev
, reg
);
126 static const struct reg_default wm9712_reg_defaults
[] = {
165 static const struct regmap_config wm9712_regmap_config
= {
169 .max_register
= 0x7e,
170 .cache_type
= REGCACHE_RBTREE
,
172 .reg_defaults
= wm9712_reg_defaults
,
173 .num_reg_defaults
= ARRAY_SIZE(wm9712_reg_defaults
),
174 .volatile_reg
= wm9712_volatile_reg
,
175 .readable_reg
= wm97xx_readable_reg
,
176 .writeable_reg
= wm97xx_writeable_reg
,
179 static struct mfd_cell wm9712_cells
[] = {
180 { .name
= "wm9712-codec", },
181 { .name
= "wm97xx-ts", },
184 static const struct reg_default wm9713_reg_defaults
[] = {
185 { 0x02, 0x8080 }, /* Speaker Output Volume */
186 { 0x04, 0x8080 }, /* Headphone Output Volume */
187 { 0x06, 0x8080 }, /* Out3/OUT4 Volume */
188 { 0x08, 0xc880 }, /* Mono Volume */
189 { 0x0a, 0xe808 }, /* LINEIN Volume */
190 { 0x0c, 0xe808 }, /* DAC PGA Volume */
191 { 0x0e, 0x0808 }, /* MIC PGA Volume */
192 { 0x10, 0x00da }, /* MIC Routing Control */
193 { 0x12, 0x8000 }, /* Record PGA Volume */
194 { 0x14, 0xd600 }, /* Record Routing */
195 { 0x16, 0xaaa0 }, /* PCBEEP Volume */
196 { 0x18, 0xaaa0 }, /* VxDAC Volume */
197 { 0x1a, 0xaaa0 }, /* AUXDAC Volume */
198 { 0x1c, 0x0000 }, /* Output PGA Mux */
199 { 0x1e, 0x0000 }, /* DAC 3D control */
200 { 0x20, 0x0f0f }, /* DAC Tone Control*/
201 { 0x22, 0x0040 }, /* MIC Input Select & Bias */
202 { 0x24, 0x0000 }, /* Output Volume Mapping & Jack */
203 { 0x26, 0x7f00 }, /* Powerdown Ctrl/Stat*/
204 { 0x28, 0x0405 }, /* Extended Audio ID */
205 { 0x2a, 0x0410 }, /* Extended Audio Start/Ctrl */
206 { 0x2c, 0xbb80 }, /* Audio DACs Sample Rate */
207 { 0x2e, 0xbb80 }, /* AUXDAC Sample Rate */
208 { 0x32, 0xbb80 }, /* Audio ADCs Sample Rate */
209 { 0x36, 0x4523 }, /* PCM codec control */
210 { 0x3a, 0x2000 }, /* SPDIF control */
211 { 0x3c, 0xfdff }, /* Powerdown 1 */
212 { 0x3e, 0xffff }, /* Powerdown 2 */
213 { 0x40, 0x0000 }, /* General Purpose */
214 { 0x42, 0x0000 }, /* Fast Power-Up Control */
215 { 0x44, 0x0080 }, /* MCLK/PLL Control */
216 { 0x46, 0x0000 }, /* MCLK/PLL Control */
218 { 0x4c, 0xfffe }, /* GPIO Pin Configuration */
219 { 0x4e, 0xffff }, /* GPIO Pin Polarity / Type */
220 { 0x50, 0x0000 }, /* GPIO Pin Sticky */
221 { 0x52, 0x0000 }, /* GPIO Pin Wake-Up */
222 /* GPIO Pin Status */
223 { 0x56, 0xfffe }, /* GPIO Pin Sharing */
224 { 0x58, 0x4000 }, /* GPIO PullUp/PullDown */
225 { 0x5a, 0x0000 }, /* Additional Functions 1 */
226 { 0x5c, 0x0000 }, /* Additional Functions 2 */
227 { 0x60, 0xb032 }, /* ALC Control */
228 { 0x62, 0x3e00 }, /* ALC / Noise Gate Control */
229 { 0x64, 0x0000 }, /* AUXDAC input control */
230 { 0x74, 0x0000 }, /* Digitiser Reg 1 */
231 { 0x76, 0x0006 }, /* Digitiser Reg 2 */
232 { 0x78, 0x0001 }, /* Digitiser Reg 3 */
233 { 0x7a, 0x0000 }, /* Digitiser Read Back */
236 static const struct regmap_config wm9713_regmap_config
= {
240 .max_register
= 0x7e,
241 .cache_type
= REGCACHE_RBTREE
,
243 .reg_defaults
= wm9713_reg_defaults
,
244 .num_reg_defaults
= ARRAY_SIZE(wm9713_reg_defaults
),
245 .volatile_reg
= regmap_ac97_default_volatile
,
246 .readable_reg
= wm97xx_readable_reg
,
247 .writeable_reg
= wm97xx_writeable_reg
,
250 static struct mfd_cell wm9713_cells
[] = {
251 { .name
= "wm9713-codec", },
252 { .name
= "wm97xx-ts", },
255 static int wm97xx_ac97_probe(struct ac97_codec_device
*adev
)
257 struct wm97xx_priv
*wm97xx
;
258 const struct regmap_config
*config
;
259 struct wm97xx_platform_data
*codec_pdata
;
260 struct mfd_cell
*cells
;
261 int ret
= -ENODEV
, nb_cells
, i
;
262 struct wm97xx_pdata
*pdata
= snd_ac97_codec_get_platdata(adev
);
264 wm97xx
= devm_kzalloc(ac97_codec_dev2dev(adev
),
265 sizeof(*wm97xx
), GFP_KERNEL
);
269 wm97xx
->dev
= ac97_codec_dev2dev(adev
);
270 wm97xx
->ac97
= snd_ac97_compat_alloc(adev
);
271 if (IS_ERR(wm97xx
->ac97
))
272 return PTR_ERR(wm97xx
->ac97
);
275 ac97_set_drvdata(adev
, wm97xx
);
276 dev_info(wm97xx
->dev
, "wm97xx core found, id=0x%x\n",
279 codec_pdata
= &wm97xx
->codec_pdata
;
280 codec_pdata
->ac97
= wm97xx
->ac97
;
281 codec_pdata
->batt_pdata
= pdata
? pdata
->batt_pdata
: NULL
;
283 switch (adev
->vendor_id
) {
284 case WM9705_VENDOR_ID
:
285 config
= &wm9705_regmap_config
;
286 cells
= wm9705_cells
;
287 nb_cells
= ARRAY_SIZE(wm9705_cells
);
289 case WM9712_VENDOR_ID
:
290 config
= &wm9712_regmap_config
;
291 cells
= wm9712_cells
;
292 nb_cells
= ARRAY_SIZE(wm9712_cells
);
294 case WM9713_VENDOR_ID
:
295 config
= &wm9713_regmap_config
;
296 cells
= wm9713_cells
;
297 nb_cells
= ARRAY_SIZE(wm9713_cells
);
300 goto err_free_compat
;
303 for (i
= 0; i
< nb_cells
; i
++) {
304 cells
[i
].platform_data
= codec_pdata
;
305 cells
[i
].pdata_size
= sizeof(*codec_pdata
);
308 codec_pdata
->regmap
= devm_regmap_init_ac97(wm97xx
->ac97
, config
);
309 if (IS_ERR(codec_pdata
->regmap
)) {
310 ret
= PTR_ERR(codec_pdata
->regmap
);
311 goto err_free_compat
;
314 ret
= devm_mfd_add_devices(wm97xx
->dev
, PLATFORM_DEVID_NONE
,
315 cells
, nb_cells
, NULL
, 0, NULL
);
317 goto err_free_compat
;
322 snd_ac97_compat_release(wm97xx
->ac97
);
326 static int wm97xx_ac97_remove(struct ac97_codec_device
*adev
)
328 struct wm97xx_priv
*wm97xx
= ac97_get_drvdata(adev
);
330 snd_ac97_compat_release(wm97xx
->ac97
);
335 static const struct ac97_id wm97xx_ac97_ids
[] = {
336 { .id
= WM9705_VENDOR_ID
, .mask
= WM97xx_VENDOR_ID_MASK
},
337 { .id
= WM9712_VENDOR_ID
, .mask
= WM97xx_VENDOR_ID_MASK
},
338 { .id
= WM9713_VENDOR_ID
, .mask
= WM97xx_VENDOR_ID_MASK
},
342 static struct ac97_codec_driver wm97xx_ac97_driver
= {
344 .name
= "wm97xx-core",
346 .probe
= wm97xx_ac97_probe
,
347 .remove
= wm97xx_ac97_remove
,
348 .id_table
= wm97xx_ac97_ids
,
351 static int __init
wm97xx_module_init(void)
353 return snd_ac97_codec_driver_register(&wm97xx_ac97_driver
);
355 module_init(wm97xx_module_init
);
357 static void __exit
wm97xx_module_exit(void)
359 snd_ac97_codec_driver_unregister(&wm97xx_ac97_driver
);
361 module_exit(wm97xx_module_exit
);
363 MODULE_DESCRIPTION("WM9712, WM9713 core driver");
364 MODULE_AUTHOR("Robert Jarzmik <robert.jarzmik@free.fr>");
365 MODULE_LICENSE("GPL");