mdss_dsi_status.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /* Copyright (c) 2013-2014, 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 <linux/module.h>
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/fb.h>
  16. #include <linux/notifier.h>
  17. #include <linux/workqueue.h>
  18. #include <linux/delay.h>
  19. #include <linux/debugfs.h>
  20. #include <linux/slab.h>
  21. #include <linux/uaccess.h>
  22. #include <linux/iopoll.h>
  23. #include <linux/kobject.h>
  24. #include <linux/string.h>
  25. #include <linux/sysfs.h>
  26. #include "mdss_fb.h"
  27. #include "mdss_dsi.h"
  28. #include "mdss_panel.h"
  29. #include "mdss_mdp.h"
  30. #define STATUS_CHECK_INTERVAL_MS 5000
  31. #define STATUS_CHECK_INTERVAL_MIN_MS 200
  32. #define DSI_STATUS_CHECK_DISABLE 0
  33. static uint32_t interval = STATUS_CHECK_INTERVAL_MS;
  34. static uint32_t dsi_status_disable = DSI_STATUS_CHECK_DISABLE;
  35. struct dsi_status_data *pstatus_data;
  36. /*
  37. * check_dsi_ctrl_status() - Reads MFD structure and
  38. * calls platform specific DSI ctrl Status function.
  39. * @work : dsi controller status data
  40. */
  41. static void check_dsi_ctrl_status(struct work_struct *work)
  42. {
  43. struct dsi_status_data *pdsi_status = NULL;
  44. pdsi_status = container_of(to_delayed_work(work),
  45. struct dsi_status_data, check_status);
  46. if (!pdsi_status) {
  47. pr_err("%s: DSI status data not available\n", __func__);
  48. return;
  49. }
  50. if (!pdsi_status->mfd) {
  51. pr_err("%s: FB data not available\n", __func__);
  52. return;
  53. }
  54. pdsi_status->mfd->mdp.check_dsi_status(work, interval);
  55. }
  56. /*
  57. * fb_event_callback() - Call back function for the fb_register_client()
  58. * notifying events
  59. * @self : notifier block
  60. * @event : The event that was triggered
  61. * @data : Of type struct fb_event
  62. *
  63. * This function listens for FB_BLANK_UNBLANK and FB_BLANK_POWERDOWN events
  64. * from frame buffer. DSI status check work is either scheduled again after
  65. * PANEL_STATUS_CHECK_INTERVAL or cancelled based on the event.
  66. */
  67. static int fb_event_callback(struct notifier_block *self,
  68. unsigned long event, void *data)
  69. {
  70. struct fb_event *evdata = data;
  71. struct dsi_status_data *pdata = container_of(self,
  72. struct dsi_status_data, fb_notifier);
  73. struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL;
  74. struct mdss_panel_info *pinfo;
  75. struct msm_fb_data_type *mfd;
  76. if (!evdata) {
  77. pr_err("%s: event data not available\n", __func__);
  78. return NOTIFY_BAD;
  79. }
  80. mfd = evdata->info->par;
  81. ctrl_pdata = container_of(dev_get_platdata(&mfd->pdev->dev),
  82. struct mdss_dsi_ctrl_pdata, panel_data);
  83. if (!ctrl_pdata) {
  84. pr_err("%s: DSI ctrl not available\n", __func__);
  85. return NOTIFY_BAD;
  86. }
  87. pinfo = &ctrl_pdata->panel_data.panel_info;
  88. if (!(pinfo->esd_check_enabled)) {
  89. pr_debug("ESD check is not enaled in panel dtsi\n");
  90. return NOTIFY_DONE;
  91. }
  92. if (dsi_status_disable) {
  93. pr_debug("%s: DSI status disabled\n", __func__);
  94. return NOTIFY_DONE;
  95. }
  96. pdata->mfd = evdata->info->par;
  97. if (event == FB_EVENT_BLANK) {
  98. int *blank = evdata->data;
  99. struct dsi_status_data *pdata = container_of(self,
  100. struct dsi_status_data, fb_notifier);
  101. pdata->mfd = evdata->info->par;
  102. switch (*blank) {
  103. case FB_BLANK_UNBLANK:
  104. schedule_delayed_work(&pdata->check_status,
  105. msecs_to_jiffies(interval));
  106. break;
  107. case FB_BLANK_POWERDOWN:
  108. case FB_BLANK_HSYNC_SUSPEND:
  109. case FB_BLANK_VSYNC_SUSPEND:
  110. case FB_BLANK_NORMAL:
  111. cancel_delayed_work(&pdata->check_status);
  112. break;
  113. default:
  114. pr_err("Unknown case in FB_EVENT_BLANK event\n");
  115. break;
  116. }
  117. }
  118. return 0;
  119. }
  120. static int param_dsi_status_disable(const char *val, struct kernel_param *kp)
  121. {
  122. int ret = 0;
  123. int int_val;
  124. ret = kstrtos32(val, 0, &int_val);
  125. if (ret)
  126. return ret;
  127. pr_info("%s: Set DSI status disable to %d\n",
  128. __func__, int_val);
  129. *((int *)kp->arg) = int_val;
  130. return ret;
  131. }
  132. static int param_set_interval(const char *val, struct kernel_param *kp)
  133. {
  134. int ret = 0;
  135. int int_val;
  136. ret = kstrtos32(val, 0, &int_val);
  137. if (ret)
  138. return ret;
  139. if (int_val < STATUS_CHECK_INTERVAL_MIN_MS) {
  140. pr_err("%s: Invalid value %d used, ignoring\n",
  141. __func__, int_val);
  142. ret = -EINVAL;
  143. } else {
  144. pr_info("%s: Set check interval to %d msecs\n",
  145. __func__, int_val);
  146. *((int *)kp->arg) = int_val;
  147. }
  148. return ret;
  149. }
  150. int __init mdss_dsi_status_init(void)
  151. {
  152. int rc = 0;
  153. pstatus_data = kzalloc(sizeof(struct dsi_status_data), GFP_KERNEL);
  154. if (!pstatus_data) {
  155. pr_err("%s: can't allocate memory\n", __func__);
  156. return -ENOMEM;
  157. }
  158. pstatus_data->fb_notifier.notifier_call = fb_event_callback;
  159. rc = fb_register_client(&pstatus_data->fb_notifier);
  160. if (rc < 0) {
  161. pr_err("%s: fb_register_client failed, returned with rc=%d\n",
  162. __func__, rc);
  163. kfree(pstatus_data);
  164. return -EPERM;
  165. }
  166. pr_info("%s: DSI status check interval:%d\n", __func__, interval);
  167. INIT_DELAYED_WORK(&pstatus_data->check_status, check_dsi_ctrl_status);
  168. pr_debug("%s: DSI ctrl status work queue initialized\n", __func__);
  169. return rc;
  170. }
  171. void __exit mdss_dsi_status_exit(void)
  172. {
  173. fb_unregister_client(&pstatus_data->fb_notifier);
  174. cancel_delayed_work_sync(&pstatus_data->check_status);
  175. kfree(pstatus_data);
  176. pr_debug("%s: DSI ctrl status work queue removed\n", __func__);
  177. }
  178. module_param_call(interval, param_set_interval, param_get_uint,
  179. &interval, 0644);
  180. MODULE_PARM_DESC(interval,
  181. "Duration in milliseconds to send BTA command for checking"
  182. "DSI status periodically");
  183. module_param_call(dsi_status_disable, param_dsi_status_disable, param_get_uint,
  184. &dsi_status_disable, 0644);
  185. MODULE_PARM_DESC(dsi_status_disable,
  186. "Disable DSI status check");
  187. module_init(mdss_dsi_status_init);
  188. module_exit(mdss_dsi_status_exit);
  189. MODULE_LICENSE("GPL v2");