+
+ for (i = 0; i < mt9p031->num_fmts; i++)
+ if (mt9p031->fmts[i] == code)
+ return mt9p031->fmts[i];
+
+ return mt9p031->fmts[mt9p031->num_fmts-1];
+}
+
static int mt9p031_read(struct i2c_client *client, u8 reg)
{
return i2c_smbus_read_word_swapped(client, reg);
@@ -476,10 +502,11 @@ static int mt9p031_enum_mbus_code(struct v4l2_subdev *subdev,
{
struct mt9p031 *mt9p031 = to_mt9p031(subdev);
- if (code->pad || code->index)
+ if (code->pad || code->index >= mt9p031->num_fmts)
return -EINVAL;
- code->code = mt9p031->format.code;
+ code->code = mt9p031->fmts[code->index];
+
return 0;
}
@@ -573,6 +600,8 @@ static int mt9p031_set_format(struct v4l2_subdev *subdev,
__format->width = __crop->width / hratio;
__format->height = __crop->height / vratio;
+ __format->code = mt9p031_find_datafmt(mt9p031, format->format.code);
+
format->format = *__format;
return 0;
@@ -951,10 +980,7 @@ static int mt9p031_open(struct v4l2_subdev *subdev, struct v4l2_subdev_fh *fh)
format = v4l2_subdev_get_try_format(subdev, fh->pad, 0);
- if (mt9p031->model == MT9P031_MODEL_MONOCHROME)
- format->code = MEDIA_BUS_FMT_Y12_1X12;
- else
- format->code = MEDIA_BUS_FMT_SGRBG12_1X12;
+ format->code = mt9p031_find_datafmt(mt9p031, 0);
format->width = MT9P031_WINDOW_WIDTH_DEF;
format->height = MT9P031_WINDOW_HEIGHT_DEF;
@@ -1121,10 +1147,14 @@ static int mt9p031_probe(struct i2c_client *client,
mt9p031->crop.left = MT9P031_COLUMN_START_DEF;
mt9p031->crop.top = MT9P031_ROW_START_DEF;
- if (mt9p031->model == MT9P031_MODEL_MONOCHROME)
- mt9p031->format.code = MEDIA_BUS_FMT_Y12_1X12;
- else
- mt9p031->format.code = MEDIA_BUS_FMT_SGRBG12_1X12;
+ if (mt9p031->model == MT9P031_MODEL_MONOCHROME) {
+ mt9p031->fmts = mt9p031_monochrome_fmts;
+ mt9p031->num_fmts = ARRAY_SIZE(mt9p031_monochrome_fmts);
+ } else {
+ mt9p031->fmts = mt9p031_color_fmts;
+ mt9p031->num_fmts = ARRAY_SIZE(mt9p031_color_fmts);
+ }
+ mt9p031->format.code = mt9p031_find_datafmt(mt9p031, 0);
mt9p031->format.width = MT9P031_WINDOW_WIDTH_DEF;
mt9p031->format.height = MT9P031_WINDOW_HEIGHT_DEF;