aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs/tlv320dac33.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/codecs/tlv320dac33.c')
-rw-r--r--sound/soc/codecs/tlv320dac33.c249
1 files changed, 82 insertions, 167 deletions
diff --git a/sound/soc/codecs/tlv320dac33.c b/sound/soc/codecs/tlv320dac33.c
index 8651b01ed223..a3c5b521da6a 100644
--- a/sound/soc/codecs/tlv320dac33.c
+++ b/sound/soc/codecs/tlv320dac33.c
@@ -66,8 +66,6 @@
66static void dac33_calculate_times(struct snd_pcm_substream *substream); 66static void dac33_calculate_times(struct snd_pcm_substream *substream);
67static int dac33_prepare_chip(struct snd_pcm_substream *substream); 67static int dac33_prepare_chip(struct snd_pcm_substream *substream);
68 68
69static struct snd_soc_codec *tlv320dac33_codec;
70
71enum dac33_state { 69enum dac33_state {
72 DAC33_IDLE = 0, 70 DAC33_IDLE = 0,
73 DAC33_PREFILL, 71 DAC33_PREFILL,
@@ -93,7 +91,7 @@ struct tlv320dac33_priv {
93 struct mutex mutex; 91 struct mutex mutex;
94 struct workqueue_struct *dac33_wq; 92 struct workqueue_struct *dac33_wq;
95 struct work_struct work; 93 struct work_struct work;
96 struct snd_soc_codec codec; 94 struct snd_soc_codec *codec;
97 struct regulator_bulk_data supplies[DAC33_NUM_SUPPLIES]; 95 struct regulator_bulk_data supplies[DAC33_NUM_SUPPLIES];
98 struct snd_pcm_substream *substream; 96 struct snd_pcm_substream *substream;
99 int power_gpio; 97 int power_gpio;
@@ -128,6 +126,8 @@ struct tlv320dac33_priv {
128 unsigned int uthr; 126 unsigned int uthr;
129 127
130 enum dac33_state state; 128 enum dac33_state state;
129 enum snd_soc_control_type control_type;
130 void *control_data;
131}; 131};
132 132
133static const u8 dac33_reg[DAC33_CACHEREGNUM] = { 133static const u8 dac33_reg[DAC33_CACHEREGNUM] = {
@@ -650,9 +650,7 @@ static int dac33_set_bias_level(struct snd_soc_codec *codec,
650 650
651static inline void dac33_prefill_handler(struct tlv320dac33_priv *dac33) 651static inline void dac33_prefill_handler(struct tlv320dac33_priv *dac33)
652{ 652{
653 struct snd_soc_codec *codec; 653 struct snd_soc_codec *codec = dac33->codec;
654
655 codec = &dac33->codec;
656 654
657 switch (dac33->fifo_mode) { 655 switch (dac33->fifo_mode) {
658 case DAC33_FIFO_MODE1: 656 case DAC33_FIFO_MODE1:
@@ -695,9 +693,7 @@ static inline void dac33_prefill_handler(struct tlv320dac33_priv *dac33)
695 693
696static inline void dac33_playback_handler(struct tlv320dac33_priv *dac33) 694static inline void dac33_playback_handler(struct tlv320dac33_priv *dac33)
697{ 695{
698 struct snd_soc_codec *codec; 696 struct snd_soc_codec *codec = dac33->codec;
699
700 codec = &dac33->codec;
701 697
702 switch (dac33->fifo_mode) { 698 switch (dac33->fifo_mode) {
703 case DAC33_FIFO_MODE1: 699 case DAC33_FIFO_MODE1:
@@ -726,7 +722,7 @@ static void dac33_work(struct work_struct *work)
726 u8 reg; 722 u8 reg;
727 723
728 dac33 = container_of(work, struct tlv320dac33_priv, work); 724 dac33 = container_of(work, struct tlv320dac33_priv, work);
729 codec = &dac33->codec; 725 codec = dac33->codec;
730 726
731 mutex_lock(&dac33->mutex); 727 mutex_lock(&dac33->mutex);
732 switch (dac33->state) { 728 switch (dac33->state) {
@@ -787,8 +783,7 @@ static int dac33_startup(struct snd_pcm_substream *substream,
787 struct snd_soc_dai *dai) 783 struct snd_soc_dai *dai)
788{ 784{
789 struct snd_soc_pcm_runtime *rtd = substream->private_data; 785 struct snd_soc_pcm_runtime *rtd = substream->private_data;
790 struct snd_soc_device *socdev = rtd->socdev; 786 struct snd_soc_codec *codec = rtd->codec;
791 struct snd_soc_codec *codec = socdev->card->codec;
792 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); 787 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
793 788
794 /* Stream started, save the substream pointer */ 789 /* Stream started, save the substream pointer */
@@ -801,8 +796,7 @@ static void dac33_shutdown(struct snd_pcm_substream *substream,
801 struct snd_soc_dai *dai) 796 struct snd_soc_dai *dai)
802{ 797{
803 struct snd_soc_pcm_runtime *rtd = substream->private_data; 798 struct snd_soc_pcm_runtime *rtd = substream->private_data;
804 struct snd_soc_device *socdev = rtd->socdev; 799 struct snd_soc_codec *codec = rtd->codec;
805 struct snd_soc_codec *codec = socdev->card->codec;
806 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); 800 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
807 801
808 dac33->substream = NULL; 802 dac33->substream = NULL;
@@ -817,8 +811,7 @@ static int dac33_hw_params(struct snd_pcm_substream *substream,
817 struct snd_soc_dai *dai) 811 struct snd_soc_dai *dai)
818{ 812{
819 struct snd_soc_pcm_runtime *rtd = substream->private_data; 813 struct snd_soc_pcm_runtime *rtd = substream->private_data;
820 struct snd_soc_device *socdev = rtd->socdev; 814 struct snd_soc_codec *codec = rtd->codec;
821 struct snd_soc_codec *codec = socdev->card->codec;
822 815
823 /* Check parameters for validity */ 816 /* Check parameters for validity */
824 switch (params_rate(params)) { 817 switch (params_rate(params)) {
@@ -856,8 +849,7 @@ static int dac33_hw_params(struct snd_pcm_substream *substream,
856static int dac33_prepare_chip(struct snd_pcm_substream *substream) 849static int dac33_prepare_chip(struct snd_pcm_substream *substream)
857{ 850{
858 struct snd_soc_pcm_runtime *rtd = substream->private_data; 851 struct snd_soc_pcm_runtime *rtd = substream->private_data;
859 struct snd_soc_device *socdev = rtd->socdev; 852 struct snd_soc_codec *codec = rtd->codec;
860 struct snd_soc_codec *codec = socdev->card->codec;
861 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); 853 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
862 unsigned int oscset, ratioset, pwr_ctrl, reg_tmp; 854 unsigned int oscset, ratioset, pwr_ctrl, reg_tmp;
863 u8 aictrl_a, aictrl_b, fifoctrl_a; 855 u8 aictrl_a, aictrl_b, fifoctrl_a;
@@ -1049,8 +1041,7 @@ static int dac33_prepare_chip(struct snd_pcm_substream *substream)
1049static void dac33_calculate_times(struct snd_pcm_substream *substream) 1041static void dac33_calculate_times(struct snd_pcm_substream *substream)
1050{ 1042{
1051 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1043 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1052 struct snd_soc_device *socdev = rtd->socdev; 1044 struct snd_soc_codec *codec = rtd->codec;
1053 struct snd_soc_codec *codec = socdev->card->codec;
1054 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); 1045 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
1055 unsigned int period_size = substream->runtime->period_size; 1046 unsigned int period_size = substream->runtime->period_size;
1056 unsigned int rate = substream->runtime->rate; 1047 unsigned int rate = substream->runtime->rate;
@@ -1129,8 +1120,7 @@ static int dac33_pcm_trigger(struct snd_pcm_substream *substream, int cmd,
1129 struct snd_soc_dai *dai) 1120 struct snd_soc_dai *dai)
1130{ 1121{
1131 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1122 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1132 struct snd_soc_device *socdev = rtd->socdev; 1123 struct snd_soc_codec *codec = rtd->codec;
1133 struct snd_soc_codec *codec = socdev->card->codec;
1134 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); 1124 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
1135 int ret = 0; 1125 int ret = 0;
1136 1126
@@ -1163,8 +1153,7 @@ static snd_pcm_sframes_t dac33_dai_delay(
1163 struct snd_soc_dai *dai) 1153 struct snd_soc_dai *dai)
1164{ 1154{
1165 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1155 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1166 struct snd_soc_device *socdev = rtd->socdev; 1156 struct snd_soc_codec *codec = rtd->codec;
1167 struct snd_soc_codec *codec = socdev->card->codec;
1168 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); 1157 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
1169 unsigned long long t0, t1, t_now; 1158 unsigned long long t0, t1, t_now;
1170 unsigned int time_delta, uthr; 1159 unsigned int time_delta, uthr;
@@ -1389,24 +1378,47 @@ static int dac33_set_dai_fmt(struct snd_soc_dai *codec_dai,
1389 return 0; 1378 return 0;
1390} 1379}
1391 1380
1392static int dac33_soc_probe(struct platform_device *pdev) 1381static int dac33_soc_probe(struct snd_soc_codec *codec)
1393{ 1382{
1394 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1383 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
1395 struct snd_soc_codec *codec;
1396 struct tlv320dac33_priv *dac33;
1397 int ret = 0; 1384 int ret = 0;
1398 1385
1399 BUG_ON(!tlv320dac33_codec); 1386 codec->control_data = dac33->control_data;
1387 codec->hw_write = (hw_write_t) i2c_master_send;
1388 codec->bias_level = SND_SOC_BIAS_OFF;
1389 codec->idle_bias_off = 1;
1390 dac33->codec = codec;
1400 1391
1401 codec = tlv320dac33_codec; 1392 /* Read the tlv320dac33 ID registers */
1402 socdev->card->codec = codec; 1393 ret = dac33_hard_power(codec, 1);
1403 dac33 = snd_soc_codec_get_drvdata(codec); 1394 if (ret != 0) {
1395 dev_err(codec->dev, "Failed to power up codec: %d\n", ret);
1396 goto err_power;
1397 }
1398 dac33_read_id(codec);
1399 dac33_hard_power(codec, 0);
1404 1400
1405 /* register pcms */ 1401 /* Check if the IRQ number is valid and request it */
1406 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); 1402 if (dac33->irq >= 0) {
1407 if (ret < 0) { 1403 ret = request_irq(dac33->irq, dac33_interrupt_handler,
1408 dev_err(codec->dev, "failed to create pcms\n"); 1404 IRQF_TRIGGER_RISING | IRQF_DISABLED,
1409 goto pcm_err; 1405 codec->name, codec);
1406 if (ret < 0) {
1407 dev_err(codec->dev, "Could not request IRQ%d (%d)\n",
1408 dac33->irq, ret);
1409 dac33->irq = -1;
1410 }
1411 if (dac33->irq != -1) {
1412 /* Setup work queue */
1413 dac33->dac33_wq =
1414 create_singlethread_workqueue("tlv320dac33");
1415 if (dac33->dac33_wq == NULL) {
1416 free_irq(dac33->irq, codec);
1417 return -ENOMEM;
1418 }
1419
1420 INIT_WORK(&dac33->work, dac33_work);
1421 }
1410 } 1422 }
1411 1423
1412 snd_soc_add_controls(codec, dac33_snd_controls, 1424 snd_soc_add_controls(codec, dac33_snd_controls,
@@ -1420,56 +1432,51 @@ static int dac33_soc_probe(struct platform_device *pdev)
1420 snd_soc_add_controls(codec, dac33_fifo_snd_controls, 1432 snd_soc_add_controls(codec, dac33_fifo_snd_controls,
1421 ARRAY_SIZE(dac33_fifo_snd_controls)); 1433 ARRAY_SIZE(dac33_fifo_snd_controls));
1422 } 1434 }
1423
1424 dac33_add_widgets(codec); 1435 dac33_add_widgets(codec);
1425 1436
1426 return 0; 1437err_power:
1427
1428pcm_err:
1429 dac33_hard_power(codec, 0);
1430 return ret; 1438 return ret;
1431} 1439}
1432 1440
1433static int dac33_soc_remove(struct platform_device *pdev) 1441static int dac33_soc_remove(struct snd_soc_codec *codec)
1434{ 1442{
1435 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1443 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
1436 struct snd_soc_codec *codec = socdev->card->codec;
1437 1444
1438 dac33_set_bias_level(codec, SND_SOC_BIAS_OFF); 1445 dac33_set_bias_level(codec, SND_SOC_BIAS_OFF);
1439 1446
1440 snd_soc_free_pcms(socdev); 1447 if (dac33->irq >= 0) {
1441 snd_soc_dapm_free(socdev); 1448 free_irq(dac33->irq, dac33->codec);
1442 1449 destroy_workqueue(dac33->dac33_wq);
1450 }
1443 return 0; 1451 return 0;
1444} 1452}
1445 1453
1446static int dac33_soc_suspend(struct platform_device *pdev, pm_message_t state) 1454static int dac33_soc_suspend(struct snd_soc_codec *codec, pm_message_t state)
1447{ 1455{
1448 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1449 struct snd_soc_codec *codec = socdev->card->codec;
1450
1451 dac33_set_bias_level(codec, SND_SOC_BIAS_OFF); 1456 dac33_set_bias_level(codec, SND_SOC_BIAS_OFF);
1452 1457
1453 return 0; 1458 return 0;
1454} 1459}
1455 1460
1456static int dac33_soc_resume(struct platform_device *pdev) 1461static int dac33_soc_resume(struct snd_soc_codec *codec)
1457{ 1462{
1458 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1459 struct snd_soc_codec *codec = socdev->card->codec;
1460
1461 dac33_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1463 dac33_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1462 1464
1463 return 0; 1465 return 0;
1464} 1466}
1465 1467
1466struct snd_soc_codec_device soc_codec_dev_tlv320dac33 = { 1468static struct snd_soc_codec_driver soc_codec_dev_tlv320dac33 = {
1469 .read = dac33_read_reg_cache,
1470 .write = dac33_write_locked,
1471 .set_bias_level = dac33_set_bias_level,
1472 .reg_cache_size = ARRAY_SIZE(dac33_reg),
1473 .reg_word_size = sizeof(u8),
1474 .reg_cache_default = dac33_reg,
1467 .probe = dac33_soc_probe, 1475 .probe = dac33_soc_probe,
1468 .remove = dac33_soc_remove, 1476 .remove = dac33_soc_remove,
1469 .suspend = dac33_soc_suspend, 1477 .suspend = dac33_soc_suspend,
1470 .resume = dac33_soc_resume, 1478 .resume = dac33_soc_resume,
1471}; 1479};
1472EXPORT_SYMBOL_GPL(soc_codec_dev_tlv320dac33);
1473 1480
1474#define DAC33_RATES (SNDRV_PCM_RATE_44100 | \ 1481#define DAC33_RATES (SNDRV_PCM_RATE_44100 | \
1475 SNDRV_PCM_RATE_48000) 1482 SNDRV_PCM_RATE_48000)
@@ -1485,8 +1492,8 @@ static struct snd_soc_dai_ops dac33_dai_ops = {
1485 .set_fmt = dac33_set_dai_fmt, 1492 .set_fmt = dac33_set_dai_fmt,
1486}; 1493};
1487 1494
1488struct snd_soc_dai dac33_dai = { 1495static struct snd_soc_dai_driver dac33_dai = {
1489 .name = "tlv320dac33", 1496 .name = "tlv320dac33-hifi",
1490 .playback = { 1497 .playback = {
1491 .stream_name = "Playback", 1498 .stream_name = "Playback",
1492 .channels_min = 2, 1499 .channels_min = 2,
@@ -1495,14 +1502,12 @@ struct snd_soc_dai dac33_dai = {
1495 .formats = DAC33_FORMATS,}, 1502 .formats = DAC33_FORMATS,},
1496 .ops = &dac33_dai_ops, 1503 .ops = &dac33_dai_ops,
1497}; 1504};
1498EXPORT_SYMBOL_GPL(dac33_dai);
1499 1505
1500static int __devinit dac33_i2c_probe(struct i2c_client *client, 1506static int __devinit dac33_i2c_probe(struct i2c_client *client,
1501 const struct i2c_device_id *id) 1507 const struct i2c_device_id *id)
1502{ 1508{
1503 struct tlv320dac33_platform_data *pdata; 1509 struct tlv320dac33_platform_data *pdata;
1504 struct tlv320dac33_priv *dac33; 1510 struct tlv320dac33_priv *dac33;
1505 struct snd_soc_codec *codec;
1506 int ret, i; 1511 int ret, i;
1507 1512
1508 if (client->dev.platform_data == NULL) { 1513 if (client->dev.platform_data == NULL) {
@@ -1515,33 +1520,9 @@ static int __devinit dac33_i2c_probe(struct i2c_client *client,
1515 if (dac33 == NULL) 1520 if (dac33 == NULL)
1516 return -ENOMEM; 1521 return -ENOMEM;
1517 1522
1518 codec = &dac33->codec; 1523 dac33->control_data = client;
1519 snd_soc_codec_set_drvdata(codec, dac33);
1520 codec->control_data = client;
1521
1522 mutex_init(&codec->mutex);
1523 mutex_init(&dac33->mutex); 1524 mutex_init(&dac33->mutex);
1524 spin_lock_init(&dac33->lock); 1525 spin_lock_init(&dac33->lock);
1525 INIT_LIST_HEAD(&codec->dapm_widgets);
1526 INIT_LIST_HEAD(&codec->dapm_paths);
1527
1528 codec->name = "tlv320dac33";
1529 codec->owner = THIS_MODULE;
1530 codec->read = dac33_read_reg_cache;
1531 codec->write = dac33_write_locked;
1532 codec->hw_write = (hw_write_t) i2c_master_send;
1533 codec->bias_level = SND_SOC_BIAS_OFF;
1534 codec->set_bias_level = dac33_set_bias_level;
1535 codec->idle_bias_off = 1;
1536 codec->dai = &dac33_dai;
1537 codec->num_dai = 1;
1538 codec->reg_cache_size = ARRAY_SIZE(dac33_reg);
1539 codec->reg_cache = kmemdup(dac33_reg, ARRAY_SIZE(dac33_reg),
1540 GFP_KERNEL);
1541 if (codec->reg_cache == NULL) {
1542 ret = -ENOMEM;
1543 goto error_reg;
1544 }
1545 1526
1546 i2c_set_clientdata(client, dac33); 1527 i2c_set_clientdata(client, dac33);
1547 1528
@@ -1561,125 +1542,59 @@ static int __devinit dac33_i2c_probe(struct i2c_client *client,
1561 /* Disable FIFO use by default */ 1542 /* Disable FIFO use by default */
1562 dac33->fifo_mode = DAC33_FIFO_BYPASS; 1543 dac33->fifo_mode = DAC33_FIFO_BYPASS;
1563 1544
1564 tlv320dac33_codec = codec;
1565
1566 codec->dev = &client->dev;
1567 dac33_dai.dev = codec->dev;
1568
1569 /* Check if the reset GPIO number is valid and request it */ 1545 /* Check if the reset GPIO number is valid and request it */
1570 if (dac33->power_gpio >= 0) { 1546 if (dac33->power_gpio >= 0) {
1571 ret = gpio_request(dac33->power_gpio, "tlv320dac33 reset"); 1547 ret = gpio_request(dac33->power_gpio, "tlv320dac33 reset");
1572 if (ret < 0) { 1548 if (ret < 0) {
1573 dev_err(codec->dev, 1549 dev_err(&client->dev,
1574 "Failed to request reset GPIO (%d)\n", 1550 "Failed to request reset GPIO (%d)\n",
1575 dac33->power_gpio); 1551 dac33->power_gpio);
1576 snd_soc_unregister_dai(&dac33_dai); 1552 goto err_gpio;
1577 snd_soc_unregister_codec(codec);
1578 goto error_gpio;
1579 } 1553 }
1580 gpio_direction_output(dac33->power_gpio, 0); 1554 gpio_direction_output(dac33->power_gpio, 0);
1581 } 1555 }
1582 1556
1583 /* Check if the IRQ number is valid and request it */
1584 if (dac33->irq >= 0) {
1585 ret = request_irq(dac33->irq, dac33_interrupt_handler,
1586 IRQF_TRIGGER_RISING | IRQF_DISABLED,
1587 codec->name, codec);
1588 if (ret < 0) {
1589 dev_err(codec->dev, "Could not request IRQ%d (%d)\n",
1590 dac33->irq, ret);
1591 dac33->irq = -1;
1592 }
1593 if (dac33->irq != -1) {
1594 /* Setup work queue */
1595 dac33->dac33_wq =
1596 create_singlethread_workqueue("tlv320dac33");
1597 if (dac33->dac33_wq == NULL) {
1598 free_irq(dac33->irq, &dac33->codec);
1599 ret = -ENOMEM;
1600 goto error_wq;
1601 }
1602
1603 INIT_WORK(&dac33->work, dac33_work);
1604 }
1605 }
1606
1607 for (i = 0; i < ARRAY_SIZE(dac33->supplies); i++) 1557 for (i = 0; i < ARRAY_SIZE(dac33->supplies); i++)
1608 dac33->supplies[i].supply = dac33_supply_names[i]; 1558 dac33->supplies[i].supply = dac33_supply_names[i];
1609 1559
1610 ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(dac33->supplies), 1560 ret = regulator_bulk_get(&client->dev, ARRAY_SIZE(dac33->supplies),
1611 dac33->supplies); 1561 dac33->supplies);
1612 1562
1613 if (ret != 0) { 1563 if (ret != 0) {
1614 dev_err(codec->dev, "Failed to request supplies: %d\n", ret); 1564 dev_err(&client->dev, "Failed to request supplies: %d\n", ret);
1615 goto err_get; 1565 goto err_get;
1616 } 1566 }
1617 1567
1618 /* Read the tlv320dac33 ID registers */ 1568 ret = snd_soc_register_codec(&client->dev,
1619 ret = dac33_hard_power(codec, 1); 1569 &soc_codec_dev_tlv320dac33, &dac33_dai, 1);
1620 if (ret != 0) { 1570 if (ret < 0)
1621 dev_err(codec->dev, "Failed to power up codec: %d\n", ret); 1571 goto err_register;
1622 goto error_codec;
1623 }
1624 dac33_read_id(codec);
1625 dac33_hard_power(codec, 0);
1626
1627 ret = snd_soc_register_codec(codec);
1628 if (ret != 0) {
1629 dev_err(codec->dev, "Failed to register codec: %d\n", ret);
1630 goto error_codec;
1631 }
1632
1633 ret = snd_soc_register_dai(&dac33_dai);
1634 if (ret != 0) {
1635 dev_err(codec->dev, "Failed to register DAI: %d\n", ret);
1636 snd_soc_unregister_codec(codec);
1637 goto error_codec;
1638 }
1639 1572
1640 return ret; 1573 return ret;
1641 1574err_register:
1642error_codec:
1643 regulator_bulk_free(ARRAY_SIZE(dac33->supplies), dac33->supplies); 1575 regulator_bulk_free(ARRAY_SIZE(dac33->supplies), dac33->supplies);
1644err_get: 1576err_get:
1645 if (dac33->irq >= 0) {
1646 free_irq(dac33->irq, &dac33->codec);
1647 destroy_workqueue(dac33->dac33_wq);
1648 }
1649error_wq:
1650 if (dac33->power_gpio >= 0) 1577 if (dac33->power_gpio >= 0)
1651 gpio_free(dac33->power_gpio); 1578 gpio_free(dac33->power_gpio);
1652error_gpio: 1579err_gpio:
1653 kfree(codec->reg_cache);
1654error_reg:
1655 tlv320dac33_codec = NULL;
1656 kfree(dac33); 1580 kfree(dac33);
1657
1658 return ret; 1581 return ret;
1659} 1582}
1660 1583
1661static int __devexit dac33_i2c_remove(struct i2c_client *client) 1584static int __devexit dac33_i2c_remove(struct i2c_client *client)
1662{ 1585{
1663 struct tlv320dac33_priv *dac33; 1586 struct tlv320dac33_priv *dac33 = i2c_get_clientdata(client);
1664
1665 dac33 = i2c_get_clientdata(client);
1666 1587
1667 if (unlikely(dac33->chip_power)) 1588 if (unlikely(dac33->chip_power))
1668 dac33_hard_power(&dac33->codec, 0); 1589 dac33_hard_power(dac33->codec, 0);
1669 1590
1670 if (dac33->power_gpio >= 0) 1591 if (dac33->power_gpio >= 0)
1671 gpio_free(dac33->power_gpio); 1592 gpio_free(dac33->power_gpio);
1672 if (dac33->irq >= 0)
1673 free_irq(dac33->irq, &dac33->codec);
1674 1593
1675 regulator_bulk_free(ARRAY_SIZE(dac33->supplies), dac33->supplies); 1594 regulator_bulk_free(ARRAY_SIZE(dac33->supplies), dac33->supplies);
1676 1595
1677 destroy_workqueue(dac33->dac33_wq); 1596 snd_soc_unregister_codec(&client->dev);
1678 snd_soc_unregister_dai(&dac33_dai);
1679 snd_soc_unregister_codec(&dac33->codec);
1680 kfree(dac33->codec.reg_cache);
1681 kfree(dac33); 1597 kfree(dac33);
1682 tlv320dac33_codec = NULL;
1683 1598
1684 return 0; 1599 return 0;
1685} 1600}
@@ -1694,7 +1609,7 @@ static const struct i2c_device_id tlv320dac33_i2c_id[] = {
1694 1609
1695static struct i2c_driver tlv320dac33_i2c_driver = { 1610static struct i2c_driver tlv320dac33_i2c_driver = {
1696 .driver = { 1611 .driver = {
1697 .name = "tlv320dac33", 1612 .name = "tlv320dac33-codec",
1698 .owner = THIS_MODULE, 1613 .owner = THIS_MODULE,
1699 }, 1614 },
1700 .probe = dac33_i2c_probe, 1615 .probe = dac33_i2c_probe,