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