ALSA: hda: cs35l41: Add Boost type flag
authorLucas Tanure <tanureal@opensource.cirrus.com>
Wed, 13 Apr 2022 08:37:18 +0000 (09:37 +0100)
committerTakashi Iwai <tiwai@suse.de>
Wed, 13 Apr 2022 08:42:33 +0000 (10:42 +0200)
Replace vspk_always_on by a enum that better characterizes the boost
type, as there is 3 types of boost hardware.
And with the new boost type other parts of the driver can better handle
the configuration of the chip.

Signed-off-by: Lucas Tanure <tanureal@opensource.cirrus.com>
Link: https://lore.kernel.org/r/20220413083728.10730-7-tanureal@opensource.cirrus.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>
include/sound/cs35l41.h
sound/pci/hda/cs35l41_hda.c

index e312eb1f6e4803343b2c338eaf3f2e95f8b0f3e5..64d98cbd5c0eb9e91b89a46890332c0e97fb0503 100644 (file)
 #define CS35L41_SPI_MAX_FREQ           4000000
 #define CS35L41_REGSTRIDE              4
 
+enum cs35l41_boost_type {
+       CS35L41_INT_BOOST,
+       CS35L41_EXT_BOOST,
+       CS35L41_EXT_BOOST_NO_VSPK_SWITCH,
+};
+
 enum cs35l41_clk_ids {
        CS35L41_CLKID_SCLK = 0,
        CS35L41_CLKID_LRCLK = 1,
@@ -768,8 +774,7 @@ struct cs35l41_hw_cfg {
        struct cs35l41_gpio_cfg gpio2;
        unsigned int spk_pos;
 
-       /* Don't put the AMP in reset if VSPK can not be turned off */
-       bool vspk_always_on;
+       enum cs35l41_boost_type bst_type;
 };
 
 struct cs35l41_otp_packed_element_t {
index f853530eb3852a341fe2b72e1b8110084a99b73e..0dac622805c480634eb6006913d42353b428b353 100644 (file)
@@ -210,20 +210,30 @@ static const struct component_ops cs35l41_hda_comp_ops = {
 static int cs35l41_hda_apply_properties(struct cs35l41_hda *cs35l41)
 {
        struct cs35l41_hw_cfg *hw_cfg = &cs35l41->hw_cfg;
-       bool internal_boost = false;
        int ret;
 
        if (!cs35l41->hw_cfg.valid)
                return -EINVAL;
 
-       if (hw_cfg->vspk_always_on) {
+       switch (hw_cfg->bst_type) {
+       case CS35L41_INT_BOOST:
+               cs35l41->reg_seq = &cs35l41_hda_reg_seq_int_bst;
+               ret = cs35l41_boost_config(cs35l41->dev, cs35l41->regmap,
+                                          hw_cfg->bst_ind, hw_cfg->bst_cap, hw_cfg->bst_ipk);
+               if (ret)
+                       return ret;
+               break;
+       case CS35L41_EXT_BOOST:
+               cs35l41->reg_seq = &cs35l41_hda_reg_seq_ext_bst;
+               break;
+       case CS35L41_EXT_BOOST_NO_VSPK_SWITCH:
                cs35l41->reg_seq = &cs35l41_hda_reg_seq_no_bst;
-               return 0;
+               break;
+       default:
+               dev_err(cs35l41->dev, "Boost type %d not supported\n", hw_cfg->bst_type);
+               return -EINVAL;
        }
 
-       if (hw_cfg->bst_ind > 0 || hw_cfg->bst_cap > 0 || hw_cfg->bst_ipk > 0)
-               internal_boost = true;
-
        if (hw_cfg->gpio1.valid) {
                switch (hw_cfg->gpio1.func) {
                case CS35L41_NOT_USED:
@@ -256,16 +266,6 @@ static int cs35l41_hda_apply_properties(struct cs35l41_hda *cs35l41)
 
        cs35l41_gpio_config(cs35l41->regmap, hw_cfg);
 
-       if (internal_boost) {
-               cs35l41->reg_seq = &cs35l41_hda_reg_seq_int_bst;
-               ret = cs35l41_boost_config(cs35l41->dev, cs35l41->regmap,
-                                          hw_cfg->bst_ind, hw_cfg->bst_cap, hw_cfg->bst_ipk);
-               if (ret)
-                       return ret;
-       } else {
-               cs35l41->reg_seq = &cs35l41_hda_reg_seq_ext_bst;
-       }
-
        return cs35l41_hda_channel_map(cs35l41->dev, 0, NULL, 1, &hw_cfg->spk_pos);
 }
 
@@ -363,6 +363,11 @@ static int cs35l41_hda_read_acpi(struct cs35l41_hda *cs35l41, const char *hid, i
        else
                hw_cfg->bst_cap = -1;
 
+       if (hw_cfg->bst_ind > 0 || hw_cfg->bst_cap > 0 || hw_cfg->bst_ipk > 0)
+               hw_cfg->bst_type = CS35L41_INT_BOOST;
+       else
+               hw_cfg->bst_type = CS35L41_EXT_BOOST;
+
        hw_cfg->valid = true;
        put_device(physdev);
 
@@ -388,7 +393,7 @@ no_acpi_dsd:
        /* check I2C address to assign the index */
        cs35l41->index = id == 0x40 ? 0 : 1;
        cs35l41->reset_gpio = gpiod_get_index(physdev, NULL, 0, GPIOD_OUT_HIGH);
-       cs35l41->hw_cfg.vspk_always_on = true;
+       cs35l41->hw_cfg.bst_type = CS35L41_EXT_BOOST_NO_VSPK_SWITCH;
        cs35l41->hw_cfg.valid = true;
        put_device(physdev);
 
@@ -515,7 +520,7 @@ int cs35l41_hda_probe(struct device *dev, const char *device_name, int id, int i
        return 0;
 
 err:
-       if (!cs35l41->hw_cfg.vspk_always_on)
+       if (cs35l41->hw_cfg.bst_type != CS35L41_EXT_BOOST_NO_VSPK_SWITCH)
                gpiod_set_value_cansleep(cs35l41->reset_gpio, 0);
        gpiod_put(cs35l41->reset_gpio);
 
@@ -529,7 +534,7 @@ void cs35l41_hda_remove(struct device *dev)
 
        component_del(cs35l41->dev, &cs35l41_hda_comp_ops);
 
-       if (!cs35l41->hw_cfg.vspk_always_on)
+       if (cs35l41->hw_cfg.bst_type != CS35L41_EXT_BOOST_NO_VSPK_SWITCH)
                gpiod_set_value_cansleep(cs35l41->reset_gpio, 0);
        gpiod_put(cs35l41->reset_gpio);
 }