Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2095356imm; Thu, 2 Aug 2018 06:13:42 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfsi9LfgXyVwSyl0/yCqWMqSNBc6cEAXDkxH4iJUTte1pO1V+ypVWUC+m0/xwShaqWBlNF+ X-Received: by 2002:a63:4b5a:: with SMTP id k26-v6mr2687582pgl.384.1533215622918; Thu, 02 Aug 2018 06:13:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533215622; cv=none; d=google.com; s=arc-20160816; b=XbHAZ6zw0GCCdyNpr7T3kDtvYVc14/JUjY53E/1Z+hbontxjXUQbS37K0YkIKkIC/f DUGT2szgB2rgyWrU3D9TcwLJ8qRQkttpNEbbAj+EuA3xzAsEQCQwmUhKFx9GQQmwM2Ot lE9j2VS5v4XOL9FvDLRV4k2DbFZOE/mVqd63FTwOMiiR/9/dbSPSl6irxS+fr9uPS11x IaIkdD675kg2CBefY5TsTZNSu/abSmt9dzKiqQkqFqrfeyqWnyt35S4hiMxNW5QGaAsQ GMvJkk760Y8IYI4VbA7YRGWfCNHRw12sbnwQDcKxEV5k3fidrGfnCEDgg4eiLx+ryKe2 tmYw== 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 :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=w4l2kBx6FRrz/x04YksigiRHmjzSUIyBsHOQfkgDNgs=; b=v5h10fDYC4cipQERycisnBEVNr0+uiMlVIt0BvZSzYHkrRRmuolOUZUVxAYUZWvepQ AHmKKCaFH947ToVq64vq2hKdewRet/lux+B46dTz483K4GYnqnGUHSGzmSlL9RJ9k9rP WF2IMjG8Q6t81wL3a+uQeJXKVDeyo4/1h4SCBIaEugh4hYuXjSuDiIlwpNh04axco0vI CUN29f3TYuHHhMwSUtdP3OTsrvQUskF3aW+W1iMu3y6B/GjUaGanPbGYcUVhLBz7fwxu dZYRaZjMSNDB8LEEZmK512N9tsw+QTJa6k0H9Jt7r0q8+VlUOTeRj1/QeCKERq1r1bYc CuUw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o2-v6si2221811pgm.288.2018.08.02.06.13.27; Thu, 02 Aug 2018 06:13:42 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732389AbeHBPDs (ORCPT + 99 others); Thu, 2 Aug 2018 11:03:48 -0400 Received: from mail.bootlin.com ([62.4.15.54]:49145 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732276AbeHBPDs (ORCPT ); Thu, 2 Aug 2018 11:03:48 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 59D2F20739; Thu, 2 Aug 2018 15:12:36 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from bbrezillon (AAubervilliers-681-1-89-120.w90-88.abo.wanadoo.fr [90.88.30.120]) by mail.bootlin.com (Postfix) with ESMTPSA id F1FFD206A6; Thu, 2 Aug 2018 15:12:35 +0200 (CEST) Date: Thu, 2 Aug 2018 15:12:36 +0200 From: Boris Brezillon To: Frieder Schrempf Cc: dwmw2@infradead.org, computersforpeace@gmail.com, marek.vasut@gmail.com, richard@nod.at, broonie@kernel.org, linux-mtd@lists.infradead.org, linux-spi@vger.kernel.org, cyrille.pitchen@wedev4u.fr, pp@emlix.com, Zhiqiang.Hou@nxp.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 2/3] spi: spi-mem: Extend the SPI mem interface to set a custom memory name Message-ID: <20180802151236.2d4006ae@bbrezillon> In-Reply-To: <1533214434-28761-3-git-send-email-frieder.schrempf@exceet.de> References: <1533214434-28761-1-git-send-email-frieder.schrempf@exceet.de> <1533214434-28761-3-git-send-email-frieder.schrempf@exceet.de> X-Mailer: Claws Mail 3.15.0-dirty (GTK+ 2.24.31; x86_64-pc-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 Thu, 2 Aug 2018 14:53:53 +0200 Frieder Schrempf wrote: > When porting (Q)SPI controller drivers from the MTD layer to the SPI > layer, the naming scheme for the memory devices changes. To be able > to keep compatibility with the old drivers naming scheme, a name > field is added to struct spi_mem and a hook is added to let controller > drivers set a custom name for the memory device. > > Example for the FSL QSPI driver: > > Name with the old driver: 21e0000.qspi, > or with multiple devices: 21e0000.qspi-0, 21e0000.qspi-1, ... > > Name with the new driver without spi_mem_get_name: spi4.0 > > Suggested-by: Boris Brezillon > Signed-off-by: Frieder Schrempf Reviewed-by: Boris Brezillon > --- > drivers/spi/spi-mem.c | 28 ++++++++++++++++++++++++++++ > include/linux/spi/spi-mem.h | 12 ++++++++++++ > 2 files changed, 40 insertions(+) > > diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c > index 990770d..e43842c 100644 > --- a/drivers/spi/spi-mem.c > +++ b/drivers/spi/spi-mem.c > @@ -311,6 +311,24 @@ int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op) > EXPORT_SYMBOL_GPL(spi_mem_exec_op); > > /** > + * spi_mem_get_name() - Return the SPI mem device name to be used by the > + * upper layer if necessary > + * @mem: the SPI memory > + * > + * This function allows SPI mem users to retrieve the SPI mem device name. > + * It is useful if the upper layer needs to expose a custom name for > + * compatibility reasons. > + * > + * Return: a string containing the name of the memory device to be used > + * by the SPI mem user > + */ > +const char *spi_mem_get_name(struct spi_mem *mem) > +{ > + return mem->name; > +} > +EXPORT_SYMBOL_GPL(spi_mem_get_name); > + > +/** > * spi_mem_adjust_op_size() - Adjust the data size of a SPI mem operation to > * match controller limitations > * @mem: the SPI memory > @@ -344,6 +362,7 @@ static inline struct spi_mem_driver *to_spi_mem_drv(struct device_driver *drv) > static int spi_mem_probe(struct spi_device *spi) > { > struct spi_mem_driver *memdrv = to_spi_mem_drv(spi->dev.driver); > + struct spi_controller *ctlr = spi->controller; > struct spi_mem *mem; > > mem = devm_kzalloc(&spi->dev, sizeof(*mem), GFP_KERNEL); > @@ -351,6 +370,15 @@ static int spi_mem_probe(struct spi_device *spi) > return -ENOMEM; > > mem->spi = spi; > + > + if (ctlr->mem_ops && ctlr->mem_ops->get_name) > + mem->name = ctlr->mem_ops->get_name(mem); > + else > + mem->name = dev_name(&spi->dev); > + > + if (IS_ERR_OR_NULL(mem->name)) > + return PTR_ERR(mem->name); > + > spi_set_drvdata(spi, mem); > > return memdrv->probe(mem); > diff --git a/include/linux/spi/spi-mem.h b/include/linux/spi/spi-mem.h > index 72cc9bc..0d41826 100644 > --- a/include/linux/spi/spi-mem.h > +++ b/include/linux/spi/spi-mem.h > @@ -125,6 +125,7 @@ struct spi_mem_op { > * struct spi_mem - describes a SPI memory device > * @spi: the underlying SPI device > * @drvpriv: spi_mem_driver private data > + * @name: name of the SPI memory device > * > * Extra information that describe the SPI memory device and may be needed by > * the controller to properly handle this device should be placed here. > @@ -135,6 +136,7 @@ struct spi_mem_op { > struct spi_mem { > struct spi_device *spi; > void *drvpriv; > + char *name; > }; > > /** > @@ -167,6 +169,13 @@ static inline void *spi_mem_get_drvdata(struct spi_mem *mem) > * limitations) > * @supports_op: check if an operation is supported by the controller > * @exec_op: execute a SPI memory operation > + * @get_name: get a custom name for the SPI mem device from the controller. > + * This might be needed if the controller driver has been ported > + * to use the SPI mem layer and a custom name is used to keep > + * mtdparts compatible. > + * Note that if the implementation of this function allocates memory > + * dynamically, then it should do so with devm_xxx(), as we don't > + * have a ->free_name() function. > * > * This interface should be implemented by SPI controllers providing an > * high-level interface to execute SPI memory operation, which is usually the > @@ -178,6 +187,7 @@ struct spi_controller_mem_ops { > const struct spi_mem_op *op); > int (*exec_op)(struct spi_mem *mem, > const struct spi_mem_op *op); > + const char *(*get_name)(struct spi_mem *mem); > }; > > /** > @@ -236,6 +246,8 @@ bool spi_mem_supports_op(struct spi_mem *mem, > int spi_mem_exec_op(struct spi_mem *mem, > const struct spi_mem_op *op); > > +const char *spi_mem_get_name(struct spi_mem *mem); > + > int spi_mem_driver_register_with_owner(struct spi_mem_driver *drv, > struct module *owner); >