From patchwork Tue Mar 25 08:19:37 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 26972 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f200.google.com (mail-ie0-f200.google.com [209.85.223.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CBF6820062 for ; Tue, 25 Mar 2014 08:21:21 +0000 (UTC) Received: by mail-ie0-f200.google.com with SMTP id lx4sf420760iec.7 for ; Tue, 25 Mar 2014 01:21:21 -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=Ii6JITGsuEY/rQSSMXFa4SIIgfPMkMu1ozHoYyg+qv0=; b=aCW6x74BRDWrpvyP3SXr/Le61guLRtglWPxqi0FSjshtMZa8R7zeX1j1P0X1zgJAVu qI2Lhnfv06TsiwrbLxqxyDuPRhzjgGiBFUZzoJwKwGcZYwt2KX8RseqzUXfnz2sDxL/L ikL3cfha4QG4NjmiX0RAvfYlLUBAmFVhxFEbvLWR52247Kn+4bp14xUc23y/QZloaXuQ S45GlZAvlgZjQTmRXudXnVHfq3riefgro0+TvDb7Y4Kc3UgAfH7WtmtHJZkUQD3q7Zvn LdlYx99A9gxhPiOszvuT3twWsFkjUVoVXsrKVr0s0WYT9NaEXFMfYOWpQ3ChQ6Lx2kIL dfxg== X-Gm-Message-State: ALoCoQmIyBfESEX/nEbsRY/QzxgsKv8eMrSktlLV3kPrBt5Y+KtEduVVWZRWevSGZSUknEOWF6KT X-Received: by 10.182.194.71 with SMTP id hu7mr14693128obc.37.1395735681253; Tue, 25 Mar 2014 01:21:21 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.109.131 with SMTP id l3ls171593qgf.40.gmail; Tue, 25 Mar 2014 01:21:21 -0700 (PDT) X-Received: by 10.220.92.135 with SMTP id r7mr54431453vcm.11.1395735681151; Tue, 25 Mar 2014 01:21:21 -0700 (PDT) Received: from mail-vc0-f170.google.com (mail-vc0-f170.google.com [209.85.220.170]) by mx.google.com with ESMTPS id bp12si3546626veb.81.2014.03.25.01.21.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Mar 2014 01:21:21 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.170 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.170; Received: by mail-vc0-f170.google.com with SMTP id hu19so130295vcb.15 for ; Tue, 25 Mar 2014 01:21:21 -0700 (PDT) X-Received: by 10.58.154.10 with SMTP id vk10mr54570618veb.18.1395735681082; Tue, 25 Mar 2014 01:21:21 -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 i9csp285292vck; Tue, 25 Mar 2014 01:21:20 -0700 (PDT) X-Received: by 10.68.178.131 with SMTP id cy3mr9216325pbc.146.1395735678641; Tue, 25 Mar 2014 01:21:18 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id td10si11021641pac.263.2014.03.25.01.21.17; Tue, 25 Mar 2014 01:21:18 -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 S1753014AbaCYIVI (ORCPT + 26 others); Tue, 25 Mar 2014 04:21:08 -0400 Received: from mail-we0-f178.google.com ([74.125.82.178]:56943 "EHLO mail-we0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752791AbaCYIU5 (ORCPT ); Tue, 25 Mar 2014 04:20:57 -0400 Received: by mail-we0-f178.google.com with SMTP id u56so76643wes.23 for ; Tue, 25 Mar 2014 01:20:56 -0700 (PDT) X-Received: by 10.180.188.229 with SMTP id gd5mr21319391wic.54.1395735656010; Tue, 25 Mar 2014 01:20:56 -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.20.54 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Mar 2014 01:20:55 -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 20/47] mtd: nand: stm_nand_bch: initialise working buffers Date: Tue, 25 Mar 2014 08:19:37 +0000 Message-Id: <1395735604-26706-21-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.220.170 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: , Initialise working buffers, accomodating DMA alignment constraints. Signed-off-by: Lee Jones --- drivers/mtd/nand/stm_nand_bch.c | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/drivers/mtd/nand/stm_nand_bch.c b/drivers/mtd/nand/stm_nand_bch.c index 351f5e2..fafde22 100644 --- a/drivers/mtd/nand/stm_nand_bch.c +++ b/drivers/mtd/nand/stm_nand_bch.c @@ -31,6 +31,9 @@ /* NANDi BCH Controller properties */ #define NANDI_BCH_SECTOR_SIZE 1024 +#define NANDI_BCH_DMA_ALIGNMENT 64 +#define NANDI_BCH_MAX_BUF_LIST 8 +#define NANDI_BCH_BUF_LIST_SIZE (4 * NANDI_BCH_MAX_BUF_LIST) /* BCH ECC sizes */ static int bch_ecc_sizes[] = { @@ -762,6 +765,44 @@ static void nandi_init_controller(struct nandi_controller *nandi, nandi_init_hamming(nandi, emi_bank); } +/* Initialise working buffers, accomodating DMA alignment constraints */ +static int nandi_init_working_buffers(struct nandi_controller *nandi, + struct nandi_bbt_info *bbt_info, + struct mtd_info *mtd) +{ + uint32_t bbt_buf_size; + uint32_t buf_size; + + /* - Page and OOB */ + buf_size = mtd->writesize + mtd->oobsize + NANDI_BCH_DMA_ALIGNMENT; + + /* - BBT data (page-size aligned) */ + bbt_info->bbt_size = nandi->blocks_per_device >> 2; /* 2 bits/block */ + bbt_buf_size = ALIGN(bbt_info->bbt_size, mtd->writesize); + buf_size += bbt_buf_size + NANDI_BCH_DMA_ALIGNMENT; + + /* - BCH BUF list */ + buf_size += NANDI_BCH_BUF_LIST_SIZE + NANDI_BCH_DMA_ALIGNMENT; + + /* Allocate bufffer */ + nandi->buf = devm_kzalloc(nandi->dev, buf_size, GFP_KERNEL); + if (!nandi->buf) { + dev_err(nandi->dev, "failed to allocate working buffers\n"); + return -ENOMEM; + } + + /* Set/Align buffer pointers */ + nandi->page_buf = PTR_ALIGN(nandi->buf, NANDI_BCH_DMA_ALIGNMENT); + nandi->oob_buf = nandi->page_buf + mtd->writesize; + bbt_info->bbt = PTR_ALIGN(nandi->oob_buf + mtd->oobsize, + NANDI_BCH_DMA_ALIGNMENT); + nandi->buf_list = (uint32_t *)PTR_ALIGN(bbt_info->bbt + bbt_buf_size, + NANDI_BCH_DMA_ALIGNMENT); + nandi->cached_page = -1; + + return 0; +} + static int remap_named_resource(struct platform_device *pdev, char *name, void __iomem **io_ptr) @@ -990,6 +1031,10 @@ static int stm_nand_bch_probe(struct platform_device *pdev) /* Tune BCH programs according to device found and ECC mode */ bch_configure_progs(nandi); + err = nandi_init_working_buffers(nandi, bbt_info, mtd); + if (err) + return err; + return 0; }