wm8990.c (c02368a9d059322f913a58111eade87a656fefd5) wm8990.c (6335d05548eece40092000aa91b64a50310d69d5)
1/*
2 * wm8990.c -- WM8990 ALSA Soc Audio driver
3 *
4 * Copyright 2008 Wolfson Microelectronics PLC.
5 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the

--- 101 unchanged lines hidden (view full) ---

110
111/*
112 * read wm8990 register cache
113 */
114static inline unsigned int wm8990_read_reg_cache(struct snd_soc_codec *codec,
115 unsigned int reg)
116{
117 u16 *cache = codec->reg_cache;
1/*
2 * wm8990.c -- WM8990 ALSA Soc Audio driver
3 *
4 * Copyright 2008 Wolfson Microelectronics PLC.
5 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the

--- 101 unchanged lines hidden (view full) ---

110
111/*
112 * read wm8990 register cache
113 */
114static inline unsigned int wm8990_read_reg_cache(struct snd_soc_codec *codec,
115 unsigned int reg)
116{
117 u16 *cache = codec->reg_cache;
118 BUG_ON(reg > (ARRAY_SIZE(wm8990_reg)) - 1);
118 BUG_ON(reg >= ARRAY_SIZE(wm8990_reg));
119 return cache[reg];
120}
121
122/*
123 * write wm8990 register cache
124 */
125static inline void wm8990_write_reg_cache(struct snd_soc_codec *codec,
126 unsigned int reg, unsigned int value)
127{
128 u16 *cache = codec->reg_cache;
129
130 /* Reset register and reserved registers are uncached */
119 return cache[reg];
120}
121
122/*
123 * write wm8990 register cache
124 */
125static inline void wm8990_write_reg_cache(struct snd_soc_codec *codec,
126 unsigned int reg, unsigned int value)
127{
128 u16 *cache = codec->reg_cache;
129
130 /* Reset register and reserved registers are uncached */
131 if (reg == 0 || reg > ARRAY_SIZE(wm8990_reg) - 1)
131 if (reg == 0 || reg >= ARRAY_SIZE(wm8990_reg))
132 return;
133
134 cache[reg] = value;
135}
136
137/*
138 * write to the wm8990 register space
139 */

--- 273 unchanged lines hidden (view full) ---

413SOC_SINGLE("RIN34 ZC Switch", WM8990_RIGHT_LINE_INPUT_3_4_VOLUME,
414 WM8990_RI34ZC_BIT, 1, 0),
415
416SOC_SINGLE("RIN34 Mute Switch", WM8990_RIGHT_LINE_INPUT_3_4_VOLUME,
417 WM8990_RI34MUTE_BIT, 1, 0),
418
419};
420
132 return;
133
134 cache[reg] = value;
135}
136
137/*
138 * write to the wm8990 register space
139 */

--- 273 unchanged lines hidden (view full) ---

413SOC_SINGLE("RIN34 ZC Switch", WM8990_RIGHT_LINE_INPUT_3_4_VOLUME,
414 WM8990_RI34ZC_BIT, 1, 0),
415
416SOC_SINGLE("RIN34 Mute Switch", WM8990_RIGHT_LINE_INPUT_3_4_VOLUME,
417 WM8990_RI34MUTE_BIT, 1, 0),
418
419};
420
421/* add non dapm controls */
422static int wm8990_add_controls(struct snd_soc_codec *codec)
423{
424 int err, i;
425
426 for (i = 0; i < ARRAY_SIZE(wm8990_snd_controls); i++) {
427 err = snd_ctl_add(codec->card,
428 snd_soc_cnew(&wm8990_snd_controls[i], codec,
429 NULL));
430 if (err < 0)
431 return err;
432 }
433 return 0;
434}
435
436/*
437 * _DAPM_ Controls
438 */
439
440static int inmixer_event(struct snd_soc_dapm_widget *w,
441 struct snd_kcontrol *kcontrol, int event)
442{
443 u16 reg, fakepower;

--- 729 unchanged lines hidden (view full) ---

1173 * Set PCM DAI bit size and sample rate.
1174 */
1175static int wm8990_hw_params(struct snd_pcm_substream *substream,
1176 struct snd_pcm_hw_params *params,
1177 struct snd_soc_dai *dai)
1178{
1179 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1180 struct snd_soc_device *socdev = rtd->socdev;
421/*
422 * _DAPM_ Controls
423 */
424
425static int inmixer_event(struct snd_soc_dapm_widget *w,
426 struct snd_kcontrol *kcontrol, int event)
427{
428 u16 reg, fakepower;

--- 729 unchanged lines hidden (view full) ---

1158 * Set PCM DAI bit size and sample rate.
1159 */
1160static int wm8990_hw_params(struct snd_pcm_substream *substream,
1161 struct snd_pcm_hw_params *params,
1162 struct snd_soc_dai *dai)
1163{
1164 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1165 struct snd_soc_device *socdev = rtd->socdev;
1181 struct snd_soc_codec *codec = socdev->codec;
1166 struct snd_soc_codec *codec = socdev->card->codec;
1182 u16 audio1 = wm8990_read_reg_cache(codec, WM8990_AUDIO_INTERFACE_1);
1183
1184 audio1 &= ~WM8990_AIF_WL_MASK;
1185 /* bit size */
1186 switch (params_format(params)) {
1187 case SNDRV_PCM_FORMAT_S16_LE:
1188 break;
1189 case SNDRV_PCM_FORMAT_S20_3LE:

--- 152 unchanged lines hidden (view full) ---

1342
1343/*
1344 * The WM8990 supports 2 different and mutually exclusive DAI
1345 * configurations.
1346 *
1347 * 1. ADC/DAC on Primary Interface
1348 * 2. ADC on Primary Interface/DAC on secondary
1349 */
1167 u16 audio1 = wm8990_read_reg_cache(codec, WM8990_AUDIO_INTERFACE_1);
1168
1169 audio1 &= ~WM8990_AIF_WL_MASK;
1170 /* bit size */
1171 switch (params_format(params)) {
1172 case SNDRV_PCM_FORMAT_S16_LE:
1173 break;
1174 case SNDRV_PCM_FORMAT_S20_3LE:

--- 152 unchanged lines hidden (view full) ---

1327
1328/*
1329 * The WM8990 supports 2 different and mutually exclusive DAI
1330 * configurations.
1331 *
1332 * 1. ADC/DAC on Primary Interface
1333 * 2. ADC on Primary Interface/DAC on secondary
1334 */
1335static struct snd_soc_dai_ops wm8990_dai_ops = {
1336 .hw_params = wm8990_hw_params,
1337 .digital_mute = wm8990_mute,
1338 .set_fmt = wm8990_set_dai_fmt,
1339 .set_clkdiv = wm8990_set_dai_clkdiv,
1340 .set_pll = wm8990_set_dai_pll,
1341 .set_sysclk = wm8990_set_dai_sysclk,
1342};
1343
1350struct snd_soc_dai wm8990_dai = {
1351/* ADC/DAC on primary */
1352 .name = "WM8990 ADC/DAC Primary",
1353 .id = 1,
1354 .playback = {
1355 .stream_name = "Playback",
1356 .channels_min = 1,
1357 .channels_max = 2,
1358 .rates = WM8990_RATES,
1359 .formats = WM8990_FORMATS,},
1360 .capture = {
1361 .stream_name = "Capture",
1362 .channels_min = 1,
1363 .channels_max = 2,
1364 .rates = WM8990_RATES,
1365 .formats = WM8990_FORMATS,},
1344struct snd_soc_dai wm8990_dai = {
1345/* ADC/DAC on primary */
1346 .name = "WM8990 ADC/DAC Primary",
1347 .id = 1,
1348 .playback = {
1349 .stream_name = "Playback",
1350 .channels_min = 1,
1351 .channels_max = 2,
1352 .rates = WM8990_RATES,
1353 .formats = WM8990_FORMATS,},
1354 .capture = {
1355 .stream_name = "Capture",
1356 .channels_min = 1,
1357 .channels_max = 2,
1358 .rates = WM8990_RATES,
1359 .formats = WM8990_FORMATS,},
1366 .ops = {
1367 .hw_params = wm8990_hw_params,
1368 .digital_mute = wm8990_mute,
1369 .set_fmt = wm8990_set_dai_fmt,
1370 .set_clkdiv = wm8990_set_dai_clkdiv,
1371 .set_pll = wm8990_set_dai_pll,
1372 .set_sysclk = wm8990_set_dai_sysclk,
1373 },
1360 .ops = &wm8990_dai_ops,
1374};
1375EXPORT_SYMBOL_GPL(wm8990_dai);
1376
1377static int wm8990_suspend(struct platform_device *pdev, pm_message_t state)
1378{
1379 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1361};
1362EXPORT_SYMBOL_GPL(wm8990_dai);
1363
1364static int wm8990_suspend(struct platform_device *pdev, pm_message_t state)
1365{
1366 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1380 struct snd_soc_codec *codec = socdev->codec;
1367 struct snd_soc_codec *codec = socdev->card->codec;
1381
1382 /* we only need to suspend if we are a valid card */
1383 if (!codec->card)
1384 return 0;
1385
1386 wm8990_set_bias_level(codec, SND_SOC_BIAS_OFF);
1387 return 0;
1388}
1389
1390static int wm8990_resume(struct platform_device *pdev)
1391{
1392 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1368
1369 /* we only need to suspend if we are a valid card */
1370 if (!codec->card)
1371 return 0;
1372
1373 wm8990_set_bias_level(codec, SND_SOC_BIAS_OFF);
1374 return 0;
1375}
1376
1377static int wm8990_resume(struct platform_device *pdev)
1378{
1379 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1393 struct snd_soc_codec *codec = socdev->codec;
1380 struct snd_soc_codec *codec = socdev->card->codec;
1394 int i;
1395 u8 data[2];
1396 u16 *cache = codec->reg_cache;
1397
1398 /* we only need to resume if we are a valid card */
1399 if (!codec->card)
1400 return 0;
1401

--- 11 unchanged lines hidden (view full) ---

1413}
1414
1415/*
1416 * initialise the WM8990 driver
1417 * register the mixer and dsp interfaces with the kernel
1418 */
1419static int wm8990_init(struct snd_soc_device *socdev)
1420{
1381 int i;
1382 u8 data[2];
1383 u16 *cache = codec->reg_cache;
1384
1385 /* we only need to resume if we are a valid card */
1386 if (!codec->card)
1387 return 0;
1388

--- 11 unchanged lines hidden (view full) ---

1400}
1401
1402/*
1403 * initialise the WM8990 driver
1404 * register the mixer and dsp interfaces with the kernel
1405 */
1406static int wm8990_init(struct snd_soc_device *socdev)
1407{
1421 struct snd_soc_codec *codec = socdev->codec;
1408 struct snd_soc_codec *codec = socdev->card->codec;
1422 u16 reg;
1423 int ret = 0;
1424
1425 codec->name = "WM8990";
1426 codec->owner = THIS_MODULE;
1427 codec->read = wm8990_read_reg_cache;
1428 codec->write = wm8990_write;
1429 codec->set_bias_level = wm8990_set_bias_level;

--- 26 unchanged lines hidden (view full) ---

1456 wm8990_write(codec, WM8990_GPIO1_GPIO2, reg | 1);
1457
1458 reg = wm8990_read_reg_cache(codec, WM8990_POWER_MANAGEMENT_2);
1459 wm8990_write(codec, WM8990_POWER_MANAGEMENT_2, reg | WM8990_OPCLK_ENA);
1460
1461 wm8990_write(codec, WM8990_LEFT_OUTPUT_VOLUME, 0x50 | (1<<8));
1462 wm8990_write(codec, WM8990_RIGHT_OUTPUT_VOLUME, 0x50 | (1<<8));
1463
1409 u16 reg;
1410 int ret = 0;
1411
1412 codec->name = "WM8990";
1413 codec->owner = THIS_MODULE;
1414 codec->read = wm8990_read_reg_cache;
1415 codec->write = wm8990_write;
1416 codec->set_bias_level = wm8990_set_bias_level;

--- 26 unchanged lines hidden (view full) ---

1443 wm8990_write(codec, WM8990_GPIO1_GPIO2, reg | 1);
1444
1445 reg = wm8990_read_reg_cache(codec, WM8990_POWER_MANAGEMENT_2);
1446 wm8990_write(codec, WM8990_POWER_MANAGEMENT_2, reg | WM8990_OPCLK_ENA);
1447
1448 wm8990_write(codec, WM8990_LEFT_OUTPUT_VOLUME, 0x50 | (1<<8));
1449 wm8990_write(codec, WM8990_RIGHT_OUTPUT_VOLUME, 0x50 | (1<<8));
1450
1464 wm8990_add_controls(codec);
1451 snd_soc_add_controls(codec, wm8990_snd_controls,
1452 ARRAY_SIZE(wm8990_snd_controls));
1465 wm8990_add_widgets(codec);
1466 ret = snd_soc_init_card(socdev);
1467 if (ret < 0) {
1468 printk(KERN_ERR "wm8990: failed to register card\n");
1469 goto card_err;
1470 }
1471 return ret;
1472

--- 17 unchanged lines hidden (view full) ---

1490 * low = 0x34
1491 * high = 0x36
1492 */
1493
1494static int wm8990_i2c_probe(struct i2c_client *i2c,
1495 const struct i2c_device_id *id)
1496{
1497 struct snd_soc_device *socdev = wm8990_socdev;
1453 wm8990_add_widgets(codec);
1454 ret = snd_soc_init_card(socdev);
1455 if (ret < 0) {
1456 printk(KERN_ERR "wm8990: failed to register card\n");
1457 goto card_err;
1458 }
1459 return ret;
1460

--- 17 unchanged lines hidden (view full) ---

1478 * low = 0x34
1479 * high = 0x36
1480 */
1481
1482static int wm8990_i2c_probe(struct i2c_client *i2c,
1483 const struct i2c_device_id *id)
1484{
1485 struct snd_soc_device *socdev = wm8990_socdev;
1498 struct snd_soc_codec *codec = socdev->codec;
1486 struct snd_soc_codec *codec = socdev->card->codec;
1499 int ret;
1500
1501 i2c_set_clientdata(i2c, codec);
1502 codec->control_data = i2c;
1503
1504 ret = wm8990_init(socdev);
1505 if (ret < 0)
1506 pr_err("failed to initialise WM8990\n");

--- 82 unchanged lines hidden (view full) ---

1589
1590 wm8990 = kzalloc(sizeof(struct wm8990_priv), GFP_KERNEL);
1591 if (wm8990 == NULL) {
1592 kfree(codec);
1593 return -ENOMEM;
1594 }
1595
1596 codec->private_data = wm8990;
1487 int ret;
1488
1489 i2c_set_clientdata(i2c, codec);
1490 codec->control_data = i2c;
1491
1492 ret = wm8990_init(socdev);
1493 if (ret < 0)
1494 pr_err("failed to initialise WM8990\n");

--- 82 unchanged lines hidden (view full) ---

1577
1578 wm8990 = kzalloc(sizeof(struct wm8990_priv), GFP_KERNEL);
1579 if (wm8990 == NULL) {
1580 kfree(codec);
1581 return -ENOMEM;
1582 }
1583
1584 codec->private_data = wm8990;
1597 socdev->codec = codec;
1585 socdev->card->codec = codec;
1598 mutex_init(&codec->mutex);
1599 INIT_LIST_HEAD(&codec->dapm_widgets);
1600 INIT_LIST_HEAD(&codec->dapm_paths);
1601 wm8990_socdev = socdev;
1602
1603 ret = -ENODEV;
1604
1605#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)

--- 9 unchanged lines hidden (view full) ---

1615 }
1616 return ret;
1617}
1618
1619/* power down chip */
1620static int wm8990_remove(struct platform_device *pdev)
1621{
1622 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1586 mutex_init(&codec->mutex);
1587 INIT_LIST_HEAD(&codec->dapm_widgets);
1588 INIT_LIST_HEAD(&codec->dapm_paths);
1589 wm8990_socdev = socdev;
1590
1591 ret = -ENODEV;
1592
1593#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)

--- 9 unchanged lines hidden (view full) ---

1603 }
1604 return ret;
1605}
1606
1607/* power down chip */
1608static int wm8990_remove(struct platform_device *pdev)
1609{
1610 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1623 struct snd_soc_codec *codec = socdev->codec;
1611 struct snd_soc_codec *codec = socdev->card->codec;
1624
1625 if (codec->control_data)
1626 wm8990_set_bias_level(codec, SND_SOC_BIAS_OFF);
1627 snd_soc_free_pcms(socdev);
1628 snd_soc_dapm_free(socdev);
1629#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1630 i2c_unregister_device(codec->control_data);
1631 i2c_del_driver(&wm8990_i2c_driver);

--- 30 unchanged lines hidden ---
1612
1613 if (codec->control_data)
1614 wm8990_set_bias_level(codec, SND_SOC_BIAS_OFF);
1615 snd_soc_free_pcms(socdev);
1616 snd_soc_dapm_free(socdev);
1617#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1618 i2c_unregister_device(codec->control_data);
1619 i2c_del_driver(&wm8990_i2c_driver);

--- 30 unchanged lines hidden ---