Commit 796fad44 authored by Vaibhav Agarwal's avatar Vaibhav Agarwal Committed by Greg Kroah-Hartman

greybus: audio: codec driver cleanup

audio codec driver is now moved to bundle driver approach.
This resolved many race conditions related to audio mgmt &
data connection init/exit sequence.
Thus, a lot of helper functions can now be safely removed.
Signed-off-by: default avatarVaibhav Agarwal <vaibhav.agarwal@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@google.com>
parent 127c1fbd
This diff is collapsed.
...@@ -84,6 +84,8 @@ struct gbaudio_control { ...@@ -84,6 +84,8 @@ struct gbaudio_control {
struct gbaudio_dai { struct gbaudio_dai {
__le16 data_cport; __le16 data_cport;
char name[NAME_SIZE]; char name[NAME_SIZE];
/* DAI users */
atomic_t users;
struct gb_connection *connection; struct gb_connection *connection;
struct list_head list; struct list_head list;
}; };
...@@ -116,8 +118,9 @@ struct gbaudio_codec_info { ...@@ -116,8 +118,9 @@ struct gbaudio_codec_info {
char *dailink_name[MAX_DAIS]; char *dailink_name[MAX_DAIS];
int num_dai_links; int num_dai_links;
/* topology related */
struct gb_connection *mgmt_connection; struct gb_connection *mgmt_connection;
size_t num_data_connections;
/* topology related */
int num_dais; int num_dais;
int num_kcontrols; int num_kcontrols;
int num_dapm_widgets; int num_dapm_widgets;
...@@ -131,9 +134,6 @@ struct gbaudio_codec_info { ...@@ -131,9 +134,6 @@ struct gbaudio_codec_info {
struct snd_soc_dapm_route *routes; struct snd_soc_dapm_route *routes;
struct snd_soc_dai_driver *dais; struct snd_soc_dai_driver *dais;
/* codec users */
atomic_t users;
/* lists */ /* lists */
struct list_head dai_list; struct list_head dai_list;
struct list_head widget_list; struct list_head widget_list;
...@@ -142,17 +142,8 @@ struct gbaudio_codec_info { ...@@ -142,17 +142,8 @@ struct gbaudio_codec_info {
struct mutex lock; struct mutex lock;
}; };
struct gb_audio { struct gbaudio_dai *gbaudio_find_dai(struct gbaudio_codec_info *gbcodec,
struct gb_connection *mgmt_connection; int data_cport, const char *name);
size_t num_data_connections;
struct gbaudio_codec_info *gbcodec;
struct gb_connection *data_connection[0];
};
struct gbaudio_dai *gbaudio_add_dai(struct gbaudio_codec_info *gbcodec,
int data_cport,
struct gb_connection *connection,
const char *name);
int gbaudio_tplg_parse_data(struct gbaudio_codec_info *gbcodec, int gbaudio_tplg_parse_data(struct gbaudio_codec_info *gbcodec,
struct gb_audio_topology *tplg_data); struct gb_audio_topology *tplg_data);
void gbaudio_tplg_release(struct gbaudio_codec_info *gbcodec); void gbaudio_tplg_release(struct gbaudio_codec_info *gbcodec);
......
...@@ -92,8 +92,7 @@ static int gbcodec_mixer_ctl_info(struct snd_kcontrol *kcontrol, ...@@ -92,8 +92,7 @@ static int gbcodec_mixer_ctl_info(struct snd_kcontrol *kcontrol,
struct gbaudio_ctl_pvt *data; struct gbaudio_ctl_pvt *data;
struct gb_audio_ctl_elem_info *info; struct gb_audio_ctl_elem_info *info;
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
struct gb_audio *audio = snd_soc_codec_get_drvdata(codec); struct gbaudio_codec_info *gbcodec = snd_soc_codec_get_drvdata(codec);
struct gbaudio_codec_info *gbcodec = audio->gbcodec;
data = (struct gbaudio_ctl_pvt *)kcontrol->private_value; data = (struct gbaudio_ctl_pvt *)kcontrol->private_value;
info = (struct gb_audio_ctl_elem_info *)data->info; info = (struct gb_audio_ctl_elem_info *)data->info;
...@@ -139,8 +138,7 @@ static int gbcodec_mixer_ctl_get(struct snd_kcontrol *kcontrol, ...@@ -139,8 +138,7 @@ static int gbcodec_mixer_ctl_get(struct snd_kcontrol *kcontrol,
struct gbaudio_ctl_pvt *data; struct gbaudio_ctl_pvt *data;
struct gb_audio_ctl_elem_value gbvalue; struct gb_audio_ctl_elem_value gbvalue;
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
struct gb_audio *audio = snd_soc_codec_get_drvdata(codec); struct gbaudio_codec_info *gb = snd_soc_codec_get_drvdata(codec);
struct gbaudio_codec_info *gb = audio->gbcodec;
data = (struct gbaudio_ctl_pvt *)kcontrol->private_value; data = (struct gbaudio_ctl_pvt *)kcontrol->private_value;
info = (struct gb_audio_ctl_elem_info *)data->info; info = (struct gb_audio_ctl_elem_info *)data->info;
...@@ -187,8 +185,7 @@ static int gbcodec_mixer_ctl_put(struct snd_kcontrol *kcontrol, ...@@ -187,8 +185,7 @@ static int gbcodec_mixer_ctl_put(struct snd_kcontrol *kcontrol,
struct gbaudio_ctl_pvt *data; struct gbaudio_ctl_pvt *data;
struct gb_audio_ctl_elem_value gbvalue; struct gb_audio_ctl_elem_value gbvalue;
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
struct gb_audio *audio = snd_soc_codec_get_drvdata(codec); struct gbaudio_codec_info *gb = snd_soc_codec_get_drvdata(codec);
struct gbaudio_codec_info *gb = audio->gbcodec;
data = (struct gbaudio_ctl_pvt *)kcontrol->private_value; data = (struct gbaudio_ctl_pvt *)kcontrol->private_value;
info = (struct gb_audio_ctl_elem_info *)data->info; info = (struct gb_audio_ctl_elem_info *)data->info;
...@@ -282,8 +279,7 @@ static int gbcodec_mixer_dapm_ctl_get(struct snd_kcontrol *kcontrol, ...@@ -282,8 +279,7 @@ static int gbcodec_mixer_dapm_ctl_get(struct snd_kcontrol *kcontrol,
struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
struct snd_soc_dapm_widget *widget = wlist->widgets[0]; struct snd_soc_dapm_widget *widget = wlist->widgets[0];
struct snd_soc_codec *codec = widget->codec; struct snd_soc_codec *codec = widget->codec;
struct gb_audio *audio = snd_soc_codec_get_drvdata(codec); struct gbaudio_codec_info *gb = snd_soc_codec_get_drvdata(codec);
struct gbaudio_codec_info *gb = audio->gbcodec;
data = (struct gbaudio_ctl_pvt *)kcontrol->private_value; data = (struct gbaudio_ctl_pvt *)kcontrol->private_value;
info = (struct gb_audio_ctl_elem_info *)data->info; info = (struct gb_audio_ctl_elem_info *)data->info;
...@@ -317,8 +313,7 @@ static int gbcodec_mixer_dapm_ctl_put(struct snd_kcontrol *kcontrol, ...@@ -317,8 +313,7 @@ static int gbcodec_mixer_dapm_ctl_put(struct snd_kcontrol *kcontrol,
struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
struct snd_soc_dapm_widget *widget = wlist->widgets[0]; struct snd_soc_dapm_widget *widget = wlist->widgets[0];
struct snd_soc_codec *codec = widget->codec; struct snd_soc_codec *codec = widget->codec;
struct gb_audio *audio = snd_soc_codec_get_drvdata(codec); struct gbaudio_codec_info *gb = snd_soc_codec_get_drvdata(codec);
struct gbaudio_codec_info *gb = audio->gbcodec;
data = (struct gbaudio_ctl_pvt *)kcontrol->private_value; data = (struct gbaudio_ctl_pvt *)kcontrol->private_value;
info = (struct gb_audio_ctl_elem_info *)data->info; info = (struct gb_audio_ctl_elem_info *)data->info;
...@@ -524,8 +519,7 @@ static int gbaudio_widget_event(struct snd_soc_dapm_widget *w, ...@@ -524,8 +519,7 @@ static int gbaudio_widget_event(struct snd_soc_dapm_widget *w,
int wid; int wid;
int ret; int ret;
struct snd_soc_codec *codec = w->codec; struct snd_soc_codec *codec = w->codec;
struct gb_audio *audio = snd_soc_codec_get_drvdata(codec); struct gbaudio_codec_info *gbcodec = snd_soc_codec_get_drvdata(codec);
struct gbaudio_codec_info *gbcodec = audio->gbcodec;
dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event); dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
...@@ -819,9 +813,9 @@ static int gbaudio_tplg_process_dais(struct gbaudio_codec_info *gbcodec, ...@@ -819,9 +813,9 @@ static int gbaudio_tplg_process_dais(struct gbaudio_codec_info *gbcodec,
int i, ret; int i, ret;
struct snd_soc_dai_driver *gb_dais; struct snd_soc_dai_driver *gb_dais;
struct gb_audio_dai *curr; struct gb_audio_dai *curr;
struct gbaudio_dai *dai, *_dai;
size_t size; size_t size;
char dai_name[NAME_SIZE]; char dai_name[NAME_SIZE];
struct gbaudio_dai *dai;
size = sizeof(struct snd_soc_dai_driver) * gbcodec->num_dais; size = sizeof(struct snd_soc_dai_driver) * gbcodec->num_dais;
gb_dais = devm_kzalloc(gbcodec->dev, size, GFP_KERNEL); gb_dais = devm_kzalloc(gbcodec->dev, size, GFP_KERNEL);
...@@ -839,10 +833,10 @@ static int gbaudio_tplg_process_dais(struct gbaudio_codec_info *gbcodec, ...@@ -839,10 +833,10 @@ static int gbaudio_tplg_process_dais(struct gbaudio_codec_info *gbcodec,
/* append dev_id to dai_name */ /* append dev_id to dai_name */
snprintf(dai_name, NAME_SIZE, "%s.%d", curr->name, snprintf(dai_name, NAME_SIZE, "%s.%d", curr->name,
gbcodec->dev_id); gbcodec->dev_id);
dai = gbaudio_add_dai(gbcodec, curr->data_cport, NULL, dai = gbaudio_find_dai(gbcodec, curr->data_cport, NULL);
dai_name);
if (!dai) if (!dai)
goto error; goto error;
strlcpy(dai->name, dai_name, NAME_SIZE);
dev_dbg(gbcodec->dev, "%s:DAI added\n", dai->name); dev_dbg(gbcodec->dev, "%s:DAI added\n", dai->name);
gb_dais[i].name = dai->name; gb_dais[i].name = dai->name;
curr++; curr++;
...@@ -852,10 +846,6 @@ static int gbaudio_tplg_process_dais(struct gbaudio_codec_info *gbcodec, ...@@ -852,10 +846,6 @@ static int gbaudio_tplg_process_dais(struct gbaudio_codec_info *gbcodec,
return 0; return 0;
error: error:
list_for_each_entry_safe(dai, _dai, &gbcodec->dai_list, list) {
list_del(&dai->list);
devm_kfree(gbcodec->dev, dai);
}
devm_kfree(gbcodec->dev, gb_dais); devm_kfree(gbcodec->dev, gb_dais);
return ret; return ret;
} }
...@@ -948,68 +938,6 @@ static int gbaudio_tplg_process_header(struct gbaudio_codec_info *gbcodec, ...@@ -948,68 +938,6 @@ static int gbaudio_tplg_process_header(struct gbaudio_codec_info *gbcodec,
return 0; return 0;
} }
static struct gbaudio_dai *gbaudio_allocate_dai(struct gbaudio_codec_info *gb,
int data_cport,
struct gb_connection *connection,
const char *name)
{
struct gbaudio_dai *dai;
mutex_lock(&gb->lock);
dai = devm_kzalloc(gb->dev, sizeof(*dai), GFP_KERNEL);
if (!dai) {
dev_err(gb->dev, "%s:DAI Malloc failure\n", name);
mutex_unlock(&gb->lock);
return NULL;
}
dai->data_cport = data_cport;
dai->connection = connection;
/* update name */
if (name)
strlcpy(dai->name, name, NAME_SIZE);
list_add(&dai->list, &gb->dai_list);
dev_dbg(gb->dev, "%d:%s: DAI added\n", data_cport, dai->name);
mutex_unlock(&gb->lock);
return dai;
}
struct gbaudio_dai *gbaudio_add_dai(struct gbaudio_codec_info *gbcodec,
int data_cport,
struct gb_connection *connection,
const char *name)
{
struct gbaudio_dai *dai, *_dai;
/* FIXME need to take care for multiple DAIs */
mutex_lock(&gbcodec->lock);
if (list_empty(&gbcodec->dai_list)) {
mutex_unlock(&gbcodec->lock);
return gbaudio_allocate_dai(gbcodec, data_cport, connection,
name);
}
list_for_each_entry_safe(dai, _dai, &gbcodec->dai_list, list) {
if (dai->data_cport == data_cport) {
if (connection)
dai->connection = connection;
if (name)
strlcpy(dai->name, name, NAME_SIZE);
dev_dbg(gbcodec->dev, "%d:%s: DAI updated\n",
data_cport, dai->name);
mutex_unlock(&gbcodec->lock);
return dai;
}
}
dev_err(gbcodec->dev, "%s:DAI not found\n", name);
mutex_unlock(&gbcodec->lock);
return NULL;
}
int gbaudio_tplg_parse_data(struct gbaudio_codec_info *gbcodec, int gbaudio_tplg_parse_data(struct gbaudio_codec_info *gbcodec,
struct gb_audio_topology *tplg_data) struct gb_audio_topology *tplg_data)
{ {
...@@ -1074,7 +1002,6 @@ int gbaudio_tplg_parse_data(struct gbaudio_codec_info *gbcodec, ...@@ -1074,7 +1002,6 @@ int gbaudio_tplg_parse_data(struct gbaudio_codec_info *gbcodec,
void gbaudio_tplg_release(struct gbaudio_codec_info *gbcodec) void gbaudio_tplg_release(struct gbaudio_codec_info *gbcodec)
{ {
struct gbaudio_dai *dai, *_dai;
struct gbaudio_control *control, *_control; struct gbaudio_control *control, *_control;
struct gbaudio_widget *widget, *_widget; struct gbaudio_widget *widget, *_widget;
...@@ -1109,12 +1036,4 @@ void gbaudio_tplg_release(struct gbaudio_codec_info *gbcodec) ...@@ -1109,12 +1036,4 @@ void gbaudio_tplg_release(struct gbaudio_codec_info *gbcodec)
/* release routes */ /* release routes */
if (gbcodec->routes) if (gbcodec->routes)
devm_kfree(gbcodec->dev, gbcodec->routes); devm_kfree(gbcodec->dev, gbcodec->routes);
/* release DAIs */
mutex_lock(&gbcodec->lock);
list_for_each_entry_safe(dai, _dai, &gbcodec->dai_list, list) {
list_del(&dai->list);
devm_kfree(gbcodec->dev, dai);
}
mutex_unlock(&gbcodec->lock);
} }
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