diff mbox

[RFC,V2,1/2] ASoC: img: Add binding document for Pistachio audio card

Message ID 1453818867-16322-2-git-send-email-Damien.Horsley@imgtec.com (mailing list archive)
State New, archived
Headers show

Commit Message

Damien Horsley Jan. 26, 2016, 2:34 p.m. UTC
From: "Damien.Horsley" <Damien.Horsley@imgtec.com>

Add a binding document for Pistachio audio card

Signed-off-by: Damien.Horsley <Damien.Horsley@imgtec.com>
---
 .../bindings/sound/img,pistachio-audio.txt         | 308 +++++++++++++++++++++
 1 file changed, 308 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/img,pistachio-audio.txt

Comments

Mark Brown Jan. 27, 2016, 2:57 p.m. UTC | #1
On Tue, Jan 26, 2016 at 02:34:26PM +0000, Damien Horsley wrote:

> +  - clock-names : Includes the following entries:
> +        "audio_pll"  The audio PLL
> +        "i2s_mclk"   The i2s reference clock
> +                     Also connected to i2s_out_0_mclk output
> +        "dac_mclk"   Dac reference clock. Connected to i2s_dac_clk output

Why are these (especially the dac_mclk and i2s_mclk) properties of the
card and not of the drivers for the respective devices?

> +  - img,mute-gpio : phandle of the mute gpio
> +
> +  - img,hp-det-gpio : phandle of the headphone detect gpio

The DT maintainers would prefer those to be named -gpios.
Damien Horsley Jan. 27, 2016, 3:18 p.m. UTC | #2
On 27/01/16 14:57, Mark Brown wrote:
> On Tue, Jan 26, 2016 at 02:34:26PM +0000, Damien Horsley wrote:
> 
>> +  - clock-names : Includes the following entries:
>> +        "audio_pll"  The audio PLL
>> +        "i2s_mclk"   The i2s reference clock
>> +                     Also connected to i2s_out_0_mclk output
>> +        "dac_mclk"   Dac reference clock. Connected to i2s_dac_clk output
> 
> Why are these (especially the dac_mclk and i2s_mclk) properties of the
> card and not of the drivers for the respective devices?
> 

Due to the shared nature of these clocks. Individual components cannot
be responsible for controlling these as this could break configurations
for other components that are sharing the clocks. Only the card driver
has visibility of all of the components and their requirements.

audio_pll is used by spdif out, parallel out, i2s out, and i2s in if
there are codecs on the i2s in path that make use of i2s_mclk and
dac_mclk (derived from audio_pll)

i2s_mclk and dac_mclk can be used by both the i2s in and i2s out paths
on some boards

>> +  - img,mute-gpio : phandle of the mute gpio
>> +
>> +  - img,hp-det-gpio : phandle of the headphone detect gpio
> 
> The DT maintainers would prefer those to be named -gpios.
> 

Ok
Mark Brown Jan. 27, 2016, 4 p.m. UTC | #3
On Wed, Jan 27, 2016 at 03:18:20PM +0000, Damien Horsley wrote:
> On 27/01/16 14:57, Mark Brown wrote:
> > On Tue, Jan 26, 2016 at 02:34:26PM +0000, Damien Horsley wrote:

> >> +  - clock-names : Includes the following entries:
> >> +        "audio_pll"  The audio PLL
> >> +        "i2s_mclk"   The i2s reference clock
> >> +                     Also connected to i2s_out_0_mclk output
> >> +        "dac_mclk"   Dac reference clock. Connected to i2s_dac_clk output

> > Why are these (especially the dac_mclk and i2s_mclk) properties of the
> > card and not of the drivers for the respective devices?

> Due to the shared nature of these clocks. Individual components cannot
> be responsible for controlling these as this could break configurations
> for other components that are sharing the clocks. Only the card driver
> has visibility of all of the components and their requirements.

You're talking about the code that decides what rates to set the clock
at, not where the properties are placed in the DT.

> i2s_mclk and dac_mclk can be used by both the i2s in and i2s out paths
> on some boards

Multiple devices can reference the same clock.
Damien Horsley Jan. 27, 2016, 5:13 p.m. UTC | #4
On 27/01/16 16:00, Mark Brown wrote:
> On Wed, Jan 27, 2016 at 03:18:20PM +0000, Damien Horsley wrote:
>> On 27/01/16 14:57, Mark Brown wrote:
>>> On Tue, Jan 26, 2016 at 02:34:26PM +0000, Damien Horsley wrote:
> 
>>>> +  - clock-names : Includes the following entries:
>>>> +        "audio_pll"  The audio PLL
>>>> +        "i2s_mclk"   The i2s reference clock
>>>> +                     Also connected to i2s_out_0_mclk output
>>>> +        "dac_mclk"   Dac reference clock. Connected to i2s_dac_clk output
> 
>>> Why are these (especially the dac_mclk and i2s_mclk) properties of the
>>> card and not of the drivers for the respective devices?
> 
>> Due to the shared nature of these clocks. Individual components cannot
>> be responsible for controlling these as this could break configurations
>> for other components that are sharing the clocks. Only the card driver
>> has visibility of all of the components and their requirements.
> 
> You're talking about the code that decides what rates to set the clock
> at, not where the properties are placed in the DT.
> 
>> i2s_mclk and dac_mclk can be used by both the i2s in and i2s out paths
>> on some boards
> 
> Multiple devices can reference the same clock.
> 

audio_pll is referenced exclusively by the card device

i2s_mclk and dac_mclk can also be referenced by other devices. The i2s
out controller references i2s_mclk, and codec devices can reference
i2s_mclk/dac_mclk dependent on their system clock requirements

without a reference to i2s_mclk and dac_mclk in the card driver, it
would not be possible to control the divisors and gates for these clocks
in the following cases:

Simplistic codecs that do not have drivers

Codec drivers that do not call clk_set_rate and clk_enable/clk_disable
Mark Brown Jan. 27, 2016, 8:14 p.m. UTC | #5
On Wed, Jan 27, 2016 at 05:13:09PM +0000, Damien Horsley wrote:

> audio_pll is referenced exclusively by the card device

That one *may* be plausible.

> i2s_mclk and dac_mclk can also be referenced by other devices. The i2s
> out controller references i2s_mclk, and codec devices can reference
> i2s_mclk/dac_mclk dependent on their system clock requirements

The clock API copes perfectly happily with this.

> without a reference to i2s_mclk and dac_mclk in the card driver, it
> would not be possible to control the divisors and gates for these clocks
> in the following cases:

> Simplistic codecs that do not have drivers

> Codec drivers that do not call clk_set_rate and clk_enable/clk_disable

Nonsense, if there is no driver or the driver doesn't do what you want
then fix that.  Don't bodge things at the wrong abstraction layer, that
just creates problems later on when someone comes along and does things
properly or tries to use the device tree outside of your particular
implementation (eg, when working with a differnet OS).
Damien Horsley Jan. 28, 2016, 2:17 p.m. UTC | #6
On 27/01/16 20:14, Mark Brown wrote:
> On Wed, Jan 27, 2016 at 05:13:09PM +0000, Damien Horsley wrote:
> 
>> audio_pll is referenced exclusively by the card device
> 
> That one *may* be plausible.
> 
>> i2s_mclk and dac_mclk can also be referenced by other devices. The i2s
>> out controller references i2s_mclk, and codec devices can reference
>> i2s_mclk/dac_mclk dependent on their system clock requirements
> 
> The clock API copes perfectly happily with this.
> 
>> without a reference to i2s_mclk and dac_mclk in the card driver, it
>> would not be possible to control the divisors and gates for these clocks
>> in the following cases:
> 
>> Simplistic codecs that do not have drivers
> 
>> Codec drivers that do not call clk_set_rate and clk_enable/clk_disable
> 
> Nonsense, if there is no driver or the driver doesn't do what you want
> then fix that.  Don't bodge things at the wrong abstraction layer, that
> just creates problems later on when someone comes along and does things
> properly or tries to use the device tree outside of your particular
> implementation (eg, when working with a differnet OS).
> 

Okay. If it can be expected that the codec driver will call these then
the references will not be required in the card driver for the codecs.

The i2s out controller also uses i2s_mclk, and calls clk_set_rate in
hw_params at present. Would creating a set_sysclk callback for the i2s
out controller, then calling snd_soc_dai_set_sysclk on the cpu dai in
addition to the codec dais in the card driver be the correct way to
manage this?
Mark Brown Jan. 28, 2016, 11:25 p.m. UTC | #7
On Thu, Jan 28, 2016 at 02:17:37PM +0000, Damien Horsley wrote:

> The i2s out controller also uses i2s_mclk, and calls clk_set_rate in
> hw_params at present. Would creating a set_sysclk callback for the i2s
> out controller, then calling snd_soc_dai_set_sysclk on the cpu dai in
> addition to the codec dais in the card driver be the correct way to
> manage this?

That'd be more normal, yes.
diff mbox

Patch

diff --git a/Documentation/devicetree/bindings/sound/img,pistachio-audio.txt b/Documentation/devicetree/bindings/sound/img,pistachio-audio.txt
new file mode 100644
index 0000000..ab5bf7f
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/img,pistachio-audio.txt
@@ -0,0 +1,308 @@ 
+Imagination Technologies Pistachio Audio Card Driver
+
+Required properties:
+
+  - compatible : Compatible list, must contain "img,pistachio-audio"
+
+  - clocks : Contains an entry for each entry in clock-names
+
+  - clock-names : Includes the following entries:
+        "audio_pll"  The audio PLL
+        "i2s_mclk"   The i2s reference clock
+                     Also connected to i2s_out_0_mclk output
+        "dac_mclk"   Dac reference clock. Connected to i2s_dac_clk output
+
+  - img,cr-periph : phandle of the peripheral control syscon
+                    node which contains the i2s loopback control registers
+
+Optional properties:
+
+  - img,widgets : Please refer to widgets.txt
+
+  - img,routing : A list of the connections between audio components
+
+  - img,mute-gpio : phandle of the mute gpio
+
+  - img,hp-det-gpio : phandle of the headphone detect gpio
+
+  - img,i2s-clk-loopback : When present, the frame and bit clock signals for
+			   the i2s out and i2s in controllers will be connected
+			   internally
+
+Optional subnodes:
+
+  - spdif-out : Contains spdif out information
+
+  - spdif-in : Contains spdif in information
+
+  - parallel-out : Contains parallel out information
+
+  - i2s-out : Contains i2s out information
+
+  - i2s-in : Contains i2s in information
+
+Required spdif-out, spdif-in subnode properties:
+
+  - cpu-dai : phandle of spdif cpu dai
+
+Required parallel-out subnode properties:
+
+  - cpu-dai : phandle of parallel out cpu dai
+
+  - sound-dai : phandle of internal dac
+
+Required i2s-out, i2s-in subnode properties:
+
+  - cpu-dai : phandle of i2s cpu dai
+
+  - format : i2s format. "i2s" and "left_j" are supported by
+	     the Pistachio iteration of the i2s controllers
+
+Optional i2s-out, i2s-in subnode properties:
+
+  - bitclock-inversion : i2s bit clock inversion
+
+  - frame-inversion : i2s frame clock inversion
+
+  - continuous-clock : i2s bit and frame clock always active
+
+Optional i2s-out, i2s-in subnodes:
+
+  - <codec-name> : Contains codec information. <codec-name> will be used as
+		   the prefix for the codec. This name must be unique for
+		   each individual codec (unique codec device node), and
+		   cannot be equal to "internal-dac", "i2s-out" or "i2s-in".
+		   The name should be short to avoid control name truncation
+
+Optional <codec-name> subnode properties:
+
+  - mclk : Contains the mclk (master clock) used by the DAC/ADC. If no mclk
+	   is required, or the mclk is provided externally, with no software
+	   intervention required to compenstate for differing sample rates,
+	   this can be omitted.
+	   Valid identifiers (dt-bindings/sound/pistachio-audio.h):
+
+	       PISTACHIO_MCLK_I2S       mclk is provided by the i2s_out_0_mclk
+					output from Pistachio SoC. This clock
+					is shared with the internal i2s out
+					controller
+
+	       PISTACHIO_MCLK_DAC	mclk is provided by the i2s_dac_clk
+					output from Pistachio SoC
+
+  - sound-dai : phandle of the codec. If the codec does not accept/require
+		software configuration, this can be omitted
+
+  - mclk-index : Index of the mclk, used for snd_soc_dai_set_sysclk call.
+		 0 is used if this property is omitted
+
+  - frame-master : Indicates this codec is the frame clock master
+
+  - bitclock-master : Indicates this codec is the bit clock master
+
+  frame-master and bitclock-master cannot exist in more than one of the codec
+  subnodes
+
+  frame-master and bitclock-master cannot be used within i2s out codec subnodes
+  as the Pistachio iteration of the i2s out controller accepts master mode
+  only
+
+  frame-master and bitclock-master can be omitted if img,i2s-clk-loopback is
+  used, or if frame/bit clock generation does not require software intervention
+  (eg a codec operating in hardware-mode)
+
+Required <codec-name> subnode properties if mclk property is present:
+
+  - mclk-fs : Contains the set of fs ratios the DAC/ADC accepts (Nfs for
+	      sample rate r specifies the master clock input to the DAC is
+	      N times r). It is assumed this set of ratios is applicable to
+	      any given sample rate where this does not lead to a violation
+	      of the minimum/maximum frequencies specified by mclk-min-fs-freq
+	      and mclk-max-fs-freq respectively
+
+  - mclk-min-fs-freq : Contains the minimum frequency the DAC/ADC accepts for
+		       the mclk-fs list above
+
+  - mclk-max-fs-freq : Contains the maximum frequency the DAC/ADC accepts for
+		       the mclk-fs list above
+
+  - mclk-max-freq : Contains the maximum frequency for the DAC/ADC. Must be
+		    greater than or equal to mclk-max-fs-freq
+
+
+Example 1:
+
+All audio components present on board. 2x pcm3168a codecs provide 3 i2s in
+and out channels each. dac_mclk provides the single master clock to both
+codecs. The Pistachio i2s out controller is the frame + bit clock master for
+the DAC path. The second pcm3168a codec is the frame + bit clock master for
+the ADC path. GPIO 1 in bank 5 is used as a mute control (active low). GPIO 3
+in bank 5 is used for headphone detect control (active high)
+
+pistachio_audio_card {
+	compatible = "img,pistachio-audio";
+
+	clocks = <&clk_core CLK_AUDIO_PLL>,
+		 <&clk_core CLK_I2S>,
+		 <&clk_core CLK_AUDIO>;
+	clock-names = "audio_pll", "i2s_mclk", "dac_mclk";
+
+	img,cr-periph = <&cr_periph>;
+
+	img,mute-gpio = <&gpio5 1 GPIO_ACTIVE_LOW>;
+	img,hp-det-gpio = <&gpio5 3 GPIO_ACTIVE_HIGH>;
+
+	img,widgets = "Headphone", "Headphones",
+		      "Speaker", "Speakers";
+
+	img,routing = "Headphones", "internal-dac AOUTL",
+		      "Headphones", "internal-dac AOUTR",
+		      "Speakers", "internal-dac AOUTL",
+		      "Speakers", "internal-dac AOUTR";
+
+	spdif-out {
+		cpu-dai = <&spdif_out>;
+	};
+
+	spdif-in {
+		cpu-dai = <&spdif_in>;
+	};
+
+	parallel-out {
+		cpu-dai = <&parallel_out>;
+		sound-dai = <&internal_dac>;
+	};
+
+	i2s-out {
+		cpu-dai = <&i2s_out>;
+		format = "i2s";
+
+		pcm3168a-1 {
+			mclk = <PISTACHIO_MCLK_DAC>;
+			mclk-fs = <128 192 256 384 512 768>;
+			mclk-min-fs-freq = <2048000>;
+			mclk-max-fs-freq = <36864000>;
+			mclk-max-freq = <36864000>;
+			sound-dai = <&pcm3168a_1 0>;
+		};
+
+		pcm3168a-2 {
+			mclk = <PISTACHIO_MCLK_DAC>;
+			mclk-fs = <128 192 256 384 512 768>;
+			mclk-min-fs-freq = <2048000>;
+			mclk-max-fs-freq = <36864000>;
+			mclk-max-freq = <36864000>;
+			sound-dai = <&pcm3168a_2 0>;
+		};
+	};
+
+	i2s-in {
+		cpu-dai = <&i2s_in>;
+		format = "i2s";
+
+		pcm3168a-1 {
+			mclk = <PISTACHIO_MCLK_DAC>;
+			mclk-fs = <256 384 512 768>;
+			mclk-min-fs-freq = <2048000>;
+			mclk-max-fs-freq = <36864000>;
+			mclk-max-freq = <36864000>;
+			sound-dai = <&pcm3168a_1 1>;
+		};
+
+		pcm3168a-2 {
+			mclk = <PISTACHIO_MCLK_DAC>;
+			mclk-fs = <256 384 512 768>;
+			mclk-min-fs-freq = <2048000>;
+			mclk-max-fs-freq = <36864000>;
+			mclk-max-freq = <36864000>;
+			sound-dai = <&pcm3168a_2 1>;
+			frame-master;
+			bitclock-master;
+		};
+	};
+};
+
+Example 2:
+
+i2s out, i2s in present on board. pcm5101 codec provides 1 i2s out channel.
+pcm1802 codec provides 1 i2s in channel. dac_mclk provides master clock to
+pcm1802. i2s_mclk provides master clock to pcm5101. Both codecs set to operate
+in hardware mode. The Pistachio i2s out controller is the frame + bit clock
+master for the DAC path. The pcm1802 codec is the frame + bit clock master for
+the ADC path
+
+pistachio_audio_card {
+	compatible = "img,pistachio-audio";
+
+	clocks = <&clk_core CLK_AUDIO_PLL>,
+		 <&clk_core CLK_I2S>,
+		 <&clk_core CLK_AUDIO>;
+	clock-names = "audio_pll", "i2s_mclk", "dac_mclk";
+
+	img,cr-periph = <&cr_periph>;
+
+	pinctrl-names = "default";
+	pinctrl-0 = <&dac_clk_pin>, <&i2s_mclk_pin>;
+
+	i2s-out {
+		cpu-dai = <&i2s_out>;
+		format = "i2s";
+
+		pcm5101 {
+			mclk = <PISTACHIO_MCLK_I2S>;
+			mclk-fs = <128 192 256 384 512 768 1024 1152 1536 2048 3072>;
+			mclk-min-fs-freq = <1024000>;
+			mclk-max-fs-freq = <49152000>;
+			mclk-max-freq = <49152000>;
+		};
+	};
+
+	i2s-in {
+		cpu-dai = <&i2s_in>;
+		format = "i2s";
+
+		pcm1802 {
+			mclk = <PISTACHIO_MCLK_DAC>;
+			mclk-fs = <256>;
+			mclk-min-fs-freq = <8192000>;
+			mclk-max-fs-freq = <49152000>;
+			mclk-max-freq = <49152000>;
+		};
+	};
+};
+
+Example 3:
+
+i2s out, i2s in present on board. dac provides 1 i2s out channel.
+microphone array provides 6 i2s in channels. No master clocks are required.
+The Pistachio i2s out controller is the frame + bit clock master
+for the DAC and microphone array paths.
+
+pistachio_audio_card {
+	compatible = "img,pistachio-audio";
+
+	clocks = <&clk_core CLK_AUDIO_PLL>,
+		 <&clk_core CLK_I2S>,
+		 <&clk_core CLK_AUDIO>;
+	clock-names = "audio_pll", "i2s_mclk", "dac_mclk";
+
+	img,cr-periph = <&cr_periph>;
+
+	img,i2s-clk-loopback;
+
+	i2s-out {
+		cpu-dai = <&i2s_out>;
+		format = "i2s";
+		bitclock-inversion;
+
+		dac {
+			sound-dai = <&simple-dac>;
+		};
+	};
+
+	i2s-in {
+		cpu-dai = <&i2s_in>;
+		format = "left_j";
+		frame-inversion;
+	};
+};