From patchwork Fri Mar 22 06:29:26 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rajeshwari Shinde X-Patchwork-Id: 15525 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id E791D23E2C for ; Fri, 22 Mar 2013 06:23:31 +0000 (UTC) Received: from mail-vb0-f45.google.com (mail-vb0-f45.google.com [209.85.212.45]) by fiordland.canonical.com (Postfix) with ESMTP id 8D101A1806C for ; Fri, 22 Mar 2013 06:23:31 +0000 (UTC) Received: by mail-vb0-f45.google.com with SMTP id q16so104157vbe.4 for ; Thu, 21 Mar 2013 23:23:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf: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; bh=DvtnnWwsvVHfu0R1KxO2b8MrCqrWcRhkt5ZN1hotRB8=; b=gJ9kmwHBmmsSD+dR6Gt8a7VtFqGop8QkouLgRpNfG/Bp0wh7qrGv+DMVCJsSlhjzco 8Dg2A91+oNQug6aJhWx+VZIBk1eIi70kjZqMsc7v4zunQYVdE0uq7hWasI9bfqXCkmeU 5qAT40Kxa8k/2zQoMGHXsdI3rBEiohgCQ0dVQXWE0SCAd6fIdqvIqahsHqWjMyvpu454 vlhH/FiDGMFuVyBlU3d8gC72WpPv7PvqBAB41Aj4nboA44rSTGwX+iMV4qAVWjCP7/Ci 0N6MPFPmwG2Mjio0VSxrDUIK6ihazs48hRUOL7k3ylkyq31OT8/31o3PoIoWnNkEV9Np pTIg== X-Received: by 10.58.207.163 with SMTP id lx3mr681886vec.35.1363933410972; Thu, 21 Mar 2013 23:23:30 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.58.233.198 with SMTP id ty6csp92055vec; Thu, 21 Mar 2013 23:23:30 -0700 (PDT) X-Received: by 10.68.11.35 with SMTP id n3mr785923pbb.220.1363933410040; Thu, 21 Mar 2013 23:23:30 -0700 (PDT) Received: from mailout1.samsung.com (mailout1.samsung.com. [203.254.224.24]) by mx.google.com with ESMTP id yx4si1790523pac.73.2013.03.21.23.23.29; Thu, 21 Mar 2013 23:23:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of rajeshwari.s@samsung.com designates 203.254.224.24 as permitted sender) client-ip=203.254.224.24; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of rajeshwari.s@samsung.com designates 203.254.224.24 as permitted sender) smtp.mail=rajeshwari.s@samsung.com Received: from epcpsbgr5.samsung.com (u145.gpu120.samsung.co.kr [203.254.230.145]) by mailout1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MK1000BNTQJPU70@mailout1.samsung.com>; Fri, 22 Mar 2013 15:23:28 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.123]) by epcpsbgr5.samsung.com (EPCPMTA) with SMTP id A6.34.12250.0E8FB415; Fri, 22 Mar 2013 15:23:28 +0900 (KST) X-AuditID: cbfee691-b7f5f6d000002fda-3c-514bf8e05679 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id B0.CA.17838.0E8FB415; Fri, 22 Mar 2013 15:23:28 +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 <0MK100JW5TQV6080@mmp1.samsung.com>; Fri, 22 Mar 2013 15:23:28 +0900 (KST) From: Rajeshwari Shinde To: u-boot@lists.denx.de Cc: patches@linaro.org, sjg@chromium.org, mk7.kang@samsung.com, chander.kashyap@linaro.org Subject: [PATCH 2/2] EXYNOS: SPI: Support SPI_PREAMBLE mode Date: Fri, 22 Mar 2013 11:59:26 +0530 Message-id: <1363933766-6555-3-git-send-email-rajeshwari.s@samsung.com> X-Mailer: git-send-email 1.7.4.4 In-reply-to: <1363933766-6555-1-git-send-email-rajeshwari.s@samsung.com> References: <1363933766-6555-1-git-send-email-rajeshwari.s@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrGLMWRmVeSWpSXmKPExsWyRsSkWvfBD+9Ag7kT5Cwerr/JYtFxpIXR YsrhLywW37ZsY7R4u7eT3YHVY3bDRRaPO9f2sHmcvbOD0aNvyyrGAJYoLpuU1JzMstQifbsE royb+44xF/xSq1j0z6+BcYdcFyMHh4SAicTFjxldjJxAppjEhXvr2boYuTiEBJYySizdfp8F ImEicbdzGitEYhGjxOl9vSwQzkQmibkNW9lBqtgEjCS2npzGCGKLCEhI/Oq/CmYzC8RIvN7/ gw3EFhawlni97DE7yGYWAVWJdXtiQcK8Au4Sh7+sg1qmIHFs6ldWEJtTwEPi+OdFYK1CQDUv Z9xgB9krIdDMLnHp/G+wvSwCAhLfJh9igfhGVmLTAWaIOZISB1fcYJnAKLyAkWEVo2hqQXJB cVJ6kalecWJucWleul5yfu4mRmAYn/73bOIOxvsHrA8xJgONm8gsJZqcD4yDvJJ4Q2MzIwtT E1NjI3NLM9KElcR51VusA4UE0hNLUrNTUwtSi+KLSnNSiw8xMnFwSjUwln3Kt10z+dPtNy/n Kew5Hb71ZvFWl8/cUxyczm3MWrj/ZX8Z64oZS06Zv7BaU1G0e5mr0P4r7v1rvM8mWIRwMHZE J105ktcjvdLs9IR/73ovbjZ6q6E/8faswqdvSkSneE6xrtyX9LgyNFnDx717jhlXsaC9zb3N HpGsTj9WVdj987rT4sW2XYmlOCPRUIu5qDgRAO+PSBZ5AgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrCIsWRmVeSWpSXmKPExsVy+t9jAd0HP7wDDS4/ELV4uP4mi0XHkRZG iymHv7BYfNuyjdHi7d5OdgdWj9kNF1k87lzbw+Zx9s4ORo++LasYA1iiGhhtMlITU1KLFFLz kvNTMvPSbZW8g+Od403NDAx1DS0tzJUU8hJzU22VXHwCdN0yc4A2KymUJeaUAoUCEouLlfTt ME0IDXHTtYBpjND1DQmC6zEyQAMJaxgzbu47xlzwS61i0T+/BsYdcl2MnBwSAiYSdzunsULY YhIX7q1n62Lk4hASWMQocXpfLwuEM5FJYm7DVnaQKjYBI4mtJ6cxgtgiAhISv/qvgtnMAjES r/f/YAOxhQWsJV4vewxUz8HBIqAqsW5PLEiYV8Bd4vCXdSwQyxQkjk39CraYU8BD4vjnRWCt QkA1L2fcYJ/AyLuAkWEVo2hqQXJBcVJ6rqFecWJucWleul5yfu4mRnCcPJPawbiyweIQowAH oxIPr4aOd6AQa2JZcWXuIUYJDmYlEd7IFKAQb0piZVVqUX58UWlOavEhxmSgoyYyS4km5wNj OK8k3tDYxNzU2NTSxMLEzJI0YSVx3gOt1oFCAumJJanZqakFqUUwW5g4OKUaGI3TLLq6WLR2 Xvzj/rLoley2MNGUP5vvH3992GaThGvlwcUls7RWV62KnWL2/Mnau+9m6FjNNcwT/H8jaJ2G 1Oo5wYVZPAZPxM6t92Q4YLt5ZiyP0RbPviS/S5+styWfbN5ibKr1P+7hdLaNvk37lVXtW0o6 M3V8F8jFbdzc83YCu+5f/7vG7kosxRmJhlrMRcWJACsqVr3XAgAA DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected X-Gm-Message-State: ALoCoQnqRjVZWCnbmUVe3b+3ZyCUTOf9CSbmIigE+ICf9KttsOO4RQjoYjPE4j5HsVM5ZDL8oWYq 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 --- drivers/spi/exynos_spi.c | 62 ++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 54 insertions(+), 8 deletions(-) diff --git a/drivers/spi/exynos_spi.c b/drivers/spi/exynos_spi.c index be60ada..09e88d5 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) @@ -107,6 +108,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); @@ -219,17 +222,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, preamable_count = 0; + 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. @@ -240,6 +249,7 @@ 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; @@ -252,13 +262,41 @@ static void spi_rx_tx(struct exynos_spi_slave *spi_slave, int todo, } if (rx_lvl > 0 && in_bytes) { temp = readl(®s->rx_data); - if (rxp) + if (!rxp && !stopping) { + in_bytes--; + } else if (spi_slave->skip_preamble) { + if (temp == SPI_PREAMBLE_END_BYTE) { + spi_slave->skip_preamble = 0; + stopping = 0; + } + } else { *rxp++ = temp; - in_bytes--; + in_bytes--; + } + 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. + */ + else if (in_bytes && !toread) { + assert(!out_bytes); + toread = out_bytes = 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); + printf("count = %d\n", preamable_count); + return -1; } } *dinp = rxp; *doutp = txp; + return 0; } /** @@ -278,6 +316,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) { @@ -291,16 +330,22 @@ 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); } /* 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; } /** @@ -327,6 +372,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; } /**