aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs/wm8993.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/codecs/wm8993.c')
-rw-r--r--sound/soc/codecs/wm8993.c307
1 files changed, 123 insertions, 184 deletions
diff --git a/sound/soc/codecs/wm8993.c b/sound/soc/codecs/wm8993.c
index d8d300c6175f..1d9e1837a2df 100644
--- a/sound/soc/codecs/wm8993.c
+++ b/sound/soc/codecs/wm8993.c
@@ -229,7 +229,8 @@ struct wm8993_priv {
229 u16 reg_cache[WM8993_REGISTER_COUNT]; 229 u16 reg_cache[WM8993_REGISTER_COUNT];
230 struct regulator_bulk_data supplies[WM8993_NUM_SUPPLIES]; 230 struct regulator_bulk_data supplies[WM8993_NUM_SUPPLIES];
231 struct wm8993_platform_data pdata; 231 struct wm8993_platform_data pdata;
232 struct snd_soc_codec codec; 232 enum snd_soc_control_type control_type;
233 void *control_data;
233 int master; 234 int master;
234 int sysclk_source; 235 int sysclk_source;
235 int tdm_slots; 236 int tdm_slots;
@@ -367,10 +368,9 @@ static int fll_factors(struct _fll_div *fll_div, unsigned int Fref,
367 return 0; 368 return 0;
368} 369}
369 370
370static int wm8993_set_fll(struct snd_soc_dai *dai, int fll_id, int source, 371static int _wm8993_set_fll(struct snd_soc_codec *codec, int fll_id, int source,
371 unsigned int Fref, unsigned int Fout) 372 unsigned int Fref, unsigned int Fout)
372{ 373{
373 struct snd_soc_codec *codec = dai->codec;
374 struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec); 374 struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec);
375 u16 reg1, reg4, reg5; 375 u16 reg1, reg4, reg5;
376 struct _fll_div fll_div; 376 struct _fll_div fll_div;
@@ -456,6 +456,12 @@ static int wm8993_set_fll(struct snd_soc_dai *dai, int fll_id, int source,
456 return 0; 456 return 0;
457} 457}
458 458
459static int wm8993_set_fll(struct snd_soc_dai *dai, int fll_id, int source,
460 unsigned int Fref, unsigned int Fout)
461{
462 return _wm8993_set_fll(dai->codec, fll_id, source, Fref, Fout);
463}
464
459static int configure_clock(struct snd_soc_codec *codec) 465static int configure_clock(struct snd_soc_codec *codec)
460{ 466{
461 struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec); 467 struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec);
@@ -1394,8 +1400,8 @@ static struct snd_soc_dai_ops wm8993_ops = {
1394 SNDRV_PCM_FMTBIT_S24_LE |\ 1400 SNDRV_PCM_FMTBIT_S24_LE |\
1395 SNDRV_PCM_FMTBIT_S32_LE) 1401 SNDRV_PCM_FMTBIT_S32_LE)
1396 1402
1397struct snd_soc_dai wm8993_dai = { 1403static struct snd_soc_dai_driver wm8993_dai = {
1398 .name = "WM8993", 1404 .name = "wm8993-hifi",
1399 .playback = { 1405 .playback = {
1400 .stream_name = "Playback", 1406 .stream_name = "Playback",
1401 .channels_min = 1, 1407 .channels_min = 1,
@@ -1413,32 +1419,82 @@ struct snd_soc_dai wm8993_dai = {
1413 .ops = &wm8993_ops, 1419 .ops = &wm8993_ops,
1414 .symmetric_rates = 1, 1420 .symmetric_rates = 1,
1415}; 1421};
1416EXPORT_SYMBOL_GPL(wm8993_dai);
1417
1418static struct snd_soc_codec *wm8993_codec;
1419 1422
1420static int wm8993_probe(struct platform_device *pdev) 1423static int wm8993_probe(struct snd_soc_codec *codec)
1421{ 1424{
1422 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1425 struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec);
1423 struct snd_soc_codec *codec; 1426 int ret, i, val;
1424 struct wm8993_priv *wm8993; 1427
1425 int ret = 0; 1428 codec->control_data = wm8993->control_data;
1429 wm8993->hubs_data.hp_startup_mode = 1;
1430 wm8993->hubs_data.dcs_codes = -2;
1431
1432 ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_I2C);
1433 if (ret != 0) {
1434 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
1435 return ret;
1436 }
1437
1438 for (i = 0; i < ARRAY_SIZE(wm8993->supplies); i++)
1439 wm8993->supplies[i].supply = wm8993_supply_names[i];
1426 1440
1427 if (!wm8993_codec) { 1441 ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(wm8993->supplies),
1428 dev_err(&pdev->dev, "I2C device not yet probed\n"); 1442 wm8993->supplies);
1429 goto err; 1443 if (ret != 0) {
1444 dev_err(codec->dev, "Failed to request supplies: %d\n", ret);
1445 return ret;
1430 } 1446 }
1431 1447
1432 socdev->card->codec = wm8993_codec; 1448 ret = regulator_bulk_enable(ARRAY_SIZE(wm8993->supplies),
1433 codec = wm8993_codec; 1449 wm8993->supplies);
1434 wm8993 = snd_soc_codec_get_drvdata(codec); 1450 if (ret != 0) {
1451 dev_err(codec->dev, "Failed to enable supplies: %d\n", ret);
1452 goto err_get;
1453 }
1435 1454
1436 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); 1455 val = snd_soc_read(codec, WM8993_SOFTWARE_RESET);
1437 if (ret < 0) { 1456 if (val != wm8993_reg_defaults[WM8993_SOFTWARE_RESET]) {
1438 dev_err(codec->dev, "failed to create pcms\n"); 1457 dev_err(codec->dev, "Invalid ID register value %x\n", val);
1439 goto err; 1458 ret = -EINVAL;
1459 goto err_enable;
1440 } 1460 }
1441 1461
1462 ret = snd_soc_write(codec, WM8993_SOFTWARE_RESET, 0xffff);
1463 if (ret != 0)
1464 goto err_enable;
1465
1466 codec->cache_only = 1;
1467
1468 /* By default we're using the output mixers */
1469 wm8993->class_w_users = 2;
1470
1471 /* Latch volume update bits and default ZC on */
1472 snd_soc_update_bits(codec, WM8993_RIGHT_DAC_DIGITAL_VOLUME,
1473 WM8993_DAC_VU, WM8993_DAC_VU);
1474 snd_soc_update_bits(codec, WM8993_RIGHT_ADC_DIGITAL_VOLUME,
1475 WM8993_ADC_VU, WM8993_ADC_VU);
1476
1477 /* Manualy manage the HPOUT sequencing for independent stereo
1478 * control. */
1479 snd_soc_update_bits(codec, WM8993_ANALOGUE_HP_0,
1480 WM8993_HPOUT1_AUTO_PU, 0);
1481
1482 /* Use automatic clock configuration */
1483 snd_soc_update_bits(codec, WM8993_CLOCKING_4, WM8993_SR_MODE, 0);
1484
1485 wm_hubs_handle_analogue_pdata(codec, wm8993->pdata.lineout1_diff,
1486 wm8993->pdata.lineout2_diff,
1487 wm8993->pdata.lineout1fb,
1488 wm8993->pdata.lineout2fb,
1489 wm8993->pdata.jd_scthr,
1490 wm8993->pdata.jd_thr,
1491 wm8993->pdata.micbias1_lvl,
1492 wm8993->pdata.micbias2_lvl);
1493
1494 ret = wm8993_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1495 if (ret != 0)
1496 goto err_enable;
1497
1442 snd_soc_add_controls(codec, wm8993_snd_controls, 1498 snd_soc_add_controls(codec, wm8993_snd_controls,
1443 ARRAY_SIZE(wm8993_snd_controls)); 1499 ARRAY_SIZE(wm8993_snd_controls));
1444 if (wm8993->pdata.num_retune_configs != 0) { 1500 if (wm8993->pdata.num_retune_configs != 0) {
@@ -1457,36 +1513,36 @@ static int wm8993_probe(struct platform_device *pdev)
1457 wm_hubs_add_analogue_routes(codec, wm8993->pdata.lineout1_diff, 1513 wm_hubs_add_analogue_routes(codec, wm8993->pdata.lineout1_diff,
1458 wm8993->pdata.lineout2_diff); 1514 wm8993->pdata.lineout2_diff);
1459 1515
1460 return ret; 1516 return 0;
1461 1517
1462err: 1518err_enable:
1519 regulator_bulk_disable(ARRAY_SIZE(wm8993->supplies), wm8993->supplies);
1520err_get:
1521 regulator_bulk_free(ARRAY_SIZE(wm8993->supplies), wm8993->supplies);
1463 return ret; 1522 return ret;
1464} 1523}
1465 1524
1466static int wm8993_remove(struct platform_device *pdev) 1525static int wm8993_remove(struct snd_soc_codec *codec)
1467{ 1526{
1468 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1527 struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec);
1469
1470 snd_soc_free_pcms(socdev);
1471 snd_soc_dapm_free(socdev);
1472 1528
1529 wm8993_set_bias_level(codec, SND_SOC_BIAS_OFF);
1530 regulator_bulk_free(ARRAY_SIZE(wm8993->supplies), wm8993->supplies);
1473 return 0; 1531 return 0;
1474} 1532}
1475 1533
1476#ifdef CONFIG_PM 1534#ifdef CONFIG_PM
1477static int wm8993_suspend(struct platform_device *pdev, pm_message_t state) 1535static int wm8993_suspend(struct snd_soc_codec *codec, pm_message_t state)
1478{ 1536{
1479 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1480 struct snd_soc_codec *codec = socdev->card->codec;
1481 struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec); 1537 struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec);
1482 int fll_fout = wm8993->fll_fout; 1538 int fll_fout = wm8993->fll_fout;
1483 int fll_fref = wm8993->fll_fref; 1539 int fll_fref = wm8993->fll_fref;
1484 int ret; 1540 int ret;
1485 1541
1486 /* Stop the FLL in an orderly fashion */ 1542 /* Stop the FLL in an orderly fashion */
1487 ret = wm8993_set_fll(codec->dai, 0, 0, 0, 0); 1543 ret = _wm8993_set_fll(codec, 0, 0, 0, 0);
1488 if (ret != 0) { 1544 if (ret != 0) {
1489 dev_err(&pdev->dev, "Failed to stop FLL\n"); 1545 dev_err(codec->dev, "Failed to stop FLL\n");
1490 return ret; 1546 return ret;
1491 } 1547 }
1492 1548
@@ -1498,10 +1554,8 @@ static int wm8993_suspend(struct platform_device *pdev, pm_message_t state)
1498 return 0; 1554 return 0;
1499} 1555}
1500 1556
1501static int wm8993_resume(struct platform_device *pdev) 1557static int wm8993_resume(struct snd_soc_codec *codec)
1502{ 1558{
1503 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1504 struct snd_soc_codec *codec = socdev->card->codec;
1505 struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec); 1559 struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec);
1506 int ret; 1560 int ret;
1507 1561
@@ -1515,7 +1569,7 @@ static int wm8993_resume(struct platform_device *pdev)
1515 wm8993->fll_fref = 0; 1569 wm8993->fll_fref = 0;
1516 wm8993->fll_fout = 0; 1570 wm8993->fll_fout = 0;
1517 1571
1518 ret = wm8993_set_fll(codec->dai, 0, wm8993->fll_src, 1572 ret = _wm8993_set_fll(codec, 0, wm8993->fll_src,
1519 fll_fref, fll_fout); 1573 fll_fref, fll_fout);
1520 if (ret != 0) 1574 if (ret != 0)
1521 dev_err(codec->dev, "Failed to restart FLL\n"); 1575 dev_err(codec->dev, "Failed to restart FLL\n");
@@ -1528,162 +1582,43 @@ static int wm8993_resume(struct platform_device *pdev)
1528#define wm8993_resume NULL 1582#define wm8993_resume NULL
1529#endif 1583#endif
1530 1584
1531struct snd_soc_codec_device soc_codec_dev_wm8993 = { 1585static struct snd_soc_codec_driver soc_codec_dev_wm8993 = {
1532 .probe = wm8993_probe, 1586 .probe = wm8993_probe,
1533 .remove = wm8993_remove, 1587 .remove = wm8993_remove,
1534 .suspend = wm8993_suspend, 1588 .suspend = wm8993_suspend,
1535 .resume = wm8993_resume, 1589 .resume = wm8993_resume,
1590 .set_bias_level = wm8993_set_bias_level,
1591 .reg_cache_size = sizeof(wm8993_reg_defaults),
1592 .reg_word_size = sizeof(u16),
1593 .reg_cache_default = wm8993_reg_defaults,
1594 .volatile_register = wm8993_volatile,
1536}; 1595};
1537EXPORT_SYMBOL_GPL(soc_codec_dev_wm8993);
1538 1596
1539static int wm8993_i2c_probe(struct i2c_client *i2c, 1597#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1540 const struct i2c_device_id *id) 1598static __devinit int wm8993_i2c_probe(struct i2c_client *i2c,
1599 const struct i2c_device_id *id)
1541{ 1600{
1542 struct wm8993_priv *wm8993; 1601 struct wm8993_priv *wm8993;
1543 struct snd_soc_codec *codec;
1544 unsigned int val;
1545 int ret; 1602 int ret;
1546 int i;
1547
1548 if (wm8993_codec) {
1549 dev_err(&i2c->dev, "A WM8993 is already registered\n");
1550 return -EINVAL;
1551 }
1552 1603
1553 wm8993 = kzalloc(sizeof(struct wm8993_priv), GFP_KERNEL); 1604 wm8993 = kzalloc(sizeof(struct wm8993_priv), GFP_KERNEL);
1554 if (wm8993 == NULL) 1605 if (wm8993 == NULL)
1555 return -ENOMEM; 1606 return -ENOMEM;
1556 1607
1557 codec = &wm8993->codec;
1558 if (i2c->dev.platform_data)
1559 memcpy(&wm8993->pdata, i2c->dev.platform_data,
1560 sizeof(wm8993->pdata));
1561
1562 mutex_init(&codec->mutex);
1563 INIT_LIST_HEAD(&codec->dapm_widgets);
1564 INIT_LIST_HEAD(&codec->dapm_paths);
1565
1566 codec->name = "WM8993";
1567 codec->volatile_register = wm8993_volatile;
1568 codec->reg_cache = wm8993->reg_cache;
1569 codec->reg_cache_size = ARRAY_SIZE(wm8993->reg_cache);
1570 codec->bias_level = SND_SOC_BIAS_OFF;
1571 codec->set_bias_level = wm8993_set_bias_level;
1572 codec->dai = &wm8993_dai;
1573 codec->num_dai = 1;
1574 snd_soc_codec_set_drvdata(codec, wm8993);
1575
1576 wm8993->hubs_data.hp_startup_mode = 1;
1577 wm8993->hubs_data.dcs_codes = -2;
1578
1579 memcpy(wm8993->reg_cache, wm8993_reg_defaults,
1580 sizeof(wm8993->reg_cache));
1581
1582 ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_I2C);
1583 if (ret != 0) {
1584 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
1585 goto err;
1586 }
1587
1588 i2c_set_clientdata(i2c, wm8993); 1608 i2c_set_clientdata(i2c, wm8993);
1589 codec->control_data = i2c; 1609 wm8993->control_data = i2c;
1590 wm8993_codec = codec;
1591
1592 codec->dev = &i2c->dev;
1593
1594 for (i = 0; i < ARRAY_SIZE(wm8993->supplies); i++)
1595 wm8993->supplies[i].supply = wm8993_supply_names[i];
1596
1597 ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(wm8993->supplies),
1598 wm8993->supplies);
1599 if (ret != 0) {
1600 dev_err(codec->dev, "Failed to request supplies: %d\n", ret);
1601 goto err;
1602 }
1603
1604 ret = regulator_bulk_enable(ARRAY_SIZE(wm8993->supplies),
1605 wm8993->supplies);
1606 if (ret != 0) {
1607 dev_err(codec->dev, "Failed to enable supplies: %d\n", ret);
1608 goto err_get;
1609 }
1610
1611 val = snd_soc_read(codec, WM8993_SOFTWARE_RESET);
1612 if (val != wm8993_reg_defaults[WM8993_SOFTWARE_RESET]) {
1613 dev_err(codec->dev, "Invalid ID register value %x\n", val);
1614 ret = -EINVAL;
1615 goto err_enable;
1616 }
1617
1618 ret = snd_soc_write(codec, WM8993_SOFTWARE_RESET, 0xffff);
1619 if (ret != 0)
1620 goto err_enable;
1621
1622 codec->cache_only = 1;
1623
1624 /* By default we're using the output mixers */
1625 wm8993->class_w_users = 2;
1626
1627 /* Latch volume update bits and default ZC on */
1628 snd_soc_update_bits(codec, WM8993_RIGHT_DAC_DIGITAL_VOLUME,
1629 WM8993_DAC_VU, WM8993_DAC_VU);
1630 snd_soc_update_bits(codec, WM8993_RIGHT_ADC_DIGITAL_VOLUME,
1631 WM8993_ADC_VU, WM8993_ADC_VU);
1632 1610
1633 /* Manualy manage the HPOUT sequencing for independent stereo 1611 ret = snd_soc_register_codec(&i2c->dev,
1634 * control. */ 1612 &soc_codec_dev_wm8993, &wm8993_dai, 1);
1635 snd_soc_update_bits(codec, WM8993_ANALOGUE_HP_0, 1613 if (ret < 0)
1636 WM8993_HPOUT1_AUTO_PU, 0); 1614 kfree(wm8993);
1637
1638 /* Use automatic clock configuration */
1639 snd_soc_update_bits(codec, WM8993_CLOCKING_4, WM8993_SR_MODE, 0);
1640
1641 wm_hubs_handle_analogue_pdata(codec, wm8993->pdata.lineout1_diff,
1642 wm8993->pdata.lineout2_diff,
1643 wm8993->pdata.lineout1fb,
1644 wm8993->pdata.lineout2fb,
1645 wm8993->pdata.jd_scthr,
1646 wm8993->pdata.jd_thr,
1647 wm8993->pdata.micbias1_lvl,
1648 wm8993->pdata.micbias2_lvl);
1649
1650 ret = wm8993_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1651 if (ret != 0)
1652 goto err_enable;
1653
1654 wm8993_dai.dev = codec->dev;
1655
1656 ret = snd_soc_register_dai(&wm8993_dai);
1657 if (ret != 0)
1658 goto err_bias;
1659
1660 ret = snd_soc_register_codec(codec);
1661
1662 return 0;
1663
1664err_bias:
1665 wm8993_set_bias_level(codec, SND_SOC_BIAS_OFF);
1666err_enable:
1667 regulator_bulk_disable(ARRAY_SIZE(wm8993->supplies), wm8993->supplies);
1668err_get:
1669 regulator_bulk_free(ARRAY_SIZE(wm8993->supplies), wm8993->supplies);
1670err:
1671 wm8993_codec = NULL;
1672 kfree(wm8993);
1673 return ret; 1615 return ret;
1674} 1616}
1675 1617
1676static int wm8993_i2c_remove(struct i2c_client *client) 1618static __devexit int wm8993_i2c_remove(struct i2c_client *client)
1677{ 1619{
1678 struct wm8993_priv *wm8993 = i2c_get_clientdata(client); 1620 snd_soc_unregister_codec(&client->dev);
1679 1621 kfree(i2c_get_clientdata(client));
1680 snd_soc_unregister_codec(&wm8993->codec);
1681 snd_soc_unregister_dai(&wm8993_dai);
1682
1683 wm8993_set_bias_level(&wm8993->codec, SND_SOC_BIAS_OFF);
1684 regulator_bulk_free(ARRAY_SIZE(wm8993->supplies), wm8993->supplies);
1685 kfree(wm8993);
1686
1687 return 0; 1622 return 0;
1688} 1623}
1689 1624
@@ -1695,30 +1630,34 @@ MODULE_DEVICE_TABLE(i2c, wm8993_i2c_id);
1695 1630
1696static struct i2c_driver wm8993_i2c_driver = { 1631static struct i2c_driver wm8993_i2c_driver = {
1697 .driver = { 1632 .driver = {
1698 .name = "WM8993", 1633 .name = "wm8993-codec",
1699 .owner = THIS_MODULE, 1634 .owner = THIS_MODULE,
1700 }, 1635 },
1701 .probe = wm8993_i2c_probe, 1636 .probe = wm8993_i2c_probe,
1702 .remove = wm8993_i2c_remove, 1637 .remove = __devexit_p(wm8993_i2c_remove),
1703 .id_table = wm8993_i2c_id, 1638 .id_table = wm8993_i2c_id,
1704}; 1639};
1705 1640#endif
1706 1641
1707static int __init wm8993_modinit(void) 1642static int __init wm8993_modinit(void)
1708{ 1643{
1709 int ret; 1644 int ret = 0;
1710 1645#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1711 ret = i2c_add_driver(&wm8993_i2c_driver); 1646 ret = i2c_add_driver(&wm8993_i2c_driver);
1712 if (ret != 0) 1647 if (ret != 0) {
1713 pr_err("WM8993: Unable to register I2C driver: %d\n", ret); 1648 pr_err("WM8993: Unable to register I2C driver: %d\n",
1714 1649 ret);
1650 }
1651#endif
1715 return ret; 1652 return ret;
1716} 1653}
1717module_init(wm8993_modinit); 1654module_init(wm8993_modinit);
1718 1655
1719static void __exit wm8993_exit(void) 1656static void __exit wm8993_exit(void)
1720{ 1657{
1658#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1721 i2c_del_driver(&wm8993_i2c_driver); 1659 i2c_del_driver(&wm8993_i2c_driver);
1660#endif
1722} 1661}
1723module_exit(wm8993_exit); 1662module_exit(wm8993_exit);
1724 1663