i2c: Pass i2c_device_id to probe func when using DT ids through ACPI
Subsystems (2)
Quoted 2 lines
From: Mika Westerberg <[email protected]> Subject: Re: [RFC v2 2/2] i2c: Pass
i2c_device_idto probe func when
using DT ids through ACPI
Quoted 6 lines
Date: Monday 13th June 2016 09:26:55 UTC (5 months ago)
Quoted 3 lines · Crestez Dan Leonard
Quoted 2 lines · Mika Westerberg
Quoted 1 line · Crestez Dan Leonard
When devices are instatiated through devicetree the
i2c_client->name
is
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
set to the compatible string with company name stripped out. This is then matched to the
i2c_device_idtable to pass thedevice_idto 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
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
to do ACPI-specific differentiation.
This patch attempts to find a valid
i2c_device_idwhen using ACPI
with
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
DT-like compatible strings.
So I don't really understand why it would be good idea to pass
i2c_device_idfor devices which are matched against their ACPI/DT tables. Apparently DT is already doing that so maybe there is some reason.
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
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_idworks for devicetree becauseof_i2c_register_devicesets i2c_board_info.type to the compatible
string
Quoted 45 lines
i2c/i2c-core.c static int acpi_i2c_get_info(struct acpi_device
Quoted 13 lines
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_infoto use theof_compatiblestring from DSD if present. Is that what you mean? That would work and it would be cleaner than my patch. Something like this:i2c/i2c-core.c +0
-0@@ -181,7 +181,24 @@ static int acpi_i2c_get_info(struct acpi_device*adev,
Quoted 8 lines
i2c/i2c-core.c +2
-1acpi_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_nodeQuoted 17 lines
+ */
+ if (adev->data.of_compatible) {
+ const unionacpi_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));Quoted 2 lines
return 0;
}>Yes, that's what I mean.
Quoted 8 lines
Quoted 2 lines
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
_DSDso I would not expect anything to break.However, I'm still not convinced it is good idea to return
i2c_device_idfrom 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.
Quoted 85 lines · Phong Vo
Quoted 2 lines
From: Mika Westerberg <[email protected]> Subject: Re: [RFC v2 2/2] i2c: Pass
i2c_device_idto probe func whenusing DT ids through ACPI
Quoted 6 lines
Date: Monday 13th June 2016 09:26:55 UTC (5 months ago)
Quoted 3 lines · Crestez Dan Leonard
Quoted 2 lines · Mika Westerberg
Quoted 1 line · Crestez Dan Leonard
When devices are instatiated through devicetree the
i2c_client->nameis
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
set to the compatible string with company name stripped out. This is then matched to the
i2c_device_idtable to pass thedevice_idto 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
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
to do ACPI-specific differentiation.
This patch attempts to find a valid
i2c_device_idwhen using ACPIwith
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
DT-like compatible strings.
So I don't really understand why it would be good idea to pass
i2c_device_idfor devices which are matched against their ACPI/DT tables. Apparently DT is already doing that so maybe there is some reason.Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
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_idworks for devicetree becauseof_i2c_register_devicesets i2c_board_info.type to the compatiblestring
Quoted 51 lines
i2c/i2c-core.c static int acpi_i2c_get_info(struct acpi_device
Quoted 13 lines
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_infoto use theof_compatiblestring from DSD if present. Is that what you mean? That would work and it would be cleaner than my patch. Something like this:i2c/i2c-core.c +0
-0@@ -181,7 +181,24 @@ static int acpi_i2c_get_info(struct acpi_device*adev,
Quoted 8 lines
i2c/i2c-core.c +2
-1acpi_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_nodeQuoted 17 lines
+ */
+ if (adev->data.of_compatible) {
+ const unionacpi_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));Quoted 2 lines
return 0;
}>Yes, that's what I mean.
Quoted 2 lines
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
_DSDso I would not expect anything to break.
Quoted 8 lines
Quoted 2 lines
However, I'm still not convinced it is good idea to return
i2c_device_idfrom 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.
FWIW I agree with Mika (I think?) and I do not like that we mangle OF data. This causes issues with module loading (where every OF ID has to be stripped and added to the legacy table), and so forth. Drivers can either use of_device_get_match_data() to get "real" OF id, or maybe we could temporarily transform of_device_id into i2c_device_id in i2c bus code and pass it to probe(), and do the same with ACPI match data.
Thanks.
Signature · 1 line
Dmitry