From patchwork Thu Jan 23 20:16:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sagar Shrikant Kadam X-Patchwork-Id: 1228555 X-Patchwork-Delegate: uboot@andestech.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=selector1 header.b=H9+xQ6Jk; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 483YVX1K2rz9sPK for ; Fri, 24 Jan 2020 07:17:56 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9CA778198A; Thu, 23 Jan 2020 21:17:11 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.b="H9+xQ6Jk"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 09C3A81965; Thu, 23 Jan 2020 21:17:04 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FORGED_SPF_HELO,MSGID_FROM_MTA_HEADER,SPF_HELO_PASS, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on20604.outbound.protection.outlook.com [IPv6:2a01:111:f400:7eaa::604]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id B05358192E for ; Thu, 23 Jan 2020 21:16:59 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sagar.kadam@sifive.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jvnytfAKXENEJXtGXX5k0bTOj7eG1YSKTDOALBc+MPfbYs6jBdvf9LEU01xJayHKeVqlPpIpDxoTTYeossQx702dpr4dmtPlziID93T9L5stbiD7/y5T+QUSXdVfJDajVdDzLgKTnz8HivSizm9uza+KqepCngSbGQoSTSUw083k7lq5ObEa0qWT3mKp2THK9Q6sZVy5eHUUQiSROHK6ZWzupuBQgE2vJmHtY/2RoUQy49kbBBFoWdXkjGufPTiWcXIMvfzEw2Amv4g8HRx6T9NOXdQkeQFeTkkPzbISroakZGOHRzeTq5uqpyCxhvuM2eQaRewxbGmkK3HQsDGBAQ== 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-SenderADCheck; bh=ToqAjJ9YNk9Wz04RmG6ts0oIclFXunbCixbaQsu3JPk=; b=c1dqYL6zbRrjqSEVISxd8iEhNOaPlsFkIah2bdiLlC58GV4guYDOxKx9haaMWcJVbJpq2LigClvPD1I8rMj9eQeB7wnnNTn+iSFa0ILEd7nQKhSUk+GfOYWbRc/2Z8pvrfeI8EGP1qPfA7b4Yw0T7Bm3Ckfmq/vXjqBaulPfWBR02Fat7oYMmx0Ci31RJvYmCwDIRTHUpLJgaWlSqPK+xWgrdsrf+ibZP4Bw6kSLGdDe9mzAgfXEXFcZDbBGOtHnV0Axhls2R9x5ygtgDUtn12tPCl1fSzcqFMLWQspyJZXcv8+etcIR9J5JrPtudqDScw+8bdfIuGIoQpMK60Pu6w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=sifive.com; dmarc=pass action=none header.from=sifive.com; dkim=pass header.d=sifive.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ToqAjJ9YNk9Wz04RmG6ts0oIclFXunbCixbaQsu3JPk=; b=H9+xQ6JkWYY1jP693slDQEBAu/oh1FWE72OKGkxbgBbHDZDrKszByet4bmgTOjFytI+/0+0DQlr5VEwTb0qh3gQP9a+JaPlR52s+uNF2DTvENFlIhJ98wASo/hedVhux2guGM4CoYLWAWWL05V1QRp6UTw0QhdbsP6S7IlwR3/o= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=sagar.kadam@sifive.com; Received: from DM6PR13MB2442.namprd13.prod.outlook.com (20.176.101.153) by DM6PR13MB2506.namprd13.prod.outlook.com (20.176.96.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2686.12; Thu, 23 Jan 2020 20:16:57 +0000 Received: from DM6PR13MB2442.namprd13.prod.outlook.com ([fe80::20cf:e8b3:b1e:c8b0]) by DM6PR13MB2442.namprd13.prod.outlook.com ([fe80::20cf:e8b3:b1e:c8b0%7]) with mapi id 15.20.2665.017; Thu, 23 Jan 2020 20:16:57 +0000 From: Sagar Shrikant Kadam To: u-boot@lists.denx.de Subject: [U-Boot Patch v1 6/7] nor: add post bfpt fix handler for is25wp256 device Date: Thu, 23 Jan 2020 12:16:05 -0800 Message-Id: <1579810566-11675-7-git-send-email-sagar.kadam@sifive.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1579810566-11675-1-git-send-email-sagar.kadam@sifive.com> References: <1579810566-11675-1-git-send-email-sagar.kadam@sifive.com> X-ClientProxiedBy: BYAPR06CA0001.namprd06.prod.outlook.com (2603:10b6:a03:d4::14) To DM6PR13MB2442.namprd13.prod.outlook.com (2603:10b6:5:cb::25) MIME-Version: 1.0 Received: from gamma07.internal.sifive.com (64.62.193.194) by BYAPR06CA0001.namprd06.prod.outlook.com (2603:10b6:a03:d4::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.2644.20 via Frontend Transport; Thu, 23 Jan 2020 20:16:56 +0000 X-Mailer: git-send-email 2.7.4 X-Originating-IP: [64.62.193.194] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 06f54163-8f47-40f6-c897-08d7a0413258 X-MS-TrafficTypeDiagnostic: DM6PR13MB2506: X-LD-Processed: 22f88e9d-ae0d-4ed9-b984-cdc9be1529f1,ExtAddr X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-Forefront-PRVS: 029174C036 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39850400004)(366004)(396003)(376002)(136003)(346002)(189003)(199004)(186003)(6486002)(2906002)(2616005)(26005)(8936002)(81166006)(81156014)(956004)(16526019)(52116002)(316002)(4326008)(7696005)(107886003)(86362001)(8676002)(6916009)(6666004)(66556008)(66476007)(66946007)(478600001)(5660300002)(36756003); DIR:OUT; SFP:1101; SCL:1; SRVR:DM6PR13MB2506; H:DM6PR13MB2442.namprd13.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: sifive.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FMXiUSV11gCxTquV+3llpXhPL1WbrMT6Qi6ZlHaVTG4msysDCzg1fRuCBlabFATrtc0JN/DHPr135ob0anoHA4xoLXbbZ5a/bR0Q7nfUY+yFhs043zlEKjWqPX/fmAntU2z5SuDPymZ1XXBmB7SgVkA76cQ/ejKpjYGWmi2T45VLxaHrl85C6tPGM3fzXb2fsTG69rwCfOoJXbXi30lmm/snUtYCeUaojUKK8NCwnx/7p6eBn2/TDbu3IQpbIDVTFwgPxm+yP4QMYQ8nY/ngrHgXa2Y3vCxDWDJkTjzTwzir6az9vQDLW5fOdD6MTTUbtXcJ9F2S/RPBEoBM1X+w7zrhxGDCshWg8VgFFwx2wrOSNColvpiIbVmrUpH5CqLHjNHh8dVGlRUemMoRWcvwjQSxJwxein9yZzi2DkME3A4ji9vt/hgjpylnWqIvtCFn X-MS-Exchange-AntiSpam-MessageData: n21o+husqv8n/zBlA5NcfWogI11WqWg/MaxdovEhx9VyAO+Simnh417eWIHrTus8IqagtER7uwOe3oCw4jbUP7WFhoVJh6o/LEgl8CXZ7OSDUUPgny1uS5z1QRdNFN0Ou0OgGDqJCXOoHGnchmdySA== X-OriginatorOrg: sifive.com X-MS-Exchange-CrossTenant-Network-Message-Id: 06f54163-8f47-40f6-c897-08d7a0413258 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Jan 2020 20:16:57.6490 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 22f88e9d-ae0d-4ed9-b984-cdc9be1529f1 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: atcqJoTXiuNgsliwP2QTvqnExrMzRWQF3iEdlJRH7UadINPciD9Jm6ZQUSr8fJl/ZI0TElyHdKgjvz+SNrtxxw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR13MB2506 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: atish.patra@wdc.com, ick@andestech.com Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean Update vendor id for ISSI flash, enable SFDP as ISSI flash supports it and add support for spi_nor_fixups similar to that done in linux. Flash vendor specific fixups can be registered in spi_nor_ids, and will be called after BFPT parsing to fix any wrong parameter read from SFDP. Signed-off-by: Sagar Shrikant Kadam --- board/sifive/fu540/Kconfig | 1 + drivers/mtd/spi/sf_internal.h | 16 +++++++++++ drivers/mtd/spi/spi-nor-core.c | 63 ++++++++++++++++++++++++++++++++++++++++-- drivers/mtd/spi/spi-nor-ids.c | 7 ++++- include/linux/mtd/spi-nor.h | 1 + 5 files changed, 85 insertions(+), 3 deletions(-) diff --git a/board/sifive/fu540/Kconfig b/board/sifive/fu540/Kconfig index 75661f3..d9e4956 100644 --- a/board/sifive/fu540/Kconfig +++ b/board/sifive/fu540/Kconfig @@ -42,6 +42,7 @@ config BOARD_SPECIFIC_OPTIONS # dummy imply SPI imply SPI_SIFIVE imply SPI_FLASH + imply SPI_FLASH_SFDP_SUPPORT imply SPI_FLASH_ISSI imply MMC imply MMC_SPI diff --git a/drivers/mtd/spi/sf_internal.h b/drivers/mtd/spi/sf_internal.h index 5c64303..856866f 100644 --- a/drivers/mtd/spi/sf_internal.h +++ b/drivers/mtd/spi/sf_internal.h @@ -66,8 +66,24 @@ struct flash_info { #define SPI_NOR_SKIP_SFDP BIT(13) /* Skip parsing of SFDP tables */ #define USE_CLSR BIT(14) /* use CLSR command */ #define SPI_NOR_HAS_SST26LOCK BIT(15) /* Flash supports lock/unlock via BPR */ + +#ifdef CONFIG_SPI_FLASH_SFDP_SUPPORT + /* Part specific fixup hooks */ + const struct spi_nor_fixups *fixups; +#endif }; +#ifdef CONFIG_SPI_FLASH_SFDP_SUPPORT +/* + * Declare manufacturer specific fixup handlers that + * can be registered as fixup's in flash info table + * so as to update any wrong/broken SFDP parameter. + */ +#ifdef CONFIG_SPI_FLASH_ISSI +extern struct spi_nor_fixups is25wp256_fixups; +#endif +#endif + extern const struct flash_info spi_nor_ids[]; #define JEDEC_MFR(info) ((info)->id[0]) diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c index 6e7fc23..c55116f 100644 --- a/drivers/mtd/spi/spi-nor-core.c +++ b/drivers/mtd/spi/spi-nor-core.c @@ -296,7 +296,6 @@ static void spi_nor_set_4byte_opcodes(struct spi_nor *nor, nor->mtd.erasesize = info->sector_size; break; - default: break; } @@ -1800,6 +1799,57 @@ static const struct sfdp_bfpt_erase sfdp_bfpt_erases[] = { static int spi_nor_hwcaps_read2cmd(u32 hwcaps); +#ifdef CONFIG_SPI_FLASH_SFDP_SUPPORT +/** + * struct spi_nor_fixups - SPI NOR fixup hooks + * @post_bfpt: called after the BFPT table has been parsed + * + * Those hooks can be used to tweak the SPI NOR configuration when the SFDP + * table is broken or not available. + */ +struct spi_nor_fixups { + int (*post_bfpt)(struct spi_nor *nor, + const struct sfdp_parameter_header *bfpt_header, + const struct sfdp_bfpt *bfpt, + struct spi_nor_flash_parameter *params); +}; + +static int spi_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) +{ + if (nor->info->fixups && nor->info->fixups->post_bfpt) + return nor->info->fixups->post_bfpt(nor, bfpt_header, bfpt, + params); + + return 0; +} + +static int is25wp256_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) + +{ + /* IS25WP256 supports 4B opcodes, but the BFPT advertises a + * BFPT_DWORD1_ADDRESS_BYTES_3_ONLY address width. + * Overwrite the address width advertised by the BFPT. + */ + if ((bfpt->dwords[BFPT_DWORD(1)] & BFPT_DWORD1_ADDRESS_BYTES_MASK) == + BFPT_DWORD1_ADDRESS_BYTES_3_ONLY) + nor->addr_width = 4; + + return 0; +} + +struct spi_nor_fixups is25wp256_fixups = { + .post_bfpt = is25wp256_post_bfpt_fixups, +}; +#endif + /** * spi_nor_parse_bfpt() - read and parse the Basic Flash Parameter Table. * @nor: pointer to a 'struct spi_nor' @@ -1971,7 +2021,13 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor, return -EINVAL; } - return 0; +#ifdef CONFIG_SPI_FLASH_SFDP_SUPPORT + err = spi_nor_post_bfpt_fixups(nor, bfpt_header, &bfpt, + params); +#else + err = 0; +#endif + return err; } /** @@ -2209,6 +2265,9 @@ static int spi_nor_init_params(struct spi_nor *nor, !(info->flags & SPI_NOR_SKIP_SFDP)) { struct spi_nor_flash_parameter sfdp_params; + /* Update flash structure information to nor structure */ + nor->info = info; + memcpy(&sfdp_params, params, sizeof(sfdp_params)); if (spi_nor_parse_sfdp(nor, &sfdp_params)) { nor->addr_width = 0; diff --git a/drivers/mtd/spi/spi-nor-ids.c b/drivers/mtd/spi/spi-nor-ids.c index 973b6f8..5a29c8b 100644 --- a/drivers/mtd/spi/spi-nor-ids.c +++ b/drivers/mtd/spi/spi-nor-ids.c @@ -135,7 +135,12 @@ const struct flash_info spi_nor_ids[] = { { INFO("is25wp128", 0x9d7018, 0, 64 * 1024, 256, SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) }, { INFO("is25wp256", 0x9d7019, 0, 64 * 1024, 512, - SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) }, + SECT_4K | SPI_NOR_4B_OPCODES | SPI_NOR_DUAL_READ + | SPI_NOR_QUAD_READ) +#ifdef CONFIG_SPI_FLASH_SFDP_SUPPORT + .fixups = &is25wp256_fixups +#endif + }, #endif #ifdef CONFIG_SPI_FLASH_MACRONIX /* MACRONIX */ /* Macronix */ diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h index 1d91177..44b7479 100644 --- a/include/linux/mtd/spi-nor.h +++ b/include/linux/mtd/spi-nor.h @@ -23,6 +23,7 @@ #define SNOR_MFR_ST CFI_MFR_ST /* ST Micro <--> Micron */ #define SNOR_MFR_MICRON CFI_MFR_MICRON /* ST Micro <--> Micron */ #define SNOR_MFR_MACRONIX CFI_MFR_MACRONIX +#define SNOR_MFR_ISSI CFI_MFR_PMC #define SNOR_MFR_SPANSION CFI_MFR_AMD #define SNOR_MFR_SST CFI_MFR_SST #define SNOR_MFR_WINBOND 0xef /* Also used by some Spansion */