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; From patchwork Thu Jul 14 14:35:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2168 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 4E7E23F066 for ; Thu, 14 Jul 2022 16:35:55 +0200 (CEST) Received: by mail-wr1-f69.google.com with SMTP id l17-20020adfc791000000b0021dc7dc268dsf292148wrg.0 for ; Thu, 14 Jul 2022 07:35:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657809355; cv=pass; d=google.com; s=arc-20160816; b=wYSGO7BOrBKl1mLvARHnl8LUx+ZPHKpIpheY88KmPtaUTHHSEYc09rIu+NyiOt5Z+h XNhPjR5GRLZ5ycXttHm0l0HGMWkrzvedgsDx7WG5uNqrctll03U3WeqNqCtUZsK2PBJm EqKiqjXFPW3QXIi0ZuX7LnbvVYfEazNHkF5LtBlVl+Us5wAvtDsWvLgqkFzX7COZXYP7 Lf8uEaoesjdErU1oWGCw/QNgo0oHIkTfZ1sJPYSvKevjg0CSBxM+tnEnowsMXpRhh0RV Wo+UCyjtliWKcQbTdrPJyOXG/DHI/xnxtgp9ki6xXNbq0tWQVA5L1MJRb6Ob5enEZjiz FZGw== 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=U6KVHMVhDQfZo32KbkTv2zF8IG0l7kHLolyZ6xRwLFk=; b=MkVvseyyUNtaAUS0cKazeSQaclLza/rfeqPO+8FNWUq3CQHFAFYQMGq8VOeB+CHFrD MzB1VE7B2ujyAKYtbToafRSzMcK0RCaSSCZKT0AiHWimbaea41XJTbC/eA4XHzyjz4Xc y+1WDKTd5LAc6Xf6fiEYbDym0/BBteUt1dIQIRjBTZ8tmLyWZH2wpazRz7REVrASa3Uq jiRaMP7eR8TTOPw63tugGZBhv2hIKsS9m01nzFapn7FFN57KkisDeb3DNPUjGbub7S2U KHTEBTQlbG5ZDYNnPECnJ62bztZ947qIL1b0VdjCwqs3hNu7xkkwTnmuyJd9gvqQYLul 4e/g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=LYKRSA3F; 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=U6KVHMVhDQfZo32KbkTv2zF8IG0l7kHLolyZ6xRwLFk=; b=cnOxdmP3t3MI+1t8rvxq3BUsFOuYxEex3Y9cDoY99V8jSxTqBNvlGtJa3f264ndNbY T2qmK6KLk1ljRRpKTE+gup5vx+lstFyxAAHMmrOeRrGU9CXKv0UYQ5XjEAyO9AUiwcox jYhS2Fw9y/EHf6EY3Z+LQtw36jQGXHiyFBFHQ= 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=U6KVHMVhDQfZo32KbkTv2zF8IG0l7kHLolyZ6xRwLFk=; b=ZPJm6dibNVUBdoj4Yt0VdavUClVhiGq6gpfVjUHkMjh+5Vrtjp5I6qlitDjsqUXNXn hjSahRVVEbRrumPkhVu+mwVDGWiK9RmYIqWsYdaeqA+DhXojtDNhIktolh9hSI0yntX8 Vdkl+y4vAzAhCpvIfhskipyvX8WnwfSgPkHIFkpuazUMNjRkCJiBYgzwADTF3zNoPXWl gf04wB3qtrM4e5ApH32VJ+xsDNI7cCE4S0JUQcImQvmWMAI5uQ+somLIAhcuKUr41MiO /MDoSq50ngE1T8KN+NE2ub1z76LqEhWSzmMjNev+7U1dBOVGULHFL/4qtqIroKvLcMZ2 MvVw== X-Gm-Message-State: AJIora9QYbHNgWfD85dRhRlGAgPpwSHeP7d1hzGqOVkM8NESp6vvKzoT eUMZqyYIXQm3c7f/TpCcd1ntVOhd X-Google-Smtp-Source: AGRyM1sw2MfNAU/yMC8cHbupJeuDcP3apGErdUaiWuHISJayl6ZGIIuR3umFekCnMQmmJ6KdH74kmQ== X-Received: by 2002:a5d:595f:0:b0:21d:78fd:70d6 with SMTP id e31-20020a5d595f000000b0021d78fd70d6mr8487287wri.402.1657809355055; Thu, 14 Jul 2022 07:35:55 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:600c:500f:b0:3a3:159:4356 with SMTP id n15-20020a05600c500f00b003a301594356ls1016152wmr.3.canary-gmail; Thu, 14 Jul 2022 07:35:53 -0700 (PDT) X-Received: by 2002:a7b:c3cc:0:b0:3a3:8ec:d69 with SMTP id t12-20020a7bc3cc000000b003a308ec0d69mr308696wmj.78.1657809353625; Thu, 14 Jul 2022 07:35:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657809353; cv=none; d=google.com; s=arc-20160816; b=rseNtWz2CaLKo35A+iLV2WKsVMep+uhrsjegKwojYecdB/cEtiJW1+4NQ5SaPIllOQ uuX9fq1QWo6IhLOhgKThKaqDFX0ADmy+3Lf9we3oDsIKQ72rmdx5N74s0/9KLg2MK1cB rva7z9/T79lHDZS9fPe4oK0FCkI2z7G4fmhIwR3QrUGSZsap7r+gMX0NX5eBgaWDAZJC k21bIBgYTFoF+Y75X6ayphEwGXoXj4k4M+bWhqZKHghwRr+GSJS8Y65/WC7K9m2o7orK BwPT/Ede2qMgR+uTDRY8M7YqZ08AV4StmuFbwcJ0jGZZkdHD2mxTjR0Sy5dveLk4HSwO 0Edw== 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=diK71uX3lIh/YgoKebxDYbelkMlwygsjJFrjrAg4a/M=; b=0YNf1piBqpxuVUhjKoz95be8YcLePiUhXD+xx5CyK2v8ziF2dwO5yYaqsMsSeZ04UP FkLklgK82L3ubqnAUz0NIlwPfWrrNNztGTuHTfWXikN+IPHB7QJ4w2fo+UY+EuG6Z2rq uYDEuMp9FqHeA62jhcVX52ZeDHgC1ddClCZMSEQBGDelvIZUJ7bHQmqe7VWCeSp98S6K KHiDjssZGRsAaMDBpFeAuFVqJeZV3OCtYukTvkmCTEs2bOzRg1oNUkX3mlkaLPirrcgK clV654F6G2/yDYsyy3epn5bdIwLM9kgULSGun1L7sfJszwHYn6LOnh7aAxxZFDyC1H8H 63Qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=LYKRSA3F; 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 n11-20020adf8b0b000000b0021d76a73a5asor874084wra.15.2022.07.14.07.35.53 for (Google Transport Security); Thu, 14 Jul 2022 07:35:53 -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:e604:0:b0:21d:6ddb:d0ec with SMTP id p4-20020adfe604000000b0021d6ddbd0ecmr8760509wrm.177.1657809352852; Thu, 14 Jul 2022 07:35:52 -0700 (PDT) Received: from panicking.. ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003973c54bd69sm5712357wmq.1.2022.07.14.07.35.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 07:35:51 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai , Boris Brezillon , Richard Weinberger , Patrice Chotard , Simon Glass , Wolfgang Denk , u-boot@lists.denx.de (open list) Cc: Boris Brezillon , Marek Vasut , Marek Vasut , u-boot@lists.denx.de (open list) Subject: [PATCH 02/11] mtd: nand: Store nand ID in struct nand_chip Date: Thu, 14 Jul 2022 16:35:34 +0200 Message-Id: <20220714143543.448991-3-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=LYKRSA3F; 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 7f501f0a72036dc29ad9a53811474c393634b401 Store the NAND ID in struct nand_chip to avoid passing id_data and id_len as function parameters. 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 | 54 ++++++++++++++++---------------- include/linux/mtd/rawnand.h | 15 +++++++++ 2 files changed, 42 insertions(+), 27 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 9a2194ebd3..4a78770a25 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -4160,16 +4160,14 @@ static int nand_get_bits_per_cell(u8 cellinfo) * chip. The rest of the parameters must be decoded according to generic or * manufacturer-specific "extended ID" decoding patterns. */ -static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, - u8 id_data[8]) +static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip) { int extid, id_len; /* The 3rd id byte holds MLC / multichip data */ - chip->bits_per_cell = nand_get_bits_per_cell(id_data[2]); + chip->bits_per_cell = nand_get_bits_per_cell(chip->id.data[2]); /* The 4th id byte is the important one */ - extid = id_data[3]; - - id_len = nand_id_len(id_data, 8); + extid = chip->id.data[3]; + id_len = chip->id.len; /* * Field definitions are in the following datasheets: @@ -4180,8 +4178,8 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, * Check for ID length, non-zero 6th byte, cell type, and Hynix/Samsung * ID to decide what to do. */ - if (id_len == 6 && id_data[0] == NAND_MFR_SAMSUNG && - !nand_is_slc(chip) && id_data[5] != 0x00) { + if (id_len == 6 && chip->id.data[0] == NAND_MFR_SAMSUNG && + !nand_is_slc(chip) && chip->id.data[5] != 0x00) { /* Calc pagesize */ mtd->writesize = 2048 << (extid & 0x03); extid >>= 2; @@ -4214,7 +4212,7 @@ 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)); - } else if (id_len == 6 && id_data[0] == NAND_MFR_HYNIX && + } else if (id_len == 6 && chip->id.data[0] == NAND_MFR_HYNIX && !nand_is_slc(chip)) { unsigned int tmp; @@ -4278,10 +4276,10 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, * 110b -> 24nm * - ID byte 5, bit[7]: 1 -> BENAND, 0 -> raw SLC */ - if (id_len >= 6 && id_data[0] == NAND_MFR_TOSHIBA && + if (id_len >= 6 && chip->id.data[0] == NAND_MFR_TOSHIBA && nand_is_slc(chip) && - (id_data[5] & 0x7) == 0x6 /* 24nm */ && - !(id_data[4] & 0x80) /* !BENAND */) { + (chip->id.data[5] & 0x7) == 0x6 /* 24nm */ && + !(chip->id.data[4] & 0x80) /* !BENAND */) { mtd->oobsize = 32 * mtd->writesize >> 9; } @@ -4294,9 +4292,9 @@ 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]) + struct nand_flash_dev *type) { - int maf_id = id_data[0]; + int maf_id = chip->id.data[0]; mtd->erasesize = type->erasesize; mtd->writesize = type->pagesize; @@ -4311,11 +4309,11 @@ static void nand_decode_id(struct mtd_info *mtd, struct nand_chip *chip, * listed in nand_ids table. * Data sheet (5 byte ID): Spansion S30ML-P ORNAND (p.39) */ - if (maf_id == NAND_MFR_AMD && id_data[4] != 0x00 && id_data[5] == 0x00 - && id_data[6] == 0x00 && id_data[7] == 0x00 + if (maf_id == NAND_MFR_AMD && chip->id.data[4] != 0x00 && chip->id.data[5] == 0x00 + && chip->id.data[6] == 0x00 && chip->id.data[7] == 0x00 && mtd->writesize == 512) { mtd->erasesize = 128 * 1024; - mtd->erasesize <<= ((id_data[3] & 0x03) << 1); + mtd->erasesize <<= ((chip->id.data[3] & 0x03) << 1); } } @@ -4325,9 +4323,9 @@ static void nand_decode_id(struct mtd_info *mtd, struct nand_chip *chip, * page size, cell-type information). */ static void nand_decode_bbm_options(struct mtd_info *mtd, - struct nand_chip *chip, u8 id_data[8]) + struct nand_chip *chip) { - int maf_id = id_data[0]; + int maf_id = chip->id.data[0]; /* Set the bad block position */ if (mtd->writesize > 512 || (chip->options & NAND_BUSWIDTH_16)) @@ -4362,14 +4360,14 @@ 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) + struct nand_flash_dev *type) { - if (!strncmp((char *)type->id, (char *)id_data, type->id_len)) { + if (!strncmp((char *)type->id, (char *)chip->id.data, type->id_len)) { mtd->writesize = type->pagesize; mtd->erasesize = type->erasesize; mtd->oobsize = type->oobsize; - chip->bits_per_cell = nand_get_bits_per_cell(id_data[2]); + chip->bits_per_cell = nand_get_bits_per_cell(chip->id.data[2]); chip->chipsize = (uint64_t)type->chipsize << 20; chip->options |= type->options; chip->ecc_strength_ds = NAND_ECC_STRENGTH(type); @@ -4395,7 +4393,7 @@ struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, { int busw, ret; int maf_idx; - u8 id_data[8]; + u8 *id_data = chip->id.data; /* * Reset the chip, required by some chips (e.g. Micron MT29FxGxxxxx) @@ -4453,9 +4451,11 @@ struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, */ chip->options &= ~NAND_BUSWIDTH_16; + chip->id.len = nand_id_len(id_data, ARRAY_SIZE(chip->id.data)); + for (; type->name != NULL; type++) { if (is_full_id_nand(type)) { - if (find_full_id_nand(mtd, chip, type, id_data)) + if (find_full_id_nand(mtd, chip, type)) goto ident_done; } else if (*dev_id == type->dev_id) { break; @@ -4483,9 +4483,9 @@ 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); + nand_decode_ext_id(mtd, chip); } else { - nand_decode_id(mtd, chip, type, id_data); + nand_decode_id(mtd, chip, type); } /* Get chip options */ @@ -4523,7 +4523,7 @@ ident_done: return ERR_PTR(-EINVAL); } - nand_decode_bbm_options(mtd, chip, id_data); + nand_decode_bbm_options(mtd, chip); /* Calculate the address shift from the page size */ chip->page_shift = ffs(mtd->writesize) - 1; diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h index 3417ca2a0d..f2c6a978cb 100644 --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -507,6 +507,19 @@ static inline void nand_hw_control_init(struct nand_hw_control *nfc) init_waitqueue_head(&nfc->wq); } +/* The maximum expected count of bytes in the NAND ID sequence */ +#define NAND_MAX_ID_LEN 8 + +/** + * struct nand_id - NAND id structure + * @data: buffer containing the id bytes. + * @len: ID length. + */ +struct nand_id { + u8 data[NAND_MAX_ID_LEN]; + int len; +}; + /** * struct nand_ecc_step_info - ECC step information of ECC engine * @stepsize: data bytes per ECC step @@ -888,6 +901,8 @@ nand_get_sdr_timings(const struct nand_data_interface *conf) struct nand_chip { struct mtd_info mtd; + struct nand_id id; + void __iomem *IO_ADDR_R; void __iomem *IO_ADDR_W; From patchwork Thu Jul 14 14:35:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2169 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 336E53F066 for ; Thu, 14 Jul 2022 16:35:58 +0200 (CEST) Received: by mail-wm1-f70.google.com with SMTP id 83-20020a1c0256000000b003a2d01897e4sf730236wmc.9 for ; Thu, 14 Jul 2022 07:35:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657809358; cv=pass; d=google.com; s=arc-20160816; b=sHkUAANChPEHQYqDMX/3nE06Z1Ju7frS0BaHiLgJ+6eHAJI1sSLDvR+PI/BkrPDkeQ T21+TPrVz9nJ7wA4T79HNoZ9jhMDN8lE3EWaWoIXS83srpdzmyahly27HHO6T3K9hMYi AMpLaiaIA33UB1edlHdqQcu3sV7Qpv1QN/7c9xngKEQ5aHGwo6OUgG4/MzF2S5R81AZ3 kMTqVNXF6Zo1kbbzJ5nF4nhKzKOLZl+n6yH1MSe8WgNwrdROjf+1P3YLSI4z31H8wbZx lWBXzfK6hIlkRYRpkC/IAF5pxmdxWhYyXw9NMS3ixMZm70fwEZrhe9ouoUQ17PgXiTiv +Zmw== 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=Z+M1ItdFJHYx2BwAoYAsuhoRsY+QaBLWxfpo4/jPYQA=; b=VvWNEDw8LWFaEmLhGW/Wd2u/cVLhkjhfLc+00bocoCJfGjBtKotuQO3Mq8qWDpB0O9 eNQqeeqp1MjKg3hp11iNtOJxkwvDPqOVwNMAB1HECHgClWEDllIQgozqcUEajNXZmSU1 hOS9AZR2BcGjVczeHd1koyP+hDe/kex54QyspqUJspFUxjL+kuWopspdDkY+IYv6UEiB WnvEOjE7U4bny+zvJSs4hCaEqBz8268PTFn1EM1NgkeleH/739KEQMeZ3XO2He3c9j/3 mLHigE+JVzgavSZBCSa3B0VwF3EOZxl0XsvV2hsSMDTpS/l47zVoynPj8/cPYhQdlz8l T1hw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=T7CT7Sgb; 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=Z+M1ItdFJHYx2BwAoYAsuhoRsY+QaBLWxfpo4/jPYQA=; b=iuC4rsE+28k8NfKVvKgXd+6Z0ZD4qwvoNvjiX0lwrmQFC8P8rRkLScGJ0IiTYnq67T P1DiPKx0SRjPrZJq11qHBI+nloYkpGtX7qHS/Npb3QaxWTttDLnwiHYAyvn0V5F9CQjU pQEpNV5ane3Dw3gwuM68kpMVC2MNVdgfd60Xo= 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=Z+M1ItdFJHYx2BwAoYAsuhoRsY+QaBLWxfpo4/jPYQA=; b=NQKnhXlWKc8eObZNxSFlSRXKptRcsGvSIQZ80ZBGx29T+LB06njfkvsJH+byKjHnpc yB/+BdwcB7EmTUfPX2BlwdVI0AAs1P9VifCsI7OaeJKuVx7u7bq34fRzw8XKhGct/1nZ rr1zYgWotjA/38Bw9H7Y1XrgUajlhsc29k4LCzcZ3NQpuySA7n87ZuQDXm1rbT/2lmhN 1sGjSBupq0mer+qJACZjZ1TFe7CDZGk+SH/GbNRmfGCiV/gEqI1EV9a+5ZMDKWEIL9Mv UAdOwyKvynekcMWcs09CS9sgbPezFY2lyaw2qj4lsemx7Em1nR2lV1sZdf1AvPxTm9x6 EM+A== X-Gm-Message-State: AJIora9gXDVz4khhM97qc8xSoyqL7pwx2tlofikrdYWS+n4lFc11ikxf tQFM/5pf7LlLp8EABNmz+ROxSPgo X-Google-Smtp-Source: AGRyM1tv9/Pff4zhfoj01IolvUbQ70aaU0gylQ8qwrIyDEIKPBlPD257pz78YhzDSocwiXyCqvzEUg== X-Received: by 2002:a05:600c:3b96:b0:3a2:e0ae:f127 with SMTP id n22-20020a05600c3b9600b003a2e0aef127mr15204639wms.64.1657809357892; Thu, 14 Jul 2022 07:35:57 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:600c:34c6:b0:3a0:4f27:977f with SMTP id d6-20020a05600c34c600b003a04f27977fls4515698wmq.2.gmail; Thu, 14 Jul 2022 07:35:56 -0700 (PDT) X-Received: by 2002:a05:600c:4f14:b0:3a2:e8be:c184 with SMTP id l20-20020a05600c4f1400b003a2e8bec184mr15630844wmq.34.1657809356674; Thu, 14 Jul 2022 07:35:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657809356; cv=none; d=google.com; s=arc-20160816; b=KoR7Txw7eMgbIzY8jIoxcafPP5Lt/S1jzznWk49ZMRfT0mUzQ0c2gs9zW+kZkRDeWJ nflGyro34ovDOTeV9Mn7LJs7vUqVhyVoVkX8hpXiqFCk5lCQqaikxLRJAB57u1o/IM48 PwwHKdDDaU1uhChgIKUaOyOzFwZhRpKbcBYuM6Ivfk0R/6r2ndk4lNLkXNJBBjhYiJXE S0SncY7wT4aQ/uWM9hRmZ0ExqsDgNhmydhwAiuxxQC7iYRM/yqhPPjZRWOmOkd0vU6PP GZJX/jplQKZJzUentkkVxr/mvo9hEdFzwkBUwqMZjaR3yFhkGZQ5iR4dxl1uXKyUpTXP yu0Q== 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=7/o+mGV8ywUVtQz4G7CKHG/IM0njUkMjI+CMpXHKhCc=; b=Ny13K6YxviJX4Lo5AucFhCsLtwNpPNCUcWQDtum/bEzDm2u93swqMIXJ9deQ4aujLd VZKNAmOrrjHOiHrqdBXlnC8jrM4JKRTCmJAC/xNJR5A/bPOqnHSbihRW0gUfE6slJFc1 DahfUPcIJki5X8xfvbhafQ1C/ZeC5n78cS93sQMJElZrsHPeCkK9SR5uQmQ0us1V+wvX D7hLpKAmARQY4BTiL9/vEEB8eNG0Vu95ptzq5pEXsxALxhDz1oJ/ezHVhHioG+ZXRrjy oyQ/rTlWL6VkRb2MARpOjZ3idEncbRCfZjuKhogkMIy8Nsi07J31OHnxdUsrniB4DDrk XRpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=T7CT7Sgb; 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 d27-20020adf9b9b000000b0021d6b86ee07sor898996wrc.28.2022.07.14.07.35.56 for (Google Transport Security); Thu, 14 Jul 2022 07:35:56 -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:dd0d:0:b0:21d:666b:298e with SMTP id a13-20020adfdd0d000000b0021d666b298emr8703565wrm.412.1657809355910; Thu, 14 Jul 2022 07:35:55 -0700 (PDT) Received: from panicking.. ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003973c54bd69sm5712357wmq.1.2022.07.14.07.35.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 07:35:55 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai , Boris Brezillon , Richard Weinberger , Patrice Chotard , Marek Vasut , Wolfgang Denk , u-boot@lists.denx.de (open list) Cc: Boris Brezillon , u-boot@lists.denx.de (open list) Subject: [PATCH 03/11] mtd: nand: Add manufacturer specific initialization/detection steps Date: Thu, 14 Jul 2022 16:35:35 +0200 Message-Id: <20220714143543.448991-4-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=T7CT7Sgb; 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 abbe26d144ec22bb067fa414d717b9f7ca2e12bd A lot of NANDs are implementing generic features in a non-generic way, or are providing advanced auto-detection logic where the NAND ID bytes meaning changes with the NAND generation. Providing this vendor specific initialization step will allow us to get rid of full-id entries in the nand_ids table or all the vendor specific cases added over the time in the generic NAND ID decoding logic. Signed-off-by: Boris Brezillon Signed-off-by: Michael Trimarchi --- drivers/mtd/nand/raw/nand_base.c | 90 +++++++++++++++++++++++++------- include/linux/mtd/rawnand.h | 30 +++++++++++ 2 files changed, 102 insertions(+), 18 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 4a78770a25..3b9c78cb24 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -4286,6 +4286,39 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip) } } +/* + * Manufacturer detection. Only used when the NAND is not ONFI or JEDEC + * compliant and does not have a full-id or legacy-id entry in the nand_ids + * table. + */ +static void nand_manufacturer_detect(struct mtd_info *mtd, struct nand_chip *chip) +{ + /* + * Try manufacturer detection if available and use + * nand_decode_ext_id() otherwise. + */ + if (chip->manufacturer.desc && chip->manufacturer.desc->ops && + chip->manufacturer.desc->ops->detect) + chip->manufacturer.desc->ops->detect(chip); + else + nand_decode_ext_id(mtd, chip); +} + +/* + * Manufacturer initialization. This function is called for all NANDs including + * ONFI and JEDEC compliant ones. + * Manufacturer drivers should put all their specific initialization code in + * their ->init() hook. + */ +static int nand_manufacturer_init(struct nand_chip *chip) +{ + if (!chip->manufacturer.desc || !chip->manufacturer.desc->ops || + !chip->manufacturer.desc->ops->init) + return 0; + + return chip->manufacturer.desc->ops->init(chip); +} + /* * Old devices have chip data hardcoded in the device ID table. nand_decode_id * decodes a matching ID table entry and assigns the MTD size parameters for @@ -4383,6 +4416,26 @@ static bool find_full_id_nand(struct mtd_info *mtd, struct nand_chip *chip, return false; } +/** + * nand_get_manufacturer_desc - Get manufacturer information from the + * manufacturer ID + * @id: manufacturer ID + * + * Returns a nand_manufacturer_desc object if the manufacturer is defined + * in the NAND manufacturers database, NULL otherwise. + */ +static const struct nand_manufacturers *nand_get_manufacturer_desc(u8 id) +{ + int i; + + for (i = 0; nand_manuf_ids[i].id != 0x0; i++) { + if (nand_manuf_ids[i].id == id) + return &nand_manuf_ids[i]; + } + + return NULL; +} + /* * Get the flash and manufacturer id and lookup if the type is supported. */ @@ -4391,8 +4444,8 @@ struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, int *maf_id, int *dev_id, struct nand_flash_dev *type) { + const struct nand_manufacturers *manufacturer_desc; int busw, ret; - int maf_idx; u8 *id_data = chip->id.data; /* @@ -4433,6 +4486,12 @@ struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, return ERR_PTR(-ENODEV); } + chip->id.len = nand_id_len(id_data, ARRAY_SIZE(chip->id.data)); + + /* Try to identify manufacturer */ + manufacturer_desc = nand_get_manufacturer_desc(*maf_id); + chip->manufacturer.desc = manufacturer_desc; + if (!type) type = nand_flash_ids; @@ -4451,8 +4510,6 @@ struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, */ chip->options &= ~NAND_BUSWIDTH_16; - chip->id.len = nand_id_len(id_data, ARRAY_SIZE(chip->id.data)); - for (; type->name != NULL; type++) { if (is_full_id_nand(type)) { if (find_full_id_nand(mtd, chip, type)) @@ -4482,8 +4539,7 @@ struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, chip->chipsize = (uint64_t)type->chipsize << 20; if (!type->pagesize) { - /* Decode parameters from extended ID */ - nand_decode_ext_id(mtd, chip); + nand_manufacturer_detect(mtd, chip); } else { nand_decode_id(mtd, chip, type); } @@ -4499,12 +4555,6 @@ struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, chip->options &= ~NAND_SAMSUNG_LP_OPTIONS; ident_done: - /* Try to identify manufacturer */ - for (maf_idx = 0; nand_manuf_ids[maf_idx].id != 0x0; maf_idx++) { - if (nand_manuf_ids[maf_idx].id == *maf_id) - break; - } - if (chip->options & NAND_BUSWIDTH_AUTO) { WARN_ON(chip->options & NAND_BUSWIDTH_16); chip->options |= busw; @@ -4516,7 +4566,7 @@ ident_done: */ pr_info("device found, Manufacturer ID: 0x%02x, Chip ID: 0x%02x\n", *maf_id, *dev_id); - pr_info("%s %s\n", nand_manuf_ids[maf_idx].name, mtd->name); + pr_info("%s %s\n", manufacturer_desc->name, mtd->name); pr_warn("bus width %d instead %d bit\n", (chip->options & NAND_BUSWIDTH_16) ? 16 : 8, busw ? 16 : 8); @@ -4549,28 +4599,32 @@ ident_done: if (mtd->writesize > 512 && chip->cmdfunc == nand_command) chip->cmdfunc = nand_command_lp; + ret = nand_manufacturer_init(chip); + if (ret) + return ERR_PTR(ret); + pr_info("device found, Manufacturer ID: 0x%02x, Chip ID: 0x%02x\n", *maf_id, *dev_id); #ifdef CONFIG_SYS_NAND_ONFI_DETECTION if (chip->onfi_version) - pr_info("%s %s\n", nand_manuf_ids[maf_idx].name, + pr_info("%s %s\n", manufacturer_desc->name, chip->onfi_params.model); else if (chip->jedec_version) - pr_info("%s %s\n", nand_manuf_ids[maf_idx].name, + pr_info("%s %s\n", manufacturer_desc->name, chip->jedec_params.model); else - pr_info("%s %s\n", nand_manuf_ids[maf_idx].name, + pr_info("%s %s\n", manufacturer_desc->name, type->name); #else if (chip->jedec_version) - pr_info("%s %s\n", nand_manuf_ids[maf_idx].name, + pr_info("%s %s\n", manufacturer_desc->name, chip->jedec_params.model); else - pr_info("%s %s\n", nand_manuf_ids[maf_idx].name, + pr_info("%s %s\n", manufacturer_desc->name, type->name); - pr_info("%s %s\n", nand_manuf_ids[maf_idx].name, + pr_info("%s %s\n", manufacturer_desc->name, type->name); #endif diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h index f2c6a978cb..57fe7fb47b 100644 --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -796,6 +796,17 @@ nand_get_sdr_timings(const struct nand_data_interface *conf) return &conf->timings.sdr; } +/** + * struct nand_manufacturer_ops - NAND Manufacturer operations + * @detect: detect the NAND memory organization and capabilities + * @init: initialize all vendor specific fields (like the ->read_retry() + * implementation) if any. + */ +struct nand_manufacturer_ops { + void (*detect)(struct nand_chip *chip); + int (*init)(struct nand_chip *chip); +}; + /** * struct nand_chip - NAND Private Flash Chip Data * @mtd: MTD device registered to the MTD framework @@ -897,6 +908,7 @@ nand_get_sdr_timings(const struct nand_data_interface *conf) * devices. * @priv: [OPTIONAL] pointer to private chip data * @write_page: [REPLACEABLE] High-level page write function + * @manufacturer: [INTERN] Contains manufacturer information */ struct nand_chip { @@ -983,6 +995,11 @@ struct nand_chip { struct nand_bbt_descr *badblock_pattern; void *priv; + + struct { + const struct nand_manufacturers *desc; + void *priv; + } manufacturer; }; static inline void nand_set_flash_node(struct nand_chip *chip, @@ -1016,6 +1033,17 @@ static inline void nand_set_controller_data(struct nand_chip *chip, void *priv) chip->priv = priv; } +static inline void nand_set_manufacturer_data(struct nand_chip *chip, + void *priv) +{ + chip->manufacturer.priv = priv; +} + +static inline void *nand_get_manufacturer_data(struct nand_chip *chip) +{ + return chip->manufacturer.priv; +} + /* * NAND Flash Manufacturer ID Codes */ @@ -1120,10 +1148,12 @@ struct nand_flash_dev { * struct nand_manufacturers - NAND Flash Manufacturer ID Structure * @name: Manufacturer name * @id: manufacturer ID code of device. + * @ops: manufacturer operations */ struct nand_manufacturers { int id; char *name; + const struct nand_manufacturer_ops *ops; }; extern struct nand_flash_dev nand_flash_ids[]; From patchwork Thu Jul 14 14:35:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2170 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 4561F3F066 for ; Thu, 14 Jul 2022 16:36:01 +0200 (CEST) Received: by mail-wm1-f69.google.com with SMTP id 130-20020a1c0288000000b003a2fe999093sf1851603wmc.6 for ; Thu, 14 Jul 2022 07:36:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657809361; cv=pass; d=google.com; s=arc-20160816; b=DJGrAFYhqLaZlJ4ZoEteaRBETpmetnJgEq4VgTUWrT5dz14xPAvr5Gi5ba+7UM+Mmy N7Pf+rbwpYmRogF/YAAknkfjBdcUk8wbPqI8/zGVaipVHTZYJTPNsC9Ls3iAET527Koh S5hxtF5swaLZwWunuy7KtMkMoyefzZlP5EeaH+RuTmUafB6R05q+q69Lv78gECxS2jiJ x2YrljZXv3PZKZewPhplDoHIUHY4sat/Clb/fJj10XUH/XsTG0VS80WF6rzCotqwxkFq FDqzw/5aOzTmYV968E3BVt3M0lXUqXvC62s5PQl3kNg/ecdDOkdNz7F8aCkUdim6MOka Ut6w== 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=bWsYoxh4EGG5Y6a44K3Swhi9kgqogfWRi+rHQcZlZ34=; b=E1m8PDbvISRWogv9CGzZLEVxHqFLX2k3br+yf+R1tl6lwI0wK12SKYEoyjJYcFUAAB Y5gvpePWL6t6s8C/XM684a+GZyYxyw7bMri6TPZdJhTArLIcsONpKbPav6nG7xBs2khG sLt1p/5kC0YyJ8oSwmFC7fHsj9X1QdRPJILBrFA2IObpm2pp5UHcSuzM03XqHI85Ohpk pNuQBwY7/wsqOBKe9+dkyEwVf2oqwBvyHec1JqdDsOmC8WcTb7+EappVeZH+pi2I/JaV GGrbzBSOFbVp2krbbX8yHEnX40BxhiE43Nf5OUq0yWDKapyJTMteq7wx379U3yt3/rj1 mdRA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="hn/bpe60"; 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=bWsYoxh4EGG5Y6a44K3Swhi9kgqogfWRi+rHQcZlZ34=; b=rclIxRhQQ3PMCmtLSzTRRO1J+DGYwTMI6gwiI4VMYxngG0f5b+iv7BUD8BOQUWfnT8 Z276aEQh92AY+/ejiSDj3vhEOnlajZmCcFJD4YxsLr9LI1w+O9cWmVon/rGMfL29cKRs 2ae3DbrAW1IK7MJVTP9yD1DGG72dDrDoVUmdY= 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=bWsYoxh4EGG5Y6a44K3Swhi9kgqogfWRi+rHQcZlZ34=; b=WrnYY0FH+/jxeRt/Q2VVx2mkGK3oaRJq0uKehuiYccDLoMaHh8/Fshlb0dJDxA1TnA VToo/6sDlnkz5U9TneimndqaRYsTZfP8C0wMUU388Hovo/ak8/WDixiKjGQeGUTOoUlr uxiG6J29C5M+RBy0x3mA72HWu4gqM2/46okcgNpOvER/VqmU1PvGUOPplrL1g5kUPxXA hKfRzPoni4Jl/dZXfHJLK9ySb/QmG6zeQ+6pL8T8uXYZKLbsE0txhBd82QZZzlyEB5iB BeBqiNTAU3vLtJFreMavxm2KHyXPTVqC/n44SLg4/Q/Mg57YGFfngn43Op80SYZhcWbU vAIA== X-Gm-Message-State: AJIora9sVnPnrw4la+CNzMYWUJw/7SANper3cqHYm5Iy753G4kl7pqvI uShm0lyxvredUoGS8iLmLL6EuGLh X-Google-Smtp-Source: AGRyM1v24evZ/uezD+MVIe56+SBI1TX1TbClYUOBe9gfwrRY0J30E33BX4iBZKjEGQ1RhBCs7xgTng== X-Received: by 2002:a05:600c:3b17:b0:3a2:ee46:e312 with SMTP id m23-20020a05600c3b1700b003a2ee46e312mr15153537wms.49.1657809361073; Thu, 14 Jul 2022 07:36:01 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a5d:588d:0:b0:21d:339f:dc1 with SMTP id n13-20020a5d588d000000b0021d339f0dc1ls242428wrf.0.gmail; Thu, 14 Jul 2022 07:36:00 -0700 (PDT) X-Received: by 2002:a5d:4c49:0:b0:21d:6df5:beb7 with SMTP id n9-20020a5d4c49000000b0021d6df5beb7mr8609960wrt.286.1657809359787; Thu, 14 Jul 2022 07:35:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657809359; cv=none; d=google.com; s=arc-20160816; b=CGuPDb2Fu8XLQLbqTeD+SU2Ycta7+/d3Qx6ScWEtD5U4AQEarKjd/Vf6a1CAYB4XY3 NDwcXEweeBsgHBZrk3fjyljnRY7jEZ37jzyjQp5raWPv9QyrquqpVniL/jx8kZqLcXbi BiLRMGNL/4YsT1KDTjsXhna9AepFVxGmgyxPQxRSyquqHdQYtM0xPYWnwwNSMkRFZ5vj v1WHJvKjTigI4VuZ+7e3lJi3zrPRgMIlNrWKUwbyWwjsWhNBFZlhDAhrUEnbX2j0n/BD M/pXDdUQzMgrkBpl+f+vR1FtDuJnUEgMvAtr6aEAdEi6swzmRbk/ttyQt6luS69Lkr2z gNCA== 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=8r1tMsApi1aj9SR1CafRswHj8lBfItFykhvwhV0futo=; b=ifq5/yZH1wc2tKgDhbo+uokwApMTVLIDvyD4WDtRyGtAGghRkG6Jw4rQoIKmo4vqi8 G/rJAuREraWKenWbqTkwwNPwuX3iO25c9rH/LW1y9fntJAqNHzKkl+6ZrymRKZTUVL87 Fh4Iym0WgTerCyDVH56jvqkGGFSVhGsHbvLM9U1aUfRAk2ETfw4V3o5owH9y3vRxzgLm TjjWJuo76fgonrIbtUSIB4quxUQ10+w5UPGQ8SBpZarm+vF/fU+Ebt33bnuqZ2efcrDn uU5j8MtrIehICshxGC/vC1ZxpP3cyrU4ppZ5NP/h0MnVQKxxGdPQG1offjw2jeGLx9Zi fjrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="hn/bpe60"; 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 az12-20020a05600c600c00b003a2f1edf4f0sor2630272wmb.0.2022.07.14.07.35.59 for (Google Transport Security); Thu, 14 Jul 2022 07:35:59 -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:4e8f:b0:3a1:8b21:ebbc with SMTP id f15-20020a05600c4e8f00b003a18b21ebbcmr9635135wmq.149.1657809359053; Thu, 14 Jul 2022 07:35:59 -0700 (PDT) Received: from panicking.. ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003973c54bd69sm5712357wmq.1.2022.07.14.07.35.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 07:35:58 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai , Boris Brezillon , Richard Weinberger , Patrice Chotard , Marek Vasut , Wolfgang Denk , u-boot@lists.denx.de (open list) Cc: u-boot@lists.denx.de (open list) Subject: [PATCH 04/11] mtd: nand: Get rid of mtd variable in function calls Date: Thu, 14 Jul 2022 16:35:36 +0200 Message-Id: <20220714143543.448991-5-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="hn/bpe60"; 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: , chip points to mtd. Passing chip is enough to have a reference to mtd when is necessary Signed-off-by: Michael Trimarchi --- drivers/mtd/nand/raw/nand_base.c | 20 +++++++++++--------- include/linux/mtd/rawnand.h | 3 +-- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 3b9c78cb24..7d52372af5 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -4160,8 +4160,9 @@ static int nand_get_bits_per_cell(u8 cellinfo) * chip. The rest of the parameters must be decoded according to generic or * manufacturer-specific "extended ID" decoding patterns. */ -static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip) +static void nand_decode_ext_id(struct nand_chip *chip) { + struct mtd_info *mtd = &chip->mtd; int extid, id_len; /* The 3rd id byte holds MLC / multichip data */ chip->bits_per_cell = nand_get_bits_per_cell(chip->id.data[2]); @@ -4291,7 +4292,7 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip) * compliant and does not have a full-id or legacy-id entry in the nand_ids * table. */ -static void nand_manufacturer_detect(struct mtd_info *mtd, struct nand_chip *chip) +static void nand_manufacturer_detect(struct nand_chip *chip) { /* * Try manufacturer detection if available and use @@ -4301,7 +4302,7 @@ static void nand_manufacturer_detect(struct mtd_info *mtd, struct nand_chip *chi chip->manufacturer.desc->ops->detect) chip->manufacturer.desc->ops->detect(chip); else - nand_decode_ext_id(mtd, chip); + nand_decode_ext_id(chip); } /* @@ -4324,9 +4325,10 @@ static int nand_manufacturer_init(struct nand_chip *chip) * decodes a matching ID table entry and assigns the MTD size parameters for * the chip. */ -static void nand_decode_id(struct mtd_info *mtd, struct nand_chip *chip, +static void nand_decode_id(struct nand_chip *chip, struct nand_flash_dev *type) { + struct mtd_info *mtd = &chip->mtd; int maf_id = chip->id.data[0]; mtd->erasesize = type->erasesize; @@ -4439,11 +4441,11 @@ static const struct nand_manufacturers *nand_get_manufacturer_desc(u8 id) /* * Get the flash and manufacturer id and lookup if the type is supported. */ -struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, - struct nand_chip *chip, +struct nand_flash_dev *nand_get_flash_type(struct nand_chip *chip, int *maf_id, int *dev_id, struct nand_flash_dev *type) { + struct mtd_info *mtd = &chip->mtd; const struct nand_manufacturers *manufacturer_desc; int busw, ret; u8 *id_data = chip->id.data; @@ -4539,9 +4541,9 @@ struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, chip->chipsize = (uint64_t)type->chipsize << 20; if (!type->pagesize) { - nand_manufacturer_detect(mtd, chip); + nand_manufacturer_detect(chip); } else { - nand_decode_id(mtd, chip, type); + nand_decode_id(chip, type); } /* Get chip options */ @@ -4731,7 +4733,7 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips, nand_set_defaults(chip, chip->options & NAND_BUSWIDTH_16); /* Read the flash type */ - type = nand_get_flash_type(mtd, chip, &nand_maf_id, + type = nand_get_flash_type(chip, &nand_maf_id, &nand_dev_id, table); if (IS_ERR(type)) { diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h index 57fe7fb47b..d8141cb4d1 100644 --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -29,8 +29,7 @@ struct nand_flash_dev; struct device_node; /* Get the flash and manufacturer id and lookup if the type is supported. */ -struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, - struct nand_chip *chip, +struct nand_flash_dev *nand_get_flash_type(struct nand_chip *chip, int *maf_id, int *dev_id, struct nand_flash_dev *type); From patchwork Thu Jul 14 14:35:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2171 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 5D8C83F066 for ; Thu, 14 Jul 2022 16:36:04 +0200 (CEST) Received: by mail-wm1-f70.google.com with SMTP id h189-20020a1c21c6000000b003a2fdf9bd2asf731717wmh.8 for ; Thu, 14 Jul 2022 07:36:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657809364; cv=pass; d=google.com; s=arc-20160816; b=PcCYSQp3q3ba6TT4Hcug5TVFSIHJFg0M4bb6hcXlV13WVbVUGhNrNVKdyIc6Ew5agu /TxRWfwU31zGLlgeptCIJmG6QhoOP+FnDlNtG1F/JM7rwMdcZ2ZRw80uXHHfyrrE6YSz 4/jnVErvqjzJ91qVwaFSKU9+QCmPicSG+F15R10mQwMuv4hrTNphcXbiAZ0iJnyo5Vaz r0l8MhzVJjzcNU5vyH4eDdC8eIROy5OOXI8ye/oVYvRH0uHY1uBMuXa4h5Zonjkpw/79 XCC52MiSU2u0boftnLh54vtOMLXhzlOxaEMM08+UUzqE1FdTxQO8mwGMdflFlTzO7UY+ HPDg== 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=pjsaOc5d3VSwvcEV367KBzy/ZYpzrfF+OATXAPBNDNo=; b=d9QSMoEiyetsUfqqzQTv9otZ6lQN7Ck/DhIyIjMSSxRhNUnBXiqiVefgNfbQ/kHoV1 QQxnJJfzLTP1BHzkisT4C/wNBqCjL0tt73Z3jPX49MabxhX7wodDf67YEjFcGmWCCAmg 4VSW9ousqXH8eOCWd1g0cpAJESRnjKNQm3pX5j93N925NSoPZrVklzHWC7jZ1uCxiFRS AA67RApgJ+17/Oj5c/dL+MxmDtiIuyuivKM4xdVK2uLWpYgcPIWu+P6IRM/M9C3usthr HdOmnV2e3BwSkcIpYbrgwc57ZZGz2S8VCIt113D5yvb3mV+nEmkZFsprHatS3x07UK1a ZWqA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=O8wsYyem; 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=pjsaOc5d3VSwvcEV367KBzy/ZYpzrfF+OATXAPBNDNo=; b=LsgOIEnW3r1W/Wey/EhqzCmXllf9tuqsgYY/EV09GYEW1nmA430WKkmc0PJ2H9MCNe pY3N+lH72lU2YONwhD9eh8YOzqTKojh7rcCoIYYgTnJ19iWghQ7tQ1uPNN5yyULYFH98 Kh8taPdJsLu9M9ol42Frag9FVf76In9vCSS0M= 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=pjsaOc5d3VSwvcEV367KBzy/ZYpzrfF+OATXAPBNDNo=; b=m7HTtDkmnqtQuk97Mn4quRLatMjoVWG//r8rngMz9s8G70x5MWoSST4HIdVvl7wM+1 E0YaBMCTtaJyukTZCheK8di1I8E9dq7Sn2zQ+ceMDjmquztUF+5NyYWq7Z7p7RzRcufy rJGV4bH2NtHNArEc1L8SxuTYooja7RCbI5ukSTKd9CGGHRRFsBkAv21NQW8DZjbCqFWE TFPdhNDof9jMrDAbbCbV6xdnnaWhu51zMcVFSPv9Sb8GAzVkEYbut7oegX6gKdpboSH5 IAaS3q7VdmyNv3TSBh1+JjLA3hkylA7l7x6IexDDbP8wQOrJrGiM1h2VvUJCI+94pxxF HZMA== X-Gm-Message-State: AJIora/eh5cWwgiLs2SgTKnu7LL70uVixVeQt2u0tyOa3dxPcuvNUvDC aW3hmIjpYqlNL856VQQUl4TH+h1w X-Google-Smtp-Source: AGRyM1uQK3vCh9PMf0xo/8LZizAe03gqDGNOoZWVuiJX66FtMT1snPPeuNJ2lrug+DGGEYXVIX0CHw== X-Received: by 2002:a05:6000:888:b0:21b:b950:f4bd with SMTP id ca8-20020a056000088800b0021bb950f4bdmr8653175wrb.253.1657809364006; Thu, 14 Jul 2022 07:36:04 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:600c:3b17:b0:3a0:2da0:3609 with SMTP id m23-20020a05600c3b1700b003a02da03609ls4512033wms.1.gmail; Thu, 14 Jul 2022 07:36:02 -0700 (PDT) X-Received: by 2002:a05:600c:17c7:b0:3a3:f1:148c with SMTP id y7-20020a05600c17c700b003a300f1148cmr4129732wmo.32.1657809362680; Thu, 14 Jul 2022 07:36:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657809362; cv=none; d=google.com; s=arc-20160816; b=wOCD5U8F99vM4/2rAMU7Pqc+HgZl63cWTfS0tbgDdqW3df+cqGf7q9It6sISoMJWmH yq/QDpbryZhPeIMaccAxm5r4vpYYmVuabi6lTwArnvoGyANyT+PalVhXImhxYmj+qoIn XgHoaeVQ25iKkD0wOPTKzkBQbY7vxZgykqyU2KeBpb0MI3njaT/ESJAKG7ZdenFdxOop XCTn7g/i7rZSGpPbRQ2UpWYqG+38DKgnNC9ZL/5hvIl8zh86b43+5QdiJHGDKAkwFNto Qz6T7I5mQrw9Wc1cgbyj6RAC0YtH+kqV8WsTRX3xsWuBIDud7DG1a3PI5pssBnMx5bXU xRDQ== 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=GUpIdmojh0UYmi+/gUfiA+lJOYYykzTcKwI0/ILa5BA=; b=aejXKbl7yt3wz7ac0wBXvC/P9RE/oe4cMVfS/WEG9EZnAlXqbA1rkNhA0YyhmO8/nV NWZaHxC0zeDr0zaS9zWJgDvL0mT8wFwouo/+nIgM6xMFr7IpFkMd0vUKb9miq31fkPep so3+1+cxz7IJjDbn34pt3FMqOrEI/KtNupyercXvOcsd26AsIqzQXZ0BBw03gC4MEtA2 Za0Icm3203X8l39NFxJ8ZWUfdchqbZ7bGL9EJbYPrGeRMszDlxeGopI9emAlh8cm0Ib9 Qg2JnxhNV8Fb8BquWd6xhAEpZkZDhS1wzxD8gsyyNPjwFkcCo8VADCsPpORhM8SucJhs H5zQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=O8wsYyem; 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 184-20020a1c02c1000000b003a3008806c2sor624716wmc.40.2022.07.14.07.36.02 for (Google Transport Security); Thu, 14 Jul 2022 07:36:02 -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:a1c:750e:0:b0:3a2:b42f:ec2c with SMTP id o14-20020a1c750e000000b003a2b42fec2cmr15709361wmc.153.1657809362003; Thu, 14 Jul 2022 07:36:02 -0700 (PDT) Received: from panicking.. ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003973c54bd69sm5712357wmq.1.2022.07.14.07.35.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 07:36:01 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai , Boris Brezillon , Richard Weinberger , Patrice Chotard , Wolfgang Denk , u-boot@lists.denx.de (open list) Cc: u-boot@lists.denx.de (open list) Subject: [PATCH 05/11] mtd: nand: Export symbol nand_decode_ext_id Date: Thu, 14 Jul 2022 16:35:37 +0200 Message-Id: <20220714143543.448991-6-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=O8wsYyem; 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: , In preparation of moving specific nand support that are not jedec or onfi Signed-off-by: Michael Trimarchi --- drivers/mtd/nand/raw/nand_base.c | 3 ++- include/linux/mtd/rawnand.h | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 7d52372af5..4cb38378f4 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -4160,7 +4160,7 @@ static int nand_get_bits_per_cell(u8 cellinfo) * chip. The rest of the parameters must be decoded according to generic or * manufacturer-specific "extended ID" decoding patterns. */ -static void nand_decode_ext_id(struct nand_chip *chip) +void nand_decode_ext_id(struct nand_chip *chip) { struct mtd_info *mtd = &chip->mtd; int extid, id_len; @@ -4286,6 +4286,7 @@ static void nand_decode_ext_id(struct nand_chip *chip) } } +EXPORT_SYMBOL_GPL(nand_decode_ext_id); /* * Manufacturer detection. Only used when the NAND is not ONFI or JEDEC diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h index d8141cb4d1..8fb2a43296 100644 --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -1374,4 +1374,7 @@ int nand_read_data_op(struct nand_chip *chip, void *buf, unsigned int len, int nand_write_data_op(struct nand_chip *chip, const void *buf, unsigned int len, bool force_8bit); +/* Default extended ID decoding function */ +void nand_decode_ext_id(struct nand_chip *chip); + #endif /* __LINUX_MTD_RAWNAND_H */ From patchwork Thu Jul 14 14:35:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2172 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 87D133F066 for ; Thu, 14 Jul 2022 16:36:07 +0200 (CEST) Received: by mail-wr1-f69.google.com with SMTP id h29-20020adfaa9d000000b0021d67fc0b4asf601146wrc.9 for ; Thu, 14 Jul 2022 07:36:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657809367; cv=pass; d=google.com; s=arc-20160816; b=O/eUOcWHFDw+x6yXFXHDwu5DEGgHoNo//ytw9t/oQoi1C+n+arz4HxfazcpRlGkPNa aZ6B9pJCIQ6BGeHdlTSHctI74jFnLL1vPP9YWtoTuvpmtZdn73xT9QQkNW615wMctnET HOwRaTb3MQrMXd9vG4F+7Aa5R8WflCYf/JCqJSKQTjJJrx6l3Vj69O+SowcEssZIo3Iw taCLJeyY6ywc/YtMLuzzaTjBJIM6iGgzrj4qy0zSbNwmbBD8Qg/Wuc+gAup8baIquHpD RxiJKNQiXI0CG8cs0RnNNEaDkXJBcRBcpc9i7XpMA4Dm84yk9hdHOWdQHzNXuZL6SNyh aI1g== 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=Z4Za9miDuNc8iaqcB/I0Z0pJsjLu4rXSfpAjBCnI4Ec=; b=upKdUqUvQsX11YFBY6zq487sKYD01cjRxhaw92D00LUwRqJeifu0fq2gX/TZYWvjBq 5Wfmhfp4ahD8iA8RVIqTraS5EE32ahUXO1rTSVfOv0cA4hlU58RH0s+N5UB58qTAlONA jeQhlJ27K2iJS5/MzNBMTsIFPvR6+Ml82FMWkdD4tDwbrAbRy+PGDXhPOiQVCli1pBjc u+KHy8PwQ3nxQfWXAgAAtHT51YmeRgI9GPQp35tKCoVBi8Mw8QY2Ptv7YKsU77RrA27H 2EN4wYXDJAp4xIgIznBrdryqtTMqQk+wXxOP9XOMr6VW3/DhNLVlBOkUlYJ72OegDoKc CxsQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=hOdjk8hx; 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=Z4Za9miDuNc8iaqcB/I0Z0pJsjLu4rXSfpAjBCnI4Ec=; b=rZ3M9Y23wD3evuKFDhh5K9Wal0gvDYv+VMQF81VEbjGn0bnmYP6ldW6em0pGZpqupa xeYxO1Iw0vVGaFegjbYs0llQS4BEZxN+cXKTNELdfOL57p3z046s2umHjvS5knh+ufJG aO9SbLOnrwhfmSP+iVBw3394BEczvOSGgPoK4= 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=Z4Za9miDuNc8iaqcB/I0Z0pJsjLu4rXSfpAjBCnI4Ec=; b=bFfyLV57RnpKE+4CjCz7L6ToldSUPji4vImsLqzA4BZBSF4G5DmmShN5VyNqcYcRJY oRwMqsd0Y5V85XWoeV9jDlgZojrhsIaGNon2uUwT4YTu2cTc834KQ9w/dXAyoBrnU8wI QFZUSGMtGL3CPefISdGg55BsYAbno13pqIoiRKsT4ZasmSQ2DquKtgYtxSZNqtjsbLpF FPc5bT6sL8w/QubnLB0eUyKPLcJi2YC/cM8PmnCsA7mdqfGOv8Rbcp9Ojkwr4fCUs+kb ywyRr/uxBqsMvNk+uge0Rg2EI/RV1eg8QzA34/XC0YlHZ+GXNAsijc8kSfTPh/lMmFhf DHmw== X-Gm-Message-State: AJIora8IUziQCvGDLGC8BbjpbRII++6rwvzVQkNK5emF0700f7XNGIN5 Wry23nlV474ylwvctuQ0OuW12Akm X-Google-Smtp-Source: AGRyM1uvjYsS6p+abbsVMbDgNRjNoMntHw6VSIjb8i0KDXPv+dpcNCN4h+JNgfd/ZoFxEp0VMHdsgw== X-Received: by 2002:a05:600c:2411:b0:3a2:e09a:6cb8 with SMTP id 17-20020a05600c241100b003a2e09a6cb8mr9249631wmp.44.1657809367173; Thu, 14 Jul 2022 07:36:07 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a5d:588d:0:b0:21d:339f:dc1 with SMTP id n13-20020a5d588d000000b0021d339f0dc1ls242834wrf.0.gmail; Thu, 14 Jul 2022 07:36:06 -0700 (PDT) X-Received: by 2002:adf:f64f:0:b0:21d:76c6:d98 with SMTP id x15-20020adff64f000000b0021d76c60d98mr8499485wrp.299.1657809365924; Thu, 14 Jul 2022 07:36:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657809365; cv=none; d=google.com; s=arc-20160816; b=qMRgeXJthnQriBlemGmcLdlxYSlyHtNhSu4ZeowpcZegN/SvEYkhYFfYwW+vnHS+ys 5egZoCKtwJWKtU3EWV8JmjB/SeBpup7BBHhHCdiiLtn4rNlY3n9SiH8oGn4o9+OIEulV Zhl/o1U32QY6tntsMgvB/Uo5ZC2slwJSRdi0Y2wGHhRU/xNXIalLDncw9TCDZOWYiTJ2 2UxuQtYYLmL05YULHahCMSa9LDGue80soqeNefRD5FKNSRRk1OUl1n/n3ty+Wa6opVjv OkYnLuYrjVLYrh3PJi1dtgjU9QVTbXMobOeIPOOZvgsbziz76+bIhcNZZ2Rwl1FuEOWz /r6A== 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=+4va1oQEAtp8P+P8+M1DvWl85yw3nFaxtze8wXVuAkY=; b=l4aqQqpyqGYfoLTp9iSlYpw09pyZ1lSqu+yo5qaSyBs5RIc+xD8GeBW/uFWw2ey6Bl 8D/UqpMZ6ITSVfvYFpKYuXpfvHSXZ1ja5217DMfQKA+LwImwtu09tw+uziZC4riJtMAJ 2x4JAZuxwSiGEJh2UjIhx8fTmBhSuYsJ3IlHCXBluC3co5xPTXweqb6ZpNEMISQAFHV+ lTE11CbY7zWGXmsFTt5//ZYU5tCS0u2Fgmem4MNxX5eEbVULNboiivJm+zxhmqYHzAlI AzwIoMmvmMwzqpBTdIX/Mro1SzgBqekpcgzOqZYYJDD26mvNnmW5TOYL+8apG/r+1cb/ /UdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=hOdjk8hx; 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 o2-20020adfa102000000b0021d765472b4sor878952wro.66.2022.07.14.07.36.05 for (Google Transport Security); Thu, 14 Jul 2022 07:36:05 -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:a5d:4402:0:b0:21d:8093:138c with SMTP id z2-20020a5d4402000000b0021d8093138cmr8497611wrq.535.1657809365132; Thu, 14 Jul 2022 07:36:05 -0700 (PDT) Received: from panicking.. ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003973c54bd69sm5712357wmq.1.2022.07.14.07.36.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 07:36:04 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai , Boris Brezillon , Richard Weinberger , Patrice Chotard , Wolfgang Denk , u-boot@lists.denx.de (open list) Cc: Boris Brezillon , Simon Glass , u-boot@lists.denx.de (open list) Subject: [PATCH 06/11] mtd: nand: Move Samsung specific init/detection logic in nand_samsung.c Date: Thu, 14 Jul 2022 16:35:38 +0200 Message-Id: <20220714143543.448991-7-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=hOdjk8hx; 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 c51d0ac59f24200dfdccc897ff7c3c9446c7599a Move Samsung specific initialization and detection logic into nand_samsung.c. This is part of the "separate vendor specific code from core" cleanup process. Signed-off-by: Boris Brezillon Acked-by: Richard Weinberger Signed-off-by: Michael Trimarchi --- drivers/mtd/nand/raw/Makefile | 3 +- drivers/mtd/nand/raw/nand_base.c | 50 +--------------- drivers/mtd/nand/raw/nand_ids.c | 4 +- drivers/mtd/nand/raw/nand_samsung.c | 90 +++++++++++++++++++++++++++++ include/linux/mtd/rawnand.h | 2 + 5 files changed, 99 insertions(+), 50 deletions(-) create mode 100644 drivers/mtd/nand/raw/nand_samsung.c diff --git a/drivers/mtd/nand/raw/Makefile b/drivers/mtd/nand/raw/Makefile index e3f6b903f7..0e3f017bf6 100644 --- a/drivers/mtd/nand/raw/Makefile +++ b/drivers/mtd/nand/raw/Makefile @@ -14,7 +14,7 @@ obj-$(CONFIG_SPL_NAND_DENALI) += denali_spl.o obj-$(CONFIG_SPL_NAND_SIMPLE) += nand_spl_simple.o obj-$(CONFIG_SPL_NAND_LOAD) += nand_spl_load.o obj-$(CONFIG_SPL_NAND_ECC) += nand_ecc.o -obj-$(CONFIG_SPL_NAND_BASE) += nand_base.o +obj-$(CONFIG_SPL_NAND_BASE) += nand_base.o nand_samsung.o obj-$(CONFIG_SPL_NAND_IDENT) += nand_ids.o nand_timings.o obj-$(CONFIG_TPL_NAND_INIT) += nand.o ifeq ($(CONFIG_SPL_ENV_SUPPORT),y) @@ -31,6 +31,7 @@ obj-y += nand_ids.o obj-y += nand_util.o obj-y += nand_ecc.o obj-y += nand_base.o +obj-y += nand_samsung.o obj-y += nand_timings.o endif # not spl diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 4cb38378f4..7f41395afe 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -4173,47 +4173,12 @@ void nand_decode_ext_id(struct nand_chip *chip) /* * Field definitions are in the following datasheets: * Old style (4,5 byte ID): Samsung K9GAG08U0M (p.32) - * New Samsung (6 byte ID): Samsung K9GAG08U0F (p.44) * Hynix MLC (6 byte ID): Hynix H27UBG8T2B (p.22) * * Check for ID length, non-zero 6th byte, cell type, and Hynix/Samsung * ID to decide what to do. */ - if (id_len == 6 && chip->id.data[0] == NAND_MFR_SAMSUNG && - !nand_is_slc(chip) && chip->id.data[5] != 0x00) { - /* Calc pagesize */ - mtd->writesize = 2048 << (extid & 0x03); - extid >>= 2; - /* Calc oobsize */ - switch (((extid >> 2) & 0x04) | (extid & 0x03)) { - case 1: - mtd->oobsize = 128; - break; - case 2: - mtd->oobsize = 218; - break; - case 3: - mtd->oobsize = 400; - break; - case 4: - mtd->oobsize = 436; - break; - case 5: - mtd->oobsize = 512; - break; - case 6: - mtd->oobsize = 640; - break; - case 7: - default: /* Other cases are "reserved" (unknown) */ - mtd->oobsize = 1024; - break; - } - extid >>= 2; - /* Calc blocksize */ - mtd->erasesize = (128 * 1024) << - (((extid >> 1) & 0x04) | (extid & 0x03)); - } else if (id_len == 6 && chip->id.data[0] == NAND_MFR_HYNIX && + if (id_len == 6 && chip->id.data[0] == NAND_MFR_HYNIX && !nand_is_slc(chip)) { unsigned int tmp; @@ -4375,13 +4340,10 @@ static void nand_decode_bbm_options(struct mtd_info *mtd, * Micron devices with 2KiB pages and on SLC Samsung, Hynix, Toshiba, * AMD/Spansion, and Macronix. All others scan only the first page. */ - if (!nand_is_slc(chip) && - (maf_id == NAND_MFR_SAMSUNG || - maf_id == NAND_MFR_HYNIX)) + if (!nand_is_slc(chip) && maf_id == NAND_MFR_HYNIX) chip->bbt_options |= NAND_BBT_SCANLASTPAGE; else if ((nand_is_slc(chip) && - (maf_id == NAND_MFR_SAMSUNG || - maf_id == NAND_MFR_HYNIX || + (maf_id == NAND_MFR_HYNIX || maf_id == NAND_MFR_TOSHIBA || maf_id == NAND_MFR_AMD || maf_id == NAND_MFR_MACRONIX)) || @@ -4550,12 +4512,6 @@ struct nand_flash_dev *nand_get_flash_type(struct nand_chip *chip, /* Get chip options */ chip->options |= type->options; - /* - * Check if chip is not a Samsung device. Do not clear the - * options for chips which do not have an extended id. - */ - if (*maf_id != NAND_MFR_SAMSUNG && !type->pagesize) - chip->options &= ~NAND_SAMSUNG_LP_OPTIONS; ident_done: if (chip->options & NAND_BUSWIDTH_AUTO) { diff --git a/drivers/mtd/nand/raw/nand_ids.c b/drivers/mtd/nand/raw/nand_ids.c index 2a50f0b214..f4126c3a5a 100644 --- a/drivers/mtd/nand/raw/nand_ids.c +++ b/drivers/mtd/nand/raw/nand_ids.c @@ -10,7 +10,7 @@ #include #include -#define LP_OPTIONS NAND_SAMSUNG_LP_OPTIONS +#define LP_OPTIONS 0 #define LP_OPTIONS16 (LP_OPTIONS | NAND_BUSWIDTH_16) #define SP_OPTIONS NAND_NEED_READRDY @@ -189,7 +189,7 @@ struct nand_flash_dev nand_flash_ids[] = { /* Manufacturer IDs */ struct nand_manufacturers nand_manuf_ids[] = { {NAND_MFR_TOSHIBA, "Toshiba"}, - {NAND_MFR_SAMSUNG, "Samsung"}, + {NAND_MFR_SAMSUNG, "Samsung", &samsung_nand_manuf_ops}, {NAND_MFR_FUJITSU, "Fujitsu"}, {NAND_MFR_NATIONAL, "National"}, {NAND_MFR_RENESAS, "Renesas"}, diff --git a/drivers/mtd/nand/raw/nand_samsung.c b/drivers/mtd/nand/raw/nand_samsung.c new file mode 100644 index 0000000000..3dfbbec382 --- /dev/null +++ b/drivers/mtd/nand/raw/nand_samsung.c @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2017 Free Electrons + * Copyright (C) 2017 NextThing Co + * + * Author: Boris Brezillon + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include + +static void samsung_nand_decode_id(struct nand_chip *chip) +{ + struct mtd_info *mtd = nand_to_mtd(chip); + + /* New Samsung (6 byte ID): Samsung K9GAG08U0F (p.44) */ + if (chip->id.len == 6 && !nand_is_slc(chip) && + chip->id.data[5] != 0x00) { + u8 extid = chip->id.data[3]; + + /* Get pagesize */ + mtd->writesize = 2048 << (extid & 0x03); + + extid >>= 2; + + /* Get oobsize */ + switch (((extid >> 2) & 0x4) | (extid & 0x3)) { + case 1: + mtd->oobsize = 128; + break; + case 2: + mtd->oobsize = 218; + break; + case 3: + mtd->oobsize = 400; + break; + case 4: + mtd->oobsize = 436; + break; + case 5: + mtd->oobsize = 512; + break; + case 6: + mtd->oobsize = 640; + break; + case 7: + default: /* Other cases are "reserved" (unknown) */ + WARN(1, "Invalid OOB size value"); + mtd->oobsize = 1024; + break; + } + + /* Get blocksize */ + extid >>= 2; + mtd->erasesize = (128 * 1024) << + (((extid >> 1) & 0x04) | (extid & 0x03)); + } else { + nand_decode_ext_id(chip); + } +} + +static int samsung_nand_init(struct nand_chip *chip) +{ + struct mtd_info *mtd = nand_to_mtd(chip); + + if (mtd->writesize > 512) + chip->options |= NAND_SAMSUNG_LP_OPTIONS; + + if (!nand_is_slc(chip)) + chip->bbt_options |= NAND_BBT_SCANLASTPAGE; + else + chip->bbt_options |= NAND_BBT_SCAN2NDPAGE; + + return 0; +} + +const struct nand_manufacturer_ops samsung_nand_manuf_ops = { + .detect = samsung_nand_decode_id, + .init = samsung_nand_init, +}; diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h index 8fb2a43296..d0312e924b 100644 --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -1158,6 +1158,8 @@ struct nand_manufacturers { extern struct nand_flash_dev nand_flash_ids[]; extern struct nand_manufacturers nand_manuf_ids[]; +extern const struct nand_manufacturer_ops samsung_nand_manuf_ops; + int nand_default_bbt(struct mtd_info *mtd); int nand_markbad_bbt(struct mtd_info *mtd, loff_t offs); int nand_isreserved_bbt(struct mtd_info *mtd, loff_t offs); From patchwork Thu Jul 14 14:35:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2173 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id C79633F066 for ; Thu, 14 Jul 2022 16:36:10 +0200 (CEST) Received: by mail-wm1-f70.google.com with SMTP id c187-20020a1c35c4000000b003a19b3b9e6csf2738546wma.5 for ; Thu, 14 Jul 2022 07:36:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657809370; cv=pass; d=google.com; s=arc-20160816; b=ltYvAc59yiG3kYgOTFf7NQ7W1+cqVCBJlucALvJXp1HpbNaZ6qWjhSLcLO1a2Ui6Al 9LuXqcHF0+1xU9K6rzUqXq8SvyJQYYUOVrG1Baj9X008J+izCWqZYnZAk62N0ZuZFmtK GeP17+CLX35rHp8isun0dIGCDgKwDVRzZ927AlY7of1h7wjMAURZXubbl3POBqMelakL DUmKLNvk00Zb0y2csE22D3YGU1SHUQfONzB8/PiZMEZrBOOf7U/g/GyelPbtKoQjKNTX eZ8cpFb+QpvPEEFmvu3aYVN4g/4SgSAlMFdycmWspilEMZaFMT51hjl8SRjpDaCzMy2I 8CXg== 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=EkkmQpa/gOGWpfcQVthVXQX7eF8aki6qBJPMY4FnCyM=; b=zBm5gRztlhHQlrcSP+ogDaeSh/A+I7zNRo5Cu7emiDrL+MRhXlDdkwksX07ScPUGk8 Mjq2jJgkcCBr2y9JA2Dt+dHKmMtgHi57UyJ3kXod0LEfOiFm8iudH0x57nynpS7tDiNO UXxs8XeVQVIIpybcgeKRqdpAL1HehS7VF10e8iRB2jc3PyxtJf9Rf/5iPSO6xAPUzII+ SZluLDBfa83LdcA9iGkEfVy8kAq2p9Cc4aRr6C2Zs+HQ40fT3QSA7vScXSzeYrcISrur JaVEjFwZLS1kGoJzPpyfMJjCEH/7Jj47kFyzQW8IrR7WS5KxmXOcYOYyhVuGrdoYfBoU yKBg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=pO0FB8Ax; 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=EkkmQpa/gOGWpfcQVthVXQX7eF8aki6qBJPMY4FnCyM=; b=ipWGlOb0vhVDTBxZqBTt/vCM2Y1PotEE/5Fhf7ij8uw4A13Gdjj1AzSI5ZDU1ff2C+ 7WFv8+S5j4BeIkONGeuqWOd2chNJVT3Cn7u59QXVj3p4HuLZQo96Dnu7OeakfQGt+hNe TJ+MyzUHLqcc6FP1y3dnnw67NI2xxcFFWOP2o= 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=EkkmQpa/gOGWpfcQVthVXQX7eF8aki6qBJPMY4FnCyM=; b=pT8lf/aVS1wByLdkmRQPLoZGzg7M7Eg5+2GSg50CkQ0lq/7NvWRXXgNqoP2rYCw7Ag hQ6sNl0RGH4zE/1x/TnMurkPEc08T099o0I3SvGQT33lRVrkgh/3hHYb9dDxeT1lS573 tg9+8bp8BDug3hUSan0Fstj+NqinK1zWsPdtCbyJAWK3W1lWwa4aTOeiPewOk8TGhjHN xp20jtG2INOJJMNOX4WnEoc+ARSSLYmnrBpZhkkAzf7cwNTO3aGtPhwt/VxyKXdNYTU3 uLt9HOTkHFES+HjpDTx6QZYN5AEz5TWpd8SwNReawNWv4ThfNFvs9+3JkkuZqFdJG6Cd szDQ== X-Gm-Message-State: AJIora8lkV3LzIviXYBuDa8MlLzlYk1fH44gwAjWN9mH4qe4drqPuyRu MCQLuc2OszCKRfDplLo+9s7DFdUz X-Google-Smtp-Source: AGRyM1s6iz7tVo05RphUY0tUrjhj8zDi3DgCRT3QrIRNt1TfNiDWxf3GK8iv6u5IyxRc/qJH+oZFEg== X-Received: by 2002:a05:6000:2cc:b0:21d:76d8:1f2c with SMTP id o12-20020a05600002cc00b0021d76d81f2cmr8441148wry.471.1657809370600; Thu, 14 Jul 2022 07:36:10 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6000:1ac7:b0:21d:ab25:25ba with SMTP id i7-20020a0560001ac700b0021dab2525bals243931wry.2.gmail; Thu, 14 Jul 2022 07:36:09 -0700 (PDT) X-Received: by 2002:a5d:6f11:0:b0:21d:7f60:e5a3 with SMTP id ay17-20020a5d6f11000000b0021d7f60e5a3mr8618156wrb.8.1657809369232; Thu, 14 Jul 2022 07:36:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657809369; cv=none; d=google.com; s=arc-20160816; b=yaOA89yreLs5Yg1YLMagKUi62yZppmKICwaAJQ3+wQn8aVKl9+v+tV+xGQW1k+F6nJ iBJEfOdg+XVKq3YMOO789R4Et+wzE2uVsGKhH0mfny484ontyiv6u5O+Le46qBwRlWWy uDoXnH1fXEcer2S/EYuDDaMETIq5fQAWrAs0UIUdXFtCfAXxvyx6GrPQS6pvgJ4HRSmP prftd7z+fOe9/tdc9enZU1nxwd7sE9BUfJha6QgeE1Ry8Y258tEa6xpld9HaVzIMosqe gehWI6b3Kw2/X3YiwjR9ym6OajizWxLzBw+XJpnSVKd+jpbe7DTQF4G4Q7Bq3L9HYN/o 4YYg== 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=N+rtp8PN0e0YtZMlSR1nEf03YbvA1gjyB7LEkd9PWAo=; b=ULyk2SuXrGB8uqY+M9VdVzvG8IzwjuddjTFpV5OYJBxUxpo6Fl6Ah4QGdfekK9PxpQ OQa9XQm6LDX49cmUFisL5LZsIlfTamSIyiww/IW0+h551f/0eQvuqh2MExlU3YToSIMc oK/k4yA6YWu+h9RlYllRmWoL9+ur/w/wNukqXNbwn63Wzkgaf7i+OHWhV1Zga88kauZW +m/iET13XplcchQ0yziCfLIhIv6jWAcWJ4tVHM7N7XH01/Oz/7HBNMPP2D2433VDqhXs IsmbQzexlYSyTSsjFbz+SM2XTd0XjTE0zpF/rDrXsacq3sjkIpk6lMfZilVI/8M4mmRA T9Bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=pO0FB8Ax; 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 e7-20020adfc847000000b0021d80ac909csor946859wrh.13.2022.07.14.07.36.09 for (Google Transport Security); Thu, 14 Jul 2022 07:36:09 -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:fe81:0:b0:21b:88ea:6981 with SMTP id l1-20020adffe81000000b0021b88ea6981mr9072349wrr.616.1657809368475; Thu, 14 Jul 2022 07:36:08 -0700 (PDT) Received: from panicking.. ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003973c54bd69sm5712357wmq.1.2022.07.14.07.36.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 07:36:07 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai , Boris Brezillon , Richard Weinberger , Patrice Chotard , Simon Glass , Wolfgang Denk , u-boot@lists.denx.de (open list) Cc: Boris Brezillon , u-boot@lists.denx.de (open list) Subject: [PATCH 07/11] mtd: nand: Move Hynix specific init/detection logic in nand_hynix.c Date: Thu, 14 Jul 2022 16:35:39 +0200 Message-Id: <20220714143543.448991-8-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=pO0FB8Ax; 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 01389b6bd2f4f7649cdbb4a99a15d9e0c05d6f8c Move Hynix specific initialization and detection logic into nand_hynix.c. This is part of the "separate vendor specific code from core" cleanup process. Signed-off-by: Boris Brezillon Acked-by: Richard Weinberger Signed-off-by: Michael Trimarchi --- drivers/mtd/nand/raw/Makefile | 3 +- drivers/mtd/nand/raw/nand_base.c | 117 ++++++++---------------------- drivers/mtd/nand/raw/nand_hynix.c | 86 ++++++++++++++++++++++ drivers/mtd/nand/raw/nand_ids.c | 2 +- include/linux/mtd/rawnand.h | 1 + 5 files changed, 121 insertions(+), 88 deletions(-) create mode 100644 drivers/mtd/nand/raw/nand_hynix.c diff --git a/drivers/mtd/nand/raw/Makefile b/drivers/mtd/nand/raw/Makefile index 0e3f017bf6..294d131264 100644 --- a/drivers/mtd/nand/raw/Makefile +++ b/drivers/mtd/nand/raw/Makefile @@ -14,7 +14,7 @@ obj-$(CONFIG_SPL_NAND_DENALI) += denali_spl.o obj-$(CONFIG_SPL_NAND_SIMPLE) += nand_spl_simple.o obj-$(CONFIG_SPL_NAND_LOAD) += nand_spl_load.o obj-$(CONFIG_SPL_NAND_ECC) += nand_ecc.o -obj-$(CONFIG_SPL_NAND_BASE) += nand_base.o nand_samsung.o +obj-$(CONFIG_SPL_NAND_BASE) += nand_base.o nand_hynix.o nand_samsung.o obj-$(CONFIG_SPL_NAND_IDENT) += nand_ids.o nand_timings.o obj-$(CONFIG_TPL_NAND_INIT) += nand.o ifeq ($(CONFIG_SPL_ENV_SUPPORT),y) @@ -31,6 +31,7 @@ obj-y += nand_ids.o obj-y += nand_util.o obj-y += nand_ecc.o obj-y += nand_base.o +obj-y += nand_hynix.o obj-y += nand_samsung.o obj-y += nand_timings.o diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 7f41395afe..6ff1a2cb29 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -4170,85 +4170,34 @@ void nand_decode_ext_id(struct nand_chip *chip) extid = chip->id.data[3]; id_len = chip->id.len; + /* Calc pagesize */ + mtd->writesize = 1024 << (extid & 0x03); + extid >>= 2; + /* Calc oobsize */ + mtd->oobsize = (8 << (extid & 0x01)) * + (mtd->writesize >> 9); + extid >>= 2; + /* Calc blocksize. Blocksize is multiples of 64KiB */ + mtd->erasesize = (64 * 1024) << (extid & 0x03); + extid >>= 2; + /* Get buswidth information */ + /* Get buswidth information */ + if (extid & 0x1) + chip->options |= NAND_BUSWIDTH_16; + /* - * Field definitions are in the following datasheets: - * Old style (4,5 byte ID): Samsung K9GAG08U0M (p.32) - * Hynix MLC (6 byte ID): Hynix H27UBG8T2B (p.22) - * - * Check for ID length, non-zero 6th byte, cell type, and Hynix/Samsung - * ID to decide what to do. + * Toshiba 24nm raw SLC (i.e., not BENAND) have 32B OOB per + * 512B page. For Toshiba SLC, we decode the 5th/6th byte as + * follows: + * - ID byte 6, bits[2:0]: 100b -> 43nm, 101b -> 32nm, + * 110b -> 24nm + * - ID byte 5, bit[7]: 1 -> BENAND, 0 -> raw SLC */ - if (id_len == 6 && chip->id.data[0] == NAND_MFR_HYNIX && - !nand_is_slc(chip)) { - unsigned int tmp; - - /* Calc pagesize */ - mtd->writesize = 2048 << (extid & 0x03); - extid >>= 2; - /* Calc oobsize */ - switch (((extid >> 2) & 0x04) | (extid & 0x03)) { - case 0: - mtd->oobsize = 128; - break; - case 1: - mtd->oobsize = 224; - break; - case 2: - mtd->oobsize = 448; - break; - case 3: - mtd->oobsize = 64; - break; - case 4: - mtd->oobsize = 32; - break; - case 5: - mtd->oobsize = 16; - break; - default: - mtd->oobsize = 640; - break; - } - extid >>= 2; - /* Calc blocksize */ - tmp = ((extid >> 1) & 0x04) | (extid & 0x03); - if (tmp < 0x03) - mtd->erasesize = (128 * 1024) << tmp; - else if (tmp == 0x03) - mtd->erasesize = 768 * 1024; - else - mtd->erasesize = (64 * 1024) << tmp; - } else { - /* Calc pagesize */ - mtd->writesize = 1024 << (extid & 0x03); - extid >>= 2; - /* Calc oobsize */ - mtd->oobsize = (8 << (extid & 0x01)) * - (mtd->writesize >> 9); - extid >>= 2; - /* Calc blocksize. Blocksize is multiples of 64KiB */ - mtd->erasesize = (64 * 1024) << (extid & 0x03); - extid >>= 2; - /* Get buswidth information */ - /* Get buswidth information */ - if (extid & 0x1) - chip->options |= NAND_BUSWIDTH_16; - - /* - * Toshiba 24nm raw SLC (i.e., not BENAND) have 32B OOB per - * 512B page. For Toshiba SLC, we decode the 5th/6th byte as - * follows: - * - ID byte 6, bits[2:0]: 100b -> 43nm, 101b -> 32nm, - * 110b -> 24nm - * - ID byte 5, bit[7]: 1 -> BENAND, 0 -> raw SLC - */ - if (id_len >= 6 && chip->id.data[0] == NAND_MFR_TOSHIBA && - nand_is_slc(chip) && - (chip->id.data[5] & 0x7) == 0x6 /* 24nm */ && - !(chip->id.data[4] & 0x80) /* !BENAND */) { - mtd->oobsize = 32 * mtd->writesize >> 9; - } - + if (id_len >= 6 && chip->id.data[0] == NAND_MFR_TOSHIBA && + nand_is_slc(chip) && + (chip->id.data[5] & 0x7) == 0x6 /* 24nm */ && + !(chip->id.data[4] & 0x80) /* !BENAND */) { + mtd->oobsize = 32 * mtd->writesize >> 9; } } EXPORT_SYMBOL_GPL(nand_decode_ext_id); @@ -4340,15 +4289,11 @@ static void nand_decode_bbm_options(struct mtd_info *mtd, * Micron devices with 2KiB pages and on SLC Samsung, Hynix, Toshiba, * AMD/Spansion, and Macronix. All others scan only the first page. */ - if (!nand_is_slc(chip) && maf_id == NAND_MFR_HYNIX) - chip->bbt_options |= NAND_BBT_SCANLASTPAGE; - else if ((nand_is_slc(chip) && - (maf_id == NAND_MFR_HYNIX || - maf_id == NAND_MFR_TOSHIBA || - maf_id == NAND_MFR_AMD || - maf_id == NAND_MFR_MACRONIX)) || - (mtd->writesize == 2048 && - maf_id == NAND_MFR_MICRON)) + if ((nand_is_slc(chip) && + (maf_id == NAND_MFR_TOSHIBA || + maf_id == NAND_MFR_AMD || + maf_id == NAND_MFR_MACRONIX)) || + (mtd->writesize == 2048 && maf_id == NAND_MFR_MICRON)) chip->bbt_options |= NAND_BBT_SCAN2NDPAGE; } diff --git a/drivers/mtd/nand/raw/nand_hynix.c b/drivers/mtd/nand/raw/nand_hynix.c new file mode 100644 index 0000000000..a5b6a61507 --- /dev/null +++ b/drivers/mtd/nand/raw/nand_hynix.c @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2017 Free Electrons + * Copyright (C) 2017 NextThing Co + * + * Author: Boris Brezillon + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include + +static void hynix_nand_decode_id(struct nand_chip *chip) +{ + struct mtd_info *mtd = nand_to_mtd(chip); + + /* Hynix MLC (6 byte ID): Hynix H27UBG8T2B (p.22) */ + if (chip->id.len == 6 && !nand_is_slc(chip)) { + u8 tmp, extid = chip->id.data[3]; + + /* Extract pagesize */ + mtd->writesize = 2048 << (extid & 0x03); + extid >>= 2; + + /* Extract oobsize */ + switch (((extid >> 2) & 0x4) | (extid & 0x3)) { + case 0: + mtd->oobsize = 128; + break; + case 1: + mtd->oobsize = 224; + break; + case 2: + mtd->oobsize = 448; + break; + case 3: + mtd->oobsize = 64; + break; + case 4: + mtd->oobsize = 32; + break; + case 5: + mtd->oobsize = 16; + break; + default: + mtd->oobsize = 640; + break; + } + + /* Extract blocksize */ + extid >>= 2; + tmp = ((extid >> 1) & 0x04) | (extid & 0x03); + if (tmp < 0x03) + mtd->erasesize = (128 * 1024) << tmp; + else if (tmp == 0x03) + mtd->erasesize = 768 * 1024; + else + mtd->erasesize = (64 * 1024) << tmp; + } else { + nand_decode_ext_id(chip); + } +} + +static int hynix_nand_init(struct nand_chip *chip) +{ + if (!nand_is_slc(chip)) + chip->bbt_options |= NAND_BBT_SCANLASTPAGE; + else + chip->bbt_options |= NAND_BBT_SCAN2NDPAGE; + + return 0; +} + +const struct nand_manufacturer_ops hynix_nand_manuf_ops = { + .detect = hynix_nand_decode_id, + .init = hynix_nand_init, +}; diff --git a/drivers/mtd/nand/raw/nand_ids.c b/drivers/mtd/nand/raw/nand_ids.c index f4126c3a5a..ec263a4327 100644 --- a/drivers/mtd/nand/raw/nand_ids.c +++ b/drivers/mtd/nand/raw/nand_ids.c @@ -194,7 +194,7 @@ struct nand_manufacturers nand_manuf_ids[] = { {NAND_MFR_NATIONAL, "National"}, {NAND_MFR_RENESAS, "Renesas"}, {NAND_MFR_STMICRO, "ST Micro"}, - {NAND_MFR_HYNIX, "Hynix"}, + {NAND_MFR_HYNIX, "Hynix", &hynix_nand_manuf_ops}, {NAND_MFR_MICRON, "Micron"}, {NAND_MFR_AMD, "AMD/Spansion"}, {NAND_MFR_MACRONIX, "Macronix"}, diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h index d0312e924b..d35277d187 100644 --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -1159,6 +1159,7 @@ extern struct nand_flash_dev nand_flash_ids[]; extern struct nand_manufacturers nand_manuf_ids[]; extern const struct nand_manufacturer_ops samsung_nand_manuf_ops; +extern const struct nand_manufacturer_ops hynix_nand_manuf_ops; int nand_default_bbt(struct mtd_info *mtd); int nand_markbad_bbt(struct mtd_info *mtd, loff_t offs); From patchwork Thu Jul 14 14:35:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2174 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 5962C3F066 for ; Thu, 14 Jul 2022 16:36:15 +0200 (CEST) Received: by mail-wm1-f70.google.com with SMTP id c187-20020a1c35c4000000b003a19b3b9e6csf2738653wma.5 for ; Thu, 14 Jul 2022 07:36:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657809375; cv=pass; d=google.com; s=arc-20160816; b=c7OshuOWLMs3NUAZfkZCTY8p1x2NO7pp3UAktk8s6pb8TqDM7cAVUq3EPffma1ISu4 YLWG4FdzKglhF0pD4bYyQToMnePzxUT5hea8AQHEhW98Y41Wub3kM+D29Nek+GyuxZJE SDUJ6CQ/XCe1nV32q+elyb7SVsqGYAyUltmY1yHWeztmdsNY6qjr2T4OVR02N+9FqznY SN/oIaoTOskM6UHy5fSLCSA6Ikmr+aGppQt60i+b4IpiiI9czO4amPGfo0CSduPF0ZS8 lB+92bQzZ5ZUm8mzqwrdWqN2krVBdZKnJQyy8Iq9ykmJZ51grFVXSH4WrXWqgUUkfjqz haNQ== 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=vmVx0z3Ubo58SrdMiS1PVaibssXAk6ZsNS2GtJ/YPc4=; b=sIkX7fAPdLtKU1781GEmrmPqm5CHH/eYyPbtPshRZsHkU6uKJQBcrHT3EbgRQ7XsAl l5uXDtKsLMdjDLuF8XhWX6G5Wld0FauoU/L0E+0kxLZD8jsNjRNk70EnSFabaWJYFUbg 9i9JqS8NeqOHjGhlH/4c4P53fOI/SPnpwIidgiS/X5t113EFEECSPm4MsQuaq/ovaj0h 7f4S2IMefaLSq+a3dRRVGuZCL6+jeomVedlyQGZor1D+bXHG/wPq0IiIM2Xy0QnNgxVD iYNQUJJ7Q3c/P/kO1pEuNKe5ei9u4h5HBPyVBmqWzVmJ0WCX6N1m2vVByquwPffouqmr oyUQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=NgV4IJmg; 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=vmVx0z3Ubo58SrdMiS1PVaibssXAk6ZsNS2GtJ/YPc4=; b=LN1ziRLyQSEEsAJV0WLtgH0BN0atCUw1dvlqBhKmcKsZbvN2GSzGZQgUQeLdsPRIdo l2eIhniMT11FZf2J319rFCqm7PWX6VAhsY6/zpdhkvDv0mkLILhhhkb3NTmTw4VNE6eh MBc6k3ZViqIrr3LkMaToIpmB5BprKCM+TfLPs= 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=vmVx0z3Ubo58SrdMiS1PVaibssXAk6ZsNS2GtJ/YPc4=; b=caCnhJX8cZMHd/cyVqGZ+eQM+dDC1XLv1UNzs28fO4jgZy13Lq1uCTpSttzLT7CstF N+gJ+gCehfbBRw16SYLgGfWU2299GqL4esRyPK9APZ4C6s23bd+v648OHgq+iFA4aND3 k9fMWAtsGAcjteyVG/JOC69X71mA1xTNYru6c/wcF/nQobgkN88hpitZNIioPLgeZai1 pYEN/vDfXl5icINHK7KrD0qtlPgcs0coLMTzJM2w6hheTIcwk0UggXdHdUdMtk28NIcr CN7kgMedTQTW8zF+ENGeYTT5QHaJGLiQefGgRdnOVl7M8FZBeMKc4RQ3MOpCwWXp4neD AwMA== X-Gm-Message-State: AJIora9HLeA99xFXiNrfOceWzyFLW6HLxLrQ9ytlv3s4cvtwka8aJ9B4 v3S0Q671bOHRpgdTnte+uVkW62/f X-Google-Smtp-Source: AGRyM1smZzILNgQjTcoFKTlk+gCB8pEiMZOXI48zmMKcC3eFOMkgRrnPAYCOdaBttVGjs/TSyF/BIA== X-Received: by 2002:adf:f88c:0:b0:21d:bac6:949f with SMTP id u12-20020adff88c000000b0021dbac6949fmr8701244wrp.551.1657809375180; Thu, 14 Jul 2022 07:36:15 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6000:1ac7:b0:21d:ab25:25ba with SMTP id i7-20020a0560001ac700b0021dab2525bals244194wry.2.gmail; Thu, 14 Jul 2022 07:36:14 -0700 (PDT) X-Received: by 2002:adf:e5c4:0:b0:21d:8b5f:ccef with SMTP id a4-20020adfe5c4000000b0021d8b5fccefmr8048984wrn.125.1657809373993; Thu, 14 Jul 2022 07:36:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657809373; cv=none; d=google.com; s=arc-20160816; b=qyGpCJFxpH0KRQPUvWae4bBrK7Bkr4QPZOS3W20uTz/QOw8WtfMlczoShvM3CyDGgu wlUp4kyVizN1xrYDA+v3FGpAkNiCddzap23+2yi+67NbnymAMhgkRh6N0ujq1FNTO+G8 I8sb86no8oOgqnE4PbIIk3Ztd+oEev0u8M7Yn5ZtUH3KMK4iSzO3B085CbX6Mu4m5HLM pAOsbvC+20zYjg821J/uNUAiHN8+YRZgZy2944ukPNXnFFVQsN9zSMHwKzfKEf8WkgIG eippDVVksL6/W7Il4X0fhsrKyChofXzg5UTc7VWzu/ktpYPIwQemTE6u5DkWceO8RW0Z UtQA== 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=bUAelgxhRmK6KYlzb4SR7SBVjPUr+bul0VwHLDW2c3U=; b=IOEmQKwxxRdSYB34a5Es1/yDX7AX0giZAGJDg4ReLsFlhig9rsdAOBchCiLqSKGzJk AxJs2StIH6B+yFxGIqR2UU1v/7t92W+19iSZHfTaU5CeyTet94SLJMOtdfW/CrPfdJPA 8pTx434bGl6WZ/+FGp6tC+O7cEdZGKfuhiY907wep46OqodmsDQAbVM3UmYyhO4ZOCBf jU2a+g3RpMf0uSqtMqGv8KNjjE1+HziiPQVMZ7mIGrAIlxwjVBydr8VhcaRKAItR8nyJ Aw/kZLk2OYwu1Vdy9IWmBZ8PrxHrmGHbSK4zoIFXjHh0XbmDxmmmuda9rtxG3WcP0yhw Yj7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=NgV4IJmg; 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 az12-20020a05600c600c00b003a2f1edf4f0sor2630514wmb.0.2022.07.14.07.36.13 for (Google Transport Security); Thu, 14 Jul 2022 07:36:13 -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:4ed0:b0:3a0:5263:cf09 with SMTP id g16-20020a05600c4ed000b003a05263cf09mr9735187wmq.6.1657809373289; Thu, 14 Jul 2022 07:36:13 -0700 (PDT) Received: from panicking.. ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003973c54bd69sm5712357wmq.1.2022.07.14.07.36.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 07:36:12 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai , Boris Brezillon , Richard Weinberger , Patrice Chotard , Simon Glass , Wolfgang Denk , u-boot@lists.denx.de (open list) Cc: Boris Brezillon , Marek Vasut , u-boot@lists.denx.de (open list) Subject: [PATCH 08/11] mtd: nand: Move Toshiba specific init/detection logic in nand_toshiba.c Date: Thu, 14 Jul 2022 16:35:40 +0200 Message-Id: <20220714143543.448991-9-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=NgV4IJmg; 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 9b2d61f80b060ce3ea5af2a99e148b0b214932b2 Move Toshiba specific initialization and detection logic into nand_toshiba.c. This is part of the "separate vendor specific code from core" cleanup process. Signed-off-by: Boris Brezillon Acked-by: Richard Weinberger Signed-off-by: Michael Trimarchi --- drivers/mtd/nand/raw/Makefile | 3 +- drivers/mtd/nand/raw/nand_base.c | 21 ++---------- drivers/mtd/nand/raw/nand_ids.c | 2 +- drivers/mtd/nand/raw/nand_toshiba.c | 53 +++++++++++++++++++++++++++++ include/linux/mtd/rawnand.h | 1 + 5 files changed, 59 insertions(+), 21 deletions(-) create mode 100644 drivers/mtd/nand/raw/nand_toshiba.c diff --git a/drivers/mtd/nand/raw/Makefile b/drivers/mtd/nand/raw/Makefile index 294d131264..db608a2830 100644 --- a/drivers/mtd/nand/raw/Makefile +++ b/drivers/mtd/nand/raw/Makefile @@ -14,7 +14,7 @@ obj-$(CONFIG_SPL_NAND_DENALI) += denali_spl.o obj-$(CONFIG_SPL_NAND_SIMPLE) += nand_spl_simple.o obj-$(CONFIG_SPL_NAND_LOAD) += nand_spl_load.o obj-$(CONFIG_SPL_NAND_ECC) += nand_ecc.o -obj-$(CONFIG_SPL_NAND_BASE) += nand_base.o nand_hynix.o nand_samsung.o +obj-$(CONFIG_SPL_NAND_BASE) += nand_base.o nand_hynix.o nand_samsung.o nand_toshiba.o obj-$(CONFIG_SPL_NAND_IDENT) += nand_ids.o nand_timings.o obj-$(CONFIG_TPL_NAND_INIT) += nand.o ifeq ($(CONFIG_SPL_ENV_SUPPORT),y) @@ -33,6 +33,7 @@ obj-y += nand_ecc.o obj-y += nand_base.o obj-y += nand_hynix.o obj-y += nand_samsung.o +obj-y += nand_toshiba.o obj-y += nand_timings.o endif # not spl diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 6ff1a2cb29..8c06b1c530 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -4163,12 +4163,11 @@ static int nand_get_bits_per_cell(u8 cellinfo) void nand_decode_ext_id(struct nand_chip *chip) { struct mtd_info *mtd = &chip->mtd; - int extid, id_len; + int extid; /* The 3rd id byte holds MLC / multichip data */ chip->bits_per_cell = nand_get_bits_per_cell(chip->id.data[2]); /* The 4th id byte is the important one */ extid = chip->id.data[3]; - id_len = chip->id.len; /* Calc pagesize */ mtd->writesize = 1024 << (extid & 0x03); @@ -4184,21 +4183,6 @@ void nand_decode_ext_id(struct nand_chip *chip) /* Get buswidth information */ if (extid & 0x1) chip->options |= NAND_BUSWIDTH_16; - - /* - * Toshiba 24nm raw SLC (i.e., not BENAND) have 32B OOB per - * 512B page. For Toshiba SLC, we decode the 5th/6th byte as - * follows: - * - ID byte 6, bits[2:0]: 100b -> 43nm, 101b -> 32nm, - * 110b -> 24nm - * - ID byte 5, bit[7]: 1 -> BENAND, 0 -> raw SLC - */ - if (id_len >= 6 && chip->id.data[0] == NAND_MFR_TOSHIBA && - nand_is_slc(chip) && - (chip->id.data[5] & 0x7) == 0x6 /* 24nm */ && - !(chip->id.data[4] & 0x80) /* !BENAND */) { - mtd->oobsize = 32 * mtd->writesize >> 9; - } } EXPORT_SYMBOL_GPL(nand_decode_ext_id); @@ -4290,8 +4274,7 @@ static void nand_decode_bbm_options(struct mtd_info *mtd, * AMD/Spansion, and Macronix. All others scan only the first page. */ if ((nand_is_slc(chip) && - (maf_id == NAND_MFR_TOSHIBA || - maf_id == NAND_MFR_AMD || + (maf_id == NAND_MFR_AMD || maf_id == NAND_MFR_MACRONIX)) || (mtd->writesize == 2048 && maf_id == NAND_MFR_MICRON)) chip->bbt_options |= NAND_BBT_SCAN2NDPAGE; diff --git a/drivers/mtd/nand/raw/nand_ids.c b/drivers/mtd/nand/raw/nand_ids.c index ec263a4327..509652c8e2 100644 --- a/drivers/mtd/nand/raw/nand_ids.c +++ b/drivers/mtd/nand/raw/nand_ids.c @@ -188,7 +188,7 @@ struct nand_flash_dev nand_flash_ids[] = { /* Manufacturer IDs */ struct nand_manufacturers nand_manuf_ids[] = { - {NAND_MFR_TOSHIBA, "Toshiba"}, + {NAND_MFR_TOSHIBA, "Toshiba", &toshiba_nand_manuf_ops}, {NAND_MFR_SAMSUNG, "Samsung", &samsung_nand_manuf_ops}, {NAND_MFR_FUJITSU, "Fujitsu"}, {NAND_MFR_NATIONAL, "National"}, diff --git a/drivers/mtd/nand/raw/nand_toshiba.c b/drivers/mtd/nand/raw/nand_toshiba.c new file mode 100644 index 0000000000..1ac80df651 --- /dev/null +++ b/drivers/mtd/nand/raw/nand_toshiba.c @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2017 Free Electrons + * Copyright (C) 2017 NextThing Co + * + * Author: Boris Brezillon + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include + +static void toshiba_nand_decode_id(struct nand_chip *chip) +{ + struct mtd_info *mtd = nand_to_mtd(chip); + + nand_decode_ext_id(chip); + + /* + * Toshiba 24nm raw SLC (i.e., not BENAND) have 32B OOB per + * 512B page. For Toshiba SLC, we decode the 5th/6th byte as + * follows: + * - ID byte 6, bits[2:0]: 100b -> 43nm, 101b -> 32nm, + * 110b -> 24nm + * - ID byte 5, bit[7]: 1 -> BENAND, 0 -> raw SLC + */ + if (chip->id.len >= 6 && nand_is_slc(chip) && + (chip->id.data[5] & 0x7) == 0x6 /* 24nm */ && + !(chip->id.data[4] & 0x80) /* !BENAND */) + mtd->oobsize = 32 * mtd->writesize >> 9; +} + +static int toshiba_nand_init(struct nand_chip *chip) +{ + if (nand_is_slc(chip)) + chip->bbt_options |= NAND_BBT_SCAN2NDPAGE; + + return 0; +} + +const struct nand_manufacturer_ops toshiba_nand_manuf_ops = { + .detect = toshiba_nand_decode_id, + .init = toshiba_nand_init, +}; diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h index d35277d187..73abb34016 100644 --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -1158,6 +1158,7 @@ struct nand_manufacturers { extern struct nand_flash_dev nand_flash_ids[]; extern struct nand_manufacturers nand_manuf_ids[]; +extern const struct nand_manufacturer_ops toshiba_nand_manuf_ops; extern const struct nand_manufacturer_ops samsung_nand_manuf_ops; extern const struct nand_manufacturer_ops hynix_nand_manuf_ops; From patchwork Thu Jul 14 14:35:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2175 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 247563F066 for ; Thu, 14 Jul 2022 16:36:19 +0200 (CEST) Received: by mail-wr1-f72.google.com with SMTP id l11-20020adfbd8b000000b0021d754b84c5sf603340wrh.17 for ; Thu, 14 Jul 2022 07:36:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657809379; cv=pass; d=google.com; s=arc-20160816; b=thy2HCs3PFWsUCdHznRxm7s4d6iNCcxZGFI2BGrT2B6+N115pPgO695mZHieb48i0h txJme0lDqVoozCEblx30yxFfJtPDvUHBeGsm8gRmCJjdd+aUBWY4CXC+AlrvCWZxC3S7 cl8PMHxRcQ+pHjZudVJnPJDA6zguf1oAIddkIQa/Aty4rSUB//MhAQcO5o5k/6cA2DnS x9RP9ejoCcJObUfeLBQfKCwDMyDf7xZtdmdUqntg5I2GDifOntxfqBAFO2Ak6RtYiw/3 TokY9GHecnsMRQzlKKQaCCeMKQBVJ2v/gX8wwg97w2/PrA6acpNlzovTbUjW2MPIlzEk Vmqg== 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=+jKhKJy2k3mldzHkeN3w5AI0zcNFlIr2NWHRBikgln8=; b=tN3UzP9v2hYi0P/hiiAdI2CEcv6txuaEYsxuVbEQUP5St9jLn4CHLHe4E6U/TvDPvc /7fhxYYqY3ecER/tAJLBkJJ7c+rufzba96iDDakPe5b9elfnDJT861eS2+yA1KF3fU15 +OjrmGXaFiCpXMnSXvOOdWGi1k8qxbBuAnycEtk6UQ7uVDXWvtFuHXKJ0lD3RRs2Rxxf OSomx7wIsb3aXRqFcPHZAbmDqHfFL/7MaXZJ81qgAHqojjP3JK6w3kqZOSYFmn+CGlNN Q2M2LJKSfbmc9e8nlW+/0TF3TJY5AEEPRYvP+5giMPcWdXaT4778rWM8EXX+1VQlkBgb nAbQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=QH+2Vn4J; 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=+jKhKJy2k3mldzHkeN3w5AI0zcNFlIr2NWHRBikgln8=; b=cz6SL8WNh0tc8T+P2Cnaj3dPllMJ2SuWQ5ZwDSOJsfm6GTkaHMk5Nq+LqtmHyrSnfJ BPy0t8YQV2sN/vfGLvFkGB5rcDEASMYzPQ4vLpYh23GWDjXwRgwp8q+zGOn0dtGxgGmg sbvKrZUJOM7UXA4GPJey1fP5nxmZKBgbLYMGY= 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=+jKhKJy2k3mldzHkeN3w5AI0zcNFlIr2NWHRBikgln8=; b=RzgA6rp15ay/t4SRS7OLxYqz75ahld67katxx7JcMmHeaymn0Yl8YTNkIdogiiatxC hnKv4AsScvnbpb8OUyeHFt3IRKxtE5eK6RAbOuYRrsEaaUbgWo4BgvneC/M1jfkl5DuS Apgspox64uSgUJQxqrSWJ/nuTx39ZMCG+55R4/LD1BEDHokYmOD7t+nz/R6YVhCwQHgB A2+oZoWau6M9VCLuO0jLsCeIZkuv7nEYVj2genezokXi8bFREMWKMS9bFVCehs8VAjnO I8NZgMlJ18E7G5VCJVP4yx4JfAdFAZL5CJS4A+meWsjowY8WvuyrpzEkjxhWra8KqByw MPvg== X-Gm-Message-State: AJIora8fxa9OePiQHY1SNWW3127fidOxL4bA79N+1wIoPgTfsgtxTgp/ 8fhVhJZw7KBFUAI8ir6u6wSjGfmL X-Google-Smtp-Source: AGRyM1tsApTMUCczqZQgo+PnZcEMlJYh5fFyfuIzCO+ZEEDjLCTWQIg1Yd82xZlc3qmKFo522y0/+w== X-Received: by 2002:a5d:4cce:0:b0:21d:755b:d4f8 with SMTP id c14-20020a5d4cce000000b0021d755bd4f8mr9098297wrt.190.1657809378923; Thu, 14 Jul 2022 07:36:18 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a5d:588d:0:b0:21d:339f:dc1 with SMTP id n13-20020a5d588d000000b0021d339f0dc1ls243458wrf.0.gmail; Thu, 14 Jul 2022 07:36:17 -0700 (PDT) X-Received: by 2002:adf:e104:0:b0:21b:9938:b07a with SMTP id t4-20020adfe104000000b0021b9938b07amr8637920wrz.682.1657809377683; Thu, 14 Jul 2022 07:36:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657809377; cv=none; d=google.com; s=arc-20160816; b=iaqbePM8REvjbSz1R7xh8hs0pQ2dWnjAGes23kx/ZEPojfHP0eoxqweu39PV9IEoMu WWUG+fDEvYiEeLSyWKFNf/QF1XqjxvCKjxx211aZcgBjDqKt5fcjuNrJ+6nyyD3cJv8n ASfaSc2tn8fkO33fvcdFQNhPKEvfkZZaCRXA6r4vfzlg0p1TWq9Mq2vAzGMQ9825cVOi yuyhc5XCLapyhruHgyT6gTP8KXynrEmjPAvWJ9m2juCTYlMY0kHvGBYIfjNuAlaLrz6G 8l7hS6IyDe4OBYJN9Ah6RR+7sG1/QaXWkeLsj6Fitl75UcN1/u38Xhfev3+Mus375PCR 2EYQ== 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=KoBfOtZSuWjXMH5ooKp+4pUgGAdKWVS7+4lORZDN2pg=; b=Bc7DRbyo32ytMuoJdj49qCt+LJx7jNhAPtEpy4u4Gwds+DBvLX8rHL0Kq/Pd+xGm1Q vgnPicVi/XWWeMSDwmMi1uu80Bi1WJ0MKJkPql2vYI5AU7/5KoZsgcpXWEsGBJettm7X q88nd2agf8g4K2dOvF1if5XXjEH0uef8DtgXBpfsH3TZ3Xmv07+kKCXMTC3u/8UxxuMJ wd/cYZ5kddbNloxiLp4n5JAkCejmsJ/bKkSa8xu4e8PrfpTn+QIkH9kCm3yf+U15F5G7 v6OI03ofeC5sg7nQuT8NcdpB9NAVMNlKkwz54orn9E2zXNsvYC2V+OiQbSaajjIst7DY NZYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=QH+2Vn4J; 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 o5-20020a5d6485000000b0021d7ecd0e3csor853659wri.37.2022.07.14.07.36.17 for (Google Transport Security); Thu, 14 Jul 2022 07:36:17 -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:e483:0:b0:21d:a52e:261d with SMTP id i3-20020adfe483000000b0021da52e261dmr8264973wrm.228.1657809376963; Thu, 14 Jul 2022 07:36:16 -0700 (PDT) Received: from panicking.. ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003973c54bd69sm5712357wmq.1.2022.07.14.07.36.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 07:36:16 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai , Boris Brezillon , Richard Weinberger , Patrice Chotard , Wolfgang Denk , u-boot@lists.denx.de (open list) Cc: Boris Brezillon , Simon Glass , u-boot@lists.denx.de (open list) Subject: [PATCH 09/11] mtd: nand: Move Micron specific init logic in nand_micron.c Date: Thu, 14 Jul 2022 16:35:41 +0200 Message-Id: <20220714143543.448991-10-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=QH+2Vn4J; 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 10d4e75c36f6c16311dde1461f318210da357219 Move Micron specific initialization logic into nand_micron.c. This is part of the "separate vendor specific code from core" cleanup process. Signed-off-by: Boris Brezillon Acked-by: Richard Weinberger Signed-off-by: Michael Trimarchi --- drivers/mtd/nand/raw/Makefile | 3 +- drivers/mtd/nand/raw/nand_base.c | 33 +---------- drivers/mtd/nand/raw/nand_ids.c | 2 +- drivers/mtd/nand/raw/nand_micron.c | 88 ++++++++++++++++++++++++++++++ include/linux/mtd/rawnand.h | 21 +------ 5 files changed, 94 insertions(+), 53 deletions(-) create mode 100644 drivers/mtd/nand/raw/nand_micron.c diff --git a/drivers/mtd/nand/raw/Makefile b/drivers/mtd/nand/raw/Makefile index db608a2830..e8fb451076 100644 --- a/drivers/mtd/nand/raw/Makefile +++ b/drivers/mtd/nand/raw/Makefile @@ -14,7 +14,7 @@ obj-$(CONFIG_SPL_NAND_DENALI) += denali_spl.o obj-$(CONFIG_SPL_NAND_SIMPLE) += nand_spl_simple.o obj-$(CONFIG_SPL_NAND_LOAD) += nand_spl_load.o obj-$(CONFIG_SPL_NAND_ECC) += nand_ecc.o -obj-$(CONFIG_SPL_NAND_BASE) += nand_base.o nand_hynix.o nand_samsung.o nand_toshiba.o +obj-$(CONFIG_SPL_NAND_BASE) += nand_base.o nand_hynix.o nand_micron.o nand_samsung.o nand_toshiba.o obj-$(CONFIG_SPL_NAND_IDENT) += nand_ids.o nand_timings.o obj-$(CONFIG_TPL_NAND_INIT) += nand.o ifeq ($(CONFIG_SPL_ENV_SUPPORT),y) @@ -32,6 +32,7 @@ obj-y += nand_util.o obj-y += nand_ecc.o obj-y += nand_base.o obj-y += nand_hynix.o +obj-y += nand_micron.o obj-y += nand_samsung.o obj-y += nand_toshiba.o obj-y += nand_timings.o diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 8c06b1c530..d2079c73fb 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -3871,30 +3871,6 @@ ext_out: return ret; } -static int nand_setup_read_retry_micron(struct mtd_info *mtd, int retry_mode) -{ - struct nand_chip *chip = mtd_to_nand(mtd); - uint8_t feature[ONFI_SUBFEATURE_PARAM_LEN] = {retry_mode}; - - return chip->onfi_set_features(mtd, chip, ONFI_FEATURE_ADDR_READ_RETRY, - feature); -} - -/* - * Configure chip properties from Micron vendor-specific ONFI table - */ -static void nand_onfi_detect_micron(struct nand_chip *chip, - struct nand_onfi_params *p) -{ - struct nand_onfi_vendor_micron *micron = (void *)p->vendor; - - if (le16_to_cpu(p->vendor_revision) < 1) - return; - - chip->read_retries = micron->read_retry_options; - chip->setup_read_retry = nand_setup_read_retry_micron; -} - /* * Check if the NAND chip is ONFI compliant, returns 1 if it is, 0 otherwise. */ @@ -3994,9 +3970,6 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip) pr_warn("Could not retrieve ONFI ECC requirements\n"); } - if (p->jedec_id == NAND_MFR_MICRON) - nand_onfi_detect_micron(chip, p); - return 1; } #else @@ -4273,10 +4246,8 @@ static void nand_decode_bbm_options(struct mtd_info *mtd, * Micron devices with 2KiB pages and on SLC Samsung, Hynix, Toshiba, * AMD/Spansion, and Macronix. All others scan only the first page. */ - if ((nand_is_slc(chip) && - (maf_id == NAND_MFR_AMD || - maf_id == NAND_MFR_MACRONIX)) || - (mtd->writesize == 2048 && maf_id == NAND_MFR_MICRON)) + if (nand_is_slc(chip) && + (maf_id == NAND_MFR_AMD || maf_id == NAND_MFR_MACRONIX)) chip->bbt_options |= NAND_BBT_SCAN2NDPAGE; } diff --git a/drivers/mtd/nand/raw/nand_ids.c b/drivers/mtd/nand/raw/nand_ids.c index 509652c8e2..bb5ac8337f 100644 --- a/drivers/mtd/nand/raw/nand_ids.c +++ b/drivers/mtd/nand/raw/nand_ids.c @@ -195,7 +195,7 @@ struct nand_manufacturers nand_manuf_ids[] = { {NAND_MFR_RENESAS, "Renesas"}, {NAND_MFR_STMICRO, "ST Micro"}, {NAND_MFR_HYNIX, "Hynix", &hynix_nand_manuf_ops}, - {NAND_MFR_MICRON, "Micron"}, + {NAND_MFR_MICRON, "Micron", µn_nand_manuf_ops}, {NAND_MFR_AMD, "AMD/Spansion"}, {NAND_MFR_MACRONIX, "Macronix"}, {NAND_MFR_EON, "Eon"}, diff --git a/drivers/mtd/nand/raw/nand_micron.c b/drivers/mtd/nand/raw/nand_micron.c new file mode 100644 index 0000000000..a99bf8bbec --- /dev/null +++ b/drivers/mtd/nand/raw/nand_micron.c @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2017 Free Electrons + * Copyright (C) 2017 NextThing Co + * + * Author: Boris Brezillon + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include + +struct nand_onfi_vendor_micron { + u8 two_plane_read; + u8 read_cache; + u8 read_unique_id; + u8 dq_imped; + u8 dq_imped_num_settings; + u8 dq_imped_feat_addr; + u8 rb_pulldown_strength; + u8 rb_pulldown_strength_feat_addr; + u8 rb_pulldown_strength_num_settings; + u8 otp_mode; + u8 otp_page_start; + u8 otp_data_prot_addr; + u8 otp_num_pages; + u8 otp_feat_addr; + u8 read_retry_options; + u8 reserved[72]; + u8 param_revision; +} __packed; + +static int micron_nand_setup_read_retry(struct mtd_info *mtd, int retry_mode) +{ + struct nand_chip *chip = mtd_to_nand(mtd); + u8 feature[ONFI_SUBFEATURE_PARAM_LEN] = {retry_mode}; + + return chip->onfi_set_features(mtd, chip, ONFI_FEATURE_ADDR_READ_RETRY, + feature); +} + +/* + * Configure chip properties from Micron vendor-specific ONFI table + */ +static int micron_nand_onfi_init(struct nand_chip *chip) +{ + struct nand_onfi_params *p = &chip->onfi_params; + struct nand_onfi_vendor_micron *micron = (void *)p->vendor; + + if (!chip->onfi_version) + return 0; + + if (le16_to_cpu(p->vendor_revision) < 1) + return 0; + + chip->read_retries = micron->read_retry_options; + chip->setup_read_retry = micron_nand_setup_read_retry; + + return 0; +} + +static int micron_nand_init(struct nand_chip *chip) +{ + struct mtd_info *mtd = nand_to_mtd(chip); + int ret; + + ret = micron_nand_onfi_init(chip); + if (ret) + return ret; + + if (mtd->writesize == 2048) + chip->bbt_options |= NAND_BBT_SCAN2NDPAGE; + + return 0; +} + +const struct nand_manufacturer_ops micron_nand_manuf_ops = { + .init = micron_nand_init, +}; diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h index 73abb34016..ec0f77b24b 100644 --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -388,26 +388,6 @@ struct onfi_ext_param_page { */ } __packed; -struct nand_onfi_vendor_micron { - u8 two_plane_read; - u8 read_cache; - u8 read_unique_id; - u8 dq_imped; - u8 dq_imped_num_settings; - u8 dq_imped_feat_addr; - u8 rb_pulldown_strength; - u8 rb_pulldown_strength_feat_addr; - u8 rb_pulldown_strength_num_settings; - u8 otp_mode; - u8 otp_page_start; - u8 otp_data_prot_addr; - u8 otp_num_pages; - u8 otp_feat_addr; - u8 read_retry_options; - u8 reserved[72]; - u8 param_revision; -} __packed; - struct jedec_ecc_info { u8 ecc_bits; u8 codeword_size; @@ -1161,6 +1141,7 @@ extern struct nand_manufacturers nand_manuf_ids[]; extern const struct nand_manufacturer_ops toshiba_nand_manuf_ops; extern const struct nand_manufacturer_ops samsung_nand_manuf_ops; extern const struct nand_manufacturer_ops hynix_nand_manuf_ops; +extern const struct nand_manufacturer_ops micron_nand_manuf_ops; int nand_default_bbt(struct mtd_info *mtd); int nand_markbad_bbt(struct mtd_info *mtd, loff_t offs); From patchwork Thu Jul 14 14:35:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2176 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 134BE3F066 for ; Thu, 14 Jul 2022 16:36:25 +0200 (CEST) Received: by mail-wm1-f71.google.com with SMTP id r82-20020a1c4455000000b003a300020352sf135531wma.5 for ; Thu, 14 Jul 2022 07:36:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657809384; cv=pass; d=google.com; s=arc-20160816; b=Yr8zNbkP+H/kv0tIFIXNWrlRseXqeMpH2pAaj0TNCmlCLxlGu4i9KJZyf/ikeYcIJc DV/Ms/opd1BB5KVpXiMDg25I2L/MyZpDl9VvmL1kWTqs0P3nIyFVpsalEkyq2dQbjes5 ZlGsaH0ziFHWo9yMaHeQgLhRoXvQePodpf7gQcH59xiTWSjRhRHRXchFj65+9GmcXmvs CMsOXr97K+NI1o8CUZrtFuFeVIitPDCXX0qtLpdLfbamXap5qHZP2HxYfjr6USgGqcEd VRCxSFJf3Qc7Eoqd1aYa275qjcbFzavxN8/UZtIPbYW7tOz3Sh4pmVrDpICcv8hXQOBO J1RQ== 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=aTsW0CwIALv70v5/D0Y2fIhQt8rFfUEfGVmcgty5HDg=; b=h4YHBtZAYx+k5isSegxPG7tbRwoP6/20FRfal0spvalUcjlfiMV9DXaEf3ssXaCoB9 y81BL/GX8gDV9r8b0g+A4CyY+m40Kkp8ma/dUYj6lV7nDVd+0dPCgFStfisqv/yrM9q2 eXtPlsrIQ8ZzOQ8NcqEeTlR5eyKLGC4KpEl+lus1bTdaOLm+5hu8Uzd3ZNtAu4RaOxpw ger9ctCC6mOOHAmjoX+h50FhMcteCn6MeULb4KGKfVZU0/0V6jO+LedlgEkxeE/2QxNW gnIQgdOtMop1OH4S7wmmKwfU8xZZ2w+kgo/lF9PPZpF/itEnYl2qzjPGzty8fFeM5k8k f88Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=kuZ2q7jz; 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=aTsW0CwIALv70v5/D0Y2fIhQt8rFfUEfGVmcgty5HDg=; b=e6VpW3ecuuVj44pXtKVA7Yk54cq4TqwXQGyrnRZT+8Hg4+qLxd1H+9NwU5edIfKgPI Xzc2f3gfUfDZ5gHs9utjQgfXo+TBNhYRu5BCo8End5ZMfOGhh+yuqt4n0Z9EsD8MTK4+ utpZ/wx1/CS4H+zif5j/fNz1sYPR2igYUI0Cg= 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=aTsW0CwIALv70v5/D0Y2fIhQt8rFfUEfGVmcgty5HDg=; b=Mdg/v076Q27izeO6aEQFRqA3nZGkBqFzggKSXzeUa4xxhadNzsrgWR8z+i0qD+gIEj JDvbmWYm8WmtYb7Q7g5i5SWLyNrG8kVcUaC0lMho/5WdCHaDXMdEiyjh1s88D9fXNbDc YHKStELLyrs0tKTzjV3k+UCbpQCR123WzbKaqkCk7DKTdjBeF7jN71gHepq5TMW4MbeE r15vnVS1U9z7Mh4wt/1wH6UbAjL7nKwzgghOCqDusZVNs9ts0GV7hqSEgnC//NRmhFrn pQL71zkBtZDv2Mwnuj5V9eKqMCl/Iy0KeNnXC9tx+Eb7oqRPVfII+QxUxAmaJuIJv5em VgOA== X-Gm-Message-State: AJIora9pM0GK98Oll9GCemno0U3kXfsf/L6xg9hV9VjXiNMp8bVUMPrV XQmM429U+s+LSTeh4OUjknUtsAwT X-Google-Smtp-Source: AGRyM1s+1wLpqGG77Iu0wLEoYcyyver3998XuF2v/A/FKz4UfurwTj4vbeSxbklQE5/UcceIm4baYw== X-Received: by 2002:a1c:4c0c:0:b0:3a2:ea68:cae7 with SMTP id z12-20020a1c4c0c000000b003a2ea68cae7mr9261339wmf.91.1657809384873; Thu, 14 Jul 2022 07:36:24 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:600c:3b17:b0:3a0:2da0:3609 with SMTP id m23-20020a05600c3b1700b003a02da03609ls4512439wms.1.gmail; Thu, 14 Jul 2022 07:36:23 -0700 (PDT) X-Received: by 2002:a05:600c:4e01:b0:3a3:342:5f55 with SMTP id b1-20020a05600c4e0100b003a303425f55mr2440718wmq.150.1657809383699; Thu, 14 Jul 2022 07:36:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657809383; cv=none; d=google.com; s=arc-20160816; b=Xb3hPsRIDDlR2j+58QkCKk+ht4MV6NBjX+ZFq5jlTI5o56UOWMhpG2MbtfyJ+/yhSq zEbasMeg3O/Q8etmSlepE/eas7Ypfn5XecpLYt0wqN6gKIuuPUDiFkXEW21Y7lD+OvrO ZvVS1Yt7xfuZ21bhRPkc3Ib1D854+zLe57WfjYnHu3Xwc7733WmbFkLStT6tipDXdPEM 7Yow9A3TBJg7WYeT52T+nXj9q7zX+LtWa1wwpBhcZ/XAFqWkZZZ6yoyv2QdY1Ma3hbLC dY03HCKZ+QiZuk6TNS+uDXe3RJ7nW1Hk0+mavjD4iTfIZ3m4MctkQQc9TVWFRcT7ATSj oRWg== 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=5iCwJ3uyZDix/RxLRXQbAC9kUK2qutEG/TqbefHAYE4=; b=YClUfUrvL8K7j0iIe71oC+zGCAPmniQiLfW36aJ+rGjJMKy36mOSSxCiodXBrVYWWl /f+XgfBDHBVAkuefQw5DtHKu8OvLY2DMfGPHNuu6BFzc/aq1ZXOXGxsdqr0SPcvDNp2B qqCIgWcD8VZy7/Ivq8yTwnZDqKBdCWsYPuav/nkv1rD3I1+qb8XJGFJgSxNWAbiK/JVo O9Ho6bb2tRCWnQftpgiNBiS/m5R0Fj3YqEVf6yGR3ejvYUTju5qx/+kiaHOkspdzz+yw /dyBTCp8zR1NlCWd7i6lruI7maiBBWGGSN/wpfE6HYuvUd/O1wBmBxsgyzRaVQMeNmhS DbVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=kuZ2q7jz; 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 w1-20020adfe041000000b0021d6c50028bsor873685wrh.60.2022.07.14.07.36.23 for (Google Transport Security); Thu, 14 Jul 2022 07:36: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:a5d:47ab:0:b0:21d:b2b1:59b1 with SMTP id 11-20020a5d47ab000000b0021db2b159b1mr8371824wrb.99.1657809382991; Thu, 14 Jul 2022 07:36:22 -0700 (PDT) Received: from panicking.. ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003973c54bd69sm5712357wmq.1.2022.07.14.07.36.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 07:36:22 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai , Boris Brezillon , Richard Weinberger , Patrice Chotard , Wolfgang Denk , u-boot@lists.denx.de (open list) Cc: Boris Brezillon , Simon Glass , u-boot@lists.denx.de (open list) Subject: [PATCH 10/11] mtd: nand: Move AMD/Spansion specific init/detection logic in nand_amd.c Date: Thu, 14 Jul 2022 16:35:42 +0200 Message-Id: <20220714143543.448991-11-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=kuZ2q7jz; 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 229204da53b31d576fcc1c93a33626943ea8202c Move AMD/Spansion specific initialization/detection logic into nand_amd.c. This is part of the "separate vendor specific code from core" cleanup process. Signed-off-by: Boris Brezillon Acked-by: Richard Weinberger Signed-off-by: Michael Trimarchi --- drivers/mtd/nand/raw/Makefile | 4 ++- drivers/mtd/nand/raw/nand_amd.c | 53 ++++++++++++++++++++++++++++++++ drivers/mtd/nand/raw/nand_base.c | 17 +--------- drivers/mtd/nand/raw/nand_ids.c | 2 +- include/linux/mtd/rawnand.h | 1 + 5 files changed, 59 insertions(+), 18 deletions(-) create mode 100644 drivers/mtd/nand/raw/nand_amd.c diff --git a/drivers/mtd/nand/raw/Makefile b/drivers/mtd/nand/raw/Makefile index e8fb451076..e1d511c12c 100644 --- a/drivers/mtd/nand/raw/Makefile +++ b/drivers/mtd/nand/raw/Makefile @@ -14,7 +14,8 @@ obj-$(CONFIG_SPL_NAND_DENALI) += denali_spl.o obj-$(CONFIG_SPL_NAND_SIMPLE) += nand_spl_simple.o obj-$(CONFIG_SPL_NAND_LOAD) += nand_spl_load.o obj-$(CONFIG_SPL_NAND_ECC) += nand_ecc.o -obj-$(CONFIG_SPL_NAND_BASE) += nand_base.o nand_hynix.o nand_micron.o nand_samsung.o nand_toshiba.o +obj-$(CONFIG_SPL_NAND_BASE) += nand_base.o nand_amd.o nand_hynix.o nand_micron.o \ + nand_samsung.o nand_toshiba.o obj-$(CONFIG_SPL_NAND_IDENT) += nand_ids.o nand_timings.o obj-$(CONFIG_TPL_NAND_INIT) += nand.o ifeq ($(CONFIG_SPL_ENV_SUPPORT),y) @@ -31,6 +32,7 @@ obj-y += nand_ids.o obj-y += nand_util.o obj-y += nand_ecc.o obj-y += nand_base.o +obj-y += nand_amd.o obj-y += nand_hynix.o obj-y += nand_micron.o obj-y += nand_samsung.o diff --git a/drivers/mtd/nand/raw/nand_amd.c b/drivers/mtd/nand/raw/nand_amd.c new file mode 100644 index 0000000000..f11166f361 --- /dev/null +++ b/drivers/mtd/nand/raw/nand_amd.c @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2017 Free Electrons + * Copyright (C) 2017 NextThing Co + * + * Author: Boris Brezillon + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include + +static void amd_nand_decode_id(struct nand_chip *chip) +{ + struct mtd_info *mtd = nand_to_mtd(chip); + + nand_decode_ext_id(chip); + + /* + * Check for Spansion/AMD ID + repeating 5th, 6th byte since + * some Spansion chips have erasesize that conflicts with size + * listed in nand_ids table. + * Data sheet (5 byte ID): Spansion S30ML-P ORNAND (p.39) + */ + if (chip->id.data[4] != 0x00 && chip->id.data[5] == 0x00 && + chip->id.data[6] == 0x00 && chip->id.data[7] == 0x00 && + mtd->writesize == 512) { + mtd->erasesize = 128 * 1024; + mtd->erasesize <<= ((chip->id.data[3] & 0x03) << 1); + } +} + +static int amd_nand_init(struct nand_chip *chip) +{ + if (nand_is_slc(chip)) + chip->bbt_options |= NAND_BBT_SCAN2NDPAGE; + + return 0; +} + +const struct nand_manufacturer_ops amd_nand_manuf_ops = { + .detect = amd_nand_decode_id, + .init = amd_nand_init, +}; diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index d2079c73fb..f79e57b9fb 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -4201,7 +4201,6 @@ static void nand_decode_id(struct nand_chip *chip, struct nand_flash_dev *type) { struct mtd_info *mtd = &chip->mtd; - int maf_id = chip->id.data[0]; mtd->erasesize = type->erasesize; mtd->writesize = type->pagesize; @@ -4209,19 +4208,6 @@ static void nand_decode_id(struct nand_chip *chip, /* All legacy ID NAND are small-page, SLC */ chip->bits_per_cell = 1; - - /* - * Check for Spansion/AMD ID + repeating 5th, 6th byte since - * some Spansion chips have erasesize that conflicts with size - * listed in nand_ids table. - * Data sheet (5 byte ID): Spansion S30ML-P ORNAND (p.39) - */ - if (maf_id == NAND_MFR_AMD && chip->id.data[4] != 0x00 && chip->id.data[5] == 0x00 - && chip->id.data[6] == 0x00 && chip->id.data[7] == 0x00 - && mtd->writesize == 512) { - mtd->erasesize = 128 * 1024; - mtd->erasesize <<= ((chip->id.data[3] & 0x03) << 1); - } } /* @@ -4246,8 +4232,7 @@ static void nand_decode_bbm_options(struct mtd_info *mtd, * Micron devices with 2KiB pages and on SLC Samsung, Hynix, Toshiba, * AMD/Spansion, and Macronix. All others scan only the first page. */ - if (nand_is_slc(chip) && - (maf_id == NAND_MFR_AMD || maf_id == NAND_MFR_MACRONIX)) + if (nand_is_slc(chip) && maf_id == NAND_MFR_MACRONIX) chip->bbt_options |= NAND_BBT_SCAN2NDPAGE; } diff --git a/drivers/mtd/nand/raw/nand_ids.c b/drivers/mtd/nand/raw/nand_ids.c index bb5ac8337f..c78f2e0880 100644 --- a/drivers/mtd/nand/raw/nand_ids.c +++ b/drivers/mtd/nand/raw/nand_ids.c @@ -196,7 +196,7 @@ struct nand_manufacturers nand_manuf_ids[] = { {NAND_MFR_STMICRO, "ST Micro"}, {NAND_MFR_HYNIX, "Hynix", &hynix_nand_manuf_ops}, {NAND_MFR_MICRON, "Micron", µn_nand_manuf_ops}, - {NAND_MFR_AMD, "AMD/Spansion"}, + {NAND_MFR_AMD, "AMD/Spansion", &amd_nand_manuf_ops}, {NAND_MFR_MACRONIX, "Macronix"}, {NAND_MFR_EON, "Eon"}, {NAND_MFR_SANDISK, "SanDisk"}, diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h index ec0f77b24b..bb1a359a9c 100644 --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -1142,6 +1142,7 @@ extern const struct nand_manufacturer_ops toshiba_nand_manuf_ops; extern const struct nand_manufacturer_ops samsung_nand_manuf_ops; extern const struct nand_manufacturer_ops hynix_nand_manuf_ops; extern const struct nand_manufacturer_ops micron_nand_manuf_ops; +extern const struct nand_manufacturer_ops amd_nand_manuf_ops; int nand_default_bbt(struct mtd_info *mtd); int nand_markbad_bbt(struct mtd_info *mtd, loff_t offs); From patchwork Thu Jul 14 14:35:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2177 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 3A59C3F066 for ; Thu, 14 Jul 2022 16:36:28 +0200 (CEST) Received: by mail-wr1-f69.google.com with SMTP id k26-20020adfb35a000000b0021d6c3b9363sf600063wrd.1 for ; Thu, 14 Jul 2022 07:36:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657809388; cv=pass; d=google.com; s=arc-20160816; b=G0bsBM5o4wHYNiSl2R+VtJ+2e2rmN1rRRgYWzEcZDfMwRQlT46ZpZspDiLjqiRHqN6 yV7mBZHet2M2w8a3dsT8MZo1m2z9PdpHKyhZd81m5FqO/JXN+JXnpr4p/kXqVEnUvp2u A7bzs+25jr00qsmw5o81qHIswb6FzZsw6Zwt/BHtgzLUPO39YPylxQpL3K1+exAoiCEZ uOn0hAyf5Fd7OzWLOFUaqfhchSIkWG+4/DtXUmm3qTyD6+mYBqYXvOoonedN6/0zHktT 8hX7r9XUWDVW+Q4yZ/LTU2fteCim8JGLxbNEc5hX+WX95D9YY977hWaLg7L0qv3V2BMc gRIg== 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=8hUoPkqEiSFS6XPC2M/gUARltnImO/Au3/3jE9dEg08=; b=QeFofFwJ51sPVbIVlY55LGNyy+eOIrjShAtgHVyDimucQNVu5W/y2Z5IsFsYt/JzJh DCWqD2wc1NNkhMZRpxo2I5RhvcPmhL2Zraf/pSGUn7gLhACiTJcJT7iJ2ZaGlO+vRInm sByhEqsh8aJSWiBUDDVrkB95ZUVb3VrVT55GHNvlrAfD4mkZfvFbWlZTHouPKGv15jLB UhFreXZiNcqCcPWyxFH0XhxmpSU/1hOjuFxxgAe8/H8bXVA4ntT/NqstZMekRJOxzck3 tjp+qOHgNKayblGduax+olR+SyqV8K/Gx1nBUC5Lvw9MZ3yhdy62G65C/oae5d4kDYgT qXew== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=d6LIp2T3; 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=8hUoPkqEiSFS6XPC2M/gUARltnImO/Au3/3jE9dEg08=; b=YPC2xHE2Fdiax0PM59u8ZS4FGRmCZSNV8yj01UYW/0NZaIqh/r2/VgA0AKxEvbvvPX Y9whea/TON0jae8Fdo45h9xJ95POzA658de5mgXW4smXAHZXB5JzbJE3eHtxe9Ypsf/F Q6tF/YHJbMhaA1msJh4gLtcPAQxF8wjIVTrHc= 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=8hUoPkqEiSFS6XPC2M/gUARltnImO/Au3/3jE9dEg08=; b=ayTSSZqIQJYbzXHO4vjeFWEum7tU7xykFW5uJV6AhmZ+BCYv0Hwt2534CfdkjJ3RT8 OEdHx6SoTWM/blHETvH73pb9MwOmzd+2aA/+LfzEDRIiK/egVM/mqma5BWXHwqdZso3E OIle7JChlARkLyYJ/gHXmmaNpjQXg9gD+g7SPZ4/p5CGe3/IkwTsxLY5izqy1XS3zpVh lyTN1oDpQT4H9p1ba6kcUdQPDFNpHzs9cQss1I6C0NtBeLVdGDKe9NESKOV630CD4Tu1 KRV7RDnZim8K2B73lwc0w5+WYgDxG5Vb452ZI3UQYiY4mY0JM8Y4m1ewfw5JcZnCM4hD mwpw== X-Gm-Message-State: AJIora83uAYR6H597rcKbKX+M3e/Vo9s7luXlkxNwB2yV3JGGEXV+U+n FbcLo09obFhZx7JcKqsWTXeRvHTc X-Google-Smtp-Source: AGRyM1tyevYuGki13Q6ZYbYyw/fJRO6LLHOMdIik/WgQhQygLzV1qJb9IWdhNNGivI25KTKau0gurQ== X-Received: by 2002:a05:6000:3c3:b0:21d:9a5e:5326 with SMTP id b3-20020a05600003c300b0021d9a5e5326mr8401719wrg.93.1657809388021; Thu, 14 Jul 2022 07:36:28 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:600c:3485:b0:3a2:e5bf:aeec with SMTP id a5-20020a05600c348500b003a2e5bfaeecls6275824wmq.0.canary-gmail; Thu, 14 Jul 2022 07:36:26 -0700 (PDT) X-Received: by 2002:a7b:cd82:0:b0:3a1:7528:2d79 with SMTP id y2-20020a7bcd82000000b003a175282d79mr15757034wmj.79.1657809386739; Thu, 14 Jul 2022 07:36:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657809386; cv=none; d=google.com; s=arc-20160816; b=mbIxZbPsO/j9VAQ4H6vAmXZ65ZliP5XdYtq3q3hkFNU0pKibWe1vWh8s1FrD3O+q4L tSuHuSqXxxouhVQ6nKxzbmdE+mZCsBlcMdXTGYMTfeszBlhOHj+dBRPgL16KTlkYxIym ToTkDqT8myHugGh/m3QAKulWhU2zovnogvlLSk/hQLnh6M6S9UjIGuDN/I38Zl2Hpzl8 Pxt0P3TtHLsBkhTdSCnAcA159g7iCUwFgj2+ew1u1YG3pnhtIJyp6Dko+mnphcgwsavc IL0ksqiv5deQZI1w+I1Ey/GpseBQJPtU8BRbeUHXC26k+5APMylrC4oo60H6/7rDlkDw t+yQ== 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=sFuEqjFl/Mfka6FIE5bPT04aWRpTL+eJm4w2Fjxnrrg=; b=mr828daIVM6LxA48ilnagFXOnVMnLR634Sk7z8/L8BTobVKWCcsf3Vr7d64lNKdC6q rcKpVA+21/XI9MFg23jUqJBF8N2X2s+6ZCRVPakIucYm/booBNYjHosp+dqIwUfRfKUG jcP1lOS8F0khYwhc8yNepULLxY3JVuOP0rPHEgGMob1BTAuqzRoC4/PUpH4E9bB/t3q1 oUIpjOf5MbP52PMgqvFiwgOdJ0cbZnMt5muxCzYwpiXsEVxcFBsiicCUm3BezUCn5G76 JVi9mqJZkP2R9xr7AlZo3cDfrOybGqzhVJ2vW1USujJYzP6fS0UZ7KrbagWWi7RtPCzk Pwlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=d6LIp2T3; 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 j2-20020adfa782000000b0021d8b1a6796sor900939wrc.16.2022.07.14.07.36.26 for (Google Transport Security); Thu, 14 Jul 2022 07:36:26 -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:6000:1549:b0:21d:c154:486d with SMTP id 9-20020a056000154900b0021dc154486dmr4448312wry.50.1657809385951; Thu, 14 Jul 2022 07:36:25 -0700 (PDT) Received: from panicking.. ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003973c54bd69sm5712357wmq.1.2022.07.14.07.36.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 07:36:25 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai , Boris Brezillon , Richard Weinberger , Patrice Chotard , Simon Glass , Wolfgang Denk , u-boot@lists.denx.de (open list) Cc: Boris Brezillon , u-boot@lists.denx.de (open list) Subject: [PATCH 11/11] mtd: nand: Move Macronix specific initialization in nand_macronix.c Date: Thu, 14 Jul 2022 16:35:43 +0200 Message-Id: <20220714143543.448991-12-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=d6LIp2T3; 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 3b5206f4be9b65d2f0f85b3239cf117a1d0de7ce Move Macronix specific initialization logic into nand_macronix.c. This is part of the "separate vendor specific code from core" cleanup process. Signed-off-by: Boris Brezillon Signed-off-by: Michael Trimarchi --- drivers/mtd/nand/raw/Makefile | 4 +++- drivers/mtd/nand/raw/nand_base.c | 11 ---------- drivers/mtd/nand/raw/nand_ids.c | 2 +- drivers/mtd/nand/raw/nand_macronix.c | 32 ++++++++++++++++++++++++++++ include/linux/mtd/rawnand.h | 1 + 5 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 drivers/mtd/nand/raw/nand_macronix.c diff --git a/drivers/mtd/nand/raw/Makefile b/drivers/mtd/nand/raw/Makefile index e1d511c12c..c8317a1078 100644 --- a/drivers/mtd/nand/raw/Makefile +++ b/drivers/mtd/nand/raw/Makefile @@ -14,7 +14,8 @@ obj-$(CONFIG_SPL_NAND_DENALI) += denali_spl.o obj-$(CONFIG_SPL_NAND_SIMPLE) += nand_spl_simple.o obj-$(CONFIG_SPL_NAND_LOAD) += nand_spl_load.o obj-$(CONFIG_SPL_NAND_ECC) += nand_ecc.o -obj-$(CONFIG_SPL_NAND_BASE) += nand_base.o nand_amd.o nand_hynix.o nand_micron.o \ +obj-$(CONFIG_SPL_NAND_BASE) += nand_base.o nand_amd.o nand_hynix.o \ + nand_macronix.o nand_micron.o \ nand_samsung.o nand_toshiba.o obj-$(CONFIG_SPL_NAND_IDENT) += nand_ids.o nand_timings.o obj-$(CONFIG_TPL_NAND_INIT) += nand.o @@ -34,6 +35,7 @@ obj-y += nand_ecc.o obj-y += nand_base.o obj-y += nand_amd.o obj-y += nand_hynix.o +obj-y += nand_macronix.o obj-y += nand_micron.o obj-y += nand_samsung.o obj-y += nand_toshiba.o diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index f79e57b9fb..a38cc4d135 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -4218,22 +4218,11 @@ static void nand_decode_id(struct nand_chip *chip, static void nand_decode_bbm_options(struct mtd_info *mtd, struct nand_chip *chip) { - int maf_id = chip->id.data[0]; - /* Set the bad block position */ if (mtd->writesize > 512 || (chip->options & NAND_BUSWIDTH_16)) chip->badblockpos = NAND_LARGE_BADBLOCK_POS; else chip->badblockpos = NAND_SMALL_BADBLOCK_POS; - - /* - * Bad block marker is stored in the last page of each block on Samsung - * and Hynix MLC devices; stored in first two pages of each block on - * Micron devices with 2KiB pages and on SLC Samsung, Hynix, Toshiba, - * AMD/Spansion, and Macronix. All others scan only the first page. - */ - if (nand_is_slc(chip) && maf_id == NAND_MFR_MACRONIX) - chip->bbt_options |= NAND_BBT_SCAN2NDPAGE; } static inline bool is_full_id_nand(struct nand_flash_dev *type) diff --git a/drivers/mtd/nand/raw/nand_ids.c b/drivers/mtd/nand/raw/nand_ids.c index c78f2e0880..7602dd30f1 100644 --- a/drivers/mtd/nand/raw/nand_ids.c +++ b/drivers/mtd/nand/raw/nand_ids.c @@ -197,7 +197,7 @@ struct nand_manufacturers nand_manuf_ids[] = { {NAND_MFR_HYNIX, "Hynix", &hynix_nand_manuf_ops}, {NAND_MFR_MICRON, "Micron", µn_nand_manuf_ops}, {NAND_MFR_AMD, "AMD/Spansion", &amd_nand_manuf_ops}, - {NAND_MFR_MACRONIX, "Macronix"}, + {NAND_MFR_MACRONIX, "Macronix", ¯onix_nand_manuf_ops}, {NAND_MFR_EON, "Eon"}, {NAND_MFR_SANDISK, "SanDisk"}, {NAND_MFR_INTEL, "Intel"}, diff --git a/drivers/mtd/nand/raw/nand_macronix.c b/drivers/mtd/nand/raw/nand_macronix.c new file mode 100644 index 0000000000..3cccb5869a --- /dev/null +++ b/drivers/mtd/nand/raw/nand_macronix.c @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2017 Free Electrons + * Copyright (C) 2017 NextThing Co + * + * Author: Boris Brezillon + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include + +static int macronix_nand_init(struct nand_chip *chip) +{ + if (nand_is_slc(chip)) + chip->bbt_options |= NAND_BBT_SCAN2NDPAGE; + + return 0; +} + +const struct nand_manufacturer_ops macronix_nand_manuf_ops = { + .init = macronix_nand_init, +}; diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h index bb1a359a9c..aa45558b3d 100644 --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -1143,6 +1143,7 @@ extern const struct nand_manufacturer_ops samsung_nand_manuf_ops; extern const struct nand_manufacturer_ops hynix_nand_manuf_ops; extern const struct nand_manufacturer_ops micron_nand_manuf_ops; extern const struct nand_manufacturer_ops amd_nand_manuf_ops; +extern const struct nand_manufacturer_ops macronix_nand_manuf_ops; int nand_default_bbt(struct mtd_info *mtd); int nand_markbad_bbt(struct mtd_info *mtd, loff_t offs);