aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Thomson <Adam.Thomson.Opensource@diasemi.com>2015-10-07 09:27:08 -0400
committerMark Brown <broonie@kernel.org>2015-10-07 10:11:34 -0400
commite90996a3ea224fbeb459b8052ecd366d7990e1f3 (patch)
treed03945c1e5311b26e1468e810e27623f8b88861f
parent6ff33f3902c3b1c5d0db6b1e2c70b6d76fba357f (diff)
ASoC: da7213: Add DT support to codec driver
This patch adds support for DT bindings in the codec driver. As part of this support, the mclk data can now be provided and used to control the mclk during codec operation. Signed-off-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com> Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--sound/soc/codecs/da7213.c123
1 files changed, 118 insertions, 5 deletions
diff --git a/sound/soc/codecs/da7213.c b/sound/soc/codecs/da7213.c
index a9c86efb3187..ab1486b04c30 100644
--- a/sound/soc/codecs/da7213.c
+++ b/sound/soc/codecs/da7213.c
@@ -1387,10 +1387,118 @@ static int da7213_set_bias_level(struct snd_soc_codec *codec,
1387 return 0; 1387 return 0;
1388} 1388}
1389 1389
1390/* DT */
1391static const struct of_device_id da7213_of_match[] = {
1392 { .compatible = "dlg,da7213", },
1393 { }
1394};
1395MODULE_DEVICE_TABLE(of, da7213_of_match);
1396
1397static enum da7213_micbias_voltage
1398 da7213_of_micbias_lvl(struct snd_soc_codec *codec, u32 val)
1399{
1400 switch (val) {
1401 case 1600:
1402 return DA7213_MICBIAS_1_6V;
1403 case 2200:
1404 return DA7213_MICBIAS_2_2V;
1405 case 2500:
1406 return DA7213_MICBIAS_2_5V;
1407 case 3000:
1408 return DA7213_MICBIAS_3_0V;
1409 default:
1410 dev_warn(codec->dev, "Invalid micbias level\n");
1411 return DA7213_MICBIAS_2_2V;
1412 }
1413}
1414
1415static enum da7213_dmic_data_sel
1416 da7213_of_dmic_data_sel(struct snd_soc_codec *codec, const char *str)
1417{
1418 if (!strcmp(str, "lrise_rfall")) {
1419 return DA7213_DMIC_DATA_LRISE_RFALL;
1420 } else if (!strcmp(str, "lfall_rrise")) {
1421 return DA7213_DMIC_DATA_LFALL_RRISE;
1422 } else {
1423 dev_warn(codec->dev, "Invalid DMIC data select type\n");
1424 return DA7213_DMIC_DATA_LRISE_RFALL;
1425 }
1426}
1427
1428static enum da7213_dmic_samplephase
1429 da7213_of_dmic_samplephase(struct snd_soc_codec *codec, const char *str)
1430{
1431 if (!strcmp(str, "on_clkedge")) {
1432 return DA7213_DMIC_SAMPLE_ON_CLKEDGE;
1433 } else if (!strcmp(str, "between_clkedge")) {
1434 return DA7213_DMIC_SAMPLE_BETWEEN_CLKEDGE;
1435 } else {
1436 dev_warn(codec->dev, "Invalid DMIC sample phase\n");
1437 return DA7213_DMIC_SAMPLE_ON_CLKEDGE;
1438 }
1439}
1440
1441static enum da7213_dmic_clk_rate
1442 da7213_of_dmic_clkrate(struct snd_soc_codec *codec, u32 val)
1443{
1444 switch (val) {
1445 case 1500000:
1446 return DA7213_DMIC_CLK_1_5MHZ;
1447 case 3000000:
1448 return DA7213_DMIC_CLK_3_0MHZ;
1449 default:
1450 dev_warn(codec->dev, "Invalid DMIC clock rate\n");
1451 return DA7213_DMIC_CLK_1_5MHZ;
1452 }
1453}
1454
1455static struct da7213_platform_data
1456 *da7213_of_to_pdata(struct snd_soc_codec *codec)
1457{
1458 struct device_node *np = codec->dev->of_node;
1459 struct da7213_platform_data *pdata;
1460 const char *of_str;
1461 u32 of_val32;
1462
1463 pdata = devm_kzalloc(codec->dev, sizeof(*pdata), GFP_KERNEL);
1464 if (!pdata) {
1465 dev_warn(codec->dev, "Failed to allocate memory for pdata\n");
1466 return NULL;
1467 }
1468
1469 if (of_property_read_u32(np, "dlg,micbias1-lvl", &of_val32) >= 0)
1470 pdata->micbias1_lvl = da7213_of_micbias_lvl(codec, of_val32);
1471 else
1472 pdata->micbias1_lvl = DA7213_MICBIAS_2_2V;
1473
1474 if (of_property_read_u32(np, "dlg,micbias2-lvl", &of_val32) >= 0)
1475 pdata->micbias2_lvl = da7213_of_micbias_lvl(codec, of_val32);
1476 else
1477 pdata->micbias2_lvl = DA7213_MICBIAS_2_2V;
1478
1479 if (!of_property_read_string(np, "dlg,dmic-data-sel", &of_str))
1480 pdata->dmic_data_sel = da7213_of_dmic_data_sel(codec, of_str);
1481 else
1482 pdata->dmic_data_sel = DA7213_DMIC_DATA_LRISE_RFALL;
1483
1484 if (!of_property_read_string(np, "dlg,dmic-samplephase", &of_str))
1485 pdata->dmic_samplephase =
1486 da7213_of_dmic_samplephase(codec, of_str);
1487 else
1488 pdata->dmic_samplephase = DA7213_DMIC_SAMPLE_ON_CLKEDGE;
1489
1490 if (of_property_read_u32(np, "dlg,dmic-clkrate", &of_val32) >= 0)
1491 pdata->dmic_clk_rate = da7213_of_dmic_clkrate(codec, of_val32);
1492 else
1493 pdata->dmic_clk_rate = DA7213_DMIC_CLK_3_0MHZ;
1494
1495 return pdata;
1496}
1497
1498
1390static int da7213_probe(struct snd_soc_codec *codec) 1499static int da7213_probe(struct snd_soc_codec *codec)
1391{ 1500{
1392 struct da7213_priv *da7213 = snd_soc_codec_get_drvdata(codec); 1501 struct da7213_priv *da7213 = snd_soc_codec_get_drvdata(codec);
1393 struct da7213_platform_data *pdata = da7213->pdata;
1394 1502
1395 /* Default to using ALC auto offset calibration mode. */ 1503 /* Default to using ALC auto offset calibration mode. */
1396 snd_soc_update_bits(codec, DA7213_ALC_CTRL1, 1504 snd_soc_update_bits(codec, DA7213_ALC_CTRL1,
@@ -1450,8 +1558,15 @@ static int da7213_probe(struct snd_soc_codec *codec)
1450 snd_soc_update_bits(codec, DA7213_LINE_CTRL, 1558 snd_soc_update_bits(codec, DA7213_LINE_CTRL,
1451 DA7213_LINE_AMP_OE, DA7213_LINE_AMP_OE); 1559 DA7213_LINE_AMP_OE, DA7213_LINE_AMP_OE);
1452 1560
1561 /* Handle DT/Platform data */
1562 if (codec->dev->of_node)
1563 da7213->pdata = da7213_of_to_pdata(codec);
1564 else
1565 da7213->pdata = dev_get_platdata(codec->dev);
1566
1453 /* Set platform data values */ 1567 /* Set platform data values */
1454 if (da7213->pdata) { 1568 if (da7213->pdata) {
1569 struct da7213_platform_data *pdata = da7213->pdata;
1455 u8 micbias_lvl = 0, dmic_cfg = 0; 1570 u8 micbias_lvl = 0, dmic_cfg = 0;
1456 1571
1457 /* Set Mic Bias voltages */ 1572 /* Set Mic Bias voltages */
@@ -1507,6 +1622,7 @@ static int da7213_probe(struct snd_soc_codec *codec)
1507 /* Set MCLK squaring */ 1622 /* Set MCLK squaring */
1508 da7213->mclk_squarer_en = pdata->mclk_squaring; 1623 da7213->mclk_squarer_en = pdata->mclk_squaring;
1509 } 1624 }
1625
1510 return 0; 1626 return 0;
1511} 1627}
1512 1628
@@ -1537,7 +1653,6 @@ static int da7213_i2c_probe(struct i2c_client *i2c,
1537 const struct i2c_device_id *id) 1653 const struct i2c_device_id *id)
1538{ 1654{
1539 struct da7213_priv *da7213; 1655 struct da7213_priv *da7213;
1540 struct da7213_platform_data *pdata = dev_get_platdata(&i2c->dev);
1541 int ret; 1656 int ret;
1542 1657
1543 da7213 = devm_kzalloc(&i2c->dev, sizeof(struct da7213_priv), 1658 da7213 = devm_kzalloc(&i2c->dev, sizeof(struct da7213_priv),
@@ -1545,9 +1660,6 @@ static int da7213_i2c_probe(struct i2c_client *i2c,
1545 if (!da7213) 1660 if (!da7213)
1546 return -ENOMEM; 1661 return -ENOMEM;
1547 1662
1548 if (pdata)
1549 da7213->pdata = pdata;
1550
1551 i2c_set_clientdata(i2c, da7213); 1663 i2c_set_clientdata(i2c, da7213);
1552 1664
1553 da7213->regmap = devm_regmap_init_i2c(i2c, &da7213_regmap_config); 1665 da7213->regmap = devm_regmap_init_i2c(i2c, &da7213_regmap_config);
@@ -1582,6 +1694,7 @@ MODULE_DEVICE_TABLE(i2c, da7213_i2c_id);
1582static struct i2c_driver da7213_i2c_driver = { 1694static struct i2c_driver da7213_i2c_driver = {
1583 .driver = { 1695 .driver = {
1584 .name = "da7213", 1696 .name = "da7213",
1697 .of_match_table = of_match_ptr(da7213_of_match),
1585 }, 1698 },
1586 .probe = da7213_i2c_probe, 1699 .probe = da7213_i2c_probe,
1587 .remove = da7213_remove, 1700 .remove = da7213_remove,