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