xref: /linux/drivers/gpu/drm/nouveau/nouveau_bios.h (revision 6efc0ab3b05de0d7bab8ec0597214e4788251071)
1 /*
2  * Copyright 2007-2008 Nouveau Project
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23 
24 #ifndef __NOUVEAU_DISPBIOS_H__
25 #define __NOUVEAU_DISPBIOS_H__
26 
27 #define DCB_MAX_NUM_ENTRIES 16
28 #define DCB_MAX_NUM_I2C_ENTRIES 16
29 #define DCB_MAX_NUM_GPIO_ENTRIES 32
30 #define DCB_MAX_NUM_CONNECTOR_ENTRIES 16
31 
32 #define DCB_LOC_ON_CHIP 0
33 
34 #define ROM16(x) get_unaligned_le16(&(x))
35 #define ROM32(x) get_unaligned_le32(&(x))
36 #define ROMPTR(d,x) ({            \
37 	struct nouveau_drm *drm = nouveau_drm((d)); \
38 	ROM16(x) ? &drm->vbios.data[ROM16(x)] : NULL; \
39 })
40 
41 struct bit_entry {
42 	uint8_t  id;
43 	uint8_t  version;
44 	uint16_t length;
45 	uint16_t offset;
46 	uint8_t *data;
47 };
48 
49 int bit_table(struct drm_device *, u8 id, struct bit_entry *);
50 
51 #include <subdev/bios.h>
52 #include <subdev/bios/dcb.h>
53 #include <subdev/bios/conn.h>
54 
55 struct dcb_table {
56 	uint8_t version;
57 	int entries;
58 	struct dcb_output entry[DCB_MAX_NUM_ENTRIES];
59 };
60 
61 enum nouveau_or {
62 	DCB_OUTPUT_A = (1 << 0),
63 	DCB_OUTPUT_B = (1 << 1),
64 	DCB_OUTPUT_C = (1 << 2)
65 };
66 
67 enum LVDS_script {
68 	/* Order *does* matter here */
69 	LVDS_INIT = 1,
70 	LVDS_RESET,
71 	LVDS_BACKLIGHT_ON,
72 	LVDS_BACKLIGHT_OFF,
73 	LVDS_PANEL_ON,
74 	LVDS_PANEL_OFF
75 };
76 
77 struct nvbios {
78 	struct drm_device *dev;
79 	enum {
80 		NVBIOS_BMP,
81 		NVBIOS_BIT
82 	} type;
83 	uint16_t offset;
84 	uint32_t length;
85 	uint8_t *data;
86 
87 	uint8_t chip_version;
88 
89 	uint32_t dactestval;
90 	uint32_t tvdactestval;
91 	uint8_t digital_min_front_porch;
92 	bool fp_no_ddc;
93 
94 	spinlock_t lock;
95 
96 	bool execute;
97 
98 	uint8_t major_version;
99 	uint8_t feature_byte;
100 	bool is_mobile;
101 
102 	uint32_t fmaxvco, fminvco;
103 
104 	bool old_style_init;
105 	uint16_t init_script_tbls_ptr;
106 	uint16_t extra_init_script_tbl_ptr;
107 
108 	uint16_t ram_restrict_tbl_ptr;
109 	uint8_t ram_restrict_group_count;
110 
111 	struct dcb_table dcb;
112 
113 	struct {
114 		int crtchead;
115 	} state;
116 
117 	struct {
118 		uint16_t fptablepointer;	/* also used by tmds */
119 		uint16_t fpxlatetableptr;
120 		int xlatwidth;
121 		uint16_t lvdsmanufacturerpointer;
122 		uint16_t fpxlatemanufacturertableptr;
123 		uint16_t mode_ptr;
124 		uint16_t xlated_entry;
125 		bool power_off_for_reset;
126 		bool reset_after_pclk_change;
127 		bool dual_link;
128 		bool link_c_increment;
129 		bool if_is_24bit;
130 		int duallink_transition_clk;
131 		uint8_t strapless_is_24bit;
132 		uint8_t *edid;
133 
134 		/* will need resetting after suspend */
135 		int last_script_invoc;
136 		bool lvds_init_run;
137 	} fp;
138 
139 	struct {
140 		uint16_t output0_script_ptr;
141 		uint16_t output1_script_ptr;
142 	} tmds;
143 
144 	struct {
145 		uint16_t mem_init_tbl_ptr;
146 		uint16_t sdr_seq_tbl_ptr;
147 		uint16_t ddr_seq_tbl_ptr;
148 
149 		struct {
150 			uint8_t crt, tv, panel;
151 		} i2c_indices;
152 
153 		uint16_t lvds_single_a_script_ptr;
154 	} legacy;
155 };
156 
157 void *olddcb_table(struct drm_device *);
158 void *olddcb_outp(struct drm_device *, u8 idx);
159 int olddcb_outp_foreach(struct drm_device *, void *data,
160 		     int (*)(struct drm_device *, void *, int idx, u8 *outp));
161 u8 *olddcb_conntab(struct drm_device *);
162 u8 *olddcb_conn(struct drm_device *, u8 idx);
163 
164 int nouveau_bios_init(struct drm_device *);
165 void nouveau_bios_takedown(struct drm_device *dev);
166 int nouveau_run_vbios_init(struct drm_device *);
167 struct dcb_connector_table_entry *
168 nouveau_bios_connector_entry(struct drm_device *, int index);
169 bool nouveau_bios_fp_mode(struct drm_device *, struct drm_display_mode *);
170 uint8_t *nouveau_bios_embedded_edid(struct drm_device *);
171 int nouveau_bios_parse_lvds_table(struct drm_device *, int pxclk,
172 					 bool *dl, bool *if_is_24bit);
173 int run_tmds_table(struct drm_device *, struct dcb_output *,
174 			  int head, int pxclk);
175 int call_lvds_script(struct drm_device *, struct dcb_output *, int head,
176 			    enum LVDS_script, int pxclk);
177 
178 #endif
179