2023-02-21 13:32:48

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v1 2/3] auxdisplay: ht16k33: Make use of device_get_match_data()

Switching to use device_get_match_data() helps getting of
i2c_of_match_device() API.

Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/auxdisplay/ht16k33.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/auxdisplay/ht16k33.c b/drivers/auxdisplay/ht16k33.c
index 02425991c159..8e2fd2291ea4 100644
--- a/drivers/auxdisplay/ht16k33.c
+++ b/drivers/auxdisplay/ht16k33.c
@@ -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;
}
}

--
2.39.1



2023-02-21 13:40:20

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v1 2/3] auxdisplay: ht16k33: Make use of device_get_match_data()

On Tue, Feb 21, 2023 at 03:33:06PM +0200, Andy Shevchenko wrote:
> Switching to use device_get_match_data() helps getting of
> i2c_of_match_device() API.

...

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

--
With Best Regards,
Andy Shevchenko



2023-02-21 16:26:15

by Robin van der Gracht

[permalink] [raw]
Subject: Re: [PATCH v1 2/3] auxdisplay: ht16k33: Make use of device_get_match_data()

Hello Andy,

On 2023-02-21 14:40, Andy Shevchenko wrote:
> On Tue, Feb 21, 2023 at 03:33:06PM +0200, Andy Shevchenko wrote:
>> Switching to use device_get_match_data() helps getting of
>> i2c_of_match_device() API.
>
> ...
>
>> - 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()?

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

2023-02-21 17:48:26

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v1 2/3] auxdisplay: ht16k33: Make use of device_get_match_data()

On Tue, Feb 21, 2023 at 05:10:00PM +0100, Robin van der Gracht wrote:
> On 2023-02-21 14:40, Andy Shevchenko wrote:
> > On Tue, Feb 21, 2023 at 03:33:06PM +0200, Andy Shevchenko wrote:
> > > Switching to use device_get_match_data() helps getting of
> > > i2c_of_match_device() API.

...

> > > - 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()?
>
> 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?

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


--
With Best Regards,
Andy Shevchenko



2023-02-22 16:46:16

by Robin van der Gracht

[permalink] [raw]
Subject: Re: [PATCH v1 2/3] auxdisplay: ht16k33: Make use of device_get_match_data()

On 2023-02-21 18:48, Andy Shevchenko wrote:
> On Tue, Feb 21, 2023 at 05:10:00PM +0100, Robin van der Gracht wrote:
>> On 2023-02-21 14:40, Andy Shevchenko wrote:
>> > On Tue, Feb 21, 2023 at 03:33:06PM +0200, Andy Shevchenko wrote:
>> > > Switching to use device_get_match_data() helps getting of
>> > > i2c_of_match_device() API.
>
> ...
>
>> > > - 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()?
>>
>> 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?
>
> 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

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,

--
Robin van der Gracht
Protonic Holland
Factorij 36
1689AL Zwaag
+31 (0)229 212928
https://www.protonic.nl

2023-02-22 17:02:23

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v1 2/3] auxdisplay: ht16k33: Make use of device_get_match_data()

On Wed, Feb 22, 2023 at 05:46:00PM +0100, Robin van der Gracht wrote:
> On 2023-02-21 18:48, Andy Shevchenko wrote:
> > On Tue, Feb 21, 2023 at 05:10:00PM +0100, Robin van der Gracht wrote:
> > > On 2023-02-21 14:40, Andy Shevchenko wrote:
> > > > On Tue, Feb 21, 2023 at 03:33:06PM +0200, Andy Shevchenko wrote:

...

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

^^^^^ (1)

> > > > So, the question is what to do with unknown type then, return -EINVAL
> > > > from probe()?
> > >
> > > 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?
> >
> > 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
>
> 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.

That's half-true. On ACPI based platforms we may have no of_node and match
against OF ID table.

> So with only device_get_match_data() and a non devicetree instantiation,
> priv->type will always be (uintptr_t)NULL = 0 = DISP_MATRIX.

Yes.

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

--
With Best Regards,
Andy Shevchenko



2023-02-22 17:21:38

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v1 2/3] auxdisplay: ht16k33: Make use of device_get_match_data()

+ Cc: OF bindings people for the mess with the IDs.

On Wed, Feb 22, 2023 at 07:01:40PM +0200, Andy Shevchenko wrote:
> On Wed, Feb 22, 2023 at 05:46:00PM +0100, Robin van der Gracht wrote:
> > On 2023-02-21 18:48, Andy Shevchenko wrote:
> > > On Tue, Feb 21, 2023 at 05:10:00PM +0100, Robin van der Gracht wrote:
> > > > On 2023-02-21 14:40, Andy Shevchenko wrote:
> > > > > On Tue, Feb 21, 2023 at 03:33:06PM +0200, Andy Shevchenko wrote:

...

> > > > > > - 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.
>
> ^^^^^ (1)
>
> > > > > So, the question is what to do with unknown type then, return -EINVAL
> > > > > from probe()?
> > > >
> > > > 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?
> > >
> > > 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
> >
> > 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.
>
> That's half-true. On ACPI based platforms we may have no of_node and match
> against OF ID table.
>
> > So with only device_get_match_data() and a non devicetree instantiation,
> > priv->type will always be (uintptr_t)NULL = 0 = DISP_MATRIX.
>
> Yes.
>
> > 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.

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?

--
With Best Regards,
Andy Shevchenko



2023-02-22 18:47:37

by Krzysztof Kozlowski

[permalink] [raw]
Subject: Re: [PATCH v1 2/3] auxdisplay: ht16k33: Make use of device_get_match_data()

On 22/02/2023 18:20, Andy Shevchenko wrote:
>>
>>> 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.
>
> 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?

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

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


2023-02-22 19:11:17

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v1 2/3] auxdisplay: ht16k33: Make use of device_get_match_data()

On Wed, Feb 22, 2023 at 07:46:25PM +0100, Krzysztof Kozlowski wrote:
> On 22/02/2023 18:20, Andy Shevchenko wrote:
> >>
> >>> 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.
> >
> > 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?

For I?C it's still possible to enumerate the device via sysfs, which is ABI.

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

> > 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?

--
With Best Regards,
Andy Shevchenko



2023-02-23 08:20:10

by Robin van der Gracht

[permalink] [raw]
Subject: Re: [PATCH v1 2/3] auxdisplay: ht16k33: Make use of device_get_match_data()

On 2023-02-22 18:20, Andy Shevchenko wrote:
> + Cc: OF bindings people for the mess with the IDs.
>
> On Wed, Feb 22, 2023 at 07:01:40PM +0200, Andy Shevchenko wrote:
>> On Wed, Feb 22, 2023 at 05:46:00PM +0100, Robin van der Gracht wrote:
>> > On 2023-02-21 18:48, Andy Shevchenko wrote:
>> > > On Tue, Feb 21, 2023 at 05:10:00PM +0100, Robin van der Gracht wrote:
>> > > > On 2023-02-21 14:40, Andy Shevchenko wrote:
>> > > > > On Tue, Feb 21, 2023 at 03:33:06PM +0200, Andy Shevchenko wrote:
>
> ...
>
>> > > > > > - 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.
>>
>> ^^^^^ (1)
>>
>> > > > > So, the question is what to do with unknown type then, return -EINVAL
>> > > > > from probe()?
>> > > >
>> > > > 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?
>> > >
>> > > 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
>> >
>> > 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.
>>
>> That's half-true. On ACPI based platforms we may have no of_node and
>> match
>> against OF ID table.
>>
>> > So with only device_get_match_data() and a non devicetree instantiation,
>> > priv->type will always be (uintptr_t)NULL = 0 = DISP_MATRIX.
>>
>> Yes.
>>
>> > 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.
>
> 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?

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

2023-02-23 09:55:59

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH v1 2/3] auxdisplay: ht16k33: Make use of device_get_match_data()

Hi Andy,

On Wed, Feb 22, 2023 at 8:21 PM Andy Shevchenko
<[email protected]> wrote:
> On Wed, Feb 22, 2023 at 07:46:25PM +0100, Krzysztof Kozlowski wrote:
> > On 22/02/2023 18:20, Andy Shevchenko wrote:
> > >>> 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.
> > >
> > > 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?
>
> 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.

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

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

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

2023-02-23 11:53:28

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v1 2/3] auxdisplay: ht16k33: Make use of device_get_match_data()

On Thu, Feb 23, 2023 at 10:55:15AM +0100, Geert Uytterhoeven wrote:
> On Wed, Feb 22, 2023 at 8:21 PM Andy Shevchenko
> <[email protected]> wrote:
> > On Wed, Feb 22, 2023 at 07:46:25PM +0100, Krzysztof Kozlowski wrote:

...

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


--
With Best Regards,
Andy Shevchenko