OpenWrt Forum Archive

Topic: i2c driver for Edimax routers.

The content of this topic has been archived on 24 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I would like to develop an i2c driver using GPIO pins on the adm5120.  Can someone tell me the best starting point for this?

thanks.

I have modifed a driver for kernel 2.4.
Please see : http://www.sunspot.co.uk/Projects/sweexproject.htm Item 6
The latest driver is included in the track from http://midge.vlad.org.ua/trac/cgi-bin/trac.cgi/timeline
(I will check if the latest version on my page)

The driver can use ALL gpio´s  or Switch-led-ports and can loaded multiple times for multiple i2c-busses.
But the driver has no reference or knowlege if the gpio or switch-port is used.
I have currently no time (and to few knowledge) for correct porting to openwrt or to kernel-2.6

4huf wrote:

I have modifed a driver for kernel 2.4.
Please see : http://www.sunspot.co.uk/Projects/sweexproject.htm Item 6
The latest driver is included in the track from http://midge.vlad.org.ua/trac/cgi-bin/trac.cgi/timeline
(I will check if the latest version on my page)

The driver can use ALL gpio´s  or Switch-led-ports and can loaded multiple times for multiple i2c-busses.
But the driver has no reference or knowlege if the gpio or switch-port is used.
I have currently no time (and to few knowledge) for correct porting to openwrt or to kernel-2.6

I know about your stuff, but  I figured there must already be an i2c driver ported to one of
the other routers for use under 2.6.  If there's nothing else to go by I can, of course port your 2.4 driver
to 2.6 as a last resort, but I hoped to avoid it.  Simply changing the IO ports and init on someone
else's driver sounds much more attractive smile.

thanks!

4huf,

Using the new gpio api, this is theoretically pretty easy:

in trunk/build_dir/linux-adm5120_router_le/linux-2.6.22.4/arch/mips/adm5120/platform.c add:

static struct i2c_gpio_platform_data i2c_gpio_data = {
    .sda_pin    = ADM5120_GPIO_P4L0,      // or use one of the other pins.... :-).
    .scl_pin    = ADM5120_GPIO_P4L1,
};

struct platform_device adm5120_i2c_gpio_device = {
    .name        = "i2c-gpio",
    .id        = 0,
    .dev        = {
        .platform_data    = &i2c_gpio_data,
    },
};

Then in trunk/build_dir/linux-adm5120_router_le/linux-2.6.22.4/arch/mips/adm5120/board.c
in adm5120_board_setup(void):

    /* register i2c device */
    platform_device_register(&adm5120_i2c_gpio_device);

I added this just after the PCI registration.

In theory this should get working i2c for the edimax a lot nicer than writing your own i2c driver.   Another option is to use
drivers/i2c/busses/i2c-parport-lite.c as a base, and substitute the relevant inb/outb commands for port reads and writes at the correct addresses.

Unfortunately I only have a TCN75 to test this, and so far the temperature seems to rapidly fluctuate between about 40 and 55 degrees when I read it using a microcontroller, so either i have blown two chips, or I don't understand the protocol.  I'm not sure how much use it will be to start experimenting with the above code given that I have no known working devices, so if you would like to try it out on some known good devices and let me know please go ahead.  I can write up a detailed description of what to do on my website.

regards,
-biff.

I just tried this and got the error when loading the driver:

i2c /dev entries driver
i2c-gpio: probe of i2c-gpio.0 failed with error -16
i2c-gpio: probe failed: -19

So I think I will investigate a hacked  i2c-parport-light driver instead.

Hello Simon,

bifferos wrote:

I just tried this and got the error when loading the driver:

i2c /dev entries driver
i2c-gpio: probe of i2c-gpio.0 failed with error -16
i2c-gpio: probe failed: -19

So I think I will investigate a hacked  i2c-parport-light driver instead.

Your idea was good, but the leds-adm5120 driver have occupied these GPIO lines already. That is why you got error -16 (-EBUSY).
If you disable the LED driver, the probe should be succeed.

Regards,
-Gabor

I thought it would be something like that.  Is it possible to put this code into OpenWRT, under a configuration
option?  There are quite a few people using i2c with the Edimax.  It would be nice if it wasn't necessary to
disable the gpio driver to use i2c, because gpio is also quite useful!

it would be nice to add similar support to spi on 2.6.24 (interface like i2c-gpio-custom should be easy to port to spi-gpio-custom)
with such driver, we could have mmc/sd host - without ugly hacks like in rest of openwrt ports.

btw. this interface would be usable in other ports...
i hope that juhosg is working now on 2.6.24 port, and i have some little progress (generic patches applicated, adm5120 patches from 2.6.23 applicated (one .rej - applicated "by hand")), but still kernel doesn't compile:

include/asm/war.h:11:17: error: war.h: No such file or directory

looks like problem yesterday resolved in ar7 by matteo

edited: exactly - this was good assumption. after copying that file (and little reading/understanding it's content) i'm compiling 2.6.24 sources wink
probably today i'll have mmc/sd driver, so now it's time to append a unionfs (or investigate mini_fo fs) :]

(Last edited by jell on 30 Jan 2008, 12:35)

jell wrote:

i hope that juhosg is working now on 2.6.24 port

Yes, i'm working on it.

i'm working on this subject only a few hours, but now i'm close to such screen wink

edit: hehe, in time of writing upper text - i had this compiled wink now time to boot wink
http://openwrt.pastebin.ca/884759
kernel stops at this moment...
probably because i didn't use C from several years ago wink but after around 6h work on this - looks promising wink

(Last edited by jell on 30 Jan 2008, 17:17)

jell wrote:

it would be nice to add similar support to spi on 2.6.24 (interface like i2c-gpio-custom should be easy to port to spi-gpio-custom)
with such driver, we could have mmc/sd host - without ugly hacks like in rest of openwrt ports.

Personally I'm more interested in 1-wire:
http://lists-archives.org/linux-kernel/ … er-v3.html

It means you could potentially add a temperature sensor to your board for... the cost of a temperature sensor!
Not even a PCB to make, just solder in place of one of the LEDs.  Sweet!

i have such temperature sensor connected to pc by centronics port, and have w1 bus master drivers to centronics and to gpio (but tested only on avr32 (little architecture dependend)).

unfortunately, i have only a little time to spend on kernel hacking and my priority is to support mmc/sd cards as main mass storage. juhosg code is very good starting point in doing both things - w1, and spi bus masters...

I patched OpenWrt to get this module working for w1-gpio:
http://squidge.svn.sourceforge.net/view … iew=markup

That loads OK.  Then I adapted juhosg code to give me w1-gpio-custom:
http://squidge.svn.sourceforge.net/view … iew=markup

Unfortunately it doesn't work, and oopses when registering the device, although I can't see anything wrong with it.

Then I simplified the example to give a more specific case:
http://squidge.svn.sourceforge.net/view … iew=markup

Still I get oops when registering the device.  Any ideas why?

Success!  I've finally read a device ID back from the DS1820 wired to my router.

I was loading the modules in the wrong order.  It should be something like:

insmod wire
insmod w1-gpio-custom bus0=0,17,0
insmod w1-gpio

I can't get w1_therm to work, but I have access to the 'rw' sysfs file, so I'll probably just
write some userland code to talk to the device.

The discussion might have continued from here.