From patchwork Tue Mar 25 08:20:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 26986 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f199.google.com (mail-ob0-f199.google.com [209.85.214.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D526020062 for ; Tue, 25 Mar 2014 08:24:27 +0000 (UTC) Received: by mail-ob0-f199.google.com with SMTP id wo20sf499533obc.10 for ; Tue, 25 Mar 2014 01:24:27 -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=G7VoS/IxG8HlOTfW+0Hdwnui8yggFEEYJ5Hrd7Viung=; b=aGAh80NIZTz/UoTwNrxE4ALB2OQzu0llVomN3swPncZqazR7uV2WOwNJYI8SCSYA10 aCzWVpVBwXE/6XezT3g9+KfDXqczmadt91cDqvvst1NLCkJgo/ZwP9MfaEvI8tZBFmCr 64RhGMITI0InMPMPvuvitxLkxPfxVXRZHl3VgR5vn0XGQOOgOT/qG+qU+oA2BmxtxneU SxQGJReu5lVAs5KH6gtlWUx3zeN1jAfoTuvN4juaSUnunjOf7f2maaSD2432sDeamkyr ASC/NgrlkrGhN8PbDRPvGv4PumzyKAG9kjVLs0Ts9/DEtRBFbYntcVtzbH887CI3wwj0 pRoA== X-Gm-Message-State: ALoCoQmgGe16tjwSa9rqW/KEifA2mxGNDusgASM86zYFBYmZgRWIFnKEKd9Mwy9PKJ7Uuu+IR8fV X-Received: by 10.50.47.6 with SMTP id z6mr7412961igm.4.1395735867417; Tue, 25 Mar 2014 01:24:27 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.16.73 with SMTP id 67ls134058qga.18.gmail; Tue, 25 Mar 2014 01:24:27 -0700 (PDT) X-Received: by 10.52.18.70 with SMTP id u6mr46925962vdd.11.1395735867277; Tue, 25 Mar 2014 01:24:27 -0700 (PDT) Received: from mail-ve0-f170.google.com (mail-ve0-f170.google.com [209.85.128.170]) by mx.google.com with ESMTPS id kp12si3590418veb.12.2014.03.25.01.24.27 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Mar 2014 01:24:27 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.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.128.170; Received: by mail-ve0-f170.google.com with SMTP id pa12so133845veb.15 for ; Tue, 25 Mar 2014 01:24:27 -0700 (PDT) X-Received: by 10.52.164.237 with SMTP id yt13mr23930572vdb.18.1395735867201; Tue, 25 Mar 2014 01:24:27 -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 i9csp285459vck; Tue, 25 Mar 2014 01:24:26 -0700 (PDT) X-Received: by 10.66.189.226 with SMTP id gl2mr77721164pac.65.1395735865784; Tue, 25 Mar 2014 01:24:25 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id yo5si11018242pab.292.2014.03.25.01.24.24; Tue, 25 Mar 2014 01:24:24 -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 S1753512AbaCYIYM (ORCPT + 26 others); Tue, 25 Mar 2014 04:24:12 -0400 Received: from mail-wi0-f181.google.com ([209.85.212.181]:62451 "EHLO mail-wi0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753296AbaCYIVn (ORCPT ); Tue, 25 Mar 2014 04:21:43 -0400 Received: by mail-wi0-f181.google.com with SMTP id hm4so342874wib.2 for ; Tue, 25 Mar 2014 01:21:42 -0700 (PDT) X-Received: by 10.181.13.15 with SMTP id eu15mr20287967wid.38.1395735702612; Tue, 25 Mar 2014 01:21:42 -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.40 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Mar 2014 01:21:41 -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 44/47] mtd: nand: stm_nand_bch: MTD read and write (BCH) Date: Tue, 25 Mar 2014 08:20:01 +0000 Message-Id: <1395735604-26706-45-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.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: , MTD interfaces: Standard set of callbacks for MTD functionality. Signed-off-by: Lee Jones --- drivers/mtd/nand/stm_nand_bch.c | 54 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/drivers/mtd/nand/stm_nand_bch.c b/drivers/mtd/nand/stm_nand_bch.c index bcaed32..f5b0a00 100644 --- a/drivers/mtd/nand/stm_nand_bch.c +++ b/drivers/mtd/nand/stm_nand_bch.c @@ -1226,6 +1226,58 @@ static int bch_load_bbt(struct nandi_controller *nandi, } /* + * MTD Interface: Standard set of callbacks for MTD functionality + */ +static int bch_mtd_read(struct mtd_info *mtd, loff_t from, size_t len, + size_t *retlen, uint8_t *buf) +{ + struct nand_chip *chip = mtd->priv; + struct nandi_controller *nandi = chip->priv; + int ret; + + dev_dbg(nandi->dev, "%s: %llu @ 0x%012llx\n", __func__, + (unsigned long long)len, from); + + nand_get_device(mtd, FL_READING); + + ret = bch_read(nandi, from, len, retlen, buf); + + nand_release_device(mtd); + + return ret; +} + +static int bch_mtd_write(struct mtd_info *mtd, loff_t to, size_t len, + size_t *retlen, const uint8_t *buf) +{ + struct nand_chip *chip = mtd->priv; + struct nandi_controller *nandi = chip->priv; + uint32_t page_mask = mtd->writesize - 1; + int ret; + + dev_dbg(nandi->dev, "%s: %llu @ 0x%012llx\n", __func__, + (unsigned long long)len, to); + + if ((to & page_mask) || (len & page_mask)) { + dev_err(nandi->dev, "attempt to write non-page-aligned data\n"); + return -EINVAL; + } + + nand_get_device(mtd, FL_WRITING); + + if (flex_check_wp(nandi)) { + dev_dbg(nandi->dev, "device is write-protected\n"); + return -EIO; + } + + ret = bch_write(nandi, to, len, retlen, buf); + + nand_release_device(mtd); + + return ret; +} + +/* * Helper function for mtd_read_oob(): handles multi-page transfers * and mapping between BCH sectors and MTD page+OOB data. */ @@ -1701,6 +1753,8 @@ static void nandi_set_mtd_defaults(struct nandi_controller *nandi, mtd->oobavail = 0; mtd->subpage_sft = 0; + mtd->_read = bch_mtd_read; + mtd->_write = bch_mtd_write; mtd->_erase = bch_mtd_erase; mtd->_read_oob = bch_mtd_read_oob; mtd->_write_oob = bch_mtd_write_oob;