drm_encoder_slave.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * Copyright (C) 2009 Francisco Jerez.
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * The above copyright notice and this permission notice (including the
  14. * next paragraph) shall be included in all copies or substantial
  15. * portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  20. * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
  21. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. *
  25. */
  26. #ifndef __DRM_ENCODER_SLAVE_H__
  27. #define __DRM_ENCODER_SLAVE_H__
  28. #include <drm/drmP.h>
  29. #include <drm/drm_crtc.h>
  30. #include <drm/drm_encoder.h>
  31. /**
  32. * struct drm_encoder_slave_funcs - Entry points exposed by a slave encoder driver
  33. * @set_config: Initialize any encoder-specific modesetting parameters.
  34. * The meaning of the @params parameter is implementation
  35. * dependent. It will usually be a structure with DVO port
  36. * data format settings or timings. It's not required for
  37. * the new parameters to take effect until the next mode
  38. * is set.
  39. *
  40. * Most of its members are analogous to the function pointers in
  41. * &drm_encoder_helper_funcs and they can optionally be used to
  42. * initialize the latter. Connector-like methods (e.g. @get_modes and
  43. * @set_property) will typically be wrapped around and only be called
  44. * if the encoder is the currently selected one for the connector.
  45. */
  46. struct drm_encoder_slave_funcs {
  47. void (*set_config)(struct drm_encoder *encoder,
  48. void *params);
  49. void (*destroy)(struct drm_encoder *encoder);
  50. void (*dpms)(struct drm_encoder *encoder, int mode);
  51. void (*save)(struct drm_encoder *encoder);
  52. void (*restore)(struct drm_encoder *encoder);
  53. bool (*mode_fixup)(struct drm_encoder *encoder,
  54. const struct drm_display_mode *mode,
  55. struct drm_display_mode *adjusted_mode);
  56. int (*mode_valid)(struct drm_encoder *encoder,
  57. struct drm_display_mode *mode);
  58. void (*mode_set)(struct drm_encoder *encoder,
  59. struct drm_display_mode *mode,
  60. struct drm_display_mode *adjusted_mode);
  61. enum drm_connector_status (*detect)(struct drm_encoder *encoder,
  62. struct drm_connector *connector);
  63. int (*get_modes)(struct drm_encoder *encoder,
  64. struct drm_connector *connector);
  65. int (*create_resources)(struct drm_encoder *encoder,
  66. struct drm_connector *connector);
  67. int (*set_property)(struct drm_encoder *encoder,
  68. struct drm_connector *connector,
  69. struct drm_property *property,
  70. uint64_t val);
  71. };
  72. /**
  73. * struct drm_encoder_slave - Slave encoder struct
  74. * @base: DRM encoder object.
  75. * @slave_funcs: Slave encoder callbacks.
  76. * @slave_priv: Slave encoder private data.
  77. * @bus_priv: Bus specific data.
  78. *
  79. * A &drm_encoder_slave has two sets of callbacks, @slave_funcs and the
  80. * ones in @base. The former are never actually called by the common
  81. * CRTC code, it's just a convenience for splitting the encoder
  82. * functions in an upper, GPU-specific layer and a (hopefully)
  83. * GPU-agnostic lower layer: It's the GPU driver responsibility to
  84. * call the slave methods when appropriate.
  85. *
  86. * drm_i2c_encoder_init() provides a way to get an implementation of
  87. * this.
  88. */
  89. struct drm_encoder_slave {
  90. struct drm_encoder base;
  91. const struct drm_encoder_slave_funcs *slave_funcs;
  92. void *slave_priv;
  93. void *bus_priv;
  94. };
  95. #define to_encoder_slave(x) container_of((x), struct drm_encoder_slave, base)
  96. int drm_i2c_encoder_init(struct drm_device *dev,
  97. struct drm_encoder_slave *encoder,
  98. struct i2c_adapter *adap,
  99. const struct i2c_board_info *info);
  100. /**
  101. * struct drm_i2c_encoder_driver
  102. *
  103. * Describes a device driver for an encoder connected to the GPU
  104. * through an I2C bus. In addition to the entry points in @i2c_driver
  105. * an @encoder_init function should be provided. It will be called to
  106. * give the driver an opportunity to allocate any per-encoder data
  107. * structures and to initialize the @slave_funcs and (optionally)
  108. * @slave_priv members of @encoder.
  109. */
  110. struct drm_i2c_encoder_driver {
  111. struct i2c_driver i2c_driver;
  112. int (*encoder_init)(struct i2c_client *client,
  113. struct drm_device *dev,
  114. struct drm_encoder_slave *encoder);
  115. };
  116. #define to_drm_i2c_encoder_driver(x) container_of((x), \
  117. struct drm_i2c_encoder_driver, \
  118. i2c_driver)
  119. /**
  120. * drm_i2c_encoder_get_client - Get the I2C client corresponding to an encoder
  121. */
  122. static inline struct i2c_client *drm_i2c_encoder_get_client(struct drm_encoder *encoder)
  123. {
  124. return (struct i2c_client *)to_encoder_slave(encoder)->bus_priv;
  125. }
  126. /**
  127. * drm_i2c_encoder_register - Register an I2C encoder driver
  128. * @owner: Module containing the driver.
  129. * @driver: Driver to be registered.
  130. */
  131. static inline int drm_i2c_encoder_register(struct module *owner,
  132. struct drm_i2c_encoder_driver *driver)
  133. {
  134. return i2c_register_driver(owner, &driver->i2c_driver);
  135. }
  136. /**
  137. * drm_i2c_encoder_unregister - Unregister an I2C encoder driver
  138. * @driver: Driver to be unregistered.
  139. */
  140. static inline void drm_i2c_encoder_unregister(struct drm_i2c_encoder_driver *driver)
  141. {
  142. i2c_del_driver(&driver->i2c_driver);
  143. }
  144. void drm_i2c_encoder_destroy(struct drm_encoder *encoder);
  145. /*
  146. * Wrapper fxns which can be plugged in to drm_encoder_helper_funcs:
  147. */
  148. void drm_i2c_encoder_dpms(struct drm_encoder *encoder, int mode);
  149. bool drm_i2c_encoder_mode_fixup(struct drm_encoder *encoder,
  150. const struct drm_display_mode *mode,
  151. struct drm_display_mode *adjusted_mode);
  152. void drm_i2c_encoder_prepare(struct drm_encoder *encoder);
  153. void drm_i2c_encoder_commit(struct drm_encoder *encoder);
  154. void drm_i2c_encoder_mode_set(struct drm_encoder *encoder,
  155. struct drm_display_mode *mode,
  156. struct drm_display_mode *adjusted_mode);
  157. enum drm_connector_status drm_i2c_encoder_detect(struct drm_encoder *encoder,
  158. struct drm_connector *connector);
  159. void drm_i2c_encoder_save(struct drm_encoder *encoder);
  160. void drm_i2c_encoder_restore(struct drm_encoder *encoder);
  161. #endif