From patchwork Thu Jan 12 22:21:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Bostic X-Patchwork-Id: 9514297 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 95506601E7 for ; Thu, 12 Jan 2017 22:22:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9C37028710 for ; Thu, 12 Jan 2017 22:22:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 90C2028719; Thu, 12 Jan 2017 22:22:03 +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=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3435528710 for ; Thu, 12 Jan 2017 22:22:03 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cRnkw-0001Nm-Hb; Thu, 12 Jan 2017 22:22:02 +0000 Received: from mail-oi0-x243.google.com ([2607:f8b0:4003:c06::243]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cRnks-0001Mr-TP for linux-arm-kernel@lists.infradead.org; Thu, 12 Jan 2017 22:22:00 +0000 Received: by mail-oi0-x243.google.com with SMTP id w144so368533oiw.1 for ; Thu, 12 Jan 2017 14:21:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=GfqLaQgOscRKDP4r8fgyPwPEPezW6xXhdJx2iy1kc9U=; b=FulpdnvE7zd61386nIFs9uQp9X57yqZaNJxDV9CQh7odIzoIag+ofZZCOTwbreWZG+ qnF1YjNYzEJTQAzIkEI5j+F66ogxwtSM/mdxikMpqujAxTsRtqfgOwZ0tuh0LN7dNgWl y6hsXZPTrO8YKo4yViSW/fBzJ27Zn/qseMN99Lo2ZVdMrS47YDnC8s91z+tM1tKN+590 BEdA3IH6+j8/122MVFdee6C7fPAc3tPvTErFvhirwf0f9qqBD1mGeMeCs7tBYG2zq0i4 oHFPAQAhQ1FwcvBUK95L2p/afz67M3PlUUm4WUuoBbpoDaKs47gmI/R658W/4rjJmOQu WWAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=GfqLaQgOscRKDP4r8fgyPwPEPezW6xXhdJx2iy1kc9U=; b=t9ixJb8w9vK28Kzp6CiHVkpfiMULXy2ITYPHod1mqHRkvVmJRsOwyOu1X3nsLBSt9z bV0INZqF+S2Qm2zIZigAN9Pxfmx6Y45RZRpNFByo/UnVOr5sTu+1xpTWglr9MSQIZsp8 rKhBzS6XpQwCb/j1C22Mjj7K+tnnOCqG2eGx2pGJfA7BpT6EMG6DGtYlrL2EW/ssmiPO 6Sf80vi3WIOw6wHI+OQ1Jc1o3QVSfGWqkhKvVnU/G9Z/ZJ4sc1YA84ZB9dwhA1qHHemP vwlw0rqk7MSMDcr383GDgPuPo0y8M2pxi7i2rqXBv4xlkRF35ELrJaH/P/KnW+AipkHC moaQ== X-Gm-Message-State: AIkVDXJUzpRiOkCDVTSPCaOFuoc5wZjOU5iwaFRf+9zxO4uuqgNceZ5uK2gEI1u7GdeJdw== X-Received: by 10.202.51.8 with SMTP id z8mr7879704oiz.79.1484259697764; Thu, 12 Jan 2017 14:21:37 -0800 (PST) Received: from Christophers-MacBook-Pro.local.com (45-20-192-79.lightspeed.austtx.sbcglobal.net. [45.20.192.79]) by smtp.gmail.com with ESMTPSA id 97sm4815852otp.37.2017.01.12.14.21.36 (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 12 Jan 2017 14:21:36 -0800 (PST) From: christopher.lee.bostic@gmail.com To: robh+dt@kernel.org, mark.rutland@arm.com, linux@armlinux.org.uk, gregkh@linuxfoundation.org, mturquette@baylibre.com, geert+renesas@glider.be, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, joel@jms.id.au, jk@ozlabs.org, linux-kernel@vger.kernel.org, andrew@aj.id.au, alistair@popple.id.au, benh@kernel.crashing.org Subject: [PATCH v2 02/18] drivers/fsi: add driver to device matches Date: Thu, 12 Jan 2017 16:21:33 -0600 Message-Id: <1484259693-79062-1-git-send-email-christopher.lee.bostic@gmail.com> X-Mailer: git-send-email 2.7.4 (Apple Git-66) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170112_142159_005820_DBEDFA44 X-CRM114-Status: GOOD ( 12.71 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Chris Bostic MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jeremy Kerr Driver bind to devices based on the engine types & (optional) versions. Signed-off-by: Jeremy Kerr Signed-off-by: Chris Bostic --- drivers/fsi/fsi-core.c | 21 +++++++++++++++++++++ include/linux/fsi.h | 21 +++++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/drivers/fsi/fsi-core.c b/drivers/fsi/fsi-core.c index 3e45306..3d55bd5 100644 --- a/drivers/fsi/fsi-core.c +++ b/drivers/fsi/fsi-core.c @@ -19,8 +19,29 @@ /* FSI core & Linux bus type definitions */ +static int fsi_bus_match(struct device *dev, struct device_driver *drv) +{ + struct fsi_device *fsi_dev = to_fsi_dev(dev); + struct fsi_driver *fsi_drv = to_fsi_drv(drv); + const struct fsi_device_id *id; + + if (!fsi_drv->id_table) + return 0; + + for (id = fsi_drv->id_table; id->engine_type; id++) { + if (id->engine_type != fsi_dev->engine_type) + continue; + if (id->version == FSI_VERSION_ANY || + id->version == fsi_dev->version) + return 1; + } + + return 0; +} + struct bus_type fsi_bus_type = { .name = "fsi", + .match = fsi_bus_match, }; EXPORT_SYMBOL_GPL(fsi_bus_type); diff --git a/include/linux/fsi.h b/include/linux/fsi.h index f73886a..273cbf6 100644 --- a/include/linux/fsi.h +++ b/include/linux/fsi.h @@ -18,11 +18,28 @@ #include struct fsi_device { - struct device dev; + struct device dev; + u8 engine_type; + u8 version; }; +struct fsi_device_id { + u8 engine_type; + u8 version; +}; + +#define FSI_VERSION_ANY 0 + +#define FSI_DEVICE(t) \ + .engine_type = (t), .version = FSI_VERSION_ANY, + +#define FSI_DEVICE_VERSIONED(t, v) \ + .engine_type = (t), .version = (v), + + struct fsi_driver { - struct device_driver drv; + struct device_driver drv; + const struct fsi_device_id *id_table; }; #define to_fsi_dev(devp) container_of(devp, struct fsi_device, dev)