Commit f69952a4 authored by Tomi Valkeinen's avatar Tomi Valkeinen Committed by Mauro Carvalho Chehab

media: subdev: add active state to struct v4l2_subdev

Add a new 'active_state' field to struct v4l2_subdev to which we can
store the active state of a subdev. This will place the subdev
configuration into a known place, allowing us to use the state directly
from the v4l2 framework, thus simplifying the drivers.

Also add functions v4l2_subdev_init_finalize() and
v4l2_subdev_cleanup(), which will allocate and free the active state.
The functions are named in a generic way so that they can be also used
for other subdev initialization work.
Signed-off-by: default avatarTomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Reviewed-by: default avatarJacopo Mondi <jacopo+renesas@jmondi.org>
Reviewed-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
parent 40aaab9d
......@@ -906,6 +906,27 @@ void __v4l2_subdev_state_free(struct v4l2_subdev_state *state)
}
EXPORT_SYMBOL_GPL(__v4l2_subdev_state_free);
int v4l2_subdev_init_finalize(struct v4l2_subdev *sd)
{
struct v4l2_subdev_state *state;
state = __v4l2_subdev_state_alloc(sd);
if (IS_ERR(state))
return PTR_ERR(state);
sd->active_state = state;
return 0;
}
EXPORT_SYMBOL_GPL(v4l2_subdev_init_finalize);
void v4l2_subdev_cleanup(struct v4l2_subdev *sd)
{
__v4l2_subdev_state_free(sd->active_state);
sd->active_state = NULL;
}
EXPORT_SYMBOL_GPL(v4l2_subdev_cleanup);
#endif /* CONFIG_MEDIA_CONTROLLER */
void v4l2_subdev_init(struct v4l2_subdev *sd, const struct v4l2_subdev_ops *ops)
......
......@@ -645,6 +645,9 @@ struct v4l2_subdev_ir_ops {
* This structure only needs to be passed to the pad op if the 'which' field
* of the main argument is set to %V4L2_SUBDEV_FORMAT_TRY. For
* %V4L2_SUBDEV_FORMAT_ACTIVE it is safe to pass %NULL.
*
* Note: This struct is also used in active state, and the 'try' prefix is
* historical and to be removed.
*/
struct v4l2_subdev_pad_config {
struct v4l2_mbus_framefmt try_fmt;
......@@ -885,6 +888,9 @@ struct v4l2_subdev_platform_data {
* @subdev_notifier: A sub-device notifier implicitly registered for the sub-
* device using v4l2_async_register_subdev_sensor().
* @pdata: common part of subdevice platform data
* @active_state: Active state for the subdev (NULL for subdevs tracking the
* state internally). Initialized by calling
* v4l2_subdev_init_finalize().
*
* Each instance of a subdev driver should create this struct, either
* stand-alone or embedded in a larger struct.
......@@ -916,6 +922,19 @@ struct v4l2_subdev {
struct v4l2_async_notifier *notifier;
struct v4l2_async_notifier *subdev_notifier;
struct v4l2_subdev_platform_data *pdata;
/*
* The fields below are private, and should only be accessed via
* appropriate functions.
*/
/*
* TODO: active_state should most likely be changed from a pointer to an
* embedded field. For the time being it's kept as a pointer to more
* easily catch uses of active_state in the cases where the driver
* doesn't support it.
*/
struct v4l2_subdev_state *active_state;
};
......@@ -1141,6 +1160,45 @@ struct v4l2_subdev_state *__v4l2_subdev_state_alloc(struct v4l2_subdev *sd);
*/
void __v4l2_subdev_state_free(struct v4l2_subdev_state *state);
/**
* v4l2_subdev_init_finalize() - Finalizes the initialization of the subdevice
* @sd: The subdev
*
* This function finalizes the initialization of the subdev, including
* allocation of the active state for the subdev.
*
* This function must be called by the subdev drivers that use the centralized
* active state, after the subdev struct has been initialized and
* media_entity_pads_init() has been called, but before registering the
* subdev.
*
* The user must call v4l2_subdev_cleanup() when the subdev is being removed.
*/
int v4l2_subdev_init_finalize(struct v4l2_subdev *sd);
/**
* v4l2_subdev_cleanup() - Releases the resources allocated by the subdevice
* @sd: The subdevice
*
* This function will release the resources allocated in
* v4l2_subdev_init_finalize.
*/
void v4l2_subdev_cleanup(struct v4l2_subdev *sd);
/**
* v4l2_subdev_get_active_state() - Returns the active subdev state for
* subdevice
* @sd: The subdevice
*
* Returns the active state for the subdevice, or NULL if the subdev does not
* support active state.
*/
static inline struct v4l2_subdev_state *
v4l2_subdev_get_active_state(struct v4l2_subdev *sd)
{
return sd->active_state;
}
#endif /* CONFIG_MEDIA_CONTROLLER */
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment