blob: 2406899f12078fd5d958a6b9495a3f6e33564fe3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * BRIEF MODULE DESCRIPTION
3 * Au1100 LCD Driver.
4 *
Pete Popov3b495f22005-04-04 01:06:19 +00005 * 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 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * 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 */
Pete Popov3b495f22005-04-04 01:06:19 +000041#include <linux/config.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/module.h>
43#include <linux/kernel.h>
44#include <linux/errno.h>
45#include <linux/string.h>
46#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <linux/fb.h>
48#include <linux/init.h>
Pete Popov3b495f22005-04-04 01:06:19 +000049#include <linux/interrupt.h>
50#include <linux/ctype.h>
51#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Pete Popov3b495f22005-04-04 01:06:19 +000053#include <asm/mach-au1x00/au1000.h>
54
55#define DEBUG 0
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#include "au1100fb.h"
58
Linus Torvalds1da177e2005-04-16 15:20:36 -070059/*
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 */
Pete Popov3b495f22005-04-04 01:06:19 +000063#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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070067#else
Pete Popov3b495f22005-04-04 01:06:19 +000068 #error "Unknown Au1100 board, Au1100 FB driver not supported"
Linus Torvalds1da177e2005-04-16 15:20:36 -070069#endif
70
Pete Popov3b495f22005-04-04 01:06:19 +000071#define DRIVER_NAME "au1100fb"
72#define DRIVER_DESC "LCD controller driver for AU1100 processors"
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Pete Popov3b495f22005-04-04 01:06:19 +000074#define to_au1100fb_device(_info) \
75 (_info ? container_of(_info, struct au1100fb_device, info) : NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Pete Popov3b495f22005-04-04 01:06:19 +000077/* 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 */
81struct fb_bitfield rgb_bitfields[][4] =
Linus Torvalds1da177e2005-04-16 15:20:36 -070082{
Pete Popov3b495f22005-04-04 01:06:19 +000083 /* 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 } },
92};
93
94static 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,
100};
101
102static struct fb_var_screeninfo au1100fb_var __initdata = {
103 .activate = FB_ACTIVATE_NOW,
104 .height = -1,
105 .width = -1,
106 .vmode = FB_VMODE_NONINTERLACED,
107};
108
109static struct au1100fb_drv_info drv_info;
110
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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 */
Pete Popov3b495f22005-04-04 01:06:19 +0000115int au1100fb_setmode(struct au1100fb_device *fbdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116{
Pete Popov3b495f22005-04-04 01:06:19 +0000117 struct fb_info *info = &fbdev->info;
118 u32 words;
119 int index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
Pete Popov3b495f22005-04-04 01:06:19 +0000121 if (!fbdev)
122 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
Pete Popov3b495f22005-04-04 01:06:19 +0000124 /* 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;
162 }
163
164 info->screen_size = info->fix.line_length * info->var.yres_virtual;
165
166 /* Determine BPP mode and format */
167 fbdev->regs->lcd_control = fbdev->panel->control_base |
168 ((info->var.rotate/90) << LCD_CONTROL_SM_BIT);
169
170 fbdev->regs->lcd_intenable = 0;
171 fbdev->regs->lcd_intstatus = 0;
172
173 fbdev->regs->lcd_horztiming = fbdev->panel->horztiming;
174
175 fbdev->regs->lcd_verttiming = fbdev->panel->verttiming;
176
177 fbdev->regs->lcd_clkcontrol = fbdev->panel->clkcontrol_base;
178
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 }
191 }
192
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);
201
202 fbdev->regs->lcd_pwmdiv = 0;
203 fbdev->regs->lcd_pwmhi = 0;
204
205 /* Resume controller */
206 fbdev->regs->lcd_control |= LCD_CONTROL_GO;
207
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 return 0;
209}
210
Pete Popov3b495f22005-04-04 01:06:19 +0000211/* fb_setcolreg
212 * Set color in LCD palette.
213 */
214int au1100fb_fb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue, unsigned transp, struct fb_info *fbi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215{
Pete Popov3b495f22005-04-04 01:06:19 +0000216 struct au1100fb_device *fbdev = to_au1100fb_device(fbi);
217 u32 *palette = fbdev->regs->lcd_pallettebase;
218 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
Pete Popov3b495f22005-04-04 01:06:19 +0000220 if (regno > (AU1100_LCD_NBR_PALETTE_ENTRIES - 1))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 return -EINVAL;
Pete Popov3b495f22005-04-04 01:06:19 +0000222
223 if (fbi->var.grayscale) {
224 /* Convert color to grayscale */
225 red = green = blue =
226 (19595 * red + 38470 * green + 7471 * blue) >> 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 }
228
Pete Popov3b495f22005-04-04 01:06:19 +0000229 if (fbi->fix.visual == FB_VISUAL_TRUECOLOR) {
230 /* Place color in the pseudopalette */
231 if (regno > 16)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 return -EINVAL;
233
Pete Popov3b495f22005-04-04 01:06:19 +0000234 palette = (u32*)fbi->pseudo_palette;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
Pete Popov3b495f22005-04-04 01:06:19 +0000236 red >>= (16 - fbi->var.red.length);
237 green >>= (16 - fbi->var.green.length);
238 blue >>= (16 - fbi->var.blue.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
Pete Popov3b495f22005-04-04 01:06:19 +0000240 value = (red << fbi->var.red.offset) |
241 (green << fbi->var.green.offset)|
242 (blue << fbi->var.blue.offset);
243 value &= 0xFFFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
Pete Popov3b495f22005-04-04 01:06:19 +0000245 } 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
Pete Popov3b495f22005-04-04 01:06:19 +0000250 } 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 }
261
Pete Popov3b495f22005-04-04 01:06:19 +0000262 palette[regno] = value;
263
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 return 0;
265}
266
Pete Popov3b495f22005-04-04 01:06:19 +0000267/* fb_blank
268 * Blank the screen. Depending on the mode, the screen will be
269 * activated with the backlight color, or desactivated
270 */
271int au1100fb_fb_blank(int blank_mode, struct fb_info *fbi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272{
Pete Popov3b495f22005-04-04 01:06:19 +0000273 struct au1100fb_device *fbdev = to_au1100fb_device(fbi);
274
275 print_dbg("fb_blank %d %p", blank_mode, fbi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
277 switch (blank_mode) {
Pete Popov3b495f22005-04-04 01:06:19 +0000278
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 case VESA_NO_BLANKING:
Pete Popov3b495f22005-04-04 01:06:19 +0000280 /* Turn on panel */
281 fbdev->regs->lcd_control |= LCD_CONTROL_GO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282#ifdef CONFIG_MIPS_PB1100
Pete Popov3b495f22005-04-04 01:06:19 +0000283 if (drv_info.panel_idx == 1) {
284 au_writew(au_readw(PB1100_G_CONTROL)
285 | (PB1100_G_CONTROL_BL | PB1100_G_CONTROL_VDD),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 PB1100_G_CONTROL);
Pete Popov3b495f22005-04-04 01:06:19 +0000287 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288#endif
289 au_sync();
290 break;
291
292 case VESA_VSYNC_SUSPEND:
293 case VESA_HSYNC_SUSPEND:
294 case VESA_POWERDOWN:
Pete Popov3b495f22005-04-04 01:06:19 +0000295 /* Turn off panel */
296 fbdev->regs->lcd_control &= ~LCD_CONTROL_GO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297#ifdef CONFIG_MIPS_PB1100
Pete Popov3b495f22005-04-04 01:06:19 +0000298 if (drv_info.panel_idx == 1) {
299 au_writew(au_readw(PB1100_G_CONTROL)
300 & ~(PB1100_G_CONTROL_BL | PB1100_G_CONTROL_VDD),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 PB1100_G_CONTROL);
Pete Popov3b495f22005-04-04 01:06:19 +0000302 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303#endif
304 au_sync();
305 break;
306 default:
307 break;
308
309 }
310 return 0;
311}
312
Pete Popov3b495f22005-04-04 01:06:19 +0000313/* fb_pan_display
314 * Pan display in x and/or y as specified
315 */
316int au1100fb_fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *fbi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317{
Pete Popov3b495f22005-04-04 01:06:19 +0000318 struct au1100fb_device *fbdev = to_au1100fb_device(fbi);
319 int dy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
Pete Popov3b495f22005-04-04 01:06:19 +0000321 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 */
361void 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 }
376}
377
Pete Popov3b495f22005-04-04 01:06:19 +0000378/* 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 */
Christoph Hellwig216d5262006-01-14 13:21:25 -0800382int au1100fb_fb_mmap(struct fb_info *fbi, struct vm_area_struct *vma)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383{
Pete Popov3b495f22005-04-04 01:06:19 +0000384 struct au1100fb_device *fbdev = to_au1100fb_device(fbi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 unsigned int len;
386 unsigned long start=0, off;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
388 if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) {
389 return -EINVAL;
390 }
391
Pete Popov3b495f22005-04-04 01:06:19 +0000392 start = fbdev->fb_phys & PAGE_MASK;
393 len = PAGE_ALIGN((start & ~PAGE_MASK) + fbdev->fb_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
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
Pete Popov3b495f22005-04-04 01:06:19 +0000404 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 pgprot_val(vma->vm_page_prot) |= (6 << 9); //CCA=6
406
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 vma->vm_flags |= VM_IO;
408
Pete Popov3b495f22005-04-04 01:06:19 +0000409 if (io_remap_page_range(vma, vma->vm_start, off,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 vma->vm_end - vma->vm_start,
411 vma->vm_page_prot)) {
412 return -EAGAIN;
413 }
414
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 return 0;
416}
417
Pete Popov3b495f22005-04-04 01:06:19 +0000418static struct fb_ops au1100fb_ops =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419{
Pete Popov3b495f22005-04-04 01:06:19 +0000420 .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,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429};
430
431
Pete Popov3b495f22005-04-04 01:06:19 +0000432/*-------------------------------------------------------------------------*/
433
434/* AU1100 LCD controller device driver */
435
436int au1100fb_drv_probe(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437{
Pete Popov3b495f22005-04-04 01:06:19 +0000438 struct au1100fb_device *fbdev = NULL;
439 struct resource *regs_res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 unsigned long page;
Pete Popov3b495f22005-04-04 01:06:19 +0000441 u32 sys_clksrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442
Pete Popov3b495f22005-04-04 01:06:19 +0000443 if (!dev)
444 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
Pete Popov3b495f22005-04-04 01:06:19 +0000446 /* Allocate new device private */
447 if (!(fbdev = kmalloc(sizeof(struct au1100fb_device), GFP_KERNEL))) {
448 print_err("fail to allocate device private record");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 return -ENOMEM;
450 }
Pete Popov3b495f22005-04-04 01:06:19 +0000451 memset((void*)fbdev, 0, sizeof(struct au1100fb_device));
452
453 fbdev->panel = &known_lcd_panels[drv_info.panel_idx];
454
455 dev_set_drvdata(dev, (void*)fbdev);
456
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 }
463
464 au1100fb_fix.mmio_start = regs_res->start;
465 au1100fb_fix.mmio_len = regs_res->end - regs_res->start + 1;
466
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 }
473
474 fbdev->regs = (struct au1100fb_regs*)KSEG1ADDR(au1100fb_fix.mmio_start);
475
476 print_dbg("Register memory map at %p", fbdev->regs);
477 print_dbg("phys=0x%08x, size=%d", fbdev->regs_phys, fbdev->regs_len);
478
479
480
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);
490 return -ENOMEM;
491 }
492
493 au1100fb_fix.smem_start = fbdev->fb_phys;
494 au1100fb_fix.smem_len = fbdev->fb_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
496 /*
497 * Set page reserved so that mmap will work. This is necessary
498 * since we'll be remapping normal memory.
499 */
Pete Popov3b495f22005-04-04 01:06:19 +0000500 for (page = (unsigned long)fbdev->fb_mem;
501 page < PAGE_ALIGN((unsigned long)fbdev->fb_mem + fbdev->fb_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 page += PAGE_SIZE) {
Pete Popov3b495f22005-04-04 01:06:19 +0000503#if CONFIG_DMA_NONCOHERENT
504 SetPageReserved(virt_to_page(CAC_ADDR(page)));
505#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 SetPageReserved(virt_to_page(page));
Pete Popov3b495f22005-04-04 01:06:19 +0000507#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 }
509
Pete Popov3b495f22005-04-04 01:06:19 +0000510 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
Pete Popov3b495f22005-04-04 01:06:19 +0000513 /* 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
Pete Popov3b495f22005-04-04 01:06:19 +0000517 /* 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
Pete Popov3b495f22005-04-04 01:06:19 +0000524 fbdev->info.screen_base = fbdev->fb_mem;
525 fbdev->info.fbops = &au1100fb_ops;
526 fbdev->info.fix = au1100fb_fix;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
Pete Popov3b495f22005-04-04 01:06:19 +0000528 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
Pete Popov3b495f22005-04-04 01:06:19 +0000533 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 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
Pete Popov3b495f22005-04-04 01:06:19 +0000540 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
553failed:
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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
566 return 0;
567}
568
Pete Popov3b495f22005-04-04 01:06:19 +0000569int au1100fb_drv_remove(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570{
Pete Popov3b495f22005-04-04 01:06:19 +0000571 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;
582
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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595}
596
Pete Popov3b495f22005-04-04 01:06:19 +0000597int au1100fb_drv_suspend(struct device *dev, u32 state, u32 level)
598{
599 /* TODO */
600 return 0;
601}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
Pete Popov3b495f22005-04-04 01:06:19 +0000603int au1100fb_drv_resume(struct device *dev, u32 level)
604{
605 /* TODO */
606 return 0;
607}
608
609static struct device_driver au1100fb_driver = {
610 .name = "au1100-lcd",
611 .bus = &platform_bus_type,
612
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
623int au1100fb_setup(char *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624{
625 char* this_opt;
Pete Popov3b495f22005-04-04 01:06:19 +0000626 int num_panels = ARRAY_SIZE(known_lcd_panels);
627 char* mode = NULL;
628 int panel_idx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629
Pete Popov3b495f22005-04-04 01:06:19 +0000630 if (num_panels <= 0) {
631 print_err("No LCD panels supported by driver!");
632 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 }
Pete Popov3b495f22005-04-04 01:06:19 +0000634
635 if (options) {
636 while ((this_opt = strsep(&options,",")) != NULL) {
637 /* Panel option */
638 if (!strncmp(this_opt, "panel:", 6)) {
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,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 strlen(this_opt))) {
Pete Popov3b495f22005-04-04 01:06:19 +0000645 panel_idx = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 break;
647 }
648 }
Pete Popov3b495f22005-04-04 01:06:19 +0000649 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 }
663 }
664
Pete Popov3b495f22005-04-04 01:06:19 +0000665 drv_info.panel_idx = panel_idx;
666 drv_info.opt_mode = mode;
667
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");
671
672 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673}
674
Pete Popov3b495f22005-04-04 01:06:19 +0000675int __init au1100fb_init(void)
676{
677 char* options;
678 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679
Pete Popov3b495f22005-04-04 01:06:19 +0000680 print_info("" DRIVER_DESC "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
Pete Popov3b495f22005-04-04 01:06:19 +0000682 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);
695}
696
697void __exit au1100fb_cleanup(void)
698{
699 driver_unregister(&au1100fb_driver);
700
701 if (drv_info.opt_mode)
702 kfree(drv_info.opt_mode);
703}
704
705module_init(au1100fb_init);
706module_exit(au1100fb_cleanup);
707
708MODULE_DESCRIPTION(DRIVER_DESC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709MODULE_LICENSE("GPL");