From patchwork Thu Jul 18 03:46:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alvin Zhou X-Patchwork-Id: 13736001 Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06AE23D552; Thu, 18 Jul 2024 03:47:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721274466; cv=none; b=kBORXxZtbDZW/7xZQlVzDMRH2iDu1EfgJFCAirUM1yG2uKYepxikQV9GXZQ3GzM82Ybs/83XcaNOc3iVWX1O3Kyqa3++VTTvMtJczqmTQf+6uDQpKajueMp/sAA6yF0bkD88rFn40+FUsP/sk1Wl+B3+SwdzRWhUF4g2xcDLrio= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721274466; c=relaxed/simple; bh=eFgwPU4n6/5dAs1L0wyfm9M3VthlXX1XC4xbvigP2tE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=t6c2hII+53p/CeYEdMj+P6sBkComBGXWhu3ITq2NNij13mQtxIaIjQKIKcJmcKgSPw16KR8swzIvosfJVIdOX7NyXfSLBwH0ImGXN2AoBZEy1vZWKo/X9Ml04MNRiPQbeo7gOfAGVjWW+/3kYnXSq0ySjDcnjF1zOJadmr0g/js= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=exhHyYCl; arc=none smtp.client-ip=209.85.215.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="exhHyYCl" Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-70b2421471aso208248a12.0; Wed, 17 Jul 2024 20:47:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721274464; x=1721879264; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pzLxElrWQ9zwK7gS/JxRiE2f82xa98E1x4NzX0Ply7k=; b=exhHyYClF18v+xJW+6m3T/zAwIc9kEhrYxjj8KG7xTeNhT5gqjDE5VpeG13ACthxhS 9FTfddM2boI2f1xGOb3WxrXvYPKmiZPAFgaE2ywfJY89rB8CAYFxceIJDaQz8rmje8O6 COvUrIjBWJC/m4oDA+9Ohqk/fwaDGfaAvpmGtGZn1SljdeykdfTSUY5WovnCLrt+x74S BIUipdykaiQeI/mMl27TPfQSdE68Tzvun3wKnuiO3Wlyz6QkJYh1thc2v0uj4au7Ei+y IEkCeEnXDPlf0SYBHmrTebs6qakZ26RGY982lcckSPjo4/bXn5H0VmCxej91rTAuYXxX HYbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721274464; x=1721879264; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pzLxElrWQ9zwK7gS/JxRiE2f82xa98E1x4NzX0Ply7k=; b=MII/kmvloZlmOYcMRDEmNMXIQ5wXaYJg99rSdYNL+rFodvoBOWPLlY1NPAROUGXqam R1NXCLo3vg0K4M+bITCHI6ttjLi+jIJYBYpmOBZPM201YFq5iDX+2cIPpJ3dWiqB5dkK BcIkAEHdLxn/lGNkPiCbTMo8UQrOvCAjJDEy4Rf0RGWiBOXeyYwVVJIAnSutzsQwz/zM WRHjOxVR6oaDZ+McQrvF4O/+aAHjcFG2WSLrooZCGCSBzskudes/+WI1T5tU5EtNd/i+ E/pE1BmRvf1eKf/xaZpcYM3U0g2H7A5GCeeS0lROJth2q8gwyyH4xf4jXSSab47ccA8Q jp2A== X-Forwarded-Encrypted: i=1; AJvYcCW2554AfDG2s2ZM070VJiNXIlFabbF5w6cfgGdWGVvmsuN78yfM/ljZmf+dSRaZk4IregnMvJYwjcr3qEh9AF6lLJe1B8fbLJE8louVPd3QsCWtPPPLGzq8R8OuhMGLJlW+BFQm/JcQ X-Gm-Message-State: AOJu0Yx11X1IEMHV7ddOkMcEPvjQlC+N5+TpzFNmN2FXjYKX6Eg2sVw4 KG5L0S7bHLOYLV2RHdi7ZpJBpXiSwk4GRsKM65kfUhjAcW+QnzKm X-Google-Smtp-Source: AGHT+IFr1OWqAhW4l4NG6tilVdQj6eglU6t3bObxxl3lVgpLLrts4FrIjsoB2bkVwVjv0ARFggj79A== X-Received: by 2002:a05:6a21:78a2:b0:1c0:f0be:1536 with SMTP id adf61e73a8af0-1c3fddb3cadmr4714398637.40.1721274464165; Wed, 17 Jul 2024 20:47:44 -0700 (PDT) Received: from twhmp6px (mxsmtp211.mxic.com.tw. [211.75.127.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fc265f9cccsm62394835ad.66.2024.07.17.20.47.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jul 2024 20:47:43 -0700 (PDT) Received: from hqs-appsw-a2o.mp600.macronix.com (linux-patcher [172.17.236.67]) by twhmp6px (Postfix) with ESMTPS id 65583800D3; Thu, 18 Jul 2024 11:56:55 +0800 (CST) From: AlvinZhou To: linux-mtd@lists.infradead.org, linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, tudor.ambarus@linaro.org, pratyush@kernel.org, mwalle@kernel.org, miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com, broonie@kernel.org Cc: chengminglin@mxic.com.tw, leoyu@mxic.com.tw, AlvinZhou , JaimeLiao Subject: [PATCH v9 1/6] mtd: spi-nor: add Octal DTR support for Macronix flash Date: Thu, 18 Jul 2024 11:46:09 +0800 Message-Id: <20240718034614.484018-2-alvinzhou.tw@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240718034614.484018-1-alvinzhou.tw@gmail.com> References: <20240718034614.484018-1-alvinzhou.tw@gmail.com> Precedence: bulk X-Mailing-List: linux-spi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: AlvinZhou Create Macronix specify method for enable Octal DTR mode and set 20 dummy cycles to allow running at the maximum supported frequency for Macronix Octal flash. Use number of dummy cycles which is parse by SFDP then convert it to bit pattern and set in CR2 register. Set CR2 register for enable octal DTR mode. Use Read ID to confirm that enabling/diabling octal DTR mode was successful. Macronix ID format is A-A-B-B-C-C in octal DTR mode. To ensure the successful enablement of octal DTR mode, confirm that the 6-byte data is entirely correct. Co-developed-by: Tudor Ambarus Signed-off-by: Tudor Ambarus Signed-off-by: JaimeLiao Signed-off-by: AlvinZhou --- drivers/mtd/spi-nor/macronix.c | 91 ++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/drivers/mtd/spi-nor/macronix.c b/drivers/mtd/spi-nor/macronix.c index ea6be95e75a5..f039819a5252 100644 --- a/drivers/mtd/spi-nor/macronix.c +++ b/drivers/mtd/spi-nor/macronix.c @@ -8,6 +8,24 @@ #include "core.h" +#define MXIC_NOR_OP_RD_CR2 0x71 /* Read configuration register 2 opcode */ +#define MXIC_NOR_OP_WR_CR2 0x72 /* Write configuration register 2 opcode */ +#define MXIC_NOR_ADDR_CR2_MODE 0x00000000 /* CR2 address for setting spi/sopi/dopi mode */ +#define MXIC_NOR_ADDR_CR2_DC 0x00000300 /* CR2 address for setting dummy cycles */ +#define MXIC_NOR_REG_DOPI_EN 0x2 /* Enable Octal DTR */ +#define MXIC_NOR_REG_SPI_EN 0x0 /* Enable SPI */ + +/* Convert dummy cycles to bit pattern */ +#define MXIC_NOR_REG_DC(p) \ + ((20 - (p)) >> 1) + +/* Macronix write CR2 operations */ +#define MXIC_NOR_WR_CR2(addr, ndata, buf) \ + SPI_MEM_OP(SPI_MEM_OP_CMD(MXIC_NOR_OP_WR_CR2, 0), \ + SPI_MEM_OP_ADDR(4, addr, 0), \ + SPI_MEM_OP_NO_DUMMY, \ + SPI_MEM_OP_DATA_OUT(ndata, buf, 0)) + static int mx25l25635_post_bfpt_fixups(struct spi_nor *nor, const struct sfdp_parameter_header *bfpt_header, @@ -185,6 +203,78 @@ static const struct flash_info macronix_nor_parts[] = { } }; +static int macronix_nor_octal_dtr_en(struct spi_nor *nor) +{ + struct spi_mem_op op; + u8 *buf = nor->bouncebuf, i; + int ret; + + /* Use dummy cycles which is parse by SFDP and convert to bit pattern. */ + buf[0] = MXIC_NOR_REG_DC(nor->params->reads[SNOR_CMD_READ_8_8_8_DTR].num_wait_states); + op = (struct spi_mem_op)MXIC_NOR_WR_CR2(MXIC_NOR_ADDR_CR2_DC, 1, buf); + ret = spi_nor_write_any_volatile_reg(nor, &op, nor->reg_proto); + if (ret) + return ret; + + /* Set the octal and DTR enable bits. */ + buf[0] = MXIC_NOR_REG_DOPI_EN; + op = (struct spi_mem_op)MXIC_NOR_WR_CR2(MXIC_NOR_ADDR_CR2_MODE, 1, buf); + ret = spi_nor_write_any_volatile_reg(nor, &op, nor->reg_proto); + if (ret) + return ret; + + /* Read flash ID to make sure the switch was successful. */ + ret = spi_nor_read_id(nor, 4, 4, buf, SNOR_PROTO_8_8_8_DTR); + if (ret) { + dev_dbg(nor->dev, "error %d reading JEDEC ID after enabling 8D-8D-8D mode\n", ret); + return ret; + } + + /* Macronix SPI-NOR flash 8D-8D-8D read ID would get 6 bytes data A-A-B-B-C-C */ + for (i = 0; i < nor->info->id->len; i++) + if (buf[i * 2] != buf[(i * 2) + 1] || buf[i * 2] != nor->info->id->bytes[i]) + return -EINVAL; + + return 0; +} + +static int macronix_nor_octal_dtr_dis(struct spi_nor *nor) +{ + struct spi_mem_op op; + u8 *buf = nor->bouncebuf; + int ret; + + /* + * The register is 1-byte wide, but 1-byte transactions are not + * allowed in 8D-8D-8D mode. Since there is no register at the + * next location, just initialize the value to 0 and let the + * transaction go on. + */ + buf[0] = MXIC_NOR_REG_SPI_EN; + buf[1] = 0x0; + op = (struct spi_mem_op)MXIC_NOR_WR_CR2(MXIC_NOR_ADDR_CR2_MODE, 2, buf); + ret = spi_nor_write_any_volatile_reg(nor, &op, SNOR_PROTO_8_8_8_DTR); + if (ret) + return ret; + + /* Read flash ID to make sure the switch was successful. */ + ret = spi_nor_read_id(nor, 0, 0, buf, SNOR_PROTO_1_1_1); + if (ret) { + dev_dbg(nor->dev, "error %d reading JEDEC ID after disabling 8D-8D-8D mode\n", ret); + return ret; + } + + if (memcmp(buf, nor->info->id->bytes, nor->info->id->len)) + return -EINVAL; + + return 0; +} + +static int macronix_nor_set_octal_dtr(struct spi_nor *nor, bool enable) +{ + return enable ? macronix_nor_octal_dtr_en(nor) : macronix_nor_octal_dtr_dis(nor); +} + static void macronix_nor_default_init(struct spi_nor *nor) { nor->params->quad_enable = spi_nor_sr1_bit6_quad_enable; @@ -194,6 +284,7 @@ static int 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; + nor->params->set_octal_dtr = macronix_nor_set_octal_dtr; return 0; } From patchwork Thu Jul 18 03:46:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alvin Zhou X-Patchwork-Id: 13736002 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F7DF38F91; Thu, 18 Jul 2024 03:47:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721274468; cv=none; b=kzL1edbuNwfzjiODPrsafnFfLxoAPwKO+/YfWVH95rqFWIliHb5I9qyj8Nu6TYH1CwpVMWV9pM7nNqiPlgPhpNnlHm6j4H+1O/F6E1HKYPid4kE60CE0MHC6ghpAzCp3nAWBxQzTdyNSXOBx6F9tnSmQBiKe5acomgo6imKsNZI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721274468; c=relaxed/simple; bh=G2dxNbG4cgMahPFPA7uDxxGN/vaF2v3jj/lh8Sbhkoc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qjOkXF/fzvgVJBda6SbA7kYg+kmYSYf6vZTGZOE9ZNpxVuRxhwHZTop7jL3ccaViRin672k1xIuU0yGFGDnONUf3AG8vYpPTCIlucjEpNV7ffuqLDFmzL8R/CqbEh0Nd26ZlybylIWur8MuA8ND5jvWxoeHJXcHySSkZXqxDjw4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=DhwE3yFV; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DhwE3yFV" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1fbfb7cdb54so3110885ad.2; Wed, 17 Jul 2024 20:47:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721274466; x=1721879266; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aiGhB9iAlrnpuT0nNXOC/VcBouLV1340qQn/2ASaTHE=; b=DhwE3yFVmPQW0INBwYVmcjPtZRt85HBX/ci3HFqeGKC1nfsLrfpfdA5r9gtDKksXUA le+wOiVYvVlq+7+cYR7+6iariQaEhxjnR4skBajU1vlLyCjNIpkixy0C/WIkQCHfuyxj 59/bXubuxlwoOVL6pWzHrWmE2R57tb8o4ii+cVEcuKai6jE2M5J+bYr8mFeV5ekISR1w PYNpAxnQj/LiQzXXab0DnhJ2T/BWNjM1GIwAX/2UCTXeDxGbSYkDaN4osZt6MZPGaiKp 58IItdNc/xQI8VR9Ds1J2YieCdIBXcifhfhVh/7T4/ZQsKkYb/ksxlnq7aImU/eA+TmJ /Njg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721274466; x=1721879266; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aiGhB9iAlrnpuT0nNXOC/VcBouLV1340qQn/2ASaTHE=; b=dXOJTamPdT1N94CNhZgDehbP5WEQy+GI+s9XlfnDxnemhWZ08NjR9U66yYUG94icH2 fqS0hCORbXuXt+fzLLJgxwQlaMVE7ZXdC8MEB0UjnuT+aAaoGNvuxb1j7JurlSTtxNuz 6p09ZbHQ2Vdvu6WMyl5Dp1t0IcvmojHbIwN/Jw2KzC4v8+elGCKz3c7p2W0dosTYv4Nw IdAcm6VMx8oP9nZ3FRirh0Jz/g0MRAjhxfCrMVj9wpqAbkZOE8abjtvQGy4/Y0i7rhiK xc3iE05UaqNVoy17+k5E4z6J0MExg3tM2FaDieOPyb8PeydbAt0MEzMAaS8zVJko1xkm lSCA== X-Forwarded-Encrypted: i=1; AJvYcCV4cFAzCCVzfwfTZSthedX/jl9C7TSS0ufJNCOQNKm5uA+bgmbzmVSyfC7iT44oPCW0OYoPRs70SRvzXUsGQtwOd39XSycXWWb6UgjV5q63j6MwTLB5ZAyqWYK9h1AhkYVx5H7CA9ge X-Gm-Message-State: AOJu0Yw2ctRo4IVSjKkuxS9t9dBUaZE5Tz2TelKW5cF0ToEMLYgVfpZB HFAxTht6/TTI/G3Ach7tcdOTYm9K9rJWIMj2sEtRd2Gdp0uDiwwb X-Google-Smtp-Source: AGHT+IHZgl9U0WUl8+4EuXclgpCb+62yP5nP7OnVXEfj9sPDD1BYRn8ossNcYdB2xJD+qRTSocLQsw== X-Received: by 2002:a17:902:dacc:b0:1fc:5ed5:ff51 with SMTP id d9443c01a7336-1fc5ed60186mr7628615ad.43.1721274465384; Wed, 17 Jul 2024 20:47:45 -0700 (PDT) Received: from twhmp6px (mxsmtp211.mxic.com.tw. [211.75.127.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fc54069156sm15587545ad.242.2024.07.17.20.47.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jul 2024 20:47:45 -0700 (PDT) Received: from hqs-appsw-a2o.mp600.macronix.com (linux-patcher [172.17.236.67]) by twhmp6px (Postfix) with ESMTPS id 72F7A805EF; Thu, 18 Jul 2024 11:56:56 +0800 (CST) From: AlvinZhou To: linux-mtd@lists.infradead.org, linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, tudor.ambarus@linaro.org, pratyush@kernel.org, mwalle@kernel.org, miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com, broonie@kernel.org Cc: chengminglin@mxic.com.tw, leoyu@mxic.com.tw, AlvinZhou , JaimeLiao Subject: [PATCH v9 2/6] spi: spi-mem: Allow specifying the byte order in Octal DTR mode Date: Thu, 18 Jul 2024 11:46:10 +0800 Message-Id: <20240718034614.484018-3-alvinzhou.tw@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240718034614.484018-1-alvinzhou.tw@gmail.com> References: <20240718034614.484018-1-alvinzhou.tw@gmail.com> Precedence: bulk X-Mailing-List: linux-spi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: AlvinZhou From: Tudor Ambarus There are NOR flashes (Macronix) that swap the bytes on a 16-bit boundary when configured in Octal DTR mode. The byte order of 16-bit words is swapped when read or written in Octal Double Transfer Rate (DTR) mode compared to Single Transfer Rate (STR) modes. If one writes D0 D1 D2 D3 bytes using 1-1-1 mode, and uses 8D-8D-8D SPI mode for reading, it will read back D1 D0 D3 D2. Swapping the bytes may introduce some endianness problems. It can affect the boot sequence if the entire boot sequence is not handled in either 8D-8D-8D mode or 1-1-1 mode. Therefore, it is necessary to swap the bytes back to ensure the same byte order as in STR modes. Fortunately there are controllers that could swap the bytes back at runtime, addressing the flash's endiannesses requirements. Provide a way for the upper layers to specify the byte order in Octal DTR mode. Merge Tudor's patch and add modifications for suiting newer version of Linux kernel. Suggested-by: Michael Walle Signed-off-by: Tudor Ambarus Signed-off-by: JaimeLiao Signed-off-by: AlvinZhou Acked-by: Mark Brown --- drivers/spi/spi-mem.c | 3 +++ include/linux/spi/spi-mem.h | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c index 17b8baf749e6..abc6792e738c 100644 --- a/drivers/spi/spi-mem.c +++ b/drivers/spi/spi-mem.c @@ -172,6 +172,9 @@ bool spi_mem_default_supports_op(struct spi_mem *mem, if (!spi_mem_controller_is_capable(ctlr, dtr)) return false; + if (op->data.swap16 && !spi_mem_controller_is_capable(ctlr, swap16)) + return false; + if (op->cmd.nbytes != 2) return false; } else { diff --git a/include/linux/spi/spi-mem.h b/include/linux/spi/spi-mem.h index f866d5c8ed32..c46d2b8029be 100644 --- a/include/linux/spi/spi-mem.h +++ b/include/linux/spi/spi-mem.h @@ -90,6 +90,8 @@ enum spi_mem_data_dir { * @data.buswidth: number of IO lanes used to send/receive the data * @data.dtr: whether the data should be sent in DTR mode or not * @data.ecc: whether error correction is required or not + * @data.swap16: whether the byte order of 16-bit words is swapped when read + * or written in Octal DTR mode compared to STR mode. * @data.dir: direction of the transfer * @data.nbytes: number of data bytes to send/receive. Can be zero if the * operation does not involve transferring data @@ -124,7 +126,8 @@ struct spi_mem_op { u8 buswidth; u8 dtr : 1; u8 ecc : 1; - u8 __pad : 6; + u8 swap16 : 1; + u8 __pad : 5; enum spi_mem_data_dir dir; unsigned int nbytes; union { @@ -297,10 +300,13 @@ struct spi_controller_mem_ops { * struct spi_controller_mem_caps - SPI memory controller capabilities * @dtr: Supports DTR operations * @ecc: Supports operations with error correction + * @swap16: Supports swapping bytes on a 16 bit boundary when configured in + * Octal DTR */ struct spi_controller_mem_caps { bool dtr; bool ecc; + bool swap16; }; #define spi_mem_controller_is_capable(ctlr, cap) \ From patchwork Thu Jul 18 03:46:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alvin Zhou X-Patchwork-Id: 13736003 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5860639FE4; Thu, 18 Jul 2024 03:47:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721274468; cv=none; b=miBo4yg+BN/hTBiNch5j2J6yDFF05PFmVac6VQQNInwSI1dLlL3/tCa4hFXNIeRhVGYr1Mzcyuc5xfzT12XkogJbS+oYVcME4cWqhth/aQ/dFLi2S9mLxlr+C4ePqKYmLUIPUn3F8rVvXdKBoITWF7QVF2+3ux/3eZeu9GZya08= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721274468; c=relaxed/simple; bh=YfVErJFWvQAjc+YAokwbZxUEeqlwW35HO2SBJoUvN7c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Gu8aJcn731yfzo0ybSKXG3imAxUOPyDHHotb+eIiJ7K9BHrI/3J33KW4i4wUlp9L+VNgmg41brcesGKUL0mks2gS5HPWB4im3HRuDL6y27BuTBi435mbl+1Vnw4HISR6W69qt1VjmSULAMdiJa5rgv2U2/F5bl/+QojxKh6MeRc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=iuKqI5h7; arc=none smtp.client-ip=209.85.210.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iuKqI5h7" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-70b0bc1ef81so265514b3a.1; Wed, 17 Jul 2024 20:47:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721274466; x=1721879266; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RGxTXo990ti5lAyVI8ZehxzUFXPwz6MqQx7qAzjMfhw=; b=iuKqI5h7yvwsRKP6p4oI3bkqNqCOiYfuKShoNX6wE9RPA4eF43a7qcjN4aeWwbmWhi mB8/XDtY/JKmtl7T5DzYDfubEtGlWgVSPUM4ZCxgaQaQBDVNLhC3fdLglH00oLqnzY0E JNwwF37K55FoczBJiUpmgjwgK2KyOBJvJbpBVGwlkjfuAHHHsrT/FFEVap/7CNkDbfhd 4nXr3ExOWr1V2xKVWl57bNg6Yd/F4Naqfu3i1ugxjzVH+nlBh+UpHCoLRysbi8H3atnk 6ChU+JnGUMhesjcC/C6ree1pDm/L16yaRnEo8htrWx6tAyMsWpqPzx79wg+rMf5JJSZb R4VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721274466; x=1721879266; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RGxTXo990ti5lAyVI8ZehxzUFXPwz6MqQx7qAzjMfhw=; b=NHTra0L6I8nrskdkLoG7VcPecaXjp1MVIbskI/qpaieeVJNMQcdkjDBCOoh3IiT0Os QfEOUPvubBMqyKxju6PVyyoxq6CZcBELRwQnOEJqFu2ufHSak/Mo3NLWV6Q7j1X1wESw CHk9r74Czz9JEMhvJdd0E/NqOPUTiwdRuE8ottUxDQ1rzCtzHVl6OaFWKDLQunS/s/rD BE3F47ieBLsy1Szmvgzq01nkxjWM8pzuEQIhYdheqNbUrZ+OISJFa7Y8Z1Pbq9TeojtO 3dsd+2RUNoA10BhWM6xVvKoOZYIoUg0mC8WgO7nOqn3bYBVFPz2TwdvuDFzbMGys6a0c 1ZFg== X-Forwarded-Encrypted: i=1; AJvYcCW2KLQ3rQHvvBTZTdP2pBPCSSgTgitkmINH96DbS6YcdEdpGo8KvBvRTo2T4My44888taM0opA/YtPoSvE2+CJO6H9hZ0D/X+mVyvJngv0COAs0KP0UyKtSazRpYXWkLqW+ZnvWatRx X-Gm-Message-State: AOJu0Yz0kOQpEVoa2BdcX3bOQMnlm382jSBfWN3rAq8ix2WCMl4eSNUC LKyuwPkD/B8uX4QnQFz3kYsx1qSBJZcC9Hd3IyOA5hGbQkRetvLT X-Google-Smtp-Source: AGHT+IFHhgdm/fpkHpJp5xeIvoQlchgAmcADiPZHZAKYg0ls+CPuWC+Msqnn+IJRt9GxdMHY5Hry0A== X-Received: by 2002:a05:6a00:23c3:b0:704:32dc:c4e4 with SMTP id d2e1a72fcca58-70ce4d8392bmr4782637b3a.1.1721274466500; Wed, 17 Jul 2024 20:47:46 -0700 (PDT) Received: from twhmp6px (mxsmtp211.mxic.com.tw. [211.75.127.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70b7ecabf2fsm8838583b3a.182.2024.07.17.20.47.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jul 2024 20:47:46 -0700 (PDT) Received: from hqs-appsw-a2o.mp600.macronix.com (linux-patcher [172.17.236.67]) by twhmp6px (Postfix) with ESMTPS id 5B94580720; Thu, 18 Jul 2024 11:56:57 +0800 (CST) From: AlvinZhou To: linux-mtd@lists.infradead.org, linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, tudor.ambarus@linaro.org, pratyush@kernel.org, mwalle@kernel.org, miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com, broonie@kernel.org Cc: chengminglin@mxic.com.tw, leoyu@mxic.com.tw, AlvinZhou , JaimeLiao Subject: [PATCH v9 3/6] mtd: spi-nor: core: Allow specifying the byte order in Octal DTR mode Date: Thu, 18 Jul 2024 11:46:11 +0800 Message-Id: <20240718034614.484018-4-alvinzhou.tw@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240718034614.484018-1-alvinzhou.tw@gmail.com> References: <20240718034614.484018-1-alvinzhou.tw@gmail.com> Precedence: bulk X-Mailing-List: linux-spi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: AlvinZhou From: Tudor Ambarus Macronix swaps bytes on a 16-bit boundary when configured in Octal DTR. The byte order of 16-bit words is swapped when read or written in 8D-8D-8D mode compared to STR modes. Allow operations to specify the byte order in DTR mode, so that controllers can swap the bytes back at run-time to address the flash's endianness requirements, if they are capable. If the controller is not capable of swapping the bytes, the protocol is downgrade via spi_nor_spimem_adjust_hwcaps(). When available, the swapping of the bytes is always done regardless if it's a data or register access, so that it comply with the JESD216 requirements: "Byte order of 16-bit words is swapped when read in 8D-8D-8D mode compared to 1-1-1". Merge Tudor's patch and add modifications for suiting newer version of Linux kernel. Suggested-by: Michael Walle Signed-off-by: Tudor Ambarus Signed-off-by: JaimeLiao Signed-off-by: AlvinZhou --- drivers/mtd/spi-nor/core.c | 4 ++++ drivers/mtd/spi-nor/core.h | 1 + 2 files changed, 5 insertions(+) diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c index 028514c6996f..31f57b17023f 100644 --- a/drivers/mtd/spi-nor/core.c +++ b/drivers/mtd/spi-nor/core.c @@ -113,6 +113,10 @@ void spi_nor_spimem_setup_op(const struct spi_nor *nor, op->cmd.opcode = (op->cmd.opcode << 8) | ext; op->cmd.nbytes = 2; } + + /* SWAP16 is only applicable when Octal DTR mode */ + if (proto == SNOR_PROTO_8_8_8_DTR && nor->flags & SNOR_F_SWAP16) + op->data.swap16 = true; } /** diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h index 442786685515..baf6c4b5912b 100644 --- a/drivers/mtd/spi-nor/core.h +++ b/drivers/mtd/spi-nor/core.h @@ -140,6 +140,7 @@ enum spi_nor_option_flags { SNOR_F_RWW = BIT(14), SNOR_F_ECC = BIT(15), SNOR_F_NO_WP = BIT(16), + SNOR_F_SWAP16 = BIT(17), }; struct spi_nor_read_command { From patchwork Thu Jul 18 03:46:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alvin Zhou X-Patchwork-Id: 13736004 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F30E3FBB3; Thu, 18 Jul 2024 03:47:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721274469; cv=none; b=FEOO6o6LBF3O+lzG86vEEyQAa/BMeCZ5yQLwpmLvfgDwGpE55DI1qLz+O9yoOQRoNQHy2qa3toousBgmVr1OD0u3wQEtxXZmdMXFfZHo6uo4S9oRIqFnMHwAWH+amGiBlcuF/Ns3BTcdsHrAWj6JtE41IGt2dnIQxrX389c+qbg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721274469; c=relaxed/simple; bh=9YsmCa6ahFQU4Baxm5f/jlWl9GbUPNUOqqm4AInViWI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=D/eT7Ewn5GocHxjcG6XbKlnX0+au0WbuORiqh/x09KJd8XhQv3LJY31PAYYpijc2miYnPA3saIRCWCQkGhAhM6sH2leybwLiBvAeUQXi4yXsPVr5pFogGTYjHRYXJwBm/cYzN3Vv/cjyEli/54RJHfcPrlOx1BhjaWm6Hp00dtw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=CW43qU+L; arc=none smtp.client-ip=209.85.210.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CW43qU+L" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-70b05260c39so269670b3a.0; Wed, 17 Jul 2024 20:47:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721274467; x=1721879267; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zK8A6fJKM9NFmReipLfzB3Jrm/Kc3i4yYA6+cJCoL4w=; b=CW43qU+LJ72zgaYTjJhz4PhxM7zSqBtOAiI2VGMh7slLzCUYLvrL49crfncOcGuR4f 1qg28y3OpcLITPDKewZE4VBMdM8dpqBDuDDhiNS4SFkFSJ5ctLqw6Muyp5eKZFe+b0WL O9xTkBpZdC60LQPa6RHlEyt+IDibAESe777TexeKY+KnB/pL4z6cVTqQ24mPdi/2tdJc XKI0l+WYvCwXgSnEqspMhySNw9gAn1jwN+GdZvV4ckDKEUlX+AV3ya7FjtYQgd7vszkj sq5w01BrHRzMAs6ulO9YoTIiuS4Jkew9GdJkXKOfnThJHwi2HwMR0cEu9G83kjCuv3Fk W3+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721274467; x=1721879267; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zK8A6fJKM9NFmReipLfzB3Jrm/Kc3i4yYA6+cJCoL4w=; b=ZemGPQfn4nysvTHv0xWvM/BsvO2T/8FzbkHZaJbONiF4BD1Eqd9xYnOaKlvi4cqawM Qzkn2t7AA/kDz2IonsEIdmEz2chu1lChWPq9nvvDjJr0iyvNxamw/rcsi3NNsCJw4zFQ khhM1wPKuNzMU41ytwlhnv3JSfnFG9Kyeeyq5BomMDRPqNNG3pW+GXkaHRiQhTQwcj/W 6znItrMe4kFwmYkP9cMcG/hM8zVtP9oS7jdhXIfUN4WARRXdHn2mhTHwNtId2p00CR/I Kul1ixo2WC7RiQVHzbeYuX/+NbZgMO61eEMlbzHnbaZefVV6ivY4lp0JQpegtj9FR8jh xxBQ== X-Forwarded-Encrypted: i=1; AJvYcCUKS+yxA7EgX8k6zf4tcH0kbJp7ztNWonex1HHI6wbEawG/PxYapx2vT5A83eVulu5ujnHHeI4cDiUR+T7TRvEXrFRVA/2rct+RxoSOMbnm7Vd30xUtmm/a/jIEH2z3qw5WwbCbfnvb X-Gm-Message-State: AOJu0Yz/b1O69ZLbo1vyPEDnNFST4vSfVrm9UCfL1osCnircZl/BtPYm Wx/H5gshxJJ8enF68NpayCW+P8BfzGdUXgwEkzvlRcMeWnagWRdg X-Google-Smtp-Source: AGHT+IHcTZWJKp3I6YvIAQebjFHORQTS8t4I/7NrZuEmULEE/tJlq9btyx9tt8pVYcgcxlGPtM4xQg== X-Received: by 2002:a05:6a20:db0c:b0:1be:c2f7:275 with SMTP id adf61e73a8af0-1c3fdd5afffmr3572006637.50.1721274467440; Wed, 17 Jul 2024 20:47:47 -0700 (PDT) Received: from twhmp6px (mxsmtp211.mxic.com.tw. [211.75.127.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fc62e57d6csm1770455ad.43.2024.07.17.20.47.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jul 2024 20:47:47 -0700 (PDT) Received: from hqs-appsw-a2o.mp600.macronix.com (linux-patcher [172.17.236.67]) by twhmp6px (Postfix) with ESMTPS id 53C0F800D3; Thu, 18 Jul 2024 11:56:58 +0800 (CST) From: AlvinZhou To: linux-mtd@lists.infradead.org, linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, tudor.ambarus@linaro.org, pratyush@kernel.org, mwalle@kernel.org, miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com, broonie@kernel.org Cc: chengminglin@mxic.com.tw, leoyu@mxic.com.tw, AlvinZhou , JaimeLiao Subject: [PATCH v9 4/6] mtd: spi-nor: sfdp: Get the 8D-8D-8D byte order from BFPT Date: Thu, 18 Jul 2024 11:46:12 +0800 Message-Id: <20240718034614.484018-5-alvinzhou.tw@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240718034614.484018-1-alvinzhou.tw@gmail.com> References: <20240718034614.484018-1-alvinzhou.tw@gmail.com> Precedence: bulk X-Mailing-List: linux-spi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: AlvinZhou From: Tudor Ambarus Parse BFPT in order to retrieve the byte order in 8D-8D-8D mode. This info flag will be used as a basis to determine whether there is byte swapping of data for SPI NOR flash in octal DTR mode. The controller driver will check whether byte swapping is supported to determin whether the corresponding operation are supported, thus avoiding the generation of unexpected data order. Merge Tudor's patch and add modifications for suiting newer version of Linux kernel. Reviewed-by: Michael Walle Signed-off-by: Tudor Ambarus Signed-off-by: JaimeLiao Signed-off-by: AlvinZhou --- drivers/mtd/spi-nor/sfdp.c | 4 ++++ drivers/mtd/spi-nor/sfdp.h | 1 + 2 files changed, 5 insertions(+) diff --git a/drivers/mtd/spi-nor/sfdp.c b/drivers/mtd/spi-nor/sfdp.c index 5b1117265bd2..21727f9a4ac6 100644 --- a/drivers/mtd/spi-nor/sfdp.c +++ b/drivers/mtd/spi-nor/sfdp.c @@ -671,6 +671,10 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor, return -EOPNOTSUPP; } + /* Byte order in 8D-8D-8D mode */ + if (bfpt.dwords[SFDP_DWORD(18)] & BFPT_DWORD18_BYTE_ORDER_SWAPPED) + nor->flags |= SNOR_F_SWAP16; + return spi_nor_post_bfpt_fixups(nor, bfpt_header, &bfpt); } diff --git a/drivers/mtd/spi-nor/sfdp.h b/drivers/mtd/spi-nor/sfdp.h index da0fe5aa9bb0..d90cbd7331f7 100644 --- a/drivers/mtd/spi-nor/sfdp.h +++ b/drivers/mtd/spi-nor/sfdp.h @@ -130,6 +130,7 @@ struct sfdp_bfpt { #define BFPT_DWORD18_CMD_EXT_INV (0x1UL << 29) /* Invert */ #define BFPT_DWORD18_CMD_EXT_RES (0x2UL << 29) /* Reserved */ #define BFPT_DWORD18_CMD_EXT_16B (0x3UL << 29) /* 16-bit opcode */ +#define BFPT_DWORD18_BYTE_ORDER_SWAPPED BIT(31) /* Byte sawp of 16-bit in 8D-8D-8D mode */ struct sfdp_parameter_header { u8 id_lsb; From patchwork Thu Jul 18 03:46:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alvin Zhou X-Patchwork-Id: 13736005 Received: from mail-oa1-f42.google.com (mail-oa1-f42.google.com [209.85.160.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BF8842052; Thu, 18 Jul 2024 03:47:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721274470; cv=none; b=LpeS++nGIBP1HhNShENzyhSwgnt8f/XV5YFfDdWLrbxTmfrRwxekXZMeSFhiIIiyqVExOCYh3g76a1Li7qoQz/H7mzsKduokFBjjRR1C3EmsSYAjYHRAH0NhjR+nfqCDJwFb7dKUTRdqs5dNxZLIaB0MnkL3R5u7HISTorbRm9w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721274470; c=relaxed/simple; bh=UEoZSelr2KPIegbn/bEtJV87t2Bt8f42OAG2gEzC8vY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=M8NX4XKBYis6ccrXo7Ojrmhwwt2lCli34NOSnZSw5vHYaWYXxq33v/UGHrutg2M/aPmWlfpHlnVRMRI01n9kCnZj7XaDoOl+Vltah9x7gr5H3mhrKSiTiQqHF2atJBuCTaQnT7CQBE7hARjFWEKWRLOk0ZrCspHccmqO8qb+VPs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=C8XG4zWw; arc=none smtp.client-ip=209.85.160.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="C8XG4zWw" Received: by mail-oa1-f42.google.com with SMTP id 586e51a60fabf-260e1b5576aso217108fac.1; Wed, 17 Jul 2024 20:47:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721274468; x=1721879268; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9EhTny12E54Go3rv+a0bpkdQLZomTRFj3isNr2azzvc=; b=C8XG4zWwgQoyRWkKBzue11LlN9Y8GPyzKZ/fg1+JLH8Qv18sk7pAuzSudv0LIrIH1B fE9YnY5ZZ+dHmfSL2GJiUQIQNd7VNp1yb73iM2xD/cHQredL51/Jxk6HYJs7CdySCkyr oFQ2CwutzstVrdREMcgyRalDWaVWOvHnKiVvBCg6qIg6+zu/ruGbjmlfhCBC7ZbriJld 45PL/ew4igTIPMVtjTstjDbHJrr9ywyVKWBAodenwTCMGi27Hjurp2lSafixwOgeQ1wv axXICvljxlrq3XWMF5LlRkanK4RB4eXh9Mpr6ldFAnwRnUw6Byefliyic0pm/WKJXpug PEUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721274468; x=1721879268; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9EhTny12E54Go3rv+a0bpkdQLZomTRFj3isNr2azzvc=; b=gGF9Ygkw0PVnH9txqPwR6QPvGNF2yrb3Vc4QrksLnyC7Cij08LYyHGmWivNIuyYvLz OHlj7OcAw7kLR32ZDBeKpLwqrpF2I2L5RjEmYM4E5PRmSCOwFnxq4Im+I5MAdmcQvnpu uW8fcx3m5Y/2+6SztpjWTOWnEusELyCmwmr5ElpYTRTbkh0mo2EYcfilM4u3ynKN3ljM SFLYQvGl8ocKEiL+xYoTuBOLtYmiRjiUtzQKEBTGcIs06Ukf/FWWaHQRTQmCfvjizeub oiRPCRtG1+qQ/Sswle4PvRmX+kAqoQz8mhnlQbMn/gAh2YOK1OSJ2gQK0vVs8I5SbyPU dikg== X-Forwarded-Encrypted: i=1; AJvYcCUKLNP+fY5VhxGaCVnBNAgVc9iJE8TA2TAWvr3hz5yMpZQQwgTmS64N6aZqKP7nNJV7Bhq/UPLYfzoKy2NO9sbsXhym0rmbFJWkNvm4stSekLxiuJEjpmAynF5ZHSE7KwFEYJuaMK4/ X-Gm-Message-State: AOJu0Yye7giFXgd4fC+p9ynNvCZFbKAJMdKOyYqxjUN7jUSztbkS/nlB cDReUZX7cQkZcrQ/4eclMEEw1T/niLEYlq4yy+OJbKA0fqaYnB/lEfWpNw== X-Google-Smtp-Source: AGHT+IHjdPa9dL94vVwe22uz34q6kOz56dIpRCh5BR8NxoERYLhhAaF0RaRLuSjVEwoiIkL7YKkVuQ== X-Received: by 2002:a05:6870:2312:b0:25e:d90:fe78 with SMTP id 586e51a60fabf-260d913efeemr3304888fac.8.1721274468237; Wed, 17 Jul 2024 20:47:48 -0700 (PDT) Received: from twhmp6px (mxsmtp211.mxic.com.tw. [211.75.127.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70b7ecd27f7sm8854360b3a.218.2024.07.17.20.47.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jul 2024 20:47:47 -0700 (PDT) Received: from hqs-appsw-a2o.mp600.macronix.com (linux-patcher [172.17.236.67]) by twhmp6px (Postfix) with ESMTPS id 1D11280B09; Thu, 18 Jul 2024 11:56:59 +0800 (CST) From: AlvinZhou To: linux-mtd@lists.infradead.org, linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, tudor.ambarus@linaro.org, pratyush@kernel.org, mwalle@kernel.org, miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com, broonie@kernel.org Cc: chengminglin@mxic.com.tw, leoyu@mxic.com.tw, AlvinZhou , JaimeLiao Subject: [PATCH v9 5/6] spi: mxic: Add support for swapping byte Date: Thu, 18 Jul 2024 11:46:13 +0800 Message-Id: <20240718034614.484018-6-alvinzhou.tw@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240718034614.484018-1-alvinzhou.tw@gmail.com> References: <20240718034614.484018-1-alvinzhou.tw@gmail.com> Precedence: bulk X-Mailing-List: linux-spi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: AlvinZhou Some SPI-NOR flash swap the bytes on a 16-bit boundary when configured in Octal DTR mode. It means data format D0 D1 D2 D3 would be swapped to D1 D0 D3 D2. So that whether controller support swapping bytes should be checked before enable Octal DTR mode. Add swap byte support on a 16-bit boundary when configured in Octal DTR mode for Macronix xSPI host controller dirver. According dtr_swab in operation to enable/disable Macronix xSPI host controller swap byte feature. To make sure swap byte feature is working well, program data in 1S-1S-1S mode then read back and compare read data in 8D-8D-8D mode. This feature have been validated on byte-swap flash and non-byte-swap flash. Macronix xSPI host controller bit "HC_CFG_DATA_PASS" determine the byte swap feature disabled/enabled and swap byte feature is working on 8D-8D-8D mode only. Suggested-by: Michael Walle Signed-off-by: JaimeLiao Signed-off-by: AlvinZhou Acked-by: Mark Brown --- drivers/spi/spi-mxic.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi-mxic.c b/drivers/spi/spi-mxic.c index 6156d691630a..f4e2f506bb2a 100644 --- a/drivers/spi/spi-mxic.c +++ b/drivers/spi/spi-mxic.c @@ -294,7 +294,8 @@ static void mxic_spi_hw_init(struct mxic_spi *mxic) mxic->regs + HC_CFG); } -static u32 mxic_spi_prep_hc_cfg(struct spi_device *spi, u32 flags) +static u32 mxic_spi_prep_hc_cfg(struct spi_device *spi, u32 flags, + bool swap16) { int nio = 1; @@ -305,6 +306,11 @@ static u32 mxic_spi_prep_hc_cfg(struct spi_device *spi, u32 flags) else if (spi->mode & (SPI_TX_DUAL | SPI_RX_DUAL)) nio = 2; + if (swap16) + flags &= ~HC_CFG_DATA_PASS; + else + flags |= HC_CFG_DATA_PASS; + return flags | HC_CFG_NIO(nio) | HC_CFG_TYPE(spi_get_chipselect(spi, 0), HC_CFG_TYPE_SPI_NOR) | HC_CFG_SLV_ACT(spi_get_chipselect(spi, 0)) | HC_CFG_IDLE_SIO_LVL(1); @@ -397,7 +403,8 @@ static ssize_t mxic_spi_mem_dirmap_read(struct spi_mem_dirmap_desc *desc, if (WARN_ON(offs + desc->info.offset + len > U32_MAX)) return -EINVAL; - writel(mxic_spi_prep_hc_cfg(desc->mem->spi, 0), mxic->regs + HC_CFG); + writel(mxic_spi_prep_hc_cfg(desc->mem->spi, 0, desc->info.op_tmpl.data.swap16), + mxic->regs + HC_CFG); writel(mxic_spi_mem_prep_op_cfg(&desc->info.op_tmpl, len), mxic->regs + LRD_CFG); @@ -441,7 +448,8 @@ static ssize_t mxic_spi_mem_dirmap_write(struct spi_mem_dirmap_desc *desc, if (WARN_ON(offs + desc->info.offset + len > U32_MAX)) return -EINVAL; - writel(mxic_spi_prep_hc_cfg(desc->mem->spi, 0), mxic->regs + HC_CFG); + writel(mxic_spi_prep_hc_cfg(desc->mem->spi, 0, desc->info.op_tmpl.data.swap16), + mxic->regs + HC_CFG); writel(mxic_spi_mem_prep_op_cfg(&desc->info.op_tmpl, len), mxic->regs + LWR_CFG); @@ -518,7 +526,7 @@ static int mxic_spi_mem_exec_op(struct spi_mem *mem, if (ret) return ret; - writel(mxic_spi_prep_hc_cfg(mem->spi, HC_CFG_MAN_CS_EN), + writel(mxic_spi_prep_hc_cfg(mem->spi, HC_CFG_MAN_CS_EN, op->data.swap16), mxic->regs + HC_CFG); writel(HC_EN_BIT, mxic->regs + HC_EN); @@ -572,6 +580,7 @@ static const struct spi_controller_mem_ops mxic_spi_mem_ops = { static const struct spi_controller_mem_caps mxic_spi_mem_caps = { .dtr = true, + .swap16 = true, .ecc = true, }; From patchwork Thu Jul 18 03:46:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alvin Zhou X-Patchwork-Id: 13736006 Received: from mail-oi1-f179.google.com (mail-oi1-f179.google.com [209.85.167.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70058481A7; Thu, 18 Jul 2024 03:47:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721274471; cv=none; b=bUKnbUmSt7NiR7TpMrWP7XJanjO3QR54OYHM4cbx6jO95MFEAYxnut/7Hn/0zRMt5ZmU73S8gd4gXKr9L/aLz8MBLN5oPHUg2XX7FWE7zFzLm8xHX0DOZFyurGJ5USPb5QpHr1b0T55eTT4WRnNMDBSTiUA2KNSdcE8W1QT6nVo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721274471; c=relaxed/simple; bh=F14fWKV1q9X6qHHW9Bq+NyKhnV5NFHLtS1NGnf+0VHE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fWz23ZdItrrdr9FwDxgceu330gShUvNwJ6O+Is5KIWaX9FAruKEUG4qZuw7tAd8kDPm2573Y1Q7tNIYkleR2w2mvNKzR5EIVR+Vj0YjVcE0ylDWQOWo4ffLIjPTIOR+FyGQYDUMwQGixs79FoSF7YmlwdHrY7RuLpMl5fbmcPoY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TDwyAmke; arc=none smtp.client-ip=209.85.167.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TDwyAmke" Received: by mail-oi1-f179.google.com with SMTP id 5614622812f47-3d93df6b54dso176120b6e.2; Wed, 17 Jul 2024 20:47:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721274469; x=1721879269; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Y5/8Zslr1MP/58mqMHISewZsB2/gBp8DHMSTzEl4QGQ=; b=TDwyAmke0nfGO8uti90r5FHKwnhtyH3vG3pKGgqYBF2OWwEOE8yzCmi8KYFE7F46qs 4RLv0u9qsfGvvKqbdi0FkWuVo0ZGjTazLXE1N4FG8ObqO2qmSS6ZMulxn4DVkdqTudtt 5wyb7JbdGi1zqzseOdA1OPYvgDVZluxN50i7CwJU5OXJyVuT0oZhQ2yrZGr0Mov1fS1Q 5v3FqnFVSVY7cfjEdbcvpStDYTiR+1McJyZGkJWV7f5MC3h/Wf5DFbq9FxSi1H6pirGQ 5fvreu4iZqBa7PfAQaDF/J301jGRwCEJUGDf5ErkxF3x5+RXOfZsZeeEA5GkCK/RY5O8 Br3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721274469; x=1721879269; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y5/8Zslr1MP/58mqMHISewZsB2/gBp8DHMSTzEl4QGQ=; b=uAspFxzB8rxNlEej9UMhkg4GsBlm/JoykcfrY1pip6Et/1iCPGM3iyoQ3oY6aJSqFf Yzp4Qx57EoffFES44qsS89XkM3hS1PMX6nsFQSJTMFLrtwGp1LrzmkjItI/ewBt0h5SB Hb2Dq28tZML6gMHivm3GM1SD7YpRkIkd2WHUt7Pa7O0qhE8Zq5D5ayQDrrSQBxh/DtGC 2VLb/DVOT2zRp7SEg4GDgeVSzDB5f3HXd0fq9VLc1Oga4ldGfgQm7qAS/UpjKLK1gIoV ery8XfgNLz49DWA65cLC+HCqXYS1CkUC9g8Sv1BUpodsZr+nmklmCokJDIhXfJeJQo6I a58g== X-Forwarded-Encrypted: i=1; AJvYcCVkWlqzxPUvVhUPxmc/4eG43Te0QO39286/DyGVyu9cMSxeEgFoVn7knOyOYhU8vc3k/7uEW4i7ivoFcheNVUckTncZWah9/kA6lm/OdnHJnTqRw4JgUnL8hP/MQ4WjjcQPdpVhMKpz X-Gm-Message-State: AOJu0Yy+MaVCJGO0rB6IlG+kpDw5Jww8Cw3ngGEQRRvDJwBEoa8Ap0u8 imXMcOR+Br4y2565JFhxfpHrx6ce4ktnoLNoqzNX/Qz9ZRLGCS+3hnrTgg== X-Google-Smtp-Source: AGHT+IFDF7qxwjD4lvstL6IWj4cD8QTRaRA0qpVS05uPxYjJp1QrxnbuNQ84hOkxLbR9ckqWdNl1uw== X-Received: by 2002:a05:6808:14d2:b0:3d9:385d:8754 with SMTP id 5614622812f47-3dad77941a9mr2005728b6e.47.1721274469600; Wed, 17 Jul 2024 20:47:49 -0700 (PDT) Received: from twhmp6px (mxsmtp211.mxic.com.tw. [211.75.127.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70b7ecc9965sm8940189b3a.199.2024.07.17.20.47.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jul 2024 20:47:49 -0700 (PDT) Received: from hqs-appsw-a2o.mp600.macronix.com (linux-patcher [172.17.236.67]) by twhmp6px (Postfix) with ESMTPS id D2E46805EF; Thu, 18 Jul 2024 11:56:59 +0800 (CST) From: AlvinZhou To: linux-mtd@lists.infradead.org, linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, tudor.ambarus@linaro.org, pratyush@kernel.org, mwalle@kernel.org, miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com, broonie@kernel.org Cc: chengminglin@mxic.com.tw, leoyu@mxic.com.tw, AlvinZhou , JaimeLiao Subject: [PATCH v9 6/6] mtd: spi-nor: add support for Macronix Octal flash Date: Thu, 18 Jul 2024 11:46:14 +0800 Message-Id: <20240718034614.484018-7-alvinzhou.tw@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240718034614.484018-1-alvinzhou.tw@gmail.com> References: <20240718034614.484018-1-alvinzhou.tw@gmail.com> Precedence: bulk X-Mailing-List: linux-spi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: AlvinZhou Adding Manufacture ID 0xC2 in last of ID table because of Octal Flash need manufacturer fixup for enabling/disabling Octal DTR mode. Signed-off-by: JaimeLiao Signed-off-by: AlvinZhou --- drivers/mtd/spi-nor/macronix.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/spi-nor/macronix.c b/drivers/mtd/spi-nor/macronix.c index f039819a5252..1a8ccebdfe0e 100644 --- a/drivers/mtd/spi-nor/macronix.c +++ b/drivers/mtd/spi-nor/macronix.c @@ -200,7 +200,9 @@ static const struct flash_info macronix_nor_parts[] = { .name = "mx25l3255e", .size = SZ_4M, .no_sfdp_flags = SECT_4K, - } + }, + /* Need the manufacturer fixups, Keep this last */ + { .id = SNOR_ID(0xc2) } }; static int macronix_nor_octal_dtr_en(struct spi_nor *nor)