From patchwork Thu Jul 14 14:02:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2155 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 3FDD93F013 for ; Thu, 14 Jul 2022 16:02:25 +0200 (CEST) Received: by mail-wm1-f69.google.com with SMTP id i187-20020a1c3bc4000000b003a2fe4c345csf258108wma.0 for ; Thu, 14 Jul 2022 07:02:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657807345; cv=pass; d=google.com; s=arc-20160816; b=sG5tM3gma2TREGSTC3BqexDAMavTna8ZlIU+fQErkXGkzYuKy8/g1Pgeq8hkeqfPwa 6UOxPt8f1xtQUKMlH9YVhNXUYzE8s0/EfKB69HoPxPyDD1LovUvAPNcluKfo7sP+d/nK C4HQXUEbcHkwQg9DEeMnwjXD4huboB1tWC2G8bmmsqzCCU1cUx6kDIpffUJllEfhKZV9 lN44z6C62hjvV2Xq7O8zPPBqRxBfsnWI027xS3T6QryNB7+GdU8UikqfGIhR3DV5wyIu iPanWsXoou+fe5YjrMINL5E/Lc6HkOd6f5HPg9acpYsh9tUXrCCq1e1fo1UlYpnyUrVU yqRg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=7hvMNiOy/LOqCyI3v4/0P1pp7mZMWWzUh5Cka+00Ah8=; b=GtLBRAORF0EYCuQDP8ySRq+HaejOSv9UoAsyw1vK2LugGdicvxaNwwNHT7ruRq9r4/ 4DX2gSTIn1NDjN6hKdIagr0gAnQZwnbCqjO0M0pjHl1FQi2hewtoVSPwrsqSePW1nCHG pWuYAFsl0TmHMKe1WIIAN26Ii4BOnJNcpJSFUQtT8dnTEHuYFXH2nUuh+w90EmkgWEN7 ey8S3NHQ/e7Ydpr2JQYs+bBglFBrdpSTUd0xXmF4BU926ag4FcppmA6Hz0C06HD1Vr07 VB4ItKr6R9kUVxjYbwyT+Ew0UpFY1Kftt5DBQpo1DhKaQ3pt4LuQqOoWp7xHF/ganU5X Iq0w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=OglpZGmB; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=7hvMNiOy/LOqCyI3v4/0P1pp7mZMWWzUh5Cka+00Ah8=; b=j+s+b5x9O/XtEykSPo38QHqMhbNCXS7BgCePuntDefN7BIzGI0guRV+sHwTeppaD3+ UGX2lSu8OrUINbG07HgjRlvkgBi5h/uWPdiMnnywGgz+Yqy46Q1n1TYdVJhIzkjmbeuX sU/AgoUW+4Za44oBrZ//YD7msFcf1ssCDKsoI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=7hvMNiOy/LOqCyI3v4/0P1pp7mZMWWzUh5Cka+00Ah8=; b=7lpDfy+F8oyCSc8uS/s3jGP8+aWi6N8YSYKIjjzlRJ8GZPYWp+PxrsfFWG4WGOkNBb D215KwLgyiaLHK3JdvpCQbTtAuQs0/ucV9aybuwVESiunnuQ5c2WVKxYvAlja+Okx/aF 4jgu0bXwtZj18hyRvvVJ9air6KlfjrcUh42BSPSLzqrngbb5tHlcjeKw8gCr/dpqysOO JAlZm+/jqi6OYX2TLM7hvxZ5Q9t/TUEsW9boLrDSRI254aSKgY0ZhSPtfExfutLvwlic TjgQY6Ak+bml4BobnfvsGFr7FW8aFvaLZwSLSH0+Ftu/FXWiF7BcPaREaOi0Kaajlq0c rXTg== X-Gm-Message-State: AJIora9wiqPeaGj7KdbYvzqOnJhFNZ+kE9qkvJSJMdskhj+V5aKsYfzc KmrL/BtPNZIjeWTLts6ALUVh6adT X-Google-Smtp-Source: AGRyM1sYdKpysLLDEUWDCqO9hpd+Yg9yWwVysCf6aT6icXPgxIgLFLYH+I9jkPPFYXk2lXYswMrepA== X-Received: by 2002:a05:6000:98b:b0:21d:b70f:2726 with SMTP id by11-20020a056000098b00b0021db70f2726mr8525505wrb.237.1657807344974; Thu, 14 Jul 2022 07:02:24 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6000:1ac7:b0:21d:ab25:25ba with SMTP id i7-20020a0560001ac700b0021dab2525bals108816wry.2.gmail; Thu, 14 Jul 2022 07:02:23 -0700 (PDT) X-Received: by 2002:a5d:4692:0:b0:21d:8e7d:b425 with SMTP id u18-20020a5d4692000000b0021d8e7db425mr8058824wrq.267.1657807343025; Thu, 14 Jul 2022 07:02:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657807343; cv=none; d=google.com; s=arc-20160816; b=QRVvu+N975yk0xnw3pBiFRx6mzDms1RQ8DEbcaq+h4Af6vBd5FBP2yI4LEwO6SS27C CCezTjSOtAcCwd8MKcqLtjKOOIMJyFaVh+1yzd75oAsDXTOXTCcu42dTnfB4xzBLzl5i CyFKco9qnFOLmoU3KDo8TQwn/KPD8oRrZUXOFyPYJKRqRVY+OSfv9SwgVVovXsfEb6eL fafrCGYNVySUdcy70b6uA0JLL+bRK4set+5XgZmWVESffFRee2oxe1fnM3BTDATp5Sk6 SR+RMZyTu5X9ZX/CWOIXV0w/3Kg1jrNVLm/dPaumL5M4Hu7b9QGY3Iq57thbZDVA0Lyw +bTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=JxxWXuTcu0HTKh33nVMpbU0X7/H1gnpPd0sUG9SCaRk=; b=rFkN0s6hulDixR3wcv6ExDl98PALALQtwa9MvPs+hwxg2e6aICFZ+febt2NleMj83/ Tzk5WQtSZdIUg+s+KgLeUQO7RdXxal2T6s6ApU9tsizbmGXaIFgI7Up8eYsJgMC0/Jww gnfkSjvvm2M2Xjx7+zbcOfQogtnjEmd7EKe/VlcW7isJhIE5hD+J7k7qB2ku3U9bBGKi 5UC/5i+nzvRMhOr30haGfwAC8boVNFTtQNWIikFwKv7LuTuSZtFaPureMS9XCx36DN5n cAWi38oIUmPoZv/jU0abI75XlvrDpvdp5EYaFBZb9v4x+pjbNRIyDuIrKceS2tAEIsDe hrBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=OglpZGmB; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id 14-20020a5d47ae000000b0021dbcd93518sor812013wrb.8.2022.07.14.07.02.23 for (Google Transport Security); Thu, 14 Jul 2022 07:02:23 -0700 (PDT) Received-SPF: pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Received: by 2002:adf:fb03:0:b0:21d:70cb:d6b5 with SMTP id c3-20020adffb03000000b0021d70cbd6b5mr8235963wrr.548.1657807342158; Thu, 14 Jul 2022 07:02:22 -0700 (PDT) Received: from panicking.. ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id k11-20020a7bc40b000000b0039c5cecf206sm2029114wmi.4.2022.07.14.07.02.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 07:02:21 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai Subject: [PATCH 01/11] mtd: nand: Get rid of busw parameter Date: Thu, 14 Jul 2022 16:02:05 +0200 Message-Id: <20220714140215.444993-2-michael@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220714140215.444993-1-michael@amarulasolutions.com> References: <20220714140215.444993-1-michael@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: michael@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=OglpZGmB; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Upstream commit 29a198a1592d83f2bc1be3b2631b3bcf3d5b380f Auto-detection functions are passed a busw parameter to retrieve the actual NAND bus width and eventually set the correct value in chip->options. Rework the nand_get_flash_type() function to get rid of this extra parameter and let detection code directly set the NAND_BUSWIDTH_16 flag in chip->options if needed. Signed-off-by: Boris Brezillon Acked-by: Richard Weinberger Reviewed-by: Marek Vasut Signed-off-by: Michael Trimarchi --- drivers/mtd/nand/raw/nand_base.c | 59 +++++++++++++++++--------------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index e8ece0a4a0..9a2194ebd3 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -3898,8 +3898,7 @@ static void nand_onfi_detect_micron(struct nand_chip *chip, /* * Check if the NAND chip is ONFI compliant, returns 1 if it is, 0 otherwise. */ -static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, - int *busw) +static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip) { struct nand_onfi_params *p = &chip->onfi_params; char id[4]; @@ -3971,9 +3970,7 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, chip->bits_per_cell = p->bits_per_cell; if (onfi_feature(chip) & ONFI_FEATURE_16_BIT_BUS) - *busw = NAND_BUSWIDTH_16; - else - *busw = 0; + chip->options |= NAND_BUSWIDTH_16; if (p->ecc_bits != 0xff) { chip->ecc_strength_ds = p->ecc_bits; @@ -4003,8 +4000,7 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, return 1; } #else -static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, - int *busw) +static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip) { return 0; } @@ -4013,8 +4009,7 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, /* * Check if the NAND chip is JEDEC compliant, returns 1 if it is, 0 otherwise. */ -static int nand_flash_detect_jedec(struct mtd_info *mtd, struct nand_chip *chip, - int *busw) +static int nand_flash_detect_jedec(struct mtd_info *mtd, struct nand_chip *chip) { struct nand_jedec_params *p = &chip->jedec_params; struct jedec_ecc_info *ecc; @@ -4076,9 +4071,7 @@ static int nand_flash_detect_jedec(struct mtd_info *mtd, struct nand_chip *chip, chip->bits_per_cell = p->bits_per_cell; if (jedec_feature(chip) & JEDEC_FEATURE_16_BIT_BUS) - *busw = NAND_BUSWIDTH_16; - else - *busw = 0; + chip->options |= NAND_BUSWIDTH_16; /* ECC info */ ecc = &p->ecc_info[0]; @@ -4168,7 +4161,7 @@ static int nand_get_bits_per_cell(u8 cellinfo) * manufacturer-specific "extended ID" decoding patterns. */ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, - u8 id_data[8], int *busw) + u8 id_data[8]) { int extid, id_len; /* The 3rd id byte holds MLC / multichip data */ @@ -4221,7 +4214,6 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, /* Calc blocksize */ mtd->erasesize = (128 * 1024) << (((extid >> 1) & 0x04) | (extid & 0x03)); - *busw = 0; } else if (id_len == 6 && id_data[0] == NAND_MFR_HYNIX && !nand_is_slc(chip)) { unsigned int tmp; @@ -4262,7 +4254,6 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, mtd->erasesize = 768 * 1024; else mtd->erasesize = (64 * 1024) << tmp; - *busw = 0; } else { /* Calc pagesize */ mtd->writesize = 1024 << (extid & 0x03); @@ -4275,7 +4266,9 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, mtd->erasesize = (64 * 1024) << (extid & 0x03); extid >>= 2; /* Get buswidth information */ - *busw = (extid & 0x01) ? NAND_BUSWIDTH_16 : 0; + /* Get buswidth information */ + if (extid & 0x1) + chip->options |= NAND_BUSWIDTH_16; /* * Toshiba 24nm raw SLC (i.e., not BENAND) have 32B OOB per @@ -4301,15 +4294,13 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, * the chip. */ static void nand_decode_id(struct mtd_info *mtd, struct nand_chip *chip, - struct nand_flash_dev *type, u8 id_data[8], - int *busw) + struct nand_flash_dev *type, u8 id_data[8]) { int maf_id = id_data[0]; mtd->erasesize = type->erasesize; mtd->writesize = type->pagesize; mtd->oobsize = mtd->writesize / 32; - *busw = type->options & NAND_BUSWIDTH_16; /* All legacy ID NAND are small-page, SLC */ chip->bits_per_cell = 1; @@ -4371,7 +4362,7 @@ static inline bool is_full_id_nand(struct nand_flash_dev *type) } static bool find_full_id_nand(struct mtd_info *mtd, struct nand_chip *chip, - struct nand_flash_dev *type, u8 *id_data, int *busw) + struct nand_flash_dev *type, u8 *id_data) { if (!strncmp((char *)type->id, (char *)id_data, type->id_len)) { mtd->writesize = type->pagesize; @@ -4386,8 +4377,6 @@ static bool find_full_id_nand(struct mtd_info *mtd, struct nand_chip *chip, chip->onfi_timing_mode_default = type->onfi_timing_mode_default; - *busw = type->options & NAND_BUSWIDTH_16; - if (!mtd->name) mtd->name = type->name; @@ -4449,9 +4438,24 @@ struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, if (!type) type = nand_flash_ids; + /* + * Save the NAND_BUSWIDTH_16 flag before letting auto-detection logic + * override it. + * This is required to make sure initial NAND bus width set by the + * NAND controller driver is coherent with the real NAND bus width + * (extracted by auto-detection code). + */ + busw = chip->options & NAND_BUSWIDTH_16; + + /* + * The flag is only set (never cleared), reset it to its default value + * before starting auto-detection. + */ + chip->options &= ~NAND_BUSWIDTH_16; + for (; type->name != NULL; type++) { if (is_full_id_nand(type)) { - if (find_full_id_nand(mtd, chip, type, id_data, &busw)) + if (find_full_id_nand(mtd, chip, type, id_data)) goto ident_done; } else if (*dev_id == type->dev_id) { break; @@ -4461,11 +4465,11 @@ struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, chip->onfi_version = 0; if (!type->name || !type->pagesize) { /* Check if the chip is ONFI compliant */ - if (nand_flash_detect_onfi(mtd, chip, &busw)) + if (nand_flash_detect_onfi(mtd, chip)) goto ident_done; /* Check if the chip is JEDEC compliant */ - if (nand_flash_detect_jedec(mtd, chip, &busw)) + if (nand_flash_detect_jedec(mtd, chip)) goto ident_done; } @@ -4479,10 +4483,11 @@ struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, if (!type->pagesize) { /* Decode parameters from extended ID */ - nand_decode_ext_id(mtd, chip, id_data, &busw); + nand_decode_ext_id(mtd, chip, id_data); } else { - nand_decode_id(mtd, chip, type, id_data, &busw); + nand_decode_id(mtd, chip, type, id_data); } + /* Get chip options */ chip->options |= type->options; From patchwork Thu Jul 14 14:02:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2156 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 80CBE3F013 for ; Thu, 14 Jul 2022 16:02:26 +0200 (CEST) Received: by mail-wr1-f72.google.com with SMTP id o1-20020adfba01000000b0021b90bd28d2sf576872wrg.14 for ; Thu, 14 Jul 2022 07:02:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657807346; cv=pass; d=google.com; s=arc-20160816; b=ju1h4cYwu5NGAECcQcrrY1HH/mQ9FsQxpCiM20URNIfzxPpfV1NsiYprnSid1GNxTe JM0HAW27bhTkhGn35epiLfd1dZ/JIc5nLqumcbZ2iemQs3PcUpSk3yOWZc7/u8wnIOrW k14MMVF8km4EAORUp3W7a21JWABVAmAGu0j65mNJcgshz00WWvZs1nDjNtx9NcLS81+a X4Bo9vl+iduQ0N0B5rvf9+q9mbxVMtgn7++WFfQwedvww83Ipxw0NRDvWFlUup9XKH5m X+5I0kXCXgcsBg6NDZ1E92KdrRi7sOSeU1GZE3PU/OBz/8ElvWae98f+HKQoYTMMdwEm WLRg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=U6KVHMVhDQfZo32KbkTv2zF8IG0l7kHLolyZ6xRwLFk=; b=oYTkM4ouMvepgCl0n046FxCv6dHDRQgAwniLQhC92kP50fFcbeksoWl46q/ypT/+Y9 tEM9heW4k7Ahfk+BQUV3Zttse2VJOMSc0fPNsx676opFfxE+i7YKdLv06ZUp9ZCRNkMH Jm7MD3W516bazrME9v0D7cR3Im/75X4roQFPDik9lmNjAeCMbR3koYEfAPMJh+gdzwAM 23mRrKXWUN6/E/tny96e2Ig0XE0jeMSycccFta8jKLrYGTOq2FZnFrTO8V3SAzJ+71se NTcvMgJrWmiojRQchra83B3KBBW6TC3ubBGJd9SumuM38PIdnMqgyvQV3bSSjZnvYRU2 fU+w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=kCJST0gT; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=U6KVHMVhDQfZo32KbkTv2zF8IG0l7kHLolyZ6xRwLFk=; b=oA7O46+icsWkYkszfRouTVaRNhST8HktyCQB1rtvzhp3YJbiv2Ju1DFM5mT+DtRmbu 6TGQAdIpL0CJgk3RIb6z5byGUbQms2UpGWY0HkagqOWIPmSk8BNenH+q8YFtd5LXHDu3 RJKNKRiPaqr+2VfeTxjG4xDESH8AM+fOwy1sQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=U6KVHMVhDQfZo32KbkTv2zF8IG0l7kHLolyZ6xRwLFk=; b=y63sARKn5EwJKpOVtnntg4cRfvFCX/DHydA7CcIV0GE6HXm+2yoVeDhDaL18j4U877 qj6RRyNUFqxHRs0SxvTFcdfvsXyMmL83AfFEwxHoa2tBml8K17Ht+X68TmcM3k70DE0d jInu5H45Jf3p+g22+tA6OnLgc5yxI9L84Lw+1fJvF5evCBVhYsKHjyHhm8CA+kuy9rqP yJFlYjog3iK2wk0p1+OgUeow7xYn4W70Q8AEEb4ixOeYnkankjquvlIo4Ttmns8uF/yo dqmwWQDg6ZHXeDKisoc0nvProamTfiyhDRiykvZYSnIlPz6EhK5VA5jsCghzEQYKY034 Sqcw== X-Gm-Message-State: AJIora/+WqwYXAYF2ukgpIUVRGO1yjFasc1eEmcQy3LOGM+0jWDgYgus y2zNNKcCHv60v3mMCWmBoQSJdqwp X-Google-Smtp-Source: AGRyM1ubfW5rjphmpOpayS48sKNadm4dnCzPsyYhbBlmc0o6L74gWlBsf8P0yKIeLuSB533B9fE5pQ== X-Received: by 2002:a1c:4487:0:b0:3a2:fb76:7981 with SMTP id r129-20020a1c4487000000b003a2fb767981mr8880003wma.98.1657807346104; Thu, 14 Jul 2022 07:02:26 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a5d:588d:0:b0:21d:339f:dc1 with SMTP id n13-20020a5d588d000000b0021d339f0dc1ls108198wrf.0.gmail; Thu, 14 Jul 2022 07:02:24 -0700 (PDT) X-Received: by 2002:adf:c64c:0:b0:21a:7a3:54a4 with SMTP id u12-20020adfc64c000000b0021a07a354a4mr8488717wrg.163.1657807344773; Thu, 14 Jul 2022 07:02:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657807344; cv=none; d=google.com; s=arc-20160816; b=rshVvMifG/0Ls1E/tCokZ9SN7QEZbsAygTIa7HU/pPSaeY+Mv5c9QSCMHirB3zwOvP z7BhIuyVET6AxyB+vptjpEPyEhby4AHKkufqXSynpZEBouUYs1rbIRJp5v+WYZsTsAsX y8vTTDf2Ckrgqr8c+szi8CudLmBJO5vepZQETdDWSTbCi6PrSWQhZdyZmM9cDJ3XHENu iGXyODZZMnhZm8u6ZwU3+MBk1E+h2q2zRmyZC7p73SJF7GsdY7reFvg1qB9TAyIm/3OD qqFoLco5JgOuLByn7PEMxKungySI2Ro/MiEuO8WhVz5OB5hqZ/g9dO5AJclLVxOIXkgs avtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=diK71uX3lIh/YgoKebxDYbelkMlwygsjJFrjrAg4a/M=; b=jFF5nAKEy0p7OMoeY2Va81N8p6+C55vPizQTB6+vRhBZjQClTTEn5pHRQTLS53eC7F k9gXMufMjfmQaOvQoW6XzB5dOyaU16jkPuKc1LbfAzzq0LIqpFqkMPjDjDMlaZL5wQUB s+JilDMrae0i4jguRK8gFTNKSmRj5EsDj6Dm+/m+yd/Xjo8i672SKa7266qPtYI8kig8 Xx4lPM8RcCibpftIedevTEzYQekBXDHulxsbtEOjyMc6R48CDR6x4PdVcG2lTPaDOeUX 9+EJuiQYkj6b4QSJnT1iSuMsUOddD4EE70jprtVdHlfVILf6KAfP2AsUXNUhejFIfWwH nofg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=kCJST0gT; 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 o14-20020a5d47ce000000b0021d7b3aaca7sor815957wrc.78.2022.07.14.07.02.24 for (Google Transport Security); Thu, 14 Jul 2022 07:02:24 -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:68c:b0:21d:868a:7f2e with SMTP id bo12-20020a056000068c00b0021d868a7f2emr8500283wrb.335.1657807343932; Thu, 14 Jul 2022 07:02:23 -0700 (PDT) Received: from panicking.. ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id k11-20020a7bc40b000000b0039c5cecf206sm2029114wmi.4.2022.07.14.07.02.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 07:02:23 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai Subject: [PATCH 02/11] mtd: nand: Store nand ID in struct nand_chip Date: Thu, 14 Jul 2022 16:02:06 +0200 Message-Id: <20220714140215.444993-3-michael@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220714140215.444993-1-michael@amarulasolutions.com> References: <20220714140215.444993-1-michael@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: michael@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=kCJST0gT; 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:02:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2157 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 ED2383F013 for ; Thu, 14 Jul 2022 16:02:28 +0200 (CEST) Received: by mail-wm1-f69.google.com with SMTP id bg6-20020a05600c3c8600b003a03d5d19e4sf808505wmb.1 for ; Thu, 14 Jul 2022 07:02:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657807348; cv=pass; d=google.com; s=arc-20160816; b=mz6jcAVRrXghP6g3vnMITIaZ6xLCpp1lWoMnwN1VWiQ502wLC5tnacscJ932yPp9rp 6YfklzgoZDJmux3wCF5fgplhYOW8sV1b7qOjqx+cCpy/AOoKMiOp4rVnP1rEIcy8PkuE Ao0+gA/IZgK+zzrd0B7E6DpglShKHAbGXr3hFG/dSfxBQInWmDNqAi5dVyuVE4kgHIrw Dqr5UuimCQuwCjfjfFCbsc/+nqzB588kG4nDasRR349wkznjZk9WlZegsgxutvAReExf 6OvnkoXaYuCxaCZZBmt60gGUQEZir19EBSfdfXbdMbSdtMooAr5nSWi7mPMYF3GpXb5t 0IIQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=Z+M1ItdFJHYx2BwAoYAsuhoRsY+QaBLWxfpo4/jPYQA=; b=lsR1+jUofuZ/yeoM6pP2MIMGu39ku7WSGeYqs1eGCiezln+2NnHifjiJ3bmWwWoCA0 /b69q5wSY8mkNkrW3mt8GVOqofX7I0Qa7uZl5GnHqIu2rPFpBLi4uJ9kg3r5ZaQ2L3vo p3vSW5mYexMFGY57axW0dPDCkKQnVa+bqfM0cfSZAZFTk5jr1g15QY+EUqKdRpqQjMCW hWauh4ghWLJcbWU+mfC10ouYwPoAwqWW3bdKpe0jTDEY72GIPnbxeXlOEny+jUFVWNIL 89OIumJHbJpBKEnbBPb7jSiiICphKGtgrj+NGpNhOe487sifqzOqDa1bqvZsPhdkjGWC UBig== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=dniUdoR4; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=Z+M1ItdFJHYx2BwAoYAsuhoRsY+QaBLWxfpo4/jPYQA=; b=BJL+wkH5zeUE1Viq3Vy676Kkj464O5nkI62iGXyHx6tVrIEZy/4+KWTibjRArXiJwE fxr+iifSr9dgfjiSrXTyTaqAUOA2nQktGBhAyVL1gWKSCREwxekfLwOWP547TL3nsrDV wCRJN1xhVuY0lwM5QPlXcxNamMFUimioaFffw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=Z+M1ItdFJHYx2BwAoYAsuhoRsY+QaBLWxfpo4/jPYQA=; b=JdCjRal3KCoDeiXFLUsnegGmgdGABtvYqaLSOcvHvDcyAIS3zEcaqES8DCiP9BnWcq P0DvE+oOTOdgVDTzMtSZBx3J9e3Y4teD19HV931fqLirx9tBcMsO9/EDNwSdSKXlYL44 NeJ2u6oa1NObrRJyUQPbRAK+QFR8Tv1n4I31Nkl62jAWdXrpmtOZyLu1pcfd9sB4/pGN 9twWhUGpwdup055AJCqD1aE0tKwYgzthIfbhqxxyMxvkdfa+o0pCPjdAM0XtkQf6+m5O frqX1/oT8UCnSylZjU8PFsmB8smlZtEGzSY7gkUC/S5noMrImImfNcM9TG3PJMBu6ULR Hzag== X-Gm-Message-State: AJIora8Pf9Km4woTJSAw+aZK80uMu5SxliP6AWpBFQPkcWbo67NzcLLD Ytq5f4EJMIfK59NkIRkgorcZgVh5 X-Google-Smtp-Source: AGRyM1tCS6oDReHBUgxZJZ/JsayCQBygunng3Ys5t1jJLroX9/OAbkm78nKF+mtFaDBvQY5+A53syQ== X-Received: by 2002:a05:6000:2a8:b0:21d:8c81:7eb0 with SMTP id l8-20020a05600002a800b0021d8c817eb0mr8222954wry.460.1657807348670; Thu, 14 Jul 2022 07:02:28 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6000:1849:b0:21d:9b2c:2273 with SMTP id c9-20020a056000184900b0021d9b2c2273ls109673wri.1.gmail; Thu, 14 Jul 2022 07:02:27 -0700 (PDT) X-Received: by 2002:a05:6000:1d86:b0:21d:6433:1455 with SMTP id bk6-20020a0560001d8600b0021d64331455mr8608262wrb.514.1657807347256; Thu, 14 Jul 2022 07:02:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657807347; cv=none; d=google.com; s=arc-20160816; b=xBYhxt2HozvwszBhpA9zeGKGWUY321EfqsJghGl8ofOgf9Hw+A3Z6gp+g7tQ8hbZfU N9dhM/6qu923VBQmFYR15uhXynjkHPUVuOVpJUIn+SsWeIsUnRfr9EYa9kQxmvuNrArT lBgM1H/EnYbx2X76fAjqdsovfZuIAhCyk1QKsfRiK8FsqNajF4MNBmzsBaFpgvkTbZSd ZMR3U/9Y3SGAUVpkduLmEZm3m4SX0recI94MKK+M3VVnQo+Uw9v0MeAEF3y/tTEh8bxa tx4EqZb7DTLFdDinCFOQIpeD4+5X3Q8TXaE+xN67/aSy2AEczg4884VH73u4ZSlnBXB0 W5Ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=7/o+mGV8ywUVtQz4G7CKHG/IM0njUkMjI+CMpXHKhCc=; b=cFag3tq6XGY3Ao0f0gZagSmWdXG2BDVtMqTA7UMn7qnLfT7HizdGcWSFE4Zq5MB4qL ahJk/jdDLyE0t4H7fut6+NFvywj4eUfEm25NGTyuMpyrT7PUtkXOfHGMrEYBTzznrwP8 R1ntAxug2ioK2V7BX+XDYIHQtBhG0zNYKpkvQCG3tP4XKCHhEpGlVRglQm891SWtkltL y/Gvz99qdfAjWqPPv9fTlUayMLLPLO7Moje3Nf7g8uVK4+UktJ7aL02mLLwqfUbZbw7y OqkrUQ/1OiuznfaUoMQ92pLTws7BtzmBTCqquGuxnBQC3AH8D/eAOnUY3O7RDisWKxNA kb2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=dniUdoR4; 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 k13-20020a05600c0b4d00b003a2d3ee66c4sor1294739wmr.13.2022.07.14.07.02.27 for (Google Transport Security); Thu, 14 Jul 2022 07:02:27 -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:4487:0:b0:3a2:fb76:7981 with SMTP id r129-20020a1c4487000000b003a2fb767981mr8879995wma.98.1657807345961; Thu, 14 Jul 2022 07:02:25 -0700 (PDT) Received: from panicking.. ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id k11-20020a7bc40b000000b0039c5cecf206sm2029114wmi.4.2022.07.14.07.02.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 07:02:25 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai Subject: [PATCH 03/11] mtd: nand: Add manufacturer specific initialization/detection steps Date: Thu, 14 Jul 2022 16:02:07 +0200 Message-Id: <20220714140215.444993-4-michael@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220714140215.444993-1-michael@amarulasolutions.com> References: <20220714140215.444993-1-michael@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: michael@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=dniUdoR4; 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:02:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2158 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 0F5E23F013 for ; Thu, 14 Jul 2022 16:02:32 +0200 (CEST) Received: by mail-wr1-f71.google.com with SMTP id l5-20020adfa385000000b0021db73f5818sf583387wrb.20 for ; Thu, 14 Jul 2022 07:02:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657807351; cv=pass; d=google.com; s=arc-20160816; b=c59McEmEHkIQEyBBXHNi6qZwNtdpZGLGRoqEfUV4dSc1OJ0Is7L6mhoeMCuFXf3vIR NA7H98DetpLsdMu7ifKqg+h2ZOsaQicwRQOjz5w4Zcqx5vaFwz/il61zhSqAvatn+Mw6 yTCjkEOIzpbyywy/UXPCV+/D7+JZVRmmLCn87vR2UXN7C2ASKXaG+7TY6ZT+pgBB5vn7 q1vP3zAG64TYrh1Pk5oC4Wlx9rWT4QjyafnJ3YdSjk3uGn5SlUoB5TeweP3zijuQFjHN cNsCEtNcS4FSEuhRahHDa0HEG+ZTQXqFi3+MKJfaSCCb+hnhFSodvLUiFmPC+dPlr3zA FdJw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=bWsYoxh4EGG5Y6a44K3Swhi9kgqogfWRi+rHQcZlZ34=; b=qo5pu3YzV7nuSOsPmsYXXYmjtC5Xpja8nsg8hnYcWDo+7mvq2UyRU0Ih+2iSnIWnMM PxW557taXrg0V1qamqCQ56JZ2Q0Oc3Uv38c8clsP6fdibzb+eHaeR+Oz6GArJ/XSHdRJ 9hbX0/bhQmdJh+F2x3JUGxNAu1GkzKqFWgVqKsjmLZF0VJJrrBfrnCD6yQ0GUtOtt8VS 1fmHZEDAtGE4THOaqF0Au/ECeXl08AFgd5K5vSIXSHxQBodFrfaWh6oV0lPsvY08KNsv ACsJQvZtdQINDGJ0RaeY0BzQ+Z0VRY8n84waxEzNw/ThGi1yQt46QrThKePlWIhHiujk iQkQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=l06w9BMf; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=bWsYoxh4EGG5Y6a44K3Swhi9kgqogfWRi+rHQcZlZ34=; b=M5gdDnayzLwO1PA2bqw448aWvlcUjo3V00lyq+KCDbbvo9YZD+W8VZ6fvhjZOXU/ZU o/5Lpj4v/J+OmvGvPvQ2NfVsjRSTTTfqpBtzE9yDbuW5uyKyCaJrJOY9mN3L/EC0+N+b fqhyg9cHzPVqCzsASIpA8Zu/ouyqorJzBhzME= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=bWsYoxh4EGG5Y6a44K3Swhi9kgqogfWRi+rHQcZlZ34=; b=7f5aamQNwr09sjFuWz4AKpRjjDDqz2sqjRx/6SzR5PEHSYgfXf6BTwiLAc6aNwdmjI lMEiZlmaTfzw7JVQuf/RMOaR7w9vOvy4kft37f4vUfkKi1U7iTInrlU3vfmzHzUWFMcf LSHzJsnpatOJEk62dPSWZ7fDnatft4SL3g3T+I6rZQ9EP+XaCRpj01CkGVur5jPEzrtJ ybEq+W/GBsL81v9Kr7PqmSjFwcu9CYk6wWhCwCY+hZvRwH5bSx3DKVzm6mzCCJPijWE8 eoTRLvYp64j/MGAcZI+GTS/k5zDQo0eTD/Xit76MtjkKyc0VPr/rpEpsbH/h9kYY0AFs Q8lw== X-Gm-Message-State: AJIora+D/ZXIeY0CUO3aETE7m6QfyEACkMvIMZutzUKim+gBIm6jN+OW 6qvbX6JBQJh/ncClfUPsw8OYSPGS X-Google-Smtp-Source: AGRyM1uzmrm0sDVcz0EHkuxzzoJr0unuq3A83PPRAkc6p6AlJdBT+bA8gLY/OU5xPkcesIU7UxaOWQ== X-Received: by 2002:a05:600c:507:b0:3a2:f6a2:7321 with SMTP id i7-20020a05600c050700b003a2f6a27321mr9270906wmc.136.1657807351847; Thu, 14 Jul 2022 07:02:31 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a5d:64af:0:b0:21d:bf45:f904 with SMTP id m15-20020a5d64af000000b0021dbf45f904ls110734wrp.3.gmail; Thu, 14 Jul 2022 07:02:30 -0700 (PDT) X-Received: by 2002:a5d:49c2:0:b0:21d:babe:e76e with SMTP id t2-20020a5d49c2000000b0021dbabee76emr8776731wrs.244.1657807350498; Thu, 14 Jul 2022 07:02:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657807350; cv=none; d=google.com; s=arc-20160816; b=oHL/wIDSwMbeoWYUW2qINtysygLEraIeJh/WEB0/c19TEfWqazurv1TvWqpUu1+Mld B62eX220vi+p14pyireQ2/UNlbLkSZrKvCu8f+AvpTgBJMxizmn0gFtUbF1qSEMbtG/4 MHMzWkeuaEmF8VF1J9O0W9HvovwGNH7gCHiw9L0ZHlwEXzNT/J0zfPd0uEEOYGjBWRb5 rI5Jm5fRIkaEZzvTtiA6oNHnG7fCHrMJjbiPny7NUM00uaYO3Aa8tvyrSoJCackozYcL g3hu/CHXfzK38PEi17/geOckkTE84cjPPhlGAhcrvHK/fiddFeA4BKnaANUOCwofP2nd /VPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=8r1tMsApi1aj9SR1CafRswHj8lBfItFykhvwhV0futo=; b=em5fLltZxePlcC9/RwqWvQeCDZVh4tEIsV45G8vcblBSn2RM4AY6s6U0EqWiPf0pOM 2hKfLG/kv3vIRytkpEPF+cxPgeUP51QnNRYOVKUGUxMh6TSfcBhcYV0AP64UwpDgI/3T 3JBeTyjgVN3492ITKAdbi1XTkSSZ70kJ1B4+frjS0uFrVYw3wrjySlvx3HPd4D+Ljp74 iWi3NKD9HAx2Zz+UjgubqYLqxbU7iGQn7/iMJSF/mZM8oUWag65GDpXDc62EpFyealfN 0axoT5xB76XZmUvizt5JFNirW72Gxxgs7RfOpNqq4/or9DJGBt9RfdAYJjGL6DrBgGKZ 8tcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=l06w9BMf; 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 k15-20020a05600c0b4f00b003a05105d3casor495281wmr.6.2022.07.14.07.02.30 for (Google Transport Security); Thu, 14 Jul 2022 07:02:30 -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:a7b:c8d3:0:b0:3a2:fe0d:ba2e with SMTP id f19-20020a7bc8d3000000b003a2fe0dba2emr7420221wml.115.1657807348318; Thu, 14 Jul 2022 07:02:28 -0700 (PDT) Received: from panicking.. ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id k11-20020a7bc40b000000b0039c5cecf206sm2029114wmi.4.2022.07.14.07.02.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 07:02:27 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai Subject: [PATCH 04/11] mtd: nand: Get rid of mtd variable in function calls Date: Thu, 14 Jul 2022 16:02:08 +0200 Message-Id: <20220714140215.444993-5-michael@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220714140215.444993-1-michael@amarulasolutions.com> References: <20220714140215.444993-1-michael@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: michael@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=l06w9BMf; 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:02:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2159 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 3FCEA3F013 for ; Thu, 14 Jul 2022 16:02:33 +0200 (CEST) Received: by mail-wr1-f70.google.com with SMTP id l17-20020adfc791000000b0021dc7dc268dsf269962wrg.0 for ; Thu, 14 Jul 2022 07:02:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657807352; cv=pass; d=google.com; s=arc-20160816; b=NBT6QqMRgx1iUlArboDymG00fMhfLWDWcF2wCbatIv3kHXkk/PPv5gZcqhCJ7sYMqs f9bE0D3tLvQk204BzX/2LiYM4PjoDbLwb1/kQlSTRwPKu08TRCtuTU/7jt/yNJjgYbnq ZavRqXqKi/UHfQ2ygv2JpaLn69y2hF9KolqZFpjasoJJqD1BDW5yuh2AvrBmJvtLe5Cc d4mv1XUjAVwGWXbJDN2iaghHu954TW6DvX2HlUQQFOTAdLlLd4R/l2nyFS2IpYXENJWi CF8OZCWDjT5TDwi2pl4fP3h++jyAgx3QUGQQFWur5KlI4auc99xFlpV1WS+oemCj4wo4 TmCA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=pjsaOc5d3VSwvcEV367KBzy/ZYpzrfF+OATXAPBNDNo=; b=RCuV9LJN23RLwvKvkihKDTVNBBx9dQwn7e+BjiVYf8Bd+eMFG6+6cAVcFguVu0430n oW6oUyN9g4Fu5PqVTRaDiAqO0lkbp0kqMBtEBDgDQqq4m07FeLPlmF8F4jrNWWm0VblA OZRiy7Ji7Nz1lMzlHcTupd3rEcy5o5krD3lBFitsqUMK3LNuss8MQ9TBWvr5RDNcg3oj Xhr5CoR+HNGKi0kI1X6cXU6+s5GOhBzjG/RFGB7M16n94mq1tx2dYU3sbY6blWio3m74 0KJfFCMTCzd1BA6AmQ/wcOoDhR8GTOt1fhzvhZ9EpBr6ScQWfDZkYzyjupVKCZ9gfCv7 5uCw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Xb5occ4N; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=pjsaOc5d3VSwvcEV367KBzy/ZYpzrfF+OATXAPBNDNo=; b=enMyDss37xgzwy5ZjZ2OfA8uBuVGycNvH9Dj0lJTunY6UdjCBGDPYipBk5lwNkPx+u 38UUrOS/Q2f6Qpew5YwTHXyE4KjnxsvSrByZpzCkjOm6OHQL5Dw/tost3PR+RUezp9yv z++CloORXBqopWhs4CUUoRAnsClac+kUBvJq4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=pjsaOc5d3VSwvcEV367KBzy/ZYpzrfF+OATXAPBNDNo=; b=tBa74fIsMU506lR8eCuYMNVQNrp9s8jG1t34w1frXxbi+UsdpTsUcBZKMxoIQQE4vf y9HsSbC3c8OJO2tjhn6t2QT1mYC+TAI0aFxVDt3zQFgHTm+EPQRjbY9TWKybxWlqYPPH LvKXTR2qh+4VtFj34JaKXQMY0hIZfBw4wWcelq2D9yTjXV6bO7M918e/UT1ES5ptaj1U eupux5Les6iQPsp8iFbaLGaWgF3coWLlE5vCnUzGKVge4WgKxBXMoaHqKCTFtfGUYQ9+ NvqxjNxAOt6dhVyBX2qDq3MWqIcg7KqaV3ffj7jOvV7Ir4T+YWHIUB8kTeiKeyPB1K6e UwHw== X-Gm-Message-State: AJIora93vain3PbDCC0mJfVV4cwXSO8pEZZKHPOCCdS6Qabc8o/BP7fj /qET8jWWc9uKu4qY1nyFDocL7pYh X-Google-Smtp-Source: AGRyM1vsYY3p1S8DDHnFlPoBP2H188APXd5XUcT035AhCiCyxbIocQDP7WxJzF/KNTLUREmlm27pJQ== X-Received: by 2002:adf:eed1:0:b0:21d:7052:278a with SMTP id a17-20020adfeed1000000b0021d7052278amr8741700wrp.170.1657807352594; Thu, 14 Jul 2022 07:02:32 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6000:1849:b0:21d:9b2c:2273 with SMTP id c9-20020a056000184900b0021d9b2c2273ls110006wri.1.gmail; Thu, 14 Jul 2022 07:02:31 -0700 (PDT) X-Received: by 2002:a05:6000:2aa:b0:21d:ac4f:587c with SMTP id l10-20020a05600002aa00b0021dac4f587cmr8598777wry.675.1657807351019; Thu, 14 Jul 2022 07:02:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657807351; cv=none; d=google.com; s=arc-20160816; b=eZKBa5dhfGRnlk7btY80AEZ0mdUSOuRMRu0rb7roooH5+WeD1eipUiwiStscchEo5E Ubc/+hSMV75yizKZiDOKf6RyBsxu0COksMs3nNb7smjoOJR4WoRzV/LD5phPAv4naUe3 AU7ypzUp8bRRLMV6oeF3RpCox/YNucaTG4l9ZxB+zeC2+jgjYTgu71TzBulBqAz9NuqG eW1KKr3iUJVUgDsM+ImFbVKZjWd6CQ8LRbvh5YnjOeo2QmBwahMsuhedcM0ySm6FCyHp 6bex1Huw3ivHgJroKu5ATPGdKR0+dljCciQ4muiox34MdWOsAi5/tvE7YMauw7tbKEWJ g1eQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=GUpIdmojh0UYmi+/gUfiA+lJOYYykzTcKwI0/ILa5BA=; b=hakoBPbmIFhFcayvm+niQePAj2KM9pBo8/JeXMLA9SJEUCkbf0sog3WfUYCjB1KAzO XQZFk+fLeA+JlNT4uIUe7Ls3MfL8mbwZD1mso08zUAlKoZrGJ7XT1J8BCZveWy/3s0e7 sEMerSyMr0yIOYGNkGZ5sYq1mbLwC2O3qy73yQUF1LZFfUrlTZxYz84O5aGW/kCK1c6c u10FQs81XtruHqJAgy23d6kAD6IRnDqHAY7dCdpoutazhuUw1Ruj8xaZWfc+dC4Sx51N ZM3qB/YR6CcncGsVPf9cSbS+qbYyOOqYV0wzKMhpaWwRT5GWH/IwXNAjHrc9LdL5mxC4 PmXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Xb5occ4N; 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 n126-20020a1ca484000000b003a2ddce8dbbsor471263wme.26.2022.07.14.07.02.30 for (Google Transport Security); Thu, 14 Jul 2022 07:02:31 -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:a1c7:0:b0:3a2:f171:8d68 with SMTP id k190-20020a1ca1c7000000b003a2f1718d68mr9455508wme.111.1657807350270; Thu, 14 Jul 2022 07:02:30 -0700 (PDT) Received: from panicking.. ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id k11-20020a7bc40b000000b0039c5cecf206sm2029114wmi.4.2022.07.14.07.02.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 07:02:29 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai Subject: [PATCH 05/11] mtd: nand: Export symbol nand_decode_ext_id Date: Thu, 14 Jul 2022 16:02:09 +0200 Message-Id: <20220714140215.444993-6-michael@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220714140215.444993-1-michael@amarulasolutions.com> References: <20220714140215.444993-1-michael@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: michael@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Xb5occ4N; 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:02:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2160 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 7CC6E3F013 for ; Thu, 14 Jul 2022 16:02:34 +0200 (CEST) Received: by mail-wr1-f69.google.com with SMTP id g9-20020adfa489000000b0021d6e786099sf576123wrb.7 for ; Thu, 14 Jul 2022 07:02:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657807354; cv=pass; d=google.com; s=arc-20160816; b=qGl8wUxsar/srOwV25Rv0TauqebzgIGa4c5fTSar0bspOkN5vcf6ob+E6kETK07fBw 7zFM6Ig3sWPz+t29+N//UBl7Urw0zQ1ir5x4MSBws34Q5idv6t5chalj7akL8n/uRVvD ikttk5P/+Qs+75j8gWxVxsaEsARAQ9m8t9PdOr1hc1yK7Q6DHZDS3mzU2fEVz7KgJBTg 5Bu2clluH8FPD/buHdt+UjPiA+WtbbWBVmEdETHS/mvqqcpUuIZ9C7JMPEq2JXRRTH5C uEiuR/d6OjUz0BDriOpF3ANKxsW0kdkFrFVEzRon2IFyTL8L9wQDQHF+iX3vfkmnOJVW 7Plw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=Z4Za9miDuNc8iaqcB/I0Z0pJsjLu4rXSfpAjBCnI4Ec=; b=N2rUhgut4yqucGgMCfWiM0x4LnHXYXKhnNhUYRltRKfXv36ouW08qdP8I+tWp+gBRW sIEYT5TudcLQBoNYVVpiiQcTGX+C59g3PB8pmkWuR1rQDTZm0eXFUHaYJnTW6r4mQD/o m82k8npkv+bySl1pmCl7o+MB+uYrpV+lDzdcjK+ZwS+a/qGDKYCGpxodiwNSxWNeAQB8 96VC2x7kACcM+qBUxpUtzmKtTKAMUfzMW2UsahUnhe3iSz56BW3Dk49gXGFx4IRrVLyp N1CAU3TkWyCMyKs2TXiAeNwaSRM6lJ3iFKw/0hRSomkwHCkWTKMEnaFSV6G2UOuisXKk GH0w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=kDFL7eAT; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=Z4Za9miDuNc8iaqcB/I0Z0pJsjLu4rXSfpAjBCnI4Ec=; b=c8yA4fXCuRJQjG4TdESRt3hOpyVYFoD3mT2lpvOH/E+x450oWJnU/9ER3DQ8pLLCp5 RZuP6xISdhykmxsnCrOpDCrsa5fLYBdPnrULqhuBZNIJbbpeS3IMfFRiS8eyPqSwzD78 8Jra+4OUiip+6ehr2ErMC4jbp+SHte9yFlJAs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=Z4Za9miDuNc8iaqcB/I0Z0pJsjLu4rXSfpAjBCnI4Ec=; b=jeyTGuH114VYmyz6+b9xK/6sn0qoehRURg8lHG3Am2+10CEGHjyue/3vKVWQmabJpU O7jhVec7IJ07Lc0hlyPumHYqanrvwPlAxjwDqLr4Aqb52Rm75tOLHWg71bx3tEwGWM/c 0oQ1LWpdWDP8XvwMY7Q8IjmLvSqTgHnGLJjd/5u3s6u6aQAq4gIMl53zh6cx/NOoRUHQ 8E/teQeLaarsIpZAEGs0tM6oLiOFT7u2Itzk7vCnN7IZfkVwEwaN9WB0mXR18X4IoBPn dCaUkq1l1KS3kd1grjoubQTEb0aQGi4HBNKmSi8SKe8UIQysCTRP5lDARUZZ1ewa0t/c X+sQ== X-Gm-Message-State: AJIora/555aczK0bZfzR9YxE+DCPW9sf54Qd7fUzdDQSxO6lIK25X/tY fEZTRC3syVg8zuydsqYFZowT2nqw X-Google-Smtp-Source: AGRyM1sZg+EKVwsN1vvz/sjvVJC6LK0e571SAyV0yJBYsx5bJtBMeekZi8S2tKRhfOfaL8jx9cU2wQ== X-Received: by 2002:a1c:7407:0:b0:3a3:1d8:5c12 with SMTP id p7-20020a1c7407000000b003a301d85c12mr3208350wmc.191.1657807354296; Thu, 14 Jul 2022 07:02:34 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a5d:64af:0:b0:21d:bf45:f904 with SMTP id m15-20020a5d64af000000b0021dbf45f904ls110927wrp.3.gmail; Thu, 14 Jul 2022 07:02:33 -0700 (PDT) X-Received: by 2002:a5d:4903:0:b0:21d:6d8f:a321 with SMTP id x3-20020a5d4903000000b0021d6d8fa321mr8312026wrq.59.1657807353046; Thu, 14 Jul 2022 07:02:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657807353; cv=none; d=google.com; s=arc-20160816; b=UeDQh1hAJs+CRzDnwaKd5KPyHHMWU8+yq9rdF9njIzum0d6mflZ4s44fRAaguJfshf fH6YjPZFYswMj82DHkUDJHre6ovwVSZbTY03U+N0kLmBEENy4GVdc1ydDmdJbZKtxKlU q2TFsjdaDad2a3O/LgiNgv2KTgS0qN3JCOqORIPCyZhFQ4h6+U9B2lGVzMDPqyNlhO/L Xm7Ctokah6k0xDq44h4oBlH03A5Nh5UzLU4ubWVqldodkkYtbcIgBWdDmPU61paQE3IS 3ha5KOo4CheOy7I1yGXJTj+VstOjlzpnIA2RDcbDZPPl84GOFOpYk/fQciR6ZtJGqH5z c4hA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=+4va1oQEAtp8P+P8+M1DvWl85yw3nFaxtze8wXVuAkY=; b=lTdewfBW8O3WZrpyBs9+jO3yKujegHhNx1ipPej3yQgaqu4rECjydF9y1B+4SUgKOA 0PkGhc+Bvwrh8vstx2PX5UWFxrwuYmcFxv7YesFh8/UnwHEimv0yGdnrQS7v0Gym0UCD fP5WHRqzzwfdisqv4No+MBzg9w1y7BO1FUFln6Ni7OEC5M66xtRP6y01PVc1Lk7HkLXm MaWJ/2MY6Y83x9Z8BKH/V8X2USy1H3aAzd7FyFHZ1Re1ZoQseLuB32VtH3f6eLS2iipH OeJKtE4VZAyYk3ZUj7s7Eke0OsUqG9jsWRiMpk+4gIhoXHvvKXyFGphVZ31E74lbMR+w F9MA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=kDFL7eAT; 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 y10-20020a05600015ca00b0021d644c7981sor782959wry.27.2022.07.14.07.02.33 for (Google Transport Security); Thu, 14 Jul 2022 07:02:33 -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:4304:0:b0:21b:9b2c:be34 with SMTP id h4-20020a5d4304000000b0021b9b2cbe34mr8778371wrq.577.1657807352248; Thu, 14 Jul 2022 07:02:32 -0700 (PDT) Received: from panicking.. ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id k11-20020a7bc40b000000b0039c5cecf206sm2029114wmi.4.2022.07.14.07.02.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 07:02:31 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai Subject: [PATCH 06/11] mtd: nand: Move Samsung specific init/detection logic in nand_samsung.c Date: Thu, 14 Jul 2022 16:02:10 +0200 Message-Id: <20220714140215.444993-7-michael@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220714140215.444993-1-michael@amarulasolutions.com> References: <20220714140215.444993-1-michael@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: michael@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=kDFL7eAT; 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:02:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2161 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 EFFEB3F013 for ; Thu, 14 Jul 2022 16:02:36 +0200 (CEST) Received: by mail-wm1-f69.google.com with SMTP id c126-20020a1c3584000000b003a02fa133cesf704033wma.2 for ; Thu, 14 Jul 2022 07:02:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657807356; cv=pass; d=google.com; s=arc-20160816; b=lvRS8oUlqtsUHItOHCHqNgos0ZYeeHnakSyUkx4i2ei3+aF6Rn+PYAIM1Ett302XEY yyBE3ng9RrU8w1kmvOlZihaLCt1HixwuLO+QYNBXHtaGIZq3Fi6pZd6KSqBdDCyLubSf AvJsZdkMixszRBN97pWNuvkHSLJppbXi3/Toj6EjFLHPLVF6sy4n049NZvfGDEfNzvn5 eQ11V2uN3kX6QZwY9+t3wTqzNLNSPvX6EoFL4GxI1W6167esncaCXHgvlyoIQpSWxtgU kO/ddwZit26Hr862vetzThGTccKaousMG2xmHKvhcDkhNxqZDpSiI1h3ACy05i+z/qJv byCg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=EkkmQpa/gOGWpfcQVthVXQX7eF8aki6qBJPMY4FnCyM=; b=Au5u4lGk9s5k0A5DQp5otQyVLd8wVS+CXSjiKgOLyy5Z3F10Ox+TTLzQrVQFiKZivM E8s3jJdocSR3xiyiW64gEc8f3I+iMKSNra3LxgZlJZSm8jaWaa/lPIwkLTdzUYtzbOOl 3KuJIhDgdPIGlR8gtRm84redDO63SKtRQ5kggJmHUoZbMSsQGIzvyzFXLzgK+GDz13P2 6LwFb/K7EAtY2OeIYnWfQznxkvvJWs1RjJea1EfUHb2icL8iC4WYKvXvXIPuJ4bG55OK 69wpa09vziaJ9NNLTd4YM5Mdg4E+20jfGG086eOAqtUlDiB8yg1Aw7sVuvYvyIAYHXrN qMLg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ltKrmqfT; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=EkkmQpa/gOGWpfcQVthVXQX7eF8aki6qBJPMY4FnCyM=; b=Ot5tslN+y1KdvCBDVmTe8OSBHKfqI3FvH5RDWC7mMsXqncIqXWtNZZ6EnjsY8r51OD cF1cc4xlHoZ+AEyxyF6KAy3JFDS4nuicBzp5+dIp4Soc5CrODnGXyY+SPDkXtfoLdpzT MaWzvIJ5LP9TicSWsiARHsvIVW4yrzQzsDz1E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=EkkmQpa/gOGWpfcQVthVXQX7eF8aki6qBJPMY4FnCyM=; b=8DAViXHvDKY2UJxEgiXKNqyuGnp56tU+Oh6TwrtEfLwMMCLiXjGwWJsAm4d3wElDZg vi2/yuFv5QlqDdCR0fIAqIUGo47heHJ0Ic0FqlNJS2aNVpncb4Fx5Xh27DLsKgz8ThLp g1IxvhK7ttI9Ukp7HxpVXE3D6zI+UBmP0nngzjAr0VQAptE+DR4nEy4M/0AJdAWUjscC 5DK+jTsrR/It3XbtVNl0GXg376DMSenbzAOYY3Z5nCZaEdhbb5PRJP5rtsQ3RcgceKfm Y/IjYgIHbm+cnMK/OtthczbFWTwlnalqgpmRHYEtUJ/Elt3zq/+y6cXobFb4Yfuy+ZvE V2JA== X-Gm-Message-State: AJIora/1DaQ3YAHfbKAGpOH7cr4fzVdk7q+Dbi+nWHKBwZCShu64Hj1n S+yRTA1+QnV+w92Uwd9Fbc95H/B/ X-Google-Smtp-Source: AGRyM1tTZhz3MWDO0w4T+Pq2UbziCerhF900Urr/WBc/ScAe2Y2GMGN6woFKrn/q8dcqGTBJstzvHg== X-Received: by 2002:a5d:634d:0:b0:21d:6789:3e4d with SMTP id b13-20020a5d634d000000b0021d67893e4dmr9041414wrw.321.1657807356757; Thu, 14 Jul 2022 07:02:36 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a5d:588d:0:b0:21d:339f:dc1 with SMTP id n13-20020a5d588d000000b0021d339f0dc1ls109119wrf.0.gmail; Thu, 14 Jul 2022 07:02:35 -0700 (PDT) X-Received: by 2002:a05:6000:2ab:b0:21d:b410:5773 with SMTP id l11-20020a05600002ab00b0021db4105773mr8333211wry.381.1657807355566; Thu, 14 Jul 2022 07:02:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657807355; cv=none; d=google.com; s=arc-20160816; b=MecbhosUxDdkmRhIaRhPODtPovSIfoqwkoyuqTAQb/pdOZdbrjZMWL0AVZEbNWSHCh g3LT6V5IbHPpZuqrCLmaOOkBMNaZ+PUFNmlZ/llr5TtRG20nFVecgIq47HrEw9c3NkZ7 pAZB5lhefczYLs1FTmiM47uVZK8nwh1TiPRnQY0vdMRc8tVT9vwdAr4FmYnr8olJJlUT hSFSYDBH3dwW2+ahxAJ8MgAWtSt0R/t3oC+QA2hGlU1fgCyhAQIfAlSCELiU9Y3bPOog 37XShXRe81ZBACqde0Z4oH2zfpDeqF5Voee/YBKCttnv+IPSEfuUO11cYmJXQMJAP7WF 3nww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=N+rtp8PN0e0YtZMlSR1nEf03YbvA1gjyB7LEkd9PWAo=; b=dGdH1XfOKWl3cxqaZAKonsNcss2qVF6gKszmaOGxH69WWDJkj6jaiZ5bR8XVQFd2px Ak7KsEB6PiEFJODf5wESYImnZoH4W3H1I3IP1ufFMBO3oDtTY6bYtZRlpcNGXKUEKCLF SRvcGYOQ1JzLEvjnSuFobZF78++hjPyqw4FPQuamXJ7Td/qheLkpcQCKww6LYSgMoSFi CLVRzOzME2S/HGJBvgSf3pgXA8NG5XHii2GoeCAek3psrzqhA9l70Y0TtDAfXA+gcQZt A9U3jL8Uej9EW7/rHRookzY59Dbicr9QQrhFGZe4eeHm4YvKPqUk/vkDid6b9sAg21iD I1Wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ltKrmqfT; 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-20020adfa102000000b0021d765472b4sor832878wro.66.2022.07.14.07.02.35 for (Google Transport Security); Thu, 14 Jul 2022 07:02:35 -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:88:b0:21d:691c:38d5 with SMTP id m8-20020a056000008800b0021d691c38d5mr8650086wrx.450.1657807354645; Thu, 14 Jul 2022 07:02:34 -0700 (PDT) Received: from panicking.. ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id k11-20020a7bc40b000000b0039c5cecf206sm2029114wmi.4.2022.07.14.07.02.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 07:02:34 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai Subject: [PATCH 07/11] mtd: nand: Move Hynix specific init/detection logic in nand_hynix.c Date: Thu, 14 Jul 2022 16:02:11 +0200 Message-Id: <20220714140215.444993-8-michael@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220714140215.444993-1-michael@amarulasolutions.com> References: <20220714140215.444993-1-michael@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: michael@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ltKrmqfT; 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:02:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2162 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 05AEB3F013 for ; Thu, 14 Jul 2022 16:02:39 +0200 (CEST) Received: by mail-wm1-f72.google.com with SMTP id h65-20020a1c2144000000b003a2cf5b5aabsf2692218wmh.8 for ; Thu, 14 Jul 2022 07:02:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657807358; cv=pass; d=google.com; s=arc-20160816; b=seBsAqM3Bvt2xAH3lBT7tJd5pjZG55CMKwU/Fslub17QfmYsI76f77QIJ39GiR6LKs Um8yIOLeSKs6J3atP2BZw7b7i2+YVfnhF4vEynBKWL3j+GVVGjXQxdmD4kz/Q/lEwD7M X+pGE5D6hnYjh65eJXKkeKwytesV1jWeLHSTZyDJDFxzCNnpRW3Tx5FbCFent2SRv144 d/36ouo8QNYKhTl1D12xh3notY4+Ffr4oRn36gabyRuV0ZKZR8P6/RZhkx8jjiZtgP3h pK/cadyIhPpvjcLGb8TlXHweqgAWD7aONZ7UdNbMWJPdF+lrJUZfig80L25nvX6oiL7g DoqQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=vmVx0z3Ubo58SrdMiS1PVaibssXAk6ZsNS2GtJ/YPc4=; b=w8UOLF2TD/sTIlB91Ns2/304iVbrAhwaHkLmY0Lx/Yfh87fRhV9ClS8ApVk98rE4cf 9g3QsEYia+ScoXWgm5yaI2WZrQeLi2xbG7hGq6XIqlIKH/YljLfW16OykMC78pte7+Pb 8H7uE6FJF4prXD6pS44azxlw2Bl4e3hpxkopN59zAAxi815DIFvWPOKwgCe/e4Qva64r mwL+7MKBCDYElRHG+oh4fGL3dY3YTWX9Imxo9ZVfsW4wP5/SBm8t/EhWviijCAMDJYwe 2uJBDkKd0GV1V9fGKX4fVGBuYpaXP7zhCLoP7+dI7y1F1xcfgIKZqx4AQZ6LrnlSVPxT blaQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=efxgs6QV; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=vmVx0z3Ubo58SrdMiS1PVaibssXAk6ZsNS2GtJ/YPc4=; b=o6tjtzEUVvqJVT1D/4RDsYXrsHEpKwoBfzZ1l6JI4TAWN0YCcUiqJQKl0lGKdE1F0Y g9IMFLh+d1I7+Axf5BhckTxwGkMQcLH3G7glM4/Q6XYYCJSWmcLDajqpJurffN36X6ng mnH/4kVkHmE5i70PuoDAIMvpbxpK/twJxjIJs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=vmVx0z3Ubo58SrdMiS1PVaibssXAk6ZsNS2GtJ/YPc4=; b=gv2uCQZxiMoHeq5zS4V121QBnEcy83u8TeVjTibwYdNcQrNo+5+AszcOvNbmwm4kiF O3zcWQAKwqQrgbgCR2EsbbuyFQ5zIsFzVvK6Y3Xz+MXzv3lJ01/MkbgfcLulI9Jxfhwo +GfbNU+ZawZenKYYnWAgAHVLUgi/o0O9orAbeepyZ4wMOh181123tCusywdKRGB6/Gul ACcs/wy2cMjsmA/TUpB7Jn5gzHx9/qRhu31TOuqGNv+Ix+PnsB5wysP0WUzOrINpvqY1 P4V6kWhXUBss5//Rc5u0wv7tSt1gz+ZHSIkw+0+SkL9P/HzcHWE8TfqktMo6zcLQvfMe EwVw== X-Gm-Message-State: AJIora/pBiDjboNueZYvHVn+GjaNJf3k5Za6ddkGcpQnPeiS5tL/haOH to5tyDPUjs/x3UtGnwZBWRxGlYqP X-Google-Smtp-Source: AGRyM1uFen7uyM4pr3ySQVNanA9DUvTqzfCb3CZVIkpop0zVYjAdO2G0fzfEWdP4vTFCbC3/AzhRCg== X-Received: by 2002:a5d:468a:0:b0:21d:6dc8:9e60 with SMTP id u10-20020a5d468a000000b0021d6dc89e60mr8840899wrq.595.1657807358788; Thu, 14 Jul 2022 07:02:38 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a5d:588d:0:b0:21d:339f:dc1 with SMTP id n13-20020a5d588d000000b0021d339f0dc1ls109309wrf.0.gmail; Thu, 14 Jul 2022 07:02:37 -0700 (PDT) X-Received: by 2002:a05:6000:1d1:b0:21d:6673:9894 with SMTP id t17-20020a05600001d100b0021d66739894mr8388279wrx.640.1657807357494; Thu, 14 Jul 2022 07:02:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657807357; cv=none; d=google.com; s=arc-20160816; b=PjhSnkcq7GtefXREUMuyr0ryd5b/8WhuNQV+7PQLvhC9zgI86YjsEUxXPfE/YjeErO lxICNAux49R5wghhzBnNseLy+EVrdhgMdeATEjBvPSq6OdFogf/UrDUdc6QbE2WKR8mP TJMo4O18Bx01BwFI29lq9uf0GkVKRJavsOqFEZuhnfEWjBC8S6UA+u/FF8jD6YJkivuU lTZ+Jth8AkPOGXtN6JuLYKNIQvyIY8uJgA18l02gbgzSHGi6fp18KRBKPio7r6WZUF2g QLtyCrQoYa7//w7RWKX+q0Nt+45rHUIIbyoN8Gjn57e1yIQrtUThgl0C34KYpVSYjaOz wKDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=bUAelgxhRmK6KYlzb4SR7SBVjPUr+bul0VwHLDW2c3U=; b=lycB4B6EbSeAYNC9Qvz8UnW2SCz7iFtO/TmPFk02f7J/7romGQDoELjBpWLK3xzLir uW0vvJnJP+uQza//rYaf/oj8HyyHUG75/ZI7S4ftjsgzsEAlNnNAcyfrS405X6bS+GE9 LMTlPwR6Dfl3simfRNIJAfF2FCYEWXRxjBakALhyngqBf019CL32D0EEmKNM0W3M3P+j X/HMunS7Ljj4DARIuPhAhIBNPzTPcHlPkXgLoylUdbMusLO3WOMcuVW4ZE6E5dL/2vtB utohJgF73Q0rdRSzsHad3lkjmKJqxhcXYgfAlgzWOH6ylKDvFI4PSIdiJLGBbAZQOP69 KK1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=efxgs6QV; 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 o3-20020a05600c060300b0039c348c0fa5sor480532wmm.22.2022.07.14.07.02.37 for (Google Transport Security); Thu, 14 Jul 2022 07:02:37 -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:a7b:cd84:0:b0:3a2:ddbe:220a with SMTP id y4-20020a7bcd84000000b003a2ddbe220amr9274664wmj.128.1657807356646; Thu, 14 Jul 2022 07:02:36 -0700 (PDT) Received: from panicking.. ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id k11-20020a7bc40b000000b0039c5cecf206sm2029114wmi.4.2022.07.14.07.02.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 07:02:35 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai Subject: [PATCH 08/11] mtd: nand: Move Toshiba specific init/detection logic in nand_toshiba.c Date: Thu, 14 Jul 2022 16:02:12 +0200 Message-Id: <20220714140215.444993-9-michael@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220714140215.444993-1-michael@amarulasolutions.com> References: <20220714140215.444993-1-michael@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: michael@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=efxgs6QV; 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:02:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2163 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 E159D3F013 for ; Thu, 14 Jul 2022 16:02:41 +0200 (CEST) Received: by mail-wr1-f71.google.com with SMTP id k26-20020adfb35a000000b0021d6c3b9363sf577588wrd.1 for ; Thu, 14 Jul 2022 07:02:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657807361; cv=pass; d=google.com; s=arc-20160816; b=DO9nPgLOPu/kFcO8G3LMiiybvjh7V9mMZcXNgQoax7lrzjIE/ehxymIGY3hdbQ53b5 mVDqiHYcq5DZy5xs7U3OGYqCN6sviDdDhiDH3X2VrEXI4UA79jitqi09N3U/w2ZdO0ea f3cRodeFT5elwh48wqVVBOR3f3M69NmbRQQjb6gSWtq+YUR3Iiq9eFSvzRAul4HFQnMD OvNr0qbwo2M4lD9iONOhkSYkXFi37NX+J2dfckFLHG/rLVe/XjttSWeUYmcB24fEdfmM Xjt+oHnrY2yO7vRjNz2tRRoCl49RHivtZAuSQPY7gR1wgFJUJgBNs0jxakMVRUnagBvJ SEeQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=+jKhKJy2k3mldzHkeN3w5AI0zcNFlIr2NWHRBikgln8=; b=eeeNPVd6inuFrxdjtOr9EZXfVNQKpWP+ZI9d5asEaiYXHMoxx9mHASyR7mzJ183P61 EBzAB1g7puA5rggsAaKSB2L3XUsvT3RF4/TgvmPYb64dsS042Zx/1NuedF7dXg1MeKuZ 7g5PelvW4pqwPrSCRODjJizXWWR1RiVxf2RKP7eDvYnQ4INT+Q9h/hCZ3PmqiZDdkchh 3u1VPma439UJtu5cqdkwGxIdI0RDompWO1nve+70BVp5Be9NySfGA8KT6HHHUgqvgdbC 3w7J9qDf6u1VXjQHyAp3OzHbMD218eJ4Z07NTjXV0eh8CDXMU13IURA+qE7g5ueLMHQf Pj1A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=cqpZMy+D; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=+jKhKJy2k3mldzHkeN3w5AI0zcNFlIr2NWHRBikgln8=; b=E6/2v2WehPPgC2rv0yraMEOLUYWPqxqSL0QUdrWUIezAB2U30v7JqnyRZ2Y1BJMuWh hGYlUoFU0RuW65WzPKRrKXGm6ep0TV4bwmpsee8IbOtwcmAxD2AbwGcjcmoknqsw9UJ4 0kCakT3tfCEpP/VKKZgvXyxachC7fh2SMHOaw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=+jKhKJy2k3mldzHkeN3w5AI0zcNFlIr2NWHRBikgln8=; b=XAKPYUXCSU7dxdKQVHA9ihXpY4JbTrf4xt6ukxoOsr/D5hNqyOc6ZRwTbTdbwvrd+o iLaTV6Fh5lomEjydFliLTNiNH+dd7cT75810NarlDUoSu5Q6T/xEMhOsQtXLW/Tuib5P a4l39s90BWLCwp4QIbUdwUcS59GoPUtpAp6OJBDE+m4Pn5cjfvNDAY9wmK4PFiV6wJrS 1mmPX6QngdU6NH679ENAmW9NNtHA1bsiu9PSFlJng8vrXBLYUiIhDe17jl1I/sCprCMk HH31puwhR3mDOxbeG5g86tfYUqQUzRLOVIHBk2nKeW8CLEtIFBYXsRQA3UqDNIHgSli3 IYng== X-Gm-Message-State: AJIora+w+rPvGlj5OGMBZVPOUYmoz8DmZugaA9aSofeTqwGykRUrUv5/ GQz5F2NpjP/tJEZfHxky586n6azF X-Google-Smtp-Source: AGRyM1tp2LU7X9ejeUidRpjZlhtQmcLumYeTGe0cNCYsjBgUbqmlAxPPwkGmSyD2IdZRNxQOKL/HaQ== X-Received: by 2002:a05:600c:3845:b0:3a2:c04d:5ff9 with SMTP id s5-20020a05600c384500b003a2c04d5ff9mr15629755wmr.74.1657807361644; Thu, 14 Jul 2022 07:02:41 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a5d:64af:0:b0:21d:bf45:f904 with SMTP id m15-20020a5d64af000000b0021dbf45f904ls111714wrp.3.gmail; Thu, 14 Jul 2022 07:02:40 -0700 (PDT) X-Received: by 2002:a5d:6f11:0:b0:21d:7f60:e5a3 with SMTP id ay17-20020a5d6f11000000b0021d7f60e5a3mr8479568wrb.8.1657807360382; Thu, 14 Jul 2022 07:02:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657807360; cv=none; d=google.com; s=arc-20160816; b=Q/b6DTQ/2eZD0hN7BXesiBnMRl1eRaUSVPAWWN32s+zDzYhZiqYL/Kl/qNUDN7uRE8 g55MNUbncV/z11pFI4G5xLz7tRYX1w+k7mLw9dX37rPCod6lp5/yGgLH5KiPY5n48bgt XLXQ7BB+dggLnO4ojNQG8v5itNsXluHEyIMBRJZ9yf7KPnFAeoEh6Nkbmr/5axgSdAcv UTkQYXdD/1HP8o94oEZFueNsnF9BkngGqYf1Nnw6UOjVzWu4u2EfFNKcAtK031+H6QcH oIEHhUQrG9FcJnVvtzl3IM3b/ep7lB2c3EwYEjbG3Fa7dXdRIkqs3D4HzhNfm+DU+hc2 cWOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=KoBfOtZSuWjXMH5ooKp+4pUgGAdKWVS7+4lORZDN2pg=; b=PMmw/UGEbz0XkEnCV3yjyYbfuUo5O9r5IUYsLGT9xdWXYh9Qh6149nzWonSMYlOQ+d Ewz4EPPv26VlWFzfyqny47AcY8MXCHhyqaRFvhJi5K+fR3zyUQj3kEqpnHsgRp0RIXzE o6Csujidnd2Fijkw3zZeSXYIxP80xCJq5LCjhrR1cjeforb7sgsDeapS4YWZ9aCRULE+ 93wDkNKMYaqXUtBFPDRa+k/2pcX2gGiQ+KzQkTmjsPZIZ7JZsSky9s15SAOx2nSbdiTi 0TXWOTJMAHmwBKF2KypdKM9ingKrHXaxxdgx5hZV/fNkOE/pr9cNs6pJJfZzSEZ5UMYy 6tJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=cqpZMy+D; 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 m18-20020adfc592000000b0021bbf881c9fsor812138wrg.30.2022.07.14.07.02.40 for (Google Transport Security); Thu, 14 Jul 2022 07:02:40 -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:474f:0:b0:21d:9a9b:a1fb with SMTP id o15-20020a5d474f000000b0021d9a9ba1fbmr8783146wrs.115.1657807359651; Thu, 14 Jul 2022 07:02:39 -0700 (PDT) Received: from panicking.. ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id k11-20020a7bc40b000000b0039c5cecf206sm2029114wmi.4.2022.07.14.07.02.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 07:02:39 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai Subject: [PATCH 09/11] mtd: nand: Move Micron specific init logic in nand_micron.c Date: Thu, 14 Jul 2022 16:02:13 +0200 Message-Id: <20220714140215.444993-10-michael@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220714140215.444993-1-michael@amarulasolutions.com> References: <20220714140215.444993-1-michael@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: michael@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=cqpZMy+D; 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:02:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2164 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 90E7F3F013 for ; Thu, 14 Jul 2022 16:02:44 +0200 (CEST) Received: by mail-wr1-f70.google.com with SMTP id v23-20020adfa1d7000000b0021d620f5ef3sf579824wrv.16 for ; Thu, 14 Jul 2022 07:02:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657807364; cv=pass; d=google.com; s=arc-20160816; b=h1dkwHxRgDbIwtfEI0gz70+l9PC8lkdhgKmh9bxG8tOqY44xoXuPf5rL2P1CsvpPdZ Jk8mK74irehhk0fUU0XzX6TShA3zLvPQnP6zOjjneGQ0Rgw9TT1pOPP2Em8eMvS+7wmb pTjGG5He3jqE98axbNSWEC2wV2zQ5rEWsMpyW2f+LleMwgasOx+TVkzGfld70pVfYMw5 xRiFTpSb4U0pisMd0heQAIoqNScdy//9Tjjujt2W6ukkYNZKnaaPQbrT0j2ViUzubno/ r9MftZhwLjmpbM40poyyBvUn/FRfW6GzfElgA5YQDc47oZ76dBnki1MmtYrgURS7PO15 B5gg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=aTsW0CwIALv70v5/D0Y2fIhQt8rFfUEfGVmcgty5HDg=; b=f6QIBFVjGIV4+0z+DsmLqSCw+5WSosQ+8CuMbAECk2f8oLpiFwB7yE7G0vh8haeW3w /zIBJqy9k0xF7E5oir1yrfHykRjJM4/G86DDYCo9UuqNfCWmHElZHBobg7IdDE8M9AwX BdwnfO0HZ7TToA7HhCaoFDN5zLLUnSzAstKhRHqCgp8YPK8m6pF41BZV/0xLXPYw5Qcf bpuC6NAOcIFSENRC1CR47Q1ahU2EEvqbcKxqrezoXf5eDY46Px30GzC+Fi/zsFIeIyGe F7Xt7bJfVSQg9mh+4IgeNON0U78mbE8d+zmonJvut2DAXLPlOUdgcn6M8NAb+J4XDHWm 1+RQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=RB9h6GGo; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=aTsW0CwIALv70v5/D0Y2fIhQt8rFfUEfGVmcgty5HDg=; b=FHVv7gUMlfAmgl156805XCG8DOqZ21NpR/4y8CZ3noY9F3uuYffNywF8HDBY9kdqKF +20CgznhOnumHIopy6kqVu+Tcb17aIz04iQWfEPwC9aNqxlwOOlVyvfjOi894QcfzH7p tP9Q2CYcl/z22M4/9JK7Nwj3wl5canDZsKCxg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=aTsW0CwIALv70v5/D0Y2fIhQt8rFfUEfGVmcgty5HDg=; b=0rEJ5J2MlPPj66nMzk3AO+ZHjtM8HAoKkKw9sjuKA/TYxlpvj432fMVbPgrJeqWUyG N1Le2J8GtlE80OAIn+3bAf+6Ym8Ce2ENmusAskvGr8sngKmX4kQpck1hDswLnyec4liC eqcC0TH6TNZpag4EngDolxeMAKlChh8UDSI/4X9YUDUJ5PPu24BZjXy2HAtPRIt+yrKu zORAdK3EGXaL4twEemCbN6TlsUuwj8b+ju7Ti9y4JrqWsem35eFycmrhADAAlh23Ugw5 bduNGmiPLL7dRTu1uMAKwXPWaFqMPZWnKuQaA1vVyemIrR00Yv7UeeqkENxayfywSyEo 9RoA== X-Gm-Message-State: AJIora9IEb2C/YlE8N3n5LkJBWJjlOh4RtGspLJ1krjpmp5ibGt4R5Da t9Uhwlv4ZRz1FkmQvU7byAdwxZda X-Google-Smtp-Source: AGRyM1sNr7MU/KjOxdN4dMxZxGAzNIQAvfip0vVeppTkYWkQb4+Numiezc1T5OsWQToj0h3OauvHxQ== X-Received: by 2002:a05:6000:1883:b0:205:c0cb:33c6 with SMTP id a3-20020a056000188300b00205c0cb33c6mr8675963wri.39.1657807364359; Thu, 14 Jul 2022 07:02:44 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:600c:1da7:b0:3a0:3b20:d119 with SMTP id p39-20020a05600c1da700b003a03b20d119ls21010274wms.1.canary-gmail; Thu, 14 Jul 2022 07:02:42 -0700 (PDT) X-Received: by 2002:a1c:4c0c:0:b0:3a2:ea68:cae7 with SMTP id z12-20020a1c4c0c000000b003a2ea68cae7mr9100264wmf.91.1657807362664; Thu, 14 Jul 2022 07:02:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657807362; cv=none; d=google.com; s=arc-20160816; b=bk7++9Tdk8X7YjYVwmf5hufXjxDh266cGABlzMLmDAwwr2t1XRceZt3JI0J68xYRnG IHJTsI9S7pUB2f/oSY8+HR9Ml04kE3krCxZ6wAb6N1mmu5b8XdgIF9UJPYx3GMXrbh8c qKnZ1vk0SqlFyykhUVMhBjUsI5XkGzToF7MlFaNs7VymGHUVVhM6so9P/xrO4ZBDS4eO 91HIgjKyGgk7NhwDYLkrshT6SeFMuj6sqwn1TiZNTnnULfx4rj1B1LFFYqa9YBMfePXP EmtIcI+UGl1Yxwi7O/u592oIjuYY+ZiYRKKCfztLbJu/Gj7S6b20Jbz1H/5ETi4U/J9c ggMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=5iCwJ3uyZDix/RxLRXQbAC9kUK2qutEG/TqbefHAYE4=; b=YrSQqqZpBPFkIRpreJa+uK/xtArcoL3uIkPZlMBE6QrC/MbLm5JCQ6YwthJOqegPOe hdOvzNDv6+AeTFGlEpNT4Wi7NVzh00kTpFz9baVhG0UZGHBLw6X/Yg//tjNBkjW9eTuq 6XRiB/AVKEJGIYezGr9BCafSLJKsOEVKRO/71EBPShLBwk5wG/LkGlW/TMRUKnAsr3IW jlpACVQeq5FQ7sdUlMBLS7msNyrwhnKiHCYdngmjiWvU+KDv3U4N1Erzo50KR7zoXZUw s6Lw98RLzqVjAyaoQTf0mHvmQ67q9WCHd3wMzO/0tLEAArxoSinRs8D93+LvyjkMgYRB QnCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=RB9h6GGo; 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 i27-20020adfa51b000000b0021db6cb4fa1sor893567wrb.42.2022.07.14.07.02.42 for (Google Transport Security); Thu, 14 Jul 2022 07:02:42 -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:f04e:0:b0:21d:6efc:8f9f with SMTP id t14-20020adff04e000000b0021d6efc8f9fmr8404897wro.308.1657807361946; Thu, 14 Jul 2022 07:02:41 -0700 (PDT) Received: from panicking.. ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id k11-20020a7bc40b000000b0039c5cecf206sm2029114wmi.4.2022.07.14.07.02.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 07:02:41 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai Subject: [PATCH 10/11] mtd: nand: Move AMD/Spansion specific init/detection logic in nand_amd.c Date: Thu, 14 Jul 2022 16:02:14 +0200 Message-Id: <20220714140215.444993-11-michael@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220714140215.444993-1-michael@amarulasolutions.com> References: <20220714140215.444993-1-michael@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: michael@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=RB9h6GGo; 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:02:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2165 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 E26553F013 for ; Thu, 14 Jul 2022 16:02:45 +0200 (CEST) Received: by mail-wm1-f71.google.com with SMTP id 130-20020a1c0288000000b003a2fe999093sf1812090wmc.6 for ; Thu, 14 Jul 2022 07:02:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657807365; cv=pass; d=google.com; s=arc-20160816; b=HxHkGEE0cU4FWWsWkjXq9DjKqF47hYQ7JAiyrguRVF8loIAApWD+FF1reF8a8ka72Y Zl7zSMrPunv0+JbP+UUxN3gfE0APsSNTOgM6+b4crFo7GDc/dHA+EMlotMGYq+UbsOvN 7lRqN1MHgu4ivuVAM0NLbMjCBI69joMiVoeEK05rVUXnwcG4P0acNxyj5N5ZKrvCiNKt mcXIjjnq6owjJrn2XC8LpMKxZAtNYBVec6NZ5MrTLIpno9kS1dN0Ez2e1XFB0R02QoSE 009inu/t2BIxwcARaxqERQs+4XMcz458TsKwd+79bwfB2rpPpv0LFI949MheiB2YJHZd s9ug== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=8hUoPkqEiSFS6XPC2M/gUARltnImO/Au3/3jE9dEg08=; b=Q8DHJL1ix8oKalgL9PdA0GaXtwbw5oKmmcJDEcAAffcZtQTAImP460RmiExpkotjee 2XO3mLSOjHNw9eUAqv412UzhUJwC4Wy0nE1ylW7rAewhBw8ad87etx/4wyK8nSwxhstM OV/Wh8CQ31OOfl6OzRDc1EyUfqmxvbRxlkjCgY+ZAZFcM2zjzjZSTLlKWvnfHWvmg7GT 0V6Vspd14taEXfEkGrAsFoXRCSANKI08rdff/cg6fx0o9NbfKzuSXQ0sRxNrB3DcL9hR sO9hksovhIXRoJCtcx6S+KbbMSMRyjwyznVX2i4Wq4dFQQ1Ewj0QqUcV8Vj5s1LZUCsR HD3A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Ub7oxuOI; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=8hUoPkqEiSFS6XPC2M/gUARltnImO/Au3/3jE9dEg08=; b=NcMA6JFc4GBtXSFO9nKaRKTZZyDq++hA5AH7ia+0IkcVsxaWIB53gQ8wE9UNlen1XU uGe5umQ1kDkKblG8fpUTcM5bfdrgZDojKDysC5R0ahmP2/n5PEJzKp0F16Lu50I9f9hY 2GxR/i6sXl/5a1pun8ILCa7FIs0p33HiSxVc0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=8hUoPkqEiSFS6XPC2M/gUARltnImO/Au3/3jE9dEg08=; b=kzrsEO5hrl3iR/7guCrKA4ieoBrS/HIUjB8XCfldqH/YcaorkYvtHuT7yBDUBi0lPI fZey19XhjROXWkJHVBM2nydN30x5tEcVkPA7XqBWiICyf+r+D8Tdo8GuShT8qLQsqr0g kWE7Wo8aLa0iXrQ8rZ5WhU5Dj/wuLHOmAPJpJVgwJ7HphixP0pOCV3D2gu1wmZkiFDJw n2ZsIEQC+YtKCYJEOGLwUIO2gBRY1tlWUn9EfkbfQWGVykxJr7Q9Wmmr1zi2T4R+5EDR t8QR9sdT9u0Bda16h5EjjrxQYd6VNffRrR3YWq6MacBdGNPVfQ9w7u5DoIfnuOe4tuIY DIQw== X-Gm-Message-State: AJIora9XQ7g39s+zGJ9qUhBZgijpVaBevN2AjOMSm9YOxTe2idq8ioLe OlTfpf5974pTuS6E1hvLaZIznN2A X-Google-Smtp-Source: AGRyM1uQdMu2/m9LSa54epzPRVf1gjQrm2TqbT3CadMVmDvx1IV1ldFUjCF1rrpSg4o3AlMNUVHZEg== X-Received: by 2002:a5d:4890:0:b0:21d:9bf3:89b5 with SMTP id g16-20020a5d4890000000b0021d9bf389b5mr8398248wrq.153.1657807365696; Thu, 14 Jul 2022 07:02:45 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a5d:64af:0:b0:21d:bf45:f904 with SMTP id m15-20020a5d64af000000b0021dbf45f904ls112421wrp.3.gmail; Thu, 14 Jul 2022 07:02:44 -0700 (PDT) X-Received: by 2002:adf:f245:0:b0:21d:a39a:bed5 with SMTP id b5-20020adff245000000b0021da39abed5mr8254400wrp.508.1657807364512; Thu, 14 Jul 2022 07:02:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657807364; cv=none; d=google.com; s=arc-20160816; b=H/wYIZq11Z1FZli58NfNhpzIIM6KnrcvrLE4ZDorUNMJxi41VUZ+31RM5cQ2wWZI91 jJD0W4jYCkNXKwMCZxf8nzyVRHJ1wp2geqyQrM06NWZdLxQFSjM3E337U99xBldqsPHU RD6uVRc+zhicGTNZ9wSRySdw+Ha6jLi62GdsoSs0FlOYF/fX5KJt3mSBcFmgDs5WyMMV Mq15rcS6ofxYyGJ1x4qQHIikS95V019Eb3hlXbM3IjS9WVhDj/cFBX1T7tZSYhoqUZB3 7JfPLFRKYvE+jLWu14YVKyGtOFJJlP+UnzNPQBNb+vf2+88OQweTDqJJoJlQ3+nJebTe xuCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=sFuEqjFl/Mfka6FIE5bPT04aWRpTL+eJm4w2Fjxnrrg=; b=NNqNdYI9A9t2pw3ZCbhsBEXbwJvpUhDHGCUJSRohY51911WVNYBVitNuyAa4sHG5p6 U8oVTUuRHCnkv/43ll1PuFVQ4XuGe2WTxe1vcuKY4P73ke/J7EpullsIsv5Lc2XdhQt1 nYnze3GghK45ndrT8BGJMYHzIHil4kZFbLx20GYFOg7SIU89ITUwj0Hv2UpC9eYizKfH 70+mn1ED+gaoWaedjVh2eox6lonK2SeANzP7vXB/fj54Ac7HbzwhveU0gTvis7ABq/n9 H+5+Gz/hHOc1HocrlSLqKCIPhH37lPJpYJfKcnjG3bQiwzylpwPrBADEYoRgJQItZA9p ro4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Ub7oxuOI; 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 n6-20020a5d5886000000b0021b89b50004sor846698wrf.44.2022.07.14.07.02.44 for (Google Transport Security); Thu, 14 Jul 2022 07:02:44 -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:887:b0:21d:4fca:44fc with SMTP id ca7-20020a056000088700b0021d4fca44fcmr8561501wrb.495.1657807363744; Thu, 14 Jul 2022 07:02:43 -0700 (PDT) Received: from panicking.. ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id k11-20020a7bc40b000000b0039c5cecf206sm2029114wmi.4.2022.07.14.07.02.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 07:02:43 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai Subject: [PATCH 11/11] mtd: nand: Move Macronix specific initialization in nand_macronix.c Date: Thu, 14 Jul 2022 16:02:15 +0200 Message-Id: <20220714140215.444993-12-michael@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220714140215.444993-1-michael@amarulasolutions.com> References: <20220714140215.444993-1-michael@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: michael@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Ub7oxuOI; 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);