i2c driver for RPi

Luiz Otavio O Souza luiz.souza at ad.com.br
Thu Aug 22 13:27:47 UTC 2013


On Aug 15, 2013, at 1:50 PM, Luiz Otavio O Souza wrote:

> Hello guys,
> 
> I've written the I2C (BSC - broadcom serial controller) driver for RPi.
> 
> The test was done by reading the registers of two lm75 on the same I2C bus (the only one available on my RPi).
> 
> You have to manually switch the I2C pins to alt0 function. There are two bsc controllers on SoC, the older ones uses the bsc0 and gpio pins 0 and 1 while the newer boards uses the bsc1 with gpio pins 2 and 3.
> 
> There is a third bsc controller which is used for the HDMI connection. I have not touched this one (although it should just work).
> 
> So for my basics tests, here is what i did:
> 
> root at raspberry-pi:~ # sysctl dev.gpio.0.pin.0.function=alt0
> dev.gpio.0.pin.0.function: input -> alt0
> root at raspberry-pi:~ # sysctl dev.gpio.0.pin.1.function=alt0
> dev.gpio.0.pin.1.function: input -> alt0
> root at raspberry-pi:~ # cd src/lm75
> root at raspberry-pi:~/src/lm75 # ./lm75 -d 150 -f /dev/iic0 -a
> lm75 in comparator mode
> O.S. polarity: active low
> Fault Queue: 1
> temperature: 17.0C
> o.s. temperature: 80.0C
> hyst temperature: 75.0C
> root at raspberry-pi:~/src/lm75 # ./lm75 -d 158 -f /dev/iic0 -a
> lm75 in comparator mode
> O.S. polarity: active low
> Fault Queue: 1
> temperature: 16.5C
> o.s. temperature: 80.0C
> hyst temperature: 75.0C
> 
> 
> The lm75 code is at: http://loos.no-ip.org/lm75.tar.gz
> 
> The BSC driver also exports some knobs under the dev.bsc sysctl:
> 
> root at raspberry-pi:~/src/lm75 # sysctl dev.bsc.0
> dev.bsc.0.%desc: BCM2708/2835 BSC controller
> dev.bsc.0.%driver: bsc
> dev.bsc.0.%parent: simplebus0
> dev.bsc.0.clock: 100000
> dev.bsc.0.clock_stretch: 64
> dev.bsc.0.fall_edge_delay: 48
> dev.bsc.0.rise_edge_delay: 48
> 
> 
> And the dmesg (for bsc part):
> 
> bsc0: <BCM2708/2835 BSC controller> mem 0x20205000-0x2020501f irq 61 on simplebus0
> iicbus0: <Philips I2C bus> on bsc0
> iic0: <I2C generic I/O> on iicbus0
> bsc1: <BCM2708/2835 BSC controller> mem 0x20804000-0x2080401f irq 61 on simplebus0
> iicbus1: <Philips I2C bus> on bsc1
> iic1: <I2C generic I/O> on iicbus1


Here is an updated patch which i'm going to ask for approval from my mentor if there are no objections.

It has a few fixes (locks, style) and now it does the gpio pin configuration (set the alternate pin function) at attachment so it works right out of the box (thanks to rpaulo).

The bcm2835_gpio-alternate.diff add a function to bcm2835 GPIO to set the alternate pin function.

Thanks,
Luiz


-------------- next part --------------
A non-text attachment was scrubbed...
Name: bcm2835_gpio-alternate.diff
Type: application/octet-stream
Size: 4223 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-arm/attachments/20130822/17b5325d/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bcm2835_bsc.diff
Type: application/octet-stream
Size: 17143 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-arm/attachments/20130822/17b5325d/attachment-0001.obj>


More information about the freebsd-arm mailing list