Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2831922lqt; Tue, 23 Apr 2024 03:02:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWQqULuqN9EC/ecR/wYzTIJ9I6CzYUUT1bBV8XqRXhkE1FKt/ww0tTYxggtUVt0I27eNS3MKXfRkJ1AXf9dpMPHXdQ4AZg35yFgMYMz5Q== X-Google-Smtp-Source: AGHT+IHj42k0uSW8FAvBMdnMvujUSzXNfRn7DPZLZlrNgCL7CG1F+3awCH/IJfgxu7d6UdPoKO/P X-Received: by 2002:a05:620a:1a21:b0:78d:67de:50a0 with SMTP id bk33-20020a05620a1a2100b0078d67de50a0mr17708888qkb.44.1713866545142; Tue, 23 Apr 2024 03:02:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713866545; cv=pass; d=google.com; s=arc-20160816; b=piW89y8gFXyNkQkJcRHF8sttDAKF0M2Uw/UIZJCzpFZK3NL01MettVR2cd9Z2vZOhO TOLwJvxhDdsFw+w/Loo5ioXhW/9C0r3HHEJ00gqjH9vlJZeVlwhYAfPpk/MQpE5U9tfA d81aojKw3QcrQ+XqIXZSJyCTNsWAfpgHzRId5jCfYEaPDnfzPKSTNpnFef/mlv3crF/K yk+esYHzGb7yHigs+PyLkiq+e9jHyzKfGnNfMQYpwPpZXV6sM9uc8RtSERwEoo6RF2zZ CCMirsZQoMHP+1QVmKC4WoQgP3HGManUebV06vp45rfktQY5Feq9sbH+VlR+L1F1U57a /TSA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=+jkSaR8RN3FHUyVZmT8l3Mp5fnnAxigkjdQtpVmnrtI=; fh=tK2ZwPrzf0wEjErhiOYEkdXvNUDFUxIIS/fYILyFyNs=; b=vkCr7tzv7Oh/vjk0Md8m3lFjcZLoN4JLQfSrNgIQNHeO1vOWsTAy3lbkEYxpEL2bzY 5VknlQIMrllIswfUVc/Nzb9OVw+/XeJjp/C+BVeG2aGWIGmpuVvI01SU/8ypjmgVbEuJ KofVUPEB+KjUyPHU5tSCsfZ7PAKTYRkKhhhZqm70M22p1WwfFMXuYnM5RNvkmMikOCa+ IY/cEHOEGtgOiUli4hUI89W6rCsudr49pz0FaWuUcAOwwpU58B4ByUUpagY9TIatj4oV l8o13KTCCpI5VKQuKFTO1XNhpsXFWsiy/4JWrXdBAdlp9a02qhw5lF0OSj2iNW8byGdp V0Rg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=np8hB3aR; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-154829-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-154829-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id v6-20020a05620a0f0600b00790624229bcsi8423204qkl.614.2024.04.23.03.02.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 03:02:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-154829-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=np8hB3aR; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-154829-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-154829-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 0A5E41C21C4D for ; Tue, 23 Apr 2024 10:02:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1286A657D9; Tue, 23 Apr 2024 10:01:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="np8hB3aR" Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A817A5EE8D; Tue, 23 Apr 2024 10:01:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713866515; cv=none; b=CINCsopKf5XJYentvX8su8Xj4+zEgegultUsUgU8o+q2LwJ8SgC2Px651V4JcN8oUyWA0s43NuaeKewsKj5KL/En1kIkpyJp1H5XT+s2iTT0t8UzsSKxGojyi1zQYZB0z4CJ2fy94juUxrZ605k4pM0GxBpVd2wTwkAACrBRvt8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713866515; c=relaxed/simple; bh=HK7nTIHxj4vRn1zLzL4Ml297uns17UJ5VfHqPQW4dAA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rfPDemz5XyfH2GYJiTDddvY9+pk70W2IuIx8vmHE3PIDQbIxB9lhXfYNhKmH9vdCUmNpoubJJhf53ogoBfXjfgXTzWm8jVBfXEjY43xmX1H33JFspdO489ClCt+QNGn1x4qxG3w+VNWtQLIegXeiCoA/6gpRzG6q6qM+cJEyh6I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=np8hB3aR; arc=none smtp.client-ip=217.70.183.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 269F41C000C; Tue, 23 Apr 2024 10:01:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1713866508; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+jkSaR8RN3FHUyVZmT8l3Mp5fnnAxigkjdQtpVmnrtI=; b=np8hB3aRqLPP/YVkDs5g4oOgvcmkH8S/H24b1cwNg4ihYKUhKBbpH8qtwvSPc7LQafk7pv +7MVQtuzACXnZWNEfb6jMduRm5IuCL7yLuTyJxApsw6n2sgnAjXtAIg8yUFpuncozYoM/I 3pne5mfZFjZt4D0pZtjprMGYBMyw2rQhU7J1QdSj4uUPaqAQA769NrjpRMnVpd7EABn1ok ObUYB5QKoBupMY2QH2IQB8aDXb9P3zSzFNCBagtVRGfYFvJHFlnE8/WYOGAaRxa2/k2MvO rD6nD7fXI4nn9xCghIgMea5yO+k+YmAM1AKWbRXEaMKojACj6pjhKJGvbQ43Bw== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Tue, 23 Apr 2024 12:01:40 +0200 Subject: [PATCH v4 1/6] spi: cadence-qspi: allow FIFO depth detection Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20240423-cdns-qspi-mbly-v4-1-3d2a7b535ad0@bootlin.com> References: <20240423-cdns-qspi-mbly-v4-0-3d2a7b535ad0@bootlin.com> In-Reply-To: <20240423-cdns-qspi-mbly-v4-0-3d2a7b535ad0@bootlin.com> To: Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Vaishnav Achath , Thomas Bogendoerfer , Rob Herring Cc: linux-spi@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, Vladimir Kondratiev , Gregory CLEMENT , Thomas Petazzoni , Tawfik Bayouk , =?utf-8?q?Th=C3=A9o_Lebrun?= X-Mailer: b4 0.13.0 X-GND-Sasl: theo.lebrun@bootlin.com If FIFO depth DT property is provided, check it matches what hardware reports and warn otherwise. Else, use hardware provided value. Hardware exposes FIFO depth indirectly because CQSPI_REG_SRAMPARTITION is partially read-only. Move probe cqspi->ddata assignment prior to cqspi_of_get_pdata() call. Signed-off-by: Théo Lebrun --- drivers/spi/spi-cadence-quadspi.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c index 9896e9fe7ffb..5a83940220a9 100644 --- a/drivers/spi/spi-cadence-quadspi.c +++ b/drivers/spi/spi-cadence-quadspi.c @@ -1510,8 +1510,8 @@ static int cqspi_of_get_pdata(struct cqspi_st *cqspi) cqspi->is_decoded_cs = of_property_read_bool(np, "cdns,is-decoded-cs"); if (of_property_read_u32(np, "cdns,fifo-depth", &cqspi->fifo_depth)) { - dev_err(dev, "couldn't determine fifo-depth\n"); - return -ENXIO; + /* Zero signals FIFO depth should be runtime detected. */ + cqspi->fifo_depth = 0; } if (of_property_read_u32(np, "cdns,fifo-width", &cqspi->fifo_width)) { @@ -1541,8 +1541,6 @@ static void cqspi_controller_init(struct cqspi_st *cqspi) { u32 reg; - cqspi_controller_enable(cqspi, 0); - /* Configure the remap address register, no remap */ writel(0, cqspi->iobase + CQSPI_REG_REMAP); @@ -1576,8 +1574,29 @@ static void cqspi_controller_init(struct cqspi_st *cqspi) reg |= CQSPI_REG_CONFIG_DMA_MASK; writel(reg, cqspi->iobase + CQSPI_REG_CONFIG); } +} - cqspi_controller_enable(cqspi, 1); +static void cqspi_controller_detect_fifo_depth(struct cqspi_st *cqspi) +{ + struct device *dev = &cqspi->pdev->dev; + u32 reg, fifo_depth; + + /* + * Bits N-1:0 are writable while bits 31:N are read as zero, with 2^N + * the FIFO depth. + */ + writel(U32_MAX, cqspi->iobase + CQSPI_REG_SRAMPARTITION); + reg = readl(cqspi->iobase + CQSPI_REG_SRAMPARTITION); + fifo_depth = reg + 1; + + /* FIFO depth of zero means no value from devicetree was provided. */ + if (cqspi->fifo_depth == 0) { + cqspi->fifo_depth = fifo_depth; + dev_dbg(dev, "using FIFO depth of %u\n", fifo_depth); + } else if (fifo_depth != cqspi->fifo_depth) { + dev_warn(dev, "detected FIFO depth (%u) different from config (%u)\n", + fifo_depth, cqspi->fifo_depth); + } } static int cqspi_request_mmap_dma(struct cqspi_st *cqspi) @@ -1730,6 +1749,7 @@ static int cqspi_probe(struct platform_device *pdev) cqspi->pdev = pdev; cqspi->host = host; cqspi->is_jh7110 = false; + cqspi->ddata = ddata = of_device_get_match_data(dev); platform_set_drvdata(pdev, cqspi); /* Obtain configuration from OF. */ @@ -1821,8 +1841,6 @@ static int cqspi_probe(struct platform_device *pdev) /* write completion is supported by default */ cqspi->wr_completion = true; - ddata = of_device_get_match_data(dev); - cqspi->ddata = ddata; if (ddata) { if (ddata->quirks & CQSPI_NEEDS_WR_DELAY) cqspi->wr_delay = 50 * DIV_ROUND_UP(NSEC_PER_SEC, @@ -1864,7 +1882,10 @@ static int cqspi_probe(struct platform_device *pdev) } cqspi_wait_idle(cqspi); + cqspi_controller_enable(cqspi, 0); + cqspi_controller_detect_fifo_depth(cqspi); cqspi_controller_init(cqspi); + cqspi_controller_enable(cqspi, 1); cqspi->current_cs = -1; cqspi->sclk = 0; @@ -1947,7 +1968,9 @@ static int cqspi_runtime_resume(struct device *dev) clk_prepare_enable(cqspi->clk); cqspi_wait_idle(cqspi); + cqspi_controller_enable(cqspi, 0); cqspi_controller_init(cqspi); + cqspi_controller_enable(cqspi, 1); cqspi->current_cs = -1; cqspi->sclk = 0; -- 2.44.0