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