ASoC: simple_card: support for hw-params rules
Subsystems (4)
cover ASoC: simple_card: support for hw-params rules
From: Martin Sperl <[email protected]>
Simple_card does require under some circumstances the ability to configure certain hw_parameters based on clocks, bits, channels.
This patchset adds a generic way to configure these kind of things via the device tree easily. This patchset implements this for simple_card, but other drivers can just as easily make use of this.
For now we have the following matchers and actions:
* matchers:
* match_sample_bits
* match_rate
* match_channels
* actions:
* set_fixed_bclk_size
As a note: the available matching rules and action rules right now are hard-coded, but this could in principle get extended to be more dynamic via kallsyms_lookup_name that would lookup the requested symbol and assume it is a struct asoc_generic_hw_params_method, on which it could apply several sanity-checks before using the pointers for real.
This would allow other kinds of action methods to get exposed in codec-drivers, that can then get used to handle some settings specific to the codec.
I leave this is an exercise for later...
Martin Sperl (2):
ASoC: hw-params-rules: add generic hw_params-rules
ASoC: simple_card: add support for hw_params_rules
.../devicetree/bindings/sound/hw-params-rules.txt | 86 +++++ .../devicetree/bindings/sound/simple-card.txt | 1 + sound/soc/generic/Kconfig | 6 + sound/soc/generic/Makefile | 2 + sound/soc/generic/hw-params-rules.c | 402 +++++++++++++++++++++ sound/soc/generic/hw-params-rules.h | 49 +++ sound/soc/generic/simple-card.c | 11 +- 7 files changed, 554 insertions(+), 3 deletions(-) create mode 100644 Documentation/devicetree/bindings/sound/hw-params-rules.txt create mode 100644 sound/soc/generic/hw-params-rules.c create mode 100644 sound/soc/generic/hw-params-rules.h
--
2.1.4
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/2 ASoC: hw-params-rules: add generic hw_params-rules
In reply to a message not in the archiveFrom: Martin Sperl <[email protected]>
Add generic rules that may execute when running hw_params methods.
These rules are configured via the device-tree.
Right now only a static list of match and action rules exist. This can get changed in the future to something more dynamic if security concerns can get handled propperly.
--- .../devicetree/bindings/sound/hw-params-rules.txt | 86 +++++ sound/soc/generic/Kconfig | 6 + sound/soc/generic/Makefile | 2 + sound/soc/generic/hw-params-rules.c | 402 +++++++++++++++++++++ sound/soc/generic/hw-params-rules.h | 49 +++ 5 files changed, 545 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/hw-params-rules.txt create mode 100644 sound/soc/generic/hw-params-rules.c create mode 100644 sound/soc/generic/hw-params-rules.h
Documentation/devicetree/bindings/sound/hw-params-rules.txt new file +86 -0
@@ -0,0 +1,86 @@ +HW-params-rules: + +Rules that execute actions during hw-params method calls. + +The following optional nodes will sit inside the sound card nodes: + +hw-params-rule subnodes: + +Required properties: +- priority: the priority of the rule - lowest is applied first. + +contains further subnodes: + +- match: list of matches that have to apply +- action: list of actions to execute + +match and action subnodes: + +Required properties: + +- method: the method name (string) to execute + +Possible values for method: +* asoc_generic_hw_params_match_sample_bits +* asoc_generic_hw_params_match_rate +* asoc_generic_hw_params_match_channel +* asoc_generic_hw_params_set_fixed_bclk_size + + +Required/optional properties depend on the method defined +typical properies: + +- value: u32 value to pass to method. +- values: u32 value array to pass to method. + +Example: +sound { + compatible = "simple-audio-card"; + ... + /* + * set bclk_size to 80 when encountering: + * 48kHz or 96kHz with 2 channels with 32bit/channel + */ + hw-params-rule@0 { + priority = <0>; + match@0 { + method = "asoc_generic_hw_params_match_sample_bits"; + values = <32>; + }; + match@1 { + method = "asoc_generic_hw_params_match_rate"; + values = <48000>, <96000>; + }; + match@2 { + method = "asoc_generic_hw_params_match_channels"; + values = <2>; + }; + action@0 { + method = "asoc_generic_hw_params_set_fixed_bclk_size"; + value = <80>; + }; + }; + /* + * set bclk_size to 40 when encountering: + * 48kHz with 2 channels with 16bit/channel + */ + hw-params-rule@1 { + priority = <1>; + match@0 { + method = "asoc_generic_hw_params_match_sample_bits"; + values = <16>; + }; + match@1 { + method = "asoc_generic_hw_params_match_rate"; + values = <48000>; + }; + match@2 { + method = "asoc_generic_hw_params_match_channels"; + values = <2>; + }; + action@0 { + method = "asoc_generic_hw_params_set_fixed_bclk_size"; + value = <40>; + }; + }; +};
sound/soc/generic/Kconfig +6 -0
@@ -1,3 +1,9 @@ +config SND_HW_PARAMS_RULES + tristate "ASoC hw_param rules support" + depends on OF + help + This option enables generic hw_param_rules support + config SND_SIMPLE_CARD tristate "ASoC Simple sound card support" help
sound/soc/generic/Makefile +2 -0
@@ -1,3 +1,5 @@ snd-soc-simple-card-objs := simple-card.o +snd-soc-hw-params-rules-objs := hw-params-rules.o obj-$(CONFIG_SND_SIMPLE_CARD) += snd-soc-simple-card.o +obj-$(CONFIG_SND_HW_PARAMS_RULES) += snd-soc-hw-params-rules.o
sound/soc/generic/hw-params-rules.c new file +402 -0
402 lines not on this page · raw message
sound/soc/generic/hw-params-rules.h new file +49 -0
49 lines not on this page · raw message
Signature · 6 lines
2.1.4 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 2/2 ASoC: simple_card: add support for hw_params_rules
In reply to a message not in the archiveFrom: Martin Sperl <[email protected]>
Add support for hw_params_rules to simple_card.
--- Documentation/devicetree/bindings/sound/simple-card.txt | 1 + sound/soc/generic/simple-card.c | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/sound/simple-card.txt +1 -0
@@ -31,6 +31,7 @@ Optional subnodes: omitted when the card has only one DAI link. See the examples and the section bellow. +- hw-params-rules : Please refer to hw-params-rules.txt. Dai-link subnode properties and subnodes:
sound/soc/generic/simple-card.c +8 -3
@@ -8,6 +8,7 @@* it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ +#include "hw-params-rules.h" #include <linux/clk.h> #include <linux/device.h> #include <linux/gpio.h>
@@ -33,6 +34,7 @@ struct simple_card_data {int gpio_hp_det_invert;int gpio_mic_det;int gpio_mic_det_invert; +struct list_head hw_params_rules;struct snd_soc_dai_link dai_link[];/* dynamically allocated */ };
@@ -51,7 +53,7 @@ static int asoc_simple_card_startup(struct snd_pcm_substream *substream) ret =clk_prepare_enable (dai_props->cpu_dai.clk);if (ret)return ret; - + ret =clk_prepare_enable (dai_props->codec_dai.clk);if (ret)clk_disable_unprepare (dai_props->cpu_dai.clk);
@@ -99,7 +101,9 @@ static int asoc_simple_card_hw_params(struct snd_pcm_substream *substream,if (ret && ret != -ENOTSUPP ) goto err; } -return 0 ; + +return asoc_generic_hw_params_process_rules ( + &priv->hw_params_rules, substream, params); err:return ret; }
@@ -509,7 +513,8 @@ static int asoc_simple_card_parse_of(struct device_node *node,if (!priv->snd_card.name) priv->snd_card.name = priv->snd_card.dai_link->name; -return 0 ; +return asoc_generic_hw_params_rules_parse_of ( + dev, node, &priv->hw_params_rules); }/* Decrease the reference count of the device nodes */
Signature · 6 lines
2.1.4 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 18 lines · On 05/20/2016 02:30 PM, [email protected] wrote:
From: Martin Sperl <[email protected]>
Simple_carddoes require under some circumstances the ability to configure certainhw_parametersbased on clocks, bits, channels.This patchset adds a generic way to configure these kind of things via the device tree easily. This patchset implements this for
simple_card, but other drivers can just as easily make use of this.For now we have the following matchers and actions:
* matchers:
*match_sample_bits
*match_rate
*match_channels
* actions:
*set_fixed_bclk_size
Quoted 6 lines
As a note: the available matching rules and action rules right now are hard-coded, but this could in principle get extended to be more dynamic via
kallsyms_lookup_namethat would lookup the requested symbol and assume it is a structasoc_generic_hw_params_method, on which it could apply several sanity-checks before using the pointers for real.
How about allowing to embed eBPF bytecode in the DT that can be installed as a constraint set? This would allow maximum for flexibility and also make the implementation a lot easier.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 3 lines · Lars-Peter Clausen
How about allowing to embed eBPF bytecode in the DT that can be installed as a constraint set? This would allow maximum for flexibility and also make the implementation a lot easier.
That seems somewhat Linux specific, I'd like to see some DT maintainer buy in on that one as well as Takashi's thoughts.
Quoted 8 lines · Mark Brown
Quoted 3 lines · Lars-Peter Clausen
How about allowing to embed eBPF bytecode in the DT that can be installed as a constraint set? This would allow maximum for flexibility and also make the implementation a lot easier.
That seems somewhat Linux specific, I'd like to see some DT maintainer buy in on that one as well as Takashi's thoughts.
I am very much not in favour of embedding eBPF bytecode into the DT.
Mark.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 9 lines · On Fri, May 20, 2016 at 12:30:43PM +0000…
From: Martin Sperl <[email protected]>
Simple_carddoes require under some circumstances the ability to configure certainhw_parametersbased on clocks, bits, channels.This patchset adds a generic way to configure these kind of things via the device tree easily. This patchset implements this for
simple_card, but other drivers can just as easily make use of this.
I'm not familiar with the class of hardware here.
What exactly needs to be configured, under which situations?
How varied is this in practice?
Why does this make more sense than having individual drivers?
Quoted 8 lines
For now we have the following matchers and actions:
* matchers:
*match_sample_bits
*match_rate
*match_channels
* actions:
*set_fixed_bclk_size
Quoted 6 lines
As a note: the available matching rules and action rules right now are hard-coded, but this could in principle get extended to be more dynamic via
kallsyms_lookup_namethat would lookup the requested symbol and assume it is a structasoc_generic_hw_params_method, on which it could apply several sanity-checks before using the pointers for real.
I'm hoping that's a joke. ;)
Thanks,
Mark.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 9 lines · Mark Brown
Quoted 3 lines · Lars-Peter Clausen
How about allowing to embed eBPF bytecode in the DT that can be installed as a constraint set? This would allow maximum for flexibility and also make the implementation a lot easier.
That seems somewhat Linux specific, I'd like to see some DT maintainer buy in on that one as well as Takashi's thoughts.
Using eBPF is a good idea for our purposes, but I understand Mark's concern, too. That said, I'm in favor of eBPF as long as DT people don't mind. We'd need some tools but the rest would be easier (less patching) once after it's done.
thanks,
Takashi
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 11 lines · Mark Rutland
Quoted 8 lines · Mark Brown
Quoted 3 lines · Lars-Peter Clausen
How about allowing to embed eBPF bytecode in the DT that can be installed as a constraint set? This would allow maximum for flexibility and also make the implementation a lot easier.
That seems somewhat Linux specific, I'd like to see some DT maintainer buy in on that one as well as Takashi's thoughts.
I am very much not in favour of embedding eBPF bytecode into the DT.
This has to be seen in the context of the suggestion to reference kernel symbols by name from the DT.
My opinion is that if the interdependence between the components in your system is non-trivial you should write a proper driver. Otherwise we'll end up with DT-script and replicate all the terrible things from the ACPI world where people ship completely horrendous and broken byte code in the firmware.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 2 lines · Lars-Peter Clausen
My opinion is that if the interdependence between the components in your system is non-trivial you should write a proper driver. Otherwise we'll end
Yes, I tend to agree - I've not looked at the actual patch yet but there's a good, solid reason why we have explicit drivers for system integration. There is no value in pushing absoutely everything into DT, at some point you just end up with something at least as complicated as a real programming language with worse tooling.
Quoted 2 lines
up with DT-script and replicate all the terrible things from the ACPI world where people ship completely horrendous and broken byte code in the firmware.
I think that's unfair, there are good solid reasons for having AML and any interface is open to abuse.
Quoted 11 lines · Mark Rutland
Quoted 8 lines · Mark Brown
Quoted 3 lines · Lars-Peter Clausen
How about allowing to embed eBPF bytecode in the DT that can be installed as a constraint set? This would allow maximum for flexibility and also make the implementation a lot easier.
That seems somewhat Linux specific, I'd like to see some DT maintainer buy in on that one as well as Takashi's thoughts.
I am very much not in favour of embedding eBPF bytecode into the DT.
+1 What's wrong with Forth? ;)
Rob
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 9 lines · Mark Rutland
Quoted 5 lines · On Fri, May 20, 2016 at 12:30:43PM +0000…
From: Martin Sperl <[email protected]>
Simple_carddoes require under some circumstances the ability to configure certainhw_parametersbased on clocks, bits, channels.
Quoted 8 lines
Quoted 4 lines
This patchset adds a generic way to configure these kind of things via the device tree easily. This patchset implements this for
simple_card, but other drivers can just as easily make use of this.I'm not familiar with the class of hardware here.
What exactly needs to be configured, under which situations?
Well one example - here specifically is to set up bclk rates that the I2S hw itself is transferring for specific combinations.
Some of these rules depend on:
* the i2s driver hw itself - the i2s bcm2835 can only handle 32 bit transfers - so the block size needs to be set as a multiple of 2. in this case: sample-bits * channels.
* HW limits - e.g 24 bit/sample need to get transferred as 32 bit for the rpi-pcm5102a combination
* Clock selection dependent - the choice of the block size may be also 40 or 80 bit so that a integer divider clock can get selected as a preference.
E.g 32 bit/sample * 2 channels * 48kHz gives a divider of 25/4 using the main oscillator at 19.2MHz, which introduces some (possibly) audible noise due to jitter.
while 40bit/sample * 2 channels * 48kHz gives an integer divider of 20.
So controlling those helps using the hw setup properly.
Quoted 2 lines
How varied is this in practice?
I heard about some other devices besides the HifiBerry DAC that also would like to control the blockrate the same way.
I remember having seen some other possible things we want to control on the driver side during hw-params invocation, but I can not remember what these were on top of my head (GPIO, external clock selection if I remember correctly)
Quoted 2 lines
Why does this make more sense than having individual drivers?
Because then the driver would have to know a lot more about the combination of board and codec.
Also the idea proposed by Mark was to use simple-card instead of a dedicated driver which does not allow for these kind of controls.
The idea was also to make it generic enough that it could get even become part of the framework.
Quoted 9 lines
Quoted 9 lines
For now we have the following matchers and actions:
* matchers:
*match_sample_bits
*match_rate
*match_channels
* actions:
*set_fixed_bclk_size
Quoted 8 lines
Quoted 6 lines
As a note: the available matching rules and action rules right now are hard-coded, but this could in principle get extended to be more dynamic via
kallsyms_lookup_namethat would lookup the requested symbol and assume it is a structasoc_generic_hw_params_method, on which it could apply several sanity-checks before using the pointers for real.I'm hoping that's a joke. ;)
Just food for thought, because otherwise there would be dependencies on compiled codecs (or a long #ifdef list)
As an alternative we could also add a method tables to the codec structure, so that codecs could expose additional methods, that could then get used.
Martin
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html