From patchwork Thu Sep 20 19:18:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Trent Piepho X-Patchwork-Id: 10608635 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B47C05A4 for ; Thu, 20 Sep 2018 19:18:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A06A02E3CE for ; Thu, 20 Sep 2018 19:18:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 921422E3D2; Thu, 20 Sep 2018 19:18:38 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,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 18F332E3CE for ; Thu, 20 Sep 2018 19:18:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388733AbeIUBDe (ORCPT ); Thu, 20 Sep 2018 21:03:34 -0400 Received: from mail-eopbgr690137.outbound.protection.outlook.com ([40.107.69.137]:14528 "EHLO NAM04-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388652AbeIUBDd (ORCPT ); Thu, 20 Sep 2018 21:03:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=impinj.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jGNdetkgkllBoqIouaP6QqHsEuc1chzVA9IwuomxqNA=; b=euYBr1kZt2LFLwX7GIwwqAdKsoKX0kiyjplY6cANzbL55D4WcicQVZg5LsXl3f0zorK1YnWn7ZQU/BcWK1VTDrfofpCzs1IZx4lniB0+XrD2iYBBUfiE+zXPQX41pTW9cU8fcJ1N8mq0rGSSJl0rfKa7Ydb2IOWy61bls0cRzec= Received: from MWHPR0601MB3708.namprd06.prod.outlook.com (10.167.236.38) by MWHPR0601MB3675.namprd06.prod.outlook.com (10.167.236.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1143.18; Thu, 20 Sep 2018 19:18:32 +0000 Received: from MWHPR0601MB3708.namprd06.prod.outlook.com ([fe80::eca3:1c00:bc20:bc48]) by MWHPR0601MB3708.namprd06.prod.outlook.com ([fe80::eca3:1c00:bc20:bc48%4]) with mapi id 15.20.1143.019; Thu, 20 Sep 2018 19:18:32 +0000 From: Trent Piepho To: "linux-spi@vger.kernel.org" CC: Henry Gomersall , Geert Uytterhoeven , Kyle Roeschley , Mark Brown , Trent Piepho Subject: [PATCH v2 1/3] spi: Add driver_override SPI device attribute Thread-Topic: [PATCH v2 1/3] spi: Add driver_override SPI device attribute Thread-Index: AQHUURa4/r5gmOf7bUOz+h7uG4sA1A== Date: Thu, 20 Sep 2018 19:18:32 +0000 Message-ID: <20180920191759.17781-2-tpiepho@impinj.com> References: <20180920191759.17781-1-tpiepho@impinj.com> In-Reply-To: <20180920191759.17781-1-tpiepho@impinj.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: DM5PR13CA0026.namprd13.prod.outlook.com (2603:10b6:3:7b::12) To MWHPR0601MB3708.namprd06.prod.outlook.com (2603:10b6:301:7c::38) x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [216.207.205.253] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;MWHPR0601MB3675;6:Yk3F5k1fLG05ACRYlY2+xpk9QCZlyw2PpuXOFONYT9UCUvhvDS2+HOnEgAbX9aVAn7jTCpG+CmqVLvLQBPNQpOjYfzWBDFqqj6NAzd2z86V5Xq86tXt8/SDTjqytlSaT7CjBLRREUpqbdH1vykf/b2E5NALwhO95n6G51l0MU0Q8uLzqF82eMceYur7D4FjgqO+tmerwOJdytxuOJ6ROJYnIqGTutHLMKZKPPPrX0bqsoHR0ga867UgzNbuE/K0losyms59ownoBE3gkllBJpEsfEjgbTa8p7DhU43oxRnyrnYQUxpL+Old3vnVfTSEd3LMmbyuq2oOropD4xVzHgMgSeOk6mxsw5MvXvS0a9KdUQn/0vUt73W9jAv+5sYzEntY66pEiKsLjbui8j3LHurK+BGGSFtSVuT27xpYygRXEMYvKIEah77Oeu8XWZcML+7Gb5fg3v6kismqE2Nq0ZA==;5:zB1t9xCWBD28POtrqU+CjnBH0fxPuH2omP++s+Rk4nvrF+UC60h3hfZwdnRntMMalKTpPTH/koih0hpE2+NfWb6kC+d/fl6mIclWrlxHvK801l5z/0c0Z5VpPSFIs+FIM1I456BijtmNR92LIFDwlNCsiFozK1fBsTn9XCW0sKI=;7:O+g6fgB+IOsIZDE0T9Q8cPQ9fh9iey5OLr2WIykQxB4AQFpoX1dm4PC85G3zFU4Y1beDkcyM+sIkVTVJOfzjt3cqw9QJ1vUt61De6nyVrdnjQPTyCA5+q8eCxyrkg0EkXGpP/awasbpERK4FbvsPZGyLyg0dmEGWGoDUWOXWBoIPyF6GkJsmlLqy8uUBF3idPD2ktRwFKl7OkAzR5mseNIq7umnCxgeQiVdM7gg49qqaUOBAofn72I5LblJfOAaA x-ms-office365-filtering-correlation-id: 2256a4f4-1242-468d-064a-08d61f2dda75 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020);SRVR:MWHPR0601MB3675; x-ms-traffictypediagnostic: MWHPR0601MB3675: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3231355)(944501410)(52105095)(3002001)(93006095)(93001095)(10201501046)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123558120)(20161123562045)(201708071742011)(7699051)(76991041);SRVR:MWHPR0601MB3675;BCL:0;PCL:0;RULEID:;SRVR:MWHPR0601MB3675; x-forefront-prvs: 0801F2E62B x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39850400004)(396003)(376002)(346002)(136003)(366004)(199004)(189003)(4326008)(3846002)(6512007)(5250100002)(6116002)(76176011)(36756003)(2501003)(53936002)(1076002)(2906002)(99286004)(52116002)(316002)(54906003)(81166006)(81156014)(5660300001)(105586002)(106356001)(2351001)(97736004)(14454004)(2900100001)(8936002)(8676002)(71190400001)(71200400001)(478600001)(305945005)(7736002)(6916009)(14444005)(66066001)(86362001)(575784001)(256004)(186003)(6346003)(26005)(486006)(102836004)(386003)(11346002)(6506007)(5640700003)(6436002)(68736007)(446003)(476003)(2616005)(6486002)(107886003)(25786009);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR0601MB3675;H:MWHPR0601MB3708.namprd06.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: impinj.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=tpiepho@impinj.com; x-microsoft-antispam-message-info: Vn/ueiAskabZrhixwWzJPDofANOt6N9G/mH96Vq8tg8CRIkdbYQMjWJUBAfrjKuiixMEZnZHpINE/6yotcijnfmMrj4AdBPssSBq/E6JGqsqy14OVb1FU7PihtCh9OMyfcdf8lMZUPBJH+0QWVM3n3PJJTz3D9MC+mXRKuMuM1blD5g049rLDhVhHQOlvJrF8LE/QJ+5Fnz7NIfViWQ2PWLLEdZhEdSNuqZAR0v2MjzFcd9mmJFr4HZ82CNnt/MdAAW5aXym8Yjf4Ttv7q1N0JSZRA19MDVvD6W+uwIe/1odwglTfoEYfVPK+4M+9yz6R9tDtyMzHkNFNvamHzPqhsRVJYBO8iIDgW7erIvOlTg= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: impinj.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2256a4f4-1242-468d-064a-08d61f2dda75 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Sep 2018 19:18:32.2508 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 6de70f0f-7357-4529-a415-d8cbb7e93e5e X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR0601MB3675 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 This attribute works the same was as the identically named attribute for PCI, AMBA, and platform devices. For reference, see: commit 3cf385713460 ("ARM: 8256/1: driver coamba: add device binding path 'driver_override'") commit 3d713e0e382e ("driver core: platform: add device binding path 'driver_override'") commit 782a985d7af2 ("PCI: Introduce new device binding path using pci_dev.driver_override") If the name of a driver is written to this attribute, then the device will bind to the named driver and only the named driver. The device will bind to the driver even if the driver does not list the device in its id table. This behavior is different than the driver's bind attribute, which only allows binding to devices that are listed as supported by the driver. It can be used to bind a generic driver, like spidev, to a device. Signed-off-by: Trent Piepho Reviewed-by: Jan Kundrát Tested-by: Jan Kundrát Reviewed-by: Geert Uytterhoeven --- drivers/spi/spi.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/spi/spi.h | 1 + 2 files changed, 52 insertions(+) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 03833924ca6c..823fc130248b 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -60,6 +60,7 @@ static void spidev_release(struct device *dev) spi->controller->cleanup(spi); spi_controller_put(spi->controller); + kfree(spi->driver_override); kfree(spi); } @@ -77,6 +78,51 @@ modalias_show(struct device *dev, struct device_attribute *a, char *buf) } static DEVICE_ATTR_RO(modalias); +static ssize_t driver_override_store(struct device *dev, + struct device_attribute *a, + const char *buf, size_t count) +{ + struct spi_device *spi = to_spi_device(dev); + const char *end = memchr(buf, '\n', count); + const size_t len = end ? end - buf : count; + const char *driver_override, *old; + + /* We need to keep extra room for a newline when displaying value */ + if (len >= (PAGE_SIZE - 1)) + return -EINVAL; + + driver_override = kstrndup(buf, len, GFP_KERNEL); + if (!driver_override) + return -ENOMEM; + + device_lock(dev); + old = spi->driver_override; + if (len) { + spi->driver_override = driver_override; + } else { + /* Emptry string, disable driver override */ + spi->driver_override = NULL; + kfree(driver_override); + } + device_unlock(dev); + kfree(old); + + return count; +} + +static ssize_t driver_override_show(struct device *dev, + struct device_attribute *a, char *buf) +{ + const struct spi_device *spi = to_spi_device(dev); + ssize_t len; + + device_lock(dev); + len = snprintf(buf, PAGE_SIZE, "%s\n", spi->driver_override ? : ""); + device_unlock(dev); + return len; +} +static DEVICE_ATTR_RW(driver_override); + #define SPI_STATISTICS_ATTRS(field, file) \ static ssize_t spi_controller_##field##_show(struct device *dev, \ struct device_attribute *attr, \ @@ -158,6 +204,7 @@ SPI_STATISTICS_SHOW(transfers_split_maxsize, "%lu"); static struct attribute *spi_dev_attrs[] = { &dev_attr_modalias.attr, + &dev_attr_driver_override.attr, NULL, }; @@ -305,6 +352,10 @@ static int spi_match_device(struct device *dev, struct device_driver *drv) const struct spi_device *spi = to_spi_device(dev); const struct spi_driver *sdrv = to_spi_driver(drv); + /* Check override first, and if set, only use the named driver */ + if (spi->driver_override) + return strcmp(spi->driver_override, drv->name) == 0; + /* Attempt an OF style match */ if (of_driver_match_device(dev, drv)) return 1; diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 7bb36145e2ba..d90e55029704 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -168,6 +168,7 @@ struct spi_device { void *controller_state; void *controller_data; char modalias[SPI_NAME_SIZE]; + const char *driver_override; int cs_gpio; /* chip select gpio */ /* the statistics */