Re: [PATCH v3 1/1] i2c: add ACPI support for I2C mux ports

From: Andy Shevchenko
Date: Tue Oct 20 2015 - 05:16:17 EST


+Cc: Ismo Puustinen

On Mon, 2015-10-19 at 15:29 -0700, Dustin Byford wrote:
> Although I2C mux devices are easily enumerated using ACPI (_HID/_CID
> or
> device property compatible string match) enumerating I2C client
> devices
> connected through a I2C mux device requires a little extra work.
>
> This change implements a method for describing an I2C device
> hierarchy that
> includes mux devices by using an ACPI Device() for each mux channel
> along
> with an _ADR to set the channel number for the device.ÂÂSee
> Documentation/acpi/i2c-muxes.txt for a simple example.

Ismo, can you test this patch on top of what you have to see if it goes
smoothly (no break of Galileo Gen2 support) ?

>
> Signed-off-by: Dustin Byford <dustin@xxxxxxxxxxxxxxxxxxx>
> ---
> ÂDocumentation/acpi/i2c-muxes.txt | 58
> ++++++++++++++++++++++++++++++++++++++++
> Âdrivers/i2c/i2c-core.cÂÂÂÂÂÂÂÂÂÂÂ| 15 +++++++++--
> Âdrivers/i2c/i2c-mux.cÂÂÂÂÂÂÂÂÂÂÂÂ|ÂÂ8 ++++++
> Âinclude/linux/acpi.hÂÂÂÂÂÂÂÂÂÂÂÂÂ|ÂÂ6 +++++
> Â4 files changed, 85 insertions(+), 2 deletions(-)
> Âcreate mode 100644 Documentation/acpi/i2c-muxes.txt
>
> diff --git a/Documentation/acpi/i2c-muxes.txt
> b/Documentation/acpi/i2c-muxes.txt
> new file mode 100644
> index 0000000..9fcc4f0
> --- /dev/null
> +++ b/Documentation/acpi/i2c-muxes.txt
> @@ -0,0 +1,58 @@
> +ACPI I2C Muxes
> +--------------
> +
> +Describing an I2C device hierarchy that includes I2C muxes requires
> an ACPI
> +Device () scope per mux channel.
> +
> +Consider this topology:
> +
> ++------+ÂÂÂ+------+
> +| SMB1 |-->| MUX0 |--CH00--> i2c client A (0x50)
> +|ÂÂÂÂÂÂ|ÂÂÂ| 0x70 |--CH01--> i2c client B (0x50)
> ++------+ÂÂÂ+------+
> +
> +which corresponds to the following ASL:
> +
> +Device (SMB1)
> +{
> +ÂÂÂÂName (_HID, ...)
> +ÂÂÂÂDevice (MUX0)
> +ÂÂÂÂ{
> +ÂÂÂÂÂÂÂÂName (_HID, ...)
> +ÂÂÂÂÂÂÂÂName (_CRS, ResourceTemplate () {
> +ÂÂÂÂÂÂÂÂÂÂÂÂI2cSerialBus (0x70, ControllerInitiated, I2C_SPEED,
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂAddressingMode7Bit, "^SMB1", 0x00,
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂResourceConsumer,,)
> +ÂÂÂÂÂÂÂÂ}
> +
> +ÂÂÂÂÂÂÂÂDevice (CH00)
> +ÂÂÂÂÂÂÂÂ{
> +ÂÂÂÂÂÂÂÂÂÂÂÂName (_ADR, 0)
> +
> +ÂÂÂÂÂÂÂÂÂÂÂÂDevice (CLIA)
> +ÂÂÂÂÂÂÂÂÂÂÂÂ{
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂName (_HID, ...)
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂName (_CRS, ResourceTemplate () {
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂI2cSerialBus (0x50, ControllerInitiated,
> I2C_SPEED,
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂAddressingMode7Bit, "^CH00", 0x00,
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂResourceConsumer,,)
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ}
> +ÂÂÂÂÂÂÂÂÂÂÂÂ}
> +ÂÂÂÂÂÂÂÂ}
> +
> +ÂÂÂÂÂÂÂÂDevice (CH01)
> +ÂÂÂÂÂÂÂÂ{
> +ÂÂÂÂÂÂÂÂÂÂÂÂName (_ADR, 1)
> +
> +ÂÂÂÂÂÂÂÂÂÂÂÂDevice (CLIB)
> +ÂÂÂÂÂÂÂÂÂÂÂÂ{
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂName (_HID, ...)
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂName (_CRS, ResourceTemplate () {
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂI2cSerialBus (0x50, ControllerInitiated,
> I2C_SPEED,
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂAddressingMode7Bit, "^CH01", 0x00,
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂResourceConsumer,,)
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ}
> +ÂÂÂÂÂÂÂÂÂÂÂÂ}
> +ÂÂÂÂÂÂÂÂ}
> +ÂÂÂÂ}
> +}
> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> index 579b99d..af0811c 100644
> --- a/drivers/i2c/i2c-core.c
> +++ b/drivers/i2c/i2c-core.c
> @@ -156,7 +156,7 @@ static acpi_status
> acpi_i2c_add_device(acpi_handle handle, u32 level,
> Â info.fwnode = acpi_fwnode_handle(adev);
> Â
> Â memset(&lookup, 0, sizeof(lookup));
> - lookup.adapter_handle = ACPI_HANDLE(adapter->dev.parent);
> + lookup.adapter_handle = ACPI_HANDLE(&adapter->dev);
> Â lookup.device_handle = handle;
> Â lookup.info = &info;
> Â
> @@ -212,7 +212,7 @@ static void acpi_i2c_register_devices(struct
> i2c_adapter *adap)
> Â{
> Â acpi_status status;
> Â
> - if (!adap->dev.parent || !has_acpi_companion(adap-
> >dev.parent))
> + if (!has_acpi_companion(&adap->dev))
> Â return;
> Â
> Â status = acpi_walk_namespace(ACPI_TYPE_DEVICE,
> ACPI_ROOT_OBJECT,
> @@ -1667,6 +1667,17 @@ int i2c_add_adapter(struct i2c_adapter
> *adapter)
> Â struct device *dev = &adapter->dev;
> Â int id;
> Â
> + /*
> + Â* By default, associate I2C adapters with their parent
> device's ACPI
> + Â* node.
> + Â*/
> + if (!has_acpi_companion(dev)) {
> + struct acpi_device *adev = ACPI_COMPANION(dev-
> >parent);
> +
> + if (adev)
> + ACPI_COMPANION_SET(dev, adev);
> + }
> +
> Â if (dev->of_node) {
> Â id = of_alias_get_id(dev->of_node, "i2c");
> Â if (id >= 0) {
> diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
> index 2ba7c0f..00fc5b1 100644
> --- a/drivers/i2c/i2c-mux.c
> +++ b/drivers/i2c/i2c-mux.c
> @@ -25,6 +25,7 @@
> Â#include <linux/i2c.h>
> Â#include <linux/i2c-mux.h>
> Â#include <linux/of.h>
> +#include <linux/acpi.h>
> Â
> Â/* multiplexer per channel data */
> Âstruct i2c_mux_priv {
> @@ -173,6 +174,13 @@ struct i2c_adapter *i2c_add_mux_adapter(struct
> i2c_adapter *parent,
> Â }
> Â }
> Â
> + /*
> + Â* Associate the mux channel with an ACPI node.
> + Â*/
> + if (has_acpi_companion(mux_dev))
> + acpi_preset_companion(&priv->adap.dev,
> ACPI_COMPANION(mux_dev),
> + ÂÂÂÂÂÂchan_id);
> +
> Â if (force_nr) {
> Â priv->adap.nr = force_nr;
> Â ret = i2c_add_numbered_adapter(&priv->adap);
> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
> index 51a96a8..66564f8 100644



> --- a/include/linux/acpi.h
> +++ b/include/linux/acpi.h
> @@ -505,6 +505,12 @@ static inline bool has_acpi_companion(struct
> device *dev)
> Â return false;
> Â}
> Â
> +static inline void acpi_preset_companion(struct device *dev,
> + Âstruct acpi_device *parent,
> u64 addr)
> +{
> + return;
> +}
> +
> Âstatic inline const char *acpi_dev_name(struct acpi_device *adev)
> Â{
> Â return NULL;

For me seems this one can go separately. Rafael, what do you think?

--
Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
Intel Finland Oy

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/