From patchwork Mon Aug 26 12:08:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tudor Ambarus X-Patchwork-Id: 1153136 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=microchip.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="c9YUkJMf"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=microchiptechnology.onmicrosoft.com header.i=@microchiptechnology.onmicrosoft.com header.b="koMOH4ne"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46H9lP3Hzzz9sNf for ; Mon, 26 Aug 2019 22:08:49 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=zn527gMpuBW9NG/PtGx4BAgzTq/TM0Y/B5VwAHzmo24=; b=c9YUkJMfNi/Iaj fNQzGkGzOyVqF3hL0fZMzneIo9xFoJSGKqwZ/EFcHhkUc+Rr1qW3bFeL+sWdvsTFEhSvaFQVemjaw jeEBzbLMkhnfc+DZCRy200oWR10oqTkGDbWkIAjrC/uNprQ55pHOXTEz58uf3m0b0iYqsyOgfhspI D/Pbmnr1MXK7d33kv0HheAide+JOSQ7bkpU9YDuhu5TMiFFwfmRQ0hbYf0gHZv/tr9TIe3OGOwVPo OSZNIlHrGx+wMDhF9oI8hSwjSkfmOcZuVZ7/X/bhn/dR+prz2xWl9hEyUAetwyvsedrX9Y/wwfiDv 2AJdnwfIz7T1OJ7KQGPw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i2Dnj-0002Ji-0E; Mon, 26 Aug 2019 12:08:47 +0000 Received: from esa5.microchip.iphmx.com ([216.71.150.166]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i2Dna-000273-Ua for linux-mtd@lists.infradead.org; Mon, 26 Aug 2019 12:08:41 +0000 Received-SPF: Pass (esa5.microchip.iphmx.com: domain of Tudor.Ambarus@microchip.com designates 198.175.253.82 as permitted sender) identity=mailfrom; client-ip=198.175.253.82; receiver=esa5.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="Tudor.Ambarus@microchip.com"; x-conformance=spf_only; x-record-type="v=spf1"; x-record-text="v=spf1 mx a:ushub1.microchip.com a:smtpout.microchip.com a:mx1.microchip.iphmx.com a:mx2.microchip.iphmx.com include:servers.mcsv.net include:mktomail.com include:spf.protection.outlook.com ~all" Received-SPF: None (esa5.microchip.iphmx.com: no sender authenticity information available from domain of postmaster@email.microchip.com) identity=helo; client-ip=198.175.253.82; receiver=esa5.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="postmaster@email.microchip.com"; x-conformance=spf_only Authentication-Results: esa5.microchip.iphmx.com; spf=Pass smtp.mailfrom=Tudor.Ambarus@microchip.com; spf=None smtp.helo=postmaster@email.microchip.com; dkim=pass (signature verified) header.i=@microchiptechnology.onmicrosoft.com; dmarc=pass (p=none dis=none) d=microchip.com IronPort-SDR: V5xWt+wl5G2t4buljh8poCRIuHBa0kbXH9njm4sor3BfKQCTWbtGgnA16yUoevLphk3TZHga0r GVc5PQoBeoa9RtopE6sXKeuu/yjpjNQGlxPRM/K2kTlRIErIYBP7BMRW+KEPNgq09WFok3iDzZ ajVm1NroTzTHYtLcgQ2Y9NKDh2AxI57ddb0qnNEi+hcu9xfWlQvkTPdPw6mn2JTUeosng3+KRo 9maFQ5mIqVZ20B+3648z4u33ZnCBCp2SzAwHkN4yURCfsFc7S/l/chW7Y+l86abWEQf9fomTvx aY4= X-IronPort-AV: E=Sophos;i="5.64,433,1559545200"; d="scan'208";a="44989583" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa5.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 26 Aug 2019 05:08:38 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 26 Aug 2019 05:08:37 -0700 Received: from NAM01-SN1-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.87.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5 via Frontend Transport; Mon, 26 Aug 2019 05:08:36 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jEb9uXyy1NC/HsuzDU6xNp7zwFBhwAKelvPs391O+vLXH85inUSMLF8t4LYxLZCujRW/hHCgBirV1LrfeMcl9WnnoME2ysfGqLLC0OUpavESUZcKTb2SLyaiFIYjGTIlr4h1nTRr7f0GJtGlQdTn+p37tAg6vnVjZBpJWtwrQPvJLGSDb3Wpbn/KMCkEG75bakvPnWs7ZORJ7pop3YY3HKShGiQmXkVvpdGcLx8/OVs6vVq429pyamJFTrZ1ZiB9a6CHRTeaUHOzolmW0zyMHAn5XkcYrmq0dOLEYwz60lR4cXHIc2A0zhs7QqMKazb6u7aO51hDDa+Pt1LzD81RfA== 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=kNJWgqpt+XlI34xYN7jthxW+soDIOhBBBwQX2gs00SI=; b=aBcpBAggturLanfq0GJERZOE44Y6TBYKtmxSx3rltIYf6Qs8KzWd+U8yjocXUQjn4uyf405mY8hYNWUyTfEgosa2de+cl2iX0/MzxrmOuY4P01wTUzlo7UW492dpZ9MGHDKQxoKM0xBjD9CVCJtG7O7M0Jk4pjBLN/qDbHCMTIuvXMXMXFUCC04jUXsCxINJ3H2FLy2eYEGFliNuXU2sSlAy2EQqDXuT8hVpKMq4hj1FoO3SXaNj15VbnlccMo9i3VEQnBOHH+apa1F+z6DOjAmmIs95gooRfPD1budIZGTu+yo2tTYJBYKM4a0eh2VtDSmmPX1DTarhYvxer8j6ng== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microchip.com; dmarc=pass action=none header.from=microchip.com; dkim=pass header.d=microchip.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microchiptechnology.onmicrosoft.com; s=selector2-microchiptechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kNJWgqpt+XlI34xYN7jthxW+soDIOhBBBwQX2gs00SI=; b=koMOH4neSD2x/haYSLqkToA1oW5kQe+m595VL9d7epiNJOArfPaYFpjv6HEEjVzkbcp0MnJqU8SMCQw5n8r4T7u2GqRgCEJIH4p7120GbgbmugZiUbt5Cn0XmjKbLWiteCoWQH+JRC+0fdveb1GsqmtWnjw5TrR6GjRrFZJ58Gk= Received: from MN2PR11MB4448.namprd11.prod.outlook.com (52.135.39.157) by MN2PR11MB3678.namprd11.prod.outlook.com (20.178.252.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.21; Mon, 26 Aug 2019 12:08:33 +0000 Received: from MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5]) by MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5%7]) with mapi id 15.20.2199.021; Mon, 26 Aug 2019 12:08:33 +0000 From: To: , , , , , , Subject: [RESEND PATCH v3 01/20] mtd: spi-nor: Regroup flash parameter and settings Thread-Topic: [RESEND PATCH v3 01/20] mtd: spi-nor: Regroup flash parameter and settings Thread-Index: AQHVXAb7Ihn2m9KKzka1TgfBbZC4ug== Date: Mon, 26 Aug 2019 12:08:32 +0000 Message-ID: <20190826120821.16351-2-tudor.ambarus@microchip.com> References: <20190826120821.16351-1-tudor.ambarus@microchip.com> In-Reply-To: <20190826120821.16351-1-tudor.ambarus@microchip.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1PR09CA0046.eurprd09.prod.outlook.com (2603:10a6:802:28::14) To MN2PR11MB4448.namprd11.prod.outlook.com (2603:10b6:208:193::29) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.9.5 x-originating-ip: [94.177.32.156] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: f733f046-60ce-4375-3cc2-08d72a1e1d5e x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:MN2PR11MB3678; x-ms-traffictypediagnostic: MN2PR11MB3678: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8882; x-forefront-prvs: 01415BB535 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(136003)(39860400002)(346002)(366004)(396003)(376002)(199004)(189003)(486006)(2616005)(476003)(107886003)(316002)(14454004)(386003)(6506007)(76176011)(99286004)(52116002)(110136005)(478600001)(102836004)(4326008)(25786009)(36756003)(446003)(26005)(11346002)(50226002)(81156014)(66066001)(8676002)(53936002)(81166006)(8936002)(6512007)(6486002)(6436002)(3846002)(6116002)(186003)(86362001)(305945005)(2201001)(7736002)(2906002)(64756008)(66446008)(1076003)(71190400001)(5660300002)(71200400001)(256004)(14444005)(66946007)(66556008)(30864003)(66476007)(2501003); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR11MB3678; H:MN2PR11MB4448.namprd11.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: microchip.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 3y/bJzodmOeTJUIo4MA/3vn+Gc+4ubMHgXIcAhNsoHyS6my55rcVThBH9b+PDHVHA7H2vFhsOTAdEaVpfDvEXpsXf/RM4cyt88Zoo7MHWbddDklSVKUUQdiS8P4PAnpTxcvN2FBwHK0qsZ9JZ7YJg3mfly9xXoX/42pb3k1V4SMlw4xW89yp5ZtzIy9PjnaY5cud+tubdYND36hYwmGVzBUxYg98vPfMkX7JrhH/aXFhvhauyYmEkZZ8JG8nVH4PC5o4Fd63PlB7nMskahlfm2c7TgiHqcrXBrFKR6V9b8lxuARWgj/lncvSVa8glj0EeGIHzZQYfm8ygUa014GJqGaMfqP/6x3F4ezmzds9YWODFi/3xhVPo/QphXoaUTC/UJZi0Yg5BajNGN2nspJM4sLjFDXX1IBnV/N7Gtwinw8= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: f733f046-60ce-4375-3cc2-08d72a1e1d5e X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Aug 2019 12:08:32.9323 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: jqeaXObmrcI+vw6PuRUNK1pUfc2ccLSl+p6Zxs5bVihj1AK2rZb1OoWN9oDzGem5tg4yxhWiW0nTX7nmzEuB444UvKW3Lf8H9m52NxK5Uh0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB3678 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190826_050839_170829_B66C834E X-CRM114-Status: GOOD ( 10.16 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [216.71.150.166 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -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 X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tudor.Ambarus@microchip.com Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Tudor Ambarus The scope is to move all [FLASH-SPECIFIC] parameters and settings from 'struct spi_nor' to 'struct spi_nor_flash_parameter'. 'struct spi_nor_flash_parameter' describes the hardware capabilities and associated settings of the SPI NOR flash memory. It includes legacy flash parameters and settings that can be overwritten by the spi_nor_fixups hooks, or dynamically when parsing the JESD216 Serial Flash Discoverable Parameters (SFDP) tables. All SFDP params and settings will fit inside 'struct spi_nor_flash_parameter'. Move spi_nor_hwcaps related code to avoid forward declarations. Add a forward declaration that we can't avoid: 'struct spi_nor' will be used in 'struct spi_nor_flash_parameter'. Signed-off-by: Tudor Ambarus Reviewed-by: Boris Brezillon Reviewed-by: Vignesh Raghavendra --- v3: collect R-b drivers/mtd/spi-nor/spi-nor.c | 65 ------------ include/linux/mtd/spi-nor.h | 239 +++++++++++++++++++++++++++++------------- 2 files changed, 164 insertions(+), 140 deletions(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index 0597cb8257b0..d35dc6a97521 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -40,71 +40,6 @@ #define SPI_NOR_MAX_ID_LEN 6 #define SPI_NOR_MAX_ADDR_WIDTH 4 -struct spi_nor_read_command { - u8 num_mode_clocks; - u8 num_wait_states; - u8 opcode; - enum spi_nor_protocol proto; -}; - -struct spi_nor_pp_command { - u8 opcode; - enum spi_nor_protocol proto; -}; - -enum spi_nor_read_command_index { - SNOR_CMD_READ, - SNOR_CMD_READ_FAST, - SNOR_CMD_READ_1_1_1_DTR, - - /* Dual SPI */ - SNOR_CMD_READ_1_1_2, - SNOR_CMD_READ_1_2_2, - SNOR_CMD_READ_2_2_2, - SNOR_CMD_READ_1_2_2_DTR, - - /* Quad SPI */ - SNOR_CMD_READ_1_1_4, - SNOR_CMD_READ_1_4_4, - SNOR_CMD_READ_4_4_4, - SNOR_CMD_READ_1_4_4_DTR, - - /* Octal SPI */ - SNOR_CMD_READ_1_1_8, - SNOR_CMD_READ_1_8_8, - SNOR_CMD_READ_8_8_8, - SNOR_CMD_READ_1_8_8_DTR, - - SNOR_CMD_READ_MAX -}; - -enum spi_nor_pp_command_index { - SNOR_CMD_PP, - - /* Quad SPI */ - SNOR_CMD_PP_1_1_4, - SNOR_CMD_PP_1_4_4, - SNOR_CMD_PP_4_4_4, - - /* Octal SPI */ - SNOR_CMD_PP_1_1_8, - SNOR_CMD_PP_1_8_8, - SNOR_CMD_PP_8_8_8, - - SNOR_CMD_PP_MAX -}; - -struct spi_nor_flash_parameter { - u64 size; - u32 page_size; - - struct spi_nor_hwcaps hwcaps; - struct spi_nor_read_command reads[SNOR_CMD_READ_MAX]; - struct spi_nor_pp_command page_programs[SNOR_CMD_PP_MAX]; - - int (*quad_enable)(struct spi_nor *nor); -}; - struct sfdp_parameter_header { u8 id_lsb; u8 minor; diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h index 3075ac73b171..77ba692d9348 100644 --- a/include/linux/mtd/spi-nor.h +++ b/include/linux/mtd/spi-nor.h @@ -334,6 +334,165 @@ struct spi_nor_erase_map { }; /** + * struct spi_nor_hwcaps - Structure for describing the hardware capabilies + * supported by the SPI controller (bus master). + * @mask: the bitmask listing all the supported hw capabilies + */ +struct spi_nor_hwcaps { + u32 mask; +}; + +/* + *(Fast) Read capabilities. + * MUST be ordered by priority: the higher bit position, the higher priority. + * As a matter of performances, it is relevant to use Octal SPI protocols first, + * then Quad SPI protocols before Dual SPI protocols, Fast Read and lastly + * (Slow) Read. + */ +#define SNOR_HWCAPS_READ_MASK GENMASK(14, 0) +#define SNOR_HWCAPS_READ BIT(0) +#define SNOR_HWCAPS_READ_FAST BIT(1) +#define SNOR_HWCAPS_READ_1_1_1_DTR BIT(2) + +#define SNOR_HWCAPS_READ_DUAL GENMASK(6, 3) +#define SNOR_HWCAPS_READ_1_1_2 BIT(3) +#define SNOR_HWCAPS_READ_1_2_2 BIT(4) +#define SNOR_HWCAPS_READ_2_2_2 BIT(5) +#define SNOR_HWCAPS_READ_1_2_2_DTR BIT(6) + +#define SNOR_HWCAPS_READ_QUAD GENMASK(10, 7) +#define SNOR_HWCAPS_READ_1_1_4 BIT(7) +#define SNOR_HWCAPS_READ_1_4_4 BIT(8) +#define SNOR_HWCAPS_READ_4_4_4 BIT(9) +#define SNOR_HWCAPS_READ_1_4_4_DTR BIT(10) + +#define SNOR_HWCAPS_READ_OCTAL GENMASK(14, 11) +#define SNOR_HWCAPS_READ_1_1_8 BIT(11) +#define SNOR_HWCAPS_READ_1_8_8 BIT(12) +#define SNOR_HWCAPS_READ_8_8_8 BIT(13) +#define SNOR_HWCAPS_READ_1_8_8_DTR BIT(14) + +/* + * Page Program capabilities. + * MUST be ordered by priority: the higher bit position, the higher priority. + * Like (Fast) Read capabilities, Octal/Quad SPI protocols are preferred to the + * legacy SPI 1-1-1 protocol. + * Note that Dual Page Programs are not supported because there is no existing + * JEDEC/SFDP standard to define them. Also at this moment no SPI flash memory + * implements such commands. + */ +#define SNOR_HWCAPS_PP_MASK GENMASK(22, 16) +#define SNOR_HWCAPS_PP BIT(16) + +#define SNOR_HWCAPS_PP_QUAD GENMASK(19, 17) +#define SNOR_HWCAPS_PP_1_1_4 BIT(17) +#define SNOR_HWCAPS_PP_1_4_4 BIT(18) +#define SNOR_HWCAPS_PP_4_4_4 BIT(19) + +#define SNOR_HWCAPS_PP_OCTAL GENMASK(22, 20) +#define SNOR_HWCAPS_PP_1_1_8 BIT(20) +#define SNOR_HWCAPS_PP_1_8_8 BIT(21) +#define SNOR_HWCAPS_PP_8_8_8 BIT(22) + +#define SNOR_HWCAPS_X_X_X (SNOR_HWCAPS_READ_2_2_2 | \ + SNOR_HWCAPS_READ_4_4_4 | \ + SNOR_HWCAPS_READ_8_8_8 | \ + SNOR_HWCAPS_PP_4_4_4 | \ + SNOR_HWCAPS_PP_8_8_8) + +#define SNOR_HWCAPS_DTR (SNOR_HWCAPS_READ_1_1_1_DTR | \ + SNOR_HWCAPS_READ_1_2_2_DTR | \ + SNOR_HWCAPS_READ_1_4_4_DTR | \ + SNOR_HWCAPS_READ_1_8_8_DTR) + +#define SNOR_HWCAPS_ALL (SNOR_HWCAPS_READ_MASK | \ + SNOR_HWCAPS_PP_MASK) + +struct spi_nor_read_command { + u8 num_mode_clocks; + u8 num_wait_states; + u8 opcode; + enum spi_nor_protocol proto; +}; + +struct spi_nor_pp_command { + u8 opcode; + enum spi_nor_protocol proto; +}; + +enum spi_nor_read_command_index { + SNOR_CMD_READ, + SNOR_CMD_READ_FAST, + SNOR_CMD_READ_1_1_1_DTR, + + /* Dual SPI */ + SNOR_CMD_READ_1_1_2, + SNOR_CMD_READ_1_2_2, + SNOR_CMD_READ_2_2_2, + SNOR_CMD_READ_1_2_2_DTR, + + /* Quad SPI */ + SNOR_CMD_READ_1_1_4, + SNOR_CMD_READ_1_4_4, + SNOR_CMD_READ_4_4_4, + SNOR_CMD_READ_1_4_4_DTR, + + /* Octal SPI */ + SNOR_CMD_READ_1_1_8, + SNOR_CMD_READ_1_8_8, + SNOR_CMD_READ_8_8_8, + SNOR_CMD_READ_1_8_8_DTR, + + SNOR_CMD_READ_MAX +}; + +enum spi_nor_pp_command_index { + SNOR_CMD_PP, + + /* Quad SPI */ + SNOR_CMD_PP_1_1_4, + SNOR_CMD_PP_1_4_4, + SNOR_CMD_PP_4_4_4, + + /* Octal SPI */ + SNOR_CMD_PP_1_1_8, + SNOR_CMD_PP_1_8_8, + SNOR_CMD_PP_8_8_8, + + SNOR_CMD_PP_MAX +}; + +/* Forward declaration that will be used in 'struct spi_nor_flash_parameter' */ +struct spi_nor; + +/** + * struct spi_nor_flash_parameter - SPI NOR flash parameters and settings. + * Includes legacy flash parameters and settings that can be overwritten + * by the spi_nor_fixups hooks, or dynamically when parsing the JESD216 + * Serial Flash Discoverable Parameters (SFDP) tables. + * + * @size: the flash memory density in bytes. + * @page_size: the page size of the SPI NOR flash memory. + * @hwcaps: describes the read and page program hardware + * capabilities. + * @reads: read capabilities ordered by priority: the higher index + * in the array, the higher priority. + * @page_programs: page program capabilities ordered by priority: the + * higher index in the array, the higher priority. + * @quad_enable: enables SPI NOR quad mode. + */ +struct spi_nor_flash_parameter { + u64 size; + u32 page_size; + + struct spi_nor_hwcaps hwcaps; + struct spi_nor_read_command reads[SNOR_CMD_READ_MAX]; + struct spi_nor_pp_command page_programs[SNOR_CMD_PP_MAX]; + + int (*quad_enable)(struct spi_nor *nor); +}; + +/** * struct flash_info - Forward declaration of a structure used internally by * spi_nor_scan() */ @@ -379,6 +538,10 @@ struct flash_info; * @quad_enable: [FLASH-SPECIFIC] enables SPI NOR quad mode * @clear_sr_bp: [FLASH-SPECIFIC] clears the Block Protection Bits from * the SPI NOR Status Register. + * @params: [FLASH-SPECIFIC] SPI-NOR flash parameters and settings. + * The structure includes legacy flash parameters and + * settings that can be overwritten by the spi_nor_fixups + * hooks, or dynamically when parsing the SFDP tables. * @priv: the private data */ struct spi_nor { @@ -418,6 +581,7 @@ struct spi_nor { int (*flash_is_locked)(struct spi_nor *nor, loff_t ofs, uint64_t len); int (*quad_enable)(struct spi_nor *nor); int (*clear_sr_bp)(struct spi_nor *nor); + struct spi_nor_flash_parameter params; void *priv; }; @@ -463,81 +627,6 @@ static inline struct device_node *spi_nor_get_flash_node(struct spi_nor *nor) } /** - * struct spi_nor_hwcaps - Structure for describing the hardware capabilies - * supported by the SPI controller (bus master). - * @mask: the bitmask listing all the supported hw capabilies - */ -struct spi_nor_hwcaps { - u32 mask; -}; - -/* - *(Fast) Read capabilities. - * MUST be ordered by priority: the higher bit position, the higher priority. - * As a matter of performances, it is relevant to use Octal SPI protocols first, - * then Quad SPI protocols before Dual SPI protocols, Fast Read and lastly - * (Slow) Read. - */ -#define SNOR_HWCAPS_READ_MASK GENMASK(14, 0) -#define SNOR_HWCAPS_READ BIT(0) -#define SNOR_HWCAPS_READ_FAST BIT(1) -#define SNOR_HWCAPS_READ_1_1_1_DTR BIT(2) - -#define SNOR_HWCAPS_READ_DUAL GENMASK(6, 3) -#define SNOR_HWCAPS_READ_1_1_2 BIT(3) -#define SNOR_HWCAPS_READ_1_2_2 BIT(4) -#define SNOR_HWCAPS_READ_2_2_2 BIT(5) -#define SNOR_HWCAPS_READ_1_2_2_DTR BIT(6) - -#define SNOR_HWCAPS_READ_QUAD GENMASK(10, 7) -#define SNOR_HWCAPS_READ_1_1_4 BIT(7) -#define SNOR_HWCAPS_READ_1_4_4 BIT(8) -#define SNOR_HWCAPS_READ_4_4_4 BIT(9) -#define SNOR_HWCAPS_READ_1_4_4_DTR BIT(10) - -#define SNOR_HWCAPS_READ_OCTAL GENMASK(14, 11) -#define SNOR_HWCAPS_READ_1_1_8 BIT(11) -#define SNOR_HWCAPS_READ_1_8_8 BIT(12) -#define SNOR_HWCAPS_READ_8_8_8 BIT(13) -#define SNOR_HWCAPS_READ_1_8_8_DTR BIT(14) - -/* - * Page Program capabilities. - * MUST be ordered by priority: the higher bit position, the higher priority. - * Like (Fast) Read capabilities, Octal/Quad SPI protocols are preferred to the - * legacy SPI 1-1-1 protocol. - * Note that Dual Page Programs are not supported because there is no existing - * JEDEC/SFDP standard to define them. Also at this moment no SPI flash memory - * implements such commands. - */ -#define SNOR_HWCAPS_PP_MASK GENMASK(22, 16) -#define SNOR_HWCAPS_PP BIT(16) - -#define SNOR_HWCAPS_PP_QUAD GENMASK(19, 17) -#define SNOR_HWCAPS_PP_1_1_4 BIT(17) -#define SNOR_HWCAPS_PP_1_4_4 BIT(18) -#define SNOR_HWCAPS_PP_4_4_4 BIT(19) - -#define SNOR_HWCAPS_PP_OCTAL GENMASK(22, 20) -#define SNOR_HWCAPS_PP_1_1_8 BIT(20) -#define SNOR_HWCAPS_PP_1_8_8 BIT(21) -#define SNOR_HWCAPS_PP_8_8_8 BIT(22) - -#define SNOR_HWCAPS_X_X_X (SNOR_HWCAPS_READ_2_2_2 | \ - SNOR_HWCAPS_READ_4_4_4 | \ - SNOR_HWCAPS_READ_8_8_8 | \ - SNOR_HWCAPS_PP_4_4_4 | \ - SNOR_HWCAPS_PP_8_8_8) - -#define SNOR_HWCAPS_DTR (SNOR_HWCAPS_READ_1_1_1_DTR | \ - SNOR_HWCAPS_READ_1_2_2_DTR | \ - SNOR_HWCAPS_READ_1_4_4_DTR | \ - SNOR_HWCAPS_READ_1_8_8_DTR) - -#define SNOR_HWCAPS_ALL (SNOR_HWCAPS_READ_MASK | \ - SNOR_HWCAPS_PP_MASK) - -/** * spi_nor_scan() - scan the SPI NOR * @nor: the spi_nor structure * @name: the chip type name From patchwork Mon Aug 26 12:08:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tudor Ambarus X-Patchwork-Id: 1153138 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=microchip.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ClDb92Ib"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=microchiptechnology.onmicrosoft.com header.i=@microchiptechnology.onmicrosoft.com header.b="ZB6dtiuG"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46H9m45swMz9sNF for ; Mon, 26 Aug 2019 22:09:24 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=DuXlHJ67OP1MOA0lG9+9K4stMRA2t9rqri3+rO1Jnkw=; b=ClDb92IbLzD5Md /gAq6ABAp2ZllxvBh3g9c0myYyGQ0sW+z3YaEH+jlI49wCWUyDj2tUF/5AIW5cINomnLvJ3DMZoBG LDxkCvvt6ZtPr1LYGk4VKNM9rvir/aIYQq6BLq+AfF2uZLYnz4WkgG0SyVHeDM/WoIINLF7DfJmWs 8cAafxgGVpVrZ8YiNG/XD7rQEfAv6W4DbU8HOrVFDtdjs7amDrZmEMN2jzLiCRKfVUYQ8rq466tr4 rX1q3r2nRO1f8ChD8rg4dNjsonQ1o6AsNnPYufgSgTk56yGICUTRJ29ddof3CygLS5LF+2YVGN3Xx HtLRhXEPPzed42LpV/eQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i2DoI-0002xa-2C; Mon, 26 Aug 2019 12:09:22 +0000 Received: from esa5.microchip.iphmx.com ([216.71.150.166]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i2Dnd-000273-9P for linux-mtd@lists.infradead.org; Mon, 26 Aug 2019 12:08:43 +0000 Received-SPF: Pass (esa5.microchip.iphmx.com: domain of Tudor.Ambarus@microchip.com designates 198.175.253.82 as permitted sender) identity=mailfrom; client-ip=198.175.253.82; receiver=esa5.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="Tudor.Ambarus@microchip.com"; x-conformance=spf_only; x-record-type="v=spf1"; x-record-text="v=spf1 mx a:ushub1.microchip.com a:smtpout.microchip.com a:mx1.microchip.iphmx.com a:mx2.microchip.iphmx.com include:servers.mcsv.net include:mktomail.com include:spf.protection.outlook.com ~all" Received-SPF: None (esa5.microchip.iphmx.com: no sender authenticity information available from domain of postmaster@email.microchip.com) identity=helo; client-ip=198.175.253.82; receiver=esa5.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="postmaster@email.microchip.com"; x-conformance=spf_only Authentication-Results: esa5.microchip.iphmx.com; spf=Pass smtp.mailfrom=Tudor.Ambarus@microchip.com; spf=None smtp.helo=postmaster@email.microchip.com; dkim=pass (signature verified) header.i=@microchiptechnology.onmicrosoft.com; dmarc=pass (p=none dis=none) d=microchip.com IronPort-SDR: 7TQrHCkwBVICkXJvnLJq0DuXM8ur/cag29gNHqHWc/rPoycOAGHPKAyORDAc4W1qMmSHoRh79k D5a1CjxKL2xGGa4/oEmwUL7MHbI79x3GtE/uFnMpUTuIx/8LK8LZx9oiKl2CNs2F559d/VVNHX V0n5JId8Gl6YErZKPCuEk7YtpRGMwfLDwGZBO4/SiHyVUcFlimuotniAuHA5nmxGyr4I04MxcM 7QpkU203+3ARWEGpuVe0uQ0HcXZG3dMMs/WFO+Is2nBZo4U8LkDEk7hEyd0gzh/E8eCoX2w3L+ 7N8= X-IronPort-AV: E=Sophos;i="5.64,433,1559545200"; d="scan'208";a="44989585" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa5.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 26 Aug 2019 05:08:38 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 26 Aug 2019 05:08:38 -0700 Received: from NAM02-BL2-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.87.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5 via Frontend Transport; Mon, 26 Aug 2019 05:08:37 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lTfqJvSG7opVtC2h32KSDFxFTK71oEY9ugW/9qF/YmO4viL61x2hQd3rwNXHSn6bHx5B1Nc9CMpV5wE28RDcjlo+TRHkDIq1ozAZsmPiI1JBru8iYl6aXM3MDjH0ikaAdCe83h2klk3hkBUMlFAxdsrepAd1muDR1VG5tNG5mK8wEXicbxLPejTC+cokOjqIFiVQoRpdrenWDxK8uCHZgfVJj7Vu1Be+rWyOiqxQpqZ+vGCwC24F40S8AEgLTlwqHruZQBGeVKaEh06sdj31pIxS0wdr7yFAJV/UWEng6dxr9ofBw3UC8M1KR3dth9H+5mV8O8ngnonIibkRrDPBkA== 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=bq93V070zUXIi/6zi0b4fz3mqqDGUW+oVUd3XOm/RXU=; b=PuL7ROgVTi9s6l/sejTNbao6UidliiNjvq7CkjzFAd5lfC5KMqC0JbMLsBZQFIEDpLzSNtQJ0xZDQAQKjQun0zFDyG/l+WPSfbDwGb21We77MNXguqCY4eWs/JjHfjsuBa5qjvsTXBQERW05fl5nki5k2OFAyWtY99p5zcn1SE27VSdy3kwbqJr5t4+QdIFK5peF+N1YYkzi9NkvoNFm7tweqlsF79n3919qzA9bZdPyXcidAJy5Jx+/276PYS3MngB3E7VoueiHH8vbHZiMpST6Rsyuu/4WuCRSatjX4dJPloyTU+8zmVofLV0L6BNcv480fHMY69SBMN79u7IjKg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microchip.com; dmarc=pass action=none header.from=microchip.com; dkim=pass header.d=microchip.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microchiptechnology.onmicrosoft.com; s=selector2-microchiptechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bq93V070zUXIi/6zi0b4fz3mqqDGUW+oVUd3XOm/RXU=; b=ZB6dtiuG4TJV7etRlO4C/Qrb9Bt6qt+XvYRHzAJdhcWq44Yrd1trTTF8UYXnUgDMgx+y1AvjSHzMpNZ2D2wOoFooDfg9lPHpc6rzRxEzTuZP2jkXOV2BvIdQD1MABGoLZPENGKI2b05IsszGZZmgBdmdVKeLDF5QNVU1TWI2xSM= Received: from MN2PR11MB4448.namprd11.prod.outlook.com (52.135.39.157) by MN2PR11MB3678.namprd11.prod.outlook.com (20.178.252.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.21; Mon, 26 Aug 2019 12:08:34 +0000 Received: from MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5]) by MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5%7]) with mapi id 15.20.2199.021; Mon, 26 Aug 2019 12:08:34 +0000 From: To: , , , , , , Subject: [RESEND PATCH v3 02/20] mtd: spi-nor: Use nor->params Thread-Topic: [RESEND PATCH v3 02/20] mtd: spi-nor: Use nor->params Thread-Index: AQHVXAb8v3HtmcSeVUudjn0kRXPbNQ== Date: Mon, 26 Aug 2019 12:08:34 +0000 Message-ID: <20190826120821.16351-3-tudor.ambarus@microchip.com> References: <20190826120821.16351-1-tudor.ambarus@microchip.com> In-Reply-To: <20190826120821.16351-1-tudor.ambarus@microchip.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1PR09CA0046.eurprd09.prod.outlook.com (2603:10a6:802:28::14) To MN2PR11MB4448.namprd11.prod.outlook.com (2603:10b6:208:193::29) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.9.5 x-originating-ip: [94.177.32.156] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 3053fddb-ffe9-4baf-fcc4-08d72a1e1e7f x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:MN2PR11MB3678; x-ms-traffictypediagnostic: MN2PR11MB3678: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8273; x-forefront-prvs: 01415BB535 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(136003)(39860400002)(346002)(366004)(396003)(376002)(199004)(189003)(486006)(2616005)(476003)(107886003)(316002)(14454004)(386003)(6506007)(76176011)(99286004)(52116002)(110136005)(478600001)(102836004)(4326008)(25786009)(36756003)(446003)(26005)(11346002)(50226002)(81156014)(66066001)(8676002)(53936002)(81166006)(8936002)(6512007)(6486002)(6436002)(3846002)(6116002)(186003)(86362001)(305945005)(2201001)(7736002)(2906002)(64756008)(66446008)(1076003)(71190400001)(5660300002)(71200400001)(256004)(66946007)(66556008)(66476007)(2501003); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR11MB3678; H:MN2PR11MB4448.namprd11.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: microchip.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: GUu4fzKNO48VsAMm3XQo58XJdkhBO8EPRaQJDtUO+UxkL41/6UKv8SC8XrBzfmLwfKNdPAuLzEkxf2u7jcbR/Pg6GvCOXZqrLDQrVH1Cc91ozZfrKsZc4zTrxUE/TUHNGgdcRP8rdZVOT8yWBScGxLlRP8bq3lArnv5v3nebcvXwHBT8uyfJSf1BizDtSXtuuwmyxvRNibGG3xv3Y4AK2+St7JF/YCMHCoWaAae78YDzuoFdq4vd99YOvYIWCEwJa7qGJd3RN4Vvwh4OiQHIxLbu2ja4B8W6ds64+B9/HhHjp01yqugbnsQyqnpBSy7sB0ZSsH9l1wbQVZr9I/+1kk9lku35Yqv0fLonAR92afQJ7iov2NlWB9PCgX9BOM+3dTmK4WtLm7GRhLamzxgnT/mJCWgw7D0aw01Zc3zaPI8= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 3053fddb-ffe9-4baf-fcc4-08d72a1e1e7f X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Aug 2019 12:08:34.7652 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 8MnNLgbgJWbU6Rebm1a86i9VLNwcHD7SMhhDLg+Bhdf+1lFiQV7sQho9d0zUaXuYWjolZl+wM4Plv7c7PJSzLge2N/9Tdpe8O9DtZGumzqc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB3678 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190826_050841_509798_A32A1872 X-CRM114-Status: GOOD ( 13.15 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [216.71.150.166 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -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 X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tudor.Ambarus@microchip.com Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Tudor Ambarus The Flash parameters and settings are now stored in 'struct spi_nor'. Use this instead of the stack allocated params. Few functions stop passing pointer to params, as they can get it from 'struct spi_nor'. spi_nor_parse_sfdp() and children will keep passing pointer to params because of the roll-back mechanism: in case the parsing of SFDP fails, the legacy flash parameter and settings will be restored. Zeroing params is no longer needed because all SPI NOR users kzalloc 'struct spi_nor'. Signed-off-by: Tudor Ambarus Reviewed-by: Boris Brezillon Reviewed-by: Vignesh Raghavendra --- v3: collect R-b drivers/mtd/spi-nor/spi-nor.c | 46 ++++++++++++++++++------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index d35dc6a97521..e9b9cd70a999 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -2974,16 +2974,13 @@ static int spi_nor_spimem_check_pp(struct spi_nor *nor, * spi_nor_spimem_adjust_hwcaps - Find optimal Read/Write protocol * based on SPI controller capabilities * @nor: pointer to a 'struct spi_nor' - * @params: pointer to the 'struct spi_nor_flash_parameter' - * representing SPI NOR flash capabilities * @hwcaps: pointer to resulting capabilities after adjusting * according to controller and flash's capability */ static void -spi_nor_spimem_adjust_hwcaps(struct spi_nor *nor, - const struct spi_nor_flash_parameter *params, - u32 *hwcaps) +spi_nor_spimem_adjust_hwcaps(struct spi_nor *nor, u32 *hwcaps) { + struct spi_nor_flash_parameter *params = &nor->params; unsigned int cap; /* DTR modes are not supported yet, mask them all. */ @@ -4129,16 +4126,13 @@ static int spi_nor_parse_sfdp(struct spi_nor *nor, return err; } -static int spi_nor_init_params(struct spi_nor *nor, - struct spi_nor_flash_parameter *params) +static int spi_nor_init_params(struct spi_nor *nor) { + struct spi_nor_flash_parameter *params = &nor->params; struct spi_nor_erase_map *map = &nor->erase_map; const struct flash_info *info = nor->info; u8 i, erase_mask; - /* Set legacy flash parameters as default. */ - memset(params, 0, sizeof(*params)); - /* Set SPI NOR sizes. */ params->size = (u64)info->sector_size * info->n_sectors; params->page_size = info->page_size; @@ -4255,7 +4249,6 @@ static int spi_nor_init_params(struct spi_nor *nor, } static int spi_nor_select_read(struct spi_nor *nor, - const struct spi_nor_flash_parameter *params, u32 shared_hwcaps) { int cmd, best_match = fls(shared_hwcaps & SNOR_HWCAPS_READ_MASK) - 1; @@ -4268,7 +4261,7 @@ static int spi_nor_select_read(struct spi_nor *nor, if (cmd < 0) return -EINVAL; - read = ¶ms->reads[cmd]; + read = &nor->params.reads[cmd]; nor->read_opcode = read->opcode; nor->read_proto = read->proto; @@ -4287,7 +4280,6 @@ static int spi_nor_select_read(struct spi_nor *nor, } static int spi_nor_select_pp(struct spi_nor *nor, - const struct spi_nor_flash_parameter *params, u32 shared_hwcaps) { int cmd, best_match = fls(shared_hwcaps & SNOR_HWCAPS_PP_MASK) - 1; @@ -4300,7 +4292,7 @@ static int spi_nor_select_pp(struct spi_nor *nor, if (cmd < 0) return -EINVAL; - pp = ¶ms->page_programs[cmd]; + pp = &nor->params.page_programs[cmd]; nor->program_opcode = pp->opcode; nor->write_proto = pp->proto; return 0; @@ -4407,9 +4399,9 @@ static int spi_nor_select_erase(struct spi_nor *nor, u32 wanted_size) } static int spi_nor_setup(struct spi_nor *nor, - const struct spi_nor_flash_parameter *params, const struct spi_nor_hwcaps *hwcaps) { + struct spi_nor_flash_parameter *params = &nor->params; u32 ignored_mask, shared_mask; bool enable_quad_io; int err; @@ -4426,7 +4418,7 @@ static int spi_nor_setup(struct spi_nor *nor, * need to discard some of them based on what the SPI * controller actually supports (using spi_mem_supports_op()). */ - spi_nor_spimem_adjust_hwcaps(nor, params, &shared_mask); + spi_nor_spimem_adjust_hwcaps(nor, &shared_mask); } else { /* * SPI n-n-n protocols are not supported when the SPI @@ -4442,7 +4434,7 @@ static int spi_nor_setup(struct spi_nor *nor, } /* Select the (Fast) Read command. */ - err = spi_nor_select_read(nor, params, shared_mask); + err = spi_nor_select_read(nor, shared_mask); if (err) { dev_err(nor->dev, "can't select read settings supported by both the SPI controller and memory.\n"); @@ -4450,7 +4442,7 @@ static int spi_nor_setup(struct spi_nor *nor, } /* Select the Page Program command. */ - err = spi_nor_select_pp(nor, params, shared_mask); + err = spi_nor_select_pp(nor, shared_mask); if (err) { dev_err(nor->dev, "can't select write settings supported by both the SPI controller and memory.\n"); @@ -4553,11 +4545,11 @@ static const struct flash_info *spi_nor_match_id(const char *name) int spi_nor_scan(struct spi_nor *nor, const char *name, const struct spi_nor_hwcaps *hwcaps) { - struct spi_nor_flash_parameter params; const struct flash_info *info = NULL; struct device *dev = nor->dev; struct mtd_info *mtd = &nor->mtd; struct device_node *np = spi_nor_get_flash_node(nor); + struct spi_nor_flash_parameter *params = &nor->params; int ret; int i; @@ -4639,7 +4631,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, nor->clear_sr_bp = spi_nor_clear_sr_bp; /* Parse the Serial Flash Discoverable Parameters table. */ - ret = spi_nor_init_params(nor, ¶ms); + ret = spi_nor_init_params(nor); if (ret) return ret; @@ -4649,7 +4641,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, mtd->type = MTD_NORFLASH; mtd->writesize = 1; mtd->flags = MTD_CAP_NORFLASH; - mtd->size = params.size; + mtd->size = params->size; mtd->_erase = spi_nor_erase; mtd->_read = spi_nor_read; mtd->_resume = spi_nor_resume; @@ -4688,18 +4680,18 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, mtd->flags |= MTD_NO_ERASE; mtd->dev.parent = dev; - nor->page_size = params.page_size; + nor->page_size = params->page_size; mtd->writebufsize = nor->page_size; if (np) { /* If we were instantiated by DT, use it */ if (of_property_read_bool(np, "m25p,fast-read")) - params.hwcaps.mask |= SNOR_HWCAPS_READ_FAST; + params->hwcaps.mask |= SNOR_HWCAPS_READ_FAST; else - params.hwcaps.mask &= ~SNOR_HWCAPS_READ_FAST; + params->hwcaps.mask &= ~SNOR_HWCAPS_READ_FAST; } else { /* If we weren't instantiated by DT, default to fast-read */ - params.hwcaps.mask |= SNOR_HWCAPS_READ_FAST; + params->hwcaps.mask |= SNOR_HWCAPS_READ_FAST; } if (of_property_read_bool(np, "broken-flash-reset")) @@ -4707,7 +4699,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, /* Some devices cannot do fast-read, no matter what DT tells us */ if (info->flags & SPI_NOR_NO_FR) - params.hwcaps.mask &= ~SNOR_HWCAPS_READ_FAST; + params->hwcaps.mask &= ~SNOR_HWCAPS_READ_FAST; /* * Configure the SPI memory: @@ -4716,7 +4708,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, * - set the SPI protocols for register and memory accesses. * - set the Quad Enable bit if needed (required by SPI x-y-4 protos). */ - ret = spi_nor_setup(nor, ¶ms, hwcaps); + ret = spi_nor_setup(nor, hwcaps); if (ret) return ret; From patchwork Mon Aug 26 12:08:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tudor Ambarus X-Patchwork-Id: 1153137 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=microchip.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="FCCmf3H3"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=microchiptechnology.onmicrosoft.com header.i=@microchiptechnology.onmicrosoft.com header.b="H5DTQqYp"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46H9m25QS9z9sN1 for ; Mon, 26 Aug 2019 22:09:20 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=s0vftubVtiibGLQsdwSFZSLNRR4+BAuAPbzURJdjbGQ=; b=FCCmf3H3XLhqmM 6wixLBIIPW3n2f08Wv7ugi310n0bUSO8Oj0M57WybrlmEcZeLHXFqrgzQkFQbRqBAikFSnkn325bO alFZZb2EtDUDNr/vHrL4Tmj+rqhFkqgo8ctYYBlhnxHHZACYz9d9En8rec+crBnwf3EGebAfRwSNh UE8x9njgfgLpQURSjR9EdZyzrPtVYS0T/+KDIBND331nCKlfrqiQqReB6Ppa0LuFUn7m6vibJwYCV 9STNubRRNpFoxhT2Ga9lUm1ngLNDHEXvOMsiSWIM1yAhdSZKihTVT4uhwC68EOTjKZX7J02cSmvOF s8VMdfWeGoCT0FKoe+Wg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i2Dnz-0002cD-H3; Mon, 26 Aug 2019 12:09:03 +0000 Received: from esa3.microchip.iphmx.com ([68.232.153.233]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i2Dnc-00029I-Ea for linux-mtd@lists.infradead.org; Mon, 26 Aug 2019 12:08:42 +0000 Received-SPF: Pass (esa3.microchip.iphmx.com: domain of Tudor.Ambarus@microchip.com designates 198.175.253.82 as permitted sender) identity=mailfrom; client-ip=198.175.253.82; receiver=esa3.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="Tudor.Ambarus@microchip.com"; x-conformance=spf_only; x-record-type="v=spf1"; x-record-text="v=spf1 mx a:ushub1.microchip.com a:smtpout.microchip.com a:mx1.microchip.iphmx.com a:mx2.microchip.iphmx.com include:servers.mcsv.net include:mktomail.com include:spf.protection.outlook.com ~all" Received-SPF: None (esa3.microchip.iphmx.com: no sender authenticity information available from domain of postmaster@email.microchip.com) identity=helo; client-ip=198.175.253.82; receiver=esa3.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="postmaster@email.microchip.com"; x-conformance=spf_only Authentication-Results: esa3.microchip.iphmx.com; spf=Pass smtp.mailfrom=Tudor.Ambarus@microchip.com; spf=None smtp.helo=postmaster@email.microchip.com; dkim=pass (signature verified) header.i=@microchiptechnology.onmicrosoft.com; dmarc=pass (p=none dis=none) d=microchip.com IronPort-SDR: TsYjKBeBeh4rqCzYiEh4c0J1KvcXP9tj8yVHEpeBr6q3H8IjDT/asl/Z331WISGPo2/fGH2e4e ok3H+01MAjk+2KUMJfC4YXflAhMEZNVW6EOKeDSxKQ3mMi7Bynjgih/Zofai+wtT/oZtGuc2ob wBLLdjx91/U2DFJ8Ua4Sb5F1V4dpCFUZ4UEioTRts48KcFfSKly5uUgKPs4//kzxZoXsqzEpOc KmV5X6EkgHSc/TAd7LUbQ5kFN5AESvItu6k61P1W1umXv1hwrCSt7RuGF/0MoElUpNYyjfXZN7 ZSw= X-IronPort-AV: E=Sophos;i="5.64,433,1559545200"; d="scan'208";a="46588644" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa3.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 26 Aug 2019 05:08:38 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 26 Aug 2019 05:08:37 -0700 Received: from NAM05-BY2-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.87.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Mon, 26 Aug 2019 05:08:38 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LxE7D1vDquQNjEcB4/BAQE7dyDsnGPCzynMzmUBWyY0HPbtmFakIIHFhesVKAXSLVfhCNhfQNcsF5JqU7NPbj/jL1sWzibnWlcrmc6RHyKLq/Tdob3uLZkABVpK+JpE34wqsdknSwHyBL95diP6bqdCPmApR3QksN0U/ZHPsdOgGlYlmDAutGk73MYTQk9r0JFmP7wnKT8sjr1GwIHKM90RaJWLXkjd5Kj3XN40kh88uO31dKoakLTy6F2gGmru96pmzkwCeMFQFMouzM5C3cV5tDnottGpRcOwiK1QYk4gRHB2KmLBd6iO023Sr/5gJ8vAi7Lt8Ecmz5D+MGuev7A== 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=8dvCftPXVjqfCZG1RlwZNZbXeH+NyMUjdEv6mgeOqrA=; b=hAYWG+j5gLrJPf8+4Ylgua+R/2zjMtn1xK9J4JBDkLXnH9RX+rEe2AbHEa7CSOxzxpbXQ96zyli+BssWTLDvdN3PfesAri+73xtW2NwzgnF1hN4QXKBMzUsfrI+DVB0Q6U8YUWEEeHzzoKB1DgdqLRpZqOBYS3EjpKXg6jB87TW5DdsPZkPNCYXdddImZlJxS6baVuQKA/7Xe/GNh9fOdjb16fX1q2S8IImhzECCO9cGDSSz6qlMNHjPXxIriwMiePWiTWGqulxMDNY4us3qsb6/vIVcv3Pa54qFdF/iMPlsmwqWCwigyUjgaUm4cJ+VOITpySTC6bxi+gtCV179yA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microchip.com; dmarc=pass action=none header.from=microchip.com; dkim=pass header.d=microchip.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microchiptechnology.onmicrosoft.com; s=selector2-microchiptechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8dvCftPXVjqfCZG1RlwZNZbXeH+NyMUjdEv6mgeOqrA=; b=H5DTQqYpGHmnHDuv4WN9ku7Jk7IwYWXd2WmxtHUzniQV2GTmTSlNU6JEnzudLdn202frifMpBN6M7wVYKrZDOqQZB9HPTDsc3/qmJicLRoxCGwVPFj2vp0oA82b4Bo9v5DD2YJ//KCj/I37O7W3s7BpAJhAiojXVNgTbOtOi/Jw= Received: from MN2PR11MB4448.namprd11.prod.outlook.com (52.135.39.157) by MN2PR11MB3776.namprd11.prod.outlook.com (20.178.251.156) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.21; Mon, 26 Aug 2019 12:08:36 +0000 Received: from MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5]) by MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5%7]) with mapi id 15.20.2199.021; Mon, 26 Aug 2019 12:08:36 +0000 From: To: , , , , , , Subject: [RESEND PATCH v3 03/20] mtd: spi-nor: Drop quad_enable() from 'struct spi-nor' Thread-Topic: [RESEND PATCH v3 03/20] mtd: spi-nor: Drop quad_enable() from 'struct spi-nor' Thread-Index: AQHVXAb946wbKymnL0+71ryjF/dWPA== Date: Mon, 26 Aug 2019 12:08:36 +0000 Message-ID: <20190826120821.16351-4-tudor.ambarus@microchip.com> References: <20190826120821.16351-1-tudor.ambarus@microchip.com> In-Reply-To: <20190826120821.16351-1-tudor.ambarus@microchip.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1PR09CA0046.eurprd09.prod.outlook.com (2603:10a6:802:28::14) To MN2PR11MB4448.namprd11.prod.outlook.com (2603:10b6:208:193::29) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.9.5 x-originating-ip: [94.177.32.156] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: c8f9bff4-6d76-4d0d-2a37-08d72a1e1f94 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:MN2PR11MB3776; x-ms-traffictypediagnostic: MN2PR11MB3776: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:6430; x-forefront-prvs: 01415BB535 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(396003)(366004)(376002)(346002)(136003)(39860400002)(189003)(199004)(81166006)(81156014)(8676002)(1076003)(2201001)(2501003)(14444005)(256004)(26005)(7736002)(99286004)(66066001)(2906002)(76176011)(52116002)(316002)(186003)(50226002)(8936002)(66476007)(66556008)(64756008)(66946007)(66446008)(110136005)(53936002)(2616005)(36756003)(25786009)(5660300002)(386003)(305945005)(6506007)(102836004)(3846002)(6116002)(446003)(11346002)(478600001)(4326008)(86362001)(6436002)(6486002)(6512007)(14454004)(71200400001)(71190400001)(107886003)(476003)(486006); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR11MB3776; H:MN2PR11MB4448.namprd11.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: microchip.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: mk2JiNYoxXXHsoCd/+IUauF/DqWWJhSg0/Wsx9iUxPdQEFTBT0c7gkas70YGze+mG6arsVEs0ULgR8fEJqLK0d+1uxOKO2w+TIoH/VJcfeF7+Xqr1gquJXwmoE8yYW6T8M36H69Jfk8GrFq0FqR8b+iQyWXe0MZ01yaGCPWJvzN+685WcBegtIP+k9lkZGNJliu6tnuVqd+D6tL5SnUM7uvjlXpm3nLnV1HeQkSly4CPvQJOLhmEKSBiZXqQT9GBqcDg7HgIUdbq+Ryeg88SHUwvwdMEi6+e++e+FeoH5POT6fc4BNU0ybx+lYWiS926VVubpq0I/R1ghG3JKr9iYZNfnWDGd6MQLj5EZ9iQ/O72uPQvOxVgLQyc+qMgHNyyHe8oZxRbx6I1BiC53SFS1PGiAW1ljMGaQR2V1qdCO9o= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: c8f9bff4-6d76-4d0d-2a37-08d72a1e1f94 X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Aug 2019 12:08:36.5522 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 4y8ohpSl/QG+TgHNSeml4eITBvOIe8VlUJaLokkwJzVTMccZlFveT1zDtd8mQGUK0a8WCvWs/LUUhzSP1ohRO4bcgdW954gtYEoKdsfjSi0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB3776 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190826_050840_705412_C17317F7 X-CRM114-Status: GOOD ( 13.19 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [68.232.153.233 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -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 X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tudor.Ambarus@microchip.com Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Tudor Ambarus All flash parameters and settings should reside inside 'struct spi_nor_flash_parameter'. Drop the local copy of quad_enable() and use the one from 'struct spi_nor_flash_parameter'. Signed-off-by: Tudor Ambarus Reviewed-by: Boris Brezillon Reviewed-by: Vignesh Raghavendra --- v3: Collect R-b drivers/mtd/spi-nor/spi-nor.c | 40 +++++++++++++++++++++++----------------- include/linux/mtd/spi-nor.h | 2 -- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index e9b9cd70a999..effda372cb33 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -4403,7 +4403,6 @@ static int spi_nor_setup(struct spi_nor *nor, { struct spi_nor_flash_parameter *params = &nor->params; u32 ignored_mask, shared_mask; - bool enable_quad_io; int err; /* @@ -4457,23 +4456,33 @@ static int spi_nor_setup(struct spi_nor *nor, return err; } - /* Enable Quad I/O if needed. */ - enable_quad_io = (spi_nor_get_protocol_width(nor->read_proto) == 4 || - spi_nor_get_protocol_width(nor->write_proto) == 4); - if (enable_quad_io && params->quad_enable) - nor->quad_enable = params->quad_enable; - else - nor->quad_enable = NULL; - return 0; } +/** + * spi_nor_quad_enable() - enable Quad I/O if needed. + * @nor: pointer to a 'struct spi_nor' + * + * Return: 0 on success, -errno otherwise. + */ +static int spi_nor_quad_enable(struct spi_nor *nor) +{ + if (!nor->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); +} + static int spi_nor_init(struct spi_nor *nor) { int err; if (nor->clear_sr_bp) { - if (nor->quad_enable == spansion_quad_enable) + if (nor->params.quad_enable == spansion_quad_enable) nor->clear_sr_bp = spi_nor_spansion_clear_sr_bp; err = nor->clear_sr_bp(nor); @@ -4484,12 +4493,10 @@ static int spi_nor_init(struct spi_nor *nor) } } - if (nor->quad_enable) { - err = nor->quad_enable(nor); - if (err) { - dev_err(nor->dev, "quad mode not supported\n"); - return err; - } + err = spi_nor_quad_enable(nor); + if (err) { + dev_err(nor->dev, "quad mode not supported\n"); + return err; } if (nor->addr_width == 4 && !(nor->flags & SNOR_F_4B_OPCODES)) { @@ -4706,7 +4713,6 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, * - select op codes for (Fast) Read, Page Program and Sector Erase. * - set the number of dummy cycles (mode cycles + wait states). * - set the SPI protocols for register and memory accesses. - * - set the Quad Enable bit if needed (required by SPI x-y-4 protos). */ ret = spi_nor_setup(nor, hwcaps); if (ret) diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h index 77ba692d9348..17787238f0e9 100644 --- a/include/linux/mtd/spi-nor.h +++ b/include/linux/mtd/spi-nor.h @@ -535,7 +535,6 @@ struct flash_info; * @flash_unlock: [FLASH-SPECIFIC] unlock a region of the SPI NOR * @flash_is_locked: [FLASH-SPECIFIC] check if a region of the SPI NOR is * completely locked - * @quad_enable: [FLASH-SPECIFIC] enables SPI NOR quad mode * @clear_sr_bp: [FLASH-SPECIFIC] clears the Block Protection Bits from * the SPI NOR Status Register. * @params: [FLASH-SPECIFIC] SPI-NOR flash parameters and settings. @@ -579,7 +578,6 @@ struct spi_nor { int (*flash_lock)(struct spi_nor *nor, loff_t ofs, uint64_t len); int (*flash_unlock)(struct spi_nor *nor, loff_t ofs, uint64_t len); int (*flash_is_locked)(struct spi_nor *nor, loff_t ofs, uint64_t len); - int (*quad_enable)(struct spi_nor *nor); int (*clear_sr_bp)(struct spi_nor *nor); struct spi_nor_flash_parameter params; From patchwork Mon Aug 26 12:08:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tudor Ambarus X-Patchwork-Id: 1153139 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=microchip.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="jLSlm8fK"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=microchiptechnology.onmicrosoft.com header.i=@microchiptechnology.onmicrosoft.com header.b="lMz8xcEl"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46H9mS3HfLz9sNm for ; Mon, 26 Aug 2019 22:09:44 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=84rBXccW0FKruWm2YJAKtaVu8TxKKgonalDe9R7PV/s=; b=jLSlm8fKQK8KlD O4NvOMIIj2lOyBvvnFELlQxAIlgWa0CfDnKi9X1fgIqNA6A7Tk8J4QXmX21fzfQrT/9nEK1udZadC FICMDfSrSnag0mdaaKONexyWz7UOjhEcorrI02cEJlCweE6xVNo7M9DUxetkj8bPV15Zk80rxKz6e NGnVGXXjW5Hw+3IF+5fjgv3N7zM1AkFS4lTpT6A83TUcF8330zAK53O9ZDLqHWyFtyp4Oi7Bh6C8M a/oXRoZP5ObeYExePcfKsUhqeMqDVOs8CAcSn4y+ImN8jq/sLInrc2MVcG0oWebAMzRodVjyIF749 HK3ya1B+I+lQA5NI1kBg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i2Doa-0003Cy-DW; Mon, 26 Aug 2019 12:09:40 +0000 Received: from esa3.microchip.iphmx.com ([68.232.153.233]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i2Dne-0002Ct-6c for linux-mtd@lists.infradead.org; Mon, 26 Aug 2019 12:08:44 +0000 Received-SPF: Pass (esa3.microchip.iphmx.com: domain of Tudor.Ambarus@microchip.com designates 198.175.253.82 as permitted sender) identity=mailfrom; client-ip=198.175.253.82; receiver=esa3.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="Tudor.Ambarus@microchip.com"; x-conformance=spf_only; x-record-type="v=spf1"; x-record-text="v=spf1 mx a:ushub1.microchip.com a:smtpout.microchip.com a:mx1.microchip.iphmx.com a:mx2.microchip.iphmx.com include:servers.mcsv.net include:mktomail.com include:spf.protection.outlook.com ~all" Received-SPF: None (esa3.microchip.iphmx.com: no sender authenticity information available from domain of postmaster@email.microchip.com) identity=helo; client-ip=198.175.253.82; receiver=esa3.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="postmaster@email.microchip.com"; x-conformance=spf_only Authentication-Results: esa3.microchip.iphmx.com; spf=Pass smtp.mailfrom=Tudor.Ambarus@microchip.com; spf=None smtp.helo=postmaster@email.microchip.com; dkim=pass (signature verified) header.i=@microchiptechnology.onmicrosoft.com; dmarc=pass (p=none dis=none) d=microchip.com IronPort-SDR: RSMfY9MQO3VDtCKe3jt5S7R1olWevzeZq5ehzvGRj+VyflnUrdjclfi/h8ASXpfm0M2WgW7+8c MwAUS8d+u0j/h/QhNTTBAeGnP+lWjALTCs8GRlqheFZ1lUBUe0OMgr1Fg22R8H/ZAGpoMSTRCT zzRExPxdHkDLJyqrjjn8/wJ9lbPiS1X+nkIm9DhaJnvplU/kjRCUSm6ckw4FZrjErFK001hely YV6nxqQhliMejvM2ADgCya7jHrn/43b1vBIPddUKV3PQpSheDrBEXRSrixzxit+v1UbweuSXo9 5kM= X-IronPort-AV: E=Sophos;i="5.64,433,1559545200"; d="scan'208";a="46588652" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa3.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 26 Aug 2019 05:08:39 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 26 Aug 2019 05:08:39 -0700 Received: from NAM05-BY2-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.87.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Mon, 26 Aug 2019 05:08:38 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gSbB9CwGQbh4c0OMxHLT3QhxhjeW1MNfYaGAc0DmYoM7FUHDoJsypQxrotuJd7RzMkW1ylimFC1QhXzIENF62BrzMqH06nlYjbaZfysuDVq434sFUPr4EYRCzNtF+O1WXa/ounAs/UVlG/mWEWubxZWAR15vRsOoNIWzyB57s//saTjHPnwYQmyNxdt60SA/6ShpKNa/M7ELZw5bbVfwIIEYls3L5JneD7DmSgySMkg1tzis9hBOOWqQ9IYettljkhO+8btL3WadK9J/xPq6uvJX3vqpKMIFL1P0qviI7Md2TO5k27C3XT5r6ZZ7XWBddAnSbYqdxUFSGVMwIlGvPg== 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=o+uGO1wnUc7VOBpwSlQm2Jwaf7rqoSKbN4C3jVfhH9Y=; b=UHLiRhJXGbDBkaZXkhSZAaKxk7x0Bo/Xd+gPcxU1Q8Soiu7ZQ0kxrOzDZddvTJo9xtP0hD+73T493DuVEG/xJy9GiyUJvWrF/4B+4lipPLJym1zngdIw8llke1Wd3DvNFo8065YOUn7TCw7guWTI0JRjppvw/oaqxZJGIKfzv7R+VwMFiwNQZFvpV2H7TnN/xS8oBjRvoKZDppp63aaiy+UqAf0veE2pyV297idhIAaL9l4kwab0p8CY0DJki27CHvoYa74dvYhTRpA4TiWYSULHLeO34W98WMxdyNX/B4fvwRyMkulv8sZ5nnb/jjwMMtb0G7HDwQlSDLyRBtDJCQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microchip.com; dmarc=pass action=none header.from=microchip.com; dkim=pass header.d=microchip.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microchiptechnology.onmicrosoft.com; s=selector2-microchiptechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=o+uGO1wnUc7VOBpwSlQm2Jwaf7rqoSKbN4C3jVfhH9Y=; b=lMz8xcElED3nyhKQca+mXVHs4JFgA//owHmL/1/Sl56kvh4uGcQ1QCJqN1zhb0YLFSVXFF8A3zxcgBJcc+Cy8qYE22jI+wwxN3DC/RsV+i8wEHhoWqXQUJlCImu2K6apFWVDKIO+QbRVr9kyI/y9j8+FIhOcjz/ch+BCRyXUBb4= Received: from MN2PR11MB4448.namprd11.prod.outlook.com (52.135.39.157) by MN2PR11MB3776.namprd11.prod.outlook.com (20.178.251.156) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.21; Mon, 26 Aug 2019 12:08:38 +0000 Received: from MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5]) by MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5%7]) with mapi id 15.20.2199.021; Mon, 26 Aug 2019 12:08:38 +0000 From: To: , , , , , , Subject: [RESEND PATCH v3 04/20] mtd: spi-nor: Move erase_map to 'struct spi_nor_flash_parameter' Thread-Topic: [RESEND PATCH v3 04/20] mtd: spi-nor: Move erase_map to 'struct spi_nor_flash_parameter' Thread-Index: AQHVXAb+LyfB/XPAd0GskU8GfSPs9A== Date: Mon, 26 Aug 2019 12:08:38 +0000 Message-ID: <20190826120821.16351-5-tudor.ambarus@microchip.com> References: <20190826120821.16351-1-tudor.ambarus@microchip.com> In-Reply-To: <20190826120821.16351-1-tudor.ambarus@microchip.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1PR09CA0046.eurprd09.prod.outlook.com (2603:10a6:802:28::14) To MN2PR11MB4448.namprd11.prod.outlook.com (2603:10b6:208:193::29) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.9.5 x-originating-ip: [94.177.32.156] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: abd8ecd2-fe80-4032-0998-08d72a1e20a8 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:MN2PR11MB3776; x-ms-traffictypediagnostic: MN2PR11MB3776: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8882; x-forefront-prvs: 01415BB535 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(396003)(366004)(376002)(346002)(136003)(39860400002)(189003)(199004)(81166006)(81156014)(8676002)(1076003)(2201001)(2501003)(14444005)(256004)(26005)(7736002)(99286004)(66066001)(2906002)(76176011)(52116002)(316002)(186003)(50226002)(8936002)(66476007)(66556008)(64756008)(66946007)(66446008)(110136005)(53936002)(2616005)(36756003)(25786009)(5660300002)(386003)(305945005)(6506007)(102836004)(3846002)(6116002)(446003)(11346002)(478600001)(4326008)(86362001)(6436002)(6486002)(6512007)(14454004)(71200400001)(71190400001)(107886003)(476003)(486006)(309714004); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR11MB3776; H:MN2PR11MB4448.namprd11.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: microchip.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: I9CMYJZzEjJk+q0prDdStHQEesGBIu6mO7Z1v7iTERZxlnLPej/QuWHk3BNNn2NqMcATsa4lCu+TEUn4D0TfP6CdGbSZ35mOgYNG/rNuW7+jXXzEP90YMUjB1xZxi4BisHTsNwv7HLiNXS0KKFj5/5ScvSVPuvQmfJENkNZ/XhHV/bBPU2pZqCfz7xwxF8BqUk+sQ16AajHDTfLrbapIgot/zSQeUdTuPqdaljb3rheM700M140NL0tdxrJILqfGJiRtlDQ1bUAckULvrcszxH+g66C05TQ9OJn8nlOAX+mrTcPt7zz7ha1zFzTToWNaboaSrqFKsSAsrVb1zCdoZsBJXgYW/NC0oMh0tBzaZM8GJ6/RfuihlYZ32XcQ6YkwkAHQdCNAhXF3j5InMf/zOFIohGet4lCrI+qSxuRBUTw= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: abd8ecd2-fe80-4032-0998-08d72a1e20a8 X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Aug 2019 12:08:38.3572 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: MNWJh5P7z/Ax1o9CiW965mcdZdeboGzTnnhf+/Lmv6s+YOVyfkWLsCBxsxS2231LKhS+ks0wsPTL/plrE8eVQDWFd+O9YAp8AAzYvysZnkc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB3776 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190826_050842_457010_5D90030C X-CRM114-Status: GOOD ( 13.80 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [68.232.153.233 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -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 X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tudor.Ambarus@microchip.com Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Tudor Ambarus All flash parameters and settings should reside inside 'struct spi_nor_flash_parameter'. Move the SMPT parsed erase map from 'struct spi_nor' to 'struct spi_nor_flash_parameter'. Please note that there is a roll-back mechanism for the flash parameter and settings, for cases when SFDP parser fails. The SFDP parser receives a Stack allocated copy of nor->params, called sfdp_params, and uses it to retrieve the serial flash discoverable parameters. JESD216 SFDP is a standard and has a higher priority than the default initialized flash parameters, so will overwrite the sfdp_params data when needed. All SFDP code uses the local copy of nor->params, that will overwrite it in the end, if the parser succeds. Saving and restoring the nor->params.erase_map is no longer needed, since the SFDP code does not touch it. Signed-off-by: Tudor Ambarus Reviewed-by: Vignesh Raghavendra --- v3: Collect R-b drivers/mtd/spi-nor/spi-nor.c | 40 +++++++++++++++++++++------------------- include/linux/mtd/spi-nor.h | 8 +++++--- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index effda372cb33..9dd6cd8cd13c 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -600,7 +600,7 @@ static void spi_nor_set_4byte_opcodes(struct spi_nor *nor) 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->erase_map; + struct spi_nor_erase_map *map = &nor->params.erase_map; struct spi_nor_erase_type *erase; int i; @@ -1133,7 +1133,7 @@ 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->erase_map; + const struct spi_nor_erase_map *map = &nor->params.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; @@ -3328,7 +3328,7 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor, const struct sfdp_parameter_header *bfpt_header, struct spi_nor_flash_parameter *params) { - struct spi_nor_erase_map *map = &nor->erase_map; + struct spi_nor_erase_map *map = ¶ms->erase_map; struct spi_nor_erase_type *erase_type = map->erase_type; struct sfdp_bfpt bfpt; size_t len; @@ -3409,7 +3409,7 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor, * Erase Types defined in the bfpt table. */ erase_mask = 0; - memset(&nor->erase_map, 0, sizeof(nor->erase_map)); + memset(¶ms->erase_map, 0, sizeof(params->erase_map)); for (i = 0; i < ARRAY_SIZE(sfdp_bfpt_erases); i++) { const struct sfdp_bfpt_erase *er = &sfdp_bfpt_erases[i]; u32 erasesize; @@ -3684,14 +3684,18 @@ spi_nor_region_check_overlay(struct spi_nor_erase_region *region, /** * spi_nor_init_non_uniform_erase_map() - initialize the non-uniform erase map * @nor: pointer to a 'struct spi_nor' + * @params: pointer to a duplicate 'struct spi_nor_flash_parameter' that is + * used for storing SFDP parsed data * @smpt: pointer to the sector map parameter table * * Return: 0 on success, -errno otherwise. */ -static int spi_nor_init_non_uniform_erase_map(struct spi_nor *nor, - const u32 *smpt) +static int +spi_nor_init_non_uniform_erase_map(struct spi_nor *nor, + struct spi_nor_flash_parameter *params, + const u32 *smpt) { - struct spi_nor_erase_map *map = &nor->erase_map; + 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; @@ -3770,6 +3774,8 @@ static int spi_nor_init_non_uniform_erase_map(struct spi_nor *nor, * spi_nor_parse_smpt() - parse Sector Map Parameter Table * @nor: pointer to a 'struct spi_nor' * @smpt_header: sector map parameter table header + * @params: pointer to a duplicate 'struct spi_nor_flash_parameter' + * that is used for storing SFDP parsed data * * This table is optional, but when available, we parse it to identify the * location and size of sectors within the main data array of the flash memory @@ -3778,7 +3784,8 @@ static int spi_nor_init_non_uniform_erase_map(struct spi_nor *nor, * Return: 0 on success, -errno otherwise. */ static int spi_nor_parse_smpt(struct spi_nor *nor, - const struct sfdp_parameter_header *smpt_header) + const struct sfdp_parameter_header *smpt_header, + struct spi_nor_flash_parameter *params) { const u32 *sector_map; u32 *smpt; @@ -3807,11 +3814,11 @@ static int spi_nor_parse_smpt(struct spi_nor *nor, goto out; } - ret = spi_nor_init_non_uniform_erase_map(nor, sector_map); + ret = spi_nor_init_non_uniform_erase_map(nor, params, sector_map); if (ret) goto out; - spi_nor_regions_sort_erase_types(&nor->erase_map); + spi_nor_regions_sort_erase_types(¶ms->erase_map); /* fall through */ out: kfree(smpt); @@ -3867,7 +3874,7 @@ static int spi_nor_parse_4bait(struct spi_nor *nor, { 0u /* not used */, BIT(12) }, }; struct spi_nor_pp_command *params_pp = params->page_programs; - struct spi_nor_erase_map *map = &nor->erase_map; + struct spi_nor_erase_map *map = ¶ms->erase_map; struct spi_nor_erase_type *erase_type = map->erase_type; u32 *dwords; size_t len; @@ -4097,7 +4104,7 @@ static int spi_nor_parse_sfdp(struct spi_nor *nor, switch (SFDP_PARAM_HEADER_ID(param_header)) { case SFDP_SECTOR_MAP_ID: - err = spi_nor_parse_smpt(nor, param_header); + err = spi_nor_parse_smpt(nor, param_header, params); break; case SFDP_4BAIT_ID: @@ -4129,7 +4136,7 @@ static int spi_nor_parse_sfdp(struct spi_nor *nor, static int spi_nor_init_params(struct spi_nor *nor) { struct spi_nor_flash_parameter *params = &nor->params; - struct spi_nor_erase_map *map = &nor->erase_map; + struct spi_nor_erase_map *map = ¶ms->erase_map; const struct flash_info *info = nor->info; u8 i, erase_mask; @@ -4229,17 +4236,12 @@ static int spi_nor_init_params(struct spi_nor *nor) if ((info->flags & (SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ)) && !(info->flags & SPI_NOR_SKIP_SFDP)) { struct spi_nor_flash_parameter sfdp_params; - struct spi_nor_erase_map prev_map; memcpy(&sfdp_params, params, sizeof(sfdp_params)); - memcpy(&prev_map, &nor->erase_map, sizeof(prev_map)); if (spi_nor_parse_sfdp(nor, &sfdp_params)) { nor->addr_width = 0; nor->flags &= ~SNOR_F_4B_OPCODES; - /* restore previous erase map */ - memcpy(&nor->erase_map, &prev_map, - sizeof(nor->erase_map)); } else { memcpy(params, &sfdp_params, sizeof(*params)); } @@ -4353,7 +4355,7 @@ spi_nor_select_uniform_erase(struct spi_nor_erase_map *map, static int spi_nor_select_erase(struct spi_nor *nor, u32 wanted_size) { - struct spi_nor_erase_map *map = &nor->erase_map; + struct spi_nor_erase_map *map = &nor->params.erase_map; const struct spi_nor_erase_type *erase = NULL; struct mtd_info *mtd = &nor->mtd; int i; diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h index 17787238f0e9..a86c0d9fb01d 100644 --- a/include/linux/mtd/spi-nor.h +++ b/include/linux/mtd/spi-nor.h @@ -479,6 +479,8 @@ struct spi_nor; * in the array, the higher priority. * @page_programs: page program capabilities ordered by priority: the * higher index in the array, the higher priority. + * @erase_map: the erase map parsed from the SFDP Sector Map Parameter + * Table. * @quad_enable: enables SPI NOR quad mode. */ struct spi_nor_flash_parameter { @@ -489,6 +491,8 @@ struct spi_nor_flash_parameter { struct spi_nor_read_command reads[SNOR_CMD_READ_MAX]; struct spi_nor_pp_command page_programs[SNOR_CMD_PP_MAX]; + struct spi_nor_erase_map erase_map; + int (*quad_enable)(struct spi_nor *nor); }; @@ -519,7 +523,6 @@ struct flash_info; * @read_proto: the SPI protocol for read operations * @write_proto: the SPI protocol for write operations * @reg_proto the SPI protocol for read_reg/write_reg/erase operations - * @erase_map: the erase map of the SPI NOR * @prepare: [OPTIONAL] do some preparations for the * read/write/erase/lock/unlock operations * @unprepare: [OPTIONAL] do some post work after the @@ -562,7 +565,6 @@ struct spi_nor { enum spi_nor_protocol reg_proto; bool sst_write_second; u32 flags; - struct spi_nor_erase_map erase_map; int (*prepare)(struct spi_nor *nor, enum spi_nor_ops ops); void (*unprepare)(struct spi_nor *nor, enum spi_nor_ops ops); @@ -610,7 +612,7 @@ spi_nor_region_mark_overlay(struct spi_nor_erase_region *region) static bool __maybe_unused spi_nor_has_uniform_erase(const struct spi_nor *nor) { - return !!nor->erase_map.uniform_erase_type; + return !!nor->params.erase_map.uniform_erase_type; } static inline void spi_nor_set_flash_node(struct spi_nor *nor, From patchwork Mon Aug 26 12:08:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tudor Ambarus X-Patchwork-Id: 1153140 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=microchip.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="nP4+VeOM"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=microchiptechnology.onmicrosoft.com header.i=@microchiptechnology.onmicrosoft.com header.b="V0CCKfaj"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46H9md0F6wz9sNm for ; Mon, 26 Aug 2019 22:09:53 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=347UlcewL/9g36A029q+972lKV6h8dsxSGSvqDP8iZ0=; b=nP4+VeOMCuWCKR dn/RYZMWq+ABstW72ZtmQ/QE3OqOl8P3wgmYIkLM7mMIKt7z8RZXqXEcup9SahMZr2ArlRzEnVKHK k8M8wIr/H6o4/9Fio85hfw16Hx4P4tcrMp3WbVxFTgP5dz9c+bsYaXyWcycPT2SYkU5KYVdOp78gA eqdYk4Kj8Oz3VaSqBsGMz4N55xEfGLfKC86bVGsxNphTusF+y80aqqvWUm1heP3HKnIDerMHH39pk ksYeM3V7TXnNzmd+YHSGXv/97fQVo4vme50yFwZsoxKDzTwH/wqO4M0ROBUsogeC/u69Q4sZV/pDt tDyjUXXjx2Q0adfvULuw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i2Dok-0003Rb-4W; Mon, 26 Aug 2019 12:09:50 +0000 Received: from esa3.microchip.iphmx.com ([68.232.153.233]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i2Dne-00029I-PM for linux-mtd@lists.infradead.org; Mon, 26 Aug 2019 12:08:44 +0000 Received-SPF: Pass (esa3.microchip.iphmx.com: domain of Tudor.Ambarus@microchip.com designates 198.175.253.82 as permitted sender) identity=mailfrom; client-ip=198.175.253.82; receiver=esa3.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="Tudor.Ambarus@microchip.com"; x-conformance=spf_only; x-record-type="v=spf1"; x-record-text="v=spf1 mx a:ushub1.microchip.com a:smtpout.microchip.com a:mx1.microchip.iphmx.com a:mx2.microchip.iphmx.com include:servers.mcsv.net include:mktomail.com include:spf.protection.outlook.com ~all" Received-SPF: None (esa3.microchip.iphmx.com: no sender authenticity information available from domain of postmaster@email.microchip.com) identity=helo; client-ip=198.175.253.82; receiver=esa3.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="postmaster@email.microchip.com"; x-conformance=spf_only Authentication-Results: esa3.microchip.iphmx.com; spf=Pass smtp.mailfrom=Tudor.Ambarus@microchip.com; spf=None smtp.helo=postmaster@email.microchip.com; dkim=pass (signature verified) header.i=@microchiptechnology.onmicrosoft.com; dmarc=pass (p=none dis=none) d=microchip.com IronPort-SDR: 4iuDsoMwAHW5V1FMMDQnp/g6KPy6xqRhZQSps6TOR4sQiH+eVP+YZkPjnqEjc1qkS1UGdIdfC/ nCarbZ50lCUaD9DVKnfaJLfVUzLAlA39+gadHfW8zG77aTFWC66qHBclFvJKUjERWolAgQX/ye Pn5ikpmZkxPw1Wr45zAa012ncBr1FT1bLKeqSav1M7IvKTVn9XL3KI/XwJjeoQ0iH4DfJbrMAS pVV/e+/IvECYmZA2hMxiy5WyfhJZq7hIl0UfygRjF0C8jOXzMB2QSfvraND5SBNfPVrEvmSpoG kno= X-IronPort-AV: E=Sophos;i="5.64,433,1559545200"; d="scan'208";a="46588662" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa3.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 26 Aug 2019 05:08:41 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 26 Aug 2019 05:08:40 -0700 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.87.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Mon, 26 Aug 2019 05:08:41 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O3ero/EGkIU1OqP/TFUYuRDpXnmMYnMD2L9RIoX3Z+vSzvuoB/QFm2UV6q5u+15Y6fvMy2exs4lPShYCw+NAmtt27yGdSvkdM2mcTotnz5rny0KkmenpmTjZde1M6gA1qiMP3UDRtVXki8hXFWh5EsTt2lRE2VQSD82w6bRzJdaIirhUJQxXNKs3cxJN4tfKs2ry6Ye/t7JdjcT7nSEfsaK7Aqc8WNzLbvzuzqd7MI4/paihdq5Ajr3ZTVri1OdQSLkrHZITnyPQQI85Se/oYBWxYgio++7ETOn89afc6suI02zJWt/1I+YPVq0BK92yKq+DIj8IAb9//MLZan8xBA== 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=DwKSHrY1sL5NFIU0YsLoNrhAdYjjSkmwTlWfEaXcz98=; b=bL6Ch0ZfRFnG+KARjul2QvNIjsyYcVGTq3ubMkRZmyNzpe8fXZzUQLgnMiwDfyKcm9Pz1gO3GWPYCBykCUTrYQB6E2AS5BpVOArLAAWuyP5E/V8O1pSX+iR7MK3dItI41ukjYktfZJOZu6L32kXQlMPrijhPKrvroWkealaB2mTi3m9htuWD2SSpXyBHkJ6tHsrpQQ60Gphk9vts9fqltDR1Qk3e8t8HhQXevAS/z6/I9uUOyBwrj/RTdls1sZgwUCJtL5WjanSxVLG1WKhwmEnN27TjMh9Z9Zc0Vc8Z9ygig/amHjj5qNNDnIKAwQTWhqyCrcgKjNaV5x39iyrE5w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microchip.com; dmarc=pass action=none header.from=microchip.com; dkim=pass header.d=microchip.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microchiptechnology.onmicrosoft.com; s=selector2-microchiptechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=DwKSHrY1sL5NFIU0YsLoNrhAdYjjSkmwTlWfEaXcz98=; b=V0CCKfajpDWf6jYEsOeQgI3swLv8gZlk0YyBQbuSNKEW15VlaNGDGnOooJ+l+BjrBBqIfqSbP6NxHsZVOazWms1Wzq6VH+U7ud9Jen83JX6FTgegtluINLMg32OB72NF1g4FxYRWDuQ4oDxJre0aWq250Q6vcvi5ruWK4X9qvcw= Received: from MN2PR11MB4448.namprd11.prod.outlook.com (52.135.39.157) by MN2PR11MB3776.namprd11.prod.outlook.com (20.178.251.156) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.21; Mon, 26 Aug 2019 12:08:40 +0000 Received: from MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5]) by MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5%7]) with mapi id 15.20.2199.021; Mon, 26 Aug 2019 12:08:40 +0000 From: To: , , , , , , Subject: [RESEND PATCH v3 05/20] mtd: spi-nor: Add default_init() hook to tweak flash parameters Thread-Topic: [RESEND PATCH v3 05/20] mtd: spi-nor: Add default_init() hook to tweak flash parameters Thread-Index: AQHVXAb/LlGxn5ixREWid4Y05AigaA== Date: Mon, 26 Aug 2019 12:08:40 +0000 Message-ID: <20190826120821.16351-6-tudor.ambarus@microchip.com> References: <20190826120821.16351-1-tudor.ambarus@microchip.com> In-Reply-To: <20190826120821.16351-1-tudor.ambarus@microchip.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1PR09CA0046.eurprd09.prod.outlook.com (2603:10a6:802:28::14) To MN2PR11MB4448.namprd11.prod.outlook.com (2603:10b6:208:193::29) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.9.5 x-originating-ip: [94.177.32.156] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 3996191c-cce0-4e42-9f61-08d72a1e21b9 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:MN2PR11MB3776; x-ms-traffictypediagnostic: MN2PR11MB3776: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-forefront-prvs: 01415BB535 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(396003)(366004)(376002)(346002)(136003)(39860400002)(189003)(199004)(81166006)(81156014)(8676002)(1076003)(2201001)(2501003)(256004)(26005)(7736002)(99286004)(66066001)(2906002)(76176011)(52116002)(316002)(186003)(50226002)(8936002)(66476007)(66556008)(64756008)(66946007)(66446008)(110136005)(53936002)(2616005)(36756003)(25786009)(5660300002)(386003)(305945005)(6506007)(102836004)(3846002)(6116002)(446003)(11346002)(478600001)(4326008)(86362001)(6436002)(6486002)(6512007)(14454004)(71200400001)(71190400001)(107886003)(476003)(486006); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR11MB3776; H:MN2PR11MB4448.namprd11.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: microchip.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: O549OfiRIUjjwCuH3lt0MB+oeJeAC+FQqb9OWfw47Qls+a+W5ljY5PgX/bMS4LGLPuVQGbuR/5dhsaKyJpmRvZAZkFBuQPlQym9mxEt9D0yJeR3ytmHf+VaMPlxMXHglNjMICFHfLVTeEz8XQnMGmW2s7ugr4kMiExFPdol20EgjF/U8veQmTWCN95MK/G1DPuBuhXoOBquKqnUJ5rs/PR2SEqJSy1cloyQiNEIWxsU6f57vZV8gWWfggclLfZtPMB7zLECFnb23C25Ygv7jvsJaxRH7wDnGH4D/batVRYtfte2x4q3XLr83mLg/fgzVbPMTpSxXPoCREx5UrL89mMH7ZEtAktetQ/h3Ct/Vx1wRZRvOlDwZCClcU0tQ9hvHuT4vB+YHKcimXq0V2qXhXMBOraEMIozOlYqMHCTlL5A= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 3996191c-cce0-4e42-9f61-08d72a1e21b9 X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Aug 2019 12:08:40.1731 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: leMllG/GNTFP/sS8u4RehwV1KAhRBqBWI6WjDJJ5iQiVXTp5AKUDzNHHYyH7WsKguiv+wOS3v8p54eMJcqmoRfxYoq5hQDDP5zV0NwkpAD4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB3776 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190826_050842_956948_3609CB37 X-CRM114-Status: GOOD ( 11.65 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [68.232.153.233 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -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 X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tudor.Ambarus@microchip.com Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Tudor Ambarus As of now, the flash parameters initialization logic is as following: a/ default flash parameters init in spi_nor_init_params() b/ manufacturer specific flash parameters updates, split across entire spi-nor core code c/ flash parameters updates based on SFDP tables d/ post BFPT flash parameter updates In the quest of removing the manufacturer specific code from the spi-nor core, we want to impose a timeline/priority on how the flash parameters are updated. The following sequence of calls is pursued: 1/ spi-nor core parameters init based on 'flash_info' struct: spi_nor_info_init_params() which can be overwritten by: 2/ MFR-based manufacturer flash parameters init: nor->manufacturer->fixups->default_init() which can be overwritten by: 3/ specific flash_info tweeks done when decisions can not be done just on MFR: nor->info->fixups->default_init() which can be overwritten by: 4/ SFDP tables flash parameters init - SFDP knows better: spi_nor_sfdp_init_params() which can be overwritten by: 5/ post SFDP tables flash parameters updates - in case manufacturers get the serial flash tables wrong or incomplete. nor->info->fixups->post_sfdp() The later can be extended to nor->manufacturer->fixups->post_sfdp() if needed. This patch opens doors for steps 2/ and 3/. Signed-off-by: Tudor Ambarus Reviewed-by: Boris Brezillon Reviewed-by: Vignesh Raghavendra --- v3: reword description drivers/mtd/spi-nor/spi-nor.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index 9dd6cd8cd13c..8fd60e1eebd2 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -154,12 +154,16 @@ struct sfdp_bfpt { /** * struct spi_nor_fixups - SPI NOR fixup hooks + * @default_init: called after default flash parameters init. Used to tweak + * flash parameters when information provided by the flash_info + * table is incomplete or wrong. * @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 { + void (*default_init)(struct spi_nor *nor); int (*post_bfpt)(struct spi_nor *nor, const struct sfdp_parameter_header *bfpt_header, const struct sfdp_bfpt *bfpt, @@ -4133,6 +4137,17 @@ static int spi_nor_parse_sfdp(struct spi_nor *nor, return err; } +/** + * spi_nor_manufacturer_init_params() - Initialize the flash's parameters and + * settings based on ->default_init() hook. + * @nor: pointer to a 'struct spi-nor'. + */ +static void spi_nor_manufacturer_init_params(struct spi_nor *nor) +{ + if (nor->info->fixups && nor->info->fixups->default_init) + nor->info->fixups->default_init(nor); +} + static int spi_nor_init_params(struct spi_nor *nor) { struct spi_nor_flash_parameter *params = &nor->params; @@ -4233,6 +4248,8 @@ static int spi_nor_init_params(struct spi_nor *nor) params->quad_enable = info->quad_enable; } + spi_nor_manufacturer_init_params(nor); + if ((info->flags & (SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ)) && !(info->flags & SPI_NOR_SKIP_SFDP)) { struct spi_nor_flash_parameter sfdp_params; From patchwork Mon Aug 26 12:08:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tudor Ambarus X-Patchwork-Id: 1153141 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=microchip.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="sRAEGamR"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=microchiptechnology.onmicrosoft.com header.i=@microchiptechnology.onmicrosoft.com header.b="PRPkNsMG"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46H9n408Qmz9sP6 for ; Mon, 26 Aug 2019 22:10:16 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=5RxR99yX0t+KWiLse2ViBrYL1yB6OSNHya0T0JDfRTk=; b=sRAEGamRPkRqK+ 8rqS+ci7S30tSyKXIDevKGsfuUX5co7V/7MQi+uX+6Gf8tP2GoZFuZhkLI/3AX5qW0pG5xan/68w0 y5GtWYy9M6xVt7TbfJvXCu3R6QUPCuii9yq9fQwJpZlkxl/+EPAwp0IyP14n6B8YPfrtV5DD4zVbn MNqR58PLIZ8UhhYB7STntBSdqXvYjXSDOpTi74c4op+DckgTqgSfAz/nimXxvVXF6Rw4Tjwcd+N3a 9sby4V4qYwZnLoWlDtSFOStsnRm1k3oQe7rqZvkTPojHeC4OZTl3WkxIv8c0lgSf3P2rkVJe/pqTT I58y1HhhlGj1UZPMdNcg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i2Dou-0003f7-Hg; Mon, 26 Aug 2019 12:10:00 +0000 Received: from esa2.microchip.iphmx.com ([68.232.149.84]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i2Dnh-0002H5-8k for linux-mtd@lists.infradead.org; Mon, 26 Aug 2019 12:08:46 +0000 Received-SPF: Pass (esa2.microchip.iphmx.com: domain of Tudor.Ambarus@microchip.com designates 198.175.253.82 as permitted sender) identity=mailfrom; client-ip=198.175.253.82; receiver=esa2.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="Tudor.Ambarus@microchip.com"; x-conformance=spf_only; x-record-type="v=spf1"; x-record-text="v=spf1 mx a:ushub1.microchip.com a:smtpout.microchip.com a:mx1.microchip.iphmx.com a:mx2.microchip.iphmx.com include:servers.mcsv.net include:mktomail.com include:spf.protection.outlook.com ~all" Received-SPF: None (esa2.microchip.iphmx.com: no sender authenticity information available from domain of postmaster@email.microchip.com) identity=helo; client-ip=198.175.253.82; receiver=esa2.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="postmaster@email.microchip.com"; x-conformance=spf_only Authentication-Results: esa2.microchip.iphmx.com; spf=Pass smtp.mailfrom=Tudor.Ambarus@microchip.com; spf=None smtp.helo=postmaster@email.microchip.com; dkim=pass (signature verified) header.i=@microchiptechnology.onmicrosoft.com; dmarc=pass (p=none dis=none) d=microchip.com IronPort-SDR: MiJUaPtqCyqy/Bgci7pOFSQRa4ycFmBJM+ro+AE4QjLAT2nE7gWggpecmP9cBiFSjkRrje2WOS HW8B27hFkpayYNgKdCbz3zji9OuDK8TfkN+gvLqs0VXyEt9i1Ek3hsUdZB3R91QG0RyNrcIHL9 zx/TXx+YuersvV2WzDYTMzEnj+QwZsCo21yCsnhRmb91F7b+Ytl93ca4xDMbg/JmwyUTt5r0pI 6nZKi1+CqhIGpRpk//Njbh/BTWaaVuH7gKSjKkrez2AeL3n7fKXSiAcWvvSPI2DpqhoQiIE9IE v+M= X-IronPort-AV: E=Sophos;i="5.64,433,1559545200"; d="scan'208";a="46520711" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 26 Aug 2019 05:08:43 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.87.72) by chn-vm-ex02.mchp-main.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 26 Aug 2019 05:08:42 -0700 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Mon, 26 Aug 2019 05:08:42 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PYa9Q7gdVqJBWIKYVxRea269WF2bO7WyCE9SkLBFdhTG7m1JvNqYB+0SOdEBHcAR/8Y/00tHYinzAP1sar7QejyqEZV6DyryMdT+DZN1IllbCUJCKz5z8mf05my5/pFNnAAB7dAfezQxZD5r2dfvWZhxMu5eFHar3j2tdM2j5Wd5auXFKufIxG4YnvwEoScbk02RxuvWCtAnu6hE1oqqFfeIFFlaFbAAzy9XIGDuAoo8U8N4AtmRPwDzcXzw7jgCSohp0Wnn1863Vw1fFLjpe9uj1D4lFClnDFykvl4nZpS+Z37b74ktNIYm/kaP5oAJz/InyDKw524QVRYlx6lozg== 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=31wWWhbWl8hBRHBnpLkx7R3DQXQ7fzcZ+VuDBHkNBEQ=; b=PClOvmhUoazt1LEVSF5zff+id8AxsZtRg/t+FEywJqPzT+2J5S4R0fJGCtyQwDCEl76hqEudcPcJwCdRNeMSsJMX/bwuJlxcjLoYsRFtBIyDJtH85k8AIqw8lA35rE0cxM/RucZ/DlNat4niq/55JwvHtLaxgWprgq2r7UutbLbrMLIfbxTH0NnRZKK2klnnsWcWkgsVWiAtD5KOg9czF/wnj4rQbKqjWHBiHz0gKCuRe0r5sTEDqAit5FmPMByTmqmIZ9jaXmdNeejG+XU/H+l9GVIkRy/JLp4wsrDr1pwkYLMsq9+XtNUDho8Cv+djgVzo3XoCEcwkqVHRiRBQDw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microchip.com; dmarc=pass action=none header.from=microchip.com; dkim=pass header.d=microchip.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microchiptechnology.onmicrosoft.com; s=selector2-microchiptechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=31wWWhbWl8hBRHBnpLkx7R3DQXQ7fzcZ+VuDBHkNBEQ=; b=PRPkNsMG0881HCLl78I/vjbRotxoAxLyNFPBqRbFM+VniFJa53Xzjjxs+/2VMSw2ocwioTOowyqOgOkBXllvU0N92pm9BwFaP5uZwCiL/QSE4UkV1lIiOUDF4TP3MO2O+wXikXTeM7UstezrrdQ+w2B3KVgVgHSYQwj6I7fedU8= Received: from MN2PR11MB4448.namprd11.prod.outlook.com (52.135.39.157) by MN2PR11MB3776.namprd11.prod.outlook.com (20.178.251.156) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.21; Mon, 26 Aug 2019 12:08:42 +0000 Received: from MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5]) by MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5%7]) with mapi id 15.20.2199.021; Mon, 26 Aug 2019 12:08:42 +0000 From: To: , , , , , , Subject: [RESEND PATCH v3 06/20] mtd: spi-nor: Add a default_init() fixup hook for gd25q256 Thread-Topic: [RESEND PATCH v3 06/20] mtd: spi-nor: Add a default_init() fixup hook for gd25q256 Thread-Index: AQHVXAcAicnY5H8dpUCDa+wa3xawzQ== Date: Mon, 26 Aug 2019 12:08:42 +0000 Message-ID: <20190826120821.16351-7-tudor.ambarus@microchip.com> References: <20190826120821.16351-1-tudor.ambarus@microchip.com> In-Reply-To: <20190826120821.16351-1-tudor.ambarus@microchip.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1PR09CA0046.eurprd09.prod.outlook.com (2603:10a6:802:28::14) To MN2PR11MB4448.namprd11.prod.outlook.com (2603:10b6:208:193::29) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.9.5 x-originating-ip: [94.177.32.156] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 118c30ca-ab4b-4b46-daee-08d72a1e22fb x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:MN2PR11MB3776; x-ms-traffictypediagnostic: MN2PR11MB3776: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-forefront-prvs: 01415BB535 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(396003)(366004)(376002)(346002)(136003)(39860400002)(189003)(199004)(81166006)(81156014)(8676002)(1076003)(2201001)(2501003)(14444005)(256004)(26005)(7736002)(99286004)(66066001)(2906002)(54906003)(76176011)(52116002)(316002)(186003)(50226002)(8936002)(66476007)(66556008)(64756008)(66946007)(66446008)(110136005)(53936002)(2616005)(36756003)(25786009)(5660300002)(386003)(305945005)(6506007)(102836004)(3846002)(6116002)(446003)(11346002)(478600001)(4326008)(86362001)(6436002)(6486002)(6512007)(14454004)(71200400001)(71190400001)(107886003)(476003)(486006)(138113003); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR11MB3776; H:MN2PR11MB4448.namprd11.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: microchip.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: bADtocYw8siqpkOtqgQUXExk165xzwBpGAcwLulkEfhgnKp9brNCGxj078f2mJSXLrMfmrI9rYV7HDOWluQRaZmYuwckHpxD2y6pU0gSrA7s3xD98HGft2H0G9ttu5ANvJJzd52N73sPyGCvGciDMRQun8/qxUUDCLRDUhhibSgKVjNw6APPRQDhjZe2Zg/ThrWDhqnoGVCXsBKzOzZ5Uy7G2S/jNJQDQ9UpylFqMATaVqItpLEemZIXBnWHmVzHKkCxlfEXokRfxe7IJ9P6oXeAlgkhpuG9hBR8sdxpgAP/dbRDcqU1kegv6oYX8Q0W68KkWwOuaBlkQ+pNx/d2g6qB8lhAwBxPWl/o0Io0cF83RvnSzEBc1hSpsZixhLRWlCdNqArH8vmtnrejYLbpcJBYFrEkIRLGE5gSOBlDh18= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 118c30ca-ab4b-4b46-daee-08d72a1e22fb X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Aug 2019 12:08:42.3219 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 3vAQ6Hx1XnTm+IZ+mYyeQCFEKR0qnCdMSq200B6ph7Y8c6dMVzxAebFVHH/8u9PYdczNJ6TEuM645nn+jchYqJA7TYFvMuf3UU0ZBCCmBTU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB3776 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190826_050845_357132_A43057A9 X-CRM114-Status: GOOD ( 12.56 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [68.232.149.84 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -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 X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: boris.brezillon@bootlin.com, Tudor.Ambarus@microchip.com Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Boris Brezillon gd25q256 needs to tweak the ->quad_enable() implementation and the ->default_init() fixup hook is the perfect place to do that. This way, if we ever need to tweak more things for this flash, we won't have to add new fields in flash_info. We can get rid of the flash_info->quad_enable field as gd25q256 was the only user. Signed-off-by: Boris Brezillon [tudor.ambarus@microchip.com: use ->default_init() hook instead of ->post_sfdp()] Signed-off-by: Tudor Ambarus Reviewed-by: Vignesh Raghavendra --- v3: no changes drivers/mtd/spi-nor/spi-nor.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index 8fd60e1eebd2..3dbbfe34d1d2 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -222,8 +222,6 @@ struct flash_info { /* Part specific fixup hooks. */ const struct spi_nor_fixups *fixups; - - int (*quad_enable)(struct spi_nor *nor); }; #define JEDEC_MFR(info) ((info)->id[0]) @@ -2126,6 +2124,21 @@ static struct spi_nor_fixups mx25l25635_fixups = { .post_bfpt = mx25l25635_post_bfpt_fixups, }; +static void gd25q256_default_init(struct spi_nor *nor) +{ + /* + * Some manufacturer like GigaDevice may use different + * bit to set QE on different memories, so the MFR can't + * indicate the quad_enable method for this case, we need + * to set it in the default_init fixup hook. + */ + nor->params.quad_enable = macronix_quad_enable; +} + +static struct spi_nor_fixups gd25q256_fixups = { + .default_init = gd25q256_default_init, +}; + /* NOTE: double check command sets and memory organization when you add * more nor chips. This current list focusses on newer chips, which * have been converging on command sets which including JEDEC ID. @@ -2218,7 +2231,7 @@ static const struct flash_info spi_nor_ids[] = { "gd25q256", INFO(0xc84019, 0, 64 * 1024, 512, SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES | SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB) - .quad_enable = macronix_quad_enable, + .fixups = &gd25q256_fixups, }, /* Intel/Numonyx -- xxxs33b */ @@ -4237,15 +4250,6 @@ static int spi_nor_init_params(struct spi_nor *nor) params->quad_enable = spansion_quad_enable; break; } - - /* - * Some manufacturer like GigaDevice may use different - * bit to set QE on different memories, so the MFR can't - * indicate the quad_enable method for this case, we need - * set it in flash info list. - */ - if (info->quad_enable) - params->quad_enable = info->quad_enable; } spi_nor_manufacturer_init_params(nor); From patchwork Mon Aug 26 12:08:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tudor Ambarus X-Patchwork-Id: 1153142 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=microchip.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="jPaSjedh"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=microchiptechnology.onmicrosoft.com header.i=@microchiptechnology.onmicrosoft.com header.b="I5XP+L2L"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46H9nT5tc5z9sDB for ; Mon, 26 Aug 2019 22:10:37 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=zU8K0S6SWsoZzZC/7eB/0lT/ihiD3QlCZ0C5GtrrfQ8=; b=jPaSjedhWp33NY Xbj0sGX6Qbk4YlyKclwNAIP8f92BZQ7Xq4WlptydWGLHJVI9pKEg2tPOhyedp3fBNrYk7XR+kqe2V ZQ3HBkXHslkoJvcSLjzTFI3m5ICXAdAit6hAt567x3sw59wrkWYcqj7yu9Zccy+WTGrUFK+Cyrkyx Zo3yduixdNJClyANVM/FnzBMUBzn8Cs7N/2qfkSBbd5L/QijZ21udPo9IcCQYJt+LsFo0qlAGevnD KUMF3d7KFP13gcQkFeRroAk5LWWVNvYGwKzYk2FJHKBgqAP9bQsjMXoLBPlvnY7vM0Nn+Qw0+7Hpf n8fZj4jOjThGC+ahxxrw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i2DpH-0005Bf-1b; Mon, 26 Aug 2019 12:10:23 +0000 Received: from esa3.microchip.iphmx.com ([68.232.153.233]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i2Dnz-0002cI-UD for linux-mtd@lists.infradead.org; Mon, 26 Aug 2019 12:09:05 +0000 Received-SPF: Pass (esa3.microchip.iphmx.com: domain of Tudor.Ambarus@microchip.com designates 198.175.253.82 as permitted sender) identity=mailfrom; client-ip=198.175.253.82; receiver=esa3.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="Tudor.Ambarus@microchip.com"; x-conformance=spf_only; x-record-type="v=spf1"; x-record-text="v=spf1 mx a:ushub1.microchip.com a:smtpout.microchip.com a:mx1.microchip.iphmx.com a:mx2.microchip.iphmx.com include:servers.mcsv.net include:mktomail.com include:spf.protection.outlook.com ~all" Received-SPF: None (esa3.microchip.iphmx.com: no sender authenticity information available from domain of postmaster@email.microchip.com) identity=helo; client-ip=198.175.253.82; receiver=esa3.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="postmaster@email.microchip.com"; x-conformance=spf_only Authentication-Results: esa3.microchip.iphmx.com; spf=Pass smtp.mailfrom=Tudor.Ambarus@microchip.com; spf=None smtp.helo=postmaster@email.microchip.com; dkim=pass (signature verified) header.i=@microchiptechnology.onmicrosoft.com; dmarc=pass (p=none dis=none) d=microchip.com IronPort-SDR: 1b23bYCo8oMGMPquIrYjlUvJ0y66Gm7Nf39v6h8iwVXzU2PTUysGsDX3zMuG8CUAu2KCtEf2zr 7KZZzmQAeTaBgeRNvwVBi1Mjce6EuKTSbzB3doge2W5dtts0f/4Bv7lUiG9PW2mB0bkqw42K59 K7iJJ0w4Q4uEzq6smrhWdpDiH1lSVgLqWtnobrqolJy40f77AqzGIhnbOlRrM1Rbgpg+SR2ZYB eVSLYJ8j4+FQvugJmQilEkbAwsKaCOFuWqjxJ+hDDmtO/jOfc1mpKwcB47jDCJRzBP95LWGnwE u4k= X-IronPort-AV: E=Sophos;i="5.64,433,1559545200"; d="scan'208";a="46588846" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa3.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 26 Aug 2019 05:09:02 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 26 Aug 2019 05:09:01 -0700 Received: from NAM02-BL2-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.87.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Mon, 26 Aug 2019 05:09:02 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=X4alxsK2hZI2VGE18wsQPBn1jUG1Jwc6DB6+OpacNGaxmMLnMdcgm76BpoVohn0Flg3Lpef5m3fHRMw1wl+iriXuYN39ijVrgAlIljdMXG7hjd4ugnoVncS4yslYLm4xbnS/QrvveDjISIaZEYAtyuaYRPzqMMlbrUqiLmSoUmUxZQ/AgWGL5vbEUCyvhU2P7L39CkvIX1Ie5e6B6lBKXdyE1nYdzjMeuBrNRQUQUZL9oCJ7jWR64Ts6xXLxtdVvba4dG0M8MoPdQhcFFQrPH2mo1V5kv+d1uB/PCVkXRKYM6OoZYqx5AEtQi0D+OiDSpEFd0/LE1Sd9aQEXmPoEvg== 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=bpDlfTaWESJytOMjMrbaec6vmrndTL8P/WfJRbmZdk8=; b=VzCUudM8T2iYsZJfwiYmyFymULzrmzgRx0GB08esxryxhijHC9BKzML4OUpCEdoYLJ54xiJAKKdAL+4WueUFZTtzeYHh/4igK4JLh+N3gpy+T9h0rFQVKYRXM9zSjiXAQnFH6mLevNfKtR1ihf0HiYkxFWHPUHrkYkC0S0biHL6G/52PY2OED8Mp47PDvxcTUAKrCiNH0nhOPdVqgkVJyRzrqkeAbOJvxaAdHIiWLRJqSKXoYhFVA5mFH8bKmB+JjSTtGpg7x1ImWeGSkxTLagGUue2OWEEPfiq+DMApL1VYyuXQgdkp6GDhzW4QYrQOPb22Cj2bpVHyzP3b3aAqMg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microchip.com; dmarc=pass action=none header.from=microchip.com; dkim=pass header.d=microchip.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microchiptechnology.onmicrosoft.com; s=selector2-microchiptechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bpDlfTaWESJytOMjMrbaec6vmrndTL8P/WfJRbmZdk8=; b=I5XP+L2LS1cLvyEjl1YteLoGaJYKJLd5ddvvtncwXXca2duvBxqwzPLBK0eyfvKYAn/JUP7H0WAPwAeq32wfWTEd/w+g2vs60lmQ02cg2OPdE/9ZFxbHULoLZQadcvenna2oiYSBrojIoSMmpG1DxikkLJxWdL9BkquI7mPJSqE= Received: from MN2PR11MB4448.namprd11.prod.outlook.com (52.135.39.157) by MN2PR11MB3678.namprd11.prod.outlook.com (20.178.252.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.21; Mon, 26 Aug 2019 12:08:44 +0000 Received: from MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5]) by MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5%7]) with mapi id 15.20.2199.021; Mon, 26 Aug 2019 12:08:44 +0000 From: To: , , , , , , Subject: [RESEND PATCH v3 07/20] mtd: spi_nor: Move manufacturer quad_enable() in ->default_init() Thread-Topic: [RESEND PATCH v3 07/20] mtd: spi_nor: Move manufacturer quad_enable() in ->default_init() Thread-Index: AQHVXAcBVqSDVjwU4UmVniY3zigyJA== Date: Mon, 26 Aug 2019 12:08:44 +0000 Message-ID: <20190826120821.16351-8-tudor.ambarus@microchip.com> References: <20190826120821.16351-1-tudor.ambarus@microchip.com> In-Reply-To: <20190826120821.16351-1-tudor.ambarus@microchip.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1PR09CA0046.eurprd09.prod.outlook.com (2603:10a6:802:28::14) To MN2PR11MB4448.namprd11.prod.outlook.com (2603:10b6:208:193::29) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.9.5 x-originating-ip: [94.177.32.156] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: fbd3d739-872a-4f40-fecb-08d72a1e241c x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:MN2PR11MB3678; x-ms-traffictypediagnostic: MN2PR11MB3678: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:5516; x-forefront-prvs: 01415BB535 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(136003)(39860400002)(346002)(366004)(396003)(376002)(199004)(189003)(486006)(2616005)(476003)(107886003)(316002)(14454004)(386003)(6506007)(76176011)(99286004)(52116002)(110136005)(478600001)(102836004)(4326008)(25786009)(36756003)(446003)(26005)(11346002)(50226002)(81156014)(66066001)(8676002)(53936002)(81166006)(8936002)(6512007)(6486002)(6436002)(3846002)(6116002)(186003)(86362001)(305945005)(2201001)(7736002)(2906002)(64756008)(66446008)(1076003)(71190400001)(5660300002)(71200400001)(256004)(66946007)(66556008)(66476007)(2501003); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR11MB3678; H:MN2PR11MB4448.namprd11.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: microchip.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: k9l89VAsgiq5Qy72JkMqb5wEzYejy7L551v7+2Vyt7IOy9MhLfHrZqs98nr4dL+LRXTx/J0XO19SIZKousqiV95o1B+gYwqRQBuIuMeeORGex+6H1jvU3n5QPxkU/2UWoIMS69Xk1klL03rCOdlgFQW2fBKxKYdUHARne1tWGkfevCQlCuusnVfASbB0ErJY+cOCU9ZyLxb3IZwFB47AhHBV5fPfGmmjX0khWuUJFUuXkX5rTIu791RE4tYzMYitqohjnSkm3TGv2NapMz1y6Q/fbuvRyiOGStcPwoWxzbusfntQ+JCWqF6yohWeMPd4c77q9nsIIsGBwMXl+psltJTHKgWyT6GKHYtL/T6jNiv1XKAm0wDcYFtVz4cPlpdj6ov7YEKYEtDwmOEvVuUdiEocy3UtYwznHbHArzzDjE4= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: fbd3d739-872a-4f40-fecb-08d72a1e241c X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Aug 2019 12:08:44.1718 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: ylhXu8uYq7o/Te42U9obuANzZaRpGq+yMvE8nfw2XyGDZp1yerIXXWOe4+eYgDP7u0Fei5JkOIjOGxeyDJ9M84wA3mEZtOiAJljNk5lwUQY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB3678 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190826_050904_124009_FCEBF704 X-CRM114-Status: UNSURE ( 9.49 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [68.232.153.233 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -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 X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tudor.Ambarus@microchip.com Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Tudor Ambarus The goal is to move the quad_enable manufacturer specific init in the nor->manufacturer->fixups->default_init() The legacy quad_enable() implementation is spansion_quad_enable(), select this method by default. Set specific manufacturer fixups->default_init() hooks to overwrite the default quad_enable() implementation when needed. Signed-off-by: Tudor Ambarus Reviewed-by: Boris Brezillon Reviewed-by: Vignesh Raghavendra --- v3: collect R-b drivers/mtd/spi-nor/spi-nor.c | 48 ++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index 3dbbfe34d1d2..2a239531704a 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -4150,13 +4150,38 @@ static int spi_nor_parse_sfdp(struct spi_nor *nor, return err; } +static void macronix_set_default_init(struct spi_nor *nor) +{ + nor->params.quad_enable = macronix_quad_enable; +} + +static void st_micron_set_default_init(struct spi_nor *nor) +{ + nor->params.quad_enable = NULL; +} + /** * spi_nor_manufacturer_init_params() - Initialize the flash's parameters and - * settings based on ->default_init() hook. + * settings based on MFR register and ->default_init() hook. * @nor: pointer to a 'struct spi-nor'. */ static void spi_nor_manufacturer_init_params(struct spi_nor *nor) { + /* Init flash parameters based on MFR */ + switch (JEDEC_MFR(nor->info)) { + case SNOR_MFR_MACRONIX: + macronix_set_default_init(nor); + break; + + case SNOR_MFR_ST: + case SNOR_MFR_MICRON: + st_micron_set_default_init(nor); + break; + + default: + break; + } + if (nor->info->fixups && nor->info->fixups->default_init) nor->info->fixups->default_init(nor); } @@ -4168,6 +4193,9 @@ static int spi_nor_init_params(struct spi_nor *nor) const struct flash_info *info = nor->info; u8 i, erase_mask; + /* Initialize legacy flash parameters and settings. */ + params->quad_enable = spansion_quad_enable; + /* Set SPI NOR sizes. */ params->size = (u64)info->sector_size * info->n_sectors; params->page_size = info->page_size; @@ -4233,24 +4261,6 @@ static int spi_nor_init_params(struct spi_nor *nor) SPINOR_OP_SE); spi_nor_init_uniform_erase_map(map, erase_mask, params->size); - /* Select the procedure to set the Quad Enable bit. */ - if (params->hwcaps.mask & (SNOR_HWCAPS_READ_QUAD | - SNOR_HWCAPS_PP_QUAD)) { - switch (JEDEC_MFR(info)) { - case SNOR_MFR_MACRONIX: - params->quad_enable = macronix_quad_enable; - break; - - case SNOR_MFR_ST: - case SNOR_MFR_MICRON: - break; - - default: - /* Kept only for backward compatibility purpose. */ - params->quad_enable = spansion_quad_enable; - break; - } - } spi_nor_manufacturer_init_params(nor); From patchwork Mon Aug 26 12:08:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tudor Ambarus X-Patchwork-Id: 1153144 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=microchip.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="HmUHgi9e"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=microchiptechnology.onmicrosoft.com header.i=@microchiptechnology.onmicrosoft.com header.b="q1aRHd0e"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46H9nj4V6yz9sMr for ; Mon, 26 Aug 2019 22:10:49 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9jqzsUxJor9ZI5eksno3ug1nX9qoGsV3y5hZ23j9qj0=; b=HmUHgi9e0v/hZI 8BzQHj06yw9ywOR+zlUKkShxAapXiMBzeR/+bFLfr/RYLiHMzA5myaJtgn18+j0OACrrQParooIwz nn+aE8FNIr+ORAlEkakdwho4zyZsfCyoXmxh26naHOdjMcAKWRkM0yCCY6BBkISG2D2j7yJ3994vt 8e0XXAkiOZhsk67u3brQtlxPDLdKvr1GJUArbnViEi6eTWMNvLTHhtr/OFswpJsjyPudv4gwXbQwj AmczMSL1RAn7+dFSxBqKMkAqDNpc6gWgeUnijToyOicc5QPVlsU4EeBMp/uAfiFTw7iy+mCwCSoLM lNDsOm4QJfJlj2J0wjeg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i2DpS-0005Pv-Uq; Mon, 26 Aug 2019 12:10:34 +0000 Received: from esa3.microchip.iphmx.com ([68.232.153.233]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i2Do1-0002cI-VF for linux-mtd@lists.infradead.org; Mon, 26 Aug 2019 12:09:07 +0000 Received-SPF: Pass (esa3.microchip.iphmx.com: domain of Tudor.Ambarus@microchip.com designates 198.175.253.82 as permitted sender) identity=mailfrom; client-ip=198.175.253.82; receiver=esa3.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="Tudor.Ambarus@microchip.com"; x-conformance=spf_only; x-record-type="v=spf1"; x-record-text="v=spf1 mx a:ushub1.microchip.com a:smtpout.microchip.com a:mx1.microchip.iphmx.com a:mx2.microchip.iphmx.com include:servers.mcsv.net include:mktomail.com include:spf.protection.outlook.com ~all" Received-SPF: None (esa3.microchip.iphmx.com: no sender authenticity information available from domain of postmaster@email.microchip.com) identity=helo; client-ip=198.175.253.82; receiver=esa3.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="postmaster@email.microchip.com"; x-conformance=spf_only Authentication-Results: esa3.microchip.iphmx.com; spf=Pass smtp.mailfrom=Tudor.Ambarus@microchip.com; spf=None smtp.helo=postmaster@email.microchip.com; dkim=pass (signature verified) header.i=@microchiptechnology.onmicrosoft.com; dmarc=pass (p=none dis=none) d=microchip.com IronPort-SDR: Iarav34xptW4JFpQenE3EXwJt2WwPZkVK5YJ4Qa4G0lH81gie1s25wcCML6zca2bCRr73htLQF h2cQn+12kJgjpIe6fRM6SwULvdGL/hOF2gLI5GhfeJGRbFcVzXh5A3L/lTc4BAmY0l054wzeO4 mlu/pF5VRxg+uek0V2fF7Oux6MtYCVVrnwHetiV7hBwLzxr5W6EgEVRfxJ8otpPrdxJlwRSPic pyTkZPbGIa98JhdZyqC9c9aqTMGaFyN9R/DVRyT3j9uarQPN6Slz1+vcxWZyR6dLTfet+fYpdn az0= X-IronPort-AV: E=Sophos;i="5.64,433,1559545200"; d="scan'208";a="46588849" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa3.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 26 Aug 2019 05:09:02 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 26 Aug 2019 05:09:02 -0700 Received: from NAM02-BL2-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.87.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Mon, 26 Aug 2019 05:09:02 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B66UkkE5HO9+DlWMM5dVK//PdN9Z8S8iGi85eC2YqcQ7hm5HElGEEsdq9Bmt9zrD6bI821jgEkavi2yzSdkb4C4SYGD5/VqlXcURJ+bp/1GOcjimrOQqug9nU8Jw1OFfsihC40UfKsTohNPFjsMYut/7IROX77e6d+GjzQmmvAwDsDMu4eikutktr2xA7XmeT7RCEGFgh+mw5GcFJylFkA1kYRpmpiY9T3UUFgGpFQxQ5CKta3rk+NQ+wKjwYCAtIg61Jm/QhiUUge3Jesj64SLhsaFU0q6ncdvBWszNl8jp6b1A8dF6/oB9AXdJmTGSXfh7f8PKpD6+b/jPyxEp7A== 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=mr6WprtHHL/51al8o4FDNLNd4upljb84M2qM0FgfKmY=; b=W2j+6WDHO3e22V4XGXCSSXA7zcyxZaQwwFwv+Wh1c9XRglKqU9Z+htU2T7wvaPGRIviM75iJPeUBdhMaAJClENTzsoXW+cnk9Yd/bq2M4bHZJBRwc+QhVaskX9tcHzvxj8T63Xdd2O3VnNe3EjamlwAeczlWkB1nFilQmwVSR1RJjEUtdV9bEdTxgT3pynznCq3WTmp9k20Bs2iLncBsDOqSQqNB0s4wHzKyTRQUih6T0S21Hmv2Ao+PAiNjNwv44WPCMV0LNEtZyxYRfbSH1iu6s3VN8IA9uSIE9d6W2wLPN3PM/Xt2WyjX1fnMopb0qmoJ0s9g0HKBZpjD6NV5Cw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microchip.com; dmarc=pass action=none header.from=microchip.com; dkim=pass header.d=microchip.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microchiptechnology.onmicrosoft.com; s=selector2-microchiptechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mr6WprtHHL/51al8o4FDNLNd4upljb84M2qM0FgfKmY=; b=q1aRHd0eZFs+5WNF4R0bAb6U9DtZBIXufmcDDbbFCb9MP0rC58Roa/+t+Te/WkNh2mvmWDjKOlJqOnSp6rJb0/lu2ST6IsVDjb3JImYqo9/4BsBEuUb7UyajrHwkR/Xa2196FPpGReelP6WB7BS6nJlawDNMu8vBqatWbE/kmbI= Received: from MN2PR11MB4448.namprd11.prod.outlook.com (52.135.39.157) by MN2PR11MB3678.namprd11.prod.outlook.com (20.178.252.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.21; Mon, 26 Aug 2019 12:08:53 +0000 Received: from MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5]) by MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5%7]) with mapi id 15.20.2199.021; Mon, 26 Aug 2019 12:08:53 +0000 From: To: , , , , , , Subject: [RESEND PATCH v3 08/20] mtd: spi-nor: Split spi_nor_init_params() Thread-Topic: [RESEND PATCH v3 08/20] mtd: spi-nor: Split spi_nor_init_params() Thread-Index: AQHVXAcDwaG7sE2Oh0OnT95bpkTmoQ== Date: Mon, 26 Aug 2019 12:08:46 +0000 Message-ID: <20190826120821.16351-9-tudor.ambarus@microchip.com> References: <20190826120821.16351-1-tudor.ambarus@microchip.com> In-Reply-To: <20190826120821.16351-1-tudor.ambarus@microchip.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1PR09CA0046.eurprd09.prod.outlook.com (2603:10a6:802:28::14) To MN2PR11MB4448.namprd11.prod.outlook.com (2603:10b6:208:193::29) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.9.5 x-originating-ip: [94.177.32.156] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: d57e02a6-458e-45c2-05d2-08d72a1e2565 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:MN2PR11MB3678; x-ms-traffictypediagnostic: MN2PR11MB3678: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:7219; x-forefront-prvs: 01415BB535 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(136003)(39860400002)(346002)(366004)(396003)(376002)(199004)(189003)(486006)(2616005)(476003)(6666004)(107886003)(316002)(14454004)(386003)(6506007)(76176011)(99286004)(52116002)(110136005)(478600001)(102836004)(4326008)(25786009)(36756003)(446003)(26005)(11346002)(50226002)(81156014)(66066001)(8676002)(53936002)(81166006)(8936002)(6512007)(6486002)(6436002)(3846002)(6116002)(186003)(86362001)(305945005)(2201001)(7736002)(2906002)(64756008)(66446008)(1076003)(71190400001)(5660300002)(71200400001)(256004)(14444005)(66946007)(66556008)(66476007)(2501003); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR11MB3678; H:MN2PR11MB4448.namprd11.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: microchip.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: rY5PNLCWeJcOFhF6su8Y3lT1tEQv9I/7IE9pd77o7DTdWFZyITSN1GXVfKUEli+aGJwfR25Oip1HBKWNJ1nnOCd+gI8fV/g9ELpAW7cctpYulzW1nGiEgQJ+QPGJonolGrd1cRkbgZ4eM1cQJJNgcg2OSXd+3C2CIe2ZotQJ51z/GRwudkcR5PITEehLuWPrv7fJybEu3iqNfmRwwSWQQmLlL03LzP/i4bYvKA3b2fBV9eAbxeYTZqV0U/4oDj7+HRP7Qq2ueWT3FWrpZSy7dqPawos1qhMr1sidt4qyPmV7kG/9jDKFgiC66Zi9NxLinMNPRlNWmUDRifDXpOvlNUGMGv34+by9l6PvOcAy9XxU7/uL3XQQK/Ajm0opDNrWPrnMM7eon8GEOA7eNT8N4Np87y/WFRhjSA/Kfr2nUrY= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: d57e02a6-458e-45c2-05d2-08d72a1e2565 X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Aug 2019 12:08:46.3276 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 1eMVKl6tXZsE7+5Mdfx+MHk9t9EJFdFNGRkgHrS8+fM5z9+ibav7nFtgTP9/Z5Hpr3o4F7NQ0jvrkZOLvmnaB8qZjWvrjHCqKQezaUf5kik= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB3678 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190826_050906_136298_AA02E515 X-CRM114-Status: GOOD ( 11.86 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [68.232.153.233 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -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 X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tudor.Ambarus@microchip.com Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Tudor Ambarus Add functions to delimit what the chunks of code do: static void spi_nor_init_params() { spi_nor_info_init_params() spi_nor_manufacturer_init_params() spi_nor_sfdp_init_params() } Add descriptions to all methods. spi_nor_init_params() becomes of type void, as all its children return void. Signed-off-by: Tudor Ambarus Reviewed-by: Boris Brezillon Reviewed-by: Vignesh Raghavendra --- v3: rename spi_nor_legacy_init_params() to spi_nor_info_init_params() drivers/mtd/spi-nor/spi-nor.c | 83 ++++++++++++++++++++++++++++++++----------- 1 file changed, 63 insertions(+), 20 deletions(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index 2a239531704a..1e7f8dc3457d 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -4186,7 +4186,34 @@ static void spi_nor_manufacturer_init_params(struct spi_nor *nor) nor->info->fixups->default_init(nor); } -static int spi_nor_init_params(struct spi_nor *nor) +/** + * spi_nor_sfdp_init_params() - Initialize the flash's parameters and settings + * based on JESD216 SFDP standard. + * @nor: pointer to a 'struct spi-nor'. + * + * The method has a roll-back mechanism: in case the SFDP parsing fails, the + * legacy flash parameters and settings will be restored. + */ +static void spi_nor_sfdp_init_params(struct spi_nor *nor) +{ + struct spi_nor_flash_parameter sfdp_params; + + memcpy(&sfdp_params, &nor->params, sizeof(sfdp_params)); + + if (spi_nor_parse_sfdp(nor, &sfdp_params)) { + nor->addr_width = 0; + nor->flags &= ~SNOR_F_4B_OPCODES; + } else { + memcpy(&nor->params, &sfdp_params, sizeof(nor->params)); + } +} + +/** + * spi_nor_info_init_params() - Initialize the flash's parameters and settings + * based on nor->info data. + * @nor: pointer to a 'struct spi-nor'. + */ +static void spi_nor_info_init_params(struct spi_nor *nor) { struct spi_nor_flash_parameter *params = &nor->params; struct spi_nor_erase_map *map = ¶ms->erase_map; @@ -4260,25 +4287,43 @@ static int spi_nor_init_params(struct spi_nor *nor) spi_nor_set_erase_type(&map->erase_type[i], info->sector_size, SPINOR_OP_SE); spi_nor_init_uniform_erase_map(map, erase_mask, params->size); +} +/** + * spi_nor_init_params() - Initialize the flash's parameters and settings. + * @nor: pointer to a 'struct spi-nor'. + * + * The flash parameters and settings are initialized based on a sequence of + * calls that are ordered by priority: + * + * 1/ Default flash parameters initialization. The initializations are done + * based on nor->info data: + * spi_nor_info_init_params() + * + * which can be overwritten by: + * 2/ Manufacturer flash parameters initialization. The initializations are + * done based on MFR register, or when the decisions can not be done solely + * based on MFR, by using specific flash_info tweeks, ->default_init(): + * spi_nor_manufacturer_init_params() + * + * which can be overwritten by: + * 3/ SFDP flash parameters initialization. JESD216 SFDP is a standard and + * should be more accurate that the above. + * spi_nor_sfdp_init_params() + * + * Please not that there is a ->post_bfpt() fixup hook that can overwrite the + * flash parameters and settings imediately after parsing the Basic Flash + * Parameter Table. + */ +static void spi_nor_init_params(struct spi_nor *nor) +{ + spi_nor_info_init_params(nor); spi_nor_manufacturer_init_params(nor); - if ((info->flags & (SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ)) && - !(info->flags & SPI_NOR_SKIP_SFDP)) { - struct spi_nor_flash_parameter sfdp_params; - - memcpy(&sfdp_params, params, sizeof(sfdp_params)); - - if (spi_nor_parse_sfdp(nor, &sfdp_params)) { - nor->addr_width = 0; - nor->flags &= ~SNOR_F_4B_OPCODES; - } else { - memcpy(params, &sfdp_params, sizeof(*params)); - } - } - - return 0; + if ((nor->info->flags & (SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ)) && + !(nor->info->flags & SPI_NOR_SKIP_SFDP)) + spi_nor_sfdp_init_params(nor); } static int spi_nor_select_read(struct spi_nor *nor, @@ -4670,10 +4715,8 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, nor->info->flags & SPI_NOR_HAS_LOCK) nor->clear_sr_bp = spi_nor_clear_sr_bp; - /* Parse the Serial Flash Discoverable Parameters table. */ - ret = spi_nor_init_params(nor); - if (ret) - return ret; + /* Init flash parameters based on flash_info struct and SFDP */ + spi_nor_init_params(nor); if (!mtd->name) mtd->name = dev_name(dev); From patchwork Mon Aug 26 12:08:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tudor Ambarus X-Patchwork-Id: 1153143 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=microchip.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="q68NjXQ4"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=microchiptechnology.onmicrosoft.com header.i=@microchiptechnology.onmicrosoft.com header.b="b2cUU8Qm"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46H9nh3NX4z9sDB for ; Mon, 26 Aug 2019 22:10:48 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=MP+0KzvYJE4pgGZjq5Ou804B/6vhm+m8jh/G39CvnqA=; b=q68NjXQ4zUN2fP yjYHdHKBXDtlyu3yMXn6aGmoIHKeTP5qjWHplZj+5f+SNpisOyyyzKIYrbWY7/3DyKdVgxrZl05H6 1dY487+bIBHnVftDU9IoDnlvsTKzSXxv/W6pASrh5yBoyUZML7BGEH6hAK/eNCFG8qX2Wrz065J5t D1ykHTeKAJg/tR+neHhqDaVI7BzR7Vdp2P3ihOggEA0iZ8wL1IsXzWsc0ezZp8axuqF3N5pIwp0+V OJYIfz3fz7KpukI+eFnw9mo7AA17EbtLtDm77ZM2oXgjCR1K2stdskNZNXJE0Xhtm2gQum3ZT8ofD O5tr3MZCeIGH7E99UM7w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i2Dpd-0005fJ-5p; Mon, 26 Aug 2019 12:10:45 +0000 Received: from esa2.microchip.iphmx.com ([68.232.149.84]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i2Do2-0002er-29 for linux-mtd@lists.infradead.org; Mon, 26 Aug 2019 12:09:09 +0000 Received-SPF: Pass (esa2.microchip.iphmx.com: domain of Tudor.Ambarus@microchip.com designates 198.175.253.82 as permitted sender) identity=mailfrom; client-ip=198.175.253.82; receiver=esa2.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="Tudor.Ambarus@microchip.com"; x-conformance=spf_only; x-record-type="v=spf1"; x-record-text="v=spf1 mx a:ushub1.microchip.com a:smtpout.microchip.com a:mx1.microchip.iphmx.com a:mx2.microchip.iphmx.com include:servers.mcsv.net include:mktomail.com include:spf.protection.outlook.com ~all" Received-SPF: None (esa2.microchip.iphmx.com: no sender authenticity information available from domain of postmaster@email.microchip.com) identity=helo; client-ip=198.175.253.82; receiver=esa2.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="postmaster@email.microchip.com"; x-conformance=spf_only Authentication-Results: esa2.microchip.iphmx.com; spf=Pass smtp.mailfrom=Tudor.Ambarus@microchip.com; spf=None smtp.helo=postmaster@email.microchip.com; dkim=pass (signature verified) header.i=@microchiptechnology.onmicrosoft.com; dmarc=pass (p=none dis=none) d=microchip.com IronPort-SDR: L7idsH8QsSwFb9NTCp9Mmh64x+NddcJ406FlZzlxruSH9yoAlLrN9EXyK2JNXwGH/UBRoHEvzT wG6fmmNlRx7vqL3FGdBdsT/GS/ZuYesVQFlHLLkva2KMSUVYiDLn9J3bgpLwnpUpOcQwH3y7y2 u00Jtfjj0eyYi3tQN2a50Slj0AqdCsDMMkvbdT5Xqjf2CCW1cS2VxagcqRQgff5ji6hJQ8bcMM M0W1JRZEOg/ax8HIonsg/JwsgdYkWjVT72qQtuTWTwGHm9zN3FrDMlB1yPPRf961ZnyA8WIMw1 Ds4= X-IronPort-AV: E=Sophos;i="5.64,433,1559545200"; d="scan'208";a="46520777" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 26 Aug 2019 05:09:05 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 26 Aug 2019 05:09:03 -0700 Received: from NAM02-BL2-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.87.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Mon, 26 Aug 2019 05:09:04 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fL1VgZZRZ9njp4rFey4KTjbLbtcwsFqSsChKLYvKyMdAGFD1sUr2Q+eoZm55SAZIYUq/Qq0OM6xZgCWmHbedhxEQPP9drhP/VtAgITvkamUMMg2SK+H0y8iGg8c6/aM7/kqiAgD5pHfM+jTf2GABwCfXipQR7wPnI8X7Q0tVu49gsmrLM4+3x4mIZ4r1HOTY8tq1WkmGwE7NoyWKUgr9NZYWHkx33OK8gBZrtkBTbO7YdHrrc53Q5PXlMTrV4A/JuDANCRpEvVuyIpntXMKkaXY+3plZgDU9sYM1HLQEz86hKH1bWuhB56emDhEGPttcz3NTKHQKexN4NB2XQ0QRJg== 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=TYkmIUFTQvRMJYvhZhq10CllljCgJS5yCXTvQ9exY1k=; b=W4huwBjcQNgDbjq4T2uUY2S6YcAzZ0TtLJ0PYVRXnhgLYyKr8KUxZOIcWS7tnqrrGCYcX0N8Ia7MS7qBJOqyzwDkakX/tpDrMtUDDts3CtigWaZ1WKIPW9VZAxgrF25+6z/PQI2sL3U6fKOsFTXpoHaNT7b22D9cyNmI68FboFgPR7WOr3tV/7k7kBwOr0qjFgpVNJ9RrXjtoEc8lT67VunAdaPphtt7INYiE+dW1axHun8Nyk865Wio4GDzQhujhKJRQCxjz/gwf5MASi7drn6cJeBkV+gyPzCwADH9pzNjNQoIM0CAmSbEPWKUFQSIcvenEpFJeZf34snELZBl4Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microchip.com; dmarc=pass action=none header.from=microchip.com; dkim=pass header.d=microchip.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microchiptechnology.onmicrosoft.com; s=selector2-microchiptechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TYkmIUFTQvRMJYvhZhq10CllljCgJS5yCXTvQ9exY1k=; b=b2cUU8QmZM6Qcb0hfK4gyCbbE6tL+wjIdNy7JrezdliLgdEPMEzI7+2Rvb6bEoazHn4cKErc3x5zd7rlzKU3tguosvHM41tetCPO0/pBGaBZBZ4inV9pqV1we0dm4G1S0+TyMTfVFJrdksmtlHe3JCsWdzqjk7uoP3UHIs8hQ+g= Received: from MN2PR11MB4448.namprd11.prod.outlook.com (52.135.39.157) by MN2PR11MB3678.namprd11.prod.outlook.com (20.178.252.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.21; Mon, 26 Aug 2019 12:08:56 +0000 Received: from MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5]) by MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5%7]) with mapi id 15.20.2199.021; Mon, 26 Aug 2019 12:08:56 +0000 From: To: , , , , , , Subject: [RESEND PATCH v3 09/20] mtd: spi-nor: Create a ->set_4byte() method Thread-Topic: [RESEND PATCH v3 09/20] mtd: spi-nor: Create a ->set_4byte() method Thread-Index: AQHVXAcE+2ySzEKDQkeCEarhbPF6Sw== Date: Mon, 26 Aug 2019 12:08:48 +0000 Message-ID: <20190826120821.16351-10-tudor.ambarus@microchip.com> References: <20190826120821.16351-1-tudor.ambarus@microchip.com> In-Reply-To: <20190826120821.16351-1-tudor.ambarus@microchip.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1PR09CA0046.eurprd09.prod.outlook.com (2603:10a6:802:28::14) To MN2PR11MB4448.namprd11.prod.outlook.com (2603:10b6:208:193::29) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.9.5 x-originating-ip: [94.177.32.156] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 65b6d62b-dae5-43c4-2022-08d72a1e2693 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:MN2PR11MB3678; x-ms-traffictypediagnostic: MN2PR11MB3678: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8273; x-forefront-prvs: 01415BB535 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(136003)(39860400002)(346002)(366004)(396003)(376002)(199004)(189003)(486006)(2616005)(476003)(6666004)(107886003)(316002)(14454004)(386003)(6506007)(76176011)(99286004)(52116002)(54906003)(110136005)(478600001)(102836004)(4326008)(25786009)(36756003)(446003)(26005)(11346002)(50226002)(81156014)(66066001)(8676002)(53936002)(81166006)(8936002)(6512007)(6486002)(6436002)(3846002)(6116002)(186003)(86362001)(305945005)(2201001)(7736002)(2906002)(64756008)(66446008)(1076003)(71190400001)(5660300002)(71200400001)(256004)(14444005)(66946007)(66556008)(66476007)(2501003); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR11MB3678; H:MN2PR11MB4448.namprd11.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: microchip.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 3jVb+vm/JSAkTJLqr5dycmuamWwNEeJkFM5jM2CooSQsaIOHII/6Om1yL8oEtBQHtX9dInzd3av1TyQUwt4czCOJMzLTr8NdVyBKWN72f3HWdLrvlbYMe4LKAhMX+UmFV8+abXnJ8ZIbt0yDv9fWxdaqqVwKpO5xM9k8V+OylAoWTVMa2UK1NBzMDFcTM/b+O0bHhCYTveMosumJ5+tjKzc+/X7oJQ+8ShzX0T4Ooa4rDqF3MD9YJ3LZrvTs/SAbzssKCuzcJMf1piDIHZJQxmNlOa5nz4HPDd2oGS/BjhsHKpGN0OrxlAussPcGCgpghfEsbm05jViVlh8IYHHHgYl3SWL5x1CLkwQe/YyLqito6f6OGSAO19RNHGVbi0et6BarFRym4OMQlHZiAS6qaZWJQNg2A5bguPwYDdh/E18= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 65b6d62b-dae5-43c4-2022-08d72a1e2693 X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Aug 2019 12:08:48.2675 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: S5MrAPvFTiaDTSzKy1sHdXqvJ631q3lnv2WBf1YWxdH2E6/i9E3YGl54oBwjHlbI5bPgYuWDo6yPFfzfxgc4/IL3j+BjSU+UsAsdbuASPJg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB3678 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190826_050906_165611_4F22200F X-CRM114-Status: GOOD ( 12.65 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [68.232.149.84 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -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 X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: boris.brezillon@bootlin.com, Tudor.Ambarus@microchip.com Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Boris Brezillon The procedure used to enable 4 byte addressing mode depends on the NOR device, so let's provide a hook so that manufacturer specific handling can be implemented in a sane way. Signed-off-by: Boris Brezillon [tudor.ambarus@microchip.com: use nor->params.set_4byte() instead of nor->set_4byte()] Signed-off-by: Tudor Ambarus Reviewed-by: Vignesh Raghavendra --- v3: no changes drivers/mtd/spi-nor/spi-nor.c | 76 ++++++++++++++++++++++--------------------- include/linux/mtd/spi-nor.h | 2 ++ 2 files changed, 41 insertions(+), 37 deletions(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index 1e7f8dc3457d..235e82a121a1 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -633,6 +633,17 @@ static int macronix_set_4byte(struct spi_nor *nor, bool enable) NULL, 0); } +static int st_micron_set_4byte(struct spi_nor *nor, bool enable) +{ + int ret; + + write_enable(nor); + ret = macronix_set_4byte(nor, enable); + write_disable(nor); + + return ret; +} + static int spansion_set_4byte(struct spi_nor *nor, bool enable) { nor->bouncebuf[0] = enable << 7; @@ -667,45 +678,24 @@ static int spi_nor_write_ear(struct spi_nor *nor, u8 ear) return nor->write_reg(nor, SPINOR_OP_WREAR, nor->bouncebuf, 1); } -/* Enable/disable 4-byte addressing mode. */ -static int set_4byte(struct spi_nor *nor, bool enable) +static int winbond_set_4byte(struct spi_nor *nor, bool enable) { - int status; - bool need_wren = false; - - switch (JEDEC_MFR(nor->info)) { - case SNOR_MFR_ST: - case SNOR_MFR_MICRON: - /* Some Micron need WREN command; all will accept it */ - need_wren = true; - /* fall through */ - case SNOR_MFR_MACRONIX: - case SNOR_MFR_WINBOND: - if (need_wren) - write_enable(nor); + int ret; - status = macronix_set_4byte(nor, enable); - if (need_wren) - write_disable(nor); + ret = macronix_set_4byte(nor, enable); + if (ret || enable) + return ret; - if (!status && !enable && - JEDEC_MFR(nor->info) == SNOR_MFR_WINBOND) { - /* - * On Winbond W25Q256FV, leaving 4byte mode causes - * the Extended Address Register to be set to 1, so all - * 3-byte-address reads come from the second 16M. - * We must clear the register to enable normal behavior. - */ - write_enable(nor); - spi_nor_write_ear(nor, 0); - write_disable(nor); - } + /* + * On Winbond W25Q256FV, leaving 4byte mode causes the Extended Address + * Register to be set to 1, so all 3-byte-address reads come from the + * second 16M. We must clear the register to enable normal behavior. + */ + write_enable(nor); + ret = spi_nor_write_ear(nor, 0); + write_disable(nor); - return status; - default: - /* Spansion style */ - return spansion_set_4byte(nor, enable); - } + return ret; } static int spi_nor_xread_sr(struct spi_nor *nor, u8 *sr) @@ -4153,11 +4143,18 @@ static int spi_nor_parse_sfdp(struct spi_nor *nor, static void macronix_set_default_init(struct spi_nor *nor) { nor->params.quad_enable = macronix_quad_enable; + nor->params.set_4byte = macronix_set_4byte; } static void st_micron_set_default_init(struct spi_nor *nor) { nor->params.quad_enable = NULL; + nor->params.set_4byte = st_micron_set_4byte; +} + +static void winbond_set_default_init(struct spi_nor *nor) +{ + nor->params.set_4byte = winbond_set_4byte; } /** @@ -4178,6 +4175,10 @@ static void spi_nor_manufacturer_init_params(struct spi_nor *nor) st_micron_set_default_init(nor); break; + case SNOR_MFR_WINBOND: + winbond_set_default_init(nor); + break; + default: break; } @@ -4222,6 +4223,7 @@ static void spi_nor_info_init_params(struct spi_nor *nor) /* Initialize legacy flash parameters and settings. */ params->quad_enable = spansion_quad_enable; + params->set_4byte = spansion_set_4byte; /* Set SPI NOR sizes. */ params->size = (u64)info->sector_size * info->n_sectors; @@ -4587,7 +4589,7 @@ 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"); - set_4byte(nor, true); + nor->params.set_4byte(nor, true); } return 0; @@ -4611,7 +4613,7 @@ void spi_nor_restore(struct spi_nor *nor) /* restore the addressing mode */ if (nor->addr_width == 4 && !(nor->flags & SNOR_F_4B_OPCODES) && nor->flags & SNOR_F_BROKEN_RESET) - set_4byte(nor, false); + nor->params.set_4byte(nor, false); } EXPORT_SYMBOL_GPL(spi_nor_restore); diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h index a86c0d9fb01d..7da89dd483cb 100644 --- a/include/linux/mtd/spi-nor.h +++ b/include/linux/mtd/spi-nor.h @@ -482,6 +482,7 @@ struct spi_nor; * @erase_map: the erase map parsed from the SFDP Sector Map Parameter * Table. * @quad_enable: enables SPI NOR quad mode. + * @set_4byte: puts the SPI NOR in 4 byte addressing mode. */ struct spi_nor_flash_parameter { u64 size; @@ -494,6 +495,7 @@ struct spi_nor_flash_parameter { struct spi_nor_erase_map erase_map; int (*quad_enable)(struct spi_nor *nor); + int (*set_4byte)(struct spi_nor *nor, bool enable); }; /** From patchwork Mon Aug 26 12:08:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tudor Ambarus X-Patchwork-Id: 1153150 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=microchip.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Dd7IqLqn"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=microchiptechnology.onmicrosoft.com header.i=@microchiptechnology.onmicrosoft.com header.b="eqXETzB5"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46H9qD61N8z9s7T for ; Mon, 26 Aug 2019 22:12:08 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=UZpr1cGqT/2QKMflt9a10CEvfeQh+gv1FC1yZkuKMYg=; b=Dd7IqLqnfx4uOb d+oOyE25pihWWCOkEuLRnUF8qp4mbt3ygmoln9O4XYlf3WIxgNoTFGCb+bUVxGS7s3wrbZ9bn0Vpe 9JfOJBiTxw1UZRrG4B5VtFaaYJRGMzT1yf1hcmaZk4EDLA8Tni8xi4+p6zzfphuMN+tdyFjanYkE7 8zGRDueI1GkDUeWP0Hx913eTUOtnHsUXkS+zgYjAhQaa5nLw+mg53qHUaYe7ZYOwxAPi/Fevveys3 RTPskUT7hxtVX5bqfnNBCHYI5xRCZ2MTcXO1gBDzUJER29Q3xYypVcNgFQ4N+NA9Ze5+5ViDVzVDP gZgHXE6aCjzJtLcNAFHA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i2Dqg-0006w8-Mm; Mon, 26 Aug 2019 12:11:50 +0000 Received: from esa2.microchip.iphmx.com ([68.232.149.84]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i2Do5-0002er-Lo for linux-mtd@lists.infradead.org; Mon, 26 Aug 2019 12:09:15 +0000 Received-SPF: Pass (esa2.microchip.iphmx.com: domain of Tudor.Ambarus@microchip.com designates 198.175.253.82 as permitted sender) identity=mailfrom; client-ip=198.175.253.82; receiver=esa2.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="Tudor.Ambarus@microchip.com"; x-conformance=spf_only; x-record-type="v=spf1"; x-record-text="v=spf1 mx a:ushub1.microchip.com a:smtpout.microchip.com a:mx1.microchip.iphmx.com a:mx2.microchip.iphmx.com include:servers.mcsv.net include:mktomail.com include:spf.protection.outlook.com ~all" Received-SPF: None (esa2.microchip.iphmx.com: no sender authenticity information available from domain of postmaster@email.microchip.com) identity=helo; client-ip=198.175.253.82; receiver=esa2.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="postmaster@email.microchip.com"; x-conformance=spf_only Authentication-Results: esa2.microchip.iphmx.com; spf=Pass smtp.mailfrom=Tudor.Ambarus@microchip.com; spf=None smtp.helo=postmaster@email.microchip.com; dkim=pass (signature verified) header.i=@microchiptechnology.onmicrosoft.com; dmarc=pass (p=none dis=none) d=microchip.com IronPort-SDR: ax6khYD2ZtdR/+3oFaHSbd14tERUVove8aIlQ9TQoJiLt4XhL9CNeFJkWTdtzzwWPU+LJGxVfv 1iFYSd9nd8pqXF4fat9chNn1ACBdcgyIU6BBSZdzmZJ/OcR75liAnTybt+c8mKzjR6QLRoNp68 I4vBhSKoJsJrSCDSgczkoU+qWzfEpoT/wWo2SFsd1o1+Ueqv/x4g2vQsFCtG8COL/b24/f1K2q d4x9e5PGTqjQM+WxvfI7RRFJYgzOlKLTYXfwODuM+rSicSv3s0Ism9K5hdyO3aniVVzUNh5M2D +dY= X-IronPort-AV: E=Sophos;i="5.64,433,1559545200"; d="scan'208";a="46520780" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 26 Aug 2019 05:09:05 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.87.72) by chn-vm-ex02.mchp-main.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 26 Aug 2019 05:09:04 -0700 Received: from NAM02-BL2-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Mon, 26 Aug 2019 05:09:04 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=btbtYDdmjpEG5hYxi3LmUFYDt+GpuWu5zCGBZXJD/I+AAoZ2pJFjvl0MJXiG1s2sxeKnSf3lk8cOfXbcRpQsgINZ9FsYyqtRMVPxNfcWIwuxmB2cmvPjNTX58WP5dbEodnRj+U8vaKdccgVpi3nfsgwh7wnVYrKFxL7BvbhYGcvQ9XoJ6lg/ICYHSkHoYgwjxFdduL/Qg1yvCxYlUohXfBAxuZBGWnR1q/uVslCedryX1IVkz/IsT6Y71xE2xkQiKHALmeAG5ipWpRV0pqGoQUxvs5u3vI6R9Lvnrv0dlO0+IgSUxbsNYpjac2YQAKupZgm2K6iSg31F3Nlzru9YEw== 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=6T1YHZWV8TyZgRF10y/o+KIqRMw8GGpK0CyRZfHJ8aM=; b=Ig5L4zzgn1H/M2GVxftiegH1u48L4bEVgVgPzpnUqvoUFuTsShVUNLsZhhBkrL1S9S6JNEEpR6N8/R8VHp3Er0OPAOtrM/wguG3iGrQuC2QerCFq98qEYUNG6lqOv13pLZS0nd6ClfEfAxquUGrNzesKn208+1alRiIXgwYh5/JUDKqDYHqe+DktA/WTlRd/Nk+EBYACGLaEHydrZkYoQtMpv8yu2NYXunM92p0db6Ao8+gOfi8r2uAyN3t0DOzPcZQgipN1iuxUK4x7e8JZnZ04QkKGAIi6oxRA9EIViMWQMxNUA8I5pwl6mwramCQTHie7BfaJgDHZH3qDnLPC6Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microchip.com; dmarc=pass action=none header.from=microchip.com; dkim=pass header.d=microchip.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microchiptechnology.onmicrosoft.com; s=selector2-microchiptechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6T1YHZWV8TyZgRF10y/o+KIqRMw8GGpK0CyRZfHJ8aM=; b=eqXETzB5cHHpFt8PtQ+1Paz6xKeMXxce7ScMKZ0TQ2F+FEpcF7mBWhOUn6EsRD3ZNJ0pnMJmGAF1jCejBK0RoZri9iLRHzZEDBR+Ce6tHpB1g509y3VIsQYoHhbajUap/m5S2yAOvWaI3s/c+3WLPULdJij9cqtoFbe2Gdbyv5M= Received: from MN2PR11MB4448.namprd11.prod.outlook.com (52.135.39.157) by MN2PR11MB3678.namprd11.prod.outlook.com (20.178.252.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.21; Mon, 26 Aug 2019 12:09:02 +0000 Received: from MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5]) by MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5%7]) with mapi id 15.20.2199.021; Mon, 26 Aug 2019 12:09:02 +0000 From: To: , , , , , , Subject: [RESEND PATCH v3 10/20] mtd: spi-nor: Rework the SPI NOR lock/unlock logic Thread-Topic: [RESEND PATCH v3 10/20] mtd: spi-nor: Rework the SPI NOR lock/unlock logic Thread-Index: AQHVXAcFrCpvcaMjzkSkkB6kiMDMIg== Date: Mon, 26 Aug 2019 12:08:50 +0000 Message-ID: <20190826120821.16351-11-tudor.ambarus@microchip.com> References: <20190826120821.16351-1-tudor.ambarus@microchip.com> In-Reply-To: <20190826120821.16351-1-tudor.ambarus@microchip.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1PR09CA0046.eurprd09.prod.outlook.com (2603:10a6:802:28::14) To MN2PR11MB4448.namprd11.prod.outlook.com (2603:10b6:208:193::29) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.9.5 x-originating-ip: [94.177.32.156] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 47bfae3d-6cee-4005-73f4-08d72a1e27b0 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:MN2PR11MB3678; x-ms-traffictypediagnostic: MN2PR11MB3678: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:7691; x-forefront-prvs: 01415BB535 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(136003)(39860400002)(346002)(366004)(396003)(376002)(199004)(189003)(486006)(2616005)(476003)(6666004)(107886003)(316002)(14454004)(386003)(6506007)(76176011)(99286004)(52116002)(54906003)(110136005)(478600001)(102836004)(4326008)(25786009)(36756003)(446003)(26005)(11346002)(50226002)(81156014)(66066001)(8676002)(53936002)(81166006)(8936002)(6512007)(6486002)(6436002)(3846002)(6116002)(186003)(86362001)(305945005)(2201001)(7736002)(2906002)(64756008)(66446008)(1076003)(71190400001)(5660300002)(71200400001)(256004)(14444005)(66946007)(66556008)(66476007)(2501003); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR11MB3678; H:MN2PR11MB4448.namprd11.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: microchip.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 4pqUzqlVaJ/xMZG8yr2QA2P0q4J/3dqSUwlro/cKDgCaUX73wd+weZ1F3TPRdjBV2M+h+nExC1rLRVNBK8r3nGvwTTjVhj0NCzhny57UYDuKL9XYpH9HDAg0JWEfxyc1wczrreXcRaORBTWpWpHN6KbRFCWbCOJsmAUpeHnaRMOq74WLHkgmIjvy3VL3Q2xow3aU8BY0oOR/foW5HyccpaMsHlBeIjXIA+DpfOB3hK+ITtZMFxnM9es2VXBHrN9pTDwVI9PwvcZ48cuqcRYpx9hZ6/k9cvYJ++/FP1vrrNsrmqXIM+8Chp5k23zzTkQH2AaNXljYggT1F9LpBdWYtxmY/OYlahUyT2Nr2js9eqWXDLM0hrqInm1AjGr94M4eViPLCAtPoyIF1eEkGaTQJQG8Y1XJOjSeyRwFizpGup8= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 47bfae3d-6cee-4005-73f4-08d72a1e27b0 X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Aug 2019 12:08:50.1704 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: qNQ7+67AFc/xFcM/eaLYrHxc9hIXFTLHpnKA3Hvnu5oEK2caxnFpSJ+t/aH26TsvhFdH+cjSAYbI0WOQ2Wxkf6XaieuBEU6MlqLpUNw/q8M= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB3678 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190826_050909_814429_7CE2CE21 X-CRM114-Status: GOOD ( 16.41 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [68.232.149.84 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -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 X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: boris.brezillon@bootlin.com, Tudor.Ambarus@microchip.com Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Boris Brezillon Add the SNOR_F_HAS_LOCK flag and set it when SPI_NOR_HAS_LOCK is set in the flash_info entry or when it's a Micron or ST flash. Move the locking hooks in a separate struct so that we have just one field to update when we change the locking implementation. Signed-off-by: Boris Brezillon [tudor.ambarus@microchip.com: use ->default_init() hook, introduce spi_nor_late_init_params(), set ops in nor->params] Signed-off-by: Tudor Ambarus Reviewed-by: Vignesh Raghavendra --- v3: no changes, clear_sr_bp() is handled in the last patch of the series. drivers/mtd/spi-nor/spi-nor.c | 50 ++++++++++++++++++++++++++++++++----------- include/linux/mtd/spi-nor.h | 23 ++++++++++++++------ 2 files changed, 53 insertions(+), 20 deletions(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index 235e82a121a1..3f997797fa9d 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -1598,6 +1598,12 @@ static int stm_is_locked(struct spi_nor *nor, loff_t ofs, uint64_t len) return stm_is_locked_sr(nor, ofs, len, status); } +static const struct spi_nor_locking_ops stm_locking_ops = { + .lock = stm_lock, + .unlock = stm_unlock, + .is_locked = stm_is_locked, +}; + static int spi_nor_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) { struct spi_nor *nor = mtd_to_spi_nor(mtd); @@ -1607,7 +1613,7 @@ static int spi_nor_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) if (ret) return ret; - ret = nor->flash_lock(nor, ofs, len); + ret = nor->params.locking_ops->lock(nor, ofs, len); spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_UNLOCK); return ret; @@ -1622,7 +1628,7 @@ static int spi_nor_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) if (ret) return ret; - ret = nor->flash_unlock(nor, ofs, len); + ret = nor->params.locking_ops->unlock(nor, ofs, len); spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_LOCK); return ret; @@ -1637,7 +1643,7 @@ static int spi_nor_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len) if (ret) return ret; - ret = nor->flash_is_locked(nor, ofs, len); + ret = nor->params.locking_ops->is_locked(nor, ofs, len); spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_LOCK); return ret; @@ -4148,6 +4154,7 @@ static void macronix_set_default_init(struct spi_nor *nor) static void st_micron_set_default_init(struct spi_nor *nor) { + nor->flags = SNOR_F_HAS_LOCK; nor->params.quad_enable = NULL; nor->params.set_4byte = st_micron_set_4byte; } @@ -4292,6 +4299,23 @@ static void spi_nor_info_init_params(struct spi_nor *nor) } /** + * spi_nor_late_init_params() - Late initialization of default flash parameters. + * @nor: pointer to a 'struct spi_nor' + * + * Used to set default flash parameters and settings when the ->default_init() + * hook or the SFDP parser let voids. + */ +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) + nor->params.locking_ops = &stm_locking_ops; +} + +/** * spi_nor_init_params() - Initialize the flash's parameters and settings. * @nor: pointer to a 'struct spi-nor'. * @@ -4316,6 +4340,10 @@ static void spi_nor_info_init_params(struct spi_nor *nor) * Please not that there is a ->post_bfpt() fixup hook that can overwrite the * flash parameters and settings imediately after parsing the Basic Flash * Parameter Table. + * + * 4/ Late default flash parameters initialization, used when the + * ->default_init() hook or the SFDP parser do not set specific params. + * spi_nor_late_init_params() */ static void spi_nor_init_params(struct spi_nor *nor) { @@ -4326,6 +4354,8 @@ static void spi_nor_init_params(struct spi_nor *nor) if ((nor->info->flags & (SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ)) && !(nor->info->flags & SPI_NOR_SKIP_SFDP)) spi_nor_sfdp_init_params(nor); + + spi_nor_late_init_params(nor); } static int spi_nor_select_read(struct spi_nor *nor, @@ -4707,6 +4737,9 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, if (info->flags & SPI_S3AN) nor->flags |= SNOR_F_READY_XSR_RDY; + if (info->flags & SPI_NOR_HAS_LOCK) + nor->flags |= SNOR_F_HAS_LOCK; + /* * Atmel, SST, Intel/Numonyx, and others serial NOR tend to power up * with the software protection bits set. @@ -4731,16 +4764,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, mtd->_read = spi_nor_read; mtd->_resume = spi_nor_resume; - /* NOR protection support for STmicro/Micron chips and similar */ - if (JEDEC_MFR(info) == SNOR_MFR_ST || - JEDEC_MFR(info) == SNOR_MFR_MICRON || - info->flags & SPI_NOR_HAS_LOCK) { - nor->flash_lock = stm_lock; - nor->flash_unlock = stm_unlock; - nor->flash_is_locked = stm_is_locked; - } - - if (nor->flash_lock && nor->flash_unlock && nor->flash_is_locked) { + if (nor->params.locking_ops) { mtd->_lock = spi_nor_lock; mtd->_unlock = spi_nor_unlock; mtd->_is_locked = spi_nor_is_locked; diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h index 7da89dd483cb..ea3bcac54dc2 100644 --- a/include/linux/mtd/spi-nor.h +++ b/include/linux/mtd/spi-nor.h @@ -243,6 +243,7 @@ enum spi_nor_option_flags { SNOR_F_BROKEN_RESET = BIT(6), SNOR_F_4B_OPCODES = BIT(7), SNOR_F_HAS_4BAIT = BIT(8), + SNOR_F_HAS_LOCK = BIT(9), }; /** @@ -466,6 +467,18 @@ enum spi_nor_pp_command_index { struct spi_nor; /** + * struct spi_nor_locking_ops - SPI NOR locking methods + * @lock: lock a region of the SPI NOR. + * @unlock: unlock a region of the SPI NOR. + * @is_locked: check if a region of the SPI NOR is completely locked + */ +struct spi_nor_locking_ops { + int (*lock)(struct spi_nor *nor, loff_t ofs, uint64_t len); + int (*unlock)(struct spi_nor *nor, loff_t ofs, uint64_t len); + int (*is_locked)(struct spi_nor *nor, loff_t ofs, uint64_t len); +}; + +/** * struct spi_nor_flash_parameter - SPI NOR flash parameters and settings. * Includes legacy flash parameters and settings that can be overwritten * by the spi_nor_fixups hooks, or dynamically when parsing the JESD216 @@ -483,6 +496,7 @@ struct spi_nor; * Table. * @quad_enable: enables SPI NOR quad mode. * @set_4byte: puts the SPI NOR in 4 byte addressing mode. + * @locking_ops: SPI NOR locking methods. */ struct spi_nor_flash_parameter { u64 size; @@ -496,6 +510,8 @@ struct spi_nor_flash_parameter { int (*quad_enable)(struct spi_nor *nor); int (*set_4byte)(struct spi_nor *nor, bool enable); + + const struct spi_nor_locking_ops *locking_ops; }; /** @@ -536,10 +552,6 @@ struct flash_info; * @erase: [DRIVER-SPECIFIC] erase a sector of the SPI NOR * at the offset @offs; if not provided by the driver, * spi-nor will send the erase opcode via write_reg() - * @flash_lock: [FLASH-SPECIFIC] lock a region of the SPI NOR - * @flash_unlock: [FLASH-SPECIFIC] unlock a region of the SPI NOR - * @flash_is_locked: [FLASH-SPECIFIC] check if a region of the SPI NOR is - * completely locked * @clear_sr_bp: [FLASH-SPECIFIC] clears the Block Protection Bits from * the SPI NOR Status Register. * @params: [FLASH-SPECIFIC] SPI-NOR flash parameters and settings. @@ -579,9 +591,6 @@ struct spi_nor { size_t len, const u_char *write_buf); int (*erase)(struct spi_nor *nor, loff_t offs); - int (*flash_lock)(struct spi_nor *nor, loff_t ofs, uint64_t len); - int (*flash_unlock)(struct spi_nor *nor, loff_t ofs, uint64_t len); - int (*flash_is_locked)(struct spi_nor *nor, loff_t ofs, uint64_t len); int (*clear_sr_bp)(struct spi_nor *nor); struct spi_nor_flash_parameter params; From patchwork Mon Aug 26 12:08:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tudor Ambarus X-Patchwork-Id: 1153145 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=microchip.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Ap35snAR"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=microchiptechnology.onmicrosoft.com header.i=@microchiptechnology.onmicrosoft.com header.b="qL+PSksg"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46H9pD5JD0z9sDB for ; Mon, 26 Aug 2019 22:11:16 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=MRLTFHaGW8q0Kp0CNuxv22CR/VLJ06ZZ0lEzxLiHM3g=; b=Ap35snAR1vGhQB EqgtA2BY8kYYaiRy9wcL4YXy47UpCkNxem+d32j1Iit9Sk9Z5txs37c89ip1Fsrjr2tys6kEDOTcb BiaJH4+8yRJGbstXq7nL3HDbjAPhut2SCPGSmIoCYy46YhLq4pCqxJZ32jAtsIiDzr+HjzxI+u4z6 P5Gx3EMZmdG50N6CkGkPub/cf8A1YaSLvA+/It52QFwal+kCIiST3Crq4lKx7MbngPhxMmQCAdn3w lcvcMPgQavkfwFNJB/4qUQAFdjq/8c3Hyh4BPFXnYf2B5RVqd5lOyNbAmom6VUM5DdMmsuic3+LCF /ZS1saISkirmMa6JyVUg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i2Dpp-0005tb-HH; Mon, 26 Aug 2019 12:10:57 +0000 Received: from esa6.microchip.iphmx.com ([216.71.154.253]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i2Do3-0002gk-67 for linux-mtd@lists.infradead.org; Mon, 26 Aug 2019 12:09:10 +0000 Received-SPF: Pass (esa6.microchip.iphmx.com: domain of Tudor.Ambarus@microchip.com designates 198.175.253.82 as permitted sender) identity=mailfrom; client-ip=198.175.253.82; receiver=esa6.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="Tudor.Ambarus@microchip.com"; x-conformance=spf_only; x-record-type="v=spf1"; x-record-text="v=spf1 mx a:ushub1.microchip.com a:smtpout.microchip.com a:mx1.microchip.iphmx.com a:mx2.microchip.iphmx.com include:servers.mcsv.net include:mktomail.com include:spf.protection.outlook.com ~all" Received-SPF: None (esa6.microchip.iphmx.com: no sender authenticity information available from domain of postmaster@email.microchip.com) identity=helo; client-ip=198.175.253.82; receiver=esa6.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="postmaster@email.microchip.com"; x-conformance=spf_only Authentication-Results: esa6.microchip.iphmx.com; spf=Pass smtp.mailfrom=Tudor.Ambarus@microchip.com; spf=None smtp.helo=postmaster@email.microchip.com; dkim=pass (signature verified) header.i=@microchiptechnology.onmicrosoft.com; dmarc=pass (p=none dis=none) d=microchip.com IronPort-SDR: 9AN7mdAyIVI+BLr/A5368/qRTb1/PC8sEOBnth8BDsDYAOxRoCj0BFc77ZgWsQDMGRsIcOKh/i 1UXhutQvZ/Hk02ZR7bZBj/rcH9Jvv+0dM8g1F7xArgX5luAXyJ4CfyYKLIucIdAJrhABQLGkix n1VhWRiAZD2uIGdvMCwXBqq7T89a7T9VCKg3YXFrnpt+gE3cza0tlgcvLiUrvY2DCG4kiMPgaT ZfPf/CopUeZHnmqnx0/pwDgkzmZJDk1T7ZzVGURKv9hgHu3uPwS9TqkLvvMTuGtMRLk3q+yide 6j8= X-IronPort-AV: E=Sophos;i="5.64,433,1559545200"; d="scan'208";a="43686984" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 26 Aug 2019 05:09:06 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 26 Aug 2019 05:09:05 -0700 Received: from NAM02-BL2-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Mon, 26 Aug 2019 05:09:04 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hB1+dT+Ad32QCxxPOJ1NR5cVBp0XDeZ51+mM/ljh8qbIG9gldNW/9aXyovNAjh5C//t7Wel7TdRtADt9zPGSvuLJBAtMon2NVGWYOQbOybdkVu9V9DIKEeu0hsYrl9+EKMLfwXtNRVHXjKRf34ta0lsbwdPSS3zVmOWVdmqYwhfCNXo4prVi8K1AlLy0cjlLy7AW9zeMBZKGydbLGPX3bU+wFNs4aHlvpQwQ83DNFTWEclT4zibwYS1Z5WjvTEurrsFk9PpZLSJFvT/c4CAYn8uaHbmPqU8/frcBiDZmZMXjZ6EJ2+LeLU2h49BTYamL+RL5d99U7MKWg7BPKTr5Vw== 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=wzKEj7C2oecdyIVgmS+q8nCE1Ab6V9iG0C1/KPjXWOM=; b=Wm7xBvNy9fy/grFY3uS/eCkNO8H3yBIbpRWnL9DNXzNXSTr0A+INKlrQohQlkYbsei1HpjpyT7UU1fne+l/CsTJ32Oh9EX9RrhTIjyd4VMsd1X7BPmSXx7zsTPXFJTorKoCiduIGzpRwNiTJHIAv3Z36v08sho7Cepj4M/Vc3qz8HoM5A/fbJa9oHRbiqcKc8brpic1jgGP5eSx4fsZJYuGL0ZDI1yxunWu9+esyZwyEuq2bUYy2nOC6TOc5kpC96dnLoeBdgiWwC7U0c75cLvjp98ntIxEcPSCzJT6wXci6IFYIX0wJQ01DIDB0reOrEcF3bGOysmWgw4M+k3parQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microchip.com; dmarc=pass action=none header.from=microchip.com; dkim=pass header.d=microchip.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microchiptechnology.onmicrosoft.com; s=selector2-microchiptechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wzKEj7C2oecdyIVgmS+q8nCE1Ab6V9iG0C1/KPjXWOM=; b=qL+PSksgUkyFPX6/ead0wIuN6zETiyp1Gs+Kn3nLBTLM/wjGmDu/fqBA756jlHKdc9LOhN4hPYw4Kq4baBVTn4c4KZNfwjLcpxj6Gcc+LE5ApnHwqVUPffKn37nRsLGFPc95ujv2GbAaZApiakr/ai12VUXbv98uGeD2v5bScHs= Received: from MN2PR11MB4448.namprd11.prod.outlook.com (52.135.39.157) by MN2PR11MB3678.namprd11.prod.outlook.com (20.178.252.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.21; Mon, 26 Aug 2019 12:09:03 +0000 Received: from MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5]) by MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5%7]) with mapi id 15.20.2199.021; Mon, 26 Aug 2019 12:09:03 +0000 From: To: , , , , , , Subject: [RESEND PATCH v3 11/20] mtd: spi-nor: Add post_sfdp() hook to tweak flash config Thread-Topic: [RESEND PATCH v3 11/20] mtd: spi-nor: Add post_sfdp() hook to tweak flash config Thread-Index: AQHVXAcGVLYagwCSlEah3QOflpgycw== Date: Mon, 26 Aug 2019 12:08:52 +0000 Message-ID: <20190826120821.16351-12-tudor.ambarus@microchip.com> References: <20190826120821.16351-1-tudor.ambarus@microchip.com> In-Reply-To: <20190826120821.16351-1-tudor.ambarus@microchip.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1PR09CA0046.eurprd09.prod.outlook.com (2603:10a6:802:28::14) To MN2PR11MB4448.namprd11.prod.outlook.com (2603:10b6:208:193::29) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.9.5 x-originating-ip: [94.177.32.156] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 56c54d9c-bd66-4bfd-1e3d-08d72a1e28d3 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:MN2PR11MB3678; x-ms-traffictypediagnostic: MN2PR11MB3678: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8882; x-forefront-prvs: 01415BB535 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(136003)(39860400002)(346002)(366004)(396003)(376002)(199004)(189003)(486006)(2616005)(476003)(6666004)(107886003)(316002)(14454004)(386003)(6506007)(76176011)(99286004)(52116002)(54906003)(110136005)(478600001)(102836004)(4326008)(25786009)(36756003)(446003)(26005)(11346002)(50226002)(81156014)(66066001)(8676002)(53936002)(81166006)(8936002)(6512007)(6486002)(6436002)(3846002)(6116002)(186003)(86362001)(305945005)(2201001)(7736002)(2906002)(64756008)(66446008)(1076003)(71190400001)(5660300002)(71200400001)(256004)(14444005)(66946007)(66556008)(66476007)(2501003); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR11MB3678; H:MN2PR11MB4448.namprd11.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: microchip.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: r2aopq3PFWxQPQGIySJrtXM987ZOsA+ZA5xZ5SMS+Hw/CtzwX0mI6Yipy+4kGHk++apI1PSU4C7su+wt42tKcKpkY5nh87wdqWC0YH2F7fJkqs2vLZi8fskPaPzXk8/883rYdqAgKXDOtBFSC8F0ogaPDlt8R2kjmS/sUX9M2Hh7w6PakDIcIBrRRkJ0WJ9INdxHNO2srARm8ck5rXryb95jrFovjqxw43aChRJpXPgYqgnmSIxgMGqRg8QiDHxZSLvx+JUTh5qAx/XAPePwiy3IX7v3LaqcLVCBfDsSWd5xKp/LQtq0PGTPf/XnpFG6q6YeqAsto8rgJzvlZLmp2/IY5Tvwuc0JSHU+/Z8jN60e4XFPlBXxfPn7l+Im1bgY7RTeRyIQM67kzzBUbPeaCKkKoLXPXC/F5dyPkGs9aWc= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 56c54d9c-bd66-4bfd-1e3d-08d72a1e28d3 X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Aug 2019 12:08:52.0933 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: p3CIlEY5nZJJrx4peh0VKdAGzPmfb0ZmPTWCcdtTFsE1DMVkzfj5KTNkJSnFh8u2DOtaEOvlhxoSScZ9CNXoF3Z2pkRMbLQQdYuDw//lPFU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB3678 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190826_050907_418284_D290A888 X-CRM114-Status: GOOD ( 12.26 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [216.71.154.253 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -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 X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: boris.brezillon@bootlin.com, Tudor.Ambarus@microchip.com Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Boris Brezillon SFDP tables are sometimes wrong and we need a way to override the config chosen by the SFDP parsing logic without discarding all of it. Add a new hook called after the SFDP parsing has taken place to deal with such problems. Signed-off-by: Boris Brezillon Signed-off-by: Tudor Ambarus Reviewed-by: Vignesh Raghavendra --- v3: no changes, rebase on previous commits drivers/mtd/spi-nor/spi-nor.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index 3f997797fa9d..b8caf5171ff5 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -158,6 +158,11 @@ struct sfdp_bfpt { * flash parameters when information provided by the flash_info * table is incomplete or wrong. * @post_bfpt: called after the BFPT table has been parsed + * @post_sfdp: called after SFDP has been parsed (is also called for SPI NORs + * that do not support RDSFDP). Typically used to tweak various + * parameters that could not be extracted by other means (i.e. + * when information provided by the SFDP/flash_info tables are + * incomplete or wrong). * * Those hooks can be used to tweak the SPI NOR configuration when the SFDP * table is broken or not available. @@ -168,6 +173,7 @@ struct spi_nor_fixups { const struct sfdp_parameter_header *bfpt_header, const struct sfdp_bfpt *bfpt, struct spi_nor_flash_parameter *params); + void (*post_sfdp)(struct spi_nor *nor); }; struct flash_info { @@ -4299,6 +4305,22 @@ static void spi_nor_info_init_params(struct spi_nor *nor) } /** + * spi_nor_post_sfdp_fixups() - Updates the flash's parameters and settings + * after SFDP has been parsed (is also called for SPI NORs that do not + * support RDSFDP). + * @nor: pointer to a 'struct spi_nor' + * + * Typically used to tweak various parameters that could not be extracted by + * other means (i.e. when information provided by the SFDP/flash_info tables + * are incomplete or wrong). + */ +static void spi_nor_post_sfdp_fixups(struct spi_nor *nor) +{ + if (nor->info->fixups && nor->info->fixups->post_sfdp) + nor->info->fixups->post_sfdp(nor); +} + +/** * spi_nor_late_init_params() - Late initialization of default flash parameters. * @nor: pointer to a 'struct spi_nor' * @@ -4341,7 +4363,14 @@ static void spi_nor_late_init_params(struct spi_nor *nor) * flash parameters and settings imediately after parsing the Basic Flash * Parameter Table. * - * 4/ Late default flash parameters initialization, used when the + * which can be overwritten by: + * 4/ Post SFDP flash parameters initialization. Used to tweak various + * parameters that could not be extracted by other means (i.e. when + * information provided by the SFDP/flash_info tables are incomplete or + * wrong). + * spi_nor_post_sfdp_fixups() + * + * 5/ Late default flash parameters initialization, used when the * ->default_init() hook or the SFDP parser do not set specific params. * spi_nor_late_init_params() */ @@ -4355,6 +4384,8 @@ static void spi_nor_init_params(struct spi_nor *nor) !(nor->info->flags & SPI_NOR_SKIP_SFDP)) spi_nor_sfdp_init_params(nor); + spi_nor_post_sfdp_fixups(nor); + spi_nor_late_init_params(nor); } From patchwork Mon Aug 26 12:08:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tudor Ambarus X-Patchwork-Id: 1153148 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=microchip.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="jPn6rKnW"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=microchiptechnology.onmicrosoft.com header.i=@microchiptechnology.onmicrosoft.com header.b="BfKKi3BZ"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46H9pf4T2Fz9sDB for ; Mon, 26 Aug 2019 22:11:38 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=f2tGTSHilSU+oCWSF2FLBPuuArru/RjePorReOKTpNY=; b=jPn6rKnWDkysHb z+oUY+QWItgyHPznVvUyX4iDIpucupDabLOoWCfUqmuZMBg0/Y4LLwbaR0jz6PRrihh1uwUIiLOh1 tVfoFef3EXi5Du8D++4tkGrX/jbCYQ6ziM7bqB0uSA9IJL84E4SsGl00Wzy9cGKpxjollXXNgaKsD mG6NtW9bEiaUMwCmvv83wl24+UNvhGH5pxr2LRkaP2er3gaVlqhgfUTAjxCw9wV4LxdnVKMeM4T9E KgG0Kn3gWys2J4vvRFK8VREcJIJ3nVuuDsrmlSDcJtOLindNyV8lZcd04rVtE0jylAvC1+8V5Q5IT 7WPV+ryhYjWB4HJFQsIg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i2DqS-0006dG-0M; Mon, 26 Aug 2019 12:11:36 +0000 Received: from esa6.microchip.iphmx.com ([216.71.154.253]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i2Do4-0002j9-UM for linux-mtd@lists.infradead.org; Mon, 26 Aug 2019 12:09:13 +0000 Received-SPF: Pass (esa6.microchip.iphmx.com: domain of Tudor.Ambarus@microchip.com designates 198.175.253.82 as permitted sender) identity=mailfrom; client-ip=198.175.253.82; receiver=esa6.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="Tudor.Ambarus@microchip.com"; x-conformance=spf_only; x-record-type="v=spf1"; x-record-text="v=spf1 mx a:ushub1.microchip.com a:smtpout.microchip.com a:mx1.microchip.iphmx.com a:mx2.microchip.iphmx.com include:servers.mcsv.net include:mktomail.com include:spf.protection.outlook.com ~all" Received-SPF: None (esa6.microchip.iphmx.com: no sender authenticity information available from domain of postmaster@email.microchip.com) identity=helo; client-ip=198.175.253.82; receiver=esa6.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="postmaster@email.microchip.com"; x-conformance=spf_only Authentication-Results: esa6.microchip.iphmx.com; spf=Pass smtp.mailfrom=Tudor.Ambarus@microchip.com; spf=None smtp.helo=postmaster@email.microchip.com; dkim=pass (signature verified) header.i=@microchiptechnology.onmicrosoft.com; dmarc=pass (p=none dis=none) d=microchip.com IronPort-SDR: EeimEHMz1ma+ntSSAemG7tGtmhnLGJv7VZs90oDkRE8RpEZhQzQaXoomlz7C+7dsyucj9huSr7 7EvBFAjYgJpaB2rTspMOph4sBcC3be5t8XOToq1oNiYvHsSHUdYN7FLwnMRPuWPRCP2/L3QmYg lUwCqThc73NVXHAOJptqnkdw4ornplRVpE2R61yWEZ9xHWqotfP+f/f3UkCf3RXXGD8G2QYjc+ iIaAZTS/ZtAQhqHSCyYWOflAVxBE2LXOn7dPrhNjJ9P/mJV+VpK/ilMYmJpMhdbWMGdLNQahU9 pCE= X-IronPort-AV: E=Sophos;i="5.64,433,1559545200"; d="scan'208";a="43686987" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 26 Aug 2019 05:09:06 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 26 Aug 2019 05:09:05 -0700 Received: from NAM02-BL2-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Mon, 26 Aug 2019 05:09:04 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c4GXh5EYFUCGkhQgvTsL+QQUVgwXvyrEYGJWhCFHNbyqdtK6SW/qoIkxzw6zPg8WYNetYAq00mq9ULKrV/lGiOebQFfDIczigKFFJlQPfT/irclsouNY/sEK9jYBPTpQeDZzZzsrVflqx8EwdEvajaXfkENaA/w2B+NpLkjPdV+nF86Uekeyvhh7NYoZNUSCVAtDVWYuPSU8kSbbrbujjpJZoHsX0H/UzTsiRMl3DgRVwATW7gC1cJ6b0Xgt8ULp1qInJvwVnNSOjS88V4VmLAQ6QHZhn6vMx0nNkBeB/ECvcMd+ytvSq+8cJ0Mo+fNL9pu0g7ZTEMFfedvACg9cIQ== 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=+83cqgcTg75/sj6NnDtNIK6PZ+w7EoY0HKjhL3s4E+o=; b=D5oFQ2e5mgSkQ3/MioIPwStfUwudhC3yznlMlc8yXIBw1SVNCiRk2q/lXhAGQ0xlNYXNtqlR78NebGZ7hmqdMZjY+4kwd4KFHBlwHaDVjXGRymNzAG7vL4/V08AExJLnGOKUGVHCKKKPzLbJaXG7YcVi32kAyORj9PKsHpzD/Phb3L4nZpfKWVBP9+DduXhOJW0mhfeYSmFYP9Co4DWc9ZvAm3YcN62uAquL5OrOL+tRDvXoxQA3Nras2j3Nmc4kITqXevayb+L7qY4UR1GWQGK8E7Q6qXYSZ1E2owPkQBc4n4afR2907Rultcs5uboSrjzwtXoRZesTnEiNjFikVw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microchip.com; dmarc=pass action=none header.from=microchip.com; dkim=pass header.d=microchip.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microchiptechnology.onmicrosoft.com; s=selector2-microchiptechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+83cqgcTg75/sj6NnDtNIK6PZ+w7EoY0HKjhL3s4E+o=; b=BfKKi3BZ6cq2d734xinZ9hStGnVR1S1CGO95RiZkXkmTXL6mQlDuMsUQuSQPjrztD52sxX/qd0tRK1eT6wC5o6ASqCvQ75blZ3iWw0l9oSYjHRjpDHfnG/hpRZcJh3YASEVjTVqQTaDx4EyjaMd0ws1IRrcwmDoVCQVyFKfzeXU= Received: from MN2PR11MB4448.namprd11.prod.outlook.com (52.135.39.157) by MN2PR11MB3678.namprd11.prod.outlook.com (20.178.252.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.21; Mon, 26 Aug 2019 12:09:04 +0000 Received: from MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5]) by MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5%7]) with mapi id 15.20.2199.021; Mon, 26 Aug 2019 12:09:04 +0000 From: To: , , , , , , Subject: [RESEND PATCH v3 12/20] mtd: spi-nor: Add spansion_post_sfdp_fixups() Thread-Topic: [RESEND PATCH v3 12/20] mtd: spi-nor: Add spansion_post_sfdp_fixups() Thread-Index: AQHVXAcHeDngrj5uK0qv/Rz830kGLw== Date: Mon, 26 Aug 2019 12:08:54 +0000 Message-ID: <20190826120821.16351-13-tudor.ambarus@microchip.com> References: <20190826120821.16351-1-tudor.ambarus@microchip.com> In-Reply-To: <20190826120821.16351-1-tudor.ambarus@microchip.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1PR09CA0046.eurprd09.prod.outlook.com (2603:10a6:802:28::14) To MN2PR11MB4448.namprd11.prod.outlook.com (2603:10b6:208:193::29) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.9.5 x-originating-ip: [94.177.32.156] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 498664ce-7e1c-417f-3bad-08d72a1e2a11 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:MN2PR11MB3678; x-ms-traffictypediagnostic: MN2PR11MB3678: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:6430; x-forefront-prvs: 01415BB535 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(136003)(39860400002)(346002)(366004)(396003)(376002)(199004)(189003)(486006)(2616005)(476003)(6666004)(107886003)(316002)(14454004)(386003)(6506007)(76176011)(99286004)(52116002)(54906003)(110136005)(478600001)(102836004)(4326008)(25786009)(36756003)(446003)(26005)(11346002)(50226002)(81156014)(66066001)(8676002)(53936002)(81166006)(8936002)(6512007)(6486002)(6436002)(3846002)(6116002)(186003)(86362001)(305945005)(2201001)(7736002)(2906002)(64756008)(66446008)(1076003)(71190400001)(5660300002)(71200400001)(256004)(66946007)(66556008)(66476007)(2501003); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR11MB3678; H:MN2PR11MB4448.namprd11.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: microchip.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: W7LfY43M0RA4WXiRYdlZaGDwhGh9Ava6KaYqwLUBir/nW3l0ypyIPfqSUbyeDfdrhd73cbFF6qPWDVZPbKaU71oF2OvlTvwQ96d8BjQELzQJMfD0yg0DYoHGxU1LQSftaiBgE7S/29pEhatd+NWAobENSkt8fuWFltsKG/UiirfdpHImqjWf2El1i0MZnKbYE14I3Cpgz2UakCJgei5R5e+xzrbcne1uqLjdZK6Ha6tEWkr99sPmyh91t3c7R+DLnwYd25qxLaQ0TwgMG7vmAwtnYpQaZ6sY5Zhe60agPu4EE2vZYOAR2zebGtgNl/Xe/ZOCBuHFXn07TVvxTrqizSiugjNfclko0Ok+8wH251upoBEMcNk7mv6Kp5I9VXt2lrDuD8Gkz+lpYif+PoeEqJMRlN7vd/NRiBT9hGhkxY8= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 498664ce-7e1c-417f-3bad-08d72a1e2a11 X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Aug 2019 12:08:54.1691 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: NFmmyk6nvYM2nLHMp3G6R7r/owL3ibuQhRD7vsjoxXpgJMNkZQk1D2G05tY5fYrA32uTm0VcppoEAZw2FAVBcSP1p0btsUdGUzZLHKGSq9Y= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB3678 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190826_050909_082459_FAC3D294 X-CRM114-Status: GOOD ( 10.49 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [216.71.154.253 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -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 X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: boris.brezillon@bootlin.com, Tudor.Ambarus@microchip.com Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Boris Brezillon Add a spansion_post_sfdp_fixups() function to fix the erase opcode, erase sector size and set the SNOR_F_4B_OPCODES flag. This way, all spansion related quirks are placed in the spansion_post_sfdp_fixups() function. Signed-off-by: Boris Brezillon Signed-off-by: Tudor Ambarus Reviewed-by: Vignesh Raghavendra --- v3: no changes, rebase on previous commits drivers/mtd/spi-nor/spi-nor.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index b8caf5171ff5..c862a59ce9df 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -591,18 +591,6 @@ static u8 spi_nor_convert_3to4_erase(u8 opcode) static void spi_nor_set_4byte_opcodes(struct spi_nor *nor) { - /* Do some manufacturer fixups first */ - switch (JEDEC_MFR(nor->info)) { - case SNOR_MFR_SPANSION: - /* No small sector erase for 4-byte command set */ - nor->erase_opcode = SPINOR_OP_SE; - nor->mtd.erasesize = nor->info->sector_size; - break; - - default: - break; - } - 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); @@ -4304,6 +4292,19 @@ static void spi_nor_info_init_params(struct spi_nor *nor) spi_nor_init_uniform_erase_map(map, erase_mask, params->size); } +static void spansion_post_sfdp_fixups(struct spi_nor *nor) +{ + struct mtd_info *mtd = &nor->mtd; + + if (mtd->size <= SZ_16M) + return; + + nor->flags |= SNOR_F_4B_OPCODES; + /* No small sector erase for 4-byte command set */ + nor->erase_opcode = SPINOR_OP_SE; + nor->mtd.erasesize = nor->info->sector_size; +} + /** * spi_nor_post_sfdp_fixups() - Updates the flash's parameters and settings * after SFDP has been parsed (is also called for SPI NORs that do not @@ -4316,6 +4317,15 @@ static void spi_nor_info_init_params(struct spi_nor *nor) */ static void spi_nor_post_sfdp_fixups(struct spi_nor *nor) { + switch (JEDEC_MFR(nor->info)) { + case SNOR_MFR_SPANSION: + spansion_post_sfdp_fixups(nor); + break; + + default: + break; + } + if (nor->info->fixups && nor->info->fixups->post_sfdp) nor->info->fixups->post_sfdp(nor); } @@ -4862,8 +4872,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, nor->addr_width = 3; } - if (info->flags & SPI_NOR_4B_OPCODES || - (JEDEC_MFR(info) == SNOR_MFR_SPANSION && mtd->size > SZ_16M)) + if (info->flags & SPI_NOR_4B_OPCODES) nor->flags |= SNOR_F_4B_OPCODES; if (nor->addr_width == 4 && nor->flags & SNOR_F_4B_OPCODES && From patchwork Mon Aug 26 12:08:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tudor Ambarus X-Patchwork-Id: 1153146 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=microchip.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="MtwDWC3n"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=microchiptechnology.onmicrosoft.com header.i=@microchiptechnology.onmicrosoft.com header.b="p3Weck66"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46H9pP44zqz9s7T for ; Mon, 26 Aug 2019 22:11:25 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=OvDROGb4YUihxPLk3XjVbTQsjzAl/rUyam4DspZPu20=; b=MtwDWC3nerEy7i U0+iLFHsaOg13RIXRSS/0UdHrUdgXWP9e7atAdpz+C6itrXLiuNwy+yqzytXHtEKfD2afGqq5R1vI ekiOUn7Wcdb/P66g1Yq4iK+yntKCSWf4KeYCT8EyyyjBG7p79hWw1h/6PrnLbJCnN7Et9sZBoZMiS /qfvTjrXRXpH44sc8q0/+qf+VMTYI+NlW14M39uyDIQzQdGkSIz2kFuVsa1ARxUGZoozil14nslmW OjECPtiinyCuLCGzgROljklHGGT4tSXSAnpQr8l/X9Ze9HJTqeBSMAhc6FI5oplaBopRhWtG67DX1 gGpGtE0/Qpm8wxSJp68Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i2Dq0-00067M-NP; Mon, 26 Aug 2019 12:11:08 +0000 Received: from esa3.microchip.iphmx.com ([68.232.153.233]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i2Do4-0002he-10 for linux-mtd@lists.infradead.org; Mon, 26 Aug 2019 12:09:12 +0000 Received-SPF: Pass (esa3.microchip.iphmx.com: domain of Tudor.Ambarus@microchip.com designates 198.175.253.82 as permitted sender) identity=mailfrom; client-ip=198.175.253.82; receiver=esa3.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="Tudor.Ambarus@microchip.com"; x-conformance=spf_only; x-record-type="v=spf1"; x-record-text="v=spf1 mx a:ushub1.microchip.com a:smtpout.microchip.com a:mx1.microchip.iphmx.com a:mx2.microchip.iphmx.com include:servers.mcsv.net include:mktomail.com include:spf.protection.outlook.com ~all" Received-SPF: None (esa3.microchip.iphmx.com: no sender authenticity information available from domain of postmaster@email.microchip.com) identity=helo; client-ip=198.175.253.82; receiver=esa3.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="postmaster@email.microchip.com"; x-conformance=spf_only Authentication-Results: esa3.microchip.iphmx.com; spf=Pass smtp.mailfrom=Tudor.Ambarus@microchip.com; spf=None smtp.helo=postmaster@email.microchip.com; dkim=pass (signature verified) header.i=@microchiptechnology.onmicrosoft.com; dmarc=pass (p=none dis=none) d=microchip.com IronPort-SDR: dsbXaXnPmw1YMfA3himaX5vdbvrj5JVGScoGN0hxPeBOL2LmmEplF8+0pVvd5VogICZ87EZW1P JO+4BGeTTWJ75i4PFwufFZF2aco8wl3lOeJwha8fvjjmCtJtQp6V2c26MexxDVfiBucsvtqHvw iQVPukzTaNBKPm+8Rx5nrYWvvaBV0KrG4GerVkcZbJJfnATrUeDq+ITYS1qJdgA15ucDdMmdi7 a5u9CgANV8SwgauGsWUlkJbma9NkUfDhh2EjdkAU+NOutFf/J0ZnCFBD7LNIDtO4X4i37rxDK6 8Co= X-IronPort-AV: E=Sophos;i="5.64,433,1559545200"; d="scan'208";a="46588879" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa3.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 26 Aug 2019 05:09:06 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 26 Aug 2019 05:09:06 -0700 Received: from NAM02-BL2-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Mon, 26 Aug 2019 05:09:05 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eNK94SrAIOjcfGYOf/jRPm7ZFBdSoSFjlNAPs/e/QOIlMreyfqAAaL7DO6IceHLjkmiTwS92cZklvTxFLun7B8ratOeR0mi093s7h7I99GqJMR7X9VUwR/GZwJ+jkx7yO8mMjjJDAe14rJEqH4Yj3JNINKTBGIOHunh4nujXF+APCvhDqnCkqrrBJqcaNBERaeeAIib4EOr2E9mguSANDlK65TDZ8fHihzYRNLQzo6So32EtZkDgydue12adWKXAfuAeAUErQrZub4jQYWtJmopuCVy1Xis7wusQj1ctDRhyhYHDkEIMN4DGFTaQJJ9tVRhYpQfv6MWXY74ziDwqKw== 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=SEa3ZqPuW8cpxsoaY8eDsDepH+bxZ+OldsB82OwGtv8=; b=ki051PhbloEF/sXAivVIiZavi/DygGiH0RppeKbr85+tqvX7/sedpPt7MykAfGhCpiv2TgBMh+tDbOxW58VSH2pDPt0VkkLj8uE7FuKDZAskXxJib68XuR4YOq+MvpA73ADUAnu6ocl2CtDIIcpYRlXILEgWuYa/PaAnPt+ebjWgMu5+mGzMP73aObUzplY+7Pkw85VD9t10ao0B0/pTgkUOFGX2k5oseoi+5VoXIwHUCDYVoNDc6YC8BWJzjjBrY25o37lVHGyKKqBcq1BHCvU0XdWSzT5fnxJBhb4Dqmg/4U7z9ly3xk+CqedFXbW83fCPKQgfR2h2e7l28n7XNA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microchip.com; dmarc=pass action=none header.from=microchip.com; dkim=pass header.d=microchip.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microchiptechnology.onmicrosoft.com; s=selector2-microchiptechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SEa3ZqPuW8cpxsoaY8eDsDepH+bxZ+OldsB82OwGtv8=; b=p3Weck66EsMsI8m7a3Em7l5ASR+nm81CXVGiKoMd7yrXLo+hprLnu0alnne9Qmr+DXk0riC9WdekXpJ/oLb4am4mvI/0wCyDLsXDmw9g+EqgXMLzQOimuvK6HilXhhuTRWng1D9wHPjGdHGlrIwEd9jnlEDKqW//Wu+Prr9c2G0= Received: from MN2PR11MB4448.namprd11.prod.outlook.com (52.135.39.157) by MN2PR11MB3678.namprd11.prod.outlook.com (20.178.252.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.21; Mon, 26 Aug 2019 12:09:05 +0000 Received: from MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5]) by MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5%7]) with mapi id 15.20.2199.021; Mon, 26 Aug 2019 12:09:05 +0000 From: To: , , , , , , Subject: [RESEND PATCH v3 13/20] mtd: spi-nor: Add a ->convert_addr() method Thread-Topic: [RESEND PATCH v3 13/20] mtd: spi-nor: Add a ->convert_addr() method Thread-Index: AQHVXAcI2bVIejaYCkq3RWETUNYd3Q== Date: Mon, 26 Aug 2019 12:08:56 +0000 Message-ID: <20190826120821.16351-14-tudor.ambarus@microchip.com> References: <20190826120821.16351-1-tudor.ambarus@microchip.com> In-Reply-To: <20190826120821.16351-1-tudor.ambarus@microchip.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1PR09CA0046.eurprd09.prod.outlook.com (2603:10a6:802:28::14) To MN2PR11MB4448.namprd11.prod.outlook.com (2603:10b6:208:193::29) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.9.5 x-originating-ip: [94.177.32.156] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 14e86f13-3029-4b26-20d2-08d72a1e2b4e x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:MN2PR11MB3678; x-ms-traffictypediagnostic: MN2PR11MB3678: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-forefront-prvs: 01415BB535 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(376002)(396003)(366004)(346002)(39860400002)(136003)(189003)(199004)(186003)(86362001)(305945005)(2906002)(7736002)(2201001)(6486002)(6436002)(6116002)(3846002)(66556008)(66946007)(66476007)(2501003)(66446008)(64756008)(5660300002)(71190400001)(14444005)(256004)(71200400001)(1076003)(6506007)(386003)(14454004)(107886003)(316002)(99286004)(76176011)(110136005)(54906003)(52116002)(6666004)(2616005)(476003)(486006)(53936002)(66066001)(8676002)(8936002)(81166006)(6512007)(4326008)(25786009)(36756003)(478600001)(81156014)(102836004)(50226002)(446003)(11346002)(26005); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR11MB3678; H:MN2PR11MB4448.namprd11.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: microchip.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 81hAESR8qciIz4XYi31ZHvqfPbi+LCWu20UMuaYCA2CSmqQDDKWhwK2vZ+pO5zuYDr19EoYSwSnNh1hWbbjuX4+20b0/PjSbVYFFomc65lKz8I1ymgpKSqcxrv6pCdv+yFIdw/YQ5kxsqaLF9lu+rl40oAsjT5g/nV9Eba4TS5e/JqhU2RqwO3loh+ACBRTNH/USf6QLDCgLs+E5atAReZf/JHRJ9WH5EZpgcAzV0DSeZ+xTy4jSzXyffuJDX7arY55wFFnrIqRISOMOEauBbaJiL0sQk2z34rN8bM43iVqxus3X66EzQpHUb3cqUilNZqQzDoBo35TWzvuj/8tCqEyxUEUmWImHasJn0740gZNuKNfv2BazTBxCX8CCs8xdsROloankFESjimRn7yHxgQ== MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 14e86f13-3029-4b26-20d2-08d72a1e2b4e X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Aug 2019 12:08:56.2449 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: tNKfbgao3xShCIJMYW2wKarIIXI5XmILfVmZCD6gj3zZ0Z+u0bqziUNINnFFmq/QvP8fGXvzQz+uEzhlL3HeQAVW7tVtf/9zByweDXRBq7o= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB3678 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190826_050908_239676_CD7B321C X-CRM114-Status: GOOD ( 13.45 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [68.232.153.233 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -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 X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: boris.brezillon@bootlin.com, Tudor.Ambarus@microchip.com Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Boris Brezillon In order to separate manufacturer quirks from the core we need to get rid of all the manufacturer specific flags, like the SNOR_F_S3AN_ADDR_DEFAULT one. This can easily be replaced by a ->convert_addr() hook, which when implemented will provide the core with an easy way to convert an absolute address into something the flash understands. Right now the only user are the S3AN chips, but other manufacturers can implement it if needed. Signed-off-by: Boris Brezillon Signed-off-by: Tudor Ambarus Reviewed-by: Vignesh Raghavendra --- v3: no changes, rebase on previous commits drivers/mtd/spi-nor/spi-nor.c | 24 ++++++++++++++---------- include/linux/mtd/spi-nor.h | 17 ++++++++++------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index c862a59ce9df..b96a7066a36c 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -899,10 +899,9 @@ static void spi_nor_unlock_and_unprep(struct spi_nor *nor, enum spi_nor_ops ops) * Addr can safely be unsigned int, the biggest S3AN device is smaller than * 4 MiB. */ -static loff_t spi_nor_s3an_addr_convert(struct spi_nor *nor, unsigned int addr) +static u32 s3an_convert_addr(struct spi_nor *nor, u32 addr) { - unsigned int offset; - unsigned int page; + u32 offset, page; offset = addr % nor->page_size; page = addr / nor->page_size; @@ -911,6 +910,14 @@ static loff_t spi_nor_s3an_addr_convert(struct spi_nor *nor, unsigned int addr) return page | offset; } +static u32 spi_nor_convert_addr(struct spi_nor *nor, loff_t addr) +{ + if (!nor->params.convert_addr) + return addr; + + return nor->params.convert_addr(nor, addr); +} + /* * Initiate the erasure of a single sector */ @@ -918,8 +925,7 @@ static int spi_nor_erase_sector(struct spi_nor *nor, u32 addr) { int i; - if (nor->flags & SNOR_F_S3AN_ADDR_DEFAULT) - addr = spi_nor_s3an_addr_convert(nor, addr); + addr = spi_nor_convert_addr(nor, addr); if (nor->erase) return nor->erase(nor, addr); @@ -2535,8 +2541,7 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len, while (len) { loff_t addr = from; - if (nor->flags & SNOR_F_S3AN_ADDR_DEFAULT) - addr = spi_nor_s3an_addr_convert(nor, addr); + addr = spi_nor_convert_addr(nor, addr); ret = spi_nor_read_data(nor, addr, len, buf); if (ret == 0) { @@ -2680,8 +2685,7 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len, page_remain = min_t(size_t, nor->page_size - page_offset, len - i); - if (nor->flags & SNOR_F_S3AN_ADDR_DEFAULT) - addr = spi_nor_s3an_addr_convert(nor, addr); + addr = spi_nor_convert_addr(nor, addr); write_enable(nor); ret = spi_nor_write_data(nor, addr, page_remain, buf + i); @@ -2748,7 +2752,7 @@ static int s3an_nor_scan(struct spi_nor *nor) nor->mtd.erasesize = 8 * nor->page_size; } else { /* Flash in Default addressing mode */ - nor->flags |= SNOR_F_S3AN_ADDR_DEFAULT; + nor->params.convert_addr = s3an_convert_addr; } return 0; diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h index ea3bcac54dc2..35aad92a4ff8 100644 --- a/include/linux/mtd/spi-nor.h +++ b/include/linux/mtd/spi-nor.h @@ -237,13 +237,12 @@ enum spi_nor_option_flags { SNOR_F_USE_FSR = BIT(0), SNOR_F_HAS_SR_TB = BIT(1), SNOR_F_NO_OP_CHIP_ERASE = BIT(2), - SNOR_F_S3AN_ADDR_DEFAULT = BIT(3), - SNOR_F_READY_XSR_RDY = BIT(4), - SNOR_F_USE_CLSR = BIT(5), - SNOR_F_BROKEN_RESET = BIT(6), - SNOR_F_4B_OPCODES = BIT(7), - SNOR_F_HAS_4BAIT = BIT(8), - SNOR_F_HAS_LOCK = BIT(9), + SNOR_F_READY_XSR_RDY = BIT(3), + SNOR_F_USE_CLSR = BIT(4), + SNOR_F_BROKEN_RESET = BIT(5), + SNOR_F_4B_OPCODES = BIT(6), + SNOR_F_HAS_4BAIT = BIT(7), + SNOR_F_HAS_LOCK = BIT(8), }; /** @@ -496,6 +495,9 @@ struct spi_nor_locking_ops { * Table. * @quad_enable: enables SPI NOR quad mode. * @set_4byte: puts the SPI NOR in 4 byte addressing mode. + * @convert_addr: converts an absolute address into something the flash + * will understand. Particularly useful when pagesize is + * not a power-of-2. * @locking_ops: SPI NOR locking methods. */ struct spi_nor_flash_parameter { @@ -510,6 +512,7 @@ struct spi_nor_flash_parameter { int (*quad_enable)(struct spi_nor *nor); int (*set_4byte)(struct spi_nor *nor, bool enable); + u32 (*convert_addr)(struct spi_nor *nor, u32 addr); const struct spi_nor_locking_ops *locking_ops; }; From patchwork Mon Aug 26 12:08:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tudor Ambarus X-Patchwork-Id: 1153149 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=microchip.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="skHFh42Z"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=microchiptechnology.onmicrosoft.com header.i=@microchiptechnology.onmicrosoft.com header.b="jCKHxUUt"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46H9q63r96z9s7T for ; Mon, 26 Aug 2019 22:12:02 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Dp1trBTedDV53ikchkc5lCVtRRCufQDuJgxxo0BEZQ4=; b=skHFh42ZDvrAkU sZQnool1ObwTb8zM7AQDoUX2llEbgtlXewlZplMc/8hbjfqff+gALI1FELnurgx8i+gjF8VGSxnCV N6tnOw+36qe8gaqEcvwJxaH7cPnFZiUr0FgOtTH0RAP5WtsDVhcrsUJUNOs+OBLEvHirphdVmml8A sUD65t4yWU7KepS1pEBY33/1KXVCCxDgv+44ZKQIGZvWNe87K9HaTHct6TsiSMnKUb6bb9Az8y0Dv 2wGCIMJul2UlEOiq+03MeMloTbzoi9rQwbqapdfGX2dNXOXRwrKFUK+sha8udTFoNlZtMMe6TGhkD ivxEzoz72anEx1s7GN9A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i2Dqq-00078m-3K; Mon, 26 Aug 2019 12:12:00 +0000 Received: from esa6.microchip.iphmx.com ([216.71.154.253]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i2Do6-0002gk-HT for linux-mtd@lists.infradead.org; Mon, 26 Aug 2019 12:09:17 +0000 Received-SPF: Pass (esa6.microchip.iphmx.com: domain of Tudor.Ambarus@microchip.com designates 198.175.253.82 as permitted sender) identity=mailfrom; client-ip=198.175.253.82; receiver=esa6.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="Tudor.Ambarus@microchip.com"; x-conformance=spf_only; x-record-type="v=spf1"; x-record-text="v=spf1 mx a:ushub1.microchip.com a:smtpout.microchip.com a:mx1.microchip.iphmx.com a:mx2.microchip.iphmx.com include:servers.mcsv.net include:mktomail.com include:spf.protection.outlook.com ~all" Received-SPF: None (esa6.microchip.iphmx.com: no sender authenticity information available from domain of postmaster@email.microchip.com) identity=helo; client-ip=198.175.253.82; receiver=esa6.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="postmaster@email.microchip.com"; x-conformance=spf_only Authentication-Results: esa6.microchip.iphmx.com; spf=Pass smtp.mailfrom=Tudor.Ambarus@microchip.com; spf=None smtp.helo=postmaster@email.microchip.com; dkim=pass (signature verified) header.i=@microchiptechnology.onmicrosoft.com; dmarc=pass (p=none dis=none) d=microchip.com IronPort-SDR: sDJok/3uqsMZnne0GVUOb9XShFwVtQDJNhmqh1qkOkjh3ZLiaAAIj5KeyBCRQJye3NZr3vZ4gT FoXd5hJ/2G2zPDxo2WNXr0KqCoU1Qal+bj28uMNzIyC6lJr5HdX10cV07IaGcCi0LbLTCsdFh3 8ItZ6Z4rCk4q/bHkrw54wsNsDRt7xHGU3LUynTtGI4TAiw0+D4UYkis1q+s8+mycRzkW2QO94X DNMu2PLpOG2GsFSfgPSRkRie+jgJTmYiMKLbnfMbqmFw9J60tkdKI1XAIrol5LmVrnknGhhU8w o+4= X-IronPort-AV: E=Sophos;i="5.64,433,1559545200"; d="scan'208";a="43686996" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 26 Aug 2019 05:09:07 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 26 Aug 2019 05:09:06 -0700 Received: from NAM02-BL2-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Mon, 26 Aug 2019 05:09:06 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jeKKyKIw/O9MzFSLe3jgs7wt/Zx7/CHg3/hSih2EW9VmYnyO5kfIY6RfdNwSzlbJSznxvl3A6I8Da3FcuAI7+DvKej4rrmwjSlb+Vakv9k+PuShrTN+l02yFNJhNC9B9SBldDK6rR47MQMxCTTAH9k/MAdgRTrw1EFzQul9K9yyu5pAgtRN+pGpiaxJmOElDLt7NlHOZpT8yDt2eob06iRiJTHdTFRNZ8i/rY+ehyhBo2unXw9yon89GYQj3SwVDhpcxvIbc/bCGgOoWjocd333XYqAMTzQN3ZmZ1Eh4rSJtfsH9fP2SF2qirpUwgdvwOrxjqQ/GpJc8tTR/w11u6Q== 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=A7rmJye5KszaQWOnckHJL0FB/ydlh5fs3DtNq501OvM=; b=TOPq6B5jgxmB950EYAuCt/RntBWR0TYluMsjnJvMchhK8Vqxdm3sWv8c8NY5LdmtJ0jUf5uHXm8RY4obJ3LKkng9X6U08Fxy0jZx9nXIn599CCZTe7XylUQutFZm8bXNwSPP5M6gDCzGB9cmLeSqWrb0wUdIHIVZHxp1L3/yCxJgKMB9PasnFCfoSVJmC58gSK0KBnQcwBtoAHpXWqp2fw85E+adjwM/xOkZ/cE8WyYrKemsoyuWAUlVMShijCKVg+0SpNg3AIlY5rhotc9wCgQByXkTdRnFfxoCYeXlXSJQcEoz9xYAcwGvKNRYCbsK5bkqWlMwLRkeT3OYcTsFxQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microchip.com; dmarc=pass action=none header.from=microchip.com; dkim=pass header.d=microchip.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microchiptechnology.onmicrosoft.com; s=selector2-microchiptechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=A7rmJye5KszaQWOnckHJL0FB/ydlh5fs3DtNq501OvM=; b=jCKHxUUta51IY/vRuc5b8ugoGpaYY58JIcvCS3EASPsGY8r33NLx687H9NGwqO+EIJA/+tpcVv1F76j3BZjp4lMWeXVvmRm+WLn1+t9dvs1wsYDhm+eGIBqOCmoZerUmjDig6vLgRY/xfQ69QqNeKsrL8H071UD2+AwsWmgxOk0= Received: from MN2PR11MB4448.namprd11.prod.outlook.com (52.135.39.157) by MN2PR11MB3678.namprd11.prod.outlook.com (20.178.252.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.21; Mon, 26 Aug 2019 12:09:06 +0000 Received: from MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5]) by MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5%7]) with mapi id 15.20.2199.021; Mon, 26 Aug 2019 12:09:06 +0000 From: To: , , , , , , Subject: [RESEND PATCH v3 14/20] mtd: spi_nor: Add a ->setup() method Thread-Topic: [RESEND PATCH v3 14/20] mtd: spi_nor: Add a ->setup() method Thread-Index: AQHVXAcK8Rt7PKQLZkm3wHDUbT1nTg== Date: Mon, 26 Aug 2019 12:08:58 +0000 Message-ID: <20190826120821.16351-15-tudor.ambarus@microchip.com> References: <20190826120821.16351-1-tudor.ambarus@microchip.com> In-Reply-To: <20190826120821.16351-1-tudor.ambarus@microchip.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1PR09CA0046.eurprd09.prod.outlook.com (2603:10a6:802:28::14) To MN2PR11MB4448.namprd11.prod.outlook.com (2603:10b6:208:193::29) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.9.5 x-originating-ip: [94.177.32.156] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: df336aad-c362-41f8-55fa-08d72a1e2c70 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:MN2PR11MB3678; x-ms-traffictypediagnostic: MN2PR11MB3678: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8882; x-forefront-prvs: 01415BB535 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(376002)(396003)(366004)(346002)(39860400002)(136003)(189003)(199004)(186003)(86362001)(305945005)(2906002)(7736002)(2201001)(6486002)(6436002)(6116002)(3846002)(66556008)(30864003)(66946007)(66476007)(2501003)(66446008)(64756008)(5660300002)(71190400001)(14444005)(256004)(71200400001)(1076003)(6506007)(386003)(14454004)(107886003)(316002)(99286004)(76176011)(110136005)(52116002)(6666004)(2616005)(476003)(486006)(53936002)(66066001)(8676002)(8936002)(81166006)(53946003)(6512007)(4326008)(25786009)(36756003)(478600001)(81156014)(102836004)(50226002)(446003)(11346002)(26005); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR11MB3678; H:MN2PR11MB4448.namprd11.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: microchip.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 8IwD/Ky3cug+zuyGXlUJg2m0r3gP+O5PSEkNWBpNN+4T0F4U/dR2j3ve+NN/ScAnXV3x7Y9Luu+t06mZeFCjnIZJWk9Y+Z1voDcoiWjxtxKmZs23aF/dVYXYDJmIbI5cURaHX1fvdiCMuT6FKYNLOIvr0Weq2GAgfM5NDecvG+KEGXiHyQWGYCW8/0XieXDDlPUjj999fbEFQyyyBEyHZ1uVPJm4Hr0VGzpq+XpplXvSPMWc7QNu7sXm169EQRcNOZxjgigxp1p+QaW4sjvnCUlKarW6VjP2EHSUNFCiU0gLoyeF4Jlq1M4FU1xKRBomAA4K1bqnuLKT20exjce09wFHSQEGoOd3KhGre4eUIAibfu0O9sFwobWBIZpIuJnuohvd56QC2318ABjcYlq9fyo/Vy6kKgFJFt2ium7I4E4= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: df336aad-c362-41f8-55fa-08d72a1e2c70 X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Aug 2019 12:08:58.1268 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Z5pIGFdjH6+8NWBp9ChuvqUGvuK6nNAf1Y2G0YIt98klqtpSWxSfY+lJ/HLi8+IcE5xYzS1rpK/Gw2TNIg/I3Vilsiv0YdyvEMynmPL+/zE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB3678 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190826_050910_640437_2D7EFAAA X-CRM114-Status: GOOD ( 18.12 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [216.71.154.253 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -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 X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tudor.Ambarus@microchip.com Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Tudor Ambarus nor->params.setup() configures the SPI NOR memory. Useful for SPI NOR flashes that have peculiarities to the SPI NOR standard, e.g. different opcodes, specific address calculation, page size, etc. Right now the only user will be the S3AN chips, but other manufacturers can implement it if needed. Move spi_nor_setup() related code in order to avoid a forward declaration to spi_nor_default_setup(). Reviewed-by: Boris Brezillon Signed-off-by: Tudor Ambarus Reviewed-by: Vignesh Raghavendra --- v3: collect R-b, rebase on previous commits drivers/mtd/spi-nor/spi-nor.c | 432 +++++++++++++++++++++--------------------- include/linux/mtd/spi-nor.h | 5 + 2 files changed, 226 insertions(+), 211 deletions(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index b96a7066a36c..2aca56e07341 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -4144,6 +4144,226 @@ static int spi_nor_parse_sfdp(struct spi_nor *nor, return err; } +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; + const struct spi_nor_read_command *read; + + if (best_match < 0) + return -EINVAL; + + cmd = spi_nor_hwcaps_read2cmd(BIT(best_match)); + if (cmd < 0) + return -EINVAL; + + read = &nor->params.reads[cmd]; + nor->read_opcode = read->opcode; + nor->read_proto = read->proto; + + /* + * In the spi-nor framework, we don't need to make the difference + * between mode clock cycles and wait state clock cycles. + * Indeed, the value of the mode clock cycles is used by a QSPI + * flash memory to know whether it should enter or leave its 0-4-4 + * (Continuous Read / XIP) mode. + * eXecution In Place is out of the scope of the mtd sub-system. + * Hence we choose to merge both mode and wait state clock cycles + * into the so called dummy clock cycles. + */ + nor->read_dummy = read->num_mode_clocks + read->num_wait_states; + return 0; +} + +static int spi_nor_select_pp(struct spi_nor *nor, + u32 shared_hwcaps) +{ + int cmd, best_match = fls(shared_hwcaps & SNOR_HWCAPS_PP_MASK) - 1; + const struct spi_nor_pp_command *pp; + + if (best_match < 0) + return -EINVAL; + + cmd = spi_nor_hwcaps_pp2cmd(BIT(best_match)); + if (cmd < 0) + return -EINVAL; + + pp = &nor->params.page_programs[cmd]; + nor->program_opcode = pp->opcode; + nor->write_proto = pp->proto; + return 0; +} + +/** + * spi_nor_select_uniform_erase() - select optimum uniform erase type + * @map: the erase map of the SPI NOR + * @wanted_size: the erase type size to search for. Contains the value of + * info->sector_size or of the "small sector" size in case + * CONFIG_MTD_SPI_NOR_USE_4K_SECTORS is defined. + * + * Once the optimum uniform sector erase command is found, disable all the + * other. + * + * Return: pointer to erase type on success, NULL otherwise. + */ +static const struct spi_nor_erase_type * +spi_nor_select_uniform_erase(struct spi_nor_erase_map *map, + const u32 wanted_size) +{ + const struct spi_nor_erase_type *tested_erase, *erase = NULL; + int i; + u8 uniform_erase_type = map->uniform_erase_type; + + for (i = SNOR_ERASE_TYPE_MAX - 1; i >= 0; i--) { + if (!(uniform_erase_type & BIT(i))) + continue; + + tested_erase = &map->erase_type[i]; + + /* + * If the current erase size is the one, stop here: + * we have found the right uniform Sector Erase command. + */ + if (tested_erase->size == wanted_size) { + erase = tested_erase; + break; + } + + /* + * Otherwise, the current erase size is still a valid canditate. + * Select the biggest valid candidate. + */ + if (!erase && tested_erase->size) + erase = tested_erase; + /* keep iterating to find the wanted_size */ + } + + if (!erase) + return NULL; + + /* Disable all other Sector Erase commands. */ + map->uniform_erase_type &= ~SNOR_ERASE_TYPE_MASK; + map->uniform_erase_type |= BIT(erase - map->erase_type); + return erase; +} + +static int spi_nor_select_erase(struct spi_nor *nor, u32 wanted_size) +{ + struct spi_nor_erase_map *map = &nor->params.erase_map; + const struct spi_nor_erase_type *erase = NULL; + struct mtd_info *mtd = &nor->mtd; + int i; + + /* + * The previous implementation handling Sector Erase commands assumed + * that the SPI flash memory has an uniform layout then used only one + * of the supported erase sizes for all Sector Erase commands. + * So to be backward compatible, the new implementation also tries to + * manage the SPI flash memory as uniform with a single erase sector + * size, when possible. + */ +#ifdef CONFIG_MTD_SPI_NOR_USE_4K_SECTORS + /* prefer "small sector" erase if possible */ + wanted_size = 4096u; +#endif + + if (spi_nor_has_uniform_erase(nor)) { + erase = spi_nor_select_uniform_erase(map, wanted_size); + if (!erase) + return -EINVAL; + nor->erase_opcode = erase->opcode; + mtd->erasesize = erase->size; + return 0; + } + + /* + * For non-uniform SPI flash memory, set mtd->erasesize to the + * maximum erase sector size. No need to set nor->erase_opcode. + */ + for (i = SNOR_ERASE_TYPE_MAX - 1; i >= 0; i--) { + if (map->erase_type[i].size) { + erase = &map->erase_type[i]; + break; + } + } + + if (!erase) + return -EINVAL; + + mtd->erasesize = erase->size; + return 0; +} + +static int spi_nor_default_setup(struct spi_nor *nor, + const struct spi_nor_hwcaps *hwcaps) +{ + struct spi_nor_flash_parameter *params = &nor->params; + u32 ignored_mask, shared_mask; + int err; + + /* + * Keep only the hardware capabilities supported by both the SPI + * controller and the SPI flash memory. + */ + shared_mask = hwcaps->mask & params->hwcaps.mask; + + if (nor->spimem) { + /* + * When called from spi_nor_probe(), all caps are set and we + * need to discard some of them based on what the SPI + * controller actually supports (using spi_mem_supports_op()). + */ + spi_nor_spimem_adjust_hwcaps(nor, &shared_mask); + } else { + /* + * SPI n-n-n protocols are not supported when the SPI + * controller directly implements the spi_nor interface. + * Yet another reason to switch to spi-mem. + */ + ignored_mask = SNOR_HWCAPS_X_X_X; + if (shared_mask & ignored_mask) { + dev_dbg(nor->dev, + "SPI n-n-n protocols are not supported.\n"); + shared_mask &= ~ignored_mask; + } + } + + /* Select the (Fast) Read command. */ + err = spi_nor_select_read(nor, shared_mask); + if (err) { + dev_err(nor->dev, + "can't select read settings supported by both the SPI controller and memory.\n"); + return err; + } + + /* Select the Page Program command. */ + err = spi_nor_select_pp(nor, shared_mask); + if (err) { + dev_err(nor->dev, + "can't select write settings supported by both the SPI controller and memory.\n"); + return err; + } + + /* Select the Sector Erase command. */ + err = spi_nor_select_erase(nor, nor->info->sector_size); + if (err) { + dev_err(nor->dev, + "can't select erase settings supported by both the SPI controller and memory.\n"); + return err; + } + + return 0; +} + +static int spi_nor_setup(struct spi_nor *nor, + const struct spi_nor_hwcaps *hwcaps) +{ + if (!nor->params.setup) + return 0; + + return nor->params.setup(nor, hwcaps); +} + static void macronix_set_default_init(struct spi_nor *nor) { nor->params.quad_enable = macronix_quad_enable; @@ -4229,6 +4449,7 @@ static void spi_nor_info_init_params(struct spi_nor *nor) /* Initialize legacy flash parameters and settings. */ params->quad_enable = spansion_quad_enable; params->set_4byte = spansion_set_4byte; + params->setup = spi_nor_default_setup; /* Set SPI NOR sizes. */ params->size = (u64)info->sector_size * info->n_sectors; @@ -4403,217 +4624,6 @@ static void spi_nor_init_params(struct spi_nor *nor) spi_nor_late_init_params(nor); } -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; - const struct spi_nor_read_command *read; - - if (best_match < 0) - return -EINVAL; - - cmd = spi_nor_hwcaps_read2cmd(BIT(best_match)); - if (cmd < 0) - return -EINVAL; - - read = &nor->params.reads[cmd]; - nor->read_opcode = read->opcode; - nor->read_proto = read->proto; - - /* - * In the spi-nor framework, we don't need to make the difference - * between mode clock cycles and wait state clock cycles. - * Indeed, the value of the mode clock cycles is used by a QSPI - * flash memory to know whether it should enter or leave its 0-4-4 - * (Continuous Read / XIP) mode. - * eXecution In Place is out of the scope of the mtd sub-system. - * Hence we choose to merge both mode and wait state clock cycles - * into the so called dummy clock cycles. - */ - nor->read_dummy = read->num_mode_clocks + read->num_wait_states; - return 0; -} - -static int spi_nor_select_pp(struct spi_nor *nor, - u32 shared_hwcaps) -{ - int cmd, best_match = fls(shared_hwcaps & SNOR_HWCAPS_PP_MASK) - 1; - const struct spi_nor_pp_command *pp; - - if (best_match < 0) - return -EINVAL; - - cmd = spi_nor_hwcaps_pp2cmd(BIT(best_match)); - if (cmd < 0) - return -EINVAL; - - pp = &nor->params.page_programs[cmd]; - nor->program_opcode = pp->opcode; - nor->write_proto = pp->proto; - return 0; -} - -/** - * spi_nor_select_uniform_erase() - select optimum uniform erase type - * @map: the erase map of the SPI NOR - * @wanted_size: the erase type size to search for. Contains the value of - * info->sector_size or of the "small sector" size in case - * CONFIG_MTD_SPI_NOR_USE_4K_SECTORS is defined. - * - * Once the optimum uniform sector erase command is found, disable all the - * other. - * - * Return: pointer to erase type on success, NULL otherwise. - */ -static const struct spi_nor_erase_type * -spi_nor_select_uniform_erase(struct spi_nor_erase_map *map, - const u32 wanted_size) -{ - const struct spi_nor_erase_type *tested_erase, *erase = NULL; - int i; - u8 uniform_erase_type = map->uniform_erase_type; - - for (i = SNOR_ERASE_TYPE_MAX - 1; i >= 0; i--) { - if (!(uniform_erase_type & BIT(i))) - continue; - - tested_erase = &map->erase_type[i]; - - /* - * If the current erase size is the one, stop here: - * we have found the right uniform Sector Erase command. - */ - if (tested_erase->size == wanted_size) { - erase = tested_erase; - break; - } - - /* - * Otherwise, the current erase size is still a valid canditate. - * Select the biggest valid candidate. - */ - if (!erase && tested_erase->size) - erase = tested_erase; - /* keep iterating to find the wanted_size */ - } - - if (!erase) - return NULL; - - /* Disable all other Sector Erase commands. */ - map->uniform_erase_type &= ~SNOR_ERASE_TYPE_MASK; - map->uniform_erase_type |= BIT(erase - map->erase_type); - return erase; -} - -static int spi_nor_select_erase(struct spi_nor *nor, u32 wanted_size) -{ - struct spi_nor_erase_map *map = &nor->params.erase_map; - const struct spi_nor_erase_type *erase = NULL; - struct mtd_info *mtd = &nor->mtd; - int i; - - /* - * The previous implementation handling Sector Erase commands assumed - * that the SPI flash memory has an uniform layout then used only one - * of the supported erase sizes for all Sector Erase commands. - * So to be backward compatible, the new implementation also tries to - * manage the SPI flash memory as uniform with a single erase sector - * size, when possible. - */ -#ifdef CONFIG_MTD_SPI_NOR_USE_4K_SECTORS - /* prefer "small sector" erase if possible */ - wanted_size = 4096u; -#endif - - if (spi_nor_has_uniform_erase(nor)) { - erase = spi_nor_select_uniform_erase(map, wanted_size); - if (!erase) - return -EINVAL; - nor->erase_opcode = erase->opcode; - mtd->erasesize = erase->size; - return 0; - } - - /* - * For non-uniform SPI flash memory, set mtd->erasesize to the - * maximum erase sector size. No need to set nor->erase_opcode. - */ - for (i = SNOR_ERASE_TYPE_MAX - 1; i >= 0; i--) { - if (map->erase_type[i].size) { - erase = &map->erase_type[i]; - break; - } - } - - if (!erase) - return -EINVAL; - - mtd->erasesize = erase->size; - return 0; -} - -static int spi_nor_setup(struct spi_nor *nor, - const struct spi_nor_hwcaps *hwcaps) -{ - struct spi_nor_flash_parameter *params = &nor->params; - u32 ignored_mask, shared_mask; - int err; - - /* - * Keep only the hardware capabilities supported by both the SPI - * controller and the SPI flash memory. - */ - shared_mask = hwcaps->mask & params->hwcaps.mask; - - if (nor->spimem) { - /* - * When called from spi_nor_probe(), all caps are set and we - * need to discard some of them based on what the SPI - * controller actually supports (using spi_mem_supports_op()). - */ - spi_nor_spimem_adjust_hwcaps(nor, &shared_mask); - } else { - /* - * SPI n-n-n protocols are not supported when the SPI - * controller directly implements the spi_nor interface. - * Yet another reason to switch to spi-mem. - */ - ignored_mask = SNOR_HWCAPS_X_X_X; - if (shared_mask & ignored_mask) { - dev_dbg(nor->dev, - "SPI n-n-n protocols are not supported.\n"); - shared_mask &= ~ignored_mask; - } - } - - /* Select the (Fast) Read command. */ - err = spi_nor_select_read(nor, shared_mask); - if (err) { - dev_err(nor->dev, - "can't select read settings supported by both the SPI controller and memory.\n"); - return err; - } - - /* Select the Page Program command. */ - err = spi_nor_select_pp(nor, shared_mask); - if (err) { - dev_err(nor->dev, - "can't select write settings supported by both the SPI controller and memory.\n"); - return err; - } - - /* Select the Sector Erase command. */ - err = spi_nor_select_erase(nor, nor->info->sector_size); - if (err) { - dev_err(nor->dev, - "can't select erase settings supported by both the SPI controller and memory.\n"); - return err; - } - - return 0; -} - /** * spi_nor_quad_enable() - enable Quad I/O if needed. * @nor: pointer to a 'struct spi_nor' diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h index 35aad92a4ff8..fc0b4b19c900 100644 --- a/include/linux/mtd/spi-nor.h +++ b/include/linux/mtd/spi-nor.h @@ -498,6 +498,10 @@ struct spi_nor_locking_ops { * @convert_addr: converts an absolute address into something the flash * will understand. Particularly useful when pagesize is * not a power-of-2. + * @setup: configures the SPI NOR memory. Useful for SPI NOR + * flashes that have peculiarities to the SPI NOR standard + * e.g. different opcodes, specific address calculation, + * page size, etc. * @locking_ops: SPI NOR locking methods. */ struct spi_nor_flash_parameter { @@ -513,6 +517,7 @@ struct spi_nor_flash_parameter { int (*quad_enable)(struct spi_nor *nor); int (*set_4byte)(struct spi_nor *nor, bool enable); u32 (*convert_addr)(struct spi_nor *nor, u32 addr); + int (*setup)(struct spi_nor *nor, const struct spi_nor_hwcaps *hwcaps); const struct spi_nor_locking_ops *locking_ops; }; From patchwork Mon Aug 26 12:09:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tudor Ambarus X-Patchwork-Id: 1153152 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=microchip.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Gn5Oyh20"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=microchiptechnology.onmicrosoft.com header.i=@microchiptechnology.onmicrosoft.com header.b="DQDQOjyN"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46H9qb0ZJ0z9s7T for ; Mon, 26 Aug 2019 22:12:27 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=misNTWYJpc6DBRyYQJENc1zQSpf+FxryyIymqeUTWRw=; b=Gn5Oyh20vqf4wv qhdA0VU8iYO4VtGBW0lNwWy9niXC9N4+dWGTeFQ7tWyoOZsVV9xbI79kxlmb59//T2K4+ZldtLvq5 R9KySUXC9yfWpmEIfvMc/BEl7qrr3wWkwcI65pOvCho5QJjLkP5Z6Vd4FtnAkAAdcbGaqVg3iFVOF nuTnz2u1cgdW4C5NANhKjpE9PBn775Sd4BrK1MbmNdgH1nK9+yCvm93NJa/K4SIX+u6H9hHfP8EwS 21ioGz+Zx0ve9J89DAmwb342Tp0FV8WZN6lGwSkhANl0whkwjlcyCYa+xQH5Th94fo+7UFUjQYoZO agBzdkW3PIto8CGd5iKQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i2DrD-0007ac-OF; Mon, 26 Aug 2019 12:12:23 +0000 Received: from esa6.microchip.iphmx.com ([216.71.154.253]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i2Do7-0002m9-Me for linux-mtd@lists.infradead.org; Mon, 26 Aug 2019 12:09:18 +0000 Received-SPF: Pass (esa6.microchip.iphmx.com: domain of Tudor.Ambarus@microchip.com designates 198.175.253.82 as permitted sender) identity=mailfrom; client-ip=198.175.253.82; receiver=esa6.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="Tudor.Ambarus@microchip.com"; x-conformance=spf_only; x-record-type="v=spf1"; x-record-text="v=spf1 mx a:ushub1.microchip.com a:smtpout.microchip.com a:mx1.microchip.iphmx.com a:mx2.microchip.iphmx.com include:servers.mcsv.net include:mktomail.com include:spf.protection.outlook.com ~all" Received-SPF: None (esa6.microchip.iphmx.com: no sender authenticity information available from domain of postmaster@email.microchip.com) identity=helo; client-ip=198.175.253.82; receiver=esa6.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="postmaster@email.microchip.com"; x-conformance=spf_only Authentication-Results: esa6.microchip.iphmx.com; spf=Pass smtp.mailfrom=Tudor.Ambarus@microchip.com; spf=None smtp.helo=postmaster@email.microchip.com; dkim=pass (signature verified) header.i=@microchiptechnology.onmicrosoft.com; dmarc=pass (p=none dis=none) d=microchip.com IronPort-SDR: +cWE3UK4kxADAkXwkfd3ldxdvBkWTYAefW9na6aoou0f4hTJF5hISjnrpJRzoJq5J9Xi3/HYrq q22jd8vUUvViPKfrCRkiSsrRa1ykR0RairRw7Vln0ROAya/YavyeH69FQaM4ICvvZto6Y7WTe+ drXn/zuMZ7AH8S8/lXOyIWvgWz8ssFiy5oQu0/6J1YwZfZHmNOgJVLDApZ+BrtKuxv9pFI0iUA LDltls/0IIk1mCS0rQbbnwVP8pc9tr2f2fyLMsN3eMtD4Qw201exzz5xibaE1gWPOkN7McprPb WrQ= X-IronPort-AV: E=Sophos;i="5.64,433,1559545200"; d="scan'208";a="43686997" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 26 Aug 2019 05:09:08 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 26 Aug 2019 05:09:07 -0700 Received: from NAM02-BL2-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Mon, 26 Aug 2019 05:09:06 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZllERcqDEEmYKjnRku+J+s8VoMfLkfPe1i5ubYCMor1XeajPypkkoJb8vPO0rraL3KCPjyxpGJ6bJ2mtGrJr9GLX3q/V5HjOUfVGBKr3zNQa6sIVZE14JP9/U1F7X4QjBjSmQQi3aAb6ng8a48MCxDWTwfOF6QkavEmMrFOKOr1ko4y7BzjW2XMhddSxYsx6tUSt3P8eGTGCEuDiqChq91TKv8CYs+yrsCT7qMAivXNtg7WhZ/8GAOGtWopELXV8mSWnHNsvynv/fkFvkyewcW+N836m4NpihK24vZfApDIiswg6P0FonbCnWAuY/vzKu4KflCoKy/zp9m8a4ut4Uw== 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=+yK9dRxC9iY3j+O2ONywA5bmxln9Fx0o7B7YIQAhH6g=; b=BFXi6nuLhNaZySALgV13ptd+uqi6TSP2KvvTkTHbRK4kBNnzPk7pdLgTSoPmdGyv/nWP1cKGHqgGPwh+WTuLNrdTvOFGVDcohzDm9X7NzMeK4TmKLKDOreHOyTnnV0ieqM72hLbipqOnAQOJvAlczTyuK6geqAe8MQGBnllNmYphjRciDNi3YKPrYD4wQHW8ESw49EfPdoodMP6v3IEclZcWFKODPPy5P2CoMk5Wn1XfwBwcskCeBazgI/VEqxD5GK+6Z3EiFUBFL7EXWtwoACvHNN8CEMdlcGj2zS5b3Aa7HBB/TyR2u4QMBD/8IpYHigTJb20DJZqm/PLwBg/9Qw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microchip.com; dmarc=pass action=none header.from=microchip.com; dkim=pass header.d=microchip.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microchiptechnology.onmicrosoft.com; s=selector2-microchiptechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+yK9dRxC9iY3j+O2ONywA5bmxln9Fx0o7B7YIQAhH6g=; b=DQDQOjyN/BOTOMswJAlzHB+Id5aRD8H8QI0VJ5FfmeC8Sl6+jSQ+WoPNTWQvWFqkAoLnBZkVVnXRFVdXHgAXECPFIDIy9XsrNr/KrprdkP9y8CXAo4JC0HkqfuRtBnT30+AYrKfj2H2GwPJP+qdd+3C4Frb/aNL57Jy4AEsy3GE= Received: from MN2PR11MB4448.namprd11.prod.outlook.com (52.135.39.157) by MN2PR11MB3678.namprd11.prod.outlook.com (20.178.252.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.21; Mon, 26 Aug 2019 12:09:06 +0000 Received: from MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5]) by MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5%7]) with mapi id 15.20.2199.021; Mon, 26 Aug 2019 12:09:06 +0000 From: To: , , , , , , Subject: [RESEND PATCH v3 15/20] mtd: spi-nor: Add s3an_post_sfdp_fixups() Thread-Topic: [RESEND PATCH v3 15/20] mtd: spi-nor: Add s3an_post_sfdp_fixups() Thread-Index: AQHVXAcLGug0TlbN8kamSzLVrzO6ow== Date: Mon, 26 Aug 2019 12:09:00 +0000 Message-ID: <20190826120821.16351-16-tudor.ambarus@microchip.com> References: <20190826120821.16351-1-tudor.ambarus@microchip.com> In-Reply-To: <20190826120821.16351-1-tudor.ambarus@microchip.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1PR09CA0046.eurprd09.prod.outlook.com (2603:10a6:802:28::14) To MN2PR11MB4448.namprd11.prod.outlook.com (2603:10b6:208:193::29) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.9.5 x-originating-ip: [94.177.32.156] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: c7e0b2f3-6486-42fb-336c-08d72a1e2d9f x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:MN2PR11MB3678; x-ms-traffictypediagnostic: MN2PR11MB3678: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:7691; x-forefront-prvs: 01415BB535 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(376002)(396003)(366004)(346002)(39860400002)(136003)(189003)(199004)(186003)(86362001)(305945005)(2906002)(7736002)(2201001)(6486002)(6436002)(6116002)(3846002)(66556008)(66946007)(66476007)(2501003)(66446008)(64756008)(5660300002)(71190400001)(14444005)(256004)(71200400001)(1076003)(6506007)(386003)(14454004)(107886003)(316002)(99286004)(76176011)(110136005)(52116002)(6666004)(2616005)(476003)(486006)(53936002)(66066001)(8676002)(8936002)(81166006)(6512007)(4326008)(25786009)(36756003)(478600001)(81156014)(102836004)(50226002)(446003)(11346002)(26005); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR11MB3678; H:MN2PR11MB4448.namprd11.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: microchip.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: RXC6BUH0PS89gCigq/42s5pMGWHujVUrypQA2rOWFeUZxbNgitlkPgxWqoEmp2JJNpQsyWNkHrzil6QuBhBsOSyD3dQMdnuLJ+RKApVFjXIvvDR17pCMyOYT7Ole6u7dPRnx8CYOOM5YVj5EpYu3VzqvgmAhXQ9VTBnKdb/t6Va/ldxwSowLXSvS7ankdHdrVPrdl/y0VY1Rz6TZONV757o+qdn9zRLvgcMSLRV/8F8xw23FIGxzLbJ54ne57DLTJA17WQhlT0/enWQ9Hxap6NAkn9MgP/pPmU/8ZA+HiputxrNAocbdXeCMPFfIWmS9Bs5byE5vQ7mTuxG14uLdT/B5a57J845Wd7MsSS+YowMoW9JUT1InJc4oSFFH62FL7QZNW0ziw0xs0wu+xyMfOJ32jc7NkSYE+ljGbvT9F60= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: c7e0b2f3-6486-42fb-336c-08d72a1e2d9f X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Aug 2019 12:09:00.0897 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: ra4WiIgyXE0fuTtc3GD/4b1Viy851cgyALWbSuJzhOoIjdp6nLIArOsgz/D1LqaiW8Ixm0sFuP5u4Emk8qKHIp8rMSu11uGeD41gCwGlmQU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB3678 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190826_050911_841072_968494BF X-CRM114-Status: GOOD ( 10.37 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [216.71.154.253 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -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 X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tudor.Ambarus@microchip.com Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Tudor Ambarus s3an_nor_scan() was overriding the opcode selection done in spi_nor_default_setup(). Set nor->setup() method in order to avoid the unnecessary call to spi_nor_default_setup(). Signed-off-by: Tudor Ambarus Reviewed-by: Boris Brezillon Reviewed-by: Vignesh Raghavendra --- v3: no changes, rebase on previous commits drivers/mtd/spi-nor/spi-nor.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index 2aca56e07341..edf1c8badac9 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -2718,7 +2718,8 @@ static int spi_nor_check(struct spi_nor *nor) return 0; } -static int s3an_nor_scan(struct spi_nor *nor) +static int s3an_nor_setup(struct spi_nor *nor, + const struct spi_nor_hwcaps *hwcaps) { int ret; @@ -4530,6 +4531,11 @@ static void spansion_post_sfdp_fixups(struct spi_nor *nor) nor->mtd.erasesize = nor->info->sector_size; } +static void s3an_post_sfdp_fixups(struct spi_nor *nor) +{ + nor->params.setup = s3an_nor_setup; +} + /** * spi_nor_post_sfdp_fixups() - Updates the flash's parameters and settings * after SFDP has been parsed (is also called for SPI NORs that do not @@ -4551,6 +4557,9 @@ static void spi_nor_post_sfdp_fixups(struct spi_nor *nor) break; } + if (nor->info->flags & SPI_S3AN) + s3an_post_sfdp_fixups(nor); + if (nor->info->fixups && nor->info->fixups->post_sfdp) nor->info->fixups->post_sfdp(nor); } @@ -4899,12 +4908,6 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, return -EINVAL; } - if (info->flags & SPI_S3AN) { - ret = s3an_nor_scan(nor); - if (ret) - return ret; - } - /* Send all the required SPI flash commands to initialize device */ ret = spi_nor_init(nor); if (ret) From patchwork Mon Aug 26 12:09:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tudor Ambarus X-Patchwork-Id: 1153147 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=microchip.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="bM6B48ai"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=microchiptechnology.onmicrosoft.com header.i=@microchiptechnology.onmicrosoft.com header.b="uYxSMqXK"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46H9pS72JXz9s7T for ; Mon, 26 Aug 2019 22:11:28 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Wz09Vg3knL+bOrdG7Ldt82HmsHLCdg75VuWhqDAwK2s=; b=bM6B48aiQQYQhd wBdHE6070PZhREsymwQ9k9XB7hzj9F9i66NUmgwUZNT8pLGxY/oKbspTLTEHKzm9JLPTSDAj1ny8C inMvu6RkXkhTPz/CBAFW/2mV1UMA1zKIfLgs29jSOrnN2h2SYkxn/tFr//HZe26Fy6XAAmWIlrwhr xJp3XoBOXJuQbkyKXYTsOTODKxzFMXPcUgBKVYlwqqntz5NNi5TwDr8LIiSxKzhhzoNU8mL1fXhRB fK8ZBZI/LGZE98zBwy5i5nty4XEJieEH8aXLVDfIPBFT034S4cn6TmPIfuLuAum4/gZsvyiqC6jyD T1YvJLGR9RTMDXGvMacQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i2DqI-0006Os-Ox; Mon, 26 Aug 2019 12:11:26 +0000 Received: from esa3.microchip.iphmx.com ([68.232.153.233]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i2Do4-0002cI-Ve for linux-mtd@lists.infradead.org; Mon, 26 Aug 2019 12:09:14 +0000 Received-SPF: Pass (esa3.microchip.iphmx.com: domain of Tudor.Ambarus@microchip.com designates 198.175.253.82 as permitted sender) identity=mailfrom; client-ip=198.175.253.82; receiver=esa3.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="Tudor.Ambarus@microchip.com"; x-conformance=spf_only; x-record-type="v=spf1"; x-record-text="v=spf1 mx a:ushub1.microchip.com a:smtpout.microchip.com a:mx1.microchip.iphmx.com a:mx2.microchip.iphmx.com include:servers.mcsv.net include:mktomail.com include:spf.protection.outlook.com ~all" Received-SPF: None (esa3.microchip.iphmx.com: no sender authenticity information available from domain of postmaster@email.microchip.com) identity=helo; client-ip=198.175.253.82; receiver=esa3.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="postmaster@email.microchip.com"; x-conformance=spf_only Authentication-Results: esa3.microchip.iphmx.com; spf=Pass smtp.mailfrom=Tudor.Ambarus@microchip.com; spf=None smtp.helo=postmaster@email.microchip.com; dkim=pass (signature verified) header.i=@microchiptechnology.onmicrosoft.com; dmarc=pass (p=none dis=none) d=microchip.com IronPort-SDR: W0a+qKpf3vHAKvcpC/5g5tlxMN46h+CqdlFzJ85mLm4PD0cjw58ezpx9S7JQHkP5Z2mf23U0nY Ty1DCj/q5dA6vaqJGz7hCg+h8u4j1EmFgZVrV4SkPq6Y/NYAYZP/MeJRjDXNu86Ccw/bh8fRYD 4sKG3SuUTTLT23cA4MIZj4tfQ1xuklLcurjBq7tBoP7rygliSvWevT/sNx9fZ52rKY3iUag/N4 YgqhlqsT5vtmfyVYwhReqvAin4eIBAvq+BQtT58hViqHpHcAMOROsUQb/VPedo/wBbOHGpGiFW jiM= X-IronPort-AV: E=Sophos;i="5.64,433,1559545200"; d="scan'208";a="46588888" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa3.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 26 Aug 2019 05:09:08 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 26 Aug 2019 05:09:08 -0700 Received: from NAM02-BL2-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Mon, 26 Aug 2019 05:09:06 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Pa7+HYQpqMr3CHw2g9FV7fFo0xfmBC3XBfeCAq7tW/A281oMOAkqebbUiOkqEbOB8hq6l8IBE8ZPxaBactpLI+zGWwanlQ5bq0g6wXqzJpnAIQGtvTwcqYsjA6j3/MZaxwHo6Nb3mI17bAHMbBQuLPMqQ3YpvIHzdjs1TJ5GGUMwzZFTwaEcsv6GjrgEisDXEApxbPT64hDAJlT9kyTAfzoswDti0dMVCg61+TSQ0aKGK4wETcKrEfFBdUABszCrrIQwlhv/OKwCLx8NfEJYBh+ACw4bJeOUD/fEOV7LDxMD3IEJNLDD2UJKa+Kj259s2u7lcINYtyr09LpU29Cl3A== 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=JhggPw0udEUtOkV0O7Isc3yHH71wedI3XwOmfNLo+5A=; b=Qvn4eGikSt72CYJNdTQssslsplAbGJ+Z9+cq3S8IGXC6oTGxckJ+0ndKtMKHpsu8dZBdxP5ioDBh/F7CAUAUIMnneWjtNt0Lp+cSWnYi1XVgj4JOWp3HWkvEJVeIoW+z67HKleVtuFIBsz0ipKEZvjKByF1po/KV9gat0gGWnqbwJ6e7Z9cZnBHikVxaIGvaNCb06UIxoH4fX1jPYzS0Ty10DHeLwZIHlK6yENWM8TLxVtSDv8glM7o7spfURTJbB42offhXBsbJqurwGvFgm1sXktcq0xZUUTnIo/XglZvUij25DMrLJQEdl0v8YwsYaxJtGH2s7rSWA0Jw/QgaaA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microchip.com; dmarc=pass action=none header.from=microchip.com; dkim=pass header.d=microchip.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microchiptechnology.onmicrosoft.com; s=selector2-microchiptechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JhggPw0udEUtOkV0O7Isc3yHH71wedI3XwOmfNLo+5A=; b=uYxSMqXK9Gdvc0POrU9VOrNnHXQXVouTlJLSSaE9O6/4l4zdbcSXUisonwf4seLW2C8HyzWtpNe0/gYU3/FvQmIfNdq0N/diDPeH1fHjfjhd4SVnQc01/FRavZx9Gs6rErzDJyXCbDTbiRhlGhRYBIerqhyBo0jf4cepXkIhoDc= Received: from MN2PR11MB4448.namprd11.prod.outlook.com (52.135.39.157) by MN2PR11MB3678.namprd11.prod.outlook.com (20.178.252.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.21; Mon, 26 Aug 2019 12:09:07 +0000 Received: from MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5]) by MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5%7]) with mapi id 15.20.2199.021; Mon, 26 Aug 2019 12:09:07 +0000 From: To: , , , , , , Subject: [RESEND PATCH v3 16/20] mtd: spi-nor: Add the SPI_NOR_XSR_RDY flag Thread-Topic: [RESEND PATCH v3 16/20] mtd: spi-nor: Add the SPI_NOR_XSR_RDY flag Thread-Index: AQHVXAcM/ZWa5nusDk2eFvW+kEyFdA== Date: Mon, 26 Aug 2019 12:09:02 +0000 Message-ID: <20190826120821.16351-17-tudor.ambarus@microchip.com> References: <20190826120821.16351-1-tudor.ambarus@microchip.com> In-Reply-To: <20190826120821.16351-1-tudor.ambarus@microchip.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1PR09CA0046.eurprd09.prod.outlook.com (2603:10a6:802:28::14) To MN2PR11MB4448.namprd11.prod.outlook.com (2603:10b6:208:193::29) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.9.5 x-originating-ip: [94.177.32.156] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 4e67c631-0694-43c1-3416-08d72a1e2ec7 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:MN2PR11MB3678; x-ms-traffictypediagnostic: MN2PR11MB3678: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8882; x-forefront-prvs: 01415BB535 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(376002)(396003)(366004)(346002)(39860400002)(136003)(189003)(199004)(186003)(86362001)(305945005)(2906002)(7736002)(2201001)(6486002)(6436002)(6116002)(3846002)(66556008)(66946007)(66476007)(2501003)(66446008)(64756008)(5660300002)(71190400001)(14444005)(256004)(71200400001)(1076003)(6506007)(386003)(14454004)(107886003)(316002)(99286004)(76176011)(110136005)(54906003)(52116002)(6666004)(2616005)(476003)(486006)(53936002)(66066001)(8676002)(8936002)(81166006)(6512007)(4326008)(25786009)(36756003)(478600001)(81156014)(102836004)(50226002)(446003)(11346002)(26005); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR11MB3678; H:MN2PR11MB4448.namprd11.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: microchip.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: qsklD+P7nLCKN3mLMk5xcNeyHrte5QVQa+UJxe40HgzLNMZ/kHTVF1LxlEeoP1ff2cI/0ts3YqhlFoGzaT/CsIz9jw1htijwx2DG/IVoQgOyFaaZXWPJy6qFeKSPtjZS1a2nAK/eqZNPu5Xrvy/iaG57sQhgzEYfRE0wLkkG3fcLQU/nn5rkcQoGnASzPOfaYvfj36JTsNpG110G1v3pd4LJjLC+v8vk0hCu6280+5ZVnP8fU0JNtDA0MN4gYgNf6ccNuB8hdMTmlQZ/XiZum8gGl5ILNSVDAXPg8LoeKzIRiTZwglXM6VwstrM1NxJq0aogLRHy9IsQYSD+yC+XmD3CMVZZlbpSNK2TdTBFWETvEJHYU4qsBGHsvlcGNaUiCWW8wppn1HKyzfDJdSGt5xYqNKKuNrJScO4/4VoY92I= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 4e67c631-0694-43c1-3416-08d72a1e2ec7 X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Aug 2019 12:09:02.0575 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Fs+tNooJm9CXAhV/Svd7tpXac5A7b2n63IZjl6SrifiiHyR0XB8UuLjV4kdGDFMxMg4XBNlCjWYhEiojhlIO13WQXJHQGPiJj/k1hx6Jze4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB3678 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190826_050909_226322_F2DFE431 X-CRM114-Status: UNSURE ( 9.73 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [68.232.153.233 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -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 X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: boris.brezillon@bootlin.com, Tudor.Ambarus@microchip.com Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Boris Brezillon S3AN flashes use a specific opcode to read the status register. We currently use the SPI_S3AN flag to decide whether this specific SR read opcode should be used, but SPI_S3AN is about to disappear, so let's add a new flag. Note that we use the same bit as SPI_S3AN implies SPI_NOR_XSR_RDY and vice versa. Signed-off-by: Boris Brezillon Signed-off-by: Tudor Ambarus Reviewed-by: Vignesh Raghavendra --- v3: no changes drivers/mtd/spi-nor/spi-nor.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index edf1c8badac9..2699e999d21a 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -211,6 +211,14 @@ struct flash_info { * bit. Must be used with * SPI_NOR_HAS_LOCK. */ +#define SPI_NOR_XSR_RDY BIT(10) /* + * S3AN flashes have specific opcode to + * read the status register. + * Flags SPI_NOR_XSR_RDY and SPI_S3AN + * use the same bit as one implies the + * other, but we will get rid of + * SPI_S3AN soon. + */ #define SPI_S3AN BIT(10) /* * Xilinx Spartan 3AN In-System Flash * (MFR cannot be used for probing @@ -4798,7 +4806,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, * spi_nor_wait_till_ready(). Xilinx S3AN share MFR * with Atmel spi-nor */ - if (info->flags & SPI_S3AN) + if (info->flags & SPI_NOR_XSR_RDY) nor->flags |= SNOR_F_READY_XSR_RDY; if (info->flags & SPI_NOR_HAS_LOCK) From patchwork Mon Aug 26 12:09:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tudor Ambarus X-Patchwork-Id: 1153153 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=microchip.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="PMfVigNt"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=microchiptechnology.onmicrosoft.com header.i=@microchiptechnology.onmicrosoft.com header.b="pbrkeAJ7"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46H9qr6cgMz9s7T for ; Mon, 26 Aug 2019 22:12:40 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=vntLHfYAi5gvxbf30wrhADwvyAGgOkLJUu/I5BqphAU=; b=PMfVigNtXPpoVa 2tt+WtGL3tNF8Eu4NajZ0leSQV2CEpz+jNho9v9uJlkiqCiXA2X0fXLEdLqdvxQOR7+BFjIp6e52X QmbcaanuXYQPXM6q/b49sXKV0n5hrixpoT7HE0RAIcxtBew9kI3JMotFk8eQnsuFuQildYE04Wz53 KqrPa8ljqDaLJZI4wUFPfFxY5NbD9HQa/AkA7Blut2yMcuEKjebSKJVZ/HILyYmGax8luzf/Q726y qaqg57Ceev1UV4k8dMO/OpWIV3phYLXgP135qnTveBNIkYKOXjF9jCPco/AZFG76q6IqeDiP0Z+di GfLyxTuz7yyGnHLjSLOg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i2DrS-0007sk-Oq; Mon, 26 Aug 2019 12:12:38 +0000 Received: from esa2.microchip.iphmx.com ([68.232.149.84]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i2Do8-0002oS-Rd for linux-mtd@lists.infradead.org; Mon, 26 Aug 2019 12:09:19 +0000 Received-SPF: Pass (esa2.microchip.iphmx.com: domain of Tudor.Ambarus@microchip.com designates 198.175.253.82 as permitted sender) identity=mailfrom; client-ip=198.175.253.82; receiver=esa2.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="Tudor.Ambarus@microchip.com"; x-conformance=spf_only; x-record-type="v=spf1"; x-record-text="v=spf1 mx a:ushub1.microchip.com a:smtpout.microchip.com a:mx1.microchip.iphmx.com a:mx2.microchip.iphmx.com include:servers.mcsv.net include:mktomail.com include:spf.protection.outlook.com ~all" Received-SPF: None (esa2.microchip.iphmx.com: no sender authenticity information available from domain of postmaster@email.microchip.com) identity=helo; client-ip=198.175.253.82; receiver=esa2.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="postmaster@email.microchip.com"; x-conformance=spf_only Authentication-Results: esa2.microchip.iphmx.com; spf=Pass smtp.mailfrom=Tudor.Ambarus@microchip.com; spf=None smtp.helo=postmaster@email.microchip.com; dkim=pass (signature verified) header.i=@microchiptechnology.onmicrosoft.com; dmarc=pass (p=none dis=none) d=microchip.com IronPort-SDR: CiHVrJUU7cmxvsry7h+JLLHsAxpeYzDctQZzi3sXW135Go7GVploil062P6UaKXtGGmZPJXKND /FObsI7rA1+bdaxLvi/0J5UxmKTNAmFXTwgUPnaFRuLHIfucLFeeF1Tomhh5aJKlehCL5dGUrx D3rzvAmqfuB9pyph2CxT296UJmRLIWBE0ja8Zt4MnsXsqFHZAxpS+qinCjknOpyOkIrk42Q0y5 gi3MbzMEOJEr67LTbOIr5hOSdoSf7MdLJi99ZjXDRgxp07UYBrT2qoDXS8vd6UeoAImm7Ul5hh Qqs= X-IronPort-AV: E=Sophos;i="5.64,433,1559545200"; d="scan'208";a="46520791" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 26 Aug 2019 05:09:09 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.87.72) by chn-vm-ex02.mchp-main.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 26 Aug 2019 05:09:07 -0700 Received: from NAM02-BL2-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Mon, 26 Aug 2019 05:09:07 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mbUR453aNfUAxxAKhUGKLXninp46uOvs1raOgD0Vr4Qbs6R1G6bJoGAIEz2xFDKwbs3xLjTzVcsR8yBuS9nY0syLJQxfZ8qSfC31cdUUNWQIqfDigNrLg6Txt5aDJdXuC7RQ8W6afrvvzmbRMZecbP1JoKfzDLTLleA1UYoB+WKX93oqkIcPJ9cW6dFj5bqGE0D2RRkdFdy5BZGo6qb/fbFD5FFcMYt1g7HIhheQrNuqI9XAuf9wzwHiWlIG/ugecExxpWYTr7D5fM9YKO0jvZbx4BTqXWHwiHVoH1MPJoZpPW1JSiyNwVNxrBEEzZyp7gvI3Ic3Nrc3vPwswK3CkA== 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=baMNcFxemh30UesYLRpSxjInG+neJNL1UAEyj/OjFCA=; b=Z8Jp7cK+BobPe6U0jTUFozume/uPCn/+eYWYSczW38T1fXQVXis0vpdsSQSM0ypn2Zt+n129hdZfH10P1KoMBGhtfsGGz5S162IQsfb3cbV74r7moU+epts1vGcp3aPnKBI+CFwYP4gyO/VqwrAyrecI7usQgjdFeH4eUZyciU3++IecgS9UMKOflY0OjJ1CWkDJZ6NZ7SrrSo7shsx8D88MVtKkLe1fJcVGC/yfFjwuei4Y5XLdc2upyuUn+cNs4VnZvD5Lxcm/3dmt0IVHajkXZ0KPcxaVcboASHfHAIxvBweIB+itv1kxe1xragRtsFWj+ZFkkwBDohfG43+zzQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microchip.com; dmarc=pass action=none header.from=microchip.com; dkim=pass header.d=microchip.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microchiptechnology.onmicrosoft.com; s=selector2-microchiptechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=baMNcFxemh30UesYLRpSxjInG+neJNL1UAEyj/OjFCA=; b=pbrkeAJ7JLFFzAV0+026hEBYck+H1KlcmqVcpuvw68Ezys+zvpSDYpmjkGQoClGKsLCcUhxRjzQTK4se0VR/IcEulfUGPNGO96CUU3LdprfmNNq/5mtKAWrUEGt0wVlk82XbZV76uuRHe9pRD7NCfL51LJKRysFwS1ZWIbMFvtg= Received: from MN2PR11MB4448.namprd11.prod.outlook.com (52.135.39.157) by MN2PR11MB3678.namprd11.prod.outlook.com (20.178.252.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.21; Mon, 26 Aug 2019 12:09:07 +0000 Received: from MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5]) by MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5%7]) with mapi id 15.20.2199.021; Mon, 26 Aug 2019 12:09:07 +0000 From: To: , , , , , , Subject: [RESEND PATCH v3 17/20] mtd: spi-nor: Bring flash params init together Thread-Topic: [RESEND PATCH v3 17/20] mtd: spi-nor: Bring flash params init together Thread-Index: AQHVXAcNKsgtTQvdf0Gwo9nlZWqAKQ== Date: Mon, 26 Aug 2019 12:09:03 +0000 Message-ID: <20190826120821.16351-18-tudor.ambarus@microchip.com> References: <20190826120821.16351-1-tudor.ambarus@microchip.com> In-Reply-To: <20190826120821.16351-1-tudor.ambarus@microchip.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1PR09CA0046.eurprd09.prod.outlook.com (2603:10a6:802:28::14) To MN2PR11MB4448.namprd11.prod.outlook.com (2603:10b6:208:193::29) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.9.5 x-originating-ip: [94.177.32.156] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 56300c36-a8f7-407d-318d-08d72a1e2fdf x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:MN2PR11MB3678; x-ms-traffictypediagnostic: MN2PR11MB3678: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:6108; x-forefront-prvs: 01415BB535 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(376002)(396003)(366004)(346002)(39860400002)(136003)(189003)(199004)(186003)(86362001)(305945005)(2906002)(7736002)(2201001)(6486002)(6436002)(6116002)(3846002)(66556008)(66946007)(66476007)(2501003)(66446008)(64756008)(5660300002)(71190400001)(256004)(71200400001)(1076003)(6506007)(386003)(14454004)(107886003)(316002)(99286004)(76176011)(110136005)(52116002)(6666004)(2616005)(476003)(486006)(53936002)(66066001)(8676002)(8936002)(81166006)(6512007)(4326008)(25786009)(36756003)(478600001)(81156014)(102836004)(50226002)(446003)(11346002)(26005); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR11MB3678; H:MN2PR11MB4448.namprd11.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: microchip.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: vdjyBlXYN05ssVtaHf7fJ6rne5xDKiLDvw5KjzhOeHN+hE+BUCcaqain4H96o5gzV4989Fg4rYYQRWJts/REmOvigyjNsIYoyWBK59PNhlAiOzkjJLCo9qLhti87Z71he9QbBF9PF4wEkcrbPP0wrTNpmpU4re7ahf1S8Ko3d7vojJidV7tkjHYyjlChz3jReByqQB2m1KtUifSO3Vq0Bhm4R8WcqGN4/DYRFY42oucxS37XHJOL8mj6Ju6oofXj0GHUOfGTXD7tvV8yjbLYBBW6R799UTzx38paf9Oki3GqFJEZXiBK2FUjORP2R3zU6gpZ3xEPce3Pg+/M0JMX4MSBmsenhIR+H/V8dlclTIrqB6PhCsUop6qPXaEmLLcyb0V81juNejwxKB/o7kxjd8ShP0eCeamLfB8KYrwt1rg= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 56300c36-a8f7-407d-318d-08d72a1e2fdf X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Aug 2019 12:09:03.8845 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: a1wgnCGFe+PsrVaPL2V4AwI+UaV5ZxIt3qxFsKLe52hsydSSh2GpSePY83sfRjz+KntNaSTxT0xoFN/m1pB/dI5YTFd/XS/UsaZqjOIYFJU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB3678 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190826_050912_998544_929DAF5D X-CRM114-Status: UNSURE ( 9.53 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [68.232.149.84 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -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 X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tudor.Ambarus@microchip.com Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Tudor Ambarus Bring all flash parameters default initialization in spi_nor_legacy_params_init(). Signed-off-by: Tudor Ambarus Reviewed-by: Boris Brezillon Reviewed-by: Vignesh Raghavendra --- v3: collect R-b drivers/mtd/spi-nor/spi-nor.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index 2699e999d21a..dcda96a20f6c 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -4453,6 +4453,7 @@ static void spi_nor_info_init_params(struct spi_nor *nor) struct spi_nor_flash_parameter *params = &nor->params; struct spi_nor_erase_map *map = ¶ms->erase_map; const struct flash_info *info = nor->info; + struct device_node *np = spi_nor_get_flash_node(nor); u8 i, erase_mask; /* Initialize legacy flash parameters and settings. */ @@ -4464,18 +4465,25 @@ static void spi_nor_info_init_params(struct spi_nor *nor) params->size = (u64)info->sector_size * info->n_sectors; params->page_size = info->page_size; + if (!(info->flags & SPI_NOR_NO_FR)) { + /* Default to Fast Read for DT and non-DT platform devices. */ + params->hwcaps.mask |= SNOR_HWCAPS_READ_FAST; + + /* Mask out Fast Read if not requested at DT instantiation. */ + if (np && !of_property_read_bool(np, "m25p,fast-read")) + params->hwcaps.mask &= ~SNOR_HWCAPS_READ_FAST; + } + /* (Fast) Read settings. */ params->hwcaps.mask |= SNOR_HWCAPS_READ; spi_nor_set_read_settings(¶ms->reads[SNOR_CMD_READ], 0, 0, SPINOR_OP_READ, SNOR_PROTO_1_1_1); - if (!(info->flags & SPI_NOR_NO_FR)) { - params->hwcaps.mask |= SNOR_HWCAPS_READ_FAST; + if (params->hwcaps.mask & SNOR_HWCAPS_READ_FAST) spi_nor_set_read_settings(¶ms->reads[SNOR_CMD_READ_FAST], 0, 8, SPINOR_OP_READ_FAST, SNOR_PROTO_1_1_1); - } if (info->flags & SPI_NOR_DUAL_READ) { params->hwcaps.mask |= SNOR_HWCAPS_READ_1_1_2; @@ -4864,24 +4872,9 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, nor->page_size = params->page_size; mtd->writebufsize = nor->page_size; - if (np) { - /* If we were instantiated by DT, use it */ - if (of_property_read_bool(np, "m25p,fast-read")) - params->hwcaps.mask |= SNOR_HWCAPS_READ_FAST; - else - params->hwcaps.mask &= ~SNOR_HWCAPS_READ_FAST; - } else { - /* If we weren't instantiated by DT, default to fast-read */ - params->hwcaps.mask |= SNOR_HWCAPS_READ_FAST; - } - if (of_property_read_bool(np, "broken-flash-reset")) nor->flags |= SNOR_F_BROKEN_RESET; - /* Some devices cannot do fast-read, no matter what DT tells us */ - if (info->flags & SPI_NOR_NO_FR) - params->hwcaps.mask &= ~SNOR_HWCAPS_READ_FAST; - /* * Configure the SPI memory: * - select op codes for (Fast) Read, Page Program and Sector Erase. From patchwork Mon Aug 26 12:09:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tudor Ambarus X-Patchwork-Id: 1153155 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=microchip.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="FDM2fOJE"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=microchiptechnology.onmicrosoft.com header.i=@microchiptechnology.onmicrosoft.com header.b="BGQbRv/q"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46H9r72BnSz9s7T for ; Mon, 26 Aug 2019 22:12:55 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=aENPAukrLTGHvFQD/1J35nRZyZNaoN+MrdCB3EHrHB8=; b=FDM2fOJE8PeDJx hTnHVUuwdSqrIPYBZjpmsBI+HSytpMbbvbYOxTQCvIGFIenS5SAFqY72O6d5DeqjqC2JKxLgfNaO0 4csv5oIxfUrup+IzSEOAE0SK1j+nSdHIb5gPvHoxk96u9TZ2zGeLcE2tyFKch4uZSZwKs2kFUwkkV 8pjZ0uQZJtDkVAi4Q66rvPaTFgZcrVY5RLve6bub3sFW/HrywziFOMH5lCKgapqctMZRZmDmvGq3Z 43QW+hJ0XsjcjaVpQG77CKzZC40xFuTqoaAJOZPY4uLVJUNMpaH++QsosxFiXQ193VHgipLfI4nX+ 7Ba5GZtiSBQbN2OoPDkQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i2Drf-00088C-Sf; Mon, 26 Aug 2019 12:12:51 +0000 Received: from esa2.microchip.iphmx.com ([68.232.149.84]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i2DoB-0002er-Pv for linux-mtd@lists.infradead.org; Mon, 26 Aug 2019 12:09:20 +0000 Received-SPF: Pass (esa2.microchip.iphmx.com: domain of Tudor.Ambarus@microchip.com designates 198.175.253.82 as permitted sender) identity=mailfrom; client-ip=198.175.253.82; receiver=esa2.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="Tudor.Ambarus@microchip.com"; x-conformance=spf_only; x-record-type="v=spf1"; x-record-text="v=spf1 mx a:ushub1.microchip.com a:smtpout.microchip.com a:mx1.microchip.iphmx.com a:mx2.microchip.iphmx.com include:servers.mcsv.net include:mktomail.com include:spf.protection.outlook.com ~all" Received-SPF: None (esa2.microchip.iphmx.com: no sender authenticity information available from domain of postmaster@email.microchip.com) identity=helo; client-ip=198.175.253.82; receiver=esa2.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="postmaster@email.microchip.com"; x-conformance=spf_only Authentication-Results: esa2.microchip.iphmx.com; spf=Pass smtp.mailfrom=Tudor.Ambarus@microchip.com; spf=None smtp.helo=postmaster@email.microchip.com; dkim=pass (signature verified) header.i=@microchiptechnology.onmicrosoft.com; dmarc=pass (p=none dis=none) d=microchip.com IronPort-SDR: b2VO+xxIKFb1CuCNtQ0a28mRRQ4CENRjBCiwKiXRVoYQvflenQQ3BOX65rRkjfcHjr+pdBuJmR MIcKl62wGvEQ92lzbduQp+Iudov6o8APhcpVH+fF4Zo/Yg1kmjoLg7GzDAgMvi9+uJbVgIl/MX tuOJn9eEQJLyJ4dm+4ijcuuD35nxwdU3JAFyZyevrMMIcnl2JSJzBCbk+wjO9PszEVEHgnP7r8 wsVRw++65M67vlTC4t+GLLuzqiGxGcVijv1UKj5roDOkCVZDsv/ycXz/NT7yCZT5MAunVp38er iUI= X-IronPort-AV: E=Sophos;i="5.64,433,1559545200"; d="scan'208";a="46520796" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 26 Aug 2019 05:09:09 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.87.72) by chn-vm-ex02.mchp-main.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 26 Aug 2019 05:09:08 -0700 Received: from NAM02-BL2-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Mon, 26 Aug 2019 05:09:08 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mNS2oYdUoEWrjEQ3tEhhQ/rDqqmiIk7okcacacAJspCOi3yYyIvkCum5KknIblW5aiis1M9GwQWuSNVUm7Cav15D4h+JuAjs5l+hUaKlzp4e+STZc3kDogtQ3pOpMd1TlDZPgcd4d+Xh2yqM6fJVz5Woz930PJLhVE6w2lil1jI6NmGFkFetkGwXgRMSG3uxWquxDR7zQ2QR7PzclMudBTrAtTQyGBwT+fzGBd+1VvV6NbXyDgYaC8C1+ozqDMFAaLTQH7lH+l6UnPPF36jTtn1JVLRS1/A5OeZ/DpGoBgKwzdI4C15+hAV01O6JC7T2EU1Emfq89mbbXJEO+FmFGA== 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=teywPRmKxNCHDCqoMd8uKvncvMQgIAjI6tlFv8GhTDU=; b=C7X89nduv/dDjWW7KjmTUNK1ivf8x9gXMhAmAyMNgpPgn6EO07Ic9NkIrtFzlCjz7Pm2DxrEeTsVLtk1lVSULQH2MGdhUG25iQQ5HCfeM0i1A8wQIwaCb149voabUCLhBaSrhWUpKT3JfO58OS8DJu9v9ZNC7aBnQ3QxYjj9Q5CwvAlGQG+DzYfMhd0nDjczRrmlx3oAI1oTkMagIEBxHBUoN1M9SF0ZCpu8Q/35l5d1ZN5qT1WzjUWECUZaCpOYNQEJnAIyqnCmBezelP6OYjJo/1hU5BuBITYFoWpZ2gG642udyz5V4nBgbx7kA6pJHYazjNRr7kLOFptm5QrJZg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microchip.com; dmarc=pass action=none header.from=microchip.com; dkim=pass header.d=microchip.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microchiptechnology.onmicrosoft.com; s=selector2-microchiptechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=teywPRmKxNCHDCqoMd8uKvncvMQgIAjI6tlFv8GhTDU=; b=BGQbRv/qpRnNGpv2yOwlSbo+YpL1svACu+DuPCCUOrvLQiXO41z1ENMYH1J5zgdkyB+VUXyoIJQs86aZKLyizKj0LiLfAUy1uqvaAiiEg6R+yZ7YrZD84oEWZGbLS1w1QHkCIVFOckkhBQVeYzdSmm21yLnC37i9t0V8bkcP+k8= Received: from MN2PR11MB4448.namprd11.prod.outlook.com (52.135.39.157) by MN2PR11MB3678.namprd11.prod.outlook.com (20.178.252.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.21; Mon, 26 Aug 2019 12:09:08 +0000 Received: from MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5]) by MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5%7]) with mapi id 15.20.2199.021; Mon, 26 Aug 2019 12:09:08 +0000 From: To: , , , , , , Subject: [RESEND PATCH v3 18/20] mtd: spi_nor: Introduce spi_nor_set_addr_width() Thread-Topic: [RESEND PATCH v3 18/20] mtd: spi_nor: Introduce spi_nor_set_addr_width() Thread-Index: AQHVXAcO02WZRVSyz024bw8uo4qH9g== Date: Mon, 26 Aug 2019 12:09:05 +0000 Message-ID: <20190826120821.16351-19-tudor.ambarus@microchip.com> References: <20190826120821.16351-1-tudor.ambarus@microchip.com> In-Reply-To: <20190826120821.16351-1-tudor.ambarus@microchip.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1PR09CA0046.eurprd09.prod.outlook.com (2603:10a6:802:28::14) To MN2PR11MB4448.namprd11.prod.outlook.com (2603:10b6:208:193::29) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.9.5 x-originating-ip: [94.177.32.156] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 23377e7b-e457-447f-d426-08d72a1e30f3 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:MN2PR11MB3678; x-ms-traffictypediagnostic: MN2PR11MB3678: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:3044; x-forefront-prvs: 01415BB535 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(376002)(396003)(366004)(346002)(39860400002)(136003)(189003)(199004)(186003)(86362001)(305945005)(2906002)(7736002)(2201001)(6486002)(6436002)(6116002)(3846002)(66556008)(66946007)(66476007)(2501003)(66446008)(64756008)(5660300002)(71190400001)(256004)(71200400001)(1076003)(6506007)(386003)(14454004)(107886003)(316002)(99286004)(76176011)(110136005)(52116002)(6666004)(2616005)(476003)(486006)(53936002)(66066001)(8676002)(8936002)(81166006)(6512007)(4326008)(25786009)(36756003)(478600001)(81156014)(102836004)(50226002)(446003)(11346002)(26005); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR11MB3678; H:MN2PR11MB4448.namprd11.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: microchip.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: cYq+6vIutXNSRxe4vZYEOezs1abEsUpqnZZoegUyPJESMpf9fn/I6lqIBhlpjjUo+TtIq0y3LGS/Eg080yXGnV7nEyk1UGzWfUiDAv81vxz2A2bshs6m8yh8VxaqaRBu5P5N3DTua7C4smqDCH7J6gMaDaW4IR1P9fQQmvaEh8vL7/q5EgTojbMx1q+Pqkp1nAt0iHvUo9vZ43lOQYopPqEUhtKPekd239ES8tHU5GhKLf28MjrWpz1UjcMa9lcTLMiBcCHtrBUUmjl5gFuwtm5kfvsAC+/T5uhmpmySwz3agrfft3X2DsJjt8oTfHufP6Xwz2SQVQV4czZRfSsLtI5gRgiQLNR3HWVq909OW1yvPkPnLfzqtt5tPa+1Lz9pCZoNoGlX+bGzv9jW8HxI3YmOoUu6zHavU6Sr3xbnw48= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 23377e7b-e457-447f-d426-08d72a1e30f3 X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Aug 2019 12:09:05.7734 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: D2Pz4AXKn8vilZDd8euInAzbBH1a6VqpgIm/8fH37H7HQ6sKZzymhlo6zLFroIWccvHRXjEcIOfKpeHOCVLbfk/TX3LQKj1u1uZ9HqKPVQI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB3678 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190826_050915_929359_CC16D141 X-CRM114-Status: GOOD ( 11.03 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [68.232.149.84 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -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 X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tudor.Ambarus@microchip.com Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Tudor Ambarus Parsing of flash parameters were interleaved with setting of the nor addr width. Dedicate a function for setting nor addr width. Signed-off-by: Tudor Ambarus Reviewed-by: Boris Brezillon Reviewed-by: Vignesh Raghavendra --- v3: no changes drivers/mtd/spi-nor/spi-nor.c | 50 ++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index dcda96a20f6c..d13317d1f372 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -4739,6 +4739,33 @@ static const struct flash_info *spi_nor_match_id(const char *name) return NULL; } +static int spi_nor_set_addr_width(struct spi_nor *nor) +{ + if (nor->addr_width) { + /* already configured from SFDP */ + } else if (nor->info->addr_width) { + nor->addr_width = nor->info->addr_width; + } else if (nor->mtd.size > 0x1000000) { + /* enable 4-byte addressing if the device exceeds 16MiB */ + nor->addr_width = 4; + } else { + nor->addr_width = 3; + } + + if (nor->addr_width > SPI_NOR_MAX_ADDR_WIDTH) { + dev_err(nor->dev, "address width is too large: %u\n", + nor->addr_width); + return -EINVAL; + } + + /* Set 4byte opcodes when possible. */ + if (nor->addr_width == 4 && nor->flags & SNOR_F_4B_OPCODES && + !(nor->flags & SNOR_F_HAS_4BAIT)) + spi_nor_set_4byte_opcodes(nor); + + return 0; +} + int spi_nor_scan(struct spi_nor *nor, const char *name, const struct spi_nor_hwcaps *hwcaps) { @@ -4885,29 +4912,12 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, if (ret) return ret; - if (nor->addr_width) { - /* already configured from SFDP */ - } else if (info->addr_width) { - nor->addr_width = info->addr_width; - } else if (mtd->size > 0x1000000) { - /* enable 4-byte addressing if the device exceeds 16MiB */ - nor->addr_width = 4; - } else { - nor->addr_width = 3; - } - if (info->flags & SPI_NOR_4B_OPCODES) nor->flags |= SNOR_F_4B_OPCODES; - if (nor->addr_width == 4 && nor->flags & SNOR_F_4B_OPCODES && - !(nor->flags & SNOR_F_HAS_4BAIT)) - spi_nor_set_4byte_opcodes(nor); - - if (nor->addr_width > SPI_NOR_MAX_ADDR_WIDTH) { - dev_err(dev, "address width is too large: %u\n", - nor->addr_width); - return -EINVAL; - } + ret = spi_nor_set_addr_width(nor); + if (ret) + return ret; /* Send all the required SPI flash commands to initialize device */ ret = spi_nor_init(nor); From patchwork Mon Aug 26 12:09:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tudor Ambarus X-Patchwork-Id: 1153151 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=microchip.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="BHbivlbP"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=microchiptechnology.onmicrosoft.com header.i=@microchiptechnology.onmicrosoft.com header.b="UndrUTp2"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46H9qL2FK2z9s7T for ; Mon, 26 Aug 2019 22:12:14 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=U7BqwiunU7ZyUV6GfHhTK3OU+dzKa4NoAG39icEXMCc=; b=BHbivlbPc7pU9C d6SGKLsH4wsP89EXcfU2CAYdEqnArMOd5vmJexGOc7FeK7a9NZdYpWhDepXRqUE2topbzi/KVpOPO nNacofzGJmst+lNC4e1lpLeG4KBOT4rhMJYXV5iuYcArqH8Yf9xyfUgwERxaczLg6ItEfdsRFkhpt ShoXxT+Q42Yv4+Yu6NvuAmCE5ZnH65w2D7J0mk2IAg1oi+bJF+YzwdvP2eq5DFU4nl2IR5nsyyjFN Tc4qevAX7HyZoCzmKEJjS1WvN+/2J0jB6JJPR3IBBYAsKHhl1H1/dPrJCgnQCirIaA1RslJM9Dixi VL8FRg7zGnm8E6sQYxNw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i2Dr1-0007MF-JJ; Mon, 26 Aug 2019 12:12:11 +0000 Received: from esa5.microchip.iphmx.com ([216.71.150.166]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i2Do8-0002ml-2O for linux-mtd@lists.infradead.org; Mon, 26 Aug 2019 12:09:18 +0000 Received-SPF: Pass (esa5.microchip.iphmx.com: domain of Tudor.Ambarus@microchip.com designates 198.175.253.82 as permitted sender) identity=mailfrom; client-ip=198.175.253.82; receiver=esa5.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="Tudor.Ambarus@microchip.com"; x-conformance=spf_only; x-record-type="v=spf1"; x-record-text="v=spf1 mx a:ushub1.microchip.com a:smtpout.microchip.com a:mx1.microchip.iphmx.com a:mx2.microchip.iphmx.com include:servers.mcsv.net include:mktomail.com include:spf.protection.outlook.com ~all" Received-SPF: None (esa5.microchip.iphmx.com: no sender authenticity information available from domain of postmaster@email.microchip.com) identity=helo; client-ip=198.175.253.82; receiver=esa5.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="postmaster@email.microchip.com"; x-conformance=spf_only Authentication-Results: esa5.microchip.iphmx.com; spf=Pass smtp.mailfrom=Tudor.Ambarus@microchip.com; spf=None smtp.helo=postmaster@email.microchip.com; dkim=pass (signature verified) header.i=@microchiptechnology.onmicrosoft.com; dmarc=pass (p=none dis=none) d=microchip.com IronPort-SDR: BfLMm0CpBFFNHxvKpMzywmsHmK4/VknBBSeV5KCIHA+WSC8gXF9ey6q8elxUrjI0fJZ8+RLcUi dix294OhckcPXkwPGBbmdif8OQL/eIn8T5eu3T5ozXme9RiPxYV3ZoSIVsmdImFTL8Y9BcpbBf HPXBMWK8wqUSGn6jj0wYm2r7VJvXC08GJR15aO3Y8xnncx1i6DaIF8rc1duRwiAGySKyeiW+B1 uCy2MB+BxldqCcInBl/Dz/OV5YehQyUoYjllB3CPDV5dWeEiNC6dWij9wcy2W0+Bi1K0q+eDIP 9lg= X-IronPort-AV: E=Sophos;i="5.64,433,1559545200"; d="scan'208";a="44989697" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa5.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 26 Aug 2019 05:09:10 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 26 Aug 2019 05:09:09 -0700 Received: from NAM02-BL2-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Mon, 26 Aug 2019 05:09:08 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kpx06c0Cw613h/pNsSQOqwR6VeAV3wXIhU0b+P0s5HBMc7PvGm3PGjyIi+QjpRXo7/6Rlv4BM+k4kuM2rgseMQ7HjCZVTQy6sUcT+KQu4UcmsmzK20WUMqfIvOL0T1vhPqDVOZDZz8tLx+TQ9nwXlAcJ4WXNvTo4pW02JWlgp0O60eVzWH785C7+eKAVBXwxW6wvDYb29R9uwS6CRN1uEYH4JuuVhoA9pB4EkCevW16ocM1T86YEIhabSWCf/RobHKyAy26DBNhOvpQMNnK8xjiQzXdV1zeoNbgpjciqqf/fR6id/Oj8mqJ++4vWFcvwUZkV/f+mnxBxt/wii1UBKA== 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=Tq2hOpJWptLTtqVywO/fAs3puBGR+PG/1p698ZvjECI=; b=ZU2V1v/G4DBN/HL7E7iYeBf/9RDMqlJAOHOQ14ST4hMn7IRIjOv+Is03UUkQypEcQUszCDDDeUXlIt1hkqnsakMQaL5KwB1u99k9LiEkPX12H0qz/75ZOMacOEusIqJYsbpr+NpZMTmcQxZ1EOuvp05Oz618PWMZ3RKOmPbNhSsMFtUeNTZRB82xnX0zy6nx2YDcpk+vGYwNv3o1572JT7CR7/Y8oYDSsmzEkrj/7L//fHDj6xf9UYWrVQ42miAx7PJXF72NE9nXEnb4hW9l346A/zMNxobxBVBHYEf5ShLaHCksDJoHlUJxY+dF9kduhdeSwRblICbwFFW2CKuBzQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microchip.com; dmarc=pass action=none header.from=microchip.com; dkim=pass header.d=microchip.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microchiptechnology.onmicrosoft.com; s=selector2-microchiptechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Tq2hOpJWptLTtqVywO/fAs3puBGR+PG/1p698ZvjECI=; b=UndrUTp2KXe2/AaCfD+tTyQsrFYEneJpUMK3j/s3VKR4HvihkpCMvWs0CYW9DxqQS+Z9ge8asbL6Nir8Sz0Mx5bi+R2Mggpk0eP1Bj2Fhn/9yoZALIVfY1zmBkX4RvPymxzkeiNoFXRw9KdB4EM0v60kfjAn3CUKOiUZWwEITj8= Received: from MN2PR11MB4448.namprd11.prod.outlook.com (52.135.39.157) by MN2PR11MB3678.namprd11.prod.outlook.com (20.178.252.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.21; Mon, 26 Aug 2019 12:09:09 +0000 Received: from MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5]) by MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5%7]) with mapi id 15.20.2199.021; Mon, 26 Aug 2019 12:09:09 +0000 From: To: , , , , , , Subject: [RESEND PATCH v3 19/20] mtd: spi-nor: Introduce spi_nor_get_flash_info() Thread-Topic: [RESEND PATCH v3 19/20] mtd: spi-nor: Introduce spi_nor_get_flash_info() Thread-Index: AQHVXAcPi3T8X+P9M0ynbxQOIh0BzA== Date: Mon, 26 Aug 2019 12:09:07 +0000 Message-ID: <20190826120821.16351-20-tudor.ambarus@microchip.com> References: <20190826120821.16351-1-tudor.ambarus@microchip.com> In-Reply-To: <20190826120821.16351-1-tudor.ambarus@microchip.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1PR09CA0046.eurprd09.prod.outlook.com (2603:10a6:802:28::14) To MN2PR11MB4448.namprd11.prod.outlook.com (2603:10b6:208:193::29) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.9.5 x-originating-ip: [94.177.32.156] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 0fdda10c-93c0-4daf-9bda-08d72a1e3223 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:MN2PR11MB3678; x-ms-traffictypediagnostic: MN2PR11MB3678: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:1824; x-forefront-prvs: 01415BB535 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(376002)(396003)(366004)(346002)(39860400002)(136003)(189003)(52314003)(199004)(186003)(86362001)(305945005)(2906002)(7736002)(2201001)(6486002)(6436002)(6116002)(3846002)(66556008)(66946007)(66476007)(2501003)(66446008)(64756008)(5660300002)(71190400001)(14444005)(256004)(71200400001)(1076003)(6506007)(386003)(14454004)(107886003)(316002)(99286004)(76176011)(110136005)(52116002)(2616005)(476003)(486006)(53936002)(66066001)(8676002)(8936002)(81166006)(6512007)(4326008)(25786009)(36756003)(478600001)(81156014)(102836004)(50226002)(446003)(11346002)(26005); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR11MB3678; H:MN2PR11MB4448.namprd11.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: microchip.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: yaTIfTFWyG6lgNytlVh6cgjVbAHjhYvq37rhYUp4oiHCS5T8IVr6uY3Ib0wZol2XYYhKcJvLdx5+5nVm4KNCylecEQEXfyLZQ+gm3Rcn/mYZg5WbWnP/OvPKJvr0Njkje5fRavXQz90Nep/hmMsbuKXFzGmnbzIbyILywTk/r0t38MAgMaE23jZdtyhnzH87XZuFMCZ7rR/zH+1g8DrKUjfAW/dtQW1rrcFn3B417DWnnXtvfUYxQTU0mWSd/24ANuzN/reUCc3iX3zZhyJQXRiLgI5GgedStndZS6Aan3Xq2JDtgvsOcZBtm5mLJ02vnNYQ/EjR5rgshuukiL+x1Pi/duEM/p125Z5H08C1R61qgV5/FPw11nfeEqOGSBM+6F6h83sWbBEJjop07YXp9JiZk4lkuWNpAZgLV4d6jcI= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 0fdda10c-93c0-4daf-9bda-08d72a1e3223 X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Aug 2019 12:09:07.6883 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 930zTI0U1seAQ2V+GCsak5DnLtLHsubZOG7tYtrS6LEb+g+Ygeq3tgN4JuM8h/DqqQE9wnxsKlRlH+VhJxH9KceNFgdwFcxuVKkjoBueOTM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB3678 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190826_050912_360990_0DEF929A X-CRM114-Status: GOOD ( 10.55 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [216.71.150.166 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -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 X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tudor.Ambarus@microchip.com Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Tudor Ambarus Dedicate a function for getting the pointer to the flash_info const struct. Trim a bit the spi_nor_scan() huge function. Signed-off-by: Tudor Ambarus Reviewed-by: Boris Brezillon Reviewed-by: Vignesh Raghavendra --- v3: no changes drivers/mtd/spi-nor/spi-nor.c | 76 +++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 32 deletions(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index d13317d1f372..ec70b58294ec 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -4766,10 +4766,50 @@ static int spi_nor_set_addr_width(struct spi_nor *nor) return 0; } +static const struct flash_info *spi_nor_get_flash_info(struct spi_nor *nor, + const char *name) +{ + const struct flash_info *info = NULL; + + if (name) + info = spi_nor_match_id(name); + /* Try to auto-detect if chip name wasn't specified or not found */ + if (!info) + info = spi_nor_read_id(nor); + if (IS_ERR_OR_NULL(info)) + return ERR_PTR(-ENOENT); + + /* + * If caller has specified name of flash model that can normally be + * detected using JEDEC, let's verify it. + */ + if (name && info->id_len) { + const struct flash_info *jinfo; + + jinfo = spi_nor_read_id(nor); + if (IS_ERR(jinfo)) { + return jinfo; + } else if (jinfo != info) { + /* + * JEDEC knows better, so overwrite platform ID. We + * can't trust partitions any longer, but we'll let + * mtd apply them anyway, since some partitions may be + * marked read-only, and we don't want to lose that + * information, even if it's not 100% accurate. + */ + dev_warn(nor->dev, "found %s, expected %s\n", + jinfo->name, info->name); + info = jinfo; + } + } + + return info; +} + int spi_nor_scan(struct spi_nor *nor, const char *name, const struct spi_nor_hwcaps *hwcaps) { - const struct flash_info *info = NULL; + const struct flash_info *info; struct device *dev = nor->dev; struct mtd_info *mtd = &nor->mtd; struct device_node *np = spi_nor_get_flash_node(nor); @@ -4800,37 +4840,9 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, if (!nor->bouncebuf) return -ENOMEM; - if (name) - info = spi_nor_match_id(name); - /* Try to auto-detect if chip name wasn't specified or not found */ - if (!info) - info = spi_nor_read_id(nor); - if (IS_ERR_OR_NULL(info)) - return -ENOENT; - - /* - * If caller has specified name of flash model that can normally be - * detected using JEDEC, let's verify it. - */ - if (name && info->id_len) { - const struct flash_info *jinfo; - - jinfo = spi_nor_read_id(nor); - if (IS_ERR(jinfo)) { - return PTR_ERR(jinfo); - } else if (jinfo != info) { - /* - * JEDEC knows better, so overwrite platform ID. We - * can't trust partitions any longer, but we'll let - * mtd apply them anyway, since some partitions may be - * marked read-only, and we don't want to lose that - * information, even if it's not 100% accurate. - */ - dev_warn(dev, "found %s, expected %s\n", - jinfo->name, info->name); - info = jinfo; - } - } + info = spi_nor_get_flash_info(nor, name); + if (IS_ERR(info)) + return PTR_ERR(info); nor->info = info; From patchwork Mon Aug 26 12:09:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tudor Ambarus X-Patchwork-Id: 1153156 X-Patchwork-Delegate: tudor.ambarus@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=microchip.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="SbsN61Ua"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=microchiptechnology.onmicrosoft.com header.i=@microchiptechnology.onmicrosoft.com header.b="NdI7+QJ8"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46H9rZ6RT3z9s7T for ; Mon, 26 Aug 2019 22:13:18 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=BYU4aT3byVCHBUk4u8BdRexgHXLRAA6bAdWwgrA374g=; b=SbsN61UaUEVR6D il8X7owPRNS/sKYA5Dp4mQOBTbQ9pqsYqk5F6LpvCtbKKFCAiqGNa74cmnAMCVFg+kmVldWT2Cvre tMLNY+StqbzM8xlgt/2Dwm7hFLKE3G4ke70Gi7sQeAvHB/LDOu6nQ7X0EKoY3w7fSg447Mth4O78Y cofXz2t84Cer6o+pirTyeieujIukpsfCCt3T+inDBn5yfU3MzP/c+CBGs8Q+DviQ6tcjWrNlK2TJO lwTjj3nb4Jtbxf8O/xeGEt3vqnQgSQc3o9XdIqpNjm/RSE2Y+kppNFOlHqnw7xUxfrcDuE75yOhMZ dxNvuQFq/AJOAyJFkU4w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i2Drs-0008MI-3X; Mon, 26 Aug 2019 12:13:04 +0000 Received: from esa2.microchip.iphmx.com ([68.232.149.84]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i2DoC-0002sM-CJ for linux-mtd@lists.infradead.org; Mon, 26 Aug 2019 12:09:24 +0000 Received-SPF: Pass (esa2.microchip.iphmx.com: domain of Tudor.Ambarus@microchip.com designates 198.175.253.82 as permitted sender) identity=mailfrom; client-ip=198.175.253.82; receiver=esa2.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="Tudor.Ambarus@microchip.com"; x-conformance=spf_only; x-record-type="v=spf1"; x-record-text="v=spf1 mx a:ushub1.microchip.com a:smtpout.microchip.com a:mx1.microchip.iphmx.com a:mx2.microchip.iphmx.com include:servers.mcsv.net include:mktomail.com include:spf.protection.outlook.com ~all" Received-SPF: None (esa2.microchip.iphmx.com: no sender authenticity information available from domain of postmaster@email.microchip.com) identity=helo; client-ip=198.175.253.82; receiver=esa2.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="postmaster@email.microchip.com"; x-conformance=spf_only Authentication-Results: esa2.microchip.iphmx.com; spf=Pass smtp.mailfrom=Tudor.Ambarus@microchip.com; spf=None smtp.helo=postmaster@email.microchip.com; dkim=pass (signature verified) header.i=@microchiptechnology.onmicrosoft.com; dmarc=pass (p=none dis=none) d=microchip.com IronPort-SDR: Q67+8tPMebLZsAjoPFwtM1yAOabWw4J0CX8GhWicnNJrKqGYkbMRIDkvUlC7HkPcgdTBfGUQv/ 03FTryggOeYKvTqM/BJ9qvnOPZUD1hI69GFFdqzlBD9E+GX9ba3Hr97RG9FeSZgIIksCQBQf7U 24V6WwjG2H1o9xJ37kvk7ML+pK3vSVLg3766AGpAxvMzluv9PXeRs7psx/pfA82ICVKUP1Oa94 5VPZT/VcydrU0PMxWLFLL/31kO20D5d34vC8gVvF+HBdMoCUNah1TMcdess8Hwz+rvrZMTpaNe v7I= X-IronPort-AV: E=Sophos;i="5.64,433,1559545200"; d="scan'208";a="46520810" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 26 Aug 2019 05:09:11 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.87.72) by chn-vm-ex02.mchp-main.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 26 Aug 2019 05:09:10 -0700 Received: from NAM02-BL2-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Mon, 26 Aug 2019 05:09:10 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bcxKWlG1/mdzv2TL4K/OEXJ469/fqrF4h5/o7Ps330T0sIwtgtz48s96sIqyk3Hm2qvq0vzCPsmLr+KbX3nkwbJr+S3YEoIiwqOYvmtDtU1JvcRp79grfeBI1y4T0zfbpPpydjIe5Yalr1tltWucV6AEFoCAfn8lqwQbSMca+env/mghuYB+kMPxjm39PijWTsD3YTdRvd2KH1COFTPU71+4Zh9tv2nvEN1j5VXwj3CRy8zmox39FFLxPGP6IxwvaAOMjcTyEb/zbHStUlFj0TRnf1okxNlt+3Xp7USaFuaSLWXvNo4MetNSF2bqxM9qjyuVv8j11vnrjiPEC8kC9A== 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=br0Zm+GNiKx2v7OTSTyHjSEIqWarxg1BOxiPf4PRPT8=; b=OJVUo2naOddRDpIFbGpGEajQsTlMQEyXJfTOjHTRXTIHJZ+c53ydFUe0gbta7uwV6zgCQMrpVt2Mcf0siKnl+XzCdp1FmTWuDgDg2x0QgmKgbgUXYEF1SFZKkooM+Mg/en8wmrEqzYsRWqW7jrMjgoOTw73c9SBGriorM6bu5/iCIYbPg4OROLxMHAmZrD0QY4+TCMr0jRRxmUut8EmdaBNbgBCLJD7NPDTfOxwMVwonCPkWK7wyaG7N73yPg4i0ailPO+Rh61rGSV4PaN0qFw/lb92R7o1keiwEEJXIERAqk5/yqNi9U4jjxu9+LjICSf7sLzG2bkvNbW/gIi+RFQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microchip.com; dmarc=pass action=none header.from=microchip.com; dkim=pass header.d=microchip.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microchiptechnology.onmicrosoft.com; s=selector2-microchiptechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=br0Zm+GNiKx2v7OTSTyHjSEIqWarxg1BOxiPf4PRPT8=; b=NdI7+QJ8r4llkbao1NlheYIb7BXACyi3xKi3E4uRjuBys9AHUqVPhLsBgTd4hP/oBSiljGhGIYjIXt+PA3NpWgMOnT4I1jRgQADudS7X2ZB2PdECABw/Z9v5C5pf2vw4bVZfj60F305qgUkwpW/ZqF5liCzJnN/hCXVdcfHfaaY= Received: from MN2PR11MB4448.namprd11.prod.outlook.com (52.135.39.157) by MN2PR11MB3678.namprd11.prod.outlook.com (20.178.252.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.21; Mon, 26 Aug 2019 12:09:09 +0000 Received: from MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5]) by MN2PR11MB4448.namprd11.prod.outlook.com ([fe80::70c3:e929:4da2:60a5%7]) with mapi id 15.20.2199.021; Mon, 26 Aug 2019 12:09:09 +0000 From: To: , , , , , , Subject: [RESEND RFC PATCH v3 20/20] mtd: spi-nor: Rework the disabling of block write protection Thread-Topic: [RESEND RFC PATCH v3 20/20] mtd: spi-nor: Rework the disabling of block write protection Thread-Index: AQHVXAcQinhjg2xtc0ydVZ7nzkNNbA== Date: Mon, 26 Aug 2019 12:09:09 +0000 Message-ID: <20190826120821.16351-21-tudor.ambarus@microchip.com> References: <20190826120821.16351-1-tudor.ambarus@microchip.com> In-Reply-To: <20190826120821.16351-1-tudor.ambarus@microchip.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1PR09CA0046.eurprd09.prod.outlook.com (2603:10a6:802:28::14) To MN2PR11MB4448.namprd11.prod.outlook.com (2603:10b6:208:193::29) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.9.5 x-originating-ip: [94.177.32.156] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: bf0993e8-f9b5-47a0-e61d-08d72a1e334d x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:MN2PR11MB3678; x-ms-traffictypediagnostic: MN2PR11MB3678: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8882; x-forefront-prvs: 01415BB535 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(376002)(396003)(366004)(346002)(39860400002)(136003)(189003)(199004)(186003)(86362001)(305945005)(2906002)(7736002)(2201001)(6486002)(6436002)(6116002)(3846002)(66556008)(30864003)(66946007)(66476007)(2501003)(66446008)(64756008)(5660300002)(71190400001)(14444005)(256004)(71200400001)(1076003)(6506007)(386003)(14454004)(107886003)(316002)(99286004)(76176011)(110136005)(52116002)(2616005)(476003)(486006)(53936002)(66066001)(8676002)(8936002)(81166006)(53946003)(6512007)(4326008)(25786009)(36756003)(478600001)(81156014)(102836004)(50226002)(446003)(11346002)(26005); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR11MB3678; H:MN2PR11MB4448.namprd11.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: microchip.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: np2oSG/CMER08nhl5qDhl617PMT5qRvDVTKyfFMOpkN+R4ULwJtEy81pAx2HwyQN7BzyY/Dvx/acXC3GKJAeh6Qr6Vy9I3swP0GuUqnLucJ8KWSbX2EEo/qmlkivkLODxCXs0f31ByaMfvlylri80t2FkusFY8fFPeT94g9wv3QlRTN6oLen4tgoCHC9KmVk+SI8DdXDICfJWYc1w6KM6mDxuP+0KymGm+YsSFs7LJZMOiohIuWaNt2liqwRKVq2uc8HVzpvVv2Ee4yhWba9aBkOp5oIBQxEcQG4c90mVgznCNluT9YwYFxG1GMH6DbpIcZY2ffcQ1+SxU0Q7YyPpMJUBQK1XDES4vMGtUoszId3XG94aoYA9rRLKY+ogr06PYMij10bSHOwr9NQea/tBk2MURyD00zGzfAZ11lo/mU= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: bf0993e8-f9b5-47a0-e61d-08d72a1e334d X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Aug 2019 12:09:09.6431 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 2ImViZunqkpLrlyff56TaClsW6k5t/rS9/Ue39u8LsRJRJ+zayQO6cCQdW9OnopJx2biNdPeYKX21du5g2GQK22l9lAQZ0z021er7m/StmU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB3678 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190826_050916_552418_37E06464 X-CRM114-Status: GOOD ( 19.58 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [68.232.149.84 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -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 X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tudor.Ambarus@microchip.com Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Tudor Ambarus spi_nor_unlock() unlocks blocks of memory or the entire flash memory array, if requested. clear_sr_bp() unlocks the entire flash memory array at boot time. This calls for some unification, clear_sr_bp() is just an optimization for the case when the unlock request covers the entire flash size. Merge the clear_sr_bp() and stm_lock/unlock logic and introduce spi_nor_unlock_all(), which makes an unlock request that covers the entire flash size. Get rid of the MFR handling and implement specific manufacturer default_init() fixup hooks. Move write_sr_cr() to avoid to add a forward declaration. Prefix new function with 'spi_nor_'. Note that this changes a bit the logic for the SNOR_MFR_ATMEL and SNOR_MFR_INTEL cases. Before this patch, the Atmel and Intel chips did not set the locking ops, but unlocked the entire flash at boot time, while now they are setting the locking ops to stm_locking_ops. This should work, since the the disable of the block protection at the boot time used the same Status Register bits to unlock the flash, as in the stm_locking_ops case. In future, we should probably add new hooks to 'struct spi_nor_flash_parameter' to describe how to interact with the Status and Configuration Registers in the form of: nor->params.ops->read_sr nor->params.ops->write_sr nor->params.ops->read_cr nor->params.ops->write_sr We can retrieve this info starting with JESD216 revB, by checking the 15th DWORD of Basic Flash Parameter Table, or with later revisions of the standard, by parsing the "Status, Control and Configuration Register Map for SPI Memory Devices". Suggested-by: Boris Brezillon Signed-off-by: Tudor Ambarus Reviewed-by: Boris Brezillon --- v3: new patch drivers/mtd/spi-nor/spi-nor.c | 337 +++++++++++++++++++++++------------------- include/linux/mtd/spi-nor.h | 4 +- 2 files changed, 185 insertions(+), 156 deletions(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index ec70b58294ec..01d4051510b6 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -1320,8 +1320,63 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr) return ret; } -/* Write status register and ensure bits in mask match written values */ -static int write_sr_and_check(struct spi_nor *nor, u8 status_new, u8 mask) +/* + * write_sr_cr() - Write the Status Register and Configuration Register. + * @nor: pointer to a 'struct spi_nor'. + * status_new: byte value to be written to the Status Register. + * mask: mask with which to check the written values. + * + * Write Status Register and Configuration Register with 2 bytes. The first + * byte will be written to the status register, while the second byte will be + * written to the configuration register. + * + * Return: 0 on success, -errno otherwise. + */ +static int write_sr_cr(struct spi_nor *nor, u8 *sr_cr) +{ + int ret; + + write_enable(nor); + + if (nor->spimem) { + struct spi_mem_op op = + SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_WRSR, 1), + SPI_MEM_OP_NO_ADDR, + SPI_MEM_OP_NO_DUMMY, + SPI_MEM_OP_DATA_OUT(2, sr_cr, 1)); + + ret = spi_mem_exec_op(nor->spimem, &op); + } else { + ret = nor->write_reg(nor, SPINOR_OP_WRSR, sr_cr, 2); + } + + if (ret < 0) { + dev_err(nor->dev, + "error while writing configuration register\n"); + return -EINVAL; + } + + ret = spi_nor_wait_till_ready(nor); + if (ret) { + dev_err(nor->dev, + "timeout while writing configuration register\n"); + return ret; + } + + return 0; +} + +/** + * spi_nor_write_sr1_and_check() - Write one byte to the Status Register and + * ensure the bits in the mask match the written values. + * @nor: pointer to a 'struct spi_nor'. + * status_new: byte value to be written to the Status Register. + * mask: mask with which to check the written values. + * + * Return: 0 on success, -errno otherwise. + */ +static int spi_nor_write_sr1_and_check(struct spi_nor *nor, u8 status_new, + u8 mask) { int ret; @@ -1341,6 +1396,88 @@ static int write_sr_and_check(struct spi_nor *nor, u8 status_new, u8 mask) return ((ret & mask) != (status_new & mask)) ? -EIO : 0; } +/** + * spi_nor_write_sr_cr_and_check() - Write the Status Register and + * Configuration Register and ensure the bits in the mask match the written + * values. + * @nor: pointer to a 'struct spi_nor'. + * status_new: byte value to be written to the Status Register. + * mask: mask with which to check the written values. + * + * The Configuration Register is written only when it has the Quad Enable (QE) + * bit set to one. When QE bit is set to one, only the Write Status (01h) + * command with two data bytes may be used, so both the Status and + * Configuration registers will be written. + * + * Return: 0 on success, -errno otherwise. + */ +static int spi_nor_write_sr_cr_and_check(struct spi_nor *nor, u8 status_new, + u8 mask) +{ + int ret; + u8 *sr_cr = nor->bouncebuf; + + /* Check current Quad Enable bit value. */ + ret = read_cr(nor); + if (ret < 0) + return ret; + + /* + * If the Quad Enable bit is zero, use the Write Status (01h) command + * with one data byte. + */ + if (!(ret & CR_QUAD_EN_SPAN)) + return spi_nor_write_sr1_and_check(nor, status_new, mask); + + /* + * When the configuration register Quad Enable bit is one, only the + * Write Status (01h) command with two data bytes may be used. + * + */ + sr_cr[0] = status_new; + sr_cr[1] = ret; + + ret = write_sr_cr(nor, sr_cr); + if (ret) { + dev_err(nor->dev, "16-bit write register failed\n"); + return ret; + } + + ret = read_sr(nor); + if (ret < 0) + return ret; + + if ((ret & mask) != (status_new & mask)) + return -EIO; + + ret = read_cr(nor); + if (ret < 0) + return ret; + + if (ret != sr_cr[1]) + return -EIO; + + return 0; +} + +/** + * spi_nor_write_sr_and_check() - Write the Status Register and ensure the bits + * in the mask match the written values. + * @nor: pointer to a 'struct spi_nor'. + * status_new: byte value to be written to the Status Register. + * mask: mask with which to check the written values. + * + * Return: 0 on success, -errno otherwise. + */ +static int spi_nor_write_sr_and_check(struct spi_nor *nor, u8 status_new, + u8 mask) +{ + if (nor->flags == SNOR_F_HAS_16BIT_SR) + return spi_nor_write_sr_cr_and_check(nor, status_new, mask); + + return spi_nor_write_sr1_and_check(nor, status_new, mask); +} + static void stm_get_locked_range(struct spi_nor *nor, u8 sr, loff_t *ofs, uint64_t *len) { @@ -1502,7 +1639,7 @@ static int stm_lock(struct spi_nor *nor, loff_t ofs, uint64_t len) if ((status_new & mask) < (status_old & mask)) return -EINVAL; - return write_sr_and_check(nor, status_new, mask); + return spi_nor_write_sr_and_check(nor, status_new, mask); } /* @@ -1585,7 +1722,7 @@ static int stm_unlock(struct spi_nor *nor, loff_t ofs, uint64_t len) if ((status_new & mask) > (status_old & mask)) return -EINVAL; - return write_sr_and_check(nor, status_new, mask); + return spi_nor_write_sr_and_check(nor, status_new, mask); } /* @@ -1657,46 +1794,6 @@ static int spi_nor_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len) return ret; } -/* - * Write status Register and configuration register with 2 bytes - * The first byte will be written to the status register, while the - * second byte will be written to the configuration register. - * Return negative if error occurred. - */ -static int write_sr_cr(struct spi_nor *nor, u8 *sr_cr) -{ - int ret; - - write_enable(nor); - - if (nor->spimem) { - struct spi_mem_op op = - SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_WRSR, 1), - SPI_MEM_OP_NO_ADDR, - SPI_MEM_OP_NO_DUMMY, - SPI_MEM_OP_DATA_OUT(2, sr_cr, 1)); - - ret = spi_mem_exec_op(nor->spimem, &op); - } else { - ret = nor->write_reg(nor, SPINOR_OP_WRSR, sr_cr, 2); - } - - if (ret < 0) { - dev_err(nor->dev, - "error while writing configuration register\n"); - return -EINVAL; - } - - ret = spi_nor_wait_till_ready(nor); - if (ret) { - dev_err(nor->dev, - "timeout while writing configuration register\n"); - return ret; - } - - return 0; -} - /** * macronix_quad_enable() - set QE bit in Status Register. * @nor: pointer to a 'struct spi_nor' @@ -1942,95 +2039,6 @@ static int sr2_bit7_quad_enable(struct spi_nor *nor) return 0; } -/** - * spi_nor_clear_sr_bp() - clear the Status Register Block Protection bits. - * @nor: pointer to a 'struct spi_nor' - * - * Read-modify-write function that clears the Block Protection bits from the - * Status Register without affecting other bits. - * - * Return: 0 on success, -errno otherwise. - */ -static int spi_nor_clear_sr_bp(struct spi_nor *nor) -{ - int ret; - u8 mask = SR_BP2 | SR_BP1 | SR_BP0; - - ret = read_sr(nor); - if (ret < 0) { - dev_err(nor->dev, "error while reading status register\n"); - return ret; - } - - write_enable(nor); - - ret = write_sr(nor, ret & ~mask); - if (ret) { - dev_err(nor->dev, "write to status register failed\n"); - return ret; - } - - ret = spi_nor_wait_till_ready(nor); - if (ret) - dev_err(nor->dev, "timeout while writing status register\n"); - return ret; -} - -/** - * spi_nor_spansion_clear_sr_bp() - clear the Status Register Block Protection - * bits on spansion flashes. - * @nor: pointer to a 'struct spi_nor' - * - * Read-modify-write function that clears the Block Protection bits from the - * Status Register without affecting other bits. The function is tightly - * coupled with the spansion_quad_enable() function. Both assume that the Write - * Register with 16 bits, together with the Read Configuration Register (35h) - * instructions are supported. - * - * Return: 0 on success, -errno otherwise. - */ -static int spi_nor_spansion_clear_sr_bp(struct spi_nor *nor) -{ - int ret; - u8 mask = SR_BP2 | SR_BP1 | SR_BP0; - u8 *sr_cr = nor->bouncebuf; - - /* Check current Quad Enable bit value. */ - ret = read_cr(nor); - if (ret < 0) { - dev_err(nor->dev, - "error while reading configuration register\n"); - return ret; - } - - /* - * When the configuration register Quad Enable bit is one, only the - * Write Status (01h) command with two data bytes may be used. - */ - if (ret & CR_QUAD_EN_SPAN) { - sr_cr[1] = ret; - - ret = read_sr(nor); - if (ret < 0) { - dev_err(nor->dev, - "error while reading status register\n"); - return ret; - } - sr_cr[0] = ret & ~mask; - - ret = write_sr_cr(nor, sr_cr); - if (ret) - dev_err(nor->dev, "16-bit write register failed\n"); - return ret; - } - - /* - * If the Quad Enable bit is zero, use the Write Status (01h) command - * with one data byte. - */ - return spi_nor_clear_sr_bp(nor); -} - /* Used when the "_ext_id" is two bytes at most */ #define INFO(_jedec_id, _ext_id, _sector_size, _n_sectors, _flags) \ .id = { \ @@ -4373,6 +4381,16 @@ static int spi_nor_setup(struct spi_nor *nor, return nor->params.setup(nor, hwcaps); } +static void atmel_set_default_init(struct spi_nor *nor) +{ + nor->flags = SNOR_F_HAS_LOCK; +} + +static void intel_set_default_init(struct spi_nor *nor) +{ + nor->flags = SNOR_F_HAS_LOCK; +} + static void macronix_set_default_init(struct spi_nor *nor) { nor->params.quad_enable = macronix_quad_enable; @@ -4400,6 +4418,14 @@ static void spi_nor_manufacturer_init_params(struct spi_nor *nor) { /* Init flash parameters based on MFR */ switch (JEDEC_MFR(nor->info)) { + case SNOR_MFR_ATMEL: + atmel_set_default_init(nor); + break; + + case SNOR_MFR_INTEL: + intel_set_default_init(nor); + break; + case SNOR_MFR_MACRONIX: macronix_set_default_init(nor); break; @@ -4595,6 +4621,9 @@ static void spi_nor_late_init_params(struct spi_nor *nor) */ if (nor->flags & SNOR_F_HAS_LOCK && !nor->params.locking_ops) nor->params.locking_ops = &stm_locking_ops; + + if (nor->params.quad_enable == spansion_quad_enable) + nor->flags |= SNOR_F_HAS_16BIT_SR; } /** @@ -4667,20 +4696,32 @@ static int spi_nor_quad_enable(struct spi_nor *nor) return nor->params.quad_enable(nor); } +/** + * spi_nor_unlock_all() - Unlocks the entire flash memory array. + * @nor: pointer to a 'struct spi_nor' + * + * Some SPI NOR flashes are write protected by default after a power-on reset + * cycle, in order to avoid inadvertent writes during power-up. Backward + * compatibility imposes to unlock the entire flash memory array at power-up + * by default. + */ +static int spi_nor_unlock_all(struct spi_nor *nor) +{ + if (nor->flags & SNOR_F_HAS_LOCK) + return spi_nor_unlock(&nor->mtd, 0, nor->params.size); + + return 0; +} + static int spi_nor_init(struct spi_nor *nor) { int err; - if (nor->clear_sr_bp) { - if (nor->params.quad_enable == spansion_quad_enable) - nor->clear_sr_bp = spi_nor_spansion_clear_sr_bp; - - err = nor->clear_sr_bp(nor); - if (err) { - dev_err(nor->dev, - "fail to clear block protection bits\n"); - return err; - } + err = spi_nor_unlock_all(nor); + if (err) { + dev_err(nor->dev, + "Failed to unlock the entire flash memory array\n"); + return err; } err = spi_nor_quad_enable(nor); @@ -4859,16 +4900,6 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, if (info->flags & SPI_NOR_HAS_LOCK) nor->flags |= SNOR_F_HAS_LOCK; - /* - * Atmel, SST, Intel/Numonyx, and others serial NOR tend to power up - * with the software protection bits set. - */ - if (JEDEC_MFR(nor->info) == SNOR_MFR_ATMEL || - JEDEC_MFR(nor->info) == SNOR_MFR_INTEL || - JEDEC_MFR(nor->info) == SNOR_MFR_SST || - nor->info->flags & SPI_NOR_HAS_LOCK) - nor->clear_sr_bp = spi_nor_clear_sr_bp; - /* Init flash parameters based on flash_info struct and SFDP */ spi_nor_init_params(nor); diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h index fc0b4b19c900..d7506dccb7da 100644 --- a/include/linux/mtd/spi-nor.h +++ b/include/linux/mtd/spi-nor.h @@ -243,6 +243,7 @@ enum spi_nor_option_flags { SNOR_F_4B_OPCODES = BIT(6), SNOR_F_HAS_4BAIT = BIT(7), SNOR_F_HAS_LOCK = BIT(8), + SNOR_F_HAS_16BIT_SR = BIT(9), }; /** @@ -560,8 +561,6 @@ struct flash_info; * @erase: [DRIVER-SPECIFIC] erase a sector of the SPI NOR * at the offset @offs; if not provided by the driver, * spi-nor will send the erase opcode via write_reg() - * @clear_sr_bp: [FLASH-SPECIFIC] clears the Block Protection Bits from - * the SPI NOR Status Register. * @params: [FLASH-SPECIFIC] SPI-NOR flash parameters and settings. * The structure includes legacy flash parameters and * settings that can be overwritten by the spi_nor_fixups @@ -599,7 +598,6 @@ struct spi_nor { size_t len, const u_char *write_buf); int (*erase)(struct spi_nor *nor, loff_t offs); - int (*clear_sr_bp)(struct spi_nor *nor); struct spi_nor_flash_parameter params; void *priv;