diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-09-10 00:53:12 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-09-10 20:16:11 -0400 |
commit | b61d6d40323997d9da3b95ecce2570f0b782a07f (patch) | |
tree | 35fc6ede45be3e75877962abcb8391d094da2943 /sound/soc/codecs/cs4270.c | |
parent | 19ace0e97a605042c481c2ea3f7aeb59c0eb54ed (diff) |
ASoC: cs4270: Move regulator acquisition to I2C probe()
This is better style since it has us obtaining all resources before we
try the ASoC probe. This change also fixes a potential issue where we
don't enable the regulators before trying to confirm the device ID which
could cause a failure during probe in some system configurations.
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: Timur Tabi <timur@freescale.com>
Diffstat (limited to 'sound/soc/codecs/cs4270.c')
-rw-r--r-- | sound/soc/codecs/cs4270.c | 46 |
1 files changed, 19 insertions, 27 deletions
diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c index c6e5a73a9f17..64c29b8a379f 100644 --- a/sound/soc/codecs/cs4270.c +++ b/sound/soc/codecs/cs4270.c | |||
@@ -487,7 +487,7 @@ static struct snd_soc_dai_driver cs4270_dai = { | |||
487 | static int cs4270_probe(struct snd_soc_codec *codec) | 487 | static int cs4270_probe(struct snd_soc_codec *codec) |
488 | { | 488 | { |
489 | struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec); | 489 | struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec); |
490 | int i, ret; | 490 | int ret; |
491 | 491 | ||
492 | /* Tell ASoC what kind of I/O to use to read the registers. ASoC will | 492 | /* Tell ASoC what kind of I/O to use to read the registers. ASoC will |
493 | * then do the I2C transactions itself. | 493 | * then do the I2C transactions itself. |
@@ -521,25 +521,8 @@ static int cs4270_probe(struct snd_soc_codec *codec) | |||
521 | return ret; | 521 | return ret; |
522 | } | 522 | } |
523 | 523 | ||
524 | /* get the power supply regulators */ | ||
525 | for (i = 0; i < ARRAY_SIZE(supply_names); i++) | ||
526 | cs4270->supplies[i].supply = supply_names[i]; | ||
527 | |||
528 | ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(cs4270->supplies), | ||
529 | cs4270->supplies); | ||
530 | if (ret < 0) | ||
531 | return ret; | ||
532 | |||
533 | ret = regulator_bulk_enable(ARRAY_SIZE(cs4270->supplies), | 524 | ret = regulator_bulk_enable(ARRAY_SIZE(cs4270->supplies), |
534 | cs4270->supplies); | 525 | cs4270->supplies); |
535 | if (ret < 0) | ||
536 | goto error_free_regulators; | ||
537 | |||
538 | return 0; | ||
539 | |||
540 | error_free_regulators: | ||
541 | regulator_bulk_free(ARRAY_SIZE(cs4270->supplies), | ||
542 | cs4270->supplies); | ||
543 | 526 | ||
544 | return ret; | 527 | return ret; |
545 | } | 528 | } |
@@ -555,7 +538,6 @@ static int cs4270_remove(struct snd_soc_codec *codec) | |||
555 | struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec); | 538 | struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec); |
556 | 539 | ||
557 | regulator_bulk_disable(ARRAY_SIZE(cs4270->supplies), cs4270->supplies); | 540 | regulator_bulk_disable(ARRAY_SIZE(cs4270->supplies), cs4270->supplies); |
558 | regulator_bulk_free(ARRAY_SIZE(cs4270->supplies), cs4270->supplies); | ||
559 | 541 | ||
560 | return 0; | 542 | return 0; |
561 | }; | 543 | }; |
@@ -658,7 +640,24 @@ static int cs4270_i2c_probe(struct i2c_client *i2c_client, | |||
658 | { | 640 | { |
659 | struct device_node *np = i2c_client->dev.of_node; | 641 | struct device_node *np = i2c_client->dev.of_node; |
660 | struct cs4270_private *cs4270; | 642 | struct cs4270_private *cs4270; |
661 | int ret; | 643 | int ret, i; |
644 | |||
645 | cs4270 = devm_kzalloc(&i2c_client->dev, sizeof(struct cs4270_private), | ||
646 | GFP_KERNEL); | ||
647 | if (!cs4270) { | ||
648 | dev_err(&i2c_client->dev, "could not allocate codec\n"); | ||
649 | return -ENOMEM; | ||
650 | } | ||
651 | |||
652 | /* get the power supply regulators */ | ||
653 | for (i = 0; i < ARRAY_SIZE(supply_names); i++) | ||
654 | cs4270->supplies[i].supply = supply_names[i]; | ||
655 | |||
656 | ret = devm_regulator_bulk_get(&i2c_client->dev, | ||
657 | ARRAY_SIZE(cs4270->supplies), | ||
658 | cs4270->supplies); | ||
659 | if (ret < 0) | ||
660 | return ret; | ||
662 | 661 | ||
663 | /* See if we have a way to bring the codec out of reset */ | 662 | /* See if we have a way to bring the codec out of reset */ |
664 | if (np) { | 663 | if (np) { |
@@ -694,13 +693,6 @@ static int cs4270_i2c_probe(struct i2c_client *i2c_client, | |||
694 | i2c_client->addr); | 693 | i2c_client->addr); |
695 | dev_info(&i2c_client->dev, "hardware revision %X\n", ret & 0xF); | 694 | dev_info(&i2c_client->dev, "hardware revision %X\n", ret & 0xF); |
696 | 695 | ||
697 | cs4270 = devm_kzalloc(&i2c_client->dev, sizeof(struct cs4270_private), | ||
698 | GFP_KERNEL); | ||
699 | if (!cs4270) { | ||
700 | dev_err(&i2c_client->dev, "could not allocate codec\n"); | ||
701 | return -ENOMEM; | ||
702 | } | ||
703 | |||
704 | i2c_set_clientdata(i2c_client, cs4270); | 696 | i2c_set_clientdata(i2c_client, cs4270); |
705 | cs4270->control_type = SND_SOC_I2C; | 697 | cs4270->control_type = SND_SOC_I2C; |
706 | 698 | ||