-
Notifications
You must be signed in to change notification settings - Fork 119
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
applespi: Remove the need to modify the DSDT. #29
applespi: Remove the need to modify the DSDT. #29
Conversation
@roadrunner2 just tried it and I can't seem to get it to work. I'm getting the |
@tudorbarascu Thanks for trying this out. There should be a second message "Got spi-master device for bus-number 2" after that, but I'm guessing not since you don't mention it. So, some issue with detecting the spi-master device then. What does |
in
|
Thanks for the info. So your model has one SPI controller - interesting (the 13,3 model has 2, but one seems unused), and possibly the reason for the device being called pxa2xx-spi.3 instead of pxa2xx-spi.5, but not the issue here. Instead, I see that the pxa2xx-spi.3 device has no driver associated with it - is the 'spi_pxa2xx_platform' module loaded on your system? If not, make sure to load it. Oh, and can you run ' |
Indeed, I retested and it works. Thanks a lot! Sorry for the noise. I've setup the touchpad to maximum speed and passing over the touchpad with the finger from left to right only does 3/4 of the screen. |
Glad to hear that fixed it. Regarding the touchpad speed, did you add the hwdb entries I specify in the "Keyboard/Touchpad/Touchbar" section in my gist? Also note that I fixed a syntax bug in the attached |
Thanks a lot! Do you still plan on pushing those upstream? |
Yes, I definitely want to upstream that (as with pretty much everything else). Before doing so I was hoping somebody could give me the proper dpi values for the MacBook touchpad's, though. |
Much of the information supplied in the DSDT resource-template returned when the DSDT is modified is also available from the _DSM method. So we register ourselves as an ACPI driver for the device, and then create and register the spi device ourselves, configuring it from the information returned by the _DSM method.
While unusual, this can happen if the corresponding drivers/modules are removed. So this now properly detects spi-slave removals (as a result of master removals) and always registers a watcher for master adds.
Added a bunch of debug logging, and enhanced some of the info logs.
2d78e21
to
e460ee3
Compare
@roadrunner2 this works well on my MacBook9,1; after removing the DSDT modification everything is still detected. Agreed that it should be temporary until there's a better solution in the kernel, although might end up in a bit of a chicken and egg problem. If you're happy with it, I'll merge it in. |
I'm reasonably happy with it, as far as things go: it's been stable for me in various scenarios, and nobody so far has reported issues. The implicit driver dependency that @tudorbarascu ran into above is unfortunate, but since that One of the reasons I created this patch is because I noticed that the modified DSDT was a huge area of problems for folks (various distros apparently make it quite hard to load a custom DSDT short of building your own modified kernel, which is definitely more work and maintenance than just building just a module or two out of tree). So I really think it'll significantly lower the barrier to using this module (and generally running Linux on these machines). |
Have been running it for some days on two different macbook9.1, no errors or problems here 👍 |
@roadrunner2 do you perhaps want to add a note about |
These are not auto-loaded anymore if the DSDT isn't patched and hence doesn't explicitly expose a resource for the keyboard/trackpad SPI device.
@cb22 Done. |
@roadrunner2
That said, you can't upstream this (part) at all. |
Regarding the legal comments, I'm having some trouble understanding how invoking _DSM is any different from invoking any other method in the DSDT - in both cases the implementation is copyrighted by whoever wrote it, but having bought the machine you also have a license to use them (I have not seen anything anywhere that indicates any restriction on what software may call these methods). So I'm going to need a bit more solid evidence to be convinced this is an actual issue. But anyway, that's a discussion for the patches to the acpi core and for the lawyers. |
I'm not a lawyer, so I'm speculating on a common sense of the reading of ACPI specification. So, the methods that are nicely defined in ACPI are free to be called under ACPI terms (via ACPICA or maybe any other custom implementation), while vendor specific methods are completely specific to vendors and specification doesn't clarify this legal aspect. So, if I would be you, I would contact Apple to clarify use of this method out of Mac OS X. |
I've coded up two commits to the ACPI core and SPI core today, essentially what I proposed last year (see link in #21). Need to do a bit of testing and polishing, please stand by. |
@l1k |
@andy-shev: Sure, of course. @roadrunner2: I've just pushed a new spi_properties_v1 branch containing these two commits:
This is an implementation of what I proposed last year (linked by @Dunedan in #21). I do not have a machine with SPI-attached keyboard, so I cannot test this. I did test retrieval of _DSM Buffer properties with a u32 stored for the Firewire device on my machine and it worked fine. Could you try rebasing the SPI driver on top of these two commits. (Preferably on a separate branch so that people can continue using the existing solution for now.) It would be good to have a Tested-by from you at least for the second commit when posting to the mailing lists. The two commits may still contain bugs and there's also some debugging code left in which hexdumps the _DSM properties. I will have to review the commits a couple of times with a fresh pair of eyeballs before I can post them to the mailing lists. I will force-push the branch and let you know if I make modifications. Thanks! |
Okay, 0-day notified me of two bugs. Fixed those and force-pushed to the branch, the commit IDs referenced above are thus already outdated. |
@roadrunner2: I've fixed a bunch of bugs and pushed the spi_properties_v1 branch once more. Still need to do some testing, but getting closer. Fun fact: I've downloaded the MacOS X 10.4.11 Combo updater to verify that indeed they had support for both, _DSM and EFI properties built in from the very beginning. :-) |
@l1k I pulled the code from the
I'm not sure what the best solution is here; for now I've hacked in some explicit checks for the |
@roadrunner2: Amazing, thanks a lot! As to (1), I think it should be sufficient to check for presence of one representative device property in As to (2), I'm not sure how that check could be a problem since |
@l1k The value of |
Hm, then While we could add another Apple-specific quirk here to ignore -EIO, it doesn't appear to be a proper solution. I'm wondering if this is a bug in the ACPICA. The AML contains an empty resource template:
And the ACPI 6.1 spec, page 800 explicitly allows empty resource templates:
Could you insert a couple of |
@l1k Ok, narrowed it down to |
@roadrunner2: If you revert commit l1k/linux@a83019eb9f1f ("ACPICA: Update resource descriptor handling"), does the issue go away? That commit is brand new (June 5) and may have introduced a regression for empty ResourceTemplates.
|
@l1k Bingo! Good catch. That indeed makes |
@roadrunner2: Okay. Getting stuff fixed in the ACPICA is somewhat complicated because it's an OS-independent layer that is merely included verbatim in the kernel and called from functions outside of the drivers/acpi/acpica directory. Usually patches have to go through ACPICA upstream and then flow down to the kernel, so the proper folks to contact are the ACPICA maintainers, which I've just done and cc'ed you. Hopefully this gets fixed quickly. Thanks a lot for taking the time to track this down.
|
@roadrunner2: I've pushed a new version of the spi_properties_v2 branch which contains a revert of the offending ACPICA commit plus a new commit to work around the enumeration issue. However it has now occurred to me that a better approach might be to modify |
@roadrunner2: Actually... maybe it's a dumb idea. There's no bijection between Apple's properties and _CRS, e.g. |
@l1k, Perhaps you may convert Apple's _DSM to _DSD somewhere, though the best case for doing that is still near to SPI core. ACPI core should be free of such mappings / conversions. |
@l1k I can confirm things work nicely now with your latest version of the branch and my modified driver. Many thanks. Regarding the properties vs _CRS, yes, the driver stills need to get those delay values from the properties as they can't be represented in the acpi spi resource. |
@andy-shev: The device properties are not only queried by the SPI core: As @roadrunner2 has pointed out above, the HID driver for the SPI-attached keyboard likewise has the need to query certain device properties. In addition, the DSDT on recent MacBooks and MacBook Pros contains device properties (instead of _CRS data) for various UART- and I2C-attached devices and I anticipate we'll have to query those as well, e.g. in the I2C core. It seems inappropriate to me to place the DSM-to-DSD converter in the SPI subsystem even though other subsystems depend on the device properties as well. The ACPI core appears to be the most logical place as the properties are stored in AML. I could however place the code in a separate file if consensus is that it clutters up |
@roadrunner2: Sorry for the delay, I've finished v3 of the SPI properties patches and pushed them to the spi_properties_v3 branch. They pass all my tests and I'm relatively confident that they should still work on MacBooks with SPI keyboards, nevertheless I'd be grateful if you could give them another spin. Thanks! |
@l1k I've built and debugged v3 now. I needed to make the following change: @@ -1452,10 +1452,15 @@ static bool acpi_is_spi_i2c_slave(struct acpi_device *device)
struct list_head resource_list;
bool is_spi_i2c_slave = false;
- /* Macs use device properties in lieu of _CRS resources */
+ /*
+ * Macs use device properties in lieu of _CRS resources.
+ *
+ * Note: can't use device_property_present() because fwnode is not set
+ * yet.
+ */
if (is_apple_system &&
- (device_property_present(&device->dev, "spiSclkPeriod") ||
- device_property_present(&device->dev, "i2cAddress")))
+ (!acpi_dev_get_property(device, "spiSclkPeriod", ACPI_TYPE_ANY, NULL) ||
+ !acpi_dev_get_property(device, "i2cAddress", ACPI_TYPE_ANY, NULL)))
return true;
INIT_LIST_HEAD(&resource_list); The problem is that |
@roadrunner2: My apologies for missing that issue and thanks so much for tracking it down. The On one hand that makes sense because the I'll ask Rafael what he thinks about it, meanwhile I've gone with |
It's not a bug, pure ACPI devices in Linux kernel module is a legacy. |
@l1k Ah, right, that explanation makes sense. Thanks. In any case, your latest v3 branch is working like a charm now. |
@roadrunner2 @andy-shev: Just a quick heads-up, I've cooked up an spi_properties_v4 series over the weekend and am planning to post it sometime this week. The retrieval of the ACPI properties and the SPI initialization is unchanged from v3, only the recognition of Apple machines was amended as discussed on the mailing list with Rafael, Andy & Darren: New commit l1k/linux@20f8b74 ("treewide: Consolidate Apple DMI checks") performs the Apple DMI check once early on in the boot sequence and the cached value is subsequently used everywhere else. Commit l1k/linux@6dad5b1 ("ACPI / osi: Exclude x86 DMI quirks on other arches") is no longer needed and thus dropped. |
@l1k FYI, I'm still debugging this, but something's busted: in OTOH, the new |
@roadrunner2: Ugh. :-/ Is this with an unpatched DSDT? It's certainly odd since it worked before and the patches should be the same. However they're on top of Rafael's bleeding-edge branch as of last Friday wheras spi_properties_v3 was based on an earlier date of that branch, it's possible something has changed in the meantime. But that would seem to be unrelated to this series and could be addressed by a separate fix. |
@l1k Ok, chased this one down now. Sorry, In short, all clear on your patches. Many thanks! |
@roadrunner2: Ah, right, dammit. Rafael said that he'd drop the offending commit from the 4.13 pull that he'd send to Linus, which he did. But he intentionally left the commit on his bleeding-edge branch as the ACPICA material for 4.14 was going to be based on it. Indeed, the ACPICA folks reverted the commit as well with acpica/acpica@f3300640 on June 27 (one day after I forwarded your report), posted the Linuxized version to the mailing list yesterday and Rafael applied it to his bleeding-edge branch 10 hours ago. I had based the series on Rafael's bleeding-edge branch to ensure that it applies cleanly once he picks it up. I should have remembered the offending commit and revert it on the spi_properties_v4 branch. (I just did that.) Truly sorry for the extra work this has caused you! :-( |
Rafael kindly merged the spi_properties_v4 series into his bleeding-edge branch yesterday and it will now get some testing in linux-next. If there are no regressions, it should land in Linus' tree during the upcoming 4.14 merge window (about a month from now). |
@l1k Excellent news! Thanks for creating these patches and pushing them through. |
Okay the SPI properties support landed in Linus' tree half an hour ago with commit torvalds/linux@53ac64a. |
@l1k Thanks for the heads-up. I see my fix for the MB8,1's is also included in that pull, so that should make things easier for those folks. I'll wrap my dsdt hacks here in some version checks so they're only enabled for < 4.14. |
This creates the spi device based on information taken from the _DSM method. While a more complete fix should probably be done in the core, this at least avoids the need for DSDT modifications right now - most of this should be removed again when the core has the desired support. Partly for this reason all the added code uses the
appleacpi_
prefix instead of theapplespi_
prefix used everywhere else in this module, thereby making it clear that it A) is related to acpi not spi per se, and B) is a piece of functionality that can be removed together. But feedback/comments welcome.This resolves #21 for now.