From patchwork Mon Jul 4 10:38:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Westerberg X-Patchwork-Id: 9212219 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 C8A9A6048B for ; Mon, 4 Jul 2016 10:38:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B6E6C28639 for ; Mon, 4 Jul 2016 10:38:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A9F5728645; Mon, 4 Jul 2016 10:38:12 +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=ham 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 1A13028639 for ; Mon, 4 Jul 2016 10:38:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753200AbcGDKiL (ORCPT ); Mon, 4 Jul 2016 06:38:11 -0400 Received: from mga09.intel.com ([134.134.136.24]:50652 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753183AbcGDKiK (ORCPT ); Mon, 4 Jul 2016 06:38:10 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP; 04 Jul 2016 03:38:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,574,1459839600"; d="scan'208";a="840290774" Received: from black.fi.intel.com ([10.237.72.93]) by orsmga003.jf.intel.com with ESMTP; 04 Jul 2016 03:38:04 -0700 Received: by black.fi.intel.com (Postfix, from userid 1001) id EFD13206; Mon, 4 Jul 2016 13:38:03 +0300 (EEST) From: Mika Westerberg To: linux-spi@vger.kernel.org Cc: Mark Brown , Jarkko Nikula , Mika Westerberg Subject: [PATCH] spi: spidev: Add ACPI probing support Date: Mon, 4 Jul 2016 13:38:03 +0300 Message-Id: <1467628683-5783-1-git-send-email-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 2.8.1 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some IoT and maker software stacks are using spidev to perform raw access to the SPI bus instead of relying existing drivers provided by the kernel. They then implement their own "drivers" in userspace on top of the spidev raw interface. This is far from being an ideal solution but we do not want to prevent using mainline Linux in these devices. Now, it turns out that Windows has similar SPI devices than spidev which allow raw access on the SPI bus to userspace programs as described in the link below: https://msdn.microsoft.com/windows/hardware/drivers/spb/spi-tests-in-mitt These SPI test devices are also meant to be used during development and testing. In order to allow usage of spidev for development and testing in Linux, add those same ACPI IDs to the spidev driver (which is Linux counterpart of the Windows SPI test devices), but complain loudly so that users know it is not good idea to use it in production systems. Instead they should be using proper drivers for peripherals connected to the SPI bus. Signed-off-by: Mika Westerberg --- drivers/spi/spidev.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c index e3c19f30f591..8dcad01b786d 100644 --- a/drivers/spi/spidev.c +++ b/drivers/spi/spidev.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -700,6 +701,16 @@ static const struct of_device_id spidev_dt_ids[] = { MODULE_DEVICE_TABLE(of, spidev_dt_ids); #endif +#ifdef CONFIG_ACPI +static const struct acpi_device_id spidev_acpi_ids[] = { + { "SPT0001" }, + { "SPT0002" }, + { "SPT0003" }, + {}, +}; +MODULE_DEVICE_TABLE(acpi, spidev_acpi_ids); +#endif + /*-------------------------------------------------------------------------*/ static int spidev_probe(struct spi_device *spi) @@ -719,6 +730,15 @@ static int spidev_probe(struct spi_device *spi) !of_match_device(spidev_dt_ids, &spi->dev)); } + /* + * The ACPI SPT000* devices are only meant for development and + * testing. Systems used in production should have a proper ACPI + * description of the connected peripheral and they should also use + * a proper driver instead of poking directly to the SPI bus. + */ + if (has_acpi_companion(&spi->dev)) + dev_warn(&spi->dev, "do not use this driver in production systems!\n"); + /* Allocate driver data */ spidev = kzalloc(sizeof(*spidev), GFP_KERNEL); if (!spidev) @@ -789,6 +809,7 @@ static struct spi_driver spidev_spi_driver = { .driver = { .name = "spidev", .of_match_table = of_match_ptr(spidev_dt_ids), + .acpi_match_table = ACPI_PTR(spidev_acpi_ids), }, .probe = spidev_probe, .remove = spidev_remove,