1 /*
2  * Copyright (c) 2009, Intel Corporation.
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms and conditions of the GNU General Public License,
6  * version 2, as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
11  * more details.
12  *
13  * You should have received a copy of the GNU General Public License along with
14  * this program; if not, write to the Free Software Foundation, Inc.,
15  * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
16  *
17  */
18 
19 #ifndef __INTEL_DRV_H__
20 #define __INTEL_DRV_H__
21 
22 #include <linux/i2c.h>
23 #include <linux/i2c-algo-bit.h>
24 #include <drm/drm_crtc.h>
25 #include <drm/drm_crtc_helper.h>
26 #include <linux/gpio.h>
27 
28 /*
29  * MOORESTOWN defines
30  */
31 #define DELAY_TIME1 2000 /* 1000 = 1ms */
32 
33 /*
34  * Display related stuff
35  */
36 
37 /* store information about an Ixxx DVO */
38 /* The i830->i865 use multiple DVOs with multiple i2cs */
39 /* the i915, i945 have a single sDVO i2c bus - which is different */
40 #define MAX_OUTPUTS 6
41 /* maximum connectors per crtcs in the mode set */
42 #define INTELFB_CONN_LIMIT 4
43 
44 #define INTEL_I2C_BUS_DVO 1
45 #define INTEL_I2C_BUS_SDVO 2
46 
47 /* these are outputs from the chip - integrated only
48  * external chips are via DVO or SDVO output */
49 #define INTEL_OUTPUT_UNUSED 0
50 #define INTEL_OUTPUT_ANALOG 1
51 #define INTEL_OUTPUT_DVO 2
52 #define INTEL_OUTPUT_SDVO 3
53 #define INTEL_OUTPUT_LVDS 4
54 #define INTEL_OUTPUT_TVOUT 5
55 #define INTEL_OUTPUT_HDMI 6
56 #define INTEL_OUTPUT_MIPI 7
57 #define INTEL_OUTPUT_MIPI2 8
58 
59 #define INTEL_DVO_CHIP_NONE 0
60 #define INTEL_DVO_CHIP_LVDS 1
61 #define INTEL_DVO_CHIP_TMDS 2
62 #define INTEL_DVO_CHIP_TVOUT 4
63 
64 enum mipi_panel_type {
65 	NSC_800X480 = 1,
66 	LGE_480X1024 = 2,
67 	TPO_864X480 = 3
68 };
69 
70 /**
71  * Hold information useally put on the device driver privates here,
72  * since it needs to be shared across multiple of devices drivers privates.
73 */
74 struct psb_intel_mode_device {
75 
76 	/*
77 	 * Abstracted memory manager operations
78 	 */
79 	void *(*bo_from_handle) (struct drm_device *dev,
80 				 struct drm_file *file_priv,
81 				 unsigned int handle);
82 	 size_t(*bo_size) (struct drm_device *dev, void *bo);
83 	 size_t(*bo_offset) (struct drm_device *dev, void *bo);
84 	int (*bo_pin_for_scanout) (struct drm_device *dev, void *bo);
85 	int (*bo_unpin_for_scanout) (struct drm_device *dev, void *bo);
86 
87 	/*
88 	 * Cursor
89 	 */
90 	int cursor_needs_physical;
91 
92 	/*
93 	 * LVDS info
94 	 */
95 	int backlight_duty_cycle;	/* restore backlight to this value */
96 	bool panel_wants_dither;
97 	struct drm_display_mode *panel_fixed_mode;
98 	struct drm_display_mode *panel_fixed_mode2;
99 	struct drm_display_mode *vbt_mode;	/* if any */
100 
101 	uint32_t saveBLC_PWM_CTL;
102 };
103 
104 struct psb_intel_i2c_chan {
105 	/* for getting at dev. private (mmio etc.) */
106 	struct drm_device *drm_dev;
107 	u32 reg;		/* GPIO reg */
108 	struct i2c_adapter adapter;
109 	struct i2c_algo_bit_data algo;
110 	u8 slave_addr;
111 };
112 
113 struct psb_intel_output {
114 	struct drm_connector base;
115 
116 	struct drm_encoder enc;
117 	int type;
118 
119 	struct psb_intel_i2c_chan *i2c_bus;	/* for control functions */
120 	struct psb_intel_i2c_chan *ddc_bus;	/* for DDC only stuff */
121 	bool load_detect_temp;
122 	void *dev_priv;
123 
124 	struct psb_intel_mode_device *mode_dev;
125 
126 };
127 
128 struct psb_intel_crtc_state {
129 	uint32_t saveDSPCNTR;
130 	uint32_t savePIPECONF;
131 	uint32_t savePIPESRC;
132 	uint32_t saveDPLL;
133 	uint32_t saveFP0;
134 	uint32_t saveFP1;
135 	uint32_t saveHTOTAL;
136 	uint32_t saveHBLANK;
137 	uint32_t saveHSYNC;
138 	uint32_t saveVTOTAL;
139 	uint32_t saveVBLANK;
140 	uint32_t saveVSYNC;
141 	uint32_t saveDSPSTRIDE;
142 	uint32_t saveDSPSIZE;
143 	uint32_t saveDSPPOS;
144 	uint32_t saveDSPBASE;
145 	uint32_t savePalette[256];
146 };
147 
148 struct psb_intel_crtc {
149 	struct drm_crtc base;
150 	int pipe;
151 	int plane;
152 	uint32_t cursor_addr;
153 	u8 lut_r[256], lut_g[256], lut_b[256];
154 	u8 lut_adj[256];
155 	struct psb_intel_framebuffer *fbdev_fb;
156 	/* a mode_set for fbdev users on this crtc */
157 	struct drm_mode_set mode_set;
158 
159 	/* current bo we scanout from */
160 	void *scanout_bo;
161 
162 	/* current bo we cursor from */
163 	void *cursor_bo;
164 
165 	struct drm_display_mode saved_mode;
166 	struct drm_display_mode saved_adjusted_mode;
167 
168 	struct psb_intel_mode_device *mode_dev;
169 
170 	/*crtc mode setting flags*/
171 	u32 mode_flags;
172 
173 	/* Saved Crtc HW states */
174 	struct psb_intel_crtc_state *crtc_state;
175 };
176 
177 #define to_psb_intel_crtc(x)	\
178 		container_of(x, struct psb_intel_crtc, base)
179 #define to_psb_intel_output(x)	\
180 		container_of(x, struct psb_intel_output, base)
181 #define enc_to_psb_intel_output(x)	\
182 		container_of(x, struct psb_intel_output, enc)
183 #define to_psb_intel_framebuffer(x)	\
184 		container_of(x, struct psb_intel_framebuffer, base)
185 
186 struct psb_intel_i2c_chan *psb_intel_i2c_create(struct drm_device *dev,
187 					const u32 reg, const char *name);
188 void psb_intel_i2c_destroy(struct psb_intel_i2c_chan *chan);
189 int psb_intel_ddc_get_modes(struct psb_intel_output *psb_intel_output);
190 extern bool psb_intel_ddc_probe(struct psb_intel_output *psb_intel_output);
191 
192 extern void psb_intel_crtc_init(struct drm_device *dev, int pipe,
193 			    struct psb_intel_mode_device *mode_dev);
194 extern void psb_intel_crt_init(struct drm_device *dev);
195 extern void psb_intel_sdvo_init(struct drm_device *dev, int output_device);
196 extern void psb_intel_dvo_init(struct drm_device *dev);
197 extern void psb_intel_tv_init(struct drm_device *dev);
198 extern void psb_intel_lvds_init(struct drm_device *dev,
199 			    struct psb_intel_mode_device *mode_dev);
200 extern void psb_intel_lvds_set_brightness(struct drm_device *dev, int level);
201 extern void mrst_lvds_init(struct drm_device *dev,
202 			   struct psb_intel_mode_device *mode_dev);
203 extern void mrst_wait_for_INTR_PKT_SENT(struct drm_device *dev);
204 extern void mrst_dsi_init(struct drm_device *dev,
205 			   struct psb_intel_mode_device *mode_dev);
206 extern void mid_dsi_init(struct drm_device *dev,
207 		    struct psb_intel_mode_device *mode_dev, int dsi_num);
208 
209 extern void psb_intel_crtc_load_lut(struct drm_crtc *crtc);
210 extern void psb_intel_encoder_prepare(struct drm_encoder *encoder);
211 extern void psb_intel_encoder_commit(struct drm_encoder *encoder);
212 
213 extern struct drm_encoder *psb_intel_best_encoder(struct drm_connector
214 					      *connector);
215 
216 extern struct drm_display_mode *psb_intel_crtc_mode_get(struct drm_device *dev,
217 						    struct drm_crtc *crtc);
218 extern void psb_intel_wait_for_vblank(struct drm_device *dev);
219 extern int psb_intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
220 				struct drm_file *file_priv);
221 extern struct drm_crtc *psb_intel_get_crtc_from_pipe(struct drm_device *dev,
222 						 int pipe);
223 extern struct drm_connector *psb_intel_sdvo_find(struct drm_device *dev,
224 					     int sdvoB);
225 extern int psb_intel_sdvo_supports_hotplug(struct drm_connector *connector);
226 extern void psb_intel_sdvo_set_hotplug(struct drm_connector *connector,
227 				   int enable);
228 extern int intelfb_probe(struct drm_device *dev);
229 extern int intelfb_remove(struct drm_device *dev,
230 			  struct drm_framebuffer *fb);
231 extern struct drm_framebuffer *psb_intel_framebuffer_create(struct drm_device
232 							*dev, struct
233 							drm_mode_fb_cmd
234 							*mode_cmd,
235 							void *mm_private);
236 extern bool psb_intel_lvds_mode_fixup(struct drm_encoder *encoder,
237 				      struct drm_display_mode *mode,
238 				      struct drm_display_mode *adjusted_mode);
239 extern int psb_intel_lvds_mode_valid(struct drm_connector *connector,
240 				     struct drm_display_mode *mode);
241 extern int psb_intel_lvds_set_property(struct drm_connector *connector,
242 					struct drm_property *property,
243 					uint64_t value);
244 extern void psb_intel_lvds_destroy(struct drm_connector *connector);
245 extern const struct drm_encoder_funcs psb_intel_lvds_enc_funcs;
246 
247 #endif				/* __INTEL_DRV_H__ */
248