Commit graph

76 commits

Author SHA1 Message Date
Jaroslav Kysela
22d5ca8b6b ucm: add a check for the empty configuration
Return an error if the UCM configuration is empty (no verbs
or no boot sequence).

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-10-06 10:43:13 +02:00
Jaroslav Kysela
eee879d381 ucm: implement CardIdByName substitution
The syntax is ${CardIdByName:CARDNAME[#INDEX]}.

The CARDNAME is the ALSA's soundcard name (short form).
The INDEX is the instance (0 = first, 1 = second etc.).

Example: ${CardIdByName:HDA Intel PCH}
(which is identical to ${CardIdByName:HDA Intel PCH#0})

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-06-03 17:17:11 +02:00
Jaroslav Kysela
ed4567d1c9 ucm: configuration - allow to define the configuration variables
It may be useful for the library files to use the runtime configuration
variables.

Example:

 Define.Var1 "hw:${CardId},2"
 Value.PlaybackPCM "${var:Var1}"

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-25 19:20:53 +02:00
Jaroslav Kysela
14636be4a8 ucm: rename _once command to _boot command
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-25 19:20:18 +02:00
Jaroslav Kysela
2d6eff3927 ucm: fix compilation error in set_defaults_user()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-19 10:55:35 +02:00
root
449bf7e191 ucm: initialize mgr->once_list
BugLink: https://github.com/alsa-project/alsa-lib/pull/50

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-16 15:48:35 +02:00
Jaroslav Kysela
0c3776a354 ucm: handle 'set _defaults' command
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-14 18:32:05 +02:00
Jaroslav Kysela
a570634a22 ucm: handle 'set _once' command
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-14 18:25:58 +02:00
Jaroslav Kysela
afb5a9cf61 ucm: execute SectionDefaults lately (when the first verb is set)
We need a way to set the SectionOnce at first before SectionDefaults.
It also does not make sense to run SectionDefaults when the API is
used only to query for values or so.

Execute the SectionDefaults commands only when the first verb
is set (before the verb specific commands).

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-14 18:24:39 +02:00
Jaroslav Kysela
fe6425af75 ucm: split conf_file_name and conf_dir_name
With ucm2, the file name might differ from the directory
name. Also, allocate those fields.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-01-15 10:40:35 +01:00
Fabrice Fontaine
8e2c70add7 src/ucm/main.c: fix build without mixer
Commit 4ce38a5ff4 breaks the build without
mixer on:

  CCLD     libasound.la
/home/buildroot/autobuild/instance-1/output-1/host/lib/gcc/xtensa-buildroot-linux-uclibc/8.3.0/../../../../xtensa-buildroot-linux-uclibc/bin/ld: ucm/.libs/libucm.a(main.o): in function `snd_use_case_set':
main.c:(.text+0x185c): undefined reference to `snd_mixer_selem_id_parse'

Fixes: http://autobuild.buildroot.org/results/4d91c9f82a2a61c50c457a851073b85cc09ea345

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-12-03 20:55:34 +01:00
Jaroslav Kysela
ebdd2b6cdb ucm: add _identifiers list
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-30 20:31:55 +01:00
Jaroslav Kysela
9baf64da2f ucm: return always at least NULL if no list is available in snd_use_case_get_list()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-29 22:32:21 +01:00
paulhsia
c79f09e1f5 ucm: Use strncmp to avoid access-out-of-boundary
If the length of the identifier is less than the length of the prefix,
access-out-of-boundary will occur in memcmp().

Signed-off-by: paulhsia <paulhsia@chromium.org>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-29 20:48:56 +01:00
Jaroslav Kysela
4c89f4eb90 ucm: fix the cdev initialization sequence
The default values must be set before the defaults
UCM sequence is executed.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-26 17:35:18 +01:00
Jaroslav Kysela
cf630e4e54 ucm: remove the new-line for uc_error() calls
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-25 19:50:47 +01:00
Jaroslav Kysela
5c88b18371 ucm: add snd_use_case_parse_selem_id()
and add strict ucm_id checks to snd_use_case_parse_ctl_elem_id()

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-14 15:00:40 +01:00
Jaroslav Kysela
cd4b07ffbd ucm: add snd_use_case_parse_ctl_elem_id()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-14 15:00:40 +01:00
Jaroslav Kysela
530e8ea4c6 ucm: add PlaybackCTL and CaptureCTL default values when they are not set
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-14 15:00:40 +01:00
Jaroslav Kysela
c01e3d30b8 ucm: small cosmetic uc_error change in execute_sequence()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-14 15:00:40 +01:00
Jaroslav Kysela
8a36e38dc4 ucm: add If condition block
The syntax is simple:

If./any-if-identificator/ {
  Condition {
    Type /type_here/
    /optional defines/
  }
  True {
    /block used when condition is evaluated as true/
  }
  False {
    /block used when condition is evaluated as false/
  }
}

The Type "ControlExists" is implemented:

Condition {
  Type ControlExists
  Device "hw:${CardId}"
  Control "iface=CARD,name='Headphone Jack'"
}

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-14 15:00:37 +01:00
Jaroslav Kysela
d8dfe4dac7 ucm: save the whole ctl info to the ctl_list structure
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-10 13:12:21 +01:00
Jaroslav Kysela
0dd89f3892 ucm: add the run-time variable substitution
Those two variables are supported:

  ${ConfName}      - configuration file name
  ${CardId}        - card identification string (like PCH)
  ${CardName}      - card name (driver)
  ${CardLongName}  - card long name (driver)
  ${env:ENV_NAME}  - returns the environment variable ENV_NAME

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-10 13:12:21 +01:00
Jaroslav Kysela
32ff0ba7a3 ucm: add support for multiple control devices, more aggresive caching
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-10 13:11:35 +01:00
Jaroslav Kysela
5b9041bced Change FSF address (Franklin Street)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2017-11-14 14:29:26 +01:00
Mengdong Lin
e93d93a8cd ucm: Add command 'get _file' to get the config file name of the opened card
After opening a card, this command can show the name of the actually
loaded configuration file, either matches the card name or card long name.
So developers can check if there is a device-sepcific configuration file
available for a given card.

Signed-off-by: Mengdong Lin <mengdong.lin@linux.intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-01-18 11:55:25 +01:00
Mengdong Lin
6ad2a9763d ucm: Add ATTRIBUTE_UNUSED for unused parameters of execute_component_seq()
To fix the following warnings:

main.c: In function ‘execute_component_seq’:
main.c:489:24: warning: unused parameter ‘value_list1’ [-Wunused-parameter]
      struct list_head *value_list1,
                        ^
main.c:490:24: warning: unused parameter ‘value_list2’ [-Wunused-parameter]
      struct list_head *value_list2,
                        ^
main.c:491:24: warning: unused parameter ‘value_list3’ [-Wunused-parameter]
      struct list_head *value_list3,
                        ^

Signed-off-by: Mengdong Lin <mengdong.lin@linux.intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-12-28 16:15:01 +01:00
Mengdong Lin
60b68cb47e ucm: Execute sequence of component devices
A machine device's sequence can enable or disable a component device. So
when executing a machine device's sequence, the enable or disable sequence
of its component devices will also be excecuted.

Components don't define card device cdev in their sequences. So before
executing a component device sequence, UCM manager will
- store cdev defined by the sequence of its parent, the machine device;
- mark itself entering 'component domain'.

Then this cdev will be used to excute the sequence of the component
device.

When UCM manager completes executing the sequence of the component device,
it will leave 'compnent domain' and reset the saved cdev to NULL.

Signed-off-by: Mengdong Lin <mengdong.lin@linux.intel.com>
Acked-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-12-02 20:29:34 +01:00
Antonio Ospite
4ec907c773 ucm: fix crash when calling snd_use_case_geti() with no device or modifier
When calling snd_use_case_geti(uc_mgr, "_devstatus", &lvalue) the code
ends up calling device_status(uc_mgr, NULL), which result in a crash in
strcmp(dev->name, NULL), when there are enabled devices.

This happens because snd_use_case_geti() allows a "_devstatus"
identifier even if it's only supposed to allow the form
"_devstatus/{device}".

So check that the device name is not null.

The same issue occurs with "_modstatus", this change fixes that as well.

Signed-off-by: Antonio Ospite <ao2@ao2.it>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-09-29 09:55:08 +02:00
Hsin-Yu Chao
e57b521c61 ucm: add cset-tlv
This patch enables UCM to set a file in TLV format to kcontrol by:
cset-tlv "name='<kcontrol-name>' <path-to-file>"
This new 'cset-tlv' command will be used to write audio DSP to
specific alsa control, where the driver expectes a file in TLV
format.
The TLV file to set to kcontrol will be checked first by file size
not larger than 16 MB, and then examine if the length field reports
correct number of bytes in the TLV file.

Signed-off-by: Hsin-Yu Chao <hychao@chromium.org>
Reviewed-by: Vinod Koul <vinod.koul@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-04-13 15:40:17 +02:00
Tanu Kaskinen
567c831e69 ucm: fix some variable constness issues
I submitted earlier a patch that made the value parameter of
snd_use_case_get() non-const, but as that changed the public API, the
patch couldn't be accepted. This is the same patch, modifying the
internal code so that there are fewer issues with constness, but the
public API is left alone (a comment was added to the function
documentation, though, so that hopefully nobody else will try to fix
the same unfixable problem).

Signed-off-by: Tanu Kaskinen <tanu.kaskinen@linux.intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-02-17 22:16:00 +01:00
Tanu Kaskinen
a102e66440 ucm: fix the logic of choosing the default cdev
If the cdev has not been configured explicitly, use the PlaybackCTL
or CaptureCTL value if one of them is set. If neither are set, or if
both are set to different values, then there's no sensible default, so
executing the sequence should fail. The previous code probably tried
to implement this logic, but it was buggy.

Also use more descriptive variable names than "cdev1" and "cdev2".

Signed-off-by: Tanu Kaskinen <tanu.kaskinen@linux.intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-02-17 22:15:53 +01:00
Tanu Kaskinen
1dd239b781 ucm: fix incorrect error code sign
Reported-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Tanu Kaskinen <tanu.kaskinen@linux.intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-02-17 22:15:44 +01:00
Tanu Kaskinen
a540bb3f89 ucm: fix variable mixup
I assume the intention was to use cdev1 for PlaybackCTL and cdev2 for
CaptureCTL, but cdev1 was being used for both and cdev2 was not used
for anything.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-02-11 12:27:54 +01:00
Lu, Han
6ea14c3624 ucm: add binary configure file parse
with cset command, UCM set kcontrol parameters directly:
    cset "name='<KCONTROL_NAME>' 1<,2,3,...>"
This patch enables UCM to set kcontrol with parameters from
configure file:
    cset-bin-file "name='<KCONTROL_NAME>' <path/to/file>"
where "cset-bin-file" is a newly added keyword alongside of "cset",
to indicate cset with binary data in file.
The binary data in file is parameter for audio DSPs, and it's just
passed by UCM/ALSA as raw data. The data type of parameter elements
must be byte, and the count must matches driver definition.

Signed-off-by: Lu, Han <han.lu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-01-23 17:21:27 +01:00
Takashi Iwai
72c8b07b2a ucm: Fix uninitialized err in snd_use_case_set()
The compiler warns like:
  main.c:1664:9: warning: 'err' may be used uninitialized in this function [-Wmaybe-uninitialized]

and actually there are slight code paths that slip.
This patch adds the proper initializations to 0 to return the success
code in these code paths.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-11-21 15:32:23 +01:00
Juho Hämäläinen
14d653d7c3 ucm: Fix segfault when device argument is missing from _sw{dev, mod}
Signed-off-by: Juho Hämäläinen <juho.hamalainen@tieto.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2013-05-24 13:03:54 +02:00
Jaroslav Kysela
b6eb0f9bfd all places: doxygen cleanups
I see no errors with these changes using doxygen 1.8.1.1 .

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2013-04-08 16:42:24 +02:00
Tanu Kaskinen
1629e2fbf3 ucm: Set uc_mgr->ctl to NULL after closing it.
Fixes a double-free bug.

Signed-off-by: Tanu Kaskinen <tanuk@iki.fi>
Acked-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2013-01-28 10:22:30 +01:00
Takashi Iwai
7c5c3ff3de ucm: Add const to execute_cset() argument
Now with the previous rewrite of execute_cset(), the cset string is no
longer modified, thus we can pass const safely.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-08-10 14:19:17 +02:00
Takashi Iwai
58d10c09e1 ucm: Improve cset command parsing
The cset command parsing in ucm/main.c assumes implicitly that the
argument contains no space, thus an example below wouldn't work:
    cset "name='Input Select' Digital Mic"

This patch introduces a new internal API function
__snd_ctl_ascii_elem_id_parse() to improve the cset parser.

Reported-by: Tanu Kaskinen <tanu.kaskinen@digia.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-08-10 14:14:28 +02:00
Tanu Kaskinen
e16a9a04b1 ucm: Return NULL from get_list0() and get_list20() in case of empty lists.
alloc_str_list() sets the result to NULL too, so this patch
makes the behavior more consistent. This also fixes a crash
in PulseAudio, because PulseAudio assumes that
snd_use_case_get_list() always initializes the result, and
since snd_use_case_get_list() uses get_list20(), this
assumption didn't hold.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-08-01 15:47:27 +02:00
Arun Raghavan
e8923f2e75 ucm: Handle repeat device and modifier enables/disables
Currently, enabling a device twice can cause it to be added to
snd_use_case_mgr_t->active_devices twice, causing the list to become a
loop and subsequent uses to result in an infinite loop.

This patch makes sure we don't enable/disable a device twice, and avoid
doing the same for modifiers.

Signed-off-by: Arun Raghavan <arun.raghavan@collabora.co.uk>
Acked-by: Liam Girdwood <lrg@ti.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-05-29 11:59:26 +02:00
Lu Guanqun
a97aa7f065 ucm: tivial code style fix
Signed-off-by: Lu Guanqun <guanqun.lu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2011-08-19 10:41:35 +02:00
Lu Guanqun
29880e8c66 ucm: fix seg fault in execute_cset()
When there's no space in 'cset', 'pos' gets NULL, dereferencing 'pos' gets a
seg fault. We need to be more robust.

Signed-off-by: Lu Guanqun <guanqun.lu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2011-08-19 10:41:26 +02:00
Stephen Warren
e2c2262403 UCM: get: Implement 'exact' value retrieval
[=]<NAME>[/[<modifier>|</device>][/<verb>]]
- value identifier <NAME>
- Search starts at given modifier or device if any,
    else at a verb
- Search starts at given verb if any,
    else current verb
- Searches modifier/device, then verb, then defaults
- Specify a leading "=" to search only the exact
  device/modifier/verb specified, and not search
  through each object in turn.
- Examples:
    "PlaybackPCM/Play Music"
    "CapturePCM/SPDIF"
  From ValueDefaults only:
    "=Variable"
  From current active verb:
    "=Variable//"
  From verb "Verb":
    "=Variable//Verb"
  From "Modifier" in current active verb:
    "=Variable/Modifier/"
  From "Modifier" in "Verb":
    "=Variable/Modifier/Verb"

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Liam Girdwood <lrg@ti.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2011-06-08 18:22:15 +02:00
Stephen Warren
a48f67c0ed UCM: snd_use_case_get: Don't segfault when no current verb
get_value, called by snd_use_case_get, uses uc_mgr->active_verb without
checking there is one, and hence can segfault. Fix this.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Liam Girdwood <lrg@ti.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2011-06-08 18:21:46 +02:00
Stephen Warren
32d24f4071 UCM: Allow querying of {Supported,Conflicting}Devices
At any time, one can query:

_supporteddevs/<modifier>|<device>/<verb>
_conflictingdevs/<modifier>|<device>/<verb>

If a verb is current, one can query:

_supporteddevs/<modifier>|<device>
_conflictingdevs/<modifier>|<device>

Note that at most one of the supported/conflicting devs lists has
any entries, and when neither is present, all devices are supported.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Liam Girdwood <lrg@ti.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2011-06-08 18:21:21 +02:00
Stephen Warren
547300fb35 UCM: Disallow gets of undefined system properties
In UCM, there are various system-defined properties whose names start
with "_". Explicitly prevent any gets from falling back to properties
defined in a config file if the property name starts with "_", in order
to reserve the entire "_" namespace for system-defined properties.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Liam Girdwood <lrg@ti.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2011-06-08 18:21:01 +02:00
Stephen Warren
fc038149c5 UCM: Implement ConflictingDevices, add device list to devices
Wherever SupportedDevice can appear, also allow ConflictingDevice. Only
one or the other (or neither) may be specified. When neither is
specified, allow anything. Sometimes, listing ConflictingDevices may
result in a shorter list than explicitly listing all SupportedDevices.

Add support for SupportedDevice and ConflictingDevice to SectionDevice.
This allows representing devices which are mutually exclusive, e.g. due
to a mux that switches between capturing from two different microphones,
without the possibility of mixing.

Enhance is_modifier_supported to allow ignoring SupportedDevice and
ConflictingDevice. This is useful when querying values from a
SectionModifier; there's no reason we shouldn't be able to query values
just because the current configuration would prevent enabling that
device. The new is_device_supported is implemented similarly.

Enhance switch_device to remove the old device from the current device
list before querying for the new device, and add it back immediately
afterwards. This allows the query for the new device to ignore any
conflicts caused solely by the old device.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Liam Girdwood <lrg@ti.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2011-06-08 18:20:26 +02:00