Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753450AbcDNEQt (ORCPT ); Thu, 14 Apr 2016 00:16:49 -0400 Received: from mail-bn1on0147.outbound.protection.outlook.com ([157.56.110.147]:17312 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752659AbcDNEQT (ORCPT ); Thu, 14 Apr 2016 00:16:19 -0400 Authentication-Results: spf=fail (sender IP is 192.88.168.50) 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 6/9] mtd: spi-nor: Support R/W for S25FS-S family flash Date: Thu, 14 Apr 2016 11:50:52 +0800 Message-ID: <1460605855-6689-7-git-send-email-B56489@freescale.com> X-Mailer: git-send-email 2.1.0.27.g96db324 In-Reply-To: <1460605855-6689-1-git-send-email-B56489@freescale.com> References: <1460605855-6689-1-git-send-email-B56489@freescale.com> X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:192.88.168.50;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(2980300002)(1110001)(1109001)(339900001)(199003)(189002)(5008740100001)(2950100001)(1220700001)(1096002)(76176999)(50986999)(5001770100001)(104016004)(81166005)(2906002)(105606002)(77096005)(11100500001)(229853001)(6806005)(106466001)(85426001)(4326007)(36756003)(189998001)(48376002)(19580395003)(19580405001)(86362001)(50466002)(87936001)(586003)(47776003)(92566002)(5003940100001)(50226001)(2201001)(4001450100002)(7059030);DIR:OUT;SFP:1102;SCL:1;SRVR:BLUPR03MB066;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;MLV:sfv;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BN1AFFO11FD022;1:W3JTJE3hGUejUCNMyWUbA/ot4v2mppWBFPU17vTacl1SQ4+OS99wUSR+jCFykLlV/K7Ym1LOPd1k68npIm/Ss7dxFYEyXT8H3ik1yrtJQsHAmBFWjfozv7iZ63fTVwIzCuL3QuLbhAjaYzBBiqUNZ818kT80IJk8t/MUyJDk1G+JXV0jdxYoGI+cDfuYy2oO0ZkcddxlcUsC0QjKuPNhnH02Rr65blE8Td2zKfKB59SAT3DP0eQbrtjJ8wSBmhCQkfgFOdW5QM5403lkrUSQV0tz+28doUq4slQ6j7uBOAa7rGh/q7G8hiqvjLYQOhgs6sFHbcR9iRPvNIQ6vGS4z15gqHItKFJu5gscAyGh7cFLenunw1BsncxMfHHlrYLrC59IA23fe4XNZ6+K8o0/54ZvIrJ57zXH4vRegqofMoGvEdVy+wmSmVhPf9zTQxl1lxnmWoO14I5LKn9HZ9uTq2PJP2K+3nHNBnn6o0BG1TbutrNDMPUkZ9YODWjlL33xsbGTZc7CoqtPPN9TkjKf0xdPBwhOzCw96CGdVsXCEib7wDCELQb/iN6QzZItWP4BtAYsXTdvYjTk3fs+ovPvYQ== MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: fd5c9c87-b67f-43b0-d92a-08d3641950f3 X-Microsoft-Exchange-Diagnostics: 1;BLUPR03MB066;2:WO/Dwq3b7WilIj1Uiwybo8RN9R1ISRor0rWPXUutBIJgMOxopfoLNGapW+GP9mpNWGFE8ti0yH0g43PieSvI91krsGP3zzNJ2DkMhEoq15pPF9GZMhuzXwni1b/V4UyFCSatcWbjybGX2zNBA01FVZ5CgeKCq+P53BOvl224QUU6z1ZTv5EJhFPqXmaOsXv5;3:DAt7w7d3SkI0/LqRLnpNEZ2sY1zJtngtWTKIWCazapbaECbAo58CFePq4jr2D4kYAbWkqWiqyWmX1SQ77o22B1+6VPrtc9A1mzzTwI9ibpXRcWrchiAPwjyQ2bx0uIdRHir8SBZrUlRsdbdtiY3zBLFtxz7eS1Bq97eqlU4WtMhGrFEYrFXq1/Oi4AsvWyFDZ42g8OoEHsbp1/ro0mTnKuW9ggqhNafAEsfuq2qX5A4= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR03MB066; X-Microsoft-Exchange-Diagnostics: 1;BLUPR03MB066;25:DpqVWurrkx3htKOaDfkoEAZQzAIQtPTn0eEbfsIPBxQ2R9vHJtfQZw53mckTO0B7vLtqnt/RpFv6kIgeXKwuEy2AveUlwvemZ5mQrWHuSaofs3feSlK3F8MfoSWSgyXGWoN9UyQNlPkmo2nYSJS6hqyDp2JnkKUeeT7uCn2WTb2cFJENeScrC0oJpvctDfsaI6FrR5ju/NL3K1iuUslfrPeNEWeWerJYof8xsH7tVy2HwqMWIZFqZHlxdBBu7qlUCkrE4RJRHT+vQna/WoCcyOB82uz2b1v6wsZCJfz9Pwn0cYvdjwLDZDhqPp6BSHNiMpnzgRZuFpzocTAa6rDJefH+XgnCVR7PuL/PguSIZcnZJ8nKTG7o10ZgMtEKcadT+d7OrM8irHENYZkdhliCk7GnZwnnPqZ4jUJSNLR2nSatoebf3NMutAqLV3g1vbvgX6d3S7rOib4wiz0u14uvAonyImAbewb7jQEcba1Je1N9fdVF6Tkbl1za5qurBHDIYgeT7L8W0ELz8i9OuInUs7krnb/sXKmb4C6DOCD6mqH+JY9g2FE8HN/JcE1j793SYvta6hF/VSXgPKbTw7bSK2Ohn1Tcat9QG40Pdc4LIhfN0VNgdPxVkgXNVltz1doD+5gxCSb838480CT0DEk2aB/MiTLcO4rJuIbr+9QwUsg= X-Microsoft-Exchange-Diagnostics: 1;BLUPR03MB066;20:dwS8xYJFjJQPQZzKiKNjGnPhPwuJK48C6TcwrMoj3RK5QGii6mlniKbyZy1o8jiOxUV+Rovz6Oi/gqAHkTkoHjG77TbsYezbf+6l/M8/yxxVg1XMw3kkxocwodEjtvElKrYRim73TqE5mZXs4ffCfRO2T9rlhMHd/vYcaSitNY0NlRoNbWXKSMb5G/J+Nwr4Hb1MWFukaF49T2XKzF/dqR23R/GH/IVNWBY/ycmSXOhDXoWoHPXTCaCO7zITU3ZVfV2VJHTiUyfWEuE1OYlRZOE6LEss+pjUnqPHzhXTBNvb13KD0zX3RzCmQVp0zP7XvJD6xQmMB4G5KNug/ZTEVyueVeNPDBKJ4P9f7dmszRNEKf6LX29zd7+p57gQ0+j5L5p/m1ow5IV4q0KP0puM2xKi7REV8MG45K5QfzrauptZ/1yf+wRAPMONjovkv3fe;4:jeRDN3OHquGRK4ofXbYKhLdwImui1P4qBHFXHuw3DZHZZxWz4O2LKtlpY0CvWL+EmULOnlWxAyOSI79kyQSPgZFfdewk5dbMS4P9pvlpzdfWrjfYOKDKarW6omffNJPk5WeLLdcDo//EjXyoutUfT9FejWrDJuDHcDgEQeO9dYv4aOVC82sxZWPZR0pw8AtBYcaC7QHhgZIfIeMu6UM7DdoNrLjgYqBlg5p8zKh/0IeCMz4ICF2Z5WYydDudc3bu+18fSCMqVw2bQnUXOf/F2/ie6ippgaqswOPN0FaWqhvmoIYct/hVKQNXS3yGauKFVcx60fgU8fX4OhlfHvXNm9IeOFgChTt6ou2ylq07FQy4PaxnUY5zSYu8YJzBeen7FYerjfAuihsN2EJ2qgvN1u7oGXQxTP+B3Frw3usLkUqykVBXmb1NQTssmNdiJ1mWSDzpCeMB4vVI96dWwUB5UBF2Q/oG96Y8+UhnI9htUwg= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(13023025)(8121501046)(13017025)(13015025)(13018025)(5005006)(13024025)(10201501046)(3002001)(6055026);SRVR:BLUPR03MB066;BCL:0;PCL:0;RULEID:;SRVR:BLUPR03MB066; X-Forefront-PRVS: 0912297777 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BLUPR03MB066;23:jzblGWcMWcdB2+88ay7CNrTviygPfUZm31KocN8eT8?= =?us-ascii?Q?Y78s+vUSYcZl6j8p68S55c9OnjICPmj0MMpLiJi8ug3pPAvpfi5QGVlRhQn1?= =?us-ascii?Q?MAJ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Q/sgwHKPZmIVN1CJpjvHLkrgkukb?= =?us-ascii?Q?7gDoEvCkpgSptrYlnv/Fk4X1z6mtBZZfiBX5j2JuxvsDFiGuuPX1Mbnt6Gph?= =?us-ascii?Q?S/8jRD0zf9SDrxL3SkX2gZT3xX?= X-Microsoft-Exchange-Diagnostics: 1;BLUPR03MB066;5:saPBnTHRJL6bWCXSKSTDtvOCuMzvIkl/xEm7YqOZcL2sRDQvHGBpFBKLx6iFaBj01xNaekG3h75mRpYhh+FJmm2tGSO5Fnaqn052oStzQvAo1l+aGGINHvwxQ07SHEe/6uq/GBWdmo+Vfja0WxCwBA==;24:GAKNnFT/sCrMx32DL2kI+zClH2ImWpm7IkPQSs9nk3k8cA6eUz8W6VSNHBNa2ij025VJJSH0tech09LIgQZpfS3zn7LqEab5gy7bcpXj3GQ= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Apr 2016 04:00:28.2618 (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.168.50];Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR03MB066 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