Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: ov8856: Set default mbus format but allow caller to alter

Setting the value of V_WIN_OFF (0x3818) from 0x02 to 0x01 to use GRBG
format still results in wrong color output if data is tuned in BGGR mode
before.

Set default mbus format for the supported modes, but allow the caller of
set(get)_fmt to change the bayer format between BGGR and GRBG.

Set the default mbus format for 3264x2448 (and 1632x1224) to BGGR as the
data sheet states the value of this reg should be 0x02 by default.

If new modes are added in the future, they can add the
mipi_data_mbus_{format} settings into bayer_offset_configs to adjust their
offset regs.

Fixes: 2984b0ddd557 ("media: ov8856: Configure sensor for GRBG Bayer for all modes")
Signed-off-by: Hsin-Yi Wang <hsinyi@chromium.org>
Reviewed-by: Robert Foss <robert.foss@linaro.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

authored by

Hsin-Yi Wang and committed by
Mauro Carvalho Chehab
f1363166 7ee85054

+72 -11
+72 -11
drivers/media/i2c/ov8856.c
··· 107 107 "dvdd", /* Digital core power */ 108 108 }; 109 109 110 + enum { 111 + OV8856_MEDIA_BUS_FMT_SBGGR10_1X10, 112 + OV8856_MEDIA_BUS_FMT_SGRBG10_1X10, 113 + }; 114 + 110 115 struct ov8856_reg { 111 116 u16 address; 112 117 u8 val; ··· 150 145 151 146 /* Number of data lanes */ 152 147 u8 data_lanes; 148 + 149 + /* Default MEDIA_BUS_FMT for this mode */ 150 + u32 default_mbus_index; 153 151 }; 154 152 155 153 struct ov8856_mipi_data_rates { ··· 1063 1055 {0x3810, 0x00}, 1064 1056 {0x3811, 0x04}, 1065 1057 {0x3812, 0x00}, 1066 - {0x3813, 0x01}, 1058 + {0x3813, 0x02}, 1067 1059 {0x3814, 0x01}, 1068 1060 {0x3815, 0x01}, 1069 1061 {0x3816, 0x00}, ··· 1267 1259 {0x3810, 0x00}, 1268 1260 {0x3811, 0x02}, 1269 1261 {0x3812, 0x00}, 1270 - {0x3813, 0x01}, 1262 + {0x3813, 0x02}, 1271 1263 {0x3814, 0x03}, 1272 1264 {0x3815, 0x01}, 1273 1265 {0x3816, 0x00}, ··· 1380 1372 {0x5e10, 0xfc} 1381 1373 }; 1382 1374 1375 + static const struct ov8856_reg mipi_data_mbus_sbggr10_1x10[] = { 1376 + {0x3813, 0x02}, 1377 + }; 1378 + 1379 + static const struct ov8856_reg mipi_data_mbus_sgrbg10_1x10[] = { 1380 + {0x3813, 0x01}, 1381 + }; 1382 + 1383 + static const u32 ov8856_mbus_codes[] = { 1384 + MEDIA_BUS_FMT_SBGGR10_1X10, 1385 + MEDIA_BUS_FMT_SGRBG10_1X10 1386 + }; 1387 + 1383 1388 static const char * const ov8856_test_pattern_menu[] = { 1384 1389 "Disabled", 1385 1390 "Standard Color Bar", 1386 1391 "Top-Bottom Darker Color Bar", 1387 1392 "Right-Left Darker Color Bar", 1388 1393 "Bottom-Top Darker Color Bar" 1394 + }; 1395 + 1396 + static const struct ov8856_reg_list bayer_offset_configs[] = { 1397 + [OV8856_MEDIA_BUS_FMT_SBGGR10_1X10] = { 1398 + .num_of_regs = ARRAY_SIZE(mipi_data_mbus_sbggr10_1x10), 1399 + .regs = mipi_data_mbus_sbggr10_1x10, 1400 + }, 1401 + [OV8856_MEDIA_BUS_FMT_SGRBG10_1X10] = { 1402 + .num_of_regs = ARRAY_SIZE(mipi_data_mbus_sgrbg10_1x10), 1403 + .regs = mipi_data_mbus_sgrbg10_1x10, 1404 + } 1389 1405 }; 1390 1406 1391 1407 struct ov8856 { ··· 1430 1398 1431 1399 /* Current mode */ 1432 1400 const struct ov8856_mode *cur_mode; 1401 + 1402 + /* Application specified mbus format */ 1403 + u32 cur_mbus_index; 1433 1404 1434 1405 /* To serialize asynchronus callbacks */ 1435 1406 struct mutex mutex; ··· 1485 1450 }, 1486 1451 .link_freq_index = 0, 1487 1452 .data_lanes = 2, 1453 + .default_mbus_index = OV8856_MEDIA_BUS_FMT_SGRBG10_1X10, 1488 1454 }, 1489 1455 { 1490 1456 .width = 1640, ··· 1500 1464 }, 1501 1465 .link_freq_index = 1, 1502 1466 .data_lanes = 2, 1467 + .default_mbus_index = OV8856_MEDIA_BUS_FMT_SGRBG10_1X10, 1503 1468 }} 1504 1469 }; 1505 1470 ··· 1536 1499 }, 1537 1500 .link_freq_index = 0, 1538 1501 .data_lanes = 4, 1502 + .default_mbus_index = OV8856_MEDIA_BUS_FMT_SGRBG10_1X10, 1539 1503 }, 1540 1504 { 1541 1505 .width = 1640, ··· 1551 1513 }, 1552 1514 .link_freq_index = 1, 1553 1515 .data_lanes = 4, 1516 + .default_mbus_index = OV8856_MEDIA_BUS_FMT_SGRBG10_1X10, 1554 1517 }, 1555 1518 { 1556 1519 .width = 3264, ··· 1566 1527 }, 1567 1528 .link_freq_index = 0, 1568 1529 .data_lanes = 4, 1530 + .default_mbus_index = OV8856_MEDIA_BUS_FMT_SBGGR10_1X10, 1569 1531 }, 1570 1532 { 1571 1533 .width = 1632, ··· 1581 1541 }, 1582 1542 .link_freq_index = 1, 1583 1543 .data_lanes = 4, 1544 + .default_mbus_index = OV8856_MEDIA_BUS_FMT_SBGGR10_1X10, 1584 1545 }} 1585 1546 }; 1586 1547 ··· 1945 1904 return 0; 1946 1905 } 1947 1906 1948 - static void ov8856_update_pad_format(const struct ov8856_mode *mode, 1907 + static void ov8856_update_pad_format(struct ov8856 *ov8856, 1908 + const struct ov8856_mode *mode, 1949 1909 struct v4l2_mbus_framefmt *fmt) 1950 1910 { 1911 + int index; 1912 + 1951 1913 fmt->width = mode->width; 1952 1914 fmt->height = mode->height; 1953 - fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10; 1915 + for (index = 0; index < ARRAY_SIZE(ov8856_mbus_codes); ++index) 1916 + if (ov8856_mbus_codes[index] == fmt->code) 1917 + break; 1918 + if (index == ARRAY_SIZE(ov8856_mbus_codes)) 1919 + index = mode->default_mbus_index; 1920 + fmt->code = ov8856_mbus_codes[index]; 1921 + ov8856->cur_mbus_index = index; 1954 1922 fmt->field = V4L2_FIELD_NONE; 1955 1923 } 1956 1924 ··· 1982 1932 ret = ov8856_write_reg_list(ov8856, reg_list); 1983 1933 if (ret) { 1984 1934 dev_err(&client->dev, "failed to set mode"); 1935 + return ret; 1936 + } 1937 + 1938 + reg_list = &bayer_offset_configs[ov8856->cur_mbus_index]; 1939 + ret = ov8856_write_reg_list(ov8856, reg_list); 1940 + if (ret) { 1941 + dev_err(&client->dev, "failed to set mbus format"); 1985 1942 return ret; 1986 1943 } 1987 1944 ··· 2153 2096 fmt->format.height); 2154 2097 2155 2098 mutex_lock(&ov8856->mutex); 2156 - ov8856_update_pad_format(mode, &fmt->format); 2099 + ov8856_update_pad_format(ov8856, mode, &fmt->format); 2157 2100 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { 2158 2101 *v4l2_subdev_get_try_format(sd, sd_state, fmt->pad) = fmt->format; 2159 2102 } else { ··· 2197 2140 sd_state, 2198 2141 fmt->pad); 2199 2142 else 2200 - ov8856_update_pad_format(ov8856->cur_mode, &fmt->format); 2143 + ov8856_update_pad_format(ov8856, ov8856->cur_mode, &fmt->format); 2201 2144 2202 2145 mutex_unlock(&ov8856->mutex); 2203 2146 ··· 2208 2151 struct v4l2_subdev_state *sd_state, 2209 2152 struct v4l2_subdev_mbus_code_enum *code) 2210 2153 { 2211 - /* Only one bayer order GRBG is supported */ 2212 - if (code->index > 0) 2154 + if (code->index >= ARRAY_SIZE(ov8856_mbus_codes)) 2213 2155 return -EINVAL; 2214 2156 2215 - code->code = MEDIA_BUS_FMT_SGRBG10_1X10; 2157 + code->code = ov8856_mbus_codes[code->index]; 2216 2158 2217 2159 return 0; 2218 2160 } ··· 2221 2165 struct v4l2_subdev_frame_size_enum *fse) 2222 2166 { 2223 2167 struct ov8856 *ov8856 = to_ov8856(sd); 2168 + int index; 2224 2169 2225 2170 if (fse->index >= ov8856->modes_size) 2226 2171 return -EINVAL; 2227 2172 2228 - if (fse->code != MEDIA_BUS_FMT_SGRBG10_1X10) 2173 + for (index = 0; index < ARRAY_SIZE(ov8856_mbus_codes); ++index) 2174 + if (fse->code == ov8856_mbus_codes[index]) 2175 + break; 2176 + if (index == ARRAY_SIZE(ov8856_mbus_codes)) 2229 2177 return -EINVAL; 2230 2178 2231 2179 fse->min_width = ov8856->priv_lane->supported_modes[fse->index].width; ··· 2245 2185 struct ov8856 *ov8856 = to_ov8856(sd); 2246 2186 2247 2187 mutex_lock(&ov8856->mutex); 2248 - ov8856_update_pad_format(&ov8856->priv_lane->supported_modes[0], 2188 + ov8856_update_pad_format(ov8856, &ov8856->priv_lane->supported_modes[0], 2249 2189 v4l2_subdev_get_try_format(sd, fh->state, 0)); 2250 2190 mutex_unlock(&ov8856->mutex); 2251 2191 ··· 2486 2426 2487 2427 mutex_init(&ov8856->mutex); 2488 2428 ov8856->cur_mode = &ov8856->priv_lane->supported_modes[0]; 2429 + ov8856->cur_mbus_index = ov8856->cur_mode->default_mbus_index; 2489 2430 ret = ov8856_init_controls(ov8856); 2490 2431 if (ret) { 2491 2432 dev_err(&client->dev, "failed to init controls: %d", ret);