i2c: stop using i2c_of_match_device()
Subsystems (6)
PATCH 1/3 usb: typec: stusb160x: Make use of device_get_match_data()
In reply to Andy ShevchenkoSwitching to use device_get_match_data() helps getting of i2c_of_match_device() API.
--- drivers/usb/typec/stusb160x.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/usb/typec/stusb160x.c +4 -4
@@ -11,6 +11,7 @@#include <linux/interrupt.h> #include <linux/kernel.h> #include <linux/module.h> +#include <linux/property.h> #include <linux/regmap.h> #include <linux/regulator/consumer.h> #include <linux/usb/role.h>
@@ -633,9 +634,8 @@ MODULE_DEVICE_TABLE(of, stusb160x_of_match);static int stusb160x_probe (struct i2c_client *client) { +const struct regmap_config *regmap_config;struct stusb160x *chip; -const struct of_device_id *match; -struct regmap_config *regmap_config;struct fwnode_handle *fwnode;int ret;
@@ -645,8 +645,8 @@ static int stusb160x_probe(struct i2c_client *client)i2c_set_clientdata (client, chip); - match =i2c_of_match_device (stusb160x_of_match, client); - regmap_config = (struct regmap_config *)match->data; + regmap_config =device_get_match_data (&client->dev); + chip->regmap =devm_regmap_init_i2c (client, regmap_config);if (IS_ERR (chip->regmap)) { ret =PTR_ERR (chip->regmap);
Signature · 1 line
2.39.1
PATCH 2/3 auxdisplay: ht16k33: Make use of device_get_match_data()
In reply to Andy ShevchenkoSwitching to use device_get_match_data() helps getting of i2c_of_match_device() API.
--- drivers/auxdisplay/ht16k33.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/auxdisplay/ht16k33.c +10 -5
@@ -60,7 +60,8 @@#define HT16K33_FB_SIZE (HT16K33_MATRIX_LED_MAX_COLS * BYTES_PER_ROW)enum display_type { -DISP_MATRIX =0 , +DISP_UNKNOWN =0 , +DISP_MATRIX ,DISP_QUAD_7SEG ,DISP_QUAD_14SEG , };
@@ -675,6 +676,7 @@ static int ht16k33_seg_probe(struct device *dev, struct ht16k33_priv *priv,return err;switch (priv->type) { +default :case DISP_MATRIX :/* not handled here */ err = -EINVAL ;
@@ -713,7 +715,6 @@ static int ht16k33_seg_probe(struct device *dev, struct ht16k33_priv *priv,static int ht16k33_probe (struct i2c_client *client) {struct device *dev = &client->dev; -const struct of_device_id *id;struct ht16k33_priv *priv;uint32_t dft_brightness;int err;
@@ -728,9 +729,8 @@ static int ht16k33_probe(struct i2c_client *client)return -ENOMEM ; priv->client = client; - id =i2c_of_match_device (dev->driver->of_match_table, client); -if (id) - priv->type = (uintptr_t )id->data; + priv->type = (uintptr_t )device_get_match_data (dev); +i2c_set_clientdata (client, priv); err =ht16k33_initialize (priv);
@@ -771,6 +771,9 @@ static int ht16k33_probe(struct i2c_client *client)/* Segment Display */ err =ht16k33_seg_probe (dev, priv, dft_brightness);break ; +default : +/* Unknown display; enumerated via user space? */ + err =0 ; }return err; }
@@ -795,6 +798,8 @@ static void ht16k33_remove(struct i2c_client *client)device_remove_file (&client->dev, &dev_attr_map_seg7);device_remove_file (&client->dev, &dev_attr_map_seg14);break ; +default : +break ; } }
Signature · 1 line
2.39.1
PATCH 3/3 i2c: Unexport i2c_of_match_device()
In reply to Andy Shevchenkoi2c_of_match_device() is not used anymore outside of I²C framework, unexport it.
--- drivers/i2c/i2c-core-of.c | 1 - drivers/i2c/i2c-core.h | 9 +++++++++ include/linux/i2c.h | 11 ----------- 3 files changed, 9 insertions(+), 12 deletions(-)
drivers/i2c/i2c-core-of.c +0 -1
@@ -157,7 +157,6 @@ const struct of_device_idreturn i2c_of_match_device_sysfs (matches, client); } -EXPORT_SYMBOL_GPL (i2c_of_match_device);#if IS_ENABLED (CONFIG_OF_DYNAMIC ) static int of_i2c_notify(struct notifier_block *nb, unsigned long action,
drivers/i2c/i2c-core.h +9 -0
@@ -82,8 +82,17 @@ static inline void i2c_acpi_remove_space_handler(struct i2c_adapter *adapter) {#ifdef CONFIG_OF void of_i2c_register_devices (struct i2c_adapter *adap); +const struct of_device_id *i2c_of_match_device (const struct of_device_id *matches, +struct i2c_client *client); +#else static inline void of_i2c_register_devices (struct i2c_adapter *adap) { } +static inline +const struct of_device_id *i2c_of_match_device (const struct of_device_id *matches, +struct i2c_client *client) +{ +return NULL ; +}#endif extern struct notifier_block i2c_of_notifier;
include/linux/i2c.h +0 -11
@@ -993,10 +993,6 @@ static inline struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_nodereturn i2c_get_adapter_by_fwnode (of_fwnode_handle (node)); } -const struct of_device_id -*i2c_of_match_device (const struct of_device_id *matches, -struct i2c_client *client); -int of_i2c_get_board_info (struct device *dev,struct device_node *node,struct i2c_board_info *info);
@@ -1017,13 +1013,6 @@ static inline struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_nodereturn NULL ; } -static inline const struct of_device_id -*i2c_of_match_device (const struct of_device_id *matches, -struct i2c_client *client) -{ -return NULL ; -} -static inline int of_i2c_get_board_info (struct device *dev,struct device_node *node,struct i2c_board_info *info)
Signature · 1 line
2.39.1
cover i2c: stop using i2c_of_match_device()
i2c_of_match_device() is used by core and a couple of drivers. Instead, convert those drivers to use device_get_match_data() and unexport i2c_of_match_device().
Andy Shevchenko (3):
usb: typec: stusb160x: Make use of device_get_match_data()
auxdisplay: ht16k33: Make use of device_get_match_data()
i2c: Unexport i2c_of_match_device()
drivers/auxdisplay/ht16k33.c | 15 ++++++++++----- drivers/i2c/i2c-core-of.c | 1 - drivers/i2c/i2c-core.h | 9 +++++++++ drivers/usb/typec/stusb160x.c | 8 ++++---- include/linux/i2c.h | 11 ----------- 5 files changed, 23 insertions(+), 21 deletions(-)
Signature · 1 line
2.39.1
Re: [PATCH v1 2/3] auxdisplay: ht16k33: Make use of device_get_match_data()
In reply to Andy ShevchenkoQuoted 2 lines · Andy Shevchenko
Switching to use
device_get_match_data()helps getting ofi2c_of_match_device()API.
...
drivers/auxdisplay/ht16k33.c static int ht16k33_probe(struct i2c_client *client) · line 732
Quoted 4 lines
drivers/auxdisplay/ht16k33.c +1
-3- id =i2c_of_match_device (dev->driver->of_match_table, client); -if (id) - priv->type = (uintptr_t )id->data; + priv->type = (uintptr_t )device_get_match_data (dev);
Looking closer the I²C ID table should provide DISP_MATRIX to keep default and this needs to be not dropped.
So, the question is what to do with unknown type then, return -EINVAL from probe()?
P.S. I would like to collect other comments anyway, so I will send a v2 later.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v1 1/3] usb: typec: stusb160x: Make use of device_get_match_data()
In reply to Andy ShevchenkoQuoted 4 lines · Andy Shevchenko
Switching to use
device_get_match_data()helps getting ofi2c_of_match_device()API.Signed-off-by Andy Shevchenko <[email protected]>
Quoted 28 lines
--- drivers/usb/typec/stusb160x.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/usb/typec/stusb160x.c +2
-2@@ -11,6 +11,7 @@#include <linux/interrupt.h> #include <linux/kernel.h> #include <linux/module.h> +#include <linux/property.h> #include <linux/regmap.h> #include <linux/regulator/consumer.h> #include <linux/usb/role.h> @@ -633,9 +634,8 @@ MODULE_DEVICE_TABLE(of, stusb160x_of_match);static int stusb160x_probe (struct i2c_client *client) { +const struct regmap_config *regmap_config;struct stusb160x *chip; -const struct of_device_id *match; -struct regmap_config *regmap_config;struct fwnode_handle *fwnode;int ret;
drivers/usb/typec/stusb160x.c static int stusb160x_probe(struct i2c_client *client) · line 652
Quoted 10 lines
drivers/usb/typec/stusb160x.c +2
-2@@ -645,8 +645,8 @@ static int stusb160x_probe(struct i2c_client *client)i2c_set_clientdata (client, chip); - match =i2c_of_match_device (stusb160x_of_match, client); - regmap_config = (struct regmap_config *)match->data; + regmap_config =device_get_match_data (&client->dev); + chip->regmap =devm_regmap_init_i2c (client, regmap_config);if (IS_ERR (chip->regmap)) { ret =PTR_ERR (chip->regmap);
thanks,
Signature · 1 line
heikki
Robin van der Gracht
maintainerRe: [PATCH v1 2/3] auxdisplay: ht16k33: Make use of device_get_match_data()
In reply to Andy ShevchenkoHello Andy,
Quoted 14 lines · Andy Shevchenko
Quoted 2 lines · Andy Shevchenko
Switching to use
device_get_match_data()helps getting ofi2c_of_match_device()API....
drivers/auxdisplay/ht16k33.c static int ht16k33_probe(struct i2c_client *client) · line 732
Quoted 4 lines
drivers/auxdisplay/ht16k33.c +1
-3- id =i2c_of_match_device (dev->driver->of_match_table, client); -if (id) - priv->type = (uintptr_t )id->data; + priv->type = (uintptr_t )device_get_match_data (dev);Looking closer the I²C ID table should provide
DISP_MATRIXto keep default and this needs to be not dropped.
Quoted 2 lines
So, the question is what to do with unknown type then, return
-EINVALfromprobe()?
If you leave out your addition of the DISP_UNKNOWN type, the default type will be DISP_MATRIX if no match is found, which is as it is now.
In that case the following change should suffice:
@@ -713,7 +715,6 @@ static int ht16k33_seg_probe(struct device *dev, struct ht16k33_priv *priv,
static int ht16k33_probe(struct i2c_client *client)
{
struct device *dev = &client->dev;
- const struct of_device_id *id;
struct ht16k33_priv *priv;
uint32_t dft_brightness;
int err;
@@ -728,9 +729,8 @@ static int ht16k33_probe(struct i2c_client *client)
return -ENOMEM;
priv->client = client;- id = i2c_of_match_device(dev->driver->of_match_table, client);
- if (id)
- priv->type = (uintptr_t)id->data;
+ priv->type = (uintptr_t)device_get_match_data(dev);
+
i2c_set_clientdata(client, priv);
err = ht16k33_initialize(priv);Or do you think falling back to DISP_MATRIX if no match is found is wrong?
Kind regards,
Robin
Re: [PATCH v1 2/3] auxdisplay: ht16k33: Make use of device_get_match_data()
Quoted 4 lines · Robin van der Gracht
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Andy Shevchenko
Switching to use
device_get_match_data()helps getting ofi2c_of_match_device()API.
...
Quoted 38 lines
Quoted 10 lines
drivers/auxdisplay/ht16k33.c static int ht16k33_probe(struct i2c_client *client) · line 732
Quoted 4 lines
drivers/auxdisplay/ht16k33.c +1
-3- id =i2c_of_match_device (dev->driver->of_match_table, client); -if (id) - priv->type = (uintptr_t )id->data; + priv->type = (uintptr_t )device_get_match_data (dev);Looking closer the I²C ID table should provide
DISP_MATRIXto keep default and this needs to be not dropped.So, the question is what to do with unknown type then, return
-EINVALfromprobe()?If you leave out your addition of the
DISP_UNKNOWNtype, the default type will beDISP_MATRIXif no match is found, which is as it is now.In that case the following change should suffice:
drivers/auxdisplay/ht16k33.c +0
-1@@ -713,7 +715,6 @@ static int ht16k33_seg_probe(struct device *dev, structht16k33_priv *priv, static int ht16k33_probe(struct i2c_client *client) { struct device *dev = &client->dev; -const struct of_device_id *id;struct ht16k33_priv *priv;uint32_t dft_brightness;int err;drivers/auxdisplay/ht16k33.c +2
-3@@ -728,9 +729,8 @@ static int ht16k33_probe(struct i2c_client *client)return -ENOMEM ; priv->client = client; - id =i2c_of_match_device (dev->driver->of_match_table, client); -if (id) - priv->type = (uintptr_t )id->data; + priv->type = (uintptr_t )device_get_match_data (dev); +i2c_set_clientdata (client, priv); err =ht16k33_initialize (priv);
Quoted 1 line
Or do you think falling back to
DISP_MATRIXif no match is found is wrong?
First of all, the I²C ID table should actually use DISP_MATRIX.
Second, there are two points:
- It would be nice to check if the OF ID table doesn't provide a setting (shouldn't we try I²C ID table and then, if still nothing, bail out?)
- The I²C ID table can be extended in the future with another entry which may want to have different default
Signature · 2 lines
With Best Regards, Andy Shevchenko
Robin van der Gracht
maintainerRe: [PATCH v1 2/3] auxdisplay: ht16k33: Make use of device_get_match_data()
Quoted 54 lines · Andy Shevchenko
Quoted 4 lines · Robin van der Gracht
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Andy Shevchenko
Switching to use
device_get_match_data()helps getting ofi2c_of_match_device()API....
Quoted 40 lines
Quoted 10 lines
drivers/auxdisplay/ht16k33.c static int ht16k33_probe(struct i2c_client *client) · line 732
Quoted 4 lines
drivers/auxdisplay/ht16k33.c +1
-3- id =i2c_of_match_device (dev->driver->of_match_table, client); -if (id) - priv->type = (uintptr_t )id->data; + priv->type = (uintptr_t )device_get_match_data (dev);Looking closer the I²C ID table should provide
DISP_MATRIXto keep default and this needs to be not dropped.So, the question is what to do with unknown type then, return
-EINVALfromprobe()?If you leave out your addition of the
DISP_UNKNOWNtype, the default type will beDISP_MATRIXif no match is found, which is as it is now.In that case the following change should suffice:
(quoted diff) +0
-0@@ -713,7 +715,6 @@ static int ht16k33_seg_probe(struct device *dev,struct
ht16k33_priv*priv,
static intht16k33_probe(struct i2c_client *client){ struct device *dev = &client->dev;drivers/auxdisplay/ht16k33.c +2
-4-const struct of_device_id *id;struct ht16k33_priv *priv;uint32_t dft_brightness;int err;@@ -728,9 +729,8 @@ static int ht16k33_probe(struct i2c_client *client)return -ENOMEM ; priv->client = client; - id =i2c_of_match_device (dev->driver->of_match_table, client); -if (id) - priv->type = (uintptr_t )id->data; + priv->type = (uintptr_t )device_get_match_data (dev); +i2c_set_clientdata (client, priv);err = ht16k33_initialize(priv);Quoted 1 line
Or do you think falling back to
DISP_MATRIXif no match is found is wrong?First of all, the I²C ID table should actually use
DISP_MATRIX.Second, there are two points:
Quoted 7 lines
- It would be nice to check if the OF ID table doesn't provide a setting
(shouldn't we try I²C ID table and then, if still nothing, bail out?)- The I²C ID table can be extended in the future with another entry which
may want to have different default
For my understanding, please correct me if I'm wrong;
For all methods of instantiation during ht16k33 probe, i2c_of_match_device() matches the compatible strings in the OF ID table due to a call to i2c_of_match_device_sysfs().
device_get_match_data() only matches the compatible strings in the OF ID table for devicetree instantiation because of_match_device() won't match is there is no actual of_node.
So with only device_get_match_data() and a non devicetree instantiation, priv->type will always be (uintptr_t)NULL = 0 = DISP_MATRIX.
Which effectively breaks i.e. user-space instantiation for other display types which now do work due to i2c_of_match_device().
(so my suggestion above is not sufficient).
Are you proposing extending and searching the I2C ID table to work around that?
Kind regards,
Signature · 6 lines
Robin van der Gracht Protonic Holland Factorij 36 1689AL Zwaag +31 (0)229 212928 https://www.protonic.nl
Re: [PATCH v1 2/3] auxdisplay: ht16k33: Make use of device_get_match_data()
Quoted 4 lines · Robin van der Gracht
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Robin van der Gracht
Quoted 1 line · Andy Shevchenko
On Tue, Feb 21, 2023 at 03:33:06PM +0200, Andy Shevchenko wrote:
...
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/auxdisplay/ht16k33.c static int ht16k33_probe(struct i2c_client *client) · line 732
Quoted 4 lines
drivers/auxdisplay/ht16k33.c +1
-3- id =i2c_of_match_device (dev->driver->of_match_table, client); -if (id) - priv->type = (uintptr_t )id->data; + priv->type = (uintptr_t )device_get_match_data (dev);Looking closer the I²C ID table should provide
DISP_MATRIXto keep default andthis needs to be not dropped.
^^^^^ (1)
Quoted 49 lines
Quoted 38 lines
Quoted 33 lines
Quoted 2 lines
So, the question is what to do with unknown type then, return
-EINVALfromprobe()?If you leave out your addition of the
DISP_UNKNOWNtype, the default type
will beDISP_MATRIXif no match is found, which is as it is now.In that case the following change should suffice:
(quoted diff) +0
-0@@ -713,7 +715,6 @@ static int ht16k33_seg_probe(struct device *dev,struct
ht16k33_priv*priv,
static intht16k33_probe(struct i2c_client *client){ struct device *dev = &client->dev;drivers/auxdisplay/ht16k33.c +2
-4-const struct of_device_id *id;struct ht16k33_priv *priv;uint32_t dft_brightness;int err;@@ -728,9 +729,8 @@ static int ht16k33_probe(struct i2c_client *client)return -ENOMEM ; priv->client = client; - id =i2c_of_match_device (dev->driver->of_match_table, client); -if (id) - priv->type = (uintptr_t )id->data; + priv->type = (uintptr_t )device_get_match_data (dev); +i2c_set_clientdata (client, priv);err = ht16k33_initialize(priv);Quoted 2 lines
Or do you think falling back to
DISP_MATRIXif no match is found is wrong?First of all, the I²C ID table should actually use
DISP_MATRIX.Quoted 8 lines
Second, there are two points:
- It would be nice to check if the OF ID table doesn't provide a setting (shouldn't we try I²C ID table and then, if still nothing, bail out?)
- The I²C ID table can be extended in the future with another entry which
may want to have different defaultFor my understanding, please correct me if I'm wrong;
Quoted 7 lines
For all methods of instantiation during ht16k33 probe,
i2c_of_match_device()matches the compatible strings in the OF ID table due to a call toi2c_of_match_device_sysfs().
device_get_match_data()only matches the compatible strings in the OF ID table for devicetree instantiation becauseof_match_device()won't match is there is no actualof_node.
That's half-true. On ACPI based platforms we may have no of_node and match against OF ID table.
Quoted 2 lines
So with only
device_get_match_data()and a non devicetree instantiation,priv->typewill always be (uintptr_t)NULL = 0 =DISP_MATRIX.
Yes.
Quoted 6 lines
Which effectively breaks i.e. user-space instantiation for other display types which now do work due to
i2c_of_match_device().
(so my suggestion above is not sufficient).Are you proposing extending and searching the I2C ID table to work around that?
See (1) above. This is the downside I have noticed after sending this series. So, the I²C ID table match has to be restored, but the above mentioned issues with existing table are not gone, hence they need to be addressed in the next version.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v1 2/3] auxdisplay: ht16k33: Make use of device_get_match_data()
+ Cc: OF bindings people for the mess with the IDs.
Quoted 5 lines · Andy Shevchenko
Quoted 4 lines · Robin van der Gracht
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Robin van der Gracht
Quoted 1 line · Andy Shevchenko
On Tue, Feb 21, 2023 at 03:33:06PM +0200, Andy Shevchenko wrote:
...
Quoted 81 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/auxdisplay/ht16k33.c static int ht16k33_probe(struct i2c_client *client) · line 732
Quoted 4 lines
drivers/auxdisplay/ht16k33.c +1
-3- id =i2c_of_match_device (dev->driver->of_match_table, client); -if (id) - priv->type = (uintptr_t )id->data; + priv->type = (uintptr_t )device_get_match_data (dev);Looking closer the I²C ID table should provide
DISP_MATRIXto keep default andthis needs to be not dropped.
^^^^^ (1)
Quoted 49 lines
Quoted 38 lines
Quoted 33 lines
Quoted 2 lines
So, the question is what to do with unknown type then, return
-EINVALfromprobe()?If you leave out your addition of the
DISP_UNKNOWNtype, the default type
will beDISP_MATRIXif no match is found, which is as it is now.In that case the following change should suffice:
(quoted diff) +0
-0@@ -713,7 +715,6 @@ static int ht16k33_seg_probe(struct device *dev,struct
ht16k33_priv*priv,
static intht16k33_probe(struct i2c_client *client){ struct device *dev = &client->dev;drivers/auxdisplay/ht16k33.c +2
-4-const struct of_device_id *id;struct ht16k33_priv *priv;uint32_t dft_brightness;int err;@@ -728,9 +729,8 @@ static int ht16k33_probe(struct i2c_client *client)return -ENOMEM ; priv->client = client; - id =i2c_of_match_device (dev->driver->of_match_table, client); -if (id) - priv->type = (uintptr_t )id->data; + priv->type = (uintptr_t )device_get_match_data (dev); +i2c_set_clientdata (client, priv);err = ht16k33_initialize(priv);Quoted 2 lines
Or do you think falling back to
DISP_MATRIXif no match is found is wrong?First of all, the I²C ID table should actually use
DISP_MATRIX.Quoted 8 lines
Second, there are two points:
- It would be nice to check if the OF ID table doesn't provide a setting (shouldn't we try I²C ID table and then, if still nothing, bail out?)
- The I²C ID table can be extended in the future with another entry which
may want to have different defaultFor my understanding, please correct me if I'm wrong;
Quoted 7 lines
For all methods of instantiation during ht16k33 probe,
i2c_of_match_device()matches the compatible strings in the OF ID table due to a call toi2c_of_match_device_sysfs().
device_get_match_data()only matches the compatible strings in the OF ID table for devicetree instantiation becauseof_match_device()won't match is there is no actualof_node.That's half-true. On ACPI based platforms we may have no
of_nodeand match against OF ID table.Quoted 2 lines
So with only
device_get_match_data()and a non devicetree instantiation,priv->typewill always be (uintptr_t)NULL = 0 =DISP_MATRIX.Yes.
Quoted 4 lines
Which effectively breaks i.e. user-space instantiation for other display types which now do work due to
i2c_of_match_device().
(so my suggestion above is not sufficient).
Quoted 7 lines
Quoted 2 lines
Are you proposing extending and searching the I2C ID table to work around that?
See (1) above. This is the downside I have noticed after sending this series. So, the I²C ID table match has to be restored, but the above mentioned issues with existing table are not gone, hence they need to be addressed in the next version.
I see now what you mean. So, we have even more issues in this driver:
- I²C table is not in sync with all devices supported
- the OF ID table seems has something really badly formed for adafruit (just a number after a comma)
The latter shows how broken it is. The I²C ID table mechanism is used as a backward compatibility to the OF. Unfortunately, user space may not provide the data except in form of DT overlays, so for the legacy enumeration we have only device name, which is a set of 4 digits for adafruit case.
Now imagine if by some reason we will get adafruit2 (you name it) with the same schema. How I²C framework can understand that you meant adafruit and not adafruit2? Or did I miss something?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v1 2/3] auxdisplay: ht16k33: Make use of device_get_match_data()
Quoted 8 lines · Andy Shevchenko
Quoted 8 lines
Quoted 7 lines
Which effectively breaks i.e. user-space instantiation for other display types which now do work due to
i2c_of_match_device().
(so my suggestion above is not sufficient).Are you proposing extending and searching the I2C ID table to work around that?
Quoted 7 lines
Quoted 4 lines
See (1) above. This is the downside I have noticed after sending this series. So, the I²C ID table match has to be restored, but the above mentioned issues with existing table are not gone, hence they need to be addressed in the next version.
I see now what you mean. So, we have even more issues in this driver:
- I²C table is not in sync with all devices supported
Does anything actually rely on i2c_device_id table? ACPI would match either via ACPI or OF tables. All modern ARM systems (e.g. imx6) are DT-based. Maybe just drop the I2C ID table?
Quoted 2 lines
- the OF ID table seems has something really badly formed for adafruit (just a number after a comma)
Maybe it is a model number? It was documented:Documentation/devicetree/bindings/auxdisplay/holtek,ht16k33.yaml
Quoted 10 lines
The latter shows how broken it is. The I²C ID table mechanism is used as a backward compatibility to the OF. Unfortunately, user space may not provide the data except in form of DT overlays, so for the legacy enumeration we have only device name, which is a set of 4 digits for adafruit case.
Now imagine if by some reason we will get adafruit2 (you name it) with the same schema. How I²C framework can understand that you meant adafruit and not adafruit2? Or did I miss something?
Best regards,
Krzysztof
Re: [PATCH v1 2/3] auxdisplay: ht16k33: Make use of device_get_match_data()
Quoted 14 lines · Krzysztof Kozlowski
Quoted 13 lines · Andy Shevchenko
Quoted 12 lines
Quoted 7 lines
Which effectively breaks i.e. user-space instantiation for other display types which now do work due to
i2c_of_match_device().
(so my suggestion above is not sufficient).Are you proposing extending and searching the I2C ID table to work around that?
See (1) above. This is the downside I have noticed after sending this series. So, the I²C ID table match has to be restored, but the above mentioned issues with existing table are not gone, hence they need to be addressed in the next version.
Quoted 6 lines
Quoted 2 lines
I see now what you mean. So, we have even more issues in this driver:
- I²C table is not in sync with all devices supportedDoes anything actually rely on
i2c_device_idtable? ACPI would match either via ACPI or OF tables. All modern ARM systems (e.g. imx6) are DT-based. Maybe just drop the I2C ID table?
For I²C it's still possible to enumerate the device via sysfs, which is ABI.
Quoted 5 lines
Quoted 2 lines
- the OF ID table seems has something really badly formed for adafruit (just a number after a comma)
Maybe it is a model number? It was documented:
Documentation/devicetree/bindings/auxdisplay/holtek,ht16k33.yaml
Yes, it's not a problem for ACPI/DT platforms, the problem is for the above way of enumeration, so if we have more than 1 manufacturer that uses plain numbers for the model, I²C framework may not distinguish which driver to use.
I.o.w. the part after comma in the compatible strings of the I²C devices must be unique globally to make that enumeration disambiguous.
Quoted 8 lines
Quoted 8 lines
The latter shows how broken it is. The I²C ID table mechanism is used as a backward compatibility to the OF. Unfortunately, user space may not provide the data except in form of DT overlays, so for the legacy enumeration we have only device name, which is a set of 4 digits for adafruit case.
Now imagine if by some reason we will get adafruit2 (you name it) with the same schema. How I²C framework can understand that you meant adafruit and not adafruit2? Or did I miss something?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Robin van der Gracht
maintainerRe: [PATCH v1 2/3] auxdisplay: ht16k33: Make use of device_get_match_data()
In reply to Andy ShevchenkoQuoted 105 lines · Andy Shevchenko
+ Cc: OF bindings people for the mess with the IDs.
Quoted 5 lines · Andy Shevchenko
Quoted 4 lines · Robin van der Gracht
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Robin van der Gracht
Quoted 1 line · Andy Shevchenko
On Tue, Feb 21, 2023 at 03:33:06PM +0200, Andy Shevchenko wrote:
...
Quoted 81 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Review
Quoted 4 lines
(quoted diff) +1
-3- id = i2c_of_match_device(dev->driver->of_match_table, client); - if (id) - priv->type = (uintptr_t)id->data; + priv->type = (uintptr_t)device_get_match_data(dev);Looking closer the I²C ID table should provide
DISP_MATRIXto keep default andthis needs to be not dropped.
^^^^^ (1)
Quoted 49 lines
Quoted 38 lines
Quoted 33 lines
Quoted 2 lines
So, the question is what to do with unknown type then, return
-EINVALfromprobe()?If you leave out your addition of the
DISP_UNKNOWNtype, the default type
will beDISP_MATRIXif no match is found, which is as it is now.In that case the following change should suffice:
(quoted diff) +0
-0@@ -713,7 +715,6 @@ static int ht16k33_seg_probe(struct device *dev,struct
ht16k33_priv*priv,
static intht16k33_probe(struct i2c_client *client){ struct device *dev = &client->dev;(quoted diff) +2
-4- const struct of_device_id *id; struct ht16k33_priv *priv; uint32_t dft_brightness; int err;@@ -728,9 +729,8 @@ static int ht16k33_probe(struct i2c_client *client) return -ENOMEM; priv->client = client; - id = i2c_of_match_device(dev->driver->of_match_table, client); - if (id) - priv->type = (uintptr_t)id->data; + priv->type = (uintptr_t)device_get_match_data(dev); + i2c_set_clientdata(client, priv);err = ht16k33_initialize(priv);Quoted 2 lines
Or do you think falling back to
DISP_MATRIXif no match is found is wrong?First of all, the I²C ID table should actually use
DISP_MATRIX.Quoted 8 lines
Second, there are two points:
- It would be nice to check if the OF ID table doesn't provide a setting (shouldn't we try I²C ID table and then, if still nothing, bail out?)
- The I²C ID table can be extended in the future with another entry which
may want to have different defaultFor my understanding, please correct me if I'm wrong;
Quoted 7 lines
For all methods of instantiation during ht16k33 probe,
i2c_of_match_device()matches the compatible strings in the OF ID table due to a call toi2c_of_match_device_sysfs().
device_get_match_data()only matches the compatible strings in the OF ID table for devicetree instantiation becauseof_match_device()won't match is there is no actualof_node.That's half-true. On ACPI based platforms we may have no
of_nodeand match against OF ID table.Quoted 2 lines
So with only
device_get_match_data()and a non devicetree instantiation,priv->typewill always be (uintptr_t)NULL = 0 =DISP_MATRIX.Yes.
Quoted 4 lines
Which effectively breaks i.e. user-space instantiation for other display types which now do work due to
i2c_of_match_device().
(so my suggestion above is not sufficient).Quoted 7 lines
Quoted 2 lines
Are you proposing extending and searching the I2C ID table to work around that?
See (1) above. This is the downside I have noticed after sending this series. So, the I²C ID table match has to be restored, but the above mentioned issues with existing table are not gone, hence they need to be addressed in the next version.
I see now what you mean. So, we have even more issues in this driver:
- I²C table is not in sync with all devices supported
- the OF ID table seems has something really badly formed for adafruit (just a number after a comma)
Quoted 8 lines
The latter shows how broken it is. The I²C ID table mechanism is used as a backward compatibility to the OF. Unfortunately, user space may not provide the data except in form of DT overlays, so for the legacy enumeration we have only device name, which is a set of 4 digits for adafruit case.
Now imagine if by some reason we will get adafruit2 (you name it) with the same schema. How I²C framework can understand that you meant adafruit and not adafruit2? Or did I miss something?
I agree.
I've added Geert Uytterhoeven to the CC. He added support for the adafruit segment displays. Maybe he has a comment on this.
Kind regards,
Robin van der Gracht
Geert Uytterhoeven
reviewerRe: [PATCH v1 2/3] auxdisplay: ht16k33: Make use of device_get_match_data()
In reply to Andy ShevchenkoHi Andy,
Quoted 14 lines · Andy Shevchenko
Quoted 13 lines · Krzysztof Kozlowski
Quoted 12 lines · Andy Shevchenko
Quoted 11 lines
Quoted 6 lines
Which effectively breaks i.e. user-space instantiation for other display types which now do work due to
i2c_of_match_device().
(so my suggestion above is not sufficient).Are you proposing extending and searching the I2C ID table to work around that?
See (1) above. This is the downside I have noticed after sending this series. So, the I²C ID table match has to be restored, but the above mentioned issues with existing table are not gone, hence they need to be addressed in the next version.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
I see now what you mean. So, we have even more issues in this driver:
- I²C table is not in sync with all devices supportedDoes anything actually rely on
i2c_device_idtable? ACPI would match either via ACPI or OF tables. All modern ARM systems (e.g. imx6) are DT-based. Maybe just drop the I2C ID table?For I²C it's still possible to enumerate the device via sysfs, which is ABI.
Yes, and AFAIK, that worked fine. E.g.
echo adafruit,3130 0x70 > /sys/class/i2c/i2c-adapter/.../new_device
Cfr. https://lore.kernel.org/all/[email protected]/
Note that that example actually includes the manufacturer. I didn't check whether the I2C core takes that part into account when matching, or just strips it.
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
- the OF ID table seems has something really badly formed for adafruit (just a number after a comma)
Maybe it is a model number? It was documented:
Documentation/devicetree/bindings/auxdisplay/holtek,ht16k33.yaml
Quoted 6 lines
Yes, it's not a problem for ACPI/DT platforms, the problem is for the above way of enumeration, so if we have more than 1 manufacturer that uses plain numbers for the model, I²C framework may not distinguish which driver to use.
I.o.w. the part after comma in the compatible strings of the I²C devices must be unique globally to make that enumeration disambiguous.
Which is not unique to this driver?
I bet you can find other compatible values that become non-unique after stripping the manufacturer.
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Re: [PATCH v1 2/3] auxdisplay: ht16k33: Make use of device_get_match_data()
Quoted 3 lines · Geert Uytterhoeven
Quoted 1 line · Andy Shevchenko
On Wed, Feb 22, 2023 at 07:46:25PM +0100, Krzysztof Kozlowski wrote:
...
Quoted 6 lines
Quoted 2 lines
I.o.w. the part after comma in the compatible strings of the I²C devices must be unique globally to make that enumeration disambiguous.
Which is not unique to this driver?
I bet you can find other compatible values that become non-unique after stripping the manufacturer.
Yes, exactly my point.
So this all schema is error prone. Hence I would not rely on it at all.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 3 lines · Andy Shevchenko
i2c_of_match_device()is used by core and a couple of drivers. Instead, convert those drivers to usedevice_get_match_data()and unexporti2c_of_match_device().
After a good discussion and reading a bit deeper some code, self-NAK for this series. We seems need to be more smart.
Signature · 2 lines
With Best Regards, Andy Shevchenko