output.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /*
  2. * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
  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 <linux/of.h>
  22. #include "omapdss.h"
  23. static LIST_HEAD(output_list);
  24. static DEFINE_MUTEX(output_lock);
  25. int omapdss_output_set_device(struct omap_dss_device *out,
  26. struct omap_dss_device *dssdev)
  27. {
  28. int r;
  29. mutex_lock(&output_lock);
  30. if (out->dst) {
  31. dev_err(out->dev,
  32. "output already has device %s connected to it\n",
  33. out->dst->name);
  34. r = -EINVAL;
  35. goto err;
  36. }
  37. if (out->output_type != dssdev->type) {
  38. dev_err(out->dev, "output type and display type don't match\n");
  39. r = -EINVAL;
  40. goto err;
  41. }
  42. out->dst = dssdev;
  43. dssdev->src = out;
  44. mutex_unlock(&output_lock);
  45. return 0;
  46. err:
  47. mutex_unlock(&output_lock);
  48. return r;
  49. }
  50. EXPORT_SYMBOL(omapdss_output_set_device);
  51. int omapdss_output_unset_device(struct omap_dss_device *out)
  52. {
  53. int r;
  54. mutex_lock(&output_lock);
  55. if (!out->dst) {
  56. dev_err(out->dev,
  57. "output doesn't have a device connected to it\n");
  58. r = -EINVAL;
  59. goto err;
  60. }
  61. if (out->dst->state != OMAP_DSS_DISPLAY_DISABLED) {
  62. dev_err(out->dev,
  63. "device %s is not disabled, cannot unset device\n",
  64. out->dst->name);
  65. r = -EINVAL;
  66. goto err;
  67. }
  68. out->dst->src = NULL;
  69. out->dst = NULL;
  70. mutex_unlock(&output_lock);
  71. return 0;
  72. err:
  73. mutex_unlock(&output_lock);
  74. return r;
  75. }
  76. EXPORT_SYMBOL(omapdss_output_unset_device);
  77. int omapdss_register_output(struct omap_dss_device *out)
  78. {
  79. list_add_tail(&out->list, &output_list);
  80. return 0;
  81. }
  82. EXPORT_SYMBOL(omapdss_register_output);
  83. void omapdss_unregister_output(struct omap_dss_device *out)
  84. {
  85. list_del(&out->list);
  86. }
  87. EXPORT_SYMBOL(omapdss_unregister_output);
  88. bool omapdss_component_is_output(struct device_node *node)
  89. {
  90. struct omap_dss_device *out;
  91. list_for_each_entry(out, &output_list, list) {
  92. if (out->dev->of_node == node)
  93. return true;
  94. }
  95. return false;
  96. }
  97. EXPORT_SYMBOL(omapdss_component_is_output);
  98. struct omap_dss_device *omap_dss_get_output(enum omap_dss_output_id id)
  99. {
  100. struct omap_dss_device *out;
  101. list_for_each_entry(out, &output_list, list) {
  102. if (out->id == id)
  103. return out;
  104. }
  105. return NULL;
  106. }
  107. EXPORT_SYMBOL(omap_dss_get_output);
  108. struct omap_dss_device *omap_dss_find_output_by_port_node(struct device_node *port)
  109. {
  110. struct device_node *src_node;
  111. struct omap_dss_device *out;
  112. u32 reg;
  113. src_node = dss_of_port_get_parent_device(port);
  114. if (!src_node)
  115. return NULL;
  116. reg = dss_of_port_get_port_number(port);
  117. list_for_each_entry(out, &output_list, list) {
  118. if (out->dev->of_node == src_node && out->port_num == reg) {
  119. of_node_put(src_node);
  120. return omap_dss_get_device(out);
  121. }
  122. }
  123. of_node_put(src_node);
  124. return NULL;
  125. }
  126. EXPORT_SYMBOL(omap_dss_find_output_by_port_node);
  127. struct omap_dss_device *omapdss_find_output_from_display(struct omap_dss_device *dssdev)
  128. {
  129. while (dssdev->src)
  130. dssdev = dssdev->src;
  131. if (dssdev->id != 0)
  132. return omap_dss_get_device(dssdev);
  133. return NULL;
  134. }
  135. EXPORT_SYMBOL(omapdss_find_output_from_display);
  136. static const struct dss_mgr_ops *dss_mgr_ops;
  137. int dss_install_mgr_ops(const struct dss_mgr_ops *mgr_ops)
  138. {
  139. if (dss_mgr_ops)
  140. return -EBUSY;
  141. dss_mgr_ops = mgr_ops;
  142. return 0;
  143. }
  144. EXPORT_SYMBOL(dss_install_mgr_ops);
  145. void dss_uninstall_mgr_ops(void)
  146. {
  147. dss_mgr_ops = NULL;
  148. }
  149. EXPORT_SYMBOL(dss_uninstall_mgr_ops);
  150. int dss_mgr_connect(enum omap_channel channel,
  151. struct omap_dss_device *dst)
  152. {
  153. return dss_mgr_ops->connect(channel, dst);
  154. }
  155. EXPORT_SYMBOL(dss_mgr_connect);
  156. void dss_mgr_disconnect(enum omap_channel channel,
  157. struct omap_dss_device *dst)
  158. {
  159. dss_mgr_ops->disconnect(channel, dst);
  160. }
  161. EXPORT_SYMBOL(dss_mgr_disconnect);
  162. void dss_mgr_set_timings(enum omap_channel channel, const struct videomode *vm)
  163. {
  164. dss_mgr_ops->set_timings(channel, vm);
  165. }
  166. EXPORT_SYMBOL(dss_mgr_set_timings);
  167. void dss_mgr_set_lcd_config(enum omap_channel channel,
  168. const struct dss_lcd_mgr_config *config)
  169. {
  170. dss_mgr_ops->set_lcd_config(channel, config);
  171. }
  172. EXPORT_SYMBOL(dss_mgr_set_lcd_config);
  173. int dss_mgr_enable(enum omap_channel channel)
  174. {
  175. return dss_mgr_ops->enable(channel);
  176. }
  177. EXPORT_SYMBOL(dss_mgr_enable);
  178. void dss_mgr_disable(enum omap_channel channel)
  179. {
  180. dss_mgr_ops->disable(channel);
  181. }
  182. EXPORT_SYMBOL(dss_mgr_disable);
  183. void dss_mgr_start_update(enum omap_channel channel)
  184. {
  185. dss_mgr_ops->start_update(channel);
  186. }
  187. EXPORT_SYMBOL(dss_mgr_start_update);
  188. int dss_mgr_register_framedone_handler(enum omap_channel channel,
  189. void (*handler)(void *), void *data)
  190. {
  191. return dss_mgr_ops->register_framedone_handler(channel, handler, data);
  192. }
  193. EXPORT_SYMBOL(dss_mgr_register_framedone_handler);
  194. void dss_mgr_unregister_framedone_handler(enum omap_channel channel,
  195. void (*handler)(void *), void *data)
  196. {
  197. dss_mgr_ops->unregister_framedone_handler(channel, handler, data);
  198. }
  199. EXPORT_SYMBOL(dss_mgr_unregister_framedone_handler);