From: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
To: Wei Liang <weiliang10-/E1597aS9LQAvxtiuMwx3w@public.gmane.org>
Cc: i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
Subject: Re: I2C device driver to simutaneously support 2 devices
Date: Fri, 16 May 2008 21:54:56 +0200 [thread overview]
Message-ID: <20080516215456.097c248c@hyperion.delvare> (raw)
In-Reply-To: <213411.97989.qm-1S7A5l4uV2KvuULXzWHTWIglqE1Y4D90QQ4Iyu8u01E@public.gmane.org>
Hi Wei,
On Wed, 14 May 2008 23:18:46 -0700 (PDT), Wei Liang wrote:
> I received this email address from Gregg Koah-Hartman. I am writing
> to seek your advise on writing a I2C device driver.
>
> I am currently writing a device driver based on the sample code by
> Gregg in Linux Journal (http://www.linuxjournal.com/article/7252).
I didn't even know that Greg had been writing articles about I2C.
Please note that this article is getting old, and many things it
mentions have changed since then. I strongly suggest that you take
a look at what i2c drivers in the current kernel tree look like, it
will give you a better picture of the current situation than Greg's
article.
> I am new to linux device driver development and am currently attempting
> to modify the code to enable it to simultaneously support 2 I2C devices
> - both devices resides on different addresses.
>
> I have tried
> adding another i2c_add_driver function in 'static int __init
> tiny_init(void)' and subsequently reduplicate all functions involved in
> registering a
> new driver (e.g. static struct i2c_driver, i2c_detect, etc). However,
> the code didn't seem to start. I have scoured through I2C
> documentations in the Linux kernel and also the book Linux Device Driver
> (O'Reilly) but have yet to come across any reference for the
> above-mentioned task.
>
> I am hoping that you could provide a few pointers on how best to proceed.
You definitely do not want to have more than one struct i2c_driver
in your module. If you are going to support really different devices,
you want to write separate modules for them. If your 2 devices are
similar enough to be supported by the same driver, then a single
struct i2c_driver should work fine.
I don't really understand what your problem is. Having an I2C driver
supporting several devices at different addresses doesn't present any
special difficulty, it is the default behavior. A lot of I2C drivers in
the kernel do that, just take a look at them. For example, the max6650
hardware monitoring driver supports I2C devices at 4 different
addresses, and declares them with:
static const unsigned short normal_i2c[] = {0x1b, 0x1f, 0x48, 0x4b,
I2C_CLIENT_END};
If you write a legacy i2c driver (which is what Greg's article
describes) then you would have something like the above in your module.
Your i2c_driver will then attempt to attach to any I2C device living at
any of the addresses in the list.
--
Jean Delvare
_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c
prev parent reply other threads:[~2008-05-16 19:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-15 6:18 I2C device driver to simutaneously support 2 devices Wei Liang
[not found] ` <213411.97989.qm-1S7A5l4uV2KvuULXzWHTWIglqE1Y4D90QQ4Iyu8u01E@public.gmane.org>
2008-05-16 19:54 ` Jean Delvare [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080516215456.097c248c@hyperion.delvare \
--to=khali-puyad+kwke1g9huczpvpmw@public.gmane.org \
--cc=i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org \
--cc=weiliang10-/E1597aS9LQAvxtiuMwx3w@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox