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