All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mika Westerberg <mika.westerberg@linux.intel.com>
To: Lukas Wunner <lukas@wunner.de>
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	Mark Brown <broonie@kernel.org>,
	Ronald Tschalaer <ronald@innovation.ch>,
	Federico Lorenzi <florenzi@gmail.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Leif Liddy <leif.liddy@gmail.com>,
	Daniel Roschka <danielroschka@phoenitydawn.de>,
	linux-acpi@vger.kernel.org, linux-spi@vger.kernel.org
Subject: Re: [PATCH 3/3] spi: Use Apple device properties in absence of ACPI resources
Date: Thu, 22 Jun 2017 11:10:48 +0300	[thread overview]
Message-ID: <20170622081048.GT629@lahna.fi.intel.com> (raw)
In-Reply-To: <19c49c0351e452bff28199abcc6b3a11ec6949b2.1498044532.git.lukas@wunner.de>

On Wed, Jun 21, 2017 at 08:05:53PM +0200, Lukas Wunner wrote:
> 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 <broonie@kernel.org>
> Cc: Federico Lorenzi <florenzi@gmail.com>
> Cc: Ronald Tschalär <ronald@innovation.ch>
> Signed-off-by: Lukas Wunner <lukas@wunner.de>
> ---
>  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 <linux/cache.h>
>  #include <linux/dma-mapping.h>
>  #include <linux/dmaengine.h>
> +#include <linux/dmi.h>
> +#include <linux/math64.h>
>  #include <linux/mutex.h>
>  #include <linux/of_device.h>
>  #include <linux/of_irq.h>
> @@ -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);

Same comment here, move the conditionals to
acpi_spi_parse_apple_properties() and then do

	if (!ret)
		acpi_spi_parse_apple_properties(spi);

  reply	other threads:[~2017-06-22  8:13 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-21 18:05 [PATCH 0/3] Apple SPI properties Lukas Wunner
2017-06-21 18:05 ` [PATCH 2/3] ACPI / property: Support Apple _DSM properties Lukas Wunner
2017-06-21 23:05   ` Rafael J. Wysocki
2017-06-22  8:57     ` Lukas Wunner
2017-06-22 14:18       ` Rafael J. Wysocki
2017-06-22  8:06   ` Mika Westerberg
2017-06-22  9:54     ` Lukas Wunner
2017-06-22 10:04       ` Mika Westerberg
2017-06-22 11:24         ` Lukas Wunner
     [not found]           ` <20170622112428.q3hpwpfs4xwumued-JFq808J9C/izQB+pC5nmwQ@public.gmane.org>
2017-06-22 13:25             ` Mark Brown
2017-06-21 18:05 ` [PATCH 3/3] spi: Use Apple device properties in absence of ACPI resources Lukas Wunner
2017-06-22  8:10   ` Mika Westerberg [this message]
2017-06-22  8:44     ` Lukas Wunner
2017-06-22  9:28     ` Mark Brown
2017-06-21 18:05 ` [PATCH 1/3] ACPI / property: Don't evaluate objects for devices w/o handle Lukas Wunner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170622081048.GT629@lahna.fi.intel.com \
    --to=mika.westerberg@linux.intel.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=broonie@kernel.org \
    --cc=danielroschka@phoenitydawn.de \
    --cc=florenzi@gmail.com \
    --cc=leif.liddy@gmail.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=rafael.j.wysocki@intel.com \
    --cc=ronald@innovation.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.