From nobody Tue Dec 30 07:41:41 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3679CC5AD4C for ; Fri, 17 Nov 2023 20:14:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235722AbjKQUOB (ORCPT ); Fri, 17 Nov 2023 15:14:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232185AbjKQUN5 (ORCPT ); Fri, 17 Nov 2023 15:13:57 -0500 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 38FD9D7E for ; Fri, 17 Nov 2023 12:13:53 -0800 (PST) Received: by mail-oi1-x230.google.com with SMTP id 5614622812f47-3b52360cdf0so1377065b6e.2 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=BRl3+opoDSn5g0alYZN2782b45mwo7T/ENY8YMQWY8GCGl40xfOp/HWWMC+J/638F4 pOPnq8YV//EGl5zyKQUuwfb1fAovG94VcVKuIfSFNrq3z6vy5rGOHMYsJJLZpbvIsn1l LfFL26mVbD45ZT3RJQTzOefNqciBtnlVe0TXTkqJOhYifZf9KwgkBh8wbdXJZzo0jTxA f6KVO0HvgimAcuRGVUMgEcWh3I76B5zMFdbj3cAYHjlStPEcGx5pKxD5yLGHtplAwyt8 92yCtzZHUBvd6vepiPWh+Y1hCRuG5uG2lhNkEmpVctyoJk/KwAZglbizNM4tTakXkGmT QjOQ== X-Gm-Message-State: AOJu0YzJyWoDMtY3Cep8eli07c45A0FEAFsCDCUTBs625SCNaqrBdQ3h oQIrOXGCxHDeTIYrAwfkzUGCyfVC3zftZNCr7adjuw== 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> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.12.4 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 =3D "adi,axi-spi-engine-1.00.a"; - reg =3D <0x44a00000 0x1000>; - interrupts =3D <0 56 4>; - clocks =3D <&clkc 15 &clkc 15>; - clock-names =3D "s_axi_aclk", "spi_clk"; - - #address-cells =3D <1>; - #size-cells =3D <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=C3=A1 + +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 =3D "adi,axi-spi-engine-1.00.a"; + reg =3D <0x44a00000 0x1000>; + interrupts =3D <0 56 4>; + clocks =3D <&clkc 15>, <&clkc 15>; + clock-names =3D "s_axi_aclk", "spi_clk"; + + #address-cells =3D <1>; + #size-cells =3D <0>; + + /* SPI devices */ + }; --=20 2.42.0 From nobody Tue Dec 30 07:41:41 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA827C072A2 for ; Fri, 17 Nov 2023 20:14:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232163AbjKQUOD (ORCPT ); Fri, 17 Nov 2023 15:14:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232195AbjKQUN5 (ORCPT ); Fri, 17 Nov 2023 15:13:57 -0500 Received: from mail-oi1-x22b.google.com (mail-oi1-x22b.google.com [IPv6:2607:f8b0:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 963E210D9 for ; Fri, 17 Nov 2023 12:13:53 -0800 (PST) Received: by mail-oi1-x22b.google.com with SMTP id 5614622812f47-3b2ea7cca04so1480148b6e.2 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=MGK3wKmilA2V0KlT1LmWTQ1vlMHefTvtlVOZ8sZ+PKOb+281CYcAEIfRzo9JTojhPa Ugw0xr64uTpoTyFK08L6S7uEr1l5e4TvWVXNbSyfJzfvSCtjDonqCK4V+kan5mOZm3Uw wxQewwfj12p52raZ94sfQ82IeSxqkIvf8rcCuhzMzvD7dNiQQREE8z0Lkd5WLM2PYEsL c4HWz/MQpxODtgC0JDaiHLlcewuAUBS+KKV2iysszbLjAPXwlItubDnTdzU0E4yhfUAh j+QO+mdt5nvIJH84z4T2clnzZ8OUE7zBxWx+Iy2RuqEpQM8wnvBTfZgTsvUT4qdpxhaH v5zA== X-Gm-Message-State: AOJu0YwdDGexlus+Y8DffVwKVYUFvWNMaUsPtr+lggDpiI/j/Soxl5qG GiVJSxOM9MNIc5VdhnlghFe2WbtLWJOss0QbHZJeKA== 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> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.12.4 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 =20 +AXI SPI ENGINE +M: Michael Hennerich +M: Nuno S=C3=A1 +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 --=20 2.42.0 From nobody Tue Dec 30 07:41:41 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A000C54FB9 for ; Fri, 17 Nov 2023 20:14:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346187AbjKQUOH (ORCPT ); Fri, 17 Nov 2023 15:14:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232705AbjKQUN5 (ORCPT ); Fri, 17 Nov 2023 15:13:57 -0500 Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55CA210E5 for ; Fri, 17 Nov 2023 12:13:54 -0800 (PST) Received: by mail-oi1-x233.google.com with SMTP id 5614622812f47-3b40d5ea323so1497219b6e.0 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=cP25IULSMNaY8IUSz3mbd0wfSQvqjHOAoV/BX2hIFBiWVAUctEQbsvD5iQbpEjJti5 h/pMnFR9ZjC56mve6sd5owhKje2tWGDMrEHaM4CFczkGM8Ea5cLQj1DD5JT2PWVefJ4T YeVigSllkA+LMzC1E0E4ax4FpKFvLp3o7+zWL1OYiNCUI1lg2oOm0GEVDGHdrDzdgXoX tea5NYNdNk5NQGuCades+IPHqIO/t+DRXESoWJ3anbQR6q1Ax0aWOqCCJQsFyb9zOYgT l+TKAn4+VOUj81t/rjK+SklIpRdxaiffuvrmF4jjGlsjQQNXpgFbUZ3etMxm5Nmce9XA PVsg== X-Gm-Message-State: AOJu0YyNXRImQrlettSQfzgtHhP4wQt/u8BjbqUdjBoE//F3YeRdjOEE QVLUAWN4h78OQGMhozBaLBdwfA== 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> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.12.4 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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-eng= ine.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 *p= dev) if (irq < 0) return irq; =20 - spi_engine =3D devm_kzalloc(&pdev->dev, sizeof(*spi_engine), GFP_KERNEL); - if (!spi_engine) - return -ENOMEM; - - host =3D spi_alloc_host(&pdev->dev, 0); + host =3D spi_alloc_host(&pdev->dev, sizeof(*spi_engine)); if (!host) return -ENOMEM; =20 - spi_controller_set_devdata(host, spi_engine); + spi_engine =3D spi_controller_get_devdata(host); =20 spin_lock_init(&spi_engine->lock); =20 --=20 2.42.0 From nobody Tue Dec 30 07:41:41 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C18F9C072A2 for ; Fri, 17 Nov 2023 20:14:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346204AbjKQUOI (ORCPT ); Fri, 17 Nov 2023 15:14:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235091AbjKQUN6 (ORCPT ); Fri, 17 Nov 2023 15:13:58 -0500 Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FC12D7E for ; Fri, 17 Nov 2023 12:13:55 -0800 (PST) Received: by mail-oi1-x233.google.com with SMTP id 5614622812f47-3b6d88dbaa3so1487346b6e.1 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=qLPfXiwEp+nV+bN6Yueubd/0rx30NhqeVMBzyPPi8kfuHySvD6AzO3ok9wvbpBkWyi SKLabHjw3LhlP2VzlP3b4eU8LM6ArXJJwX6xdZ4tlKilCPf4NNw29dFoBtGyZHuXTyct oUlMl1BrqBjyIdYgT4o2ePAbcbC9PZndFNLZny0B4FZuutgmCZraoIwkohs0UhUVkzyZ dLDwEr1zMclUqZSO7uLhhRZGDStKz+lwplHgsfVJLNggcuHN4PH5T4rg24c9p2UMHNTV EMQtkTHkHDwP1hXT8cDbqpffYjhyHxk7/FOo/NGwhcYY2oZKt5NevG8rCfTP7i0xFfVE YMjw== X-Gm-Message-State: AOJu0YzIIOWCyUpicWaLzvU9uQQACYOGrhevUN1ulL+WLU21EdJLHZvc lawkn2mXsIYeFXTM5/vbay6P6Q== 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> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.12.4 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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-eng= ine.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 *pde= v) if (irq < 0) return irq; =20 - host =3D spi_alloc_host(&pdev->dev, sizeof(*spi_engine)); + host =3D devm_spi_alloc_host(&pdev->dev, sizeof(*spi_engine)); if (!host) return -ENOMEM; =20 @@ -482,22 +482,16 @@ static int spi_engine_probe(struct platform_device *p= dev) spin_lock_init(&spi_engine->lock); =20 spi_engine->clk =3D devm_clk_get_enabled(&pdev->dev, "s_axi_aclk"); - if (IS_ERR(spi_engine->clk)) { - ret =3D PTR_ERR(spi_engine->clk); - goto err_put_host; - } + if (IS_ERR(spi_engine->clk)) + return PTR_ERR(spi_engine->clk); =20 spi_engine->ref_clk =3D devm_clk_get_enabled(&pdev->dev, "spi_clk"); - if (IS_ERR(spi_engine->ref_clk)) { - ret =3D PTR_ERR(spi_engine->ref_clk); - goto err_put_host; - } + if (IS_ERR(spi_engine->ref_clk)) + return PTR_ERR(spi_engine->ref_clk); =20 spi_engine->base =3D devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(spi_engine->base)) { - ret =3D PTR_ERR(spi_engine->base); - goto err_put_host; - } + if (IS_ERR(spi_engine->base)) + return PTR_ERR(spi_engine->base); =20 version =3D readl(spi_engine->base + SPI_ENGINE_REG_VERSION); if (SPI_ENGINE_VERSION_MAJOR(version) !=3D 1) { @@ -505,8 +499,7 @@ static int spi_engine_probe(struct platform_device *pde= v) SPI_ENGINE_VERSION_MAJOR(version), SPI_ENGINE_VERSION_MINOR(version), SPI_ENGINE_VERSION_PATCH(version)); - ret =3D -ENODEV; - goto err_put_host; + return -ENODEV; } =20 writel_relaxed(0x00, spi_engine->base + SPI_ENGINE_REG_RESET); @@ -515,7 +508,7 @@ static int spi_engine_probe(struct platform_device *pde= v) =20 ret =3D request_irq(irq, spi_engine_irq, 0, pdev->name, host); if (ret) - goto err_put_host; + return ret; =20 host->dev.of_node =3D pdev->dev.of_node; host->mode_bits =3D SPI_CPOL | SPI_CPHA | SPI_3WIRE; @@ -533,14 +526,12 @@ static int spi_engine_probe(struct platform_device *p= dev) return 0; err_free_irq: free_irq(irq, host); -err_put_host: - spi_controller_put(host); return ret; } =20 static void spi_engine_remove(struct platform_device *pdev) { - struct spi_controller *host =3D spi_controller_get(platform_get_drvdata(p= dev)); + struct spi_controller *host =3D platform_get_drvdata(pdev); struct spi_engine *spi_engine =3D spi_controller_get_devdata(host); int irq =3D platform_get_irq(pdev, 0); =20 @@ -548,8 +539,6 @@ static void spi_engine_remove(struct platform_device *p= dev) =20 free_irq(irq, host); =20 - 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); --=20 2.42.0 From nobody Tue Dec 30 07:41:41 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6194AC5ACB3 for ; Fri, 17 Nov 2023 20:14:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346208AbjKQUOK (ORCPT ); Fri, 17 Nov 2023 15:14:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232631AbjKQUN7 (ORCPT ); Fri, 17 Nov 2023 15:13:59 -0500 Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12D68D57 for ; Fri, 17 Nov 2023 12:13:56 -0800 (PST) Received: by mail-oi1-x233.google.com with SMTP id 5614622812f47-3b3f55e1bbbso1513212b6e.2 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=WfBAF98ih7L9z3cUCHXTl0hdPs5QST9A/yzTqbhekIxqugNHamwl6EK0xdkG7RFHBk g0ohF4iG5zqur0eS4mzelyXMni3B9i7XqXsPmiCN+/8KleYDcsQWB0bzY2ltmkL2bVlg cTmdR4OQhPtQyG0xhSqlt5qQ1glO2gY69s/UnEhjvkbfBjk5ehcJMpIZzttXMTxC47HB Q+pO8hUA6uvErA1WanC8izm1tfG25XmDDOA30m56Vai/JfFYj1g2Kpvole/rF/8DAIcn WVtk6lf25vi8LB8enCn4z4G56Fs4OGiQv93JYkHs2IxRCazo91hG69Qlztx6Cioho4q9 HiPQ== X-Gm-Message-State: AOJu0Yyjew+Ft7rG0q4yVmAX+mN29SQ6pPoiZcj3huhxFkPdWXYeA4wI ucF8khiT+XMPpInIoxbOfvqTFg== 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> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.12.4 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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-eng= ine.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; } =20 +static void spi_engine_release_hw(void *p) +{ + struct spi_engine *spi_engine =3D 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 *pd= ev) writel_relaxed(0xff, spi_engine->base + SPI_ENGINE_REG_INT_PENDING); writel_relaxed(0x00, spi_engine->base + SPI_ENGINE_REG_INT_ENABLE); =20 + ret =3D devm_add_action_or_reset(&pdev->dev, spi_engine_release_hw, + spi_engine); + if (ret) + return ret; + ret =3D 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 *p= dev) static void spi_engine_remove(struct platform_device *pdev) { struct spi_controller *host =3D platform_get_drvdata(pdev); - struct spi_engine *spi_engine =3D spi_controller_get_devdata(host); int irq =3D platform_get_irq(pdev, 0); =20 spi_unregister_controller(host); =20 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); } =20 static const struct of_device_id spi_engine_match_table[] =3D { --=20 2.42.0 From nobody Tue Dec 30 07:41:41 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA080C072A2 for ; Fri, 17 Nov 2023 20:14:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346211AbjKQUON (ORCPT ); Fri, 17 Nov 2023 15:14:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235724AbjKQUOB (ORCPT ); Fri, 17 Nov 2023 15:14:01 -0500 Received: from mail-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E63A3D7A for ; Fri, 17 Nov 2023 12:13:56 -0800 (PST) Received: by mail-oi1-x236.google.com with SMTP id 5614622812f47-3b3f55e1bbbso1513218b6e.2 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=hQdCcrNZNXAGrO5b6GASfVQviodzD9WV+yRxCSh5nWJMT2YzZ0PNPouwY29jKt59V4 +iRIrJFGQOUWhgbPNRZMJ0iRe7YP6kjXrmK71y+x3bIaizbAksd95vxM796BS29gQMPD i8wqOZZAmuPM4GIYanLe85gL9v1UVa+8uRw6Txc8FT68IsUX1H57W4ab2UddrBCfD+c6 Clx9euK3XfhCQilDNMLawdFjlwIrWGp36k3QZj9o32ExgF+Qsq/4oLTIMrzsfOQ29Pp0 Q85O8a35dle7hTUZ32xkbSACTWNJlA8KG0N+NJNgL5Ws1dDC5wMNfRfWUUPztxbwiwnB UcHQ== X-Gm-Message-State: AOJu0YxvFRWZQzUu+q5IAT7w8TLeDVgAL+sGuPx9ZSIEofw8KKJCVRDi p95o4bgcvzS4Y+VTDs0MIAlnIg== 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> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.12.4 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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-eng= ine.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 *pde= v) if (ret) return ret; =20 - ret =3D request_irq(irq, spi_engine_irq, 0, pdev->name, host); + ret =3D devm_request_irq(&pdev->dev, irq, spi_engine_irq, 0, pdev->name, + host); if (ret) return ret; =20 @@ -533,24 +534,18 @@ static int spi_engine_probe(struct platform_device *p= dev) =20 ret =3D spi_register_controller(host); if (ret) - goto err_free_irq; + return ret; =20 platform_set_drvdata(pdev, host); =20 return 0; -err_free_irq: - free_irq(irq, host); - return ret; } =20 static void spi_engine_remove(struct platform_device *pdev) { struct spi_controller *host =3D platform_get_drvdata(pdev); - int irq =3D platform_get_irq(pdev, 0); =20 spi_unregister_controller(host); - - free_irq(irq, host); } =20 static const struct of_device_id spi_engine_match_table[] =3D { --=20 2.42.0 From nobody Tue Dec 30 07:41:41 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98DC5C54FB9 for ; Fri, 17 Nov 2023 20:14:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346198AbjKQUOP (ORCPT ); Fri, 17 Nov 2023 15:14:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235726AbjKQUOB (ORCPT ); Fri, 17 Nov 2023 15:14:01 -0500 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 AE00410D5 for ; Fri, 17 Nov 2023 12:13:57 -0800 (PST) Received: by mail-oi1-x22e.google.com with SMTP id 5614622812f47-3b2df2fb611so1609902b6e.0 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=imBIKK6AUSZJTm+5s1peYQnkB0flDt+7qkJnA8PTP95EQkhnvwPRcSFQ9CKnPkMvni zxQLDXH46N3m7hsxQg/17GKQjNeEx34sb9CYFci01SpkH1Aburz3X0JqiImnvYEx+six dHNIVPd1j+btYwPCvKcjhesAeWBJwp1SapxG0pNolYaIP8RfXHu3a+apDqRmvKiAVwEw WNT4/QjnII22jwx7TtefUQFWXg2cfHoE8Nfvt2R/GX0Ct1Jv3JqL5H8QsiwXZI5bsvcc MHW6XssUgMmoprsagLC0aeIjSSrEzvaRRxVPEDwUcUwX2Utf5TsIfkB0nivFVGB99f2l nT1w== X-Gm-Message-State: AOJu0YwBthyXBWePystdeGkR/qHjjTzSFbwRMirbVNA0HZ1CmHGlzP/C XTyghPls7m6bzaaTfm3Y+71Upg== 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> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.12.4 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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-eng= ine.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 *pde= v) host->transfer_one_message =3D spi_engine_transfer_one_message; host->num_chipselect =3D 8; =20 - ret =3D spi_register_controller(host); + ret =3D devm_spi_register_controller(&pdev->dev, host); if (ret) return ret; =20 @@ -541,13 +541,6 @@ static int spi_engine_probe(struct platform_device *pd= ev) return 0; } =20 -static void spi_engine_remove(struct platform_device *pdev) -{ - struct spi_controller *host =3D platform_get_drvdata(pdev); - - spi_unregister_controller(host); -} - static const struct of_device_id spi_engine_match_table[] =3D { { .compatible =3D "adi,axi-spi-engine-1.00.a" }, { }, @@ -556,7 +549,6 @@ MODULE_DEVICE_TABLE(of, spi_engine_match_table); =20 static struct platform_driver spi_engine_driver =3D { .probe =3D spi_engine_probe, - .remove_new =3D spi_engine_remove, .driver =3D { .name =3D "spi-engine", .of_match_table =3D spi_engine_match_table, --=20 2.42.0 From nobody Tue Dec 30 07:41:41 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A76FC5ACB3 for ; Fri, 17 Nov 2023 20:14:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235769AbjKQUOW (ORCPT ); Fri, 17 Nov 2023 15:14:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346154AbjKQUOD (ORCPT ); Fri, 17 Nov 2023 15:14:03 -0500 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 6D96510D9 for ; Fri, 17 Nov 2023 12:13:58 -0800 (PST) Received: by mail-oi1-x232.google.com with SMTP id 5614622812f47-3b566ee5f1dso1446450b6e.0 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=arnrjCngIYOWQ/wrnXpvq07rL3xZ9sZ+hT7INJ+3qAgOsVmMcd0fW+Yg9BH4ZB5p/d VYppAg40Zn4Py/fJkx1Q3RMJEeuC00HcSzLnNr6Ak6FYZ21sGl/9mQy/uI2k/lwqSnOn Ud5pEI6cr7XvYYrO1RwaPKEgOJLgEdbSo0Xu3j3LZlJXHHq113sVspL62FWAGx+GcJHX q3RYgZS06ez+knUf60G7ZqP7byhUe2x1nZ+MQ53e/L3+fYNULATglCRxGV3VabkqPK28 qE2tYKuln3/fOZhw1ClcbSV1u0vcMf+KDup78ESPIhVewzLdarbP1giqGezV81Y7wkaS tpEg== X-Gm-Message-State: AOJu0YwtHjSIBAAWwX6Iv9GB0KjOGavnfHjXIN6eqLJgw7vGuiyO16EN Ij6S3HQJGGIEFXTjYAFayC8DVw== 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> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.12.4 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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-eng= ine.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 *pde= v) host->transfer_one_message =3D spi_engine_transfer_one_message; host->num_chipselect =3D 8; =20 + if (host->max_speed_hz =3D=3D 0) + return dev_err_probe(&pdev->dev, -EINVAL, "spi_clk rate is 0"); + ret =3D devm_spi_register_controller(&pdev->dev, host); if (ret) return ret; --=20 2.42.0 From nobody Tue Dec 30 07:41:41 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD105C54FB9 for ; Fri, 17 Nov 2023 20:14:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235773AbjKQUOY (ORCPT ); Fri, 17 Nov 2023 15:14:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346189AbjKQUOH (ORCPT ); Fri, 17 Nov 2023 15:14:07 -0500 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 5C51110EC for ; Fri, 17 Nov 2023 12:13:59 -0800 (PST) Received: by mail-oi1-x232.google.com with SMTP id 5614622812f47-3b2ec9a79bdso1596279b6e.3 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=BlLBkFOBGp0DAjYSXl9FsyR3Fjoz3Ip7ILJS+PSb7VC9h3nut+BsJzd70WlnlsoAY2 WjG1u2GJd7+bxAvQ3Jf0Ugd/NEUPTfHmBVaungMPe3YnkuGQpMRioNmq9Eh0jUSpzdAj aVx1K+zNFdLybRUMbuL7QTosq2qxX7rr8coMNfPeBbFGOabJYCTaDxvbY5RFvkb7auJz uV8KnJSU6LtwH3AE4fRN1aXmDHHQHwoHzvfM2CnkkUgSwSUDAe2tjj+grEY4SSXvBS46 m2I1PvW5i9krRINl5M4dAA0KzB28+fhTTW5kvwnxJ02z2cBPeIcFfIrbXmRWlwH69c2N 9KxA== X-Gm-Message-State: AOJu0YyPwnamvaLZyKeMucIwJmvkEL7ZuhyaSSTINAY0JdCvR2N5tETY +HiCMVO6zIk81bQkrhJovih+hQ== 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> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.12.4 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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-eng= ine.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 @@ */ =20 #include +#include #include #include #include @@ -78,28 +79,42 @@ struct spi_engine_program { uint16_t instructions[]; }; =20 -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; =20 - unsigned int sync_id; + spinlock_t lock; + + void __iomem *base; + + struct spi_message *msg; + struct ida sync_ida; unsigned int completed_id; =20 unsigned int int_enable; @@ -258,100 +273,105 @@ static void spi_engine_xfer_next(struct spi_engine = *spi_engine, =20 static void spi_engine_tx_next(struct spi_engine *spi_engine) { - struct spi_transfer *xfer =3D spi_engine->tx_xfer; + struct spi_engine_message_state *st =3D spi_engine->msg->state; + struct spi_transfer *xfer =3D st->tx_xfer; =20 do { spi_engine_xfer_next(spi_engine, &xfer); } while (xfer && !xfer->tx_buf); =20 - spi_engine->tx_xfer =3D xfer; + st->tx_xfer =3D xfer; if (xfer) { - spi_engine->tx_length =3D xfer->len; - spi_engine->tx_buf =3D xfer->tx_buf; + st->tx_length =3D xfer->len; + st->tx_buf =3D xfer->tx_buf; } else { - spi_engine->tx_buf =3D NULL; + st->tx_buf =3D NULL; } } =20 static void spi_engine_rx_next(struct spi_engine *spi_engine) { - struct spi_transfer *xfer =3D spi_engine->rx_xfer; + struct spi_engine_message_state *st =3D spi_engine->msg->state; + struct spi_transfer *xfer =3D st->rx_xfer; =20 do { spi_engine_xfer_next(spi_engine, &xfer); } while (xfer && !xfer->rx_buf); =20 - spi_engine->rx_xfer =3D xfer; + st->rx_xfer =3D xfer; if (xfer) { - spi_engine->rx_length =3D xfer->len; - spi_engine->rx_buf =3D xfer->rx_buf; + st->rx_length =3D xfer->len; + st->rx_buf =3D xfer->rx_buf; } else { - spi_engine->rx_buf =3D NULL; + st->rx_buf =3D NULL; } } =20 static bool spi_engine_write_cmd_fifo(struct spi_engine *spi_engine) { void __iomem *addr =3D spi_engine->base + SPI_ENGINE_REG_CMD_FIFO; + struct spi_engine_message_state *st =3D spi_engine->msg->state; unsigned int n, m, i; const uint16_t *buf; =20 n =3D readl_relaxed(spi_engine->base + SPI_ENGINE_REG_CMD_FIFO_ROOM); - while (n && spi_engine->cmd_length) { - m =3D min(n, spi_engine->cmd_length); - buf =3D spi_engine->cmd_buf; + while (n && st->cmd_length) { + m =3D min(n, st->cmd_length); + buf =3D st->cmd_buf; for (i =3D 0; i < m; i++) writel_relaxed(buf[i], addr); - spi_engine->cmd_buf +=3D m; - spi_engine->cmd_length -=3D m; + st->cmd_buf +=3D m; + st->cmd_length -=3D m; n -=3D m; } =20 - return spi_engine->cmd_length !=3D 0; + return st->cmd_length !=3D 0; } =20 static bool spi_engine_write_tx_fifo(struct spi_engine *spi_engine) { void __iomem *addr =3D spi_engine->base + SPI_ENGINE_REG_SDO_DATA_FIFO; + struct spi_engine_message_state *st =3D spi_engine->msg->state; unsigned int n, m, i; const uint8_t *buf; =20 n =3D readl_relaxed(spi_engine->base + SPI_ENGINE_REG_SDO_FIFO_ROOM); - while (n && spi_engine->tx_length) { - m =3D min(n, spi_engine->tx_length); - buf =3D spi_engine->tx_buf; + while (n && st->tx_length) { + m =3D min(n, st->tx_length); + buf =3D st->tx_buf; for (i =3D 0; i < m; i++) writel_relaxed(buf[i], addr); - spi_engine->tx_buf +=3D m; - spi_engine->tx_length -=3D m; + st->tx_buf +=3D m; + st->tx_length -=3D m; n -=3D m; - if (spi_engine->tx_length =3D=3D 0) + if (st->tx_length =3D=3D 0) spi_engine_tx_next(spi_engine); } =20 - return spi_engine->tx_length !=3D 0; + return st->tx_length !=3D 0; } =20 static bool spi_engine_read_rx_fifo(struct spi_engine *spi_engine) { void __iomem *addr =3D spi_engine->base + SPI_ENGINE_REG_SDI_DATA_FIFO; + struct spi_engine_message_state *st =3D spi_engine->msg->state; unsigned int n, m, i; uint8_t *buf; =20 n =3D readl_relaxed(spi_engine->base + SPI_ENGINE_REG_SDI_FIFO_LEVEL); - while (n && spi_engine->rx_length) { - m =3D min(n, spi_engine->rx_length); - buf =3D spi_engine->rx_buf; + while (n && st->rx_length) { + m =3D min(n, st->rx_length); + buf =3D st->rx_buf; for (i =3D 0; i < m; i++) buf[i] =3D readl_relaxed(addr); - spi_engine->rx_buf +=3D m; - spi_engine->rx_length -=3D m; + st->rx_buf +=3D m; + st->rx_length -=3D m; n -=3D m; - if (spi_engine->rx_length =3D=3D 0) + if (st->rx_length =3D=3D 0) spi_engine_rx_next(spi_engine); } =20 - return spi_engine->rx_length !=3D 0; + return st->rx_length !=3D 0; } =20 static irqreturn_t spi_engine_irq(int irq, void *devid) @@ -387,12 +407,16 @@ static irqreturn_t spi_engine_irq(int irq, void *devi= d) disable_int |=3D SPI_ENGINE_INT_SDI_ALMOST_FULL; } =20 - if (pending & SPI_ENGINE_INT_SYNC) { - if (spi_engine->msg && - spi_engine->completed_id =3D=3D spi_engine->sync_id) { + if (pending & SPI_ENGINE_INT_SYNC && spi_engine->msg) { + struct spi_engine_message_state *st =3D spi_engine->msg->state; + + if (spi_engine->completed_id =3D=3D st->sync_id) { struct spi_message *msg =3D spi_engine->msg; + struct spi_engine_message_state *st =3D msg->state; =20 - kfree(spi_engine->p); + ida_free(&spi_engine->sync_ida, st->sync_id); + kfree(st->p); + kfree(st); msg->status =3D 0; msg->actual_length =3D msg->frame_length; spi_engine->msg =3D 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 =3D spi_controller_get_devdata(host); + struct spi_engine_message_state *st; unsigned int int_enable =3D 0; unsigned long flags; size_t size; + int ret; + + st =3D kzalloc(sizeof(*st), GFP_KERNEL); + if (!st) + return -ENOMEM; =20 p_dry.length =3D 0; spi_engine_compile_message(spi_engine, msg, true, &p_dry); =20 size =3D sizeof(*p->instructions) * (p_dry.length + 1); p =3D kzalloc(sizeof(*p) + size, GFP_KERNEL); - if (!p) + if (!p) { + kfree(st); return -ENOMEM; + } + + ret =3D ida_alloc_range(&spi_engine->sync_ida, 0, U8_MAX, GFP_KERNEL); + if (ret < 0) { + kfree(p); + kfree(st); + return ret; + } + + st->sync_id =3D ret; + spi_engine_compile_message(spi_engine, msg, false, p); =20 spin_lock_irqsave(&spi_engine->lock, flags); - spi_engine->sync_id =3D (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)); =20 + msg->state =3D st; spi_engine->msg =3D msg; - spi_engine->p =3D p; + st->p =3D p; =20 - spi_engine->cmd_buf =3D p->instructions; - spi_engine->cmd_length =3D p->length; + st->cmd_buf =3D p->instructions; + st->cmd_length =3D p->length; if (spi_engine_write_cmd_fifo(spi_engine)) int_enable |=3D SPI_ENGINE_INT_CMD_ALMOST_EMPTY; =20 @@ -448,7 +489,7 @@ static int spi_engine_transfer_one_message(struct spi_c= ontroller *host, int_enable |=3D SPI_ENGINE_INT_SDO_ALMOST_EMPTY; =20 spi_engine_rx_next(spi_engine); - if (spi_engine->rx_length !=3D 0) + if (st->rx_length !=3D 0) int_enable |=3D SPI_ENGINE_INT_SDI_ALMOST_FULL; =20 int_enable |=3D SPI_ENGINE_INT_SYNC; @@ -489,6 +530,7 @@ static int spi_engine_probe(struct platform_device *pde= v) spi_engine =3D spi_controller_get_devdata(host); =20 spin_lock_init(&spi_engine->lock); + ida_init(&spi_engine->sync_ida); =20 spi_engine->clk =3D devm_clk_get_enabled(&pdev->dev, "s_axi_aclk"); if (IS_ERR(spi_engine->clk)) --=20 2.42.0 From nobody Tue Dec 30 07:41:41 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB125C5AD4C for ; Fri, 17 Nov 2023 20:14:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346216AbjKQUO0 (ORCPT ); Fri, 17 Nov 2023 15:14:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346191AbjKQUOH (ORCPT ); Fri, 17 Nov 2023 15:14:07 -0500 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 1EF4CD6D for ; Fri, 17 Nov 2023 12:14:00 -0800 (PST) Received: by mail-oi1-x231.google.com with SMTP id 5614622812f47-3b2df2fb611so1609925b6e.0 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=JP17il+EYXhoeJu0VVZ4wg9tmjMusmvcWFAE3s1hlevm0mGRUv313CyMP0345wQ30m vNniMq3R+s4gztVFEc2FIqnTptdBJgem8mFBUFuYbP+QaQcyrZaP+B+7qiiYslpMOSa5 he5zT6ocvFupb/YIbJL8LT2k1xQX4ef2Sm7nNAkUi2ALSZ7uSr+3z1Ihlg6aM4/6pMcG sBU/t3J08566ai49FTgNeXTDFjulhe9l3wtsbC+LfU4a4fMMuhssIirLTfEUOjsr3/GE 8cCWepSmpdCgr82Uk6TwjOnKbp0ROhYSuD5iXVkLnPPw2mdFpAhXUB2V5tv911c1wg/j HSJw== X-Gm-Message-State: AOJu0Yx4BvANI0hxc7G2Cw/HQnXQAteodupnr5o54gg9zxceeInk+ifm Lt05/9bYHSJri8n/ABitdkdgbw== 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> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.12.4 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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-eng= ine.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) =20 if (spi_engine->completed_id =3D=3D st->sync_id) { struct spi_message *msg =3D spi_engine->msg; - struct spi_engine_message_state *st =3D msg->state; =20 - ida_free(&spi_engine->sync_ida, st->sync_id); - kfree(st->p); - kfree(st); msg->status =3D 0; msg->actual_length =3D msg->frame_length; spi_engine->msg =3D NULL; @@ -436,14 +432,12 @@ static irqreturn_t spi_engine_irq(int irq, void *devi= d) return IRQ_HANDLED; } =20 -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 =3D spi_controller_get_devdata(host); struct spi_engine_message_state *st; - unsigned int int_enable =3D 0; - unsigned long flags; size_t size; int ret; =20 @@ -472,15 +466,41 @@ static int spi_engine_transfer_one_message(struct spi= _controller *host, =20 spi_engine_compile_message(spi_engine, msg, false, p); =20 - spin_lock_irqsave(&spi_engine->lock, flags); spi_engine_program_add_cmd(p, false, SPI_ENGINE_CMD_SYNC(st->sync_id)); =20 - msg->state =3D st; - spi_engine->msg =3D msg; st->p =3D p; - st->cmd_buf =3D p->instructions; st->cmd_length =3D p->length; + msg->state =3D st; + + return 0; +} + +static int spi_engine_unprepare_message(struct spi_controller *host, + struct spi_message *msg) +{ + struct spi_engine *spi_engine =3D spi_controller_get_devdata(host); + struct spi_engine_message_state *st =3D 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 =3D spi_controller_get_devdata(host); + struct spi_engine_message_state *st =3D msg->state; + unsigned int int_enable =3D 0; + unsigned long flags; + + spin_lock_irqsave(&spi_engine->lock, flags); + + spi_engine->msg =3D msg; + if (spi_engine_write_cmd_fifo(spi_engine)) int_enable |=3D SPI_ENGINE_INT_CMD_ALMOST_EMPTY; =20 @@ -572,6 +592,8 @@ static int spi_engine_probe(struct platform_device *pde= v) host->bits_per_word_mask =3D SPI_BPW_MASK(8); host->max_speed_hz =3D clk_get_rate(spi_engine->ref_clk) / 2; host->transfer_one_message =3D spi_engine_transfer_one_message; + host->prepare_message =3D spi_engine_prepare_message; + host->unprepare_message =3D spi_engine_unprepare_message; host->num_chipselect =3D 8; =20 if (host->max_speed_hz =3D=3D 0) --=20 2.42.0 From nobody Tue Dec 30 07:41:41 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B437C54FB9 for ; Fri, 17 Nov 2023 20:14:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346262AbjKQUO2 (ORCPT ); Fri, 17 Nov 2023 15:14:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346223AbjKQUOT (ORCPT ); Fri, 17 Nov 2023 15:14:19 -0500 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 287741727 for ; Fri, 17 Nov 2023 12:14:01 -0800 (PST) Received: by mail-oi1-x232.google.com with SMTP id 5614622812f47-3b3e13fc1f7so1496423b6e.0 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=ZcRZauHhZnv0YG7kgj1NmOlxJ8hcYkOkChCqnwmTYLOwWtXqxXyGyRcDEZJJTocvzh 8K13W7qgKVIPjmoEr5xOuIkic9C9uCVymsJFh8BJPeA/E3JLLkjNP0ggwZUL4JjGuFET NVhCapDQ750LzST/rHlA2NI3w7DL7gnmsVShZ5ffCc2G8iCixwmR9A/c8H8KkYjZO+KX U51ByHyG/2tJFrktyX4KoDPMYvHU9/lQ743qsC6ntn6Ma4+rXNZO3iwl0D42yE3D0CL2 FpswF8uhTj4eOnOM5L+d806MJtJ3jbkCtDZN9o19e9KEAO8EXBSnFy46D57NpP2rZJw1 n37Q== X-Gm-Message-State: AOJu0YyMJ6oe7OjcUqwu840bZ4xEcWjjJQDhBoAmkcnomFGZaCvxws2M L01uxjbs1kqvIOE+a/sUu39X4w== 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> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.12.4 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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-eng= ine.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 { =20 struct spi_message *msg; struct ida sync_ida; - unsigned int completed_id; =20 unsigned int int_enable; }; @@ -380,13 +379,14 @@ static irqreturn_t spi_engine_irq(int irq, void *devi= d) struct spi_engine *spi_engine =3D spi_controller_get_devdata(host); unsigned int disable_int =3D 0; unsigned int pending; + int completed_id =3D -1; =20 pending =3D readl_relaxed(spi_engine->base + SPI_ENGINE_REG_INT_PENDING); =20 if (pending & SPI_ENGINE_INT_SYNC) { writel_relaxed(SPI_ENGINE_INT_SYNC, spi_engine->base + SPI_ENGINE_REG_INT_PENDING); - spi_engine->completed_id =3D readl_relaxed( + completed_id =3D readl_relaxed( spi_engine->base + SPI_ENGINE_REG_SYNC_ID); } =20 @@ -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 =3D spi_engine->msg->state; =20 - if (spi_engine->completed_id =3D=3D st->sync_id) { + if (completed_id =3D=3D st->sync_id) { struct spi_message *msg =3D spi_engine->msg; =20 msg->status =3D 0; --=20 2.42.0 From nobody Tue Dec 30 07:41:41 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 648E5C072A2 for ; Fri, 17 Nov 2023 20:14:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346266AbjKQUOb (ORCPT ); Fri, 17 Nov 2023 15:14:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346235AbjKQUOU (ORCPT ); Fri, 17 Nov 2023 15:14:20 -0500 Received: from mail-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E53211732 for ; Fri, 17 Nov 2023 12:14:01 -0800 (PST) Received: by mail-oi1-x236.google.com with SMTP id 5614622812f47-3b56b618217so1447177b6e.0 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=JjhX9y79BE83wJtZLBDOJAGQqP1eI8nm262J4Jn0fgdJ6g5IrKIFycFbq0OP8OgVAX OLtS2OVXNRow4vtQI4FqdslYCE+Vk0EBAEP9X7iia7GTSjN/nq+G6OndppYq2PtCBTrV yevJgcfGyMjEcsECDWJ8UG4QF86NXfRzDPgHuy/a59eCLVLP3DyXOVRMBg76Ly3LXm7L vtnurSUChd5+AnTxZ2cBOkjYZooVL2zJ5+Qzq3tS9dcCSUEdM212Cmx65t8Rr6gJ9pCv KY+AqBMi14H5qV1n7CLdnw9vWBDCPI5G3gwl1qEXpMkscQA4Z1BlMk2AXDuJhwxRLmlJ 5mXw== X-Gm-Message-State: AOJu0Yxfntfp6ptOMFdkI+ybLk7oxBMVLquN8+taTseWJ6yjwXoJ45KZ UgcWB04NovuZpnsEyFzm59h5jg== 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> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.12.4 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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-eng= ine.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; =20 void __iomem *base; - - struct spi_message *msg; struct ida sync_ida; =20 unsigned int int_enable; @@ -252,10 +250,9 @@ static int spi_engine_compile_message(struct spi_engin= e *spi_engine, return 0; } =20 -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 =3D spi_engine->msg; struct spi_transfer *xfer =3D *_xfer; =20 if (!xfer) { @@ -270,13 +267,13 @@ static void spi_engine_xfer_next(struct spi_engine *s= pi_engine, *_xfer =3D xfer; } =20 -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 =3D spi_engine->msg->state; + struct spi_engine_message_state *st =3D msg->state; struct spi_transfer *xfer =3D st->tx_xfer; =20 do { - spi_engine_xfer_next(spi_engine, &xfer); + spi_engine_xfer_next(msg, &xfer); } while (xfer && !xfer->tx_buf); =20 st->tx_xfer =3D xfer; @@ -288,13 +285,13 @@ static void spi_engine_tx_next(struct spi_engine *spi= _engine) } } =20 -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 =3D spi_engine->msg->state; + struct spi_engine_message_state *st =3D msg->state; struct spi_transfer *xfer =3D st->rx_xfer; =20 do { - spi_engine_xfer_next(spi_engine, &xfer); + spi_engine_xfer_next(msg, &xfer); } while (xfer && !xfer->rx_buf); =20 st->rx_xfer =3D xfer; @@ -306,10 +303,11 @@ static void spi_engine_rx_next(struct spi_engine *spi= _engine) } } =20 -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 =3D spi_engine->base + SPI_ENGINE_REG_CMD_FIFO; - struct spi_engine_message_state *st =3D spi_engine->msg->state; + struct spi_engine_message_state *st =3D msg->state; unsigned int n, m, i; const uint16_t *buf; =20 @@ -327,10 +325,11 @@ static bool spi_engine_write_cmd_fifo(struct spi_engi= ne *spi_engine) return st->cmd_length !=3D 0; } =20 -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 =3D spi_engine->base + SPI_ENGINE_REG_SDO_DATA_FIFO; - struct spi_engine_message_state *st =3D spi_engine->msg->state; + struct spi_engine_message_state *st =3D msg->state; unsigned int n, m, i; const uint8_t *buf; =20 @@ -344,16 +343,17 @@ static bool spi_engine_write_tx_fifo(struct spi_engin= e *spi_engine) st->tx_length -=3D m; n -=3D m; if (st->tx_length =3D=3D 0) - spi_engine_tx_next(spi_engine); + spi_engine_tx_next(msg); } =20 return st->tx_length !=3D 0; } =20 -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 =3D spi_engine->base + SPI_ENGINE_REG_SDI_DATA_FIFO; - struct spi_engine_message_state *st =3D spi_engine->msg->state; + struct spi_engine_message_state *st =3D msg->state; unsigned int n, m, i; uint8_t *buf; =20 @@ -367,7 +367,7 @@ static bool spi_engine_read_rx_fifo(struct spi_engine *= spi_engine) st->rx_length -=3D m; n -=3D m; if (st->rx_length =3D=3D 0) - spi_engine_rx_next(spi_engine); + spi_engine_rx_next(msg); } =20 return st->rx_length !=3D 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 =3D devid; + struct spi_message *msg =3D host->cur_msg; struct spi_engine *spi_engine =3D spi_controller_get_devdata(host); unsigned int disable_int =3D 0; unsigned int pending; @@ -393,29 +394,26 @@ static irqreturn_t spi_engine_irq(int irq, void *devi= d) spin_lock(&spi_engine->lock); =20 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 |=3D SPI_ENGINE_INT_CMD_ALMOST_EMPTY; } =20 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 |=3D SPI_ENGINE_INT_SDO_ALMOST_EMPTY; } =20 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 |=3D SPI_ENGINE_INT_SDI_ALMOST_FULL; } =20 - if (pending & SPI_ENGINE_INT_SYNC && spi_engine->msg) { - struct spi_engine_message_state *st =3D spi_engine->msg->state; + if (pending & SPI_ENGINE_INT_SYNC && msg) { + struct spi_engine_message_state *st =3D msg->state; =20 if (completed_id =3D=3D st->sync_id) { - struct spi_message *msg =3D spi_engine->msg; - msg->status =3D 0; msg->actual_length =3D msg->frame_length; - spi_engine->msg =3D NULL; spi_finalize_current_message(host); disable_int |=3D SPI_ENGINE_INT_SYNC; } @@ -499,16 +497,14 @@ static int spi_engine_transfer_one_message(struct spi= _controller *host, =20 spin_lock_irqsave(&spi_engine->lock, flags); =20 - spi_engine->msg =3D msg; - - if (spi_engine_write_cmd_fifo(spi_engine)) + if (spi_engine_write_cmd_fifo(spi_engine, msg)) int_enable |=3D SPI_ENGINE_INT_CMD_ALMOST_EMPTY; =20 - 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 |=3D SPI_ENGINE_INT_SDO_ALMOST_EMPTY; =20 - spi_engine_rx_next(spi_engine); + spi_engine_rx_next(msg); if (st->rx_length !=3D 0) int_enable |=3D SPI_ENGINE_INT_SDI_ALMOST_FULL; =20 --=20 2.42.0 From nobody Tue Dec 30 07:41:41 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E69F6C5ACB3 for ; Fri, 17 Nov 2023 20:14:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346271AbjKQUOe (ORCPT ); Fri, 17 Nov 2023 15:14:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346184AbjKQUOU (ORCPT ); Fri, 17 Nov 2023 15:14:20 -0500 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 1B389173B for ; Fri, 17 Nov 2023 12:14:02 -0800 (PST) Received: by mail-oi1-x231.google.com with SMTP id 5614622812f47-3b2e44c7941so1438968b6e.2 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=c2cyiDK3FrwU/CxZAUG+ek91o3YE5CogrRsO2T7gijW9zZgyxLLFl7jXhd4QPRjka0 zNzUeBo/kOfjnlZZJTaqI5W7qAVp0cZPak41oO/H797YonqUsDg+iPWCtziqd3CE38iQ hD5TLl+EIlNVc2BanP8Xm9sNK/JARdGdRqWCHAJE8ROQC46P32Bk/4S4mlTP0CK2Sv8X PNOcG+/u6mxJr1M6Xq4qsUF4sL8vjxEjh8c1IHZ6+YQBYnvGMyPjMAiOudeAzTfgaxvA HUNkDQ3PcoqDpM+61p9Ehz5Wymf1+uAGyZUbqJH9sfgNBYqHd0VPDnDQpjtwsgRyRNbv QaXw== X-Gm-Message-State: AOJu0Yz7HldkT96Uw1DOqbF67WnB8CqKVGe87TzB3OYtpAC6IJFUVY5J kn+MCxQrGpSfncMzpP9HumkEvw== 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> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.12.4 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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-eng= ine.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 =3D msg->spi; struct spi_transfer *xfer; int clk_div, new_clk_div; - bool cs_change =3D true; + bool keep_cs =3D false; =20 clk_div =3D -1; =20 @@ -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))); =20 + xfer =3D 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 =3D spi_engine_get_clk_div(spi_engine, spi, xfer); if (new_clk_div !=3D clk_div) { @@ -233,20 +236,28 @@ static int spi_engine_compile_message(struct spi_engi= ne *spi_engine, clk_div)); } =20 - 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); =20 - cs_change =3D xfer->cs_change; - if (list_is_last(&xfer->transfer_list, &msg->transfers)) - cs_change =3D !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 =3D 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 !=3D list_next_entry(xfer, transfer_list)->cs_off) { + spi_engine_gen_cs(p, dry, spi, xfer->cs_off); + } } =20 + if (!keep_cs) + spi_engine_gen_cs(p, dry, spi, false); + return 0; } =20 --=20 2.42.0 From nobody Tue Dec 30 07:41:41 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7BACAC54FB9 for ; Fri, 17 Nov 2023 20:14:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346274AbjKQUOg (ORCPT ); Fri, 17 Nov 2023 15:14:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235757AbjKQUOV (ORCPT ); Fri, 17 Nov 2023 15:14:21 -0500 Received: from mail-oi1-x22b.google.com (mail-oi1-x22b.google.com [IPv6:2607:f8b0:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A10181987 for ; Fri, 17 Nov 2023 12:14:03 -0800 (PST) Received: by mail-oi1-x22b.google.com with SMTP id 5614622812f47-3b3f938331fso1145617b6e.1 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=LGOLfjSmUafwLOwQF9M9cDlPIGQx+Ws85gj9VKDaT4RWb7cnF3q794C4tJ7NkERRMX i93zePGCQKaefjMvAihJi7SPmTBqbaHDT+y48opOYZy/cAzJ54m1UB8BJVRJEFydEGdf hSCVijfhOdCW3BY5gkXxlzi+DwvuOyHdv0ZTs8KQ8EBmMXWMq5QT6/gOS4zLt6FNmga5 GzQpNaVvKiNHUKM8MBvwmiGPEilHh/37LgKceMAJGPFNa5E8x0ZBvzfXYT0aQN1to8vl uzmoF7AqoY5fEn6jUCFYAPTbAQ17nWX7IYe/1qhhrH/GgOrzUA46YgmEjqMV9oXrAs96 Wnsw== X-Gm-Message-State: AOJu0Yw5WhMQgPkkoeU/FZjGQeE7ZOERnf4BzmwIiEarGJnmKR0T2G5x humhiU07KvadHHkZjyvzjo/3sg== 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> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.12.4 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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-eng= ine.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 @@ =20 #define SPI_ENGINE_CMD_REG_CLK_DIV 0x0 #define SPI_ENGINE_CMD_REG_CONFIG 0x1 +#define SPI_ENGINE_CMD_REG_XFER_BITS 0x2 =20 #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 =3D xfer->len; + unsigned int len; + + if (xfer->bits_per_word <=3D 8) + len =3D xfer->len; + else if (xfer->bits_per_word <=3D 16) + len =3D xfer->len / 2; + else + len =3D xfer->len / 4; =20 while (len) { unsigned int n =3D 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 =3D false; + u8 bits_per_word =3D 0; =20 clk_div =3D -1; =20 @@ -236,6 +245,13 @@ static int spi_engine_compile_message(struct spi_engin= e *spi_engine, clk_div)); } =20 + if (bits_per_word !=3D xfer->bits_per_word) { + bits_per_word =3D 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); =20 @@ -342,16 +358,34 @@ static bool spi_engine_write_tx_fifo(struct spi_engin= e *spi_engine, void __iomem *addr =3D spi_engine->base + SPI_ENGINE_REG_SDO_DATA_FIFO; struct spi_engine_message_state *st =3D msg->state; unsigned int n, m, i; - const uint8_t *buf; =20 n =3D readl_relaxed(spi_engine->base + SPI_ENGINE_REG_SDO_FIFO_ROOM); while (n && st->tx_length) { - m =3D min(n, st->tx_length); - buf =3D st->tx_buf; - for (i =3D 0; i < m; i++) - writel_relaxed(buf[i], addr); - st->tx_buf +=3D m; - st->tx_length -=3D m; + if (st->tx_xfer->bits_per_word <=3D 8) { + const u8 *buf =3D st->tx_buf; + + m =3D min(n, st->tx_length); + for (i =3D 0; i < m; i++) + writel_relaxed(buf[i], addr); + st->tx_buf +=3D m; + st->tx_length -=3D m; + } else if (st->tx_xfer->bits_per_word <=3D 16) { + const u16 *buf =3D (const u16 *)st->tx_buf; + + m =3D min(n, st->tx_length / 2); + for (i =3D 0; i < m; i++) + writel_relaxed(buf[i], addr); + st->tx_buf +=3D m * 2; + st->tx_length -=3D m * 2; + } else { + const u32 *buf =3D (const u32 *)st->tx_buf; + + m =3D min(n, st->tx_length / 4); + for (i =3D 0; i < m; i++) + writel_relaxed(buf[i], addr); + st->tx_buf +=3D m * 4; + st->tx_length -=3D m * 4; + } n -=3D m; if (st->tx_length =3D=3D 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 =3D spi_engine->base + SPI_ENGINE_REG_SDI_DATA_FIFO; struct spi_engine_message_state *st =3D msg->state; unsigned int n, m, i; - uint8_t *buf; =20 n =3D readl_relaxed(spi_engine->base + SPI_ENGINE_REG_SDI_FIFO_LEVEL); while (n && st->rx_length) { - m =3D min(n, st->rx_length); - buf =3D st->rx_buf; - for (i =3D 0; i < m; i++) - buf[i] =3D readl_relaxed(addr); - st->rx_buf +=3D m; - st->rx_length -=3D m; + if (st->rx_xfer->bits_per_word <=3D 8) { + u8 *buf =3D st->rx_buf; + + m =3D min(n, st->rx_length); + for (i =3D 0; i < m; i++) + buf[i] =3D readl_relaxed(addr); + st->rx_buf +=3D m; + st->rx_length -=3D m; + } else if (st->rx_xfer->bits_per_word <=3D 16) { + u16 *buf =3D (u16 *)st->rx_buf; + + m =3D min(n, st->rx_length / 2); + for (i =3D 0; i < m; i++) + buf[i] =3D readl_relaxed(addr); + st->rx_buf +=3D m * 2; + st->rx_length -=3D m * 2; + } else { + u32 *buf =3D (u32 *)st->rx_buf; + + m =3D min(n, st->rx_length / 4); + for (i =3D 0; i < m; i++) + buf[i] =3D readl_relaxed(addr); + st->rx_buf +=3D m * 4; + st->rx_length -=3D m * 4; + } n -=3D m; if (st->rx_length =3D=3D 0) spi_engine_rx_next(msg); @@ -596,7 +648,7 @@ static int spi_engine_probe(struct platform_device *pde= v) =20 host->dev.of_node =3D pdev->dev.of_node; host->mode_bits =3D SPI_CPOL | SPI_CPHA | SPI_3WIRE; - host->bits_per_word_mask =3D SPI_BPW_MASK(8); + host->bits_per_word_mask =3D SPI_BPW_RANGE_MASK(1, 32); host->max_speed_hz =3D clk_get_rate(spi_engine->ref_clk) / 2; host->transfer_one_message =3D spi_engine_transfer_one_message; host->prepare_message =3D spi_engine_prepare_message; --=20 2.42.0