blob: a13c258bd32f45ed1abe7126fdc3728b1657b5e7 [file] [log] [blame]
Joseph Chan29b619f2008-10-15 22:03:27 -07001/*
Harald Welte109771a2009-05-19 17:12:58 +08002 * Copyright 1998-2009 VIA Technologies, Inc. All Rights Reserved.
Joseph Chan29b619f2008-10-15 22:03:27 -07003 * 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 Dobriyanafbd3c12009-09-22 16:47:27 -070023#include <linux/seq_file.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
Harald Welte93967be2009-09-22 16:47:32 -070025#include <linux/stat.h>
Jonathan Corbetec668412010-05-05 14:44:55 -060026#include <linux/via-core.h>
Daniel Drake8aa4d962011-05-10 22:34:11 +010027#include <asm/olpc.h>
Joseph Chan29b619f2008-10-15 22:03:27 -070028
Jonathan Corbetec668412010-05-05 14:44:55 -060029#define _MASTER_FILE
Joseph Chan29b619f2008-10-15 22:03:27 -070030#include "global.h"
31
Joseph Chan29b619f2008-10-15 22:03:27 -070032static char *viafb_name = "Via";
33static u32 pseudo_pal[17];
34
35/* video mode */
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -080036static char *viafb_mode;
37static char *viafb_mode1;
Florian Tobias Schandinatdba77f82010-03-10 15:21:37 -080038static int viafb_bpp = 32;
39static int viafb_bpp1 = 32;
40
41static unsigned int viafb_second_offset;
42static int viafb_second_size;
Joseph Chan29b619f2008-10-15 22:03:27 -070043
Florian Tobias Schandinat31de59d2009-09-22 16:47:31 -070044static int viafb_accel = 1;
45
Joseph Chan29b619f2008-10-15 22:03:27 -070046/* Added for specifying active devices.*/
Stephen Hemminger23e5abd2011-03-03 10:00:08 -080047static char *viafb_active_dev;
Joseph Chan29b619f2008-10-15 22:03:27 -070048
Joseph Chan29b619f2008-10-15 22:03:27 -070049/*Added for specify lcd output port*/
Stephen Hemminger23e5abd2011-03-03 10:00:08 -080050static char *viafb_lcd_port = "";
51static char *viafb_dvi_port = "";
Joseph Chan29b619f2008-10-15 22:03:27 -070052
Joseph Chan29b619f2008-10-15 22:03:27 -070053static void retrieve_device_setting(struct viafb_ioctl_setting
54 *setting_info);
Florian Tobias Schandinatee79d542010-03-10 15:21:32 -080055static int viafb_pan_display(struct fb_var_screeninfo *var,
56 struct fb_info *info);
Joseph Chan29b619f2008-10-15 22:03:27 -070057
Joseph Chan29b619f2008-10-15 22:03:27 -070058static struct fb_ops viafb_ops;
59
Florian Tobias Schandinatdd7a0b02010-09-19 04:20:55 +000060/* supported output devices on each IGP
Florian Tobias Schandinat51f43322010-10-24 04:02:14 +000061 * only CX700, VX800, VX855, VX900 were documented
Florian Tobias Schandinatdd7a0b02010-09-19 04:20:55 +000062 * VIA_CRT should be everywhere
63 * VIA_6C can be onle pre-CX700 (probably only on CLE266) as 6C is used for PLL
64 * source selection on CX700 and later
65 * K400 seems to support VIA_96, VIA_DVP1, VIA_LVDS{1,2} as in viamode.c
66 */
67static const u32 supported_odev_map[] = {
Florian Tobias Schandinata2aa9f92010-09-19 04:40:15 +000068 [UNICHROME_CLE266] = VIA_CRT | VIA_LDVP0 | VIA_LDVP1,
69 [UNICHROME_K400] = VIA_CRT | VIA_DVP0 | VIA_DVP1 | VIA_LVDS1
Florian Tobias Schandinatdd7a0b02010-09-19 04:20:55 +000070 | VIA_LVDS2,
Florian Tobias Schandinata2aa9f92010-09-19 04:40:15 +000071 [UNICHROME_K800] = VIA_CRT | VIA_DVP0 | VIA_DVP1 | VIA_LVDS1
Florian Tobias Schandinatdd7a0b02010-09-19 04:20:55 +000072 | VIA_LVDS2,
Florian Tobias Schandinata2aa9f92010-09-19 04:40:15 +000073 [UNICHROME_PM800] = VIA_CRT | VIA_DVP0 | VIA_DVP1 | VIA_LVDS1
Florian Tobias Schandinatdd7a0b02010-09-19 04:20:55 +000074 | VIA_LVDS2,
Florian Tobias Schandinata2aa9f92010-09-19 04:40:15 +000075 [UNICHROME_CN700] = VIA_CRT | VIA_DVP0 | VIA_DVP1 | VIA_LVDS1
Florian Tobias Schandinatdd7a0b02010-09-19 04:20:55 +000076 | VIA_LVDS2,
77 [UNICHROME_CX700] = VIA_CRT | VIA_DVP1 | VIA_LVDS1 | VIA_LVDS2,
78 [UNICHROME_CN750] = VIA_CRT | VIA_DVP1 | VIA_LVDS1 | VIA_LVDS2,
79 [UNICHROME_K8M890] = VIA_CRT | VIA_DVP1 | VIA_LVDS1 | VIA_LVDS2,
80 [UNICHROME_P4M890] = VIA_CRT | VIA_DVP1 | VIA_LVDS1 | VIA_LVDS2,
81 [UNICHROME_P4M900] = VIA_CRT | VIA_DVP1 | VIA_LVDS1 | VIA_LVDS2,
82 [UNICHROME_VX800] = VIA_CRT | VIA_DVP1 | VIA_LVDS1 | VIA_LVDS2,
83 [UNICHROME_VX855] = VIA_CRT | VIA_DVP1 | VIA_LVDS1 | VIA_LVDS2,
Florian Tobias Schandinat51f43322010-10-24 04:02:14 +000084 [UNICHROME_VX900] = VIA_CRT | VIA_DVP1 | VIA_LVDS1 | VIA_LVDS2,
Florian Tobias Schandinatdd7a0b02010-09-19 04:20:55 +000085};
Florian Tobias Schandinat81228a32009-09-22 16:47:13 -070086
Florian Tobias Schandinatbd140692010-03-10 15:21:38 -080087static void viafb_fill_var_color_info(struct fb_var_screeninfo *var, u8 depth)
88{
89 var->grayscale = 0;
90 var->red.msb_right = 0;
91 var->green.msb_right = 0;
92 var->blue.msb_right = 0;
93 var->transp.offset = 0;
94 var->transp.length = 0;
95 var->transp.msb_right = 0;
96 var->nonstd = 0;
97 switch (depth) {
98 case 8:
99 var->bits_per_pixel = 8;
100 var->red.offset = 0;
101 var->green.offset = 0;
102 var->blue.offset = 0;
Florian Tobias Schandinat415559f2010-03-10 15:21:40 -0800103 var->red.length = 8;
104 var->green.length = 8;
105 var->blue.length = 8;
Florian Tobias Schandinatbd140692010-03-10 15:21:38 -0800106 break;
Florian Tobias Schandinate17cea32010-03-10 15:21:41 -0800107 case 15:
108 var->bits_per_pixel = 16;
109 var->red.offset = 10;
110 var->green.offset = 5;
111 var->blue.offset = 0;
112 var->red.length = 5;
113 var->green.length = 5;
114 var->blue.length = 5;
115 break;
Florian Tobias Schandinatbd140692010-03-10 15:21:38 -0800116 case 16:
117 var->bits_per_pixel = 16;
118 var->red.offset = 11;
119 var->green.offset = 5;
120 var->blue.offset = 0;
121 var->red.length = 5;
122 var->green.length = 6;
123 var->blue.length = 5;
124 break;
125 case 24:
126 var->bits_per_pixel = 32;
127 var->red.offset = 16;
128 var->green.offset = 8;
129 var->blue.offset = 0;
130 var->red.length = 8;
131 var->green.length = 8;
132 var->blue.length = 8;
133 break;
Florian Tobias Schandinate17cea32010-03-10 15:21:41 -0800134 case 30:
135 var->bits_per_pixel = 32;
136 var->red.offset = 20;
137 var->green.offset = 10;
138 var->blue.offset = 0;
139 var->red.length = 10;
140 var->green.length = 10;
141 var->blue.length = 10;
142 break;
Florian Tobias Schandinatbd140692010-03-10 15:21:38 -0800143 }
144}
145
Florian Tobias Schandinat81228a32009-09-22 16:47:13 -0700146static void viafb_update_fix(struct fb_info *info)
Joseph Chan29b619f2008-10-15 22:03:27 -0700147{
Florian Tobias Schandinat81228a32009-09-22 16:47:13 -0700148 u32 bpp = info->var.bits_per_pixel;
Joseph Chan29b619f2008-10-15 22:03:27 -0700149
Florian Tobias Schandinat81228a32009-09-22 16:47:13 -0700150 info->fix.visual =
151 bpp == 8 ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
Florian Tobias Schandinat936a3f72011-06-06 01:27:34 +0000152 info->fix.line_length = ALIGN(info->var.xres_virtual * bpp / 8,
153 VIA_PITCH_SIZE);
Joseph Chan29b619f2008-10-15 22:03:27 -0700154}
155
Joseph Chan29b619f2008-10-15 22:03:27 -0700156static void viafb_setup_fixinfo(struct fb_fix_screeninfo *fix,
157 struct viafb_par *viaparinfo)
158{
159 memset(fix, 0, sizeof(struct fb_fix_screeninfo));
160 strcpy(fix->id, viafb_name);
161
162 fix->smem_start = viaparinfo->fbmem;
163 fix->smem_len = viaparinfo->fbmem_free;
Joseph Chan29b619f2008-10-15 22:03:27 -0700164
165 fix->type = FB_TYPE_PACKED_PIXELS;
166 fix->type_aux = 0;
Florian Tobias Schandinatbd140692010-03-10 15:21:38 -0800167 fix->visual = FB_VISUAL_TRUECOLOR;
Joseph Chan29b619f2008-10-15 22:03:27 -0700168
169 fix->xpanstep = fix->ywrapstep = 0;
170 fix->ypanstep = 1;
171
172 /* Just tell the accel name */
173 viafbinfo->fix.accel = FB_ACCEL_VIA_UNICHROME;
174}
175static int viafb_open(struct fb_info *info, int user)
176{
177 DEBUG_MSG(KERN_INFO "viafb_open!\n");
178 return 0;
179}
180
181static int viafb_release(struct fb_info *info, int user)
182{
183 DEBUG_MSG(KERN_INFO "viafb_release!\n");
184 return 0;
185}
186
Florian Tobias Schandinat726abbc2011-03-16 16:31:32 +0000187static inline int get_var_refresh(struct fb_var_screeninfo *var)
188{
189 u32 htotal, vtotal;
190
191 htotal = var->left_margin + var->xres + var->right_margin
192 + var->hsync_len;
193 vtotal = var->upper_margin + var->yres + var->lower_margin
194 + var->vsync_len;
195 return PICOS2KHZ(var->pixclock) * 1000 / (htotal * vtotal);
196}
197
Joseph Chan29b619f2008-10-15 22:03:27 -0700198static int viafb_check_var(struct fb_var_screeninfo *var,
199 struct fb_info *info)
200{
Florian Tobias Schandinat726abbc2011-03-16 16:31:32 +0000201 int depth, refresh;
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700202 struct viafb_par *ppar = info->par;
Florian Tobias Schandinat726abbc2011-03-16 16:31:32 +0000203 u32 line;
Joseph Chan29b619f2008-10-15 22:03:27 -0700204
205 DEBUG_MSG(KERN_INFO "viafb_check_var!\n");
206 /* Sanity check */
207 /* HW neither support interlacte nor double-scaned mode */
208 if (var->vmode & FB_VMODE_INTERLACED || var->vmode & FB_VMODE_DOUBLE)
209 return -EINVAL;
210
Florian Tobias Schandinat94715ba2011-08-06 23:04:43 +0000211 /* the refresh rate is not important here, as we only want to know
212 * whether the resolution exists
213 */
214 if (!viafb_get_best_mode(var->xres, var->yres, 60)) {
Joseph Chan29b619f2008-10-15 22:03:27 -0700215 DEBUG_MSG(KERN_INFO
216 "viafb: Mode %dx%dx%d not supported!!\n",
217 var->xres, var->yres, var->bits_per_pixel);
218 return -EINVAL;
219 }
220
Florian Tobias Schandinatbd140692010-03-10 15:21:38 -0800221 depth = fb_get_color_depth(var, &info->fix);
222 if (!depth)
223 depth = var->bits_per_pixel;
Joseph Chan29b619f2008-10-15 22:03:27 -0700224
Florian Tobias Schandinatbd140692010-03-10 15:21:38 -0800225 if (depth < 0 || depth > 32)
Joseph Chan29b619f2008-10-15 22:03:27 -0700226 return -EINVAL;
Florian Tobias Schandinatbd140692010-03-10 15:21:38 -0800227 else if (!depth)
228 depth = 24;
Florian Tobias Schandinate17cea32010-03-10 15:21:41 -0800229 else if (depth == 15 && viafb_dual_fb && ppar->iga_path == IGA1)
230 depth = 15;
231 else if (depth == 30)
232 depth = 30;
Florian Tobias Schandinatbd140692010-03-10 15:21:38 -0800233 else if (depth <= 8)
234 depth = 8;
235 else if (depth <= 16)
236 depth = 16;
237 else
238 depth = 24;
Joseph Chan29b619f2008-10-15 22:03:27 -0700239
Florian Tobias Schandinatbd140692010-03-10 15:21:38 -0800240 viafb_fill_var_color_info(var, depth);
Florian Tobias Schandinat936a3f72011-06-06 01:27:34 +0000241 if (var->xres_virtual < var->xres)
242 var->xres_virtual = var->xres;
243
244 line = ALIGN(var->xres_virtual * var->bits_per_pixel / 8,
245 VIA_PITCH_SIZE);
246 if (line > VIA_PITCH_MAX || line * var->yres_virtual > ppar->memsize)
Joseph Chan29b619f2008-10-15 22:03:27 -0700247 return -EINVAL;
248
249 /* Based on var passed in to calculate the refresh,
250 * because our driver use some modes special.
251 */
Florian Tobias Schandinat726abbc2011-03-16 16:31:32 +0000252 refresh = viafb_get_refresh(var->xres, var->yres,
253 get_var_refresh(var));
Joseph Chan29b619f2008-10-15 22:03:27 -0700254
255 /* Adjust var according to our driver's own table */
Florian Tobias Schandinat94715ba2011-08-06 23:04:43 +0000256 viafb_fill_var_timing_info(var,
257 viafb_get_best_mode(var->xres, var->yres, refresh));
Florian Tobias Schandinataf29a5b2010-07-23 11:32:25 +0000258 if (var->accel_flags & FB_ACCELF_TEXT &&
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600259 !ppar->shared->vdev->engine_mmio)
Florian Tobias Schandinataf29a5b2010-07-23 11:32:25 +0000260 var->accel_flags = 0;
Joseph Chan29b619f2008-10-15 22:03:27 -0700261
Joseph Chan29b619f2008-10-15 22:03:27 -0700262 return 0;
263}
264
265static int viafb_set_par(struct fb_info *info)
266{
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700267 struct viafb_par *viapar = info->par;
Florian Tobias Schandinat726abbc2011-03-16 16:31:32 +0000268 int refresh;
Joseph Chan29b619f2008-10-15 22:03:27 -0700269 DEBUG_MSG(KERN_INFO "viafb_set_par!\n");
270
Florian Tobias Schandinat65123c62010-07-13 17:58:06 +0000271 viafb_update_fix(info);
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700272 viapar->depth = fb_get_color_depth(&info->var, &info->fix);
Florian Tobias Schandinat5c9443e2010-03-10 15:21:34 -0800273 viafb_update_device_setting(viafbinfo->var.xres, viafbinfo->var.yres,
Florian Tobias Schandinat726abbc2011-03-16 16:31:32 +0000274 viafbinfo->var.bits_per_pixel, 0);
Joseph Chan29b619f2008-10-15 22:03:27 -0700275
Florian Tobias Schandinat5c9443e2010-03-10 15:21:34 -0800276 if (viafb_dual_fb) {
Florian Tobias Schandinat5c9443e2010-03-10 15:21:34 -0800277 viafb_update_device_setting(viafbinfo1->var.xres,
278 viafbinfo1->var.yres, viafbinfo1->var.bits_per_pixel,
Florian Tobias Schandinat726abbc2011-03-16 16:31:32 +0000279 1);
Florian Tobias Schandinat5c9443e2010-03-10 15:21:34 -0800280 } else if (viafb_SAMM_ON == 1) {
Joseph Chan29b619f2008-10-15 22:03:27 -0700281 DEBUG_MSG(KERN_INFO
282 "viafb_second_xres = %d, viafb_second_yres = %d, bpp = %d\n",
283 viafb_second_xres, viafb_second_yres, viafb_bpp1);
Joseph Chan29b619f2008-10-15 22:03:27 -0700284
285 viafb_update_device_setting(viafb_second_xres,
Florian Tobias Schandinat726abbc2011-03-16 16:31:32 +0000286 viafb_second_yres, viafb_bpp1, 1);
Joseph Chan29b619f2008-10-15 22:03:27 -0700287 }
288
Florian Tobias Schandinat726abbc2011-03-16 16:31:32 +0000289 refresh = viafb_get_refresh(info->var.xres, info->var.yres,
290 get_var_refresh(&info->var));
Florian Tobias Schandinat5dd72f12011-08-07 13:34:35 +0000291 if (viafb_get_best_mode(viafbinfo->var.xres, viafbinfo->var.yres,
292 refresh)) {
Florian Tobias Schandinat726abbc2011-03-16 16:31:32 +0000293 if (viafb_dual_fb && viapar->iga_path == IGA2) {
Florian Tobias Schandinat5c9443e2010-03-10 15:21:34 -0800294 viafb_bpp1 = info->var.bits_per_pixel;
Florian Tobias Schandinat726abbc2011-03-16 16:31:32 +0000295 viafb_refresh1 = refresh;
296 } else {
Florian Tobias Schandinat5c9443e2010-03-10 15:21:34 -0800297 viafb_bpp = info->var.bits_per_pixel;
Florian Tobias Schandinat726abbc2011-03-16 16:31:32 +0000298 viafb_refresh = refresh;
299 }
Florian Tobias Schandinat5c9443e2010-03-10 15:21:34 -0800300
Florian Tobias Schandinat31de59d2009-09-22 16:47:31 -0700301 if (info->var.accel_flags & FB_ACCELF_TEXT)
302 info->flags &= ~FBINFO_HWACCEL_DISABLED;
303 else
304 info->flags |= FBINFO_HWACCEL_DISABLED;
Florian Tobias Schandinat5dd72f12011-08-07 13:34:35 +0000305 viafb_setmode(info->var.bits_per_pixel, viafb_bpp1);
Florian Tobias Schandinatee79d542010-03-10 15:21:32 -0800306 viafb_pan_display(&info->var, info);
Joseph Chan29b619f2008-10-15 22:03:27 -0700307 }
308
309 return 0;
310}
311
312/* Set one color register */
313static int viafb_setcolreg(unsigned regno, unsigned red, unsigned green,
314unsigned blue, unsigned transp, struct fb_info *info)
315{
Florian Tobias Schandinat415559f2010-03-10 15:21:40 -0800316 struct viafb_par *viapar = info->par;
317 u32 r, g, b;
Joseph Chan29b619f2008-10-15 22:03:27 -0700318
Florian Tobias Schandinat415559f2010-03-10 15:21:40 -0800319 if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR) {
320 if (regno > 255)
321 return -EINVAL;
Joseph Chan29b619f2008-10-15 22:03:27 -0700322
Florian Tobias Schandinat415559f2010-03-10 15:21:40 -0800323 if (!viafb_dual_fb || viapar->iga_path == IGA1)
324 viafb_set_primary_color_register(regno, red >> 8,
325 green >> 8, blue >> 8);
Joseph Chan29b619f2008-10-15 22:03:27 -0700326
Florian Tobias Schandinat415559f2010-03-10 15:21:40 -0800327 if (!viafb_dual_fb || viapar->iga_path == IGA2)
328 viafb_set_secondary_color_register(regno, red >> 8,
329 green >> 8, blue >> 8);
330 } else {
331 if (regno > 15)
332 return -EINVAL;
Joseph Chan29b619f2008-10-15 22:03:27 -0700333
Florian Tobias Schandinat415559f2010-03-10 15:21:40 -0800334 r = (red >> (16 - info->var.red.length))
335 << info->var.red.offset;
336 b = (blue >> (16 - info->var.blue.length))
337 << info->var.blue.offset;
338 g = (green >> (16 - info->var.green.length))
339 << info->var.green.offset;
340 ((u32 *) info->pseudo_palette)[regno] = r | g | b;
Joseph Chan29b619f2008-10-15 22:03:27 -0700341 }
342
343 return 0;
Joseph Chan29b619f2008-10-15 22:03:27 -0700344}
345
346static int viafb_pan_display(struct fb_var_screeninfo *var,
347 struct fb_info *info)
348{
Florian Tobias Schandinatee79d542010-03-10 15:21:32 -0800349 struct viafb_par *viapar = info->par;
Florian Tobias Schandinatd9339902011-05-23 21:39:58 +0000350 u32 vram_addr = viapar->vram_addr
351 + var->yoffset * info->fix.line_length
352 + var->xoffset * info->var.bits_per_pixel / 8;
Joseph Chan29b619f2008-10-15 22:03:27 -0700353
Florian Tobias Schandinatee79d542010-03-10 15:21:32 -0800354 DEBUG_MSG(KERN_DEBUG "viafb_pan_display, address = %d\n", vram_addr);
355 if (!viafb_dual_fb) {
Florian Tobias Schandinat27494132010-04-17 19:44:52 +0000356 via_set_primary_address(vram_addr);
357 via_set_secondary_address(vram_addr);
Florian Tobias Schandinatee79d542010-03-10 15:21:32 -0800358 } else if (viapar->iga_path == IGA1)
Florian Tobias Schandinat27494132010-04-17 19:44:52 +0000359 via_set_primary_address(vram_addr);
Florian Tobias Schandinatee79d542010-03-10 15:21:32 -0800360 else
Florian Tobias Schandinat27494132010-04-17 19:44:52 +0000361 via_set_secondary_address(vram_addr);
Joseph Chan29b619f2008-10-15 22:03:27 -0700362
Joseph Chan29b619f2008-10-15 22:03:27 -0700363 return 0;
364}
365
366static int viafb_blank(int blank_mode, struct fb_info *info)
367{
368 DEBUG_MSG(KERN_INFO "viafb_blank!\n");
369 /* clear DPMS setting */
370
371 switch (blank_mode) {
372 case FB_BLANK_UNBLANK:
373 /* Screen: On, HSync: On, VSync: On */
374 /* control CRT monitor power management */
Florian Tobias Schandinat6f9422d2010-09-07 14:28:26 +0000375 via_set_state(VIA_CRT, VIA_STATE_ON);
Joseph Chan29b619f2008-10-15 22:03:27 -0700376 break;
377 case FB_BLANK_HSYNC_SUSPEND:
378 /* Screen: Off, HSync: Off, VSync: On */
379 /* control CRT monitor power management */
Florian Tobias Schandinat6f9422d2010-09-07 14:28:26 +0000380 via_set_state(VIA_CRT, VIA_STATE_STANDBY);
Joseph Chan29b619f2008-10-15 22:03:27 -0700381 break;
382 case FB_BLANK_VSYNC_SUSPEND:
383 /* Screen: Off, HSync: On, VSync: Off */
384 /* control CRT monitor power management */
Florian Tobias Schandinat6f9422d2010-09-07 14:28:26 +0000385 via_set_state(VIA_CRT, VIA_STATE_SUSPEND);
Joseph Chan29b619f2008-10-15 22:03:27 -0700386 break;
387 case FB_BLANK_POWERDOWN:
388 /* Screen: Off, HSync: Off, VSync: Off */
389 /* control CRT monitor power management */
Florian Tobias Schandinat6f9422d2010-09-07 14:28:26 +0000390 via_set_state(VIA_CRT, VIA_STATE_OFF);
Joseph Chan29b619f2008-10-15 22:03:27 -0700391 break;
392 }
393
394 return 0;
395}
396
397static int viafb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
398{
Bruno Prémonte687d692009-01-04 13:11:54 -0800399 union {
400 struct viafb_ioctl_mode viamode;
401 struct viafb_ioctl_samm viasamm;
402 struct viafb_driver_version driver_version;
403 struct fb_var_screeninfo sec_var;
404 struct _panel_size_pos_info panel_pos_size_para;
405 struct viafb_ioctl_setting viafb_setting;
406 struct device_t active_dev;
407 } u;
Joseph Chan29b619f2008-10-15 22:03:27 -0700408 u32 state_info = 0;
Joseph Chan29b619f2008-10-15 22:03:27 -0700409 u32 *viafb_gamma_table;
410 char driver_name[] = "viafb";
411
412 u32 __user *argp = (u32 __user *) arg;
413 u32 gpu32;
Joseph Chan29b619f2008-10-15 22:03:27 -0700414
415 DEBUG_MSG(KERN_INFO "viafb_ioctl: 0x%X !!\n", cmd);
Florian Tobias Schandinatcc8b82f2010-03-10 15:21:26 -0800416 printk(KERN_WARNING "viafb_ioctl: Please avoid this interface as it is unstable and might change or vanish at any time!\n");
Bruno Prémonte687d692009-01-04 13:11:54 -0800417 memset(&u, 0, sizeof(u));
Joseph Chan29b619f2008-10-15 22:03:27 -0700418
419 switch (cmd) {
420 case VIAFB_GET_CHIP_INFO:
421 if (copy_to_user(argp, viaparinfo->chip_info,
422 sizeof(struct chip_information)))
423 return -EFAULT;
424 break;
425 case VIAFB_GET_INFO_SIZE:
Bruno Prémonte687d692009-01-04 13:11:54 -0800426 return put_user((u32)sizeof(struct viafb_ioctl_info), argp);
Joseph Chan29b619f2008-10-15 22:03:27 -0700427 case VIAFB_GET_INFO:
428 return viafb_ioctl_get_viafb_info(arg);
429 case VIAFB_HOTPLUG:
430 return put_user(viafb_ioctl_hotplug(info->var.xres,
431 info->var.yres,
432 info->var.bits_per_pixel), argp);
433 case VIAFB_SET_HOTPLUG_FLAG:
434 if (copy_from_user(&gpu32, argp, sizeof(gpu32)))
435 return -EFAULT;
436 viafb_hotplug = (gpu32) ? 1 : 0;
437 break;
438 case VIAFB_GET_RESOLUTION:
Bruno Prémonte687d692009-01-04 13:11:54 -0800439 u.viamode.xres = (u32) viafb_hotplug_Xres;
440 u.viamode.yres = (u32) viafb_hotplug_Yres;
441 u.viamode.refresh = (u32) viafb_hotplug_refresh;
442 u.viamode.bpp = (u32) viafb_hotplug_bpp;
Joseph Chan29b619f2008-10-15 22:03:27 -0700443 if (viafb_SAMM_ON == 1) {
Bruno Prémonte687d692009-01-04 13:11:54 -0800444 u.viamode.xres_sec = viafb_second_xres;
445 u.viamode.yres_sec = viafb_second_yres;
Florian Tobias Schandinat7f980a02011-03-27 02:54:32 +0000446 u.viamode.virtual_xres_sec = viafb_dual_fb ? viafbinfo1->var.xres_virtual : viafbinfo->var.xres_virtual;
447 u.viamode.virtual_yres_sec = viafb_dual_fb ? viafbinfo1->var.yres_virtual : viafbinfo->var.yres_virtual;
Bruno Prémonte687d692009-01-04 13:11:54 -0800448 u.viamode.refresh_sec = viafb_refresh1;
449 u.viamode.bpp_sec = viafb_bpp1;
Joseph Chan29b619f2008-10-15 22:03:27 -0700450 } else {
Bruno Prémonte687d692009-01-04 13:11:54 -0800451 u.viamode.xres_sec = 0;
452 u.viamode.yres_sec = 0;
453 u.viamode.virtual_xres_sec = 0;
454 u.viamode.virtual_yres_sec = 0;
455 u.viamode.refresh_sec = 0;
456 u.viamode.bpp_sec = 0;
Joseph Chan29b619f2008-10-15 22:03:27 -0700457 }
Bruno Prémonte687d692009-01-04 13:11:54 -0800458 if (copy_to_user(argp, &u.viamode, sizeof(u.viamode)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700459 return -EFAULT;
460 break;
461 case VIAFB_GET_SAMM_INFO:
Bruno Prémonte687d692009-01-04 13:11:54 -0800462 u.viasamm.samm_status = viafb_SAMM_ON;
Joseph Chan29b619f2008-10-15 22:03:27 -0700463
464 if (viafb_SAMM_ON == 1) {
465 if (viafb_dual_fb) {
Bruno Prémonte687d692009-01-04 13:11:54 -0800466 u.viasamm.size_prim = viaparinfo->fbmem_free;
467 u.viasamm.size_sec = viaparinfo1->fbmem_free;
Joseph Chan29b619f2008-10-15 22:03:27 -0700468 } else {
469 if (viafb_second_size) {
Bruno Prémonte687d692009-01-04 13:11:54 -0800470 u.viasamm.size_prim =
Joseph Chan29b619f2008-10-15 22:03:27 -0700471 viaparinfo->fbmem_free -
472 viafb_second_size * 1024 * 1024;
Bruno Prémonte687d692009-01-04 13:11:54 -0800473 u.viasamm.size_sec =
Joseph Chan29b619f2008-10-15 22:03:27 -0700474 viafb_second_size * 1024 * 1024;
475 } else {
Bruno Prémonte687d692009-01-04 13:11:54 -0800476 u.viasamm.size_prim =
Joseph Chan29b619f2008-10-15 22:03:27 -0700477 viaparinfo->fbmem_free >> 1;
Bruno Prémonte687d692009-01-04 13:11:54 -0800478 u.viasamm.size_sec =
Joseph Chan29b619f2008-10-15 22:03:27 -0700479 (viaparinfo->fbmem_free >> 1);
480 }
481 }
Bruno Prémonte687d692009-01-04 13:11:54 -0800482 u.viasamm.mem_base = viaparinfo->fbmem;
483 u.viasamm.offset_sec = viafb_second_offset;
Joseph Chan29b619f2008-10-15 22:03:27 -0700484 } else {
Bruno Prémonte687d692009-01-04 13:11:54 -0800485 u.viasamm.size_prim =
Joseph Chan29b619f2008-10-15 22:03:27 -0700486 viaparinfo->memsize - viaparinfo->fbmem_used;
Bruno Prémonte687d692009-01-04 13:11:54 -0800487 u.viasamm.size_sec = 0;
488 u.viasamm.mem_base = viaparinfo->fbmem;
489 u.viasamm.offset_sec = 0;
Joseph Chan29b619f2008-10-15 22:03:27 -0700490 }
491
Bruno Prémonte687d692009-01-04 13:11:54 -0800492 if (copy_to_user(argp, &u.viasamm, sizeof(u.viasamm)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700493 return -EFAULT;
494
495 break;
496 case VIAFB_TURN_ON_OUTPUT_DEVICE:
497 if (copy_from_user(&gpu32, argp, sizeof(gpu32)))
498 return -EFAULT;
499 if (gpu32 & CRT_Device)
Florian Tobias Schandinat6f9422d2010-09-07 14:28:26 +0000500 via_set_state(VIA_CRT, VIA_STATE_ON);
Joseph Chan29b619f2008-10-15 22:03:27 -0700501 if (gpu32 & DVI_Device)
502 viafb_dvi_enable();
503 if (gpu32 & LCD_Device)
504 viafb_lcd_enable();
505 break;
506 case VIAFB_TURN_OFF_OUTPUT_DEVICE:
507 if (copy_from_user(&gpu32, argp, sizeof(gpu32)))
508 return -EFAULT;
509 if (gpu32 & CRT_Device)
Florian Tobias Schandinat6f9422d2010-09-07 14:28:26 +0000510 via_set_state(VIA_CRT, VIA_STATE_OFF);
Joseph Chan29b619f2008-10-15 22:03:27 -0700511 if (gpu32 & DVI_Device)
512 viafb_dvi_disable();
513 if (gpu32 & LCD_Device)
514 viafb_lcd_disable();
515 break;
Joseph Chan29b619f2008-10-15 22:03:27 -0700516 case VIAFB_GET_DEVICE:
Bruno Prémonte687d692009-01-04 13:11:54 -0800517 u.active_dev.crt = viafb_CRT_ON;
518 u.active_dev.dvi = viafb_DVI_ON;
519 u.active_dev.lcd = viafb_LCD_ON;
520 u.active_dev.samm = viafb_SAMM_ON;
521 u.active_dev.primary_dev = viafb_primary_dev;
Joseph Chan29b619f2008-10-15 22:03:27 -0700522
Bruno Prémonte687d692009-01-04 13:11:54 -0800523 u.active_dev.lcd_dsp_cent = viafb_lcd_dsp_method;
524 u.active_dev.lcd_panel_id = viafb_lcd_panel_id;
525 u.active_dev.lcd_mode = viafb_lcd_mode;
Joseph Chan29b619f2008-10-15 22:03:27 -0700526
Bruno Prémonte687d692009-01-04 13:11:54 -0800527 u.active_dev.xres = viafb_hotplug_Xres;
528 u.active_dev.yres = viafb_hotplug_Yres;
Joseph Chan29b619f2008-10-15 22:03:27 -0700529
Bruno Prémonte687d692009-01-04 13:11:54 -0800530 u.active_dev.xres1 = viafb_second_xres;
531 u.active_dev.yres1 = viafb_second_yres;
Joseph Chan29b619f2008-10-15 22:03:27 -0700532
Bruno Prémonte687d692009-01-04 13:11:54 -0800533 u.active_dev.bpp = viafb_bpp;
534 u.active_dev.bpp1 = viafb_bpp1;
535 u.active_dev.refresh = viafb_refresh;
536 u.active_dev.refresh1 = viafb_refresh1;
Joseph Chan29b619f2008-10-15 22:03:27 -0700537
Bruno Prémonte687d692009-01-04 13:11:54 -0800538 u.active_dev.epia_dvi = viafb_platform_epia_dvi;
539 u.active_dev.lcd_dual_edge = viafb_device_lcd_dualedge;
540 u.active_dev.bus_width = viafb_bus_width;
Joseph Chan29b619f2008-10-15 22:03:27 -0700541
Bruno Prémonte687d692009-01-04 13:11:54 -0800542 if (copy_to_user(argp, &u.active_dev, sizeof(u.active_dev)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700543 return -EFAULT;
544 break;
545
546 case VIAFB_GET_DRIVER_VERSION:
Bruno Prémonte687d692009-01-04 13:11:54 -0800547 u.driver_version.iMajorNum = VERSION_MAJOR;
548 u.driver_version.iKernelNum = VERSION_KERNEL;
549 u.driver_version.iOSNum = VERSION_OS;
550 u.driver_version.iMinorNum = VERSION_MINOR;
Joseph Chan29b619f2008-10-15 22:03:27 -0700551
Bruno Prémonte687d692009-01-04 13:11:54 -0800552 if (copy_to_user(argp, &u.driver_version,
553 sizeof(u.driver_version)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700554 return -EFAULT;
555
556 break;
557
Joseph Chan29b619f2008-10-15 22:03:27 -0700558 case VIAFB_GET_DEVICE_INFO:
559
Bruno Prémonte687d692009-01-04 13:11:54 -0800560 retrieve_device_setting(&u.viafb_setting);
Joseph Chan29b619f2008-10-15 22:03:27 -0700561
Bruno Prémonte687d692009-01-04 13:11:54 -0800562 if (copy_to_user(argp, &u.viafb_setting,
563 sizeof(u.viafb_setting)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700564 return -EFAULT;
565
566 break;
567
568 case VIAFB_GET_DEVICE_SUPPORT:
569 viafb_get_device_support_state(&state_info);
570 if (put_user(state_info, argp))
571 return -EFAULT;
572 break;
573
574 case VIAFB_GET_DEVICE_CONNECT:
575 viafb_get_device_connect_state(&state_info);
576 if (put_user(state_info, argp))
577 return -EFAULT;
578 break;
579
580 case VIAFB_GET_PANEL_SUPPORT_EXPAND:
581 state_info =
582 viafb_lcd_get_support_expand_state(info->var.xres,
583 info->var.yres);
584 if (put_user(state_info, argp))
585 return -EFAULT;
586 break;
587
588 case VIAFB_GET_DRIVER_NAME:
589 if (copy_to_user(argp, driver_name, sizeof(driver_name)))
590 return -EFAULT;
591 break;
592
593 case VIAFB_SET_GAMMA_LUT:
Julia Lawalla51faab2010-05-26 14:42:29 -0700594 viafb_gamma_table = memdup_user(argp, 256 * sizeof(u32));
595 if (IS_ERR(viafb_gamma_table))
596 return PTR_ERR(viafb_gamma_table);
Joseph Chan29b619f2008-10-15 22:03:27 -0700597 viafb_set_gamma_table(viafb_bpp, viafb_gamma_table);
598 kfree(viafb_gamma_table);
599 break;
600
601 case VIAFB_GET_GAMMA_LUT:
602 viafb_gamma_table = kmalloc(256 * sizeof(u32), GFP_KERNEL);
603 if (!viafb_gamma_table)
604 return -ENOMEM;
605 viafb_get_gamma_table(viafb_gamma_table);
606 if (copy_to_user(argp, viafb_gamma_table,
Julia Lawall0f050582009-12-17 15:27:09 -0800607 256 * sizeof(u32))) {
Joseph Chan29b619f2008-10-15 22:03:27 -0700608 kfree(viafb_gamma_table);
609 return -EFAULT;
610 }
611 kfree(viafb_gamma_table);
612 break;
613
614 case VIAFB_GET_GAMMA_SUPPORT_STATE:
615 viafb_get_gamma_support_state(viafb_bpp, &state_info);
616 if (put_user(state_info, argp))
617 return -EFAULT;
618 break;
Joseph Chan29b619f2008-10-15 22:03:27 -0700619 case VIAFB_SYNC_SURFACE:
620 DEBUG_MSG(KERN_INFO "lobo VIAFB_SYNC_SURFACE\n");
621 break;
622 case VIAFB_GET_DRIVER_CAPS:
623 break;
624
625 case VIAFB_GET_PANEL_MAX_SIZE:
Bruno Prémonte687d692009-01-04 13:11:54 -0800626 if (copy_from_user(&u.panel_pos_size_para, argp,
627 sizeof(u.panel_pos_size_para)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700628 return -EFAULT;
Bruno Prémonte687d692009-01-04 13:11:54 -0800629 u.panel_pos_size_para.x = u.panel_pos_size_para.y = 0;
630 if (copy_to_user(argp, &u.panel_pos_size_para,
631 sizeof(u.panel_pos_size_para)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700632 return -EFAULT;
633 break;
634 case VIAFB_GET_PANEL_MAX_POSITION:
Bruno Prémonte687d692009-01-04 13:11:54 -0800635 if (copy_from_user(&u.panel_pos_size_para, argp,
636 sizeof(u.panel_pos_size_para)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700637 return -EFAULT;
Bruno Prémonte687d692009-01-04 13:11:54 -0800638 u.panel_pos_size_para.x = u.panel_pos_size_para.y = 0;
639 if (copy_to_user(argp, &u.panel_pos_size_para,
640 sizeof(u.panel_pos_size_para)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700641 return -EFAULT;
642 break;
643
644 case VIAFB_GET_PANEL_POSITION:
Bruno Prémonte687d692009-01-04 13:11:54 -0800645 if (copy_from_user(&u.panel_pos_size_para, argp,
646 sizeof(u.panel_pos_size_para)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700647 return -EFAULT;
Bruno Prémonte687d692009-01-04 13:11:54 -0800648 u.panel_pos_size_para.x = u.panel_pos_size_para.y = 0;
649 if (copy_to_user(argp, &u.panel_pos_size_para,
650 sizeof(u.panel_pos_size_para)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700651 return -EFAULT;
652 break;
653 case VIAFB_GET_PANEL_SIZE:
Bruno Prémonte687d692009-01-04 13:11:54 -0800654 if (copy_from_user(&u.panel_pos_size_para, argp,
655 sizeof(u.panel_pos_size_para)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700656 return -EFAULT;
Bruno Prémonte687d692009-01-04 13:11:54 -0800657 u.panel_pos_size_para.x = u.panel_pos_size_para.y = 0;
658 if (copy_to_user(argp, &u.panel_pos_size_para,
659 sizeof(u.panel_pos_size_para)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700660 return -EFAULT;
661 break;
662
663 case VIAFB_SET_PANEL_POSITION:
Bruno Prémonte687d692009-01-04 13:11:54 -0800664 if (copy_from_user(&u.panel_pos_size_para, argp,
665 sizeof(u.panel_pos_size_para)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700666 return -EFAULT;
667 break;
668 case VIAFB_SET_PANEL_SIZE:
Bruno Prémonte687d692009-01-04 13:11:54 -0800669 if (copy_from_user(&u.panel_pos_size_para, argp,
670 sizeof(u.panel_pos_size_para)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700671 return -EFAULT;
672 break;
673
674 default:
675 return -EINVAL;
676 }
677
678 return 0;
679}
680
681static void viafb_fillrect(struct fb_info *info,
682 const struct fb_fillrect *rect)
683{
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700684 struct viafb_par *viapar = info->par;
Florian Tobias Schandinat31de59d2009-09-22 16:47:31 -0700685 struct viafb_shared *shared = viapar->shared;
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700686 u32 fg_color;
687 u8 rop;
Joseph Chan29b619f2008-10-15 22:03:27 -0700688
Florian Tobias Schandinat31de59d2009-09-22 16:47:31 -0700689 if (info->flags & FBINFO_HWACCEL_DISABLED || !shared->hw_bitblt) {
Hannes Eder2899bb02009-01-06 14:42:32 -0800690 cfb_fillrect(info, rect);
691 return;
692 }
Joseph Chan29b619f2008-10-15 22:03:27 -0700693
694 if (!rect->width || !rect->height)
695 return;
696
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700697 if (info->fix.visual == FB_VISUAL_TRUECOLOR)
698 fg_color = ((u32 *)info->pseudo_palette)[rect->color];
699 else
700 fg_color = rect->color;
701
702 if (rect->rop == ROP_XOR)
Joseph Chan29b619f2008-10-15 22:03:27 -0700703 rop = 0x5A;
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700704 else
Joseph Chan29b619f2008-10-15 22:03:27 -0700705 rop = 0xF0;
Joseph Chan29b619f2008-10-15 22:03:27 -0700706
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700707 DEBUG_MSG(KERN_DEBUG "viafb 2D engine: fillrect\n");
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600708 if (shared->hw_bitblt(shared->vdev->engine_mmio, VIA_BITBLT_FILL,
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700709 rect->width, rect->height, info->var.bits_per_pixel,
710 viapar->vram_addr, info->fix.line_length, rect->dx, rect->dy,
711 NULL, 0, 0, 0, 0, fg_color, 0, rop))
712 cfb_fillrect(info, rect);
Joseph Chan29b619f2008-10-15 22:03:27 -0700713}
714
715static void viafb_copyarea(struct fb_info *info,
716 const struct fb_copyarea *area)
717{
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700718 struct viafb_par *viapar = info->par;
Florian Tobias Schandinat31de59d2009-09-22 16:47:31 -0700719 struct viafb_shared *shared = viapar->shared;
Joseph Chan29b619f2008-10-15 22:03:27 -0700720
Florian Tobias Schandinat31de59d2009-09-22 16:47:31 -0700721 if (info->flags & FBINFO_HWACCEL_DISABLED || !shared->hw_bitblt) {
Hannes Eder2899bb02009-01-06 14:42:32 -0800722 cfb_copyarea(info, area);
723 return;
724 }
Joseph Chan29b619f2008-10-15 22:03:27 -0700725
726 if (!area->width || !area->height)
727 return;
728
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700729 DEBUG_MSG(KERN_DEBUG "viafb 2D engine: copyarea\n");
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600730 if (shared->hw_bitblt(shared->vdev->engine_mmio, VIA_BITBLT_COLOR,
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700731 area->width, area->height, info->var.bits_per_pixel,
732 viapar->vram_addr, info->fix.line_length, area->dx, area->dy,
733 NULL, viapar->vram_addr, info->fix.line_length,
734 area->sx, area->sy, 0, 0, 0))
735 cfb_copyarea(info, area);
Joseph Chan29b619f2008-10-15 22:03:27 -0700736}
737
738static void viafb_imageblit(struct fb_info *info,
739 const struct fb_image *image)
740{
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700741 struct viafb_par *viapar = info->par;
Florian Tobias Schandinat31de59d2009-09-22 16:47:31 -0700742 struct viafb_shared *shared = viapar->shared;
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700743 u32 fg_color = 0, bg_color = 0;
744 u8 op;
Joseph Chan29b619f2008-10-15 22:03:27 -0700745
Florian Tobias Schandinat31de59d2009-09-22 16:47:31 -0700746 if (info->flags & FBINFO_HWACCEL_DISABLED || !shared->hw_bitblt ||
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700747 (image->depth != 1 && image->depth != viapar->depth)) {
Hannes Eder2899bb02009-01-06 14:42:32 -0800748 cfb_imageblit(info, image);
749 return;
750 }
Joseph Chan29b619f2008-10-15 22:03:27 -0700751
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700752 if (image->depth == 1) {
753 op = VIA_BITBLT_MONO;
754 if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
755 fg_color =
756 ((u32 *)info->pseudo_palette)[image->fg_color];
757 bg_color =
758 ((u32 *)info->pseudo_palette)[image->bg_color];
759 } else {
760 fg_color = image->fg_color;
761 bg_color = image->bg_color;
762 }
763 } else
764 op = VIA_BITBLT_COLOR;
Joseph Chan29b619f2008-10-15 22:03:27 -0700765
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700766 DEBUG_MSG(KERN_DEBUG "viafb 2D engine: imageblit\n");
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600767 if (shared->hw_bitblt(shared->vdev->engine_mmio, op,
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700768 image->width, image->height, info->var.bits_per_pixel,
769 viapar->vram_addr, info->fix.line_length, image->dx, image->dy,
770 (u32 *)image->data, 0, 0, 0, 0, fg_color, bg_color, 0))
771 cfb_imageblit(info, image);
Joseph Chan29b619f2008-10-15 22:03:27 -0700772}
773
774static int viafb_cursor(struct fb_info *info, struct fb_cursor *cursor)
775{
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700776 struct viafb_par *viapar = info->par;
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600777 void __iomem *engine = viapar->shared->vdev->engine_mmio;
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700778 u32 temp, xx, yy, bg_color = 0, fg_color = 0,
779 chip_name = viapar->shared->chip_info.gfx_chip_name;
780 int i, j = 0, cur_size = 64;
Joseph Chan29b619f2008-10-15 22:03:27 -0700781
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700782 if (info->flags & FBINFO_HWACCEL_DISABLED || info != viafbinfo)
Joseph Chan29b619f2008-10-15 22:03:27 -0700783 return -ENODEV;
784
Florian Tobias Schandinat0b941902010-01-15 17:01:03 -0800785 /* LCD ouput does not support hw cursors (at least on VN896) */
786 if ((chip_name == UNICHROME_CLE266 && viapar->iga_path == IGA2) ||
787 viafb_LCD_ON)
Joseph Chan29b619f2008-10-15 22:03:27 -0700788 return -ENODEV;
789
790 viafb_show_hw_cursor(info, HW_Cursor_OFF);
Joseph Chan29b619f2008-10-15 22:03:27 -0700791
792 if (cursor->set & FB_CUR_SETHOT) {
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700793 temp = (cursor->hot.x << 16) + cursor->hot.y;
Florian Tobias Schandinat31de59d2009-09-22 16:47:31 -0700794 writel(temp, engine + VIA_REG_CURSOR_ORG);
Joseph Chan29b619f2008-10-15 22:03:27 -0700795 }
796
797 if (cursor->set & FB_CUR_SETPOS) {
Joseph Chan29b619f2008-10-15 22:03:27 -0700798 yy = cursor->image.dy - info->var.yoffset;
799 xx = cursor->image.dx - info->var.xoffset;
800 temp = yy & 0xFFFF;
801 temp |= (xx << 16);
Florian Tobias Schandinat31de59d2009-09-22 16:47:31 -0700802 writel(temp, engine + VIA_REG_CURSOR_POS);
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700803 }
804
805 if (cursor->image.width <= 32 && cursor->image.height <= 32)
806 cur_size = 32;
807 else if (cursor->image.width <= 64 && cursor->image.height <= 64)
808 cur_size = 64;
809 else {
810 printk(KERN_WARNING "viafb_cursor: The cursor is too large "
811 "%dx%d", cursor->image.width, cursor->image.height);
812 return -ENXIO;
Joseph Chan29b619f2008-10-15 22:03:27 -0700813 }
814
815 if (cursor->set & FB_CUR_SETSIZE) {
Florian Tobias Schandinat31de59d2009-09-22 16:47:31 -0700816 temp = readl(engine + VIA_REG_CURSOR_MODE);
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700817 if (cur_size == 32)
Joseph Chan29b619f2008-10-15 22:03:27 -0700818 temp |= 0x2;
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700819 else
820 temp &= ~0x2;
Joseph Chan29b619f2008-10-15 22:03:27 -0700821
Florian Tobias Schandinat31de59d2009-09-22 16:47:31 -0700822 writel(temp, engine + VIA_REG_CURSOR_MODE);
Joseph Chan29b619f2008-10-15 22:03:27 -0700823 }
824
825 if (cursor->set & FB_CUR_SETCMAP) {
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700826 fg_color = cursor->image.fg_color;
827 bg_color = cursor->image.bg_color;
828 if (chip_name == UNICHROME_CX700 ||
Harald Welte0306ab12009-09-22 16:47:35 -0700829 chip_name == UNICHROME_VX800 ||
Florian Tobias Schandinat51f43322010-10-24 04:02:14 +0000830 chip_name == UNICHROME_VX855 ||
831 chip_name == UNICHROME_VX900) {
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700832 fg_color =
833 ((info->cmap.red[fg_color] & 0xFFC0) << 14) |
834 ((info->cmap.green[fg_color] & 0xFFC0) << 4) |
835 ((info->cmap.blue[fg_color] & 0xFFC0) >> 6);
836 bg_color =
837 ((info->cmap.red[bg_color] & 0xFFC0) << 14) |
838 ((info->cmap.green[bg_color] & 0xFFC0) << 4) |
839 ((info->cmap.blue[bg_color] & 0xFFC0) >> 6);
840 } else {
841 fg_color =
842 ((info->cmap.red[fg_color] & 0xFF00) << 8) |
843 (info->cmap.green[fg_color] & 0xFF00) |
844 ((info->cmap.blue[fg_color] & 0xFF00) >> 8);
845 bg_color =
846 ((info->cmap.red[bg_color] & 0xFF00) << 8) |
847 (info->cmap.green[bg_color] & 0xFF00) |
848 ((info->cmap.blue[bg_color] & 0xFF00) >> 8);
Joseph Chan29b619f2008-10-15 22:03:27 -0700849 }
850
Florian Tobias Schandinat31de59d2009-09-22 16:47:31 -0700851 writel(bg_color, engine + VIA_REG_CURSOR_BG);
852 writel(fg_color, engine + VIA_REG_CURSOR_FG);
Joseph Chan29b619f2008-10-15 22:03:27 -0700853 }
854
855 if (cursor->set & FB_CUR_SETSHAPE) {
Bruno Prémonte687d692009-01-04 13:11:54 -0800856 struct {
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700857 u8 data[CURSOR_SIZE];
858 u32 bak[CURSOR_SIZE / 4];
Bruno Prémonte687d692009-01-04 13:11:54 -0800859 } *cr_data = kzalloc(sizeof(*cr_data), GFP_ATOMIC);
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700860 int size = ((cursor->image.width + 7) >> 3) *
861 cursor->image.height;
Joseph Chan29b619f2008-10-15 22:03:27 -0700862
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700863 if (!cr_data)
864 return -ENOMEM;
Bruno Prémonte687d692009-01-04 13:11:54 -0800865
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700866 if (cur_size == 32) {
867 for (i = 0; i < (CURSOR_SIZE / 4); i++) {
Bruno Prémonte687d692009-01-04 13:11:54 -0800868 cr_data->bak[i] = 0x0;
869 cr_data->bak[i + 1] = 0xFFFFFFFF;
Joseph Chan29b619f2008-10-15 22:03:27 -0700870 i += 1;
871 }
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700872 } else {
873 for (i = 0; i < (CURSOR_SIZE / 4); i++) {
Bruno Prémonte687d692009-01-04 13:11:54 -0800874 cr_data->bak[i] = 0x0;
875 cr_data->bak[i + 1] = 0x0;
876 cr_data->bak[i + 2] = 0xFFFFFFFF;
877 cr_data->bak[i + 3] = 0xFFFFFFFF;
Joseph Chan29b619f2008-10-15 22:03:27 -0700878 i += 3;
879 }
880 }
881
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700882 switch (cursor->rop) {
Joseph Chan29b619f2008-10-15 22:03:27 -0700883 case ROP_XOR:
884 for (i = 0; i < size; i++)
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700885 cr_data->data[i] = cursor->mask[i];
Joseph Chan29b619f2008-10-15 22:03:27 -0700886 break;
887 case ROP_COPY:
888
889 for (i = 0; i < size; i++)
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700890 cr_data->data[i] = cursor->mask[i];
Joseph Chan29b619f2008-10-15 22:03:27 -0700891 break;
892 default:
893 break;
894 }
895
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700896 if (cur_size == 32) {
Joseph Chan29b619f2008-10-15 22:03:27 -0700897 for (i = 0; i < size; i++) {
Bruno Prémonte687d692009-01-04 13:11:54 -0800898 cr_data->bak[j] = (u32) cr_data->data[i];
899 cr_data->bak[j + 1] = ~cr_data->bak[j];
Joseph Chan29b619f2008-10-15 22:03:27 -0700900 j += 2;
901 }
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700902 } else {
Joseph Chan29b619f2008-10-15 22:03:27 -0700903 for (i = 0; i < size; i++) {
Bruno Prémonte687d692009-01-04 13:11:54 -0800904 cr_data->bak[j] = (u32) cr_data->data[i];
905 cr_data->bak[j + 1] = 0x0;
906 cr_data->bak[j + 2] = ~cr_data->bak[j];
907 cr_data->bak[j + 3] = ~cr_data->bak[j + 1];
Joseph Chan29b619f2008-10-15 22:03:27 -0700908 j += 4;
909 }
910 }
911
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700912 memcpy_toio(viafbinfo->screen_base + viapar->shared->
913 cursor_vram_addr, cr_data->bak, CURSOR_SIZE);
Bruno Prémonte687d692009-01-04 13:11:54 -0800914 kfree(cr_data);
Joseph Chan29b619f2008-10-15 22:03:27 -0700915 }
916
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700917 if (cursor->enable)
Joseph Chan29b619f2008-10-15 22:03:27 -0700918 viafb_show_hw_cursor(info, HW_Cursor_ON);
919
920 return 0;
921}
922
923static int viafb_sync(struct fb_info *info)
924{
Florian Tobias Schandinat31de59d2009-09-22 16:47:31 -0700925 if (!(info->flags & FBINFO_HWACCEL_DISABLED))
926 viafb_wait_engine_idle(info);
Joseph Chan29b619f2008-10-15 22:03:27 -0700927 return 0;
928}
929
Joseph Chan29b619f2008-10-15 22:03:27 -0700930static int get_primary_device(void)
931{
932 int primary_device = 0;
933 /* Rule: device on iga1 path are the primary device. */
934 if (viafb_SAMM_ON) {
935 if (viafb_CRT_ON) {
Florian Tobias Schandinat05236562011-03-21 01:46:24 +0000936 if (viaparinfo->shared->iga1_devices & VIA_CRT) {
937 DEBUG_MSG(KERN_INFO "CRT IGA Path:%d\n", IGA1);
Joseph Chan29b619f2008-10-15 22:03:27 -0700938 primary_device = CRT_Device;
939 }
940 }
941 if (viafb_DVI_ON) {
942 if (viaparinfo->tmds_setting_info->iga_path == IGA1) {
943 DEBUG_MSG(KERN_INFO "DVI IGA Path:%d\n",
944 viaparinfo->
945 tmds_setting_info->iga_path);
946 primary_device = DVI_Device;
947 }
948 }
949 if (viafb_LCD_ON) {
950 if (viaparinfo->lvds_setting_info->iga_path == IGA1) {
951 DEBUG_MSG(KERN_INFO "LCD IGA Path:%d\n",
952 viaparinfo->
953 lvds_setting_info->iga_path);
954 primary_device = LCD_Device;
955 }
956 }
957 if (viafb_LCD2_ON) {
958 if (viaparinfo->lvds_setting_info2->iga_path == IGA1) {
959 DEBUG_MSG(KERN_INFO "LCD2 IGA Path:%d\n",
960 viaparinfo->
961 lvds_setting_info2->iga_path);
962 primary_device = LCD2_Device;
963 }
964 }
965 }
966 return primary_device;
967}
968
Joseph Chan29b619f2008-10-15 22:03:27 -0700969static void retrieve_device_setting(struct viafb_ioctl_setting
970 *setting_info)
971{
972
973 /* get device status */
974 if (viafb_CRT_ON == 1)
975 setting_info->device_status = CRT_Device;
976 if (viafb_DVI_ON == 1)
977 setting_info->device_status |= DVI_Device;
978 if (viafb_LCD_ON == 1)
979 setting_info->device_status |= LCD_Device;
980 if (viafb_LCD2_ON == 1)
981 setting_info->device_status |= LCD2_Device;
Joseph Chan29b619f2008-10-15 22:03:27 -0700982
983 setting_info->samm_status = viafb_SAMM_ON;
984 setting_info->primary_device = get_primary_device();
985
986 setting_info->first_dev_bpp = viafb_bpp;
987 setting_info->second_dev_bpp = viafb_bpp1;
988
989 setting_info->first_dev_refresh = viafb_refresh;
990 setting_info->second_dev_refresh = viafb_refresh1;
991
992 setting_info->first_dev_hor_res = viafb_hotplug_Xres;
993 setting_info->first_dev_ver_res = viafb_hotplug_Yres;
994 setting_info->second_dev_hor_res = viafb_second_xres;
995 setting_info->second_dev_ver_res = viafb_second_yres;
996
997 /* Get lcd attributes */
998 setting_info->lcd_attributes.display_center = viafb_lcd_dsp_method;
999 setting_info->lcd_attributes.panel_id = viafb_lcd_panel_id;
1000 setting_info->lcd_attributes.lcd_mode = viafb_lcd_mode;
1001}
1002
Florian Tobias Schandinatf4ab2f7a2010-08-09 01:34:27 +00001003static int __init parse_active_dev(void)
Joseph Chan29b619f2008-10-15 22:03:27 -07001004{
1005 viafb_CRT_ON = STATE_OFF;
1006 viafb_DVI_ON = STATE_OFF;
1007 viafb_LCD_ON = STATE_OFF;
1008 viafb_LCD2_ON = STATE_OFF;
1009 /* 1. Modify the active status of devices. */
1010 /* 2. Keep the order of devices, so we can set corresponding
1011 IGA path to devices in SAMM case. */
1012 /* Note: The previous of active_dev is primary device,
1013 and the following is secondary device. */
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001014 if (!viafb_active_dev) {
Daniel Drake8aa4d962011-05-10 22:34:11 +01001015 if (machine_is_olpc()) { /* LCD only */
1016 viafb_LCD_ON = STATE_ON;
1017 viafb_SAMM_ON = STATE_OFF;
1018 } else {
1019 viafb_CRT_ON = STATE_ON;
1020 viafb_SAMM_ON = STATE_OFF;
1021 }
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001022 } else if (!strcmp(viafb_active_dev, "CRT+DVI")) {
Joseph Chan29b619f2008-10-15 22:03:27 -07001023 /* CRT+DVI */
1024 viafb_CRT_ON = STATE_ON;
1025 viafb_DVI_ON = STATE_ON;
1026 viafb_primary_dev = CRT_Device;
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001027 } else if (!strcmp(viafb_active_dev, "DVI+CRT")) {
Joseph Chan29b619f2008-10-15 22:03:27 -07001028 /* DVI+CRT */
1029 viafb_CRT_ON = STATE_ON;
1030 viafb_DVI_ON = STATE_ON;
1031 viafb_primary_dev = DVI_Device;
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001032 } else if (!strcmp(viafb_active_dev, "CRT+LCD")) {
Joseph Chan29b619f2008-10-15 22:03:27 -07001033 /* CRT+LCD */
1034 viafb_CRT_ON = STATE_ON;
1035 viafb_LCD_ON = STATE_ON;
1036 viafb_primary_dev = CRT_Device;
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001037 } else if (!strcmp(viafb_active_dev, "LCD+CRT")) {
Joseph Chan29b619f2008-10-15 22:03:27 -07001038 /* LCD+CRT */
1039 viafb_CRT_ON = STATE_ON;
1040 viafb_LCD_ON = STATE_ON;
1041 viafb_primary_dev = LCD_Device;
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001042 } else if (!strcmp(viafb_active_dev, "DVI+LCD")) {
Joseph Chan29b619f2008-10-15 22:03:27 -07001043 /* DVI+LCD */
1044 viafb_DVI_ON = STATE_ON;
1045 viafb_LCD_ON = STATE_ON;
1046 viafb_primary_dev = DVI_Device;
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001047 } else if (!strcmp(viafb_active_dev, "LCD+DVI")) {
Joseph Chan29b619f2008-10-15 22:03:27 -07001048 /* LCD+DVI */
1049 viafb_DVI_ON = STATE_ON;
1050 viafb_LCD_ON = STATE_ON;
1051 viafb_primary_dev = LCD_Device;
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001052 } else if (!strcmp(viafb_active_dev, "LCD+LCD2")) {
Joseph Chan29b619f2008-10-15 22:03:27 -07001053 viafb_LCD_ON = STATE_ON;
1054 viafb_LCD2_ON = STATE_ON;
1055 viafb_primary_dev = LCD_Device;
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001056 } else if (!strcmp(viafb_active_dev, "LCD2+LCD")) {
Joseph Chan29b619f2008-10-15 22:03:27 -07001057 viafb_LCD_ON = STATE_ON;
1058 viafb_LCD2_ON = STATE_ON;
1059 viafb_primary_dev = LCD2_Device;
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001060 } else if (!strcmp(viafb_active_dev, "CRT")) {
Joseph Chan29b619f2008-10-15 22:03:27 -07001061 /* CRT only */
1062 viafb_CRT_ON = STATE_ON;
1063 viafb_SAMM_ON = STATE_OFF;
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001064 } else if (!strcmp(viafb_active_dev, "DVI")) {
Joseph Chan29b619f2008-10-15 22:03:27 -07001065 /* DVI only */
1066 viafb_DVI_ON = STATE_ON;
1067 viafb_SAMM_ON = STATE_OFF;
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001068 } else if (!strcmp(viafb_active_dev, "LCD")) {
Joseph Chan29b619f2008-10-15 22:03:27 -07001069 /* LCD only */
1070 viafb_LCD_ON = STATE_ON;
1071 viafb_SAMM_ON = STATE_OFF;
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001072 } else
1073 return -EINVAL;
1074
1075 return 0;
Joseph Chan29b619f2008-10-15 22:03:27 -07001076}
1077
Florian Tobias Schandinatf4ab2f7a2010-08-09 01:34:27 +00001078static int __devinit parse_port(char *opt_str, int *output_interface)
Joseph Chan29b619f2008-10-15 22:03:27 -07001079{
1080 if (!strncmp(opt_str, "DVP0", 4))
1081 *output_interface = INTERFACE_DVP0;
1082 else if (!strncmp(opt_str, "DVP1", 4))
1083 *output_interface = INTERFACE_DVP1;
1084 else if (!strncmp(opt_str, "DFP_HIGHLOW", 11))
1085 *output_interface = INTERFACE_DFP;
1086 else if (!strncmp(opt_str, "DFP_HIGH", 8))
1087 *output_interface = INTERFACE_DFP_HIGH;
1088 else if (!strncmp(opt_str, "DFP_LOW", 7))
1089 *output_interface = INTERFACE_DFP_LOW;
1090 else
1091 *output_interface = INTERFACE_NONE;
1092 return 0;
1093}
1094
Florian Tobias Schandinatf4ab2f7a2010-08-09 01:34:27 +00001095static void __devinit parse_lcd_port(void)
Joseph Chan29b619f2008-10-15 22:03:27 -07001096{
1097 parse_port(viafb_lcd_port, &viaparinfo->chip_info->lvds_chip_info.
1098 output_interface);
1099 /*Initialize to avoid unexpected behavior */
1100 viaparinfo->chip_info->lvds_chip_info2.output_interface =
1101 INTERFACE_NONE;
1102
1103 DEBUG_MSG(KERN_INFO "parse_lcd_port: viafb_lcd_port:%s,interface:%d\n",
1104 viafb_lcd_port, viaparinfo->chip_info->lvds_chip_info.
1105 output_interface);
1106}
1107
Florian Tobias Schandinatf4ab2f7a2010-08-09 01:34:27 +00001108static void __devinit parse_dvi_port(void)
Joseph Chan29b619f2008-10-15 22:03:27 -07001109{
1110 parse_port(viafb_dvi_port, &viaparinfo->chip_info->tmds_chip_info.
1111 output_interface);
1112
1113 DEBUG_MSG(KERN_INFO "parse_dvi_port: viafb_dvi_port:%s,interface:%d\n",
1114 viafb_dvi_port, viaparinfo->chip_info->tmds_chip_info.
1115 output_interface);
1116}
1117
Florian Tobias Schandinat2b78a962010-04-17 19:44:57 +00001118#ifdef CONFIG_FB_VIA_DIRECT_PROCFS
1119
Joseph Chan29b619f2008-10-15 22:03:27 -07001120/*
1121 * The proc filesystem read/write function, a simple proc implement to
1122 * get/set the value of DPA DVP0, DVP0DataDriving, DVP0ClockDriving, DVP1,
1123 * DVP1Driving, DFPHigh, DFPLow CR96, SR2A[5], SR1B[1], SR2A[4], SR1E[2],
1124 * CR9B, SR65, CR97, CR99
1125 */
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001126static int viafb_dvp0_proc_show(struct seq_file *m, void *v)
Joseph Chan29b619f2008-10-15 22:03:27 -07001127{
Joseph Chan29b619f2008-10-15 22:03:27 -07001128 u8 dvp0_data_dri = 0, dvp0_clk_dri = 0, dvp0 = 0;
1129 dvp0_data_dri =
1130 (viafb_read_reg(VIASR, SR2A) & BIT5) >> 4 |
1131 (viafb_read_reg(VIASR, SR1B) & BIT1) >> 1;
1132 dvp0_clk_dri =
1133 (viafb_read_reg(VIASR, SR2A) & BIT4) >> 3 |
1134 (viafb_read_reg(VIASR, SR1E) & BIT2) >> 2;
1135 dvp0 = viafb_read_reg(VIACR, CR96) & 0x0f;
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001136 seq_printf(m, "%x %x %x\n", dvp0, dvp0_data_dri, dvp0_clk_dri);
1137 return 0;
Joseph Chan29b619f2008-10-15 22:03:27 -07001138}
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001139
1140static int viafb_dvp0_proc_open(struct inode *inode, struct file *file)
1141{
1142 return single_open(file, viafb_dvp0_proc_show, NULL);
1143}
1144
1145static ssize_t viafb_dvp0_proc_write(struct file *file,
1146 const char __user *buffer, size_t count, loff_t *pos)
Joseph Chan29b619f2008-10-15 22:03:27 -07001147{
1148 char buf[20], *value, *pbuf;
1149 u8 reg_val = 0;
1150 unsigned long length, i;
1151 if (count < 1)
1152 return -EINVAL;
1153 length = count > 20 ? 20 : count;
1154 if (copy_from_user(&buf[0], buffer, length))
1155 return -EFAULT;
1156 buf[length - 1] = '\0'; /*Ensure end string */
1157 pbuf = &buf[0];
1158 for (i = 0; i < 3; i++) {
1159 value = strsep(&pbuf, " ");
1160 if (value != NULL) {
Wang Shaoyan4ce36bb2011-08-08 10:18:15 +08001161 if (kstrtou8(value, 0, &reg_val) < 0)
1162 return -EINVAL;
Joseph Chan29b619f2008-10-15 22:03:27 -07001163 DEBUG_MSG(KERN_INFO "DVP0:reg_val[%l]=:%x\n", i,
1164 reg_val);
1165 switch (i) {
1166 case 0:
1167 viafb_write_reg_mask(CR96, VIACR,
1168 reg_val, 0x0f);
1169 break;
1170 case 1:
1171 viafb_write_reg_mask(SR2A, VIASR,
1172 reg_val << 4, BIT5);
1173 viafb_write_reg_mask(SR1B, VIASR,
1174 reg_val << 1, BIT1);
1175 break;
1176 case 2:
1177 viafb_write_reg_mask(SR2A, VIASR,
1178 reg_val << 3, BIT4);
1179 viafb_write_reg_mask(SR1E, VIASR,
1180 reg_val << 2, BIT2);
1181 break;
1182 default:
1183 break;
1184 }
1185 } else {
1186 break;
1187 }
1188 }
1189 return count;
1190}
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001191
1192static const struct file_operations viafb_dvp0_proc_fops = {
1193 .owner = THIS_MODULE,
1194 .open = viafb_dvp0_proc_open,
1195 .read = seq_read,
1196 .llseek = seq_lseek,
1197 .release = single_release,
1198 .write = viafb_dvp0_proc_write,
1199};
1200
1201static int viafb_dvp1_proc_show(struct seq_file *m, void *v)
Joseph Chan29b619f2008-10-15 22:03:27 -07001202{
Joseph Chan29b619f2008-10-15 22:03:27 -07001203 u8 dvp1 = 0, dvp1_data_dri = 0, dvp1_clk_dri = 0;
1204 dvp1 = viafb_read_reg(VIACR, CR9B) & 0x0f;
1205 dvp1_data_dri = (viafb_read_reg(VIASR, SR65) & 0x0c) >> 2;
1206 dvp1_clk_dri = viafb_read_reg(VIASR, SR65) & 0x03;
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001207 seq_printf(m, "%x %x %x\n", dvp1, dvp1_data_dri, dvp1_clk_dri);
1208 return 0;
Joseph Chan29b619f2008-10-15 22:03:27 -07001209}
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001210
1211static int viafb_dvp1_proc_open(struct inode *inode, struct file *file)
1212{
1213 return single_open(file, viafb_dvp1_proc_show, NULL);
1214}
1215
1216static ssize_t viafb_dvp1_proc_write(struct file *file,
1217 const char __user *buffer, size_t count, loff_t *pos)
Joseph Chan29b619f2008-10-15 22:03:27 -07001218{
1219 char buf[20], *value, *pbuf;
1220 u8 reg_val = 0;
1221 unsigned long length, i;
1222 if (count < 1)
1223 return -EINVAL;
1224 length = count > 20 ? 20 : count;
1225 if (copy_from_user(&buf[0], buffer, length))
1226 return -EFAULT;
1227 buf[length - 1] = '\0'; /*Ensure end string */
1228 pbuf = &buf[0];
1229 for (i = 0; i < 3; i++) {
1230 value = strsep(&pbuf, " ");
1231 if (value != NULL) {
Wang Shaoyan4ce36bb2011-08-08 10:18:15 +08001232 if (kstrtou8(value, 0, &reg_val) < 0)
1233 return -EINVAL;
Joseph Chan29b619f2008-10-15 22:03:27 -07001234 switch (i) {
1235 case 0:
1236 viafb_write_reg_mask(CR9B, VIACR,
1237 reg_val, 0x0f);
1238 break;
1239 case 1:
1240 viafb_write_reg_mask(SR65, VIASR,
1241 reg_val << 2, 0x0c);
1242 break;
1243 case 2:
1244 viafb_write_reg_mask(SR65, VIASR,
1245 reg_val, 0x03);
1246 break;
1247 default:
1248 break;
1249 }
1250 } else {
1251 break;
1252 }
1253 }
1254 return count;
1255}
1256
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001257static const struct file_operations viafb_dvp1_proc_fops = {
1258 .owner = THIS_MODULE,
1259 .open = viafb_dvp1_proc_open,
1260 .read = seq_read,
1261 .llseek = seq_lseek,
1262 .release = single_release,
1263 .write = viafb_dvp1_proc_write,
1264};
1265
1266static int viafb_dfph_proc_show(struct seq_file *m, void *v)
Joseph Chan29b619f2008-10-15 22:03:27 -07001267{
Joseph Chan29b619f2008-10-15 22:03:27 -07001268 u8 dfp_high = 0;
1269 dfp_high = viafb_read_reg(VIACR, CR97) & 0x0f;
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001270 seq_printf(m, "%x\n", dfp_high);
1271 return 0;
Joseph Chan29b619f2008-10-15 22:03:27 -07001272}
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001273
1274static int viafb_dfph_proc_open(struct inode *inode, struct file *file)
1275{
1276 return single_open(file, viafb_dfph_proc_show, NULL);
1277}
1278
1279static ssize_t viafb_dfph_proc_write(struct file *file,
1280 const char __user *buffer, size_t count, loff_t *pos)
Joseph Chan29b619f2008-10-15 22:03:27 -07001281{
1282 char buf[20];
1283 u8 reg_val = 0;
1284 unsigned long length;
1285 if (count < 1)
1286 return -EINVAL;
1287 length = count > 20 ? 20 : count;
1288 if (copy_from_user(&buf[0], buffer, length))
1289 return -EFAULT;
1290 buf[length - 1] = '\0'; /*Ensure end string */
Wang Shaoyan4ce36bb2011-08-08 10:18:15 +08001291 if (kstrtou8(buf, 0, &reg_val) < 0)
1292 return -EINVAL;
Joseph Chan29b619f2008-10-15 22:03:27 -07001293 viafb_write_reg_mask(CR97, VIACR, reg_val, 0x0f);
1294 return count;
1295}
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001296
1297static const struct file_operations viafb_dfph_proc_fops = {
1298 .owner = THIS_MODULE,
1299 .open = viafb_dfph_proc_open,
1300 .read = seq_read,
1301 .llseek = seq_lseek,
1302 .release = single_release,
1303 .write = viafb_dfph_proc_write,
1304};
1305
1306static int viafb_dfpl_proc_show(struct seq_file *m, void *v)
Joseph Chan29b619f2008-10-15 22:03:27 -07001307{
Joseph Chan29b619f2008-10-15 22:03:27 -07001308 u8 dfp_low = 0;
1309 dfp_low = viafb_read_reg(VIACR, CR99) & 0x0f;
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001310 seq_printf(m, "%x\n", dfp_low);
1311 return 0;
Joseph Chan29b619f2008-10-15 22:03:27 -07001312}
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001313
1314static int viafb_dfpl_proc_open(struct inode *inode, struct file *file)
1315{
1316 return single_open(file, viafb_dfpl_proc_show, NULL);
1317}
1318
1319static ssize_t viafb_dfpl_proc_write(struct file *file,
1320 const char __user *buffer, size_t count, loff_t *pos)
Joseph Chan29b619f2008-10-15 22:03:27 -07001321{
1322 char buf[20];
1323 u8 reg_val = 0;
1324 unsigned long length;
1325 if (count < 1)
1326 return -EINVAL;
1327 length = count > 20 ? 20 : count;
1328 if (copy_from_user(&buf[0], buffer, length))
1329 return -EFAULT;
1330 buf[length - 1] = '\0'; /*Ensure end string */
Wang Shaoyan4ce36bb2011-08-08 10:18:15 +08001331 if (kstrtou8(buf, 0, &reg_val) < 0)
1332 return -EINVAL;
Joseph Chan29b619f2008-10-15 22:03:27 -07001333 viafb_write_reg_mask(CR99, VIACR, reg_val, 0x0f);
1334 return count;
1335}
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001336
1337static const struct file_operations viafb_dfpl_proc_fops = {
1338 .owner = THIS_MODULE,
1339 .open = viafb_dfpl_proc_open,
1340 .read = seq_read,
1341 .llseek = seq_lseek,
1342 .release = single_release,
1343 .write = viafb_dfpl_proc_write,
1344};
1345
1346static int viafb_vt1636_proc_show(struct seq_file *m, void *v)
Joseph Chan29b619f2008-10-15 22:03:27 -07001347{
Joseph Chan29b619f2008-10-15 22:03:27 -07001348 u8 vt1636_08 = 0, vt1636_09 = 0;
1349 switch (viaparinfo->chip_info->lvds_chip_info.lvds_chip_name) {
1350 case VT1636_LVDS:
1351 vt1636_08 =
1352 viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info,
1353 &viaparinfo->chip_info->lvds_chip_info, 0x08) & 0x0f;
1354 vt1636_09 =
1355 viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info,
1356 &viaparinfo->chip_info->lvds_chip_info, 0x09) & 0x1f;
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001357 seq_printf(m, "%x %x\n", vt1636_08, vt1636_09);
Joseph Chan29b619f2008-10-15 22:03:27 -07001358 break;
1359 default:
1360 break;
1361 }
1362 switch (viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name) {
1363 case VT1636_LVDS:
1364 vt1636_08 =
1365 viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info2,
1366 &viaparinfo->chip_info->lvds_chip_info2, 0x08) & 0x0f;
1367 vt1636_09 =
1368 viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info2,
1369 &viaparinfo->chip_info->lvds_chip_info2, 0x09) & 0x1f;
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001370 seq_printf(m, " %x %x\n", vt1636_08, vt1636_09);
Joseph Chan29b619f2008-10-15 22:03:27 -07001371 break;
1372 default:
1373 break;
1374 }
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001375 return 0;
Joseph Chan29b619f2008-10-15 22:03:27 -07001376}
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001377
1378static int viafb_vt1636_proc_open(struct inode *inode, struct file *file)
1379{
1380 return single_open(file, viafb_vt1636_proc_show, NULL);
1381}
1382
1383static ssize_t viafb_vt1636_proc_write(struct file *file,
1384 const char __user *buffer, size_t count, loff_t *pos)
Joseph Chan29b619f2008-10-15 22:03:27 -07001385{
1386 char buf[30], *value, *pbuf;
1387 struct IODATA reg_val;
1388 unsigned long length, i;
1389 if (count < 1)
1390 return -EINVAL;
1391 length = count > 30 ? 30 : count;
1392 if (copy_from_user(&buf[0], buffer, length))
1393 return -EFAULT;
1394 buf[length - 1] = '\0'; /*Ensure end string */
1395 pbuf = &buf[0];
1396 switch (viaparinfo->chip_info->lvds_chip_info.lvds_chip_name) {
1397 case VT1636_LVDS:
1398 for (i = 0; i < 2; i++) {
1399 value = strsep(&pbuf, " ");
1400 if (value != NULL) {
Wang Shaoyan4ce36bb2011-08-08 10:18:15 +08001401 if (kstrtou8(value, 0, &reg_val.Data) < 0)
1402 return -EINVAL;
Joseph Chan29b619f2008-10-15 22:03:27 -07001403 switch (i) {
1404 case 0:
1405 reg_val.Index = 0x08;
1406 reg_val.Mask = 0x0f;
1407 viafb_gpio_i2c_write_mask_lvds
1408 (viaparinfo->lvds_setting_info,
1409 &viaparinfo->
1410 chip_info->lvds_chip_info,
1411 reg_val);
1412 break;
1413 case 1:
1414 reg_val.Index = 0x09;
1415 reg_val.Mask = 0x1f;
1416 viafb_gpio_i2c_write_mask_lvds
1417 (viaparinfo->lvds_setting_info,
1418 &viaparinfo->
1419 chip_info->lvds_chip_info,
1420 reg_val);
1421 break;
1422 default:
1423 break;
1424 }
1425 } else {
1426 break;
1427 }
1428 }
1429 break;
1430 default:
1431 break;
1432 }
1433 switch (viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name) {
1434 case VT1636_LVDS:
1435 for (i = 0; i < 2; i++) {
1436 value = strsep(&pbuf, " ");
1437 if (value != NULL) {
Wang Shaoyan4ce36bb2011-08-08 10:18:15 +08001438 if (kstrtou8(value, 0, &reg_val.Data) < 0)
1439 return -EINVAL;
Joseph Chan29b619f2008-10-15 22:03:27 -07001440 switch (i) {
1441 case 0:
1442 reg_val.Index = 0x08;
1443 reg_val.Mask = 0x0f;
1444 viafb_gpio_i2c_write_mask_lvds
1445 (viaparinfo->lvds_setting_info2,
1446 &viaparinfo->
1447 chip_info->lvds_chip_info2,
1448 reg_val);
1449 break;
1450 case 1:
1451 reg_val.Index = 0x09;
1452 reg_val.Mask = 0x1f;
1453 viafb_gpio_i2c_write_mask_lvds
1454 (viaparinfo->lvds_setting_info2,
1455 &viaparinfo->
1456 chip_info->lvds_chip_info2,
1457 reg_val);
1458 break;
1459 default:
1460 break;
1461 }
1462 } else {
1463 break;
1464 }
1465 }
1466 break;
1467 default:
1468 break;
1469 }
1470 return count;
1471}
1472
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001473static const struct file_operations viafb_vt1636_proc_fops = {
1474 .owner = THIS_MODULE,
1475 .open = viafb_vt1636_proc_open,
1476 .read = seq_read,
1477 .llseek = seq_lseek,
1478 .release = single_release,
1479 .write = viafb_vt1636_proc_write,
1480};
1481
Florian Tobias Schandinat2a918392010-09-05 01:33:28 +00001482#endif /* CONFIG_FB_VIA_DIRECT_PROCFS */
Joseph Chan29b619f2008-10-15 22:03:27 -07001483
Florian Tobias Schandinatdd7a0b02010-09-19 04:20:55 +00001484static int viafb_sup_odev_proc_show(struct seq_file *m, void *v)
1485{
1486 via_odev_to_seq(m, supported_odev_map[
1487 viaparinfo->shared->chip_info.gfx_chip_name]);
1488 return 0;
1489}
1490
1491static int viafb_sup_odev_proc_open(struct inode *inode, struct file *file)
1492{
1493 return single_open(file, viafb_sup_odev_proc_show, NULL);
1494}
1495
1496static const struct file_operations viafb_sup_odev_proc_fops = {
1497 .owner = THIS_MODULE,
1498 .open = viafb_sup_odev_proc_open,
1499 .read = seq_read,
1500 .llseek = seq_lseek,
1501 .release = single_release,
1502};
1503
Florian Tobias Schandinat2a918392010-09-05 01:33:28 +00001504static ssize_t odev_update(const char __user *buffer, size_t count, u32 *odev)
1505{
1506 char buf[64], *ptr = buf;
1507 u32 devices;
1508 bool add, sub;
1509
1510 if (count < 1 || count > 63)
1511 return -EINVAL;
1512 if (copy_from_user(&buf[0], buffer, count))
1513 return -EFAULT;
1514 buf[count] = '\0';
1515 add = buf[0] == '+';
1516 sub = buf[0] == '-';
1517 if (add || sub)
1518 ptr++;
1519 devices = via_parse_odev(ptr, &ptr);
1520 if (*ptr == '\n')
1521 ptr++;
1522 if (*ptr != 0)
1523 return -EINVAL;
1524 if (add)
1525 *odev |= devices;
1526 else if (sub)
1527 *odev &= ~devices;
1528 else
1529 *odev = devices;
1530 return count;
1531}
1532
1533static int viafb_iga1_odev_proc_show(struct seq_file *m, void *v)
1534{
1535 via_odev_to_seq(m, viaparinfo->shared->iga1_devices);
1536 return 0;
1537}
1538
1539static int viafb_iga1_odev_proc_open(struct inode *inode, struct file *file)
1540{
1541 return single_open(file, viafb_iga1_odev_proc_show, NULL);
1542}
1543
1544static ssize_t viafb_iga1_odev_proc_write(struct file *file,
1545 const char __user *buffer, size_t count, loff_t *pos)
1546{
1547 u32 dev_on, dev_off, dev_old, dev_new;
1548 ssize_t res;
1549
1550 dev_old = dev_new = viaparinfo->shared->iga1_devices;
1551 res = odev_update(buffer, count, &dev_new);
1552 if (res != count)
1553 return res;
1554 dev_off = dev_old & ~dev_new;
1555 dev_on = dev_new & ~dev_old;
1556 viaparinfo->shared->iga1_devices = dev_new;
1557 viaparinfo->shared->iga2_devices &= ~dev_new;
Florian Tobias Schandinat6f9422d2010-09-07 14:28:26 +00001558 via_set_state(dev_off, VIA_STATE_OFF);
Florian Tobias Schandinat2a918392010-09-05 01:33:28 +00001559 via_set_source(dev_new, IGA1);
Florian Tobias Schandinat6f9422d2010-09-07 14:28:26 +00001560 via_set_state(dev_on, VIA_STATE_ON);
Florian Tobias Schandinat2a918392010-09-05 01:33:28 +00001561 return res;
1562}
1563
1564static const struct file_operations viafb_iga1_odev_proc_fops = {
1565 .owner = THIS_MODULE,
1566 .open = viafb_iga1_odev_proc_open,
1567 .read = seq_read,
1568 .llseek = seq_lseek,
1569 .release = single_release,
1570 .write = viafb_iga1_odev_proc_write,
1571};
1572
1573static int viafb_iga2_odev_proc_show(struct seq_file *m, void *v)
1574{
1575 via_odev_to_seq(m, viaparinfo->shared->iga2_devices);
1576 return 0;
1577}
1578
1579static int viafb_iga2_odev_proc_open(struct inode *inode, struct file *file)
1580{
1581 return single_open(file, viafb_iga2_odev_proc_show, NULL);
1582}
1583
1584static ssize_t viafb_iga2_odev_proc_write(struct file *file,
1585 const char __user *buffer, size_t count, loff_t *pos)
1586{
1587 u32 dev_on, dev_off, dev_old, dev_new;
1588 ssize_t res;
1589
1590 dev_old = dev_new = viaparinfo->shared->iga2_devices;
1591 res = odev_update(buffer, count, &dev_new);
1592 if (res != count)
1593 return res;
1594 dev_off = dev_old & ~dev_new;
1595 dev_on = dev_new & ~dev_old;
1596 viaparinfo->shared->iga2_devices = dev_new;
1597 viaparinfo->shared->iga1_devices &= ~dev_new;
Florian Tobias Schandinat6f9422d2010-09-07 14:28:26 +00001598 via_set_state(dev_off, VIA_STATE_OFF);
Florian Tobias Schandinat2a918392010-09-05 01:33:28 +00001599 via_set_source(dev_new, IGA2);
Florian Tobias Schandinat6f9422d2010-09-07 14:28:26 +00001600 via_set_state(dev_on, VIA_STATE_ON);
Florian Tobias Schandinat2a918392010-09-05 01:33:28 +00001601 return res;
1602}
1603
1604static const struct file_operations viafb_iga2_odev_proc_fops = {
1605 .owner = THIS_MODULE,
1606 .open = viafb_iga2_odev_proc_open,
1607 .read = seq_read,
1608 .llseek = seq_lseek,
1609 .release = single_release,
1610 .write = viafb_iga2_odev_proc_write,
1611};
1612
1613#define IS_VT1636(lvds_chip) ((lvds_chip).lvds_chip_name == VT1636_LVDS)
1614static void viafb_init_proc(struct viafb_shared *shared)
1615{
1616 struct proc_dir_entry *iga1_entry, *iga2_entry,
1617 *viafb_entry = proc_mkdir("viafb", NULL);
1618
1619 shared->proc_entry = viafb_entry;
1620 if (viafb_entry) {
1621#ifdef CONFIG_FB_VIA_DIRECT_PROCFS
1622 proc_create("dvp0", 0, viafb_entry, &viafb_dvp0_proc_fops);
1623 proc_create("dvp1", 0, viafb_entry, &viafb_dvp1_proc_fops);
1624 proc_create("dfph", 0, viafb_entry, &viafb_dfph_proc_fops);
1625 proc_create("dfpl", 0, viafb_entry, &viafb_dfpl_proc_fops);
1626 if (IS_VT1636(shared->chip_info.lvds_chip_info)
1627 || IS_VT1636(shared->chip_info.lvds_chip_info2))
1628 proc_create("vt1636", 0, viafb_entry,
1629 &viafb_vt1636_proc_fops);
1630#endif /* CONFIG_FB_VIA_DIRECT_PROCFS */
1631
Florian Tobias Schandinatdd7a0b02010-09-19 04:20:55 +00001632 proc_create("supported_output_devices", 0, viafb_entry,
1633 &viafb_sup_odev_proc_fops);
Florian Tobias Schandinat2a918392010-09-05 01:33:28 +00001634 iga1_entry = proc_mkdir("iga1", viafb_entry);
1635 shared->iga1_proc_entry = iga1_entry;
1636 proc_create("output_devices", 0, iga1_entry,
1637 &viafb_iga1_odev_proc_fops);
1638 iga2_entry = proc_mkdir("iga2", viafb_entry);
1639 shared->iga2_proc_entry = iga2_entry;
1640 proc_create("output_devices", 0, iga2_entry,
1641 &viafb_iga2_odev_proc_fops);
Joseph Chan29b619f2008-10-15 22:03:27 -07001642 }
1643}
Florian Tobias Schandinat2a918392010-09-05 01:33:28 +00001644static void viafb_remove_proc(struct viafb_shared *shared)
Joseph Chan29b619f2008-10-15 22:03:27 -07001645{
Florian Tobias Schandinat2a918392010-09-05 01:33:28 +00001646 struct proc_dir_entry *viafb_entry = shared->proc_entry,
1647 *iga1_entry = shared->iga1_proc_entry,
1648 *iga2_entry = shared->iga2_proc_entry;
Florian Tobias Schandinat2fed5472010-04-17 19:44:56 +00001649
Florian Tobias Schandinat2a918392010-09-05 01:33:28 +00001650 if (!viafb_entry)
1651 return;
1652
1653 remove_proc_entry("output_devices", iga2_entry);
1654 remove_proc_entry("iga2", viafb_entry);
1655 remove_proc_entry("output_devices", iga1_entry);
1656 remove_proc_entry("iga1", viafb_entry);
Florian Tobias Schandinatdd7a0b02010-09-19 04:20:55 +00001657 remove_proc_entry("supported_output_devices", viafb_entry);
Florian Tobias Schandinat2a918392010-09-05 01:33:28 +00001658
1659#ifdef CONFIG_FB_VIA_DIRECT_PROCFS
Joseph Chan29b619f2008-10-15 22:03:27 -07001660 remove_proc_entry("dvp0", viafb_entry);/* parent dir */
1661 remove_proc_entry("dvp1", viafb_entry);
1662 remove_proc_entry("dfph", viafb_entry);
1663 remove_proc_entry("dfpl", viafb_entry);
Florian Tobias Schandinat2a918392010-09-05 01:33:28 +00001664 if (IS_VT1636(shared->chip_info.lvds_chip_info)
1665 || IS_VT1636(shared->chip_info.lvds_chip_info2))
Florian Tobias Schandinat2fed5472010-04-17 19:44:56 +00001666 remove_proc_entry("vt1636", viafb_entry);
Florian Tobias Schandinat2a918392010-09-05 01:33:28 +00001667#endif /* CONFIG_FB_VIA_DIRECT_PROCFS */
Florian Tobias Schandinat2fed5472010-04-17 19:44:56 +00001668
Bruno Prémontc267fd72008-11-19 15:36:23 -08001669 remove_proc_entry("viafb", NULL);
Joseph Chan29b619f2008-10-15 22:03:27 -07001670}
Florian Tobias Schandinat2a918392010-09-05 01:33:28 +00001671#undef IS_VT1636
Florian Tobias Schandinat2b78a962010-04-17 19:44:57 +00001672
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001673static int parse_mode(const char *str, u32 *xres, u32 *yres)
Florian Tobias Schandinat5ff32f62009-09-22 16:47:34 -07001674{
1675 char *ptr;
1676
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001677 if (!str) {
Daniel Drake8aa4d962011-05-10 22:34:11 +01001678 if (machine_is_olpc()) {
1679 *xres = 1200;
1680 *yres = 900;
1681 } else {
1682 *xres = 640;
1683 *yres = 480;
1684 }
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001685 return 0;
1686 }
1687
Florian Tobias Schandinat5ff32f62009-09-22 16:47:34 -07001688 *xres = simple_strtoul(str, &ptr, 10);
1689 if (ptr[0] != 'x')
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001690 return -EINVAL;
Florian Tobias Schandinat5ff32f62009-09-22 16:47:34 -07001691
1692 *yres = simple_strtoul(&ptr[1], &ptr, 10);
1693 if (ptr[0])
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001694 return -EINVAL;
Florian Tobias Schandinat5ff32f62009-09-22 16:47:34 -07001695
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001696 return 0;
Florian Tobias Schandinat5ff32f62009-09-22 16:47:34 -07001697}
1698
Jonathan Corbetf045f772009-12-01 20:29:39 -07001699
Deepak Saxena3fd9b6c2010-04-08 11:15:41 -06001700#ifdef CONFIG_PM
Daniel Drake751305d2010-10-28 18:23:01 +01001701static int viafb_suspend(void *unused)
Deepak Saxena3fd9b6c2010-04-08 11:15:41 -06001702{
Torben Hohnac751ef2011-01-25 15:07:35 -08001703 console_lock();
Daniel Drake751305d2010-10-28 18:23:01 +01001704 fb_set_suspend(viafbinfo, 1);
1705 viafb_sync(viafbinfo);
Torben Hohnac751ef2011-01-25 15:07:35 -08001706 console_unlock();
Deepak Saxena3fd9b6c2010-04-08 11:15:41 -06001707
1708 return 0;
1709}
1710
Daniel Drake751305d2010-10-28 18:23:01 +01001711static int viafb_resume(void *unused)
Deepak Saxena3fd9b6c2010-04-08 11:15:41 -06001712{
Torben Hohnac751ef2011-01-25 15:07:35 -08001713 console_lock();
Florian Tobias Schandinatadac8d62010-04-26 17:31:03 +00001714 if (viaparinfo->shared->vdev->engine_mmio)
1715 viafb_reset_engine(viaparinfo);
Florian Tobias Schandinatb75f2c02010-04-26 16:37:53 +00001716 viafb_set_par(viafbinfo);
1717 if (viafb_dual_fb)
1718 viafb_set_par(viafbinfo1);
Deepak Saxena3fd9b6c2010-04-08 11:15:41 -06001719 fb_set_suspend(viafbinfo, 0);
1720
Torben Hohnac751ef2011-01-25 15:07:35 -08001721 console_unlock();
Deepak Saxena3fd9b6c2010-04-08 11:15:41 -06001722 return 0;
1723}
1724
Daniel Drake751305d2010-10-28 18:23:01 +01001725static struct viafb_pm_hooks viafb_fb_pm_hooks = {
1726 .suspend = viafb_suspend,
1727 .resume = viafb_resume
1728};
1729
Deepak Saxena3fd9b6c2010-04-08 11:15:41 -06001730#endif
1731
1732
Jonathan Corbet24b4d822010-04-22 13:48:09 -06001733int __devinit via_fb_pci_probe(struct viafb_dev *vdev)
Joseph Chan29b619f2008-10-15 22:03:27 -07001734{
Florian Tobias Schandinat5ff32f62009-09-22 16:47:34 -07001735 u32 default_xres, default_yres;
Florian Tobias Schandinatdba77f82010-03-10 15:21:37 -08001736 struct fb_var_screeninfo default_var;
Harald Welte109771a2009-05-19 17:12:58 +08001737 int rc;
Florian Tobias Schandinatc4df5482009-09-22 16:47:24 -07001738 u32 viafb_par_length;
Joseph Chan29b619f2008-10-15 22:03:27 -07001739
1740 DEBUG_MSG(KERN_INFO "VIAFB PCI Probe!!\n");
Florian Tobias Schandinatdba77f82010-03-10 15:21:37 -08001741 memset(&default_var, 0, sizeof(default_var));
Joseph Chan29b619f2008-10-15 22:03:27 -07001742 viafb_par_length = ALIGN(sizeof(struct viafb_par), BITS_PER_LONG/8);
Joseph Chan29b619f2008-10-15 22:03:27 -07001743
1744 /* Allocate fb_info and ***_par here, also including some other needed
1745 * variables
1746 */
Florian Tobias Schandinatc4df5482009-09-22 16:47:24 -07001747 viafbinfo = framebuffer_alloc(viafb_par_length +
Harald Weltedb8df7b2009-09-22 16:47:38 -07001748 ALIGN(sizeof(struct viafb_shared), BITS_PER_LONG/8),
Jonathan Corbet24b4d822010-04-22 13:48:09 -06001749 &vdev->pdev->dev);
Joseph Chan29b619f2008-10-15 22:03:27 -07001750 if (!viafbinfo) {
1751 printk(KERN_ERR"Could not allocate memory for viafb_info.\n");
Harald Welte109771a2009-05-19 17:12:58 +08001752 return -ENOMEM;
Joseph Chan29b619f2008-10-15 22:03:27 -07001753 }
1754
1755 viaparinfo = (struct viafb_par *)viafbinfo->par;
Florian Tobias Schandinatc4df5482009-09-22 16:47:24 -07001756 viaparinfo->shared = viafbinfo->par + viafb_par_length;
Jonathan Corbet24b4d822010-04-22 13:48:09 -06001757 viaparinfo->shared->vdev = vdev;
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -07001758 viaparinfo->vram_addr = 0;
Florian Tobias Schandinatc4df5482009-09-22 16:47:24 -07001759 viaparinfo->tmds_setting_info = &viaparinfo->shared->tmds_setting_info;
1760 viaparinfo->lvds_setting_info = &viaparinfo->shared->lvds_setting_info;
1761 viaparinfo->lvds_setting_info2 =
1762 &viaparinfo->shared->lvds_setting_info2;
Florian Tobias Schandinatc4df5482009-09-22 16:47:24 -07001763 viaparinfo->chip_info = &viaparinfo->shared->chip_info;
Joseph Chan29b619f2008-10-15 22:03:27 -07001764
1765 if (viafb_dual_fb)
1766 viafb_SAMM_ON = 1;
Joseph Chan29b619f2008-10-15 22:03:27 -07001767 parse_lcd_port();
1768 parse_dvi_port();
1769
Jonathan Corbet24b4d822010-04-22 13:48:09 -06001770 viafb_init_chip_info(vdev->chip_type);
1771 /*
1772 * The framebuffer will have been successfully mapped by
1773 * the core (or we'd not be here), but we still need to
1774 * set up our own accounting.
1775 */
1776 viaparinfo->fbmem = vdev->fbmem_start;
1777 viaparinfo->memsize = vdev->fbmem_len;
Joseph Chan29b619f2008-10-15 22:03:27 -07001778 viaparinfo->fbmem_free = viaparinfo->memsize;
1779 viaparinfo->fbmem_used = 0;
Jonathan Corbet24b4d822010-04-22 13:48:09 -06001780 viafbinfo->screen_base = vdev->fbmem;
Joseph Chan29b619f2008-10-15 22:03:27 -07001781
Jonathan Corbet24b4d822010-04-22 13:48:09 -06001782 viafbinfo->fix.mmio_start = vdev->engine_start;
1783 viafbinfo->fix.mmio_len = vdev->engine_len;
Joseph Chan29b619f2008-10-15 22:03:27 -07001784 viafbinfo->node = 0;
1785 viafbinfo->fbops = &viafb_ops;
1786 viafbinfo->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
1787
1788 viafbinfo->pseudo_palette = pseudo_pal;
Florian Tobias Schandinatadac8d62010-04-26 17:31:03 +00001789 if (viafb_accel && !viafb_setup_engine(viafbinfo)) {
Florian Tobias Schandinat31de59d2009-09-22 16:47:31 -07001790 viafbinfo->flags |= FBINFO_HWACCEL_COPYAREA |
1791 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_IMAGEBLIT;
1792 default_var.accel_flags = FB_ACCELF_TEXT;
1793 } else {
1794 viafbinfo->flags |= FBINFO_HWACCEL_DISABLED;
1795 default_var.accel_flags = 0;
Joseph Chan29b619f2008-10-15 22:03:27 -07001796 }
1797
1798 if (viafb_second_size && (viafb_second_size < 8)) {
1799 viafb_second_offset = viaparinfo->fbmem_free -
1800 viafb_second_size * 1024 * 1024;
1801 } else {
1802 viafb_second_size = 8;
1803 viafb_second_offset = viaparinfo->fbmem_free -
1804 viafb_second_size * 1024 * 1024;
1805 }
1806
Florian Tobias Schandinat5ff32f62009-09-22 16:47:34 -07001807 parse_mode(viafb_mode, &default_xres, &default_yres);
Florian Tobias Schandinat7f980a02011-03-27 02:54:32 +00001808 if (viafb_SAMM_ON == 1)
Florian Tobias Schandinat5ff32f62009-09-22 16:47:34 -07001809 parse_mode(viafb_mode1, &viafb_second_xres,
1810 &viafb_second_yres);
1811
Joseph Chan29b619f2008-10-15 22:03:27 -07001812 default_var.xres = default_xres;
1813 default_var.yres = default_yres;
Florian Tobias Schandinatcd589952010-07-13 19:44:05 +00001814 default_var.xres_virtual = default_xres;
Joseph Chan29b619f2008-10-15 22:03:27 -07001815 default_var.yres_virtual = default_yres;
1816 default_var.bits_per_pixel = viafb_bpp;
Florian Tobias Schandinat94715ba2011-08-06 23:04:43 +00001817 viafb_fill_var_timing_info(&default_var, viafb_get_best_mode(
1818 default_var.xres, default_var.yres, viafb_refresh));
Florian Tobias Schandinat7cf60792010-03-10 15:21:31 -08001819 viafb_setup_fixinfo(&viafbinfo->fix, viaparinfo);
Florian Tobias Schandinat7cf60792010-03-10 15:21:31 -08001820 viafbinfo->var = default_var;
Joseph Chan29b619f2008-10-15 22:03:27 -07001821
1822 if (viafb_dual_fb) {
Jonathan Corbet24b4d822010-04-22 13:48:09 -06001823 viafbinfo1 = framebuffer_alloc(viafb_par_length,
1824 &vdev->pdev->dev);
Joseph Chan29b619f2008-10-15 22:03:27 -07001825 if (!viafbinfo1) {
1826 printk(KERN_ERR
1827 "allocate the second framebuffer struct error\n");
Harald Welte109771a2009-05-19 17:12:58 +08001828 rc = -ENOMEM;
Jonathan Corbet24b4d822010-04-22 13:48:09 -06001829 goto out_fb_release;
Joseph Chan29b619f2008-10-15 22:03:27 -07001830 }
1831 viaparinfo1 = viafbinfo1->par;
1832 memcpy(viaparinfo1, viaparinfo, viafb_par_length);
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -07001833 viaparinfo1->vram_addr = viafb_second_offset;
Joseph Chan29b619f2008-10-15 22:03:27 -07001834 viaparinfo1->memsize = viaparinfo->memsize -
1835 viafb_second_offset;
1836 viaparinfo->memsize = viafb_second_offset;
Joseph Chan29b619f2008-10-15 22:03:27 -07001837 viaparinfo1->fbmem = viaparinfo->fbmem + viafb_second_offset;
1838
1839 viaparinfo1->fbmem_used = viaparinfo->fbmem_used;
1840 viaparinfo1->fbmem_free = viaparinfo1->memsize -
1841 viaparinfo1->fbmem_used;
1842 viaparinfo->fbmem_free = viaparinfo->memsize;
1843 viaparinfo->fbmem_used = 0;
Joseph Chan29b619f2008-10-15 22:03:27 -07001844
Florian Tobias Schandinat09cf1182009-09-22 16:47:14 -07001845 viaparinfo->iga_path = IGA1;
1846 viaparinfo1->iga_path = IGA2;
Joseph Chan29b619f2008-10-15 22:03:27 -07001847 memcpy(viafbinfo1, viafbinfo, sizeof(struct fb_info));
Florian Tobias Schandinatc4df5482009-09-22 16:47:24 -07001848 viafbinfo1->par = viaparinfo1;
Joseph Chan29b619f2008-10-15 22:03:27 -07001849 viafbinfo1->screen_base = viafbinfo->screen_base +
1850 viafb_second_offset;
Joseph Chan29b619f2008-10-15 22:03:27 -07001851
1852 default_var.xres = viafb_second_xres;
1853 default_var.yres = viafb_second_yres;
Florian Tobias Schandinat7f980a02011-03-27 02:54:32 +00001854 default_var.xres_virtual = viafb_second_xres;
1855 default_var.yres_virtual = viafb_second_yres;
Joseph Chan29b619f2008-10-15 22:03:27 -07001856 default_var.bits_per_pixel = viafb_bpp1;
Florian Tobias Schandinat94715ba2011-08-06 23:04:43 +00001857 viafb_fill_var_timing_info(&default_var, viafb_get_best_mode(
1858 default_var.xres, default_var.yres, viafb_refresh1));
Joseph Chan29b619f2008-10-15 22:03:27 -07001859
1860 viafb_setup_fixinfo(&viafbinfo1->fix, viaparinfo1);
1861 viafb_check_var(&default_var, viafbinfo1);
1862 viafbinfo1->var = default_var;
Florian Tobias Schandinat81228a32009-09-22 16:47:13 -07001863 viafb_update_fix(viafbinfo1);
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -07001864 viaparinfo1->depth = fb_get_color_depth(&viafbinfo1->var,
1865 &viafbinfo1->fix);
Joseph Chan29b619f2008-10-15 22:03:27 -07001866 }
1867
Florian Tobias Schandinate17cea32010-03-10 15:21:41 -08001868 viafb_check_var(&viafbinfo->var, viafbinfo);
Florian Tobias Schandinat81228a32009-09-22 16:47:13 -07001869 viafb_update_fix(viafbinfo);
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -07001870 viaparinfo->depth = fb_get_color_depth(&viafbinfo->var,
1871 &viafbinfo->fix);
Joseph Chan29b619f2008-10-15 22:03:27 -07001872 default_var.activate = FB_ACTIVATE_NOW;
Harald Welte109771a2009-05-19 17:12:58 +08001873 rc = fb_alloc_cmap(&viafbinfo->cmap, 256, 0);
1874 if (rc)
1875 goto out_fb1_release;
Joseph Chan29b619f2008-10-15 22:03:27 -07001876
1877 if (viafb_dual_fb && (viafb_primary_dev == LCD_Device)
1878 && (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)) {
Harald Welte109771a2009-05-19 17:12:58 +08001879 rc = register_framebuffer(viafbinfo1);
1880 if (rc)
1881 goto out_dealloc_cmap;
Joseph Chan29b619f2008-10-15 22:03:27 -07001882 }
Harald Welte109771a2009-05-19 17:12:58 +08001883 rc = register_framebuffer(viafbinfo);
1884 if (rc)
1885 goto out_fb1_unreg_lcd_cle266;
Joseph Chan29b619f2008-10-15 22:03:27 -07001886
1887 if (viafb_dual_fb && ((viafb_primary_dev != LCD_Device)
1888 || (viaparinfo->chip_info->gfx_chip_name !=
1889 UNICHROME_CLE266))) {
Harald Welte109771a2009-05-19 17:12:58 +08001890 rc = register_framebuffer(viafbinfo1);
1891 if (rc)
1892 goto out_fb_unreg;
Joseph Chan29b619f2008-10-15 22:03:27 -07001893 }
1894 DEBUG_MSG(KERN_INFO "fb%d: %s frame buffer device %dx%d-%dbpp\n",
1895 viafbinfo->node, viafbinfo->fix.id, default_var.xres,
1896 default_var.yres, default_var.bits_per_pixel);
1897
Florian Tobias Schandinat2a918392010-09-05 01:33:28 +00001898 viafb_init_proc(viaparinfo->shared);
Joseph Chan29b619f2008-10-15 22:03:27 -07001899 viafb_init_dac(IGA2);
Daniel Drake751305d2010-10-28 18:23:01 +01001900
1901#ifdef CONFIG_PM
1902 viafb_pm_register(&viafb_fb_pm_hooks);
1903#endif
Joseph Chan29b619f2008-10-15 22:03:27 -07001904 return 0;
Harald Welte109771a2009-05-19 17:12:58 +08001905
1906out_fb_unreg:
1907 unregister_framebuffer(viafbinfo);
1908out_fb1_unreg_lcd_cle266:
1909 if (viafb_dual_fb && (viafb_primary_dev == LCD_Device)
1910 && (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266))
1911 unregister_framebuffer(viafbinfo1);
1912out_dealloc_cmap:
1913 fb_dealloc_cmap(&viafbinfo->cmap);
1914out_fb1_release:
1915 if (viafbinfo1)
1916 framebuffer_release(viafbinfo1);
Harald Welte109771a2009-05-19 17:12:58 +08001917out_fb_release:
1918 framebuffer_release(viafbinfo);
1919 return rc;
Joseph Chan29b619f2008-10-15 22:03:27 -07001920}
1921
Jonathan Corbetf045f772009-12-01 20:29:39 -07001922void __devexit via_fb_pci_remove(struct pci_dev *pdev)
Joseph Chan29b619f2008-10-15 22:03:27 -07001923{
1924 DEBUG_MSG(KERN_INFO "via_pci_remove!\n");
1925 fb_dealloc_cmap(&viafbinfo->cmap);
1926 unregister_framebuffer(viafbinfo);
1927 if (viafb_dual_fb)
1928 unregister_framebuffer(viafbinfo1);
Florian Tobias Schandinat2a918392010-09-05 01:33:28 +00001929 viafb_remove_proc(viaparinfo->shared);
Joseph Chan29b619f2008-10-15 22:03:27 -07001930 framebuffer_release(viafbinfo);
1931 if (viafb_dual_fb)
1932 framebuffer_release(viafbinfo1);
Joseph Chan29b619f2008-10-15 22:03:27 -07001933}
1934
1935#ifndef MODULE
Daniel Drake8aa4d962011-05-10 22:34:11 +01001936static int __init viafb_setup(void)
Joseph Chan29b619f2008-10-15 22:03:27 -07001937{
1938 char *this_opt;
Daniel Drake8aa4d962011-05-10 22:34:11 +01001939 char *options;
1940
Joseph Chan29b619f2008-10-15 22:03:27 -07001941 DEBUG_MSG(KERN_INFO "viafb_setup!\n");
1942
Daniel Drake8aa4d962011-05-10 22:34:11 +01001943 if (fb_get_options("viafb", &options))
1944 return -ENODEV;
1945
Joseph Chan29b619f2008-10-15 22:03:27 -07001946 if (!options || !*options)
1947 return 0;
1948
1949 while ((this_opt = strsep(&options, ",")) != NULL) {
1950 if (!*this_opt)
1951 continue;
1952
Wang Shaoyan4ce36bb2011-08-08 10:18:15 +08001953 if (!strncmp(this_opt, "viafb_mode1=", 12)) {
Joseph Chan29b619f2008-10-15 22:03:27 -07001954 viafb_mode1 = kstrdup(this_opt + 12, GFP_KERNEL);
Wang Shaoyan4ce36bb2011-08-08 10:18:15 +08001955 } else if (!strncmp(this_opt, "viafb_mode=", 11)) {
Joseph Chan29b619f2008-10-15 22:03:27 -07001956 viafb_mode = kstrdup(this_opt + 11, GFP_KERNEL);
Wang Shaoyan4ce36bb2011-08-08 10:18:15 +08001957 } else if (!strncmp(this_opt, "viafb_bpp1=", 11)) {
1958 if (kstrtouint(this_opt + 11, 0, &viafb_bpp1) < 0)
1959 return -EINVAL;
1960 } else if (!strncmp(this_opt, "viafb_bpp=", 10)) {
1961 if (kstrtouint(this_opt + 10, 0, &viafb_bpp) < 0)
1962 return -EINVAL;
1963 } else if (!strncmp(this_opt, "viafb_refresh1=", 15)) {
1964 if (kstrtoint(this_opt + 15, 0, &viafb_refresh1) < 0)
1965 return -EINVAL;
1966 } else if (!strncmp(this_opt, "viafb_refresh=", 14)) {
1967 if (kstrtoint(this_opt + 14, 0, &viafb_refresh) < 0)
1968 return -EINVAL;
1969 } else if (!strncmp(this_opt, "viafb_lcd_dsp_method=", 21)) {
1970 if (kstrtoint(this_opt + 21, 0,
1971 &viafb_lcd_dsp_method) < 0)
1972 return -EINVAL;
1973 } else if (!strncmp(this_opt, "viafb_lcd_panel_id=", 19)) {
1974 if (kstrtoint(this_opt + 19, 0,
1975 &viafb_lcd_panel_id) < 0)
1976 return -EINVAL;
1977 } else if (!strncmp(this_opt, "viafb_accel=", 12)) {
1978 if (kstrtoint(this_opt + 12, 0, &viafb_accel) < 0)
1979 return -EINVAL;
1980 } else if (!strncmp(this_opt, "viafb_SAMM_ON=", 14)) {
1981 if (kstrtoint(this_opt + 14, 0, &viafb_SAMM_ON) < 0)
1982 return -EINVAL;
1983 } else if (!strncmp(this_opt, "viafb_active_dev=", 17)) {
Joseph Chan29b619f2008-10-15 22:03:27 -07001984 viafb_active_dev = kstrdup(this_opt + 17, GFP_KERNEL);
Wang Shaoyan4ce36bb2011-08-08 10:18:15 +08001985 } else if (!strncmp(this_opt,
1986 "viafb_display_hardware_layout=", 30)) {
1987 if (kstrtoint(this_opt + 30, 0,
1988 &viafb_display_hardware_layout) < 0)
1989 return -EINVAL;
1990 } else if (!strncmp(this_opt, "viafb_second_size=", 18)) {
1991 if (kstrtoint(this_opt + 18, 0, &viafb_second_size) < 0)
1992 return -EINVAL;
1993 } else if (!strncmp(this_opt,
1994 "viafb_platform_epia_dvi=", 24)) {
1995 if (kstrtoint(this_opt + 24, 0,
1996 &viafb_platform_epia_dvi) < 0)
1997 return -EINVAL;
1998 } else if (!strncmp(this_opt,
1999 "viafb_device_lcd_dualedge=", 26)) {
2000 if (kstrtoint(this_opt + 26, 0,
2001 &viafb_device_lcd_dualedge) < 0)
2002 return -EINVAL;
2003 } else if (!strncmp(this_opt, "viafb_bus_width=", 16)) {
2004 if (kstrtoint(this_opt + 16, 0, &viafb_bus_width) < 0)
2005 return -EINVAL;
2006 } else if (!strncmp(this_opt, "viafb_lcd_mode=", 15)) {
2007 if (kstrtoint(this_opt + 15, 0, &viafb_lcd_mode) < 0)
2008 return -EINVAL;
2009 } else if (!strncmp(this_opt, "viafb_lcd_port=", 15)) {
Joseph Chan29b619f2008-10-15 22:03:27 -07002010 viafb_lcd_port = kstrdup(this_opt + 15, GFP_KERNEL);
Wang Shaoyan4ce36bb2011-08-08 10:18:15 +08002011 } else if (!strncmp(this_opt, "viafb_dvi_port=", 15)) {
Joseph Chan29b619f2008-10-15 22:03:27 -07002012 viafb_dvi_port = kstrdup(this_opt + 15, GFP_KERNEL);
Wang Shaoyan4ce36bb2011-08-08 10:18:15 +08002013 }
Joseph Chan29b619f2008-10-15 22:03:27 -07002014 }
2015 return 0;
2016}
2017#endif
2018
Jonathan Corbetf045f772009-12-01 20:29:39 -07002019/*
2020 * These are called out of via-core for now.
2021 */
2022int __init viafb_init(void)
Joseph Chan29b619f2008-10-15 22:03:27 -07002023{
Florian Tobias Schandinat3f086fe2011-03-21 17:01:07 +00002024 u32 dummy_x, dummy_y;
Nikanth Karthikesan0acd33d2011-06-10 14:27:04 +05302025 int r = 0;
Daniel Drake8aa4d962011-05-10 22:34:11 +01002026
2027 if (machine_is_olpc())
2028 /* Apply XO-1.5-specific configuration. */
2029 viafb_lcd_panel_id = 23;
2030
Joseph Chan29b619f2008-10-15 22:03:27 -07002031#ifndef MODULE
Daniel Drake8aa4d962011-05-10 22:34:11 +01002032 r = viafb_setup();
2033 if (r < 0)
2034 return r;
Joseph Chan29b619f2008-10-15 22:03:27 -07002035#endif
Florian Tobias Schandinat3f086fe2011-03-21 17:01:07 +00002036 if (parse_mode(viafb_mode, &dummy_x, &dummy_y)
Florian Tobias Schandinat94715ba2011-08-06 23:04:43 +00002037 || !viafb_get_best_mode(dummy_x, dummy_y, viafb_refresh)
Florian Tobias Schandinat3f086fe2011-03-21 17:01:07 +00002038 || parse_mode(viafb_mode1, &dummy_x, &dummy_y)
Florian Tobias Schandinat94715ba2011-08-06 23:04:43 +00002039 || !viafb_get_best_mode(dummy_x, dummy_y, viafb_refresh1)
Florian Tobias Schandinate17cea32010-03-10 15:21:41 -08002040 || viafb_bpp < 0 || viafb_bpp > 32
2041 || viafb_bpp1 < 0 || viafb_bpp1 > 32
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08002042 || parse_active_dev())
2043 return -EINVAL;
2044
Joseph Chan29b619f2008-10-15 22:03:27 -07002045 printk(KERN_INFO
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002046 "VIA Graphics Integration Chipset framebuffer %d.%d initializing\n",
Joseph Chan29b619f2008-10-15 22:03:27 -07002047 VERSION_MAJOR, VERSION_MINOR);
Nikanth Karthikesan0acd33d2011-06-10 14:27:04 +05302048 return r;
Joseph Chan29b619f2008-10-15 22:03:27 -07002049}
2050
Jonathan Corbetf045f772009-12-01 20:29:39 -07002051void __exit viafb_exit(void)
Joseph Chan29b619f2008-10-15 22:03:27 -07002052{
2053 DEBUG_MSG(KERN_INFO "viafb_exit!\n");
Joseph Chan29b619f2008-10-15 22:03:27 -07002054}
2055
2056static struct fb_ops viafb_ops = {
2057 .owner = THIS_MODULE,
2058 .fb_open = viafb_open,
2059 .fb_release = viafb_release,
2060 .fb_check_var = viafb_check_var,
2061 .fb_set_par = viafb_set_par,
2062 .fb_setcolreg = viafb_setcolreg,
2063 .fb_pan_display = viafb_pan_display,
2064 .fb_blank = viafb_blank,
2065 .fb_fillrect = viafb_fillrect,
2066 .fb_copyarea = viafb_copyarea,
2067 .fb_imageblit = viafb_imageblit,
2068 .fb_cursor = viafb_cursor,
2069 .fb_ioctl = viafb_ioctl,
2070 .fb_sync = viafb_sync,
Joseph Chan29b619f2008-10-15 22:03:27 -07002071};
2072
Joseph Chan29b619f2008-10-15 22:03:27 -07002073
2074#ifdef MODULE
Harald Welte93967be2009-09-22 16:47:32 -07002075module_param(viafb_mode, charp, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002076MODULE_PARM_DESC(viafb_mode, "Set resolution (default=640x480)");
2077
Harald Welte93967be2009-09-22 16:47:32 -07002078module_param(viafb_mode1, charp, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002079MODULE_PARM_DESC(viafb_mode1, "Set resolution (default=640x480)");
2080
Harald Welte93967be2009-09-22 16:47:32 -07002081module_param(viafb_bpp, int, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002082MODULE_PARM_DESC(viafb_bpp, "Set color depth (default=32bpp)");
2083
Harald Welte93967be2009-09-22 16:47:32 -07002084module_param(viafb_bpp1, int, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002085MODULE_PARM_DESC(viafb_bpp1, "Set color depth (default=32bpp)");
2086
Harald Welte93967be2009-09-22 16:47:32 -07002087module_param(viafb_refresh, int, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002088MODULE_PARM_DESC(viafb_refresh,
2089 "Set CRT viafb_refresh rate (default = 60)");
2090
Harald Welte93967be2009-09-22 16:47:32 -07002091module_param(viafb_refresh1, int, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002092MODULE_PARM_DESC(viafb_refresh1,
2093 "Set CRT refresh rate (default = 60)");
2094
Harald Welte93967be2009-09-22 16:47:32 -07002095module_param(viafb_lcd_panel_id, int, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002096MODULE_PARM_DESC(viafb_lcd_panel_id,
2097 "Set Flat Panel type(Default=1024x768)");
2098
Harald Welte93967be2009-09-22 16:47:32 -07002099module_param(viafb_lcd_dsp_method, int, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002100MODULE_PARM_DESC(viafb_lcd_dsp_method,
2101 "Set Flat Panel display scaling method.(Default=Expandsion)");
2102
Harald Welte93967be2009-09-22 16:47:32 -07002103module_param(viafb_SAMM_ON, int, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002104MODULE_PARM_DESC(viafb_SAMM_ON,
2105 "Turn on/off flag of SAMM(Default=OFF)");
2106
Harald Welte93967be2009-09-22 16:47:32 -07002107module_param(viafb_accel, int, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002108MODULE_PARM_DESC(viafb_accel,
Florian Tobias Schandinat31de59d2009-09-22 16:47:31 -07002109 "Set 2D Hardware Acceleration: 0 = OFF, 1 = ON (default)");
Joseph Chan29b619f2008-10-15 22:03:27 -07002110
Harald Welte93967be2009-09-22 16:47:32 -07002111module_param(viafb_active_dev, charp, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002112MODULE_PARM_DESC(viafb_active_dev, "Specify active devices.");
2113
Harald Welte93967be2009-09-22 16:47:32 -07002114module_param(viafb_display_hardware_layout, int, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002115MODULE_PARM_DESC(viafb_display_hardware_layout,
2116 "Display Hardware Layout (LCD Only, DVI Only...,etc)");
2117
Harald Welte93967be2009-09-22 16:47:32 -07002118module_param(viafb_second_size, int, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002119MODULE_PARM_DESC(viafb_second_size,
2120 "Set secondary device memory size");
2121
Harald Welte93967be2009-09-22 16:47:32 -07002122module_param(viafb_dual_fb, int, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002123MODULE_PARM_DESC(viafb_dual_fb,
2124 "Turn on/off flag of dual framebuffer devices.(Default = OFF)");
2125
Harald Welte93967be2009-09-22 16:47:32 -07002126module_param(viafb_platform_epia_dvi, int, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002127MODULE_PARM_DESC(viafb_platform_epia_dvi,
2128 "Turn on/off flag of DVI devices on EPIA board.(Default = OFF)");
2129
Harald Welte93967be2009-09-22 16:47:32 -07002130module_param(viafb_device_lcd_dualedge, int, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002131MODULE_PARM_DESC(viafb_device_lcd_dualedge,
2132 "Turn on/off flag of dual edge panel.(Default = OFF)");
2133
Harald Welte93967be2009-09-22 16:47:32 -07002134module_param(viafb_bus_width, int, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002135MODULE_PARM_DESC(viafb_bus_width,
2136 "Set bus width of panel.(Default = 12)");
2137
Harald Welte93967be2009-09-22 16:47:32 -07002138module_param(viafb_lcd_mode, int, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002139MODULE_PARM_DESC(viafb_lcd_mode,
2140 "Set Flat Panel mode(Default=OPENLDI)");
2141
Harald Welte93967be2009-09-22 16:47:32 -07002142module_param(viafb_lcd_port, charp, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002143MODULE_PARM_DESC(viafb_lcd_port, "Specify LCD output port.");
2144
Harald Welte93967be2009-09-22 16:47:32 -07002145module_param(viafb_dvi_port, charp, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002146MODULE_PARM_DESC(viafb_dvi_port, "Specify DVI output port.");
2147
2148MODULE_LICENSE("GPL");
2149#endif