Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/video/arkfb.c -- Frame buffer device driver for ARK 2000PV |
| 3 | * with ICS 5342 dac (it is easy to add support for different dacs). |
| 4 | * |
| 5 | * Copyright (c) 2007 Ondrej Zajicek <santiago@crfreenet.org> |
| 6 | * |
| 7 | * This file is subject to the terms and conditions of the GNU General Public |
| 8 | * License. See the file COPYING in the main directory of this archive for |
| 9 | * more details. |
| 10 | * |
| 11 | * Code is based on s3fb |
| 12 | */ |
| 13 | |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 14 | #include <linux/module.h> |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/errno.h> |
| 17 | #include <linux/string.h> |
| 18 | #include <linux/mm.h> |
| 19 | #include <linux/tty.h> |
| 20 | #include <linux/slab.h> |
| 21 | #include <linux/delay.h> |
| 22 | #include <linux/fb.h> |
| 23 | #include <linux/svga.h> |
| 24 | #include <linux/init.h> |
| 25 | #include <linux/pci.h> |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 26 | #include <linux/console.h> /* Why should fb driver call console functions? because console_lock() */ |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 27 | #include <video/vga.h> |
| 28 | |
| 29 | #ifdef CONFIG_MTRR |
| 30 | #include <asm/mtrr.h> |
| 31 | #endif |
| 32 | |
| 33 | struct arkfb_info { |
| 34 | int mclk_freq; |
| 35 | int mtrr_reg; |
| 36 | |
| 37 | struct dac_info *dac; |
| 38 | struct vgastate state; |
| 39 | struct mutex open_lock; |
| 40 | unsigned int ref_count; |
| 41 | u32 pseudo_palette[16]; |
| 42 | }; |
| 43 | |
| 44 | |
| 45 | /* ------------------------------------------------------------------------- */ |
| 46 | |
| 47 | |
| 48 | static const struct svga_fb_format arkfb_formats[] = { |
| 49 | { 0, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0, |
| 50 | FB_TYPE_TEXT, FB_AUX_TEXT_SVGA_STEP4, FB_VISUAL_PSEUDOCOLOR, 8, 8}, |
| 51 | { 4, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0, |
| 52 | FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_PSEUDOCOLOR, 8, 16}, |
| 53 | { 4, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 1, |
| 54 | FB_TYPE_INTERLEAVED_PLANES, 1, FB_VISUAL_PSEUDOCOLOR, 8, 16}, |
| 55 | { 8, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0, |
| 56 | FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_PSEUDOCOLOR, 8, 8}, |
| 57 | {16, {10, 5, 0}, {5, 5, 0}, {0, 5, 0}, {0, 0, 0}, 0, |
| 58 | FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 4, 4}, |
| 59 | {16, {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0}, 0, |
| 60 | FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 4, 4}, |
| 61 | {24, {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0, |
| 62 | FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 8, 8}, |
| 63 | {32, {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0, |
| 64 | FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 2, 2}, |
| 65 | SVGA_FORMAT_END |
| 66 | }; |
| 67 | |
| 68 | |
| 69 | /* CRT timing register sets */ |
| 70 | |
| 71 | static const struct vga_regset ark_h_total_regs[] = {{0x00, 0, 7}, {0x41, 7, 7}, VGA_REGSET_END}; |
| 72 | static const struct vga_regset ark_h_display_regs[] = {{0x01, 0, 7}, {0x41, 6, 6}, VGA_REGSET_END}; |
| 73 | static const struct vga_regset ark_h_blank_start_regs[] = {{0x02, 0, 7}, {0x41, 5, 5}, VGA_REGSET_END}; |
| 74 | static const struct vga_regset ark_h_blank_end_regs[] = {{0x03, 0, 4}, {0x05, 7, 7 }, VGA_REGSET_END}; |
| 75 | static const struct vga_regset ark_h_sync_start_regs[] = {{0x04, 0, 7}, {0x41, 4, 4}, VGA_REGSET_END}; |
| 76 | static const struct vga_regset ark_h_sync_end_regs[] = {{0x05, 0, 4}, VGA_REGSET_END}; |
| 77 | |
| 78 | static const struct vga_regset ark_v_total_regs[] = {{0x06, 0, 7}, {0x07, 0, 0}, {0x07, 5, 5}, {0x40, 7, 7}, VGA_REGSET_END}; |
| 79 | static const struct vga_regset ark_v_display_regs[] = {{0x12, 0, 7}, {0x07, 1, 1}, {0x07, 6, 6}, {0x40, 6, 6}, VGA_REGSET_END}; |
| 80 | static const struct vga_regset ark_v_blank_start_regs[] = {{0x15, 0, 7}, {0x07, 3, 3}, {0x09, 5, 5}, {0x40, 5, 5}, VGA_REGSET_END}; |
| 81 | // const struct vga_regset ark_v_blank_end_regs[] = {{0x16, 0, 6}, VGA_REGSET_END}; |
| 82 | static const struct vga_regset ark_v_blank_end_regs[] = {{0x16, 0, 7}, VGA_REGSET_END}; |
| 83 | static const struct vga_regset ark_v_sync_start_regs[] = {{0x10, 0, 7}, {0x07, 2, 2}, {0x07, 7, 7}, {0x40, 4, 4}, VGA_REGSET_END}; |
| 84 | static const struct vga_regset ark_v_sync_end_regs[] = {{0x11, 0, 3}, VGA_REGSET_END}; |
| 85 | |
| 86 | static const struct vga_regset ark_line_compare_regs[] = {{0x18, 0, 7}, {0x07, 4, 4}, {0x09, 6, 6}, VGA_REGSET_END}; |
| 87 | static const struct vga_regset ark_start_address_regs[] = {{0x0d, 0, 7}, {0x0c, 0, 7}, {0x40, 0, 2}, VGA_REGSET_END}; |
| 88 | static const struct vga_regset ark_offset_regs[] = {{0x13, 0, 7}, {0x41, 3, 3}, VGA_REGSET_END}; |
| 89 | |
| 90 | static const struct svga_timing_regs ark_timing_regs = { |
| 91 | ark_h_total_regs, ark_h_display_regs, ark_h_blank_start_regs, |
| 92 | ark_h_blank_end_regs, ark_h_sync_start_regs, ark_h_sync_end_regs, |
| 93 | ark_v_total_regs, ark_v_display_regs, ark_v_blank_start_regs, |
| 94 | ark_v_blank_end_regs, ark_v_sync_start_regs, ark_v_sync_end_regs, |
| 95 | }; |
| 96 | |
| 97 | |
| 98 | /* ------------------------------------------------------------------------- */ |
| 99 | |
| 100 | |
| 101 | /* Module parameters */ |
| 102 | |
Krzysztof Helt | 1abf917 | 2008-04-28 02:15:08 -0700 | [diff] [blame] | 103 | static char *mode_option __devinitdata = "640x480-8@60"; |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 104 | |
| 105 | #ifdef CONFIG_MTRR |
| 106 | static int mtrr = 1; |
| 107 | #endif |
| 108 | |
| 109 | MODULE_AUTHOR("(c) 2007 Ondrej Zajicek <santiago@crfreenet.org>"); |
| 110 | MODULE_LICENSE("GPL"); |
| 111 | MODULE_DESCRIPTION("fbdev driver for ARK 2000PV"); |
| 112 | |
Krzysztof Helt | 1abf917 | 2008-04-28 02:15:08 -0700 | [diff] [blame] | 113 | module_param(mode_option, charp, 0444); |
| 114 | MODULE_PARM_DESC(mode_option, "Default video mode ('640x480-8@60', etc)"); |
| 115 | module_param_named(mode, mode_option, charp, 0444); |
| 116 | MODULE_PARM_DESC(mode, "Default video mode ('640x480-8@60', etc) (deprecated)"); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 117 | |
| 118 | #ifdef CONFIG_MTRR |
| 119 | module_param(mtrr, int, 0444); |
| 120 | MODULE_PARM_DESC(mtrr, "Enable write-combining with MTRR (1=enable, 0=disable, default=1)"); |
| 121 | #endif |
| 122 | |
| 123 | static int threshold = 4; |
| 124 | |
| 125 | module_param(threshold, int, 0644); |
| 126 | MODULE_PARM_DESC(threshold, "FIFO threshold"); |
| 127 | |
| 128 | |
| 129 | /* ------------------------------------------------------------------------- */ |
| 130 | |
| 131 | |
| 132 | static void arkfb_settile(struct fb_info *info, struct fb_tilemap *map) |
| 133 | { |
| 134 | const u8 *font = map->data; |
| 135 | u8 __iomem *fb = (u8 __iomem *)info->screen_base; |
| 136 | int i, c; |
| 137 | |
| 138 | if ((map->width != 8) || (map->height != 16) || |
| 139 | (map->depth != 1) || (map->length != 256)) { |
| 140 | printk(KERN_ERR "fb%d: unsupported font parameters: width %d, " |
| 141 | "height %d, depth %d, length %d\n", info->node, |
| 142 | map->width, map->height, map->depth, map->length); |
| 143 | return; |
| 144 | } |
| 145 | |
| 146 | fb += 2; |
| 147 | for (c = 0; c < map->length; c++) { |
| 148 | for (i = 0; i < map->height; i++) { |
| 149 | fb_writeb(font[i], &fb[i * 4]); |
| 150 | fb_writeb(font[i], &fb[i * 4 + (128 * 8)]); |
| 151 | } |
| 152 | fb += 128; |
| 153 | |
| 154 | if ((c % 8) == 7) |
| 155 | fb += 128*8; |
| 156 | |
| 157 | font += map->height; |
| 158 | } |
| 159 | } |
| 160 | |
David Miller | 55db092 | 2011-01-11 23:52:11 +0000 | [diff] [blame] | 161 | static void arkfb_tilecursor(struct fb_info *info, struct fb_tilecursor *cursor) |
| 162 | { |
| 163 | struct arkfb_info *par = info->par; |
| 164 | |
| 165 | svga_tilecursor(par->state.vgabase, info, cursor); |
| 166 | } |
| 167 | |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 168 | static struct fb_tile_ops arkfb_tile_ops = { |
| 169 | .fb_settile = arkfb_settile, |
| 170 | .fb_tilecopy = svga_tilecopy, |
| 171 | .fb_tilefill = svga_tilefill, |
| 172 | .fb_tileblit = svga_tileblit, |
David Miller | 55db092 | 2011-01-11 23:52:11 +0000 | [diff] [blame] | 173 | .fb_tilecursor = arkfb_tilecursor, |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 174 | .fb_get_tilemax = svga_get_tilemax, |
| 175 | }; |
| 176 | |
| 177 | |
| 178 | /* ------------------------------------------------------------------------- */ |
| 179 | |
| 180 | |
| 181 | /* image data is MSB-first, fb structure is MSB-first too */ |
| 182 | static inline u32 expand_color(u32 c) |
| 183 | { |
| 184 | return ((c & 1) | ((c & 2) << 7) | ((c & 4) << 14) | ((c & 8) << 21)) * 0xFF; |
| 185 | } |
| 186 | |
| 187 | /* arkfb_iplan_imageblit silently assumes that almost everything is 8-pixel aligned */ |
| 188 | static void arkfb_iplan_imageblit(struct fb_info *info, const struct fb_image *image) |
| 189 | { |
| 190 | u32 fg = expand_color(image->fg_color); |
| 191 | u32 bg = expand_color(image->bg_color); |
| 192 | const u8 *src1, *src; |
| 193 | u8 __iomem *dst1; |
| 194 | u32 __iomem *dst; |
| 195 | u32 val; |
| 196 | int x, y; |
| 197 | |
| 198 | src1 = image->data; |
| 199 | dst1 = info->screen_base + (image->dy * info->fix.line_length) |
| 200 | + ((image->dx / 8) * 4); |
| 201 | |
| 202 | for (y = 0; y < image->height; y++) { |
| 203 | src = src1; |
| 204 | dst = (u32 __iomem *) dst1; |
| 205 | for (x = 0; x < image->width; x += 8) { |
| 206 | val = *(src++) * 0x01010101; |
| 207 | val = (val & fg) | (~val & bg); |
| 208 | fb_writel(val, dst++); |
| 209 | } |
| 210 | src1 += image->width / 8; |
| 211 | dst1 += info->fix.line_length; |
| 212 | } |
| 213 | |
| 214 | } |
| 215 | |
| 216 | /* arkfb_iplan_fillrect silently assumes that almost everything is 8-pixel aligned */ |
| 217 | static void arkfb_iplan_fillrect(struct fb_info *info, const struct fb_fillrect *rect) |
| 218 | { |
| 219 | u32 fg = expand_color(rect->color); |
| 220 | u8 __iomem *dst1; |
| 221 | u32 __iomem *dst; |
| 222 | int x, y; |
| 223 | |
| 224 | dst1 = info->screen_base + (rect->dy * info->fix.line_length) |
| 225 | + ((rect->dx / 8) * 4); |
| 226 | |
| 227 | for (y = 0; y < rect->height; y++) { |
| 228 | dst = (u32 __iomem *) dst1; |
| 229 | for (x = 0; x < rect->width; x += 8) { |
| 230 | fb_writel(fg, dst++); |
| 231 | } |
| 232 | dst1 += info->fix.line_length; |
| 233 | } |
| 234 | |
| 235 | } |
| 236 | |
| 237 | |
| 238 | /* image data is MSB-first, fb structure is high-nibble-in-low-byte-first */ |
| 239 | static inline u32 expand_pixel(u32 c) |
| 240 | { |
| 241 | return (((c & 1) << 24) | ((c & 2) << 27) | ((c & 4) << 14) | ((c & 8) << 17) | |
| 242 | ((c & 16) << 4) | ((c & 32) << 7) | ((c & 64) >> 6) | ((c & 128) >> 3)) * 0xF; |
| 243 | } |
| 244 | |
| 245 | /* arkfb_cfb4_imageblit silently assumes that almost everything is 8-pixel aligned */ |
| 246 | static void arkfb_cfb4_imageblit(struct fb_info *info, const struct fb_image *image) |
| 247 | { |
| 248 | u32 fg = image->fg_color * 0x11111111; |
| 249 | u32 bg = image->bg_color * 0x11111111; |
| 250 | const u8 *src1, *src; |
| 251 | u8 __iomem *dst1; |
| 252 | u32 __iomem *dst; |
| 253 | u32 val; |
| 254 | int x, y; |
| 255 | |
| 256 | src1 = image->data; |
| 257 | dst1 = info->screen_base + (image->dy * info->fix.line_length) |
| 258 | + ((image->dx / 8) * 4); |
| 259 | |
| 260 | for (y = 0; y < image->height; y++) { |
| 261 | src = src1; |
| 262 | dst = (u32 __iomem *) dst1; |
| 263 | for (x = 0; x < image->width; x += 8) { |
| 264 | val = expand_pixel(*(src++)); |
| 265 | val = (val & fg) | (~val & bg); |
| 266 | fb_writel(val, dst++); |
| 267 | } |
| 268 | src1 += image->width / 8; |
| 269 | dst1 += info->fix.line_length; |
| 270 | } |
| 271 | |
| 272 | } |
| 273 | |
| 274 | static void arkfb_imageblit(struct fb_info *info, const struct fb_image *image) |
| 275 | { |
| 276 | if ((info->var.bits_per_pixel == 4) && (image->depth == 1) |
| 277 | && ((image->width % 8) == 0) && ((image->dx % 8) == 0)) { |
| 278 | if (info->fix.type == FB_TYPE_INTERLEAVED_PLANES) |
| 279 | arkfb_iplan_imageblit(info, image); |
| 280 | else |
| 281 | arkfb_cfb4_imageblit(info, image); |
| 282 | } else |
| 283 | cfb_imageblit(info, image); |
| 284 | } |
| 285 | |
| 286 | static void arkfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect) |
| 287 | { |
| 288 | if ((info->var.bits_per_pixel == 4) |
| 289 | && ((rect->width % 8) == 0) && ((rect->dx % 8) == 0) |
| 290 | && (info->fix.type == FB_TYPE_INTERLEAVED_PLANES)) |
| 291 | arkfb_iplan_fillrect(info, rect); |
| 292 | else |
| 293 | cfb_fillrect(info, rect); |
| 294 | } |
| 295 | |
| 296 | |
| 297 | /* ------------------------------------------------------------------------- */ |
| 298 | |
| 299 | |
| 300 | enum |
| 301 | { |
| 302 | DAC_PSEUDO8_8, |
| 303 | DAC_RGB1555_8, |
| 304 | DAC_RGB0565_8, |
| 305 | DAC_RGB0888_8, |
| 306 | DAC_RGB8888_8, |
| 307 | DAC_PSEUDO8_16, |
| 308 | DAC_RGB1555_16, |
| 309 | DAC_RGB0565_16, |
| 310 | DAC_RGB0888_16, |
| 311 | DAC_RGB8888_16, |
| 312 | DAC_MAX |
| 313 | }; |
| 314 | |
| 315 | struct dac_ops { |
| 316 | int (*dac_get_mode)(struct dac_info *info); |
| 317 | int (*dac_set_mode)(struct dac_info *info, int mode); |
| 318 | int (*dac_get_freq)(struct dac_info *info, int channel); |
| 319 | int (*dac_set_freq)(struct dac_info *info, int channel, u32 freq); |
| 320 | void (*dac_release)(struct dac_info *info); |
| 321 | }; |
| 322 | |
| 323 | typedef void (*dac_read_regs_t)(void *data, u8 *code, int count); |
| 324 | typedef void (*dac_write_regs_t)(void *data, u8 *code, int count); |
| 325 | |
| 326 | struct dac_info |
| 327 | { |
| 328 | struct dac_ops *dacops; |
| 329 | dac_read_regs_t dac_read_regs; |
| 330 | dac_write_regs_t dac_write_regs; |
| 331 | void *data; |
| 332 | }; |
| 333 | |
| 334 | |
| 335 | static inline u8 dac_read_reg(struct dac_info *info, u8 reg) |
| 336 | { |
| 337 | u8 code[2] = {reg, 0}; |
| 338 | info->dac_read_regs(info->data, code, 1); |
| 339 | return code[1]; |
| 340 | } |
| 341 | |
| 342 | static inline void dac_read_regs(struct dac_info *info, u8 *code, int count) |
| 343 | { |
| 344 | info->dac_read_regs(info->data, code, count); |
| 345 | } |
| 346 | |
| 347 | static inline void dac_write_reg(struct dac_info *info, u8 reg, u8 val) |
| 348 | { |
| 349 | u8 code[2] = {reg, val}; |
| 350 | info->dac_write_regs(info->data, code, 1); |
| 351 | } |
| 352 | |
| 353 | static inline void dac_write_regs(struct dac_info *info, u8 *code, int count) |
| 354 | { |
| 355 | info->dac_write_regs(info->data, code, count); |
| 356 | } |
| 357 | |
| 358 | static inline int dac_set_mode(struct dac_info *info, int mode) |
| 359 | { |
| 360 | return info->dacops->dac_set_mode(info, mode); |
| 361 | } |
| 362 | |
| 363 | static inline int dac_set_freq(struct dac_info *info, int channel, u32 freq) |
| 364 | { |
| 365 | return info->dacops->dac_set_freq(info, channel, freq); |
| 366 | } |
| 367 | |
| 368 | static inline void dac_release(struct dac_info *info) |
| 369 | { |
| 370 | info->dacops->dac_release(info); |
| 371 | } |
| 372 | |
| 373 | |
| 374 | /* ------------------------------------------------------------------------- */ |
| 375 | |
| 376 | |
| 377 | /* ICS5342 DAC */ |
| 378 | |
| 379 | struct ics5342_info |
| 380 | { |
| 381 | struct dac_info dac; |
| 382 | u8 mode; |
| 383 | }; |
| 384 | |
| 385 | #define DAC_PAR(info) ((struct ics5342_info *) info) |
| 386 | |
| 387 | /* LSB is set to distinguish unused slots */ |
| 388 | static const u8 ics5342_mode_table[DAC_MAX] = { |
| 389 | [DAC_PSEUDO8_8] = 0x01, [DAC_RGB1555_8] = 0x21, [DAC_RGB0565_8] = 0x61, |
| 390 | [DAC_RGB0888_8] = 0x41, [DAC_PSEUDO8_16] = 0x11, [DAC_RGB1555_16] = 0x31, |
| 391 | [DAC_RGB0565_16] = 0x51, [DAC_RGB0888_16] = 0x91, [DAC_RGB8888_16] = 0x71 |
| 392 | }; |
| 393 | |
| 394 | static int ics5342_set_mode(struct dac_info *info, int mode) |
| 395 | { |
| 396 | u8 code; |
| 397 | |
| 398 | if (mode >= DAC_MAX) |
| 399 | return -EINVAL; |
| 400 | |
| 401 | code = ics5342_mode_table[mode]; |
| 402 | |
| 403 | if (! code) |
| 404 | return -EINVAL; |
| 405 | |
| 406 | dac_write_reg(info, 6, code & 0xF0); |
| 407 | DAC_PAR(info)->mode = mode; |
| 408 | |
| 409 | return 0; |
| 410 | } |
| 411 | |
| 412 | static const struct svga_pll ics5342_pll = {3, 129, 3, 33, 0, 3, |
| 413 | 60000, 250000, 14318}; |
| 414 | |
| 415 | /* pd4 - allow only posdivider 4 (r=2) */ |
| 416 | static const struct svga_pll ics5342_pll_pd4 = {3, 129, 3, 33, 2, 2, |
| 417 | 60000, 335000, 14318}; |
| 418 | |
| 419 | /* 270 MHz should be upper bound for VCO clock according to specs, |
| 420 | but that is too restrictive in pd4 case */ |
| 421 | |
| 422 | static int ics5342_set_freq(struct dac_info *info, int channel, u32 freq) |
| 423 | { |
| 424 | u16 m, n, r; |
| 425 | |
| 426 | /* only postdivider 4 (r=2) is valid in mode DAC_PSEUDO8_16 */ |
| 427 | int rv = svga_compute_pll((DAC_PAR(info)->mode == DAC_PSEUDO8_16) |
| 428 | ? &ics5342_pll_pd4 : &ics5342_pll, |
| 429 | freq, &m, &n, &r, 0); |
| 430 | |
| 431 | if (rv < 0) { |
| 432 | return -EINVAL; |
| 433 | } else { |
| 434 | u8 code[6] = {4, 3, 5, m-2, 5, (n-2) | (r << 5)}; |
| 435 | dac_write_regs(info, code, 3); |
| 436 | return 0; |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | static void ics5342_release(struct dac_info *info) |
| 441 | { |
| 442 | ics5342_set_mode(info, DAC_PSEUDO8_8); |
| 443 | kfree(info); |
| 444 | } |
| 445 | |
| 446 | static struct dac_ops ics5342_ops = { |
| 447 | .dac_set_mode = ics5342_set_mode, |
| 448 | .dac_set_freq = ics5342_set_freq, |
| 449 | .dac_release = ics5342_release |
| 450 | }; |
| 451 | |
| 452 | |
| 453 | static struct dac_info * ics5342_init(dac_read_regs_t drr, dac_write_regs_t dwr, void *data) |
| 454 | { |
| 455 | struct dac_info *info = kzalloc(sizeof(struct ics5342_info), GFP_KERNEL); |
| 456 | |
| 457 | if (! info) |
| 458 | return NULL; |
| 459 | |
| 460 | info->dacops = &ics5342_ops; |
| 461 | info->dac_read_regs = drr; |
| 462 | info->dac_write_regs = dwr; |
| 463 | info->data = data; |
| 464 | DAC_PAR(info)->mode = DAC_PSEUDO8_8; /* estimation */ |
| 465 | return info; |
| 466 | } |
| 467 | |
| 468 | |
| 469 | /* ------------------------------------------------------------------------- */ |
| 470 | |
| 471 | |
| 472 | static unsigned short dac_regs[4] = {0x3c8, 0x3c9, 0x3c6, 0x3c7}; |
| 473 | |
| 474 | static void ark_dac_read_regs(void *data, u8 *code, int count) |
| 475 | { |
| 476 | u8 regval = vga_rseq(NULL, 0x1C); |
| 477 | |
| 478 | while (count != 0) |
| 479 | { |
Roel Kluin | b935257 | 2009-03-31 15:25:34 -0700 | [diff] [blame] | 480 | vga_wseq(NULL, 0x1C, regval | (code[0] & 4 ? 0x80 : 0)); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 481 | code[1] = vga_r(NULL, dac_regs[code[0] & 3]); |
| 482 | count--; |
| 483 | code += 2; |
| 484 | } |
| 485 | |
| 486 | vga_wseq(NULL, 0x1C, regval); |
| 487 | } |
| 488 | |
| 489 | static void ark_dac_write_regs(void *data, u8 *code, int count) |
| 490 | { |
| 491 | u8 regval = vga_rseq(NULL, 0x1C); |
| 492 | |
| 493 | while (count != 0) |
| 494 | { |
Roel Kluin | b935257 | 2009-03-31 15:25:34 -0700 | [diff] [blame] | 495 | vga_wseq(NULL, 0x1C, regval | (code[0] & 4 ? 0x80 : 0)); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 496 | vga_w(NULL, dac_regs[code[0] & 3], code[1]); |
| 497 | count--; |
| 498 | code += 2; |
| 499 | } |
| 500 | |
| 501 | vga_wseq(NULL, 0x1C, regval); |
| 502 | } |
| 503 | |
| 504 | |
| 505 | static void ark_set_pixclock(struct fb_info *info, u32 pixclock) |
| 506 | { |
| 507 | struct arkfb_info *par = info->par; |
| 508 | u8 regval; |
| 509 | |
| 510 | int rv = dac_set_freq(par->dac, 0, 1000000000 / pixclock); |
| 511 | if (rv < 0) { |
| 512 | printk(KERN_ERR "fb%d: cannot set requested pixclock, keeping old value\n", info->node); |
| 513 | return; |
| 514 | } |
| 515 | |
| 516 | /* Set VGA misc register */ |
| 517 | regval = vga_r(NULL, VGA_MIS_R); |
| 518 | vga_w(NULL, VGA_MIS_W, regval | VGA_MIS_ENB_PLL_LOAD); |
| 519 | } |
| 520 | |
| 521 | |
| 522 | /* Open framebuffer */ |
| 523 | |
| 524 | static int arkfb_open(struct fb_info *info, int user) |
| 525 | { |
| 526 | struct arkfb_info *par = info->par; |
| 527 | |
| 528 | mutex_lock(&(par->open_lock)); |
| 529 | if (par->ref_count == 0) { |
| 530 | memset(&(par->state), 0, sizeof(struct vgastate)); |
| 531 | par->state.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS | VGA_SAVE_CMAP; |
| 532 | par->state.num_crtc = 0x60; |
| 533 | par->state.num_seq = 0x30; |
| 534 | save_vga(&(par->state)); |
| 535 | } |
| 536 | |
| 537 | par->ref_count++; |
| 538 | mutex_unlock(&(par->open_lock)); |
| 539 | |
| 540 | return 0; |
| 541 | } |
| 542 | |
| 543 | /* Close framebuffer */ |
| 544 | |
| 545 | static int arkfb_release(struct fb_info *info, int user) |
| 546 | { |
| 547 | struct arkfb_info *par = info->par; |
| 548 | |
| 549 | mutex_lock(&(par->open_lock)); |
| 550 | if (par->ref_count == 0) { |
| 551 | mutex_unlock(&(par->open_lock)); |
| 552 | return -EINVAL; |
| 553 | } |
| 554 | |
| 555 | if (par->ref_count == 1) { |
| 556 | restore_vga(&(par->state)); |
| 557 | dac_set_mode(par->dac, DAC_PSEUDO8_8); |
| 558 | } |
| 559 | |
| 560 | par->ref_count--; |
| 561 | mutex_unlock(&(par->open_lock)); |
| 562 | |
| 563 | return 0; |
| 564 | } |
| 565 | |
| 566 | /* Validate passed in var */ |
| 567 | |
| 568 | static int arkfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) |
| 569 | { |
| 570 | int rv, mem, step; |
| 571 | |
| 572 | /* Find appropriate format */ |
| 573 | rv = svga_match_format (arkfb_formats, var, NULL); |
| 574 | if (rv < 0) |
| 575 | { |
| 576 | printk(KERN_ERR "fb%d: unsupported mode requested\n", info->node); |
| 577 | return rv; |
| 578 | } |
| 579 | |
| 580 | /* Do not allow to have real resoulution larger than virtual */ |
| 581 | if (var->xres > var->xres_virtual) |
| 582 | var->xres_virtual = var->xres; |
| 583 | |
| 584 | if (var->yres > var->yres_virtual) |
| 585 | var->yres_virtual = var->yres; |
| 586 | |
| 587 | /* Round up xres_virtual to have proper alignment of lines */ |
| 588 | step = arkfb_formats[rv].xresstep - 1; |
| 589 | var->xres_virtual = (var->xres_virtual+step) & ~step; |
| 590 | |
| 591 | |
| 592 | /* Check whether have enough memory */ |
| 593 | mem = ((var->bits_per_pixel * var->xres_virtual) >> 3) * var->yres_virtual; |
| 594 | if (mem > info->screen_size) |
| 595 | { |
| 596 | printk(KERN_ERR "fb%d: not enough framebuffer memory (%d kB requested , %d kB available)\n", info->node, mem >> 10, (unsigned int) (info->screen_size >> 10)); |
| 597 | return -EINVAL; |
| 598 | } |
| 599 | |
| 600 | rv = svga_check_timings (&ark_timing_regs, var, info->node); |
| 601 | if (rv < 0) |
| 602 | { |
| 603 | printk(KERN_ERR "fb%d: invalid timings requested\n", info->node); |
| 604 | return rv; |
| 605 | } |
| 606 | |
| 607 | /* Interlaced mode is broken */ |
| 608 | if (var->vmode & FB_VMODE_INTERLACED) |
| 609 | return -EINVAL; |
| 610 | |
| 611 | return 0; |
| 612 | } |
| 613 | |
| 614 | /* Set video mode from par */ |
| 615 | |
| 616 | static int arkfb_set_par(struct fb_info *info) |
| 617 | { |
| 618 | struct arkfb_info *par = info->par; |
| 619 | u32 value, mode, hmul, hdiv, offset_value, screen_size; |
| 620 | u32 bpp = info->var.bits_per_pixel; |
| 621 | u8 regval; |
| 622 | |
| 623 | if (bpp != 0) { |
| 624 | info->fix.ypanstep = 1; |
| 625 | info->fix.line_length = (info->var.xres_virtual * bpp) / 8; |
| 626 | |
| 627 | info->flags &= ~FBINFO_MISC_TILEBLITTING; |
| 628 | info->tileops = NULL; |
| 629 | |
| 630 | /* in 4bpp supports 8p wide tiles only, any tiles otherwise */ |
| 631 | info->pixmap.blit_x = (bpp == 4) ? (1 << (8 - 1)) : (~(u32)0); |
| 632 | info->pixmap.blit_y = ~(u32)0; |
| 633 | |
| 634 | offset_value = (info->var.xres_virtual * bpp) / 64; |
| 635 | screen_size = info->var.yres_virtual * info->fix.line_length; |
| 636 | } else { |
| 637 | info->fix.ypanstep = 16; |
| 638 | info->fix.line_length = 0; |
| 639 | |
| 640 | info->flags |= FBINFO_MISC_TILEBLITTING; |
| 641 | info->tileops = &arkfb_tile_ops; |
| 642 | |
| 643 | /* supports 8x16 tiles only */ |
| 644 | info->pixmap.blit_x = 1 << (8 - 1); |
| 645 | info->pixmap.blit_y = 1 << (16 - 1); |
| 646 | |
| 647 | offset_value = info->var.xres_virtual / 16; |
| 648 | screen_size = (info->var.xres_virtual * info->var.yres_virtual) / 64; |
| 649 | } |
| 650 | |
| 651 | info->var.xoffset = 0; |
| 652 | info->var.yoffset = 0; |
| 653 | info->var.activate = FB_ACTIVATE_NOW; |
| 654 | |
| 655 | /* Unlock registers */ |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 656 | svga_wcrt_mask(par->state.vgabase, 0x11, 0x00, 0x80); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 657 | |
| 658 | /* Blank screen and turn off sync */ |
David Miller | d907ec0 | 2011-01-11 23:51:08 +0000 | [diff] [blame] | 659 | svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20); |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 660 | svga_wcrt_mask(par->state.vgabase, 0x17, 0x00, 0x80); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 661 | |
| 662 | /* Set default values */ |
David Miller | e2fade2 | 2011-01-11 23:50:04 +0000 | [diff] [blame] | 663 | svga_set_default_gfx_regs(par->state.vgabase); |
David Miller | f51a14d | 2011-01-11 23:50:36 +0000 | [diff] [blame] | 664 | svga_set_default_atc_regs(par->state.vgabase); |
David Miller | a4ade839 | 2011-01-11 23:50:54 +0000 | [diff] [blame] | 665 | svga_set_default_seq_regs(par->state.vgabase); |
David Miller | 1d28fca | 2011-01-11 23:51:41 +0000 | [diff] [blame] | 666 | svga_set_default_crt_regs(par->state.vgabase); |
David Miller | 21da386 | 2011-01-11 23:49:34 +0000 | [diff] [blame] | 667 | svga_wcrt_multi(par->state.vgabase, ark_line_compare_regs, 0xFFFFFFFF); |
| 668 | svga_wcrt_multi(par->state.vgabase, ark_start_address_regs, 0); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 669 | |
| 670 | /* ARK specific initialization */ |
David Miller | d907ec0 | 2011-01-11 23:51:08 +0000 | [diff] [blame] | 671 | svga_wseq_mask(par->state.vgabase, 0x10, 0x1F, 0x1F); /* enable linear framebuffer and full memory access */ |
| 672 | svga_wseq_mask(par->state.vgabase, 0x12, 0x03, 0x03); /* 4 MB linear framebuffer size */ |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 673 | |
| 674 | vga_wseq(NULL, 0x13, info->fix.smem_start >> 16); |
| 675 | vga_wseq(NULL, 0x14, info->fix.smem_start >> 24); |
| 676 | vga_wseq(NULL, 0x15, 0); |
| 677 | vga_wseq(NULL, 0x16, 0); |
| 678 | |
| 679 | /* Set the FIFO threshold register */ |
| 680 | /* It is fascinating way to store 5-bit value in 8-bit register */ |
| 681 | regval = 0x10 | ((threshold & 0x0E) >> 1) | (threshold & 0x01) << 7 | (threshold & 0x10) << 1; |
| 682 | vga_wseq(NULL, 0x18, regval); |
| 683 | |
| 684 | /* Set the offset register */ |
| 685 | pr_debug("fb%d: offset register : %d\n", info->node, offset_value); |
David Miller | 21da386 | 2011-01-11 23:49:34 +0000 | [diff] [blame] | 686 | svga_wcrt_multi(par->state.vgabase, ark_offset_regs, offset_value); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 687 | |
| 688 | /* fix for hi-res textmode */ |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 689 | svga_wcrt_mask(par->state.vgabase, 0x40, 0x08, 0x08); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 690 | |
| 691 | if (info->var.vmode & FB_VMODE_DOUBLE) |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 692 | svga_wcrt_mask(par->state.vgabase, 0x09, 0x80, 0x80); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 693 | else |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 694 | svga_wcrt_mask(par->state.vgabase, 0x09, 0x00, 0x80); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 695 | |
| 696 | if (info->var.vmode & FB_VMODE_INTERLACED) |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 697 | svga_wcrt_mask(par->state.vgabase, 0x44, 0x04, 0x04); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 698 | else |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 699 | svga_wcrt_mask(par->state.vgabase, 0x44, 0x00, 0x04); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 700 | |
| 701 | hmul = 1; |
| 702 | hdiv = 1; |
| 703 | mode = svga_match_format(arkfb_formats, &(info->var), &(info->fix)); |
| 704 | |
| 705 | /* Set mode-specific register values */ |
| 706 | switch (mode) { |
| 707 | case 0: |
| 708 | pr_debug("fb%d: text mode\n", info->node); |
David Miller | 9c96394 | 2011-01-11 23:51:56 +0000 | [diff] [blame] | 709 | svga_set_textmode_vga_regs(par->state.vgabase); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 710 | |
| 711 | vga_wseq(NULL, 0x11, 0x10); /* basic VGA mode */ |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 712 | svga_wcrt_mask(par->state.vgabase, 0x46, 0x00, 0x04); /* 8bit pixel path */ |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 713 | dac_set_mode(par->dac, DAC_PSEUDO8_8); |
| 714 | |
| 715 | break; |
| 716 | case 1: |
| 717 | pr_debug("fb%d: 4 bit pseudocolor\n", info->node); |
| 718 | vga_wgfx(NULL, VGA_GFX_MODE, 0x40); |
| 719 | |
| 720 | vga_wseq(NULL, 0x11, 0x10); /* basic VGA mode */ |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 721 | svga_wcrt_mask(par->state.vgabase, 0x46, 0x00, 0x04); /* 8bit pixel path */ |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 722 | dac_set_mode(par->dac, DAC_PSEUDO8_8); |
| 723 | break; |
| 724 | case 2: |
| 725 | pr_debug("fb%d: 4 bit pseudocolor, planar\n", info->node); |
| 726 | |
| 727 | vga_wseq(NULL, 0x11, 0x10); /* basic VGA mode */ |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 728 | svga_wcrt_mask(par->state.vgabase, 0x46, 0x00, 0x04); /* 8bit pixel path */ |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 729 | dac_set_mode(par->dac, DAC_PSEUDO8_8); |
| 730 | break; |
| 731 | case 3: |
| 732 | pr_debug("fb%d: 8 bit pseudocolor\n", info->node); |
| 733 | |
| 734 | vga_wseq(NULL, 0x11, 0x16); /* 8bpp accel mode */ |
| 735 | |
| 736 | if (info->var.pixclock > 20000) { |
| 737 | pr_debug("fb%d: not using multiplex\n", info->node); |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 738 | svga_wcrt_mask(par->state.vgabase, 0x46, 0x00, 0x04); /* 8bit pixel path */ |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 739 | dac_set_mode(par->dac, DAC_PSEUDO8_8); |
| 740 | } else { |
| 741 | pr_debug("fb%d: using multiplex\n", info->node); |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 742 | svga_wcrt_mask(par->state.vgabase, 0x46, 0x04, 0x04); /* 16bit pixel path */ |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 743 | dac_set_mode(par->dac, DAC_PSEUDO8_16); |
| 744 | hdiv = 2; |
| 745 | } |
| 746 | break; |
| 747 | case 4: |
| 748 | pr_debug("fb%d: 5/5/5 truecolor\n", info->node); |
| 749 | |
| 750 | vga_wseq(NULL, 0x11, 0x1A); /* 16bpp accel mode */ |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 751 | svga_wcrt_mask(par->state.vgabase, 0x46, 0x04, 0x04); /* 16bit pixel path */ |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 752 | dac_set_mode(par->dac, DAC_RGB1555_16); |
| 753 | break; |
| 754 | case 5: |
| 755 | pr_debug("fb%d: 5/6/5 truecolor\n", info->node); |
| 756 | |
| 757 | vga_wseq(NULL, 0x11, 0x1A); /* 16bpp accel mode */ |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 758 | svga_wcrt_mask(par->state.vgabase, 0x46, 0x04, 0x04); /* 16bit pixel path */ |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 759 | dac_set_mode(par->dac, DAC_RGB0565_16); |
| 760 | break; |
| 761 | case 6: |
| 762 | pr_debug("fb%d: 8/8/8 truecolor\n", info->node); |
| 763 | |
| 764 | vga_wseq(NULL, 0x11, 0x16); /* 8bpp accel mode ??? */ |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 765 | svga_wcrt_mask(par->state.vgabase, 0x46, 0x04, 0x04); /* 16bit pixel path */ |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 766 | dac_set_mode(par->dac, DAC_RGB0888_16); |
| 767 | hmul = 3; |
| 768 | hdiv = 2; |
| 769 | break; |
| 770 | case 7: |
| 771 | pr_debug("fb%d: 8/8/8/8 truecolor\n", info->node); |
| 772 | |
| 773 | vga_wseq(NULL, 0x11, 0x1E); /* 32bpp accel mode */ |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 774 | svga_wcrt_mask(par->state.vgabase, 0x46, 0x04, 0x04); /* 16bit pixel path */ |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 775 | dac_set_mode(par->dac, DAC_RGB8888_16); |
| 776 | hmul = 2; |
| 777 | break; |
| 778 | default: |
| 779 | printk(KERN_ERR "fb%d: unsupported mode - bug\n", info->node); |
| 780 | return -EINVAL; |
| 781 | } |
| 782 | |
| 783 | ark_set_pixclock(info, (hdiv * info->var.pixclock) / hmul); |
David Miller | 38d2620 | 2011-01-11 23:52:25 +0000 | [diff] [blame^] | 784 | svga_set_timings(par->state.vgabase, &ark_timing_regs, &(info->var), hmul, hdiv, |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 785 | (info->var.vmode & FB_VMODE_DOUBLE) ? 2 : 1, |
| 786 | (info->var.vmode & FB_VMODE_INTERLACED) ? 2 : 1, |
| 787 | hmul, info->node); |
| 788 | |
| 789 | /* Set interlaced mode start/end register */ |
| 790 | value = info->var.xres + info->var.left_margin + info->var.right_margin + info->var.hsync_len; |
| 791 | value = ((value * hmul / hdiv) / 8) - 5; |
| 792 | vga_wcrt(NULL, 0x42, (value + 1) / 2); |
| 793 | |
| 794 | memset_io(info->screen_base, 0x00, screen_size); |
| 795 | /* Device and screen back on */ |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 796 | svga_wcrt_mask(par->state.vgabase, 0x17, 0x80, 0x80); |
David Miller | d907ec0 | 2011-01-11 23:51:08 +0000 | [diff] [blame] | 797 | svga_wseq_mask(par->state.vgabase, 0x01, 0x00, 0x20); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 798 | |
| 799 | return 0; |
| 800 | } |
| 801 | |
| 802 | /* Set a colour register */ |
| 803 | |
| 804 | static int arkfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue, |
| 805 | u_int transp, struct fb_info *fb) |
| 806 | { |
| 807 | switch (fb->var.bits_per_pixel) { |
| 808 | case 0: |
| 809 | case 4: |
| 810 | if (regno >= 16) |
| 811 | return -EINVAL; |
| 812 | |
| 813 | if ((fb->var.bits_per_pixel == 4) && |
| 814 | (fb->var.nonstd == 0)) { |
| 815 | outb(0xF0, VGA_PEL_MSK); |
| 816 | outb(regno*16, VGA_PEL_IW); |
| 817 | } else { |
| 818 | outb(0x0F, VGA_PEL_MSK); |
| 819 | outb(regno, VGA_PEL_IW); |
| 820 | } |
| 821 | outb(red >> 10, VGA_PEL_D); |
| 822 | outb(green >> 10, VGA_PEL_D); |
| 823 | outb(blue >> 10, VGA_PEL_D); |
| 824 | break; |
| 825 | case 8: |
| 826 | if (regno >= 256) |
| 827 | return -EINVAL; |
| 828 | |
| 829 | outb(0xFF, VGA_PEL_MSK); |
| 830 | outb(regno, VGA_PEL_IW); |
| 831 | outb(red >> 10, VGA_PEL_D); |
| 832 | outb(green >> 10, VGA_PEL_D); |
| 833 | outb(blue >> 10, VGA_PEL_D); |
| 834 | break; |
| 835 | case 16: |
| 836 | if (regno >= 16) |
| 837 | return 0; |
| 838 | |
| 839 | if (fb->var.green.length == 5) |
| 840 | ((u32*)fb->pseudo_palette)[regno] = ((red & 0xF800) >> 1) | |
| 841 | ((green & 0xF800) >> 6) | ((blue & 0xF800) >> 11); |
| 842 | else if (fb->var.green.length == 6) |
| 843 | ((u32*)fb->pseudo_palette)[regno] = (red & 0xF800) | |
| 844 | ((green & 0xFC00) >> 5) | ((blue & 0xF800) >> 11); |
| 845 | else |
| 846 | return -EINVAL; |
| 847 | break; |
| 848 | case 24: |
| 849 | case 32: |
| 850 | if (regno >= 16) |
| 851 | return 0; |
| 852 | |
| 853 | ((u32*)fb->pseudo_palette)[regno] = ((red & 0xFF00) << 8) | |
| 854 | (green & 0xFF00) | ((blue & 0xFF00) >> 8); |
| 855 | break; |
| 856 | default: |
| 857 | return -EINVAL; |
| 858 | } |
| 859 | |
| 860 | return 0; |
| 861 | } |
| 862 | |
| 863 | /* Set the display blanking state */ |
| 864 | |
| 865 | static int arkfb_blank(int blank_mode, struct fb_info *info) |
| 866 | { |
David Miller | d907ec0 | 2011-01-11 23:51:08 +0000 | [diff] [blame] | 867 | struct arkfb_info *par = info->par; |
| 868 | |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 869 | switch (blank_mode) { |
| 870 | case FB_BLANK_UNBLANK: |
| 871 | pr_debug("fb%d: unblank\n", info->node); |
David Miller | d907ec0 | 2011-01-11 23:51:08 +0000 | [diff] [blame] | 872 | svga_wseq_mask(par->state.vgabase, 0x01, 0x00, 0x20); |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 873 | svga_wcrt_mask(par->state.vgabase, 0x17, 0x80, 0x80); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 874 | break; |
| 875 | case FB_BLANK_NORMAL: |
| 876 | pr_debug("fb%d: blank\n", info->node); |
David Miller | d907ec0 | 2011-01-11 23:51:08 +0000 | [diff] [blame] | 877 | svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20); |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 878 | svga_wcrt_mask(par->state.vgabase, 0x17, 0x80, 0x80); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 879 | break; |
| 880 | case FB_BLANK_POWERDOWN: |
| 881 | case FB_BLANK_HSYNC_SUSPEND: |
| 882 | case FB_BLANK_VSYNC_SUSPEND: |
| 883 | pr_debug("fb%d: sync down\n", info->node); |
David Miller | d907ec0 | 2011-01-11 23:51:08 +0000 | [diff] [blame] | 884 | svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20); |
David Miller | ea77078 | 2011-01-11 23:51:26 +0000 | [diff] [blame] | 885 | svga_wcrt_mask(par->state.vgabase, 0x17, 0x00, 0x80); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 886 | break; |
| 887 | } |
| 888 | return 0; |
| 889 | } |
| 890 | |
| 891 | |
| 892 | /* Pan the display */ |
| 893 | |
| 894 | static int arkfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info) |
| 895 | { |
David Miller | 21da386 | 2011-01-11 23:49:34 +0000 | [diff] [blame] | 896 | struct arkfb_info *par = info->par; |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 897 | unsigned int offset; |
| 898 | |
| 899 | /* Calculate the offset */ |
| 900 | if (var->bits_per_pixel == 0) { |
| 901 | offset = (var->yoffset / 16) * (var->xres_virtual / 2) + (var->xoffset / 2); |
| 902 | offset = offset >> 2; |
| 903 | } else { |
| 904 | offset = (var->yoffset * info->fix.line_length) + |
| 905 | (var->xoffset * var->bits_per_pixel / 8); |
| 906 | offset = offset >> ((var->bits_per_pixel == 4) ? 2 : 3); |
| 907 | } |
| 908 | |
| 909 | /* Set the offset */ |
David Miller | 21da386 | 2011-01-11 23:49:34 +0000 | [diff] [blame] | 910 | svga_wcrt_multi(par->state.vgabase, ark_start_address_regs, offset); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 911 | |
| 912 | return 0; |
| 913 | } |
| 914 | |
| 915 | |
| 916 | /* ------------------------------------------------------------------------- */ |
| 917 | |
| 918 | |
| 919 | /* Frame buffer operations */ |
| 920 | |
| 921 | static struct fb_ops arkfb_ops = { |
| 922 | .owner = THIS_MODULE, |
| 923 | .fb_open = arkfb_open, |
| 924 | .fb_release = arkfb_release, |
| 925 | .fb_check_var = arkfb_check_var, |
| 926 | .fb_set_par = arkfb_set_par, |
| 927 | .fb_setcolreg = arkfb_setcolreg, |
| 928 | .fb_blank = arkfb_blank, |
| 929 | .fb_pan_display = arkfb_pan_display, |
| 930 | .fb_fillrect = arkfb_fillrect, |
| 931 | .fb_copyarea = cfb_copyarea, |
| 932 | .fb_imageblit = arkfb_imageblit, |
Antonino A. Daplas | 5a87ede | 2007-05-09 02:35:32 -0700 | [diff] [blame] | 933 | .fb_get_caps = svga_get_caps, |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 934 | }; |
| 935 | |
| 936 | |
| 937 | /* ------------------------------------------------------------------------- */ |
| 938 | |
| 939 | |
| 940 | /* PCI probe */ |
| 941 | static int __devinit ark_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) |
| 942 | { |
| 943 | struct fb_info *info; |
| 944 | struct arkfb_info *par; |
| 945 | int rc; |
| 946 | u8 regval; |
| 947 | |
| 948 | /* Ignore secondary VGA device because there is no VGA arbitration */ |
| 949 | if (! svga_primary_device(dev)) { |
| 950 | dev_info(&(dev->dev), "ignoring secondary device\n"); |
| 951 | return -ENODEV; |
| 952 | } |
| 953 | |
| 954 | /* Allocate and fill driver data structure */ |
Ondrej Zajicek | 20e061f | 2008-04-28 02:15:18 -0700 | [diff] [blame] | 955 | info = framebuffer_alloc(sizeof(struct arkfb_info), &(dev->dev)); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 956 | if (! info) { |
| 957 | dev_err(&(dev->dev), "cannot allocate memory\n"); |
| 958 | return -ENOMEM; |
| 959 | } |
| 960 | |
| 961 | par = info->par; |
| 962 | mutex_init(&par->open_lock); |
| 963 | |
| 964 | info->flags = FBINFO_PARTIAL_PAN_OK | FBINFO_HWACCEL_YPAN; |
| 965 | info->fbops = &arkfb_ops; |
| 966 | |
| 967 | /* Prepare PCI device */ |
| 968 | rc = pci_enable_device(dev); |
| 969 | if (rc < 0) { |
Ondrej Zajicek | 594a881 | 2008-08-05 13:01:06 -0700 | [diff] [blame] | 970 | dev_err(info->device, "cannot enable PCI device\n"); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 971 | goto err_enable_device; |
| 972 | } |
| 973 | |
| 974 | rc = pci_request_regions(dev, "arkfb"); |
| 975 | if (rc < 0) { |
Ondrej Zajicek | 594a881 | 2008-08-05 13:01:06 -0700 | [diff] [blame] | 976 | dev_err(info->device, "cannot reserve framebuffer region\n"); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 977 | goto err_request_regions; |
| 978 | } |
| 979 | |
| 980 | par->dac = ics5342_init(ark_dac_read_regs, ark_dac_write_regs, info); |
| 981 | if (! par->dac) { |
| 982 | rc = -ENOMEM; |
Ondrej Zajicek | 594a881 | 2008-08-05 13:01:06 -0700 | [diff] [blame] | 983 | dev_err(info->device, "RAMDAC initialization failed\n"); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 984 | goto err_dac; |
| 985 | } |
| 986 | |
| 987 | info->fix.smem_start = pci_resource_start(dev, 0); |
| 988 | info->fix.smem_len = pci_resource_len(dev, 0); |
| 989 | |
| 990 | /* Map physical IO memory address into kernel space */ |
| 991 | info->screen_base = pci_iomap(dev, 0, 0); |
| 992 | if (! info->screen_base) { |
| 993 | rc = -ENOMEM; |
Ondrej Zajicek | 594a881 | 2008-08-05 13:01:06 -0700 | [diff] [blame] | 994 | dev_err(info->device, "iomap for framebuffer failed\n"); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 995 | goto err_iomap; |
| 996 | } |
| 997 | |
| 998 | /* FIXME get memsize */ |
| 999 | regval = vga_rseq(NULL, 0x10); |
| 1000 | info->screen_size = (1 << (regval >> 6)) << 20; |
| 1001 | info->fix.smem_len = info->screen_size; |
| 1002 | |
| 1003 | strcpy(info->fix.id, "ARK 2000PV"); |
| 1004 | info->fix.mmio_start = 0; |
| 1005 | info->fix.mmio_len = 0; |
| 1006 | info->fix.type = FB_TYPE_PACKED_PIXELS; |
| 1007 | info->fix.visual = FB_VISUAL_PSEUDOCOLOR; |
| 1008 | info->fix.ypanstep = 0; |
| 1009 | info->fix.accel = FB_ACCEL_NONE; |
| 1010 | info->pseudo_palette = (void*) (par->pseudo_palette); |
| 1011 | |
| 1012 | /* Prepare startup mode */ |
Krzysztof Helt | 1abf917 | 2008-04-28 02:15:08 -0700 | [diff] [blame] | 1013 | rc = fb_find_mode(&(info->var), info, mode_option, NULL, 0, NULL, 8); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 1014 | if (! ((rc == 1) || (rc == 2))) { |
| 1015 | rc = -EINVAL; |
Ondrej Zajicek | 594a881 | 2008-08-05 13:01:06 -0700 | [diff] [blame] | 1016 | dev_err(info->device, "mode %s not found\n", mode_option); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 1017 | goto err_find_mode; |
| 1018 | } |
| 1019 | |
| 1020 | rc = fb_alloc_cmap(&info->cmap, 256, 0); |
| 1021 | if (rc < 0) { |
Ondrej Zajicek | 594a881 | 2008-08-05 13:01:06 -0700 | [diff] [blame] | 1022 | dev_err(info->device, "cannot allocate colormap\n"); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 1023 | goto err_alloc_cmap; |
| 1024 | } |
| 1025 | |
| 1026 | rc = register_framebuffer(info); |
| 1027 | if (rc < 0) { |
Ondrej Zajicek | 594a881 | 2008-08-05 13:01:06 -0700 | [diff] [blame] | 1028 | dev_err(info->device, "cannot register framebugger\n"); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 1029 | goto err_reg_fb; |
| 1030 | } |
| 1031 | |
| 1032 | printk(KERN_INFO "fb%d: %s on %s, %d MB RAM\n", info->node, info->fix.id, |
| 1033 | pci_name(dev), info->fix.smem_len >> 20); |
| 1034 | |
| 1035 | /* Record a reference to the driver data */ |
| 1036 | pci_set_drvdata(dev, info); |
| 1037 | |
| 1038 | #ifdef CONFIG_MTRR |
| 1039 | if (mtrr) { |
| 1040 | par->mtrr_reg = -1; |
| 1041 | par->mtrr_reg = mtrr_add(info->fix.smem_start, info->fix.smem_len, MTRR_TYPE_WRCOMB, 1); |
| 1042 | } |
| 1043 | #endif |
| 1044 | |
| 1045 | return 0; |
| 1046 | |
| 1047 | /* Error handling */ |
| 1048 | err_reg_fb: |
| 1049 | fb_dealloc_cmap(&info->cmap); |
| 1050 | err_alloc_cmap: |
| 1051 | err_find_mode: |
| 1052 | pci_iounmap(dev, info->screen_base); |
| 1053 | err_iomap: |
| 1054 | dac_release(par->dac); |
| 1055 | err_dac: |
| 1056 | pci_release_regions(dev); |
| 1057 | err_request_regions: |
| 1058 | /* pci_disable_device(dev); */ |
| 1059 | err_enable_device: |
| 1060 | framebuffer_release(info); |
| 1061 | return rc; |
| 1062 | } |
| 1063 | |
| 1064 | /* PCI remove */ |
| 1065 | |
| 1066 | static void __devexit ark_pci_remove(struct pci_dev *dev) |
| 1067 | { |
| 1068 | struct fb_info *info = pci_get_drvdata(dev); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 1069 | |
| 1070 | if (info) { |
Ondrej Zajicek | 38d473f | 2007-06-01 00:46:43 -0700 | [diff] [blame] | 1071 | struct arkfb_info *par = info->par; |
| 1072 | |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 1073 | #ifdef CONFIG_MTRR |
| 1074 | if (par->mtrr_reg >= 0) { |
| 1075 | mtrr_del(par->mtrr_reg, 0, 0); |
| 1076 | par->mtrr_reg = -1; |
| 1077 | } |
| 1078 | #endif |
| 1079 | |
| 1080 | dac_release(par->dac); |
| 1081 | unregister_framebuffer(info); |
| 1082 | fb_dealloc_cmap(&info->cmap); |
| 1083 | |
| 1084 | pci_iounmap(dev, info->screen_base); |
| 1085 | pci_release_regions(dev); |
| 1086 | /* pci_disable_device(dev); */ |
| 1087 | |
| 1088 | pci_set_drvdata(dev, NULL); |
| 1089 | framebuffer_release(info); |
| 1090 | } |
| 1091 | } |
| 1092 | |
| 1093 | |
| 1094 | #ifdef CONFIG_PM |
| 1095 | /* PCI suspend */ |
| 1096 | |
| 1097 | static int ark_pci_suspend (struct pci_dev* dev, pm_message_t state) |
| 1098 | { |
| 1099 | struct fb_info *info = pci_get_drvdata(dev); |
| 1100 | struct arkfb_info *par = info->par; |
| 1101 | |
Ondrej Zajicek | 594a881 | 2008-08-05 13:01:06 -0700 | [diff] [blame] | 1102 | dev_info(info->device, "suspend\n"); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 1103 | |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 1104 | console_lock(); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 1105 | mutex_lock(&(par->open_lock)); |
| 1106 | |
| 1107 | if ((state.event == PM_EVENT_FREEZE) || (par->ref_count == 0)) { |
| 1108 | mutex_unlock(&(par->open_lock)); |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 1109 | console_unlock(); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 1110 | return 0; |
| 1111 | } |
| 1112 | |
| 1113 | fb_set_suspend(info, 1); |
| 1114 | |
| 1115 | pci_save_state(dev); |
| 1116 | pci_disable_device(dev); |
| 1117 | pci_set_power_state(dev, pci_choose_state(dev, state)); |
| 1118 | |
| 1119 | mutex_unlock(&(par->open_lock)); |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 1120 | console_unlock(); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 1121 | |
| 1122 | return 0; |
| 1123 | } |
| 1124 | |
| 1125 | |
| 1126 | /* PCI resume */ |
| 1127 | |
| 1128 | static int ark_pci_resume (struct pci_dev* dev) |
| 1129 | { |
| 1130 | struct fb_info *info = pci_get_drvdata(dev); |
| 1131 | struct arkfb_info *par = info->par; |
| 1132 | |
Ondrej Zajicek | 594a881 | 2008-08-05 13:01:06 -0700 | [diff] [blame] | 1133 | dev_info(info->device, "resume\n"); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 1134 | |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 1135 | console_lock(); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 1136 | mutex_lock(&(par->open_lock)); |
| 1137 | |
Julia Lawall | 950d442 | 2008-07-29 22:33:28 -0700 | [diff] [blame] | 1138 | if (par->ref_count == 0) |
| 1139 | goto fail; |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 1140 | |
| 1141 | pci_set_power_state(dev, PCI_D0); |
| 1142 | pci_restore_state(dev); |
| 1143 | |
| 1144 | if (pci_enable_device(dev)) |
| 1145 | goto fail; |
| 1146 | |
| 1147 | pci_set_master(dev); |
| 1148 | |
| 1149 | arkfb_set_par(info); |
| 1150 | fb_set_suspend(info, 0); |
| 1151 | |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 1152 | fail: |
Julia Lawall | 950d442 | 2008-07-29 22:33:28 -0700 | [diff] [blame] | 1153 | mutex_unlock(&(par->open_lock)); |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 1154 | console_unlock(); |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 1155 | return 0; |
| 1156 | } |
| 1157 | #else |
| 1158 | #define ark_pci_suspend NULL |
| 1159 | #define ark_pci_resume NULL |
| 1160 | #endif /* CONFIG_PM */ |
| 1161 | |
| 1162 | /* List of boards that we are trying to support */ |
| 1163 | |
| 1164 | static struct pci_device_id ark_devices[] __devinitdata = { |
| 1165 | {PCI_DEVICE(0xEDD8, 0xA099)}, |
| 1166 | {0, 0, 0, 0, 0, 0, 0} |
| 1167 | }; |
| 1168 | |
| 1169 | |
| 1170 | MODULE_DEVICE_TABLE(pci, ark_devices); |
| 1171 | |
| 1172 | static struct pci_driver arkfb_pci_driver = { |
| 1173 | .name = "arkfb", |
| 1174 | .id_table = ark_devices, |
| 1175 | .probe = ark_pci_probe, |
| 1176 | .remove = __devexit_p(ark_pci_remove), |
| 1177 | .suspend = ark_pci_suspend, |
| 1178 | .resume = ark_pci_resume, |
| 1179 | }; |
| 1180 | |
| 1181 | /* Cleanup */ |
| 1182 | |
| 1183 | static void __exit arkfb_cleanup(void) |
| 1184 | { |
| 1185 | pr_debug("arkfb: cleaning up\n"); |
| 1186 | pci_unregister_driver(&arkfb_pci_driver); |
| 1187 | } |
| 1188 | |
| 1189 | /* Driver Initialisation */ |
| 1190 | |
| 1191 | static int __init arkfb_init(void) |
| 1192 | { |
| 1193 | |
| 1194 | #ifndef MODULE |
| 1195 | char *option = NULL; |
| 1196 | |
| 1197 | if (fb_get_options("arkfb", &option)) |
| 1198 | return -ENODEV; |
| 1199 | |
| 1200 | if (option && *option) |
Krzysztof Helt | 1abf917 | 2008-04-28 02:15:08 -0700 | [diff] [blame] | 1201 | mode_option = option; |
Ondrej Zajicek | 681e147 | 2007-05-09 02:35:31 -0700 | [diff] [blame] | 1202 | #endif |
| 1203 | |
| 1204 | pr_debug("arkfb: initializing\n"); |
| 1205 | return pci_register_driver(&arkfb_pci_driver); |
| 1206 | } |
| 1207 | |
| 1208 | module_init(arkfb_init); |
| 1209 | module_exit(arkfb_cleanup); |