output.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. struct omap_dss_device *omapdss_find_output_from_display(struct omap_dss_device *dssdev)
  127. {
  128. while (dssdev->src)
  129. dssdev = dssdev->src;
  130. if (dssdev->id != 0)
  131. return omap_dss_get_device(dssdev);
  132. return NULL;
  133. }
  134. EXPORT_SYMBOL(omapdss_find_output_from_display);
  135. static const struct dss_mgr_ops *dss_mgr_ops;
  136. static struct omap_drm_private *dss_mgr_ops_priv;
  137. int dss_install_mgr_ops(const struct dss_mgr_ops *mgr_ops,
  138. struct omap_drm_private *priv)
  139. {
  140. if (dss_mgr_ops)
  141. return -EBUSY;
  142. dss_mgr_ops = mgr_ops;
  143. dss_mgr_ops_priv = priv;
  144. return 0;
  145. }
  146. EXPORT_SYMBOL(dss_install_mgr_ops);
  147. void dss_uninstall_mgr_ops(void)
  148. {
  149. dss_mgr_ops = NULL;
  150. dss_mgr_ops_priv = NULL;
  151. }
  152. EXPORT_SYMBOL(dss_uninstall_mgr_ops);
  153. int dss_mgr_connect(struct omap_dss_device *dssdev, struct omap_dss_device *dst)
  154. {
  155. return dss_mgr_ops->connect(dss_mgr_ops_priv,
  156. dssdev->dispc_channel, dst);
  157. }
  158. EXPORT_SYMBOL(dss_mgr_connect);
  159. void dss_mgr_disconnect(struct omap_dss_device *dssdev,
  160. struct omap_dss_device *dst)
  161. {
  162. dss_mgr_ops->disconnect(dss_mgr_ops_priv, dssdev->dispc_channel, dst);
  163. }
  164. EXPORT_SYMBOL(dss_mgr_disconnect);
  165. void dss_mgr_set_timings(struct omap_dss_device *dssdev,
  166. const struct videomode *vm)
  167. {
  168. dss_mgr_ops->set_timings(dss_mgr_ops_priv, dssdev->dispc_channel, vm);
  169. }
  170. EXPORT_SYMBOL(dss_mgr_set_timings);
  171. void dss_mgr_set_lcd_config(struct omap_dss_device *dssdev,
  172. const struct dss_lcd_mgr_config *config)
  173. {
  174. dss_mgr_ops->set_lcd_config(dss_mgr_ops_priv,
  175. dssdev->dispc_channel, config);
  176. }
  177. EXPORT_SYMBOL(dss_mgr_set_lcd_config);
  178. int dss_mgr_enable(struct omap_dss_device *dssdev)
  179. {
  180. return dss_mgr_ops->enable(dss_mgr_ops_priv, dssdev->dispc_channel);
  181. }
  182. EXPORT_SYMBOL(dss_mgr_enable);
  183. void dss_mgr_disable(struct omap_dss_device *dssdev)
  184. {
  185. dss_mgr_ops->disable(dss_mgr_ops_priv, dssdev->dispc_channel);
  186. }
  187. EXPORT_SYMBOL(dss_mgr_disable);
  188. void dss_mgr_start_update(struct omap_dss_device *dssdev)
  189. {
  190. dss_mgr_ops->start_update(dss_mgr_ops_priv, dssdev->dispc_channel);
  191. }
  192. EXPORT_SYMBOL(dss_mgr_start_update);
  193. int dss_mgr_register_framedone_handler(struct omap_dss_device *dssdev,
  194. void (*handler)(void *), void *data)
  195. {
  196. return dss_mgr_ops->register_framedone_handler(dss_mgr_ops_priv,
  197. dssdev->dispc_channel,
  198. handler, data);
  199. }
  200. EXPORT_SYMBOL(dss_mgr_register_framedone_handler);
  201. void dss_mgr_unregister_framedone_handler(struct omap_dss_device *dssdev,
  202. void (*handler)(void *), void *data)
  203. {
  204. dss_mgr_ops->unregister_framedone_handler(dss_mgr_ops_priv,
  205. dssdev->dispc_channel,
  206. handler, data);
  207. }
  208. EXPORT_SYMBOL(dss_mgr_unregister_framedone_handler);