From patchwork Fri Nov 17 20:12:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 744975 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="ekVvqiLE" Received: from mail-oi1-x230.google.com (mail-oi1-x230.google.com [IPv6:2607:f8b0:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3938D10C6 for ; Fri, 17 Nov 2023 12:13:53 -0800 (PST) Received: by mail-oi1-x230.google.com with SMTP id 5614622812f47-3b6f4d8ddccso1389391b6e.0 for ; Fri, 17 Nov 2023 12:13:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1700252032; x=1700856832; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=m9n1o/iZUaxSEnICaWfmjkoxeuoE9nljoI9vgcv8+Pc=; b=ekVvqiLE2X0AyxL40gEGgL8S9/W3gsGfadcgVpEJCyZECyqemP4b6NMfF4Btphzf8l QTRUSjCfVzye+1ry7lGnCcoVXAOhDm+841XSEM+Nq1Tu6oEyh8wUnwzJ2E4fxhqF4dJY G6DlfTtXOszf77/l8q8/mFhcBVx53JNYB2KQm9TX/X8dfvSouFQpiDgxdGQKLvFMYnWo zNIKoyHRhPXqlK0wrCsdRSkZGN2iz/F0m2hKzp44BJEn0gTBMhd9aI4bkk28a4cNpAlF PL6/DYGxqlh3hRdm3R4AOXgdgAshcm2JjospjAhMea+ZcEBAbKyFC//NOhZTv0rTsZTh SRNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700252032; x=1700856832; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=m9n1o/iZUaxSEnICaWfmjkoxeuoE9nljoI9vgcv8+Pc=; b=oC3FoWr/nH2vWkxYXqAoOgyiRxcTZtWtpBTetdnbqJS7sdLFMFXcjqHfQB31cNuIOd C29pKK+mNQKGij/5vJy618iwPRM/unbppZ/K/pgyOo9VAqZiLhthtyd7X2PFkSdzn+Z7 +ez/iavdrU4FdR4nEhnxB0u1XQXDX1tpuXjvr+eISGaVUIvUMGlWL4zL+i9FVlIbLwjm 7YRZT+vxbebCxpKt7a5CLzjSahLQfyxYl4FM1E69WxI4vRqkAYOaleRA4KY7txduZJap I9qO2fmQHjqZ9zBDb2CVQJgMPFT1DE+N7Yt74OCSdZPDAIQFTA29N90o8+UQ4uGScd6V eMuA== X-Gm-Message-State: AOJu0YxBj1UPOInydb2Ppkd3wF9XKBgNNFXpcsZclxHg2NNUg+pYYXyR 1blTB9phD+h7iyktHfO22fThjg== X-Google-Smtp-Source: AGHT+IGOxWWmVTcro47+CfoBzs66smlpjH26pJyUOrimWvjymyEudIaiiZt12oijMWo9J4oq49iVOg== X-Received: by 2002:a05:6808:308a:b0:3a7:4161:44ee with SMTP id bl10-20020a056808308a00b003a7416144eemr509227oib.6.1700252032112; Fri, 17 Nov 2023 12:13:52 -0800 (PST) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id l21-20020a544515000000b003a8560a9d34sm393814oil.25.2023.11.17.12.13.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 12:13:51 -0800 (PST) From: David Lechner To: linux-spi@vger.kernel.org, devicetree@vger.kernel.org Cc: David Lechner , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , Lars-Peter Clausen , linux-kernel@vger.kernel.org Subject: [PATCH 01/14] dt-bindings: spi: axi-spi-engine: convert to yaml Date: Fri, 17 Nov 2023 14:12:52 -0600 Message-ID: <20231117-axi-spi-engine-series-1-v1-1-cc59db999b87@baylibre.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231117-axi-spi-engine-series-1-v1-0-cc59db999b87@baylibre.com> References: <20231117-axi-spi-engine-series-1-v1-0-cc59db999b87@baylibre.com> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.12.4 This converts the axi-spi-engine binding to yaml. There are a few minor fixes in the conversion: * Added maintainers. * Added descriptions for the clocks. * Fixed the double "@" in the example. * Added a comma between the clocks in the example. Signed-off-by: David Lechner Reviewed-by: Rob Herring --- Note: This work is being done by BayLibre on behalf of Analog Devices Inc. This is why the maintainers are @analog.com rather than @baylibre.com. .../devicetree/bindings/spi/adi,axi-spi-engine.txt | 31 ---------- .../bindings/spi/adi,axi-spi-engine.yaml | 66 ++++++++++++++++++++++ 2 files changed, 66 insertions(+), 31 deletions(-) diff --git a/Documentation/devicetree/bindings/spi/adi,axi-spi-engine.txt b/Documentation/devicetree/bindings/spi/adi,axi-spi-engine.txt deleted file mode 100644 index 8a18d71e6879..000000000000 --- a/Documentation/devicetree/bindings/spi/adi,axi-spi-engine.txt +++ /dev/null @@ -1,31 +0,0 @@ -Analog Devices AXI SPI Engine controller Device Tree Bindings - -Required properties: -- compatible : Must be "adi,axi-spi-engine-1.00.a"" -- reg : Physical base address and size of the register map. -- interrupts : Property with a value describing the interrupt - number. -- clock-names : List of input clock names - "s_axi_aclk", "spi_clk" -- clocks : Clock phandles and specifiers (See clock bindings for - details on clock-names and clocks). -- #address-cells : Must be <1> -- #size-cells : Must be <0> - -Optional subnodes: - Subnodes are use to represent the SPI slave devices connected to the SPI - master. They follow the generic SPI bindings as outlined in spi-bus.txt. - -Example: - - spi@@44a00000 { - compatible = "adi,axi-spi-engine-1.00.a"; - reg = <0x44a00000 0x1000>; - interrupts = <0 56 4>; - clocks = <&clkc 15 &clkc 15>; - clock-names = "s_axi_aclk", "spi_clk"; - - #address-cells = <1>; - #size-cells = <0>; - - /* SPI devices */ - }; diff --git a/Documentation/devicetree/bindings/spi/adi,axi-spi-engine.yaml b/Documentation/devicetree/bindings/spi/adi,axi-spi-engine.yaml new file mode 100644 index 000000000000..d48faa42d025 --- /dev/null +++ b/Documentation/devicetree/bindings/spi/adi,axi-spi-engine.yaml @@ -0,0 +1,66 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/spi/adi,axi-spi-engine.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices AXI SPI Engine Controller + +description: | + The AXI SPI Engine controller is part of the SPI Engine framework[1] and + allows memory mapped access to the SPI Engine control bus. This allows it + to be used as a general purpose software driven SPI controller as well as + some optional advanced acceleration and offloading capabilities. + + [1] https://wiki.analog.com/resources/fpga/peripherals/spi_engine + +maintainers: + - Michael Hennerich + - Nuno Sá + +allOf: + - $ref: /schemas/spi/spi-controller.yaml# + +properties: + compatible: + const: adi,axi-spi-engine-1.00.a + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks: + items: + - description: The AXI interconnect clock. + - description: The SPI controller clock. + + clock-names: + items: + - const: s_axi_aclk + - const: spi_clk + +required: + - compatible + - reg + - interrupts + - clocks + - clock-names + +unevaluatedProperties: false + +examples: + - | + spi@44a00000 { + compatible = "adi,axi-spi-engine-1.00.a"; + reg = <0x44a00000 0x1000>; + interrupts = <0 56 4>; + clocks = <&clkc 15>, <&clkc 15>; + clock-names = "s_axi_aclk", "spi_clk"; + + #address-cells = <1>; + #size-cells = <0>; + + /* SPI devices */ + }; From patchwork Fri Nov 17 20:12:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 744976 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="f48DKjAE" Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D02E10D5 for ; Fri, 17 Nov 2023 12:13:53 -0800 (PST) Received: by mail-oi1-x22f.google.com with SMTP id 5614622812f47-3b3e13fc1f7so1496344b6e.0 for ; Fri, 17 Nov 2023 12:13:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1700252033; x=1700856833; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=daUtcUgvD3JlASmZskT09A6jBu8ff2l03YGGYSvkuOo=; b=f48DKjAEIQUdrbqTo8CyXZNyvcYeKbLZzgsbK9bp6xrsHmzxpAXHkNPhWNfRkTSaLa 0S/L9/iwFFvnwYMTjARBSJg3tj8Nb4n9UYVr9cQ0+/A7YKRIr8xhMD34l/INVH9noRdv 9sOMzurGwze+y4Z16rKZnoMzqdj7ZsHnFWAFZsmIJPnZM5Ysl96ymCgwGMcU+1Yo+grr R2BMwrIsnXk1o7hHcd4VHpErxPyU2y242szks8KOljLatQlm48qqF/67x7UV5cEjzZF/ DOtJgqQZNeC9twILU8f8qd/LocFsJI1WtV6R6aSTts6gmTUm+Hj8/l69wZ17ldD5twCc xi0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700252033; x=1700856833; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=daUtcUgvD3JlASmZskT09A6jBu8ff2l03YGGYSvkuOo=; b=lLRqkT/87rdFm6LBX4cqs7v6ip1K3tAH3rZK5pVLhsJg4ONbdxsYOSNHqOnTk+N9wO 3Zz07AE+bfR9Jq6hbCUwgtWo7OH3wsOa7YdfX5FVd72TA7AwGT5L7OhQw5O3yNzsYioT krTBx0TMY7O6XV6kra2a2cim57x9IL7FH/khMCHip5BhPTEDT9JA+BLvbq6Q3//ArVPN Bkt+x0EjNOYen/MBEyASOjWZUXxMWbWx94fH66lPA57E5uux6fzEfCWhglex7gFLSCaM /B/JTJ79QxKGE1+R5VMI+hwhxEIbdzd5d0BJqxCf65ZOmGI1FJGJQ8QXybXgipPeCTpJ 59/A== X-Gm-Message-State: AOJu0YxNEW78QhkOewltZiRCBAD9Qn4jqKJhc+HQC1S1bDowEhQ/zpzp XkdWCKiNLaBfqWdyXkulc7RxhA== X-Google-Smtp-Source: AGHT+IGupY9tgQkSOvQ1he/qTdneFPbPBSmCn8gJ3wctSyTP/DRvtzXTw5+16bwfGWkofb9g09taVw== X-Received: by 2002:a05:6808:1704:b0:3b6:d617:a6f7 with SMTP id bc4-20020a056808170400b003b6d617a6f7mr595509oib.3.1700252032911; Fri, 17 Nov 2023 12:13:52 -0800 (PST) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id l21-20020a544515000000b003a8560a9d34sm393814oil.25.2023.11.17.12.13.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 12:13:52 -0800 (PST) From: David Lechner To: linux-spi@vger.kernel.org, devicetree@vger.kernel.org Cc: David Lechner , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , Lars-Peter Clausen , linux-kernel@vger.kernel.org Subject: [PATCH 02/14] MAINTAINERS: add entry for AXI SPI Engine Date: Fri, 17 Nov 2023 14:12:53 -0600 Message-ID: <20231117-axi-spi-engine-series-1-v1-2-cc59db999b87@baylibre.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231117-axi-spi-engine-series-1-v1-0-cc59db999b87@baylibre.com> References: <20231117-axi-spi-engine-series-1-v1-0-cc59db999b87@baylibre.com> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.12.4 The AXI SPI Engine driver has been in the kernel for many years but has lacked a proper maintainers entry. This adds a new entry for the driver and the devicetree bindings. Signed-off-by: David Lechner --- Note: This work is being done by BayLibre on behalf of Analog Devices Inc. This is why the maintainers are @analog.com rather than @baylibre.com. MAINTAINERS | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 97f51d5ec1cf..a40f61ad5843 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3415,6 +3415,16 @@ W: https://ez.analog.com/linux-software-drivers F: Documentation/devicetree/bindings/hwmon/adi,axi-fan-control.yaml F: drivers/hwmon/axi-fan-control.c +AXI SPI ENGINE +M: Michael Hennerich +M: Nuno Sá +R: David Lechner +L: linux-spi@vger.kernel.org +S: Supported +W: https://ez.analog.com/linux-software-drivers +F: Documentation/devicetree/bindings/spi/adi,axi-spi-engine.yaml +F: drivers/spi/spi-axi-spi-engine.c + AXXIA I2C CONTROLLER M: Krzysztof Adamski L: linux-i2c@vger.kernel.org From patchwork Fri Nov 17 20:12:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 744747 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="a3T6+vYC" Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61D0B10EC for ; Fri, 17 Nov 2023 12:13:54 -0800 (PST) Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-3b6cb515917so1486768b6e.1 for ; Fri, 17 Nov 2023 12:13:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1700252033; x=1700856833; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6ldjfSGznOnPblU5dGC3l3g5toq9lO7sGMGu6CgtS3M=; b=a3T6+vYCIGb5Q//Z/lesLocw+DyzyxQIQXdyrbzc9cNj/QahPUsj2yjDirdjsw7FV7 1Bm5vbLuiu2/pdkN5ZUyBl2QSygMoYWBTozG4IUYwR8xuGC7Z1sjn37OCM1/SjTZAPMB vxg2HXd3+TRGSAS+OpW5Y1YaX44jGZqmN9Mo+tZcQppikM73mmcIPNfJH22THUSMCiqr mwHQ1SqlyYfs6GTzGW9VdW4f7qdrWr4wKTSfXih/vgf6Fc6SprgzX9wFRvlJr1yb2CVN bKf0jBCcvcz3kJb3H+bGQBBUrv/fahRmCyB9RvY+0umlhAJD+lSDStQRixSGDiDrd8eY fD+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700252033; x=1700856833; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6ldjfSGznOnPblU5dGC3l3g5toq9lO7sGMGu6CgtS3M=; b=Jmm199PXm5Au3Zwj9EIAUHyOVKZZND7y7r9iYh7Rdj/AldGAcKXWH9x1ecdSf1m0B0 X9ELlXOnnTVbfwuymtWMxjduBFZKuYh59LA+Z8++j+5TG83ZquQUq22dQ9+FgTBqCcvF a60Wg5eJ0oeQTTrRQJFK2Uf4iz15a9XkPbNp2PTfbLk28yQo3uWLDE9rPTyNdZWFeQ4N 5Ha3rkv+owGp76tzifAZyYL5YcS+Yki7eDdVUhILDzSTWNVnMYIBf4ye0bP7c5pnB/d8 BeWoT04LzCW4gDnyv16JjuOQbC3XYGUPh3m+Ztf+RJXb32Ssrf9WaXkonuwQZ532lIZE Ri8Q== X-Gm-Message-State: AOJu0YzQ6F9oxUa4tNVQtX2Iz8JhQZ7zWk3G/4ycYHk46bN2CbV8HOw8 eh4m3zROxPkqSeciSJwkO12w+Q== X-Google-Smtp-Source: AGHT+IFkdcnKGb/veAHN78+zN7NC2qdGgVsEjtKNCmABZd6JhCDDXzUcWb6I51Glk8WhVK/eRrCtYw== X-Received: by 2002:a05:6808:1718:b0:3b6:da98:437c with SMTP id bc24-20020a056808171800b003b6da98437cmr544507oib.0.1700252033671; Fri, 17 Nov 2023 12:13:53 -0800 (PST) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id l21-20020a544515000000b003a8560a9d34sm393814oil.25.2023.11.17.12.13.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 12:13:53 -0800 (PST) From: David Lechner To: linux-spi@vger.kernel.org, devicetree@vger.kernel.org Cc: David Lechner , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , Lars-Peter Clausen , linux-kernel@vger.kernel.org Subject: [PATCH 03/14] spi: axi-spi-engine: simplify driver data allocation Date: Fri, 17 Nov 2023 14:12:54 -0600 Message-ID: <20231117-axi-spi-engine-series-1-v1-3-cc59db999b87@baylibre.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231117-axi-spi-engine-series-1-v1-0-cc59db999b87@baylibre.com> References: <20231117-axi-spi-engine-series-1-v1-0-cc59db999b87@baylibre.com> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.12.4 This simplifies the private data allocation in the AXI SPI Engine driver by making use of the feature built into the spi_alloc_host() function instead of doing it manually. Signed-off-by: David Lechner --- drivers/spi/spi-axi-spi-engine.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c index b96e55f59d1a..bdf0aa4ceb1d 100644 --- a/drivers/spi/spi-axi-spi-engine.c +++ b/drivers/spi/spi-axi-spi-engine.c @@ -473,15 +473,11 @@ static int spi_engine_probe(struct platform_device *pdev) if (irq < 0) return irq; - spi_engine = devm_kzalloc(&pdev->dev, sizeof(*spi_engine), GFP_KERNEL); - if (!spi_engine) - return -ENOMEM; - - host = spi_alloc_host(&pdev->dev, 0); + host = spi_alloc_host(&pdev->dev, sizeof(*spi_engine)); if (!host) return -ENOMEM; - spi_controller_set_devdata(host, spi_engine); + spi_engine = spi_controller_get_devdata(host); spin_lock_init(&spi_engine->lock); From patchwork Fri Nov 17 20:12:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 744973 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="EUNEI5bF" Received: from mail-oi1-x22c.google.com (mail-oi1-x22c.google.com [IPv6:2607:f8b0:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EBCFD6D for ; Fri, 17 Nov 2023 12:13:55 -0800 (PST) Received: by mail-oi1-x22c.google.com with SMTP id 5614622812f47-3b2ea7cca04so1480169b6e.2 for ; Fri, 17 Nov 2023 12:13:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1700252034; x=1700856834; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kwzXznL4NYavhVUNHzr4kJuVjofxWovc+jaQlF/tetc=; b=EUNEI5bFxbQ+wjUpIFeqryFo8RgL/jszVWX5ykUtkBoQOWq2M/e6FzFsFicDMatiqq cmVlUSsGgNU3HseLs/oWs1599irG5YXdWMAqYadiRsliOHB3GsgJsoNVbNwmNG/k9kPk +vxM2bcGHn3Tk3aYOvBNHLucWF+NGgKTQGxYvl9HElEpy0fd16OxZviC1OOGxmDdQGOM o+sTBaOF6AgqJn+qiBJRBC0kX0qsNV3Dj12lt30uzWQ2e1YYFBYBmxya4hkaGwPEQC7w LlOde6ReuyTrrIRKhc+gCL6y/uqggP0SL7IpTxaZ5z2hsXT6YFT5wYhFxDXrGVdD/sUi zSsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700252034; x=1700856834; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kwzXznL4NYavhVUNHzr4kJuVjofxWovc+jaQlF/tetc=; b=E8pnGDN8kV2ejA0c3lwPUnZ29okaH98N+rTny2LCZsqgecYElaiguRrSXj0Pil4Rc3 4k0ea5HUx86fWoMAgAgyIaSxHiJr2skZ909dP+QhpEj2rajxQtShoc+JWZqXnqAz52CK 62JqVjGZoJxUs35oNj/6jXJUGL8rXqRKzBrkbP3mm0Hn63BTgXA0yEs0MnGZ7Mt9Fvge Yd7kC+vcSsINgKD9Mo+Q9k6h+bugS0mMrDP4Nw0oNnS/XzWl+XtzdOAJWsz20+22sqMN KG8mDDD3ZlKXTlQTo8fx5hfXy680/8V4lfAx9LIAl1V49iELstQKaZQvuTFp01lV0t+X Grzw== X-Gm-Message-State: AOJu0YxgwBlXj5rDgfTGtqmqxKYVqn0j5mXHVyaR6fXLU9BLymgpvhMs 2YTPwsveuc+sgttDYU7+KUYzlA== X-Google-Smtp-Source: AGHT+IGavxcM6yTEubR3PYLm487eVYtQfilkeWcy9vAYSJ/yk+i5Xgcq3QXKWV7F/hyvpN3JwgA7IA== X-Received: by 2002:a05:6808:1241:b0:3ae:2b43:dd47 with SMTP id o1-20020a056808124100b003ae2b43dd47mr537281oiv.22.1700252034604; Fri, 17 Nov 2023 12:13:54 -0800 (PST) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id l21-20020a544515000000b003a8560a9d34sm393814oil.25.2023.11.17.12.13.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 12:13:54 -0800 (PST) From: David Lechner To: linux-spi@vger.kernel.org, devicetree@vger.kernel.org Cc: David Lechner , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , Lars-Peter Clausen , linux-kernel@vger.kernel.org Subject: [PATCH 04/14] spi: axi-spi-engine: use devm_spi_alloc_host() Date: Fri, 17 Nov 2023 14:12:55 -0600 Message-ID: <20231117-axi-spi-engine-series-1-v1-4-cc59db999b87@baylibre.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231117-axi-spi-engine-series-1-v1-0-cc59db999b87@baylibre.com> References: <20231117-axi-spi-engine-series-1-v1-0-cc59db999b87@baylibre.com> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.12.4 This modifies the AXI SPI Engine driver to use devm_spi_alloc_host() instead of spi_alloc_host() to simplify the code a bit. In addition to simplifying the error paths in the probe function, we can also remove spi_controller_get/put() calls in the remove function since devm_spi_alloc_host() sets a flag to no longer decrement the controller reference count in the spi_unregister_controller() function. Signed-off-by: David Lechner --- drivers/spi/spi-axi-spi-engine.c | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c index bdf0aa4ceb1d..77c1c115448d 100644 --- a/drivers/spi/spi-axi-spi-engine.c +++ b/drivers/spi/spi-axi-spi-engine.c @@ -473,7 +473,7 @@ static int spi_engine_probe(struct platform_device *pdev) if (irq < 0) return irq; - host = spi_alloc_host(&pdev->dev, sizeof(*spi_engine)); + host = devm_spi_alloc_host(&pdev->dev, sizeof(*spi_engine)); if (!host) return -ENOMEM; @@ -482,22 +482,16 @@ static int spi_engine_probe(struct platform_device *pdev) spin_lock_init(&spi_engine->lock); spi_engine->clk = devm_clk_get_enabled(&pdev->dev, "s_axi_aclk"); - if (IS_ERR(spi_engine->clk)) { - ret = PTR_ERR(spi_engine->clk); - goto err_put_host; - } + if (IS_ERR(spi_engine->clk)) + return PTR_ERR(spi_engine->clk); spi_engine->ref_clk = devm_clk_get_enabled(&pdev->dev, "spi_clk"); - if (IS_ERR(spi_engine->ref_clk)) { - ret = PTR_ERR(spi_engine->ref_clk); - goto err_put_host; - } + if (IS_ERR(spi_engine->ref_clk)) + return PTR_ERR(spi_engine->ref_clk); spi_engine->base = devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(spi_engine->base)) { - ret = PTR_ERR(spi_engine->base); - goto err_put_host; - } + if (IS_ERR(spi_engine->base)) + return PTR_ERR(spi_engine->base); version = readl(spi_engine->base + SPI_ENGINE_REG_VERSION); if (SPI_ENGINE_VERSION_MAJOR(version) != 1) { @@ -505,8 +499,7 @@ static int spi_engine_probe(struct platform_device *pdev) SPI_ENGINE_VERSION_MAJOR(version), SPI_ENGINE_VERSION_MINOR(version), SPI_ENGINE_VERSION_PATCH(version)); - ret = -ENODEV; - goto err_put_host; + return -ENODEV; } writel_relaxed(0x00, spi_engine->base + SPI_ENGINE_REG_RESET); @@ -515,7 +508,7 @@ static int spi_engine_probe(struct platform_device *pdev) ret = request_irq(irq, spi_engine_irq, 0, pdev->name, host); if (ret) - goto err_put_host; + return ret; host->dev.of_node = pdev->dev.of_node; host->mode_bits = SPI_CPOL | SPI_CPHA | SPI_3WIRE; @@ -533,14 +526,12 @@ static int spi_engine_probe(struct platform_device *pdev) return 0; err_free_irq: free_irq(irq, host); -err_put_host: - spi_controller_put(host); return ret; } static void spi_engine_remove(struct platform_device *pdev) { - struct spi_controller *host = spi_controller_get(platform_get_drvdata(pdev)); + struct spi_controller *host = platform_get_drvdata(pdev); struct spi_engine *spi_engine = spi_controller_get_devdata(host); int irq = platform_get_irq(pdev, 0); @@ -548,8 +539,6 @@ static void spi_engine_remove(struct platform_device *pdev) free_irq(irq, host); - spi_controller_put(host); - writel_relaxed(0xff, spi_engine->base + SPI_ENGINE_REG_INT_PENDING); writel_relaxed(0x00, spi_engine->base + SPI_ENGINE_REG_INT_ENABLE); writel_relaxed(0x01, spi_engine->base + SPI_ENGINE_REG_RESET); From patchwork Fri Nov 17 20:12:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 744974 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="2+XdxDiO" Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1338510CE for ; Fri, 17 Nov 2023 12:13:56 -0800 (PST) Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-3b2e72fe47fso1514016b6e.1 for ; Fri, 17 Nov 2023 12:13:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1700252035; x=1700856835; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/Uy/nGn2rChA8c7KicPA5RLHwOBZWkxwdXoqQs+T9FI=; b=2+XdxDiOVAUwEHBmlFn/U/iOIbLMEN6BE1ylmm/F72DBfFvWneB9Tkwbs1kV7Iwmxa WKhZLCP1UztnIUpLY4l02FHU/eobad4LFjrmvcLwrBj7/3bfUQrorKrx1vWKdjHRwVlY KsgfhFJKSp2EJMzx56Nbc8GJpZfrV4qEhEcxmvcOl9xsOGWjjt5STQzCRDpT7uH4gBOp 9jZVIJDO2OKaKOSFL0uvUu7e+TVErcRkMLqvdvm7f/r8mmI91rHVgv3Y1P51V8h4+jXP fkUsoamL9iJYFbTS1JhmEOCIgbpvfmrm8U2ht0qXHba0UcZWk84RQ/yoLFA3R37/TO8R 5naw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700252035; x=1700856835; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/Uy/nGn2rChA8c7KicPA5RLHwOBZWkxwdXoqQs+T9FI=; b=odUM71qEBaRVmsPVPs2oYtfftr4NrBiI621dAeylR135ZHD8lLrQb7dAjiejQKm6pJ cQhMQ/YVIcoamhVhiZGbaESzOQPwWNhBog2LZRF9zSPAuRtmQ9bUk2fbJf7yYNIGaiMq CGqYVxME2y1uxLHMVdijzSK6mtNqtEBLWlt888v3VKAu4mOnD/n5C0t2+svOfW+dXNvf i1e6HASgPtq0NGGtb5s14+MnJ8wRrAZDg6kXpizTBYEseZzKaVaXyOmNA6mYalZp/8Ai xHceQl8OS1iFw3bfgltFuo87REX9qRmDzD7D3oRlsARkDMyEXSUNxKmTmMEPztsipozc 58xw== X-Gm-Message-State: AOJu0YyZL3aXWNHVHYlV6iabJYbijoyyao7LKUF8WpwDWEsHKmsLEWCJ NEu9qhAB94krsnGY76+zP4EHkg== X-Google-Smtp-Source: AGHT+IEpNY443K2DTvic/4nX3g59+w/t2iGjY1+g+xvMgSfgHtSIdUiY9qzOZHhk0/Foi7Fgc7LpRw== X-Received: by 2002:a05:6808:14cd:b0:3a4:3b56:72b2 with SMTP id f13-20020a05680814cd00b003a43b5672b2mr589101oiw.8.1700252035422; Fri, 17 Nov 2023 12:13:55 -0800 (PST) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id l21-20020a544515000000b003a8560a9d34sm393814oil.25.2023.11.17.12.13.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 12:13:55 -0800 (PST) From: David Lechner To: linux-spi@vger.kernel.org, devicetree@vger.kernel.org Cc: David Lechner , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , Lars-Peter Clausen , linux-kernel@vger.kernel.org Subject: [PATCH 05/14] spi: axi-spi-engine: use devm action to reset hw on remove Date: Fri, 17 Nov 2023 14:12:56 -0600 Message-ID: <20231117-axi-spi-engine-series-1-v1-5-cc59db999b87@baylibre.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231117-axi-spi-engine-series-1-v1-0-cc59db999b87@baylibre.com> References: <20231117-axi-spi-engine-series-1-v1-0-cc59db999b87@baylibre.com> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.12.4 This moves the reset of the hardware to a devm action in the AXI SPI Engine driver. This will allow us to use devm on later calls in the probe function while preserving the order during cleanup. Signed-off-by: David Lechner --- drivers/spi/spi-axi-spi-engine.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c index 77c1c115448d..c18a4b34777e 100644 --- a/drivers/spi/spi-axi-spi-engine.c +++ b/drivers/spi/spi-axi-spi-engine.c @@ -461,6 +461,15 @@ static int spi_engine_transfer_one_message(struct spi_controller *host, return 0; } +static void spi_engine_release_hw(void *p) +{ + struct spi_engine *spi_engine = p; + + writel_relaxed(0xff, spi_engine->base + SPI_ENGINE_REG_INT_PENDING); + writel_relaxed(0x00, spi_engine->base + SPI_ENGINE_REG_INT_ENABLE); + writel_relaxed(0x01, spi_engine->base + SPI_ENGINE_REG_RESET); +} + static int spi_engine_probe(struct platform_device *pdev) { struct spi_engine *spi_engine; @@ -506,6 +515,11 @@ static int spi_engine_probe(struct platform_device *pdev) writel_relaxed(0xff, spi_engine->base + SPI_ENGINE_REG_INT_PENDING); writel_relaxed(0x00, spi_engine->base + SPI_ENGINE_REG_INT_ENABLE); + ret = devm_add_action_or_reset(&pdev->dev, spi_engine_release_hw, + spi_engine); + if (ret) + return ret; + ret = request_irq(irq, spi_engine_irq, 0, pdev->name, host); if (ret) return ret; @@ -532,16 +546,11 @@ static int spi_engine_probe(struct platform_device *pdev) static void spi_engine_remove(struct platform_device *pdev) { struct spi_controller *host = platform_get_drvdata(pdev); - struct spi_engine *spi_engine = spi_controller_get_devdata(host); int irq = platform_get_irq(pdev, 0); spi_unregister_controller(host); free_irq(irq, host); - - writel_relaxed(0xff, spi_engine->base + SPI_ENGINE_REG_INT_PENDING); - writel_relaxed(0x00, spi_engine->base + SPI_ENGINE_REG_INT_ENABLE); - writel_relaxed(0x01, spi_engine->base + SPI_ENGINE_REG_RESET); } static const struct of_device_id spi_engine_match_table[] = { From patchwork Fri Nov 17 20:12:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 744746 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="GlzlcKT6" Received: from mail-oi1-x232.google.com (mail-oi1-x232.google.com [IPv6:2607:f8b0:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBF1AD6C for ; Fri, 17 Nov 2023 12:13:56 -0800 (PST) Received: by mail-oi1-x232.google.com with SMTP id 5614622812f47-3b2f4a5ccebso1512585b6e.3 for ; Fri, 17 Nov 2023 12:13:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1700252036; x=1700856836; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7LNYfVKcT7JMz9dURfBMFGVc3NYglRs5IQioTfjD6HM=; b=GlzlcKT63c7jWtIAMe3jmcQOBcMb0qs+2CwppZtzYE+Ko5QS+cljsUj442lH/CKqB8 rKoERKdZTydDrroa3t0J28oaO8BUgPBJYZ5BNkicbImd4zDFF5OX6LjrrpYTOQ/OPadl vWi4jp+F2VN+d+T7nRLMgJFO1EUeujAnR8Kt+YhPLYohMhK3wjzcPySUdT4dWHfBDs9I QxOBr1NbHZy7hyxxPjbY3P6JrU4V5XlFpHwinvsv5NneThCJRjro71Z4AOC2ikHxiiI9 CdflXTfKqFxB/Sc9cf7yzj7qHXGZpJ6kRQa3NX9hyz5AQUDMppbmJAR6KDdf/quTWY5W jJ3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700252036; x=1700856836; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7LNYfVKcT7JMz9dURfBMFGVc3NYglRs5IQioTfjD6HM=; b=UycGGgaL34gmT64l37k8/j0AevrV5bBhb7LJazpaIxB7tdygHAlizBIw1sH7xxSR7v CVaUJpu/48d4ff1ZKlgkRIZSVirNqM3tjYnauqb4alK3JMJTXQcXvRInoJh/zBcZ1NLV HPGDe0NmZ9gRiMUnLMW/HYSHv0WxZsB1FJGbhh/2BNzaSfQMgT7yMwfrthU3Rd5kxM3Z zgu4lWXi2ocNd5dH4HdUyZh7R0US9Jytfg5d+EKul9eisCDInFNFciFOArmIn8bd6BGc uq92RHLrcQ6P50Lh+BCwdGyYFnWS5OjlX+z2BNsHL2rRCsUMF0x8qnAIoLM1XaKCN0dX 0M/w== X-Gm-Message-State: AOJu0YxcKagEr8DxTcfPN/8GIqidlC2UWDjNhgw4e6HQZrYAVs5174qk wiP+sodxz5Jb2QnUC5ry8eJd7w== X-Google-Smtp-Source: AGHT+IGg2FRB34z9CXeDmTL8vY+4gqMAua4B68XqFMEtbGb7bY0wDKlsZUjbnqLNSi2hQuDWdGbI7A== X-Received: by 2002:a05:6808:1410:b0:3b5:a58c:cca6 with SMTP id w16-20020a056808141000b003b5a58ccca6mr608163oiv.3.1700252036277; Fri, 17 Nov 2023 12:13:56 -0800 (PST) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id l21-20020a544515000000b003a8560a9d34sm393814oil.25.2023.11.17.12.13.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 12:13:55 -0800 (PST) From: David Lechner To: linux-spi@vger.kernel.org, devicetree@vger.kernel.org Cc: David Lechner , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , Lars-Peter Clausen , linux-kernel@vger.kernel.org Subject: [PATCH 06/14] spi: axi-spi-engine: use devm_request_irq() Date: Fri, 17 Nov 2023 14:12:57 -0600 Message-ID: <20231117-axi-spi-engine-series-1-v1-6-cc59db999b87@baylibre.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231117-axi-spi-engine-series-1-v1-0-cc59db999b87@baylibre.com> References: <20231117-axi-spi-engine-series-1-v1-0-cc59db999b87@baylibre.com> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.12.4 This replaces request_irq() with devm_request_irq() in the AXI SPI Engine driver. This simplifies the error path and removes the need to call free_irq() in the remove function. Signed-off-by: David Lechner --- drivers/spi/spi-axi-spi-engine.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c index c18a4b34777e..81d7352d2b8b 100644 --- a/drivers/spi/spi-axi-spi-engine.c +++ b/drivers/spi/spi-axi-spi-engine.c @@ -520,7 +520,8 @@ static int spi_engine_probe(struct platform_device *pdev) if (ret) return ret; - ret = request_irq(irq, spi_engine_irq, 0, pdev->name, host); + ret = devm_request_irq(&pdev->dev, irq, spi_engine_irq, 0, pdev->name, + host); if (ret) return ret; @@ -533,24 +534,18 @@ static int spi_engine_probe(struct platform_device *pdev) ret = spi_register_controller(host); if (ret) - goto err_free_irq; + return ret; platform_set_drvdata(pdev, host); return 0; -err_free_irq: - free_irq(irq, host); - return ret; } static void spi_engine_remove(struct platform_device *pdev) { struct spi_controller *host = platform_get_drvdata(pdev); - int irq = platform_get_irq(pdev, 0); spi_unregister_controller(host); - - free_irq(irq, host); } static const struct of_device_id spi_engine_match_table[] = { From patchwork Fri Nov 17 20:12:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 744745 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="zs/TE/2d" Received: from mail-oi1-x231.google.com (mail-oi1-x231.google.com [IPv6:2607:f8b0:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC25B10D0 for ; Fri, 17 Nov 2023 12:13:57 -0800 (PST) Received: by mail-oi1-x231.google.com with SMTP id 5614622812f47-3b2ec9a79bdso1596262b6e.3 for ; Fri, 17 Nov 2023 12:13:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1700252037; x=1700856837; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=M1wQ6CLb/dDh5KiZFFpLs1bmPNGn2Z5vlnYTp1713SY=; b=zs/TE/2dzcTIHUUgBQPW21glYKrUWr6e4lez1HsM2FETRIb0q8ttXaWHDhMMvtxAvz PAhB3Tm0uoj1B5VYSmFBymiCNJ0qscRwXnixBcesVok1F1NthOM3gCQJ55ulb6TnQ81w QoE73k5cJYhWxylpLelYJJ9WOz/68NEgZf77Zx0lX97Ju/Mu1kuYqoQmdP9/AZnwdQKa tTR0PXgA2IwZFFujByP9vR/f06oghFv9yczgJDjOQWmB2ZuW3pJugDhDIl+vje0E7HCk PZ6+/txXyoTmm2d67EzqcMSCnYEhdm1ANSv96YH/3FiQaCQyBA+EZ7MB4QuoamUFPEdh 9RIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700252037; x=1700856837; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=M1wQ6CLb/dDh5KiZFFpLs1bmPNGn2Z5vlnYTp1713SY=; b=LGrFc3/JpNJ9IBr9rcjHv+7OqhG0aA4HR/PIgy8IqqNdGHjEnI0DTrr2l/IjWMkWSr aVmE0+BX5FsIY+75MHlpXm+hCDIAuPsPBFrcjZ8BSOpd5tu7noRZg/6xVF7R83ig7BQO IVNUcEtp/T6RhI0RePrWIKKkhiCCnrMl7xStyreglXaLGvoUGtzS3FLzf8b10tSdTlmX xB0vKjav7W5MA2kpnsFk2J8fWDz3rOl6NmwhH3kLiCYNyZBWYwnHC/AFlq5oTt7VzesY F0BYW3wvQIK9oMR/jQcWRJylee775wGIvC+lVBQBbOwVbe6gzQpxsFrlkFBoFJ1GpgJE ltPw== X-Gm-Message-State: AOJu0YxS+MmimlfhqxpAJBBgW2ZhuJfrWZ/rpfAaBsPfzk9BZ3DXaOy1 ZpTPHZN9zHtola3AZFFRQWhmzQ== X-Google-Smtp-Source: AGHT+IGtzh7e1k7njF++1U+zMaywWCDh65jE1df5WPD+UmMUdAI4bHvmiDb/8jACwIXkHFTXypjZ/g== X-Received: by 2002:a05:6808:1922:b0:3b2:e70e:b448 with SMTP id bf34-20020a056808192200b003b2e70eb448mr531624oib.8.1700252037075; Fri, 17 Nov 2023 12:13:57 -0800 (PST) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id l21-20020a544515000000b003a8560a9d34sm393814oil.25.2023.11.17.12.13.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 12:13:56 -0800 (PST) From: David Lechner To: linux-spi@vger.kernel.org, devicetree@vger.kernel.org Cc: David Lechner , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , Lars-Peter Clausen , linux-kernel@vger.kernel.org Subject: [PATCH 07/14] spi: axi-spi-engine: use devm_spi_register_controller() Date: Fri, 17 Nov 2023 14:12:58 -0600 Message-ID: <20231117-axi-spi-engine-series-1-v1-7-cc59db999b87@baylibre.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231117-axi-spi-engine-series-1-v1-0-cc59db999b87@baylibre.com> References: <20231117-axi-spi-engine-series-1-v1-0-cc59db999b87@baylibre.com> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.12.4 This replaces spi_register_controller() with devm_spi_register_controller() in the AXI SPI Engine driver. This saves us from having to call spi_unregister_controller() in the remove function. The remove function is also removed since it is no longer needed. Signed-off-by: David Lechner --- drivers/spi/spi-axi-spi-engine.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c index 81d7352d2b8b..819744246952 100644 --- a/drivers/spi/spi-axi-spi-engine.c +++ b/drivers/spi/spi-axi-spi-engine.c @@ -532,7 +532,7 @@ static int spi_engine_probe(struct platform_device *pdev) host->transfer_one_message = spi_engine_transfer_one_message; host->num_chipselect = 8; - ret = spi_register_controller(host); + ret = devm_spi_register_controller(&pdev->dev, host); if (ret) return ret; @@ -541,13 +541,6 @@ static int spi_engine_probe(struct platform_device *pdev) return 0; } -static void spi_engine_remove(struct platform_device *pdev) -{ - struct spi_controller *host = platform_get_drvdata(pdev); - - spi_unregister_controller(host); -} - static const struct of_device_id spi_engine_match_table[] = { { .compatible = "adi,axi-spi-engine-1.00.a" }, { }, @@ -556,7 +549,6 @@ MODULE_DEVICE_TABLE(of, spi_engine_match_table); static struct platform_driver spi_engine_driver = { .probe = spi_engine_probe, - .remove_new = spi_engine_remove, .driver = { .name = "spi-engine", .of_match_table = spi_engine_match_table, From patchwork Fri Nov 17 20:12:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 744972 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="dF4HhDH2" Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73BA010E5 for ; Fri, 17 Nov 2023 12:13:58 -0800 (PST) Received: by mail-oi1-x22e.google.com with SMTP id 5614622812f47-3b5ff072fc4so1435810b6e.3 for ; Fri, 17 Nov 2023 12:13:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1700252038; x=1700856838; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=npvMQYAJSwyILZ7IKukB/DvG7sNQ93TySYJ1U4gDkl4=; b=dF4HhDH2eqiJds+sz20xspLu3qG1xNOdNILpBOPIQlUyyAd/h6KZkNRbNNuCYrZuvG 42zo54xPs/eko/hE5oub++KHHUkCnGYIbv4p+2xIgz/IPQ6e0KsOon+CTZn7MywympNu oYh8XdrJbK3gLKJIzbrlD3wX+DsY5Ll/opwJh9SJKt9JBpjKzhe12AWXCvlcXdkYVpxa GJSl4jWRDwE9c3vUto2rD5w3tFfh/g/c630723YIhpvthgo9nOo2waY3gx/BdmNOexZO 7P2BZAidQZchZ5ouG7SqPpT64+d4u7uthtwRXC5M+KLgpoUxJasnS9SqQnHqWfXIHZw/ Ckvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700252038; x=1700856838; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=npvMQYAJSwyILZ7IKukB/DvG7sNQ93TySYJ1U4gDkl4=; b=WWMLYg9dmvmNedrSGgDaahtevUGJEjif6PAUuc991p74TmpCTb7oIxtd9JE8b5NqZN 5OZ2OK0oTrIikPGH2NDYG37Mgd/JL7ZnsekJuYA4+H9OdpmqxTMtIojVGQ6TELVxRt3B 1HU7obEwWhredOk6c65t0ECYrE+ej2cRUQDOLoT0dgucBo98u+yEJZ5psxNETRfgQJMB q98L2Kp9m8VsGwHep8ENAX8/dd1czTexBXRyMQzDflUxIMWEZpNZwYrqkEYbi7n6zrrl ic2+eApKbZCggteQ0WrY3K2bdZkhgcr6XPnsX/eyy/N3aul1q7RthJY4GIwCvLrYCX8o kKPw== X-Gm-Message-State: AOJu0YzFLfPhOuS4j6xD2z9ME5nlGgzVFqN+ifoudwrzzA4HsxlVfOKE 2tp8Ka6bv8G2m/tkzcXmLnZELw== X-Google-Smtp-Source: AGHT+IG/IrKsnh7EvBouduSI/F9prrBZP+rKdeDxzs2BynwF/hXH1i+4jAjYYRswiZ4KwgtdAuPN5A== X-Received: by 2002:a05:6808:1288:b0:3ab:84f0:b49d with SMTP id a8-20020a056808128800b003ab84f0b49dmr594399oiw.3.1700252037854; Fri, 17 Nov 2023 12:13:57 -0800 (PST) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id l21-20020a544515000000b003a8560a9d34sm393814oil.25.2023.11.17.12.13.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 12:13:57 -0800 (PST) From: David Lechner To: linux-spi@vger.kernel.org, devicetree@vger.kernel.org Cc: David Lechner , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , Lars-Peter Clausen , linux-kernel@vger.kernel.org Subject: [PATCH 08/14] spi: axi-spi-engine: check for valid clock rate Date: Fri, 17 Nov 2023 14:12:59 -0600 Message-ID: <20231117-axi-spi-engine-series-1-v1-8-cc59db999b87@baylibre.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231117-axi-spi-engine-series-1-v1-0-cc59db999b87@baylibre.com> References: <20231117-axi-spi-engine-series-1-v1-0-cc59db999b87@baylibre.com> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.12.4 This adds a check for a valid SCLK rate in the axi-spi-engine driver during probe. A valid rate is required to get accurate timing for delays and by not allowing 0 we can avoid divide by zero errors later without additional checks. Signed-off-by: David Lechner --- drivers/spi/spi-axi-spi-engine.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c index 819744246952..8a6fbb3bb3f1 100644 --- a/drivers/spi/spi-axi-spi-engine.c +++ b/drivers/spi/spi-axi-spi-engine.c @@ -532,6 +532,9 @@ static int spi_engine_probe(struct platform_device *pdev) host->transfer_one_message = spi_engine_transfer_one_message; host->num_chipselect = 8; + if (host->max_speed_hz == 0) + return dev_err_probe(&pdev->dev, -EINVAL, "spi_clk rate is 0"); + ret = devm_spi_register_controller(&pdev->dev, host); if (ret) return ret; From patchwork Fri Nov 17 20:13:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 744971 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="z3zTquZ/" Received: from mail-oi1-x230.google.com (mail-oi1-x230.google.com [IPv6:2607:f8b0:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D6481706 for ; Fri, 17 Nov 2023 12:13:59 -0800 (PST) Received: by mail-oi1-x230.google.com with SMTP id 5614622812f47-3b2df2fb611so1609916b6e.0 for ; Fri, 17 Nov 2023 12:13:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1700252038; x=1700856838; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1RuICcIcIl3AaiTh6lEHwrcRrEfhi3pyQa5k6SJhLUA=; b=z3zTquZ/PPv2BrCckuX+EitkYM/I38XDoZFzCE5W1EYWyPeOUTI1YkuhNWWKqolK82 hTf+jkNQhB/Ys074Zs0o8ZMqISyPVChgSffD7nOBLS3AHrZM9aRz/ebbzYCn1AylZusF MMWn7u6sUqQxS25amZGsnVyt3VCeTit36BoxR1LBjQk8vUD9IrIEaXSXL25p/a5qac2r x9tAde+rnFSdIJA4HzMtxk+gDiZoTmIUrzLZJqU57x4sJ07QMJtN8WVl0Sd/PG1JkC22 jjNbpNQJDxOURyZ+09RaVPGg/DD8WS2b7qzeeTRiHIwY1A3jht6ddO1g2P2CztvvAwP3 sNrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700252038; x=1700856838; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1RuICcIcIl3AaiTh6lEHwrcRrEfhi3pyQa5k6SJhLUA=; b=P4WeMD4tWX4kQ/460mbya4kAlN7JsI4X+qwqEESUNsHhwuAI3rHpfjDEqTcB4qDvSI JRU/+Ez+JrhKQtxQn+dTcZp5vMbnsRSAvW+6wX6nzM1wlk0Vb/NH5wLVLSAhELSRAP1H ++AbECvpT5qo+SccUig4BXuoIPIDRQ3fciAqvah63MWvtvcfIxcMN+Wf89w0f4yQxiu7 tH00sYz3onDoJ8ICYhNxU36QLDjImmr6JBPbz7xS/KwzjPbEaWdbQhaJvoIKSxhZCcSr hxyDAa+c5+pnAyS60pWQjHhWTdE1bRu9/3YJY0HcfU4wVp5POf2WaXco/n6Qk+y8qx8A q9cw== X-Gm-Message-State: AOJu0YxId1rQu2H/iniekDNkrjQFm1Yq9MA4f0bFJr1ulxO5Hkb2XKHN sKuub3lxj37Pr45tyU+uFkFR0w== X-Google-Smtp-Source: AGHT+IHNjNba+w42QRjeuUJ5nb+6+heLtiYkGLBV0Zfw34pSh8V5KqYbKqfblYnfTX57gEZCbO4BZA== X-Received: by 2002:a05:6808:1a0e:b0:3b2:e624:43a0 with SMTP id bk14-20020a0568081a0e00b003b2e62443a0mr530324oib.15.1700252038650; Fri, 17 Nov 2023 12:13:58 -0800 (PST) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id l21-20020a544515000000b003a8560a9d34sm393814oil.25.2023.11.17.12.13.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 12:13:58 -0800 (PST) From: David Lechner To: linux-spi@vger.kernel.org, devicetree@vger.kernel.org Cc: David Lechner , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , Lars-Peter Clausen , linux-kernel@vger.kernel.org Subject: [PATCH 09/14] spi: axi-spi-engine: move msg state to new struct Date: Fri, 17 Nov 2023 14:13:00 -0600 Message-ID: <20231117-axi-spi-engine-series-1-v1-9-cc59db999b87@baylibre.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231117-axi-spi-engine-series-1-v1-0-cc59db999b87@baylibre.com> References: <20231117-axi-spi-engine-series-1-v1-0-cc59db999b87@baylibre.com> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.12.4 This moves the message state in the AXI SPI Engine driver to a new struct spi_engine_msg_state. Previously, the driver state contained various pointers that pointed to memory owned by a struct spi_message. However, it did not set any of these pointers to NULL when a message was completed. This could lead to use after free bugs. Example of how this could happen: 1. SPI core calls into spi_engine_transfer_one_message() with msg1. 2. Assume something was misconfigured and spi_engine_tx_next() is not called enough times in interrupt callbacks for msg1 such that spi_engine->tx_xfer is never set to NULL before the msg1 completes. 3. SYNC interrupt is received and spi_finalize_current_message() is called for msg1. spi_engine->msg is set to NULL but no other message-specific state is reset. 4. Caller that sent msg1 is notified of the completion and frees msg1 and the associated xfers and tx/rx buffers. 4. SPI core calls into spi_engine_transfer_one_message() with msg2. 5. When spi_engine_tx_next() is called for msg2, spi_engine->tx_xfer is still be pointing to an xfer from msg1, which was already freed. spi_engine_xfer_next() tries to access xfer->transfer_list of one of the freed xfers and we get a segfault or undefined behavior. To avoid issues like this, instead of putting per-message state in the driver state struct, we can make use of the struct spi_message::state field to store a pointer to a new struct spi_engine_msg_state. This way, all of the state that belongs to specific message stays with that message and we don't have to remember to manually reset all aspects of the message state when a message is completed. Rather, a new state is allocated for each message. Most of the changes are just renames where the state is accessed. One place where this wasn't straightforward was the sync_id member. This has been changed to use ida_alloc_range() since we needed to separate the per-message sync_id from the per-controller next available sync_id. Signed-off-by: David Lechner --- drivers/spi/spi-axi-spi-engine.c | 150 +++++++++++++++++++++++++-------------- 1 file changed, 96 insertions(+), 54 deletions(-) diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c index 8a6fbb3bb3f1..745000a9b2c7 100644 --- a/drivers/spi/spi-axi-spi-engine.c +++ b/drivers/spi/spi-axi-spi-engine.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -78,28 +79,42 @@ struct spi_engine_program { uint16_t instructions[]; }; -struct spi_engine { - struct clk *clk; - struct clk *ref_clk; - - spinlock_t lock; - - void __iomem *base; - - struct spi_message *msg; +/** + * struct spi_engine_message_state - SPI engine per-message state + */ +struct spi_engine_message_state { + /** Instructions for executing this message. */ struct spi_engine_program *p; + /** Number of elements in cmd_buf array. */ unsigned cmd_length; + /** Array of commands not yet written to CMD FIFO. */ const uint16_t *cmd_buf; - + /** Next xfer with tx_buf not yet fully written to TX FIFO. */ struct spi_transfer *tx_xfer; + /** Size of tx_buf in bytes. */ unsigned int tx_length; + /** Bytes not yet written to TX FIFO. */ const uint8_t *tx_buf; - + /** Next xfer with rx_buf not yet fully written to RX FIFO. */ struct spi_transfer *rx_xfer; + /** Size of tx_buf in bytes. */ unsigned int rx_length; + /** Bytes not yet written to the RX FIFO. */ uint8_t *rx_buf; + /** ID to correlate SYNC interrupts with this message. */ + u8 sync_id; +}; + +struct spi_engine { + struct clk *clk; + struct clk *ref_clk; - unsigned int sync_id; + spinlock_t lock; + + void __iomem *base; + + struct spi_message *msg; + struct ida sync_ida; unsigned int completed_id; unsigned int int_enable; @@ -258,100 +273,105 @@ static void spi_engine_xfer_next(struct spi_engine *spi_engine, static void spi_engine_tx_next(struct spi_engine *spi_engine) { - struct spi_transfer *xfer = spi_engine->tx_xfer; + struct spi_engine_message_state *st = spi_engine->msg->state; + struct spi_transfer *xfer = st->tx_xfer; do { spi_engine_xfer_next(spi_engine, &xfer); } while (xfer && !xfer->tx_buf); - spi_engine->tx_xfer = xfer; + st->tx_xfer = xfer; if (xfer) { - spi_engine->tx_length = xfer->len; - spi_engine->tx_buf = xfer->tx_buf; + st->tx_length = xfer->len; + st->tx_buf = xfer->tx_buf; } else { - spi_engine->tx_buf = NULL; + st->tx_buf = NULL; } } static void spi_engine_rx_next(struct spi_engine *spi_engine) { - struct spi_transfer *xfer = spi_engine->rx_xfer; + struct spi_engine_message_state *st = spi_engine->msg->state; + struct spi_transfer *xfer = st->rx_xfer; do { spi_engine_xfer_next(spi_engine, &xfer); } while (xfer && !xfer->rx_buf); - spi_engine->rx_xfer = xfer; + st->rx_xfer = xfer; if (xfer) { - spi_engine->rx_length = xfer->len; - spi_engine->rx_buf = xfer->rx_buf; + st->rx_length = xfer->len; + st->rx_buf = xfer->rx_buf; } else { - spi_engine->rx_buf = NULL; + st->rx_buf = NULL; } } static bool spi_engine_write_cmd_fifo(struct spi_engine *spi_engine) { void __iomem *addr = spi_engine->base + SPI_ENGINE_REG_CMD_FIFO; + struct spi_engine_message_state *st = spi_engine->msg->state; unsigned int n, m, i; const uint16_t *buf; n = readl_relaxed(spi_engine->base + SPI_ENGINE_REG_CMD_FIFO_ROOM); - while (n && spi_engine->cmd_length) { - m = min(n, spi_engine->cmd_length); - buf = spi_engine->cmd_buf; + while (n && st->cmd_length) { + m = min(n, st->cmd_length); + buf = st->cmd_buf; for (i = 0; i < m; i++) writel_relaxed(buf[i], addr); - spi_engine->cmd_buf += m; - spi_engine->cmd_length -= m; + st->cmd_buf += m; + st->cmd_length -= m; n -= m; } - return spi_engine->cmd_length != 0; + return st->cmd_length != 0; } static bool spi_engine_write_tx_fifo(struct spi_engine *spi_engine) { void __iomem *addr = spi_engine->base + SPI_ENGINE_REG_SDO_DATA_FIFO; + struct spi_engine_message_state *st = spi_engine->msg->state; unsigned int n, m, i; const uint8_t *buf; n = readl_relaxed(spi_engine->base + SPI_ENGINE_REG_SDO_FIFO_ROOM); - while (n && spi_engine->tx_length) { - m = min(n, spi_engine->tx_length); - buf = spi_engine->tx_buf; + while (n && st->tx_length) { + m = min(n, st->tx_length); + buf = st->tx_buf; for (i = 0; i < m; i++) writel_relaxed(buf[i], addr); - spi_engine->tx_buf += m; - spi_engine->tx_length -= m; + st->tx_buf += m; + st->tx_length -= m; n -= m; - if (spi_engine->tx_length == 0) + if (st->tx_length == 0) spi_engine_tx_next(spi_engine); } - return spi_engine->tx_length != 0; + return st->tx_length != 0; } static bool spi_engine_read_rx_fifo(struct spi_engine *spi_engine) { void __iomem *addr = spi_engine->base + SPI_ENGINE_REG_SDI_DATA_FIFO; + struct spi_engine_message_state *st = spi_engine->msg->state; unsigned int n, m, i; uint8_t *buf; n = readl_relaxed(spi_engine->base + SPI_ENGINE_REG_SDI_FIFO_LEVEL); - while (n && spi_engine->rx_length) { - m = min(n, spi_engine->rx_length); - buf = spi_engine->rx_buf; + while (n && st->rx_length) { + m = min(n, st->rx_length); + buf = st->rx_buf; for (i = 0; i < m; i++) buf[i] = readl_relaxed(addr); - spi_engine->rx_buf += m; - spi_engine->rx_length -= m; + st->rx_buf += m; + st->rx_length -= m; n -= m; - if (spi_engine->rx_length == 0) + if (st->rx_length == 0) spi_engine_rx_next(spi_engine); } - return spi_engine->rx_length != 0; + return st->rx_length != 0; } static irqreturn_t spi_engine_irq(int irq, void *devid) @@ -387,12 +407,16 @@ static irqreturn_t spi_engine_irq(int irq, void *devid) disable_int |= SPI_ENGINE_INT_SDI_ALMOST_FULL; } - if (pending & SPI_ENGINE_INT_SYNC) { - if (spi_engine->msg && - spi_engine->completed_id == spi_engine->sync_id) { + if (pending & SPI_ENGINE_INT_SYNC && spi_engine->msg) { + struct spi_engine_message_state *st = spi_engine->msg->state; + + if (spi_engine->completed_id == st->sync_id) { struct spi_message *msg = spi_engine->msg; + struct spi_engine_message_state *st = msg->state; - kfree(spi_engine->p); + ida_free(&spi_engine->sync_ida, st->sync_id); + kfree(st->p); + kfree(st); msg->status = 0; msg->actual_length = msg->frame_length; spi_engine->msg = NULL; @@ -417,29 +441,46 @@ static int spi_engine_transfer_one_message(struct spi_controller *host, { struct spi_engine_program p_dry, *p; struct spi_engine *spi_engine = spi_controller_get_devdata(host); + struct spi_engine_message_state *st; unsigned int int_enable = 0; unsigned long flags; size_t size; + int ret; + + st = kzalloc(sizeof(*st), GFP_KERNEL); + if (!st) + return -ENOMEM; p_dry.length = 0; spi_engine_compile_message(spi_engine, msg, true, &p_dry); size = sizeof(*p->instructions) * (p_dry.length + 1); p = kzalloc(sizeof(*p) + size, GFP_KERNEL); - if (!p) + if (!p) { + kfree(st); return -ENOMEM; + } + + ret = ida_alloc_range(&spi_engine->sync_ida, 0, U8_MAX, GFP_KERNEL); + if (ret < 0) { + kfree(p); + kfree(st); + return ret; + } + + st->sync_id = ret; + spi_engine_compile_message(spi_engine, msg, false, p); spin_lock_irqsave(&spi_engine->lock, flags); - spi_engine->sync_id = (spi_engine->sync_id + 1) & 0xff; - spi_engine_program_add_cmd(p, false, - SPI_ENGINE_CMD_SYNC(spi_engine->sync_id)); + spi_engine_program_add_cmd(p, false, SPI_ENGINE_CMD_SYNC(st->sync_id)); + msg->state = st; spi_engine->msg = msg; - spi_engine->p = p; + st->p = p; - spi_engine->cmd_buf = p->instructions; - spi_engine->cmd_length = p->length; + st->cmd_buf = p->instructions; + st->cmd_length = p->length; if (spi_engine_write_cmd_fifo(spi_engine)) int_enable |= SPI_ENGINE_INT_CMD_ALMOST_EMPTY; @@ -448,7 +489,7 @@ static int spi_engine_transfer_one_message(struct spi_controller *host, int_enable |= SPI_ENGINE_INT_SDO_ALMOST_EMPTY; spi_engine_rx_next(spi_engine); - if (spi_engine->rx_length != 0) + if (st->rx_length != 0) int_enable |= SPI_ENGINE_INT_SDI_ALMOST_FULL; int_enable |= SPI_ENGINE_INT_SYNC; @@ -489,6 +530,7 @@ static int spi_engine_probe(struct platform_device *pdev) spi_engine = spi_controller_get_devdata(host); spin_lock_init(&spi_engine->lock); + ida_init(&spi_engine->sync_ida); spi_engine->clk = devm_clk_get_enabled(&pdev->dev, "s_axi_aclk"); if (IS_ERR(spi_engine->clk)) From patchwork Fri Nov 17 20:13:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 744744 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="CwKoOETZ" Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E477D6C for ; Fri, 17 Nov 2023 12:14:00 -0800 (PST) Received: by mail-oi1-x22e.google.com with SMTP id 5614622812f47-3b2e4107f47so1592625b6e.2 for ; Fri, 17 Nov 2023 12:14:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1700252039; x=1700856839; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3x/o+ZhKJLhCZxPJDvSVJn2SYXdsZyrTC3illb8aSGE=; b=CwKoOETZGqRe5UOqmT1L2acNwFT+sCm90z6Wce9bLIOiYNpu/NIa1HtvwKYSaZiosg CUxX+YsEjzHJKPMfFL/itqTlHCgyxQgMoTsEx+2ELphA+EAjxkoo7kUlquYWYRuLxlR8 ST1uNo5tL5iLc9bBnTV6vJSF0Y1HVASK2OkTP3jMKCKupM/YLkIMNzSNrk4ZWT7v/1hz ssMBdM/fDX7YTxgu7Vq199CLU1bF0Y10A07bFl9/SqstvjvtTKwzkPxrJ4Oy+6YbGoci wXmTeMrOk/eI9tuE5MqIqQ1NTp/m2CMe7bRSUPg+F1MbGpxC8coWdqbcsYdg4t96uB/w IxsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700252039; x=1700856839; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3x/o+ZhKJLhCZxPJDvSVJn2SYXdsZyrTC3illb8aSGE=; b=n3MD3Sh5H8xqE0FjEcX2EbsXPesFttfroDUb+b9h7bnBMvZDhORXYtXi3JhiZc7ex4 7oGnueKjoTqq2QndXC0m0jxNNbCkLYZT6uM4698b36lK3Uj6mWg0mVk3X27TdSNzIHtO ja54WsjRAaS/noNTNUDGPwBrcAJmO48aFyYJa6v43fhQ0fFvroNTkk9ZsNhSCEbHpGED 3H9/aZnIkPGgZPq45LMPzJ44XefJ5bW0/4udqji3+A6E74HpRSN9Lf6k+pccb/dbvMG8 Lk2dX94Z6rlFsVmijDnjfcuqYU0im6NNZIabqaQL7KsAQ5phs7qbDJ0tBCTzLoduLMO0 gIDg== X-Gm-Message-State: AOJu0Yw4QcU9fnfr66t0fOcWg/oYo47zto0Ty5/0h5VcjKZy4/E1wP3o Im+NJh4pLgQKXL7FJlWOLmkRvg== X-Google-Smtp-Source: AGHT+IEbin8UNO6r4Ykm5emy9h67aMHC8MsdLHv1PzpTun13feE0DMgvGrPV0W2CxfD98j+AiJB+qg== X-Received: by 2002:a05:6808:15a8:b0:3b6:3d44:4d75 with SMTP id t40-20020a05680815a800b003b63d444d75mr576150oiw.22.1700252039458; Fri, 17 Nov 2023 12:13:59 -0800 (PST) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id l21-20020a544515000000b003a8560a9d34sm393814oil.25.2023.11.17.12.13.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 12:13:59 -0800 (PST) From: David Lechner To: linux-spi@vger.kernel.org, devicetree@vger.kernel.org Cc: David Lechner , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , Lars-Peter Clausen , linux-kernel@vger.kernel.org Subject: [PATCH 10/14] spi: axi-spi-engine: use message_prepare/unprepare Date: Fri, 17 Nov 2023 14:13:01 -0600 Message-ID: <20231117-axi-spi-engine-series-1-v1-10-cc59db999b87@baylibre.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231117-axi-spi-engine-series-1-v1-0-cc59db999b87@baylibre.com> References: <20231117-axi-spi-engine-series-1-v1-0-cc59db999b87@baylibre.com> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.12.4 This modifies the AXI SPI Engine driver to make use of the message_prepare and message_unprepare callbacks. This separates the concerns of allocating and freeing the message state from the transfer_one_message callback. The main benfit of this is so that future callers of spi_finalize_current_message() will not have to do manual cleanup of the state. Signed-off-by: David Lechner --- drivers/spi/spi-axi-spi-engine.c | 46 +++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c index 745000a9b2c7..210bea23f433 100644 --- a/drivers/spi/spi-axi-spi-engine.c +++ b/drivers/spi/spi-axi-spi-engine.c @@ -412,11 +412,7 @@ static irqreturn_t spi_engine_irq(int irq, void *devid) if (spi_engine->completed_id == st->sync_id) { struct spi_message *msg = spi_engine->msg; - struct spi_engine_message_state *st = msg->state; - ida_free(&spi_engine->sync_ida, st->sync_id); - kfree(st->p); - kfree(st); msg->status = 0; msg->actual_length = msg->frame_length; spi_engine->msg = NULL; @@ -436,14 +432,12 @@ static irqreturn_t spi_engine_irq(int irq, void *devid) return IRQ_HANDLED; } -static int spi_engine_transfer_one_message(struct spi_controller *host, - struct spi_message *msg) +static int spi_engine_prepare_message(struct spi_controller *host, + struct spi_message *msg) { struct spi_engine_program p_dry, *p; struct spi_engine *spi_engine = spi_controller_get_devdata(host); struct spi_engine_message_state *st; - unsigned int int_enable = 0; - unsigned long flags; size_t size; int ret; @@ -472,15 +466,41 @@ static int spi_engine_transfer_one_message(struct spi_controller *host, spi_engine_compile_message(spi_engine, msg, false, p); - spin_lock_irqsave(&spi_engine->lock, flags); spi_engine_program_add_cmd(p, false, SPI_ENGINE_CMD_SYNC(st->sync_id)); - msg->state = st; - spi_engine->msg = msg; st->p = p; - st->cmd_buf = p->instructions; st->cmd_length = p->length; + msg->state = st; + + return 0; +} + +static int spi_engine_unprepare_message(struct spi_controller *host, + struct spi_message *msg) +{ + struct spi_engine *spi_engine = spi_controller_get_devdata(host); + struct spi_engine_message_state *st = msg->state; + + ida_free(&spi_engine->sync_ida, st->sync_id); + kfree(st->p); + kfree(st); + + return 0; +} + +static int spi_engine_transfer_one_message(struct spi_controller *host, + struct spi_message *msg) +{ + struct spi_engine *spi_engine = spi_controller_get_devdata(host); + struct spi_engine_message_state *st = msg->state; + unsigned int int_enable = 0; + unsigned long flags; + + spin_lock_irqsave(&spi_engine->lock, flags); + + spi_engine->msg = msg; + if (spi_engine_write_cmd_fifo(spi_engine)) int_enable |= SPI_ENGINE_INT_CMD_ALMOST_EMPTY; @@ -572,6 +592,8 @@ static int spi_engine_probe(struct platform_device *pdev) host->bits_per_word_mask = SPI_BPW_MASK(8); host->max_speed_hz = clk_get_rate(spi_engine->ref_clk) / 2; host->transfer_one_message = spi_engine_transfer_one_message; + host->prepare_message = spi_engine_prepare_message; + host->unprepare_message = spi_engine_unprepare_message; host->num_chipselect = 8; if (host->max_speed_hz == 0) From patchwork Fri Nov 17 20:13:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 744743 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="zoLAan9f" Received: from mail-oi1-x234.google.com (mail-oi1-x234.google.com [IPv6:2607:f8b0:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33806172A for ; Fri, 17 Nov 2023 12:14:01 -0800 (PST) Received: by mail-oi1-x234.google.com with SMTP id 5614622812f47-3b6d88dbaa3so1487412b6e.1 for ; Fri, 17 Nov 2023 12:14:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1700252040; x=1700856840; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zreOIPUyiZAgHTr9pZpsQXo6OBnZGTBQCaGdmdfM/3Q=; b=zoLAan9fa7rF1Edza9nm2jZE0ZBA2io3ee+yQtzpom8/qDZNmf1O2inL7rvBihiqXt uSKPLQcs1pynXpmq7QkhlUa/ts1LLe1MhE5Bq1Tejlu3WRjKEy1rybpUqZHtovTjacwF C+ROjK58rYm5bH32qxjS34t59j539+SG+xgAWf2388nKTANOJ12A21PlkuBP2bAtgi2x c5dl/2ktAwHeJL1RDvKxHGZSn7SPVfBWW4P13t3SRQsZO+W6CxmFJ/jTieWDYBSJIeQo CaGDwtT4JrG724a+zDuKoWV8iV8YjsVVAQEXvu9JAJPfkWV9aT1XPSAl/wcPgYo+wMCb qMNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700252040; x=1700856840; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zreOIPUyiZAgHTr9pZpsQXo6OBnZGTBQCaGdmdfM/3Q=; b=rVoGIPOmYV7LfiO8F+SRSJI+q6EFtgAQr4X7vk1V7318vI6ZbXsIWlwvqB1CjjwIBa CQs5dkBk36ynS7DL5iay98FiTYNkQzva/eAoMHzaQsNcbA3PqeOBBuk3A+A2rpqNFPGK /XiuWdSRP0/KmZ0+UV5WARtDqO0BkmyYNvSGXzKIx48lNezGbLOpC0fsCdrvfJqTrvEq tABitT5D8Z2bYtwvqzOJM/MSNFcLHPfxoZcDS9HXVgAXosDbFKpvp07hg2Mz6WcD9gG1 0P3C6VRebnkN3kAJZoBoQEvohRcywcsouvP1nxz9T6McgEkluBUHq8rm03XbVdlsnPRd M8Wg== X-Gm-Message-State: AOJu0Yx9BoofghsyGQF9WVgvvtw6V0v5uwpGsmld1G77fYKLNkPKrELJ BlbQBf7V1tEavPOGSoauusD9bg== X-Google-Smtp-Source: AGHT+IEqiwWYiN6HZnqgB/+CsCCnBfOkvomVsWS+AdUE9yqrHGAW/CfIPxPRNw63N4msQ3nIF68LFQ== X-Received: by 2002:a05:6808:60b:b0:3b2:a9bd:c38f with SMTP id y11-20020a056808060b00b003b2a9bdc38fmr428452oih.37.1700252040479; Fri, 17 Nov 2023 12:14:00 -0800 (PST) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id l21-20020a544515000000b003a8560a9d34sm393814oil.25.2023.11.17.12.13.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 12:13:59 -0800 (PST) From: David Lechner To: linux-spi@vger.kernel.org, devicetree@vger.kernel.org Cc: David Lechner , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , Lars-Peter Clausen , linux-kernel@vger.kernel.org Subject: [PATCH 11/14] spi: axi-spi-engine: remove completed_id from driver state Date: Fri, 17 Nov 2023 14:13:02 -0600 Message-ID: <20231117-axi-spi-engine-series-1-v1-11-cc59db999b87@baylibre.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231117-axi-spi-engine-series-1-v1-0-cc59db999b87@baylibre.com> References: <20231117-axi-spi-engine-series-1-v1-0-cc59db999b87@baylibre.com> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.12.4 In the AXI SPI Engine driver, the completed_id field in the driver state is only used in one function and the value does not need to persist between function calls. Therefore, it can be removed from the driver state and made a local variable in the function where it is used. Signed-off-by: David Lechner --- drivers/spi/spi-axi-spi-engine.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c index 210bea23f433..120001dbc4dc 100644 --- a/drivers/spi/spi-axi-spi-engine.c +++ b/drivers/spi/spi-axi-spi-engine.c @@ -115,7 +115,6 @@ struct spi_engine { struct spi_message *msg; struct ida sync_ida; - unsigned int completed_id; unsigned int int_enable; }; @@ -380,13 +379,14 @@ static irqreturn_t spi_engine_irq(int irq, void *devid) struct spi_engine *spi_engine = spi_controller_get_devdata(host); unsigned int disable_int = 0; unsigned int pending; + int completed_id = -1; pending = readl_relaxed(spi_engine->base + SPI_ENGINE_REG_INT_PENDING); if (pending & SPI_ENGINE_INT_SYNC) { writel_relaxed(SPI_ENGINE_INT_SYNC, spi_engine->base + SPI_ENGINE_REG_INT_PENDING); - spi_engine->completed_id = readl_relaxed( + completed_id = readl_relaxed( spi_engine->base + SPI_ENGINE_REG_SYNC_ID); } @@ -410,7 +410,7 @@ static irqreturn_t spi_engine_irq(int irq, void *devid) if (pending & SPI_ENGINE_INT_SYNC && spi_engine->msg) { struct spi_engine_message_state *st = spi_engine->msg->state; - if (spi_engine->completed_id == st->sync_id) { + if (completed_id == st->sync_id) { struct spi_message *msg = spi_engine->msg; msg->status = 0; From patchwork Fri Nov 17 20:13:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 744970 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="qeHkjhHM" Received: from mail-oi1-x234.google.com (mail-oi1-x234.google.com [IPv6:2607:f8b0:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4F191730 for ; Fri, 17 Nov 2023 12:14:01 -0800 (PST) Received: by mail-oi1-x234.google.com with SMTP id 5614622812f47-3b6ce6fac81so1439814b6e.1 for ; Fri, 17 Nov 2023 12:14:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1700252041; x=1700856841; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ja9GtlZjFcJxKQ+nfaNBwXl6V3JiSfQSXjsqjsMOXR4=; b=qeHkjhHMpbe+odDvMjcQssxmn9Jowjsrg73ntJ+RtcqkYbOiVvW5PZhwUrE4EK/xCh 1UDziF6/w3MfjL88xjkyZ3J5yLtUKySnM+qRrvzH759BslAaVqwVrf4bA+fLv1PlLESn ayjRjGQAZpwhXLGHM+OLdddEOL0xDC6gb6mZiGevesvubH2tm1CrFOvGgWefZHL906E2 yFEY1FhhH2QYdyiDUdspgMiwd9dixwAfbcsScBQmh1LBI6lfEC99UC8YHOdDUS1Tdh2A ktVLlKVKV4XQjg8Y17nkCpCHLXEb0NPON6TXTe/ao7zz7kq7TJm/OUnUGzkDtCuKOz6I zmqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700252041; x=1700856841; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ja9GtlZjFcJxKQ+nfaNBwXl6V3JiSfQSXjsqjsMOXR4=; b=xJ3GHzkcKXmJVPxchAuNg9pUNfuxygu3s7TJRQA78CfxnnC6dTkdDE28K53O2jx+3d zJIhaUdLxBVIPkIWv9aPmlwzufIBczWjINwL0Q8wOjcPO5SZ/8WUmPRNS3fQX3iz5Ziw sUkSqa9Uz1TE8qUBamrytApBYx9aWGWxHICfxg15XoS+/fAjThmG47W9T0b04jl1kvhA XpXxk3d6NaDqXsyMAOf76hcheyThdYVq2GHlZVNJGvEETZyLsxWEzByPnyCVL7SJcRCP +QNPX9Frd7VDKUfPkoH7VMbhQtY6bC3bXoeOPEJXCGdzI4uum1EY+ZMda8657+yonPnO 4PQQ== X-Gm-Message-State: AOJu0YwC9erfpERDPfFE6vyw52IdIHLi5t2YY136LISHv8agHg6Jt6rt n75T+u9cUaHQ1204I9M+oGOm2w== X-Google-Smtp-Source: AGHT+IEDfybKnOu/GGZq916PIuwCUX/WXL1yy1MdxiH5bac/b8Q9vM1y0sN41DdLNS8Rd6WpsgoCyg== X-Received: by 2002:a05:6808:1315:b0:3b5:6462:3191 with SMTP id y21-20020a056808131500b003b564623191mr555089oiv.48.1700252041296; Fri, 17 Nov 2023 12:14:01 -0800 (PST) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id l21-20020a544515000000b003a8560a9d34sm393814oil.25.2023.11.17.12.14.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 12:14:00 -0800 (PST) From: David Lechner To: linux-spi@vger.kernel.org, devicetree@vger.kernel.org Cc: David Lechner , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , Lars-Peter Clausen , linux-kernel@vger.kernel.org Subject: [PATCH 12/14] spi: axi-spi-engine: remove struct spi_engine::msg Date: Fri, 17 Nov 2023 14:13:03 -0600 Message-ID: <20231117-axi-spi-engine-series-1-v1-12-cc59db999b87@baylibre.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231117-axi-spi-engine-series-1-v1-0-cc59db999b87@baylibre.com> References: <20231117-axi-spi-engine-series-1-v1-0-cc59db999b87@baylibre.com> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.12.4 In the AXI SPI Engine driver, the struct spi_engine::msg member was used to keep track of the current message being processed. The SPI core is already keeping track of this, so we don't need to duplicate the effort. In most cases, we already have a pointer to the current message, so we can pass it directly to the functions that need it. In the one case where we don't have a pointer to the current message, we can get it from struct spi_controller::cur_msg. Signed-off-by: David Lechner --- drivers/spi/spi-axi-spi-engine.c | 60 +++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c index 120001dbc4dc..c39f478f34a7 100644 --- a/drivers/spi/spi-axi-spi-engine.c +++ b/drivers/spi/spi-axi-spi-engine.c @@ -112,8 +112,6 @@ struct spi_engine { spinlock_t lock; void __iomem *base; - - struct spi_message *msg; struct ida sync_ida; unsigned int int_enable; @@ -252,10 +250,9 @@ static int spi_engine_compile_message(struct spi_engine *spi_engine, return 0; } -static void spi_engine_xfer_next(struct spi_engine *spi_engine, +static void spi_engine_xfer_next(struct spi_message *msg, struct spi_transfer **_xfer) { - struct spi_message *msg = spi_engine->msg; struct spi_transfer *xfer = *_xfer; if (!xfer) { @@ -270,13 +267,13 @@ static void spi_engine_xfer_next(struct spi_engine *spi_engine, *_xfer = xfer; } -static void spi_engine_tx_next(struct spi_engine *spi_engine) +static void spi_engine_tx_next(struct spi_message *msg) { - struct spi_engine_message_state *st = spi_engine->msg->state; + struct spi_engine_message_state *st = msg->state; struct spi_transfer *xfer = st->tx_xfer; do { - spi_engine_xfer_next(spi_engine, &xfer); + spi_engine_xfer_next(msg, &xfer); } while (xfer && !xfer->tx_buf); st->tx_xfer = xfer; @@ -288,13 +285,13 @@ static void spi_engine_tx_next(struct spi_engine *spi_engine) } } -static void spi_engine_rx_next(struct spi_engine *spi_engine) +static void spi_engine_rx_next(struct spi_message *msg) { - struct spi_engine_message_state *st = spi_engine->msg->state; + struct spi_engine_message_state *st = msg->state; struct spi_transfer *xfer = st->rx_xfer; do { - spi_engine_xfer_next(spi_engine, &xfer); + spi_engine_xfer_next(msg, &xfer); } while (xfer && !xfer->rx_buf); st->rx_xfer = xfer; @@ -306,10 +303,11 @@ static void spi_engine_rx_next(struct spi_engine *spi_engine) } } -static bool spi_engine_write_cmd_fifo(struct spi_engine *spi_engine) +static bool spi_engine_write_cmd_fifo(struct spi_engine *spi_engine, + struct spi_message *msg) { void __iomem *addr = spi_engine->base + SPI_ENGINE_REG_CMD_FIFO; - struct spi_engine_message_state *st = spi_engine->msg->state; + struct spi_engine_message_state *st = msg->state; unsigned int n, m, i; const uint16_t *buf; @@ -327,10 +325,11 @@ static bool spi_engine_write_cmd_fifo(struct spi_engine *spi_engine) return st->cmd_length != 0; } -static bool spi_engine_write_tx_fifo(struct spi_engine *spi_engine) +static bool spi_engine_write_tx_fifo(struct spi_engine *spi_engine, + struct spi_message *msg) { void __iomem *addr = spi_engine->base + SPI_ENGINE_REG_SDO_DATA_FIFO; - struct spi_engine_message_state *st = spi_engine->msg->state; + struct spi_engine_message_state *st = msg->state; unsigned int n, m, i; const uint8_t *buf; @@ -344,16 +343,17 @@ static bool spi_engine_write_tx_fifo(struct spi_engine *spi_engine) st->tx_length -= m; n -= m; if (st->tx_length == 0) - spi_engine_tx_next(spi_engine); + spi_engine_tx_next(msg); } return st->tx_length != 0; } -static bool spi_engine_read_rx_fifo(struct spi_engine *spi_engine) +static bool spi_engine_read_rx_fifo(struct spi_engine *spi_engine, + struct spi_message *msg) { void __iomem *addr = spi_engine->base + SPI_ENGINE_REG_SDI_DATA_FIFO; - struct spi_engine_message_state *st = spi_engine->msg->state; + struct spi_engine_message_state *st = msg->state; unsigned int n, m, i; uint8_t *buf; @@ -367,7 +367,7 @@ static bool spi_engine_read_rx_fifo(struct spi_engine *spi_engine) st->rx_length -= m; n -= m; if (st->rx_length == 0) - spi_engine_rx_next(spi_engine); + spi_engine_rx_next(msg); } return st->rx_length != 0; @@ -376,6 +376,7 @@ static bool spi_engine_read_rx_fifo(struct spi_engine *spi_engine) static irqreturn_t spi_engine_irq(int irq, void *devid) { struct spi_controller *host = devid; + struct spi_message *msg = host->cur_msg; struct spi_engine *spi_engine = spi_controller_get_devdata(host); unsigned int disable_int = 0; unsigned int pending; @@ -393,29 +394,26 @@ static irqreturn_t spi_engine_irq(int irq, void *devid) spin_lock(&spi_engine->lock); if (pending & SPI_ENGINE_INT_CMD_ALMOST_EMPTY) { - if (!spi_engine_write_cmd_fifo(spi_engine)) + if (!spi_engine_write_cmd_fifo(spi_engine, msg)) disable_int |= SPI_ENGINE_INT_CMD_ALMOST_EMPTY; } if (pending & SPI_ENGINE_INT_SDO_ALMOST_EMPTY) { - if (!spi_engine_write_tx_fifo(spi_engine)) + if (!spi_engine_write_tx_fifo(spi_engine, msg)) disable_int |= SPI_ENGINE_INT_SDO_ALMOST_EMPTY; } if (pending & (SPI_ENGINE_INT_SDI_ALMOST_FULL | SPI_ENGINE_INT_SYNC)) { - if (!spi_engine_read_rx_fifo(spi_engine)) + if (!spi_engine_read_rx_fifo(spi_engine, msg)) disable_int |= SPI_ENGINE_INT_SDI_ALMOST_FULL; } - if (pending & SPI_ENGINE_INT_SYNC && spi_engine->msg) { - struct spi_engine_message_state *st = spi_engine->msg->state; + if (pending & SPI_ENGINE_INT_SYNC && msg) { + struct spi_engine_message_state *st = msg->state; if (completed_id == st->sync_id) { - struct spi_message *msg = spi_engine->msg; - msg->status = 0; msg->actual_length = msg->frame_length; - spi_engine->msg = NULL; spi_finalize_current_message(host); disable_int |= SPI_ENGINE_INT_SYNC; } @@ -499,16 +497,14 @@ static int spi_engine_transfer_one_message(struct spi_controller *host, spin_lock_irqsave(&spi_engine->lock, flags); - spi_engine->msg = msg; - - if (spi_engine_write_cmd_fifo(spi_engine)) + if (spi_engine_write_cmd_fifo(spi_engine, msg)) int_enable |= SPI_ENGINE_INT_CMD_ALMOST_EMPTY; - spi_engine_tx_next(spi_engine); - if (spi_engine_write_tx_fifo(spi_engine)) + spi_engine_tx_next(msg); + if (spi_engine_write_tx_fifo(spi_engine, msg)) int_enable |= SPI_ENGINE_INT_SDO_ALMOST_EMPTY; - spi_engine_rx_next(spi_engine); + spi_engine_rx_next(msg); if (st->rx_length != 0) int_enable |= SPI_ENGINE_INT_SDI_ALMOST_FULL; From patchwork Fri Nov 17 20:13:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 744742 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="mJuBTJQy" Received: from mail-oi1-x234.google.com (mail-oi1-x234.google.com [IPv6:2607:f8b0:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B475173E for ; Fri, 17 Nov 2023 12:14:02 -0800 (PST) Received: by mail-oi1-x234.google.com with SMTP id 5614622812f47-3b566ee5f1dso1446484b6e.0 for ; Fri, 17 Nov 2023 12:14:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1700252042; x=1700856842; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6P+/RJb/cpUDSZO9aZmvZcYWX64h3DCpi271jxLHolk=; b=mJuBTJQyYIMZXnaCfua6kd7F4fee5sTKKD/NSeXd0DEH8JMEXpWpvWeYM+UxSvPdhL igr9ZTk3aWYW4EKOr4jJmq74uKxBn/zMM8srLf/HJz3ldK9b2vekNqWIZJgMt+3LbZh7 DkFozzyjukJtnZ0lw9w+YW1yas8rIYPyhPlHRujUhO4Y/o0k5GGMC260bA1fLKq6I+iD dXG9qfwYI5ov35igQhrlHcO7GoiKNV0otvgNcaasvQr7hk26GpRfztiet6KrD1Xm9M7s /emAhjdEVL2TWm0gLBpDsWQwpu3bO7B9kpYAkkIAMbb8cEkPX+Jc2XwiYRqqH5gULECB 2A7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700252042; x=1700856842; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6P+/RJb/cpUDSZO9aZmvZcYWX64h3DCpi271jxLHolk=; b=CCOK6yoU2R6ktx/XtxeX+UgYHu5l3HGV71EmlkymYF2OKGENwVGHguimAU1KiBK6m6 HdN6eobIE2MXe2E1iJGBd7hnKPbU2gvolWBpOVqNcXhnn4PlJMUHQ+fSy7NIaR+jIYYc KIcQ1qzDnBDZxV0EkKmpypdJRaBk4Yrj6HIxU7h7bIOvwh1ZHXZTxnnMqKi+WsUc+33k PMah3mldH8KypmbQmrBIu1cDCkUMXXS6TvUFih828bsG/ts1fMYhfsE+j9ia3DO5H8Lo cjZbaEQoVWtizF1lq40TVQMqxgAa4Fs6+KfQqD9L1sIRSwWIaMTSs+86qVaurhbuHEyz PqlQ== X-Gm-Message-State: AOJu0YyDslTISPr5GIWamCGJxgwnFa3/OI9aXpDwaz+3JBjpxKZb8dbI nAIV4t7+rLjNS9ST9yly3aDelQ== X-Google-Smtp-Source: AGHT+IFEitzBPfYZPR5lABqTFEOeHF0t8EqCeQ2/c/+BO/rZ9LzA3npUgrEGfGJe2sKopIY/JWdDoQ== X-Received: by 2002:a05:6808:f07:b0:3b2:d8c8:7bfa with SMTP id m7-20020a0568080f0700b003b2d8c87bfamr555396oiw.8.1700252042081; Fri, 17 Nov 2023 12:14:02 -0800 (PST) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id l21-20020a544515000000b003a8560a9d34sm393814oil.25.2023.11.17.12.14.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 12:14:01 -0800 (PST) From: David Lechner To: linux-spi@vger.kernel.org, devicetree@vger.kernel.org Cc: David Lechner , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , Lars-Peter Clausen , linux-kernel@vger.kernel.org Subject: [PATCH 13/14] spi: axi-spi-engine: add support for cs_off Date: Fri, 17 Nov 2023 14:13:04 -0600 Message-ID: <20231117-axi-spi-engine-series-1-v1-13-cc59db999b87@baylibre.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231117-axi-spi-engine-series-1-v1-0-cc59db999b87@baylibre.com> References: <20231117-axi-spi-engine-series-1-v1-0-cc59db999b87@baylibre.com> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.12.4 This adds support for the spi_transfer::cs_off flag to the AXI SPI Engine driver. The logic is copied from the generic spi_transfer_one_message() in spi.c. Signed-off-by: David Lechner --- drivers/spi/spi-axi-spi-engine.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c index c39f478f34a7..1c60e6486ee2 100644 --- a/drivers/spi/spi-axi-spi-engine.c +++ b/drivers/spi/spi-axi-spi-engine.c @@ -216,7 +216,7 @@ static int spi_engine_compile_message(struct spi_engine *spi_engine, struct spi_device *spi = msg->spi; struct spi_transfer *xfer; int clk_div, new_clk_div; - bool cs_change = true; + bool keep_cs = false; clk_div = -1; @@ -224,6 +224,9 @@ static int spi_engine_compile_message(struct spi_engine *spi_engine, SPI_ENGINE_CMD_WRITE(SPI_ENGINE_CMD_REG_CONFIG, spi_engine_get_config(spi))); + xfer = list_first_entry(&msg->transfers, struct spi_transfer, transfer_list); + spi_engine_gen_cs(p, dry, spi, !xfer->cs_off); + list_for_each_entry(xfer, &msg->transfers, transfer_list) { new_clk_div = spi_engine_get_clk_div(spi_engine, spi, xfer); if (new_clk_div != clk_div) { @@ -233,20 +236,28 @@ static int spi_engine_compile_message(struct spi_engine *spi_engine, clk_div)); } - if (cs_change) - spi_engine_gen_cs(p, dry, spi, true); - spi_engine_gen_xfer(p, dry, xfer); spi_engine_gen_sleep(p, dry, spi_engine, clk_div, xfer); - cs_change = xfer->cs_change; - if (list_is_last(&xfer->transfer_list, &msg->transfers)) - cs_change = !cs_change; - - if (cs_change) - spi_engine_gen_cs(p, dry, spi, false); + if (xfer->cs_change) { + if (list_is_last(&xfer->transfer_list, &msg->transfers)) { + keep_cs = true; + } else { + if (!xfer->cs_off) + spi_engine_gen_cs(p, dry, spi, false); + + if (!list_next_entry(xfer, transfer_list)->cs_off) + spi_engine_gen_cs(p, dry, spi, true); + } + } else if (!list_is_last(&xfer->transfer_list, &msg->transfers) && + xfer->cs_off != list_next_entry(xfer, transfer_list)->cs_off) { + spi_engine_gen_cs(p, dry, spi, xfer->cs_off); + } } + if (!keep_cs) + spi_engine_gen_cs(p, dry, spi, false); + return 0; } From patchwork Fri Nov 17 20:13:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 744969 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="QoyamuIG" Received: from mail-oi1-x22a.google.com (mail-oi1-x22a.google.com [IPv6:2607:f8b0:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A09D6D6C for ; Fri, 17 Nov 2023 12:14:03 -0800 (PST) Received: by mail-oi1-x22a.google.com with SMTP id 5614622812f47-3b6cfc62514so1157104b6e.0 for ; Fri, 17 Nov 2023 12:14:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1700252043; x=1700856843; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PH/rzTgmg6EPZdKGbbueBGhoeiFd6EbUxFAdwFmnGz0=; b=QoyamuIGyvaCFAItIzBvcz/WC2NNgCFhQq9ulXDGjENTXxp5EDmYMcoJWQGIkKlEVX rIi+lyAMhebdHjrXs41naJGKzHRLuFqrCSVxwPKY4LxYBvz05rdnXO8DmENJam6SByjw JUyoL0BA2WBd0MbI5QhTuAo6/1FUOBpyBpgrz9RO876ycQplhlGj3LOieJyZx9kxvqB8 n8xwsrgNtx2cTSxOLP0BHdDemNIqYXtCQMK9TRPhjbAlirYftngbVrtKwpxtmXdZkx8m UkH7bBck+ypFFj/hITwss8XBLxXwGFJKMMHwDeiHSWhtPG9ou4ZAS25bC1O2IPJUEEaM 8GvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700252043; x=1700856843; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PH/rzTgmg6EPZdKGbbueBGhoeiFd6EbUxFAdwFmnGz0=; b=pyk1q9mNm8t5/7mS0qWEmk0ckx/DBCWhgLOsq9Mb/04wsBd+N+thIuSiH2i3zw8mk+ 3ITdssdyIizMwLyAh+4dgd7nWBTVx8p8/lqmr1w4JThC/N/UbS1kcDt4xtWECSd4kKAq Smpsc7m4BCUAQkELYNHuEts+k0anQkCFIfh1OrJAsXreiopvEKaugaBPRJzI2/2ekvdK KlIUaVRDs3RNJLvc9ATj6VraNqfka9ZHE0D66h45SBP05vSx/CBaIV6kIZCCzogH1imL hByLt/ID3SSVkCxXeZ4VA+vhaKARXNJNWS/kE99tzyrs4Eqc8QrQf2ink+GRhNPxdWIP i5DQ== X-Gm-Message-State: AOJu0Yx5v/V0ZThsGLr8lZz6HNElvVnIpTux1S2CapVsGR5+enh3YJqO yZc0Omrv4t77AsTZuU0XnpBVQQ== X-Google-Smtp-Source: AGHT+IHL8X+/aek0UmGtyfVgTRCGoiVnXbvK0cUocB5DvFljKkSQo3iFU0tbHLO3SetM0Kkp/lsXmw== X-Received: by 2002:a05:6808:d1:b0:3b2:e4b7:2af2 with SMTP id t17-20020a05680800d100b003b2e4b72af2mr3093122oic.6.1700252042902; Fri, 17 Nov 2023 12:14:02 -0800 (PST) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id l21-20020a544515000000b003a8560a9d34sm393814oil.25.2023.11.17.12.14.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 12:14:02 -0800 (PST) From: David Lechner To: linux-spi@vger.kernel.org, devicetree@vger.kernel.org Cc: David Lechner , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , Lars-Peter Clausen , linux-kernel@vger.kernel.org Subject: [PATCH 14/14] spi: axi-spi-engine: add support for any word size Date: Fri, 17 Nov 2023 14:13:05 -0600 Message-ID: <20231117-axi-spi-engine-series-1-v1-14-cc59db999b87@baylibre.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231117-axi-spi-engine-series-1-v1-0-cc59db999b87@baylibre.com> References: <20231117-axi-spi-engine-series-1-v1-0-cc59db999b87@baylibre.com> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.12.4 The AXI SPI Engine IP supports any word size from 1 to 32 bits. This adds support for this by setting the bits_per_word_mask and emitting the appropriate instruction to the SPI Engine each time a transfer requires a new word size. The functions that transfer tx/rx buffers from/to the SPI Engine registers (spi_engine_write_{tx,rx}_fifo()) as well as the function that creates the transfer instruction (spi_engine_gen_xfer()) also have to be modified to take into account the word size since xfer->len is the size of the buffers in bytes rather than words. Signed-off-by: David Lechner --- drivers/spi/spi-axi-spi-engine.c | 84 ++++++++++++++++++++++++++++++++-------- 1 file changed, 68 insertions(+), 16 deletions(-) diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c index 1c60e6486ee2..cbca783830ea 100644 --- a/drivers/spi/spi-axi-spi-engine.c +++ b/drivers/spi/spi-axi-spi-engine.c @@ -53,6 +53,7 @@ #define SPI_ENGINE_CMD_REG_CLK_DIV 0x0 #define SPI_ENGINE_CMD_REG_CONFIG 0x1 +#define SPI_ENGINE_CMD_REG_XFER_BITS 0x2 #define SPI_ENGINE_MISC_SYNC 0x0 #define SPI_ENGINE_MISC_SLEEP 0x1 @@ -157,7 +158,14 @@ static unsigned int spi_engine_get_clk_div(struct spi_engine *spi_engine, static void spi_engine_gen_xfer(struct spi_engine_program *p, bool dry, struct spi_transfer *xfer) { - unsigned int len = xfer->len; + unsigned int len; + + if (xfer->bits_per_word <= 8) + len = xfer->len; + else if (xfer->bits_per_word <= 16) + len = xfer->len / 2; + else + len = xfer->len / 4; while (len) { unsigned int n = min(len, 256U); @@ -217,6 +225,7 @@ static int spi_engine_compile_message(struct spi_engine *spi_engine, struct spi_transfer *xfer; int clk_div, new_clk_div; bool keep_cs = false; + u8 bits_per_word = 0; clk_div = -1; @@ -236,6 +245,13 @@ static int spi_engine_compile_message(struct spi_engine *spi_engine, clk_div)); } + if (bits_per_word != xfer->bits_per_word) { + bits_per_word = xfer->bits_per_word; + spi_engine_program_add_cmd(p, dry, + SPI_ENGINE_CMD_WRITE(SPI_ENGINE_CMD_REG_XFER_BITS, + bits_per_word)); + } + spi_engine_gen_xfer(p, dry, xfer); spi_engine_gen_sleep(p, dry, spi_engine, clk_div, xfer); @@ -342,16 +358,34 @@ static bool spi_engine_write_tx_fifo(struct spi_engine *spi_engine, void __iomem *addr = spi_engine->base + SPI_ENGINE_REG_SDO_DATA_FIFO; struct spi_engine_message_state *st = msg->state; unsigned int n, m, i; - const uint8_t *buf; n = readl_relaxed(spi_engine->base + SPI_ENGINE_REG_SDO_FIFO_ROOM); while (n && st->tx_length) { - m = min(n, st->tx_length); - buf = st->tx_buf; - for (i = 0; i < m; i++) - writel_relaxed(buf[i], addr); - st->tx_buf += m; - st->tx_length -= m; + if (st->tx_xfer->bits_per_word <= 8) { + const u8 *buf = st->tx_buf; + + m = min(n, st->tx_length); + for (i = 0; i < m; i++) + writel_relaxed(buf[i], addr); + st->tx_buf += m; + st->tx_length -= m; + } else if (st->tx_xfer->bits_per_word <= 16) { + const u16 *buf = (const u16 *)st->tx_buf; + + m = min(n, st->tx_length / 2); + for (i = 0; i < m; i++) + writel_relaxed(buf[i], addr); + st->tx_buf += m * 2; + st->tx_length -= m * 2; + } else { + const u32 *buf = (const u32 *)st->tx_buf; + + m = min(n, st->tx_length / 4); + for (i = 0; i < m; i++) + writel_relaxed(buf[i], addr); + st->tx_buf += m * 4; + st->tx_length -= m * 4; + } n -= m; if (st->tx_length == 0) spi_engine_tx_next(msg); @@ -366,16 +400,34 @@ static bool spi_engine_read_rx_fifo(struct spi_engine *spi_engine, void __iomem *addr = spi_engine->base + SPI_ENGINE_REG_SDI_DATA_FIFO; struct spi_engine_message_state *st = msg->state; unsigned int n, m, i; - uint8_t *buf; n = readl_relaxed(spi_engine->base + SPI_ENGINE_REG_SDI_FIFO_LEVEL); while (n && st->rx_length) { - m = min(n, st->rx_length); - buf = st->rx_buf; - for (i = 0; i < m; i++) - buf[i] = readl_relaxed(addr); - st->rx_buf += m; - st->rx_length -= m; + if (st->rx_xfer->bits_per_word <= 8) { + u8 *buf = st->rx_buf; + + m = min(n, st->rx_length); + for (i = 0; i < m; i++) + buf[i] = readl_relaxed(addr); + st->rx_buf += m; + st->rx_length -= m; + } else if (st->rx_xfer->bits_per_word <= 16) { + u16 *buf = (u16 *)st->rx_buf; + + m = min(n, st->rx_length / 2); + for (i = 0; i < m; i++) + buf[i] = readl_relaxed(addr); + st->rx_buf += m * 2; + st->rx_length -= m * 2; + } else { + u32 *buf = (u32 *)st->rx_buf; + + m = min(n, st->rx_length / 4); + for (i = 0; i < m; i++) + buf[i] = readl_relaxed(addr); + st->rx_buf += m * 4; + st->rx_length -= m * 4; + } n -= m; if (st->rx_length == 0) spi_engine_rx_next(msg); @@ -596,7 +648,7 @@ static int spi_engine_probe(struct platform_device *pdev) host->dev.of_node = pdev->dev.of_node; host->mode_bits = SPI_CPOL | SPI_CPHA | SPI_3WIRE; - host->bits_per_word_mask = SPI_BPW_MASK(8); + host->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32); host->max_speed_hz = clk_get_rate(spi_engine->ref_clk) / 2; host->transfer_one_message = spi_engine_transfer_one_message; host->prepare_message = spi_engine_prepare_message;