diff options
Diffstat (limited to 'sound/soc/codecs/cs4271.c')
-rw-r--r-- | sound/soc/codecs/cs4271.c | 63 |
1 files changed, 41 insertions, 22 deletions
diff --git a/sound/soc/codecs/cs4271.c b/sound/soc/codecs/cs4271.c index ce05fd93dc74..aef4965750c7 100644 --- a/sound/soc/codecs/cs4271.c +++ b/sound/soc/codecs/cs4271.c | |||
@@ -159,7 +159,6 @@ static bool cs4271_volatile_reg(struct device *dev, unsigned int reg) | |||
159 | } | 159 | } |
160 | 160 | ||
161 | struct cs4271_private { | 161 | struct cs4271_private { |
162 | /* SND_SOC_I2C or SND_SOC_SPI */ | ||
163 | unsigned int mclk; | 162 | unsigned int mclk; |
164 | bool master; | 163 | bool master; |
165 | bool deemph; | 164 | bool deemph; |
@@ -540,14 +539,10 @@ static int cs4271_probe(struct snd_soc_codec *codec) | |||
540 | struct cs4271_private *cs4271 = snd_soc_codec_get_drvdata(codec); | 539 | struct cs4271_private *cs4271 = snd_soc_codec_get_drvdata(codec); |
541 | struct cs4271_platform_data *cs4271plat = codec->dev->platform_data; | 540 | struct cs4271_platform_data *cs4271plat = codec->dev->platform_data; |
542 | int ret; | 541 | int ret; |
543 | int gpio_nreset = -EINVAL; | ||
544 | bool amutec_eq_bmutec = false; | 542 | bool amutec_eq_bmutec = false; |
545 | 543 | ||
546 | #ifdef CONFIG_OF | 544 | #ifdef CONFIG_OF |
547 | if (of_match_device(cs4271_dt_ids, codec->dev)) { | 545 | if (of_match_device(cs4271_dt_ids, codec->dev)) { |
548 | gpio_nreset = of_get_named_gpio(codec->dev->of_node, | ||
549 | "reset-gpio", 0); | ||
550 | |||
551 | if (of_get_property(codec->dev->of_node, | 546 | if (of_get_property(codec->dev->of_node, |
552 | "cirrus,amutec-eq-bmutec", NULL)) | 547 | "cirrus,amutec-eq-bmutec", NULL)) |
553 | amutec_eq_bmutec = true; | 548 | amutec_eq_bmutec = true; |
@@ -559,27 +554,19 @@ static int cs4271_probe(struct snd_soc_codec *codec) | |||
559 | #endif | 554 | #endif |
560 | 555 | ||
561 | if (cs4271plat) { | 556 | if (cs4271plat) { |
562 | if (gpio_is_valid(cs4271plat->gpio_nreset)) | ||
563 | gpio_nreset = cs4271plat->gpio_nreset; | ||
564 | |||
565 | amutec_eq_bmutec = cs4271plat->amutec_eq_bmutec; | 557 | amutec_eq_bmutec = cs4271plat->amutec_eq_bmutec; |
566 | cs4271->enable_soft_reset = cs4271plat->enable_soft_reset; | 558 | cs4271->enable_soft_reset = cs4271plat->enable_soft_reset; |
567 | } | 559 | } |
568 | 560 | ||
569 | if (gpio_nreset >= 0) | 561 | if (gpio_is_valid(cs4271->gpio_nreset)) { |
570 | if (devm_gpio_request(codec->dev, gpio_nreset, "CS4271 Reset")) | ||
571 | gpio_nreset = -EINVAL; | ||
572 | if (gpio_nreset >= 0) { | ||
573 | /* Reset codec */ | 562 | /* Reset codec */ |
574 | gpio_direction_output(gpio_nreset, 0); | 563 | gpio_direction_output(cs4271->gpio_nreset, 0); |
575 | udelay(1); | 564 | udelay(1); |
576 | gpio_set_value(gpio_nreset, 1); | 565 | gpio_set_value(cs4271->gpio_nreset, 1); |
577 | /* Give the codec time to wake up */ | 566 | /* Give the codec time to wake up */ |
578 | udelay(1); | 567 | udelay(1); |
579 | } | 568 | } |
580 | 569 | ||
581 | cs4271->gpio_nreset = gpio_nreset; | ||
582 | |||
583 | ret = regmap_update_bits(cs4271->regmap, CS4271_MODE2, | 570 | ret = regmap_update_bits(cs4271->regmap, CS4271_MODE2, |
584 | CS4271_MODE2_PDN | CS4271_MODE2_CPEN, | 571 | CS4271_MODE2_PDN | CS4271_MODE2_CPEN, |
585 | CS4271_MODE2_PDN | CS4271_MODE2_CPEN); | 572 | CS4271_MODE2_PDN | CS4271_MODE2_CPEN); |
@@ -625,6 +612,36 @@ static struct snd_soc_codec_driver soc_codec_dev_cs4271 = { | |||
625 | .num_dapm_routes = ARRAY_SIZE(cs4271_dapm_routes), | 612 | .num_dapm_routes = ARRAY_SIZE(cs4271_dapm_routes), |
626 | }; | 613 | }; |
627 | 614 | ||
615 | static int cs4271_common_probe(struct device *dev, | ||
616 | struct cs4271_private **c) | ||
617 | { | ||
618 | struct cs4271_platform_data *cs4271plat = dev->platform_data; | ||
619 | struct cs4271_private *cs4271; | ||
620 | |||
621 | cs4271 = devm_kzalloc(dev, sizeof(*cs4271), GFP_KERNEL); | ||
622 | if (!cs4271) | ||
623 | return -ENOMEM; | ||
624 | |||
625 | if (of_match_device(cs4271_dt_ids, dev)) | ||
626 | cs4271->gpio_nreset = | ||
627 | of_get_named_gpio(dev->of_node, "reset-gpio", 0); | ||
628 | |||
629 | if (cs4271plat) | ||
630 | cs4271->gpio_nreset = cs4271plat->gpio_nreset; | ||
631 | |||
632 | if (gpio_is_valid(cs4271->gpio_nreset)) { | ||
633 | int ret; | ||
634 | |||
635 | ret = devm_gpio_request(dev, cs4271->gpio_nreset, | ||
636 | "CS4271 Reset"); | ||
637 | if (ret < 0) | ||
638 | return ret; | ||
639 | } | ||
640 | |||
641 | *c = cs4271; | ||
642 | return 0; | ||
643 | } | ||
644 | |||
628 | #if defined(CONFIG_SPI_MASTER) | 645 | #if defined(CONFIG_SPI_MASTER) |
629 | 646 | ||
630 | static const struct regmap_config cs4271_spi_regmap = { | 647 | static const struct regmap_config cs4271_spi_regmap = { |
@@ -644,10 +661,11 @@ static const struct regmap_config cs4271_spi_regmap = { | |||
644 | static int cs4271_spi_probe(struct spi_device *spi) | 661 | static int cs4271_spi_probe(struct spi_device *spi) |
645 | { | 662 | { |
646 | struct cs4271_private *cs4271; | 663 | struct cs4271_private *cs4271; |
664 | int ret; | ||
647 | 665 | ||
648 | cs4271 = devm_kzalloc(&spi->dev, sizeof(*cs4271), GFP_KERNEL); | 666 | ret = cs4271_common_probe(&spi->dev, &cs4271); |
649 | if (!cs4271) | 667 | if (ret < 0) |
650 | return -ENOMEM; | 668 | return ret; |
651 | 669 | ||
652 | spi_set_drvdata(spi, cs4271); | 670 | spi_set_drvdata(spi, cs4271); |
653 | cs4271->regmap = devm_regmap_init_spi(spi, &cs4271_spi_regmap); | 671 | cs4271->regmap = devm_regmap_init_spi(spi, &cs4271_spi_regmap); |
@@ -698,10 +716,11 @@ static int cs4271_i2c_probe(struct i2c_client *client, | |||
698 | const struct i2c_device_id *id) | 716 | const struct i2c_device_id *id) |
699 | { | 717 | { |
700 | struct cs4271_private *cs4271; | 718 | struct cs4271_private *cs4271; |
719 | int ret; | ||
701 | 720 | ||
702 | cs4271 = devm_kzalloc(&client->dev, sizeof(*cs4271), GFP_KERNEL); | 721 | ret = cs4271_common_probe(&client->dev, &cs4271); |
703 | if (!cs4271) | 722 | if (ret < 0) |
704 | return -ENOMEM; | 723 | return ret; |
705 | 724 | ||
706 | i2c_set_clientdata(client, cs4271); | 725 | i2c_set_clientdata(client, cs4271); |
707 | cs4271->regmap = devm_regmap_init_i2c(client, &cs4271_i2c_regmap); | 726 | cs4271->regmap = devm_regmap_init_i2c(client, &cs4271_i2c_regmap); |