drm_encoder_slave.h 7.4 KB

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