mirror of
https://github.com/torvalds/linux.git
synced 2024-12-20 10:01:56 +00:00
media: vimc: embed the pads of entities in the entities' structs
since the pads array is of known small size, there is no reason to allocate it separately. Instead, it is embedded in the entity struct. This also conforms to the media controller doc: 'Most drivers will embed the pads array in a driver-specific structure, avoiding dynamic allocation.' Signed-off-by: Dafna Hirschfeld <dafna.hirschfeld@collabora.com> [hverkuil-cisco@xs4all.nl: remove unused vimc_pads_init()] Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
This commit is contained in:
parent
ad1cec89db
commit
23df45d038
@ -30,6 +30,7 @@ struct vimc_cap_device {
|
|||||||
struct mutex lock;
|
struct mutex lock;
|
||||||
u32 sequence;
|
u32 sequence;
|
||||||
struct vimc_stream stream;
|
struct vimc_stream stream;
|
||||||
|
struct media_pad pad;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct v4l2_pix_format fmt_default = {
|
static const struct v4l2_pix_format fmt_default = {
|
||||||
@ -331,7 +332,6 @@ static void vimc_cap_release(struct video_device *vdev)
|
|||||||
container_of(vdev, struct vimc_cap_device, vdev);
|
container_of(vdev, struct vimc_cap_device, vdev);
|
||||||
|
|
||||||
media_entity_cleanup(vcap->ved.ent);
|
media_entity_cleanup(vcap->ved.ent);
|
||||||
vimc_pads_cleanup(vcap->ved.pads);
|
|
||||||
kfree(vcap);
|
kfree(vcap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -398,21 +398,14 @@ struct vimc_ent_device *vimc_cap_add(struct vimc_device *vimc,
|
|||||||
if (!vcap)
|
if (!vcap)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* Allocate the pads */
|
|
||||||
vcap->ved.pads =
|
|
||||||
vimc_pads_init(1, (const unsigned long[1]) {MEDIA_PAD_FL_SINK});
|
|
||||||
if (IS_ERR(vcap->ved.pads)) {
|
|
||||||
ret = PTR_ERR(vcap->ved.pads);
|
|
||||||
goto err_free_vcap;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Initialize the media entity */
|
/* Initialize the media entity */
|
||||||
vcap->vdev.entity.name = vcfg_name;
|
vcap->vdev.entity.name = vcfg_name;
|
||||||
vcap->vdev.entity.function = MEDIA_ENT_F_IO_V4L;
|
vcap->vdev.entity.function = MEDIA_ENT_F_IO_V4L;
|
||||||
|
vcap->pad.flags = MEDIA_PAD_FL_SINK;
|
||||||
ret = media_entity_pads_init(&vcap->vdev.entity,
|
ret = media_entity_pads_init(&vcap->vdev.entity,
|
||||||
1, vcap->ved.pads);
|
1, &vcap->pad);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err_clean_pads;
|
goto err_free_vcap;
|
||||||
|
|
||||||
/* Initialize the lock */
|
/* Initialize the lock */
|
||||||
mutex_init(&vcap->lock);
|
mutex_init(&vcap->lock);
|
||||||
@ -481,8 +474,6 @@ err_release_queue:
|
|||||||
vb2_queue_release(q);
|
vb2_queue_release(q);
|
||||||
err_clean_m_ent:
|
err_clean_m_ent:
|
||||||
media_entity_cleanup(&vcap->vdev.entity);
|
media_entity_cleanup(&vcap->vdev.entity);
|
||||||
err_clean_pads:
|
|
||||||
vimc_pads_cleanup(vcap->ved.pads);
|
|
||||||
err_free_vcap:
|
err_free_vcap:
|
||||||
kfree(vcap);
|
kfree(vcap);
|
||||||
|
|
||||||
|
@ -194,26 +194,6 @@ const struct vimc_pix_map *vimc_pix_map_by_pixelformat(u32 pixelformat)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Helper function to allocate and initialize pads */
|
|
||||||
struct media_pad *vimc_pads_init(u16 num_pads, const unsigned long *pads_flag)
|
|
||||||
{
|
|
||||||
struct media_pad *pads;
|
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
/* Allocate memory for the pads */
|
|
||||||
pads = kcalloc(num_pads, sizeof(*pads), GFP_KERNEL);
|
|
||||||
if (!pads)
|
|
||||||
return ERR_PTR(-ENOMEM);
|
|
||||||
|
|
||||||
/* Initialize the pads */
|
|
||||||
for (i = 0; i < num_pads; i++) {
|
|
||||||
pads[i].index = i;
|
|
||||||
pads[i].flags = pads_flag[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
return pads;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int vimc_get_mbus_format(struct media_pad *pad,
|
static int vimc_get_mbus_format(struct media_pad *pad,
|
||||||
struct v4l2_subdev_format *fmt)
|
struct v4l2_subdev_format *fmt)
|
||||||
{
|
{
|
||||||
@ -335,17 +315,12 @@ int vimc_ent_sd_register(struct vimc_ent_device *ved,
|
|||||||
const char *const name,
|
const char *const name,
|
||||||
u32 function,
|
u32 function,
|
||||||
u16 num_pads,
|
u16 num_pads,
|
||||||
const unsigned long *pads_flag,
|
struct media_pad *pads,
|
||||||
const struct v4l2_subdev_internal_ops *sd_int_ops,
|
const struct v4l2_subdev_internal_ops *sd_int_ops,
|
||||||
const struct v4l2_subdev_ops *sd_ops)
|
const struct v4l2_subdev_ops *sd_ops)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Allocate the pads. Should be released from the sd_int_op release */
|
|
||||||
ved->pads = vimc_pads_init(num_pads, pads_flag);
|
|
||||||
if (IS_ERR(ved->pads))
|
|
||||||
return PTR_ERR(ved->pads);
|
|
||||||
|
|
||||||
/* Fill the vimc_ent_device struct */
|
/* Fill the vimc_ent_device struct */
|
||||||
ved->ent = &sd->entity;
|
ved->ent = &sd->entity;
|
||||||
|
|
||||||
@ -364,9 +339,9 @@ int vimc_ent_sd_register(struct vimc_ent_device *ved,
|
|||||||
sd->flags |= V4L2_SUBDEV_FL_HAS_EVENTS;
|
sd->flags |= V4L2_SUBDEV_FL_HAS_EVENTS;
|
||||||
|
|
||||||
/* Initialize the media entity */
|
/* Initialize the media entity */
|
||||||
ret = media_entity_pads_init(&sd->entity, num_pads, ved->pads);
|
ret = media_entity_pads_init(&sd->entity, num_pads, pads);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err_clean_pads;
|
return ret;
|
||||||
|
|
||||||
/* Register the subdev with the v4l2 and the media framework */
|
/* Register the subdev with the v4l2 and the media framework */
|
||||||
ret = v4l2_device_register_subdev(v4l2_dev, sd);
|
ret = v4l2_device_register_subdev(v4l2_dev, sd);
|
||||||
@ -381,7 +356,5 @@ int vimc_ent_sd_register(struct vimc_ent_device *ved,
|
|||||||
|
|
||||||
err_clean_m_ent:
|
err_clean_m_ent:
|
||||||
media_entity_cleanup(&sd->entity);
|
media_entity_cleanup(&sd->entity);
|
||||||
err_clean_pads:
|
|
||||||
vimc_pads_cleanup(ved->pads);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -75,10 +75,10 @@ struct vimc_pix_map {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* struct vimc_ent_device - core struct that represents a node in the topology
|
* struct vimc_ent_device - core struct that represents an entity in the
|
||||||
|
* topology
|
||||||
*
|
*
|
||||||
* @ent: the pointer to struct media_entity for the node
|
* @ent: the pointer to struct media_entity for the node
|
||||||
* @pads: the list of pads of the node
|
|
||||||
* @process_frame: callback send a frame to that node
|
* @process_frame: callback send a frame to that node
|
||||||
* @vdev_get_format: callback that returns the current format a pad, used
|
* @vdev_get_format: callback that returns the current format a pad, used
|
||||||
* only when is_media_entity_v4l2_video_device(ent) returns
|
* only when is_media_entity_v4l2_video_device(ent) returns
|
||||||
@ -94,7 +94,6 @@ struct vimc_pix_map {
|
|||||||
*/
|
*/
|
||||||
struct vimc_ent_device {
|
struct vimc_ent_device {
|
||||||
struct media_entity *ent;
|
struct media_entity *ent;
|
||||||
struct media_pad *pads;
|
|
||||||
void * (*process_frame)(struct vimc_ent_device *ved,
|
void * (*process_frame)(struct vimc_ent_device *ved,
|
||||||
const void *frame);
|
const void *frame);
|
||||||
void (*vdev_get_format)(struct vimc_ent_device *ved,
|
void (*vdev_get_format)(struct vimc_ent_device *ved,
|
||||||
@ -154,29 +153,6 @@ struct vimc_ent_device *vimc_sen_add(struct vimc_device *vimc,
|
|||||||
const char *vcfg_name);
|
const char *vcfg_name);
|
||||||
void vimc_sen_rm(struct vimc_device *vimc, struct vimc_ent_device *ved);
|
void vimc_sen_rm(struct vimc_device *vimc, struct vimc_ent_device *ved);
|
||||||
|
|
||||||
/**
|
|
||||||
* vimc_pads_init - initialize pads
|
|
||||||
*
|
|
||||||
* @num_pads: number of pads to initialize
|
|
||||||
* @pads_flags: flags to use in each pad
|
|
||||||
*
|
|
||||||
* Helper functions to allocate/initialize pads
|
|
||||||
*/
|
|
||||||
struct media_pad *vimc_pads_init(u16 num_pads,
|
|
||||||
const unsigned long *pads_flag);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* vimc_pads_cleanup - free pads
|
|
||||||
*
|
|
||||||
* @pads: pointer to the pads
|
|
||||||
*
|
|
||||||
* Helper function to free the pads initialized with vimc_pads_init
|
|
||||||
*/
|
|
||||||
static inline void vimc_pads_cleanup(struct media_pad *pads)
|
|
||||||
{
|
|
||||||
kfree(pads);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* vimc_pix_map_by_index - get vimc_pix_map struct by its index
|
* vimc_pix_map_by_index - get vimc_pix_map struct by its index
|
||||||
*
|
*
|
||||||
@ -208,7 +184,8 @@ const struct vimc_pix_map *vimc_pix_map_by_pixelformat(u32 pixelformat);
|
|||||||
* unique.
|
* unique.
|
||||||
* @function: media entity function defined by MEDIA_ENT_F_* macros
|
* @function: media entity function defined by MEDIA_ENT_F_* macros
|
||||||
* @num_pads: number of pads to initialize
|
* @num_pads: number of pads to initialize
|
||||||
* @pads_flag: flags to use in each pad
|
* @pads: the array of pads of the entity, the caller should set the
|
||||||
|
flags of the pads
|
||||||
* @sd_int_ops: pointer to &struct v4l2_subdev_internal_ops
|
* @sd_int_ops: pointer to &struct v4l2_subdev_internal_ops
|
||||||
* @sd_ops: pointer to &struct v4l2_subdev_ops.
|
* @sd_ops: pointer to &struct v4l2_subdev_ops.
|
||||||
*
|
*
|
||||||
@ -221,7 +198,7 @@ int vimc_ent_sd_register(struct vimc_ent_device *ved,
|
|||||||
const char *const name,
|
const char *const name,
|
||||||
u32 function,
|
u32 function,
|
||||||
u16 num_pads,
|
u16 num_pads,
|
||||||
const unsigned long *pads_flag,
|
struct media_pad *pads,
|
||||||
const struct v4l2_subdev_internal_ops *sd_int_ops,
|
const struct v4l2_subdev_internal_ops *sd_int_ops,
|
||||||
const struct v4l2_subdev_ops *sd_ops);
|
const struct v4l2_subdev_ops *sd_ops);
|
||||||
|
|
||||||
|
@ -44,6 +44,7 @@ struct vimc_deb_device {
|
|||||||
u8 *src_frame;
|
u8 *src_frame;
|
||||||
const struct vimc_deb_pix_map *sink_pix_map;
|
const struct vimc_deb_pix_map *sink_pix_map;
|
||||||
unsigned int sink_bpp;
|
unsigned int sink_bpp;
|
||||||
|
struct media_pad pads[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct v4l2_mbus_framefmt sink_fmt_default = {
|
static const struct v4l2_mbus_framefmt sink_fmt_default = {
|
||||||
@ -478,7 +479,6 @@ static void vimc_deb_release(struct v4l2_subdev *sd)
|
|||||||
container_of(sd, struct vimc_deb_device, sd);
|
container_of(sd, struct vimc_deb_device, sd);
|
||||||
|
|
||||||
media_entity_cleanup(vdeb->ved.ent);
|
media_entity_cleanup(vdeb->ved.ent);
|
||||||
vimc_pads_cleanup(vdeb->ved.pads);
|
|
||||||
kfree(vdeb);
|
kfree(vdeb);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -507,11 +507,13 @@ struct vimc_ent_device *vimc_deb_add(struct vimc_device *vimc,
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* Initialize ved and sd */
|
/* Initialize ved and sd */
|
||||||
|
vdeb->pads[0].flags = MEDIA_PAD_FL_SINK;
|
||||||
|
vdeb->pads[1].flags = MEDIA_PAD_FL_SOURCE;
|
||||||
|
|
||||||
ret = vimc_ent_sd_register(&vdeb->ved, &vdeb->sd, v4l2_dev,
|
ret = vimc_ent_sd_register(&vdeb->ved, &vdeb->sd, v4l2_dev,
|
||||||
vcfg_name,
|
vcfg_name,
|
||||||
MEDIA_ENT_F_PROC_VIDEO_PIXEL_ENC_CONV, 2,
|
MEDIA_ENT_F_PROC_VIDEO_PIXEL_ENC_CONV, 2,
|
||||||
(const unsigned long[2]) {MEDIA_PAD_FL_SINK,
|
vdeb->pads,
|
||||||
MEDIA_PAD_FL_SOURCE},
|
|
||||||
&vimc_deb_int_ops, &vimc_deb_ops);
|
&vimc_deb_int_ops, &vimc_deb_ops);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
kfree(vdeb);
|
kfree(vdeb);
|
||||||
|
@ -30,6 +30,7 @@ struct vimc_sca_device {
|
|||||||
u8 *src_frame;
|
u8 *src_frame;
|
||||||
unsigned int src_line_size;
|
unsigned int src_line_size;
|
||||||
unsigned int bpp;
|
unsigned int bpp;
|
||||||
|
struct media_pad pads[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct v4l2_mbus_framefmt sink_fmt_default = {
|
static const struct v4l2_mbus_framefmt sink_fmt_default = {
|
||||||
@ -337,7 +338,6 @@ static void vimc_sca_release(struct v4l2_subdev *sd)
|
|||||||
container_of(sd, struct vimc_sca_device, sd);
|
container_of(sd, struct vimc_sca_device, sd);
|
||||||
|
|
||||||
media_entity_cleanup(vsca->ved.ent);
|
media_entity_cleanup(vsca->ved.ent);
|
||||||
vimc_pads_cleanup(vsca->ved.pads);
|
|
||||||
kfree(vsca);
|
kfree(vsca);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -366,11 +366,13 @@ struct vimc_ent_device *vimc_sca_add(struct vimc_device *vimc,
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* Initialize ved and sd */
|
/* Initialize ved and sd */
|
||||||
|
vsca->pads[0].flags = MEDIA_PAD_FL_SINK;
|
||||||
|
vsca->pads[1].flags = MEDIA_PAD_FL_SOURCE;
|
||||||
|
|
||||||
ret = vimc_ent_sd_register(&vsca->ved, &vsca->sd, v4l2_dev,
|
ret = vimc_ent_sd_register(&vsca->ved, &vsca->sd, v4l2_dev,
|
||||||
vcfg_name,
|
vcfg_name,
|
||||||
MEDIA_ENT_F_PROC_VIDEO_SCALER, 2,
|
MEDIA_ENT_F_PROC_VIDEO_SCALER, 2,
|
||||||
(const unsigned long[2]) {MEDIA_PAD_FL_SINK,
|
vsca->pads,
|
||||||
MEDIA_PAD_FL_SOURCE},
|
|
||||||
&vimc_sca_int_ops, &vimc_sca_ops);
|
&vimc_sca_int_ops, &vimc_sca_ops);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
kfree(vsca);
|
kfree(vsca);
|
||||||
|
@ -24,6 +24,7 @@ struct vimc_sen_device {
|
|||||||
/* The active format */
|
/* The active format */
|
||||||
struct v4l2_mbus_framefmt mbus_format;
|
struct v4l2_mbus_framefmt mbus_format;
|
||||||
struct v4l2_ctrl_handler hdl;
|
struct v4l2_ctrl_handler hdl;
|
||||||
|
struct media_pad pad;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct v4l2_mbus_framefmt fmt_default = {
|
static const struct v4l2_mbus_framefmt fmt_default = {
|
||||||
@ -292,7 +293,6 @@ static void vimc_sen_release(struct v4l2_subdev *sd)
|
|||||||
v4l2_ctrl_handler_free(&vsen->hdl);
|
v4l2_ctrl_handler_free(&vsen->hdl);
|
||||||
tpg_free(&vsen->tpg);
|
tpg_free(&vsen->tpg);
|
||||||
media_entity_cleanup(vsen->ved.ent);
|
media_entity_cleanup(vsen->ved.ent);
|
||||||
vimc_pads_cleanup(vsen->ved.pads);
|
|
||||||
kfree(vsen);
|
kfree(vsen);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -367,10 +367,10 @@ struct vimc_ent_device *vimc_sen_add(struct vimc_device *vimc,
|
|||||||
goto err_free_hdl;
|
goto err_free_hdl;
|
||||||
|
|
||||||
/* Initialize ved and sd */
|
/* Initialize ved and sd */
|
||||||
|
vsen->pad.flags = MEDIA_PAD_FL_SOURCE;
|
||||||
ret = vimc_ent_sd_register(&vsen->ved, &vsen->sd, v4l2_dev,
|
ret = vimc_ent_sd_register(&vsen->ved, &vsen->sd, v4l2_dev,
|
||||||
vcfg_name,
|
vcfg_name,
|
||||||
MEDIA_ENT_F_CAM_SENSOR, 1,
|
MEDIA_ENT_F_CAM_SENSOR, 1, &vsen->pad,
|
||||||
(const unsigned long[1]) {MEDIA_PAD_FL_SOURCE},
|
|
||||||
&vimc_sen_int_ops, &vimc_sen_ops);
|
&vimc_sen_int_ops, &vimc_sen_ops);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err_free_tpg;
|
goto err_free_tpg;
|
||||||
|
Loading…
Reference in New Issue
Block a user