]> www.infradead.org Git - users/hch/configfs.git/commitdiff
ALSA: hda: hda_component: Change codecs to use component parent structure
authorSimon Trimmer <simont@opensource.cirrus.com>
Mon, 17 Jun 2024 15:41:03 +0000 (16:41 +0100)
committerTakashi Iwai <tiwai@suse.de>
Tue, 18 Jun 2024 09:58:45 +0000 (11:58 +0200)
Change the hda_component binding APIs to pass the hds_component_parent
as the parameter so the array of components can be abstracted.

Signed-off-by: Simon Trimmer <simont@opensource.cirrus.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/20240617154105.108635-3-simont@opensource.cirrus.com
sound/pci/hda/cs35l41_hda.c
sound/pci/hda/cs35l56_hda.c
sound/pci/hda/hda_component.c
sound/pci/hda/hda_component.h
sound/pci/hda/tas2781_hda_i2c.c

index 031703f010be5b25aee4f124915862a4b1af77dc..ceba4f2c85f1a58fcaae8c892659f92c7d072618 100644 (file)
@@ -1419,27 +1419,28 @@ static void cs35l41_acpi_device_notify(acpi_handle handle, u32 event, struct dev
 static int cs35l41_hda_bind(struct device *dev, struct device *master, void *master_data)
 {
        struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev);
-       struct hda_component *comps = master_data;
+       struct hda_component_parent *parent = master_data;
+       struct hda_component *comp;
        unsigned int sleep_flags;
        int ret = 0;
 
-       if (!comps || cs35l41->index < 0 || cs35l41->index >= HDA_MAX_COMPONENTS)
+       comp = hda_component_from_index(parent, cs35l41->index);
+       if (!comp)
                return -EINVAL;
 
-       comps = &comps[cs35l41->index];
-       if (comps->dev)
+       if (comp->dev)
                return -EBUSY;
 
        pm_runtime_get_sync(dev);
 
        mutex_lock(&cs35l41->fw_mutex);
 
-       comps->dev = dev;
+       comp->dev = dev;
        if (!cs35l41->acpi_subsystem_id)
                cs35l41->acpi_subsystem_id = kasprintf(GFP_KERNEL, "%.8x",
-                                                      comps->codec->core.subsystem_id);
-       cs35l41->codec = comps->codec;
-       strscpy(comps->name, dev_name(dev), sizeof(comps->name));
+                                                      comp->codec->core.subsystem_id);
+       cs35l41->codec = comp->codec;
+       strscpy(comp->name, dev_name(dev), sizeof(comp->name));
 
        cs35l41->firmware_type = HDA_CS_DSP_FW_SPK_PROT;
 
@@ -1454,13 +1455,13 @@ static int cs35l41_hda_bind(struct device *dev, struct device *master, void *mas
 
        ret = cs35l41_create_controls(cs35l41);
 
-       comps->playback_hook = cs35l41_hda_playback_hook;
-       comps->pre_playback_hook = cs35l41_hda_pre_playback_hook;
-       comps->post_playback_hook = cs35l41_hda_post_playback_hook;
-       comps->acpi_notify = cs35l41_acpi_device_notify;
-       comps->adev = cs35l41->dacpi;
+       comp->playback_hook = cs35l41_hda_playback_hook;
+       comp->pre_playback_hook = cs35l41_hda_pre_playback_hook;
+       comp->post_playback_hook = cs35l41_hda_post_playback_hook;
+       comp->acpi_notify = cs35l41_acpi_device_notify;
+       comp->adev = cs35l41->dacpi;
 
-       comps->acpi_notifications_supported = cs35l41_dsm_supported(acpi_device_handle(comps->adev),
+       comp->acpi_notifications_supported = cs35l41_dsm_supported(acpi_device_handle(comp->adev),
                CS35L41_DSM_GET_MUTE);
 
        cs35l41->mute_override = cs35l41_get_acpi_mute_state(cs35l41,
@@ -1469,7 +1470,7 @@ static int cs35l41_hda_bind(struct device *dev, struct device *master, void *mas
        mutex_unlock(&cs35l41->fw_mutex);
 
        sleep_flags = lock_system_sleep();
-       if (!device_link_add(&comps->codec->core.dev, cs35l41->dev, DL_FLAG_STATELESS))
+       if (!device_link_add(&comp->codec->core.dev, cs35l41->dev, DL_FLAG_STATELESS))
                dev_warn(dev, "Unable to create device link\n");
        unlock_system_sleep(sleep_flags);
 
@@ -1489,14 +1490,19 @@ static int cs35l41_hda_bind(struct device *dev, struct device *master, void *mas
 static void cs35l41_hda_unbind(struct device *dev, struct device *master, void *master_data)
 {
        struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev);
-       struct hda_component *comps = master_data;
+       struct hda_component_parent *parent = master_data;
+       struct hda_component *comp;
        unsigned int sleep_flags;
 
-       if (comps[cs35l41->index].dev == dev) {
-               memset(&comps[cs35l41->index], 0, sizeof(*comps));
+       comp = hda_component_from_index(parent, cs35l41->index);
+       if (!comp)
+               return;
+
+       if (comp->dev == dev) {
                sleep_flags = lock_system_sleep();
                device_link_remove(&cs35l41->codec->core.dev, cs35l41->dev);
                unlock_system_sleep(sleep_flags);
+               memset(comp, 0, sizeof(*comp));
        }
 }
 
index e134ede6c5aa54d98454467222c863005533801c..df4498c77171cca334eed94c503c3964b48d81d8 100644 (file)
@@ -685,20 +685,21 @@ err_pm_put:
 static int cs35l56_hda_bind(struct device *dev, struct device *master, void *master_data)
 {
        struct cs35l56_hda *cs35l56 = dev_get_drvdata(dev);
-       struct hda_component *comps = master_data;
+       struct hda_component_parent *parent = master_data;
+       struct hda_component *comp;
        int ret;
 
-       if (!comps || cs35l56->index < 0 || cs35l56->index >= HDA_MAX_COMPONENTS)
+       comp = hda_component_from_index(parent, cs35l56->index);
+       if (!comp)
                return -EINVAL;
 
-       comps = &comps[cs35l56->index];
-       if (comps->dev)
+       if (comp->dev)
                return -EBUSY;
 
-       comps->dev = dev;
-       cs35l56->codec = comps->codec;
-       strscpy(comps->name, dev_name(dev), sizeof(comps->name));
-       comps->playback_hook = cs35l56_hda_playback_hook;
+       comp->dev = dev;
+       cs35l56->codec = comp->codec;
+       strscpy(comp->name, dev_name(dev), sizeof(comp->name));
+       comp->playback_hook = cs35l56_hda_playback_hook;
 
        ret = cs35l56_hda_fw_load(cs35l56);
        if (ret)
@@ -720,7 +721,8 @@ static int cs35l56_hda_bind(struct device *dev, struct device *master, void *mas
 static void cs35l56_hda_unbind(struct device *dev, struct device *master, void *master_data)
 {
        struct cs35l56_hda *cs35l56 = dev_get_drvdata(dev);
-       struct hda_component *comps = master_data;
+       struct hda_component_parent *parent = master_data;
+       struct hda_component *comp;
 
        cs35l56_hda_remove_controls(cs35l56);
 
@@ -732,8 +734,9 @@ static void cs35l56_hda_unbind(struct device *dev, struct device *master, void *
        if (cs35l56->base.fw_patched)
                cs_dsp_power_down(&cs35l56->cs_dsp);
 
-       if (comps[cs35l56->index].dev == dev)
-               memset(&comps[cs35l56->index], 0, sizeof(*comps));
+       comp = hda_component_from_index(parent, cs35l56->index);
+       if (comp && (comp->dev == dev))
+               memset(comp, 0, sizeof(*comp));
 
        cs35l56->codec = NULL;
 
index b05a0b87d32a31acc11d4ede008e02705288fcd3..8c11c8b37799b2e8bf57931e0436f777b4917c7a 100644 (file)
@@ -141,7 +141,7 @@ int hda_component_manager_bind(struct hda_codec *cdc,
        for (i = 0; i < ARRAY_SIZE(parent->comps); i++)
                parent->comps[i].codec = cdc;
 
-       return component_bind_all(hda_codec_dev(cdc), &parent->comps);
+       return component_bind_all(hda_codec_dev(cdc), parent);
 }
 EXPORT_SYMBOL_NS_GPL(hda_component_manager_bind, SND_HDA_SCODEC_COMPONENT);
 
index a016f1b942a2703259a25fb653ba31a948fd5af1..e547e1f1e6740f85817aa9dc53426be792cb5174 100644 (file)
@@ -93,7 +93,7 @@ static inline struct hda_component *hda_component_from_index(struct hda_componen
 static inline void hda_component_manager_unbind(struct hda_codec *cdc,
                                                struct hda_component_parent *parent)
 {
-       component_unbind_all(hda_codec_dev(cdc), &parent->comps);
+       component_unbind_all(hda_codec_dev(cdc), parent);
 }
 
 #endif /* ifndef __HDA_COMPONENT_H__ */
index fdee6592c502d0528b25c642c7fab37f31decf2d..c6c1e8e819723ad1822c17089dcb6f9b421556ad 100644 (file)
@@ -706,20 +706,20 @@ static int tas2781_hda_bind(struct device *dev, struct device *master,
        void *master_data)
 {
        struct tas2781_hda *tas_hda = dev_get_drvdata(dev);
-       struct hda_component *comps = master_data;
+       struct hda_component_parent *parent = master_data;
+       struct hda_component *comp;
        struct hda_codec *codec;
        unsigned int subid;
        int ret;
 
-       if (!comps || tas_hda->priv->index < 0 ||
-               tas_hda->priv->index >= HDA_MAX_COMPONENTS)
+       comp = hda_component_from_index(parent, tas_hda->priv->index);
+       if (!comp)
                return -EINVAL;
 
-       comps = &comps[tas_hda->priv->index];
-       if (comps->dev)
+       if (comp->dev)
                return -EBUSY;
 
-       codec = comps->codec;
+       codec = comp->codec;
        subid = codec->core.subsystem_id >> 16;
 
        switch (subid) {
@@ -733,13 +733,13 @@ static int tas2781_hda_bind(struct device *dev, struct device *master,
 
        pm_runtime_get_sync(dev);
 
-       comps->dev = dev;
+       comp->dev = dev;
 
-       strscpy(comps->name, dev_name(dev), sizeof(comps->name));
+       strscpy(comp->name, dev_name(dev), sizeof(comp->name));
 
        ret = tascodec_init(tas_hda->priv, codec, THIS_MODULE, tasdev_fw_ready);
        if (!ret)
-               comps->playback_hook = tas2781_hda_playback_hook;
+               comp->playback_hook = tas2781_hda_playback_hook;
 
        pm_runtime_mark_last_busy(dev);
        pm_runtime_put_autosuspend(dev);
@@ -751,13 +751,14 @@ static void tas2781_hda_unbind(struct device *dev,
        struct device *master, void *master_data)
 {
        struct tas2781_hda *tas_hda = dev_get_drvdata(dev);
-       struct hda_component *comps = master_data;
-       comps = &comps[tas_hda->priv->index];
-
-       if (comps->dev == dev) {
-               comps->dev = NULL;
-               memset(comps->name, 0, sizeof(comps->name));
-               comps->playback_hook = NULL;
+       struct hda_component_parent *parent = master_data;
+       struct hda_component *comp;
+
+       comp = hda_component_from_index(parent, tas_hda->priv->index);
+       if (comp && (comp->dev == dev)) {
+               comp->dev = NULL;
+               memset(comp->name, 0, sizeof(comp->name));
+               comp->playback_hook = NULL;
        }
 
        tas2781_hda_remove_controls(tas_hda);