1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef LYNXDRV_H_
3 #define LYNXDRV_H_
4 #include "ddk750_chip.h"
5
6 #define FB_ACCEL_SMI 0xab
7
8 #define MHZ(x) ((x) * 1000000)
9
10 #define DEFAULT_SM750_CHIP_CLOCK 290
11 #define DEFAULT_SM750LE_CHIP_CLOCK 333
12 #ifndef SM750LE_REVISION_ID
13 #define SM750LE_REVISION_ID ((unsigned char)0xfe)
14 #endif
15
16 enum sm750_pnltype {
17 SM750_24TFT = 0, /* 24bit tft */
18 SM750_DUAL_TFT = 2, /* dual 18 bit tft */
19 SM750_DOUBLE_TFT = 1, /* 36 bit double pixel tft */
20 };
21
22 /* vga channel is not concerned */
23 enum sm750_dataflow {
24 sm750_simul_pri, /* primary => all head */
25 sm750_simul_sec, /* secondary => all head */
26 sm750_dual_normal, /* primary => panel head and secondary => crt */
27 sm750_dual_swap, /* primary => crt head and secondary => panel */
28 };
29
30 enum sm750_channel {
31 sm750_primary = 0,
32 /* enum value equal to the register filed data */
33 sm750_secondary = 1,
34 };
35
36 enum sm750_path {
37 sm750_panel = 1,
38 sm750_crt = 2,
39 sm750_pnc = 3, /* panel and crt */
40 };
41
42 struct lynx_accel {
43 /* base virtual address of DPR registers */
44 unsigned char __iomem *dpr_base;
45 /* base virtual address of de data port */
46 unsigned char __iomem *dp_port_base;
47
48 /* function pointers */
49 void (*de_init)(struct lynx_accel *accel);
50
51 int (*de_wait)(void); /* see if hardware ready to work */
52
53 int (*de_fillrect)(struct lynx_accel *accel,
54 u32 base, u32 pitch, u32 bpp,
55 u32 x, u32 y, u32 width, u32 height,
56 u32 color, u32 rop);
57
58 int (*de_copyarea)(struct lynx_accel *accel,
59 u32 s_base, u32 s_pitch,
60 u32 sx, u32 sy,
61 u32 d_base, u32 d_pitch,
62 u32 bpp, u32 dx, u32 dy,
63 u32 width, u32 height,
64 u32 rop2);
65
66 int (*de_imageblit)(struct lynx_accel *accel, const char *p_srcbuf,
67 u32 start_bit, u32 d_base, u32 d_pitch,
68 u32 byte_per_pixel, u32 dx, u32 dy, u32 width,
69 u32 height, u32 f_color, u32 b_color, u32 rop2);
70
71 };
72
73 struct sm750_dev {
74 /* common members */
75 u16 devid;
76 u8 revid;
77 struct pci_dev *pdev;
78 struct fb_info *fbinfo[2];
79 struct lynx_accel accel;
80 int accel_off;
81 int fb_count;
82 int mtrr_off;
83 struct{
84 int vram;
85 } mtrr;
86 /* all smi graphic adaptor got below attributes */
87 unsigned long vidmem_start;
88 unsigned long vidreg_start;
89 __u32 vidmem_size;
90 __u32 vidreg_size;
91 void __iomem *mmio;
92 unsigned char __iomem *vmem;
93 /* locks*/
94 spinlock_t slock;
95
96 struct initchip_param init_parm;
97 enum sm750_pnltype pnltype;
98 enum sm750_dataflow dataflow;
99 int nocrt;
100
101 /*
102 * 0: no hardware cursor
103 * 1: primary crtc hw cursor enabled,
104 * 2: secondary crtc hw cursor enabled
105 * 3: both ctrc hw cursor enabled
106 */
107 int hw_cursor;
108 };
109
110 struct lynx_cursor {
111 /* cursor width ,height and size */
112 int w;
113 int h;
114 int size;
115 /* hardware limitation */
116 int max_w;
117 int max_h;
118 /* base virtual address and offset of cursor image */
119 char __iomem *vstart;
120 int offset;
121 /* mmio addr of hw cursor */
122 char __iomem *mmio;
123 };
124
125 struct lynxfb_crtc {
126 unsigned char __iomem *v_cursor; /* virtual address of cursor */
127 unsigned char __iomem *v_screen; /* virtual address of on_screen */
128 int o_cursor; /* cursor address offset in vidmem */
129 int o_screen; /* onscreen address offset in vidmem */
130 int channel;/* which channel this crtc stands for*/
131 resource_size_t vidmem_size;/* this view's video memory max size */
132
133 /* below attributes belong to info->fix, their value depends on specific adaptor*/
134 u16 line_pad;/* padding information:0,1,2,4,8,16,... */
135 u16 xpanstep;
136 u16 ypanstep;
137 u16 ywrapstep;
138
139 /* cursor information */
140 struct lynx_cursor cursor;
141 };
142
143 struct lynxfb_output {
144 int dpms;
145 int paths;
146 /*
147 * which paths(s) this output stands for,for sm750:
148 * paths=1:means output for panel paths
149 * paths=2:means output for crt paths
150 * paths=3:means output for both panel and crt paths
151 */
152
153 int *channel;
154 /*
155 * which channel these outputs linked with,for sm750:
156 * *channel=0 means primary channel
157 * *channel=1 means secondary channel
158 * output->channel ==> &crtc->channel
159 */
160 };
161
162 struct lynxfb_par {
163 /* either 0 or 1 for dual head adaptor,0 is the older one registered */
164 int index;
165 unsigned int pseudo_palette[256];
166 struct lynxfb_crtc crtc;
167 struct lynxfb_output output;
168 struct fb_info *info;
169 struct sm750_dev *dev;
170 };
171
ps_to_hz(unsigned int psvalue)172 static inline unsigned long ps_to_hz(unsigned int psvalue)
173 {
174 unsigned long long numerator = 1000 * 1000 * 1000 * 1000ULL;
175 /* 10^12 / picosecond period gives frequency in Hz */
176 do_div(numerator, psvalue);
177 return (unsigned long)numerator;
178 }
179
180 int hw_sm750_map(struct sm750_dev *sm750_dev, struct pci_dev *pdev);
181 int hw_sm750_inithw(struct sm750_dev *sm750_dev, struct pci_dev *pdev);
182 void hw_sm750_init_accel(struct sm750_dev *sm750_dev);
183 int hw_sm750_de_wait(void);
184 int hw_sm750le_de_wait(void);
185
186 int hw_sm750_output_set_mode(struct lynxfb_output *output,
187 struct fb_var_screeninfo *var,
188 struct fb_fix_screeninfo *fix);
189
190 int hw_sm750_crtc_check_mode(struct lynxfb_crtc *crtc,
191 struct fb_var_screeninfo *var);
192
193 int hw_sm750_crtc_set_mode(struct lynxfb_crtc *crtc,
194 struct fb_var_screeninfo *var,
195 struct fb_fix_screeninfo *fix);
196
197 int hw_sm750_set_col_reg(struct lynxfb_crtc *crtc, ushort index,
198 ushort red, ushort green, ushort blue);
199
200 int hw_sm750_set_blank(struct lynxfb_output *output, int blank);
201 int hw_sm750le_set_blank(struct lynxfb_output *output, int blank);
202 int hw_sm750_pan_display(struct lynxfb_crtc *crtc,
203 const struct fb_var_screeninfo *var,
204 const struct fb_info *info);
205
206 #endif
207