From patchwork Thu Dec 29 19:09:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 37489 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2550352wrt; Thu, 29 Dec 2022 11:09:39 -0800 (PST) X-Google-Smtp-Source: AMrXdXvb4q9iPqCAdsTNZeQ3Fvy3Cn6gT9R7e6ARC5T/K+Z3Bm4gq3JQTIPZNT1aYaa8RmAjF9aQ X-Received: by 2002:a05:6a20:e686:b0:ac:b2a3:e39c with SMTP id mz6-20020a056a20e68600b000acb2a3e39cmr34653560pzb.62.1672340978805; Thu, 29 Dec 2022 11:09:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672340978; cv=none; d=google.com; s=arc-20160816; b=qzpbmbDvz9ur8q1xD6swRHXqa2fAlyr1MSLf4L/0Wte5/KFI/ixk0UyrGzdEX8R8g3 GtywYKWeYMehGIfPYPVgW7OfoSjRYz2yKaGBMDAfamKiabgCvKHze9PjjjPn+fxsB7G/ nSwrwYedniZ6/f9IaPXxLhDgRQkOcWyTxIQLU0N4nUoTir6I6degMaIg0wQNyE20iEqs HxzuBTF3MmDp1XskzD2vOL7G70Qgj2IL5lc1avhUg9A88/FNtDwwTGdj6KoQq5VMFCbo x29mevztey/iFObrw5AtaLSsKD0Q8FwFg0wGnp2+ion5DoU4CfmDM8Wu72VyMQTndC4Q 05qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=g5qIXCdzDVSxDpcNOdyuqgoqHDHz1BqdbXW1iSCF4RQ=; b=VIsHDzQghzqiUwlbt72lSDtsTzS5RjRDAaH+vK8jJ1xEuT+7Gelm/Unc1bBszJWMTv isXI08MWngKGgPI5RY/jsfVk+P0M2uEBz7rbOA1Rzj1S2zi8dtPhRIuq9q5o+OnTJxPa Z/LorflEC6HBawCXr2G8WoQAgVBl4mPP6A20CMtZSjfbYCNDLJpbukMpuLTfHT3ialgG WvpC7aAYJfrPOurWBO7siztVU9HX6yn2uOYq7wQdgpWrdQGvNZWj1rnw2REnt020ibha CCVN6srzTbh3mJdlbEx3oNnwNO4OWBDr/v08miZl+31OCXDz1t7DWK2HbV+nQxtPr1h6 CvCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sholland.org header.s=fm3 header.b="kId0KHA/"; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=GscAcTS8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sholland.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id eb19-20020a056a004c9300b0056ce0f64370si19152713pfb.108.2022.12.29.11.09.27; Thu, 29 Dec 2022 11:09:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sholland.org header.s=fm3 header.b="kId0KHA/"; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=GscAcTS8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sholland.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233913AbiL2TJR (ORCPT + 99 others); Thu, 29 Dec 2022 14:09:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233614AbiL2TJO (ORCPT ); Thu, 29 Dec 2022 14:09:14 -0500 Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AB4D14D3C for ; Thu, 29 Dec 2022 11:09:13 -0800 (PST) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 6DCB432005B5; Thu, 29 Dec 2022 14:09:12 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Thu, 29 Dec 2022 14:09:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= cc:cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1672340952; x=1672427352; bh=g5 qIXCdzDVSxDpcNOdyuqgoqHDHz1BqdbXW1iSCF4RQ=; b=kId0KHA/Yh/Tao9yLi sVxAs6/QCg5Hh8jzHO0IxjRVrXCnNkAybj4+8mPbwCGiQq5f/HfGPkhgnVei3/MZ nyN3cWblK5XqrHIZ5ryOpVBecaHw+8V7WboS3jjnv0L6UQvTeLi9oM3MJxFf2iIS bQDTeBHO4YDoKsgINIHWAoVMoD9Lbj9omyLHV+NO+9Op8MWsMay1RJozwMerrJ/J HCxJT7L1bhg9wBM3jIkkm4ZOmwblOcX/esNnLj2JBeYszamhfbocSYQypldGfBSl XEmFpzGx/AMZ16f1jkvgem3N4c3JfEkknWYykkgzFX4QY4Xk8Xgm6hHBibQJktdS rGnQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1672340952; x=1672427352; bh=g5qIXCdzDVSxD pcNOdyuqgoqHDHz1BqdbXW1iSCF4RQ=; b=GscAcTS8q4m6HwlCdc3FoLVACmKZy 4Xg8WgSFCMxf4DBfQoqQvpEufdjsVyBdbbZ6wKBiQLT2em7FTezVIvWiuZqvXRD/ QrKlPM4faGsEEVipnhmWaqSNeWxcGHxbmnV36rGgNRQAw0wDSyDwspAb0m3SKaSl azSw+oKts8o3R/NvDNbvXAk6wBeQuJI0SPG0sxj4n6Sg6E6naVJcl/hHV2qviPLv o7gTlSGreKJwnIwfFxIPvDU36gs28yeZkIUnEyhqgOqrbisQRiPIRb9wx7VBMiFO bTV4igaPTGGzmb1uZ0SRzLsYVj+lzR3pTCnfSm+LGBB2zgxM1ioxQG1CA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrieeggdduvddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepufgrmhhu vghlucfjohhllhgrnhguuceoshgrmhhuvghlsehshhholhhlrghnugdrohhrgheqnecugg ftrfgrthhtvghrnhepudekteeuudehtdelteevgfduvddvjefhfedulefgudevgeeghefg udefiedtveetnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrh homhepshgrmhhuvghlsehshhholhhlrghnugdrohhrgh X-ME-Proxy: Feedback-ID: i0ad843c9:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Dec 2022 14:09:11 -0500 (EST) From: Samuel Holland To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Samuel Holland Subject: [RFC PATCH 2/3] mtd: rawnand: Support non-power-of-two chip sizes Date: Thu, 29 Dec 2022 13:09:04 -0600 Message-Id: <20221229190906.6467-3-samuel@sholland.org> X-Mailer: git-send-email 2.37.4 In-Reply-To: <20221229190906.6467-1-samuel@sholland.org> References: <20221229190906.6467-1-samuel@sholland.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,URIBL_BLACK autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753576614584200106?= X-GMAIL-MSGID: =?utf-8?q?1753576614584200106?= Some NAND chips have a number of pages that is not exactly a power of two. Support this by calculating the shifts and masks for the next larger power of two. Signed-off-by: Samuel Holland --- drivers/mtd/nand/raw/nand_base.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index c3cc66039925..f46bad7796ed 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -5003,6 +5003,7 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type) u8 *id_data = chip->id.data; u8 maf_id, dev_id; u64 targetsize; + u32 chip_page_shift; /* * Let's start by initializing memorg fields that might be left @@ -5148,18 +5149,13 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type) chip->page_shift = ffs(mtd->writesize) - 1; /* Convert chipsize to number of pages per chip -1 */ targetsize = nanddev_target_size(&chip->base); - chip->pagemask = (targetsize >> chip->page_shift) - 1; + chip_page_shift = order_base_2(targetsize >> chip->page_shift); + chip->pagemask = BIT(chip_page_shift) - 1; chip->bbt_erase_shift = chip->phys_erase_shift = ffs(mtd->erasesize) - 1; - if (targetsize & 0xffffffff) - chip->chip_shift = ffs((unsigned)targetsize) - 1; - else { - chip->chip_shift = ffs((unsigned)(targetsize >> 32)); - chip->chip_shift += 32 - 1; - } - - if (chip->chip_shift - chip->page_shift > 16) + chip->chip_shift = chip_page_shift + chip->page_shift; + if (chip_page_shift > 16) chip->options |= NAND_ROW_ADDR_3; chip->badblockbits = 8;