intel_drv.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. /*
  2. * Copyright (c) 2006 Dave Airlie <airlied@linux.ie>
  3. * Copyright (c) 2007-2008 Intel Corporation
  4. * Jesse Barnes <jesse.barnes@intel.com>
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice (including the next
  14. * paragraph) shall be included in all copies or substantial portions of the
  15. * Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  20. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  23. * IN THE SOFTWARE.
  24. */
  25. #ifndef __INTEL_DRV_H__
  26. #define __INTEL_DRV_H__
  27. #include <linux/i2c.h>
  28. #include "i915_drv.h"
  29. #include "drm_crtc.h"
  30. #include "drm_crtc_helper.h"
  31. #include "drm_fb_helper.h"
  32. #define _wait_for(COND, MS, W) ({ \
  33. unsigned long timeout__ = jiffies + msecs_to_jiffies(MS); \
  34. int ret__ = 0; \
  35. while (! (COND)) { \
  36. if (time_after(jiffies, timeout__)) { \
  37. ret__ = -ETIMEDOUT; \
  38. break; \
  39. } \
  40. if (W && !in_dbg_master()) msleep(W); \
  41. } \
  42. ret__; \
  43. })
  44. #define wait_for(COND, MS) _wait_for(COND, MS, 1)
  45. #define wait_for_atomic(COND, MS) _wait_for(COND, MS, 0)
  46. #define MSLEEP(x) do { \
  47. if (in_dbg_master()) \
  48. mdelay(x); \
  49. else \
  50. msleep(x); \
  51. } while(0)
  52. #define KHz(x) (1000*x)
  53. #define MHz(x) KHz(1000*x)
  54. /*
  55. * Display related stuff
  56. */
  57. /* store information about an Ixxx DVO */
  58. /* The i830->i865 use multiple DVOs with multiple i2cs */
  59. /* the i915, i945 have a single sDVO i2c bus - which is different */
  60. #define MAX_OUTPUTS 6
  61. /* maximum connectors per crtcs in the mode set */
  62. #define INTELFB_CONN_LIMIT 4
  63. #define INTEL_I2C_BUS_DVO 1
  64. #define INTEL_I2C_BUS_SDVO 2
  65. /* these are outputs from the chip - integrated only
  66. external chips are via DVO or SDVO output */
  67. #define INTEL_OUTPUT_UNUSED 0
  68. #define INTEL_OUTPUT_ANALOG 1
  69. #define INTEL_OUTPUT_DVO 2
  70. #define INTEL_OUTPUT_SDVO 3
  71. #define INTEL_OUTPUT_LVDS 4
  72. #define INTEL_OUTPUT_TVOUT 5
  73. #define INTEL_OUTPUT_HDMI 6
  74. #define INTEL_OUTPUT_DISPLAYPORT 7
  75. #define INTEL_OUTPUT_EDP 8
  76. /* Intel Pipe Clone Bit */
  77. #define INTEL_HDMIB_CLONE_BIT 1
  78. #define INTEL_HDMIC_CLONE_BIT 2
  79. #define INTEL_HDMID_CLONE_BIT 3
  80. #define INTEL_HDMIE_CLONE_BIT 4
  81. #define INTEL_HDMIF_CLONE_BIT 5
  82. #define INTEL_SDVO_NON_TV_CLONE_BIT 6
  83. #define INTEL_SDVO_TV_CLONE_BIT 7
  84. #define INTEL_SDVO_LVDS_CLONE_BIT 8
  85. #define INTEL_ANALOG_CLONE_BIT 9
  86. #define INTEL_TV_CLONE_BIT 10
  87. #define INTEL_DP_B_CLONE_BIT 11
  88. #define INTEL_DP_C_CLONE_BIT 12
  89. #define INTEL_DP_D_CLONE_BIT 13
  90. #define INTEL_LVDS_CLONE_BIT 14
  91. #define INTEL_DVO_TMDS_CLONE_BIT 15
  92. #define INTEL_DVO_LVDS_CLONE_BIT 16
  93. #define INTEL_EDP_CLONE_BIT 17
  94. #define INTEL_DVO_CHIP_NONE 0
  95. #define INTEL_DVO_CHIP_LVDS 1
  96. #define INTEL_DVO_CHIP_TMDS 2
  97. #define INTEL_DVO_CHIP_TVOUT 4
  98. /* drm_display_mode->private_flags */
  99. #define INTEL_MODE_PIXEL_MULTIPLIER_SHIFT (0x0)
  100. #define INTEL_MODE_PIXEL_MULTIPLIER_MASK (0xf << INTEL_MODE_PIXEL_MULTIPLIER_SHIFT)
  101. static inline void
  102. intel_mode_set_pixel_multiplier(struct drm_display_mode *mode,
  103. int multiplier)
  104. {
  105. mode->clock *= multiplier;
  106. mode->private_flags |= multiplier;
  107. }
  108. static inline int
  109. intel_mode_get_pixel_multiplier(const struct drm_display_mode *mode)
  110. {
  111. return (mode->private_flags & INTEL_MODE_PIXEL_MULTIPLIER_MASK) >> INTEL_MODE_PIXEL_MULTIPLIER_SHIFT;
  112. }
  113. struct intel_framebuffer {
  114. struct drm_framebuffer base;
  115. struct drm_i915_gem_object *obj;
  116. };
  117. struct intel_fbdev {
  118. struct drm_fb_helper helper;
  119. struct intel_framebuffer ifb;
  120. struct list_head fbdev_list;
  121. struct drm_display_mode *our_mode;
  122. };
  123. struct intel_encoder {
  124. struct drm_encoder base;
  125. int type;
  126. bool load_detect_temp;
  127. bool needs_tv_clock;
  128. void (*hot_plug)(struct intel_encoder *);
  129. int crtc_mask;
  130. int clone_mask;
  131. };
  132. struct intel_connector {
  133. struct drm_connector base;
  134. struct intel_encoder *encoder;
  135. };
  136. struct intel_crtc {
  137. struct drm_crtc base;
  138. enum pipe pipe;
  139. enum plane plane;
  140. u8 lut_r[256], lut_g[256], lut_b[256];
  141. int dpms_mode;
  142. bool active; /* is the crtc on? independent of the dpms mode */
  143. bool busy; /* is scanout buffer being updated frequently? */
  144. struct timer_list idle_timer;
  145. bool lowfreq_avail;
  146. struct intel_overlay *overlay;
  147. struct intel_unpin_work *unpin_work;
  148. int fdi_lanes;
  149. struct drm_i915_gem_object *cursor_bo;
  150. uint32_t cursor_addr;
  151. int16_t cursor_x, cursor_y;
  152. int16_t cursor_width, cursor_height;
  153. bool cursor_visible;
  154. };
  155. #define to_intel_crtc(x) container_of(x, struct intel_crtc, base)
  156. #define to_intel_connector(x) container_of(x, struct intel_connector, base)
  157. #define to_intel_encoder(x) container_of(x, struct intel_encoder, base)
  158. #define to_intel_framebuffer(x) container_of(x, struct intel_framebuffer, base)
  159. #define DIP_TYPE_AVI 0x82
  160. #define DIP_VERSION_AVI 0x2
  161. #define DIP_LEN_AVI 13
  162. struct dip_infoframe {
  163. uint8_t type; /* HB0 */
  164. uint8_t ver; /* HB1 */
  165. uint8_t len; /* HB2 - body len, not including checksum */
  166. uint8_t ecc; /* Header ECC */
  167. uint8_t checksum; /* PB0 */
  168. union {
  169. struct {
  170. /* PB1 - Y 6:5, A 4:4, B 3:2, S 1:0 */
  171. uint8_t Y_A_B_S;
  172. /* PB2 - C 7:6, M 5:4, R 3:0 */
  173. uint8_t C_M_R;
  174. /* PB3 - ITC 7:7, EC 6:4, Q 3:2, SC 1:0 */
  175. uint8_t ITC_EC_Q_SC;
  176. /* PB4 - VIC 6:0 */
  177. uint8_t VIC;
  178. /* PB5 - PR 3:0 */
  179. uint8_t PR;
  180. /* PB6 to PB13 */
  181. uint16_t top_bar_end;
  182. uint16_t bottom_bar_start;
  183. uint16_t left_bar_end;
  184. uint16_t right_bar_start;
  185. } avi;
  186. uint8_t payload[27];
  187. } __attribute__ ((packed)) body;
  188. } __attribute__((packed));
  189. static inline struct drm_crtc *
  190. intel_get_crtc_for_pipe(struct drm_device *dev, int pipe)
  191. {
  192. struct drm_i915_private *dev_priv = dev->dev_private;
  193. return dev_priv->pipe_to_crtc_mapping[pipe];
  194. }
  195. struct intel_unpin_work {
  196. struct work_struct work;
  197. struct drm_device *dev;
  198. struct drm_i915_gem_object *old_fb_obj;
  199. struct drm_i915_gem_object *pending_flip_obj;
  200. struct drm_pending_vblank_event *event;
  201. int pending;
  202. bool enable_stall_check;
  203. };
  204. int intel_ddc_get_modes(struct drm_connector *c, struct i2c_adapter *adapter);
  205. extern bool intel_ddc_probe(struct intel_encoder *intel_encoder, int ddc_bus);
  206. extern void intel_crt_init(struct drm_device *dev);
  207. extern void intel_hdmi_init(struct drm_device *dev, int sdvox_reg);
  208. void intel_dip_infoframe_csum(struct dip_infoframe *avi_if);
  209. extern bool intel_sdvo_init(struct drm_device *dev, int output_device);
  210. extern void intel_dvo_init(struct drm_device *dev);
  211. extern void intel_tv_init(struct drm_device *dev);
  212. extern void intel_mark_busy(struct drm_device *dev,
  213. struct drm_i915_gem_object *obj);
  214. extern bool intel_lvds_init(struct drm_device *dev);
  215. extern void intel_dp_init(struct drm_device *dev, int dp_reg);
  216. void
  217. intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode,
  218. struct drm_display_mode *adjusted_mode);
  219. extern bool intel_dpd_is_edp(struct drm_device *dev);
  220. extern void intel_edp_link_config (struct intel_encoder *, int *, int *);
  221. extern bool intel_encoder_is_pch_edp(struct drm_encoder *encoder);
  222. /* intel_panel.c */
  223. extern void intel_fixed_panel_mode(struct drm_display_mode *fixed_mode,
  224. struct drm_display_mode *adjusted_mode);
  225. extern void intel_pch_panel_fitting(struct drm_device *dev,
  226. int fitting_mode,
  227. struct drm_display_mode *mode,
  228. struct drm_display_mode *adjusted_mode);
  229. extern u32 intel_panel_get_max_backlight(struct drm_device *dev);
  230. extern u32 intel_panel_get_backlight(struct drm_device *dev);
  231. extern void intel_panel_set_backlight(struct drm_device *dev, u32 level);
  232. extern void intel_panel_setup_backlight(struct drm_device *dev);
  233. extern void intel_panel_enable_backlight(struct drm_device *dev);
  234. extern void intel_panel_disable_backlight(struct drm_device *dev);
  235. extern void intel_crtc_load_lut(struct drm_crtc *crtc);
  236. extern void intel_encoder_prepare (struct drm_encoder *encoder);
  237. extern void intel_encoder_commit (struct drm_encoder *encoder);
  238. extern void intel_encoder_destroy(struct drm_encoder *encoder);
  239. static inline struct intel_encoder *intel_attached_encoder(struct drm_connector *connector)
  240. {
  241. return to_intel_connector(connector)->encoder;
  242. }
  243. extern void intel_connector_attach_encoder(struct intel_connector *connector,
  244. struct intel_encoder *encoder);
  245. extern struct drm_encoder *intel_best_encoder(struct drm_connector *connector);
  246. extern struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
  247. struct drm_crtc *crtc);
  248. int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
  249. struct drm_file *file_priv);
  250. extern void intel_wait_for_vblank(struct drm_device *dev, int pipe);
  251. extern void intel_wait_for_pipe_off(struct drm_device *dev, int pipe);
  252. extern struct drm_crtc *intel_get_load_detect_pipe(struct intel_encoder *intel_encoder,
  253. struct drm_connector *connector,
  254. struct drm_display_mode *mode,
  255. int *dpms_mode);
  256. extern void intel_release_load_detect_pipe(struct intel_encoder *intel_encoder,
  257. struct drm_connector *connector,
  258. int dpms_mode);
  259. extern struct drm_connector* intel_sdvo_find(struct drm_device *dev, int sdvoB);
  260. extern int intel_sdvo_supports_hotplug(struct drm_connector *connector);
  261. extern void intel_sdvo_set_hotplug(struct drm_connector *connector, int enable);
  262. extern void intelfb_restore(void);
  263. extern void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
  264. u16 blue, int regno);
  265. extern void intel_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
  266. u16 *blue, int regno);
  267. extern void intel_enable_clock_gating(struct drm_device *dev);
  268. extern void intel_disable_clock_gating(struct drm_device *dev);
  269. extern void ironlake_enable_drps(struct drm_device *dev);
  270. extern void ironlake_disable_drps(struct drm_device *dev);
  271. extern void gen6_enable_rps(struct drm_i915_private *dev_priv);
  272. extern void gen6_disable_rps(struct drm_device *dev);
  273. extern void intel_init_emon(struct drm_device *dev);
  274. extern int intel_pin_and_fence_fb_obj(struct drm_device *dev,
  275. struct drm_i915_gem_object *obj,
  276. struct intel_ring_buffer *pipelined);
  277. extern int intel_framebuffer_init(struct drm_device *dev,
  278. struct intel_framebuffer *ifb,
  279. struct drm_mode_fb_cmd *mode_cmd,
  280. struct drm_i915_gem_object *obj);
  281. extern int intel_fbdev_init(struct drm_device *dev);
  282. extern void intel_fbdev_fini(struct drm_device *dev);
  283. extern void intel_prepare_page_flip(struct drm_device *dev, int plane);
  284. extern void intel_finish_page_flip(struct drm_device *dev, int pipe);
  285. extern void intel_finish_page_flip_plane(struct drm_device *dev, int plane);
  286. extern void intel_setup_overlay(struct drm_device *dev);
  287. extern void intel_cleanup_overlay(struct drm_device *dev);
  288. extern int intel_overlay_switch_off(struct intel_overlay *overlay,
  289. bool interruptible);
  290. extern int intel_overlay_put_image(struct drm_device *dev, void *data,
  291. struct drm_file *file_priv);
  292. extern int intel_overlay_attrs(struct drm_device *dev, void *data,
  293. struct drm_file *file_priv);
  294. extern void intel_fb_output_poll_changed(struct drm_device *dev);
  295. #endif /* __INTEL_DRV_H__ */