Received: by 2002:ac0:a591:0:0:0:0:0 with SMTP id m17-v6csp585687imm; Thu, 5 Jul 2018 05:41:16 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeRVqO9GuNzN1tNXQzjts83pe+o0LHPvI4ih2ODP0HgCMMRKU10DzqphwfIoj/R/Cy/u39o X-Received: by 2002:a63:6b86:: with SMTP id g128-v6mr5587423pgc.344.1530794476470; Thu, 05 Jul 2018 05:41:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530794476; cv=none; d=google.com; s=arc-20160816; b=Er2h8myPXOvgoWO0gowx3EaLgLxOzD+iPXd6uW1X/yQgEY+kf3mnI8aqO+BrFCVn2Y 9eiXc767yqfaICWIV5aoN3Bc7KEhF84k4WqPig//ISXP+XacW451GsdK5WAzs6CIMgP8 Sd6q04Ilcdnc6nDbnhEdIWeJklwiyECCHzG3VX38wXM46+Sf1giC1iD5LmjPMoWkQ5Hi CnWSLOYPOgMLaxFnbh4GGCalU+6kl56W3qeFxtxcykFVhHOaAt0sVF5mFtEEnuN7sPe+ 3kdl340v4mVhsj8VHn4XM/XwewkC2IdjFO36VpM/L/Db2DEN28VmkVnd0ghWtMujlZXk 30fg== 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=gyig7d1q/ArXkfcrkf4k9cWWqRd7q08a8fOBPq/47hY=; b=k0E3JSmgK3IGa+jDIRqtPPMREz5XyM6VfWf0YO8QgHCjw6u+KHK8iB1lGzvIuQ3yfp nruc6YtEI1IK/oobtFv7CqF10d46b07lBxcwqvaUB/pvTF6vQUdOImgt9lvU3Qrsb4jc 5QcijQBUq+o6nfCVRmDpjELST9ubuB75f3D7lp81fkdOw0NBoz8pN9bdDxVo7F2C4tqi y/7vrQBig26TTuuA0o1//hR48yMHJuXYL0A0Y+M74Y8rYNaQoJ/u7yf5QfP1qqLjEfC4 ghW0IlvF3j1s3hI1ggZ0WDVeYwfYiPpGi1mQ778gAe0k7f82yhyL2RuZMZAdP/4bH84k /7GA== 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 l30-v6si5770567plg.420.2018.07.05.05.40.50; Thu, 05 Jul 2018 05:41:16 -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 S1753975AbeGEMkD (ORCPT + 99 others); Thu, 5 Jul 2018 08:40:03 -0400 Received: from mail.bootlin.com ([62.4.15.54]:49897 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753718AbeGEMkB (ORCPT ); Thu, 5 Jul 2018 08:40:01 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 1DD7C2079C; Thu, 5 Jul 2018 14:39:59 +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-39-106.w90-88.abo.wanadoo.fr [90.88.158.106]) by mail.bootlin.com (Postfix) with ESMTPSA id AC26F203D9; Thu, 5 Jul 2018 14:39:48 +0200 (CEST) Date: Thu, 5 Jul 2018 14:39:48 +0200 From: Boris Brezillon To: Frieder Schrempf Cc: linux-mtd@lists.infradead.org, linux-spi@vger.kernel.org, dwmw2@infradead.org, computersforpeace@gmail.com, marek.vasut@gmail.com, richard@nod.at, miquel.raynal@bootlin.com, broonie@kernel.org, david.wolfe@nxp.com, fabio.estevam@nxp.com, prabhakar.kushwaha@nxp.com, yogeshnarayan.gaur@nxp.com, han.xu@nxp.com, shawnguo@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 01/12] spi: spi-mem: Extend the SPI mem interface to set a custom memory name Message-ID: <20180705143948.2c864bf6@bbrezillon> In-Reply-To: <1530789310-16254-2-git-send-email-frieder.schrempf@exceet.de> References: <1530789310-16254-1-git-send-email-frieder.schrempf@exceet.de> <1530789310-16254-2-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 Hi Frieder, On Thu, 5 Jul 2018 13:14:57 +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 function > is added to the SPI mem interface to let controller drivers set a > custom name for the memory. > > 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 > > Signed-off-by: Frieder Schrempf > --- > Changes in v2: > ============== > * Add a name field to struct spi_mem and fill it while probing > > drivers/spi/spi-mem.c | 30 ++++++++++++++++++++++++++++++ > include/linux/spi/spi-mem.h | 7 ++++++- > 2 files changed, 36 insertions(+), 1 deletion(-) > > diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c > index 990770d..048101c 100644 > --- a/drivers/spi/spi-mem.c > +++ b/drivers/spi/spi-mem.c > @@ -311,6 +311,26 @@ 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() - Let drivers using the SPI mem interface specify a > + * custom name for the memory to avoid compatibility > + * issues with ported drivers. You're not describing what this function does, but why it was introduced. Not sure the spi-mem user/driver cares about that, these are just internal details. Probably something you should put in the ->get_name() hook doc. > + * @mem: the SPI memory > + * > + * 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, this function can > + * be used to get a custom name from the controller driver. > + * If no custom name is available, the name of the SPI device is returned. Ditto. Just say that this function returns the spi-mem device name which can be used by the upper layer if they need to expose a user-friendly name. > + * > + * Return: a char array that contains the name for the flash memory ^ a string? 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 +364,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 +372,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 4fa34a2..c3f82d1 100644 > --- a/include/linux/spi/spi-mem.h > +++ b/include/linux/spi/spi-mem.h > @@ -124,7 +124,8 @@ struct spi_mem_op { > /** > * struct spi_mem - describes a SPI memory device > * @spi: the underlying SPI device > - * @drvpriv: spi_mem_drviver private data > + * @drvpriv: spi_mem_driver private data Can you fix this typo in a separate patch? > + * @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; > }; > > /** > @@ -178,6 +180,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); You forgot to document this hook. Also, it's important to mention that if the name returned by this function is dynamically allocated, it should be allocated with devm_xxxx(), because we don't have a ->free_name() function. > }; > > /** > @@ -236,6 +239,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); > Thanks, Boris