output.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. struct omap_dss_output *omapdss_get_output_from_dssdev(struct omap_dss_device *dssdev)
  92. {
  93. struct omap_dss_output *out = NULL;
  94. enum omap_dss_output_id id;
  95. switch (dssdev->type) {
  96. case OMAP_DISPLAY_TYPE_DPI:
  97. out = omap_dss_get_output(OMAP_DSS_OUTPUT_DPI);
  98. break;
  99. case OMAP_DISPLAY_TYPE_DBI:
  100. out = omap_dss_get_output(OMAP_DSS_OUTPUT_DBI);
  101. break;
  102. case OMAP_DISPLAY_TYPE_SDI:
  103. out = omap_dss_get_output(OMAP_DSS_OUTPUT_SDI);
  104. break;
  105. case OMAP_DISPLAY_TYPE_VENC:
  106. out = omap_dss_get_output(OMAP_DSS_OUTPUT_VENC);
  107. break;
  108. case OMAP_DISPLAY_TYPE_HDMI:
  109. out = omap_dss_get_output(OMAP_DSS_OUTPUT_HDMI);
  110. break;
  111. case OMAP_DISPLAY_TYPE_DSI:
  112. id = dssdev->phy.dsi.module == 0 ? OMAP_DSS_OUTPUT_DSI1 :
  113. OMAP_DSS_OUTPUT_DSI2;
  114. out = omap_dss_get_output(id);
  115. break;
  116. default:
  117. break;
  118. }
  119. return out;
  120. }