Message ID | 20240411124543.199-6-quic_grosikop@quicinc.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Move camss version related defs in to resources | expand |
On 11/04/2024 13:45, Gjorgji Rosikopulos wrote: > From: Radoslav Tsvetkov <quic_rtsvetko@quicinc.com> > > Move out the format related helper functions from vfe and video in a > separate file. The goal here is to create a format API. > > Signed-off-by: Radoslav Tsvetkov <quic_rtsvetko@quicinc.com> > Signed-off-by: Gjorgji Rosikopulos <quic_grosikop@quicinc.com> > --- Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> Tested-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> # sc8280xp/sm8250/sdm845/apq8016
On 4/11/24 15:45, Gjorgji Rosikopulos wrote: > From: Radoslav Tsvetkov <quic_rtsvetko@quicinc.com> > > Move out the format related helper functions from vfe and video in a > separate file. The goal here is to create a format API. > > Signed-off-by: Radoslav Tsvetkov <quic_rtsvetko@quicinc.com> > Signed-off-by: Gjorgji Rosikopulos <quic_grosikop@quicinc.com> > --- > drivers/media/platform/qcom/camss/Makefile | 1 + > .../media/platform/qcom/camss/camss-format.c | 98 +++++++++++++++++++ > .../media/platform/qcom/camss/camss-format.h | 5 + > drivers/media/platform/qcom/camss/camss-vfe.c | 86 +++++----------- > .../media/platform/qcom/camss/camss-video.c | 26 +---- > 5 files changed, 128 insertions(+), 88 deletions(-) > create mode 100644 drivers/media/platform/qcom/camss/camss-format.c > > diff --git a/drivers/media/platform/qcom/camss/Makefile b/drivers/media/platform/qcom/camss/Makefile > index 0d4389ab312d..e636968a1126 100644 > --- a/drivers/media/platform/qcom/camss/Makefile > +++ b/drivers/media/platform/qcom/camss/Makefile > @@ -19,5 +19,6 @@ qcom-camss-objs += \ > camss-vfe-gen1.o \ > camss-vfe.o \ > camss-video.o \ > + camss-format.o \ > > obj-$(CONFIG_VIDEO_QCOM_CAMSS) += qcom-camss.o > diff --git a/drivers/media/platform/qcom/camss/camss-format.c b/drivers/media/platform/qcom/camss/camss-format.c > new file mode 100644 > index 000000000000..6279cb099625 > --- /dev/null > +++ b/drivers/media/platform/qcom/camss/camss-format.c > @@ -0,0 +1,98 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* Copyright (c) 2023, The Linux Foundation. All rights reserved. > + * Copyright (c) 2023 Qualcomm Technologies, Inc. > + * > + * This program is free software; you can redistribute it and/or modify > + * it under the terms of the GNU General Public License version 2 and > + * only version 2 as published by the Free Software Foundation. > + * > + * This program is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + * GNU General Public License for more details. > + */ SPDX-License-Identifier is fully sufficient, the licence description shall be removed. > + > +#include <linux/bug.h> > +#include <linux/errno.h> > + > +#include "camss-format.h" > + > +/* > + * camss_format_get_bpp - Map media bus format to bits per pixel > + * @formats: supported media bus formats array > + * @nformats: size of @formats array > + * @code: media bus format code > + * > + * Return number of bits per pixel > + */ > +u8 camss_format_get_bpp(const struct camss_format_info *formats, unsigned int nformats, u32 code) > +{ > + unsigned int i; > + > + for (i = 0; i < nformats; i++) > + if (code == formats[i].code) > + return formats[i].mbus_bpp; > + > + WARN(1, "Unknown format\n"); > + > + return formats[0].mbus_bpp; > +} > + > +/* > + * camss_format_find_code - Find a format code in an array > + * @code: a pointer to media bus format codes array > + * @n_code: size of @code array > + * @index: index of code in the array > + * @req_code: required code > + * > + * Return media bus format code > + */ > +u32 camss_format_find_code(u32 *code, unsigned int n_code, unsigned int index, u32 req_code) > +{ > + int i; > + > + if (!req_code && index >= n_code) > + return 0; > + 0 as an error condition indicator is not very common, at least it shall be documented in the comment. > + for (i = 0; i < n_code; i++) { > + if (req_code) { > + if (req_code == code[i]) > + return req_code; > + } else { > + if (i == index) > + return code[i]; > + } > + } > + > + return code[0]; > +} > + > +/* > + * camss_format_find_format - Find a format in an array > + * @code: media bus format code > + * @pixelformat: V4L2 pixel format FCC identifier > + * @formats: a pointer to formats array > + * @nformats: size of @formats array > + * > + * Return index of a format or a negative error code otherwise > + */ > +int camss_format_find_format(u32 code, u32 pixelformat, const struct camss_format_info *formats, > + unsigned int nformats) > +{ > + int i; unsigned int i > + > + for (i = 0; i < nformats; i++) { > + if (formats[i].code == code && > + formats[i].pixelformat == pixelformat) > + return i; > + } > + > + for (i = 0; i < nformats; i++) { > + if (formats[i].code == code) > + return i; > + } > + > + WARN_ON(1); > + WARN_ON() is not needed here, it has to be removed. > + return -EINVAL; > +} > diff --git a/drivers/media/platform/qcom/camss/camss-format.h b/drivers/media/platform/qcom/camss/camss-format.h > index bfbc761bd46c..86b5790e343d 100644 > --- a/drivers/media/platform/qcom/camss/camss-format.h > +++ b/drivers/media/platform/qcom/camss/camss-format.h > @@ -59,4 +59,9 @@ struct camss_formats { > const struct camss_format_info *formats; > }; > > +u8 camss_format_get_bpp(const struct camss_format_info *formats, unsigned int nformats, u32 code); > +u32 camss_format_find_code(u32 *code, unsigned int n_code, unsigned int index, u32 req_code); > +int camss_format_find_format(u32 code, u32 pixelformat, const struct camss_format_info *formats, > + unsigned int nformats); > + > #endif /* __CAMSS_FORMAT_H__ */ > diff --git a/drivers/media/platform/qcom/camss/camss-vfe.c b/drivers/media/platform/qcom/camss/camss-vfe.c > index 2d5a64c055f1..83c5a36d071f 100644 > --- a/drivers/media/platform/qcom/camss/camss-vfe.c > +++ b/drivers/media/platform/qcom/camss/camss-vfe.c > @@ -278,48 +278,6 @@ const struct camss_formats vfe_formats_pix_845 = { > .formats = formats_rdi_845 > }; > > -/* > - * vfe_get_bpp - map media bus format to bits per pixel > - * @formats: supported media bus formats array > - * @nformats: size of @formats array > - * @code: media bus format code > - * > - * Return number of bits per pixel > - */ > -static u8 vfe_get_bpp(const struct camss_format_info *formats, > - unsigned int nformats, u32 code) > -{ > - unsigned int i; > - > - for (i = 0; i < nformats; i++) > - if (code == formats[i].code) > - return formats[i].mbus_bpp; > - > - WARN(1, "Unknown format\n"); > - > - return formats[0].mbus_bpp; > -} > - > -static u32 vfe_find_code(u32 *code, unsigned int n_code, > - unsigned int index, u32 req_code) > -{ > - int i; > - > - if (!req_code && (index >= n_code)) > - return 0; > - > - for (i = 0; i < n_code; i++) > - if (req_code) { > - if (req_code == code[i]) > - return req_code; > - } else { > - if (i == index) > - return code[i]; > - } > - > - return code[0]; > -} > - > static u32 vfe_src_pad_code(struct vfe_line *line, u32 sink_code, > unsigned int index, u32 src_req_code) > { > @@ -335,8 +293,8 @@ static u32 vfe_src_pad_code(struct vfe_line *line, u32 sink_code, > MEDIA_BUS_FMT_YUYV8_1_5X8, > }; > > - return vfe_find_code(src_code, ARRAY_SIZE(src_code), > - index, src_req_code); > + return camss_format_find_code(src_code, ARRAY_SIZE(src_code), > + index, src_req_code); > } > case MEDIA_BUS_FMT_YVYU8_1X16: > { > @@ -345,8 +303,8 @@ static u32 vfe_src_pad_code(struct vfe_line *line, u32 sink_code, > MEDIA_BUS_FMT_YVYU8_1_5X8, > }; > > - return vfe_find_code(src_code, ARRAY_SIZE(src_code), > - index, src_req_code); > + return camss_format_find_code(src_code, ARRAY_SIZE(src_code), > + index, src_req_code); > } > case MEDIA_BUS_FMT_UYVY8_1X16: > { > @@ -355,8 +313,8 @@ static u32 vfe_src_pad_code(struct vfe_line *line, u32 sink_code, > MEDIA_BUS_FMT_UYVY8_1_5X8, > }; > > - return vfe_find_code(src_code, ARRAY_SIZE(src_code), > - index, src_req_code); > + return camss_format_find_code(src_code, ARRAY_SIZE(src_code), > + index, src_req_code); > } > case MEDIA_BUS_FMT_VYUY8_1X16: > { > @@ -365,8 +323,8 @@ static u32 vfe_src_pad_code(struct vfe_line *line, u32 sink_code, > MEDIA_BUS_FMT_VYUY8_1_5X8, > }; > > - return vfe_find_code(src_code, ARRAY_SIZE(src_code), > - index, src_req_code); > + return camss_format_find_code(src_code, ARRAY_SIZE(src_code), > + index, src_req_code); > } > default: > if (index > 0) > @@ -391,8 +349,8 @@ static u32 vfe_src_pad_code(struct vfe_line *line, u32 sink_code, > MEDIA_BUS_FMT_YUYV8_1_5X8, > }; > > - return vfe_find_code(src_code, ARRAY_SIZE(src_code), > - index, src_req_code); > + return camss_format_find_code(src_code, ARRAY_SIZE(src_code), > + index, src_req_code); > } > case MEDIA_BUS_FMT_YVYU8_1X16: > { > @@ -404,8 +362,8 @@ static u32 vfe_src_pad_code(struct vfe_line *line, u32 sink_code, > MEDIA_BUS_FMT_YVYU8_1_5X8, > }; > > - return vfe_find_code(src_code, ARRAY_SIZE(src_code), > - index, src_req_code); > + return camss_format_find_code(src_code, ARRAY_SIZE(src_code), > + index, src_req_code); > } > case MEDIA_BUS_FMT_UYVY8_1X16: > { > @@ -417,8 +375,8 @@ static u32 vfe_src_pad_code(struct vfe_line *line, u32 sink_code, > MEDIA_BUS_FMT_UYVY8_1_5X8, > }; > > - return vfe_find_code(src_code, ARRAY_SIZE(src_code), > - index, src_req_code); > + return camss_format_find_code(src_code, ARRAY_SIZE(src_code), > + index, src_req_code); > } > case MEDIA_BUS_FMT_VYUY8_1X16: > { > @@ -430,8 +388,8 @@ static u32 vfe_src_pad_code(struct vfe_line *line, u32 sink_code, > MEDIA_BUS_FMT_VYUY8_1_5X8, > }; > > - return vfe_find_code(src_code, ARRAY_SIZE(src_code), > - index, src_req_code); > + return camss_format_find_code(src_code, ARRAY_SIZE(src_code), > + index, src_req_code); > } > default: > if (index > 0) > @@ -714,9 +672,9 @@ static int vfe_set_clock_rates(struct vfe_device *vfe) > } else { > struct vfe_line *l = &vfe->line[j]; > > - bpp = vfe_get_bpp(l->formats, > - l->nformats, > - l->fmt[MSM_VFE_PAD_SINK].code); > + bpp = camss_format_get_bpp(l->formats, > + l->nformats, > + l->fmt[MSM_VFE_PAD_SINK].code); > tmp = pixel_clock[j] * bpp / 64; > } > > @@ -795,9 +753,9 @@ static int vfe_check_clock_rates(struct vfe_device *vfe) > } else { > struct vfe_line *l = &vfe->line[j]; > > - bpp = vfe_get_bpp(l->formats, > - l->nformats, > - l->fmt[MSM_VFE_PAD_SINK].code); > + bpp = camss_format_get_bpp(l->formats, > + l->nformats, > + l->fmt[MSM_VFE_PAD_SINK].code); > tmp = pixel_clock[j] * bpp / 64; > } > > diff --git a/drivers/media/platform/qcom/camss/camss-video.c b/drivers/media/platform/qcom/camss/camss-video.c > index cd13a432e291..00b10dda3615 100644 > --- a/drivers/media/platform/qcom/camss/camss-video.c > +++ b/drivers/media/platform/qcom/camss/camss-video.c > @@ -28,27 +28,6 @@ > * Helper functions > */ > > -static int video_find_format(u32 code, u32 pixelformat, > - const struct camss_format_info *formats, > - unsigned int nformats) > -{ > - int i; > - > - for (i = 0; i < nformats; i++) { > - if (formats[i].code == code && > - formats[i].pixelformat == pixelformat) > - return i; > - } > - > - for (i = 0; i < nformats; i++) > - if (formats[i].code == code) > - return i; > - > - WARN_ON(1); > - > - return -EINVAL; > -} > - > /* > * video_mbus_to_pix_mp - Convert v4l2_mbus_framefmt to v4l2_pix_format_mplane > * @mbus: v4l2_mbus_framefmt format (input) > @@ -121,9 +100,8 @@ static int video_get_subdev_format(struct camss_video *video, > if (ret) > return ret; > > - ret = video_find_format(fmt.format.code, > - format->fmt.pix_mp.pixelformat, > - video->formats, video->nformats); > + ret = camss_format_find_format(fmt.format.code, format->fmt.pix_mp.pixelformat, > + video->formats, video->nformats); > if (ret < 0) > return ret; > -- Best wishes, Vladimir
Hi Vladimir, Thanks for the review, On 5/13/2024 6:39 PM, Vladimir Zapolskiy wrote: > On 4/11/24 15:45, Gjorgji Rosikopulos wrote: >> From: Radoslav Tsvetkov <quic_rtsvetko@quicinc.com> >> >> Move out the format related helper functions from vfe and video in a >> separate file. The goal here is to create a format API. >> >> Signed-off-by: Radoslav Tsvetkov <quic_rtsvetko@quicinc.com> >> Signed-off-by: Gjorgji Rosikopulos <quic_grosikop@quicinc.com> >> --- >> drivers/media/platform/qcom/camss/Makefile | 1 + >> .../media/platform/qcom/camss/camss-format.c | 98 +++++++++++++++++++ >> .../media/platform/qcom/camss/camss-format.h | 5 + >> drivers/media/platform/qcom/camss/camss-vfe.c | 86 +++++----------- >> .../media/platform/qcom/camss/camss-video.c | 26 +---- >> 5 files changed, 128 insertions(+), 88 deletions(-) >> create mode 100644 drivers/media/platform/qcom/camss/camss-format.c >> >> diff --git a/drivers/media/platform/qcom/camss/Makefile >> b/drivers/media/platform/qcom/camss/Makefile >> index 0d4389ab312d..e636968a1126 100644 >> --- a/drivers/media/platform/qcom/camss/Makefile >> +++ b/drivers/media/platform/qcom/camss/Makefile >> @@ -19,5 +19,6 @@ qcom-camss-objs += \ >> camss-vfe-gen1.o \ >> camss-vfe.o \ >> camss-video.o \ >> + camss-format.o \ >> obj-$(CONFIG_VIDEO_QCOM_CAMSS) += qcom-camss.o >> diff --git a/drivers/media/platform/qcom/camss/camss-format.c >> b/drivers/media/platform/qcom/camss/camss-format.c >> new file mode 100644 >> index 000000000000..6279cb099625 >> --- /dev/null >> +++ b/drivers/media/platform/qcom/camss/camss-format.c >> @@ -0,0 +1,98 @@ >> +// SPDX-License-Identifier: GPL-2.0-only >> +/* Copyright (c) 2023, The Linux Foundation. All rights reserved. >> + * Copyright (c) 2023 Qualcomm Technologies, Inc. >> + * >> + * This program is free software; you can redistribute it and/or modify >> + * it under the terms of the GNU General Public License version 2 and >> + * only version 2 as published by the Free Software Foundation. >> + * >> + * This program is distributed in the hope that it will be useful, >> + * but WITHOUT ANY WARRANTY; without even the implied warranty of >> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >> + * GNU General Public License for more details. >> + */ > > SPDX-License-Identifier is fully sufficient, the licence description > shall be removed. I need to check, but as i can see with other files the license description can be removed. > >> + >> +#include <linux/bug.h> >> +#include <linux/errno.h> >> + >> +#include "camss-format.h" >> + >> +/* >> + * camss_format_get_bpp - Map media bus format to bits per pixel >> + * @formats: supported media bus formats array >> + * @nformats: size of @formats array >> + * @code: media bus format code >> + * >> + * Return number of bits per pixel >> + */ >> +u8 camss_format_get_bpp(const struct camss_format_info *formats, >> unsigned int nformats, u32 code) >> +{ >> + unsigned int i; >> + >> + for (i = 0; i < nformats; i++) >> + if (code == formats[i].code) >> + return formats[i].mbus_bpp; >> + >> + WARN(1, "Unknown format\n"); >> + >> + return formats[0].mbus_bpp; >> +} >> + >> +/* >> + * camss_format_find_code - Find a format code in an array >> + * @code: a pointer to media bus format codes array >> + * @n_code: size of @code array >> + * @index: index of code in the array >> + * @req_code: required code >> + * >> + * Return media bus format code >> + */ >> +u32 camss_format_find_code(u32 *code, unsigned int n_code, unsigned >> int index, u32 req_code) >> +{ >> + int i; >> + >> + if (!req_code && index >= n_code) >> + return 0; >> + > > 0 as an error condition indicator is not very common, at least it shall be > documented in the comment. The original function was vfe_find_code. This change moves all format related functions across the sub-device files to camss-format I believe that 0 is default format. > >> + for (i = 0; i < n_code; i++) { >> + if (req_code) { >> + if (req_code == code[i]) >> + return req_code; >> + } else { >> + if (i == index) >> + return code[i]; >> + } >> + } >> + >> + return code[0]; >> +} >> + >> +/* >> + * camss_format_find_format - Find a format in an array >> + * @code: media bus format code >> + * @pixelformat: V4L2 pixel format FCC identifier >> + * @formats: a pointer to formats array >> + * @nformats: size of @formats array >> + * >> + * Return index of a format or a negative error code otherwise >> + */ >> +int camss_format_find_format(u32 code, u32 pixelformat, const struct >> camss_format_info *formats, >> + unsigned int nformats) >> +{ >> + int i; > > unsigned int i Maybe it makes sense to go to all functions already existing in camss and change int with unsigned int for for loops... > >> + >> + for (i = 0; i < nformats; i++) { >> + if (formats[i].code == code && >> + formats[i].pixelformat == pixelformat) >> + return i; >> + } >> + >> + for (i = 0; i < nformats; i++) { >> + if (formats[i].code == code) >> + return i; >> + } >> + >> + WARN_ON(1); >> + > > WARN_ON() is not needed here, it has to be removed. Again this is migrated code from camss-video :/. I guess we need bigger consensus to remove this WARN_ON. For me it makes sense to be removed. ~Gjorgji
On 13/05/2024 17:52, Gjorgji Rosikopulos (Consultant) wrote: >> 0 as an error condition indicator is not very common, at least it shall be >> documented in the comment. > The original function was vfe_find_code. This change moves all format > related functions across the sub-device files to camss-format > I believe that 0 is default format For this series changing the result code is extraneous, agree. We can debate such a change in a standalone patch on its own merits. --- bod
diff --git a/drivers/media/platform/qcom/camss/Makefile b/drivers/media/platform/qcom/camss/Makefile index 0d4389ab312d..e636968a1126 100644 --- a/drivers/media/platform/qcom/camss/Makefile +++ b/drivers/media/platform/qcom/camss/Makefile @@ -19,5 +19,6 @@ qcom-camss-objs += \ camss-vfe-gen1.o \ camss-vfe.o \ camss-video.o \ + camss-format.o \ obj-$(CONFIG_VIDEO_QCOM_CAMSS) += qcom-camss.o diff --git a/drivers/media/platform/qcom/camss/camss-format.c b/drivers/media/platform/qcom/camss/camss-format.c new file mode 100644 index 000000000000..6279cb099625 --- /dev/null +++ b/drivers/media/platform/qcom/camss/camss-format.c @@ -0,0 +1,98 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (c) 2023, The Linux Foundation. All rights reserved. + * Copyright (c) 2023 Qualcomm Technologies, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <linux/bug.h> +#include <linux/errno.h> + +#include "camss-format.h" + +/* + * camss_format_get_bpp - Map media bus format to bits per pixel + * @formats: supported media bus formats array + * @nformats: size of @formats array + * @code: media bus format code + * + * Return number of bits per pixel + */ +u8 camss_format_get_bpp(const struct camss_format_info *formats, unsigned int nformats, u32 code) +{ + unsigned int i; + + for (i = 0; i < nformats; i++) + if (code == formats[i].code) + return formats[i].mbus_bpp; + + WARN(1, "Unknown format\n"); + + return formats[0].mbus_bpp; +} + +/* + * camss_format_find_code - Find a format code in an array + * @code: a pointer to media bus format codes array + * @n_code: size of @code array + * @index: index of code in the array + * @req_code: required code + * + * Return media bus format code + */ +u32 camss_format_find_code(u32 *code, unsigned int n_code, unsigned int index, u32 req_code) +{ + int i; + + if (!req_code && index >= n_code) + return 0; + + for (i = 0; i < n_code; i++) { + if (req_code) { + if (req_code == code[i]) + return req_code; + } else { + if (i == index) + return code[i]; + } + } + + return code[0]; +} + +/* + * camss_format_find_format - Find a format in an array + * @code: media bus format code + * @pixelformat: V4L2 pixel format FCC identifier + * @formats: a pointer to formats array + * @nformats: size of @formats array + * + * Return index of a format or a negative error code otherwise + */ +int camss_format_find_format(u32 code, u32 pixelformat, const struct camss_format_info *formats, + unsigned int nformats) +{ + int i; + + for (i = 0; i < nformats; i++) { + if (formats[i].code == code && + formats[i].pixelformat == pixelformat) + return i; + } + + for (i = 0; i < nformats; i++) { + if (formats[i].code == code) + return i; + } + + WARN_ON(1); + + return -EINVAL; +} diff --git a/drivers/media/platform/qcom/camss/camss-format.h b/drivers/media/platform/qcom/camss/camss-format.h index bfbc761bd46c..86b5790e343d 100644 --- a/drivers/media/platform/qcom/camss/camss-format.h +++ b/drivers/media/platform/qcom/camss/camss-format.h @@ -59,4 +59,9 @@ struct camss_formats { const struct camss_format_info *formats; }; +u8 camss_format_get_bpp(const struct camss_format_info *formats, unsigned int nformats, u32 code); +u32 camss_format_find_code(u32 *code, unsigned int n_code, unsigned int index, u32 req_code); +int camss_format_find_format(u32 code, u32 pixelformat, const struct camss_format_info *formats, + unsigned int nformats); + #endif /* __CAMSS_FORMAT_H__ */ diff --git a/drivers/media/platform/qcom/camss/camss-vfe.c b/drivers/media/platform/qcom/camss/camss-vfe.c index 2d5a64c055f1..83c5a36d071f 100644 --- a/drivers/media/platform/qcom/camss/camss-vfe.c +++ b/drivers/media/platform/qcom/camss/camss-vfe.c @@ -278,48 +278,6 @@ const struct camss_formats vfe_formats_pix_845 = { .formats = formats_rdi_845 }; -/* - * vfe_get_bpp - map media bus format to bits per pixel - * @formats: supported media bus formats array - * @nformats: size of @formats array - * @code: media bus format code - * - * Return number of bits per pixel - */ -static u8 vfe_get_bpp(const struct camss_format_info *formats, - unsigned int nformats, u32 code) -{ - unsigned int i; - - for (i = 0; i < nformats; i++) - if (code == formats[i].code) - return formats[i].mbus_bpp; - - WARN(1, "Unknown format\n"); - - return formats[0].mbus_bpp; -} - -static u32 vfe_find_code(u32 *code, unsigned int n_code, - unsigned int index, u32 req_code) -{ - int i; - - if (!req_code && (index >= n_code)) - return 0; - - for (i = 0; i < n_code; i++) - if (req_code) { - if (req_code == code[i]) - return req_code; - } else { - if (i == index) - return code[i]; - } - - return code[0]; -} - static u32 vfe_src_pad_code(struct vfe_line *line, u32 sink_code, unsigned int index, u32 src_req_code) { @@ -335,8 +293,8 @@ static u32 vfe_src_pad_code(struct vfe_line *line, u32 sink_code, MEDIA_BUS_FMT_YUYV8_1_5X8, }; - return vfe_find_code(src_code, ARRAY_SIZE(src_code), - index, src_req_code); + return camss_format_find_code(src_code, ARRAY_SIZE(src_code), + index, src_req_code); } case MEDIA_BUS_FMT_YVYU8_1X16: { @@ -345,8 +303,8 @@ static u32 vfe_src_pad_code(struct vfe_line *line, u32 sink_code, MEDIA_BUS_FMT_YVYU8_1_5X8, }; - return vfe_find_code(src_code, ARRAY_SIZE(src_code), - index, src_req_code); + return camss_format_find_code(src_code, ARRAY_SIZE(src_code), + index, src_req_code); } case MEDIA_BUS_FMT_UYVY8_1X16: { @@ -355,8 +313,8 @@ static u32 vfe_src_pad_code(struct vfe_line *line, u32 sink_code, MEDIA_BUS_FMT_UYVY8_1_5X8, }; - return vfe_find_code(src_code, ARRAY_SIZE(src_code), - index, src_req_code); + return camss_format_find_code(src_code, ARRAY_SIZE(src_code), + index, src_req_code); } case MEDIA_BUS_FMT_VYUY8_1X16: { @@ -365,8 +323,8 @@ static u32 vfe_src_pad_code(struct vfe_line *line, u32 sink_code, MEDIA_BUS_FMT_VYUY8_1_5X8, }; - return vfe_find_code(src_code, ARRAY_SIZE(src_code), - index, src_req_code); + return camss_format_find_code(src_code, ARRAY_SIZE(src_code), + index, src_req_code); } default: if (index > 0) @@ -391,8 +349,8 @@ static u32 vfe_src_pad_code(struct vfe_line *line, u32 sink_code, MEDIA_BUS_FMT_YUYV8_1_5X8, }; - return vfe_find_code(src_code, ARRAY_SIZE(src_code), - index, src_req_code); + return camss_format_find_code(src_code, ARRAY_SIZE(src_code), + index, src_req_code); } case MEDIA_BUS_FMT_YVYU8_1X16: { @@ -404,8 +362,8 @@ static u32 vfe_src_pad_code(struct vfe_line *line, u32 sink_code, MEDIA_BUS_FMT_YVYU8_1_5X8, }; - return vfe_find_code(src_code, ARRAY_SIZE(src_code), - index, src_req_code); + return camss_format_find_code(src_code, ARRAY_SIZE(src_code), + index, src_req_code); } case MEDIA_BUS_FMT_UYVY8_1X16: { @@ -417,8 +375,8 @@ static u32 vfe_src_pad_code(struct vfe_line *line, u32 sink_code, MEDIA_BUS_FMT_UYVY8_1_5X8, }; - return vfe_find_code(src_code, ARRAY_SIZE(src_code), - index, src_req_code); + return camss_format_find_code(src_code, ARRAY_SIZE(src_code), + index, src_req_code); } case MEDIA_BUS_FMT_VYUY8_1X16: { @@ -430,8 +388,8 @@ static u32 vfe_src_pad_code(struct vfe_line *line, u32 sink_code, MEDIA_BUS_FMT_VYUY8_1_5X8, }; - return vfe_find_code(src_code, ARRAY_SIZE(src_code), - index, src_req_code); + return camss_format_find_code(src_code, ARRAY_SIZE(src_code), + index, src_req_code); } default: if (index > 0) @@ -714,9 +672,9 @@ static int vfe_set_clock_rates(struct vfe_device *vfe) } else { struct vfe_line *l = &vfe->line[j]; - bpp = vfe_get_bpp(l->formats, - l->nformats, - l->fmt[MSM_VFE_PAD_SINK].code); + bpp = camss_format_get_bpp(l->formats, + l->nformats, + l->fmt[MSM_VFE_PAD_SINK].code); tmp = pixel_clock[j] * bpp / 64; } @@ -795,9 +753,9 @@ static int vfe_check_clock_rates(struct vfe_device *vfe) } else { struct vfe_line *l = &vfe->line[j]; - bpp = vfe_get_bpp(l->formats, - l->nformats, - l->fmt[MSM_VFE_PAD_SINK].code); + bpp = camss_format_get_bpp(l->formats, + l->nformats, + l->fmt[MSM_VFE_PAD_SINK].code); tmp = pixel_clock[j] * bpp / 64; } diff --git a/drivers/media/platform/qcom/camss/camss-video.c b/drivers/media/platform/qcom/camss/camss-video.c index cd13a432e291..00b10dda3615 100644 --- a/drivers/media/platform/qcom/camss/camss-video.c +++ b/drivers/media/platform/qcom/camss/camss-video.c @@ -28,27 +28,6 @@ * Helper functions */ -static int video_find_format(u32 code, u32 pixelformat, - const struct camss_format_info *formats, - unsigned int nformats) -{ - int i; - - for (i = 0; i < nformats; i++) { - if (formats[i].code == code && - formats[i].pixelformat == pixelformat) - return i; - } - - for (i = 0; i < nformats; i++) - if (formats[i].code == code) - return i; - - WARN_ON(1); - - return -EINVAL; -} - /* * video_mbus_to_pix_mp - Convert v4l2_mbus_framefmt to v4l2_pix_format_mplane * @mbus: v4l2_mbus_framefmt format (input) @@ -121,9 +100,8 @@ static int video_get_subdev_format(struct camss_video *video, if (ret) return ret; - ret = video_find_format(fmt.format.code, - format->fmt.pix_mp.pixelformat, - video->formats, video->nformats); + ret = camss_format_find_format(fmt.format.code, format->fmt.pix_mp.pixelformat, + video->formats, video->nformats); if (ret < 0) return ret;