]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * BRIEF MODULE DESCRIPTION | |
3 | * Au1100 LCD Driver. | |
4 | * | |
3b495f2b PP |
5 | * Rewritten for 2.6 by Embedded Alley Solutions |
6 | * <source@embeddedalley.com>, based on submissions by | |
7 | * Karl Lessard <klessard@sunrisetelecom.com> | |
8 | * <c.pellegrin@exadron.com> | |
9 | * | |
f77f50ca | 10 | * PM support added by Rodolfo Giometti <giometti@linux.it> |
ca27ac4c | 11 | * Cursor enable/disable by Rodolfo Giometti <giometti@linux.it> |
f77f50ca | 12 | * |
1da177e4 LT |
13 | * Copyright 2002 MontaVista Software |
14 | * Author: MontaVista Software, Inc. | |
15 | * ppopov@mvista.com or source@mvista.com | |
16 | * | |
17 | * Copyright 2002 Alchemy Semiconductor | |
18 | * Author: Alchemy Semiconductor | |
19 | * | |
20 | * Based on: | |
21 | * linux/drivers/video/skeletonfb.c -- Skeleton for a frame buffer device | |
22 | * Created 28 Dec 1997 by Geert Uytterhoeven | |
23 | * | |
24 | * This program is free software; you can redistribute it and/or modify it | |
25 | * under the terms of the GNU General Public License as published by the | |
26 | * Free Software Foundation; either version 2 of the License, or (at your | |
27 | * option) any later version. | |
28 | * | |
29 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED | |
30 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
31 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN | |
32 | * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
33 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
34 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |
35 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | |
36 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
37 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
38 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
39 | * | |
40 | * You should have received a copy of the GNU General Public License along | |
41 | * with this program; if not, write to the Free Software Foundation, Inc., | |
42 | * 675 Mass Ave, Cambridge, MA 02139, USA. | |
43 | */ | |
1da177e4 LT |
44 | #include <linux/module.h> |
45 | #include <linux/kernel.h> | |
46 | #include <linux/errno.h> | |
47 | #include <linux/string.h> | |
48 | #include <linux/mm.h> | |
1da177e4 LT |
49 | #include <linux/fb.h> |
50 | #include <linux/init.h> | |
3b495f2b PP |
51 | #include <linux/interrupt.h> |
52 | #include <linux/ctype.h> | |
53 | #include <linux/dma-mapping.h> | |
cacfc8cf | 54 | #include <linux/platform_device.h> |
1da177e4 | 55 | |
3b495f2b | 56 | #include <asm/mach-au1x00/au1000.h> |
1da177e4 | 57 | |
3b495f2b PP |
58 | #define DEBUG 0 |
59 | ||
60 | #include "au1100fb.h" | |
1da177e4 LT |
61 | |
62 | /* | |
63 | * Sanity check. If this is a new Au1100 based board, search for | |
64 | * the PB1100 ifdefs to make sure you modify the code accordingly. | |
65 | */ | |
3b495f2b PP |
66 | #if defined(CONFIG_MIPS_PB1100) |
67 | #include <asm/mach-pb1x00/pb1100.h> | |
68 | #elif defined(CONFIG_MIPS_DB1100) | |
69 | #include <asm/mach-db1x00/db1x00.h> | |
1da177e4 | 70 | #else |
3b495f2b | 71 | #error "Unknown Au1100 board, Au1100 FB driver not supported" |
1da177e4 LT |
72 | #endif |
73 | ||
3b495f2b PP |
74 | #define DRIVER_NAME "au1100fb" |
75 | #define DRIVER_DESC "LCD controller driver for AU1100 processors" | |
1da177e4 | 76 | |
3b495f2b PP |
77 | #define to_au1100fb_device(_info) \ |
78 | (_info ? container_of(_info, struct au1100fb_device, info) : NULL); | |
1da177e4 | 79 | |
3b495f2b PP |
80 | /* Bitfields format supported by the controller. Note that the order of formats |
81 | * SHOULD be the same as in the LCD_CONTROL_SBPPF field, so we can retrieve the | |
82 | * right pixel format by doing rgb_bitfields[LCD_CONTROL_SBPPF_XXX >> LCD_CONTROL_SBPPF] | |
83 | */ | |
84 | struct fb_bitfield rgb_bitfields[][4] = | |
85 | { | |
86 | /* Red, Green, Blue, Transp */ | |
87 | { { 10, 6, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } }, | |
88 | { { 11, 5, 0 }, { 5, 6, 0 }, { 0, 5, 0 }, { 0, 0, 0 } }, | |
89 | { { 11, 5, 0 }, { 6, 5, 0 }, { 0, 6, 0 }, { 0, 0, 0 } }, | |
90 | { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 15, 1, 0 } }, | |
91 | { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 1, 0 } }, | |
92 | ||
93 | /* The last is used to describe 12bpp format */ | |
94 | { { 8, 4, 0 }, { 4, 4, 0 }, { 0, 4, 0 }, { 0, 0, 0 } }, | |
1da177e4 LT |
95 | }; |
96 | ||
3b495f2b PP |
97 | static struct fb_fix_screeninfo au1100fb_fix __initdata = { |
98 | .id = "AU1100 FB", | |
99 | .xpanstep = 1, | |
100 | .ypanstep = 1, | |
101 | .type = FB_TYPE_PACKED_PIXELS, | |
102 | .accel = FB_ACCEL_NONE, | |
1da177e4 LT |
103 | }; |
104 | ||
3b495f2b PP |
105 | static struct fb_var_screeninfo au1100fb_var __initdata = { |
106 | .activate = FB_ACTIVATE_NOW, | |
107 | .height = -1, | |
108 | .width = -1, | |
109 | .vmode = FB_VMODE_NONINTERLACED, | |
1da177e4 LT |
110 | }; |
111 | ||
3b495f2b | 112 | static struct au1100fb_drv_info drv_info; |
1da177e4 | 113 | |
ca27ac4c RG |
114 | static int nocursor = 0; |
115 | module_param(nocursor, int, 0644); | |
116 | MODULE_PARM_DESC(nocursor, "cursor enable/disable"); | |
117 | ||
3b495f2b PP |
118 | /* |
119 | * Set hardware with var settings. This will enable the controller with a specific | |
120 | * mode, normally validated with the fb_check_var method | |
1da177e4 | 121 | */ |
3b495f2b | 122 | int au1100fb_setmode(struct au1100fb_device *fbdev) |
1da177e4 | 123 | { |
3b495f2b PP |
124 | struct fb_info *info = &fbdev->info; |
125 | u32 words; | |
126 | int index; | |
1da177e4 | 127 | |
3b495f2b PP |
128 | if (!fbdev) |
129 | return -EINVAL; | |
130 | ||
131 | /* Update var-dependent FB info */ | |
132 | if (panel_is_active(fbdev->panel) || panel_is_color(fbdev->panel)) { | |
133 | if (info->var.bits_per_pixel <= 8) { | |
134 | /* palettized */ | |
135 | info->var.red.offset = 0; | |
136 | info->var.red.length = info->var.bits_per_pixel; | |
137 | info->var.red.msb_right = 0; | |
138 | ||
139 | info->var.green.offset = 0; | |
140 | info->var.green.length = info->var.bits_per_pixel; | |
141 | info->var.green.msb_right = 0; | |
142 | ||
143 | info->var.blue.offset = 0; | |
144 | info->var.blue.length = info->var.bits_per_pixel; | |
145 | info->var.blue.msb_right = 0; | |
146 | ||
147 | info->var.transp.offset = 0; | |
148 | info->var.transp.length = 0; | |
149 | info->var.transp.msb_right = 0; | |
150 | ||
151 | info->fix.visual = FB_VISUAL_PSEUDOCOLOR; | |
152 | info->fix.line_length = info->var.xres_virtual / | |
153 | (8/info->var.bits_per_pixel); | |
154 | } else { | |
155 | /* non-palettized */ | |
156 | index = (fbdev->panel->control_base & LCD_CONTROL_SBPPF_MASK) >> LCD_CONTROL_SBPPF_BIT; | |
157 | info->var.red = rgb_bitfields[index][0]; | |
158 | info->var.green = rgb_bitfields[index][1]; | |
159 | info->var.blue = rgb_bitfields[index][2]; | |
160 | info->var.transp = rgb_bitfields[index][3]; | |
161 | ||
162 | info->fix.visual = FB_VISUAL_TRUECOLOR; | |
163 | info->fix.line_length = info->var.xres_virtual << 1; /* depth=16 */ | |
bb39e419 | 164 | } |
3b495f2b PP |
165 | } else { |
166 | /* mono */ | |
167 | info->fix.visual = FB_VISUAL_MONO10; | |
168 | info->fix.line_length = info->var.xres_virtual / 8; | |
1da177e4 LT |
169 | } |
170 | ||
3b495f2b | 171 | info->screen_size = info->fix.line_length * info->var.yres_virtual; |
fd2d5430 RG |
172 | info->var.rotate = ((fbdev->panel->control_base&LCD_CONTROL_SM_MASK) \ |
173 | >> LCD_CONTROL_SM_BIT) * 90; | |
1da177e4 | 174 | |
3b495f2b | 175 | /* Determine BPP mode and format */ |
fd2d5430 | 176 | fbdev->regs->lcd_control = fbdev->panel->control_base; |
3b495f2b | 177 | fbdev->regs->lcd_horztiming = fbdev->panel->horztiming; |
3b495f2b | 178 | fbdev->regs->lcd_verttiming = fbdev->panel->verttiming; |
3b495f2b | 179 | fbdev->regs->lcd_clkcontrol = fbdev->panel->clkcontrol_base; |
bb39e419 RG |
180 | fbdev->regs->lcd_intenable = 0; |
181 | fbdev->regs->lcd_intstatus = 0; | |
3b495f2b PP |
182 | fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(fbdev->fb_phys); |
183 | ||
184 | if (panel_is_dual(fbdev->panel)) { | |
185 | /* Second panel display seconf half of screen if possible, | |
186 | * otherwise display the same as the first panel */ | |
187 | if (info->var.yres_virtual >= (info->var.yres << 1)) { | |
188 | fbdev->regs->lcd_dmaaddr1 = LCD_DMA_SA_N(fbdev->fb_phys + | |
189 | (info->fix.line_length * | |
190 | (info->var.yres_virtual >> 1))); | |
191 | } else { | |
192 | fbdev->regs->lcd_dmaaddr1 = LCD_DMA_SA_N(fbdev->fb_phys); | |
193 | } | |
1da177e4 | 194 | } |
1da177e4 | 195 | |
3b495f2b PP |
196 | words = info->fix.line_length / sizeof(u32); |
197 | if (!info->var.rotate || (info->var.rotate == 180)) { | |
198 | words *= info->var.yres_virtual; | |
199 | if (info->var.rotate /* 180 */) { | |
200 | words -= (words % 8); /* should be divisable by 8 */ | |
201 | } | |
202 | } | |
203 | fbdev->regs->lcd_words = LCD_WRD_WRDS_N(words); | |
1da177e4 | 204 | |
3b495f2b PP |
205 | fbdev->regs->lcd_pwmdiv = 0; |
206 | fbdev->regs->lcd_pwmhi = 0; | |
1da177e4 | 207 | |
3b495f2b PP |
208 | /* Resume controller */ |
209 | fbdev->regs->lcd_control |= LCD_CONTROL_GO; | |
bb39e419 RG |
210 | mdelay(10); |
211 | au1100fb_fb_blank(VESA_NO_BLANKING, info); | |
1da177e4 | 212 | |
3b495f2b | 213 | return 0; |
1da177e4 LT |
214 | } |
215 | ||
3b495f2b PP |
216 | /* fb_setcolreg |
217 | * Set color in LCD palette. | |
218 | */ | |
219 | int au1100fb_fb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue, unsigned transp, struct fb_info *fbi) | |
1da177e4 | 220 | { |
c05b7f3d RG |
221 | struct au1100fb_device *fbdev; |
222 | u32 *palette; | |
3b495f2b | 223 | u32 value; |
1da177e4 | 224 | |
c05b7f3d RG |
225 | fbdev = to_au1100fb_device(fbi); |
226 | palette = fbdev->regs->lcd_pallettebase; | |
227 | ||
3b495f2b PP |
228 | if (regno > (AU1100_LCD_NBR_PALETTE_ENTRIES - 1)) |
229 | return -EINVAL; | |
1da177e4 | 230 | |
3b495f2b PP |
231 | if (fbi->var.grayscale) { |
232 | /* Convert color to grayscale */ | |
233 | red = green = blue = | |
234 | (19595 * red + 38470 * green + 7471 * blue) >> 16; | |
235 | } | |
1da177e4 | 236 | |
3b495f2b PP |
237 | if (fbi->fix.visual == FB_VISUAL_TRUECOLOR) { |
238 | /* Place color in the pseudopalette */ | |
239 | if (regno > 16) | |
240 | return -EINVAL; | |
1da177e4 | 241 | |
3b495f2b PP |
242 | palette = (u32*)fbi->pseudo_palette; |
243 | ||
244 | red >>= (16 - fbi->var.red.length); | |
245 | green >>= (16 - fbi->var.green.length); | |
246 | blue >>= (16 - fbi->var.blue.length); | |
247 | ||
248 | value = (red << fbi->var.red.offset) | | |
249 | (green << fbi->var.green.offset)| | |
250 | (blue << fbi->var.blue.offset); | |
251 | value &= 0xFFFF; | |
252 | ||
253 | } else if (panel_is_active(fbdev->panel)) { | |
254 | /* COLOR TFT PALLETTIZED (use RGB 565) */ | |
255 | value = (red & 0xF800)|((green >> 5) & 0x07E0)|((blue >> 11) & 0x001F); | |
256 | value &= 0xFFFF; | |
257 | ||
258 | } else if (panel_is_color(fbdev->panel)) { | |
259 | /* COLOR STN MODE */ | |
260 | value = (((panel_swap_rgb(fbdev->panel) ? blue : red) >> 12) & 0x000F) | | |
261 | ((green >> 8) & 0x00F0) | | |
262 | (((panel_swap_rgb(fbdev->panel) ? red : blue) >> 4) & 0x0F00); | |
263 | value &= 0xFFF; | |
264 | } else { | |
265 | /* MONOCHROME MODE */ | |
266 | value = (green >> 12) & 0x000F; | |
267 | value &= 0xF; | |
1da177e4 LT |
268 | } |
269 | ||
3b495f2b PP |
270 | palette[regno] = value; |
271 | ||
1da177e4 LT |
272 | return 0; |
273 | } | |
274 | ||
3b495f2b PP |
275 | /* fb_blank |
276 | * Blank the screen. Depending on the mode, the screen will be | |
277 | * activated with the backlight color, or desactivated | |
278 | */ | |
279 | int au1100fb_fb_blank(int blank_mode, struct fb_info *fbi) | |
1da177e4 | 280 | { |
3b495f2b PP |
281 | struct au1100fb_device *fbdev = to_au1100fb_device(fbi); |
282 | ||
283 | print_dbg("fb_blank %d %p", blank_mode, fbi); | |
1da177e4 LT |
284 | |
285 | switch (blank_mode) { | |
3b495f2b | 286 | |
1da177e4 | 287 | case VESA_NO_BLANKING: |
3b495f2b PP |
288 | /* Turn on panel */ |
289 | fbdev->regs->lcd_control |= LCD_CONTROL_GO; | |
1da177e4 | 290 | #ifdef CONFIG_MIPS_PB1100 |
3b495f2b PP |
291 | if (drv_info.panel_idx == 1) { |
292 | au_writew(au_readw(PB1100_G_CONTROL) | |
293 | | (PB1100_G_CONTROL_BL | PB1100_G_CONTROL_VDD), | |
1da177e4 | 294 | PB1100_G_CONTROL); |
3b495f2b | 295 | } |
1da177e4 LT |
296 | #endif |
297 | au_sync(); | |
298 | break; | |
299 | ||
300 | case VESA_VSYNC_SUSPEND: | |
301 | case VESA_HSYNC_SUSPEND: | |
302 | case VESA_POWERDOWN: | |
3b495f2b PP |
303 | /* Turn off panel */ |
304 | fbdev->regs->lcd_control &= ~LCD_CONTROL_GO; | |
1da177e4 | 305 | #ifdef CONFIG_MIPS_PB1100 |
3b495f2b PP |
306 | if (drv_info.panel_idx == 1) { |
307 | au_writew(au_readw(PB1100_G_CONTROL) | |
308 | & ~(PB1100_G_CONTROL_BL | PB1100_G_CONTROL_VDD), | |
1da177e4 | 309 | PB1100_G_CONTROL); |
3b495f2b | 310 | } |
1da177e4 LT |
311 | #endif |
312 | au_sync(); | |
313 | break; | |
314 | default: | |
315 | break; | |
316 | ||
317 | } | |
318 | return 0; | |
319 | } | |
320 | ||
3b495f2b PP |
321 | /* fb_pan_display |
322 | * Pan display in x and/or y as specified | |
323 | */ | |
324 | int au1100fb_fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *fbi) | |
1da177e4 | 325 | { |
c05b7f3d | 326 | struct au1100fb_device *fbdev; |
3b495f2b PP |
327 | int dy; |
328 | ||
c05b7f3d RG |
329 | fbdev = to_au1100fb_device(fbi); |
330 | ||
3b495f2b PP |
331 | print_dbg("fb_pan_display %p %p", var, fbi); |
332 | ||
333 | if (!var || !fbdev) { | |
334 | return -EINVAL; | |
335 | } | |
336 | ||
337 | if (var->xoffset - fbi->var.xoffset) { | |
338 | /* No support for X panning for now! */ | |
339 | return -EINVAL; | |
340 | } | |
341 | ||
342 | print_dbg("fb_pan_display 2 %p %p", var, fbi); | |
343 | dy = var->yoffset - fbi->var.yoffset; | |
344 | if (dy) { | |
345 | ||
346 | u32 dmaaddr; | |
347 | ||
348 | print_dbg("Panning screen of %d lines", dy); | |
349 | ||
350 | dmaaddr = fbdev->regs->lcd_dmaaddr0; | |
351 | dmaaddr += (fbi->fix.line_length * dy); | |
352 | ||
353 | /* TODO: Wait for current frame to finished */ | |
354 | fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(dmaaddr); | |
355 | ||
356 | if (panel_is_dual(fbdev->panel)) { | |
357 | dmaaddr = fbdev->regs->lcd_dmaaddr1; | |
358 | dmaaddr += (fbi->fix.line_length * dy); | |
359 | fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(dmaaddr); | |
360 | } | |
361 | } | |
362 | print_dbg("fb_pan_display 3 %p %p", var, fbi); | |
363 | ||
364 | return 0; | |
365 | } | |
366 | ||
367 | /* fb_rotate | |
368 | * Rotate the display of this angle. This doesn't seems to be used by the core, | |
369 | * but as our hardware supports it, so why not implementing it... | |
370 | */ | |
371 | void au1100fb_fb_rotate(struct fb_info *fbi, int angle) | |
372 | { | |
373 | struct au1100fb_device *fbdev = to_au1100fb_device(fbi); | |
374 | ||
375 | print_dbg("fb_rotate %p %d", fbi, angle); | |
376 | ||
377 | if (fbdev && (angle > 0) && !(angle % 90)) { | |
378 | ||
379 | fbdev->regs->lcd_control &= ~LCD_CONTROL_GO; | |
380 | ||
381 | fbdev->regs->lcd_control &= ~(LCD_CONTROL_SM_MASK); | |
382 | fbdev->regs->lcd_control |= ((angle/90) << LCD_CONTROL_SM_BIT); | |
383 | ||
384 | fbdev->regs->lcd_control |= LCD_CONTROL_GO; | |
1da177e4 LT |
385 | } |
386 | } | |
387 | ||
3b495f2b PP |
388 | /* fb_mmap |
389 | * Map video memory in user space. We don't use the generic fb_mmap method mainly | |
390 | * to allow the use of the TLB streaming flag (CCA=6) | |
391 | */ | |
216d526c | 392 | int au1100fb_fb_mmap(struct fb_info *fbi, struct vm_area_struct *vma) |
1da177e4 | 393 | { |
c05b7f3d | 394 | struct au1100fb_device *fbdev; |
1da177e4 LT |
395 | unsigned int len; |
396 | unsigned long start=0, off; | |
1da177e4 | 397 | |
c05b7f3d RG |
398 | fbdev = to_au1100fb_device(fbi); |
399 | ||
1da177e4 LT |
400 | if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) { |
401 | return -EINVAL; | |
402 | } | |
403 | ||
3b495f2b PP |
404 | start = fbdev->fb_phys & PAGE_MASK; |
405 | len = PAGE_ALIGN((start & ~PAGE_MASK) + fbdev->fb_len); | |
1da177e4 LT |
406 | |
407 | off = vma->vm_pgoff << PAGE_SHIFT; | |
408 | ||
409 | if ((vma->vm_end - vma->vm_start + off) > len) { | |
410 | return -EINVAL; | |
411 | } | |
412 | ||
413 | off += start; | |
414 | vma->vm_pgoff = off >> PAGE_SHIFT; | |
415 | ||
3b495f2b | 416 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); |
1da177e4 LT |
417 | pgprot_val(vma->vm_page_prot) |= (6 << 9); //CCA=6 |
418 | ||
1da177e4 LT |
419 | vma->vm_flags |= VM_IO; |
420 | ||
cacfc8cf | 421 | if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT, |
1da177e4 LT |
422 | vma->vm_end - vma->vm_start, |
423 | vma->vm_page_prot)) { | |
424 | return -EAGAIN; | |
425 | } | |
426 | ||
1da177e4 LT |
427 | return 0; |
428 | } | |
429 | ||
ca27ac4c RG |
430 | /* fb_cursor |
431 | * Used to disable cursor drawing... | |
432 | */ | |
433 | int au1100fb_fb_cursor(struct fb_info *info, struct fb_cursor *cursor) | |
434 | { | |
435 | if (nocursor) | |
436 | return 0; | |
437 | else | |
438 | return -EINVAL; /* just to force soft_cursor() call */ | |
439 | } | |
440 | ||
3b495f2b | 441 | static struct fb_ops au1100fb_ops = |
1da177e4 | 442 | { |
3b495f2b PP |
443 | .owner = THIS_MODULE, |
444 | .fb_setcolreg = au1100fb_fb_setcolreg, | |
445 | .fb_blank = au1100fb_fb_blank, | |
446 | .fb_pan_display = au1100fb_fb_pan_display, | |
447 | .fb_fillrect = cfb_fillrect, | |
448 | .fb_copyarea = cfb_copyarea, | |
449 | .fb_imageblit = cfb_imageblit, | |
450 | .fb_rotate = au1100fb_fb_rotate, | |
451 | .fb_mmap = au1100fb_fb_mmap, | |
ca27ac4c | 452 | .fb_cursor = au1100fb_fb_cursor, |
3b495f2b | 453 | }; |
1da177e4 | 454 | |
1da177e4 | 455 | |
3b495f2b | 456 | /*-------------------------------------------------------------------------*/ |
1da177e4 | 457 | |
3b495f2b | 458 | /* AU1100 LCD controller device driver */ |
1da177e4 | 459 | |
3b495f2b | 460 | int au1100fb_drv_probe(struct device *dev) |
1da177e4 | 461 | { |
3b495f2b PP |
462 | struct au1100fb_device *fbdev = NULL; |
463 | struct resource *regs_res; | |
464 | unsigned long page; | |
465 | u32 sys_clksrc; | |
466 | ||
467 | if (!dev) | |
1da177e4 | 468 | return -EINVAL; |
3b495f2b PP |
469 | |
470 | /* Allocate new device private */ | |
f5610b9c | 471 | if (!(fbdev = kzalloc(sizeof(struct au1100fb_device), GFP_KERNEL))) { |
3b495f2b PP |
472 | print_err("fail to allocate device private record"); |
473 | return -ENOMEM; | |
1da177e4 LT |
474 | } |
475 | ||
3b495f2b | 476 | fbdev->panel = &known_lcd_panels[drv_info.panel_idx]; |
1da177e4 | 477 | |
3b495f2b | 478 | dev_set_drvdata(dev, (void*)fbdev); |
1da177e4 | 479 | |
3b495f2b PP |
480 | /* Allocate region for our registers and map them */ |
481 | if (!(regs_res = platform_get_resource(to_platform_device(dev), | |
482 | IORESOURCE_MEM, 0))) { | |
483 | print_err("fail to retrieve registers resource"); | |
484 | return -EFAULT; | |
485 | } | |
1da177e4 | 486 | |
3b495f2b PP |
487 | au1100fb_fix.mmio_start = regs_res->start; |
488 | au1100fb_fix.mmio_len = regs_res->end - regs_res->start + 1; | |
1da177e4 | 489 | |
3b495f2b PP |
490 | if (!request_mem_region(au1100fb_fix.mmio_start, au1100fb_fix.mmio_len, |
491 | DRIVER_NAME)) { | |
c05b7f3d | 492 | print_err("fail to lock memory region at 0x%08lx", |
3b495f2b PP |
493 | au1100fb_fix.mmio_start); |
494 | return -EBUSY; | |
495 | } | |
1da177e4 | 496 | |
3b495f2b | 497 | fbdev->regs = (struct au1100fb_regs*)KSEG1ADDR(au1100fb_fix.mmio_start); |
1da177e4 | 498 | |
3b495f2b PP |
499 | print_dbg("Register memory map at %p", fbdev->regs); |
500 | print_dbg("phys=0x%08x, size=%d", fbdev->regs_phys, fbdev->regs_len); | |
1da177e4 | 501 | |
1da177e4 | 502 | |
1da177e4 | 503 | |
3b495f2b PP |
504 | /* Allocate the framebuffer to the maximum screen size * nbr of video buffers */ |
505 | fbdev->fb_len = fbdev->panel->xres * fbdev->panel->yres * | |
506 | (fbdev->panel->bpp >> 3) * AU1100FB_NBR_VIDEO_BUFFERS; | |
507 | ||
508 | fbdev->fb_mem = dma_alloc_coherent(dev, PAGE_ALIGN(fbdev->fb_len), | |
509 | &fbdev->fb_phys, GFP_KERNEL); | |
510 | if (!fbdev->fb_mem) { | |
511 | print_err("fail to allocate frambuffer (size: %dK))", | |
512 | fbdev->fb_len / 1024); | |
1da177e4 LT |
513 | return -ENOMEM; |
514 | } | |
3b495f2b PP |
515 | |
516 | au1100fb_fix.smem_start = fbdev->fb_phys; | |
517 | au1100fb_fix.smem_len = fbdev->fb_len; | |
1da177e4 LT |
518 | |
519 | /* | |
520 | * Set page reserved so that mmap will work. This is necessary | |
521 | * since we'll be remapping normal memory. | |
522 | */ | |
3b495f2b PP |
523 | for (page = (unsigned long)fbdev->fb_mem; |
524 | page < PAGE_ALIGN((unsigned long)fbdev->fb_mem + fbdev->fb_len); | |
1da177e4 | 525 | page += PAGE_SIZE) { |
3b495f2b PP |
526 | #if CONFIG_DMA_NONCOHERENT |
527 | SetPageReserved(virt_to_page(CAC_ADDR(page))); | |
528 | #else | |
1da177e4 | 529 | SetPageReserved(virt_to_page(page)); |
3b495f2b | 530 | #endif |
1da177e4 LT |
531 | } |
532 | ||
3b495f2b PP |
533 | print_dbg("Framebuffer memory map at %p", fbdev->fb_mem); |
534 | print_dbg("phys=0x%08x, size=%dK", fbdev->fb_phys, fbdev->fb_len / 1024); | |
535 | ||
536 | /* Setup LCD clock to AUX (48 MHz) */ | |
537 | sys_clksrc = au_readl(SYS_CLKSRC) & ~(SYS_CS_ML_MASK | SYS_CS_DL | SYS_CS_CL); | |
538 | au_writel((sys_clksrc | (1 << SYS_CS_ML_BIT)), SYS_CLKSRC); | |
539 | ||
540 | /* load the panel info into the var struct */ | |
541 | au1100fb_var.bits_per_pixel = fbdev->panel->bpp; | |
542 | au1100fb_var.xres = fbdev->panel->xres; | |
543 | au1100fb_var.xres_virtual = au1100fb_var.xres; | |
544 | au1100fb_var.yres = fbdev->panel->yres; | |
545 | au1100fb_var.yres_virtual = au1100fb_var.yres; | |
546 | ||
547 | fbdev->info.screen_base = fbdev->fb_mem; | |
548 | fbdev->info.fbops = &au1100fb_ops; | |
549 | fbdev->info.fix = au1100fb_fix; | |
550 | ||
f5610b9c | 551 | if (!(fbdev->info.pseudo_palette = kzalloc(sizeof(u32) * 16, GFP_KERNEL))) { |
3b495f2b PP |
552 | return -ENOMEM; |
553 | } | |
3b495f2b PP |
554 | |
555 | if (fb_alloc_cmap(&fbdev->info.cmap, AU1100_LCD_NBR_PALETTE_ENTRIES, 0) < 0) { | |
556 | print_err("Fail to allocate colormap (%d entries)", | |
557 | AU1100_LCD_NBR_PALETTE_ENTRIES); | |
558 | kfree(fbdev->info.pseudo_palette); | |
559 | return -EFAULT; | |
560 | } | |
561 | ||
562 | fbdev->info.var = au1100fb_var; | |
563 | ||
564 | /* Set h/w registers */ | |
565 | au1100fb_setmode(fbdev); | |
566 | ||
567 | /* Register new framebuffer */ | |
568 | if (register_framebuffer(&fbdev->info) < 0) { | |
569 | print_err("cannot register new framebuffer"); | |
570 | goto failed; | |
571 | } | |
572 | ||
573 | return 0; | |
574 | ||
575 | failed: | |
576 | if (fbdev->regs) { | |
577 | release_mem_region(fbdev->regs_phys, fbdev->regs_len); | |
578 | } | |
579 | if (fbdev->fb_mem) { | |
580 | dma_free_noncoherent(dev, fbdev->fb_len, fbdev->fb_mem, fbdev->fb_phys); | |
581 | } | |
582 | if (fbdev->info.cmap.len != 0) { | |
583 | fb_dealloc_cmap(&fbdev->info.cmap); | |
584 | } | |
585 | kfree(fbdev); | |
586 | dev_set_drvdata(dev, NULL); | |
1da177e4 LT |
587 | |
588 | return 0; | |
589 | } | |
590 | ||
3b495f2b PP |
591 | int au1100fb_drv_remove(struct device *dev) |
592 | { | |
593 | struct au1100fb_device *fbdev = NULL; | |
594 | ||
595 | if (!dev) | |
596 | return -ENODEV; | |
597 | ||
598 | fbdev = (struct au1100fb_device*) dev_get_drvdata(dev); | |
599 | ||
600 | #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO) | |
601 | au1100fb_fb_blank(VESA_POWERDOWN, &fbdev->info); | |
602 | #endif | |
603 | fbdev->regs->lcd_control &= ~LCD_CONTROL_GO; | |
1da177e4 | 604 | |
3b495f2b PP |
605 | /* Clean up all probe data */ |
606 | unregister_framebuffer(&fbdev->info); | |
607 | ||
608 | release_mem_region(fbdev->regs_phys, fbdev->regs_len); | |
609 | ||
610 | dma_free_coherent(dev, PAGE_ALIGN(fbdev->fb_len), fbdev->fb_mem, fbdev->fb_phys); | |
611 | ||
612 | fb_dealloc_cmap(&fbdev->info.cmap); | |
613 | kfree(fbdev->info.pseudo_palette); | |
614 | kfree((void*)fbdev); | |
615 | ||
616 | return 0; | |
617 | } | |
618 | ||
f77f50ca RG |
619 | #ifdef CONFIG_PM |
620 | static u32 sys_clksrc; | |
621 | static struct au1100fb_regs fbregs; | |
622 | ||
c05b7f3d | 623 | int au1100fb_drv_suspend(struct device *dev, pm_message_t state) |
3b495f2b | 624 | { |
f77f50ca RG |
625 | struct au1100fb_device *fbdev = dev_get_drvdata(dev); |
626 | ||
627 | if (!fbdev) | |
628 | return 0; | |
629 | ||
630 | /* Save the clock source state */ | |
631 | sys_clksrc = au_readl(SYS_CLKSRC); | |
632 | ||
633 | /* Blank the LCD */ | |
634 | au1100fb_fb_blank(VESA_POWERDOWN, &fbdev->info); | |
635 | ||
636 | /* Stop LCD clocking */ | |
637 | au_writel(sys_clksrc & ~SYS_CS_ML_MASK, SYS_CLKSRC); | |
638 | ||
639 | memcpy(&fbregs, fbdev->regs, sizeof(struct au1100fb_regs)); | |
640 | ||
3b495f2b PP |
641 | return 0; |
642 | } | |
643 | ||
c05b7f3d | 644 | int au1100fb_drv_resume(struct device *dev) |
1da177e4 | 645 | { |
f77f50ca RG |
646 | struct au1100fb_device *fbdev = dev_get_drvdata(dev); |
647 | ||
648 | if (!fbdev) | |
649 | return 0; | |
650 | ||
651 | memcpy(fbdev->regs, &fbregs, sizeof(struct au1100fb_regs)); | |
652 | ||
653 | /* Restart LCD clocking */ | |
654 | au_writel(sys_clksrc, SYS_CLKSRC); | |
655 | ||
656 | /* Unblank the LCD */ | |
657 | au1100fb_fb_blank(VESA_NO_BLANKING, &fbdev->info); | |
658 | ||
3b495f2b | 659 | return 0; |
1da177e4 | 660 | } |
f77f50ca RG |
661 | #else |
662 | #define au1100fb_drv_suspend NULL | |
663 | #define au1100fb_drv_resume NULL | |
664 | #endif | |
1da177e4 | 665 | |
3b495f2b PP |
666 | static struct device_driver au1100fb_driver = { |
667 | .name = "au1100-lcd", | |
668 | .bus = &platform_bus_type, | |
1da177e4 | 669 | |
3b495f2b PP |
670 | .probe = au1100fb_drv_probe, |
671 | .remove = au1100fb_drv_remove, | |
672 | .suspend = au1100fb_drv_suspend, | |
673 | .resume = au1100fb_drv_resume, | |
674 | }; | |
675 | ||
676 | /*-------------------------------------------------------------------------*/ | |
677 | ||
678 | /* Kernel driver */ | |
679 | ||
680 | int au1100fb_setup(char *options) | |
1da177e4 LT |
681 | { |
682 | char* this_opt; | |
3b495f2b PP |
683 | int num_panels = ARRAY_SIZE(known_lcd_panels); |
684 | char* mode = NULL; | |
685 | int panel_idx = 0; | |
1da177e4 | 686 | |
3b495f2b PP |
687 | if (num_panels <= 0) { |
688 | print_err("No LCD panels supported by driver!"); | |
689 | return -EFAULT; | |
690 | } | |
1da177e4 | 691 | |
3b495f2b PP |
692 | if (options) { |
693 | while ((this_opt = strsep(&options,",")) != NULL) { | |
694 | /* Panel option */ | |
ca27ac4c | 695 | if (!strncmp(this_opt, "panel:", 6)) { |
3b495f2b PP |
696 | int i; |
697 | this_opt += 6; | |
698 | for (i = 0; i < num_panels; i++) { | |
699 | if (!strncmp(this_opt, | |
700 | known_lcd_panels[i].name, | |
1da177e4 | 701 | strlen(this_opt))) { |
3b495f2b | 702 | panel_idx = i; |
ca27ac4c RG |
703 | break; |
704 | } | |
1da177e4 | 705 | } |
3b495f2b PP |
706 | if (i >= num_panels) { |
707 | print_warn("Panel %s not supported!", this_opt); | |
708 | } | |
709 | } | |
ca27ac4c RG |
710 | if (!strncmp(this_opt, "nocursor", 8)) { |
711 | this_opt += 8; | |
712 | nocursor = 1; | |
713 | print_info("Cursor disabled"); | |
714 | } | |
3b495f2b PP |
715 | /* Mode option (only option that start with digit) */ |
716 | else if (isdigit(this_opt[0])) { | |
717 | mode = kmalloc(strlen(this_opt) + 1, GFP_KERNEL); | |
718 | strncpy(mode, this_opt, strlen(this_opt) + 1); | |
719 | } | |
720 | /* Unsupported option */ | |
721 | else { | |
722 | print_warn("Unsupported option \"%s\"", this_opt); | |
ca27ac4c | 723 | } |
1da177e4 LT |
724 | } |
725 | } | |
726 | ||
3b495f2b PP |
727 | drv_info.panel_idx = panel_idx; |
728 | drv_info.opt_mode = mode; | |
1da177e4 | 729 | |
3b495f2b PP |
730 | print_info("Panel=%s Mode=%s", |
731 | known_lcd_panels[drv_info.panel_idx].name, | |
732 | drv_info.opt_mode ? drv_info.opt_mode : "default"); | |
1da177e4 | 733 | |
3b495f2b PP |
734 | return 0; |
735 | } | |
1da177e4 | 736 | |
3b495f2b | 737 | int __init au1100fb_init(void) |
1da177e4 | 738 | { |
3b495f2b PP |
739 | char* options; |
740 | int ret; | |
741 | ||
742 | print_info("" DRIVER_DESC ""); | |
743 | ||
744 | memset(&drv_info, 0, sizeof(drv_info)); | |
745 | ||
746 | if (fb_get_options(DRIVER_NAME, &options)) | |
747 | return -ENODEV; | |
748 | ||
749 | /* Setup driver with options */ | |
750 | ret = au1100fb_setup(options); | |
751 | if (ret < 0) { | |
752 | print_err("Fail to setup driver"); | |
753 | return ret; | |
754 | } | |
755 | ||
756 | return driver_register(&au1100fb_driver); | |
1da177e4 LT |
757 | } |
758 | ||
3b495f2b | 759 | void __exit au1100fb_cleanup(void) |
1da177e4 | 760 | { |
3b495f2b PP |
761 | driver_unregister(&au1100fb_driver); |
762 | ||
8f760780 | 763 | kfree(drv_info.opt_mode); |
1da177e4 LT |
764 | } |
765 | ||
3b495f2b PP |
766 | module_init(au1100fb_init); |
767 | module_exit(au1100fb_cleanup); | |
768 | ||
769 | MODULE_DESCRIPTION(DRIVER_DESC); | |
770 | MODULE_LICENSE("GPL"); |