Merge branch 'org.openembedded.dev' of git@git.openembedded.net:openembedded into...
[vuplus_openembedded] / packages / linux / linux-openmoko-2.6.28 / 0007-Subject-glamo_fix_improper_xrandr_geometry_setting.patch
1 From 3192193f8a1a799783963aaf10119b39c3e8df24 Mon Sep 17 00:00:00 2001
2 From: Balaji Rao <balajirrao@openmoko.org>
3 Date: Thu, 29 Jan 2009 18:25:32 +0000
4 Subject: [PATCH 7/8] Subject: glamo_fix_improper_xrandr_geometry_setting.patch
5
6 glamo_fix_improper_xrandr_geometry_setting.patch
7
8 Switching to xrandr -o 3 from xrandr -o 1 caused the screen to look crazy
9 because of the way lcd geometry is set in glamo. This patch fixes it.
10
11 Signed-off-by: Balaji Rao <balajirrao@openmoko.org>
12 ---
13  drivers/mfd/glamo/glamo-fb.c |  109 ++++++++++++++++++-----------------------
14  1 files changed, 48 insertions(+), 61 deletions(-)
15
16 diff --git a/drivers/mfd/glamo/glamo-fb.c b/drivers/mfd/glamo/glamo-fb.c
17 index 91cf75b..16531fa 100644
18 --- a/drivers/mfd/glamo/glamo-fb.c
19 +++ b/drivers/mfd/glamo/glamo-fb.c
20 @@ -75,6 +75,7 @@ struct glamofb_handle {
21         int cursor_on;
22         u_int32_t pseudo_pal[16];
23         spinlock_t lock_cmd;
24 +       int angle;      /* Current rotation angle */
25  };
26  
27  /* 'sibling' spi device for lcm init */
28 @@ -255,11 +256,6 @@ static void reg_set_bit_mask(struct glamofb_handle *glamo,
29  #define GLAMO_LCD_HV_RETR_DISP_START_MASK 0x03FF
30  #define GLAMO_LCD_HV_RETR_DISP_END_MASK 0x03FF
31  
32 -enum orientation {
33 -    ORIENTATION_PORTRAIT,
34 -    ORIENTATION_LANDSCAPE
35 -};
36 -
37  
38  /* the caller has to enxure lock_cmd is held and we are in cmd mode */
39  static void __rotate_lcd(struct glamofb_handle *glamo, __u32 rotation)
40 @@ -275,17 +271,22 @@ static void __rotate_lcd(struct glamofb_handle *glamo, __u32 rotation)
41         switch (rotation) {
42                 case FB_ROTATE_UR:
43                         glamo_rot = GLAMO_LCD_ROT_MODE_0;
44 +                       glamo->angle = 0;
45                         break;
46                 case FB_ROTATE_CW:
47                         glamo_rot = GLAMO_LCD_ROT_MODE_90;
48 +                       glamo->angle = 90;
49                         break;
50                 case FB_ROTATE_UD:
51                         glamo_rot = GLAMO_LCD_ROT_MODE_180;
52 +                       glamo->angle = 180;
53                         break;
54                 case FB_ROTATE_CCW:
55                         glamo_rot = GLAMO_LCD_ROT_MODE_270;
56 +                       glamo->angle = 270;
57                         break;
58                 default:
59 +                       glamo->angle = 0;
60                         glamo_rot = GLAMO_LCD_ROT_MODE_0;
61                         break;
62         }
63 @@ -301,38 +302,12 @@ static void __rotate_lcd(struct glamofb_handle *glamo, __u32 rotation)
64                                  GLAMO_LCD_MODE1_ROTATE_EN : 0);
65  }
66  
67 -static enum orientation get_orientation(struct fb_var_screeninfo *var)
68 -{
69 -       if (var->xres <= var->yres)
70 -               return ORIENTATION_PORTRAIT;
71 -
72 -       return ORIENTATION_LANDSCAPE;
73 -}
74 -
75 -static int will_orientation_change(struct fb_var_screeninfo *var)
76 -{
77 -       enum orientation orient = get_orientation(var);
78 -
79 -       switch (orient) {
80 -               case ORIENTATION_LANDSCAPE:
81 -                       if (var->rotate == FB_ROTATE_UR ||
82 -                           var->rotate == FB_ROTATE_UD)
83 -                               return 1;
84 -                       break;
85 -               case ORIENTATION_PORTRAIT:
86 -                       if (var->rotate == FB_ROTATE_CW ||
87 -                           var->rotate == FB_ROTATE_CCW)
88 -                               return 1;
89 -                       break;
90 -       }
91 -       return 0;
92 -}
93 -
94  static void glamofb_update_lcd_controller(struct glamofb_handle *glamo,
95                                           struct fb_var_screeninfo *var)
96  {
97 -       int sync, bp, disp, fp, total, xres, yres, pitch, orientation_changing;
98 +       int sync, bp, disp, fp, total, pitch;
99         unsigned long flags;
100 +       int width, height;
101  
102         if (!glamo || !var)
103                 return;
104 @@ -355,31 +330,52 @@ static void glamofb_update_lcd_controller(struct glamofb_handle *glamo,
105                                      GLAMO_ENGINE_LCD,
106                                      var->pixclock);
107  
108 -       xres = var->xres;
109 -       yres = var->yres;
110 +       if (glamo->angle == 90 || glamo->angle == 270) {
111 +               /* 
112 +                * But if we are going back to portrait mode from here,
113 +                * we get inverted values from Xglamo 
114 +                */ 
115 +               if (!(var->rotate == FB_ROTATE_UR ||
116 +                               var->rotate == FB_ROTATE_UD)) {
117 +                       width = var->yres;
118 +                       height = var->xres;
119 +               } else {
120 +                       width = var->xres;
121 +                       height = var->yres;
122 +               }
123  
124 -       /* figure out if orientation is going to change */
125 -       orientation_changing = will_orientation_change(var);
126 +       } else {
127 +               width = var->xres;
128 +               height = var->yres;
129 +       }
130  
131 -       /* adjust the pitch according to new orientation to come */
132 +       /* Portrait ? */
133 +       if (var->rotate == FB_ROTATE_UR || var->rotate == FB_ROTATE_UD) {
134 +               /* We don't need to set xres and yres in this particular case
135 +                * because Xglamo does it for us */
136 +               if (!(glamo->angle == 90 || glamo->angle == 270)) {
137 +                       var->xres = width;var->yres = height;
138 +               }
139  
140 -       if (orientation_changing) {
141 -               pitch = var->yres * var->bits_per_pixel / 8;
142 -        } else {
143 -               pitch = var->xres * var->bits_per_pixel / 8;
144 -        }
145 +               var->xres_virtual = width * 2;
146 +               var->yres_virtual = height;
147 +               pitch = width * var->bits_per_pixel / 8;
148 +       } else {
149 +               var->xres = height;
150 +               var->yres = width;
151 +               var->xres_virtual = height;
152 +               var->yres_virtual = width * 2;
153 +               pitch = height * var->bits_per_pixel / 8;
154 +       }
155  
156 -       /*
157 -        * set the desired LCD geometry
158 -        */
159         reg_set_bit_mask(glamo,
160                          GLAMO_REG_LCD_WIDTH,
161                          GLAMO_LCD_WIDTH_MASK,
162 -                        xres);
163 +                        width);
164         reg_set_bit_mask(glamo,
165                          GLAMO_REG_LCD_HEIGHT,
166                          GLAMO_LCD_HEIGHT_MASK,
167 -                        yres);
168 +                        height);
169         reg_set_bit_mask(glamo,
170                          GLAMO_REG_LCD_PITCH,
171                          GLAMO_LCD_PITCH_MASK,
172 @@ -388,22 +384,11 @@ static void glamofb_update_lcd_controller(struct glamofb_handle *glamo,
173         /* honour the rotation request */
174         __rotate_lcd(glamo, var->rotate);
175  
176 -       /* update the reported geometry of the framebuffer. */
177 -       if (orientation_changing) {
178 -               var->xres_virtual = var->xres = yres;
179 -               var->xres_virtual *= 2;
180 -               var->yres_virtual = var->yres = xres;
181 -       } else {
182 -               var->xres_virtual = var->xres = xres;
183 -               var->yres_virtual = var->yres = yres;
184 -               var->yres_virtual *= 2;
185 -       }
186 -
187         /* update scannout timings */
188         sync = 0;
189         bp = sync + var->hsync_len;
190         disp = bp + var->left_margin;
191 -       fp = disp + xres;
192 +       fp = disp + width;
193         total = fp + var->right_margin;
194  
195         reg_set_bit_mask(glamo, GLAMO_REG_LCD_HORIZ_TOTAL,
196 @@ -420,7 +405,7 @@ static void glamofb_update_lcd_controller(struct glamofb_handle *glamo,
197         sync = 0;
198         bp = sync + var->vsync_len;
199         disp = bp + var->upper_margin;
200 -       fp = disp + yres;
201 +       fp = disp + height;
202         total = fp + var->lower_margin;
203  
204         reg_set_bit_mask(glamo, GLAMO_REG_LCD_VERT_TOTAL,
205 @@ -836,6 +821,8 @@ static int __init glamofb_probe(struct platform_device *pdev)
206         glamofb->fb = fbinfo;
207         glamofb->dev = &pdev->dev;
208  
209 +       glamofb->angle = 0;
210 +
211         strcpy(fbinfo->fix.id, "SMedia Glamo");
212  
213         glamofb->reg = platform_get_resource_byname(pdev, IORESOURCE_MEM,
214 -- 
215 1.5.2.2
216