1
0
Fork 0

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>
hifive-unleashed-5.1
Sakari Ailus 2018-08-29 05:52:46 -04:00 committed by Mauro Carvalho Chehab
parent e6002df8f3
commit 0658293012
2 changed files with 26 additions and 4 deletions

View File

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

View File

@ -154,6 +154,18 @@ struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev,
struct i2c_adapter *adapter, struct i2c_board_info *info,
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.