summaryrefslogtreecommitdiffstats
path: root/drivers/media/v4l2-core/v4l2-common.c
diff options
context:
space:
mode:
authorSakari Ailus <sakari.ailus@linux.intel.com>2018-08-29 05:52:46 -0400
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>2018-09-17 15:17:22 -0400
commit0658293012af1e69d8bb8a25e71781470f9b2ac6 (patch)
tree69196e8b283dd4fbcb8ffc6df5f4bf4c4d6ba47e /drivers/media/v4l2-core/v4l2-common.c
parente6002df8f37fdeb1b00c65892e45dffbec8d39ed (diff)
downloadlinux-0658293012af1e69d8bb8a25e71781470f9b2ac6.tar.gz
linux-0658293012af1e69d8bb8a25e71781470f9b2ac6.tar.bz2
linux-0658293012af1e69d8bb8a25e71781470f9b2ac6.zip
media: 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. Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Acked-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Diffstat (limited to 'drivers/media/v4l2-core/v4l2-common.c')
-rw-r--r--drivers/media/v4l2-core/v4l2-common.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c
index 7c755952398f..50763fb42a1b 100644
--- a/drivers/media/v4l2-core/v4l2-common.c
+++ b/drivers/media/v4l2-core/v4l2-common.c
@@ -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);