Received: by 2002:ac0:a591:0:0:0:0:0 with SMTP id m17-v6csp507853imm; Thu, 5 Jul 2018 04:19:10 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe2ZNj1TYPjQEDmMs3ygCzM7HAmxLDwH43kaLNRHGb9ouCbLsrBWaZbfsUuWMzU7a+SIDC7 X-Received: by 2002:a62:6659:: with SMTP id a86-v6mr5963903pfc.31.1530789550877; Thu, 05 Jul 2018 04:19:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530789550; cv=none; d=google.com; s=arc-20160816; b=FY7u18Zgy0S4Q7TW3Q6VIcPJJDvKbTyx1GaMhAd/ODudZI7bHqNNeABgHAgxqrLN8d XL3Ws1JXTkQecBrHrtaLIPcbsBgsjf8bKVwyhvrxVcsPN9rFlqK2SYk9EfZLg3nMJcSn Ff0hBD6ywb1aqGWcJ+IZ6F1YurSVG43CpgO0oSYyfwKPf0nANvtnCFZsk9769e0TCT46 ddQfcxQ/GkbWNT5I2uTdAibw2qQAaAUfyLyAj4N8lfF7Yy6ExOTv/+djW6EVBJKnDF/V r01p/DZnDki0VYMDbwPoMQxge2BWKjhsJL26lsTMtJPuZuUAWQswxgdeqIYQTZjJYqiM JJKg== 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:arc-authentication-results; bh=tZCaPM+ETK/jVFWKAexZNweKjFocXwoGR7nnTUtOZMM=; b=quS/ugkjXj7NuDkpf/Xjo+GK8X/mrDRnGs2PYMg0O4Gjm3kPNz/LaVe0OD6ROsS/JR 19MjgLwunBWni3Fjd3QzAbJsIhwMt2fmD4Kcp41VlUikQTs9ZGO8cGjB+v/dzMC+gSPJ GkMYAcZDmMu6Ucib0E4S5kBGnq+u09sy+B2T2WzzuNdxdnbIRPx5YdDn51qRJNofYpVU mbeiJGKiUqe2MwYa9ItAvSPMjoGZjEzgjT5qKFvfMix4zFpbYpzBQpe4r3LQN9V2P3TE fh2PYug31C7MPex4OBypEHQw9zS5GoYTpiKA9/4eLoIkn6nPe2OtzVkXt5yytF8dGemt e/2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@as-electronics.de header.s=strato-dkim-0002 header.b=YFC1bIVW; 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 h16-v6si5508561pgb.39.2018.07.05.04.18.55; Thu, 05 Jul 2018 04:19:10 -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=fail header.i=@as-electronics.de header.s=strato-dkim-0002 header.b=YFC1bIVW; 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 S1753973AbeGELRd (ORCPT + 99 others); Thu, 5 Jul 2018 07:17:33 -0400 Received: from mo4-p05-ob.smtp.rzone.de ([85.215.255.130]:26838 "EHLO mo4-p05-ob.smtp.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753488AbeGELRa (ORCPT ); Thu, 5 Jul 2018 07:17:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1530789449; s=strato-dkim-0002; d=as-electronics.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=tZCaPM+ETK/jVFWKAexZNweKjFocXwoGR7nnTUtOZMM=; b=YFC1bIVWnV2GGYsVBuItgbA0fdPJdXxbat6G2C080PNLRquYqEMVwZo2OldwXlfaK9 kT1HJ/bzIXbpiMH02ATUSV26Q9HPpVBmWW4u4kGl+78hLT8ji4EHWxpXnPzGhdh5NmlW CMpVOvAS7Ja0CQC9VF79JvUXZj7XwAThutH3i42U3e3IkfJkXgbxIe7DYTQZVIcXSQYD bNhTj0ABlko5ZqAlgWCAQqkXjvRHsKSsbLliQJsonH4dEM18cSC7S/ez6ZHP9sN2A5UC oOb+bFO1owtm0P8+jjdLG9PTjleALBrO872Z2QqzuKch6wOvAnf0uwTMdKSOhN1kTdrs fSCg== X-RZG-AUTH: ":LX8JdEmkW/4tAFwMkcNJIloh1hrA5u3owhPk7bdT5Fx22AatU+eLaHfutoZdl+X9BETxn4/4+IVqx+daE87UU5bgm7XHzClQnm8VxHglxo5wj3H1fls=" X-RZG-CLASS-ID: mo05 Received: from fs-work.fritz.box by smtp.strato.de (RZmta 43.12 AUTH) with ESMTPSA id a0925bu65BH04i1 (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Thu, 5 Jul 2018 13:17:00 +0200 (CEST) From: Frieder Schrempf To: linux-mtd@lists.infradead.org, boris.brezillon@bootlin.com, linux-spi@vger.kernel.org Cc: 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, Frieder Schrempf , linux-kernel@vger.kernel.org Subject: [PATCH v2 01/12] spi: spi-mem: Extend the SPI mem interface to set a custom memory name Date: Thu, 5 Jul 2018 13:14:57 +0200 Message-Id: <1530789310-16254-2-git-send-email-frieder.schrempf@exceet.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1530789310-16254-1-git-send-email-frieder.schrempf@exceet.de> References: <1530789310-16254-1-git-send-email-frieder.schrempf@exceet.de> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. + * @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. + * + * Return: a char array that contains the name for the flash memory + */ +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 + * @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); }; /** @@ -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); -- 2.7.4