smart_mtp_s6e8aa0x01.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. /*
  2. * =================================================================
  3. *
  4. * Filename: smart_mtp_s6e8aa0x01.h
  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. #ifndef _SMART_MTP_S6E8AA0X01_H_
  33. #define _SMART_MTP_S6E8AA0X01_H_
  34. #include <linux/module.h>
  35. #include <linux/kernel.h>
  36. #include <linux/errno.h>
  37. #include <linux/mutex.h>
  38. #include <linux/wait.h>
  39. #include <linux/ctype.h>
  40. #include <asm/div64.h>
  41. #if defined (CONFIG_FB_MSM_MDSS_S6E8AA0A_HD_PANEL)
  42. enum {
  43. CI_RED = 0,
  44. CI_GREEN = 1,
  45. CI_BLUE = 2,
  46. CI_MAX = 3,
  47. };
  48. enum {
  49. IV_1 = 0,
  50. IV_15 = 1,
  51. IV_35 = 2,
  52. IV_59 = 3,
  53. IV_87 = 4,
  54. IV_171 = 5,
  55. IV_255 = 6,
  56. IV_MAX = 7,
  57. IV_TABLE_MAX = 8,
  58. };
  59. enum {
  60. AD_IV0 = 0,
  61. AD_IV1 = 1,
  62. AD_IV15 = 2,
  63. AD_IV35 = 3,
  64. AD_IV59 = 4,
  65. AD_IV87 = 5,
  66. AD_IV171 = 6,
  67. AD_IV255 = 7,
  68. AD_IVMAX = 8,
  69. };
  70. #define MAX_GRADATION 300
  71. struct str_voltage_entry {
  72. u32 v[CI_MAX];
  73. };
  74. struct str_table_info {
  75. u8 st;
  76. u8 et;
  77. u8 count;
  78. u8 *offset_table;
  79. u32 rv;
  80. };
  81. struct str_flookup_table {
  82. u16 entry;
  83. u16 count;
  84. };
  85. struct str_smart_dim {
  86. s16 mtp[CI_MAX][IV_MAX];
  87. struct str_voltage_entry ve[256];
  88. u8 *default_gamma;
  89. struct str_table_info t_info[IV_TABLE_MAX];
  90. struct str_flookup_table *flooktbl;
  91. u32 *g22_tbl;
  92. u32 *g300_gra_tbl;
  93. u32 adjust_volt[CI_MAX][AD_IVMAX];
  94. s16 adjust_mtp[CI_MAX][IV_MAX];
  95. };
  96. int init_table_info(struct str_smart_dim *smart, unsigned char *srcGammaTable);
  97. u8 calc_voltage_table(struct str_smart_dim *smart, const u8 * mtp);
  98. u32 calc_gamma_table(struct str_smart_dim *smart, u32 gv, u8 result[]);
  99. #endif
  100. #if defined(CONFIG_MACH_STRETTO) || defined(CONFIG_MACH_SUPERIORLTE_SKT)
  101. /*
  102. * STRETTO/SUPERIORLTE_SKT: 4.65 inch / no AID
  103. */
  104. #else
  105. /*
  106. * 4.8 inch model use AID function
  107. * CASE#1 is used for now.
  108. */
  109. #define AID_OPERATION_4_8_INCH
  110. #define AID_CASE_1
  111. /*
  112. * To set default AID algorithm
  113. */
  114. #if !defined(AID_CASE_1) && !defined(AID_CASE_2) && !defined(AID_CASE_3)
  115. #define AID_CASE_1
  116. #endif
  117. #endif
  118. #define LUMINANCE_MAX 35
  119. #define GAMMA_SET_MAX 24
  120. #define BIT_SHIFT 14
  121. /*
  122. it means BIT_SHIFT is 14. pow(2,BIT_SHIFT) is 16384.
  123. BIT_SHIFT is used for right bit shfit
  124. */
  125. #define BIT_SHFIT_MUL 16384
  126. #define S6E8AA0X01_GRAY_SCALE_MAX 256
  127. /*4.713*16384 */
  128. #define S6E8AA0X01_VREG0_REF 77218
  129. /*V0,V1,V15,V35,V59,V87,V177,V255*/
  130. #define S6E8AA0X01_MAX 8
  131. /* PANEL DEPENDENT THINGS */
  132. #define MAX_CANDELA 300
  133. #define MIN_CANDELA 20
  134. /*
  135. * ID 0x20
  136. */
  137. #define V1_300CD_R_20 0x43
  138. #define V1_300CD_G_20 0x14
  139. #define V1_300CD_B_20 0x45
  140. #define V15_300CD_R_20 0xAD
  141. #define V15_300CD_G_20 0xBE
  142. #define V15_300CD_B_20 0xA9
  143. #define V35_300CD_R_20 0xB0
  144. #define V35_300CD_G_20 0xC3
  145. #define V35_300CD_B_20 0xAF
  146. #define V59_300CD_R_20 0xC1
  147. #define V59_300CD_G_20 0xCD
  148. #define V59_300CD_B_20 0xC0
  149. #define V87_300CD_R_20 0x95
  150. #define V87_300CD_G_20 0xA2
  151. #define V87_300CD_B_20 0x91
  152. #define V171_300CD_R_20 0xAC
  153. #define V171_300CD_G_20 0xB5
  154. #define V171_300CD_B_20 0xAA
  155. #define V255_300CD_R_MSB_20 0x00
  156. #define V255_300CD_R_LSB_20 0xB0
  157. #define V255_300CD_G_MSB_20 0x00
  158. #define V255_300CD_G_LSB_20 0xA0
  159. #define V255_300CD_B_MSB_20 0x00
  160. #define V255_300CD_B_LSB_20 0xCC
  161. /*
  162. * ID 0x40
  163. */
  164. #define V1_300CD_R_40 0x44
  165. #define V1_300CD_G_40 0x0F
  166. #define V1_300CD_B_40 0x42
  167. #define V15_300CD_R_40 0xAB
  168. #define V15_300CD_G_40 0xC1
  169. #define V15_300CD_B_40 0xAC
  170. #define V35_300CD_R_40 0xAF
  171. #define V35_300CD_G_40 0xC8
  172. #define V35_300CD_B_40 0xB3
  173. #define V59_300CD_R_40 0xC2
  174. #define V59_300CD_G_40 0xD0
  175. #define V59_300CD_B_40 0xC1
  176. #define V87_300CD_R_40 0x97
  177. #define V87_300CD_G_40 0xA9
  178. #define V87_300CD_B_40 0x95
  179. #define V171_300CD_R_40 0xB3
  180. #define V171_300CD_G_40 0xBE
  181. #define V171_300CD_B_40 0xB3
  182. #define V255_300CD_R_MSB_40 0x00
  183. #define V255_300CD_R_LSB_40 0x9C
  184. #define V255_300CD_G_MSB_40 0x00
  185. #define V255_300CD_G_LSB_40 0x85
  186. #define V255_300CD_B_MSB_40 0x00
  187. #define V255_300CD_B_LSB_40 0xB2
  188. /*
  189. * ID 0x60
  190. */
  191. #define V1_300CD_R_60 0x3F
  192. #define V1_300CD_G_60 0x12
  193. #define V1_300CD_B_60 0x41
  194. #define V15_300CD_R_60 0xB4
  195. #define V15_300CD_G_60 0xCB
  196. #define V15_300CD_B_60 0xB0
  197. #define V35_300CD_R_60 0xB2
  198. #define V35_300CD_G_60 0xC4
  199. #define V35_300CD_B_60 0xB2
  200. #define V59_300CD_R_60 0xC4
  201. #define V59_300CD_G_60 0xCF
  202. #define V59_300CD_B_60 0xC2
  203. #define V87_300CD_R_60 0x9A
  204. #define V87_300CD_G_60 0xA7
  205. #define V87_300CD_B_60 0x97
  206. #define V171_300CD_R_60 0xB2
  207. #define V171_300CD_G_60 0xBA
  208. #define V171_300CD_B_60 0xB0
  209. #define V255_300CD_R_MSB_60 0x00
  210. #define V255_300CD_R_LSB_60 0xA0
  211. #define V255_300CD_G_MSB_60 0x00
  212. #define V255_300CD_G_LSB_60 0x98
  213. #define V255_300CD_B_MSB_60 0x00
  214. #define V255_300CD_B_LSB_60 0xB7
  215. #if defined(CONFIG_MACH_STRETTO) || defined(CONFIG_MACH_SUPERIORLTE_SKT)
  216. /*
  217. * ID 0xAE
  218. */
  219. #define V1_300CD_R_AE 0x5F
  220. #define V1_300CD_G_AE 0x2E
  221. #define V1_300CD_B_AE 0x67
  222. #define V15_300CD_R_AE 0xAA
  223. #define V15_300CD_G_AE 0xC6
  224. #define V15_300CD_B_AE 0xAC
  225. #define V35_300CD_R_AE 0xB0
  226. #define V35_300CD_G_AE 0xC8
  227. #define V35_300CD_B_AE 0xBB
  228. #define V59_300CD_R_AE 0xBE
  229. #define V59_300CD_G_AE 0xCB
  230. #define V59_300CD_B_AE 0xBD
  231. #define V87_300CD_R_AE 0x97
  232. #define V87_300CD_G_AE 0xA5
  233. #define V87_300CD_B_AE 0x91
  234. #define V171_300CD_R_AE 0xAF
  235. #define V171_300CD_G_AE 0xB8
  236. #define V171_300CD_B_AE 0xAB
  237. #define V255_300CD_R_MSB_AE 0x00
  238. #define V255_300CD_R_LSB_AE 0xC2
  239. #define V255_300CD_G_MSB_AE 0x00
  240. #define V255_300CD_G_LSB_AE 0xBA
  241. #define V255_300CD_B_MSB_AE 0x00
  242. #define V255_300CD_B_LSB_AE 0xE2
  243. #endif
  244. /* PANEL DEPENDENT THINGS END*/
  245. enum {
  246. V1_INDEX = 0,
  247. V15_INDEX = 1,
  248. V35_INDEX = 2,
  249. V59_INDEX = 3,
  250. V87_INDEX = 4,
  251. V171_INDEX = 5,
  252. V255_INDEX = 6,
  253. };
  254. struct GAMMA_LEVEL {
  255. int level_0;
  256. int level_1;
  257. int level_15;
  258. int level_35;
  259. int level_59;
  260. int level_87;
  261. int level_171;
  262. int level_255;
  263. } __packed;
  264. struct RGB_OUTPUT_VOLTARE {
  265. struct GAMMA_LEVEL R_VOLTAGE;
  266. struct GAMMA_LEVEL G_VOLTAGE;
  267. struct GAMMA_LEVEL B_VOLTAGE;
  268. } __packed;
  269. struct GRAY_VOLTAGE {
  270. /*
  271. This voltage value use 14bit right shit
  272. it means voltage is divied by 16384.
  273. */
  274. int R_Gray;
  275. int G_Gray;
  276. int B_Gray;
  277. } __packed;
  278. struct GRAY_SCALE {
  279. struct GRAY_VOLTAGE TABLE[S6E8AA0X01_GRAY_SCALE_MAX];
  280. } __packed;
  281. struct MTP_SET {
  282. char OFFSET_1;
  283. char OFFSET_15;
  284. char OFFSET_35;
  285. char OFFSET_59;
  286. char OFFSET_87;
  287. char OFFSET_171;
  288. char OFFSET_255_MSB;
  289. char OFFSET_255_LSB;
  290. } __packed;
  291. struct MTP_OFFSET {
  292. /*
  293. MTP_OFFSET is consist of 22 byte.
  294. First byte is dummy and 21 byte is useful.
  295. */
  296. struct MTP_SET R_OFFSET;
  297. struct MTP_SET G_OFFSET;
  298. struct MTP_SET B_OFFSET;
  299. } __packed;
  300. struct illuminance_table {
  301. int lux;
  302. char gamma_setting[GAMMA_SET_MAX];
  303. } __packed;
  304. struct SMART_DIM {
  305. struct MTP_OFFSET MTP;
  306. struct RGB_OUTPUT_VOLTARE RGB_OUTPUT;
  307. struct GRAY_SCALE GRAY;
  308. /* Because of AID funtion, below members are added*/
  309. int lux_table_max;
  310. int *plux_table;
  311. struct illuminance_table gen_table[LUMINANCE_MAX];
  312. int brightness_level;
  313. int ldi_revision;
  314. } __packed;
  315. int smart_dimming_init(struct SMART_DIM *psmart);
  316. void get_min_lux_table(char *str, int size);
  317. void generate_gamma(struct SMART_DIM *psmart, char *str, int size);
  318. #endif