+static int imx219_resolve_binning(struct imx219 *imx219,
+ const struct v4l2_mbus_framefmt *format,
+ enum binning_mode *binning)
+{
+ u32 fmt;
+
+ if (format)
+ fmt = format->code;
+ else
+ fmt = MEDIA_BUS_FMT_SRGGB10_1X10;
+
+ switch (fmt) {
+ case MEDIA_BUS_FMT_SRGGB8_1X8:
+ case MEDIA_BUS_FMT_SGRBG8_1X8:
+ case MEDIA_BUS_FMT_SGBRG8_1X8:
+ case MEDIA_BUS_FMT_SBGGR8_1X8:
+ *binning = imx219->mode->binning[BINNING_IDX_8_BIT];
+ return 0;
+
+ case MEDIA_BUS_FMT_SRGGB10_1X10:
+ case MEDIA_BUS_FMT_SGRBG10_1X10:
+ case MEDIA_BUS_FMT_SGBRG10_1X10:
+ case MEDIA_BUS_FMT_SBGGR10_1X10:
+ *binning = imx219->mode->binning[BINNING_IDX_10_BIT];
+ return 0;
+ }
+ return -EINVAL;
+}
+
+static int imx219_get_rate_factor(struct imx219 *imx219,
+ const struct v4l2_mbus_framefmt *format)
+{
+ enum binning_mode binning = BINNING_NONE;
+ int ret;
+
+ ret = imx219_resolve_binning(imx219, format, &binning);
+ if (ret < 0)
+ return ret;
+
+ switch (binning) {
+ case BINNING_NONE:
+ case BINNING_NORMAL_2x2:
+ return 1;
+ case BINNING_SPECIAL_2x2:
+ return 2;
+ }
+ return -EINVAL;
+}
+