From patchwork Wed Jul 13 06:54:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2120 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 097D03F1F7 for ; Wed, 13 Jul 2022 08:54:46 +0200 (CEST) Received: by mail-ed1-f69.google.com with SMTP id z5-20020a05640235c500b0043ae18edeeesf4114720edc.5 for ; Tue, 12 Jul 2022 23:54:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657695285; cv=pass; d=google.com; s=arc-20160816; b=0yYWfT2p/NWZWzCpUuISvKU9ZQNpUS3/6MbtH4f/UT0Qi6uhoCLEAUK5QiY+5GwgVO T4RXWoH1fBdgaMNqERjlfa0hd64LDo3x33Fn/mW1pHGuJw7VvCUoYoRJ4qfg3GPbc+AE P1gXPfgkYs/XR8tBXf10qk4P/+nQtT1lz/bzh6SY7ikb20XadFEBYqM+U6ZkZ/8xIV9M b+qRSprfUQGz2c9DJEqs+paws4EAtcHMnjAd10tmsrKQ6uN8Mba4k2v+/pogwQvAzT44 GGo0tlQC1RQ2ll/PhO4jC9PosTAV0uOraZu4qE2R3z44iETU/qss0Oqo9mBTxhM6HLvg ihkw== 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:message-id:date:subject:to :from:dkim-signature; bh=w6jeEffYbyh5yW4irRptvwg51uM2EHfMcnY/JdAF/24=; b=TqFRt10X02nJ1UCoBTrtCinlEWWpyA6EcSc3f5Pm5boSy8Pzu3SzA720zOVYAJ8jwj c0zDzGNFdgiFRcZkO+Cilt01dseAifc2Lak53V6GT0egUNX5m4lSxJS94YqP7Hd+asNE qZ7+dy/p7DmCffmLx9x0/y/JEgMdb39xQhJJ9OXI+wSP71uJf9Xl6HBtCiVVDrKprptT xPaCPId9m2Vj2B0guCnqVdh1Dseu/x+GwRPkQuh4lzm+s9CL9hiSy7PK0GnuvRL3G+L7 YCWZuLOIvjlkgKIxswxH8l6RXMxfo8lPATmysBPOPQV/W0UHBTmw5p543UDsj5tkhpFB qa6g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=b64P4jEL; 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:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=w6jeEffYbyh5yW4irRptvwg51uM2EHfMcnY/JdAF/24=; b=TPyCD4yh7ij6tWs0nN7DiTvDnOkEAV1591v3ZxX1w4U8/3Y9nEcWTLH0yJuddyVSBm yyeuO/OvMin+GcPnuvkqYMRKDdemgbRWAYYKKRBdTFUyXx/P4QiyfdXgj/BbSUwnXkaD sWj4LBOqQPt3M22OBTFcvd7NpjzQq7+4jNvHI= 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: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=w6jeEffYbyh5yW4irRptvwg51uM2EHfMcnY/JdAF/24=; b=l8SLIQOLlG4d971qyPGlTrMqDZYmiJfemhY/wwfM8Fus9CEJ2DfU579SYa56NmO5Zz SBmsGdtj2HTnbDoN4totpQ2yxig3qUrS8dmlWep1YV5MKNxoWGTnMvUbqpaj+7/I/8aF rPkJjluGq5GgV/U9VNkdqh7PMEfcHx+BSVC+UlT79BIZLwF9/jA0z4eXciHcb3oCLPak Z54nxb+7kpxfXDEZzMliAsY52OfV+w3gSvq3BqUVeDk3ayEmljmyZ2KOZOF3Ebvg+JAF br7hilr19LQ4OVdJv4wUjVg1RV+grxYL9vLGc7NQlydl+1ONt65t5HtL9mDEqz55O7Zm 4vMA== X-Gm-Message-State: AJIora/RMhiJ7kwN7uzD9G731/zgnRZMJRc7oION4b/VGmx/rpcw34KK 4fOUFYDwqwTafBWSuFWlC5A55+51 X-Google-Smtp-Source: AGRyM1vLAN/xO/3PZJeBeM3Qedbap8E7wtLD73niBXC5r5OCivfz9ccugVUtNKR2wx+EQFJGTTFTZg== X-Received: by 2002:a17:907:9613:b0:72b:68df:8ada with SMTP id gb19-20020a170907961300b0072b68df8adamr1983069ejc.31.1657695285877; Tue, 12 Jul 2022 23:54:45 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:d0e:b0:43a:6e96:4ae7 with SMTP id eb14-20020a0564020d0e00b0043a6e964ae7ls151644edb.1.gmail; Tue, 12 Jul 2022 23:54:44 -0700 (PDT) X-Received: by 2002:a05:6402:1d97:b0:43a:7b45:8e14 with SMTP id dk23-20020a0564021d9700b0043a7b458e14mr2792928edb.418.1657695284500; Tue, 12 Jul 2022 23:54:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657695284; cv=none; d=google.com; s=arc-20160816; b=GNQD/11SCfW8oi/TmAX7jxA4mpUXqDZ8MAa91DiYZ0u3KXC7yustPZiTCSy+TA547o QBZONxEaVSSgW+/CYAruJZL00A8n7QhyjrKAGAocu2R9x6hlarfUG2i6n1ZmENUaO1LX S1qI/+IlKynCpmSkrkr/t0afPU9GbDmHuhVnuUbBsLnd7HwGlBhtiJLtZywYd4lBsm0l c2EaygzuUH1iVWxtYPzAJHFgfG4+S0VhJbxBDDkB8jK7vgkXQuijJYYJ3+CU1lUo3CFm /Qlsg5ejLSojwSSGMlgs2j5kb8GLinUJiUANcMhA+Mfx6J6VD7g4x238VVHEP00IlM2j XB/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:dkim-signature; bh=lIuIWLqqz2ogXeLR2OiG+YgBNXzZxQ2P6FCSJQWqai8=; b=0pFZI5AayBnGB6ojo9oXJaPQAQVrHRWFW7bHPEar3IsqgZx8Gi6DjgT/YjpAJSLCDu v8nE6HZ1l5dhyS7IKyHr6+tgkdorf7Rrlt3gmMwEPuW39ER0It1cvzEqhwC41nUYCbNT LtQq7yOWo0rXze3OWUm5N/gneb4pT5VAC8t6ZdSO/SDCqVhYkJiFqYBjJg4ezJ0QoUca dN+y7d48M684NBWFjkKX6SswuvWwSlxHhToy06VdMu8VfcEdQtGjm9ixWmcVpQu+mL6K u0o1J0mrBjaM1bIwYPssB6nbKPlzq3Y9CtckE/ilIXkdf1TnJKqY3q/qNKa+xxPBQk8+ kwlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=b64P4jEL; 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 e21-20020a170906081500b007262f75c699sor3576142ejd.116.2022.07.12.23.54.44 for (Google Transport Security); Tue, 12 Jul 2022 23:54: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:a17:906:6d98:b0:715:76eb:9e33 with SMTP id h24-20020a1709066d9800b0071576eb9e33mr1986477ejt.729.1657695284082; Tue, 12 Jul 2022 23:54:44 -0700 (PDT) Received: from panicking.amarulasolutions.com ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id lz21-20020a170906fb1500b0072aa38d768esm4635263ejb.64.2022.07.12.23.54.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jul 2022 23:54:43 -0700 (PDT) From: Michael Trimarchi To: Dario Binacchi , linux-amarula@amarulasolutions.com, Tommaso Merciai Subject: [PATCH 1/4] mtd: nand: Drop busw variable and use chip->options field Date: Wed, 13 Jul 2022 08:54:36 +0200 Message-Id: <20220713065439.272149-1-michael@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 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=b64P4jEL; 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: , No functional change. Reduce the function parameters in preparation of support specific nand manufacture Signed-off-by: Michael Trimarchi --- drivers/mtd/nand/raw/nand_base.c | 58 ++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 6f81257cf1..cb22e0ec13 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -3890,8 +3890,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]; @@ -3963,9 +3962,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; @@ -3995,8 +3992,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; } @@ -4005,8 +4001,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; @@ -4068,9 +4063,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]; @@ -4160,7 +4153,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 */ @@ -4213,7 +4206,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; @@ -4254,7 +4246,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); @@ -4267,7 +4258,7 @@ 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; + chip->options |= (extid & 0x01) ? NAND_BUSWIDTH_16 : 0; /* * Toshiba 24nm raw SLC (i.e., not BENAND) have 32B OOB per @@ -4293,15 +4284,14 @@ 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; + chip->options |= (type->options & NAND_BUSWIDTH_16) ? NAND_BUSWIDTH_16 : 0; /* All legacy ID NAND are small-page, SLC */ chip->bits_per_cell = 1; @@ -4363,7 +4353,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; @@ -4378,7 +4368,7 @@ 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; + chip->options |= (type->options & NAND_BUSWIDTH_16) ? NAND_BUSWIDTH_16 : 0; if (!mtd->name) mtd->name = type->name; @@ -4441,9 +4431,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; @@ -4453,11 +4458,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; } @@ -4471,10 +4476,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;