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