From patchwork Tue Aug 8 20:51:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Packham X-Patchwork-Id: 9889095 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id ACD7D60363 for ; Tue, 8 Aug 2017 20:52:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F09D28932 for ; Tue, 8 Aug 2017 20:52:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 93E732894B; Tue, 8 Aug 2017 20:52:49 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable 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 E3A1928932 for ; Tue, 8 Aug 2017 20:52:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752520AbdHHUvj (ORCPT ); Tue, 8 Aug 2017 16:51:39 -0400 Received: from gate2.alliedtelesis.co.nz ([202.36.163.20]:53349 "EHLO gate2.alliedtelesis.co.nz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752456AbdHHUvi (ORCPT ); Tue, 8 Aug 2017 16:51:38 -0400 Received: from mmarshal3.atlnz.lc (mmarshal3.atlnz.lc [10.32.18.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by gate2.alliedtelesis.co.nz (Postfix) with ESMTPS id B5C628448A; Wed, 9 Aug 2017 08:51:35 +1200 (NZST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail; t=1502225495; bh=cFzMnacHIdBxMibm9WCvktyiC5t5Brkk3+1QZ5r1zTE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=KsF/RespUguQDmvVeNZSeSmVee5UYUZ3PoFxf9oUhu4/t/52/qQXn5YkicvxgeLeB YUsfiB40rFOOxij60Zr/YUMhQx4x4ZpxrmtKLdCIlC9LRtRJ+ilByw4w90Z6TESyua R9GEum0LaT6PiS8H9UpSt84g3ZIzpFK6CaPPqOSQ= Received: from smtp (Not Verified[10.32.16.33]) by mmarshal3.atlnz.lc with Trustwave SEG (v7, 5, 8, 10121) id ; Wed, 09 Aug 2017 08:51:36 +1200 Received: from chrisp-dl.ws.atlnz.lc (chrisp-dl.ws.atlnz.lc [10.33.22.30]) by smtp (Postfix) with ESMTP id AFD9413ED49; Wed, 9 Aug 2017 08:51:43 +1200 (NZST) Received: by chrisp-dl.ws.atlnz.lc (Postfix, from userid 1030) id A864B1E1D59; Wed, 9 Aug 2017 08:51:35 +1200 (NZST) From: Chris Packham To: broonie@kernel.org, linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, andy.shevchenko@gmail.com, hsweeten@visionengravers.com Cc: Chris Packham Subject: [PATCH v3 3/7] spi: spi-ep93xx: add spi master prepare_transfer_hardware() Date: Wed, 9 Aug 2017 08:51:27 +1200 Message-Id: <20170808205131.30874-4-chris.packham@alliedtelesis.co.nz> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170808205131.30874-1-chris.packham@alliedtelesis.co.nz> References: <20170808205131.30874-1-chris.packham@alliedtelesis.co.nz> 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 From: H Hartley Sweeten This driver currently enables the hardware at the start of every message and disabled it when the message is complete. Make it a bit smarter by adding the prepare_transfer_hardware() and unprepare_transfer_hardware() callbacks so that the core can enable/disable the hardware based on spi message queue. Signed-off-by: H Hartley Sweeten [chris: use u32 instead of unsigned int] Signed-off-by: Chris Packham Reviewed-by: Andy Shevchenko --- drivers/spi/spi-ep93xx.c | 72 ++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 39 deletions(-) diff --git a/drivers/spi/spi-ep93xx.c b/drivers/spi/spi-ep93xx.c index 0bd792020471..ce6ec164f2f2 100644 --- a/drivers/spi/spi-ep93xx.c +++ b/drivers/spi/spi-ep93xx.c @@ -111,33 +111,6 @@ struct ep93xx_spi { /* converts bits per word to CR0.DSS value */ #define bits_per_word_to_dss(bpw) ((bpw) - 1) -static int ep93xx_spi_enable(const struct ep93xx_spi *espi) -{ - u32 val; - int err; - - err = clk_enable(espi->clk); - if (err) - return err; - - val = readl(espi->mmio + SSPCR1); - val |= SSPCR1_SSE; - writel(val, espi->mmio + SSPCR1); - - return 0; -} - -static void ep93xx_spi_disable(const struct ep93xx_spi *espi) -{ - u32 val; - - val = readl(espi->mmio + SSPCR1); - val &= ~SSPCR1_SSE; - writel(val, espi->mmio + SSPCR1); - - clk_disable(espi->clk); -} - static void ep93xx_spi_enable_interrupts(const struct ep93xx_spi *espi) { u32 val; @@ -571,17 +544,6 @@ static void ep93xx_spi_process_message(struct ep93xx_spi *espi, { unsigned long timeout; struct spi_transfer *t; - int err; - - /* - * Enable the SPI controller and its clock. - */ - err = ep93xx_spi_enable(espi); - if (err) { - dev_err(&espi->pdev->dev, "failed to enable SPI controller\n"); - msg->status = err; - return; - } /* * Just to be sure: flush any data from RX FIFO. @@ -619,7 +581,6 @@ static void ep93xx_spi_process_message(struct ep93xx_spi *espi, * deselect the device and disable the SPI controller. */ ep93xx_spi_cs_control(msg->spi, false); - ep93xx_spi_disable(espi); } static int ep93xx_spi_transfer_one_message(struct spi_master *master, @@ -679,6 +640,37 @@ static irqreturn_t ep93xx_spi_interrupt(int irq, void *dev_id) return IRQ_HANDLED; } +static int ep93xx_spi_prepare_hardware(struct spi_master *master) +{ + struct ep93xx_spi *espi = spi_master_get_devdata(master); + u32 val; + int ret; + + ret = clk_enable(espi->clk); + if (ret) + return ret; + + val = readl(espi->mmio + SSPCR1); + val |= SSPCR1_SSE; + writel(val, espi->mmio + SSPCR1); + + return 0; +} + +static int ep93xx_spi_unprepare_hardware(struct spi_master *master) +{ + struct ep93xx_spi *espi = spi_master_get_devdata(master); + u32 val; + + val = readl(espi->mmio + SSPCR1); + val &= ~SSPCR1_SSE; + writel(val, espi->mmio + SSPCR1); + + clk_disable(espi->clk); + + return 0; +} + static bool ep93xx_spi_dma_filter(struct dma_chan *chan, void *filter_param) { if (ep93xx_dma_chan_is_m2p(chan)) @@ -780,6 +772,8 @@ static int ep93xx_spi_probe(struct platform_device *pdev) if (!master) return -ENOMEM; + master->prepare_transfer_hardware = ep93xx_spi_prepare_hardware; + master->unprepare_transfer_hardware = ep93xx_spi_unprepare_hardware; master->transfer_one_message = ep93xx_spi_transfer_one_message; master->bus_num = pdev->id; master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;