ALSA: hda/tas2781: select program 0, conf 0 by default
[platform/kernel/linux-rpi.git] / sound / pci / hda / tas2781_hda_i2c.c
index 37114fd..2fb1a70 100644 (file)
@@ -173,16 +173,6 @@ static int tasdevice_get_profile_id(struct snd_kcontrol *kcontrol,
        return 0;
 }
 
-static int tasdevice_hda_clamp(int val, int max)
-{
-       if (val > max)
-               val = max;
-
-       if (val < 0)
-               val = 0;
-       return val;
-}
-
 static int tasdevice_set_profile_id(struct snd_kcontrol *kcontrol,
                struct snd_ctl_elem_value *ucontrol)
 {
@@ -191,7 +181,7 @@ static int tasdevice_set_profile_id(struct snd_kcontrol *kcontrol,
        int max = tas_priv->rcabin.ncfgs - 1;
        int val, ret = 0;
 
-       val = tasdevice_hda_clamp(nr_profile, max);
+       val = clamp(nr_profile, 0, max);
 
        if (tas_priv->rcabin.profile_cfg_id != val) {
                tas_priv->rcabin.profile_cfg_id = val;
@@ -248,7 +238,7 @@ static int tasdevice_program_put(struct snd_kcontrol *kcontrol,
        int max = tas_fw->nr_programs - 1;
        int val, ret = 0;
 
-       val = tasdevice_hda_clamp(nr_program, max);
+       val = clamp(nr_program, 0, max);
 
        if (tas_priv->cur_prog != val) {
                tas_priv->cur_prog = val;
@@ -277,7 +267,7 @@ static int tasdevice_config_put(struct snd_kcontrol *kcontrol,
        int max = tas_fw->nr_configurations - 1;
        int val, ret = 0;
 
-       val = tasdevice_hda_clamp(nr_config, max);
+       val = clamp(nr_config, 0, max);
 
        if (tas_priv->cur_conf != val) {
                tas_priv->cur_conf = val;
@@ -465,9 +455,9 @@ static int tas2781_save_calibration(struct tasdevice_priv *tas_priv)
                status = efi.get_variable(efi_name, &efi_guid, &attr,
                        &tas_priv->cali_data.total_sz,
                        tas_priv->cali_data.data);
-               if (status != EFI_SUCCESS)
-                       return -EINVAL;
        }
+       if (status != EFI_SUCCESS)
+               return -EINVAL;
 
        tmp_val = (unsigned int *)tas_priv->cali_data.data;
 
@@ -553,6 +543,10 @@ static void tasdev_fw_ready(const struct firmware *fmw, void *context)
 
        tas_priv->fw_state = TASDEVICE_DSP_FW_ALL_OK;
        tasdevice_prmg_load(tas_priv, 0);
+       if (tas_priv->fmw->nr_programs > 0)
+               tas_priv->cur_prog = 0;
+       if (tas_priv->fmw->nr_configurations > 0)
+               tas_priv->cur_conf = 0;
 
        /* If calibrated data occurs error, dsp will still works with default
         * calibrated data inside algo.
@@ -560,11 +554,6 @@ static void tasdev_fw_ready(const struct firmware *fmw, void *context)
        tas2781_save_calibration(tas_priv);
 
 out:
-       if (tas_priv->fw_state == TASDEVICE_DSP_FW_FAIL) {
-               /*If DSP FW fail, kcontrol won't be created */
-               tasdevice_config_info_remove(tas_priv);
-               tasdevice_dsp_remove(tas_priv);
-       }
        mutex_unlock(&tas_priv->codec_lock);
        if (fmw)
                release_firmware(fmw);
@@ -622,9 +611,13 @@ static void tas2781_hda_unbind(struct device *dev,
 {
        struct tasdevice_priv *tas_priv = dev_get_drvdata(dev);
        struct hda_component *comps = master_data;
+       comps = &comps[tas_priv->index];
 
-       if (comps[tas_priv->index].dev == dev)
-               memset(&comps[tas_priv->index], 0, sizeof(*comps));
+       if (comps->dev == dev) {
+               comps->dev = NULL;
+               memset(comps->name, 0, sizeof(comps->name));
+               comps->playback_hook = NULL;
+       }
 
        tasdevice_config_info_remove(tas_priv);
        tasdevice_dsp_remove(tas_priv);
@@ -685,14 +678,14 @@ static int tas2781_hda_i2c_probe(struct i2c_client *clt)
 
        pm_runtime_put_autosuspend(tas_priv->dev);
 
+       tas2781_reset(tas_priv);
+
        ret = component_add(tas_priv->dev, &tas2781_hda_comp_ops);
        if (ret) {
                dev_err(tas_priv->dev, "Register component failed: %d\n", ret);
                pm_runtime_disable(tas_priv->dev);
-               goto err;
        }
 
-       tas2781_reset(tas_priv);
 err:
        if (ret)
                tas2781_hda_remove(&clt->dev);