Page history last edited by Banned User 13 years, 3 months ago

I've been working on an I2C bus driver for the WGT634U's GPIO pins. This I2C bus driver has worked (preliminary testing only) under Kamikaze r5435 with 2.6.17 kernel:


I was able to flip the output bits on a PCF8574 chip with a user-space program talking to /dev/i2c-0.


Here are my steps to installing it:

  • copy or link the i2c-bcm5365.c file above into build_mipsel/linux/drivers/i2c/busses
  • edit build_mipsel/linux/drivers/i2c/busses/Makefile adding i2c-bcm5365.o line
  • edit build_mipsel/linux/drivers/i2c/busses/Kconfig adding I2C_BCM5365 stanza
  • edit package/kernel/modules/other.mk adding i2c-core, i2c-dev, i2c-algo-bit, and i2c-bcm5365 stanzas. Autoload priorities should be set so i2c-core loads first, and i2c-bcm5365 loads last.
  • make ARCH=mips menuconfig in the kernel build directory (see http://wiki.openwrt.org/BuildRoot#Customizingthekerneloptions ) and choose <m> for I2C, I2C_CHARDEV, I2C_ALGO_BIT, and I2C_BCM5365


  • make menuconfig in the top directory and choose <*> for i2c-core, i2c-dev, i2c-algo-bit, and i2c-bcm5365.
  • make in the top directory.
  • copy the new binary to the router with tftp


running lsmod on the router should show all four i2c-* modules loaded.


You can specify which gpio bits are used in /etc/modules.d/nn-i2c-bcm5365, e.g.

  • i2c-bcm5365 sclbit=0x10 sdabit=0x20


You must mknod /dev/i2c-0 c 89 0 to create the character device for user-space access to the bus.



Now available as an ipkg! I'll post steps to how I made it here soon (See I2CPackage)... meanwhile, you can try to ipkg install kmod-i2c_2.6.17-brcm-1_mipsel.ipk. Then insmod i2c-core, insmod i2c-dev, insmod i2c-algo-bit and insmod i2c-bcm5365 . Make sure you mknod /dev/i2c-0 c 89 0 ! I haven't tried to see if the i2c bus works yet, I just wanted to get this up here. All the modules loaded fine, but I did have to ipkg -force-depends install ... (OpenWrt changed the kernel versioning since 5370). If this works/doesn't, let me (flyashi-@-gmail) know :) Thanks!


P.S. HUGE thanks to Chuck Harrison for this awesome driver!

P.P.S. If you have any programs to access I2C devices (PCF8574, other GPIO chips, ADC chips, etc.), it would be nice to post them here for everyone to use :) I'm going to write one for a thermistor chip to monitor the CPU temp :D


Update for Kamikaze 7.09! Now that Kamikaze comes from the OpenWrt developers officially, I've stopped messing with new images (well, for now). But since we have a common basis to work from, I've updated Chuck's I2C driver for 2.6.22 and packaged it as an ipkg: same directions as above, but the file is now: ipkg install http://openwrt.pbwiki.com/f/kmod-wgti2c_0%2B2.6.22-brcm47xx-1_mipsel.ipk . I've successfully run a MCP23017 GPIO expander and DS1631+ temperature sensor. It's quite nifty.


some command-line i2c programs

These have worked under recent kamikaze w/2.6.17 kernel (and Kamikaze 7.09/Linux 2.6.22 as well)


<device node> is typically /dev/i2c-0.

Note: <dev addr> above is in the range 0-127 (7-bit address). If your datasheet says "write address 0x40, read address 0x41" it is talking about 8-bit codes which include the read/write flag as LSB. The corresponding 7-bit <dev addr> is 0x20 (decimal 32).


Some more command line programs

Tested under Kamikaze 7.09/Linux 2.6.22

  • compile : one-line shell script that calls proper gcc with proper -I... and -L...
  • writegpio.c : write to a given register (similar to i2c-putregs above)
  • gettemp.c : read temperature from DS1631-compatible chip
  • settemp.c : set lower and upper temperature thresholds
  • ledscroll.c : scroll through the output bits of MCP23017
  • ledtemp.c : display DS1631's temperature on LEDs via MCP23017


The above are by no means complete. Use them as you wish, no warranty provided, though you can contact me for help.

compile needs to be modified with the path to your OpenWrt installation (either the SDK, ImageBuilder, or full install).

The rest use chips that you can get from Microchip.

http://www.charmed.com/txt/dev-interface.txt has some info on Linux user-space I2C programming via the /dev/ interface, which Chuck's driver provides and all the above programs use.



WifiCar v2 uses I2C! http://charlie.okshtein.net/


lcd4linux uses I2C to drive a standard (HD44780) LCD with a PCF8574 by default to display a lot of informations.

you have to modify the settings for plugins and size (see here)


If you add a new topic, please add it to this list on the main page so people can easily find it.
You can easily add a new page by creating a wiki link with the title of the page like Car Shipping Rates
 you want to create on the front page. Then, when you click on that link, you will be taken to a new page that you can add to.


Comments (0)

You don't have permission to comment on this page.