TWI under Linux

Go To Last Post
15 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Anyone out there have a TWI driver they're able to share? Or shall I get to work?

Cheers,
S.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If so, you might be able to use the AT91 TWI driver as a starting point. This patch appears to be the most recent one:

http://lists.lm-sensors.org/pipe...

But it has a few problems, which you can read about here:

http://lists.lm-sensors.org/pipe...

Also, I think krangnes has actually been able to use this driver on AVR32 with some modifications. Maybe he can tell you more about the status?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Cheers how, none of those issues look too terrible so I will indeed start from that one.

Regards,
S.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I found there are some codes about TWI of AVR32 in the file /arch/avr32/lib/spd.c. But I am not sure it's the TWI driver and also don't know what is its aim.
To TWI driver, you can find one in the folder /appnotes/twi of STK1000_BSP_CD_image_1.0. But I think it is for AVR32 Embedded Development, not for Linux Development. You might refer to it and then write a driver for Linux to share with us if you like. :-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yeah, the bit defs are in the kernel already and that driver is indeed for non-linux devel. The non-linux driver could be made rough and linux ready very simply but I'll put in the extra effort and make the driver properly conform to the linux TWI model.

I've got another project here at work for the next week odd but I'll hit the TWI after that. I'll keep you all up to date!

Cheers,
S.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As said above there is a TWI kernel module, the status on it is mostly complete and working AFAIK.

Hans-Christian

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oh, good news, hce! If as you said it's ok, I will try to use it. But, could you please give us some examples how to use, so we can get starting quickly? Thanks!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

heha wrote:
Oh, good news, hce! If as you said it's ok, I will try to use it. But, could you please give us some examples how to use, so we can get starting quickly? Thanks!

You will need the driver code first :) I have prodded krangnes about it, will try to get him to post it here or similar :)

Hans-Christian

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ah, even better. Cheers hce and an advance cheers to krangnes.

S.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Finally able to access freaks, and due to the huge amount of probing; here's a dev patch for the avr32 patched 2.6.16.11 kernel. Any feedback on the driver is highly welcome.

Enjoy :D

PS: I had to rename the patch to .txt due to some naming rules. Will be fixed shortly (for all future patch posters), but I don't have the time to wait...

Attachment(s): 

11011110101011011100000011011110

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Patch posting now possible! A big cheers to JoFreak and the webmasters for making that happen. No more code-tag deformed patches for us!

There's a test thread at https://www.avrfreaks.net/index.p...

S.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, I have a working 2.6.19-rc4, is there I2C support in here for the AVR32 or do i need a patch? If so will the above patch apply? Has anyone got something similar working - I want to try and talk to a tuner through i2c on the avr, taking the linuxtv drivers as a reference.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No, TWI drivers aren't in the kernel yet and the PIO framework has changed alot since the BSP release. I have a TWI patch (attached) which has been modified to compile in to 2.6.19-*. I only did the changes recently and I haven't had a chance to test it on HW so there's a good chance it won't actually work! Nevertheless, feel free to have a play. If it doesn't work, let us know how and why. Any feedback on the code is of course welcome as well!

S.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks, I applied it and built it. I get an initialisation error so I put some printk's in, it appears it's expecting a clock I don't have, here's the output:

i2c /dev entries driver
i2c-core: driver [dev_driver] registered
twi twi.0: TWI resource start -2095104, len 1023<7>i2c_adapter i2c-0: adapter [AVR32_TWI] registered
i2c-dev: adapter [AVR32_TWI] registered as minor 0
Got Clock osc32k
Got Clock osc0
Got Clock osc1
Got Clock pll0
Got Clock pll1
Got Clock cpu
Got Clock hsb
Got Clock pba
Got Clock pbb
Got Clock pclk
Got Clock ebi
Got Clock hramc
Got Clock pico
Got Clock usart
Got Clock hclk
Got Clock mck
Got Clock pixclk
twi twi.0: no TWI clock defined
twi twi.0: HW Init failed, error -2
twi: probe of twi.0 failed with error -2
TCP cubic registered
NET: Registered protocol family 1
NET: Registered protocol family 17
Time: avr32 clocksource has been installed.

The TWI driver is looking for 'mclk'. Could I substitute mck? Sorry for my ignorance - steep learning curve here...!!!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You're absolutely right, typo there. It should indeed be searching for mck.

Also it looks like the resource data is incorrect. Until I get that sorted you might just like to hardcode twi_res_start = 0xFFE00800 and twi_res_len = 0x34. And there should be a /n at the end of the printk reporting the resource data.

Anyway, I should have access to hardware this arvo so I'll get stuck in to it proper.

Cheers,
S.