getting device descriptors / file handler in kernel space ?

I've got some I2c stuff running from userspace. But originally I want
to write a kernel module, initialising all the i2c devices and handle
the transfer.
But what do I have to do to get a device descriptor / filehandler for /
dev/i2c-1 ... in a kernel module? open does not work ...
Same for writing/reading files ...

I’ve got some I2c stuff running from userspace.

Cool!

Would you mind sharing the necessary changes to enable access to the I2C port on the expansion connector?

(At least I assume this is what you are using)

Sharing the userspace code would also be very much appreciated!

John

Enabled i2c dev modules in the kernel?
Regards,
Nishanth Menon

No changes to do, just some lines in userspace. Take a look and the
i2c-tools
Some line added - far away from being perfect, just as an example.

But again to all others: How to do a fd=open("/dev/i2c_1",O_RDWR ) in
kernelspace or what is the way to get a file descriptor?

Sorry? The devices are available, otherwise I couldn't access them fro
userspace.
But I will do all this inside a driver, a loadable kernel module...

You need to use i2c_transfer API calls if you need to access it from
kernel space. see [1] for sample drivers. [2] is a very simplistic
usage.
Regards,
Nishanth Menon
[1] http://source.mvista.com/git/gitweb.cgi?p=linux-omap-2.6.git;a=tree;f=drivers/i2c/chips;h=57bb57541d7a35a3e21e582d788da878e0a3b9f8;hb=HEAD
[2] http://source.mvista.com/git/gitweb.cgi?p=linux-omap-2.6.git;a=blob;f=drivers/i2c/chips/gpio_expander_omap.c;h=dfe7f040fac261cf5983015a613541273b62f3a4;hb=HEAD

Please forgive my ignorance, but is there a mechanism to use i2c
userspace tools from kernel space?

I always thought one should write an i2c driver and client for the
related i2c device.

I remember in DaVinci tree there was a generic driver/client to
read/write from an i2c address. They were using this generic driver to
communicate with various devices like i2c expanders, msp430 based rtc,
etc. I used that driver to write a driver for tsc2004 touchscreen
controller.

Regards,
Caglar

There are two ways to access i2c:
a) using i2c-dev driver in kernel space and a userapp to interface to
the i2c-dev (this basically uses a "dummy client").
b) as you mentioned using the kernel client-driver architecture.
[1] has more information on the architecture in general.
Regards,
Nishanth Menon
[1] http://www.lm-sensors.org/wiki/Documentation

I did use the way you showed me - and it works. Thanks!
Originally I wanted to use the way at it was described in the kernel-
Docu:

res = i2c_smbus_read_word_data(file,register);

That's way I asked for the file descriptor...