ASoC: add a core API to share more product information with user space
Subsystems (3)
PATCH v2 1/1 ASoC: add a core API to share more product information with user space
From: "Lu, Han" <[email protected]>
Add a core API to share more machine/board information, for user space apps such as PA and UCM to distinguish various products. Previously on ASoC, the card short name, driver name and long name are all the same as the machine driver name.
For example, on T100TA:
$ cat /proc/asound/cards
0 [bytcr-rt5640]: bytcr-rt5640 - bytcr-rt5640
bytcr-rt5640The patch adds more board information:
card driver name ---> machine driver name
card short name ---> DMI_PRODUCT_NAME or DMI_BOARD_NAME card long name and
card component ---> short name:driver name(:DMI_SYS_VENDOR if
available)(:firmware name if available)
For example, on T100TA:
$ cat /proc/asound/cards
0 [T100TA ]: bytcr-rt5640 - T100TA
T100TA:bytcr-rt5640:ASUSTek COMPUTER INC.:intel/fw_
sst_0f28.bin
$ amixer -c0 info
Card hw:0 'T100TA'/'T100TA:bytcr-rt5640:ASUSTek COMPUTER INC.:intel/fw_
sst_0f28.bin'
Mixer name : ''
Components : 'T100TA:bytcr-rt5640:ASUSTek COMPUTER INC.:intel/fw_s
st_0f28.bin'
Controls : 256
Simple ctrls : 228include/sound/soc.h +3 -0
@@ -486,6 +486,9 @@ void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream);int snd_soc_runtime_set_dai_fmt (struct snd_soc_pcm_runtime *rtd,unsigned int dai_fmt); +int snd_soc_set_card_names (struct snd_soc_card *card,const char *board, +const char *vendor,const char *firmware); +/* Utility functions to get clock rates from various things */ int snd_soc_calc_frame_size (int sample_size,int channels,int tdm_slots);int snd_soc_params_to_frame_size (struct snd_pcm_hw_params *params);
sound/soc/intel/boards/bytcr_rt5640.c +15 -0
@@ -152,6 +152,8 @@ static const struct dmi_system_id byt_rt5640_quirk_table[] = { {} }; +static struct snd_soc_card byt_rt5640_card; +static int byt_rt5640_init (struct snd_soc_pcm_runtime *runtime) {int ret;
@@ -159,6 +161,19 @@ static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)struct snd_soc_card *card = runtime->card;const struct snd_soc_dapm_route *custom_map;int num_routes; +const char *board, *vendor; +struct sst_acpi_mach *mach = byt_rt5640_card.dev->platform_data; + +/* Add machine/board information for userspace */ + board =dmi_get_system_info (DMI_PRODUCT_NAME ); +if (!board) + board =dmi_get_system_info (DMI_BOARD_NAME ); + vendor =dmi_get_system_info (DMI_SYS_VENDOR ); + ret =snd_soc_set_card_names (card, board, vendor, mach->fw_filename); +if (ret <0 ) { +dev_err (card->dev,"unable to set card names\n" ); +return ret; + } card->dapm.idle_bias_off = true;
sound/soc/soc-core.c +52 -0
58 lines not on this page · raw message
Signature · 1 line
2.5.0
Liam Girdwood
maintainerQuoted 2 lines · On Wed, 2016-03-30 at 16:52 +0800, [email protected] wrote:
From: "Lu, Han" <[email protected]>
Best to write $SUBJECT as ASoC: core: Add API for registering DMI card names.
Quoted 50 lines
Add a core API to share more machine/board information, for user space apps such as PA and UCM to distinguish various products. Previously on ASoC, the card short name, driver name and long name are all the same as the machine driver name.
For example, on T100TA:$ cat /proc/asound/cards 0 [bytcr-rt5640]: bytcr-rt5640 - bytcr-rt5640 bytcr-rt5640The patch adds more board information:
card driver name ---> machine driver name
card short name --->DMI_PRODUCT_NAMEorDMI_BOARD_NAMEcard long name and
card component ---> short name:driver name(:DMI_SYS_VENDOR if
available)(:firmware name if available)
For example, on T100TA:$ cat /proc/asound/cards 0 [T100TA ]: bytcr-rt5640 - T100TA T100TA:bytcr-rt5640:ASUSTek COMPUTER INC.:intel/fw_ sst_0f28.bin $ amixer -c0 info Card hw:0 'T100TA'/'T100TA:bytcr-rt5640:ASUSTek COMPUTER INC.:intel/fw_ sst_0f28.bin' Mixer name : '' Components : 'T100TA:bytcr-rt5640:ASUSTek COMPUTER INC.:intel/fw_s st_0f28.bin' Controls : 256 Simple ctrls : 228Signed-off-by Lu, Han <[email protected]>include/sound/soc.h +3
-0@@ -486,6 +486,9 @@ void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream);int snd_soc_runtime_set_dai_fmt (struct snd_soc_pcm_runtime *rtd,unsigned int dai_fmt); +int snd_soc_set_card_names (struct snd_soc_card *card,const char *board, +const char *vendor,const char *firmware); +/* Utility functions to get clock rates from various things */ int snd_soc_calc_frame_size (int sample_size,int channels,int tdm_slots);int snd_soc_params_to_frame_size (struct snd_pcm_hw_params *params);sound/soc/intel/boards/bytcr_rt5640.c +0
-0
sound/soc/intel/boards/bytcr_rt5640.c static const struct dmi_system_id byt_rt5640_quirk_table[] = { · line 154
Quoted 3 lines
sound/soc/intel/boards/bytcr_rt5640.c +0
-0@@ -152,6 +152,8 @@ static const struct dmi_system_id byt_rt5640_quirk_table[] = { {} };
The usage of the new API call in the bytcr_rt5640 should be a separate follow up patch.
Quoted 50 lines
sound/soc/intel/boards/bytcr_rt5640.c +15
-0+static struct snd_soc_card byt_rt5640_card; +static int byt_rt5640_init (struct snd_soc_pcm_runtime *runtime) {int ret;@@ -159,6 +161,19 @@ static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)struct snd_soc_card *card = runtime->card;const struct snd_soc_dapm_route *custom_map;int num_routes; +const char *board, *vendor; +struct sst_acpi_mach *mach = byt_rt5640_card.dev->platform_data; + +/* Add machine/board information for userspace */ + board =dmi_get_system_info (DMI_PRODUCT_NAME ); +if (!board) + board =dmi_get_system_info (DMI_BOARD_NAME ); + vendor =dmi_get_system_info (DMI_SYS_VENDOR ); + ret =snd_soc_set_card_names (card, board, vendor, mach->fw_filename); +if (ret <0 ) { +dev_err (card->dev,"unable to set card names\n" ); +return ret; + } card->dapm.idle_bias_off = true;sound/soc/soc-core.c +17
-0@@ -1828,6 +1828,58 @@ int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd, }EXPORT_SYMBOL_GPL (snd_soc_runtime_set_dai_fmt); +/** +* snd_soc_set_card_names() - Set the shortname/drivername/longname/component +* of a ASoC card. +* @card: The card to set names +* @board: The board name or product name +* @vendor: The vendor name +* @firmware: The firmware name +* +* This function adds more information for the userspace to distinguish +* different products: +* card driver name ---> machine driver name +* card short name ---> DMI_PRODUCT_NAME or DMI_BOARD_NAME +* card long name and +* card component ---> short name:driver name(:DMI_SYS_VENDOR) +* (:firmware name) +* +* Returns 0 on success, otherwise a negative error code.
sound/soc/soc-core.c int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd, · line 1857
Quoted 10 lines
sound/soc/soc-core.c +10
-0+*/ +int snd_soc_set_card_names (struct snd_soc_card *card,const char *board, +const char *vendor,const char *firmware) +{ +int ret =0 ; +char *name; + +if (!board) { +dev_err (card->dev,"ASoC: the board/product name is empty!\n" ); +return -1 ;
return -EINVAL;
sound/soc/soc-core.c int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd, · line 1858
Quoted 1 line
sound/soc/soc-core.c +1
-0+ }
newline ?
Quoted 17 lines
sound/soc/soc-core.c +17
-0+/* card driver name */ + card->driver_name = card->name; +/* card short name */ + card->name = board; +/* card long name / card component */ + name =kstrdup (card->name,GFP_KERNEL ); +if (!name) +return -ENOMEM ; +strcat (name,":" ); +strcat (name, card->driver_name); +strcat (name,":" ); +if (vendor) +strcat (name, vendor); +strcat (name,":" ); +if (firmware) +strcat (name, firmware); + ret =snd_component_add (card->snd_card, name);
sound/soc/soc-core.c int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd, · line 1885
Quoted 10 lines
sound/soc/soc-core.c +7
-0+ card->long_name = card->snd_card->components; + +kfree (name); +return ret; +} +EXPORT_SYMBOL_GPL (snd_soc_set_card_names); +static int snd_soc_instantiate_card (struct snd_soc_card *card) {struct snd_soc_codec *codec;
Liam
sound/soc/soc-core.c int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd, · line 1874
Quoted 13 lines · On Wed, 30 Mar 2016 10:52:32 +0200, [email protected] wrote:
sound/soc/soc-core.c +12
-0+/* card long name / card component */ + name =kstrdup (card->name,GFP_KERNEL ); +if (!name) +return -ENOMEM ; +strcat (name,":" ); +strcat (name, card->driver_name); +strcat (name,":" ); +if (vendor) +strcat (name, vendor); +strcat (name,":" ); +if (firmware) +strcat (name, firmware);
strcat() can't be used in that way. You'd need to allocate an enough large string buffer, and use strlcat() to fill in.
Also, ideally check whether each name string has no colon letter included. Otherwise it'll confuse the parser in user space.
thanks,
Takashi