GC02M1B.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791
  1. /******************************************************************************\ |* Copyright (c) 2020 by VeriSilicon Holdings Co., Ltd. ("VeriSilicon") *| |* All Rights Reserved. *| |* *| |* The material in this file is confidential and contains trade secrets of *| |* of VeriSilicon. This is proprietary information owned or licensed by *| |* VeriSilicon. No part of this work may be disclosed, reproduced, copied, *| |* transmitted, or used in any way for any purpose, without the express *| |* written permission of VeriSilicon. *| |* *|
  2. \******************************************************************************/
  3. #include <ebase/types.h>
  4. #include <ebase/trace.h>
  5. #include <ebase/builtins.h>
  6. #include <common/return_codes.h>
  7. #include <common/misc.h>
  8. #include <sys/ioctl.h>
  9. #include <fcntl.h>
  10. #include <isi/isi.h>
  11. #include <isi/isi_iss.h>
  12. #include <isi/isi_priv.h>
  13. #include <vvsensor.h>
  14. #include "GC02M1B_priv.h"
  15. #include "gc02m1b.h"
  16. CREATE_TRACER( GC02M1B_INFO , "GC02M1B: ", INFO, 0);
  17. CREATE_TRACER( GC02M1B_WARN , "GC02M1B: ", WARNING, 0);
  18. CREATE_TRACER( GC02M1B_ERROR, "GC02M1B: ", ERROR, 1);
  19. CREATE_TRACER( GC02M1B_DEBUG, "GC02M1B: ", INFO, 0);
  20. CREATE_TRACER( GC02M1B_REG_INFO , "GC02M1B: ", INFO, 0);
  21. CREATE_TRACER( GC02M1B_REG_DEBUG, "GC02M1B: ", INFO, 0);
  22. #ifdef SUBDEV_V4L2
  23. #include <sys/ioctl.h>
  24. #include <sys/mman.h>
  25. #include <fcntl.h>
  26. #include <linux/videodev2.h>
  27. #include <linux/v4l2-subdev.h>
  28. #undef TRACE
  29. #define TRACE(x, ...)
  30. #endif
  31. #define GC02M1B_MIN_GAIN_STEP ( 1.0f/16.0f ) /**< min gain step size used by GUI (hardware min = 1/16; 1/16..32/16 depending on actual gain ) */
  32. #define GC02M1B_MAX_GAIN_AEC ( 32.0f ) /**< max. gain used by the AEC (arbitrarily chosen, hardware limit = 62.0, driver limit = 32.0 ) */
  33. #define GC02M1B_VS_MAX_INTEGRATION_TIME (0.0018)
  34. /*****************************************************************************
  35. *Sensor Info
  36. *****************************************************************************/
  37. static const char SensorName[16] = "GC02M1B";
  38. static struct vvcam_mode_info pgc02m1b_mode_info[] = {
  39. {
  40. .index = 0,
  41. .width = 1600,
  42. .height = 1200,
  43. .fps = 30,
  44. .hdr_mode = SENSOR_MODE_LINEAR,
  45. .bit_width = 10,
  46. .bayer_pattern = BAYER_BGGR,
  47. .mipi_phy_freq = 672, //mbps
  48. .mipi_line_num = 1,
  49. .preg_data = (void *)"gc02m1b sensor liner mode 1600*1200@30",
  50. },
  51. };
  52. static RESULT GC02M1B_IsiRegisterWriteIss(IsiSensorHandle_t handle, const uint32_t address, const uint32_t value);
  53. static RESULT GC02M1B_IsiSensorSetPowerIss(IsiSensorHandle_t handle, bool_t on) {
  54. RESULT result = RET_SUCCESS;
  55. int ret = 0;
  56. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  57. if (pGC02M1BCtx == NULL || pGC02M1BCtx->IsiCtx.HalHandle == NULL) {
  58. return RET_NULL_POINTER;
  59. }
  60. HalContext_t *pHalCtx = (HalContext_t *) pGC02M1BCtx->IsiCtx.HalHandle;
  61. TRACE(GC02M1B_INFO, "%s (enter)\n", __func__);
  62. int32_t enable = on;
  63. ret = ioctl(pHalCtx->sensor_fd, VVSENSORIOC_S_POWER, &enable);
  64. if (ret != 0) {
  65. // to do
  66. //TRACE(GC02M1B_ERROR, "%s: sensor set power error!\n", __func__);
  67. //return (RET_FAILURE);
  68. }
  69. TRACE(GC02M1B_INFO, "%s (exit)\n", __func__);
  70. return (result);
  71. }
  72. static RESULT GC02M1B_IsiResetSensorIss(IsiSensorHandle_t handle) {
  73. RESULT result = RET_SUCCESS;
  74. int ret = 0;
  75. TRACE(GC02M1B_INFO, "%s (enter)\n", __func__);
  76. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  77. if (pGC02M1BCtx == NULL || pGC02M1BCtx->IsiCtx.HalHandle == NULL) {
  78. return RET_NULL_POINTER;
  79. }
  80. HalContext_t *pHalCtx = (HalContext_t *) pGC02M1BCtx->IsiCtx.HalHandle;
  81. ret = ioctl(pHalCtx->sensor_fd, VVSENSORIOC_RESET, NULL);
  82. if (ret != 0) {
  83. TRACE(GC02M1B_ERROR, "%s: sensor reset error!\n", __func__);
  84. return (RET_FAILURE);
  85. }
  86. TRACE(GC02M1B_INFO, "%s (exit)\n", __func__);
  87. return (result);
  88. }
  89. #ifdef SUBDEV_CHAR
  90. static RESULT GC02M1B_IsiSensorSetClkIss(IsiSensorHandle_t handle, uint32_t clk) {
  91. RESULT result = RET_SUCCESS;
  92. int32_t ret = 0;
  93. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  94. if (pGC02M1BCtx == NULL || pGC02M1BCtx->IsiCtx.HalHandle == NULL) {
  95. return RET_NULL_POINTER;
  96. }
  97. HalContext_t *pHalCtx = (HalContext_t *) pGC02M1BCtx->IsiCtx.HalHandle;
  98. TRACE(GC02M1B_INFO, "%s (enter)\n", __func__);
  99. ret = ioctl(pHalCtx->sensor_fd, VVSENSORIOC_S_CLK, &clk);
  100. if (ret != 0) {
  101. // to do
  102. //TRACE(GC02M1B_ERROR, "%s: sensor set clk error!\n", __func__);
  103. //return (RET_FAILURE);
  104. }
  105. TRACE(GC02M1B_INFO, "%s (exit)\n", __func__);
  106. return (result);
  107. }
  108. static RESULT GC02M1B_IsiSensorGetClkIss
  109. (IsiSensorHandle_t handle, uint32_t * pclk) {
  110. RESULT result = RET_SUCCESS;
  111. int ret = 0;
  112. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  113. if (pGC02M1BCtx == NULL || pGC02M1BCtx->IsiCtx.HalHandle == NULL) {
  114. return RET_NULL_POINTER;
  115. }
  116. HalContext_t *pHalCtx = (HalContext_t *) pGC02M1BCtx->IsiCtx.HalHandle;
  117. TRACE(GC02M1B_INFO, "%s (enter)\n", __func__);
  118. ret = ioctl(pHalCtx->sensor_fd, VVSENSORIOC_G_CLK, pclk);
  119. if (ret != 0) {
  120. // to do
  121. //TRACE(GC02M1B_ERROR, "%s: sensor get clk error!\n", __func__);
  122. //return (RET_FAILURE);
  123. }
  124. TRACE(GC02M1B_INFO, "%s (exit)\n", __func__);
  125. return (result);
  126. }
  127. static RESULT GC02M1B_IsiConfigSensorSCCBIss(IsiSensorHandle_t handle)
  128. {
  129. return RET_SUCCESS;
  130. }
  131. #endif
  132. static RESULT GC02M1B_IsiRegisterReadIss
  133. (IsiSensorHandle_t handle, const uint32_t address, uint32_t * p_value) {
  134. RESULT result = RET_SUCCESS;
  135. int32_t ret = 0;
  136. TRACE(GC02M1B_INFO, "%s (enter)\n", __func__);
  137. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  138. if (pGC02M1BCtx == NULL || pGC02M1BCtx->IsiCtx.HalHandle == NULL) {
  139. return RET_NULL_POINTER;
  140. }
  141. HalContext_t *pHalCtx = (HalContext_t *) pGC02M1BCtx->IsiCtx.HalHandle;
  142. struct vvcam_sccb_data sccb_data;
  143. sccb_data.addr = address;
  144. sccb_data.data = 0;
  145. ret = ioctl(pHalCtx->sensor_fd, VVSENSORIOC_READ_REG, &sccb_data);
  146. if (ret != 0) {
  147. TRACE(GC02M1B_ERROR, "%s: read sensor register error!\n",
  148. __func__);
  149. return (RET_FAILURE);
  150. }
  151. *p_value = sccb_data.data;
  152. TRACE(GC02M1B_INFO, "%s (exit) result = %d\n", __func__, result);
  153. return (result);
  154. }
  155. static RESULT GC02M1B_IsiRegisterWriteIss
  156. (IsiSensorHandle_t handle, const uint32_t address, const uint32_t value) {
  157. RESULT result = RET_SUCCESS;
  158. int ret = 0;
  159. TRACE(GC02M1B_INFO, "%s (enter)\n", __func__);
  160. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  161. if (pGC02M1BCtx == NULL || pGC02M1BCtx->IsiCtx.HalHandle == NULL) {
  162. return RET_NULL_POINTER;
  163. }
  164. HalContext_t *pHalCtx = (HalContext_t *) pGC02M1BCtx->IsiCtx.HalHandle;
  165. struct vvcam_sccb_data sccb_data;
  166. sccb_data.addr = address;
  167. sccb_data.data = value;
  168. ret = ioctl(pHalCtx->sensor_fd, VVSENSORIOC_WRITE_REG, &sccb_data);
  169. if (ret != 0) {
  170. TRACE(GC02M1B_ERROR, "%s: write sensor register error!\n",
  171. __func__);
  172. return (RET_FAILURE);
  173. }
  174. TRACE(GC02M1B_INFO, "%s (exit) result = %d\n", __func__, result);
  175. return (result);
  176. }
  177. static RESULT GC02M1B_IsiQuerySensorSupportIss(HalHandle_t HalHandle, vvcam_mode_info_array_t *pSensorSupportInfo)
  178. {
  179. TRACE(GC02M1B_DEBUG, "enter %s", __func__);
  180. //int ret = 0;
  181. struct vvcam_mode_info_array *psensor_mode_info_arry;
  182. HalContext_t *pHalCtx = HalHandle;
  183. if ( pHalCtx == NULL ) {
  184. return RET_NULL_POINTER;
  185. }
  186. psensor_mode_info_arry = pSensorSupportInfo;
  187. #if 0
  188. ret = ioctl(pHalCtx->sensor_fd, VVSENSORIOC_QUERY, psensor_mode_info_arry);
  189. if (ret != 0) {
  190. TRACE(GC02M1B_ERROR, "%s: sensor kernel query error! Use isi query\n",__func__);
  191. psensor_mode_info_arry->count = sizeof(pgc02m1b_mode_info) / sizeof(struct vvcam_mode_info);
  192. memcpy(psensor_mode_info_arry->modes, pgc02m1b_mode_info, sizeof(pgc02m1b_mode_info));
  193. }
  194. #endif
  195. psensor_mode_info_arry->count = sizeof(pgc02m1b_mode_info) / sizeof(struct vvcam_mode_info);
  196. memcpy(psensor_mode_info_arry->modes, pgc02m1b_mode_info, sizeof(pgc02m1b_mode_info));
  197. TRACE(GC02M1B_DEBUG, "%s-%s-%d: cnt=%d\n", __FILE__, __func__, __LINE__, psensor_mode_info_arry->count);
  198. return RET_SUCCESS;
  199. }
  200. static RESULT GC02M1B_IsiQuerySensorIss(IsiSensorHandle_t handle, vvcam_mode_info_array_t *pSensorInfo)
  201. {
  202. RESULT result = RET_SUCCESS;
  203. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  204. if (pGC02M1BCtx == NULL || pGC02M1BCtx->IsiCtx.HalHandle == NULL) {
  205. return RET_NULL_POINTER;
  206. }
  207. HalContext_t *pHalCtx = (HalContext_t *) pGC02M1BCtx->IsiCtx.HalHandle;
  208. GC02M1B_IsiQuerySensorSupportIss(pHalCtx,pSensorInfo);
  209. return result;
  210. }
  211. static RESULT GC02M1B_IsiGetSensorModeIss(IsiSensorHandle_t handle,void *mode)
  212. {
  213. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  214. if (pGC02M1BCtx == NULL) {
  215. return (RET_WRONG_HANDLE);
  216. }
  217. memcpy(mode,&(pGC02M1BCtx->SensorMode), sizeof(pGC02M1BCtx->SensorMode));
  218. return ( RET_SUCCESS );
  219. }
  220. static RESULT GC02M1B_IsiCreateSensorIss(IsiSensorInstanceConfig_t * pConfig) {
  221. RESULT result = RET_SUCCESS;
  222. GC02M1B_Context_t *pGC02M1BCtx;
  223. TRACE(GC02M1B_INFO, "%s (enter)\n", __func__);
  224. if (!pConfig || !pConfig->pSensor)
  225. return (RET_NULL_POINTER);
  226. pGC02M1BCtx = (GC02M1B_Context_t *) malloc(sizeof(GC02M1B_Context_t));
  227. if (!pGC02M1BCtx) {
  228. TRACE(GC02M1B_ERROR, "%s: Can't allocate gc02m1b context\n",
  229. __func__);
  230. return (RET_OUTOFMEM);
  231. }
  232. MEMSET(pGC02M1BCtx, 0, sizeof(GC02M1B_Context_t));
  233. result = HalAddRef(pConfig->HalHandle);
  234. if (result != RET_SUCCESS) {
  235. free(pGC02M1BCtx);
  236. return (result);
  237. }
  238. pGC02M1BCtx->IsiCtx.HalHandle = pConfig->HalHandle;
  239. pGC02M1BCtx->IsiCtx.pSensor = pConfig->pSensor;
  240. pGC02M1BCtx->GroupHold = BOOL_FALSE;
  241. pGC02M1BCtx->OldGain = 0;
  242. pGC02M1BCtx->OldIntegrationTime = 0;
  243. pGC02M1BCtx->Configured = BOOL_FALSE;
  244. pGC02M1BCtx->Streaming = BOOL_FALSE;
  245. pGC02M1BCtx->TestPattern = BOOL_FALSE;
  246. pGC02M1BCtx->isAfpsRun = BOOL_FALSE;
  247. pGC02M1BCtx->SensorMode.index = pConfig->SensorModeIndex;
  248. pConfig->hSensor = (IsiSensorHandle_t) pGC02M1BCtx;
  249. #ifdef SUBDEV_CHAR
  250. struct vvcam_mode_info *SensorDefaultMode = NULL;
  251. for (int i=0; i < sizeof(pgc02m1b_mode_info)/ sizeof(struct vvcam_mode_info); i++)
  252. {
  253. if (pgc02m1b_mode_info[i].index == pGC02M1BCtx->SensorMode.index)
  254. {
  255. SensorDefaultMode = &(pgc02m1b_mode_info[i]);
  256. break;
  257. }
  258. }
  259. if (SensorDefaultMode != NULL)
  260. {
  261. strcpy(pGC02M1BCtx->SensorRegCfgFile, get_vi_config_path());
  262. switch(SensorDefaultMode->index)
  263. {
  264. case 0:
  265. strcat(pGC02M1BCtx->SensorRegCfgFile,
  266. "GC02M1B_mipi1lane_1600x1200@30_mayi.txt");
  267. break;
  268. default:
  269. break;
  270. }
  271. if (access(pGC02M1BCtx->SensorRegCfgFile, F_OK) == 0) {
  272. pGC02M1BCtx->KernelDriverFlag = 0;
  273. memcpy(&(pGC02M1BCtx->SensorMode),SensorDefaultMode,sizeof(struct vvcam_mode_info));
  274. } else {
  275. pGC02M1BCtx->KernelDriverFlag = 1;
  276. }
  277. }else
  278. {
  279. pGC02M1BCtx->KernelDriverFlag = 1;
  280. }
  281. result = GC02M1B_IsiSensorSetPowerIss(pGC02M1BCtx, BOOL_TRUE);
  282. RETURN_RESULT_IF_DIFFERENT(RET_SUCCESS, result);
  283. uint32_t SensorClkIn = 0;
  284. if (pGC02M1BCtx->KernelDriverFlag) {
  285. result = GC02M1B_IsiSensorGetClkIss(pGC02M1BCtx, &SensorClkIn);
  286. RETURN_RESULT_IF_DIFFERENT(RET_SUCCESS, result);
  287. }
  288. result = GC02M1B_IsiSensorSetClkIss(pGC02M1BCtx, SensorClkIn);
  289. RETURN_RESULT_IF_DIFFERENT(RET_SUCCESS, result);
  290. result = GC02M1B_IsiResetSensorIss(pGC02M1BCtx);
  291. RETURN_RESULT_IF_DIFFERENT(RET_SUCCESS, result);
  292. pGC02M1BCtx->pattern = ISI_BPAT_BGBGGRGR;
  293. if (!pGC02M1BCtx->KernelDriverFlag) {
  294. result = GC02M1B_IsiConfigSensorSCCBIss(pGC02M1BCtx);
  295. RETURN_RESULT_IF_DIFFERENT(RET_SUCCESS, result);
  296. }
  297. #endif
  298. TRACE(GC02M1B_INFO, "%s (exit pConfig->hSensor = %p)\n", __func__, pConfig->hSensor);
  299. return (result);
  300. }
  301. static RESULT GC02M1B_IsiGetRegCfgIss(const char *registerFileName,
  302. struct vvcam_sccb_array *arry)
  303. {
  304. if (NULL == registerFileName) {
  305. TRACE(GC02M1B_ERROR, "%s:registerFileName is NULL\n", __func__);
  306. return (RET_NULL_POINTER);
  307. }
  308. #ifdef SUBDEV_CHAR
  309. FILE *fp = NULL;
  310. fp = fopen(registerFileName, "rb");
  311. if (!fp) {
  312. TRACE(GC02M1B_ERROR, "%s:load register file %s error!\n",
  313. __func__, registerFileName);
  314. return (RET_FAILURE);
  315. }
  316. char LineBuf[512];
  317. uint32_t FileTotalLine = 0;
  318. while (!feof(fp)) {
  319. fgets(LineBuf, 512, fp);
  320. FileTotalLine++;
  321. }
  322. arry->sccb_data =
  323. malloc(FileTotalLine * sizeof(struct vvcam_sccb_data));
  324. if (arry->sccb_data == NULL) {
  325. TRACE(GC02M1B_ERROR, "%s:malloc failed NULL Point!\n", __func__,
  326. registerFileName);
  327. return (RET_FAILURE);
  328. }
  329. rewind(fp);
  330. arry->count = 0;
  331. while (!feof(fp)) {
  332. memset(LineBuf, 0, sizeof(LineBuf));
  333. fgets(LineBuf, 512, fp);
  334. int result =
  335. sscanf(LineBuf, "0x%x 0x%x",
  336. &(arry->sccb_data[arry->count].addr),
  337. &(arry->sccb_data[arry->count].data));
  338. if (result != 2)
  339. continue;
  340. arry->count++;
  341. }
  342. #endif
  343. return 0;
  344. }
  345. static RESULT GC02M1B_IsiInitSensorIss(IsiSensorHandle_t handle) {
  346. RESULT result = RET_SUCCESS;
  347. int ret = 0;
  348. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  349. HalContext_t *pHalCtx = (HalContext_t *) pGC02M1BCtx->IsiCtx.HalHandle;
  350. TRACE(GC02M1B_INFO, "%s (enter handle = %p)\n", __func__, handle);
  351. if (pGC02M1BCtx == NULL) {
  352. return (RET_WRONG_HANDLE);
  353. }
  354. TRACE(GC02M1B_INFO, "%s (pGC02M1BCtx->KernelDriverFlag = %d)\n", __func__, pGC02M1BCtx->KernelDriverFlag);
  355. if (pGC02M1BCtx->KernelDriverFlag) {
  356. ;
  357. } else {
  358. TRACE(GC02M1B_INFO, "%s (001)\n", __func__);
  359. struct vvcam_sccb_array arry;
  360. result = GC02M1B_IsiGetRegCfgIss(pGC02M1BCtx->SensorRegCfgFile, &arry);
  361. if (result != 0) {
  362. TRACE(GC02M1B_ERROR,
  363. "%s:GC02M1B_IsiGetRegCfgIss error!\n", __func__);
  364. return (RET_FAILURE);
  365. }
  366. ret = ioctl(pHalCtx->sensor_fd, VVSENSORIOC_WRITE_ARRAY, &arry);
  367. if (ret != 0) {
  368. TRACE(GC02M1B_ERROR, "%s:Sensor Write Reg arry error!\n",
  369. __func__);
  370. return (RET_FAILURE);
  371. }
  372. TRACE(GC02M1B_INFO, "%s (pGC02M1BCtx->SensorMode.index = %d)\n", __func__, pGC02M1BCtx->SensorMode.index);
  373. switch(pGC02M1BCtx->SensorMode.index)
  374. {
  375. case 0:
  376. pGC02M1BCtx->one_line_exp_time = 0.00002609; // line_time = line_length / pclk =1460/87.6mhz = 0.0000167
  377. pGC02M1BCtx->FrameLengthLines = 0x4FE; //framelength=1278=0x4FE
  378. pGC02M1BCtx->CurFrameLengthLines = pGC02M1BCtx->FrameLengthLines;
  379. pGC02M1BCtx->MaxIntegrationLine = pGC02M1BCtx->CurFrameLengthLines - 16;
  380. pGC02M1BCtx->MinIntegrationLine = 1;
  381. pGC02M1BCtx->AecMaxGain = 16;
  382. pGC02M1BCtx->AecMinGain = 1;
  383. break;
  384. default:
  385. return (RET_FAILURE);
  386. }
  387. pGC02M1BCtx->AecIntegrationTimeIncrement = pGC02M1BCtx->one_line_exp_time;
  388. pGC02M1BCtx->AecMinIntegrationTime =
  389. pGC02M1BCtx->one_line_exp_time * pGC02M1BCtx->MinIntegrationLine;
  390. pGC02M1BCtx->AecMaxIntegrationTime =
  391. pGC02M1BCtx->one_line_exp_time * pGC02M1BCtx->MaxIntegrationLine;
  392. pGC02M1BCtx->MaxFps = pGC02M1BCtx->SensorMode.fps;
  393. pGC02M1BCtx->MinFps = 1;
  394. pGC02M1BCtx->CurrFps = pGC02M1BCtx->MaxFps;
  395. }
  396. TRACE(GC02M1B_INFO, "%s (pGC02M1BCtx->one_line_exp_time = %f)\n", __func__, pGC02M1BCtx->one_line_exp_time);
  397. TRACE(GC02M1B_INFO, "%s (pGC02M1BCtx->MinIntegrationLine = %d, pGC02M1BCtx->MaxIntegrationLine = %d)\n", __func__, pGC02M1BCtx->MinIntegrationLine, pGC02M1BCtx->MaxIntegrationLine);
  398. return (result);
  399. }
  400. static RESULT GC02M1B_IsiReleaseSensorIss(IsiSensorHandle_t handle) {
  401. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  402. RESULT result = RET_SUCCESS;
  403. TRACE(GC02M1B_INFO, "%s (enter)\n", __func__);
  404. if (pGC02M1BCtx == NULL)
  405. return (RET_WRONG_HANDLE);
  406. (void)GC02M1B_IsiSensorSetStreamingIss(pGC02M1BCtx, BOOL_FALSE);
  407. (void)GC02M1B_IsiSensorSetPowerIss(pGC02M1BCtx, BOOL_FALSE);
  408. (void)HalDelRef(pGC02M1BCtx->IsiCtx.HalHandle);
  409. MEMSET(pGC02M1BCtx, 0, sizeof(GC02M1B_Context_t));
  410. free(pGC02M1BCtx);
  411. TRACE(GC02M1B_INFO, "%s (exit)\n", __func__);
  412. return (result);
  413. }
  414. struct gc02m1b_fmt {
  415. int width;
  416. int height;
  417. int fps;
  418. };
  419. static RESULT GC02M1B_IsiSetupSensorIss
  420. (IsiSensorHandle_t handle, const IsiSensorConfig_t * pConfig) {
  421. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  422. HalContext_t *pHalCtx = (HalContext_t *) pGC02M1BCtx->IsiCtx.HalHandle;
  423. RESULT result = RET_SUCCESS;
  424. TRACE(GC02M1B_INFO, "%s: (enter)\n", __func__);
  425. if (!pGC02M1BCtx) {
  426. TRACE(GC02M1B_ERROR,
  427. "%s: Invalid sensor handle (NULL pointer detected)\n",
  428. __func__);
  429. return (RET_WRONG_HANDLE);
  430. }
  431. if (!pConfig) {
  432. TRACE(GC02M1B_ERROR,
  433. "%s: Invalid configuration (NULL pointer detected)\n",
  434. __func__);
  435. return (RET_NULL_POINTER);
  436. }
  437. if (pGC02M1BCtx->Streaming != BOOL_FALSE) {
  438. return RET_WRONG_STATE;
  439. }
  440. memcpy(&pGC02M1BCtx->Config, pConfig, sizeof(IsiSensorConfig_t));
  441. /* 1.) SW reset of image sensor (via I2C register interface) be careful, bits 6..0 are reserved, reset bit is not sticky */
  442. TRACE(GC02M1B_DEBUG, "%s: GC02M1B System-Reset executed\n", __func__);
  443. osSleep(100);
  444. //GC02M1B_AecSetModeParameters not defined yet as of 2021/8/9.
  445. //result = GC02M1B_AecSetModeParameters(pGC02M1BCtx, pConfig);
  446. //if (result != RET_SUCCESS) {
  447. // TRACE(GC02M1B_ERROR, "%s: SetupOutputWindow failed.\n",
  448. // __func__);
  449. // return (result);
  450. //}
  451. #if 1
  452. struct gc02m1b_fmt fmt;
  453. fmt.width = pConfig->Resolution.width;
  454. fmt.height = pConfig->Resolution.height;
  455. ioctl(pHalCtx->sensor_fd, VVSENSORIOC_S_FPS, &fmt);//result = ioctl(pHalCtx->sensor_fd, VVSENSORIOC_S_FPS, &fmt);
  456. #endif
  457. pGC02M1BCtx->Configured = BOOL_TRUE;
  458. TRACE(GC02M1B_INFO, "%s: (exit) ret=0x%x \n", __func__, result);
  459. return result;
  460. }
  461. static RESULT GC02M1B_IsiChangeSensorResolutionIss(IsiSensorHandle_t handle, uint16_t width, uint16_t height) {
  462. RESULT result = RET_SUCCESS;
  463. #if 0
  464. struct gc02m1b_fmt fmt;
  465. fmt.width = width;
  466. fmt.height = height;
  467. int ret = ioctl(pHalCtx->sensor_fd, VVSENSORIOC_S_FPS, &fmt);
  468. #endif
  469. TRACE(GC02M1B_INFO, "%s (exit)\n", __func__);
  470. return (result);
  471. }
  472. static RESULT GC02M1B_IsiSensorSetStreamingIss
  473. (IsiSensorHandle_t handle, bool_t on) {
  474. RESULT result = RET_SUCCESS;
  475. int ret = 0;
  476. TRACE(GC02M1B_INFO, "%s (enter)\n", __func__);
  477. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  478. if (pGC02M1BCtx == NULL || pGC02M1BCtx->IsiCtx.HalHandle == NULL) {
  479. return RET_NULL_POINTER;
  480. }
  481. HalContext_t *pHalCtx = (HalContext_t *) pGC02M1BCtx->IsiCtx.HalHandle;
  482. if (pGC02M1BCtx->Configured != BOOL_TRUE)
  483. return RET_WRONG_STATE;
  484. int32_t enable = (uint32_t) on;
  485. ret = GC02M1B_IsiRegisterWriteIss(handle, 0xfe, 0x00);
  486. if (ret != 0) {
  487. return (RET_FAILURE);
  488. }
  489. if (on == true) {
  490. ret = GC02M1B_IsiRegisterWriteIss(handle, 0x3e, 0x90);
  491. } else {
  492. ret = GC02M1B_IsiRegisterWriteIss(handle, 0x3e, 0x00);
  493. }
  494. if (ret != 0) {
  495. return (RET_FAILURE);
  496. }
  497. pGC02M1BCtx->Streaming = on;
  498. TRACE(GC02M1B_INFO, "%s (exit)\n", __func__);
  499. return (result);
  500. }
  501. static int32_t sensor_get_chip_id(IsiSensorHandle_t handle, uint32_t *chip_id)
  502. {
  503. RESULT result = RET_SUCCESS;
  504. int32_t ret = 0;
  505. int32_t chip_id_high = 0;
  506. int32_t chip_id_low = 0;
  507. ret = GC02M1B_IsiRegisterReadIss(handle, 0xf0, &chip_id_high);
  508. if (ret != 0) {
  509. TRACE(GC02M1B_ERROR,
  510. "%s: Read Sensor correct ID Error! \n", __func__);
  511. return (RET_FAILURE);
  512. }
  513. ret = GC02M1B_IsiRegisterReadIss(handle, 0xf1, &chip_id_low);
  514. if (ret != 0) {
  515. TRACE(GC02M1B_ERROR,
  516. "%s: Read Sensor correct ID Error! \n", __func__);
  517. return (RET_FAILURE);
  518. }
  519. *chip_id = ((chip_id_high & 0xff)<<8) | (chip_id_low & 0xff);
  520. return 0;
  521. }
  522. static RESULT GC02M1B_IsiCheckSensorConnectionIss(IsiSensorHandle_t handle) {
  523. RESULT result = RET_SUCCESS;
  524. int ret = 0;
  525. uint32_t correct_id = 0x02e0;
  526. uint32_t sensor_id = 0;
  527. TRACE(GC02M1B_INFO, "%s (enter)\n", __func__);
  528. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  529. if (pGC02M1BCtx == NULL || pGC02M1BCtx->IsiCtx.HalHandle == NULL) {
  530. return RET_NULL_POINTER;
  531. }
  532. HalContext_t *pHalCtx = (HalContext_t *) pGC02M1BCtx->IsiCtx.HalHandle;
  533. ret = sensor_get_chip_id(handle, &sensor_id);
  534. if (ret != 0) {
  535. TRACE(GC02M1B_ERROR,
  536. "%s: Read Sensor chip ID Error! \n", __func__);
  537. return (RET_FAILURE);
  538. }
  539. if (correct_id != sensor_id) {
  540. TRACE(GC02M1B_ERROR, "%s:ChipID =0x%x sensor_id=%x error! \n",
  541. __func__, correct_id, sensor_id);
  542. return (RET_FAILURE);
  543. }
  544. printf("%s ChipID = 0x%08x, sensor_id = 0x%08x, success! \n", __func__,
  545. correct_id, sensor_id);
  546. TRACE(GC02M1B_INFO, "%s (exit)\n", __func__);
  547. return (result);
  548. }
  549. static RESULT GC02M1B_IsiGetSensorRevisionIss
  550. (IsiSensorHandle_t handle, uint32_t * p_value) {
  551. RESULT result = RET_SUCCESS;
  552. TRACE(GC02M1B_INFO, "%s (enter)\n", __func__);
  553. *p_value = 0X5690;
  554. TRACE(GC02M1B_INFO, "%s (exit)\n", __func__);
  555. return (result);
  556. }
  557. static RESULT GC02M1B_IsiGetGainLimitsIss
  558. (IsiSensorHandle_t handle, float *pMinGain, float *pMaxGain) {
  559. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  560. RESULT result = RET_SUCCESS;
  561. /*TODO*/
  562. TRACE(GC02M1B_INFO, "%s: (enter)\n", __func__);
  563. if (pGC02M1BCtx == NULL) {
  564. TRACE(GC02M1B_ERROR,
  565. "%s: Invalid sensor handle (NULL pointer detected)\n",
  566. __func__);
  567. return (RET_WRONG_HANDLE);
  568. }
  569. if ((pMinGain == NULL) || (pMaxGain == NULL)) {
  570. TRACE(GC02M1B_ERROR, "%s: NULL pointer received!!\n");
  571. return (RET_NULL_POINTER);
  572. }
  573. *pMinGain = pGC02M1BCtx->AecMinGain;
  574. *pMaxGain = pGC02M1BCtx->AecMaxGain;
  575. TRACE(GC02M1B_INFO, "%s: (exit)\n", __func__);
  576. return (result);
  577. }
  578. static RESULT GC02M1B_IsiGetIntegrationTimeLimitsIss
  579. (IsiSensorHandle_t handle,
  580. float *pMinIntegrationTime, float *pMaxIntegrationTime) {
  581. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  582. RESULT result = RET_SUCCESS;
  583. /*TODO*/
  584. TRACE(GC02M1B_INFO, "%s: (enter)\n", __func__);
  585. if (pGC02M1BCtx == NULL) {
  586. TRACE(GC02M1B_ERROR,
  587. "%s: Invalid sensor handle (NULL pointer detected)\n",
  588. __func__);
  589. return (RET_WRONG_HANDLE);
  590. }
  591. if ((pMinIntegrationTime == NULL) || (pMaxIntegrationTime == NULL)) {
  592. TRACE(GC02M1B_ERROR, "%s: NULL pointer received!!\n");
  593. return (RET_NULL_POINTER);
  594. }
  595. *pMinIntegrationTime = pGC02M1BCtx->AecMinIntegrationTime;
  596. *pMaxIntegrationTime = pGC02M1BCtx->AecMaxIntegrationTime;
  597. TRACE(GC02M1B_INFO, "%s: (exit)\n", __func__);
  598. return (result);
  599. }
  600. RESULT GC02M1B_IsiGetGainIss(IsiSensorHandle_t handle, float *pSetGain) {
  601. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  602. RESULT result = RET_SUCCESS;
  603. TRACE(GC02M1B_INFO, "%s: (enter)\n", __func__);
  604. if (pGC02M1BCtx == NULL) {
  605. TRACE(GC02M1B_ERROR,
  606. "%s: Invalid sensor handle (NULL pointer detected)\n",
  607. __func__);
  608. return (RET_WRONG_HANDLE);
  609. }
  610. if (pSetGain == NULL) {
  611. return (RET_NULL_POINTER);
  612. }
  613. *pSetGain = pGC02M1BCtx->AecCurGain;
  614. TRACE(GC02M1B_INFO, "%s: (exit)\n", __func__);
  615. return (result);
  616. }
  617. RESULT GC02M1B_IsiGetLongGainIss(IsiSensorHandle_t handle, float *gain)
  618. {
  619. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  620. TRACE(GC02M1B_INFO, "%s: (enter)\n", __func__);
  621. if (pGC02M1BCtx == NULL) {
  622. TRACE(GC02M1B_ERROR,"%s: Invalid sensor handle (NULL pointer detected)\n",__func__);
  623. return (RET_WRONG_HANDLE);
  624. }
  625. if (gain == NULL) {
  626. return (RET_NULL_POINTER);
  627. }
  628. *gain = pGC02M1BCtx->AecCurLongGain;
  629. TRACE(GC02M1B_INFO, "%s: (exit)\n", __func__);
  630. return (RET_SUCCESS);
  631. }
  632. RESULT GC02M1B_IsiGetVSGainIss(IsiSensorHandle_t handle, float *pSetGain) {
  633. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  634. RESULT result = RET_SUCCESS;
  635. TRACE(GC02M1B_INFO, "%s: (enter)\n", __func__);
  636. if (pGC02M1BCtx == NULL) {
  637. TRACE(GC02M1B_ERROR,
  638. "%s: Invalid sensor handle (NULL pointer detected)\n",
  639. __func__);
  640. return (RET_WRONG_HANDLE);
  641. }
  642. if (pSetGain == NULL) {
  643. return (RET_NULL_POINTER);
  644. }
  645. *pSetGain = pGC02M1BCtx->AecCurVSGain;
  646. TRACE(GC02M1B_INFO, "%s: (exit)\n", __func__);
  647. return (result);
  648. }
  649. RESULT GC02M1B_IsiGetGainIncrementIss(IsiSensorHandle_t handle, float *pIncr) {
  650. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  651. RESULT result = RET_SUCCESS;
  652. TRACE(GC02M1B_INFO, "%s: (enter)\n", __func__);
  653. if (pGC02M1BCtx == NULL) {
  654. TRACE(GC02M1B_ERROR,
  655. "%s: Invalid sensor handle (NULL pointer detected)\n",
  656. __func__);
  657. return (RET_WRONG_HANDLE);
  658. }
  659. if (pIncr == NULL)
  660. return (RET_NULL_POINTER);
  661. *pIncr = pGC02M1BCtx->AecGainIncrement;
  662. TRACE(GC02M1B_INFO, "%s: (exit)\n", __func__);
  663. return (result);
  664. }
  665. uint32_t gainLevelTable[17] = {
  666. 64,
  667. 96,
  668. 127,
  669. 157,
  670. 197,
  671. 226,
  672. 259,
  673. 287,
  674. 318,
  675. 356,
  676. 391,
  677. 419,
  678. 450,
  679. 480,
  680. 513,
  681. 646,
  682. 0xffffffff,
  683. };
  684. RESULT GC02M1B_IsiSetGainIss
  685. (IsiSensorHandle_t handle,
  686. float NewGain, float *pSetGain, float *hdr_ratio) {
  687. RESULT result = RET_SUCCESS;
  688. int32_t ret = 0;
  689. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  690. if (pGC02M1BCtx == NULL || pGC02M1BCtx->IsiCtx.HalHandle == NULL) {
  691. return RET_NULL_POINTER;
  692. }
  693. HalContext_t *pHalCtx = (HalContext_t *) pGC02M1BCtx->IsiCtx.HalHandle;
  694. //GC02M1B specific
  695. int Analog_Index;
  696. uint32_t tol_dig_gain = 0, SensorGain;
  697. int total;
  698. total = sizeof(gainLevelTable) / sizeof(uint32_t);
  699. SensorGain = NewGain * 64;
  700. if (SensorGain < 64) {
  701. SensorGain = 64;
  702. }
  703. for(Analog_Index = 0; Analog_Index < total; Analog_Index++)
  704. {
  705. if((gainLevelTable[Analog_Index] <= SensorGain)&&(SensorGain < gainLevelTable[Analog_Index+1]))
  706. break;
  707. }
  708. tol_dig_gain = SensorGain*1024/gainLevelTable[Analog_Index];
  709. ret = GC02M1B_IsiRegisterWriteIss(handle, 0xfe, 0x00);
  710. if (ret != 0) {
  711. return (RET_FAILURE);
  712. }
  713. ret = GC02M1B_IsiRegisterWriteIss(handle, 0xb6, Analog_Index);
  714. if (ret != 0) {
  715. return (RET_FAILURE);
  716. }
  717. ret = GC02M1B_IsiRegisterWriteIss(handle, 0xb1,(tol_dig_gain>>8));
  718. if (ret != 0) {
  719. return (RET_FAILURE);
  720. }
  721. ret = GC02M1B_IsiRegisterWriteIss(handle, 0xb2, (tol_dig_gain&0xff));
  722. if (ret != 0) {
  723. return (RET_FAILURE);
  724. }
  725. volatile int32_t reg;
  726. TRACE(GC02M1B_DEBUG, "%s NewGain=%f SensorGain=%d Analog_Index=%d,gainLevelTable[Analog_Index]=%d,tol_dig_gain=%u b1=0x%x b2=0x%x\n",__func__,
  727. NewGain, SensorGain, Analog_Index, gainLevelTable[Analog_Index], tol_dig_gain, (tol_dig_gain>>8), (tol_dig_gain&0xff));
  728. TRACE(GC02M1B_DEBUG, "%s 0xb6 write=0x%x,0xb1 write 0x%x,0xb2 write 0x%x\n",__func__, Analog_Index,(tol_dig_gain>>8), (tol_dig_gain&0xff));
  729. GC02M1B_IsiRegisterReadIss(handle, 0xb6, &reg);
  730. TRACE(GC02M1B_DEBUG, "%s 0xb6 read 0x0%x\n",__func__, reg);
  731. GC02M1B_IsiRegisterReadIss(handle, 0xb1, &reg);
  732. TRACE(GC02M1B_DEBUG, "%s 0xb1 read 0x0%x\n",__func__, reg);
  733. GC02M1B_IsiRegisterReadIss(handle, 0xb2, &reg);
  734. TRACE(GC02M1B_DEBUG, "%s 0xb2 read 0x0%x\n",__func__, reg);
  735. pGC02M1BCtx->AecCurGain = ((float)(NewGain));
  736. *pSetGain = pGC02M1BCtx->AecCurGain;
  737. TRACE(GC02M1B_DEBUG, "%s: g=%f\n", __func__, *pSetGain);
  738. return (result);
  739. }
  740. RESULT GC02M1B_IsiSetLongGainIss(IsiSensorHandle_t handle, float gain)
  741. {
  742. int ret = 0;
  743. TRACE(GC02M1B_INFO, "%s: (enter)\n", __func__);
  744. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  745. if (!pGC02M1BCtx || !pGC02M1BCtx->IsiCtx.HalHandle)
  746. {
  747. TRACE(GC02M1B_ERROR,"%s: Invalid sensor handle (NULL pointer detected)\n",__func__);
  748. return (RET_WRONG_HANDLE);
  749. }
  750. HalContext_t *pHalCtx = (HalContext_t *) pGC02M1BCtx->IsiCtx.HalHandle;
  751. uint32_t SensorGain = 0;
  752. SensorGain = gain * pGC02M1BCtx->gain_accuracy;
  753. if (pGC02M1BCtx->LastLongGain != SensorGain)
  754. {
  755. /*TODO*/
  756. #if 0
  757. ret = ioctl(pHalCtx->sensor_fd, VVSENSORIOC_S_LONG_GAIN, &SensorGain);
  758. if (ret != 0)
  759. {
  760. return (RET_FAILURE);
  761. TRACE(GC02M1B_ERROR,"%s: set long gain failed\n");
  762. }
  763. #endif
  764. pGC02M1BCtx->LastLongGain = SensorGain;
  765. pGC02M1BCtx->AecCurLongGain = gain;
  766. }
  767. TRACE(GC02M1B_INFO, "%s: (exit)\n", __func__);
  768. return (RET_SUCCESS);
  769. }
  770. RESULT GC02M1B_IsiSetVSGainIss
  771. (IsiSensorHandle_t handle,
  772. float NewIntegrationTime,
  773. float NewGain, float *pSetGain, float *hdr_ratio) {
  774. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  775. HalContext_t *pHalCtx = (HalContext_t *) pGC02M1BCtx->IsiCtx.HalHandle;
  776. RESULT result = RET_SUCCESS;
  777. #if 0
  778. float Gain = 0.0f;
  779. uint32_t ucGain = 0U;
  780. uint32_t again = 0U;
  781. #endif
  782. TRACE(GC02M1B_INFO, "%s: (enter)\n", __func__);
  783. if (!pGC02M1BCtx) {
  784. TRACE(GC02M1B_ERROR,
  785. "%s: Invalid sensor handle (NULL pointer detected)\n",
  786. __func__);
  787. return (RET_WRONG_HANDLE);
  788. }
  789. if (!pSetGain || !hdr_ratio)
  790. return (RET_NULL_POINTER);
  791. uint32_t SensorGain = 0;
  792. SensorGain = NewGain * pGC02M1BCtx->gain_accuracy;
  793. /*TODO*/
  794. //ioctl(pHalCtx->sensor_fd, VVSENSORIOC_S_VSGAIN, &SensorGain);
  795. pGC02M1BCtx->AecCurVSGain = NewGain;
  796. *pSetGain = pGC02M1BCtx->AecCurGain;
  797. TRACE(GC02M1B_DEBUG, "%s: g=%f\n", __func__, *pSetGain);
  798. TRACE(GC02M1B_INFO, "%s: (exit)\n", __func__);
  799. return (result);
  800. }
  801. RESULT GC02M1B_IsiSetBayerPattern(IsiSensorHandle_t handle, uint8_t pattern)
  802. {
  803. RESULT result = RET_SUCCESS;
  804. #if 0
  805. uint8_t h_shift = 0, v_shift = 0;
  806. uint32_t val_h = 0, val_l = 0;
  807. uint16_t val = 0;
  808. uint8_t Start_p = 0;
  809. bool_t streaming_status;
  810. TRACE(GC02M1B_INFO, "%s: (enter)\n", __func__);
  811. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  812. if (pGC02M1BCtx == NULL || pGC02M1BCtx->IsiCtx.HalHandle == NULL) {
  813. return RET_NULL_POINTER;
  814. }
  815. // pattern 0:B 1:GB 2:GR 3:R
  816. streaming_status = pGC02M1BCtx->Streaming;
  817. result = GC02M1B_IsiSensorSetStreamingIss(handle, 0);
  818. switch (pattern) {
  819. case BAYER_BGGR:
  820. Start_p = 0;
  821. break;
  822. case BAYER_GBRG:
  823. Start_p = 1;
  824. break;
  825. case BAYER_GRBG:
  826. Start_p = 2;
  827. break;
  828. case BAYER_RGGB:
  829. Start_p = 3;
  830. break;
  831. }
  832. h_shift = Start_p % 2;
  833. v_shift = Start_p / 2;
  834. GC02M1B_IsiRegisterReadIss(handle, 0x30a0, &val_h);
  835. GC02M1B_IsiRegisterReadIss(handle, 0x30a1, &val_l);
  836. val = (((val_h << 8) & 0xff00) | (val_l & 0x00ff)) + h_shift;
  837. val_h = (val >> 8) & 0xff;
  838. val_l = val & 0xff;
  839. GC02M1B_IsiRegisterWriteIss(handle, 0x30a0, (uint8_t)val_h);
  840. GC02M1B_IsiRegisterWriteIss(handle, 0x30a1, (uint8_t)val_l);
  841. GC02M1B_IsiRegisterReadIss(handle, 0x30a2, &val_h);
  842. GC02M1B_IsiRegisterReadIss(handle, 0x30a3, &val_l);
  843. val = (((val_h << 8) & 0xff00) | (val_l & 0x00ff)) + v_shift;
  844. val_h = (val >> 8) & 0xff;
  845. val_l = val & 0xff;
  846. GC02M1B_IsiRegisterWriteIss(handle, 0x30a2, (uint8_t)val_h);
  847. GC02M1B_IsiRegisterWriteIss(handle, 0x30a3, (uint8_t)val_l);
  848. GC02M1B_IsiRegisterReadIss(handle, 0x30a4, &val_h);
  849. GC02M1B_IsiRegisterReadIss(handle, 0x30a5, &val_l);
  850. val = (((val_h << 8) & 0xff00) | (val_l & 0x00ff)) + h_shift;
  851. val_h = (val >> 8) & 0xff;
  852. val_l = val & 0xff;
  853. GC02M1B_IsiRegisterWriteIss(handle, 0x30a4, (uint8_t)val_h);
  854. GC02M1B_IsiRegisterWriteIss(handle, 0x30a5, (uint8_t)val_l);
  855. GC02M1B_IsiRegisterReadIss(handle, 0x30a6, &val_h);
  856. GC02M1B_IsiRegisterReadIss(handle, 0x30a7, &val_l);
  857. val = (((val_h << 8) & 0xff00) | (val_l & 0x00ff)) + v_shift;
  858. val_h = (val >> 8) & 0xff;
  859. val_l = val & 0xff;
  860. GC02M1B_IsiRegisterWriteIss(handle, 0x30a6, (uint8_t)val_h);
  861. GC02M1B_IsiRegisterWriteIss(handle, 0x30a7, (uint8_t)val_l);
  862. pGC02M1BCtx->pattern = pattern;
  863. result = GC02M1B_IsiSensorSetStreamingIss(handle, streaming_status);
  864. #endif
  865. return (result);
  866. }
  867. RESULT GC02M1B_IsiGetIntegrationTimeIss
  868. (IsiSensorHandle_t handle, float *pSetIntegrationTime)
  869. {
  870. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  871. RESULT result = RET_SUCCESS;
  872. TRACE(GC02M1B_INFO, "%s: (enter)\n", __func__);
  873. if (!pGC02M1BCtx) {
  874. TRACE(GC02M1B_ERROR,
  875. "%s: Invalid sensor handle (NULL pointer detected)\n",
  876. __func__);
  877. return (RET_WRONG_HANDLE);
  878. }
  879. if (!pSetIntegrationTime)
  880. return (RET_NULL_POINTER);
  881. *pSetIntegrationTime = pGC02M1BCtx->AecCurIntegrationTime;
  882. TRACE(GC02M1B_INFO, "%s: (exit)\n", __func__);
  883. return (result);
  884. }
  885. RESULT GC02M1B_IsiGetLongIntegrationTimeIss(IsiSensorHandle_t handle, float *pIntegrationTime)
  886. {
  887. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  888. TRACE(GC02M1B_INFO, "%s: (enter)\n", __func__);
  889. if (!pGC02M1BCtx) {
  890. TRACE(GC02M1B_ERROR,"%s: Invalid sensor handle (NULL pointer detected)\n",__func__);
  891. return (RET_WRONG_HANDLE);
  892. }
  893. if (!pIntegrationTime)
  894. return (RET_NULL_POINTER);
  895. pGC02M1BCtx->AecCurLongIntegrationTime = pGC02M1BCtx->AecCurIntegrationTime;
  896. *pIntegrationTime = pGC02M1BCtx->AecCurLongIntegrationTime;
  897. TRACE(GC02M1B_INFO, "%s: (exit)\n", __func__);
  898. return (RET_SUCCESS);
  899. }
  900. RESULT GC02M1B_IsiGetVSIntegrationTimeIss
  901. (IsiSensorHandle_t handle, float *pSetIntegrationTime)
  902. {
  903. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  904. RESULT result = RET_SUCCESS;
  905. TRACE(GC02M1B_INFO, "%s: (enter)\n", __func__);
  906. if (!pGC02M1BCtx) {
  907. TRACE(GC02M1B_ERROR,
  908. "%s: Invalid sensor handle (NULL pointer detected)\n",
  909. __func__);
  910. return (RET_WRONG_HANDLE);
  911. }
  912. if (!pSetIntegrationTime)
  913. return (RET_NULL_POINTER);
  914. *pSetIntegrationTime = pGC02M1BCtx->AecCurVSIntegrationTime;
  915. TRACE(GC02M1B_INFO, "%s: (exit)\n", __func__);
  916. return (result);
  917. }
  918. RESULT GC02M1B_IsiGetIntegrationTimeIncrementIss
  919. (IsiSensorHandle_t handle, float *pIncr)
  920. {
  921. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  922. RESULT result = RET_SUCCESS;
  923. TRACE(GC02M1B_INFO, "%s: (enter)\n", __func__);
  924. if (!pGC02M1BCtx) {
  925. TRACE(GC02M1B_ERROR,
  926. "%s: Invalid sensor handle (NULL pointer detected)\n",
  927. __func__);
  928. return (RET_WRONG_HANDLE);
  929. }
  930. if (!pIncr)
  931. return (RET_NULL_POINTER);
  932. //_smallest_ increment the sensor/driver can handle (e.g. used for sliders in the application)
  933. *pIncr = pGC02M1BCtx->AecIntegrationTimeIncrement;
  934. TRACE(GC02M1B_INFO, "%s: (exit)\n", __func__);
  935. return (result);
  936. }
  937. RESULT GC02M1B_IsiSetIntegrationTimeIss
  938. (IsiSensorHandle_t handle,
  939. float NewIntegrationTime,
  940. float *pSetIntegrationTime,
  941. uint8_t * pNumberOfFramesToSkip, float *hdr_ratio)
  942. {
  943. RESULT result = RET_SUCCESS;
  944. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  945. HalContext_t *pHalCtx = (HalContext_t *) pGC02M1BCtx->IsiCtx.HalHandle;
  946. uint32_t exp_line = 0;
  947. uint32_t exp_line_old = 0;
  948. int ret = 0;
  949. TRACE(GC02M1B_INFO, "%s: (enter handle = %p)\n", __func__, handle);
  950. if (!pGC02M1BCtx) {
  951. TRACE(GC02M1B_ERROR,
  952. "%s: Invalid sensor handle (NULL pointer detected)\n",
  953. __func__);
  954. return (RET_WRONG_HANDLE);
  955. }
  956. if (!pSetIntegrationTime || !pNumberOfFramesToSkip) {
  957. TRACE(GC02M1B_ERROR,
  958. "%s: Invalid parameter (NULL pointer detected)\n",
  959. __func__);
  960. return (RET_NULL_POINTER);
  961. }
  962. exp_line = NewIntegrationTime / pGC02M1BCtx->one_line_exp_time;
  963. exp_line_old = exp_line;
  964. exp_line =
  965. MIN(pGC02M1BCtx->MaxIntegrationLine,
  966. MAX(pGC02M1BCtx->MinIntegrationLine, exp_line));
  967. TRACE(GC02M1B_DEBUG, "%s: set AEC_PK_EXPO=0x%05x min_exp_line = %d, max_exp_line = %d\n", __func__, exp_line, pGC02M1BCtx->MinIntegrationLine, pGC02M1BCtx->MaxIntegrationLine);
  968. if (exp_line != pGC02M1BCtx->OldIntegrationTime) {
  969. /*TODO*/
  970. //ioctl(pHalCtx->sensor_fd, VVSENSORIOC_S_EXP, &exp_line);
  971. pGC02M1BCtx->OldIntegrationTime = exp_line; // remember current integration time
  972. pGC02M1BCtx->AecCurIntegrationTime =
  973. exp_line * pGC02M1BCtx->one_line_exp_time;
  974. *pNumberOfFramesToSkip = 1U; //skip 1 frame
  975. } else {
  976. *pNumberOfFramesToSkip = 0U; //no frame skip
  977. }
  978. if (NewIntegrationTime > pGC02M1BCtx->MaxIntegrationLine * pGC02M1BCtx->one_line_exp_time)
  979. NewIntegrationTime = pGC02M1BCtx->MaxIntegrationLine * pGC02M1BCtx->one_line_exp_time;
  980. // GC02M1B specific
  981. int vts = exp_line + 16;
  982. ret = GC02M1B_IsiRegisterWriteIss(handle, 0xfe, 0x00);
  983. if (ret != 0) {
  984. return (RET_FAILURE);
  985. }
  986. ret = GC02M1B_IsiRegisterWriteIss(handle, 0x41, (vts>>8)&0xff);
  987. if (ret != 0) {
  988. return (RET_FAILURE);
  989. }
  990. ret = GC02M1B_IsiRegisterWriteIss(handle, 0x42, (vts&0xff));
  991. if (ret != 0) {
  992. return (RET_FAILURE);
  993. }
  994. ret = GC02M1B_IsiRegisterWriteIss(handle, 0x03, (exp_line>>8));
  995. if (ret != 0) {
  996. return (RET_FAILURE);
  997. }
  998. ret = GC02M1B_IsiRegisterWriteIss(handle, 0x04, (exp_line&0xff));
  999. if (ret != 0) {
  1000. return (RET_FAILURE);
  1001. }
  1002. volatile int32_t reg;
  1003. TRACE(GC02M1B_DEBUG, "%s exp_line = %fs / %fs = %d vts=%d\n",__func__, NewIntegrationTime, pGC02M1BCtx->one_line_exp_time, exp_line, vts);
  1004. //TRACE(GC02M1B_DEBUG, "%s cal_shutter=%d,Dgain_ratio=%u\n", __func__, cal_shutter, Dgain_ratio);
  1005. TRACE(GC02M1B_DEBUG, "%s 0x41 write 0x%x, 0x42 write 0x%x\n", __func__, (vts>>8)&0xff, (vts&0xff));
  1006. TRACE(GC02M1B_DEBUG, "%s 0x03 write 0x%x, 0x04 write 0x%x\n", __func__, (exp_line>>8), (exp_line&0xff));
  1007. GC02M1B_IsiRegisterReadIss(handle, 0x41, &reg);
  1008. TRACE(GC02M1B_DEBUG, "%s 0x41 read 0x0%x\n",__func__, reg);
  1009. GC02M1B_IsiRegisterReadIss(handle, 0x42, &reg);
  1010. TRACE(GC02M1B_DEBUG, "%s 0x42 read 0x0%x\n",__func__, reg);
  1011. GC02M1B_IsiRegisterReadIss(handle, 0x03, &reg);
  1012. TRACE(GC02M1B_DEBUG, "%s 0x03 read 0x0%x\n",__func__, reg);
  1013. GC02M1B_IsiRegisterReadIss(handle, 0x04, &reg);
  1014. TRACE(GC02M1B_DEBUG, "%s 0x04 read 0x0%x\n",__func__, reg);
  1015. if (exp_line_old != exp_line) {
  1016. *pSetIntegrationTime = pGC02M1BCtx->AecCurIntegrationTime;
  1017. } else {
  1018. *pSetIntegrationTime = NewIntegrationTime;
  1019. }
  1020. TRACE(GC02M1B_DEBUG, "%s: Ti=%f\n", __func__, *pSetIntegrationTime);
  1021. TRACE(GC02M1B_INFO, "%s: (exit)\n", __func__);
  1022. return (result);
  1023. }
  1024. RESULT GC02M1B_IsiSetLongIntegrationTimeIss(IsiSensorHandle_t handle,float IntegrationTime)
  1025. {
  1026. int ret;
  1027. TRACE(GC02M1B_INFO, "%s: (enter)\n", __func__);
  1028. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  1029. if (!handle || !pGC02M1BCtx->IsiCtx.HalHandle)
  1030. {
  1031. TRACE(GC02M1B_ERROR,"%s: Invalid sensor handle (NULL pointer detected)\n",__func__);
  1032. return (RET_WRONG_HANDLE);
  1033. }
  1034. HalContext_t *pHalCtx = (HalContext_t *) pGC02M1BCtx->IsiCtx.HalHandle;
  1035. uint32_t exp_line = 0;
  1036. exp_line = IntegrationTime / pGC02M1BCtx->one_line_exp_time;
  1037. exp_line = MIN(pGC02M1BCtx->MaxIntegrationLine, MAX(pGC02M1BCtx->MinIntegrationLine, exp_line));
  1038. if (exp_line != pGC02M1BCtx->LastLongExpLine)
  1039. {
  1040. if (pGC02M1BCtx->KernelDriverFlag)
  1041. {
  1042. ret = ioctl(pHalCtx->sensor_fd, VVSENSORIOC_S_LONG_EXP, &exp_line);
  1043. if (ret != 0)
  1044. {
  1045. TRACE(GC02M1B_ERROR,"%s: set long gain failed\n");
  1046. return RET_FAILURE;
  1047. }
  1048. }
  1049. pGC02M1BCtx->LastLongExpLine = exp_line;
  1050. pGC02M1BCtx->AecCurLongIntegrationTime = pGC02M1BCtx->LastLongExpLine*pGC02M1BCtx->one_line_exp_time;
  1051. }
  1052. TRACE(GC02M1B_INFO, "%s: (exit)\n", __func__);
  1053. return (RET_SUCCESS);
  1054. }
  1055. RESULT GC02M1B_IsiSetVSIntegrationTimeIss
  1056. (IsiSensorHandle_t handle,
  1057. float NewIntegrationTime,
  1058. float *pSetVSIntegrationTime,
  1059. uint8_t * pNumberOfFramesToSkip, float *hdr_ratio)
  1060. {
  1061. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  1062. RESULT result = RET_SUCCESS;
  1063. uint32_t exp_line = 0;
  1064. TRACE(GC02M1B_INFO, "%s: (enter)\n", __func__);
  1065. if (!pGC02M1BCtx) {
  1066. TRACE(GC02M1B_ERROR,
  1067. "%s: Invalid sensor handle (NULL pointer detected)\n",
  1068. __func__);
  1069. return (RET_WRONG_HANDLE);
  1070. }
  1071. if (!pSetVSIntegrationTime || !pNumberOfFramesToSkip) {
  1072. TRACE(GC02M1B_ERROR,
  1073. "%s: Invalid parameter (NULL pointer detected)\n",
  1074. __func__);
  1075. return (RET_NULL_POINTER);
  1076. }
  1077. TRACE(GC02M1B_INFO,
  1078. "%s: maxIntegrationTime-=%f minIntegrationTime = %f\n", __func__,
  1079. pGC02M1BCtx->AecMaxIntegrationTime,
  1080. pGC02M1BCtx->AecMinIntegrationTime);
  1081. exp_line = NewIntegrationTime / pGC02M1BCtx->one_line_exp_time;
  1082. exp_line =
  1083. MIN(pGC02M1BCtx->MaxIntegrationLine,
  1084. MAX(pGC02M1BCtx->MinIntegrationLine, exp_line));
  1085. if (exp_line != pGC02M1BCtx->OldVsIntegrationTime) {
  1086. /*TODO*/
  1087. // ioctl(pHalCtx->sensor_fd, VVSENSORIOC_S_VSEXP, &exp_line);
  1088. } else if (1){
  1089. pGC02M1BCtx->OldVsIntegrationTime = exp_line;
  1090. pGC02M1BCtx->AecCurVSIntegrationTime = exp_line * pGC02M1BCtx->one_line_exp_time; //remember current integration time
  1091. *pNumberOfFramesToSkip = 1U; //skip 1 frame
  1092. } else {
  1093. *pNumberOfFramesToSkip = 0U; //no frame skip
  1094. }
  1095. *pSetVSIntegrationTime = pGC02M1BCtx->AecCurVSIntegrationTime;
  1096. TRACE(GC02M1B_DEBUG, "%s: NewIntegrationTime=%f\n", __func__,
  1097. NewIntegrationTime);
  1098. TRACE(GC02M1B_INFO, "%s: (exit)\n", __func__);
  1099. return (result);
  1100. }
  1101. RESULT GC02M1B_IsiExposureControlIss
  1102. (IsiSensorHandle_t handle,
  1103. float NewGain,
  1104. float NewIntegrationTime,
  1105. uint8_t * pNumberOfFramesToSkip,
  1106. float *pSetGain, float *pSetIntegrationTime, float *hdr_ratio)
  1107. {
  1108. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  1109. RESULT result = RET_SUCCESS;
  1110. int TmpGain;
  1111. /*TODO*/
  1112. TRACE(GC02M1B_INFO, "%s: (enter)\n", __func__);
  1113. if (pGC02M1BCtx == NULL) {
  1114. TRACE(GC02M1B_ERROR,
  1115. "%s: Invalid sensor handle (NULL pointer detected)\n",
  1116. __func__);
  1117. return (RET_WRONG_HANDLE);
  1118. }
  1119. if ((pNumberOfFramesToSkip == NULL) || (pSetGain == NULL)
  1120. || (pSetIntegrationTime == NULL)) {
  1121. TRACE(GC02M1B_ERROR,
  1122. "%s: Invalid parameter (NULL pointer detected)\n",
  1123. __func__);
  1124. return (RET_NULL_POINTER);
  1125. }
  1126. TRACE(GC02M1B_ERROR, "%s: g=%f, Ti=%f\n", __func__, NewGain,
  1127. NewIntegrationTime);
  1128. result = GC02M1B_IsiSetIntegrationTimeIss(handle, NewIntegrationTime,
  1129. pSetIntegrationTime,
  1130. pNumberOfFramesToSkip, hdr_ratio);
  1131. result = GC02M1B_IsiSetGainIss(handle, NewGain, pSetGain, hdr_ratio);
  1132. pGC02M1BCtx->CurHdrRatio = *hdr_ratio;
  1133. TRACE(GC02M1B_INFO, "%s: (exit)\n", __func__);
  1134. return result;
  1135. }
  1136. RESULT GC02M1B_IsiGetCurrentExposureIss
  1137. (IsiSensorHandle_t handle, float *pSetGain, float *pSetIntegrationTime, float *hdr_ratio) {
  1138. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  1139. RESULT result = RET_SUCCESS;
  1140. TRACE(GC02M1B_INFO, "%s: (enter)\n", __func__);
  1141. if (pGC02M1BCtx == NULL) {
  1142. TRACE(GC02M1B_ERROR,
  1143. "%s: Invalid sensor handle (NULL pointer detected)\n",
  1144. __func__);
  1145. return (RET_WRONG_HANDLE);
  1146. }
  1147. if ((pSetGain == NULL) || (pSetIntegrationTime == NULL))
  1148. return (RET_NULL_POINTER);
  1149. *pSetGain = pGC02M1BCtx->AecCurGain;
  1150. *pSetIntegrationTime = pGC02M1BCtx->AecCurIntegrationTime;
  1151. *hdr_ratio = pGC02M1BCtx->CurHdrRatio;
  1152. TRACE(GC02M1B_INFO, "%s: (exit)\n", __func__);
  1153. return (result);
  1154. }
  1155. RESULT GC02M1B_IsiGetResolutionIss(IsiSensorHandle_t handle, uint16_t *pwidth, uint16_t *pheight) {
  1156. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  1157. RESULT result = RET_SUCCESS;
  1158. TRACE(GC02M1B_INFO, "%s: (enter)\n", __func__);
  1159. if (pGC02M1BCtx == NULL) {
  1160. TRACE(GC02M1B_ERROR,
  1161. "%s: Invalid sensor handle (NULL pointer detected)\n",
  1162. __func__);
  1163. return (RET_WRONG_HANDLE);
  1164. }
  1165. *pwidth = pGC02M1BCtx->SensorMode.width;
  1166. *pheight = pGC02M1BCtx->SensorMode.height;
  1167. TRACE(GC02M1B_INFO, "%s: (exit)\n", __func__);
  1168. return (result);
  1169. }
  1170. RESULT GC02M1B_IsiGetSensorFpsIss(IsiSensorHandle_t handle, uint32_t * pfps)
  1171. {
  1172. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  1173. RESULT result = RET_SUCCESS;
  1174. TRACE(GC02M1B_INFO, "%s: (enter)\n", __func__);
  1175. if (pGC02M1BCtx == NULL) {
  1176. TRACE(GC02M1B_ERROR,
  1177. "%s: Invalid sensor handle (NULL pointer detected)\n",
  1178. __func__);
  1179. return (RET_WRONG_HANDLE);
  1180. }
  1181. HalContext_t *pHalCtx = (HalContext_t *) pGC02M1BCtx->IsiCtx.HalHandle;
  1182. if (pGC02M1BCtx->KernelDriverFlag) {
  1183. /*TODO*/
  1184. ioctl(pHalCtx->sensor_fd, VVSENSORIOC_G_FPS, pfps);
  1185. pGC02M1BCtx->CurrFps = *pfps;
  1186. }
  1187. *pfps = pGC02M1BCtx->CurrFps;
  1188. TRACE(GC02M1B_INFO, "%s: (exit)\n", __func__);
  1189. return (result);
  1190. }
  1191. RESULT GC02M1B_IsiSetSensorFpsIss(IsiSensorHandle_t handle, uint32_t fps)
  1192. {
  1193. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  1194. RESULT result = RET_SUCCESS;
  1195. int32_t ret = 0;
  1196. TRACE(GC02M1B_INFO, "%s: (enter)\n", __func__);
  1197. if (pGC02M1BCtx == NULL) {
  1198. TRACE(GC02M1B_ERROR,
  1199. "%s: Invalid sensor handle (NULL pointer detected)\n",
  1200. __func__);
  1201. return (RET_WRONG_HANDLE);
  1202. }
  1203. HalContext_t *pHalCtx = (HalContext_t *) pGC02M1BCtx->IsiCtx.HalHandle;
  1204. if (fps > pGC02M1BCtx->MaxFps) {
  1205. TRACE(GC02M1B_ERROR,
  1206. "%s: set fps(%d) out of range, correct to %d (%d, %d)\n",
  1207. __func__, fps, pGC02M1BCtx->MaxFps, pGC02M1BCtx->MinFps,
  1208. pGC02M1BCtx->MaxFps);
  1209. fps = pGC02M1BCtx->MaxFps;
  1210. }
  1211. if (fps < pGC02M1BCtx->MinFps) {
  1212. TRACE(GC02M1B_ERROR,
  1213. "%s: set fps(%d) out of range, correct to %d (%d, %d)\n",
  1214. __func__, fps, pGC02M1BCtx->MinFps, pGC02M1BCtx->MinFps,
  1215. pGC02M1BCtx->MaxFps);
  1216. fps = pGC02M1BCtx->MinFps;
  1217. }
  1218. if (pGC02M1BCtx->KernelDriverFlag) {
  1219. ret = ioctl(pHalCtx->sensor_fd, VVSENSORIOC_S_FPS, &fps);
  1220. if (ret != 0) {
  1221. TRACE(GC02M1B_ERROR, "%s: set sensor fps=%d error\n",
  1222. __func__);
  1223. return (RET_FAILURE);
  1224. }
  1225. ret = ioctl(pHalCtx->sensor_fd, VVSENSORIOC_G_SENSOR_MODE, &(pGC02M1BCtx->SensorMode));
  1226. {
  1227. pGC02M1BCtx->MaxIntegrationLine = pGC02M1BCtx->SensorMode.ae_info.max_integration_time;
  1228. pGC02M1BCtx->AecMaxIntegrationTime = pGC02M1BCtx->MaxIntegrationLine * pGC02M1BCtx->one_line_exp_time;
  1229. }
  1230. #ifdef SUBDEV_CHAR
  1231. struct vvcam_ae_info_s ae_info;
  1232. ret =
  1233. ioctl(pHalCtx->sensor_fd, VVSENSORIOC_G_AE_INFO, &ae_info);
  1234. if (ret != 0) {
  1235. TRACE(GC02M1B_ERROR, "%s:sensor get ae info error!\n",
  1236. __func__);
  1237. return (RET_FAILURE);
  1238. }
  1239. pGC02M1BCtx->one_line_exp_time =
  1240. (float)ae_info.one_line_exp_time_ns / 1000000000;
  1241. pGC02M1BCtx->MaxIntegrationLine = ae_info.max_integration_time;
  1242. pGC02M1BCtx->AecMaxIntegrationTime =
  1243. pGC02M1BCtx->MaxIntegrationLine *
  1244. pGC02M1BCtx->one_line_exp_time;
  1245. #endif
  1246. }
  1247. TRACE(GC02M1B_INFO, "%s: set sensor fps = %d\n", __func__,
  1248. pGC02M1BCtx->CurrFps);
  1249. TRACE(GC02M1B_INFO, "%s: (exit)\n", __func__);
  1250. return (result);
  1251. }
  1252. static RESULT GC02M1B_IsiActivateTestPattern(IsiSensorHandle_t handle,
  1253. const bool_t enable)
  1254. {
  1255. RESULT result = RET_SUCCESS;
  1256. TRACE(GC02M1B_INFO, "%s: (enter)\n", __func__);
  1257. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  1258. if (pGC02M1BCtx == NULL || pGC02M1BCtx->IsiCtx.HalHandle == NULL) {
  1259. return RET_NULL_POINTER;
  1260. }
  1261. if (pGC02M1BCtx->Configured != BOOL_TRUE)
  1262. return RET_WRONG_STATE;
  1263. if (BOOL_TRUE == enable) {
  1264. //result = GC02M1B_IsiRegisterWriteIss(handle, 0x3253, 0x80);
  1265. } else {
  1266. //result = GC02M1B_IsiRegisterWriteIss(handle, 0x3253, 0x00);
  1267. }
  1268. pGC02M1BCtx->TestPattern = enable;
  1269. TRACE(GC02M1B_INFO, "%s: (exit)\n", __func__);
  1270. return (result);
  1271. }
  1272. static RESULT GC02M1B_IsiSensorSetBlcIss(IsiSensorHandle_t handle, sensor_blc_t * pblc)
  1273. {
  1274. int32_t ret = 0;
  1275. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  1276. if (pGC02M1BCtx == NULL || pGC02M1BCtx->IsiCtx.HalHandle == NULL) {
  1277. return RET_WRONG_HANDLE;
  1278. }
  1279. if (pblc == NULL)
  1280. return RET_NULL_POINTER;
  1281. HalContext_t *pHalCtx = (HalContext_t *) pGC02M1BCtx->IsiCtx.HalHandle;
  1282. ret = ioctl(pHalCtx->sensor_fd, VVSENSORIOC_S_BLC, pblc);
  1283. if (ret != 0)
  1284. {
  1285. TRACE(GC02M1B_ERROR, "%s: set wb error\n", __func__);
  1286. }
  1287. return RET_SUCCESS;
  1288. }
  1289. static RESULT GC02M1B_IsiSensorSetWBIss(IsiSensorHandle_t handle, sensor_white_balance_t * pwb)
  1290. {
  1291. int32_t ret = 0;
  1292. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  1293. if (pGC02M1BCtx == NULL || pGC02M1BCtx->IsiCtx.HalHandle == NULL) {
  1294. return RET_WRONG_HANDLE;
  1295. }
  1296. HalContext_t *pHalCtx = (HalContext_t *) pGC02M1BCtx->IsiCtx.HalHandle;
  1297. if (pwb == NULL)
  1298. return RET_NULL_POINTER;
  1299. ret = ioctl(pHalCtx->sensor_fd, VVSENSORIOC_S_WB, pwb);
  1300. if (ret != 0)
  1301. {
  1302. TRACE(GC02M1B_ERROR, "%s: set wb error\n", __func__);
  1303. }
  1304. return RET_SUCCESS;
  1305. }
  1306. static RESULT GC02M1B_IsiGetSensorAWBModeIss(IsiSensorHandle_t handle, IsiSensorAwbMode_t *pawbmode)
  1307. {
  1308. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  1309. if (pGC02M1BCtx == NULL || pGC02M1BCtx->IsiCtx.HalHandle == NULL) {
  1310. return RET_NULL_POINTER;
  1311. }
  1312. if (pGC02M1BCtx->SensorMode.hdr_mode == SENSOR_MODE_HDR_NATIVE){
  1313. *pawbmode = ISI_SENSOR_AWB_MODE_SENSOR;
  1314. }else{
  1315. *pawbmode = ISI_SENSOR_AWB_MODE_NORMAL;
  1316. }
  1317. return RET_SUCCESS;
  1318. }
  1319. static RESULT GC02M1B_IsiSensorGetExpandCurveIss(IsiSensorHandle_t handle, sensor_expand_curve_t * pexpand_curve)
  1320. {
  1321. int32_t ret = 0;
  1322. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  1323. if (pGC02M1BCtx == NULL || pGC02M1BCtx->IsiCtx.HalHandle == NULL) {
  1324. return RET_NULL_POINTER;
  1325. }
  1326. HalContext_t *pHalCtx = (HalContext_t *) pGC02M1BCtx->IsiCtx.HalHandle;
  1327. ret = ioctl(pHalCtx->sensor_fd, VVSENSORIOC_G_EXPAND_CURVE, pexpand_curve);
  1328. if (ret != 0)
  1329. {
  1330. TRACE(GC02M1B_ERROR, "%s: get expand cure error\n", __func__);
  1331. return RET_FAILURE;
  1332. }
  1333. return RET_SUCCESS;
  1334. }
  1335. static RESULT GC02M1B_IsiGetCapsIss(IsiSensorHandle_t handle,
  1336. IsiSensorCaps_t * pIsiSensorCaps)
  1337. {
  1338. GC02M1B_Context_t *pGC02M1BCtx = (GC02M1B_Context_t *) handle;
  1339. RESULT result = RET_SUCCESS;
  1340. TRACE(GC02M1B_INFO, "%s (enter)\n", __func__);
  1341. if (pGC02M1BCtx == NULL) {
  1342. return (RET_WRONG_HANDLE);
  1343. }
  1344. if (pIsiSensorCaps == NULL) {
  1345. return (RET_NULL_POINTER);
  1346. }
  1347. pIsiSensorCaps->BusWidth = pGC02M1BCtx->SensorMode.bit_width;
  1348. pIsiSensorCaps->Mode = ISI_MODE_BAYER;
  1349. pIsiSensorCaps->FieldSelection = ISI_FIELDSEL_BOTH;
  1350. pIsiSensorCaps->YCSequence = ISI_YCSEQ_YCBYCR;
  1351. pIsiSensorCaps->Conv422 = ISI_CONV422_NOCOSITED;
  1352. pIsiSensorCaps->BPat = pGC02M1BCtx->SensorMode.bayer_pattern;
  1353. pIsiSensorCaps->HPol = ISI_HPOL_REFPOS;
  1354. pIsiSensorCaps->VPol = ISI_VPOL_NEG;
  1355. pIsiSensorCaps->Edge = ISI_EDGE_RISING;
  1356. pIsiSensorCaps->Resolution.width = pGC02M1BCtx->SensorMode.width;
  1357. pIsiSensorCaps->Resolution.height = pGC02M1BCtx->SensorMode.height;
  1358. pIsiSensorCaps->SmiaMode = ISI_SMIA_OFF;
  1359. pIsiSensorCaps->MipiLanes = ISI_MIPI_2LANES;
  1360. if (pIsiSensorCaps->BusWidth == 10) {
  1361. pIsiSensorCaps->MipiMode = ISI_MIPI_MODE_RAW_10;
  1362. }else if (pIsiSensorCaps->BusWidth == 12){
  1363. pIsiSensorCaps->MipiMode = ISI_MIPI_MODE_RAW_12;
  1364. }else{
  1365. pIsiSensorCaps->MipiMode = ISI_MIPI_OFF;
  1366. }
  1367. TRACE(GC02M1B_INFO, "%s (exit)\n", __func__);
  1368. return result;
  1369. }
  1370. RESULT GC02M1B_IsiGetSensorIss(IsiSensor_t *pIsiSensor)
  1371. {
  1372. RESULT result = RET_SUCCESS;
  1373. TRACE( GC02M1B_INFO, "%s (enter)\n", __func__);
  1374. if ( pIsiSensor != NULL ) {
  1375. pIsiSensor->pszName = SensorName;
  1376. pIsiSensor->pIsiCreateSensorIss = GC02M1B_IsiCreateSensorIss;
  1377. pIsiSensor->pIsiInitSensorIss = GC02M1B_IsiInitSensorIss;
  1378. pIsiSensor->pIsiGetSensorModeIss = GC02M1B_IsiGetSensorModeIss;
  1379. pIsiSensor->pIsiResetSensorIss = GC02M1B_IsiResetSensorIss;
  1380. pIsiSensor->pIsiReleaseSensorIss = GC02M1B_IsiReleaseSensorIss;
  1381. pIsiSensor->pIsiGetCapsIss = GC02M1B_IsiGetCapsIss;
  1382. pIsiSensor->pIsiSetupSensorIss = GC02M1B_IsiSetupSensorIss;
  1383. pIsiSensor->pIsiChangeSensorResolutionIss = GC02M1B_IsiChangeSensorResolutionIss;
  1384. pIsiSensor->pIsiSensorSetStreamingIss = GC02M1B_IsiSensorSetStreamingIss;
  1385. pIsiSensor->pIsiSensorSetPowerIss = GC02M1B_IsiSensorSetPowerIss;
  1386. pIsiSensor->pIsiCheckSensorConnectionIss = GC02M1B_IsiCheckSensorConnectionIss;
  1387. pIsiSensor->pIsiGetSensorRevisionIss = GC02M1B_IsiGetSensorRevisionIss;
  1388. pIsiSensor->pIsiRegisterReadIss = GC02M1B_IsiRegisterReadIss;
  1389. pIsiSensor->pIsiRegisterWriteIss = GC02M1B_IsiRegisterWriteIss;
  1390. /* AEC functions */
  1391. pIsiSensor->pIsiExposureControlIss = GC02M1B_IsiExposureControlIss;
  1392. pIsiSensor->pIsiGetGainLimitsIss = GC02M1B_IsiGetGainLimitsIss;
  1393. pIsiSensor->pIsiGetIntegrationTimeLimitsIss = GC02M1B_IsiGetIntegrationTimeLimitsIss;
  1394. pIsiSensor->pIsiGetCurrentExposureIss = GC02M1B_IsiGetCurrentExposureIss;
  1395. pIsiSensor->pIsiGetVSGainIss = GC02M1B_IsiGetVSGainIss;
  1396. pIsiSensor->pIsiGetGainIss = GC02M1B_IsiGetGainIss;
  1397. pIsiSensor->pIsiGetLongGainIss = GC02M1B_IsiGetLongGainIss;
  1398. pIsiSensor->pIsiGetGainIncrementIss = GC02M1B_IsiGetGainIncrementIss;
  1399. pIsiSensor->pIsiSetGainIss = GC02M1B_IsiSetGainIss;
  1400. pIsiSensor->pIsiGetIntegrationTimeIss = GC02M1B_IsiGetIntegrationTimeIss;
  1401. pIsiSensor->pIsiGetVSIntegrationTimeIss = GC02M1B_IsiGetVSIntegrationTimeIss;
  1402. pIsiSensor->pIsiGetLongIntegrationTimeIss = GC02M1B_IsiGetLongIntegrationTimeIss;
  1403. pIsiSensor->pIsiGetIntegrationTimeIncrementIss = GC02M1B_IsiGetIntegrationTimeIncrementIss;
  1404. pIsiSensor->pIsiSetIntegrationTimeIss = GC02M1B_IsiSetIntegrationTimeIss;
  1405. pIsiSensor->pIsiQuerySensorIss = GC02M1B_IsiQuerySensorIss;
  1406. pIsiSensor->pIsiGetResolutionIss = GC02M1B_IsiGetResolutionIss;
  1407. pIsiSensor->pIsiGetSensorFpsIss = GC02M1B_IsiGetSensorFpsIss;
  1408. pIsiSensor->pIsiSetSensorFpsIss = GC02M1B_IsiSetSensorFpsIss;
  1409. pIsiSensor->pIsiSensorGetExpandCurveIss = GC02M1B_IsiSensorGetExpandCurveIss;
  1410. /* AWB specific functions */
  1411. /* Testpattern */
  1412. pIsiSensor->pIsiActivateTestPattern = GC02M1B_IsiActivateTestPattern;
  1413. pIsiSensor->pIsiSetBayerPattern = GC02M1B_IsiSetBayerPattern;
  1414. pIsiSensor->pIsiSensorSetBlcIss = GC02M1B_IsiSensorSetBlcIss;
  1415. pIsiSensor->pIsiSensorSetWBIss = GC02M1B_IsiSensorSetWBIss;
  1416. pIsiSensor->pIsiGetSensorAWBModeIss = GC02M1B_IsiGetSensorAWBModeIss;
  1417. } else {
  1418. result = RET_NULL_POINTER;
  1419. }
  1420. TRACE( GC02M1B_INFO, "%s (exit)\n", __func__);
  1421. return ( result );
  1422. }
  1423. /*****************************************************************************
  1424. * each sensor driver need declare this struct for isi load
  1425. *****************************************************************************/
  1426. IsiCamDrvConfig_t GC02M1B_IsiCamDrvConfig = {
  1427. 0,
  1428. GC02M1B_IsiQuerySensorSupportIss,
  1429. GC02M1B_IsiGetSensorIss,
  1430. {
  1431. SensorName, /**< IsiSensor_t.pszName */
  1432. 0, /**< IsiSensor_t.pIsiInitIss>*/
  1433. 0, /**< IsiSensor_t.pIsiResetSensorIss>*/
  1434. 0, /**< IsiSensor_t.pRegisterTable */
  1435. 0, /**< IsiSensor_t.pIsiSensorCaps */
  1436. 0, /**< IsiSensor_t.pIsiCreateSensorIss */
  1437. 0, /**< IsiSensor_t.pIsiReleaseSensorIss */
  1438. 0, /**< IsiSensor_t.pIsiGetCapsIss */
  1439. 0, /**< IsiSensor_t.pIsiSetupSensorIss */
  1440. 0, /**< IsiSensor_t.pIsiChangeSensorResolutionIss */
  1441. 0, /**< IsiSensor_t.pIsiSensorSetStreamingIss */
  1442. 0, /**< IsiSensor_t.pIsiSensorSetPowerIss */
  1443. 0, /**< IsiSensor_t.pIsiCheckSensorConnectionIss */
  1444. 0, /**< IsiSensor_t.pIsiGetSensorRevisionIss */
  1445. 0, /**< IsiSensor_t.pIsiRegisterReadIss */
  1446. 0, /**< IsiSensor_t.pIsiRegisterWriteIss */
  1447. 0, /**< IsiSensor_t.pIsiExposureControlIss */
  1448. 0, /**< IsiSensor_t.pIsiGetGainLimitsIss */
  1449. 0, /**< IsiSensor_t.pIsiGetIntegrationTimeLimitsIss */
  1450. 0, /**< IsiSensor_t.pIsiGetCurrentExposureIss */
  1451. 0, /**< IsiSensor_t.pIsiGetGainIss */
  1452. 0, /**< IsiSensor_t.pIsiGetVSGainIss */
  1453. 0, /**< IsiSensor_t.pIsiGetGainIncrementIss */
  1454. 0, /**< IsiSensor_t.pIsiGetGainIncrementIss */
  1455. 0, /**< IsiSensor_t.pIsiSetGainIss */
  1456. 0, /**< IsiSensor_t.pIsiGetIntegrationTimeIss */
  1457. 0, /**< IsiSensor_t.pIsiGetIntegrationTimeIncrementIss */
  1458. 0, /**< IsiSensor_t.pIsiSetIntegrationTimeIss */
  1459. 0, /**< IsiSensor_t.pIsiGetResolutionIss */
  1460. 0, /**< IsiSensor_t.pIsiGetAfpsInfoIss */
  1461. 0, /**< IsiSensor_t.pIsiMdiInitMotoDriveMds */
  1462. 0, /**< IsiSensor_t.pIsiMdiSetupMotoDrive */
  1463. 0, /**< IsiSensor_t.pIsiMdiFocusSet */
  1464. 0, /**< IsiSensor_t.pIsiMdiFocusGet */
  1465. 0, /**< IsiSensor_t.pIsiMdiFocusCalibrate */
  1466. 0, /**< IsiSensor_t.pIsiGetSensorMipiInfoIss */
  1467. 0, /**< IsiSensor_t.pIsiActivateTestPattern */
  1468. 0, /**< IsiSensor_t.pIsiSetBayerPattern */
  1469. }
  1470. };