smart_mtp_s6tnmr7.c 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230
  1. /*
  2. * =================================================================
  3. *
  4. * Filename: smart_mtp_se6e8fa.c
  5. *
  6. * Description: Smart dimming algorithm implementation
  7. *
  8. * Author: jb09.kim
  9. * Company: Samsung Electronics
  10. *
  11. * ================================================================
  12. */
  13. /*
  14. <one line to give the program's name and a brief idea of what it does.>
  15. Copyright (C) 2012, Samsung Electronics. All rights reserved.
  16. *
  17. * This program is free software; you can redistribute it and/or modify
  18. * it under the terms of the GNU General Public License version 2 and
  19. * only version 2 as published by the Free Software Foundation.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  29. * 02110-1301, USA.
  30. *
  31. */
  32. #include "smart_mtp_s6tnmr7.h"
  33. #include "smart_mtp_2p2_gamma.h"
  34. #include "smart_dimming.h"
  35. /*
  36. #define SMART_DIMMING_DEBUG
  37. */
  38. static char max_lux_table[GAMMA_SET_MAX];
  39. static char min_lux_table[GAMMA_SET_MAX];
  40. /*
  41. * To support different center cell gamma setting
  42. */
  43. static char V255_300CD_R_MSB;
  44. static char V255_300CD_R_LSB;
  45. static char V255_300CD_G_MSB;
  46. static char V255_300CD_G_LSB;
  47. static char V255_300CD_B_MSB;
  48. static char V255_300CD_B_LSB;
  49. static char V203_300CD_R;
  50. static char V203_300CD_G;
  51. static char V203_300CD_B;
  52. static char V151_300CD_R;
  53. static char V151_300CD_G;
  54. static char V151_300CD_B;
  55. static char V87_300CD_R;
  56. static char V87_300CD_G;
  57. static char V87_300CD_B;
  58. static char V51_300CD_R;
  59. static char V51_300CD_G;
  60. static char V51_300CD_B;
  61. static char V35_300CD_R;
  62. static char V35_300CD_G;
  63. static char V35_300CD_B;
  64. static char V23_300CD_R;
  65. static char V23_300CD_G;
  66. static char V23_300CD_B;
  67. static char V11_300CD_R;
  68. static char V11_300CD_G;
  69. static char V11_300CD_B;
  70. static char V3_300CD_R;
  71. static char V3_300CD_G;
  72. static char V3_300CD_B;
  73. static char VT_300CD_R;
  74. static char VT_300CD_G;
  75. static char VT_300CD_B;
  76. static int char_to_int(char data1)
  77. {
  78. int cal_data;
  79. if (data1 & 0x80) {
  80. cal_data = data1 & 0x7F;
  81. cal_data *= -1;
  82. } else
  83. cal_data = data1;
  84. return cal_data;
  85. }
  86. static int char_to_int_v255(char data1, char data2)
  87. {
  88. int cal_data;
  89. if (data1)
  90. cal_data = data2 * -1;
  91. else
  92. cal_data = data2;
  93. return cal_data;
  94. }
  95. #ifdef SMART_DIMMING_DEBUG
  96. static void print_RGB_offset(struct SMART_DIM *pSmart)
  97. {
  98. pr_info("%s MTP Offset VT R:%d G:%d B:%d\n", __func__,
  99. char_to_int(pSmart->MTP.R_OFFSET.OFFSET_1),
  100. char_to_int(pSmart->MTP.G_OFFSET.OFFSET_1),
  101. char_to_int(pSmart->MTP.B_OFFSET.OFFSET_1));
  102. pr_info("%s MTP Offset V3 R:%d G:%d B:%d\n", __func__,
  103. char_to_int(pSmart->MTP.R_OFFSET.OFFSET_3),
  104. char_to_int(pSmart->MTP.G_OFFSET.OFFSET_3),
  105. char_to_int(pSmart->MTP.B_OFFSET.OFFSET_3));
  106. pr_info("%s MTP Offset V11 R:%d G:%d B:%d\n", __func__,
  107. char_to_int(pSmart->MTP.R_OFFSET.OFFSET_11),
  108. char_to_int(pSmart->MTP.G_OFFSET.OFFSET_11),
  109. char_to_int(pSmart->MTP.B_OFFSET.OFFSET_11));
  110. pr_info("%s MTP Offset V23 R:%d G:%d B:%d\n", __func__,
  111. char_to_int(pSmart->MTP.R_OFFSET.OFFSET_23),
  112. char_to_int(pSmart->MTP.G_OFFSET.OFFSET_23),
  113. char_to_int(pSmart->MTP.B_OFFSET.OFFSET_23));
  114. pr_info("%s MTP Offset V35 R:%d G:%d B:%d\n", __func__,
  115. char_to_int(pSmart->MTP.R_OFFSET.OFFSET_35),
  116. char_to_int(pSmart->MTP.G_OFFSET.OFFSET_35),
  117. char_to_int(pSmart->MTP.B_OFFSET.OFFSET_35));
  118. pr_info("%s MTP Offset V51 R:%d G:%d B:%d\n", __func__,
  119. char_to_int(pSmart->MTP.R_OFFSET.OFFSET_51),
  120. char_to_int(pSmart->MTP.G_OFFSET.OFFSET_51),
  121. char_to_int(pSmart->MTP.B_OFFSET.OFFSET_51));
  122. pr_info("%s MTP Offset V87 R:%d G:%d B:%d\n", __func__,
  123. char_to_int(pSmart->MTP.R_OFFSET.OFFSET_87),
  124. char_to_int(pSmart->MTP.G_OFFSET.OFFSET_87),
  125. char_to_int(pSmart->MTP.B_OFFSET.OFFSET_87));
  126. pr_info("%s MTP Offset V151 R:%d G:%d B:%d\n", __func__,
  127. char_to_int(pSmart->MTP.R_OFFSET.OFFSET_151),
  128. char_to_int(pSmart->MTP.G_OFFSET.OFFSET_151),
  129. char_to_int(pSmart->MTP.B_OFFSET.OFFSET_151));
  130. pr_info("%s MTP Offset V203 R:%d G:%d B:%d\n", __func__,
  131. char_to_int(pSmart->MTP.R_OFFSET.OFFSET_203),
  132. char_to_int(pSmart->MTP.G_OFFSET.OFFSET_203),
  133. char_to_int(pSmart->MTP.B_OFFSET.OFFSET_203));
  134. pr_info("%s MTP Offset V255 R:%d G:%d B:%d\n", __func__,
  135. char_to_int_v255(pSmart->MTP.R_OFFSET.OFFSET_255_MSB,
  136. pSmart->MTP.R_OFFSET.OFFSET_255_LSB),
  137. char_to_int_v255(pSmart->MTP.G_OFFSET.OFFSET_255_MSB,
  138. pSmart->MTP.G_OFFSET.OFFSET_255_LSB),
  139. char_to_int_v255(pSmart->MTP.B_OFFSET.OFFSET_255_MSB,
  140. pSmart->MTP.B_OFFSET.OFFSET_255_LSB));
  141. }
  142. #endif
  143. #define v255_coefficient 129
  144. #define v255_denominator 640
  145. static int v255_adjustment(struct SMART_DIM *pSmart)
  146. {
  147. unsigned long long result_1, result_2, result_3, result_4;
  148. unsigned long long add_mtp;
  149. int LSB;
  150. int v255_value;
  151. v255_value = (V255_300CD_R_MSB << 8) | (V255_300CD_R_LSB);
  152. LSB = char_to_int_v255(pSmart->MTP.R_OFFSET.OFFSET_255_MSB,
  153. pSmart->MTP.R_OFFSET.OFFSET_255_LSB);
  154. add_mtp = LSB + v255_value;
  155. result_1 = result_2 = (v255_coefficient+add_mtp) << BIT_SHIFT;
  156. do_div(result_2, v255_denominator);
  157. result_3 = ((S6TNMR7_VREG0_REF_L-S6TNMR7_VREG0_REF_H) * result_2) >> BIT_SHIFT;
  158. result_4 = S6TNMR7_VREG0_REF_L - result_3;
  159. pSmart->RGB_OUTPUT.R_VOLTAGE.level_255 = result_4;
  160. pSmart->RGB_OUTPUT.R_VOLTAGE.level_0 = S6TNMR7_VREG0_REF_L;
  161. v255_value = (V255_300CD_G_MSB << 8) | (V255_300CD_G_LSB);
  162. LSB = char_to_int_v255(pSmart->MTP.G_OFFSET.OFFSET_255_MSB,
  163. pSmart->MTP.G_OFFSET.OFFSET_255_LSB);
  164. add_mtp = LSB + v255_value;
  165. result_1 = result_2 = (v255_coefficient+add_mtp) << BIT_SHIFT;
  166. do_div(result_2, v255_denominator);
  167. result_3 = ((S6TNMR7_VREG0_REF_L-S6TNMR7_VREG0_REF_H) * result_2) >> BIT_SHIFT;
  168. result_4 = S6TNMR7_VREG0_REF_L - result_3;
  169. pSmart->RGB_OUTPUT.G_VOLTAGE.level_255 = result_4;
  170. pSmart->RGB_OUTPUT.G_VOLTAGE.level_0 = S6TNMR7_VREG0_REF_L;
  171. v255_value = (V255_300CD_B_MSB << 8) | (V255_300CD_B_LSB);
  172. LSB = char_to_int_v255(pSmart->MTP.B_OFFSET.OFFSET_255_MSB,
  173. pSmart->MTP.B_OFFSET.OFFSET_255_LSB);
  174. add_mtp = LSB + v255_value;
  175. result_1 = result_2 = (v255_coefficient+add_mtp) << BIT_SHIFT;
  176. do_div(result_2, v255_denominator);
  177. result_3 = ((S6TNMR7_VREG0_REF_L-S6TNMR7_VREG0_REF_H) * result_2) >> BIT_SHIFT;
  178. result_4 = S6TNMR7_VREG0_REF_L - result_3;
  179. pSmart->RGB_OUTPUT.B_VOLTAGE.level_255 = result_4;
  180. pSmart->RGB_OUTPUT.B_VOLTAGE.level_0 = S6TNMR7_VREG0_REF_L;
  181. #ifdef SMART_DIMMING_DEBUG
  182. pr_info("%s MTP Offset VT R:%d G:%d B:%d\n", __func__,
  183. char_to_int(pSmart->MTP.R_OFFSET.OFFSET_1),
  184. char_to_int(pSmart->MTP.G_OFFSET.OFFSET_1),
  185. char_to_int(pSmart->MTP.B_OFFSET.OFFSET_1));
  186. pr_info("%s MTP Offset V3 R:%d G:%d B:%d\n", __func__,
  187. char_to_int(pSmart->MTP.R_OFFSET.OFFSET_3),
  188. char_to_int(pSmart->MTP.G_OFFSET.OFFSET_3),
  189. char_to_int(pSmart->MTP.B_OFFSET.OFFSET_3));
  190. pr_info("%s MTP Offset V11 R:%d G:%d B:%d\n", __func__,
  191. char_to_int(pSmart->MTP.R_OFFSET.OFFSET_11),
  192. char_to_int(pSmart->MTP.G_OFFSET.OFFSET_11),
  193. char_to_int(pSmart->MTP.B_OFFSET.OFFSET_11));
  194. pr_info("%s MTP Offset V23 R:%d G:%d B:%d\n", __func__,
  195. char_to_int(pSmart->MTP.R_OFFSET.OFFSET_23),
  196. char_to_int(pSmart->MTP.G_OFFSET.OFFSET_23),
  197. char_to_int(pSmart->MTP.B_OFFSET.OFFSET_23));
  198. pr_info("%s MTP Offset V35 R:%d G:%d B:%d\n", __func__,
  199. char_to_int(pSmart->MTP.R_OFFSET.OFFSET_35),
  200. char_to_int(pSmart->MTP.G_OFFSET.OFFSET_35),
  201. char_to_int(pSmart->MTP.B_OFFSET.OFFSET_35));
  202. pr_info("%s MTP Offset V51 R:%d G:%d B:%d\n", __func__,
  203. char_to_int(pSmart->MTP.R_OFFSET.OFFSET_51),
  204. char_to_int(pSmart->MTP.G_OFFSET.OFFSET_51),
  205. char_to_int(pSmart->MTP.B_OFFSET.OFFSET_51));
  206. pr_info("%s MTP Offset V87 R:%d G:%d B:%d\n", __func__,
  207. char_to_int(pSmart->MTP.R_OFFSET.OFFSET_87),
  208. char_to_int(pSmart->MTP.G_OFFSET.OFFSET_87),
  209. char_to_int(pSmart->MTP.B_OFFSET.OFFSET_87));
  210. pr_info("%s MTP Offset V151 R:%d G:%d B:%d\n", __func__,
  211. char_to_int(pSmart->MTP.R_OFFSET.OFFSET_151),
  212. char_to_int(pSmart->MTP.G_OFFSET.OFFSET_151),
  213. char_to_int(pSmart->MTP.B_OFFSET.OFFSET_151));
  214. pr_info("%s MTP Offset V203 R:%d G:%d B:%d\n", __func__,
  215. char_to_int(pSmart->MTP.R_OFFSET.OFFSET_203),
  216. char_to_int(pSmart->MTP.G_OFFSET.OFFSET_203),
  217. char_to_int(pSmart->MTP.B_OFFSET.OFFSET_203));
  218. pr_info("%s MTP Offset V255 R:%d G:%d B:%d\n", __func__,
  219. char_to_int_v255(pSmart->MTP.R_OFFSET.OFFSET_255_MSB,
  220. pSmart->MTP.R_OFFSET.OFFSET_255_LSB),
  221. char_to_int_v255(pSmart->MTP.G_OFFSET.OFFSET_255_MSB,
  222. pSmart->MTP.G_OFFSET.OFFSET_255_LSB),
  223. char_to_int_v255(pSmart->MTP.B_OFFSET.OFFSET_255_MSB,
  224. pSmart->MTP.B_OFFSET.OFFSET_255_LSB));
  225. pr_info("%s V255 RED:%d GREEN:%d BLUE:%d\n", __func__,
  226. pSmart->RGB_OUTPUT.R_VOLTAGE.level_255,
  227. pSmart->RGB_OUTPUT.G_VOLTAGE.level_255,
  228. pSmart->RGB_OUTPUT.B_VOLTAGE.level_255);
  229. #endif
  230. return 0;
  231. }
  232. static void v255_hexa(int *index, struct SMART_DIM *pSmart, char *str)
  233. {
  234. unsigned long long result_1, result_2, result_3;
  235. result_1 = S6TNMR7_VREG0_REF_L -
  236. (pSmart->GRAY.TABLE[index[V255_INDEX]].R_Gray);
  237. result_2 = result_1 * v255_denominator;
  238. do_div(result_2, (S6TNMR7_VREG0_REF_L-S6TNMR7_VREG0_REF_H));
  239. result_3 = result_2 - v255_coefficient;
  240. str[0] = (result_3 & 0xff00) >> 8;
  241. str[1] = result_3 & 0xff;
  242. result_1 = S6TNMR7_VREG0_REF_L -
  243. (pSmart->GRAY.TABLE[index[V255_INDEX]].G_Gray);
  244. result_2 = result_1 * v255_denominator;
  245. do_div(result_2, (S6TNMR7_VREG0_REF_L-S6TNMR7_VREG0_REF_H));
  246. result_3 = result_2 - v255_coefficient;
  247. str[2] = (result_3 & 0xff00) >> 8;
  248. str[3] = result_3 & 0xff;
  249. result_1 = S6TNMR7_VREG0_REF_L -
  250. (pSmart->GRAY.TABLE[index[V255_INDEX]].B_Gray);
  251. result_2 = result_1 * v255_denominator;
  252. do_div(result_2, (S6TNMR7_VREG0_REF_L-S6TNMR7_VREG0_REF_H));
  253. result_3 = result_2 - v255_coefficient;
  254. str[4] = (result_3 & 0xff00) >> 8;
  255. str[5] = result_3 & 0xff;
  256. }
  257. static int vt_coefficient[] = {
  258. 0, 12, 24, 36, 48,
  259. 60, 72, 84, 96, 108,
  260. 138, 148, 158, 168,
  261. 178, 186,
  262. };
  263. #define vt_denominator 600
  264. static int vt_adjustment(struct SMART_DIM *pSmart)
  265. {
  266. unsigned long long result_1, result_2, result_3, result_4;
  267. int add_mtp;
  268. int LSB;
  269. LSB = char_to_int(pSmart->MTP.R_OFFSET.OFFSET_1);
  270. add_mtp = LSB + VT_300CD_R;
  271. result_1 = result_2 = vt_coefficient[LSB] << BIT_SHIFT;
  272. do_div(result_2, vt_denominator);
  273. result_3 = (S6TNMR7_VREG0_REF_L * result_2) >> BIT_SHIFT;
  274. result_4 = S6TNMR7_VREG0_REF_L - result_3;
  275. pSmart->GRAY.VT_TABLE.R_Gray = result_4;
  276. LSB = char_to_int(pSmart->MTP.G_OFFSET.OFFSET_1);
  277. add_mtp = LSB + VT_300CD_G;
  278. result_1 = result_2 = vt_coefficient[LSB] << BIT_SHIFT;
  279. do_div(result_2, vt_denominator);
  280. result_3 = (S6TNMR7_VREG0_REF_L * result_2) >> BIT_SHIFT;
  281. result_4 = S6TNMR7_VREG0_REF_L - result_3;
  282. pSmart->GRAY.VT_TABLE.G_Gray = result_4;
  283. LSB = char_to_int(pSmart->MTP.B_OFFSET.OFFSET_1);
  284. add_mtp = LSB + VT_300CD_B;
  285. result_1 = result_2 = vt_coefficient[LSB] << BIT_SHIFT;
  286. do_div(result_2, vt_denominator);
  287. result_3 = (S6TNMR7_VREG0_REF_L * result_2) >> BIT_SHIFT;
  288. result_4 = S6TNMR7_VREG0_REF_L - result_3;
  289. pSmart->GRAY.VT_TABLE.B_Gray = result_4;
  290. #ifdef SMART_DIMMING_DEBUG
  291. pr_info("%s VT RED:%d GREEN:%d BLUE:%d\n", __func__,
  292. pSmart->GRAY.VT_TABLE.R_Gray,
  293. pSmart->GRAY.VT_TABLE.G_Gray,
  294. pSmart->GRAY.VT_TABLE.B_Gray);
  295. #endif
  296. return 0;
  297. }
  298. static void vt_hexa(int *index, struct SMART_DIM *pSmart, char *str)
  299. {
  300. str[30] = VT_300CD_R;
  301. str[31] = VT_300CD_G;
  302. str[32] = VT_300CD_B;
  303. }
  304. #define v203_coefficient 64
  305. #define v203_denominator 320
  306. static int v203_adjustment(struct SMART_DIM *pSmart)
  307. {
  308. unsigned long long result_1, result_2, result_3, result_4;
  309. int add_mtp;
  310. int LSB;
  311. LSB = char_to_int(pSmart->MTP.R_OFFSET.OFFSET_203);
  312. add_mtp = LSB + V203_300CD_R;
  313. result_1 = (pSmart->GRAY.VT_TABLE.R_Gray)
  314. - (pSmart->RGB_OUTPUT.R_VOLTAGE.level_255);
  315. result_2 = (v203_coefficient + add_mtp) << BIT_SHIFT;
  316. do_div(result_2, v203_denominator);
  317. result_3 = (result_1 * result_2) >> BIT_SHIFT;
  318. result_4 = (pSmart->GRAY.VT_TABLE.R_Gray) - result_3;
  319. pSmart->RGB_OUTPUT.R_VOLTAGE.level_203 = result_4;
  320. LSB = char_to_int(pSmart->MTP.G_OFFSET.OFFSET_203);
  321. add_mtp = LSB + V203_300CD_G;
  322. result_1 = (pSmart->GRAY.VT_TABLE.G_Gray)
  323. - (pSmart->RGB_OUTPUT.G_VOLTAGE.level_255);
  324. result_2 = (v203_coefficient + add_mtp) << BIT_SHIFT;
  325. do_div(result_2, v203_denominator);
  326. result_3 = (result_1 * result_2) >> BIT_SHIFT;
  327. result_4 = (pSmart->GRAY.VT_TABLE.G_Gray) - result_3;
  328. pSmart->RGB_OUTPUT.G_VOLTAGE.level_203 = result_4;
  329. LSB = char_to_int(pSmart->MTP.B_OFFSET.OFFSET_203);
  330. add_mtp = LSB + V203_300CD_B;
  331. result_1 = (pSmart->GRAY.VT_TABLE.B_Gray)
  332. - (pSmart->RGB_OUTPUT.B_VOLTAGE.level_255);
  333. result_2 = (v203_coefficient+add_mtp) << BIT_SHIFT;
  334. do_div(result_2, v203_denominator);
  335. result_3 = (result_1 * result_2) >> BIT_SHIFT;
  336. result_4 = (pSmart->GRAY.VT_TABLE.B_Gray) - result_3;
  337. pSmart->RGB_OUTPUT.B_VOLTAGE.level_203 = result_4;
  338. #ifdef SMART_DIMMING_DEBUG
  339. pr_info("%s V203 RED:%d GREEN:%d BLUE:%d\n", __func__,
  340. pSmart->RGB_OUTPUT.R_VOLTAGE.level_203,
  341. pSmart->RGB_OUTPUT.G_VOLTAGE.level_203,
  342. pSmart->RGB_OUTPUT.B_VOLTAGE.level_203);
  343. #endif
  344. return 0;
  345. }
  346. static void v203_hexa(int *index, struct SMART_DIM *pSmart, char *str)
  347. {
  348. unsigned long long result_1, result_2, result_3;
  349. result_1 = (pSmart->GRAY.VT_TABLE.R_Gray)
  350. - (pSmart->GRAY.TABLE[index[V203_INDEX]].R_Gray);
  351. result_2 = result_1 * v203_denominator;
  352. result_3 = (pSmart->GRAY.VT_TABLE.R_Gray)
  353. - (pSmart->GRAY.TABLE[index[V255_INDEX]].R_Gray);
  354. do_div(result_2, result_3);
  355. str[6] = (result_2 - v203_coefficient) & 0xff;
  356. result_1 = (pSmart->GRAY.VT_TABLE.G_Gray)
  357. - (pSmart->GRAY.TABLE[index[V203_INDEX]].G_Gray);
  358. result_2 = result_1 * v203_denominator;
  359. result_3 = (pSmart->GRAY.VT_TABLE.G_Gray)
  360. - (pSmart->GRAY.TABLE[index[V255_INDEX]].G_Gray);
  361. do_div(result_2, result_3);
  362. str[7] = (result_2 - v203_coefficient) & 0xff;
  363. result_1 = (pSmart->GRAY.VT_TABLE.B_Gray)
  364. - (pSmart->GRAY.TABLE[index[V203_INDEX]].B_Gray);
  365. result_2 = result_1 * v203_denominator;
  366. result_3 = (pSmart->GRAY.VT_TABLE.B_Gray)
  367. - (pSmart->GRAY.TABLE[index[V255_INDEX]].B_Gray);
  368. do_div(result_2, result_3);
  369. str[8] = (result_2 - v203_coefficient) & 0xff;
  370. }
  371. #define v151_coefficient 64
  372. #define v151_denominator 320
  373. static int v151_adjustment(struct SMART_DIM *pSmart)
  374. {
  375. unsigned long long result_1, result_2, result_3, result_4;
  376. int add_mtp;
  377. int LSB;
  378. LSB = char_to_int(pSmart->MTP.R_OFFSET.OFFSET_151);
  379. add_mtp = LSB + V151_300CD_R;
  380. result_1 = (pSmart->GRAY.VT_TABLE.R_Gray)
  381. - (pSmart->RGB_OUTPUT.R_VOLTAGE.level_203);
  382. result_2 = (v151_coefficient + add_mtp) << BIT_SHIFT;
  383. do_div(result_2, v151_denominator);
  384. result_3 = (result_1 * result_2) >> BIT_SHIFT;
  385. result_4 = (pSmart->GRAY.VT_TABLE.R_Gray) - result_3;
  386. pSmart->RGB_OUTPUT.R_VOLTAGE.level_151 = result_4;
  387. LSB = char_to_int(pSmart->MTP.G_OFFSET.OFFSET_151);
  388. add_mtp = LSB + V151_300CD_G;
  389. result_1 = (pSmart->GRAY.VT_TABLE.G_Gray)
  390. - (pSmart->RGB_OUTPUT.G_VOLTAGE.level_203);
  391. result_2 = (v151_coefficient + add_mtp) << BIT_SHIFT;
  392. do_div(result_2, v151_denominator);
  393. result_3 = (result_1 * result_2) >> BIT_SHIFT;
  394. result_4 = (pSmart->GRAY.VT_TABLE.G_Gray) - result_3;
  395. pSmart->RGB_OUTPUT.G_VOLTAGE.level_151 = result_4;
  396. LSB = char_to_int(pSmart->MTP.B_OFFSET.OFFSET_151);
  397. add_mtp = LSB + V151_300CD_B;
  398. result_1 = (pSmart->GRAY.VT_TABLE.B_Gray)
  399. - (pSmart->RGB_OUTPUT.B_VOLTAGE.level_203);
  400. result_2 = (v151_coefficient + add_mtp) << BIT_SHIFT;
  401. do_div(result_2, v151_denominator);
  402. result_3 = (result_1 * result_2) >> BIT_SHIFT;
  403. result_4 = (pSmart->GRAY.VT_TABLE.B_Gray) - result_3;
  404. pSmart->RGB_OUTPUT.B_VOLTAGE.level_151 = result_4;
  405. #ifdef SMART_DIMMING_DEBUG
  406. pr_info("%s V151 RED:%d GREEN:%d BLUE:%d\n", __func__,
  407. pSmart->RGB_OUTPUT.R_VOLTAGE.level_151,
  408. pSmart->RGB_OUTPUT.G_VOLTAGE.level_151,
  409. pSmart->RGB_OUTPUT.B_VOLTAGE.level_151);
  410. #endif
  411. return 0;
  412. }
  413. static void v151_hexa(int *index, struct SMART_DIM *pSmart, char *str)
  414. {
  415. unsigned long long result_1, result_2, result_3;
  416. result_1 = (pSmart->GRAY.VT_TABLE.R_Gray)
  417. - (pSmart->GRAY.TABLE[index[V151_INDEX]].R_Gray);
  418. result_2 = result_1 * v151_denominator;
  419. result_3 = (pSmart->GRAY.VT_TABLE.R_Gray)
  420. - (pSmart->GRAY.TABLE[index[V203_INDEX]].R_Gray);
  421. do_div(result_2, result_3);
  422. str[9] = (result_2 - v151_coefficient) & 0xff;
  423. result_1 = (pSmart->GRAY.VT_TABLE.G_Gray)
  424. - (pSmart->GRAY.TABLE[index[V151_INDEX]].G_Gray);
  425. result_2 = result_1 * v151_denominator;
  426. result_3 = (pSmart->GRAY.VT_TABLE.G_Gray)
  427. - (pSmart->GRAY.TABLE[index[V203_INDEX]].G_Gray);
  428. do_div(result_2, result_3);
  429. str[10] = (result_2 - v151_coefficient) & 0xff;
  430. result_1 = (pSmart->GRAY.VT_TABLE.B_Gray)
  431. - (pSmart->GRAY.TABLE[index[V151_INDEX]].B_Gray);
  432. result_2 = result_1 * v151_denominator;
  433. result_3 = (pSmart->GRAY.VT_TABLE.B_Gray)
  434. - (pSmart->GRAY.TABLE[index[V203_INDEX]].B_Gray);
  435. do_div(result_2, result_3);
  436. str[11] = (result_2 - v151_coefficient) & 0xff;
  437. }
  438. #define v87_coefficient 64
  439. #define v87_denominator 320
  440. static int v87_adjustment(struct SMART_DIM *pSmart)
  441. {
  442. unsigned long long result_1, result_2, result_3, result_4;
  443. int add_mtp;
  444. int LSB;
  445. LSB = char_to_int(pSmart->MTP.R_OFFSET.OFFSET_87);
  446. add_mtp = LSB + V87_300CD_R;
  447. result_1 = (pSmart->GRAY.VT_TABLE.R_Gray)
  448. - (pSmart->RGB_OUTPUT.R_VOLTAGE.level_151);
  449. result_2 = (v87_coefficient + add_mtp) << BIT_SHIFT;
  450. do_div(result_2, v87_denominator);
  451. result_3 = (result_1 * result_2) >> BIT_SHIFT;
  452. result_4 = (pSmart->GRAY.VT_TABLE.R_Gray) - result_3;
  453. pSmart->RGB_OUTPUT.R_VOLTAGE.level_87 = result_4;
  454. LSB = char_to_int(pSmart->MTP.G_OFFSET.OFFSET_87);
  455. add_mtp = LSB + V87_300CD_G;
  456. result_1 = (pSmart->GRAY.VT_TABLE.G_Gray)
  457. - (pSmart->RGB_OUTPUT.G_VOLTAGE.level_151);
  458. result_2 = (v87_coefficient + add_mtp) << BIT_SHIFT;
  459. do_div(result_2, v87_denominator);
  460. result_3 = (result_1 * result_2) >> BIT_SHIFT;
  461. result_4 = (pSmart->GRAY.VT_TABLE.G_Gray) - result_3;
  462. pSmart->RGB_OUTPUT.G_VOLTAGE.level_87 = result_4;
  463. LSB = char_to_int(pSmart->MTP.B_OFFSET.OFFSET_87);
  464. add_mtp = LSB + V87_300CD_B;
  465. result_1 = (pSmart->GRAY.VT_TABLE.B_Gray)
  466. - (pSmart->RGB_OUTPUT.B_VOLTAGE.level_151);
  467. result_2 = (v87_coefficient + add_mtp) << BIT_SHIFT;
  468. do_div(result_2, v87_denominator);
  469. result_3 = (result_1 * result_2) >> BIT_SHIFT;
  470. result_4 = (pSmart->GRAY.VT_TABLE.B_Gray) - result_3;
  471. pSmart->RGB_OUTPUT.B_VOLTAGE.level_87 = result_4;
  472. #ifdef SMART_DIMMING_DEBUG
  473. pr_info("%s V87 RED:%d GREEN:%d BLUE:%d\n", __func__,
  474. pSmart->RGB_OUTPUT.R_VOLTAGE.level_87,
  475. pSmart->RGB_OUTPUT.G_VOLTAGE.level_87,
  476. pSmart->RGB_OUTPUT.B_VOLTAGE.level_87);
  477. #endif
  478. return 0;
  479. }
  480. static void v87_hexa(int *index, struct SMART_DIM *pSmart, char *str)
  481. {
  482. unsigned long long result_1, result_2, result_3;
  483. result_1 = (pSmart->GRAY.VT_TABLE.R_Gray)
  484. - (pSmart->GRAY.TABLE[index[V87_INDEX]].R_Gray);
  485. result_2 = result_1 * v87_denominator;
  486. result_3 = (pSmart->GRAY.VT_TABLE.R_Gray)
  487. - (pSmart->GRAY.TABLE[index[V151_INDEX]].R_Gray);
  488. do_div(result_2, result_3);
  489. str[12] = (result_2 - v87_coefficient) & 0xff;
  490. result_1 = (pSmart->GRAY.VT_TABLE.G_Gray)
  491. - (pSmart->GRAY.TABLE[index[V87_INDEX]].G_Gray);
  492. result_2 = result_1 * v87_denominator;
  493. result_3 = (pSmart->GRAY.VT_TABLE.G_Gray)
  494. - (pSmart->GRAY.TABLE[index[V151_INDEX]].G_Gray);
  495. do_div(result_2, result_3);
  496. str[13] = (result_2 - v87_coefficient) & 0xff;
  497. result_1 = (pSmart->GRAY.VT_TABLE.B_Gray)
  498. - (pSmart->GRAY.TABLE[index[V87_INDEX]].B_Gray);
  499. result_2 = result_1 * v87_denominator;
  500. result_3 = (pSmart->GRAY.VT_TABLE.B_Gray)
  501. - (pSmart->GRAY.TABLE[index[V151_INDEX]].B_Gray);
  502. do_div(result_2, result_3);
  503. str[14] = (result_2 - v87_coefficient) & 0xff;
  504. }
  505. #define v51_coefficient 64
  506. #define v51_denominator 320
  507. static int v51_adjustment(struct SMART_DIM *pSmart)
  508. {
  509. unsigned long long result_1, result_2, result_3, result_4;
  510. int add_mtp;
  511. int LSB;
  512. LSB = char_to_int(pSmart->MTP.R_OFFSET.OFFSET_51);
  513. add_mtp = LSB + V51_300CD_R;
  514. result_1 = (pSmart->GRAY.VT_TABLE.R_Gray)
  515. - (pSmart->RGB_OUTPUT.R_VOLTAGE.level_87);
  516. result_2 = (v51_coefficient + add_mtp) << BIT_SHIFT;
  517. do_div(result_2, v51_denominator);
  518. result_3 = (result_1 * result_2) >> BIT_SHIFT;
  519. result_4 = (pSmart->GRAY.VT_TABLE.R_Gray) - result_3;
  520. pSmart->RGB_OUTPUT.R_VOLTAGE.level_51 = result_4;
  521. LSB = char_to_int(pSmart->MTP.G_OFFSET.OFFSET_51);
  522. add_mtp = LSB + V51_300CD_G;
  523. result_1 = (pSmart->GRAY.VT_TABLE.G_Gray)
  524. - (pSmart->RGB_OUTPUT.G_VOLTAGE.level_87);
  525. result_2 = (v51_coefficient + add_mtp) << BIT_SHIFT;
  526. do_div(result_2, v51_denominator);
  527. result_3 = (result_1 * result_2) >> BIT_SHIFT;
  528. result_4 = (pSmart->GRAY.VT_TABLE.G_Gray) - result_3;
  529. pSmart->RGB_OUTPUT.G_VOLTAGE.level_51 = result_4;
  530. LSB = char_to_int(pSmart->MTP.B_OFFSET.OFFSET_51);
  531. add_mtp = LSB + V51_300CD_B;
  532. result_1 = (pSmart->GRAY.VT_TABLE.B_Gray)
  533. - (pSmart->RGB_OUTPUT.B_VOLTAGE.level_87);
  534. result_2 = (v51_coefficient + add_mtp) << BIT_SHIFT;
  535. do_div(result_2, v51_denominator);
  536. result_3 = (result_1 * result_2) >> BIT_SHIFT;
  537. result_4 = (pSmart->GRAY.VT_TABLE.B_Gray) - result_3;
  538. pSmart->RGB_OUTPUT.B_VOLTAGE.level_51 = result_4;
  539. #ifdef SMART_DIMMING_DEBUG
  540. pr_info("%s V51 RED:%d GREEN:%d BLUE:%d\n", __func__,
  541. pSmart->RGB_OUTPUT.R_VOLTAGE.level_51,
  542. pSmart->RGB_OUTPUT.G_VOLTAGE.level_51,
  543. pSmart->RGB_OUTPUT.B_VOLTAGE.level_51);
  544. #endif
  545. return 0;
  546. }
  547. static void v51_hexa(int *index, struct SMART_DIM *pSmart, char *str)
  548. {
  549. unsigned long long result_1, result_2, result_3;
  550. result_1 = (pSmart->GRAY.VT_TABLE.R_Gray)
  551. - (pSmart->GRAY.TABLE[index[V51_INDEX]].R_Gray);
  552. result_2 = result_1 * v51_denominator;
  553. result_3 = (pSmart->GRAY.VT_TABLE.R_Gray)
  554. - (pSmart->GRAY.TABLE[index[V87_INDEX]].R_Gray);
  555. do_div(result_2, result_3);
  556. str[15] = (result_2 - v51_coefficient) & 0xff;
  557. result_1 = (pSmart->GRAY.VT_TABLE.G_Gray)
  558. - (pSmart->GRAY.TABLE[index[V51_INDEX]].G_Gray);
  559. result_2 = result_1 * v51_denominator;
  560. result_3 = (pSmart->GRAY.VT_TABLE.G_Gray)
  561. - (pSmart->GRAY.TABLE[index[V87_INDEX]].G_Gray);
  562. do_div(result_2, result_3);
  563. str[16] = (result_2 - v51_coefficient) & 0xff;
  564. result_1 = (pSmart->GRAY.VT_TABLE.B_Gray)
  565. - (pSmart->GRAY.TABLE[index[V51_INDEX]].B_Gray);
  566. result_2 = result_1 * v51_denominator;
  567. result_3 = (pSmart->GRAY.VT_TABLE.B_Gray)
  568. - (pSmart->GRAY.TABLE[index[V87_INDEX]].B_Gray);
  569. do_div(result_2, result_3);
  570. str[17] = (result_2 - v51_coefficient) & 0xff;
  571. }
  572. #define v35_coefficient 64
  573. #define v35_denominator 320
  574. static int v35_adjustment(struct SMART_DIM *pSmart)
  575. {
  576. unsigned long long result_1, result_2, result_3, result_4;
  577. int add_mtp;
  578. int LSB;
  579. LSB = char_to_int(pSmart->MTP.R_OFFSET.OFFSET_35);
  580. add_mtp = LSB + V35_300CD_R;
  581. result_1 = (pSmart->GRAY.VT_TABLE.R_Gray)
  582. - (pSmart->RGB_OUTPUT.R_VOLTAGE.level_51);
  583. result_2 = (v35_coefficient + add_mtp) << BIT_SHIFT;
  584. do_div(result_2, v35_denominator);
  585. result_3 = (result_1 * result_2) >> BIT_SHIFT;
  586. result_4 = (pSmart->GRAY.VT_TABLE.R_Gray) - result_3;
  587. pSmart->RGB_OUTPUT.R_VOLTAGE.level_35 = result_4;
  588. LSB = char_to_int(pSmart->MTP.G_OFFSET.OFFSET_35);
  589. add_mtp = LSB + V35_300CD_G;
  590. result_1 = (pSmart->GRAY.VT_TABLE.G_Gray)
  591. - (pSmart->RGB_OUTPUT.G_VOLTAGE.level_51);
  592. result_2 = (v35_coefficient + add_mtp) << BIT_SHIFT;
  593. do_div(result_2, v35_denominator);
  594. result_3 = (result_1 * result_2) >> BIT_SHIFT;
  595. result_4 = (pSmart->GRAY.VT_TABLE.G_Gray) - result_3;
  596. pSmart->RGB_OUTPUT.G_VOLTAGE.level_35 = result_4;
  597. LSB = char_to_int(pSmart->MTP.B_OFFSET.OFFSET_35);
  598. add_mtp = LSB + V35_300CD_B;
  599. result_1 = (pSmart->GRAY.VT_TABLE.B_Gray)
  600. - (pSmart->RGB_OUTPUT.B_VOLTAGE.level_51);
  601. result_2 = (v35_coefficient + add_mtp) << BIT_SHIFT;
  602. do_div(result_2, v35_denominator);
  603. result_3 = (result_1 * result_2) >> BIT_SHIFT;
  604. result_4 = (pSmart->GRAY.VT_TABLE.B_Gray) - result_3;
  605. pSmart->RGB_OUTPUT.B_VOLTAGE.level_35 = result_4;
  606. #ifdef SMART_DIMMING_DEBUG
  607. pr_info("%s V35 RED:%d GREEN:%d BLUE:%d\n", __func__,
  608. pSmart->RGB_OUTPUT.R_VOLTAGE.level_35,
  609. pSmart->RGB_OUTPUT.G_VOLTAGE.level_35,
  610. pSmart->RGB_OUTPUT.B_VOLTAGE.level_35);
  611. #endif
  612. return 0;
  613. }
  614. static void v35_hexa(int *index, struct SMART_DIM *pSmart, char *str)
  615. {
  616. unsigned long long result_1, result_2, result_3;
  617. result_1 = (pSmart->GRAY.VT_TABLE.R_Gray)
  618. - (pSmart->GRAY.TABLE[index[V35_INDEX]].R_Gray);
  619. result_2 = result_1 * v35_denominator;
  620. result_3 = (pSmart->GRAY.VT_TABLE.R_Gray)
  621. - (pSmart->GRAY.TABLE[index[V51_INDEX]].R_Gray);
  622. do_div(result_2, result_3);
  623. str[18] = (result_2 - v35_coefficient) & 0xff;
  624. result_1 = (pSmart->GRAY.VT_TABLE.G_Gray)
  625. - (pSmart->GRAY.TABLE[index[V35_INDEX]].G_Gray);
  626. result_2 = result_1 * v35_denominator;
  627. result_3 = (pSmart->GRAY.VT_TABLE.G_Gray)
  628. - (pSmart->GRAY.TABLE[index[V51_INDEX]].G_Gray);
  629. do_div(result_2, result_3);
  630. str[19] = (result_2 - v35_coefficient) & 0xff;
  631. result_1 = (pSmart->GRAY.VT_TABLE.B_Gray)
  632. - (pSmart->GRAY.TABLE[index[V35_INDEX]].B_Gray);
  633. result_2 = result_1 * v35_denominator;
  634. result_3 = (pSmart->GRAY.VT_TABLE.B_Gray)
  635. - (pSmart->GRAY.TABLE[index[V51_INDEX]].B_Gray);
  636. do_div(result_2, result_3);
  637. str[20] = (result_2 - v35_coefficient) & 0xff;
  638. }
  639. #define v23_coefficient 64
  640. #define v23_denominator 320
  641. static int v23_adjustment(struct SMART_DIM *pSmart)
  642. {
  643. unsigned long long result_1, result_2, result_3, result_4;
  644. int add_mtp;
  645. int LSB;
  646. LSB = char_to_int(pSmart->MTP.R_OFFSET.OFFSET_23);
  647. add_mtp = LSB + V23_300CD_R;
  648. result_1 = (pSmart->GRAY.VT_TABLE.R_Gray)
  649. - (pSmart->RGB_OUTPUT.R_VOLTAGE.level_35);
  650. result_2 = (v23_coefficient + add_mtp) << BIT_SHIFT;
  651. do_div(result_2, v23_denominator);
  652. result_3 = (result_1 * result_2) >> BIT_SHIFT;
  653. result_4 = (pSmart->GRAY.VT_TABLE.R_Gray) - result_3;
  654. pSmart->RGB_OUTPUT.R_VOLTAGE.level_23 = result_4;
  655. LSB = char_to_int(pSmart->MTP.G_OFFSET.OFFSET_23);
  656. add_mtp = LSB + V23_300CD_G;
  657. result_1 = (pSmart->GRAY.VT_TABLE.G_Gray)
  658. - (pSmart->RGB_OUTPUT.G_VOLTAGE.level_35);
  659. result_2 = (v23_coefficient + add_mtp) << BIT_SHIFT;
  660. do_div(result_2, v23_denominator);
  661. result_3 = (result_1 * result_2) >> BIT_SHIFT;
  662. result_4 = (pSmart->GRAY.VT_TABLE.G_Gray) - result_3;
  663. pSmart->RGB_OUTPUT.G_VOLTAGE.level_23 = result_4;
  664. LSB = char_to_int(pSmart->MTP.B_OFFSET.OFFSET_23);
  665. add_mtp = LSB + V23_300CD_B;
  666. result_1 = (pSmart->GRAY.VT_TABLE.B_Gray)
  667. - (pSmart->RGB_OUTPUT.B_VOLTAGE.level_35);
  668. result_2 = (v23_coefficient + add_mtp) << BIT_SHIFT;
  669. do_div(result_2, v23_denominator);
  670. result_3 = (result_1 * result_2) >> BIT_SHIFT;
  671. result_4 = (pSmart->GRAY.VT_TABLE.B_Gray) - result_3;
  672. pSmart->RGB_OUTPUT.B_VOLTAGE.level_23 = result_4;
  673. #ifdef SMART_DIMMING_DEBUG
  674. pr_info("%s V23 RED:%d GREEN:%d BLUE:%d\n", __func__,
  675. pSmart->RGB_OUTPUT.R_VOLTAGE.level_23,
  676. pSmart->RGB_OUTPUT.G_VOLTAGE.level_23,
  677. pSmart->RGB_OUTPUT.B_VOLTAGE.level_23);
  678. #endif
  679. return 0;
  680. }
  681. static void v23_hexa(int *index, struct SMART_DIM *pSmart, char *str)
  682. {
  683. unsigned long long result_1, result_2, result_3;
  684. result_1 = (pSmart->GRAY.VT_TABLE.R_Gray)
  685. - (pSmart->GRAY.TABLE[index[V23_INDEX]].R_Gray);
  686. result_2 = result_1 * v23_denominator;
  687. result_3 = (pSmart->GRAY.VT_TABLE.R_Gray)
  688. - (pSmart->GRAY.TABLE[index[V35_INDEX]].R_Gray);
  689. do_div(result_2, result_3);
  690. str[21] = (result_2 - v23_coefficient) & 0xff;
  691. result_1 = (pSmart->GRAY.VT_TABLE.G_Gray)
  692. - (pSmart->GRAY.TABLE[index[V23_INDEX]].G_Gray);
  693. result_2 = result_1 * v23_denominator;
  694. result_3 = (pSmart->GRAY.VT_TABLE.G_Gray)
  695. - (pSmart->GRAY.TABLE[index[V35_INDEX]].G_Gray);
  696. do_div(result_2, result_3);
  697. str[22] = (result_2 - v23_coefficient) & 0xff;
  698. result_1 = (pSmart->GRAY.VT_TABLE.B_Gray)
  699. - (pSmart->GRAY.TABLE[index[V23_INDEX]].B_Gray);
  700. result_2 = result_1 * v23_denominator;
  701. result_3 = (pSmart->GRAY.VT_TABLE.B_Gray)
  702. - (pSmart->GRAY.TABLE[index[V35_INDEX]].B_Gray);
  703. do_div(result_2, result_3);
  704. str[23] = (result_2 - v23_coefficient) & 0xff;
  705. }
  706. #define v11_coefficient 64
  707. #define v11_denominator 320
  708. static int v11_adjustment(struct SMART_DIM *pSmart)
  709. {
  710. unsigned long long result_1, result_2, result_3, result_4;
  711. int add_mtp;
  712. int LSB;
  713. LSB = char_to_int(pSmart->MTP.R_OFFSET.OFFSET_11);
  714. add_mtp = LSB + V11_300CD_R;
  715. result_1 = (pSmart->GRAY.VT_TABLE.R_Gray)
  716. - (pSmart->RGB_OUTPUT.R_VOLTAGE.level_23);
  717. result_2 = (v11_coefficient + add_mtp) << BIT_SHIFT;
  718. do_div(result_2, v11_denominator);
  719. result_3 = (result_1 * result_2) >> BIT_SHIFT;
  720. result_4 = (pSmart->GRAY.VT_TABLE.R_Gray) - result_3;
  721. pSmart->RGB_OUTPUT.R_VOLTAGE.level_11 = result_4;
  722. LSB = char_to_int(pSmart->MTP.G_OFFSET.OFFSET_11);
  723. add_mtp = LSB + V11_300CD_G;
  724. result_1 = (pSmart->GRAY.VT_TABLE.G_Gray)
  725. - (pSmart->RGB_OUTPUT.G_VOLTAGE.level_23);
  726. result_2 = (v11_coefficient + add_mtp) << BIT_SHIFT;
  727. do_div(result_2, v11_denominator);
  728. result_3 = (result_1 * result_2) >> BIT_SHIFT;
  729. result_4 = (pSmart->GRAY.VT_TABLE.G_Gray) - result_3;
  730. pSmart->RGB_OUTPUT.G_VOLTAGE.level_11 = result_4;
  731. LSB = char_to_int(pSmart->MTP.B_OFFSET.OFFSET_11);
  732. add_mtp = LSB + V11_300CD_B;
  733. result_1 = (pSmart->GRAY.VT_TABLE.B_Gray)
  734. - (pSmart->RGB_OUTPUT.B_VOLTAGE.level_23);
  735. result_2 = (v11_coefficient + add_mtp) << BIT_SHIFT;
  736. do_div(result_2, v11_denominator);
  737. result_3 = (result_1 * result_2) >> BIT_SHIFT;
  738. result_4 = (pSmart->GRAY.VT_TABLE.B_Gray) - result_3;
  739. pSmart->RGB_OUTPUT.B_VOLTAGE.level_11 = result_4;
  740. #ifdef SMART_DIMMING_DEBUG
  741. pr_info("%s V11 RED:%d GREEN:%d BLUE:%d\n", __func__,
  742. pSmart->RGB_OUTPUT.R_VOLTAGE.level_11,
  743. pSmart->RGB_OUTPUT.G_VOLTAGE.level_11,
  744. pSmart->RGB_OUTPUT.B_VOLTAGE.level_11);
  745. #endif
  746. return 0;
  747. }
  748. static void v11_hexa(int *index, struct SMART_DIM *pSmart, char *str)
  749. {
  750. unsigned long long result_1, result_2, result_3;
  751. result_1 = (pSmart->GRAY.VT_TABLE.R_Gray)
  752. - (pSmart->GRAY.TABLE[index[V11_INDEX]].R_Gray);
  753. result_2 = result_1 * v11_denominator;
  754. result_3 = (pSmart->GRAY.VT_TABLE.R_Gray)
  755. - (pSmart->GRAY.TABLE[index[V23_INDEX]].R_Gray);
  756. do_div(result_2, result_3);
  757. str[24] = (result_2 - v11_coefficient) & 0xff;
  758. result_1 = (pSmart->GRAY.VT_TABLE.G_Gray)
  759. - (pSmart->GRAY.TABLE[index[V11_INDEX]].G_Gray);
  760. result_2 = result_1 * v11_denominator;
  761. result_3 = (pSmart->GRAY.VT_TABLE.G_Gray)
  762. - (pSmart->GRAY.TABLE[index[V23_INDEX]].G_Gray);
  763. do_div(result_2, result_3);
  764. str[25] = (result_2 - v11_coefficient) & 0xff;
  765. result_1 = (pSmart->GRAY.VT_TABLE.B_Gray)
  766. - (pSmart->GRAY.TABLE[index[V11_INDEX]].B_Gray);
  767. result_2 = result_1 * v11_denominator;
  768. result_3 = (pSmart->GRAY.VT_TABLE.B_Gray)
  769. - (pSmart->GRAY.TABLE[index[V23_INDEX]].B_Gray);
  770. do_div(result_2, result_3);
  771. str[26] = (result_2 - v11_coefficient) & 0xff;
  772. }
  773. #define v3_coefficient 64
  774. #define v3_denominator 320
  775. static int v3_adjustment(struct SMART_DIM *pSmart)
  776. {
  777. unsigned long long result_1, result_2, result_3, result_4;
  778. int add_mtp;
  779. int LSB;
  780. LSB = char_to_int(pSmart->MTP.R_OFFSET.OFFSET_3);
  781. add_mtp = LSB + V3_300CD_R;
  782. result_1 = (S6TNMR7_VREG0_REF_L)
  783. - (pSmart->RGB_OUTPUT.R_VOLTAGE.level_11);
  784. result_2 = (v3_coefficient + add_mtp) << BIT_SHIFT;
  785. do_div(result_2, v3_denominator);
  786. result_3 = (result_1 * result_2) >> BIT_SHIFT;
  787. result_4 = (S6TNMR7_VREG0_REF_L) - result_3;
  788. pSmart->RGB_OUTPUT.R_VOLTAGE.level_3 = result_4;
  789. LSB = char_to_int(pSmart->MTP.G_OFFSET.OFFSET_3);
  790. add_mtp = LSB + V3_300CD_G;
  791. result_1 = (S6TNMR7_VREG0_REF_L)
  792. - (pSmart->RGB_OUTPUT.G_VOLTAGE.level_11);
  793. result_2 = (v3_coefficient + add_mtp) << BIT_SHIFT;
  794. do_div(result_2, v3_denominator);
  795. result_3 = (result_1 * result_2) >> BIT_SHIFT;
  796. result_4 = (S6TNMR7_VREG0_REF_L) - result_3;
  797. pSmart->RGB_OUTPUT.G_VOLTAGE.level_3 = result_4;
  798. LSB = char_to_int(pSmart->MTP.B_OFFSET.OFFSET_3);
  799. add_mtp = LSB + V3_300CD_B;
  800. result_1 = (S6TNMR7_VREG0_REF_L)
  801. - (pSmart->RGB_OUTPUT.B_VOLTAGE.level_11);
  802. result_2 = (v3_coefficient + add_mtp) << BIT_SHIFT;
  803. do_div(result_2, v3_denominator);
  804. result_3 = (result_1 * result_2) >> BIT_SHIFT;
  805. result_4 = (S6TNMR7_VREG0_REF_L) - result_3;
  806. pSmart->RGB_OUTPUT.B_VOLTAGE.level_3 = result_4;
  807. #ifdef SMART_DIMMING_DEBUG
  808. pr_info("%s V3 RED:%d GREEN:%d BLUE:%d\n", __func__,
  809. pSmart->RGB_OUTPUT.R_VOLTAGE.level_3,
  810. pSmart->RGB_OUTPUT.G_VOLTAGE.level_3,
  811. pSmart->RGB_OUTPUT.B_VOLTAGE.level_3);
  812. #endif
  813. return 0;
  814. }
  815. static void v3_hexa(int *index, struct SMART_DIM *pSmart, char *str)
  816. {
  817. unsigned long long result_1, result_2, result_3;
  818. result_1 = (S6TNMR7_VREG0_REF_L)
  819. - (pSmart->GRAY.TABLE[index[V3_INDEX]].R_Gray);
  820. result_2 = result_1 * v3_denominator;
  821. result_3 = (S6TNMR7_VREG0_REF_L)
  822. - (pSmart->GRAY.TABLE[index[V11_INDEX]].R_Gray);
  823. do_div(result_2, result_3);
  824. str[27] = (result_2 - v3_coefficient) & 0xff;
  825. result_1 = (S6TNMR7_VREG0_REF_L)
  826. - (pSmart->GRAY.TABLE[index[V3_INDEX]].G_Gray);
  827. result_2 = result_1 * v3_denominator;
  828. result_3 = (S6TNMR7_VREG0_REF_L)
  829. - (pSmart->GRAY.TABLE[index[V11_INDEX]].G_Gray);
  830. do_div(result_2, result_3);
  831. str[28] = (result_2 - v3_coefficient) & 0xff;
  832. result_1 = (S6TNMR7_VREG0_REF_L)
  833. - (pSmart->GRAY.TABLE[index[V3_INDEX]].B_Gray);
  834. result_2 = result_1 * v3_denominator;
  835. result_3 = (S6TNMR7_VREG0_REF_L)
  836. - (pSmart->GRAY.TABLE[index[V11_INDEX]].B_Gray);
  837. do_div(result_2, result_3);
  838. str[29] = (result_2 - v3_coefficient) & 0xff;
  839. }
  840. /*V0,V1,V3,V11,V23,V35,V51,V87,V151,V203,V255*/
  841. static int S6TNMR7_ARRAY[S6TNMR7_MAX] = {0, 1, 3, 11, 23, 35, 51, 87, 151, 203, 255};
  842. #define V0toV3_Coefficient 2
  843. #define V0toV3_Multiple 1
  844. #define V0toV3_denominator 3
  845. #define V3toV11_Coefficient 7
  846. #define V3toV11_Multiple 1
  847. #define V3toV11_denominator 8
  848. #define V11toV23_Coefficient 11
  849. #define V11toV23_Multiple 1
  850. #define V11toV23_denominator 12
  851. #define V23toV35_Coefficient 11
  852. #define V23toV35_Multiple 1
  853. #define V23toV35_denominator 12
  854. #define V35toV51_Coefficient 15
  855. #define V35toV51_Multiple 1
  856. #define V35toV51_denominator 16
  857. #define V51toV87_Coefficient 35
  858. #define V51toV87_Multiple 1
  859. #define V51toV87_denominator 36
  860. #define V87toV151_Coefficient 63
  861. #define V87toV151_Multiple 1
  862. #define V87toV151_denominator 64
  863. #define V151toV203_Coefficient 51
  864. #define V151toV203_Multiple 1
  865. #define V151toV203_denominator 52
  866. #define V203toV255_Coefficient 51
  867. #define V203toV255_Multiple 1
  868. #define V203toV255_denominator 52
  869. static int cal_gray_scale_linear(int up, int low, int coeff,
  870. int mul, int deno, int cnt)
  871. {
  872. unsigned long long result_1, result_2, result_3, result_4;
  873. result_1 = up - low;
  874. result_2 = (result_1 * (coeff - (cnt * mul))) << BIT_SHIFT;
  875. do_div(result_2, deno);
  876. result_3 = result_2 >> BIT_SHIFT;
  877. result_4 = low + result_3;
  878. return (int)result_4;
  879. }
  880. static int generate_gray_scale(struct SMART_DIM *pSmart)
  881. {
  882. int cnt = 0, cal_cnt = 0;
  883. int array_index = 0;
  884. struct GRAY_VOLTAGE *ptable = (struct GRAY_VOLTAGE *)
  885. (&(pSmart->GRAY.TABLE));
  886. for (cnt = 0; cnt < S6TNMR7_MAX; cnt++) {
  887. pSmart->GRAY.TABLE[S6TNMR7_ARRAY[cnt]].R_Gray =
  888. ((int *)&(pSmart->RGB_OUTPUT.R_VOLTAGE))[cnt];
  889. pSmart->GRAY.TABLE[S6TNMR7_ARRAY[cnt]].G_Gray =
  890. ((int *)&(pSmart->RGB_OUTPUT.G_VOLTAGE))[cnt];
  891. pSmart->GRAY.TABLE[S6TNMR7_ARRAY[cnt]].B_Gray =
  892. ((int *)&(pSmart->RGB_OUTPUT.B_VOLTAGE))[cnt];
  893. }
  894. /*
  895. below codes use hard coded value.
  896. So it is possible to modify on each model.
  897. V0,V1,V3,V11,V23,V35,V51,V87,V151,V203,V255
  898. */
  899. for (cnt = 0; cnt < S6TNMR7_GRAY_SCALE_MAX; cnt++) {
  900. if (cnt == S6TNMR7_ARRAY[0]) {
  901. /* 0 */
  902. array_index = 0;
  903. cal_cnt = 0;
  904. } else if ((cnt > S6TNMR7_ARRAY[0]) &&
  905. (cnt < S6TNMR7_ARRAY[2])) {
  906. /* 1 ~ 2 */
  907. array_index = 2;
  908. pSmart->GRAY.TABLE[cnt].R_Gray = cal_gray_scale_linear(
  909. ptable[S6TNMR7_ARRAY[array_index-2]].R_Gray,
  910. ptable[S6TNMR7_ARRAY[array_index]].R_Gray,
  911. V0toV3_Coefficient, V0toV3_Multiple,
  912. V0toV3_denominator, cal_cnt);
  913. pSmart->GRAY.TABLE[cnt].G_Gray = cal_gray_scale_linear(
  914. ptable[S6TNMR7_ARRAY[array_index-2]].G_Gray,
  915. ptable[S6TNMR7_ARRAY[array_index]].G_Gray,
  916. V0toV3_Coefficient, V0toV3_Multiple,
  917. V0toV3_denominator, cal_cnt);
  918. pSmart->GRAY.TABLE[cnt].B_Gray = cal_gray_scale_linear(
  919. ptable[S6TNMR7_ARRAY[array_index-2]].B_Gray,
  920. ptable[S6TNMR7_ARRAY[array_index]].B_Gray,
  921. V0toV3_Coefficient, V0toV3_Multiple,
  922. V0toV3_denominator , cal_cnt);
  923. cal_cnt++;
  924. } else if (cnt == S6TNMR7_ARRAY[2]) {
  925. /* 3 */
  926. cal_cnt = 0;
  927. } else if ((cnt > S6TNMR7_ARRAY[2]) &&
  928. (cnt < S6TNMR7_ARRAY[3])) {
  929. /* 4 ~ 10 */
  930. array_index = 3;
  931. pSmart->GRAY.TABLE[cnt].R_Gray = cal_gray_scale_linear(
  932. ptable[S6TNMR7_ARRAY[array_index-1]].R_Gray,
  933. ptable[S6TNMR7_ARRAY[array_index]].R_Gray,
  934. V3toV11_Coefficient, V3toV11_Multiple,
  935. V3toV11_denominator, cal_cnt);
  936. pSmart->GRAY.TABLE[cnt].G_Gray = cal_gray_scale_linear(
  937. ptable[S6TNMR7_ARRAY[array_index-1]].G_Gray,
  938. ptable[S6TNMR7_ARRAY[array_index]].G_Gray,
  939. V3toV11_Coefficient, V3toV11_Multiple,
  940. V3toV11_denominator, cal_cnt);
  941. pSmart->GRAY.TABLE[cnt].B_Gray = cal_gray_scale_linear(
  942. ptable[S6TNMR7_ARRAY[array_index-1]].B_Gray,
  943. ptable[S6TNMR7_ARRAY[array_index]].B_Gray,
  944. V3toV11_Coefficient, V3toV11_Multiple,
  945. V3toV11_denominator , cal_cnt);
  946. cal_cnt++;
  947. } else if (cnt == S6TNMR7_ARRAY[3]) {
  948. /* 11 */
  949. cal_cnt = 0;
  950. } else if ((cnt > S6TNMR7_ARRAY[3]) &&
  951. (cnt < S6TNMR7_ARRAY[4])) {
  952. /* 12 ~ 22 */
  953. array_index = 4;
  954. pSmart->GRAY.TABLE[cnt].R_Gray = cal_gray_scale_linear(
  955. ptable[S6TNMR7_ARRAY[array_index-1]].R_Gray,
  956. ptable[S6TNMR7_ARRAY[array_index]].R_Gray,
  957. V11toV23_Coefficient, V11toV23_Multiple,
  958. V11toV23_denominator, cal_cnt);
  959. pSmart->GRAY.TABLE[cnt].G_Gray = cal_gray_scale_linear(
  960. ptable[S6TNMR7_ARRAY[array_index-1]].G_Gray,
  961. ptable[S6TNMR7_ARRAY[array_index]].G_Gray,
  962. V11toV23_Coefficient, V11toV23_Multiple,
  963. V11toV23_denominator, cal_cnt);
  964. pSmart->GRAY.TABLE[cnt].B_Gray = cal_gray_scale_linear(
  965. ptable[S6TNMR7_ARRAY[array_index-1]].B_Gray,
  966. ptable[S6TNMR7_ARRAY[array_index]].B_Gray,
  967. V11toV23_Coefficient, V11toV23_Multiple,
  968. V11toV23_denominator , cal_cnt);
  969. cal_cnt++;
  970. } else if (cnt == S6TNMR7_ARRAY[4]) {
  971. /* 23 */
  972. cal_cnt = 0;
  973. } else if ((cnt > S6TNMR7_ARRAY[4]) &&
  974. (cnt < S6TNMR7_ARRAY[5])) {
  975. /* 24 ~ 34 */
  976. array_index = 5;
  977. pSmart->GRAY.TABLE[cnt].R_Gray = cal_gray_scale_linear(
  978. ptable[S6TNMR7_ARRAY[array_index-1]].R_Gray,
  979. ptable[S6TNMR7_ARRAY[array_index]].R_Gray,
  980. V23toV35_Coefficient, V23toV35_Multiple,
  981. V23toV35_denominator, cal_cnt);
  982. pSmart->GRAY.TABLE[cnt].G_Gray = cal_gray_scale_linear(
  983. ptable[S6TNMR7_ARRAY[array_index-1]].G_Gray,
  984. ptable[S6TNMR7_ARRAY[array_index]].G_Gray,
  985. V23toV35_Coefficient, V23toV35_Multiple,
  986. V23toV35_denominator, cal_cnt);
  987. pSmart->GRAY.TABLE[cnt].B_Gray = cal_gray_scale_linear(
  988. ptable[S6TNMR7_ARRAY[array_index-1]].B_Gray,
  989. ptable[S6TNMR7_ARRAY[array_index]].B_Gray,
  990. V23toV35_Coefficient, V23toV35_Multiple,
  991. V23toV35_denominator , cal_cnt);
  992. cal_cnt++;
  993. } else if (cnt == S6TNMR7_ARRAY[5]) {
  994. /* 35 */
  995. cal_cnt = 0;
  996. } else if ((cnt > S6TNMR7_ARRAY[5]) &&
  997. (cnt < S6TNMR7_ARRAY[6])) {
  998. /* 36 ~ 50 */
  999. array_index = 6;
  1000. pSmart->GRAY.TABLE[cnt].R_Gray = cal_gray_scale_linear(
  1001. ptable[S6TNMR7_ARRAY[array_index-1]].R_Gray,
  1002. ptable[S6TNMR7_ARRAY[array_index]].R_Gray,
  1003. V35toV51_Coefficient, V35toV51_Multiple,
  1004. V35toV51_denominator, cal_cnt);
  1005. pSmart->GRAY.TABLE[cnt].G_Gray = cal_gray_scale_linear(
  1006. ptable[S6TNMR7_ARRAY[array_index-1]].G_Gray,
  1007. ptable[S6TNMR7_ARRAY[array_index]].G_Gray,
  1008. V35toV51_Coefficient, V35toV51_Multiple,
  1009. V35toV51_denominator, cal_cnt);
  1010. pSmart->GRAY.TABLE[cnt].B_Gray = cal_gray_scale_linear(
  1011. ptable[S6TNMR7_ARRAY[array_index-1]].B_Gray,
  1012. ptable[S6TNMR7_ARRAY[array_index]].B_Gray,
  1013. V35toV51_Coefficient, V35toV51_Multiple,
  1014. V35toV51_denominator, cal_cnt);
  1015. cal_cnt++;
  1016. } else if (cnt == S6TNMR7_ARRAY[6]) {
  1017. /* 51 */
  1018. cal_cnt = 0;
  1019. } else if ((cnt > S6TNMR7_ARRAY[6]) &&
  1020. (cnt < S6TNMR7_ARRAY[7])) {
  1021. /* 52 ~ 86 */
  1022. array_index = 7;
  1023. pSmart->GRAY.TABLE[cnt].R_Gray = cal_gray_scale_linear(
  1024. ptable[S6TNMR7_ARRAY[array_index-1]].R_Gray,
  1025. ptable[S6TNMR7_ARRAY[array_index]].R_Gray,
  1026. V51toV87_Coefficient, V51toV87_Multiple,
  1027. V51toV87_denominator, cal_cnt);
  1028. pSmart->GRAY.TABLE[cnt].G_Gray = cal_gray_scale_linear(
  1029. ptable[S6TNMR7_ARRAY[array_index-1]].G_Gray,
  1030. ptable[S6TNMR7_ARRAY[array_index]].G_Gray,
  1031. V51toV87_Coefficient, V51toV87_Multiple,
  1032. V51toV87_denominator, cal_cnt);
  1033. pSmart->GRAY.TABLE[cnt].B_Gray = cal_gray_scale_linear(
  1034. ptable[S6TNMR7_ARRAY[array_index-1]].B_Gray,
  1035. ptable[S6TNMR7_ARRAY[array_index]].B_Gray,
  1036. V51toV87_Coefficient, V51toV87_Multiple,
  1037. V51toV87_denominator, cal_cnt);
  1038. cal_cnt++;
  1039. } else if (cnt == S6TNMR7_ARRAY[7]) {
  1040. /* 87 */
  1041. cal_cnt = 0;
  1042. } else if ((cnt > S6TNMR7_ARRAY[7]) &&
  1043. (cnt < S6TNMR7_ARRAY[8])) {
  1044. /* 88 ~ 150 */
  1045. array_index = 8;
  1046. pSmart->GRAY.TABLE[cnt].R_Gray = cal_gray_scale_linear(
  1047. ptable[S6TNMR7_ARRAY[array_index-1]].R_Gray,
  1048. ptable[S6TNMR7_ARRAY[array_index]].R_Gray,
  1049. V87toV151_Coefficient, V87toV151_Multiple,
  1050. V87toV151_denominator, cal_cnt);
  1051. pSmart->GRAY.TABLE[cnt].G_Gray = cal_gray_scale_linear(
  1052. ptable[S6TNMR7_ARRAY[array_index-1]].G_Gray,
  1053. ptable[S6TNMR7_ARRAY[array_index]].G_Gray,
  1054. V87toV151_Coefficient, V87toV151_Multiple,
  1055. V87toV151_denominator, cal_cnt);
  1056. pSmart->GRAY.TABLE[cnt].B_Gray = cal_gray_scale_linear(
  1057. ptable[S6TNMR7_ARRAY[array_index-1]].B_Gray,
  1058. ptable[S6TNMR7_ARRAY[array_index]].B_Gray,
  1059. V87toV151_Coefficient, V87toV151_Multiple,
  1060. V87toV151_denominator, cal_cnt);
  1061. cal_cnt++;
  1062. } else if (cnt == S6TNMR7_ARRAY[8]) {
  1063. /* 151 */
  1064. cal_cnt = 0;
  1065. } else if ((cnt > S6TNMR7_ARRAY[8]) &&
  1066. (cnt < S6TNMR7_ARRAY[9])) {
  1067. /* 152 ~ 202 */
  1068. array_index = 9;
  1069. pSmart->GRAY.TABLE[cnt].R_Gray = cal_gray_scale_linear(
  1070. ptable[S6TNMR7_ARRAY[array_index-1]].R_Gray,
  1071. ptable[S6TNMR7_ARRAY[array_index]].R_Gray,
  1072. V151toV203_Coefficient, V151toV203_Multiple,
  1073. V151toV203_denominator, cal_cnt);
  1074. pSmart->GRAY.TABLE[cnt].G_Gray = cal_gray_scale_linear(
  1075. ptable[S6TNMR7_ARRAY[array_index-1]].G_Gray,
  1076. ptable[S6TNMR7_ARRAY[array_index]].G_Gray,
  1077. V151toV203_Coefficient, V151toV203_Multiple,
  1078. V151toV203_denominator, cal_cnt);
  1079. pSmart->GRAY.TABLE[cnt].B_Gray = cal_gray_scale_linear(
  1080. ptable[S6TNMR7_ARRAY[array_index-1]].B_Gray,
  1081. ptable[S6TNMR7_ARRAY[array_index]].B_Gray,
  1082. V151toV203_Coefficient, V151toV203_Multiple,
  1083. V151toV203_denominator, cal_cnt);
  1084. cal_cnt++;
  1085. } else if (cnt == S6TNMR7_ARRAY[9]) {
  1086. /* 203 */
  1087. cal_cnt = 0;
  1088. } else if ((cnt > S6TNMR7_ARRAY[9]) &&
  1089. (cnt < S6TNMR7_ARRAY[10])) {
  1090. /* 204 ~ 254 */
  1091. array_index = 10;
  1092. pSmart->GRAY.TABLE[cnt].R_Gray = cal_gray_scale_linear(
  1093. ptable[S6TNMR7_ARRAY[array_index-1]].R_Gray,
  1094. ptable[S6TNMR7_ARRAY[array_index]].R_Gray,
  1095. V203toV255_Coefficient, V203toV255_Multiple,
  1096. V203toV255_denominator, cal_cnt);
  1097. pSmart->GRAY.TABLE[cnt].G_Gray = cal_gray_scale_linear(
  1098. ptable[S6TNMR7_ARRAY[array_index-1]].G_Gray,
  1099. ptable[S6TNMR7_ARRAY[array_index]].G_Gray,
  1100. V203toV255_Coefficient, V203toV255_Multiple,
  1101. V203toV255_denominator, cal_cnt);
  1102. pSmart->GRAY.TABLE[cnt].B_Gray = cal_gray_scale_linear(
  1103. ptable[S6TNMR7_ARRAY[array_index-1]].B_Gray,
  1104. ptable[S6TNMR7_ARRAY[array_index]].B_Gray,
  1105. V203toV255_Coefficient, V203toV255_Multiple,
  1106. V203toV255_denominator, cal_cnt);
  1107. cal_cnt++;
  1108. } else {
  1109. if (cnt == S6TNMR7_ARRAY[10]) {
  1110. pr_info("%s end\n", __func__);
  1111. } else {
  1112. pr_err("%s fail cnt:%d\n", __func__, cnt);
  1113. return -EINVAL;
  1114. }
  1115. }
  1116. }
  1117. #ifdef SMART_DIMMING_DEBUG
  1118. for (cnt = 0; cnt < S6TNMR7_GRAY_SCALE_MAX; cnt++) {
  1119. pr_info("%s %8d %8d %8d %d\n", __func__,
  1120. pSmart->GRAY.TABLE[cnt].R_Gray,
  1121. pSmart->GRAY.TABLE[cnt].G_Gray,
  1122. pSmart->GRAY.TABLE[cnt].B_Gray, cnt);
  1123. }
  1124. #endif
  1125. return 0;
  1126. }
  1127. char offset_cal(int offset, char value)
  1128. {
  1129. unsigned char real_value;
  1130. if (value < 0 )
  1131. real_value = value * -1;
  1132. else
  1133. real_value = value;
  1134. if (real_value - offset < 0)
  1135. return 0;
  1136. else if (real_value - offset > 255)
  1137. return 0xFF;
  1138. else
  1139. return real_value - offset;
  1140. }
  1141. static void mtp_offset_substraction(struct SMART_DIM *pSmart, char *str)
  1142. {
  1143. int level_255_temp = 0;
  1144. int level_255_temp_MSB = 0;
  1145. int MTP_V255;
  1146. /*subtration MTP_OFFSET value from generated gamma table*/
  1147. level_255_temp = (str[0] << 8) | str[1] ;
  1148. MTP_V255 = char_to_int_v255(pSmart->MTP.R_OFFSET.OFFSET_255_MSB,
  1149. pSmart->MTP.R_OFFSET.OFFSET_255_LSB);
  1150. level_255_temp -= MTP_V255;
  1151. level_255_temp_MSB = level_255_temp / 256;
  1152. str[0] = level_255_temp_MSB & 0xff;
  1153. str[1] = level_255_temp & 0xff;
  1154. level_255_temp = (str[2] << 8) | str[3] ;
  1155. MTP_V255 = char_to_int_v255(pSmart->MTP.G_OFFSET.OFFSET_255_MSB,
  1156. pSmart->MTP.G_OFFSET.OFFSET_255_LSB);
  1157. level_255_temp -= MTP_V255;
  1158. level_255_temp_MSB = level_255_temp / 256;
  1159. str[2] = level_255_temp_MSB & 0xff;
  1160. str[3] = level_255_temp & 0xff;
  1161. level_255_temp = (str[4] << 8) | str[5] ;
  1162. MTP_V255 = char_to_int_v255(pSmart->MTP.B_OFFSET.OFFSET_255_MSB,
  1163. pSmart->MTP.B_OFFSET.OFFSET_255_LSB);
  1164. level_255_temp -= MTP_V255;
  1165. level_255_temp_MSB = level_255_temp / 256;
  1166. str[4] = level_255_temp_MSB & 0xff;
  1167. str[5] = level_255_temp & 0xff;
  1168. str[6] = offset_cal(char_to_int(pSmart->MTP.R_OFFSET.OFFSET_203), str[6]);
  1169. str[7] = offset_cal(char_to_int(pSmart->MTP.G_OFFSET.OFFSET_203), str[7]);
  1170. str[8] = offset_cal(char_to_int(pSmart->MTP.B_OFFSET.OFFSET_203), str[8]);
  1171. str[9] = offset_cal(char_to_int(pSmart->MTP.R_OFFSET.OFFSET_151), str[9]);
  1172. str[10] = offset_cal(char_to_int(pSmart->MTP.G_OFFSET.OFFSET_151), str[10]);
  1173. str[11] = offset_cal(char_to_int(pSmart->MTP.B_OFFSET.OFFSET_151), str[11]);
  1174. str[12] = offset_cal(char_to_int(pSmart->MTP.R_OFFSET.OFFSET_87), str[12]);
  1175. str[13] = offset_cal(char_to_int(pSmart->MTP.G_OFFSET.OFFSET_87), str[13]);
  1176. str[14] = offset_cal(char_to_int(pSmart->MTP.B_OFFSET.OFFSET_87), str[14]);
  1177. str[15] = offset_cal(char_to_int(pSmart->MTP.R_OFFSET.OFFSET_51), str[15]);
  1178. str[16] = offset_cal(char_to_int(pSmart->MTP.G_OFFSET.OFFSET_51), str[16]);
  1179. str[17] = offset_cal(char_to_int(pSmart->MTP.B_OFFSET.OFFSET_51), str[17]);
  1180. str[18] = offset_cal(char_to_int(pSmart->MTP.R_OFFSET.OFFSET_35), str[18]);
  1181. str[19] = offset_cal(char_to_int(pSmart->MTP.G_OFFSET.OFFSET_35), str[19]);
  1182. str[20] = offset_cal(char_to_int(pSmart->MTP.B_OFFSET.OFFSET_35), str[20]);
  1183. str[21] = offset_cal(char_to_int(pSmart->MTP.R_OFFSET.OFFSET_23), str[21]);
  1184. str[22] = offset_cal(char_to_int(pSmart->MTP.G_OFFSET.OFFSET_23), str[22]);
  1185. str[23] = offset_cal(char_to_int(pSmart->MTP.B_OFFSET.OFFSET_23), str[23]);
  1186. str[24] = offset_cal(char_to_int(pSmart->MTP.R_OFFSET.OFFSET_11), str[24]);
  1187. str[25] = offset_cal(char_to_int(pSmart->MTP.G_OFFSET.OFFSET_11), str[25]);
  1188. str[26] = offset_cal(char_to_int(pSmart->MTP.B_OFFSET.OFFSET_11), str[26]);
  1189. str[27] = offset_cal(char_to_int(pSmart->MTP.R_OFFSET.OFFSET_3), str[27]);
  1190. str[28] = offset_cal(char_to_int(pSmart->MTP.G_OFFSET.OFFSET_3), str[28]);
  1191. str[29] = offset_cal(char_to_int(pSmart->MTP.B_OFFSET.OFFSET_3), str[29]);
  1192. }
  1193. static int searching_function(long long candela, int *index, int gamma_curve)
  1194. {
  1195. long long delta_1 = 0, delta_2 = 0;
  1196. int cnt;
  1197. /*
  1198. * This searching_functin should be changed with improved
  1199. searcing algorithm to reduce searching time.
  1200. */
  1201. *index = -1;
  1202. for (cnt = 0; cnt < (S6TNMR7_GRAY_SCALE_MAX-1); cnt++) {
  1203. if (gamma_curve == GAMMA_CURVE_1P9) {
  1204. delta_1 = candela - curve_1p9[cnt];
  1205. delta_2 = candela - curve_1p9[cnt+1];
  1206. } else {
  1207. delta_1 = candela - curve_2p2[cnt];
  1208. delta_2 = candela - curve_2p2[cnt+1];
  1209. }
  1210. if (delta_2 < 0) {
  1211. *index = (delta_1 + delta_2) <= 0 ? cnt : cnt+1;
  1212. break;
  1213. }
  1214. if (delta_1 == 0) {
  1215. *index = cnt;
  1216. break;
  1217. }
  1218. if (delta_2 == 0) {
  1219. *index = cnt+1;
  1220. break;
  1221. }
  1222. }
  1223. if (*index == -1)
  1224. return -EINVAL;
  1225. else
  1226. return 0;
  1227. }
  1228. /* -1 means V1 */
  1229. #define S6TNMR7_TABLE_MAX (S6TNMR7_MAX-1)
  1230. static void(*Make_hexa[S6TNMR7_TABLE_MAX])(int*, struct SMART_DIM*, char*) = {
  1231. v255_hexa,
  1232. v203_hexa,
  1233. v151_hexa,
  1234. v87_hexa,
  1235. v51_hexa,
  1236. v35_hexa,
  1237. v23_hexa,
  1238. v11_hexa,
  1239. v3_hexa,
  1240. vt_hexa,
  1241. };
  1242. #if defined(AID_OPERATION)
  1243. /*
  1244. * Because of AID operation & display quality.
  1245. *
  1246. * only smart dimmg range : 300CD ~ 190CD
  1247. * AOR fix range : 180CD ~ 110CD AOR 40%
  1248. * AOR adjust range : 100CD ~ 10CD
  1249. */
  1250. #define AOR_FIX_CD 230
  1251. #define AOR_ADJUST_CD 68
  1252. #define CCG6_MAX_TABLE 61
  1253. static int ccg6_candela_table[][2] = {
  1254. {2, 0,},
  1255. {3, 1,},
  1256. {4, 2,},
  1257. {5, 3,},
  1258. {6, 4,},
  1259. {7, 5,},
  1260. {8, 6,},
  1261. {9, 7,},
  1262. {10, 8,},
  1263. {11, 9,},
  1264. {12, 10,},
  1265. {13, 11,},
  1266. {14, 12,},
  1267. {15, 13,},
  1268. {16, 14,},
  1269. {17, 15,},
  1270. {19, 16,},
  1271. {20, 17,},
  1272. {21, 18,},
  1273. {22, 19,},
  1274. {24, 20,},
  1275. {25, 21,},
  1276. {27, 22,},
  1277. {29, 23,},
  1278. {30, 24,},
  1279. {32, 25,},
  1280. {34, 26,},
  1281. {37, 27,},
  1282. {39, 28,},
  1283. {41, 29,},
  1284. {44, 30,},
  1285. {47, 31,},
  1286. {50, 32,},
  1287. {53, 33,},
  1288. {56, 34,},
  1289. {60, 35,},
  1290. {64, 36,},
  1291. {68, 37,},
  1292. {72, 38,},
  1293. {77, 39,},
  1294. {82, 40,},
  1295. {87, 41,},
  1296. {93, 42,},
  1297. {98, 43,},
  1298. {105, 44,},
  1299. {111, 45,},
  1300. {119, 46,},
  1301. {126, 47,},
  1302. {134, 48,},
  1303. {143, 49,},
  1304. {152, 50,},
  1305. {162, 51,},
  1306. {172, 52,},
  1307. {183, 53,},
  1308. {195, 54,},
  1309. {207, 55,},
  1310. {220, 56,},
  1311. {234, 57,},
  1312. {249, 58,},
  1313. {265, 59,},
  1314. {282, 60,},
  1315. {300, 61,},
  1316. };
  1317. static int find_cadela_table(int brightness)
  1318. {
  1319. int loop;
  1320. int err = -1;
  1321. for(loop = 0; loop <= CCG6_MAX_TABLE; loop++)
  1322. if (ccg6_candela_table[loop][0] == brightness)
  1323. return ccg6_candela_table[loop][1];
  1324. return err;
  1325. }
  1326. #define RGB_COMPENSATION 24
  1327. static int gradation_offset_CH_revA[][9] = {
  1328. /* V255 V203 V151 V87 V51 V35 V23 V11 V3 */
  1329. {0, 9, 17, 27, 34, 38, 40, 40, 40},
  1330. {-2, 6, 11, 20, 25, 28, 30, 32, 32},
  1331. {-2, 5, 9, 16, 20, 23, 25, 27, 27},
  1332. {-2, 5, 8, 14, 17, 21, 23, 25, 25},
  1333. {-2, 5, 7, 13, 15, 18, 20, 23, 23},
  1334. {-2, 5, 6, 11, 13, 15, 18, 21, 21},
  1335. {-2, 5, 6, 10, 12, 14, 16, 19, 20},
  1336. {-2, 5, 6, 10, 12, 13, 16, 19, 19},
  1337. {-1, 5, 6, 10, 12, 13, 16, 18, 18},
  1338. {-1, 5, 6, 9, 11, 12, 15, 17, 17},
  1339. {-1, 5, 6, 9, 10, 12, 14, 17, 17},
  1340. {0, 4, 6, 8, 10, 11, 14, 16, 16},
  1341. {0, 4, 6, 8, 9, 11, 13, 15, 15},
  1342. {0, 4, 5, 8, 9, 10, 13, 15, 15},
  1343. {0, 4, 5, 8, 9, 10, 13, 15, 15},
  1344. {0, 4, 5, 7, 8, 10, 12, 14, 14},
  1345. {0, 4, 5, 7, 7, 9, 11, 13, 13},
  1346. {0, 4, 5, 7, 7, 9, 11, 12, 12},
  1347. {0, 4, 5, 6, 6, 8, 10, 12, 12},
  1348. {0, 4, 4, 6, 6, 8, 10, 12, 12},
  1349. {0, 3, 3, 5, 5, 7, 9, 11, 11},
  1350. {0, 3, 3, 5, 5, 7, 8, 10, 10},
  1351. {0, 3, 3, 5, 4, 6, 8, 10, 10},
  1352. {0, 3, 3, 5, 4, 6, 7, 9, 9},
  1353. {0, 3, 3, 5, 4, 6, 7, 9, 9},
  1354. {0, 3, 3, 5, 4, 6, 7, 9, 9},
  1355. {0, 3, 3, 4, 4, 6, 7, 8, 8},
  1356. {0, 3, 3, 4, 3, 5, 6, 8, 8},
  1357. {0, 3, 3, 3, 3, 5, 6, 7, 7},
  1358. {0, 3, 3, 3, 2, 5, 6, 7, 7},
  1359. {0, 3, 3, 3, 2, 4, 5, 6, 6},
  1360. {0, 3, 3, 3, 2, 4, 5, 6, 6},
  1361. {0, 3, 3, 3, 2, 4, 5, 6, 6},
  1362. {0, 3, 3, 3, 2, 3, 4, 5, 5},
  1363. {0, 3, 3, 3, 2, 3, 4, 5, 5},
  1364. {0, 2, 3, 3, 2, 3, 4, 4, 4},
  1365. {0, 2, 3, 3, 2, 3, 3, 4, 4},
  1366. {0, 2, 3, 3, 3, 2, 3, 4, 4},
  1367. {0, 2, 3, 3, 3, 2, 3, 4, 4},
  1368. {0, 2, 3, 3, 3, 2, 3, 4, 4},
  1369. {0, 2, 3, 3, 3, 2, 3, 4, 4},
  1370. {0, 2, 3, 3, 3, 2, 3, 4, 4},
  1371. {0, 2, 3, 3, 3, 2, 3, 4, 4},
  1372. {0, 2, 3, 3, 3, 2, 3, 4, 4},
  1373. {0, 2, 3, 3, 3, 2, 3, 4, 4},
  1374. {0, 2, 3, 3, 3, 2, 3, 4, 4},
  1375. {0, 2, 3, 3, 3, 2, 3, 3, 3},
  1376. {0, 2, 3, 3, 3, 2, 3, 3, 3},
  1377. {0, 2, 3, 3, 2, 2, 2, 3, 3},
  1378. {0, 2, 3, 3, 2, 2, 2, 3, 3},
  1379. {0, 2, 3, 2, 2, 1, 2, 3, 3},
  1380. {0, 2, 3, 2, 1, 1, 2, 2, 2},
  1381. {0, 1, 2, 2, 1, 1, 1, 2, 2},
  1382. {0, 1, 2, 2, 1, 1, 1, 2, 2},
  1383. {0, 1, 2, 1, 1, 0, 1, 1, 2},
  1384. {0, 1, 2, 1, 1, 0, 1, 1, 2},
  1385. {0, 1, 2, 1, 0, 0, 1, 1, 1},
  1386. {0, 0, 1, 1, 0, 0, 1, 1, 0},
  1387. {0, 0, 1, 1, 0, 0, 0, 1, 0},
  1388. {0, 0, 1, 0, 0, -1, 1, 1, 0},
  1389. {0, 1, 1, -1, -1, -1, -1, 0, 0},
  1390. {0, 0, 0, 0, 0, 0, 0, 0, 0},
  1391. };
  1392. static int rgb_offset_CH_revA[][RGB_COMPENSATION] = {
  1393. /* R255 G255 B255 R203 G203 B203 R151 G151 B151
  1394. R87 G87 B87 R51 G51 B51 R35 G35 B35
  1395. R23 G23 B23 R11 G11 B11
  1396. */
  1397. {-7, 4, -5, -2, 3, -3, -7, 3, -6, -17, 4, -8, -18, 7, -12, -13, 4, -10, -6, 6, -10, -2, 4, -12},
  1398. {-5, 2, -4, 0, 2, 0, -4, 3, -4, -14, 6, -8, -18, 8, -9, -16, 8, -9, -6, 6, -10, -2, 4, -12},
  1399. {-5, 0, -4, 0, 2, 0, -4, 3, -4, -12, 5, -8, -18, 8, -9, -16, 7, -9, -9, 6, -13, -7, 6, -16},
  1400. {-4, 0, -3, 0, 2, 0, -1, 3, -1, -10, 4, -7, -17, 7, -8, -16, 7, -9, -11, 6, -13, -8, 9, -18},
  1401. {-3, 0, -2, 0, 1, 0, -1, 3, -1, -9, 4, -7, -16, 7, -8, -16, 7, -9, -13, 6, -13, -9, 10, -19},
  1402. {-2, 0, -1, 0, 0, 0, -1, 2, -1, -8, 4, -7, -14, 7, -8, -15, 7, -9, -13, 6, -13, -9, 10, -19},
  1403. {-2, 0, -1, 0, 0, 0, -1, 2, -1, -7, 4, -6, -12, 7, -8, -13, 6, -9, -13, 6, -13, -9, 10, -19},
  1404. {-1, 0, 0, 0, 0, 0, -1, 2, -1, -7, 4, -6, -12, 6, -8, -13, 6, -9, -13, 6, -13, -9, 10, -19},
  1405. {-1, 0, 0, 0, 0, 0, -1, 2, -1, -7, 3, -6, -12, 5, -8, -13, 5, -9, -13, 5, -13, -9, 10, -19},
  1406. {-1, 0, 0, 0, 0, 0, -1, 1, -1, -7, 3, -6, -12, 4, -8, -13, 4, -9, -13, 4, -13, -9, 10, -19},
  1407. {-1, 0, 0, 0, 0, 0, -1, 1, -1, -6, 2, -6, -12, 4, -8, -12, 4, -9, -13, 4, -13, -9, 10, -19},
  1408. {-1, 0, 0, 0, 0, 0, -1, 1, -1, -6, 2, -5, -12, 3, -8, -12, 3, -9, -13, 4, -13, -9, 10, -19},
  1409. {-1, 0, 0, 0, 0, 0, -1, 1, -1, -6, 2, -5, -12, 3, -8, -12, 3, -9, -13, 4, -13, -9, 10, -19},
  1410. {0, 0, 1, 0, 0, 0, -1, 0, -1, -6, 2, -4, -11, 3, -7, -12, 3, -9, -13, 3, -13, -9, 10, -19},
  1411. {0, 0, 1, 0, 0, 0, -1, 0, -1, -6, 2, -4, -11, 3, -7, -12, 3, -9, -13, 3, -13, -9, 10, -19},
  1412. {0, 0, 1, 0, 0, 0, -1, 0, -1, -6, 1, -4, -11, 3, -7, -12, 3, -9, -13, 3, -13, -9, 10, -19},
  1413. {0, 0, 1, 0, 0, 0, -1, 0, -1, -5, 1, -4, -10, 2, -6, -11, 3, -8, -12, 3, -12, -8, 10, -19},
  1414. {0, 0, 1, 0, 0, 0, -1, 0, -1, -5, 1, -4, -9, 2, -6, -11, 3, -8, -12, 3, -12, -8, 10, -18},
  1415. {0, 0, 1, 0, 0, 0, -1, 0, -1, -5, 1, -4, -9, 2, -6, -10, 3, -7, -11, 3, -12, -8, 10, -18},
  1416. {0, 0, 1, 0, 0, 0, -1, 0, -1, -5, 1, -4, -9, 2, -6, -10, 3, -7, -11, 3, -12, -8, 10, -18},
  1417. {0, 0, 1, 0, 0, 0, -1, 0, -1, -4, 1, -3, -8, 2, -6, -9, 3, -7, -11, 3, -12, -8, 10, -18},
  1418. {0, 0, 1, 0, 0, 0, 0, 0, 0, -4, 1, -3, -8, 2, -6, -8, 3, -7, -10, 3, -12, -8, 10, -18},
  1419. {0, 0, 1, 0, 0, 0, 0, 0, 0, -4, 1, -3, -7, 2, -6, -7, 3, -6, -8, 3, -11, -8, 10, -18},
  1420. {0, 0, 1, 0, 0, 0, 0, 0, 0, -4, 1, -3, -7, 2, -6, -7, 3, -6, -8, 3, -11, -8, 10, -18},
  1421. {0, 0, 1, 0, 0, 0, 0, 0, 0, -4, 1, -3, -7, 2, -5, -7, 3, -6, -8, 3, -10, -8, 10, -18},
  1422. {0, 0, 1, 0, 0, 0, 0, 0, 0, -4, 1, -3, -7, 1, -5, -7, 2, -6, -8, 3, -10, -8, 10, -17},
  1423. {0, 0, 1, 0, 0, 0, 0, 0, 0, -4, 1, -3, -7, 1, -5, -7, 2, -6, -8, 3, -10, -8, 10, -17},
  1424. {0, 0, 1, 0, 0, 0, 0, 0, 0, -4, 0, -3, -6, 1, -4, -6, 2, -5, -7, 3, -9, -8, 10, -16},
  1425. {0, 0, 1, 0, 0, 0, 0, 0, 0, -3, 0, -3, -5, 1, -4, -5, 2, -5, -7, 3, -8, -8, 10, -16},
  1426. {0, 0, 1, 0, 0, 0, 0, 0, 0, -2, 0, -2, -5, 1, -4, -5, 1, -5, -6, 3, -7, -8, 10, -16},
  1427. {0, 0, 1, 0, 0, 0, 0, 0, 0, -2, 0, -2, -5, 1, -4, -4, 1, -5, -5, 3, -7, -7, 10, -16},
  1428. {0, 0, 1, 0, 0, 0, 0, 0, 0, -2, 0, -2, -5, 1, -4, -4, 1, -5, -4, 3, -6, -6, 9, -15},
  1429. {0, 0, 1, 0, 0, 0, 0, 0, 0, -1, 0, -1, -4, 0, -3, -3, 1, -4, -4, 3, -6, -6, 9, -15},
  1430. {0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -1, -4, 0, -3, -3, 1, -4, -4, 3, -6, -6, 9, -15},
  1431. {0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -1, -4, 0, -3, -3, 1, -3, -3, 3, -6, -5, 9, -14},
  1432. {0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -1, -2, 0, -2, -2, 1, -3, -2, 3, -5, -5, 9, -14},
  1433. {0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -1, -2, 0, -2, -2, 1, -3, -2, 3, -4, -5, 8, -12},
  1434. {0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -1, -2, 0, -2, -2, 1, -3, -2, 2, -4, -5, 7, -11},
  1435. {0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -1, -2, 0, -2, -2, 1, -3, -2, 2, -4, -5, 7, -11},
  1436. {0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -1, -2, 0, -2, -2, 1, -3, -2, 2, -4, -5, 7, -11},
  1437. {0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -1, -2, 0, -2, -2, 1, -3, -2, 2, -4, -5, 7, -11},
  1438. {0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -1, -2, 0, -2, -2, 1, -3, -2, 2, -4, -5, 7, -11},
  1439. {0, 0, 1, 0, 0, 0, 0, 0, 0, -1, 0, -1, -2, 0, -1, -2, 0, -3, -2, 1, -4, -5, 6, -11},
  1440. {0, 0, 1, 0, 0, 0, 0, 0, 0, -1, 0, -1, -2, 0, -1, -2, 0, -3, -2, 1, -4, -5, 6, -11},
  1441. {0, 0, 1, 0, 0, 0, 0, 0, 0, -1, 0, -1, -2, 0, -1, -2, 0, -2, -2, 1, -4, -5, 6, -11},
  1442. {0, 0, 1, 0, 0, 0, 0, 0, 0, -1, 0, -1, -2, 0, -1, -2, 0, -2, -2, 1, -4, -5, 6, -11},
  1443. {0, 0, 1, 0, 0, 0, 0, 0, 0, -1, 0, -1, -2, 0, -1, -2, 0, -2, -2, 1, -4, -5, 5, -11},
  1444. {0, 0, 1, 0, 0, 0, 0, 0, 0, -1, 0, -1, -2, 0, -1, -2, 0, -2, -2, 1, -4, -5, 5, -11},
  1445. {0, 0, 1, 0, 0, 0, 0, 0, 0, -1, 0, -1, -2, 0, -1, -2, 0, -2, -2, 1, -3, -5, 5, -10},
  1446. {0, 0, 1, 0, 0, 0, 0, 0, 0, -1, 0, -1, -2, 0, -1, -2, 0, -2, -2, 1, -3, -5, 4, -9},
  1447. {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, 0, -1, -2, 0, -1, -2, 1, -3, -5, 4, -8},
  1448. {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, 0, -1, -2, 0, -1, -2, 1, -3, -4, 3, -7},
  1449. {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -1, -2, 0, -2, -2, 0, -3, -3, 2, -6},
  1450. {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2, 0, -1, -2, 0, -3, -2, 2, -5},
  1451. {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -1, -1, 0, -2, -2, 2, -5},
  1452. {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, -1, 0, -2, -2, 1, -4},
  1453. {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, 0, -3},
  1454. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  1455. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  1456. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  1457. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  1458. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  1459. };
  1460. static void gamma_init_CH_revA(struct SMART_DIM *pSmart, char *str, int size)
  1461. {
  1462. long long candela_level[S6TNMR7_TABLE_MAX] = {-1, };
  1463. int bl_index[S6TNMR7_TABLE_MAX] = {-1, };
  1464. long long temp_cal_data = 0;
  1465. int bl_level;
  1466. int level_255_temp_MSB = 0;
  1467. int level_V255 = 0;
  1468. int point_index;
  1469. int cnt;
  1470. int table_index;
  1471. pr_debug("%s : start !!\n",__func__);
  1472. /*calculate candela level */
  1473. if (pSmart->brightness_level > AOR_FIX_CD) {
  1474. /* 300CD ~ 230CD */
  1475. if (pSmart->brightness_level == 234)
  1476. bl_level = 241;
  1477. else if (pSmart->brightness_level == 249)
  1478. bl_level = 256;
  1479. else if (pSmart->brightness_level == 265)
  1480. bl_level = 270;
  1481. else if (pSmart->brightness_level == 282)
  1482. bl_level = 287;
  1483. else
  1484. bl_level = 300;
  1485. } else if ((pSmart->brightness_level <= AOR_FIX_CD) &&
  1486. (pSmart->brightness_level >= AOR_ADJUST_CD)) {
  1487. /* 230CD ~ 68CD */
  1488. if (pSmart->brightness_level == 68)
  1489. bl_level = 114;
  1490. else if (pSmart->brightness_level == 72)
  1491. bl_level = 121;
  1492. else if (pSmart->brightness_level == 77)
  1493. bl_level = 130;
  1494. else if (pSmart->brightness_level == 82)
  1495. bl_level = 136;
  1496. else if (pSmart->brightness_level == 87)
  1497. bl_level = 144;
  1498. else if (pSmart->brightness_level == 93)
  1499. bl_level = 154;
  1500. else if (pSmart->brightness_level == 98)
  1501. bl_level = 160;
  1502. else if (pSmart->brightness_level == 105)
  1503. bl_level = 172;
  1504. else if (pSmart->brightness_level == 111)
  1505. bl_level = 180;
  1506. else if (pSmart->brightness_level == 119)
  1507. bl_level = 193;
  1508. else if (pSmart->brightness_level == 126)
  1509. bl_level = 204;
  1510. else if (pSmart->brightness_level == 134)
  1511. bl_level = 216;
  1512. else if (pSmart->brightness_level == 143)
  1513. bl_level = 228;
  1514. else
  1515. bl_level = 241;
  1516. } else {
  1517. /* 64CD ~ 2CD */
  1518. bl_level = 110;
  1519. }
  1520. if (pSmart->brightness_level < 300) {
  1521. for (cnt = 0; cnt < S6TNMR7_TABLE_MAX; cnt++) {
  1522. point_index = S6TNMR7_ARRAY[cnt+1];
  1523. temp_cal_data =
  1524. ((long long)(candela_coeff_2p15[point_index])) *
  1525. ((long long)(bl_level));
  1526. candela_level[cnt] = temp_cal_data;
  1527. }
  1528. } else {
  1529. for (cnt = 0; cnt < S6TNMR7_TABLE_MAX; cnt++) {
  1530. point_index = S6TNMR7_ARRAY[cnt+1];
  1531. temp_cal_data =
  1532. ((long long)(candela_coeff_2p2[point_index])) *
  1533. ((long long)(bl_level));
  1534. candela_level[cnt] = temp_cal_data;
  1535. }
  1536. }
  1537. #ifdef SMART_DIMMING_DEBUG_PLUS
  1538. printk(KERN_INFO "\n candela_1:%llu candela_3:%llu candela_11:%llu ",
  1539. candela_level[0], candela_level[1], candela_level[2]);
  1540. printk(KERN_INFO "candela_23:%llu candela_35:%llu candela_51:%llu ",
  1541. candela_level[3], candela_level[4], candela_level[5]);
  1542. printk(KERN_INFO "candela_87:%llu candela_151:%llu candela_203:%llu ",
  1543. candela_level[6], candela_level[7], candela_level[8]);
  1544. printk(KERN_INFO "candela_255:%llu brightness_level %d\n", candela_level[9], pSmart->brightness_level);
  1545. #endif
  1546. for (cnt = 0; cnt < S6TNMR7_TABLE_MAX; cnt++) {
  1547. if (searching_function(candela_level[cnt],
  1548. &(bl_index[cnt]), GAMMA_CURVE_2P15)) {
  1549. pr_info("%s searching functioin error cnt:%d\n",
  1550. __func__, cnt);
  1551. }
  1552. }
  1553. /*
  1554. * Candela compensation
  1555. */
  1556. for (cnt = 1; cnt < S6TNMR7_TABLE_MAX; cnt++) {
  1557. table_index = find_cadela_table(pSmart->brightness_level);
  1558. if (table_index == -1) {
  1559. table_index = CCG6_MAX_TABLE;
  1560. pr_info("%s fail candela table_index cnt : %d brightness %d",
  1561. __func__, cnt, pSmart->brightness_level);
  1562. }
  1563. bl_index[S6TNMR7_TABLE_MAX - cnt] +=
  1564. gradation_offset_CH_revA[table_index][cnt - 1];
  1565. /* THERE IS M-GRAY0 target */
  1566. if (bl_index[S6TNMR7_TABLE_MAX - cnt] == 0)
  1567. bl_index[S6TNMR7_TABLE_MAX - cnt] = 1;
  1568. }
  1569. #ifdef SMART_DIMMING_DEBUG_PLUS
  1570. printk(KERN_INFO "\n bl_index_1:%d bl_index_3:%d bl_index_11:%d",
  1571. bl_index[0], bl_index[1], bl_index[2]);
  1572. printk(KERN_INFO "bl_index_23:%d bl_index_35:%d bl_index_51:%d",
  1573. bl_index[3], bl_index[4], bl_index[5]);
  1574. printk(KERN_INFO "bl_index_87:%d bl_index_151:%d bl_index_203:%d",
  1575. bl_index[6], bl_index[7], bl_index[8]);
  1576. printk(KERN_INFO "bl_index_255:%d\n", bl_index[9]);
  1577. #endif
  1578. /*Generate Gamma table*/
  1579. for (cnt = 0; cnt < S6TNMR7_TABLE_MAX; cnt++)
  1580. (void)Make_hexa[cnt](bl_index , pSmart, str);
  1581. /*
  1582. * RGB compensation
  1583. */
  1584. for (cnt = 0; cnt < RGB_COMPENSATION; cnt++) {
  1585. table_index = find_cadela_table(pSmart->brightness_level);
  1586. if (table_index == -1) {
  1587. table_index = CCG6_MAX_TABLE;
  1588. pr_info("%s fail RGB table_index cnt : %d brightness %d",
  1589. __func__, cnt, pSmart->brightness_level);
  1590. }
  1591. if (cnt < 3) {
  1592. level_V255 = str[cnt * 2] << 8 | str[(cnt * 2) + 1];
  1593. level_V255 +=
  1594. rgb_offset_CH_revA[table_index][cnt];
  1595. level_255_temp_MSB = level_V255 / 256;
  1596. str[cnt * 2] = level_255_temp_MSB & 0xff;
  1597. str[(cnt * 2) + 1] = level_V255 & 0xff;
  1598. } else {
  1599. str[cnt+3] += rgb_offset_CH_revA[table_index][cnt];
  1600. }
  1601. }
  1602. /*subtration MTP_OFFSET value from generated gamma table*/
  1603. mtp_offset_substraction(pSmart, str);
  1604. }
  1605. #endif
  1606. static void pure_gamma_init(struct SMART_DIM *pSmart, char *str, int size)
  1607. {
  1608. long long candela_level[S6TNMR7_TABLE_MAX] = {-1, };
  1609. int bl_index[S6TNMR7_TABLE_MAX] = {-1, };
  1610. long long temp_cal_data = 0;
  1611. int bl_level, cnt;
  1612. int point_index;
  1613. bl_level = pSmart->brightness_level;
  1614. for (cnt = 0; cnt < S6TNMR7_TABLE_MAX; cnt++) {
  1615. point_index = S6TNMR7_ARRAY[cnt+1];
  1616. temp_cal_data =
  1617. ((long long)(candela_coeff_2p2[point_index])) *
  1618. ((long long)(bl_level));
  1619. candela_level[cnt] = temp_cal_data;
  1620. }
  1621. #ifdef SMART_DIMMING_DEBUG
  1622. printk(KERN_INFO "\n candela_1:%llu candela_3:%llu candela_11:%llu ",
  1623. candela_level[0], candela_level[1], candela_level[2]);
  1624. printk(KERN_INFO "candela_23:%llu candela_35:%llu candela_51:%llu ",
  1625. candela_level[3], candela_level[4], candela_level[5]);
  1626. printk(KERN_INFO "candela_87:%llu candela_151:%llu candela_203:%llu ",
  1627. candela_level[6], candela_level[7], candela_level[8]);
  1628. printk(KERN_INFO "candela_255:%llu\n", candela_level[9]);
  1629. #endif
  1630. /*calculate brightness level*/
  1631. for (cnt = 0; cnt < S6TNMR7_TABLE_MAX; cnt++) {
  1632. if (searching_function(candela_level[cnt],
  1633. &(bl_index[cnt]), GAMMA_CURVE_2P2)) {
  1634. pr_info("%s searching functioin error cnt:%d\n",
  1635. __func__, cnt);
  1636. }
  1637. }
  1638. /*
  1639. * 210CD ~ 190CD compensation
  1640. * V3 level + 1
  1641. */
  1642. if ((bl_level >= 190) && (bl_level <= 210))
  1643. bl_index[1] += 1;
  1644. #ifdef SMART_DIMMING_DEBUG
  1645. printk(KERN_INFO "\n bl_index_1:%d bl_index_3:%d bl_index_11:%d",
  1646. bl_index[0], bl_index[1], bl_index[2]);
  1647. printk(KERN_INFO "bl_index_23:%d bl_index_35:%d bl_index_51:%d",
  1648. bl_index[3], bl_index[4], bl_index[5]);
  1649. printk(KERN_INFO "bl_index_87:%d bl_index_151:%d bl_index_203:%d",
  1650. bl_index[5], bl_index[7], bl_index[8]);
  1651. printk(KERN_INFO "bl_index_255:%d\n", bl_index[9]);
  1652. #endif
  1653. /*Generate Gamma table*/
  1654. for (cnt = 0; cnt < S6TNMR7_TABLE_MAX; cnt++)
  1655. (void)Make_hexa[cnt](bl_index , pSmart, str);
  1656. mtp_offset_substraction(pSmart, str);
  1657. }
  1658. static void set_max_lux_table(void)
  1659. {
  1660. max_lux_table[0] = V255_300CD_R_MSB;
  1661. max_lux_table[1] = V255_300CD_R_LSB;
  1662. max_lux_table[2] = V255_300CD_G_MSB;
  1663. max_lux_table[3] = V255_300CD_G_LSB;
  1664. max_lux_table[4] = V255_300CD_B_MSB;
  1665. max_lux_table[5] = V255_300CD_B_LSB;
  1666. max_lux_table[6] = V203_300CD_R;
  1667. max_lux_table[7] = V203_300CD_G;
  1668. max_lux_table[8] = V203_300CD_B;
  1669. max_lux_table[9] = V151_300CD_R;
  1670. max_lux_table[10] = V151_300CD_G;
  1671. max_lux_table[11] = V151_300CD_B;
  1672. max_lux_table[12] = V87_300CD_R;
  1673. max_lux_table[13] = V87_300CD_G;
  1674. max_lux_table[14] = V87_300CD_B;
  1675. max_lux_table[15] = V51_300CD_R;
  1676. max_lux_table[16] = V51_300CD_G;
  1677. max_lux_table[17] = V51_300CD_B;
  1678. max_lux_table[18] = V35_300CD_R;
  1679. max_lux_table[19] = V35_300CD_G;
  1680. max_lux_table[20] = V35_300CD_B;
  1681. max_lux_table[21] = V23_300CD_R;
  1682. max_lux_table[22] = V23_300CD_G;
  1683. max_lux_table[23] = V23_300CD_B;
  1684. max_lux_table[24] = V11_300CD_R;
  1685. max_lux_table[25] = V11_300CD_G;
  1686. max_lux_table[26] = V11_300CD_B;
  1687. max_lux_table[27] = V3_300CD_R;
  1688. max_lux_table[28] = V3_300CD_G;
  1689. max_lux_table[29] = V3_300CD_B;
  1690. max_lux_table[30] = VT_300CD_R;
  1691. max_lux_table[31] = VT_300CD_G;
  1692. max_lux_table[32] = VT_300CD_B;
  1693. }
  1694. static void set_min_lux_table(struct SMART_DIM *psmart)
  1695. {
  1696. psmart->brightness_level = MIN_CANDELA;
  1697. pure_gamma_init(psmart, min_lux_table, GAMMA_SET_MAX);
  1698. }
  1699. static void get_min_lux_table(char *str, int size)
  1700. {
  1701. memcpy(str, min_lux_table, size);
  1702. }
  1703. static void generate_gamma(struct SMART_DIM *psmart, char *str, int size)
  1704. {
  1705. int lux_loop;
  1706. struct illuminance_table *ptable = (struct illuminance_table *)
  1707. (&(psmart->gen_table));
  1708. /* searching already generated gamma table */
  1709. for (lux_loop = 0; lux_loop < psmart->lux_table_max; lux_loop++) {
  1710. if (ptable[lux_loop].lux == psmart->brightness_level) {
  1711. memcpy(str, &(ptable[lux_loop].gamma_setting), size);
  1712. break;
  1713. }
  1714. }
  1715. /* searching fail... Setting 300CD value on gamma table */
  1716. if (lux_loop == psmart->lux_table_max) {
  1717. pr_info("%s searching fail lux : %d\n", __func__,
  1718. psmart->brightness_level);
  1719. memcpy(str, max_lux_table, size);
  1720. }
  1721. #ifdef SMART_DIMMING_DEBUG
  1722. if (lux_loop != psmart->lux_table_max)
  1723. pr_info("%s searching ok index : %d lux : %d", __func__,
  1724. lux_loop, ptable[lux_loop].lux);
  1725. #endif
  1726. }
  1727. static void mtp_sorting(struct SMART_DIM *psmart)
  1728. {
  1729. int sorting[GAMMA_SET_MAX] = {
  1730. 9, 7, 6, 5, 4, 3, 2, 1, 0, 8, 10, /* R*/
  1731. 20, 18, 17, 16, 15, 14, 13, 12, 11, 19, 21, /* G */
  1732. 31, 29, 28, 27, 26, 25, 24, 23, 22, 30, 32, /* B */
  1733. };
  1734. int loop;
  1735. char *pfrom, *pdest;
  1736. pfrom = (char *)&(psmart->MTP_ORIGN);
  1737. pdest = (char *)&(psmart->MTP);
  1738. for (loop = 0; loop < GAMMA_SET_MAX; loop++)
  1739. pdest[loop] = pfrom[sorting[loop]];
  1740. for (loop = 0; loop < 3 ; loop++) {
  1741. if(pdest[loop*11])
  1742. pdest[loop * 11] *= -1;
  1743. }
  1744. }
  1745. static void gamma_cell_determine(int ldi_revision)
  1746. {
  1747. pr_info("%s ldi_revision: 0x%x", __func__, ldi_revision);
  1748. V255_300CD_R_MSB = V255_300CD_R_MSB_20;
  1749. V255_300CD_R_LSB = V255_300CD_R_LSB_20;
  1750. V255_300CD_G_MSB = V255_300CD_G_MSB_20;
  1751. V255_300CD_G_LSB = V255_300CD_G_LSB_20;
  1752. V255_300CD_B_MSB = V255_300CD_B_MSB_20;
  1753. V255_300CD_B_LSB = V255_300CD_B_LSB_20;
  1754. V203_300CD_R = V203_300CD_R_20;
  1755. V203_300CD_G = V203_300CD_G_20;
  1756. V203_300CD_B = V203_300CD_B_20;
  1757. V151_300CD_R = V151_300CD_R_20;
  1758. V151_300CD_G = V151_300CD_G_20;
  1759. V151_300CD_B = V151_300CD_B_20;
  1760. V87_300CD_R = V87_300CD_R_20;
  1761. V87_300CD_G = V87_300CD_G_20;
  1762. V87_300CD_B = V87_300CD_B_20;
  1763. V51_300CD_R = V51_300CD_R_20;
  1764. V51_300CD_G = V51_300CD_G_20;
  1765. V51_300CD_B = V51_300CD_B_20;
  1766. V35_300CD_R = V35_300CD_R_20;
  1767. V35_300CD_G = V35_300CD_G_20;
  1768. V35_300CD_B = V35_300CD_B_20;
  1769. V23_300CD_R = V23_300CD_R_20;
  1770. V23_300CD_G = V23_300CD_G_20;
  1771. V23_300CD_B = V23_300CD_B_20;
  1772. V11_300CD_R = V11_300CD_R_20;
  1773. V11_300CD_G = V11_300CD_G_20;
  1774. V11_300CD_B = V11_300CD_B_20;
  1775. V3_300CD_R = V3_300CD_R_20;
  1776. V3_300CD_G = V3_300CD_G_20;
  1777. V3_300CD_B = V3_300CD_B_20;
  1778. VT_300CD_R = VT_300CD_R_20;
  1779. VT_300CD_G = VT_300CD_G_20;
  1780. VT_300CD_B = VT_300CD_B_20;
  1781. }
  1782. static void gamma_command_sorting_post(struct SMART_DIM *psmart)
  1783. {
  1784. int sorting[GAMMA_SET_MAX] = {
  1785. 24, 21, 18, 15, 12, 9, 6, 1, 27, 0, 30, /* R*/
  1786. 25, 22, 19, 16, 13, 10, 7, 3, 28, 2, 31, /* G */
  1787. 26, 23, 20, 17, 14, 11, 8, 5, 29, 4, 32, /* B */
  1788. };
  1789. int loop, loop2;
  1790. char gamma_temp[GAMMA_SET_MAX];
  1791. for (loop = 0; loop < LUMINANCE_MAX; loop++) {
  1792. /* sorting */
  1793. for (loop2 = 0; loop2 < GAMMA_SET_MAX; loop2++)
  1794. gamma_temp[loop2] =
  1795. psmart->gen_table[loop].gamma_setting[sorting[loop2]];
  1796. /* V255 Check */
  1797. for (loop2 = 0; loop2 < 3 ; loop2++) {
  1798. if(gamma_temp[(loop2*11)+9] == 0x01)
  1799. gamma_temp[(loop2*11)+9] =
  1800. gamma_temp[(loop2*11)+9] << 7;
  1801. }
  1802. /* Copy */
  1803. memcpy(psmart->gen_table[loop].gamma_setting,
  1804. gamma_temp, GAMMA_SET_MAX);
  1805. }
  1806. }
  1807. static int smart_dimming_init(struct SMART_DIM *psmart)
  1808. {
  1809. int lux_loop;
  1810. int id1, id2, id3;
  1811. #ifdef SMART_DIMMING_DEBUG
  1812. int cnt;
  1813. char pBuffer[256];
  1814. memset(pBuffer, 0x00, 256);
  1815. #endif
  1816. id1 = (psmart->ldi_revision & 0x00FF0000) >> 16;
  1817. id2 = (psmart->ldi_revision & 0x0000FF00) >> 8;
  1818. id3 = psmart->ldi_revision & 0xFF;
  1819. mtp_sorting(psmart);
  1820. gamma_cell_determine(psmart->ldi_revision);
  1821. set_max_lux_table();
  1822. #ifdef SMART_DIMMING_DEBUG
  1823. print_RGB_offset(psmart);
  1824. #endif
  1825. v255_adjustment(psmart);
  1826. vt_adjustment(psmart);
  1827. v203_adjustment(psmart);
  1828. v151_adjustment(psmart);
  1829. v87_adjustment(psmart);
  1830. v51_adjustment(psmart);
  1831. v35_adjustment(psmart);
  1832. v23_adjustment(psmart);
  1833. v11_adjustment(psmart);
  1834. v3_adjustment(psmart);
  1835. if (generate_gray_scale(psmart)) {
  1836. pr_info(KERN_ERR "lcd smart dimming fail generate_gray_scale\n");
  1837. return -EINVAL;
  1838. }
  1839. /*Generating lux_table*/
  1840. for (lux_loop = 0; lux_loop < psmart->lux_table_max; lux_loop++) {
  1841. /* To set brightness value */
  1842. psmart->brightness_level = psmart->plux_table[lux_loop];
  1843. /* To make lux table index*/
  1844. psmart->gen_table[lux_loop].lux = psmart->plux_table[lux_loop];
  1845. #if defined(AID_OPERATION)
  1846. gamma_init_CH_revA(psmart,
  1847. (char *)(&(psmart->gen_table[lux_loop].gamma_setting)),
  1848. GAMMA_SET_MAX);
  1849. #else
  1850. pure_gamma_init(psmart,
  1851. (char *)(&(psmart->gen_table[lux_loop].gamma_setting)),
  1852. GAMMA_SET_MAX);
  1853. #endif
  1854. }
  1855. /* set 300CD max gamma table */
  1856. memcpy(&(psmart->gen_table[lux_loop-1].gamma_setting),
  1857. max_lux_table, GAMMA_SET_MAX);
  1858. set_min_lux_table(psmart);
  1859. #ifdef SMART_DIMMING_DEBUG
  1860. for (lux_loop = 0; lux_loop < psmart->lux_table_max; lux_loop++) {
  1861. for (cnt = 0; cnt < GAMMA_SET_MAX; cnt++)
  1862. snprintf(pBuffer + strnlen(pBuffer, 256), 256, " %d",
  1863. psmart->gen_table[lux_loop].gamma_setting[cnt]);
  1864. pr_info("lux : %d %s", psmart->plux_table[lux_loop], pBuffer);
  1865. memset(pBuffer, 0x00, 256);
  1866. }
  1867. #endif
  1868. gamma_command_sorting_post(psmart);
  1869. #ifdef SMART_DIMMING_DEBUG
  1870. for (lux_loop = 0; lux_loop < psmart->lux_table_max; lux_loop++) {
  1871. for (cnt = 0; cnt < GAMMA_SET_MAX; cnt++)
  1872. snprintf(pBuffer + strnlen(pBuffer, 256), 256, " %d",
  1873. psmart->gen_table[lux_loop].gamma_setting[cnt]);
  1874. pr_info("lux : %d %s", psmart->plux_table[lux_loop], pBuffer);
  1875. memset(pBuffer, 0x00, 256);
  1876. }
  1877. #endif
  1878. return 0;
  1879. }
  1880. /* ----------------------------------------------------------------------------
  1881. * Wrapper functions for smart dimming to work with 8974 generic code
  1882. * ----------------------------------------------------------------------------
  1883. */
  1884. static struct SMART_DIM smart_S6TNMR7;
  1885. static struct smartdim_conf __S6TNMR7__ ;
  1886. static void wrap_generate_gamma(int cd, char *cmd_str) {
  1887. smart_S6TNMR7.brightness_level = cd;
  1888. generate_gamma(&smart_S6TNMR7, cmd_str, GAMMA_SET_MAX);
  1889. }
  1890. static void wrap_smart_dimming_init(void) {
  1891. smart_S6TNMR7.plux_table = __S6TNMR7__.lux_tab;
  1892. smart_S6TNMR7.lux_table_max = __S6TNMR7__.lux_tabsize;
  1893. smart_S6TNMR7.ldi_revision = __S6TNMR7__.man_id;
  1894. smart_dimming_init(&smart_S6TNMR7);
  1895. }
  1896. struct smartdim_conf *smart_S6TNMR7_get_conf(void){
  1897. __S6TNMR7__.generate_gamma = wrap_generate_gamma;
  1898. __S6TNMR7__.init = wrap_smart_dimming_init;
  1899. __S6TNMR7__.get_min_lux_table = get_min_lux_table;
  1900. __S6TNMR7__.mtp_buffer = (char *)(&smart_S6TNMR7.MTP_ORIGN);
  1901. return (struct smartdim_conf *)&__S6TNMR7__;
  1902. }
  1903. /* ----------------------------------------------------------------------------
  1904. * END - Wrapper
  1905. * ----------------------------------------------------------------------------
  1906. */