linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC v2 0/2] Match i2c_device_id when using DT ids through ACPI
@ 2016-06-09 13:06 Crestez Dan Leonard
  2016-06-09 13:06 ` [RFC v2 1/2] acpi: Expose acpi_of_match_device Crestez Dan Leonard
  2016-06-09 13:06 ` [RFC v2 2/2] i2c: Pass i2c_device_id to probe func when using DT ids through ACPI Crestez Dan Leonard
  0 siblings, 2 replies; 11+ messages in thread
From: Crestez Dan Leonard @ 2016-06-09 13:06 UTC (permalink / raw)
  To: linux-acpi, Rafael J. Wysocki, Len Brown
  Cc: Crestez Dan Leonard, linux-i2c, Wolfram Sang, Mika Westerberg,
	linux-kernel, Irina Tirdea, Octavian Purdila, Daniel Baluta

Linux supports instantiating devices using devicetree ids from ACPI by setting
the id to PRP0001 and adding the devicetree compatible string in _DSD
properties. This is described in Documentation/acpi/enumeration.txt.

I've tried to use this feature using custom ACPI tables and one issue I
encountered is that a lot of i2c device drivers are written for DT only and
expect a valid i2c_device_id *id parameter to their probe function but this is
always NULL for the PRP0001 case. Others call of_match_device in order to
determine their exact model number and that will also fail.

Drivers normally do this in order to differentiate between minor model numbers
supported by the same driver, for example hmc5883 versus hmc5983.

For ACPI it is common to add calls to acpi_match_device in order to do such
differentiation. It might make sense to call some form of acpi_of_match_device
except no such function is currently exported. I think it makes a lot of sense
to refactor the current acpi_of_match_device to return the of_device_id and
export it.

This is in PATCH 1. After exposing this function it could be called from each
driver that needs to support multiple models through PRP0001. I guess the
alternative to exposing acpi_of_match_device would be for driver code to poke
at acpi_device->data.of_compatible?

Going further it might make sense to attempt to fetch the i2c_device_id when
instantiating through PRP0001. This already happens automatically for
devicetree and it makes a lot of sense it would work through ACPI with DT ids.
Patch 2 hacks an additional search in i2c register code. This makes some
drivers "just work" without manually handling the "ACPI with DT ids" case.

For P1 it might make sense to change the parameters around so that
acpi_of_match_device will have the same signature as of_match_device.

The purpose of these changes would be to make more drivers easier to
instantiate through ACPI firmware.

v2 fixes the code to actually work correctly. Hopefully the patches will also
be sent to the correct addresses this time.

Crestez Dan Leonard (2):
  acpi: Expose acpi_of_match_device
  i2c: Pass i2c_device_id to probe func when using DT ids through ACPI

 drivers/acpi/bus.c     | 13 +++++++------
 drivers/i2c/i2c-core.c | 30 ++++++++++++++++++++++++++----
 include/linux/acpi.h   |  8 ++++++++
 3 files changed, 41 insertions(+), 10 deletions(-)

-- 
2.5.5

^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: [RFC v2 2/2] i2c: Pass i2c_device_id to probe func when using DT ids through ACPI
@ 2016-11-01  6:14 Phong Vo
  2016-12-06 17:00 ` Dmitry Torokhov
  0 siblings, 1 reply; 11+ messages in thread
From: Phong Vo @ 2016-11-01  6:14 UTC (permalink / raw)
  To: mika.westerberg, leonard.crestez
  Cc: wsa+renesas, rafael.j.wysocki, len.brown, irina.tirdea,
	octavian.purdila, daniel.baluta, linux-kernel, linux-acpi,
	linux-i2c, Tin Huynh, Loc Ho, patches

>From: Mika Westerberg <mika.westerberg@linux.intel.com>
>Subject: Re: [RFC v2 2/2] i2c: Pass i2c_device_id to probe func when
using DT ids through ACPI
>Date: Monday 13th June 2016 09:26:55 UTC (5 months ago)
>
>On Fri, Jun 10, 2016 at 06:57:36PM +0300, Crestez Dan Leonard wrote:
>> On 06/10/2016 09:32 AM, Mika Westerberg wrote:
>> > On Thu, Jun 09, 2016 at 04:06:03PM +0300, Crestez Dan Leonard wrote:
>> >> When devices are instatiated through devicetree the i2c_client->name
is
>> >> set to the compatible string with company name stripped out. This is
>> >> then matched to the i2c_device_id table to pass the device_id to the
>> >> probe function. This id parameter is used by some device drivers to
>> >> differentiate between model numbers.
>> >>
>> >> When using ACPI this id parameter is NULL and the driver usually
needs
>> >> to do ACPI-specific differentiation.
>> >>
>> >> This patch attempts to find a valid i2c_device_id when using ACPI
with
>> >> DT-like compatible strings.
>> >
>> > So I don't really understand why it would be good idea to pass
>> > i2c_device_id for devices which are matched against their ACPI/DT
>> > tables. Apparently DT is already doing that so maybe there is some
>> > reason.
>> >
>> > Anyway, why not fill in the device name when it is first enumerated
>> > if it uses DT compatible property? Just like DT does.
>> >
>> This automatic matching of i2c_device_id works for devicetree because
>> of_i2c_register_device sets i2c_board_info.type to the compatible
string
>> with the vendor prefix removed. For I2C devices described via ACPI the
>> i2c_board_info.type string is set to the ACPI device name. This ends up
>> something like "PRP0001:00".
>>
>> This could be changed in acpi_i2c_get_info to use the of_compatible
>> string from DSD if present. Is that what you mean? That would work and
>> it would be cleaner than my patch. Something like this:
>>
>> diff --git drivers/i2c/i2c-core.c drivers/i2c/i2c-core.c
>> index 1e0ef9b..ba2fe7f 100644
>> --- drivers/i2c/i2c-core.c
>> +++ drivers/i2c/i2c-core.c
>> @@ -181,7 +181,24 @@ static int acpi_i2c_get_info(struct acpi_device
>*adev,
>>
>>         acpi_dev_free_resource_list(&resource_list);
>>
>> -       strlcpy(info->type, dev_name(&adev->dev), sizeof(info->type));
>> +       /*
>> +        * If we have a DT id set info.type to the first compatible
>> string with
>> +        * the vendor prefix stripped. This is similar to
>of_modalias_node
>> +        */
>> +       if (adev->data.of_compatible) {
>> +               const union acpi_object *obj;
>> +               const char *str, *chr;
>> +
>> +               obj = adev->data.of_compatible;
>> +               if (obj->type == ACPI_TYPE_PACKAGE)
>> +                       obj = obj->package.elements;
>> +               str = obj->string.pointer;
>> +               chr = strchr(str, ',');
>> +               if (chr)
>> +                       str = chr + 1;
>> +               strlcpy(info->type, str, sizeof(info->type));
>> +       } else
>> +               strlcpy(info->type, dev_name(&adev->dev),
>> sizeof(info->type));
>>
>>         return 0;
>>  }>
>
>Yes, that's what I mean.
>
>> The biggest concern is that this would change the i2c device name
>> between kernel versions. Is that acceptable?
>
>I don't think that is a problem since I still have not seen a single
>system using ACPI _DSD so I would not expect anything to break.
>
>However, I'm still not convinced it is good idea to return i2c_device_id
>from a completely different table if we match using ACPI/DT table.

All,

Is there a conclusion on this? We have been tackling the same issue and
incidentally arrived at a
similar solution as like Lenard proposed  in the patch above.

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

end of thread, other threads:[~2016-12-06 17:00 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-09 13:06 [RFC v2 0/2] Match i2c_device_id when using DT ids through ACPI Crestez Dan Leonard
2016-06-09 13:06 ` [RFC v2 1/2] acpi: Expose acpi_of_match_device Crestez Dan Leonard
2016-06-09 13:06 ` [RFC v2 2/2] i2c: Pass i2c_device_id to probe func when using DT ids through ACPI Crestez Dan Leonard
2016-06-10  6:32   ` Mika Westerberg
2016-06-10 15:57     ` Crestez Dan Leonard
2016-06-13  9:26       ` Mika Westerberg
2016-06-10  7:04   ` Wolfram Sang
2016-06-10 12:00     ` Crestez Dan Leonard
2016-06-10 13:07       ` Wolfram Sang
2016-11-01  6:14 Phong Vo
2016-12-06 17:00 ` Dmitry Torokhov

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).