output.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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 <video/omapdss.h>
  23. #include "dss.h"
  24. static LIST_HEAD(output_list);
  25. static DEFINE_MUTEX(output_lock);
  26. int omapdss_output_set_device(struct omap_dss_device *out,
  27. struct omap_dss_device *dssdev)
  28. {
  29. int r;
  30. mutex_lock(&output_lock);
  31. if (out->dst) {
  32. DSSERR("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. DSSERR("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. DSSERR("output doesn't have a device connected to it\n");
  57. r = -EINVAL;
  58. goto err;
  59. }
  60. if (out->dst->state != OMAP_DSS_DISPLAY_DISABLED) {
  61. DSSERR("device %s is not disabled, cannot unset device\n",
  62. out->dst->name);
  63. r = -EINVAL;
  64. goto err;
  65. }
  66. out->dst->src = NULL;
  67. out->dst = NULL;
  68. mutex_unlock(&output_lock);
  69. return 0;
  70. err:
  71. mutex_unlock(&output_lock);
  72. return r;
  73. }
  74. EXPORT_SYMBOL(omapdss_output_unset_device);
  75. int omapdss_register_output(struct omap_dss_device *out)
  76. {
  77. list_add_tail(&out->list, &output_list);
  78. return 0;
  79. }
  80. EXPORT_SYMBOL(omapdss_register_output);
  81. void omapdss_unregister_output(struct omap_dss_device *out)
  82. {
  83. list_del(&out->list);
  84. }
  85. EXPORT_SYMBOL(omapdss_unregister_output);
  86. struct omap_dss_device *omap_dss_get_output(enum omap_dss_output_id id)
  87. {
  88. struct omap_dss_device *out;
  89. list_for_each_entry(out, &output_list, list) {
  90. if (out->id == id)
  91. return out;
  92. }
  93. return NULL;
  94. }
  95. EXPORT_SYMBOL(omap_dss_get_output);
  96. struct omap_dss_device *omap_dss_find_output(const char *name)
  97. {
  98. struct omap_dss_device *out;
  99. list_for_each_entry(out, &output_list, list) {
  100. if (strcmp(out->name, name) == 0)
  101. return omap_dss_get_device(out);
  102. }
  103. return NULL;
  104. }
  105. EXPORT_SYMBOL(omap_dss_find_output);
  106. struct omap_dss_device *omap_dss_find_output_by_port_node(struct device_node *port)
  107. {
  108. struct device_node *src_node;
  109. struct omap_dss_device *out;
  110. u32 reg;
  111. src_node = dss_of_port_get_parent_device(port);
  112. if (!src_node)
  113. return NULL;
  114. reg = dss_of_port_get_port_number(port);
  115. list_for_each_entry(out, &output_list, list) {
  116. if (out->dev->of_node == src_node && out->port_num == reg) {
  117. of_node_put(src_node);
  118. return omap_dss_get_device(out);
  119. }
  120. }
  121. of_node_put(src_node);
  122. return NULL;
  123. }
  124. EXPORT_SYMBOL(omap_dss_find_output_by_port_node);
  125. struct omap_dss_device *omapdss_find_output_from_display(struct omap_dss_device *dssdev)
  126. {
  127. while (dssdev->src)
  128. dssdev = dssdev->src;
  129. if (dssdev->id != 0)
  130. return omap_dss_get_device(dssdev);
  131. return NULL;
  132. }
  133. EXPORT_SYMBOL(omapdss_find_output_from_display);
  134. struct omap_overlay_manager *omapdss_find_mgr_from_display(struct omap_dss_device *dssdev)
  135. {
  136. struct omap_dss_device *out;
  137. struct omap_overlay_manager *mgr;
  138. out = omapdss_find_output_from_display(dssdev);
  139. if (out == NULL)
  140. return NULL;
  141. mgr = out->manager;
  142. omap_dss_put_device(out);
  143. return mgr;
  144. }
  145. EXPORT_SYMBOL(omapdss_find_mgr_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(struct omap_overlay_manager *mgr,
  161. struct omap_dss_device *dst)
  162. {
  163. return dss_mgr_ops->connect(mgr, dst);
  164. }
  165. EXPORT_SYMBOL(dss_mgr_connect);
  166. void dss_mgr_disconnect(struct omap_overlay_manager *mgr,
  167. struct omap_dss_device *dst)
  168. {
  169. dss_mgr_ops->disconnect(mgr, dst);
  170. }
  171. EXPORT_SYMBOL(dss_mgr_disconnect);
  172. void dss_mgr_set_timings(struct omap_overlay_manager *mgr,
  173. const struct omap_video_timings *timings)
  174. {
  175. dss_mgr_ops->set_timings(mgr, timings);
  176. }
  177. EXPORT_SYMBOL(dss_mgr_set_timings);
  178. void dss_mgr_set_lcd_config(struct omap_overlay_manager *mgr,
  179. const struct dss_lcd_mgr_config *config)
  180. {
  181. dss_mgr_ops->set_lcd_config(mgr, config);
  182. }
  183. EXPORT_SYMBOL(dss_mgr_set_lcd_config);
  184. int dss_mgr_enable(struct omap_overlay_manager *mgr)
  185. {
  186. return dss_mgr_ops->enable(mgr);
  187. }
  188. EXPORT_SYMBOL(dss_mgr_enable);
  189. void dss_mgr_disable(struct omap_overlay_manager *mgr)
  190. {
  191. dss_mgr_ops->disable(mgr);
  192. }
  193. EXPORT_SYMBOL(dss_mgr_disable);
  194. void dss_mgr_start_update(struct omap_overlay_manager *mgr)
  195. {
  196. dss_mgr_ops->start_update(mgr);
  197. }
  198. EXPORT_SYMBOL(dss_mgr_start_update);
  199. int dss_mgr_register_framedone_handler(struct omap_overlay_manager *mgr,
  200. void (*handler)(void *), void *data)
  201. {
  202. return dss_mgr_ops->register_framedone_handler(mgr, handler, data);
  203. }
  204. EXPORT_SYMBOL(dss_mgr_register_framedone_handler);
  205. void dss_mgr_unregister_framedone_handler(struct omap_overlay_manager *mgr,
  206. void (*handler)(void *), void *data)
  207. {
  208. dss_mgr_ops->unregister_framedone_handler(mgr, handler, data);
  209. }
  210. EXPORT_SYMBOL(dss_mgr_unregister_framedone_handler);