aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2012-03-04 09:20:18 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-04-01 06:28:21 -0400
commit253322c18830965331e54ee33c5e8064a2f15717 (patch)
tree225d9e6ba24db51310f64d042efaf8bb0c98f7ab
parenta0abacd82c553d18f8e359f7296246b3009cc207 (diff)
ASoC: ak4641: Push GPIO allocation out into the I2C probe
It's more idiomatic to do this and it means we don't try to bring up the card if the CODEC didn't manage to bind successfully. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
-rw-r--r--sound/soc/codecs/ak4641.c92
1 files changed, 48 insertions, 44 deletions
diff --git a/sound/soc/codecs/ak4641.c b/sound/soc/codecs/ak4641.c
index 611e8f05d87e..7f42d4a673e3 100644
--- a/sound/soc/codecs/ak4641.c
+++ b/sound/soc/codecs/ak4641.c
@@ -517,67 +517,24 @@ static int ak4641_resume(struct snd_soc_codec *codec)
517 517
518static int ak4641_probe(struct snd_soc_codec *codec) 518static int ak4641_probe(struct snd_soc_codec *codec)
519{ 519{
520 struct ak4641_platform_data *pdata = codec->dev->platform_data;
521 int ret; 520 int ret;
522 521
523
524 if (pdata) {
525 if (gpio_is_valid(pdata->gpio_power)) {
526 ret = gpio_request_one(pdata->gpio_power,
527 GPIOF_OUT_INIT_LOW, "ak4641 power");
528 if (ret)
529 goto err_out;
530 }
531 if (gpio_is_valid(pdata->gpio_npdn)) {
532 ret = gpio_request_one(pdata->gpio_npdn,
533 GPIOF_OUT_INIT_LOW, "ak4641 npdn");
534 if (ret)
535 goto err_gpio;
536
537 udelay(1); /* > 150 ns */
538 gpio_set_value(pdata->gpio_npdn, 1);
539 }
540 }
541
542 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_I2C); 522 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_I2C);
543 if (ret != 0) { 523 if (ret != 0) {
544 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); 524 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
545 goto err_register; 525 return ret;
546 } 526 }
547 527
548 /* power on device */ 528 /* power on device */
549 ak4641_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 529 ak4641_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
550 530
551 return 0; 531 return 0;
552
553err_register:
554 if (pdata) {
555 if (gpio_is_valid(pdata->gpio_power))
556 gpio_set_value(pdata->gpio_power, 0);
557 if (gpio_is_valid(pdata->gpio_npdn))
558 gpio_free(pdata->gpio_npdn);
559 }
560err_gpio:
561 if (pdata && gpio_is_valid(pdata->gpio_power))
562 gpio_free(pdata->gpio_power);
563err_out:
564 return ret;
565} 532}
566 533
567static int ak4641_remove(struct snd_soc_codec *codec) 534static int ak4641_remove(struct snd_soc_codec *codec)
568{ 535{
569 struct ak4641_platform_data *pdata = codec->dev->platform_data;
570
571 ak4641_set_bias_level(codec, SND_SOC_BIAS_OFF); 536 ak4641_set_bias_level(codec, SND_SOC_BIAS_OFF);
572 537
573 if (pdata) {
574 if (gpio_is_valid(pdata->gpio_power)) {
575 gpio_set_value(pdata->gpio_power, 0);
576 gpio_free(pdata->gpio_power);
577 }
578 if (gpio_is_valid(pdata->gpio_npdn))
579 gpio_free(pdata->gpio_npdn);
580 }
581 return 0; 538 return 0;
582} 539}
583 540
@@ -604,6 +561,7 @@ static struct snd_soc_codec_driver soc_codec_dev_ak4641 = {
604static int __devinit ak4641_i2c_probe(struct i2c_client *i2c, 561static int __devinit ak4641_i2c_probe(struct i2c_client *i2c,
605 const struct i2c_device_id *id) 562 const struct i2c_device_id *id)
606{ 563{
564 struct ak4641_platform_data *pdata = i2c->dev.platform_data;
607 struct ak4641_priv *ak4641; 565 struct ak4641_priv *ak4641;
608 int ret; 566 int ret;
609 567
@@ -612,16 +570,62 @@ static int __devinit ak4641_i2c_probe(struct i2c_client *i2c,
612 if (!ak4641) 570 if (!ak4641)
613 return -ENOMEM; 571 return -ENOMEM;
614 572
573 if (pdata) {
574 if (gpio_is_valid(pdata->gpio_power)) {
575 ret = gpio_request_one(pdata->gpio_power,
576 GPIOF_OUT_INIT_LOW, "ak4641 power");
577 if (ret)
578 goto err_out;
579 }
580 if (gpio_is_valid(pdata->gpio_npdn)) {
581 ret = gpio_request_one(pdata->gpio_npdn,
582 GPIOF_OUT_INIT_LOW, "ak4641 npdn");
583 if (ret)
584 goto err_gpio;
585
586 udelay(1); /* > 150 ns */
587 gpio_set_value(pdata->gpio_npdn, 1);
588 }
589 }
590
615 i2c_set_clientdata(i2c, ak4641); 591 i2c_set_clientdata(i2c, ak4641);
616 592
617 ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_ak4641, 593 ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_ak4641,
618 ak4641_dai, ARRAY_SIZE(ak4641_dai)); 594 ak4641_dai, ARRAY_SIZE(ak4641_dai));
595 if (ret != 0)
596 goto err_gpio2;
597
598 return 0;
599
600err_gpio2:
601 if (pdata) {
602 if (gpio_is_valid(pdata->gpio_power))
603 gpio_set_value(pdata->gpio_power, 0);
604 if (gpio_is_valid(pdata->gpio_npdn))
605 gpio_free(pdata->gpio_npdn);
606 }
607err_gpio:
608 if (pdata && gpio_is_valid(pdata->gpio_power))
609 gpio_free(pdata->gpio_power);
610err_out:
619 return ret; 611 return ret;
620} 612}
621 613
622static int __devexit ak4641_i2c_remove(struct i2c_client *i2c) 614static int __devexit ak4641_i2c_remove(struct i2c_client *i2c)
623{ 615{
616 struct ak4641_platform_data *pdata = i2c->dev.platform_data;
617
624 snd_soc_unregister_codec(&i2c->dev); 618 snd_soc_unregister_codec(&i2c->dev);
619
620 if (pdata) {
621 if (gpio_is_valid(pdata->gpio_power)) {
622 gpio_set_value(pdata->gpio_power, 0);
623 gpio_free(pdata->gpio_power);
624 }
625 if (gpio_is_valid(pdata->gpio_npdn))
626 gpio_free(pdata->gpio_npdn);
627 }
628
625 return 0; 629 return 0;
626} 630}
627 631