From patchwork Tue Nov 15 08:02:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mengdong.lin@linux.intel.com X-Patchwork-Id: 9429935 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2279360484 for ; Tue, 15 Nov 2016 14:46:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F10028B73 for ; Tue, 15 Nov 2016 14:46:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0298E28BBA; Tue, 15 Nov 2016 14:46:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 06E4528B73 for ; Tue, 15 Nov 2016 14:46:40 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 416D426716F; Tue, 15 Nov 2016 15:46:39 +0100 (CET) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id EC086267168; Tue, 15 Nov 2016 15:44:16 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 2E5B026701D; Tue, 15 Nov 2016 09:00:38 +0100 (CET) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by alsa0.perex.cz (Postfix) with ESMTP id DD5E8266FF6 for ; Tue, 15 Nov 2016 09:00:31 +0100 (CET) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga101.fm.intel.com with ESMTP; 15 Nov 2016 00:00:30 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,641,1473145200"; d="scan'208";a="31435552" Received: from amanda-haswell-pc.sh.intel.com ([10.239.159.21]) by fmsmga005.fm.intel.com with ESMTP; 15 Nov 2016 00:00:28 -0800 From: mengdong.lin@linux.intel.com To: alsa-devel@alsa-project.org Date: Tue, 15 Nov 2016 16:02:16 +0800 Message-Id: <9baaf7a3d55a86e417826715e8e63d1a76582156.1479195801.git.mengdong.lin@linux.intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: References: Cc: Mengdong Lin , tiwai@suse.de, mengdong.lin@intel.com, liam.r.girdwood@linux.intel.com, vinod.koul@intel.com, broonie@kernel.org Subject: [alsa-devel] [RFC PATCH 2/3] ucm: Parse sequence of component devices X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP From: Mengdong Lin A machine device's verb file (e.g.HiFi) can include configuration files of component devices via alsaconf syntax and . Then the machine device's sequence can enable or disable a component device by keyword 'enadev' and 'disdev' followed the name of the component device. UCM sequence parser will find the component device and mark if its enable or disable sequence is needed by the parent, the machine device. New element type and struct are defined for the sequence of a component device. Component devices will be removed from the machine device list 'device_list' of a verb, since we don't want to expose them to audio servers with original API to list devices for backward compatibility. A new list 'cmpt_device_list' is used for the component devices of a verb. Signed-off-by: Mengdong Lin diff --git a/src/ucm/parser.c b/src/ucm/parser.c index 5fc98a1..fe1dfbc 100644 --- a/src/ucm/parser.c +++ b/src/ucm/parser.c @@ -235,6 +235,81 @@ static int parse_device_list(snd_use_case_mgr_t *uc_mgr ATTRIBUTE_UNUSED, return 0; } +/* find a component device by its name + * + * Component devices are defined by machine components (usually off-soc + * codes or DSP embeded in SoC). Since alsaconf imports their configuration + * files automatically, we don't know which devices are component devices + * until they are referenced by a machine device sequence. So here when we + * find a referenced device, we move it from the machine device list to the + * component device list. Component devices will not be exposed to applications + * by the original API to list devices for backward compatibility. So audio + * servers can only see the machine devices. + */ +struct use_case_device *find_component_dev(snd_use_case_mgr_t *uc_mgr, + const char *name) +{ + struct list_head *pos, *posdev, *_posdev; + struct use_case_verb *verb; + struct use_case_device *dev; + + list_for_each(pos, &uc_mgr->verb_list) { + verb = list_entry(pos, struct use_case_verb, list); + + /* search in the component device list */ + list_for_each(posdev, &verb->cmpt_device_list) { + dev = list_entry(posdev, struct use_case_device, list); + if (!strcmp(dev->name, name)) + return dev; + } + + /* search the machine device list */ + list_for_each_safe(posdev, _posdev, &verb->device_list) { + dev = list_entry(posdev, struct use_case_device, list); + if (!strcmp(dev->name, name)) { + /* find the component device, move it from the + * machine device list to the component device + * list. + */ + list_del(&dev->list); + list_add_tail(&dev->list, + &verb->cmpt_device_list); + return dev; + } + } + } + + return NULL; +} + +/* parse sequence of a component device + * + * This function will find the component device and mark if its enable or + * disable sequence is needed by its parenet device. + */ +static int parse_component_seq(snd_use_case_mgr_t *uc_mgr, + snd_config_t *n, int enable, + struct component_sequence *cmpt_seq) +{ + const char *val; + int err; + + err = snd_config_get_string(n, &val); + if (err < 0) + return err; + + cmpt_seq->device = find_component_dev(uc_mgr, val); + if (!cmpt_seq->device) { + uc_error("error: Cannot find component device %s", val); + return -EINVAL; + } + + /* Parent needs its enable or disable sequence */ + cmpt_seq->enable = enable; + + return 0; +} + /* * Parse sequences. * @@ -249,7 +324,7 @@ static int parse_device_list(snd_use_case_mgr_t *uc_mgr ATTRIBUTE_UNUSED, * cset "name='Master Playback Switch' 0,0" * cset "iface=PCM,name='Disable HDMI',index=1 0" */ -static int parse_sequence(snd_use_case_mgr_t *uc_mgr ATTRIBUTE_UNUSED, +static int parse_sequence(snd_use_case_mgr_t *uc_mgr, struct list_head *base, snd_config_t *cfg) { @@ -306,6 +381,30 @@ static int parse_sequence(snd_use_case_mgr_t *uc_mgr ATTRIBUTE_UNUSED, continue; } + if (strcmp(cmd, "enadev") == 0) { + /* need to enable a component device */ + curr->type = SEQUENCE_ELEMENT_TYPE_CMPT_SEQ; + err = parse_component_seq(uc_mgr, n, 1, + &curr->data.cmpt_seq); + if (err < 0) { + uc_error("error: enadev requires a valid device!"); + return err; + } + continue; + } + + if (strcmp(cmd, "disdev") == 0) { + /* need to disable a component device */ + curr->type = SEQUENCE_ELEMENT_TYPE_CMPT_SEQ; + err = parse_component_seq(uc_mgr, n, 0, + &curr->data.cmpt_seq); + if (err < 0) { + uc_error("error: disdev requires a valid device!"); + return err; + } + continue; + } + if (strcmp(cmd, "cset-bin-file") == 0) { curr->type = SEQUENCE_ELEMENT_TYPE_CSET_BIN_FILE; err = parse_string(n, &curr->data.cset); @@ -938,6 +1037,7 @@ static int parse_verb_file(snd_use_case_mgr_t *uc_mgr, INIT_LIST_HEAD(&verb->disable_list); INIT_LIST_HEAD(&verb->transition_list); INIT_LIST_HEAD(&verb->device_list); + INIT_LIST_HEAD(&verb->cmpt_device_list); INIT_LIST_HEAD(&verb->modifier_list); INIT_LIST_HEAD(&verb->value_list); list_add_tail(&verb->list, &uc_mgr->verb_list); diff --git a/src/ucm/ucm_local.h b/src/ucm/ucm_local.h index b89de2a..3bfdd67 100644 --- a/src/ucm/ucm_local.h +++ b/src/ucm/ucm_local.h @@ -49,6 +49,7 @@ #define SEQUENCE_ELEMENT_TYPE_EXEC 4 #define SEQUENCE_ELEMENT_TYPE_CSET_BIN_FILE 5 #define SEQUENCE_ELEMENT_TYPE_CSET_TLV 6 +#define SEQUENCE_ELEMENT_TYPE_CMPT_SEQ 7 struct ucm_value { struct list_head list; @@ -56,6 +57,12 @@ struct ucm_value { char *data; }; +/* sequence of a component device */ +struct component_sequence { + struct use_case_device *device; /* component device */ + int enable; /* flag to choose enable or disable list of the device */ +}; + struct sequence_element { struct list_head list; unsigned int type; @@ -64,6 +71,7 @@ struct sequence_element { char *cdev; char *cset; char *exec; + struct component_sequence cmpt_seq; /* component sequence */ } data; }; @@ -167,6 +175,9 @@ struct use_case_verb { /* hardware devices that can be used with this use case */ struct list_head device_list; + /* component device list */ + struct list_head cmpt_device_list; + /* modifiers that can be used with this use case */ struct list_head modifier_list; diff --git a/src/ucm/utils.c b/src/ucm/utils.c index 45307b0..0fba85a 100644 --- a/src/ucm/utils.c +++ b/src/ucm/utils.c @@ -210,6 +210,7 @@ void uc_mgr_free_verb(snd_use_case_mgr_t *uc_mgr) uc_mgr_free_transition(&verb->transition_list); uc_mgr_free_value(&verb->value_list); uc_mgr_free_device(&verb->device_list); + uc_mgr_free_device(&verb->cmpt_device_list); uc_mgr_free_modifier(&verb->modifier_list); list_del(&verb->list); free(verb);