mipi_simulator.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /* Copyright (c) 2011-2012, The Linux Foundation. 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 "msm_fb.h"
  13. #include "mipi_dsi.h"
  14. #include "mipi_simulator.h"
  15. static struct dsi_buf simulator_tx_buf;
  16. static struct dsi_buf simulator_rx_buf;
  17. static struct msm_panel_common_pdata *mipi_simulator_pdata;
  18. static int mipi_simulator_lcd_init(void);
  19. static char display_on[2] = {0x00, 0x00};
  20. static char display_off[2] = {0x00, 0x00};
  21. static struct dsi_cmd_desc display_on_cmds[] = {
  22. {DTYPE_PERIPHERAL_ON, 1, 0, 0, 0, sizeof(display_on),
  23. display_on}
  24. };
  25. static struct dsi_cmd_desc display_off_cmds[] = {
  26. {DTYPE_PERIPHERAL_OFF, 1, 0, 0, 0, sizeof(display_off),
  27. display_off}
  28. };
  29. static int mipi_simulator_lcd_on(struct platform_device *pdev)
  30. {
  31. struct msm_fb_data_type *mfd;
  32. struct mipi_panel_info *mipi;
  33. struct dcs_cmd_req cmdreq;
  34. mfd = platform_get_drvdata(pdev);
  35. mipi = &mfd->panel_info.mipi;
  36. if (!mfd)
  37. return -ENODEV;
  38. if (mfd->key != MFD_KEY)
  39. return -EINVAL;
  40. pr_debug("%s:%d, debug info (mode) : %d", __func__, __LINE__,
  41. mipi->mode);
  42. memset(&cmdreq, 0, sizeof(cmdreq));
  43. if (mipi->mode == DSI_VIDEO_MODE) {
  44. cmdreq.cmds = display_on_cmds;
  45. cmdreq.cmds_cnt = ARRAY_SIZE(display_on_cmds);
  46. cmdreq.flags = CMD_REQ_COMMIT;
  47. cmdreq.rlen = 0;
  48. cmdreq.cb = NULL;
  49. mipi_dsi_cmdlist_put(&cmdreq);
  50. } else {
  51. pr_err("%s:%d, CMD MODE NOT SUPPORTED", __func__, __LINE__);
  52. return -EINVAL;
  53. }
  54. return 0;
  55. }
  56. static int mipi_simulator_lcd_off(struct platform_device *pdev)
  57. {
  58. struct msm_fb_data_type *mfd;
  59. struct mipi_panel_info *mipi;
  60. struct dcs_cmd_req cmdreq;
  61. mfd = platform_get_drvdata(pdev);
  62. mipi = &mfd->panel_info.mipi;
  63. if (!mfd)
  64. return -ENODEV;
  65. if (mfd->key != MFD_KEY)
  66. return -EINVAL;
  67. pr_debug("%s:%d, debug info", __func__, __LINE__);
  68. memset(&cmdreq, 0, sizeof(cmdreq));
  69. if (mipi->mode == DSI_VIDEO_MODE) {
  70. cmdreq.cmds = display_off_cmds;
  71. cmdreq.cmds_cnt = ARRAY_SIZE(display_off_cmds);
  72. cmdreq.flags = CMD_REQ_COMMIT;
  73. cmdreq.rlen = 0;
  74. cmdreq.cb = NULL;
  75. mipi_dsi_cmdlist_put(&cmdreq);
  76. } else {
  77. pr_debug("%s:%d, DONT REACH HERE", __func__, __LINE__);
  78. return -EINVAL;
  79. }
  80. return 0;
  81. }
  82. static int __devinit mipi_simulator_lcd_probe(struct platform_device *pdev)
  83. {
  84. if (pdev->id == 0) {
  85. mipi_simulator_pdata = pdev->dev.platform_data;
  86. return 0;
  87. }
  88. pr_debug("%s:%d, debug info", __func__, __LINE__);
  89. msm_fb_add_device(pdev);
  90. return 0;
  91. }
  92. static struct platform_driver this_driver = {
  93. .probe = mipi_simulator_lcd_probe,
  94. .driver = {
  95. .name = "mipi_simulator",
  96. },
  97. };
  98. static struct msm_fb_panel_data simulator_panel_data = {
  99. .on = mipi_simulator_lcd_on,
  100. .off = mipi_simulator_lcd_off,
  101. };
  102. static int ch_used[3];
  103. int mipi_simulator_device_register(struct msm_panel_info *pinfo,
  104. u32 channel, u32 panel)
  105. {
  106. struct platform_device *pdev = NULL;
  107. int ret;
  108. if ((channel >= 3) || ch_used[channel])
  109. return -ENODEV;
  110. ch_used[channel] = TRUE;
  111. pr_debug("%s:%d, debug info", __func__, __LINE__);
  112. ret = mipi_simulator_lcd_init();
  113. if (ret) {
  114. pr_err("mipi_simulator_lcd_init() failed with ret %u\n", ret);
  115. return ret;
  116. }
  117. pdev = platform_device_alloc("mipi_simulator", (panel << 8)|channel);
  118. if (!pdev)
  119. return -ENOMEM;
  120. simulator_panel_data.panel_info = *pinfo;
  121. ret = platform_device_add_data(pdev, &simulator_panel_data,
  122. sizeof(simulator_panel_data));
  123. if (ret) {
  124. pr_err(KERN_ERR
  125. "%s: platform_device_add_data failed!\n", __func__);
  126. goto err_device_put;
  127. }
  128. ret = platform_device_add(pdev);
  129. if (ret) {
  130. pr_err(KERN_ERR
  131. "%s: platform_device_register failed!\n", __func__);
  132. goto err_device_put;
  133. }
  134. return 0;
  135. err_device_put:
  136. platform_device_put(pdev);
  137. return ret;
  138. }
  139. static int mipi_simulator_lcd_init(void)
  140. {
  141. mipi_dsi_buf_alloc(&simulator_tx_buf, DSI_BUF_SIZE);
  142. mipi_dsi_buf_alloc(&simulator_rx_buf, DSI_BUF_SIZE);
  143. return platform_driver_register(&this_driver);
  144. }