Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved. |
| 3 | * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved. |
| 4 | |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public |
| 7 | * License as published by the Free Software Foundation; |
| 8 | * either version 2, or (at your option) any later version. |
| 9 | |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even |
| 12 | * the implied warranty of MERCHANTABILITY or FITNESS FOR |
| 13 | * A PARTICULAR PURPOSE.See the GNU General Public License |
| 14 | * for more details. |
| 15 | |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., |
| 19 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 20 | */ |
| 21 | |
| 22 | #include <linux/module.h> |
Alexey Dobriyan | afbd3c1 | 2009-09-22 16:47:27 -0700 | [diff] [blame] | 23 | #include <linux/seq_file.h> |
Harald Welte | 93967be | 2009-09-22 16:47:32 -0700 | [diff] [blame] | 24 | #include <linux/stat.h> |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 25 | #define _MASTER_FILE |
| 26 | |
| 27 | #include "global.h" |
| 28 | |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 29 | static struct fb_var_screeninfo default_var; |
| 30 | static char *viafb_name = "Via"; |
| 31 | static u32 pseudo_pal[17]; |
| 32 | |
| 33 | /* video mode */ |
| 34 | static char *viafb_mode = "640x480"; |
| 35 | static char *viafb_mode1 = "640x480"; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 36 | |
Florian Tobias Schandinat | 31de59d | 2009-09-22 16:47:31 -0700 | [diff] [blame] | 37 | static int viafb_accel = 1; |
| 38 | |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 39 | /* Added for specifying active devices.*/ |
| 40 | char *viafb_active_dev = ""; |
| 41 | |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 42 | /*Added for specify lcd output port*/ |
| 43 | char *viafb_lcd_port = ""; |
| 44 | char *viafb_dvi_port = ""; |
| 45 | |
| 46 | static void viafb_set_device(struct device_t active_dev); |
| 47 | static int apply_device_setting(struct viafb_ioctl_setting setting_info, |
| 48 | struct fb_info *info); |
| 49 | static void apply_second_mode_setting(struct fb_var_screeninfo |
| 50 | *sec_var); |
| 51 | static void retrieve_device_setting(struct viafb_ioctl_setting |
| 52 | *setting_info); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 53 | |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 54 | static struct fb_ops viafb_ops; |
| 55 | |
Florian Tobias Schandinat | 81228a3 | 2009-09-22 16:47:13 -0700 | [diff] [blame] | 56 | |
| 57 | static void viafb_update_fix(struct fb_info *info) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 58 | { |
Florian Tobias Schandinat | 81228a3 | 2009-09-22 16:47:13 -0700 | [diff] [blame] | 59 | u32 bpp = info->var.bits_per_pixel; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 60 | |
Florian Tobias Schandinat | 81228a3 | 2009-09-22 16:47:13 -0700 | [diff] [blame] | 61 | info->fix.visual = |
| 62 | bpp == 8 ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR; |
| 63 | info->fix.line_length = |
| 64 | ((info->var.xres_virtual + 7) & ~7) * bpp / 8; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 67 | static void viafb_setup_fixinfo(struct fb_fix_screeninfo *fix, |
| 68 | struct viafb_par *viaparinfo) |
| 69 | { |
| 70 | memset(fix, 0, sizeof(struct fb_fix_screeninfo)); |
| 71 | strcpy(fix->id, viafb_name); |
| 72 | |
| 73 | fix->smem_start = viaparinfo->fbmem; |
| 74 | fix->smem_len = viaparinfo->fbmem_free; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 75 | |
| 76 | fix->type = FB_TYPE_PACKED_PIXELS; |
| 77 | fix->type_aux = 0; |
| 78 | |
| 79 | fix->xpanstep = fix->ywrapstep = 0; |
| 80 | fix->ypanstep = 1; |
| 81 | |
| 82 | /* Just tell the accel name */ |
| 83 | viafbinfo->fix.accel = FB_ACCEL_VIA_UNICHROME; |
| 84 | } |
| 85 | static int viafb_open(struct fb_info *info, int user) |
| 86 | { |
| 87 | DEBUG_MSG(KERN_INFO "viafb_open!\n"); |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | static int viafb_release(struct fb_info *info, int user) |
| 92 | { |
| 93 | DEBUG_MSG(KERN_INFO "viafb_release!\n"); |
| 94 | return 0; |
| 95 | } |
| 96 | |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 97 | static int viafb_check_var(struct fb_var_screeninfo *var, |
| 98 | struct fb_info *info) |
| 99 | { |
| 100 | int vmode_index, htotal, vtotal; |
Florian Tobias Schandinat | c3e2567 | 2009-09-22 16:47:26 -0700 | [diff] [blame] | 101 | struct viafb_par *ppar = info->par; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 102 | u32 long_refresh; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 103 | |
| 104 | DEBUG_MSG(KERN_INFO "viafb_check_var!\n"); |
| 105 | /* Sanity check */ |
| 106 | /* HW neither support interlacte nor double-scaned mode */ |
| 107 | if (var->vmode & FB_VMODE_INTERLACED || var->vmode & FB_VMODE_DOUBLE) |
| 108 | return -EINVAL; |
| 109 | |
Florian Tobias Schandinat | 5215944 | 2009-08-06 15:07:34 -0700 | [diff] [blame] | 110 | vmode_index = viafb_get_mode_index(var->xres, var->yres); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 111 | if (vmode_index == VIA_RES_INVALID) { |
| 112 | DEBUG_MSG(KERN_INFO |
| 113 | "viafb: Mode %dx%dx%d not supported!!\n", |
| 114 | var->xres, var->yres, var->bits_per_pixel); |
| 115 | return -EINVAL; |
| 116 | } |
| 117 | |
| 118 | if (24 == var->bits_per_pixel) |
| 119 | var->bits_per_pixel = 32; |
| 120 | |
| 121 | if (var->bits_per_pixel != 8 && var->bits_per_pixel != 16 && |
| 122 | var->bits_per_pixel != 32) |
| 123 | return -EINVAL; |
| 124 | |
| 125 | if ((var->xres_virtual * (var->bits_per_pixel >> 3)) & 0x1F) |
| 126 | /*32 pixel alignment */ |
| 127 | var->xres_virtual = (var->xres_virtual + 31) & ~31; |
| 128 | if (var->xres_virtual * var->yres_virtual * var->bits_per_pixel / 8 > |
| 129 | ppar->memsize) |
| 130 | return -EINVAL; |
| 131 | |
| 132 | /* Based on var passed in to calculate the refresh, |
| 133 | * because our driver use some modes special. |
| 134 | */ |
| 135 | htotal = var->xres + var->left_margin + |
| 136 | var->right_margin + var->hsync_len; |
| 137 | vtotal = var->yres + var->upper_margin + |
| 138 | var->lower_margin + var->vsync_len; |
| 139 | long_refresh = 1000000000UL / var->pixclock * 1000; |
| 140 | long_refresh /= (htotal * vtotal); |
| 141 | |
| 142 | viafb_refresh = viafb_get_refresh(var->xres, var->yres, long_refresh); |
| 143 | |
| 144 | /* Adjust var according to our driver's own table */ |
| 145 | viafb_fill_var_timing_info(var, viafb_refresh, vmode_index); |
Florian Tobias Schandinat | 31de59d | 2009-09-22 16:47:31 -0700 | [diff] [blame] | 146 | if (info->var.accel_flags & FB_ACCELF_TEXT && |
| 147 | !ppar->shared->engine_mmio) |
| 148 | info->var.accel_flags = 0; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 149 | |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 150 | return 0; |
| 151 | } |
| 152 | |
| 153 | static int viafb_set_par(struct fb_info *info) |
| 154 | { |
Florian Tobias Schandinat | c3e2567 | 2009-09-22 16:47:26 -0700 | [diff] [blame] | 155 | struct viafb_par *viapar = info->par; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 156 | int vmode_index; |
| 157 | int vmode_index1 = 0; |
| 158 | DEBUG_MSG(KERN_INFO "viafb_set_par!\n"); |
| 159 | |
Florian Tobias Schandinat | c3e2567 | 2009-09-22 16:47:26 -0700 | [diff] [blame] | 160 | viapar->depth = fb_get_color_depth(&info->var, &info->fix); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 161 | viafb_update_device_setting(info->var.xres, info->var.yres, |
| 162 | info->var.bits_per_pixel, viafb_refresh, 0); |
| 163 | |
Florian Tobias Schandinat | 5215944 | 2009-08-06 15:07:34 -0700 | [diff] [blame] | 164 | vmode_index = viafb_get_mode_index(info->var.xres, info->var.yres); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 165 | |
| 166 | if (viafb_SAMM_ON == 1) { |
| 167 | DEBUG_MSG(KERN_INFO |
| 168 | "viafb_second_xres = %d, viafb_second_yres = %d, bpp = %d\n", |
| 169 | viafb_second_xres, viafb_second_yres, viafb_bpp1); |
| 170 | vmode_index1 = viafb_get_mode_index(viafb_second_xres, |
Florian Tobias Schandinat | 5215944 | 2009-08-06 15:07:34 -0700 | [diff] [blame] | 171 | viafb_second_yres); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 172 | DEBUG_MSG(KERN_INFO "->viafb_SAMM_ON: index=%d\n", |
| 173 | vmode_index1); |
| 174 | |
| 175 | viafb_update_device_setting(viafb_second_xres, |
| 176 | viafb_second_yres, viafb_bpp1, viafb_refresh1, 1); |
| 177 | } |
| 178 | |
| 179 | if (vmode_index != VIA_RES_INVALID) { |
| 180 | viafb_setmode(vmode_index, info->var.xres, info->var.yres, |
| 181 | info->var.bits_per_pixel, vmode_index1, |
| 182 | viafb_second_xres, viafb_second_yres, viafb_bpp1); |
| 183 | |
Florian Tobias Schandinat | 81228a3 | 2009-09-22 16:47:13 -0700 | [diff] [blame] | 184 | viafb_update_fix(info); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 185 | viafb_bpp = info->var.bits_per_pixel; |
Florian Tobias Schandinat | 31de59d | 2009-09-22 16:47:31 -0700 | [diff] [blame] | 186 | if (info->var.accel_flags & FB_ACCELF_TEXT) |
| 187 | info->flags &= ~FBINFO_HWACCEL_DISABLED; |
| 188 | else |
| 189 | info->flags |= FBINFO_HWACCEL_DISABLED; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | return 0; |
| 193 | } |
| 194 | |
| 195 | /* Set one color register */ |
| 196 | static int viafb_setcolreg(unsigned regno, unsigned red, unsigned green, |
| 197 | unsigned blue, unsigned transp, struct fb_info *info) |
| 198 | { |
| 199 | u8 sr1a, sr1b, cr67, cr6a, rev = 0, shift = 10; |
| 200 | unsigned cmap_entries = (info->var.bits_per_pixel == 8) ? 256 : 16; |
| 201 | DEBUG_MSG(KERN_INFO "viafb_setcolreg!\n"); |
| 202 | if (regno >= cmap_entries) |
| 203 | return 1; |
| 204 | if (UNICHROME_CLE266 == viaparinfo->chip_info->gfx_chip_name) { |
| 205 | /* |
| 206 | * Read PCI bus 0,dev 0,function 0,index 0xF6 to get chip rev. |
| 207 | */ |
| 208 | outl(0x80000000 | (0xf6 & ~3), (unsigned long)0xCF8); |
| 209 | rev = (inl((unsigned long)0xCFC) >> ((0xf6 & 3) * 8)) & 0xff; |
| 210 | } |
| 211 | switch (info->var.bits_per_pixel) { |
| 212 | case 8: |
| 213 | outb(0x1A, 0x3C4); |
| 214 | sr1a = inb(0x3C5); |
| 215 | outb(0x1B, 0x3C4); |
| 216 | sr1b = inb(0x3C5); |
| 217 | outb(0x67, 0x3D4); |
| 218 | cr67 = inb(0x3D5); |
| 219 | outb(0x6A, 0x3D4); |
| 220 | cr6a = inb(0x3D5); |
| 221 | |
| 222 | /* Map the 3C6/7/8/9 to the IGA2 */ |
| 223 | outb(0x1A, 0x3C4); |
| 224 | outb(sr1a | 0x01, 0x3C5); |
| 225 | /* Second Display Engine colck always on */ |
| 226 | outb(0x1B, 0x3C4); |
| 227 | outb(sr1b | 0x80, 0x3C5); |
| 228 | /* Second Display Color Depth 8 */ |
| 229 | outb(0x67, 0x3D4); |
| 230 | outb(cr67 & 0x3F, 0x3D5); |
| 231 | outb(0x6A, 0x3D4); |
| 232 | /* Second Display Channel Reset CR6A[6]) */ |
| 233 | outb(cr6a & 0xBF, 0x3D5); |
| 234 | /* Second Display Channel Enable CR6A[7] */ |
| 235 | outb(cr6a | 0x80, 0x3D5); |
| 236 | /* Second Display Channel stop reset) */ |
| 237 | outb(cr6a | 0x40, 0x3D5); |
| 238 | |
| 239 | /* Bit mask of palette */ |
| 240 | outb(0xFF, 0x3c6); |
| 241 | /* Write one register of IGA2 */ |
| 242 | outb(regno, 0x3C8); |
| 243 | if (UNICHROME_CLE266 == viaparinfo->chip_info->gfx_chip_name && |
| 244 | rev >= 15) { |
| 245 | shift = 8; |
| 246 | viafb_write_reg_mask(CR6A, VIACR, BIT5, BIT5); |
| 247 | viafb_write_reg_mask(SR15, VIASR, BIT7, BIT7); |
| 248 | } else { |
| 249 | shift = 10; |
| 250 | viafb_write_reg_mask(CR6A, VIACR, 0, BIT5); |
| 251 | viafb_write_reg_mask(SR15, VIASR, 0, BIT7); |
| 252 | } |
| 253 | outb(red >> shift, 0x3C9); |
| 254 | outb(green >> shift, 0x3C9); |
| 255 | outb(blue >> shift, 0x3C9); |
| 256 | |
| 257 | /* Map the 3C6/7/8/9 to the IGA1 */ |
| 258 | outb(0x1A, 0x3C4); |
| 259 | outb(sr1a & 0xFE, 0x3C5); |
| 260 | /* Bit mask of palette */ |
| 261 | outb(0xFF, 0x3c6); |
| 262 | /* Write one register of IGA1 */ |
| 263 | outb(regno, 0x3C8); |
| 264 | outb(red >> shift, 0x3C9); |
| 265 | outb(green >> shift, 0x3C9); |
| 266 | outb(blue >> shift, 0x3C9); |
| 267 | |
| 268 | outb(0x1A, 0x3C4); |
| 269 | outb(sr1a, 0x3C5); |
| 270 | outb(0x1B, 0x3C4); |
| 271 | outb(sr1b, 0x3C5); |
| 272 | outb(0x67, 0x3D4); |
| 273 | outb(cr67, 0x3D5); |
| 274 | outb(0x6A, 0x3D4); |
| 275 | outb(cr6a, 0x3D5); |
| 276 | break; |
| 277 | case 16: |
| 278 | ((u32 *) info->pseudo_palette)[regno] = (red & 0xF800) | |
| 279 | ((green & 0xFC00) >> 5) | ((blue & 0xF800) >> 11); |
| 280 | break; |
| 281 | case 32: |
| 282 | ((u32 *) info->pseudo_palette)[regno] = |
| 283 | ((transp & 0xFF00) << 16) | |
| 284 | ((red & 0xFF00) << 8) | |
| 285 | ((green & 0xFF00)) | ((blue & 0xFF00) >> 8); |
| 286 | break; |
| 287 | } |
| 288 | |
| 289 | return 0; |
| 290 | |
| 291 | } |
| 292 | |
| 293 | /*CALLED BY: fb_set_cmap */ |
| 294 | /* fb_set_var, pass 256 colors */ |
| 295 | /*CALLED BY: fb_set_cmap */ |
| 296 | /* fbcon_set_palette, pass 16 colors */ |
| 297 | static int viafb_setcmap(struct fb_cmap *cmap, struct fb_info *info) |
| 298 | { |
| 299 | u32 len = cmap->len; |
| 300 | u32 i; |
| 301 | u16 *pred = cmap->red; |
| 302 | u16 *pgreen = cmap->green; |
| 303 | u16 *pblue = cmap->blue; |
| 304 | u16 *ptransp = cmap->transp; |
| 305 | u8 sr1a, sr1b, cr67, cr6a, rev = 0, shift = 10; |
| 306 | if (len > 256) |
| 307 | return 1; |
| 308 | if (UNICHROME_CLE266 == viaparinfo->chip_info->gfx_chip_name) { |
| 309 | /* |
| 310 | * Read PCI bus 0, dev 0, function 0, index 0xF6 to get chip |
| 311 | * rev. |
| 312 | */ |
| 313 | outl(0x80000000 | (0xf6 & ~3), (unsigned long)0xCF8); |
| 314 | rev = (inl((unsigned long)0xCFC) >> ((0xf6 & 3) * 8)) & 0xff; |
| 315 | } |
| 316 | switch (info->var.bits_per_pixel) { |
| 317 | case 8: |
| 318 | outb(0x1A, 0x3C4); |
| 319 | sr1a = inb(0x3C5); |
| 320 | outb(0x1B, 0x3C4); |
| 321 | sr1b = inb(0x3C5); |
| 322 | outb(0x67, 0x3D4); |
| 323 | cr67 = inb(0x3D5); |
| 324 | outb(0x6A, 0x3D4); |
| 325 | cr6a = inb(0x3D5); |
| 326 | /* Map the 3C6/7/8/9 to the IGA2 */ |
| 327 | outb(0x1A, 0x3C4); |
| 328 | outb(sr1a | 0x01, 0x3C5); |
| 329 | outb(0x1B, 0x3C4); |
| 330 | /* Second Display Engine colck always on */ |
| 331 | outb(sr1b | 0x80, 0x3C5); |
| 332 | outb(0x67, 0x3D4); |
| 333 | /* Second Display Color Depth 8 */ |
| 334 | outb(cr67 & 0x3F, 0x3D5); |
| 335 | outb(0x6A, 0x3D4); |
| 336 | /* Second Display Channel Reset CR6A[6]) */ |
| 337 | outb(cr6a & 0xBF, 0x3D5); |
| 338 | /* Second Display Channel Enable CR6A[7] */ |
| 339 | outb(cr6a | 0x80, 0x3D5); |
| 340 | /* Second Display Channel stop reset) */ |
| 341 | outb(cr6a | 0xC0, 0x3D5); |
| 342 | |
| 343 | /* Bit mask of palette */ |
| 344 | outb(0xFF, 0x3c6); |
| 345 | outb(0x00, 0x3C8); |
| 346 | if (UNICHROME_CLE266 == viaparinfo->chip_info->gfx_chip_name && |
| 347 | rev >= 15) { |
| 348 | shift = 8; |
| 349 | viafb_write_reg_mask(CR6A, VIACR, BIT5, BIT5); |
| 350 | viafb_write_reg_mask(SR15, VIASR, BIT7, BIT7); |
| 351 | } else { |
| 352 | shift = 10; |
| 353 | viafb_write_reg_mask(CR6A, VIACR, 0, BIT5); |
| 354 | viafb_write_reg_mask(SR15, VIASR, 0, BIT7); |
| 355 | } |
| 356 | for (i = 0; i < len; i++) { |
| 357 | outb((*(pred + i)) >> shift, 0x3C9); |
| 358 | outb((*(pgreen + i)) >> shift, 0x3C9); |
| 359 | outb((*(pblue + i)) >> shift, 0x3C9); |
| 360 | } |
| 361 | |
| 362 | outb(0x1A, 0x3C4); |
| 363 | /* Map the 3C6/7/8/9 to the IGA1 */ |
| 364 | outb(sr1a & 0xFE, 0x3C5); |
| 365 | /* Bit mask of palette */ |
| 366 | outb(0xFF, 0x3c6); |
| 367 | outb(0x00, 0x3C8); |
| 368 | for (i = 0; i < len; i++) { |
| 369 | outb((*(pred + i)) >> shift, 0x3C9); |
| 370 | outb((*(pgreen + i)) >> shift, 0x3C9); |
| 371 | outb((*(pblue + i)) >> shift, 0x3C9); |
| 372 | } |
| 373 | |
| 374 | outb(0x1A, 0x3C4); |
| 375 | outb(sr1a, 0x3C5); |
| 376 | outb(0x1B, 0x3C4); |
| 377 | outb(sr1b, 0x3C5); |
| 378 | outb(0x67, 0x3D4); |
| 379 | outb(cr67, 0x3D5); |
| 380 | outb(0x6A, 0x3D4); |
| 381 | outb(cr6a, 0x3D5); |
| 382 | break; |
| 383 | case 16: |
| 384 | if (len > 17) |
| 385 | return 0; /* Because static u32 pseudo_pal[17]; */ |
| 386 | for (i = 0; i < len; i++) |
| 387 | ((u32 *) info->pseudo_palette)[i] = |
| 388 | (*(pred + i) & 0xF800) | |
| 389 | ((*(pgreen + i) & 0xFC00) >> 5) | |
| 390 | ((*(pblue + i) & 0xF800) >> 11); |
| 391 | break; |
| 392 | case 32: |
| 393 | if (len > 17) |
| 394 | return 0; |
| 395 | if (ptransp) { |
| 396 | for (i = 0; i < len; i++) |
| 397 | ((u32 *) info->pseudo_palette)[i] = |
| 398 | ((*(ptransp + i) & 0xFF00) << 16) | |
| 399 | ((*(pred + i) & 0xFF00) << 8) | |
| 400 | ((*(pgreen + i) & 0xFF00)) | |
| 401 | ((*(pblue + i) & 0xFF00) >> 8); |
| 402 | } else { |
| 403 | for (i = 0; i < len; i++) |
| 404 | ((u32 *) info->pseudo_palette)[i] = |
| 405 | 0x00000000 | |
| 406 | ((*(pred + i) & 0xFF00) << 8) | |
| 407 | ((*(pgreen + i) & 0xFF00)) | |
| 408 | ((*(pblue + i) & 0xFF00) >> 8); |
| 409 | } |
| 410 | break; |
| 411 | } |
| 412 | return 0; |
| 413 | } |
| 414 | |
| 415 | static int viafb_pan_display(struct fb_var_screeninfo *var, |
| 416 | struct fb_info *info) |
| 417 | { |
| 418 | unsigned int offset; |
| 419 | |
| 420 | DEBUG_MSG(KERN_INFO "viafb_pan_display!\n"); |
| 421 | |
| 422 | offset = (var->xoffset + (var->yoffset * var->xres_virtual)) * |
| 423 | var->bits_per_pixel / 16; |
| 424 | |
| 425 | DEBUG_MSG(KERN_INFO "\nviafb_pan_display,offset =%d ", offset); |
Florian Tobias Schandinat | 09cf118 | 2009-09-22 16:47:14 -0700 | [diff] [blame] | 426 | viafb_set_primary_address(offset); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 427 | return 0; |
| 428 | } |
| 429 | |
| 430 | static int viafb_blank(int blank_mode, struct fb_info *info) |
| 431 | { |
| 432 | DEBUG_MSG(KERN_INFO "viafb_blank!\n"); |
| 433 | /* clear DPMS setting */ |
| 434 | |
| 435 | switch (blank_mode) { |
| 436 | case FB_BLANK_UNBLANK: |
| 437 | /* Screen: On, HSync: On, VSync: On */ |
| 438 | /* control CRT monitor power management */ |
| 439 | viafb_write_reg_mask(CR36, VIACR, 0x00, BIT4 + BIT5); |
| 440 | break; |
| 441 | case FB_BLANK_HSYNC_SUSPEND: |
| 442 | /* Screen: Off, HSync: Off, VSync: On */ |
| 443 | /* control CRT monitor power management */ |
| 444 | viafb_write_reg_mask(CR36, VIACR, 0x10, BIT4 + BIT5); |
| 445 | break; |
| 446 | case FB_BLANK_VSYNC_SUSPEND: |
| 447 | /* Screen: Off, HSync: On, VSync: Off */ |
| 448 | /* control CRT monitor power management */ |
| 449 | viafb_write_reg_mask(CR36, VIACR, 0x20, BIT4 + BIT5); |
| 450 | break; |
| 451 | case FB_BLANK_POWERDOWN: |
| 452 | /* Screen: Off, HSync: Off, VSync: Off */ |
| 453 | /* control CRT monitor power management */ |
| 454 | viafb_write_reg_mask(CR36, VIACR, 0x30, BIT4 + BIT5); |
| 455 | break; |
| 456 | } |
| 457 | |
| 458 | return 0; |
| 459 | } |
| 460 | |
| 461 | static int viafb_ioctl(struct fb_info *info, u_int cmd, u_long arg) |
| 462 | { |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 463 | union { |
| 464 | struct viafb_ioctl_mode viamode; |
| 465 | struct viafb_ioctl_samm viasamm; |
| 466 | struct viafb_driver_version driver_version; |
| 467 | struct fb_var_screeninfo sec_var; |
| 468 | struct _panel_size_pos_info panel_pos_size_para; |
| 469 | struct viafb_ioctl_setting viafb_setting; |
| 470 | struct device_t active_dev; |
| 471 | } u; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 472 | u32 state_info = 0; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 473 | u32 *viafb_gamma_table; |
| 474 | char driver_name[] = "viafb"; |
| 475 | |
| 476 | u32 __user *argp = (u32 __user *) arg; |
| 477 | u32 gpu32; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 478 | |
| 479 | DEBUG_MSG(KERN_INFO "viafb_ioctl: 0x%X !!\n", cmd); |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 480 | memset(&u, 0, sizeof(u)); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 481 | |
| 482 | switch (cmd) { |
| 483 | case VIAFB_GET_CHIP_INFO: |
| 484 | if (copy_to_user(argp, viaparinfo->chip_info, |
| 485 | sizeof(struct chip_information))) |
| 486 | return -EFAULT; |
| 487 | break; |
| 488 | case VIAFB_GET_INFO_SIZE: |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 489 | return put_user((u32)sizeof(struct viafb_ioctl_info), argp); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 490 | case VIAFB_GET_INFO: |
| 491 | return viafb_ioctl_get_viafb_info(arg); |
| 492 | case VIAFB_HOTPLUG: |
| 493 | return put_user(viafb_ioctl_hotplug(info->var.xres, |
| 494 | info->var.yres, |
| 495 | info->var.bits_per_pixel), argp); |
| 496 | case VIAFB_SET_HOTPLUG_FLAG: |
| 497 | if (copy_from_user(&gpu32, argp, sizeof(gpu32))) |
| 498 | return -EFAULT; |
| 499 | viafb_hotplug = (gpu32) ? 1 : 0; |
| 500 | break; |
| 501 | case VIAFB_GET_RESOLUTION: |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 502 | u.viamode.xres = (u32) viafb_hotplug_Xres; |
| 503 | u.viamode.yres = (u32) viafb_hotplug_Yres; |
| 504 | u.viamode.refresh = (u32) viafb_hotplug_refresh; |
| 505 | u.viamode.bpp = (u32) viafb_hotplug_bpp; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 506 | if (viafb_SAMM_ON == 1) { |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 507 | u.viamode.xres_sec = viafb_second_xres; |
| 508 | u.viamode.yres_sec = viafb_second_yres; |
| 509 | u.viamode.virtual_xres_sec = viafb_second_virtual_xres; |
| 510 | u.viamode.virtual_yres_sec = viafb_second_virtual_yres; |
| 511 | u.viamode.refresh_sec = viafb_refresh1; |
| 512 | u.viamode.bpp_sec = viafb_bpp1; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 513 | } else { |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 514 | u.viamode.xres_sec = 0; |
| 515 | u.viamode.yres_sec = 0; |
| 516 | u.viamode.virtual_xres_sec = 0; |
| 517 | u.viamode.virtual_yres_sec = 0; |
| 518 | u.viamode.refresh_sec = 0; |
| 519 | u.viamode.bpp_sec = 0; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 520 | } |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 521 | if (copy_to_user(argp, &u.viamode, sizeof(u.viamode))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 522 | return -EFAULT; |
| 523 | break; |
| 524 | case VIAFB_GET_SAMM_INFO: |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 525 | u.viasamm.samm_status = viafb_SAMM_ON; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 526 | |
| 527 | if (viafb_SAMM_ON == 1) { |
| 528 | if (viafb_dual_fb) { |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 529 | u.viasamm.size_prim = viaparinfo->fbmem_free; |
| 530 | u.viasamm.size_sec = viaparinfo1->fbmem_free; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 531 | } else { |
| 532 | if (viafb_second_size) { |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 533 | u.viasamm.size_prim = |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 534 | viaparinfo->fbmem_free - |
| 535 | viafb_second_size * 1024 * 1024; |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 536 | u.viasamm.size_sec = |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 537 | viafb_second_size * 1024 * 1024; |
| 538 | } else { |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 539 | u.viasamm.size_prim = |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 540 | viaparinfo->fbmem_free >> 1; |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 541 | u.viasamm.size_sec = |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 542 | (viaparinfo->fbmem_free >> 1); |
| 543 | } |
| 544 | } |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 545 | u.viasamm.mem_base = viaparinfo->fbmem; |
| 546 | u.viasamm.offset_sec = viafb_second_offset; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 547 | } else { |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 548 | u.viasamm.size_prim = |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 549 | viaparinfo->memsize - viaparinfo->fbmem_used; |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 550 | u.viasamm.size_sec = 0; |
| 551 | u.viasamm.mem_base = viaparinfo->fbmem; |
| 552 | u.viasamm.offset_sec = 0; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 553 | } |
| 554 | |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 555 | if (copy_to_user(argp, &u.viasamm, sizeof(u.viasamm))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 556 | return -EFAULT; |
| 557 | |
| 558 | break; |
| 559 | case VIAFB_TURN_ON_OUTPUT_DEVICE: |
| 560 | if (copy_from_user(&gpu32, argp, sizeof(gpu32))) |
| 561 | return -EFAULT; |
| 562 | if (gpu32 & CRT_Device) |
| 563 | viafb_crt_enable(); |
| 564 | if (gpu32 & DVI_Device) |
| 565 | viafb_dvi_enable(); |
| 566 | if (gpu32 & LCD_Device) |
| 567 | viafb_lcd_enable(); |
| 568 | break; |
| 569 | case VIAFB_TURN_OFF_OUTPUT_DEVICE: |
| 570 | if (copy_from_user(&gpu32, argp, sizeof(gpu32))) |
| 571 | return -EFAULT; |
| 572 | if (gpu32 & CRT_Device) |
| 573 | viafb_crt_disable(); |
| 574 | if (gpu32 & DVI_Device) |
| 575 | viafb_dvi_disable(); |
| 576 | if (gpu32 & LCD_Device) |
| 577 | viafb_lcd_disable(); |
| 578 | break; |
| 579 | case VIAFB_SET_DEVICE: |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 580 | if (copy_from_user(&u.active_dev, (void *)argp, |
| 581 | sizeof(u.active_dev))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 582 | return -EFAULT; |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 583 | viafb_set_device(u.active_dev); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 584 | viafb_set_par(info); |
| 585 | break; |
| 586 | case VIAFB_GET_DEVICE: |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 587 | u.active_dev.crt = viafb_CRT_ON; |
| 588 | u.active_dev.dvi = viafb_DVI_ON; |
| 589 | u.active_dev.lcd = viafb_LCD_ON; |
| 590 | u.active_dev.samm = viafb_SAMM_ON; |
| 591 | u.active_dev.primary_dev = viafb_primary_dev; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 592 | |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 593 | u.active_dev.lcd_dsp_cent = viafb_lcd_dsp_method; |
| 594 | u.active_dev.lcd_panel_id = viafb_lcd_panel_id; |
| 595 | u.active_dev.lcd_mode = viafb_lcd_mode; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 596 | |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 597 | u.active_dev.xres = viafb_hotplug_Xres; |
| 598 | u.active_dev.yres = viafb_hotplug_Yres; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 599 | |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 600 | u.active_dev.xres1 = viafb_second_xres; |
| 601 | u.active_dev.yres1 = viafb_second_yres; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 602 | |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 603 | u.active_dev.bpp = viafb_bpp; |
| 604 | u.active_dev.bpp1 = viafb_bpp1; |
| 605 | u.active_dev.refresh = viafb_refresh; |
| 606 | u.active_dev.refresh1 = viafb_refresh1; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 607 | |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 608 | u.active_dev.epia_dvi = viafb_platform_epia_dvi; |
| 609 | u.active_dev.lcd_dual_edge = viafb_device_lcd_dualedge; |
| 610 | u.active_dev.bus_width = viafb_bus_width; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 611 | |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 612 | if (copy_to_user(argp, &u.active_dev, sizeof(u.active_dev))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 613 | return -EFAULT; |
| 614 | break; |
| 615 | |
| 616 | case VIAFB_GET_DRIVER_VERSION: |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 617 | u.driver_version.iMajorNum = VERSION_MAJOR; |
| 618 | u.driver_version.iKernelNum = VERSION_KERNEL; |
| 619 | u.driver_version.iOSNum = VERSION_OS; |
| 620 | u.driver_version.iMinorNum = VERSION_MINOR; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 621 | |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 622 | if (copy_to_user(argp, &u.driver_version, |
| 623 | sizeof(u.driver_version))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 624 | return -EFAULT; |
| 625 | |
| 626 | break; |
| 627 | |
| 628 | case VIAFB_SET_DEVICE_INFO: |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 629 | if (copy_from_user(&u.viafb_setting, |
| 630 | argp, sizeof(u.viafb_setting))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 631 | return -EFAULT; |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 632 | if (apply_device_setting(u.viafb_setting, info) < 0) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 633 | return -EINVAL; |
| 634 | |
| 635 | break; |
| 636 | |
| 637 | case VIAFB_SET_SECOND_MODE: |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 638 | if (copy_from_user(&u.sec_var, argp, sizeof(u.sec_var))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 639 | return -EFAULT; |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 640 | apply_second_mode_setting(&u.sec_var); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 641 | break; |
| 642 | |
| 643 | case VIAFB_GET_DEVICE_INFO: |
| 644 | |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 645 | retrieve_device_setting(&u.viafb_setting); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 646 | |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 647 | if (copy_to_user(argp, &u.viafb_setting, |
| 648 | sizeof(u.viafb_setting))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 649 | return -EFAULT; |
| 650 | |
| 651 | break; |
| 652 | |
| 653 | case VIAFB_GET_DEVICE_SUPPORT: |
| 654 | viafb_get_device_support_state(&state_info); |
| 655 | if (put_user(state_info, argp)) |
| 656 | return -EFAULT; |
| 657 | break; |
| 658 | |
| 659 | case VIAFB_GET_DEVICE_CONNECT: |
| 660 | viafb_get_device_connect_state(&state_info); |
| 661 | if (put_user(state_info, argp)) |
| 662 | return -EFAULT; |
| 663 | break; |
| 664 | |
| 665 | case VIAFB_GET_PANEL_SUPPORT_EXPAND: |
| 666 | state_info = |
| 667 | viafb_lcd_get_support_expand_state(info->var.xres, |
| 668 | info->var.yres); |
| 669 | if (put_user(state_info, argp)) |
| 670 | return -EFAULT; |
| 671 | break; |
| 672 | |
| 673 | case VIAFB_GET_DRIVER_NAME: |
| 674 | if (copy_to_user(argp, driver_name, sizeof(driver_name))) |
| 675 | return -EFAULT; |
| 676 | break; |
| 677 | |
| 678 | case VIAFB_SET_GAMMA_LUT: |
| 679 | viafb_gamma_table = kmalloc(256 * sizeof(u32), GFP_KERNEL); |
| 680 | if (!viafb_gamma_table) |
| 681 | return -ENOMEM; |
| 682 | if (copy_from_user(viafb_gamma_table, argp, |
| 683 | sizeof(viafb_gamma_table))) { |
| 684 | kfree(viafb_gamma_table); |
| 685 | return -EFAULT; |
| 686 | } |
| 687 | viafb_set_gamma_table(viafb_bpp, viafb_gamma_table); |
| 688 | kfree(viafb_gamma_table); |
| 689 | break; |
| 690 | |
| 691 | case VIAFB_GET_GAMMA_LUT: |
| 692 | viafb_gamma_table = kmalloc(256 * sizeof(u32), GFP_KERNEL); |
| 693 | if (!viafb_gamma_table) |
| 694 | return -ENOMEM; |
| 695 | viafb_get_gamma_table(viafb_gamma_table); |
| 696 | if (copy_to_user(argp, viafb_gamma_table, |
| 697 | sizeof(viafb_gamma_table))) { |
| 698 | kfree(viafb_gamma_table); |
| 699 | return -EFAULT; |
| 700 | } |
| 701 | kfree(viafb_gamma_table); |
| 702 | break; |
| 703 | |
| 704 | case VIAFB_GET_GAMMA_SUPPORT_STATE: |
| 705 | viafb_get_gamma_support_state(viafb_bpp, &state_info); |
| 706 | if (put_user(state_info, argp)) |
| 707 | return -EFAULT; |
| 708 | break; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 709 | case VIAFB_SYNC_SURFACE: |
| 710 | DEBUG_MSG(KERN_INFO "lobo VIAFB_SYNC_SURFACE\n"); |
| 711 | break; |
| 712 | case VIAFB_GET_DRIVER_CAPS: |
| 713 | break; |
| 714 | |
| 715 | case VIAFB_GET_PANEL_MAX_SIZE: |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 716 | if (copy_from_user(&u.panel_pos_size_para, argp, |
| 717 | sizeof(u.panel_pos_size_para))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 718 | return -EFAULT; |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 719 | u.panel_pos_size_para.x = u.panel_pos_size_para.y = 0; |
| 720 | if (copy_to_user(argp, &u.panel_pos_size_para, |
| 721 | sizeof(u.panel_pos_size_para))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 722 | return -EFAULT; |
| 723 | break; |
| 724 | case VIAFB_GET_PANEL_MAX_POSITION: |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 725 | if (copy_from_user(&u.panel_pos_size_para, argp, |
| 726 | sizeof(u.panel_pos_size_para))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 727 | return -EFAULT; |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 728 | u.panel_pos_size_para.x = u.panel_pos_size_para.y = 0; |
| 729 | if (copy_to_user(argp, &u.panel_pos_size_para, |
| 730 | sizeof(u.panel_pos_size_para))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 731 | return -EFAULT; |
| 732 | break; |
| 733 | |
| 734 | case VIAFB_GET_PANEL_POSITION: |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 735 | if (copy_from_user(&u.panel_pos_size_para, argp, |
| 736 | sizeof(u.panel_pos_size_para))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 737 | return -EFAULT; |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 738 | u.panel_pos_size_para.x = u.panel_pos_size_para.y = 0; |
| 739 | if (copy_to_user(argp, &u.panel_pos_size_para, |
| 740 | sizeof(u.panel_pos_size_para))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 741 | return -EFAULT; |
| 742 | break; |
| 743 | case VIAFB_GET_PANEL_SIZE: |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 744 | if (copy_from_user(&u.panel_pos_size_para, argp, |
| 745 | sizeof(u.panel_pos_size_para))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 746 | return -EFAULT; |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 747 | u.panel_pos_size_para.x = u.panel_pos_size_para.y = 0; |
| 748 | if (copy_to_user(argp, &u.panel_pos_size_para, |
| 749 | sizeof(u.panel_pos_size_para))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 750 | return -EFAULT; |
| 751 | break; |
| 752 | |
| 753 | case VIAFB_SET_PANEL_POSITION: |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 754 | if (copy_from_user(&u.panel_pos_size_para, argp, |
| 755 | sizeof(u.panel_pos_size_para))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 756 | return -EFAULT; |
| 757 | break; |
| 758 | case VIAFB_SET_PANEL_SIZE: |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 759 | if (copy_from_user(&u.panel_pos_size_para, argp, |
| 760 | sizeof(u.panel_pos_size_para))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 761 | return -EFAULT; |
| 762 | break; |
| 763 | |
| 764 | default: |
| 765 | return -EINVAL; |
| 766 | } |
| 767 | |
| 768 | return 0; |
| 769 | } |
| 770 | |
| 771 | static void viafb_fillrect(struct fb_info *info, |
| 772 | const struct fb_fillrect *rect) |
| 773 | { |
Florian Tobias Schandinat | c3e2567 | 2009-09-22 16:47:26 -0700 | [diff] [blame] | 774 | struct viafb_par *viapar = info->par; |
Florian Tobias Schandinat | 31de59d | 2009-09-22 16:47:31 -0700 | [diff] [blame] | 775 | struct viafb_shared *shared = viapar->shared; |
Florian Tobias Schandinat | c3e2567 | 2009-09-22 16:47:26 -0700 | [diff] [blame] | 776 | u32 fg_color; |
| 777 | u8 rop; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 778 | |
Florian Tobias Schandinat | 31de59d | 2009-09-22 16:47:31 -0700 | [diff] [blame] | 779 | if (info->flags & FBINFO_HWACCEL_DISABLED || !shared->hw_bitblt) { |
Hannes Eder | 2899bb0 | 2009-01-06 14:42:32 -0800 | [diff] [blame] | 780 | cfb_fillrect(info, rect); |
| 781 | return; |
| 782 | } |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 783 | |
| 784 | if (!rect->width || !rect->height) |
| 785 | return; |
| 786 | |
Florian Tobias Schandinat | c3e2567 | 2009-09-22 16:47:26 -0700 | [diff] [blame] | 787 | if (info->fix.visual == FB_VISUAL_TRUECOLOR) |
| 788 | fg_color = ((u32 *)info->pseudo_palette)[rect->color]; |
| 789 | else |
| 790 | fg_color = rect->color; |
| 791 | |
| 792 | if (rect->rop == ROP_XOR) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 793 | rop = 0x5A; |
Florian Tobias Schandinat | c3e2567 | 2009-09-22 16:47:26 -0700 | [diff] [blame] | 794 | else |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 795 | rop = 0xF0; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 796 | |
Florian Tobias Schandinat | c3e2567 | 2009-09-22 16:47:26 -0700 | [diff] [blame] | 797 | DEBUG_MSG(KERN_DEBUG "viafb 2D engine: fillrect\n"); |
Florian Tobias Schandinat | 31de59d | 2009-09-22 16:47:31 -0700 | [diff] [blame] | 798 | if (shared->hw_bitblt(shared->engine_mmio, VIA_BITBLT_FILL, |
Florian Tobias Schandinat | c3e2567 | 2009-09-22 16:47:26 -0700 | [diff] [blame] | 799 | rect->width, rect->height, info->var.bits_per_pixel, |
| 800 | viapar->vram_addr, info->fix.line_length, rect->dx, rect->dy, |
| 801 | NULL, 0, 0, 0, 0, fg_color, 0, rop)) |
| 802 | cfb_fillrect(info, rect); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | static void viafb_copyarea(struct fb_info *info, |
| 806 | const struct fb_copyarea *area) |
| 807 | { |
Florian Tobias Schandinat | c3e2567 | 2009-09-22 16:47:26 -0700 | [diff] [blame] | 808 | struct viafb_par *viapar = info->par; |
Florian Tobias Schandinat | 31de59d | 2009-09-22 16:47:31 -0700 | [diff] [blame] | 809 | struct viafb_shared *shared = viapar->shared; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 810 | |
Florian Tobias Schandinat | 31de59d | 2009-09-22 16:47:31 -0700 | [diff] [blame] | 811 | if (info->flags & FBINFO_HWACCEL_DISABLED || !shared->hw_bitblt) { |
Hannes Eder | 2899bb0 | 2009-01-06 14:42:32 -0800 | [diff] [blame] | 812 | cfb_copyarea(info, area); |
| 813 | return; |
| 814 | } |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 815 | |
| 816 | if (!area->width || !area->height) |
| 817 | return; |
| 818 | |
Florian Tobias Schandinat | c3e2567 | 2009-09-22 16:47:26 -0700 | [diff] [blame] | 819 | DEBUG_MSG(KERN_DEBUG "viafb 2D engine: copyarea\n"); |
Florian Tobias Schandinat | 31de59d | 2009-09-22 16:47:31 -0700 | [diff] [blame] | 820 | if (shared->hw_bitblt(shared->engine_mmio, VIA_BITBLT_COLOR, |
Florian Tobias Schandinat | c3e2567 | 2009-09-22 16:47:26 -0700 | [diff] [blame] | 821 | area->width, area->height, info->var.bits_per_pixel, |
| 822 | viapar->vram_addr, info->fix.line_length, area->dx, area->dy, |
| 823 | NULL, viapar->vram_addr, info->fix.line_length, |
| 824 | area->sx, area->sy, 0, 0, 0)) |
| 825 | cfb_copyarea(info, area); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | static void viafb_imageblit(struct fb_info *info, |
| 829 | const struct fb_image *image) |
| 830 | { |
Florian Tobias Schandinat | c3e2567 | 2009-09-22 16:47:26 -0700 | [diff] [blame] | 831 | struct viafb_par *viapar = info->par; |
Florian Tobias Schandinat | 31de59d | 2009-09-22 16:47:31 -0700 | [diff] [blame] | 832 | struct viafb_shared *shared = viapar->shared; |
Florian Tobias Schandinat | c3e2567 | 2009-09-22 16:47:26 -0700 | [diff] [blame] | 833 | u32 fg_color = 0, bg_color = 0; |
| 834 | u8 op; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 835 | |
Florian Tobias Schandinat | 31de59d | 2009-09-22 16:47:31 -0700 | [diff] [blame] | 836 | if (info->flags & FBINFO_HWACCEL_DISABLED || !shared->hw_bitblt || |
Florian Tobias Schandinat | c3e2567 | 2009-09-22 16:47:26 -0700 | [diff] [blame] | 837 | (image->depth != 1 && image->depth != viapar->depth)) { |
Hannes Eder | 2899bb0 | 2009-01-06 14:42:32 -0800 | [diff] [blame] | 838 | cfb_imageblit(info, image); |
| 839 | return; |
| 840 | } |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 841 | |
Florian Tobias Schandinat | c3e2567 | 2009-09-22 16:47:26 -0700 | [diff] [blame] | 842 | if (image->depth == 1) { |
| 843 | op = VIA_BITBLT_MONO; |
| 844 | if (info->fix.visual == FB_VISUAL_TRUECOLOR) { |
| 845 | fg_color = |
| 846 | ((u32 *)info->pseudo_palette)[image->fg_color]; |
| 847 | bg_color = |
| 848 | ((u32 *)info->pseudo_palette)[image->bg_color]; |
| 849 | } else { |
| 850 | fg_color = image->fg_color; |
| 851 | bg_color = image->bg_color; |
| 852 | } |
| 853 | } else |
| 854 | op = VIA_BITBLT_COLOR; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 855 | |
Florian Tobias Schandinat | c3e2567 | 2009-09-22 16:47:26 -0700 | [diff] [blame] | 856 | DEBUG_MSG(KERN_DEBUG "viafb 2D engine: imageblit\n"); |
Florian Tobias Schandinat | 31de59d | 2009-09-22 16:47:31 -0700 | [diff] [blame] | 857 | if (shared->hw_bitblt(shared->engine_mmio, op, |
Florian Tobias Schandinat | c3e2567 | 2009-09-22 16:47:26 -0700 | [diff] [blame] | 858 | image->width, image->height, info->var.bits_per_pixel, |
| 859 | viapar->vram_addr, info->fix.line_length, image->dx, image->dy, |
| 860 | (u32 *)image->data, 0, 0, 0, 0, fg_color, bg_color, 0)) |
| 861 | cfb_imageblit(info, image); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | static int viafb_cursor(struct fb_info *info, struct fb_cursor *cursor) |
| 865 | { |
Florian Tobias Schandinat | 5016af53 | 2009-09-22 16:47:28 -0700 | [diff] [blame] | 866 | struct viafb_par *viapar = info->par; |
Florian Tobias Schandinat | 31de59d | 2009-09-22 16:47:31 -0700 | [diff] [blame] | 867 | void __iomem *engine = viapar->shared->engine_mmio; |
Florian Tobias Schandinat | 5016af53 | 2009-09-22 16:47:28 -0700 | [diff] [blame] | 868 | u32 temp, xx, yy, bg_color = 0, fg_color = 0, |
| 869 | chip_name = viapar->shared->chip_info.gfx_chip_name; |
| 870 | int i, j = 0, cur_size = 64; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 871 | |
Florian Tobias Schandinat | 5016af53 | 2009-09-22 16:47:28 -0700 | [diff] [blame] | 872 | if (info->flags & FBINFO_HWACCEL_DISABLED || info != viafbinfo) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 873 | return -ENODEV; |
| 874 | |
Florian Tobias Schandinat | 5016af53 | 2009-09-22 16:47:28 -0700 | [diff] [blame] | 875 | if (chip_name == UNICHROME_CLE266 && viapar->iga_path == IGA2) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 876 | return -ENODEV; |
| 877 | |
| 878 | viafb_show_hw_cursor(info, HW_Cursor_OFF); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 879 | |
| 880 | if (cursor->set & FB_CUR_SETHOT) { |
Florian Tobias Schandinat | 5016af53 | 2009-09-22 16:47:28 -0700 | [diff] [blame] | 881 | temp = (cursor->hot.x << 16) + cursor->hot.y; |
Florian Tobias Schandinat | 31de59d | 2009-09-22 16:47:31 -0700 | [diff] [blame] | 882 | writel(temp, engine + VIA_REG_CURSOR_ORG); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | if (cursor->set & FB_CUR_SETPOS) { |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 886 | yy = cursor->image.dy - info->var.yoffset; |
| 887 | xx = cursor->image.dx - info->var.xoffset; |
| 888 | temp = yy & 0xFFFF; |
| 889 | temp |= (xx << 16); |
Florian Tobias Schandinat | 31de59d | 2009-09-22 16:47:31 -0700 | [diff] [blame] | 890 | writel(temp, engine + VIA_REG_CURSOR_POS); |
Florian Tobias Schandinat | 5016af53 | 2009-09-22 16:47:28 -0700 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | if (cursor->image.width <= 32 && cursor->image.height <= 32) |
| 894 | cur_size = 32; |
| 895 | else if (cursor->image.width <= 64 && cursor->image.height <= 64) |
| 896 | cur_size = 64; |
| 897 | else { |
| 898 | printk(KERN_WARNING "viafb_cursor: The cursor is too large " |
| 899 | "%dx%d", cursor->image.width, cursor->image.height); |
| 900 | return -ENXIO; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 901 | } |
| 902 | |
| 903 | if (cursor->set & FB_CUR_SETSIZE) { |
Florian Tobias Schandinat | 31de59d | 2009-09-22 16:47:31 -0700 | [diff] [blame] | 904 | temp = readl(engine + VIA_REG_CURSOR_MODE); |
Florian Tobias Schandinat | 5016af53 | 2009-09-22 16:47:28 -0700 | [diff] [blame] | 905 | if (cur_size == 32) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 906 | temp |= 0x2; |
Florian Tobias Schandinat | 5016af53 | 2009-09-22 16:47:28 -0700 | [diff] [blame] | 907 | else |
| 908 | temp &= ~0x2; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 909 | |
Florian Tobias Schandinat | 31de59d | 2009-09-22 16:47:31 -0700 | [diff] [blame] | 910 | writel(temp, engine + VIA_REG_CURSOR_MODE); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | if (cursor->set & FB_CUR_SETCMAP) { |
Florian Tobias Schandinat | 5016af53 | 2009-09-22 16:47:28 -0700 | [diff] [blame] | 914 | fg_color = cursor->image.fg_color; |
| 915 | bg_color = cursor->image.bg_color; |
| 916 | if (chip_name == UNICHROME_CX700 || |
Harald Welte | 0306ab1 | 2009-09-22 16:47:35 -0700 | [diff] [blame] | 917 | chip_name == UNICHROME_VX800 || |
| 918 | chip_name == UNICHROME_VX855) { |
Florian Tobias Schandinat | 5016af53 | 2009-09-22 16:47:28 -0700 | [diff] [blame] | 919 | fg_color = |
| 920 | ((info->cmap.red[fg_color] & 0xFFC0) << 14) | |
| 921 | ((info->cmap.green[fg_color] & 0xFFC0) << 4) | |
| 922 | ((info->cmap.blue[fg_color] & 0xFFC0) >> 6); |
| 923 | bg_color = |
| 924 | ((info->cmap.red[bg_color] & 0xFFC0) << 14) | |
| 925 | ((info->cmap.green[bg_color] & 0xFFC0) << 4) | |
| 926 | ((info->cmap.blue[bg_color] & 0xFFC0) >> 6); |
| 927 | } else { |
| 928 | fg_color = |
| 929 | ((info->cmap.red[fg_color] & 0xFF00) << 8) | |
| 930 | (info->cmap.green[fg_color] & 0xFF00) | |
| 931 | ((info->cmap.blue[fg_color] & 0xFF00) >> 8); |
| 932 | bg_color = |
| 933 | ((info->cmap.red[bg_color] & 0xFF00) << 8) | |
| 934 | (info->cmap.green[bg_color] & 0xFF00) | |
| 935 | ((info->cmap.blue[bg_color] & 0xFF00) >> 8); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 936 | } |
| 937 | |
Florian Tobias Schandinat | 31de59d | 2009-09-22 16:47:31 -0700 | [diff] [blame] | 938 | writel(bg_color, engine + VIA_REG_CURSOR_BG); |
| 939 | writel(fg_color, engine + VIA_REG_CURSOR_FG); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | if (cursor->set & FB_CUR_SETSHAPE) { |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 943 | struct { |
Florian Tobias Schandinat | 5016af53 | 2009-09-22 16:47:28 -0700 | [diff] [blame] | 944 | u8 data[CURSOR_SIZE]; |
| 945 | u32 bak[CURSOR_SIZE / 4]; |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 946 | } *cr_data = kzalloc(sizeof(*cr_data), GFP_ATOMIC); |
Florian Tobias Schandinat | 5016af53 | 2009-09-22 16:47:28 -0700 | [diff] [blame] | 947 | int size = ((cursor->image.width + 7) >> 3) * |
| 948 | cursor->image.height; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 949 | |
Florian Tobias Schandinat | 5016af53 | 2009-09-22 16:47:28 -0700 | [diff] [blame] | 950 | if (!cr_data) |
| 951 | return -ENOMEM; |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 952 | |
Florian Tobias Schandinat | 5016af53 | 2009-09-22 16:47:28 -0700 | [diff] [blame] | 953 | if (cur_size == 32) { |
| 954 | for (i = 0; i < (CURSOR_SIZE / 4); i++) { |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 955 | cr_data->bak[i] = 0x0; |
| 956 | cr_data->bak[i + 1] = 0xFFFFFFFF; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 957 | i += 1; |
| 958 | } |
Florian Tobias Schandinat | 5016af53 | 2009-09-22 16:47:28 -0700 | [diff] [blame] | 959 | } else { |
| 960 | for (i = 0; i < (CURSOR_SIZE / 4); i++) { |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 961 | cr_data->bak[i] = 0x0; |
| 962 | cr_data->bak[i + 1] = 0x0; |
| 963 | cr_data->bak[i + 2] = 0xFFFFFFFF; |
| 964 | cr_data->bak[i + 3] = 0xFFFFFFFF; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 965 | i += 3; |
| 966 | } |
| 967 | } |
| 968 | |
Florian Tobias Schandinat | 5016af53 | 2009-09-22 16:47:28 -0700 | [diff] [blame] | 969 | switch (cursor->rop) { |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 970 | case ROP_XOR: |
| 971 | for (i = 0; i < size; i++) |
Florian Tobias Schandinat | 5016af53 | 2009-09-22 16:47:28 -0700 | [diff] [blame] | 972 | cr_data->data[i] = cursor->mask[i]; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 973 | break; |
| 974 | case ROP_COPY: |
| 975 | |
| 976 | for (i = 0; i < size; i++) |
Florian Tobias Schandinat | 5016af53 | 2009-09-22 16:47:28 -0700 | [diff] [blame] | 977 | cr_data->data[i] = cursor->mask[i]; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 978 | break; |
| 979 | default: |
| 980 | break; |
| 981 | } |
| 982 | |
Florian Tobias Schandinat | 5016af53 | 2009-09-22 16:47:28 -0700 | [diff] [blame] | 983 | if (cur_size == 32) { |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 984 | for (i = 0; i < size; i++) { |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 985 | cr_data->bak[j] = (u32) cr_data->data[i]; |
| 986 | cr_data->bak[j + 1] = ~cr_data->bak[j]; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 987 | j += 2; |
| 988 | } |
Florian Tobias Schandinat | 5016af53 | 2009-09-22 16:47:28 -0700 | [diff] [blame] | 989 | } else { |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 990 | for (i = 0; i < size; i++) { |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 991 | cr_data->bak[j] = (u32) cr_data->data[i]; |
| 992 | cr_data->bak[j + 1] = 0x0; |
| 993 | cr_data->bak[j + 2] = ~cr_data->bak[j]; |
| 994 | cr_data->bak[j + 3] = ~cr_data->bak[j + 1]; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 995 | j += 4; |
| 996 | } |
| 997 | } |
| 998 | |
Florian Tobias Schandinat | 5016af53 | 2009-09-22 16:47:28 -0700 | [diff] [blame] | 999 | memcpy_toio(viafbinfo->screen_base + viapar->shared-> |
| 1000 | cursor_vram_addr, cr_data->bak, CURSOR_SIZE); |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 1001 | kfree(cr_data); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1002 | } |
| 1003 | |
Florian Tobias Schandinat | 5016af53 | 2009-09-22 16:47:28 -0700 | [diff] [blame] | 1004 | if (cursor->enable) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1005 | viafb_show_hw_cursor(info, HW_Cursor_ON); |
| 1006 | |
| 1007 | return 0; |
| 1008 | } |
| 1009 | |
| 1010 | static int viafb_sync(struct fb_info *info) |
| 1011 | { |
Florian Tobias Schandinat | 31de59d | 2009-09-22 16:47:31 -0700 | [diff] [blame] | 1012 | if (!(info->flags & FBINFO_HWACCEL_DISABLED)) |
| 1013 | viafb_wait_engine_idle(info); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1014 | return 0; |
| 1015 | } |
| 1016 | |
Florian Tobias Schandinat | 5215944 | 2009-08-06 15:07:34 -0700 | [diff] [blame] | 1017 | int viafb_get_mode_index(int hres, int vres) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1018 | { |
| 1019 | u32 i; |
| 1020 | DEBUG_MSG(KERN_INFO "viafb_get_mode_index!\n"); |
| 1021 | |
Florian Tobias Schandinat | 13147f2 | 2009-09-22 16:47:17 -0700 | [diff] [blame] | 1022 | for (i = 0; i < NUM_TOTAL_MODETABLE; i++) |
| 1023 | if (CLE266Modes[i].mode_array && |
| 1024 | CLE266Modes[i].crtc[0].crtc.hor_addr == hres && |
| 1025 | CLE266Modes[i].crtc[0].crtc.ver_addr == vres) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1026 | break; |
| 1027 | |
Florian Tobias Schandinat | 13147f2 | 2009-09-22 16:47:17 -0700 | [diff] [blame] | 1028 | if (i == NUM_TOTAL_MODETABLE) |
| 1029 | return VIA_RES_INVALID; |
| 1030 | |
| 1031 | return CLE266Modes[i].ModeIndex; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | static void check_available_device_to_enable(int device_id) |
| 1035 | { |
| 1036 | int device_num = 0; |
| 1037 | |
| 1038 | /* Initialize: */ |
| 1039 | viafb_CRT_ON = STATE_OFF; |
| 1040 | viafb_DVI_ON = STATE_OFF; |
| 1041 | viafb_LCD_ON = STATE_OFF; |
| 1042 | viafb_LCD2_ON = STATE_OFF; |
| 1043 | viafb_DeviceStatus = None_Device; |
| 1044 | |
| 1045 | if ((device_id & CRT_Device) && (device_num < MAX_ACTIVE_DEV_NUM)) { |
| 1046 | viafb_CRT_ON = STATE_ON; |
| 1047 | device_num++; |
| 1048 | viafb_DeviceStatus |= CRT_Device; |
| 1049 | } |
| 1050 | |
| 1051 | if ((device_id & DVI_Device) && (device_num < MAX_ACTIVE_DEV_NUM)) { |
| 1052 | viafb_DVI_ON = STATE_ON; |
| 1053 | device_num++; |
| 1054 | viafb_DeviceStatus |= DVI_Device; |
| 1055 | } |
| 1056 | |
| 1057 | if ((device_id & LCD_Device) && (device_num < MAX_ACTIVE_DEV_NUM)) { |
| 1058 | viafb_LCD_ON = STATE_ON; |
| 1059 | device_num++; |
| 1060 | viafb_DeviceStatus |= LCD_Device; |
| 1061 | } |
| 1062 | |
| 1063 | if ((device_id & LCD2_Device) && (device_num < MAX_ACTIVE_DEV_NUM)) { |
| 1064 | viafb_LCD2_ON = STATE_ON; |
| 1065 | device_num++; |
| 1066 | viafb_DeviceStatus |= LCD2_Device; |
| 1067 | } |
| 1068 | |
| 1069 | if (viafb_DeviceStatus == None_Device) { |
| 1070 | /* Use CRT as default active device: */ |
| 1071 | viafb_CRT_ON = STATE_ON; |
| 1072 | viafb_DeviceStatus = CRT_Device; |
| 1073 | } |
| 1074 | DEBUG_MSG(KERN_INFO "Device Status:%x", viafb_DeviceStatus); |
| 1075 | } |
| 1076 | |
| 1077 | static void viafb_set_device(struct device_t active_dev) |
| 1078 | { |
| 1079 | /* Check available device to enable: */ |
| 1080 | int device_id = None_Device; |
| 1081 | if (active_dev.crt) |
| 1082 | device_id |= CRT_Device; |
| 1083 | if (active_dev.dvi) |
| 1084 | device_id |= DVI_Device; |
| 1085 | if (active_dev.lcd) |
| 1086 | device_id |= LCD_Device; |
| 1087 | |
| 1088 | check_available_device_to_enable(device_id); |
| 1089 | |
| 1090 | /* Check property of LCD: */ |
| 1091 | if (viafb_LCD_ON) { |
| 1092 | if (active_dev.lcd_dsp_cent) { |
| 1093 | viaparinfo->lvds_setting_info->display_method = |
| 1094 | viafb_lcd_dsp_method = LCD_CENTERING; |
| 1095 | } else { |
| 1096 | viaparinfo->lvds_setting_info->display_method = |
| 1097 | viafb_lcd_dsp_method = LCD_EXPANDSION; |
| 1098 | } |
| 1099 | |
| 1100 | if (active_dev.lcd_mode == LCD_SPWG) { |
| 1101 | viaparinfo->lvds_setting_info->lcd_mode = |
| 1102 | viafb_lcd_mode = LCD_SPWG; |
| 1103 | } else { |
| 1104 | viaparinfo->lvds_setting_info->lcd_mode = |
| 1105 | viafb_lcd_mode = LCD_OPENLDI; |
| 1106 | } |
| 1107 | |
| 1108 | if (active_dev.lcd_panel_id <= LCD_PANEL_ID_MAXIMUM) { |
| 1109 | viafb_lcd_panel_id = active_dev.lcd_panel_id; |
| 1110 | viafb_init_lcd_size(); |
| 1111 | } |
| 1112 | } |
| 1113 | |
| 1114 | /* Check property of mode: */ |
| 1115 | if (!active_dev.xres1) |
| 1116 | viafb_second_xres = 640; |
| 1117 | else |
| 1118 | viafb_second_xres = active_dev.xres1; |
| 1119 | if (!active_dev.yres1) |
| 1120 | viafb_second_yres = 480; |
| 1121 | else |
| 1122 | viafb_second_yres = active_dev.yres1; |
| 1123 | if (active_dev.bpp != 0) |
| 1124 | viafb_bpp = active_dev.bpp; |
| 1125 | if (active_dev.bpp1 != 0) |
| 1126 | viafb_bpp1 = active_dev.bpp1; |
| 1127 | if (active_dev.refresh != 0) |
| 1128 | viafb_refresh = active_dev.refresh; |
| 1129 | if (active_dev.refresh1 != 0) |
| 1130 | viafb_refresh1 = active_dev.refresh1; |
| 1131 | if ((active_dev.samm == STATE_OFF) || (active_dev.samm == STATE_ON)) |
| 1132 | viafb_SAMM_ON = active_dev.samm; |
| 1133 | viafb_primary_dev = active_dev.primary_dev; |
| 1134 | |
Florian Tobias Schandinat | 09cf118 | 2009-09-22 16:47:14 -0700 | [diff] [blame] | 1135 | viafb_set_primary_address(0); |
| 1136 | viafb_set_secondary_address(viafb_SAMM_ON ? viafb_second_offset : 0); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1137 | viafb_set_iga_path(); |
| 1138 | } |
| 1139 | |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1140 | static int get_primary_device(void) |
| 1141 | { |
| 1142 | int primary_device = 0; |
| 1143 | /* Rule: device on iga1 path are the primary device. */ |
| 1144 | if (viafb_SAMM_ON) { |
| 1145 | if (viafb_CRT_ON) { |
| 1146 | if (viaparinfo->crt_setting_info->iga_path == IGA1) { |
| 1147 | DEBUG_MSG(KERN_INFO "CRT IGA Path:%d\n", |
| 1148 | viaparinfo-> |
| 1149 | crt_setting_info->iga_path); |
| 1150 | primary_device = CRT_Device; |
| 1151 | } |
| 1152 | } |
| 1153 | if (viafb_DVI_ON) { |
| 1154 | if (viaparinfo->tmds_setting_info->iga_path == IGA1) { |
| 1155 | DEBUG_MSG(KERN_INFO "DVI IGA Path:%d\n", |
| 1156 | viaparinfo-> |
| 1157 | tmds_setting_info->iga_path); |
| 1158 | primary_device = DVI_Device; |
| 1159 | } |
| 1160 | } |
| 1161 | if (viafb_LCD_ON) { |
| 1162 | if (viaparinfo->lvds_setting_info->iga_path == IGA1) { |
| 1163 | DEBUG_MSG(KERN_INFO "LCD IGA Path:%d\n", |
| 1164 | viaparinfo-> |
| 1165 | lvds_setting_info->iga_path); |
| 1166 | primary_device = LCD_Device; |
| 1167 | } |
| 1168 | } |
| 1169 | if (viafb_LCD2_ON) { |
| 1170 | if (viaparinfo->lvds_setting_info2->iga_path == IGA1) { |
| 1171 | DEBUG_MSG(KERN_INFO "LCD2 IGA Path:%d\n", |
| 1172 | viaparinfo-> |
| 1173 | lvds_setting_info2->iga_path); |
| 1174 | primary_device = LCD2_Device; |
| 1175 | } |
| 1176 | } |
| 1177 | } |
| 1178 | return primary_device; |
| 1179 | } |
| 1180 | |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1181 | static void apply_second_mode_setting(struct fb_var_screeninfo |
| 1182 | *sec_var) |
| 1183 | { |
| 1184 | u32 htotal, vtotal, long_refresh; |
| 1185 | |
| 1186 | htotal = sec_var->xres + sec_var->left_margin + |
| 1187 | sec_var->right_margin + sec_var->hsync_len; |
| 1188 | vtotal = sec_var->yres + sec_var->upper_margin + |
| 1189 | sec_var->lower_margin + sec_var->vsync_len; |
| 1190 | if ((sec_var->xres_virtual * (sec_var->bits_per_pixel >> 3)) & 0x1F) { |
| 1191 | /*Is 32 bytes alignment? */ |
| 1192 | /*32 pixel alignment */ |
| 1193 | sec_var->xres_virtual = (sec_var->xres_virtual + 31) & ~31; |
| 1194 | } |
| 1195 | |
| 1196 | htotal = sec_var->xres + sec_var->left_margin + |
| 1197 | sec_var->right_margin + sec_var->hsync_len; |
| 1198 | vtotal = sec_var->yres + sec_var->upper_margin + |
| 1199 | sec_var->lower_margin + sec_var->vsync_len; |
| 1200 | long_refresh = 1000000000UL / sec_var->pixclock * 1000; |
| 1201 | long_refresh /= (htotal * vtotal); |
| 1202 | |
| 1203 | viafb_second_xres = sec_var->xres; |
| 1204 | viafb_second_yres = sec_var->yres; |
| 1205 | viafb_second_virtual_xres = sec_var->xres_virtual; |
| 1206 | viafb_second_virtual_yres = sec_var->yres_virtual; |
| 1207 | viafb_bpp1 = sec_var->bits_per_pixel; |
| 1208 | viafb_refresh1 = viafb_get_refresh(sec_var->xres, sec_var->yres, |
| 1209 | long_refresh); |
| 1210 | } |
| 1211 | |
| 1212 | static int apply_device_setting(struct viafb_ioctl_setting setting_info, |
| 1213 | struct fb_info *info) |
| 1214 | { |
| 1215 | int need_set_mode = 0; |
| 1216 | DEBUG_MSG(KERN_INFO "apply_device_setting\n"); |
| 1217 | |
| 1218 | if (setting_info.device_flag) { |
| 1219 | need_set_mode = 1; |
| 1220 | check_available_device_to_enable(setting_info.device_status); |
| 1221 | } |
| 1222 | |
| 1223 | /* Unlock LCD's operation according to LCD flag |
| 1224 | and check if the setting value is valid. */ |
| 1225 | /* If the value is valid, apply the new setting value to the device. */ |
| 1226 | if (viafb_LCD_ON) { |
| 1227 | if (setting_info.lcd_operation_flag & OP_LCD_CENTERING) { |
| 1228 | need_set_mode = 1; |
| 1229 | if (setting_info.lcd_attributes.display_center) { |
| 1230 | /* Centering */ |
| 1231 | viaparinfo->lvds_setting_info->display_method = |
| 1232 | LCD_CENTERING; |
| 1233 | viafb_lcd_dsp_method = LCD_CENTERING; |
| 1234 | viaparinfo->lvds_setting_info2->display_method = |
| 1235 | viafb_lcd_dsp_method = LCD_CENTERING; |
| 1236 | } else { |
| 1237 | /* expandsion */ |
| 1238 | viaparinfo->lvds_setting_info->display_method = |
| 1239 | LCD_EXPANDSION; |
| 1240 | viafb_lcd_dsp_method = LCD_EXPANDSION; |
| 1241 | viaparinfo->lvds_setting_info2->display_method = |
| 1242 | LCD_EXPANDSION; |
| 1243 | viafb_lcd_dsp_method = LCD_EXPANDSION; |
| 1244 | } |
| 1245 | } |
| 1246 | |
| 1247 | if (setting_info.lcd_operation_flag & OP_LCD_MODE) { |
| 1248 | need_set_mode = 1; |
| 1249 | if (setting_info.lcd_attributes.lcd_mode == |
| 1250 | LCD_SPWG) { |
| 1251 | viaparinfo->lvds_setting_info->lcd_mode = |
| 1252 | viafb_lcd_mode = LCD_SPWG; |
| 1253 | } else { |
| 1254 | viaparinfo->lvds_setting_info->lcd_mode = |
| 1255 | viafb_lcd_mode = LCD_OPENLDI; |
| 1256 | } |
| 1257 | viaparinfo->lvds_setting_info2->lcd_mode = |
| 1258 | viaparinfo->lvds_setting_info->lcd_mode; |
| 1259 | } |
| 1260 | |
| 1261 | if (setting_info.lcd_operation_flag & OP_LCD_PANEL_ID) { |
| 1262 | need_set_mode = 1; |
| 1263 | if (setting_info.lcd_attributes.panel_id <= |
| 1264 | LCD_PANEL_ID_MAXIMUM) { |
| 1265 | viafb_lcd_panel_id = |
| 1266 | setting_info.lcd_attributes.panel_id; |
| 1267 | viafb_init_lcd_size(); |
| 1268 | } |
| 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | if (0 != (setting_info.samm_status & OP_SAMM)) { |
| 1273 | setting_info.samm_status = |
| 1274 | setting_info.samm_status & (~OP_SAMM); |
| 1275 | if (setting_info.samm_status == 0 |
| 1276 | || setting_info.samm_status == 1) { |
| 1277 | viafb_SAMM_ON = setting_info.samm_status; |
| 1278 | |
| 1279 | if (viafb_SAMM_ON) |
| 1280 | viafb_primary_dev = setting_info.primary_device; |
| 1281 | |
Florian Tobias Schandinat | 09cf118 | 2009-09-22 16:47:14 -0700 | [diff] [blame] | 1282 | viafb_set_primary_address(0); |
| 1283 | viafb_set_secondary_address(viafb_SAMM_ON ? viafb_second_offset : 0); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1284 | viafb_set_iga_path(); |
| 1285 | } |
| 1286 | need_set_mode = 1; |
| 1287 | } |
| 1288 | |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1289 | if (!need_set_mode) { |
| 1290 | ; |
| 1291 | } else { |
| 1292 | viafb_set_iga_path(); |
| 1293 | viafb_set_par(info); |
| 1294 | } |
| 1295 | return true; |
| 1296 | } |
| 1297 | |
| 1298 | static void retrieve_device_setting(struct viafb_ioctl_setting |
| 1299 | *setting_info) |
| 1300 | { |
| 1301 | |
| 1302 | /* get device status */ |
| 1303 | if (viafb_CRT_ON == 1) |
| 1304 | setting_info->device_status = CRT_Device; |
| 1305 | if (viafb_DVI_ON == 1) |
| 1306 | setting_info->device_status |= DVI_Device; |
| 1307 | if (viafb_LCD_ON == 1) |
| 1308 | setting_info->device_status |= LCD_Device; |
| 1309 | if (viafb_LCD2_ON == 1) |
| 1310 | setting_info->device_status |= LCD2_Device; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1311 | |
| 1312 | setting_info->samm_status = viafb_SAMM_ON; |
| 1313 | setting_info->primary_device = get_primary_device(); |
| 1314 | |
| 1315 | setting_info->first_dev_bpp = viafb_bpp; |
| 1316 | setting_info->second_dev_bpp = viafb_bpp1; |
| 1317 | |
| 1318 | setting_info->first_dev_refresh = viafb_refresh; |
| 1319 | setting_info->second_dev_refresh = viafb_refresh1; |
| 1320 | |
| 1321 | setting_info->first_dev_hor_res = viafb_hotplug_Xres; |
| 1322 | setting_info->first_dev_ver_res = viafb_hotplug_Yres; |
| 1323 | setting_info->second_dev_hor_res = viafb_second_xres; |
| 1324 | setting_info->second_dev_ver_res = viafb_second_yres; |
| 1325 | |
| 1326 | /* Get lcd attributes */ |
| 1327 | setting_info->lcd_attributes.display_center = viafb_lcd_dsp_method; |
| 1328 | setting_info->lcd_attributes.panel_id = viafb_lcd_panel_id; |
| 1329 | setting_info->lcd_attributes.lcd_mode = viafb_lcd_mode; |
| 1330 | } |
| 1331 | |
| 1332 | static void parse_active_dev(void) |
| 1333 | { |
| 1334 | viafb_CRT_ON = STATE_OFF; |
| 1335 | viafb_DVI_ON = STATE_OFF; |
| 1336 | viafb_LCD_ON = STATE_OFF; |
| 1337 | viafb_LCD2_ON = STATE_OFF; |
| 1338 | /* 1. Modify the active status of devices. */ |
| 1339 | /* 2. Keep the order of devices, so we can set corresponding |
| 1340 | IGA path to devices in SAMM case. */ |
| 1341 | /* Note: The previous of active_dev is primary device, |
| 1342 | and the following is secondary device. */ |
| 1343 | if (!strncmp(viafb_active_dev, "CRT+DVI", 7)) { |
| 1344 | /* CRT+DVI */ |
| 1345 | viafb_CRT_ON = STATE_ON; |
| 1346 | viafb_DVI_ON = STATE_ON; |
| 1347 | viafb_primary_dev = CRT_Device; |
| 1348 | } else if (!strncmp(viafb_active_dev, "DVI+CRT", 7)) { |
| 1349 | /* DVI+CRT */ |
| 1350 | viafb_CRT_ON = STATE_ON; |
| 1351 | viafb_DVI_ON = STATE_ON; |
| 1352 | viafb_primary_dev = DVI_Device; |
| 1353 | } else if (!strncmp(viafb_active_dev, "CRT+LCD", 7)) { |
| 1354 | /* CRT+LCD */ |
| 1355 | viafb_CRT_ON = STATE_ON; |
| 1356 | viafb_LCD_ON = STATE_ON; |
| 1357 | viafb_primary_dev = CRT_Device; |
| 1358 | } else if (!strncmp(viafb_active_dev, "LCD+CRT", 7)) { |
| 1359 | /* LCD+CRT */ |
| 1360 | viafb_CRT_ON = STATE_ON; |
| 1361 | viafb_LCD_ON = STATE_ON; |
| 1362 | viafb_primary_dev = LCD_Device; |
| 1363 | } else if (!strncmp(viafb_active_dev, "DVI+LCD", 7)) { |
| 1364 | /* DVI+LCD */ |
| 1365 | viafb_DVI_ON = STATE_ON; |
| 1366 | viafb_LCD_ON = STATE_ON; |
| 1367 | viafb_primary_dev = DVI_Device; |
| 1368 | } else if (!strncmp(viafb_active_dev, "LCD+DVI", 7)) { |
| 1369 | /* LCD+DVI */ |
| 1370 | viafb_DVI_ON = STATE_ON; |
| 1371 | viafb_LCD_ON = STATE_ON; |
| 1372 | viafb_primary_dev = LCD_Device; |
| 1373 | } else if (!strncmp(viafb_active_dev, "LCD+LCD2", 8)) { |
| 1374 | viafb_LCD_ON = STATE_ON; |
| 1375 | viafb_LCD2_ON = STATE_ON; |
| 1376 | viafb_primary_dev = LCD_Device; |
| 1377 | } else if (!strncmp(viafb_active_dev, "LCD2+LCD", 8)) { |
| 1378 | viafb_LCD_ON = STATE_ON; |
| 1379 | viafb_LCD2_ON = STATE_ON; |
| 1380 | viafb_primary_dev = LCD2_Device; |
| 1381 | } else if (!strncmp(viafb_active_dev, "CRT", 3)) { |
| 1382 | /* CRT only */ |
| 1383 | viafb_CRT_ON = STATE_ON; |
| 1384 | viafb_SAMM_ON = STATE_OFF; |
| 1385 | } else if (!strncmp(viafb_active_dev, "DVI", 3)) { |
| 1386 | /* DVI only */ |
| 1387 | viafb_DVI_ON = STATE_ON; |
| 1388 | viafb_SAMM_ON = STATE_OFF; |
| 1389 | } else if (!strncmp(viafb_active_dev, "LCD", 3)) { |
| 1390 | /* LCD only */ |
| 1391 | viafb_LCD_ON = STATE_ON; |
| 1392 | viafb_SAMM_ON = STATE_OFF; |
| 1393 | } else { |
| 1394 | viafb_CRT_ON = STATE_ON; |
| 1395 | viafb_SAMM_ON = STATE_OFF; |
| 1396 | } |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1397 | } |
| 1398 | |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1399 | static int parse_port(char *opt_str, int *output_interface) |
| 1400 | { |
| 1401 | if (!strncmp(opt_str, "DVP0", 4)) |
| 1402 | *output_interface = INTERFACE_DVP0; |
| 1403 | else if (!strncmp(opt_str, "DVP1", 4)) |
| 1404 | *output_interface = INTERFACE_DVP1; |
| 1405 | else if (!strncmp(opt_str, "DFP_HIGHLOW", 11)) |
| 1406 | *output_interface = INTERFACE_DFP; |
| 1407 | else if (!strncmp(opt_str, "DFP_HIGH", 8)) |
| 1408 | *output_interface = INTERFACE_DFP_HIGH; |
| 1409 | else if (!strncmp(opt_str, "DFP_LOW", 7)) |
| 1410 | *output_interface = INTERFACE_DFP_LOW; |
| 1411 | else |
| 1412 | *output_interface = INTERFACE_NONE; |
| 1413 | return 0; |
| 1414 | } |
| 1415 | |
| 1416 | static void parse_lcd_port(void) |
| 1417 | { |
| 1418 | parse_port(viafb_lcd_port, &viaparinfo->chip_info->lvds_chip_info. |
| 1419 | output_interface); |
| 1420 | /*Initialize to avoid unexpected behavior */ |
| 1421 | viaparinfo->chip_info->lvds_chip_info2.output_interface = |
| 1422 | INTERFACE_NONE; |
| 1423 | |
| 1424 | DEBUG_MSG(KERN_INFO "parse_lcd_port: viafb_lcd_port:%s,interface:%d\n", |
| 1425 | viafb_lcd_port, viaparinfo->chip_info->lvds_chip_info. |
| 1426 | output_interface); |
| 1427 | } |
| 1428 | |
| 1429 | static void parse_dvi_port(void) |
| 1430 | { |
| 1431 | parse_port(viafb_dvi_port, &viaparinfo->chip_info->tmds_chip_info. |
| 1432 | output_interface); |
| 1433 | |
| 1434 | DEBUG_MSG(KERN_INFO "parse_dvi_port: viafb_dvi_port:%s,interface:%d\n", |
| 1435 | viafb_dvi_port, viaparinfo->chip_info->tmds_chip_info. |
| 1436 | output_interface); |
| 1437 | } |
| 1438 | |
| 1439 | /* |
| 1440 | * The proc filesystem read/write function, a simple proc implement to |
| 1441 | * get/set the value of DPA DVP0, DVP0DataDriving, DVP0ClockDriving, DVP1, |
| 1442 | * DVP1Driving, DFPHigh, DFPLow CR96, SR2A[5], SR1B[1], SR2A[4], SR1E[2], |
| 1443 | * CR9B, SR65, CR97, CR99 |
| 1444 | */ |
Alexey Dobriyan | afbd3c1 | 2009-09-22 16:47:27 -0700 | [diff] [blame] | 1445 | static int viafb_dvp0_proc_show(struct seq_file *m, void *v) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1446 | { |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1447 | u8 dvp0_data_dri = 0, dvp0_clk_dri = 0, dvp0 = 0; |
| 1448 | dvp0_data_dri = |
| 1449 | (viafb_read_reg(VIASR, SR2A) & BIT5) >> 4 | |
| 1450 | (viafb_read_reg(VIASR, SR1B) & BIT1) >> 1; |
| 1451 | dvp0_clk_dri = |
| 1452 | (viafb_read_reg(VIASR, SR2A) & BIT4) >> 3 | |
| 1453 | (viafb_read_reg(VIASR, SR1E) & BIT2) >> 2; |
| 1454 | dvp0 = viafb_read_reg(VIACR, CR96) & 0x0f; |
Alexey Dobriyan | afbd3c1 | 2009-09-22 16:47:27 -0700 | [diff] [blame] | 1455 | seq_printf(m, "%x %x %x\n", dvp0, dvp0_data_dri, dvp0_clk_dri); |
| 1456 | return 0; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1457 | } |
Alexey Dobriyan | afbd3c1 | 2009-09-22 16:47:27 -0700 | [diff] [blame] | 1458 | |
| 1459 | static int viafb_dvp0_proc_open(struct inode *inode, struct file *file) |
| 1460 | { |
| 1461 | return single_open(file, viafb_dvp0_proc_show, NULL); |
| 1462 | } |
| 1463 | |
| 1464 | static ssize_t viafb_dvp0_proc_write(struct file *file, |
| 1465 | const char __user *buffer, size_t count, loff_t *pos) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1466 | { |
| 1467 | char buf[20], *value, *pbuf; |
| 1468 | u8 reg_val = 0; |
| 1469 | unsigned long length, i; |
| 1470 | if (count < 1) |
| 1471 | return -EINVAL; |
| 1472 | length = count > 20 ? 20 : count; |
| 1473 | if (copy_from_user(&buf[0], buffer, length)) |
| 1474 | return -EFAULT; |
| 1475 | buf[length - 1] = '\0'; /*Ensure end string */ |
| 1476 | pbuf = &buf[0]; |
| 1477 | for (i = 0; i < 3; i++) { |
| 1478 | value = strsep(&pbuf, " "); |
| 1479 | if (value != NULL) { |
| 1480 | strict_strtoul(value, 0, (unsigned long *)®_val); |
| 1481 | DEBUG_MSG(KERN_INFO "DVP0:reg_val[%l]=:%x\n", i, |
| 1482 | reg_val); |
| 1483 | switch (i) { |
| 1484 | case 0: |
| 1485 | viafb_write_reg_mask(CR96, VIACR, |
| 1486 | reg_val, 0x0f); |
| 1487 | break; |
| 1488 | case 1: |
| 1489 | viafb_write_reg_mask(SR2A, VIASR, |
| 1490 | reg_val << 4, BIT5); |
| 1491 | viafb_write_reg_mask(SR1B, VIASR, |
| 1492 | reg_val << 1, BIT1); |
| 1493 | break; |
| 1494 | case 2: |
| 1495 | viafb_write_reg_mask(SR2A, VIASR, |
| 1496 | reg_val << 3, BIT4); |
| 1497 | viafb_write_reg_mask(SR1E, VIASR, |
| 1498 | reg_val << 2, BIT2); |
| 1499 | break; |
| 1500 | default: |
| 1501 | break; |
| 1502 | } |
| 1503 | } else { |
| 1504 | break; |
| 1505 | } |
| 1506 | } |
| 1507 | return count; |
| 1508 | } |
Alexey Dobriyan | afbd3c1 | 2009-09-22 16:47:27 -0700 | [diff] [blame] | 1509 | |
| 1510 | static const struct file_operations viafb_dvp0_proc_fops = { |
| 1511 | .owner = THIS_MODULE, |
| 1512 | .open = viafb_dvp0_proc_open, |
| 1513 | .read = seq_read, |
| 1514 | .llseek = seq_lseek, |
| 1515 | .release = single_release, |
| 1516 | .write = viafb_dvp0_proc_write, |
| 1517 | }; |
| 1518 | |
| 1519 | static int viafb_dvp1_proc_show(struct seq_file *m, void *v) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1520 | { |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1521 | u8 dvp1 = 0, dvp1_data_dri = 0, dvp1_clk_dri = 0; |
| 1522 | dvp1 = viafb_read_reg(VIACR, CR9B) & 0x0f; |
| 1523 | dvp1_data_dri = (viafb_read_reg(VIASR, SR65) & 0x0c) >> 2; |
| 1524 | dvp1_clk_dri = viafb_read_reg(VIASR, SR65) & 0x03; |
Alexey Dobriyan | afbd3c1 | 2009-09-22 16:47:27 -0700 | [diff] [blame] | 1525 | seq_printf(m, "%x %x %x\n", dvp1, dvp1_data_dri, dvp1_clk_dri); |
| 1526 | return 0; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1527 | } |
Alexey Dobriyan | afbd3c1 | 2009-09-22 16:47:27 -0700 | [diff] [blame] | 1528 | |
| 1529 | static int viafb_dvp1_proc_open(struct inode *inode, struct file *file) |
| 1530 | { |
| 1531 | return single_open(file, viafb_dvp1_proc_show, NULL); |
| 1532 | } |
| 1533 | |
| 1534 | static ssize_t viafb_dvp1_proc_write(struct file *file, |
| 1535 | const char __user *buffer, size_t count, loff_t *pos) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1536 | { |
| 1537 | char buf[20], *value, *pbuf; |
| 1538 | u8 reg_val = 0; |
| 1539 | unsigned long length, i; |
| 1540 | if (count < 1) |
| 1541 | return -EINVAL; |
| 1542 | length = count > 20 ? 20 : count; |
| 1543 | if (copy_from_user(&buf[0], buffer, length)) |
| 1544 | return -EFAULT; |
| 1545 | buf[length - 1] = '\0'; /*Ensure end string */ |
| 1546 | pbuf = &buf[0]; |
| 1547 | for (i = 0; i < 3; i++) { |
| 1548 | value = strsep(&pbuf, " "); |
| 1549 | if (value != NULL) { |
| 1550 | strict_strtoul(value, 0, (unsigned long *)®_val); |
| 1551 | switch (i) { |
| 1552 | case 0: |
| 1553 | viafb_write_reg_mask(CR9B, VIACR, |
| 1554 | reg_val, 0x0f); |
| 1555 | break; |
| 1556 | case 1: |
| 1557 | viafb_write_reg_mask(SR65, VIASR, |
| 1558 | reg_val << 2, 0x0c); |
| 1559 | break; |
| 1560 | case 2: |
| 1561 | viafb_write_reg_mask(SR65, VIASR, |
| 1562 | reg_val, 0x03); |
| 1563 | break; |
| 1564 | default: |
| 1565 | break; |
| 1566 | } |
| 1567 | } else { |
| 1568 | break; |
| 1569 | } |
| 1570 | } |
| 1571 | return count; |
| 1572 | } |
| 1573 | |
Alexey Dobriyan | afbd3c1 | 2009-09-22 16:47:27 -0700 | [diff] [blame] | 1574 | static const struct file_operations viafb_dvp1_proc_fops = { |
| 1575 | .owner = THIS_MODULE, |
| 1576 | .open = viafb_dvp1_proc_open, |
| 1577 | .read = seq_read, |
| 1578 | .llseek = seq_lseek, |
| 1579 | .release = single_release, |
| 1580 | .write = viafb_dvp1_proc_write, |
| 1581 | }; |
| 1582 | |
| 1583 | static int viafb_dfph_proc_show(struct seq_file *m, void *v) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1584 | { |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1585 | u8 dfp_high = 0; |
| 1586 | dfp_high = viafb_read_reg(VIACR, CR97) & 0x0f; |
Alexey Dobriyan | afbd3c1 | 2009-09-22 16:47:27 -0700 | [diff] [blame] | 1587 | seq_printf(m, "%x\n", dfp_high); |
| 1588 | return 0; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1589 | } |
Alexey Dobriyan | afbd3c1 | 2009-09-22 16:47:27 -0700 | [diff] [blame] | 1590 | |
| 1591 | static int viafb_dfph_proc_open(struct inode *inode, struct file *file) |
| 1592 | { |
| 1593 | return single_open(file, viafb_dfph_proc_show, NULL); |
| 1594 | } |
| 1595 | |
| 1596 | static ssize_t viafb_dfph_proc_write(struct file *file, |
| 1597 | const char __user *buffer, size_t count, loff_t *pos) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1598 | { |
| 1599 | char buf[20]; |
| 1600 | u8 reg_val = 0; |
| 1601 | unsigned long length; |
| 1602 | if (count < 1) |
| 1603 | return -EINVAL; |
| 1604 | length = count > 20 ? 20 : count; |
| 1605 | if (copy_from_user(&buf[0], buffer, length)) |
| 1606 | return -EFAULT; |
| 1607 | buf[length - 1] = '\0'; /*Ensure end string */ |
| 1608 | strict_strtoul(&buf[0], 0, (unsigned long *)®_val); |
| 1609 | viafb_write_reg_mask(CR97, VIACR, reg_val, 0x0f); |
| 1610 | return count; |
| 1611 | } |
Alexey Dobriyan | afbd3c1 | 2009-09-22 16:47:27 -0700 | [diff] [blame] | 1612 | |
| 1613 | static const struct file_operations viafb_dfph_proc_fops = { |
| 1614 | .owner = THIS_MODULE, |
| 1615 | .open = viafb_dfph_proc_open, |
| 1616 | .read = seq_read, |
| 1617 | .llseek = seq_lseek, |
| 1618 | .release = single_release, |
| 1619 | .write = viafb_dfph_proc_write, |
| 1620 | }; |
| 1621 | |
| 1622 | static int viafb_dfpl_proc_show(struct seq_file *m, void *v) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1623 | { |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1624 | u8 dfp_low = 0; |
| 1625 | dfp_low = viafb_read_reg(VIACR, CR99) & 0x0f; |
Alexey Dobriyan | afbd3c1 | 2009-09-22 16:47:27 -0700 | [diff] [blame] | 1626 | seq_printf(m, "%x\n", dfp_low); |
| 1627 | return 0; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1628 | } |
Alexey Dobriyan | afbd3c1 | 2009-09-22 16:47:27 -0700 | [diff] [blame] | 1629 | |
| 1630 | static int viafb_dfpl_proc_open(struct inode *inode, struct file *file) |
| 1631 | { |
| 1632 | return single_open(file, viafb_dfpl_proc_show, NULL); |
| 1633 | } |
| 1634 | |
| 1635 | static ssize_t viafb_dfpl_proc_write(struct file *file, |
| 1636 | const char __user *buffer, size_t count, loff_t *pos) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1637 | { |
| 1638 | char buf[20]; |
| 1639 | u8 reg_val = 0; |
| 1640 | unsigned long length; |
| 1641 | if (count < 1) |
| 1642 | return -EINVAL; |
| 1643 | length = count > 20 ? 20 : count; |
| 1644 | if (copy_from_user(&buf[0], buffer, length)) |
| 1645 | return -EFAULT; |
| 1646 | buf[length - 1] = '\0'; /*Ensure end string */ |
| 1647 | strict_strtoul(&buf[0], 0, (unsigned long *)®_val); |
| 1648 | viafb_write_reg_mask(CR99, VIACR, reg_val, 0x0f); |
| 1649 | return count; |
| 1650 | } |
Alexey Dobriyan | afbd3c1 | 2009-09-22 16:47:27 -0700 | [diff] [blame] | 1651 | |
| 1652 | static const struct file_operations viafb_dfpl_proc_fops = { |
| 1653 | .owner = THIS_MODULE, |
| 1654 | .open = viafb_dfpl_proc_open, |
| 1655 | .read = seq_read, |
| 1656 | .llseek = seq_lseek, |
| 1657 | .release = single_release, |
| 1658 | .write = viafb_dfpl_proc_write, |
| 1659 | }; |
| 1660 | |
| 1661 | static int viafb_vt1636_proc_show(struct seq_file *m, void *v) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1662 | { |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1663 | u8 vt1636_08 = 0, vt1636_09 = 0; |
| 1664 | switch (viaparinfo->chip_info->lvds_chip_info.lvds_chip_name) { |
| 1665 | case VT1636_LVDS: |
| 1666 | vt1636_08 = |
| 1667 | viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info, |
| 1668 | &viaparinfo->chip_info->lvds_chip_info, 0x08) & 0x0f; |
| 1669 | vt1636_09 = |
| 1670 | viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info, |
| 1671 | &viaparinfo->chip_info->lvds_chip_info, 0x09) & 0x1f; |
Alexey Dobriyan | afbd3c1 | 2009-09-22 16:47:27 -0700 | [diff] [blame] | 1672 | seq_printf(m, "%x %x\n", vt1636_08, vt1636_09); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1673 | break; |
| 1674 | default: |
| 1675 | break; |
| 1676 | } |
| 1677 | switch (viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name) { |
| 1678 | case VT1636_LVDS: |
| 1679 | vt1636_08 = |
| 1680 | viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info2, |
| 1681 | &viaparinfo->chip_info->lvds_chip_info2, 0x08) & 0x0f; |
| 1682 | vt1636_09 = |
| 1683 | viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info2, |
| 1684 | &viaparinfo->chip_info->lvds_chip_info2, 0x09) & 0x1f; |
Alexey Dobriyan | afbd3c1 | 2009-09-22 16:47:27 -0700 | [diff] [blame] | 1685 | seq_printf(m, " %x %x\n", vt1636_08, vt1636_09); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1686 | break; |
| 1687 | default: |
| 1688 | break; |
| 1689 | } |
Alexey Dobriyan | afbd3c1 | 2009-09-22 16:47:27 -0700 | [diff] [blame] | 1690 | return 0; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1691 | } |
Alexey Dobriyan | afbd3c1 | 2009-09-22 16:47:27 -0700 | [diff] [blame] | 1692 | |
| 1693 | static int viafb_vt1636_proc_open(struct inode *inode, struct file *file) |
| 1694 | { |
| 1695 | return single_open(file, viafb_vt1636_proc_show, NULL); |
| 1696 | } |
| 1697 | |
| 1698 | static ssize_t viafb_vt1636_proc_write(struct file *file, |
| 1699 | const char __user *buffer, size_t count, loff_t *pos) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1700 | { |
| 1701 | char buf[30], *value, *pbuf; |
| 1702 | struct IODATA reg_val; |
| 1703 | unsigned long length, i; |
| 1704 | if (count < 1) |
| 1705 | return -EINVAL; |
| 1706 | length = count > 30 ? 30 : count; |
| 1707 | if (copy_from_user(&buf[0], buffer, length)) |
| 1708 | return -EFAULT; |
| 1709 | buf[length - 1] = '\0'; /*Ensure end string */ |
| 1710 | pbuf = &buf[0]; |
| 1711 | switch (viaparinfo->chip_info->lvds_chip_info.lvds_chip_name) { |
| 1712 | case VT1636_LVDS: |
| 1713 | for (i = 0; i < 2; i++) { |
| 1714 | value = strsep(&pbuf, " "); |
| 1715 | if (value != NULL) { |
| 1716 | strict_strtoul(value, 0, |
| 1717 | (unsigned long *)®_val.Data); |
| 1718 | switch (i) { |
| 1719 | case 0: |
| 1720 | reg_val.Index = 0x08; |
| 1721 | reg_val.Mask = 0x0f; |
| 1722 | viafb_gpio_i2c_write_mask_lvds |
| 1723 | (viaparinfo->lvds_setting_info, |
| 1724 | &viaparinfo-> |
| 1725 | chip_info->lvds_chip_info, |
| 1726 | reg_val); |
| 1727 | break; |
| 1728 | case 1: |
| 1729 | reg_val.Index = 0x09; |
| 1730 | reg_val.Mask = 0x1f; |
| 1731 | viafb_gpio_i2c_write_mask_lvds |
| 1732 | (viaparinfo->lvds_setting_info, |
| 1733 | &viaparinfo-> |
| 1734 | chip_info->lvds_chip_info, |
| 1735 | reg_val); |
| 1736 | break; |
| 1737 | default: |
| 1738 | break; |
| 1739 | } |
| 1740 | } else { |
| 1741 | break; |
| 1742 | } |
| 1743 | } |
| 1744 | break; |
| 1745 | default: |
| 1746 | break; |
| 1747 | } |
| 1748 | switch (viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name) { |
| 1749 | case VT1636_LVDS: |
| 1750 | for (i = 0; i < 2; i++) { |
| 1751 | value = strsep(&pbuf, " "); |
| 1752 | if (value != NULL) { |
| 1753 | strict_strtoul(value, 0, |
| 1754 | (unsigned long *)®_val.Data); |
| 1755 | switch (i) { |
| 1756 | case 0: |
| 1757 | reg_val.Index = 0x08; |
| 1758 | reg_val.Mask = 0x0f; |
| 1759 | viafb_gpio_i2c_write_mask_lvds |
| 1760 | (viaparinfo->lvds_setting_info2, |
| 1761 | &viaparinfo-> |
| 1762 | chip_info->lvds_chip_info2, |
| 1763 | reg_val); |
| 1764 | break; |
| 1765 | case 1: |
| 1766 | reg_val.Index = 0x09; |
| 1767 | reg_val.Mask = 0x1f; |
| 1768 | viafb_gpio_i2c_write_mask_lvds |
| 1769 | (viaparinfo->lvds_setting_info2, |
| 1770 | &viaparinfo-> |
| 1771 | chip_info->lvds_chip_info2, |
| 1772 | reg_val); |
| 1773 | break; |
| 1774 | default: |
| 1775 | break; |
| 1776 | } |
| 1777 | } else { |
| 1778 | break; |
| 1779 | } |
| 1780 | } |
| 1781 | break; |
| 1782 | default: |
| 1783 | break; |
| 1784 | } |
| 1785 | return count; |
| 1786 | } |
| 1787 | |
Alexey Dobriyan | afbd3c1 | 2009-09-22 16:47:27 -0700 | [diff] [blame] | 1788 | static const struct file_operations viafb_vt1636_proc_fops = { |
| 1789 | .owner = THIS_MODULE, |
| 1790 | .open = viafb_vt1636_proc_open, |
| 1791 | .read = seq_read, |
| 1792 | .llseek = seq_lseek, |
| 1793 | .release = single_release, |
| 1794 | .write = viafb_vt1636_proc_write, |
| 1795 | }; |
| 1796 | |
Bruno Prémont | c267fd7 | 2008-11-19 15:36:23 -0800 | [diff] [blame] | 1797 | static void viafb_init_proc(struct proc_dir_entry **viafb_entry) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1798 | { |
Bruno Prémont | c267fd7 | 2008-11-19 15:36:23 -0800 | [diff] [blame] | 1799 | *viafb_entry = proc_mkdir("viafb", NULL); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1800 | if (viafb_entry) { |
Alexey Dobriyan | afbd3c1 | 2009-09-22 16:47:27 -0700 | [diff] [blame] | 1801 | proc_create("dvp0", 0, *viafb_entry, &viafb_dvp0_proc_fops); |
| 1802 | proc_create("dvp1", 0, *viafb_entry, &viafb_dvp1_proc_fops); |
| 1803 | proc_create("dfph", 0, *viafb_entry, &viafb_dfph_proc_fops); |
| 1804 | proc_create("dfpl", 0, *viafb_entry, &viafb_dfpl_proc_fops); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1805 | if (VT1636_LVDS == viaparinfo->chip_info->lvds_chip_info. |
| 1806 | lvds_chip_name || VT1636_LVDS == |
| 1807 | viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name) { |
Alexey Dobriyan | afbd3c1 | 2009-09-22 16:47:27 -0700 | [diff] [blame] | 1808 | proc_create("vt1636", 0, *viafb_entry, &viafb_vt1636_proc_fops); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1809 | } |
| 1810 | |
| 1811 | } |
| 1812 | } |
| 1813 | static void viafb_remove_proc(struct proc_dir_entry *viafb_entry) |
| 1814 | { |
| 1815 | /* no problem if it was not registered */ |
| 1816 | remove_proc_entry("dvp0", viafb_entry);/* parent dir */ |
| 1817 | remove_proc_entry("dvp1", viafb_entry); |
| 1818 | remove_proc_entry("dfph", viafb_entry); |
| 1819 | remove_proc_entry("dfpl", viafb_entry); |
| 1820 | remove_proc_entry("vt1636", viafb_entry); |
| 1821 | remove_proc_entry("vt1625", viafb_entry); |
Bruno Prémont | c267fd7 | 2008-11-19 15:36:23 -0800 | [diff] [blame] | 1822 | remove_proc_entry("viafb", NULL); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1823 | } |
| 1824 | |
Florian Tobias Schandinat | 5ff32f6 | 2009-09-22 16:47:34 -0700 | [diff] [blame] | 1825 | static void parse_mode(const char *str, u32 *xres, u32 *yres) |
| 1826 | { |
| 1827 | char *ptr; |
| 1828 | |
| 1829 | *xres = simple_strtoul(str, &ptr, 10); |
| 1830 | if (ptr[0] != 'x') |
| 1831 | goto out_default; |
| 1832 | |
| 1833 | *yres = simple_strtoul(&ptr[1], &ptr, 10); |
| 1834 | if (ptr[0]) |
| 1835 | goto out_default; |
| 1836 | |
| 1837 | return; |
| 1838 | |
| 1839 | out_default: |
| 1840 | printk(KERN_WARNING "viafb received invalid mode string: %s\n", str); |
| 1841 | *xres = 640; |
| 1842 | *yres = 480; |
| 1843 | } |
| 1844 | |
Harald Welte | 2d280f7 | 2009-09-22 16:47:37 -0700 | [diff] [blame] | 1845 | static int __devinit via_pci_probe(struct pci_dev *pdev, |
| 1846 | const struct pci_device_id *ent) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1847 | { |
Florian Tobias Schandinat | 5ff32f6 | 2009-09-22 16:47:34 -0700 | [diff] [blame] | 1848 | u32 default_xres, default_yres; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1849 | int vmode_index; |
Florian Tobias Schandinat | c4df548 | 2009-09-22 16:47:24 -0700 | [diff] [blame] | 1850 | u32 viafb_par_length; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1851 | |
| 1852 | DEBUG_MSG(KERN_INFO "VIAFB PCI Probe!!\n"); |
| 1853 | |
| 1854 | viafb_par_length = ALIGN(sizeof(struct viafb_par), BITS_PER_LONG/8); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1855 | |
| 1856 | /* Allocate fb_info and ***_par here, also including some other needed |
| 1857 | * variables |
| 1858 | */ |
Florian Tobias Schandinat | c4df548 | 2009-09-22 16:47:24 -0700 | [diff] [blame] | 1859 | viafbinfo = framebuffer_alloc(viafb_par_length + |
Harald Welte | db8df7b | 2009-09-22 16:47:38 -0700 | [diff] [blame] | 1860 | ALIGN(sizeof(struct viafb_shared), BITS_PER_LONG/8), |
| 1861 | &pdev->dev); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1862 | if (!viafbinfo) { |
| 1863 | printk(KERN_ERR"Could not allocate memory for viafb_info.\n"); |
| 1864 | return -ENODEV; |
| 1865 | } |
| 1866 | |
| 1867 | viaparinfo = (struct viafb_par *)viafbinfo->par; |
Florian Tobias Schandinat | c4df548 | 2009-09-22 16:47:24 -0700 | [diff] [blame] | 1868 | viaparinfo->shared = viafbinfo->par + viafb_par_length; |
Florian Tobias Schandinat | c3e2567 | 2009-09-22 16:47:26 -0700 | [diff] [blame] | 1869 | viaparinfo->vram_addr = 0; |
Florian Tobias Schandinat | c4df548 | 2009-09-22 16:47:24 -0700 | [diff] [blame] | 1870 | viaparinfo->tmds_setting_info = &viaparinfo->shared->tmds_setting_info; |
| 1871 | viaparinfo->lvds_setting_info = &viaparinfo->shared->lvds_setting_info; |
| 1872 | viaparinfo->lvds_setting_info2 = |
| 1873 | &viaparinfo->shared->lvds_setting_info2; |
| 1874 | viaparinfo->crt_setting_info = &viaparinfo->shared->crt_setting_info; |
| 1875 | viaparinfo->chip_info = &viaparinfo->shared->chip_info; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1876 | |
| 1877 | if (viafb_dual_fb) |
| 1878 | viafb_SAMM_ON = 1; |
| 1879 | parse_active_dev(); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1880 | parse_lcd_port(); |
| 1881 | parse_dvi_port(); |
| 1882 | |
| 1883 | /* for dual-fb must viafb_SAMM_ON=1 and viafb_dual_fb=1 */ |
| 1884 | if (!viafb_SAMM_ON) |
| 1885 | viafb_dual_fb = 0; |
| 1886 | |
| 1887 | /* Set up I2C bus stuff */ |
| 1888 | viafb_create_i2c_bus(viaparinfo); |
| 1889 | |
Harald Welte | 2d280f7 | 2009-09-22 16:47:37 -0700 | [diff] [blame] | 1890 | viafb_init_chip_info(pdev, ent); |
| 1891 | viaparinfo->fbmem = pci_resource_start(pdev, 0); |
| 1892 | viaparinfo->memsize = viafb_get_fb_size_from_pci(); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1893 | viaparinfo->fbmem_free = viaparinfo->memsize; |
| 1894 | viaparinfo->fbmem_used = 0; |
Florian Tobias Schandinat | db88e38 | 2009-09-22 16:47:20 -0700 | [diff] [blame] | 1895 | viafbinfo->screen_base = ioremap_nocache(viaparinfo->fbmem, |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1896 | viaparinfo->memsize); |
Florian Tobias Schandinat | db88e38 | 2009-09-22 16:47:20 -0700 | [diff] [blame] | 1897 | if (!viafbinfo->screen_base) { |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1898 | printk(KERN_INFO "ioremap failed\n"); |
Florian Tobias Schandinat | bc6932b | 2009-09-22 16:47:15 -0700 | [diff] [blame] | 1899 | return -ENOMEM; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1900 | } |
| 1901 | |
Harald Welte | 2d280f7 | 2009-09-22 16:47:37 -0700 | [diff] [blame] | 1902 | viafbinfo->fix.mmio_start = pci_resource_start(pdev, 1); |
| 1903 | viafbinfo->fix.mmio_len = pci_resource_len(pdev, 1); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1904 | viafbinfo->node = 0; |
| 1905 | viafbinfo->fbops = &viafb_ops; |
| 1906 | viafbinfo->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN; |
| 1907 | |
| 1908 | viafbinfo->pseudo_palette = pseudo_pal; |
Florian Tobias Schandinat | 31de59d | 2009-09-22 16:47:31 -0700 | [diff] [blame] | 1909 | if (viafb_accel && !viafb_init_engine(viafbinfo)) { |
| 1910 | viafbinfo->flags |= FBINFO_HWACCEL_COPYAREA | |
| 1911 | FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_IMAGEBLIT; |
| 1912 | default_var.accel_flags = FB_ACCELF_TEXT; |
| 1913 | } else { |
| 1914 | viafbinfo->flags |= FBINFO_HWACCEL_DISABLED; |
| 1915 | default_var.accel_flags = 0; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1916 | } |
| 1917 | |
| 1918 | if (viafb_second_size && (viafb_second_size < 8)) { |
| 1919 | viafb_second_offset = viaparinfo->fbmem_free - |
| 1920 | viafb_second_size * 1024 * 1024; |
| 1921 | } else { |
| 1922 | viafb_second_size = 8; |
| 1923 | viafb_second_offset = viaparinfo->fbmem_free - |
| 1924 | viafb_second_size * 1024 * 1024; |
| 1925 | } |
| 1926 | |
Florian Tobias Schandinat | 5ff32f6 | 2009-09-22 16:47:34 -0700 | [diff] [blame] | 1927 | parse_mode(viafb_mode, &default_xres, &default_yres); |
Florian Tobias Schandinat | 5215944 | 2009-08-06 15:07:34 -0700 | [diff] [blame] | 1928 | vmode_index = viafb_get_mode_index(default_xres, default_yres); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1929 | DEBUG_MSG(KERN_INFO "0->index=%d\n", vmode_index); |
| 1930 | |
| 1931 | if (viafb_SAMM_ON == 1) { |
Florian Tobias Schandinat | 5ff32f6 | 2009-09-22 16:47:34 -0700 | [diff] [blame] | 1932 | parse_mode(viafb_mode1, &viafb_second_xres, |
| 1933 | &viafb_second_yres); |
| 1934 | |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1935 | if (0 == viafb_second_virtual_xres) { |
| 1936 | switch (viafb_second_xres) { |
| 1937 | case 1400: |
| 1938 | viafb_second_virtual_xres = 1408; |
| 1939 | break; |
| 1940 | default: |
| 1941 | viafb_second_virtual_xres = viafb_second_xres; |
| 1942 | break; |
| 1943 | } |
| 1944 | } |
| 1945 | if (0 == viafb_second_virtual_yres) |
| 1946 | viafb_second_virtual_yres = viafb_second_yres; |
| 1947 | } |
| 1948 | |
| 1949 | switch (viafb_bpp) { |
| 1950 | case 0 ... 8: |
| 1951 | viafb_bpp = 8; |
| 1952 | break; |
| 1953 | case 9 ... 16: |
| 1954 | viafb_bpp = 16; |
| 1955 | break; |
| 1956 | case 17 ... 32: |
| 1957 | viafb_bpp = 32; |
| 1958 | break; |
| 1959 | default: |
| 1960 | viafb_bpp = 8; |
| 1961 | } |
| 1962 | default_var.xres = default_xres; |
| 1963 | default_var.yres = default_yres; |
| 1964 | switch (default_xres) { |
| 1965 | case 1400: |
| 1966 | default_var.xres_virtual = 1408; |
| 1967 | break; |
| 1968 | default: |
| 1969 | default_var.xres_virtual = default_xres; |
| 1970 | break; |
| 1971 | } |
| 1972 | default_var.yres_virtual = default_yres; |
| 1973 | default_var.bits_per_pixel = viafb_bpp; |
| 1974 | if (default_var.bits_per_pixel == 15) |
| 1975 | default_var.bits_per_pixel = 16; |
| 1976 | default_var.pixclock = |
| 1977 | viafb_get_pixclock(default_xres, default_yres, viafb_refresh); |
| 1978 | default_var.left_margin = (default_xres >> 3) & 0xf8; |
| 1979 | default_var.right_margin = 32; |
| 1980 | default_var.upper_margin = 16; |
| 1981 | default_var.lower_margin = 4; |
| 1982 | default_var.hsync_len = default_var.left_margin; |
| 1983 | default_var.vsync_len = 4; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1984 | |
| 1985 | if (viafb_dual_fb) { |
Harald Welte | db8df7b | 2009-09-22 16:47:38 -0700 | [diff] [blame] | 1986 | viafbinfo1 = framebuffer_alloc(viafb_par_length, &pdev->dev); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1987 | if (!viafbinfo1) { |
| 1988 | printk(KERN_ERR |
| 1989 | "allocate the second framebuffer struct error\n"); |
| 1990 | framebuffer_release(viafbinfo); |
| 1991 | return -ENOMEM; |
| 1992 | } |
| 1993 | viaparinfo1 = viafbinfo1->par; |
| 1994 | memcpy(viaparinfo1, viaparinfo, viafb_par_length); |
Florian Tobias Schandinat | c3e2567 | 2009-09-22 16:47:26 -0700 | [diff] [blame] | 1995 | viaparinfo1->vram_addr = viafb_second_offset; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1996 | viaparinfo1->memsize = viaparinfo->memsize - |
| 1997 | viafb_second_offset; |
| 1998 | viaparinfo->memsize = viafb_second_offset; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1999 | viaparinfo1->fbmem = viaparinfo->fbmem + viafb_second_offset; |
| 2000 | |
| 2001 | viaparinfo1->fbmem_used = viaparinfo->fbmem_used; |
| 2002 | viaparinfo1->fbmem_free = viaparinfo1->memsize - |
| 2003 | viaparinfo1->fbmem_used; |
| 2004 | viaparinfo->fbmem_free = viaparinfo->memsize; |
| 2005 | viaparinfo->fbmem_used = 0; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2006 | |
Florian Tobias Schandinat | 09cf118 | 2009-09-22 16:47:14 -0700 | [diff] [blame] | 2007 | viaparinfo->iga_path = IGA1; |
| 2008 | viaparinfo1->iga_path = IGA2; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2009 | memcpy(viafbinfo1, viafbinfo, sizeof(struct fb_info)); |
Florian Tobias Schandinat | c4df548 | 2009-09-22 16:47:24 -0700 | [diff] [blame] | 2010 | viafbinfo1->par = viaparinfo1; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2011 | viafbinfo1->screen_base = viafbinfo->screen_base + |
| 2012 | viafb_second_offset; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2013 | |
| 2014 | default_var.xres = viafb_second_xres; |
| 2015 | default_var.yres = viafb_second_yres; |
| 2016 | default_var.xres_virtual = viafb_second_virtual_xres; |
| 2017 | default_var.yres_virtual = viafb_second_virtual_yres; |
| 2018 | if (viafb_bpp1 != viafb_bpp) |
| 2019 | viafb_bpp1 = viafb_bpp; |
| 2020 | default_var.bits_per_pixel = viafb_bpp1; |
| 2021 | default_var.pixclock = |
| 2022 | viafb_get_pixclock(viafb_second_xres, viafb_second_yres, |
| 2023 | viafb_refresh); |
| 2024 | default_var.left_margin = (viafb_second_xres >> 3) & 0xf8; |
| 2025 | default_var.right_margin = 32; |
| 2026 | default_var.upper_margin = 16; |
| 2027 | default_var.lower_margin = 4; |
| 2028 | default_var.hsync_len = default_var.left_margin; |
| 2029 | default_var.vsync_len = 4; |
| 2030 | |
| 2031 | viafb_setup_fixinfo(&viafbinfo1->fix, viaparinfo1); |
| 2032 | viafb_check_var(&default_var, viafbinfo1); |
| 2033 | viafbinfo1->var = default_var; |
Florian Tobias Schandinat | 81228a3 | 2009-09-22 16:47:13 -0700 | [diff] [blame] | 2034 | viafb_update_fix(viafbinfo1); |
Florian Tobias Schandinat | c3e2567 | 2009-09-22 16:47:26 -0700 | [diff] [blame] | 2035 | viaparinfo1->depth = fb_get_color_depth(&viafbinfo1->var, |
| 2036 | &viafbinfo1->fix); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2037 | } |
| 2038 | |
| 2039 | viafb_setup_fixinfo(&viafbinfo->fix, viaparinfo); |
| 2040 | viafb_check_var(&default_var, viafbinfo); |
| 2041 | viafbinfo->var = default_var; |
Florian Tobias Schandinat | 81228a3 | 2009-09-22 16:47:13 -0700 | [diff] [blame] | 2042 | viafb_update_fix(viafbinfo); |
Florian Tobias Schandinat | c3e2567 | 2009-09-22 16:47:26 -0700 | [diff] [blame] | 2043 | viaparinfo->depth = fb_get_color_depth(&viafbinfo->var, |
| 2044 | &viafbinfo->fix); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2045 | default_var.activate = FB_ACTIVATE_NOW; |
| 2046 | fb_alloc_cmap(&viafbinfo->cmap, 256, 0); |
| 2047 | |
| 2048 | if (viafb_dual_fb && (viafb_primary_dev == LCD_Device) |
| 2049 | && (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)) { |
| 2050 | if (register_framebuffer(viafbinfo1) < 0) |
| 2051 | return -EINVAL; |
| 2052 | } |
| 2053 | if (register_framebuffer(viafbinfo) < 0) |
| 2054 | return -EINVAL; |
| 2055 | |
| 2056 | if (viafb_dual_fb && ((viafb_primary_dev != LCD_Device) |
| 2057 | || (viaparinfo->chip_info->gfx_chip_name != |
| 2058 | UNICHROME_CLE266))) { |
| 2059 | if (register_framebuffer(viafbinfo1) < 0) |
| 2060 | return -EINVAL; |
| 2061 | } |
| 2062 | DEBUG_MSG(KERN_INFO "fb%d: %s frame buffer device %dx%d-%dbpp\n", |
| 2063 | viafbinfo->node, viafbinfo->fix.id, default_var.xres, |
| 2064 | default_var.yres, default_var.bits_per_pixel); |
| 2065 | |
Florian Tobias Schandinat | c4df548 | 2009-09-22 16:47:24 -0700 | [diff] [blame] | 2066 | viafb_init_proc(&viaparinfo->shared->proc_entry); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2067 | viafb_init_dac(IGA2); |
| 2068 | return 0; |
| 2069 | } |
| 2070 | |
Harald Welte | 2d280f7 | 2009-09-22 16:47:37 -0700 | [diff] [blame] | 2071 | static void __devexit via_pci_remove(struct pci_dev *pdev) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2072 | { |
| 2073 | DEBUG_MSG(KERN_INFO "via_pci_remove!\n"); |
| 2074 | fb_dealloc_cmap(&viafbinfo->cmap); |
| 2075 | unregister_framebuffer(viafbinfo); |
| 2076 | if (viafb_dual_fb) |
| 2077 | unregister_framebuffer(viafbinfo1); |
Florian Tobias Schandinat | db88e38 | 2009-09-22 16:47:20 -0700 | [diff] [blame] | 2078 | iounmap((void *)viafbinfo->screen_base); |
Florian Tobias Schandinat | 31de59d | 2009-09-22 16:47:31 -0700 | [diff] [blame] | 2079 | iounmap(viaparinfo->shared->engine_mmio); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2080 | |
| 2081 | viafb_delete_i2c_buss(viaparinfo); |
| 2082 | |
| 2083 | framebuffer_release(viafbinfo); |
| 2084 | if (viafb_dual_fb) |
| 2085 | framebuffer_release(viafbinfo1); |
| 2086 | |
Florian Tobias Schandinat | c4df548 | 2009-09-22 16:47:24 -0700 | [diff] [blame] | 2087 | viafb_remove_proc(viaparinfo->shared->proc_entry); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2088 | } |
| 2089 | |
| 2090 | #ifndef MODULE |
| 2091 | static int __init viafb_setup(char *options) |
| 2092 | { |
| 2093 | char *this_opt; |
| 2094 | DEBUG_MSG(KERN_INFO "viafb_setup!\n"); |
| 2095 | |
| 2096 | if (!options || !*options) |
| 2097 | return 0; |
| 2098 | |
| 2099 | while ((this_opt = strsep(&options, ",")) != NULL) { |
| 2100 | if (!*this_opt) |
| 2101 | continue; |
| 2102 | |
| 2103 | if (!strncmp(this_opt, "viafb_mode1=", 12)) |
| 2104 | viafb_mode1 = kstrdup(this_opt + 12, GFP_KERNEL); |
| 2105 | else if (!strncmp(this_opt, "viafb_mode=", 11)) |
| 2106 | viafb_mode = kstrdup(this_opt + 11, GFP_KERNEL); |
| 2107 | else if (!strncmp(this_opt, "viafb_bpp1=", 11)) |
| 2108 | strict_strtoul(this_opt + 11, 0, |
| 2109 | (unsigned long *)&viafb_bpp1); |
| 2110 | else if (!strncmp(this_opt, "viafb_bpp=", 10)) |
| 2111 | strict_strtoul(this_opt + 10, 0, |
| 2112 | (unsigned long *)&viafb_bpp); |
| 2113 | else if (!strncmp(this_opt, "viafb_refresh1=", 15)) |
| 2114 | strict_strtoul(this_opt + 15, 0, |
| 2115 | (unsigned long *)&viafb_refresh1); |
| 2116 | else if (!strncmp(this_opt, "viafb_refresh=", 14)) |
| 2117 | strict_strtoul(this_opt + 14, 0, |
| 2118 | (unsigned long *)&viafb_refresh); |
| 2119 | else if (!strncmp(this_opt, "viafb_lcd_dsp_method=", 21)) |
| 2120 | strict_strtoul(this_opt + 21, 0, |
| 2121 | (unsigned long *)&viafb_lcd_dsp_method); |
| 2122 | else if (!strncmp(this_opt, "viafb_lcd_panel_id=", 19)) |
| 2123 | strict_strtoul(this_opt + 19, 0, |
| 2124 | (unsigned long *)&viafb_lcd_panel_id); |
| 2125 | else if (!strncmp(this_opt, "viafb_accel=", 12)) |
| 2126 | strict_strtoul(this_opt + 12, 0, |
| 2127 | (unsigned long *)&viafb_accel); |
| 2128 | else if (!strncmp(this_opt, "viafb_SAMM_ON=", 14)) |
| 2129 | strict_strtoul(this_opt + 14, 0, |
| 2130 | (unsigned long *)&viafb_SAMM_ON); |
| 2131 | else if (!strncmp(this_opt, "viafb_active_dev=", 17)) |
| 2132 | viafb_active_dev = kstrdup(this_opt + 17, GFP_KERNEL); |
| 2133 | else if (!strncmp(this_opt, |
| 2134 | "viafb_display_hardware_layout=", 30)) |
| 2135 | strict_strtoul(this_opt + 30, 0, |
| 2136 | (unsigned long *)&viafb_display_hardware_layout); |
| 2137 | else if (!strncmp(this_opt, "viafb_second_size=", 18)) |
| 2138 | strict_strtoul(this_opt + 18, 0, |
| 2139 | (unsigned long *)&viafb_second_size); |
| 2140 | else if (!strncmp(this_opt, |
| 2141 | "viafb_platform_epia_dvi=", 24)) |
| 2142 | strict_strtoul(this_opt + 24, 0, |
| 2143 | (unsigned long *)&viafb_platform_epia_dvi); |
| 2144 | else if (!strncmp(this_opt, |
| 2145 | "viafb_device_lcd_dualedge=", 26)) |
| 2146 | strict_strtoul(this_opt + 26, 0, |
| 2147 | (unsigned long *)&viafb_device_lcd_dualedge); |
| 2148 | else if (!strncmp(this_opt, "viafb_bus_width=", 16)) |
| 2149 | strict_strtoul(this_opt + 16, 0, |
| 2150 | (unsigned long *)&viafb_bus_width); |
| 2151 | else if (!strncmp(this_opt, "viafb_lcd_mode=", 15)) |
| 2152 | strict_strtoul(this_opt + 15, 0, |
| 2153 | (unsigned long *)&viafb_lcd_mode); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2154 | else if (!strncmp(this_opt, "viafb_lcd_port=", 15)) |
| 2155 | viafb_lcd_port = kstrdup(this_opt + 15, GFP_KERNEL); |
| 2156 | else if (!strncmp(this_opt, "viafb_dvi_port=", 15)) |
| 2157 | viafb_dvi_port = kstrdup(this_opt + 15, GFP_KERNEL); |
| 2158 | } |
| 2159 | return 0; |
| 2160 | } |
| 2161 | #endif |
| 2162 | |
Harald Welte | 2d280f7 | 2009-09-22 16:47:37 -0700 | [diff] [blame] | 2163 | static struct pci_device_id viafb_pci_table[] __devinitdata = { |
| 2164 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_CLE266_DID), |
| 2165 | .driver_data = UNICHROME_CLE266 }, |
| 2166 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_PM800_DID), |
| 2167 | .driver_data = UNICHROME_PM800 }, |
| 2168 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_K400_DID), |
| 2169 | .driver_data = UNICHROME_K400 }, |
| 2170 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_K800_DID), |
| 2171 | .driver_data = UNICHROME_K800 }, |
| 2172 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_P4M890_DID), |
| 2173 | .driver_data = UNICHROME_CN700 }, |
| 2174 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_K8M890_DID), |
| 2175 | .driver_data = UNICHROME_K8M890 }, |
| 2176 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_CX700_DID), |
| 2177 | .driver_data = UNICHROME_CX700 }, |
| 2178 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_P4M900_DID), |
| 2179 | .driver_data = UNICHROME_P4M900 }, |
| 2180 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_CN750_DID), |
| 2181 | .driver_data = UNICHROME_CN750 }, |
| 2182 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_VX800_DID), |
| 2183 | .driver_data = UNICHROME_VX800 }, |
| 2184 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_VX855_DID), |
| 2185 | .driver_data = UNICHROME_VX855 }, |
| 2186 | { } |
| 2187 | }; |
| 2188 | MODULE_DEVICE_TABLE(pci, viafb_pci_table); |
| 2189 | |
| 2190 | static struct pci_driver viafb_driver = { |
| 2191 | .name = "viafb", |
| 2192 | .id_table = viafb_pci_table, |
| 2193 | .probe = via_pci_probe, |
| 2194 | .remove = __devexit_p(via_pci_remove), |
| 2195 | }; |
| 2196 | |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2197 | static int __init viafb_init(void) |
| 2198 | { |
| 2199 | #ifndef MODULE |
| 2200 | char *option = NULL; |
| 2201 | if (fb_get_options("viafb", &option)) |
| 2202 | return -ENODEV; |
| 2203 | viafb_setup(option); |
| 2204 | #endif |
| 2205 | printk(KERN_INFO |
| 2206 | "VIA Graphics Intergration Chipset framebuffer %d.%d initializing\n", |
| 2207 | VERSION_MAJOR, VERSION_MINOR); |
Harald Welte | 2d280f7 | 2009-09-22 16:47:37 -0700 | [diff] [blame] | 2208 | return pci_register_driver(&viafb_driver); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2209 | } |
| 2210 | |
| 2211 | static void __exit viafb_exit(void) |
| 2212 | { |
| 2213 | DEBUG_MSG(KERN_INFO "viafb_exit!\n"); |
Harald Welte | 2d280f7 | 2009-09-22 16:47:37 -0700 | [diff] [blame] | 2214 | pci_unregister_driver(&viafb_driver); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2215 | } |
| 2216 | |
| 2217 | static struct fb_ops viafb_ops = { |
| 2218 | .owner = THIS_MODULE, |
| 2219 | .fb_open = viafb_open, |
| 2220 | .fb_release = viafb_release, |
| 2221 | .fb_check_var = viafb_check_var, |
| 2222 | .fb_set_par = viafb_set_par, |
| 2223 | .fb_setcolreg = viafb_setcolreg, |
| 2224 | .fb_pan_display = viafb_pan_display, |
| 2225 | .fb_blank = viafb_blank, |
| 2226 | .fb_fillrect = viafb_fillrect, |
| 2227 | .fb_copyarea = viafb_copyarea, |
| 2228 | .fb_imageblit = viafb_imageblit, |
| 2229 | .fb_cursor = viafb_cursor, |
| 2230 | .fb_ioctl = viafb_ioctl, |
| 2231 | .fb_sync = viafb_sync, |
| 2232 | .fb_setcmap = viafb_setcmap, |
| 2233 | }; |
| 2234 | |
| 2235 | module_init(viafb_init); |
| 2236 | module_exit(viafb_exit); |
| 2237 | |
| 2238 | #ifdef MODULE |
Harald Welte | 93967be | 2009-09-22 16:47:32 -0700 | [diff] [blame] | 2239 | module_param(viafb_memsize, int, S_IRUSR); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2240 | |
Harald Welte | 93967be | 2009-09-22 16:47:32 -0700 | [diff] [blame] | 2241 | module_param(viafb_mode, charp, S_IRUSR); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2242 | MODULE_PARM_DESC(viafb_mode, "Set resolution (default=640x480)"); |
| 2243 | |
Harald Welte | 93967be | 2009-09-22 16:47:32 -0700 | [diff] [blame] | 2244 | module_param(viafb_mode1, charp, S_IRUSR); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2245 | MODULE_PARM_DESC(viafb_mode1, "Set resolution (default=640x480)"); |
| 2246 | |
Harald Welte | 93967be | 2009-09-22 16:47:32 -0700 | [diff] [blame] | 2247 | module_param(viafb_bpp, int, S_IRUSR); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2248 | MODULE_PARM_DESC(viafb_bpp, "Set color depth (default=32bpp)"); |
| 2249 | |
Harald Welte | 93967be | 2009-09-22 16:47:32 -0700 | [diff] [blame] | 2250 | module_param(viafb_bpp1, int, S_IRUSR); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2251 | MODULE_PARM_DESC(viafb_bpp1, "Set color depth (default=32bpp)"); |
| 2252 | |
Harald Welte | 93967be | 2009-09-22 16:47:32 -0700 | [diff] [blame] | 2253 | module_param(viafb_refresh, int, S_IRUSR); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2254 | MODULE_PARM_DESC(viafb_refresh, |
| 2255 | "Set CRT viafb_refresh rate (default = 60)"); |
| 2256 | |
Harald Welte | 93967be | 2009-09-22 16:47:32 -0700 | [diff] [blame] | 2257 | module_param(viafb_refresh1, int, S_IRUSR); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2258 | MODULE_PARM_DESC(viafb_refresh1, |
| 2259 | "Set CRT refresh rate (default = 60)"); |
| 2260 | |
Harald Welte | 93967be | 2009-09-22 16:47:32 -0700 | [diff] [blame] | 2261 | module_param(viafb_lcd_panel_id, int, S_IRUSR); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2262 | MODULE_PARM_DESC(viafb_lcd_panel_id, |
| 2263 | "Set Flat Panel type(Default=1024x768)"); |
| 2264 | |
Harald Welte | 93967be | 2009-09-22 16:47:32 -0700 | [diff] [blame] | 2265 | module_param(viafb_lcd_dsp_method, int, S_IRUSR); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2266 | MODULE_PARM_DESC(viafb_lcd_dsp_method, |
| 2267 | "Set Flat Panel display scaling method.(Default=Expandsion)"); |
| 2268 | |
Harald Welte | 93967be | 2009-09-22 16:47:32 -0700 | [diff] [blame] | 2269 | module_param(viafb_SAMM_ON, int, S_IRUSR); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2270 | MODULE_PARM_DESC(viafb_SAMM_ON, |
| 2271 | "Turn on/off flag of SAMM(Default=OFF)"); |
| 2272 | |
Harald Welte | 93967be | 2009-09-22 16:47:32 -0700 | [diff] [blame] | 2273 | module_param(viafb_accel, int, S_IRUSR); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2274 | MODULE_PARM_DESC(viafb_accel, |
Florian Tobias Schandinat | 31de59d | 2009-09-22 16:47:31 -0700 | [diff] [blame] | 2275 | "Set 2D Hardware Acceleration: 0 = OFF, 1 = ON (default)"); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2276 | |
Harald Welte | 93967be | 2009-09-22 16:47:32 -0700 | [diff] [blame] | 2277 | module_param(viafb_active_dev, charp, S_IRUSR); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2278 | MODULE_PARM_DESC(viafb_active_dev, "Specify active devices."); |
| 2279 | |
Harald Welte | 93967be | 2009-09-22 16:47:32 -0700 | [diff] [blame] | 2280 | module_param(viafb_display_hardware_layout, int, S_IRUSR); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2281 | MODULE_PARM_DESC(viafb_display_hardware_layout, |
| 2282 | "Display Hardware Layout (LCD Only, DVI Only...,etc)"); |
| 2283 | |
Harald Welte | 93967be | 2009-09-22 16:47:32 -0700 | [diff] [blame] | 2284 | module_param(viafb_second_size, int, S_IRUSR); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2285 | MODULE_PARM_DESC(viafb_second_size, |
| 2286 | "Set secondary device memory size"); |
| 2287 | |
Harald Welte | 93967be | 2009-09-22 16:47:32 -0700 | [diff] [blame] | 2288 | module_param(viafb_dual_fb, int, S_IRUSR); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2289 | MODULE_PARM_DESC(viafb_dual_fb, |
| 2290 | "Turn on/off flag of dual framebuffer devices.(Default = OFF)"); |
| 2291 | |
Harald Welte | 93967be | 2009-09-22 16:47:32 -0700 | [diff] [blame] | 2292 | module_param(viafb_platform_epia_dvi, int, S_IRUSR); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2293 | MODULE_PARM_DESC(viafb_platform_epia_dvi, |
| 2294 | "Turn on/off flag of DVI devices on EPIA board.(Default = OFF)"); |
| 2295 | |
Harald Welte | 93967be | 2009-09-22 16:47:32 -0700 | [diff] [blame] | 2296 | module_param(viafb_device_lcd_dualedge, int, S_IRUSR); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2297 | MODULE_PARM_DESC(viafb_device_lcd_dualedge, |
| 2298 | "Turn on/off flag of dual edge panel.(Default = OFF)"); |
| 2299 | |
Harald Welte | 93967be | 2009-09-22 16:47:32 -0700 | [diff] [blame] | 2300 | module_param(viafb_bus_width, int, S_IRUSR); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2301 | MODULE_PARM_DESC(viafb_bus_width, |
| 2302 | "Set bus width of panel.(Default = 12)"); |
| 2303 | |
Harald Welte | 93967be | 2009-09-22 16:47:32 -0700 | [diff] [blame] | 2304 | module_param(viafb_lcd_mode, int, S_IRUSR); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2305 | MODULE_PARM_DESC(viafb_lcd_mode, |
| 2306 | "Set Flat Panel mode(Default=OPENLDI)"); |
| 2307 | |
Harald Welte | 93967be | 2009-09-22 16:47:32 -0700 | [diff] [blame] | 2308 | module_param(viafb_lcd_port, charp, S_IRUSR); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2309 | MODULE_PARM_DESC(viafb_lcd_port, "Specify LCD output port."); |
| 2310 | |
Harald Welte | 93967be | 2009-09-22 16:47:32 -0700 | [diff] [blame] | 2311 | module_param(viafb_dvi_port, charp, S_IRUSR); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2312 | MODULE_PARM_DESC(viafb_dvi_port, "Specify DVI output port."); |
| 2313 | |
| 2314 | MODULE_LICENSE("GPL"); |
| 2315 | #endif |