linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mika Westerberg <mika.westerberg@linux.intel.com>
To: Dustin Byford <dustin@cumulusnetworks.com>
Cc: rjw@rjwysocki.net, linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org
Subject: Re: [RFC v2 0/1] i2c: acpi: scan ACPI enumerated I2C mux channels
Date: Wed, 30 Sep 2015 12:43:36 +0300	[thread overview]
Message-ID: <20150930094336.GF1551@lahna.fi.intel.com> (raw)
In-Reply-To: <20150929231912.GA7913@cumulusnetworks.com>

On Tue, Sep 29, 2015 at 04:19:12PM -0700, Dustin Byford wrote:
> Hi Mika,
> 
> On Mon Aug 17 15:03, Mika Westerberg wrote:
> > I think the current code in I2C core is not actually doing the right
> > thing according the ACPI spec at least. To my understanding you can have
> > device with I2cSerialBus resource _anywhere_ in the namespace, not just
> > directly below the host controller. It's the ResourceSource attribute
> > that tells the corresponding host controller.
> > 
> > I wonder if it helps if we scan the whole namespace for devices with
> > I2cSerialBus that matches the just registered adapter? Something like
> > the patch below.
> 
> I've been working with the patch you suggested below.
> 
> > diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> > index c83e4d13cfc5..2a309d27421a 100644
> > --- a/drivers/i2c/i2c-core.c
> > +++ b/drivers/i2c/i2c-core.c
> 
> ...
> 
> >  static void acpi_i2c_register_devices(struct i2c_adapter *adap)
> >  {
> > -     acpi_handle handle;
> >       acpi_status status;
> >  
> > -     if (!adap->dev.parent)
> > -             return;
> > -
> > -     handle = ACPI_HANDLE(adap->dev.parent);
> > -     if (!handle)
> > +     if (!adap->dev.parent || !has_acpi_companion(adap->dev.parent))
> >               return;
> >  
> > -     status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1,
> > +     status = acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
> > +                                  ACPI_I2C_MAX_SCAN_DEPTH,
> >                                    acpi_i2c_add_device, NULL,
> >                                    adap, NULL);
> 
> On my systems (which admittedly all define their i2c clients below the
> controller) this works as expected, i.e. there's no change in behavior.
> As far as I can tell it more accurately implements the spec.
> 
> 
> However, it doesn't quite solve my problem.  When
> acpi_i2c_register_devices(adap) is called on the "virtual" controller
> that is created for an i2c mux channel, the adap->dev.parent (set to the
> parent i2c bus for the mux) does not have an acpi companion.  That
> ultimately causes acpi_i2c_add_device() to never find a match.
> 
> I'll recap a bit since it's been a while and I've learned a few things
> that might affect the discussion.  For now, I'll focus on my proposed
> ASL for an I2C mux using device properties.
> 
> Lets say we have i2c hardware attached like this:
> 
> i801 controller (PCI)
>    pca9548 8-channel mux (address 0x70)
>        lm75 temperature sensor (channel 0 on the mux with address 0x50)
> 
> I think this is a sensible way to represent it:
> 
> Device (MUX0) {
>     Name (_ADR, 0x70)

This..

>     Name (_HID, "PRP0001")
>     Name (_CRS, ResourceTemplate()
>     {
>         I2cSerialBus (0x70, ControllerInitiated, I2C_SPEED,
>                       AddressingMode7Bit, "^^SMB2", 0x00,
>                       ResourceConsumer,,)
>     })
>     Name (_DSD, Package ()
>     {
>         ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
>         Package () {
>             Package (2) { "compatible", "nxp,pca9548" },
>         }
>     })
> 
>     // MUX channel 0
>     Device (CH00) {
>         Name (_ADR, 0x0)
> 
>         Device (TMP0) {
>             Name (_ADR, 0x50)

... and this are not needed. I2cSerialBus already contains the address.

Also I think you need to have "PRP0001" here as well.

>             Name (_CRS, ResourceTemplate()
>             {
>                 I2cSerialBus (0x60, ControllerInitiated, I2C_SPEED,
>                               AddressingMode7Bit, "^CH00", 0x00,
>                               ResourceConsumer,,)
>             })
>             Name (_DSD, Package ()
>             {
>                 ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
>                 Package () {
>                     Package (2) { "compatible", "national,lm75" },
>                 }
>             })
>         }
>     }
> }
> 
> The new thing here is using _ADR to treat each mux channel as a device
> and referencing those devices elsewhere (CH00).  I arrived at this
> because it seems to fit the ACPI model reasonably well* and it's easy to
> implement (just like in other callers to acpi_preset_companion())
> 
> * by reasonably well, I think it's clear and works naturally but this
> use of _ADR isn't explicitly defined in the spec [ACPI 6, Table 6-168
> (page 278)]
> 
> Hopefully the spec ambiguity isn't too much effort to clarify.  I think
> it's a good change.  But, perhaps it's unnecessary.  Any feedback on
> whether this ASL seem like the right way to go for device property i2c
> muxes?

Well to me your ASL looks reasonable. Usage of _ADR to specify mux
channel seems natural and follows other buses which have an entry in
that table. I don't know if it is forbidden to invent this kind of
things that are not explicitly mentioned in the spec, though.

> If not, is there an acceptable alternative?  I wonder how muxes are
> handled otherwise?  Hopefully not ASL methods :)

I cannot think of any better way. I have never seen ACPI DSDT/SSDT
containing I2C mux before.

  reply	other threads:[~2015-09-30  9:43 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-13 23:59 [RFC PATCH 0/1] i2c: scan ACPI enumerated I2C mux channels Dustin Byford
2015-08-13 23:59 ` [RFC PATCH 1/1] i2c: acpi: " Dustin Byford
     [not found] ` <1439510358-16664-1-git-send-email-dustin-qUQiAmfTcIp+XZJcv9eMoEEOCMrvLtNR@public.gmane.org>
2015-08-14 19:31   ` [RFC v2 0/1] " Dustin Byford
2015-08-14 19:31     ` [RFC v2 1/1] " Dustin Byford
2015-10-09 21:42       ` Wolfram Sang
2015-10-09 21:50         ` Dustin Byford
2015-10-09 21:51           ` Wolfram Sang
2015-08-15 20:22     ` [RFC v2 0/1] " Wolfram Sang
2015-08-17 12:03     ` Mika Westerberg
2015-08-17 19:00       ` Dustin Byford
2015-09-29 23:19       ` Dustin Byford
2015-09-30  9:43         ` Mika Westerberg [this message]
2015-09-30 12:52           ` Rafael J. Wysocki
2015-09-30 13:57             ` Mika Westerberg
2015-09-30 17:54               ` Dustin Byford
2015-10-10  0:41     ` [PATCH 0/2] " Dustin Byford
2015-10-10  0:41       ` [PATCH 1/2] i2c: scan entire ACPI namespace for I2C connections Dustin Byford
2015-10-12 10:46         ` Mika Westerberg
2015-10-12 11:20           ` Andy Shevchenko
2015-10-12 17:00             ` Dustin Byford
2015-10-12 19:01         ` Rafael J. Wysocki
2015-10-12 18:57           ` Dustin Byford
2015-10-10  0:41       ` [PATCH 2/2] i2c: add ACPI support for I2C mux ports Dustin Byford
2015-10-10  1:03         ` kbuild test robot
2015-10-12 10:50         ` Mika Westerberg
2015-10-12 18:32           ` Dustin Byford
2015-10-13 11:32             ` Mika Westerberg
2015-10-19  9:01 ` [PATCH v2 0/1] i2c: acpi: scan ACPI enumerated I2C mux channels Dustin Byford
2015-10-19 22:28 ` [PATCH v3 " Dustin Byford
2015-10-19 22:29   ` [PATCH v3 1/1] i2c: add ACPI support for I2C mux ports Dustin Byford
2015-10-20  9:16     ` Andy Shevchenko
2015-10-20 12:51     ` Mika Westerberg
2015-10-20 17:49       ` Dustin Byford
2015-10-20 23:13         ` Rafael J. Wysocki
2015-10-21  8:12         ` Mika Westerberg
2015-10-21  8:21           ` Dustin Byford
2015-10-21  8:34             ` Mika Westerberg
2015-10-21  8:52               ` Dustin Byford
2015-10-21  9:08                 ` Mika Westerberg
2015-10-21  9:25                   ` Dustin Byford
2015-10-21 22:39                     ` Rafael J. Wysocki
2015-10-22  9:27                       ` Dustin Byford
2015-10-20 23:12       ` Rafael J. Wysocki
2015-10-21  8:02         ` Mika Westerberg
2015-10-22  9:17 ` [PATCH v4 0/2] i2c: acpi: scan ACPI enumerated I2C mux channels Dustin Byford
2015-10-22  9:17   ` [PATCH v4 1/2] acpi: add acpi_preset_companion() stub Dustin Byford
2015-10-23  8:33     ` Mika Westerberg
2015-10-25 13:40     ` Rafael J. Wysocki
2015-10-25 15:01       ` Rafael J. Wysocki
2015-10-22  9:17   ` [PATCH v4 2/2] i2c: add ACPI support for I2C mux ports Dustin Byford
2015-10-23  8:40     ` Mika Westerberg
2015-10-23 10:16       ` Wolfram Sang
2015-10-23 13:13         ` Mika Westerberg
2015-10-23 13:40           ` Mika Westerberg
2015-10-23 13:55             ` Jarkko Nikula
2015-10-23 19:27 ` [PATCH v5 0/2] i2c: acpi: scan ACPI enumerated I2C mux channels Dustin Byford
2015-10-23 19:27   ` [PATCH v5 1/2] acpi: add acpi_preset_companion() stub Dustin Byford
2015-10-24 16:41     ` Wolfram Sang
2015-10-25 15:00       ` Rafael J. Wysocki
2015-10-23 19:27   ` [PATCH v5 2/2] i2c: add ACPI support for I2C mux ports Dustin Byford
2015-10-25 14:53   ` [PATCH v5 0/2] i2c: acpi: scan ACPI enumerated I2C mux channels Wolfram Sang
2015-10-25 15:15     ` Dustin Byford

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=20150930094336.GF1551@lahna.fi.intel.com \
    --to=mika.westerberg@linux.intel.com \
    --cc=dustin@cumulusnetworks.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=rjw@rjwysocki.net \
    /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;
as well as URLs for NNTP newsgroup(s).