From patchwork Wed Jun 21 18:05:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lukas Wunner X-Patchwork-Id: 9802497 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3F93860329 for ; Wed, 21 Jun 2017 18:07:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC8472821F for ; Wed, 21 Jun 2017 18:07:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B0CA9283FB; Wed, 21 Jun 2017 18:07:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 85D3B2821F for ; Wed, 21 Jun 2017 18:07:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752384AbdFUSHP (ORCPT ); Wed, 21 Jun 2017 14:07:15 -0400 Received: from mailout2.hostsharing.net ([83.223.90.233]:37933 "EHLO mailout2.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752149AbdFUSHN (ORCPT ); Wed, 21 Jun 2017 14:07:13 -0400 Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mailout2.hostsharing.net (Postfix) with ESMTPS id 826A41019D65D; Wed, 21 Jun 2017 20:07:05 +0200 (CEST) Received: from localhost (5-38-90-81.adsl.cmo.de [81.90.38.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by h08.hostsharing.net (Postfix) with ESMTPSA id 5C29E611D538; Wed, 21 Jun 2017 20:07:04 +0200 (CEST) X-Mailbox-Line: From 19c49c0351e452bff28199abcc6b3a11ec6949b2 Mon Sep 17 00:00:00 2001 Message-Id: <19c49c0351e452bff28199abcc6b3a11ec6949b2.1498044532.git.lukas@wunner.de> In-Reply-To: References: From: Lukas Wunner Date: Wed, 21 Jun 2017 20:05:53 +0200 Subject: [PATCH 3/3] spi: Use Apple device properties in absence of ACPI resources MIME-Version: 1.0 To: "Rafael J. Wysocki" , Mark Brown , Ronald Tschalaer , Federico Lorenzi Cc: Mika Westerberg , Andy Shevchenko , Leif Liddy , Daniel Roschka , linux-acpi@vger.kernel.org, linux-spi@vger.kernel.org Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP MacBooks and MacBook Pros introduced since 2015 return empty _CRS data for SPI slaves, causing device initialization to fail. Most of the information that would normally be conveyed via _CRS is available through ACPI device properties instead, so take advantage of them. The meaning and appropriate usage of the device properties was reverse engineered by Ronald Tschalär and carried over from these commits authored by him: https://github.com/cb22/macbook12-spi-driver/commit/9a416d699ef4 https://github.com/cb22/macbook12-spi-driver/commit/0c34936ed9a1 According to Ronald, the device properties have the following meaning: spiSclkPeriod /* period in ns */ spiWordSize /* in number of bits */ spiBitOrder /* 1 = MSB_FIRST, 0 = LSB_FIRST */ spiSPO /* clock polarity: 0 = low, 1 = high */ spiSPH /* clock phase: 0 = first, 1 = second */ spiCSDelay /* delay between cs and receive on reads in 10 us */ resetA2RUsec /* active-to-receive delay? */ resetRecUsec /* receive delay? */ Cc: Mark Brown Cc: Federico Lorenzi Cc: Ronald Tschalär Signed-off-by: Lukas Wunner --- drivers/spi/spi.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 89254a55eb2e..a4066b75d02b 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include #include #include @@ -1685,6 +1687,29 @@ static void of_register_spi_devices(struct spi_master *master) { } #endif #ifdef CONFIG_ACPI +static void acpi_spi_parse_apple_properties(struct spi_device *spi) +{ + struct acpi_device *dev = ACPI_COMPANION(&spi->dev); + const union acpi_object *o; + + if (!acpi_dev_get_property(dev, "spiSclkPeriod", ACPI_TYPE_BUFFER, &o)) + spi->max_speed_hz = div64_u64(NSEC_PER_SEC, + *(u64 *)o->buffer.pointer); + + if (!acpi_dev_get_property(dev, "spiWordSize", ACPI_TYPE_BUFFER, &o)) + spi->bits_per_word = *(u64 *)o->buffer.pointer; + + if (!acpi_dev_get_property(dev, "spiBitOrder", ACPI_TYPE_BUFFER, &o) && + !*(u64 *)o->buffer.pointer) + spi->mode |= SPI_LSB_FIRST; + if (!acpi_dev_get_property(dev, "spiSPO", ACPI_TYPE_BUFFER, &o) && + *(u64 *)o->buffer.pointer) + spi->mode |= SPI_CPOL; + if (!acpi_dev_get_property(dev, "spiSPH", ACPI_TYPE_BUFFER, &o) && + *(u64 *)o->buffer.pointer) + spi->mode |= SPI_CPHA; +} + static int acpi_spi_add_resource(struct acpi_resource *ares, void *data) { struct spi_device *spi = data; @@ -1758,6 +1783,11 @@ static acpi_status acpi_register_spi_device(struct spi_master *master, acpi_spi_add_resource, spi); acpi_dev_free_resource_list(&resource_list); + /* Zero ACPI resources? Try Apple device properties instead. */ + if (!ret && IS_ENABLED(CONFIG_X86) && + dmi_match(DMI_SYS_VENDOR, "Apple Inc.")) + acpi_spi_parse_apple_properties(spi); + if (ret < 0 || !spi->max_speed_hz) { spi_dev_put(spi); return AE_OK;