#asahi-dev · 2022-02-13 13:24
marcan(this is also why I *am* splitting it into 3 at least; if you try to cover the entire 64K PMU space with one NVMEM block, you get the whole thing when you cat the file, and that's bound to cause trouble)#asahi-dev · 2022-02-13 13:24
marcanbut I figured splitting it up into even tinier bits to avoid that isn't really worth it#asahi-dev · 2022-02-13 13:23
marcanthere's one somewhat hacky thing in there, the RTC "nvmem" area actually covers the whole RTC including the counter, so you get the RTC included in the /nvmem file in sysfs if you cat it#asahi-dev · 2022-02-13 13:21
marcanI'm going to make the reboot driver handle the boot failure stuff properly too, since otherwise something could complain or decide to go into recovery mode or something#asahi-dev · 2022-02-13 13:21
marcanI also added a bunch more nvmem/flag details I could gather around from the ADT and the PMU driver#asahi-dev · 2022-02-13 13:21
marcangeneric spmi-mfd-nvmem driver is done, going to write the SMC RTC driver now hooking into it#asahi-dev · 2022-02-13 13:20
marcankettenis, robher: ^#asahi-dev · 2022-02-13 13:20
marcangoing to grab dinner, but here's a first pass at the binding: https://mrcn.st/p/fuLM5PaN#asahi-dev · 2022-02-13 11:24
marcanexactly#asahi-dev · 2022-02-13 11:20
marcanwhich means we can just treat the entire PMU as an nvmem device (a lot of it is), though I'd still make it an mfd so that if in the future we need to throw other things in there we can#asahi-dev · 2022-02-13 11:20
marcanalso looking at the nvmem stuff, that eliminates the entire question about how to represent this in the PMU binding since it just lets you define address ranges for cells#asahi-dev · 2022-02-13 11:19
marcanbut we don't even have suspend yet :)#asahi-dev · 2022-02-13 11:19
marcanor from off#asahi-dev · 2022-02-13 11:19
marcanyeah#asahi-dev · 2022-02-13 11:16
marcanthen we just never have a PMU RTC driver#asahi-dev · 2022-02-13 11:16
marcanI'd be okay with saying no alarms in 12.x if 13.x comes around with everything doable from SMC#asahi-dev · 2022-02-13 11:16
marcanit does kind of make sense to do it all in one driver under SMC and treat the PMU as dumb memory in this case#asahi-dev · 2022-02-13 11:16
marcanand then I can also move the power sequencing stuff to SMC, that needs to poke at other PMU bits#asahi-dev · 2022-02-13 11:15
marcanthat said, there's a decent argument for doing that anyway, since we won't support alarms yet, and just hope 13.0 lets us do everything from SMC#asahi-dev · 2022-02-13 11:14
marcanwhich isn't quite nvmem#asahi-dev · 2022-02-13 11:14
marcanbut then the RTC needs to do the alarm stuff too#asahi-dev · 2022-02-13 11:01
marcanpolling from m1n1 until the PMU rolls over, then reading SMC, I get: 001115b48005 (PMU) 001115b47fa8 (SMC)#asahi-dev · 2022-02-13 11:01
marcanand always rolls over a seemingly consistent-ish fraction of a second prior#asahi-dev · 2022-02-13 11:00
marcanat the seconds#asahi-dev · 2022-02-13 11:00
marcanit has the same value though#asahi-dev · 2022-02-13 11:00
marcanor maybe it has some magic way of reading it?#asahi-dev · 2022-02-13 11:00
marcanbecause if it's just free-running, it would fall out of sync with the real PMC clock, unless it continuously updates the PMC clock? but it's not writable as far as I can tell...#asahi-dev · 2022-02-13 10:59
marcanthe curious thing is how the SMC is synthesizing the sub-second precision#asahi-dev · 2022-02-13 10:57
marcanhence the rtc helper function thing in the ADT#asahi-dev · 2022-02-13 10:57
marcanyeah#asahi-dev · 2022-02-13 10:55
marcankettenis: yeah, it always reads the clock from SMC then immediately writes the offset to the PMU#asahi-dev · 2022-02-13 10:48
marcanlet me check, but I think so#asahi-dev · 2022-02-13 10:43
marcansure#asahi-dev · 2022-02-13 10:42
marcanbut I guess for now this will have to do; if in 13.x they switch to a full SMC based solution we can just implement that and deprecate the PMU mechanism, and if they don't we can think of doing what macOS does and having the drivers talk to each other#asahi-dev · 2022-02-13 10:42
marcanso while linux will do sub-second updates when syncing to NTP on most RTCs, we can't implement that sanely here without hooking up the PMU driver to SMC#asahi-dev · 2022-02-13 10:41
marcanand who knows how SMC implements that sub-second counter#asahi-dev · 2022-02-13 10:41
marcanmost RTCs will reset the sub-second counter when you write to them, but we can't emulate that behavior without knowing when the second rolls over, which is annoying#asahi-dev · 2022-02-13 10:40
marcanthe problem is the SMC is still providing sub-second resolution, and the offset also provides sub-second resolution#asahi-dev · 2022-02-13 10:40
marcankind of#asahi-dev · 2022-02-13 10:34
marcansince the time is atomically loaded into the registers when you read the first byte#asahi-dev · 2022-02-13 10:34
marcanwhich you can tell because if you start reading at the seconds offset, the time never updates#asahi-dev · 2022-02-13 10:34
marcanhowever, the field still starts at the a (!)#asahi-dev · 2022-02-13 10:34
marcanso only integer seconds are valid#asahi-dev · 2022-02-13 10:34
marcanbut on maverick, the tick count always ends in 000a (pre shift) for some reason#asahi-dev · 2022-02-13 10:33
marcanthe offset is already in ticks#asahi-dev · 2022-02-13 10:33
marcanthe tick count is >>1 to get 32768Hz ticks#asahi-dev · 2022-02-13 10:33
marcannow I almost want to just wait until 13.x and see if we can just put the RTC driver in SMC...#asahi-dev · 2022-02-13 10:22
marcanmaybe it reads the PMU RTC on startup and then just free-runs off of some other clock in SMC?#asahi-dev · 2022-02-13 10:22
marcanif I wait for the PMU second to roll over, then read SMC, the SMC is a few milliseconds *behind* in its count, still on the previous second#asahi-dev · 2022-02-13 10:21
marcanha, I think SMC is faking that tick count