mtk_fbconfig_kdebug.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. /*
  2. * Copyright (C) 2015 MediaTek Inc.
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <linux/string.h>
  14. #include <linux/time.h>
  15. #include <linux/uaccess.h>
  16. #include <linux/fb.h>
  17. #include <linux/vmalloc.h>
  18. #include <linux/sched.h>
  19. #include <linux/debugfs.h>
  20. #include <linux/wait.h>
  21. #include <linux/types.h>
  22. #include "mtk_fbconfig_kdebug.h"
  23. #include "mtk_mipi_tx.h"
  24. #include "mtk_drm_crtc.h"
  25. #include "mtk_panel_ext.h"
  26. #include "mtk_drm_drv.h"
  27. #include "mtk_drm_ddp_comp.h"
  28. /* ************************************************************************* */
  29. /* This part is for customization parameters of D-IC and DSI . */
  30. /* ************************************************************************* */
  31. #define FBCONFIG_KEEP_NEW_SETTING 1
  32. #define FBCONFIG_DEBUG 0
  33. #define FBCONFIG_IOW(num, dtype) _IOW('X', num, dtype)
  34. #define FBCONFIG_IOR(num, dtype) _IOR('X', num, dtype)
  35. #define FBCONFIG_IOWR(num, dtype) _IOWR('X', num, dtype)
  36. #define FBCONFIG_IO(num) _IO('X', num)
  37. #define GET_DSI_ID FBCONFIG_IOW(43, unsigned int)
  38. #define SET_DSI_ID FBCONFIG_IOW(44, unsigned int)
  39. #define LCM_GET_ID FBCONFIG_IOR(45, unsigned int)
  40. #define LCM_GET_ESD FBCONFIG_IOWR(46, unsigned int)
  41. #define DRIVER_IC_CONFIG FBCONFIG_IOR(47, unsigned int)
  42. #define DRIVER_IC_CONFIG_DONE FBCONFIG_IO(0)
  43. #define DRIVER_IC_RESET FBCONFIG_IOR(48, unsigned int)
  44. #define MIPI_SET_CLK FBCONFIG_IOW(51, unsigned int)
  45. #define MIPI_SET_LANE FBCONFIG_IOW(52, unsigned int)
  46. #define MIPI_SET_TIMING FBCONFIG_IOW(53, unsigned int)
  47. /* mipi video mode timing setting */
  48. #define MIPI_SET_VM FBCONFIG_IOW(54, unsigned int)
  49. /* mipi non-continuous clock */
  50. #define MIPI_SET_CC FBCONFIG_IOW(55, unsigned int)
  51. /* spread frequency */
  52. #define MIPI_SET_SSC FBCONFIG_IOW(56, unsigned int)
  53. /* For div1,div2,fbk_div case */
  54. #define MIPI_SET_CLK_V2 FBCONFIG_IOW(57, unsigned int)
  55. #define TE_SET_ENABLE FBCONFIG_IOW(61, unsigned int)
  56. #define FB_LAYER_DUMP FBCONFIG_IOW(62, unsigned int)
  57. #define FB_LAYER_GET_INFO FBCONFIG_IOW(63, unsigned int)
  58. #define FB_LAYER_GET_EN FBCONFIG_IOW(64, unsigned int)
  59. #define LCM_GET_ESD_RET FBCONFIG_IOR(65, unsigned int)
  60. #define LCM_GET_DSI_CONTINU FBCONFIG_IOR(71, unsigned int)
  61. #define LCM_GET_DSI_CLK FBCONFIG_IOR(72, unsigned int)
  62. #define LCM_GET_DSI_TIMING FBCONFIG_IOR(73, unsigned int)
  63. #define LCM_GET_DSI_LANE_NUM FBCONFIG_IOR(74, unsigned int)
  64. #define LCM_GET_DSI_TE FBCONFIG_IOR(75, unsigned int)
  65. #define LCM_GET_DSI_SSC FBCONFIG_IOR(76, unsigned int)
  66. #define LCM_GET_DSI_CLK_V2 FBCONFIG_IOR(77, unsigned int)
  67. #define LCM_TEST_DSI_CLK FBCONFIG_IOR(78, unsigned int)
  68. #define FB_GET_MISC FBCONFIG_IOR(80, unsigned int)
  69. #ifdef UFMT_GET_bpp
  70. #define DP_COLOR_BITS_PER_PIXEL(color) UFMT_GET_bpp(color)
  71. #else
  72. #define DP_COLOR_BITS_PER_PIXEL(color) ((0x0003FF00 & color) >> 8)
  73. #endif
  74. struct dentry *ConfigPara_dbgfs;
  75. struct CONFIG_RECORD_LIST head_list;
  76. struct LCM_REG_READ reg_read;
  77. struct drm_device *drm_dev;
  78. struct drm_crtc *crtc;
  79. struct mtk_drm_crtc *mtk_crtc;
  80. struct mtk_ddp_comp *output_comp;
  81. struct PM_TOOL_S {
  82. enum DSI_INDEX dsi_id;
  83. struct LCM_REG_READ reg_read;
  84. struct mtk_panel_params *pMtk_panel_params;
  85. };
  86. static struct PM_TOOL_S pm_params = {
  87. .dsi_id = PM_DSI0,
  88. .pMtk_panel_params = NULL,
  89. };
  90. static void *pm_get_handle(void)
  91. {
  92. return (void *)&pm_params;
  93. }
  94. static int fbconfig_open(struct inode *inode, struct file *file)
  95. {
  96. struct PM_TOOL_S *pm_params = NULL;
  97. file->private_data = inode->i_private;
  98. pm_params = (struct PM_TOOL_S *) pm_get_handle();
  99. if (pm_params == NULL)
  100. return -EFAULT;
  101. crtc = list_first_entry(&(drm_dev)->mode_config.crtc_list,
  102. typeof(*crtc), head);
  103. if (!crtc) {
  104. DDPPR_ERR("find crtc fail\n");
  105. return -EFAULT;
  106. }
  107. mtk_crtc = to_mtk_crtc(crtc);
  108. if (!(crtc->enabled) || mtk_crtc->ddp_mode == DDP_NO_USE)
  109. return -EFAULT;
  110. output_comp = mtk_ddp_comp_request_output(mtk_crtc);
  111. if (!output_comp)
  112. return -EFAULT;
  113. pm_params->pMtk_panel_params = mtk_drm_get_lcm_ext_params(crtc);
  114. switch (output_comp->id) {
  115. case DDP_COMPONENT_DSI0:
  116. {
  117. pm_params->dsi_id = PM_DSI0;
  118. break;
  119. }
  120. case DDP_COMPONENT_DSI1:
  121. {
  122. pm_params->dsi_id = PM_DSI1;
  123. break;
  124. }
  125. default:
  126. break;
  127. }
  128. return 0;
  129. }
  130. static char fbconfig_buffer[2048];
  131. static ssize_t fbconfig_read(struct file *file, char __user *ubuf,
  132. size_t count, loff_t *ppos)
  133. {
  134. const int debug_bufmax = sizeof(fbconfig_buffer) - 1; /* 2047 */
  135. int n = 0;
  136. n += scnprintf(fbconfig_buffer + n, debug_bufmax - n, "sxkhome");
  137. fbconfig_buffer[n++] = 0;
  138. /* n = 5 ; */
  139. /* memcpy(fbconfig_buffer,"sxkhome",6); */
  140. return simple_read_from_buffer(ubuf, count, ppos, fbconfig_buffer, n);
  141. }
  142. static ssize_t fbconfig_write(struct file *file,
  143. const char __user *ubuf, size_t count, loff_t *ppos)
  144. {
  145. return 0;
  146. }
  147. static long fbconfig_ioctl(struct file *file, unsigned int cmd,
  148. unsigned long arg)
  149. {
  150. int ret = 0;
  151. void __user *argp = (void __user *)arg;
  152. struct PM_TOOL_S *pm = (struct PM_TOOL_S *) pm_get_handle();
  153. uint32_t dsi_id = pm->dsi_id;
  154. if (!(crtc->state->active))
  155. return -EFAULT;
  156. #ifdef FBCONFIG_SHOULD_KICK_IDLEMGR
  157. mtk_drm_idlemgr_kick(__func__, crtc, 1);
  158. #endif
  159. switch (cmd) {
  160. case GET_DSI_ID:
  161. {
  162. put_user(dsi_id, (unsigned long *)argp);
  163. return 0;
  164. }
  165. case SET_DSI_ID:
  166. {
  167. if (arg > PM_DSI1)
  168. return -EINVAL;
  169. pm->dsi_id = arg;
  170. pr_debug("fbconfig=>SET_DSI_ID:%d\n", dsi_id);
  171. return 0;
  172. }
  173. case LCM_TEST_DSI_CLK:
  174. {
  175. struct LCM_TYPE_FB lcm_fb;
  176. lcm_fb.clock = pm->pMtk_panel_params->pll_clk;
  177. lcm_fb.lcm_type = fbconfig_mtk_dsi_get_mode_type(output_comp);
  178. pr_debug("fbconfig=>LCM_TEST_DSI_CLK:%d\n", ret);
  179. return copy_to_user(argp, &lcm_fb,
  180. sizeof(lcm_fb)) ? -EFAULT : 0;
  181. }
  182. case LCM_GET_ID:
  183. {
  184. /* not support anymore */
  185. return 0;
  186. }
  187. case DRIVER_IC_CONFIG:
  188. {
  189. /* not support anymore */
  190. return 0;
  191. }
  192. case DRIVER_IC_CONFIG_DONE:
  193. {
  194. /* not support anymore */
  195. return 0;
  196. }
  197. case MIPI_SET_CC:
  198. {
  199. uint32_t enable = 0;
  200. if (get_user(enable, (uint32_t __user *) argp)) {
  201. pr_debug("[MIPI_SET_CC]: copy_from_user failed! line:%d\n",
  202. __LINE__);
  203. return -EFAULT;
  204. }
  205. if (enable > 1)
  206. return -EFAULT;
  207. Panel_Master_mipi_set_cc_entry(crtc, enable);
  208. return 0;
  209. }
  210. case LCM_GET_DSI_CONTINU:
  211. {
  212. uint32_t ret = Panel_Master_mipi_get_cc_entry(crtc);
  213. /*need to improve ,0 now means nothing but one parameter. */
  214. pr_debug("LCM_GET_DSI_CONTINU=>DSI: %d\n", ret);
  215. return put_user(ret, (unsigned long *)argp);
  216. }
  217. case MIPI_SET_CLK:
  218. {
  219. uint32_t clk = 0;
  220. if (get_user(clk, (uint32_t __user *) argp)) {
  221. pr_debug("[MIPI_SET_CLK]: copy_from_user failed! line:%d\n",
  222. __LINE__);
  223. return -EFAULT;
  224. }
  225. pr_debug("LCM_GET_DSI_CLK=>dsi:%d\n", clk);
  226. Panel_Master_dsi_config_entry(crtc, "PM_CLK", clk);
  227. return 0;
  228. }
  229. case LCM_GET_DSI_CLK:
  230. {
  231. uint32_t clk = pm->pMtk_panel_params->pll_clk;
  232. pr_debug("LCM_GET_DSI_CLK=>dsi:%d\n", clk);
  233. return put_user(clk, (unsigned long *)argp);
  234. }
  235. case MIPI_SET_SSC:
  236. {
  237. struct DSI_RET dsi_ssc;
  238. if (copy_from_user(&dsi_ssc, (void __user *)argp,
  239. sizeof(dsi_ssc))) {
  240. pr_debug("[MIPI_SET_SSC]: copy_from_user failed! line:%d\n",
  241. __LINE__);
  242. return -EFAULT;
  243. }
  244. pr_debug("Pmaster:set mipi ssc line:%d\n", __LINE__);
  245. /* not support ssc in drm */
  246. /* Panel_Master_dsi_config_entry(crtc, "PM_SSC", dsi_ssc); */
  247. return 0;
  248. }
  249. case LCM_GET_DSI_SSC:
  250. {
  251. /* but drm framework not support ssc anymore */
  252. uint32_t ssc = pm->pMtk_panel_params->ssc_range;
  253. if (pm->pMtk_panel_params->ssc_disable)
  254. ssc = 0;
  255. return put_user(ssc, (unsigned long *)argp);
  256. }
  257. case LCM_GET_DSI_LANE_NUM:
  258. {
  259. uint32_t lanes_num;
  260. lanes_num = fbconfig_mtk_dsi_get_lanes_num(output_comp);
  261. pr_debug("Panel Master=>LCM_GET_DSI_Lane_num=>dsi:%d\r\n",
  262. lanes_num);
  263. return put_user(lanes_num, (unsigned long *)argp);
  264. }
  265. case LCM_GET_DSI_TE:
  266. {
  267. /* not support anymore */
  268. return 0;
  269. }
  270. case LCM_GET_DSI_TIMING:
  271. {
  272. uint32_t ret;
  273. struct MIPI_TIMING timing;
  274. if (copy_from_user(&timing, (void __user *)argp,
  275. sizeof(timing))) {
  276. pr_debug("[MIPI_GET_TIMING]: copy_from_user failed! line:%d\n",
  277. __LINE__);
  278. return -EFAULT;
  279. }
  280. ret = Panel_Master_lcm_get_dsi_timing_entry(crtc, timing.type);
  281. pr_debug("fbconfig=>LCM_GET_DSI_TIMING:%d\n", ret);
  282. timing.value = ret;
  283. return copy_to_user(argp,
  284. &timing, sizeof(timing)) ? -EFAULT : 0;
  285. }
  286. case MIPI_SET_TIMING:
  287. {
  288. struct MIPI_TIMING timing;
  289. int ret = 0;
  290. if (!(crtc->state->active))
  291. return -EFAULT;
  292. if (copy_from_user(&timing, (void __user *)argp,
  293. sizeof(timing))) {
  294. pr_debug("[MIPI_SET_TIMING]: copy_from_user failed! line:%d\n",
  295. __LINE__);
  296. return -EFAULT;
  297. }
  298. ret = Panel_Master_mipi_set_timing_entry(crtc, timing);
  299. return ret;
  300. }
  301. case FB_LAYER_GET_EN:
  302. {
  303. pr_debug("[FB_LAYER_GET_EN] not support any more\n");
  304. return 0;
  305. }
  306. case FB_LAYER_GET_INFO:
  307. {
  308. pr_debug("[FB_LAYER_GET_INFO] not support any more\n");
  309. return 0;
  310. }
  311. case FB_LAYER_DUMP:
  312. {
  313. pr_debug("[FB_LAYER_DUMP] not support any more\n");
  314. return 0;
  315. }
  316. case LCM_GET_ESD:
  317. {
  318. struct ESD_PARA esd_para;
  319. uint8_t *buffer;
  320. if (copy_from_user(&esd_para, (void __user *)arg,
  321. sizeof(esd_para))) {
  322. pr_debug("[LCM_GET_ESD]: copy_from_user failed! line:%d\n",
  323. __LINE__);
  324. return -EFAULT;
  325. }
  326. if (esd_para.para_num < 0 || esd_para.para_num > 0x30) {
  327. pr_debug(
  328. "[LCM_GET_ESD]: wrong esd_para.para_num= %d! line:%d\n",
  329. esd_para.para_num, __LINE__);
  330. return -EFAULT;
  331. }
  332. buffer = kzalloc(esd_para.para_num + 6, GFP_KERNEL);
  333. if (!buffer)
  334. return -ENOMEM;
  335. ret = fbconfig_get_esd_check_test(crtc, esd_para.addr,
  336. buffer, esd_para.para_num);
  337. if (ret < 0) {
  338. kfree(buffer);
  339. return -EFAULT;
  340. }
  341. ret = copy_to_user(esd_para.esd_ret_buffer,
  342. buffer, esd_para.para_num);
  343. kfree(buffer);
  344. return ret;
  345. }
  346. case TE_SET_ENABLE:
  347. {
  348. return 0;
  349. }
  350. case DRIVER_IC_RESET:
  351. {
  352. Panel_Master_dsi_config_entry(crtc, "PM_DRIVER_IC_RESET", 0);
  353. return 0;
  354. }
  355. case FB_GET_MISC:
  356. {
  357. /* not support anymore */
  358. return 0;
  359. }
  360. default:
  361. return ret;
  362. }
  363. }
  364. static int fbconfig_release(struct inode *inode, struct file *file)
  365. {
  366. return 0;
  367. }
  368. static const struct file_operations fbconfig_fops = {
  369. .read = fbconfig_read,
  370. .write = fbconfig_write,
  371. .open = fbconfig_open,
  372. .unlocked_ioctl = fbconfig_ioctl,
  373. /*
  374. * #ifdef CONFIG_COMPAT
  375. * waiting to designed
  376. * .compat_ioctl = compat_fbconfig_ioctl,
  377. * #endif
  378. */
  379. .release = fbconfig_release,
  380. };
  381. void PanelMaster_probe(void)
  382. {
  383. ConfigPara_dbgfs = debugfs_create_file("fbconfig", S_IFREG | 0444,
  384. NULL, (void *)0, &fbconfig_fops);
  385. INIT_LIST_HEAD(&head_list.list);
  386. }
  387. void PanelMaster_Init(struct drm_device *dev)
  388. {
  389. drm_dev = dev;
  390. }
  391. void PanelMaster_Deinit(void)
  392. {
  393. debugfs_remove(ConfigPara_dbgfs);
  394. }