Class D edge rate control
authorTracy Yi <tracy-yi@ti.com>
Thu, 7 Jun 2018 10:34:28 +0000 (18:34 +0800)
committerTracy Yi <tracy-yi@ti.com>
Tue, 12 Jun 2018 01:39:18 +0000 (09:39 +0800)
Signed-off-by: Tracy Yi <tracy-yi@ti.com>
tas2557-codec.c
tas2557-core.c
tas2557-core.h
tas2557-regmap.c
tas2557.h

index 0a23976f0da4ac069bbc8d8961fbc8644f4d4bc6..cf9c4193ee8a123d1dd833bf09b54a6f3bc94fd4 100755 (executable)
@@ -469,6 +469,58 @@ static int tas2557_calibration_put(struct snd_kcontrol *pKcontrol,
        return ret;
 }
 
+static const char * const classd_edge_text[] = {
+       "0 (50ns)",
+       "1 (40ns)",
+       "2 (29ns)",
+       "3 (25ns)",
+       "4 (14ns)",
+       "5 (13ns)",
+       "6 (12ns)",
+       "7 (11ns)",
+};
+
+static const struct soc_enum classd_edge_enum[] = {
+       SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(classd_edge_text), classd_edge_text),
+};
+
+static int tas2557_edge_get(struct snd_kcontrol *pKcontrol,
+                       struct snd_ctl_elem_value *pValue)
+{
+#ifdef KCONTROL_CODEC
+       struct snd_soc_codec *codec = snd_soc_kcontrol_codec(pKcontrol);
+#else
+       struct snd_soc_codec *codec = snd_kcontrol_chip(pKcontrol);
+#endif
+       struct tas2557_priv *pTAS2557 = snd_soc_codec_get_drvdata(codec);
+       mutex_lock(&pTAS2557->codec_lock);
+
+       pValue->value.integer.value[0] = pTAS2557->mnEdge;
+
+       mutex_unlock(&pTAS2557->codec_lock);
+       return 0;
+}
+static int tas2557_edge_put(struct snd_kcontrol *pKcontrol,
+                       struct snd_ctl_elem_value *pValue)
+{
+#ifdef KCONTROL_CODEC
+       struct snd_soc_codec *codec = snd_soc_kcontrol_codec(pKcontrol);
+#else
+       struct snd_soc_codec *codec = snd_kcontrol_chip(pKcontrol);
+#endif
+       struct tas2557_priv *pTAS2557 = snd_soc_codec_get_drvdata(codec);
+       unsigned int edge = pValue->value.integer.value[0];
+
+       mutex_lock(&pTAS2557->codec_lock);
+
+       dev_dbg(pTAS2557->dev, "%s, edge %d\n", __func__, edge);
+       pTAS2557->mnEdge = pValue->value.integer.value[0];
+       tas2557_update_edge(pTAS2557);
+
+       mutex_unlock(&pTAS2557->codec_lock);
+       return 0;
+}
+
 static const struct snd_kcontrol_new tas2557_snd_controls[] = {
        SOC_SINGLE_EXT("PowerCtrl", SND_SOC_NOPM, 0, 0x0001, 0,
                tas2557_power_ctrl_get, tas2557_power_ctrl_put),
@@ -482,6 +534,8 @@ static const struct snd_kcontrol_new tas2557_snd_controls[] = {
                tas2557_Cali_get, NULL),
        SOC_SINGLE_EXT("Calibration", SND_SOC_NOPM, 0, 0x00FF, 0,
                tas2557_calibration_get, tas2557_calibration_put),
+       SOC_ENUM_EXT("TAS2557 ClassD Edge", classd_edge_enum[0],
+               tas2557_edge_get, tas2557_edge_put),
 };
 
 static struct snd_soc_codec_driver soc_codec_driver_tas2557 = {
index d482a71e32c872b058afb5bbddcd1240e9da4fff..444693069baf0a624e67f50d4161860059c09f93 100755 (executable)
@@ -445,6 +445,18 @@ end:
        return nResult;
 }
 
+int tas2557_update_edge(struct tas2557_priv *pTAS2557)
+{
+       int nResult = 0;
+       dev_dbg(pTAS2557->dev,
+               "%s, edge: %d\n",
+               __func__, pTAS2557->mnEdge);
+
+       nResult = pTAS2557->update_bits(pTAS2557, TAS2557_SPK_CTRL_REG, 0x7, pTAS2557->mnEdge);
+
+       return nResult;
+}
+
 int tas2557_enable(struct tas2557_priv *pTAS2557, bool bEnable)
 {
        int nResult = 0;
@@ -1862,6 +1874,8 @@ int tas2557_set_program(struct tas2557_priv *pTAS2557,
        if (nResult < 0)
                goto end;
 
+       tas2557_update_edge(pTAS2557);
+
        if (pTAS2557->mbPowerUp) {
                pTAS2557->clearIRQ(pTAS2557);
                dev_dbg(pTAS2557->dev, "device powered up, load startup\n");
index 77f84f81d645e4b8fc3f32f171a4d794654f771c..cb46eee353208a8c3034b7c94c1eaa926c875a75 100755 (executable)
@@ -75,4 +75,5 @@ int tas2557_parse_dt(struct device *dev, struct tas2557_priv *pTAS2557);
 int tas2557_get_DAC_gain(struct tas2557_priv *pTAS2557, unsigned char *pnGain);
 int tas2557_set_DAC_gain(struct tas2557_priv *pTAS2557, unsigned int nGain);
 int tas2557_configIRQ(struct tas2557_priv *pTAS2557);
+int tas2557_update_edge(struct tas2557_priv *pTAS2557);
 #endif /* _TAS2557_CORE_H */
index a48eca2017d7477467165ef283f8e42e0e85f7ba..e9befd485964fb0b47855756b5d42166b4194595 100755 (executable)
@@ -759,6 +759,7 @@ static int tas2557_i2c_probe(struct i2c_client *pClient,
        pTAS2557->runtime_suspend = tas2557_runtime_suspend;
        pTAS2557->runtime_resume = tas2557_runtime_resume;
        pTAS2557->mnRestart = 0;
+       pTAS2557->mnEdge = 4;
 
        mutex_init(&pTAS2557->dev_lock);
 
index 3f44f27b23782f10950d9b795c0dbdc6e72b51a1..a45c4ec1420c9529b77b73b33b281ed235de5528 100755 (executable)
--- a/tas2557.h
+++ b/tas2557.h
@@ -472,6 +472,8 @@ struct tas2557_priv {
        */
        bool mbBypassTMax;
 
+       unsigned int mnEdge;
+
 #ifdef CONFIG_TAS2557_CODEC
        struct mutex codec_lock;
 #endif