public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
From: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
To: "Zheng, Lv" <lv.zheng-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: multiple slave addresses for single I2C chip
Date: Wed, 5 Sep 2012 08:40:18 +0200	[thread overview]
Message-ID: <20120905084018.464d72c8@endymion.delvare> (raw)
In-Reply-To: <1AE640813FDE7649BE1B193DEA596E88B9367A-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>

Hi Lv,

On Wed, 5 Sep 2012 04:50:02 +0000, Zheng, Lv wrote:
> We are trying to drive some sensors on Linux. The sensors are connected to the board as I2C slaves.
> I noticed the i2c_board_info can be used to register i2c slaves for the embedded platforms.
> I noticed there's also "address_list" member in the i2c_driver which can be used to detect the I2C slaves.
> The first question is: Which one shall I use to draft my sensor codes?

Depends. If your sensor device has identification registers such that
it can be easily and reliably detected, and it can only use a limited
set of slave addresses, you can have its driver implement the detect
method for automatic device discovery. I that case, the detection
method should also go to the sensors-detect [1] user-space script. See
drivers/hwmon/lm63.c for a simple example.

[1] http://dl.lm-sensors.org/lm-sensors/files/sensors-detect

If there are no identification registers, implementing the detect
driver method is not possible, and you have to rely on explicit I2C
slave instantiation.

I invite you to read Documentation/i2c/instantiating-devices for a
complete view of the available options. As a general rule, for sensor
devices, we do our best to support auto-detection for devices which are
commonly found on PC hardware. For devices which are mostly found on
embedded devices, this isn't so useful, as the platform initialization
code typically knows exactly what devices it expects.

> If i2c_board_info is used to register platform i2c slaves, there is another issue for me:
> One of the sensors has 2 slave addresses. I noticed only one slave address can be declared in one i2c_board_info.
> The second question is: Shall I register the sensor's resource using 2 i2c_board_info? By doing this, shall I draft a single .c file containing 2 "i2c_driver" for them?

No. You choose one I2C address which you consider the main address for
the device, and in the driver's probe function, you request the extra
address(es) using i2c_new_dummy(). Here's a list of drivers doing that,
which you can use as examples:
drivers/hwmon/smm665.c
drivers/hwmon/asb100.c
drivers/misc/eeprom/max6875.c
drivers/misc/eeprom/at24.c

-- 
Jean Delvare

  parent reply	other threads:[~2012-09-05  6:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-05  4:50 multiple slave addresses for single I2C chip Zheng, Lv
     [not found] ` <1AE640813FDE7649BE1B193DEA596E88B9367A-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2012-09-05  6:40   ` Jean Delvare [this message]
     [not found]     ` <20120905084018.464d72c8-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2012-09-06  3:48       ` Zheng, Lv

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=20120905084018.464d72c8@endymion.delvare \
    --to=khali-puyad+kwke1g9huczpvpmw@public.gmane.org \
    --cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=lv.zheng-ral2JQCrhuEAvxtiuMwx3w@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