summaryrefslogtreecommitdiff
path: root/packages/linux/linux-openmoko-2.6.28/0007-Subject-glamo_fix_improper_xrandr_geometry_setting.patch
blob: 0856e06020d0c004e2950bcac58a4fc7ffa8c76d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
From 3192193f8a1a799783963aaf10119b39c3e8df24 Mon Sep 17 00:00:00 2001
From: Balaji Rao <balajirrao@openmoko.org>
Date: Thu, 29 Jan 2009 18:25:32 +0000
Subject: [PATCH 7/8] Subject: glamo_fix_improper_xrandr_geometry_setting.patch

glamo_fix_improper_xrandr_geometry_setting.patch

Switching to xrandr -o 3 from xrandr -o 1 caused the screen to look crazy
because of the way lcd geometry is set in glamo. This patch fixes it.

Signed-off-by: Balaji Rao <balajirrao@openmoko.org>
---
 drivers/mfd/glamo/glamo-fb.c |  109 ++++++++++++++++++-----------------------
 1 files changed, 48 insertions(+), 61 deletions(-)

diff --git a/drivers/mfd/glamo/glamo-fb.c b/drivers/mfd/glamo/glamo-fb.c
index 91cf75b..16531fa 100644
--- a/drivers/mfd/glamo/glamo-fb.c
+++ b/drivers/mfd/glamo/glamo-fb.c
@@ -75,6 +75,7 @@ struct glamofb_handle {
 	int cursor_on;
 	u_int32_t pseudo_pal[16];
 	spinlock_t lock_cmd;
+	int angle;	/* Current rotation angle */
 };
 
 /* 'sibling' spi device for lcm init */
@@ -255,11 +256,6 @@ static void reg_set_bit_mask(struct glamofb_handle *glamo,
 #define GLAMO_LCD_HV_RETR_DISP_START_MASK 0x03FF
 #define GLAMO_LCD_HV_RETR_DISP_END_MASK 0x03FF
 
-enum orientation {
-    ORIENTATION_PORTRAIT,
-    ORIENTATION_LANDSCAPE
-};
-
 
 /* the caller has to enxure lock_cmd is held and we are in cmd mode */
 static void __rotate_lcd(struct glamofb_handle *glamo, __u32 rotation)
@@ -275,17 +271,22 @@ static void __rotate_lcd(struct glamofb_handle *glamo, __u32 rotation)
 	switch (rotation) {
 		case FB_ROTATE_UR:
 			glamo_rot = GLAMO_LCD_ROT_MODE_0;
+			glamo->angle = 0;
 			break;
 		case FB_ROTATE_CW:
 			glamo_rot = GLAMO_LCD_ROT_MODE_90;
+			glamo->angle = 90;
 			break;
 		case FB_ROTATE_UD:
 			glamo_rot = GLAMO_LCD_ROT_MODE_180;
+			glamo->angle = 180;
 			break;
 		case FB_ROTATE_CCW:
 			glamo_rot = GLAMO_LCD_ROT_MODE_270;
+			glamo->angle = 270;
 			break;
 		default:
+			glamo->angle = 0;
 			glamo_rot = GLAMO_LCD_ROT_MODE_0;
 			break;
 	}
@@ -301,38 +302,12 @@ static void __rotate_lcd(struct glamofb_handle *glamo, __u32 rotation)
 				 GLAMO_LCD_MODE1_ROTATE_EN : 0);
 }
 
-static enum orientation get_orientation(struct fb_var_screeninfo *var)
-{
-	if (var->xres <= var->yres)
-		return ORIENTATION_PORTRAIT;
-
-	return ORIENTATION_LANDSCAPE;
-}
-
-static int will_orientation_change(struct fb_var_screeninfo *var)
-{
-	enum orientation orient = get_orientation(var);
-
-	switch (orient) {
-		case ORIENTATION_LANDSCAPE:
-			if (var->rotate == FB_ROTATE_UR ||
-			    var->rotate == FB_ROTATE_UD)
-				return 1;
-			break;
-		case ORIENTATION_PORTRAIT:
-			if (var->rotate == FB_ROTATE_CW ||
-			    var->rotate == FB_ROTATE_CCW)
-				return 1;
-			break;
-	}
-	return 0;
-}
-
 static void glamofb_update_lcd_controller(struct glamofb_handle *glamo,
 					  struct fb_var_screeninfo *var)
 {
-	int sync, bp, disp, fp, total, xres, yres, pitch, orientation_changing;
+	int sync, bp, disp, fp, total, pitch;
 	unsigned long flags;
+	int width, height;
 
 	if (!glamo || !var)
 		return;
@@ -355,31 +330,52 @@ static void glamofb_update_lcd_controller(struct glamofb_handle *glamo,
 				     GLAMO_ENGINE_LCD,
 				     var->pixclock);
 
-	xres = var->xres;
-	yres = var->yres;
+	if (glamo->angle == 90 || glamo->angle == 270) {
+		/* 
+		 * But if we are going back to portrait mode from here,
+		 * we get inverted values from Xglamo 
+		 */ 
+		if (!(var->rotate == FB_ROTATE_UR ||
+				var->rotate == FB_ROTATE_UD)) {
+			width = var->yres;
+			height = var->xres;
+		} else {
+			width = var->xres;
+			height = var->yres;
+		}
 
-	/* figure out if orientation is going to change */
-	orientation_changing = will_orientation_change(var);
+	} else {
+		width = var->xres;
+		height = var->yres;
+	}
 
-	/* adjust the pitch according to new orientation to come */
+	/* Portrait ? */
+	if (var->rotate == FB_ROTATE_UR || var->rotate == FB_ROTATE_UD) {
+		/* We don't need to set xres and yres in this particular case
+		 * because Xglamo does it for us */
+		if (!(glamo->angle == 90 || glamo->angle == 270)) {
+			var->xres = width;var->yres = height;
+		}
 
-	if (orientation_changing) {
-		pitch = var->yres * var->bits_per_pixel / 8;
-        } else {
-		pitch = var->xres * var->bits_per_pixel / 8;
-        }
+		var->xres_virtual = width * 2;
+		var->yres_virtual = height;
+		pitch = width * var->bits_per_pixel / 8;
+	} else {
+		var->xres = height;
+		var->yres = width;
+		var->xres_virtual = height;
+		var->yres_virtual = width * 2;
+		pitch = height * var->bits_per_pixel / 8;
+	}
 
-	/*
-	 * set the desired LCD geometry
-	 */
 	reg_set_bit_mask(glamo,
 			 GLAMO_REG_LCD_WIDTH,
 			 GLAMO_LCD_WIDTH_MASK,
-			 xres);
+			 width);
 	reg_set_bit_mask(glamo,
 			 GLAMO_REG_LCD_HEIGHT,
 			 GLAMO_LCD_HEIGHT_MASK,
-			 yres);
+			 height);
 	reg_set_bit_mask(glamo,
 			 GLAMO_REG_LCD_PITCH,
 			 GLAMO_LCD_PITCH_MASK,
@@ -388,22 +384,11 @@ static void glamofb_update_lcd_controller(struct glamofb_handle *glamo,
 	/* honour the rotation request */
 	__rotate_lcd(glamo, var->rotate);
 
-	/* update the reported geometry of the framebuffer. */
-	if (orientation_changing) {
-		var->xres_virtual = var->xres = yres;
-		var->xres_virtual *= 2;
-		var->yres_virtual = var->yres = xres;
-	} else {
-		var->xres_virtual = var->xres = xres;
-		var->yres_virtual = var->yres = yres;
-		var->yres_virtual *= 2;
-	}
-
 	/* update scannout timings */
 	sync = 0;
 	bp = sync + var->hsync_len;
 	disp = bp + var->left_margin;
-	fp = disp + xres;
+	fp = disp + width;
 	total = fp + var->right_margin;
 
 	reg_set_bit_mask(glamo, GLAMO_REG_LCD_HORIZ_TOTAL,
@@ -420,7 +405,7 @@ static void glamofb_update_lcd_controller(struct glamofb_handle *glamo,
 	sync = 0;
 	bp = sync + var->vsync_len;
 	disp = bp + var->upper_margin;
-	fp = disp + yres;
+	fp = disp + height;
 	total = fp + var->lower_margin;
 
 	reg_set_bit_mask(glamo, GLAMO_REG_LCD_VERT_TOTAL,
@@ -836,6 +821,8 @@ static int __init glamofb_probe(struct platform_device *pdev)
 	glamofb->fb = fbinfo;
 	glamofb->dev = &pdev->dev;
 
+	glamofb->angle = 0;
+
 	strcpy(fbinfo->fix.id, "SMedia Glamo");
 
 	glamofb->reg = platform_get_resource_byname(pdev, IORESOURCE_MEM,
-- 
1.5.2.2