drm_encoder_slave.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. /**
  31. * struct drm_encoder_slave_funcs - Entry points exposed by a slave encoder driver
  32. * @set_config: Initialize any encoder-specific modesetting parameters.
  33. * The meaning of the @params parameter is implementation
  34. * dependent. It will usually be a structure with DVO port
  35. * data format settings or timings. It's not required for
  36. * the new parameters to take effect until the next mode
  37. * is set.
  38. *
  39. * Most of its members are analogous to the function pointers in
  40. * &drm_encoder_helper_funcs and they can optionally be used to
  41. * initialize the latter. Connector-like methods (e.g. @get_modes and
  42. * @set_property) will typically be wrapped around and only be called
  43. * if the encoder is the currently selected one for the connector.
  44. */
  45. struct drm_encoder_slave_funcs {
  46. void (*set_config)(struct drm_encoder *encoder,
  47. void *params);
  48. void (*destroy)(struct drm_encoder *encoder);
  49. void (*dpms)(struct drm_encoder *encoder, int mode);
  50. void (*save)(struct drm_encoder *encoder);
  51. void (*restore)(struct drm_encoder *encoder);
  52. bool (*mode_fixup)(struct drm_encoder *encoder,
  53. const struct drm_display_mode *mode,
  54. struct drm_display_mode *adjusted_mode);
  55. int (*mode_valid)(struct drm_encoder *encoder,
  56. struct drm_display_mode *mode);
  57. void (*mode_set)(struct drm_encoder *encoder,
  58. struct drm_display_mode *mode,
  59. struct drm_display_mode *adjusted_mode);
  60. enum drm_connector_status (*detect)(struct drm_encoder *encoder,
  61. struct drm_connector *connector);
  62. int (*get_modes)(struct drm_encoder *encoder,
  63. struct drm_connector *connector);
  64. int (*create_resources)(struct drm_encoder *encoder,
  65. struct drm_connector *connector);
  66. int (*set_property)(struct drm_encoder *encoder,
  67. struct drm_connector *connector,
  68. struct drm_property *property,
  69. uint64_t val);
  70. };
  71. /**
  72. * struct drm_encoder_slave - Slave encoder struct
  73. * @base: DRM encoder object.
  74. * @slave_funcs: Slave encoder callbacks.
  75. * @slave_priv: Slave encoder private data.
  76. * @bus_priv: Bus specific data.
  77. *
  78. * A &drm_encoder_slave has two sets of callbacks, @slave_funcs and the
  79. * ones in @base. The former are never actually called by the common
  80. * CRTC code, it's just a convenience for splitting the encoder
  81. * functions in an upper, GPU-specific layer and a (hopefully)
  82. * GPU-agnostic lower layer: It's the GPU driver responsibility to
  83. * call the slave methods when appropriate.
  84. *
  85. * drm_i2c_encoder_init() provides a way to get an implementation of
  86. * this.
  87. */
  88. struct drm_encoder_slave {
  89. struct drm_encoder base;
  90. struct drm_encoder_slave_funcs *slave_funcs;
  91. void *slave_priv;
  92. void *bus_priv;
  93. };
  94. #define to_encoder_slave(x) container_of((x), struct drm_encoder_slave, base)
  95. int drm_i2c_encoder_init(struct drm_device *dev,
  96. struct drm_encoder_slave *encoder,
  97. struct i2c_adapter *adap,
  98. const struct i2c_board_info *info);
  99. /**
  100. * struct drm_i2c_encoder_driver
  101. *
  102. * Describes a device driver for an encoder connected to the GPU
  103. * through an I2C bus. In addition to the entry points in @i2c_driver
  104. * an @encoder_init function should be provided. It will be called to
  105. * give the driver an opportunity to allocate any per-encoder data
  106. * structures and to initialize the @slave_funcs and (optionally)
  107. * @slave_priv members of @encoder.
  108. */
  109. struct drm_i2c_encoder_driver {
  110. struct i2c_driver i2c_driver;
  111. int (*encoder_init)(struct i2c_client *client,
  112. struct drm_device *dev,
  113. struct drm_encoder_slave *encoder);
  114. };
  115. #define to_drm_i2c_encoder_driver(x) container_of((x), \
  116. struct drm_i2c_encoder_driver, \
  117. i2c_driver)
  118. /**
  119. * drm_i2c_encoder_get_client - Get the I2C client corresponding to an encoder
  120. */
  121. static inline struct i2c_client *drm_i2c_encoder_get_client(struct drm_encoder *encoder)
  122. {
  123. return (struct i2c_client *)to_encoder_slave(encoder)->bus_priv;
  124. }
  125. /**
  126. * drm_i2c_encoder_register - Register an I2C encoder driver
  127. * @owner: Module containing the driver.
  128. * @driver: Driver to be registered.
  129. */
  130. static inline int drm_i2c_encoder_register(struct module *owner,
  131. struct drm_i2c_encoder_driver *driver)
  132. {
  133. return i2c_register_driver(owner, &driver->i2c_driver);
  134. }
  135. /**
  136. * drm_i2c_encoder_unregister - Unregister an I2C encoder driver
  137. * @driver: Driver to be unregistered.
  138. */
  139. static inline void drm_i2c_encoder_unregister(struct drm_i2c_encoder_driver *driver)
  140. {
  141. i2c_del_driver(&driver->i2c_driver);
  142. }
  143. void drm_i2c_encoder_destroy(struct drm_encoder *encoder);
  144. /*
  145. * Wrapper fxns which can be plugged in to drm_encoder_helper_funcs:
  146. */
  147. void drm_i2c_encoder_dpms(struct drm_encoder *encoder, int mode);
  148. bool drm_i2c_encoder_mode_fixup(struct drm_encoder *encoder,
  149. const struct drm_display_mode *mode,
  150. struct drm_display_mode *adjusted_mode);
  151. void drm_i2c_encoder_prepare(struct drm_encoder *encoder);
  152. void drm_i2c_encoder_commit(struct drm_encoder *encoder);
  153. void drm_i2c_encoder_mode_set(struct drm_encoder *encoder,
  154. struct drm_display_mode *mode,
  155. struct drm_display_mode *adjusted_mode);
  156. enum drm_connector_status drm_i2c_encoder_detect(struct drm_encoder *encoder,
  157. struct drm_connector *connector);
  158. void drm_i2c_encoder_save(struct drm_encoder *encoder);
  159. void drm_i2c_encoder_restore(struct drm_encoder *encoder);
  160. #endif