ov13858.c (8be98d2f2a0a262f8bf8a0bc1fdf522b3c7aab17) | ov13858.c (5bd4098c3d92be0c0124cfc13bd2a11ba3c39323) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2// Copyright (c) 2017 Intel Corporation. 3 4#include <linux/acpi.h> 5#include <linux/i2c.h> 6#include <linux/module.h> 7#include <linux/pm_runtime.h> 8#include <media/v4l2-ctrls.h> 9#include <media/v4l2-device.h> | 1// SPDX-License-Identifier: GPL-2.0 2// Copyright (c) 2017 Intel Corporation. 3 4#include <linux/acpi.h> 5#include <linux/i2c.h> 6#include <linux/module.h> 7#include <linux/pm_runtime.h> 8#include <media/v4l2-ctrls.h> 9#include <media/v4l2-device.h> |
10#include <media/v4l2-event.h> |
|
10#include <media/v4l2-fwnode.h> 11 12#define OV13858_REG_VALUE_08BIT 1 13#define OV13858_REG_VALUE_16BIT 2 14#define OV13858_REG_VALUE_24BIT 3 15 16#define OV13858_REG_MODE_SELECT 0x0100 17#define OV13858_MODE_STANDBY 0x00 --- 1127 unchanged lines hidden (view full) --- 1145 return ov13858_write_regs(ov13858, r_list->regs, r_list->num_of_regs); 1146} 1147 1148/* Open sub-device */ 1149static int ov13858_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) 1150{ 1151 struct ov13858 *ov13858 = to_ov13858(sd); 1152 struct v4l2_mbus_framefmt *try_fmt = v4l2_subdev_get_try_format(sd, | 11#include <media/v4l2-fwnode.h> 12 13#define OV13858_REG_VALUE_08BIT 1 14#define OV13858_REG_VALUE_16BIT 2 15#define OV13858_REG_VALUE_24BIT 3 16 17#define OV13858_REG_MODE_SELECT 0x0100 18#define OV13858_MODE_STANDBY 0x00 --- 1127 unchanged lines hidden (view full) --- 1146 return ov13858_write_regs(ov13858, r_list->regs, r_list->num_of_regs); 1147} 1148 1149/* Open sub-device */ 1150static int ov13858_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) 1151{ 1152 struct ov13858 *ov13858 = to_ov13858(sd); 1153 struct v4l2_mbus_framefmt *try_fmt = v4l2_subdev_get_try_format(sd, |
1153 fh->pad, | 1154 fh->state, |
1154 0); 1155 1156 mutex_lock(&ov13858->mutex); 1157 1158 /* Initialize try_fmt */ 1159 try_fmt->width = ov13858->cur_mode->width; 1160 try_fmt->height = ov13858->cur_mode->height; 1161 try_fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10; --- 108 unchanged lines hidden (view full) --- 1270 return ret; 1271} 1272 1273static const struct v4l2_ctrl_ops ov13858_ctrl_ops = { 1274 .s_ctrl = ov13858_set_ctrl, 1275}; 1276 1277static int ov13858_enum_mbus_code(struct v4l2_subdev *sd, | 1155 0); 1156 1157 mutex_lock(&ov13858->mutex); 1158 1159 /* Initialize try_fmt */ 1160 try_fmt->width = ov13858->cur_mode->width; 1161 try_fmt->height = ov13858->cur_mode->height; 1162 try_fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10; --- 108 unchanged lines hidden (view full) --- 1271 return ret; 1272} 1273 1274static const struct v4l2_ctrl_ops ov13858_ctrl_ops = { 1275 .s_ctrl = ov13858_set_ctrl, 1276}; 1277 1278static int ov13858_enum_mbus_code(struct v4l2_subdev *sd, |
1278 struct v4l2_subdev_pad_config *cfg, | 1279 struct v4l2_subdev_state *sd_state, |
1279 struct v4l2_subdev_mbus_code_enum *code) 1280{ 1281 /* Only one bayer order(GRBG) is supported */ 1282 if (code->index > 0) 1283 return -EINVAL; 1284 1285 code->code = MEDIA_BUS_FMT_SGRBG10_1X10; 1286 1287 return 0; 1288} 1289 1290static int ov13858_enum_frame_size(struct v4l2_subdev *sd, | 1280 struct v4l2_subdev_mbus_code_enum *code) 1281{ 1282 /* Only one bayer order(GRBG) is supported */ 1283 if (code->index > 0) 1284 return -EINVAL; 1285 1286 code->code = MEDIA_BUS_FMT_SGRBG10_1X10; 1287 1288 return 0; 1289} 1290 1291static int ov13858_enum_frame_size(struct v4l2_subdev *sd, |
1291 struct v4l2_subdev_pad_config *cfg, | 1292 struct v4l2_subdev_state *sd_state, |
1292 struct v4l2_subdev_frame_size_enum *fse) 1293{ 1294 if (fse->index >= ARRAY_SIZE(supported_modes)) 1295 return -EINVAL; 1296 1297 if (fse->code != MEDIA_BUS_FMT_SGRBG10_1X10) 1298 return -EINVAL; 1299 --- 10 unchanged lines hidden (view full) --- 1310{ 1311 fmt->format.width = mode->width; 1312 fmt->format.height = mode->height; 1313 fmt->format.code = MEDIA_BUS_FMT_SGRBG10_1X10; 1314 fmt->format.field = V4L2_FIELD_NONE; 1315} 1316 1317static int ov13858_do_get_pad_format(struct ov13858 *ov13858, | 1293 struct v4l2_subdev_frame_size_enum *fse) 1294{ 1295 if (fse->index >= ARRAY_SIZE(supported_modes)) 1296 return -EINVAL; 1297 1298 if (fse->code != MEDIA_BUS_FMT_SGRBG10_1X10) 1299 return -EINVAL; 1300 --- 10 unchanged lines hidden (view full) --- 1311{ 1312 fmt->format.width = mode->width; 1313 fmt->format.height = mode->height; 1314 fmt->format.code = MEDIA_BUS_FMT_SGRBG10_1X10; 1315 fmt->format.field = V4L2_FIELD_NONE; 1316} 1317 1318static int ov13858_do_get_pad_format(struct ov13858 *ov13858, |
1318 struct v4l2_subdev_pad_config *cfg, | 1319 struct v4l2_subdev_state *sd_state, |
1319 struct v4l2_subdev_format *fmt) 1320{ 1321 struct v4l2_mbus_framefmt *framefmt; 1322 struct v4l2_subdev *sd = &ov13858->sd; 1323 1324 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { | 1320 struct v4l2_subdev_format *fmt) 1321{ 1322 struct v4l2_mbus_framefmt *framefmt; 1323 struct v4l2_subdev *sd = &ov13858->sd; 1324 1325 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { |
1325 framefmt = v4l2_subdev_get_try_format(sd, cfg, fmt->pad); | 1326 framefmt = v4l2_subdev_get_try_format(sd, sd_state, fmt->pad); |
1326 fmt->format = *framefmt; 1327 } else { 1328 ov13858_update_pad_format(ov13858->cur_mode, fmt); 1329 } 1330 1331 return 0; 1332} 1333 1334static int ov13858_get_pad_format(struct v4l2_subdev *sd, | 1327 fmt->format = *framefmt; 1328 } else { 1329 ov13858_update_pad_format(ov13858->cur_mode, fmt); 1330 } 1331 1332 return 0; 1333} 1334 1335static int ov13858_get_pad_format(struct v4l2_subdev *sd, |
1335 struct v4l2_subdev_pad_config *cfg, | 1336 struct v4l2_subdev_state *sd_state, |
1336 struct v4l2_subdev_format *fmt) 1337{ 1338 struct ov13858 *ov13858 = to_ov13858(sd); 1339 int ret; 1340 1341 mutex_lock(&ov13858->mutex); | 1337 struct v4l2_subdev_format *fmt) 1338{ 1339 struct ov13858 *ov13858 = to_ov13858(sd); 1340 int ret; 1341 1342 mutex_lock(&ov13858->mutex); |
1342 ret = ov13858_do_get_pad_format(ov13858, cfg, fmt); | 1343 ret = ov13858_do_get_pad_format(ov13858, sd_state, fmt); |
1343 mutex_unlock(&ov13858->mutex); 1344 1345 return ret; 1346} 1347 1348static int 1349ov13858_set_pad_format(struct v4l2_subdev *sd, | 1344 mutex_unlock(&ov13858->mutex); 1345 1346 return ret; 1347} 1348 1349static int 1350ov13858_set_pad_format(struct v4l2_subdev *sd, |
1350 struct v4l2_subdev_pad_config *cfg, | 1351 struct v4l2_subdev_state *sd_state, |
1351 struct v4l2_subdev_format *fmt) 1352{ 1353 struct ov13858 *ov13858 = to_ov13858(sd); 1354 const struct ov13858_mode *mode; 1355 struct v4l2_mbus_framefmt *framefmt; 1356 s32 vblank_def; 1357 s32 vblank_min; 1358 s64 h_blank; --- 7 unchanged lines hidden (view full) --- 1366 fmt->format.code = MEDIA_BUS_FMT_SGRBG10_1X10; 1367 1368 mode = v4l2_find_nearest_size(supported_modes, 1369 ARRAY_SIZE(supported_modes), 1370 width, height, 1371 fmt->format.width, fmt->format.height); 1372 ov13858_update_pad_format(mode, fmt); 1373 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { | 1352 struct v4l2_subdev_format *fmt) 1353{ 1354 struct ov13858 *ov13858 = to_ov13858(sd); 1355 const struct ov13858_mode *mode; 1356 struct v4l2_mbus_framefmt *framefmt; 1357 s32 vblank_def; 1358 s32 vblank_min; 1359 s64 h_blank; --- 7 unchanged lines hidden (view full) --- 1367 fmt->format.code = MEDIA_BUS_FMT_SGRBG10_1X10; 1368 1369 mode = v4l2_find_nearest_size(supported_modes, 1370 ARRAY_SIZE(supported_modes), 1371 width, height, 1372 fmt->format.width, fmt->format.height); 1373 ov13858_update_pad_format(mode, fmt); 1374 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { |
1374 framefmt = v4l2_subdev_get_try_format(sd, cfg, fmt->pad); | 1375 framefmt = v4l2_subdev_get_try_format(sd, sd_state, fmt->pad); |
1375 *framefmt = fmt->format; 1376 } else { 1377 ov13858->cur_mode = mode; 1378 __v4l2_ctrl_s_ctrl(ov13858->link_freq, mode->link_freq_index); 1379 link_freq = link_freq_menu_items[mode->link_freq_index]; 1380 pixel_rate = link_freq_to_pixel_rate(link_freq); 1381 __v4l2_ctrl_s_ctrl_int64(ov13858->pixel_rate, pixel_rate); 1382 --- 84 unchanged lines hidden (view full) --- 1467 1468 mutex_lock(&ov13858->mutex); 1469 if (ov13858->streaming == enable) { 1470 mutex_unlock(&ov13858->mutex); 1471 return 0; 1472 } 1473 1474 if (enable) { | 1376 *framefmt = fmt->format; 1377 } else { 1378 ov13858->cur_mode = mode; 1379 __v4l2_ctrl_s_ctrl(ov13858->link_freq, mode->link_freq_index); 1380 link_freq = link_freq_menu_items[mode->link_freq_index]; 1381 pixel_rate = link_freq_to_pixel_rate(link_freq); 1382 __v4l2_ctrl_s_ctrl_int64(ov13858->pixel_rate, pixel_rate); 1383 --- 84 unchanged lines hidden (view full) --- 1468 1469 mutex_lock(&ov13858->mutex); 1470 if (ov13858->streaming == enable) { 1471 mutex_unlock(&ov13858->mutex); 1472 return 0; 1473 } 1474 1475 if (enable) { |
1475 ret = pm_runtime_get_sync(&client->dev); 1476 if (ret < 0) { 1477 pm_runtime_put_noidle(&client->dev); | 1476 ret = pm_runtime_resume_and_get(&client->dev); 1477 if (ret < 0) |
1478 goto err_unlock; | 1478 goto err_unlock; |
1479 } | |
1480 1481 /* 1482 * Apply default & customized values 1483 * and then start streaming. 1484 */ 1485 ret = ov13858_start_streaming(ov13858); 1486 if (ret) 1487 goto err_rpm_put; --- 62 unchanged lines hidden (view full) --- 1550 dev_err(&client->dev, "chip id mismatch: %x!=%x\n", 1551 OV13858_CHIP_ID, val); 1552 return -EIO; 1553 } 1554 1555 return 0; 1556} 1557 | 1479 1480 /* 1481 * Apply default & customized values 1482 * and then start streaming. 1483 */ 1484 ret = ov13858_start_streaming(ov13858); 1485 if (ret) 1486 goto err_rpm_put; --- 62 unchanged lines hidden (view full) --- 1549 dev_err(&client->dev, "chip id mismatch: %x!=%x\n", 1550 OV13858_CHIP_ID, val); 1551 return -EIO; 1552 } 1553 1554 return 0; 1555} 1556 |
1557static const struct v4l2_subdev_core_ops ov13858_core_ops = { 1558 .log_status = v4l2_ctrl_subdev_log_status, 1559 .subscribe_event = v4l2_ctrl_subdev_subscribe_event, 1560 .unsubscribe_event = v4l2_event_subdev_unsubscribe, 1561}; 1562 |
|
1558static const struct v4l2_subdev_video_ops ov13858_video_ops = { 1559 .s_stream = ov13858_set_stream, 1560}; 1561 1562static const struct v4l2_subdev_pad_ops ov13858_pad_ops = { 1563 .enum_mbus_code = ov13858_enum_mbus_code, 1564 .get_fmt = ov13858_get_pad_format, 1565 .set_fmt = ov13858_set_pad_format, 1566 .enum_frame_size = ov13858_enum_frame_size, 1567}; 1568 1569static const struct v4l2_subdev_sensor_ops ov13858_sensor_ops = { 1570 .g_skip_frames = ov13858_get_skip_frames, 1571}; 1572 1573static const struct v4l2_subdev_ops ov13858_subdev_ops = { | 1563static const struct v4l2_subdev_video_ops ov13858_video_ops = { 1564 .s_stream = ov13858_set_stream, 1565}; 1566 1567static const struct v4l2_subdev_pad_ops ov13858_pad_ops = { 1568 .enum_mbus_code = ov13858_enum_mbus_code, 1569 .get_fmt = ov13858_get_pad_format, 1570 .set_fmt = ov13858_set_pad_format, 1571 .enum_frame_size = ov13858_enum_frame_size, 1572}; 1573 1574static const struct v4l2_subdev_sensor_ops ov13858_sensor_ops = { 1575 .g_skip_frames = ov13858_get_skip_frames, 1576}; 1577 1578static const struct v4l2_subdev_ops ov13858_subdev_ops = { |
1579 .core = &ov13858_core_ops, |
|
1574 .video = &ov13858_video_ops, 1575 .pad = &ov13858_pad_ops, 1576 .sensor = &ov13858_sensor_ops, 1577}; 1578 1579static const struct media_entity_operations ov13858_subdev_entity_ops = { 1580 .link_validate = v4l2_subdev_link_validate, 1581}; --- 139 unchanged lines hidden (view full) --- 1721 ov13858->cur_mode = &supported_modes[0]; 1722 1723 ret = ov13858_init_controls(ov13858); 1724 if (ret) 1725 return ret; 1726 1727 /* Initialize subdev */ 1728 ov13858->sd.internal_ops = &ov13858_internal_ops; | 1580 .video = &ov13858_video_ops, 1581 .pad = &ov13858_pad_ops, 1582 .sensor = &ov13858_sensor_ops, 1583}; 1584 1585static const struct media_entity_operations ov13858_subdev_entity_ops = { 1586 .link_validate = v4l2_subdev_link_validate, 1587}; --- 139 unchanged lines hidden (view full) --- 1727 ov13858->cur_mode = &supported_modes[0]; 1728 1729 ret = ov13858_init_controls(ov13858); 1730 if (ret) 1731 return ret; 1732 1733 /* Initialize subdev */ 1734 ov13858->sd.internal_ops = &ov13858_internal_ops; |
1729 ov13858->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; | 1735 ov13858->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | 1736 V4L2_SUBDEV_FL_HAS_EVENTS; |
1730 ov13858->sd.entity.ops = &ov13858_subdev_entity_ops; 1731 ov13858->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; 1732 1733 /* Initialize source pad */ 1734 ov13858->pad.flags = MEDIA_PAD_FL_SOURCE; 1735 ret = media_entity_pads_init(&ov13858->sd.entity, 1, &ov13858->pad); 1736 if (ret) { 1737 dev_err(&client->dev, "%s failed:%d\n", __func__, ret); --- 79 unchanged lines hidden --- | 1737 ov13858->sd.entity.ops = &ov13858_subdev_entity_ops; 1738 ov13858->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; 1739 1740 /* Initialize source pad */ 1741 ov13858->pad.flags = MEDIA_PAD_FL_SOURCE; 1742 ret = media_entity_pads_init(&ov13858->sd.entity, 1, &ov13858->pad); 1743 if (ret) { 1744 dev_err(&client->dev, "%s failed:%d\n", __func__, ret); --- 79 unchanged lines hidden --- |