output.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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 <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(const char *name)
  109. {
  110. struct omap_dss_device *out;
  111. list_for_each_entry(out, &output_list, list) {
  112. if (strcmp(out->name, name) == 0)
  113. return omap_dss_get_device(out);
  114. }
  115. return NULL;
  116. }
  117. EXPORT_SYMBOL(omap_dss_find_output);
  118. struct omap_dss_device *omap_dss_find_output_by_port_node(struct device_node *port)
  119. {
  120. struct device_node *src_node;
  121. struct omap_dss_device *out;
  122. u32 reg;
  123. src_node = dss_of_port_get_parent_device(port);
  124. if (!src_node)
  125. return NULL;
  126. reg = dss_of_port_get_port_number(port);
  127. list_for_each_entry(out, &output_list, list) {
  128. if (out->dev->of_node == src_node && out->port_num == reg) {
  129. of_node_put(src_node);
  130. return omap_dss_get_device(out);
  131. }
  132. }
  133. of_node_put(src_node);
  134. return NULL;
  135. }
  136. EXPORT_SYMBOL(omap_dss_find_output_by_port_node);
  137. struct omap_dss_device *omapdss_find_output_from_display(struct omap_dss_device *dssdev)
  138. {
  139. while (dssdev->src)
  140. dssdev = dssdev->src;
  141. if (dssdev->id != 0)
  142. return omap_dss_get_device(dssdev);
  143. return NULL;
  144. }
  145. EXPORT_SYMBOL(omapdss_find_output_from_display);
  146. static const struct dss_mgr_ops *dss_mgr_ops;
  147. int dss_install_mgr_ops(const struct dss_mgr_ops *mgr_ops)
  148. {
  149. if (dss_mgr_ops)
  150. return -EBUSY;
  151. dss_mgr_ops = mgr_ops;
  152. return 0;
  153. }
  154. EXPORT_SYMBOL(dss_install_mgr_ops);
  155. void dss_uninstall_mgr_ops(void)
  156. {
  157. dss_mgr_ops = NULL;
  158. }
  159. EXPORT_SYMBOL(dss_uninstall_mgr_ops);
  160. int dss_mgr_connect(enum omap_channel channel,
  161. struct omap_dss_device *dst)
  162. {
  163. return dss_mgr_ops->connect(channel, dst);
  164. }
  165. EXPORT_SYMBOL(dss_mgr_connect);
  166. void dss_mgr_disconnect(enum omap_channel channel,
  167. struct omap_dss_device *dst)
  168. {
  169. dss_mgr_ops->disconnect(channel, dst);
  170. }
  171. EXPORT_SYMBOL(dss_mgr_disconnect);
  172. void dss_mgr_set_timings(enum omap_channel channel, const struct videomode *vm)
  173. {
  174. dss_mgr_ops->set_timings(channel, vm);
  175. }
  176. EXPORT_SYMBOL(dss_mgr_set_timings);
  177. void dss_mgr_set_lcd_config(enum omap_channel channel,
  178. const struct dss_lcd_mgr_config *config)
  179. {
  180. dss_mgr_ops->set_lcd_config(channel, config);
  181. }
  182. EXPORT_SYMBOL(dss_mgr_set_lcd_config);
  183. int dss_mgr_enable(enum omap_channel channel)
  184. {
  185. return dss_mgr_ops->enable(channel);
  186. }
  187. EXPORT_SYMBOL(dss_mgr_enable);
  188. void dss_mgr_disable(enum omap_channel channel)
  189. {
  190. dss_mgr_ops->disable(channel);
  191. }
  192. EXPORT_SYMBOL(dss_mgr_disable);
  193. void dss_mgr_start_update(enum omap_channel channel)
  194. {
  195. dss_mgr_ops->start_update(channel);
  196. }
  197. EXPORT_SYMBOL(dss_mgr_start_update);
  198. int dss_mgr_register_framedone_handler(enum omap_channel channel,
  199. void (*handler)(void *), void *data)
  200. {
  201. return dss_mgr_ops->register_framedone_handler(channel, handler, data);
  202. }
  203. EXPORT_SYMBOL(dss_mgr_register_framedone_handler);
  204. void dss_mgr_unregister_framedone_handler(enum omap_channel channel,
  205. void (*handler)(void *), void *data)
  206. {
  207. dss_mgr_ops->unregister_framedone_handler(channel, handler, data);
  208. }
  209. EXPORT_SYMBOL(dss_mgr_unregister_framedone_handler);