From patchwork Wed Sep 6 11:26:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 111760 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp705109qge; Wed, 6 Sep 2017 04:27:14 -0700 (PDT) X-Received: by 10.84.233.66 with SMTP id k2mr7642200plt.85.1504697233953; Wed, 06 Sep 2017 04:27:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504697233; cv=none; d=google.com; s=arc-20160816; b=r2Ue1iSRDkLyYLl1EhyWyTVtNZHpIMRHDVe6mdS4+IzUkQHrJo47apUJtLXeEb0qmF g9KSU2IitCqRR463+zbRbq++tTJLrSXVhkrr75wJHJbNmC7ONaNKBFqYdBX41mdi18TM 8p6qUyFk0g6QNjLkz2c5oWfhwDCK+R/jdcMWcTwSSmNq+r1nVsPbWnkgQmEJ3IbhnRSN dZn8qh6y2m8pMCVSlU/GeH9SKNTrJpZbZX/0YWzqHggk3/kpWBkfr3V6dbZ8RW9b+h6h oVnR8ZUjHvQBsRl7Q+8IsG0DFzpgNgGBQMlOZ4lqWPuLGoyfaKYw1Nvv95tAqc+noncb tGfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=/uzlyyV3uQSS9RzOig53KVZ9pT9fMUPQ50shT3JiCFo=; b=hEv4qfYbswqxgx5RAe+W9rMB7NuFjbnjHIDmh0no99HATbffi5ZbNImqLbavTg6aKh rchwgqnrvo3Z7cWFcD2HdC/f6FSe4vKKtmOnrZO8Rlnk7sZJ26Usq3yCXtrjtHMO97CD +VoHOk5RLlkX7WMphbG0F62CMYRYry+Din8+XOxGYjQ5lOZ8YEWNaLLywb5OQtRDqJee FDZplRsenS0+bOc8zrRbMnsADZP7H/Cf3SCKtpxigcx2AbJ0+fr0+ojXKxtQu3YaXyxf 7HDtadvGdmmYJ73HNEOdZWiyMlbGuFiNDd1PhKsHL7Acxve4ERTRciJLClO7vATLoT0y jBxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=JNfGL83/; spf=pass (google.com: best guess record for domain of linux-spi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-spi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c131si1009394pga.649.2017.09.06.04.27.13; Wed, 06 Sep 2017 04:27:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-spi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=JNfGL83/; spf=pass (google.com: best guess record for domain of linux-spi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-spi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753145AbdIFL1N (ORCPT + 1 other); Wed, 6 Sep 2017 07:27:13 -0400 Received: from mail-pf0-f170.google.com ([209.85.192.170]:33530 "EHLO mail-pf0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753079AbdIFL1M (ORCPT ); Wed, 6 Sep 2017 07:27:12 -0400 Received: by mail-pf0-f170.google.com with SMTP id y68so12390164pfd.0 for ; Wed, 06 Sep 2017 04:27:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=suWj0hyHl2/t/uiYJ9+AWzDukI0J4ui2wlZfyl9JWjM=; b=JNfGL83/YQZeSyWhyJaC+JbjuQslQFr1442vslMaEXuWOnx9CzCSF9R6W4njlifZNY YA9T7UGregNz0tJeNBb15PFmSGWkzCCXbB63autyT4tt7SQ3Q1WCho3Q8nNsnVeeA/6W 3m7U5A39oorREeFN0q8hib9PHty2QtwpbfjXc= 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=suWj0hyHl2/t/uiYJ9+AWzDukI0J4ui2wlZfyl9JWjM=; b=f1dUCxIPsg6R4rLV0BiuHxcW14vBIsCQkvJUL/4zW8i+Npo/F6UVcCv+hgxTsJJzyg fe0g9z2Au/9krFRDtnUs29hH1upeMO/K5LEgbe/dCgHm/vnp7uGcJ0+SyM+iu+3C7HPk kW3nWFP2/+lXLgJq2KNAD4TKL+f4ao3tMwIrngmBo8l0ELdQ4MVULrtbAI+8t0oBuICx vlTfit9KyoxO9cwyxGDE6M3wqUa4CadZaHHoJe7JTqXiYSWY9w+M3rKjvwqe+LZ2AwP8 hGErggLbR2d47Eu1HPqI117Q0KDQINA5OM/kkQuoU6XJOvkqlKZs2ObjHNw+F+ppXufn HadQ== X-Gm-Message-State: AHPjjUhfVQ2/AcgxhcxyLuomAKksYgHvcXjHxiMk9lKVaMqK8f1N0OGb zyxlXnsTq85G29F2aq0cHA== X-Google-Smtp-Source: ADKCNb4IxRJPQvqRrWoUfYkb0MvWaOlXxCV+W2R4SeukdCTiVJZ+1uCCUXd/1MV4PgbHShnNkoLNcA== X-Received: by 10.84.244.204 with SMTP id f12mr8129362plt.32.1504697231626; Wed, 06 Sep 2017 04:27:11 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id o73sm2702508pfk.96.2017.09.06.04.27.09 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 06 Sep 2017 04:27:10 -0700 (PDT) From: Baolin Wang To: broonie@kernel.org Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, baolin.wang@linaro.org Subject: [PATCH] spi: Use ida to manage SPI bus number Date: Wed, 6 Sep 2017 19:26:51 +0800 Message-Id: <2a15b398a8f8d3f6f46f9fd6e8591242d29c44a2.1504697026.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org This patch adds one static ida variable to manage SPI bus number, moreover we can get dynamic bus number from ida instead of one "dynamic" IDs, which can be removed. Signed-off-by: Baolin Wang --- drivers/spi/spi.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 4fcbb0a..1498be2 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -40,10 +40,13 @@ #include #include #include +#include #define CREATE_TRACE_POINTS #include +static DEFINE_IDA(spi_bus_ida); + static void spidev_release(struct device *dev) { struct spi_device *spi = to_spi_device(dev); @@ -2052,7 +2055,6 @@ static int of_spi_register_master(struct spi_controller *ctlr) */ int spi_register_controller(struct spi_controller *ctlr) { - static atomic_t dyn_bus_id = ATOMIC_INIT((1<<15) - 1); struct device *dev = ctlr->dev.parent; struct boardinfo *bi; int status = -ENODEV; @@ -2076,12 +2078,15 @@ int spi_register_controller(struct spi_controller *ctlr) if ((ctlr->bus_num < 0) && ctlr->dev.of_node) ctlr->bus_num = of_alias_get_id(ctlr->dev.of_node, "spi"); - /* convention: dynamically assigned bus IDs count down from the max */ + if (ctlr->bus_num >= 0) + ctlr->bus_num = ida_simple_get(&spi_bus_ida, ctlr->bus_num, + ctlr->bus_num + 1, GFP_KERNEL); + if (ctlr->bus_num < 0) { - /* FIXME switch to an IDR based scheme, something like - * I2C now uses, so we can't run out of "dynamic" IDs - */ - ctlr->bus_num = atomic_dec_return(&dyn_bus_id); + ctlr->bus_num = ida_simple_get(&spi_bus_ida, 0, 0, GFP_KERNEL); + if (ctlr->bus_num < 0) + return ctlr->bus_num; + dynamic = 1; } @@ -2128,7 +2133,10 @@ int spi_register_controller(struct spi_controller *ctlr) /* Register devices from the device tree and ACPI */ of_register_spi_devices(ctlr); acpi_register_spi_devices(ctlr); + + return 0; done: + ida_simple_remove(&spi_bus_ida, ctlr->bus_num); return status; } EXPORT_SYMBOL_GPL(spi_register_controller); @@ -2202,6 +2210,7 @@ void spi_unregister_controller(struct spi_controller *ctlr) list_del(&ctlr->list); mutex_unlock(&board_lock); + ida_simple_remove(&spi_bus_ida, ctlr->bus_num); dummy = device_for_each_child(&ctlr->dev, NULL, __unregister); device_unregister(&ctlr->dev); }