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