From patchwork Fri Jul 26 07:20:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 169786 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp12648171ilk; Fri, 26 Jul 2019 00:21:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqwZzoJFV3Srs9RTLxEINkMGmoK2EyKiyuM7D7kjmb/rWzEU7aOXaVQrBHaWlffRr+hL2JLg X-Received: by 2002:a65:4844:: with SMTP id i4mr91439066pgs.113.1564125703572; Fri, 26 Jul 2019 00:21:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564125703; cv=none; d=google.com; s=arc-20160816; b=fz5vt97o1ihXANGqaIHGINHzlteB4U00lUNtW2GGa4hfW7tUfNuNfr+OYXRUd/EsDy AWHdDCmYDxE6fO2uRfdIfdtroFoy7LKUKY8fCyK9vafNi+2fkF8gpm+mDAXV0+8LvHSU dQPNGciJsHvNCkOS5JHRTOxTtW3z1nRR9w3FOPISuzlp6ueEU0+niqJv6so491Jl7yHw eCLPADRy+jqzNsn3XcefkZc70rfoK4AQQ2O1wH/jh3HQOIUzMfjpAgSiPqDjyZdjxBzO y92Oy6EmFSh69gFKrbeOfG8OYabhTSeniVZZ2y9h2SY2GJJxoxj5PkIZmgIKTlz0bIsX 7MwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=NWVsUkkDHIuRmUj9QU93X+5+YMySiLs15Fa6SS5cpaE=; b=kv3sha3cJzhphsb8pXyow0tEj4+7Reo0ivfEKw7OgUGP+g6JDea5dXBBHpSOxzqCl9 JxGaKT17HzRXBe/ailoOcFLoKPQX2GUyQlPeec6p0mtiTaKTG2hamervVzq/p6iYZDA5 LDRjENE+Y+xuHNQ9VkLrWa2ixAPxt2WZVS5RAr2qgO454RGzI8SXNe/XZweCha7xCGr5 HnXhlO+h1PYerNac+eXy2ONM4pYicvRT+COZuFB28VJbP4Ab1CmctmXPH6cdo2KysAOj LG8o8dpj7PjoMj2DYvJvj6/z9ZyhBHXFTCC7GZBCzZ8y0689f4yNtcW6oxlCRngwPoB0 NLBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PV6UmmpT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (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 r17si18447977pgg.155.2019.07.26.00.21.43; Fri, 26 Jul 2019 00:21:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PV6UmmpT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726561AbfGZHVm (ORCPT + 29 others); Fri, 26 Jul 2019 03:21:42 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:33932 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726529AbfGZHVk (ORCPT ); Fri, 26 Jul 2019 03:21:40 -0400 Received: by mail-pg1-f194.google.com with SMTP id n9so18111207pgc.1 for ; Fri, 26 Jul 2019 00:21:40 -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:in-reply-to:references :in-reply-to:references; bh=NWVsUkkDHIuRmUj9QU93X+5+YMySiLs15Fa6SS5cpaE=; b=PV6UmmpTsl4qyL9YLpPEkrDLpNgZumlLqQgJL5tf2AhWNCYTaorte9k2Pj6IBUNSly P3k2AtwrjF3ASvtlPfbzMtob1Cg03Jd+goAm4I7kOQisa12ZR8ojvxgnuaesv3WCzKFe Pq4rBflmWmlGTT2BdXqwa0x25C5sGnY4r3dCX5ZxUlkDj23l8P1xT5sr2XjxSPYPgErI 6schkzFTtMrRNHU3fT2UZrOgBpsicdyIYMZgQj3x1b4OkZNx911u9ycHBJuLm7pEVZda IlKXw2hSsZESskRI+3b+vVA34+9nm2QXl2cxQB7Nb6VGGObnFHwYVgBPu6WvUEsFzssY vvvQ== 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:in-reply-to :references:in-reply-to:references; bh=NWVsUkkDHIuRmUj9QU93X+5+YMySiLs15Fa6SS5cpaE=; b=Y+Or2/DDUXYPwgSWBgAFITAleGBM6HtGe44dhSRhQ0n30w4PnUTCYlCJ0z8VFhLzXi 1ErSX6QEQ6Di+Avnm6ky0vwH+M9IT89K9hi5hKYIQVBz/gDfNqmIzV51/yCHYlbqRSYW 4hHd9m1bodBb7MBCfShovCF5winh6qvlk8UOONeZ3iQWeQf4qxbOQ6ymKT8QkTwwRzBy I349eOV+dEV5up0Z+1+GpnNavfOJqoLl3GeTf6XqjSVwIBbav3ysttuRP2qDt4f2I60j bG6795XRsLvgu2gbSyb2KPJsWcyCROSIUMduc6iaSo02LdldbT0PUz+pSjVin48rN4k4 qXGw== X-Gm-Message-State: APjAAAWUPABVvtX3eiGlvFUyfz63pAM4sVLWtE0Sa9Evn4CVOHT+EGTW cjS60LxW+7eVgMee5Yx4N4kobQ== X-Received: by 2002:a63:7358:: with SMTP id d24mr89898767pgn.224.1564125700079; Fri, 26 Jul 2019 00:21:40 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id o12sm39216152pjr.22.2019.07.26.00.21.36 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Jul 2019 00:21:39 -0700 (PDT) From: Baolin Wang To: broonie@kernel.org, robh+dt@kernel.org, mark.rutland@arm.com, orsonzhai@gmail.com, zhang.lyra@gmail.com Cc: weicx@spreadst.com, sherry.zong@unisoc.com, baolin.wang@linaro.org, vincent.guittot@linaro.org, linux-spi@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/6] spi: sprd: adi: Change hwlock to be optional Date: Fri, 26 Jul 2019 15:20:52 +0800 Message-Id: <2abe7dcf210e4197f8c5ece7fc6d6cc1eda8c655.1564125131.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now Spreadtrum ADI controller supplies multiple master accessing channel to support multiple subsystems accessing, instead of using a hardware spinlock to synchronize between the multiple subsystems. To keep backward compatibility, we should change the hardware spinlock to be optional. Moreover change to use of_hwspin_lock_get_id() function which return -ENOENT error number to indicate no hwlock support. Signed-off-by: Baolin Wang --- drivers/spi/spi-sprd-adi.c | 68 +++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 26 deletions(-) -- 1.7.9.5 diff --git a/drivers/spi/spi-sprd-adi.c b/drivers/spi/spi-sprd-adi.c index 0d767eb..9a05128 100644 --- a/drivers/spi/spi-sprd-adi.c +++ b/drivers/spi/spi-sprd-adi.c @@ -165,14 +165,16 @@ static int sprd_adi_read(struct sprd_adi *sadi, u32 reg_paddr, u32 *read_val) int read_timeout = ADI_READ_TIMEOUT; unsigned long flags; u32 val, rd_addr; - int ret; - - ret = hwspin_lock_timeout_irqsave(sadi->hwlock, - ADI_HWSPINLOCK_TIMEOUT, - &flags); - if (ret) { - dev_err(sadi->dev, "get the hw lock failed\n"); - return ret; + int ret = 0; + + if (sadi->hwlock) { + ret = hwspin_lock_timeout_irqsave(sadi->hwlock, + ADI_HWSPINLOCK_TIMEOUT, + &flags); + if (ret) { + dev_err(sadi->dev, "get the hw lock failed\n"); + return ret; + } } /* @@ -219,7 +221,8 @@ static int sprd_adi_read(struct sprd_adi *sadi, u32 reg_paddr, u32 *read_val) *read_val = val & RD_VALUE_MASK; out: - hwspin_unlock_irqrestore(sadi->hwlock, &flags); + if (sadi->hwlock) + hwspin_unlock_irqrestore(sadi->hwlock, &flags); return ret; } @@ -230,12 +233,14 @@ static int sprd_adi_write(struct sprd_adi *sadi, u32 reg_paddr, u32 val) unsigned long flags; int ret; - ret = hwspin_lock_timeout_irqsave(sadi->hwlock, - ADI_HWSPINLOCK_TIMEOUT, - &flags); - if (ret) { - dev_err(sadi->dev, "get the hw lock failed\n"); - return ret; + if (sadi->hwlock) { + ret = hwspin_lock_timeout_irqsave(sadi->hwlock, + ADI_HWSPINLOCK_TIMEOUT, + &flags); + if (ret) { + dev_err(sadi->dev, "get the hw lock failed\n"); + return ret; + } } ret = sprd_adi_drain_fifo(sadi); @@ -261,7 +266,8 @@ static int sprd_adi_write(struct sprd_adi *sadi, u32 reg_paddr, u32 val) } out: - hwspin_unlock_irqrestore(sadi->hwlock, &flags); + if (sadi->hwlock) + hwspin_unlock_irqrestore(sadi->hwlock, &flags); return ret; } @@ -476,16 +482,26 @@ static int sprd_adi_probe(struct platform_device *pdev) sadi->slave_pbase = res->start + ADI_SLAVE_OFFSET; sadi->ctlr = ctlr; sadi->dev = &pdev->dev; - ret = of_hwspin_lock_get_id_byname(np, "adi"); - if (ret < 0) { - dev_err(&pdev->dev, "can not get the hardware spinlock\n"); - goto put_ctlr; - } - - sadi->hwlock = devm_hwspin_lock_request_specific(&pdev->dev, ret); - if (!sadi->hwlock) { - ret = -ENXIO; - goto put_ctlr; + ret = of_hwspin_lock_get_id(np, 0); + if (ret > 0 || (IS_ENABLED(CONFIG_HWSPINLOCK) && ret == 0)) { + sadi->hwlock = + devm_hwspin_lock_request_specific(&pdev->dev, ret); + if (!sadi->hwlock) { + ret = -ENXIO; + goto put_ctlr; + } + } else { + switch (ret) { + case -ENOENT: + dev_info(&pdev->dev, "no hardware spinlock supplied\n"); + break; + default: + dev_err(&pdev->dev, + "failed to find hwlock id, %d\n", ret); + /* fall-through */ + case -EPROBE_DEFER: + goto put_ctlr; + } } sprd_adi_hw_init(sadi);