aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Mack <zonque@gmail.com>2013-10-01 08:48:25 -0400
committerMark Brown <broonie@linaro.org>2013-10-03 09:14:37 -0400
commitd5fd3ccc2d9df493ad6f1eaf7aba72f690e98937 (patch)
treee32d896baf377e744f430847f4d40b858c22a779
parent648c538204c23370c734d72921155cc24aff928d (diff)
ASoC: tas5086: move initialization code to own functions
We'll need to call code to initialize and reset the codec again at resume time, so factor it out first. Signed-off-by: Daniel Mack <zonque@gmail.com> Signed-off-by: Mark Brown <broonie@linaro.org>
-rw-r--r--sound/soc/codecs/tas5086.c128
1 files changed, 72 insertions, 56 deletions
diff --git a/sound/soc/codecs/tas5086.c b/sound/soc/codecs/tas5086.c
index 31b5868ef7c1..3a88c68145c2 100644
--- a/sound/soc/codecs/tas5086.c
+++ b/sound/soc/codecs/tas5086.c
@@ -458,6 +458,75 @@ static int tas5086_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
458 return regmap_write(priv->regmap, TAS5086_SOFT_MUTE, val); 458 return regmap_write(priv->regmap, TAS5086_SOFT_MUTE, val);
459} 459}
460 460
461static void tas5086_reset(struct tas5086_private *priv)
462{
463 if (gpio_is_valid(priv->gpio_nreset)) {
464 /* Reset codec - minimum assertion time is 400ns */
465 gpio_direction_output(priv->gpio_nreset, 0);
466 udelay(1);
467 gpio_set_value(priv->gpio_nreset, 1);
468
469 /* Codec needs ~15ms to wake up */
470 msleep(15);
471 }
472}
473
474/* charge period values in microseconds */
475static const int tas5086_charge_period[] = {
476 13000, 16900, 23400, 31200, 41600, 54600, 72800, 96200,
477 130000, 156000, 234000, 312000, 416000, 546000, 728000, 962000,
478 1300000, 169000, 2340000, 3120000, 4160000, 5460000, 7280000, 9620000,
479};
480
481static int tas5086_init(struct device *dev, struct tas5086_private *priv)
482{
483 int ret, i;
484
485 /*
486 * If any of the channels is configured to start in Mid-Z mode,
487 * configure 'part 1' of the PWM starts to use Mid-Z, and tell
488 * all configured mid-z channels to start start under 'part 1'.
489 */
490 if (priv->pwm_start_mid_z)
491 regmap_write(priv->regmap, TAS5086_PWM_START,
492 TAS5086_PWM_START_MIDZ_FOR_START_1 |
493 priv->pwm_start_mid_z);
494
495 /* lookup and set split-capacitor charge period */
496 if (priv->charge_period == 0) {
497 regmap_write(priv->regmap, TAS5086_SPLIT_CAP_CHARGE, 0);
498 } else {
499 i = index_in_array(tas5086_charge_period,
500 ARRAY_SIZE(tas5086_charge_period),
501 priv->charge_period);
502 if (i >= 0)
503 regmap_write(priv->regmap, TAS5086_SPLIT_CAP_CHARGE,
504 i + 0x08);
505 else
506 dev_warn(dev,
507 "Invalid split-cap charge period of %d ns.\n",
508 priv->charge_period);
509 }
510
511 /* enable factory trim */
512 ret = regmap_write(priv->regmap, TAS5086_OSC_TRIM, 0x00);
513 if (ret < 0)
514 return ret;
515
516 /* start all channels */
517 ret = regmap_write(priv->regmap, TAS5086_SYS_CONTROL_2, 0x20);
518 if (ret < 0)
519 return ret;
520
521 /* mute all channels for now */
522 ret = regmap_write(priv->regmap, TAS5086_SOFT_MUTE,
523 TAS5086_SOFT_MUTE_ALL);
524 if (ret < 0)
525 return ret;
526
527 return 0;
528}
529
461/* TAS5086 controls */ 530/* TAS5086 controls */
462static const DECLARE_TLV_DB_SCALE(tas5086_dac_tlv, -10350, 50, 1); 531static const DECLARE_TLV_DB_SCALE(tas5086_dac_tlv, -10350, 50, 1);
463 532
@@ -712,13 +781,6 @@ static const struct of_device_id tas5086_dt_ids[] = {
712MODULE_DEVICE_TABLE(of, tas5086_dt_ids); 781MODULE_DEVICE_TABLE(of, tas5086_dt_ids);
713#endif 782#endif
714 783
715/* charge period values in microseconds */
716static const int tas5086_charge_period[] = {
717 13000, 16900, 23400, 31200, 41600, 54600, 72800, 96200,
718 130000, 156000, 234000, 312000, 416000, 546000, 728000, 962000,
719 1300000, 169000, 2340000, 3120000, 4160000, 5460000, 7280000, 9620000,
720};
721
722static int tas5086_probe(struct snd_soc_codec *codec) 784static int tas5086_probe(struct snd_soc_codec *codec)
723{ 785{
724 struct tas5086_private *priv = snd_soc_codec_get_drvdata(codec); 786 struct tas5086_private *priv = snd_soc_codec_get_drvdata(codec);
@@ -729,6 +791,7 @@ static int tas5086_probe(struct snd_soc_codec *codec)
729 791
730 if (of_match_device(of_match_ptr(tas5086_dt_ids), codec->dev)) { 792 if (of_match_device(of_match_ptr(tas5086_dt_ids), codec->dev)) {
731 struct device_node *of_node = codec->dev->of_node; 793 struct device_node *of_node = codec->dev->of_node;
794
732 of_property_read_u32(of_node, "ti,charge-period", 795 of_property_read_u32(of_node, "ti,charge-period",
733 &priv->charge_period); 796 &priv->charge_period);
734 797
@@ -743,39 +806,7 @@ static int tas5086_probe(struct snd_soc_codec *codec)
743 } 806 }
744 } 807 }
745 808
746 /* 809 ret = tas5086_init(codec->dev, priv);
747 * If any of the channels is configured to start in Mid-Z mode,
748 * configure 'part 1' of the PWM starts to use Mid-Z, and tell
749 * all configured mid-z channels to start start under 'part 1'.
750 */
751 if (priv->pwm_start_mid_z)
752 regmap_write(priv->regmap, TAS5086_PWM_START,
753 TAS5086_PWM_START_MIDZ_FOR_START_1 |
754 priv->pwm_start_mid_z);
755
756 /* lookup and set split-capacitor charge period */
757 if (priv->charge_period == 0) {
758 regmap_write(priv->regmap, TAS5086_SPLIT_CAP_CHARGE, 0);
759 } else {
760 i = index_in_array(tas5086_charge_period,
761 ARRAY_SIZE(tas5086_charge_period),
762 priv->charge_period);
763 if (i >= 0)
764 regmap_write(priv->regmap, TAS5086_SPLIT_CAP_CHARGE,
765 i + 0x08);
766 else
767 dev_warn(codec->dev,
768 "Invalid split-cap charge period of %d ns.\n",
769 priv->charge_period);
770 }
771
772 /* enable factory trim */
773 ret = regmap_write(priv->regmap, TAS5086_OSC_TRIM, 0x00);
774 if (ret < 0)
775 return ret;
776
777 /* start all channels */
778 ret = regmap_write(priv->regmap, TAS5086_SYS_CONTROL_2, 0x20);
779 if (ret < 0) 810 if (ret < 0)
780 return ret; 811 return ret;
781 812
@@ -784,12 +815,6 @@ static int tas5086_probe(struct snd_soc_codec *codec)
784 if (ret < 0) 815 if (ret < 0)
785 return ret; 816 return ret;
786 817
787 /* mute all channels for now */
788 ret = regmap_write(priv->regmap, TAS5086_SOFT_MUTE,
789 TAS5086_SOFT_MUTE_ALL);
790 if (ret < 0)
791 return ret;
792
793 return 0; 818 return 0;
794} 819}
795 820
@@ -866,17 +891,8 @@ static int tas5086_i2c_probe(struct i2c_client *i2c,
866 if (devm_gpio_request(dev, gpio_nreset, "TAS5086 Reset")) 891 if (devm_gpio_request(dev, gpio_nreset, "TAS5086 Reset"))
867 gpio_nreset = -EINVAL; 892 gpio_nreset = -EINVAL;
868 893
869 if (gpio_is_valid(gpio_nreset)) {
870 /* Reset codec - minimum assertion time is 400ns */
871 gpio_direction_output(gpio_nreset, 0);
872 udelay(1);
873 gpio_set_value(gpio_nreset, 1);
874
875 /* Codec needs ~15ms to wake up */
876 msleep(15);
877 }
878
879 priv->gpio_nreset = gpio_nreset; 894 priv->gpio_nreset = gpio_nreset;
895 tas5086_reset(priv);
880 896
881 /* The TAS5086 always returns 0x03 in its TAS5086_DEV_ID register */ 897 /* The TAS5086 always returns 0x03 in its TAS5086_DEV_ID register */
882 ret = regmap_read(priv->regmap, TAS5086_DEV_ID, &i); 898 ret = regmap_read(priv->regmap, TAS5086_DEV_ID, &i);