linux-i3c.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/4] i3c: Address i3c_device_id related issues
@ 2020-02-27 11:31 Vitor Soares
  2020-02-27 11:31 ` [PATCH v2 1/4] i3c: Fix MODALIAS uevents Vitor Soares
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Vitor Soares @ 2020-02-27 11:31 UTC (permalink / raw)
  To: pgaj, bbrezillon, linux-i3c; +Cc: linux-kernel, Vitor Soares

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


_______________________________________________
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

* [PATCH v2 1/4] i3c: Fix MODALIAS uevents
  2020-02-27 11:31 [PATCH v2 0/4] i3c: Address i3c_device_id related issues Vitor Soares
@ 2020-02-27 11:31 ` Vitor Soares
  2020-02-27 11:31 ` [PATCH v2 2/4] i3c: Add modalias sysfs attribute Vitor Soares
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Vitor Soares @ 2020-02-27 11:31 UTC (permalink / raw)
  To: pgaj, bbrezillon, linux-i3c; +Cc: Boris Brezillon, linux-kernel, Vitor Soares

From: Boris Brezillon <boris.brezillon@collabora.com>

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

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Vitor Soares <vitor.soares@synopsys.com>
---
 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


_______________________________________________
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

* [PATCH v2 2/4] i3c: Add modalias sysfs attribute
  2020-02-27 11:31 [PATCH v2 0/4] i3c: Address i3c_device_id related issues Vitor Soares
  2020-02-27 11:31 ` [PATCH v2 1/4] i3c: Fix MODALIAS uevents Vitor Soares
@ 2020-02-27 11:31 ` Vitor Soares
  2020-02-27 14:41   ` Boris Brezillon
  2020-02-27 11:31 ` [PATCH v2 3/4] i3c: Generate aliases for i3c modules Vitor Soares
  2020-02-27 11:31 ` [PATCH v2 4/4] i3c: Simplify i3c_device_match_id() Vitor Soares
  3 siblings, 1 reply; 6+ messages in thread
From: Vitor Soares @ 2020-02-27 11:31 UTC (permalink / raw)
  To: pgaj, bbrezillon, linux-i3c; +Cc: Boris Brezillon, linux-kernel, Vitor Soares

Create modalias sysfs attribute for modalias devices.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Vitor Soares <vitor.soares@synopsys.com>
---
 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


_______________________________________________
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

* [PATCH v2 3/4] i3c: Generate aliases for i3c modules
  2020-02-27 11:31 [PATCH v2 0/4] i3c: Address i3c_device_id related issues Vitor Soares
  2020-02-27 11:31 ` [PATCH v2 1/4] i3c: Fix MODALIAS uevents Vitor Soares
  2020-02-27 11:31 ` [PATCH v2 2/4] i3c: Add modalias sysfs attribute Vitor Soares
@ 2020-02-27 11:31 ` Vitor Soares
  2020-02-27 11:31 ` [PATCH v2 4/4] i3c: Simplify i3c_device_match_id() Vitor Soares
  3 siblings, 0 replies; 6+ messages in thread
From: Vitor Soares @ 2020-02-27 11:31 UTC (permalink / raw)
  To: pgaj, bbrezillon, linux-i3c; +Cc: Boris Brezillon, linux-kernel, Vitor Soares

From: Boris Brezillon <boris.brezillon@collabora.com>

This part was missing, thus preventing user space from loading modules
automatically when MODALIAS uevents are received.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Vitor Soares <vitor.soares@synopsys.com>
---
 scripts/mod/devicetable-offsets.c |  7 +++++++
 scripts/mod/file2alias.c          | 19 +++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/scripts/mod/devicetable-offsets.c b/scripts/mod/devicetable-offsets.c
index 054405b..d3c237b 100644
--- a/scripts/mod/devicetable-offsets.c
+++ b/scripts/mod/devicetable-offsets.c
@@ -145,6 +145,13 @@ int main(void)
 	DEVID(i2c_device_id);
 	DEVID_FIELD(i2c_device_id, name);
 
+	DEVID(i3c_device_id);
+	DEVID_FIELD(i3c_device_id, match_flags);
+	DEVID_FIELD(i3c_device_id, dcr);
+	DEVID_FIELD(i3c_device_id, manuf_id);
+	DEVID_FIELD(i3c_device_id, part_id);
+	DEVID_FIELD(i3c_device_id, extra_info);
+
 	DEVID(spi_device_id);
 	DEVID_FIELD(spi_device_id, name);
 
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index c91eba7..f81cbe0 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -919,6 +919,24 @@ static int do_i2c_entry(const char *filename, void *symval,
 	return 1;
 }
 
+static int do_i3c_entry(const char *filename, void *symval,
+			char *alias)
+{
+	DEF_FIELD(symval, i3c_device_id, match_flags);
+	DEF_FIELD(symval, i3c_device_id, dcr);
+	DEF_FIELD(symval, i3c_device_id, manuf_id);
+	DEF_FIELD(symval, i3c_device_id, part_id);
+	DEF_FIELD(symval, i3c_device_id, extra_info);
+
+	strcpy(alias, "i3c:");
+	ADD(alias, "dcr", match_flags & I3C_MATCH_DCR, dcr);
+	ADD(alias, "manuf", match_flags & I3C_MATCH_MANUF, manuf_id);
+	ADD(alias, "part", match_flags & I3C_MATCH_PART, part_id);
+	ADD(alias, "ext", match_flags & I3C_MATCH_EXTRA_INFO, extra_info);
+
+	return 1;
+}
+
 /* Looks like: spi:S */
 static int do_spi_entry(const char *filename, void *symval,
 			char *alias)
@@ -1386,6 +1404,7 @@ static const struct devtable devtable[] = {
 	{"vmbus", SIZE_hv_vmbus_device_id, do_vmbus_entry},
 	{"rpmsg", SIZE_rpmsg_device_id, do_rpmsg_entry},
 	{"i2c", SIZE_i2c_device_id, do_i2c_entry},
+	{"i3c", SIZE_i3c_device_id, do_i3c_entry},
 	{"spi", SIZE_spi_device_id, do_spi_entry},
 	{"dmi", SIZE_dmi_system_id, do_dmi_entry},
 	{"platform", SIZE_platform_device_id, do_platform_entry},
-- 
2.7.4


_______________________________________________
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

* [PATCH v2 4/4] i3c: Simplify i3c_device_match_id()
  2020-02-27 11:31 [PATCH v2 0/4] i3c: Address i3c_device_id related issues Vitor Soares
                   ` (2 preceding siblings ...)
  2020-02-27 11:31 ` [PATCH v2 3/4] i3c: Generate aliases for i3c modules Vitor Soares
@ 2020-02-27 11:31 ` Vitor Soares
  3 siblings, 0 replies; 6+ messages in thread
From: Vitor Soares @ 2020-02-27 11:31 UTC (permalink / raw)
  To: pgaj, bbrezillon, linux-i3c; +Cc: Boris Brezillon, linux-kernel, Vitor Soares

From: Boris Brezillon <boris.brezillon@collabora.com>

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

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Vitor Soares <vitor.soares@synopsys.com>
---
 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


_______________________________________________
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

* Re: [PATCH v2 2/4] i3c: Add modalias sysfs attribute
  2020-02-27 11:31 ` [PATCH v2 2/4] i3c: Add modalias sysfs attribute Vitor Soares
@ 2020-02-27 14:41   ` Boris Brezillon
  0 siblings, 0 replies; 6+ messages in thread
From: Boris Brezillon @ 2020-02-27 14:41 UTC (permalink / raw)
  To: Vitor Soares; +Cc: linux-kernel, pgaj, linux-i3c, bbrezillon

On Thu, 27 Feb 2020 12:31:07 +0100
Vitor Soares <Vitor.Soares@synopsys.com> 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 <boris.brezillon@collabora.com>
> Signed-off-by: Vitor Soares <vitor.soares@synopsys.com>
> ---
>  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);


_______________________________________________
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

end of thread, other threads:[~2020-02-27 14:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-27 11:31 [PATCH v2 0/4] i3c: Address i3c_device_id related issues Vitor Soares
2020-02-27 11:31 ` [PATCH v2 1/4] i3c: Fix MODALIAS uevents Vitor Soares
2020-02-27 11:31 ` [PATCH v2 2/4] i3c: Add modalias sysfs attribute Vitor Soares
2020-02-27 14:41   ` Boris Brezillon
2020-02-27 11:31 ` [PATCH v2 3/4] i3c: Generate aliases for i3c modules Vitor Soares
2020-02-27 11:31 ` [PATCH v2 4/4] i3c: Simplify i3c_device_match_id() Vitor Soares

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