Home | History | Annotate | Line # | Download | only in ast
      1  1.2  riastrad /*	$NetBSD: ast_drv.h,v 1.3 2021/12/18 23:45:27 riastradh Exp $	*/
      2  1.2  riastrad 
      3  1.1  riastrad /*
      4  1.1  riastrad  * Copyright 2012 Red Hat Inc.
      5  1.1  riastrad  *
      6  1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining a
      7  1.1  riastrad  * copy of this software and associated documentation files (the
      8  1.1  riastrad  * "Software"), to deal in the Software without restriction, including
      9  1.1  riastrad  * without limitation the rights to use, copy, modify, merge, publish,
     10  1.1  riastrad  * distribute, sub license, and/or sell copies of the Software, and to
     11  1.1  riastrad  * permit persons to whom the Software is furnished to do so, subject to
     12  1.1  riastrad  * the following conditions:
     13  1.1  riastrad  *
     14  1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     15  1.1  riastrad  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     16  1.1  riastrad  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
     17  1.1  riastrad  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
     18  1.1  riastrad  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
     19  1.1  riastrad  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
     20  1.1  riastrad  * USE OR OTHER DEALINGS IN THE SOFTWARE.
     21  1.1  riastrad  *
     22  1.1  riastrad  * The above copyright notice and this permission notice (including the
     23  1.1  riastrad  * next paragraph) shall be included in all copies or substantial portions
     24  1.1  riastrad  * of the Software.
     25  1.1  riastrad  *
     26  1.1  riastrad  */
     27  1.1  riastrad /*
     28  1.1  riastrad  * Authors: Dave Airlie <airlied (at) redhat.com>
     29  1.1  riastrad  */
     30  1.1  riastrad #ifndef __AST_DRV_H__
     31  1.1  riastrad #define __AST_DRV_H__
     32  1.1  riastrad 
     33  1.3  riastrad #include <linux/types.h>
     34  1.3  riastrad #include <linux/io.h>
     35  1.1  riastrad #include <linux/i2c.h>
     36  1.1  riastrad #include <linux/i2c-algo-bit.h>
     37  1.1  riastrad 
     38  1.3  riastrad #include <drm/drm_connector.h>
     39  1.3  riastrad #include <drm/drm_crtc.h>
     40  1.3  riastrad #include <drm/drm_encoder.h>
     41  1.3  riastrad #include <drm/drm_mode.h>
     42  1.3  riastrad #include <drm/drm_framebuffer.h>
     43  1.3  riastrad #include <drm/drm_fb_helper.h>
     44  1.3  riastrad 
     45  1.1  riastrad #define DRIVER_AUTHOR		"Dave Airlie"
     46  1.1  riastrad 
     47  1.1  riastrad #define DRIVER_NAME		"ast"
     48  1.1  riastrad #define DRIVER_DESC		"AST"
     49  1.1  riastrad #define DRIVER_DATE		"20120228"
     50  1.1  riastrad 
     51  1.1  riastrad #define DRIVER_MAJOR		0
     52  1.1  riastrad #define DRIVER_MINOR		1
     53  1.1  riastrad #define DRIVER_PATCHLEVEL	0
     54  1.1  riastrad 
     55  1.1  riastrad #define PCI_CHIP_AST2000 0x2000
     56  1.1  riastrad #define PCI_CHIP_AST2100 0x2010
     57  1.1  riastrad #define PCI_CHIP_AST1180 0x1180
     58  1.1  riastrad 
     59  1.1  riastrad 
     60  1.1  riastrad enum ast_chip {
     61  1.1  riastrad 	AST2000,
     62  1.1  riastrad 	AST2100,
     63  1.1  riastrad 	AST1100,
     64  1.1  riastrad 	AST2200,
     65  1.1  riastrad 	AST2150,
     66  1.1  riastrad 	AST2300,
     67  1.2  riastrad 	AST2400,
     68  1.3  riastrad 	AST2500,
     69  1.1  riastrad 	AST1180,
     70  1.1  riastrad };
     71  1.1  riastrad 
     72  1.2  riastrad enum ast_tx_chip {
     73  1.2  riastrad 	AST_TX_NONE,
     74  1.2  riastrad 	AST_TX_SIL164,
     75  1.2  riastrad 	AST_TX_ITE66121,
     76  1.2  riastrad 	AST_TX_DP501,
     77  1.2  riastrad };
     78  1.2  riastrad 
     79  1.1  riastrad #define AST_DRAM_512Mx16 0
     80  1.1  riastrad #define AST_DRAM_1Gx16   1
     81  1.1  riastrad #define AST_DRAM_512Mx32 2
     82  1.1  riastrad #define AST_DRAM_1Gx32   3
     83  1.1  riastrad #define AST_DRAM_2Gx16   6
     84  1.1  riastrad #define AST_DRAM_4Gx16   7
     85  1.3  riastrad #define AST_DRAM_8Gx16   8
     86  1.3  riastrad 
     87  1.3  riastrad 
     88  1.3  riastrad #define AST_MAX_HWC_WIDTH	64
     89  1.3  riastrad #define AST_MAX_HWC_HEIGHT	64
     90  1.3  riastrad 
     91  1.3  riastrad #define AST_HWC_SIZE		(AST_MAX_HWC_WIDTH * AST_MAX_HWC_HEIGHT * 2)
     92  1.3  riastrad #define AST_HWC_SIGNATURE_SIZE	32
     93  1.3  riastrad 
     94  1.3  riastrad #define AST_DEFAULT_HWC_NUM	2
     95  1.3  riastrad 
     96  1.3  riastrad /* define for signature structure */
     97  1.3  riastrad #define AST_HWC_SIGNATURE_CHECKSUM	0x00
     98  1.3  riastrad #define AST_HWC_SIGNATURE_SizeX		0x04
     99  1.3  riastrad #define AST_HWC_SIGNATURE_SizeY		0x08
    100  1.3  riastrad #define AST_HWC_SIGNATURE_X		0x0C
    101  1.3  riastrad #define AST_HWC_SIGNATURE_Y		0x10
    102  1.3  riastrad #define AST_HWC_SIGNATURE_HOTSPOTX	0x14
    103  1.3  riastrad #define AST_HWC_SIGNATURE_HOTSPOTY	0x18
    104  1.1  riastrad 
    105  1.1  riastrad 
    106  1.1  riastrad struct ast_private {
    107  1.1  riastrad 	struct drm_device *dev;
    108  1.1  riastrad 
    109  1.1  riastrad 	void __iomem *regs;
    110  1.1  riastrad 	void __iomem *ioregs;
    111  1.1  riastrad 
    112  1.1  riastrad 	enum ast_chip chip;
    113  1.1  riastrad 	bool vga2_clone;
    114  1.1  riastrad 	uint32_t dram_bus_width;
    115  1.1  riastrad 	uint32_t dram_type;
    116  1.1  riastrad 	uint32_t mclk;
    117  1.1  riastrad 	uint32_t vram_size;
    118  1.1  riastrad 
    119  1.1  riastrad 	int fb_mtrr;
    120  1.1  riastrad 
    121  1.1  riastrad 	struct {
    122  1.3  riastrad 		struct drm_gem_vram_object *gbo[AST_DEFAULT_HWC_NUM];
    123  1.3  riastrad 		unsigned int next_index;
    124  1.3  riastrad 	} cursor;
    125  1.3  riastrad 
    126  1.3  riastrad 	struct drm_plane primary_plane;
    127  1.3  riastrad 	struct drm_plane cursor_plane;
    128  1.3  riastrad 
    129  1.2  riastrad 	bool support_wide_screen;
    130  1.2  riastrad 	enum {
    131  1.2  riastrad 		ast_use_p2a,
    132  1.2  riastrad 		ast_use_dt,
    133  1.2  riastrad 		ast_use_defaults
    134  1.2  riastrad 	} config_mode;
    135  1.2  riastrad 
    136  1.2  riastrad 	enum ast_tx_chip tx_chip_type;
    137  1.2  riastrad 	u8 dp501_maxclk;
    138  1.2  riastrad 	u8 *dp501_fw_addr;
    139  1.2  riastrad 	const struct firmware *dp501_fw;	/* dp501 fw */
    140  1.1  riastrad };
    141  1.1  riastrad 
    142  1.1  riastrad int ast_driver_load(struct drm_device *dev, unsigned long flags);
    143  1.3  riastrad void ast_driver_unload(struct drm_device *dev);
    144  1.1  riastrad 
    145  1.1  riastrad #define AST_IO_AR_PORT_WRITE		(0x40)
    146  1.1  riastrad #define AST_IO_MISC_PORT_WRITE		(0x42)
    147  1.2  riastrad #define AST_IO_VGA_ENABLE_PORT		(0x43)
    148  1.1  riastrad #define AST_IO_SEQ_PORT			(0x44)
    149  1.2  riastrad #define AST_IO_DAC_INDEX_READ		(0x47)
    150  1.1  riastrad #define AST_IO_DAC_INDEX_WRITE		(0x48)
    151  1.1  riastrad #define AST_IO_DAC_DATA		        (0x49)
    152  1.1  riastrad #define AST_IO_GR_PORT			(0x4E)
    153  1.1  riastrad #define AST_IO_CRTC_PORT		(0x54)
    154  1.1  riastrad #define AST_IO_INPUT_STATUS1_READ	(0x5A)
    155  1.1  riastrad #define AST_IO_MISC_PORT_READ		(0x4C)
    156  1.1  riastrad 
    157  1.2  riastrad #define AST_IO_MM_OFFSET		(0x380)
    158  1.2  riastrad 
    159  1.1  riastrad #define __ast_read(x) \
    160  1.1  riastrad static inline u##x ast_read##x(struct ast_private *ast, u32 reg) { \
    161  1.1  riastrad u##x val = 0;\
    162  1.1  riastrad val = ioread##x(ast->regs + reg); \
    163  1.1  riastrad return val;\
    164  1.1  riastrad }
    165  1.1  riastrad 
    166  1.1  riastrad __ast_read(8);
    167  1.1  riastrad __ast_read(16);
    168  1.1  riastrad __ast_read(32)
    169  1.1  riastrad 
    170  1.1  riastrad #define __ast_io_read(x) \
    171  1.1  riastrad static inline u##x ast_io_read##x(struct ast_private *ast, u32 reg) { \
    172  1.1  riastrad u##x val = 0;\
    173  1.1  riastrad val = ioread##x(ast->ioregs + reg); \
    174  1.1  riastrad return val;\
    175  1.1  riastrad }
    176  1.1  riastrad 
    177  1.1  riastrad __ast_io_read(8);
    178  1.1  riastrad __ast_io_read(16);
    179  1.1  riastrad __ast_io_read(32);
    180  1.1  riastrad 
    181  1.1  riastrad #define __ast_write(x) \
    182  1.1  riastrad static inline void ast_write##x(struct ast_private *ast, u32 reg, u##x val) {\
    183  1.1  riastrad 	iowrite##x(val, ast->regs + reg);\
    184  1.1  riastrad 	}
    185  1.1  riastrad 
    186  1.1  riastrad __ast_write(8);
    187  1.1  riastrad __ast_write(16);
    188  1.1  riastrad __ast_write(32);
    189  1.1  riastrad 
    190  1.1  riastrad #define __ast_io_write(x) \
    191  1.1  riastrad static inline void ast_io_write##x(struct ast_private *ast, u32 reg, u##x val) {\
    192  1.1  riastrad 	iowrite##x(val, ast->ioregs + reg);\
    193  1.1  riastrad 	}
    194  1.1  riastrad 
    195  1.1  riastrad __ast_io_write(8);
    196  1.1  riastrad __ast_io_write(16);
    197  1.1  riastrad #undef __ast_io_write
    198  1.1  riastrad 
    199  1.1  riastrad static inline void ast_set_index_reg(struct ast_private *ast,
    200  1.1  riastrad 				     uint32_t base, uint8_t index,
    201  1.1  riastrad 				     uint8_t val)
    202  1.1  riastrad {
    203  1.1  riastrad 	ast_io_write16(ast, base, ((u16)val << 8) | index);
    204  1.1  riastrad }
    205  1.1  riastrad 
    206  1.1  riastrad void ast_set_index_reg_mask(struct ast_private *ast,
    207  1.1  riastrad 			    uint32_t base, uint8_t index,
    208  1.1  riastrad 			    uint8_t mask, uint8_t val);
    209  1.1  riastrad uint8_t ast_get_index_reg(struct ast_private *ast,
    210  1.1  riastrad 			  uint32_t base, uint8_t index);
    211  1.1  riastrad uint8_t ast_get_index_reg_mask(struct ast_private *ast,
    212  1.1  riastrad 			       uint32_t base, uint8_t index, uint8_t mask);
    213  1.1  riastrad 
    214  1.1  riastrad static inline void ast_open_key(struct ast_private *ast)
    215  1.1  riastrad {
    216  1.2  riastrad 	ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x80, 0xA8);
    217  1.1  riastrad }
    218  1.1  riastrad 
    219  1.1  riastrad #define AST_VIDMEM_SIZE_8M    0x00800000
    220  1.1  riastrad #define AST_VIDMEM_SIZE_16M   0x01000000
    221  1.1  riastrad #define AST_VIDMEM_SIZE_32M   0x02000000
    222  1.1  riastrad #define AST_VIDMEM_SIZE_64M   0x04000000
    223  1.1  riastrad #define AST_VIDMEM_SIZE_128M  0x08000000
    224  1.1  riastrad 
    225  1.1  riastrad #define AST_VIDMEM_DEFAULT_SIZE AST_VIDMEM_SIZE_8M
    226  1.1  riastrad 
    227  1.1  riastrad struct ast_i2c_chan {
    228  1.1  riastrad 	struct i2c_adapter adapter;
    229  1.1  riastrad 	struct drm_device *dev;
    230  1.1  riastrad 	struct i2c_algo_bit_data bit;
    231  1.1  riastrad };
    232  1.1  riastrad 
    233  1.1  riastrad struct ast_connector {
    234  1.1  riastrad 	struct drm_connector base;
    235  1.1  riastrad 	struct ast_i2c_chan *i2c;
    236  1.1  riastrad };
    237  1.1  riastrad 
    238  1.1  riastrad struct ast_crtc {
    239  1.1  riastrad 	struct drm_crtc base;
    240  1.1  riastrad 	u8 offset_x, offset_y;
    241  1.1  riastrad };
    242  1.1  riastrad 
    243  1.1  riastrad struct ast_encoder {
    244  1.1  riastrad 	struct drm_encoder base;
    245  1.1  riastrad };
    246  1.1  riastrad 
    247  1.1  riastrad #define to_ast_crtc(x) container_of(x, struct ast_crtc, base)
    248  1.1  riastrad #define to_ast_connector(x) container_of(x, struct ast_connector, base)
    249  1.1  riastrad #define to_ast_encoder(x) container_of(x, struct ast_encoder, base)
    250  1.1  riastrad 
    251  1.1  riastrad struct ast_vbios_stdtable {
    252  1.1  riastrad 	u8 misc;
    253  1.1  riastrad 	u8 seq[4];
    254  1.1  riastrad 	u8 crtc[25];
    255  1.1  riastrad 	u8 ar[20];
    256  1.1  riastrad 	u8 gr[9];
    257  1.1  riastrad };
    258  1.1  riastrad 
    259  1.1  riastrad struct ast_vbios_enhtable {
    260  1.1  riastrad 	u32 ht;
    261  1.1  riastrad 	u32 hde;
    262  1.1  riastrad 	u32 hfp;
    263  1.1  riastrad 	u32 hsync;
    264  1.1  riastrad 	u32 vt;
    265  1.1  riastrad 	u32 vde;
    266  1.1  riastrad 	u32 vfp;
    267  1.1  riastrad 	u32 vsync;
    268  1.1  riastrad 	u32 dclk_index;
    269  1.1  riastrad 	u32 flags;
    270  1.1  riastrad 	u32 refresh_rate;
    271  1.1  riastrad 	u32 refresh_rate_index;
    272  1.1  riastrad 	u32 mode_id;
    273  1.1  riastrad };
    274  1.1  riastrad 
    275  1.1  riastrad struct ast_vbios_dclk_info {
    276  1.1  riastrad 	u8 param1;
    277  1.1  riastrad 	u8 param2;
    278  1.1  riastrad 	u8 param3;
    279  1.1  riastrad };
    280  1.1  riastrad 
    281  1.1  riastrad struct ast_vbios_mode_info {
    282  1.3  riastrad 	const struct ast_vbios_stdtable *std_table;
    283  1.3  riastrad 	const struct ast_vbios_enhtable *enh_table;
    284  1.1  riastrad };
    285  1.1  riastrad 
    286  1.3  riastrad struct ast_crtc_state {
    287  1.3  riastrad 	struct drm_crtc_state base;
    288  1.3  riastrad 
    289  1.3  riastrad 	/* Last known format of primary plane */
    290  1.3  riastrad 	const struct drm_format_info *format;
    291  1.1  riastrad 
    292  1.3  riastrad 	struct ast_vbios_mode_info vbios_mode_info;
    293  1.1  riastrad };
    294  1.1  riastrad 
    295  1.3  riastrad #define to_ast_crtc_state(state) container_of(state, struct ast_crtc_state, base)
    296  1.1  riastrad 
    297  1.3  riastrad extern int ast_mode_init(struct drm_device *dev);
    298  1.3  riastrad extern void ast_mode_fini(struct drm_device *dev);
    299  1.1  riastrad 
    300  1.1  riastrad #define AST_MM_ALIGN_SHIFT 4
    301  1.1  riastrad #define AST_MM_ALIGN_MASK ((1 << AST_MM_ALIGN_SHIFT) - 1)
    302  1.1  riastrad 
    303  1.1  riastrad int ast_mm_init(struct ast_private *ast);
    304  1.1  riastrad void ast_mm_fini(struct ast_private *ast);
    305  1.1  riastrad 
    306  1.1  riastrad /* ast post */
    307  1.2  riastrad void ast_enable_vga(struct drm_device *dev);
    308  1.2  riastrad void ast_enable_mmio(struct drm_device *dev);
    309  1.2  riastrad bool ast_is_vga_enabled(struct drm_device *dev);
    310  1.1  riastrad void ast_post_gpu(struct drm_device *dev);
    311  1.2  riastrad u32 ast_mindwm(struct ast_private *ast, u32 r);
    312  1.2  riastrad void ast_moutdwm(struct ast_private *ast, u32 r, u32 v);
    313  1.2  riastrad /* ast dp501 */
    314  1.2  riastrad void ast_set_dp501_video_output(struct drm_device *dev, u8 mode);
    315  1.2  riastrad bool ast_backup_fw(struct drm_device *dev, u8 *addr, u32 size);
    316  1.2  riastrad bool ast_dp501_read_edid(struct drm_device *dev, u8 *ediddata);
    317  1.2  riastrad u8 ast_get_dp501_max_clk(struct drm_device *dev);
    318  1.2  riastrad void ast_init_3rdtx(struct drm_device *dev);
    319  1.3  riastrad void ast_release_firmware(struct drm_device *dev);
    320  1.1  riastrad #endif
    321