From owner-freebsd-arm@FreeBSD.ORG Fri Mar 6 14:38:11 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 B9C5BA14 for ; Fri, 6 Mar 2015 14:38:11 +0000 (UTC) Received: from mail-wi0-x22a.google.com (mail-wi0-x22a.google.com [IPv6:2a00:1450:400c:c05::22a]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48DDFB8 for ; Fri, 6 Mar 2015 14:38:11 +0000 (UTC) Received: by wiwl15 with SMTP id l15so4045241wiw.0 for ; Fri, 06 Mar 2015 06:38:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=vi9vjWLgBMFumRcxED9ACvQzycISra5PKctpXuBxPjY=; b=ZlOWXHzG643elr4W+ouCoARPFpGpzfq08xpxHURztIg4dEo73oQhKHEL5KkwHws0qO f+Zco/OeNlBaKUsfCjUOOlpJu3MQ46fvEsJwMR22+LC2/R++NmMT+sCoUxbDwMszBvpG pdCvdNqY6KRmmJ1dD1a5Yg2cpWrIpHfQvM4Mc5mcFXdmPUZewsYIB/DM9Wb9yUu6T0/f J8QWIPqReVXfireipkfnyGXsm6i3wBNvMKG9qRpuokh268h2mhnxx7+xeHkHbfoUslpu 0cBqH5iknEd7vlXvIiRgs2ZHfdIuP1nz3KUFbUUsSVFYGctBgAiNtgc4FnlC4bC21Suo ivXQ== MIME-Version: 1.0 X-Received: by 10.180.83.69 with SMTP id o5mr74554284wiy.48.1425652689842; Fri, 06 Mar 2015 06:38:09 -0800 (PST) Received: by 10.180.195.99 with HTTP; Fri, 6 Mar 2015 06:38:09 -0800 (PST) In-Reply-To: <20150305123903.1050694f@zeta.dino.sk> References: <20150216093418.3d1be83b@zeta.dino.sk> <20150219075342.7d2e7eec@zeta.dino.sk> <20150302124103.689135d3@zeta.dino.sk> <20150303215040.13f8439f@zeta.dino.sk> <20150305123903.1050694f@zeta.dino.sk> Date: Fri, 6 Mar 2015 11:38:09 -0300 Message-ID: Subject: Re: Raspberry Pi SPI device example? From: Luiz Otavio O Souza To: Milan Obuch Content-Type: text/plain; charset=UTF-8 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: Fri, 06 Mar 2015 14:38:11 -0000 On 5 March 2015 at 08:39, Milan Obuch wrote: [...] > > 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 The SPI driver for RPi uses interrupts to do the data tx/rx and as such, it won't work that early (at proble/attach time). You have to use config_intrhook_establish() to set a callback that will run when interrupts are enabled. Look at the mx25l patch to see how convert an existent driver: http://loos.com.br/mx25l-fdt-intr.diff Regards, Luiz