Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5954938yba; Mon, 13 May 2019 22:05:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqx+sjfphoZq2aSexfkFhh/NHaxnXQd/aPalsHY+6V9DII0pXEIUR5xtom8SGbb1s0UnOEum X-Received: by 2002:a63:9d8d:: with SMTP id i135mr36292158pgd.245.1557810322088; Mon, 13 May 2019 22:05:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557810322; cv=none; d=google.com; s=arc-20160816; b=nbw+WbfExZSxQTxJ+e07NPKWfdnJSDFLE/SQA5Im6ePkzwKm0Eard05bkEe9MW1N96 22Bl2qWK0dFBpXqWzFgrajfgtsTKjGzIyOWqC1SzwEPRGQVFZdpZ24Ttsdl0zK3seLRA MIyVzFiZLdxXY7SK4t7H3m5JxQrFIlTQi27HSAtszJW8o1E7xC3ayGEKzrjR3cGgLh2t O4NKh9I7IzhRBzXNN5Bp6+Nd5jNwvXXmDZWMYnG9UPDJhOAVp3fKxNpMCgtbt77vKVKx kifxL64wgvAv2tI+1zHrKl4I3Ej9+oOwYUtl2JWbG7JzwqyIgumoagjjSXQl0MVuLzZj uLsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from; bh=0RKRq2bvltptfksFYSB9GGkwDLDaXxP6AB/leTsEVgY=; b=R/7MaKMgWda4XGZkunWpt8bY7G4XlJL0Zk5n4YOzgdvZ9HrXVDfNvkk+cW7ob/pJh6 TbLgCfPD+s2jil/bb+ZgHHWLYyC0/5jd27OJCYec4qPqZR/YKOQ9h4wYGarAY/4RsDoN 28QEz+zUt7ioSO2q+852vZKXnUcdAHOnKX1H4H1pqcDCA9KQ9Vv/OqgwU2DFTJSjJavR Sf2lJGVAKCketjx1T5qX1Ql1oYN0KcI7h3uBjvaryrSqNbm6sZbZmwWhtLLUtq6+mKNq r44rKkGNo24h+HxZfUJqec6vKlb9s2YN7c/gfLFZ/BwxgaJyPxuDKqOxIK8oWIqLSVBp TaQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=ZLz+A3oW; 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=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q2si20437582pfi.165.2019.05.13.22.05.06; Mon, 13 May 2019 22:05:22 -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=pass header.i=@nvidia.com header.s=n1 header.b=ZLz+A3oW; 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=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726838AbfENFEF (ORCPT + 99 others); Tue, 14 May 2019 01:04:05 -0400 Received: from hqemgate15.nvidia.com ([216.228.121.64]:17394 "EHLO hqemgate15.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726727AbfENFED (ORCPT ); Tue, 14 May 2019 01:04:03 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate15.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Mon, 13 May 2019 22:03:23 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Mon, 13 May 2019 22:04:02 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Mon, 13 May 2019 22:04:02 -0700 Received: from HQMAIL104.nvidia.com (172.18.146.11) by HQMAIL104.nvidia.com (172.18.146.11) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 14 May 2019 05:04:02 +0000 Received: from hqnvemgw01.nvidia.com (172.20.150.20) by HQMAIL104.nvidia.com (172.18.146.11) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Tue, 14 May 2019 05:04:02 +0000 Received: from skomatineni-linux.nvidia.com (Not Verified[10.2.164.159]) by hqnvemgw01.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Mon, 13 May 2019 22:04:02 -0700 From: Sowjanya Komatineni To: , , , CC: , , , Sowjanya Komatineni Subject: [PATCH V5 3/4] spi: tegra114: add support for HW CS timing Date: Mon, 13 May 2019 22:03:54 -0700 Message-ID: <1557810235-16401-4-git-send-email-skomatineni@nvidia.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1557810235-16401-1-git-send-email-skomatineni@nvidia.com> References: <1557810235-16401-1-git-send-email-skomatineni@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 Content-Type: text/plain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1557810203; bh=0RKRq2bvltptfksFYSB9GGkwDLDaXxP6AB/leTsEVgY=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=ZLz+A3oW04veRzkP1nIhIr6IfePDMkG0O3qmT6tZszN4Knng5F5HXNtCleLTwGf1e HZjxE6LZOnraY7H3JxjNYKbgKqlYsMJB/VllfUGE6fykhB5FEwqtO691xEks08Obf6 Wpp2PkyDB/v1+CISoUr2Q4w26q3weiqQTRkqmyRIuep3B4c+WUvkEBV2aRqv4ZMKbd SUoPQtCNxS1nh0GBdh984eIvjWsHlIllQ7K9xYVafvF936VgPda0CpptWB6aNPUKQQ Pi2UPyVBsPwguCC4ldHfxDFSs6XINUy0UsQo4df8ntzyF1g0Hm25TZ7XdqZPtDglhQ MTN9pi4WozCzQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch implements set_cs_timing SPI controller method to allow SPI client driver to configure device specific SPI CS timings. Signed-off-by: Sowjanya Komatineni --- drivers/spi/spi-tegra114.c | 48 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi-tegra114.c b/drivers/spi/spi-tegra114.c index 0cb0932d32fd..e59ff7c1cee6 100644 --- a/drivers/spi/spi-tegra114.c +++ b/drivers/spi/spi-tegra114.c @@ -95,8 +95,10 @@ (reg = (((val) & 0x1) << ((cs) * 8 + 5)) | \ ((reg) & ~(1 << ((cs) * 8 + 5)))) #define SPI_SET_CYCLES_BETWEEN_PACKETS(reg, cs, val) \ - (reg = (((val) & 0xF) << ((cs) * 8)) | \ - ((reg) & ~(0xF << ((cs) * 8)))) + (reg = (((val) & 0x1F) << ((cs) * 8)) | \ + ((reg) & ~(0x1F << ((cs) * 8)))) +#define MAX_SETUP_HOLD_CYCLES 16 +#define MAX_INACTIVE_CYCLES 32 #define SPI_TRANS_STATUS 0x010 #define SPI_BLK_CNT(val) (((val) >> 0) & 0xFFFF) @@ -206,6 +208,8 @@ struct tegra_spi_data { u32 command1_reg; u32 dma_control_reg; u32 def_command1_reg; + u32 spi_cs_timing1; + u32 spi_cs_timing2; struct completion xfer_completion; struct spi_transfer *curr_xfer; @@ -723,6 +727,43 @@ static void tegra_spi_deinit_dma_param(struct tegra_spi_data *tspi, dma_release_channel(dma_chan); } +static void tegra_spi_set_hw_cs_timing(struct spi_device *spi, u8 setup_dly, + u8 hold_dly, u8 inactive_dly) +{ + struct tegra_spi_data *tspi = spi_master_get_devdata(spi->master); + u32 setup_hold; + u32 spi_cs_timing; + u32 inactive_cycles; + u8 cs_state; + + setup_dly = min_t(u8, setup_dly, MAX_SETUP_HOLD_CYCLES); + hold_dly = min_t(u8, hold_dly, MAX_SETUP_HOLD_CYCLES); + if (setup_dly && hold_dly) { + setup_hold = SPI_SETUP_HOLD(setup_dly - 1, hold_dly - 1); + spi_cs_timing = SPI_CS_SETUP_HOLD(tspi->spi_cs_timing1, + spi->chip_select, + setup_hold); + if (tspi->spi_cs_timing1 != spi_cs_timing) { + tspi->spi_cs_timing1 = spi_cs_timing; + tegra_spi_writel(tspi, spi_cs_timing, SPI_CS_TIMING1); + } + } + + inactive_cycles = min_t(u8, inactive_dly, MAX_INACTIVE_CYCLES); + if (inactive_cycles) + inactive_cycles--; + cs_state = inactive_cycles ? 0 : 1; + spi_cs_timing = tspi->spi_cs_timing2; + SPI_SET_CS_ACTIVE_BETWEEN_PACKETS(spi_cs_timing, spi->chip_select, + cs_state); + SPI_SET_CYCLES_BETWEEN_PACKETS(spi_cs_timing, spi->chip_select, + inactive_cycles); + if (tspi->spi_cs_timing2 != spi_cs_timing) { + tspi->spi_cs_timing2 = spi_cs_timing; + tegra_spi_writel(tspi, spi_cs_timing, SPI_CS_TIMING2); + } +} + static u32 tegra_spi_setup_transfer_one(struct spi_device *spi, struct spi_transfer *t, bool is_first_of_msg, @@ -1232,6 +1273,7 @@ static int tegra_spi_probe(struct platform_device *pdev) master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32); master->setup = tegra_spi_setup; master->transfer_one_message = tegra_spi_transfer_one_message; + master->set_cs_timing = tegra_spi_set_hw_cs_timing; master->num_chipselect = MAX_CHIP_SELECT; master->auto_runtime_pm = true; bus_num = of_alias_get_id(pdev->dev.of_node, "spi"); @@ -1307,6 +1349,8 @@ static int tegra_spi_probe(struct platform_device *pdev) reset_control_deassert(tspi->rst); tspi->def_command1_reg = SPI_M_S; tegra_spi_writel(tspi, tspi->def_command1_reg, SPI_COMMAND1); + tspi->spi_cs_timing1 = tegra_spi_readl(tspi, SPI_CS_TIMING1); + tspi->spi_cs_timing2 = tegra_spi_readl(tspi, SPI_CS_TIMING2); pm_runtime_put(&pdev->dev); ret = request_threaded_irq(tspi->irq, tegra_spi_isr, tegra_spi_isr_thread, IRQF_ONESHOT, -- 2.7.4