From patchwork Thu Jul 14 14:35:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2167 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id E18933F066 for ; Thu, 14 Jul 2022 16:35:51 +0200 (CEST) Received: by mail-wr1-f71.google.com with SMTP id i13-20020adfaacd000000b0021d96b4da5esf599959wrc.18 for ; Thu, 14 Jul 2022 07:35:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657809351; cv=pass; d=google.com; s=arc-20160816; b=XYBapo4wDEk9WnjHF6AFjy4SjXSJQwQh09+8wp/PBt8gs60t/xQ3pzL8HbszovZWBO JAnQu9VWvznXUvXEl/k/v3ZamXwsONj8TipgHdGQyyR9Uw5nfUrwCv08z4BqI3LxvV3x 5TCxceORfowarjWn5sETVl3p2iB6wl2cyeJpp6sYRVRE3eOIlzhdQJQ28LBXqG76jrS4 lsQb7/1rYjTe+dyiYnotrTQSNg1aPqvZzWFQz77pQDyhjjd6fcxvMUjR+Ssk2dNPHsFb vmytcWthsgAXHBqjuenwOyL8KkmVEDptIHBYr9QautkamybPgVFUqLCCd9OewIX2yisv HPfg== 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=7hvMNiOy/LOqCyI3v4/0P1pp7mZMWWzUh5Cka+00Ah8=; b=Fx9Aah0JuQlSvFTjYH9SrPyE+N7s6DEqTJEnGrykq+mcNKqynLsMW8iiT65forNl6y FXYidC+N5VjoQ9jbf0R13ITn4lo1g+FdbaNjlKjmCgzhARHpEcjex4CCGsZgtoRd+WjJ ZjFGhMYYMVHLhbcYOKaIOiVQMGxlNPNaPEWojBTEC+MTCAunVedfVZGhT1PbHZks5Idc AmqQp2R858nfz6liZfaFzh5PFNnBe3R62T+KX+z9pIbKFNWpzmXfOtSg98+LJwBtDSVJ EE8vRew80PgqzTtRfUkWQmz6BNTC0O7kus0y0v1iBmndCD58PaPMvIVaYiC6fC6F5K71 D/Tg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=pO5kxnUL; 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: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=7hvMNiOy/LOqCyI3v4/0P1pp7mZMWWzUh5Cka+00Ah8=; b=D/KhpWTPhbY2icO+0lHxJqKfMQkcixr5atYFOuPw2FFqw5d3r1KxIsGFnD38PQtncM DcvhzM4zdXnrCzdO/qyoeN2vfDniIErdJLKuFuyFyEC4yb56rPAb/wzTKgF8cfiO9c35 aRkBEgd0Nqgoo//NKsNYSPj2bNnGTUlBDl8Vo= 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=7hvMNiOy/LOqCyI3v4/0P1pp7mZMWWzUh5Cka+00Ah8=; b=EFpyyzWIAHsGooZJbMbrtX9yCNAhGKqd6riLqsu6GnhPaUY5ttuz2OREhdGiiWXLQ3 WpJo9u1IWtv/2nS2X9V6c/ljzOurn5ymgQi1blbpczsGcuqkbvuDK0EKjOQD/QfwSAiZ Hn1S0iyrW6bXBQLYtZbUiSck6H84HmmVh6y4XfQX/fIxwSY2EXGoyRVtYVtf9o0k9Dnr au2FfQmtepAnCiEXKziaaq2pfWcUd4Xb+Q+NeO/orFPOSJ5y3d//OkXryapx0yUZnMqv JZXyolkaFnANE6T/XtWz78eETcLtDvs9yV4rHNKxTm0zZnJ1AYs/tgqaau7CrDtGvbLR FJdw== X-Gm-Message-State: AJIora9AAQfuh+EvHbo1wlwy3tZBtdOklpSy94dFrlr7hEbvL4X5kFeN 93jrRbvkci9t00mUw4KFXxbWsCNp X-Google-Smtp-Source: AGRyM1ucDqYVaf7wXF7weNkMw7zZ27uFJkxnaxZqVY7jTsZe8kZOJLgf4GsQReWNy0K+xta3ONWZog== X-Received: by 2002:adf:e6c1:0:b0:21d:6497:f819 with SMTP id y1-20020adfe6c1000000b0021d6497f819mr8119789wrm.243.1657809351665; Thu, 14 Jul 2022 07:35:51 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:600c:5119:b0:3a2:d019:ba21 with SMTP id o25-20020a05600c511900b003a2d019ba21ls4512902wms.3.gmail; Thu, 14 Jul 2022 07:35:50 -0700 (PDT) X-Received: by 2002:a05:600c:3507:b0:3a1:9fbb:4d62 with SMTP id h7-20020a05600c350700b003a19fbb4d62mr9182985wmq.161.1657809350332; Thu, 14 Jul 2022 07:35:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657809350; cv=none; d=google.com; s=arc-20160816; b=bP2C26BKQ1aMAhG6ddpq/N2Kq6bmkxsUrFgBMjdvr9frcT+wAnhcCvTbOTOeRvYm8+ wQ46yNCaW4bc/hHFg+FXgVzOI7L4jYi7KJRzREcyGRbOGMwxP6+c+5VAIfFu4jWfyGI9 VR7mlJEw1GrQAARh/Y5lFMXmsJ5D1r3IyFpLUxHIrHMUx7VJ5e1DnNYqK8aKZNQlYj6S VOSsexH+r5Iz7+wXUnKHqjaCSOak7kLLxYmUDzIDP4qc603IDmMvhox1yIC9nKra+doV oQguoofEljm0uFE+Ss0eULiuo51EPGWEDJfhv2Pz4cLNLwmZ/8GFIPE1rK2xJ9qXv1SA KuBQ== 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=JxxWXuTcu0HTKh33nVMpbU0X7/H1gnpPd0sUG9SCaRk=; b=R2mm8QdKJrVsFhJV3zET9RCUXIG6MJjfayFSuFGnkxJahxb908PLNbuSqE7NphFE9X Ice2/WfI+0cuFNd+1EpoXP7dxwksto9n6DHM0o4PoRYjWglzsxzh1njpdm2yA5NLHMuC 3CX5dKZaRBxkRyG3WdKsnFI1LPfE4ysxw80xSYlNUu63Zg8328IwYTvgQWMDfK87Ubqc 8kop3egbBckHuCBSxvhB9d7Tc2EndJsNTwv/smftVPoV6xIfXltlP8Xm9kga5GvwMGS5 qtEr/hhJA79YZLkNQZFPBvkMp9NRS4XgcBHJ8sYSXxXXhQu4KR7m8qwvY6fGu3ozAYOv /hsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=pO5kxnUL; 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 f6-20020a1cc906000000b003a04c522658sor1342470wmb.1.2022.07.14.07.35.50 for (Google Transport Security); Thu, 14 Jul 2022 07:35:50 -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:a05:600c:19cd:b0:3a2:f2bb:72ad with SMTP id u13-20020a05600c19cd00b003a2f2bb72admr9496173wmq.106.1657809349551; Thu, 14 Jul 2022 07:35:49 -0700 (PDT) Received: from panicking.. ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003973c54bd69sm5712357wmq.1.2022.07.14.07.35.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 07:35:48 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai , u-boot@lists.denx.de (open list) Cc: Boris Brezillon , Richard Weinberger , Marek Vasut , u-boot@lists.denx.de (open list) Subject: [PATCH 01/11] mtd: nand: Get rid of busw parameter Date: Thu, 14 Jul 2022 16:35:33 +0200 Message-Id: <20220714143543.448991-2-michael@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220714143543.448991-1-michael@amarulasolutions.com> References: <20220714143543.448991-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=pO5kxnUL; 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;