Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
12748 Discussions

I2C interface on Linux (with MMU)

Altera_Forum
Honored Contributor II
3,519 Views

I have a few questions about I2C interfaces on Nios II on Linux with MMU. 

 

I found this thread http://www.alteraforum.com/forum/showthread.php?t=18441 (though forum search for "i2c" or "I2C" doesn't find it). It is a bit fragmented, and difficult to follow. 

 

I have a Microtronix i2c interface. 

 

Should the OpenCores drivers work with this? 

 

I defined I2C_0_BASE, I2C_0_IRQ based on my custom_fpga.h 

 

I2C_0_FREQ is being a bit trickier. I assumed it should be the i2c bus speed; however, I discovered that it seems to hang the system at boot if I don't define it as the system clock speed (85 MHz for me).
0 Kudos
15 Replies
Altera_Forum
Honored Contributor II
1,934 Views

Do you need I²C Master or Slave ?  

 

AFAIK, there is a (not bit banging) open core I²C design. I'm not sure if same is already available for the Avalon bus and if there is a current Kernel driver in place.  

 

Do you think the Microtronix design offer advantages ?  

 

-Michael
0 Kudos
Altera_Forum
Honored Contributor II
1,934 Views

I need the I2C to talk to an RTC chip, an M41T0. 

 

I assume that means the I2C on the FPGA is the master, and the RTC is the slave. 

 

I have no idea if the Microtronix design has advantages over the OpenCores design. It is what the hardware guys put in the design.
0 Kudos
Altera_Forum
Honored Contributor II
1,934 Views

With the RTC chip, of course the NIOS is the I²C Master.  

 

For accessing just an RTC Chip, a bit banging I²C driver (no I²C-specific hardware) should work fine. Such a driver is standard in the Linux distribution.  

 

If the hardware guys decided to use a piece of hardware they of course will be able to tell you where to find the appropriate (and not outdated) driver.  

 

Microtronix usually do provide Linux drivers for their IP Cores. 

 

-Michael
0 Kudos
Altera_Forum
Honored Contributor II
1,934 Views

You will need to check the hardware. The hardware decides which driver to use. 

 

I guess the microtronix one is opencore i2c. You have to make sure the component names match the config.c. The m41t00 uses the ds1307 driver. You will need to make sure the i2c address matches the config.c. 

 

Please refer to the wiki, 

 

http://www.nioswiki.com/operatingsystems/uclinux/video 

 

- Hippo
0 Kudos
Altera_Forum
Honored Contributor II
1,934 Views

I've mapped the I2C component name from custom_fpga.h to the one used in config.c., with# defines in nios.h. 

 

My custom_fpga.h does not have a frequency for the I2C. I tried a few differet vaues. When I use the CPU clock speed (85 MHz), it doesn't hang. 

 

When I start up, the I2C seems to be initializing correctly. 

 

It does not, however, recognize the RTC chip. I have selected the ds1307 driver. It does probe for the RTC. 

 

The RTC is an M41T0, not an M41T00. This makes it quite difficult to google anything on the chip.
0 Kudos
Altera_Forum
Honored Contributor II
1,934 Views

Please check your data sheet or user guide of the i2c daughter board to find out the exact part number. 

 

What is the result of i2cdetect? 

 

Please note that you must match the i2c board info with the bus number, i2c address and i2c part in config.c, 

 

 

- Hippo
0 Kudos
Altera_Forum
Honored Contributor II
1,934 Views

I have verified: M41T0. 

 

Here is the relevant output from boot: 

i2c /dev entries driver rtc-ds1307: probe of 0-0068 failed with error -5 i2c-0: I2C OpenCores Bus Adapter, MMIO = 0x2120C00, irq = 9 i2c-0: Using 85000kHz clock source And when I run i2cdetect: 

 

/# i2cdetect 0 WARNING! This program can confuse your I2C bus, cause data loss and worse! I will probe file /dev/i2c-0. I will probe address range 0x03-0x77. Continue? y 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- --  

 

I have verified in the part data sheet that the device address is 0x68. 

 

I finally got my hands on the Microtronix driver, but it is in a full linux distribution, for nios2nommu. 

 

I'm working on getting the relevant pieces transfered into the MMU build.
0 Kudos
Altera_Forum
Honored Contributor II
1,934 Views

I think there are problems in your i2c setup from the i2cdetect output. I would suggest changing the interface to gpio because it is simple and easy to debug. 

 

http://www.nioswiki.com/gpio 

 

- Hippo
0 Kudos
Altera_Forum
Honored Contributor II
1,934 Views

I'm not quite ready to give up on the Microtronix I2C yet. 

 

I think I have the Microtronix I2C driver compiled in, but it seems to have no connection to /dev/i2c-0 (so i2cdetect fails). 

 

Microtronix sent me their entire Linux distribution. (I think it is uClinux, as there is nios2nommu). 

 

I've copied over what I think are the relevant I2C files: 

  • drivers/i2c/algos/i2c-algo-mtx.c 

  • drivers/i2c/algos/i2c-mtx.h 

  • drivers/i2c/busses/i2c-mtx.c 

  • include/linux/i2c-algo-mtx.h
I copied over the relevant sections of Kconfig and Makefile from the i2c/algos and i2c/busses directory. 

 

I coped the I2C-related portions of arch/nios2nommu/kernel/avalon_devices.c to my arch/nios2/kernel/config.c (mimicing the sections for I2C OpenCores). 

 

There was a printk() in the init in i2c_algo_mtx.c. I added one to i2c-mtx.c. 

 

At startup, I can see the printk output from both files, so I know they are compiled in, and the init functions are being called. 

 

I can also see that the "i2c /dev entries driver" is started.  

 

When I run "i2cdetect 0", I get "Error: Count not open file `/dev/i2c-0': No such device". 

 

How do I connect the device driver to the /dev device? 

 

Nina
0 Kudos
Altera_Forum
Honored Contributor II
1,934 Views

Sorry, I cannot help. I gave up i2c oc early and made gpio instead. It might be easier to modify the sopc design than fighting with a vendor driver. I cannot see the point to spend time on a simple i2c rtc interface. 

 

- Hippo
0 Kudos
Altera_Forum
Honored Contributor II
1,934 Views

> Microtronix sent me their entire Linux distribution. 

 

What Kernel Version does same use ? The only Microtronix Linux I saw up till now was based on a very old Kernel Version that uses a quite different driver interface.  

 

To work with the community, you would need to use the community distribution and if you want to use the Microtronix IP-Core supposedly you would need to port the driver to thr new Kernel interface. 

 

-Michael
0 Kudos
Altera_Forum
Honored Contributor II
1,934 Views

I tried to find the kernel version today. Didn't see any sign of it. Any suggestions on where I should look? 

 

I did notice that the files were dated May '07. at the latest. 

 

I did see some differences in the driver structure. 

 

I've asked the hardware guys about putting in the OpenCores I2C. If that fails, I'll be asking them for a bit-banging interface.
0 Kudos
Altera_Forum
Honored Contributor II
1,934 Views

> the files were dated May '07. at the latest. 

 

That is what I feared :(  

 

> If that fails, I'll be asking them for a bit-banging interface. 

 

That would be very easy for them as it's a simple Bit I/O port. 

 

-Michael
0 Kudos
Altera_Forum
Honored Contributor II
1,934 Views

Well, I had them switch to the OpenCores I2C interface. 

 

I pointed them at both http://www.opencores.org/project,i2c and http://www.niosforum.com/pages/project_details.php?p_id=111&t_id=18 as sources for the design. 

 

I compiled the kernel with I2C_0_FREQ defined as 400000 (400 kHz), and the ds1307 Real Time Clock support. 

 

The I2C initialized, and the RTC was read. 

 

I have not tried to write to the RTC, but the OpenCores I2C interface and driver seem to work just fine.
0 Kudos
Altera_Forum
Honored Contributor II
1,934 Views

Great ! 

 

Thanks for letting us know. :) 

 

-Michael
0 Kudos
Reply