int main(void) { short var = 0x1234; printf("low = %x\n", SLOW(var)); printf("low = %#x\n", SLOW(var)); printf("high = %#x\n", SHIGH(var)); printf("SSWAP = %#x\n", SSWAP(var)); return 0; }
/** sonyimx135_format_calibration_data: * @e_ctrl: address of pointer to * chromatix struct * * This function call all the sub function to read chromatix data and calibrate * the sensor * * Return: * void **/ void sonyimx135_format_calibration_data(void *e_ctrl) { SLOW("Enter"); sensor_eeprom_data_t *ectrl = (sensor_eeprom_data_t *)e_ctrl; uint8_t *data = ectrl->eeprom_params.buffer; sonyimx135_format_afdata(ectrl); sonyimx135_format_wbdata(ectrl); sonyimx135_format_lensshading(ectrl); SLOW("Exit"); }
int32_t led_flash_rer_wait_pupil_contract( rer_cfg_t *rer, module_sensor_params_t *led_module_params) { if (rer->status == RER_WAIT_PUPIL_CONTRACT) { /* Wait before to start the main flash after RER sequence */ long int delay; struct timeval ts_now, ts, ts_diff; ts = rer->last_rer_flash_ts; gettimeofday(&ts_now, NULL); timersub(&ts_now, &ts, &ts_diff); delay = (ts_diff.tv_sec * 1000000) + ts_diff.tv_usec; delay = (long int)(RER_PUPIL_CONTRACT_TIME * 1000) - delay; if (delay > 0) { /* Wait until Pupil contraction time RER_PUPIL_CONTRACT_TIME */ if (delay <= (RER_PUPIL_CONTRACT_TIME * 1000)) { SLOW("Wait %ld us to reach RER_PUPIL_CONTRACT_TIME\n", delay); usleep(delay); } else { /* Error - delay can not be bigger than RER_PUPIL_CONTRACT_TIME */ SERR("Error - RER delay out of range %d us\n", delay); } } else { /* Delay is bigger than the requested RER_PUPIL_CONTRACT_TIME */ SERR("RER Over delay %ld us (total delay %ld us)\n", -(long int)delay, (long int)(RER_PUPIL_CONTRACT_TIME * 1000) - delay); } rer->status = RER_DONE; } return SENSOR_SUCCESS; }
/** sonyimx135_format_afdata_internal: * @e_ctrl: address of pointer to * chromatix struct * @AF_START_OFFSET: start offset of page in eeprom memory * * Format Auto Focus calibration data for AF calibration * * Return: * void **/ void sonyimx135_format_afdata_internal( sensor_eeprom_data_t *e_ctrl, uint32_t AF_START_OFFSET ) { e_ctrl->eeprom_data.afc.starting_dac = (uint16_t) (((e_ctrl->eeprom_params.buffer[AF_START_OFFSET]) << 8) | (e_ctrl->eeprom_params.buffer[AF_START_OFFSET + 1])); e_ctrl->eeprom_data.afc.infinity_dac = (uint16_t)(((e_ctrl->eeprom_params.buffer[AF_START_OFFSET + 2]) << 8) | (e_ctrl->eeprom_params.buffer[AF_START_OFFSET + 3])); e_ctrl->eeprom_data.afc.macro_dac = (uint16_t)(((e_ctrl->eeprom_params.buffer[AF_START_OFFSET + 4]) << 8) | (e_ctrl->eeprom_params.buffer[AF_START_OFFSET + 5])); SLOW("AF Starting DAC = %d", e_ctrl->eeprom_data.afc.starting_dac); SLOW("AF Macro DAC = %d", e_ctrl->eeprom_data.afc.macro_dac); SLOW("AF Infinity DAC = %d", e_ctrl->eeprom_data.afc.infinity_dac); }
/** sonyimx135_print_otp_matrix: * @paramlist: address of pointer to * chromatix struct * * Prints out debug logs * * This function executes in module sensor context * * Return: * void **/ void sonyimx135_print_otp_matrix(float* paramlist) { int x =0; for( x=0; x < OTP_MESH_HWROLLOFF_SIZE; x = x+9 ){ SLOW("%.1f, %.1f, %.1f, %.1f, %.1f, %.1f, %.1f, %.1f, %.1f", paramlist[x], paramlist[x+1],paramlist[x+2], paramlist[x+3], paramlist[x+4], paramlist[x+5], paramlist[x+6], paramlist[x+7], paramlist[x+8]); } }
/** sonyimx135_format_wbdata: * @e_ctrl: address of pointer to * chromatix struct * * Checks for non empty page to calibrate sensor for Auto Focus * * Return: * void **/ static void sonyimx135_format_wbdata(sensor_eeprom_data_t *e_ctrl) { SLOW("Enter sonyimx135_format_wbdata"); bLscAwbValid = FALSE; /* Reset value before every read */ if ( PAGE_NOT_EMPTY == sonyimx135_check_awblsc_valid( &e_ctrl->eeprom_params.buffer[WB_OFFSET_L3]) ) { SLOW("Loading WB_OFFSET_L3"); sonyimx135_format_wbdata_internal(e_ctrl, WB_OFFSET_L3); } else if ( PAGE_NOT_EMPTY == sonyimx135_check_awblsc_valid( &e_ctrl->eeprom_params.buffer[WB_OFFSET_L2])){ SLOW("Loading WB_OFFSET_L2"); sonyimx135_format_wbdata_internal(e_ctrl, WB_OFFSET_L2); } else if ( PAGE_NOT_EMPTY == sonyimx135_check_awblsc_valid( &e_ctrl->eeprom_params.buffer[WB_OFFSET_L1])){ SLOW("Loading WB_OFFSET_L1"); sonyimx135_format_wbdata_internal(e_ctrl, WB_OFFSET_L1); } else if ( PAGE_NOT_EMPTY == sonyimx135_check_awblsc_valid( &e_ctrl->eeprom_params.buffer[WB_OFFSET_L0])){ SLOW("Loading WB_OFFSET_L0"); sonyimx135_format_wbdata_internal(e_ctrl, WB_OFFSET_L0); } SLOW("Exit"); }
/** sonyimx135_format_afdata_internal: * @e_ctrl: address of pointer to * chromatix struct * * Checks for non empty page to calibrate sensor for Auto Focus * This function is called by sonyimx135_format_afdata * * Return: * void **/ static void sonyimx135_format_afdata( sensor_eeprom_data_t *e_ctrl ) { SLOW("Enter"); if ( PAGE_NOT_EMPTY == sonyimx135_check_empty_page( &e_ctrl->eeprom_params.buffer[AF_OFFSET_L3]) ){ SLOW( "Loading AF_OFFSET_L3" ); sonyimx135_format_afdata_internal( e_ctrl, AF_OFFSET_L3 ); } else if ( PAGE_NOT_EMPTY == sonyimx135_check_empty_page( &e_ctrl->eeprom_params.buffer[AF_OFFSET_L2]) ){ SLOW( "Loading AF_OFFSET_L2" ); sonyimx135_format_afdata_internal(e_ctrl, AF_OFFSET_L2); } else if ( PAGE_NOT_EMPTY == sonyimx135_check_empty_page( &e_ctrl->eeprom_params.buffer[AF_OFFSET_L1]) ){ SLOW("Loading AF_OFFSET_L1"); sonyimx135_format_afdata_internal(e_ctrl, AF_OFFSET_L1); } else if ( PAGE_NOT_EMPTY == sonyimx135_check_empty_page( &e_ctrl->eeprom_params.buffer[AF_OFFSET_L0])){ SLOW("Loading AF_OFFSET_L0"); sonyimx135_format_afdata_internal(e_ctrl, AF_OFFSET_L0); } SLOW("Exit"); }
static int32_t led_flash_close(void *led_flash_ctrl) { int32_t rc = SENSOR_SUCCESS; sensor_led_flash_data_t *ctrl = (sensor_led_flash_data_t *)led_flash_ctrl; struct msm_camera_led_cfg_t cfg; SLOW("Enter"); cfg.cfgtype = MSM_CAMERA_LED_RELEASE; rc = ioctl(ctrl->fd, VIDIOC_MSM_FLASH_LED_DATA_CFG, &cfg); if (rc < 0) { SERR("VIDIOC_MSM_FLASH_LED_DATA_CFG failed %s", strerror(errno)); } /* close subdev */ close(ctrl->fd); if (ctrl->rer != NULL) { if (ctrl->rer->cfg != NULL) { /* Free rer->cfg */ free(ctrl->rer->cfg); ctrl->rer->cfg = NULL; } /* Free rer */ free(ctrl->rer); ctrl->rer = NULL; } if (ctrl->dual_led_setting != NULL) { /* Free dual_led_setting */ free(ctrl->dual_led_setting); ctrl->dual_led_setting = NULL; } free(ctrl); SLOW("Exit"); return rc; }
/*============================================================================ * FUNCTION - load_chromatix - * * DESCRIPTION: *==========================================================================*/ void *load_chromatix(void) { SLOW("chromatix ptr %p", &chromatix_ov8825_parms); return &chromatix_ov8825_parms; }
/*============================================================================ * FUNCTION - load_chromatix - * * DESCRIPTION: *==========================================================================*/ void *load_chromatix(void) { SLOW("chromatix ptr %p", &chromatix_imx214_parms); return &chromatix_imx214_parms; }
/*============================================================================ * FUNCTION - load_chromatix - * * DESCRIPTION: *==========================================================================*/ void *load_chromatix(void) { SLOW("chromatix ptr %p", &chromatix_s5k3l1yx_parms); return &chromatix_s5k3l1yx_parms; }
/*============================================================================ * FUNCTION - load_chromatix - * * DESCRIPTION: *==========================================================================*/ void *load_chromatix(void) { SLOW("chromatix ptr %p", &chromatix_ov5670_qc700_parms); return &chromatix_ov5670_qc700_parms; }
/*============================================================================ * FUNCTION - load_chromatix - * * DESCRIPTION: *==========================================================================*/ void *load_chromatix(void) { SLOW("chromatix ptr %p", &chromatix_skuf_ov12830_p12v01c_parms); return &chromatix_skuf_ov12830_p12v01c_parms; }
/** sonyimx135_format_lensshading: * @e_ctrl: address of pointer to * chromatix struct * * Loads lens shading data from the eeprom into the chromatix data * * Return: * void **/ static void sonyimx135_format_lensshading (void *e_ctrl) { sensor_eeprom_data_t *ectrl = (sensor_eeprom_data_t *)e_ctrl; uint8_t *a_r_gain, *a_gr_gain, *a_gb_gain, *a_b_gain; uint16_t i, j; uint16_t x,y; SLOW("Enter"); a_r_gain = ( uint8_t *) &(ectrl->eeprom_params.buffer[LSC_R_OFFSET]); a_gr_gain = ( uint8_t *) &(ectrl->eeprom_params.buffer[LSC_GR_OFFSET]); a_gb_gain = ( uint8_t *) &(ectrl->eeprom_params.buffer[LSC_GB_OFFSET]); a_b_gain = ( uint8_t *) &(ectrl->eeprom_params.buffer[LSC_B_OFFSET]); /* Load data from eeprom */ for (j = 0; j < OTP_MESH_HWROLLOFF_SIZE; j++) { otp_r[j] = (float) (((*a_r_gain) << 8) | (*(a_r_gain+1))); otp_gr[j] = (float) (((*a_gr_gain) << 8) | (*(a_gr_gain+1))); otp_gb[j] = (float) (((*a_gb_gain) << 8) | (*(a_gb_gain+1))); otp_b[j] = (float) (((*a_b_gain) << 8) | (*(a_b_gain+1))); a_r_gain += 4; /* R is interlaced with GR hence two increments */ a_gr_gain += 4; a_gb_gain += 4; /* B is interlaced with GB hence two increments */ a_b_gain += 4; } memset( mesh_r, 0, sizeof(mesh_r) ); memset( mesh_gr, 0, sizeof(mesh_gr) ); memset( mesh_gb, 0, sizeof(mesh_gb) ); memset( mesh_b, 0, sizeof(mesh_b) ); /* Convert 9x7 Grid to 13x10 grid for all params */ mesh_rolloff_V4_UpScaleOTPMesh_9x7to10x13(otp_r, mesh_r, SENSOR_FULL_SIZE_WIDTH, SENSOR_FULL_SIZE_HEIGHT, 56, 24); mesh_rolloff_V4_UpScaleOTPMesh_9x7to10x13(otp_gr, mesh_gr, SENSOR_FULL_SIZE_WIDTH, SENSOR_FULL_SIZE_HEIGHT, 56, 24); mesh_rolloff_V4_UpScaleOTPMesh_9x7to10x13(otp_gb, mesh_gb, SENSOR_FULL_SIZE_WIDTH, SENSOR_FULL_SIZE_HEIGHT, 56, 24); mesh_rolloff_V4_UpScaleOTPMesh_9x7to10x13(otp_b, mesh_b, SENSOR_FULL_SIZE_WIDTH, SENSOR_FULL_SIZE_HEIGHT, 56, 24); for (j = 0; j < MESH_HWROLLOFF_SIZE; j++) { ectrl->eeprom_data.lsc.lsc_calib[ROLLOFF_TL84_LIGHT].r_gain[j] = ectrl->eeprom_data.lsc.lsc_calib[ROLLOFF_A_LIGHT].r_gain[j] = ectrl->eeprom_data.lsc.lsc_calib[ROLLOFF_D65_LIGHT].r_gain[j] = mesh_r[j]; ectrl->eeprom_data.lsc.lsc_calib[ROLLOFF_TL84_LIGHT].gr_gain[j] = ectrl->eeprom_data.lsc.lsc_calib[ROLLOFF_A_LIGHT].gr_gain[j] = ectrl->eeprom_data.lsc.lsc_calib[ROLLOFF_D65_LIGHT].gr_gain[j] = mesh_gr[j]; ectrl->eeprom_data.lsc.lsc_calib[ROLLOFF_TL84_LIGHT].gb_gain[j] = ectrl->eeprom_data.lsc.lsc_calib[ROLLOFF_A_LIGHT].gb_gain[j] = ectrl->eeprom_data.lsc.lsc_calib[ROLLOFF_D65_LIGHT].gb_gain[j] = mesh_gb[j]; ectrl->eeprom_data.lsc.lsc_calib[ROLLOFF_TL84_LIGHT].b_gain[j] = ectrl->eeprom_data.lsc.lsc_calib[ROLLOFF_A_LIGHT].b_gain[j] = ectrl->eeprom_data.lsc.lsc_calib[ROLLOFF_D65_LIGHT].b_gain[j] = mesh_b[j]; } ectrl->eeprom_data.lsc.lsc_calib[ROLLOFF_TL84_LIGHT].mesh_rolloff_table_size= MESH_HWROLLOFF_SIZE; ectrl->eeprom_data.lsc.lsc_calib[ROLLOFF_A_LIGHT].mesh_rolloff_table_size= MESH_HWROLLOFF_SIZE; ectrl->eeprom_data.lsc.lsc_calib[ROLLOFF_D65_LIGHT].mesh_rolloff_table_size= MESH_HWROLLOFF_SIZE; SLOW("OTP R MATRIX") ; sonyimx135_print_otp_matrix(otp_r); SLOW("OTP GR MATRIX") ; sonyimx135_print_otp_matrix(otp_gr); SLOW("OTP GB MATRIX") ; sonyimx135_print_otp_matrix(otp_gb); SLOW("OTP B MATRIX") ; sonyimx135_print_otp_matrix(otp_b); SLOW("MESH R MATRIX"); sonyimx135_print_matrix(ectrl->eeprom_data.lsc.lsc_calib[0].r_gain); SLOW("MESH GR MATRIX"); sonyimx135_print_matrix(ectrl->eeprom_data.lsc.lsc_calib[0].gr_gain); SLOW("MESH GB MATRIX"); sonyimx135_print_matrix(ectrl->eeprom_data.lsc.lsc_calib[0].gb_gain); SLOW("MESH B MATRIX"); sonyimx135_print_matrix(ectrl->eeprom_data.lsc.lsc_calib[0].b_gain); SLOW("Exit"); }
boolean sensor_init_probe(module_sensor_ctrl_t *module_ctrl) { int32_t rc = 0, dev_fd = 0, sd_fd = 0; uint32_t i = 0; struct media_device_info mdev_info; int32_t num_media_devices = 0; char dev_name[32]; char subdev_name[32]; struct sensor_init_cfg_data cfg; boolean ret = TRUE; while (1) { int32_t num_entities = 1; snprintf(dev_name, sizeof(dev_name), "/dev/media%d", num_media_devices); dev_fd = open(dev_name, O_RDWR | O_NONBLOCK); if (dev_fd < 0) { SLOW("Done enumerating media devices"); break; } num_media_devices++; rc = ioctl(dev_fd, MEDIA_IOC_DEVICE_INFO, &mdev_info); if (rc < 0) { SLOW("Done enumerating media devices"); close(dev_fd); break; } if (strncmp(mdev_info.model, "msm_config", sizeof(mdev_info.model) != 0)) { close(dev_fd); continue; } while (1) { struct media_entity_desc entity; memset(&entity, 0, sizeof(entity)); entity.id = num_entities++; SLOW("entity id %d", entity.id); rc = ioctl(dev_fd, MEDIA_IOC_ENUM_ENTITIES, &entity); if (rc < 0) { SLOW("Done enumerating media entities"); rc = 0; break; } SLOW("entity name %s type %d group id %d", entity.name, entity.type, entity.group_id); if (entity.type == MEDIA_ENT_T_V4L2_SUBDEV && entity.group_id == MSM_CAMERA_SUBDEV_SENSOR_INIT) { snprintf(subdev_name, sizeof(dev_name), "/dev/%s", entity.name); break; } } close(dev_fd); } /* Open sensor_init subdev */ sd_fd = open(subdev_name, O_RDWR); if (sd_fd < 0) { SHIGH("Open sensor_init subdev failed"); return FALSE; } /* Open sensor libraries and get init information */ for (i = 0; i < ARRAY_SIZE(sensor_libs); i++) { ret = sensor_probe(sd_fd, sensor_libs[i]); if (ret == FALSE) { SERR("failed: to load %s", sensor_libs[i]); } } cfg.cfgtype = CFG_SINIT_PROBE_DONE; if (ioctl(sd_fd, VIDIOC_MSM_SENSOR_INIT_CFG, &cfg) < 0) { SERR("failed"); ret = FALSE; } close(sd_fd); return TRUE; }
static int32_t led_flash_open(void **led_flash_ctrl, const char *subdev_name) { int32_t rc = SENSOR_SUCCESS; sensor_led_flash_data_t *ctrl = NULL; struct msm_camera_led_cfg_t cfg; char subdev_string[32]; SLOW("Enter"); if (!led_flash_ctrl || !subdev_name) { SERR("failed sctrl %p subdev name %p", led_flash_ctrl, subdev_name); return SENSOR_ERROR_INVAL; } ctrl = malloc(sizeof(sensor_led_flash_data_t)); if (!ctrl) { SERR("failed"); return SENSOR_FAILURE; } memset(ctrl, 0, sizeof(sensor_led_flash_data_t)); snprintf(subdev_string, sizeof(subdev_string), "/dev/%s", subdev_name); SLOW("sd name %s", subdev_string); /* Open subdev */ ctrl->fd = open(subdev_string, O_RDWR); if (ctrl->fd < 0) { SERR("failed"); rc = SENSOR_FAILURE; goto ERROR1; } ctrl->rer = malloc(sizeof(rer_cfg_t)); if (!ctrl->rer) { SERR("failed"); rc = SENSOR_FAILURE; goto ERROR1; } memset(ctrl->rer, 0, sizeof(rer_cfg_t)); ctrl->rer->cfg = malloc(sizeof(red_eye_reduction_type)); if (!ctrl->rer->cfg) { SERR("failed"); rc = SENSOR_FAILURE; goto ERROR2; } memset(ctrl->rer->cfg, 0, sizeof(red_eye_reduction_type)); ctrl->dual_led_setting = malloc(sizeof(awb_dual_led_settings_t)); if (!ctrl->dual_led_setting) { SERR("failed"); rc = SENSOR_FAILURE; goto ERROR3; } memset(ctrl->dual_led_setting, 0, sizeof(awb_dual_led_settings_t)); cfg.cfgtype = MSM_CAMERA_LED_INIT; rc = ioctl(ctrl->fd, VIDIOC_MSM_FLASH_LED_DATA_CFG, &cfg); if (rc < 0) { SERR("VIDIOC_MSM_FLASH_LED_DATA_CFG failed %s", strerror(errno)); goto ERROR4; } *led_flash_ctrl = (void *)ctrl; SLOW("Exit"); return rc; ERROR4: free(ctrl->dual_led_setting); ERROR3: free(ctrl->rer->cfg); ERROR2: free(ctrl->rer); ERROR1: free(ctrl); return rc; }