From patchwork Fri May 24 13:54:54 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rajeshwari Shinde X-Patchwork-Id: 17202 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f197.google.com (mail-vc0-f197.google.com [209.85.220.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B55DB238FC for ; Fri, 24 May 2013 13:48:41 +0000 (UTC) Received: by mail-vc0-f197.google.com with SMTP id m17sf5635412vca.0 for ; Fri, 24 May 2013 06:47:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-beenthere:x-forwarded-to:x-forwarded-for :delivered-to:x-auditid:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-brightmail-tracker:x-brightmail-tracker :dlp-filter:x-mtr:x-cfilter-loop: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; bh=wH9VVzqJ/ygYHKTQO5yM64XpnpLZFjwWhrueCYtFYCI=; b=Yv6aBOyH5dFPLsiipMYKwzWk9YAb2Ad253IF4TFX5+cwPdmB0xugvBiqVBbplqqMPq HyDH7W+w18BPasoPTT6gvQhxeXn+YMbpEj9thFNzuUSW8Rc7x96ci86qT81jQjmBPT4k 9PSvdzvoRJTRSjxeZxQVgt3OKwQId37G+xBUVvrvHHJzW0ga3XViqG4p4MTF+OTfeXWc ul0kVUZaZl/ry/pPlhxfcTZJFfN+7afh2+BiS0eOhd4giOEkpaGE++uCKO/OERyyiBiZ g5Gzqob3xrc4MSte99VIllAptpkNkJfPM8+KtCxk8aWrWI2nEUKvVTF7TaH9W3HPD293 QgDg== X-Received: by 10.224.59.205 with SMTP id m13mr8644332qah.7.1369403264130; Fri, 24 May 2013 06:47:44 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.134.8 with SMTP id pg8ls2025382qeb.43.gmail; Fri, 24 May 2013 06:47:44 -0700 (PDT) X-Received: by 10.58.215.200 with SMTP id ok8mr8598406vec.21.1369403264001; Fri, 24 May 2013 06:47:44 -0700 (PDT) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id r12si9517147vcv.12.2013.05.24.06.47.43 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 24 May 2013 06:47:43 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.174 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.174; Received: by mail-vc0-f174.google.com with SMTP id hr11so3147884vcb.33 for ; Fri, 24 May 2013 06:47:43 -0700 (PDT) X-Received: by 10.220.238.4 with SMTP id kq4mr8607255vcb.73.1369403263868; Fri, 24 May 2013 06:47:43 -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.220.126.138 with SMTP id c10csp102445vcs; Fri, 24 May 2013 06:47:43 -0700 (PDT) X-Received: by 10.68.255.130 with SMTP id aq2mr17459320pbd.164.1369403262947; Fri, 24 May 2013 06:47:42 -0700 (PDT) Received: from mailout4.samsung.com (mailout4.samsung.com. [203.254.224.34]) by mx.google.com with ESMTP id vs8si12890705pab.159.2013.05.24.06.47.42 for ; Fri, 24 May 2013 06:47:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of rajeshwari.s@samsung.com designates 203.254.224.34 as permitted sender) client-ip=203.254.224.34; Received: from epcpsbgr3.samsung.com (u143.gpu120.samsung.co.kr [203.254.230.143]) by mailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MNB0072U2BGN710@mailout4.samsung.com> for patches@linaro.org; Fri, 24 May 2013 22:47:41 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.122]) by epcpsbgr3.samsung.com (EPCPMTA) with SMTP id C0.1D.03969.D7F6F915; Fri, 24 May 2013 22:47:41 +0900 (KST) X-AuditID: cbfee68f-b7f436d000000f81-e3-519f6f7d866d Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 6A.0A.28381.D7F6F915; Fri, 24 May 2013 22:47:41 +0900 (KST) Received: from rajeshwari-linux.sisodomain.com ([107.108.215.115]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MNB009282A1MN40@mmp1.samsung.com>; Fri, 24 May 2013 22:47:41 +0900 (KST) From: Rajeshwari Shinde To: u-boot@lists.denx.de Cc: patches@linaro.org, sjg@chromium.org, mk7.kang@samsung.com, u-boot-review@google.com Subject: [PATCH 2/2 V4] EXYNOS: SPI: Support SPI_PREAMBLE mode Date: Fri, 24 May 2013 19:24:54 +0530 Message-id: <1369403694-15098-3-git-send-email-rajeshwari.s@samsung.com> X-Mailer: git-send-email 1.7.4.4 In-reply-to: <1369403694-15098-1-git-send-email-rajeshwari.s@samsung.com> References: <1369403694-15098-1-git-send-email-rajeshwari.s@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrDLMWRmVeSWpSXmKPExsWyRsSkSrc2f36gwe1GaYuOIy2MFlMOf2Gx +LZlG6PF8tcb2S3e7u1kd2D1mN1wkcVjwaZSjzvX9rB5nL2zg9Gjb8sqxgDWKC6blNSczLLU In27BK6MN/M/sRV0aFVs/zuXpYHxjkIXIyeHhICJxOq27awQtpjEhXvr2boYuTiEBJYySrRN mA2U4AArap9dARFfxCgx99MzqKKJTBL9e6cygXSzCRhJbD05jRHEFhGQkPjVfxXMZhaIkvje fYkdxBYWsJPY9baFGcRmEVCVuDNvHpjNK+Ah0bt4CtQVChLHpn4FszkF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BbGHi4JRqYFTi W/W4OMP0c36EVuyH7LyvEpKZJxttDYz/+d5K+c/7/9olvROvDXh/Pbn3R6X5662biX8L1+80 2v2yfEX7YZmezPMXu9/w/fYrvyvQl7Jw+bo9ahlnJsc25HBECmlumLPQO50r4+zZw8d5L+wO ZwrtOuGocJT3iPPyo7t3uV05nbdbWMj9SoUSS3FGoqEWc1FxIgCqksR63AIAAA== DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected X-Gm-Message-State: ALoCoQmY06uDY/45PH/jNlGWnSqUdIFAR2GCs0/e6cSEphl1qPRucB5n2gtWqGzPfl8ObKtNp5kL X-Original-Sender: rajeshwari.s@samsung.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.174 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 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: , Support interfaces with a preamble before each received message. We handle this when the client has requested a SPI_XFER_END, meaning that we must close of the transaction. In this case we read until we see the preamble (or a timeout occurs), skipping all data before and including the preamble. The client will receive only data bytes after the preamble. Signed-off-by: Simon Glass Signed-off-by: Rajeshwari Shinde --- Changes in V2: - Remove preamable_count variable which is not really needed - Fix checkpatch warning (multiple assignments) Changes in V3: - Modified the if logic in spi_rx_tx function - Added blank lines as suggested by Minkyu Kang. - Removed in_bytes check in while loop. - Added a error check. Changes in V4: - Corrected a if condition. drivers/spi/exynos_spi.c | 69 +++++++++++++++++++++++++++++++++++++++------ 1 files changed, 59 insertions(+), 10 deletions(-) diff --git a/drivers/spi/exynos_spi.c b/drivers/spi/exynos_spi.c index 607e1cd..01378d0 100644 --- a/drivers/spi/exynos_spi.c +++ b/drivers/spi/exynos_spi.c @@ -51,6 +51,7 @@ struct exynos_spi_slave { unsigned int mode; enum periph_id periph_id; /* Peripheral ID for this device */ unsigned int fifo_size; + int skip_preamble; }; static struct spi_bus *spi_get_bus(unsigned dev_index) @@ -105,6 +106,8 @@ struct spi_slave *spi_setup_slave(unsigned int busnum, unsigned int cs, else spi_slave->fifo_size = 256; + spi_slave->skip_preamble = 0; + spi_slave->freq = bus->frequency; if (max_hz) spi_slave->freq = min(max_hz, spi_slave->freq); @@ -217,17 +220,23 @@ static void spi_request_bytes(struct exynos_spi *regs, int count) writel(count | SPI_PACKET_CNT_EN, ®s->pkt_cnt); } -static void spi_rx_tx(struct exynos_spi_slave *spi_slave, int todo, - void **dinp, void const **doutp) +static int spi_rx_tx(struct exynos_spi_slave *spi_slave, int todo, + void **dinp, void const **doutp, unsigned long flags) { struct exynos_spi *regs = spi_slave->regs; uchar *rxp = *dinp; const uchar *txp = *doutp; int rx_lvl, tx_lvl; uint out_bytes, in_bytes; + int toread; + unsigned start = get_timer(0); + int stopping; out_bytes = in_bytes = todo; + stopping = spi_slave->skip_preamble && (flags & SPI_XFER_END) && + !(spi_slave->mode & SPI_SLAVE); + /* * If there's something to send, do a software reset and set a * transaction size. @@ -238,6 +247,8 @@ static void spi_rx_tx(struct exynos_spi_slave *spi_slave, int todo, * Bytes are transmitted/received in pairs. Wait to receive all the * data because then transmission will be done as well. */ + toread = in_bytes; + while (in_bytes) { int temp; @@ -248,15 +259,43 @@ static void spi_rx_tx(struct exynos_spi_slave *spi_slave, int todo, writel(temp, ®s->tx_data); out_bytes--; } - if (rx_lvl > 0 && in_bytes) { + if (rx_lvl > 0) { temp = readl(®s->rx_data); - if (rxp) - *rxp++ = temp; - in_bytes--; + if (spi_slave->skip_preamble) { + if (temp == SPI_PREAMBLE_END_BYTE) { + spi_slave->skip_preamble = 0; + stopping = 0; + } + } else { + if (rxp || stopping) + *rxp++ = temp; + in_bytes--; + } + toread--; + } else if (!toread) { + /* + * We have run out of input data, but haven't read + * enough bytes after the preamble yet. Read some more, + * and make sure that we transmit dummy bytes too, to + * keep things going. + */ + assert(!out_bytes); + out_bytes = in_bytes; + toread = in_bytes; + txp = NULL; + spi_request_bytes(regs, toread); + } + if (spi_slave->skip_preamble && get_timer(start) > 100) { + printf("SPI timeout: in_bytes=%d, out_bytes=%d, ", + in_bytes, out_bytes); + return -1; } } + *dinp = rxp; *doutp = txp; + + return 0; } /** @@ -276,6 +315,7 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout, struct exynos_spi_slave *spi_slave = to_exynos_spi(slave); int upto, todo; int bytelen; + int ret = 0; /* spi core configured to do 8 bit transfers */ if (bitlen % 8) { @@ -289,16 +329,24 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout, /* Exynos SPI limits each transfer to 65535 bytes */ bytelen = bitlen / 8; - for (upto = 0; upto < bytelen; upto += todo) { + for (upto = 0; !ret && upto < bytelen; upto += todo) { todo = min(bytelen - upto, (1 << 16) - 1); - spi_rx_tx(spi_slave, todo, &din, &dout); + ret = spi_rx_tx(spi_slave, todo, &din, &dout, flags); + if (ret) + break; } /* Stop the transaction, if necessary. */ - if ((flags & SPI_XFER_END)) + if ((flags & SPI_XFER_END) && !(spi_slave->mode & SPI_SLAVE)) { spi_cs_deactivate(slave); + if (spi_slave->skip_preamble) { + assert(!spi_slave->skip_preamble); + debug("Failed to complete premable transaction\n"); + ret = -1; + } + } - return 0; + return ret; } /** @@ -325,6 +373,7 @@ void spi_cs_activate(struct spi_slave *slave) clrbits_le32(&spi_slave->regs->cs_reg, SPI_SLAVE_SIG_INACT); debug("Activate CS, bus %d\n", spi_slave->slave.bus); + spi_slave->skip_preamble = spi_slave->mode & SPI_PREAMBLE; } /**