blob: 649cb35de4ed401d2ffce0e1c5abcaeb71f4037a [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090055#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Pete Popov3b495f22005-04-04 01:06:19 +000057#include <asm/mach-au1x00/au1000.h>
58
59#define DEBUG 0
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#include "au1100fb.h"
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063/*
64 * Sanity check. If this is a new Au1100 based board, search for
65 * the PB1100 ifdefs to make sure you modify the code accordingly.
66 */
Pete Popov3b495f22005-04-04 01:06:19 +000067#if defined(CONFIG_MIPS_PB1100)
68 #include <asm/mach-pb1x00/pb1100.h>
69#elif defined(CONFIG_MIPS_DB1100)
70 #include <asm/mach-db1x00/db1x00.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070071#else
Pete Popov3b495f22005-04-04 01:06:19 +000072 #error "Unknown Au1100 board, Au1100 FB driver not supported"
Linus Torvalds1da177e2005-04-16 15:20:36 -070073#endif
74
Pete Popov3b495f22005-04-04 01:06:19 +000075#define DRIVER_NAME "au1100fb"
76#define DRIVER_DESC "LCD controller driver for AU1100 processors"
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Pete Popov3b495f22005-04-04 01:06:19 +000078#define to_au1100fb_device(_info) \
79 (_info ? container_of(_info, struct au1100fb_device, info) : NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Pete Popov3b495f22005-04-04 01:06:19 +000081/* Bitfields format supported by the controller. Note that the order of formats
82 * SHOULD be the same as in the LCD_CONTROL_SBPPF field, so we can retrieve the
83 * right pixel format by doing rgb_bitfields[LCD_CONTROL_SBPPF_XXX >> LCD_CONTROL_SBPPF]
84 */
85struct fb_bitfield rgb_bitfields[][4] =
Linus Torvalds1da177e2005-04-16 15:20:36 -070086{
Pete Popov3b495f22005-04-04 01:06:19 +000087 /* Red, Green, Blue, Transp */
88 { { 10, 6, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
89 { { 11, 5, 0 }, { 5, 6, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
90 { { 11, 5, 0 }, { 6, 5, 0 }, { 0, 6, 0 }, { 0, 0, 0 } },
91 { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 15, 1, 0 } },
92 { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 1, 0 } },
93
94 /* The last is used to describe 12bpp format */
95 { { 8, 4, 0 }, { 4, 4, 0 }, { 0, 4, 0 }, { 0, 0, 0 } },
96};
97
Ralf Baechle362992b2010-07-26 19:08:15 +010098static struct fb_fix_screeninfo au1100fb_fix __devinitdata = {
Pete Popov3b495f22005-04-04 01:06:19 +000099 .id = "AU1100 FB",
100 .xpanstep = 1,
101 .ypanstep = 1,
102 .type = FB_TYPE_PACKED_PIXELS,
103 .accel = FB_ACCEL_NONE,
104};
105
Ralf Baechle362992b2010-07-26 19:08:15 +0100106static struct fb_var_screeninfo au1100fb_var __devinitdata = {
Pete Popov3b495f22005-04-04 01:06:19 +0000107 .activate = FB_ACTIVATE_NOW,
108 .height = -1,
109 .width = -1,
110 .vmode = FB_VMODE_NONINTERLACED,
111};
112
Yoichi Yuasa8e92f212007-08-22 14:02:03 -0700113/* fb_blank
114 * Blank the screen. Depending on the mode, the screen will be
115 * activated with the backlight color, or desactivated
116 */
117static int au1100fb_fb_blank(int blank_mode, struct fb_info *fbi)
118{
119 struct au1100fb_device *fbdev = to_au1100fb_device(fbi);
120
121 print_dbg("fb_blank %d %p", blank_mode, fbi);
122
123 switch (blank_mode) {
124
125 case VESA_NO_BLANKING:
126 /* Turn on panel */
127 fbdev->regs->lcd_control |= LCD_CONTROL_GO;
128#ifdef CONFIG_MIPS_PB1100
Manuel Laussd121c3f2011-09-30 20:49:43 +0200129 if (fbdev->panel_idx == 1) {
Yoichi Yuasa8e92f212007-08-22 14:02:03 -0700130 au_writew(au_readw(PB1100_G_CONTROL)
131 | (PB1100_G_CONTROL_BL | PB1100_G_CONTROL_VDD),
132 PB1100_G_CONTROL);
133 }
134#endif
135 au_sync();
136 break;
137
138 case VESA_VSYNC_SUSPEND:
139 case VESA_HSYNC_SUSPEND:
140 case VESA_POWERDOWN:
141 /* Turn off panel */
142 fbdev->regs->lcd_control &= ~LCD_CONTROL_GO;
143#ifdef CONFIG_MIPS_PB1100
Manuel Laussd121c3f2011-09-30 20:49:43 +0200144 if (fbdev->panel_idx == 1) {
Yoichi Yuasa8e92f212007-08-22 14:02:03 -0700145 au_writew(au_readw(PB1100_G_CONTROL)
146 & ~(PB1100_G_CONTROL_BL | PB1100_G_CONTROL_VDD),
147 PB1100_G_CONTROL);
148 }
149#endif
150 au_sync();
151 break;
152 default:
153 break;
154
155 }
156 return 0;
157}
158
Pete Popov3b495f22005-04-04 01:06:19 +0000159/*
160 * Set hardware with var settings. This will enable the controller with a specific
161 * mode, normally validated with the fb_check_var method
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 */
Pete Popov3b495f22005-04-04 01:06:19 +0000163int au1100fb_setmode(struct au1100fb_device *fbdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164{
Pete Popov3b495f22005-04-04 01:06:19 +0000165 struct fb_info *info = &fbdev->info;
166 u32 words;
167 int index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
Pete Popov3b495f22005-04-04 01:06:19 +0000169 if (!fbdev)
170 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
Pete Popov3b495f22005-04-04 01:06:19 +0000172 /* Update var-dependent FB info */
173 if (panel_is_active(fbdev->panel) || panel_is_color(fbdev->panel)) {
174 if (info->var.bits_per_pixel <= 8) {
175 /* palettized */
176 info->var.red.offset = 0;
177 info->var.red.length = info->var.bits_per_pixel;
178 info->var.red.msb_right = 0;
179
180 info->var.green.offset = 0;
181 info->var.green.length = info->var.bits_per_pixel;
182 info->var.green.msb_right = 0;
183
184 info->var.blue.offset = 0;
185 info->var.blue.length = info->var.bits_per_pixel;
186 info->var.blue.msb_right = 0;
187
188 info->var.transp.offset = 0;
189 info->var.transp.length = 0;
190 info->var.transp.msb_right = 0;
191
192 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
193 info->fix.line_length = info->var.xres_virtual /
194 (8/info->var.bits_per_pixel);
195 } else {
196 /* non-palettized */
197 index = (fbdev->panel->control_base & LCD_CONTROL_SBPPF_MASK) >> LCD_CONTROL_SBPPF_BIT;
198 info->var.red = rgb_bitfields[index][0];
199 info->var.green = rgb_bitfields[index][1];
200 info->var.blue = rgb_bitfields[index][2];
201 info->var.transp = rgb_bitfields[index][3];
202
203 info->fix.visual = FB_VISUAL_TRUECOLOR;
204 info->fix.line_length = info->var.xres_virtual << 1; /* depth=16 */
Rodolfo Giomettibb39e412006-08-05 12:14:22 -0700205 }
Pete Popov3b495f22005-04-04 01:06:19 +0000206 } else {
207 /* mono */
208 info->fix.visual = FB_VISUAL_MONO10;
209 info->fix.line_length = info->var.xres_virtual / 8;
210 }
211
212 info->screen_size = info->fix.line_length * info->var.yres_virtual;
Rodolfo Giomettifd2d5432006-08-05 12:14:19 -0700213 info->var.rotate = ((fbdev->panel->control_base&LCD_CONTROL_SM_MASK) \
214 >> LCD_CONTROL_SM_BIT) * 90;
Pete Popov3b495f22005-04-04 01:06:19 +0000215
216 /* Determine BPP mode and format */
Rodolfo Giomettifd2d5432006-08-05 12:14:19 -0700217 fbdev->regs->lcd_control = fbdev->panel->control_base;
Rodolfo Giomettibb39e412006-08-05 12:14:22 -0700218 fbdev->regs->lcd_horztiming = fbdev->panel->horztiming;
219 fbdev->regs->lcd_verttiming = fbdev->panel->verttiming;
220 fbdev->regs->lcd_clkcontrol = fbdev->panel->clkcontrol_base;
Pete Popov3b495f22005-04-04 01:06:19 +0000221 fbdev->regs->lcd_intenable = 0;
222 fbdev->regs->lcd_intstatus = 0;
Pete Popov3b495f22005-04-04 01:06:19 +0000223 fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(fbdev->fb_phys);
224
225 if (panel_is_dual(fbdev->panel)) {
226 /* Second panel display seconf half of screen if possible,
227 * otherwise display the same as the first panel */
228 if (info->var.yres_virtual >= (info->var.yres << 1)) {
229 fbdev->regs->lcd_dmaaddr1 = LCD_DMA_SA_N(fbdev->fb_phys +
230 (info->fix.line_length *
231 (info->var.yres_virtual >> 1)));
232 } else {
233 fbdev->regs->lcd_dmaaddr1 = LCD_DMA_SA_N(fbdev->fb_phys);
234 }
235 }
236
237 words = info->fix.line_length / sizeof(u32);
238 if (!info->var.rotate || (info->var.rotate == 180)) {
239 words *= info->var.yres_virtual;
240 if (info->var.rotate /* 180 */) {
241 words -= (words % 8); /* should be divisable by 8 */
242 }
243 }
244 fbdev->regs->lcd_words = LCD_WRD_WRDS_N(words);
245
246 fbdev->regs->lcd_pwmdiv = 0;
247 fbdev->regs->lcd_pwmhi = 0;
248
249 /* Resume controller */
250 fbdev->regs->lcd_control |= LCD_CONTROL_GO;
Rodolfo Giomettibb39e412006-08-05 12:14:22 -0700251 mdelay(10);
252 au1100fb_fb_blank(VESA_NO_BLANKING, info);
Pete Popov3b495f22005-04-04 01:06:19 +0000253
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 return 0;
255}
256
Pete Popov3b495f22005-04-04 01:06:19 +0000257/* fb_setcolreg
258 * Set color in LCD palette.
259 */
260int au1100fb_fb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue, unsigned transp, struct fb_info *fbi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261{
Rodolfo Giomettic05b7f32006-05-30 21:26:57 -0700262 struct au1100fb_device *fbdev;
263 u32 *palette;
Pete Popov3b495f22005-04-04 01:06:19 +0000264 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
Rodolfo Giomettic05b7f32006-05-30 21:26:57 -0700266 fbdev = to_au1100fb_device(fbi);
267 palette = fbdev->regs->lcd_pallettebase;
268
Pete Popov3b495f22005-04-04 01:06:19 +0000269 if (regno > (AU1100_LCD_NBR_PALETTE_ENTRIES - 1))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 return -EINVAL;
Pete Popov3b495f22005-04-04 01:06:19 +0000271
272 if (fbi->var.grayscale) {
273 /* Convert color to grayscale */
274 red = green = blue =
275 (19595 * red + 38470 * green + 7471 * blue) >> 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 }
277
Pete Popov3b495f22005-04-04 01:06:19 +0000278 if (fbi->fix.visual == FB_VISUAL_TRUECOLOR) {
279 /* Place color in the pseudopalette */
280 if (regno > 16)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 return -EINVAL;
282
Pete Popov3b495f22005-04-04 01:06:19 +0000283 palette = (u32*)fbi->pseudo_palette;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
Pete Popov3b495f22005-04-04 01:06:19 +0000285 red >>= (16 - fbi->var.red.length);
286 green >>= (16 - fbi->var.green.length);
287 blue >>= (16 - fbi->var.blue.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
Pete Popov3b495f22005-04-04 01:06:19 +0000289 value = (red << fbi->var.red.offset) |
290 (green << fbi->var.green.offset)|
291 (blue << fbi->var.blue.offset);
292 value &= 0xFFFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
Pete Popov3b495f22005-04-04 01:06:19 +0000294 } else if (panel_is_active(fbdev->panel)) {
295 /* COLOR TFT PALLETTIZED (use RGB 565) */
296 value = (red & 0xF800)|((green >> 5) & 0x07E0)|((blue >> 11) & 0x001F);
297 value &= 0xFFFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
Pete Popov3b495f22005-04-04 01:06:19 +0000299 } else if (panel_is_color(fbdev->panel)) {
300 /* COLOR STN MODE */
301 value = (((panel_swap_rgb(fbdev->panel) ? blue : red) >> 12) & 0x000F) |
302 ((green >> 8) & 0x00F0) |
303 (((panel_swap_rgb(fbdev->panel) ? red : blue) >> 4) & 0x0F00);
304 value &= 0xFFF;
305 } else {
306 /* MONOCHROME MODE */
307 value = (green >> 12) & 0x000F;
308 value &= 0xF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 }
310
Pete Popov3b495f22005-04-04 01:06:19 +0000311 palette[regno] = value;
312
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 return 0;
314}
315
Pete Popov3b495f22005-04-04 01:06:19 +0000316/* fb_pan_display
317 * Pan display in x and/or y as specified
318 */
319int au1100fb_fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *fbi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320{
Rodolfo Giomettic05b7f32006-05-30 21:26:57 -0700321 struct au1100fb_device *fbdev;
Pete Popov3b495f22005-04-04 01:06:19 +0000322 int dy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
Rodolfo Giomettic05b7f32006-05-30 21:26:57 -0700324 fbdev = to_au1100fb_device(fbi);
325
Pete Popov3b495f22005-04-04 01:06:19 +0000326 print_dbg("fb_pan_display %p %p", var, fbi);
327
328 if (!var || !fbdev) {
329 return -EINVAL;
330 }
331
332 if (var->xoffset - fbi->var.xoffset) {
333 /* No support for X panning for now! */
334 return -EINVAL;
335 }
336
337 print_dbg("fb_pan_display 2 %p %p", var, fbi);
338 dy = var->yoffset - fbi->var.yoffset;
339 if (dy) {
340
341 u32 dmaaddr;
342
343 print_dbg("Panning screen of %d lines", dy);
344
345 dmaaddr = fbdev->regs->lcd_dmaaddr0;
346 dmaaddr += (fbi->fix.line_length * dy);
347
348 /* TODO: Wait for current frame to finished */
349 fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(dmaaddr);
350
351 if (panel_is_dual(fbdev->panel)) {
352 dmaaddr = fbdev->regs->lcd_dmaaddr1;
353 dmaaddr += (fbi->fix.line_length * dy);
354 fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(dmaaddr);
355 }
356 }
357 print_dbg("fb_pan_display 3 %p %p", var, fbi);
358
359 return 0;
360}
361
362/* fb_rotate
363 * Rotate the display of this angle. This doesn't seems to be used by the core,
364 * but as our hardware supports it, so why not implementing it...
365 */
366void au1100fb_fb_rotate(struct fb_info *fbi, int angle)
367{
368 struct au1100fb_device *fbdev = to_au1100fb_device(fbi);
369
370 print_dbg("fb_rotate %p %d", fbi, angle);
371
372 if (fbdev && (angle > 0) && !(angle % 90)) {
373
374 fbdev->regs->lcd_control &= ~LCD_CONTROL_GO;
375
376 fbdev->regs->lcd_control &= ~(LCD_CONTROL_SM_MASK);
377 fbdev->regs->lcd_control |= ((angle/90) << LCD_CONTROL_SM_BIT);
378
379 fbdev->regs->lcd_control |= LCD_CONTROL_GO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 }
381}
382
Pete Popov3b495f22005-04-04 01:06:19 +0000383/* fb_mmap
384 * Map video memory in user space. We don't use the generic fb_mmap method mainly
385 * to allow the use of the TLB streaming flag (CCA=6)
386 */
Christoph Hellwig216d5262006-01-14 13:21:25 -0800387int au1100fb_fb_mmap(struct fb_info *fbi, struct vm_area_struct *vma)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388{
Rodolfo Giomettic05b7f32006-05-30 21:26:57 -0700389 struct au1100fb_device *fbdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 unsigned int len;
391 unsigned long start=0, off;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
Rodolfo Giomettic05b7f32006-05-30 21:26:57 -0700393 fbdev = to_au1100fb_device(fbi);
394
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) {
396 return -EINVAL;
397 }
398
Pete Popov3b495f22005-04-04 01:06:19 +0000399 start = fbdev->fb_phys & PAGE_MASK;
400 len = PAGE_ALIGN((start & ~PAGE_MASK) + fbdev->fb_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
402 off = vma->vm_pgoff << PAGE_SHIFT;
403
404 if ((vma->vm_end - vma->vm_start + off) > len) {
405 return -EINVAL;
406 }
407
408 off += start;
409 vma->vm_pgoff = off >> PAGE_SHIFT;
410
Pete Popov3b495f22005-04-04 01:06:19 +0000411 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 pgprot_val(vma->vm_page_prot) |= (6 << 9); //CCA=6
413
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 vma->vm_flags |= VM_IO;
415
Freddy Spierenburgcacfc8c2006-02-24 13:04:17 -0800416 if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 vma->vm_end - vma->vm_start,
418 vma->vm_page_prot)) {
419 return -EAGAIN;
420 }
421
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 return 0;
423}
424
Pete Popov3b495f22005-04-04 01:06:19 +0000425static struct fb_ops au1100fb_ops =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426{
Pete Popov3b495f22005-04-04 01:06:19 +0000427 .owner = THIS_MODULE,
428 .fb_setcolreg = au1100fb_fb_setcolreg,
429 .fb_blank = au1100fb_fb_blank,
430 .fb_pan_display = au1100fb_fb_pan_display,
431 .fb_fillrect = cfb_fillrect,
432 .fb_copyarea = cfb_copyarea,
433 .fb_imageblit = cfb_imageblit,
434 .fb_rotate = au1100fb_fb_rotate,
435 .fb_mmap = au1100fb_fb_mmap,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436};
437
438
Pete Popov3b495f22005-04-04 01:06:19 +0000439/*-------------------------------------------------------------------------*/
440
Manuel Laussd121c3f2011-09-30 20:49:43 +0200441static int au1100fb_setup(struct au1100fb_device *fbdev)
442{
443 char *this_opt, *options;
444 int num_panels = ARRAY_SIZE(known_lcd_panels);
445
446 if (num_panels <= 0) {
447 print_err("No LCD panels supported by driver!");
448 return -ENODEV;
449 }
450
451 if (fb_get_options(DRIVER_NAME, &options))
452 return -ENODEV;
453 if (!options)
454 return -ENODEV;
455
456 while ((this_opt = strsep(&options, ",")) != NULL) {
457 /* Panel option */
458 if (!strncmp(this_opt, "panel:", 6)) {
459 int i;
460 this_opt += 6;
461 for (i = 0; i < num_panels; i++) {
462 if (!strncmp(this_opt, known_lcd_panels[i].name,
463 strlen(this_opt))) {
464 fbdev->panel = &known_lcd_panels[i];
465 fbdev->panel_idx = i;
466 break;
467 }
468 }
469 if (i >= num_panels) {
470 print_warn("Panel '%s' not supported!", this_opt);
471 return -ENODEV;
472 }
473 }
474 /* Unsupported option */
475 else
476 print_warn("Unsupported option \"%s\"", this_opt);
477 }
478
479 print_info("Panel=%s", fbdev->panel->name);
480
481 return 0;
482}
Pete Popov3b495f22005-04-04 01:06:19 +0000483
Ralf Baechle362992b2010-07-26 19:08:15 +0100484static int __devinit au1100fb_drv_probe(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485{
Pete Popov3b495f22005-04-04 01:06:19 +0000486 struct au1100fb_device *fbdev = NULL;
487 struct resource *regs_res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 unsigned long page;
Pete Popov3b495f22005-04-04 01:06:19 +0000489 u32 sys_clksrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Pete Popov3b495f22005-04-04 01:06:19 +0000491 /* Allocate new device private */
Manuel Laussd121c3f2011-09-30 20:49:43 +0200492 fbdev = kzalloc(sizeof(struct au1100fb_device), GFP_KERNEL);
493 if (!fbdev) {
Pete Popov3b495f22005-04-04 01:06:19 +0000494 print_err("fail to allocate device private record");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 return -ENOMEM;
496 }
Pete Popov3b495f22005-04-04 01:06:19 +0000497
Manuel Laussd121c3f2011-09-30 20:49:43 +0200498 if (au1100fb_setup(fbdev))
499 goto failed;
Pete Popov3b495f22005-04-04 01:06:19 +0000500
Ming Lei7a192ec2009-02-06 23:40:12 +0800501 platform_set_drvdata(dev, (void *)fbdev);
Pete Popov3b495f22005-04-04 01:06:19 +0000502
503 /* Allocate region for our registers and map them */
Manuel Laussd121c3f2011-09-30 20:49:43 +0200504 regs_res = platform_get_resource(dev, IORESOURCE_MEM, 0);
505 if (!regs_res) {
Pete Popov3b495f22005-04-04 01:06:19 +0000506 print_err("fail to retrieve registers resource");
507 return -EFAULT;
508 }
509
510 au1100fb_fix.mmio_start = regs_res->start;
Joe Perches28f65c112011-06-09 09:13:32 -0700511 au1100fb_fix.mmio_len = resource_size(regs_res);
Pete Popov3b495f22005-04-04 01:06:19 +0000512
513 if (!request_mem_region(au1100fb_fix.mmio_start, au1100fb_fix.mmio_len,
514 DRIVER_NAME)) {
Rodolfo Giomettic05b7f32006-05-30 21:26:57 -0700515 print_err("fail to lock memory region at 0x%08lx",
Pete Popov3b495f22005-04-04 01:06:19 +0000516 au1100fb_fix.mmio_start);
517 return -EBUSY;
518 }
519
520 fbdev->regs = (struct au1100fb_regs*)KSEG1ADDR(au1100fb_fix.mmio_start);
521
522 print_dbg("Register memory map at %p", fbdev->regs);
523 print_dbg("phys=0x%08x, size=%d", fbdev->regs_phys, fbdev->regs_len);
524
Pete Popov3b495f22005-04-04 01:06:19 +0000525 /* Allocate the framebuffer to the maximum screen size * nbr of video buffers */
526 fbdev->fb_len = fbdev->panel->xres * fbdev->panel->yres *
527 (fbdev->panel->bpp >> 3) * AU1100FB_NBR_VIDEO_BUFFERS;
528
Manuel Laussd121c3f2011-09-30 20:49:43 +0200529 fbdev->fb_mem = dma_alloc_coherent(&dev->dev, PAGE_ALIGN(fbdev->fb_len),
Pete Popov3b495f22005-04-04 01:06:19 +0000530 &fbdev->fb_phys, GFP_KERNEL);
531 if (!fbdev->fb_mem) {
532 print_err("fail to allocate frambuffer (size: %dK))",
533 fbdev->fb_len / 1024);
534 return -ENOMEM;
535 }
536
537 au1100fb_fix.smem_start = fbdev->fb_phys;
538 au1100fb_fix.smem_len = fbdev->fb_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
540 /*
541 * Set page reserved so that mmap will work. This is necessary
542 * since we'll be remapping normal memory.
543 */
Pete Popov3b495f22005-04-04 01:06:19 +0000544 for (page = (unsigned long)fbdev->fb_mem;
545 page < PAGE_ALIGN((unsigned long)fbdev->fb_mem + fbdev->fb_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 page += PAGE_SIZE) {
Pete Popov3b495f22005-04-04 01:06:19 +0000547#if CONFIG_DMA_NONCOHERENT
Manuel Laussd121c3f2011-09-30 20:49:43 +0200548 SetPageReserved(virt_to_page(CAC_ADDR((void *)page)));
Pete Popov3b495f22005-04-04 01:06:19 +0000549#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 SetPageReserved(virt_to_page(page));
Pete Popov3b495f22005-04-04 01:06:19 +0000551#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 }
553
Pete Popov3b495f22005-04-04 01:06:19 +0000554 print_dbg("Framebuffer memory map at %p", fbdev->fb_mem);
555 print_dbg("phys=0x%08x, size=%dK", fbdev->fb_phys, fbdev->fb_len / 1024);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556
Pete Popov3b495f22005-04-04 01:06:19 +0000557 /* Setup LCD clock to AUX (48 MHz) */
558 sys_clksrc = au_readl(SYS_CLKSRC) & ~(SYS_CS_ML_MASK | SYS_CS_DL | SYS_CS_CL);
559 au_writel((sys_clksrc | (1 << SYS_CS_ML_BIT)), SYS_CLKSRC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
Pete Popov3b495f22005-04-04 01:06:19 +0000561 /* load the panel info into the var struct */
562 au1100fb_var.bits_per_pixel = fbdev->panel->bpp;
563 au1100fb_var.xres = fbdev->panel->xres;
564 au1100fb_var.xres_virtual = au1100fb_var.xres;
565 au1100fb_var.yres = fbdev->panel->yres;
566 au1100fb_var.yres_virtual = au1100fb_var.yres;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
Pete Popov3b495f22005-04-04 01:06:19 +0000568 fbdev->info.screen_base = fbdev->fb_mem;
569 fbdev->info.fbops = &au1100fb_ops;
570 fbdev->info.fix = au1100fb_fix;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571
Jiri Slabyf5610b92007-02-12 00:55:12 -0800572 if (!(fbdev->info.pseudo_palette = kzalloc(sizeof(u32) * 16, GFP_KERNEL))) {
Pete Popov3b495f22005-04-04 01:06:19 +0000573 return -ENOMEM;
574 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575
Pete Popov3b495f22005-04-04 01:06:19 +0000576 if (fb_alloc_cmap(&fbdev->info.cmap, AU1100_LCD_NBR_PALETTE_ENTRIES, 0) < 0) {
577 print_err("Fail to allocate colormap (%d entries)",
578 AU1100_LCD_NBR_PALETTE_ENTRIES);
579 kfree(fbdev->info.pseudo_palette);
580 return -EFAULT;
581 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
Pete Popov3b495f22005-04-04 01:06:19 +0000583 fbdev->info.var = au1100fb_var;
584
585 /* Set h/w registers */
586 au1100fb_setmode(fbdev);
587
588 /* Register new framebuffer */
589 if (register_framebuffer(&fbdev->info) < 0) {
590 print_err("cannot register new framebuffer");
591 goto failed;
592 }
593
594 return 0;
595
596failed:
597 if (fbdev->regs) {
598 release_mem_region(fbdev->regs_phys, fbdev->regs_len);
599 }
600 if (fbdev->fb_mem) {
Manuel Laussd121c3f2011-09-30 20:49:43 +0200601 dma_free_noncoherent(&dev->dev, fbdev->fb_len, fbdev->fb_mem,
602 fbdev->fb_phys);
Pete Popov3b495f22005-04-04 01:06:19 +0000603 }
604 if (fbdev->info.cmap.len != 0) {
605 fb_dealloc_cmap(&fbdev->info.cmap);
606 }
607 kfree(fbdev);
Ming Lei7a192ec2009-02-06 23:40:12 +0800608 platform_set_drvdata(dev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
610 return 0;
611}
612
Ming Lei7a192ec2009-02-06 23:40:12 +0800613int au1100fb_drv_remove(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614{
Pete Popov3b495f22005-04-04 01:06:19 +0000615 struct au1100fb_device *fbdev = NULL;
616
617 if (!dev)
618 return -ENODEV;
619
Ming Lei7a192ec2009-02-06 23:40:12 +0800620 fbdev = (struct au1100fb_device *) platform_get_drvdata(dev);
Pete Popov3b495f22005-04-04 01:06:19 +0000621
622#if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
623 au1100fb_fb_blank(VESA_POWERDOWN, &fbdev->info);
624#endif
625 fbdev->regs->lcd_control &= ~LCD_CONTROL_GO;
626
627 /* Clean up all probe data */
628 unregister_framebuffer(&fbdev->info);
629
630 release_mem_region(fbdev->regs_phys, fbdev->regs_len);
631
Manuel Laussd121c3f2011-09-30 20:49:43 +0200632 dma_free_coherent(&dev->dev, PAGE_ALIGN(fbdev->fb_len), fbdev->fb_mem,
633 fbdev->fb_phys);
Pete Popov3b495f22005-04-04 01:06:19 +0000634
635 fb_dealloc_cmap(&fbdev->info.cmap);
636 kfree(fbdev->info.pseudo_palette);
637 kfree((void*)fbdev);
638
639 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640}
641
Rodolfo Giomettif77f50c2006-06-26 00:26:49 -0700642#ifdef CONFIG_PM
643static u32 sys_clksrc;
644static struct au1100fb_regs fbregs;
645
Ming Lei7a192ec2009-02-06 23:40:12 +0800646int au1100fb_drv_suspend(struct platform_device *dev, pm_message_t state)
Pete Popov3b495f22005-04-04 01:06:19 +0000647{
Ming Lei7a192ec2009-02-06 23:40:12 +0800648 struct au1100fb_device *fbdev = platform_get_drvdata(dev);
Rodolfo Giomettif77f50c2006-06-26 00:26:49 -0700649
650 if (!fbdev)
651 return 0;
652
653 /* Save the clock source state */
654 sys_clksrc = au_readl(SYS_CLKSRC);
655
656 /* Blank the LCD */
657 au1100fb_fb_blank(VESA_POWERDOWN, &fbdev->info);
658
659 /* Stop LCD clocking */
660 au_writel(sys_clksrc & ~SYS_CS_ML_MASK, SYS_CLKSRC);
661
662 memcpy(&fbregs, fbdev->regs, sizeof(struct au1100fb_regs));
663
Pete Popov3b495f22005-04-04 01:06:19 +0000664 return 0;
665}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666
Ming Lei7a192ec2009-02-06 23:40:12 +0800667int au1100fb_drv_resume(struct platform_device *dev)
Pete Popov3b495f22005-04-04 01:06:19 +0000668{
Ming Lei7a192ec2009-02-06 23:40:12 +0800669 struct au1100fb_device *fbdev = platform_get_drvdata(dev);
Rodolfo Giomettif77f50c2006-06-26 00:26:49 -0700670
671 if (!fbdev)
672 return 0;
673
674 memcpy(fbdev->regs, &fbregs, sizeof(struct au1100fb_regs));
675
676 /* Restart LCD clocking */
677 au_writel(sys_clksrc, SYS_CLKSRC);
678
679 /* Unblank the LCD */
680 au1100fb_fb_blank(VESA_NO_BLANKING, &fbdev->info);
681
Pete Popov3b495f22005-04-04 01:06:19 +0000682 return 0;
683}
Rodolfo Giomettif77f50c2006-06-26 00:26:49 -0700684#else
685#define au1100fb_drv_suspend NULL
686#define au1100fb_drv_resume NULL
687#endif
Pete Popov3b495f22005-04-04 01:06:19 +0000688
Ming Lei7a192ec2009-02-06 23:40:12 +0800689static struct platform_driver au1100fb_driver = {
690 .driver = {
691 .name = "au1100-lcd",
692 .owner = THIS_MODULE,
693 },
Pete Popov3b495f22005-04-04 01:06:19 +0000694 .probe = au1100fb_drv_probe,
695 .remove = au1100fb_drv_remove,
696 .suspend = au1100fb_drv_suspend,
697 .resume = au1100fb_drv_resume,
698};
699
Manuel Laussd121c3f2011-09-30 20:49:43 +0200700static int __init au1100fb_load(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701{
Ming Lei7a192ec2009-02-06 23:40:12 +0800702 return platform_driver_register(&au1100fb_driver);
Pete Popov3b495f22005-04-04 01:06:19 +0000703}
704
Manuel Laussd121c3f2011-09-30 20:49:43 +0200705static void __exit au1100fb_unload(void)
Pete Popov3b495f22005-04-04 01:06:19 +0000706{
Ming Lei7a192ec2009-02-06 23:40:12 +0800707 platform_driver_unregister(&au1100fb_driver);
Pete Popov3b495f22005-04-04 01:06:19 +0000708}
709
Manuel Laussd121c3f2011-09-30 20:49:43 +0200710module_init(au1100fb_load);
711module_exit(au1100fb_unload);
Pete Popov3b495f22005-04-04 01:06:19 +0000712
713MODULE_DESCRIPTION(DRIVER_DESC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714MODULE_LICENSE("GPL");