From owner-freebsd-hackers@freebsd.org Tue Mar 7 18:38:59 2017 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 117ACD004F1 for ; Tue, 7 Mar 2017 18:38:59 +0000 (UTC) (envelope-from gergely.czuczy@harmless.hu) Received: from marvin.harmless.hu (marvin.harmless.hu [195.56.55.204]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C9F7C1B15 for ; Tue, 7 Mar 2017 18:38:58 +0000 (UTC) (envelope-from gergely.czuczy@harmless.hu) Received: from 84-236-108-40.pool.digikabel.hu ([84.236.108.40] helo=[10.219.16.1]) by marvin.harmless.hu with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.88 (FreeBSD)) (envelope-from ) id 1clK0d-000A9T-5W for freebsd-hackers@freebsd.org; Tue, 07 Mar 2017 18:38:55 +0000 To: freebsd-hackers@freebsd.org From: Gergely Czuczy Subject: SPI communication from userspace Message-ID: <313fdb93-92c6-609f-57c9-3dec0ce84798@harmless.hu> Date: Tue, 7 Mar 2017 19:38:54 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Mar 2017 18:38:59 -0000 Hello, I would like to ask for some help, on how to communicate with an Adafruit MAX31856 breakout board over the SPI bus under freebsd, on an RPi3. As far as I can see, the spibus(4) driver is there, but there's no driver for this chip, and I can't access the SPI calls from userspace either. I could try to write a driver, however I don't have the experience working with the FreeBSD kernel. SPI communication is quite simple, you send a single byte to the device, and if the MSB was 1 it's a write, if it's 0 it's a read operation, remaining 7 bits is the address. Then you either write a byte to the address, or wait for the device to respond by the next cycle. Other difficulty is, the RPi3 provides 2 PINs for CS, and I have 3 devices, so I either have to use generic GPIO PINs, or de/multiplex it, which might require a userspace call for device selection on the bus. So, how should I start? What would be a good way to do the userspace-kernelspace communication? Also, I'm not sure whether I should do a specific driver for this device, or a generic one, and writing the specifics in userspace. Also, if you could point me to some documentation which would explain how to work with the kernel, make a custom module, the possible user/kernelspace communication possibilities, and how to call another kernel module's functions, would be quite appreciated. Also, if someone knows where could I find docs on the spibus driver, would be quite nice since, it's just code so far. Best regards, Gergely