From patchwork Fri Sep 22 03:46:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 113953 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp2798498qgf; Thu, 21 Sep 2017 20:49:54 -0700 (PDT) X-Google-Smtp-Source: AOwi7QBi79j7FoYW4ijqNJMmPII3cKKiYElwrXrblzNunMvOm0hWnVsRogeemvPa+makJ3a82GkV X-Received: by 10.159.246.2 with SMTP id b2mr7659692pls.85.1506052194138; Thu, 21 Sep 2017 20:49:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506052194; cv=none; d=google.com; s=arc-20160816; b=tQAqdiqXHxZNMDT0w1Va3JY0d42oMoFkQJsKzngankTribSlmV9B7jl9i/7bxgZkCe t9AI5pQn2PE40akPuTDh6Tghoj7qeFdGlrbUn7LVrOsXrvqLSfbsKuGleB1FSZuG7/HL 17sebfd+Iqr1L+fE2N1BYeQuI2hTUHtUxKy3u5MB4W22dXl0hV2ubgYQkA4VOi/UexL8 IxlYmuc84GOb2jLwLo/V8k1e2weHCZAUJpqrEnZllopvWMilblX3uaU/Np84bkpPWtsR KP+c4tBvgkTho1PLKgmMvg9E1vt+UaCpveC2NtZK8zttHOmIt8pyHRYJZKFAZVVEOUDl 6Xqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:references:in-reply-to:message-id:date:subject :to:from:dkim-signature:dkim-filter:dkim-signature :arc-authentication-results; bh=UgfZWerSYZyTkO4D92yUmBhUglSJkf50W6iJp+3ZR/0=; b=ukzGC8gI7ghfinGLObLv6FTQ0++dJ2iqv9x1H64MD8ke3Pve4VK72coqHCjaFOc7xf kYEsGxs2yVSrSVvdDYJ6XMXJTIFy/KYV8knnj4hwsFrjbM/zg+4hoivFjpxpuYeoUVui 6n7/H7Rqs8IHYmwEhvEMzqAYiXKxldkjLRDHcRe6NQEmHZ/whY4SYoN4CFxj2ot5jphx ivnk05EGHPKTpQmcsvsu4iwMtRiq0rxw+A5fG6xrvVW4Ndf0hgIAZiP+DaVtNR2JRrIF YPYTHH7TpxW3SGrmbTUXhTueuVSdLK5vW7vox5fUVwbuh0fWIvbg76KE+dJS9zb8wKy+ 996w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=OXr9OrTw; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=loZ4IFoB; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 65.50.211.133 as permitted sender) smtp.mailfrom=linux-mtd-bounces+patch=linaro.org@lists.infradead.org Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [65.50.211.133]) by mx.google.com with ESMTPS id b63si2046195plb.433.2017.09.21.20.49.54 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Sep 2017 20:49:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 65.50.211.133 as permitted sender) client-ip=65.50.211.133; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=OXr9OrTw; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=loZ4IFoB; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 65.50.211.133 as permitted sender) smtp.mailfrom=linux-mtd-bounces+patch=linaro.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=UgfZWerSYZyTkO4D92yUmBhUglSJkf50W6iJp+3ZR/0=; b=OXr9OrTwXF+0q1r3BBwsTKZqGz /CW8JSj0iU5tASzFVNHnRQGQslYnaGIKQ/LBql8+3RxoJSIqsR06gCnYFiks6aW+vuORqVbuuYuo2 V8kCS9v6/sKYUN7QaF6nZpK8P9BXgjuyc3pqvADPv9CUDamSAqm8d7Hmc58dLbK+QNe1zLvka9lWn VUFVlkoVz19Rt0kX1xFY6ZlpJ2uM0/KMsRG+xor6mROP48BdSbDBFmO7eSed6MAUBPHn+Pxlhs7nL gZaT6CKL/x8j5bkQB1Nqmiafef6FmQfLUVM/VqYsgc1b62Qd4EMHPP0Vrrq3oSALmXu8R4S4wGez0 GekXEjrw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dvEyE-0005bi-Im; Fri, 22 Sep 2017 03:49:42 +0000 Received: from conuserg-09.nifty.com ([210.131.2.76]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dvEwJ-0004Fg-3L for linux-mtd@lists.infradead.org; Fri, 22 Sep 2017 03:47:49 +0000 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id v8M3kwAP029389; Fri, 22 Sep 2017 12:47:04 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com v8M3kwAP029389 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1506052024; bh=mfGw0JoEuuDddv64haurMlN9KOCuYTksVaq+96Va9sQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=loZ4IFoBtEQ8+dd2UKnnYdehtDF5oigPc21NizGK+K5KQRGw2VovsdBjgAP3fUdlB K9ofxLEOZi7laADScmSQL0DMFouY52gULUo1kOSo+r49nzXAGjQ3yzBO4KncY+NE3I Ac4g4yfcRYn6t16OtuNieriEWgPORMjmQGnDvFwnBPDj+aPNxQIU2cTE9dKmoc3+KM 73jLGZGlxqqRK7J8FXBEAzsUu433QZWdAbyqGOxTV3gWV2GnGd9RdTzT1kW66qLYVY H95EEJ+Nf0ppzAIyr+hMJFkMKbiS7+18Ou2tPeiPOd4CaK0SYg8JejyiK1bTuCq8wT 7y2Eac3a47VLw== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-mtd@lists.infradead.org Subject: [PATCH v2 06/12] mtd: nand: denali: clean up macros with Date: Fri, 22 Sep 2017 12:46:43 +0900 Message-Id: <1506052009-8285-7-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1506052009-8285-1-git-send-email-yamada.masahiro@socionext.com> References: <1506052009-8285-1-git-send-email-yamada.masahiro@socionext.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170921_204743_470238_386E5357 X-CRM114-Status: GOOD ( 13.51 ) X-Spam-Score: -1.2 (-) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-1.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.7 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Boris Brezillon , Marek Vasut , Richard Weinberger , linux-kernel@vger.kernel.org, Masahiro Yamada , Cyrille Pitchen , Brian Norris , David Woodhouse MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+patch=linaro.org@lists.infradead.org All the register offsets and bitfield masks are defined in denali.h, but the driver code ended up with additional crappy macros such as MAKE_ECC_CORRECTION(), ECC_SECTOR(), etc. The reason is apparent - accessing a register field requires mask and shift pair. The denali.h only provides mask. However, defining both is tedious. provides a convenient way to get register fields only with a single shifted mask. Now use it. While I am here, I shortened some macros. Signed-off-by: Masahiro Yamada --- Changes in v2: None drivers/mtd/nand/denali.c | 25 +++++++++++-------------- drivers/mtd/nand/denali.h | 13 +++++-------- 2 files changed, 16 insertions(+), 22 deletions(-) -- 2.7.4 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c index 3cc56de..1525c4e 100644 --- a/drivers/mtd/nand/denali.c +++ b/drivers/mtd/nand/denali.c @@ -17,6 +17,7 @@ * */ +#include #include #include #include @@ -386,13 +387,6 @@ static int denali_hw_ecc_fixup(struct mtd_info *mtd, return max_bitflips; } -#define ECC_SECTOR(x) (((x) & ECC_ERROR_ADDRESS__SECTOR_NR) >> 12) -#define ECC_BYTE(x) (((x) & ECC_ERROR_ADDRESS__OFFSET)) -#define ECC_CORRECTION_VALUE(x) ((x) & ERR_CORRECTION_INFO__BYTEMASK) -#define ECC_ERROR_UNCORRECTABLE(x) ((x) & ERR_CORRECTION_INFO__ERROR_TYPE) -#define ECC_ERR_DEVICE(x) (((x) & ERR_CORRECTION_INFO__DEVICE_NR) >> 8) -#define ECC_LAST_ERR(x) ((x) & ERR_CORRECTION_INFO__LAST_ERR_INFO) - static int denali_sw_ecc_fixup(struct mtd_info *mtd, struct denali_nand_info *denali, unsigned long *uncor_ecc_flags, uint8_t *buf) @@ -410,18 +404,20 @@ static int denali_sw_ecc_fixup(struct mtd_info *mtd, do { err_addr = ioread32(denali->reg + ECC_ERROR_ADDRESS); - err_sector = ECC_SECTOR(err_addr); - err_byte = ECC_BYTE(err_addr); + err_sector = FIELD_GET(ECC_ERROR_ADDRESS__SECTOR, err_addr); + err_byte = FIELD_GET(ECC_ERROR_ADDRESS__OFFSET, err_addr); err_cor_info = ioread32(denali->reg + ERR_CORRECTION_INFO); - err_cor_value = ECC_CORRECTION_VALUE(err_cor_info); - err_device = ECC_ERR_DEVICE(err_cor_info); + err_cor_value = FIELD_GET(ERR_CORRECTION_INFO__BYTE, + err_cor_info); + err_device = FIELD_GET(ERR_CORRECTION_INFO__DEVICE, + err_cor_info); /* reset the bitflip counter when crossing ECC sector */ if (err_sector != prev_sector) bitflips = 0; - if (ECC_ERROR_UNCORRECTABLE(err_cor_info)) { + if (err_cor_info & ERR_CORRECTION_INFO__UNCOR) { /* * Check later if this is a real ECC error, or * an erased sector. @@ -451,7 +447,7 @@ static int denali_sw_ecc_fixup(struct mtd_info *mtd, } prev_sector = err_sector; - } while (!ECC_LAST_ERR(err_cor_info)); + } while (!(err_cor_info & ERR_CORRECTION_INFO__LAST_ERR)); /* * Once handle all ecc errors, controller will trigger a @@ -1351,7 +1347,8 @@ int denali_init(struct denali_nand_info *denali) "chosen ECC settings: step=%d, strength=%d, bytes=%d\n", chip->ecc.size, chip->ecc.strength, chip->ecc.bytes); - iowrite32(MAKE_ECC_CORRECTION(chip->ecc.strength, 1), + iowrite32(FIELD_PREP(ECC_CORRECTION__ERASE_THRESHOLD, 1) | + FIELD_PREP(ECC_CORRECTION__VALUE, chip->ecc.strength), denali->reg + ECC_CORRECTION); iowrite32(mtd->erasesize / mtd->writesize, denali->reg + PAGES_PER_BLOCK); diff --git a/drivers/mtd/nand/denali.h b/drivers/mtd/nand/denali.h index dc3f970..73aad3a 100644 --- a/drivers/mtd/nand/denali.h +++ b/drivers/mtd/nand/denali.h @@ -114,9 +114,6 @@ #define ECC_CORRECTION 0x1b0 #define ECC_CORRECTION__VALUE GENMASK(4, 0) #define ECC_CORRECTION__ERASE_THRESHOLD GENMASK(31, 16) -#define MAKE_ECC_CORRECTION(val, thresh) \ - (((val) & (ECC_CORRECTION__VALUE)) | \ - (((thresh) << 16) & (ECC_CORRECTION__ERASE_THRESHOLD))) #define READ_MODE 0x1c0 #define READ_MODE__VALUE GENMASK(3, 0) @@ -258,13 +255,13 @@ #define ECC_ERROR_ADDRESS 0x630 #define ECC_ERROR_ADDRESS__OFFSET GENMASK(11, 0) -#define ECC_ERROR_ADDRESS__SECTOR_NR GENMASK(15, 12) +#define ECC_ERROR_ADDRESS__SECTOR GENMASK(15, 12) #define ERR_CORRECTION_INFO 0x640 -#define ERR_CORRECTION_INFO__BYTEMASK GENMASK(7, 0) -#define ERR_CORRECTION_INFO__DEVICE_NR GENMASK(11, 8) -#define ERR_CORRECTION_INFO__ERROR_TYPE BIT(14) -#define ERR_CORRECTION_INFO__LAST_ERR_INFO BIT(15) +#define ERR_CORRECTION_INFO__BYTE GENMASK(7, 0) +#define ERR_CORRECTION_INFO__DEVICE GENMASK(11, 8) +#define ERR_CORRECTION_INFO__UNCOR BIT(14) +#define ERR_CORRECTION_INFO__LAST_ERR BIT(15) #define ECC_COR_INFO(bank) (0x650 + (bank) / 2 * 0x10) #define ECC_COR_INFO__SHIFT(bank) ((bank) % 2 * 8)