From patchwork Thu Apr 11 22:11:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brandon Maier X-Patchwork-Id: 10897017 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 57602922 for ; Thu, 11 Apr 2019 22:20:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4231F28D77 for ; Thu, 11 Apr 2019 22:20:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 36D6828DE7; Thu, 11 Apr 2019 22:20:52 +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=-7.9 required=2.0 tests=BAYES_00,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 A6EA228D05 for ; Thu, 11 Apr 2019 22:20:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726636AbfDKWUv (ORCPT ); Thu, 11 Apr 2019 18:20:51 -0400 Received: from da1vs03.rockwellcollins.com ([205.175.227.47]:11497 "EHLO da1vs03.rockwellcollins.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726825AbfDKWUu (ORCPT ); Thu, 11 Apr 2019 18:20:50 -0400 X-Greylist: delayed 566 seconds by postgrey-1.27 at vger.kernel.org; Thu, 11 Apr 2019 18:20:50 EDT Received: from ofwda1n02.rockwellcollins.com (HELO crulimr01.rockwellcollins.com) ([205.175.227.14]) by da1vs03.rockwellcollins.com with ESMTP; 11 Apr 2019 17:11:24 -0500 X-Received: from righttwix.rockwellcollins.com (righttwix.rockwellcollins.com [192.168.141.218]) by crulimr01.rockwellcollins.com (Postfix) with ESMTP id DF4996032F; Thu, 11 Apr 2019 17:11:23 -0500 (CDT) From: Brandon Maier To: atull@kernel.org, mdf@kernel.org Cc: linux-fpga@vger.kernel.org, clayton.shotwell@rockwellcollins.com, Brandon Maier Subject: [PATCH] fpga: mgr: Use devicetree /alias to assign FPGA IDs Date: Thu, 11 Apr 2019 17:11:09 -0500 Message-Id: <20190411221109.173242-1-brandon.maier@rockwellcollins.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: linux-fpga-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The fpga-mgr assigns device IDs based on the order each driver calls fpga_mgr_register(). This is fine for systems with one FPGA, but if multiple FPGAs are in use, the device ID can change as probe order changes across reboots or configuration changes. This makes it difficult to use the sysfs attributes, as the device path may change. Instead allow a static ID to be set by adding fpgaX props to the devicetree /aliases. Falling back to incrementing IDs if none are provided. This is based on the function rtc_device_get_id() in drivers/rtc/class.c (9d2b7e532da8 rtc: honor device tree /alias entries when assigning IDs). Signed-off-by: Brandon Maier Acked-by: Alan Tull --- drivers/fpga/fpga-mgr.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c index c3866816456a..d8b7e7a61117 100644 --- a/drivers/fpga/fpga-mgr.c +++ b/drivers/fpga/fpga-mgr.c @@ -551,6 +551,26 @@ void fpga_mgr_unlock(struct fpga_manager *mgr) } EXPORT_SYMBOL_GPL(fpga_mgr_unlock); +static int fpga_mgr_get_id(struct device *dev) +{ + int of_id = -1, id = -1; + + if (dev->of_node) + of_id = of_alias_get_id(dev->of_node, "fpga"); + + if (of_id >= 0) { + id = ida_simple_get(&fpga_mgr_ida, of_id, of_id + 1, + GFP_KERNEL); + if (id < 0) + dev_warn(dev, "/aliases ID %d not available\n", of_id); + } + + if (id < 0) + id = ida_simple_get(&fpga_mgr_ida, 0, 0, GFP_KERNEL); + + return id; +} + /** * fpga_mgr_create - create and initialize a FPGA manager struct * @dev: fpga manager device from pdev @@ -586,7 +606,7 @@ struct fpga_manager *fpga_mgr_create(struct device *dev, const char *name, if (!mgr) return NULL; - id = ida_simple_get(&fpga_mgr_ida, 0, 0, GFP_KERNEL); + id = fpga_mgr_get_id(dev); if (id < 0) { ret = id; goto error_kfree;