From patchwork Mon Feb 24 10:12:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Longbin Li X-Patchwork-Id: 13987763 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2C30EC021A4 for ; Mon, 24 Feb 2025 10:22:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=R84bui6NoD0Ofwl5PQRV1Q3V4YlVx02a0VIUHseIx0E=; b=qKd6ksj+3tqClf uGJ+goWZb6fq83242O/QyOLt/E5vQWnHybhA0x66x8IJ48uyGIx3CgT4D/6P4XuaGXtdZYxyS/Ysu wFC1cLHIUp85gTxXRxlq/qiqyUgi9Pqole5Lu1M4/LpsTr7fnRc/98c+4Z32t+GqylrcUP4B1oIfq 8UwKIdUSWAAjbsw4OZQSMMx0ykmofnUdVTgQpB0d6XOQb2TnYIeGBZZuNWZ0RS2VmPFxKhI5ul9i4 2nGWstP8H5ZwiIXy8HQN60TOT2HgtY1UrcVJY/rH76SmyW/d1uz3+cv9dK5G1UuPKtM7TKbsA0/4d EQ7/9BtkrbD7PUEsUvmQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tmVbS-0000000D6TF-3vMu; Mon, 24 Feb 2025 10:22:22 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tmVSL-0000000D4Xg-3NII for linux-riscv@lists.infradead.org; Mon, 24 Feb 2025 10:12:59 +0000 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-220d28c215eso62106885ad.1 for ; Mon, 24 Feb 2025 02:12:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740391977; x=1740996777; darn=lists.infradead.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=tfgdDU3dHCgHvLuyG46NLXGA1z+1QvVU4idXkiLTeYg=; b=DCwKIyX//xr8iK2qghZM7db/mqVGkO0qxUSEXhTmd3JyjfxcCkKakWQQJWDTg8mD24 +ArGrvHohWa1cp61458HoNoMTl18hZoOQe+f/5sAq8+237/u6rMftfRq6fDRqPuQ3537 m4leYrdpLCAadsy2ipO3abr0K+iOxtwqLrM7vVLWbqzH18CzxYmFAUiCBIDhYWU/Bzuk ERfBl+URT8M2YbHvnj9Y2jbiErHddjriSrGQoHAgN9ehd6/p9KpiKZn71syO4dlSMakP 95t2Azo8VvQJiGv1sihovX+Kw0/2frk1Kn72xFHjrfYpM85wNsT+tyH/D8VMC6xUNCTs eTCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740391977; x=1740996777; 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=tfgdDU3dHCgHvLuyG46NLXGA1z+1QvVU4idXkiLTeYg=; b=L3fhYC4mn2owCfeYh3KnBBkRWeHpS8+vnLS6n5Jn9/xAWoItRYaFJI53SJXYcsQywv XS0ilSHtrjqxtbt/okPZWSkRA2i655oYqNgQN1ay9HrUhuADgPz2WxbuKMN38vqkIQvN 5JRCq76QWOK9vAGkcyy/UQKsKJcdZXWA/HOn8S4OvMbZw8GQX76Kw9PsF+VNkh63Mqlc vzBx1gAk5mNffT1mLoQiUM2dtrHlqj04NJhOqFQ4PWFirpOKYfOJVCwFTv49ynQJkEDR GQ9wk3A2N4RzbXODSY1sVELP5DnfNmArUrf2tA/WeKwDL7uwxfm6vwHyLtjtvC0RkBVu WXeg== X-Forwarded-Encrypted: i=1; AJvYcCW1vddOQfxRiKk59f1AK2bO4q/fgHDNYi1QzXN1L1FOXwbVNPJK0yoEAkbtAK6RmPSkKSkgIjnaVD1Jgw==@lists.infradead.org X-Gm-Message-State: AOJu0YzaJ3HW81owK0q+Kb8Mkqh7wdI3TJbW+XXMrQiuvIsQ+yPjfR4Q ectvyPlGXEdv54CmTooFseoRDWZBrpEsLnYJmH0S0LdIj3QVkZNu X-Gm-Gg: ASbGncuA9DX8P9b/CE4l3rH8lQghOGD56L+7dwsDL0yK01wJAI9mShLlD9EVGaKXGAI MN2MtA1Z3AwxlCDgEvNSqQUgfFo68VGTRD4wI9OdDSJ7Nws5SXCcoh0xtqD+dKpK+A1sU3n6uiY UyAYqAeT56XLyt/1RssG828uTq0U8ug7r52oKNAgxRIuZZsfxRmE93IyEIJ+cOk6BUhVzC9OI45 8C7+/cpyLJKgyK3DtIhqIbni2SibbtbDdDQR9i5N81q8/lBGe6t+NxQUE8WTHaBokzpCwUPjqni zev/WMvDxib18oiYBZ98 X-Google-Smtp-Source: AGHT+IF04L64yddkAFq03o8LvF25Xq5MWdPj2nGFRbtcPd0hUWOcQ6Di7Lct9JFSZGV4Unfn5iL97Q== X-Received: by 2002:a17:902:fc4e:b0:21f:7964:e989 with SMTP id d9443c01a7336-2219fffb650mr207806035ad.52.1740391977163; Mon, 24 Feb 2025 02:12:57 -0800 (PST) Received: from cu.. ([2001:19f0:ac00:4eb8:5400:5ff:fe30:7df3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d7a464f1sm173274365ad.206.2025.02.24.02.12.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2025 02:12:56 -0800 (PST) From: Longbin Li To: Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen Wang , Inochi Amaoto , Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: Longbin Li , linux-spi@vger.kernel.org, devicetree@vger.kernel.org, sophgo@lists.linux.dev, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH 1/3] dt-bindings: spi: add Sophgo SPI NOR controller driver Date: Mon, 24 Feb 2025 18:12:00 +0800 Message-ID: <20250224101213.26003-2-looong.bin@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250224101213.26003-1-looong.bin@gmail.com> References: <20250224101213.26003-1-looong.bin@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250224_021257_853116_B2047B9F X-CRM114-Status: GOOD ( 11.63 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Add SPI NOR driver for Sophgo, including read, write operations. Signed-off-by: Longbin Li Reviewed-by: Rob Herring (Arm) --- .../bindings/spi/spi-sophgo-nor.yaml | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Documentation/devicetree/bindings/spi/spi-sophgo-nor.yaml -- 2.48.1 diff --git a/Documentation/devicetree/bindings/spi/spi-sophgo-nor.yaml b/Documentation/devicetree/bindings/spi/spi-sophgo-nor.yaml new file mode 100644 index 000000000000..0b54946c649f --- /dev/null +++ b/Documentation/devicetree/bindings/spi/spi-sophgo-nor.yaml @@ -0,0 +1,52 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/spi/spi-sophgo-nor.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Sophgo SPI NOR controller + +maintainers: + - Longbin Li + +allOf: + - $ref: spi-controller.yaml# + +properties: + compatible: + const: sophgo,sg2044-spifmc-nor + + reg: + maxItems: 1 + + clocks: + maxItems: 1 + + interrupts: + maxItems: 1 + + resets: + maxItems: 1 + +required: + - compatible + - reg + - clocks + - interrupts + - resets + +unevaluatedProperties: false + +examples: + - | + #include + + spi@1000000 { + compatible = "sophgo,sg2044-spifmc-nor"; + reg = <0x1000000 0x4000000>; + #address-cells = <1>; + #size-cells = <0>; + clocks = <&clk 0>; + interrupts = <37 IRQ_TYPE_LEVEL_HIGH>; + resets = <&rst 0>; + }; From patchwork Mon Feb 24 10:12:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Longbin Li X-Patchwork-Id: 13987764 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 88A26C021B3 for ; Mon, 24 Feb 2025 10:22:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=OkP4idYGbvNixoTAKrg+qvFUiK1lbDWzH3ES1D8VGUk=; b=mtT1GJH9gKzV/w TlPLmhvzJL1NoKMdyQMaHmL0H1BOOHCl6NWgcYiuPHkoI2BZ8a2kLhR/cjw0j1077JoNrbcMY2nPm qWUjL5NhI83JLWum6yEJkwjxGghAuAUELc1POkWwh/UZyOfQ2k+qhXG2KKEPr/09RJ7DZXKzNXzBB LZzPFiOwvYWV0rpIhhml3+HFYJrIRojn/277QO9ssJ2k12LUVzLzkkm1MYNG5SS7uNm158nkjtSTp SamZ2u2hF+gl89AwK09M96JhUT1+7w1LfWiwA9F6hkb/fd4pQgYU/MiUDH57M7LTsuSSqtjTl/rnw G0JDx8VBCPzypalseIrw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tmVbT-0000000D6TO-2MIm; Mon, 24 Feb 2025 10:22:23 +0000 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tmVSS-0000000D4Yr-2iQH for linux-riscv@lists.infradead.org; Mon, 24 Feb 2025 10:13:05 +0000 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-220c92c857aso70402435ad.0 for ; Mon, 24 Feb 2025 02:13:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740391984; x=1740996784; darn=lists.infradead.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=i9K1JqtTmWf8xTIkMB47iCGqHODGTaRdIkV2ZLfyu+I=; b=BMmOPTLawz1w6G3gHs1HqRk6/0rG+eX57VUHu6Mttwb8X8ss3KZ9zKR6N9jAmUKAHx romNZG0uA+6KkVVs3A9Ayang3GttES2P9uXaH35H+Niy5HZR7lAF/lr8Hq9a56Xp0G+K gwXHyn6OErg57B42VMQyB9jd1M1WVTRR6gYPSFHMRSIAIYvSdGYN1XvPIVzrJK0O1jBY PUrqvzHGWlblogy6nK6A1bU/pPNz8tz/bTCyH4zETb6H6xsbtTK8mxdorB6Qhn8RFhzz vp7N3JK0wI1+jFAcXrSyuiJe5lArG9QZ1O2vWhuih42iQ4WEORDqWG5pB6+0IL2FAeSp ZtLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740391984; x=1740996784; 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=i9K1JqtTmWf8xTIkMB47iCGqHODGTaRdIkV2ZLfyu+I=; b=OrtejHIvJrCKnU+GHhNksDnLKXtDNcHHQzLzJzgrxjwp1XHvj/UEPbFFZwdIRFYq2q IRmFPnR4jOBKRxEMMQkDDgr6VV34LIrZIbG9ka5ZvaE4hyy9PWNqsn9vQ1lWSmt36kzM 33ZdTdCKh9uQvhPHlF5JU9j5vQ/1j1XBC2bjaxQ/FsNokJ/mplA6LEvTnQ9HQVgE0yI5 /42jvpLk4DD4cwJfvpDS74qvCwHfx0ufLA7tEdaiPhFnwyPvwKkI6w1rt0yhDqBSI7ro mp1WcpxlR/bQYKwBp2gCrVMfU2eu8VtKbCjrMe6ao2sr6Iv9kqi0vcaVsE0WDlokhdZ/ hhhA== X-Forwarded-Encrypted: i=1; AJvYcCXEMQai0e1StlT98BkjzBFHSM8dkgPaF3lgF1jmzqijm8ulauIqYtw2HM13ZED5ehI8DQVExyi3kFegMg==@lists.infradead.org X-Gm-Message-State: AOJu0YwHc6H/oRuxSS0ArbIG9wtz353tjXhW95O4ZoTg5AYNrR9hq3oS RbA1oFFjC4c29trH79iYUPIjQ70bIHQoKITBplxVACgaYRHzQnBd X-Gm-Gg: ASbGncsC7qN888mcEplcqobqGqwCK47+3r96IHj2QKn5PuNq736o10Kp+D8/UYsKWP8 ciIEv/yd1KtC9lu7LnkGeT14uoO7IB+pMr9VXVxcHc40eKQmPmzpln5q24F9xEVTFHtRWOXY2kW k0N2s0CD/F8JSQR/sZmQ7JaeYP3yyh8hMdxZlr+2kS7oQqCBgsydbTf+U+EOPsuR4DtdmQUzDi3 ukYv54paBAtjWV3hdSEDCtDWnfnJW+gd13vryfu5JHtThap954OVeLiYYR8W/55x5BdW6MvMoEE llnOJykcgcDAo85z8A2U X-Google-Smtp-Source: AGHT+IHb1ImqlO2BqodvFSOU+dtSSudUpLUD3cK/AcFo/b9Ciwsf44zUCCMrsJc76r+i7ooTlRFeKQ== X-Received: by 2002:a17:903:2446:b0:215:58be:334e with SMTP id d9443c01a7336-2219ff89cafmr193548465ad.10.1740391983805; Mon, 24 Feb 2025 02:13:03 -0800 (PST) Received: from cu.. ([2001:19f0:ac00:4eb8:5400:5ff:fe30:7df3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d7a464f1sm173274365ad.206.2025.02.24.02.12.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2025 02:13:03 -0800 (PST) From: Longbin Li To: Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen Wang , Inochi Amaoto , Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: Longbin Li , linux-spi@vger.kernel.org, devicetree@vger.kernel.org, sophgo@lists.linux.dev, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH 2/3] spi: sophgo: add Sophgo SPI NOR controller driver Date: Mon, 24 Feb 2025 18:12:01 +0800 Message-ID: <20250224101213.26003-3-looong.bin@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250224101213.26003-1-looong.bin@gmail.com> References: <20250224101213.26003-1-looong.bin@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250224_021304_700282_B5D3B7B2 X-CRM114-Status: GOOD ( 21.36 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Add support for Sophgo SPI NOR controller in Sophgo SoC. Signed-off-by: Longbin Li --- drivers/spi/Kconfig | 9 + drivers/spi/Makefile | 1 + drivers/spi/spi-sophgo-nor.c | 501 +++++++++++++++++++++++++++++++++++ 3 files changed, 511 insertions(+) create mode 100644 drivers/spi/spi-sophgo-nor.c -- 2.48.1 diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig index ea8a31032927..6b6d7b348485 100644 --- a/drivers/spi/Kconfig +++ b/drivers/spi/Kconfig @@ -1021,6 +1021,15 @@ config SPI_SN_F_OSPI for connecting an SPI Flash memory over up to 8-bit wide bus. It supports indirect access mode only. +config SPI_SOPHGO_NOR + tristate "Sophgo SPI NOR Controller" + depends on ARCH_SOPHGO || COMPILE_TEST + help + This enables support for the Sophgo SPI NOR controller, + which supports Dual/Qual read and write operations while + also supporting 3Byte address devices and 4Byte address + devices. + config SPI_SPRD tristate "Spreadtrum SPI controller" depends on ARCH_SPRD || COMPILE_TEST diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile index 9db7554c1864..9ded1de4b2fd 100644 --- a/drivers/spi/Makefile +++ b/drivers/spi/Makefile @@ -134,6 +134,7 @@ obj-$(CONFIG_SPI_SH_SCI) += spi-sh-sci.o obj-$(CONFIG_SPI_SIFIVE) += spi-sifive.o obj-$(CONFIG_SPI_SLAVE_MT27XX) += spi-slave-mt27xx.o obj-$(CONFIG_SPI_SN_F_OSPI) += spi-sn-f-ospi.o +obj-$(CONFIG_SPI_SOPHGO_NOR) += spi-sophgo-nor.o obj-$(CONFIG_SPI_SPRD) += spi-sprd.o obj-$(CONFIG_SPI_SPRD_ADI) += spi-sprd-adi.o obj-$(CONFIG_SPI_STM32) += spi-stm32.o diff --git a/drivers/spi/spi-sophgo-nor.c b/drivers/spi/spi-sophgo-nor.c new file mode 100644 index 000000000000..1139deeac327 --- /dev/null +++ b/drivers/spi/spi-sophgo-nor.c @@ -0,0 +1,501 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Sophgo SPI NOR controller driver + * + * Copyright (c) 2025 Longbin Li + */ + +#include +#include +#include +#include +#include +#include +#include + +/* Hardware register definitions */ +#define SPIFMC_CTRL 0x00 +#define SPIFMC_CTRL_CPHA BIT(12) +#define SPIFMC_CTRL_CPOL BIT(13) +#define SPIFMC_CTRL_HOLD_OL BIT(14) +#define SPIFMC_CTRL_WP_OL BIT(15) +#define SPIFMC_CTRL_LSBF BIT(20) +#define SPIFMC_CTRL_SRST BIT(21) +#define SPIFMC_CTRL_SCK_DIV_SHIFT 0 +#define SPIFMC_CTRL_FRAME_LEN_SHIFT 16 +#define SPIFMC_CTRL_SCK_DIV_MASK 0x7FF + +#define SPIFMC_CE_CTRL 0x04 +#define SPIFMC_CE_CTRL_CEMANUAL BIT(0) +#define SPIFMC_CE_CTRL_CEMANUAL_EN BIT(1) + +#define SPIFMC_DLY_CTRL 0x08 +#define SPIFMC_CTRL_FM_INTVL_MASK 0x000f +#define SPIFMC_CTRL_FM_INTVL BIT(0) +#define SPIFMC_CTRL_CET_MASK 0x0f00 +#define SPIFMC_CTRL_CET BIT(8) + +#define SPIFMC_DMMR 0x0c + +#define SPIFMC_TRAN_CSR 0x10 +#define SPIFMC_TRAN_CSR_TRAN_MODE_MASK GENMASK(1, 0) +#define SPIFMC_TRAN_CSR_TRAN_MODE_RX BIT(0) +#define SPIFMC_TRAN_CSR_TRAN_MODE_TX BIT(1) +#define SPIFMC_TRAN_CSR_FAST_MODE BIT(3) +#define SPIFMC_TRAN_CSR_BUS_WIDTH_1_BIT (0x00 << 4) +#define SPIFMC_TRAN_CSR_BUS_WIDTH_2_BIT (0x01 << 4) +#define SPIFMC_TRAN_CSR_BUS_WIDTH_4_BIT (0x02 << 4) +#define SPIFMC_TRAN_CSR_DMA_EN BIT(6) +#define SPIFMC_TRAN_CSR_MISO_LEVEL BIT(7) +#define SPIFMC_TRAN_CSR_ADDR_BYTES_MASK GENMASK(10, 8) +#define SPIFMC_TRAN_CSR_ADDR_BYTES_SHIFT 8 +#define SPIFMC_TRAN_CSR_WITH_CMD BIT(11) +#define SPIFMC_TRAN_CSR_FIFO_TRG_LVL_MASK GENMASK(13, 12) +#define SPIFMC_TRAN_CSR_FIFO_TRG_LVL_1_BYTE (0x00 << 12) +#define SPIFMC_TRAN_CSR_FIFO_TRG_LVL_2_BYTE (0x01 << 12) +#define SPIFMC_TRAN_CSR_FIFO_TRG_LVL_4_BYTE (0x02 << 12) +#define SPIFMC_TRAN_CSR_FIFO_TRG_LVL_8_BYTE (0x03 << 12) +#define SPIFMC_TRAN_CSR_GO_BUSY BIT(15) +#define SPIFMC_TRAN_CSR_ADDR4B_SHIFT 20 +#define SPIFMC_TRAN_CSR_CMD4B_SHIFT 21 + +#define SPIFMC_TRAN_NUM 0x14 +#define SPIFMC_FIFO_PORT 0x18 +#define SPIFMC_FIFO_PT 0x20 + +#define SPIFMC_INT_STS 0x28 +#define SPIFMC_INT_TRAN_DONE BIT(0) +#define SPIFMC_INT_RD_FIFO BIT(2) +#define SPIFMC_INT_WR_FIFO BIT(3) +#define SPIFMC_INT_RX_FRAME BIT(4) +#define SPIFMC_INT_TX_FRAME BIT(5) + +#define SPIFMC_INT_EN 0x2c +#define SPIFMC_INT_TRAN_DONE_EN BIT(0) +#define SPIFMC_INT_RD_FIFO_EN BIT(2) +#define SPIFMC_INT_WR_FIFO_EN BIT(3) +#define SPIFMC_INT_RX_FRAME_EN BIT(4) +#define SPIFMC_INT_TX_FRAME_EN BIT(5) + +#define SPIFMC_OPT 0x030 +#define SPIFMC_OPT_DISABLE_FIFO_FLUSH BIT(1) + +#define SPIFMC_MAX_FIFO_DEPTH 8 + +#define SPIFMC_MAX_READ_SIZE 0x10000 + +struct sophgo_spifmc { + struct spi_controller *ctrl; + void __iomem *io_base; + struct device *dev; + struct mutex lock; + struct clk *clk; +}; + +static int sophgo_spifmc_wait_int(struct sophgo_spifmc *spifmc, u8 int_type) +{ + u32 stat; + + return readl_poll_timeout(spifmc->io_base + SPIFMC_INT_STS, stat, + (stat & int_type), 0, 1000000); +} + +static int sophgo_spifmc_wait_xfer_size(struct sophgo_spifmc *spifmc, + int xfer_size) +{ + u8 stat; + + return readl_poll_timeout(spifmc->io_base + SPIFMC_FIFO_PT, stat, + ((stat & 0xf) == xfer_size), 1, 1000000); +} + +static u32 sophgo_spifmc_init_reg(struct sophgo_spifmc *spifmc) +{ + u32 reg; + + reg = readl(spifmc->io_base + SPIFMC_TRAN_CSR); + reg &= ~(SPIFMC_TRAN_CSR_TRAN_MODE_MASK | + SPIFMC_TRAN_CSR_FAST_MODE | + SPIFMC_TRAN_CSR_BUS_WIDTH_2_BIT | + SPIFMC_TRAN_CSR_BUS_WIDTH_4_BIT | + SPIFMC_TRAN_CSR_DMA_EN | + SPIFMC_TRAN_CSR_ADDR_BYTES_MASK | + SPIFMC_TRAN_CSR_WITH_CMD | + SPIFMC_TRAN_CSR_FIFO_TRG_LVL_MASK); + + writel(reg, spifmc->io_base + SPIFMC_TRAN_CSR); + + return reg; +} + +static ssize_t sophgo_spifmc_read_64k(struct sophgo_spifmc *spifmc, + const struct spi_mem_op *op, loff_t from, + size_t len, u_char *buf) +{ + int xfer_size, offset; + u32 reg; + int ret; + int i; + + reg = sophgo_spifmc_init_reg(spifmc); + reg |= (op->addr.nbytes + op->dummy.nbytes) << SPIFMC_TRAN_CSR_ADDR_BYTES_SHIFT; + reg |= SPIFMC_TRAN_CSR_FIFO_TRG_LVL_8_BYTE; + reg |= SPIFMC_TRAN_CSR_WITH_CMD; + reg |= SPIFMC_TRAN_CSR_TRAN_MODE_RX; + + writel(0, spifmc->io_base + SPIFMC_FIFO_PT); + writeb(op->cmd.opcode, spifmc->io_base + SPIFMC_FIFO_PORT); + + for (i = op->addr.nbytes - 1; i >= 0; i--) + writeb((from >> i * 8) & 0xff, spifmc->io_base + SPIFMC_FIFO_PORT); + + for (i = 0; i < op->dummy.nbytes; i++) + writeb(0xff, spifmc->io_base + SPIFMC_FIFO_PORT); + + writel(len, spifmc->io_base + SPIFMC_TRAN_NUM); + writel(0, spifmc->io_base + SPIFMC_INT_STS); + reg |= SPIFMC_TRAN_CSR_GO_BUSY; + writel(reg, spifmc->io_base + SPIFMC_TRAN_CSR); + + ret = sophgo_spifmc_wait_int(spifmc, SPIFMC_INT_RD_FIFO); + if (ret < 0) + return ret; + + offset = 0; + while (offset < len) { + xfer_size = min_t(size_t, SPIFMC_MAX_FIFO_DEPTH, len - offset); + + ret = sophgo_spifmc_wait_xfer_size(spifmc, xfer_size); + if (ret < 0) + return ret; + + for (i = 0; i < xfer_size; i++) + buf[i + offset] = readb(spifmc->io_base + SPIFMC_FIFO_PORT); + + offset += xfer_size; + } + + ret = sophgo_spifmc_wait_int(spifmc, SPIFMC_INT_TRAN_DONE); + if (ret < 0) + return ret; + + writel(0, spifmc->io_base + SPIFMC_FIFO_PT); + + return len; +} + +static ssize_t sophgo_spifmc_read(struct sophgo_spifmc *spifmc, + const struct spi_mem_op *op) +{ + size_t xfer_size; + size_t offset; + loff_t from = op->addr.val; + size_t len = op->data.nbytes; + int ret; + u8 *din = op->data.buf.in; + + offset = 0; + while (offset < len) { + xfer_size = min_t(size_t, SPIFMC_MAX_READ_SIZE, len - offset); + + ret = sophgo_spifmc_read_64k(spifmc, op, from, xfer_size, din); + if (ret < 0) + return ret; + + offset += xfer_size; + din += xfer_size; + from += xfer_size; + } + + return 0; +} + +static ssize_t sophgo_spifmc_write(struct sophgo_spifmc *spifmc, + const struct spi_mem_op *op) +{ + size_t xfer_size; + const u8 *dout = op->data.buf.out; + int i, offset; + size_t ret; + u32 reg; + + reg = sophgo_spifmc_init_reg(spifmc); + reg |= (op->addr.nbytes + op->dummy.nbytes) << SPIFMC_TRAN_CSR_ADDR_BYTES_SHIFT; + reg |= SPIFMC_TRAN_CSR_FIFO_TRG_LVL_8_BYTE; + reg |= SPIFMC_TRAN_CSR_WITH_CMD; + reg |= SPIFMC_TRAN_CSR_TRAN_MODE_TX; + + writel(0, spifmc->io_base + SPIFMC_FIFO_PT); + writeb(op->cmd.opcode, spifmc->io_base + SPIFMC_FIFO_PORT); + + for (i = op->addr.nbytes - 1; i >= 0; i--) + writeb((op->addr.val >> i * 8) & 0xff, spifmc->io_base + SPIFMC_FIFO_PORT); + + for (i = 0; i < op->dummy.nbytes; i++) + writeb(0xff, spifmc->io_base + SPIFMC_FIFO_PORT); + + writel(0, spifmc->io_base + SPIFMC_INT_STS); + writel(op->data.nbytes, spifmc->io_base + SPIFMC_TRAN_NUM); + reg |= SPIFMC_TRAN_CSR_GO_BUSY; + writel(reg, spifmc->io_base + SPIFMC_TRAN_CSR); + + ret = sophgo_spifmc_wait_xfer_size(spifmc, 0); + if (ret < 0) + return ret; + + writel(0, spifmc->io_base + SPIFMC_FIFO_PT); + + offset = 0; + while (offset < op->data.nbytes) { + xfer_size = min_t(size_t, SPIFMC_MAX_FIFO_DEPTH, op->data.nbytes - offset); + + ret = sophgo_spifmc_wait_xfer_size(spifmc, 0); + if (ret < 0) + return ret; + + for (i = 0; i < xfer_size; i++) + writeb(dout[i + offset], spifmc->io_base + SPIFMC_FIFO_PORT); + + offset += xfer_size; + } + + ret = sophgo_spifmc_wait_int(spifmc, SPIFMC_INT_TRAN_DONE); + if (ret < 0) + return ret; + + writel(0, spifmc->io_base + SPIFMC_FIFO_PT); + + return 0; +} + +static ssize_t sophgo_spifmc_tran_cmd(struct sophgo_spifmc *spifmc, + const struct spi_mem_op *op) +{ + int i, ret; + u32 reg; + + reg = sophgo_spifmc_init_reg(spifmc); + reg |= (op->addr.nbytes + op->dummy.nbytes) << SPIFMC_TRAN_CSR_ADDR_BYTES_SHIFT; + reg |= SPIFMC_TRAN_CSR_FIFO_TRG_LVL_1_BYTE; + reg |= SPIFMC_TRAN_CSR_WITH_CMD; + + writel(0, spifmc->io_base + SPIFMC_FIFO_PT); + writeb(op->cmd.opcode, spifmc->io_base + SPIFMC_FIFO_PORT); + + for (i = op->addr.nbytes - 1; i >= 0; i--) + writeb((op->addr.val >> i * 8) & 0xff, spifmc->io_base + SPIFMC_FIFO_PORT); + + for (i = 0; i < op->dummy.nbytes; i++) + writeb(0xff, spifmc->io_base + SPIFMC_FIFO_PORT); + + writel(0, spifmc->io_base + SPIFMC_INT_STS); + reg |= SPIFMC_TRAN_CSR_GO_BUSY; + writel(reg, spifmc->io_base + SPIFMC_TRAN_CSR); + + ret = sophgo_spifmc_wait_int(spifmc, SPIFMC_INT_TRAN_DONE); + if (ret < 0) + return ret; + + writel(0, spifmc->io_base + SPIFMC_FIFO_PT); + + return 0; +} + +static void sophgo_spifmc_trans(struct sophgo_spifmc *spifmc, + const struct spi_mem_op *op) +{ + if (op->data.dir == SPI_MEM_DATA_IN) + sophgo_spifmc_read(spifmc, op); + else if (op->data.dir == SPI_MEM_DATA_OUT) + sophgo_spifmc_write(spifmc, op); + else + sophgo_spifmc_tran_cmd(spifmc, op); +} + +static ssize_t sophgo_spifmc_trans_reg(struct sophgo_spifmc *spifmc, + const struct spi_mem_op *op) +{ + const u8 *dout = NULL; + u8 *din = NULL; + size_t len = op->data.nbytes; + u32 reg; + int ret; + int i; + + if (op->data.dir == SPI_MEM_DATA_IN) + din = op->data.buf.in; + else + dout = op->data.buf.out; + + reg = sophgo_spifmc_init_reg(spifmc); + reg |= SPIFMC_TRAN_CSR_FIFO_TRG_LVL_1_BYTE; + reg |= SPIFMC_TRAN_CSR_WITH_CMD; + + if (din) { + reg |= SPIFMC_TRAN_CSR_BUS_WIDTH_1_BIT; + reg |= SPIFMC_TRAN_CSR_TRAN_MODE_RX; + reg |= SPIFMC_TRAN_CSR_TRAN_MODE_TX; + + writel(SPIFMC_OPT_DISABLE_FIFO_FLUSH, spifmc->io_base + SPIFMC_OPT); + } else { + /* + * If write values to the Status Register, + * configure TRAN_CSR register as the same as + * sophgo_spifmc_read_reg. + */ + if (op->cmd.opcode == 0x01) { + reg |= SPIFMC_TRAN_CSR_TRAN_MODE_RX; + reg |= SPIFMC_TRAN_CSR_TRAN_MODE_TX; + writel(len, spifmc->io_base + SPIFMC_TRAN_NUM); + } + } + + writel(0, spifmc->io_base + SPIFMC_FIFO_PT); + writeb(op->cmd.opcode, spifmc->io_base + SPIFMC_FIFO_PORT); + + for (i = 0; i < len; i++) { + if (din) + writeb(0xff, spifmc->io_base + SPIFMC_FIFO_PORT); + else + writeb(dout[i], spifmc->io_base + SPIFMC_FIFO_PORT); + } + + writel(0, spifmc->io_base + SPIFMC_INT_STS); + writel(len, spifmc->io_base + SPIFMC_TRAN_NUM); + reg |= SPIFMC_TRAN_CSR_GO_BUSY; + writel(reg, spifmc->io_base + SPIFMC_TRAN_CSR); + + ret = sophgo_spifmc_wait_int(spifmc, SPIFMC_INT_TRAN_DONE); + if (ret < 0) + return ret; + + if (din) { + while (len--) + *din++ = readb(spifmc->io_base + SPIFMC_FIFO_PORT); + } + + writel(0, spifmc->io_base + SPIFMC_FIFO_PT); + + return 0; +} + +static int sophgo_spifmc_exec_op(struct spi_mem *mem, + const struct spi_mem_op *op) +{ + struct sophgo_spifmc *spifmc; + + spifmc = spi_controller_get_devdata(mem->spi->controller); + + mutex_lock(&spifmc->lock); + + if (op->addr.nbytes == 0) + sophgo_spifmc_trans_reg(spifmc, op); + else + sophgo_spifmc_trans(spifmc, op); + + mutex_unlock(&spifmc->lock); + + return 0; +} + +static const struct spi_controller_mem_ops sophgo_spifmc_mem_ops = { + .exec_op = sophgo_spifmc_exec_op, +}; + +static void sophgo_spifmc_init(struct sophgo_spifmc *spifmc) +{ + u32 tran_csr; + u32 reg; + + writel(0, spifmc->io_base + SPIFMC_DMMR); + + reg = readl(spifmc->io_base + SPIFMC_CTRL); + reg |= SPIFMC_CTRL_SRST; + reg &= ~((1 << 11) - 1); + reg |= 1; + writel(reg, spifmc->io_base + SPIFMC_CTRL); + + writel(0, spifmc->io_base + SPIFMC_CE_CTRL); + + tran_csr = readl(spifmc->io_base + SPIFMC_TRAN_CSR); + tran_csr |= (0 << SPIFMC_TRAN_CSR_ADDR_BYTES_SHIFT); + tran_csr |= SPIFMC_TRAN_CSR_FIFO_TRG_LVL_4_BYTE; + tran_csr |= SPIFMC_TRAN_CSR_WITH_CMD; + writel(tran_csr, spifmc->io_base + SPIFMC_TRAN_CSR); +} + +static int sophgo_spifmc_probe(struct platform_device *pdev) +{ + struct spi_controller *ctrl; + struct sophgo_spifmc *spifmc; + void __iomem *base; + int ret; + + ctrl = devm_spi_alloc_host(&pdev->dev, sizeof(*spifmc)); + if (!ctrl) + return -ENOMEM; + + spifmc = spi_controller_get_devdata(ctrl); + dev_set_drvdata(&pdev->dev, ctrl); + + spifmc->clk = devm_clk_get(&pdev->dev, NULL); + if (IS_ERR(spifmc->clk)) { + dev_err(&pdev->dev, "AHB clock not found.\n"); + return PTR_ERR(spifmc->clk); + } + + ret = clk_prepare_enable(spifmc->clk); + if (ret) { + dev_err(&pdev->dev, "Unable to enable AHB clock.\n"); + return ret; + } + + spifmc->dev = &pdev->dev; + spifmc->ctrl = ctrl; + + spifmc->io_base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(base)) + return PTR_ERR(base); + + ctrl->num_chipselect = 1; + ctrl->dev.of_node = pdev->dev.of_node; + ctrl->bits_per_word_mask = SPI_BPW_MASK(8); + ctrl->auto_runtime_pm = false; + ctrl->mem_ops = &sophgo_spifmc_mem_ops; + ctrl->mode_bits = SPI_RX_DUAL | SPI_TX_DUAL | SPI_RX_QUAD | SPI_TX_QUAD; + + mutex_init(&spifmc->lock); + + sophgo_spifmc_init(spifmc); + sophgo_spifmc_init_reg(spifmc); + + return devm_spi_register_controller(&pdev->dev, ctrl); +} + +static void sophgo_spifmc_remove(struct platform_device *pdev) +{ + struct sophgo_spifmc *spifmc = platform_get_drvdata(pdev); + + mutex_destroy(&spifmc->lock); +} + +static const struct of_device_id sophgo_spifmc_match[] = { + { .compatible = "sophgo,sg2044-spifmc-nor" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, sophgo_spifmc_match); + +static struct platform_driver sophgo_nor_driver = { + .driver = { + .name = "sophgo,spifmc-nor", + .of_match_table = sophgo_spifmc_match, + }, + .probe = sophgo_spifmc_probe, + .remove = sophgo_spifmc_remove, +}; + +module_platform_driver(sophgo_nor_driver); + +MODULE_DESCRIPTION("Sophgo SPI NOR controller driver"); +MODULE_AUTHOR("Longbin Li "); +MODULE_LICENSE("GPL"); From patchwork Mon Feb 24 10:12:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Longbin Li X-Patchwork-Id: 13987766 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E80EDC021A6 for ; Mon, 24 Feb 2025 10:22:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=YK4uqwi85lRSoJpzUsvQNjpSYynLY4mEbnT8CQFAczE=; b=fpf9PCk9dT8qEr E0LZKtTaKogyof8Y6RN8+UY4lZnEeWBBgGjNMbuXqtOENV2tvsHnT/gyG9FyHSSKqEPuFiMQkCnOc QtFpE8QGOgRQCBSXRA0908G3BAPTrxUO7uhK/eq6Y85/AXBEJVt+6+jByUqx9AWJbPHPMnDqDKJpk 2oR50M5j8R7kRyqCgu/cklwou6CEnrS1H/0FrkPL5M2gd90L7qJk1fP/RRE+kno7P8FAeXhRhbDtE JpWyJegTEQKSHzW+e3BO1Q1OwjCIPFOblSB4nHxhmp6MygiGw7Yx0ez3xBWDLLJMrzU3TuFtvTESm vDYYA1NdVWwCxEYUWDOA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tmVbU-0000000D6US-1CPA; Mon, 24 Feb 2025 10:22:24 +0000 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tmVSY-0000000D4Zw-43jl for linux-riscv@lists.infradead.org; Mon, 24 Feb 2025 10:13:12 +0000 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-220c92c857aso70403895ad.0 for ; Mon, 24 Feb 2025 02:13:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740391990; x=1740996790; darn=lists.infradead.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=zHH1Bo2ngh238ZBojTHJqWRsImuzKw7MT/RetGGhdDs=; b=KJqV4S2JGfJsEniturIA9APHST3uMcgDne78VfY6rohKANkOWsArvUreW4LyHm3G9K +BI60gO+Ht4pRlWzubRrIbmjdjR8q2mAQx7h+NulQo03+ZpJtaYSGN9gS4rs2RPMoA0g 5k/QnT8XDIZlJ8ER7Ped4t45dw0fGvbFpokvPfHZvArA0xtZEZwHf6lzOe5wywPMhX8w bQ7Qh6RQIvV9o59roGCc8zpjK23poL7Ytk6nMY9RlNBNzi+vWsy6m0k1RP5+cIlj5MDM uUKwRimcgNTHk3HSaaEpI6n4lqNgkwKnNvg1gQG3Shldt0oXrp1elWGGWxyYlnkp+NsE PjPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740391990; x=1740996790; 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=zHH1Bo2ngh238ZBojTHJqWRsImuzKw7MT/RetGGhdDs=; b=XoibucjgxM6q9m7XxRwQMADmjAALHXb8bVVjMsx77P8Y6AA9DGtMre8pfvzrz7Ft5u R2OAkqvMBpktCwZLd4nS9plGmZ7npGbgW8vamL1UltLsJBzT1M7YDJpExJTYCNGInv3s 8StMmHvMnc6taNl5n+ypvwO2os/ub2c+rPN3H85Zv/ueZwJxA+bvnmFzAdcqQ+VZf2MO G2PA0MB1o/Pog0aNZO0PSd34jiR5z6sRGa+JSA6b7Xs3x8IPhvFfZpipuvrJS45VBV5j W55V3QKFlu0GmGE2Iwh1QaZ5XZjevbTnSXxKFFWsooOoDKYJn+c+SR6WOXCq9VfmmxUZ 4Ztg== X-Forwarded-Encrypted: i=1; AJvYcCWRQs+OwLClk3wD20nOCL57UyVNxRUn3QZuTjga9iQBVZlAtxgWchGPJlmJKTjksgTj5Gkkc+z/a9La8A==@lists.infradead.org X-Gm-Message-State: AOJu0Yy9nc/lMRlZbgXL/NRsX661wX8lzzBnuhouumQaDm6sypvl0coO 7bjDNU3WesrMS/xRfxLfPXrPqOhvl+HaK33WBECg0rdhKL08Twu/ X-Gm-Gg: ASbGncvYd1Fcu7RZFLvqza/TkGgBylR9bvt0JAD2koQ5maOLzSnsI9BxwgxmIMK1gsm qgextNZh7scjZFUJJv6yAMjUuo0bQ5Y+bnZnTUVipGkoJ2hwEiW0GcmqmP4N//A8nYsffJE5h3W FLwCNT08Spew5Svp8Agpi/kZduhGqHFG0xbqMCimy2iGiIrfxshOX+9aAJBSQcwLbGKzf4/ve7I lYTU3yTbZIEbEtxPkEFnQn2dmO6hmRxdTJLbpQjT80usfQ5eQPfTzf7pZcrZ00G5ChfVY2OpgG+ SwOzAFbgg7drnrf4DDdF X-Google-Smtp-Source: AGHT+IGtCyZFRUi+gbIX4aSNZJGXzCxJh7yxdOzB199I7UFF6fkdtprcsgYmp8oGaKiLKViiu8/0JA== X-Received: by 2002:a17:902:f547:b0:215:6c5f:d142 with SMTP id d9443c01a7336-2219fff87c0mr224305655ad.20.1740391990140; Mon, 24 Feb 2025 02:13:10 -0800 (PST) Received: from cu.. ([2001:19f0:ac00:4eb8:5400:5ff:fe30:7df3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d7a464f1sm173274365ad.206.2025.02.24.02.13.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2025 02:13:09 -0800 (PST) From: Longbin Li To: Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen Wang , Inochi Amaoto , Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: Longbin Li , linux-spi@vger.kernel.org, devicetree@vger.kernel.org, sophgo@lists.linux.dev, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH 3/3] riscv: dts: sophgo: add Sophgo SPI NOR controller driver Date: Mon, 24 Feb 2025 18:12:02 +0800 Message-ID: <20250224101213.26003-4-looong.bin@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250224101213.26003-1-looong.bin@gmail.com> References: <20250224101213.26003-1-looong.bin@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250224_021311_006431_5FDFC191 X-CRM114-Status: UNSURE ( 8.80 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Add SPI NOR device node for Sophgo. Signed-off-by: Longbin Li --- .../boot/dts/sophgo/sg2044-sophgo-sd3-10.dts | 18 ++++++++++++++ arch/riscv/boot/dts/sophgo/sg2044.dtsi | 24 +++++++++++++++++++ 2 files changed, 42 insertions(+) -- 2.48.1 diff --git a/arch/riscv/boot/dts/sophgo/sg2044-sophgo-sd3-10.dts b/arch/riscv/boot/dts/sophgo/sg2044-sophgo-sd3-10.dts index c50e61a50013..9c634920f37e 100644 --- a/arch/riscv/boot/dts/sophgo/sg2044-sophgo-sd3-10.dts +++ b/arch/riscv/boot/dts/sophgo/sg2044-sophgo-sd3-10.dts @@ -80,6 +80,24 @@ &sd { status = "okay"; }; +&spifmc0 { + status = "okay"; + + flash@0 { + compatible = "jedec,spi-nor"; + reg = <0>; + }; +}; + +&spifmc1 { + status = "okay"; + + flash@0 { + compatible = "jedec,spi-nor"; + reg = <0>; + }; +}; + &uart1 { status = "okay"; }; diff --git a/arch/riscv/boot/dts/sophgo/sg2044.dtsi b/arch/riscv/boot/dts/sophgo/sg2044.dtsi index 6eaf92dd0a90..e45f7218de04 100644 --- a/arch/riscv/boot/dts/sophgo/sg2044.dtsi +++ b/arch/riscv/boot/dts/sophgo/sg2044.dtsi @@ -33,6 +33,30 @@ soc { dma-noncoherent; ranges; + spifmc0: spi@7001000000 { + compatible = "sophgo,sg2044-spifmc-nor"; + reg = <0x70 0x01000000 0x0 0x4000000>; + #address-cells = <1>; + #size-cells = <0>; + clocks = <&clk CLK_GATE_AHB_SPIFMC>; + interrupt-parent = <&intc>; + interrupts = <37 IRQ_TYPE_LEVEL_HIGH>; + resets = <&rst RST_SPIFMC0>; + status = "disabled"; + }; + + spifmc1: spi@7005000000 { + compatible = "sophgo,sg2044-spifmc-nor"; + reg = <0x70 0x05000000 0x0 0x4000000>; + #address-cells = <1>; + #size-cells = <0>; + clocks = <&clk CLK_GATE_AHB_SPIFMC>; + interrupt-parent = <&intc>; + interrupts = <38 IRQ_TYPE_LEVEL_HIGH>; + resets = <&rst RST_SPIFMC1>; + status = "disabled"; + }; + dmac0: dma-controller@7020000000 { compatible = "snps,axi-dma-1.01a"; reg = <0x70 0x20000000 0x0 0x10000>;