1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Copyright (c) 2009-2011, Intel Corporation. 4 */ 5 6 #ifndef __INTEL_DRV_H__ 7 #define __INTEL_DRV_H__ 8 9 #include <linux/i2c.h> 10 #include <linux/i2c-algo-bit.h> 11 #include <drm/drm_crtc.h> 12 #include <drm/drm_crtc_helper.h> 13 #include <drm/drm_encoder.h> 14 #include <drm/drm_probe_helper.h> 15 #include <drm/drm_vblank.h> 16 #include <linux/gpio.h> 17 #include "gma_display.h" 18 19 /* 20 * Display related stuff 21 */ 22 23 /* maximum connectors per crtcs in the mode set */ 24 #define INTELFB_CONN_LIMIT 4 25 26 /* Intel Pipe Clone Bit */ 27 #define INTEL_HDMIB_CLONE_BIT 1 28 #define INTEL_HDMIC_CLONE_BIT 2 29 #define INTEL_HDMID_CLONE_BIT 3 30 #define INTEL_HDMIE_CLONE_BIT 4 31 #define INTEL_HDMIF_CLONE_BIT 5 32 #define INTEL_SDVO_NON_TV_CLONE_BIT 6 33 #define INTEL_SDVO_TV_CLONE_BIT 7 34 #define INTEL_SDVO_LVDS_CLONE_BIT 8 35 #define INTEL_ANALOG_CLONE_BIT 9 36 #define INTEL_TV_CLONE_BIT 10 37 #define INTEL_DP_B_CLONE_BIT 11 38 #define INTEL_DP_C_CLONE_BIT 12 39 #define INTEL_DP_D_CLONE_BIT 13 40 #define INTEL_LVDS_CLONE_BIT 14 41 #define INTEL_DVO_TMDS_CLONE_BIT 15 42 #define INTEL_DVO_LVDS_CLONE_BIT 16 43 #define INTEL_EDP_CLONE_BIT 17 44 45 /* these are outputs from the chip - integrated only 46 * external chips are via DVO or SDVO output */ 47 #define INTEL_OUTPUT_UNUSED 0 48 #define INTEL_OUTPUT_ANALOG 1 49 #define INTEL_OUTPUT_DVO 2 50 #define INTEL_OUTPUT_SDVO 3 51 #define INTEL_OUTPUT_LVDS 4 52 #define INTEL_OUTPUT_TVOUT 5 53 #define INTEL_OUTPUT_HDMI 6 54 #define INTEL_OUTPUT_MIPI 7 55 #define INTEL_OUTPUT_MIPI2 8 56 #define INTEL_OUTPUT_DISPLAYPORT 9 57 #define INTEL_OUTPUT_EDP 10 58 59 /* 60 * Hold information useally put on the device driver privates here, 61 * since it needs to be shared across multiple of devices drivers privates. 62 */ 63 struct psb_intel_mode_device { 64 65 /* 66 * Abstracted memory manager operations 67 */ 68 size_t(*bo_offset) (struct drm_device *dev, void *bo); 69 70 /* 71 * LVDS info 72 */ 73 int backlight_duty_cycle; /* restore backlight to this value */ 74 bool panel_wants_dither; 75 struct drm_display_mode *panel_fixed_mode; 76 struct drm_display_mode *panel_fixed_mode2; 77 struct drm_display_mode *vbt_mode; /* if any */ 78 79 uint32_t saveBLC_PWM_CTL; 80 }; 81 82 struct psb_intel_i2c_chan { 83 /* for getting at dev. private (mmio etc.) */ 84 struct drm_device *drm_dev; 85 u32 reg; /* GPIO reg */ 86 struct i2c_adapter adapter; 87 struct i2c_algo_bit_data algo; 88 u8 slave_addr; 89 }; 90 91 struct gma_encoder { 92 struct drm_encoder base; 93 int type; 94 bool needs_tv_clock; 95 void (*hot_plug)(struct gma_encoder *); 96 int crtc_mask; 97 int clone_mask; 98 u32 ddi_select; /* Channel info */ 99 #define DDI0_SELECT 0x01 100 #define DDI1_SELECT 0x02 101 #define DP_MASK 0x8000 102 #define DDI_MASK 0x03 103 void *dev_priv; /* For sdvo_priv, lvds_priv, etc... */ 104 105 /* FIXME: Either make SDVO and LVDS store it's i2c here or give CDV it's 106 own set of output privates */ 107 struct psb_intel_i2c_chan *i2c_bus; 108 struct psb_intel_i2c_chan *ddc_bus; 109 }; 110 111 struct gma_connector { 112 struct drm_connector base; 113 struct gma_encoder *encoder; 114 115 void (*save)(struct drm_connector *connector); 116 void (*restore)(struct drm_connector *connector); 117 }; 118 119 struct psb_intel_crtc_state { 120 uint32_t saveDSPCNTR; 121 uint32_t savePIPECONF; 122 uint32_t savePIPESRC; 123 uint32_t saveDPLL; 124 uint32_t saveFP0; 125 uint32_t saveFP1; 126 uint32_t saveHTOTAL; 127 uint32_t saveHBLANK; 128 uint32_t saveHSYNC; 129 uint32_t saveVTOTAL; 130 uint32_t saveVBLANK; 131 uint32_t saveVSYNC; 132 uint32_t saveDSPSTRIDE; 133 uint32_t saveDSPSIZE; 134 uint32_t saveDSPPOS; 135 uint32_t saveDSPBASE; 136 uint32_t savePalette[256]; 137 }; 138 139 struct gma_crtc { 140 struct drm_crtc base; 141 int pipe; 142 int plane; 143 uint32_t cursor_addr; 144 struct gtt_range *cursor_gt; 145 u8 lut_adj[256]; 146 struct psb_intel_framebuffer *fbdev_fb; 147 /* a mode_set for fbdev users on this crtc */ 148 struct drm_mode_set mode_set; 149 150 /* GEM object that holds our cursor */ 151 struct drm_gem_object *cursor_obj; 152 153 struct drm_display_mode saved_mode; 154 struct drm_display_mode saved_adjusted_mode; 155 156 struct psb_intel_mode_device *mode_dev; 157 158 /*crtc mode setting flags*/ 159 u32 mode_flags; 160 161 bool active; 162 163 /* Saved Crtc HW states */ 164 struct psb_intel_crtc_state *crtc_state; 165 166 const struct gma_clock_funcs *clock_funcs; 167 168 struct drm_pending_vblank_event *page_flip_event; 169 }; 170 171 #define to_gma_crtc(x) \ 172 container_of(x, struct gma_crtc, base) 173 #define to_gma_connector(x) \ 174 container_of(x, struct gma_connector, base) 175 #define to_gma_encoder(x) \ 176 container_of(x, struct gma_encoder, base) 177 #define to_psb_intel_framebuffer(x) \ 178 container_of(x, struct psb_intel_framebuffer, base) 179 180 struct psb_intel_i2c_chan *psb_intel_i2c_create(struct drm_device *dev, 181 const u32 reg, const char *name); 182 void psb_intel_i2c_destroy(struct psb_intel_i2c_chan *chan); 183 int psb_intel_ddc_get_modes(struct drm_connector *connector, 184 struct i2c_adapter *adapter); 185 extern bool psb_intel_ddc_probe(struct i2c_adapter *adapter); 186 187 extern void psb_intel_crtc_init(struct drm_device *dev, int pipe, 188 struct psb_intel_mode_device *mode_dev); 189 extern void psb_intel_crt_init(struct drm_device *dev); 190 extern bool psb_intel_sdvo_init(struct drm_device *dev, int output_device); 191 extern void psb_intel_dvo_init(struct drm_device *dev); 192 extern void psb_intel_tv_init(struct drm_device *dev); 193 extern void psb_intel_lvds_init(struct drm_device *dev, 194 struct psb_intel_mode_device *mode_dev); 195 extern void psb_intel_lvds_set_brightness(struct drm_device *dev, int level); 196 extern void oaktrail_lvds_init(struct drm_device *dev, 197 struct psb_intel_mode_device *mode_dev); 198 extern void oaktrail_wait_for_INTR_PKT_SENT(struct drm_device *dev); 199 extern void oaktrail_dsi_init(struct drm_device *dev, 200 struct psb_intel_mode_device *mode_dev); 201 extern void oaktrail_lvds_i2c_init(struct drm_encoder *encoder); 202 extern void mid_dsi_init(struct drm_device *dev, 203 struct psb_intel_mode_device *mode_dev, int dsi_num); 204 205 extern struct drm_encoder *gma_best_encoder(struct drm_connector *connector); 206 extern void gma_connector_attach_encoder(struct gma_connector *connector, 207 struct gma_encoder *encoder); 208 209 static inline struct gma_encoder *gma_attached_encoder( 210 struct drm_connector *connector) 211 { 212 return to_gma_connector(connector)->encoder; 213 } 214 215 extern struct drm_display_mode *psb_intel_crtc_mode_get(struct drm_device *dev, 216 struct drm_crtc *crtc); 217 extern struct drm_crtc *psb_intel_get_crtc_from_pipe(struct drm_device *dev, 218 int pipe); 219 extern struct drm_connector *psb_intel_sdvo_find(struct drm_device *dev, 220 int sdvoB); 221 extern int psb_intel_sdvo_supports_hotplug(struct drm_connector *connector); 222 extern void psb_intel_sdvo_set_hotplug(struct drm_connector *connector, 223 int enable); 224 extern int intelfb_probe(struct drm_device *dev); 225 extern int intelfb_remove(struct drm_device *dev, 226 struct drm_framebuffer *fb); 227 extern bool psb_intel_lvds_mode_fixup(struct drm_encoder *encoder, 228 const struct drm_display_mode *mode, 229 struct drm_display_mode *adjusted_mode); 230 extern enum drm_mode_status psb_intel_lvds_mode_valid(struct drm_connector *connector, 231 struct drm_display_mode *mode); 232 extern int psb_intel_lvds_set_property(struct drm_connector *connector, 233 struct drm_property *property, 234 uint64_t value); 235 extern void psb_intel_lvds_destroy(struct drm_connector *connector); 236 237 /* intel_gmbus.c */ 238 extern void gma_intel_i2c_reset(struct drm_device *dev); 239 extern int gma_intel_setup_gmbus(struct drm_device *dev); 240 extern void gma_intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed); 241 extern void gma_intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit); 242 extern void gma_intel_teardown_gmbus(struct drm_device *dev); 243 244 /* DP support */ 245 extern void cdv_intel_dp_init(struct drm_device *dev, struct psb_intel_mode_device *mode_dev, int output_reg); 246 extern void cdv_intel_dp_set_m_n(struct drm_crtc *crtc, 247 struct drm_display_mode *mode, 248 struct drm_display_mode *adjusted_mode); 249 250 extern void psb_intel_attach_force_audio_property(struct drm_connector *connector); 251 extern void psb_intel_attach_broadcast_rgb_property(struct drm_connector *connector); 252 253 extern int cdv_sb_read(struct drm_device *dev, u32 reg, u32 *val); 254 extern int cdv_sb_write(struct drm_device *dev, u32 reg, u32 val); 255 extern void cdv_sb_reset(struct drm_device *dev); 256 257 extern void cdv_intel_attach_force_audio_property(struct drm_connector *connector); 258 extern void cdv_intel_attach_broadcast_rgb_property(struct drm_connector *connector); 259 260 #endif /* __INTEL_DRV_H__ */ 261