From patchwork Thu Jul 14 14:02:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2155 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 3FDD93F013 for ; Thu, 14 Jul 2022 16:02:25 +0200 (CEST) Received: by mail-wm1-f69.google.com with SMTP id i187-20020a1c3bc4000000b003a2fe4c345csf258108wma.0 for ; Thu, 14 Jul 2022 07:02:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657807345; cv=pass; d=google.com; s=arc-20160816; b=sG5tM3gma2TREGSTC3BqexDAMavTna8ZlIU+fQErkXGkzYuKy8/g1Pgeq8hkeqfPwa 6UOxPt8f1xtQUKMlH9YVhNXUYzE8s0/EfKB69HoPxPyDD1LovUvAPNcluKfo7sP+d/nK C4HQXUEbcHkwQg9DEeMnwjXD4huboB1tWC2G8bmmsqzCCU1cUx6kDIpffUJllEfhKZV9 lN44z6C62hjvV2Xq7O8zPPBqRxBfsnWI027xS3T6QryNB7+GdU8UikqfGIhR3DV5wyIu iPanWsXoou+fe5YjrMINL5E/Lc6HkOd6f5HPg9acpYsh9tUXrCCq1e1fo1UlYpnyUrVU yqRg== 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:to:from:dkim-signature; bh=7hvMNiOy/LOqCyI3v4/0P1pp7mZMWWzUh5Cka+00Ah8=; b=GtLBRAORF0EYCuQDP8ySRq+HaejOSv9UoAsyw1vK2LugGdicvxaNwwNHT7ruRq9r4/ 4DX2gSTIn1NDjN6hKdIagr0gAnQZwnbCqjO0M0pjHl1FQi2hewtoVSPwrsqSePW1nCHG pWuYAFsl0TmHMKe1WIIAN26Ii4BOnJNcpJSFUQtT8dnTEHuYFXH2nUuh+w90EmkgWEN7 ey8S3NHQ/e7Ydpr2JQYs+bBglFBrdpSTUd0xXmF4BU926ag4FcppmA6Hz0C06HD1Vr07 VB4ItKr6R9kUVxjYbwyT+Ew0UpFY1Kftt5DBQpo1DhKaQ3pt4LuQqOoWp7xHF/ganU5X Iq0w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=OglpZGmB; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@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: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=7hvMNiOy/LOqCyI3v4/0P1pp7mZMWWzUh5Cka+00Ah8=; b=j+s+b5x9O/XtEykSPo38QHqMhbNCXS7BgCePuntDefN7BIzGI0guRV+sHwTeppaD3+ UGX2lSu8OrUINbG07HgjRlvkgBi5h/uWPdiMnnywGgz+Yqy46Q1n1TYdVJhIzkjmbeuX sU/AgoUW+4Za44oBrZ//YD7msFcf1ssCDKsoI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to: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=7hvMNiOy/LOqCyI3v4/0P1pp7mZMWWzUh5Cka+00Ah8=; b=7lpDfy+F8oyCSc8uS/s3jGP8+aWi6N8YSYKIjjzlRJ8GZPYWp+PxrsfFWG4WGOkNBb D215KwLgyiaLHK3JdvpCQbTtAuQs0/ucV9aybuwVESiunnuQ5c2WVKxYvAlja+Okx/aF 4jgu0bXwtZj18hyRvvVJ9air6KlfjrcUh42BSPSLzqrngbb5tHlcjeKw8gCr/dpqysOO JAlZm+/jqi6OYX2TLM7hvxZ5Q9t/TUEsW9boLrDSRI254aSKgY0ZhSPtfExfutLvwlic TjgQY6Ak+bml4BobnfvsGFr7FW8aFvaLZwSLSH0+Ftu/FXWiF7BcPaREaOi0Kaajlq0c rXTg== X-Gm-Message-State: AJIora9wiqPeaGj7KdbYvzqOnJhFNZ+kE9qkvJSJMdskhj+V5aKsYfzc KmrL/BtPNZIjeWTLts6ALUVh6adT X-Google-Smtp-Source: AGRyM1sYdKpysLLDEUWDCqO9hpd+Yg9yWwVysCf6aT6icXPgxIgLFLYH+I9jkPPFYXk2lXYswMrepA== X-Received: by 2002:a05:6000:98b:b0:21d:b70f:2726 with SMTP id by11-20020a056000098b00b0021db70f2726mr8525505wrb.237.1657807344974; Thu, 14 Jul 2022 07:02:24 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6000:1ac7:b0:21d:ab25:25ba with SMTP id i7-20020a0560001ac700b0021dab2525bals108816wry.2.gmail; Thu, 14 Jul 2022 07:02:23 -0700 (PDT) X-Received: by 2002:a5d:4692:0:b0:21d:8e7d:b425 with SMTP id u18-20020a5d4692000000b0021d8e7db425mr8058824wrq.267.1657807343025; Thu, 14 Jul 2022 07:02:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657807343; cv=none; d=google.com; s=arc-20160816; b=QRVvu+N975yk0xnw3pBiFRx6mzDms1RQ8DEbcaq+h4Af6vBd5FBP2yI4LEwO6SS27C CCezTjSOtAcCwd8MKcqLtjKOOIMJyFaVh+1yzd75oAsDXTOXTCcu42dTnfB4xzBLzl5i CyFKco9qnFOLmoU3KDo8TQwn/KPD8oRrZUXOFyPYJKRqRVY+OSfv9SwgVVovXsfEb6eL fafrCGYNVySUdcy70b6uA0JLL+bRK4set+5XgZmWVESffFRee2oxe1fnM3BTDATp5Sk6 SR+RMZyTu5X9ZX/CWOIXV0w/3Kg1jrNVLm/dPaumL5M4Hu7b9QGY3Iq57thbZDVA0Lyw +bTQ== 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:to:from:dkim-signature; bh=JxxWXuTcu0HTKh33nVMpbU0X7/H1gnpPd0sUG9SCaRk=; b=rFkN0s6hulDixR3wcv6ExDl98PALALQtwa9MvPs+hwxg2e6aICFZ+febt2NleMj83/ Tzk5WQtSZdIUg+s+KgLeUQO7RdXxal2T6s6ApU9tsizbmGXaIFgI7Up8eYsJgMC0/Jww gnfkSjvvm2M2Xjx7+zbcOfQogtnjEmd7EKe/VlcW7isJhIE5hD+J7k7qB2ku3U9bBGKi 5UC/5i+nzvRMhOr30haGfwAC8boVNFTtQNWIikFwKv7LuTuSZtFaPureMS9XCx36DN5n cAWi38oIUmPoZv/jU0abI75XlvrDpvdp5EYaFBZb9v4x+pjbNRIyDuIrKceS2tAEIsDe hrBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=OglpZGmB; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@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 14-20020a5d47ae000000b0021dbcd93518sor812013wrb.8.2022.07.14.07.02.23 for (Google Transport Security); Thu, 14 Jul 2022 07:02:23 -0700 (PDT) Received-SPF: pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Received: by 2002:adf:fb03:0:b0:21d:70cb:d6b5 with SMTP id c3-20020adffb03000000b0021d70cbd6b5mr8235963wrr.548.1657807342158; Thu, 14 Jul 2022 07:02:22 -0700 (PDT) Received: from panicking.. ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id k11-20020a7bc40b000000b0039c5cecf206sm2029114wmi.4.2022.07.14.07.02.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 07:02:21 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai Subject: [PATCH 01/11] mtd: nand: Get rid of busw parameter Date: Thu, 14 Jul 2022 16:02:05 +0200 Message-Id: <20220714140215.444993-2-michael@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220714140215.444993-1-michael@amarulasolutions.com> References: <20220714140215.444993-1-michael@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: michael@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=OglpZGmB; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@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: , Upstream commit 29a198a1592d83f2bc1be3b2631b3bcf3d5b380f 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: Boris Brezillon Acked-by: Richard Weinberger Reviewed-by: Marek Vasut Signed-off-by: Michael Trimarchi --- 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 e8ece0a4a0..9a2194ebd3 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;