blob: c80e770e180029a132087f73f3cbbfc6295a7c5e [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>
Florian Tobias Schandinate7589272011-07-30 01:25:29 +000027#include <linux/via_i2c.h>
Daniel Drake8aa4d962011-05-10 22:34:11 +010028#include <asm/olpc.h>
Joseph Chan29b619f2008-10-15 22:03:27 -070029
Jonathan Corbetec668412010-05-05 14:44:55 -060030#define _MASTER_FILE
Joseph Chan29b619f2008-10-15 22:03:27 -070031#include "global.h"
32
Joseph Chan29b619f2008-10-15 22:03:27 -070033static char *viafb_name = "Via";
34static u32 pseudo_pal[17];
35
36/* video mode */
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -080037static char *viafb_mode;
38static char *viafb_mode1;
Florian Tobias Schandinatdba77f82010-03-10 15:21:37 -080039static int viafb_bpp = 32;
40static int viafb_bpp1 = 32;
41
42static unsigned int viafb_second_offset;
43static int viafb_second_size;
Joseph Chan29b619f2008-10-15 22:03:27 -070044
Florian Tobias Schandinat31de59d2009-09-22 16:47:31 -070045static int viafb_accel = 1;
46
Joseph Chan29b619f2008-10-15 22:03:27 -070047/* Added for specifying active devices.*/
Stephen Hemminger23e5abd2011-03-03 10:00:08 -080048static char *viafb_active_dev;
Joseph Chan29b619f2008-10-15 22:03:27 -070049
Joseph Chan29b619f2008-10-15 22:03:27 -070050/*Added for specify lcd output port*/
Stephen Hemminger23e5abd2011-03-03 10:00:08 -080051static char *viafb_lcd_port = "";
52static char *viafb_dvi_port = "";
Joseph Chan29b619f2008-10-15 22:03:27 -070053
Joseph Chan29b619f2008-10-15 22:03:27 -070054static void retrieve_device_setting(struct viafb_ioctl_setting
55 *setting_info);
Florian Tobias Schandinatee79d542010-03-10 15:21:32 -080056static int viafb_pan_display(struct fb_var_screeninfo *var,
57 struct fb_info *info);
Joseph Chan29b619f2008-10-15 22:03:27 -070058
Joseph Chan29b619f2008-10-15 22:03:27 -070059static struct fb_ops viafb_ops;
60
Florian Tobias Schandinatdd7a0b02010-09-19 04:20:55 +000061/* supported output devices on each IGP
Florian Tobias Schandinat51f43322010-10-24 04:02:14 +000062 * only CX700, VX800, VX855, VX900 were documented
Florian Tobias Schandinatdd7a0b02010-09-19 04:20:55 +000063 * VIA_CRT should be everywhere
64 * VIA_6C can be onle pre-CX700 (probably only on CLE266) as 6C is used for PLL
65 * source selection on CX700 and later
66 * K400 seems to support VIA_96, VIA_DVP1, VIA_LVDS{1,2} as in viamode.c
67 */
68static const u32 supported_odev_map[] = {
Florian Tobias Schandinata2aa9f92010-09-19 04:40:15 +000069 [UNICHROME_CLE266] = VIA_CRT | VIA_LDVP0 | VIA_LDVP1,
70 [UNICHROME_K400] = VIA_CRT | VIA_DVP0 | VIA_DVP1 | VIA_LVDS1
Florian Tobias Schandinatdd7a0b02010-09-19 04:20:55 +000071 | VIA_LVDS2,
Florian Tobias Schandinata2aa9f92010-09-19 04:40:15 +000072 [UNICHROME_K800] = VIA_CRT | VIA_DVP0 | VIA_DVP1 | VIA_LVDS1
Florian Tobias Schandinatdd7a0b02010-09-19 04:20:55 +000073 | VIA_LVDS2,
Florian Tobias Schandinata2aa9f92010-09-19 04:40:15 +000074 [UNICHROME_PM800] = VIA_CRT | VIA_DVP0 | VIA_DVP1 | VIA_LVDS1
Florian Tobias Schandinatdd7a0b02010-09-19 04:20:55 +000075 | VIA_LVDS2,
Florian Tobias Schandinata2aa9f92010-09-19 04:40:15 +000076 [UNICHROME_CN700] = VIA_CRT | VIA_DVP0 | VIA_DVP1 | VIA_LVDS1
Florian Tobias Schandinatdd7a0b02010-09-19 04:20:55 +000077 | VIA_LVDS2,
78 [UNICHROME_CX700] = VIA_CRT | VIA_DVP1 | VIA_LVDS1 | VIA_LVDS2,
79 [UNICHROME_CN750] = VIA_CRT | VIA_DVP1 | VIA_LVDS1 | VIA_LVDS2,
80 [UNICHROME_K8M890] = VIA_CRT | VIA_DVP1 | VIA_LVDS1 | VIA_LVDS2,
81 [UNICHROME_P4M890] = VIA_CRT | VIA_DVP1 | VIA_LVDS1 | VIA_LVDS2,
82 [UNICHROME_P4M900] = VIA_CRT | VIA_DVP1 | VIA_LVDS1 | VIA_LVDS2,
83 [UNICHROME_VX800] = VIA_CRT | VIA_DVP1 | VIA_LVDS1 | VIA_LVDS2,
84 [UNICHROME_VX855] = VIA_CRT | VIA_DVP1 | VIA_LVDS1 | VIA_LVDS2,
Florian Tobias Schandinat51f43322010-10-24 04:02:14 +000085 [UNICHROME_VX900] = VIA_CRT | VIA_DVP1 | VIA_LVDS1 | VIA_LVDS2,
Florian Tobias Schandinatdd7a0b02010-09-19 04:20:55 +000086};
Florian Tobias Schandinat81228a32009-09-22 16:47:13 -070087
Florian Tobias Schandinatbd140692010-03-10 15:21:38 -080088static void viafb_fill_var_color_info(struct fb_var_screeninfo *var, u8 depth)
89{
90 var->grayscale = 0;
91 var->red.msb_right = 0;
92 var->green.msb_right = 0;
93 var->blue.msb_right = 0;
94 var->transp.offset = 0;
95 var->transp.length = 0;
96 var->transp.msb_right = 0;
97 var->nonstd = 0;
98 switch (depth) {
99 case 8:
100 var->bits_per_pixel = 8;
101 var->red.offset = 0;
102 var->green.offset = 0;
103 var->blue.offset = 0;
Florian Tobias Schandinat415559f2010-03-10 15:21:40 -0800104 var->red.length = 8;
105 var->green.length = 8;
106 var->blue.length = 8;
Florian Tobias Schandinatbd140692010-03-10 15:21:38 -0800107 break;
Florian Tobias Schandinate17cea32010-03-10 15:21:41 -0800108 case 15:
109 var->bits_per_pixel = 16;
110 var->red.offset = 10;
111 var->green.offset = 5;
112 var->blue.offset = 0;
113 var->red.length = 5;
114 var->green.length = 5;
115 var->blue.length = 5;
116 break;
Florian Tobias Schandinatbd140692010-03-10 15:21:38 -0800117 case 16:
118 var->bits_per_pixel = 16;
119 var->red.offset = 11;
120 var->green.offset = 5;
121 var->blue.offset = 0;
122 var->red.length = 5;
123 var->green.length = 6;
124 var->blue.length = 5;
125 break;
126 case 24:
127 var->bits_per_pixel = 32;
128 var->red.offset = 16;
129 var->green.offset = 8;
130 var->blue.offset = 0;
131 var->red.length = 8;
132 var->green.length = 8;
133 var->blue.length = 8;
134 break;
Florian Tobias Schandinate17cea32010-03-10 15:21:41 -0800135 case 30:
136 var->bits_per_pixel = 32;
137 var->red.offset = 20;
138 var->green.offset = 10;
139 var->blue.offset = 0;
140 var->red.length = 10;
141 var->green.length = 10;
142 var->blue.length = 10;
143 break;
Florian Tobias Schandinatbd140692010-03-10 15:21:38 -0800144 }
145}
146
Florian Tobias Schandinat81228a32009-09-22 16:47:13 -0700147static void viafb_update_fix(struct fb_info *info)
Joseph Chan29b619f2008-10-15 22:03:27 -0700148{
Florian Tobias Schandinat81228a32009-09-22 16:47:13 -0700149 u32 bpp = info->var.bits_per_pixel;
Joseph Chan29b619f2008-10-15 22:03:27 -0700150
Florian Tobias Schandinat81228a32009-09-22 16:47:13 -0700151 info->fix.visual =
152 bpp == 8 ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
Florian Tobias Schandinat936a3f72011-06-06 01:27:34 +0000153 info->fix.line_length = ALIGN(info->var.xres_virtual * bpp / 8,
154 VIA_PITCH_SIZE);
Joseph Chan29b619f2008-10-15 22:03:27 -0700155}
156
Joseph Chan29b619f2008-10-15 22:03:27 -0700157static void viafb_setup_fixinfo(struct fb_fix_screeninfo *fix,
158 struct viafb_par *viaparinfo)
159{
160 memset(fix, 0, sizeof(struct fb_fix_screeninfo));
161 strcpy(fix->id, viafb_name);
162
163 fix->smem_start = viaparinfo->fbmem;
164 fix->smem_len = viaparinfo->fbmem_free;
Joseph Chan29b619f2008-10-15 22:03:27 -0700165
166 fix->type = FB_TYPE_PACKED_PIXELS;
167 fix->type_aux = 0;
Florian Tobias Schandinatbd140692010-03-10 15:21:38 -0800168 fix->visual = FB_VISUAL_TRUECOLOR;
Joseph Chan29b619f2008-10-15 22:03:27 -0700169
170 fix->xpanstep = fix->ywrapstep = 0;
171 fix->ypanstep = 1;
172
173 /* Just tell the accel name */
174 viafbinfo->fix.accel = FB_ACCEL_VIA_UNICHROME;
175}
176static int viafb_open(struct fb_info *info, int user)
177{
178 DEBUG_MSG(KERN_INFO "viafb_open!\n");
179 return 0;
180}
181
182static int viafb_release(struct fb_info *info, int user)
183{
184 DEBUG_MSG(KERN_INFO "viafb_release!\n");
185 return 0;
186}
187
Florian Tobias Schandinat726abbc2011-03-16 16:31:32 +0000188static inline int get_var_refresh(struct fb_var_screeninfo *var)
189{
190 u32 htotal, vtotal;
191
192 htotal = var->left_margin + var->xres + var->right_margin
193 + var->hsync_len;
194 vtotal = var->upper_margin + var->yres + var->lower_margin
195 + var->vsync_len;
196 return PICOS2KHZ(var->pixclock) * 1000 / (htotal * vtotal);
197}
198
Joseph Chan29b619f2008-10-15 22:03:27 -0700199static int viafb_check_var(struct fb_var_screeninfo *var,
200 struct fb_info *info)
201{
Florian Tobias Schandinat726abbc2011-03-16 16:31:32 +0000202 int depth, refresh;
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700203 struct viafb_par *ppar = info->par;
Florian Tobias Schandinat726abbc2011-03-16 16:31:32 +0000204 u32 line;
Joseph Chan29b619f2008-10-15 22:03:27 -0700205
206 DEBUG_MSG(KERN_INFO "viafb_check_var!\n");
207 /* Sanity check */
208 /* HW neither support interlacte nor double-scaned mode */
209 if (var->vmode & FB_VMODE_INTERLACED || var->vmode & FB_VMODE_DOUBLE)
210 return -EINVAL;
211
Florian Tobias Schandinat94715ba2011-08-06 23:04:43 +0000212 /* the refresh rate is not important here, as we only want to know
213 * whether the resolution exists
214 */
215 if (!viafb_get_best_mode(var->xres, var->yres, 60)) {
Joseph Chan29b619f2008-10-15 22:03:27 -0700216 DEBUG_MSG(KERN_INFO
217 "viafb: Mode %dx%dx%d not supported!!\n",
218 var->xres, var->yres, var->bits_per_pixel);
219 return -EINVAL;
220 }
221
Florian Tobias Schandinatbd140692010-03-10 15:21:38 -0800222 depth = fb_get_color_depth(var, &info->fix);
223 if (!depth)
224 depth = var->bits_per_pixel;
Joseph Chan29b619f2008-10-15 22:03:27 -0700225
Florian Tobias Schandinatbd140692010-03-10 15:21:38 -0800226 if (depth < 0 || depth > 32)
Joseph Chan29b619f2008-10-15 22:03:27 -0700227 return -EINVAL;
Florian Tobias Schandinatbd140692010-03-10 15:21:38 -0800228 else if (!depth)
229 depth = 24;
Florian Tobias Schandinate17cea32010-03-10 15:21:41 -0800230 else if (depth == 15 && viafb_dual_fb && ppar->iga_path == IGA1)
231 depth = 15;
232 else if (depth == 30)
233 depth = 30;
Florian Tobias Schandinatbd140692010-03-10 15:21:38 -0800234 else if (depth <= 8)
235 depth = 8;
236 else if (depth <= 16)
237 depth = 16;
238 else
239 depth = 24;
Joseph Chan29b619f2008-10-15 22:03:27 -0700240
Florian Tobias Schandinatbd140692010-03-10 15:21:38 -0800241 viafb_fill_var_color_info(var, depth);
Florian Tobias Schandinat936a3f72011-06-06 01:27:34 +0000242 if (var->xres_virtual < var->xres)
243 var->xres_virtual = var->xres;
244
245 line = ALIGN(var->xres_virtual * var->bits_per_pixel / 8,
246 VIA_PITCH_SIZE);
247 if (line > VIA_PITCH_MAX || line * var->yres_virtual > ppar->memsize)
Joseph Chan29b619f2008-10-15 22:03:27 -0700248 return -EINVAL;
249
250 /* Based on var passed in to calculate the refresh,
251 * because our driver use some modes special.
252 */
Florian Tobias Schandinat726abbc2011-03-16 16:31:32 +0000253 refresh = viafb_get_refresh(var->xres, var->yres,
254 get_var_refresh(var));
Joseph Chan29b619f2008-10-15 22:03:27 -0700255
256 /* Adjust var according to our driver's own table */
Florian Tobias Schandinat94715ba2011-08-06 23:04:43 +0000257 viafb_fill_var_timing_info(var,
258 viafb_get_best_mode(var->xres, var->yres, refresh));
Florian Tobias Schandinataf29a5b2010-07-23 11:32:25 +0000259 if (var->accel_flags & FB_ACCELF_TEXT &&
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600260 !ppar->shared->vdev->engine_mmio)
Florian Tobias Schandinataf29a5b2010-07-23 11:32:25 +0000261 var->accel_flags = 0;
Joseph Chan29b619f2008-10-15 22:03:27 -0700262
Joseph Chan29b619f2008-10-15 22:03:27 -0700263 return 0;
264}
265
266static int viafb_set_par(struct fb_info *info)
267{
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700268 struct viafb_par *viapar = info->par;
Florian Tobias Schandinat726abbc2011-03-16 16:31:32 +0000269 int refresh;
Joseph Chan29b619f2008-10-15 22:03:27 -0700270 DEBUG_MSG(KERN_INFO "viafb_set_par!\n");
271
Florian Tobias Schandinat65123c62010-07-13 17:58:06 +0000272 viafb_update_fix(info);
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700273 viapar->depth = fb_get_color_depth(&info->var, &info->fix);
Florian Tobias Schandinat5c9443e2010-03-10 15:21:34 -0800274 viafb_update_device_setting(viafbinfo->var.xres, viafbinfo->var.yres,
Florian Tobias Schandinat726abbc2011-03-16 16:31:32 +0000275 viafbinfo->var.bits_per_pixel, 0);
Joseph Chan29b619f2008-10-15 22:03:27 -0700276
Florian Tobias Schandinat5c9443e2010-03-10 15:21:34 -0800277 if (viafb_dual_fb) {
Florian Tobias Schandinat5c9443e2010-03-10 15:21:34 -0800278 viafb_update_device_setting(viafbinfo1->var.xres,
279 viafbinfo1->var.yres, viafbinfo1->var.bits_per_pixel,
Florian Tobias Schandinat726abbc2011-03-16 16:31:32 +0000280 1);
Florian Tobias Schandinat5c9443e2010-03-10 15:21:34 -0800281 } else if (viafb_SAMM_ON == 1) {
Joseph Chan29b619f2008-10-15 22:03:27 -0700282 DEBUG_MSG(KERN_INFO
283 "viafb_second_xres = %d, viafb_second_yres = %d, bpp = %d\n",
284 viafb_second_xres, viafb_second_yres, viafb_bpp1);
Joseph Chan29b619f2008-10-15 22:03:27 -0700285
286 viafb_update_device_setting(viafb_second_xres,
Florian Tobias Schandinat726abbc2011-03-16 16:31:32 +0000287 viafb_second_yres, viafb_bpp1, 1);
Joseph Chan29b619f2008-10-15 22:03:27 -0700288 }
289
Florian Tobias Schandinat838ac782012-02-26 10:51:51 +0000290 refresh = get_var_refresh(&info->var);
291 if (viafb_dual_fb && viapar->iga_path == IGA2) {
292 viafb_bpp1 = info->var.bits_per_pixel;
293 viafb_refresh1 = refresh;
294 } else {
295 viafb_bpp = info->var.bits_per_pixel;
296 viafb_refresh = refresh;
Joseph Chan29b619f2008-10-15 22:03:27 -0700297 }
298
Florian Tobias Schandinat838ac782012-02-26 10:51:51 +0000299 if (info->var.accel_flags & FB_ACCELF_TEXT)
300 info->flags &= ~FBINFO_HWACCEL_DISABLED;
301 else
302 info->flags |= FBINFO_HWACCEL_DISABLED;
303 viafb_setmode();
304 viafb_pan_display(&info->var, info);
305
Joseph Chan29b619f2008-10-15 22:03:27 -0700306 return 0;
307}
308
309/* Set one color register */
310static int viafb_setcolreg(unsigned regno, unsigned red, unsigned green,
311unsigned blue, unsigned transp, struct fb_info *info)
312{
Florian Tobias Schandinat415559f2010-03-10 15:21:40 -0800313 struct viafb_par *viapar = info->par;
314 u32 r, g, b;
Joseph Chan29b619f2008-10-15 22:03:27 -0700315
Florian Tobias Schandinat415559f2010-03-10 15:21:40 -0800316 if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR) {
317 if (regno > 255)
318 return -EINVAL;
Joseph Chan29b619f2008-10-15 22:03:27 -0700319
Florian Tobias Schandinat415559f2010-03-10 15:21:40 -0800320 if (!viafb_dual_fb || viapar->iga_path == IGA1)
321 viafb_set_primary_color_register(regno, red >> 8,
322 green >> 8, blue >> 8);
Joseph Chan29b619f2008-10-15 22:03:27 -0700323
Florian Tobias Schandinat415559f2010-03-10 15:21:40 -0800324 if (!viafb_dual_fb || viapar->iga_path == IGA2)
325 viafb_set_secondary_color_register(regno, red >> 8,
326 green >> 8, blue >> 8);
327 } else {
328 if (regno > 15)
329 return -EINVAL;
Joseph Chan29b619f2008-10-15 22:03:27 -0700330
Florian Tobias Schandinat415559f2010-03-10 15:21:40 -0800331 r = (red >> (16 - info->var.red.length))
332 << info->var.red.offset;
333 b = (blue >> (16 - info->var.blue.length))
334 << info->var.blue.offset;
335 g = (green >> (16 - info->var.green.length))
336 << info->var.green.offset;
337 ((u32 *) info->pseudo_palette)[regno] = r | g | b;
Joseph Chan29b619f2008-10-15 22:03:27 -0700338 }
339
340 return 0;
Joseph Chan29b619f2008-10-15 22:03:27 -0700341}
342
343static int viafb_pan_display(struct fb_var_screeninfo *var,
344 struct fb_info *info)
345{
Florian Tobias Schandinatee79d542010-03-10 15:21:32 -0800346 struct viafb_par *viapar = info->par;
Florian Tobias Schandinatd9339902011-05-23 21:39:58 +0000347 u32 vram_addr = viapar->vram_addr
348 + var->yoffset * info->fix.line_length
349 + var->xoffset * info->var.bits_per_pixel / 8;
Joseph Chan29b619f2008-10-15 22:03:27 -0700350
Florian Tobias Schandinatee79d542010-03-10 15:21:32 -0800351 DEBUG_MSG(KERN_DEBUG "viafb_pan_display, address = %d\n", vram_addr);
352 if (!viafb_dual_fb) {
Florian Tobias Schandinat27494132010-04-17 19:44:52 +0000353 via_set_primary_address(vram_addr);
354 via_set_secondary_address(vram_addr);
Florian Tobias Schandinatee79d542010-03-10 15:21:32 -0800355 } else if (viapar->iga_path == IGA1)
Florian Tobias Schandinat27494132010-04-17 19:44:52 +0000356 via_set_primary_address(vram_addr);
Florian Tobias Schandinatee79d542010-03-10 15:21:32 -0800357 else
Florian Tobias Schandinat27494132010-04-17 19:44:52 +0000358 via_set_secondary_address(vram_addr);
Joseph Chan29b619f2008-10-15 22:03:27 -0700359
Joseph Chan29b619f2008-10-15 22:03:27 -0700360 return 0;
361}
362
363static int viafb_blank(int blank_mode, struct fb_info *info)
364{
365 DEBUG_MSG(KERN_INFO "viafb_blank!\n");
366 /* clear DPMS setting */
367
368 switch (blank_mode) {
369 case FB_BLANK_UNBLANK:
370 /* Screen: On, HSync: On, VSync: On */
371 /* control CRT monitor power management */
Florian Tobias Schandinat6f9422d2010-09-07 14:28:26 +0000372 via_set_state(VIA_CRT, VIA_STATE_ON);
Joseph Chan29b619f2008-10-15 22:03:27 -0700373 break;
374 case FB_BLANK_HSYNC_SUSPEND:
375 /* Screen: Off, HSync: Off, VSync: On */
376 /* control CRT monitor power management */
Florian Tobias Schandinat6f9422d2010-09-07 14:28:26 +0000377 via_set_state(VIA_CRT, VIA_STATE_STANDBY);
Joseph Chan29b619f2008-10-15 22:03:27 -0700378 break;
379 case FB_BLANK_VSYNC_SUSPEND:
380 /* Screen: Off, HSync: On, VSync: Off */
381 /* control CRT monitor power management */
Florian Tobias Schandinat6f9422d2010-09-07 14:28:26 +0000382 via_set_state(VIA_CRT, VIA_STATE_SUSPEND);
Joseph Chan29b619f2008-10-15 22:03:27 -0700383 break;
384 case FB_BLANK_POWERDOWN:
385 /* Screen: Off, HSync: Off, VSync: Off */
386 /* control CRT monitor power management */
Florian Tobias Schandinat6f9422d2010-09-07 14:28:26 +0000387 via_set_state(VIA_CRT, VIA_STATE_OFF);
Joseph Chan29b619f2008-10-15 22:03:27 -0700388 break;
389 }
390
391 return 0;
392}
393
394static int viafb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
395{
Bruno Prémonte687d692009-01-04 13:11:54 -0800396 union {
397 struct viafb_ioctl_mode viamode;
398 struct viafb_ioctl_samm viasamm;
399 struct viafb_driver_version driver_version;
400 struct fb_var_screeninfo sec_var;
401 struct _panel_size_pos_info panel_pos_size_para;
402 struct viafb_ioctl_setting viafb_setting;
403 struct device_t active_dev;
404 } u;
Joseph Chan29b619f2008-10-15 22:03:27 -0700405 u32 state_info = 0;
Joseph Chan29b619f2008-10-15 22:03:27 -0700406 u32 *viafb_gamma_table;
407 char driver_name[] = "viafb";
408
409 u32 __user *argp = (u32 __user *) arg;
410 u32 gpu32;
Joseph Chan29b619f2008-10-15 22:03:27 -0700411
412 DEBUG_MSG(KERN_INFO "viafb_ioctl: 0x%X !!\n", cmd);
Florian Tobias Schandinatcc8b82f2010-03-10 15:21:26 -0800413 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 -0800414 memset(&u, 0, sizeof(u));
Joseph Chan29b619f2008-10-15 22:03:27 -0700415
416 switch (cmd) {
417 case VIAFB_GET_CHIP_INFO:
418 if (copy_to_user(argp, viaparinfo->chip_info,
419 sizeof(struct chip_information)))
420 return -EFAULT;
421 break;
422 case VIAFB_GET_INFO_SIZE:
Bruno Prémonte687d692009-01-04 13:11:54 -0800423 return put_user((u32)sizeof(struct viafb_ioctl_info), argp);
Joseph Chan29b619f2008-10-15 22:03:27 -0700424 case VIAFB_GET_INFO:
425 return viafb_ioctl_get_viafb_info(arg);
426 case VIAFB_HOTPLUG:
427 return put_user(viafb_ioctl_hotplug(info->var.xres,
428 info->var.yres,
429 info->var.bits_per_pixel), argp);
430 case VIAFB_SET_HOTPLUG_FLAG:
431 if (copy_from_user(&gpu32, argp, sizeof(gpu32)))
432 return -EFAULT;
433 viafb_hotplug = (gpu32) ? 1 : 0;
434 break;
435 case VIAFB_GET_RESOLUTION:
Bruno Prémonte687d692009-01-04 13:11:54 -0800436 u.viamode.xres = (u32) viafb_hotplug_Xres;
437 u.viamode.yres = (u32) viafb_hotplug_Yres;
438 u.viamode.refresh = (u32) viafb_hotplug_refresh;
439 u.viamode.bpp = (u32) viafb_hotplug_bpp;
Joseph Chan29b619f2008-10-15 22:03:27 -0700440 if (viafb_SAMM_ON == 1) {
Bruno Prémonte687d692009-01-04 13:11:54 -0800441 u.viamode.xres_sec = viafb_second_xres;
442 u.viamode.yres_sec = viafb_second_yres;
Florian Tobias Schandinat7f980a02011-03-27 02:54:32 +0000443 u.viamode.virtual_xres_sec = viafb_dual_fb ? viafbinfo1->var.xres_virtual : viafbinfo->var.xres_virtual;
444 u.viamode.virtual_yres_sec = viafb_dual_fb ? viafbinfo1->var.yres_virtual : viafbinfo->var.yres_virtual;
Bruno Prémonte687d692009-01-04 13:11:54 -0800445 u.viamode.refresh_sec = viafb_refresh1;
446 u.viamode.bpp_sec = viafb_bpp1;
Joseph Chan29b619f2008-10-15 22:03:27 -0700447 } else {
Bruno Prémonte687d692009-01-04 13:11:54 -0800448 u.viamode.xres_sec = 0;
449 u.viamode.yres_sec = 0;
450 u.viamode.virtual_xres_sec = 0;
451 u.viamode.virtual_yres_sec = 0;
452 u.viamode.refresh_sec = 0;
453 u.viamode.bpp_sec = 0;
Joseph Chan29b619f2008-10-15 22:03:27 -0700454 }
Bruno Prémonte687d692009-01-04 13:11:54 -0800455 if (copy_to_user(argp, &u.viamode, sizeof(u.viamode)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700456 return -EFAULT;
457 break;
458 case VIAFB_GET_SAMM_INFO:
Bruno Prémonte687d692009-01-04 13:11:54 -0800459 u.viasamm.samm_status = viafb_SAMM_ON;
Joseph Chan29b619f2008-10-15 22:03:27 -0700460
461 if (viafb_SAMM_ON == 1) {
462 if (viafb_dual_fb) {
Bruno Prémonte687d692009-01-04 13:11:54 -0800463 u.viasamm.size_prim = viaparinfo->fbmem_free;
464 u.viasamm.size_sec = viaparinfo1->fbmem_free;
Joseph Chan29b619f2008-10-15 22:03:27 -0700465 } else {
466 if (viafb_second_size) {
Bruno Prémonte687d692009-01-04 13:11:54 -0800467 u.viasamm.size_prim =
Joseph Chan29b619f2008-10-15 22:03:27 -0700468 viaparinfo->fbmem_free -
469 viafb_second_size * 1024 * 1024;
Bruno Prémonte687d692009-01-04 13:11:54 -0800470 u.viasamm.size_sec =
Joseph Chan29b619f2008-10-15 22:03:27 -0700471 viafb_second_size * 1024 * 1024;
472 } else {
Bruno Prémonte687d692009-01-04 13:11:54 -0800473 u.viasamm.size_prim =
Joseph Chan29b619f2008-10-15 22:03:27 -0700474 viaparinfo->fbmem_free >> 1;
Bruno Prémonte687d692009-01-04 13:11:54 -0800475 u.viasamm.size_sec =
Joseph Chan29b619f2008-10-15 22:03:27 -0700476 (viaparinfo->fbmem_free >> 1);
477 }
478 }
Bruno Prémonte687d692009-01-04 13:11:54 -0800479 u.viasamm.mem_base = viaparinfo->fbmem;
480 u.viasamm.offset_sec = viafb_second_offset;
Joseph Chan29b619f2008-10-15 22:03:27 -0700481 } else {
Bruno Prémonte687d692009-01-04 13:11:54 -0800482 u.viasamm.size_prim =
Joseph Chan29b619f2008-10-15 22:03:27 -0700483 viaparinfo->memsize - viaparinfo->fbmem_used;
Bruno Prémonte687d692009-01-04 13:11:54 -0800484 u.viasamm.size_sec = 0;
485 u.viasamm.mem_base = viaparinfo->fbmem;
486 u.viasamm.offset_sec = 0;
Joseph Chan29b619f2008-10-15 22:03:27 -0700487 }
488
Bruno Prémonte687d692009-01-04 13:11:54 -0800489 if (copy_to_user(argp, &u.viasamm, sizeof(u.viasamm)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700490 return -EFAULT;
491
492 break;
493 case VIAFB_TURN_ON_OUTPUT_DEVICE:
494 if (copy_from_user(&gpu32, argp, sizeof(gpu32)))
495 return -EFAULT;
496 if (gpu32 & CRT_Device)
Florian Tobias Schandinat6f9422d2010-09-07 14:28:26 +0000497 via_set_state(VIA_CRT, VIA_STATE_ON);
Joseph Chan29b619f2008-10-15 22:03:27 -0700498 if (gpu32 & DVI_Device)
499 viafb_dvi_enable();
500 if (gpu32 & LCD_Device)
501 viafb_lcd_enable();
502 break;
503 case VIAFB_TURN_OFF_OUTPUT_DEVICE:
504 if (copy_from_user(&gpu32, argp, sizeof(gpu32)))
505 return -EFAULT;
506 if (gpu32 & CRT_Device)
Florian Tobias Schandinat6f9422d2010-09-07 14:28:26 +0000507 via_set_state(VIA_CRT, VIA_STATE_OFF);
Joseph Chan29b619f2008-10-15 22:03:27 -0700508 if (gpu32 & DVI_Device)
509 viafb_dvi_disable();
510 if (gpu32 & LCD_Device)
511 viafb_lcd_disable();
512 break;
Joseph Chan29b619f2008-10-15 22:03:27 -0700513 case VIAFB_GET_DEVICE:
Bruno Prémonte687d692009-01-04 13:11:54 -0800514 u.active_dev.crt = viafb_CRT_ON;
515 u.active_dev.dvi = viafb_DVI_ON;
516 u.active_dev.lcd = viafb_LCD_ON;
517 u.active_dev.samm = viafb_SAMM_ON;
518 u.active_dev.primary_dev = viafb_primary_dev;
Joseph Chan29b619f2008-10-15 22:03:27 -0700519
Bruno Prémonte687d692009-01-04 13:11:54 -0800520 u.active_dev.lcd_dsp_cent = viafb_lcd_dsp_method;
521 u.active_dev.lcd_panel_id = viafb_lcd_panel_id;
522 u.active_dev.lcd_mode = viafb_lcd_mode;
Joseph Chan29b619f2008-10-15 22:03:27 -0700523
Bruno Prémonte687d692009-01-04 13:11:54 -0800524 u.active_dev.xres = viafb_hotplug_Xres;
525 u.active_dev.yres = viafb_hotplug_Yres;
Joseph Chan29b619f2008-10-15 22:03:27 -0700526
Bruno Prémonte687d692009-01-04 13:11:54 -0800527 u.active_dev.xres1 = viafb_second_xres;
528 u.active_dev.yres1 = viafb_second_yres;
Joseph Chan29b619f2008-10-15 22:03:27 -0700529
Bruno Prémonte687d692009-01-04 13:11:54 -0800530 u.active_dev.bpp = viafb_bpp;
531 u.active_dev.bpp1 = viafb_bpp1;
532 u.active_dev.refresh = viafb_refresh;
533 u.active_dev.refresh1 = viafb_refresh1;
Joseph Chan29b619f2008-10-15 22:03:27 -0700534
Bruno Prémonte687d692009-01-04 13:11:54 -0800535 u.active_dev.epia_dvi = viafb_platform_epia_dvi;
536 u.active_dev.lcd_dual_edge = viafb_device_lcd_dualedge;
537 u.active_dev.bus_width = viafb_bus_width;
Joseph Chan29b619f2008-10-15 22:03:27 -0700538
Bruno Prémonte687d692009-01-04 13:11:54 -0800539 if (copy_to_user(argp, &u.active_dev, sizeof(u.active_dev)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700540 return -EFAULT;
541 break;
542
543 case VIAFB_GET_DRIVER_VERSION:
Bruno Prémonte687d692009-01-04 13:11:54 -0800544 u.driver_version.iMajorNum = VERSION_MAJOR;
545 u.driver_version.iKernelNum = VERSION_KERNEL;
546 u.driver_version.iOSNum = VERSION_OS;
547 u.driver_version.iMinorNum = VERSION_MINOR;
Joseph Chan29b619f2008-10-15 22:03:27 -0700548
Bruno Prémonte687d692009-01-04 13:11:54 -0800549 if (copy_to_user(argp, &u.driver_version,
550 sizeof(u.driver_version)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700551 return -EFAULT;
552
553 break;
554
Joseph Chan29b619f2008-10-15 22:03:27 -0700555 case VIAFB_GET_DEVICE_INFO:
556
Bruno Prémonte687d692009-01-04 13:11:54 -0800557 retrieve_device_setting(&u.viafb_setting);
Joseph Chan29b619f2008-10-15 22:03:27 -0700558
Bruno Prémonte687d692009-01-04 13:11:54 -0800559 if (copy_to_user(argp, &u.viafb_setting,
560 sizeof(u.viafb_setting)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700561 return -EFAULT;
562
563 break;
564
565 case VIAFB_GET_DEVICE_SUPPORT:
566 viafb_get_device_support_state(&state_info);
567 if (put_user(state_info, argp))
568 return -EFAULT;
569 break;
570
571 case VIAFB_GET_DEVICE_CONNECT:
572 viafb_get_device_connect_state(&state_info);
573 if (put_user(state_info, argp))
574 return -EFAULT;
575 break;
576
577 case VIAFB_GET_PANEL_SUPPORT_EXPAND:
578 state_info =
579 viafb_lcd_get_support_expand_state(info->var.xres,
580 info->var.yres);
581 if (put_user(state_info, argp))
582 return -EFAULT;
583 break;
584
585 case VIAFB_GET_DRIVER_NAME:
586 if (copy_to_user(argp, driver_name, sizeof(driver_name)))
587 return -EFAULT;
588 break;
589
590 case VIAFB_SET_GAMMA_LUT:
Julia Lawalla51faab2010-05-26 14:42:29 -0700591 viafb_gamma_table = memdup_user(argp, 256 * sizeof(u32));
592 if (IS_ERR(viafb_gamma_table))
593 return PTR_ERR(viafb_gamma_table);
Joseph Chan29b619f2008-10-15 22:03:27 -0700594 viafb_set_gamma_table(viafb_bpp, viafb_gamma_table);
595 kfree(viafb_gamma_table);
596 break;
597
598 case VIAFB_GET_GAMMA_LUT:
599 viafb_gamma_table = kmalloc(256 * sizeof(u32), GFP_KERNEL);
600 if (!viafb_gamma_table)
601 return -ENOMEM;
602 viafb_get_gamma_table(viafb_gamma_table);
603 if (copy_to_user(argp, viafb_gamma_table,
Julia Lawall0f050582009-12-17 15:27:09 -0800604 256 * sizeof(u32))) {
Joseph Chan29b619f2008-10-15 22:03:27 -0700605 kfree(viafb_gamma_table);
606 return -EFAULT;
607 }
608 kfree(viafb_gamma_table);
609 break;
610
611 case VIAFB_GET_GAMMA_SUPPORT_STATE:
612 viafb_get_gamma_support_state(viafb_bpp, &state_info);
613 if (put_user(state_info, argp))
614 return -EFAULT;
615 break;
Joseph Chan29b619f2008-10-15 22:03:27 -0700616 case VIAFB_SYNC_SURFACE:
617 DEBUG_MSG(KERN_INFO "lobo VIAFB_SYNC_SURFACE\n");
618 break;
619 case VIAFB_GET_DRIVER_CAPS:
620 break;
621
622 case VIAFB_GET_PANEL_MAX_SIZE:
Bruno Prémonte687d692009-01-04 13:11:54 -0800623 if (copy_from_user(&u.panel_pos_size_para, argp,
624 sizeof(u.panel_pos_size_para)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700625 return -EFAULT;
Bruno Prémonte687d692009-01-04 13:11:54 -0800626 u.panel_pos_size_para.x = u.panel_pos_size_para.y = 0;
627 if (copy_to_user(argp, &u.panel_pos_size_para,
628 sizeof(u.panel_pos_size_para)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700629 return -EFAULT;
630 break;
631 case VIAFB_GET_PANEL_MAX_POSITION:
Bruno Prémonte687d692009-01-04 13:11:54 -0800632 if (copy_from_user(&u.panel_pos_size_para, argp,
633 sizeof(u.panel_pos_size_para)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700634 return -EFAULT;
Bruno Prémonte687d692009-01-04 13:11:54 -0800635 u.panel_pos_size_para.x = u.panel_pos_size_para.y = 0;
636 if (copy_to_user(argp, &u.panel_pos_size_para,
637 sizeof(u.panel_pos_size_para)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700638 return -EFAULT;
639 break;
640
641 case VIAFB_GET_PANEL_POSITION:
Bruno Prémonte687d692009-01-04 13:11:54 -0800642 if (copy_from_user(&u.panel_pos_size_para, argp,
643 sizeof(u.panel_pos_size_para)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700644 return -EFAULT;
Bruno Prémonte687d692009-01-04 13:11:54 -0800645 u.panel_pos_size_para.x = u.panel_pos_size_para.y = 0;
646 if (copy_to_user(argp, &u.panel_pos_size_para,
647 sizeof(u.panel_pos_size_para)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700648 return -EFAULT;
649 break;
650 case VIAFB_GET_PANEL_SIZE:
Bruno Prémonte687d692009-01-04 13:11:54 -0800651 if (copy_from_user(&u.panel_pos_size_para, argp,
652 sizeof(u.panel_pos_size_para)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700653 return -EFAULT;
Bruno Prémonte687d692009-01-04 13:11:54 -0800654 u.panel_pos_size_para.x = u.panel_pos_size_para.y = 0;
655 if (copy_to_user(argp, &u.panel_pos_size_para,
656 sizeof(u.panel_pos_size_para)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700657 return -EFAULT;
658 break;
659
660 case VIAFB_SET_PANEL_POSITION:
Bruno Prémonte687d692009-01-04 13:11:54 -0800661 if (copy_from_user(&u.panel_pos_size_para, argp,
662 sizeof(u.panel_pos_size_para)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700663 return -EFAULT;
664 break;
665 case VIAFB_SET_PANEL_SIZE:
Bruno Prémonte687d692009-01-04 13:11:54 -0800666 if (copy_from_user(&u.panel_pos_size_para, argp,
667 sizeof(u.panel_pos_size_para)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700668 return -EFAULT;
669 break;
670
671 default:
672 return -EINVAL;
673 }
674
675 return 0;
676}
677
678static void viafb_fillrect(struct fb_info *info,
679 const struct fb_fillrect *rect)
680{
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700681 struct viafb_par *viapar = info->par;
Florian Tobias Schandinat31de59d2009-09-22 16:47:31 -0700682 struct viafb_shared *shared = viapar->shared;
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700683 u32 fg_color;
684 u8 rop;
Joseph Chan29b619f2008-10-15 22:03:27 -0700685
Florian Tobias Schandinat31de59d2009-09-22 16:47:31 -0700686 if (info->flags & FBINFO_HWACCEL_DISABLED || !shared->hw_bitblt) {
Hannes Eder2899bb02009-01-06 14:42:32 -0800687 cfb_fillrect(info, rect);
688 return;
689 }
Joseph Chan29b619f2008-10-15 22:03:27 -0700690
691 if (!rect->width || !rect->height)
692 return;
693
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700694 if (info->fix.visual == FB_VISUAL_TRUECOLOR)
695 fg_color = ((u32 *)info->pseudo_palette)[rect->color];
696 else
697 fg_color = rect->color;
698
699 if (rect->rop == ROP_XOR)
Joseph Chan29b619f2008-10-15 22:03:27 -0700700 rop = 0x5A;
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700701 else
Joseph Chan29b619f2008-10-15 22:03:27 -0700702 rop = 0xF0;
Joseph Chan29b619f2008-10-15 22:03:27 -0700703
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700704 DEBUG_MSG(KERN_DEBUG "viafb 2D engine: fillrect\n");
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600705 if (shared->hw_bitblt(shared->vdev->engine_mmio, VIA_BITBLT_FILL,
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700706 rect->width, rect->height, info->var.bits_per_pixel,
707 viapar->vram_addr, info->fix.line_length, rect->dx, rect->dy,
708 NULL, 0, 0, 0, 0, fg_color, 0, rop))
709 cfb_fillrect(info, rect);
Joseph Chan29b619f2008-10-15 22:03:27 -0700710}
711
712static void viafb_copyarea(struct fb_info *info,
713 const struct fb_copyarea *area)
714{
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700715 struct viafb_par *viapar = info->par;
Florian Tobias Schandinat31de59d2009-09-22 16:47:31 -0700716 struct viafb_shared *shared = viapar->shared;
Joseph Chan29b619f2008-10-15 22:03:27 -0700717
Florian Tobias Schandinat31de59d2009-09-22 16:47:31 -0700718 if (info->flags & FBINFO_HWACCEL_DISABLED || !shared->hw_bitblt) {
Hannes Eder2899bb02009-01-06 14:42:32 -0800719 cfb_copyarea(info, area);
720 return;
721 }
Joseph Chan29b619f2008-10-15 22:03:27 -0700722
723 if (!area->width || !area->height)
724 return;
725
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700726 DEBUG_MSG(KERN_DEBUG "viafb 2D engine: copyarea\n");
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600727 if (shared->hw_bitblt(shared->vdev->engine_mmio, VIA_BITBLT_COLOR,
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700728 area->width, area->height, info->var.bits_per_pixel,
729 viapar->vram_addr, info->fix.line_length, area->dx, area->dy,
730 NULL, viapar->vram_addr, info->fix.line_length,
731 area->sx, area->sy, 0, 0, 0))
732 cfb_copyarea(info, area);
Joseph Chan29b619f2008-10-15 22:03:27 -0700733}
734
735static void viafb_imageblit(struct fb_info *info,
736 const struct fb_image *image)
737{
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700738 struct viafb_par *viapar = info->par;
Florian Tobias Schandinat31de59d2009-09-22 16:47:31 -0700739 struct viafb_shared *shared = viapar->shared;
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700740 u32 fg_color = 0, bg_color = 0;
741 u8 op;
Joseph Chan29b619f2008-10-15 22:03:27 -0700742
Florian Tobias Schandinat31de59d2009-09-22 16:47:31 -0700743 if (info->flags & FBINFO_HWACCEL_DISABLED || !shared->hw_bitblt ||
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700744 (image->depth != 1 && image->depth != viapar->depth)) {
Hannes Eder2899bb02009-01-06 14:42:32 -0800745 cfb_imageblit(info, image);
746 return;
747 }
Joseph Chan29b619f2008-10-15 22:03:27 -0700748
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700749 if (image->depth == 1) {
750 op = VIA_BITBLT_MONO;
751 if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
752 fg_color =
753 ((u32 *)info->pseudo_palette)[image->fg_color];
754 bg_color =
755 ((u32 *)info->pseudo_palette)[image->bg_color];
756 } else {
757 fg_color = image->fg_color;
758 bg_color = image->bg_color;
759 }
760 } else
761 op = VIA_BITBLT_COLOR;
Joseph Chan29b619f2008-10-15 22:03:27 -0700762
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700763 DEBUG_MSG(KERN_DEBUG "viafb 2D engine: imageblit\n");
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600764 if (shared->hw_bitblt(shared->vdev->engine_mmio, op,
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -0700765 image->width, image->height, info->var.bits_per_pixel,
766 viapar->vram_addr, info->fix.line_length, image->dx, image->dy,
767 (u32 *)image->data, 0, 0, 0, 0, fg_color, bg_color, 0))
768 cfb_imageblit(info, image);
Joseph Chan29b619f2008-10-15 22:03:27 -0700769}
770
771static int viafb_cursor(struct fb_info *info, struct fb_cursor *cursor)
772{
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700773 struct viafb_par *viapar = info->par;
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600774 void __iomem *engine = viapar->shared->vdev->engine_mmio;
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700775 u32 temp, xx, yy, bg_color = 0, fg_color = 0,
776 chip_name = viapar->shared->chip_info.gfx_chip_name;
777 int i, j = 0, cur_size = 64;
Joseph Chan29b619f2008-10-15 22:03:27 -0700778
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700779 if (info->flags & FBINFO_HWACCEL_DISABLED || info != viafbinfo)
Joseph Chan29b619f2008-10-15 22:03:27 -0700780 return -ENODEV;
781
Florian Tobias Schandinat0b941902010-01-15 17:01:03 -0800782 /* LCD ouput does not support hw cursors (at least on VN896) */
783 if ((chip_name == UNICHROME_CLE266 && viapar->iga_path == IGA2) ||
784 viafb_LCD_ON)
Joseph Chan29b619f2008-10-15 22:03:27 -0700785 return -ENODEV;
786
787 viafb_show_hw_cursor(info, HW_Cursor_OFF);
Joseph Chan29b619f2008-10-15 22:03:27 -0700788
789 if (cursor->set & FB_CUR_SETHOT) {
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700790 temp = (cursor->hot.x << 16) + cursor->hot.y;
Florian Tobias Schandinat31de59d2009-09-22 16:47:31 -0700791 writel(temp, engine + VIA_REG_CURSOR_ORG);
Joseph Chan29b619f2008-10-15 22:03:27 -0700792 }
793
794 if (cursor->set & FB_CUR_SETPOS) {
Joseph Chan29b619f2008-10-15 22:03:27 -0700795 yy = cursor->image.dy - info->var.yoffset;
796 xx = cursor->image.dx - info->var.xoffset;
797 temp = yy & 0xFFFF;
798 temp |= (xx << 16);
Florian Tobias Schandinat31de59d2009-09-22 16:47:31 -0700799 writel(temp, engine + VIA_REG_CURSOR_POS);
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700800 }
801
802 if (cursor->image.width <= 32 && cursor->image.height <= 32)
803 cur_size = 32;
804 else if (cursor->image.width <= 64 && cursor->image.height <= 64)
805 cur_size = 64;
806 else {
807 printk(KERN_WARNING "viafb_cursor: The cursor is too large "
808 "%dx%d", cursor->image.width, cursor->image.height);
809 return -ENXIO;
Joseph Chan29b619f2008-10-15 22:03:27 -0700810 }
811
812 if (cursor->set & FB_CUR_SETSIZE) {
Florian Tobias Schandinat31de59d2009-09-22 16:47:31 -0700813 temp = readl(engine + VIA_REG_CURSOR_MODE);
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700814 if (cur_size == 32)
Joseph Chan29b619f2008-10-15 22:03:27 -0700815 temp |= 0x2;
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700816 else
817 temp &= ~0x2;
Joseph Chan29b619f2008-10-15 22:03:27 -0700818
Florian Tobias Schandinat31de59d2009-09-22 16:47:31 -0700819 writel(temp, engine + VIA_REG_CURSOR_MODE);
Joseph Chan29b619f2008-10-15 22:03:27 -0700820 }
821
822 if (cursor->set & FB_CUR_SETCMAP) {
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700823 fg_color = cursor->image.fg_color;
824 bg_color = cursor->image.bg_color;
825 if (chip_name == UNICHROME_CX700 ||
Harald Welte0306ab12009-09-22 16:47:35 -0700826 chip_name == UNICHROME_VX800 ||
Florian Tobias Schandinat51f43322010-10-24 04:02:14 +0000827 chip_name == UNICHROME_VX855 ||
828 chip_name == UNICHROME_VX900) {
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700829 fg_color =
830 ((info->cmap.red[fg_color] & 0xFFC0) << 14) |
831 ((info->cmap.green[fg_color] & 0xFFC0) << 4) |
832 ((info->cmap.blue[fg_color] & 0xFFC0) >> 6);
833 bg_color =
834 ((info->cmap.red[bg_color] & 0xFFC0) << 14) |
835 ((info->cmap.green[bg_color] & 0xFFC0) << 4) |
836 ((info->cmap.blue[bg_color] & 0xFFC0) >> 6);
837 } else {
838 fg_color =
839 ((info->cmap.red[fg_color] & 0xFF00) << 8) |
840 (info->cmap.green[fg_color] & 0xFF00) |
841 ((info->cmap.blue[fg_color] & 0xFF00) >> 8);
842 bg_color =
843 ((info->cmap.red[bg_color] & 0xFF00) << 8) |
844 (info->cmap.green[bg_color] & 0xFF00) |
845 ((info->cmap.blue[bg_color] & 0xFF00) >> 8);
Joseph Chan29b619f2008-10-15 22:03:27 -0700846 }
847
Florian Tobias Schandinat31de59d2009-09-22 16:47:31 -0700848 writel(bg_color, engine + VIA_REG_CURSOR_BG);
849 writel(fg_color, engine + VIA_REG_CURSOR_FG);
Joseph Chan29b619f2008-10-15 22:03:27 -0700850 }
851
852 if (cursor->set & FB_CUR_SETSHAPE) {
Bruno Prémonte687d692009-01-04 13:11:54 -0800853 struct {
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700854 u8 data[CURSOR_SIZE];
855 u32 bak[CURSOR_SIZE / 4];
Bruno Prémonte687d692009-01-04 13:11:54 -0800856 } *cr_data = kzalloc(sizeof(*cr_data), GFP_ATOMIC);
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700857 int size = ((cursor->image.width + 7) >> 3) *
858 cursor->image.height;
Joseph Chan29b619f2008-10-15 22:03:27 -0700859
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700860 if (!cr_data)
861 return -ENOMEM;
Bruno Prémonte687d692009-01-04 13:11:54 -0800862
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700863 if (cur_size == 32) {
864 for (i = 0; i < (CURSOR_SIZE / 4); i++) {
Bruno Prémonte687d692009-01-04 13:11:54 -0800865 cr_data->bak[i] = 0x0;
866 cr_data->bak[i + 1] = 0xFFFFFFFF;
Joseph Chan29b619f2008-10-15 22:03:27 -0700867 i += 1;
868 }
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700869 } else {
870 for (i = 0; i < (CURSOR_SIZE / 4); i++) {
Bruno Prémonte687d692009-01-04 13:11:54 -0800871 cr_data->bak[i] = 0x0;
872 cr_data->bak[i + 1] = 0x0;
873 cr_data->bak[i + 2] = 0xFFFFFFFF;
874 cr_data->bak[i + 3] = 0xFFFFFFFF;
Joseph Chan29b619f2008-10-15 22:03:27 -0700875 i += 3;
876 }
877 }
878
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700879 switch (cursor->rop) {
Joseph Chan29b619f2008-10-15 22:03:27 -0700880 case ROP_XOR:
881 for (i = 0; i < size; i++)
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700882 cr_data->data[i] = cursor->mask[i];
Joseph Chan29b619f2008-10-15 22:03:27 -0700883 break;
884 case ROP_COPY:
885
886 for (i = 0; i < size; i++)
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700887 cr_data->data[i] = cursor->mask[i];
Joseph Chan29b619f2008-10-15 22:03:27 -0700888 break;
889 default:
890 break;
891 }
892
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700893 if (cur_size == 32) {
Joseph Chan29b619f2008-10-15 22:03:27 -0700894 for (i = 0; i < size; i++) {
Bruno Prémonte687d692009-01-04 13:11:54 -0800895 cr_data->bak[j] = (u32) cr_data->data[i];
896 cr_data->bak[j + 1] = ~cr_data->bak[j];
Joseph Chan29b619f2008-10-15 22:03:27 -0700897 j += 2;
898 }
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700899 } else {
Joseph Chan29b619f2008-10-15 22:03:27 -0700900 for (i = 0; i < size; i++) {
Bruno Prémonte687d692009-01-04 13:11:54 -0800901 cr_data->bak[j] = (u32) cr_data->data[i];
902 cr_data->bak[j + 1] = 0x0;
903 cr_data->bak[j + 2] = ~cr_data->bak[j];
904 cr_data->bak[j + 3] = ~cr_data->bak[j + 1];
Joseph Chan29b619f2008-10-15 22:03:27 -0700905 j += 4;
906 }
907 }
908
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700909 memcpy_toio(viafbinfo->screen_base + viapar->shared->
910 cursor_vram_addr, cr_data->bak, CURSOR_SIZE);
Bruno Prémonte687d692009-01-04 13:11:54 -0800911 kfree(cr_data);
Joseph Chan29b619f2008-10-15 22:03:27 -0700912 }
913
Florian Tobias Schandinat5016af532009-09-22 16:47:28 -0700914 if (cursor->enable)
Joseph Chan29b619f2008-10-15 22:03:27 -0700915 viafb_show_hw_cursor(info, HW_Cursor_ON);
916
917 return 0;
918}
919
920static int viafb_sync(struct fb_info *info)
921{
Florian Tobias Schandinat31de59d2009-09-22 16:47:31 -0700922 if (!(info->flags & FBINFO_HWACCEL_DISABLED))
923 viafb_wait_engine_idle(info);
Joseph Chan29b619f2008-10-15 22:03:27 -0700924 return 0;
925}
926
Joseph Chan29b619f2008-10-15 22:03:27 -0700927static int get_primary_device(void)
928{
929 int primary_device = 0;
930 /* Rule: device on iga1 path are the primary device. */
931 if (viafb_SAMM_ON) {
932 if (viafb_CRT_ON) {
Florian Tobias Schandinat05236562011-03-21 01:46:24 +0000933 if (viaparinfo->shared->iga1_devices & VIA_CRT) {
934 DEBUG_MSG(KERN_INFO "CRT IGA Path:%d\n", IGA1);
Joseph Chan29b619f2008-10-15 22:03:27 -0700935 primary_device = CRT_Device;
936 }
937 }
938 if (viafb_DVI_ON) {
939 if (viaparinfo->tmds_setting_info->iga_path == IGA1) {
940 DEBUG_MSG(KERN_INFO "DVI IGA Path:%d\n",
941 viaparinfo->
942 tmds_setting_info->iga_path);
943 primary_device = DVI_Device;
944 }
945 }
946 if (viafb_LCD_ON) {
947 if (viaparinfo->lvds_setting_info->iga_path == IGA1) {
948 DEBUG_MSG(KERN_INFO "LCD IGA Path:%d\n",
949 viaparinfo->
950 lvds_setting_info->iga_path);
951 primary_device = LCD_Device;
952 }
953 }
954 if (viafb_LCD2_ON) {
955 if (viaparinfo->lvds_setting_info2->iga_path == IGA1) {
956 DEBUG_MSG(KERN_INFO "LCD2 IGA Path:%d\n",
957 viaparinfo->
958 lvds_setting_info2->iga_path);
959 primary_device = LCD2_Device;
960 }
961 }
962 }
963 return primary_device;
964}
965
Joseph Chan29b619f2008-10-15 22:03:27 -0700966static void retrieve_device_setting(struct viafb_ioctl_setting
967 *setting_info)
968{
969
970 /* get device status */
971 if (viafb_CRT_ON == 1)
972 setting_info->device_status = CRT_Device;
973 if (viafb_DVI_ON == 1)
974 setting_info->device_status |= DVI_Device;
975 if (viafb_LCD_ON == 1)
976 setting_info->device_status |= LCD_Device;
977 if (viafb_LCD2_ON == 1)
978 setting_info->device_status |= LCD2_Device;
Joseph Chan29b619f2008-10-15 22:03:27 -0700979
980 setting_info->samm_status = viafb_SAMM_ON;
981 setting_info->primary_device = get_primary_device();
982
983 setting_info->first_dev_bpp = viafb_bpp;
984 setting_info->second_dev_bpp = viafb_bpp1;
985
986 setting_info->first_dev_refresh = viafb_refresh;
987 setting_info->second_dev_refresh = viafb_refresh1;
988
989 setting_info->first_dev_hor_res = viafb_hotplug_Xres;
990 setting_info->first_dev_ver_res = viafb_hotplug_Yres;
991 setting_info->second_dev_hor_res = viafb_second_xres;
992 setting_info->second_dev_ver_res = viafb_second_yres;
993
994 /* Get lcd attributes */
995 setting_info->lcd_attributes.display_center = viafb_lcd_dsp_method;
996 setting_info->lcd_attributes.panel_id = viafb_lcd_panel_id;
997 setting_info->lcd_attributes.lcd_mode = viafb_lcd_mode;
998}
999
Florian Tobias Schandinatf4ab2f7a2010-08-09 01:34:27 +00001000static int __init parse_active_dev(void)
Joseph Chan29b619f2008-10-15 22:03:27 -07001001{
1002 viafb_CRT_ON = STATE_OFF;
1003 viafb_DVI_ON = STATE_OFF;
1004 viafb_LCD_ON = STATE_OFF;
1005 viafb_LCD2_ON = STATE_OFF;
1006 /* 1. Modify the active status of devices. */
1007 /* 2. Keep the order of devices, so we can set corresponding
1008 IGA path to devices in SAMM case. */
1009 /* Note: The previous of active_dev is primary device,
1010 and the following is secondary device. */
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001011 if (!viafb_active_dev) {
Daniel Drake8aa4d962011-05-10 22:34:11 +01001012 if (machine_is_olpc()) { /* LCD only */
1013 viafb_LCD_ON = STATE_ON;
1014 viafb_SAMM_ON = STATE_OFF;
1015 } else {
1016 viafb_CRT_ON = STATE_ON;
1017 viafb_SAMM_ON = STATE_OFF;
1018 }
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001019 } else if (!strcmp(viafb_active_dev, "CRT+DVI")) {
Joseph Chan29b619f2008-10-15 22:03:27 -07001020 /* CRT+DVI */
1021 viafb_CRT_ON = STATE_ON;
1022 viafb_DVI_ON = STATE_ON;
1023 viafb_primary_dev = CRT_Device;
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001024 } else if (!strcmp(viafb_active_dev, "DVI+CRT")) {
Joseph Chan29b619f2008-10-15 22:03:27 -07001025 /* DVI+CRT */
1026 viafb_CRT_ON = STATE_ON;
1027 viafb_DVI_ON = STATE_ON;
1028 viafb_primary_dev = DVI_Device;
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001029 } else if (!strcmp(viafb_active_dev, "CRT+LCD")) {
Joseph Chan29b619f2008-10-15 22:03:27 -07001030 /* CRT+LCD */
1031 viafb_CRT_ON = STATE_ON;
1032 viafb_LCD_ON = STATE_ON;
1033 viafb_primary_dev = CRT_Device;
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001034 } else if (!strcmp(viafb_active_dev, "LCD+CRT")) {
Joseph Chan29b619f2008-10-15 22:03:27 -07001035 /* LCD+CRT */
1036 viafb_CRT_ON = STATE_ON;
1037 viafb_LCD_ON = STATE_ON;
1038 viafb_primary_dev = LCD_Device;
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001039 } else if (!strcmp(viafb_active_dev, "DVI+LCD")) {
Joseph Chan29b619f2008-10-15 22:03:27 -07001040 /* DVI+LCD */
1041 viafb_DVI_ON = STATE_ON;
1042 viafb_LCD_ON = STATE_ON;
1043 viafb_primary_dev = DVI_Device;
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001044 } else if (!strcmp(viafb_active_dev, "LCD+DVI")) {
Joseph Chan29b619f2008-10-15 22:03:27 -07001045 /* LCD+DVI */
1046 viafb_DVI_ON = STATE_ON;
1047 viafb_LCD_ON = STATE_ON;
1048 viafb_primary_dev = LCD_Device;
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001049 } else if (!strcmp(viafb_active_dev, "LCD+LCD2")) {
Joseph Chan29b619f2008-10-15 22:03:27 -07001050 viafb_LCD_ON = STATE_ON;
1051 viafb_LCD2_ON = STATE_ON;
1052 viafb_primary_dev = LCD_Device;
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001053 } else if (!strcmp(viafb_active_dev, "LCD2+LCD")) {
Joseph Chan29b619f2008-10-15 22:03:27 -07001054 viafb_LCD_ON = STATE_ON;
1055 viafb_LCD2_ON = STATE_ON;
1056 viafb_primary_dev = LCD2_Device;
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001057 } else if (!strcmp(viafb_active_dev, "CRT")) {
Joseph Chan29b619f2008-10-15 22:03:27 -07001058 /* CRT only */
1059 viafb_CRT_ON = STATE_ON;
1060 viafb_SAMM_ON = STATE_OFF;
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001061 } else if (!strcmp(viafb_active_dev, "DVI")) {
Joseph Chan29b619f2008-10-15 22:03:27 -07001062 /* DVI only */
1063 viafb_DVI_ON = STATE_ON;
1064 viafb_SAMM_ON = STATE_OFF;
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001065 } else if (!strcmp(viafb_active_dev, "LCD")) {
Joseph Chan29b619f2008-10-15 22:03:27 -07001066 /* LCD only */
1067 viafb_LCD_ON = STATE_ON;
1068 viafb_SAMM_ON = STATE_OFF;
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001069 } else
1070 return -EINVAL;
1071
1072 return 0;
Joseph Chan29b619f2008-10-15 22:03:27 -07001073}
1074
Florian Tobias Schandinatf4ab2f7a2010-08-09 01:34:27 +00001075static int __devinit parse_port(char *opt_str, int *output_interface)
Joseph Chan29b619f2008-10-15 22:03:27 -07001076{
1077 if (!strncmp(opt_str, "DVP0", 4))
1078 *output_interface = INTERFACE_DVP0;
1079 else if (!strncmp(opt_str, "DVP1", 4))
1080 *output_interface = INTERFACE_DVP1;
1081 else if (!strncmp(opt_str, "DFP_HIGHLOW", 11))
1082 *output_interface = INTERFACE_DFP;
1083 else if (!strncmp(opt_str, "DFP_HIGH", 8))
1084 *output_interface = INTERFACE_DFP_HIGH;
1085 else if (!strncmp(opt_str, "DFP_LOW", 7))
1086 *output_interface = INTERFACE_DFP_LOW;
1087 else
1088 *output_interface = INTERFACE_NONE;
1089 return 0;
1090}
1091
Florian Tobias Schandinatf4ab2f7a2010-08-09 01:34:27 +00001092static void __devinit parse_lcd_port(void)
Joseph Chan29b619f2008-10-15 22:03:27 -07001093{
1094 parse_port(viafb_lcd_port, &viaparinfo->chip_info->lvds_chip_info.
1095 output_interface);
1096 /*Initialize to avoid unexpected behavior */
1097 viaparinfo->chip_info->lvds_chip_info2.output_interface =
1098 INTERFACE_NONE;
1099
1100 DEBUG_MSG(KERN_INFO "parse_lcd_port: viafb_lcd_port:%s,interface:%d\n",
1101 viafb_lcd_port, viaparinfo->chip_info->lvds_chip_info.
1102 output_interface);
1103}
1104
Florian Tobias Schandinatf4ab2f7a2010-08-09 01:34:27 +00001105static void __devinit parse_dvi_port(void)
Joseph Chan29b619f2008-10-15 22:03:27 -07001106{
1107 parse_port(viafb_dvi_port, &viaparinfo->chip_info->tmds_chip_info.
1108 output_interface);
1109
1110 DEBUG_MSG(KERN_INFO "parse_dvi_port: viafb_dvi_port:%s,interface:%d\n",
1111 viafb_dvi_port, viaparinfo->chip_info->tmds_chip_info.
1112 output_interface);
1113}
1114
Florian Tobias Schandinat2b78a962010-04-17 19:44:57 +00001115#ifdef CONFIG_FB_VIA_DIRECT_PROCFS
1116
Joseph Chan29b619f2008-10-15 22:03:27 -07001117/*
1118 * The proc filesystem read/write function, a simple proc implement to
1119 * get/set the value of DPA DVP0, DVP0DataDriving, DVP0ClockDriving, DVP1,
1120 * DVP1Driving, DFPHigh, DFPLow CR96, SR2A[5], SR1B[1], SR2A[4], SR1E[2],
1121 * CR9B, SR65, CR97, CR99
1122 */
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001123static int viafb_dvp0_proc_show(struct seq_file *m, void *v)
Joseph Chan29b619f2008-10-15 22:03:27 -07001124{
Joseph Chan29b619f2008-10-15 22:03:27 -07001125 u8 dvp0_data_dri = 0, dvp0_clk_dri = 0, dvp0 = 0;
1126 dvp0_data_dri =
1127 (viafb_read_reg(VIASR, SR2A) & BIT5) >> 4 |
1128 (viafb_read_reg(VIASR, SR1B) & BIT1) >> 1;
1129 dvp0_clk_dri =
1130 (viafb_read_reg(VIASR, SR2A) & BIT4) >> 3 |
1131 (viafb_read_reg(VIASR, SR1E) & BIT2) >> 2;
1132 dvp0 = viafb_read_reg(VIACR, CR96) & 0x0f;
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001133 seq_printf(m, "%x %x %x\n", dvp0, dvp0_data_dri, dvp0_clk_dri);
1134 return 0;
Joseph Chan29b619f2008-10-15 22:03:27 -07001135}
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001136
1137static int viafb_dvp0_proc_open(struct inode *inode, struct file *file)
1138{
1139 return single_open(file, viafb_dvp0_proc_show, NULL);
1140}
1141
1142static ssize_t viafb_dvp0_proc_write(struct file *file,
1143 const char __user *buffer, size_t count, loff_t *pos)
Joseph Chan29b619f2008-10-15 22:03:27 -07001144{
1145 char buf[20], *value, *pbuf;
1146 u8 reg_val = 0;
1147 unsigned long length, i;
1148 if (count < 1)
1149 return -EINVAL;
1150 length = count > 20 ? 20 : count;
1151 if (copy_from_user(&buf[0], buffer, length))
1152 return -EFAULT;
1153 buf[length - 1] = '\0'; /*Ensure end string */
1154 pbuf = &buf[0];
1155 for (i = 0; i < 3; i++) {
1156 value = strsep(&pbuf, " ");
1157 if (value != NULL) {
Wang Shaoyan4ce36bb2011-08-08 10:18:15 +08001158 if (kstrtou8(value, 0, &reg_val) < 0)
1159 return -EINVAL;
Joseph Chan29b619f2008-10-15 22:03:27 -07001160 DEBUG_MSG(KERN_INFO "DVP0:reg_val[%l]=:%x\n", i,
1161 reg_val);
1162 switch (i) {
1163 case 0:
1164 viafb_write_reg_mask(CR96, VIACR,
1165 reg_val, 0x0f);
1166 break;
1167 case 1:
1168 viafb_write_reg_mask(SR2A, VIASR,
1169 reg_val << 4, BIT5);
1170 viafb_write_reg_mask(SR1B, VIASR,
1171 reg_val << 1, BIT1);
1172 break;
1173 case 2:
1174 viafb_write_reg_mask(SR2A, VIASR,
1175 reg_val << 3, BIT4);
1176 viafb_write_reg_mask(SR1E, VIASR,
1177 reg_val << 2, BIT2);
1178 break;
1179 default:
1180 break;
1181 }
1182 } else {
1183 break;
1184 }
1185 }
1186 return count;
1187}
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001188
1189static const struct file_operations viafb_dvp0_proc_fops = {
1190 .owner = THIS_MODULE,
1191 .open = viafb_dvp0_proc_open,
1192 .read = seq_read,
1193 .llseek = seq_lseek,
1194 .release = single_release,
1195 .write = viafb_dvp0_proc_write,
1196};
1197
1198static int viafb_dvp1_proc_show(struct seq_file *m, void *v)
Joseph Chan29b619f2008-10-15 22:03:27 -07001199{
Joseph Chan29b619f2008-10-15 22:03:27 -07001200 u8 dvp1 = 0, dvp1_data_dri = 0, dvp1_clk_dri = 0;
1201 dvp1 = viafb_read_reg(VIACR, CR9B) & 0x0f;
1202 dvp1_data_dri = (viafb_read_reg(VIASR, SR65) & 0x0c) >> 2;
1203 dvp1_clk_dri = viafb_read_reg(VIASR, SR65) & 0x03;
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001204 seq_printf(m, "%x %x %x\n", dvp1, dvp1_data_dri, dvp1_clk_dri);
1205 return 0;
Joseph Chan29b619f2008-10-15 22:03:27 -07001206}
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001207
1208static int viafb_dvp1_proc_open(struct inode *inode, struct file *file)
1209{
1210 return single_open(file, viafb_dvp1_proc_show, NULL);
1211}
1212
1213static ssize_t viafb_dvp1_proc_write(struct file *file,
1214 const char __user *buffer, size_t count, loff_t *pos)
Joseph Chan29b619f2008-10-15 22:03:27 -07001215{
1216 char buf[20], *value, *pbuf;
1217 u8 reg_val = 0;
1218 unsigned long length, i;
1219 if (count < 1)
1220 return -EINVAL;
1221 length = count > 20 ? 20 : count;
1222 if (copy_from_user(&buf[0], buffer, length))
1223 return -EFAULT;
1224 buf[length - 1] = '\0'; /*Ensure end string */
1225 pbuf = &buf[0];
1226 for (i = 0; i < 3; i++) {
1227 value = strsep(&pbuf, " ");
1228 if (value != NULL) {
Wang Shaoyan4ce36bb2011-08-08 10:18:15 +08001229 if (kstrtou8(value, 0, &reg_val) < 0)
1230 return -EINVAL;
Joseph Chan29b619f2008-10-15 22:03:27 -07001231 switch (i) {
1232 case 0:
1233 viafb_write_reg_mask(CR9B, VIACR,
1234 reg_val, 0x0f);
1235 break;
1236 case 1:
1237 viafb_write_reg_mask(SR65, VIASR,
1238 reg_val << 2, 0x0c);
1239 break;
1240 case 2:
1241 viafb_write_reg_mask(SR65, VIASR,
1242 reg_val, 0x03);
1243 break;
1244 default:
1245 break;
1246 }
1247 } else {
1248 break;
1249 }
1250 }
1251 return count;
1252}
1253
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001254static const struct file_operations viafb_dvp1_proc_fops = {
1255 .owner = THIS_MODULE,
1256 .open = viafb_dvp1_proc_open,
1257 .read = seq_read,
1258 .llseek = seq_lseek,
1259 .release = single_release,
1260 .write = viafb_dvp1_proc_write,
1261};
1262
1263static int viafb_dfph_proc_show(struct seq_file *m, void *v)
Joseph Chan29b619f2008-10-15 22:03:27 -07001264{
Joseph Chan29b619f2008-10-15 22:03:27 -07001265 u8 dfp_high = 0;
1266 dfp_high = viafb_read_reg(VIACR, CR97) & 0x0f;
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001267 seq_printf(m, "%x\n", dfp_high);
1268 return 0;
Joseph Chan29b619f2008-10-15 22:03:27 -07001269}
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001270
1271static int viafb_dfph_proc_open(struct inode *inode, struct file *file)
1272{
1273 return single_open(file, viafb_dfph_proc_show, NULL);
1274}
1275
1276static ssize_t viafb_dfph_proc_write(struct file *file,
1277 const char __user *buffer, size_t count, loff_t *pos)
Joseph Chan29b619f2008-10-15 22:03:27 -07001278{
Peter Huewe9f5610e2012-05-04 02:23:17 +02001279 int err;
1280 u8 reg_val;
1281 err = kstrtou8_from_user(buffer, count, 0, &reg_val);
1282 if (err)
1283 return err;
1284
Joseph Chan29b619f2008-10-15 22:03:27 -07001285 viafb_write_reg_mask(CR97, VIACR, reg_val, 0x0f);
1286 return count;
1287}
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001288
1289static const struct file_operations viafb_dfph_proc_fops = {
1290 .owner = THIS_MODULE,
1291 .open = viafb_dfph_proc_open,
1292 .read = seq_read,
1293 .llseek = seq_lseek,
1294 .release = single_release,
1295 .write = viafb_dfph_proc_write,
1296};
1297
1298static int viafb_dfpl_proc_show(struct seq_file *m, void *v)
Joseph Chan29b619f2008-10-15 22:03:27 -07001299{
Joseph Chan29b619f2008-10-15 22:03:27 -07001300 u8 dfp_low = 0;
1301 dfp_low = viafb_read_reg(VIACR, CR99) & 0x0f;
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001302 seq_printf(m, "%x\n", dfp_low);
1303 return 0;
Joseph Chan29b619f2008-10-15 22:03:27 -07001304}
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001305
1306static int viafb_dfpl_proc_open(struct inode *inode, struct file *file)
1307{
1308 return single_open(file, viafb_dfpl_proc_show, NULL);
1309}
1310
1311static ssize_t viafb_dfpl_proc_write(struct file *file,
1312 const char __user *buffer, size_t count, loff_t *pos)
Joseph Chan29b619f2008-10-15 22:03:27 -07001313{
Peter Huewe9f5610e2012-05-04 02:23:17 +02001314 int err;
1315 u8 reg_val;
1316 err = kstrtou8_from_user(buffer, count, 0, &reg_val);
1317 if (err)
1318 return err;
1319
Joseph Chan29b619f2008-10-15 22:03:27 -07001320 viafb_write_reg_mask(CR99, VIACR, reg_val, 0x0f);
1321 return count;
1322}
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001323
1324static const struct file_operations viafb_dfpl_proc_fops = {
1325 .owner = THIS_MODULE,
1326 .open = viafb_dfpl_proc_open,
1327 .read = seq_read,
1328 .llseek = seq_lseek,
1329 .release = single_release,
1330 .write = viafb_dfpl_proc_write,
1331};
1332
1333static int viafb_vt1636_proc_show(struct seq_file *m, void *v)
Joseph Chan29b619f2008-10-15 22:03:27 -07001334{
Joseph Chan29b619f2008-10-15 22:03:27 -07001335 u8 vt1636_08 = 0, vt1636_09 = 0;
1336 switch (viaparinfo->chip_info->lvds_chip_info.lvds_chip_name) {
1337 case VT1636_LVDS:
1338 vt1636_08 =
1339 viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info,
1340 &viaparinfo->chip_info->lvds_chip_info, 0x08) & 0x0f;
1341 vt1636_09 =
1342 viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info,
1343 &viaparinfo->chip_info->lvds_chip_info, 0x09) & 0x1f;
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001344 seq_printf(m, "%x %x\n", vt1636_08, vt1636_09);
Joseph Chan29b619f2008-10-15 22:03:27 -07001345 break;
1346 default:
1347 break;
1348 }
1349 switch (viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name) {
1350 case VT1636_LVDS:
1351 vt1636_08 =
1352 viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info2,
1353 &viaparinfo->chip_info->lvds_chip_info2, 0x08) & 0x0f;
1354 vt1636_09 =
1355 viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info2,
1356 &viaparinfo->chip_info->lvds_chip_info2, 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 }
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001362 return 0;
Joseph Chan29b619f2008-10-15 22:03:27 -07001363}
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001364
1365static int viafb_vt1636_proc_open(struct inode *inode, struct file *file)
1366{
1367 return single_open(file, viafb_vt1636_proc_show, NULL);
1368}
1369
1370static ssize_t viafb_vt1636_proc_write(struct file *file,
1371 const char __user *buffer, size_t count, loff_t *pos)
Joseph Chan29b619f2008-10-15 22:03:27 -07001372{
1373 char buf[30], *value, *pbuf;
1374 struct IODATA reg_val;
1375 unsigned long length, i;
1376 if (count < 1)
1377 return -EINVAL;
1378 length = count > 30 ? 30 : count;
1379 if (copy_from_user(&buf[0], buffer, length))
1380 return -EFAULT;
1381 buf[length - 1] = '\0'; /*Ensure end string */
1382 pbuf = &buf[0];
1383 switch (viaparinfo->chip_info->lvds_chip_info.lvds_chip_name) {
1384 case VT1636_LVDS:
1385 for (i = 0; i < 2; i++) {
1386 value = strsep(&pbuf, " ");
1387 if (value != NULL) {
Wang Shaoyan4ce36bb2011-08-08 10:18:15 +08001388 if (kstrtou8(value, 0, &reg_val.Data) < 0)
1389 return -EINVAL;
Joseph Chan29b619f2008-10-15 22:03:27 -07001390 switch (i) {
1391 case 0:
1392 reg_val.Index = 0x08;
1393 reg_val.Mask = 0x0f;
1394 viafb_gpio_i2c_write_mask_lvds
1395 (viaparinfo->lvds_setting_info,
1396 &viaparinfo->
1397 chip_info->lvds_chip_info,
1398 reg_val);
1399 break;
1400 case 1:
1401 reg_val.Index = 0x09;
1402 reg_val.Mask = 0x1f;
1403 viafb_gpio_i2c_write_mask_lvds
1404 (viaparinfo->lvds_setting_info,
1405 &viaparinfo->
1406 chip_info->lvds_chip_info,
1407 reg_val);
1408 break;
1409 default:
1410 break;
1411 }
1412 } else {
1413 break;
1414 }
1415 }
1416 break;
1417 default:
1418 break;
1419 }
1420 switch (viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name) {
1421 case VT1636_LVDS:
1422 for (i = 0; i < 2; i++) {
1423 value = strsep(&pbuf, " ");
1424 if (value != NULL) {
Wang Shaoyan4ce36bb2011-08-08 10:18:15 +08001425 if (kstrtou8(value, 0, &reg_val.Data) < 0)
1426 return -EINVAL;
Joseph Chan29b619f2008-10-15 22:03:27 -07001427 switch (i) {
1428 case 0:
1429 reg_val.Index = 0x08;
1430 reg_val.Mask = 0x0f;
1431 viafb_gpio_i2c_write_mask_lvds
1432 (viaparinfo->lvds_setting_info2,
1433 &viaparinfo->
1434 chip_info->lvds_chip_info2,
1435 reg_val);
1436 break;
1437 case 1:
1438 reg_val.Index = 0x09;
1439 reg_val.Mask = 0x1f;
1440 viafb_gpio_i2c_write_mask_lvds
1441 (viaparinfo->lvds_setting_info2,
1442 &viaparinfo->
1443 chip_info->lvds_chip_info2,
1444 reg_val);
1445 break;
1446 default:
1447 break;
1448 }
1449 } else {
1450 break;
1451 }
1452 }
1453 break;
1454 default:
1455 break;
1456 }
1457 return count;
1458}
1459
Alexey Dobriyanafbd3c12009-09-22 16:47:27 -07001460static const struct file_operations viafb_vt1636_proc_fops = {
1461 .owner = THIS_MODULE,
1462 .open = viafb_vt1636_proc_open,
1463 .read = seq_read,
1464 .llseek = seq_lseek,
1465 .release = single_release,
1466 .write = viafb_vt1636_proc_write,
1467};
1468
Florian Tobias Schandinat2a918392010-09-05 01:33:28 +00001469#endif /* CONFIG_FB_VIA_DIRECT_PROCFS */
Joseph Chan29b619f2008-10-15 22:03:27 -07001470
Florian Tobias Schandinatdd7a0b02010-09-19 04:20:55 +00001471static int viafb_sup_odev_proc_show(struct seq_file *m, void *v)
1472{
1473 via_odev_to_seq(m, supported_odev_map[
1474 viaparinfo->shared->chip_info.gfx_chip_name]);
1475 return 0;
1476}
1477
1478static int viafb_sup_odev_proc_open(struct inode *inode, struct file *file)
1479{
1480 return single_open(file, viafb_sup_odev_proc_show, NULL);
1481}
1482
1483static const struct file_operations viafb_sup_odev_proc_fops = {
1484 .owner = THIS_MODULE,
1485 .open = viafb_sup_odev_proc_open,
1486 .read = seq_read,
1487 .llseek = seq_lseek,
1488 .release = single_release,
1489};
1490
Florian Tobias Schandinat2a918392010-09-05 01:33:28 +00001491static ssize_t odev_update(const char __user *buffer, size_t count, u32 *odev)
1492{
1493 char buf[64], *ptr = buf;
1494 u32 devices;
1495 bool add, sub;
1496
1497 if (count < 1 || count > 63)
1498 return -EINVAL;
1499 if (copy_from_user(&buf[0], buffer, count))
1500 return -EFAULT;
1501 buf[count] = '\0';
1502 add = buf[0] == '+';
1503 sub = buf[0] == '-';
1504 if (add || sub)
1505 ptr++;
1506 devices = via_parse_odev(ptr, &ptr);
1507 if (*ptr == '\n')
1508 ptr++;
1509 if (*ptr != 0)
1510 return -EINVAL;
1511 if (add)
1512 *odev |= devices;
1513 else if (sub)
1514 *odev &= ~devices;
1515 else
1516 *odev = devices;
1517 return count;
1518}
1519
1520static int viafb_iga1_odev_proc_show(struct seq_file *m, void *v)
1521{
1522 via_odev_to_seq(m, viaparinfo->shared->iga1_devices);
1523 return 0;
1524}
1525
1526static int viafb_iga1_odev_proc_open(struct inode *inode, struct file *file)
1527{
1528 return single_open(file, viafb_iga1_odev_proc_show, NULL);
1529}
1530
1531static ssize_t viafb_iga1_odev_proc_write(struct file *file,
1532 const char __user *buffer, size_t count, loff_t *pos)
1533{
1534 u32 dev_on, dev_off, dev_old, dev_new;
1535 ssize_t res;
1536
1537 dev_old = dev_new = viaparinfo->shared->iga1_devices;
1538 res = odev_update(buffer, count, &dev_new);
1539 if (res != count)
1540 return res;
1541 dev_off = dev_old & ~dev_new;
1542 dev_on = dev_new & ~dev_old;
1543 viaparinfo->shared->iga1_devices = dev_new;
1544 viaparinfo->shared->iga2_devices &= ~dev_new;
Florian Tobias Schandinat6f9422d2010-09-07 14:28:26 +00001545 via_set_state(dev_off, VIA_STATE_OFF);
Florian Tobias Schandinat2a918392010-09-05 01:33:28 +00001546 via_set_source(dev_new, IGA1);
Florian Tobias Schandinat6f9422d2010-09-07 14:28:26 +00001547 via_set_state(dev_on, VIA_STATE_ON);
Florian Tobias Schandinat2a918392010-09-05 01:33:28 +00001548 return res;
1549}
1550
1551static const struct file_operations viafb_iga1_odev_proc_fops = {
1552 .owner = THIS_MODULE,
1553 .open = viafb_iga1_odev_proc_open,
1554 .read = seq_read,
1555 .llseek = seq_lseek,
1556 .release = single_release,
1557 .write = viafb_iga1_odev_proc_write,
1558};
1559
1560static int viafb_iga2_odev_proc_show(struct seq_file *m, void *v)
1561{
1562 via_odev_to_seq(m, viaparinfo->shared->iga2_devices);
1563 return 0;
1564}
1565
1566static int viafb_iga2_odev_proc_open(struct inode *inode, struct file *file)
1567{
1568 return single_open(file, viafb_iga2_odev_proc_show, NULL);
1569}
1570
1571static ssize_t viafb_iga2_odev_proc_write(struct file *file,
1572 const char __user *buffer, size_t count, loff_t *pos)
1573{
1574 u32 dev_on, dev_off, dev_old, dev_new;
1575 ssize_t res;
1576
1577 dev_old = dev_new = viaparinfo->shared->iga2_devices;
1578 res = odev_update(buffer, count, &dev_new);
1579 if (res != count)
1580 return res;
1581 dev_off = dev_old & ~dev_new;
1582 dev_on = dev_new & ~dev_old;
1583 viaparinfo->shared->iga2_devices = dev_new;
1584 viaparinfo->shared->iga1_devices &= ~dev_new;
Florian Tobias Schandinat6f9422d2010-09-07 14:28:26 +00001585 via_set_state(dev_off, VIA_STATE_OFF);
Florian Tobias Schandinat2a918392010-09-05 01:33:28 +00001586 via_set_source(dev_new, IGA2);
Florian Tobias Schandinat6f9422d2010-09-07 14:28:26 +00001587 via_set_state(dev_on, VIA_STATE_ON);
Florian Tobias Schandinat2a918392010-09-05 01:33:28 +00001588 return res;
1589}
1590
1591static const struct file_operations viafb_iga2_odev_proc_fops = {
1592 .owner = THIS_MODULE,
1593 .open = viafb_iga2_odev_proc_open,
1594 .read = seq_read,
1595 .llseek = seq_lseek,
1596 .release = single_release,
1597 .write = viafb_iga2_odev_proc_write,
1598};
1599
1600#define IS_VT1636(lvds_chip) ((lvds_chip).lvds_chip_name == VT1636_LVDS)
1601static void viafb_init_proc(struct viafb_shared *shared)
1602{
1603 struct proc_dir_entry *iga1_entry, *iga2_entry,
1604 *viafb_entry = proc_mkdir("viafb", NULL);
1605
1606 shared->proc_entry = viafb_entry;
1607 if (viafb_entry) {
1608#ifdef CONFIG_FB_VIA_DIRECT_PROCFS
1609 proc_create("dvp0", 0, viafb_entry, &viafb_dvp0_proc_fops);
1610 proc_create("dvp1", 0, viafb_entry, &viafb_dvp1_proc_fops);
1611 proc_create("dfph", 0, viafb_entry, &viafb_dfph_proc_fops);
1612 proc_create("dfpl", 0, viafb_entry, &viafb_dfpl_proc_fops);
1613 if (IS_VT1636(shared->chip_info.lvds_chip_info)
1614 || IS_VT1636(shared->chip_info.lvds_chip_info2))
1615 proc_create("vt1636", 0, viafb_entry,
1616 &viafb_vt1636_proc_fops);
1617#endif /* CONFIG_FB_VIA_DIRECT_PROCFS */
1618
Florian Tobias Schandinatdd7a0b02010-09-19 04:20:55 +00001619 proc_create("supported_output_devices", 0, viafb_entry,
1620 &viafb_sup_odev_proc_fops);
Florian Tobias Schandinat2a918392010-09-05 01:33:28 +00001621 iga1_entry = proc_mkdir("iga1", viafb_entry);
1622 shared->iga1_proc_entry = iga1_entry;
1623 proc_create("output_devices", 0, iga1_entry,
1624 &viafb_iga1_odev_proc_fops);
1625 iga2_entry = proc_mkdir("iga2", viafb_entry);
1626 shared->iga2_proc_entry = iga2_entry;
1627 proc_create("output_devices", 0, iga2_entry,
1628 &viafb_iga2_odev_proc_fops);
Joseph Chan29b619f2008-10-15 22:03:27 -07001629 }
1630}
Florian Tobias Schandinat2a918392010-09-05 01:33:28 +00001631static void viafb_remove_proc(struct viafb_shared *shared)
Joseph Chan29b619f2008-10-15 22:03:27 -07001632{
Florian Tobias Schandinat2a918392010-09-05 01:33:28 +00001633 struct proc_dir_entry *viafb_entry = shared->proc_entry,
1634 *iga1_entry = shared->iga1_proc_entry,
1635 *iga2_entry = shared->iga2_proc_entry;
Florian Tobias Schandinat2fed5472010-04-17 19:44:56 +00001636
Florian Tobias Schandinat2a918392010-09-05 01:33:28 +00001637 if (!viafb_entry)
1638 return;
1639
1640 remove_proc_entry("output_devices", iga2_entry);
1641 remove_proc_entry("iga2", viafb_entry);
1642 remove_proc_entry("output_devices", iga1_entry);
1643 remove_proc_entry("iga1", viafb_entry);
Florian Tobias Schandinatdd7a0b02010-09-19 04:20:55 +00001644 remove_proc_entry("supported_output_devices", viafb_entry);
Florian Tobias Schandinat2a918392010-09-05 01:33:28 +00001645
1646#ifdef CONFIG_FB_VIA_DIRECT_PROCFS
Joseph Chan29b619f2008-10-15 22:03:27 -07001647 remove_proc_entry("dvp0", viafb_entry);/* parent dir */
1648 remove_proc_entry("dvp1", viafb_entry);
1649 remove_proc_entry("dfph", viafb_entry);
1650 remove_proc_entry("dfpl", viafb_entry);
Florian Tobias Schandinat2a918392010-09-05 01:33:28 +00001651 if (IS_VT1636(shared->chip_info.lvds_chip_info)
1652 || IS_VT1636(shared->chip_info.lvds_chip_info2))
Florian Tobias Schandinat2fed5472010-04-17 19:44:56 +00001653 remove_proc_entry("vt1636", viafb_entry);
Florian Tobias Schandinat2a918392010-09-05 01:33:28 +00001654#endif /* CONFIG_FB_VIA_DIRECT_PROCFS */
Florian Tobias Schandinat2fed5472010-04-17 19:44:56 +00001655
Bruno Prémontc267fd72008-11-19 15:36:23 -08001656 remove_proc_entry("viafb", NULL);
Joseph Chan29b619f2008-10-15 22:03:27 -07001657}
Florian Tobias Schandinat2a918392010-09-05 01:33:28 +00001658#undef IS_VT1636
Florian Tobias Schandinat2b78a962010-04-17 19:44:57 +00001659
Florian Tobias Schandinat5dc5f612012-01-12 12:52:37 +00001660static int parse_mode(const char *str, u32 devices, u32 *xres, u32 *yres)
Florian Tobias Schandinat5ff32f62009-09-22 16:47:34 -07001661{
Florian Tobias Schandinat5dc5f612012-01-12 12:52:37 +00001662 const struct fb_videomode *mode = NULL;
Florian Tobias Schandinat5ff32f62009-09-22 16:47:34 -07001663 char *ptr;
1664
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001665 if (!str) {
Florian Tobias Schandinat5dc5f612012-01-12 12:52:37 +00001666 if (devices == VIA_CRT)
1667 mode = via_aux_get_preferred_mode(
1668 viaparinfo->shared->i2c_26);
1669 else if (devices == VIA_DVP1)
1670 mode = via_aux_get_preferred_mode(
1671 viaparinfo->shared->i2c_31);
1672
1673 if (mode) {
1674 *xres = mode->xres;
1675 *yres = mode->yres;
1676 } else if (machine_is_olpc()) {
Daniel Drake8aa4d962011-05-10 22:34:11 +01001677 *xres = 1200;
1678 *yres = 900;
1679 } else {
1680 *xres = 640;
1681 *yres = 480;
1682 }
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001683 return 0;
1684 }
1685
Florian Tobias Schandinat5ff32f62009-09-22 16:47:34 -07001686 *xres = simple_strtoul(str, &ptr, 10);
1687 if (ptr[0] != 'x')
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001688 return -EINVAL;
Florian Tobias Schandinat5ff32f62009-09-22 16:47:34 -07001689
1690 *yres = simple_strtoul(&ptr[1], &ptr, 10);
1691 if (ptr[0])
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001692 return -EINVAL;
Florian Tobias Schandinat5ff32f62009-09-22 16:47:34 -07001693
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08001694 return 0;
Florian Tobias Schandinat5ff32f62009-09-22 16:47:34 -07001695}
1696
Jonathan Corbetf045f772009-12-01 20:29:39 -07001697
Deepak Saxena3fd9b6c2010-04-08 11:15:41 -06001698#ifdef CONFIG_PM
Daniel Drake751305d2010-10-28 18:23:01 +01001699static int viafb_suspend(void *unused)
Deepak Saxena3fd9b6c2010-04-08 11:15:41 -06001700{
Torben Hohnac751ef2011-01-25 15:07:35 -08001701 console_lock();
Daniel Drake751305d2010-10-28 18:23:01 +01001702 fb_set_suspend(viafbinfo, 1);
1703 viafb_sync(viafbinfo);
Torben Hohnac751ef2011-01-25 15:07:35 -08001704 console_unlock();
Deepak Saxena3fd9b6c2010-04-08 11:15:41 -06001705
1706 return 0;
1707}
1708
Daniel Drake751305d2010-10-28 18:23:01 +01001709static int viafb_resume(void *unused)
Deepak Saxena3fd9b6c2010-04-08 11:15:41 -06001710{
Torben Hohnac751ef2011-01-25 15:07:35 -08001711 console_lock();
Florian Tobias Schandinatadac8d62010-04-26 17:31:03 +00001712 if (viaparinfo->shared->vdev->engine_mmio)
1713 viafb_reset_engine(viaparinfo);
Florian Tobias Schandinatb75f2c02010-04-26 16:37:53 +00001714 viafb_set_par(viafbinfo);
1715 if (viafb_dual_fb)
1716 viafb_set_par(viafbinfo1);
Deepak Saxena3fd9b6c2010-04-08 11:15:41 -06001717 fb_set_suspend(viafbinfo, 0);
1718
Torben Hohnac751ef2011-01-25 15:07:35 -08001719 console_unlock();
Deepak Saxena3fd9b6c2010-04-08 11:15:41 -06001720 return 0;
1721}
1722
Daniel Drake751305d2010-10-28 18:23:01 +01001723static struct viafb_pm_hooks viafb_fb_pm_hooks = {
1724 .suspend = viafb_suspend,
1725 .resume = viafb_resume
1726};
1727
Deepak Saxena3fd9b6c2010-04-08 11:15:41 -06001728#endif
1729
Florian Tobias Schandinate7589272011-07-30 01:25:29 +00001730static void __devinit i2c_bus_probe(struct viafb_shared *shared)
1731{
1732 /* should be always CRT */
1733 printk(KERN_INFO "viafb: Probing I2C bus 0x26\n");
1734 shared->i2c_26 = via_aux_probe(viafb_find_i2c_adapter(VIA_PORT_26));
1735
1736 /* seems to be usually DVP1 */
1737 printk(KERN_INFO "viafb: Probing I2C bus 0x31\n");
1738 shared->i2c_31 = via_aux_probe(viafb_find_i2c_adapter(VIA_PORT_31));
1739
1740 /* FIXME: what is this? */
Florian Tobias Schandinat78145b72012-02-19 01:23:20 +00001741 if (!machine_is_olpc()) {
1742 printk(KERN_INFO "viafb: Probing I2C bus 0x2C\n");
1743 shared->i2c_2C = via_aux_probe(viafb_find_i2c_adapter(VIA_PORT_2C));
1744 }
Florian Tobias Schandinate7589272011-07-30 01:25:29 +00001745
1746 printk(KERN_INFO "viafb: Finished I2C bus probing");
1747}
1748
1749static void i2c_bus_free(struct viafb_shared *shared)
1750{
1751 via_aux_free(shared->i2c_26);
1752 via_aux_free(shared->i2c_31);
1753 via_aux_free(shared->i2c_2C);
1754}
Deepak Saxena3fd9b6c2010-04-08 11:15:41 -06001755
Jonathan Corbet24b4d822010-04-22 13:48:09 -06001756int __devinit via_fb_pci_probe(struct viafb_dev *vdev)
Joseph Chan29b619f2008-10-15 22:03:27 -07001757{
Florian Tobias Schandinat5ff32f62009-09-22 16:47:34 -07001758 u32 default_xres, default_yres;
Florian Tobias Schandinatdba77f82010-03-10 15:21:37 -08001759 struct fb_var_screeninfo default_var;
Harald Welte109771a2009-05-19 17:12:58 +08001760 int rc;
Florian Tobias Schandinatc4df5482009-09-22 16:47:24 -07001761 u32 viafb_par_length;
Joseph Chan29b619f2008-10-15 22:03:27 -07001762
1763 DEBUG_MSG(KERN_INFO "VIAFB PCI Probe!!\n");
Florian Tobias Schandinatdba77f82010-03-10 15:21:37 -08001764 memset(&default_var, 0, sizeof(default_var));
Joseph Chan29b619f2008-10-15 22:03:27 -07001765 viafb_par_length = ALIGN(sizeof(struct viafb_par), BITS_PER_LONG/8);
Joseph Chan29b619f2008-10-15 22:03:27 -07001766
1767 /* Allocate fb_info and ***_par here, also including some other needed
1768 * variables
1769 */
Florian Tobias Schandinatc4df5482009-09-22 16:47:24 -07001770 viafbinfo = framebuffer_alloc(viafb_par_length +
Harald Weltedb8df7b2009-09-22 16:47:38 -07001771 ALIGN(sizeof(struct viafb_shared), BITS_PER_LONG/8),
Jonathan Corbet24b4d822010-04-22 13:48:09 -06001772 &vdev->pdev->dev);
Joseph Chan29b619f2008-10-15 22:03:27 -07001773 if (!viafbinfo) {
1774 printk(KERN_ERR"Could not allocate memory for viafb_info.\n");
Harald Welte109771a2009-05-19 17:12:58 +08001775 return -ENOMEM;
Joseph Chan29b619f2008-10-15 22:03:27 -07001776 }
1777
1778 viaparinfo = (struct viafb_par *)viafbinfo->par;
Florian Tobias Schandinatc4df5482009-09-22 16:47:24 -07001779 viaparinfo->shared = viafbinfo->par + viafb_par_length;
Jonathan Corbet24b4d822010-04-22 13:48:09 -06001780 viaparinfo->shared->vdev = vdev;
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -07001781 viaparinfo->vram_addr = 0;
Florian Tobias Schandinatc4df5482009-09-22 16:47:24 -07001782 viaparinfo->tmds_setting_info = &viaparinfo->shared->tmds_setting_info;
1783 viaparinfo->lvds_setting_info = &viaparinfo->shared->lvds_setting_info;
1784 viaparinfo->lvds_setting_info2 =
1785 &viaparinfo->shared->lvds_setting_info2;
Florian Tobias Schandinatc4df5482009-09-22 16:47:24 -07001786 viaparinfo->chip_info = &viaparinfo->shared->chip_info;
Joseph Chan29b619f2008-10-15 22:03:27 -07001787
Florian Tobias Schandinate7589272011-07-30 01:25:29 +00001788 i2c_bus_probe(viaparinfo->shared);
Joseph Chan29b619f2008-10-15 22:03:27 -07001789 if (viafb_dual_fb)
1790 viafb_SAMM_ON = 1;
Joseph Chan29b619f2008-10-15 22:03:27 -07001791 parse_lcd_port();
1792 parse_dvi_port();
1793
Jonathan Corbet24b4d822010-04-22 13:48:09 -06001794 viafb_init_chip_info(vdev->chip_type);
1795 /*
1796 * The framebuffer will have been successfully mapped by
1797 * the core (or we'd not be here), but we still need to
1798 * set up our own accounting.
1799 */
1800 viaparinfo->fbmem = vdev->fbmem_start;
1801 viaparinfo->memsize = vdev->fbmem_len;
Joseph Chan29b619f2008-10-15 22:03:27 -07001802 viaparinfo->fbmem_free = viaparinfo->memsize;
1803 viaparinfo->fbmem_used = 0;
Jonathan Corbet24b4d822010-04-22 13:48:09 -06001804 viafbinfo->screen_base = vdev->fbmem;
Joseph Chan29b619f2008-10-15 22:03:27 -07001805
Jonathan Corbet24b4d822010-04-22 13:48:09 -06001806 viafbinfo->fix.mmio_start = vdev->engine_start;
1807 viafbinfo->fix.mmio_len = vdev->engine_len;
Joseph Chan29b619f2008-10-15 22:03:27 -07001808 viafbinfo->node = 0;
1809 viafbinfo->fbops = &viafb_ops;
1810 viafbinfo->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
1811
1812 viafbinfo->pseudo_palette = pseudo_pal;
Florian Tobias Schandinatadac8d62010-04-26 17:31:03 +00001813 if (viafb_accel && !viafb_setup_engine(viafbinfo)) {
Florian Tobias Schandinat31de59d2009-09-22 16:47:31 -07001814 viafbinfo->flags |= FBINFO_HWACCEL_COPYAREA |
1815 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_IMAGEBLIT;
1816 default_var.accel_flags = FB_ACCELF_TEXT;
1817 } else {
1818 viafbinfo->flags |= FBINFO_HWACCEL_DISABLED;
1819 default_var.accel_flags = 0;
Joseph Chan29b619f2008-10-15 22:03:27 -07001820 }
1821
1822 if (viafb_second_size && (viafb_second_size < 8)) {
1823 viafb_second_offset = viaparinfo->fbmem_free -
1824 viafb_second_size * 1024 * 1024;
1825 } else {
1826 viafb_second_size = 8;
1827 viafb_second_offset = viaparinfo->fbmem_free -
1828 viafb_second_size * 1024 * 1024;
1829 }
1830
Florian Tobias Schandinat5dc5f612012-01-12 12:52:37 +00001831 parse_mode(viafb_mode, viaparinfo->shared->iga1_devices,
1832 &default_xres, &default_yres);
Florian Tobias Schandinat7f980a02011-03-27 02:54:32 +00001833 if (viafb_SAMM_ON == 1)
Florian Tobias Schandinat5dc5f612012-01-12 12:52:37 +00001834 parse_mode(viafb_mode1, viaparinfo->shared->iga2_devices,
1835 &viafb_second_xres, &viafb_second_yres);
Florian Tobias Schandinat5ff32f62009-09-22 16:47:34 -07001836
Joseph Chan29b619f2008-10-15 22:03:27 -07001837 default_var.xres = default_xres;
1838 default_var.yres = default_yres;
Florian Tobias Schandinatcd589952010-07-13 19:44:05 +00001839 default_var.xres_virtual = default_xres;
Joseph Chan29b619f2008-10-15 22:03:27 -07001840 default_var.yres_virtual = default_yres;
1841 default_var.bits_per_pixel = viafb_bpp;
Florian Tobias Schandinat94715ba2011-08-06 23:04:43 +00001842 viafb_fill_var_timing_info(&default_var, viafb_get_best_mode(
1843 default_var.xres, default_var.yres, viafb_refresh));
Florian Tobias Schandinat7cf60792010-03-10 15:21:31 -08001844 viafb_setup_fixinfo(&viafbinfo->fix, viaparinfo);
Florian Tobias Schandinat7cf60792010-03-10 15:21:31 -08001845 viafbinfo->var = default_var;
Joseph Chan29b619f2008-10-15 22:03:27 -07001846
1847 if (viafb_dual_fb) {
Jonathan Corbet24b4d822010-04-22 13:48:09 -06001848 viafbinfo1 = framebuffer_alloc(viafb_par_length,
1849 &vdev->pdev->dev);
Joseph Chan29b619f2008-10-15 22:03:27 -07001850 if (!viafbinfo1) {
1851 printk(KERN_ERR
1852 "allocate the second framebuffer struct error\n");
Harald Welte109771a2009-05-19 17:12:58 +08001853 rc = -ENOMEM;
Jonathan Corbet24b4d822010-04-22 13:48:09 -06001854 goto out_fb_release;
Joseph Chan29b619f2008-10-15 22:03:27 -07001855 }
1856 viaparinfo1 = viafbinfo1->par;
1857 memcpy(viaparinfo1, viaparinfo, viafb_par_length);
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -07001858 viaparinfo1->vram_addr = viafb_second_offset;
Joseph Chan29b619f2008-10-15 22:03:27 -07001859 viaparinfo1->memsize = viaparinfo->memsize -
1860 viafb_second_offset;
1861 viaparinfo->memsize = viafb_second_offset;
Joseph Chan29b619f2008-10-15 22:03:27 -07001862 viaparinfo1->fbmem = viaparinfo->fbmem + viafb_second_offset;
1863
1864 viaparinfo1->fbmem_used = viaparinfo->fbmem_used;
1865 viaparinfo1->fbmem_free = viaparinfo1->memsize -
1866 viaparinfo1->fbmem_used;
1867 viaparinfo->fbmem_free = viaparinfo->memsize;
1868 viaparinfo->fbmem_used = 0;
Joseph Chan29b619f2008-10-15 22:03:27 -07001869
Florian Tobias Schandinat09cf1182009-09-22 16:47:14 -07001870 viaparinfo->iga_path = IGA1;
1871 viaparinfo1->iga_path = IGA2;
Joseph Chan29b619f2008-10-15 22:03:27 -07001872 memcpy(viafbinfo1, viafbinfo, sizeof(struct fb_info));
Florian Tobias Schandinatc4df5482009-09-22 16:47:24 -07001873 viafbinfo1->par = viaparinfo1;
Joseph Chan29b619f2008-10-15 22:03:27 -07001874 viafbinfo1->screen_base = viafbinfo->screen_base +
1875 viafb_second_offset;
Joseph Chan29b619f2008-10-15 22:03:27 -07001876
1877 default_var.xres = viafb_second_xres;
1878 default_var.yres = viafb_second_yres;
Florian Tobias Schandinat7f980a02011-03-27 02:54:32 +00001879 default_var.xres_virtual = viafb_second_xres;
1880 default_var.yres_virtual = viafb_second_yres;
Joseph Chan29b619f2008-10-15 22:03:27 -07001881 default_var.bits_per_pixel = viafb_bpp1;
Florian Tobias Schandinat94715ba2011-08-06 23:04:43 +00001882 viafb_fill_var_timing_info(&default_var, viafb_get_best_mode(
1883 default_var.xres, default_var.yres, viafb_refresh1));
Joseph Chan29b619f2008-10-15 22:03:27 -07001884
1885 viafb_setup_fixinfo(&viafbinfo1->fix, viaparinfo1);
1886 viafb_check_var(&default_var, viafbinfo1);
1887 viafbinfo1->var = default_var;
Florian Tobias Schandinat81228a32009-09-22 16:47:13 -07001888 viafb_update_fix(viafbinfo1);
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -07001889 viaparinfo1->depth = fb_get_color_depth(&viafbinfo1->var,
1890 &viafbinfo1->fix);
Joseph Chan29b619f2008-10-15 22:03:27 -07001891 }
1892
Florian Tobias Schandinate17cea32010-03-10 15:21:41 -08001893 viafb_check_var(&viafbinfo->var, viafbinfo);
Florian Tobias Schandinat81228a32009-09-22 16:47:13 -07001894 viafb_update_fix(viafbinfo);
Florian Tobias Schandinatc3e25672009-09-22 16:47:26 -07001895 viaparinfo->depth = fb_get_color_depth(&viafbinfo->var,
1896 &viafbinfo->fix);
Joseph Chan29b619f2008-10-15 22:03:27 -07001897 default_var.activate = FB_ACTIVATE_NOW;
Harald Welte109771a2009-05-19 17:12:58 +08001898 rc = fb_alloc_cmap(&viafbinfo->cmap, 256, 0);
1899 if (rc)
1900 goto out_fb1_release;
Joseph Chan29b619f2008-10-15 22:03:27 -07001901
1902 if (viafb_dual_fb && (viafb_primary_dev == LCD_Device)
1903 && (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)) {
Harald Welte109771a2009-05-19 17:12:58 +08001904 rc = register_framebuffer(viafbinfo1);
1905 if (rc)
1906 goto out_dealloc_cmap;
Joseph Chan29b619f2008-10-15 22:03:27 -07001907 }
Harald Welte109771a2009-05-19 17:12:58 +08001908 rc = register_framebuffer(viafbinfo);
1909 if (rc)
1910 goto out_fb1_unreg_lcd_cle266;
Joseph Chan29b619f2008-10-15 22:03:27 -07001911
1912 if (viafb_dual_fb && ((viafb_primary_dev != LCD_Device)
1913 || (viaparinfo->chip_info->gfx_chip_name !=
1914 UNICHROME_CLE266))) {
Harald Welte109771a2009-05-19 17:12:58 +08001915 rc = register_framebuffer(viafbinfo1);
1916 if (rc)
1917 goto out_fb_unreg;
Joseph Chan29b619f2008-10-15 22:03:27 -07001918 }
1919 DEBUG_MSG(KERN_INFO "fb%d: %s frame buffer device %dx%d-%dbpp\n",
1920 viafbinfo->node, viafbinfo->fix.id, default_var.xres,
1921 default_var.yres, default_var.bits_per_pixel);
1922
Florian Tobias Schandinat2a918392010-09-05 01:33:28 +00001923 viafb_init_proc(viaparinfo->shared);
Joseph Chan29b619f2008-10-15 22:03:27 -07001924 viafb_init_dac(IGA2);
Daniel Drake751305d2010-10-28 18:23:01 +01001925
1926#ifdef CONFIG_PM
1927 viafb_pm_register(&viafb_fb_pm_hooks);
1928#endif
Joseph Chan29b619f2008-10-15 22:03:27 -07001929 return 0;
Harald Welte109771a2009-05-19 17:12:58 +08001930
1931out_fb_unreg:
1932 unregister_framebuffer(viafbinfo);
1933out_fb1_unreg_lcd_cle266:
1934 if (viafb_dual_fb && (viafb_primary_dev == LCD_Device)
1935 && (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266))
1936 unregister_framebuffer(viafbinfo1);
1937out_dealloc_cmap:
1938 fb_dealloc_cmap(&viafbinfo->cmap);
1939out_fb1_release:
1940 if (viafbinfo1)
1941 framebuffer_release(viafbinfo1);
Harald Welte109771a2009-05-19 17:12:58 +08001942out_fb_release:
Florian Tobias Schandinate7589272011-07-30 01:25:29 +00001943 i2c_bus_free(viaparinfo->shared);
Harald Welte109771a2009-05-19 17:12:58 +08001944 framebuffer_release(viafbinfo);
1945 return rc;
Joseph Chan29b619f2008-10-15 22:03:27 -07001946}
1947
Jonathan Corbetf045f772009-12-01 20:29:39 -07001948void __devexit via_fb_pci_remove(struct pci_dev *pdev)
Joseph Chan29b619f2008-10-15 22:03:27 -07001949{
1950 DEBUG_MSG(KERN_INFO "via_pci_remove!\n");
1951 fb_dealloc_cmap(&viafbinfo->cmap);
1952 unregister_framebuffer(viafbinfo);
1953 if (viafb_dual_fb)
1954 unregister_framebuffer(viafbinfo1);
Florian Tobias Schandinat2a918392010-09-05 01:33:28 +00001955 viafb_remove_proc(viaparinfo->shared);
Florian Tobias Schandinate7589272011-07-30 01:25:29 +00001956 i2c_bus_free(viaparinfo->shared);
Joseph Chan29b619f2008-10-15 22:03:27 -07001957 framebuffer_release(viafbinfo);
1958 if (viafb_dual_fb)
1959 framebuffer_release(viafbinfo1);
Joseph Chan29b619f2008-10-15 22:03:27 -07001960}
1961
1962#ifndef MODULE
Daniel Drake8aa4d962011-05-10 22:34:11 +01001963static int __init viafb_setup(void)
Joseph Chan29b619f2008-10-15 22:03:27 -07001964{
1965 char *this_opt;
Daniel Drake8aa4d962011-05-10 22:34:11 +01001966 char *options;
1967
Joseph Chan29b619f2008-10-15 22:03:27 -07001968 DEBUG_MSG(KERN_INFO "viafb_setup!\n");
1969
Daniel Drake8aa4d962011-05-10 22:34:11 +01001970 if (fb_get_options("viafb", &options))
1971 return -ENODEV;
1972
Joseph Chan29b619f2008-10-15 22:03:27 -07001973 if (!options || !*options)
1974 return 0;
1975
1976 while ((this_opt = strsep(&options, ",")) != NULL) {
1977 if (!*this_opt)
1978 continue;
1979
Wang Shaoyan4ce36bb2011-08-08 10:18:15 +08001980 if (!strncmp(this_opt, "viafb_mode1=", 12)) {
Joseph Chan29b619f2008-10-15 22:03:27 -07001981 viafb_mode1 = kstrdup(this_opt + 12, GFP_KERNEL);
Wang Shaoyan4ce36bb2011-08-08 10:18:15 +08001982 } else if (!strncmp(this_opt, "viafb_mode=", 11)) {
Joseph Chan29b619f2008-10-15 22:03:27 -07001983 viafb_mode = kstrdup(this_opt + 11, GFP_KERNEL);
Wang Shaoyan4ce36bb2011-08-08 10:18:15 +08001984 } else if (!strncmp(this_opt, "viafb_bpp1=", 11)) {
1985 if (kstrtouint(this_opt + 11, 0, &viafb_bpp1) < 0)
1986 return -EINVAL;
1987 } else if (!strncmp(this_opt, "viafb_bpp=", 10)) {
1988 if (kstrtouint(this_opt + 10, 0, &viafb_bpp) < 0)
1989 return -EINVAL;
1990 } else if (!strncmp(this_opt, "viafb_refresh1=", 15)) {
1991 if (kstrtoint(this_opt + 15, 0, &viafb_refresh1) < 0)
1992 return -EINVAL;
1993 } else if (!strncmp(this_opt, "viafb_refresh=", 14)) {
1994 if (kstrtoint(this_opt + 14, 0, &viafb_refresh) < 0)
1995 return -EINVAL;
1996 } else if (!strncmp(this_opt, "viafb_lcd_dsp_method=", 21)) {
1997 if (kstrtoint(this_opt + 21, 0,
1998 &viafb_lcd_dsp_method) < 0)
1999 return -EINVAL;
2000 } else if (!strncmp(this_opt, "viafb_lcd_panel_id=", 19)) {
2001 if (kstrtoint(this_opt + 19, 0,
2002 &viafb_lcd_panel_id) < 0)
2003 return -EINVAL;
2004 } else if (!strncmp(this_opt, "viafb_accel=", 12)) {
2005 if (kstrtoint(this_opt + 12, 0, &viafb_accel) < 0)
2006 return -EINVAL;
2007 } else if (!strncmp(this_opt, "viafb_SAMM_ON=", 14)) {
2008 if (kstrtoint(this_opt + 14, 0, &viafb_SAMM_ON) < 0)
2009 return -EINVAL;
2010 } else if (!strncmp(this_opt, "viafb_active_dev=", 17)) {
Joseph Chan29b619f2008-10-15 22:03:27 -07002011 viafb_active_dev = kstrdup(this_opt + 17, GFP_KERNEL);
Wang Shaoyan4ce36bb2011-08-08 10:18:15 +08002012 } else if (!strncmp(this_opt,
2013 "viafb_display_hardware_layout=", 30)) {
2014 if (kstrtoint(this_opt + 30, 0,
2015 &viafb_display_hardware_layout) < 0)
2016 return -EINVAL;
2017 } else if (!strncmp(this_opt, "viafb_second_size=", 18)) {
2018 if (kstrtoint(this_opt + 18, 0, &viafb_second_size) < 0)
2019 return -EINVAL;
2020 } else if (!strncmp(this_opt,
2021 "viafb_platform_epia_dvi=", 24)) {
2022 if (kstrtoint(this_opt + 24, 0,
2023 &viafb_platform_epia_dvi) < 0)
2024 return -EINVAL;
2025 } else if (!strncmp(this_opt,
2026 "viafb_device_lcd_dualedge=", 26)) {
2027 if (kstrtoint(this_opt + 26, 0,
2028 &viafb_device_lcd_dualedge) < 0)
2029 return -EINVAL;
2030 } else if (!strncmp(this_opt, "viafb_bus_width=", 16)) {
2031 if (kstrtoint(this_opt + 16, 0, &viafb_bus_width) < 0)
2032 return -EINVAL;
2033 } else if (!strncmp(this_opt, "viafb_lcd_mode=", 15)) {
2034 if (kstrtoint(this_opt + 15, 0, &viafb_lcd_mode) < 0)
2035 return -EINVAL;
2036 } else if (!strncmp(this_opt, "viafb_lcd_port=", 15)) {
Joseph Chan29b619f2008-10-15 22:03:27 -07002037 viafb_lcd_port = kstrdup(this_opt + 15, GFP_KERNEL);
Wang Shaoyan4ce36bb2011-08-08 10:18:15 +08002038 } else if (!strncmp(this_opt, "viafb_dvi_port=", 15)) {
Joseph Chan29b619f2008-10-15 22:03:27 -07002039 viafb_dvi_port = kstrdup(this_opt + 15, GFP_KERNEL);
Wang Shaoyan4ce36bb2011-08-08 10:18:15 +08002040 }
Joseph Chan29b619f2008-10-15 22:03:27 -07002041 }
2042 return 0;
2043}
2044#endif
2045
Jonathan Corbetf045f772009-12-01 20:29:39 -07002046/*
2047 * These are called out of via-core for now.
2048 */
2049int __init viafb_init(void)
Joseph Chan29b619f2008-10-15 22:03:27 -07002050{
Florian Tobias Schandinat3f086fe2011-03-21 17:01:07 +00002051 u32 dummy_x, dummy_y;
Nikanth Karthikesan0acd33d2011-06-10 14:27:04 +05302052 int r = 0;
Daniel Drake8aa4d962011-05-10 22:34:11 +01002053
2054 if (machine_is_olpc())
2055 /* Apply XO-1.5-specific configuration. */
2056 viafb_lcd_panel_id = 23;
2057
Joseph Chan29b619f2008-10-15 22:03:27 -07002058#ifndef MODULE
Daniel Drake8aa4d962011-05-10 22:34:11 +01002059 r = viafb_setup();
2060 if (r < 0)
2061 return r;
Joseph Chan29b619f2008-10-15 22:03:27 -07002062#endif
Florian Tobias Schandinat5dc5f612012-01-12 12:52:37 +00002063 if (parse_mode(viafb_mode, 0, &dummy_x, &dummy_y)
Florian Tobias Schandinat94715ba2011-08-06 23:04:43 +00002064 || !viafb_get_best_mode(dummy_x, dummy_y, viafb_refresh)
Florian Tobias Schandinat5dc5f612012-01-12 12:52:37 +00002065 || parse_mode(viafb_mode1, 0, &dummy_x, &dummy_y)
Florian Tobias Schandinat94715ba2011-08-06 23:04:43 +00002066 || !viafb_get_best_mode(dummy_x, dummy_y, viafb_refresh1)
Florian Tobias Schandinate17cea32010-03-10 15:21:41 -08002067 || viafb_bpp < 0 || viafb_bpp > 32
2068 || viafb_bpp1 < 0 || viafb_bpp1 > 32
Florian Tobias Schandinatfe9aab82010-03-10 15:21:34 -08002069 || parse_active_dev())
2070 return -EINVAL;
2071
Joseph Chan29b619f2008-10-15 22:03:27 -07002072 printk(KERN_INFO
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002073 "VIA Graphics Integration Chipset framebuffer %d.%d initializing\n",
Joseph Chan29b619f2008-10-15 22:03:27 -07002074 VERSION_MAJOR, VERSION_MINOR);
Nikanth Karthikesan0acd33d2011-06-10 14:27:04 +05302075 return r;
Joseph Chan29b619f2008-10-15 22:03:27 -07002076}
2077
Jonathan Corbetf045f772009-12-01 20:29:39 -07002078void __exit viafb_exit(void)
Joseph Chan29b619f2008-10-15 22:03:27 -07002079{
2080 DEBUG_MSG(KERN_INFO "viafb_exit!\n");
Joseph Chan29b619f2008-10-15 22:03:27 -07002081}
2082
2083static struct fb_ops viafb_ops = {
2084 .owner = THIS_MODULE,
2085 .fb_open = viafb_open,
2086 .fb_release = viafb_release,
2087 .fb_check_var = viafb_check_var,
2088 .fb_set_par = viafb_set_par,
2089 .fb_setcolreg = viafb_setcolreg,
2090 .fb_pan_display = viafb_pan_display,
2091 .fb_blank = viafb_blank,
2092 .fb_fillrect = viafb_fillrect,
2093 .fb_copyarea = viafb_copyarea,
2094 .fb_imageblit = viafb_imageblit,
2095 .fb_cursor = viafb_cursor,
2096 .fb_ioctl = viafb_ioctl,
2097 .fb_sync = viafb_sync,
Joseph Chan29b619f2008-10-15 22:03:27 -07002098};
2099
Joseph Chan29b619f2008-10-15 22:03:27 -07002100
2101#ifdef MODULE
Harald Welte93967be2009-09-22 16:47:32 -07002102module_param(viafb_mode, charp, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002103MODULE_PARM_DESC(viafb_mode, "Set resolution (default=640x480)");
2104
Harald Welte93967be2009-09-22 16:47:32 -07002105module_param(viafb_mode1, charp, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002106MODULE_PARM_DESC(viafb_mode1, "Set resolution (default=640x480)");
2107
Harald Welte93967be2009-09-22 16:47:32 -07002108module_param(viafb_bpp, int, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002109MODULE_PARM_DESC(viafb_bpp, "Set color depth (default=32bpp)");
2110
Harald Welte93967be2009-09-22 16:47:32 -07002111module_param(viafb_bpp1, int, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002112MODULE_PARM_DESC(viafb_bpp1, "Set color depth (default=32bpp)");
2113
Harald Welte93967be2009-09-22 16:47:32 -07002114module_param(viafb_refresh, int, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002115MODULE_PARM_DESC(viafb_refresh,
2116 "Set CRT viafb_refresh rate (default = 60)");
2117
Harald Welte93967be2009-09-22 16:47:32 -07002118module_param(viafb_refresh1, int, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002119MODULE_PARM_DESC(viafb_refresh1,
2120 "Set CRT refresh rate (default = 60)");
2121
Harald Welte93967be2009-09-22 16:47:32 -07002122module_param(viafb_lcd_panel_id, int, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002123MODULE_PARM_DESC(viafb_lcd_panel_id,
2124 "Set Flat Panel type(Default=1024x768)");
2125
Harald Welte93967be2009-09-22 16:47:32 -07002126module_param(viafb_lcd_dsp_method, int, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002127MODULE_PARM_DESC(viafb_lcd_dsp_method,
2128 "Set Flat Panel display scaling method.(Default=Expandsion)");
2129
Harald Welte93967be2009-09-22 16:47:32 -07002130module_param(viafb_SAMM_ON, int, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002131MODULE_PARM_DESC(viafb_SAMM_ON,
2132 "Turn on/off flag of SAMM(Default=OFF)");
2133
Harald Welte93967be2009-09-22 16:47:32 -07002134module_param(viafb_accel, int, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002135MODULE_PARM_DESC(viafb_accel,
Florian Tobias Schandinat31de59d2009-09-22 16:47:31 -07002136 "Set 2D Hardware Acceleration: 0 = OFF, 1 = ON (default)");
Joseph Chan29b619f2008-10-15 22:03:27 -07002137
Harald Welte93967be2009-09-22 16:47:32 -07002138module_param(viafb_active_dev, charp, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002139MODULE_PARM_DESC(viafb_active_dev, "Specify active devices.");
2140
Harald Welte93967be2009-09-22 16:47:32 -07002141module_param(viafb_display_hardware_layout, int, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002142MODULE_PARM_DESC(viafb_display_hardware_layout,
2143 "Display Hardware Layout (LCD Only, DVI Only...,etc)");
2144
Harald Welte93967be2009-09-22 16:47:32 -07002145module_param(viafb_second_size, int, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002146MODULE_PARM_DESC(viafb_second_size,
2147 "Set secondary device memory size");
2148
Harald Welte93967be2009-09-22 16:47:32 -07002149module_param(viafb_dual_fb, int, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002150MODULE_PARM_DESC(viafb_dual_fb,
2151 "Turn on/off flag of dual framebuffer devices.(Default = OFF)");
2152
Harald Welte93967be2009-09-22 16:47:32 -07002153module_param(viafb_platform_epia_dvi, int, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002154MODULE_PARM_DESC(viafb_platform_epia_dvi,
2155 "Turn on/off flag of DVI devices on EPIA board.(Default = OFF)");
2156
Harald Welte93967be2009-09-22 16:47:32 -07002157module_param(viafb_device_lcd_dualedge, int, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002158MODULE_PARM_DESC(viafb_device_lcd_dualedge,
2159 "Turn on/off flag of dual edge panel.(Default = OFF)");
2160
Harald Welte93967be2009-09-22 16:47:32 -07002161module_param(viafb_bus_width, int, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002162MODULE_PARM_DESC(viafb_bus_width,
2163 "Set bus width of panel.(Default = 12)");
2164
Harald Welte93967be2009-09-22 16:47:32 -07002165module_param(viafb_lcd_mode, int, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002166MODULE_PARM_DESC(viafb_lcd_mode,
2167 "Set Flat Panel mode(Default=OPENLDI)");
2168
Harald Welte93967be2009-09-22 16:47:32 -07002169module_param(viafb_lcd_port, charp, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002170MODULE_PARM_DESC(viafb_lcd_port, "Specify LCD output port.");
2171
Harald Welte93967be2009-09-22 16:47:32 -07002172module_param(viafb_dvi_port, charp, S_IRUSR);
Joseph Chan29b619f2008-10-15 22:03:27 -07002173MODULE_PARM_DESC(viafb_dvi_port, "Specify DVI output port.");
2174
2175MODULE_LICENSE("GPL");
2176#endif