xref: /linux/drivers/gpu/drm/gma500/psb_intel_drv.h (revision ab93e0dd72c37d378dd936f031ffb83ff2bd87ce)
1a61127c2SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
289c78134SAlan Cox /*
389c78134SAlan Cox  * Copyright (c) 2009-2011, Intel Corporation.
489c78134SAlan Cox  */
589c78134SAlan Cox 
689c78134SAlan Cox #ifndef __INTEL_DRV_H__
789c78134SAlan Cox #define __INTEL_DRV_H__
889c78134SAlan Cox 
989c78134SAlan Cox #include <linux/i2c.h>
1089c78134SAlan Cox #include <linux/i2c-algo-bit.h>
1189c78134SAlan Cox #include <drm/drm_crtc.h>
129338203cSLaurent Pinchart #include <drm/drm_encoder.h>
13fcd70cd3SDaniel Vetter #include <drm/drm_probe_helper.h>
14f76c22ceSPaul Kocialkowski #include <drm/drm_vblank.h>
155ea75e0fSPatrik Jakobsson #include "gma_display.h"
1689c78134SAlan Cox 
1789c78134SAlan Cox /*
1889c78134SAlan Cox  * Display related stuff
1989c78134SAlan Cox  */
2089c78134SAlan Cox 
2189c78134SAlan Cox /* maximum connectors per crtcs in the mode set */
2289c78134SAlan Cox #define INTELFB_CONN_LIMIT 4
2389c78134SAlan Cox 
245736995bSPatrik Jakobsson /* Intel Pipe Clone Bit */
255736995bSPatrik Jakobsson #define INTEL_HDMIB_CLONE_BIT 1
265736995bSPatrik Jakobsson #define INTEL_HDMIC_CLONE_BIT 2
275736995bSPatrik Jakobsson #define INTEL_HDMID_CLONE_BIT 3
285736995bSPatrik Jakobsson #define INTEL_HDMIE_CLONE_BIT 4
295736995bSPatrik Jakobsson #define INTEL_HDMIF_CLONE_BIT 5
305736995bSPatrik Jakobsson #define INTEL_SDVO_NON_TV_CLONE_BIT 6
315736995bSPatrik Jakobsson #define INTEL_SDVO_TV_CLONE_BIT 7
325736995bSPatrik Jakobsson #define INTEL_SDVO_LVDS_CLONE_BIT 8
335736995bSPatrik Jakobsson #define INTEL_ANALOG_CLONE_BIT 9
345736995bSPatrik Jakobsson #define INTEL_TV_CLONE_BIT 10
355736995bSPatrik Jakobsson #define INTEL_DP_B_CLONE_BIT 11
365736995bSPatrik Jakobsson #define INTEL_DP_C_CLONE_BIT 12
375736995bSPatrik Jakobsson #define INTEL_DP_D_CLONE_BIT 13
385736995bSPatrik Jakobsson #define INTEL_LVDS_CLONE_BIT 14
395736995bSPatrik Jakobsson #define INTEL_DVO_TMDS_CLONE_BIT 15
405736995bSPatrik Jakobsson #define INTEL_DVO_LVDS_CLONE_BIT 16
415736995bSPatrik Jakobsson #define INTEL_EDP_CLONE_BIT 17
425736995bSPatrik Jakobsson 
4389c78134SAlan Cox /* these are outputs from the chip - integrated only
4489c78134SAlan Cox  * external chips are via DVO or SDVO output */
4589c78134SAlan Cox #define INTEL_OUTPUT_UNUSED 0
4689c78134SAlan Cox #define INTEL_OUTPUT_ANALOG 1
4789c78134SAlan Cox #define INTEL_OUTPUT_DVO 2
4889c78134SAlan Cox #define INTEL_OUTPUT_SDVO 3
4989c78134SAlan Cox #define INTEL_OUTPUT_LVDS 4
5089c78134SAlan Cox #define INTEL_OUTPUT_TVOUT 5
5189c78134SAlan Cox #define INTEL_OUTPUT_HDMI 6
5289c78134SAlan Cox #define INTEL_OUTPUT_MIPI 7
5389c78134SAlan Cox #define INTEL_OUTPUT_MIPI2 8
548695b612SAlan Cox #define INTEL_OUTPUT_DISPLAYPORT 9
558695b612SAlan Cox #define INTEL_OUTPUT_EDP 10
5689c78134SAlan Cox 
5789c78134SAlan Cox /*
5889c78134SAlan Cox  * Hold information useally put on the device driver privates here,
5989c78134SAlan Cox  * since it needs to be shared across multiple of devices drivers privates.
6089c78134SAlan Cox  */
6189c78134SAlan Cox struct psb_intel_mode_device {
6289c78134SAlan Cox 
6389c78134SAlan Cox 	/*
6489c78134SAlan Cox 	 * Abstracted memory manager operations
6589c78134SAlan Cox 	 */
6689c78134SAlan Cox 	 size_t(*bo_offset) (struct drm_device *dev, void *bo);
6789c78134SAlan Cox 
6889c78134SAlan Cox 	/*
6989c78134SAlan Cox 	 * LVDS info
7089c78134SAlan Cox 	 */
7189c78134SAlan Cox 	int backlight_duty_cycle;	/* restore backlight to this value */
7289c78134SAlan Cox 	bool panel_wants_dither;
7389c78134SAlan Cox 	struct drm_display_mode *panel_fixed_mode;
7489c78134SAlan Cox 	struct drm_display_mode *panel_fixed_mode2;
7589c78134SAlan Cox 	struct drm_display_mode *vbt_mode;	/* if any */
7689c78134SAlan Cox 
7789c78134SAlan Cox 	uint32_t saveBLC_PWM_CTL;
7889c78134SAlan Cox };
7989c78134SAlan Cox 
8004477e5eSPatrik Jakobsson struct gma_i2c_chan {
81ba1677f7SPatrik Jakobsson 	struct i2c_adapter base;
82ba1677f7SPatrik Jakobsson 	struct i2c_algo_bit_data algo;
830c3f3a83SEaswar Hariharan 	u8 target_addr;
84ba1677f7SPatrik Jakobsson 
8589c78134SAlan Cox 	/* for getting at dev. private (mmio etc.) */
8689c78134SAlan Cox 	struct drm_device *drm_dev;
8789c78134SAlan Cox 	u32 reg; /* GPIO reg */
8889c78134SAlan Cox };
8989c78134SAlan Cox 
90367e4408SPatrik Jakobsson struct gma_encoder {
9175e9d019SPatrik Jakobsson 	struct drm_encoder base;
9289c78134SAlan Cox 	int type;
9375e9d019SPatrik Jakobsson 	bool needs_tv_clock;
94367e4408SPatrik Jakobsson 	void (*hot_plug)(struct gma_encoder *);
9575e9d019SPatrik Jakobsson 	int crtc_mask;
9675e9d019SPatrik Jakobsson 	int clone_mask;
97d6676096SZhao Yakui 	u32 ddi_select;	/* Channel info */
98d6676096SZhao Yakui #define DDI0_SELECT	0x01
99d6676096SZhao Yakui #define DDI1_SELECT	0x02
100220801bdSAlan Cox #define DP_MASK		0x8000
101d6676096SZhao Yakui #define DDI_MASK	0x03
10275e9d019SPatrik Jakobsson 	void *dev_priv; /* For sdvo_priv, lvds_priv, etc... */
103a12d6a07SPatrik Jakobsson 
104a12d6a07SPatrik Jakobsson 	/* FIXME: Either make SDVO and LVDS store it's i2c here or give CDV it's
105a12d6a07SPatrik Jakobsson 	   own set of output privates */
10604477e5eSPatrik Jakobsson 	struct gma_i2c_chan *i2c_bus;
10775e9d019SPatrik Jakobsson };
10889c78134SAlan Cox 
109a3d5d75fSPatrik Jakobsson struct gma_connector {
11075e9d019SPatrik Jakobsson 	struct drm_connector base;
111367e4408SPatrik Jakobsson 	struct gma_encoder *encoder;
112d56f57acSDaniel Vetter 
113d56f57acSDaniel Vetter 	void (*save)(struct drm_connector *connector);
114d56f57acSDaniel Vetter 	void (*restore)(struct drm_connector *connector);
11589c78134SAlan Cox };
11689c78134SAlan Cox 
11789c78134SAlan Cox struct psb_intel_crtc_state {
11889c78134SAlan Cox 	uint32_t saveDSPCNTR;
11989c78134SAlan Cox 	uint32_t savePIPECONF;
12089c78134SAlan Cox 	uint32_t savePIPESRC;
12189c78134SAlan Cox 	uint32_t saveDPLL;
12289c78134SAlan Cox 	uint32_t saveFP0;
12389c78134SAlan Cox 	uint32_t saveFP1;
12489c78134SAlan Cox 	uint32_t saveHTOTAL;
12589c78134SAlan Cox 	uint32_t saveHBLANK;
12689c78134SAlan Cox 	uint32_t saveHSYNC;
12789c78134SAlan Cox 	uint32_t saveVTOTAL;
12889c78134SAlan Cox 	uint32_t saveVBLANK;
12989c78134SAlan Cox 	uint32_t saveVSYNC;
13089c78134SAlan Cox 	uint32_t saveDSPSTRIDE;
13189c78134SAlan Cox 	uint32_t saveDSPSIZE;
13289c78134SAlan Cox 	uint32_t saveDSPPOS;
13389c78134SAlan Cox 	uint32_t saveDSPBASE;
13489c78134SAlan Cox 	uint32_t savePalette[256];
13589c78134SAlan Cox };
13689c78134SAlan Cox 
1376306865dSPatrik Jakobsson struct gma_crtc {
13889c78134SAlan Cox 	struct drm_crtc base;
13989c78134SAlan Cox 	int pipe;
14089c78134SAlan Cox 	int plane;
14189c78134SAlan Cox 	uint32_t cursor_addr;
142f2d061edSThomas Zimmermann 	struct psb_gem_object *cursor_pobj;
14389c78134SAlan Cox 	u8 lut_adj[256];
14489c78134SAlan Cox 	struct psb_intel_framebuffer *fbdev_fb;
14589c78134SAlan Cox 	/* a mode_set for fbdev users on this crtc */
14689c78134SAlan Cox 	struct drm_mode_set mode_set;
14789c78134SAlan Cox 
14889c78134SAlan Cox 	/* GEM object that holds our cursor */
14989c78134SAlan Cox 	struct drm_gem_object *cursor_obj;
15089c78134SAlan Cox 
15189c78134SAlan Cox 	struct drm_display_mode saved_mode;
15289c78134SAlan Cox 	struct drm_display_mode saved_adjusted_mode;
15389c78134SAlan Cox 
15489c78134SAlan Cox 	struct psb_intel_mode_device *mode_dev;
15589c78134SAlan Cox 
15689c78134SAlan Cox 	/*crtc mode setting flags*/
15789c78134SAlan Cox 	u32 mode_flags;
15889c78134SAlan Cox 
159acd7ef92SAlan Cox 	bool active;
160acd7ef92SAlan Cox 
16189c78134SAlan Cox 	/* Saved Crtc HW states */
16289c78134SAlan Cox 	struct psb_intel_crtc_state *crtc_state;
1635ea75e0fSPatrik Jakobsson 
1645ea75e0fSPatrik Jakobsson 	const struct gma_clock_funcs *clock_funcs;
165f76c22ceSPaul Kocialkowski 
166f76c22ceSPaul Kocialkowski 	struct drm_pending_vblank_event *page_flip_event;
16789c78134SAlan Cox };
16889c78134SAlan Cox 
1696306865dSPatrik Jakobsson #define to_gma_crtc(x)	\
1706306865dSPatrik Jakobsson 		container_of(x, struct gma_crtc, base)
171a3d5d75fSPatrik Jakobsson #define to_gma_connector(x) \
172a3d5d75fSPatrik Jakobsson 		container_of(x, struct gma_connector, base)
173367e4408SPatrik Jakobsson #define to_gma_encoder(x)	\
174367e4408SPatrik Jakobsson 		container_of(x, struct gma_encoder, base)
17589c78134SAlan Cox #define to_psb_intel_framebuffer(x)	\
17689c78134SAlan Cox 		container_of(x, struct psb_intel_framebuffer, base)
177ba1677f7SPatrik Jakobsson #define to_gma_i2c_chan(x)	\
178ba1677f7SPatrik Jakobsson 		container_of(x, struct gma_i2c_chan, base)
17989c78134SAlan Cox 
18004477e5eSPatrik Jakobsson struct gma_i2c_chan *gma_i2c_create(struct drm_device *dev, const u32 reg,
18104477e5eSPatrik Jakobsson 				    const char *name);
18204477e5eSPatrik Jakobsson void gma_i2c_destroy(struct gma_i2c_chan *chan);
183352b16a0SPatrik Jakobsson int psb_intel_ddc_get_modes(struct drm_connector *connector,
184352b16a0SPatrik Jakobsson 			    struct i2c_adapter *adapter);
18589c78134SAlan Cox 
18689c78134SAlan Cox extern void psb_intel_crtc_init(struct drm_device *dev, int pipe,
18789c78134SAlan Cox 			    struct psb_intel_mode_device *mode_dev);
1885736995bSPatrik Jakobsson extern bool psb_intel_sdvo_init(struct drm_device *dev, int output_device);
18989c78134SAlan Cox extern void psb_intel_lvds_init(struct drm_device *dev,
19089c78134SAlan Cox 			    struct psb_intel_mode_device *mode_dev);
19189c78134SAlan Cox extern void psb_intel_lvds_set_brightness(struct drm_device *dev, int level);
19289c78134SAlan Cox extern void oaktrail_lvds_init(struct drm_device *dev,
19389c78134SAlan Cox 			   struct psb_intel_mode_device *mode_dev);
194a57ebfc0SPatrik Jakobsson struct gma_i2c_chan *oaktrail_lvds_i2c_init(struct drm_device *dev);
19589c78134SAlan Cox 
19659345847SPatrik Jakobsson extern struct drm_encoder *gma_best_encoder(struct drm_connector *connector);
197a3d5d75fSPatrik Jakobsson extern void gma_connector_attach_encoder(struct gma_connector *connector,
198367e4408SPatrik Jakobsson 					 struct gma_encoder *encoder);
19959345847SPatrik Jakobsson 
gma_attached_encoder(struct drm_connector * connector)200367e4408SPatrik Jakobsson static inline struct gma_encoder *gma_attached_encoder(
20159345847SPatrik Jakobsson 						struct drm_connector *connector)
20259345847SPatrik Jakobsson {
203a3d5d75fSPatrik Jakobsson 	return to_gma_connector(connector)->encoder;
20459345847SPatrik Jakobsson }
20559345847SPatrik Jakobsson 
20689c78134SAlan Cox extern struct drm_display_mode *psb_intel_crtc_mode_get(struct drm_device *dev,
20789c78134SAlan Cox 						    struct drm_crtc *crtc);
20889c78134SAlan Cox extern struct drm_crtc *psb_intel_get_crtc_from_pipe(struct drm_device *dev,
20989c78134SAlan Cox 						 int pipe);
21089c78134SAlan Cox extern bool psb_intel_lvds_mode_fixup(struct drm_encoder *encoder,
211e811f5aeSLaurent Pinchart 				      const struct drm_display_mode *mode,
21289c78134SAlan Cox 				      struct drm_display_mode *adjusted_mode);
2132ea00909SLuc Van Oostenryck extern enum drm_mode_status psb_intel_lvds_mode_valid(struct drm_connector *connector,
214*26d6fd81SDmitry Baryshkov 				     const struct drm_display_mode *mode);
21589c78134SAlan Cox extern int psb_intel_lvds_set_property(struct drm_connector *connector,
21689c78134SAlan Cox 					struct drm_property *property,
21789c78134SAlan Cox 					uint64_t value);
21889c78134SAlan Cox extern void psb_intel_lvds_destroy(struct drm_connector *connector);
21989c78134SAlan Cox 
2205c0c1d50SPatrik Jakobsson /* intel_gmbus.c */
2215c0c1d50SPatrik Jakobsson extern void gma_intel_i2c_reset(struct drm_device *dev);
2225c0c1d50SPatrik Jakobsson extern int gma_intel_setup_gmbus(struct drm_device *dev);
2235c0c1d50SPatrik Jakobsson extern void gma_intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
2245c0c1d50SPatrik Jakobsson extern void gma_intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
2255c0c1d50SPatrik Jakobsson extern void gma_intel_teardown_gmbus(struct drm_device *dev);
22689c78134SAlan Cox 
22737e7b184SAlan Cox /* DP support */
22837e7b184SAlan Cox extern void cdv_intel_dp_init(struct drm_device *dev, struct psb_intel_mode_device *mode_dev, int output_reg);
229ce5fdd63SDave Airlie extern void cdv_intel_dp_set_m_n(struct drm_crtc *crtc,
23037e7b184SAlan Cox 					struct drm_display_mode *mode,
23137e7b184SAlan Cox 					struct drm_display_mode *adjusted_mode);
23237e7b184SAlan Cox 
23337e7b184SAlan Cox extern int cdv_sb_read(struct drm_device *dev, u32 reg, u32 *val);
23437e7b184SAlan Cox extern int cdv_sb_write(struct drm_device *dev, u32 reg, u32 val);
23537e7b184SAlan Cox extern void cdv_sb_reset(struct drm_device *dev);
23637e7b184SAlan Cox 
23737e7b184SAlan Cox extern void cdv_intel_attach_force_audio_property(struct drm_connector *connector);
23837e7b184SAlan Cox extern void cdv_intel_attach_broadcast_rgb_property(struct drm_connector *connector);
23937e7b184SAlan Cox 
24089c78134SAlan Cox #endif				/* __INTEL_DRV_H__ */
241