From patchwork Thu May 1 09:56:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 29469 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 E1E37203F3 for ; Thu, 1 May 2014 09:58:03 +0000 (UTC) Received: by mail-yh0-f70.google.com with SMTP id a41sf1837620yho.1 for ; Thu, 01 May 2014 02:58:03 -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:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=KEL0iruXfMAASshOU3QG6z0L/M9PCnpy+9w73Hc/Uas=; b=bpx72i5Ix1SKovAdrdDkPwJ39YyN6Z7oeGaYjO0Z/oPyVC70YkNonIovEovg6xc0W+ fKpRvAvcnOykmt0bPyr9LdAdTv55eVd6e2lN+6JRZGY+j8q92T09/oAortNRRqm5MF9b vB7DyZXA/21JzCyN+2dzzt3YbzQYWywMn/mTSOvFnlfBuPLZpRxgc1Jo9GdPcbSQKhV1 Q8NodSFAEhL2uMQZ9U7Zb5r7i6vzZ34C+9+xNxbpxoayX72dHLFQDieH3J9A4QyUvqB8 EFuV/0yUapwsSNWsPppXw7ufRf4DuCkPC5dBHc6apIUsygvf+vwhjD4ojTOupOJr3EDE RK0Q== X-Gm-Message-State: ALoCoQlXCMIXSRKrJHNVPlBY2iQe9nxOxGDW3P5Lu7BVTzyIkI8AaTtaVyMY9MDzFA4Ld+c7WuxQ X-Received: by 10.236.92.204 with SMTP id j52mr4660373yhf.26.1398938283632; Thu, 01 May 2014 02:58:03 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.105.54 with SMTP id b51ls1051950qgf.48.gmail; Thu, 01 May 2014 02:58:03 -0700 (PDT) X-Received: by 10.52.72.138 with SMTP id d10mr2570496vdv.15.1398938283490; Thu, 01 May 2014 02:58:03 -0700 (PDT) Received: from mail-ve0-f174.google.com (mail-ve0-f174.google.com [209.85.128.174]) by mx.google.com with ESMTPS id c6si5974344veo.0.2014.05.01.02.58.03 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:58:03 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.128.174; Received: by mail-ve0-f174.google.com with SMTP id oz11so3568430veb.5 for ; Thu, 01 May 2014 02:58:03 -0700 (PDT) X-Received: by 10.221.74.200 with SMTP id yx8mr8061913vcb.3.1398938283432; Thu, 01 May 2014 02:58:03 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp12944vcb; Thu, 1 May 2014 02:58:02 -0700 (PDT) X-Received: by 10.194.92.7 with SMTP id ci7mr8321316wjb.7.1398938282244; Thu, 01 May 2014 02:58:02 -0700 (PDT) Received: from mail-wi0-f180.google.com (mail-wi0-f180.google.com [209.85.212.180]) by mx.google.com with ESMTPS id mu10si577068wib.49.2014.05.01.02.58.01 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:58:02 -0700 (PDT) Received-SPF: none (google.com: lee.jones@linaro.org does not designate permitted sender hosts) client-ip=209.85.212.180; Received: by mail-wi0-f180.google.com with SMTP id hi2so402443wib.13 for ; Thu, 01 May 2014 02:58:01 -0700 (PDT) X-Received: by 10.180.85.134 with SMTP id h6mr1528599wiz.44.1398938281694; Thu, 01 May 2014 02:58:01 -0700 (PDT) Received: from lee--X1.home (host109-148-238-223.range109-148.btcentralplus.com. [109.148.238.223]) by mx.google.com with ESMTPSA id bj5sm2696494wib.3.2014.05.01.02.57.59 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:58:00 -0700 (PDT) From: Lee Jones To: linux-kernel@vger.kernel.org Cc: computersforpeace@gmail.com, linux-mtd@lists.infradead.org, kernel@stlinux.com, Lee Jones Subject: [PATCH 26/47] mtd: nand: stm_nand_bch: provide write functionality (BCH) Date: Thu, 1 May 2014 10:56:33 +0100 Message-Id: <1398938214-17847-27-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1398938214-17847-1-git-send-email-lee.jones@linaro.org> References: <1398938214-17847-1-git-send-email-lee.jones@linaro.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: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Use DMA to write a single page of data. Signed-off-by: Lee Jones --- drivers/mtd/nand/stm_nand_bch.c | 76 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/drivers/mtd/nand/stm_nand_bch.c b/drivers/mtd/nand/stm_nand_bch.c index 72c9734..e875446 100644 --- a/drivers/mtd/nand/stm_nand_bch.c +++ b/drivers/mtd/nand/stm_nand_bch.c @@ -606,6 +606,81 @@ static int bch_read(struct mtd_info *mtd, struct nand_chip *chip, return ret; } +/* Returns the status of the NAND device following the write operation */ +static uint8_t bch_write_page(struct nandi_controller *nandi, + loff_t offs, const uint8_t *buf) +{ + struct bch_prog *prog = &bch_prog_write_page; + uint32_t page_size = nandi->info.mtd.writesize; + uint8_t *p = (uint8_t *)buf; + unsigned long list_phys; + unsigned long buf_phys; + uint8_t status; + bool bounce = false; + + dev_dbg(nandi->dev, "%s: offs = 0x%012llx\n", __func__, offs); + + BUG_ON(offs & (page_size - 1)); + + if (((unsigned long)buf & (NANDI_BCH_DMA_ALIGNMENT - 1)) || + !virt_addr_valid(buf)) { /* vmalloc'd buffer! */ + bounce = true; + } + + if (bounce) { + memcpy(nandi->page_buf, buf, page_size); + p = nandi->page_buf; + nandi->cached_page = -1; + } + + emiss_nandi_select(STM_NANDI_BCH); + + nandi_enable_interrupts(nandi, NANDBCH_INT_SEQNODESOVER); + reinit_completion(&nandi->seq_completed); + + prog->addr = (uint32_t)((offs >> (nandi->page_shift - 8)) & 0xffffff00); + + buf_phys = dma_map_single(NULL, p, page_size, DMA_TO_DEVICE); + memset(nandi->buf_list, 0x00, NANDI_BCH_BUF_LIST_SIZE); + nandi->buf_list[0] = buf_phys | (nandi->sectors_per_page - 1); + + list_phys = dma_map_single(NULL, nandi->buf_list, + NANDI_BCH_BUF_LIST_SIZE, DMA_TO_DEVICE); + + writel(list_phys, nandi->base + NANDBCH_BUFFER_LIST_PTR); + + bch_load_prog_cpu(nandi, prog); + + bch_wait_seq(nandi); + + nandi_disable_interrupts(nandi, NANDBCH_INT_SEQNODESOVER); + + dma_unmap_single(NULL, list_phys, NANDI_BCH_BUF_LIST_SIZE, + DMA_TO_DEVICE); + dma_unmap_single(NULL, buf_phys, page_size, DMA_FROM_DEVICE); + + status = (uint8_t)(readl(nandi->base + + NANDBCH_CHECK_STATUS_REG_A) & 0xff); + + return status; +} + +static int bch_write(struct mtd_info *mtd, struct nand_chip *chip, + uint32_t offset, int data_len, const uint8_t *buf, + int oob_required, int page, int cached, int raw) +{ + struct nandi_controller *nandi = chip->priv; + uint32_t page_size = mtd->writesize; + loff_t offs = page * page_size; + int ret; + + ret = bch_write_page(nandi, offs, buf); + if (ret & NAND_STATUS_FAIL) + return -EIO; + + return 0; +} + /* * Initialisation */ @@ -686,6 +761,7 @@ static void nandi_set_mtd_defaults(struct nandi_controller *nandi, mtd->subpage_sft = 0; chip->ecc.read_page = bch_read; + chip->write_page = bch_write; } /*