2 * Copyright 2012 Red Hat Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
15 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
17 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
18 * USE OR OTHER DEALINGS IN THE SOFTWARE.
20 * The above copyright notice and this permission notice (including the
21 * next paragraph) shall be included in all copies or substantial portions
31 #include <linux/i2c.h>
32 #include <linux/i2c-algo-bit.h>
34 #include <linux/types.h>
36 #include <drm/drm_connector.h>
37 #include <drm/drm_crtc.h>
38 #include <drm/drm_encoder.h>
39 #include <drm/drm_mode.h>
40 #include <drm/drm_framebuffer.h>
42 #define DRIVER_AUTHOR "Dave Airlie"
44 #define DRIVER_NAME "ast"
45 #define DRIVER_DESC "AST"
46 #define DRIVER_DATE "20120228"
48 #define DRIVER_MAJOR 0
49 #define DRIVER_MINOR 1
50 #define DRIVER_PATCHLEVEL 0
52 #define PCI_CHIP_AST2000 0x2000
53 #define PCI_CHIP_AST2100 0x2010
75 #define AST_TX_NONE_BIT BIT(AST_TX_NONE)
76 #define AST_TX_SIL164_BIT BIT(AST_TX_SIL164)
77 #define AST_TX_DP501_BIT BIT(AST_TX_DP501)
78 #define AST_TX_ASTDP_BIT BIT(AST_TX_ASTDP)
80 #define AST_DRAM_512Mx16 0
81 #define AST_DRAM_1Gx16 1
82 #define AST_DRAM_512Mx32 2
83 #define AST_DRAM_1Gx32 3
84 #define AST_DRAM_2Gx16 6
85 #define AST_DRAM_4Gx16 7
86 #define AST_DRAM_8Gx16 8
92 #define AST_MAX_HWC_WIDTH 64
93 #define AST_MAX_HWC_HEIGHT 64
95 #define AST_HWC_SIZE (AST_MAX_HWC_WIDTH * AST_MAX_HWC_HEIGHT * 2)
96 #define AST_HWC_SIGNATURE_SIZE 32
98 /* define for signature structure */
99 #define AST_HWC_SIGNATURE_CHECKSUM 0x00
100 #define AST_HWC_SIGNATURE_SizeX 0x04
101 #define AST_HWC_SIGNATURE_SizeY 0x08
102 #define AST_HWC_SIGNATURE_X 0x0C
103 #define AST_HWC_SIGNATURE_Y 0x10
104 #define AST_HWC_SIGNATURE_HOTSPOTX 0x14
105 #define AST_HWC_SIGNATURE_HOTSPOTY 0x18
112 struct drm_plane base;
119 static inline struct ast_plane *to_ast_plane(struct drm_plane *plane)
121 return container_of(plane, struct ast_plane, base);
125 * Connector with i2c channel
128 struct ast_i2c_chan {
129 struct i2c_adapter adapter;
130 struct drm_device *dev;
131 struct i2c_algo_bit_data bit;
134 struct ast_vga_connector {
135 struct drm_connector base;
136 struct ast_i2c_chan *i2c;
139 static inline struct ast_vga_connector *
140 to_ast_vga_connector(struct drm_connector *connector)
142 return container_of(connector, struct ast_vga_connector, base);
145 struct ast_sil164_connector {
146 struct drm_connector base;
147 struct ast_i2c_chan *i2c;
150 static inline struct ast_sil164_connector *
151 to_ast_sil164_connector(struct drm_connector *connector)
153 return container_of(connector, struct ast_sil164_connector, base);
161 struct drm_device base;
163 struct mutex ioregs_lock; /* Protects access to I/O registers in ioregs */
165 void __iomem *ioregs;
166 void __iomem *dp501_fw_buf;
170 uint32_t dram_bus_width;
175 unsigned long vram_base;
176 unsigned long vram_size;
177 unsigned long vram_fb_available;
179 struct ast_plane primary_plane;
180 struct ast_plane cursor_plane;
181 struct drm_crtc crtc;
184 struct drm_encoder encoder;
185 struct ast_vga_connector vga_connector;
188 struct drm_encoder encoder;
189 struct ast_sil164_connector sil164_connector;
192 struct drm_encoder encoder;
193 struct drm_connector connector;
196 struct drm_encoder encoder;
197 struct drm_connector connector;
201 bool support_wide_screen;
208 unsigned long tx_chip_types; /* bitfield of enum ast_chip_type */
210 const struct firmware *dp501_fw; /* dp501 fw */
213 static inline struct ast_device *to_ast_device(struct drm_device *dev)
215 return container_of(dev, struct ast_device, base);
218 struct ast_device *ast_device_create(const struct drm_driver *drv,
219 struct pci_dev *pdev,
220 unsigned long flags);
222 #define AST_IO_AR_PORT_WRITE (0x40)
223 #define AST_IO_MISC_PORT_WRITE (0x42)
224 #define AST_IO_VGA_ENABLE_PORT (0x43)
225 #define AST_IO_SEQ_PORT (0x44)
226 #define AST_IO_DAC_INDEX_READ (0x47)
227 #define AST_IO_DAC_INDEX_WRITE (0x48)
228 #define AST_IO_DAC_DATA (0x49)
229 #define AST_IO_GR_PORT (0x4E)
230 #define AST_IO_CRTC_PORT (0x54)
231 #define AST_IO_INPUT_STATUS1_READ (0x5A)
232 #define AST_IO_MISC_PORT_READ (0x4C)
234 #define AST_IO_MM_OFFSET (0x380)
236 #define AST_IO_VGAIR1_VREFRESH BIT(3)
238 #define AST_IO_VGACRCB_HWC_ENABLED BIT(1)
239 #define AST_IO_VGACRCB_HWC_16BPP BIT(0) /* set: ARGB4444, cleared: 2bpp palette */
241 static inline u32 ast_read32(struct ast_device *ast, u32 reg)
243 return ioread32(ast->regs + reg);
246 static inline void ast_write32(struct ast_device *ast, u32 reg, u32 val)
248 iowrite32(val, ast->regs + reg);
251 static inline u8 ast_io_read8(struct ast_device *ast, u32 reg)
253 return ioread8(ast->ioregs + reg);
256 static inline void ast_io_write8(struct ast_device *ast, u32 reg, u8 val)
258 iowrite8(val, ast->ioregs + reg);
261 static inline void ast_set_index_reg(struct ast_device *ast,
262 uint32_t base, uint8_t index,
265 ast_io_write8(ast, base, index);
267 ast_io_write8(ast, base, val);
270 void ast_set_index_reg_mask(struct ast_device *ast,
271 uint32_t base, uint8_t index,
272 uint8_t mask, uint8_t val);
273 uint8_t ast_get_index_reg(struct ast_device *ast,
274 uint32_t base, uint8_t index);
275 uint8_t ast_get_index_reg_mask(struct ast_device *ast,
276 uint32_t base, uint8_t index, uint8_t mask);
278 static inline void ast_open_key(struct ast_device *ast)
280 ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x80, 0xA8);
283 #define AST_VIDMEM_SIZE_8M 0x00800000
284 #define AST_VIDMEM_SIZE_16M 0x01000000
285 #define AST_VIDMEM_SIZE_32M 0x02000000
286 #define AST_VIDMEM_SIZE_64M 0x04000000
287 #define AST_VIDMEM_SIZE_128M 0x08000000
289 #define AST_VIDMEM_DEFAULT_SIZE AST_VIDMEM_SIZE_8M
291 struct ast_vbios_stdtable {
299 struct ast_vbios_enhtable {
311 u32 refresh_rate_index;
315 struct ast_vbios_dclk_info {
321 struct ast_vbios_mode_info {
322 const struct ast_vbios_stdtable *std_table;
323 const struct ast_vbios_enhtable *enh_table;
326 struct ast_crtc_state {
327 struct drm_crtc_state base;
329 /* Last known format of primary plane */
330 const struct drm_format_info *format;
332 struct ast_vbios_mode_info vbios_mode_info;
335 #define to_ast_crtc_state(state) container_of(state, struct ast_crtc_state, base)
337 int ast_mode_config_init(struct ast_device *ast);
339 #define AST_MM_ALIGN_SHIFT 4
340 #define AST_MM_ALIGN_MASK ((1 << AST_MM_ALIGN_SHIFT) - 1)
342 #define AST_DP501_FW_VERSION_MASK GENMASK(7, 4)
343 #define AST_DP501_FW_VERSION_1 BIT(4)
344 #define AST_DP501_PNP_CONNECTED BIT(1)
346 #define AST_DP501_DEFAULT_DCLK 65
348 #define AST_DP501_GBL_VERSION 0xf000
349 #define AST_DP501_PNPMONITOR 0xf010
350 #define AST_DP501_LINKRATE 0xf014
351 #define AST_DP501_EDID_DATA 0xf020
353 /* Define for Soc scratched reg */
354 #define COPROCESSOR_LAUNCH BIT(5)
357 * Display Transmitter Type:
359 #define TX_TYPE_MASK GENMASK(3, 1)
360 #define NO_TX (0 << 1)
361 #define ITE66121_VBIOS_TX (1 << 1)
362 #define SI164_VBIOS_TX (2 << 1)
363 #define CH7003_VBIOS_TX (3 << 1)
364 #define DP501_VBIOS_TX (4 << 1)
365 #define ANX9807_VBIOS_TX (5 << 1)
366 #define TX_FW_EMBEDDED_FW_TX (6 << 1)
367 #define ASTDP_DPMCU_TX (7 << 1)
369 #define AST_VRAM_INIT_STATUS_MASK GENMASK(7, 6)
370 //#define AST_VRAM_INIT_BY_BMC BIT(7)
371 //#define AST_VRAM_INIT_READY BIT(6)
373 /* Define for Soc scratched reg used on ASTDP */
374 #define AST_DP_PHY_SLEEP BIT(4)
375 #define AST_DP_VIDEO_ENABLE BIT(0)
377 #define AST_DP_POWER_ON true
378 #define AST_DP_POWER_OFF false
381 * CRD1[b5]: DP MCU FW is executing
382 * CRDC[b0]: DP link success
384 * CRE5[b0]: Host reading EDID process is done
386 #define ASTDP_MCU_FW_EXECUTING BIT(5)
387 #define ASTDP_LINK_SUCCESS BIT(0)
388 #define ASTDP_HPD BIT(0)
389 #define ASTDP_HOST_EDID_READ_DONE BIT(0)
390 #define ASTDP_HOST_EDID_READ_DONE_MASK GENMASK(0, 0)
393 * CRB8[b1]: Enable VSYNC off
394 * CRB8[b0]: Enable HSYNC off
396 #define AST_DPMS_VSYNC_OFF BIT(1)
397 #define AST_DPMS_HSYNC_OFF BIT(0)
400 * CRDF[b4]: Mirror of AST_DP_VIDEO_ENABLE
401 * Precondition: A. ~AST_DP_PHY_SLEEP &&
405 #define ASTDP_MIRROR_VIDEO_ENABLE BIT(4)
407 #define ASTDP_EDID_READ_POINTER_MASK GENMASK(7, 0)
408 #define ASTDP_EDID_VALID_FLAG_MASK GENMASK(0, 0)
409 #define ASTDP_EDID_READ_DATA_MASK GENMASK(7, 0)
412 * ASTDP setmode registers:
413 * CRE0[7:0]: MISC0 ((0x00: 18-bpp) or (0x20: 24-bpp)
414 * CRE1[7:0]: MISC1 (default: 0x00)
415 * CRE2[7:0]: video format index (0x00 ~ 0x20 or 0x40 ~ 0x50)
417 #define ASTDP_MISC0_24bpp BIT(5)
418 #define ASTDP_MISC1 0
419 #define ASTDP_AND_CLEAR_MASK 0x00
422 * ASTDP resoultion table:
426 * C: Misc information, such as CVT, Reduce Blanked
428 #define ASTDP_640x480_60 0x00
429 #define ASTDP_640x480_72 0x01
430 #define ASTDP_640x480_75 0x02
431 #define ASTDP_640x480_85 0x03
432 #define ASTDP_800x600_56 0x04
433 #define ASTDP_800x600_60 0x05
434 #define ASTDP_800x600_72 0x06
435 #define ASTDP_800x600_75 0x07
436 #define ASTDP_800x600_85 0x08
437 #define ASTDP_1024x768_60 0x09
438 #define ASTDP_1024x768_70 0x0A
439 #define ASTDP_1024x768_75 0x0B
440 #define ASTDP_1024x768_85 0x0C
441 #define ASTDP_1280x1024_60 0x0D
442 #define ASTDP_1280x1024_75 0x0E
443 #define ASTDP_1280x1024_85 0x0F
444 #define ASTDP_1600x1200_60 0x10
445 #define ASTDP_320x240_60 0x11
446 #define ASTDP_400x300_60 0x12
447 #define ASTDP_512x384_60 0x13
448 #define ASTDP_1920x1200_60 0x14
449 #define ASTDP_1920x1080_60 0x15
450 #define ASTDP_1280x800_60 0x16
451 #define ASTDP_1280x800_60_RB 0x17
452 #define ASTDP_1440x900_60 0x18
453 #define ASTDP_1440x900_60_RB 0x19
454 #define ASTDP_1680x1050_60 0x1A
455 #define ASTDP_1680x1050_60_RB 0x1B
456 #define ASTDP_1600x900_60 0x1C
457 #define ASTDP_1600x900_60_RB 0x1D
458 #define ASTDP_1366x768_60 0x1E
459 #define ASTDP_1152x864_75 0x1F
461 int ast_mm_init(struct ast_device *ast);
464 void ast_enable_vga(struct drm_device *dev);
465 void ast_enable_mmio(struct drm_device *dev);
466 bool ast_is_vga_enabled(struct drm_device *dev);
467 void ast_post_gpu(struct drm_device *dev);
468 u32 ast_mindwm(struct ast_device *ast, u32 r);
469 void ast_moutdwm(struct ast_device *ast, u32 r, u32 v);
470 void ast_patch_ahb_2500(struct ast_device *ast);
472 void ast_set_dp501_video_output(struct drm_device *dev, u8 mode);
473 bool ast_backup_fw(struct drm_device *dev, u8 *addr, u32 size);
474 bool ast_dp501_read_edid(struct drm_device *dev, u8 *ediddata);
475 u8 ast_get_dp501_max_clk(struct drm_device *dev);
476 void ast_init_3rdtx(struct drm_device *dev);
479 struct ast_i2c_chan *ast_i2c_create(struct drm_device *dev);
482 int ast_astdp_read_edid(struct drm_device *dev, u8 *ediddata);
483 void ast_dp_launch(struct drm_device *dev, u8 bPower);
484 void ast_dp_power_on_off(struct drm_device *dev, bool no);
485 void ast_dp_set_on_off(struct drm_device *dev, bool no);
486 void ast_dp_set_mode(struct drm_crtc *crtc, struct ast_vbios_mode_info *vbios_mode);