From patchwork Tue Mar 25 08:19:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 26977 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f70.google.com (mail-yh0-f70.google.com [209.85.213.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A374620062 for ; Tue, 25 Mar 2014 08:22:04 +0000 (UTC) Received: by mail-yh0-f70.google.com with SMTP id c41sf308834yho.1 for ; Tue, 25 Mar 2014 01:22:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=O5F7eQ6ipspgAXNAP5a6WuelLCL2Bx/x+HBnsI+B8ro=; b=FZ3JHlmUbgOH+1a2+nb6X1MQ6Y5v34ihkQbPCd0jE+Pnnhys4wc4GNfI/C7OClzH06 6L89fmGfz4XH+cvlXw00xMo0e/HTtT5qHWQGRWbb9Bwd31kN76ltSr4krwvgM/SCbGSo evWzHsYBMbWedGl/WjNpzAXk9EYz9jVuUBzmDwnDUr6Vw6Rt4lWfAM9WUCP4f+9VQfGw 9kpwx1x1mst6g4dITEJNJOCKHS6I9s35yMi+snmfW6Fi/mYeDgwUzTb0Jk2m9JqMDtki 1cDX3Nwxs+NXFmeHYQRq4TGD5KXx/Lb1eMlcbWK6p2Afyck8v0y6WBe4vus1w5/zCoSA vxGA== X-Gm-Message-State: ALoCoQlH2GfG1PumvNWKtlwrK0nPBb5BeW25BQm9yoChZu5fhwfi4ZS8/N1TJnVlcPVG/2REWesy X-Received: by 10.236.29.51 with SMTP id h39mr1664921yha.45.1395735724449; Tue, 25 Mar 2014 01:22:04 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.90.80 with SMTP id w74ls146956qgd.95.gmail; Tue, 25 Mar 2014 01:22:04 -0700 (PDT) X-Received: by 10.220.114.135 with SMTP id e7mr5461263vcq.23.1395735724339; Tue, 25 Mar 2014 01:22:04 -0700 (PDT) Received: from mail-ve0-f178.google.com (mail-ve0-f178.google.com [209.85.128.178]) by mx.google.com with ESMTPS id fi2si3674316vdb.10.2014.03.25.01.22.04 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Mar 2014 01:22:04 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.178 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.178; Received: by mail-ve0-f178.google.com with SMTP id jw12so123712veb.23 for ; Tue, 25 Mar 2014 01:22:04 -0700 (PDT) X-Received: by 10.221.4.66 with SMTP id ob2mr39484vcb.28.1395735724263; Tue, 25 Mar 2014 01:22:04 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.78.9 with SMTP id i9csp285345vck; Tue, 25 Mar 2014 01:22:03 -0700 (PDT) X-Received: by 10.68.4.232 with SMTP id n8mr77586857pbn.114.1395735720865; Tue, 25 Mar 2014 01:22:00 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b5si10889653pbq.233.2014.03.25.01.22.00; Tue, 25 Mar 2014 01:22:00 -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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753364AbaCYIVq (ORCPT + 26 others); Tue, 25 Mar 2014 04:21:46 -0400 Received: from mail-we0-f176.google.com ([74.125.82.176]:41871 "EHLO mail-we0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753285AbaCYIVk (ORCPT ); Tue, 25 Mar 2014 04:21:40 -0400 Received: by mail-we0-f176.google.com with SMTP id x48so76586wes.7 for ; Tue, 25 Mar 2014 01:21:39 -0700 (PDT) X-Received: by 10.180.164.69 with SMTP id yo5mr20904200wib.55.1395735694363; Tue, 25 Mar 2014 01:21:34 -0700 (PDT) Received: from lee--X1.home (host109-148-113-193.range109-148.btcentralplus.com. [109.148.113.193]) by mx.google.com with ESMTPSA id k4sm5567676wib.19.2014.03.25.01.21.32 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Mar 2014 01:21:33 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: lee.jones@linaro.org, kernel@stlinux.com, computersforpeace@gmail.com, linux-mtd@lists.infradead.org, dwmw2@infradead.org, angus.clark@st.com, pekon@ti.com Subject: [RFC 40/47] mtd: nand: stm_nand_bch: MTD erase (BCH) Date: Tue, 25 Mar 2014 08:19:57 +0000 Message-Id: <1395735604-26706-41-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1395735604-26706-1-git-send-email-lee.jones@linaro.org> References: <1395735604-26706-1-git-send-email-lee.jones@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lee.jones@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.178 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Carry out the normal checks, then attempt to erase a given block. Signed-off-by: Lee Jones --- drivers/mtd/nand/stm_nand_bch.c | 85 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/drivers/mtd/nand/stm_nand_bch.c b/drivers/mtd/nand/stm_nand_bch.c index 75c5c9b..55f4a4c 100644 --- a/drivers/mtd/nand/stm_nand_bch.c +++ b/drivers/mtd/nand/stm_nand_bch.c @@ -1218,6 +1218,89 @@ static int flex_do_write_ops(struct nandi_controller *nandi, return 0; } +static int bch_mtd_erase(struct mtd_info *mtd, struct erase_info *instr) +{ + struct nand_chip *chip = mtd->priv; + struct nandi_controller *nandi = chip->priv; + uint64_t block_mask = mtd->erasesize - 1; + uint64_t offs_cached; + loff_t offs = instr->addr; + size_t len = instr->len; + uint8_t status; + int ret; + + dev_dbg(nandi->dev, "%s: 0x%012llx @ 0x%012llx\n", __func__, + (unsigned long long)len, offs); + + if (offs & block_mask) { + dev_err(nandi->dev, + "attempt to erase from non-block-aligned offset\n"); + return -EINVAL; + } + + if (len & block_mask) { + dev_err(nandi->dev, + "attempt to erase non-block-aligned length\n"); + return -EINVAL; + } + + if ((offs + len) > mtd->size) { + dev_err(nandi->dev, "attempt to erase past end of device\n"); + return -EINVAL; + } + + nand_get_device(mtd, FL_ERASING); + instr->fail_addr = MTD_FAIL_ADDR_UNKNOWN; + + if (flex_check_wp(nandi)) { + dev_dbg(nandi->dev, "device is write-protected\n"); + instr->state = MTD_ERASE_FAILED; + goto erase_exit; + } + + /* Offset of block containing cached page */ + offs_cached = ((uint64_t)nandi->cached_page << nandi->page_shift) & + ~block_mask; + + instr->state = MTD_ERASING; + while (len) { + if (mtd_block_isbad(mtd, offs)) { + dev_err(nandi->dev, + "attempt to erase a bad block at 0x%012llx\n", + offs); + instr->state = MTD_ERASE_FAILED; + instr->fail_addr = offs; + goto erase_exit; + } + + if (offs == offs_cached) + nandi->cached_page = -1; + + status = bch_erase_block(nandi, offs); + + if (status & NAND_STATUS_FAIL) { + dev_err(nandi->dev, + "failed to erase block at 0x%012llx\n", offs); + instr->state = MTD_ERASE_FAILED; + instr->fail_addr = offs; + goto erase_exit; + } + + len -= mtd->erasesize; + offs += mtd->erasesize; + } + instr->state = MTD_ERASE_DONE; + + erase_exit: + nand_release_device(mtd); + + ret = instr->state == MTD_ERASE_DONE ? 0 : -EIO; + if (ret == 0) + mtd_erase_callback(instr); + + return ret; +} + static void nandi_dump_bad_blocks(struct nandi_controller *nandi) { int bad_count = 0; @@ -1321,6 +1404,8 @@ static void nandi_set_mtd_defaults(struct nandi_controller *nandi, mtd->oobavail = 0; mtd->subpage_sft = 0; + mtd->_erase = bch_mtd_erase; + mtd->_point = NULL; mtd->_unpoint = NULL; mtd->_lock = NULL;