Received: by 10.223.164.202 with SMTP id h10csp1282881wrb; Wed, 15 Nov 2017 16:57:04 -0800 (PST) X-Google-Smtp-Source: AGs4zMb2ep/Bq8YtvLr4+eleAvFTwpheyqJLgFj+PLql0acA1CaIN1eT+FdCzWeQWQb+KtNAjbdN X-Received: by 10.84.138.1 with SMTP id 1mr17635944plo.156.1510793823984; Wed, 15 Nov 2017 16:57:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510793823; cv=none; d=google.com; s=arc-20160816; b=SKh2GWvyiLH8Y8CxeV87ECPBWvP6CD3iDcAq7hTJcPLL29joxmw6iv3XSq59bI3/4E f2ZxDb0mVlO6TuRVo9zhhEll66WM94AG6nJr4ht+MR7qxOEaXEGovpkPuI0BnX/ro3K0 tJ8Fm41lNotyoFJR5weGcPAJh6rhbmtLgV4vd4+hR4VAmVCHwX0Xb+Sth8hbiV0ckGBz j8Ko7WeXqVsLckdnljofmfm8NRk185EnWys57RgvTG4wOV947TRpM9xgJAjRwc9ybnVO LMy7amUpsh6AbdtZMThWCAtvUtyBGRR65wsXZaaASzmCWnESlM+kK0etTqUyOQi7LbJV k4tQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=wVinS4KEqaFF1g/l73AX7LhcmdbqsdHckDs4fbBS/sw=; b=xwbY4DOY4YNxx4ASQqIi9920xWjd5ZUntVHUMuRI0dHCaIkV3zZGDndS/Ci9qP8OFM ARBdG2hsz5QKIlO8pQx7ILE9YEaM75ErONTwrr8ZMcrS0ICK6ZKzPxpHX5tApb/JYTDv QfyWQ7ku2YBU1P1fwMj/3pcW2mzGIbZRiXyGJwZFovLimNoynNxfltEehohQk5ea4snl lXo6xxv/7E7C81WL0PTo5jDtv2dZhzRccUoequv2/l/2wAEj5ZTK5p0sJ4HAYs59fX0F p9rlPF/EwwkE8grXqmZquQbSzz1WAICNX8wUy4/vCxwflgYQOcgl4Q5SZ9+RkGUwKRFq 093A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gateworks-com.20150623.gappssmtp.com header.s=20150623 header.b=urLGTVGo; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d18si7268307pls.617.2017.11.15.16.56.51; Wed, 15 Nov 2017 16:57:03 -0800 (PST) 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=@gateworks-com.20150623.gappssmtp.com header.s=20150623 header.b=urLGTVGo; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933171AbdKOXTQ (ORCPT + 89 others); Wed, 15 Nov 2017 18:19:16 -0500 Received: from mail-wm0-f44.google.com ([74.125.82.44]:33398 "EHLO mail-wm0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933025AbdKOXTB (ORCPT ); Wed, 15 Nov 2017 18:19:01 -0500 Received: by mail-wm0-f44.google.com with SMTP id r68so19320wmr.0 for ; Wed, 15 Nov 2017 15:19:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gateworks-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=wVinS4KEqaFF1g/l73AX7LhcmdbqsdHckDs4fbBS/sw=; b=urLGTVGoTzCQ2Z46JU1K/00w9ypA95/OLA6gnup9ZiG4/aw7uS+mKscpip1kVV7J47 RAiF9uzeFh/RJ8J4SCVh1IuoRPBQhRtQa84N32sIi8YzEsHlZpkY7Aw9lXijuYLcz2V1 LqedrSWU4/Yo+xfnmcf96lJFwDf9TXUlVoJnoQlbDSeJfBdITI/p6r2lfqW/epy5LgV8 3O8s7ysZb44qESuV6LNwrmso1jqjMxHl8bxwfgXHRiLBxG28KB9YfNl8L+x3MK74ZFZp 8v6MmXTZMEyGNeYoVv2M23vpzTv8yF07NR7i5Yu5hY/A7NHbKByxrbeDoFB2hugVHCoA mi2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=wVinS4KEqaFF1g/l73AX7LhcmdbqsdHckDs4fbBS/sw=; b=XbC3LYIEhIliBpudAdEwv1qcJTv8f0rNIj5PvnoCwaF7QB+Jo+9abaDiklwctVjZAN E+E6vw0mIu3uZykpyDSIN0oI4ud9kUbwg1Pf44MkUN+cjOi4dS6siDL7/+DLt6JfpSkT n5XqH15Xya0RYO5+ohqW/AhgSm+rc5U+oveAlUA37svmNC3grkBnA4guJCRgwQo+NR7R V/j1bs0HLLlVB2pDzBxYTEJsBR/TbR6zzCze8J80dRpbmAwt23vVCp6ALm4yverA6u3O 9r5lL9W77crmBCda7oaF1skB/rfFF1abEn2Ij8Po5WpYBJprvgdgfWtXpuR7rtk099GF J1XQ== X-Gm-Message-State: AJaThX6WWOOy1qpFECTwyEJ6w7tO58I683S5dmn3K1Fu4DdW/HeoyVc3 fykvUJqRtbfpL6oLONWHvB6QlcCjmfo8WC9KoswWtg== X-Received: by 10.28.62.67 with SMTP id l64mr40774wma.6.1510787939787; Wed, 15 Nov 2017 15:18:59 -0800 (PST) MIME-Version: 1.0 Received: by 10.28.209.197 with HTTP; Wed, 15 Nov 2017 15:18:59 -0800 (PST) In-Reply-To: References: <2771c4a8-ed85-86c1-a08c-5b62d177b107@caviumnetworks.com> From: Tim Harvey Date: Wed, 15 Nov 2017 15:18:59 -0800 Message-ID: Subject: Re: MCP251x SPI CAN controller on Cavium ThunderX To: David Daney , Jan Glauber Cc: Mark Brown , linux-spi@vger.kernel.org, "linux-kernel@vger.kernel.org" , Wolfgang Grandegger , Marc Kleine-Budde Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 15, 2017 at 10:23 AM, Tim Harvey wrote: > On Wed, Nov 15, 2017 at 8:02 AM, David Daney wrote: >> On 11/13/2017 01:17 PM, Tim Harvey wrote: >>> >>> Mark/Jan, >>> >>> I have been unsuccessful getting a MCP251x SPI based CAN controller >>> working on a CN80xx using Linux mainline. >>> >>> When a register is read from the mcp251x driver the >>> octeon_spi_do_transfer() gets a spi_message with a single spi_xfer of >>> len=3, a tx_buf, and an rx_buf which I believe is supposed to shift >>> out 3 bytes out MOSI and shift in 3 bytes from MISO where the last >>> byte shifted in would be the response. >>> >>> The cavium CN80xx MPI_TX register has fields for 'Number of bytes to >>> transmit' (TXNUM) and 'Total number of bytes to shift (transmit and >>> receive)' (TOTNUM) and these are both getting set to 3 by >>> octeon_spi_do_transfer() but I find that this causes unexpected data >>> in the shifted in response unless I make TOTNUM = TXNUM + 1. >>> >>> I should also note that Cavium has a software suite called the 'BDK' >>> which provides a CLI to SPI transfers which allows you to set the >>> TXNUM and TOTNUM fields uniquely and if I send a 2-byte command >>> (TXNUM=2) to read a register (READ command followed by the register) >>> and a 1 byte read (thus TOTNUM=3) then I get the response from the >>> mcp251x I expect. >>> >> >> By looking at the driver, and from my recollection, I think that SPI_3WIRE >> may never have been tested, so there could be bugs in this mode. >> >> The driver as is works with various SPI eeprom devices, so any proposed >> changes would need to be validated against things that currently work. >> >> It could be that you need the CN80xx Hardware Reference Manual, board >> schematics and a logic analyzer to be able to figure out what is happening. >> > > David, > > I have all three here and can debug. This isn't hooked up as SPI_3WIRE > (wireor) - its got full a 4 wire connection. > > So thanks to the discussion here I now understand we are doing a > 3-byte full-duplex transfer (the third dummy byte threw me off) and > that is what the spi-cavium.c driver is setting up. > > So the transfer from the cavium side looks like this and TXNUM=3 > TOTNUM=3 makes sense to me for a 3-byte full duplex transfer (shift a > total of 3 bytes). > > // configure spi: 10MHz (clockdiv=0x11; cshi=0 wireor=0 cslate=0) > mpi_cfg => 0x112001 > // send three bytes (0x03 = READ, 0x0f = CANSTAT, 0x00 = dummy byte) > mpi_dat0 => 0x03 > mpi_dat1 => 0x0f > mpi_dat2 => 0x00 > // do the transfer (CS1, leavecs=0 Deassert SPI_CSn_L after the > transaction is done, TXNUM=3 TOTNUM=3) > mpi_tx => 0x100303 > // read response > mpi_dat0 <= 0xff > mpi_dat1 <= 0xff > mpi_dat2 <= 0x00 > ^^^^ I expect mpi_dat2 to be 0x80 > > Looking at the scope of CLK and MSIO I do see 3-bytes of CLK cycles > and the 0x80 on the wire and I'm wondering now if the cavium isn't > latching the 1st bit because of clock polarity (MPI_CFG[CSHI]) or > phase (MPI_CFG[CSLATE]). > > Regardless of scope shots though, what is strange to me is that if I > increase TOTNUM to 4 (write 3 bytes, read 1 bytes, shift a total of 4 > bytes) I get: > // configure spi: 10MHz (clockdiv=0x11; cshi=0 wireor=0 cslate=0) > mpi_cfg => 0x112001 > // send three bytes (0x03 = READ, 0x0f = CANSTAT, 0x00 = dummy byte) > mpi_dat0 => 0x03 > mpi_dat1 => 0x0f > mpi_dat2 => 0x00 > // do the transfer (CS1, leavecs=0 Deassert SPI_CSn_L after the > transaction is done, TXNUM=3 TOTNUM=4) > mpi_tx => 0x100304 > // read response > mpi_dat0 <= 0xff > mpi_dat1 <= 0xff > mpi_dat2 <= 0x80 > ^^^^^ 0x80 'is' the response I expect > David / Jan, For reference, the HM describes TXNUM/TOTNUM as: TXNUM - Number of bytes to transmit TOTNUM - Total number of bytes to shift (transmit and receive) Here are some experiments that show somewhat inconsistent results: - full duplex 3byte tx / 3byte rx to MCP251x mpi_dat0 => 0x03 // READ mpi_dat1 => 0x0e // CANSTAT mip_dat2 => 0xa5 // dummy (but making it 0xa5 instead of 0x00 to prove a point) mpi_tx => 0x100303 // TXNUM=3 TOTNUM=3; we see 24 clock cycles // wait for completion mpi_dat0 <= 0xff mpi_dat1 <= 0xff mpi_dat2 <=0xa5 // this the dummy byte we sent out MOSI not what came in on MISO which the scope shows as 0x80 if I set TXNUM=3 TOTNUM=4: mpi_dat0 => 0x03 // READ mpi_dat1 => 0x0e // CANSTAT mip_dat2 => 0xa5 // dummy mpi_tx => 0x100304 // TXNUM=3 TOTNUM=4; we see 32 clock cycles // wait for completion mpi_dat0 <= 0xff mpi_dat1 <= 0xff mpi_dat2 <= 0x80 // response for CANSTAT reg 0x0e mpi_dat3 <= 0x87 // response for CANCTRL reg 0x0f (because we shifted 32 clock cycles) if I set TXNUM=2 TOTNUM=3: mpi_dat0 => 0x03 // READ mpi_dat1 => 0x0e // CANSTAT mpi_tx => 0x100203 // TXNUM=2 TOTNUM=3; we see 24 clock cycles // wait for completion mpi_dat0 <= 0xff mpi_dat1 <= 0xff mpi_dat2 <= 0x80 // response for CANSTAT reg 0x0e if I set TXNUM=1 TOTNUM=1 to send a RESET command: mpi_dat0 => 0xc0 // RESET mpi_tx => 0x100101 // TXNUM=1 TOTNUM=1; we see 8 clock cycles // wait for completion mpi_dat0 <= 0xc0 In all cases above what is seen on MISO in relation to CLK matches the expectations of the mcp251x but the CN80xx MPI_DAT registers don't return what I see on MISO. Am I missing a consistent pattern of MPI_DAT vs TXNUM/TOTNUM here that would allow us to work-around this? Is this a CN80xx chip errata? There is no known errata for the CN80XX MPI engine. I could re-write the mcp251x driver to not use full-duplex but I'm assuming most SPI drivers use full-duplex transactions. Regards, Tim From 1584168050790785581@xxx Wed Nov 15 21:13:02 +0000 2017 X-GM-THRID: 1583987213767022680 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread