Received: by 10.223.164.202 with SMTP id h10csp1100075wrb; Wed, 15 Nov 2017 13:13:03 -0800 (PST) X-Google-Smtp-Source: AGs4zMbOmX0MpU/0Gyy38yfCIfipOHfu1seiNi4PEVlj+ANDvLORN3gMQl3AfYMVWW3aNVkyS90h X-Received: by 10.98.166.84 with SMTP id t81mr19099037pfe.196.1510780383134; Wed, 15 Nov 2017 13:13:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510780383; cv=none; d=google.com; s=arc-20160816; b=tapd+xTZIY5m3kra9X91xhxcMZ92fN6n1WmPC1+G2OCXncwFI5XmYR+gpEpBr1PpZ1 wdA3GHf6PlDUNG+SBqjXfQIuoY2m8AEFEo0fThb/RAx4C8O1cfQ7NcYgbe158KK0BB9U s3WlOPd0aGeV6cMsM2OM8Wv5oKdPP9MgOu9nW2SY8dLPf7NRyyJC8OmgTS/X/O1GidXv yWdUYPmCiKwHf7TcgFHotgoEQyOAqdsndtkxJa6D6hOkYwiyWd5xWEptIYNxEeDqlSUq RPU6jh0/HDfRr1J4CErHfwK2R/JCGQ9n/ApS18v6xwsPhdjeWofs+whE+Gv/MzrSHyMH CjpQ== 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=EYx6pg9+HCRgsQCr8F87ChuVM9HjIGS2azJssuCyxbo=; b=em/kNA3XksftR/ixsZHYe3+LclOsNK7qSz8+c9xaF80PsAhNqjH++4tkkc1NNdwmkG pg8mDSe5T4f06ZiQSUD8WGEoRc2SFxQkS08Cx4WrwjBSGiJ4dls6qlX8ouJ2nLvL8zUd 33yCkAoZ1jSHfbCfkvQDP7OamyVtsUK9Exk3PsILNFWFfibkjxs7iv/FkBIfpKWXgwyc skIXcHOzAOtZpZf94G+P0xQ2xGruqK27ygPtqr006Gj6C2tbWQyat+ADpdeWbZm/Ctcw wkZ3TbvAJZwS1tTc3vUkVQb8LUTq8z2h5c7epRrooHICoHwurWyXWoh1dw1SfC9cMwhe roAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gateworks-com.20150623.gappssmtp.com header.s=20150623 header.b=bquvO9+9; 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 s13si18207178plp.502.2017.11.15.13.12.50; Wed, 15 Nov 2017 13:13: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=bquvO9+9; 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 S1758094AbdKOSXn (ORCPT + 89 others); Wed, 15 Nov 2017 13:23:43 -0500 Received: from mail-wr0-f171.google.com ([209.85.128.171]:44070 "EHLO mail-wr0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756651AbdKOSXf (ORCPT ); Wed, 15 Nov 2017 13:23:35 -0500 Received: by mail-wr0-f171.google.com with SMTP id u97so21280281wrc.1 for ; Wed, 15 Nov 2017 10:23:35 -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=EYx6pg9+HCRgsQCr8F87ChuVM9HjIGS2azJssuCyxbo=; b=bquvO9+9Y07u+3zyO4Zm59bu9p45yVfICPPd9mBXgt9g6pCGvcbNuzs1oCmfbPJajD Pf9Mr+pFvcAXIldFDT/0snJjqhD91GVQSIxfkb1MIo2AE0JZLtXq5umGVES4geHvqrO2 DXO1mk509J/xRnVnSaTzPpg2e76N55ufKvRRGBQ99mxrTCL36il036EYnMWUX/K7BBhx Wm/9m7wk0xWc2FJOGzG+nqqVLu5qAixDSbl1djsYBu2A+O+08SUoSpgA+8V4UDA77hYQ jIk1mOzFjh4Ercn4hR1nd2dOEywdcliMiI0DXb50qaYE138wS5OW0tIH3m1SAZSNQiM/ zUAg== 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=EYx6pg9+HCRgsQCr8F87ChuVM9HjIGS2azJssuCyxbo=; b=pXIrNlv5u6IR9Z2Xkw+DM4BblBZDIzQcD8yUOJ0mdWS6MRhoO62Lx86q19Ny8meuN2 Ndio4VEhPPiuA1BaQyfFFy5kkT6D7jRBR/HjDE0Q+5GZMhtCC2RaleuF6nVQgMVDBYua +BPjduRuKjOXB6Ba2wwCKvRNmxw+OP9C/V8Yg2vrKjtZlFS2cMx/4pXnN9HE7RLrtJG7 3J5cr2Iwb6io3P+w2PLWylaGtnldKaXgB+nxJxITQqnEpBBb/ZS22clnDgxcJcxZ2pav 3dmssL9RSir6Fb5Fzkb6QeBHDsx9EveleiXbXUf3BGbkhajvelnP4ka5N96q8AibIVdf dkIg== X-Gm-Message-State: AJaThX6w42OL1z5JWYTFDSTdviAcxkhY6y6Gl5x9MNzdTssVzXykOeZA gxzpVNyinSw50UEyDTycUfWDSpwCQ8tko6c5G0qfbg== X-Received: by 10.223.144.71 with SMTP id h65mr14319329wrh.41.1510770214258; Wed, 15 Nov 2017 10:23:34 -0800 (PST) MIME-Version: 1.0 Received: by 10.28.209.197 with HTTP; Wed, 15 Nov 2017 10:23:33 -0800 (PST) In-Reply-To: <2771c4a8-ed85-86c1-a08c-5b62d177b107@caviumnetworks.com> References: <2771c4a8-ed85-86c1-a08c-5b62d177b107@caviumnetworks.com> From: Tim Harvey Date: Wed, 15 Nov 2017 10:23:33 -0800 Message-ID: Subject: Re: MCP251x SPI CAN controller on Cavium ThunderX To: David Daney Cc: Mark Brown , Jan Glauber , 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 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 Regards, Tim From 1584148718850393951@xxx Wed Nov 15 16:05:46 +0000 2017 X-GM-THRID: 1583987213767022680 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread