From patchwork Thu Jan 21 18:33:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 8084201 Return-Path: X-Original-To: patchwork-linux-spi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 06D109F6FA for ; Thu, 21 Jan 2016 18:34:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 27A702045B for ; Thu, 21 Jan 2016 18:34:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 37D8B20461 for ; Thu, 21 Jan 2016 18:34:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759809AbcAUSeB (ORCPT ); Thu, 21 Jan 2016 13:34:01 -0500 Received: from mail-wm0-f47.google.com ([74.125.82.47]:35265 "EHLO mail-wm0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759781AbcAUSeA (ORCPT ); Thu, 21 Jan 2016 13:34:00 -0500 Received: by mail-wm0-f47.google.com with SMTP id r129so183852194wmr.0 for ; Thu, 21 Jan 2016 10:33:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=Wmiu/HMadxzXXOocOSV+F2AzD/y5hcRctK0FIiqV52Y=; b=YEYTtjlQ+X9uxJQt0VDBzynhkhnEwhKUCCKoA9cwNy+vFQBfvmMmDs73N8OoJT8Oxa sM523XpRFMdOUtbUqJayxi3NYaHjuOu9i1MF/mYse8VbMl15G5qUdBq9b7m8500Kcktn FydHevN2PHyWQ3ame+eIOwc1jg69XKDHX7VqQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Wmiu/HMadxzXXOocOSV+F2AzD/y5hcRctK0FIiqV52Y=; b=mxQPaIHwExuVO9TtZS7y0yHgqRlJF+YGN8YwCEGFWsfr0fzCnao2ejRFfQuyzDp5bv QTs33Uy3u5KzWAv+QRSaJ+AnxD34H9Sjyw8HqjIMUKNjjUxsADWPwRJS60d064nVjJCP efyH1scodNoZ2vAVXbXpmHRDWJjsJob6f7/V8fVn9DFJuYIVTcWJK77T2+r3GcGWoxBd jx05KE6Cy3LroTlUwh/aAPqUL2OIwNWLEBFbEZKxWX4P7XmmB+urXbN4tntwTH8CDNg0 DP70I/FtUMUgGkjzuxjEfIcaAHBl2xzFkMQfNQkcrXNsDkHH6yJSw3ZSevz1fgl3x9BM hPgA== X-Gm-Message-State: ALoCoQnlFXTeRMGr4QcP6dVTHZI9/jp2EOyush8U+FzEruardnZGR7IyDxSNbqh+3L3kev4SSwoBT0p1wE9BKt/J30+8sKCVMw== X-Received: by 10.194.157.165 with SMTP id wn5mr50931133wjb.41.1453401238765; Thu, 21 Jan 2016 10:33:58 -0800 (PST) Received: from localhost.localdomain (host-92-13-246-184.as43234.net. [92.13.246.184]) by smtp.gmail.com with ESMTPSA id x189sm3836060wmg.1.2016.01.21.10.33.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 21 Jan 2016 10:33:57 -0800 (PST) From: Srinivas Kandagatla To: Andy Gross , linux-spi@vger.kernel.org Cc: David Brown , Mark Brown , linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Srinivas Kandagatla Subject: [PATCH] spi: qup: provide proper bus numbers Date: Thu, 21 Jan 2016 18:33:47 +0000 Message-Id: <1453401227-27135-1-git-send-email-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 1.9.1 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This driver reuses pdev->id for spi bus numbers resulting in random or very large bus numbering when used with device trees. pdev->id is not the correct choice when using device trees. So add code to get bus numbers via device tree aliases and if it fails then generate a unique bus number. Without this patch the driver get a random and useless bus number. Signed-off-by: Srinivas Kandagatla --- drivers/spi/spi-qup.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi-qup.c b/drivers/spi/spi-qup.c index 810a7fa..2bc67a9 100644 --- a/drivers/spi/spi-qup.c +++ b/drivers/spi/spi-qup.c @@ -127,6 +127,8 @@ #define SPI_DELAY_THRESHOLD 1 #define SPI_DELAY_RETRY 10 +static atomic_t spi_qup_next_id = ATOMIC_INIT(0); + struct spi_qup { void __iomem *base; struct device *dev; @@ -759,7 +761,7 @@ static int spi_qup_probe(struct platform_device *pdev) struct device *dev; void __iomem *base; u32 max_freq, iomode, num_cs; - int ret, irq, size; + int ret, irq, size, bus_num; dev = &pdev->dev; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); @@ -816,7 +818,15 @@ static int spi_qup_probe(struct platform_device *pdev) else master->num_chipselect = num_cs; - master->bus_num = pdev->id; + if (dev->of_node) + bus_num = of_alias_get_id(dev->of_node, "spi"); + else + bus_num = pdev->id; + + if (bus_num < 0) + bus_num = atomic_inc_return(&spi_qup_next_id) - 1; + + master->bus_num = bus_num; master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LOOP; master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32); master->max_speed_hz = max_freq;