Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2497230imm; Wed, 3 Oct 2018 04:59:38 -0700 (PDT) X-Google-Smtp-Source: ACcGV62Snqh1VI05u3cYDDjh/YcZ5KKsPGlRlJZdY7y4YMyk0xjB+G4XHwigqG26IHjVme2SJYar X-Received: by 2002:a63:70e:: with SMTP id 14-v6mr1087063pgh.70.1538567978796; Wed, 03 Oct 2018 04:59:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538567978; cv=none; d=google.com; s=arc-20160816; b=ZzmUl8R9oHv9IpemDHBdwHC8i41fDk8keOFmpZqfSqz5ZtHcDlL7jwVp0+IOlNy18Z Xol2LWis4kgZjVwPYwZhf7dXH8ojAmG8YPn7cGadZSG40Xld9RXn5qGueWilBaTMM/6D ouqpyjZjY3qBmwpscTNcbOHcgjHpUB+o5rJaRkMK9XlycmrlJmCy+jCeBDCvbgxtc97c RStodcnixmSneVi8sRBMuPJXwSLu4IDWy3nJFlI1MUY2lXgiFPjJM+EXVhPGOszFTN6K EnUtE2Mh8A8nVnUP1QVt55fdzmaPq3xgajGRiRDXAxhnKtgEVIN3pOeEB46ZhfhtTpZJ /jNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=FlZqKwjVoeFu/nEuPnA5WnfWrBB8OUWnxD8mhm28kUQ=; b=UyNyaIYi/VnR1OCA/9w1A3633gdrdASM7+Ht0XZBFiKXL9cNrJFI80wa6THuaRng6p aWALraHjvpd/efLKt7jayWwoAC6r9YudOuezz3tO9HvJD9ZTh/Bh5IRfnEX9tmfw2+4V j4oUF1SeQSJ5Zr70jfl7js0SJCm0FYrjmThDh0YM9rED7P794X6JHtUWQAUPzFT7FWox vKRNRb+CxBiy5GhLVrySnG0QjSCj9CtjmMurXtL3U82Dvt4+4Vxswphg0WTMEp1KNbMW uJPsFZnUuxeeKCj6hTNGzEMtuki4o9k+HC1vwXAEu0oZ7+IFawCmM4iwXJBCBjaCGSPV DlMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Q41sJ55Z; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n6-v6si1455280pla.79.2018.10.03.04.59.23; Wed, 03 Oct 2018 04:59:38 -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; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Q41sJ55Z; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726989AbeJCSrO (ORCPT + 99 others); Wed, 3 Oct 2018 14:47:14 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:39859 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726809AbeJCSrO (ORCPT ); Wed, 3 Oct 2018 14:47:14 -0400 Received: by mail-lf1-f65.google.com with SMTP id w21-v6so3917148lff.6 for ; Wed, 03 Oct 2018 04:59:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FlZqKwjVoeFu/nEuPnA5WnfWrBB8OUWnxD8mhm28kUQ=; b=Q41sJ55ZIFpVmf6K5XSH0egwojzvcE6ZsZ3PIBQmODsuDnashWlNFjt4g8x9dsL3HT VunYEtbc/Z2Wo2piS0jjD212n1ttuDwfprb1bmYAmV6gcX6zGJkcFgVQHclN9Ea/C5Xv rNRkgYviNsOKdgzoE+ZhPuovUzRBzRMn8BorxieQKXJ+Ph961kjgIyeHSWl5NkDEToPX sMR26S4+6Blw6uoMQFHeBIJuvXSKDjBMYTFp5aYXHXkANNn8hm/3cNG63FjbwUz9S+VX foEwefumt3m5qkK3Q/drwEKHkAtk/Q/+OwqoSqdLaDfOZfBTZQTCk1afUn/HNGc2wEOk qzWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=FlZqKwjVoeFu/nEuPnA5WnfWrBB8OUWnxD8mhm28kUQ=; b=BV2wnI5Sx1RJYPeCOJrQa7PrwahI3Sf8zvgrHG+vQoWTGjHseb6VsKNx7J9tOneGK5 SpmmsjAjI5UHg2EbYc9K6mc+xCU8Xw4o1r/9tZ0F+elNZIlyZD9hmfPthp/Puy1kWxgg UUWNFbF0aQP4kyZV0jPDTe9tAQxlLnK0+u3kFNZYcc/t/VmScZFww3XszuPHrXjtO3H8 4kxgzC8PIT+ViWIGD8T0ehNG52dSITu+/ZhLz6k/N7nnXIyQs23Qzq9mXkn0mlEtPOF7 Svyr59rRKN/OhrHHaZIaXxer9P8JH8gfLCEI2UcO8ahWIkGRCV+HIInGe/+pILVDwrYv CXDg== X-Gm-Message-State: ABuFfojwaOQJlzuhlfO2pgw2G13PO5l8/aIkEhJ+H71QJD7R1ApQ5v62 I3oDt6WfSvh8AkgqYjjK9rdv8y5W X-Received: by 2002:a19:5118:: with SMTP id f24-v6mr873303lfb.104.1538567946426; Wed, 03 Oct 2018 04:59:06 -0700 (PDT) Received: from z50.intranet (78-10-164-223.static.ip.netia.com.pl. [78.10.164.223]) by smtp.gmail.com with ESMTPSA id j5-v6sm286654lfb.62.2018.10.03.04.59.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Oct 2018 04:59:05 -0700 (PDT) From: Janusz Krzysztofik To: Boris Brezillon , Miquel Raynal Cc: Richard Weinberger , David Woodhouse , Brian Norris , Marek Vasut , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Janusz Krzysztofik Subject: [RFC PATCH] mtd: rawnand: ams-delta: use ->exec_op() Date: Wed, 3 Oct 2018 14:00:28 +0200 Message-Id: <20181003120028.9257-1-jmkrzyszt@gmail.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180719081508.5dafebde@bbrezillon> References: <20180719081508.5dafebde@bbrezillon> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Replace legacy callbacks with ->select_chip() and ->exec_op(). Implementation of NAND_OP_WAITRDY_INSTR has been based on legacy nand_wait_ready(), otherwise that function would probabaly have to be reimplemented inside the driver. Hence, legacy callback ->dev_ready() is still used. Use of IO_ADDR_R and IO_ADDR_W legacy structure members will be dropped later, as soon as the driver is converted to use GPIO API for data I/O. Suggested-by: Boris Brezillon Signed-off-by: Janusz Krzysztofik --- Hi, I've not tested the change on hardware yet as I'm not sure if: - handling of NCE limited to that inside ->select_chip() is sufficient, - releasing ALE / CLE immediately after ams_delta_write_buf() is correct. Please advise before I break my test hardware :-). Thanks, Janusz drivers/mtd/nand/raw/ams-delta.c | 83 +++++++++++++++++++++++++--------------- 1 file changed, 52 insertions(+), 31 deletions(-) diff --git a/drivers/mtd/nand/raw/ams-delta.c b/drivers/mtd/nand/raw/ams-delta.c index 5ba180a291eb..90c283a2c1b7 100644 --- a/drivers/mtd/nand/raw/ams-delta.c +++ b/drivers/mtd/nand/raw/ams-delta.c @@ -124,46 +124,69 @@ static void ams_delta_read_buf(struct nand_chip *this, u_char *buf, int len) buf[i] = ams_delta_io_read(priv); } -static u_char ams_delta_read_byte(struct nand_chip *this) +static int ams_delta_nand_ready(struct nand_chip *this) { - u_char res; - - ams_delta_read_buf(this, &res, 1); + struct ams_delta_nand *priv = nand_get_controller_data(this); - return res; + return gpiod_get_value(priv->gpiod_rdy); } -/* - * Command control function - * - * ctrl: - * NAND_NCE: bit 0 -> bit 2 - * NAND_CLE: bit 1 -> bit 7 - * NAND_ALE: bit 2 -> bit 6 - */ -static void ams_delta_hwcontrol(struct nand_chip *this, int cmd, - unsigned int ctrl) +static void ams_delta_select_chip(struct nand_chip *this, int n) { struct ams_delta_nand *priv = nand_get_controller_data(this); - if (ctrl & NAND_CTRL_CHANGE) { - gpiod_set_value(priv->gpiod_nce, !(ctrl & NAND_NCE)); - gpiod_set_value(priv->gpiod_cle, !!(ctrl & NAND_CLE)); - gpiod_set_value(priv->gpiod_ale, !!(ctrl & NAND_ALE)); - } - - if (cmd != NAND_CMD_NONE) { - u_char byte = cmd; + if (n > 0) + return; - ams_delta_write_buf(this, &byte, 1); - } + gpiod_set_value(priv->gpiod_nce, n < 0); } -static int ams_delta_nand_ready(struct nand_chip *this) +static int ams_delta_exec_op(struct nand_chip *this, + const struct nand_operation *op, bool check_only) { struct ams_delta_nand *priv = nand_get_controller_data(this); + const struct nand_op_instr *instr; + int i; - return gpiod_get_value(priv->gpiod_rdy); + for (i = 0; i < op->ninstrs; i++) { + instr = &op->instrs[i]; + + switch (instr->type) { + case NAND_OP_CMD_INSTR: + gpiod_set_value(priv->gpiod_cle, 1); + ams_delta_write_buf(this, &instr->ctx.cmd.opcode, 1); + gpiod_set_value(priv->gpiod_cle, 0); + break; + + case NAND_OP_ADDR_INSTR: + gpiod_set_value(priv->gpiod_ale, 1); + ams_delta_write_buf(this, instr->ctx.addr.addrs, + instr->ctx.addr.naddrs); + gpiod_set_value(priv->gpiod_ale, 0); + break; + + case NAND_OP_DATA_IN_INSTR: + ams_delta_read_buf(this, instr->ctx.data.buf.in, + instr->ctx.data.len); + break; + + case NAND_OP_DATA_OUT_INSTR: + ams_delta_write_buf(this, instr->ctx.data.buf.out, + instr->ctx.data.len); + break; + + case NAND_OP_WAITRDY_INSTR: + if (this->legacy.dev_ready) { + nand_wait_ready(this); + break; + } + + return nand_soft_waitrdy(this, + instr->ctx.waitrdy.timeout_ms); + } + } + + return 0; } @@ -213,10 +236,8 @@ static int ams_delta_init(struct platform_device *pdev) /* Set address of NAND IO lines */ this->legacy.IO_ADDR_R = io_base + OMAP_MPUIO_INPUT_LATCH; this->legacy.IO_ADDR_W = io_base + OMAP_MPUIO_OUTPUT; - this->legacy.read_byte = ams_delta_read_byte; - this->legacy.write_buf = ams_delta_write_buf; - this->legacy.read_buf = ams_delta_read_buf; - this->legacy.cmd_ctrl = ams_delta_hwcontrol; + this->select_chip = ams_delta_select_chip; + this->exec_op = ams_delta_exec_op; priv->gpiod_rdy = devm_gpiod_get_optional(&pdev->dev, "rdy", GPIOD_IN); if (IS_ERR(priv->gpiod_rdy)) { -- 2.16.4