Skip to content

backport of upstream i2s and clock #1439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from

Conversation

msperl
Copy link
Contributor

@msperl msperl commented Apr 25, 2016

Note that there are still some clocks in the device tree that are not yet configured properly and use the hard-coded clocks:

  • uart
  • sdhost
  • mmc
  • pwm
  • spi/i2c
  • smi (actually smi is running its own clockmanager - we need to fix that driver!)

msperl added 11 commits April 25, 2016 06:54
Enable the clock manager by default.

Signed-off-by: Martin Sperl <[email protected]>
Removed clock registers from reg and added clock
to i2s devicetree node.

Signed-off-by: Martin Sperl <[email protected]>
Cleanup of includes so that they are ordered alphabetically.

Signed-off-by: Martin Sperl <[email protected]>
Signed-off-by: Mark Brown <[email protected]>
Since the move to the new clock framework with commit 94cb7f7
("ARM: bcm2835: Switch to using the new clock driver support.")
this driver was no longer functional as it was manipulating the
clock registers locally without going true the framework.

This patch moves to use the new clock framework and also
moves away from the hardcoded address offsets for DMA getting
the dma-address directly from the device tree.

Note that the optimal bclk_ratio selection to avoid jitter
due to the use of fractional dividers, which is in the
current version has been removed, because not all devices
support these non power of 2 sized transfers, which resulted
in lots of (downstream) modules that use:
  snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);

Signed-off-by: Martin Sperl <[email protected]>
Signed-off-by: Mark Brown <[email protected]>
@clivem
Copy link

clivem commented Apr 25, 2016

@msperl Please can you add a quick hack patch to clock manager to only allow use of OSC and PLLD and I will test again.

Forget about trying to cat anything from debugfs, system is foobar. USB gone, SDCARD gone!!!! I'm left with this on the screen of serial console on a Pi2B.

[ 197.902760] mmc0: timeout waiting for hardware interrupt.
[ 197.931874] [8933ec5e] FCM> bca54834 0
[ 197.946087] [8933ecdb] CMD 19 200
[ 197.959193] [8933ed15] REQ> bca54834 0
[ 197.971714] [09358fe1] DMA< bca548f8 0
[ 197.984547] [09359064] DMA 99 10801
[ 200.458698] [0935917d] FDA< bca54834 0
[ 202.978264] [0935923e] TCM< bca548f8 0
[ 205.249962] [093592dc] CMD< c 0
[ 207.341919] [09359480] TCM> bca548f8 0
[ 209.049010] INFO: rcu_sched detected stalls on CPUs/tasks:
[ 209.050836] 0-...: (1 GPs behind) idle=777/140000000000002/0 softirq=4776/4776 fqs=1373
[ 209.051537](detected by 2, t=6304 jiffies, g=3143, c=3142, q=147)
[ 209.051995] Task dump for CPU 0:
[ 209.052646] kworker/u8:1 R running 0 78 2 0x00000002
[ 209.107529] Workqueue: phy0 ieee80211_scan_work [mac80211]
[ 226.866166] [093594b6] FDA> bca54834 bca548c4
[ 229.795524] [093594e9] DMA> 0 0
[ 232.594755] [09359e8b] IRQ< 400 0
[ 235.416595] [09359eb4] IRQB bca548c4 400
[ 238.351456] [09359ed8] FCM< bca54834 bca548c4
[ 241.311103] [09359f5f] RSP c00 0
[ 244.349641] [09359fff] FCM> bca54834 bca548c4
[ 247.267096] [0935a046] IRQ> 0 0
[ 250.091178] [0935a249] TSK< bca54834 0
[ 252.943149] [0935a519] TSK> bca54834 0
[ 255.729910] [c935b53b] REQ< bc139cc8 10801
[ 258.565930] [c935b587] CMD< d 70000
[ 261.398968] [c935b65e] FCM< bc139cc8 bc139d14
[ 264.274840] [c935b7df] RSP 900 0
[ 267.236973] [c935b8ff] FCM> bc139cc8 0
[ 270.196124] [c935b950] CMD d 0
[ 272.097062] INFO: rcu_sched detected stalls on CPUs/tasks:
[ 272.098559] 0-...: (1 GPs behind) idle=777/140000000000002/0

@msperl
Copy link
Contributor Author

msperl commented Apr 25, 2016

I fear I guess what it could be...

Are you removing the driver or something? Switching clocks?

I have seen something similar (minus the display dump) when loading the uart as a module...

It may take me some time to get a quick working hack...

Actually I got a hack, but it is not worth it - something that I had reported upstream earlier about the clock framework seems to bite us again...

Essentially we have no "customer" for the parent PLLs initially:

root@raspcm:~# head /sys/kernel/debug/clk/pll*_per/clk_enable_count
==> /sys/kernel/debug/clk/plla_per/clk_enable_count <==
0

==> /sys/kernel/debug/clk/pllc_per/clk_enable_count <==
0

==> /sys/kernel/debug/clk/plld_per/clk_enable_count <==
0

When we use any of those clocks as parent, then the clk_enable_count increases.
But when we release the clock, then the clk_enable_count decreases and the pll gets disabled.
This really should not happen!

@anholt : I had submitted a patch for that, but you turned that down because it interfered with something. So what is the solution we want to go with?

As a workaround I guess I could set up the clock for the uart correctly - then that pll clock_count would be at least 1...

As for the quick hack to limit to use xosc only:

diff --git a/drivers/clk/bcm/clk-bcm2835.c b/drivers/clk/bcm/clk-bcm2835.c
index 35f8de7..ca47828 100644
--- a/drivers/clk/bcm/clk-bcm2835.c
+++ b/drivers/clk/bcm/clk-bcm2835.c
@@ -1313,12 +1313,12 @@ static const char *const bcm2835_clock_osc_parents[] = {
 static const char *const bcm2835_clock_per_parents[] = {
        "gnd",
        "xosc",
-       "testdebug0",
-       "testdebug1",
-       "plla_per",
-       "pllc_per",
-       "plld_per",
-       "pllh_aux",
+       "testdebug0_ignore",
+       "testdebug1_ignore",
+       "plla_per_ignore",
+       "pllc_per_ignore",
+       "plld_per_ignore",
+       "pllh_aux_ignore",
 };

 #define REGISTER_PER_CLK(...)  REGISTER_CLK(                           \

This adds 24 bit support to the I2S driver of the BCM2835

Code ported from bcm2708-i2s driver in Raspberry Pi tree.

Signed-off-by: Florian Meier <[email protected]>
Signed-off-by: Matthias Reichl <[email protected]>
Signed-off-by: Martin Sperl <[email protected]>
We only need to enable the clock if we are a clock master.

Code ported from bcm2708-i2s driver in Raspberry Pi tree.
Original work by Zoltan Szenczi.

Signed-off-by: Matthias Reichl <[email protected]>
Signed-off-by: Martin Sperl <[email protected]>
@clivem
Copy link

clivem commented Apr 25, 2016

@msperl Quick update..... LOL. I'll take the "dirty" hack until you and Eric come up with a solution and bring PLL's back into play. Who cares whether the music plays back at the wrong speed! (Just kidding....) Lock-ups, and having to re-image trashed SDCARD's are a thing of the past! ;)

Obviously, I never had an issue with any board that was running master for bit clock and frame clock with the new code, like the Digi and the Takazine. (They aren't enabling/preparing clocks). That's one box that can be ticked. As for slave mode, with Pi as clock master, progress is progress! Good job Martin!

I'd suggest that as much as we might want to get other people involved with testing, Phil doesn't pull the i2s-backport into a "next" branch until you have a solution for getting PLL clock(s) back into the the selection process, without any negative consequences. Just get the dma-backport pull into a "next" branch for now........

@clivem
Copy link

clivem commented Apr 25, 2016

Couple of thoughts....

Revert "bcm2835-i2s: Enable MMAP support via a DT property"

Probably want to revert the dt parts as well as code.

rpi-kernel-msperl-i2s-backport-clock-v2-waiting-for-upstream-0004a-Revert-bcm2835-i2s-Enable-MMAP-support-via-a-DT-prop.txt

@clivem
Copy link

clivem commented Apr 25, 2016

And, if you have to work on clk code, and not too much trouble, any chance you can add a dev_dbg in clock selection to show, requested_freq, actual_freq, clk_src, divi, divf, and mash. Similar to what I have kludged into old i2s driver clock selection code, so when I compare side by side, old to new, with 2 players in sync group and tailing the journals on both, I can see exactly what I'm getting old vs new, with regard to clocks.....

Apr 26 00:41:10 IQPlus3B1 kernel: bcm2835-i2s 3f203000.i2s: bcm2835_i2s_hw_params: clk_src=PLLD, clock_freq=500000000, target_freq=2822400, sampling_rate=44100, bclk_ratio=64, mash=3, divi=177, divf=631.

@clivem
Copy link

clivem commented Apr 26, 2016

@msperl Am I not allowed a divi of 1 with OSC? I'm requesting 19M2. (192k x bclk_ratio=100). Music playing at half speed, so figure I'm getting divi=2. Not possible to use OSC for PCM clk without a divider>1?

Using 19M2 OSC with INT and FRAC divisors...
*frequency=32000, bclk_ratio=32, req_clk=1024000, actual_clk=1024000
*frequency=32000, bclk_ratio=50, req_clk=1600000, actual_clk=1600000
*frequency=32000, bclk_ratio=64, req_clk=2048000, actual_clk=2048000
*frequency=32000, bclk_ratio=100, req_clk=3200000, actual_clk=3200000
*frequency=44100, bclk_ratio=32, req_clk=1411200, actual_clk=1411197
*frequency=44100, bclk_ratio=64, req_clk=2822400, actual_clk=2822394
*frequency=48000, bclk_ratio=32, req_clk=1536000, actual_clk=1536000
*frequency=48000, bclk_ratio=50, req_clk=2400000, actual_clk=2400000
*frequency=48000, bclk_ratio=64, req_clk=3072000, actual_clk=3072000
*frequency=48000, bclk_ratio=100, req_clk=4800000, actual_clk=4800000
*frequency=88200, bclk_ratio=32, req_clk=2822400, actual_clk=2822394
*frequency=88200, bclk_ratio=64, req_clk=5644800, actual_clk=5644788
*frequency=96000, bclk_ratio=32, req_clk=3072000, actual_clk=3072000
*frequency=96000, bclk_ratio=50, req_clk=4800000, actual_clk=4800000
*frequency=96000, bclk_ratio=64, req_clk=6144000, actual_clk=6144000
*frequency=96000, bclk_ratio=100, req_clk=9600000, actual_clk=9600000
*frequency=176400, bclk_ratio=32, req_clk=5644800, actual_clk=5644788
!frequency=176400, bclk_ratio=64, req_clk=11289600, actual_clk=9600000
*frequency=192000, bclk_ratio=32, req_clk=6144000, actual_clk=6144000
*frequency=192000, bclk_ratio=50, req_clk=9600000, actual_clk=9600000
!frequency=192000, bclk_ratio=64, req_clk=12288000, actual_clk=9600000
!frequency=192000, bclk_ratio=100, req_clk=19200000, actual_clk=9600000

@msperl
Copy link
Contributor Author

msperl commented Apr 26, 2016

@clivem until we fix the count issue you can always enable KMS, which claims some clocks and does not release them - pll never gets stopped.

There exists a patch to expose the parent name, but it did not get accepted (as it is assumed to be too much information - I guess). The reginfo still gives you all (but encoded) - and fortunately this got accepted...

As for divider of < 2 the clock hw does not support that for any clock with mash support (this was actually a point discussed in the long original thread) - similarly the max clock divider has to be <= max integer clock divider (not max fractional clock divider).

@msperl
Copy link
Contributor Author

msperl commented Apr 26, 2016

So here a separate branch that avoids the clock issues:
https://github.com/msperl/linux-rpi/commits/i2s-backport-clock-v2-avoid-clockissue
and exposes the parent clock, divider and mash (mash 1 is used anyway - see the mixed results when using a Hifiberry DAC using distinct mashes that make it hard to decide when to use mash and when not) via debugfs

@msperl
Copy link
Contributor Author

msperl commented Apr 26, 2016

I got a patch that makes use of CLK_IS_CRITICAL (which had to get cherry-picked as well):
https://github.com/msperl/linux-rpi/commits/i2s-backport-clock-v2-critical_pll

Now the issue of the freeze as soon as the clock is released has gone in my testing.

If you want to avoid the pllc then - as mentioned above - you can add a "ignore" to the "pllc_per" string.
This still needs a better solution, but works for now - a email asking how to solve this correctly has been sent, but no feedback yet...

@clivem
Copy link

clivem commented Apr 26, 2016

until we fix the count issue you can always enable KMS, which claims some clocks and does not release them - pll never gets stopped.

@msperl I need to think very carefully about how I put this, as tact isn't one of my qualities..... ;) There are/were several PITA issues with vc4, not least that it doesn't play nice, having enabled it, with a headless boot and not having HDMI connected...... Which makes enabling it a non-starter on the multiple units in my test "farm". Of course, they are all headless.

I'll take a look and rebuild kernels with CRITICAL patch when I finish typing this.

@msperl
Copy link
Contributor Author

msperl commented Apr 26, 2016

Well - see the critical patch - that works without KMS - at least for me.

I have to admit: I have - for now - got a hdmi display connected, but that only came of the requirement to test KMS more than anything else (and it sometimes gives me serial headaches...)

@clivem
Copy link

clivem commented Apr 26, 2016

Well - see the critical patch - that works without KMS - at least for me.

@msperl I've left the PLL's "in play", haven't added a patch to ignore them.

I haven't done much testing yet, but have upgraded 10x units to this new build with CRITICAL clock patches and left them looping through a sample rate test playlist. One is connected to amp at moment, (a Pi3B with IQAudIO Zero DAC attached, so slave and using Pi clock, selection via clock manager). Gordon will be pleased to hear that all sample rates working (32k,44k1,48k,88k2,96k,176k4, & 192k) and playing back at correct speed! ;)

@msperl
Copy link
Contributor Author

msperl commented Apr 26, 2016

So I have uploaded an almost complete changeset for the clock migration now.
see the https://github.com/msperl/linux-rpi/commits/i2s-backport-clock-v2-critical_pll

The only thing not really tested is:

  • spi1/2 - too lazy to create the corresponding overlays to make it work
  • pwm - no idea how I can test that
  • sdhost - there exists an overlay for sdhost, but that does not change the MUX of GPIO48 to 53 to ALT0

Note that I had to backport(cherry-pick) the upstream aux-uart driver to make everything work fine.

The only thing that remains is SMI, which does run its own clock manager, but that should be very easy to change - I can propose a change, but I can not easily test it...

@clivem
Copy link

clivem commented Apr 26, 2016

These latest patches.... Nothing to do with I2S, just migrating other subsystems to use clock framework, right?

@msperl
Copy link
Contributor Author

msperl commented Apr 26, 2016

That is right, but that is what is needed to make everything work with the clockmanager.

@clivem
Copy link

clivem commented Apr 26, 2016

That is right, but that is what is needed to make everything work with the clockmanager.

Just figuring out whether I needed to rebase straight away or not. (I'm halfway through testing every sample rate, at every possible bit depth/bclk_ratio possible with their downstream drivers, with 6 different I2S "slave" DAC's.)

@clivem
Copy link

clivem commented May 5, 2016

unfortunately this approach of yours can never work

@msperl It was FYI, was not expecting you to use it as a blueprint, just showing you what I have been doing, prior to the upstream backport.

But there are 2 things to argument this:

Or simply, don't even try to argue this with upstream and have a downstream patch. ;)

64bit@48k has the same frequency as 32bit@96k - as there is no means to differentiate between those 2 use-case... Is this a valid assumption?

From a user point of view, (from the feedback I had), when choosing which noise shaping to apply, there is no need to differentiate on anything but parent clock. Doesn't matter which numbers (sample freq and frame size) we multiplied to get to a final frequency..... If PLLD is the parent, use MASH3.

I hold my hands up and admit that in a blind test I couldn't tell any audible difference between MASH1/2/3. (Earlier patches of mine allowed choosing specific clock parent/div/mash for each target_frequency, but in the end, the consensus was that if using MASH2 for any clock freq with PLLD, you would want to prefer it for any freq generated with PLLD as the clock parent. So I don't really see a need for it to be very fine grained...... Avoid a config nightmare at the expense of flexibility.)

@msperl
Copy link
Contributor Author

msperl commented May 5, 2016

@clivem : look at the measurements and the Fouriers i have calculated where I tested all variations coming to very inconsistent results - at least for the Hifiberry DAC - and there it showed that the settings needed to be different for each to get the best Signal/noise.

@clivem
Copy link

clivem commented May 5, 2016

@msperl Yes, I looked at your measurements. I try to have one foot in the objective and the other in the subjective. The thing is, that the die-hard audiphools interested in "playing with" MASH settings at the moment, aren't looking at FFT and scope traces. ;)

@msperl
Copy link
Contributor Author

msperl commented May 6, 2016

@pelwell @popcornmix : I got a patch that currently disables pllc_per usage - the question is:
for other VPU-clocks we stil have those pllc clocks enabled for parent clock selection:

  • BCM2835_VPU_PARENT_PLLC_CORE0
  • BCM2835_VPU_PARENT_PLLC_CORE1
  • BCM2835_VPU_PARENT_PLLC_CORE2

Should these also be disabled for vpu clocks during automatic parent-clock selection?
Maybe there are other policies for those clocks you want to enforce?

Note that we have the following clocks that are (known) VPU clocks (and their default parent configured the firmware with the corresponding frequencies):

  • H264 - enabled - plla_core - 249799997Hz
  • ISP - enabled - plla_core - 249799997Hz
  • SDRAM - disabled - plld_core - 166533331Hz
  • V3D - enabled - plla_core - 249799997Hz
  • VPU - enabled - pllc_core - 249799997Hz

These clocks are not typically set from the kernel, so it may not be necessary to filter those.

Note that for PER clocks we have eMMC clock also set to use pllc_per set by the firmware!

@HiassofT
Copy link
Contributor

HiassofT commented May 6, 2016

It would be great if someone with proper test equipment (Audio Precision, Prism, ... gear) could do some SNR and THD performance tests comparing mash and oscillator settings.

@iqaudio @bonezuk @hifiberry @clivem do you have access to such equipment?

The tests @msperl and I performed are most certainly meaningless if not completely flawed.

Clock/jitter issues should show up as spurs in the FFT and typically a 5-15dB performance drop in SNR (eg 90dB SNR instead of 100dB), but neither my M-Audio card nor the Red Pitaya with it's 14bit ADC have the specs to reveal such things.

The spurs I saw in my FFTs quite certainly came from the oscillator of my M-Audio card and not the DUT...

@msperl
Copy link
Contributor Author

msperl commented May 13, 2016

Status update: there are still discussions arround the clock interface.
Essentially it looks as if we have a problem with the sdram clock that is (in parts) responsible for the "crashes" when the plld_core0 clock gets disabled either by PCM or by UART (when the AMA0 uart is not used as the boot console), when the corresponding clock gets disabled.

So there are still discussions going back and forth arround this.

@msperl
Copy link
Contributor Author

msperl commented May 13, 2016

On a different front I tried to upstream the HifiBerry DAC driver and qot asked why (besides one glitch) we would not be using snd-soc-simple-card instead and configure that in the device-tree alone.

There it became apparent that the setting of BLCK is not implemented in that driver - the one just multiplying by 2.

So I am thinking now of patching that driver to get this fixed and at the same time we can also try something that would allow us to generically set the blck size and others in a generic way, so that bclk sizes of 40, 50, 80 or 100 can easily get selected - maybe also parent clocks or other parameters (but that would require some more changes to the clock core framework...

Here one idea that I have:

sound {
  compatible = "simple-audio-card";
  simple-audio-card,name = "HifiBerry DAC";
...
  /* for 32bit@48k set bclk size to 40bit/channel = 80bits effectively */
  hw-params-filter@0 {
    match-rate = <48000>;
    match-sample-bits = <32>;
    match-channels = <2>;
    action = "set-fixed-bclk-ratio";
    action-value = <40>;
  };

  /* for 16bit@96k set bclk size to 20bit/channel = 40bits effectively */
  hw-params-filter@1 {
    match-rate = <96000>;
    match-sample-bits = <16>;
    match-channels = <2>;
    action = "set-fixed-bclk-ratio";
    action-value = <40>;
  };
  /* for all others take the multiple of sample_bits times channel */
  hw-params-filter@999 {
    action = "set-bclk-ratio-multiple-sample-bits-channels";
  };
};

Other actions could also be possible that might set some specific extra
flags that would modify the clock to allow mash to get controlled in
a fine grained way by creating another option flag to get set.

Might something like this work for your cards or help in any way?

This would be based on simple-sound-card though...

@clivem
Copy link

clivem commented May 13, 2016

This was the "kludge" I was using last week...... although setting custom bclk_ratio from bcm2835-i2s rather than simple sound card. (I have major misgivings about using simple-card for anything but simple. ie. slave, with simple codec. It's meant to be simple right? Which is fine for berry_dac/pcm5102a combo, but not really workable where you actually do need a bunch of "glue" in the card driver, IMHO.)

https://gist.github.com/clivem/0670a2f43e36e9c54c22ca2b90de6dd7

@clivem
Copy link

clivem commented May 13, 2016

On a different front I tried to upstream the HifiBerry DAC driver and qot asked why

@msperl Where can I find this conversation? ALSA mailing list archive?

@msperl
Copy link
Contributor Author

msperl commented May 14, 2016

@clivem rpi list plus alsa
Subject: [PATCH 0/2] ASoC: bcm2835: add support for hifiberry-dac

@clivem
Copy link

clivem commented May 15, 2016

@msperl Martin, what you were talking about, adding set_bclk func from simple-card.... Is this something you have already started doing?

would something like this be a possibility:

sound {
compatible = "simple-audio-card";
simple-audio-card,name = "HifiBerry DAC";
...
/* for 32bit@48k set bclk size to 40bit/channel = 80bits effectively */
hw-params-filter@0 {
match-rate = <48000>;
match-sample-bits = <32>;
match-channels = <2>;
action = "set-fixed-bclk-ratio";
action-value = <40>;
};

@msperl
Copy link
Contributor Author

msperl commented May 15, 2016

Something along these lines: yes!
Maybe also a means to select the clock parent and flags - this may require changes to alsa and the clock framework... And other stuff that one could do inside the set_hw_param method.

I guess this could even be a generic method that could get used by other drivers as well...
Possibly also with a means to have some custom code per 'target'.

There must be other things to do for other drivers as well - enabling a certain clock or others...

@clivem
Copy link

clivem commented May 15, 2016

@msperl I thought I was going to have a few hours this afternoon to write some code, but I'm not. I do agree with trying to do as much as this type of thing from dt as possible, and having generic "card" drivers, whether that be simple-card from upstream or some other driver in downstream sound/soc/bcm ONLY, but I guess it depends what you can get Broonie to go along with. ;)

I'm still playing with simple-card and that "kludge" to bcm2835-i2s for integer bclk divider preference..
My latest patch on top of your is2/dma backport and my 384k and ES9023 patchsets....
https://gist.github.com/clivem/9d1da750f666dc1d1ede4df761079742

If you do implement the set_blck_ratio from simple-card dt before I even get a chance to think about it some more, I'd like to know and whether it is accepted upstream or not, I'd test it. It could be very helpful with the stuff I'm still thinking through, to get my head around trying to rationalise the downstream driver situation, for what is effectively the same hardware...... But after a discussion with a new manufacturer, that I suspect is going to have a very popular DAC HAT board within a short space of time, this is really starting to feel like herding cats..... They have zero interest in upstreaming code, (whether that be via RPi github or mainline), they just want to do "deals" in private to make sure their board is supported with a driver in 2 of the more popular Pi audio distributions, which is where they see the market for their boards, rather than the mainstream, and wanting support in Raspbian, Arch, etc. etc.. This sort of crap thinking needs to stop. It's just making things harder! Of course, the distribution sees a benefit to their popularity by "exclusively" supporting a card. I suspect users are going to be peed off, at the point an upstream/downstream ASoC or i2s change breaks audio playback on that card, the driver not having been upstreamed.....

@msperl
Copy link
Contributor Author

msperl commented May 15, 2016

@clivem: do you have a basic config for simple card that I could use for my HifiBerry DAC?
then I could take that as a basis...

I have thougth about this a bit more and have come up with a slight variation that may allow more "flexibility":

hw-params-filter@0 {
  match-rate = <48000>;
  match-sample-bits = <32>;
  match-channels = <2>;
  action@0 {
    method = "snd_hw_params_action_set_fixed_bclk_ratio";
    arg = <40>;
  };
};

Where "snd_hw_params_action_set_fixed_bclk_ratio" would be a method that would get used.

The idea is to use dynamic linking for this, so that the method argument would be the method called
without any extra coding - new drivers/modules could just (GPL) export such methods and it would become available in the configs...

Unfortunately we are unable to do static argument checking in those cases, but people may think of something...

I still have some doubts about how to handle arguments in a flexible manner - parsing the DT every time we run the actions is probably not acceptable...

Would u32 be sufficient or would we need to support something else as well?

What are other candidate things we may need?

Anyway: this should go to a separate thread...

@msperl
Copy link
Contributor Author

msperl commented May 15, 2016

@clivem : not upstreaming and requirements could get easily get controlled by the maintainer of the relevant kernel - if they do not accept such patches, then those vendors would need to do the extra work, as otherwise they would need to maintain their own kernel...
But that depends on the "corresponding" people responsible...

@clivem
Copy link

clivem commented May 15, 2016

do you have a basic config for simple card that I could use for my HifiBerry DAC?

It is in the gist above, the simple-pcm5102a-dac config, assuming you are actually talking about the HB DAC (PCM5102) and not the HB DAC+ (PCM5122). The HB DAC+ needs to keep it's own card driver, because of the clock master option and the way they have implemented that. (That's what I'm using right now with HB first gen PCM5102 DAC on a PiB and Pimoroni PHAT DAC on Zero.)

If you want the 384k support, you'll also need to grab 2 of the 384k patches.....

ebbb254 and f7025d9

Actually, another conversation later, and again I'm not sure that trying to "shoehorn" everything we need into simple-card is the way to go.....

@clivem
Copy link

clivem commented May 15, 2016

not upstreaming and requirements could get easily get controlled by the maintainer of the relevant kernel - if they do not accept such patches, then those vendors would need to do the extra work, as otherwise they would need to maintain their own kernel...

LOL. Some of the people (that we are actually talking about here) make me look like a professional! They barely know how to apply a patch, let alone maintain a driver and how the ASoC components "glue" together.....

@msperl
Copy link
Contributor Author

msperl commented May 15, 2016

as for the patches: why not enable the 384 modes by default and configure them instead in the DT?
Does it require specific IC versions to support that?

If so then a different compatiblity string is the "better" approach...

@clivem
Copy link

clivem commented May 15, 2016

as for the patches: why not enable the 384 modes by default and configure them instead in the DT?

The problem with enabling 384k for default with pcm5102a codec is that HB is using it for both PCM5102 (original PCM5102 DAC) and DAC+ Light with (ES9023).
Although it is possible to have ES9023 work @ 384k, not every chip can do it, datasheet max is 192k and every manu uses a different MHz OSC, which also factors into it. I already tried to move HB off of hifiberry_dac/pcm5102a combo for their ES9023 boards, (which was half the point of the es9023 stuff I did), but as noted in my commit msg, Daniel wants to carry on using it (hifiberry_dac/pcm5102a driver combo and single hifiberry-dac overlay) for both boards. Yes, pcm5102a codec should be 384k enabled by default, The reason it cannot be is a synthetic one, because of HB use of it for both PCM5102 and ES9023.

There is a lot more going on here, than appears from the surface. Gordon (IQAudIO) on our phone call yesterday, has backed me and my judgement, even if that means he gives up an IQ specific card driver for his stuff and using a generic. I hope to speak to Daniel (on phone) this coming week.

The splitting out of pcm5102 and es9023, (which has always been a piggyback on pcm5102 and not just by HB, there are 3 other board ES9023 board manu's also doing this approach), is the first stumbling block. Anyway, can we just leave that alone for the moment and concentrate on how we get the custom bclk ratio into the bcm2835-i2s driver. The ES9023 really does benefit from that. It's not important for the TI chips anyway. Once we have a way to set it, and I don't care about the how..... via a dedicated card driver, bcm2835-i2s dt prop, or simple-card dt.... Don't care whether it is upstream or downstream. I am concerned that implementing anything when it involves upstream takes too long. Your back and forth with Eric about CRITICAL/HAND_OFF for clocks, (and it still isn't concluded??????), kind of proves the point. We could have had a working backport dma/i2s impl getting tested already in a downstream next branch. It now seems that moving forward on that, is waiting on upstream "co-operation" and decision making process.

And this whole thing makes me laugh. There are no card drivers upstream. No-one is using upstream for Pi and I2S DAC. Get stuff working downstream, refine and hone it before submitting it upstream. If you want to get any testing done, that's what you need to do. Only a couple of devs and their dog are running upstream kernel builds on the Pi. ;) Waiting for upstream approval, and getting things in there, before using them downstream, is just going to result in more and more people trying to do things outside of the process...... Like these new manufacturers being more bothered about distributions providing drivers, rather than first priority being to at least get them into Pi git and the distribs getting them from there, as part of a "standard" Pi kernel.

Anyway, not a criticism. I appreciate your time and effort. Just being as blunt as I usually am and stating an opinion, even if it is controversial.

@msperl
Copy link
Contributor Author

msperl commented May 20, 2016

note: current status is that:

  • all i2s patches have been up-streamed and is in the master branch
  • dma-patches are also in

For some reason the clock patches have not made it (yet) into the kernel

On another note: it seems now to be identified that SD-Ram is using the PLLD_CORE0 clock, so
we need to handle that (and assign ownership of that clock, so that it can not get disabled by another driver when releasing a clock).

For that exists a new SDRam driver that primarily owns and enables those clocks and does nothing more.

But to make it complete (and avoid other pitfalls where a different driver mai claim and enable a clock and then disable it again) this will require also that we start both the clock and sdram driver early during the boot-process - using core_initcall or maybe even early_initcall...

Incidentally this also does away with all those warnings about not found clocks during boot as well...

@clivem
Copy link

clivem commented May 24, 2016

@msperl Martin, I'm a little confused having looked at the most recent pull from Anholt into rpi-4.4.y....
Specifically, #1472
I thought both CRITICAL and HAND_OFF were an issue with upstream? Anyway, has this dealt with "our" clockmgr issues as well, of a) not using PLLC as a parent and b) reference count decrease causing clocks to be disabled, that need to be enabled for firmware?

@msperl
Copy link
Contributor Author

msperl commented May 24, 2016

@anholt applied some patches that went in upstream - but these do not solve all the issues with regards to plld-clocks - especially CPU uses pllc while plld-per is the one that the sdram really uses.

There are instead some patch sets out that:

  • claim the sdram clocks (making them critical implicitly)
  • initialize the clock and sdram drivers much earlier during boot - but there has not any comments on those yet.

@clivem
Copy link

clivem commented May 24, 2016

...... but there has not any comments on those yet

Can we not just ask Phil to pull your "upstream not accepted" branch into the "next" tree he setup? It works! We know it works! At the point your few "not accepted patches" can be replaced with mechanisms upstream has accepted, they can be reverted downstream in favour of the new mechanism. It feels as if we have hit a roadblock with clkmgr. We need to move forward. IMHO, (having put terrabyte upon terrabyte of data through it), the dma code is GOOD to go! The I2S code is GOOD to go! This clkmgr stuff, (and waiting for upstream to decide a solution is acceptable, when fully working proposals have already been thrown into the bit bucket), has already delayed moving this forward to a wider audience for several weeks.

@pelwell
Copy link
Contributor

pelwell commented May 24, 2016

There's been a lot of back-and-forth, so I'm just waiting for a consensus and the nod before updating next.

@msperl
Copy link
Contributor Author

msperl commented May 24, 2016

well - as mentioned: most of my "crashes" are related to plld_core0 (and possibly the sdram clock SDRAM), which is used by the SDRAM controller.

The patchset by Eric (#1472) does not address this - hence the sdram driver that has not seen any acceptance or similar - this should solve most of the "issues" with regards to crashes - every thing else (or mostly) is patches that are related to re configuring the device-tree to use the new clock system.

@msperl
Copy link
Contributor Author

msperl commented May 24, 2016

I guess I will review the changes in recent kernels and look into how I may rebase the patchset with everything that went in already...

@mi-hol
Copy link

mi-hol commented Nov 8, 2016

@msperl @pelwell
Is this issue still active or should it be closed as superseded?

@clivem
Copy link

clivem commented Nov 8, 2016

= rpi-4.7.y already includes dma/I2S/clockmgr. rpi-4.4.y contains dma backport. My rpi-4.4.y-simple tree, which is mostly used by the DIY audio guys, adds I2S and clockmgr backports on top of rpi-4.4.y. Anyway, this PR needs to be closed, IMHO.

@Ruffio
Copy link

Ruffio commented Dec 6, 2016

@msperl @pelwell
Is this issue still active or should it be closed as superseded?

@msperl msperl closed this Jan 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants