Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1140209yba; Sun, 14 Apr 2019 01:37:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqyS/oo8MvOckJKobsN9jbC8Vy1IBFMeQrEP/cr1/UcJ50QIMECBl5f682aDbMzuJ2sbgXYH X-Received: by 2002:a17:902:9a85:: with SMTP id w5mr26116762plp.157.1555231052679; Sun, 14 Apr 2019 01:37:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555231052; cv=none; d=google.com; s=arc-20160816; b=K0Y3LPmVMTW0vd8BmsWYRVcfBd2eqO/C2mYR1oHVWSyEGwlRqU0xWzRGeuvvw45oEQ VhC3oeKyhAbyDGsbp7kokF4ylvRigaIE5/Pt2MPzDDv1ZD+NulWP2g/B8UUdsJHHB6EZ jwJEL4SCrBNdu4f3OBPyMPY0MVvYQgJtvoB0pxa8XJM2cfTn1zFs6XQQWgKaam4DyoJd i2QEnluRRWEfjrYLQts9dLChNXg6UbLSzdvPJBtIVhd//mWJF7svIgRqcsXorgoYgG3h x6wUPAeix1KPOVa+JVZkG430E+nPY0KLtSKGSuFT1NV737p+00NnAoBHQQI+T9QtS7wy FozA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=+Lhs0L0CGv2iEdNkRTm6tNpInA1lF6wZpXPCKMsHW0s=; b=R/rqKg1ciEuUjQjVQnM+8q8Mbok7fKz9soCXW93s7PH99OQ5NTM4gHiEdbAnuQxkai UtXG1l43rg5zQUH90jb39WDvZk5nXyOBnpC0s8KzSxQwZlJs0VEoD2wZ+r7RvRS/PFnZ uqRh/VOjT0SsbmEqeIuRLkZ7cFc9jYSkLO3jLD4+jLuOfzcQhuDetKR2KyTxmgkgI/hq szfmVIzC7sE9ZUc1Glo7OI82T5pioMLENGwiqwInr/meSLTx7ePh5yToKK54pQj7oAMV U685bWasVxFBugAUtB0Whk1maov1MkV+0lqKzQVQ1AITWjMOfpJKKTpNvLfjOHSHIweF uEMA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z8si39510654pgp.185.2019.04.14.01.37.16; Sun, 14 Apr 2019 01:37:32 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726305AbfDNIgO (ORCPT + 99 others); Sun, 14 Apr 2019 04:36:14 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:40854 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725768AbfDNIgN (ORCPT ); Sun, 14 Apr 2019 04:36:13 -0400 Received: from localhost (unknown [IPv6:2a01:e0a:2c:6930:5cf4:84a1:2763:fe0d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: bbrezillon) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id B2304263959; Sun, 14 Apr 2019 09:36:11 +0100 (BST) Date: Sun, 14 Apr 2019 10:36:08 +0200 From: Boris Brezillon To: Richard Weinberger Cc: linux-mtd@lists.infradead.org, bbrezillon@kernel.org, linux-kernel@vger.kernel.org, marek.vasut@gmail.com, miquel.raynal@bootlin.com, computersforpeace@gmail.com, dwmw2@infradead.org Subject: Re: [PATCH 2/2] mtd: nandsim: switch to exec_op interface Message-ID: <20190414103608.257bd8b9@collabora.com> In-Reply-To: <20190413084052.15416-2-richard@nod.at> References: <20190413084052.15416-1-richard@nod.at> <20190413084052.15416-2-richard@nod.at> Organization: Collabora X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 13 Apr 2019 10:40:52 +0200 Richard Weinberger wrote: > Stop using the legacy interface. Thanks for converting the nandsim driver. > > Signed-off-by: Richard Weinberger > --- > drivers/mtd/nand/raw/nandsim.c | 78 ++++++++++++++++++++-------------- > 1 file changed, 47 insertions(+), 31 deletions(-) > > diff --git a/drivers/mtd/nand/raw/nandsim.c b/drivers/mtd/nand/raw/nandsim.c > index 3d80e2d23b6e..33c369f9a607 100644 > --- a/drivers/mtd/nand/raw/nandsim.c > +++ b/drivers/mtd/nand/raw/nandsim.c > @@ -299,6 +299,7 @@ union ns_mem { > */ > struct nandsim { > struct nand_chip chip; > + struct nand_controller base; > struct mtd_partition partitions[CONFIG_NANDSIM_MAX_PARTS]; > unsigned int nbparts; > > @@ -645,9 +646,6 @@ static int __init init_nandsim(struct mtd_info *mtd) > return -EIO; > } > > - /* Force mtd to not do delays */ > - chip->legacy.chip_delay = 0; > - > /* Initialize the NAND flash parameters */ > ns->busw = chip->options & NAND_BUSWIDTH_16 ? 16 : 8; > ns->geom.totsz = mtd->size; > @@ -2077,24 +2075,6 @@ static void ns_nand_write_byte(struct nand_chip *chip, u_char byte) > return; > } > > -static void ns_hwcontrol(struct nand_chip *chip, int cmd, unsigned int bitmask) > -{ > - struct nandsim *ns = nand_get_controller_data(chip); > - > - ns->lines.cle = bitmask & NAND_CLE ? 1 : 0; > - ns->lines.ale = bitmask & NAND_ALE ? 1 : 0; > - ns->lines.ce = bitmask & NAND_NCE ? 1 : 0; > - > - if (cmd != NAND_CMD_NONE) > - ns_nand_write_byte(chip, cmd); > -} > - > -static int ns_device_ready(struct nand_chip *chip) > -{ > - NS_DBG("device_ready\n"); > - return 1; > -} > - > static void ns_nand_write_buf(struct nand_chip *chip, const u_char *buf, > int len) > { > @@ -2146,7 +2126,7 @@ static void ns_nand_read_buf(struct nand_chip *chip, u_char *buf, int len) > int i; > > for (i = 0; i < len; i++) > - buf[i] = chip->legacy.read_byte(chip); > + buf[i] = ns_nand_read_byte(chip); > > return; > } > @@ -2169,6 +2149,46 @@ static void ns_nand_read_buf(struct nand_chip *chip, u_char *buf, int len) > return; > } > > +static int ns_exec_op(struct nand_chip *chip, const struct nand_operation *op, > + bool check_only) > +{ > + int i; > + unsigned int op_id; > + const struct nand_op_instr *instr = NULL; > + struct nandsim *ns = nand_get_controller_data(chip); > + > + ns->lines.ce = chip->cur_cs == -1 ? 0 : 1; You can assume ns->lines.ce is always 1, since there's no point executing a NAND operation if the CS pin is not asserted. BTW, in case you ever consider supporting multi-CS chips, the CS line to select is passed through op->cs (you should not use nand->cur_cs). The rest of the patch looks good. Once this tiny detail is addressed you can add Reviewed-by: Boris Brezillon > + > + for (op_id = 0; op_id < op->ninstrs; op_id++) { > + instr = &op->instrs[op_id]; > + ns->lines.cle = 0; > + ns->lines.ale = 0; > + > + switch (instr->type) { > + case NAND_OP_CMD_INSTR: > + ns->lines.cle = 1; > + ns_nand_write_byte(chip, instr->ctx.cmd.opcode); > + break; > + case NAND_OP_ADDR_INSTR: > + ns->lines.ale = 1; > + for (i = 0; i < instr->ctx.addr.naddrs; i++) > + ns_nand_write_byte(chip, instr->ctx.addr.addrs[i]); > + break; > + case NAND_OP_DATA_IN_INSTR: > + ns_nand_read_buf(chip, instr->ctx.data.buf.in, instr->ctx.data.len); > + break; > + case NAND_OP_DATA_OUT_INSTR: > + ns_nand_write_buf(chip, instr->ctx.data.buf.out, instr->ctx.data.len); > + break; > + case NAND_OP_WAITRDY_INSTR: > + /* we are always ready */ > + break; > + } > + } > + > + return 0; > +} > + > static int ns_attach_chip(struct nand_chip *chip) > { > unsigned int eccsteps, eccbytes; > @@ -2209,6 +2229,7 @@ static int ns_attach_chip(struct nand_chip *chip) > > static const struct nand_controller_ops ns_controller_ops = { > .attach_chip = ns_attach_chip, > + .exec_op = ns_exec_op, > }; > > /* > @@ -2234,14 +2255,6 @@ static int __init ns_init_module(void) > nsmtd = nand_to_mtd(chip); > nand_set_controller_data(chip, (void *)ns); > > - /* > - * Register simulator's callbacks. > - */ > - chip->legacy.cmd_ctrl = ns_hwcontrol; > - chip->legacy.read_byte = ns_nand_read_byte; > - chip->legacy.dev_ready = ns_device_ready; > - chip->legacy.write_buf = ns_nand_write_buf; > - chip->legacy.read_buf = ns_nand_read_buf; > chip->ecc.mode = NAND_ECC_SOFT; > chip->ecc.algo = NAND_ECC_HAMMING; > /* The NAND_SKIP_BBTSCAN option is necessary for 'overridesize' */ > @@ -2292,7 +2305,10 @@ static int __init ns_init_module(void) > if ((retval = parse_gravepages()) != 0) > goto error; > > - chip->legacy.dummy_controller.ops = &ns_controller_ops; > + nand_controller_init(&ns->base); > + ns->base.ops = &ns_controller_ops; > + chip->controller = &ns->base; > + > retval = nand_scan(chip, 1); > if (retval) { > NS_ERR("Could not scan NAND Simulator device\n");