Merge remote-tracking branches 'asoc/topic/rk3036', 'asoc/topic/rockchip', 'asoc...
[sfrench/cifs-2.6.git] / sound / soc / codecs / rt5514.c
index 882fdc4a6fd4fb9bba4b8aae5383b9ab88572f1f..0945d212b8dca9d34d19b273d9075977075964e1 100644 (file)
@@ -31,7 +31,7 @@
 
 #include "rl6231.h"
 #include "rt5514.h"
-#if defined(CONFIG_SND_SOC_RT5514_SPI)
+#if IS_ENABLED(CONFIG_SND_SOC_RT5514_SPI)
 #include "rt5514-spi.h"
 #endif
 
@@ -64,6 +64,8 @@ static const struct reg_sequence rt5514_patch[] = {
        {RT5514_ANA_CTRL_LDO10,         0x00028604},
        {RT5514_ANA_CTRL_ADCFED,        0x00000800},
        {RT5514_ASRC_IN_CTRL1,          0x00000003},
+       {RT5514_DOWNFILTER0_CTRL3,      0x10000362},
+       {RT5514_DOWNFILTER1_CTRL3,      0x10000362},
 };
 
 static const struct reg_default rt5514_reg[] = {
@@ -89,10 +91,10 @@ static const struct reg_default rt5514_reg[] = {
        {RT5514_DELAY_BUF_CTRL3,        0x00000000},
        {RT5514_DOWNFILTER0_CTRL1,      0x00020c2f},
        {RT5514_DOWNFILTER0_CTRL2,      0x00020c2f},
-       {RT5514_DOWNFILTER0_CTRL3,      0x00000362},
+       {RT5514_DOWNFILTER0_CTRL3,      0x10000362},
        {RT5514_DOWNFILTER1_CTRL1,      0x00020c2f},
        {RT5514_DOWNFILTER1_CTRL2,      0x00020c2f},
-       {RT5514_DOWNFILTER1_CTRL3,      0x00000362},
+       {RT5514_DOWNFILTER1_CTRL3,      0x10000362},
        {RT5514_ANA_CTRL_LDO10,         0x00028604},
        {RT5514_ANA_CTRL_LDO18_16,      0x02000345},
        {RT5514_ANA_CTRL_ADC12,         0x0000a2a8},
@@ -312,7 +314,7 @@ static int rt5514_dsp_voice_wake_up_put(struct snd_kcontrol *kcontrol,
 
                        request_firmware(&fw, RT5514_FIRMWARE1, codec->dev);
                        if (fw) {
-#if defined(CONFIG_SND_SOC_RT5514_SPI)
+#if IS_ENABLED(CONFIG_SND_SOC_RT5514_SPI)
                                rt5514_spi_burst_write(0x4ff60000, fw->data,
                                        ((fw->size/8)+1)*8);
 #else
@@ -325,7 +327,7 @@ static int rt5514_dsp_voice_wake_up_put(struct snd_kcontrol *kcontrol,
 
                        request_firmware(&fw, RT5514_FIRMWARE2, codec->dev);
                        if (fw) {
-#if defined(CONFIG_SND_SOC_RT5514_SPI)
+#if IS_ENABLED(CONFIG_SND_SOC_RT5514_SPI)
                                rt5514_spi_burst_write(0x4ffc0000, fw->data,
                                        ((fw->size/8)+1)*8);
 #else
@@ -336,6 +338,39 @@ static int rt5514_dsp_voice_wake_up_put(struct snd_kcontrol *kcontrol,
                                fw = NULL;
                        }
 
+                       if (rt5514->model_buf && rt5514->model_len) {
+#if IS_ENABLED(CONFIG_SND_SOC_RT5514_SPI)
+                               int ret;
+
+                               ret = rt5514_spi_burst_write(0x4ff80000,
+                                       rt5514->model_buf,
+                                       ((rt5514->model_len / 8) + 1) * 8);
+                               if (ret) {
+                                       dev_err(codec->dev,
+                                               "Model load failed %d\n", ret);
+                                       return ret;
+                               }
+#else
+                               dev_err(codec->dev,
+                                       "No SPI driver for loading firmware\n");
+#endif
+                       } else {
+                               request_firmware(&fw, RT5514_FIRMWARE3,
+                                                codec->dev);
+                               if (fw) {
+#if IS_ENABLED(CONFIG_SND_SOC_RT5514_SPI)
+                                       rt5514_spi_burst_write(0x4ff80000,
+                                               fw->data,
+                                               ((fw->size/8)+1)*8);
+#else
+                                       dev_err(codec->dev,
+                                               "No SPI driver to load fw\n");
+#endif
+                                       release_firmware(fw);
+                                       fw = NULL;
+                               }
+                       }
+
                        /* DSP run */
                        regmap_write(rt5514->i2c_regmap, 0x18002f00,
                                0x00055148);
@@ -350,6 +385,34 @@ static int rt5514_dsp_voice_wake_up_put(struct snd_kcontrol *kcontrol,
        return 0;
 }
 
+static int rt5514_hotword_model_put(struct snd_kcontrol *kcontrol,
+               const unsigned int __user *bytes, unsigned int size)
+{
+       struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
+       struct rt5514_priv *rt5514 = snd_soc_component_get_drvdata(component);
+       struct snd_soc_codec *codec = rt5514->codec;
+       int ret = 0;
+
+       if (rt5514->model_buf || rt5514->model_len < size) {
+               if (rt5514->model_buf)
+                       devm_kfree(codec->dev, rt5514->model_buf);
+               rt5514->model_buf = devm_kmalloc(codec->dev, size, GFP_KERNEL);
+               if (!rt5514->model_buf) {
+                       ret = -ENOMEM;
+                       goto done;
+               }
+       }
+
+       /* Skips the TLV header. */
+       bytes += 2;
+
+       if (copy_from_user(rt5514->model_buf, bytes, size))
+               ret = -EFAULT;
+done:
+       rt5514->model_len = (ret ? 0 : size);
+       return ret;
+}
+
 static const struct snd_kcontrol_new rt5514_snd_controls[] = {
        SOC_DOUBLE_TLV("MIC Boost Volume", RT5514_ANA_CTRL_MICBST,
                RT5514_SEL_BSTL_SFT, RT5514_SEL_BSTR_SFT, 8, 0, bst_tlv),
@@ -361,6 +424,8 @@ static const struct snd_kcontrol_new rt5514_snd_controls[] = {
                adc_vol_tlv),
        SOC_SINGLE_EXT("DSP Voice Wake Up", SND_SOC_NOPM, 0, 1, 0,
                rt5514_dsp_voice_wake_up_get, rt5514_dsp_voice_wake_up_put),
+       SND_SOC_BYTES_TLV("Hotword Model", 0x8504,
+               NULL, rt5514_hotword_model_put),
 };
 
 /* ADC Mixer*/
@@ -1064,7 +1129,7 @@ static const struct snd_soc_dai_ops rt5514_aif_dai_ops = {
        .set_tdm_slot = rt5514_set_tdm_slot,
 };
 
-struct snd_soc_dai_driver rt5514_dai[] = {
+static struct snd_soc_dai_driver rt5514_dai[] = {
        {
                .name = "rt5514-aif1",
                .id = 0,
@@ -1079,7 +1144,7 @@ struct snd_soc_dai_driver rt5514_dai[] = {
        }
 };
 
-static struct snd_soc_codec_driver soc_codec_dev_rt5514 = {
+static const struct snd_soc_codec_driver soc_codec_dev_rt5514 = {
        .probe = rt5514_probe,
        .idle_bias_off = true,
        .set_bias_level = rt5514_set_bias_level,
@@ -1134,7 +1199,7 @@ MODULE_DEVICE_TABLE(of, rt5514_of_match);
 #endif
 
 #ifdef CONFIG_ACPI
-static struct acpi_device_id rt5514_acpi_match[] = {
+static const struct acpi_device_id rt5514_acpi_match[] = {
        { "10EC5514", 0},
        {},
 };