aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs/wm8990.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/codecs/wm8990.c')
-rw-r--r--sound/soc/codecs/wm8990.c223
1 files changed, 50 insertions, 173 deletions
diff --git a/sound/soc/codecs/wm8990.c b/sound/soc/codecs/wm8990.c
index dd8d909788c1..264828e4e67c 100644
--- a/sound/soc/codecs/wm8990.c
+++ b/sound/soc/codecs/wm8990.c
@@ -32,6 +32,7 @@
32 32
33/* codec private data */ 33/* codec private data */
34struct wm8990_priv { 34struct wm8990_priv {
35 enum snd_soc_control_type control_type;
35 unsigned int sysclk; 36 unsigned int sysclk;
36 unsigned int pcmclk; 37 unsigned int pcmclk;
37}; 38};
@@ -1114,8 +1115,7 @@ static int wm8990_hw_params(struct snd_pcm_substream *substream,
1114 struct snd_soc_dai *dai) 1115 struct snd_soc_dai *dai)
1115{ 1116{
1116 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1117 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1117 struct snd_soc_device *socdev = rtd->socdev; 1118 struct snd_soc_codec *codec = rtd->codec;
1118 struct snd_soc_codec *codec = socdev->card->codec;
1119 u16 audio1 = snd_soc_read(codec, WM8990_AUDIO_INTERFACE_1); 1119 u16 audio1 = snd_soc_read(codec, WM8990_AUDIO_INTERFACE_1);
1120 1120
1121 audio1 &= ~WM8990_AIF_WL_MASK; 1121 audio1 &= ~WM8990_AIF_WL_MASK;
@@ -1293,10 +1293,9 @@ static struct snd_soc_dai_ops wm8990_dai_ops = {
1293 .set_sysclk = wm8990_set_dai_sysclk, 1293 .set_sysclk = wm8990_set_dai_sysclk,
1294}; 1294};
1295 1295
1296struct snd_soc_dai wm8990_dai = { 1296static struct snd_soc_dai_driver wm8990_dai = {
1297/* ADC/DAC on primary */ 1297/* ADC/DAC on primary */
1298 .name = "WM8990 ADC/DAC Primary", 1298 .name = "wm8990-hifi",
1299 .id = 1,
1300 .playback = { 1299 .playback = {
1301 .stream_name = "Playback", 1300 .stream_name = "Playback",
1302 .channels_min = 1, 1301 .channels_min = 1,
@@ -1311,21 +1310,15 @@ struct snd_soc_dai wm8990_dai = {
1311 .formats = WM8990_FORMATS,}, 1310 .formats = WM8990_FORMATS,},
1312 .ops = &wm8990_dai_ops, 1311 .ops = &wm8990_dai_ops,
1313}; 1312};
1314EXPORT_SYMBOL_GPL(wm8990_dai);
1315 1313
1316static int wm8990_suspend(struct platform_device *pdev, pm_message_t state) 1314static int wm8990_suspend(struct snd_soc_codec *codec, pm_message_t state)
1317{ 1315{
1318 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1319 struct snd_soc_codec *codec = socdev->card->codec;
1320
1321 wm8990_set_bias_level(codec, SND_SOC_BIAS_OFF); 1316 wm8990_set_bias_level(codec, SND_SOC_BIAS_OFF);
1322 return 0; 1317 return 0;
1323} 1318}
1324 1319
1325static int wm8990_resume(struct platform_device *pdev) 1320static int wm8990_resume(struct snd_soc_codec *codec)
1326{ 1321{
1327 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1328 struct snd_soc_codec *codec = socdev->card->codec;
1329 int i; 1322 int i;
1330 u8 data[2]; 1323 u8 data[2];
1331 u16 *cache = codec->reg_cache; 1324 u16 *cache = codec->reg_cache;
@@ -1347,40 +1340,20 @@ static int wm8990_resume(struct platform_device *pdev)
1347 * initialise the WM8990 driver 1340 * initialise the WM8990 driver
1348 * register the mixer and dsp interfaces with the kernel 1341 * register the mixer and dsp interfaces with the kernel
1349 */ 1342 */
1350static int wm8990_init(struct snd_soc_device *socdev) 1343static int wm8990_probe(struct snd_soc_codec *codec)
1351{ 1344{
1352 struct snd_soc_codec *codec = socdev->card->codec; 1345 int ret;
1353 u16 reg; 1346 u16 reg;
1354 int ret = 0;
1355
1356 codec->name = "WM8990";
1357 codec->owner = THIS_MODULE;
1358 codec->set_bias_level = wm8990_set_bias_level;
1359 codec->dai = &wm8990_dai;
1360 codec->num_dai = 2;
1361 codec->reg_cache_size = ARRAY_SIZE(wm8990_reg);
1362 codec->reg_cache = kmemdup(wm8990_reg, sizeof(wm8990_reg), GFP_KERNEL);
1363
1364 if (codec->reg_cache == NULL)
1365 return -ENOMEM;
1366 1347
1367 ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_I2C); 1348 ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_I2C);
1368 if (ret < 0) { 1349 if (ret < 0) {
1369 printk(KERN_ERR "wm8990: failed to set cache I/O: %d\n", ret); 1350 printk(KERN_ERR "wm8990: failed to set cache I/O: %d\n", ret);
1370 goto pcm_err; 1351 return ret;
1371 } 1352 }
1372 1353
1373 wm8990_reset(codec); 1354 wm8990_reset(codec);
1374 1355
1375 /* register pcms */
1376 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
1377 if (ret < 0) {
1378 printk(KERN_ERR "wm8990: failed to create pcms\n");
1379 goto pcm_err;
1380 }
1381
1382 /* charge output caps */ 1356 /* charge output caps */
1383 codec->bias_level = SND_SOC_BIAS_OFF;
1384 wm8990_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1357 wm8990_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1385 1358
1386 reg = snd_soc_read(codec, WM8990_AUDIO_INTERFACE_4); 1359 reg = snd_soc_read(codec, WM8990_AUDIO_INTERFACE_4);
@@ -1400,47 +1373,51 @@ static int wm8990_init(struct snd_soc_device *socdev)
1400 ARRAY_SIZE(wm8990_snd_controls)); 1373 ARRAY_SIZE(wm8990_snd_controls));
1401 wm8990_add_widgets(codec); 1374 wm8990_add_widgets(codec);
1402 1375
1403 return ret; 1376 return 0;
1377}
1404 1378
1405pcm_err: 1379/* power down chip */
1406 kfree(codec->reg_cache); 1380static int wm8990_remove(struct snd_soc_codec *codec)
1407 return ret; 1381{
1382 wm8990_set_bias_level(codec, SND_SOC_BIAS_OFF);
1383 return 0;
1408} 1384}
1409 1385
1410/* If the i2c layer weren't so broken, we could pass this kind of data 1386static struct snd_soc_codec_driver soc_codec_dev_wm8990 = {
1411 around */ 1387 .probe = wm8990_probe,
1412static struct snd_soc_device *wm8990_socdev; 1388 .remove = wm8990_remove,
1389 .suspend = wm8990_suspend,
1390 .resume = wm8990_resume,
1391 .set_bias_level = wm8990_set_bias_level,
1392 .reg_cache_size = ARRAY_SIZE(wm8990_reg),
1393 .reg_word_size = sizeof(u16),
1394 .reg_cache_default = wm8990_reg,
1395};
1413 1396
1414#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 1397#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1415 1398static __devinit int wm8990_i2c_probe(struct i2c_client *i2c,
1416/* 1399 const struct i2c_device_id *id)
1417 * WM891 2 wire address is determined by GPIO5
1418 * state during powerup.
1419 * low = 0x34
1420 * high = 0x36
1421 */
1422
1423static int wm8990_i2c_probe(struct i2c_client *i2c,
1424 const struct i2c_device_id *id)
1425{ 1400{
1426 struct snd_soc_device *socdev = wm8990_socdev; 1401 struct wm8990_priv *wm8990;
1427 struct snd_soc_codec *codec = socdev->card->codec;
1428 int ret; 1402 int ret;
1429 1403
1430 i2c_set_clientdata(i2c, codec); 1404 wm8990 = kzalloc(sizeof(struct wm8990_priv), GFP_KERNEL);
1431 codec->control_data = i2c; 1405 if (wm8990 == NULL)
1406 return -ENOMEM;
1432 1407
1433 ret = wm8990_init(socdev); 1408 i2c_set_clientdata(i2c, wm8990);
1434 if (ret < 0)
1435 pr_err("failed to initialise WM8990\n");
1436 1409
1410 ret = snd_soc_register_codec(&i2c->dev,
1411 &soc_codec_dev_wm8990, &wm8990_dai, 1);
1412 if (ret < 0)
1413 kfree(wm8990);
1437 return ret; 1414 return ret;
1438} 1415}
1439 1416
1440static int wm8990_i2c_remove(struct i2c_client *client) 1417static __devexit int wm8990_i2c_remove(struct i2c_client *client)
1441{ 1418{
1442 struct snd_soc_codec *codec = i2c_get_clientdata(client); 1419 snd_soc_unregister_codec(&client->dev);
1443 kfree(codec->reg_cache); 1420 kfree(i2c_get_clientdata(client));
1444 return 0; 1421 return 0;
1445} 1422}
1446 1423
@@ -1452,134 +1429,34 @@ MODULE_DEVICE_TABLE(i2c, wm8990_i2c_id);
1452 1429
1453static struct i2c_driver wm8990_i2c_driver = { 1430static struct i2c_driver wm8990_i2c_driver = {
1454 .driver = { 1431 .driver = {
1455 .name = "WM8990 I2C Codec", 1432 .name = "wm8990-codec",
1456 .owner = THIS_MODULE, 1433 .owner = THIS_MODULE,
1457 }, 1434 },
1458 .probe = wm8990_i2c_probe, 1435 .probe = wm8990_i2c_probe,
1459 .remove = wm8990_i2c_remove, 1436 .remove = __devexit_p(wm8990_i2c_remove),
1460 .id_table = wm8990_i2c_id, 1437 .id_table = wm8990_i2c_id,
1461}; 1438};
1462
1463static int wm8990_add_i2c_device(struct platform_device *pdev,
1464 const struct wm8990_setup_data *setup)
1465{
1466 struct i2c_board_info info;
1467 struct i2c_adapter *adapter;
1468 struct i2c_client *client;
1469 int ret;
1470
1471 ret = i2c_add_driver(&wm8990_i2c_driver);
1472 if (ret != 0) {
1473 dev_err(&pdev->dev, "can't add i2c driver\n");
1474 return ret;
1475 }
1476
1477 memset(&info, 0, sizeof(struct i2c_board_info));
1478 info.addr = setup->i2c_address;
1479 strlcpy(info.type, "wm8990", I2C_NAME_SIZE);
1480
1481 adapter = i2c_get_adapter(setup->i2c_bus);
1482 if (!adapter) {
1483 dev_err(&pdev->dev, "can't get i2c adapter %d\n",
1484 setup->i2c_bus);
1485 goto err_driver;
1486 }
1487
1488 client = i2c_new_device(adapter, &info);
1489 i2c_put_adapter(adapter);
1490 if (!client) {
1491 dev_err(&pdev->dev, "can't add i2c device at 0x%x\n",
1492 (unsigned int)info.addr);
1493 goto err_driver;
1494 }
1495
1496 return 0;
1497
1498err_driver:
1499 i2c_del_driver(&wm8990_i2c_driver);
1500 return -ENODEV;
1501}
1502#endif 1439#endif
1503 1440
1504static int wm8990_probe(struct platform_device *pdev) 1441static int __init wm8990_modinit(void)
1505{ 1442{
1506 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1443 int ret = 0;
1507 struct wm8990_setup_data *setup;
1508 struct snd_soc_codec *codec;
1509 struct wm8990_priv *wm8990;
1510 int ret;
1511
1512 setup = socdev->codec_data;
1513 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
1514 if (codec == NULL)
1515 return -ENOMEM;
1516
1517 wm8990 = kzalloc(sizeof(struct wm8990_priv), GFP_KERNEL);
1518 if (wm8990 == NULL) {
1519 kfree(codec);
1520 return -ENOMEM;
1521 }
1522
1523 snd_soc_codec_set_drvdata(codec, wm8990);
1524 socdev->card->codec = codec;
1525 mutex_init(&codec->mutex);
1526 INIT_LIST_HEAD(&codec->dapm_widgets);
1527 INIT_LIST_HEAD(&codec->dapm_paths);
1528 wm8990_socdev = socdev;
1529
1530 ret = -ENODEV;
1531
1532#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 1444#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1533 if (setup->i2c_address) { 1445 ret = i2c_add_driver(&wm8990_i2c_driver);
1534 codec->hw_write = (hw_write_t)i2c_master_send;
1535 ret = wm8990_add_i2c_device(pdev, setup);
1536 }
1537#endif
1538
1539 if (ret != 0) { 1446 if (ret != 0) {
1540 kfree(snd_soc_codec_get_drvdata(codec)); 1447 printk(KERN_ERR "Failed to register wm8990 I2C driver: %d\n",
1541 kfree(codec); 1448 ret);
1542 } 1449 }
1450#endif
1543 return ret; 1451 return ret;
1544} 1452}
1453module_init(wm8990_modinit);
1545 1454
1546/* power down chip */ 1455static void __exit wm8990_exit(void)
1547static int wm8990_remove(struct platform_device *pdev)
1548{ 1456{
1549 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1550 struct snd_soc_codec *codec = socdev->card->codec;
1551
1552 if (codec->control_data)
1553 wm8990_set_bias_level(codec, SND_SOC_BIAS_OFF);
1554 snd_soc_free_pcms(socdev);
1555 snd_soc_dapm_free(socdev);
1556#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 1457#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1557 i2c_unregister_device(codec->control_data);
1558 i2c_del_driver(&wm8990_i2c_driver); 1458 i2c_del_driver(&wm8990_i2c_driver);
1559#endif 1459#endif
1560 kfree(snd_soc_codec_get_drvdata(codec));
1561 kfree(codec);
1562
1563 return 0;
1564}
1565
1566struct snd_soc_codec_device soc_codec_dev_wm8990 = {
1567 .probe = wm8990_probe,
1568 .remove = wm8990_remove,
1569 .suspend = wm8990_suspend,
1570 .resume = wm8990_resume,
1571};
1572EXPORT_SYMBOL_GPL(soc_codec_dev_wm8990);
1573
1574static int __init wm8990_modinit(void)
1575{
1576 return snd_soc_register_dai(&wm8990_dai);
1577}
1578module_init(wm8990_modinit);
1579
1580static void __exit wm8990_exit(void)
1581{
1582 snd_soc_unregister_dai(&wm8990_dai);
1583} 1460}
1584module_exit(wm8990_exit); 1461module_exit(wm8990_exit);
1585 1462