aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs/cs4271.c
diff options
context:
space:
mode:
authorDaniel Mack <zonque@gmail.com>2014-02-19 08:05:54 -0500
committerMark Brown <broonie@linaro.org>2014-02-19 11:36:39 -0500
commitd6cf89ee07cbfd980f189cc12ae924c811b00ee4 (patch)
treeb319ce97753dc1e5ce58994e08f4970108c7f320 /sound/soc/codecs/cs4271.c
parentb224e9b857438afbd802f47008ab36863f71d8d1 (diff)
ASoC: cs4271: claim reset GPIO in bus probe function
Move the GPIO acquisition from the codec to the bus probe functions. Signed-off-by: Daniel Mack <zonque@gmail.com> Acked-by: Brian Austin <brian.austin@cirrus.com> Signed-off-by: Mark Brown <broonie@linaro.org>
Diffstat (limited to 'sound/soc/codecs/cs4271.c')
-rw-r--r--sound/soc/codecs/cs4271.c60
1 files changed, 40 insertions, 20 deletions
diff --git a/sound/soc/codecs/cs4271.c b/sound/soc/codecs/cs4271.c
index f7bbe6fdba67..96c309777208 100644
--- a/sound/soc/codecs/cs4271.c
+++ b/sound/soc/codecs/cs4271.c
@@ -539,14 +539,10 @@ static int cs4271_probe(struct snd_soc_codec *codec)
539 struct cs4271_private *cs4271 = snd_soc_codec_get_drvdata(codec); 539 struct cs4271_private *cs4271 = snd_soc_codec_get_drvdata(codec);
540 struct cs4271_platform_data *cs4271plat = codec->dev->platform_data; 540 struct cs4271_platform_data *cs4271plat = codec->dev->platform_data;
541 int ret; 541 int ret;
542 int gpio_nreset = -EINVAL;
543 bool amutec_eq_bmutec = false; 542 bool amutec_eq_bmutec = false;
544 543
545#ifdef CONFIG_OF 544#ifdef CONFIG_OF
546 if (of_match_device(cs4271_dt_ids, codec->dev)) { 545 if (of_match_device(cs4271_dt_ids, codec->dev)) {
547 gpio_nreset = of_get_named_gpio(codec->dev->of_node,
548 "reset-gpio", 0);
549
550 if (of_get_property(codec->dev->of_node, 546 if (of_get_property(codec->dev->of_node,
551 "cirrus,amutec-eq-bmutec", NULL)) 547 "cirrus,amutec-eq-bmutec", NULL))
552 amutec_eq_bmutec = true; 548 amutec_eq_bmutec = true;
@@ -558,27 +554,19 @@ static int cs4271_probe(struct snd_soc_codec *codec)
558#endif 554#endif
559 555
560 if (cs4271plat) { 556 if (cs4271plat) {
561 if (gpio_is_valid(cs4271plat->gpio_nreset))
562 gpio_nreset = cs4271plat->gpio_nreset;
563
564 amutec_eq_bmutec = cs4271plat->amutec_eq_bmutec; 557 amutec_eq_bmutec = cs4271plat->amutec_eq_bmutec;
565 cs4271->enable_soft_reset = cs4271plat->enable_soft_reset; 558 cs4271->enable_soft_reset = cs4271plat->enable_soft_reset;
566 } 559 }
567 560
568 if (gpio_nreset >= 0) 561 if (gpio_is_valid(cs4271->gpio_nreset)) {
569 if (devm_gpio_request(codec->dev, gpio_nreset, "CS4271 Reset"))
570 gpio_nreset = -EINVAL;
571 if (gpio_nreset >= 0) {
572 /* Reset codec */ 562 /* Reset codec */
573 gpio_direction_output(gpio_nreset, 0); 563 gpio_direction_output(cs4271->gpio_nreset, 0);
574 udelay(1); 564 udelay(1);
575 gpio_set_value(gpio_nreset, 1); 565 gpio_set_value(cs4271->gpio_nreset, 1);
576 /* Give the codec time to wake up */ 566 /* Give the codec time to wake up */
577 udelay(1); 567 udelay(1);
578 } 568 }
579 569
580 cs4271->gpio_nreset = gpio_nreset;
581
582 ret = regmap_update_bits(cs4271->regmap, CS4271_MODE2, 570 ret = regmap_update_bits(cs4271->regmap, CS4271_MODE2,
583 CS4271_MODE2_PDN | CS4271_MODE2_CPEN, 571 CS4271_MODE2_PDN | CS4271_MODE2_CPEN,
584 CS4271_MODE2_PDN | CS4271_MODE2_CPEN); 572 CS4271_MODE2_PDN | CS4271_MODE2_CPEN);
@@ -640,14 +628,45 @@ static const struct regmap_config cs4271_spi_regmap = {
640 .volatile_reg = cs4271_volatile_reg, 628 .volatile_reg = cs4271_volatile_reg,
641}; 629};
642 630
643static int cs4271_spi_probe(struct spi_device *spi) 631static int cs4271_common_probe(struct device *dev,
632 struct cs4271_private **c)
644{ 633{
634 struct cs4271_platform_data *cs4271plat = dev->platform_data;
645 struct cs4271_private *cs4271; 635 struct cs4271_private *cs4271;
646 636
647 cs4271 = devm_kzalloc(&spi->dev, sizeof(*cs4271), GFP_KERNEL); 637 cs4271 = devm_kzalloc(dev, sizeof(*cs4271), GFP_KERNEL);
648 if (!cs4271) 638 if (!cs4271)
649 return -ENOMEM; 639 return -ENOMEM;
650 640
641 if (of_match_device(cs4271_dt_ids, dev))
642 cs4271->gpio_nreset =
643 of_get_named_gpio(dev->of_node, "reset-gpio", 0);
644
645 if (cs4271plat)
646 cs4271->gpio_nreset = cs4271plat->gpio_nreset;
647
648 if (gpio_is_valid(cs4271->gpio_nreset)) {
649 int ret;
650
651 ret = devm_gpio_request(dev, cs4271->gpio_nreset,
652 "CS4271 Reset");
653 if (ret < 0)
654 return ret;
655 }
656
657 *c = cs4271;
658 return 0;
659}
660
661static int cs4271_spi_probe(struct spi_device *spi)
662{
663 struct cs4271_private *cs4271;
664 int ret;
665
666 ret = cs4271_common_probe(&spi->dev, &cs4271);
667 if (ret < 0)
668 return ret;
669
651 spi_set_drvdata(spi, cs4271); 670 spi_set_drvdata(spi, cs4271);
652 cs4271->regmap = devm_regmap_init_spi(spi, &cs4271_spi_regmap); 671 cs4271->regmap = devm_regmap_init_spi(spi, &cs4271_spi_regmap);
653 if (IS_ERR(cs4271->regmap)) 672 if (IS_ERR(cs4271->regmap))
@@ -697,10 +716,11 @@ static int cs4271_i2c_probe(struct i2c_client *client,
697 const struct i2c_device_id *id) 716 const struct i2c_device_id *id)
698{ 717{
699 struct cs4271_private *cs4271; 718 struct cs4271_private *cs4271;
719 int ret;
700 720
701 cs4271 = devm_kzalloc(&client->dev, sizeof(*cs4271), GFP_KERNEL); 721 ret = cs4271_common_probe(&client->dev, &cs4271);
702 if (!cs4271) 722 if (ret < 0)
703 return -ENOMEM; 723 return ret;
704 724
705 i2c_set_clientdata(client, cs4271); 725 i2c_set_clientdata(client, cs4271);
706 cs4271->regmap = devm_regmap_init_i2c(client, &cs4271_i2c_regmap); 726 cs4271->regmap = devm_regmap_init_i2c(client, &cs4271_i2c_regmap);