#
…

2021-10-29

00:13amw has joined #asahi-dev
01:31user982492 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
01:47psykose has quit [Remote host closed the connection]
01:48psykose has joined #asahi-dev
02:07phiologe has joined #asahi-dev
02:08marcanjmr2: linux.py is unaffected by the DT selection thing, it assumes you know what you're doing
02:08marcanwhat does the filtering is payload mode
02:10user982492 has joined #asahi-dev
02:10PhilippvK has quit [Ping timeout: 480 seconds]
02:32rkt has joined #asahi-dev
02:41jmr2 has joined #asahi-dev
02:41jmr2Got it. Thanks.
02:42jmr2 has quit []
02:43marcan has left #asahi-dev [#asahi-dev]
02:43marcan has joined #asahi-dev
02:53rkt has quit [Quit: rkt]
03:24rkt has joined #asahi-dev
03:54kov has quit [Quit: Coyote finally caught me]
03:54kov has joined #asahi-dev
04:16rkt has quit [Quit: rkt]
04:27rkt has joined #asahi-dev
04:30rkt has left #asahi-dev [#asahi-dev]
04:47rohin2 has joined #asahi-dev
05:19rohin2 has quit [Ping timeout: 480 seconds]
05:35kenzie has quit [Quit: Ping timeout (120 seconds)]
05:36kenzie has joined #asahi-dev
06:29rkt has joined #asahi-dev
06:40rkt is now known as Guest4338
06:40rkt_ has joined #asahi-dev
06:40rkt_ is now known as rkt
06:45Guest4338 has quit [Ping timeout: 480 seconds]
07:02chadmed has quit [Quit: Konversation terminated!]
07:03chadmed has joined #asahi-dev
07:29aleasto has joined #asahi-dev
08:42nsklaus has joined #asahi-dev
08:56rkt has quit [Quit: rkt]
09:12rkt has joined #asahi-dev
09:34user982492 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
09:42rkt has quit [Quit: rkt]
09:49rkt has joined #asahi-dev
09:52chadmed has quit [Quit: Konversation terminated!]
09:53chadmed has joined #asahi-dev
09:57povikso, about that NCO block on M1
09:57povikwe already know it provides audio clocks
09:58povikturns out macos writes to its ranges, it's just that they also resolve as error-handler[15] that i didn't notice the writes earlier
10:02poviknow i would like to know to relationship between the outputted frequency and the nco's registers
10:02poviki tried measuring and plotting the dependence but it didnt enlighten me
10:03povikon the contrary, i now am really curious what the dependence is, because that plot is nuts
10:03povikso if someone wanted to look up this information in a kext, i wouldnt be angry at all
10:07rkt has quit [Quit: rkt]
10:15rkt has joined #asahi-dev
10:19marcanpovik: do you have some numbers?
10:19poviksure, what you have in mind? addresses?
10:19marcannormally an NCO would be using some kind of accumulator design, followed by some kind of cleanup pass or something like that
10:19marcanI mean like register values vs frequency
10:19marcanwhatever you plotted
10:20povikgive me a sec
10:22marcanI see the setFrequency proto in the kext, but this is the kind of code I don't want to look at before trying to blackbox it
10:22marcanthis kind of stuff is easy to accidentally veer into copyright issues with
10:26marcanso it looks like we have 4 NCO clock inputs, 5 NCOs (selectable I guess?), and 6 MCA clock selects
10:26marcaninteresting fanout
10:29skipwich has quit [Quit: DISCONNECT]
10:29skipwich has joined #asahi-dev
10:31rkt has quit [Quit: rkt]
10:32marcanpovik: https://mrcn.st/p/I7B97zDA some clocktree notes (mostly not useful)
10:33marcangetting the feeling the iBoot clock numbers are kinda bullshit
10:33marcan(some of them anyway)
10:33rkt has joined #asahi-dev
10:35marcanhow did you measure the freq? dma frequency?
10:35povikmarcan: should i upload the plot somewhere also, or are you handy with gnuplot? :-)
10:35povikyeah, watching the dma data rate
10:35marcantbh I'm more interested in throwing this into python ;)
10:35marcanwhat's with the gaps?
10:35marcan859 2816.5058968377184
10:35marcan1118 47902.4243718684
10:36poviksee the comment at the top, it is over two arbitrary ranges
10:36povikand within the ranges there are gaps due to the frequency being too low
10:37poviksee the iboot value measures as
10:37povik1118 47902.4243718684
10:37marcanthat one should be exactly 48000 if they didn't screw it up
10:38marcanso I guess that's your error margin
10:38poviksure, it gives you an idea what's the measurement error
10:38poviki sped it up and increased the error margin for later values, this is one of them
10:40marcanso one thing to keep in mind is that if there is a PLL or similar cleanup pass after it, the other reg values might affect it and that might cause insanity for some ranges
10:40marcanbut let's see
10:43marcanthe value is definitely a bitfield
10:48povikgreat. i was trying to isolate some fields yesterday late in night but with no result
10:52marcanI'm getting the feeling this register is kind of interesting
10:55rkt has quit [Quit: rkt]
10:56marcanokay, this has to be a shift register of some sort
10:57marcanif you sort by frequency you get patterns like these: https://mrcn.st/p/O30FM5sz
10:57marcanpovik: ^
10:57marcanthe bottom two bits are some kind of finetune
10:57marcanand obviously there is measurement error
10:58marcanlet me see if I can look up some NCO designs
10:58povikinteresting
10:58povikthat NCO has some heritage, looking at compatible=
11:07marcanpovik: do you have your test script somewhere?
11:13rkt has joined #asahi-dev
11:45rkt has quit [Quit: rkt]
11:51rkt has joined #asahi-dev
11:53povikhad to clean up a bit, it depends on some m1n1.hw.admac changes
11:53povikmarcan: ^ experiments/mca_mark.py
11:53povikusage in comment at top
11:57poviki guess it is obvious to you how to reduce the error margin
11:58marcanpovik: I just figured out a way to get more accurate measurements
11:58povikdo tell
11:59marcanpovik: I just figured out a way to get more accurate measurements
11:59marcan47999.384773510596
11:59marcanI just use the countval from admac reports
11:59povikof course
11:59marcanthat's in clkref units
12:07svenmarcan: huh, weird w.r.t DAPF.
12:08svenbut at least the locked DART makes sense now. otherwise you could just switch the mapped firmware region to bypass-dapf i guess
12:10sveni wonder what those two weird bypass streams are now though
12:31vivg[m] has joined #asahi-dev
12:36marcanignore the third column, but the fourth column is the divider vs. the input clock
12:36marcanit's always in units of 0.5 and has an offset of 0.25 (set elsewhere?)
12:36marcanso the register values are kind of crazy but we are enumerating integer dividers of the refclk here after all
12:39marcanI wonder if...
12:39marcanmaybe this is an LFSR counter?
12:39marcanthat would make sense, it gives better timing
12:39marcanif so, then the question is what's the polynomial
12:46marcanokay, it's the wikipedia one, of course
12:46marcan11 bits, x^9 + x^5 + 1
12:46marcanplus a normal binary counter for the low bits
12:47marcanpovik: mystery solved; hardware engineers being clever
12:47marcanI think the other registers are fine tuning, doing the fractional part
12:47mikebeaton[m] has joined #asahi-dev
12:47marcanI'm not sure if there is an easy way of generating the LFSR value other than a table, though
12:47marcanI mean, the table is easy to generate
12:48marcanbut I don't know if there is a formula
12:55marcan0x1ffc 144176271.4194868
12:55marcan0x1bfc 219604.30389050167
12:56marcanso that's the rollover, at all 1s, and 0 is special (not normally valid in an LFSR)
12:59povikmarcan: great!
12:59poviki will look at this in detail later, but i am happy we have this figured out
13:00poviki volunteer adding this to m1n1
13:00povik(i mean, at least having dump_pmgr show it up)
13:04marcanthat calculates the lookup table and then computes the divider based on the reg value
13:04marcanmatches all of them fine
13:04marcanignore the last stuff, the div calculation is what matters
13:05marcanI'm not sure where the 4.25 thing comes from, probably other registers
13:06jixmarcan: you can use modular exponentiation by squaring to directly compute the n-th step of a lfsr, but for 11 bits I wouldn't bother
13:08mikebeaton[m] has quit [Quit: issued !quit command]
13:10jixwithout using carryless (i.e. polynomial over F_2) multiplication instructions (which I assume arm also has these days) it might even be slower than the naive approach for 11 bits
13:10marcanheh, yeah, table it is then
13:10jixwith those instruction it's probably faster than generating the table, but that's a lot of added complexity
13:11marcanthis is a kernel driver, not going to use NEON for this
13:15mazmarcan: kernel_neon_begin()/end(). the crypto code is full of it! :-)
13:15marcanyes but it feels very silly for this ;)
13:15mazI'm all for silly things, today...
13:20* rktis reviewing today’s chat log with a web brower
13:24marcanpovik: the next register is the fractional part, but it's also not just a straight thing
13:24marcanI think it's probably a delta for the accumulator or so
13:40marcanpovik, jix: want to take a crack at this relation for the NCO fractional part register? https://mrcn.st/p/8L7N8zW5
14:00marcanit's a weird S shape in a log plot
14:01jixfrac = 1 / (np.exp2(23.5 - np.log2(reg)) + 2) # is pretty close
14:02jixbut that's just eyeballed, so no idea if that's close enough for what it's used for
14:03jixoh and it's not close for the small values, I assumed they are noise because they jump all over the place in a log plot, but that might not be the case?
14:03marcanyes, the small ones are noisy
14:03marcanthere's error in the measurement
14:04chadmedis this lfsr used to derive the dac's sample rate? if so values not between 8000 and 384000 should never ever matter
14:06marcanmaybe, but there's no good reason to hardcode it when we know the formula
14:06marcanmagic numbers suck
14:07chadmedoh yeah for sure im just saying that noise causing inaccuracy in low values shouldnt be too much of an issue unless the hardware is doing double duty for something else
14:07marcanjix: I wonder how that comes about from the implementation...
14:07marcanchadmed: I mean the noise is just in my measurement
14:07jixmarcan: same, do you have a rough idea what it does?
14:08marcanit's supposed to be an NCO
14:08marcanwe know the half-integer part is that counter
14:08marcanI would expect further fractions to be the phase accumulator thing
14:08marcanbut this does not match what I expect from a phase accumulator
14:20marcanjix: 0.5 - 0.5 / ((reg / (2**22.5)) + 1) makes more sense
14:20marcan(equivalent)
14:20marcanthe sqrt(2) factor there bothers me
14:25marcanactually 22.6 matches even better
14:26jixmaybe 2**22.??? is just 0x600000 ?
14:27marcanit might just... yeah that
14:27marcanwhy a factor of 3 then though :D
14:30marcanahh wait
14:30marcanthe other registers are related
14:33jixalso 0x60a000 is even closer ... but it also seems to be off by a small factor
14:34marcan0xff9f5200 is -0x60ae00
14:34marcanwhich is another register
14:34marcanand yes it does that
14:35nsklaus has quit [Quit: Textual IRC Client: www.textualapp.com]
14:36nsklaus has joined #asahi-dev
14:38jixhmm not a small factor but a small offset... if you use 0x60ae00 and then add 2**(-13) at the end it's really close (but that offset might also be measurement error? no idea how you measure this)
14:39marcanthere may be some measurement error, or the other register is messing with things
14:40marcanjix: so basically (1 - 1 / (1 - (r1 / r2))) / 2
14:43jixor equivalently 1/2 * r1 / (r1 - r2)
14:43marcanyeah, I was about to say...
14:44marcanso it's just two periods
14:44marcanhow long to be +0.5 and how long not to
14:45jixcan you do the measurement over a longer interval or so to figure out if the 2**(-13) are just measurement error? I expect it to be... but a constant offset could also be plausible
14:45marcanpretty sure it's error
14:48rkt has quit [Quit: rkt]
14:50marcanok, so small values take a while to converge, which tells me these are accumulator increments indeed
14:52marcanso basically the logic would be a state flip-flop driving a mux that selects the increment register
14:53marcanyeah, so any time the top bit of the accumulator toggles, the flip-flop toggles
14:53marcanand the flip-frop drives an LSB's worth of divider
14:54marcanand that's all of the data registers then, reg0 is presumably control, might want to poke around the bits there at some point
14:55marcanso the first register is the increment for the ddiv = +0 state, and the second for the ddiv = +0.5 state
14:56marcanwhich means there's an inverse relationship, if r2 is 2*r1, then it spends half as long at 0.5, so the overall div is 0.16666
14:57marcanpovik: and this is how you reverse an NCO without looking at the kext
14:58marcanah wait, there was one more register
14:58marcannot sure what that one's about
15:00marcanmacos sets these to 0x5ad200 0xff9f5200 0x7f9f5200
15:00marcanmaybe the third one is just some initializer, perhaps it needs a control reg kick to set?
15:05marcanyes, that's what it is
15:06marcanso you have to stop the NCO first, clearing bit 31 of the control register
15:06brentr123[m]So hyped for the m1 pro stream
15:06marcanthen you write the config
15:06marcan00: ctl 04: div/lfsr 08: low-inc 0c: high-inc 10: init accumulator
15:06marcanthen you set bit 31 of the ctl reg and it goes off
15:06marcanthat way you can use small incs without having to wait for the accumulator to wrap back across the midpoint
15:07marcanthe midpoint is indeed 0x80000000
15:07marcanand top bit 1 means high div and use high-inc
15:08marcanso really that register can just always be set to 0x80000000 I guess, I have no idea why you'd bother with anything else?
15:08marcan(or 0x7fffffff)
15:10marcan>>> 5952000+6336000
15:10marcan12288000
15:10marcan>>> 48000 * 256
15:10marcan12288000
15:10jixI guess it's always a good idea to avoid small incs anyway... i.e. multiply them by the largest constant that still fits
15:10marcannah, see what xnu did there
15:10marcan(r1 - r2) == desired_freq
15:12marcanthat's gotta make sense mathematically
15:16jixwait is it doing a zigzag around the midpoint or is it always wrapping around in one direction? (or I guess you could do it either if the increment regs are as wide as the accumulator reg)
15:32marcanI actually suspect macos has some rounding error here...
15:32marcanhm, wait, no, that's too much
15:32marcanah, had it backwards
15:32marcanstill has some error though
15:38povikmarcan: re: this is how you reverse NCO -- 10/10, would give marcan puzzling data again
15:39povikfunny thing is yesterday i noticed the similarities in frequency of shifted bit patterns, in couple instances
15:39povikbut ruled that out as probably a meaningless coincidence
15:40povikand went on looking for fixed subfields in the registers
15:44marcanjix: yeah I don't know why they use fout as the sum of the params
15:49marcanso I measure 47999.3839 but I calculate that macos should be setting 48000.5586 and I don't know if that's measurement error or what
15:50marcanI'd *think* my timer and this thing would be frequency-locked to some extent, which is a bit weird
15:50marcanunless the input clock is a bit of a lie and not exact
15:51jixpretty strange to not set it exactly anyway
15:52marcanhttps://mrcn.st/p/w1wM9Yvh is my attempt at calculating the values
15:52marcan(high_inc needs to be negated in the register)
15:52jixwhat's fin?
15:53marcaninput freq
15:53jixno, what's the frequency
15:53marcan900000000, supposedly
15:54jixthat's quite high 0o
15:54marcanprobably why they used an LFSR divider ;)
15:57jixso this is used to adjust the fractional period of the lfsr divider? (just making sure I understand the whole chain here)
15:57marcanthe lfsr divider works in 0.5 units (half clocks I guess?)
15:57marcanand then this accumulator toggles between two adjacent dividers
15:59jixwhat d1/d2 values does mac os set this to?
16:00jix(shouldn't be a choice here AFAIUI, just wanting to make sure that I have everything right)
16:03marcanok, something's off
16:03marcanNCO1: #156: 900000000 0 0xa8/0x23b048000: nco: 0x80300000 0x45e 0x5ad200 0xff9f5200 0x7f9f5200 0x0
16:04marcanI get a divider of 4.50005766 with the flop one way, and 4.05639163 the other
16:04marcanthat doesn't look right
16:04marcan(for the highest freq)
16:05jixuh I think the math for the values you said mac os sets checks out? (also not quite following the last thing you said)
16:06marcandoes it?
16:06jixI get that it should set a fractional value of 31/64 and that's what 5952000 / (5952000 + 6336000) reduces to... except wait is it actually the right thing to do? it matches what mac os does but uh not sure
16:07marcanI'm probably doing the math wrong
16:08marcanalso I get better numbers with a div6
16:08marcanso I think that must just be a weird artifact of the lowest div
16:08marcan00000000 540858.4014394722 -0000001 6.50008392 0.000000
16:08marcan00000000 585929.9563842667 -0000001 6.00007725 0.000000
16:09marcanjix: I'm probably getting some 1/x relationships wrong
16:11jixI also totally don't trust that what I'm computing is the right thing, just that it ends up telling me mac os is setting 48k exactly
16:14jixhmm but no it should be fine I think... now let me try to do this the other way around to get from freq to incs
16:17marcanjix: ok, my interpretation of the dither was wrong
16:17marcanit's per output cycle, not input cycle
16:17marcanthat's where my error comes from
16:18jixah yeah, what I did was just to use high_inc and low_inc to directly match the fractional part of the divider period ... and that should check out if it's per output cycle as the formula for the fractional part already takes into account that the longer output cycles are longer
16:19marcanand yeah that works out to 48k from macos
16:24marcanyeah okay and that makes the math make sense
16:24marcan div = (2 * fin // fout)
16:24marcan low_inc = (2 * fin - div * fout)
16:24marcan high_inc = fout - low_inc
16:26marcanstill not sure where that measurement error comes from, but shrug
16:27marcanokay, I should *not* have let myself get nerdsniped with this today :S
16:27jixah and that's why the difference is fout... by scaling both values by fout you can use an integer division here, that also explains why they're not using a reduced fraction
16:27jixeh sum, not difference, well depends on how you view it ^^
16:43bps2 has quit [Ping timeout: 480 seconds]
16:44stzsch has quit [Remote host closed the connection]
17:02marcan(also, I just realized I messed up the polynomial earlier; it's x^11 + x^9 + 1)
17:03user982492 has joined #asahi-dev
17:06marcanpovik: so to do this "properly" in linux we need two clock drivers: one for the NCOs and one for the clocksels that go after them
17:16user982492 has quit [Quit: Textual IRC Client: www.textualapp.com]
17:22agraf has quit [Ping timeout: 480 seconds]
17:56gig has joined #asahi-dev
19:06povikmarcan: AFAIK the muxes that go after NCOs can remain in the state left by iboot
19:07povikso an option we can fabulate in our DT that the MCA blocks are connected to NCOs directly
19:08povik*so as an option,
19:18jeffmiw has joined #asahi-dev
19:22aleasto has quit [Remote host closed the connection]
20:07agraf has joined #asahi-dev
20:13agraf has quit [Quit: ZNC 1.7.2 - https://znc.in]
20:22X-Scale` has joined #asahi-dev
20:28agraf has joined #asahi-dev
20:28X-Scale has quit [Ping timeout: 480 seconds]
20:53jacoxon has joined #asahi-dev
21:20marcanwe could do that, yeah
22:30rohin2 has joined #asahi-dev
23:01bps2 has joined #asahi-dev
23:06jacoxon has quit []
23:26X-Scale has joined #asahi-dev
23:31X-Scale` has quit [Ping timeout: 480 seconds]
23:31doggkruse has joined #asahi-dev
23:47doggkruse has quit [Ping timeout: 480 seconds]
23:54rohin2 has quit [Ping timeout: 480 seconds]
…