From patchwork Wed Jul 13 11:06:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Nazzareno Trimarchi X-Patchwork-Id: 2128 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id F11863F066 for ; Wed, 13 Jul 2022 13:06:21 +0200 (CEST) Received: by mail-ej1-f69.google.com with SMTP id l2-20020a170906078200b006fed42bfeacsf3293411ejc.16 for ; Wed, 13 Jul 2022 04:06:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657710381; cv=pass; d=google.com; s=arc-20160816; b=CJpmUtKdw6Cyl1cv6IVfFG1mCnlzJGksiCK+rZlNlk9K1RfGTA7kOXSKkI8IguxU11 g/J7DkAUE36XUTVBEAoH6ep140poySrunf2VF2gwWfPSlJkK3pY+l6drUcvj1my7EnsD KLflWF4mg2CmuL9m71vg81FodzTXirDahJB47HG7BbvtiV7iulpFo+b1GANEV7jGTAeG rpNOp+jEKRV8pTBcuxpcsfmt1T4PbTuZ9c8vfZPZ4NfL/U0ixQpYiBj15CQBKF0cLMmr /uZBSs+CnCitGm5GjHxpGZGgCVxr60ZFYTvVGaLFMjz7pDhTozWCfdwXS/s7fy2f2tLt rRSQ== 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=ibuk6iijeVnWsvDmCkJ4JvKF1GNHzpHwVAaMYrAcGGk=; b=roLvbru5zyRM6hxl2/C+bvbFyiVkjGhmm+ULyS2vdkO5KBAHRtoC9+fq1Ho8x8jvn9 JvcVT5RpvTTabEVTJ0zwI/gtuVriwlvuW76MUz64bsZnCQjilsmsS7qoOGWBChUnJlA6 xUcWXmp7eybLIMWhH3EuFzn2Xz0eK0UA3lghcTH8e4YxHauTOhZT8uIynueXhK5oA6F8 0dW0x0DUamw6IyXxyon2ZkT6YwxS5fCyGaeuV4IoLe+qKRfbeS9QC79+Vl/ofOkpPqIR qSjgNRPUBnTkb3Qw4xkXOGGzXCllzJP2ERlMbwiSBv8kDLM4DaVxjXy0Ra1kR8hBAgnl 6ocg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="JZ/0KeUY"; 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=ibuk6iijeVnWsvDmCkJ4JvKF1GNHzpHwVAaMYrAcGGk=; b=YodjzadH1DlZjIcLhsEQR4qPxZKv9Cw5VrDtt+HlXZlK++fRawapm3i/FLo23iCsjr 62eUJmOewrj9oQxnfE48WsIUAvY/2p1zBFBH69r7RkdNpmoAJHPa51d7f1galXxkyd8d As5S7KPc+vvbo3HaLYkrpFtbC6BQFXt0Pddbo= 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=ibuk6iijeVnWsvDmCkJ4JvKF1GNHzpHwVAaMYrAcGGk=; b=dnSAUnTbw+UYO+30QIhUwsRG6pQYuxZS2Oziso5EKyhWb2BmwMoUtaMcUHwd6ptACk PlAMH9ocQcszK2fQDqX+venkcVsrbZlXqmbtetmaqiP5SB2FQnvB4BTtjDmxW9/Gt7Px B65yaCphfGwM0xt13HzZSM2sAcwGvJv5n0LDI9b9GR3R4lr3AYHrtHGEeZnOD2LG++Of T0c6s5y0/1CXi54igUFbrR+Wyp84LQZH+9l2H15tco6Vcfu0Nqicae+NBqR873Xo1446 NlQJHbnpKDFsVbevlxedJMBDgbZ6ckqb5CLAcUClMntCEg1/3qT7S/jTg2LExvFsXLxD xk3A== X-Gm-Message-State: AJIora9nh1uWOh5iBfAZehRFHp0MFzWWE284Y7AfHd/zr6iQM9mBFCZC D0bOCAOXOfy7pSH7AxHLhZEtcVUb X-Google-Smtp-Source: AGRyM1sNr1KF3AyOwQzBu8CDQoR6m769HF/uLhENsRbSWFggZWj8F+DiZ4Dm3SMIpgawcHsv/IJ6zg== X-Received: by 2002:a05:6402:1115:b0:43a:f5db:b891 with SMTP id u21-20020a056402111500b0043af5dbb891mr4022049edv.315.1657710381583; Wed, 13 Jul 2022 04:06:21 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:907:7f27:b0:72b:6e70:8c8c with SMTP id qf39-20020a1709077f2700b0072b6e708c8cls971351ejc.10.gmail; Wed, 13 Jul 2022 04:06:20 -0700 (PDT) X-Received: by 2002:a17:907:7628:b0:72b:4d6f:ce8a with SMTP id jy8-20020a170907762800b0072b4d6fce8amr2897193ejc.59.1657710380218; Wed, 13 Jul 2022 04:06:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657710380; cv=none; d=google.com; s=arc-20160816; b=EThfa3e5gf4mkoNnZHzuj0wYZ/rVkIimXzNtMG1fkYahwXPg2Qiy9XrcrSjg1JcFeE 5PogexmrBX3fXD0nkuGs1zBkQvrxKP8W93eUcevbYNL51tr/hlYakSGY+fZhVbW78tMU DFXAXaTWETJLYCservELADkKCaf5mzN5fv/UjODJ77LXbx4s9S5smIXqJt1KN4PXcT/I Jd07REUi0/bJhTeCurIcAJAXM/it0LefeVVlWZv7azLhCGa45tQyVK6Q4mAA8ODF9gFE 0bvsaK2RA3HmPxtgkglGN38sfPDk5R1SVI4VKIAZCRp8FajSSNY5et+tZQ/JpDoYYTY2 Uv4g== 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=scgZb0bC4B0X7WUv3UyK3BSDdHPIjlgd8bR1EBbI9lI=; b=NZ/zi3PbnAKjnJNqrRFlqpL4YJ8gFoIZXradHqWKhlMOM+uX669XSd/OK6V4V806qC S4uEheukQKuHz54JWOBJ9bbsRHzylnuKwR3euXQiJtAeNS6bfgPh/THvbVQSR9rgbu1U 7XLZ77rhWD++Xt5QQn9o67Ln6bIbqSS9/2LeS7YwIm3ZY2qPmXoIsWM0R5jaFIehQICA NImNGEOMWndFNnG8bgkF24dOFnwYCoCGclaFuKVOy8gb7zpOVWOWoXnsJmjxdaJLASaw 6qY8V95HmIaUSzvJnbkCQEfyEf9/S22/vtUmH/0nC1eI8KpqaH8Bck3uviJmVxJpc+gb W+JA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="JZ/0KeUY"; 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 h2-20020a50cdc2000000b0043a507ac036sor4900974edj.33.2022.07.13.04.06.20 for (Google Transport Security); Wed, 13 Jul 2022 04:06:20 -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:6402:40d6:b0:43a:cc69:1db9 with SMTP id z22-20020a05640240d600b0043acc691db9mr4125239edb.380.1657710379449; Wed, 13 Jul 2022 04:06:19 -0700 (PDT) Received: from panicking.amarulasolutions.com ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id fg16-20020a1709069c5000b006fec27575f1sm4830767ejc.123.2022.07.13.04.06.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 04:06:18 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai Subject: [PATCH V2 1/4] mtd: nand: Drop busw variable and use chip->options field Date: Wed, 13 Jul 2022 13:06:13 +0200 Message-Id: <20220713110616.305444-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="JZ/0KeUY"; 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 --- V1->V2: - reset the prefix as suggested by Dario - only drop busw assigment in find_full_id_nand --- drivers/mtd/nand/raw/nand_base.c | 60 +++++++++++++++++++------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 6f81257cf1..0f45fe676f 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,9 @@ 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; + chip->options |= 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 +3994,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 +4003,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 +4065,9 @@ 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; + chip->options |= NAND_BUSWIDTH_16; else - *busw = 0; + chip->options &= ~NAND_BUSWIDTH_16; /* ECC info */ ecc = &p->ecc_info[0]; @@ -4160,7 +4157,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 +4210,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)); - *busw = 0; + chip->options &= ~NAND_BUSWIDTH_16; } else if (id_len == 6 && id_data[0] == NAND_MFR_HYNIX && !nand_is_slc(chip)) { unsigned int tmp; @@ -4254,7 +4251,7 @@ 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; + chip->options &= ~NAND_BUSWIDTH_16; } else { /* Calc pagesize */ mtd->writesize = 1024 << (extid & 0x03); @@ -4267,7 +4264,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 +4290,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 +4359,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,8 +4374,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; @@ -4441,9 +4435,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 +4462,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 +4480,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;