Skip to content

Commit 8b1dfea

Browse files
Camera Software IntegrationGerrit - the friendly Code Review server
authored andcommitted
Merge "msm: camera: flash: Add support for I2C flash" into camera-kernel.qclinux.1.0
2 parents 38d6efd + 630d15f commit 8b1dfea

7 files changed

Lines changed: 248 additions & 15 deletions

File tree

camera/drivers/cam_sensor_module/cam_flash/cam_flash_core.c

Lines changed: 134 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,8 @@ static int cam_flash_ops(struct cam_flash_ctrl *flash_ctrl,
455455

456456
int 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

469481
static 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

582609
static 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;

camera/drivers/cam_sensor_module/cam_flash/cam_flash_dev.c

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ static int32_t cam_flash_driver_cmd(struct cam_flash_ctrl *fctrl,
7777
flash_acq_dev.device_handle;
7878
fctrl->bridge_intf.session_hdl =
7979
flash_acq_dev.session_handle;
80+
fctrl->apply_streamoff = false;
8081

8182
rc = copy_to_user(u64_to_user_ptr(cmd->handle),
8283
&flash_acq_dev,
@@ -135,14 +136,15 @@ static int32_t cam_flash_driver_cmd(struct cam_flash_ctrl *fctrl,
135136
CAM_WARN(CAM_FLASH, "Power Down Failed");
136137
}
137138

139+
fctrl->streamoff_count = 0;
138140
fctrl->flash_state = CAM_FLASH_STATE_INIT;
139141
break;
140142
}
141143
case CAM_QUERY_CAP: {
142144
struct cam_flash_query_cap_info flash_cap = {0};
143145

144-
CAM_DBG(CAM_FLASH, "CAM_QUERY_CAP");
145-
flash_cap.slot_info = fctrl->soc_info.index;
146+
CAM_DBG(CAM_FLASH, "CAM_QUERY_CAP_V1");
147+
flash_cap.slot_info = fctrl->soc_info.index;
146148
for (i = 0; i < fctrl->flash_num_sources; i++) {
147149
flash_cap.max_current_flash[i] =
148150
soc_private->flash_max_current[i];
@@ -160,8 +162,39 @@ static int32_t cam_flash_driver_cmd(struct cam_flash_ctrl *fctrl,
160162
rc = -EFAULT;
161163
goto release_mutex;
162164
}
165+
fctrl->apply_streamoff = false;
163166
break;
164167
}
168+
169+
case CAM_QUERY_CAP_V2: {
170+
struct cam_flash_query_cap_info_v2 flash_cap = {0};
171+
172+
CAM_DBG(CAM_FLASH, "CAM_QUERY_CAP_V2");
173+
flash_cap.slot_info = fctrl->soc_info.index;
174+
flash_cap.flash_type = soc_private->flash_type;
175+
flash_cap.version = 1;
176+
flash_cap.num_valid_params = 0;
177+
for (i = 0; i < fctrl->flash_num_sources; i++) {
178+
flash_cap.max_current_flash[i] =
179+
soc_private->flash_max_current[i];
180+
flash_cap.max_duration_flash[i] =
181+
soc_private->flash_max_duration[i];
182+
}
183+
184+
for (i = 0; i < fctrl->torch_num_sources; i++)
185+
flash_cap.max_current_torch[i] =
186+
soc_private->torch_max_current[i];
187+
188+
if (copy_to_user(u64_to_user_ptr(cmd->handle),
189+
&flash_cap, sizeof(struct cam_flash_query_cap_info_v2))) {
190+
CAM_ERR(CAM_FLASH, "Failed Copy to User");
191+
rc = -EFAULT;
192+
goto release_mutex;
193+
}
194+
break;
195+
}
196+
197+
165198
case CAM_START_DEV: {
166199
CAM_INFO(CAM_FLASH, "CAM_START_DEV for dev_hdl: 0x%x",
167200
fctrl->bridge_intf.device_hdl);
@@ -174,6 +207,7 @@ static int32_t cam_flash_driver_cmd(struct cam_flash_ctrl *fctrl,
174207
goto release_mutex;
175208
}
176209

210+
fctrl->apply_streamoff = false;
177211
fctrl->flash_state = CAM_FLASH_STATE_START;
178212
break;
179213
}
@@ -419,6 +453,7 @@ static int cam_flash_component_bind(struct device *dev,
419453
struct device_node *of_parent = NULL;
420454
bool i3c_i2c_target;
421455
struct platform_device *pdev = to_platform_device(dev);
456+
struct cam_hw_soc_info *soc_info = NULL;
422457

423458
CAM_DBG(CAM_FLASH, "Binding flash component");
424459
if (!pdev->dev.of_node) {
@@ -478,6 +513,15 @@ static int cam_flash_component_bind(struct device *dev,
478513
fctrl->io_master_info.cci_client->cci_device = fctrl->cci_num;
479514
CAM_DBG(CAM_FLASH, "cci-index %d", fctrl->cci_num, rc);
480515

516+
soc_info = &fctrl->soc_info;
517+
518+
rc = cam_sensor_util_init_gpio_pin_tbl(soc_info,
519+
&fctrl->power_info.gpio_num_info);
520+
if ((rc < 0) || (!fctrl->power_info.gpio_num_info)) {
521+
/* In Current target no GPIO required for flash */
522+
CAM_WARN(CAM_FLASH, "No Flash GPIOs configured");
523+
}
524+
481525
fctrl->i2c_data.per_frame =
482526
kzalloc(sizeof(struct i2c_settings_array) *
483527
MAX_PER_FRAME_ARRAY, GFP_KERNEL);
@@ -489,6 +533,7 @@ static int cam_flash_component_bind(struct device *dev,
489533

490534
INIT_LIST_HEAD(&(fctrl->i2c_data.init_settings.list_head));
491535
INIT_LIST_HEAD(&(fctrl->i2c_data.config_settings.list_head));
536+
INIT_LIST_HEAD(&(fctrl->i2c_data.streamoff_settings.list_head));
492537
for (i = 0; i < MAX_PER_FRAME_ARRAY; i++)
493538
INIT_LIST_HEAD(
494539
&(fctrl->i2c_data.per_frame[i].list_head));
@@ -497,6 +542,21 @@ static int cam_flash_component_bind(struct device *dev,
497542
fctrl->func_tbl.apply_setting = cam_flash_i2c_apply_setting;
498543
fctrl->func_tbl.power_ops = cam_flash_i2c_power_ops;
499544
fctrl->func_tbl.flush_req = cam_flash_i2c_flush_request;
545+
546+
/* Initialize regulators to default parameters */
547+
for (i = 0; i < soc_info->num_rgltr; i++) {
548+
soc_info->rgltr[i] = devm_regulator_get(soc_info->dev,
549+
soc_info->rgltr_name[i]);
550+
if (IS_ERR_OR_NULL(soc_info->rgltr[i])) {
551+
rc = PTR_ERR(soc_info->rgltr[i]);
552+
rc = rc ? rc : -EINVAL;
553+
CAM_ERR(CAM_FLASH, "Get failed for regulator %s %d",
554+
soc_info->rgltr_name[i], rc);
555+
goto free_cci_resource;
556+
}
557+
CAM_DBG(CAM_FLASH, "Get for regulator %s",
558+
soc_info->rgltr_name[i]);
559+
}
500560
} else {
501561
/* PMIC Flash */
502562
fctrl->func_tbl.parser = cam_flash_pmic_pkt_parser;
@@ -686,6 +746,7 @@ static int cam_flash_i2c_component_bind(struct device *dev,
686746

687747
INIT_LIST_HEAD(&(fctrl->i2c_data.init_settings.list_head));
688748
INIT_LIST_HEAD(&(fctrl->i2c_data.config_settings.list_head));
749+
INIT_LIST_HEAD(&(fctrl->i2c_data.streamoff_settings.list_head));
689750
for (i = 0; i < MAX_PER_FRAME_ARRAY; i++)
690751
INIT_LIST_HEAD(&(fctrl->i2c_data.per_frame[i].list_head));
691752

0 commit comments

Comments
 (0)