Merge tag 'pm-6.16-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
[linux-2.6-block.git] / drivers / video / fbdev / au1100fb.c
CommitLineData
1da177e4
LT
1/*
2 * BRIEF MODULE DESCRIPTION
3 * Au1100 LCD Driver.
4 *
3b495f2b
PP
5 * Rewritten for 2.6 by Embedded Alley Solutions
6 * <source@embeddedalley.com>, based on submissions by
7 * Karl Lessard <klessard@sunrisetelecom.com>
8 * <c.pellegrin@exadron.com>
9 *
f77f50ca 10 * PM support added by Rodolfo Giometti <giometti@linux.it>
ca27ac4c 11 * Cursor enable/disable by Rodolfo Giometti <giometti@linux.it>
f77f50ca 12 *
1da177e4
LT
13 * 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 */
6b1889c1 44#include <linux/clk.h>
1da177e4
LT
45#include <linux/module.h>
46#include <linux/kernel.h>
47#include <linux/errno.h>
48#include <linux/string.h>
49#include <linux/mm.h>
1da177e4
LT
50#include <linux/fb.h>
51#include <linux/init.h>
3b495f2b
PP
52#include <linux/interrupt.h>
53#include <linux/ctype.h>
54#include <linux/dma-mapping.h>
cacfc8cf 55#include <linux/platform_device.h>
5a0e3ad6 56#include <linux/slab.h>
1da177e4 57
3b495f2b 58#include <asm/mach-au1x00/au1000.h>
1da177e4 59
3b495f2b
PP
60#define DEBUG 0
61
62#include "au1100fb.h"
1da177e4 63
3b495f2b
PP
64#define DRIVER_NAME "au1100fb"
65#define DRIVER_DESC "LCD controller driver for AU1100 processors"
1da177e4 66
3b495f2b
PP
67#define to_au1100fb_device(_info) \
68 (_info ? container_of(_info, struct au1100fb_device, info) : NULL);
1da177e4 69
3b495f2b
PP
70/* Bitfields format supported by the controller. Note that the order of formats
71 * SHOULD be the same as in the LCD_CONTROL_SBPPF field, so we can retrieve the
72 * right pixel format by doing rgb_bitfields[LCD_CONTROL_SBPPF_XXX >> LCD_CONTROL_SBPPF]
73 */
74struct fb_bitfield rgb_bitfields[][4] =
75{
76 /* Red, Green, Blue, Transp */
77 { { 10, 6, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
78 { { 11, 5, 0 }, { 5, 6, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
79 { { 11, 5, 0 }, { 6, 5, 0 }, { 0, 6, 0 }, { 0, 0, 0 } },
80 { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 15, 1, 0 } },
81 { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 1, 0 } },
82
83 /* The last is used to describe 12bpp format */
84 { { 8, 4, 0 }, { 4, 4, 0 }, { 0, 4, 0 }, { 0, 0, 0 } },
1da177e4
LT
85};
86
48c68c4f 87static struct fb_fix_screeninfo au1100fb_fix = {
3b495f2b
PP
88 .id = "AU1100 FB",
89 .xpanstep = 1,
90 .ypanstep = 1,
91 .type = FB_TYPE_PACKED_PIXELS,
92 .accel = FB_ACCEL_NONE,
1da177e4
LT
93};
94
48c68c4f 95static struct fb_var_screeninfo au1100fb_var = {
3b495f2b
PP
96 .activate = FB_ACTIVATE_NOW,
97 .height = -1,
98 .width = -1,
99 .vmode = FB_VMODE_NONINTERLACED,
1da177e4
LT
100};
101
8e92f21b
YY
102/* fb_blank
103 * Blank the screen. Depending on the mode, the screen will be
104 * activated with the backlight color, or desactivated
105 */
106static int au1100fb_fb_blank(int blank_mode, struct fb_info *fbi)
107{
108 struct au1100fb_device *fbdev = to_au1100fb_device(fbi);
109
110 print_dbg("fb_blank %d %p", blank_mode, fbi);
111
112 switch (blank_mode) {
113
114 case VESA_NO_BLANKING:
88564dda
PB
115 /* Turn on panel */
116 fbdev->regs->lcd_control |= LCD_CONTROL_GO;
2f73bfbe 117 wmb(); /* drain writebuffer */
8e92f21b
YY
118 break;
119
120 case VESA_VSYNC_SUSPEND:
121 case VESA_HSYNC_SUSPEND:
122 case VESA_POWERDOWN:
88564dda
PB
123 /* Turn off panel */
124 fbdev->regs->lcd_control &= ~LCD_CONTROL_GO;
2f73bfbe 125 wmb(); /* drain writebuffer */
8e92f21b
YY
126 break;
127 default:
128 break;
129
130 }
131 return 0;
132}
133
3b495f2b
PP
134/*
135 * Set hardware with var settings. This will enable the controller with a specific
136 * mode, normally validated with the fb_check_var method
1da177e4 137 */
3b495f2b 138int au1100fb_setmode(struct au1100fb_device *fbdev)
1da177e4 139{
2df2c0ca 140 struct fb_info *info;
3b495f2b
PP
141 u32 words;
142 int index;
1da177e4 143
3b495f2b
PP
144 if (!fbdev)
145 return -EINVAL;
146
2df2c0ca
ME
147 info = &fbdev->info;
148
3b495f2b
PP
149 /* Update var-dependent FB info */
150 if (panel_is_active(fbdev->panel) || panel_is_color(fbdev->panel)) {
151 if (info->var.bits_per_pixel <= 8) {
152 /* palettized */
153 info->var.red.offset = 0;
154 info->var.red.length = info->var.bits_per_pixel;
155 info->var.red.msb_right = 0;
156
157 info->var.green.offset = 0;
158 info->var.green.length = info->var.bits_per_pixel;
159 info->var.green.msb_right = 0;
160
161 info->var.blue.offset = 0;
162 info->var.blue.length = info->var.bits_per_pixel;
163 info->var.blue.msb_right = 0;
164
165 info->var.transp.offset = 0;
166 info->var.transp.length = 0;
167 info->var.transp.msb_right = 0;
168
169 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
170 info->fix.line_length = info->var.xres_virtual /
171 (8/info->var.bits_per_pixel);
172 } else {
173 /* non-palettized */
174 index = (fbdev->panel->control_base & LCD_CONTROL_SBPPF_MASK) >> LCD_CONTROL_SBPPF_BIT;
175 info->var.red = rgb_bitfields[index][0];
176 info->var.green = rgb_bitfields[index][1];
177 info->var.blue = rgb_bitfields[index][2];
178 info->var.transp = rgb_bitfields[index][3];
179
180 info->fix.visual = FB_VISUAL_TRUECOLOR;
181 info->fix.line_length = info->var.xres_virtual << 1; /* depth=16 */
bb39e419 182 }
3b495f2b
PP
183 } else {
184 /* mono */
185 info->fix.visual = FB_VISUAL_MONO10;
186 info->fix.line_length = info->var.xres_virtual / 8;
1da177e4
LT
187 }
188
3b495f2b 189 info->screen_size = info->fix.line_length * info->var.yres_virtual;
fd2d5430
RG
190 info->var.rotate = ((fbdev->panel->control_base&LCD_CONTROL_SM_MASK) \
191 >> LCD_CONTROL_SM_BIT) * 90;
1da177e4 192
3b495f2b 193 /* Determine BPP mode and format */
fd2d5430 194 fbdev->regs->lcd_control = fbdev->panel->control_base;
3b495f2b 195 fbdev->regs->lcd_horztiming = fbdev->panel->horztiming;
3b495f2b 196 fbdev->regs->lcd_verttiming = fbdev->panel->verttiming;
3b495f2b 197 fbdev->regs->lcd_clkcontrol = fbdev->panel->clkcontrol_base;
bb39e419
RG
198 fbdev->regs->lcd_intenable = 0;
199 fbdev->regs->lcd_intstatus = 0;
3b495f2b
PP
200 fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(fbdev->fb_phys);
201
202 if (panel_is_dual(fbdev->panel)) {
203 /* Second panel display seconf half of screen if possible,
204 * otherwise display the same as the first panel */
205 if (info->var.yres_virtual >= (info->var.yres << 1)) {
206 fbdev->regs->lcd_dmaaddr1 = LCD_DMA_SA_N(fbdev->fb_phys +
207 (info->fix.line_length *
208 (info->var.yres_virtual >> 1)));
209 } else {
210 fbdev->regs->lcd_dmaaddr1 = LCD_DMA_SA_N(fbdev->fb_phys);
211 }
1da177e4 212 }
1da177e4 213
3b495f2b
PP
214 words = info->fix.line_length / sizeof(u32);
215 if (!info->var.rotate || (info->var.rotate == 180)) {
216 words *= info->var.yres_virtual;
217 if (info->var.rotate /* 180 */) {
218 words -= (words % 8); /* should be divisable by 8 */
219 }
220 }
221 fbdev->regs->lcd_words = LCD_WRD_WRDS_N(words);
1da177e4 222
3b495f2b
PP
223 fbdev->regs->lcd_pwmdiv = 0;
224 fbdev->regs->lcd_pwmhi = 0;
1da177e4 225
3b495f2b
PP
226 /* Resume controller */
227 fbdev->regs->lcd_control |= LCD_CONTROL_GO;
bb39e419
RG
228 mdelay(10);
229 au1100fb_fb_blank(VESA_NO_BLANKING, info);
1da177e4 230
3b495f2b 231 return 0;
1da177e4
LT
232}
233
3b495f2b
PP
234/* fb_setcolreg
235 * Set color in LCD palette.
236 */
237int au1100fb_fb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue, unsigned transp, struct fb_info *fbi)
1da177e4 238{
c05b7f3d
RG
239 struct au1100fb_device *fbdev;
240 u32 *palette;
3b495f2b 241 u32 value;
1da177e4 242
c05b7f3d 243 fbdev = to_au1100fb_device(fbi);
0714ea33 244 palette = fbdev->regs->lcd_palettebase;
c05b7f3d 245
3b495f2b
PP
246 if (regno > (AU1100_LCD_NBR_PALETTE_ENTRIES - 1))
247 return -EINVAL;
1da177e4 248
3b495f2b
PP
249 if (fbi->var.grayscale) {
250 /* Convert color to grayscale */
251 red = green = blue =
252 (19595 * red + 38470 * green + 7471 * blue) >> 16;
253 }
1da177e4 254
3b495f2b
PP
255 if (fbi->fix.visual == FB_VISUAL_TRUECOLOR) {
256 /* Place color in the pseudopalette */
257 if (regno > 16)
258 return -EINVAL;
1da177e4 259
3b495f2b
PP
260 palette = (u32*)fbi->pseudo_palette;
261
262 red >>= (16 - fbi->var.red.length);
263 green >>= (16 - fbi->var.green.length);
264 blue >>= (16 - fbi->var.blue.length);
265
266 value = (red << fbi->var.red.offset) |
267 (green << fbi->var.green.offset)|
268 (blue << fbi->var.blue.offset);
269 value &= 0xFFFF;
270
271 } else if (panel_is_active(fbdev->panel)) {
272 /* COLOR TFT PALLETTIZED (use RGB 565) */
273 value = (red & 0xF800)|((green >> 5) & 0x07E0)|((blue >> 11) & 0x001F);
274 value &= 0xFFFF;
275
276 } else if (panel_is_color(fbdev->panel)) {
277 /* COLOR STN MODE */
278 value = (((panel_swap_rgb(fbdev->panel) ? blue : red) >> 12) & 0x000F) |
279 ((green >> 8) & 0x00F0) |
280 (((panel_swap_rgb(fbdev->panel) ? red : blue) >> 4) & 0x0F00);
281 value &= 0xFFF;
282 } else {
283 /* MONOCHROME MODE */
284 value = (green >> 12) & 0x000F;
285 value &= 0xF;
1da177e4
LT
286 }
287
3b495f2b
PP
288 palette[regno] = value;
289
1da177e4
LT
290 return 0;
291}
292
3b495f2b
PP
293/* fb_pan_display
294 * Pan display in x and/or y as specified
295 */
296int au1100fb_fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *fbi)
1da177e4 297{
c05b7f3d 298 struct au1100fb_device *fbdev;
3b495f2b
PP
299 int dy;
300
c05b7f3d
RG
301 fbdev = to_au1100fb_device(fbi);
302
3b495f2b
PP
303 print_dbg("fb_pan_display %p %p", var, fbi);
304
305 if (!var || !fbdev) {
306 return -EINVAL;
307 }
308
309 if (var->xoffset - fbi->var.xoffset) {
310 /* No support for X panning for now! */
311 return -EINVAL;
312 }
313
314 print_dbg("fb_pan_display 2 %p %p", var, fbi);
315 dy = var->yoffset - fbi->var.yoffset;
316 if (dy) {
317
318 u32 dmaaddr;
319
320 print_dbg("Panning screen of %d lines", dy);
321
322 dmaaddr = fbdev->regs->lcd_dmaaddr0;
323 dmaaddr += (fbi->fix.line_length * dy);
324
325 /* TODO: Wait for current frame to finished */
326 fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(dmaaddr);
327
328 if (panel_is_dual(fbdev->panel)) {
329 dmaaddr = fbdev->regs->lcd_dmaaddr1;
330 dmaaddr += (fbi->fix.line_length * dy);
331 fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(dmaaddr);
332 }
333 }
334 print_dbg("fb_pan_display 3 %p %p", var, fbi);
335
336 return 0;
337}
338
3b495f2b
PP
339/* fb_mmap
340 * Map video memory in user space. We don't use the generic fb_mmap method mainly
341 * to allow the use of the TLB streaming flag (CCA=6)
342 */
216d526c 343int au1100fb_fb_mmap(struct fb_info *fbi, struct vm_area_struct *vma)
1da177e4 344{
67f30ad1 345 struct au1100fb_device *fbdev = to_au1100fb_device(fbi);
c05b7f3d 346
76f92201
TZ
347 vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot);
348
1da177e4
LT
349 pgprot_val(vma->vm_page_prot) |= (6 << 9); //CCA=6
350
67f30ad1
CH
351 return dma_mmap_coherent(fbdev->dev, vma, fbdev->fb_mem, fbdev->fb_phys,
352 fbdev->fb_len);
1da177e4
LT
353}
354
93ede59c 355static const struct fb_ops au1100fb_ops = {
3b495f2b 356 .owner = THIS_MODULE,
93ede59c 357 __FB_DEFAULT_IOMEM_OPS_RDWR,
3b495f2b
PP
358 .fb_setcolreg = au1100fb_fb_setcolreg,
359 .fb_blank = au1100fb_fb_blank,
360 .fb_pan_display = au1100fb_fb_pan_display,
93ede59c 361 __FB_DEFAULT_IOMEM_OPS_DRAW,
3b495f2b
PP
362 .fb_mmap = au1100fb_fb_mmap,
363};
1da177e4 364
1da177e4 365
3b495f2b 366/*-------------------------------------------------------------------------*/
1da177e4 367
d121c3f3
ML
368static int au1100fb_setup(struct au1100fb_device *fbdev)
369{
370 char *this_opt, *options;
371 int num_panels = ARRAY_SIZE(known_lcd_panels);
372
373 if (num_panels <= 0) {
374 print_err("No LCD panels supported by driver!");
375 return -ENODEV;
376 }
377
378 if (fb_get_options(DRIVER_NAME, &options))
379 return -ENODEV;
380 if (!options)
381 return -ENODEV;
382
383 while ((this_opt = strsep(&options, ",")) != NULL) {
384 /* Panel option */
385 if (!strncmp(this_opt, "panel:", 6)) {
386 int i;
387 this_opt += 6;
388 for (i = 0; i < num_panels; i++) {
389 if (!strncmp(this_opt, known_lcd_panels[i].name,
390 strlen(this_opt))) {
391 fbdev->panel = &known_lcd_panels[i];
392 fbdev->panel_idx = i;
393 break;
394 }
395 }
396 if (i >= num_panels) {
397 print_warn("Panel '%s' not supported!", this_opt);
398 return -ENODEV;
399 }
400 }
401 /* Unsupported option */
402 else
403 print_warn("Unsupported option \"%s\"", this_opt);
404 }
405
406 print_info("Panel=%s", fbdev->panel->name);
407
408 return 0;
409}
1da177e4 410
48c68c4f 411static int au1100fb_drv_probe(struct platform_device *dev)
1da177e4 412{
46953e6a 413 struct au1100fb_device *fbdev;
3b495f2b 414 struct resource *regs_res;
6b1889c1 415 struct clk *c;
3b495f2b 416
3b495f2b 417 /* Allocate new device private */
db66f025 418 fbdev = devm_kzalloc(&dev->dev, sizeof(*fbdev), GFP_KERNEL);
29914bad 419 if (!fbdev)
3b495f2b 420 return -ENOMEM;
1da177e4 421
d121c3f3
ML
422 if (au1100fb_setup(fbdev))
423 goto failed;
1da177e4 424
7a192ec3 425 platform_set_drvdata(dev, (void *)fbdev);
67f30ad1 426 fbdev->dev = &dev->dev;
1da177e4 427
3b495f2b 428 /* Allocate region for our registers and map them */
d121c3f3
ML
429 regs_res = platform_get_resource(dev, IORESOURCE_MEM, 0);
430 if (!regs_res) {
3b495f2b
PP
431 print_err("fail to retrieve registers resource");
432 return -EFAULT;
433 }
1da177e4 434
3b495f2b 435 au1100fb_fix.mmio_start = regs_res->start;
28f65c11 436 au1100fb_fix.mmio_len = resource_size(regs_res);
1da177e4 437
93019734
ML
438 if (!devm_request_mem_region(&dev->dev,
439 au1100fb_fix.mmio_start,
1c16697b
JL
440 au1100fb_fix.mmio_len,
441 DRIVER_NAME)) {
c05b7f3d 442 print_err("fail to lock memory region at 0x%08lx",
3b495f2b
PP
443 au1100fb_fix.mmio_start);
444 return -EBUSY;
445 }
1da177e4 446
3b495f2b 447 fbdev->regs = (struct au1100fb_regs*)KSEG1ADDR(au1100fb_fix.mmio_start);
1da177e4 448
3b495f2b
PP
449 print_dbg("Register memory map at %p", fbdev->regs);
450 print_dbg("phys=0x%08x, size=%d", fbdev->regs_phys, fbdev->regs_len);
1da177e4 451
6b1889c1
ML
452 c = clk_get(NULL, "lcd_intclk");
453 if (!IS_ERR(c)) {
454 fbdev->lcdclk = c;
455 clk_set_rate(c, 48000000);
456 clk_prepare_enable(c);
457 }
458
3b495f2b
PP
459 /* Allocate the framebuffer to the maximum screen size * nbr of video buffers */
460 fbdev->fb_len = fbdev->panel->xres * fbdev->panel->yres *
461 (fbdev->panel->bpp >> 3) * AU1100FB_NBR_VIDEO_BUFFERS;
462
93019734 463 fbdev->fb_mem = dmam_alloc_coherent(&dev->dev,
1c16697b
JL
464 PAGE_ALIGN(fbdev->fb_len),
465 &fbdev->fb_phys, GFP_KERNEL);
3b495f2b 466 if (!fbdev->fb_mem) {
3879490f 467 print_err("fail to allocate framebuffer (size: %dK))",
3b495f2b 468 fbdev->fb_len / 1024);
1da177e4
LT
469 return -ENOMEM;
470 }
3b495f2b
PP
471
472 au1100fb_fix.smem_start = fbdev->fb_phys;
473 au1100fb_fix.smem_len = fbdev->fb_len;
1da177e4 474
3b495f2b
PP
475 print_dbg("Framebuffer memory map at %p", fbdev->fb_mem);
476 print_dbg("phys=0x%08x, size=%dK", fbdev->fb_phys, fbdev->fb_len / 1024);
477
3b495f2b
PP
478 /* load the panel info into the var struct */
479 au1100fb_var.bits_per_pixel = fbdev->panel->bpp;
480 au1100fb_var.xres = fbdev->panel->xres;
481 au1100fb_var.xres_virtual = au1100fb_var.xres;
482 au1100fb_var.yres = fbdev->panel->yres;
483 au1100fb_var.yres_virtual = au1100fb_var.yres;
484
485 fbdev->info.screen_base = fbdev->fb_mem;
486 fbdev->info.fbops = &au1100fb_ops;
487 fbdev->info.fix = au1100fb_fix;
488
1c16697b 489 fbdev->info.pseudo_palette =
a86854d0 490 devm_kcalloc(&dev->dev, 16, sizeof(u32), GFP_KERNEL);
1c16697b 491 if (!fbdev->info.pseudo_palette)
3b495f2b 492 return -ENOMEM;
3b495f2b
PP
493
494 if (fb_alloc_cmap(&fbdev->info.cmap, AU1100_LCD_NBR_PALETTE_ENTRIES, 0) < 0) {
495 print_err("Fail to allocate colormap (%d entries)",
496 AU1100_LCD_NBR_PALETTE_ENTRIES);
3b495f2b
PP
497 return -EFAULT;
498 }
499
500 fbdev->info.var = au1100fb_var;
501
502 /* Set h/w registers */
503 au1100fb_setmode(fbdev);
504
505 /* Register new framebuffer */
506 if (register_framebuffer(&fbdev->info) < 0) {
507 print_err("cannot register new framebuffer");
508 goto failed;
509 }
510
511 return 0;
512
513failed:
6b1889c1
ML
514 if (fbdev->lcdclk) {
515 clk_disable_unprepare(fbdev->lcdclk);
516 clk_put(fbdev->lcdclk);
517 }
3b495f2b
PP
518 if (fbdev->info.cmap.len != 0) {
519 fb_dealloc_cmap(&fbdev->info.cmap);
520 }
1da177e4 521
1c16697b 522 return -ENODEV;
1da177e4
LT
523}
524
bf76544d 525void au1100fb_drv_remove(struct platform_device *dev)
3b495f2b
PP
526{
527 struct au1100fb_device *fbdev = NULL;
528
5a7bbe86 529 fbdev = platform_get_drvdata(dev);
3b495f2b
PP
530
531#if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
532 au1100fb_fb_blank(VESA_POWERDOWN, &fbdev->info);
533#endif
534 fbdev->regs->lcd_control &= ~LCD_CONTROL_GO;
1da177e4 535
3b495f2b
PP
536 /* Clean up all probe data */
537 unregister_framebuffer(&fbdev->info);
538
3b495f2b 539 fb_dealloc_cmap(&fbdev->info.cmap);
3b495f2b 540
6b1889c1
ML
541 if (fbdev->lcdclk) {
542 clk_disable_unprepare(fbdev->lcdclk);
543 clk_put(fbdev->lcdclk);
544 }
3b495f2b
PP
545}
546
f77f50ca 547#ifdef CONFIG_PM
f77f50ca
RG
548static struct au1100fb_regs fbregs;
549
7a192ec3 550int au1100fb_drv_suspend(struct platform_device *dev, pm_message_t state)
3b495f2b 551{
7a192ec3 552 struct au1100fb_device *fbdev = platform_get_drvdata(dev);
f77f50ca
RG
553
554 if (!fbdev)
555 return 0;
556
f77f50ca
RG
557 /* Blank the LCD */
558 au1100fb_fb_blank(VESA_POWERDOWN, &fbdev->info);
559
b5c525ab 560 clk_disable(fbdev->lcdclk);
f77f50ca
RG
561
562 memcpy(&fbregs, fbdev->regs, sizeof(struct au1100fb_regs));
563
3b495f2b
PP
564 return 0;
565}
566
7a192ec3 567int au1100fb_drv_resume(struct platform_device *dev)
1da177e4 568{
7a192ec3 569 struct au1100fb_device *fbdev = platform_get_drvdata(dev);
f77f50ca
RG
570
571 if (!fbdev)
572 return 0;
573
574 memcpy(fbdev->regs, &fbregs, sizeof(struct au1100fb_regs));
575
b5c525ab 576 clk_enable(fbdev->lcdclk);
f77f50ca
RG
577
578 /* Unblank the LCD */
579 au1100fb_fb_blank(VESA_NO_BLANKING, &fbdev->info);
580
3b495f2b 581 return 0;
1da177e4 582}
f77f50ca
RG
583#else
584#define au1100fb_drv_suspend NULL
585#define au1100fb_drv_resume NULL
586#endif
1da177e4 587
7a192ec3
ML
588static struct platform_driver au1100fb_driver = {
589 .driver = {
590 .name = "au1100-lcd",
7a192ec3 591 },
3b495f2b 592 .probe = au1100fb_drv_probe,
01ecc142 593 .remove = au1100fb_drv_remove,
3b495f2b 594 .suspend = au1100fb_drv_suspend,
bf76544d 595 .resume = au1100fb_drv_resume,
3b495f2b 596};
55be3108 597module_platform_driver(au1100fb_driver);
3b495f2b
PP
598
599MODULE_DESCRIPTION(DRIVER_DESC);
600MODULE_LICENSE("GPL");