KillerInk / FreeDcam

FreeDcam is a CameraApp for Android >4.0(ics) wich try to enable stuff that is forgotten by the manufacturs
GNU General Public License v2.0
295 stars 44 forks source link

Raw capture on monochrome sensor on Mate 10 rooted 8.0 #124

Open Julientaming opened 3 years ago

Julientaming commented 3 years ago

Notes:

Phone Model: Huawei Mate 10 ALP-L29 8.0.0.141 rooted

FreeDcam Version: 4.3.3

Problem Description:

So, it's not really a problem but I am wondering how on Earth I could enable raw capture on the monochrome sensor ? I do have a rooted + unlocked phone, so I can access to every file, or I can flash a different rom, I don't care about other features, I just want raw on both cameras (street photographer here :) ). I know Huawei locked it in some ways but having a rooted phone, maybe there is a solution ? I also saw that the phone AGM X2 SE got the same IMX386 sensors, would it be possible to do raw on this phone ? Can't find any good review on this weird phone. If the sensor is Sony, Leica is a bit of a stretch here on Huawei, it's basically just the tiny optics ?

Kind regards,

ghost commented 3 years ago

You will probably need to reverse engineer .so files with IDA or Ghidra (camera libs), this process is pain in the ass.

Julientaming commented 3 years ago

Alright so I tried with IDA, OMG, so difficult for me, lost in thousands of lines. I tried to look at some files libdualCamera_calibration.so, android.hardware.camera.device@1.0.so, camera.kirin970.so, libdcamera_capture.so such a mess ! Some weird functions too "unLinkToDeath"

ghost commented 3 years ago

Ask help on XDA Developers there are developers that reverse engineer camera libs they can help you.

KillerInk commented 3 years ago

Hi. Normaly its not needed to have root or edit libs on cam2 devices. The oem trend is to use hidden keys and they are stored inside the apk. Pls check if you see in setting, on the right panel on bottom, a dualsensor mode. There you can switch between mono,color and dual. I know its working on p9,p10 and p20. With p30 huawei changed the api. If the dual sensor mode dont work for you, then best practise is to pull the stock camera apk and decompile it. Jadx is a nice tool to translate the dex into readable java. But it complain about the dex version mostly. Its easy to fix with a hexeditor changing dex version to 35. After that jadx can decompile the dex. Leica itself created the lens and calibrated the sensor. Good luck

Julientaming commented 3 years ago

Hi. Normaly its not needed to have root or edit libs on cam2 devices. The oem trend is to use hidden keys and they are stored inside the apk. Pls check if you see in setting, on the right panel on bottom, a dualsensor mode. There you can switch between mono,color and dual. I know its working on p9,p10 and p20. With p30 huawei changed the api. If the dual sensor mode dont work for you, then best practise is to pull the stock camera apk and decompile it. Jadx is a nice tool to translate the dex into readable java. But it complain about the dex version mostly. Its easy to fix with a hexeditor changing dex version to 35. After that jadx can decompile the dex. Leica itself created the lens and calibrated the sensor. Good luck

Hidden keys ?? I cam switch to mono or color, but I can't take any raw or full size jpg with the mono, it becomes black or freeze.I can do raw with the color one so Im guessing its deeper than that. I was thinking maybe trick the app by changing id of the sensor and invert what is the main and second camera ?

Julientaming commented 3 years ago

Ask help on XDA Developers there are developers that reverse engineer camera libs they can help you.

I will try thanks

Julientaming commented 3 years ago

oem trend ? I see a oem folder inside the app with hwcamera2.vdex and hwcamera2.odex ?

beniroquai commented 3 years ago

From my experience some features are blocked inside the ROM from Huawei. I had three different P20 Pro (for work) and all of them behaved differently. I have one which does everything. Using mono for video and RAW capturing (at full frame-size). I don't know if a rooted phone helps. It looks as if they changed their Cam API.

Julientaming commented 3 years ago

Wow so can you tell me please which rom and build number etc this p20 pro is using ? So its somewhere in the rom I will need to dive in

ghost commented 3 years ago

@Julientaming AOSP ROMs usually don't port the camera libs so I think they perform worse than stock Huawei ROMs, if I remember correctly from porting, they usually focus on making the main sensor work.

Julientaming commented 3 years ago

@Julientaming AOSP ROMs usually don't port the camera libs so I think they perform worse than stock Huawei ROMs, if I remember correctly from porting, they usually focus on making the main sensor work.

So, maybe if I delete the right lib I could unlock everything?

beniroquai commented 3 years ago

@Julientaming the Build-Number which works (so far) is the following: EMUI 9.1.0.328

Julientaming commented 3 years ago

You have access to raw mono with the stock camera app or with freedcam ?

beniroquai commented 3 years ago

With freedcam. But only a version before the recent major update. I can check once I'm back.. something from march does the trick. Also if you look into the branch cellstorm, this should also work.

On Sun, 23 Aug 2020, 15:45 Julientaming, notifications@github.com wrote:

You have access to raw mono with the stock camera app or with freedcam ?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/KillerInk/FreeDcam/issues/124#issuecomment-678776426, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABBE5OBQKHS3AXBYYKSDAILSCEMQXANCNFSM4QIGNKXA .

Julientaming commented 3 years ago

Sorry what is the branch cellstorm ? another app ? I just modified too deep lol my phone doesnt boot anymore I will need to flash it

KillerInk commented 3 years ago

Hidden keys ?? https://github.com/KillerInk/FreeDcam/blob/62b2283ccd0b5972d7f3321cdfcd817b1ff5d5bb/app/src/main/java/camera2_hidden_keys/huawei/CaptureRequestHuawei.java#L220

I cam switch to mono or color, but I can't take any raw or full size jpg with the mono

take a mono jpeg with stock cam and check the size. after that set same size inside freedcam and try it again. hopefully its then working. mono raw is offical not supported by huawei(? p9 stock cam cant capture it, only support jpeg)

So, maybe if I delete the right lib I could unlock everything?

dont delete libs, it ends in bootloop. but you can try to copy over the libs from EMUI 9.1.0.328.

Sorry what is the branch cellstorm

cellstorm is a extra module for freedcam to stream cropped rawdata. https://github.com/KillerInk/FreeDcam/tree/cellstorm

ghost commented 3 years ago

@Julientaming AOSP ROMs usually don't port the camera libs so I think they perform worse than stock Huawei ROMs, if I remember correctly from porting, they usually focus on making the main sensor work.

So, maybe if I delete the right lib I could unlock everything?

That will brick your Phone DO NOT do that, you will need to patch the libs or downgrade as someone pointed out. Also moving old libs to new Android Version probably will result in bootloop.

ghost commented 3 years ago

@Julientaming AOSP ROMs usually don't port the camera libs so I think they perform worse than stock Huawei ROMs, if I remember correctly from porting, they usually focus on making the main sensor work.

So, maybe if I delete the right lib I could unlock everything?

That will brick your Phone DO NOT do that, you will need to patch the libs or downgrade as someone pointed out. Also moving old libs to new Android Version probably will result in bootloop.

You can try using Dual Boot Patcher (https://github.com/chenxiaolong/DualBootPatcher) and install the older rom on other partition on your phone or sd and use it like that.

Julientaming commented 3 years ago

Yes too late I had to flash the stock rom again so I lost the root and its lock again :( I still have the bootloader unlock code but I cant turn on oem unlock its grey in developper options

Julientaming commented 3 years ago

Ok, I managed to unlock it again. I will try the freedcam March version

Julientaming commented 3 years ago

So with the version 4.1beta9, I can select raw with the monochrome and click on the shutter but the file is a black image in dng.

Julientaming commented 3 years ago

Sorry but I don't understand how I can add the module cellstorm to Freedcam ?

Julientaming commented 3 years ago

Hidden keys ?? https://github.com/KillerInk/FreeDcam/blob/62b2283ccd0b5972d7f3321cdfcd817b1ff5d5bb/app/src/main/java/camera2_hidden_keys/huawei/CaptureRequestHuawei.java#L220

I cam switch to mono or color, but I can't take any raw or full size jpg with the mono

take a mono jpeg with stock cam and check the size. after that set same size inside freedcam and try it again. hopefully its then working. mono raw is offical not supported by huawei(? p9 stock cam cant capture it, only support jpeg)

So, maybe if I delete the right lib I could unlock everything?

dont delete libs, it ends in bootloop. but you can try to copy over the libs from EMUI 9.1.0.328.

Sorry what is the branch cellstorm

cellstorm is a extra module for freedcam to stream cropped rawdata. https://github.com/KillerInk/FreeDcam/tree/cellstorm

How I can install this camera2_hidden_keys java?

KillerInk commented 3 years ago

Sorry but I don't understand how I can add the module cellstorm to Freedcam ?

clone the branch and build it.

How I can install this camera2_hidden_keys java?

no need to install them. they are inside the source.

So with the version 4.1beta9, I can select raw with the monochrome and click on the shutter but the file is a black image in dng.

then your emui has broken raw stream. but you can try to copy over the libs from EMUI 9.1.0.328.

Julientaming commented 3 years ago

Sorry but I don't understand how I can add the module cellstorm to Freedcam ?

clone the branch and build it.

How I can install this camera2_hidden_keys java?

no need to install them. they are inside the source.

So with the version 4.1beta9, I can select raw with the monochrome and click on the shutter but the file is a black image in dng.

then your emui has broken raw stream. but you can try to copy over the libs from EMUI 9.1.0.328.

I don't think so, it was always like that no matter which rom I have, it's a limitation on mate series and p series. It's why raw mono isn't available with the stock app. Also there isn't a 9.1.0.138 for mate 10. That's for a p20 pro. But this particular rom might have a bug and doesn't come with this limitation. How could I copy the lib if I don't have a P20 Pro?

KillerInk commented 3 years ago

Well then you are lost. About that emui version, i thought we are talking in meantime about a p20. dont copy libs from p20 to the mate. it ends in bootloop. i wouldnt say that this version is a bug. its more a correct working hal imho. all sensors can capture raw, but in your case its restricted by the overlaying software. maybe its fixable with modding the libs, but that have nothing todo with freedcam. good luck

Julientaming commented 3 years ago

I meant a bug because a "normal" p20 can't shoot raw with all cameras, just the main one. Which lib should I look into ? There are tons, like android.hardware.camera.common android.hardware.camera.device camera.device camera.kirin970 camerafactoryservice cameraserver libcamera_algo libcamera_client libcameraservice libcamera_capture libdualcamera_calibration vendor.huawei.hardware.camera.camRessource

Julientaming commented 3 years ago

So, I opened the hwcamera2.apk the stock app with android studio on my pc, I saw that in AndroidManifest.xml : <uses-feature android:name="android.hardware.camera2" android:required="false" />

<uses-feature
    android:name="android.hardware.camera.autofocus"
    android:required="false" />

<uses-feature
    android:name="android.hardware.camera.level.full"
    android:required="false" />

Should it be on true ? Is it possible to recompile the app with those values ?

KillerInk commented 3 years ago

i would look into:

if one of them is only a wrapper you have to figure out to wich lib its pointing.

search for "com.huawei.capture.metadata.dualSensorMode" and from that try to follow it to the part where streams get created. its not a easy task. and depending on your skills it could be impossible.

<uses-feature
    android:name="android.hardware.camera.autofocus"
    android:required="false" />

<uses-feature
    android:name="android.hardware.camera.level.full"
    android:required="false" />

are only feature checks what the device need to support to install the apk. front cam is most time fixed focus. most huawei devices are level 3. non of it should be true.

beniroquai commented 3 years ago

I wanted to have a look at it anyway since the newer version of freedcam does not seem to like the mono mode in the p20 anymore. I'll check it once I get back to my computer!

Julientaming commented 3 years ago

Thank you !! I will check that, also I found a function recordRawData2File(char ,char const,int) .text 00000000000F6BC4 0000011C 00000030 FFFFFFFFFFFFFFF8 R . . . . T . in libcamera_capture

Julientaming commented 3 years ago

Oh crap, I start to feel hopeless. I tried a custom rom openkirin on lineageOS 16. So no emui, same thing. Dng are empty, only jpg works in monochrome. With freedcam or the camera app included. How its possible its not the same camera lib?

ghost commented 3 years ago

Oh crap, I start to feel hopeless. I tried a custom rom openkirin on lineageOS 16. So no emui, same thing. Dng are empty, only jpg works in monochrome. With freedcam or the camera app included. How its possible its not the same camera lib?

LineageOS uses basic Camera drivers for the cameras

Julientaming commented 3 years ago

So the "stock" camera app still uses com.huawei.camera, but freedcam uses troop.com.freedcam. I will try to root it again

KillerInk commented 3 years ago

thats equal. its only the app namespace. huawei dont care about.

you can try to check if the correct raw size get set, freedcam does it here:

https://github.com/KillerInk/FreeDcam/blob/09ad4395c717bb13c524c7219554c5f82f2281c9/app/src/main/java/freed/cam/apis/camera2/modules/helper/FindOutputHelper.java#L80-L92

wich get used then here: https://github.com/KillerInk/FreeDcam/blob/09ad4395c717bb13c524c7219554c5f82f2281c9/app/src/main/java/freed/cam/apis/camera2/modules/PictureModuleApi2.java#L339

try to harcoded the values for the mono camera, if it works with the hardcoded value then u are lucky. but i tend to say its a broken rawstream

maybe a dumpsys can help you to find the correct size

adb shell dumpsys media.camera > info.txt get then saved into the folder where adb is

all the huawei stuff is based on a p9. on p9 mono and color sensor have the same size. there i have only to set the dualcamera key to mono without recreating the imagereaders. i dont remember with wich devices they started use different sensor sizes for mono and color.

beniroquai commented 3 years ago

So I tested a bit and in the very last version, everything seems to be working fine again. I had some problems with the permission manager on the P20, but manually setting it did the job in the end.

Thanks!

Julientaming commented 3 years ago

I think the 20 meg is marketing bullshit, on the specs sheet the IMX386 is 12 meg, also on the stock app, 12 meg are sharper than 20 meg mode. I think both sensors are 12 meg and Huawei did a kind of pixels binning to get a larger image. I actually found a file talking about binning somewhere. Only the aperture changed since th P9, not even sure it's a true f1.6 vs f2.2. Could you send me a raw mono from your P20 if everything works now please ?

Julientaming commented 3 years ago

thats equal. its only the app namespace. huawei dont care about.

you can try to check if the correct raw size get set, freedcam does it here:

https://github.com/KillerInk/FreeDcam/blob/09ad4395c717bb13c524c7219554c5f82f2281c9/app/src/main/java/freed/cam/apis/camera2/modules/helper/FindOutputHelper.java#L80-L92

wich get used then here: https://github.com/KillerInk/FreeDcam/blob/09ad4395c717bb13c524c7219554c5f82f2281c9/app/src/main/java/freed/cam/apis/camera2/modules/PictureModuleApi2.java#L339

try to harcoded the values for the mono camera, if it works with the hardcoded value then u are lucky. but i tend to say its a broken rawstream

maybe a dumpsys can help you to find the correct size

adb shell dumpsys media.camera > info.txt get then saved into the folder where adb is

all the huawei stuff is based on a p9. on p9 mono and color sensor have the same size. there i have only to set the dualcamera key to mono without recreating the imagereaders. i dont remember with wich devices they started use different sensor sizes for mono and color.

From the specs sheet, the resolution should be 4032 x 3016? On raw colors, the size is actually 3952x2960, which is different from the jpeg of both sensors 3968x2976. Maybe if the size 3952x2960 could be added it would work ?

Julientaming commented 3 years ago

I saw a raw monochrome from the Nokia 9 and the image is 4032x3016.

KillerInk commented 3 years ago

i dont know. you have to try. i dont have that devices. install android studio, clone freedcam, hardcode the size and be prepared for freez/crash. adb shell dumpsys media.camera > info.txt gives you mostly the needed information. feel free to attach that file. then its alot lesser guessing.

if (subsize.length > 2) { // if this is null it crash correct 
         output.raw_width = 4032; 
         output.raw_height = 3016; 
     } else { 
         output.raw_width =  4032; ; 
         output.raw_height = 3016; 
     } 

just as sample the dump from p9 https://github.com/KillerInk/FreeDcam/blob/master/Camera1Parameters/eva-09_dump.txt p20 https://github.com/KillerInk/FreeDcam/blob/master/Camera1Parameters/huawei_p20pro.txt mate9 https://github.com/KillerInk/FreeDcam/blob/master/Camera1Parameters/huawei%20mate9.txt

Julientaming commented 3 years ago

Ok I will try, thank you. If you need any file from the mate 10 tell me I can send it 😃

Julientaming commented 3 years ago

Something I don't understand, I shot raw with the color sensor, the dng size is 3952x2960 (16 pixels difference from 3968x2976), but after edit with an app (photo editor pro), the exported jpg size is 5126x3840 ??

KillerInk commented 3 years ago

there is the image with and height: 3968x2976 then there is a default crop origin: 8x8 wich removes on top,bottom,left,right 8 pixels for demosaic. so default crop size is then 3952x2960. on my dngs ps use the cropsize. no idea how you get 5126x3840

pls dump the camera and attach the file here.

adb shell dumpsys media.camera > info.txt

Julientaming commented 3 years ago

So I found out Huawei realised the source code for my phone, would it be possible to create a modified rom from that ?

Julientaming commented 3 years ago

I did the file info.txt

Julientaming commented 3 years ago

By the way, how come Freedcam is the only app to be able to access the monochrome sensor ? Any other app I tried, I can't access it, even basics rooted camera info app, tells me everything about the main sensor but nothing about the second sensor. Screenshot_20200910-081351_Device_Info_HW

Julientaming commented 3 years ago

So from the info file, I need to access to com.huawei.device.capabilities or com.huawei.capture.metadata but even rooted I can't find them

Julientaming commented 3 years ago

Also I found the imx386hybird.c file in the source code "Hisilicon K3 SOC camera driver source file" would it be possible to invert the sensors ID so I get raw on the mono and jpg on the color one ?

/* * Hisilicon K3 SOC camera driver source file * * Copyright (C) Huawei Technology Co., Ltd. * * Author: * Email: * Date: * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include "hwsensor.h" #include "sensor_commom.h" #include "hw_csi.h" #include "../pmic/hw_pmic.h" #define I2S(i) container_of(i, sensor_t, intf) #define CTL_RESET_HOLD (0) #define CTL_RESET_RELEASE (1) static struct sensor_power_setting imx386hybird_power_setting [] = { //M0 AVDD0 2.80V [LDO19] { .seq_type = SENSOR_AVDD0, .config_val = LDO_VOLTAGE_V2P8V, .sensor_index = SENSOR_INDEX_INVALID, .delay = 0, }, //M1 AVDD1 2.80V [CAM_PMIC_LDO3] { .seq_type = SENSOR_AVDD1, .config_val = LDO_VOLTAGE_V2P8V, .sensor_index = SENSOR_INDEX_INVALID, .delay = 0, }, //M1 AVDD1 1.80V [CAM_PMIC_LDO5] { .seq_type = SENSOR_PMIC, .seq_val = VOUT_LDO_5, .config_val = PMIC_1P8V, .sensor_index = SENSOR_INDEX_INVALID, .delay = 0, }, // DVDD BUCK_1 1.125v { .seq_type = SENSOR_PMIC, .seq_val = VOUT_BUCK_1, .config_val = PMIC_1P125V, // 1.125v .sensor_index = SENSOR_INDEX_INVALID, .delay = 0, }, //M0 VCM 3V [PMIC BUCK2] { .seq_type = SENSOR_PMIC, .seq_val = VOUT_BUCK_2, .config_val = PMIC_2P9V, .sensor_index = SENSOR_INDEX_INVALID, .delay = 0, }, //DRVVDD 2.85V [PMIC_LDO4] { .seq_type = SENSOR_PMIC, .seq_val = VOUT_LDO_4, .config_val = PMIC_2P85V, .sensor_index = SENSOR_INDEX_INVALID, .delay = 0, }, //M0 + M1 IOVDD 1.8V [CAM_PMIC_LDO1] { .seq_type = SENSOR_PMIC, .seq_val = VOUT_LDO_1, .config_val = LDO_VOLTAGE_1P8V, .sensor_index = SENSOR_INDEX_INVALID, .delay = 0, }, { .seq_type = SENSOR_MCLK, .sensor_index = 0, .delay = 1, }, { .seq_type = SENSOR_MCLK, .sensor_index = 2, .delay = 1, }, //M0 RESET [GPIO_018] { .seq_type = SENSOR_RST, .config_val = SENSOR_GPIO_LOW, .sensor_index = SENSOR_INDEX_INVALID, .delay = 1, }, //M1 RESET [GPIO_17] { .seq_type = SENSOR_RST2, .config_val = SENSOR_GPIO_LOW, .sensor_index = SENSOR_INDEX_INVALID, .delay = 1, }, }; static struct sensor_power_setting imx386hybird_lon_power_setting[] = { //M0 AVDD0 2.80V [LDO19] { .seq_type = SENSOR_AVDD0, .config_val = LDO_VOLTAGE_V2P8V, .sensor_index = SENSOR_INDEX_INVALID, .delay = 0, }, //M1 AVDD1 2.80V [CAM_PMIC_LDO3] { .seq_type = SENSOR_AVDD1, .config_val = LDO_VOLTAGE_V2P8V, .sensor_index = SENSOR_INDEX_INVALID, .delay = 0, }, //M1 AVDD1 1.80V [CAM_PMIC_LDO5] { .seq_type = SENSOR_PMIC, .seq_val = VOUT_LDO_5, .config_val = PMIC_1P8V, .sensor_index = SENSOR_INDEX_INVALID, .delay = 0, }, // DVDD BUCK_1 1.125v { .seq_type = SENSOR_PMIC, .seq_val = VOUT_BUCK_1, .config_val = PMIC_1P125V, // 1.125v .sensor_index = SENSOR_INDEX_INVALID, .delay = 0, }, //M0 VCM 3V [PMIC BUCK2] { .seq_type = SENSOR_PMIC, .seq_val = VOUT_BUCK_2, .config_val = PMIC_2P85V, .sensor_index = SENSOR_INDEX_INVALID, .delay = 0, }, //DRVVDD 2.85V [PMIC_LDO4] { .seq_type = SENSOR_VCM_AVDD2, .config_val = LDO_VOLTAGE_V2P85V, .sensor_index = SENSOR_INDEX_INVALID, .delay = 0, }, //M0 + M1 IOVDD 1.8V [CAM_PMIC_LDO1] { .seq_type = SENSOR_PMIC, .seq_val = VOUT_LDO_1, .config_val = LDO_VOLTAGE_1P8V, .sensor_index = SENSOR_INDEX_INVALID, .delay = 0, }, { .seq_type = SENSOR_MCLK, .sensor_index = 0, .delay = 1, }, { .seq_type = SENSOR_MCLK, .sensor_index = 2, .delay = 1, }, //M0 RESET [GPIO_018] { .seq_type = SENSOR_RST, .config_val = SENSOR_GPIO_LOW, .sensor_index = SENSOR_INDEX_INVALID, .delay = 1, }, //M1 RESET [GPIO_17] { .seq_type = SENSOR_RST2, .config_val = SENSOR_GPIO_LOW, .sensor_index = SENSOR_INDEX_INVALID, .delay = 1, }, }; // ES UDP board power up static struct sensor_power_setting imx386hybird_udp_power_setting[] = { //disable front camera reset { .seq_type = SENSOR_SUSPEND, .config_val = SENSOR_GPIO_LOW, .sensor_index = SENSOR_INDEX_INVALID, .delay = 0, }, //M0 AVDD0 2.85V [CAM_PMIC_LDO4] { .seq_type = SENSOR_PMIC, .seq_val = VOUT_LDO_4, .config_val = PMIC_2P85V, .sensor_index = SENSOR_INDEX_INVALID, .delay = 0, }, //M1 AVDD1 2.85V [CAM_PMIC_LDO2] { .seq_type = SENSOR_PMIC, .seq_val = VOUT_LDO_2, .config_val = PMIC_2P85V, .sensor_index = SENSOR_INDEX_INVALID, .delay = 0, }, //M1 AVDD1 1.80V [CAM_PMIC_LDO5] { .seq_type = SENSOR_PMIC, .seq_val = VOUT_LDO_5, .config_val = PMIC_1P8V, .sensor_index = SENSOR_INDEX_INVALID, .delay = 0, }, //MCAM IOVDD 1.80V { .seq_type = SENSOR_IOVDD, .config_val = LDO_VOLTAGE_1P8V, .sensor_index = SENSOR_INDEX_INVALID, .delay = 1, }, //MCAM0 DVDD 1.1V [LDO] { .seq_type = SENSOR_DVDD, .config_val = LDO_VOLTAGE_1P1V, .sensor_index = SENSOR_INDEX_INVALID, .delay = 0, }, //MCAM1 DVDD 1.05V [LDO] { .seq_type = SENSOR_DVDD2, .config_val = LDO_VOLTAGE_1P05V, .sensor_index = SENSOR_INDEX_INVALID, .delay = 0, }, //M0 VCM 2.8V [PMIC BUCK1] { .seq_type = SENSOR_PMIC, .seq_val = VOUT_BUCK_1, .config_val = PMIC_2P8V, .sensor_index = SENSOR_INDEX_INVALID, .delay = 0, }, //M1 VCM 2.8V [PMIC BUCK2] { .seq_type = SENSOR_PMIC, .seq_val = VOUT_BUCK_2, .config_val = PMIC_2P8V, .sensor_index = SENSOR_INDEX_INVALID, .delay = 0, }, //MCAM OISVDD 2.80V { .seq_type = SENSOR_OIS_DRV, .config_val = 2800000, .sensor_index = SENSOR_INDEX_INVALID, .delay = 0, }, { .seq_type = SENSOR_MCLK, .sensor_index = 0, .delay = 1, }, { .seq_type = SENSOR_MCLK, .sensor_index = 2, .delay = 1, }, // M0 RESET [GPIO_051] { .seq_type = SENSOR_RST, .config_val = SENSOR_GPIO_LOW, .sensor_index = SENSOR_INDEX_INVALID, .delay = 1, }, // M1 RESET [GPIO_013] { .seq_type = SENSOR_RST2, .config_val = SENSOR_GPIO_LOW, .sensor_index = SENSOR_INDEX_INVALID, .delay = 1, }, }; static struct sensor_power_setting imx386hybird_power_setting_ab [] = { //M0 OIS DRV 2.85 [ldo25] { .seq_type = SENSOR_OIS_DRV, .config_val = LDO_VOLTAGE_V2P8V, .sensor_index = SENSOR_INDEX_INVALID, .delay = 1, }, //AFVDD GPIO 004 ENABLE // Power up vcm first, then power up AVDD1 // XBUCK_AFVDD 2V55---| bucker |---> AVDD1 1V8 { .seq_type = SENSOR_VCM_PWDN, .config_val = SENSOR_GPIO_LOW, .sensor_index = SENSOR_INDEX_INVALID, .delay = 0, }, //M0+M1 IOVDD 1.8V [ld021] { .seq_type = SENSOR_IOVDD, .config_val = LDO_VOLTAGE_1P8V, .sensor_index = SENSOR_INDEX_INVALID, .delay = 0, }, //M0 AVDD0 2.8v [ldo33] { .seq_type = SENSOR_AVDD0, .config_val = LDO_VOLTAGE_V2P8V, .sensor_index = SENSOR_INDEX_INVALID, .delay = 0, }, //M1 AVDD 2.8v [ldo13] { .seq_type = SENSOR_AVDD, .config_val = LDO_VOLTAGE_V2P8V, .sensor_index = SENSOR_INDEX_INVALID, .delay = 0, }, //M1 AVDD1 gpio 008 VBUCK3(2v55) -> 1V8 { .seq_type = SENSOR_AVDD1_EN, .config_val = SENSOR_GPIO_LOW, .sensor_index = SENSOR_INDEX_INVALID, .delay = 0, }, // M0 DVDD0 [ldo19] 1v2 { .seq_type = SENSOR_DVDD, .config_val = LDO_VOLTAGE_1P13V, .sensor_index = SENSOR_INDEX_INVALID, .delay = 0, }, // M1 DVDD1 [ldo20] 1v1 { .seq_type = SENSOR_DVDD2, .config_val = LDO_VOLTAGE_1P1V, .sensor_index = SENSOR_INDEX_INVALID, .delay = 0, }, { .seq_type = SENSOR_MCLK, .sensor_index = 0, .delay = 1, }, { .seq_type = SENSOR_MCLK, .sensor_index = 2, .delay = 1, }, //M0 RESET [GPIO_013] { .seq_type = SENSOR_RST, .config_val = SENSOR_GPIO_LOW, .sensor_index = SENSOR_INDEX_INVALID, .delay = 1, }, //M1 RESET [GPIO_136] { .seq_type = SENSOR_RST2, .config_val = SENSOR_GPIO_LOW, .sensor_index = SENSOR_INDEX_INVALID, .delay = 1, }, }; static char const* imx386hybird_get_name( hwsensor_intf_t* si) { sensor_t* sensor = I2S(si); return sensor->board_info->name; } static int imx386hybird_power_up( hwsensor_intf_t* si) { int ret = 0; sensor_t* sensor = NULL; sensor = I2S(si); cam_info("enter %s. index = %d name = %s", __func__, sensor->board_info->sensor_index, sensor->board_info->name); if (hw_is_fpga_board()) { ret = do_sensor_power_on(sensor->board_info->sensor_index, sensor->board_info->name); } else { ret = hw_sensor_power_up(sensor); } if (0 == ret ) { cam_info("%s. power up sensor success.", __func__); } else { cam_err("%s. power up sensor fail.", __func__); } return ret; } static int imx386hybird_power_down( hwsensor_intf_t* si) { int ret = 0; sensor_t* sensor = NULL; sensor = I2S(si); cam_info("enter %s. index = %d name = %s", __func__, sensor->board_info->sensor_index, sensor->board_info->name); if (hw_is_fpga_board()) { ret = do_sensor_power_off(sensor->board_info->sensor_index, sensor->board_info->name); } else { ret = hw_sensor_power_down(sensor); } if (0 == ret ) { cam_info("%s. power down sensor success.", __func__); } else { cam_err("%s. power down sensor fail.", __func__); } return ret; } static int imx386hybird_csi_enable(hwsensor_intf_t* si) { return 0; } static int imx386hybird_csi_disable(hwsensor_intf_t* si) { return 0; } static int imx386hybird_match_id( hwsensor_intf_t* si, void * data) { sensor_t* sensor = I2S(si); struct sensor_cfg_data *cdata = (struct sensor_cfg_data *)data; cam_info("%s name:%s", __func__, sensor->board_info->name); strncpy(cdata->cfg.name, sensor->board_info->name, DEVICE_NAME_SIZE-1); cdata->data = sensor->board_info->sensor_index; return 0; } enum camera_metadata_enum_android_hw_dual_primary_mode{ ANDROID_HW_DUAL_PRIMARY_FIRST = 0, ANDROID_HW_DUAL_PRIMARY_SECOND = 2, ANDROID_HW_DUAL_PRIMARY_BOTH = 3, }; static int imx386hybird_do_hw_reset(hwsensor_intf_t* si, int ctl, int id) { //lint -save -e826 -e778 -e774 -e747 sensor_t* sensor = I2S(si); hwsensor_board_info_t *b_info; int ret; b_info = sensor->board_info; if (NULL == b_info) { cam_warn("%s invalid sensor board info", __func__); return 0; } ret = gpio_request(b_info->gpios[RESETB].gpio, "imx386reset-0"); ret |= gpio_request(b_info->gpios[RESETB2].gpio, "imx386reset-1"); if (ret) { cam_err("%s requeset reset pin failed", __func__); return ret; } if(CTL_RESET_HOLD == ctl) { ret |= gpio_direction_output(b_info->gpios[RESETB].gpio,CTL_RESET_HOLD); ret |= gpio_direction_output(b_info->gpios[RESETB2].gpio, CTL_RESET_HOLD); cam_info("RESETB = CTL_RESET_HOLD, RESETB2 = CTL_RESET_HOLD"); udelay(2000); } else if (CTL_RESET_RELEASE == ctl) { if(id == ANDROID_HW_DUAL_PRIMARY_FIRST) { ret |= gpio_direction_output(b_info->gpios[RESETB].gpio, CTL_RESET_RELEASE); ret |= gpio_direction_output(b_info->gpios[RESETB2].gpio, CTL_RESET_HOLD); cam_info("RESETB = CTL_RESET_RELEASE, RESETB2 = CTL_RESET_HOLD"); }else if (id == ANDROID_HW_DUAL_PRIMARY_BOTH) { ret |= gpio_direction_output(b_info->gpios[RESETB].gpio, CTL_RESET_RELEASE); ret |= gpio_direction_output(b_info->gpios[RESETB2].gpio, CTL_RESET_RELEASE); cam_info("RESETB = CTL_RESET_RELEASE, RESETB2 = CTL_RESET_RELEASE"); }else if (id == ANDROID_HW_DUAL_PRIMARY_SECOND) { ret |= gpio_direction_output(b_info->gpios[RESETB2].gpio, CTL_RESET_RELEASE); ret |= gpio_direction_output(b_info->gpios[RESETB].gpio, CTL_RESET_HOLD); cam_info("RESETB = CTL_RESET_HOLD, RESETB2 = CTL_RESET_RELEASE"); } } gpio_free(b_info->gpios[RESETB].gpio); gpio_free(b_info->gpios[RESETB2].gpio); if (ret) { cam_err("%s set reset pin failed", __func__); } else { cam_info("%s: set reset state=%d, mode=%d", __func__, ctl, id); } //lint -restore return ret; } static int imx386hybird_config( hwsensor_intf_t* si, void *argp) { struct sensor_cfg_data *data; int ret =0; if (NULL == si || NULL == argp){ cam_err("%s : si or argp is null", __func__); return -1; } data = (struct sensor_cfg_data *)argp; cam_debug("imx386hybird cfgtype = %d",data->cfgtype); switch(data->cfgtype){ case SEN_CONFIG_POWER_ON: ret = si->vtbl->power_up(si); break; case SEN_CONFIG_POWER_OFF: ret = si->vtbl->power_down(si); break; case SEN_CONFIG_WRITE_REG: break; case SEN_CONFIG_READ_REG: break; case SEN_CONFIG_WRITE_REG_SETTINGS: break; case SEN_CONFIG_READ_REG_SETTINGS: break; case SEN_CONFIG_ENABLE_CSI: break; case SEN_CONFIG_DISABLE_CSI: break; case SEN_CONFIG_MATCH_ID: ret = si->vtbl->match_id(si,argp); break; case SEN_CONFIG_RESET_HOLD: ret = imx386hybird_do_hw_reset(si, CTL_RESET_HOLD, data->mode); break; case SEN_CONFIG_RESET_RELEASE: ret = imx386hybird_do_hw_reset(si, CTL_RESET_RELEASE, data->mode); break; default: cam_err("%s cfgtype(%d) is error", __func__, data->cfgtype); break; } return ret; } static hwsensor_vtbl_t s_imx386hybird_vtbl = { .get_name = imx386hybird_get_name, .config = imx386hybird_config, .power_up = imx386hybird_power_up, .power_down = imx386hybird_power_down, .match_id = imx386hybird_match_id, .csi_enable = imx386hybird_csi_enable, .csi_disable = imx386hybird_csi_disable, }; /* individual driver data for each device */ static sensor_t s_imx386hybird = { .intf = { .vtbl = &s_imx386hybird_vtbl, }, .power_setting_array = { .size = ARRAY_SIZE(imx386hybird_power_setting), .power_setting = imx386hybird_power_setting, }, }; static sensor_t s_imx386hybird_lon = { .intf = { .vtbl = &s_imx386hybird_vtbl, }, .power_setting_array = { .size = ARRAY_SIZE(imx386hybird_lon_power_setting), .power_setting = imx386hybird_lon_power_setting, }, }; static sensor_t s_imx386hybird_udp = { .intf = { .vtbl = &s_imx386hybird_vtbl, }, .power_setting_array = { .size = ARRAY_SIZE(imx386hybird_udp_power_setting), .power_setting = imx386hybird_udp_power_setting, }, }; static sensor_t s_imx386hybird_ab = { .intf = { .vtbl = &s_imx386hybird_vtbl, }, .power_setting_array = { .size = ARRAY_SIZE(imx386hybird_power_setting_ab), .power_setting = imx386hybird_power_setting_ab, }, }; /* support both imx386hybird & imx386legacydual */ static const struct of_device_id s_imx386hybird_dt_match[] = { { .compatible = "huawei,imx386hybird", .data = &s_imx386hybird.intf, }, { .compatible = "huawei,imx386hybird_lon", .data = &s_imx386hybird_lon.intf, }, { .compatible = "huawei,imx386hybird_udp", .data = &s_imx386hybird_udp.intf, }, { .compatible = "huawei,imx386hybird_ab", .data = &s_imx386hybird_ab.intf, }, { } /* terminate list */ }; MODULE_DEVICE_TABLE(of, s_imx386hybird_dt_match); /* platform driver struct */ static int32_t imx386hybird_platform_probe(struct platform_device* pdev); static int32_t imx386hybird_platform_remove(struct platform_device* pdev); static struct platform_driver s_imx386hybird_driver = { .probe = imx386hybird_platform_probe, .remove = imx386hybird_platform_remove, .driver = { .name = "huawei,imx386hybird", .owner = THIS_MODULE, .of_match_table = s_imx386hybird_dt_match, }, }; static int32_t imx386hybird_platform_probe( struct platform_device* pdev) { int rc = 0; struct device_node *np = pdev->dev.of_node; const struct of_device_id *id; hwsensor_intf_t *intf; sensor_t *sensor; cam_info("enter %s gal",__func__); if (!np) { cam_err("%s of_node is NULL", __func__); return -ENODEV; } id = of_match_node(s_imx386hybird_dt_match, np); if (!id) { cam_err("%s none id matched", __func__); return -ENODEV; } intf = (hwsensor_intf_t*)id->data; sensor = I2S(intf); rc = hw_sensor_get_dt_data(pdev, sensor); if (rc < 0) { cam_err("%s no dt data", __func__); return -ENODEV; } sensor->dev = &pdev->dev; rc = hwsensor_register(pdev, intf); rc = rpmsg_sensor_register(pdev, (void*)sensor); return rc; } static int32_t imx386hybird_platform_remove( struct platform_device * pdev) { struct device_node *np = pdev->dev.of_node; const struct of_device_id *id; hwsensor_intf_t *intf; sensor_t *sensor; cam_info("enter %s",__func__); if (!np) { cam_info("%s of_node is NULL", __func__); return 0; } /* don't use dev->p->driver_data * we need to search again */ id = of_match_node(s_imx386hybird_dt_match, np); if (!id) { cam_info("%s none id matched", __func__); return 0; } intf = (hwsensor_intf_t*)id->data; sensor = I2S(intf); rpmsg_sensor_unregister((void*)&sensor); hwsensor_unregister(intf); return 0; } static int __init imx386hybird_init_module(void) { cam_info("enter %s",__func__); return platform_driver_probe(&s_imx386hybird_driver, imx386hybird_platform_probe); } static void __exit imx386hybird_exit_module(void) { platform_driver_unregister(&s_imx386hybird_driver); } module_init(imx386hybird_init_module); module_exit(imx386hybird_exit_module); MODULE_DESCRIPTION("imx386hybird"); MODULE_LICENSE("GPL v2");
Julientaming commented 3 years ago

Any suggestion ? I can send other files if needed

KillerInk commented 3 years ago

By the way, how come Freedcam is the only app to be able to access the monochrome sensor ? Any other app I tried, I can't access it, even basics rooted camera info app, tells me everything about the main sensor but nothing about the second sensor.

huawei use the same camera id for all back cameras. due that only the color sensor is visible by default. to switch between color/mono you must use the key com.huawei.capture.metadata.dualSensorMode

from the info.txt; color sensor:

android.sensor.info.activeArraySize (f0000): int32[4]
        [0 0 3968 2976 ]

mono sensor:

com.huawei.device.capabilities.hwSubActiveArraySize (800100c2): int32[4]
        [0 0 5120 3840 ]