From patchwork Thu Sep 20 19:18:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trent Piepho X-Patchwork-Id: 10608633 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 3FD376CB for ; Thu, 20 Sep 2018 19:18:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D73F2E3CE for ; Thu, 20 Sep 2018 19:18:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 212612E3D2; Thu, 20 Sep 2018 19:18:34 +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 6FC6F2E3CE for ; Thu, 20 Sep 2018 19:18:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388696AbeIUBDb (ORCPT ); Thu, 20 Sep 2018 21:03:31 -0400 Received: from mail-eopbgr730120.outbound.protection.outlook.com ([40.107.73.120]:38336 "EHLO NAM05-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388652AbeIUBDa (ORCPT ); Thu, 20 Sep 2018 21:03:30 -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=McdikINQNlbshycr2pgBDBsdxjXfOjKs9SaZG9eQdOM=; b=fwllgcNiX38NQJXwiho9IFNoh76F2To3NzvybNXes2RZmJpdlFe6xWf6PJY7tM/i5+s9dl5JQsRnIUBcvc1Yez4gvNEB4NllJmRvoSDEs7uoWQRR7JFWdpn0xO+USF6Bja4pmUDbRBNgGzaGLoSFV3StKQfZJgdzlfLv2Rs5Wt0= 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:28 +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:28 +0000 From: Trent Piepho To: "linux-spi@vger.kernel.org" CC: Henry Gomersall , Geert Uytterhoeven , Kyle Roeschley , Mark Brown , Trent Piepho Subject: [PATCH v2 0/3] device tree spidev solution - driver_override for SPI Thread-Topic: [PATCH v2 0/3] device tree spidev solution - driver_override for SPI Thread-Index: AQHUURa1Kj/OWNDId0uWyrquV09NwA== Date: Thu, 20 Sep 2018 19:18:27 +0000 Message-ID: <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:MzgtVvq4AxYwaLBm1TAfWo+USkeuxm5Y6dZCqqanV9YLvp0rnfxBxkylayj7OdhNmfuDLQlW2Hirys+p5xl1T0zZu/H7/TOnPbfeJ85gS37qgDxocazDU3D6T2bovpyyHntA2AMtySRS44EvZpVTiHDyBpeIeNUVUCrJ8QohXnFBZrvIG9cu9GXrnqCOaG7GOnmXosVuN2ZNVgfs+QoyXEckymTNAWGgdHmurIrWWYWNPf4lwzFzvOIcmowTo701NzWst9v7gF6X4uaiyzkJe01sGitOtgx33r/I6AAlf5aj2o5CTuWs1MuLV0ewiOS9LbdsdJsh79MReR042++t0uY7sHh486wLkwDqhko+IbuS0TC9eR4K5EFkwnltJ0jB0mLgWcOtNKBo15vZ0M08Xdg7aYNrHMhZj1hMatB8yMIq9Yf3e1wUeoNixRjU2ubW7WaksbKpnBv0xFwXbnudJg==;5:dEuDl1pPjJQ05gFzZvQGrY1w3yLwXFGEQUp20PWYUd9LFch+dVnaAWXYMYMvfBnzK8rQrbXx4W3kUM+zcrQdiPy9CiIR+Y3gzzxyaTiT5ngLjyHsLUVtU+I7ENRs+HeWFM6mBO/ncL2WdWVNgbofmbcfTSkZJ/e3FxI4bNsznf8=;7:Q8wgwOv8i3anIjj9pIu2dTeBGxUyFmkXBQlMD3Co4chdHjvvwjRU2ua0qwqYhs6id2kVQLnOUFitDyOjsfeyDLaTBIuKnGp2aEW4nzKxZOxubAzRfZZ0Hn8kEllPrxL65/0OwuwVyPJ6RZMIK+pdCPPijX/kznCBR52SQ9QJqc55M6j8YV1elj+uIzw6JWF7t2LCd5xky+h6heyn3YZINd2E3nVFNJWfGFBVPpZIn0Fqh51xTQekNDRRDRCwLKWh x-ms-office365-filtering-correlation-id: 94be164c-827a-4ec5-7661-08d61f2dd7b8 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:(17755550239193); 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)(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)(5024004)(256004)(186003)(6346003)(26005)(486006)(102836004)(386003)(6506007)(5640700003)(6436002)(68736007)(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: v5LTW6w7dCLlcCdNSsH+g5XV5jyVDfHP5+z3TQpEJPznbmaUdYH4Dmy4Ys4bG3BDmmH5314Mje3BmukxPo8KHn8cCbzzGHpGx/Fbyvy9ay7gxojs9Rv8e23W6RwfMkD8XaPtq9RBharWqGQ2yXWt2/ODc5HjBmvLgkRkxyR8UfJyNFPoETWhwbhjJHX3fHy+9azwYaroHN33C422GqHCTP5iqUwlRbLdugWx+hZ5D7WwV/eCtU51Wn9OnWnm4YJMblPZTw/eZeruoqu2YSl2QL931ii9MUG0HrLlqR9E+rVBFeqa+2X095IPkJdesKrTYhzVi0jWmzmzB5hYRiqDdzYNtAh9nwi+c5DNwB0wEw8= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: impinj.com X-MS-Exchange-CrossTenant-Network-Message-Id: 94be164c-827a-4ec5-7661-08d61f2dd7b8 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Sep 2018 19:18:28.2010 (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 is an attempt to solve the problem of binding spidev to a device on a device-tree system. Explicitly listing spidev in the "compatible" property of a device is not allowed, as it not type of the device but rather a Linux specific driver name. The current solution is to list every possible device spidev can be bound to, but this is highly unsatisfactory. 1. Needing to patch and compile the kernel is a significant barrier to many who could otherwise make use of embedded dev kits, such as RPi, that have SPI hardware. 2. Up-streaming a new spi device ID is a lengthy undertaking even to those who know how. This causes unneeded delay in upstream kernel support for a new device. 3. Maintaining a list of obscure and one-off device IDs in the spidev driver is largely a waste of effort to nearly every developer to use the driver. 4. It's not possible to bind a device that has a kernel SPI driver to spidev instead of its normal driver. This is quite useful to debug hardware problems, development of the kernel driver, and testing SPI bus timing, impedance, etc. It can also be used to access device features, like a one time programming step, that the device's kernel driver does not necessary need to support. This approach should solve these problems. Three existing Linux busses - AMBA, PCI, and platform - give device's a "driver_override" attribute, which can be used to bind them to a driver without requiring a match against the driver's device ID table. This can be used to bind spidev to a device without needing to add the device to some list inside the spidev driver. Udev rules can be written to make this automatic, example: ACTION=="add|change",, SUBSYSTEM=="spi", ENV{MODALIAS}=="spi:adrf6820", ATTR{driver_override}+="spidev" This will automatically bind a device that claims (likely via device-tree compatible value) to be an "adrf6820" to spidev. Additional rules could be imagined to bind specific spi bus chip selects, or any device on a certain bus, or via the device's node name in the device tree, to spidev. Changes from v1: - Fix leak on device release with override set - Simplifly spidev warn logic and remove dev_err - Split automatic attach attempt into another commit Trent Piepho (3): spi: Add driver_override SPI device attribute spi: Automatically attempt attach after driver_override alteration spi: spidev: Fix OF tree warning logic drivers/spi/spi.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ drivers/spi/spidev.c | 8 +++---- include/linux/spi/spi.h | 1 + 3 files changed, 62 insertions(+), 5 deletions(-) Tested-by: Kyle Roeschley