Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5504320ybi; Tue, 4 Jun 2019 07:38:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqxl6BUIsGDslLzSIeMI0wjY/QqTSWgnBSkC+mMktL7GlRKMsr77HtYgw8vovOL25zibUTGI X-Received: by 2002:aa7:8292:: with SMTP id s18mr7513639pfm.111.1559659134923; Tue, 04 Jun 2019 07:38:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559659134; cv=none; d=google.com; s=arc-20160816; b=DDnRuAln1ZnVjBpt5/n9BosP30sP0rPxgIEu8vEqsFbkFnLHSR+FlIfiB1/xtYJ4Xq qJmB23I77NA3xVWB1q57tlGU+I375n2QYpjfNZP3Lc7QzH2igswrGAq1eSxezlyi1g6m 3iYC0VRjZsza9uRI2hB5lS3In8AxlQln1pP4Ni+xcg6kjxv3sNeNLobOITV9tZnxrRjp jmxDC2von2RbdTVoSgck2ohqUiqxrcMVob16OT8z6qXfoKXiR84OLTvcsW6Dttv1RcVS elm83IzY3UN53/kdPY1IQ3nBz+TUGOUyCp5RcexSFr3R3hD7c6VtefepOgt67kLlHblp J8tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=otDo9JTAjxXUIL0wLWnsf0TMryCbgHF9GFg/VIogBAs=; b=yUWHCpFbyK9iTu5eOsZEE1sjJulq4bxYcAmCcO/qexQncYrFiSeYon8ffQe7tKUP4m FV5Xb3OR+vziQRUaUe0tX8Nb79knrtEIQMX3tHtxhT29KLh7vC/NqRj2xzin89CRjsEs SlDkMqzIgn2JxanBBXUP/YmI7aiKQLZ+5h4Abnvlh/cJhwFGR2hnlZxwdSoBZpVpLyD6 anMx3CdgsLNVD0pgyhQqdJ8KPB1c4ECjcrNGLiNcQYxFWgUyIf7ZYx4ERCNaYUnUfMo+ mcI3MT0N9mwci0nVEDWiBnPAcnKmVHR3zyOQA5NAfRMVO3pHNXOKaBTsGCThncSP4/JK aY5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kCjoVhgd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n8si17262450plk.272.2019.06.04.07.38.38; Tue, 04 Jun 2019 07:38:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kCjoVhgd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727715AbfFDOhP (ORCPT + 99 others); Tue, 4 Jun 2019 10:37:15 -0400 Received: from mail-pf1-f180.google.com ([209.85.210.180]:37995 "EHLO mail-pf1-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727607AbfFDOhN (ORCPT ); Tue, 4 Jun 2019 10:37:13 -0400 Received: by mail-pf1-f180.google.com with SMTP id a186so12108665pfa.5 for ; Tue, 04 Jun 2019 07:37:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=otDo9JTAjxXUIL0wLWnsf0TMryCbgHF9GFg/VIogBAs=; b=kCjoVhgdZdcOvP3sZPyHTyIZ85jJnetO5gXKqNfILh57x1IyOoKasY2xq1+oWnqr9O /r9Bm+1nN4LFlCXnZzsQli1WhvGWny5lhx5RBZbe6CGxAslWqt+0ZOTyuKugBd+ZmBV0 W6HakKVRh1X6jIsVuCT65dnHppF7xOh2ZvBQaVzLkjTuecQulX4y9Kj64AYCZmDVYHwf gy/o5wgQm1NT4XDchxHwTFkv8BLAEjDwyqbYRrWa84wgkO0wPBlv1V/NE06sy7s8cyt4 ws4vpjKnoYQr6lTzKQ4k31QbHihv/TDa2QPSBgzz9P8tsNf4bVI28k/+cjVw/fxMyG6/ HZmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=otDo9JTAjxXUIL0wLWnsf0TMryCbgHF9GFg/VIogBAs=; b=C20uYjLrCQZ4zf/423OXxIpsUokwjY0f5kqlVVOJemVdrRlvqDIICU0NGSRGpuOVc3 Lqi7ofb397eRh6+uaoNfXrZF4x92IiszZ7LCGS8SVE7/wniwu010AJok4WBM5aK1qxev wzqVU4rXjrmk/a4eie3SGpy8ZdwQfJmaMVpayxytVf4WuZMR7p6uXBj3azulCtPl21JN hYJ35Q7fn9FamgfAv91RdigYEjT2kG71EB6HUmVVCY9P1AmplxKl/Jg0B7lyIjgKyJ7J JVHK7l3k9huFjQzXxW2fBiz+HFlTK9ytW9XagIB//D38ZQ793yypvhpBl5lJDfBKwptk xsvQ== X-Gm-Message-State: APjAAAUqQGbXPPn3WQ3MmhXqwDqwF+/A4i6hzuLcvPs1lZnSoMiFf46t 7OJ+AGHoceLrGttXUaSn8n8= X-Received: by 2002:a17:90a:4814:: with SMTP id a20mr38088311pjh.62.1559659032979; Tue, 04 Jun 2019 07:37:12 -0700 (PDT) Received: from mail.broadcom.com ([192.19.231.250]) by smtp.gmail.com with ESMTPSA id m6sm24156872pjl.18.2019.06.04.07.37.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Jun 2019 07:37:12 -0700 (PDT) From: Kamal Dasu To: linux-mtd@lists.infradead.org Cc: bcm-kernel-feedback-list@broadcom.com, linux-kernel@vger.kernel.org, Kamal Dasu , Brian Norris , Miquel Raynal , Richard Weinberger , David Woodhouse , Marek Vasut , Vignesh Raghavendra Subject: [PATCH v2 1/3] mtd: nand: raw: brcmnand: Refactored code to introduce helper functions Date: Tue, 4 Jun 2019 10:36:29 -0400 Message-Id: <1559659013-34502-1-git-send-email-kdasu.kdev@gmail.com> X-Mailer: git-send-email 1.9.0.138.g2de3478 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Refactored NAND ECC and CMD address configuration code to use helper functions. Signed-off-by: Kamal Dasu --- drivers/mtd/nand/raw/brcmnand/brcmnand.c | 100 +++++++++++++++++++------------ 1 file changed, 62 insertions(+), 38 deletions(-) diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c index ce0b8ff..c534ea8 100644 --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c @@ -588,6 +588,54 @@ static inline void brcmnand_write_fc(struct brcmnand_controller *ctrl, __raw_writel(val, ctrl->nand_fc + word * 4); } +static void brcmnand_clear_ecc_addr(struct brcmnand_controller *ctrl) +{ + + /* Clear error addresses */ + brcmnand_write_reg(ctrl, BRCMNAND_UNCORR_ADDR, 0); + brcmnand_write_reg(ctrl, BRCMNAND_CORR_ADDR, 0); + brcmnand_write_reg(ctrl, BRCMNAND_UNCORR_EXT_ADDR, 0); + brcmnand_write_reg(ctrl, BRCMNAND_CORR_EXT_ADDR, 0); +} + +static u64 brcmnand_get_uncorrecc_addr(struct brcmnand_controller *ctrl) +{ + u64 err_addr; + + err_addr = brcmnand_read_reg(ctrl, BRCMNAND_UNCORR_ADDR); + err_addr |= ((u64)(brcmnand_read_reg(ctrl, + BRCMNAND_UNCORR_EXT_ADDR) + & 0xffff) << 32); + + return err_addr; +} + +static u64 brcmnand_get_correcc_addr(struct brcmnand_controller *ctrl) +{ + u64 err_addr; + + err_addr = brcmnand_read_reg(ctrl, BRCMNAND_CORR_ADDR); + err_addr |= ((u64)(brcmnand_read_reg(ctrl, + BRCMNAND_CORR_EXT_ADDR) + & 0xffff) << 32); + + return err_addr; +} + +static void brcmnand_set_cmd_addr(struct mtd_info *mtd, u64 addr) +{ + struct nand_chip *chip = mtd_to_nand(mtd); + struct brcmnand_host *host = nand_get_controller_data(chip); + struct brcmnand_controller *ctrl = host->ctrl; + + brcmnand_write_reg(ctrl, BRCMNAND_CMD_EXT_ADDRESS, + (host->cs << 16) | ((addr >> 32) & 0xffff)); + (void)brcmnand_read_reg(ctrl, BRCMNAND_CMD_EXT_ADDRESS); + brcmnand_write_reg(ctrl, BRCMNAND_CMD_ADDRESS, + lower_32_bits(addr)); + (void)brcmnand_read_reg(ctrl, BRCMNAND_CMD_ADDRESS); +} + static inline u16 brcmnand_cs_offset(struct brcmnand_controller *ctrl, int cs, enum brcmnand_cs_reg reg) { @@ -1213,9 +1261,12 @@ static void brcmnand_send_cmd(struct brcmnand_host *host, int cmd) { struct brcmnand_controller *ctrl = host->ctrl; int ret; + u64 cmd_addr; + + cmd_addr = brcmnand_read_reg(ctrl, BRCMNAND_CMD_ADDRESS); + + dev_dbg(ctrl->dev, "send native cmd %d addr 0x%llx\n", cmd, cmd_addr); - dev_dbg(ctrl->dev, "send native cmd %d addr_lo 0x%x\n", cmd, - brcmnand_read_reg(ctrl, BRCMNAND_CMD_ADDRESS)); BUG_ON(ctrl->cmd_pending != 0); ctrl->cmd_pending = cmd; @@ -1374,12 +1425,7 @@ static void brcmnand_cmdfunc(struct nand_chip *chip, unsigned command, if (!native_cmd) return; - brcmnand_write_reg(ctrl, BRCMNAND_CMD_EXT_ADDRESS, - (host->cs << 16) | ((addr >> 32) & 0xffff)); - (void)brcmnand_read_reg(ctrl, BRCMNAND_CMD_EXT_ADDRESS); - brcmnand_write_reg(ctrl, BRCMNAND_CMD_ADDRESS, lower_32_bits(addr)); - (void)brcmnand_read_reg(ctrl, BRCMNAND_CMD_ADDRESS); - + brcmnand_set_cmd_addr(mtd, addr); brcmnand_send_cmd(host, native_cmd); brcmnand_waitfunc(chip); @@ -1597,20 +1643,10 @@ static int brcmnand_read_by_pio(struct mtd_info *mtd, struct nand_chip *chip, struct brcmnand_controller *ctrl = host->ctrl; int i, j, ret = 0; - /* Clear error addresses */ - brcmnand_write_reg(ctrl, BRCMNAND_UNCORR_ADDR, 0); - brcmnand_write_reg(ctrl, BRCMNAND_CORR_ADDR, 0); - brcmnand_write_reg(ctrl, BRCMNAND_UNCORR_EXT_ADDR, 0); - brcmnand_write_reg(ctrl, BRCMNAND_CORR_EXT_ADDR, 0); - - brcmnand_write_reg(ctrl, BRCMNAND_CMD_EXT_ADDRESS, - (host->cs << 16) | ((addr >> 32) & 0xffff)); - (void)brcmnand_read_reg(ctrl, BRCMNAND_CMD_EXT_ADDRESS); + brcmnand_clear_ecc_addr(ctrl); for (i = 0; i < trans; i++, addr += FC_BYTES) { - brcmnand_write_reg(ctrl, BRCMNAND_CMD_ADDRESS, - lower_32_bits(addr)); - (void)brcmnand_read_reg(ctrl, BRCMNAND_CMD_ADDRESS); + brcmnand_set_cmd_addr(mtd, addr); /* SPARE_AREA_READ does not use ECC, so just use PAGE_READ */ brcmnand_send_cmd(host, CMD_PAGE_READ); brcmnand_waitfunc(chip); @@ -1630,21 +1666,15 @@ static int brcmnand_read_by_pio(struct mtd_info *mtd, struct nand_chip *chip, host->hwcfg.sector_size_1k); if (!ret) { - *err_addr = brcmnand_read_reg(ctrl, - BRCMNAND_UNCORR_ADDR) | - ((u64)(brcmnand_read_reg(ctrl, - BRCMNAND_UNCORR_EXT_ADDR) - & 0xffff) << 32); + *err_addr = brcmnand_get_uncorrecc_addr(ctrl); + if (*err_addr) ret = -EBADMSG; } if (!ret) { - *err_addr = brcmnand_read_reg(ctrl, - BRCMNAND_CORR_ADDR) | - ((u64)(brcmnand_read_reg(ctrl, - BRCMNAND_CORR_EXT_ADDR) - & 0xffff) << 32); + *err_addr = brcmnand_get_correcc_addr(ctrl); + if (*err_addr) ret = -EUCLEAN; } @@ -1711,7 +1741,7 @@ static int brcmnand_read(struct mtd_info *mtd, struct nand_chip *chip, dev_dbg(ctrl->dev, "read %llx -> %p\n", (unsigned long long)addr, buf); try_dmaread: - brcmnand_write_reg(ctrl, BRCMNAND_UNCORR_COUNT, 0); + brcmnand_clear_ecc_addr(ctrl); if (has_flash_dma(ctrl) && !oob && flash_dma_buf_ok(buf)) { err = brcmnand_dma_trans(host, addr, buf, trans * FC_BYTES, @@ -1858,15 +1888,9 @@ static int brcmnand_write(struct mtd_info *mtd, struct nand_chip *chip, goto out; } - brcmnand_write_reg(ctrl, BRCMNAND_CMD_EXT_ADDRESS, - (host->cs << 16) | ((addr >> 32) & 0xffff)); - (void)brcmnand_read_reg(ctrl, BRCMNAND_CMD_EXT_ADDRESS); - for (i = 0; i < trans; i++, addr += FC_BYTES) { /* full address MUST be set before populating FC */ - brcmnand_write_reg(ctrl, BRCMNAND_CMD_ADDRESS, - lower_32_bits(addr)); - (void)brcmnand_read_reg(ctrl, BRCMNAND_CMD_ADDRESS); + brcmnand_set_cmd_addr(mtd, addr); if (buf) { brcmnand_soc_data_bus_prepare(ctrl->soc, false); -- 1.9.0.138.g2de3478