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.c276
1 files changed, 105 insertions, 171 deletions
diff --git a/sound/soc/codecs/tlv320dac33.c b/sound/soc/codecs/tlv320dac33.c
index 8651b01ed223..d251ff54a2d3 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] = {
@@ -524,6 +524,22 @@ static const struct soc_enum dac33_fifo_mode_enum =
524 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(dac33_fifo_mode_texts), 524 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(dac33_fifo_mode_texts),
525 dac33_fifo_mode_texts); 525 dac33_fifo_mode_texts);
526 526
527/* L/R Line Output Gain */
528static const char *lr_lineout_gain_texts[] = {
529 "Line -12dB DAC 0dB", "Line -6dB DAC 6dB",
530 "Line 0dB DAC 12dB", "Line 6dB DAC 18dB",
531};
532
533static const struct soc_enum l_lineout_gain_enum =
534 SOC_ENUM_SINGLE(DAC33_LDAC_PWR_CTRL, 0,
535 ARRAY_SIZE(lr_lineout_gain_texts),
536 lr_lineout_gain_texts);
537
538static const struct soc_enum r_lineout_gain_enum =
539 SOC_ENUM_SINGLE(DAC33_RDAC_PWR_CTRL, 0,
540 ARRAY_SIZE(lr_lineout_gain_texts),
541 lr_lineout_gain_texts);
542
527/* 543/*
528 * DACL/R digital volume control: 544 * DACL/R digital volume control:
529 * from 0 dB to -63.5 in 0.5 dB steps 545 * from 0 dB to -63.5 in 0.5 dB steps
@@ -541,6 +557,8 @@ static const struct snd_kcontrol_new dac33_snd_controls[] = {
541 DAC33_LDAC_DIG_VOL_CTRL, DAC33_RDAC_DIG_VOL_CTRL, 7, 1, 1), 557 DAC33_LDAC_DIG_VOL_CTRL, DAC33_RDAC_DIG_VOL_CTRL, 7, 1, 1),
542 SOC_DOUBLE_R("Line to Line Out Volume", 558 SOC_DOUBLE_R("Line to Line Out Volume",
543 DAC33_LINEL_TO_LLO_VOL, DAC33_LINER_TO_RLO_VOL, 0, 127, 1), 559 DAC33_LINEL_TO_LLO_VOL, DAC33_LINER_TO_RLO_VOL, 0, 127, 1),
560 SOC_ENUM("Left Line Output Gain", l_lineout_gain_enum),
561 SOC_ENUM("Right Line Output Gain", r_lineout_gain_enum),
544}; 562};
545 563
546static const struct snd_kcontrol_new dac33_mode_snd_controls[] = { 564static const struct snd_kcontrol_new dac33_mode_snd_controls[] = {
@@ -650,9 +668,8 @@ static int dac33_set_bias_level(struct snd_soc_codec *codec,
650 668
651static inline void dac33_prefill_handler(struct tlv320dac33_priv *dac33) 669static inline void dac33_prefill_handler(struct tlv320dac33_priv *dac33)
652{ 670{
653 struct snd_soc_codec *codec; 671 struct snd_soc_codec *codec = dac33->codec;
654 672 unsigned int delay;
655 codec = &dac33->codec;
656 673
657 switch (dac33->fifo_mode) { 674 switch (dac33->fifo_mode) {
658 case DAC33_FIFO_MODE1: 675 case DAC33_FIFO_MODE1:
@@ -668,8 +685,9 @@ static inline void dac33_prefill_handler(struct tlv320dac33_priv *dac33)
668 dac33_write16(codec, DAC33_PREFILL_MSB, 685 dac33_write16(codec, DAC33_PREFILL_MSB,
669 DAC33_THRREG(dac33->alarm_threshold)); 686 DAC33_THRREG(dac33->alarm_threshold));
670 /* Enable Alarm Threshold IRQ with a delay */ 687 /* Enable Alarm Threshold IRQ with a delay */
671 udelay(SAMPLES_TO_US(dac33->burst_rate, 688 delay = SAMPLES_TO_US(dac33->burst_rate,
672 dac33->alarm_threshold)); 689 dac33->alarm_threshold) + 1000;
690 usleep_range(delay, delay + 500);
673 dac33_write(codec, DAC33_FIFO_IRQ_MASK, DAC33_MAT); 691 dac33_write(codec, DAC33_FIFO_IRQ_MASK, DAC33_MAT);
674 break; 692 break;
675 case DAC33_FIFO_MODE7: 693 case DAC33_FIFO_MODE7:
@@ -695,9 +713,7 @@ static inline void dac33_prefill_handler(struct tlv320dac33_priv *dac33)
695 713
696static inline void dac33_playback_handler(struct tlv320dac33_priv *dac33) 714static inline void dac33_playback_handler(struct tlv320dac33_priv *dac33)
697{ 715{
698 struct snd_soc_codec *codec; 716 struct snd_soc_codec *codec = dac33->codec;
699
700 codec = &dac33->codec;
701 717
702 switch (dac33->fifo_mode) { 718 switch (dac33->fifo_mode) {
703 case DAC33_FIFO_MODE1: 719 case DAC33_FIFO_MODE1:
@@ -726,7 +742,7 @@ static void dac33_work(struct work_struct *work)
726 u8 reg; 742 u8 reg;
727 743
728 dac33 = container_of(work, struct tlv320dac33_priv, work); 744 dac33 = container_of(work, struct tlv320dac33_priv, work);
729 codec = &dac33->codec; 745 codec = dac33->codec;
730 746
731 mutex_lock(&dac33->mutex); 747 mutex_lock(&dac33->mutex);
732 switch (dac33->state) { 748 switch (dac33->state) {
@@ -771,11 +787,11 @@ static irqreturn_t dac33_interrupt_handler(int irq, void *dev)
771 787
772static void dac33_oscwait(struct snd_soc_codec *codec) 788static void dac33_oscwait(struct snd_soc_codec *codec)
773{ 789{
774 int timeout = 20; 790 int timeout = 60;
775 u8 reg; 791 u8 reg;
776 792
777 do { 793 do {
778 msleep(1); 794 usleep_range(1000, 2000);
779 dac33_read(codec, DAC33_INT_OSC_STATUS, &reg); 795 dac33_read(codec, DAC33_INT_OSC_STATUS, &reg);
780 } while (((reg & 0x03) != DAC33_OSCSTATUS_NORMAL) && timeout--); 796 } while (((reg & 0x03) != DAC33_OSCSTATUS_NORMAL) && timeout--);
781 if ((reg & 0x03) != DAC33_OSCSTATUS_NORMAL) 797 if ((reg & 0x03) != DAC33_OSCSTATUS_NORMAL)
@@ -787,8 +803,7 @@ static int dac33_startup(struct snd_pcm_substream *substream,
787 struct snd_soc_dai *dai) 803 struct snd_soc_dai *dai)
788{ 804{
789 struct snd_soc_pcm_runtime *rtd = substream->private_data; 805 struct snd_soc_pcm_runtime *rtd = substream->private_data;
790 struct snd_soc_device *socdev = rtd->socdev; 806 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); 807 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
793 808
794 /* Stream started, save the substream pointer */ 809 /* Stream started, save the substream pointer */
@@ -801,8 +816,7 @@ static void dac33_shutdown(struct snd_pcm_substream *substream,
801 struct snd_soc_dai *dai) 816 struct snd_soc_dai *dai)
802{ 817{
803 struct snd_soc_pcm_runtime *rtd = substream->private_data; 818 struct snd_soc_pcm_runtime *rtd = substream->private_data;
804 struct snd_soc_device *socdev = rtd->socdev; 819 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); 820 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
807 821
808 dac33->substream = NULL; 822 dac33->substream = NULL;
@@ -817,8 +831,7 @@ static int dac33_hw_params(struct snd_pcm_substream *substream,
817 struct snd_soc_dai *dai) 831 struct snd_soc_dai *dai)
818{ 832{
819 struct snd_soc_pcm_runtime *rtd = substream->private_data; 833 struct snd_soc_pcm_runtime *rtd = substream->private_data;
820 struct snd_soc_device *socdev = rtd->socdev; 834 struct snd_soc_codec *codec = rtd->codec;
821 struct snd_soc_codec *codec = socdev->card->codec;
822 835
823 /* Check parameters for validity */ 836 /* Check parameters for validity */
824 switch (params_rate(params)) { 837 switch (params_rate(params)) {
@@ -856,8 +869,7 @@ static int dac33_hw_params(struct snd_pcm_substream *substream,
856static int dac33_prepare_chip(struct snd_pcm_substream *substream) 869static int dac33_prepare_chip(struct snd_pcm_substream *substream)
857{ 870{
858 struct snd_soc_pcm_runtime *rtd = substream->private_data; 871 struct snd_soc_pcm_runtime *rtd = substream->private_data;
859 struct snd_soc_device *socdev = rtd->socdev; 872 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); 873 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
862 unsigned int oscset, ratioset, pwr_ctrl, reg_tmp; 874 unsigned int oscset, ratioset, pwr_ctrl, reg_tmp;
863 u8 aictrl_a, aictrl_b, fifoctrl_a; 875 u8 aictrl_a, aictrl_b, fifoctrl_a;
@@ -1049,8 +1061,7 @@ static int dac33_prepare_chip(struct snd_pcm_substream *substream)
1049static void dac33_calculate_times(struct snd_pcm_substream *substream) 1061static void dac33_calculate_times(struct snd_pcm_substream *substream)
1050{ 1062{
1051 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1063 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1052 struct snd_soc_device *socdev = rtd->socdev; 1064 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); 1065 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
1055 unsigned int period_size = substream->runtime->period_size; 1066 unsigned int period_size = substream->runtime->period_size;
1056 unsigned int rate = substream->runtime->rate; 1067 unsigned int rate = substream->runtime->rate;
@@ -1129,8 +1140,7 @@ static int dac33_pcm_trigger(struct snd_pcm_substream *substream, int cmd,
1129 struct snd_soc_dai *dai) 1140 struct snd_soc_dai *dai)
1130{ 1141{
1131 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1142 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1132 struct snd_soc_device *socdev = rtd->socdev; 1143 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); 1144 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
1135 int ret = 0; 1145 int ret = 0;
1136 1146
@@ -1163,8 +1173,7 @@ static snd_pcm_sframes_t dac33_dai_delay(
1163 struct snd_soc_dai *dai) 1173 struct snd_soc_dai *dai)
1164{ 1174{
1165 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1175 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1166 struct snd_soc_device *socdev = rtd->socdev; 1176 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); 1177 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
1169 unsigned long long t0, t1, t_now; 1178 unsigned long long t0, t1, t_now;
1170 unsigned int time_delta, uthr; 1179 unsigned int time_delta, uthr;
@@ -1389,24 +1398,46 @@ static int dac33_set_dai_fmt(struct snd_soc_dai *codec_dai,
1389 return 0; 1398 return 0;
1390} 1399}
1391 1400
1392static int dac33_soc_probe(struct platform_device *pdev) 1401static int dac33_soc_probe(struct snd_soc_codec *codec)
1393{ 1402{
1394 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1403 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; 1404 int ret = 0;
1398 1405
1399 BUG_ON(!tlv320dac33_codec); 1406 codec->control_data = dac33->control_data;
1407 codec->hw_write = (hw_write_t) i2c_master_send;
1408 codec->idle_bias_off = 1;
1409 dac33->codec = codec;
1400 1410
1401 codec = tlv320dac33_codec; 1411 /* Read the tlv320dac33 ID registers */
1402 socdev->card->codec = codec; 1412 ret = dac33_hard_power(codec, 1);
1403 dac33 = snd_soc_codec_get_drvdata(codec); 1413 if (ret != 0) {
1414 dev_err(codec->dev, "Failed to power up codec: %d\n", ret);
1415 goto err_power;
1416 }
1417 dac33_read_id(codec);
1418 dac33_hard_power(codec, 0);
1419
1420 /* Check if the IRQ number is valid and request it */
1421 if (dac33->irq >= 0) {
1422 ret = request_irq(dac33->irq, dac33_interrupt_handler,
1423 IRQF_TRIGGER_RISING | IRQF_DISABLED,
1424 codec->name, codec);
1425 if (ret < 0) {
1426 dev_err(codec->dev, "Could not request IRQ%d (%d)\n",
1427 dac33->irq, ret);
1428 dac33->irq = -1;
1429 }
1430 if (dac33->irq != -1) {
1431 /* Setup work queue */
1432 dac33->dac33_wq =
1433 create_singlethread_workqueue("tlv320dac33");
1434 if (dac33->dac33_wq == NULL) {
1435 free_irq(dac33->irq, codec);
1436 return -ENOMEM;
1437 }
1404 1438
1405 /* register pcms */ 1439 INIT_WORK(&dac33->work, dac33_work);
1406 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); 1440 }
1407 if (ret < 0) {
1408 dev_err(codec->dev, "failed to create pcms\n");
1409 goto pcm_err;
1410 } 1441 }
1411 1442
1412 snd_soc_add_controls(codec, dac33_snd_controls, 1443 snd_soc_add_controls(codec, dac33_snd_controls,
@@ -1420,56 +1451,51 @@ static int dac33_soc_probe(struct platform_device *pdev)
1420 snd_soc_add_controls(codec, dac33_fifo_snd_controls, 1451 snd_soc_add_controls(codec, dac33_fifo_snd_controls,
1421 ARRAY_SIZE(dac33_fifo_snd_controls)); 1452 ARRAY_SIZE(dac33_fifo_snd_controls));
1422 } 1453 }
1423
1424 dac33_add_widgets(codec); 1454 dac33_add_widgets(codec);
1425 1455
1426 return 0; 1456err_power:
1427
1428pcm_err:
1429 dac33_hard_power(codec, 0);
1430 return ret; 1457 return ret;
1431} 1458}
1432 1459
1433static int dac33_soc_remove(struct platform_device *pdev) 1460static int dac33_soc_remove(struct snd_soc_codec *codec)
1434{ 1461{
1435 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1462 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
1436 struct snd_soc_codec *codec = socdev->card->codec;
1437 1463
1438 dac33_set_bias_level(codec, SND_SOC_BIAS_OFF); 1464 dac33_set_bias_level(codec, SND_SOC_BIAS_OFF);
1439 1465
1440 snd_soc_free_pcms(socdev); 1466 if (dac33->irq >= 0) {
1441 snd_soc_dapm_free(socdev); 1467 free_irq(dac33->irq, dac33->codec);
1442 1468 destroy_workqueue(dac33->dac33_wq);
1469 }
1443 return 0; 1470 return 0;
1444} 1471}
1445 1472
1446static int dac33_soc_suspend(struct platform_device *pdev, pm_message_t state) 1473static int dac33_soc_suspend(struct snd_soc_codec *codec, pm_message_t state)
1447{ 1474{
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); 1475 dac33_set_bias_level(codec, SND_SOC_BIAS_OFF);
1452 1476
1453 return 0; 1477 return 0;
1454} 1478}
1455 1479
1456static int dac33_soc_resume(struct platform_device *pdev) 1480static int dac33_soc_resume(struct snd_soc_codec *codec)
1457{ 1481{
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); 1482 dac33_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1462 1483
1463 return 0; 1484 return 0;
1464} 1485}
1465 1486
1466struct snd_soc_codec_device soc_codec_dev_tlv320dac33 = { 1487static struct snd_soc_codec_driver soc_codec_dev_tlv320dac33 = {
1488 .read = dac33_read_reg_cache,
1489 .write = dac33_write_locked,
1490 .set_bias_level = dac33_set_bias_level,
1491 .reg_cache_size = ARRAY_SIZE(dac33_reg),
1492 .reg_word_size = sizeof(u8),
1493 .reg_cache_default = dac33_reg,
1467 .probe = dac33_soc_probe, 1494 .probe = dac33_soc_probe,
1468 .remove = dac33_soc_remove, 1495 .remove = dac33_soc_remove,
1469 .suspend = dac33_soc_suspend, 1496 .suspend = dac33_soc_suspend,
1470 .resume = dac33_soc_resume, 1497 .resume = dac33_soc_resume,
1471}; 1498};
1472EXPORT_SYMBOL_GPL(soc_codec_dev_tlv320dac33);
1473 1499
1474#define DAC33_RATES (SNDRV_PCM_RATE_44100 | \ 1500#define DAC33_RATES (SNDRV_PCM_RATE_44100 | \
1475 SNDRV_PCM_RATE_48000) 1501 SNDRV_PCM_RATE_48000)
@@ -1485,8 +1511,8 @@ static struct snd_soc_dai_ops dac33_dai_ops = {
1485 .set_fmt = dac33_set_dai_fmt, 1511 .set_fmt = dac33_set_dai_fmt,
1486}; 1512};
1487 1513
1488struct snd_soc_dai dac33_dai = { 1514static struct snd_soc_dai_driver dac33_dai = {
1489 .name = "tlv320dac33", 1515 .name = "tlv320dac33-hifi",
1490 .playback = { 1516 .playback = {
1491 .stream_name = "Playback", 1517 .stream_name = "Playback",
1492 .channels_min = 2, 1518 .channels_min = 2,
@@ -1495,14 +1521,12 @@ struct snd_soc_dai dac33_dai = {
1495 .formats = DAC33_FORMATS,}, 1521 .formats = DAC33_FORMATS,},
1496 .ops = &dac33_dai_ops, 1522 .ops = &dac33_dai_ops,
1497}; 1523};
1498EXPORT_SYMBOL_GPL(dac33_dai);
1499 1524
1500static int __devinit dac33_i2c_probe(struct i2c_client *client, 1525static int __devinit dac33_i2c_probe(struct i2c_client *client,
1501 const struct i2c_device_id *id) 1526 const struct i2c_device_id *id)
1502{ 1527{
1503 struct tlv320dac33_platform_data *pdata; 1528 struct tlv320dac33_platform_data *pdata;
1504 struct tlv320dac33_priv *dac33; 1529 struct tlv320dac33_priv *dac33;
1505 struct snd_soc_codec *codec;
1506 int ret, i; 1530 int ret, i;
1507 1531
1508 if (client->dev.platform_data == NULL) { 1532 if (client->dev.platform_data == NULL) {
@@ -1515,33 +1539,9 @@ static int __devinit dac33_i2c_probe(struct i2c_client *client,
1515 if (dac33 == NULL) 1539 if (dac33 == NULL)
1516 return -ENOMEM; 1540 return -ENOMEM;
1517 1541
1518 codec = &dac33->codec; 1542 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); 1543 mutex_init(&dac33->mutex);
1524 spin_lock_init(&dac33->lock); 1544 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 1545
1546 i2c_set_clientdata(client, dac33); 1546 i2c_set_clientdata(client, dac33);
1547 1547
@@ -1561,125 +1561,59 @@ static int __devinit dac33_i2c_probe(struct i2c_client *client,
1561 /* Disable FIFO use by default */ 1561 /* Disable FIFO use by default */
1562 dac33->fifo_mode = DAC33_FIFO_BYPASS; 1562 dac33->fifo_mode = DAC33_FIFO_BYPASS;
1563 1563
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 */ 1564 /* Check if the reset GPIO number is valid and request it */
1570 if (dac33->power_gpio >= 0) { 1565 if (dac33->power_gpio >= 0) {
1571 ret = gpio_request(dac33->power_gpio, "tlv320dac33 reset"); 1566 ret = gpio_request(dac33->power_gpio, "tlv320dac33 reset");
1572 if (ret < 0) { 1567 if (ret < 0) {
1573 dev_err(codec->dev, 1568 dev_err(&client->dev,
1574 "Failed to request reset GPIO (%d)\n", 1569 "Failed to request reset GPIO (%d)\n",
1575 dac33->power_gpio); 1570 dac33->power_gpio);
1576 snd_soc_unregister_dai(&dac33_dai); 1571 goto err_gpio;
1577 snd_soc_unregister_codec(codec);
1578 goto error_gpio;
1579 } 1572 }
1580 gpio_direction_output(dac33->power_gpio, 0); 1573 gpio_direction_output(dac33->power_gpio, 0);
1581 } 1574 }
1582 1575
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++) 1576 for (i = 0; i < ARRAY_SIZE(dac33->supplies); i++)
1608 dac33->supplies[i].supply = dac33_supply_names[i]; 1577 dac33->supplies[i].supply = dac33_supply_names[i];
1609 1578
1610 ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(dac33->supplies), 1579 ret = regulator_bulk_get(&client->dev, ARRAY_SIZE(dac33->supplies),
1611 dac33->supplies); 1580 dac33->supplies);
1612 1581
1613 if (ret != 0) { 1582 if (ret != 0) {
1614 dev_err(codec->dev, "Failed to request supplies: %d\n", ret); 1583 dev_err(&client->dev, "Failed to request supplies: %d\n", ret);
1615 goto err_get; 1584 goto err_get;
1616 } 1585 }
1617 1586
1618 /* Read the tlv320dac33 ID registers */ 1587 ret = snd_soc_register_codec(&client->dev,
1619 ret = dac33_hard_power(codec, 1); 1588 &soc_codec_dev_tlv320dac33, &dac33_dai, 1);
1620 if (ret != 0) { 1589 if (ret < 0)
1621 dev_err(codec->dev, "Failed to power up codec: %d\n", ret); 1590 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 1591
1640 return ret; 1592 return ret;
1641 1593err_register:
1642error_codec:
1643 regulator_bulk_free(ARRAY_SIZE(dac33->supplies), dac33->supplies); 1594 regulator_bulk_free(ARRAY_SIZE(dac33->supplies), dac33->supplies);
1644err_get: 1595err_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) 1596 if (dac33->power_gpio >= 0)
1651 gpio_free(dac33->power_gpio); 1597 gpio_free(dac33->power_gpio);
1652error_gpio: 1598err_gpio:
1653 kfree(codec->reg_cache);
1654error_reg:
1655 tlv320dac33_codec = NULL;
1656 kfree(dac33); 1599 kfree(dac33);
1657
1658 return ret; 1600 return ret;
1659} 1601}
1660 1602
1661static int __devexit dac33_i2c_remove(struct i2c_client *client) 1603static int __devexit dac33_i2c_remove(struct i2c_client *client)
1662{ 1604{
1663 struct tlv320dac33_priv *dac33; 1605 struct tlv320dac33_priv *dac33 = i2c_get_clientdata(client);
1664
1665 dac33 = i2c_get_clientdata(client);
1666 1606
1667 if (unlikely(dac33->chip_power)) 1607 if (unlikely(dac33->chip_power))
1668 dac33_hard_power(&dac33->codec, 0); 1608 dac33_hard_power(dac33->codec, 0);
1669 1609
1670 if (dac33->power_gpio >= 0) 1610 if (dac33->power_gpio >= 0)
1671 gpio_free(dac33->power_gpio); 1611 gpio_free(dac33->power_gpio);
1672 if (dac33->irq >= 0)
1673 free_irq(dac33->irq, &dac33->codec);
1674 1612
1675 regulator_bulk_free(ARRAY_SIZE(dac33->supplies), dac33->supplies); 1613 regulator_bulk_free(ARRAY_SIZE(dac33->supplies), dac33->supplies);
1676 1614
1677 destroy_workqueue(dac33->dac33_wq); 1615 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); 1616 kfree(dac33);
1682 tlv320dac33_codec = NULL;
1683 1617
1684 return 0; 1618 return 0;
1685} 1619}
@@ -1694,7 +1628,7 @@ static const struct i2c_device_id tlv320dac33_i2c_id[] = {
1694 1628
1695static struct i2c_driver tlv320dac33_i2c_driver = { 1629static struct i2c_driver tlv320dac33_i2c_driver = {
1696 .driver = { 1630 .driver = {
1697 .name = "tlv320dac33", 1631 .name = "tlv320dac33-codec",
1698 .owner = THIS_MODULE, 1632 .owner = THIS_MODULE,
1699 }, 1633 },
1700 .probe = dac33_i2c_probe, 1634 .probe = dac33_i2c_probe,