From patchwork Mon Jul 29 14:25:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomer Maimon X-Patchwork-Id: 11064011 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B1D11912 for ; Mon, 29 Jul 2019 15:20:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E75B27F10 for ; Mon, 29 Jul 2019 15:20:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8C2872857D; Mon, 29 Jul 2019 15:20:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE8C127F10 for ; Mon, 29 Jul 2019 15:20:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728683AbfG2PUT (ORCPT ); Mon, 29 Jul 2019 11:20:19 -0400 Received: from 212.199.177.27.static.012.net.il ([212.199.177.27]:40105 "EHLO herzl.nuvoton.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728023AbfG2PUT (ORCPT ); Mon, 29 Jul 2019 11:20:19 -0400 Received: from taln60.nuvoton.co.il (ntil-fw [212.199.177.25]) by herzl.nuvoton.co.il (8.13.8/8.13.8) with ESMTP id x6TEP6AT025572; Mon, 29 Jul 2019 17:25:06 +0300 Received: by taln60.nuvoton.co.il (Postfix, from userid 10070) id 5665861FD4; Mon, 29 Jul 2019 17:25:06 +0300 (IDT) From: Tomer Maimon To: broonie@kernel.org, dwmw2@infradead.org, computersforpeace@gmail.com, marek.vasut@gmail.com, miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com, bbrezillon@kernel.org, yogeshnarayan.gaur@nxp.com, tudor.ambarus@microchip.com, gregkh@linuxfoundation.org, frieder.schrempf@exceet.de, tglx@linutronix.de Cc: linux-spi@vger.kernel.org, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Tomer Maimon Subject: [RFC v1 1/3] spi: spi-mem: add spi-mem setup function Date: Mon, 29 Jul 2019 17:25:02 +0300 Message-Id: <20190729142504.188336-2-tmaimon77@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190729142504.188336-1-tmaimon77@gmail.com> References: <20190729142504.188336-1-tmaimon77@gmail.com> Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add spi-mem setup function support SPI memory operations the spi-mem setup function running after the spi-mem probe function if the spi-mem setup function implemented. Signed-off-by: Tomer Maimon --- drivers/spi/spi-mem.c | 27 ++++++++++++++++++++++++++- include/linux/spi/spi-mem.h | 4 ++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c index 9f0fa9f3116d..21fe3a75d636 100644 --- a/drivers/spi/spi-mem.c +++ b/drivers/spi/spi-mem.c @@ -398,6 +398,26 @@ const char *spi_mem_get_name(struct spi_mem *mem) } EXPORT_SYMBOL_GPL(spi_mem_get_name); +/** + * spi_mem_setup() - Execute spi memory setup + * @mem: the SPI memory + * + * This function allows SPI mem users to execute spi memory + * setup after the probe finished. + * + * Return: 0 in case of success, a negative error code otherwise. + */ +int spi_mem_setup(struct spi_mem *mem) +{ + struct spi_controller *ctlr = mem->spi->controller; + + if (ctlr->mem_ops && ctlr->mem_ops->setup) + return ctlr->mem_ops->setup(mem); + + return 0; +} +EXPORT_SYMBOL_GPL(spi_mem_setup); + /** * spi_mem_adjust_op_size() - Adjust the data size of a SPI mem operation to * match controller limitations @@ -723,6 +743,7 @@ 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; + int ret; mem = devm_kzalloc(&spi->dev, sizeof(*mem), GFP_KERNEL); if (!mem) @@ -740,7 +761,11 @@ static int spi_mem_probe(struct spi_device *spi) spi_set_drvdata(spi, mem); - return memdrv->probe(mem); + ret = memdrv->probe(mem); + if (ret) + return ret; + + return spi_mem_setup(mem); } static int spi_mem_remove(struct spi_device *spi) diff --git a/include/linux/spi/spi-mem.h b/include/linux/spi/spi-mem.h index af9ff2f0f1b2..5f7d20bd2b09 100644 --- a/include/linux/spi/spi-mem.h +++ b/include/linux/spi/spi-mem.h @@ -222,6 +222,7 @@ static inline void *spi_mem_get_drvdata(struct spi_mem *mem) * 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. + * @setup: execute a SPI memory setup * @dirmap_create: create a direct mapping descriptor that can later be used to * access the memory device. This method is optional * @dirmap_destroy: destroy a memory descriptor previous created by @@ -256,6 +257,7 @@ struct spi_controller_mem_ops { int (*exec_op)(struct spi_mem *mem, const struct spi_mem_op *op); const char *(*get_name)(struct spi_mem *mem); + int (*setup)(struct spi_mem *mem); int (*dirmap_create)(struct spi_mem_dirmap_desc *desc); void (*dirmap_destroy)(struct spi_mem_dirmap_desc *desc); ssize_t (*dirmap_read)(struct spi_mem_dirmap_desc *desc, @@ -334,6 +336,8 @@ int spi_mem_exec_op(struct spi_mem *mem, const char *spi_mem_get_name(struct spi_mem *mem); +int spi_mem_setup(struct spi_mem *mem); + struct spi_mem_dirmap_desc * spi_mem_dirmap_create(struct spi_mem *mem, const struct spi_mem_dirmap_info *info); From patchwork Mon Jul 29 14:25:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomer Maimon X-Patchwork-Id: 11064009 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8F0DE1398 for ; Mon, 29 Jul 2019 15:19:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7E7E2262FF for ; Mon, 29 Jul 2019 15:19:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7212628517; Mon, 29 Jul 2019 15:19:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1CC2D262FF for ; Mon, 29 Jul 2019 15:19:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387913AbfG2PTt (ORCPT ); Mon, 29 Jul 2019 11:19:49 -0400 Received: from 212.199.177.27.static.012.net.il ([212.199.177.27]:40097 "EHLO herzl.nuvoton.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2387854AbfG2PTt (ORCPT ); Mon, 29 Jul 2019 11:19:49 -0400 X-Greylist: delayed 3197 seconds by postgrey-1.27 at vger.kernel.org; Mon, 29 Jul 2019 11:19:46 EDT Received: from taln60.nuvoton.co.il (ntil-fw [212.199.177.25]) by herzl.nuvoton.co.il (8.13.8/8.13.8) with ESMTP id x6TEP6lN025573; Mon, 29 Jul 2019 17:25:06 +0300 Received: by taln60.nuvoton.co.il (Postfix, from userid 10070) id C3EFF622ED; Mon, 29 Jul 2019 17:25:06 +0300 (IDT) From: Tomer Maimon To: broonie@kernel.org, dwmw2@infradead.org, computersforpeace@gmail.com, marek.vasut@gmail.com, miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com, bbrezillon@kernel.org, yogeshnarayan.gaur@nxp.com, tudor.ambarus@microchip.com, gregkh@linuxfoundation.org, frieder.schrempf@exceet.de, tglx@linutronix.de Cc: linux-spi@vger.kernel.org, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Tomer Maimon Subject: [RFC v1 2/3] spi: spi-mem: add callback function to spi-mem device Date: Mon, 29 Jul 2019 17:25:03 +0300 Message-Id: <20190729142504.188336-3-tmaimon77@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190729142504.188336-1-tmaimon77@gmail.com> References: <20190729142504.188336-1-tmaimon77@gmail.com> Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add callback function support to the spi-mem device for passing an argument from the spi-mem layer to the spi layer. Signed-off-by: Tomer Maimon --- include/linux/spi/spi-mem.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/linux/spi/spi-mem.h b/include/linux/spi/spi-mem.h index 5f7d20bd2b09..b9841a9030be 100644 --- a/include/linux/spi/spi-mem.h +++ b/include/linux/spi/spi-mem.h @@ -13,6 +13,8 @@ #include +typedef size_t (*spi_mem_callback)(void *spi_mem_param); + #define SPI_MEM_OP_CMD(__opcode, __buswidth) \ { \ .buswidth = __buswidth, \ @@ -172,6 +174,9 @@ struct spi_mem_dirmap_desc { * @spi: the underlying SPI device * @drvpriv: spi_mem_driver private data * @name: name of the SPI memory device + * @callback: routine for passing an argument from the + * spi-mem layer to the spi layer. + * @callback_param: general parameter to pass to the callback routine * * Extra information that describe the SPI memory device and may be needed by * the controller to properly handle this device should be placed here. @@ -183,6 +188,8 @@ struct spi_mem { struct spi_device *spi; void *drvpriv; const char *name; + spi_mem_callback callback; + void *callback_param; }; /** From patchwork Mon Jul 29 14:25:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomer Maimon X-Patchwork-Id: 11064007 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 92760912 for ; Mon, 29 Jul 2019 15:19:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D73A262FF for ; Mon, 29 Jul 2019 15:19:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6EE9A28517; Mon, 29 Jul 2019 15:19:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 178F0262FF for ; Mon, 29 Jul 2019 15:19:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387894AbfG2PTr (ORCPT ); Mon, 29 Jul 2019 11:19:47 -0400 Received: from 212.199.177.27.static.012.net.il ([212.199.177.27]:40097 "EHLO herzl.nuvoton.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2387854AbfG2PTr (ORCPT ); Mon, 29 Jul 2019 11:19:47 -0400 X-Greylist: delayed 3197 seconds by postgrey-1.27 at vger.kernel.org; Mon, 29 Jul 2019 11:19:46 EDT Received: from taln60.nuvoton.co.il (ntil-fw [212.199.177.25]) by herzl.nuvoton.co.il (8.13.8/8.13.8) with ESMTP id x6TEP7Fj025574; Mon, 29 Jul 2019 17:25:07 +0300 Received: by taln60.nuvoton.co.il (Postfix, from userid 10070) id 29394622F0; Mon, 29 Jul 2019 17:25:07 +0300 (IDT) From: Tomer Maimon To: broonie@kernel.org, dwmw2@infradead.org, computersforpeace@gmail.com, marek.vasut@gmail.com, miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com, bbrezillon@kernel.org, yogeshnarayan.gaur@nxp.com, tudor.ambarus@microchip.com, gregkh@linuxfoundation.org, frieder.schrempf@exceet.de, tglx@linutronix.de Cc: linux-spi@vger.kernel.org, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Tomer Maimon Subject: [RFC v1 3/3] mtd: m25p80: add get Flash size callback support Date: Mon, 29 Jul 2019 17:25:04 +0300 Message-Id: <20190729142504.188336-4-tmaimon77@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190729142504.188336-1-tmaimon77@gmail.com> References: <20190729142504.188336-1-tmaimon77@gmail.com> Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add get Flash size function support for passing Flash size through callback use to the spi layer. Add get Flash size function support Signed-off-by: Tomer Maimon --- drivers/mtd/devices/m25p80.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c index c50888670250..fd14c8c6d8d8 100644 --- a/drivers/mtd/devices/m25p80.c +++ b/drivers/mtd/devices/m25p80.c @@ -151,6 +151,15 @@ static ssize_t m25p80_read(struct spi_nor *nor, loff_t from, size_t len, return len; } +/* Sending Flash size thourgh callback function to spi layer */ +size_t m25p80_get_flash_size(void *param) +{ + struct spi_mem *spimem = param; + struct m25p *flash = spi_mem_get_drvdata(spimem); + + return (u32)(flash->spi_nor.mtd.size >> 10) * 1024; +} + /* * board specific setup should have ensured the SPI clock used here * matches what the READ command supports, at least until this driver @@ -188,6 +197,9 @@ static int m25p_probe(struct spi_mem *spimem) spi_nor_set_flash_node(nor, spi->dev.of_node); nor->priv = flash; + spimem->callback = m25p80_get_flash_size; + spimem->callback_param = spimem; + spi_mem_set_drvdata(spimem, flash); flash->spimem = spimem;