From patchwork Thu May 1 09:56:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 29464 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f197.google.com (mail-vc0-f197.google.com [209.85.220.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 37501203F3 for ; Thu, 1 May 2014 09:57:52 +0000 (UTC) Received: by mail-vc0-f197.google.com with SMTP id if11sf2694950vcb.4 for ; Thu, 01 May 2014 02:57:52 -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=Fof0r46ensgydb64DEZuamNtxrzc0TL3PA5QXf10d70=; b=lFcRqokRZD9jXrXJRKQxjIotD9kNg+f4MyXYgc6lQsK9Aqgi+c6im6Z1QOI05ic+VX MZEOqbWyhfMAVMnXdgxm4XObO0mstz8948eU9Y0lBloSaA1v1Q4hWVROn0WiAycOp41c DYDlPPilnCvXftIX1pQiHVu7hlzivLQ8SWUYWJTWsvSbakgqknWzy3gAy4lpebB9xXPb WJ3qaCgxL5BF66qXR50ig4NT3dAQfKxyAFeqNf0Zh3j5+SjMO8zM9mJWSrBR+8kWgaZd ksMsqxnMT13w2rRCFP4W4FOkVh9n6kFcX8g3syMZHcCLyEEfeGRV3jkn00ZHWYbyOILg ceTg== X-Gm-Message-State: ALoCoQmDZWsq8l5t1CdOJTFvFZVw50Yl1SttrVElWc5R9U0tUTdNxoYOL85k7n7SYaPF5qeIfuBV X-Received: by 10.236.88.210 with SMTP id a58mr4720779yhf.50.1398938271995; Thu, 01 May 2014 02:57:51 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.35.210 with SMTP id n76ls1069085qgn.15.gmail; Thu, 01 May 2014 02:57:51 -0700 (PDT) X-Received: by 10.58.116.175 with SMTP id jx15mr2098589veb.9.1398938271837; Thu, 01 May 2014 02:57:51 -0700 (PDT) Received: from mail-ve0-f169.google.com (mail-ve0-f169.google.com [209.85.128.169]) by mx.google.com with ESMTPS id ui2si5953659vdc.100.2014.05.01.02.57.51 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:57:51 -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.169; Received: by mail-ve0-f169.google.com with SMTP id jx11so3693547veb.0 for ; Thu, 01 May 2014 02:57:51 -0700 (PDT) X-Received: by 10.52.255.99 with SMTP id ap3mr6742933vdd.19.1398938271761; Thu, 01 May 2014 02:57:51 -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 ib8csp12930vcb; Thu, 1 May 2014 02:57:51 -0700 (PDT) X-Received: by 10.180.82.133 with SMTP id i5mr1530551wiy.50.1398938270805; Thu, 01 May 2014 02:57:50 -0700 (PDT) Received: from mail-we0-f177.google.com (mail-we0-f177.google.com [74.125.82.177]) by mx.google.com with ESMTPS id e6si566482wiy.107.2014.05.01.02.57.50 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:57:50 -0700 (PDT) Received-SPF: none (google.com: lee.jones@linaro.org does not designate permitted sender hosts) client-ip=74.125.82.177; Received: by mail-we0-f177.google.com with SMTP id t60so2787744wes.8 for ; Thu, 01 May 2014 02:57:50 -0700 (PDT) X-Received: by 10.180.74.242 with SMTP id x18mr1553679wiv.20.1398938270312; Thu, 01 May 2014 02:57:50 -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.48 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:57:48 -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 21/47] mtd: nand: stm_nand_bch: initialise working buffers Date: Thu, 1 May 2014 10:56:28 +0100 Message-Id: <1398938214-17847-22-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: , 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 cf57b90..5be7889 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[] = { @@ -920,6 +923,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) @@ -1140,6 +1181,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; }