blob: 789450bb0bc9c020aec0320bf6125a85417a7bb5 [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>
Freddy Spierenburgcacfc8c2006-02-24 13:04:17 -080052#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Pete Popov3b495f22005-04-04 01:06:19 +000054#include <asm/mach-au1x00/au1000.h>
55
56#define DEBUG 0
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#include "au1100fb.h"
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060/*
61 * Sanity check. If this is a new Au1100 based board, search for
62 * the PB1100 ifdefs to make sure you modify the code accordingly.
63 */
Pete Popov3b495f22005-04-04 01:06:19 +000064#if defined(CONFIG_MIPS_PB1100)
65 #include <asm/mach-pb1x00/pb1100.h>
66#elif defined(CONFIG_MIPS_DB1100)
67 #include <asm/mach-db1x00/db1x00.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#else
Pete Popov3b495f22005-04-04 01:06:19 +000069 #error "Unknown Au1100 board, Au1100 FB driver not supported"
Linus Torvalds1da177e2005-04-16 15:20:36 -070070#endif
71
Pete Popov3b495f22005-04-04 01:06:19 +000072#define DRIVER_NAME "au1100fb"
73#define DRIVER_DESC "LCD controller driver for AU1100 processors"
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Pete Popov3b495f22005-04-04 01:06:19 +000075#define to_au1100fb_device(_info) \
76 (_info ? container_of(_info, struct au1100fb_device, info) : NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Pete Popov3b495f22005-04-04 01:06:19 +000078/* Bitfields format supported by the controller. Note that the order of formats
79 * SHOULD be the same as in the LCD_CONTROL_SBPPF field, so we can retrieve the
80 * right pixel format by doing rgb_bitfields[LCD_CONTROL_SBPPF_XXX >> LCD_CONTROL_SBPPF]
81 */
82struct fb_bitfield rgb_bitfields[][4] =
Linus Torvalds1da177e2005-04-16 15:20:36 -070083{
Pete Popov3b495f22005-04-04 01:06:19 +000084 /* Red, Green, Blue, Transp */
85 { { 10, 6, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
86 { { 11, 5, 0 }, { 5, 6, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
87 { { 11, 5, 0 }, { 6, 5, 0 }, { 0, 6, 0 }, { 0, 0, 0 } },
88 { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 15, 1, 0 } },
89 { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 1, 0 } },
90
91 /* The last is used to describe 12bpp format */
92 { { 8, 4, 0 }, { 4, 4, 0 }, { 0, 4, 0 }, { 0, 0, 0 } },
93};
94
95static struct fb_fix_screeninfo au1100fb_fix __initdata = {
96 .id = "AU1100 FB",
97 .xpanstep = 1,
98 .ypanstep = 1,
99 .type = FB_TYPE_PACKED_PIXELS,
100 .accel = FB_ACCEL_NONE,
101};
102
103static struct fb_var_screeninfo au1100fb_var __initdata = {
104 .activate = FB_ACTIVATE_NOW,
105 .height = -1,
106 .width = -1,
107 .vmode = FB_VMODE_NONINTERLACED,
108};
109
110static struct au1100fb_drv_info drv_info;
111
112/*
113 * Set hardware with var settings. This will enable the controller with a specific
114 * mode, normally validated with the fb_check_var method
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 */
Pete Popov3b495f22005-04-04 01:06:19 +0000116int au1100fb_setmode(struct au1100fb_device *fbdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117{
Pete Popov3b495f22005-04-04 01:06:19 +0000118 struct fb_info *info = &fbdev->info;
119 u32 words;
120 int index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Pete Popov3b495f22005-04-04 01:06:19 +0000122 if (!fbdev)
123 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
Pete Popov3b495f22005-04-04 01:06:19 +0000125 /* Update var-dependent FB info */
126 if (panel_is_active(fbdev->panel) || panel_is_color(fbdev->panel)) {
127 if (info->var.bits_per_pixel <= 8) {
128 /* palettized */
129 info->var.red.offset = 0;
130 info->var.red.length = info->var.bits_per_pixel;
131 info->var.red.msb_right = 0;
132
133 info->var.green.offset = 0;
134 info->var.green.length = info->var.bits_per_pixel;
135 info->var.green.msb_right = 0;
136
137 info->var.blue.offset = 0;
138 info->var.blue.length = info->var.bits_per_pixel;
139 info->var.blue.msb_right = 0;
140
141 info->var.transp.offset = 0;
142 info->var.transp.length = 0;
143 info->var.transp.msb_right = 0;
144
145 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
146 info->fix.line_length = info->var.xres_virtual /
147 (8/info->var.bits_per_pixel);
148 } else {
149 /* non-palettized */
150 index = (fbdev->panel->control_base & LCD_CONTROL_SBPPF_MASK) >> LCD_CONTROL_SBPPF_BIT;
151 info->var.red = rgb_bitfields[index][0];
152 info->var.green = rgb_bitfields[index][1];
153 info->var.blue = rgb_bitfields[index][2];
154 info->var.transp = rgb_bitfields[index][3];
155
156 info->fix.visual = FB_VISUAL_TRUECOLOR;
157 info->fix.line_length = info->var.xres_virtual << 1; /* depth=16 */
158 }
159 } else {
160 /* mono */
161 info->fix.visual = FB_VISUAL_MONO10;
162 info->fix.line_length = info->var.xres_virtual / 8;
163 }
164
165 info->screen_size = info->fix.line_length * info->var.yres_virtual;
166
167 /* Determine BPP mode and format */
168 fbdev->regs->lcd_control = fbdev->panel->control_base |
169 ((info->var.rotate/90) << LCD_CONTROL_SM_BIT);
170
171 fbdev->regs->lcd_intenable = 0;
172 fbdev->regs->lcd_intstatus = 0;
173
174 fbdev->regs->lcd_horztiming = fbdev->panel->horztiming;
175
176 fbdev->regs->lcd_verttiming = fbdev->panel->verttiming;
177
178 fbdev->regs->lcd_clkcontrol = fbdev->panel->clkcontrol_base;
179
180 fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(fbdev->fb_phys);
181
182 if (panel_is_dual(fbdev->panel)) {
183 /* Second panel display seconf half of screen if possible,
184 * otherwise display the same as the first panel */
185 if (info->var.yres_virtual >= (info->var.yres << 1)) {
186 fbdev->regs->lcd_dmaaddr1 = LCD_DMA_SA_N(fbdev->fb_phys +
187 (info->fix.line_length *
188 (info->var.yres_virtual >> 1)));
189 } else {
190 fbdev->regs->lcd_dmaaddr1 = LCD_DMA_SA_N(fbdev->fb_phys);
191 }
192 }
193
194 words = info->fix.line_length / sizeof(u32);
195 if (!info->var.rotate || (info->var.rotate == 180)) {
196 words *= info->var.yres_virtual;
197 if (info->var.rotate /* 180 */) {
198 words -= (words % 8); /* should be divisable by 8 */
199 }
200 }
201 fbdev->regs->lcd_words = LCD_WRD_WRDS_N(words);
202
203 fbdev->regs->lcd_pwmdiv = 0;
204 fbdev->regs->lcd_pwmhi = 0;
205
206 /* Resume controller */
207 fbdev->regs->lcd_control |= LCD_CONTROL_GO;
208
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 return 0;
210}
211
Pete Popov3b495f22005-04-04 01:06:19 +0000212/* fb_setcolreg
213 * Set color in LCD palette.
214 */
215int au1100fb_fb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue, unsigned transp, struct fb_info *fbi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216{
Rodolfo Giomettic05b7f32006-05-30 21:26:57 -0700217 struct au1100fb_device *fbdev;
218 u32 *palette;
Pete Popov3b495f22005-04-04 01:06:19 +0000219 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
Rodolfo Giomettic05b7f32006-05-30 21:26:57 -0700221 fbdev = to_au1100fb_device(fbi);
222 palette = fbdev->regs->lcd_pallettebase;
223
Pete Popov3b495f22005-04-04 01:06:19 +0000224 if (regno > (AU1100_LCD_NBR_PALETTE_ENTRIES - 1))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 return -EINVAL;
Pete Popov3b495f22005-04-04 01:06:19 +0000226
227 if (fbi->var.grayscale) {
228 /* Convert color to grayscale */
229 red = green = blue =
230 (19595 * red + 38470 * green + 7471 * blue) >> 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 }
232
Pete Popov3b495f22005-04-04 01:06:19 +0000233 if (fbi->fix.visual == FB_VISUAL_TRUECOLOR) {
234 /* Place color in the pseudopalette */
235 if (regno > 16)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 return -EINVAL;
237
Pete Popov3b495f22005-04-04 01:06:19 +0000238 palette = (u32*)fbi->pseudo_palette;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
Pete Popov3b495f22005-04-04 01:06:19 +0000240 red >>= (16 - fbi->var.red.length);
241 green >>= (16 - fbi->var.green.length);
242 blue >>= (16 - fbi->var.blue.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
Pete Popov3b495f22005-04-04 01:06:19 +0000244 value = (red << fbi->var.red.offset) |
245 (green << fbi->var.green.offset)|
246 (blue << fbi->var.blue.offset);
247 value &= 0xFFFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
Pete Popov3b495f22005-04-04 01:06:19 +0000249 } else if (panel_is_active(fbdev->panel)) {
250 /* COLOR TFT PALLETTIZED (use RGB 565) */
251 value = (red & 0xF800)|((green >> 5) & 0x07E0)|((blue >> 11) & 0x001F);
252 value &= 0xFFFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
Pete Popov3b495f22005-04-04 01:06:19 +0000254 } else if (panel_is_color(fbdev->panel)) {
255 /* COLOR STN MODE */
256 value = (((panel_swap_rgb(fbdev->panel) ? blue : red) >> 12) & 0x000F) |
257 ((green >> 8) & 0x00F0) |
258 (((panel_swap_rgb(fbdev->panel) ? red : blue) >> 4) & 0x0F00);
259 value &= 0xFFF;
260 } else {
261 /* MONOCHROME MODE */
262 value = (green >> 12) & 0x000F;
263 value &= 0xF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 }
265
Pete Popov3b495f22005-04-04 01:06:19 +0000266 palette[regno] = value;
267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 return 0;
269}
270
Pete Popov3b495f22005-04-04 01:06:19 +0000271/* fb_blank
272 * Blank the screen. Depending on the mode, the screen will be
273 * activated with the backlight color, or desactivated
274 */
275int au1100fb_fb_blank(int blank_mode, struct fb_info *fbi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276{
Pete Popov3b495f22005-04-04 01:06:19 +0000277 struct au1100fb_device *fbdev = to_au1100fb_device(fbi);
278
279 print_dbg("fb_blank %d %p", blank_mode, fbi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
281 switch (blank_mode) {
Pete Popov3b495f22005-04-04 01:06:19 +0000282
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 case VESA_NO_BLANKING:
Pete Popov3b495f22005-04-04 01:06:19 +0000284 /* Turn on panel */
285 fbdev->regs->lcd_control |= LCD_CONTROL_GO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286#ifdef CONFIG_MIPS_PB1100
Pete Popov3b495f22005-04-04 01:06:19 +0000287 if (drv_info.panel_idx == 1) {
288 au_writew(au_readw(PB1100_G_CONTROL)
289 | (PB1100_G_CONTROL_BL | PB1100_G_CONTROL_VDD),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 PB1100_G_CONTROL);
Pete Popov3b495f22005-04-04 01:06:19 +0000291 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292#endif
293 au_sync();
294 break;
295
296 case VESA_VSYNC_SUSPEND:
297 case VESA_HSYNC_SUSPEND:
298 case VESA_POWERDOWN:
Pete Popov3b495f22005-04-04 01:06:19 +0000299 /* Turn off panel */
300 fbdev->regs->lcd_control &= ~LCD_CONTROL_GO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301#ifdef CONFIG_MIPS_PB1100
Pete Popov3b495f22005-04-04 01:06:19 +0000302 if (drv_info.panel_idx == 1) {
303 au_writew(au_readw(PB1100_G_CONTROL)
304 & ~(PB1100_G_CONTROL_BL | PB1100_G_CONTROL_VDD),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 PB1100_G_CONTROL);
Pete Popov3b495f22005-04-04 01:06:19 +0000306 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307#endif
308 au_sync();
309 break;
310 default:
311 break;
312
313 }
314 return 0;
315}
316
Pete Popov3b495f22005-04-04 01:06:19 +0000317/* fb_pan_display
318 * Pan display in x and/or y as specified
319 */
320int au1100fb_fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *fbi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321{
Rodolfo Giomettic05b7f32006-05-30 21:26:57 -0700322 struct au1100fb_device *fbdev;
Pete Popov3b495f22005-04-04 01:06:19 +0000323 int dy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
Rodolfo Giomettic05b7f32006-05-30 21:26:57 -0700325 fbdev = to_au1100fb_device(fbi);
326
Pete Popov3b495f22005-04-04 01:06:19 +0000327 print_dbg("fb_pan_display %p %p", var, fbi);
328
329 if (!var || !fbdev) {
330 return -EINVAL;
331 }
332
333 if (var->xoffset - fbi->var.xoffset) {
334 /* No support for X panning for now! */
335 return -EINVAL;
336 }
337
338 print_dbg("fb_pan_display 2 %p %p", var, fbi);
339 dy = var->yoffset - fbi->var.yoffset;
340 if (dy) {
341
342 u32 dmaaddr;
343
344 print_dbg("Panning screen of %d lines", dy);
345
346 dmaaddr = fbdev->regs->lcd_dmaaddr0;
347 dmaaddr += (fbi->fix.line_length * dy);
348
349 /* TODO: Wait for current frame to finished */
350 fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(dmaaddr);
351
352 if (panel_is_dual(fbdev->panel)) {
353 dmaaddr = fbdev->regs->lcd_dmaaddr1;
354 dmaaddr += (fbi->fix.line_length * dy);
355 fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(dmaaddr);
356 }
357 }
358 print_dbg("fb_pan_display 3 %p %p", var, fbi);
359
360 return 0;
361}
362
363/* fb_rotate
364 * Rotate the display of this angle. This doesn't seems to be used by the core,
365 * but as our hardware supports it, so why not implementing it...
366 */
367void au1100fb_fb_rotate(struct fb_info *fbi, int angle)
368{
369 struct au1100fb_device *fbdev = to_au1100fb_device(fbi);
370
371 print_dbg("fb_rotate %p %d", fbi, angle);
372
373 if (fbdev && (angle > 0) && !(angle % 90)) {
374
375 fbdev->regs->lcd_control &= ~LCD_CONTROL_GO;
376
377 fbdev->regs->lcd_control &= ~(LCD_CONTROL_SM_MASK);
378 fbdev->regs->lcd_control |= ((angle/90) << LCD_CONTROL_SM_BIT);
379
380 fbdev->regs->lcd_control |= LCD_CONTROL_GO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 }
382}
383
Pete Popov3b495f22005-04-04 01:06:19 +0000384/* fb_mmap
385 * Map video memory in user space. We don't use the generic fb_mmap method mainly
386 * to allow the use of the TLB streaming flag (CCA=6)
387 */
Christoph Hellwig216d5262006-01-14 13:21:25 -0800388int au1100fb_fb_mmap(struct fb_info *fbi, struct vm_area_struct *vma)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389{
Rodolfo Giomettic05b7f32006-05-30 21:26:57 -0700390 struct au1100fb_device *fbdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 unsigned int len;
392 unsigned long start=0, off;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
Rodolfo Giomettic05b7f32006-05-30 21:26:57 -0700394 fbdev = to_au1100fb_device(fbi);
395
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) {
397 return -EINVAL;
398 }
399
Pete Popov3b495f22005-04-04 01:06:19 +0000400 start = fbdev->fb_phys & PAGE_MASK;
401 len = PAGE_ALIGN((start & ~PAGE_MASK) + fbdev->fb_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
403 off = vma->vm_pgoff << PAGE_SHIFT;
404
405 if ((vma->vm_end - vma->vm_start + off) > len) {
406 return -EINVAL;
407 }
408
409 off += start;
410 vma->vm_pgoff = off >> PAGE_SHIFT;
411
Pete Popov3b495f22005-04-04 01:06:19 +0000412 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 pgprot_val(vma->vm_page_prot) |= (6 << 9); //CCA=6
414
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 vma->vm_flags |= VM_IO;
416
Freddy Spierenburgcacfc8c2006-02-24 13:04:17 -0800417 if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 vma->vm_end - vma->vm_start,
419 vma->vm_page_prot)) {
420 return -EAGAIN;
421 }
422
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 return 0;
424}
425
Pete Popov3b495f22005-04-04 01:06:19 +0000426static struct fb_ops au1100fb_ops =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427{
Pete Popov3b495f22005-04-04 01:06:19 +0000428 .owner = THIS_MODULE,
429 .fb_setcolreg = au1100fb_fb_setcolreg,
430 .fb_blank = au1100fb_fb_blank,
431 .fb_pan_display = au1100fb_fb_pan_display,
432 .fb_fillrect = cfb_fillrect,
433 .fb_copyarea = cfb_copyarea,
434 .fb_imageblit = cfb_imageblit,
435 .fb_rotate = au1100fb_fb_rotate,
436 .fb_mmap = au1100fb_fb_mmap,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437};
438
439
Pete Popov3b495f22005-04-04 01:06:19 +0000440/*-------------------------------------------------------------------------*/
441
442/* AU1100 LCD controller device driver */
443
444int au1100fb_drv_probe(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445{
Pete Popov3b495f22005-04-04 01:06:19 +0000446 struct au1100fb_device *fbdev = NULL;
447 struct resource *regs_res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 unsigned long page;
Pete Popov3b495f22005-04-04 01:06:19 +0000449 u32 sys_clksrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
Pete Popov3b495f22005-04-04 01:06:19 +0000451 if (!dev)
452 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
Pete Popov3b495f22005-04-04 01:06:19 +0000454 /* Allocate new device private */
455 if (!(fbdev = kmalloc(sizeof(struct au1100fb_device), GFP_KERNEL))) {
456 print_err("fail to allocate device private record");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 return -ENOMEM;
458 }
Pete Popov3b495f22005-04-04 01:06:19 +0000459 memset((void*)fbdev, 0, sizeof(struct au1100fb_device));
460
461 fbdev->panel = &known_lcd_panels[drv_info.panel_idx];
462
463 dev_set_drvdata(dev, (void*)fbdev);
464
465 /* Allocate region for our registers and map them */
466 if (!(regs_res = platform_get_resource(to_platform_device(dev),
467 IORESOURCE_MEM, 0))) {
468 print_err("fail to retrieve registers resource");
469 return -EFAULT;
470 }
471
472 au1100fb_fix.mmio_start = regs_res->start;
473 au1100fb_fix.mmio_len = regs_res->end - regs_res->start + 1;
474
475 if (!request_mem_region(au1100fb_fix.mmio_start, au1100fb_fix.mmio_len,
476 DRIVER_NAME)) {
Rodolfo Giomettic05b7f32006-05-30 21:26:57 -0700477 print_err("fail to lock memory region at 0x%08lx",
Pete Popov3b495f22005-04-04 01:06:19 +0000478 au1100fb_fix.mmio_start);
479 return -EBUSY;
480 }
481
482 fbdev->regs = (struct au1100fb_regs*)KSEG1ADDR(au1100fb_fix.mmio_start);
483
484 print_dbg("Register memory map at %p", fbdev->regs);
485 print_dbg("phys=0x%08x, size=%d", fbdev->regs_phys, fbdev->regs_len);
486
487
488
489 /* Allocate the framebuffer to the maximum screen size * nbr of video buffers */
490 fbdev->fb_len = fbdev->panel->xres * fbdev->panel->yres *
491 (fbdev->panel->bpp >> 3) * AU1100FB_NBR_VIDEO_BUFFERS;
492
493 fbdev->fb_mem = dma_alloc_coherent(dev, PAGE_ALIGN(fbdev->fb_len),
494 &fbdev->fb_phys, GFP_KERNEL);
495 if (!fbdev->fb_mem) {
496 print_err("fail to allocate frambuffer (size: %dK))",
497 fbdev->fb_len / 1024);
498 return -ENOMEM;
499 }
500
501 au1100fb_fix.smem_start = fbdev->fb_phys;
502 au1100fb_fix.smem_len = fbdev->fb_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
504 /*
505 * Set page reserved so that mmap will work. This is necessary
506 * since we'll be remapping normal memory.
507 */
Pete Popov3b495f22005-04-04 01:06:19 +0000508 for (page = (unsigned long)fbdev->fb_mem;
509 page < PAGE_ALIGN((unsigned long)fbdev->fb_mem + fbdev->fb_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 page += PAGE_SIZE) {
Pete Popov3b495f22005-04-04 01:06:19 +0000511#if CONFIG_DMA_NONCOHERENT
512 SetPageReserved(virt_to_page(CAC_ADDR(page)));
513#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 SetPageReserved(virt_to_page(page));
Pete Popov3b495f22005-04-04 01:06:19 +0000515#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 }
517
Pete Popov3b495f22005-04-04 01:06:19 +0000518 print_dbg("Framebuffer memory map at %p", fbdev->fb_mem);
519 print_dbg("phys=0x%08x, size=%dK", fbdev->fb_phys, fbdev->fb_len / 1024);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520
Pete Popov3b495f22005-04-04 01:06:19 +0000521 /* Setup LCD clock to AUX (48 MHz) */
522 sys_clksrc = au_readl(SYS_CLKSRC) & ~(SYS_CS_ML_MASK | SYS_CS_DL | SYS_CS_CL);
523 au_writel((sys_clksrc | (1 << SYS_CS_ML_BIT)), SYS_CLKSRC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
Pete Popov3b495f22005-04-04 01:06:19 +0000525 /* load the panel info into the var struct */
526 au1100fb_var.bits_per_pixel = fbdev->panel->bpp;
527 au1100fb_var.xres = fbdev->panel->xres;
528 au1100fb_var.xres_virtual = au1100fb_var.xres;
529 au1100fb_var.yres = fbdev->panel->yres;
530 au1100fb_var.yres_virtual = au1100fb_var.yres;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
Pete Popov3b495f22005-04-04 01:06:19 +0000532 fbdev->info.screen_base = fbdev->fb_mem;
533 fbdev->info.fbops = &au1100fb_ops;
534 fbdev->info.fix = au1100fb_fix;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
Pete Popov3b495f22005-04-04 01:06:19 +0000536 if (!(fbdev->info.pseudo_palette = kmalloc(sizeof(u32) * 16, GFP_KERNEL))) {
537 return -ENOMEM;
538 }
539 memset(fbdev->info.pseudo_palette, 0, sizeof(u32) * 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
Pete Popov3b495f22005-04-04 01:06:19 +0000541 if (fb_alloc_cmap(&fbdev->info.cmap, AU1100_LCD_NBR_PALETTE_ENTRIES, 0) < 0) {
542 print_err("Fail to allocate colormap (%d entries)",
543 AU1100_LCD_NBR_PALETTE_ENTRIES);
544 kfree(fbdev->info.pseudo_palette);
545 return -EFAULT;
546 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
Pete Popov3b495f22005-04-04 01:06:19 +0000548 fbdev->info.var = au1100fb_var;
549
550 /* Set h/w registers */
551 au1100fb_setmode(fbdev);
552
553 /* Register new framebuffer */
554 if (register_framebuffer(&fbdev->info) < 0) {
555 print_err("cannot register new framebuffer");
556 goto failed;
557 }
558
559 return 0;
560
561failed:
562 if (fbdev->regs) {
563 release_mem_region(fbdev->regs_phys, fbdev->regs_len);
564 }
565 if (fbdev->fb_mem) {
566 dma_free_noncoherent(dev, fbdev->fb_len, fbdev->fb_mem, fbdev->fb_phys);
567 }
568 if (fbdev->info.cmap.len != 0) {
569 fb_dealloc_cmap(&fbdev->info.cmap);
570 }
571 kfree(fbdev);
572 dev_set_drvdata(dev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573
574 return 0;
575}
576
Pete Popov3b495f22005-04-04 01:06:19 +0000577int au1100fb_drv_remove(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578{
Pete Popov3b495f22005-04-04 01:06:19 +0000579 struct au1100fb_device *fbdev = NULL;
580
581 if (!dev)
582 return -ENODEV;
583
584 fbdev = (struct au1100fb_device*) dev_get_drvdata(dev);
585
586#if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
587 au1100fb_fb_blank(VESA_POWERDOWN, &fbdev->info);
588#endif
589 fbdev->regs->lcd_control &= ~LCD_CONTROL_GO;
590
591 /* Clean up all probe data */
592 unregister_framebuffer(&fbdev->info);
593
594 release_mem_region(fbdev->regs_phys, fbdev->regs_len);
595
596 dma_free_coherent(dev, PAGE_ALIGN(fbdev->fb_len), fbdev->fb_mem, fbdev->fb_phys);
597
598 fb_dealloc_cmap(&fbdev->info.cmap);
599 kfree(fbdev->info.pseudo_palette);
600 kfree((void*)fbdev);
601
602 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603}
604
Rodolfo Giomettic05b7f32006-05-30 21:26:57 -0700605int au1100fb_drv_suspend(struct device *dev, pm_message_t state)
Pete Popov3b495f22005-04-04 01:06:19 +0000606{
607 /* TODO */
608 return 0;
609}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
Rodolfo Giomettic05b7f32006-05-30 21:26:57 -0700611int au1100fb_drv_resume(struct device *dev)
Pete Popov3b495f22005-04-04 01:06:19 +0000612{
613 /* TODO */
614 return 0;
615}
616
617static struct device_driver au1100fb_driver = {
618 .name = "au1100-lcd",
619 .bus = &platform_bus_type,
620
621 .probe = au1100fb_drv_probe,
622 .remove = au1100fb_drv_remove,
623 .suspend = au1100fb_drv_suspend,
624 .resume = au1100fb_drv_resume,
625};
626
627/*-------------------------------------------------------------------------*/
628
629/* Kernel driver */
630
631int au1100fb_setup(char *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632{
633 char* this_opt;
Pete Popov3b495f22005-04-04 01:06:19 +0000634 int num_panels = ARRAY_SIZE(known_lcd_panels);
635 char* mode = NULL;
636 int panel_idx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637
Pete Popov3b495f22005-04-04 01:06:19 +0000638 if (num_panels <= 0) {
639 print_err("No LCD panels supported by driver!");
640 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 }
Pete Popov3b495f22005-04-04 01:06:19 +0000642
643 if (options) {
644 while ((this_opt = strsep(&options,",")) != NULL) {
645 /* Panel option */
646 if (!strncmp(this_opt, "panel:", 6)) {
647 int i;
648 this_opt += 6;
649 for (i = 0; i < num_panels; i++) {
650 if (!strncmp(this_opt,
651 known_lcd_panels[i].name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 strlen(this_opt))) {
Pete Popov3b495f22005-04-04 01:06:19 +0000653 panel_idx = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 break;
655 }
656 }
Pete Popov3b495f22005-04-04 01:06:19 +0000657 if (i >= num_panels) {
658 print_warn("Panel %s not supported!", this_opt);
659 }
660 }
661 /* Mode option (only option that start with digit) */
662 else if (isdigit(this_opt[0])) {
663 mode = kmalloc(strlen(this_opt) + 1, GFP_KERNEL);
664 strncpy(mode, this_opt, strlen(this_opt) + 1);
665 }
666 /* Unsupported option */
667 else {
668 print_warn("Unsupported option \"%s\"", this_opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 }
671 }
672
Pete Popov3b495f22005-04-04 01:06:19 +0000673 drv_info.panel_idx = panel_idx;
674 drv_info.opt_mode = mode;
675
676 print_info("Panel=%s Mode=%s",
677 known_lcd_panels[drv_info.panel_idx].name,
678 drv_info.opt_mode ? drv_info.opt_mode : "default");
679
680 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681}
682
Pete Popov3b495f22005-04-04 01:06:19 +0000683int __init au1100fb_init(void)
684{
685 char* options;
686 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
Pete Popov3b495f22005-04-04 01:06:19 +0000688 print_info("" DRIVER_DESC "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689
Pete Popov3b495f22005-04-04 01:06:19 +0000690 memset(&drv_info, 0, sizeof(drv_info));
691
692 if (fb_get_options(DRIVER_NAME, &options))
693 return -ENODEV;
694
695 /* Setup driver with options */
696 ret = au1100fb_setup(options);
697 if (ret < 0) {
698 print_err("Fail to setup driver");
699 return ret;
700 }
701
702 return driver_register(&au1100fb_driver);
703}
704
705void __exit au1100fb_cleanup(void)
706{
707 driver_unregister(&au1100fb_driver);
708
709 if (drv_info.opt_mode)
710 kfree(drv_info.opt_mode);
711}
712
713module_init(au1100fb_init);
714module_exit(au1100fb_cleanup);
715
716MODULE_DESCRIPTION(DRIVER_DESC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717MODULE_LICENSE("GPL");