Uniformly assign sub-device names
cover Uniformly assign sub-device names
Hi all,
Recently we noticed the sub-device drivers used a few different naming schemes, as well as a few more different implementations of that naming. This set adds a framework function to call to name sub-devices for cases where a sub-device driver exposes more than one sub-device.
This set brings no functional change.
Sakari Ailus (3):
v4l: subdev: Add a function to set an I²C sub-device's name
smiapp: Use v4l2_i2c_subdev_set_name
v4l: sr030pc30: Remove redundant setting of sub-device name
drivers/media/i2c/smiapp/smiapp-core.c | 10 ++++------ drivers/media/i2c/sr030pc30.c | 1 - drivers/media/v4l2-core/v4l2-common.c | 18 ++++++++++++++---- include/media/v4l2-common.h | 12 ++++++++++++ 4 files changed, 30 insertions(+), 11 deletions(-)
Signature · 1 line
2.11.0
PATCH 1/3 v4l: subdev: Add a function to set an I²C sub-device's name
v4l2_i2c_subdev_set_name() can be used to assign a name to a sub-device. This way uniform names can be formed easily without having to resort to things such as snprintf in drivers.
--- drivers/media/v4l2-core/v4l2-common.c | 18 ++++++++++++++---- include/media/v4l2-common.h | 12 ++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-)
drivers/media/v4l2-core/v4l2-common.c +14 -4
@@ -109,6 +109,19 @@ EXPORT_SYMBOL(v4l2_ctrl_query_fill);#if IS_ENABLED (CONFIG_I2C ) +void v4l2_i2c_subdev_set_name (struct v4l2_subdev *sd,struct i2c_client *client, +const char *devname,const char *postfix) +{ +if (!devname) + devname = client->dev.driver->name; +if (!postfix) + postfix ="" ; + +snprintf (sd->name,sizeof (sd->name),"%s%s %d-%04x" , devname, postfix, +i2c_adapter_id (client->adapter), client->addr); +} +EXPORT_SYMBOL_GPL (v4l2_i2c_subdev_set_name); +void v4l2_i2c_subdev_init (struct v4l2_subdev *sd,struct i2c_client *client,const struct v4l2_subdev_ops *ops) {
@@ -120,10 +133,7 @@ void v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client,/* i2c_client and v4l2_subdev point to one another */ v4l2_set_subdevdata (sd, client);i2c_set_clientdata (client, sd); -/* initialize name */ -snprintf (sd->name,sizeof (sd->name),"%s %d-%04x" , - client->dev.driver->name,i2c_adapter_id (client->adapter), - client->addr); +v4l2_i2c_subdev_set_name (sd, client,NULL ,NULL ); }EXPORT_SYMBOL_GPL (v4l2_i2c_subdev_init);
include/media/v4l2-common.h +12 -0
@@ -155,6 +155,18 @@ struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev, const unsigned short *probe_addrs);/** +* v4l2_i2c_subdev_set_name - Set name for an I²C sub-device +* +* @sd: pointer to &struct v4l2_subdev +* @client: pointer to struct i2c_client +* @devname: the name of the device; if NULL, the I²C device's name will be used +* @postfix: sub-device specific string to put right after the I²C device name; +* may be NULL +*/ +void v4l2_i2c_subdev_set_name (struct v4l2_subdev *sd,struct i2c_client *client, +const char *devname,const char *postfix); + +/** * v4l2_i2c_subdev_init - Initializes a &struct v4l2_subdev with data from * an i2c_client struct. *
Signature · 1 line
2.11.0
Re: [PATCH 1/3] v4l: subdev: Add a function to set an I²C sub-device's name
Quoted 5 lines · Sakari Ailus
v4l2_i2c_subdev_set_name()can be used to assign a name to a sub-device. This way uniform names can be formed easily without having to resort to things such as snprintf in drivers.Signed-off-by Sakari Ailus <[email protected]>
Thanks!
Hans
Quoted 65 lines
--- drivers/media/v4l2-core/v4l2-common.c | 18 ++++++++++++++---- include/media/v4l2-common.h | 12 ++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-)drivers/media/v4l2-core/v4l2-common.c +14
-4@@ -109,6 +109,19 @@ EXPORT_SYMBOL(v4l2_ctrl_query_fill);#if IS_ENABLED (CONFIG_I2C ) +void v4l2_i2c_subdev_set_name (struct v4l2_subdev *sd,struct i2c_client *client, +const char *devname,const char *postfix) +{ +if (!devname) + devname = client->dev.driver->name; +if (!postfix) + postfix ="" ; + +snprintf (sd->name,sizeof (sd->name),"%s%s %d-%04x" , devname, postfix, +i2c_adapter_id (client->adapter), client->addr); +} +EXPORT_SYMBOL_GPL (v4l2_i2c_subdev_set_name); +void v4l2_i2c_subdev_init (struct v4l2_subdev *sd,struct i2c_client *client,const struct v4l2_subdev_ops *ops) {@@ -120,10 +133,7 @@ void v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client,/* i2c_client and v4l2_subdev point to one another */ v4l2_set_subdevdata (sd, client);i2c_set_clientdata (client, sd); -/* initialize name */ -snprintf (sd->name,sizeof (sd->name),"%s %d-%04x" , - client->dev.driver->name,i2c_adapter_id (client->adapter), - client->addr); +v4l2_i2c_subdev_set_name (sd, client,NULL ,NULL ); }EXPORT_SYMBOL_GPL (v4l2_i2c_subdev_init);include/media/v4l2-common.h +12
-0@@ -155,6 +155,18 @@ struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev, const unsigned short *probe_addrs);/** +* v4l2_i2c_subdev_set_name - Set name for an I²C sub-device +* +* @sd: pointer to &struct v4l2_subdev +* @client: pointer to struct i2c_client +* @devname: the name of the device; if NULL, the I²C device's name will be used +* @postfix: sub-device specific string to put right after the I²C device name; +* may be NULL +*/ +void v4l2_i2c_subdev_set_name (struct v4l2_subdev *sd,struct i2c_client *client, +const char *devname,const char *postfix); + +/** * v4l2_i2c_subdev_init - Initializes a &struct v4l2_subdev with data from * an i2c_client struct. *
PATCH 2/3 smiapp: Use v4l2_i2c_subdev_set_name
In reply to Sakari AilusUse v4l2_i2c_subdev_set_name() to set the name of the smiapp driver's sub-devices. There is no functional change.
--- drivers/media/i2c/smiapp/smiapp-core.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/media/i2c/smiapp/smiapp-core.c +4 -6
@@ -2617,9 +2617,7 @@ static void smiapp_create_subdev(struct smiapp_sensor *sensor, ssd->npads = num_pads; ssd->source_pad = num_pads -1 ; -snprintf (ssd->sd.name, -sizeof (ssd->sd.name),"%s %s %d-%4.4x" , sensor->minfo.name, - name,i2c_adapter_id (client->adapter), client->addr); +v4l2_i2c_subdev_set_name (&ssd->sd, client, sensor->minfo.name, name);smiapp_get_native_size (ssd, &ssd->sink_fmt);
@@ -3064,9 +3062,9 @@ static int smiapp_probe(struct i2c_client *client,if (sensor->minfo.smiapp_profile ==SMIAPP_PROFILE_0 ) sensor->pll.flags |=SMIAPP_PLL_FLAG_NO_OP_CLOCKS ; -smiapp_create_subdev (sensor, sensor->scaler,"scaler" ,2 ); -smiapp_create_subdev (sensor, sensor->binner,"binner" ,2 ); -smiapp_create_subdev (sensor, sensor->pixel_array,"pixel_array" ,1 ); +smiapp_create_subdev (sensor, sensor->scaler," scaler" ,2 ); +smiapp_create_subdev (sensor, sensor->binner," binner" ,2 ); +smiapp_create_subdev (sensor, sensor->pixel_array," pixel_array" ,1 );dev_dbg (&client->dev,"profile %d\n" , sensor->minfo.smiapp_profile);
Signature · 1 line
2.11.0
Re: [PATCH 2/3] smiapp: Use v4l2_i2c_subdev_set_name
Quoted 4 lines · Sakari Ailus
Use
v4l2_i2c_subdev_set_name()to set the name of the smiapp driver's sub-devices. There is no functional change.Signed-off-by Sakari Ailus <[email protected]>
Thanks!
Hans
Quoted 33 lines
--- drivers/media/i2c/smiapp/smiapp-core.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)drivers/media/i2c/smiapp/smiapp-core.c +4
-6@@ -2617,9 +2617,7 @@ static void smiapp_create_subdev(struct smiapp_sensor *sensor, ssd->npads = num_pads; ssd->source_pad = num_pads -1 ; -snprintf (ssd->sd.name, -sizeof (ssd->sd.name),"%s %s %d-%4.4x" , sensor->minfo.name, - name,i2c_adapter_id (client->adapter), client->addr); +v4l2_i2c_subdev_set_name (&ssd->sd, client, sensor->minfo.name, name);smiapp_get_native_size (ssd, &ssd->sink_fmt);@@ -3064,9 +3062,9 @@ static int smiapp_probe(struct i2c_client *client,if (sensor->minfo.smiapp_profile ==SMIAPP_PROFILE_0 ) sensor->pll.flags |=SMIAPP_PLL_FLAG_NO_OP_CLOCKS ; -smiapp_create_subdev (sensor, sensor->scaler,"scaler" ,2 ); -smiapp_create_subdev (sensor, sensor->binner,"binner" ,2 ); -smiapp_create_subdev (sensor, sensor->pixel_array,"pixel_array" ,1 ); +smiapp_create_subdev (sensor, sensor->scaler," scaler" ,2 ); +smiapp_create_subdev (sensor, sensor->binner," binner" ,2 ); +smiapp_create_subdev (sensor, sensor->pixel_array," pixel_array" ,1 );dev_dbg (&client->dev,"profile %d\n" , sensor->minfo.smiapp_profile);
PATCH 3/3 sr030pc30: Remove redundant setting of sub-device name
In reply to Sakari AilusThe sub-device name is set right after in v4l2_i2c_subdev_init(). Remove the redundant strcpy() call.
--- drivers/media/i2c/sr030pc30.c | 1 - 1 file changed, 1 deletion(-)
drivers/media/i2c/sr030pc30.c +0 -1
@@ -703,7 +703,6 @@ static int sr030pc30_probe(struct i2c_client *client,return -ENOMEM ; sd = &info->sd; -strcpy (sd->name,MODULE_NAME ); info->pdata = client->dev.platform_data;v4l2_i2c_subdev_init (sd, client, &sr030pc30_ops);
Signature · 1 line
2.11.0
Re: [PATCH 3/3] sr030pc30: Remove redundant setting of sub-device name
Quoted 4 lines · Sakari Ailus
The sub-device name is set right after in
v4l2_i2c_subdev_init(). Remove the redundantstrcpy()call.Signed-off-by Sakari Ailus <[email protected]>
Thanks!
Hans
Quoted 17 lines
--- drivers/media/i2c/sr030pc30.c | 1 - 1 file changed, 1 deletion(-)drivers/media/i2c/sr030pc30.c +0
-1@@ -703,7 +703,6 @@ static int sr030pc30_probe(struct i2c_client *client,return -ENOMEM ; sd = &info->sd; -strcpy (sd->name,MODULE_NAME ); info->pdata = client->dev.platform_data;v4l2_i2c_subdev_init (sd, client, &sr030pc30_ops);