@@ -455,6 +455,8 @@ static int cam_flash_ops(struct cam_flash_ctrl *flash_ctrl,
455455
456456int cam_flash_off (struct cam_flash_ctrl * flash_ctrl )
457457{
458+ int rc = 0 ;
459+
458460 if (!flash_ctrl ) {
459461 CAM_ERR (CAM_FLASH , "Flash control Null" );
460462 return - EINVAL ;
@@ -463,7 +465,17 @@ int cam_flash_off(struct cam_flash_ctrl *flash_ctrl)
463465 if (flash_ctrl -> switch_trigger )
464466 cam_res_mgr_led_trigger_event (flash_ctrl -> switch_trigger ,
465467 (enum led_brightness )LED_SWITCH_OFF );
466- return 0 ;
468+
469+ if ((flash_ctrl -> i2c_data .streamoff_settings .is_settings_valid ) &&
470+ (flash_ctrl -> i2c_data .streamoff_settings .request_id == 0 )) {
471+ flash_ctrl -> apply_streamoff = true;
472+ rc = cam_flash_i2c_apply_setting (flash_ctrl , 0 );
473+ if (rc < 0 ) {
474+ CAM_ERR (CAM_SENSOR ,
475+ "cannot apply streamoff settings" );
476+ }
477+ }
478+ return rc ;
467479}
468480
469481static int cam_flash_low (
@@ -572,11 +584,26 @@ static int cam_flash_i2c_delete_req(struct cam_flash_ctrl *fctrl,
572584
573585 CAM_DBG (CAM_FLASH , "top: %llu, del_req_id:%llu" ,
574586 top , del_req_id );
587+
588+ for (i = 0 ; i < MAX_PER_FRAME_ARRAY ; i ++ ) {
589+ if ((del_req_id >
590+ fctrl -> i2c_data .per_frame [i ].request_id ) && (
591+ fctrl -> i2c_data .per_frame [i ].is_settings_valid
592+ == 1 )) {
593+ fctrl -> i2c_data .per_frame [i ].request_id = 0 ;
594+ rc = delete_request (
595+ & (fctrl -> i2c_data .per_frame [i ]));
596+ if (rc < 0 )
597+ CAM_ERR (CAM_SENSOR ,
598+ "Delete request Fail:%lld rc:%d" ,
599+ del_req_id , rc );
600+ }
601+ }
575602 }
576603
577604 cam_flash_i2c_flush_nrt (fctrl );
578605
579- return 0 ;
606+ return rc ;
580607}
581608
582609static int cam_flash_pmic_delete_req (struct cam_flash_ctrl * fctrl ,
@@ -672,9 +699,28 @@ int cam_flash_i2c_apply_setting(struct cam_flash_ctrl *fctrl,
672699 struct i2c_settings_array * i2c_set = NULL ;
673700 int frame_offset = 0 , rc = 0 ;
674701
702+ if (!fctrl ) {
703+ CAM_ERR (CAM_FLASH , "fctrl is NULL" );
704+ return - EINVAL ;
705+ }
675706 if (req_id == 0 ) {
676707 /* NonRealTime Init settings*/
677- if (fctrl -> i2c_data .init_settings .is_settings_valid == true) {
708+ if (fctrl -> apply_streamoff == true) {
709+ fctrl -> apply_streamoff = false;
710+ i2c_set = & fctrl -> i2c_data .streamoff_settings ;
711+ list_for_each_entry (i2c_list ,
712+ & (i2c_set -> list_head ),
713+ list ) {
714+ rc = cam_sensor_util_i2c_apply_setting
715+ (& (fctrl -> io_master_info ), i2c_list );
716+ if (rc ) {
717+ CAM_ERR (CAM_FLASH ,
718+ "Failed to apply stream on settings: %d" , rc );
719+ return rc ;
720+ }
721+ break ;
722+ }
723+ } else if (fctrl -> i2c_data .init_settings .is_settings_valid == true) {
678724 list_for_each_entry (i2c_list ,
679725 & (fctrl -> i2c_data .init_settings .list_head ),
680726 list ) {
@@ -936,6 +982,7 @@ int cam_flash_i2c_pkt_parser(struct cam_flash_ctrl *fctrl, void *arg)
936982 uint32_t * cmd_buf = NULL ;
937983 uint32_t * offset = NULL ;
938984 uint32_t frm_offset = 0 ;
985+ uint32_t csl_req_id = 0 ;
939986 size_t len_of_buffer ;
940987 size_t remain_len ;
941988 struct cam_flash_init * flash_init = NULL ;
@@ -947,6 +994,7 @@ int cam_flash_i2c_pkt_parser(struct cam_flash_ctrl *fctrl, void *arg)
947994 struct cam_req_mgr_add_request add_req ;
948995 struct i2c_settings_array * i2c_reg_settings = NULL ;
949996 struct cam_sensor_power_ctrl_t * power_info = NULL ;
997+ struct i2c_data_settings * i2c_data = NULL ;
950998
951999 if (!fctrl || !arg ) {
9521000 CAM_ERR (CAM_FLASH , "fctrl/arg is NULL" );
@@ -1170,6 +1218,7 @@ int cam_flash_i2c_pkt_parser(struct cam_flash_ctrl *fctrl, void *arg)
11701218 csl_packet -> cmd_buf_offset );
11711219 frm_offset = csl_packet -> header .request_id %
11721220 MAX_PER_FRAME_ARRAY ;
1221+ csl_req_id = csl_packet -> header .request_id ;
11731222 /* add support for handling i2c_data*/
11741223 i2c_reg_settings =
11751224 & fctrl -> i2c_data .per_frame [frm_offset ];
@@ -1191,8 +1240,49 @@ int cam_flash_i2c_pkt_parser(struct cam_flash_ctrl *fctrl, void *arg)
11911240 cam_mem_put_cpu_buf (config .packet_handle );
11921241 return rc ;
11931242 }
1243+ if ((fctrl -> flash_state == CAM_FLASH_STATE_ACQUIRE ) ||
1244+ (fctrl -> flash_state == CAM_FLASH_STATE_CONFIG )) {
1245+ fctrl -> flash_state = CAM_FLASH_STATE_CONFIG ;
1246+ rc = fctrl -> func_tbl .apply_setting (fctrl , csl_req_id );
1247+ if (rc ) {
1248+ CAM_ERR (CAM_FLASH , "cannot apply fire settings rc = %d" , rc );
1249+ return rc ;
1250+ }
1251+ return rc ;
1252+ }
11941253 break ;
11951254 }
1255+ case CAM_FLASH_PACKET_OPCODE_INIT_FIRE : {
1256+ frm_offset = csl_packet -> header .request_id %
1257+ MAX_PER_FRAME_ARRAY ;
1258+ csl_req_id = csl_packet -> header .request_id ;
1259+ CAM_DBG (CAM_FLASH , "Flash pkt init fire opcode received" );
1260+ /* add support for handling i2c_data*/
1261+ i2c_reg_settings =
1262+ & fctrl -> i2c_data .per_frame [frm_offset ];
1263+ if (i2c_reg_settings -> is_settings_valid == true) {
1264+ i2c_reg_settings -> request_id = 0 ;
1265+ i2c_reg_settings -> is_settings_valid = false;
1266+ goto update_req_mgr ;
1267+ }
1268+ i2c_reg_settings -> is_settings_valid = true;
1269+ i2c_reg_settings -> request_id =
1270+ csl_packet -> header .request_id ;
1271+ rc = cam_sensor_i2c_command_parser (
1272+ & fctrl -> io_master_info ,
1273+ i2c_reg_settings , cmd_desc , 1 , NULL );
1274+ if (rc ) {
1275+ CAM_ERR (CAM_FLASH ,
1276+ "Failed in parsing i2c packets" );
1277+ return rc ;
1278+ }
1279+
1280+ /* Apply the settings immediately as it is an EPR Req*/
1281+ rc = fctrl -> func_tbl .apply_setting (fctrl , csl_req_id );
1282+ if (rc )
1283+ CAM_ERR (CAM_FLASH , "cannot apply init fire cmd rc = %d" , rc );
1284+ return rc ;
1285+ }
11961286 case CAM_FLASH_PACKET_OPCODE_NON_REALTIME_SET_OPS : {
11971287 offset = (uint32_t * )((uint8_t * )& csl_packet -> payload_flex +
11981288 csl_packet -> cmd_buf_offset );
@@ -1232,6 +1322,8 @@ int cam_flash_i2c_pkt_parser(struct cam_flash_ctrl *fctrl, void *arg)
12321322 return rc ;
12331323 }
12341324 case CAM_PKT_NOP_OPCODE : {
1325+ frm_offset = csl_packet -> header .request_id %
1326+ MAX_PER_FRAME_ARRAY ;
12351327 if ((fctrl -> flash_state == CAM_FLASH_STATE_INIT ) ||
12361328 (fctrl -> flash_state == CAM_FLASH_STATE_ACQUIRE )) {
12371329 CAM_WARN (CAM_FLASH ,
@@ -1243,11 +1335,39 @@ int cam_flash_i2c_pkt_parser(struct cam_flash_ctrl *fctrl, void *arg)
12431335 cam_mem_put_cpu_buf (config .packet_handle );
12441336 return 0 ;
12451337 }
1338+ i2c_reg_settings =
1339+ & fctrl -> i2c_data .per_frame [frm_offset ];
1340+ i2c_reg_settings -> is_settings_valid = true;
1341+ i2c_reg_settings -> request_id =
1342+ csl_packet -> header .request_id ;
12461343
12471344 CAM_DBG (CAM_FLASH , "NOP Packet is Received: req_id: %u" ,
12481345 csl_packet -> header .request_id );
12491346 goto update_req_mgr ;
12501347 }
1348+ case CAM_FLASH_PACKET_OPCODE_STREAM_OFF : {
1349+ if (fctrl -> streamoff_count > 0 )
1350+ return rc ;
1351+
1352+ CAM_DBG (CAM_FLASH , "Received Stream off Settings" );
1353+ i2c_data = & (fctrl -> i2c_data );
1354+ fctrl -> streamoff_count = fctrl -> streamoff_count + 1 ;
1355+ i2c_reg_settings = & i2c_data -> streamoff_settings ;
1356+ i2c_reg_settings -> request_id = 0 ;
1357+ i2c_reg_settings -> is_settings_valid = 1 ;
1358+ offset = (uint32_t * )((uint8_t * )& csl_packet -> payload +
1359+ csl_packet -> cmd_buf_offset );
1360+ cmd_desc = (struct cam_cmd_buf_desc * )(offset );
1361+ rc = cam_sensor_i2c_command_parser (& fctrl -> io_master_info ,
1362+ i2c_reg_settings ,
1363+ cmd_desc , 1 , NULL );
1364+ if (rc ) {
1365+ CAM_ERR (CAM_FLASH ,
1366+ "Failed in parsing i2c Stream off packets" );
1367+ return rc ;
1368+ }
1369+ break ;
1370+ }
12511371 default :
12521372 CAM_ERR (CAM_FLASH , "Wrong Opcode : %d" ,
12531373 (csl_packet -> header .op_code & 0xFFFFFF ));
@@ -1985,6 +2105,16 @@ int cam_flash_release_dev(struct cam_flash_ctrl *fctrl)
19852105{
19862106 int rc = 0 ;
19872107
2108+ if (fctrl -> i2c_data .streamoff_settings .is_settings_valid == true) {
2109+ fctrl -> i2c_data .streamoff_settings .is_settings_valid = false;
2110+ rc = delete_request (& fctrl -> i2c_data .streamoff_settings );
2111+ if (rc ) {
2112+ CAM_WARN (CAM_FLASH ,
2113+ "Failed to delete Stream off i2c_setting: %d" ,
2114+ rc );
2115+ }
2116+ }
2117+
19882118 if (fctrl -> bridge_intf .device_hdl != 1 ) {
19892119 rc = cam_destroy_device_hdl (fctrl -> bridge_intf .device_hdl );
19902120 if (rc )
@@ -1995,6 +2125,7 @@ int cam_flash_release_dev(struct cam_flash_ctrl *fctrl)
19952125 fctrl -> bridge_intf .link_hdl = -1 ;
19962126 fctrl -> bridge_intf .session_hdl = -1 ;
19972127 fctrl -> last_flush_req = 0 ;
2128+ fctrl -> streamoff_count = 0 ;
19982129 }
19992130
20002131 return rc ;
0 commit comments