Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp501287img; Mon, 18 Mar 2019 07:53:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqxaBQ3+LMlAvgFKFFfyB1cjdGQQzDb01vfnEpVjdx6eXAqucFIoRSphX2ljJfmTS9Cbp4b5 X-Received: by 2002:a17:902:a612:: with SMTP id u18mr19909865plq.145.1552920825736; Mon, 18 Mar 2019 07:53:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552920825; cv=none; d=google.com; s=arc-20160816; b=ZAebzmJdLtwlpO/9ErWKNGZcaTWTUKU6uyIScpG7IRmQ7FB2Ru0VuiMjDDvOJCL8h5 1ai7kM6XPbQsLHHLJdzimUdV1P9wFtvrdaFzXR7dgk96hvokDcLVfgb7ff3b4T+bMsFM UwMpXWUYT4/Ij2W2g/HWIy/Ltu3vIRWEO+GTrXwS2OfJepd0tmz1DSBAeJ1pDhKEGyrE t2nBxCW9VCq5F8qvj2XG3irmJMA7QpCA3uhEOklStVRg+1gqjEzHQ13c6YSdiB8c2Khn /1Z2ol1oaq5VrWq9OjIMft1Xrg1vs1X/PixCMTJ1F2ohi8+wgQ2K+Q3U+jlNOUKgzlno LxSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:message-id:in-reply-to:subject:cc:to :from:dkim-signature; bh=7iNLrKNFfsFI4ahXFRhYvdw8dGz2OhledZhxn+3r9Zs=; b=FWnkat6/Lv3iVf8lUkThAUdQ5/zPlsx9EYY/uDgEGxm580NpNofp27lQf6TQgjXJCr RH8QCtdWlPbnibO1GhX5QyWlnoRjcpu7knWzbRj2ArMt3OwfAd/BnI76noplSKAlC+tn BLKmnSAFj6/+Dp24ujr4AOjoejdojDlsvwiT4UdmIk8giJzgPGUnb0A7BGEJ5lmBGcwD uD8NG2tpYBk9j4n3HMAqv1xAaAer65IhunPbyyYE9Id0DWfz/IG3eU29ygXBDsIDR8gD /rHmEvz7Y/IvcQTBjQsACR3cprGuRSIEXDV+26FG7+sVIjVV1JmNYakkezDQ2Ye05jxp Mo/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@sirena.org.uk header.s=20170815-heliosphere header.b=uIfFANzy; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k1si10000733pld.332.2019.03.18.07.53.30; Mon, 18 Mar 2019 07:53:45 -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=@sirena.org.uk header.s=20170815-heliosphere header.b=uIfFANzy; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727979AbfCROwT (ORCPT + 99 others); Mon, 18 Mar 2019 10:52:19 -0400 Received: from heliosphere.sirena.org.uk ([172.104.155.198]:56226 "EHLO heliosphere.sirena.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728001AbfCROwQ (ORCPT ); Mon, 18 Mar 2019 10:52:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sirena.org.uk; s=20170815-heliosphere; h=Date:Message-Id:In-Reply-To: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:References: List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner: List-Archive; bh=7iNLrKNFfsFI4ahXFRhYvdw8dGz2OhledZhxn+3r9Zs=; b=uIfFANzylAyI I13fM7vuJibnx3Y3oC4Ro5WksXgjdOPirjG6QcCvPNBch5ketUhzj2F5OXT9QhLjoyvvCsO4GMX5l aohGDgmLIrZdOB04+Dz7KcQd0R5OBSkNDvkpDyvVqgJkBE7UvSqDQdAnjyRuyHpXvmcEoEUGjfohb jzv5E=; Received: from cpc102320-sgyl38-2-0-cust46.18-2.cable.virginm.net ([82.37.168.47] helo=debutante.sirena.org.uk) by heliosphere.sirena.org.uk with esmtpa (Exim 4.89) (envelope-from ) id 1h5tca-0005q4-MW; Mon, 18 Mar 2019 14:52:12 +0000 Received: by debutante.sirena.org.uk (Postfix, from userid 1000) id 32ADB1128874; Mon, 18 Mar 2019 14:52:12 +0000 (GMT) From: Mark Brown To: Clark Wang Cc: Fugang Duan , Mark Brown , "broonie@kernel.org" , "linux-spi@vger.kernel.org" , "linux-kernel@vger.kernel.org" , linux-spi@vger.kernel.org Subject: Applied "spi: lpspi: use the core way to implement cs-gpio function" to the spi tree In-Reply-To: <20190306063020.793-6-xiaoning.wang@nxp.com> X-Patchwork-Hint: ignore Message-Id: <20190318145212.32ADB1128874@debutante.sirena.org.uk> Date: Mon, 18 Mar 2019 14:52:12 +0000 (GMT) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The patch spi: lpspi: use the core way to implement cs-gpio function has been applied to the spi tree at https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted. You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed. If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced. Please add any relevant lists and maintainers to the CCs when replying to this mail. Thanks, Mark From c7a402599504384efe0e5232a4c78cb8eb7cb3d0 Mon Sep 17 00:00:00 2001 From: Clark Wang Date: Wed, 6 Mar 2019 06:30:43 +0000 Subject: [PATCH] spi: lpspi: use the core way to implement cs-gpio function Use the default implementation of transfer_one_msg/chipselect/setup functions in spi core to implement cs-gpio control. Use fsl_lpspi_prepare_message to init the cs_gpio pin. Signed-off-by: Clark Wang Acked-by: Fugang Duan Signed-off-by: Mark Brown --- drivers/spi/spi-fsl-lpspi.c | 101 +++++++++++++++++++++++------------- 1 file changed, 66 insertions(+), 35 deletions(-) diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c index 69635cde0e22..a25e0e03f058 100644 --- a/drivers/spi/spi-fsl-lpspi.c +++ b/drivers/spi/spi-fsl-lpspi.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -16,8 +17,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -91,6 +94,7 @@ struct fsl_lpspi_data { struct clk *clk_ipg; struct clk *clk_per; bool is_slave; + bool is_first_byte; void *rx_buf; const void *tx_buf; @@ -106,6 +110,8 @@ struct fsl_lpspi_data { struct completion xfer_done; bool slave_aborted; + + int chipselect[0]; }; static const struct of_device_id fsl_lpspi_dt_ids[] = { @@ -178,6 +184,20 @@ static int lpspi_unprepare_xfer_hardware(struct spi_controller *controller) return 0; } +static int fsl_lpspi_prepare_message(struct spi_controller *controller, + struct spi_message *msg) +{ + struct fsl_lpspi_data *fsl_lpspi = + spi_controller_get_devdata(controller); + struct spi_device *spi = msg->spi; + int gpio = fsl_lpspi->chipselect[spi->chip_select]; + + if (gpio_is_valid(gpio)) + gpio_direction_output(gpio, spi->mode & SPI_CS_HIGH ? 0 : 1); + + return 0; +} + static void fsl_lpspi_write_tx_fifo(struct fsl_lpspi_data *fsl_lpspi) { u8 txfifo_cnt; @@ -210,8 +230,7 @@ static void fsl_lpspi_read_rx_fifo(struct fsl_lpspi_data *fsl_lpspi) fsl_lpspi->rx(fsl_lpspi); } -static void fsl_lpspi_set_cmd(struct fsl_lpspi_data *fsl_lpspi, - bool is_first_xfer) +static void fsl_lpspi_set_cmd(struct fsl_lpspi_data *fsl_lpspi) { u32 temp = 0; @@ -227,7 +246,7 @@ static void fsl_lpspi_set_cmd(struct fsl_lpspi_data *fsl_lpspi, * For subsequent transfer, set TCR_CONTC to keep SS asserted. */ temp |= TCR_CONT; - if (is_first_xfer) + if (fsl_lpspi->is_first_byte) temp &= ~TCR_CONTC; else temp |= TCR_CONTC; @@ -396,8 +415,7 @@ static int fsl_lpspi_reset(struct fsl_lpspi_data *fsl_lpspi) return 0; } -static int fsl_lpspi_transfer_one(struct spi_controller *controller, - struct spi_device *spi, +static int fsl_lpspi_pio_transfer(struct spi_controller *controller, struct spi_transfer *t) { struct fsl_lpspi_data *fsl_lpspi = @@ -422,40 +440,27 @@ static int fsl_lpspi_transfer_one(struct spi_controller *controller, return 0; } -static int fsl_lpspi_transfer_one_msg(struct spi_controller *controller, - struct spi_message *msg) +static int fsl_lpspi_transfer_one(struct spi_controller *controller, + struct spi_device *spi, + struct spi_transfer *t) { struct fsl_lpspi_data *fsl_lpspi = - spi_controller_get_devdata(controller); - struct spi_device *spi = msg->spi; - struct spi_transfer *xfer; - bool is_first_xfer = true; - int ret = 0; - - msg->status = 0; - msg->actual_length = 0; - - list_for_each_entry(xfer, &msg->transfers, transfer_list) { - ret = fsl_lpspi_setup_transfer(spi, xfer); - if (ret < 0) - goto complete; - - fsl_lpspi_set_cmd(fsl_lpspi, is_first_xfer); - - is_first_xfer = false; + spi_controller_get_devdata(controller); + int ret; - ret = fsl_lpspi_transfer_one(controller, spi, xfer); - if (ret < 0) - goto complete; + fsl_lpspi->is_first_byte = true; + ret = fsl_lpspi_setup_transfer(spi, t); + if (ret < 0) + return ret; - msg->actual_length += xfer->len; - } + fsl_lpspi_set_cmd(fsl_lpspi); + fsl_lpspi->is_first_byte = false; -complete: - msg->status = ret; - spi_finalize_current_message(controller); + ret = fsl_lpspi_pio_transfer(controller, t); + if (ret < 0) + return ret; - return ret; + return 0; } static irqreturn_t fsl_lpspi_isr(int irq, void *dev_id) @@ -531,10 +536,13 @@ static int fsl_lpspi_init_rpm(struct fsl_lpspi_data *fsl_lpspi) static int fsl_lpspi_probe(struct platform_device *pdev) { + struct device_node *np = pdev->dev.of_node; struct fsl_lpspi_data *fsl_lpspi; struct spi_controller *controller; + struct spi_imx_master *lpspi_platform_info = + dev_get_platdata(&pdev->dev); struct resource *res; - int ret, irq; + int i, ret, irq; u32 temp; if (of_property_read_bool((&pdev->dev)->of_node, "spi-slave")) @@ -558,7 +566,30 @@ static int fsl_lpspi_probe(struct platform_device *pdev) fsl_lpspi->is_slave = of_property_read_bool((&pdev->dev)->of_node, "spi-slave"); - controller->transfer_one_message = fsl_lpspi_transfer_one_msg; + if (!fsl_lpspi->is_slave) { + for (i = 0; i < controller->num_chipselect; i++) { + int cs_gpio = of_get_named_gpio(np, "cs-gpios", i); + + if (!gpio_is_valid(cs_gpio) && lpspi_platform_info) + cs_gpio = lpspi_platform_info->chipselect[i]; + + fsl_lpspi->chipselect[i] = cs_gpio; + if (!gpio_is_valid(cs_gpio)) + continue; + + ret = devm_gpio_request(&pdev->dev, + fsl_lpspi->chipselect[i], + DRIVER_NAME); + if (ret) { + dev_err(&pdev->dev, "can't get cs gpios\n"); + goto out_controller_put; + } + } + controller->cs_gpios = fsl_lpspi->chipselect; + controller->prepare_message = fsl_lpspi_prepare_message; + } + + controller->transfer_one = fsl_lpspi_transfer_one; controller->prepare_transfer_hardware = lpspi_prepare_xfer_hardware; controller->unprepare_transfer_hardware = lpspi_unprepare_xfer_hardware; controller->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH; -- 2.20.1