Re: [PATCH v5 1/1] media: v4l2-common: Add helper function media_bus_fmt_to_csi2_(bpp|dt)()

From: Frank Li

Date: Fri May 15 2026 - 10:15:16 EST


On Fri, May 15, 2026 at 12:41:02PM +0300, Sakari Ailus wrote:
> Hi Frank,
>
> Thanks for the update!
>
> On Thu, May 14, 2026 at 02:33:53PM -0400, Frank Li wrote:
> > +static const struct media_bus_fmt_info *media_bus_fmt_info_get(u32 bus_fmt)
> > +{
> > + for (unsigned int i = 0; i < ARRAY_SIZE(media_bus_fmt_info); i++) {
> > + if (media_bus_fmt_info[i].code == bus_fmt)
> > + return &media_bus_fmt_info[i];
> > + }
> > +
> > + return NULL;
> > +}
> > +
> > +u32 media_bus_fmt_to_csi2_dt(u32 bus_fmt)
>
> I meant to use int and a negative return value here, too.
>
> I'll pick this into my set and change this as well.

Yes, make sense. so needn't MIPI_CSI2_DT_INVALID.

Frank
>
> > +{
> > + const struct media_bus_fmt_info *info = media_bus_fmt_info_get(bus_fmt);
> > +
> > + if (!info)
> > + return MIPI_CSI2_DT_INVALID;
> > +
> > + /* Check bpp because 0 (MIPI_CSI2_DT_FS) is a valid data type code */
> > + return info->bpp ? info->dt : MIPI_CSI2_DT_INVALID;
> > +}
> > +EXPORT_SYMBOL_GPL(media_bus_fmt_to_csi2_dt);
> > +
> > +int media_bus_fmt_to_csi2_bpp(u32 bus_fmt)
> > +{
> > + const struct media_bus_fmt_info *info = media_bus_fmt_info_get(bus_fmt);
> > +
> > + if (!info)
> > + return -EINVAL;
> > +
> > + return info->bpp ? info->bpp : -EINVAL;
> > +}
> > +EXPORT_SYMBOL_GPL(media_bus_fmt_to_csi2_bpp);
>
> --
> Kind regards,
>
> Sakari Ailus