From patchwork Thu May 11 07:31:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Mahapatra, Amit Kumar" X-Patchwork-Id: 1779799 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=wHTYaWEl; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=IXpqryvF; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QH3Wz4w2Qz213w for ; Thu, 11 May 2023 17:32:47 +1000 (AEST) 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=z/Mfp7lcXgNJJ0PFnLND+blJOgJhxPAIal2D45OTjck=; b=wHTYaWElYCuIf8 d9FHAYRxM0xkVpdHp4a0fslj6hSgivgpmYKjupoAOwSkM8zPGLD00fuZHC/svmNpHHK33A2ZtYjtA C+7sVsMg6GXpgCRpU5Ta9mC0YRqgWIVM7u0ZcNZsEuwYGZbMCGNZ1tyl7Xg3/VEiHmJComfnIEBj6 kWgQAMpXP2Bj6C0EgvcZf9TPHgJvJJ3QwidF09yibgGeAIP79ubqpsWYLvUa3LQ7hp4EMQFj4BKuL Q1cKsXXp/n2212A4GnLOQmHoMAtv9paQ3SxoBnOK6SPeN3tZqL4gfJIW+BYaAZ+L8LLuZhO7xJd2E 30hOW5FrlhLDuUjcAB7g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1px0me-0088o6-23; Thu, 11 May 2023 07:32:16 +0000 Received: from mail-dm6nam11on2062b.outbound.protection.outlook.com ([2a01:111:f400:7eaa::62b] helo=NAM11-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1px0ma-0088jS-1w; Thu, 11 May 2023 07:32:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Bz57yN6Jni5B8RhpImzJ2TZtWiLnfI/ysa3YGlVtcasLw1dgd+eMQ/oZFa5I1aa/W2R/I/ZHeyWNRGxf/6JpVbgcNS4pbnPUR5eOOfDFO4iiQ8IMrEX47ePGl+9tnS8E0tpl0hQz8yqlARGNn9gZxf8aH72n3+vgIAsRAuZWO8cg4BTorlmLvXNJYy/BbL7y1ZAGyxE9snaaphe31PO9T0PzGA9CcYK1i+pespSok1bc9eZ/EBiVme1TT4ZYhGHDv6LA4h2aMiBy0IL6tMUVi3QEkWFbLNP9pEMyzIjRFYM4OKe3pRLXNTeAKLOxWYqVVDvpFkBp4D3JraP8q7p/9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Pd8javLJzZDbAEgQKEQcqeFybkTfClftzfV855fu7Z4=; b=PWi9dwREwK/P0fFPQPagM548CR1HWIGXSwj8cNEYiqDsCWVizY3T42kaVAXvquittlerRpdw9d1UYsqF0Bf71DQ6JqIWW5wum4KVx8x0lr70xrZkFD+dE8gjij18NOVI+N9X4KTyefV7ZcDeC00szdTe16w6IAOc2ogJ04RWHGLS2NYO5SleWTTEyRRfLINtQak+W9XbNhmrxLVOBAOu5KXXeibpNqyH0nUb6m5/3ZEQJOBAZmE5VqTiRvxZplcMT4ZMhTF8emEJxI81I/wudcg3Jc7i3pQnkxEMezxbPQ81NH9KXrS8pfNksD+AuH2icvkLepvqpAHc7C3RzYEyqA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Pd8javLJzZDbAEgQKEQcqeFybkTfClftzfV855fu7Z4=; b=IXpqryvF85S8gEuyN9q27s0JurGGAmvjmDhgOt2EZgCH6lyJdBOSdz+MZjJljoLbcQePkLh5sNND+nKSOF3UNWRH6BcJwi8POZVNqE6XsBj9r0PKJjMTf146TCLest8Dpro8PF9Y25vneF3M3QHuZuHcFVURkD7QauC3LpQxrB4= Received: from MWH0EPF00056D18.namprd21.prod.outlook.com (2603:10b6:30f:fff2:0:1:0:19) by PH8PR12MB7279.namprd12.prod.outlook.com (2603:10b6:510:221::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.19; Thu, 11 May 2023 07:31:48 +0000 Received: from CO1NAM11FT115.eop-nam11.prod.protection.outlook.com (2a01:111:f400:7eab::203) by MWH0EPF00056D18.outlook.office365.com (2603:1036:d20::b) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.6 via Frontend Transport; Thu, 11 May 2023 07:31:48 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT115.mail.protection.outlook.com (10.13.174.211) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6387.22 via Frontend Transport; Thu, 11 May 2023 07:31:47 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 11 May 2023 02:31:46 -0500 Received: from xhdakumarma40u.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Thu, 11 May 2023 02:31:41 -0500 From: Amit Kumar Mahapatra To: , , , , , , CC: , , , , , , , , , , , Amit Kumar Mahapatra Subject: [PATCH V8 1/7] spi: Add stacked and parallel memories support in SPI core Date: Thu, 11 May 2023 13:01:28 +0530 Message-ID: <20230511073134.41180-2-amit.kumar-mahapatra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230511073134.41180-1-amit.kumar-mahapatra@amd.com> References: <20230511073134.41180-1-amit.kumar-mahapatra@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT115:EE_|PH8PR12MB7279:EE_ X-MS-Office365-Filtering-Correlation-Id: 22bf3570-fd2b-4ffa-fc44-08db51f1c794 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2MZPJXmS1CtnfwY4iMIeuyQq8PxiVQoJcPc3/tluNvwIirVxST/MMcfv9gRCYDUmeq8TLmPDVXKpQYoMMShYjNFS09v378Z8t5vp8JawiMfMk55MJ5/Cg4SRoq1BIPKISEAbqOoQmrnkhtLRrc83ffsdsUoVZTFsgodXeYrseQWpKV5IBZYVOyYbgjy2tzESH2M6kL3ICN0W439W06beeEA3UcDtnZOZltRMGnCWoo8p/iqQTAJjtVcg5GfqQqEkM41aUujD1nV+p4ox10YoRDGHcdpuh8EgiLTLMGI1y6fU+oNzPZOWr4jkCc1drKzmvXTIXCV1erx5OL7m0z308N0jgF6qZ29AGqzP/1lk3V3FTxQGkMUoOsfjzA1EpkHTKUhwbCIgt9b7wNcm2ZdkUr2YXpX/voSAAkn+yOCWsfZW8WiIAQLQsHHl3XKc22iVD2mZzsVoxWyCa6D+ix7XJAe/D8skmdqqAWyLYb9u7QTOLBlAlpS/SgdGK8FGXVRtUZ1+kN6Mwre36J+Uku8M+YGvB7ViAUS/7qUcsssi/kAqPEtfeAwWqobiJmB86shY+Z1WNcYfDANwMr0kSbopJVhMBV7QUp7Hl6iyuLBSg6UCCmhAuWHLnuITBgm5VJlHyzV0n4f1gKC98gDCD2oXhIhhcrN/OKe+ovwlNobZWIKO2eMWZOaiU56yWJAgwdgXUipEaS8aDSq/ACNakaCvcrQi7Dt1iQ7svjtSURHv75S+9E0T9FLAPJ+qsC1ECQ5G X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(346002)(396003)(376002)(39860400002)(136003)(451199021)(36840700001)(46966006)(40470700004)(6666004)(8676002)(40460700003)(966005)(30864003)(70586007)(110136005)(82740400003)(70206006)(54906003)(36756003)(7416002)(4326008)(2906002)(356005)(86362001)(41300700001)(81166007)(316002)(82310400005)(8936002)(40480700001)(5660300002)(478600001)(186003)(1076003)(26005)(426003)(83380400001)(2616005)(47076005)(336012)(36860700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 May 2023 07:31:47.9049 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 22bf3570-fd2b-4ffa-fc44-08db51f1c794 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT115.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB7279 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230511_003212_689345_CC40DBBD X-CRM114-Status: GOOD ( 29.01 ) X-Spam-Score: 0.8 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: For supporting multiple CS the SPI device need to be aware of all the CS values. So, the "chip_select" member in the spi_device structure is now an array that holds all the CS values. spi_device structure now has a "cs_index_mask" member. This acts as an index to the chip_select array. If nth bit of spi->cs_index_mask is set then the driver would assert spi->chip_select[n]. Content analysis details: (0.8 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 1.0 FORGED_SPF_HELO No description available. X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org For supporting multiple CS the SPI device need to be aware of all the CS values. So, the "chip_select" member in the spi_device structure is now an array that holds all the CS values. spi_device structure now has a "cs_index_mask" member. This acts as an index to the chip_select array. If nth bit of spi->cs_index_mask is set then the driver would assert spi->chip_select[n]. In parallel mode all the chip selects are asserted/de-asserted simultaneously and each byte of data is stored in both devices, the even bits in one, the odd bits in the other. The split is automatically handled by the GQSPI controller. The GQSPI controller supports a maximum of two flashes connected in parallel mode. A SPI_CONTROLLER_MULTI_CS flag bit is added in the spi controntroller flags, through ctlr->flags the spi core will make sure that the controller is capable of handling multiple chip selects at once. For supporting multiple CS via GPIO the cs_gpiod member of the spi_device structure is now an array that holds the gpio descriptor for each chipselect. Signed-off-by: Amit Kumar Mahapatra Tested-by: Stefan Binding --- CS GPIO is not tested on our hardware but it has been tested by @Stefan https://lore.kernel.org/all/3f148a0c-8885-0425-28f4-2a53937a388f@opensource.cirrus.com/ Stefan, could you please provide your Tested-by tag for this patch --- drivers/spi/spi.c | 231 ++++++++++++++++++++++++++++------------ include/linux/spi/spi.h | 32 ++++-- 2 files changed, 189 insertions(+), 74 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 9291b2a0e887..a793e56f6a21 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -612,10 +612,24 @@ static int spi_dev_check(struct device *dev, void *data) { struct spi_device *spi = to_spi_device(dev); struct spi_device *new_spi = data; + int idx, nw_idx; - if (spi->controller == new_spi->controller && - spi_get_chipselect(spi, 0) == spi_get_chipselect(new_spi, 0)) - return -EBUSY; + if (spi->controller == new_spi->controller) { + for (idx = 0; idx < SPI_CS_CNT_MAX; idx++) { + for (nw_idx = 0; nw_idx < SPI_CS_CNT_MAX; nw_idx++) { + if ((idx != 0 && !spi_get_chipselect(spi, idx)) || + (nw_idx != 0 && !spi_get_chipselect(spi, nw_idx))) { + continue; + } else if (spi_get_chipselect(spi, idx) == + spi_get_chipselect(new_spi, nw_idx)) { + dev_err(dev, + "chipselect %d already in use\n", + spi_get_chipselect(new_spi, nw_idx)); + return -EBUSY; + } + } + } + } return 0; } @@ -629,7 +643,7 @@ static int __spi_add_device(struct spi_device *spi) { struct spi_controller *ctlr = spi->controller; struct device *dev = ctlr->dev.parent; - int status; + int status, idx; /* * We need to make sure there's no other device with this @@ -638,8 +652,6 @@ static int __spi_add_device(struct spi_device *spi) */ status = bus_for_each_dev(&spi_bus_type, NULL, spi, spi_dev_check); if (status) { - dev_err(dev, "chipselect %d already in use\n", - spi_get_chipselect(spi, 0)); return status; } @@ -649,8 +661,13 @@ static int __spi_add_device(struct spi_device *spi) return -ENODEV; } - if (ctlr->cs_gpiods) - spi_set_csgpiod(spi, 0, ctlr->cs_gpiods[spi_get_chipselect(spi, 0)]); + if (ctlr->cs_gpiods) { + for (idx = 0; idx < SPI_CS_CNT_MAX; idx++) { + if (!(idx != 0 && !spi_get_chipselect(spi, idx))) + spi_set_csgpiod(spi, idx, + ctlr->cs_gpiods[spi_get_chipselect(spi, idx)]); + } + } /* * Drivers may modify this initial i/o setup, but will @@ -690,13 +707,15 @@ int spi_add_device(struct spi_device *spi) { struct spi_controller *ctlr = spi->controller; struct device *dev = ctlr->dev.parent; - int status; + int status, idx; - /* Chipselects are numbered 0..max; validate. */ - if (spi_get_chipselect(spi, 0) >= ctlr->num_chipselect) { - dev_err(dev, "cs%d >= max %d\n", spi_get_chipselect(spi, 0), - ctlr->num_chipselect); - return -EINVAL; + for (idx = 0; idx < SPI_CS_CNT_MAX; idx++) { + /* Chipselects are numbered 0..max; validate. */ + if (spi_get_chipselect(spi, idx) >= ctlr->num_chipselect) { + dev_err(dev, "cs%d >= max %d\n", spi_get_chipselect(spi, idx), + ctlr->num_chipselect); + return -EINVAL; + } } /* Set the bus ID string */ @@ -713,12 +732,15 @@ static int spi_add_device_locked(struct spi_device *spi) { struct spi_controller *ctlr = spi->controller; struct device *dev = ctlr->dev.parent; + int idx; - /* Chipselects are numbered 0..max; validate. */ - if (spi_get_chipselect(spi, 0) >= ctlr->num_chipselect) { - dev_err(dev, "cs%d >= max %d\n", spi_get_chipselect(spi, 0), - ctlr->num_chipselect); - return -EINVAL; + for (idx = 0; idx < SPI_CS_CNT_MAX; idx++) { + /* Chipselects are numbered 0..max; validate. */ + if (spi_get_chipselect(spi, idx) >= ctlr->num_chipselect) { + dev_err(dev, "cs%d >= max %d\n", spi_get_chipselect(spi, idx), + ctlr->num_chipselect); + return -EINVAL; + } } /* Set the bus ID string */ @@ -966,58 +988,122 @@ static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes static void spi_set_cs(struct spi_device *spi, bool enable, bool force) { bool activate = enable; + u32 cs_num = 0; + int idx; /* - * Avoid calling into the driver (or doing delays) if the chip select - * isn't actually changing from the last time this was called. + * In parallel mode all the chip selects are asserted/de-asserted + * at once */ - if (!force && ((enable && spi->controller->last_cs == spi_get_chipselect(spi, 0)) || - (!enable && spi->controller->last_cs != spi_get_chipselect(spi, 0))) && - (spi->controller->last_cs_mode_high == (spi->mode & SPI_CS_HIGH))) - return; - - trace_spi_set_cs(spi, activate); + if ((spi->cs_index_mask & SPI_PARALLEL_CS_MASK) == SPI_PARALLEL_CS_MASK) { + spi->controller->last_cs_mode_high = spi->mode & SPI_CS_HIGH; + + if ((spi_get_csgpiod(spi, 0) || !spi->controller->set_cs_timing) && !activate) + spi_delay_exec(&spi->cs_hold, NULL); + + if (spi->mode & SPI_CS_HIGH) + enable = !enable; + + if (spi_get_csgpiod(spi, 0) && spi_get_csgpiod(spi, 1)) { + if (!(spi->mode & SPI_NO_CS)) { + /* + * Historically ACPI has no means of the GPIO polarity and + * thus the SPISerialBus() resource defines it on the per-chip + * basis. In order to avoid a chain of negations, the GPIO + * polarity is considered being Active High. Even for the cases + * when _DSD() is involved (in the updated versions of ACPI) + * the GPIO CS polarity must be defined Active High to avoid + * ambiguity. That's why we use enable, that takes SPI_CS_HIGH + * into account. + */ + if (has_acpi_companion(&spi->dev)) { + for (idx = 0; idx < SPI_CS_CNT_MAX; idx++) + gpiod_set_value_cansleep(spi_get_csgpiod(spi, idx), + !enable); + } else { + for (idx = 0; idx < SPI_CS_CNT_MAX; idx++) + /* Polarity handled by GPIO library */ + gpiod_set_value_cansleep(spi_get_csgpiod(spi, idx), + activate); + } + } + /* Some SPI masters need both GPIO CS & slave_select */ + if ((spi->controller->flags & SPI_MASTER_GPIO_SS) && + spi->controller->set_cs) + spi->controller->set_cs(spi, !enable); + } else if (spi->controller->set_cs) { + spi->controller->set_cs(spi, !enable); + } - spi->controller->last_cs = enable ? spi_get_chipselect(spi, 0) : -1; - spi->controller->last_cs_mode_high = spi->mode & SPI_CS_HIGH; + if (spi_get_csgpiod(spi, 0) || spi_get_csgpiod(spi, 1) || + !spi->controller->set_cs_timing) { + if (activate) + spi_delay_exec(&spi->cs_setup, NULL); + else + spi_delay_exec(&spi->cs_inactive, NULL); + } + } else { - if ((spi_get_csgpiod(spi, 0) || !spi->controller->set_cs_timing) && !activate) - spi_delay_exec(&spi->cs_hold, NULL); + if (spi->cs_index_mask) + cs_num = ffs(spi->cs_index_mask) - 1; - if (spi->mode & SPI_CS_HIGH) - enable = !enable; + /* + * Avoid calling into the driver (or doing delays) if the chip select + * isn't actually changing from the last time this was called. + */ + if (!force && ((enable && spi->controller->last_cs == + spi_get_chipselect(spi, cs_num)) || + (!enable && spi->controller->last_cs != + spi_get_chipselect(spi, cs_num))) && + (spi->controller->last_cs_mode_high == + (spi->mode & SPI_CS_HIGH))) + return; + + trace_spi_set_cs(spi, activate); + + spi->controller->last_cs = enable ? spi_get_chipselect(spi, cs_num) : -1; + spi->controller->last_cs_mode_high = spi->mode & SPI_CS_HIGH; + + if ((spi_get_csgpiod(spi, cs_num) || !spi->controller->set_cs_timing) && !activate) + spi_delay_exec(&spi->cs_hold, NULL); + + if (spi->mode & SPI_CS_HIGH) + enable = !enable; + + if (spi_get_csgpiod(spi, cs_num)) { + if (!(spi->mode & SPI_NO_CS)) { + /* + * Historically ACPI has no means of the GPIO polarity and + * thus the SPISerialBus() resource defines it on the per-chip + * basis. In order to avoid a chain of negations, the GPIO + * polarity is considered being Active High. Even for the cases + * when _DSD() is involved (in the updated versions of ACPI) + * the GPIO CS polarity must be defined Active High to avoid + * ambiguity. That's why we use enable, that takes SPI_CS_HIGH + * into account. + */ + if (has_acpi_companion(&spi->dev)) + gpiod_set_value_cansleep(spi_get_csgpiod(spi, cs_num), + !enable); + else + /* Polarity handled by GPIO library */ + gpiod_set_value_cansleep(spi_get_csgpiod(spi, cs_num), + activate); + } + /* Some SPI masters need both GPIO CS & slave_select */ + if ((spi->controller->flags & SPI_MASTER_GPIO_SS) && + spi->controller->set_cs) + spi->controller->set_cs(spi, !enable); + } else if (spi->controller->set_cs) { + spi->controller->set_cs(spi, !enable); + } - if (spi_get_csgpiod(spi, 0)) { - if (!(spi->mode & SPI_NO_CS)) { - /* - * Historically ACPI has no means of the GPIO polarity and - * thus the SPISerialBus() resource defines it on the per-chip - * basis. In order to avoid a chain of negations, the GPIO - * polarity is considered being Active High. Even for the cases - * when _DSD() is involved (in the updated versions of ACPI) - * the GPIO CS polarity must be defined Active High to avoid - * ambiguity. That's why we use enable, that takes SPI_CS_HIGH - * into account. - */ - if (has_acpi_companion(&spi->dev)) - gpiod_set_value_cansleep(spi_get_csgpiod(spi, 0), !enable); + if (spi_get_csgpiod(spi, cs_num) || !spi->controller->set_cs_timing) { + if (activate) + spi_delay_exec(&spi->cs_setup, NULL); else - /* Polarity handled by GPIO library */ - gpiod_set_value_cansleep(spi_get_csgpiod(spi, 0), activate); + spi_delay_exec(&spi->cs_inactive, NULL); } - /* Some SPI masters need both GPIO CS & slave_select */ - if ((spi->controller->flags & SPI_MASTER_GPIO_SS) && - spi->controller->set_cs) - spi->controller->set_cs(spi, !enable); - } else if (spi->controller->set_cs) { - spi->controller->set_cs(spi, !enable); - } - - if (spi_get_csgpiod(spi, 0) || !spi->controller->set_cs_timing) { - if (activate) - spi_delay_exec(&spi->cs_setup, NULL); - else - spi_delay_exec(&spi->cs_inactive, NULL); } } @@ -2246,8 +2332,8 @@ static void of_spi_parse_dt_cs_delay(struct device_node *nc, static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi, struct device_node *nc) { - u32 value; - int rc; + u32 value, cs[SPI_CS_CNT_MAX] = {0}; + int rc, idx; /* Mode (clock phase/polarity/etc.) */ if (of_property_read_bool(nc, "spi-cpha")) @@ -2320,13 +2406,21 @@ static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi, } /* Device address */ - rc = of_property_read_u32(nc, "reg", &value); - if (rc) { + rc = of_property_read_variable_u32_array(nc, "reg", &cs[0], 1, + SPI_CS_CNT_MAX); + if (rc < 0 || rc > ctlr->num_chipselect) { dev_err(&ctlr->dev, "%pOF has no valid 'reg' property (%d)\n", nc, rc); return rc; + } else if ((of_property_read_bool(nc, "parallel-memories")) && + (!(ctlr->flags & SPI_CONTROLLER_MULTI_CS))) { + dev_err(&ctlr->dev, "SPI controller doesn't support multi CS\n"); + return -EINVAL; } - spi_set_chipselect(spi, 0, value); + for (idx = 0; idx < rc; idx++) + spi_set_chipselect(spi, idx, cs[idx]); + /* By default set the spi->cs_index_mask as 1 */ + spi->cs_index_mask = 0x01; /* Device speed */ if (!of_property_read_u32(nc, "spi-max-frequency", &value)) @@ -3905,7 +3999,8 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message) * cs_change is set for each transfer. */ if ((spi->mode & SPI_CS_WORD) && (!(ctlr->mode_bits & SPI_CS_WORD) || - spi_get_csgpiod(spi, 0))) { + spi_get_csgpiod(spi, 0) || + spi_get_csgpiod(spi, 1))) { size_t maxsize; int ret; diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index cfe42f8cd7a4..d0f9a9a8b6d8 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -19,6 +19,11 @@ #include #include +/* Max no. of CS supported per spi device */ +#define SPI_CS_CNT_MAX 2 + +/* chip select mask */ +#define SPI_PARALLEL_CS_MASK (BIT(0) | BIT(1)) struct dma_chan; struct software_node; struct ptp_system_timestamp; @@ -166,6 +171,7 @@ extern void spi_transfer_cs_change_delay_exec(struct spi_message *msg, * deasserted. If @cs_change_delay is used from @spi_transfer, then the * two delays will be added up. * @pcpu_statistics: statistics for the spi_device + * @cs_index_mask: Bit mask of the active chipselect(s) in the chipselect array * * A @spi_device is used to interchange data between an SPI slave * (usually a discrete chip) and CPU memory. @@ -181,7 +187,7 @@ struct spi_device { struct spi_controller *controller; struct spi_controller *master; /* Compatibility layer */ u32 max_speed_hz; - u8 chip_select; + u8 chip_select[SPI_CS_CNT_MAX]; u8 bits_per_word; bool rt; #define SPI_NO_TX BIT(31) /* No transmit wire */ @@ -212,7 +218,7 @@ struct spi_device { void *controller_data; char modalias[SPI_NAME_SIZE]; const char *driver_override; - struct gpio_desc *cs_gpiod; /* Chip select gpio desc */ + struct gpio_desc *cs_gpiod[SPI_CS_CNT_MAX]; /* Chip select gpio desc */ struct spi_delay word_delay; /* Inter-word delay */ /* CS delays */ struct spi_delay cs_setup; @@ -222,6 +228,13 @@ struct spi_device { /* The statistics */ struct spi_statistics __percpu *pcpu_statistics; + /* Bit mask of the chipselect(s) that the driver need to use from + * the chipselect array.When the controller is capable to handle + * multiple chip selects & memories are connected in parallel + * then more than one bit need to be set in cs_index_mask. + */ + u32 cs_index_mask : SPI_CS_CNT_MAX; + /* * likely need more hooks for more protocol options affecting how * the controller talks to each chip, like: @@ -278,22 +291,22 @@ static inline void *spi_get_drvdata(const struct spi_device *spi) static inline u8 spi_get_chipselect(const struct spi_device *spi, u8 idx) { - return spi->chip_select; + return spi->chip_select[idx]; } static inline void spi_set_chipselect(struct spi_device *spi, u8 idx, u8 chipselect) { - spi->chip_select = chipselect; + spi->chip_select[idx] = chipselect; } static inline struct gpio_desc *spi_get_csgpiod(const struct spi_device *spi, u8 idx) { - return spi->cs_gpiod; + return spi->cs_gpiod[idx]; } static inline void spi_set_csgpiod(struct spi_device *spi, u8 idx, struct gpio_desc *csgpiod) { - spi->cs_gpiod = csgpiod; + spi->cs_gpiod[idx] = csgpiod; } /** @@ -398,6 +411,8 @@ extern struct spi_device *spi_new_ancillary_device(struct spi_device *spi, u8 ch * @bus_lock_spinlock: spinlock for SPI bus locking * @bus_lock_mutex: mutex for exclusion of multiple callers * @bus_lock_flag: indicates that the SPI bus is locked for exclusive use + * @multi_cs_cap: indicates that the SPI Controller can assert/de-assert + * more than one chip select at once. * @setup: updates the device mode and clocking records used by a * device's SPI controller; protocol code may call this. This * must fail if an unrecognized or unsupported mode is requested. @@ -564,6 +579,11 @@ struct spi_controller { #define SPI_CONTROLLER_MUST_TX BIT(4) /* Requires tx */ #define SPI_MASTER_GPIO_SS BIT(5) /* GPIO CS must select slave */ + /* + * The spi-controller has multi chip select capability and can + * assert/de-assert more than one chip select at once. + */ +#define SPI_CONTROLLER_MULTI_CS BIT(6) /* Flag indicating if the allocation of this struct is devres-managed */ bool devm_allocated; From patchwork Thu May 11 07:31:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Mahapatra, Amit Kumar" X-Patchwork-Id: 1779797 X-Patchwork-Delegate: tudor.ambarus@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=b9MNK6i7; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=LXTy9jPs; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QH3Wn1NB2z213w for ; Thu, 11 May 2023 17:32:37 +1000 (AEST) 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=O7/z8I21ySbPVRujiFxTJcU+hOOHKTZ9cHZFw5wuE1s=; b=b9MNK6i7T624rI EXoKJPtx/ELcGsfy2ghPeXavjBKfLP2Uh9CmqFRf6w/gSlU5pMIl3eycbh36f0GExkZBualn1EJsr LBxh14IIBxNXU6PgTjCkbsQtlUaAQvoR+mxBJipPxNbHdMWCcLuhG30xEo3SLidFlO18PghlzgiXn dy4rhvr0a+LJ45YH92qNQxCiJgOpgEVqW1je9A6gqI7Upe3inWJRcGyD7H+Hm5DOdO4/xRp5e7rL/ mGh5nB7CYg8Yf1ciZMpMRH9GeqQyfdqPIuiXUNrfT8J0zYN415Upj9Iv3BtAhUxe81qaI1y5xugGU O7iiOC7Xt89pNPOxvZSQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1px0mP-0088hg-20; Thu, 11 May 2023 07:32:01 +0000 Received: from mail-co1nam11on20606.outbound.protection.outlook.com ([2a01:111:f400:7eab::606] helo=NAM11-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1px0mM-0088gw-2a; Thu, 11 May 2023 07:32:00 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GY3ts4ZSpOpeV4EMXBe+8M+OzbbHeJSE4zjW2KFH0Qyh1HSEsiJslEGzko1OnHIQlakf/CVtS62IFpRArrTLu1uUh04HWoERiEXRUqosFzmma/aO1vsAdZfEknpx8Y0/dfaBMXLSOrRtzyHTaArYs+3JeP451VdeavYhv+ceDqXLGsCZPi3h8aNeqI4TplX29SXdkTJ5vPivrsa+v3z8uVv01qDAZtQfquIA/VQl7UsFspZVaD+g62tNge70MlYJSwSXleS693yIXe2VjR91Aeb2x/ZzRCe1e8KcPRCZezN81k9Ac8/M9pTvMIxcURiv164dREiLtHMXYU7OuIl4Rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=D5mqpHnfYMEPp/K3f3bZgmug97OgZD/HN9a0e4dtXkU=; b=i0K9yB+NZnwFOtT7KEwxUEZ8LqdtL4TncN1WvpdDOUyf019GKgLMGlbtjhKj6xyHhWC4NZx67eQSwaX1Olbn5wXHEk6/nnCHo6/eh+zfGuuqowMqHhV6EOhYyFgQV1wxb+a7RggDI8T6Vz8reMyyIiG6+wXf0YwRc34CtcyoFxZU4NX/7svaG32z8Cc8l1O9Z5VuitT1xkZ3RHcyg2o0EysK8Pia+SkCRZphBzcWczM/IwgFPyYj7H8ApdEzl3BOTagjdMAlx6iPLYuXZbotHeD5aGsNvzezwG9n+C8jr58A015+8z4MkG5SS9GG7OT3A0dC4H8pnvV2OAcw/GsxSw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=D5mqpHnfYMEPp/K3f3bZgmug97OgZD/HN9a0e4dtXkU=; b=LXTy9jPsm6XgpFUZCpvulgic7LKy+XA7vJVuFGlpGn8hhZKGKc7VdeRf4SgbYF9lsyN50NssoAOT0zftNQSKrOpXAqBi/VZi+B2VQ9cjonNDoC96QV1zfU68T5DB0/47Rwi1WmVhH4t4PMrmCbRfJmA0X56c0aa4hFrJfJurGAQ= Received: from MW4PR03CA0240.namprd03.prod.outlook.com (2603:10b6:303:b9::35) by BL0PR12MB4996.namprd12.prod.outlook.com (2603:10b6:208:1c6::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.33; Thu, 11 May 2023 07:31:53 +0000 Received: from CO1NAM11FT030.eop-nam11.prod.protection.outlook.com (2603:10b6:303:b9:cafe::97) by MW4PR03CA0240.outlook.office365.com (2603:10b6:303:b9::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.21 via Frontend Transport; Thu, 11 May 2023 07:31:53 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT030.mail.protection.outlook.com (10.13.174.125) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6387.21 via Frontend Transport; Thu, 11 May 2023 07:31:53 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 11 May 2023 02:31:52 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 11 May 2023 00:31:52 -0700 Received: from xhdakumarma40u.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Thu, 11 May 2023 02:31:47 -0500 From: Amit Kumar Mahapatra To: , , , , , , CC: , , , , , , , , , , , Amit Kumar Mahapatra Subject: [PATCH V8 2/7] mtd: spi-nor: Convert macros with inline functions Date: Thu, 11 May 2023 13:01:29 +0530 Message-ID: <20230511073134.41180-3-amit.kumar-mahapatra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230511073134.41180-1-amit.kumar-mahapatra@amd.com> References: <20230511073134.41180-1-amit.kumar-mahapatra@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT030:EE_|BL0PR12MB4996:EE_ X-MS-Office365-Filtering-Correlation-Id: e96a6a92-c115-4d46-3dff-08db51f1cad2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UgscT75HcWclaA8ySCls8Pc4Dk40hyo9Khd4A8Nvep/wkf9Ud+s/ILV1PnlRcG5FS41WsZKhG4xpv1gW6RJTVMLmbNt3ZXsacFOq1gv+X1p5cjqe2NoILpMhWqBZrRWKzvRKZF9RtWqaWvKj23l7TmqhN4RJSuHFurlSwjpyFn9LzQ9k6tODWL6HM8e6OndD8AOVxNiSjzPNyqI4B0rNW3c7/yvbBvFbCtGEJs6pjUIOd0G5+cZC+mPJYcrGBt+9JCT9qylQy350+8KR6Q/MJgg60Aho29S0lONeRUfbdzTKIu3gygG+bH7+ZUZM0NeCiW4DF8k1SXGhLzAxRIMS9gfMC422HZWSL0OJjVgZ823iSkqSGIG8ZpHSEmOfynnD6i0OS++v6k1kvzRetTwwuLkfC1eAPiPtYvW9Tl+/63l41VTnPVs0zo8WBvej1lvDCTV4uUNws+ANOzREDoEoe4ch/jN501sOsL8NQ/TzE7spENxMn0xGBLGk9B2oczCtMzHvL0L9OMRk5Kjaanu++KxiPg+Ug7eH0C/q1GifmxuGOZOxSKATdWTGCLN1lyK0XiU9bKlAOiFSLG2BbpviXIOm5F2hvmAqmMjLQiVyO3s35GMG8udo2GSnhp4r59Ae6YU4GhwSTw4JT9/ANNswMJo2itnyZp3ykNTU6M4roR4AWf9+u6nbkkSxl97+Qe7BgfvFbOVT7LWlvqnPKX4bh64HLvoPbPKzUX+il6Lx93g= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(136003)(396003)(376002)(39860400002)(346002)(451199021)(36840700001)(46966006)(40470700004)(5660300002)(4326008)(26005)(6666004)(316002)(7416002)(81166007)(41300700001)(356005)(82740400003)(110136005)(86362001)(1076003)(70206006)(70586007)(54906003)(8676002)(186003)(8936002)(2906002)(82310400005)(36860700001)(36756003)(478600001)(40460700003)(83380400001)(47076005)(426003)(2616005)(336012)(40480700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 May 2023 07:31:53.3082 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e96a6a92-c115-4d46-3dff-08db51f1cad2 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT030.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB4996 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230511_003158_839307_B7E73C1F X-CRM114-Status: GOOD ( 10.05 ) X-Spam-Score: 0.8 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: In further patches the nor->params references in spi_nor_otp_region_len(nor) & spi_nor_otp_n_regions(nor) macros will be replaced with spi_nor_get_params() API. To make the transition smoother, first [...] Content analysis details: (0.8 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 1.0 FORGED_SPF_HELO No description available. X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org In further patches the nor->params references in spi_nor_otp_region_len(nor) & spi_nor_otp_n_regions(nor) macros will be replaced with spi_nor_get_params() API. To make the transition smoother, first converting the macros into static inline functions. Suggested-by: Michal Simek Signed-off-by: Amit Kumar Mahapatra --- drivers/mtd/spi-nor/otp.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/spi-nor/otp.c b/drivers/mtd/spi-nor/otp.c index 9a729aa3452d..23fe75ddc9cf 100644 --- a/drivers/mtd/spi-nor/otp.c +++ b/drivers/mtd/spi-nor/otp.c @@ -11,8 +11,27 @@ #include "core.h" -#define spi_nor_otp_region_len(nor) ((nor)->params->otp.org->len) -#define spi_nor_otp_n_regions(nor) ((nor)->params->otp.org->n_regions) +/** + * spi_nor_otp_region_len() - get size of one OTP region in bytes + * @nor: pointer to 'struct spi_nor' + * + * Return: size of one OTP region in bytes + */ +static inline unsigned int spi_nor_otp_region_len(struct spi_nor *nor) +{ + return nor->params->otp.org->len; +} + +/** + * spi_nor_otp_n_regions() - get number of individual OTP regions + * @nor: pointer to 'struct spi_nor' + * + * Return: number of individual OTP regions + */ +static inline unsigned int spi_nor_otp_n_regions(struct spi_nor *nor) +{ + return nor->params->otp.org->n_regions; +} /** * spi_nor_otp_read_secr() - read security register From patchwork Thu May 11 07:31:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Mahapatra, Amit Kumar" X-Patchwork-Id: 1779800 X-Patchwork-Delegate: tudor.ambarus@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=BI7yCcJT; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=5aLVwOUp; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QH3X95YBwz213w for ; Thu, 11 May 2023 17:32:57 +1000 (AEST) 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=O6DSeue86SqYHL2TEBThkh6Ifj7sGJh71dsYVpdXYGM=; b=BI7yCcJTKZvibq 8xr2W9xlzVMoRwOsxnKEE40mxIoX8qrDJimIhhscR4LPvVsVsioULzzD03FuSLG2I5y3HwGLOdobT qbO+pbTiBkasCQPaH75prHq2lKjfuz5VRIqMrc8vYoXGM5uqwP7l8ivL3k5rw/aY3yR2PwSykLvbR So4cjedaJu+V6OMFZ4lzNVXuViImf4yGUdiunS6/rDO+hnKodi5CB5QTljlBRC30XM3140imT/O/Q ROBjyT/iO0xCFanma7NEd4bcfQlQfR3V89VgGCUKPUvOM+8lq1Au3TTIWKTW7bWgRzseoYPu/oho2 Ph6gAa7s9OuTUjHnH6TA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1px0mi-0088q1-1L; Thu, 11 May 2023 07:32:20 +0000 Received: from mail-mw2nam10on2062a.outbound.protection.outlook.com ([2a01:111:f400:7e89::62a] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1px0mb-0088ls-0e; Thu, 11 May 2023 07:32:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hseO5f7dc9JdgXGJ+Y/wMaReetXbAGarC6cBF/7ZcHSniu4ymQa7CLoWdnM4UrXW4eWUiY2Cj+GQxaJ1OYGjSjdpkZ1fBSWoMfoSCyn0w+kwVjgdgl3PzuY80t8+zVApUlHNnUtvS363dGsmbd4LUbM5W6GKQCIW3CrkGJ+5VMFJZj9C4vifj4F7yzQpGhckTs8puQAdTGQC8DGdL/amOSzkJutCWDJ1bnleZct6C00bXwayBZsWqPbAIr2tcy98CA03rsOZn59MemO348U4jjyNT2jPRMWuVbm49TIgiuvEDHVHi6YkzWOcs1HXeNsSCLn5gKU+vCtncdvy+PyQjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=2wCY6GIeTh0fT1CnezrR7i3+E620xGalIIj8CpLtlWg=; b=RfjD7C9oTmiPYwBk2EiVZFMQMRhKMZGWBWqS6e+zRyqwGk2FrHD59sYEwPOKUuUHQT7flAEmJ91muchVuY1CV1N4nlFPhsjV0A+8l/K/+hmkq4olRbGxWblQgeoHq8TO3FmIK1QeCd1yZ+ULYrHh6JpiR+vjJd1HY/tRyH4mUfJW6+Eio8aB7oMuLZ5eHbTrjAPcDoZR4XG+NOKauughY2iii9FbOyo/69rOWLjkVXxu1xva6ER9h5DM+CrOjAN+t4MbEBxC1PfBOv0KEQKlm5l2sz2U9cnwNpaYKWOj1JYsj7KeiSlcTr8z6xrDulDXT4MsbGOGR3zl2bW1wpyCtg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2wCY6GIeTh0fT1CnezrR7i3+E620xGalIIj8CpLtlWg=; b=5aLVwOUpx341pt/sIgNBl+yJeT4A04MRDqgDjkMOei2CAyqOGolUmE9tXObbwwAHmc+p0MyZvYap08R3mOFv3KtZH96J8tVdc+RWgcaD08CDF0LXDxS4MEJb5ySgeQXeglgkIzaSilb0ZlwX9c0lrPXeuB09gldFw0R75fKkcXc= Received: from MW4PR03CA0219.namprd03.prod.outlook.com (2603:10b6:303:b9::14) by CO6PR12MB5395.namprd12.prod.outlook.com (2603:10b6:303:13a::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.20; Thu, 11 May 2023 07:31:59 +0000 Received: from CO1NAM11FT030.eop-nam11.prod.protection.outlook.com (2603:10b6:303:b9:cafe::e2) by MW4PR03CA0219.outlook.office365.com (2603:10b6:303:b9::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.21 via Frontend Transport; Thu, 11 May 2023 07:31:59 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT030.mail.protection.outlook.com (10.13.174.125) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6387.21 via Frontend Transport; Thu, 11 May 2023 07:31:59 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 11 May 2023 02:31:58 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 11 May 2023 00:31:57 -0700 Received: from xhdakumarma40u.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Thu, 11 May 2023 02:31:52 -0500 From: Amit Kumar Mahapatra To: , , , , , , CC: , , , , , , , , , , , Amit Kumar Mahapatra Subject: [PATCH V8 3/7] mtd: spi-nor: Add APIs to set/get nor->params Date: Thu, 11 May 2023 13:01:30 +0530 Message-ID: <20230511073134.41180-4-amit.kumar-mahapatra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230511073134.41180-1-amit.kumar-mahapatra@amd.com> References: <20230511073134.41180-1-amit.kumar-mahapatra@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT030:EE_|CO6PR12MB5395:EE_ X-MS-Office365-Filtering-Correlation-Id: da268c71-9295-4126-8904-08db51f1ce9c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9wssy+iXE3uJMCitt3DdEOi0PUNVdVjhAT9n5k+9+NciVextbwvG9/ihp3FWg8Kyxl97mBGsp31ABZ4mwqEe3gpGKjg+kAMhen8kXh4xrjLt9pZE5eMWnMPzSry2/Xv9DvbAKrIZ35JztGNfmF3DciwHcqNNIstbDfEMdVj1fY2aRVgKHExSGnNTmDdH1ICMUh3ZDjuHSxgQGRd3y8DEpHuxArv6CsspVVbYLFFp0RXzU6AG4KdOPzmYzgT52R4XdOKcfkM51Zso5CKwnilGhSnHf4+wLpCZgI/8QwCZFN5rmPejX2IT71aM1rxKM3ju6/4UVPFJkmXqNOr/F93QIpndmJyTcVut0/nZPvVtc+zaYeQpMu4dJUnnOM4h11tyvtv0+rZ/APjh6A+CorXxrnDZuOWkc+owga/DXs1KFNHFbnRpfvIJ2Z2iIfcYTz5jR//Uz0+xP1a7Fqbimp2uREnOMBbCujZsjqTcFa8oz5JWtxF8S6uRBrTDLdBGVh3sshg9OR5E+1033lmJNa/ACbej+xgmWT+xoTOdVliPaoNdQXUE76sFENfNO5ZhVrbbEZMenK8DH+gxkbEGZeQnxYdTfNgKH6g2iTbalDv66/LLBS6hcCbO7gtGzEt/h62QBPQcwVH4SREVrTsdL8X3avm8YHNYXRqTgNj+D4RHatVISKa9+NXT5hMDryvXOYZt5HB1bN7XoOHXy1dgH43EulbL+IC+TifUHYM2SLhcD1zYrukoryNQ3Hwur7GWMJpmCEVLcaMRouQ4dBCh/egcjALTtp4Pk8JdmObEmyjxpx8= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(396003)(136003)(376002)(39860400002)(346002)(451199021)(46966006)(40470700004)(36840700001)(5660300002)(7416002)(110136005)(54906003)(478600001)(6666004)(41300700001)(8936002)(8676002)(316002)(26005)(1076003)(70206006)(4326008)(70586007)(2906002)(30864003)(83380400001)(47076005)(336012)(40460700003)(426003)(2616005)(186003)(36860700001)(356005)(82740400003)(81166007)(40480700001)(86362001)(82310400005)(36756003)(36900700001)(559001)(579004)(309714004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 May 2023 07:31:59.6671 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: da268c71-9295-4126-8904-08db51f1ce9c X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT030.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR12MB5395 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230511_003213_300717_1E30B6E8 X-CRM114-Status: GOOD ( 25.25 ) X-Spam-Score: 0.8 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Supporting multi-cs in spi-nor would require the *params member of struct spi_nor to be an array. To make the transition smoother introduced spi_nor_get_params() & spi_nor_set_params() APIs to get & s [...] Content analysis details: (0.8 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 1.0 FORGED_SPF_HELO No description available. X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Supporting multi-cs in spi-nor would require the *params member of struct spi_nor to be an array. To make the transition smoother introduced spi_nor_get_params() & spi_nor_set_params() APIs to get & set nor->params, added a new local variable (struct spi_nor_flash_parameter *params) to hold the return value of the spi_nor_get_params() function call and replaced all nor->params references with the "params". While adding multi-cs support in further patches the *params member of the spi_nor structure would be converted to arrays & the "idx" parameter of the APIs would be used as array index i.e., nor->params[idx]. Signed-off-by: Amit Kumar Mahapatra --- drivers/mtd/spi-nor/atmel.c | 17 ++-- drivers/mtd/spi-nor/core.c | 137 ++++++++++++++++++++----------- drivers/mtd/spi-nor/debugfs.c | 4 +- drivers/mtd/spi-nor/gigadevice.c | 4 +- drivers/mtd/spi-nor/issi.c | 11 ++- drivers/mtd/spi-nor/macronix.c | 10 ++- drivers/mtd/spi-nor/micron-st.c | 30 ++++--- drivers/mtd/spi-nor/otp.c | 29 +++++-- drivers/mtd/spi-nor/sfdp.c | 33 ++++---- drivers/mtd/spi-nor/spansion.c | 80 +++++++++++------- drivers/mtd/spi-nor/sst.c | 7 +- drivers/mtd/spi-nor/swp.c | 22 +++-- drivers/mtd/spi-nor/winbond.c | 2 +- drivers/mtd/spi-nor/xilinx.c | 18 ++-- include/linux/mtd/spi-nor.h | 10 +++ 15 files changed, 271 insertions(+), 143 deletions(-) diff --git a/drivers/mtd/spi-nor/atmel.c b/drivers/mtd/spi-nor/atmel.c index 656dd80a0be7..57ca9f5ee205 100644 --- a/drivers/mtd/spi-nor/atmel.c +++ b/drivers/mtd/spi-nor/atmel.c @@ -23,10 +23,11 @@ static int at25fs_nor_lock(struct spi_nor *nor, loff_t ofs, uint64_t len) static int at25fs_nor_unlock(struct spi_nor *nor, loff_t ofs, uint64_t len) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); int ret; /* We only support unlocking the whole flash array */ - if (ofs || len != nor->params->size) + if (ofs || len != params->size) return -EINVAL; /* Write 0x00 to the status register to disable write protection */ @@ -50,7 +51,9 @@ static const struct spi_nor_locking_ops at25fs_nor_locking_ops = { static void at25fs_nor_late_init(struct spi_nor *nor) { - nor->params->locking_ops = &at25fs_nor_locking_ops; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + + params->locking_ops = &at25fs_nor_locking_ops; } static const struct spi_nor_fixups at25fs_nor_fixups = { @@ -69,11 +72,12 @@ static const struct spi_nor_fixups at25fs_nor_fixups = { static int atmel_nor_set_global_protection(struct spi_nor *nor, loff_t ofs, uint64_t len, bool is_protect) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); int ret; u8 sr; /* We only support locking the whole flash array */ - if (ofs || len != nor->params->size) + if (ofs || len != params->size) return -EINVAL; ret = spi_nor_read_sr(nor, nor->bouncebuf); @@ -131,9 +135,10 @@ static int atmel_nor_global_unprotect(struct spi_nor *nor, loff_t ofs, static int atmel_nor_is_global_protected(struct spi_nor *nor, loff_t ofs, uint64_t len) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); int ret; - if (ofs >= nor->params->size || (ofs + len) > nor->params->size) + if (ofs >= params->size || (ofs + len) > params->size) return -EINVAL; ret = spi_nor_read_sr(nor, nor->bouncebuf); @@ -151,7 +156,9 @@ static const struct spi_nor_locking_ops atmel_nor_global_protection_ops = { static void atmel_nor_global_protection_late_init(struct spi_nor *nor) { - nor->params->locking_ops = &atmel_nor_global_protection_ops; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + + params->locking_ops = &atmel_nor_global_protection_ops; } static const struct spi_nor_fixups atmel_nor_global_protection_fixups = { diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c index 0bb0ad14a2fc..c5d752a65575 100644 --- a/drivers/mtd/spi-nor/core.c +++ b/drivers/mtd/spi-nor/core.c @@ -448,14 +448,15 @@ int spi_nor_read_id(struct spi_nor *nor, u8 naddr, u8 ndummy, u8 *id, */ int spi_nor_read_sr(struct spi_nor *nor, u8 *sr) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); int ret; if (nor->spimem) { struct spi_mem_op op = SPI_NOR_RDSR_OP(sr); if (nor->reg_proto == SNOR_PROTO_8_8_8_DTR) { - op.addr.nbytes = nor->params->rdsr_addr_nbytes; - op.dummy.nbytes = nor->params->rdsr_dummy; + op.addr.nbytes = params->rdsr_addr_nbytes; + op.dummy.nbytes = params->rdsr_dummy; /* * We don't want to read only one byte in DTR mode. So, * read 2 and then discard the second byte. @@ -688,14 +689,15 @@ static void spi_nor_unlock_rdst(struct spi_nor *nor) static int spi_nor_ready(struct spi_nor *nor) { int ret; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); ret = spi_nor_lock_rdst(nor); if (ret) return 0; /* Flashes might override the standard routine. */ - if (nor->params->ready) - ret = nor->params->ready(nor); + if (params->ready) + ret = params->ready(nor); else ret = spi_nor_sr_ready(nor); @@ -861,6 +863,7 @@ static int spi_nor_write_sr1_and_check(struct spi_nor *nor, u8 sr1) */ static int spi_nor_write_16bit_sr_and_check(struct spi_nor *nor, u8 sr1) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); int ret; u8 *sr_cr = nor->bouncebuf; u8 cr_written; @@ -870,7 +873,7 @@ static int spi_nor_write_16bit_sr_and_check(struct spi_nor *nor, u8 sr1) ret = spi_nor_read_cr(nor, &sr_cr[1]); if (ret) return ret; - } else if (nor->params->quad_enable) { + } else if (params->quad_enable) { /* * If the Status Register 2 Read command (35h) is not * supported, we should at least be sure we don't @@ -878,7 +881,7 @@ static int spi_nor_write_16bit_sr_and_check(struct spi_nor *nor, u8 sr1) * * We can safely assume that when the Quad Enable method is * set, the value of the QE bit is one, as a consequence of the - * nor->params->quad_enable() call. + * params->quad_enable() call. * * We can safely assume that the Quad Enable bit is present in * the Status Register 2 at BIT(1). According to the JESD216 @@ -1149,17 +1152,21 @@ static u8 spi_nor_convert_3to4_erase(u8 opcode) static bool spi_nor_has_uniform_erase(const struct spi_nor *nor) { - return !!nor->params->erase_map.uniform_erase_type; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + + return !!params->erase_map.uniform_erase_type; } static void spi_nor_set_4byte_opcodes(struct spi_nor *nor) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + nor->read_opcode = spi_nor_convert_3to4_read(nor->read_opcode); nor->program_opcode = spi_nor_convert_3to4_program(nor->program_opcode); nor->erase_opcode = spi_nor_convert_3to4_erase(nor->erase_opcode); if (!spi_nor_has_uniform_erase(nor)) { - struct spi_nor_erase_map *map = &nor->params->erase_map; + struct spi_nor_erase_map *map = ¶ms->erase_map; struct spi_nor_erase_type *erase; int i; @@ -1301,6 +1308,7 @@ void spi_nor_unlock_and_unprep(struct spi_nor *nor) /* Internal locking helpers for program and erase operations */ static bool spi_nor_rww_start_pe(struct spi_nor *nor, loff_t start, size_t len) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); struct spi_nor_rww *rww = &nor->rww; unsigned int used_banks = 0; bool started = false; @@ -1312,7 +1320,7 @@ static bool spi_nor_rww_start_pe(struct spi_nor *nor, loff_t start, size_t len) if (rww->ongoing_io || rww->ongoing_rd || rww->ongoing_pe) goto busy; - spi_nor_offset_to_banks(nor->params->bank_size, start, len, &first, &last); + spi_nor_offset_to_banks(params->bank_size, start, len, &first, &last); for (bank = first; bank <= last; bank++) { if (rww->used_banks & BIT(bank)) goto busy; @@ -1331,13 +1339,14 @@ static bool spi_nor_rww_start_pe(struct spi_nor *nor, loff_t start, size_t len) static void spi_nor_rww_end_pe(struct spi_nor *nor, loff_t start, size_t len) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); struct spi_nor_rww *rww = &nor->rww; u8 first, last; int bank; mutex_lock(&nor->lock); - spi_nor_offset_to_banks(nor->params->bank_size, start, len, &first, &last); + spi_nor_offset_to_banks(params->bank_size, start, len, &first, &last); for (bank = first; bank <= last; bank++) rww->used_banks &= ~BIT(bank); @@ -1378,6 +1387,7 @@ static void spi_nor_unlock_and_unprep_pe(struct spi_nor *nor, loff_t start, size /* Internal locking helpers for read operations */ static bool spi_nor_rww_start_rd(struct spi_nor *nor, loff_t start, size_t len) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); struct spi_nor_rww *rww = &nor->rww; unsigned int used_banks = 0; bool started = false; @@ -1389,7 +1399,7 @@ static bool spi_nor_rww_start_rd(struct spi_nor *nor, loff_t start, size_t len) if (rww->ongoing_io || rww->ongoing_rd) goto busy; - spi_nor_offset_to_banks(nor->params->bank_size, start, len, &first, &last); + spi_nor_offset_to_banks(params->bank_size, start, len, &first, &last); for (bank = first; bank <= last; bank++) { if (rww->used_banks & BIT(bank)) goto busy; @@ -1409,13 +1419,14 @@ static bool spi_nor_rww_start_rd(struct spi_nor *nor, loff_t start, size_t len) static void spi_nor_rww_end_rd(struct spi_nor *nor, loff_t start, size_t len) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); struct spi_nor_rww *rww = &nor->rww; u8 first, last; int bank; mutex_lock(&nor->lock); - spi_nor_offset_to_banks(nor->params->bank_size, start, len, &first, &last); + spi_nor_offset_to_banks(params->bank_size, start, len, &first, &last); for (bank = first; bank <= last; bank++) nor->rww.used_banks &= ~BIT(bank); @@ -1456,10 +1467,12 @@ static void spi_nor_unlock_and_unprep_rd(struct spi_nor *nor, loff_t start, size static u32 spi_nor_convert_addr(struct spi_nor *nor, loff_t addr) { - if (!nor->params->convert_addr) + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + + if (!params->convert_addr) return addr; - return nor->params->convert_addr(nor, addr); + return params->convert_addr(nor, addr); } /* @@ -1679,7 +1692,8 @@ static int spi_nor_init_erase_cmd_list(struct spi_nor *nor, struct list_head *erase_list, u64 addr, u32 len) { - const struct spi_nor_erase_map *map = &nor->params->erase_map; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + const struct spi_nor_erase_map *map = ¶ms->erase_map; const struct spi_nor_erase_type *erase, *prev_erase = NULL; struct spi_nor_erase_region *region; struct spi_nor_erase_command *cmd = NULL; @@ -2131,9 +2145,10 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf) { struct spi_nor *nor = mtd_to_spi_nor(mtd); + struct spi_nor_flash_parameter *params; size_t page_offset, page_remain, i; ssize_t ret; - u32 page_size = nor->params->page_size; + u32 page_size; dev_dbg(nor->dev, "to 0x%08x, len %zd\n", (u32)to, len); @@ -2141,6 +2156,9 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len, if (ret) return ret; + params = spi_nor_get_params(nor, 0); + page_size = params->page_size; + for (i = 0; i < len; ) { ssize_t written; loff_t addr = to + i; @@ -2296,6 +2314,8 @@ int spi_nor_hwcaps_pp2cmd(u32 hwcaps) static int spi_nor_spimem_check_op(struct spi_nor *nor, struct spi_mem_op *op) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + /* * First test with 4 address bytes. The opcode itself might * be a 3B addressing opcode but we don't care, because @@ -2304,7 +2324,7 @@ static int spi_nor_spimem_check_op(struct spi_nor *nor, */ op->addr.nbytes = 4; if (!spi_mem_supports_op(nor->spimem, op)) { - if (nor->params->size > SZ_16M) + if (params->size > SZ_16M) return -EOPNOTSUPP; /* If flash size <= 16MB, 3 address bytes are sufficient */ @@ -2368,7 +2388,7 @@ static int spi_nor_spimem_check_pp(struct spi_nor *nor, static void spi_nor_spimem_adjust_hwcaps(struct spi_nor *nor, u32 *hwcaps) { - struct spi_nor_flash_parameter *params = nor->params; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); unsigned int cap; /* X-X-X modes are not supported yet, mask them all. */ @@ -2469,6 +2489,7 @@ static int spi_nor_select_read(struct spi_nor *nor, u32 shared_hwcaps) { int cmd, best_match = fls(shared_hwcaps & SNOR_HWCAPS_READ_MASK) - 1; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); const struct spi_nor_read_command *read; if (best_match < 0) @@ -2478,7 +2499,7 @@ static int spi_nor_select_read(struct spi_nor *nor, if (cmd < 0) return -EINVAL; - read = &nor->params->reads[cmd]; + read = ¶ms->reads[cmd]; nor->read_opcode = read->opcode; nor->read_proto = read->proto; @@ -2499,6 +2520,7 @@ static int spi_nor_select_read(struct spi_nor *nor, static int spi_nor_select_pp(struct spi_nor *nor, u32 shared_hwcaps) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); int cmd, best_match = fls(shared_hwcaps & SNOR_HWCAPS_PP_MASK) - 1; const struct spi_nor_pp_command *pp; @@ -2509,7 +2531,7 @@ static int spi_nor_select_pp(struct spi_nor *nor, if (cmd < 0) return -EINVAL; - pp = &nor->params->page_programs[cmd]; + pp = ¶ms->page_programs[cmd]; nor->program_opcode = pp->opcode; nor->write_proto = pp->proto; return 0; @@ -2578,7 +2600,8 @@ spi_nor_select_uniform_erase(struct spi_nor_erase_map *map, static int spi_nor_select_erase(struct spi_nor *nor) { - struct spi_nor_erase_map *map = &nor->params->erase_map; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + struct spi_nor_erase_map *map = ¶ms->erase_map; const struct spi_nor_erase_type *erase = NULL; struct mtd_info *mtd = &nor->mtd; u32 wanted_size = nor->info->sector_size; @@ -2627,7 +2650,7 @@ static int spi_nor_select_erase(struct spi_nor *nor) static int spi_nor_default_setup(struct spi_nor *nor, const struct spi_nor_hwcaps *hwcaps) { - struct spi_nor_flash_parameter *params = nor->params; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); u32 ignored_mask, shared_mask; int err; @@ -2687,8 +2710,10 @@ static int spi_nor_default_setup(struct spi_nor *nor, static int spi_nor_set_addr_nbytes(struct spi_nor *nor) { - if (nor->params->addr_nbytes) { - nor->addr_nbytes = nor->params->addr_nbytes; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + + if (params->addr_nbytes) { + nor->addr_nbytes = params->addr_nbytes; } else if (nor->read_proto == SNOR_PROTO_8_8_8_DTR) { /* * In 8D-8D-8D mode, one byte takes half a cycle to transfer. So @@ -2709,7 +2734,7 @@ static int spi_nor_set_addr_nbytes(struct spi_nor *nor) nor->addr_nbytes = 3; } - if (nor->addr_nbytes == 3 && nor->params->size > 0x1000000) { + if (nor->addr_nbytes == 3 && params->size > 0x1000000) { /* enable 4-byte addressing if the device exceeds 16MiB */ nor->addr_nbytes = 4; } @@ -2731,10 +2756,11 @@ static int spi_nor_set_addr_nbytes(struct spi_nor *nor) static int spi_nor_setup(struct spi_nor *nor, const struct spi_nor_hwcaps *hwcaps) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); int ret; - if (nor->params->setup) - ret = nor->params->setup(nor, hwcaps); + if (params->setup) + ret = params->setup(nor, hwcaps); else ret = spi_nor_default_setup(nor, hwcaps); if (ret) @@ -2769,7 +2795,7 @@ static void spi_nor_manufacturer_init_params(struct spi_nor *nor) */ static void spi_nor_no_sfdp_init_params(struct spi_nor *nor) { - struct spi_nor_flash_parameter *params = nor->params; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); struct spi_nor_erase_map *map = ¶ms->erase_map; const u8 no_sfdp_flags = nor->info->no_sfdp_flags; u8 i, erase_mask; @@ -2898,7 +2924,7 @@ static void spi_nor_init_fixup_flags(struct spi_nor *nor) */ static void spi_nor_late_init_params(struct spi_nor *nor) { - struct spi_nor_flash_parameter *params = nor->params; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); if (nor->manufacturer && nor->manufacturer->fixups && nor->manufacturer->fixups->late_init) @@ -2918,10 +2944,10 @@ static void spi_nor_late_init_params(struct spi_nor *nor) * NOR protection support. When locking_ops are not provided, we pick * the default ones. */ - if (nor->flags & SNOR_F_HAS_LOCK && !nor->params->locking_ops) + if (nor->flags & SNOR_F_HAS_LOCK && !params->locking_ops) spi_nor_init_default_locking_ops(nor); - nor->params->bank_size = div64_u64(nor->params->size, nor->info->n_banks); + params->bank_size = div64_u64(params->size, nor->info->n_banks); } /** @@ -2934,12 +2960,13 @@ static void spi_nor_late_init_params(struct spi_nor *nor) */ static void spi_nor_sfdp_init_params_deprecated(struct spi_nor *nor) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); struct spi_nor_flash_parameter sfdp_params; - memcpy(&sfdp_params, nor->params, sizeof(sfdp_params)); + memcpy(&sfdp_params, params, sizeof(sfdp_params)); if (spi_nor_parse_sfdp(nor)) { - memcpy(nor->params, &sfdp_params, sizeof(*nor->params)); + memcpy(params, &sfdp_params, sizeof(*params)); nor->flags &= ~SNOR_F_4B_OPCODES; } } @@ -2974,7 +3001,7 @@ static void spi_nor_init_params_deprecated(struct spi_nor *nor) */ static void spi_nor_init_default_params(struct spi_nor *nor) { - struct spi_nor_flash_parameter *params = nor->params; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); const struct flash_info *info = nor->info; struct device_node *np = spi_nor_get_flash_node(nor); @@ -3059,12 +3086,15 @@ static void spi_nor_init_default_params(struct spi_nor *nor) */ static int spi_nor_init_params(struct spi_nor *nor) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); int ret; - nor->params = devm_kzalloc(nor->dev, sizeof(*nor->params), GFP_KERNEL); - if (!nor->params) + params = devm_kzalloc(nor->dev, sizeof(*params), GFP_KERNEL); + if (!params) return -ENOMEM; + spi_nor_set_params(nor, 0, params); + spi_nor_init_default_params(nor); if (nor->info->parse_sfdp) { @@ -3092,9 +3122,10 @@ static int spi_nor_init_params(struct spi_nor *nor) */ static int spi_nor_octal_dtr_enable(struct spi_nor *nor, bool enable) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); int ret; - if (!nor->params->octal_dtr_enable) + if (!params->octal_dtr_enable) return 0; if (!(nor->read_proto == SNOR_PROTO_8_8_8_DTR && @@ -3104,7 +3135,7 @@ static int spi_nor_octal_dtr_enable(struct spi_nor *nor, bool enable) if (!(nor->flags & SNOR_F_IO_MODE_EN_VOLATILE)) return 0; - ret = nor->params->octal_dtr_enable(nor, enable); + ret = params->octal_dtr_enable(nor, enable); if (ret) return ret; @@ -3124,14 +3155,16 @@ static int spi_nor_octal_dtr_enable(struct spi_nor *nor, bool enable) */ static int spi_nor_quad_enable(struct spi_nor *nor) { - if (!nor->params->quad_enable) + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + + if (!params->quad_enable) return 0; if (!(spi_nor_get_protocol_width(nor->read_proto) == 4 || spi_nor_get_protocol_width(nor->write_proto) == 4)) return 0; - return nor->params->quad_enable(nor); + return params->quad_enable(nor); } /** @@ -3143,7 +3176,7 @@ static int spi_nor_quad_enable(struct spi_nor *nor) */ int spi_nor_set_4byte_addr_mode(struct spi_nor *nor, bool enable) { - struct spi_nor_flash_parameter *params = nor->params; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); int ret; ret = params->set_4byte_addr_mode(nor, enable); @@ -3396,6 +3429,7 @@ static const struct flash_info *spi_nor_get_flash_info(struct spi_nor *nor, static void spi_nor_set_mtd_info(struct spi_nor *nor) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); struct mtd_info *mtd = &nor->mtd; struct device *dev = nor->dev; @@ -3414,9 +3448,9 @@ static void spi_nor_set_mtd_info(struct spi_nor *nor) mtd->flags |= MTD_NO_ERASE; else mtd->_erase = spi_nor_erase; - mtd->writesize = nor->params->writesize; - mtd->writebufsize = nor->params->page_size; - mtd->size = nor->params->size; + mtd->writesize = params->writesize; + mtd->writebufsize = params->page_size; + mtd->size = params->size; mtd->_read = spi_nor_read; /* Might be already set by some SST flashes. */ if (!mtd->_write) @@ -3470,7 +3504,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, * We need the bounce buffer early to read/write registers when going * through the spi-mem layer (buffers have to be DMA-able). * For spi-mem drivers, we'll reallocate a new buffer if - * nor->params->page_size turns out to be greater than PAGE_SIZE (which + * params->page_size turns out to be greater than PAGE_SIZE (which * shouldn't happen before long since NOR pages are usually less * than 1KB) after spi_nor_scan() returns. */ @@ -3544,13 +3578,14 @@ EXPORT_SYMBOL_GPL(spi_nor_scan); static int spi_nor_create_read_dirmap(struct spi_nor *nor) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); struct spi_mem_dirmap_info info = { .op_tmpl = SPI_MEM_OP(SPI_MEM_OP_CMD(nor->read_opcode, 0), SPI_MEM_OP_ADDR(nor->addr_nbytes, 0, 0), SPI_MEM_OP_DUMMY(nor->read_dummy, 0), SPI_MEM_OP_DATA_IN(0, NULL, 0)), .offset = 0, - .length = nor->params->size, + .length = params->size, }; struct spi_mem_op *op = &info.op_tmpl; @@ -3575,13 +3610,14 @@ static int spi_nor_create_read_dirmap(struct spi_nor *nor) static int spi_nor_create_write_dirmap(struct spi_nor *nor) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); struct spi_mem_dirmap_info info = { .op_tmpl = SPI_MEM_OP(SPI_MEM_OP_CMD(nor->program_opcode, 0), SPI_MEM_OP_ADDR(nor->addr_nbytes, 0, 0), SPI_MEM_OP_NO_DUMMY, SPI_MEM_OP_DATA_OUT(0, NULL, 0)), .offset = 0, - .length = nor->params->size, + .length = params->size, }; struct spi_mem_op *op = &info.op_tmpl; @@ -3604,6 +3640,7 @@ static int spi_nor_create_write_dirmap(struct spi_nor *nor) static int spi_nor_probe(struct spi_mem *spimem) { + struct spi_nor_flash_parameter *params; struct spi_device *spi = spimem->spi; struct flash_platform_data *data = dev_get_platdata(&spi->dev); struct spi_nor *nor; @@ -3650,13 +3687,15 @@ static int spi_nor_probe(struct spi_mem *spimem) spi_nor_debugfs_register(nor); + params = spi_nor_get_params(nor, 0); + /* * None of the existing parts have > 512B pages, but let's play safe * and add this logic so that if anyone ever adds support for such * a NOR we don't end up with buffer overflows. */ - if (nor->params->page_size > PAGE_SIZE) { - nor->bouncebuf_size = nor->params->page_size; + if (params->page_size > PAGE_SIZE) { + nor->bouncebuf_size = params->page_size; devm_kfree(nor->dev, nor->bouncebuf); nor->bouncebuf = devm_kmalloc(nor->dev, nor->bouncebuf_size, diff --git a/drivers/mtd/spi-nor/debugfs.c b/drivers/mtd/spi-nor/debugfs.c index e11536fffe0f..304a24a69e01 100644 --- a/drivers/mtd/spi-nor/debugfs.c +++ b/drivers/mtd/spi-nor/debugfs.c @@ -75,7 +75,7 @@ static void spi_nor_print_flags(struct seq_file *s, unsigned long flags, static int spi_nor_params_show(struct seq_file *s, void *data) { struct spi_nor *nor = s->private; - struct spi_nor_flash_parameter *params = nor->params; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); struct spi_nor_erase_map *erase_map = ¶ms->erase_map; struct spi_nor_erase_region *region; const struct flash_info *info = nor->info; @@ -183,7 +183,7 @@ static void spi_nor_print_pp_cmd(struct seq_file *s, static int spi_nor_capabilities_show(struct seq_file *s, void *data) { struct spi_nor *nor = s->private; - struct spi_nor_flash_parameter *params = nor->params; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); u32 hwcaps = params->hwcaps.mask; int i, cmd; diff --git a/drivers/mtd/spi-nor/gigadevice.c b/drivers/mtd/spi-nor/gigadevice.c index d57ddaf1525b..643f131d3916 100644 --- a/drivers/mtd/spi-nor/gigadevice.c +++ b/drivers/mtd/spi-nor/gigadevice.c @@ -13,6 +13,8 @@ gd25q256_post_bfpt(struct spi_nor *nor, const struct sfdp_parameter_header *bfpt_header, const struct sfdp_bfpt *bfpt) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + /* * GD25Q256C supports the first version of JESD216 which does not define * the Quad Enable methods. Overwrite the default Quad Enable method. @@ -24,7 +26,7 @@ gd25q256_post_bfpt(struct spi_nor *nor, */ if (bfpt_header->major == SFDP_JESD216_MAJOR && bfpt_header->minor == SFDP_JESD216_MINOR) - nor->params->quad_enable = spi_nor_sr1_bit6_quad_enable; + params->quad_enable = spi_nor_sr1_bit6_quad_enable; return 0; } diff --git a/drivers/mtd/spi-nor/issi.c b/drivers/mtd/spi-nor/issi.c index 400e2b42f45a..7785ba347526 100644 --- a/drivers/mtd/spi-nor/issi.c +++ b/drivers/mtd/spi-nor/issi.c @@ -13,6 +13,8 @@ is25lp256_post_bfpt_fixups(struct spi_nor *nor, const struct sfdp_parameter_header *bfpt_header, const struct sfdp_bfpt *bfpt) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + /* * IS25LP256 supports 4B opcodes, but the BFPT advertises * BFPT_DWORD1_ADDRESS_BYTES_3_ONLY. @@ -20,7 +22,7 @@ is25lp256_post_bfpt_fixups(struct spi_nor *nor, */ if ((bfpt->dwords[SFDP_DWORD(1)] & BFPT_DWORD1_ADDRESS_BYTES_MASK) == BFPT_DWORD1_ADDRESS_BYTES_3_ONLY) - nor->params->addr_nbytes = 4; + params->addr_nbytes = 4; return 0; } @@ -31,7 +33,8 @@ static const struct spi_nor_fixups is25lp256_fixups = { static void pm25lv_nor_late_init(struct spi_nor *nor) { - struct spi_nor_erase_map *map = &nor->params->erase_map; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + struct spi_nor_erase_map *map = ¶ms->erase_map; int i; /* The PM25LV series has a different 4k sector erase opcode */ @@ -91,7 +94,9 @@ static const struct flash_info issi_nor_parts[] = { static void issi_nor_default_init(struct spi_nor *nor) { - nor->params->quad_enable = spi_nor_sr1_bit6_quad_enable; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + + params->quad_enable = spi_nor_sr1_bit6_quad_enable; } static const struct spi_nor_fixups issi_fixups = { diff --git a/drivers/mtd/spi-nor/macronix.c b/drivers/mtd/spi-nor/macronix.c index 04888258e891..88ddfc6ea77f 100644 --- a/drivers/mtd/spi-nor/macronix.c +++ b/drivers/mtd/spi-nor/macronix.c @@ -107,13 +107,17 @@ static const struct flash_info macronix_nor_parts[] = { static void macronix_nor_default_init(struct spi_nor *nor) { - nor->params->quad_enable = spi_nor_sr1_bit6_quad_enable; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + + params->quad_enable = spi_nor_sr1_bit6_quad_enable; } static void macronix_nor_late_init(struct spi_nor *nor) { - if (!nor->params->set_4byte_addr_mode) - nor->params->set_4byte_addr_mode = spi_nor_set_4byte_addr_mode_en4b_ex4b; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + + if (!params->set_4byte_addr_mode) + params->set_4byte_addr_mode = spi_nor_set_4byte_addr_mode_en4b_ex4b; } static const struct spi_nor_fixups macronix_nor_fixups = { diff --git a/drivers/mtd/spi-nor/micron-st.c b/drivers/mtd/spi-nor/micron-st.c index 4b919756a205..92d6b0e7512c 100644 --- a/drivers/mtd/spi-nor/micron-st.c +++ b/drivers/mtd/spi-nor/micron-st.c @@ -49,10 +49,11 @@ static int micron_st_nor_octal_dtr_en(struct spi_nor *nor) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); struct spi_mem_op op; u8 *buf = nor->bouncebuf; int ret; - u8 addr_mode_nbytes = nor->params->addr_mode_nbytes; + u8 addr_mode_nbytes = params->addr_mode_nbytes; /* Use 20 dummy cycles for memory array reads. */ *buf = 20; @@ -128,27 +129,31 @@ static int micron_st_nor_octal_dtr_enable(struct spi_nor *nor, bool enable) static void mt35xu512aba_default_init(struct spi_nor *nor) { - nor->params->octal_dtr_enable = micron_st_nor_octal_dtr_enable; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + + params->octal_dtr_enable = micron_st_nor_octal_dtr_enable; } static int mt35xu512aba_post_sfdp_fixup(struct spi_nor *nor) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + /* Set the Fast Read settings. */ - nor->params->hwcaps.mask |= SNOR_HWCAPS_READ_8_8_8_DTR; - spi_nor_set_read_settings(&nor->params->reads[SNOR_CMD_READ_8_8_8_DTR], + params->hwcaps.mask |= SNOR_HWCAPS_READ_8_8_8_DTR; + spi_nor_set_read_settings(¶ms->reads[SNOR_CMD_READ_8_8_8_DTR], 0, 20, SPINOR_OP_MT_DTR_RD, SNOR_PROTO_8_8_8_DTR); nor->cmd_ext_type = SPI_NOR_EXT_REPEAT; - nor->params->rdsr_dummy = 8; - nor->params->rdsr_addr_nbytes = 0; + params->rdsr_dummy = 8; + params->rdsr_addr_nbytes = 0; /* * The BFPT quad enable field is set to a reserved value so the quad * enable function is ignored by spi_nor_parse_bfpt(). Make sure we * disable it. */ - nor->params->quad_enable = NULL; + params->quad_enable = NULL; return 0; } @@ -314,14 +319,15 @@ static const struct flash_info st_nor_parts[] = { */ static int micron_st_nor_read_fsr(struct spi_nor *nor, u8 *fsr) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); int ret; if (nor->spimem) { struct spi_mem_op op = MICRON_ST_RDFSR_OP(fsr); if (nor->reg_proto == SNOR_PROTO_8_8_8_DTR) { - op.addr.nbytes = nor->params->rdsr_addr_nbytes; - op.dummy.nbytes = nor->params->rdsr_dummy; + op.addr.nbytes = params->rdsr_addr_nbytes; + op.dummy.nbytes = params->rdsr_dummy; /* * We don't want to read only one byte in DTR mode. So, * read 2 and then discard the second byte. @@ -424,14 +430,16 @@ static int micron_st_nor_ready(struct spi_nor *nor) static void micron_st_nor_default_init(struct spi_nor *nor) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + nor->flags |= SNOR_F_HAS_LOCK; nor->flags &= ~SNOR_F_HAS_16BIT_SR; - nor->params->quad_enable = NULL; + params->quad_enable = NULL; } static void micron_st_nor_late_init(struct spi_nor *nor) { - struct spi_nor_flash_parameter *params = nor->params; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); if (nor->info->mfr_flags & USE_FSR) params->ready = micron_st_nor_ready; diff --git a/drivers/mtd/spi-nor/otp.c b/drivers/mtd/spi-nor/otp.c index 23fe75ddc9cf..16a9a0375aeb 100644 --- a/drivers/mtd/spi-nor/otp.c +++ b/drivers/mtd/spi-nor/otp.c @@ -19,7 +19,9 @@ */ static inline unsigned int spi_nor_otp_region_len(struct spi_nor *nor) { - return nor->params->otp.org->len; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + + return params->otp.org->len; } /** @@ -30,7 +32,9 @@ static inline unsigned int spi_nor_otp_region_len(struct spi_nor *nor) */ static inline unsigned int spi_nor_otp_n_regions(struct spi_nor *nor) { - return nor->params->otp.org->n_regions; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + + return params->otp.org->n_regions; } /** @@ -241,7 +245,8 @@ int spi_nor_otp_is_locked_sr2(struct spi_nor *nor, unsigned int region) static loff_t spi_nor_otp_region_start(const struct spi_nor *nor, unsigned int region) { - const struct spi_nor_otp_organization *org = nor->params->otp.org; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + const struct spi_nor_otp_organization *org = params->otp.org; return org->base + region * org->offset; } @@ -266,7 +271,8 @@ static int spi_nor_mtd_otp_info(struct mtd_info *mtd, size_t len, size_t *retlen, struct otp_info *buf) { struct spi_nor *nor = mtd_to_spi_nor(mtd); - const struct spi_nor_otp_ops *ops = nor->params->otp.ops; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + const struct spi_nor_otp_ops *ops = params->otp.ops; unsigned int n_regions = spi_nor_otp_n_regions(nor); unsigned int i; int ret, locked; @@ -303,7 +309,8 @@ static int spi_nor_mtd_otp_info(struct mtd_info *mtd, size_t len, static int spi_nor_mtd_otp_range_is_locked(struct spi_nor *nor, loff_t ofs, size_t len) { - const struct spi_nor_otp_ops *ops = nor->params->otp.ops; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + const struct spi_nor_otp_ops *ops = params->otp.ops; unsigned int region; int locked; @@ -328,7 +335,8 @@ static int spi_nor_mtd_otp_read_write(struct mtd_info *mtd, loff_t ofs, const u8 *buf, bool is_write) { struct spi_nor *nor = mtd_to_spi_nor(mtd); - const struct spi_nor_otp_ops *ops = nor->params->otp.ops; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + const struct spi_nor_otp_ops *ops = params->otp.ops; const size_t rlen = spi_nor_otp_region_len(nor); loff_t rstart, rofs; unsigned int region; @@ -414,7 +422,8 @@ static int spi_nor_mtd_otp_write(struct mtd_info *mtd, loff_t to, size_t len, static int spi_nor_mtd_otp_erase(struct mtd_info *mtd, loff_t from, size_t len) { struct spi_nor *nor = mtd_to_spi_nor(mtd); - const struct spi_nor_otp_ops *ops = nor->params->otp.ops; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + const struct spi_nor_otp_ops *ops = params->otp.ops; const size_t rlen = spi_nor_otp_region_len(nor); unsigned int region; loff_t rstart; @@ -467,7 +476,8 @@ static int spi_nor_mtd_otp_erase(struct mtd_info *mtd, loff_t from, size_t len) static int spi_nor_mtd_otp_lock(struct mtd_info *mtd, loff_t from, size_t len) { struct spi_nor *nor = mtd_to_spi_nor(mtd); - const struct spi_nor_otp_ops *ops = nor->params->otp.ops; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + const struct spi_nor_otp_ops *ops = params->otp.ops; const size_t rlen = spi_nor_otp_region_len(nor); unsigned int region; int ret; @@ -501,9 +511,10 @@ static int spi_nor_mtd_otp_lock(struct mtd_info *mtd, loff_t from, size_t len) void spi_nor_set_mtd_otp_ops(struct spi_nor *nor) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); struct mtd_info *mtd = &nor->mtd; - if (!nor->params->otp.ops) + if (!params->otp.ops) return; if (WARN_ON(!is_power_of_2(spi_nor_otp_region_len(nor)))) diff --git a/drivers/mtd/spi-nor/sfdp.c b/drivers/mtd/spi-nor/sfdp.c index b3b11dfed789..f7137c100569 100644 --- a/drivers/mtd/spi-nor/sfdp.c +++ b/drivers/mtd/spi-nor/sfdp.c @@ -436,7 +436,7 @@ static void spi_nor_regions_sort_erase_types(struct spi_nor_erase_map *map) static int spi_nor_parse_bfpt(struct spi_nor *nor, const struct sfdp_parameter_header *bfpt_header) { - struct spi_nor_flash_parameter *params = nor->params; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); struct spi_nor_erase_map *map = ¶ms->erase_map; struct spi_nor_erase_type *erase_type = map->erase_type; struct sfdp_bfpt bfpt; @@ -661,6 +661,8 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor, */ static u8 spi_nor_smpt_addr_nbytes(const struct spi_nor *nor, const u32 settings) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + switch (settings & SMPT_CMD_ADDRESS_LEN_MASK) { case SMPT_CMD_ADDRESS_LEN_0: return 0; @@ -670,7 +672,7 @@ static u8 spi_nor_smpt_addr_nbytes(const struct spi_nor *nor, const u32 settings return 4; case SMPT_CMD_ADDRESS_LEN_USE_CURRENT: default: - return nor->params->addr_mode_nbytes; + return params->addr_mode_nbytes; } } @@ -822,7 +824,8 @@ spi_nor_region_check_overlay(struct spi_nor_erase_region *region, static int spi_nor_init_non_uniform_erase_map(struct spi_nor *nor, const u32 *smpt) { - struct spi_nor_erase_map *map = &nor->params->erase_map; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + struct spi_nor_erase_map *map = ¶ms->erase_map; struct spi_nor_erase_type *erase = map->erase_type; struct spi_nor_erase_region *region; u64 offset; @@ -910,6 +913,7 @@ static int spi_nor_init_non_uniform_erase_map(struct spi_nor *nor, static int spi_nor_parse_smpt(struct spi_nor *nor, const struct sfdp_parameter_header *smpt_header) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); const u32 *sector_map; u32 *smpt; size_t len; @@ -940,7 +944,7 @@ static int spi_nor_parse_smpt(struct spi_nor *nor, if (ret) goto out; - spi_nor_regions_sort_erase_types(&nor->params->erase_map); + spi_nor_regions_sort_erase_types(¶ms->erase_map); /* fall through */ out: kfree(smpt); @@ -980,7 +984,7 @@ static int spi_nor_parse_4bait(struct spi_nor *nor, { 0u /* not used */, BIT(11) }, { 0u /* not used */, BIT(12) }, }; - struct spi_nor_flash_parameter *params = nor->params; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); struct spi_nor_pp_command *params_pp = params->page_programs; struct spi_nor_erase_map *map = ¶ms->erase_map; struct spi_nor_erase_type *erase_type = map->erase_type; @@ -1143,6 +1147,7 @@ static int spi_nor_parse_4bait(struct spi_nor *nor, static int spi_nor_parse_profile1(struct spi_nor *nor, const struct sfdp_parameter_header *profile1_header) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); u32 *dwords, addr; size_t len; int ret; @@ -1165,14 +1170,14 @@ static int spi_nor_parse_profile1(struct spi_nor *nor, /* Set the Read Status Register dummy cycles and dummy address bytes. */ if (dwords[SFDP_DWORD(1)] & PROFILE1_DWORD1_RDSR_DUMMY) - nor->params->rdsr_dummy = 8; + params->rdsr_dummy = 8; else - nor->params->rdsr_dummy = 4; + params->rdsr_dummy = 4; if (dwords[SFDP_DWORD(1)] & PROFILE1_DWORD1_RDSR_ADDR_BYTES) - nor->params->rdsr_addr_nbytes = 4; + params->rdsr_addr_nbytes = 4; else - nor->params->rdsr_addr_nbytes = 0; + params->rdsr_addr_nbytes = 0; /* * We don't know what speed the controller is running at. Find the @@ -1201,8 +1206,8 @@ static int spi_nor_parse_profile1(struct spi_nor *nor, dummy = round_up(dummy, 2); /* Update the fast read settings. */ - nor->params->hwcaps.mask |= SNOR_HWCAPS_READ_8_8_8_DTR; - spi_nor_set_read_settings(&nor->params->reads[SNOR_CMD_READ_8_8_8_DTR], + params->hwcaps.mask |= SNOR_HWCAPS_READ_8_8_8_DTR; + spi_nor_set_read_settings(¶ms->reads[SNOR_CMD_READ_8_8_8_DTR], 0, dummy, opcode, SNOR_PROTO_8_8_8_DTR); @@ -1210,7 +1215,7 @@ static int spi_nor_parse_profile1(struct spi_nor *nor, * Page Program is "Required Command" in the xSPI Profile 1.0. Update * the params->hwcaps.mask here. */ - nor->params->hwcaps.mask |= SNOR_HWCAPS_PP_8_8_8_DTR; + params->hwcaps.mask |= SNOR_HWCAPS_PP_8_8_8_DTR; out: kfree(dwords); @@ -1231,7 +1236,7 @@ static int spi_nor_parse_profile1(struct spi_nor *nor, static int spi_nor_parse_sccr(struct spi_nor *nor, const struct sfdp_parameter_header *sccr_header) { - struct spi_nor_flash_parameter *params = nor->params; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); u32 *dwords, addr; size_t len; int ret; @@ -1282,7 +1287,7 @@ static int spi_nor_parse_sccr(struct spi_nor *nor, static int spi_nor_parse_sccr_mc(struct spi_nor *nor, const struct sfdp_parameter_header *sccr_mc_header) { - struct spi_nor_flash_parameter *params = nor->params; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); u32 *dwords, addr; u8 i, n_dice; size_t len; diff --git a/drivers/mtd/spi-nor/spansion.c b/drivers/mtd/spi-nor/spansion.c index 15f9a80c10b9..fdbc428c49dd 100644 --- a/drivers/mtd/spi-nor/spansion.c +++ b/drivers/mtd/spi-nor/spansion.c @@ -88,8 +88,9 @@ static void spansion_nor_clear_sr(struct spi_nor *nor) static int cypress_nor_sr_ready_and_clear_reg(struct spi_nor *nor, u64 addr) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); struct spi_mem_op op = - CYPRESS_NOR_RD_ANY_REG_OP(nor->params->addr_mode_nbytes, addr, + CYPRESS_NOR_RD_ANY_REG_OP(params->addr_mode_nbytes, addr, 0, nor->bouncebuf); int ret; @@ -124,7 +125,7 @@ static int cypress_nor_sr_ready_and_clear_reg(struct spi_nor *nor, u64 addr) */ static int cypress_nor_sr_ready_and_clear(struct spi_nor *nor) { - struct spi_nor_flash_parameter *params = nor->params; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); u64 addr; int ret; u8 i; @@ -143,10 +144,11 @@ static int cypress_nor_sr_ready_and_clear(struct spi_nor *nor) static int cypress_nor_octal_dtr_en(struct spi_nor *nor) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); struct spi_mem_op op; u8 *buf = nor->bouncebuf; int ret; - u8 addr_mode_nbytes = nor->params->addr_mode_nbytes; + u8 addr_mode_nbytes = params->addr_mode_nbytes; /* Use 24 dummy cycles for memory array reads. */ *buf = SPINOR_REG_CYPRESS_CFR2_MEMLAT_11_24; @@ -219,8 +221,9 @@ static int cypress_nor_octal_dtr_dis(struct spi_nor *nor) static int cypress_nor_quad_enable_volatile_reg(struct spi_nor *nor, u64 addr) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); struct spi_mem_op op; - u8 addr_mode_nbytes = nor->params->addr_mode_nbytes; + u8 addr_mode_nbytes = params->addr_mode_nbytes; u8 cfr1v_written; int ret; @@ -278,7 +281,7 @@ static int cypress_nor_quad_enable_volatile_reg(struct spi_nor *nor, u64 addr) */ static int cypress_nor_quad_enable_volatile(struct spi_nor *nor) { - struct spi_nor_flash_parameter *params = nor->params; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); u64 addr; u8 i; int ret; @@ -361,6 +364,7 @@ static int cypress_nor_determine_addr_mode_by_sr1(struct spi_nor *nor, */ static int cypress_nor_set_addr_mode_nbytes(struct spi_nor *nor) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); struct spi_mem_op op; u8 addr_mode; int ret; @@ -402,16 +406,17 @@ static int cypress_nor_set_addr_mode_nbytes(struct spi_nor *nor) return spi_nor_set_4byte_addr_mode(nor, true); } - nor->params->addr_nbytes = addr_mode; - nor->params->addr_mode_nbytes = addr_mode; + params->addr_nbytes = addr_mode; + params->addr_mode_nbytes = addr_mode; return 0; } static int cypress_nor_get_page_size_single_chip(struct spi_nor *nor) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); struct spi_mem_op op = - CYPRESS_NOR_RD_ANY_REG_OP(nor->params->addr_mode_nbytes, + CYPRESS_NOR_RD_ANY_REG_OP(params->addr_mode_nbytes, SPINOR_REG_CYPRESS_CFR3V, 0, nor->bouncebuf); int ret; @@ -421,9 +426,9 @@ static int cypress_nor_get_page_size_single_chip(struct spi_nor *nor) return ret; if (nor->bouncebuf[0] & SPINOR_REG_CYPRESS_CFR3_PGSZ) - nor->params->page_size = 512; + params->page_size = 512; else - nor->params->page_size = 256; + params->page_size = 256; return 0; } @@ -431,10 +436,10 @@ static int cypress_nor_get_page_size_single_chip(struct spi_nor *nor) static int cypress_nor_get_page_size_mcp(struct spi_nor *nor) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); struct spi_mem_op op = - CYPRESS_NOR_RD_ANY_REG_OP(nor->params->addr_mode_nbytes, + CYPRESS_NOR_RD_ANY_REG_OP(params->addr_mode_nbytes, 0, 0, nor->bouncebuf); - struct spi_nor_flash_parameter *params = nor->params; int ret; u8 i; @@ -471,19 +476,23 @@ static int cypress_nor_get_page_size_mcp(struct spi_nor *nor) */ static int cypress_nor_get_page_size(struct spi_nor *nor) { - if (nor->params->n_dice) + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + + if (params->n_dice) return cypress_nor_get_page_size_mcp(nor); return cypress_nor_get_page_size_single_chip(nor); } static void cypress_nor_ecc_init(struct spi_nor *nor) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + /* * Programming is supported only in 16-byte ECC data unit granularity. * Byte-programming, bit-walking, or multiple program operations to the * same ECC data unit without an erase are not allowed. */ - nor->params->writesize = 16; + params->writesize = 16; nor->flags |= SNOR_F_ECC; } @@ -492,6 +501,7 @@ s25fs256t_post_bfpt_fixup(struct spi_nor *nor, const struct sfdp_parameter_header *bfpt_header, const struct sfdp_bfpt *bfpt) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); struct spi_mem_op op; int ret; @@ -501,7 +511,7 @@ s25fs256t_post_bfpt_fixup(struct spi_nor *nor, /* Read Architecture Configuration Register (ARCFN) */ op = (struct spi_mem_op) - CYPRESS_NOR_RD_ANY_REG_OP(nor->params->addr_mode_nbytes, + CYPRESS_NOR_RD_ANY_REG_OP(params->addr_mode_nbytes, SPINOR_REG_CYPRESS_ARCFN, 1, nor->bouncebuf); ret = spi_nor_read_any_reg(nor, &op, nor->reg_proto); @@ -517,7 +527,7 @@ s25fs256t_post_bfpt_fixup(struct spi_nor *nor, static int s25fs256t_post_sfdp_fixup(struct spi_nor *nor) { - struct spi_nor_flash_parameter *params = nor->params; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); /* PP_1_1_4_4B is supported but missing in 4BAIT. */ params->hwcaps.mask |= SNOR_HWCAPS_PP_1_1_4; @@ -545,21 +555,23 @@ s25hx_t_post_bfpt_fixup(struct spi_nor *nor, const struct sfdp_bfpt *bfpt) { int ret; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); ret = cypress_nor_set_addr_mode_nbytes(nor); if (ret) return ret; /* Replace Quad Enable with volatile version */ - nor->params->quad_enable = cypress_nor_quad_enable_volatile; + params->quad_enable = cypress_nor_quad_enable_volatile; return 0; } static int s25hx_t_post_sfdp_fixup(struct spi_nor *nor) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); struct spi_nor_erase_type *erase_type = - nor->params->erase_map.erase_type; + params->erase_map.erase_type; unsigned int i; /* @@ -580,15 +592,15 @@ static int s25hx_t_post_sfdp_fixup(struct spi_nor *nor) } /* The 2 Gb parts duplicate info and advertise 4 dice instead of 2. */ - if (nor->params->size == SZ_256M) - nor->params->n_dice = 2; + if (params->size == SZ_256M) + params->n_dice = 2; return cypress_nor_get_page_size(nor); } static void s25hx_t_late_init(struct spi_nor *nor) { - struct spi_nor_flash_parameter *params = nor->params; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); /* Fast Read 4B requires mode cycles */ params->reads[SNOR_CMD_READ_FAST].num_mode_clocks = 8; @@ -624,22 +636,24 @@ static int cypress_nor_octal_dtr_enable(struct spi_nor *nor, bool enable) static int s28hx_t_post_sfdp_fixup(struct spi_nor *nor) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + /* * On older versions of the flash the xSPI Profile 1.0 table has the * 8D-8D-8D Fast Read opcode as 0x00. But it actually should be 0xEE. */ - if (nor->params->reads[SNOR_CMD_READ_8_8_8_DTR].opcode == 0) - nor->params->reads[SNOR_CMD_READ_8_8_8_DTR].opcode = + if (params->reads[SNOR_CMD_READ_8_8_8_DTR].opcode == 0) + params->reads[SNOR_CMD_READ_8_8_8_DTR].opcode = SPINOR_OP_CYPRESS_RD_FAST; /* This flash is also missing the 4-byte Page Program opcode bit. */ - spi_nor_set_pp_settings(&nor->params->page_programs[SNOR_CMD_PP], + spi_nor_set_pp_settings(¶ms->page_programs[SNOR_CMD_PP], SPINOR_OP_PP_4B, SNOR_PROTO_1_1_1); /* * Since xSPI Page Program opcode is backward compatible with * Legacy SPI, use Legacy SPI opcode there as well. */ - spi_nor_set_pp_settings(&nor->params->page_programs[SNOR_CMD_PP_8_8_8_DTR], + spi_nor_set_pp_settings(¶ms->page_programs[SNOR_CMD_PP_8_8_8_DTR], SPINOR_OP_PP_4B, SNOR_PROTO_8_8_8_DTR); /* @@ -647,7 +661,7 @@ static int s28hx_t_post_sfdp_fixup(struct spi_nor *nor) * address bytes needed for Read Status Register command as 0 but the * actual value for that is 4. */ - nor->params->rdsr_addr_nbytes = 4; + params->rdsr_addr_nbytes = 4; return cypress_nor_get_page_size(nor); } @@ -667,7 +681,9 @@ static int s28hx_t_post_bfpt_fixup(struct spi_nor *nor, static void s28hx_t_late_init(struct spi_nor *nor) { - nor->params->octal_dtr_enable = cypress_nor_octal_dtr_enable; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + + params->octal_dtr_enable = cypress_nor_octal_dtr_enable; cypress_nor_ecc_init(nor); } @@ -682,13 +698,15 @@ s25fs_s_nor_post_bfpt_fixups(struct spi_nor *nor, const struct sfdp_parameter_header *bfpt_header, const struct sfdp_bfpt *bfpt) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + /* * The S25FS-S chip family reports 512-byte pages in BFPT but * in reality the write buffer still wraps at the safe default * of 256 bytes. Overwrite the page size advertised by BFPT * to get the writes working. */ - nor->params->page_size = 256; + params->page_size = 256; return 0; } @@ -878,7 +896,9 @@ static int spansion_nor_sr_ready_and_clear(struct spi_nor *nor) static void spansion_nor_late_init(struct spi_nor *nor) { - if (nor->params->size > SZ_16M) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + + if (params->size > SZ_16M) { nor->flags |= SNOR_F_4B_OPCODES; /* No small sector erase for 4-byte command set */ nor->erase_opcode = SPINOR_OP_SE; @@ -886,7 +906,7 @@ static void spansion_nor_late_init(struct spi_nor *nor) } if (nor->info->mfr_flags & USE_CLSR) - nor->params->ready = spansion_nor_sr_ready_and_clear; + params->ready = spansion_nor_sr_ready_and_clear; } static const struct spi_nor_fixups spansion_nor_fixups = { diff --git a/drivers/mtd/spi-nor/sst.c b/drivers/mtd/spi-nor/sst.c index 688eb20c763e..f6edc6c962f5 100644 --- a/drivers/mtd/spi-nor/sst.c +++ b/drivers/mtd/spi-nor/sst.c @@ -20,10 +20,11 @@ static int sst26vf_nor_lock(struct spi_nor *nor, loff_t ofs, uint64_t len) static int sst26vf_nor_unlock(struct spi_nor *nor, loff_t ofs, uint64_t len) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); int ret; /* We only support unlocking the entire flash array. */ - if (ofs != 0 || len != nor->params->size) + if (ofs != 0 || len != params->size) return -EINVAL; ret = spi_nor_read_cr(nor, nor->bouncebuf); @@ -51,7 +52,9 @@ static const struct spi_nor_locking_ops sst26vf_nor_locking_ops = { static void sst26vf_nor_late_init(struct spi_nor *nor) { - nor->params->locking_ops = &sst26vf_nor_locking_ops; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + + params->locking_ops = &sst26vf_nor_locking_ops; } static const struct spi_nor_fixups sst26vf_nor_fixups = { diff --git a/drivers/mtd/spi-nor/swp.c b/drivers/mtd/spi-nor/swp.c index 0ba716e84377..fa023c4112b1 100644 --- a/drivers/mtd/spi-nor/swp.c +++ b/drivers/mtd/spi-nor/swp.c @@ -340,11 +340,14 @@ static const struct spi_nor_locking_ops spi_nor_sr_locking_ops = { void spi_nor_init_default_locking_ops(struct spi_nor *nor) { - nor->params->locking_ops = &spi_nor_sr_locking_ops; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + + params->locking_ops = &spi_nor_sr_locking_ops; } static int spi_nor_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) { + struct spi_nor_flash_parameter *params; struct spi_nor *nor = mtd_to_spi_nor(mtd); int ret; @@ -352,7 +355,8 @@ static int spi_nor_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) if (ret) return ret; - ret = nor->params->locking_ops->lock(nor, ofs, len); + params = spi_nor_get_params(nor, 0); + ret = params->locking_ops->lock(nor, ofs, len); spi_nor_unlock_and_unprep(nor); return ret; @@ -360,6 +364,7 @@ static int spi_nor_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) static int spi_nor_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) { + struct spi_nor_flash_parameter *params; struct spi_nor *nor = mtd_to_spi_nor(mtd); int ret; @@ -367,7 +372,8 @@ static int spi_nor_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) if (ret) return ret; - ret = nor->params->locking_ops->unlock(nor, ofs, len); + params = spi_nor_get_params(nor, 0); + ret = params->locking_ops->unlock(nor, ofs, len); spi_nor_unlock_and_unprep(nor); return ret; @@ -375,6 +381,7 @@ static int spi_nor_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) static int spi_nor_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len) { + struct spi_nor_flash_parameter *params; struct spi_nor *nor = mtd_to_spi_nor(mtd); int ret; @@ -382,7 +389,8 @@ static int spi_nor_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len) if (ret) return ret; - ret = nor->params->locking_ops->is_locked(nor, ofs, len); + params = spi_nor_get_params(nor, 0); + ret = params->locking_ops->is_locked(nor, ofs, len); spi_nor_unlock_and_unprep(nor); return ret; @@ -402,6 +410,7 @@ static int spi_nor_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len) */ void spi_nor_try_unlock_all(struct spi_nor *nor) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); int ret; if (!(nor->flags & SNOR_F_HAS_LOCK)) @@ -409,16 +418,17 @@ void spi_nor_try_unlock_all(struct spi_nor *nor) dev_dbg(nor->dev, "Unprotecting entire flash array\n"); - ret = spi_nor_unlock(&nor->mtd, 0, nor->params->size); + ret = spi_nor_unlock(&nor->mtd, 0, params->size); if (ret) dev_dbg(nor->dev, "Failed to unlock the entire flash memory array\n"); } void spi_nor_set_mtd_locking_ops(struct spi_nor *nor) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); struct mtd_info *mtd = &nor->mtd; - if (!nor->params->locking_ops) + if (!params->locking_ops) return; mtd->_lock = spi_nor_lock; diff --git a/drivers/mtd/spi-nor/winbond.c b/drivers/mtd/spi-nor/winbond.c index 834d6ba5ce70..5b433b74cbdd 100644 --- a/drivers/mtd/spi-nor/winbond.c +++ b/drivers/mtd/spi-nor/winbond.c @@ -218,7 +218,7 @@ static const struct spi_nor_otp_ops winbond_nor_otp_ops = { static void winbond_nor_late_init(struct spi_nor *nor) { - struct spi_nor_flash_parameter *params = nor->params; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); if (params->otp.org->n_regions) params->otp.ops = &winbond_nor_otp_ops; diff --git a/drivers/mtd/spi-nor/xilinx.c b/drivers/mtd/spi-nor/xilinx.c index 7175de8aa336..59bec7a24fc8 100644 --- a/drivers/mtd/spi-nor/xilinx.c +++ b/drivers/mtd/spi-nor/xilinx.c @@ -56,7 +56,8 @@ static const struct flash_info xilinx_nor_parts[] = { */ static u32 s3an_nor_convert_addr(struct spi_nor *nor, u32 addr) { - u32 page_size = nor->params->page_size; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + u32 page_size = params->page_size; u32 offset, page; offset = addr % page_size; @@ -116,6 +117,7 @@ static int xilinx_nor_sr_ready(struct spi_nor *nor) static int xilinx_nor_setup(struct spi_nor *nor, const struct spi_nor_hwcaps *hwcaps) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); u32 page_size; int ret; @@ -141,14 +143,14 @@ static int xilinx_nor_setup(struct spi_nor *nor, */ if (nor->bouncebuf[0] & XSR_PAGESIZE) { /* Flash in Power of 2 mode */ - page_size = (nor->params->page_size == 264) ? 256 : 512; - nor->params->page_size = page_size; + page_size = (params->page_size == 264) ? 256 : 512; + params->page_size = page_size; nor->mtd.writebufsize = page_size; - nor->params->size = 8 * page_size * nor->info->n_sectors; + params->size = 8 * page_size * nor->info->n_sectors; nor->mtd.erasesize = 8 * page_size; } else { /* Flash in Default addressing mode */ - nor->params->convert_addr = s3an_nor_convert_addr; + params->convert_addr = s3an_nor_convert_addr; nor->mtd.erasesize = nor->info->sector_size; } @@ -157,8 +159,10 @@ static int xilinx_nor_setup(struct spi_nor *nor, static void xilinx_nor_late_init(struct spi_nor *nor) { - nor->params->setup = xilinx_nor_setup; - nor->params->ready = xilinx_nor_sr_ready; + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + + params->setup = xilinx_nor_setup; + params->ready = xilinx_nor_sr_ready; } static const struct spi_nor_fixups xilinx_nor_fixups = { diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h index cdcfe0fd2e7d..59909e7d6f53 100644 --- a/include/linux/mtd/spi-nor.h +++ b/include/linux/mtd/spi-nor.h @@ -433,6 +433,16 @@ static inline struct device_node *spi_nor_get_flash_node(struct spi_nor *nor) return mtd_get_of_node(&nor->mtd); } +static inline struct spi_nor_flash_parameter *spi_nor_get_params(const struct spi_nor *nor, u8 idx) +{ + return nor->params; +} + +static inline void spi_nor_set_params(struct spi_nor *nor, u8 idx, + struct spi_nor_flash_parameter *params) +{ + nor->params = params; +} /** * spi_nor_scan() - scan the SPI NOR * @nor: the spi_nor structure From patchwork Thu May 11 07:31:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Mahapatra, Amit Kumar" X-Patchwork-Id: 1779801 X-Patchwork-Delegate: tudor.ambarus@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=M/Eae7eK; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=QuBf9yYC; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QH3Xm4Yfrz213w for ; Thu, 11 May 2023 17:33:28 +1000 (AEST) 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=r5mr+Y3zPFy8en10v9iwNe3RFlbKTRv1gDw1g6XBpCU=; b=M/Eae7eKSfHUbf xXaY9LxGKDCCQyhtOx6AcjNQDdaHsyr+XO9y9EL80FH99nZ/gBY2lzom88EPAC/hGE1I/ZeGe99j3 6muTV0jxopj3oylMHjrv8DSexupA/5vX5ZI7WaCwdyRo1S3ZB6jIUzE+JtbGoS/3fZN9qJZbbtd03 SN/RNSCnrerueabBCJ3xLsuTOFv1apItI+fdoHEcDNxgxSR82haGPGyAs8ujIHAFre/7khRIwz+Ay 2OaRQbvyEdZR4p2oGhkkpZ4WWStQO4hgeB2P0Z+h4UFLSzV1RskSZr67eurT6n9uKuJd9PUxy0yqo 8qG64EbztSctOFqJlgvA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1px0nH-00897Z-2T; Thu, 11 May 2023 07:32:55 +0000 Received: from mail-bn8nam11on20600.outbound.protection.outlook.com ([2a01:111:f400:7eae::600] helo=NAM11-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1px0nC-00893I-0T; Thu, 11 May 2023 07:32:54 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IGvyFz4jp7J1SG2WLfZcE5tc08tNtQsaK3wOlRurooxOHsOr1QOowsg03X87e95NcJpDG9LFF7d99QSvbJ6DHk9uC4Kq7TxyiGbX6Vv5iTsgn2Ab6A8p//wAzrUiGrElWf2Z0fmf71ny/3fMPEyUBFNntkWNgAu6YNpObi6yx13Vjv3NEMKWVj/ccJUCA2bhayzxjK5/Rv5Aac2m6Y1C+JWBniV2vU4bE4guSFxnmuqQB2LpRrvZdjw4+4eMDLc9bFotVJRQaUnD4yD/a5fkSHXEpcOJW/UI0MCsVVIPzyg6MfP9Q29xSmdYVXU9t3i5I2z8WWuzHKQgao68WKRTTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Mv+ix3Z9xzH6airQ3pe6ZegdxTHbtutMl8h1Jbjk6Gw=; b=SOnYY2y/E1qH0nR/G+lrDmLL22Ivvk3Sqg0atNq/Mtrlz0LBVmZ4VaUPT6CRM1UtXyl2R9qJuiXqLolr/axg5HP3BJCMICbXd2rKh6fJopTFe4GOOVEqDV/Sw0SmYi8YFIlLiX6dYG6jvGt1os8eJhQcOdOxwC4/VEsRRuOX9NmsBdCTqSnBNah1auqcpZk5L8+QzEa0eV9DhFtxITeVTRetkaKxqxHQZXw76nWvv2sIBg78Kaa05Q3pfoxB7vc6Rwv9esN2EWQNf/ii4tYH4VY3bZN5XcfQmL6M/ZAbiP4j8/VCbJ9IAoVRYYmIaQ/8zO7Q0jL+89hb2xdEvIyzIA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Mv+ix3Z9xzH6airQ3pe6ZegdxTHbtutMl8h1Jbjk6Gw=; b=QuBf9yYCFhcGIoYuxOTl3SoQlPtw/hGW4lhTiGTRsIe9W/8QbkMrLBlk7rH+9zgGNHvlrffRV8TxuvVE2V3OTXoFdh/UykVg2n48Ww2uM8zKeKiDa0jNjAI7SqDLk6+v1JgMESduFmVPPPb5pyjA9kAVj9I2p1V68NAI8w7hnyk= Received: from BL0PR05CA0013.namprd05.prod.outlook.com (2603:10b6:208:91::23) by DM4PR12MB5309.namprd12.prod.outlook.com (2603:10b6:5:390::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.21; Thu, 11 May 2023 07:32:27 +0000 Received: from BL02EPF000145BB.namprd05.prod.outlook.com (2603:10b6:208:91:cafe::6e) by BL0PR05CA0013.outlook.office365.com (2603:10b6:208:91::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.20 via Frontend Transport; Thu, 11 May 2023 07:32:27 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by BL02EPF000145BB.mail.protection.outlook.com (10.167.241.211) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6387.21 via Frontend Transport; Thu, 11 May 2023 07:32:27 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 11 May 2023 02:32:23 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB06.amd.com (10.181.40.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 11 May 2023 02:32:23 -0500 Received: from xhdakumarma40u.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Thu, 11 May 2023 02:31:58 -0500 From: Amit Kumar Mahapatra To: , , , , , , CC: , , , , , , , , , , , Amit Kumar Mahapatra Subject: [PATCH V8 4/7] mtd: spi-nor: Add stacked memories support in spi-nor Date: Thu, 11 May 2023 13:01:31 +0530 Message-ID: <20230511073134.41180-5-amit.kumar-mahapatra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230511073134.41180-1-amit.kumar-mahapatra@amd.com> References: <20230511073134.41180-1-amit.kumar-mahapatra@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF000145BB:EE_|DM4PR12MB5309:EE_ X-MS-Office365-Filtering-Correlation-Id: 5b680aa9-ec06-4f35-2960-08db51f1ded7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xBDlOYUWWXJdkSFKyyP76YL8Q1hWhuEm1AR5IVXzdasLvtVLqzj4/6mAWP/m3g1bKFPYViOYRM3TBc9BBcwZiOh/cTdh5c6XB3Tl9ENO5PrtPJtWE6X4Lzza2OSg97O6jzvoQHg+6lL/1VG4EcvGU4U1dU77eZrQrm42wAL0iJ5lFDaCTOR6DTcltgWvi9k+7Zy5ipxU7bpewIFnjQLxTHaJAXBjFX6p8wFmW07RBP0Rc78eIgYFBEtmp8APbK0rU+POvr08y+KeiDP+kLvugQBzmY2uiILuNwsB8XQGQFWcGTEwhQd0XWFxOCshCOduiooRtFQGc2zf5a3k8f9q8kZvwU/+DhoIkU5eQPQvErh5NkbGSPo2Wd5ul4ENSB5KZsTfWFhpVzQW0VJh24vtMemOGAnowL1pOXOIgFqykQ4VHkB4FxZ3dnB7RUDHJTrvW09Fb6C6v1FeqB+PKBomjoxtuRxE6XPAJINEnkCmkldMlyyIqumCQmUjEYj49yI3XHz33iwNtfNVtlpSubUgekCDeOjjPg+bC7O2k2ckCqvCje6MKuwbH/V6WD/a3OejzzZeJ5+Ig+77b9VfqboMkbXjqCrCva39cKXQUT1I7fDjJj4Aw8M3izwTcEpPtGMQwkSf0IJLYWtEs0l92DaFpL8NirWbFox3QPPG6uyzlRuFQ3CWO0HBmJn4M7zf31Re111RWeRgtESEyzBM6/nTYNm4TC+jRipW7/Wyx37S7hCsTjcxGyRehPzioLb5HUVnKSg6Lls241iqkK0bkysc8w== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(346002)(376002)(136003)(39860400002)(396003)(451199021)(36840700001)(46966006)(40470700004)(40460700003)(6666004)(36860700001)(81166007)(41300700001)(82740400003)(356005)(47076005)(8936002)(26005)(1076003)(7416002)(8676002)(5660300002)(2616005)(336012)(426003)(83380400001)(186003)(2906002)(30864003)(40480700001)(82310400005)(86362001)(70586007)(70206006)(4326008)(316002)(478600001)(36756003)(54906003)(110136005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 May 2023 07:32:27.0199 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5b680aa9-ec06-4f35-2960-08db51f1ded7 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF000145BB.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5309 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230511_003250_311243_0ABD85E3 X-CRM114-Status: GOOD ( 26.49 ) X-Spam-Score: 0.8 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Each flash that is connected in stacked mode should have a separate parameter structure. So, the flash parameter member(*params) of the spi_nor structure is changed to an array (*params[2]). The array [...] Content analysis details: (0.8 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 1.0 FORGED_SPF_HELO No description available. X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Each flash that is connected in stacked mode should have a separate parameter structure. So, the flash parameter member(*params) of the spi_nor structure is changed to an array (*params[2]). The array is used to store the parameters of each flash connected in stacked configuration. The current implementation assumes that a maximum of two flashes are connected in stacked mode and both the flashes are of same make but can differ in sizes. So, except the sizes all other flash parameters of both the flashes are identical. SPI-NOR is not aware of the chip_select values, for any incoming request SPI-NOR will decide the flash index with the help of individual flash size and the configuration type (single/stacked). SPI-NOR will pass on the flash index information to the SPI core & SPI driver by setting the appropriate bit in nor->spimem->spi->cs_index_mask. For example, if nth bit of nor->spimem->spi->cs_index_mask is set then the driver would assert/de-assert spi->chip_slect[n]. Signed-off-by: Amit Kumar Mahapatra --- drivers/mtd/spi-nor/core.c | 282 +++++++++++++++++++++++++++++------- drivers/mtd/spi-nor/core.h | 4 + include/linux/mtd/spi-nor.h | 12 +- 3 files changed, 242 insertions(+), 56 deletions(-) diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c index c5d752a65575..87eea547910c 100644 --- a/drivers/mtd/spi-nor/core.c +++ b/drivers/mtd/spi-nor/core.c @@ -1812,13 +1812,18 @@ static int spi_nor_erase_multi_sectors(struct spi_nor *nor, u64 addr, u32 len) static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr) { struct spi_nor *nor = mtd_to_spi_nor(mtd); - u32 addr, len; + struct spi_nor_flash_parameter *params; + u32 addr, len, offset, cur_cs_num = 0; uint32_t rem; int ret; + u64 sz; dev_dbg(nor->dev, "at 0x%llx, len %lld\n", (long long)instr->addr, (long long)instr->len); + params = spi_nor_get_params(nor, 0); + sz = params->size; + if (spi_nor_has_uniform_erase(nor)) { div_u64_rem(instr->len, mtd->erasesize, &rem); if (rem) @@ -1840,29 +1845,32 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr) if (ret) goto erase_err; - ret = spi_nor_write_enable(nor); - if (ret) { + while (cur_cs_num < SNOR_FLASH_CNT_MAX && params) { + nor->spimem->spi->cs_index_mask = 0x01 << cur_cs_num; + ret = spi_nor_write_enable(nor); + if (ret) { + spi_nor_unlock_device(nor); + goto erase_err; + } + ret = spi_nor_erase_chip(nor); spi_nor_unlock_device(nor); - goto erase_err; - } - - ret = spi_nor_erase_chip(nor); - spi_nor_unlock_device(nor); - if (ret) - goto erase_err; + if (ret) + goto erase_err; - /* - * Scale the timeout linearly with the size of the flash, with - * a minimum calibrated to an old 2MB flash. We could try to - * pull these from CFI/SFDP, but these values should be good - * enough for now. - */ - timeout = max(CHIP_ERASE_2MB_READY_WAIT_JIFFIES, - CHIP_ERASE_2MB_READY_WAIT_JIFFIES * - (unsigned long)(mtd->size / SZ_2M)); - ret = spi_nor_wait_till_ready_with_timeout(nor, timeout); - if (ret) - goto erase_err; + /* + * Scale the timeout linearly with the size of the flash, with + * a minimum calibrated to an old 2MB flash. We could try to + * pull these from CFI/SFDP, but these values should be good + * enough for now. + */ + timeout = max(CHIP_ERASE_2MB_READY_WAIT_JIFFIES, + CHIP_ERASE_2MB_READY_WAIT_JIFFIES * + (unsigned long)(params->size / SZ_2M)); + ret = spi_nor_wait_till_ready_with_timeout(nor, timeout); + if (ret) + goto erase_err; + cur_cs_num++; + } /* REVISIT in some cases we could speed up erasing large regions * by using SPINOR_OP_SE instead of SPINOR_OP_BE_4K. We may have set up @@ -1871,18 +1879,31 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr) /* "sector"-at-a-time erase */ } else if (spi_nor_has_uniform_erase(nor)) { + /* Determine the flash from which the operation need to start */ + while ((cur_cs_num < SNOR_FLASH_CNT_MAX) && (addr > sz - 1) && params) { + cur_cs_num++; + params = spi_nor_get_params(nor, cur_cs_num); + sz += params->size; + } + while (len) { ret = spi_nor_lock_device(nor); if (ret) goto erase_err; + nor->spimem->spi->cs_index_mask = 0x01 << cur_cs_num; ret = spi_nor_write_enable(nor); if (ret) { spi_nor_unlock_device(nor); goto erase_err; } + offset = addr; + if (nor->flags & SNOR_F_HAS_STACKED) { + params = spi_nor_get_params(nor, cur_cs_num); + offset -= (sz - params->size); + } - ret = spi_nor_erase_sector(nor, addr); + ret = spi_nor_erase_sector(nor, offset); spi_nor_unlock_device(nor); if (ret) goto erase_err; @@ -1893,13 +1914,45 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr) addr += mtd->erasesize; len -= mtd->erasesize; + + /* + * Flash cross over condition in stacked mode. + */ + if ((nor->flags & SNOR_F_HAS_STACKED) && (addr > sz - 1)) { + cur_cs_num++; + params = spi_nor_get_params(nor, cur_cs_num); + sz += params->size; + } } /* erase multiple sectors */ } else { - ret = spi_nor_erase_multi_sectors(nor, addr, len); - if (ret) - goto erase_err; + u64 erase_len = 0; + + /* Determine the flash from which the operation need to start */ + while ((cur_cs_num < SNOR_FLASH_CNT_MAX) && (addr > sz - 1) && params) { + cur_cs_num++; + params = spi_nor_get_params(nor, cur_cs_num); + sz += params->size; + } + /* perform multi sector erase onec per Flash*/ + while (len) { + erase_len = (len > (sz - addr)) ? (sz - addr) : len; + offset = addr; + nor->spimem->spi->cs_index_mask = 0x01 << cur_cs_num; + if (nor->flags & SNOR_F_HAS_STACKED) { + params = spi_nor_get_params(nor, cur_cs_num); + offset -= (sz - params->size); + } + ret = spi_nor_erase_multi_sectors(nor, offset, erase_len); + if (ret) + goto erase_err; + len -= erase_len; + addr += erase_len; + cur_cs_num++; + params = spi_nor_get_params(nor, cur_cs_num); + sz += params->size; + } } ret = spi_nor_write_disable(nor); @@ -2098,9 +2151,11 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf) { struct spi_nor *nor = mtd_to_spi_nor(mtd); + struct spi_nor_flash_parameter *params; + ssize_t ret, read_len, len_lock = len; loff_t from_lock = from; - size_t len_lock = len; - ssize_t ret; + u32 cur_cs_num = 0; + u64 sz; dev_dbg(nor->dev, "from 0x%08x, len %zd\n", (u32)from, len); @@ -2108,9 +2163,23 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len, if (ret) return ret; + params = spi_nor_get_params(nor, 0); + sz = params->size; + + /* Determine the flash from which the operation need to start */ + while ((cur_cs_num < SNOR_FLASH_CNT_MAX) && (from > sz - 1) && params) { + cur_cs_num++; + params = spi_nor_get_params(nor, cur_cs_num); + sz += params->size; + } while (len) { loff_t addr = from; + nor->spimem->spi->cs_index_mask = 0x01 << cur_cs_num; + read_len = (len > (sz - addr)) ? (sz - addr) : len; + params = spi_nor_get_params(nor, cur_cs_num); + addr -= (sz - params->size); + addr = spi_nor_convert_addr(nor, addr); ret = spi_nor_read_data(nor, addr, len, buf); @@ -2122,11 +2191,22 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len, if (ret < 0) goto read_err; - WARN_ON(ret > len); + WARN_ON(ret > read_len); *retlen += ret; buf += ret; from += ret; len -= ret; + + /* + * Flash cross over condition in stacked mode. + * + */ + if ((nor->flags & SNOR_F_HAS_STACKED) && (from > sz - 1)) { + cur_cs_num++; + params = spi_nor_get_params(nor, cur_cs_num); + sz += params->size; + } + } ret = 0; @@ -2147,8 +2227,9 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len, struct spi_nor *nor = mtd_to_spi_nor(mtd); struct spi_nor_flash_parameter *params; size_t page_offset, page_remain, i; + u32 page_size, cur_cs_num = 0; ssize_t ret; - u32 page_size; + u64 sz; dev_dbg(nor->dev, "to 0x%08x, len %zd\n", (u32)to, len); @@ -2158,6 +2239,14 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len, params = spi_nor_get_params(nor, 0); page_size = params->page_size; + sz = params->size; + + /* Determine the flash from which the operation need to start */ + while ((cur_cs_num < SNOR_FLASH_CNT_MAX) && (to > sz - 1) && params) { + cur_cs_num++; + params = spi_nor_get_params(nor, cur_cs_num); + sz += params->size; + } for (i = 0; i < len; ) { ssize_t written; @@ -2178,6 +2267,10 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len, /* the size of data remaining on the first page */ page_remain = min_t(size_t, page_size - page_offset, len - i); + nor->spimem->spi->cs_index_mask = 0x01 << cur_cs_num; + params = spi_nor_get_params(nor, cur_cs_num); + addr -= (sz - params->size); + addr = spi_nor_convert_addr(nor, addr); ret = spi_nor_lock_device(nor); @@ -2201,6 +2294,15 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len, goto write_err; *retlen += written; i += written; + + /* + * Flash cross over condition in stacked mode. + */ + if ((nor->flags & SNOR_F_HAS_STACKED) && ((to + i) > sz - 1)) { + cur_cs_num++; + params = spi_nor_get_params(nor, cur_cs_num); + sz += params->size; + } } write_err: @@ -2314,8 +2416,6 @@ int spi_nor_hwcaps_pp2cmd(u32 hwcaps) static int spi_nor_spimem_check_op(struct spi_nor *nor, struct spi_mem_op *op) { - struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); - /* * First test with 4 address bytes. The opcode itself might * be a 3B addressing opcode but we don't care, because @@ -2324,7 +2424,7 @@ static int spi_nor_spimem_check_op(struct spi_nor *nor, */ op->addr.nbytes = 4; if (!spi_mem_supports_op(nor->spimem, op)) { - if (params->size > SZ_16M) + if (nor->mtd.size > SZ_16M) return -EOPNOTSUPP; /* If flash size <= 16MB, 3 address bytes are sufficient */ @@ -2925,6 +3025,10 @@ static void spi_nor_init_fixup_flags(struct spi_nor *nor) static void spi_nor_late_init_params(struct spi_nor *nor) { struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + struct device_node *np = spi_nor_get_flash_node(nor); + u64 flash_size[SNOR_FLASH_CNT_MAX]; + u32 idx = 0, i = 0; + int rc; if (nor->manufacturer && nor->manufacturer->fixups && nor->manufacturer->fixups->late_init) @@ -2948,6 +3052,36 @@ static void spi_nor_late_init_params(struct spi_nor *nor) spi_nor_init_default_locking_ops(nor); params->bank_size = div64_u64(params->size, nor->info->n_banks); + /* + * The flashes that are connected in stacked mode should be of same make. + * Except the flash size all other properties are identical for all the + * flashes connected in stacked mode. + * The flashes that are connected in parallel mode should be identical. + */ + while (i < SNOR_FLASH_CNT_MAX) { + rc = of_property_read_u64_index(np, "stacked-memories", idx, &flash_size[i]); + if (rc == -EINVAL) { + break; + } else if (rc == -EOVERFLOW) { + idx++; + } else { + idx++; + i++; + if (!(nor->flags & SNOR_F_HAS_STACKED)) + nor->flags |= SNOR_F_HAS_STACKED; + } + } + if (nor->flags & SNOR_F_HAS_STACKED) { + for (idx = 1; idx < SNOR_FLASH_CNT_MAX; idx++) { + params = spi_nor_get_params(nor, idx); + params = devm_kzalloc(nor->dev, sizeof(*params), GFP_KERNEL); + if (params) { + memcpy(params, spi_nor_get_params(nor, 0), sizeof(*params)); + params->size = flash_size[idx]; + spi_nor_set_params(nor, idx, params); + } + } + } } /** @@ -3155,16 +3289,30 @@ static int spi_nor_octal_dtr_enable(struct spi_nor *nor, bool enable) */ static int spi_nor_quad_enable(struct spi_nor *nor) { - struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); + struct spi_nor_flash_parameter *params; + int err, idx; - if (!params->quad_enable) - return 0; + for (idx = 0; idx < SNOR_FLASH_CNT_MAX; idx++) { + params = spi_nor_get_params(nor, idx); + if (params) { + if (!params->quad_enable) + return 0; - if (!(spi_nor_get_protocol_width(nor->read_proto) == 4 || - spi_nor_get_protocol_width(nor->write_proto) == 4)) - return 0; + if (!(spi_nor_get_protocol_width(nor->read_proto) == 4 || + spi_nor_get_protocol_width(nor->write_proto) == 4)) + return 0; + /* + * Set the appropriate CS index before + * issuing the command. + */ + nor->spimem->spi->cs_index_mask = 0x01 << idx; - return params->quad_enable(nor); + err = params->quad_enable(nor); + if (err) + return err; + } + } + return err; } /** @@ -3196,7 +3344,7 @@ int spi_nor_set_4byte_addr_mode(struct spi_nor *nor, bool enable) static int spi_nor_init(struct spi_nor *nor) { - int err; + int err, idx; err = spi_nor_octal_dtr_enable(nor, true); if (err) { @@ -3237,9 +3385,18 @@ static int spi_nor_init(struct spi_nor *nor) */ WARN_ONCE(nor->flags & SNOR_F_BROKEN_RESET, "enabling reset hack; may not recover from unexpected reboots\n"); - err = spi_nor_set_4byte_addr_mode(nor, true); - if (err) - return err; + for (idx = 0; idx < SNOR_FLASH_CNT_MAX; idx++) { + if (spi_nor_get_params(nor, idx)) { + /* + * Select the appropriate CS index before + * issuing the command. + */ + nor->spimem->spi->cs_index_mask = 0x01 << idx; + err = spi_nor_set_4byte_addr_mode(nor, true); + if (err) + return err; + } + } } return 0; @@ -3354,18 +3511,30 @@ static void spi_nor_put_device(struct mtd_info *mtd) static void spi_nor_restore(struct spi_nor *nor) { int ret; + int idx; /* restore the addressing mode */ if (nor->addr_nbytes == 4 && !(nor->flags & SNOR_F_4B_OPCODES) && nor->flags & SNOR_F_BROKEN_RESET) { - ret = spi_nor_set_4byte_addr_mode(nor, false); - if (ret) - /* - * Do not stop the execution in the hope that the flash - * will default to the 3-byte address mode after the - * software reset. - */ - dev_err(nor->dev, "Failed to exit 4-byte address mode, err = %d\n", ret); + for (idx = 0; idx < SNOR_FLASH_CNT_MAX; idx++) { + if (spi_nor_get_params(nor, idx)) { + /* + * Select the appropriate CS index before + * issuing the command. + */ + nor->spimem->spi->cs_index_mask = 1 << idx; + ret = spi_nor_set_4byte_addr_mode(nor, false); + if (ret) + /* + * Do not stop the execution in the hope that the flash + * will default to the 3-byte address mode after the + * software reset. + */ + dev_err(nor->dev, + "Failed to exit 4-byte address mode, err = %d\n", + ret); + } + } } if (nor->flags & SNOR_F_SOFT_RESET) @@ -3432,6 +3601,8 @@ static void spi_nor_set_mtd_info(struct spi_nor *nor) struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); struct mtd_info *mtd = &nor->mtd; struct device *dev = nor->dev; + u64 total_sz = 0; + int idx; spi_nor_set_mtd_locking_ops(nor); spi_nor_set_mtd_otp_ops(nor); @@ -3450,7 +3621,12 @@ static void spi_nor_set_mtd_info(struct spi_nor *nor) mtd->_erase = spi_nor_erase; mtd->writesize = params->writesize; mtd->writebufsize = params->page_size; - mtd->size = params->size; + for (idx = 0; idx < SNOR_FLASH_CNT_MAX; idx++) { + params = spi_nor_get_params(nor, idx); + if (params) + total_sz += params->size; + } + mtd->size = total_sz; mtd->_read = spi_nor_read; /* Might be already set by some SST flashes. */ if (!mtd->_write) diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h index 4fb5ff09c63a..89dc65a697b8 100644 --- a/drivers/mtd/spi-nor/core.h +++ b/drivers/mtd/spi-nor/core.h @@ -11,6 +11,9 @@ #define SPI_NOR_MAX_ID_LEN 6 +/* In single configuration enable CS0 */ +#define SPI_NOR_ENABLE_CS0 BIT(0) + /* Standard SPI NOR flash operations. */ #define SPI_NOR_READID_OP(naddr, ndummy, buf, len) \ SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_RDID, 0), \ @@ -132,6 +135,7 @@ enum spi_nor_option_flags { SNOR_F_SWP_IS_VOLATILE = BIT(13), SNOR_F_RWW = BIT(14), SNOR_F_ECC = BIT(15), + SNOR_F_HAS_STACKED = BIT(16), }; struct spi_nor_read_command { diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h index 59909e7d6f53..1a3076787c90 100644 --- a/include/linux/mtd/spi-nor.h +++ b/include/linux/mtd/spi-nor.h @@ -127,6 +127,12 @@ #define SR2_LB3 BIT(5) /* Security Register Lock Bit 3 */ #define SR2_QUAD_EN_BIT7 BIT(7) +/* + * Maximum number of flashes that can be connected + * in stacked/parallel configuration + */ +#define SNOR_FLASH_CNT_MAX 2 + /* Supported SPI protocols */ #define SNOR_PROTO_INST_MASK GENMASK(23, 16) #define SNOR_PROTO_INST_SHIFT 16 @@ -412,7 +418,7 @@ struct spi_nor { const struct spi_nor_controller_ops *controller_ops; - struct spi_nor_flash_parameter *params; + struct spi_nor_flash_parameter *params[SNOR_FLASH_CNT_MAX]; struct { struct spi_mem_dirmap_desc *rdesc; @@ -435,13 +441,13 @@ static inline struct device_node *spi_nor_get_flash_node(struct spi_nor *nor) static inline struct spi_nor_flash_parameter *spi_nor_get_params(const struct spi_nor *nor, u8 idx) { - return nor->params; + return nor->params[idx]; } static inline void spi_nor_set_params(struct spi_nor *nor, u8 idx, struct spi_nor_flash_parameter *params) { - nor->params = params; + nor->params[idx] = params; } /** * spi_nor_scan() - scan the SPI NOR From patchwork Thu May 11 07:31:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Mahapatra, Amit Kumar" X-Patchwork-Id: 1779804 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=wWinW3ui; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=l0FdDW5X; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QH3Yj6Sxrz213w for ; Thu, 11 May 2023 17:34:17 +1000 (AEST) 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=ogeDRbt/+JoZPgvLt5eIzLQw7GXfrmDaJW9lsQAb7Rw=; b=wWinW3uitc377N HD8VFLo0OmJRrOVsx4wJ5lCcTU2Wvn08QNcfHQV80HhFOMrc56QDW003mku6rGkgETrkCW2Gvsv1H PNgf0cTxkOOBlMkkYg+4qI7ayl6CxNLi1EZauThb7fpf4KpEjg8BB65+eRKocTjMwXBV2HYk/Gj7O 1ER6hZxgOpVc3EmCiPmhzAzXgn0p125P7wVOU48SuXqUESy/hYPyjvHzYWeZgYJ8AqmaZfTfFc6aD o4J63rD8c3R6zQ35bggiO7bvoV5IhU1JKLud3akfKCtMXeM433zJx3pkJAZn5Z2Z0nt/l2p7atqzT 4UXmmtO+j+0by1K0NA+w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1px0o4-0089YD-1N; Thu, 11 May 2023 07:33:44 +0000 Received: from mail-mw2nam12on2062d.outbound.protection.outlook.com ([2a01:111:f400:fe5a::62d] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1px0nx-0089SD-14; Thu, 11 May 2023 07:33:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VQUXKX/WqGVm/IiCsQR9uWAFrF88W0OwZU+P9qKLRfwRVe1iBLZUw0i/rWDfUu8VvFpeoitNTO686vnJm6IztEtnorfO4nkxJXK+Ap9bJaifRWJSer9nb3QGnbOry0uPvfpp4lL0usMP+p/jH+oZWOU7SWEo7AbP0wxTKEsW0HNSVyknQtaVtVg8VkW8w1s0ErIxX3oRbDoVl1CZdASHRTn3feCrTShnmXXyAQRwf1ruKPms2N+c4GD7nBaTl0Xa30RZWhNgpV62K4yOSrjCU8BNaevbL+QWYUJ35VEM/m3yB2ehF4+dTWKzGQo/BdMvWbtmbWWTyqEWBqW5NTQ+FQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=v5KdSSDQ2nsI2TY2AaFPPmoyVvEQ1ALcxSgb22XsW3Y=; b=GpZ4F+Dyz4GF02U+73d5Gw+A20I04WpFqTAHWStPRJzG5IG5Vl4hIq2AjP7JkSSIRWSPNUlUpKpdCipP4lY+TyCjm6ui5GsW/x7pSoMjFaaii7wJzQxEHp0wGo4vUwGEUCOqk3gKXBRnREwF0D1bbICQsZpVbq9qPe++YmsJoAfEe2pENiGk07DzV5qJJ8uOJWkzgIYkO3Dx4Xz9GAXf0t2/HGfazqSEhOu1RT/hWKiyBCgi9WyC17Oe7FW3vb74TFwv1q1XCKs/IqXqXsDoEFdEiwpwZrqa0Ot50fuSF40kPM2hjSkvyycmOFX/dDYKwk5yhPX3uETTc023rg7eZQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=v5KdSSDQ2nsI2TY2AaFPPmoyVvEQ1ALcxSgb22XsW3Y=; b=l0FdDW5XzjncuZOfFQ9uXUfmnnPtrAJu7EtXueIjIJox4i/JNGjWqDier/fwtYEXzXcixrINWf8E+4vYghCQmof4vQF60ca602U2bxHaCCQ7wE3eRc5Cd4O1PY0Lqk1s5MOnvp4VLfIGIxdYXALpvaBMQGdN1QPp25N6mNn42vQ= Received: from BL1PR13CA0135.namprd13.prod.outlook.com (2603:10b6:208:2bb::20) by SN7PR12MB7978.namprd12.prod.outlook.com (2603:10b6:806:34b::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.21; Thu, 11 May 2023 07:33:13 +0000 Received: from BL02EPF000145B8.namprd05.prod.outlook.com (2603:10b6:208:2bb:cafe::bd) by BL1PR13CA0135.outlook.office365.com (2603:10b6:208:2bb::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.7 via Frontend Transport; Thu, 11 May 2023 07:33:13 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by BL02EPF000145B8.mail.protection.outlook.com (10.167.241.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6387.21 via Frontend Transport; Thu, 11 May 2023 07:33:13 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 11 May 2023 02:33:11 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 11 May 2023 00:32:28 -0700 Received: from xhdakumarma40u.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Thu, 11 May 2023 02:32:23 -0500 From: Amit Kumar Mahapatra To: , , , , , , CC: , , , , , , , , , , , Amit Kumar Mahapatra Subject: [PATCH V8 5/7] spi: spi-zynqmp-gqspi: Add stacked memories support in GQSPI driver Date: Thu, 11 May 2023 13:01:32 +0530 Message-ID: <20230511073134.41180-6-amit.kumar-mahapatra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230511073134.41180-1-amit.kumar-mahapatra@amd.com> References: <20230511073134.41180-1-amit.kumar-mahapatra@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF000145B8:EE_|SN7PR12MB7978:EE_ X-MS-Office365-Filtering-Correlation-Id: 6ec74146-3478-4d24-cf0c-08db51f1fa3f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1l6E8Z0QHmmKNIqn2/PT9ZmYtZceJvnhBgv4CDAk8isTnp9v/+w++V6njM/j0HrGDiJvO+T0xIhXu/WdOB5O3KdUdpU/08y5x8VYrabQrgXPTRmjEcYE4GsknmSsTJ0WyDgNLUa34oUvkhyYkCkM5R2HKk7POb/vh9Xl+S3yY3HwVNxzmCzUVYoEdpfYW7RG55YuIFvaUsu/odY6qCQO+cURgesTU08KEwi6CuCFN9YcbJVfeDprsDWjhCyrEpVXiB5QLDiJK7FMEyjUMfAmGQYAQ2hBQQD1pop0FlJuWhfYHTXESxbQQQCLEQIJEm44yiRz1AkCyGTVE3MUiPuFlydDFplfyVoc6hMXfQ5K8UtzvglF9EPDkOkFMtZWJSBe2aoBo02h9FJV9HJKqnWCl8fu3hp3ScEsoqbLW4mmZ/+DbFe51SGVW1MoQPhqZ04O5+waX0grmlc7zAaQM7nwXsI2QaSOJg5gcIHORIaBbUbnyUaz3sz8jBxc0foq/xJpq+Tup3Pp9thR01FxLQ4jm+WsIwew1or3wDjpzef24f2KTtMnZov1X3c142du6KjG4i20lwuYqRlc3p2BHTKBqoHwewj+S6MdnA2nqiKD3OHDpvPtZXxmaojD1HISuOiMIqFNu1VMvAGUv4BWL1mO5l50oe3ALJIkhftGXXQsJQlOvxr6sEz403mfIyDQ5aUmAB/XsLA1iDExAh5m4ZsGZCGzSTwz3dfCq0GJuWKrJMdvP9p+2t3K7/EjAu2/oxFJMSTiTqsF+EGLYGodnOS1KA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(346002)(376002)(136003)(39860400002)(396003)(451199021)(40470700004)(36840700001)(46966006)(40460700003)(6666004)(36860700001)(81166007)(41300700001)(82740400003)(356005)(47076005)(8936002)(26005)(1076003)(7416002)(8676002)(5660300002)(2616005)(336012)(426003)(83380400001)(186003)(2906002)(40480700001)(86362001)(82310400005)(70586007)(70206006)(4326008)(316002)(478600001)(36756003)(54906003)(110136005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 May 2023 07:33:13.0042 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6ec74146-3478-4d24-cf0c-08db51f1fa3f X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF000145B8.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7978 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230511_003337_382139_4504B6F9 X-CRM114-Status: GOOD ( 12.56 ) X-Spam-Score: 0.8 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: GQSPI supports two chip select CS0 & CS1. Update the driver to assert/de-assert the appropriate chip select as per the bits set in qspi->cs_index_mask. Signed-off-by: Amit Kumar Mahapatra --- drivers/spi/spi-zynqmp-gqspi.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) Content analysis details: (0.8 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 1.0 FORGED_SPF_HELO No description available. X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org GQSPI supports two chip select CS0 & CS1. Update the driver to assert/de-assert the appropriate chip select as per the bits set in qspi->cs_index_mask. Signed-off-by: Amit Kumar Mahapatra --- drivers/spi/spi-zynqmp-gqspi.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/drivers/spi/spi-zynqmp-gqspi.c b/drivers/spi/spi-zynqmp-gqspi.c index fb2ca9b90eab..3d2b92a88e8a 100644 --- a/drivers/spi/spi-zynqmp-gqspi.c +++ b/drivers/spi/spi-zynqmp-gqspi.c @@ -156,6 +156,9 @@ #define GQSPI_FREQ_100MHZ 100000000 #define GQSPI_FREQ_150MHZ 150000000 +#define GQSPI_SELECT_LOWER_CS BIT(0) +#define GQSPI_SELECT_UPPER_CS BIT(1) + #define SPI_AUTOSUSPEND_TIMEOUT 3000 enum mode_type {GQSPI_MODE_IO, GQSPI_MODE_DMA}; @@ -467,15 +470,17 @@ static void zynqmp_qspi_chipselect(struct spi_device *qspi, bool is_high) genfifoentry |= GQSPI_GENFIFO_MODE_SPI; + if (qspi->cs_index_mask & GQSPI_SELECT_UPPER_CS) { + zynqmp_gqspi_selectslave(xqspi, + GQSPI_SELECT_FLASH_CS_UPPER, + GQSPI_SELECT_FLASH_BUS_LOWER); + } else if (qspi->cs_index_mask & GQSPI_SELECT_LOWER_CS) { + zynqmp_gqspi_selectslave(xqspi, + GQSPI_SELECT_FLASH_CS_LOWER, + GQSPI_SELECT_FLASH_BUS_LOWER); + } + genfifoentry |= xqspi->genfifobus; if (!is_high) { - if (!spi_get_chipselect(qspi, 0)) { - xqspi->genfifobus = GQSPI_GENFIFO_BUS_LOWER; - xqspi->genfifocs = GQSPI_GENFIFO_CS_LOWER; - } else { - xqspi->genfifobus = GQSPI_GENFIFO_BUS_UPPER; - xqspi->genfifocs = GQSPI_GENFIFO_CS_UPPER; - } - genfifoentry |= xqspi->genfifobus; genfifoentry |= xqspi->genfifocs; genfifoentry |= GQSPI_GENFIFO_CS_SETUP; } else { From patchwork Thu May 11 07:31:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Mahapatra, Amit Kumar" X-Patchwork-Id: 1779803 X-Patchwork-Delegate: tudor.ambarus@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=rUNzZtyg; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=KEqFdbQ0; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QH3YY0yX9z213w for ; Thu, 11 May 2023 17:34:09 +1000 (AEST) 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=SK5Mi1kGzP2wkEJHDkJVAYPMZ4yHmC9yfx7Lse0uOfE=; b=rUNzZtygQcMffg mFreUpbkzD6XFsUefowrUxu8MDhbX690Y2mQUHPb3vtx9U4jhBtInyMpuZ4mBLRPCPLbXJS7M+QwB b3rsRqhQ6w1TaAl2opECwgzRUjBVNjailhmQ2aRl+vbKHBnv5e3hXusiohypVjlTA52M1P66wEVKp FwyVUYOQV2GL3Y9DqNx0jwswx29no16zd4ZLJk4rdXqSXIkFGu8njcQHEGb8lGUz12sioBDj8Ql6o q24dYyTtd3BgFUiAXk59PmuWFFKY5fU9476udXDw0/MdNwvJ+uLARzLxlvagJT9vI3LNMud5phkKg f88w1lGRnFQBQAVdTW+A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1px0ny-0089U4-2j; Thu, 11 May 2023 07:33:38 +0000 Received: from mail-bn8nam11on20601.outbound.protection.outlook.com ([2a01:111:f400:7eae::601] helo=NAM11-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1px0nt-0089Pf-06; Thu, 11 May 2023 07:33:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SvDWcRFXOzklK99g0fvh0a8zwJVqEip/Hqa/bcCOCymACmP4Axm4EkH5lPA6dGowNLRlOHJcACBHgCo586LV8andD0zeMtqJp1nEvBoYYPLmhVG+ndb5+Zo8io7OfXU400RpmXVNO0UzGVhYXuYK6VGEHn5O9f9jMgynmdxOEEny3HBdHzZDmLFrGzM9Qy6oyOGJ4xAMPFwKWxu8PDcffcUeIS7vGzzJnb8GOabAB9UKkwAvoyjNgLHvj1rQgwIn1OrmV7qArns48VtSxz4Ebn4fQ1BvPUR7xL/paQ7gukk0oLlBi0MFL897HIOKLeG5+gWuhlo+u4yd3N431KFlvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=CT2kXCIugqpqyHA9ppng2qcmbVe8qrLggSXJSAQsdq0=; b=XZdQFlKjp/7ulXu6V+6lXb5xcUwpQpA4bhu0JW7rZ9nsIkBooMUdK23xdKqNm/lEyYNpq3AY7GMwOmQVmHDtAoxY43KOxEeMlK+tkZyjPCfb6sjinsurIxxh8HR2ec7Ym18533wDArwvGJnHhcmTzK77/cSp2T0DdR8LBLKkEAO6vlQhmDSYVlDvpQRYr3vv3G+agYozRVvGNk2R9PyuTummXeXCgzoRHBLJTn8RN84lkQaqzfQyxPN2Lzc98r+SRe9nYeh0ckkyn4z1sreWCS9FzSG8dO0sLvSNigzFRamCF7nN0TzkjrWQAoJMb1AKSRBuXTSEwF9DdopcOP9qEA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CT2kXCIugqpqyHA9ppng2qcmbVe8qrLggSXJSAQsdq0=; b=KEqFdbQ0G0sgLjDnShrFpH8gpd1Z4lw2rp0TwJQH1lNFI6R/PmbL1NC7uiwkzMVkxPrDoCakZf/OXUX3GhLoZm2PzJScMjJ1jU5Pr2zg9aFreBOYBJ8SPQBWEB9YyLAlMbBnL9fWBzEJ+QhovammBZgTESXO71bufBNl1AGEBcQ= Received: from BL1PR13CA0123.namprd13.prod.outlook.com (2603:10b6:208:2bb::8) by PH0PR12MB5403.namprd12.prod.outlook.com (2603:10b6:510:eb::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.29; Thu, 11 May 2023 07:33:17 +0000 Received: from BL02EPF000145B8.namprd05.prod.outlook.com (2603:10b6:208:2bb:cafe::42) by BL1PR13CA0123.outlook.office365.com (2603:10b6:208:2bb::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.6 via Frontend Transport; Thu, 11 May 2023 07:33:16 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by BL02EPF000145B8.mail.protection.outlook.com (10.167.241.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6387.21 via Frontend Transport; Thu, 11 May 2023 07:33:16 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 11 May 2023 02:33:15 -0500 Received: from xhdakumarma40u.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Thu, 11 May 2023 02:33:11 -0500 From: Amit Kumar Mahapatra To: , , , , , , CC: , , , , , , , , , , , Amit Kumar Mahapatra Subject: [PATCH V8 6/7] mtd: spi-nor: Add parallel memories support in spi-nor Date: Thu, 11 May 2023 13:01:33 +0530 Message-ID: <20230511073134.41180-7-amit.kumar-mahapatra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230511073134.41180-1-amit.kumar-mahapatra@amd.com> References: <20230511073134.41180-1-amit.kumar-mahapatra@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF000145B8:EE_|PH0PR12MB5403:EE_ X-MS-Office365-Filtering-Correlation-Id: 958da3f9-e899-4196-b75c-08db51f1fc4e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hv2fzpM4MTvQJEE8YQVdYo+Vr/NaapMEuPj7Z47pPsSnBHsjfgmULH8NpKJbOWGPj3/x1nr9xGqdj7rou3EIZv+6LJ8gLFWKhAcHR9e1OEOM6N44WECVgZOYbvQFBZLD1cTQMoeGJy7GNfTpYVDbojm6Xtyurt/E8cztwouPd4n7VboRveUgvvJ365wa8uFLXeXpcDEljdaNJV/n+u5IhbDWoH7NYMs98LWWeMD47YdJZ7L7DzC6k9v5cOOxXWGosKXNSkuNekO68xE0+QR2yMQdW/OGOxtcnmvjfFZi+q0HpTKr7sbFQI5Q5LjnZfmHteTjb/WL3jS8+5E/iSiwx7DbhCDSFOfhOA0fAdsu0aB1nXJ/kPnTKYK9LZCY6HqZlBxuhXCW6boa0xLpXpdRHzk7j7zq9Hn/z/LHMpUZMjOhkE8BPy0aCUs7k7dSewTeUkj2OqZpcqbGJtUbh3wsYQ9P3ROm474ayzneohNWykQzVBZDXeaEoagsvW43KKs/Ow2GBO8dHQ78v5R1RvCMb59Dan4ecN8+XT4spfWQprl8tcpl5dNOx4s7JvnAOq6ZiGBi1C7MvW6ZCZU4uIvJK9RsU7aOSpSxLPLZ7NbBesd2pZiT+BV3k+6PrMZX4w/8x3GV651PNhCV4uoIv3aLHPkSIxh8CfJ9Eih8rjZa1SoTI7NRgnxqAj4o5OOKKfkUeiwOjcASh+kCy+vok6c+JXCSfI7WWQ290QL9UpxNG8s= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(376002)(396003)(39860400002)(136003)(346002)(451199021)(40470700004)(36840700001)(46966006)(40460700003)(82310400005)(8936002)(1076003)(426003)(2616005)(7416002)(26005)(8676002)(40480700001)(336012)(54906003)(2906002)(47076005)(83380400001)(5660300002)(30864003)(356005)(6666004)(41300700001)(110136005)(70586007)(478600001)(316002)(70206006)(4326008)(186003)(81166007)(36756003)(36860700001)(86362001)(82740400003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 May 2023 07:33:16.4573 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 958da3f9-e899-4196-b75c-08db51f1fc4e X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF000145B8.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB5403 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230511_003333_139391_8899F337 X-CRM114-Status: GOOD ( 25.37 ) X-Spam-Score: 0.8 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: The current implementation assumes that a maximum of two flashes are connected in parallel mode. The QSPI controller splits the data evenly between both the flashes so, both the flashes that are conne [...] Content analysis details: (0.8 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 1.0 FORGED_SPF_HELO No description available. X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The current implementation assumes that a maximum of two flashes are connected in parallel mode. The QSPI controller splits the data evenly between both the flashes so, both the flashes that are connected in parallel mode should be identical. During each operation SPI-NOR sets 0th bit for CS0 & 1st bit for CS1 in nor->spimem->spi->cs_index_mask. The QSPI driver will then assert/de-assert CS0 & CS1. Write operation in parallel mode are performed in page size * 2 chunks as each write operation results in writing both the flashes. For doubling the address space each operation is performed at addr/2 flash offset, where addr is the address specified by the user. Signed-off-by: Amit Kumar Mahapatra --- drivers/mtd/spi-nor/core.c | 545 +++++++++++++++++++++++--------- drivers/mtd/spi-nor/core.h | 4 + drivers/mtd/spi-nor/micron-st.c | 5 + 3 files changed, 406 insertions(+), 148 deletions(-) diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c index 87eea547910c..8d3027ac9e8d 100644 --- a/drivers/mtd/spi-nor/core.c +++ b/drivers/mtd/spi-nor/core.c @@ -464,17 +464,29 @@ int spi_nor_read_sr(struct spi_nor *nor, u8 *sr) op.data.nbytes = 2; } + if (nor->flags & SNOR_F_HAS_PARALLEL) + op.data.nbytes = 2; + spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); ret = spi_mem_exec_op(nor->spimem, &op); } else { - ret = spi_nor_controller_ops_read_reg(nor, SPINOR_OP_RDSR, sr, - 1); + if (nor->flags & SNOR_F_HAS_PARALLEL) + ret = spi_nor_controller_ops_read_reg(nor, + SPINOR_OP_RDSR, + sr, 2); + else + ret = spi_nor_controller_ops_read_reg(nor, + SPINOR_OP_RDSR, + sr, 1); } if (ret) dev_dbg(nor->dev, "error %d reading SR\n", ret); + if (nor->flags & SNOR_F_HAS_PARALLEL) + sr[0] |= sr[1]; + return ret; } @@ -1837,16 +1849,140 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr) if (ret) return ret; - /* whole-chip erase? */ - if (len == mtd->size && !(nor->flags & SNOR_F_NO_OP_CHIP_ERASE)) { - unsigned long timeout; + if (!(nor->flags & SNOR_F_HAS_PARALLEL)) { + /* whole-chip erase? */ + if (len == mtd->size && !(nor->flags & SNOR_F_NO_OP_CHIP_ERASE)) { + unsigned long timeout; - ret = spi_nor_lock_device(nor); - if (ret) - goto erase_err; + ret = spi_nor_lock_device(nor); + if (ret) + goto erase_err; + + while ((cur_cs_num < SNOR_FLASH_CNT_MAX) && params) { + nor->spimem->spi->cs_index_mask = 1 << cur_cs_num; + ret = spi_nor_write_enable(nor); + if (ret) { + spi_nor_unlock_device(nor); + goto erase_err; + } + + ret = spi_nor_erase_chip(nor); + spi_nor_unlock_device(nor); + if (ret) + goto erase_err; + + /* + * Scale the timeout linearly with the size of the flash, with + * a minimum calibrated to an old 2MB flash. We could try to + * pull these from CFI/SFDP, but these values should be good + * enough for now. + */ + timeout = max(CHIP_ERASE_2MB_READY_WAIT_JIFFIES, + CHIP_ERASE_2MB_READY_WAIT_JIFFIES * + (unsigned long)(params->size / + SZ_2M)); + ret = spi_nor_wait_till_ready_with_timeout(nor, timeout); + if (ret) + goto erase_err; + + cur_cs_num++; + params = spi_nor_get_params(nor, cur_cs_num); + } + + /* REVISIT in some cases we could speed up erasing large regions + * by using SPINOR_OP_SE instead of SPINOR_OP_BE_4K. We may have set up + * to use "small sector erase", but that's not always optimal. + */ + + /* "sector"-at-a-time erase */ + } else if (spi_nor_has_uniform_erase(nor)) { + /* Determine the flash from which the operation need to start */ + while ((cur_cs_num < SNOR_FLASH_CNT_MAX) && + (addr > sz - 1) && params) { + cur_cs_num++; + params = spi_nor_get_params(nor, cur_cs_num); + sz += params->size; + } + while (len) { + ret = spi_nor_lock_device(nor); + if (ret) + goto erase_err; + + nor->spimem->spi->cs_index_mask = 1 << cur_cs_num; + ret = spi_nor_write_enable(nor); + if (ret) { + spi_nor_unlock_device(nor); + goto erase_err; + } + + offset = addr; + if (nor->flags & SNOR_F_HAS_STACKED) { + params = spi_nor_get_params(nor, cur_cs_num); + offset -= (sz - params->size); + } + ret = spi_nor_erase_sector(nor, offset); + spi_nor_unlock_device(nor); + if (ret) + goto erase_err; + + ret = spi_nor_wait_till_ready(nor); + if (ret) + goto erase_err; + + addr += mtd->erasesize; + len -= mtd->erasesize; + + /* + * Flash cross over condition in stacked mode. + */ + if ((nor->flags & SNOR_F_HAS_STACKED) && (addr > sz - 1)) { + cur_cs_num++; + params = spi_nor_get_params(nor, cur_cs_num); + sz += params->size; + } + } + + /* erase multiple sectors */ + } else { + u64 erase_len = 0; + + /* Determine the flash from which the operation need to start */ + while ((cur_cs_num < SNOR_FLASH_CNT_MAX) && + (addr > sz - 1) && params) { + cur_cs_num++; + params = spi_nor_get_params(nor, cur_cs_num); + sz += params->size; + } + /* perform multi sector erase onec per Flash*/ + while (len) { + erase_len = (len > (sz - addr)) ? (sz - addr) : len; + offset = addr; + nor->spimem->spi->cs_index_mask = 1 << cur_cs_num; + if (nor->flags & SNOR_F_HAS_STACKED) { + params = spi_nor_get_params(nor, cur_cs_num); + offset -= (sz - params->size); + } + ret = spi_nor_erase_multi_sectors(nor, offset, erase_len); + if (ret) + goto erase_err; + len -= erase_len; + addr += erase_len; + params = spi_nor_get_params(nor, cur_cs_num); + sz += params->size; + } + } + } else { + nor->spimem->spi->cs_index_mask = SPI_NOR_ENABLE_MULTI_CS; + + /* whole-chip erase? */ + if (len == mtd->size && !(nor->flags & + SNOR_F_NO_OP_CHIP_ERASE)) { + unsigned long timeout; + + ret = spi_nor_lock_device(nor); + if (ret) + goto erase_err; - while (cur_cs_num < SNOR_FLASH_CNT_MAX && params) { - nor->spimem->spi->cs_index_mask = 0x01 << cur_cs_num; ret = spi_nor_write_enable(nor); if (ret) { spi_nor_unlock_device(nor); @@ -1865,96 +2001,51 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr) */ timeout = max(CHIP_ERASE_2MB_READY_WAIT_JIFFIES, CHIP_ERASE_2MB_READY_WAIT_JIFFIES * - (unsigned long)(params->size / SZ_2M)); + (unsigned long)(mtd->size / SZ_2M)); ret = spi_nor_wait_till_ready_with_timeout(nor, timeout); if (ret) goto erase_err; - cur_cs_num++; - } - /* REVISIT in some cases we could speed up erasing large regions - * by using SPINOR_OP_SE instead of SPINOR_OP_BE_4K. We may have set up - * to use "small sector erase", but that's not always optimal. - */ + /* REVISIT in some cases we could speed up erasing large regions + * by using SPINOR_OP_SE instead of SPINOR_OP_BE_4K. We may have set up + * to use "small sector erase", but that's not always optimal. + */ - /* "sector"-at-a-time erase */ - } else if (spi_nor_has_uniform_erase(nor)) { - /* Determine the flash from which the operation need to start */ - while ((cur_cs_num < SNOR_FLASH_CNT_MAX) && (addr > sz - 1) && params) { - cur_cs_num++; - params = spi_nor_get_params(nor, cur_cs_num); - sz += params->size; - } + /* "sector"-at-a-time erase */ + } else if (spi_nor_has_uniform_erase(nor)) { + while (len) { + ret = spi_nor_lock_device(nor); + if (ret) + goto erase_err; + ret = spi_nor_write_enable(nor); + if (ret) { + spi_nor_unlock_device(nor); + goto erase_err; + } - while (len) { - ret = spi_nor_lock_device(nor); - if (ret) - goto erase_err; + offset = addr / 2; - nor->spimem->spi->cs_index_mask = 0x01 << cur_cs_num; - ret = spi_nor_write_enable(nor); - if (ret) { + ret = spi_nor_erase_sector(nor, offset); spi_nor_unlock_device(nor); - goto erase_err; - } - offset = addr; - if (nor->flags & SNOR_F_HAS_STACKED) { - params = spi_nor_get_params(nor, cur_cs_num); - offset -= (sz - params->size); - } - - ret = spi_nor_erase_sector(nor, offset); - spi_nor_unlock_device(nor); - if (ret) - goto erase_err; - - ret = spi_nor_wait_till_ready(nor); - if (ret) - goto erase_err; + if (ret) + goto erase_err; - addr += mtd->erasesize; - len -= mtd->erasesize; + ret = spi_nor_wait_till_ready(nor); + if (ret) + goto erase_err; - /* - * Flash cross over condition in stacked mode. - */ - if ((nor->flags & SNOR_F_HAS_STACKED) && (addr > sz - 1)) { - cur_cs_num++; - params = spi_nor_get_params(nor, cur_cs_num); - sz += params->size; + addr += mtd->erasesize; + len -= mtd->erasesize; } - } - /* erase multiple sectors */ - } else { - u64 erase_len = 0; - - /* Determine the flash from which the operation need to start */ - while ((cur_cs_num < SNOR_FLASH_CNT_MAX) && (addr > sz - 1) && params) { - cur_cs_num++; - params = spi_nor_get_params(nor, cur_cs_num); - sz += params->size; - } - /* perform multi sector erase onec per Flash*/ - while (len) { - erase_len = (len > (sz - addr)) ? (sz - addr) : len; - offset = addr; - nor->spimem->spi->cs_index_mask = 0x01 << cur_cs_num; - if (nor->flags & SNOR_F_HAS_STACKED) { - params = spi_nor_get_params(nor, cur_cs_num); - offset -= (sz - params->size); - } - ret = spi_nor_erase_multi_sectors(nor, offset, erase_len); + /* erase multiple sectors */ + } else { + offset = addr / 2; + ret = spi_nor_erase_multi_sectors(nor, offset, len); if (ret) goto erase_err; - len -= erase_len; - addr += erase_len; - cur_cs_num++; - params = spi_nor_get_params(nor, cur_cs_num); - sz += params->size; } } - ret = spi_nor_write_disable(nor); erase_err: @@ -2155,7 +2246,9 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len, ssize_t ret, read_len, len_lock = len; loff_t from_lock = from; u32 cur_cs_num = 0; - u64 sz; + u_char *readbuf; + bool is_ofst_odd = false; + u64 sz = 0; dev_dbg(nor->dev, "from 0x%08x, len %zd\n", (u32)from, len); @@ -2166,23 +2259,47 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len, params = spi_nor_get_params(nor, 0); sz = params->size; - /* Determine the flash from which the operation need to start */ - while ((cur_cs_num < SNOR_FLASH_CNT_MAX) && (from > sz - 1) && params) { - cur_cs_num++; - params = spi_nor_get_params(nor, cur_cs_num); - sz += params->size; + /* + * Cannot read from odd offset in parallel mode, so read + * len + 1 from offset + 1 and ignore offset[0] data. + */ + if ((nor->flags & SNOR_F_HAS_PARALLEL) && (from & 0x01)) { + from = (loff_t)(from - 1); + len = (size_t)(len + 1); + is_ofst_odd = true; + readbuf = kmalloc(len, GFP_KERNEL); + if (!readbuf) + return -ENOMEM; + } else { + readbuf = buf; + } + + if (!(nor->flags & SNOR_F_HAS_PARALLEL)) { + /* Determine the flash from which the operation need to start */ + while ((cur_cs_num < SNOR_FLASH_CNT_MAX) && (from > sz - 1) && params) { + cur_cs_num++; + params = spi_nor_get_params(nor, cur_cs_num); + sz += params->size; + } } + while (len) { loff_t addr = from; - nor->spimem->spi->cs_index_mask = 0x01 << cur_cs_num; - read_len = (len > (sz - addr)) ? (sz - addr) : len; - params = spi_nor_get_params(nor, cur_cs_num); - addr -= (sz - params->size); + if (nor->flags & SNOR_F_HAS_PARALLEL) { + nor->spimem->spi->cs_index_mask = SPI_NOR_ENABLE_MULTI_CS; + read_len = len; + addr /= 2; + } else { + nor->spimem->spi->cs_index_mask = 1 << cur_cs_num; + read_len = (len > (sz - addr)) ? (sz - addr) : len; + params = spi_nor_get_params(nor, cur_cs_num); + addr -= (sz - params->size); + } addr = spi_nor_convert_addr(nor, addr); - ret = spi_nor_read_data(nor, addr, len, buf); + ret = spi_nor_read_data(nor, addr, read_len, readbuf); if (ret == 0) { /* We shouldn't see 0-length reads */ ret = -EIO; @@ -2192,8 +2309,20 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len, goto read_err; WARN_ON(ret > read_len); - *retlen += ret; + if (is_ofst_odd) { + /* + * Cannot read from odd offset in parallel mode. + * So read len + 1 from offset + 1 from the flash + * and copy len data from readbuf[1]. + */ + memcpy(buf, (readbuf + 1), (len - 1)); + *retlen += (ret - 1); + } else { + *retlen += ret; + } buf += ret; + if (!is_ofst_odd) + readbuf += ret; from += ret; len -= ret; @@ -2211,8 +2340,10 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len, ret = 0; read_err: - spi_nor_unlock_and_unprep_rd(nor, from_lock, len_lock); + if (is_ofst_odd) + kfree(readbuf); + spi_nor_unlock_and_unprep_rd(nor, from_lock, len_lock); return ret; } @@ -2241,11 +2372,37 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len, page_size = params->page_size; sz = params->size; - /* Determine the flash from which the operation need to start */ - while ((cur_cs_num < SNOR_FLASH_CNT_MAX) && (to > sz - 1) && params) { - cur_cs_num++; - params = spi_nor_get_params(nor, cur_cs_num); - sz += params->size; + if (nor->flags & SNOR_F_HAS_PARALLEL) { + /* + * Cannot write to odd offset in parallel mode, + * so write 2 byte first. + */ + if (to & 0x01) { + u8 two[2] = {0xff, buf[0]}; + size_t written_len; + + ret = spi_nor_write(mtd, to & ~1, 2, &written_len, two); + if (ret < 0) + return ret; + *retlen += 1; /* We've written only one actual byte */ + ++buf; + --len; + ++to; + } + /* + * Write operation are performed in page size chunks and in + * parallel memories both the flashes are written simultaneously, + * hence doubled the page_size. + */ + page_size <<= 1; + + } else { + /* Determine the flash from which the operation need to start */ + while ((cur_cs_num < SNOR_FLASH_CNT_MAX) && (to > sz - 1) && params) { + cur_cs_num++; + params = spi_nor_get_params(nor, cur_cs_num); + sz += params->size; + } } for (i = 0; i < len; ) { @@ -2267,9 +2424,14 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len, /* the size of data remaining on the first page */ page_remain = min_t(size_t, page_size - page_offset, len - i); - nor->spimem->spi->cs_index_mask = 0x01 << cur_cs_num; - params = spi_nor_get_params(nor, cur_cs_num); - addr -= (sz - params->size); + if (nor->flags & SNOR_F_HAS_PARALLEL) { + nor->spimem->spi->cs_index_mask = SPI_NOR_ENABLE_MULTI_CS; + addr /= 2; + } else { + nor->spimem->spi->cs_index_mask = 1 << cur_cs_num; + params = spi_nor_get_params(nor, cur_cs_num); + addr -= (sz - params->size); + } addr = spi_nor_convert_addr(nor, addr); @@ -2725,7 +2887,15 @@ static int spi_nor_select_erase(struct spi_nor *nor) if (!erase) return -EINVAL; nor->erase_opcode = erase->opcode; - mtd->erasesize = erase->size; + /* + * In parallel-memories the erase operation is + * performed on both the flashes simultaneously + * so, double the erasesize. + */ + if (nor->flags & SNOR_F_HAS_PARALLEL) + mtd->erasesize = erase->size * 2; + else + mtd->erasesize = erase->size; return 0; } @@ -2743,7 +2913,15 @@ static int spi_nor_select_erase(struct spi_nor *nor) if (!erase) return -EINVAL; - mtd->erasesize = erase->size; + /* + * In parallel-memories the erase operation is + * performed on both the flashes simultaneously + * so, double the erasesize. + */ + if (nor->flags & SNOR_F_HAS_PARALLEL) + mtd->erasesize = erase->size * 2; + else + mtd->erasesize = erase->size; return 0; } @@ -3071,7 +3249,22 @@ static void spi_nor_late_init_params(struct spi_nor *nor) nor->flags |= SNOR_F_HAS_STACKED; } } - if (nor->flags & SNOR_F_HAS_STACKED) { + i = 0; + idx = 0; + while (i < SNOR_FLASH_CNT_MAX) { + rc = of_property_read_u64_index(np, "parallel-memories", idx, &flash_size[i]); + if (rc == -EINVAL) { + break; + } else if (rc == -EOVERFLOW) { + idx++; + } else { + idx++; + i++; + if (!(nor->flags & SNOR_F_HAS_PARALLEL)) + nor->flags |= SNOR_F_HAS_PARALLEL; + } + } + if (nor->flags & (SNOR_F_HAS_STACKED | SNOR_F_HAS_PARALLEL)) { for (idx = 1; idx < SNOR_FLASH_CNT_MAX; idx++) { params = spi_nor_get_params(nor, idx); params = devm_kzalloc(nor->dev, sizeof(*params), GFP_KERNEL); @@ -3292,24 +3485,42 @@ static int spi_nor_quad_enable(struct spi_nor *nor) struct spi_nor_flash_parameter *params; int err, idx; - for (idx = 0; idx < SNOR_FLASH_CNT_MAX; idx++) { - params = spi_nor_get_params(nor, idx); - if (params) { - if (!params->quad_enable) - return 0; + if (nor->flags & SNOR_F_HAS_PARALLEL) { + params = spi_nor_get_params(nor, 0); + if (!params->quad_enable) + return 0; - if (!(spi_nor_get_protocol_width(nor->read_proto) == 4 || - spi_nor_get_protocol_width(nor->write_proto) == 4)) - return 0; - /* - * Set the appropriate CS index before - * issuing the command. - */ - nor->spimem->spi->cs_index_mask = 0x01 << idx; + if (!(spi_nor_get_protocol_width(nor->read_proto) == 4 || + spi_nor_get_protocol_width(nor->write_proto) == 4)) + return 0; + /* + * In parallel mode both chip selects i.e., CS0 & + * CS1 need to be asserted simulatneously. + */ + nor->spimem->spi->cs_index_mask = SPI_NOR_ENABLE_MULTI_CS; + err = params->quad_enable(nor); + if (err) + return err; + } else { + for (idx = 0; idx < SNOR_FLASH_CNT_MAX; idx++) { + params = spi_nor_get_params(nor, idx); + if (params) { + if (!params->quad_enable) + return 0; - err = params->quad_enable(nor); - if (err) - return err; + if (!(spi_nor_get_protocol_width(nor->read_proto) == 4 || + spi_nor_get_protocol_width(nor->write_proto) == 4)) + return 0; + /* + * Set the appropriate CS index before + * issuing the command. + */ + nor->spimem->spi->cs_index_mask = 1 << idx; + + err = params->quad_enable(nor); + if (err) + return err; + } } } return err; @@ -3385,16 +3596,27 @@ static int spi_nor_init(struct spi_nor *nor) */ WARN_ONCE(nor->flags & SNOR_F_BROKEN_RESET, "enabling reset hack; may not recover from unexpected reboots\n"); - for (idx = 0; idx < SNOR_FLASH_CNT_MAX; idx++) { - if (spi_nor_get_params(nor, idx)) { - /* - * Select the appropriate CS index before - * issuing the command. - */ - nor->spimem->spi->cs_index_mask = 0x01 << idx; - err = spi_nor_set_4byte_addr_mode(nor, true); - if (err) - return err; + if (nor->flags & SNOR_F_HAS_PARALLEL) { + /* + * In parallel mode both chip selects i.e., CS0 & + * CS1 need to be asserted simulatneously. + */ + nor->spimem->spi->cs_index_mask = SPI_NOR_ENABLE_MULTI_CS; + err = spi_nor_set_4byte_addr_mode(nor, true); + if (err) + return err; + } else { + for (idx = 0; idx < SNOR_FLASH_CNT_MAX; idx++) { + if (spi_nor_get_params(nor, idx)) { + /* + * Select the appropriate CS index before + * issuing the command. + */ + nor->spimem->spi->cs_index_mask = 1 << idx; + err = spi_nor_set_4byte_addr_mode(nor, true); + if (err) + return err; + } } } } @@ -3516,23 +3738,41 @@ static void spi_nor_restore(struct spi_nor *nor) /* restore the addressing mode */ if (nor->addr_nbytes == 4 && !(nor->flags & SNOR_F_4B_OPCODES) && nor->flags & SNOR_F_BROKEN_RESET) { - for (idx = 0; idx < SNOR_FLASH_CNT_MAX; idx++) { - if (spi_nor_get_params(nor, idx)) { + if (nor->flags & SNOR_F_HAS_PARALLEL) { + /* + * In parallel mode both chip selects i.e., CS0 & + * CS1 need to be asserted simulatneously. + */ + nor->spimem->spi->cs_index_mask = SPI_NOR_ENABLE_MULTI_CS; + spi_nor_set_4byte_addr_mode(nor, false); + if (ret) /* - * Select the appropriate CS index before - * issuing the command. + * Do not stop the execution in the hope that the flash + * will default to the 3-byte address mode after the + * software reset. */ - nor->spimem->spi->cs_index_mask = 1 << idx; - ret = spi_nor_set_4byte_addr_mode(nor, false); - if (ret) + dev_err(nor->dev, + "Failed to exit 4-byte address mode, err = %d\n", + ret); + } else { + for (idx = 0; idx < SNOR_FLASH_CNT_MAX; idx++) { + if (spi_nor_get_params(nor, idx)) { /* - * Do not stop the execution in the hope that the flash - * will default to the 3-byte address mode after the - * software reset. + * Select the appropriate CS index before + * issuing the command. */ - dev_err(nor->dev, - "Failed to exit 4-byte address mode, err = %d\n", - ret); + nor->spimem->spi->cs_index_mask = 1 << idx; + ret = spi_nor_set_4byte_addr_mode(nor, false); + if (ret) + /* + * Do not stop the execution in the hope that the + * flash will default to the 3-byte address mode + * after the software reset. + */ + dev_err(nor->dev, + "Failed to exit 4-byte address mode, err = %d\n", + ret); + } } } } @@ -3620,7 +3860,16 @@ static void spi_nor_set_mtd_info(struct spi_nor *nor) else mtd->_erase = spi_nor_erase; mtd->writesize = params->writesize; - mtd->writebufsize = params->page_size; + /* + * In parallel-memories the write operation is + * performed on both the flashes simultaneously + * one page per flash, so double the writebufsize. + */ + if (nor->flags & SNOR_F_HAS_PARALLEL) + mtd->writebufsize = params->page_size << 1; + else + mtd->writebufsize = params->page_size; + for (idx = 0; idx < SNOR_FLASH_CNT_MAX; idx++) { params = spi_nor_get_params(nor, idx); if (params) diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h index 89dc65a697b8..52bc8041a4f9 100644 --- a/drivers/mtd/spi-nor/core.h +++ b/drivers/mtd/spi-nor/core.h @@ -14,6 +14,9 @@ /* In single configuration enable CS0 */ #define SPI_NOR_ENABLE_CS0 BIT(0) +/* In parallel configuration enable multiple CS */ +#define SPI_NOR_ENABLE_MULTI_CS (BIT(0) | BIT(1)) + /* Standard SPI NOR flash operations. */ #define SPI_NOR_READID_OP(naddr, ndummy, buf, len) \ SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_RDID, 0), \ @@ -136,6 +139,7 @@ enum spi_nor_option_flags { SNOR_F_RWW = BIT(14), SNOR_F_ECC = BIT(15), SNOR_F_HAS_STACKED = BIT(16), + SNOR_F_HAS_PARALLEL = BIT(17), }; struct spi_nor_read_command { diff --git a/drivers/mtd/spi-nor/micron-st.c b/drivers/mtd/spi-nor/micron-st.c index 92d6b0e7512c..26a871c4fe98 100644 --- a/drivers/mtd/spi-nor/micron-st.c +++ b/drivers/mtd/spi-nor/micron-st.c @@ -335,6 +335,9 @@ static int micron_st_nor_read_fsr(struct spi_nor *nor, u8 *fsr) op.data.nbytes = 2; } + if (nor->flags & SNOR_F_HAS_PARALLEL) + op.data.nbytes = 2; + spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); ret = spi_mem_exec_op(nor->spimem, &op); @@ -346,6 +349,8 @@ static int micron_st_nor_read_fsr(struct spi_nor *nor, u8 *fsr) if (ret) dev_dbg(nor->dev, "error %d reading FSR\n", ret); + if (nor->flags & SNOR_F_HAS_PARALLEL) + fsr[0] &= fsr[1]; return ret; } From patchwork Thu May 11 07:31:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Mahapatra, Amit Kumar" X-Patchwork-Id: 1779802 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=MRbAoN9e; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=j7RrGtmV; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QH3YY33dnz214l for ; Thu, 11 May 2023 17:34:09 +1000 (AEST) 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=IN2Clte5/J77jnIBT5KrTaCx48PRU1Ys2xJ9Bb/qwHQ=; b=MRbAoN9eFLtoJP FNO6U8unbTkDdyC7vQqcqPWoiqCq8UchEvp221px15byjEk/c+zt9/vWdmKFoJKhUAzpQl4TpR0xe 1lbafv3jR2mhZGDnceXyfjmE0wu4d8xtaQEO1ETZiu0S5AkhlDz8j4J/S0M7AgPRWYVFexCtW5u3D 6LEAzOhTrJhfVY/Yr4UJnLiezJJeGphy5XeyNxYHQdNpr7rOPpjpENmMSMFGc020FrMZDYsmmIzGr alEjEmsrr8PqyzGagCwIJW6KUoXIG1GzLrODN0E1qPZ3eOxhL+xOn0rStxbUt5azb++m90YZABjPu Tk7dUEkcPL/rfEHsbXdg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1px0nw-0089S6-0y; Thu, 11 May 2023 07:33:36 +0000 Received: from mail-mw2nam04on20604.outbound.protection.outlook.com ([2a01:111:f400:7e8c::604] helo=NAM04-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1px0nt-0089Q3-1x; Thu, 11 May 2023 07:33:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YG4gBRCwahp2ovMCGmYbqqxD1bVjoOLHA9lTjG/A1oxIbFqrZDI84LWs121fVkLYV8wrdw6I5t9WvR1R+7jcFr3tHxvm0AGDCOlgH+jUWIPYJuLauiQ+fdJHS32ldYT0jG475uAC7ft8M85+jX0R8cJIv3g0XRmRe49CA0OOfBfBf20D/Q0HGHcKhCp1OOWWgxVVADXbfNABMEsqk0StCjS6Nqtcj6LMPy5Z7/wRDM0B1ZCssSVv0nIzqwM+bENIhWkXD6sG5OAHMa38spTQ6+KKH0aOkonwoz9uBAHTkNTZ8kGnrxU7FuAmX6YMmsB64n16ruaDKT0Nev5Rs4Sp8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=he65cIQQwqLcPUh0K7+4CXQr0jLidhcBa3blMtvOwsw=; b=S+9PYvX9nLZPQ+Z/guIVpp40rOprqd+jQcVcbqRTOFEu5xTFW9zBSUoMnKmNUIIjCskh0Dp6NM+rCcWDEA6D+7uOEzihAjTDPCksjocTjg/7oy5TNrXPAkORRUt5cCv+ErBDvZDm9yD1l34Tp580LH6gs/LSU3aA5izdJS2YjRThIyB/YkwiA6CTqJN6901Pwa6rFYVi4RFtuiF03hTFcbN3/saCE2gGJZdbBTSQuPVoxUJNzhEHeNYpWaKvTbuh8azG/63btZsvJzcnFXcyt7NJdIJC+z4NJkVSecyDgbnFhFvAIF5j1P5/SJNZ2+TBtqycICNrLoOz5nHHm2/TPQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=he65cIQQwqLcPUh0K7+4CXQr0jLidhcBa3blMtvOwsw=; b=j7RrGtmVn+CwvDpExd74nZkuXT15lZcHaEeq2A6zS2jVfCr9BZjx1utzfPbRrTTOFkXfRC1DCQkarbK+x5R5/8EOl690Oh0J0zXNQNAZYZLKCWWcWfA0ur/h8BDzKRH8UTuSuw+WFGL9Yw5rz2mZ7KB5RLrKefTDbD0QGiqRXYA= Received: from MWH0EPF00056D11.namprd21.prod.outlook.com (2603:10b6:30f:fff2:0:1:0:14) by BL1PR12MB5160.namprd12.prod.outlook.com (2603:10b6:208:311::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.18; Thu, 11 May 2023 07:33:23 +0000 Received: from CO1NAM11FT115.eop-nam11.prod.protection.outlook.com (2a01:111:f400:7eab::204) by MWH0EPF00056D11.outlook.office365.com (2603:1036:d20::b) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.5 via Frontend Transport; Thu, 11 May 2023 07:33:21 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT115.mail.protection.outlook.com (10.13.174.211) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6387.22 via Frontend Transport; Thu, 11 May 2023 07:33:21 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 11 May 2023 02:33:20 -0500 Received: from xhdakumarma40u.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Thu, 11 May 2023 02:33:16 -0500 From: Amit Kumar Mahapatra To: , , , , , , CC: , , , , , , , , , , , Amit Kumar Mahapatra Subject: [PATCH V8 7/7] spi: spi-zynqmp-gqspi: Add parallel memories support in GQSPI driver Date: Thu, 11 May 2023 13:01:34 +0530 Message-ID: <20230511073134.41180-8-amit.kumar-mahapatra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230511073134.41180-1-amit.kumar-mahapatra@amd.com> References: <20230511073134.41180-1-amit.kumar-mahapatra@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT115:EE_|BL1PR12MB5160:EE_ X-MS-Office365-Filtering-Correlation-Id: c3a40346-e233-49da-e6b2-08db51f1ff72 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /d4LnYtR7TJG+UlbcJ8tUE4yGYLjOPi8iHBeo9OhbKCP8s9AZ7SPkM5cjYeUjj99afh/GwJhx8NWm6l0+thRSJfRb40fITGcDYiI/LfrHfRZAbOBMUipi9ZQfqapRzsRL+XP2/D9Aqw6ve5UgQJPsBiGs+Y8loseW7jF4aZW0iH6gLJxML1ZLIzhX4ePp7b7B8bYcJNSLiWMkMea4vTKmdOw7IDQWnEB28Mp8fsuKa5cMPZHAO5YiQ0Cz+9zEMDfA3d4XZ5roOoWcqF60BgR6x96Ziiq2VolWBSTtzZ17udLF8r5j//NGe26bquC6mLnwe5fzQFEJo2Mt7wmmaqWJtkGnNO9qZfosDxRuQwWwLviDcbE1h1FtZR2SP8N6LzZTvA5DrDWEGH7KuSAS+k2bi0tglxokgWzSXf72ziI3c9d5HNjNxgLyVSf8vLRxhr3TcxGsy784+mCToJXc46qqxggRZQ8wc9tIinpmlmWuT+q+c/OwWgHn0EEPZN14fNNGNYxptS0aTuleaCdcOM886LlO6xD8iyQ2m83u2pRcQTZbO3UB0nKVfETtFy52b7QLfG5R2H0n+ZDwM8JbPYPkGIKTedDMrXXmBmEKoDdUbLpeFRCD+VsiojjsE2vTj7JzV1s8feoicU2krlre1QCuEGYcBe/xrXZXuodsT6EWzVXQASN3iDoiMwqOky7OGxDuwmEXcj7/61G/dJ2o0RVwPpEBW3vWbuiic4Ba4aw3DMEW6+qrBMPbwxySFFHI/9ib5aUACEc9HZameOxvZPGeg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(396003)(376002)(346002)(136003)(451199021)(40470700004)(36840700001)(46966006)(40480700001)(70206006)(82310400005)(70586007)(41300700001)(336012)(4326008)(316002)(426003)(82740400003)(110136005)(36756003)(40460700003)(356005)(83380400001)(54906003)(2906002)(81166007)(8936002)(8676002)(86362001)(7416002)(5660300002)(26005)(1076003)(186003)(36860700001)(47076005)(2616005)(478600001)(6666004)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 May 2023 07:33:21.6026 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c3a40346-e233-49da-e6b2-08db51f1ff72 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT115.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5160 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230511_003333_651274_D4AD0D86 X-CRM114-Status: GOOD ( 19.49 ) X-Spam-Score: 0.8 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: During probe GQSPI driver sets SPI_CONTROLLER_MULTI_CS bit in ctlr->flags for notifying SPI core about multi CS capability of the controller. In parallel mode the controller can either split the data [...] Content analysis details: (0.8 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 1.0 FORGED_SPF_HELO No description available. X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org During probe GQSPI driver sets SPI_CONTROLLER_MULTI_CS bit in ctlr->flags for notifying SPI core about multi CS capability of the controller. In parallel mode the controller can either split the data between both the flash or can send the same data to both the flashes, this is determined by the STRIPE bit. While sending commands to the flashes the GQSPI driver send the same command to both the flashes by resetting the STRIPE bit, but while writing/reading data to & from the flash the GQSPI driver splits the data evenly between both the flashes by setting the STRIPE bit. Signed-off-by: Amit Kumar Mahapatra --- drivers/spi/spi-zynqmp-gqspi.c | 39 +++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-zynqmp-gqspi.c b/drivers/spi/spi-zynqmp-gqspi.c index 3d2b92a88e8a..2b2b5c0385fc 100644 --- a/drivers/spi/spi-zynqmp-gqspi.c +++ b/drivers/spi/spi-zynqmp-gqspi.c @@ -23,6 +23,7 @@ #include #include #include +#include /* Generic QSPI register offsets */ #define GQSPI_CONFIG_OFST 0x00000100 @@ -192,6 +193,7 @@ struct qspi_platform_data { * @op_lock: Operational lock * @speed_hz: Current SPI bus clock speed in hz * @has_tapdelay: Used for tapdelay register available in qspi + * @is_parallel: Used for multi CS support */ struct zynqmp_qspi { struct spi_controller *ctlr; @@ -214,8 +216,33 @@ struct zynqmp_qspi { struct mutex op_lock; u32 speed_hz; bool has_tapdelay; + bool is_parallel; }; +/** + * zynqmp_gqspi_update_stripe - For GQSPI controller data stripe capabilities + * @op: Pointer to mem ops + * Return: Status of the data stripe + * + * Returns true if data stripe need to be enabled, else returns false + */ +bool zynqmp_gqspi_update_stripe(const struct spi_mem_op *op) +{ + if (op->cmd.opcode == SPINOR_OP_BE_4K || + op->cmd.opcode == SPINOR_OP_BE_32K || + op->cmd.opcode == SPINOR_OP_CHIP_ERASE || + op->cmd.opcode == SPINOR_OP_SE || + op->cmd.opcode == SPINOR_OP_BE_32K_4B || + op->cmd.opcode == SPINOR_OP_SE_4B || + op->cmd.opcode == SPINOR_OP_BE_4K_4B || + op->cmd.opcode == SPINOR_OP_WRSR || + op->cmd.opcode == SPINOR_OP_BRWR || + (op->cmd.opcode == SPINOR_OP_WRSR2 && !op->addr.nbytes)) + return false; + + return true; +} + /** * zynqmp_gqspi_read - For GQSPI controller read operation * @xqspi: Pointer to the zynqmp_qspi structure @@ -470,7 +497,14 @@ static void zynqmp_qspi_chipselect(struct spi_device *qspi, bool is_high) genfifoentry |= GQSPI_GENFIFO_MODE_SPI; - if (qspi->cs_index_mask & GQSPI_SELECT_UPPER_CS) { + if ((qspi->cs_index_mask & GQSPI_SELECT_LOWER_CS) && + (qspi->cs_index_mask & GQSPI_SELECT_UPPER_CS)) { + zynqmp_gqspi_selectslave(xqspi, + GQSPI_SELECT_FLASH_CS_BOTH, + GQSPI_SELECT_FLASH_BUS_BOTH); + if (!xqspi->is_parallel) + xqspi->is_parallel = true; + } else if (qspi->cs_index_mask & GQSPI_SELECT_UPPER_CS) { zynqmp_gqspi_selectslave(xqspi, GQSPI_SELECT_FLASH_CS_UPPER, GQSPI_SELECT_FLASH_BUS_LOWER); @@ -1139,6 +1173,8 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem, } if (op->data.nbytes) { + if (xqspi->is_parallel && zynqmp_gqspi_update_stripe(op)) + genfifoentry |= GQSPI_GENFIFO_STRIPE; reinit_completion(&xqspi->data_completion); if (op->data.dir == SPI_MEM_DATA_OUT) { xqspi->txbuf = (u8 *)op->data.buf.out; @@ -1334,6 +1370,7 @@ static int zynqmp_qspi_probe(struct platform_device *pdev) ctlr->bits_per_word_mask = SPI_BPW_MASK(8); ctlr->dev.of_node = np; ctlr->auto_runtime_pm = true; + ctlr->flags |= SPI_CONTROLLER_MULTI_CS; ret = devm_spi_register_controller(&pdev->dev, ctlr); if (ret) {