From patchwork Fri May 3 04:53:49 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vadim Bendebury X-Patchwork-Id: 16611 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f71.google.com (mail-yh0-f71.google.com [209.85.213.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C7DB0238EC for ; Fri, 3 May 2013 04:54:20 +0000 (UTC) Received: by mail-yh0-f71.google.com with SMTP id a41sf2326760yho.10 for ; Thu, 02 May 2013 21:54:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:x-beenthere:x-received:received-spf:x-received :x-forwarded-to:x-forwarded-for:delivered-to:x-received:received-spf :x-received:mime-version:from:date:message-id:subject:to:cc :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:x-google-group-id:list-post:list-help :list-archive:list-unsubscribe:content-type; bh=onNjGeGDxy0CYuhsrA/E6qxcmmij98v3heDS2NQo7JU=; b=KoEcBWrsLtYWxzVoraNq2XyC1ch7Bd7DKuTGChrjnTDTNjeAivAu3sqfXxYVdta3GR L/6kLiVyESBhGs3tnxE5hl44DWXUkrrpmmEBvqJigQ60Lxe+jp9AMIdLY5mqvy1y/Vd1 QVd7P6mYiZ/NIFB64vhQH6Ww/dFWDDV5EdPiVHKiVPGsq+8ZZ7zV+JVbvW/RSO3fxUlZ x5OKEsi8PP3uLojj5cFem60+qcxzE8HesSfGb4XzFuGdkh8d/IqY0JcTVl+hUKQ9fMVn cCNrMQ8YCEySiFGeH1iQVGpuus3uagbxofx1FV9n19V3mYpfEsf8YiuQ3qE29mmAb+7x ihBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-beenthere:x-received:received-spf:x-received :x-forwarded-to:x-forwarded-for:delivered-to:x-received:received-spf :x-received:mime-version:from:date:message-id:subject:to:cc :x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe :content-type; bh=onNjGeGDxy0CYuhsrA/E6qxcmmij98v3heDS2NQo7JU=; b=U08hWuoaafUpOaGHEI178b8AUFXVp3e/EBlxbdaGFDaDHGNABG1HSHb4sgSjULG6s9 pGNraLwzv+P8R+xzPbNAIg/LzD1aEU/dcHSYzl9pU1uvNO5u9eT5rsDIbvDqLQ+E9sj5 LB6YpsJTM+IVFpg3Qs9YwraOmsMCbmlqrXqotW7/dQM/ApVOelFnBPqXNoprPiaY6rAx +Aw88m//7YO63btxiejqMYDiKcKKsbTlbFzgomAbypP3RXR66UYba7c22LuIrf6lAF71 xGVm/bcGgxSlWc+6waBdzT3h58ijNNoP0iKrt0kJ/AmDpkV3S3qEAzMLWa/974avlV8Y tC9w== X-Received: by 10.236.91.206 with SMTP id h54mr7197798yhf.27.1367556851651; Thu, 02 May 2013 21:54:11 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.58.172 with SMTP id s12ls1578000qeq.18.gmail; Thu, 02 May 2013 21:54:11 -0700 (PDT) X-Received: by 10.52.165.36 with SMTP id yv4mr1819599vdb.31.1367556851494; Thu, 02 May 2013 21:54:11 -0700 (PDT) Received: from mail-vb0-x231.google.com (mail-vb0-x231.google.com [2607:f8b0:400c:c02::231]) by mx.google.com with ESMTPS id bz7si4440309vcb.9.2013.05.02.21.54.11 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 02 May 2013 21:54:11 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c02::231 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=2607:f8b0:400c:c02::231; Received: by mail-vb0-f49.google.com with SMTP id q12so1082739vbe.36 for ; Thu, 02 May 2013 21:54:11 -0700 (PDT) X-Received: by 10.52.66.101 with SMTP id e5mr2698454vdt.57.1367556851293; Thu, 02 May 2013 21:54:11 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.58.127.98 with SMTP id nf2csp5360veb; Thu, 2 May 2013 21:54:10 -0700 (PDT) X-Received: by 10.112.149.226 with SMTP id ud2mr3788443lbb.13.1367556849710; Thu, 02 May 2013 21:54:09 -0700 (PDT) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com [209.85.217.182]) by mx.google.com with ESMTPS id dm9si1569152lbc.152.2013.05.02.21.54.09 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 02 May 2013 21:54:09 -0700 (PDT) Received-SPF: pass (google.com: domain of vbendeb@gmail.com designates 209.85.217.182 as permitted sender) client-ip=209.85.217.182; Received: by mail-lb0-f182.google.com with SMTP id r11so1181586lbv.41 for ; Thu, 02 May 2013 21:54:09 -0700 (PDT) X-Received: by 10.112.162.130 with SMTP id ya2mr3667335lbb.122.1367556849081; Thu, 02 May 2013 21:54:09 -0700 (PDT) MIME-Version: 1.0 Received: by 10.114.71.138 with HTTP; Thu, 2 May 2013 21:53:49 -0700 (PDT) From: Vadim Bendebury Date: Thu, 2 May 2013 21:53:49 -0700 Message-ID: Subject: [U-Boot] [PATCH 2/2] EXYNOS: SPI: Support SPI_PREAMBLE mode To: Rajeshwari Shinde , Simon Glass Cc: uboot , patches@linaro.org X-Gm-Message-State: ALoCoQkVcPx9a0cII1o/3a3WfKFVqfkPCg3p5T6bQc187wIlMiHs6hiw2+ho68luRFKQUmxLTaa8 X-Original-Sender: vbendeb@gmail.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c02::231 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@gmail.com Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , [the original patch removed] So, I spent some more time debugging a system which requires this patch: a system, where on a SPI interface a response to a command could come way later then the command data transmission completes. The original patch was trying to address many corner cases, but come to think of it, in this situation the slave does not care about extra data sent on the transmit interface, as otherwise there is no clock and no data could be transferred from the slave. Then, for this SPI interface we do not need to set the counter of clocks, and do not need to keep adding more clocks if the data has not been received yet, the clocks could be just free running. And then the patch becomes much simpler, what do you think: * Bytes are transmitted/received in pairs. Wait to receive all the @@ -243,13 +249,23 @@ static void spi_rx_tx(struct exynos_spi_slave *spi_slave, int todo, /* Keep the fifos full/empty. */ spi_get_fifo_levels(regs, &rx_lvl, &tx_lvl); - if (tx_lvl < spi_slave->fifo_size && out_bytes) { - temp = txp ? *txp++ : 0xff; + if (tx_lvl < spi_slave->fifo_size) { + if (txp && out_bytes) { + temp = *txp++; + out_bytes--; + } else { + temp = 0xff; + } writel(temp, ®s->tx_data); - out_bytes--; } if (rx_lvl > 0 && in_bytes) { temp = readl(®s->rx_data); + if (hunting) { + if ((temp & 0xff) != PREAMBLE_VALUE) + continue; + else + hunting = 0; + } if (rxp) *rxp++ = temp; in_bytes--; diff --git a/drivers/spi/exynos_spi.c b/drivers/spi/exynos_spi.c index c697db8..fff8310 100644 --- a/drivers/spi/exynos_spi.c +++ b/drivers/spi/exynos_spi.c @@ -211,10 +211,10 @@ static void spi_get_fifo_levels(struct exynos_spi *regs, */ static void spi_request_bytes(struct exynos_spi *regs, int count) { - assert(count && count < (1 << 16)); setbits_le32(®s->ch_cfg, SPI_CH_RST); clrbits_le32(®s->ch_cfg, SPI_CH_RST); - writel(count | SPI_PACKET_CNT_EN, ®s->pkt_cnt); + if (count) + writel(count | SPI_PACKET_CNT_EN, ®s->pkt_cnt); } static void spi_rx_tx(struct exynos_spi_slave *spi_slave, int todo, @@ -225,14 +225,20 @@ static void spi_rx_tx(struct exynos_spi_slave *spi_slave, int todo, const uchar *txp = *doutp; int rx_lvl, tx_lvl; uint out_bytes, in_bytes; - + int hunting; + + if (spi_slave->free_running_mode) { + spi_request_bytes(regs, 0); + hunting = 1; + } else { + hunting = 0; + spi_request_bytes(regs, todo); + } out_bytes = in_bytes = todo; - /* - * If there's something to send, do a software reset and set a - * transaction size. - */ - spi_request_bytes(regs, todo); + /* Software reset the channel. */ + setbits_le32(®s->ch_cfg, SPI_CH_RST); + clrbits_le32(®s->ch_cfg, SPI_CH_RST); /*