Commit 1adf9101 authored by Simon Trimmer's avatar Simon Trimmer Committed by Takashi Iwai

ALSA: hda: hda_component: Change codecs to use component parent structure

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: default avatarSimon Trimmer <simont@opensource.cirrus.com>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/20240617154105.108635-3-simont@opensource.cirrus.com
parent 960ccf6e
...@@ -1419,27 +1419,28 @@ static void cs35l41_acpi_device_notify(acpi_handle handle, u32 event, struct dev ...@@ -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) static int cs35l41_hda_bind(struct device *dev, struct device *master, void *master_data)
{ {
struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev); 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; unsigned int sleep_flags;
int ret = 0; 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; return -EINVAL;
comps = &comps[cs35l41->index]; if (comp->dev)
if (comps->dev)
return -EBUSY; return -EBUSY;
pm_runtime_get_sync(dev); pm_runtime_get_sync(dev);
mutex_lock(&cs35l41->fw_mutex); mutex_lock(&cs35l41->fw_mutex);
comps->dev = dev; comp->dev = dev;
if (!cs35l41->acpi_subsystem_id) if (!cs35l41->acpi_subsystem_id)
cs35l41->acpi_subsystem_id = kasprintf(GFP_KERNEL, "%.8x", cs35l41->acpi_subsystem_id = kasprintf(GFP_KERNEL, "%.8x",
comps->codec->core.subsystem_id); comp->codec->core.subsystem_id);
cs35l41->codec = comps->codec; cs35l41->codec = comp->codec;
strscpy(comps->name, dev_name(dev), sizeof(comps->name)); strscpy(comp->name, dev_name(dev), sizeof(comp->name));
cs35l41->firmware_type = HDA_CS_DSP_FW_SPK_PROT; 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 ...@@ -1454,13 +1455,13 @@ static int cs35l41_hda_bind(struct device *dev, struct device *master, void *mas
ret = cs35l41_create_controls(cs35l41); ret = cs35l41_create_controls(cs35l41);
comps->playback_hook = cs35l41_hda_playback_hook; comp->playback_hook = cs35l41_hda_playback_hook;
comps->pre_playback_hook = cs35l41_hda_pre_playback_hook; comp->pre_playback_hook = cs35l41_hda_pre_playback_hook;
comps->post_playback_hook = cs35l41_hda_post_playback_hook; comp->post_playback_hook = cs35l41_hda_post_playback_hook;
comps->acpi_notify = cs35l41_acpi_device_notify; comp->acpi_notify = cs35l41_acpi_device_notify;
comps->adev = cs35l41->dacpi; 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_DSM_GET_MUTE);
cs35l41->mute_override = cs35l41_get_acpi_mute_state(cs35l41, 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 ...@@ -1469,7 +1470,7 @@ static int cs35l41_hda_bind(struct device *dev, struct device *master, void *mas
mutex_unlock(&cs35l41->fw_mutex); mutex_unlock(&cs35l41->fw_mutex);
sleep_flags = lock_system_sleep(); 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"); dev_warn(dev, "Unable to create device link\n");
unlock_system_sleep(sleep_flags); unlock_system_sleep(sleep_flags);
...@@ -1489,14 +1490,19 @@ static int cs35l41_hda_bind(struct device *dev, struct device *master, void *mas ...@@ -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) static void cs35l41_hda_unbind(struct device *dev, struct device *master, void *master_data)
{ {
struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev); 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; unsigned int sleep_flags;
if (comps[cs35l41->index].dev == dev) { comp = hda_component_from_index(parent, cs35l41->index);
memset(&comps[cs35l41->index], 0, sizeof(*comps)); if (!comp)
return;
if (comp->dev == dev) {
sleep_flags = lock_system_sleep(); sleep_flags = lock_system_sleep();
device_link_remove(&cs35l41->codec->core.dev, cs35l41->dev); device_link_remove(&cs35l41->codec->core.dev, cs35l41->dev);
unlock_system_sleep(sleep_flags); unlock_system_sleep(sleep_flags);
memset(comp, 0, sizeof(*comp));
} }
} }
......
...@@ -685,20 +685,21 @@ static int cs35l56_hda_fw_load(struct cs35l56_hda *cs35l56) ...@@ -685,20 +685,21 @@ static int cs35l56_hda_fw_load(struct cs35l56_hda *cs35l56)
static int cs35l56_hda_bind(struct device *dev, struct device *master, void *master_data) static int cs35l56_hda_bind(struct device *dev, struct device *master, void *master_data)
{ {
struct cs35l56_hda *cs35l56 = dev_get_drvdata(dev); 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; int ret;
if (!comps || cs35l56->index < 0 || cs35l56->index >= HDA_MAX_COMPONENTS) comp = hda_component_from_index(parent, cs35l56->index);
if (!comp)
return -EINVAL; return -EINVAL;
comps = &comps[cs35l56->index]; if (comp->dev)
if (comps->dev)
return -EBUSY; return -EBUSY;
comps->dev = dev; comp->dev = dev;
cs35l56->codec = comps->codec; cs35l56->codec = comp->codec;
strscpy(comps->name, dev_name(dev), sizeof(comps->name)); strscpy(comp->name, dev_name(dev), sizeof(comp->name));
comps->playback_hook = cs35l56_hda_playback_hook; comp->playback_hook = cs35l56_hda_playback_hook;
ret = cs35l56_hda_fw_load(cs35l56); ret = cs35l56_hda_fw_load(cs35l56);
if (ret) if (ret)
...@@ -720,7 +721,8 @@ static int cs35l56_hda_bind(struct device *dev, struct device *master, void *mas ...@@ -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) static void cs35l56_hda_unbind(struct device *dev, struct device *master, void *master_data)
{ {
struct cs35l56_hda *cs35l56 = dev_get_drvdata(dev); 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); cs35l56_hda_remove_controls(cs35l56);
...@@ -732,8 +734,9 @@ static void cs35l56_hda_unbind(struct device *dev, struct device *master, void * ...@@ -732,8 +734,9 @@ static void cs35l56_hda_unbind(struct device *dev, struct device *master, void *
if (cs35l56->base.fw_patched) if (cs35l56->base.fw_patched)
cs_dsp_power_down(&cs35l56->cs_dsp); cs_dsp_power_down(&cs35l56->cs_dsp);
if (comps[cs35l56->index].dev == dev) comp = hda_component_from_index(parent, cs35l56->index);
memset(&comps[cs35l56->index], 0, sizeof(*comps)); if (comp && (comp->dev == dev))
memset(comp, 0, sizeof(*comp));
cs35l56->codec = NULL; cs35l56->codec = NULL;
......
...@@ -141,7 +141,7 @@ int hda_component_manager_bind(struct hda_codec *cdc, ...@@ -141,7 +141,7 @@ int hda_component_manager_bind(struct hda_codec *cdc,
for (i = 0; i < ARRAY_SIZE(parent->comps); i++) for (i = 0; i < ARRAY_SIZE(parent->comps); i++)
parent->comps[i].codec = cdc; 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); EXPORT_SYMBOL_NS_GPL(hda_component_manager_bind, SND_HDA_SCODEC_COMPONENT);
......
...@@ -93,7 +93,7 @@ static inline struct hda_component *hda_component_from_index(struct hda_componen ...@@ -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, static inline void hda_component_manager_unbind(struct hda_codec *cdc,
struct hda_component_parent *parent) 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__ */ #endif /* ifndef __HDA_COMPONENT_H__ */
...@@ -706,20 +706,20 @@ static int tas2781_hda_bind(struct device *dev, struct device *master, ...@@ -706,20 +706,20 @@ static int tas2781_hda_bind(struct device *dev, struct device *master,
void *master_data) void *master_data)
{ {
struct tas2781_hda *tas_hda = dev_get_drvdata(dev); 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; struct hda_codec *codec;
unsigned int subid; unsigned int subid;
int ret; int ret;
if (!comps || tas_hda->priv->index < 0 || comp = hda_component_from_index(parent, tas_hda->priv->index);
tas_hda->priv->index >= HDA_MAX_COMPONENTS) if (!comp)
return -EINVAL; return -EINVAL;
comps = &comps[tas_hda->priv->index]; if (comp->dev)
if (comps->dev)
return -EBUSY; return -EBUSY;
codec = comps->codec; codec = comp->codec;
subid = codec->core.subsystem_id >> 16; subid = codec->core.subsystem_id >> 16;
switch (subid) { switch (subid) {
...@@ -733,13 +733,13 @@ static int tas2781_hda_bind(struct device *dev, struct device *master, ...@@ -733,13 +733,13 @@ static int tas2781_hda_bind(struct device *dev, struct device *master,
pm_runtime_get_sync(dev); 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); ret = tascodec_init(tas_hda->priv, codec, THIS_MODULE, tasdev_fw_ready);
if (!ret) if (!ret)
comps->playback_hook = tas2781_hda_playback_hook; comp->playback_hook = tas2781_hda_playback_hook;
pm_runtime_mark_last_busy(dev); pm_runtime_mark_last_busy(dev);
pm_runtime_put_autosuspend(dev); pm_runtime_put_autosuspend(dev);
...@@ -751,13 +751,14 @@ static void tas2781_hda_unbind(struct device *dev, ...@@ -751,13 +751,14 @@ static void tas2781_hda_unbind(struct device *dev,
struct device *master, void *master_data) struct device *master, void *master_data)
{ {
struct tas2781_hda *tas_hda = dev_get_drvdata(dev); struct tas2781_hda *tas_hda = dev_get_drvdata(dev);
struct hda_component *comps = master_data; struct hda_component_parent *parent = master_data;
comps = &comps[tas_hda->priv->index]; struct hda_component *comp;
if (comps->dev == dev) { comp = hda_component_from_index(parent, tas_hda->priv->index);
comps->dev = NULL; if (comp && (comp->dev == dev)) {
memset(comps->name, 0, sizeof(comps->name)); comp->dev = NULL;
comps->playback_hook = NULL; memset(comp->name, 0, sizeof(comp->name));
comp->playback_hook = NULL;
} }
tas2781_hda_remove_controls(tas_hda); tas2781_hda_remove_controls(tas_hda);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment