output.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * Copyright (C) 2012 Texas Instruments Ltd
  3. * Author: Archit Taneja <archit@ti.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published by
  7. * the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/module.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/slab.h>
  21. #include <video/omapdss.h>
  22. #include "dss.h"
  23. static LIST_HEAD(output_list);
  24. static DEFINE_MUTEX(output_lock);
  25. int omapdss_output_set_device(struct omap_dss_output *out,
  26. struct omap_dss_device *dssdev)
  27. {
  28. int r;
  29. mutex_lock(&output_lock);
  30. if (out->device) {
  31. DSSERR("output already has device %s connected to it\n",
  32. out->device->name);
  33. r = -EINVAL;
  34. goto err;
  35. }
  36. if (out->type != dssdev->type) {
  37. DSSERR("output type and display type don't match\n");
  38. r = -EINVAL;
  39. goto err;
  40. }
  41. out->device = dssdev;
  42. dssdev->output = out;
  43. mutex_unlock(&output_lock);
  44. return 0;
  45. err:
  46. mutex_unlock(&output_lock);
  47. return r;
  48. }
  49. EXPORT_SYMBOL(omapdss_output_set_device);
  50. int omapdss_output_unset_device(struct omap_dss_output *out)
  51. {
  52. int r;
  53. mutex_lock(&output_lock);
  54. if (!out->device) {
  55. DSSERR("output doesn't have a device connected to it\n");
  56. r = -EINVAL;
  57. goto err;
  58. }
  59. if (out->device->state != OMAP_DSS_DISPLAY_DISABLED) {
  60. DSSERR("device %s is not disabled, cannot unset device\n",
  61. out->device->name);
  62. r = -EINVAL;
  63. goto err;
  64. }
  65. out->device->output = NULL;
  66. out->device = NULL;
  67. mutex_unlock(&output_lock);
  68. return 0;
  69. err:
  70. mutex_unlock(&output_lock);
  71. return r;
  72. }
  73. EXPORT_SYMBOL(omapdss_output_unset_device);
  74. void dss_register_output(struct omap_dss_output *out)
  75. {
  76. list_add_tail(&out->list, &output_list);
  77. }
  78. void dss_unregister_output(struct omap_dss_output *out)
  79. {
  80. list_del(&out->list);
  81. }
  82. struct omap_dss_output *omap_dss_get_output(enum omap_dss_output_id id)
  83. {
  84. struct omap_dss_output *out;
  85. list_for_each_entry(out, &output_list, list) {
  86. if (out->id == id)
  87. return out;
  88. }
  89. return NULL;
  90. }
  91. EXPORT_SYMBOL(omap_dss_get_output);
  92. struct omap_dss_output *omap_dss_find_output(const char *name)
  93. {
  94. struct omap_dss_output *out;
  95. list_for_each_entry(out, &output_list, list) {
  96. if (strcmp(out->name, name) == 0)
  97. return out;
  98. }
  99. return NULL;
  100. }
  101. EXPORT_SYMBOL(omap_dss_find_output);
  102. struct omap_dss_output *omap_dss_find_output_by_node(struct device_node *node)
  103. {
  104. struct omap_dss_output *out;
  105. list_for_each_entry(out, &output_list, list) {
  106. if (out->pdev->dev.of_node == node)
  107. return out;
  108. }
  109. return NULL;
  110. }
  111. EXPORT_SYMBOL(omap_dss_find_output_by_node);
  112. static const struct dss_mgr_ops *dss_mgr_ops;
  113. int dss_install_mgr_ops(const struct dss_mgr_ops *mgr_ops)
  114. {
  115. if (dss_mgr_ops)
  116. return -EBUSY;
  117. dss_mgr_ops = mgr_ops;
  118. return 0;
  119. }
  120. EXPORT_SYMBOL(dss_install_mgr_ops);
  121. void dss_uninstall_mgr_ops(void)
  122. {
  123. dss_mgr_ops = NULL;
  124. }
  125. EXPORT_SYMBOL(dss_uninstall_mgr_ops);
  126. void dss_mgr_set_timings(struct omap_overlay_manager *mgr,
  127. const struct omap_video_timings *timings)
  128. {
  129. dss_mgr_ops->set_timings(mgr, timings);
  130. }
  131. EXPORT_SYMBOL(dss_mgr_set_timings);
  132. void dss_mgr_set_lcd_config(struct omap_overlay_manager *mgr,
  133. const struct dss_lcd_mgr_config *config)
  134. {
  135. dss_mgr_ops->set_lcd_config(mgr, config);
  136. }
  137. EXPORT_SYMBOL(dss_mgr_set_lcd_config);
  138. int dss_mgr_enable(struct omap_overlay_manager *mgr)
  139. {
  140. return dss_mgr_ops->enable(mgr);
  141. }
  142. EXPORT_SYMBOL(dss_mgr_enable);
  143. void dss_mgr_disable(struct omap_overlay_manager *mgr)
  144. {
  145. dss_mgr_ops->disable(mgr);
  146. }
  147. EXPORT_SYMBOL(dss_mgr_disable);
  148. void dss_mgr_start_update(struct omap_overlay_manager *mgr)
  149. {
  150. dss_mgr_ops->start_update(mgr);
  151. }
  152. EXPORT_SYMBOL(dss_mgr_start_update);
  153. int dss_mgr_register_framedone_handler(struct omap_overlay_manager *mgr,
  154. void (*handler)(void *), void *data)
  155. {
  156. return dss_mgr_ops->register_framedone_handler(mgr, handler, data);
  157. }
  158. EXPORT_SYMBOL(dss_mgr_register_framedone_handler);
  159. void dss_mgr_unregister_framedone_handler(struct omap_overlay_manager *mgr,
  160. void (*handler)(void *), void *data)
  161. {
  162. dss_mgr_ops->unregister_framedone_handler(mgr, handler, data);
  163. }
  164. EXPORT_SYMBOL(dss_mgr_unregister_framedone_handler);