blob: ef5c16f7f5a64852b1505fbab982f8f63f6b899e [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 *
Rodolfo Giomettif77f50c2006-06-26 00:26:49 -070010 * PM support added by Rodolfo Giometti <giometti@linux.it>
Rodolfo Giomettica27ac42006-10-03 01:14:36 -070011 * Cursor enable/disable by Rodolfo Giometti <giometti@linux.it>
Rodolfo Giomettif77f50c2006-06-26 00:26:49 -070012 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 * 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <linux/module.h>
45#include <linux/kernel.h>
46#include <linux/errno.h>
47#include <linux/string.h>
48#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/fb.h>
50#include <linux/init.h>
Pete Popov3b495f22005-04-04 01:06:19 +000051#include <linux/interrupt.h>
52#include <linux/ctype.h>
53#include <linux/dma-mapping.h>
Freddy Spierenburgcacfc8c2006-02-24 13:04:17 -080054#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Pete Popov3b495f22005-04-04 01:06:19 +000056#include <asm/mach-au1x00/au1000.h>
57
58#define DEBUG 0
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#include "au1100fb.h"
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062/*
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 */
Pete Popov3b495f22005-04-04 01:06:19 +000066#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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070070#else
Pete Popov3b495f22005-04-04 01:06:19 +000071 #error "Unknown Au1100 board, Au1100 FB driver not supported"
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#endif
73
Pete Popov3b495f22005-04-04 01:06:19 +000074#define DRIVER_NAME "au1100fb"
75#define DRIVER_DESC "LCD controller driver for AU1100 processors"
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Pete Popov3b495f22005-04-04 01:06:19 +000077#define to_au1100fb_device(_info) \
78 (_info ? container_of(_info, struct au1100fb_device, info) : NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Pete Popov3b495f22005-04-04 01:06:19 +000080/* 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 */
84struct fb_bitfield rgb_bitfields[][4] =
Linus Torvalds1da177e2005-04-16 15:20:36 -070085{
Pete Popov3b495f22005-04-04 01:06:19 +000086 /* 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 } },
95};
96
97static 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,
103};
104
105static struct fb_var_screeninfo au1100fb_var __initdata = {
106 .activate = FB_ACTIVATE_NOW,
107 .height = -1,
108 .width = -1,
109 .vmode = FB_VMODE_NONINTERLACED,
110};
111
112static struct au1100fb_drv_info drv_info;
113
Rodolfo Giomettica27ac42006-10-03 01:14:36 -0700114static int nocursor = 0;
115module_param(nocursor, int, 0644);
116MODULE_PARM_DESC(nocursor, "cursor enable/disable");
117
Pete Popov3b495f22005-04-04 01:06:19 +0000118/*
119 * Set hardware with var settings. This will enable the controller with a specific
120 * mode, normally validated with the fb_check_var method
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 */
Pete Popov3b495f22005-04-04 01:06:19 +0000122int au1100fb_setmode(struct au1100fb_device *fbdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123{
Pete Popov3b495f22005-04-04 01:06:19 +0000124 struct fb_info *info = &fbdev->info;
125 u32 words;
126 int index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
Pete Popov3b495f22005-04-04 01:06:19 +0000128 if (!fbdev)
129 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Pete Popov3b495f22005-04-04 01:06:19 +0000131 /* 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 */
Rodolfo Giomettibb39e412006-08-05 12:14:22 -0700164 }
Pete Popov3b495f22005-04-04 01:06:19 +0000165 } else {
166 /* mono */
167 info->fix.visual = FB_VISUAL_MONO10;
168 info->fix.line_length = info->var.xres_virtual / 8;
169 }
170
171 info->screen_size = info->fix.line_length * info->var.yres_virtual;
Rodolfo Giomettifd2d5432006-08-05 12:14:19 -0700172 info->var.rotate = ((fbdev->panel->control_base&LCD_CONTROL_SM_MASK) \
173 >> LCD_CONTROL_SM_BIT) * 90;
Pete Popov3b495f22005-04-04 01:06:19 +0000174
175 /* Determine BPP mode and format */
Rodolfo Giomettifd2d5432006-08-05 12:14:19 -0700176 fbdev->regs->lcd_control = fbdev->panel->control_base;
Rodolfo Giomettibb39e412006-08-05 12:14:22 -0700177 fbdev->regs->lcd_horztiming = fbdev->panel->horztiming;
178 fbdev->regs->lcd_verttiming = fbdev->panel->verttiming;
179 fbdev->regs->lcd_clkcontrol = fbdev->panel->clkcontrol_base;
Pete Popov3b495f22005-04-04 01:06:19 +0000180 fbdev->regs->lcd_intenable = 0;
181 fbdev->regs->lcd_intstatus = 0;
Pete Popov3b495f22005-04-04 01:06:19 +0000182 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 }
194 }
195
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);
204
205 fbdev->regs->lcd_pwmdiv = 0;
206 fbdev->regs->lcd_pwmhi = 0;
207
208 /* Resume controller */
209 fbdev->regs->lcd_control |= LCD_CONTROL_GO;
Rodolfo Giomettibb39e412006-08-05 12:14:22 -0700210 mdelay(10);
211 au1100fb_fb_blank(VESA_NO_BLANKING, info);
Pete Popov3b495f22005-04-04 01:06:19 +0000212
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 return 0;
214}
215
Pete Popov3b495f22005-04-04 01:06:19 +0000216/* fb_setcolreg
217 * Set color in LCD palette.
218 */
219int au1100fb_fb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue, unsigned transp, struct fb_info *fbi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
Rodolfo Giomettic05b7f32006-05-30 21:26:57 -0700221 struct au1100fb_device *fbdev;
222 u32 *palette;
Pete Popov3b495f22005-04-04 01:06:19 +0000223 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
Rodolfo Giomettic05b7f32006-05-30 21:26:57 -0700225 fbdev = to_au1100fb_device(fbi);
226 palette = fbdev->regs->lcd_pallettebase;
227
Pete Popov3b495f22005-04-04 01:06:19 +0000228 if (regno > (AU1100_LCD_NBR_PALETTE_ENTRIES - 1))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 return -EINVAL;
Pete Popov3b495f22005-04-04 01:06:19 +0000230
231 if (fbi->var.grayscale) {
232 /* Convert color to grayscale */
233 red = green = blue =
234 (19595 * red + 38470 * green + 7471 * blue) >> 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 }
236
Pete Popov3b495f22005-04-04 01:06:19 +0000237 if (fbi->fix.visual == FB_VISUAL_TRUECOLOR) {
238 /* Place color in the pseudopalette */
239 if (regno > 16)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 return -EINVAL;
241
Pete Popov3b495f22005-04-04 01:06:19 +0000242 palette = (u32*)fbi->pseudo_palette;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
Pete Popov3b495f22005-04-04 01:06:19 +0000244 red >>= (16 - fbi->var.red.length);
245 green >>= (16 - fbi->var.green.length);
246 blue >>= (16 - fbi->var.blue.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
Pete Popov3b495f22005-04-04 01:06:19 +0000248 value = (red << fbi->var.red.offset) |
249 (green << fbi->var.green.offset)|
250 (blue << fbi->var.blue.offset);
251 value &= 0xFFFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
Pete Popov3b495f22005-04-04 01:06:19 +0000253 } 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
Pete Popov3b495f22005-04-04 01:06:19 +0000258 } 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 }
269
Pete Popov3b495f22005-04-04 01:06:19 +0000270 palette[regno] = value;
271
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 return 0;
273}
274
Pete Popov3b495f22005-04-04 01:06:19 +0000275/* fb_blank
276 * Blank the screen. Depending on the mode, the screen will be
277 * activated with the backlight color, or desactivated
278 */
279int au1100fb_fb_blank(int blank_mode, struct fb_info *fbi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280{
Pete Popov3b495f22005-04-04 01:06:19 +0000281 struct au1100fb_device *fbdev = to_au1100fb_device(fbi);
282
283 print_dbg("fb_blank %d %p", blank_mode, fbi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
285 switch (blank_mode) {
Pete Popov3b495f22005-04-04 01:06:19 +0000286
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 case VESA_NO_BLANKING:
Pete Popov3b495f22005-04-04 01:06:19 +0000288 /* Turn on panel */
289 fbdev->regs->lcd_control |= LCD_CONTROL_GO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290#ifdef CONFIG_MIPS_PB1100
Pete Popov3b495f22005-04-04 01:06:19 +0000291 if (drv_info.panel_idx == 1) {
292 au_writew(au_readw(PB1100_G_CONTROL)
293 | (PB1100_G_CONTROL_BL | PB1100_G_CONTROL_VDD),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 PB1100_G_CONTROL);
Pete Popov3b495f22005-04-04 01:06:19 +0000295 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296#endif
297 au_sync();
298 break;
299
300 case VESA_VSYNC_SUSPEND:
301 case VESA_HSYNC_SUSPEND:
302 case VESA_POWERDOWN:
Pete Popov3b495f22005-04-04 01:06:19 +0000303 /* Turn off panel */
304 fbdev->regs->lcd_control &= ~LCD_CONTROL_GO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305#ifdef CONFIG_MIPS_PB1100
Pete Popov3b495f22005-04-04 01:06:19 +0000306 if (drv_info.panel_idx == 1) {
307 au_writew(au_readw(PB1100_G_CONTROL)
308 & ~(PB1100_G_CONTROL_BL | PB1100_G_CONTROL_VDD),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 PB1100_G_CONTROL);
Pete Popov3b495f22005-04-04 01:06:19 +0000310 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311#endif
312 au_sync();
313 break;
314 default:
315 break;
316
317 }
318 return 0;
319}
320
Pete Popov3b495f22005-04-04 01:06:19 +0000321/* fb_pan_display
322 * Pan display in x and/or y as specified
323 */
324int au1100fb_fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *fbi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325{
Rodolfo Giomettic05b7f32006-05-30 21:26:57 -0700326 struct au1100fb_device *fbdev;
Pete Popov3b495f22005-04-04 01:06:19 +0000327 int dy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
Rodolfo Giomettic05b7f32006-05-30 21:26:57 -0700329 fbdev = to_au1100fb_device(fbi);
330
Pete Popov3b495f22005-04-04 01:06:19 +0000331 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 */
371void 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 }
386}
387
Pete Popov3b495f22005-04-04 01:06:19 +0000388/* 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 */
Christoph Hellwig216d5262006-01-14 13:21:25 -0800392int au1100fb_fb_mmap(struct fb_info *fbi, struct vm_area_struct *vma)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393{
Rodolfo Giomettic05b7f32006-05-30 21:26:57 -0700394 struct au1100fb_device *fbdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 unsigned int len;
396 unsigned long start=0, off;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
Rodolfo Giomettic05b7f32006-05-30 21:26:57 -0700398 fbdev = to_au1100fb_device(fbi);
399
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) {
401 return -EINVAL;
402 }
403
Pete Popov3b495f22005-04-04 01:06:19 +0000404 start = fbdev->fb_phys & PAGE_MASK;
405 len = PAGE_ALIGN((start & ~PAGE_MASK) + fbdev->fb_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
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
Pete Popov3b495f22005-04-04 01:06:19 +0000416 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 pgprot_val(vma->vm_page_prot) |= (6 << 9); //CCA=6
418
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 vma->vm_flags |= VM_IO;
420
Freddy Spierenburgcacfc8c2006-02-24 13:04:17 -0800421 if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 vma->vm_end - vma->vm_start,
423 vma->vm_page_prot)) {
424 return -EAGAIN;
425 }
426
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 return 0;
428}
429
Rodolfo Giomettica27ac42006-10-03 01:14:36 -0700430/* fb_cursor
431 * Used to disable cursor drawing...
432 */
433int 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
Pete Popov3b495f22005-04-04 01:06:19 +0000441static struct fb_ops au1100fb_ops =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442{
Pete Popov3b495f22005-04-04 01:06:19 +0000443 .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,
Rodolfo Giomettica27ac42006-10-03 01:14:36 -0700452 .fb_cursor = au1100fb_fb_cursor,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453};
454
455
Pete Popov3b495f22005-04-04 01:06:19 +0000456/*-------------------------------------------------------------------------*/
457
458/* AU1100 LCD controller device driver */
459
460int au1100fb_drv_probe(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461{
Pete Popov3b495f22005-04-04 01:06:19 +0000462 struct au1100fb_device *fbdev = NULL;
463 struct resource *regs_res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 unsigned long page;
Pete Popov3b495f22005-04-04 01:06:19 +0000465 u32 sys_clksrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466
Pete Popov3b495f22005-04-04 01:06:19 +0000467 if (!dev)
468 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
Pete Popov3b495f22005-04-04 01:06:19 +0000470 /* Allocate new device private */
471 if (!(fbdev = kmalloc(sizeof(struct au1100fb_device), GFP_KERNEL))) {
472 print_err("fail to allocate device private record");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 return -ENOMEM;
474 }
Pete Popov3b495f22005-04-04 01:06:19 +0000475 memset((void*)fbdev, 0, sizeof(struct au1100fb_device));
476
477 fbdev->panel = &known_lcd_panels[drv_info.panel_idx];
478
479 dev_set_drvdata(dev, (void*)fbdev);
480
481 /* Allocate region for our registers and map them */
482 if (!(regs_res = platform_get_resource(to_platform_device(dev),
483 IORESOURCE_MEM, 0))) {
484 print_err("fail to retrieve registers resource");
485 return -EFAULT;
486 }
487
488 au1100fb_fix.mmio_start = regs_res->start;
489 au1100fb_fix.mmio_len = regs_res->end - regs_res->start + 1;
490
491 if (!request_mem_region(au1100fb_fix.mmio_start, au1100fb_fix.mmio_len,
492 DRIVER_NAME)) {
Rodolfo Giomettic05b7f32006-05-30 21:26:57 -0700493 print_err("fail to lock memory region at 0x%08lx",
Pete Popov3b495f22005-04-04 01:06:19 +0000494 au1100fb_fix.mmio_start);
495 return -EBUSY;
496 }
497
498 fbdev->regs = (struct au1100fb_regs*)KSEG1ADDR(au1100fb_fix.mmio_start);
499
500 print_dbg("Register memory map at %p", fbdev->regs);
501 print_dbg("phys=0x%08x, size=%d", fbdev->regs_phys, fbdev->regs_len);
502
503
504
505 /* Allocate the framebuffer to the maximum screen size * nbr of video buffers */
506 fbdev->fb_len = fbdev->panel->xres * fbdev->panel->yres *
507 (fbdev->panel->bpp >> 3) * AU1100FB_NBR_VIDEO_BUFFERS;
508
509 fbdev->fb_mem = dma_alloc_coherent(dev, PAGE_ALIGN(fbdev->fb_len),
510 &fbdev->fb_phys, GFP_KERNEL);
511 if (!fbdev->fb_mem) {
512 print_err("fail to allocate frambuffer (size: %dK))",
513 fbdev->fb_len / 1024);
514 return -ENOMEM;
515 }
516
517 au1100fb_fix.smem_start = fbdev->fb_phys;
518 au1100fb_fix.smem_len = fbdev->fb_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
520 /*
521 * Set page reserved so that mmap will work. This is necessary
522 * since we'll be remapping normal memory.
523 */
Pete Popov3b495f22005-04-04 01:06:19 +0000524 for (page = (unsigned long)fbdev->fb_mem;
525 page < PAGE_ALIGN((unsigned long)fbdev->fb_mem + fbdev->fb_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 page += PAGE_SIZE) {
Pete Popov3b495f22005-04-04 01:06:19 +0000527#if CONFIG_DMA_NONCOHERENT
528 SetPageReserved(virt_to_page(CAC_ADDR(page)));
529#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 SetPageReserved(virt_to_page(page));
Pete Popov3b495f22005-04-04 01:06:19 +0000531#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 }
533
Pete Popov3b495f22005-04-04 01:06:19 +0000534 print_dbg("Framebuffer memory map at %p", fbdev->fb_mem);
535 print_dbg("phys=0x%08x, size=%dK", fbdev->fb_phys, fbdev->fb_len / 1024);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
Pete Popov3b495f22005-04-04 01:06:19 +0000537 /* Setup LCD clock to AUX (48 MHz) */
538 sys_clksrc = au_readl(SYS_CLKSRC) & ~(SYS_CS_ML_MASK | SYS_CS_DL | SYS_CS_CL);
539 au_writel((sys_clksrc | (1 << SYS_CS_ML_BIT)), SYS_CLKSRC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
Pete Popov3b495f22005-04-04 01:06:19 +0000541 /* load the panel info into the var struct */
542 au1100fb_var.bits_per_pixel = fbdev->panel->bpp;
543 au1100fb_var.xres = fbdev->panel->xres;
544 au1100fb_var.xres_virtual = au1100fb_var.xres;
545 au1100fb_var.yres = fbdev->panel->yres;
546 au1100fb_var.yres_virtual = au1100fb_var.yres;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
Pete Popov3b495f22005-04-04 01:06:19 +0000548 fbdev->info.screen_base = fbdev->fb_mem;
549 fbdev->info.fbops = &au1100fb_ops;
550 fbdev->info.fix = au1100fb_fix;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
Pete Popov3b495f22005-04-04 01:06:19 +0000552 if (!(fbdev->info.pseudo_palette = kmalloc(sizeof(u32) * 16, GFP_KERNEL))) {
553 return -ENOMEM;
554 }
555 memset(fbdev->info.pseudo_palette, 0, sizeof(u32) * 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556
Pete Popov3b495f22005-04-04 01:06:19 +0000557 if (fb_alloc_cmap(&fbdev->info.cmap, AU1100_LCD_NBR_PALETTE_ENTRIES, 0) < 0) {
558 print_err("Fail to allocate colormap (%d entries)",
559 AU1100_LCD_NBR_PALETTE_ENTRIES);
560 kfree(fbdev->info.pseudo_palette);
561 return -EFAULT;
562 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563
Pete Popov3b495f22005-04-04 01:06:19 +0000564 fbdev->info.var = au1100fb_var;
565
566 /* Set h/w registers */
567 au1100fb_setmode(fbdev);
568
569 /* Register new framebuffer */
570 if (register_framebuffer(&fbdev->info) < 0) {
571 print_err("cannot register new framebuffer");
572 goto failed;
573 }
574
575 return 0;
576
577failed:
578 if (fbdev->regs) {
579 release_mem_region(fbdev->regs_phys, fbdev->regs_len);
580 }
581 if (fbdev->fb_mem) {
582 dma_free_noncoherent(dev, fbdev->fb_len, fbdev->fb_mem, fbdev->fb_phys);
583 }
584 if (fbdev->info.cmap.len != 0) {
585 fb_dealloc_cmap(&fbdev->info.cmap);
586 }
587 kfree(fbdev);
588 dev_set_drvdata(dev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
590 return 0;
591}
592
Pete Popov3b495f22005-04-04 01:06:19 +0000593int au1100fb_drv_remove(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594{
Pete Popov3b495f22005-04-04 01:06:19 +0000595 struct au1100fb_device *fbdev = NULL;
596
597 if (!dev)
598 return -ENODEV;
599
600 fbdev = (struct au1100fb_device*) dev_get_drvdata(dev);
601
602#if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
603 au1100fb_fb_blank(VESA_POWERDOWN, &fbdev->info);
604#endif
605 fbdev->regs->lcd_control &= ~LCD_CONTROL_GO;
606
607 /* Clean up all probe data */
608 unregister_framebuffer(&fbdev->info);
609
610 release_mem_region(fbdev->regs_phys, fbdev->regs_len);
611
612 dma_free_coherent(dev, PAGE_ALIGN(fbdev->fb_len), fbdev->fb_mem, fbdev->fb_phys);
613
614 fb_dealloc_cmap(&fbdev->info.cmap);
615 kfree(fbdev->info.pseudo_palette);
616 kfree((void*)fbdev);
617
618 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619}
620
Rodolfo Giomettif77f50c2006-06-26 00:26:49 -0700621#ifdef CONFIG_PM
622static u32 sys_clksrc;
623static struct au1100fb_regs fbregs;
624
Rodolfo Giomettic05b7f32006-05-30 21:26:57 -0700625int au1100fb_drv_suspend(struct device *dev, pm_message_t state)
Pete Popov3b495f22005-04-04 01:06:19 +0000626{
Rodolfo Giomettif77f50c2006-06-26 00:26:49 -0700627 struct au1100fb_device *fbdev = dev_get_drvdata(dev);
628
629 if (!fbdev)
630 return 0;
631
632 /* Save the clock source state */
633 sys_clksrc = au_readl(SYS_CLKSRC);
634
635 /* Blank the LCD */
636 au1100fb_fb_blank(VESA_POWERDOWN, &fbdev->info);
637
638 /* Stop LCD clocking */
639 au_writel(sys_clksrc & ~SYS_CS_ML_MASK, SYS_CLKSRC);
640
641 memcpy(&fbregs, fbdev->regs, sizeof(struct au1100fb_regs));
642
Pete Popov3b495f22005-04-04 01:06:19 +0000643 return 0;
644}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
Rodolfo Giomettic05b7f32006-05-30 21:26:57 -0700646int au1100fb_drv_resume(struct device *dev)
Pete Popov3b495f22005-04-04 01:06:19 +0000647{
Rodolfo Giomettif77f50c2006-06-26 00:26:49 -0700648 struct au1100fb_device *fbdev = dev_get_drvdata(dev);
649
650 if (!fbdev)
651 return 0;
652
653 memcpy(fbdev->regs, &fbregs, sizeof(struct au1100fb_regs));
654
655 /* Restart LCD clocking */
656 au_writel(sys_clksrc, SYS_CLKSRC);
657
658 /* Unblank the LCD */
659 au1100fb_fb_blank(VESA_NO_BLANKING, &fbdev->info);
660
Pete Popov3b495f22005-04-04 01:06:19 +0000661 return 0;
662}
Rodolfo Giomettif77f50c2006-06-26 00:26:49 -0700663#else
664#define au1100fb_drv_suspend NULL
665#define au1100fb_drv_resume NULL
666#endif
Pete Popov3b495f22005-04-04 01:06:19 +0000667
668static struct device_driver au1100fb_driver = {
669 .name = "au1100-lcd",
670 .bus = &platform_bus_type,
671
672 .probe = au1100fb_drv_probe,
673 .remove = au1100fb_drv_remove,
674 .suspend = au1100fb_drv_suspend,
675 .resume = au1100fb_drv_resume,
676};
677
678/*-------------------------------------------------------------------------*/
679
680/* Kernel driver */
681
682int au1100fb_setup(char *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683{
684 char* this_opt;
Pete Popov3b495f22005-04-04 01:06:19 +0000685 int num_panels = ARRAY_SIZE(known_lcd_panels);
686 char* mode = NULL;
687 int panel_idx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688
Pete Popov3b495f22005-04-04 01:06:19 +0000689 if (num_panels <= 0) {
690 print_err("No LCD panels supported by driver!");
691 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 }
Pete Popov3b495f22005-04-04 01:06:19 +0000693
694 if (options) {
695 while ((this_opt = strsep(&options,",")) != NULL) {
696 /* Panel option */
Rodolfo Giomettica27ac42006-10-03 01:14:36 -0700697 if (!strncmp(this_opt, "panel:", 6)) {
Pete Popov3b495f22005-04-04 01:06:19 +0000698 int i;
699 this_opt += 6;
700 for (i = 0; i < num_panels; i++) {
701 if (!strncmp(this_opt,
702 known_lcd_panels[i].name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 strlen(this_opt))) {
Pete Popov3b495f22005-04-04 01:06:19 +0000704 panel_idx = i;
Rodolfo Giomettica27ac42006-10-03 01:14:36 -0700705 break;
706 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 }
Pete Popov3b495f22005-04-04 01:06:19 +0000708 if (i >= num_panels) {
709 print_warn("Panel %s not supported!", this_opt);
710 }
711 }
Rodolfo Giomettica27ac42006-10-03 01:14:36 -0700712 if (!strncmp(this_opt, "nocursor", 8)) {
713 this_opt += 8;
714 nocursor = 1;
715 print_info("Cursor disabled");
716 }
Pete Popov3b495f22005-04-04 01:06:19 +0000717 /* Mode option (only option that start with digit) */
718 else if (isdigit(this_opt[0])) {
719 mode = kmalloc(strlen(this_opt) + 1, GFP_KERNEL);
720 strncpy(mode, this_opt, strlen(this_opt) + 1);
721 }
722 /* Unsupported option */
723 else {
724 print_warn("Unsupported option \"%s\"", this_opt);
Rodolfo Giomettica27ac42006-10-03 01:14:36 -0700725 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 }
727 }
728
Pete Popov3b495f22005-04-04 01:06:19 +0000729 drv_info.panel_idx = panel_idx;
730 drv_info.opt_mode = mode;
731
732 print_info("Panel=%s Mode=%s",
733 known_lcd_panels[drv_info.panel_idx].name,
734 drv_info.opt_mode ? drv_info.opt_mode : "default");
735
736 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737}
738
Pete Popov3b495f22005-04-04 01:06:19 +0000739int __init au1100fb_init(void)
740{
741 char* options;
742 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743
Pete Popov3b495f22005-04-04 01:06:19 +0000744 print_info("" DRIVER_DESC "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
Pete Popov3b495f22005-04-04 01:06:19 +0000746 memset(&drv_info, 0, sizeof(drv_info));
747
748 if (fb_get_options(DRIVER_NAME, &options))
749 return -ENODEV;
750
751 /* Setup driver with options */
752 ret = au1100fb_setup(options);
753 if (ret < 0) {
754 print_err("Fail to setup driver");
755 return ret;
756 }
757
758 return driver_register(&au1100fb_driver);
759}
760
761void __exit au1100fb_cleanup(void)
762{
763 driver_unregister(&au1100fb_driver);
764
Jesper Juhl8f760782006-06-27 02:55:06 -0700765 kfree(drv_info.opt_mode);
Pete Popov3b495f22005-04-04 01:06:19 +0000766}
767
768module_init(au1100fb_init);
769module_exit(au1100fb_cleanup);
770
771MODULE_DESCRIPTION(DRIVER_DESC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772MODULE_LICENSE("GPL");