Enable IFE linearization (#33852)

* enable linearization

* fixup

* gate that

---------

Co-authored-by: Comma Device <device@comma.ai>
pull/33855/head
Adeeb Shihadeh 8 months ago committed by GitHub
parent fc5f761fa8
commit fc5aed10d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 56
      system/camerad/cameras/ife.h
  2. 29
      system/camerad/cameras/spectra.cc
  3. 1
      system/camerad/cameras/spectra.h
  4. 3
      system/camerad/sensors/ox03c10.cc
  5. 3
      system/camerad/sensors/sensor.h

@ -5,6 +5,7 @@
int build_initial_config(uint8_t *dst, const SensorInfo *s, std::vector<uint32_t> &patches) {
uint64_t addr;
uint8_t *start = dst;
dst += write_random(dst, {
@ -70,6 +71,9 @@ int build_initial_config(uint8_t *dst, const SensorInfo *s, std::vector<uint32_t
0x2200297f,
0x30ff387f,
});
// TODO: this is DMI64 in the dump, does that matter?
dst += write_dmi(dst, &addr, 288, 0xc24, 9);
patches.push_back(addr - (uint64_t)start);
/* TODO
cdm_dmi_cmd_t 248
.length = 287
@ -182,7 +186,6 @@ int build_initial_config(uint8_t *dst, const SensorInfo *s, std::vector<uint32_t
dst += write_cont(dst, 0x798, {
0x00000000,
});
uint64_t addr;
dst += write_dmi(dst, &addr, 256, 0xc24, 26); // G
patches.push_back(addr - (uint64_t)start);
dst += write_dmi(dst, &addr, 256, 0xc24, 28); // B
@ -295,7 +298,7 @@ int build_initial_config(uint8_t *dst, const SensorInfo *s, std::vector<uint32_t
});
dst += write_cont(dst, 0x40, {
0x00000586,
0x00000c06,
});
dst += write_cont(dst, 0x48, {
@ -365,51 +368,6 @@ int build_first_update(uint8_t *dst) {
0x3c, 0xffffffff,
});
dst += write_cont(dst, 0x4dc, {
0x00000001,
0x04050b84,
0x13031a82,
0x22022981,
0x3100387f,
0x04010b80,
0x13001a80,
0x2200297f,
0x30ff387f,
0x04050b84,
0x13031a82,
0x22022981,
0x3100387f,
0x04010b80,
0x13001a80,
0x2200297f,
0x30ff387f,
0x04050b84,
0x13031a82,
0x22022981,
0x3100387f,
0x04010b80,
0x13001a80,
0x2200297f,
0x30ff387f,
0x04050b84,
0x13031a82,
0x22022981,
0x3100387f,
0x04010b80,
0x13001a80,
0x2200297f,
0x30ff387f,
});
/* TODO
cdm_dmi_cmd_t 184
.length = 287
.reserved = 33
.cmd = 11
.addr = 832
.DMIAddr = 3108
.DMISel = 10
*/
dst += write_cont(dst, 0x560, {
0x00000001,
0x04440444,
@ -510,7 +468,7 @@ int build_first_update(uint8_t *dst) {
});
dst += write_cont(dst, 0x40, {
0x00000444,
0x00000c06,
});
dst += write_cont(dst, 0x48, {
@ -621,7 +579,7 @@ int build_update(uint8_t *dst, const CameraConfig &cc, const SensorInfo *s, std:
});
dst += write_cont(dst, 0x40, {
0x00000c04,
0x00000c06,
});
dst += write_cont(dst, 0x48, {

@ -463,7 +463,7 @@ void SpectraCamera::config_ife(int idx, int request_id, bool init) {
* IFE = Image Front End
*/
int size = sizeof(struct cam_packet) + sizeof(struct cam_cmd_buf_desc)*2;
size += sizeof(struct cam_patch_desc)*3;
size += sizeof(struct cam_patch_desc)*4;
if (!init) {
size += sizeof(struct cam_buf_io_cfg);
}
@ -637,12 +637,19 @@ void SpectraCamera::config_ife(int idx, int request_id, bool init) {
pkt->num_patches = patches.size();
pkt->patch_offset = sizeof(struct cam_cmd_buf_desc)*pkt->num_cmd_buf + sizeof(struct cam_buf_io_cfg)*pkt->num_io_configs;
if (pkt->num_patches > 0) {
// linearization LUT
struct cam_patch_desc *patch = (struct cam_patch_desc *)((char*)&pkt->payload + pkt->patch_offset);
patch->dst_buf_hdl = ife_cmd.handle;
patch->src_buf_hdl = ife_linearization_lut.handle;
patch->dst_offset = patches[0];
patch->src_offset = 0;
// gamma LUT
for (int i = 0; i < 3; i++) {
struct cam_patch_desc *patch = (struct cam_patch_desc *)((char*)&pkt->payload + pkt->patch_offset + sizeof(cam_patch_desc)*i);
patch = (struct cam_patch_desc *)((char*)&pkt->payload + pkt->patch_offset + sizeof(cam_patch_desc)*(i+1));
patch->dst_buf_hdl = ife_cmd.handle;
patch->src_buf_hdl = ife_gamma_lut.handle;
patch->dst_offset = patches[i];
patch->dst_offset = patches[i+1];
patch->src_offset = ife_gamma_lut.size*i;
}
}
@ -857,11 +864,17 @@ void SpectraCamera::configISP() {
ife_cmd.init(m, 67984, 0x20,
CAM_MEM_FLAG_HW_READ_WRITE | CAM_MEM_FLAG_KMD_ACCESS | CAM_MEM_FLAG_UMD_ACCESS | CAM_MEM_FLAG_CMD_BUF_TYPE,
m->device_iommu, m->cdm_iommu, FRAME_BUF_COUNT);
ife_gamma_lut.init(m, 64*sizeof(uint32_t), 0x20,
CAM_MEM_FLAG_HW_READ_WRITE | CAM_MEM_FLAG_KMD_ACCESS | CAM_MEM_FLAG_UMD_ACCESS | CAM_MEM_FLAG_CMD_BUF_TYPE,
m->device_iommu, m->cdm_iommu, 3); // 3 for RGB
for (int i = 0; i < 3; i++) {
memcpy(ife_gamma_lut.ptr + ife_gamma_lut.size*i, sensor->gamma_lut_rgb.data(), ife_gamma_lut.size);
if (!is_raw) {
ife_gamma_lut.init(m, 64*sizeof(uint32_t), 0x20,
CAM_MEM_FLAG_HW_READ_WRITE | CAM_MEM_FLAG_KMD_ACCESS | CAM_MEM_FLAG_UMD_ACCESS | CAM_MEM_FLAG_CMD_BUF_TYPE,
m->device_iommu, m->cdm_iommu, 3); // 3 for RGB
for (int i = 0; i < 3; i++) {
memcpy(ife_gamma_lut.ptr + ife_gamma_lut.size*i, sensor->gamma_lut_rgb.data(), ife_gamma_lut.size);
}
ife_linearization_lut.init(m, sensor->linearization_lut.size(), 0x20,
CAM_MEM_FLAG_HW_READ_WRITE | CAM_MEM_FLAG_KMD_ACCESS | CAM_MEM_FLAG_UMD_ACCESS | CAM_MEM_FLAG_CMD_BUF_TYPE,
m->device_iommu, m->cdm_iommu);
memcpy(ife_linearization_lut.ptr, sensor->linearization_lut.data(), ife_linearization_lut.size);
}
config_ife(0, 1, true);

@ -141,6 +141,7 @@ public:
SpectraBuf ife_cmd;
SpectraBuf ife_gamma_lut;
SpectraBuf ife_linearization_lut;
SpectraBuf bps_cmd;
SpectraBuf bps_cdm_buffer;

@ -73,6 +73,9 @@ OX03C10::OX03C10() {
fx = -0.507089*exp(-12.54124638*fx) + 0.9655*pow(fx, 0.5) - 0.472597*fx + 0.507089;
gamma_lut_rgb.push_back((uint32_t)(fx*1023.0 + 0.5));
}
for (int i = 0; i < 288; i++) {
linearization_lut.push_back(0xff);
}
}
std::vector<i2c_random_wr_payload> OX03C10::getExposureRegisters(int exposure_time, int new_exp_g, bool dc_gain_enabled) const {

@ -69,7 +69,8 @@ public:
// ISP image processing params
uint32_t black_level;
std::vector<uint32_t> color_correct_matrix; // 3x3
std::vector<uint32_t> gamma_lut_rgb; // gamma LUTs are length 64 * sizeof(uint32_t); same for r/g/b here
std::vector<uint32_t> gamma_lut_rgb; // gamma LUTs are length 64 * sizeof(uint32_t); same for r/g/b here
std::vector<uint32_t> linearization_lut; // length 288
};
class AR0231 : public SensorInfo {

Loading…
Cancel
Save