From owner-freebsd-arm@FreeBSD.ORG Thu Mar 5 11:39:22 2015 Return-Path: Delivered-To: freebsd-arm@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 9ECE1A7 for ; Thu, 5 Mar 2015 11:39:22 +0000 (UTC) Received: from mailhost.netlabit.sk (mailhost.netlabit.sk [84.245.65.72]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 17A16860 for ; Thu, 5 Mar 2015 11:39:21 +0000 (UTC) Received: from zeta.dino.sk (fw1.dino.sk [84.245.95.252]) (AUTH: LOGIN milan) by mailhost.netlabit.sk with ESMTPA; Thu, 05 Mar 2015 12:39:12 +0100 id 00DCA89B.54F84060.0000C51A Date: Thu, 5 Mar 2015 12:39:03 +0100 From: Milan Obuch To: Luiz Otavio O Souza Subject: Re: Raspberry Pi SPI device example? Message-ID: <20150305123903.1050694f@zeta.dino.sk> In-Reply-To: References: <20150216093418.3d1be83b@zeta.dino.sk> <20150219075342.7d2e7eec@zeta.dino.sk> <20150302124103.689135d3@zeta.dino.sk> <20150303215040.13f8439f@zeta.dino.sk> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.25; i386-portbld-freebsd10.1) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: freebsd-arm@freebsd.org X-BeenThere: freebsd-arm@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "Porting FreeBSD to ARM processors." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Mar 2015 11:39:22 -0000 On Wed, 4 Mar 2015 14:11:29 -0300 Luiz Otavio O Souza wrote: > On 3 March 2015 at 17:50, Milan Obuch wrote: [ snip ] > > no success yet. I wrote simple skeleton containing only basic > > functions, attached, but nothing shows any call to them. In my dts, > > I put > > > > spi0 { > > tsc0 { > > compatible = "st,stmpe_tc"; > > spi-chipselect = <0>; > > }; > > }; > > > > I tried some variations, too, but no change. There are just two > > lines in dmesg mentioning spi: > > > > spi0: mem 0x204000-0x20401f irq 62 on > > simplebus0 spibus0: on spi0 > > > > I think I am just missing something simple and obvious, but I can't > > see it. Anybody knows what is missing here? > > > > Regards, > > Milan > > It (kinda) works for me: > > spi0: mem 0x204000-0x20401f irq 62 on > simplebus0 spibus0: on spi0 > tsc0: probe > tsc0: probe > tsc0: at cs 0 on spibus0 > tsc0: attach > That was the intended result of this skeleton code. [ snip ] > Check if your dtb has the necessary nodes: > > # ofwdump -a > [...] > Node 0x1704: bsc1 > Node 0x17a0: spi0 > Node 0x1818: tsc0 > Node 0x1854: dma > Node 0x1914: mbox > [...] > [ snip ] Good hint, and stupid pilot error. I had wrong dtb select statement in config.txt boot file... Now it works as expected. I am trying now some SPI transaction to communicate with the device. As there are actually two SPI devices, just for test I made two instances in FDT: spi0 { tsc0 { compatible = "st,stmpe_tc"; spi-chipselect = <0>; }; tsc1 { compatible = "st,stmpe_tc"; spi-chipselect = <1>; }; }; and changed my attach function like this: static int tsc_attach(device_t dev) { struct tsc_softc *sc; uint8_t txBuf[2], rxBuf[2]; struct spi_command cmd; int err; sc = device_get_softc(dev); sc->dev = dev; memset(&cmd, 0, sizeof(cmd)); memset(txBuf, 0, sizeof(txBuf)); memset(rxBuf, 0, sizeof(rxBuf)); txBuf[0] = 0x80; //CMD_READ | REG_CHIP_ID; cmd.tx_cmd = txBuf; cmd.tx_cmd_sz = 2; cmd.rx_cmd = rxBuf; cmd.rx_cmd_sz = 2; err = SPIBUS_TRANSFER(device_get_parent(dev), dev, &cmd); device_printf(dev, "chip id %.2x %.2x (err %d)\n", rxBuf[0], rxBuf[1], err); return (0); } With following result in dmesg: spi0: mem 0x204000-0x20401f irq 62 on simplebus0 spibus0: on spi0 tsc0: at cs 0 on spibus0 tsc0: chip id 00 00 (err 0) tsc1: at cs 1 on spibus0 tsc1: chip id 00 00 (err 0) As the first one is actually ILI9341, where undefined command 0x80 is treated as NOP, and the second one should read device identification of STMPE610, 0x811 according the docs, I think my SPI transaction does not work the expected way. Code snippet was taken from mx25l_get_status function almost verbatim, I did not find any docs for spibus, so that's the only source I have to study. Some description of various fields of spi_command structure would be helpfull, too, but there is none. Do I need anything more to do, like some pin setup or spi initialisation? I did not see anything like this in sources present in our tree. Again, any hint greatly appreciated. Regards, Milan