2020-02-27 11:31:55

by Vitor Soares

[permalink] [raw]
Subject: [PATCH v2 0/4] i3c: Address i3c_device_id related issues

Hello,

When the I3C subsystem was introduced part of the modalias generation
logic was missing (modalias generation based on i3c_device_id tables).
This patch series addresses that limitation and simplifies our match
function along the way.

Changes in v2:
Add modalias sysfs attribute
Fix i3c_entry fields

Boris Brezillon (4):
i3c: Fix MODALIAS uevents
i3c: Add modalias sysfs attribute
i3c: Generate aliases for i3c modules
i3c: Simplify i3c_device_match_id()

drivers/i3c/device.c | 50 +++++++++++++++++----------------------
drivers/i3c/master.c | 24 ++++++++++++++++++-
scripts/mod/devicetable-offsets.c | 7 ++++++
scripts/mod/file2alias.c | 19 +++++++++++++++
4 files changed, 71 insertions(+), 29 deletions(-)

--
2.7.4


2020-02-27 11:32:38

by Vitor Soares

[permalink] [raw]
Subject: [PATCH v2 2/4] i3c: Add modalias sysfs attribute

Create modalias sysfs attribute for modalias devices.

Signed-off-by: Boris Brezillon <[email protected]>
Signed-off-by: Vitor Soares <[email protected]>
---
drivers/i3c/master.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)

diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index b6db828..925e1ed 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -241,12 +241,34 @@ static ssize_t hdrcap_show(struct device *dev,
}
static DEVICE_ATTR_RO(hdrcap);

+static ssize_t modalias_show(struct device *dev,
+ struct device_attribute *da, char *buf)
+{
+ struct i3c_device *i3c = dev_to_i3cdev(dev);
+ struct i3c_device_info devinfo;
+ u16 manuf, part, ext;
+
+ i3c_device_get_info(i3c, &devinfo);
+ manuf = I3C_PID_MANUF_ID(devinfo.pid);
+ part = I3C_PID_PART_ID(devinfo.pid);
+ ext = I3C_PID_EXTRA_INFO(devinfo.pid);
+
+ if (I3C_PID_RND_LOWER_32BITS(devinfo.pid))
+ return sprintf(buf, "i3c:dcr%02Xmanuf%04X", devinfo.dcr,
+ manuf);
+
+ return sprintf(buf, "i3c:dcr%02Xmanuf%04Xpart%04Xext%04X",
+ devinfo.dcr, manuf, part, ext);
+}
+static DEVICE_ATTR_RO(modalias);
+
static struct attribute *i3c_device_attrs[] = {
&dev_attr_bcr.attr,
&dev_attr_dcr.attr,
&dev_attr_pid.attr,
&dev_attr_dynamic_address.attr,
&dev_attr_hdrcap.attr,
+ &dev_attr_modalias.attr,
NULL,
};
ATTRIBUTE_GROUPS(i3c_device);
--
2.7.4

2020-02-27 11:32:43

by Vitor Soares

[permalink] [raw]
Subject: [PATCH v2 1/4] i3c: Fix MODALIAS uevents

From: Boris Brezillon <[email protected]>

file2alias uses %X formatters. Fix typos in the MODALIAS uevent to print
the part and ext IDs in uppercase.

Signed-off-by: Boris Brezillon <[email protected]>
Signed-off-by: Vitor Soares <[email protected]>
---
drivers/i3c/master.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index b56207b..b6db828 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -267,7 +267,7 @@ static int i3c_device_uevent(struct device *dev, struct kobj_uevent_env *env)
devinfo.dcr, manuf);

return add_uevent_var(env,
- "MODALIAS=i3c:dcr%02Xmanuf%04Xpart%04xext%04x",
+ "MODALIAS=i3c:dcr%02Xmanuf%04Xpart%04Xext%04X",
devinfo.dcr, manuf, part, ext);
}

--
2.7.4

2020-02-27 11:32:53

by Vitor Soares

[permalink] [raw]
Subject: [PATCH v2 4/4] i3c: Simplify i3c_device_match_id()

From: Boris Brezillon <[email protected]>

Simply match against ->match_flags instead of trying to be smart and
fix drivers inconsistent ID tables.

Signed-off-by: Boris Brezillon <[email protected]>
Signed-off-by: Vitor Soares <[email protected]>
---
drivers/i3c/device.c | 50 ++++++++++++++++++++++----------------------------
1 file changed, 22 insertions(+), 28 deletions(-)

diff --git a/drivers/i3c/device.c b/drivers/i3c/device.c
index 9e2e140..bb8e60d 100644
--- a/drivers/i3c/device.c
+++ b/drivers/i3c/device.c
@@ -213,40 +213,34 @@ i3c_device_match_id(struct i3c_device *i3cdev,
{
struct i3c_device_info devinfo;
const struct i3c_device_id *id;
+ u16 manuf, part, ext_info;
+ bool rndpid;

i3c_device_get_info(i3cdev, &devinfo);

- /*
- * The lower 32bits of the provisional ID is just filled with a random
- * value, try to match using DCR info.
- */
- if (!I3C_PID_RND_LOWER_32BITS(devinfo.pid)) {
- u16 manuf = I3C_PID_MANUF_ID(devinfo.pid);
- u16 part = I3C_PID_PART_ID(devinfo.pid);
- u16 ext_info = I3C_PID_EXTRA_INFO(devinfo.pid);
-
- /* First try to match by manufacturer/part ID. */
- for (id = id_table; id->match_flags != 0; id++) {
- if ((id->match_flags & I3C_MATCH_MANUF_AND_PART) !=
- I3C_MATCH_MANUF_AND_PART)
- continue;
-
- if (manuf != id->manuf_id || part != id->part_id)
- continue;
-
- if ((id->match_flags & I3C_MATCH_EXTRA_INFO) &&
- ext_info != id->extra_info)
- continue;
-
- return id;
- }
- }
+ manuf = I3C_PID_MANUF_ID(devinfo.pid);
+ part = I3C_PID_PART_ID(devinfo.pid);
+ ext_info = I3C_PID_EXTRA_INFO(devinfo.pid);
+ rndpid = I3C_PID_RND_LOWER_32BITS(devinfo.pid);

- /* Fallback to DCR match. */
for (id = id_table; id->match_flags != 0; id++) {
if ((id->match_flags & I3C_MATCH_DCR) &&
- id->dcr == devinfo.dcr)
- return id;
+ id->dcr != devinfo.dcr)
+ continue;
+
+ if ((id->match_flags & I3C_MATCH_MANUF) &&
+ id->manuf_id != manuf)
+ continue;
+
+ if ((id->match_flags & I3C_MATCH_PART) &&
+ (rndpid || id->part_id != part))
+ continue;
+
+ if ((id->match_flags & I3C_MATCH_EXTRA_INFO) &&
+ (rndpid || id->extra_info != ext_info))
+ continue;
+
+ return id;
}

return NULL;
--
2.7.4

2020-02-27 14:42:22

by Boris Brezillon

[permalink] [raw]
Subject: Re: [PATCH v2 2/4] i3c: Add modalias sysfs attribute

On Thu, 27 Feb 2020 12:31:07 +0100
Vitor Soares <[email protected]> wrote:

> Create modalias sysfs attribute for modalias devices.

^i3c

No need to send a new version, I'll fix it when applying.

>
> Signed-off-by: Boris Brezillon <[email protected]>
> Signed-off-by: Vitor Soares <[email protected]>
> ---
> drivers/i3c/master.c | 22 ++++++++++++++++++++++
> 1 file changed, 22 insertions(+)
>
> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> index b6db828..925e1ed 100644
> --- a/drivers/i3c/master.c
> +++ b/drivers/i3c/master.c
> @@ -241,12 +241,34 @@ static ssize_t hdrcap_show(struct device *dev,
> }
> static DEVICE_ATTR_RO(hdrcap);
>
> +static ssize_t modalias_show(struct device *dev,
> + struct device_attribute *da, char *buf)
> +{
> + struct i3c_device *i3c = dev_to_i3cdev(dev);
> + struct i3c_device_info devinfo;
> + u16 manuf, part, ext;
> +
> + i3c_device_get_info(i3c, &devinfo);
> + manuf = I3C_PID_MANUF_ID(devinfo.pid);
> + part = I3C_PID_PART_ID(devinfo.pid);
> + ext = I3C_PID_EXTRA_INFO(devinfo.pid);
> +
> + if (I3C_PID_RND_LOWER_32BITS(devinfo.pid))
> + return sprintf(buf, "i3c:dcr%02Xmanuf%04X", devinfo.dcr,
> + manuf);
> +
> + return sprintf(buf, "i3c:dcr%02Xmanuf%04Xpart%04Xext%04X",
> + devinfo.dcr, manuf, part, ext);
> +}
> +static DEVICE_ATTR_RO(modalias);
> +
> static struct attribute *i3c_device_attrs[] = {
> &dev_attr_bcr.attr,
> &dev_attr_dcr.attr,
> &dev_attr_pid.attr,
> &dev_attr_dynamic_address.attr,
> &dev_attr_hdrcap.attr,
> + &dev_attr_modalias.attr,
> NULL,
> };
> ATTRIBUTE_GROUPS(i3c_device);