intel_drv.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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_drm.h"
  29. #include "i915_drv.h"
  30. #include "drm_crtc.h"
  31. #include "drm_crtc_helper.h"
  32. #include "drm_fb_helper.h"
  33. #define _wait_for(COND, MS, W) ({ \
  34. unsigned long timeout__ = jiffies + msecs_to_jiffies(MS); \
  35. int ret__ = 0; \
  36. while (!(COND)) { \
  37. if (time_after(jiffies, timeout__)) { \
  38. ret__ = -ETIMEDOUT; \
  39. break; \
  40. } \
  41. if (W && drm_can_sleep()) msleep(W); \
  42. } \
  43. ret__; \
  44. })
  45. #define wait_for(COND, MS) _wait_for(COND, MS, 1)
  46. #define wait_for_atomic(COND, MS) _wait_for(COND, MS, 0)
  47. #define KHz(x) (1000*x)
  48. #define MHz(x) KHz(1000*x)
  49. /*
  50. * Display related stuff
  51. */
  52. /* store information about an Ixxx DVO */
  53. /* The i830->i865 use multiple DVOs with multiple i2cs */
  54. /* the i915, i945 have a single sDVO i2c bus - which is different */
  55. #define MAX_OUTPUTS 6
  56. /* maximum connectors per crtcs in the mode set */
  57. #define INTELFB_CONN_LIMIT 4
  58. #define INTEL_I2C_BUS_DVO 1
  59. #define INTEL_I2C_BUS_SDVO 2
  60. /* these are outputs from the chip - integrated only
  61. external chips are via DVO or SDVO output */
  62. #define INTEL_OUTPUT_UNUSED 0
  63. #define INTEL_OUTPUT_ANALOG 1
  64. #define INTEL_OUTPUT_DVO 2
  65. #define INTEL_OUTPUT_SDVO 3
  66. #define INTEL_OUTPUT_LVDS 4
  67. #define INTEL_OUTPUT_TVOUT 5
  68. #define INTEL_OUTPUT_HDMI 6
  69. #define INTEL_OUTPUT_DISPLAYPORT 7
  70. #define INTEL_OUTPUT_EDP 8
  71. /* Intel Pipe Clone Bit */
  72. #define INTEL_HDMIB_CLONE_BIT 1
  73. #define INTEL_HDMIC_CLONE_BIT 2
  74. #define INTEL_HDMID_CLONE_BIT 3
  75. #define INTEL_HDMIE_CLONE_BIT 4
  76. #define INTEL_HDMIF_CLONE_BIT 5
  77. #define INTEL_SDVO_NON_TV_CLONE_BIT 6
  78. #define INTEL_SDVO_TV_CLONE_BIT 7
  79. #define INTEL_SDVO_LVDS_CLONE_BIT 8
  80. #define INTEL_ANALOG_CLONE_BIT 9
  81. #define INTEL_TV_CLONE_BIT 10
  82. #define INTEL_DP_B_CLONE_BIT 11
  83. #define INTEL_DP_C_CLONE_BIT 12
  84. #define INTEL_DP_D_CLONE_BIT 13
  85. #define INTEL_LVDS_CLONE_BIT 14
  86. #define INTEL_DVO_TMDS_CLONE_BIT 15
  87. #define INTEL_DVO_LVDS_CLONE_BIT 16
  88. #define INTEL_EDP_CLONE_BIT 17
  89. #define INTEL_DVO_CHIP_NONE 0
  90. #define INTEL_DVO_CHIP_LVDS 1
  91. #define INTEL_DVO_CHIP_TMDS 2
  92. #define INTEL_DVO_CHIP_TVOUT 4
  93. /* drm_display_mode->private_flags */
  94. #define INTEL_MODE_PIXEL_MULTIPLIER_SHIFT (0x0)
  95. #define INTEL_MODE_PIXEL_MULTIPLIER_MASK (0xf << INTEL_MODE_PIXEL_MULTIPLIER_SHIFT)
  96. #define INTEL_MODE_DP_FORCE_6BPC (0x10)
  97. /* This flag must be set by the encoder's mode_fixup if it changes the crtc
  98. * timings in the mode to prevent the crtc fixup from overwriting them.
  99. * Currently only lvds needs that. */
  100. #define INTEL_MODE_CRTC_TIMINGS_SET (0x20)
  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 needs_tv_clock;
  127. void (*hot_plug)(struct intel_encoder *);
  128. int crtc_mask;
  129. int clone_mask;
  130. };
  131. struct intel_connector {
  132. struct drm_connector base;
  133. struct intel_encoder *encoder;
  134. };
  135. struct intel_crtc {
  136. struct drm_crtc base;
  137. enum pipe pipe;
  138. enum plane plane;
  139. u8 lut_r[256], lut_g[256], lut_b[256];
  140. int dpms_mode;
  141. bool active; /* is the crtc on? independent of the dpms mode */
  142. bool busy; /* is scanout buffer being updated frequently? */
  143. struct timer_list idle_timer;
  144. bool lowfreq_avail;
  145. struct intel_overlay *overlay;
  146. struct intel_unpin_work *unpin_work;
  147. int fdi_lanes;
  148. struct drm_i915_gem_object *cursor_bo;
  149. uint32_t cursor_addr;
  150. int16_t cursor_x, cursor_y;
  151. int16_t cursor_width, cursor_height;
  152. bool cursor_visible;
  153. unsigned int bpp;
  154. bool no_pll; /* tertiary pipe for IVB */
  155. bool use_pll_a;
  156. };
  157. struct intel_plane {
  158. struct drm_plane base;
  159. enum pipe pipe;
  160. struct drm_i915_gem_object *obj;
  161. bool primary_disabled;
  162. int max_downscale;
  163. u32 lut_r[1024], lut_g[1024], lut_b[1024];
  164. void (*update_plane)(struct drm_plane *plane,
  165. struct drm_framebuffer *fb,
  166. struct drm_i915_gem_object *obj,
  167. int crtc_x, int crtc_y,
  168. unsigned int crtc_w, unsigned int crtc_h,
  169. uint32_t x, uint32_t y,
  170. uint32_t src_w, uint32_t src_h);
  171. void (*disable_plane)(struct drm_plane *plane);
  172. int (*update_colorkey)(struct drm_plane *plane,
  173. struct drm_intel_sprite_colorkey *key);
  174. void (*get_colorkey)(struct drm_plane *plane,
  175. struct drm_intel_sprite_colorkey *key);
  176. };
  177. #define to_intel_crtc(x) container_of(x, struct intel_crtc, base)
  178. #define to_intel_connector(x) container_of(x, struct intel_connector, base)
  179. #define to_intel_encoder(x) container_of(x, struct intel_encoder, base)
  180. #define to_intel_framebuffer(x) container_of(x, struct intel_framebuffer, base)
  181. #define to_intel_plane(x) container_of(x, struct intel_plane, base)
  182. #define DIP_HEADER_SIZE 5
  183. #define DIP_TYPE_AVI 0x82
  184. #define DIP_VERSION_AVI 0x2
  185. #define DIP_LEN_AVI 13
  186. #define DIP_TYPE_SPD 0x83
  187. #define DIP_VERSION_SPD 0x1
  188. #define DIP_LEN_SPD 25
  189. #define DIP_SPD_UNKNOWN 0
  190. #define DIP_SPD_DSTB 0x1
  191. #define DIP_SPD_DVDP 0x2
  192. #define DIP_SPD_DVHS 0x3
  193. #define DIP_SPD_HDDVR 0x4
  194. #define DIP_SPD_DVC 0x5
  195. #define DIP_SPD_DSC 0x6
  196. #define DIP_SPD_VCD 0x7
  197. #define DIP_SPD_GAME 0x8
  198. #define DIP_SPD_PC 0x9
  199. #define DIP_SPD_BD 0xa
  200. #define DIP_SPD_SCD 0xb
  201. struct dip_infoframe {
  202. uint8_t type; /* HB0 */
  203. uint8_t ver; /* HB1 */
  204. uint8_t len; /* HB2 - body len, not including checksum */
  205. uint8_t ecc; /* Header ECC */
  206. uint8_t checksum; /* PB0 */
  207. union {
  208. struct {
  209. /* PB1 - Y 6:5, A 4:4, B 3:2, S 1:0 */
  210. uint8_t Y_A_B_S;
  211. /* PB2 - C 7:6, M 5:4, R 3:0 */
  212. uint8_t C_M_R;
  213. /* PB3 - ITC 7:7, EC 6:4, Q 3:2, SC 1:0 */
  214. uint8_t ITC_EC_Q_SC;
  215. /* PB4 - VIC 6:0 */
  216. uint8_t VIC;
  217. /* PB5 - PR 3:0 */
  218. uint8_t PR;
  219. /* PB6 to PB13 */
  220. uint16_t top_bar_end;
  221. uint16_t bottom_bar_start;
  222. uint16_t left_bar_end;
  223. uint16_t right_bar_start;
  224. } __attribute__ ((packed)) avi;
  225. struct {
  226. uint8_t vn[8];
  227. uint8_t pd[16];
  228. uint8_t sdi;
  229. } __attribute__ ((packed)) spd;
  230. uint8_t payload[27];
  231. } __attribute__ ((packed)) body;
  232. } __attribute__((packed));
  233. static inline struct drm_crtc *
  234. intel_get_crtc_for_pipe(struct drm_device *dev, int pipe)
  235. {
  236. struct drm_i915_private *dev_priv = dev->dev_private;
  237. return dev_priv->pipe_to_crtc_mapping[pipe];
  238. }
  239. static inline struct drm_crtc *
  240. intel_get_crtc_for_plane(struct drm_device *dev, int plane)
  241. {
  242. struct drm_i915_private *dev_priv = dev->dev_private;
  243. return dev_priv->plane_to_crtc_mapping[plane];
  244. }
  245. struct intel_unpin_work {
  246. struct work_struct work;
  247. struct drm_device *dev;
  248. struct drm_i915_gem_object *old_fb_obj;
  249. struct drm_i915_gem_object *pending_flip_obj;
  250. struct drm_pending_vblank_event *event;
  251. atomic_t pending;
  252. #define INTEL_FLIP_INACTIVE 0
  253. #define INTEL_FLIP_PENDING 1
  254. #define INTEL_FLIP_COMPLETE 2
  255. bool enable_stall_check;
  256. };
  257. struct intel_fbc_work {
  258. struct delayed_work work;
  259. struct drm_crtc *crtc;
  260. struct drm_framebuffer *fb;
  261. int interval;
  262. };
  263. int intel_connector_update_modes(struct drm_connector *connector,
  264. struct edid *edid);
  265. int intel_ddc_get_modes(struct drm_connector *c, struct i2c_adapter *adapter);
  266. extern bool intel_ddc_probe(struct intel_encoder *intel_encoder, int ddc_bus);
  267. extern void intel_attach_force_audio_property(struct drm_connector *connector);
  268. extern void intel_attach_broadcast_rgb_property(struct drm_connector *connector);
  269. extern void intel_crt_init(struct drm_device *dev);
  270. extern void intel_hdmi_init(struct drm_device *dev, int sdvox_reg);
  271. void intel_dip_infoframe_csum(struct dip_infoframe *avi_if);
  272. extern bool intel_sdvo_init(struct drm_device *dev, int output_device);
  273. extern void intel_dvo_init(struct drm_device *dev);
  274. extern void intel_tv_init(struct drm_device *dev);
  275. extern void intel_mark_busy(struct drm_device *dev,
  276. struct drm_i915_gem_object *obj);
  277. extern bool intel_lvds_init(struct drm_device *dev);
  278. extern void intel_dp_init(struct drm_device *dev, int dp_reg);
  279. void
  280. intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode,
  281. struct drm_display_mode *adjusted_mode);
  282. extern bool intel_dpd_is_edp(struct drm_device *dev);
  283. extern void intel_edp_link_config(struct intel_encoder *, int *, int *);
  284. extern bool intel_encoder_is_pch_edp(struct drm_encoder *encoder);
  285. extern int intel_plane_init(struct drm_device *dev, enum pipe pipe);
  286. /* intel_panel.c */
  287. extern void intel_fixed_panel_mode(struct drm_display_mode *fixed_mode,
  288. struct drm_display_mode *adjusted_mode);
  289. extern void intel_pch_panel_fitting(struct drm_device *dev,
  290. int fitting_mode,
  291. struct drm_display_mode *mode,
  292. struct drm_display_mode *adjusted_mode);
  293. extern u32 intel_panel_get_max_backlight(struct drm_device *dev);
  294. extern u32 intel_panel_get_backlight(struct drm_device *dev);
  295. extern void intel_panel_set_backlight(struct drm_device *dev, u32 level);
  296. extern int intel_panel_setup_backlight(struct drm_device *dev);
  297. extern void intel_panel_enable_backlight(struct drm_device *dev);
  298. extern void intel_panel_disable_backlight(struct drm_device *dev);
  299. extern void intel_panel_destroy_backlight(struct drm_device *dev);
  300. extern enum drm_connector_status intel_panel_detect(struct drm_device *dev);
  301. extern void intel_crtc_load_lut(struct drm_crtc *crtc);
  302. extern void intel_encoder_prepare(struct drm_encoder *encoder);
  303. extern void intel_encoder_commit(struct drm_encoder *encoder);
  304. extern void intel_encoder_destroy(struct drm_encoder *encoder);
  305. static inline struct intel_encoder *intel_attached_encoder(struct drm_connector *connector)
  306. {
  307. return to_intel_connector(connector)->encoder;
  308. }
  309. extern void intel_connector_attach_encoder(struct intel_connector *connector,
  310. struct intel_encoder *encoder);
  311. extern struct drm_encoder *intel_best_encoder(struct drm_connector *connector);
  312. extern struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
  313. struct drm_crtc *crtc);
  314. int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
  315. struct drm_file *file_priv);
  316. extern void intel_wait_for_vblank(struct drm_device *dev, int pipe);
  317. extern void intel_wait_for_pipe_off(struct drm_device *dev, int pipe);
  318. struct intel_load_detect_pipe {
  319. struct drm_framebuffer *release_fb;
  320. bool load_detect_temp;
  321. int dpms_mode;
  322. };
  323. extern bool intel_get_load_detect_pipe(struct intel_encoder *intel_encoder,
  324. struct drm_connector *connector,
  325. struct drm_display_mode *mode,
  326. struct intel_load_detect_pipe *old);
  327. extern void intel_release_load_detect_pipe(struct intel_encoder *intel_encoder,
  328. struct drm_connector *connector,
  329. struct intel_load_detect_pipe *old);
  330. extern void intelfb_restore(void);
  331. extern void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
  332. u16 blue, int regno);
  333. extern void intel_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
  334. u16 *blue, int regno);
  335. extern void intel_enable_clock_gating(struct drm_device *dev);
  336. extern void ironlake_enable_drps(struct drm_device *dev);
  337. extern void ironlake_disable_drps(struct drm_device *dev);
  338. extern void gen6_enable_rps(struct drm_i915_private *dev_priv);
  339. extern void gen6_update_ring_freq(struct drm_i915_private *dev_priv);
  340. extern void gen6_disable_rps(struct drm_device *dev);
  341. extern void intel_init_emon(struct drm_device *dev);
  342. extern int intel_pin_and_fence_fb_obj(struct drm_device *dev,
  343. struct drm_i915_gem_object *obj,
  344. struct intel_ring_buffer *pipelined);
  345. extern void intel_unpin_fb_obj(struct drm_i915_gem_object *obj);
  346. extern int intel_framebuffer_init(struct drm_device *dev,
  347. struct intel_framebuffer *ifb,
  348. struct drm_mode_fb_cmd2 *mode_cmd,
  349. struct drm_i915_gem_object *obj);
  350. extern int intel_fbdev_init(struct drm_device *dev);
  351. extern void intel_fbdev_fini(struct drm_device *dev);
  352. extern void intel_fbdev_set_suspend(struct drm_device *dev, int state);
  353. extern void intel_prepare_page_flip(struct drm_device *dev, int plane);
  354. extern void intel_finish_page_flip(struct drm_device *dev, int pipe);
  355. extern void intel_finish_page_flip_plane(struct drm_device *dev, int plane);
  356. extern void intel_setup_overlay(struct drm_device *dev);
  357. extern void intel_cleanup_overlay(struct drm_device *dev);
  358. extern int intel_overlay_switch_off(struct intel_overlay *overlay);
  359. extern int intel_overlay_put_image(struct drm_device *dev, void *data,
  360. struct drm_file *file_priv);
  361. extern int intel_overlay_attrs(struct drm_device *dev, void *data,
  362. struct drm_file *file_priv);
  363. extern void intel_fb_output_poll_changed(struct drm_device *dev);
  364. extern void intel_fb_restore_mode(struct drm_device *dev);
  365. extern void assert_pipe(struct drm_i915_private *dev_priv, enum pipe pipe,
  366. bool state);
  367. #define assert_pipe_enabled(d, p) assert_pipe(d, p, true)
  368. #define assert_pipe_disabled(d, p) assert_pipe(d, p, false)
  369. extern void intel_init_clock_gating(struct drm_device *dev);
  370. extern void intel_write_eld(struct drm_encoder *encoder,
  371. struct drm_display_mode *mode);
  372. extern void intel_cpt_verify_modeset(struct drm_device *dev, int pipe);
  373. /* For use by IVB LP watermark workaround in intel_sprite.c */
  374. extern void sandybridge_update_wm(struct drm_device *dev);
  375. extern void intel_update_sprite_watermarks(struct drm_device *dev, int pipe,
  376. uint32_t sprite_width,
  377. int pixel_size);
  378. extern int intel_sprite_set_colorkey(struct drm_device *dev, void *data,
  379. struct drm_file *file_priv);
  380. extern int intel_sprite_get_colorkey(struct drm_device *dev, void *data,
  381. struct drm_file *file_priv);
  382. #endif /* __INTEL_DRV_H__ */