Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp336214ybl; Thu, 9 Jan 2020 23:01:19 -0800 (PST) X-Google-Smtp-Source: APXvYqx6c8B+NFJHBsYlWJYvTIfFCiqphWTM/uiyjaWkvdoJyHKeN1DDeo5kOunw3roClLvhgc14 X-Received: by 2002:a9d:7e8a:: with SMTP id m10mr1294658otp.27.1578639679922; Thu, 09 Jan 2020 23:01:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578639679; cv=none; d=google.com; s=arc-20160816; b=WslqW4IB2q1pAQoFo9wufmgEj6/dlTZSglyxwlOH4EWHJUjYwgAQccQxtan0Vtzi3O YeyPy4fN6Ns0k8Z7mIDNzznSG7AgP8zDpIwyaGp2NkxidTj8Q8ixHtERcinbEnRv53+D jNweL6Z80vTh5c38+Gy1Wa0j1Bgwp4do5oGcNBzPV6BZvdIP9dDcoXUFGg9GyejIz5yW Brva9dOkVGzmmq4y7n38VRm1r3rTiKIoqv7rjdaGFEfwrccTJHOV32no6Fk5XNiIi7/O Dh99xx7/LHJajLae+m3b8hP2Xyona8d1/qazAbXTbn0RJzZY3FQ0uBcMkfTOQArgN8N2 T9MA== 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=XDJevekLHPJTM+moP0urMU9VH4c4QyvEOZ+mb10F9F0=; b=Bzf/JmGiuMi5/BY1vzdMmhljsh6rc4Q4SJqEaPf79KN9LH0fYWnWoViixCTGdm3H2p +kuWX5SjBOeZx8txeG3RPL/lR/VJuNWdExo8M8QhR1qB1wM46quQbp/8b9DePFFUbPFK IEqiVfO3cle8gMnfw9K7366kYDi5fm640YX88CnhVXX9/EM7gppVMRRYrgB8vtbnIUoD AjY5sLI3k0k6mn6Kc0/hfj6n9nbDrBMdg74yCF2FKY76L+JxI70mPh6ETeUvmmyeYIXR 8vvq9u1o0IkGQOwlWmTMo6RHVhBzdOmFbFxYkp++c0AQBErpXZlIXm1NgUs1PQINz1Sb 3wTA== 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 d6si571452oic.274.2020.01.09.23.01.07; Thu, 09 Jan 2020 23:01:19 -0800 (PST) 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 S1727655AbgAJG7F (ORCPT + 99 others); Fri, 10 Jan 2020 01:59:05 -0500 Received: from bhuna.collabora.co.uk ([46.235.227.227]:49496 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727074AbgAJG7E (ORCPT ); Fri, 10 Jan 2020 01:59:04 -0500 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 E8618293934; Fri, 10 Jan 2020 06:59:02 +0000 (GMT) Date: Fri, 10 Jan 2020 07:58:59 +0100 From: Boris Brezillon To: Chuanhong Guo Cc: linux-mtd@lists.infradead.org, Boris Brezillon , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mtd: nand: spi: rework detect procedure for different read id op Message-ID: <20200110075859.3edfae3a@collabora.com> In-Reply-To: <20200110025218.1257809-1-gch981213@gmail.com> References: <20200110025218.1257809-1-gch981213@gmail.com> Organization: Collabora X-Mailer: Claws Mail 3.17.4 (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 Fri, 10 Jan 2020 10:51:14 +0800 Chuanhong Guo wrote: > +static int spinand_manufacturer_detect(struct spinand_device *spinand) > +{ > + u8 *id = spinand->id.data; > + int ret; > + > + ret = spinand_read_id_op(spinand, 0, 0, id); > + if (ret) > + return ret; > + ret = spinand_manufacturer_match(spinand, SPINAND_READID_METHOD_OPCODE); > + if (!ret) > + return 0; > + > + ret = spinand_read_id_op(spinand, 1, 0, id); > + if (ret) > + return ret; > + ret = spinand_manufacturer_match(spinand, > + SPINAND_READID_METHOD_OPCODE_ADDR); > + if (!ret) > + return 0; > + > + ret = spinand_read_id_op(spinand, 0, 1, id); Hm, we should probably do only one of each read_id and iterate over all manufacturers/chips each time instead of doing 3 read_ids per manufacturer. > + if (ret) > + return ret; > + ret = spinand_manufacturer_match(spinand, > + SPINAND_READID_METHOD_OPCODE_DUMMY); > + > + return ret; > +} > + [...] > +/** > + * struct spinand_devid - SPI NAND device id structure > + * @id: device id of current chip > + * @len: number of bytes in device id > + * @method: method to read chip id > + * There are 3 possible variants: > + * SPINAND_READID_METHOD_OPCODE: chip id is returned immediately > + * after read_id opcode. > + * SPINAND_READID_METHOD_OPCODE_ADDR: chip id is returned after > + * read_id opcode + 1-byte address. > + * SPINAND_READID_METHOD_OPCODE_DUMMY: chip id is returned after > + * read_id opcode + 1 dummy byte. > + */ > +struct spinand_devid { > + u16 id; Can we make that field an array of u8? const u8 *id; > + u8 len; > + enum spinand_readid_method method; > +}; > + > /** > * struct manufacurer_ops - SPI NAND manufacturer specific operations > - * @detect: detect a SPI NAND device. Every time a SPI NAND device is probed > - * the core calls the struct_manufacurer_ops->detect() hook of each > - * registered manufacturer until one of them return 1. Note that > - * the first thing to check in this hook is that the manufacturer ID > - * in struct_spinand_device->id matches the manufacturer whose > - * ->detect() hook has been called. Should return 1 if there's a > - * match, 0 if the manufacturer ID does not match and a negative > - * error code otherwise. When true is returned, the core assumes > - * that properties of the NAND chip (spinand->base.memorg and > - * spinand->base.eccreq) have been filled > * @init: initialize a SPI NAND device > * @cleanup: cleanup a SPI NAND device > * > * Each SPI NAND manufacturer driver should implement this interface so that > - * NAND chips coming from this vendor can be detected and initialized properly. > + * NAND chips coming from this vendor can be initialized properly. > */ > struct spinand_manufacturer_ops { > - int (*detect)(struct spinand_device *spinand); > int (*init)(struct spinand_device *spinand); > void (*cleanup)(struct spinand_device *spinand); > }; > @@ -215,11 +224,16 @@ struct spinand_manufacturer_ops { > * struct spinand_manufacturer - SPI NAND manufacturer instance > * @id: manufacturer ID > * @name: manufacturer name > + * @devid_len: number of bytes in device ID > + * @chips: supported SPI NANDs under current manufacturer > + * @nchips: number of SPI NANDs available in chips array > * @ops: manufacturer operations > */ > struct spinand_manufacturer { > u8 id; > char *name; > + const struct spinand_info *chips; > + const size_t nchips; > const struct spinand_manufacturer_ops *ops; > }; > > @@ -291,7 +305,7 @@ struct spinand_ecc_info { > */ > struct spinand_info { > const char *model; > - u16 devid; > + struct spinand_devid devid; > u32 flags; > struct nand_memory_organization memorg; > struct nand_ecc_req eccreq; > @@ -305,6 +319,13 @@ struct spinand_info { > unsigned int target); > }; > > +#define SPINAND_ID(__id, __len, __method) \ > + { \ > + .id = __id, \ > + .len = __len, \ > + .method = __method, \ > + } That one can be turned into #define SPINAND_ID(__method, ...) \ { \ .id = (const u8[]){ __VA_ARGS }, \ .len = sizeof((u8[]){ __VA_ARGS }), \ .method = __method, \ } > + > #define SPINAND_INFO_OP_VARIANTS(__read, __write, __update) \ > { \ > .read_cache = __read, \ > @@ -451,9 +472,10 @@ static inline void spinand_set_of_node(struct spinand_device *spinand, > nanddev_set_of_node(&spinand->base, np); > } > > -int spinand_match_and_init(struct spinand_device *dev, > +int spinand_match_and_init(struct spinand_device *spinand, > const struct spinand_info *table, > - unsigned int table_size, u16 devid); > + unsigned int table_size, > + enum spinand_readid_method rdid_method); > > int spinand_upd_cfg(struct spinand_device *spinand, u8 mask, u8 val); > int spinand_select_target(struct spinand_device *spinand, unsigned int target);