mdss_jdi_dsi_panel.c 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161
  1. /* Copyright (c) 2012, Samsung Electronics. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/of.h>
  15. #include <linux/of_gpio.h>
  16. #include <linux/gpio.h>
  17. #include <linux/qpnp/pin.h>
  18. #include <linux/delay.h>
  19. #include <linux/slab.h>
  20. #include <linux/leds.h>
  21. #include <linux/pwm.h>
  22. #include <linux/err.h>
  23. #include <linux/lcd.h>
  24. #ifdef CONFIG_HAS_EARLYSUSPEND
  25. #include <linux/earlysuspend.h>
  26. #endif
  27. #include "mdss_dsi.h"
  28. #include "mdss_jdi_dsi_panel.h"
  29. #include "mdss_fb.h"
  30. #if defined(CONFIG_MDNIE_LITE_TUNING)
  31. #include "mdnie_lite_tuning.h"
  32. #endif
  33. #define DDI_VIDEO_ENHANCE_TUNING
  34. #if defined(DDI_VIDEO_ENHANCE_TUNING)
  35. #include <linux/syscalls.h>
  36. #include <asm/uaccess.h>
  37. #endif
  38. #include <asm/system_info.h>
  39. #define DT_CMD_HDR 6
  40. static struct dsi_buf dsi_panel_tx_buf;
  41. static struct dsi_buf dsi_panel_rx_buf;
  42. static struct dsi_cmd display_qcom_on_cmds;
  43. static struct dsi_cmd display_qcom_off_cmds;
  44. static struct dsi_cmd display_on_cmd;
  45. static struct dsi_cmd display_off_cmd;
  46. static struct dsi_cmd display_blank_cmd;
  47. static struct dsi_cmd display_unblank_cmd;
  48. static struct dsi_cmd touchsensing_on_cmd;
  49. static struct dsi_cmd touchsensing_off_cmd;
  50. static struct dsi_cmd late_on_cmds;
  51. static struct dsi_cmd early_off_cmds;
  52. static struct dsi_cmd brightness_cmds;
  53. static struct dsi_cmd mtp_enable_cmds;
  54. static struct dsi_cmd mtp_disable_cmds;
  55. static struct dsi_cmd cabc_on_cmds;
  56. static struct dsi_cmd cabc_off_cmds;
  57. static struct dsi_cmd hsync_on_cmds;
  58. static struct dsi_cmd hsync_off_cmds;
  59. static struct dsi_cmd manufacture_id_cmds;
  60. static struct candella_lux_map candela_map_table;
  61. /*List of supported Panels with HW revision detail
  62. * (one structure per project)
  63. * {hw_rev,"label string given in panel dtsi file"}
  64. * */
  65. static struct panel_hrev panel_supp_cdp[]= {
  66. {"jdi tft 1080p video mode dsi S6D6FA0 panel", PANEL_TFT_FHD_S6D6FA0},
  67. {NULL}
  68. };
  69. DEFINE_LED_TRIGGER(bl_led_trigger);
  70. static struct mdss_dsi_phy_ctrl phy_params;
  71. static int lcd_attached = 1;
  72. static int lcd_id = 0;
  73. static char board_rev;
  74. static int mipi_samsung_disp_send_cmd(
  75. enum mipi_samsung_cmd_list cmd,
  76. unsigned char lock);
  77. int get_lcd_attached(void);
  78. void mdss_dsi_panel_pwm_cfg(struct mdss_dsi_ctrl_pdata *ctrl)
  79. {
  80. int ret;
  81. if (!gpio_is_valid(ctrl->pwm_pmic_gpio)) {
  82. pr_err("%s: pwm_pmic_gpio=%d Invalid\n", __func__,
  83. ctrl->pwm_pmic_gpio);
  84. return;
  85. }
  86. ret = gpio_request(ctrl->pwm_pmic_gpio, "disp_pwm");
  87. if (ret) {
  88. pr_err("%s: pwm_pmic_gpio=%d request failed\n", __func__,
  89. ctrl->pwm_pmic_gpio);
  90. return;
  91. }
  92. ctrl->pwm_bl = pwm_request(ctrl->pwm_lpg_chan, "lcd-bklt");
  93. if (ctrl->pwm_bl == NULL || IS_ERR(ctrl->pwm_bl)) {
  94. pr_err("%s: lpg_chan=%d pwm request failed", __func__,
  95. ctrl->pwm_lpg_chan);
  96. gpio_free(ctrl->pwm_pmic_gpio);
  97. ctrl->pwm_pmic_gpio = -1;
  98. }
  99. }
  100. static void mdss_dsi_panel_bklt_pwm(struct mdss_dsi_ctrl_pdata *ctrl, int level)
  101. {
  102. int ret;
  103. u32 duty;
  104. if (ctrl->pwm_bl == NULL) {
  105. pr_err("%s: no PWM\n", __func__);
  106. return;
  107. }
  108. duty = level * ctrl->pwm_period;
  109. duty /= ctrl->bklt_max;
  110. pr_debug("%s: bklt_ctrl=%d pwm_period=%d pwm_pmic_gpio=%d pwm_lpg_chan=%d\n",
  111. __func__, ctrl->bklt_ctrl, ctrl->pwm_period,
  112. ctrl->pwm_pmic_gpio, ctrl->pwm_lpg_chan);
  113. pr_debug("%s: ndx=%d level=%d duty=%d\n", __func__,
  114. ctrl->ndx, level, duty);
  115. ret = pwm_config(ctrl->pwm_bl, duty, ctrl->pwm_period);
  116. if (ret) {
  117. pr_err("%s: pwm_config() failed err=%d.\n", __func__, ret);
  118. return;
  119. }
  120. ret = pwm_enable(ctrl->pwm_bl);
  121. if (ret)
  122. pr_err("%s: pwm_enable() failed err=%d\n", __func__, ret);
  123. }
  124. static char dcs_cmd[2] = {0x54, 0x00}; /* DTYPE_DCS_READ */
  125. static struct dsi_cmd_desc dcs_read_cmd = {
  126. {DTYPE_DCS_READ, 1, 0, 1, 5, sizeof(dcs_cmd)},
  127. dcs_cmd
  128. };
  129. static void dcs_read_cb(int data)
  130. {
  131. pr_info("%s: bklt_ctrl=%x\n", __func__, data);
  132. }
  133. u32 mdss_dsi_dcs_read(struct mdss_dsi_ctrl_pdata *ctrl,
  134. char cmd0, char cmd1)
  135. {
  136. struct dcs_cmd_req cmdreq;
  137. dcs_cmd[0] = cmd0;
  138. dcs_cmd[1] = cmd1;
  139. memset(&cmdreq, 0, sizeof(cmdreq));
  140. cmdreq.cmds = &dcs_read_cmd;
  141. cmdreq.cmds_cnt = 1;
  142. cmdreq.flags = CMD_REQ_RX | CMD_REQ_COMMIT;
  143. cmdreq.rlen = 1;
  144. cmdreq.cb = dcs_read_cb; /* call back */
  145. mdss_dsi_cmdlist_put(ctrl, &cmdreq);
  146. /*
  147. * blocked here, untill call back called
  148. */
  149. return 0;
  150. }
  151. void mdss_dsi_samsung_panel_reset(struct mdss_panel_data *pdata, int enable)
  152. {
  153. struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL;
  154. if (pdata == NULL) {
  155. pr_err("%s: Invalid input data\n", __func__);
  156. return;
  157. }
  158. ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata,
  159. panel_data);
  160. if (!gpio_is_valid(ctrl_pdata->rst_gpio)) {
  161. pr_debug("%s:%d, reset line not configured\n",
  162. __func__, __LINE__);
  163. }
  164. pr_debug("%s: enable = %d\n", __func__, enable);
  165. if (enable) {
  166. msleep(20);
  167. gpio_set_value((ctrl_pdata->rst_gpio), 1);
  168. msleep(20);
  169. wmb();
  170. if (ctrl_pdata->ctrl_state & CTRL_STATE_PANEL_INIT) {
  171. pr_debug("%s: Panel Not properly turned OFF\n",
  172. __func__);
  173. ctrl_pdata->ctrl_state &= ~CTRL_STATE_PANEL_INIT;
  174. pr_debug("%s: Reset panel done\n", __func__);
  175. }
  176. } else {
  177. gpio_set_value((ctrl_pdata->rst_gpio), 0);
  178. #if defined(CONFIG_FB_MSM_MIPI_JDI_TFT_VIDEO_FULL_HD_PT_PANEL)
  179. msleep(20);
  180. if (gpio_is_valid(ctrl_pdata->disp_en_gpio)) {
  181. pr_info("%s : Set Low LCD Enable GPIO \n", __func__);
  182. gpio_tlmm_config(GPIO_CFG(ctrl_pdata->disp_en_gpio, 0,
  183. GPIO_CFG_OUTPUT,GPIO_CFG_NO_PULL,GPIO_CFG_8MA),
  184. GPIO_CFG_ENABLE);
  185. gpio_set_value((ctrl_pdata->disp_en_gpio), 0);
  186. }
  187. if (gpio_is_valid(ctrl_pdata->bl_on_gpio)) {
  188. pr_info("%s : Set Low Backlight Enable GPIO \n", __func__);
  189. gpio_set_value((ctrl_pdata->bl_on_gpio), 0);
  190. }
  191. msleep(20);
  192. #endif
  193. }
  194. }
  195. #define MAX_BL_LEVEL 254 /*254 ~ 255*/
  196. static int get_candela_value(int bl_level)
  197. {
  198. if((msd.dstat.auto_brightness > 0) && (msd.dstat.auto_brightness < 5) && (bl_level >= MAX_BL_LEVEL))
  199. return candela_map_table.lux_tab[candela_map_table.bkl[MAX_BL_LEVEL-1]]; //if auto level < 5, auto brightness max : 282cd
  200. return candela_map_table.lux_tab[candela_map_table.bkl[bl_level]];
  201. }
  202. static char get_pwm_value(int bl_level)
  203. {
  204. if((msd.dstat.auto_brightness > 0) && (msd.dstat.auto_brightness < 5))
  205. return candela_map_table.cabc_pwm_tab[candela_map_table.bkl[bl_level]];
  206. else
  207. return candela_map_table.pwm_tab[candela_map_table.bkl[bl_level]];
  208. }
  209. static int get_cmd_idx(int bl_level)
  210. {
  211. return candela_map_table.cmd_idx[candela_map_table.bkl[bl_level]];
  212. }
  213. int mipi_samsung_cabc_onoff ( int cabc_set )
  214. {
  215. if (cabc_set && !(msd.dstat.cabc_on||msd.dstat.siop_status)) {
  216. msd.dstat.cabc_on = true;
  217. pr_info("%s: cabc on : cabc %d, siop %d", __func__,
  218. msd.dstat.cabc_on, msd.dstat.siop_status);
  219. mipi_samsung_disp_send_cmd(PANEL_CABC_ENABLE, true);
  220. } else if (!cabc_set && msd.dstat.cabc_on && !msd.dstat.siop_status) {
  221. msd.dstat.cabc_on = false;
  222. msd.dstat.curr_cabc_idx = -1;
  223. pr_info("%s: cabc off : cabc %d, siop %d", __func__,
  224. msd.dstat.cabc_on, msd.dstat.siop_status);
  225. mipi_samsung_disp_send_cmd(PANEL_CABC_DISABLE, true);
  226. } else {
  227. msd.dstat.cabc_on = cabc_set;
  228. pr_info("%s: skip but cabc update!! cabc %d, siop %d", __func__,
  229. msd.dstat.cabc_on, msd.dstat.siop_status);
  230. }
  231. return 0;
  232. }
  233. #if defined(CONFIG_LCD_CLASS_DEVICE)
  234. static ssize_t mipi_samsung_disp_get_power(struct device *dev,
  235. struct device_attribute *attr, char *buf)
  236. {
  237. struct msm_fb_data_type *mfd = msd.mfd;
  238. int rc;
  239. if (unlikely(!mfd))
  240. return -ENODEV;
  241. if (unlikely(mfd->key != MFD_KEY))
  242. return -EINVAL;
  243. rc = snprintf((char *)buf, 10, "%d\n", mfd->panel_power_on);
  244. pr_info("mipi_samsung_disp_get_power(%d)\n", mfd->panel_power_on);
  245. return rc;
  246. }
  247. static ssize_t mipi_samsung_disp_set_power(struct device *dev,
  248. struct device_attribute *attr, const char *buf, size_t size)
  249. {
  250. unsigned int power;
  251. struct msm_fb_data_type *mfd = msd.mfd;
  252. if (sscanf(buf, "%u", &power) != 1)
  253. return -EINVAL;
  254. if (power == mfd->panel_power_on)
  255. return 0;
  256. if (power) {
  257. mfd->fbi->fbops->fb_blank(FB_BLANK_UNBLANK, mfd->fbi);
  258. mfd->fbi->fbops->fb_pan_display(&mfd->fbi->var, mfd->fbi);
  259. mipi_samsung_disp_send_cmd(PANEL_BRIGHT_CTRL, true);
  260. } else {
  261. mfd->fbi->fbops->fb_blank(FB_BLANK_POWERDOWN, mfd->fbi);
  262. }
  263. pr_info("mipi_samsung_disp_set_power\n");
  264. return size;
  265. }
  266. static ssize_t mipi_samsung_disp_lcdtype_show(struct device *dev,
  267. struct device_attribute *attr, char *buf)
  268. {
  269. char temp[100];
  270. switch (msd.panel) {
  271. case PANEL_TFT_FHD_S6D6FA0:
  272. snprintf(temp, 20, "JDI_ACX454AKM-7");
  273. break;
  274. default :
  275. snprintf(temp, strnlen(msd.panel_name, 100),
  276. msd.panel_name);
  277. break;
  278. }
  279. strlcat(buf, temp, 100);
  280. return strnlen(buf, 100);
  281. }
  282. static ssize_t mipi_samsung_disp_windowtype_show(struct device *dev,
  283. struct device_attribute *attr, char *buf)
  284. {
  285. char temp[15];
  286. int id1, id2, id3;
  287. id1 = (msd.manufacture_id & 0x00FF0000) >> 16;
  288. id2 = (msd.manufacture_id & 0x0000FF00) >> 8;
  289. id3 = msd.manufacture_id & 0xFF;
  290. snprintf(temp, sizeof(temp), "%x %x %x\n", id1, id2, id3);
  291. strlcat(buf, temp, 15);
  292. return strnlen(buf, 15);
  293. }
  294. static ssize_t mipi_samsung_disp_cabc_show(struct device *dev,
  295. struct device_attribute *attr, char *buf)
  296. {
  297. int rc;
  298. rc = snprintf((char *)buf, 10, "%d\n", msd.dstat.cabc_on);
  299. pr_info("cabc status: %c\n", *buf);
  300. return rc;
  301. }
  302. static int make_brightcontrol_set(int bl_level)
  303. {
  304. int cd_idx = get_cmd_idx(bl_level);
  305. int cd_level = get_candela_value(bl_level);
  306. char backlight_pwm = get_pwm_value(bl_level);
  307. brightness_cmds.cmd_desc[0].payload[1] = backlight_pwm;
  308. if(msd.dstat.cabc_on ||msd.dstat.siop_status)
  309. {
  310. LCD_DEBUG("bright_level: %d, candela_idx: %d( %d cd ), cabc_pwm set: 0x%x, cabc : %d, siop : %d\n",\
  311. msd.dstat.bright_level, cd_idx, cd_level, backlight_pwm, msd.dstat.cabc_on, msd.dstat.siop_status );
  312. }
  313. else {
  314. LCD_DEBUG("bright_level: %d, candela_idx: %d( %d cd ), pwm set: 0x%x\n",\
  315. msd.dstat.bright_level, cd_idx, cd_level, backlight_pwm);
  316. }
  317. return brightness_cmds.num_of_cmds;
  318. }
  319. static ssize_t mipi_samsung_disp_cabc_store(struct device *dev,
  320. struct device_attribute *attr, const char *buf, size_t size)
  321. {
  322. struct msm_fb_data_type *mfd = msd.mfd;
  323. int cabc_on;
  324. cabc_on = msd.dstat.cabc_on;
  325. if (sysfs_streq(buf, "1"))
  326. cabc_on = true;
  327. else if (sysfs_streq(buf, "0"))
  328. cabc_on = false;
  329. else
  330. pr_info("%s: Invalid argument!!", __func__);
  331. if(mfd->resume_state == MIPI_RESUME_STATE)
  332. mipi_samsung_cabc_onoff(cabc_on);
  333. return size;
  334. }
  335. static ssize_t mipi_samsung_disp_siop_show(struct device *dev,
  336. struct device_attribute *attr, char *buf)
  337. {
  338. int rc;
  339. rc = snprintf((char *)buf, 10, "%d\n", msd.dstat.siop_status);
  340. pr_info("siop status: %d\n", *buf);
  341. return rc;
  342. }
  343. static ssize_t mipi_samsung_disp_siop_store(struct device *dev,
  344. struct device_attribute *attr, const char *buf, size_t size)
  345. {
  346. struct msm_fb_data_type *mfd = msd.mfd;
  347. int siop_set;
  348. siop_set = msd.dstat.siop_status;
  349. if (sysfs_streq(buf, "1"))
  350. siop_set = true;
  351. else if (sysfs_streq(buf, "0"))
  352. siop_set = false;
  353. else
  354. pr_info("%s: Invalid argument!!", __func__);
  355. if (mfd->panel_power_on) {
  356. if (siop_set && !(msd.dstat.cabc_on||msd.dstat.siop_status)) {
  357. msd.dstat.siop_status = true;
  358. mipi_samsung_disp_send_cmd(PANEL_CABC_ENABLE, true);
  359. pr_info("%s: cabc on : cabc %d, siop %d", __func__,
  360. msd.dstat.cabc_on, msd.dstat.siop_status);
  361. } else if (!siop_set && !msd.dstat.cabc_on && msd.dstat.siop_status) {
  362. mutex_lock(&msd.lock);
  363. msd.dstat.siop_status = false;
  364. msd.dstat.curr_cabc_idx = -1;
  365. mipi_samsung_disp_send_cmd(PANEL_CABC_DISABLE, false);
  366. mutex_unlock(&msd.lock);
  367. pr_info("%s: cabc off : cabc %d, siop %d", __func__,
  368. msd.dstat.cabc_on, msd.dstat.siop_status);
  369. } else {
  370. msd.dstat.siop_status = siop_set;
  371. pr_info("%s: skip but siop update!! cabc %d, siop %d", __func__,
  372. msd.dstat.cabc_on, msd.dstat.siop_status);
  373. }
  374. }else {
  375. msd.dstat.siop_status = siop_set;
  376. pr_info("%s: panel is off state. updating state value.\n",
  377. __func__);
  378. }
  379. return size;
  380. }
  381. static int atoi(const char *name)
  382. {
  383. int val = 0;
  384. for (;; name++) {
  385. switch (*name) {
  386. case '0' ... '9':
  387. val = 10*val+(*name-'0');
  388. break;
  389. default:
  390. return val;
  391. }
  392. }
  393. }
  394. static ssize_t mipi_samsung_backlight_show(struct device *dev,
  395. struct device_attribute *attr, char *buf)
  396. {
  397. int rc;
  398. rc = snprintf((char *)buf, 10, "%d\n",
  399. msd.dstat.bright_level );
  400. pr_info("backlight : %d\n", *buf);
  401. return rc;
  402. }
  403. static ssize_t mipi_samsung_backlight_store(struct device *dev,
  404. struct device_attribute *attr, const char *buf, size_t size)
  405. {
  406. int bl_level = atoi(buf);
  407. pr_info("%s : level (%d)\n",__func__,bl_level);
  408. msd.dstat.bright_level = bl_level;
  409. mipi_samsung_disp_send_cmd(PANEL_BRIGHT_CTRL, true);
  410. return size;
  411. }
  412. static ssize_t mipi_samsung_auto_brightness_show(struct device *dev,
  413. struct device_attribute *attr, char *buf)
  414. {
  415. int rc;
  416. rc = snprintf((char *)buf, 10, "%d\n",
  417. msd.dstat.auto_brightness);
  418. pr_info("auto_brightness: %d\n", *buf);
  419. return rc;
  420. }
  421. static ssize_t mipi_samsung_auto_brightness_store(struct device *dev,
  422. struct device_attribute *attr, const char *buf, size_t size)
  423. {
  424. // 0, 5, 6 => CABC OFF
  425. // 1, 2, 3, 4 => CABC ON
  426. if (sysfs_streq(buf, "0"))
  427. msd.dstat.auto_brightness = 0;
  428. else if (sysfs_streq(buf, "1"))
  429. msd.dstat.auto_brightness = 1;
  430. else if (sysfs_streq(buf, "2"))
  431. msd.dstat.auto_brightness = 2;
  432. else if (sysfs_streq(buf, "3"))
  433. msd.dstat.auto_brightness = 3;
  434. else if (sysfs_streq(buf, "4"))
  435. msd.dstat.auto_brightness = 4;
  436. else if (sysfs_streq(buf, "5"))
  437. msd.dstat.auto_brightness = 5;
  438. else if (sysfs_streq(buf, "6")) // HBM mode (HBM + PSRE) will be changed to // leve 6 : no HBM , RE
  439. msd.dstat.auto_brightness = 6;
  440. else if (sysfs_streq(buf, "7")) // HBM mode (HBM + PSRE)
  441. msd.dstat.auto_brightness = 7;
  442. else
  443. pr_info("%s: Invalid argument!!", __func__);
  444. if (msd.mfd->resume_state == MIPI_RESUME_STATE) {
  445. mipi_samsung_disp_send_cmd(PANEL_BRIGHT_CTRL, true);
  446. pr_info("%s %d %d\n", __func__, msd.dstat.auto_brightness, msd.dstat.bright_level);
  447. #if defined(AUTO_BRIGHTNESS_CABC_FUNCTION)
  448. if( (msd.dstat.auto_brightness >= 1) && (msd.dstat.auto_brightness <= 4) )
  449. mipi_samsung_cabc_onoff ( 1 );
  450. else
  451. mipi_samsung_cabc_onoff ( 0 );
  452. #endif
  453. } else {
  454. pr_info("%s : panel is off state!!\n", __func__);
  455. }
  456. return size;
  457. }
  458. /*pwm backlight tunning*/
  459. static ssize_t pwm_backlight_store(struct device *dev,
  460. struct device_attribute *attr, const char *buf, size_t size)
  461. {
  462. unsigned int pwm_buf;
  463. if (sscanf(buf, "%u", &pwm_buf) != 1)
  464. return -EINVAL;
  465. if (msd.mfd->resume_state == MIPI_RESUME_STATE)
  466. {
  467. mutex_lock(&msd.lock);
  468. brightness_cmds.cmd_desc[0].payload[1] = (char)pwm_buf;
  469. mdss_dsi_cmds_send(msd.ctrl_pdata, brightness_cmds.cmd_desc, brightness_cmds.num_of_cmds, 0);
  470. mutex_unlock(&msd.lock);
  471. pr_info("%s, pwm set : 0x%x\n", __func__, (char)pwm_buf);
  472. } else {
  473. pr_info("%s : panel is off state!!\n", __func__);
  474. }
  475. return size;
  476. }
  477. static struct lcd_ops mipi_samsung_disp_props = {
  478. .get_power = NULL,
  479. .set_power = NULL,
  480. };
  481. static DEVICE_ATTR(lcd_power, S_IRUGO | S_IWUSR,
  482. mipi_samsung_disp_get_power,
  483. mipi_samsung_disp_set_power);
  484. static DEVICE_ATTR(lcd_type, S_IRUGO, mipi_samsung_disp_lcdtype_show, NULL);
  485. static DEVICE_ATTR(window_type, S_IRUGO,
  486. mipi_samsung_disp_windowtype_show, NULL);
  487. static DEVICE_ATTR(power_reduce, S_IRUGO | S_IWUSR | S_IWGRP,
  488. mipi_samsung_disp_cabc_show,
  489. mipi_samsung_disp_cabc_store);
  490. static DEVICE_ATTR(auto_brightness, S_IRUGO | S_IWUSR | S_IWGRP,
  491. mipi_samsung_auto_brightness_show,
  492. mipi_samsung_auto_brightness_store);
  493. static DEVICE_ATTR(backlight, S_IRUGO | S_IWUSR | S_IWGRP,
  494. mipi_samsung_backlight_show,
  495. mipi_samsung_backlight_store);
  496. static DEVICE_ATTR(siop_enable, S_IRUGO | S_IWUSR | S_IWGRP,
  497. mipi_samsung_disp_siop_show,
  498. mipi_samsung_disp_siop_store);
  499. static DEVICE_ATTR(pwm_backlight, S_IRUGO | S_IWUSR | S_IWGRP,
  500. NULL,
  501. pwm_backlight_store);
  502. #endif
  503. #if !defined(CONFIG_FB_MSM_EDP_SAMSUNG)
  504. static int __init current_boot_mode(char *mode)
  505. {
  506. /*
  507. * 1,2 is recovery booting
  508. * 0 is normal booting
  509. */
  510. if ((strncmp(mode, "1", 1) == 0)||(strncmp(mode, "2", 1) == 0))
  511. msd.dstat.recovery_boot_mode = 1;
  512. else
  513. msd.dstat.recovery_boot_mode = 0;
  514. pr_debug("%s %s", __func__, msd.dstat.recovery_boot_mode == 1 ?
  515. "recovery" : "normal");
  516. return 1;
  517. }
  518. __setup("androidboot.boot_recovery=", current_boot_mode);
  519. #endif
  520. void mdss_dsi_cmds_send(struct mdss_dsi_ctrl_pdata *ctrl, struct dsi_cmd_desc *cmds, int cnt,int flag)
  521. {
  522. struct dcs_cmd_req cmdreq;
  523. if (get_lcd_attached() == 0)
  524. {
  525. printk("%s: get_lcd_attached(0)!\n",__func__);
  526. return;
  527. }
  528. memset(&cmdreq, 0, sizeof(cmdreq));
  529. if (flag & CMD_REQ_SINGLE_TX) {
  530. cmdreq.flags = CMD_REQ_SINGLE_TX | CMD_CLK_CTRL | CMD_REQ_COMMIT;
  531. }else
  532. cmdreq.flags = CMD_REQ_COMMIT | CMD_CLK_CTRL;
  533. cmdreq.cmds = cmds;
  534. cmdreq.cmds_cnt = cnt;
  535. cmdreq.rlen = 0;
  536. cmdreq.cb = NULL;
  537. /*
  538. * This mutex is to sync up with dynamic FPS changes
  539. * so that DSI lockups shall not happen
  540. */
  541. BUG_ON(msd.ctrl_pdata == NULL);
  542. mutex_lock(&msd.ctrl_pdata->dfps_mutex);
  543. mdss_dsi_cmdlist_put(ctrl, &cmdreq);
  544. mutex_unlock(&msd.ctrl_pdata->dfps_mutex);
  545. }
  546. u32 mdss_dsi_cmd_receive(struct mdss_dsi_ctrl_pdata *ctrl, struct dsi_cmd_desc *cmd, int rlen)
  547. {
  548. struct dcs_cmd_req cmdreq;
  549. memset(&cmdreq, 0, sizeof(cmdreq));
  550. cmdreq.cmds = cmd;
  551. cmdreq.cmds_cnt = 1;
  552. cmdreq.flags = CMD_REQ_RX | CMD_REQ_COMMIT;
  553. cmdreq.rbuf = ctrl->rx_buf.data;
  554. cmdreq.rlen = rlen;
  555. cmdreq.cb = NULL; /* call back */
  556. /*
  557. * This mutex is to sync up with dynamic FPS changes
  558. * so that DSI lockups shall not happen
  559. */
  560. BUG_ON(msd.ctrl_pdata == NULL);
  561. mutex_lock(&msd.ctrl_pdata->dfps_mutex);
  562. mdss_dsi_cmdlist_put(ctrl, &cmdreq);
  563. mutex_unlock(&msd.ctrl_pdata->dfps_mutex);
  564. /*
  565. * blocked here, untill call back called
  566. */
  567. return ctrl->rx_buf.len;
  568. }
  569. static unsigned int mipi_samsung_manufacture_id(struct mdss_panel_data *pdata)
  570. {
  571. struct dsi_buf *rp, *tp;
  572. unsigned int id = 0 ;
  573. if (get_lcd_attached() == 0)
  574. {
  575. printk("%s: get_lcd_attached(0)!\n",__func__);
  576. return id;
  577. }
  578. if (!manufacture_id_cmds.num_of_cmds)
  579. return 0;
  580. mipi_samsung_disp_send_cmd(PANEL_MTP_ENABLE, true);
  581. tp = &dsi_panel_tx_buf;
  582. rp = &dsi_panel_rx_buf;
  583. mdss_dsi_cmd_receive(msd.ctrl_pdata,
  584. &manufacture_id_cmds.cmd_desc[0],
  585. manufacture_id_cmds.read_size[0]);
  586. pr_info("%s: manufacture_id1=%x\n", __func__, *msd.ctrl_pdata->rx_buf.data);
  587. id = (*((unsigned int *)msd.ctrl_pdata->rx_buf.data) & 0xFF);
  588. id <<= 8;
  589. mdss_dsi_cmd_receive(msd.ctrl_pdata,
  590. &manufacture_id_cmds.cmd_desc[1],
  591. manufacture_id_cmds.read_size[1]);
  592. pr_info("%s: manufacture_id2=%x\n", __func__, *msd.ctrl_pdata->rx_buf.data);
  593. id |= (*((unsigned int *)msd.ctrl_pdata->rx_buf.data) & 0xFF);
  594. id <<= 8;
  595. mdss_dsi_cmd_receive(msd.ctrl_pdata,
  596. &manufacture_id_cmds.cmd_desc[2],
  597. manufacture_id_cmds.read_size[2]);
  598. pr_info("%s: manufacture_id3=%x\n", __func__, *msd.ctrl_pdata->rx_buf.data);
  599. id |= (*((unsigned int *)msd.ctrl_pdata->rx_buf.data) & 0xFF);
  600. gv_manufacture_id = id;
  601. mipi_samsung_disp_send_cmd(PANEL_MTP_DISABLE, true);
  602. pr_info("%s: manufacture_id=%x\n", __func__, id);
  603. return id;
  604. }
  605. static void mdss_dsi_panel_bl_ctrl(struct mdss_panel_data *pdata,
  606. u32 bl_level)
  607. {
  608. struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL;
  609. /*Dont need to send backlight command if display off*/
  610. if (msd.mfd->resume_state != MIPI_RESUME_STATE)
  611. return;
  612. ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata,
  613. panel_data);
  614. if (!ctrl_pdata) {
  615. pr_err("%s: Invalid input data\n", __func__);
  616. return;
  617. }
  618. switch (ctrl_pdata->bklt_ctrl) {
  619. case BL_WLED:
  620. led_trigger_event(bl_led_trigger, bl_level);
  621. break;
  622. case BL_PWM:
  623. mdss_dsi_panel_bklt_pwm(ctrl_pdata, bl_level);
  624. break;
  625. case BL_DCS_CMD:
  626. msd.dstat.bright_level = bl_level;
  627. mipi_samsung_disp_send_cmd(PANEL_BRIGHT_CTRL, true);
  628. break;
  629. default:
  630. pr_err("%s: Unknown bl_ctrl configuration\n",
  631. __func__);
  632. break;
  633. }
  634. }
  635. static int mipi_samsung_disp_send_cmd(
  636. enum mipi_samsung_cmd_list cmd,
  637. unsigned char lock)
  638. {
  639. /* fix build error temporary */
  640. /* struct msm_fb_data_type *mfd = msd.mfd;*/
  641. struct dsi_cmd_desc *cmd_desc;
  642. int cmd_size = 0;
  643. int flag = 0;
  644. #ifdef CMD_DEBUG
  645. int i,j;
  646. #endif
  647. if (get_lcd_attached() == 0)
  648. {
  649. printk("%s: get_lcd_attached(0)!\n",__func__);
  650. return -ENODEV;
  651. }
  652. if (lock)
  653. mutex_lock(&msd.lock);
  654. switch (cmd) {
  655. case PANEL_READY_TO_ON:
  656. cmd_desc = display_qcom_on_cmds.cmd_desc;
  657. cmd_size = display_qcom_on_cmds.num_of_cmds;
  658. break;
  659. case PANEL_DISP_OFF:
  660. cmd_desc = display_qcom_off_cmds.cmd_desc;
  661. cmd_size = display_qcom_off_cmds.num_of_cmds;
  662. break;
  663. case PANEL_DISPLAY_ON:
  664. cmd_desc = display_on_cmd.cmd_desc;
  665. cmd_size = display_on_cmd.num_of_cmds;
  666. break;
  667. case PANEL_DISPLAY_OFF:
  668. cmd_desc = display_off_cmd.cmd_desc;
  669. cmd_size = display_off_cmd.num_of_cmds;
  670. break;
  671. case PANEL_DISPLAY_UNBLANK:
  672. cmd_desc = display_unblank_cmd.cmd_desc;
  673. cmd_size = display_unblank_cmd.num_of_cmds;
  674. break;
  675. case PANEL_DISPLAY_BLANK:
  676. cmd_desc = display_blank_cmd.cmd_desc;
  677. cmd_size = display_blank_cmd.num_of_cmds;
  678. break;
  679. case PANEL_BRIGHT_CTRL:
  680. if(msd.mfd->blank_mode != 0){
  681. pr_err("%s : panel is off state!!\n", __func__);
  682. goto panel_power_off;
  683. }
  684. cmd_desc = brightness_cmds.cmd_desc;
  685. cmd_size = make_brightcontrol_set(msd.dstat.bright_level);
  686. /* Single Tx use for DSI_VIDEO_MODE Only */
  687. #if 0
  688. if(msd.pdata->panel_info.mipi.mode == DSI_VIDEO_MODE)
  689. flag = CMD_REQ_SINGLE_TX;
  690. else
  691. flag = 0;
  692. #endif
  693. break;
  694. case PANEL_MTP_ENABLE:
  695. cmd_desc = mtp_enable_cmds.cmd_desc;
  696. cmd_size = mtp_enable_cmds.num_of_cmds;
  697. break;
  698. case PANEL_MTP_DISABLE:
  699. cmd_desc = mtp_disable_cmds.cmd_desc;
  700. cmd_size = mtp_disable_cmds.num_of_cmds;
  701. break;
  702. case PANEL_LATE_ON:
  703. cmd_desc = late_on_cmds.cmd_desc;
  704. cmd_size = late_on_cmds.num_of_cmds;
  705. break;
  706. case PANEL_TOUCHSENSING_ON:
  707. cmd_desc = touchsensing_on_cmd.cmd_desc;
  708. cmd_size = touchsensing_on_cmd.num_of_cmds;
  709. break;
  710. case PANEL_TOUCHSENSING_OFF:
  711. cmd_desc = touchsensing_off_cmd.cmd_desc;
  712. cmd_size = touchsensing_off_cmd.num_of_cmds;
  713. break;
  714. case PANEL_EARLY_OFF:
  715. cmd_desc = early_off_cmds.cmd_desc;
  716. cmd_size = early_off_cmds.num_of_cmds;
  717. break;
  718. #if defined(AUTO_BRIGHTNESS_CABC_FUNCTION)
  719. case PANEL_CABC_ENABLE:
  720. if(msd.mfd->blank_mode != 0){
  721. pr_err("%s : panel is off state!!\n", __func__);
  722. goto panel_power_off;
  723. }
  724. cmd_desc = cabc_on_cmds.cmd_desc;
  725. cmd_size = cabc_on_cmds.num_of_cmds;
  726. break;
  727. case PANEL_CABC_DISABLE:
  728. cmd_desc = cabc_off_cmds.cmd_desc;
  729. cmd_size = cabc_off_cmds.num_of_cmds;
  730. break;
  731. #endif
  732. case PANEL_HSYNC_ON:
  733. cmd_desc = hsync_on_cmds.cmd_desc;
  734. cmd_size = hsync_on_cmds.num_of_cmds;
  735. break;
  736. case PANEL_HSYNC_OFF:
  737. cmd_desc = hsync_off_cmds.cmd_desc;
  738. cmd_size = hsync_off_cmds.num_of_cmds;
  739. break;
  740. default:
  741. pr_err("%s : unknown_command.. \n", __func__);
  742. goto unknown_command;
  743. ;
  744. }
  745. if (!cmd_size) {
  746. pr_err("%s : cmd_size is zero!.. \n", __func__);
  747. goto unknown_command;
  748. }
  749. #ifdef CMD_DEBUG
  750. for (i = 0; i < cmd_size; i++)
  751. {
  752. for (j = 0; j < cmd_desc[i].dchdr.dlen; j++)
  753. printk("%x ",cmd_desc[i].payload[j]);
  754. printk("\n");
  755. }
  756. #endif
  757. #ifdef MDP_RECOVERY
  758. if (!mdss_recovery_start)
  759. mdss_dsi_cmds_send(msd.ctrl_pdata, cmd_desc, cmd_size, flag);
  760. else
  761. pr_err ("%s : Can't send command during mdss_recovery_start\n", __func__);
  762. #else
  763. mdss_dsi_cmds_send(msd.ctrl_pdata, cmd_desc, cmd_size, flag);
  764. #endif
  765. if (lock)
  766. mutex_unlock(&msd.lock);
  767. return 0;
  768. unknown_command:
  769. LCD_DEBUG("Undefined command\n");
  770. panel_power_off:
  771. if (lock)
  772. mutex_unlock(&msd.lock);
  773. return -EINVAL;
  774. }
  775. void mdss_dsi_panel_touchsensing(int enable)
  776. {
  777. if(!msd.dstat.on)
  778. {
  779. pr_err("%s: No panel on! %d\n", __func__, enable);
  780. return;
  781. }
  782. /*
  783. if(enable)
  784. mipi_samsung_disp_send_cmd(PANEL_TOUCHSENSING_ON, true);
  785. else
  786. mipi_samsung_disp_send_cmd(PANEL_TOUCHSENSING_OFF, true);
  787. */
  788. pr_info("%s --\n", __func__);
  789. }
  790. void mdss_dsi_panel_hsync_onoff(bool onoff)
  791. {
  792. struct msm_fb_data_type *mfd = msd.mfd;
  793. if (mfd && mfd->panel_power_on/* && msd.dstat.on*/)
  794. {
  795. if( onoff )
  796. {
  797. msleep(30);
  798. mipi_samsung_disp_send_cmd(PANEL_HSYNC_ON, true);
  799. pr_info("%s : HSYNC On\n",__func__);
  800. }
  801. else
  802. {
  803. mipi_samsung_disp_send_cmd(PANEL_HSYNC_OFF, true);
  804. msleep(10);
  805. pr_info("%s : HSYNC Off\n",__func__);
  806. }
  807. }
  808. else
  809. pr_err("%s : panel power off\n",__func__);
  810. return;
  811. }
  812. EXPORT_SYMBOL(mdss_dsi_panel_hsync_onoff);
  813. static int mdss_dsi_panel_registered(struct mdss_panel_data *pdata)
  814. {
  815. struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL;
  816. if (pdata == NULL) {
  817. pr_err("%s: Invalid input data\n", __func__);
  818. return -EINVAL;
  819. }
  820. ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata,
  821. panel_data);
  822. msd.mfd = (struct msm_fb_data_type *)registered_fb[0]->par;
  823. msd.pdata = pdata;
  824. msd.ctrl_pdata = ctrl_pdata;
  825. #if defined(CONFIG_MDNIE_LITE_TUNING)
  826. pr_info("[%s] CONFIG_MDNIE_LITE_TUNING ok ! init class called!\n",
  827. __func__);
  828. mdnie_lite_tuning_init(&msd);
  829. #endif
  830. /* Set the initial state to Suspend until it is switched on */
  831. msd.mfd->resume_state = MIPI_SUSPEND_STATE;
  832. pr_info("%s:%d, Panel registered succesfully\n", __func__, __LINE__);
  833. return 0;
  834. }
  835. static int mdss_dsi_panel_on(struct mdss_panel_data *pdata)
  836. {
  837. struct mipi_panel_info *mipi;
  838. struct mdss_dsi_ctrl_pdata *ctrl = NULL;
  839. if (pdata == NULL) {
  840. pr_err("%s: Invalid input data\n", __func__);
  841. return -EINVAL;
  842. }
  843. ctrl = container_of(pdata, struct mdss_dsi_ctrl_pdata,
  844. panel_data);
  845. mipi = &pdata->panel_info.mipi;
  846. pr_info("mdss_dsi_panel_on DSI_MODE = %d ++\n",mipi->mode);
  847. pr_debug("%s: ctrl=%pK ndx=%d\n", __func__, ctrl, ctrl->ndx);
  848. if (0 && !msd.manufacture_id)
  849. msd.manufacture_id = mipi_samsung_manufacture_id(pdata);
  850. // mipi_samsung_disp_send_cmd(PANEL_READY_TO_ON, true);
  851. /* Recovery Mode : Set some default brightness */
  852. if (msd.dstat.recovery_boot_mode) {
  853. msd.dstat.bright_level = RECOVERY_BRIGHTNESS;
  854. }
  855. mipi_samsung_disp_send_cmd(PANEL_BRIGHT_CTRL, true);
  856. /* Init Index Values */
  857. msd.dstat.curr_elvss_idx = -1;
  858. msd.dstat.curr_cabc_idx = -1;
  859. msd.dstat.curr_aid_idx = -1;
  860. msd.dstat.hbm_mode = 0;
  861. msd.dstat.on = 1;
  862. msd.dstat.wait_disp_on = 1;
  863. msd.mfd->resume_state = MIPI_RESUME_STATE;
  864. pr_info("%s--\n", __func__);
  865. return 0;
  866. }
  867. static int mdss_dsi_panel_off(struct mdss_panel_data *pdata)
  868. {
  869. struct mipi_panel_info *mipi;
  870. struct mdss_dsi_ctrl_pdata *ctrl = NULL;
  871. if (pdata == NULL) {
  872. pr_err("%s: Invalid input data\n", __func__);
  873. return -EINVAL;
  874. }
  875. pr_info("mdss_dsi_panel_off ++\n");
  876. ctrl = container_of(pdata, struct mdss_dsi_ctrl_pdata,
  877. panel_data);
  878. pr_debug("%s: ctrl=%pK ndx=%d\n", __func__, ctrl, ctrl->ndx);
  879. mipi = &pdata->panel_info.mipi;
  880. mutex_lock(&msd.lock);
  881. msd.dstat.on = 0;
  882. msd.mfd->resume_state = MIPI_SUSPEND_STATE;
  883. ctrl->dsi_err_cnt = 0;
  884. mipi_samsung_disp_send_cmd(PANEL_DISPLAY_OFF, false);
  885. mutex_unlock(&msd.lock);
  886. pr_info("mdss_dsi_panel_off --\n");
  887. return 0;
  888. }
  889. static int mdss_samsung_parse_candela_lux_mapping_table(struct device_node *np,
  890. struct candella_lux_map *table, char *keystring)
  891. {
  892. const __be32 *data;
  893. int data_offset, len = 0 , i = 0;
  894. int cdmap_start=0, cdmap_end=0;
  895. data = of_get_property(np, keystring, &len);
  896. if (!data) {
  897. pr_err("%s:%d, Unable to read table %s ",
  898. __func__, __LINE__, keystring);
  899. return -EINVAL;
  900. }
  901. if ((len % 4) != 0) {
  902. pr_err("%s:%d, Incorrect table entries for %s",
  903. __func__, __LINE__, keystring);
  904. return -EINVAL;
  905. }
  906. table->lux_tab_size = len / (sizeof(int)*6);
  907. table->lux_tab = kzalloc((sizeof(int) * table->lux_tab_size), GFP_KERNEL);
  908. if (!table->lux_tab)
  909. return -ENOMEM;
  910. table->pwm_tab = kzalloc((sizeof(int) * table->lux_tab_size), GFP_KERNEL);
  911. if (!table->pwm_tab)
  912. return -ENOMEM;
  913. table->cabc_pwm_tab = kzalloc((sizeof(int) * table->lux_tab_size), GFP_KERNEL);
  914. if (!table->cabc_pwm_tab)
  915. return -ENOMEM;
  916. table->cmd_idx = kzalloc((sizeof(int) * table->lux_tab_size), GFP_KERNEL);
  917. if (!table->cmd_idx)
  918. goto error;
  919. data_offset = 0;
  920. for (i = 0 ; i < table->lux_tab_size; i++) {
  921. table->cmd_idx[i]= be32_to_cpup(&data[data_offset++]); /* 1rst field => <idx> */
  922. cdmap_start = be32_to_cpup(&data[data_offset++]); /* 2nd field => <from> */
  923. cdmap_end = be32_to_cpup(&data[data_offset++]); /* 3rd field => <till> */
  924. table->lux_tab[i] = be32_to_cpup(&data[data_offset++]); /* 4th field => <candella> */
  925. table->pwm_tab[i]= be32_to_cpup(&data[data_offset++]); /* 5th field => <pwm> */
  926. table->cabc_pwm_tab[i]= be32_to_cpup(&data[data_offset++]); /* 6th field => <cabc_pwm> */
  927. /* Fill the backlight level to lux mapping array */
  928. do{
  929. table->bkl[cdmap_start++] = i;
  930. }while(cdmap_start <= cdmap_end);
  931. }
  932. return 0;
  933. error:
  934. kfree(table->lux_tab);
  935. kfree(table->pwm_tab);
  936. kfree(table->cabc_pwm_tab);
  937. return -ENOMEM;
  938. }
  939. static int mdss_samsung_parse_panel_cmd(struct device_node *np,
  940. struct dsi_cmd *commands, char *keystring)
  941. {
  942. const char *data;
  943. int type, len = 0, i = 0;
  944. char *bp;
  945. struct dsi_ctrl_hdr *dchdr;
  946. int is_read = 0;
  947. data = of_get_property(np, keystring, &len);
  948. if (!data) {
  949. pr_err("%s:%d, Unable to read %s",
  950. __func__, __LINE__, keystring);
  951. return -ENOMEM;
  952. }
  953. commands->cmds_buff = kzalloc(sizeof(char) * len, GFP_KERNEL);
  954. if (!commands->cmds_buff)
  955. return -ENOMEM;
  956. memcpy(commands->cmds_buff, data, len);
  957. commands->cmds_len = len;
  958. /* scan dcs commands */
  959. bp = commands->cmds_buff;
  960. while (len > sizeof(*dchdr)) {
  961. dchdr = (struct dsi_ctrl_hdr *)bp;
  962. dchdr->dlen = ntohs(dchdr->dlen);
  963. if (dchdr->dlen >200)
  964. goto error2;
  965. bp += sizeof(*dchdr);
  966. len -= sizeof(*dchdr);
  967. bp += dchdr->dlen;
  968. len -= dchdr->dlen;
  969. commands->num_of_cmds++;
  970. type = dchdr->dtype;
  971. if (type == DTYPE_GEN_READ ||
  972. type == DTYPE_GEN_READ1 ||
  973. type == DTYPE_GEN_READ2 ||
  974. type == DTYPE_DCS_READ) {
  975. /* Read command :last byte contain read size, read start */
  976. bp += 2;
  977. len -= 2;
  978. is_read = 1;
  979. }
  980. }
  981. if (len != 0) {
  982. pr_err("%s: dcs OFF command byte Error, len=%d", __func__, len);
  983. commands->cmds_len = 0;
  984. commands->num_of_cmds = 0;
  985. goto error2;
  986. }
  987. if (is_read) {
  988. /*
  989. Allocate an array which will store the number
  990. for bytes to read for each read command
  991. */
  992. commands->read_size = kzalloc(sizeof(char) * \
  993. commands->num_of_cmds, GFP_KERNEL);
  994. if (!commands->read_size) {
  995. pr_err("%s:%d, Unable to read NV cmds",
  996. __func__, __LINE__);
  997. goto error2;
  998. }
  999. commands->read_startoffset = kzalloc(sizeof(char) * \
  1000. commands->num_of_cmds, GFP_KERNEL);
  1001. if (!commands->read_startoffset) {
  1002. pr_err("%s:%d, Unable to read NV cmds",
  1003. __func__, __LINE__);
  1004. goto error1;
  1005. }
  1006. }
  1007. commands->cmd_desc = kzalloc(commands->num_of_cmds
  1008. * sizeof(struct dsi_cmd_desc),
  1009. GFP_KERNEL);
  1010. if (!commands->cmd_desc)
  1011. goto error1;
  1012. bp = commands->cmds_buff;
  1013. len = commands->cmds_len;
  1014. for (i = 0; i < commands->num_of_cmds; i++) {
  1015. dchdr = (struct dsi_ctrl_hdr *)bp;
  1016. len -= sizeof(*dchdr);
  1017. bp += sizeof(*dchdr);
  1018. commands->cmd_desc[i].dchdr = *dchdr;
  1019. commands->cmd_desc[i].payload = bp;
  1020. bp += dchdr->dlen;
  1021. len -= dchdr->dlen;
  1022. if (is_read)
  1023. {
  1024. commands->read_size[i] = *bp++;
  1025. commands->read_startoffset[i] = *bp++;
  1026. len -= 2;
  1027. }
  1028. }
  1029. return 0;
  1030. error1:
  1031. kfree(commands->read_size);
  1032. error2:
  1033. kfree(commands->cmds_buff);
  1034. return -EINVAL;
  1035. }
  1036. static int mdss_dsi_parse_dcs_cmds(struct device_node *np,
  1037. struct dsi_panel_cmds *pcmds, char *cmd_key, char *link_key)
  1038. {
  1039. const char *data;
  1040. int blen = 0, len;
  1041. char *buf, *bp;
  1042. struct dsi_ctrl_hdr *dchdr;
  1043. int i, cnt;
  1044. data = of_get_property(np, cmd_key, &blen);
  1045. if (!data) {
  1046. pr_err("%s: failed, key=%s\n", __func__, cmd_key);
  1047. return -ENOMEM;
  1048. }
  1049. buf = kzalloc(sizeof(char) * blen, GFP_KERNEL);
  1050. if (!buf)
  1051. return -ENOMEM;
  1052. memcpy(buf, data, blen);
  1053. /* scan dcs commands */
  1054. bp = buf;
  1055. len = blen;
  1056. cnt = 0;
  1057. while (len > sizeof(*dchdr)) {
  1058. dchdr = (struct dsi_ctrl_hdr *)bp;
  1059. dchdr->dlen = ntohs(dchdr->dlen);
  1060. if (dchdr->dlen > len) {
  1061. pr_err("%s: dtsi cmd=%x error, len=%d",
  1062. __func__, dchdr->dtype, dchdr->dlen);
  1063. return -ENOMEM;
  1064. }
  1065. bp += sizeof(*dchdr);
  1066. len -= sizeof(*dchdr);
  1067. bp += dchdr->dlen;
  1068. len -= dchdr->dlen;
  1069. cnt++;
  1070. }
  1071. if (len != 0) {
  1072. pr_err("%s: dcs_cmd=%x len=%d error!",
  1073. __func__, buf[0], blen);
  1074. kfree(buf);
  1075. return -ENOMEM;
  1076. }
  1077. pcmds->cmds = kzalloc(cnt * sizeof(struct dsi_cmd_desc),
  1078. GFP_KERNEL);
  1079. if (!pcmds->cmds){
  1080. kfree(buf);
  1081. return -ENOMEM;
  1082. }
  1083. pcmds->cmd_cnt = cnt;
  1084. pcmds->buf = buf;
  1085. pcmds->blen = blen;
  1086. bp = buf;
  1087. len = blen;
  1088. for (i = 0; i < cnt; i++) {
  1089. dchdr = (struct dsi_ctrl_hdr *)bp;
  1090. len -= sizeof(*dchdr);
  1091. bp += sizeof(*dchdr);
  1092. pcmds->cmds[i].dchdr = *dchdr;
  1093. pcmds->cmds[i].payload = bp;
  1094. bp += dchdr->dlen;
  1095. len -= dchdr->dlen;
  1096. }
  1097. data = of_get_property(np, link_key, NULL);
  1098. if (!strncmp(data, "dsi_hs_mode", 11))
  1099. pcmds->link_state = DSI_HS_MODE;
  1100. else
  1101. pcmds->link_state = DSI_LP_MODE;
  1102. pr_debug("%s: dcs_cmd=%x len=%d, cmd_cnt=%d link_state=%d\n", __func__,
  1103. pcmds->buf[0], pcmds->blen, pcmds->cmd_cnt, pcmds->link_state);
  1104. return 0;
  1105. }
  1106. static int mdss_panel_parse_dt(struct device_node *np,
  1107. struct mdss_dsi_ctrl_pdata *ctrl_pdata)
  1108. {
  1109. u32 res[6], tmp;
  1110. u32 fbc_res[7];
  1111. int rc, i, len;
  1112. const char *data;
  1113. static const char *bl_ctrl_type, *pdest;
  1114. struct mdss_panel_info *pinfo = &(ctrl_pdata->panel_data.panel_info);
  1115. bool fbc_enabled = false;
  1116. rc = of_property_read_u32_array(np, "qcom,mdss-pan-res", res, 2);
  1117. if (rc) {
  1118. pr_err("%s:%d, panel resolution not specified\n",
  1119. __func__, __LINE__);
  1120. return -EINVAL;
  1121. }
  1122. pinfo->xres = (!rc ? res[0] : 640);
  1123. pinfo->yres= (!rc ? res[1] : 480);
  1124. rc = of_property_read_u32_array(np, "qcom,mdss-pan-size", res, 2);
  1125. if (rc == 0) {
  1126. pinfo->width = res[0];
  1127. pinfo->height = res[1];
  1128. }
  1129. rc = of_property_read_u32_array(np, "qcom,mdss-pan-active-res", res, 2);
  1130. if (rc == 0) {
  1131. pinfo->lcdc.xres_pad =
  1132. pinfo->xres - res[0];
  1133. pinfo->lcdc.yres_pad =
  1134. pinfo->yres - res[1];
  1135. }
  1136. rc = of_property_read_u32(np, "qcom,mdss-pan-bpp", &tmp);
  1137. if (rc) {
  1138. pr_err("%s:%d, panel bpp not specified\n",
  1139. __func__, __LINE__);
  1140. return -EINVAL;
  1141. }
  1142. pinfo->bpp = (!rc ? tmp : 24);
  1143. pdest = of_get_property(np,
  1144. "qcom,mdss-pan-dest", NULL);
  1145. if (strlen(pdest) != 9) {
  1146. pr_err("%s: Unknown pdest specified\n", __func__);
  1147. return -EINVAL;
  1148. }
  1149. if (!strncmp(pdest, "display_1", 9))
  1150. pinfo->pdest = DISPLAY_1;
  1151. else if (!strncmp(pdest, "display_2", 9))
  1152. pinfo->pdest = DISPLAY_2;
  1153. else {
  1154. pr_debug("%s: pdest not specified. Set Default\n",
  1155. __func__);
  1156. pinfo->pdest = DISPLAY_1;
  1157. }
  1158. rc = of_property_read_u32_array(np,
  1159. "qcom,mdss-pan-porch-values", res, 6);
  1160. pinfo->lcdc.h_back_porch = (!rc ? res[0] : 6);
  1161. pinfo->lcdc.h_pulse_width = (!rc ? res[1] : 2);
  1162. pinfo->lcdc.h_front_porch = (!rc ? res[2] : 6);
  1163. pinfo->lcdc.v_back_porch = (!rc ? res[3] : 6);
  1164. pinfo->lcdc.v_pulse_width = (!rc ? res[4] : 2);
  1165. pinfo->lcdc.v_front_porch = (!rc ? res[5] : 6);
  1166. rc = of_property_read_u32(np,
  1167. "qcom,mdss-pan-underflow-clr", &tmp);
  1168. pinfo->lcdc.underflow_clr = (!rc ? tmp : 0xff);
  1169. bl_ctrl_type = of_get_property(np,
  1170. "qcom,mdss-pan-bl-ctrl", NULL);
  1171. if ((bl_ctrl_type) && (!strncmp(bl_ctrl_type, "bl_ctrl_wled", 12))) {
  1172. led_trigger_register_simple("bkl-trigger", &bl_led_trigger);
  1173. pr_debug("%s: SUCCESS-> WLED TRIGGER register\n", __func__);
  1174. pinfo->bklt_ctrl = BL_WLED;
  1175. } else if (!strncmp(bl_ctrl_type, "bl_ctrl_pwm", 11)) {
  1176. ctrl_pdata->bklt_ctrl = BL_PWM;
  1177. rc = of_property_read_u32(np, "qcom,dsi-pwm-period", &tmp);
  1178. if (rc) {
  1179. pr_err("%s:%d, Error, dsi pwm_period\n",
  1180. __func__, __LINE__);
  1181. return -EINVAL;
  1182. }
  1183. ctrl_pdata->pwm_period = tmp;
  1184. rc = of_property_read_u32(np, "qcom,dsi-lpg-channel", &tmp);
  1185. if (rc) {
  1186. pr_err("%s:%d, Error, dsi lpg channel\n",
  1187. __func__, __LINE__);
  1188. return -EINVAL;
  1189. }
  1190. ctrl_pdata->pwm_lpg_chan = tmp;
  1191. tmp = of_get_named_gpio(np, "qcom,dsi-pwm-gpio", 0);
  1192. ctrl_pdata->pwm_pmic_gpio = tmp;
  1193. } else if (!strncmp(bl_ctrl_type, "bl_ctrl_dcs_cmds", 12)) {
  1194. pr_debug("%s: SUCCESS-> DCS CMD BACKLIGHT register\n",
  1195. __func__);
  1196. ctrl_pdata->bklt_ctrl = BL_DCS_CMD;
  1197. } else {
  1198. pr_debug("%s: Unknown backlight control\n", __func__);
  1199. ctrl_pdata->bklt_ctrl = UNKNOWN_CTRL;
  1200. }
  1201. rc = of_property_read_u32_array(np,
  1202. "qcom,mdss-pan-bl-levels", res, 2);
  1203. pinfo->bl_min = (!rc ? res[0] : 0);
  1204. pinfo->bl_max = (!rc ? res[1] : 255);
  1205. ctrl_pdata->bklt_max = pinfo->bl_max;
  1206. rc = of_property_read_u32(np, "qcom,mdss-brightness-max-level", &tmp);
  1207. pinfo->brightness_max = (!rc ? tmp : MDSS_MAX_BL_BRIGHTNESS);
  1208. rc = of_property_read_u32(np, "qcom,mdss-pan-dsi-mode", &tmp);
  1209. pinfo->mipi.mode = (!rc ? tmp : DSI_VIDEO_MODE);
  1210. rc = of_property_read_u32(np, "qcom,mdss-vsync-enable", &tmp);
  1211. pinfo->mipi.vsync_enable = (!rc ? tmp : 0);
  1212. rc = of_property_read_u32(np, "qcom,mdss-hw-vsync-mode", &tmp);
  1213. pinfo->mipi.hw_vsync_mode = (!rc ? tmp : 0);
  1214. rc = of_property_read_u32(np,
  1215. "qcom,mdss-pan-dsi-h-pulse-mode", &tmp);
  1216. pinfo->mipi.pulse_mode_hsa_he = (!rc ? tmp : false);
  1217. rc = of_property_read_u32_array(np,
  1218. "qcom,mdss-pan-dsi-h-power-stop", res, 3);
  1219. pinfo->mipi.hbp_power_stop = (!rc ? res[0] : false);
  1220. pinfo->mipi.hsa_power_stop = (!rc ? res[1] : false);
  1221. pinfo->mipi.hfp_power_stop = (!rc ? res[2] : false);
  1222. rc = of_property_read_u32_array(np,
  1223. "qcom,mdss-pan-dsi-bllp-power-stop", res, 2);
  1224. pinfo->mipi.bllp_power_stop =
  1225. (!rc ? res[0] : false);
  1226. pinfo->mipi.eof_bllp_power_stop =
  1227. (!rc ? res[1] : false);
  1228. rc = of_property_read_u32(np, "qcom,mdss-pan-dsi-traffic-mode", &tmp);
  1229. pinfo->mipi.traffic_mode = (!rc ? tmp : DSI_NON_BURST_SYNCH_PULSE);
  1230. rc = of_property_read_u32(np, "qcom,mdss-pan-insert-dcs-cmd", &tmp);
  1231. pinfo->mipi.insert_dcs_cmd = (!rc ? tmp : 1);
  1232. rc = of_property_read_u32(np, "qcom,mdss-pan-wr-mem-continue", &tmp);
  1233. pinfo->mipi.wr_mem_continue = (!rc ? tmp : 0x3c);
  1234. rc = of_property_read_u32(np, "qcom,mdss-pan-wr-mem-start", &tmp);
  1235. pinfo->mipi.wr_mem_start = (!rc ? tmp : 0x2c);
  1236. rc = of_property_read_u32(np, "qcom,mdss-pan-te-sel", &tmp);
  1237. pinfo->mipi.te_sel = (!rc ? tmp : 1);
  1238. rc = of_property_read_u32(np, "qcom,mdss-pan-dsi-dst-format", &tmp);
  1239. pinfo->mipi.dst_format = (!rc ? tmp : DSI_VIDEO_DST_FORMAT_RGB888);
  1240. rc = of_property_read_u32(np, "qcom,mdss-pan-dsi-vc", &tmp);
  1241. pinfo->mipi.vc = (!rc ? tmp : 0);
  1242. rc = of_property_read_u32(np, "qcom,mdss-pan-dsi-rgb-swap", &tmp);
  1243. pinfo->mipi.rgb_swap = (!rc ? tmp : DSI_RGB_SWAP_RGB);
  1244. rc = of_property_read_u32(np, "qcom,mdss-force-clk-lane-hs", &tmp);
  1245. pinfo->mipi.force_clk_lane_hs = (!rc ? tmp : 0);
  1246. rc = of_property_read_u32(np, "samsung,mdss-early-lcd-on", &tmp);
  1247. pinfo->early_lcd_on = (!rc ? tmp : 0);
  1248. rc = of_property_read_u32_array(np,
  1249. "qcom,mdss-pan-dsi-data-lanes", res, 4);
  1250. pinfo->mipi.data_lane0 = (!rc ? res[0] : true);
  1251. pinfo->mipi.data_lane1 = (!rc ? res[1] : false);
  1252. pinfo->mipi.data_lane2 = (!rc ? res[2] : false);
  1253. pinfo->mipi.data_lane3 = (!rc ? res[3] : false);
  1254. rc = of_property_read_u32(np, "qcom,mdss-pan-dsi-dlane-swap", &tmp);
  1255. pinfo->mipi.dlane_swap = (!rc ? tmp : 0);
  1256. rc = of_property_read_u32_array(np, "qcom,mdss-pan-dsi-t-clk", res, 2);
  1257. pinfo->mipi.t_clk_pre = (!rc ? res[0] : 0x24);
  1258. pinfo->mipi.t_clk_post = (!rc ? res[1] : 0x03);
  1259. rc = of_property_read_u32(np, "qcom,mdss-pan-dsi-stream", &tmp);
  1260. pinfo->mipi.stream = (!rc ? tmp : 0);
  1261. rc = of_property_read_u32(np, "qcom,mdss-pan-dsi-tx-eot-append", &tmp);
  1262. pinfo->mipi.tx_eot_append = (!rc ? tmp : 0);
  1263. rc = of_property_read_u32(np, "qcom,mdss-pan-dsi-mdp-tr", &tmp);
  1264. pinfo->mipi.mdp_trigger =
  1265. (!rc ? tmp : DSI_CMD_TRIGGER_SW);
  1266. if (pinfo->mipi.mdp_trigger > 6) {
  1267. pr_err("%s:%d, Invalid mdp trigger. Forcing to sw trigger",
  1268. __func__, __LINE__);
  1269. pinfo->mipi.mdp_trigger = DSI_CMD_TRIGGER_SW;
  1270. }
  1271. rc = of_property_read_u32(np, "qcom,mdss-pan-dsi-dma-tr", &tmp);
  1272. pinfo->mipi.dma_trigger = (!rc ? tmp : DSI_CMD_TRIGGER_SW);
  1273. if (pinfo->mipi.dma_trigger > 6) {
  1274. pr_err("%s:%d, Invalid dma trigger. Forcing to sw trigger",
  1275. __func__, __LINE__);
  1276. pinfo->mipi.dma_trigger = DSI_CMD_TRIGGER_SW;
  1277. }
  1278. rc = of_property_read_u32(np, "qcom,mdss-pan-dsi-frame-rate", &tmp);
  1279. pinfo->mipi.frame_rate = (!rc ? tmp : 60);
  1280. rc = of_property_read_u32(np, "qcom,mdss-pan-clk-rate", &tmp);
  1281. pinfo->clk_rate = (!rc ? tmp : 0);
  1282. data = of_get_property(np, "qcom,panel-phy-regulatorSettings", &len);
  1283. if ((!data) || (len != 7)) {
  1284. pr_err("%s:%d, Unable to read Phy regulator settings",
  1285. __func__, __LINE__);
  1286. return -EINVAL;
  1287. }
  1288. for (i = 0; i < len; i++)
  1289. phy_params.regulator[i] = data[i];
  1290. data = of_get_property(np, "qcom,panel-phy-timingSettings", &len);
  1291. if ((!data) || (len != 12)) {
  1292. pr_err("%s:%d, Unable to read Phy timing settings",
  1293. __func__, __LINE__);
  1294. return -EINVAL;
  1295. }
  1296. for (i = 0; i < len; i++)
  1297. phy_params.timing[i] = data[i];
  1298. data = of_get_property(np, "qcom,panel-phy-strengthCtrl", &len);
  1299. if ((!data) || (len != 2)) {
  1300. pr_err("%s:%d, Unable to read Phy Strength ctrl settings",
  1301. __func__, __LINE__);
  1302. return -EINVAL;
  1303. }
  1304. phy_params.strength[0] = data[0];
  1305. phy_params.strength[1] = data[1];
  1306. data = of_get_property(np, "qcom,panel-phy-bistCtrl", &len);
  1307. if ((!data) || (len != 6)) {
  1308. pr_err("%s:%d, Unable to read Phy Bist Ctrl settings",
  1309. __func__, __LINE__);
  1310. return -EINVAL;
  1311. }
  1312. for (i = 0; i < len; i++)
  1313. phy_params.bistctrl[i] = data[i];
  1314. data = of_get_property(np, "qcom,panel-phy-laneConfig", &len);
  1315. if ((!data) || (len != 45)) {
  1316. pr_err("%s:%d, Unable to read Phy lane configure settings",
  1317. __func__, __LINE__);
  1318. return -EINVAL;
  1319. }
  1320. for (i = 0; i < len; i++)
  1321. phy_params.lanecfg[i] = data[i];
  1322. pinfo->mipi.dsi_phy_db = phy_params;
  1323. fbc_enabled = of_property_read_bool(np,
  1324. "qcom,fbc-enabled");
  1325. if (fbc_enabled) {
  1326. pr_debug("%s:%d FBC panel enabled.\n", __func__, __LINE__);
  1327. pinfo->fbc.enabled = 1;
  1328. rc = of_property_read_u32_array(np,
  1329. "qcom,fbc-mode", fbc_res, 7);
  1330. pinfo->fbc.target_bpp =
  1331. (!rc ? fbc_res[0] : pinfo->bpp);
  1332. pinfo->fbc.comp_mode = (!rc ? fbc_res[1] : 0);
  1333. pinfo->fbc.qerr_enable =
  1334. (!rc ? fbc_res[2] : 0);
  1335. pinfo->fbc.cd_bias = (!rc ? fbc_res[3] : 0);
  1336. pinfo->fbc.pat_enable = (!rc ? fbc_res[4] : 0);
  1337. pinfo->fbc.vlc_enable = (!rc ? fbc_res[5] : 0);
  1338. pinfo->fbc.bflc_enable =
  1339. (!rc ? fbc_res[6] : 0);
  1340. rc = of_property_read_u32_array(np,
  1341. "qcom,fbc-budget-ctl", fbc_res, 3);
  1342. pinfo->fbc.line_x_budget =
  1343. (!rc ? fbc_res[0] : 0);
  1344. pinfo->fbc.block_x_budget =
  1345. (!rc ? fbc_res[1] : 0);
  1346. pinfo->fbc.block_budget =
  1347. (!rc ? fbc_res[2] : 0);
  1348. rc = of_property_read_u32_array(np,
  1349. "qcom,fbc-lossy-mode", fbc_res, 4);
  1350. pinfo->fbc.lossless_mode_thd =
  1351. (!rc ? fbc_res[0] : 0);
  1352. pinfo->fbc.lossy_mode_thd =
  1353. (!rc ? fbc_res[1] : 0);
  1354. pinfo->fbc.lossy_rgb_thd =
  1355. (!rc ? fbc_res[2] : 0);
  1356. pinfo->fbc.lossy_mode_idx =
  1357. (!rc ? fbc_res[3] : 0);
  1358. } else {
  1359. pr_debug("%s:%d Panel does not support FBC.\n",
  1360. __func__, __LINE__);
  1361. pinfo->fbc.enabled = 0;
  1362. pinfo->fbc.target_bpp =
  1363. pinfo->bpp;
  1364. }
  1365. mdss_dsi_parse_dcs_cmds(np, &ctrl_pdata->on_cmds,
  1366. "qcom,panel-on-cmds", "qcom,on-cmds-dsi-state");
  1367. mdss_dsi_parse_dcs_cmds(np, &ctrl_pdata->off_cmds,
  1368. "qcom,panel-off-cmds", "qcom,off-cmds-dsi-state");
  1369. mdss_samsung_parse_panel_cmd(np, &display_qcom_on_cmds,
  1370. "qcom,panel-on-cmds");
  1371. mdss_samsung_parse_panel_cmd(np, &display_qcom_off_cmds,
  1372. "qcom,panel-off-cmds");
  1373. mdss_samsung_parse_panel_cmd(np, &late_on_cmds,
  1374. "samsung,panel-late-on-cmds");
  1375. mdss_samsung_parse_panel_cmd(np, &early_off_cmds,
  1376. "samsung,panel-early-off-cmds");
  1377. mdss_samsung_parse_panel_cmd(np, &brightness_cmds,
  1378. "samsung,panel-brightness-cmds");
  1379. mdss_samsung_parse_panel_cmd(np, &mtp_enable_cmds,
  1380. "samsung,panel-mtp-enable-cmds");
  1381. mdss_samsung_parse_panel_cmd(np, &mtp_disable_cmds,
  1382. "samsung,panel-mtp-disable-cmds");
  1383. mdss_samsung_parse_panel_cmd(np, &cabc_on_cmds,
  1384. "samsung,panel-cabc-on-cmds");
  1385. mdss_samsung_parse_panel_cmd(np, &cabc_off_cmds,
  1386. "samsung,panel-cabc-off-cmds");
  1387. mdss_samsung_parse_panel_cmd(np, &hsync_on_cmds,
  1388. "samsung,panel-hsync-on-cmds");
  1389. mdss_samsung_parse_panel_cmd(np, &hsync_off_cmds,
  1390. "samsung,panel-hsync-off-cmds");
  1391. mdss_samsung_parse_panel_cmd(np, &manufacture_id_cmds,
  1392. "samsung,panel-manufacture-id-read-cmds");
  1393. mdss_samsung_parse_panel_cmd(np, &display_on_cmd,
  1394. "qcom,panel-on-cmds");
  1395. mdss_samsung_parse_panel_cmd(np, &display_off_cmd,
  1396. "qcom,panel-off-cmds");
  1397. mdss_samsung_parse_panel_cmd(np, &display_unblank_cmd,
  1398. "qcom,panel-display-unblank-cmds");
  1399. mdss_samsung_parse_panel_cmd(np, &display_blank_cmd,
  1400. "qcom,panel-display-blank-cmds");
  1401. /* Process the lux value table */
  1402. mdss_samsung_parse_candela_lux_mapping_table(np, &candela_map_table,
  1403. "samsung,panel-candela-mapping-table");
  1404. /* Process touch sensing */
  1405. mdss_samsung_parse_panel_cmd(np, &touchsensing_on_cmd,
  1406. "qcom,panel-touchsensing-on-cmds");
  1407. mdss_samsung_parse_panel_cmd(np, &touchsensing_off_cmd,
  1408. "qcom,panel-touchsensing-off-cmds");
  1409. return 0;
  1410. }
  1411. #if defined(CONFIG_HAS_EARLYSUSPEND)
  1412. static void mipi_samsung_disp_early_suspend(struct early_suspend *h)
  1413. {
  1414. msd.mfd->resume_state = MIPI_SUSPEND_STATE;
  1415. LCD_DEBUG("------");
  1416. }
  1417. static void mipi_samsung_disp_late_resume(struct early_suspend *h)
  1418. {
  1419. msd.mfd->resume_state = MIPI_RESUME_STATE;
  1420. LCD_DEBUG("------");
  1421. }
  1422. #endif
  1423. static int is_panel_supported(const char *panel_name)
  1424. {
  1425. int i = 0;
  1426. if (panel_name == NULL)
  1427. return -EINVAL;
  1428. if(!of_machine_is_compatible("qcom,msm8974-cdp"))
  1429. return -EINVAL;
  1430. while(panel_supp_cdp[i].name != NULL) {
  1431. if(!strcmp(panel_name,panel_supp_cdp[i].name))
  1432. break;
  1433. i++;
  1434. }
  1435. if( i < ARRAY_SIZE(panel_supp_cdp)) {
  1436. memcpy(msd.panel_name, panel_name, MAX_PANEL_NAME_SIZE);
  1437. msd.panel = panel_supp_cdp[i].panel_code;
  1438. return 0;
  1439. }
  1440. return -EINVAL;
  1441. }
  1442. #ifdef DDI_VIDEO_ENHANCE_TUNING
  1443. #define MAX_FILE_NAME 128
  1444. #define TUNING_FILE_PATH "/sdcard/"
  1445. #define TUNE_FIRST_SIZE 5
  1446. #define TUNE_SECOND_SIZE 108
  1447. static char tuning_file[MAX_FILE_NAME];
  1448. static char mdni_tuning1[TUNE_FIRST_SIZE];
  1449. static char mdni_tuning2[TUNE_SECOND_SIZE];
  1450. static struct dsi_cmd_desc mdni_tune_cmd[] = {
  1451. {{DTYPE_DCS_LWRITE, 1, 0, 0, 0,
  1452. sizeof(mdni_tuning2)}, mdni_tuning2},
  1453. {{DTYPE_DCS_LWRITE, 1, 0, 0, 0,
  1454. sizeof(mdni_tuning1)}, mdni_tuning1},
  1455. };
  1456. static char char_to_dec(char data1, char data2)
  1457. {
  1458. char dec;
  1459. dec = 0;
  1460. if (data1 >= 'a') {
  1461. data1 -= 'a';
  1462. data1 += 10;
  1463. } else if (data1 >= 'A') {
  1464. data1 -= 'A';
  1465. data1 += 10;
  1466. } else
  1467. data1 -= '0';
  1468. dec = data1 << 4;
  1469. if (data2 >= 'a') {
  1470. data2 -= 'a';
  1471. data2 += 10;
  1472. } else if (data2 >= 'A') {
  1473. data2 -= 'A';
  1474. data2 += 10;
  1475. } else
  1476. data2 -= '0';
  1477. dec |= data2;
  1478. return dec;
  1479. }
  1480. static void sending_tune_cmd(char *src, int len)
  1481. {
  1482. int data_pos;
  1483. int cmd_step;
  1484. int cmd_pos;
  1485. cmd_step = 0;
  1486. cmd_pos = 0;
  1487. for (data_pos = 0; data_pos < len;) {
  1488. if (*(src + data_pos) == '0') {
  1489. if (*(src + data_pos + 1) == 'x') {
  1490. if (!cmd_step) {
  1491. mdni_tuning1[cmd_pos] =
  1492. char_to_dec(*(src + data_pos + 2),
  1493. *(src + data_pos + 3));
  1494. } else {
  1495. mdni_tuning2[cmd_pos] =
  1496. char_to_dec(*(src + data_pos + 2),
  1497. *(src + data_pos + 3));
  1498. }
  1499. data_pos += 3;
  1500. cmd_pos++;
  1501. if (cmd_pos == TUNE_FIRST_SIZE && !cmd_step) {
  1502. cmd_pos = 0;
  1503. cmd_step = 1;
  1504. }
  1505. } else
  1506. data_pos++;
  1507. } else {
  1508. data_pos++;
  1509. }
  1510. }
  1511. printk(KERN_INFO "\n");
  1512. for (data_pos = 0; data_pos < TUNE_FIRST_SIZE ; data_pos++)
  1513. printk(KERN_INFO "0x%x ", mdni_tuning1[data_pos]);
  1514. printk(KERN_INFO "\n");
  1515. for (data_pos = 0; data_pos < TUNE_SECOND_SIZE ; data_pos++)
  1516. printk(KERN_INFO"0x%x ", mdni_tuning2[data_pos]);
  1517. printk(KERN_INFO "\n");
  1518. mutex_lock(&msd.lock);
  1519. mdss_dsi_cmds_send(msd.ctrl_pdata, mdni_tune_cmd, ARRAY_SIZE(mdni_tune_cmd), 0);
  1520. mutex_unlock(&msd.lock);
  1521. }
  1522. static void load_tuning_file(char *filename)
  1523. {
  1524. struct file *filp;
  1525. char *dp;
  1526. long l;
  1527. loff_t pos;
  1528. int ret;
  1529. mm_segment_t fs;
  1530. pr_info("%s called loading file name : [%s]\n", __func__,
  1531. filename);
  1532. fs = get_fs();
  1533. set_fs(get_ds());
  1534. filp = filp_open(filename, O_RDONLY, 0);
  1535. if (IS_ERR(filp)) {
  1536. printk(KERN_ERR "%s File open failed\n", __func__);
  1537. goto err;
  1538. }
  1539. l = filp->f_path.dentry->d_inode->i_size;
  1540. pr_info("%s Loading File Size : %ld(bytes)", __func__, l);
  1541. dp = kmalloc(l + 10, GFP_KERNEL);
  1542. if (dp == NULL) {
  1543. pr_info("Can't not alloc memory for tuning file load\n");
  1544. filp_close(filp, current->files);
  1545. goto err;
  1546. }
  1547. pos = 0;
  1548. memset(dp, 0, l);
  1549. pr_info("%s before vfs_read()\n", __func__);
  1550. ret = vfs_read(filp, (char __user *)dp, l, &pos);
  1551. pr_info("%s after vfs_read()\n", __func__);
  1552. if (ret != l) {
  1553. pr_info("vfs_read() filed ret : %d\n", ret);
  1554. kfree(dp);
  1555. filp_close(filp, current->files);
  1556. goto err;
  1557. }
  1558. filp_close(filp, current->files);
  1559. set_fs(fs);
  1560. sending_tune_cmd(dp, l);
  1561. kfree(dp);
  1562. return;
  1563. err:
  1564. set_fs(fs);
  1565. }
  1566. static ssize_t tuning_show(struct device *dev,
  1567. struct device_attribute *attr, char *buf)
  1568. {
  1569. int ret = 0;
  1570. ret = snprintf(buf, MAX_FILE_NAME, "Tunned File Name : %s\n",
  1571. tuning_file);
  1572. return ret;
  1573. }
  1574. static ssize_t tuning_store(struct device *dev,
  1575. struct device_attribute *attr, const char *buf,
  1576. size_t size)
  1577. {
  1578. char *pt;
  1579. memset(tuning_file, 0, sizeof(tuning_file));
  1580. snprintf(tuning_file, MAX_FILE_NAME, "%s%s", TUNING_FILE_PATH, buf);
  1581. pt = tuning_file;
  1582. while (*pt) {
  1583. if (*pt == '\r' || *pt == '\n') {
  1584. *pt = 0;
  1585. break;
  1586. }
  1587. pt++;
  1588. }
  1589. pr_info("%s:%s\n", __func__, tuning_file);
  1590. load_tuning_file(tuning_file);
  1591. return size;
  1592. }
  1593. static DEVICE_ATTR(tuning, 0664, tuning_show, tuning_store);
  1594. #endif
  1595. static int samsung_dsi_panel_event_handler(int event)
  1596. {
  1597. pr_debug("SS DSI Event Handler");
  1598. switch (event) {
  1599. case MDSS_EVENT_FRAME_UPDATE:
  1600. if(msd.dstat.wait_disp_on) {
  1601. mipi_samsung_disp_send_cmd(PANEL_DISPLAY_ON, true);
  1602. #if defined(AUTO_BRIGHTNESS_CABC_FUNCTION)
  1603. if( (msd.dstat.auto_brightness >= 1) && (msd.dstat.auto_brightness <= 4) )
  1604. mipi_samsung_cabc_onoff (1);
  1605. else
  1606. mipi_samsung_cabc_onoff (0);
  1607. #endif
  1608. #if defined(CONFIG_MDNIE_LITE_TUNING)
  1609. is_negative_on();
  1610. #endif
  1611. msd.dstat.wait_disp_on = 0;
  1612. }
  1613. break;
  1614. }
  1615. return 0;
  1616. }
  1617. static int mdss_dsi_panel_blank(struct mdss_panel_data *pdata, int blank)
  1618. {
  1619. if(blank) {
  1620. pr_debug("%s:%d, blanking panel\n", __func__, __LINE__);
  1621. mipi_samsung_disp_send_cmd(PANEL_DISPLAY_BLANK, false);
  1622. }
  1623. else {
  1624. pr_debug("%s:%d, unblanking panel\n", __func__, __LINE__);
  1625. mipi_samsung_disp_send_cmd(PANEL_DISPLAY_UNBLANK, false);
  1626. }
  1627. return 0;
  1628. }
  1629. #if defined(CONFIG_LCD_CLASS_DEVICE)
  1630. static struct attribute *panel_sysfs_attributes[] = {
  1631. &dev_attr_lcd_power.attr,
  1632. &dev_attr_lcd_type.attr,
  1633. &dev_attr_window_type.attr,
  1634. &dev_attr_power_reduce.attr,
  1635. &dev_attr_siop_enable.attr,
  1636. NULL
  1637. };
  1638. static const struct attribute_group panel_sysfs_group = {
  1639. .attrs = panel_sysfs_attributes,
  1640. };
  1641. #if defined(CONFIG_BACKLIGHT_CLASS_DEVICE)
  1642. static struct attribute *bl_sysfs_attributes[] = {
  1643. &dev_attr_auto_brightness.attr,
  1644. &dev_attr_backlight.attr,
  1645. &dev_attr_pwm_backlight.attr,
  1646. NULL
  1647. };
  1648. static const struct attribute_group bl_sysfs_group = {
  1649. .attrs = bl_sysfs_attributes,
  1650. };
  1651. #endif
  1652. #endif
  1653. int mdss_dsi_panel_init(struct device_node *node, struct mdss_dsi_ctrl_pdata *ctrl_pdata,
  1654. bool cmd_cfg_conf_splash)
  1655. {
  1656. int rc = 0;
  1657. static const char *panel_name;
  1658. bool cont_splash_enabled = false;
  1659. #if defined(CONFIG_LCD_CLASS_DEVICE)
  1660. struct lcd_device *lcd_device;
  1661. #endif
  1662. #if defined(CONFIG_BACKLIGHT_CLASS_DEVICE)
  1663. struct backlight_device *bd = NULL;
  1664. #endif
  1665. pr_debug("%s:%d", __func__, __LINE__);
  1666. if (!node)
  1667. return -ENODEV;
  1668. panel_name = of_get_property(node, "label", NULL);
  1669. if (!panel_name)
  1670. pr_info("%s:%d, panel name not specified\n",
  1671. __func__, __LINE__);
  1672. else
  1673. pr_info("%s: Panel Name = %s\n", __func__, panel_name);
  1674. if(is_panel_supported(panel_name)) {
  1675. LCD_DEBUG("Panel : %s is not supported:",panel_name);
  1676. return -1;
  1677. }
  1678. rc = mdss_panel_parse_dt(node, ctrl_pdata);
  1679. if (rc)
  1680. return rc;
  1681. ctrl_pdata->on = mdss_dsi_panel_on;
  1682. ctrl_pdata->off = mdss_dsi_panel_off;
  1683. ctrl_pdata->bl_fnc = mdss_dsi_panel_bl_ctrl;
  1684. ctrl_pdata->panel_reset = mdss_dsi_samsung_panel_reset;
  1685. ctrl_pdata->registered = mdss_dsi_panel_registered;
  1686. ctrl_pdata->dimming_init = NULL;
  1687. ctrl_pdata->event_handler = samsung_dsi_panel_event_handler;
  1688. ctrl_pdata->panel_blank = mdss_dsi_panel_blank;
  1689. ctrl_pdata->panel_data.set_backlight = mdss_dsi_panel_bl_ctrl;
  1690. /* Init driver specific data */
  1691. mutex_init(&msd.lock);
  1692. msd.dstat.on = 0;
  1693. cont_splash_enabled = of_property_read_bool(node,
  1694. "qcom,cont-splash-enabled");
  1695. if (!cont_splash_enabled) {
  1696. pr_info("%s:%d Continuous splash flag not found.\n",
  1697. __func__, __LINE__);
  1698. ctrl_pdata->panel_data.panel_info.cont_splash_enabled = 0;
  1699. } else {
  1700. pr_info("%s:%d Continuous splash flag enabled.\n",
  1701. __func__, __LINE__);
  1702. ctrl_pdata->panel_data.panel_info.cont_splash_enabled = 1;
  1703. }
  1704. #if defined(CONFIG_LCD_CLASS_DEVICE)
  1705. lcd_device = lcd_device_register("panel", NULL, NULL,
  1706. &mipi_samsung_disp_props);
  1707. if (IS_ERR(lcd_device)) {
  1708. rc = PTR_ERR(lcd_device);
  1709. printk(KERN_ERR "lcd : failed to register device\n");
  1710. return rc;
  1711. }
  1712. sysfs_remove_file(&lcd_device->dev.kobj,
  1713. &dev_attr_lcd_power.attr);
  1714. rc = sysfs_create_group(&lcd_device->dev.kobj, &panel_sysfs_group);
  1715. if (rc) {
  1716. pr_err("Failed to create panel sysfs group..\n");
  1717. sysfs_remove_group(&lcd_device->dev.kobj, &panel_sysfs_group);
  1718. }
  1719. #if defined(CONFIG_BACKLIGHT_CLASS_DEVICE)
  1720. bd = backlight_device_register("panel", &lcd_device->dev,
  1721. NULL, NULL, NULL);
  1722. if (IS_ERR(bd)) {
  1723. rc = PTR_ERR(bd);
  1724. pr_info("backlight : failed to register device\n");
  1725. return rc;
  1726. }
  1727. rc = sysfs_create_group(&bd->dev.kobj, &bl_sysfs_group);
  1728. if (rc) {
  1729. pr_err("Failed to create backlight sysfs group..\n");
  1730. sysfs_remove_group(&bd->dev.kobj, &bl_sysfs_group);
  1731. }
  1732. #endif
  1733. #endif
  1734. #if defined(CONFIG_MDNIE_LITE_TUNING)
  1735. pr_info("[%s] CONFIG_MDNIE_LITE_TUNING ok ! init class called!\n",
  1736. __func__);
  1737. init_mdnie_class();
  1738. #endif
  1739. #if defined(DDI_VIDEO_ENHANCE_TUNING)
  1740. rc = sysfs_create_file(&lcd_device->dev.kobj,
  1741. &dev_attr_tuning.attr);
  1742. if (rc) {
  1743. pr_info("sysfs create fail-%s\n",
  1744. dev_attr_tuning.attr.name);
  1745. }
  1746. #endif
  1747. #if defined(CONFIG_HAS_EARLYSUSPEND)
  1748. msd.early_suspend.suspend = mipi_samsung_disp_early_suspend;
  1749. msd.early_suspend.resume = mipi_samsung_disp_late_resume;
  1750. msd.early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN-1;
  1751. register_early_suspend(&msd.early_suspend);
  1752. #endif
  1753. /*
  1754. * unless panel is powered on don't set the state to true
  1755. * This is to handle cases like cont splash or lpm in which panel
  1756. * will be powered on later on.
  1757. */
  1758. msd.dstat.on = 0;
  1759. msd.dstat.bright_level = RECOVERY_BRIGHTNESS;
  1760. return 0;
  1761. }
  1762. int get_samsung_lcd_attached(void)
  1763. {
  1764. return lcd_attached;
  1765. }
  1766. EXPORT_SYMBOL(get_samsung_lcd_attached);
  1767. static int __init get_lcd_id_cmdline(char *mode)
  1768. {
  1769. char *pt;
  1770. lcd_id = 0;
  1771. if( mode == NULL ) return 1;
  1772. for( pt = mode; *pt != 0; pt++ )
  1773. {
  1774. lcd_id <<= 4;
  1775. switch(*pt)
  1776. {
  1777. case '0' ... '9' :
  1778. lcd_id += *pt -'0';
  1779. break;
  1780. case 'a' ... 'f' :
  1781. lcd_id += 10 + *pt -'a';
  1782. break;
  1783. case 'A' ... 'F' :
  1784. lcd_id += 10 + *pt -'A';
  1785. break;
  1786. }
  1787. }
  1788. lcd_attached = ((lcd_id&0xFFFFFF)!=0x000000);
  1789. pr_info( "%s: LCD_ID = 0x%X, lcd_attached =%d", __func__,lcd_id, lcd_attached);
  1790. return 0;
  1791. }
  1792. __setup( "lcd_id=0x", get_lcd_id_cmdline );
  1793. static int __init mdss_panel_current_hw_rev(char *rev)
  1794. {
  1795. /*
  1796. * 1 is recovery booting
  1797. * 0 is normal booting
  1798. */
  1799. board_rev = atoi(rev);
  1800. pr_info("%s : %d", __func__, board_rev);
  1801. return 1;
  1802. }
  1803. __setup("samsung.board_rev=", mdss_panel_current_hw_rev);
  1804. MODULE_DESCRIPTION("Samsung DSI panel driver");
  1805. MODULE_AUTHOR("Krishna Kishor Jha <krishna.jha@samsung.com>");
  1806. MODULE_LICENSE("GPL");