Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp4317378imm; Mon, 15 Oct 2018 12:40:50 -0700 (PDT) X-Google-Smtp-Source: ACcGV62Do9uT6GnA7k7rlosw4nHgY/Vmh12qh+zUZiH6NbKJhnf3+LXxXklX9l9S6zAohNwDw1Kk X-Received: by 2002:aa7:86cc:: with SMTP id h12-v6mr18532193pfo.58.1539632450620; Mon, 15 Oct 2018 12:40:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539632450; cv=none; d=google.com; s=arc-20160816; b=cLMRICs/eTN//+FIP1UZrBQLMLS8tyZiSYrWI0DXkLRLS77Ax8lZWtNUfk5maySlnt 2xE1CWwPIHA9bNM3TpRWoFfBxGaJVfLkaTU9nDuG6cY3n1AGLx0ua07K+aIr6gwm5OYP GuU2vvOWcmrACF1TnQFoW+k3Hrps77LghDyMJ9cgwtruoxP/tdYQRq9YNJc2clSebia0 owdrUkVwTk89Iyzjr35+Z2hfb3HJaBF4c7iOQcvqmCNoAk7X5mukCoQMUoDobUb+F3GA DL/OiFlMGx4Tb+9LPBhWr4Cfv1JoT2ur5zF4v+8REzzNlTKOobamvDawiGDJjHgmfcUJ jtJw== 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=gpAxKCJHhJjj+lN8WLPl+rXChbbfElVUx5p01InmYQs=; b=ZuLT3GBOFOZG9ajO5lTvvEDtwUFbfiSazYYmOPbmwuDymKuCoT5YP/xM4NlrSgDkwH Ll43oORBdo3nEpi5ZozVgpIdJtZtpO1RHU89DeXxlGdN8/YZ9kZdmTVD/WfcJJsnnnOR TpMJ+eNG0m3Q/w3WIxbJdawj4d6/BFfPvyQQeJAiWniyRptkqzyFi2FH3p+Od9RPob77 EL9NzLJFrmmnMSIsx6Sfm0dPEp6AHxwj/O3EieVmvGSmsbe5HYdDaOJkT4hvVDpFY3v+ zbTH5TxnAwtgBBp85uD7lSGrRbkrkqHiGvrDTvsejQJHmIYur4KfXnC2PgmoqUS3PJZa fvUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MYHurD4X; 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 r134-v6si11629524pgr.252.2018.10.15.12.40.35; Mon, 15 Oct 2018 12:40:50 -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=MYHurD4X; 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 S1727023AbeJPD0s (ORCPT + 99 others); Mon, 15 Oct 2018 23:26:48 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:36076 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726713AbeJPD0r (ORCPT ); Mon, 15 Oct 2018 23:26:47 -0400 Received: by mail-lj1-f195.google.com with SMTP id p89-v6so18624425ljb.3 for ; Mon, 15 Oct 2018 12:40: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=gpAxKCJHhJjj+lN8WLPl+rXChbbfElVUx5p01InmYQs=; b=MYHurD4Xkb1B7L+kxZUVQlsP5PUnaB9kLusgTgCH1UuMUclt5SPa5GMyRQPNqgsetc Vy6Nmdc3/kIyXTJuh3wfBO6ruqDTO7N69jL2JQ0+XCVyHt4Vo0AB2E0jv8HKv+Cm4msB xiLCST16guNCVuQLzxW1zLxFTiYcOpzac9kAdp5lG4emuPzUpmeCZ3URzlTtcS3FZw3L /g0zo9ub/DLTELFMm2P1YP0ZWsGGZYTgel6sclAL4/ZxaTlm9jv6UkNOZmc9a5/PJbQ0 pZGhPE0S7XUf02kpuIqmOmJmbPruGz7XZjYECqcTkhC627Umt1nmKhepFHQvXBOP9oEt 6IAA== 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=gpAxKCJHhJjj+lN8WLPl+rXChbbfElVUx5p01InmYQs=; b=lAXCep81te2r0g1/lTL5/qTq2hyIjIGkS5dSZzNu4q58wAU3EPG71HGv3qmyvnCKbR nI/GIXZiJqroF4AWm7oZ2j1E+6IYoqPxAYKWS1n2Huq2GW9l3N+RSMlZVWi7ag05u0Kj 7XROF/IyVGZWpULRo19oc+fMQv1Qn0PcnIHRhER84EFT9rVmnTQb+oiQFjxzr0dW+u4H kMD2oDIWL2GT+/c+SWECrTmgqDgex3bD3e16gOAnOZUac2YEvBBlcmUOLbvvrMhE4/AM oH3YDbyx714nxuVmhCAn88gk9yBVmOVVZmj0oJ4PocdD98ojwU2jcVnRiATi/i19X0c7 OQ2Q== X-Gm-Message-State: ABuFfojafaDM/Hbsofs1101haGIG0iNk6mtdAvzyK0d/w7SBHGBF5rjW n9IhKBJL9QMwaesrIrPLShu9CgZXVLo= X-Received: by 2002:a2e:8797:: with SMTP id n23-v6mr11701628lji.173.1539632406519; Mon, 15 Oct 2018 12:40:06 -0700 (PDT) Received: from z50.lan (93-181-165-181.internetia.net.pl. [93.181.165.181]) by smtp.gmail.com with ESMTPSA id l3-v6sm2658830lji.60.2018.10.15.12.40.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 12:40: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: [PATCH v3 3/3] mtd: rawnand: ams-delta: Convert the driver to ->exec_op() Date: Mon, 15 Oct 2018 21:41:30 +0200 Message-Id: <20181015194130.21764-3-jmkrzyszt@gmail.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20181015194130.21764-1-jmkrzyszt@gmail.com> References: <20181012204101.26274-1-jmkrzyszt@gmail.com> <20181015194130.21764-1-jmkrzyszt@gmail.com> 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(). Suggested-by: Boris Brezillon Signed-off-by: Janusz Krzysztofik Reviewed-by: Boris Brezillon --- Changelog: v3: - former PATCH 2/2 from which PATCH v3 2/3 has been split out, - added missing return on check_only - requested by Boris Brezillon, thanks v2: - replace references to legacy structure .IO_ADDR_R/W members with runtime calculated values - requested by Boris Brezillon, thanks! - modify ams_delta_read/write_buf() functions, no longer exposed as callbacks, to accept driver private structure instead of struct nand_chip, - use newly introduced nand_gpio_waitrdy() helper instead of legacy nand_wait_ready() - suggested by Boris Brezillon, thanks! - remove no longer needed ams_delta_dev_ready() legacy callback and legacy structure member .chip_delay. drivers/mtd/nand/raw/ams-delta.c | 100 ++++++++++++++++++++++----------------- 1 file changed, 56 insertions(+), 44 deletions(-) diff --git a/drivers/mtd/nand/raw/ams-delta.c b/drivers/mtd/nand/raw/ams-delta.c index 46193db6d368..9ca70aab199d 100644 --- a/drivers/mtd/nand/raw/ams-delta.c +++ b/drivers/mtd/nand/raw/ams-delta.c @@ -99,10 +99,9 @@ static void ams_delta_dir_input(struct ams_delta_nand *priv, bool in) priv->data_in = in; } -static void ams_delta_write_buf(struct nand_chip *this, const u_char *buf, +static void ams_delta_write_buf(struct ams_delta_nand *priv, const u_char *buf, int len) { - struct ams_delta_nand *priv = nand_get_controller_data(this); int i; if (priv->data_in) @@ -112,9 +111,9 @@ static void ams_delta_write_buf(struct nand_chip *this, const u_char *buf, ams_delta_io_write(priv, buf[i]); } -static void ams_delta_read_buf(struct nand_chip *this, u_char *buf, int len) +static void ams_delta_read_buf(struct ams_delta_nand *priv, u_char *buf, + int len) { - struct ams_delta_nand *priv = nand_get_controller_data(this); int i; if (!priv->data_in) @@ -124,46 +123,66 @@ 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) -{ - u_char res; - - ams_delta_read_buf(this, &res, 1); - - return res; -} - -/* - * 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 ret = 0; + + if (check_only) + return 0; + + for (instr = op->instrs; instr < op->instrs + op->ninstrs; instr++) { + + switch (instr->type) { + case NAND_OP_CMD_INSTR: + gpiod_set_value(priv->gpiod_cle, 1); + ams_delta_write_buf(priv, &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(priv, 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(priv, instr->ctx.data.buf.in, + instr->ctx.data.len); + break; + + case NAND_OP_DATA_OUT_INSTR: + ams_delta_write_buf(priv, instr->ctx.data.buf.out, + instr->ctx.data.len); + break; + + case NAND_OP_WAITRDY_INSTR: + ret = priv->gpiod_rdy ? + nand_gpio_waitrdy(this, priv->gpiod_rdy, + instr->ctx.waitrdy.timeout_ms) : + nand_soft_waitrdy(this, + instr->ctx.waitrdy.timeout_ms); + break; + } + + if (ret) + break; + } - return gpiod_get_value(priv->gpiod_rdy); + return ret; } @@ -211,10 +230,8 @@ static int ams_delta_init(struct platform_device *pdev) nand_set_controller_data(this, priv); /* Set address of NAND IO lines */ - 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)) { @@ -223,11 +240,6 @@ static int ams_delta_init(struct platform_device *pdev) goto out_mtd; } - if (priv->gpiod_rdy) - this->legacy.dev_ready = ams_delta_nand_ready; - - /* 25 us command delay time */ - this->legacy.chip_delay = 30; this->ecc.mode = NAND_ECC_SOFT; this->ecc.algo = NAND_ECC_HAMMING; -- 2.16.4