diff mbox series

[v2,2/4] i3c: Add modalias sysfs attribute

Message ID a90f64f830128cd12762153de7828b775574c156.1582796652.git.vitor.soares@synopsys.com (mailing list archive)
State Mainlined
Commit 7ec0ddb007cf2bdc4531b5100f35c084028d4587
Headers show
Series i3c: Address i3c_device_id related issues | expand

Commit Message

Vitor Soares Feb. 27, 2020, 11:31 a.m. UTC
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(+)

Comments

Boris Brezillon Feb. 27, 2020, 2:41 p.m. UTC | #1
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);
diff mbox series

Patch

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