asoc: Add support for sysfs based SSR
Create sysfs node for SSR. Change-Id: Ia181a51ae969632b739676b4b95e2bf0f50ce432
This commit is contained in:

committed by
Gerrit - the friendly Code Review server

parent
1207f8266b
commit
9d0e5be6b5
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2020, The Linux Foundation. All rights reserved.
|
||||
/* Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 and
|
||||
@@ -25,6 +25,11 @@
|
||||
|
||||
#include "msm_common.h"
|
||||
|
||||
struct snd_card_pdata {
|
||||
struct kobject snd_card_kobj;
|
||||
int card_status;
|
||||
}*snd_card_pdata;
|
||||
|
||||
#define to_asoc_mach_common_pdata(kobj) \
|
||||
container_of((kobj), struct msm_common_pdata, aud_dev_kobj)
|
||||
|
||||
@@ -32,12 +37,19 @@
|
||||
#define DEVICE_DISABLE 0
|
||||
|
||||
#define ARRAY_SZ 21
|
||||
#define BUF_SZ 32
|
||||
#define DIR_SZ 10
|
||||
|
||||
static struct attribute device_state_attr = {
|
||||
.name = "state",
|
||||
.mode = 0660,
|
||||
};
|
||||
|
||||
static struct attribute card_state_attr = {
|
||||
.name = "card_state",
|
||||
.mode = 0660,
|
||||
};
|
||||
|
||||
#define MAX_PORT 20
|
||||
#define CODEC_CHMAP "Channel Map"
|
||||
|
||||
@@ -124,6 +136,65 @@ done:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int snd_card_notify_user(int card_status)
|
||||
{
|
||||
snd_card_pdata->card_status = card_status;
|
||||
sysfs_notify(&snd_card_pdata->snd_card_kobj, NULL, "card_state");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t snd_card_sysfs_show(struct kobject *kobj,
|
||||
struct attribute *attr, char *buf)
|
||||
{
|
||||
return snprintf(buf, BUF_SZ, "%d", snd_card_pdata->card_status);
|
||||
}
|
||||
|
||||
static ssize_t snd_card_sysfs_store(struct kobject *kobj,
|
||||
struct attribute *attr, const char *buf, size_t count)
|
||||
{
|
||||
sscanf(buf, "%d", &snd_card_pdata->card_status);
|
||||
sysfs_notify(&snd_card_pdata->snd_card_kobj, NULL, "card_state");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct sysfs_ops snd_card_sysfs_ops = {
|
||||
.show = snd_card_sysfs_show,
|
||||
.store = snd_card_sysfs_store,
|
||||
};
|
||||
|
||||
static struct kobj_type snd_card_ktype = {
|
||||
.sysfs_ops = &snd_card_sysfs_ops,
|
||||
};
|
||||
|
||||
int snd_card_sysfs_init(void)
|
||||
{
|
||||
int ret = 0;
|
||||
char dir[DIR_SZ] = "snd_card";
|
||||
|
||||
snd_card_pdata = kcalloc(1, sizeof(struct snd_card_pdata), GFP_KERNEL);
|
||||
ret = kobject_init_and_add(&snd_card_pdata->snd_card_kobj, &snd_card_ktype,
|
||||
kernel_kobj, dir);
|
||||
if (ret < 0) {
|
||||
pr_err("%s: Failed to add kobject %s, err = %d\n",
|
||||
__func__, dir, ret);
|
||||
goto done;
|
||||
}
|
||||
|
||||
ret = sysfs_create_file(&snd_card_pdata->snd_card_kobj, &card_state_attr);
|
||||
if (ret < 0) {
|
||||
pr_err("%s: Failed to add snd_card sysfs entry to %s\n",
|
||||
__func__, dir);
|
||||
goto fail_create_file;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
fail_create_file:
|
||||
kobject_put(&snd_card_pdata->snd_card_kobj);
|
||||
done:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void check_userspace_service_state(struct snd_soc_pcm_runtime *rtd,
|
||||
struct msm_common_pdata *pdata)
|
||||
{
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2020, The Linux Foundation. All rights reserved.
|
||||
/* Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 and
|
||||
@@ -41,11 +41,14 @@ struct msm_common_pdata {
|
||||
atomic_t mi2s_gpio_ref_cnt[MI2S_TDM_AUXPCM_MAX];
|
||||
};
|
||||
|
||||
int snd_card_notify_user(int card_status);
|
||||
struct msm_common_pdata *msm_common_get_pdata(struct snd_soc_card *card);
|
||||
|
||||
void msm_common_set_pdata(struct snd_soc_card *card,
|
||||
struct msm_common_pdata *pdata);
|
||||
|
||||
int snd_card_sysfs_init(void);
|
||||
|
||||
int msm_common_snd_startup(struct snd_pcm_substream *substream);
|
||||
|
||||
void msm_common_snd_shutdown(struct snd_pcm_substream *substream);
|
||||
|
@@ -1483,9 +1483,7 @@ static int waipio_ssr_enable(struct device *dev, void *data)
|
||||
dev_dbg(dev, "%s: TODO \n", __func__);
|
||||
}
|
||||
|
||||
#if IS_ENABLED(CONFIG_AUDIO_QGKI)
|
||||
snd_soc_card_change_online_state(card, 1);
|
||||
#endif /* CONFIG_AUDIO_QGKI */
|
||||
snd_card_notify_user(1);
|
||||
dev_dbg(dev, "%s: setting snd_card to ONLINE\n", __func__);
|
||||
|
||||
err:
|
||||
@@ -1503,9 +1501,7 @@ static void waipio_ssr_disable(struct device *dev, void *data)
|
||||
}
|
||||
|
||||
dev_dbg(dev, "%s: setting snd_card to OFFLINE\n", __func__);
|
||||
#if IS_ENABLED(CONFIG_AUDIO_QGKI)
|
||||
snd_soc_card_change_online_state(card, 0);
|
||||
#endif /* CONFIG_AUDIO_QGKI */
|
||||
snd_card_notify_user(0);
|
||||
|
||||
if (!strcmp(card->name, "waipio-stub-snd-card")) {
|
||||
/* TODO */
|
||||
@@ -1736,7 +1732,19 @@ static struct platform_driver waipio_asoc_machine_driver = {
|
||||
.probe = msm_asoc_machine_probe,
|
||||
.remove = msm_asoc_machine_remove,
|
||||
};
|
||||
module_platform_driver(waipio_asoc_machine_driver);
|
||||
|
||||
static int __init msm_asoc_machine_init(void)
|
||||
{
|
||||
snd_card_sysfs_init();
|
||||
return platform_driver_register(&waipio_asoc_machine_driver);
|
||||
}
|
||||
module_init(msm_asoc_machine_init);
|
||||
|
||||
static void __exit msm_asoc_machine_exit(void)
|
||||
{
|
||||
platform_driver_unregister(&waipio_asoc_machine_driver);
|
||||
}
|
||||
module_exit(msm_asoc_machine_exit);
|
||||
|
||||
MODULE_SOFTDEP("pre: bt_fm_slim");
|
||||
MODULE_DESCRIPTION("ALSA SoC msm");
|
||||
|
Reference in New Issue
Block a user