From patchwork Thu Jul 21 06:44:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2216 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id C406344190 for ; Thu, 21 Jul 2022 08:44:52 +0200 (CEST) Received: by mail-wr1-f69.google.com with SMTP id s16-20020adf9790000000b0021e36810385sf68721wrb.15 for ; Wed, 20 Jul 2022 23:44:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1658385892; cv=pass; d=google.com; s=arc-20160816; b=FRWyYo647A2EexsmK91XT+gwBow4ytdbCXAeaVUypwtIonpIU77b0wJKXr9485g0n7 3NgTJThehws4hsxYJVKFKUxNnbgIbiHGfBwhvPKHc1xuhscVg7/0bB6m+5HMzIV4U2iK ZhwCLKM44+nv88EHNTMVVludW6F7F/CHD0VRBCKfYkel39vE2AwJYQAVQfTVibPuh0sS V85b96aDr0JyOC4Nm1HXJwuucAzvEhv2sD1YLcZeZbm3zmasXy6/EHhHm02E682RmouZ 2yTz1Ovarurql2FvIF45H4rpnX5iq+Wbs9TP9JBX4TOfgGXuTrtvRgoPbSpa2nZvL0SB 71sQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=ouBh2Q3M3uq8SGXgzpjsuL+uKHbP9udtl7iMsA//JLA=; b=Uvbj12WxiYFGXzHmNEWs7qMlpwIDMuIdg8Wk996H177nQusRlEfkwodRu1Moi6o9Zs RdK5x8ajeasxbHG0EeIYvKWE/NFRkIkAV4VpwVVZi61AT/pGhQUi+eCo1pOpOp7lXN1+ NBfKsuFFpe1rXimEn3HTpHtVM/uieA1jImb2E+kZ7Ij+oNMWK4PKuMBFxSawy27XUZHr xmBasShRS5dDXuUp+axmy/4v9onlI9SFteQuZ/jluKt5l+oM9KTGDQ5rkkf56Qq3iZ3/ L338M5aGSYU9seik7i4Ysbv8OC8F1HjFZKVXJNjZWgF51RZWkCx88Kcog6T8ztUwplEx XtYA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=bYuDstZ3; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=ouBh2Q3M3uq8SGXgzpjsuL+uKHbP9udtl7iMsA//JLA=; b=I2xIJNND9w/iPWw046XHAdcMMpMJj4ExAwusIIdMQ7WNiLkrJpv8PfGadeEyjZ0GlI OqXVpKt+wEr3mNRgOZ3TXjhNO2j/X2PSJ+QNPSuIlUXpCz7k5MGFbt/PzHGWc96fP186 46EmeVNO8haVsr0OxGVk/ZO2llZ1Ic6h+syMU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=ouBh2Q3M3uq8SGXgzpjsuL+uKHbP9udtl7iMsA//JLA=; b=A/m537AWB8J79dcd612/4uyLmRM1G/QXJ6yOwgj2knDdzJBab61xfGrkR4JYDBFehP BGoqi4L2lXNmJrImTKU81VSFdAZfkGy3CISV6WXxFqagy1aXdiarACwCY8YyAb9Is9C4 uHumG1QWcnVaM5IFBojKy1pdNhyMsDbQoZ0ed7zIQ9qQbWDYoBTpMNe8LzRGZ2rP2lvY 1j0vnAx15z96qzPcOg89uiRzDqQKD65wYvGLLWMWdd6sa/NrQYq2f9LTj9oaRY6zH430 PYtSRmNadATkv4HyaPg7H/eRauRTOKd3uFWWaPDDdCdQ/JF4SU9IL7MBWYmz7Dj6DwuJ o4VA== X-Gm-Message-State: AJIora8yDr7AOY9jaECEihXy87Q/ftx5IbDMdkfAT5fJ9endl1wWkC8i oHCid+qO91Nskk/tlnt+V1uOd11W X-Google-Smtp-Source: AGRyM1vjwsDL72GvTGXoLDoz/pUQZsBEkSlf0VnQPMJ/SweFJaVxfNUkNDQMjFop3SwxgM/0dRPmcQ== X-Received: by 2002:adf:e98b:0:b0:21e:3367:cb43 with SMTP id h11-20020adfe98b000000b0021e3367cb43mr9592388wrm.25.1658385892388; Wed, 20 Jul 2022 23:44:52 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a5d:6f03:0:b0:21d:9636:a730 with SMTP id ay3-20020a5d6f03000000b0021d9636a730ls243348wrb.0.-pod-prod-gmail; Wed, 20 Jul 2022 23:44:51 -0700 (PDT) X-Received: by 2002:adf:e192:0:b0:21d:62ee:ef10 with SMTP id az18-20020adfe192000000b0021d62eeef10mr34329611wrb.693.1658385891324; Wed, 20 Jul 2022 23:44:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658385891; cv=none; d=google.com; s=arc-20160816; b=bWxqdwzBlwpuR9Wmae7nmfm9bcG0MT8JxHm8nU+S7knOcyU695BAPAN0jhX52r88pB 8gTAepyoZKoar+lXnmwKkqz+WNIjuWyJ8XQN5QwPiqWDtYCRPC9/Qr8tBR/vMxgyQVnC Y4qluv6rLdMo405h/WK/ZbGtV5N12ARjgWSroPnsPXR6VoIRTYS8P5raZ6BlryVeF82n ER+uHfhfgOyCr0d2DBEMnLfO+T2WDsizv0aS+qjiXCo/iYAyagOp/AzNHtXmzTr5ofbz GgUtOctDibHAg9emZmLk+Y4yFqujEegrdZnR+lK6ujMLEpMkEG34FPrINQ9f0LtMkQCx SRFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=Pjc68EH3MfbHU+IghcH+O86js6/5fZzjKV5AuE4OsIU=; b=VDrK2v0/PttGevLw+dnezwxdo1dQwrNao1QibD0oNUr5XEVALaan3SkGWORGsFPO7w /bUMKUiqXIvHzHK/k+XEZ6FqLm02blhjL3Pm6ILWhNq4DfremTBUtQ+decLcGIZLWjos LyrFdfp8eae+sge4DegKnE6AChEUYReiSTETm2mJBdCsqJnk5awE29BAB/nmqIfPBN3F Jwm4SqZqU4j8jnRgYukKfGHOY5yz1NFDCBq7I6S3pB7SJ4UcC8eQU58NosBx80tKUAB/ EYWtMXd/n6y+OmBZLrOSX7GqwqERAXMuNb+qWsj9XkiIN/pT8AEsPz1f9D/SN7PKGAz+ yh9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=bYuDstZ3; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id o8-20020a05600002c800b0021e4b033178sor434440wry.29.2022.07.20.23.44.51 for (Google Transport Security); Wed, 20 Jul 2022 23:44:51 -0700 (PDT) Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Received: by 2002:a5d:64c2:0:b0:21e:2e1b:d031 with SMTP id f2-20020a5d64c2000000b0021e2e1bd031mr9637397wri.8.1658385890948; Wed, 20 Jul 2022 23:44:50 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.pdxnet.pdxeng.ch (mob-5-90-140-42.net.vodafone.it. [5.90.140.42]) by smtp.gmail.com with ESMTPSA id c18-20020a056000105200b0021e4f446d43sm903711wrx.58.2022.07.20.23.44.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 23:44:50 -0700 (PDT) From: Dario Binacchi To: u-boot@lists.denx.de Cc: Amarula patchwork , michael@amarulasolutions.com, Dario Binacchi Subject: [PATCH v3 01/13] mtd: nand: Get rid of busw parameter Date: Thu, 21 Jul 2022 08:44:23 +0200 Message-Id: <20220721064435.2456601-2-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220721064435.2456601-1-dario.binacchi@amarulasolutions.com> References: <20220721064435.2456601-1-dario.binacchi@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: dario.binacchi@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=bYuDstZ3; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Michael Trimarchi Upstream linux commit 29a198a1592d83. Auto-detection functions are passed a busw parameter to retrieve the actual NAND bus width and eventually set the correct value in chip->options. Rework the nand_get_flash_type() function to get rid of this extra parameter and let detection code directly set the NAND_BUSWIDTH_16 flag in chip->options if needed. Signed-off-by: Michael Trimarchi Signed-off-by: Dario Binacchi --- Changes in v3: - Use commit sha1 with 13 digits. Changes in v2: - Use short-commit form. - Remove linux info. Uboot seems that backport without add this extra information. drivers/mtd/nand/raw/nand_base.c | 59 +++++++++++++++++--------------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index e8ece0a4a0dd..9a2194ebd3f8 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -3898,8 +3898,7 @@ static void nand_onfi_detect_micron(struct nand_chip *chip, /* * Check if the NAND chip is ONFI compliant, returns 1 if it is, 0 otherwise. */ -static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, - int *busw) +static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip) { struct nand_onfi_params *p = &chip->onfi_params; char id[4]; @@ -3971,9 +3970,7 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, chip->bits_per_cell = p->bits_per_cell; if (onfi_feature(chip) & ONFI_FEATURE_16_BIT_BUS) - *busw = NAND_BUSWIDTH_16; - else - *busw = 0; + chip->options |= NAND_BUSWIDTH_16; if (p->ecc_bits != 0xff) { chip->ecc_strength_ds = p->ecc_bits; @@ -4003,8 +4000,7 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, return 1; } #else -static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, - int *busw) +static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip) { return 0; } @@ -4013,8 +4009,7 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, /* * Check if the NAND chip is JEDEC compliant, returns 1 if it is, 0 otherwise. */ -static int nand_flash_detect_jedec(struct mtd_info *mtd, struct nand_chip *chip, - int *busw) +static int nand_flash_detect_jedec(struct mtd_info *mtd, struct nand_chip *chip) { struct nand_jedec_params *p = &chip->jedec_params; struct jedec_ecc_info *ecc; @@ -4076,9 +4071,7 @@ static int nand_flash_detect_jedec(struct mtd_info *mtd, struct nand_chip *chip, chip->bits_per_cell = p->bits_per_cell; if (jedec_feature(chip) & JEDEC_FEATURE_16_BIT_BUS) - *busw = NAND_BUSWIDTH_16; - else - *busw = 0; + chip->options |= NAND_BUSWIDTH_16; /* ECC info */ ecc = &p->ecc_info[0]; @@ -4168,7 +4161,7 @@ static int nand_get_bits_per_cell(u8 cellinfo) * manufacturer-specific "extended ID" decoding patterns. */ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, - u8 id_data[8], int *busw) + u8 id_data[8]) { int extid, id_len; /* The 3rd id byte holds MLC / multichip data */ @@ -4221,7 +4214,6 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, /* Calc blocksize */ mtd->erasesize = (128 * 1024) << (((extid >> 1) & 0x04) | (extid & 0x03)); - *busw = 0; } else if (id_len == 6 && id_data[0] == NAND_MFR_HYNIX && !nand_is_slc(chip)) { unsigned int tmp; @@ -4262,7 +4254,6 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, mtd->erasesize = 768 * 1024; else mtd->erasesize = (64 * 1024) << tmp; - *busw = 0; } else { /* Calc pagesize */ mtd->writesize = 1024 << (extid & 0x03); @@ -4275,7 +4266,9 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, mtd->erasesize = (64 * 1024) << (extid & 0x03); extid >>= 2; /* Get buswidth information */ - *busw = (extid & 0x01) ? NAND_BUSWIDTH_16 : 0; + /* Get buswidth information */ + if (extid & 0x1) + chip->options |= NAND_BUSWIDTH_16; /* * Toshiba 24nm raw SLC (i.e., not BENAND) have 32B OOB per @@ -4301,15 +4294,13 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, * the chip. */ static void nand_decode_id(struct mtd_info *mtd, struct nand_chip *chip, - struct nand_flash_dev *type, u8 id_data[8], - int *busw) + struct nand_flash_dev *type, u8 id_data[8]) { int maf_id = id_data[0]; mtd->erasesize = type->erasesize; mtd->writesize = type->pagesize; mtd->oobsize = mtd->writesize / 32; - *busw = type->options & NAND_BUSWIDTH_16; /* All legacy ID NAND are small-page, SLC */ chip->bits_per_cell = 1; @@ -4371,7 +4362,7 @@ static inline bool is_full_id_nand(struct nand_flash_dev *type) } static bool find_full_id_nand(struct mtd_info *mtd, struct nand_chip *chip, - struct nand_flash_dev *type, u8 *id_data, int *busw) + struct nand_flash_dev *type, u8 *id_data) { if (!strncmp((char *)type->id, (char *)id_data, type->id_len)) { mtd->writesize = type->pagesize; @@ -4386,8 +4377,6 @@ static bool find_full_id_nand(struct mtd_info *mtd, struct nand_chip *chip, chip->onfi_timing_mode_default = type->onfi_timing_mode_default; - *busw = type->options & NAND_BUSWIDTH_16; - if (!mtd->name) mtd->name = type->name; @@ -4449,9 +4438,24 @@ struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, if (!type) type = nand_flash_ids; + /* + * Save the NAND_BUSWIDTH_16 flag before letting auto-detection logic + * override it. + * This is required to make sure initial NAND bus width set by the + * NAND controller driver is coherent with the real NAND bus width + * (extracted by auto-detection code). + */ + busw = chip->options & NAND_BUSWIDTH_16; + + /* + * The flag is only set (never cleared), reset it to its default value + * before starting auto-detection. + */ + chip->options &= ~NAND_BUSWIDTH_16; + for (; type->name != NULL; type++) { if (is_full_id_nand(type)) { - if (find_full_id_nand(mtd, chip, type, id_data, &busw)) + if (find_full_id_nand(mtd, chip, type, id_data)) goto ident_done; } else if (*dev_id == type->dev_id) { break; @@ -4461,11 +4465,11 @@ struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, chip->onfi_version = 0; if (!type->name || !type->pagesize) { /* Check if the chip is ONFI compliant */ - if (nand_flash_detect_onfi(mtd, chip, &busw)) + if (nand_flash_detect_onfi(mtd, chip)) goto ident_done; /* Check if the chip is JEDEC compliant */ - if (nand_flash_detect_jedec(mtd, chip, &busw)) + if (nand_flash_detect_jedec(mtd, chip)) goto ident_done; } @@ -4479,10 +4483,11 @@ struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, if (!type->pagesize) { /* Decode parameters from extended ID */ - nand_decode_ext_id(mtd, chip, id_data, &busw); + nand_decode_ext_id(mtd, chip, id_data); } else { - nand_decode_id(mtd, chip, type, id_data, &busw); + nand_decode_id(mtd, chip, type, id_data); } + /* Get chip options */ chip->options |= type->options;