public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
* Complex I2C device
@ 2008-01-30 14:46 Rodolfo Giometti
       [not found] ` <20080130144657.GA9444-AVVDYK/kqiJWk0Htik3J/w@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Rodolfo Giometti @ 2008-01-30 14:46 UTC (permalink / raw)
  To: i2c-GZX6beZjE8VD60Wz+7aTrA

Hello,

my custom board has a «complex» device... let me explain better: it's
formed by a custom I2C device and an I/O extender PCA9539.

Ascii art:


                +---------+
          --+---+         |
            |   | PCA9539 |
            |   +---------+
Bus I2C ->> |      | | |
            |      | | | <<--- GPIOs
            |      | | |
            |   +---------+
            +---+         |
                |   CHIP  |
                +---------+  

Some input GPIOs of CHIP are managed by the PCA9539. So fisically I
have two devices but logically they are merged together into one.

I can send commands to CHIP by both I2C bus and the GPIOs, which in
turn are controlled by the PCA9539.

Can you please suggest me the best way to manage this problem? My
solution was to provide PCA9539's driver of some exported symbols and
using them into the CHIP's driver. Is that right? Or, can I "call" (in
any way) PCA9539 driver's methods from CHIP's driver?

Thanks,

Rodolfo

-- 

GNU/Linux Solutions                  e-mail:    giometti-AVVDYK/kqiJWk0Htik3J/w@public.gmane.org
Linux Device Driver                             giometti-kaDoWcXyVrEAvxtiuMwx3w@public.gmane.org
Embedded Systems                     		giometti-k2GhghHVRtY@public.gmane.org
UNIX programming                     phone:     +39 349 2432127

_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Complex I2C device
       [not found] ` <20080130144657.GA9444-AVVDYK/kqiJWk0Htik3J/w@public.gmane.org>
@ 2008-01-30 20:32   ` Guennadi Liakhovetski
       [not found]     ` <Pine.LNX.4.64.0801302126150.6547-0199iw4Nj15frtckUFj5Ag@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Guennadi Liakhovetski @ 2008-01-30 20:32 UTC (permalink / raw)
  To: Rodolfo Giometti; +Cc: i2c-GZX6beZjE8VD60Wz+7aTrA

Hi Rodolfo,

On Wed, 30 Jan 2008, Rodolfo Giometti wrote:

> my custom board has a «complex» device... let me explain better: it's
> formed by a custom I2C device and an I/O extender PCA9539.
> 
> Ascii art:
> 
> 
>                 +---------+
>           --+---+         |
>             |   | PCA9539 |
>             |   +---------+
> Bus I2C ->> |      | | |
>             |      | | | <<--- GPIOs
>             |      | | |
>             |   +---------+
>             +---+         |
>                 |   CHIP  |
>                 +---------+  
> 
> Some input GPIOs of CHIP are managed by the PCA9539. So fisically I
> have two devices but logically they are merged together into one.
> 
> I can send commands to CHIP by both I2C bus and the GPIOs, which in
> turn are controlled by the PCA9539.
> 
> Can you please suggest me the best way to manage this problem? My
> solution was to provide PCA9539's driver of some exported symbols and
> using them into the CHIP's driver. Is that right? Or, can I "call" (in
> any way) PCA9539 driver's methods from CHIP's driver?

First, you want to use gpiolib, which in -mm tree now lives under 
drivers/gpio and includes a driver for pca9539. With it the pca9539 driver 
registers a gpio controller with the system, and then your driver for the 
other part can just request respective GPIOs as if they were normal CPU 
GPIOs or whatever else. And toggle them using the standard API. I will 
(hopefully tomorrow) post an example of exactly this to the 
video4linux-list-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org list. In my case this other chip is a CMOS 
camera.

Thanks
Guennadi
---
Guennadi Liakhovetski

_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Complex I2C device
       [not found]     ` <Pine.LNX.4.64.0801302126150.6547-0199iw4Nj15frtckUFj5Ag@public.gmane.org>
@ 2008-01-31  9:16       ` Rodolfo Giometti
       [not found]         ` <20080131091619.GI9444-AVVDYK/kqiJWk0Htik3J/w@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Rodolfo Giometti @ 2008-01-31  9:16 UTC (permalink / raw)
  To: Guennadi Liakhovetski; +Cc: i2c-GZX6beZjE8VD60Wz+7aTrA


[-- Attachment #1.1: Type: text/plain, Size: 3387 bytes --]

On Wed, Jan 30, 2008 at 09:32:38PM +0100, Guennadi Liakhovetski wrote:
> Hi Rodolfo,
> 
> On Wed, 30 Jan 2008, Rodolfo Giometti wrote:
> 
> > my custom board has a «complex» device... let me explain better: it's
> > formed by a custom I2C device and an I/O extender PCA9539.
> > 
> > Ascii art:
> > 
> > 
> >                 +---------+
> >           --+---+         |
> >             |   | PCA9539 |
> >             |   +---------+
> > Bus I2C ->> |      | | |
> >             |      | | | <<--- GPIOs
> >             |      | | |
> >             |   +---------+
> >             +---+         |
> >                 |   CHIP  |
> >                 +---------+  
> > 
> > Some input GPIOs of CHIP are managed by the PCA9539. So fisically I
> > have two devices but logically they are merged together into one.
> > 
> > I can send commands to CHIP by both I2C bus and the GPIOs, which in
> > turn are controlled by the PCA9539.
> > 
> > Can you please suggest me the best way to manage this problem? My
> > solution was to provide PCA9539's driver of some exported symbols and
> > using them into the CHIP's driver. Is that right? Or, can I "call" (in
> > any way) PCA9539 driver's methods from CHIP's driver?
> 
> First, you want to use gpiolib, which in -mm tree now lives under 
> drivers/gpio and includes a driver for pca9539. With it the pca9539 driver 
> registers a gpio controller with the system, and then your driver for the 
> other part can just request respective GPIOs as if they were normal CPU 
> GPIOs or whatever else. And toggle them using the standard API. I will 
> (hopefully tomorrow) post an example of exactly this to the 
> video4linux-list-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org list. In my case this other chip is a CMOS 
> camera.

Great, this would be a good solution for this scenario... but I'm
looking something more "general". A related problem of mine is on
another custom board which has the following:


                 +---------+
           --+---+ Battery |
             |   | Manager |
             |   +---------+
 Bus I2C ->> |
             |
             |
             |   +---------+
             +---+         |
                 |  CHIP   |
                 +---------+

A (complex) battery pack are managed by a "battery manager" and a
custom chip connected by the I2C bus (my hardware designer _loves_ I2C
bus :). Even these devices can be logically considered as only one
(big) battery...

Looking at I2C code, which uses the new style driver model, I see the
function i2c_register_board_info() where we can specify the bus number
and the devices list attached on that I2C bus, so I suppose we can add
a function as:

	struct i2c_client *i2c_find_client(int busnum, unsigned short addr);

which can return the i2c_client struct associated to the given bus
number and i2c address.

This should resolve any possible problem related to every I2C
"complex" device. Shouldn't it?

Thanks for your help,

Rodolfo

-- 

GNU/Linux Solutions                  e-mail:    giometti-AVVDYK/kqiJWk0Htik3J/w@public.gmane.org
Linux Device Driver                             giometti-kaDoWcXyVrEAvxtiuMwx3w@public.gmane.org
Embedded Systems                     		giometti-k2GhghHVRtY@public.gmane.org
UNIX programming                     phone:     +39 349 2432127

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

[-- Attachment #2: Type: text/plain, Size: 157 bytes --]

_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Complex I2C device
       [not found]         ` <20080131091619.GI9444-AVVDYK/kqiJWk0Htik3J/w@public.gmane.org>
@ 2008-02-19 13:21           ` Jean Delvare
       [not found]             ` <20080219142133.2e022910-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Jean Delvare @ 2008-02-19 13:21 UTC (permalink / raw)
  To: Rodolfo Giometti; +Cc: Guennadi Liakhovetski, i2c-GZX6beZjE8VD60Wz+7aTrA

Hi Rodolfo,

On Thu, 31 Jan 2008 10:16:19 +0100, Rodolfo Giometti wrote:
> On Wed, Jan 30, 2008 at 09:32:38PM +0100, Guennadi Liakhovetski wrote:
> > Hi Rodolfo,
> > 
> > On Wed, 30 Jan 2008, Rodolfo Giometti wrote:
> > 
> > > my custom board has a «complex» device... let me explain better: it's
> > > formed by a custom I2C device and an I/O extender PCA9539.
> > > 
> > > Ascii art:
> > > 
> > > 
> > >                 +---------+
> > >           --+---+         |
> > >             |   | PCA9539 |
> > >             |   +---------+
> > > Bus I2C ->> |      | | |
> > >             |      | | | <<--- GPIOs
> > >             |      | | |
> > >             |   +---------+
> > >             +---+         |
> > >                 |   CHIP  |
> > >                 +---------+  
> > > 
> > > Some input GPIOs of CHIP are managed by the PCA9539. So fisically I
> > > have two devices but logically they are merged together into one.
> > > 
> > > I can send commands to CHIP by both I2C bus and the GPIOs, which in
> > > turn are controlled by the PCA9539.
> > > 
> > > Can you please suggest me the best way to manage this problem? My
> > > solution was to provide PCA9539's driver of some exported symbols and
> > > using them into the CHIP's driver. Is that right? Or, can I "call" (in
> > > any way) PCA9539 driver's methods from CHIP's driver?
> > 
> > First, you want to use gpiolib, which in -mm tree now lives under 
> > drivers/gpio and includes a driver for pca9539. With it the pca9539 driver 
> > registers a gpio controller with the system, and then your driver for the 
> > other part can just request respective GPIOs as if they were normal CPU 
> > GPIOs or whatever else. And toggle them using the standard API. I will 
> > (hopefully tomorrow) post an example of exactly this to the 
> > video4linux-list-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org list. In my case this other chip is a CMOS 
> > camera.
> 
> Great, this would be a good solution for this scenario... but I'm
> looking something more "general". A related problem of mine is on
> another custom board which has the following:

Guennadi's solution (based on David Brownell's work) is actually pretty
generic as far as GPIOs are concerned. I like it.

> 
> 
>                  +---------+
>            --+---+ Battery |
>              |   | Manager |
>              |   +---------+
>  Bus I2C ->> |
>              |
>              |
>              |   +---------+
>              +---+         |
>                  |  CHIP   |
>                  +---------+
> 
> A (complex) battery pack are managed by a "battery manager" and a
> custom chip connected by the I2C bus (my hardware designer _loves_ I2C
> bus :). Even these devices can be logically considered as only one
> (big) battery...
> 
> Looking at I2C code, which uses the new style driver model, I see the
> function i2c_register_board_info() where we can specify the bus number
> and the devices list attached on that I2C bus, so I suppose we can add
> a function as:
> 
> 	struct i2c_client *i2c_find_client(int busnum, unsigned short addr);
> 
> which can return the i2c_client struct associated to the given bus
> number and i2c address.
> 
> This should resolve any possible problem related to every I2C
> "complex" device. Shouldn't it?

This would be doing things the wrong way around IMHO. Assuming that
there is no clean interface between both physical components of your
complex logical device, that would make a GPIO-like solution possible,
what you really have is a single device with 2 I2C addresses. We
support this already thanks to the i2c_new_dummy() function, so I see
no need for an additional interface.

-- 
Jean Delvare

_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Complex I2C device
       [not found]             ` <20080219142133.2e022910-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
@ 2008-02-19 14:10               ` Rodolfo Giometti
       [not found]                 ` <20080219141049.GD8190-AVVDYK/kqiJWk0Htik3J/w@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Rodolfo Giometti @ 2008-02-19 14:10 UTC (permalink / raw)
  To: Jean Delvare; +Cc: Guennadi Liakhovetski, i2c-GZX6beZjE8VD60Wz+7aTrA


[-- Attachment #1.1: Type: text/plain, Size: 1466 bytes --]

On Tue, Feb 19, 2008 at 02:21:33PM +0100, Jean Delvare wrote:
> 
> Guennadi's solution (based on David Brownell's work) is actually pretty
> generic as far as GPIOs are concerned. I like it.

If I well understand it I should use i2c_new_dummy() to simply create
an handler for the alternate address.

> > 
> > 
> >                  +---------+
> >            --+---+ Battery |
> >              |   | Manager |
> >              |   +---------+
> >  Bus I2C ->> |
> >              |
> >              |
> >              |   +---------+
> >              +---+         |
> >                  |  CHIP   |
> >                  +---------+
> > 
> > A (complex) battery pack are managed by a "battery manager" and a
> > custom chip connected by the I2C bus (my hardware designer _loves_ I2C
> > bus :). Even these devices can be logically considered as only one
> > (big) battery...
> > 

In this situation into the driver of the «main» device (the battery
manager) I can use i2c_new_dummy() to get an handler to manage the
other I2C chip. Is that right?

It looks *really* good. :)

Rodolfo

-- 

GNU/Linux Solutions                  e-mail:    giometti-AVVDYK/kqiJWk0Htik3J/w@public.gmane.org
Linux Device Driver                             giometti-kaDoWcXyVrEAvxtiuMwx3w@public.gmane.org
Embedded Systems                     		giometti-k2GhghHVRtY@public.gmane.org
UNIX programming                     phone:     +39 349 2432127

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

[-- Attachment #2: Type: text/plain, Size: 157 bytes --]

_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Complex I2C device
       [not found]                 ` <20080219141049.GD8190-AVVDYK/kqiJWk0Htik3J/w@public.gmane.org>
@ 2008-02-19 14:23                   ` Jean Delvare
  0 siblings, 0 replies; 6+ messages in thread
From: Jean Delvare @ 2008-02-19 14:23 UTC (permalink / raw)
  To: Rodolfo Giometti; +Cc: Guennadi Liakhovetski, i2c-GZX6beZjE8VD60Wz+7aTrA

On Tue, 19 Feb 2008 15:10:49 +0100, Rodolfo Giometti wrote:
> On Tue, Feb 19, 2008 at 02:21:33PM +0100, Jean Delvare wrote:
> > 
> > Guennadi's solution (based on David Brownell's work) is actually pretty
> > generic as far as GPIOs are concerned. I like it.
> 
> If I well understand it I should use i2c_new_dummy() to simply create
> an handler for the alternate address.
> 
> > > 
> > > 
> > >                  +---------+
> > >            --+---+ Battery |
> > >              |   | Manager |
> > >              |   +---------+
> > >  Bus I2C ->> |
> > >              |
> > >              |
> > >              |   +---------+
> > >              +---+         |
> > >                  |  CHIP   |
> > >                  +---------+
> > > 
> > > A (complex) battery pack are managed by a "battery manager" and a
> > > custom chip connected by the I2C bus (my hardware designer _loves_ I2C
> > > bus :). Even these devices can be logically considered as only one
> > > (big) battery...
> > > 
> 
> In this situation into the driver of the «main» device (the battery
> manager) I can use i2c_new_dummy() to get an handler to manage the
> other I2C chip. Is that right?

Yep, that's exactly the idea.

> It looks *really* good. :)

Credit go to David Brownell.

-- 
Jean Delvare

_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-02-19 14:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-30 14:46 Complex I2C device Rodolfo Giometti
     [not found] ` <20080130144657.GA9444-AVVDYK/kqiJWk0Htik3J/w@public.gmane.org>
2008-01-30 20:32   ` Guennadi Liakhovetski
     [not found]     ` <Pine.LNX.4.64.0801302126150.6547-0199iw4Nj15frtckUFj5Ag@public.gmane.org>
2008-01-31  9:16       ` Rodolfo Giometti
     [not found]         ` <20080131091619.GI9444-AVVDYK/kqiJWk0Htik3J/w@public.gmane.org>
2008-02-19 13:21           ` Jean Delvare
     [not found]             ` <20080219142133.2e022910-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-02-19 14:10               ` Rodolfo Giometti
     [not found]                 ` <20080219141049.GD8190-AVVDYK/kqiJWk0Htik3J/w@public.gmane.org>
2008-02-19 14:23                   ` Jean Delvare

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox