#
…

2021-12-10

00:00jannauI haven't added the pins for t8103 but fixed the compatible string
00:01j`eycs_setup is only used if the spi core is in charge of the cs gpio
00:01jannauif cs is already configured as periph it should work
00:02j`eyoh hm, !spi->controller->set_cs_timing should be true actually?
00:02jannauno, also if the controller has no method to set the cs timing: !spi->controller->set_cs_timing
00:03j`eyyeah I missed that when i first read it, thought it was inside the if () {..
00:03yuyichao has quit [Ping timeout: 480 seconds]
00:04j`ey(I probably need to do more testing with linux.py, I always used hv)
00:05bps has quit [Ping timeout: 480 seconds]
00:08marcanjannau/j`ey: thanks for catching that!
00:08marcanyup, that was a dumb typo
00:09marcandid you not hit the WARN_ON(fifo_flags & APPLE_SPI_FIFO_TXOVERFLOW); ? I would expect that to fire with the bad code
00:09rwhitby has joined #asahi-dev
00:09bps has joined #asahi-dev
00:11marcaneither that or it would get stuck
00:11jannauI saw tx_overflow set in the spi trace I did not notice it in the kernel log but I was not really looking at it
00:12marcanit might be it was never making it out of the transfer loop
00:27j`eymarcan: I managed to see one packet from the keyboard at least, but then it gets stuck
00:39aidenfoxivey has joined #asahi-dev
01:17StupidYui has quit [Read error: Connection reset by peer]
01:30yuyichao has joined #asahi-dev
01:39rwhitby has quit [Quit: rwhitby]
03:12phiologe has joined #asahi-dev
03:16PhilippvK has quit [Ping timeout: 480 seconds]
06:10vx^ has quit [Ping timeout: 480 seconds]
06:10marcanj`ey: can you push that branch somewhere?
06:10marcanin principle we can run the HV in UP mode (or just filter out one CPU, might add an option for that) and then throw the gpiola on that one and see what linux does
06:14marcanah, saw the link
06:14marcanlet's see
06:18jannauI suppose j`ey was using something very similar to https://github.com/jannau/linux/tree/exp/spi-keyboard except for the random delays which fix it somewhat on bare metal
06:18marcandoes it not need those delays with the HV *even without* SPI tracing?
06:18marcanjust plain HV should have relatively little performance impact, mostly the timer IRQ spam
06:19jannaulet me test that
06:20jannauit's broken without spi tracing
06:21marcanalso oh god just looking at the diff context for that applespi.c makes me cringe
06:21marcansuch a mess of ACPI stuff mixed in there
06:21marcanwe definitely want to rewrite that as a HID transport properly (and someone else can add the bits to make it work with ACPI laptops too and then we can deprecate applespi in the future)
06:22marcanbut for now let's see if it breaks because of a driver problem or a SPI problem...
06:26jannautouchpad seems to need more delay than I currently have. broken both with bare metal and hv without tracing
06:27marcan[ 0.709687] applespi spi1.0: Received corrupted packet (crc mismatch)
06:27marcan[ 0.716454] applespi spi1.0: Unknown touchpad model 0 - falling back to MB8 touchpad
06:27marcanthat, right?
06:28jannauon applespi side it presents received spi data as 0x00
06:29jannaunot sure but I see those two messages with spi tracing and working touchpad
06:33marcanthat sounds like there's more than one problem
06:33kettenisthere are some packets that get sent early one that I haven't been able to give a meaning to
06:33marcanI seem to have working touchpad with that branch as-is
06:34marcanon the M1 Pro
06:34marcanHV, no tracing
06:34jannauincreasing SPI_END_CS_DELAY_US in applespi to 100 fixes the touchpad on baremetal
06:34marcankeyboard too
06:35jannaucaps lock led still breaks it but that ought to be an applespi problem
06:36jannaukeyboard seems to be more reliable
06:37marcanlet me actually try the touchpad (I was just catting the device)
06:37marcanhow does it break for you?
06:40marcanseems to work for me
06:41marcanahh xorg broke it
06:41marcan[ 14.081273] applespi spi1.0: Received corrupted packet (invalid message length 8 - num-fingers 0, tp-len 48)
06:41marcan[ 14.089493] applespi spi1.0: Received corrupted packet (invalid message length 8 - num-fingers 0, tp-len 48)
06:41marcanworked with gpm though
06:42marcankeyboard does work though
06:42marcanwhich is weird, being the same device...
06:44marcanbut even tracing spi after the error happens doesn't fix it
06:51kettenisbtw, how did you determine the input clock for the spi controller?
06:51jannauthe spi device might be a multiplexer with distinct keyboard and touchpad sub devices
06:51kettenisjannau: almost certainly the case
06:55marcankettenis: ADT tells us (see dump_pmgr.py)
06:56kettenisso is it correct that the M1 models use the 24MHz refclk and the M1 Pro/Max models a 200MHz clock?
07:05kettenishmm, dump_pmgr.py suggests spi3 uses a 120MHz clock on j293
07:06marcankettenis: no, 200MHz is for spinor
07:06marcanhuh, really?
07:07marcanI see 24MHz on pro/max models
07:07marcanI don't have a pmgr dump for j293 handy
07:08marcankettenis: can you paste that pmgr dump somewhere?
07:08kettenis#123: 120000000 2 0xa0/0x23b040100: regval: 0x85100000
07:09kettenis User: /device-tree/arm-io/spi3.clk[0]
07:09marcanspi1 is 200MHz for spi1 on at least the mini and pro/max
07:09marcanthat's interesting, I wonder why that is
07:09marcanspi3 is 24MHz on pro/max, and is unused on mini of course
07:10marcanwhat does spi1 say on that machine?
07:11kettenis#121: 200000000 2 0xa0/0x23b0400f8: regval: 0x85100000
07:11kettenis User: /device-tree/arm-io/spi1.clk[0]
07:11marcaninteresting, so clock #5 is not the same frequency for those SPIs
07:12marcan#121: 200000000 2 0xa0/0x23b0400f8: regval: 0x85100000
07:12marcan User: /device-tree/arm-io/spi1.clk[0]
07:12marcan#122: 120000000 2 0xa0/0x23b0400fc: regval: 0x85100000
07:12marcan#123: 120000000 2 0xa0/0x23b040100: regval: 0x85100000
07:12marcan#124: 120000000 2 0xa0/0x23b040104: regval: 0x85100000
07:12marcanso the *unused* spis on the mac mini get set to 120MHz, heh
07:12marcanI wonder if this is actually an oversight...
07:12marcanalso it feels really weird that #5 is 120 for spi2/3/4 but not spi1
07:14marcanmaybe they actually forgot to initialize that clock in iBoot (but it works anyway because the spi driver does the right thing wrt divider)
07:18ketteniswell, if the input frequency isn't 24MHz but 200MHz the actual SPI clock frequency won't be what I think it is
07:18marcan200MHz is only used for spi1 as far as I can tell
07:19marcanfor spi3 we have either 24 or 120 apparently?
07:19marcanbut my point is the spi driver should be computing its divider based on this information
07:19marcannow the question is is it 120 on the air too...
07:19kettenisof course I copied the spi-max-frequency property from corellium
07:19marcanspi-max-frequency is something else, isn't it?
07:19marcanthat's a max, not the base clock
07:19marcanthe base clock comes from the clock provider
07:20marcanbut the clock being 5x faster by accident on j293 would explain why it's breaking for people
07:20kettenisspi-max-frequency is the max frequency the spi device can run at if my understanding is correct
07:20kettenisspi-max-frequency = <2000000>;
07:20kettenisthat is what I have
07:21marcanyes, and if your clock provider is claiming the controller is clocked at 24 when it's actually at 120, then you're driving the device at 10MHz instead of 2MHz
07:21marcanwhich is bound to cause some issues :-)
07:21marcanlet me try the m1 air...
07:23kettenisyour gpiola.py stuff can actually measure the clock frequency?
07:24marcansure, it's timed
07:24marcanjust capture it and eyeball it in gtkwave by selecting a range of cycles
07:25marcanit's a real logic analyzer with proper delta compression ;)
07:25marcan(some call it RLE)
07:27kettenisI'll need to fugure out how to use it ;)
07:28marcanok, at least it's badly broken on the m1air, much more than the pro
07:28kettenisalso, how did you figure out which gpio pins are used?
07:28marcanlet's look at pmgr
07:28marcanthe CS pin is specified in the ADT, I guessed it was nearby pins. that worked for spi3 but not spi1, for spi1 I spammed the RegMonitor during a SPI transaction until I saw something change
07:28marcanthat found me the two disjointed pins
07:29marcanyou could also just trace, like, all pins in groups of 32 (the analyzer supports up to 32)
07:32kettenisthe adt doesn't actually provide the equivalent of spi-max-frequency for the spi devices isn't it?
07:33marcan#123: 120000000 2 0xa0/0x23b040100: regval: 0x85100000
07:33marcan User: /device-tree/arm-io/spi3.clk[0]
07:33marcanindeed, it's 120 on the m1 air too
07:33marcanlooks like it's 120 on all the m1 devices then
07:34marcanstill broken though
07:44marcan[GPIOTracer@/arm-io/gpio] Pin-49 W 0x876220 (GROUP=7, CFG_DONE=1, PERIPH=1, CONFIG=0, VALUE=0)
07:44marcanthis is wrong, it's setting the CS pin to hardware control but then the spi node is being told to use software CS
07:46kettenisare you tracing macos?
07:48jannauprobably my tree, I think I updated just the compatible for t8103
07:49marcanno, that's linux
07:49marcanpins={"clk": 46, "mosi": 47, "miso": 48, "cs": 49},
07:50marcanI think those are the spi3 pins for t8103 (miso unconfirmed)
07:52marcankeyboard/touchpad works on j313 now
07:52marcannot sure about X, I need to figure out why that breaks the touchpad, but I get the feeling that's an applespi problem, not a SPI problem
07:54marcancs-gpios should work, but then you need to pinconfig it to 0 instead
07:54marcansince it defaults to 1 on these machines
07:55kettenisI think we should not add cs-gpios if we want to use hardware cs control
07:55marcancorrect, but what I'm saying is software CS control should work too
07:55marcanbut then you need the pinconfig; without that it tries to use software CS control while the hardware is the one actually owning the pin
07:56marcanwhich is why none of this was working a minute ago, CS wasn't changing
07:58jannauthanks, fix pushed
08:01marcanjannau: were you testing on t6k or t8103?
08:02jannauI'm testing on t6000-j314c, I have no t8103 laptop
08:03marcanI'll go back to t6k since that's where I have a root partition for X, but hopefully those DT changes were the only difference that matters on t8103
08:05kettenisso the 24/120MHz difference suggests that we can actually use a 10MHz spi-max-frequency on t8103-j293
08:06marcandoes that work?
08:06marcanI mean it was broken due to the CS anyway
08:06jannauI'm not sure how much time we should spend on applespi. I'll work on the spi hid transport this weekend
08:06marcanlet me see what apple does
08:06jannauI doubt kettenis uses my linux tree
08:07marcan# [SPITracer@/arm-io/spi3] MMIO: W.4 CLKDIV = 0x3 ()
08:07marcanso 24/4 = 6
08:07marcanI wouldn't be surprised if 10MHz works if 6MHz is officially kosher
08:07marcanbut 3 would be 8, so apple definitely don't do 10
08:07marcanso let's go with 6000000?
08:08kettenisI'll give that a go with OpenBSD
08:08marcanthis is on j314s but I imagine it'd apply to the m1 devices too
08:08kettenisjannau: that is the current version of my OpenBSD driver
08:08kettenishopefully that gives you some hints on how I think the HID stuff works
08:09kettenisthis version uses "raw" mode to support the touchpad
08:09kettenisthe previous revision uses HID mode which just emulates a mouse
08:10marcanah, so the "proper" touchpad mode isn't real HID?
08:13kettenisit matches the linux drivers/input/bcm5974.c behaviour
08:14marcanheh, that sounds like more refactoring that needs to happen to share that code...
08:14kettenisyes, same issue on the OpenBSD side
08:14kettenisso I just copied code ;)
08:15marcanwhat a mess...
08:16marcanI guess the right way to do this would be something like
08:17marcanfirst write a HID transport that can do the keyboard/mouse bits via the standard HID framework
08:17kettenisthe usb hid group never properly standardized multi-touch
08:17marcanthen break up the bcm5974 driver into a core that sets up the input device and parses reports, and a transport layer
08:17marcanthe existing code would be the USB transport
08:17marcanand then we add a SPI transport
08:18marcanif both drivers are enabled the SPI/HID transport thing knows to switch modes and delegate to bcm5974 for that part
08:18marcanor something like that
08:20kettenisso my driver has some weird delays in it; it would be nice to get a better understanding of those
08:20marcanother than the CS stuff?
08:20marcanand reset
08:20marcanthose make sense
08:21marcanah, I see delays between command and status?
08:21marcanthat looks wrong, surely there's some way of knowing when a command is complete
08:22kettenisthe delay between command and status is defenitely necessary
08:22marcanyeah, but that sounds like there must be a better way
08:22kettenisand you need to keep CS# asserted
08:24kettenisbut maybe the hardware will assert the GPIO that is used for interrupts when it is ready
08:24kettenisi've not checked that
08:25marcanyeah, I was going to suggest that
08:33Glanzmannmarcan / jannau: I can test on macbook air if you tell me which tree I should use and what patch I should apply to the dtb.
08:37j`eymarcan: fwiw I always get one corrupted packet on boot
08:39kettenisI think that is just a packet with a different layout that isn't handled by the current code
08:39marcanhold on, I found a thing
08:44* j`eyholds
08:45marcanall the gory details of the SPI timings aren't in the ADT but they're *somewhere*
08:45marcantrying to figure out where
08:45marcanI found a pile of debugs about that in the driver
08:46j`eymarcan: I dont want to distract, but I'm confused now if m1air uses a 24mhz or 120mhz clock?
08:46marcanm1air uses 120
08:46marcanand apparently m1mbp does too
08:46marcanso probably all t8103 devices use 120
08:46j`eyI see, I wonder then how corelliums code worked, maybe its buggy
08:47marcancorellium code, buggy?
08:47j`eyand divides too much or something
08:47marcan(but also, they set the max-freq to 2MHz when in fact it's at least 6MHz)
08:47marcan(running a 6MHz device at 10MHz is relatively likely to work)
08:48kettenisin the end, all that matters is that you end up with a divider that "works"
08:48j`eyin the end it doesnt even matter
08:49j`ey(any linkin park fans?)
08:50marcanheh, I remember that lyric :-)
08:52marcanbtw, the ioreg on macos has lots of info, like the HID descriptors
08:53marcanand it tells you what the interface numbers are etc
08:54marcan(e.g. 3 is apparently the actuator, i.e. the force feedback thing)
08:54marcanthere is also apparently an accelerometer in here?
08:55kettenisdo you have the output for that handy?
08:57marcanthis is from m1air
08:57j`eymarcan: im happy the air is getting some attention ^_^
08:58marcanI mean I want all the machines to work :-)
08:58j`eyyeah but it was always the mini you worked on, then the t6000 :P
08:59Andre[m]1 has joined #asahi-dev
08:59marcanyeah, because a lot is shared
08:59marcanbut now that things are starting to come together I do want to test stuff on all of them and fix whatever's broken :)
09:08kettenisinterface 3 and 4 only provide vendor-specific stuff
09:09kettenisso the descriptors don't tell us very much
09:20marcanoh derp it's in the firmware
09:20marcanso I guess the device reports its own properties
09:21marcanjust running `strings` in the firmware yields a giant plist
09:21marcanthis "firmware" *is* the plist
09:21marcanand it includes the actual firmware and more stuff inside
09:22marcan... so where is this stored?
09:23marcan/System/Library/AssetsV2/com_apple_MobileAsset_SFRSoftwareUpdate/e1e322bee87acc15973794a58f6e551734c82adf.asset/AssetData/boot/Firmware/J293_Multitouch.im4p for one... but surely it doesn't get it from there
09:25FireFox317apple really do like firmware, doesnt it
09:27kettenisno real surprise that the descriptors are contained in the firmware
09:27marcanI mean stuff like SPI config
09:30marcanhttps://mrcn.st/p/ue4byz9Y this is for J314C with the firmware blobs snipped
09:31marcanthat stupid IDREF compression is annoying
09:31marcanbut anyway, you have all the timings at the end
09:43marcanbut there's supposed to be more stuff that I'm not finding...
10:11marcanyou know...
10:11marcan reg = 000000007d0000000000010800000000204e0000000000000000000000000000
10:11marcanthe "reg" of the spi device might be the timings, now that I think about it...
10:11marcanthis is the kind of horrible hack apple would do...
10:12aleasto has joined #asahi-dev
10:14marcangoddammit I think it is
10:14marcan*facepalm*
10:15j`eyit certainly looks outside of physical memory space :P
10:15marcanu32 unk, clock_period, flags, word_delay, cs_delay, cs_preamble_delay, cs_postamble_delay
10:15marcanthis claims the clock is 8MHz (assuming that's nsec) and the cs_delay 20us
10:17GlanzmannLets ship it.
10:18marcanoh, and where is AppleARMSPIDevice defined? in AppleARMPlatform of course
10:18marcanso not only are they tying their SPI device abstraction to ARM platforms only, they define it in the kitchen sink driver
10:19marcanseriously, people need to give us credit, the stuff we come up with is way cleaner than macOS :p
10:20marcanalso the controller driver is called AppleSamsungSPI so I was right that it's somehow a relative of Samsung stuff
10:22svenyeah, there are some horrible hacks in some drivers
10:23sventhere's also the entire gpu iommu node that's just used to create a small shim driver that just calls back to the main gpu driver
10:26marcanlooks like the preamble/postamble ones are cs to data and data to cs, and take effect if cs_delay is zero
10:26marcanso this means 20us after cs assert and before cs deassert
10:28marcanthe four flag bytes I think are clock_polarity, flags (I think only bit 0 does something), some other bool, and bits per word
10:30j`eymarcan: either that 120MHZ clock fixed it.. or the change I made to use gpio instead of hw-cs /me reverts back to hw-cs and checks
10:32j`eyyes it was the clock (obviously!)
10:33aidenfoxivey has quit [Quit: aidenfoxivey]
10:33aidenfoxivey has joined #asahi-dev
11:02gladiac is now known as Guest8136
11:02gladiac has joined #asahi-dev
11:03bps has quit [Ping timeout: 480 seconds]
11:08Guest8136 has quit [Ping timeout: 480 seconds]
11:52bps2 has joined #asahi-dev
12:40the_lanetly_052__ has joined #asahi-dev
12:40marcanI think the CLKDIV must be off by one, assuming apple's driver isn't wrong
12:41marcanit sets it to 3, which for 24MHz would be 8MHz under that interpretation (I had it as divisor - 1 instead which would give 6MHz)
12:42marcanwonder if I can get the gpiotracer accurate enough to test that... probably measuring the entire transfer with auto-cs
13:05aleasto has quit [Remote host closed the connection]
13:19Gaspare has joined #asahi-dev
13:31j`eyIm getting what seems to be recursive exceptions when trying to use linux.py, anyone else seeing this?
13:35j`eynevermind, I forgot to chainload
14:05yuyichao has quit [Ping timeout: 480 seconds]
14:07marcanj`ey: why going back to 24?
14:08j`eymarcan: because I misunderstood what you said before
14:08marcanI was talking about t6000
14:08marcanbut if that works then I guess it can handle 30MHz lol?
14:15marcanok, confirmed with spi.py, the CLKDIV is not -1 and the minimum is 2
14:16kettenisso you end up with 200000000 / CLKDIV on the t6000?
14:18marcanno, 24MHz / CLKDIV
14:19kettenisah for spi3
14:19marcanfor spi1 it would be 200M, yes
14:24aleasto has joined #asahi-dev
14:25yuyichao has joined #asahi-dev
14:39kgarrington has joined #asahi-dev
14:40kgarrington has quit [Remote host closed the connection]
14:41yuyichao has quit [Ping timeout: 480 seconds]
14:45mini_ has joined #asahi-dev
14:47marcanok, got gpiola running on the hypervisor while running linux; I can't see the signals accurately at 8MHz, but I can tell the CS to clock delay isn't being correctly implemented
14:49the_lanetly_052___ has joined #asahi-dev
14:52mini_ has quit [Quit: ZNC closing...]
14:53marcan... because applespi calls applespi_setup_read_txfrs before applespi_setup_spi, which is what sets the cs delay value
14:54j`eylooks like youre missing a patch
14:55the_lanetly_052__ has quit [Ping timeout: 480 seconds]
14:55marcanthat wasn't in jannau's branch I think
14:56marcanyup, keyboard works now
14:56j`eyoh, he must have missed it, it was in previous branches of his
14:57marcanunless I dropped it while rebasing at some point, but I don't think so? at least not intentionally
14:57_jannau_I must have dropped that during the rebase onto asahi
14:58marcaneither way obviously the way that driver is doing things is wrong; instead of that delay message it should be setting up a cs_hold
15:00marcanalso, is it me or is set_cs_timing broken in the spi core?
15:00j`eyits not used
15:00marcanthere is nothing that calls it, but it existing cancels the delay code
15:01j`eybroonie seemed to think it was important for some reason..
15:04marcanthat would be the function for the new HID driver to se the CS delays
15:05j`eyif there's a user for it, I thin it would be okay to bring back
15:06marcanit bugs me that it changes the delays on the controller though
15:06marcanshouldn't those values be per-device, not per-controller?
15:06kettenishmm, there are fields in struct spi_device now
15:06marcanahh right
15:06marcanso I guess we're just supposed to set those directly
15:06marcannot through a function
15:07marcan(though no drivers do that)
15:07kettenisit is a fairly recent addition
15:07marcanthe set_cs_timing thing is definitely wrong though
15:07marcanthat removal removed its usage
15:08marcanthe spi core needs some code to call it during transfer setup passing in spi_device values
15:09kettenisspi_set_cs() handles all that isn't it?
15:10marcannot if set_cs_timing exists
15:10marcanalso, er, I think it's wrong?
15:11kettenisunless you provide the set_cs_timing() callback in your driver
15:11marcancs_setup handling is wrong lol
15:11marcanit needs to happen at the end of the function
15:11marcanbroken code, broken code everywhere
15:13j`eymarcan: oof
15:17Gaspare has quit [Quit: Gaspare]
15:31marcanj`ey, jannau: pushed the core fixes to asahi
15:31marcanthen on top of that, you can do this to applespi: https://mrcn.st/p/O5dbDo3P
15:31marcanI'm just going to send off that spi core patch now, it's obvious
15:32j`eymarcan: ty!
15:33marcanah, forgot the signoff. adding it before submission :p
15:36j`eymarcan: you can set set format.signoff true in git config
15:36marcanah, yeah
15:37j`eyor commit.signoff.. I seem to have both *shrug*
15:37marcanI also just added myself a fixes = Fixes: %h (\"%s\") format
15:37marcanand a fixes = log -1 --format=fixes alias
15:44Gaspare has joined #asahi-dev
15:53balrog has quit [Quit: Bye]
15:59balrog has joined #asahi-dev
16:02kettenisfwiw, 120MHz base clock and 8MHz bus clock seems to work fine with my OpenBSD drivers
16:08Dcow_ has joined #asahi-dev
16:08Dcow has quit [Remote host closed the connection]
16:08Gaspare has quit [Quit: Gaspare]
16:31aidenfoxivey has quit [Quit: aidenfoxivey]
16:31aidenfoxivey has joined #asahi-dev
17:08Gaspare has joined #asahi-dev
17:13bps2 has quit [Ping timeout: 480 seconds]
18:10Glanzmann has quit [Quit: leaving]
18:34bpye has quit [Quit: The Lounge - https://thelounge.chat]
18:39Gaspare has quit [Quit: Gaspare]
18:51the_lanetly_052___ has quit [Ping timeout: 480 seconds]
19:35zimsneexh has joined #asahi-dev
22:27kumoko has joined #asahi-dev
22:29kumoko has quit []
23:04slicey has joined #asahi-dev
23:35ted[m] has left #asahi-dev [#asahi-dev]
…