Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752884AbcDVGth (ORCPT ); Fri, 22 Apr 2016 02:49:37 -0400 Received: from mail-bn1bon0144.outbound.protection.outlook.com ([157.56.111.144]:25232 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752498AbcDVGtd (ORCPT ); Fri, 22 Apr 2016 02:49:33 -0400 Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=freescale.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=none action=none header.from=freescale.com; From: Yunhui Cui To: , , CC: , , , , Yunhui Cui Subject: [PATCH v2 6/9] mtd: spi-nor: Support R/W for S25FS-S family flash Date: Fri, 22 Apr 2016 14:39:49 +0800 Message-ID: <1461307192-866-6-git-send-email-B56489@freescale.com> X-Mailer: git-send-email 2.1.0.27.g96db324 In-Reply-To: <1461307192-866-1-git-send-email-B56489@freescale.com> References: <1461307192-866-1-git-send-email-B56489@freescale.com> X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:192.88.158.2;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(2980300002)(1110001)(1109001)(339900001)(189002)(199003)(4001450100002)(2906002)(229853001)(36756003)(586003)(86362001)(85426001)(105606002)(106466001)(2201001)(92566002)(6806005)(11100500001)(5008740100001)(87936001)(4326007)(76176999)(50226001)(189998001)(50986999)(19580405001)(77096005)(19580395003)(48376002)(5003940100001)(104016004)(2950100001)(81166005)(50466002)(47776003)(1220700001)(1096002)(5001770100001)(7059030);DIR:OUT;SFP:1102;SCL:1;SRVR:BLUPR03MB068;H:az84smr01.freescale.net;FPR:;SPF:Fail;MLV:sfv;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BN1AFFO11FD005;1:cHdEUdO4/GpaOtCvk46hDwff+RFUH7Cm9RRBok63XNas1GQZWx5XJfK4+w6aeRpZg4OnGJ7+4vqydq/cPiU5wToUyQ6Q6Xn31icY34nnMRecix8s8PRvrDIjlDk2Ayi7gDOIHpLc+m97tf0WvT3TsISO+CQNvI5mYstyAvjofVp26XSxRcVa44s0yZBMPwS/ZktirJS62NSJkRlMvYRT8+ZHgY3cvzxsDB9Vy95sKaXYY4fQpKMjB2XvQ8+4nWJ/+FtH0C5N0pZAyz0BLvgnlhkU4+CVVcbuhZKCX9BxX/5Re+9gIXT6dcnWtK4WFeLxmhIcr1NkQ+ighNINNmpbdIQpoET6YC5sUs0c8PoYQiHCqqjLKzMy72GPtL2k3dayWmlgu9jmAzd8E9QwDBFC6yT690RosVGPyr/+tUWGM1v1/vZzOODRmd7zkiiJOLyQ5TFrc0nDY6F54oUfj2LvLgv5T57I0cB9Ww2erd6CoyO1BQNPLSIUzEk//ZhV63YUqLXKfxLOBbTTgfkr/xNRdpr7Q4tOL7KjTN/kTfoNFAjPgVn6tq5rDwmEHXSF56qCbcf4J4XUJEMsj0oYSIkd6w== MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 257a0d4f-8771-4028-c39a-08d36a7a3e88 X-Microsoft-Exchange-Diagnostics: 1;BLUPR03MB068;2:N5T1lUdSndCSVFotO54DDgYar6nXl2veBauAK3xi5PCLplIFr4ZkfmuBLZPt807gEX2G8bNCKlPq00eJ/OQY560p6L1dYozrv1kse+50Bzu4IK2XE3L50+b3HXTr5UP5foozrgri6yqm5NdmMx8csqMKKtKixiViFyD1ZmLfkhnuQDAzWU529aYfbH6JmpgW;3:1c7ZTTrwz7RPibOaasoSqPJyw2oWdOYkiScFh3A4ZfVqmJSD+dtqB/DKzTsw70NVi94fIUP9VA787Ja/YuZXVN4OGmgga6lOO+HkOQAca7NbiNq0VQWHgHCr2xyd9JH0/tTuWCd1L9bVKTAb1/LwEGlTVHsLs6NYdQmqZ0w6NXPsrwYWnsjmhZl3oHIHAgmrQLrb2MbQoooBgHzCta0mf1fCxPayd5USJe9rjYWZ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QX8V0lSS6hDrxAQDbicH5m7Umj0LjkLSRfqcdl/VTfqhUit6OHHCt9TRlmgeC6jOcHpTBtc5JsQDTrzeyY1PnBKgKy2SzcGwZV4UVIdCYyPik9HDBycb7ZjsNGJnbBGpGtPb52HDO+2O/dtldaXFhY3HdCE/BtoO137gTrewXUqYx1lyUhNG3CGecUCQn0hcEIFweIXyQcV7QAml9/aRIjjYO/RZr1PrUoVRM7dgCarZjlTsteAJvkvwdsNMJ09+cMwuBGIZOuToJQ/EJx7oDgbH0BLVF6ELVfWmAK3C+OGvDQNfMPeBrzJVST/MlUjPmtEw28mBw9lATd X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(9101521026)(601004)(2401047)(13017025)(13015025)(13023025)(13024025)(5005006)(13018025)(8121501046)(10201501046)(3002001)(6055026);SRVR:BLUPR03MB068;BCL:0;PCL:0;RULEID:;SRVR:BLUPR03MB068; X-Forefront-PRVS: 0920602B08 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BLUPR03MB068;23:HhGFyYg03znUvOm1OYuZlVus94GCQ8gWhUAZml46WW?= =?us-ascii?Q?DnWRwv0g6kW6xCIvDDxQ5rO6mo8tK8DcSsRCTIC7L/megjLHiHxDWzG3V5rC?= =?us-ascii?Q?ArDyHXIDU969EcrVymZLd0zqvswkfcT8SfFh+IHDQXj8KldJGZsIk+o/9DYL?= =?us-ascii?Q?nsd5XZX48bc/0CybIpZ7wZqMMwGNlW5qhlwaVEqpHbYlzK3phF0lfCIQ42eA?= =?us-ascii?Q?X+Cra4ANYq51/Ehw1Ey2rDHAMLJBIYnjxwLjiiyHSfqE1w/njOhn/pYmn2k0?= =?us-ascii?Q?F9lg7A5mckqR4Ms0et7xyAafI9S7A8uhzj+oHBXsR5r3NynY7P5DLs1Hol8v?= =?us-ascii?Q?U6+eAvRUcvknMoxLMMj87gdEa2EFahlOUmGh1dsbDsA+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gywFsc6lijaiCt4l;24:lWpBUF8lBedd0CP7f/k4jvxGaZ7iT5tjZrx4fB6KND8o93n9PXoMX7kpMEUA2PEiS5OEeG4swJ5q60Y/Yi4XOdvP13cTrN5lpBMXRIjQWoc=;7:MuglQmynEbvED5QLd+JKxGESXMfCmmLxZ3Q7iB5aDMCeGVIHso6tSMveK/DolOseLUhbJNqYtB7HTtlsmgElFKbLotzLrMLnAwbFpP23Wyu2s+46jCdy/dJGAtYQX1pJHLeVEwweLS3OEL2cKnGxXVNaPYlD7oQrcaGqxykDHLw3hMOgT7uuGPYSfLUeyVJSLYPs4ImoU+6ZR8GuyKp4Uw== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2016 06:49:25.4892 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d;Ip=[192.88.158.2];Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR03MB068 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3651 Lines: 110 From: Yunhui Cui With the physical sectors combination, S25FS-S family flash requires some special operations for read/write functions. Signed-off-by: Yunhui Cui --- drivers/mtd/spi-nor/spi-nor.c | 59 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index 157841d..91ee920 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -39,6 +39,10 @@ #define SPI_NOR_MAX_ID_LEN 6 #define SPI_NOR_MAX_ADDR_WIDTH 4 +/* Added for S25FS-S family flash */ +#define SPINOR_CONFIG_REG3_OFFSET 0x800004 +#define CR3V_4KB_ERASE_UNABLE 0x8 +#define SPINOR_S25FS_FAMILY_ID 0x81 struct flash_info { char *name; @@ -78,6 +82,7 @@ struct flash_info { }; #define JEDEC_MFR(info) ((info)->id[0]) +#define EXT_ID(info) ((info)->id[5]) static const struct flash_info *spi_nor_match_id(const char *name); @@ -881,6 +886,7 @@ static const struct flash_info spi_nor_ids[] = { */ { "s25sl032p", INFO(0x010215, 0x4d00, 64 * 1024, 64, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) }, { "s25sl064p", INFO(0x010216, 0x4d00, 64 * 1024, 128, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) }, + { "s25fs256s1", INFO6(0x010219, 0x4d0181, 64 * 1024, 512, 0)}, { "s25fl256s0", INFO(0x010219, 0x4d00, 256 * 1024, 128, 0) }, { "s25fl256s1", INFO(0x010219, 0x4d01, 64 * 1024, 512, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) }, { "s25fl512s", INFO(0x010220, 0x4d00, 256 * 1024, 256, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) }, @@ -1018,6 +1024,53 @@ static const struct flash_info *spi_nor_read_id(struct spi_nor *nor) return ERR_PTR(-ENODEV); } +/* + * The S25FS-S family physical sectors may be configured as a + * hybrid combination of eight 4-kB parameter sectors + * at the top or bottom of the address space with all + * but one of the remaining sectors being uniform size. + * The Parameter Sector Erase commands (20h or 21h) must + * be used to erase the 4-kB parameter sectors individually. + * The Sector (uniform sector) Erase commands (D8h or DCh) + * must be used to erase any of the remaining + * sectors, including the portion of highest or lowest address + * sector that is not overlaid by the parameter sectors. + * The uniform sector erase command has no effect on parameter sectors. + */ +static int spansion_s25fs_disable_4kb_erase(struct spi_nor *nor) +{ + struct fsl_qspi *q; + u32 cr3v_addr = SPINOR_CONFIG_REG3_OFFSET; + u8 cr3v = 0x0; + int ret = 0x0; + + q = nor->priv; + + nor->cmd_buf[2] = cr3v_addr >> 16; + nor->cmd_buf[1] = cr3v_addr >> 8; + nor->cmd_buf[0] = cr3v_addr >> 0; + + ret = nor->read_reg(nor, SPINOR_OP_SPANSION_RDAR, &cr3v, 1); + if (ret) + return ret; + if (cr3v & CR3V_4KB_ERASE_UNABLE) + return 0; + ret = nor->write_reg(nor, SPINOR_OP_WREN, NULL, 0); + if (ret) + return ret; + cr3v = CR3V_4KB_ERASE_UNABLE; + nor->program_opcode = SPINOR_OP_SPANSION_WRAR; + nor->write(nor, cr3v_addr, 1, NULL, &cr3v); + + ret = nor->read_reg(nor, SPINOR_OP_SPANSION_RDAR, &cr3v, 1); + if (ret) + return ret; + if (!(cr3v & CR3V_4KB_ERASE_UNABLE)) + return -EPERM; + + return 0; +} + static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf) { @@ -1311,6 +1364,12 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode) spi_nor_wait_till_ready(nor); } + if (EXT_ID(info) == SPINOR_S25FS_FAMILY_ID) { + ret = spansion_s25fs_disable_4kb_erase(nor); + if (ret) + return ret; + } + if (!mtd->name) mtd->name = dev_name(dev); mtd->priv = nor; -- 2.1.0.27.g96db324