blob: 5df406c87c5075d41735ba9d242e14eaae6d4ec0 [file] [log] [blame]
Ben Dooks5fc404e2007-02-20 13:58:21 -08001/* linux/drivers/video/sm501fb.c
2 *
3 * Copyright (c) 2006 Simtec Electronics
4 * Vincent Sanders <vince@simtec.co.uk>
5 * Ben Dooks <ben@simtec.co.uk>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * Framebuffer driver for the Silicon Motion SM501
12 */
13
14#include <linux/module.h>
15#include <linux/kernel.h>
16#include <linux/errno.h>
17#include <linux/string.h>
18#include <linux/mm.h>
19#include <linux/tty.h>
20#include <linux/slab.h>
21#include <linux/delay.h>
22#include <linux/fb.h>
23#include <linux/init.h>
24#include <linux/vmalloc.h>
25#include <linux/dma-mapping.h>
26#include <linux/interrupt.h>
27#include <linux/workqueue.h>
28#include <linux/wait.h>
29#include <linux/platform_device.h>
30#include <linux/clk.h>
Ben Dooksf22e5212007-10-16 01:28:38 -070031#include <linux/console.h>
Ben Dooks2d72b112009-12-15 16:46:34 -080032#include <linux/io.h>
Ben Dooks5fc404e2007-02-20 13:58:21 -080033
Ben Dooks5fc404e2007-02-20 13:58:21 -080034#include <asm/uaccess.h>
35#include <asm/div64.h>
36
37#ifdef CONFIG_PM
38#include <linux/pm.h>
39#endif
40
41#include <linux/sm501.h>
42#include <linux/sm501-regs.h>
43
44#define NR_PALETTE 256
45
46enum sm501_controller {
47 HEAD_CRT = 0,
48 HEAD_PANEL = 1,
49};
50
Ben Dooksd0525412008-07-23 21:31:37 -070051/* SM501 memory address.
52 *
53 * This structure is used to track memory usage within the SM501 framebuffer
54 * allocation. The sm_addr field is stored as an offset as it is often used
55 * against both the physical and mapped addresses.
56 */
Ben Dooks5fc404e2007-02-20 13:58:21 -080057struct sm501_mem {
58 unsigned long size;
Ben Dooksd0525412008-07-23 21:31:37 -070059 unsigned long sm_addr; /* offset from base of sm501 fb. */
Ben Dooks5fc404e2007-02-20 13:58:21 -080060 void __iomem *k_addr;
61};
62
63/* private data that is shared between all frambuffers* */
64struct sm501fb_info {
65 struct device *dev;
66 struct fb_info *fb[2]; /* fb info for both heads */
67 struct resource *fbmem_res; /* framebuffer resource */
68 struct resource *regs_res; /* registers resource */
Vincent Sanders92655762009-12-15 16:46:35 -080069 struct resource *regs2d_res; /* 2d registers resource */
Ben Dooks5fc404e2007-02-20 13:58:21 -080070 struct sm501_platdata_fb *pdata; /* our platform data */
71
Ben Dooksc1f303b2007-10-16 01:28:37 -070072 unsigned long pm_crt_ctrl; /* pm: crt ctrl save */
73
Ben Dooks5fc404e2007-02-20 13:58:21 -080074 int irq;
75 int swap_endian; /* set to swap rgb=>bgr */
76 void __iomem *regs; /* remapped registers */
Vincent Sanders92655762009-12-15 16:46:35 -080077 void __iomem *regs2d; /* 2d remapped registers */
Ben Dooks5fc404e2007-02-20 13:58:21 -080078 void __iomem *fbmem; /* remapped framebuffer */
79 size_t fbmem_len; /* length of remapped region */
80};
81
82/* per-framebuffer private data */
83struct sm501fb_par {
84 u32 pseudo_palette[16];
85
86 enum sm501_controller head;
87 struct sm501_mem cursor;
88 struct sm501_mem screen;
89 struct fb_ops ops;
90
91 void *store_fb;
92 void *store_cursor;
93 void __iomem *cursor_regs;
94 struct sm501fb_info *info;
95};
96
97/* Helper functions */
98
99static inline int h_total(struct fb_var_screeninfo *var)
100{
101 return var->xres + var->left_margin +
102 var->right_margin + var->hsync_len;
103}
104
105static inline int v_total(struct fb_var_screeninfo *var)
106{
107 return var->yres + var->upper_margin +
108 var->lower_margin + var->vsync_len;
109}
110
111/* sm501fb_sync_regs()
112 *
113 * This call is mainly for PCI bus systems where we need to
114 * ensure that any writes to the bus are completed before the
115 * next phase, or after completing a function.
116*/
117
118static inline void sm501fb_sync_regs(struct sm501fb_info *info)
119{
Heiko Schocherbf5f0012011-01-24 09:57:20 +0000120 smc501_readl(info->regs);
Ben Dooks5fc404e2007-02-20 13:58:21 -0800121}
122
123/* sm501_alloc_mem
124 *
125 * This is an attempt to lay out memory for the two framebuffers and
126 * everything else
127 *
Vincent Sanders92655762009-12-15 16:46:35 -0800128 * |fbmem_res->start fbmem_res->end|
129 * | |
130 * |fb[0].fix.smem_start | |fb[1].fix.smem_start | 2K |
Ben Dooks5fc404e2007-02-20 13:58:21 -0800131 * |-> fb[0].fix.smem_len <-| spare |-> fb[1].fix.smem_len <-|-> cursors <-|
132 *
133 * The "spare" space is for the 2d engine data
134 * the fixed is space for the cursors (2x1Kbyte)
135 *
136 * we need to allocate memory for the 2D acceleration engine
137 * command list and the data for the engine to deal with.
138 *
139 * - all allocations must be 128bit aligned
140 * - cursors are 64x64x2 bits (1Kbyte)
141 *
142 */
143
144#define SM501_MEMF_CURSOR (1)
145#define SM501_MEMF_PANEL (2)
146#define SM501_MEMF_CRT (4)
147#define SM501_MEMF_ACCEL (8)
148
Adrian Bunk9540f752007-02-28 20:11:06 -0800149static int sm501_alloc_mem(struct sm501fb_info *inf, struct sm501_mem *mem,
Krzysztof Helt537a1bf2009-06-30 11:41:29 -0700150 unsigned int why, size_t size, u32 smem_len)
Ben Dooks5fc404e2007-02-20 13:58:21 -0800151{
Ben Dooksd0525412008-07-23 21:31:37 -0700152 struct sm501fb_par *par;
Ben Dooks9b599fb2008-07-23 21:31:36 -0700153 struct fb_info *fbi;
Ben Dooksd0525412008-07-23 21:31:37 -0700154 unsigned int ptr;
155 unsigned int end;
Ben Dooks5fc404e2007-02-20 13:58:21 -0800156
157 switch (why) {
158 case SM501_MEMF_CURSOR:
159 ptr = inf->fbmem_len - size;
Ben Dooksd0525412008-07-23 21:31:37 -0700160 inf->fbmem_len = ptr; /* adjust available memory. */
Ben Dooks5fc404e2007-02-20 13:58:21 -0800161 break;
162
163 case SM501_MEMF_PANEL:
roel kluinc00b1b72009-01-06 14:42:36 -0800164 if (size > inf->fbmem_len)
165 return -ENOMEM;
166
Ben Dooks5fc404e2007-02-20 13:58:21 -0800167 ptr = inf->fbmem_len - size;
Ben Dooksd0525412008-07-23 21:31:37 -0700168 fbi = inf->fb[HEAD_CRT];
169
170 /* round down, some programs such as directfb do not draw
171 * 0,0 correctly unless the start is aligned to a page start.
172 */
173
174 if (ptr > 0)
175 ptr &= ~(PAGE_SIZE - 1);
Ben Dooks9b599fb2008-07-23 21:31:36 -0700176
Krzysztof Helt537a1bf2009-06-30 11:41:29 -0700177 if (fbi && ptr < smem_len)
Ben Dooks5fc404e2007-02-20 13:58:21 -0800178 return -ENOMEM;
179
180 break;
181
182 case SM501_MEMF_CRT:
183 ptr = 0;
Ben Dooksd0525412008-07-23 21:31:37 -0700184
185 /* check to see if we have panel memory allocated
186 * which would put an limit on available memory. */
187
188 fbi = inf->fb[HEAD_PANEL];
189 if (fbi) {
190 par = fbi->par;
191 end = par->screen.k_addr ? par->screen.sm_addr : inf->fbmem_len;
192 } else
193 end = inf->fbmem_len;
194
195 if ((ptr + size) > end)
196 return -ENOMEM;
197
Ben Dooks5fc404e2007-02-20 13:58:21 -0800198 break;
199
200 case SM501_MEMF_ACCEL:
Ben Dooksd0525412008-07-23 21:31:37 -0700201 fbi = inf->fb[HEAD_CRT];
Krzysztof Helt537a1bf2009-06-30 11:41:29 -0700202 ptr = fbi ? smem_len : 0;
Ben Dooks5fc404e2007-02-20 13:58:21 -0800203
Ben Dooksd0525412008-07-23 21:31:37 -0700204 fbi = inf->fb[HEAD_PANEL];
205 if (fbi) {
206 par = fbi->par;
207 end = par->screen.sm_addr;
208 } else
Ben Dooks9b599fb2008-07-23 21:31:36 -0700209 end = inf->fbmem_len;
210
211 if ((ptr + size) > end)
Ben Dooks5fc404e2007-02-20 13:58:21 -0800212 return -ENOMEM;
Ben Dooks9b599fb2008-07-23 21:31:36 -0700213
Ben Dooks5fc404e2007-02-20 13:58:21 -0800214 break;
215
216 default:
217 return -EINVAL;
218 }
219
220 mem->size = size;
221 mem->sm_addr = ptr;
222 mem->k_addr = inf->fbmem + ptr;
223
224 dev_dbg(inf->dev, "%s: result %08lx, %p - %u, %zd\n",
225 __func__, mem->sm_addr, mem->k_addr, why, size);
226
227 return 0;
228}
229
230/* sm501fb_ps_to_hz
231 *
232 * Converts a period in picoseconds to Hz.
233 *
234 * Note, we try to keep this in Hz to minimise rounding with
235 * the limited PLL settings on the SM501.
236*/
237
238static unsigned long sm501fb_ps_to_hz(unsigned long psvalue)
239{
240 unsigned long long numerator=1000000000000ULL;
241
242 /* 10^12 / picosecond period gives frequency in Hz */
243 do_div(numerator, psvalue);
244 return (unsigned long)numerator;
245}
246
247/* sm501fb_hz_to_ps is identical to the oposite transform */
248
249#define sm501fb_hz_to_ps(x) sm501fb_ps_to_hz(x)
250
251/* sm501fb_setup_gamma
252 *
253 * Programs a linear 1.0 gamma ramp in case the gamma
254 * correction is enabled without programming anything else.
255*/
256
257static void sm501fb_setup_gamma(struct sm501fb_info *fbi,
258 unsigned long palette)
259{
260 unsigned long value = 0;
261 int offset;
262
263 /* set gamma values */
264 for (offset = 0; offset < 256 * 4; offset += 4) {
Heiko Schocherbf5f0012011-01-24 09:57:20 +0000265 smc501_writel(value, fbi->regs + palette + offset);
Ben Dooks5fc404e2007-02-20 13:58:21 -0800266 value += 0x010101; /* Advance RGB by 1,1,1.*/
267 }
268}
269
270/* sm501fb_check_var
271 *
272 * check common variables for both panel and crt
273*/
274
275static int sm501fb_check_var(struct fb_var_screeninfo *var,
276 struct fb_info *info)
277{
278 struct sm501fb_par *par = info->par;
279 struct sm501fb_info *sm = par->info;
280 unsigned long tmp;
281
282 /* check we can fit these values into the registers */
283
Ville Syrjala7e533702008-03-04 14:28:49 -0800284 if (var->hsync_len > 255 || var->vsync_len > 63)
Ben Dooks5fc404e2007-02-20 13:58:21 -0800285 return -EINVAL;
286
Ville Syrjala7e533702008-03-04 14:28:49 -0800287 /* hdisplay end and hsync start */
288 if ((var->xres + var->right_margin) > 4096)
Ben Dooks5fc404e2007-02-20 13:58:21 -0800289 return -EINVAL;
290
Ville Syrjala7e533702008-03-04 14:28:49 -0800291 /* vdisplay end and vsync start */
Ben Dooks5fc404e2007-02-20 13:58:21 -0800292 if ((var->yres + var->lower_margin) > 2048)
293 return -EINVAL;
294
295 /* hard limits of device */
296
297 if (h_total(var) > 4096 || v_total(var) > 2048)
298 return -EINVAL;
299
300 /* check our line length is going to be 128 bit aligned */
301
302 tmp = (var->xres * var->bits_per_pixel) / 8;
303 if ((tmp & 15) != 0)
304 return -EINVAL;
305
306 /* check the virtual size */
307
308 if (var->xres_virtual > 4096 || var->yres_virtual > 2048)
309 return -EINVAL;
310
311 /* can cope with 8,16 or 32bpp */
312
313 if (var->bits_per_pixel <= 8)
314 var->bits_per_pixel = 8;
315 else if (var->bits_per_pixel <= 16)
316 var->bits_per_pixel = 16;
317 else if (var->bits_per_pixel == 24)
318 var->bits_per_pixel = 32;
319
320 /* set r/g/b positions and validate bpp */
321 switch(var->bits_per_pixel) {
322 case 8:
323 var->red.length = var->bits_per_pixel;
324 var->red.offset = 0;
325 var->green.length = var->bits_per_pixel;
326 var->green.offset = 0;
327 var->blue.length = var->bits_per_pixel;
328 var->blue.offset = 0;
329 var->transp.length = 0;
Ville Syrjala19d06ef2008-03-04 14:28:48 -0800330 var->transp.offset = 0;
Ben Dooks5fc404e2007-02-20 13:58:21 -0800331
332 break;
333
334 case 16:
335 if (sm->pdata->flags & SM501_FBPD_SWAP_FB_ENDIAN) {
Ben Dooks5fc404e2007-02-20 13:58:21 -0800336 var->blue.offset = 11;
337 var->green.offset = 5;
338 var->red.offset = 0;
Ville Syrjalafedbb362008-03-04 14:28:47 -0800339 } else {
340 var->red.offset = 11;
341 var->green.offset = 5;
342 var->blue.offset = 0;
Ben Dooks5fc404e2007-02-20 13:58:21 -0800343 }
Ville Syrjala19d06ef2008-03-04 14:28:48 -0800344 var->transp.offset = 0;
Ben Dooks5fc404e2007-02-20 13:58:21 -0800345
346 var->red.length = 5;
347 var->green.length = 6;
348 var->blue.length = 5;
349 var->transp.length = 0;
350 break;
351
352 case 32:
353 if (sm->pdata->flags & SM501_FBPD_SWAP_FB_ENDIAN) {
354 var->transp.offset = 0;
355 var->red.offset = 8;
356 var->green.offset = 16;
357 var->blue.offset = 24;
358 } else {
359 var->transp.offset = 24;
360 var->red.offset = 16;
361 var->green.offset = 8;
362 var->blue.offset = 0;
363 }
364
365 var->red.length = 8;
366 var->green.length = 8;
367 var->blue.length = 8;
368 var->transp.length = 0;
369 break;
370
371 default:
372 return -EINVAL;
373 }
374
375 return 0;
376}
377
378/*
379 * sm501fb_check_var_crt():
380 *
381 * check the parameters for the CRT head, and either bring them
382 * back into range, or return -EINVAL.
383*/
384
385static int sm501fb_check_var_crt(struct fb_var_screeninfo *var,
386 struct fb_info *info)
387{
388 return sm501fb_check_var(var, info);
389}
390
391/* sm501fb_check_var_pnl():
392 *
393 * check the parameters for the CRT head, and either bring them
394 * back into range, or return -EINVAL.
395*/
396
397static int sm501fb_check_var_pnl(struct fb_var_screeninfo *var,
398 struct fb_info *info)
399{
400 return sm501fb_check_var(var, info);
401}
402
403/* sm501fb_set_par_common
404 *
405 * set common registers for framebuffers
406*/
407
408static int sm501fb_set_par_common(struct fb_info *info,
409 struct fb_var_screeninfo *var)
410{
411 struct sm501fb_par *par = info->par;
412 struct sm501fb_info *fbi = par->info;
413 unsigned long pixclock; /* pixelclock in Hz */
Daniel Mack3ad2f3f2010-02-03 08:01:28 +0800414 unsigned long sm501pixclock; /* pixelclock the 501 can achieve in Hz */
Ben Dooks5fc404e2007-02-20 13:58:21 -0800415 unsigned int mem_type;
416 unsigned int clock_type;
417 unsigned int head_addr;
Krzysztof Helt537a1bf2009-06-30 11:41:29 -0700418 unsigned int smem_len;
Ben Dooks5fc404e2007-02-20 13:58:21 -0800419
420 dev_dbg(fbi->dev, "%s: %dx%d, bpp = %d, virtual %dx%d\n",
421 __func__, var->xres, var->yres, var->bits_per_pixel,
422 var->xres_virtual, var->yres_virtual);
423
424 switch (par->head) {
425 case HEAD_CRT:
426 mem_type = SM501_MEMF_CRT;
427 clock_type = SM501_CLOCK_V2XCLK;
428 head_addr = SM501_DC_CRT_FB_ADDR;
429 break;
430
431 case HEAD_PANEL:
432 mem_type = SM501_MEMF_PANEL;
433 clock_type = SM501_CLOCK_P2XCLK;
434 head_addr = SM501_DC_PANEL_FB_ADDR;
435 break;
436
437 default:
438 mem_type = 0; /* stop compiler warnings */
439 head_addr = 0;
440 clock_type = 0;
441 }
442
443 switch (var->bits_per_pixel) {
444 case 8:
445 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
446 break;
447
448 case 16:
Ville Syrjala5619d822008-03-04 14:28:46 -0800449 info->fix.visual = FB_VISUAL_TRUECOLOR;
Ben Dooks5fc404e2007-02-20 13:58:21 -0800450 break;
451
452 case 32:
453 info->fix.visual = FB_VISUAL_TRUECOLOR;
454 break;
455 }
456
457 /* allocate fb memory within 501 */
458 info->fix.line_length = (var->xres_virtual * var->bits_per_pixel)/8;
Krzysztof Helt537a1bf2009-06-30 11:41:29 -0700459 smem_len = info->fix.line_length * var->yres_virtual;
Ben Dooks5fc404e2007-02-20 13:58:21 -0800460
461 dev_dbg(fbi->dev, "%s: line length = %u\n", __func__,
462 info->fix.line_length);
463
Krzysztof Helt537a1bf2009-06-30 11:41:29 -0700464 if (sm501_alloc_mem(fbi, &par->screen, mem_type, smem_len, smem_len)) {
Ben Dooks5fc404e2007-02-20 13:58:21 -0800465 dev_err(fbi->dev, "no memory available\n");
466 return -ENOMEM;
467 }
468
Krzysztof Helt537a1bf2009-06-30 11:41:29 -0700469 mutex_lock(&info->mm_lock);
Ben Dooks5fc404e2007-02-20 13:58:21 -0800470 info->fix.smem_start = fbi->fbmem_res->start + par->screen.sm_addr;
Krzysztof Helt537a1bf2009-06-30 11:41:29 -0700471 info->fix.smem_len = smem_len;
472 mutex_unlock(&info->mm_lock);
Ben Dooks5fc404e2007-02-20 13:58:21 -0800473
474 info->screen_base = fbi->fbmem + par->screen.sm_addr;
475 info->screen_size = info->fix.smem_len;
476
477 /* set start of framebuffer to the screen */
478
Heiko Schocherbf5f0012011-01-24 09:57:20 +0000479 smc501_writel(par->screen.sm_addr | SM501_ADDR_FLIP,
480 fbi->regs + head_addr);
Ben Dooks5fc404e2007-02-20 13:58:21 -0800481
482 /* program CRT clock */
483
484 pixclock = sm501fb_ps_to_hz(var->pixclock);
485
486 sm501pixclock = sm501_set_clock(fbi->dev->parent, clock_type,
487 pixclock);
488
489 /* update fb layer with actual clock used */
490 var->pixclock = sm501fb_hz_to_ps(sm501pixclock);
491
492 dev_dbg(fbi->dev, "%s: pixclock(ps) = %u, pixclock(Hz) = %lu, "
493 "sm501pixclock = %lu, error = %ld%%\n",
494 __func__, var->pixclock, pixclock, sm501pixclock,
495 ((pixclock - sm501pixclock)*100)/pixclock);
496
497 return 0;
498}
499
500/* sm501fb_set_par_geometry
501 *
502 * set the geometry registers for specified framebuffer.
503*/
504
505static void sm501fb_set_par_geometry(struct fb_info *info,
506 struct fb_var_screeninfo *var)
507{
508 struct sm501fb_par *par = info->par;
509 struct sm501fb_info *fbi = par->info;
510 void __iomem *base = fbi->regs;
511 unsigned long reg;
512
513 if (par->head == HEAD_CRT)
514 base += SM501_DC_CRT_H_TOT;
515 else
516 base += SM501_DC_PANEL_H_TOT;
517
518 /* set framebuffer width and display width */
519
520 reg = info->fix.line_length;
521 reg |= ((var->xres * var->bits_per_pixel)/8) << 16;
522
Heiko Schocherbf5f0012011-01-24 09:57:20 +0000523 smc501_writel(reg, fbi->regs + (par->head == HEAD_CRT ?
Ben Dooks5fc404e2007-02-20 13:58:21 -0800524 SM501_DC_CRT_FB_OFFSET : SM501_DC_PANEL_FB_OFFSET));
525
526 /* program horizontal total */
527
528 reg = (h_total(var) - 1) << 16;
529 reg |= (var->xres - 1);
530
Heiko Schocherbf5f0012011-01-24 09:57:20 +0000531 smc501_writel(reg, base + SM501_OFF_DC_H_TOT);
Ben Dooks5fc404e2007-02-20 13:58:21 -0800532
533 /* program horizontal sync */
534
535 reg = var->hsync_len << 16;
536 reg |= var->xres + var->right_margin - 1;
537
Heiko Schocherbf5f0012011-01-24 09:57:20 +0000538 smc501_writel(reg, base + SM501_OFF_DC_H_SYNC);
Ben Dooks5fc404e2007-02-20 13:58:21 -0800539
540 /* program vertical total */
541
542 reg = (v_total(var) - 1) << 16;
543 reg |= (var->yres - 1);
544
Heiko Schocherbf5f0012011-01-24 09:57:20 +0000545 smc501_writel(reg, base + SM501_OFF_DC_V_TOT);
Ben Dooks5fc404e2007-02-20 13:58:21 -0800546
547 /* program vertical sync */
548 reg = var->vsync_len << 16;
549 reg |= var->yres + var->lower_margin - 1;
550
Heiko Schocherbf5f0012011-01-24 09:57:20 +0000551 smc501_writel(reg, base + SM501_OFF_DC_V_SYNC);
Ben Dooks5fc404e2007-02-20 13:58:21 -0800552}
553
554/* sm501fb_pan_crt
555 *
556 * pan the CRT display output within an virtual framebuffer
557*/
558
559static int sm501fb_pan_crt(struct fb_var_screeninfo *var,
560 struct fb_info *info)
561{
562 struct sm501fb_par *par = info->par;
563 struct sm501fb_info *fbi = par->info;
564 unsigned int bytes_pixel = var->bits_per_pixel / 8;
565 unsigned long reg;
566 unsigned long xoffs;
567
568 xoffs = var->xoffset * bytes_pixel;
569
Heiko Schocherbf5f0012011-01-24 09:57:20 +0000570 reg = smc501_readl(fbi->regs + SM501_DC_CRT_CONTROL);
Ben Dooks5fc404e2007-02-20 13:58:21 -0800571
572 reg &= ~SM501_DC_CRT_CONTROL_PIXEL_MASK;
573 reg |= ((xoffs & 15) / bytes_pixel) << 4;
Heiko Schocherbf5f0012011-01-24 09:57:20 +0000574 smc501_writel(reg, fbi->regs + SM501_DC_CRT_CONTROL);
Ben Dooks5fc404e2007-02-20 13:58:21 -0800575
576 reg = (par->screen.sm_addr + xoffs +
577 var->yoffset * info->fix.line_length);
Heiko Schocherbf5f0012011-01-24 09:57:20 +0000578 smc501_writel(reg | SM501_ADDR_FLIP, fbi->regs + SM501_DC_CRT_FB_ADDR);
Ben Dooks5fc404e2007-02-20 13:58:21 -0800579
580 sm501fb_sync_regs(fbi);
581 return 0;
582}
583
584/* sm501fb_pan_pnl
585 *
586 * pan the panel display output within an virtual framebuffer
587*/
588
589static int sm501fb_pan_pnl(struct fb_var_screeninfo *var,
590 struct fb_info *info)
591{
592 struct sm501fb_par *par = info->par;
593 struct sm501fb_info *fbi = par->info;
594 unsigned long reg;
595
596 reg = var->xoffset | (var->xres_virtual << 16);
Heiko Schocherbf5f0012011-01-24 09:57:20 +0000597 smc501_writel(reg, fbi->regs + SM501_DC_PANEL_FB_WIDTH);
Ben Dooks5fc404e2007-02-20 13:58:21 -0800598
599 reg = var->yoffset | (var->yres_virtual << 16);
Heiko Schocherbf5f0012011-01-24 09:57:20 +0000600 smc501_writel(reg, fbi->regs + SM501_DC_PANEL_FB_HEIGHT);
Ben Dooks5fc404e2007-02-20 13:58:21 -0800601
602 sm501fb_sync_regs(fbi);
603 return 0;
604}
605
606/* sm501fb_set_par_crt
607 *
608 * Set the CRT video mode from the fb_info structure
609*/
610
611static int sm501fb_set_par_crt(struct fb_info *info)
612{
613 struct sm501fb_par *par = info->par;
614 struct sm501fb_info *fbi = par->info;
615 struct fb_var_screeninfo *var = &info->var;
616 unsigned long control; /* control register */
617 int ret;
618
619 /* activate new configuration */
620
621 dev_dbg(fbi->dev, "%s(%p)\n", __func__, info);
622
623 /* enable CRT DAC - note 0 is on!*/
624 sm501_misc_control(fbi->dev->parent, 0, SM501_MISC_DAC_POWER);
625
Heiko Schocherbf5f0012011-01-24 09:57:20 +0000626 control = smc501_readl(fbi->regs + SM501_DC_CRT_CONTROL);
Ben Dooks5fc404e2007-02-20 13:58:21 -0800627
628 control &= (SM501_DC_CRT_CONTROL_PIXEL_MASK |
629 SM501_DC_CRT_CONTROL_GAMMA |
630 SM501_DC_CRT_CONTROL_BLANK |
631 SM501_DC_CRT_CONTROL_SEL |
632 SM501_DC_CRT_CONTROL_CP |
633 SM501_DC_CRT_CONTROL_TVP);
634
635 /* set the sync polarities before we check data source */
636
637 if ((var->sync & FB_SYNC_HOR_HIGH_ACT) == 0)
638 control |= SM501_DC_CRT_CONTROL_HSP;
639
640 if ((var->sync & FB_SYNC_VERT_HIGH_ACT) == 0)
641 control |= SM501_DC_CRT_CONTROL_VSP;
642
643 if ((control & SM501_DC_CRT_CONTROL_SEL) == 0) {
644 /* the head is displaying panel data... */
645
Krzysztof Helt537a1bf2009-06-30 11:41:29 -0700646 sm501_alloc_mem(fbi, &par->screen, SM501_MEMF_CRT, 0,
647 info->fix.smem_len);
Ben Dooks5fc404e2007-02-20 13:58:21 -0800648 goto out_update;
649 }
650
651 ret = sm501fb_set_par_common(info, var);
652 if (ret) {
653 dev_err(fbi->dev, "failed to set common parameters\n");
654 return ret;
655 }
656
657 sm501fb_pan_crt(var, info);
658 sm501fb_set_par_geometry(info, var);
659
660 control |= SM501_FIFO_3; /* fill if >3 free slots */
661
662 switch(var->bits_per_pixel) {
663 case 8:
664 control |= SM501_DC_CRT_CONTROL_8BPP;
665 break;
666
667 case 16:
668 control |= SM501_DC_CRT_CONTROL_16BPP;
Ville Syrjala5619d822008-03-04 14:28:46 -0800669 sm501fb_setup_gamma(fbi, SM501_DC_CRT_PALETTE);
Ben Dooks5fc404e2007-02-20 13:58:21 -0800670 break;
671
672 case 32:
673 control |= SM501_DC_CRT_CONTROL_32BPP;
674 sm501fb_setup_gamma(fbi, SM501_DC_CRT_PALETTE);
675 break;
676
677 default:
678 BUG();
679 }
680
681 control |= SM501_DC_CRT_CONTROL_SEL; /* CRT displays CRT data */
682 control |= SM501_DC_CRT_CONTROL_TE; /* enable CRT timing */
683 control |= SM501_DC_CRT_CONTROL_ENABLE; /* enable CRT plane */
684
685 out_update:
686 dev_dbg(fbi->dev, "new control is %08lx\n", control);
687
Heiko Schocherbf5f0012011-01-24 09:57:20 +0000688 smc501_writel(control, fbi->regs + SM501_DC_CRT_CONTROL);
Ben Dooks5fc404e2007-02-20 13:58:21 -0800689 sm501fb_sync_regs(fbi);
690
691 return 0;
692}
693
694static void sm501fb_panel_power(struct sm501fb_info *fbi, int to)
695{
696 unsigned long control;
697 void __iomem *ctrl_reg = fbi->regs + SM501_DC_PANEL_CONTROL;
Magnus Dammdfcffa42008-02-06 01:39:24 -0800698 struct sm501_platdata_fbsub *pd = fbi->pdata->fb_pnl;
Ben Dooks5fc404e2007-02-20 13:58:21 -0800699
Heiko Schocherbf5f0012011-01-24 09:57:20 +0000700 control = smc501_readl(ctrl_reg);
Ben Dooks5fc404e2007-02-20 13:58:21 -0800701
702 if (to && (control & SM501_DC_PANEL_CONTROL_VDD) == 0) {
703 /* enable panel power */
704
705 control |= SM501_DC_PANEL_CONTROL_VDD; /* FPVDDEN */
Heiko Schocherbf5f0012011-01-24 09:57:20 +0000706 smc501_writel(control, ctrl_reg);
Ben Dooks5fc404e2007-02-20 13:58:21 -0800707 sm501fb_sync_regs(fbi);
708 mdelay(10);
709
710 control |= SM501_DC_PANEL_CONTROL_DATA; /* DATA */
Heiko Schocherbf5f0012011-01-24 09:57:20 +0000711 smc501_writel(control, ctrl_reg);
Ben Dooks5fc404e2007-02-20 13:58:21 -0800712 sm501fb_sync_regs(fbi);
713 mdelay(10);
714
Ben Dooks206c5d62008-07-23 21:31:35 -0700715 /* VBIASEN */
716
Ben Dookscdc83ae2008-05-23 13:04:53 -0700717 if (!(pd->flags & SM501FB_FLAG_PANEL_NO_VBIASEN)) {
Ben Dooks206c5d62008-07-23 21:31:35 -0700718 if (pd->flags & SM501FB_FLAG_PANEL_INV_VBIASEN)
719 control &= ~SM501_DC_PANEL_CONTROL_BIAS;
720 else
721 control |= SM501_DC_PANEL_CONTROL_BIAS;
722
Heiko Schocherbf5f0012011-01-24 09:57:20 +0000723 smc501_writel(control, ctrl_reg);
Magnus Dammdfcffa42008-02-06 01:39:24 -0800724 sm501fb_sync_regs(fbi);
725 mdelay(10);
726 }
Ben Dooks5fc404e2007-02-20 13:58:21 -0800727
Ben Dookscdc83ae2008-05-23 13:04:53 -0700728 if (!(pd->flags & SM501FB_FLAG_PANEL_NO_FPEN)) {
Ben Dooks206c5d62008-07-23 21:31:35 -0700729 if (pd->flags & SM501FB_FLAG_PANEL_INV_FPEN)
730 control &= ~SM501_DC_PANEL_CONTROL_FPEN;
731 else
732 control |= SM501_DC_PANEL_CONTROL_FPEN;
733
Heiko Schocherbf5f0012011-01-24 09:57:20 +0000734 smc501_writel(control, ctrl_reg);
Magnus Dammdfcffa42008-02-06 01:39:24 -0800735 sm501fb_sync_regs(fbi);
736 mdelay(10);
737 }
Ben Dooks5fc404e2007-02-20 13:58:21 -0800738 } else if (!to && (control & SM501_DC_PANEL_CONTROL_VDD) != 0) {
739 /* disable panel power */
Ben Dookscdc83ae2008-05-23 13:04:53 -0700740 if (!(pd->flags & SM501FB_FLAG_PANEL_NO_FPEN)) {
Ben Dooks206c5d62008-07-23 21:31:35 -0700741 if (pd->flags & SM501FB_FLAG_PANEL_INV_FPEN)
742 control |= SM501_DC_PANEL_CONTROL_FPEN;
743 else
744 control &= ~SM501_DC_PANEL_CONTROL_FPEN;
745
Heiko Schocherbf5f0012011-01-24 09:57:20 +0000746 smc501_writel(control, ctrl_reg);
Magnus Dammdfcffa42008-02-06 01:39:24 -0800747 sm501fb_sync_regs(fbi);
748 mdelay(10);
749 }
Ben Dooks5fc404e2007-02-20 13:58:21 -0800750
Ben Dookscdc83ae2008-05-23 13:04:53 -0700751 if (!(pd->flags & SM501FB_FLAG_PANEL_NO_VBIASEN)) {
Ben Dooks206c5d62008-07-23 21:31:35 -0700752 if (pd->flags & SM501FB_FLAG_PANEL_INV_VBIASEN)
753 control |= SM501_DC_PANEL_CONTROL_BIAS;
754 else
755 control &= ~SM501_DC_PANEL_CONTROL_BIAS;
756
Heiko Schocherbf5f0012011-01-24 09:57:20 +0000757 smc501_writel(control, ctrl_reg);
Magnus Dammdfcffa42008-02-06 01:39:24 -0800758 sm501fb_sync_regs(fbi);
759 mdelay(10);
760 }
Ben Dooks5fc404e2007-02-20 13:58:21 -0800761
762 control &= ~SM501_DC_PANEL_CONTROL_DATA;
Heiko Schocherbf5f0012011-01-24 09:57:20 +0000763 smc501_writel(control, ctrl_reg);
Ben Dooks5fc404e2007-02-20 13:58:21 -0800764 sm501fb_sync_regs(fbi);
765 mdelay(10);
766
767 control &= ~SM501_DC_PANEL_CONTROL_VDD;
Heiko Schocherbf5f0012011-01-24 09:57:20 +0000768 smc501_writel(control, ctrl_reg);
Ben Dooks5fc404e2007-02-20 13:58:21 -0800769 sm501fb_sync_regs(fbi);
770 mdelay(10);
771 }
772
773 sm501fb_sync_regs(fbi);
774}
775
776/* sm501fb_set_par_pnl
777 *
778 * Set the panel video mode from the fb_info structure
779*/
780
781static int sm501fb_set_par_pnl(struct fb_info *info)
782{
783 struct sm501fb_par *par = info->par;
784 struct sm501fb_info *fbi = par->info;
785 struct fb_var_screeninfo *var = &info->var;
786 unsigned long control;
787 unsigned long reg;
788 int ret;
789
790 dev_dbg(fbi->dev, "%s(%p)\n", __func__, info);
791
792 /* activate this new configuration */
793
794 ret = sm501fb_set_par_common(info, var);
795 if (ret)
796 return ret;
797
798 sm501fb_pan_pnl(var, info);
799 sm501fb_set_par_geometry(info, var);
800
801 /* update control register */
802
Heiko Schocherbf5f0012011-01-24 09:57:20 +0000803 control = smc501_readl(fbi->regs + SM501_DC_PANEL_CONTROL);
Ben Dooks5fc404e2007-02-20 13:58:21 -0800804 control &= (SM501_DC_PANEL_CONTROL_GAMMA |
805 SM501_DC_PANEL_CONTROL_VDD |
806 SM501_DC_PANEL_CONTROL_DATA |
807 SM501_DC_PANEL_CONTROL_BIAS |
808 SM501_DC_PANEL_CONTROL_FPEN |
809 SM501_DC_PANEL_CONTROL_CP |
810 SM501_DC_PANEL_CONTROL_CK |
811 SM501_DC_PANEL_CONTROL_HP |
812 SM501_DC_PANEL_CONTROL_VP |
813 SM501_DC_PANEL_CONTROL_HPD |
814 SM501_DC_PANEL_CONTROL_VPD);
815
816 control |= SM501_FIFO_3; /* fill if >3 free slots */
817
818 switch(var->bits_per_pixel) {
819 case 8:
820 control |= SM501_DC_PANEL_CONTROL_8BPP;
821 break;
822
823 case 16:
824 control |= SM501_DC_PANEL_CONTROL_16BPP;
Ville Syrjala5619d822008-03-04 14:28:46 -0800825 sm501fb_setup_gamma(fbi, SM501_DC_PANEL_PALETTE);
Ben Dooks5fc404e2007-02-20 13:58:21 -0800826 break;
827
828 case 32:
829 control |= SM501_DC_PANEL_CONTROL_32BPP;
830 sm501fb_setup_gamma(fbi, SM501_DC_PANEL_PALETTE);
831 break;
832
833 default:
834 BUG();
835 }
836
Heiko Schocherbf5f0012011-01-24 09:57:20 +0000837 smc501_writel(0x0, fbi->regs + SM501_DC_PANEL_PANNING_CONTROL);
Ben Dooks5fc404e2007-02-20 13:58:21 -0800838
839 /* panel plane top left and bottom right location */
840
Heiko Schocherbf5f0012011-01-24 09:57:20 +0000841 smc501_writel(0x00, fbi->regs + SM501_DC_PANEL_TL_LOC);
Ben Dooks5fc404e2007-02-20 13:58:21 -0800842
843 reg = var->xres - 1;
844 reg |= (var->yres - 1) << 16;
845
Heiko Schocherbf5f0012011-01-24 09:57:20 +0000846 smc501_writel(reg, fbi->regs + SM501_DC_PANEL_BR_LOC);
Ben Dooks5fc404e2007-02-20 13:58:21 -0800847
848 /* program panel control register */
849
850 control |= SM501_DC_PANEL_CONTROL_TE; /* enable PANEL timing */
851 control |= SM501_DC_PANEL_CONTROL_EN; /* enable PANEL gfx plane */
852
853 if ((var->sync & FB_SYNC_HOR_HIGH_ACT) == 0)
854 control |= SM501_DC_PANEL_CONTROL_HSP;
855
856 if ((var->sync & FB_SYNC_VERT_HIGH_ACT) == 0)
857 control |= SM501_DC_PANEL_CONTROL_VSP;
858
Heiko Schocherbf5f0012011-01-24 09:57:20 +0000859 smc501_writel(control, fbi->regs + SM501_DC_PANEL_CONTROL);
Ben Dooks5fc404e2007-02-20 13:58:21 -0800860 sm501fb_sync_regs(fbi);
861
Ben Dookseb78f9b2007-10-16 01:28:39 -0700862 /* ensure the panel interface is not tristated at this point */
863
864 sm501_modify_reg(fbi->dev->parent, SM501_SYSTEM_CONTROL,
865 0, SM501_SYSCTRL_PANEL_TRISTATE);
866
Ben Dooks5fc404e2007-02-20 13:58:21 -0800867 /* power the panel up */
868 sm501fb_panel_power(fbi, 1);
869 return 0;
870}
871
872
873/* chan_to_field
874 *
875 * convert a colour value into a field position
876 *
877 * from pxafb.c
878*/
879
880static inline unsigned int chan_to_field(unsigned int chan,
881 struct fb_bitfield *bf)
882{
883 chan &= 0xffff;
884 chan >>= 16 - bf->length;
885 return chan << bf->offset;
886}
887
888/* sm501fb_setcolreg
889 *
890 * set the colour mapping for modes that support palettised data
891*/
892
893static int sm501fb_setcolreg(unsigned regno,
894 unsigned red, unsigned green, unsigned blue,
895 unsigned transp, struct fb_info *info)
896{
897 struct sm501fb_par *par = info->par;
898 struct sm501fb_info *fbi = par->info;
899 void __iomem *base = fbi->regs;
900 unsigned int val;
901
902 if (par->head == HEAD_CRT)
903 base += SM501_DC_CRT_PALETTE;
904 else
905 base += SM501_DC_PANEL_PALETTE;
906
907 switch (info->fix.visual) {
908 case FB_VISUAL_TRUECOLOR:
909 /* true-colour, use pseuo-palette */
910
911 if (regno < 16) {
912 u32 *pal = par->pseudo_palette;
913
914 val = chan_to_field(red, &info->var.red);
915 val |= chan_to_field(green, &info->var.green);
916 val |= chan_to_field(blue, &info->var.blue);
917
918 pal[regno] = val;
919 }
920 break;
921
922 case FB_VISUAL_PSEUDOCOLOR:
923 if (regno < 256) {
924 val = (red >> 8) << 16;
925 val |= (green >> 8) << 8;
926 val |= blue >> 8;
927
Heiko Schocherbf5f0012011-01-24 09:57:20 +0000928 smc501_writel(val, base + (regno * 4));
Ben Dooks5fc404e2007-02-20 13:58:21 -0800929 }
930
931 break;
932
933 default:
934 return 1; /* unknown type */
935 }
936
937 return 0;
938}
939
940/* sm501fb_blank_pnl
941 *
942 * Blank or un-blank the panel interface
943*/
944
945static int sm501fb_blank_pnl(int blank_mode, struct fb_info *info)
946{
947 struct sm501fb_par *par = info->par;
948 struct sm501fb_info *fbi = par->info;
949
950 dev_dbg(fbi->dev, "%s(mode=%d, %p)\n", __func__, blank_mode, info);
951
952 switch (blank_mode) {
953 case FB_BLANK_POWERDOWN:
954 sm501fb_panel_power(fbi, 0);
955 break;
956
957 case FB_BLANK_UNBLANK:
958 sm501fb_panel_power(fbi, 1);
959 break;
960
961 case FB_BLANK_NORMAL:
962 case FB_BLANK_VSYNC_SUSPEND:
963 case FB_BLANK_HSYNC_SUSPEND:
964 default:
965 return 1;
966 }
967
968 return 0;
969}
970
971/* sm501fb_blank_crt
972 *
973 * Blank or un-blank the crt interface
974*/
975
976static int sm501fb_blank_crt(int blank_mode, struct fb_info *info)
977{
978 struct sm501fb_par *par = info->par;
979 struct sm501fb_info *fbi = par->info;
980 unsigned long ctrl;
981
982 dev_dbg(fbi->dev, "%s(mode=%d, %p)\n", __func__, blank_mode, info);
983
Heiko Schocherbf5f0012011-01-24 09:57:20 +0000984 ctrl = smc501_readl(fbi->regs + SM501_DC_CRT_CONTROL);
Ben Dooks5fc404e2007-02-20 13:58:21 -0800985
986 switch (blank_mode) {
987 case FB_BLANK_POWERDOWN:
988 ctrl &= ~SM501_DC_CRT_CONTROL_ENABLE;
989 sm501_misc_control(fbi->dev->parent, SM501_MISC_DAC_POWER, 0);
990
991 case FB_BLANK_NORMAL:
992 ctrl |= SM501_DC_CRT_CONTROL_BLANK;
993 break;
994
995 case FB_BLANK_UNBLANK:
996 ctrl &= ~SM501_DC_CRT_CONTROL_BLANK;
997 ctrl |= SM501_DC_CRT_CONTROL_ENABLE;
998 sm501_misc_control(fbi->dev->parent, 0, SM501_MISC_DAC_POWER);
999 break;
1000
1001 case FB_BLANK_VSYNC_SUSPEND:
1002 case FB_BLANK_HSYNC_SUSPEND:
1003 default:
1004 return 1;
1005
1006 }
1007
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001008 smc501_writel(ctrl, fbi->regs + SM501_DC_CRT_CONTROL);
Ben Dooks5fc404e2007-02-20 13:58:21 -08001009 sm501fb_sync_regs(fbi);
1010
1011 return 0;
1012}
1013
1014/* sm501fb_cursor
1015 *
1016 * set or change the hardware cursor parameters
1017*/
1018
Adrian Bunk9540f752007-02-28 20:11:06 -08001019static int sm501fb_cursor(struct fb_info *info, struct fb_cursor *cursor)
Ben Dooks5fc404e2007-02-20 13:58:21 -08001020{
1021 struct sm501fb_par *par = info->par;
1022 struct sm501fb_info *fbi = par->info;
1023 void __iomem *base = fbi->regs;
1024 unsigned long hwc_addr;
1025 unsigned long fg, bg;
1026
1027 dev_dbg(fbi->dev, "%s(%p,%p)\n", __func__, info, cursor);
1028
1029 if (par->head == HEAD_CRT)
1030 base += SM501_DC_CRT_HWC_BASE;
1031 else
1032 base += SM501_DC_PANEL_HWC_BASE;
1033
1034 /* check not being asked to exceed capabilities */
1035
1036 if (cursor->image.width > 64)
1037 return -EINVAL;
1038
1039 if (cursor->image.height > 64)
1040 return -EINVAL;
1041
1042 if (cursor->image.depth > 1)
1043 return -EINVAL;
1044
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001045 hwc_addr = smc501_readl(base + SM501_OFF_HWC_ADDR);
Ben Dooks5fc404e2007-02-20 13:58:21 -08001046
1047 if (cursor->enable)
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001048 smc501_writel(hwc_addr | SM501_HWC_EN,
1049 base + SM501_OFF_HWC_ADDR);
Ben Dooks5fc404e2007-02-20 13:58:21 -08001050 else
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001051 smc501_writel(hwc_addr & ~SM501_HWC_EN,
1052 base + SM501_OFF_HWC_ADDR);
Ben Dooks5fc404e2007-02-20 13:58:21 -08001053
1054 /* set data */
1055 if (cursor->set & FB_CUR_SETPOS) {
1056 unsigned int x = cursor->image.dx;
1057 unsigned int y = cursor->image.dy;
1058
1059 if (x >= 2048 || y >= 2048 )
1060 return -EINVAL;
1061
1062 dev_dbg(fbi->dev, "set position %d,%d\n", x, y);
1063
1064 //y += cursor->image.height;
1065
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001066 smc501_writel(x | (y << 16), base + SM501_OFF_HWC_LOC);
Ben Dooks5fc404e2007-02-20 13:58:21 -08001067 }
1068
1069 if (cursor->set & FB_CUR_SETCMAP) {
1070 unsigned int bg_col = cursor->image.bg_color;
1071 unsigned int fg_col = cursor->image.fg_color;
1072
1073 dev_dbg(fbi->dev, "%s: update cmap (%08x,%08x)\n",
1074 __func__, bg_col, fg_col);
1075
1076 bg = ((info->cmap.red[bg_col] & 0xF8) << 8) |
1077 ((info->cmap.green[bg_col] & 0xFC) << 3) |
1078 ((info->cmap.blue[bg_col] & 0xF8) >> 3);
1079
1080 fg = ((info->cmap.red[fg_col] & 0xF8) << 8) |
1081 ((info->cmap.green[fg_col] & 0xFC) << 3) |
1082 ((info->cmap.blue[fg_col] & 0xF8) >> 3);
1083
Andrew Mortonbe3478d2007-05-08 00:40:22 -07001084 dev_dbg(fbi->dev, "fgcol %08lx, bgcol %08lx\n", fg, bg);
Ben Dooks5fc404e2007-02-20 13:58:21 -08001085
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001086 smc501_writel(bg, base + SM501_OFF_HWC_COLOR_1_2);
1087 smc501_writel(fg, base + SM501_OFF_HWC_COLOR_3);
Ben Dooks5fc404e2007-02-20 13:58:21 -08001088 }
1089
1090 if (cursor->set & FB_CUR_SETSIZE ||
1091 cursor->set & (FB_CUR_SETIMAGE | FB_CUR_SETSHAPE)) {
1092 /* SM501 cursor is a two bpp 64x64 bitmap this routine
1093 * clears it to transparent then combines the cursor
1094 * shape plane with the colour plane to set the
1095 * cursor */
1096 int x, y;
1097 const unsigned char *pcol = cursor->image.data;
1098 const unsigned char *pmsk = cursor->mask;
1099 void __iomem *dst = par->cursor.k_addr;
1100 unsigned char dcol = 0;
1101 unsigned char dmsk = 0;
1102 unsigned int op;
1103
1104 dev_dbg(fbi->dev, "%s: setting shape (%d,%d)\n",
1105 __func__, cursor->image.width, cursor->image.height);
1106
1107 for (op = 0; op < (64*64*2)/8; op+=4)
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001108 smc501_writel(0x0, dst + op);
Ben Dooks5fc404e2007-02-20 13:58:21 -08001109
1110 for (y = 0; y < cursor->image.height; y++) {
1111 for (x = 0; x < cursor->image.width; x++) {
1112 if ((x % 8) == 0) {
1113 dcol = *pcol++;
1114 dmsk = *pmsk++;
1115 } else {
1116 dcol >>= 1;
1117 dmsk >>= 1;
1118 }
1119
1120 if (dmsk & 1) {
1121 op = (dcol & 1) ? 1 : 3;
1122 op <<= ((x % 4) * 2);
1123
1124 op |= readb(dst + (x / 4));
1125 writeb(op, dst + (x / 4));
1126 }
1127 }
1128 dst += (64*2)/8;
1129 }
1130 }
1131
1132 sm501fb_sync_regs(fbi); /* ensure cursor data flushed */
1133 return 0;
1134}
1135
1136/* sm501fb_crtsrc_show
1137 *
1138 * device attribute code to show where the crt output is sourced from
1139*/
1140
1141static ssize_t sm501fb_crtsrc_show(struct device *dev,
1142 struct device_attribute *attr, char *buf)
1143{
1144 struct sm501fb_info *info = dev_get_drvdata(dev);
1145 unsigned long ctrl;
1146
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001147 ctrl = smc501_readl(info->regs + SM501_DC_CRT_CONTROL);
Ben Dooks5fc404e2007-02-20 13:58:21 -08001148 ctrl &= SM501_DC_CRT_CONTROL_SEL;
1149
1150 return snprintf(buf, PAGE_SIZE, "%s\n", ctrl ? "crt" : "panel");
1151}
1152
1153/* sm501fb_crtsrc_show
1154 *
1155 * device attribute code to set where the crt output is sourced from
1156*/
1157
1158static ssize_t sm501fb_crtsrc_store(struct device *dev,
1159 struct device_attribute *attr,
1160 const char *buf, size_t len)
1161{
1162 struct sm501fb_info *info = dev_get_drvdata(dev);
1163 enum sm501_controller head;
1164 unsigned long ctrl;
1165
1166 if (len < 1)
1167 return -EINVAL;
1168
Paul Mundt1f2b69f2007-03-05 00:30:31 -08001169 if (strnicmp(buf, "crt", 3) == 0)
Ben Dooks5fc404e2007-02-20 13:58:21 -08001170 head = HEAD_CRT;
Paul Mundt1f2b69f2007-03-05 00:30:31 -08001171 else if (strnicmp(buf, "panel", 5) == 0)
Ben Dooks5fc404e2007-02-20 13:58:21 -08001172 head = HEAD_PANEL;
1173 else
1174 return -EINVAL;
1175
1176 dev_info(dev, "setting crt source to head %d\n", head);
1177
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001178 ctrl = smc501_readl(info->regs + SM501_DC_CRT_CONTROL);
Ben Dooks5fc404e2007-02-20 13:58:21 -08001179
1180 if (head == HEAD_CRT) {
1181 ctrl |= SM501_DC_CRT_CONTROL_SEL;
1182 ctrl |= SM501_DC_CRT_CONTROL_ENABLE;
1183 ctrl |= SM501_DC_CRT_CONTROL_TE;
1184 } else {
1185 ctrl &= ~SM501_DC_CRT_CONTROL_SEL;
1186 ctrl &= ~SM501_DC_CRT_CONTROL_ENABLE;
1187 ctrl &= ~SM501_DC_CRT_CONTROL_TE;
1188 }
1189
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001190 smc501_writel(ctrl, info->regs + SM501_DC_CRT_CONTROL);
Ben Dooks5fc404e2007-02-20 13:58:21 -08001191 sm501fb_sync_regs(info);
1192
Paul Mundt1f2b69f2007-03-05 00:30:31 -08001193 return len;
Ben Dooks5fc404e2007-02-20 13:58:21 -08001194}
1195
1196/* Prepare the device_attr for registration with sysfs later */
1197static DEVICE_ATTR(crt_src, 0666, sm501fb_crtsrc_show, sm501fb_crtsrc_store);
1198
1199/* sm501fb_show_regs
1200 *
1201 * show the primary sm501 registers
1202*/
1203static int sm501fb_show_regs(struct sm501fb_info *info, char *ptr,
1204 unsigned int start, unsigned int len)
1205{
1206 void __iomem *mem = info->regs;
1207 char *buf = ptr;
1208 unsigned int reg;
1209
1210 for (reg = start; reg < (len + start); reg += 4)
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001211 ptr += sprintf(ptr, "%08x = %08x\n", reg,
1212 smc501_readl(mem + reg));
Ben Dooks5fc404e2007-02-20 13:58:21 -08001213
1214 return ptr - buf;
1215}
1216
1217/* sm501fb_debug_show_crt
1218 *
1219 * show the crt control and cursor registers
1220*/
1221
1222static ssize_t sm501fb_debug_show_crt(struct device *dev,
1223 struct device_attribute *attr, char *buf)
1224{
1225 struct sm501fb_info *info = dev_get_drvdata(dev);
1226 char *ptr = buf;
1227
1228 ptr += sm501fb_show_regs(info, ptr, SM501_DC_CRT_CONTROL, 0x40);
1229 ptr += sm501fb_show_regs(info, ptr, SM501_DC_CRT_HWC_BASE, 0x10);
1230
1231 return ptr - buf;
1232}
1233
1234static DEVICE_ATTR(fbregs_crt, 0444, sm501fb_debug_show_crt, NULL);
1235
1236/* sm501fb_debug_show_pnl
1237 *
1238 * show the panel control and cursor registers
1239*/
1240
1241static ssize_t sm501fb_debug_show_pnl(struct device *dev,
1242 struct device_attribute *attr, char *buf)
1243{
1244 struct sm501fb_info *info = dev_get_drvdata(dev);
1245 char *ptr = buf;
1246
1247 ptr += sm501fb_show_regs(info, ptr, 0x0, 0x40);
1248 ptr += sm501fb_show_regs(info, ptr, SM501_DC_PANEL_HWC_BASE, 0x10);
1249
1250 return ptr - buf;
1251}
1252
1253static DEVICE_ATTR(fbregs_pnl, 0444, sm501fb_debug_show_pnl, NULL);
1254
Vincent Sanders92655762009-12-15 16:46:35 -08001255/* acceleration operations */
1256static int sm501fb_sync(struct fb_info *info)
1257{
1258 int count = 1000000;
1259 struct sm501fb_par *par = info->par;
1260 struct sm501fb_info *fbi = par->info;
1261
1262 /* wait for the 2d engine to be ready */
1263 while ((count > 0) &&
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001264 (smc501_readl(fbi->regs + SM501_SYSTEM_CONTROL) &
Vincent Sanders92655762009-12-15 16:46:35 -08001265 SM501_SYSCTRL_2D_ENGINE_STATUS) != 0)
1266 count--;
1267
1268 if (count <= 0) {
1269 dev_err(info->dev, "Timeout waiting for 2d engine sync\n");
1270 return 1;
1271 }
1272 return 0;
1273}
1274
1275static void sm501fb_copyarea(struct fb_info *info, const struct fb_copyarea *area)
1276{
1277 struct sm501fb_par *par = info->par;
1278 struct sm501fb_info *fbi = par->info;
1279 int width = area->width;
1280 int height = area->height;
1281 int sx = area->sx;
1282 int sy = area->sy;
1283 int dx = area->dx;
1284 int dy = area->dy;
1285 unsigned long rtl = 0;
1286
1287 /* source clip */
1288 if ((sx >= info->var.xres_virtual) ||
1289 (sy >= info->var.yres_virtual))
1290 /* source Area not within virtual screen, skipping */
1291 return;
1292 if ((sx + width) >= info->var.xres_virtual)
1293 width = info->var.xres_virtual - sx - 1;
1294 if ((sy + height) >= info->var.yres_virtual)
1295 height = info->var.yres_virtual - sy - 1;
1296
1297 /* dest clip */
1298 if ((dx >= info->var.xres_virtual) ||
1299 (dy >= info->var.yres_virtual))
1300 /* Destination Area not within virtual screen, skipping */
1301 return;
1302 if ((dx + width) >= info->var.xres_virtual)
1303 width = info->var.xres_virtual - dx - 1;
1304 if ((dy + height) >= info->var.yres_virtual)
1305 height = info->var.yres_virtual - dy - 1;
1306
1307 if ((sx < dx) || (sy < dy)) {
1308 rtl = 1 << 27;
1309 sx += width - 1;
1310 dx += width - 1;
1311 sy += height - 1;
1312 dy += height - 1;
1313 }
1314
1315 if (sm501fb_sync(info))
1316 return;
1317
1318 /* set the base addresses */
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001319 smc501_writel(par->screen.sm_addr, fbi->regs2d + SM501_2D_SOURCE_BASE);
1320 smc501_writel(par->screen.sm_addr,
1321 fbi->regs2d + SM501_2D_DESTINATION_BASE);
Vincent Sanders92655762009-12-15 16:46:35 -08001322
1323 /* set the window width */
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001324 smc501_writel((info->var.xres << 16) | info->var.xres,
Vincent Sanders92655762009-12-15 16:46:35 -08001325 fbi->regs2d + SM501_2D_WINDOW_WIDTH);
1326
1327 /* set window stride */
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001328 smc501_writel((info->var.xres_virtual << 16) | info->var.xres_virtual,
Vincent Sanders92655762009-12-15 16:46:35 -08001329 fbi->regs2d + SM501_2D_PITCH);
1330
1331 /* set data format */
1332 switch (info->var.bits_per_pixel) {
1333 case 8:
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001334 smc501_writel(0, fbi->regs2d + SM501_2D_STRETCH);
Vincent Sanders92655762009-12-15 16:46:35 -08001335 break;
1336 case 16:
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001337 smc501_writel(0x00100000, fbi->regs2d + SM501_2D_STRETCH);
Vincent Sanders92655762009-12-15 16:46:35 -08001338 break;
1339 case 32:
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001340 smc501_writel(0x00200000, fbi->regs2d + SM501_2D_STRETCH);
Vincent Sanders92655762009-12-15 16:46:35 -08001341 break;
1342 }
1343
1344 /* 2d compare mask */
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001345 smc501_writel(0xffffffff, fbi->regs2d + SM501_2D_COLOR_COMPARE_MASK);
Vincent Sanders92655762009-12-15 16:46:35 -08001346
1347 /* 2d mask */
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001348 smc501_writel(0xffffffff, fbi->regs2d + SM501_2D_MASK);
Vincent Sanders92655762009-12-15 16:46:35 -08001349
1350 /* source and destination x y */
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001351 smc501_writel((sx << 16) | sy, fbi->regs2d + SM501_2D_SOURCE);
1352 smc501_writel((dx << 16) | dy, fbi->regs2d + SM501_2D_DESTINATION);
Vincent Sanders92655762009-12-15 16:46:35 -08001353
1354 /* w/h */
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001355 smc501_writel((width << 16) | height, fbi->regs2d + SM501_2D_DIMENSION);
Vincent Sanders92655762009-12-15 16:46:35 -08001356
1357 /* do area move */
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001358 smc501_writel(0x800000cc | rtl, fbi->regs2d + SM501_2D_CONTROL);
Vincent Sanders92655762009-12-15 16:46:35 -08001359}
1360
1361static void sm501fb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
1362{
1363 struct sm501fb_par *par = info->par;
1364 struct sm501fb_info *fbi = par->info;
1365 int width = rect->width, height = rect->height;
1366
1367 if ((rect->dx >= info->var.xres_virtual) ||
1368 (rect->dy >= info->var.yres_virtual))
1369 /* Rectangle not within virtual screen, skipping */
1370 return;
1371 if ((rect->dx + width) >= info->var.xres_virtual)
1372 width = info->var.xres_virtual - rect->dx - 1;
1373 if ((rect->dy + height) >= info->var.yres_virtual)
1374 height = info->var.yres_virtual - rect->dy - 1;
1375
1376 if (sm501fb_sync(info))
1377 return;
1378
1379 /* set the base addresses */
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001380 smc501_writel(par->screen.sm_addr, fbi->regs2d + SM501_2D_SOURCE_BASE);
1381 smc501_writel(par->screen.sm_addr,
1382 fbi->regs2d + SM501_2D_DESTINATION_BASE);
Vincent Sanders92655762009-12-15 16:46:35 -08001383
1384 /* set the window width */
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001385 smc501_writel((info->var.xres << 16) | info->var.xres,
Vincent Sanders92655762009-12-15 16:46:35 -08001386 fbi->regs2d + SM501_2D_WINDOW_WIDTH);
1387
1388 /* set window stride */
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001389 smc501_writel((info->var.xres_virtual << 16) | info->var.xres_virtual,
Vincent Sanders92655762009-12-15 16:46:35 -08001390 fbi->regs2d + SM501_2D_PITCH);
1391
1392 /* set data format */
1393 switch (info->var.bits_per_pixel) {
1394 case 8:
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001395 smc501_writel(0, fbi->regs2d + SM501_2D_STRETCH);
Vincent Sanders92655762009-12-15 16:46:35 -08001396 break;
1397 case 16:
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001398 smc501_writel(0x00100000, fbi->regs2d + SM501_2D_STRETCH);
Vincent Sanders92655762009-12-15 16:46:35 -08001399 break;
1400 case 32:
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001401 smc501_writel(0x00200000, fbi->regs2d + SM501_2D_STRETCH);
Vincent Sanders92655762009-12-15 16:46:35 -08001402 break;
1403 }
1404
1405 /* 2d compare mask */
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001406 smc501_writel(0xffffffff, fbi->regs2d + SM501_2D_COLOR_COMPARE_MASK);
Vincent Sanders92655762009-12-15 16:46:35 -08001407
1408 /* 2d mask */
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001409 smc501_writel(0xffffffff, fbi->regs2d + SM501_2D_MASK);
Vincent Sanders92655762009-12-15 16:46:35 -08001410
1411 /* colour */
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001412 smc501_writel(rect->color, fbi->regs2d + SM501_2D_FOREGROUND);
Vincent Sanders92655762009-12-15 16:46:35 -08001413
1414 /* x y */
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001415 smc501_writel((rect->dx << 16) | rect->dy,
1416 fbi->regs2d + SM501_2D_DESTINATION);
Vincent Sanders92655762009-12-15 16:46:35 -08001417
1418 /* w/h */
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001419 smc501_writel((width << 16) | height, fbi->regs2d + SM501_2D_DIMENSION);
Vincent Sanders92655762009-12-15 16:46:35 -08001420
1421 /* do rectangle fill */
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001422 smc501_writel(0x800100cc, fbi->regs2d + SM501_2D_CONTROL);
Vincent Sanders92655762009-12-15 16:46:35 -08001423}
1424
Ben Dooks5fc404e2007-02-20 13:58:21 -08001425
1426static struct fb_ops sm501fb_ops_crt = {
1427 .owner = THIS_MODULE,
1428 .fb_check_var = sm501fb_check_var_crt,
1429 .fb_set_par = sm501fb_set_par_crt,
1430 .fb_blank = sm501fb_blank_crt,
1431 .fb_setcolreg = sm501fb_setcolreg,
1432 .fb_pan_display = sm501fb_pan_crt,
1433 .fb_cursor = sm501fb_cursor,
Vincent Sanders92655762009-12-15 16:46:35 -08001434 .fb_fillrect = sm501fb_fillrect,
1435 .fb_copyarea = sm501fb_copyarea,
Ben Dooks5fc404e2007-02-20 13:58:21 -08001436 .fb_imageblit = cfb_imageblit,
Vincent Sanders92655762009-12-15 16:46:35 -08001437 .fb_sync = sm501fb_sync,
Ben Dooks5fc404e2007-02-20 13:58:21 -08001438};
1439
1440static struct fb_ops sm501fb_ops_pnl = {
1441 .owner = THIS_MODULE,
1442 .fb_check_var = sm501fb_check_var_pnl,
1443 .fb_set_par = sm501fb_set_par_pnl,
1444 .fb_pan_display = sm501fb_pan_pnl,
1445 .fb_blank = sm501fb_blank_pnl,
1446 .fb_setcolreg = sm501fb_setcolreg,
1447 .fb_cursor = sm501fb_cursor,
Vincent Sanders92655762009-12-15 16:46:35 -08001448 .fb_fillrect = sm501fb_fillrect,
1449 .fb_copyarea = sm501fb_copyarea,
Ben Dooks5fc404e2007-02-20 13:58:21 -08001450 .fb_imageblit = cfb_imageblit,
Vincent Sanders92655762009-12-15 16:46:35 -08001451 .fb_sync = sm501fb_sync,
Ben Dooks5fc404e2007-02-20 13:58:21 -08001452};
1453
Ben Dooks5fc404e2007-02-20 13:58:21 -08001454/* sm501_init_cursor
1455 *
1456 * initialise hw cursor parameters
1457*/
1458
Adrian Bunk9540f752007-02-28 20:11:06 -08001459static int sm501_init_cursor(struct fb_info *fbi, unsigned int reg_base)
Ben Dooks5fc404e2007-02-20 13:58:21 -08001460{
Ben Dooks9b599fb2008-07-23 21:31:36 -07001461 struct sm501fb_par *par;
1462 struct sm501fb_info *info;
Ben Dooks5fc404e2007-02-20 13:58:21 -08001463 int ret;
1464
Ben Dooks9b599fb2008-07-23 21:31:36 -07001465 if (fbi == NULL)
1466 return 0;
1467
1468 par = fbi->par;
1469 info = par->info;
1470
Ben Dooks5fc404e2007-02-20 13:58:21 -08001471 par->cursor_regs = info->regs + reg_base;
1472
Krzysztof Helt537a1bf2009-06-30 11:41:29 -07001473 ret = sm501_alloc_mem(info, &par->cursor, SM501_MEMF_CURSOR, 1024,
1474 fbi->fix.smem_len);
Ben Dooks5fc404e2007-02-20 13:58:21 -08001475 if (ret < 0)
1476 return ret;
1477
1478 /* initialise the colour registers */
1479
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001480 smc501_writel(par->cursor.sm_addr,
1481 par->cursor_regs + SM501_OFF_HWC_ADDR);
Ben Dooks5fc404e2007-02-20 13:58:21 -08001482
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001483 smc501_writel(0x00, par->cursor_regs + SM501_OFF_HWC_LOC);
1484 smc501_writel(0x00, par->cursor_regs + SM501_OFF_HWC_COLOR_1_2);
1485 smc501_writel(0x00, par->cursor_regs + SM501_OFF_HWC_COLOR_3);
Ben Dooks5fc404e2007-02-20 13:58:21 -08001486 sm501fb_sync_regs(info);
1487
1488 return 0;
1489}
1490
1491/* sm501fb_info_start
1492 *
1493 * fills the par structure claiming resources and remapping etc.
1494*/
1495
1496static int sm501fb_start(struct sm501fb_info *info,
1497 struct platform_device *pdev)
1498{
1499 struct resource *res;
Ben Dooks9b599fb2008-07-23 21:31:36 -07001500 struct device *dev = &pdev->dev;
Magnus Dammb1230ee2008-02-06 01:39:25 -08001501 int k;
Ben Dooks5fc404e2007-02-20 13:58:21 -08001502 int ret;
1503
Ben Dooks5fc404e2007-02-20 13:58:21 -08001504 info->irq = ret = platform_get_irq(pdev, 0);
1505 if (ret < 0) {
1506 /* we currently do not use the IRQ */
1507 dev_warn(dev, "no irq for device\n");
1508 }
1509
Vincent Sanders92655762009-12-15 16:46:35 -08001510 /* allocate, reserve and remap resources for display
1511 * controller registers */
Ben Dooks5fc404e2007-02-20 13:58:21 -08001512 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1513 if (res == NULL) {
1514 dev_err(dev, "no resource definition for registers\n");
1515 ret = -ENOENT;
1516 goto err_release;
1517 }
1518
1519 info->regs_res = request_mem_region(res->start,
Ben Dooksd60f6c22009-12-15 16:46:33 -08001520 resource_size(res),
Ben Dooks5fc404e2007-02-20 13:58:21 -08001521 pdev->name);
1522
1523 if (info->regs_res == NULL) {
1524 dev_err(dev, "cannot claim registers\n");
1525 ret = -ENXIO;
1526 goto err_release;
1527 }
1528
Ben Dooksd60f6c22009-12-15 16:46:33 -08001529 info->regs = ioremap(res->start, resource_size(res));
Ben Dooks5fc404e2007-02-20 13:58:21 -08001530 if (info->regs == NULL) {
1531 dev_err(dev, "cannot remap registers\n");
1532 ret = -ENXIO;
1533 goto err_regs_res;
1534 }
1535
Vincent Sanders92655762009-12-15 16:46:35 -08001536 /* allocate, reserve and remap resources for 2d
1537 * controller registers */
1538 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1539 if (res == NULL) {
1540 dev_err(dev, "no resource definition for 2d registers\n");
1541 ret = -ENOENT;
1542 goto err_regs_map;
1543 }
1544
1545 info->regs2d_res = request_mem_region(res->start,
1546 resource_size(res),
1547 pdev->name);
1548
1549 if (info->regs2d_res == NULL) {
1550 dev_err(dev, "cannot claim registers\n");
1551 ret = -ENXIO;
1552 goto err_regs_map;
1553 }
1554
1555 info->regs2d = ioremap(res->start, resource_size(res));
1556 if (info->regs2d == NULL) {
1557 dev_err(dev, "cannot remap registers\n");
1558 ret = -ENXIO;
1559 goto err_regs2d_res;
1560 }
1561
Ben Dooks5fc404e2007-02-20 13:58:21 -08001562 /* allocate, reserve resources for framebuffer */
1563 res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
1564 if (res == NULL) {
1565 dev_err(dev, "no memory resource defined\n");
1566 ret = -ENXIO;
Vincent Sanders92655762009-12-15 16:46:35 -08001567 goto err_regs2d_map;
Ben Dooks5fc404e2007-02-20 13:58:21 -08001568 }
1569
1570 info->fbmem_res = request_mem_region(res->start,
Ben Dooksd60f6c22009-12-15 16:46:33 -08001571 resource_size(res),
Ben Dooks5fc404e2007-02-20 13:58:21 -08001572 pdev->name);
1573 if (info->fbmem_res == NULL) {
1574 dev_err(dev, "cannot claim framebuffer\n");
1575 ret = -ENXIO;
Vincent Sanders92655762009-12-15 16:46:35 -08001576 goto err_regs2d_map;
Ben Dooks5fc404e2007-02-20 13:58:21 -08001577 }
1578
Ben Dooksd60f6c22009-12-15 16:46:33 -08001579 info->fbmem = ioremap(res->start, resource_size(res));
Ben Dooks5fc404e2007-02-20 13:58:21 -08001580 if (info->fbmem == NULL) {
1581 dev_err(dev, "cannot remap framebuffer\n");
1582 goto err_mem_res;
1583 }
1584
Ben Dooksd60f6c22009-12-15 16:46:33 -08001585 info->fbmem_len = resource_size(res);
Ben Dooks5fc404e2007-02-20 13:58:21 -08001586
Magnus Dammb1230ee2008-02-06 01:39:25 -08001587 /* clear framebuffer memory - avoids garbage data on unused fb */
1588 memset(info->fbmem, 0, info->fbmem_len);
1589
1590 /* clear palette ram - undefined at power on */
1591 for (k = 0; k < (256 * 3); k++)
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001592 smc501_writel(0, info->regs + SM501_DC_PANEL_PALETTE + (k * 4));
Magnus Dammb1230ee2008-02-06 01:39:25 -08001593
Ben Dooks5fc404e2007-02-20 13:58:21 -08001594 /* enable display controller */
1595 sm501_unit_power(dev->parent, SM501_GATE_DISPLAY, 1);
1596
Vincent Sanders92655762009-12-15 16:46:35 -08001597 /* enable 2d controller */
1598 sm501_unit_power(dev->parent, SM501_GATE_2D_ENGINE, 1);
Ben Dooks5fc404e2007-02-20 13:58:21 -08001599
Vincent Sanders92655762009-12-15 16:46:35 -08001600 /* setup cursors */
Ben Dooks5fc404e2007-02-20 13:58:21 -08001601 sm501_init_cursor(info->fb[HEAD_CRT], SM501_DC_CRT_HWC_ADDR);
1602 sm501_init_cursor(info->fb[HEAD_PANEL], SM501_DC_PANEL_HWC_ADDR);
1603
1604 return 0; /* everything is setup */
1605
1606 err_mem_res:
1607 release_resource(info->fbmem_res);
1608 kfree(info->fbmem_res);
1609
Vincent Sanders92655762009-12-15 16:46:35 -08001610 err_regs2d_map:
1611 iounmap(info->regs2d);
1612
1613 err_regs2d_res:
1614 release_resource(info->regs2d_res);
1615 kfree(info->regs2d_res);
1616
Ben Dooks5fc404e2007-02-20 13:58:21 -08001617 err_regs_map:
1618 iounmap(info->regs);
1619
1620 err_regs_res:
1621 release_resource(info->regs_res);
1622 kfree(info->regs_res);
1623
1624 err_release:
1625 return ret;
1626}
1627
1628static void sm501fb_stop(struct sm501fb_info *info)
1629{
1630 /* disable display controller */
1631 sm501_unit_power(info->dev->parent, SM501_GATE_DISPLAY, 0);
1632
1633 iounmap(info->fbmem);
1634 release_resource(info->fbmem_res);
1635 kfree(info->fbmem_res);
1636
Vincent Sanders92655762009-12-15 16:46:35 -08001637 iounmap(info->regs2d);
1638 release_resource(info->regs2d_res);
1639 kfree(info->regs2d_res);
1640
Ben Dooks5fc404e2007-02-20 13:58:21 -08001641 iounmap(info->regs);
1642 release_resource(info->regs_res);
1643 kfree(info->regs_res);
1644}
1645
Ben Dooks5fc404e2007-02-20 13:58:21 -08001646static int sm501fb_init_fb(struct fb_info *fb,
1647 enum sm501_controller head,
1648 const char *fbname)
1649{
1650 struct sm501_platdata_fbsub *pd;
1651 struct sm501fb_par *par = fb->par;
1652 struct sm501fb_info *info = par->info;
1653 unsigned long ctrl;
1654 unsigned int enable;
1655 int ret;
1656
1657 switch (head) {
1658 case HEAD_CRT:
1659 pd = info->pdata->fb_crt;
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001660 ctrl = smc501_readl(info->regs + SM501_DC_CRT_CONTROL);
Ben Dooks5fc404e2007-02-20 13:58:21 -08001661 enable = (ctrl & SM501_DC_CRT_CONTROL_ENABLE) ? 1 : 0;
1662
1663 /* ensure we set the correct source register */
1664 if (info->pdata->fb_route != SM501_FB_CRT_PANEL) {
1665 ctrl |= SM501_DC_CRT_CONTROL_SEL;
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001666 smc501_writel(ctrl, info->regs + SM501_DC_CRT_CONTROL);
Ben Dooks5fc404e2007-02-20 13:58:21 -08001667 }
1668
1669 break;
1670
1671 case HEAD_PANEL:
1672 pd = info->pdata->fb_pnl;
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001673 ctrl = smc501_readl(info->regs + SM501_DC_PANEL_CONTROL);
Ben Dooks5fc404e2007-02-20 13:58:21 -08001674 enable = (ctrl & SM501_DC_PANEL_CONTROL_EN) ? 1 : 0;
1675 break;
1676
1677 default:
1678 pd = NULL; /* stop compiler warnings */
1679 ctrl = 0;
1680 enable = 0;
1681 BUG();
1682 }
1683
1684 dev_info(info->dev, "fb %s %sabled at start\n",
1685 fbname, enable ? "en" : "dis");
1686
1687 /* check to see if our routing allows this */
1688
1689 if (head == HEAD_CRT && info->pdata->fb_route == SM501_FB_CRT_PANEL) {
1690 ctrl &= ~SM501_DC_CRT_CONTROL_SEL;
Heiko Schocherbf5f0012011-01-24 09:57:20 +00001691 smc501_writel(ctrl, info->regs + SM501_DC_CRT_CONTROL);
Ben Dooks5fc404e2007-02-20 13:58:21 -08001692 enable = 0;
1693 }
1694
1695 strlcpy(fb->fix.id, fbname, sizeof(fb->fix.id));
1696
1697 memcpy(&par->ops,
1698 (head == HEAD_CRT) ? &sm501fb_ops_crt : &sm501fb_ops_pnl,
1699 sizeof(struct fb_ops));
1700
1701 /* update ops dependant on what we've been passed */
1702
1703 if ((pd->flags & SM501FB_FLAG_USE_HWCURSOR) == 0)
1704 par->ops.fb_cursor = NULL;
1705
1706 fb->fbops = &par->ops;
Vincent Sanders92655762009-12-15 16:46:35 -08001707 fb->flags = FBINFO_FLAG_DEFAULT | FBINFO_READS_FAST |
1708 FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT |
Ben Dooks5fc404e2007-02-20 13:58:21 -08001709 FBINFO_HWACCEL_XPAN | FBINFO_HWACCEL_YPAN;
1710
1711 /* fixed data */
1712
1713 fb->fix.type = FB_TYPE_PACKED_PIXELS;
1714 fb->fix.type_aux = 0;
1715 fb->fix.xpanstep = 1;
1716 fb->fix.ypanstep = 1;
1717 fb->fix.ywrapstep = 0;
1718 fb->fix.accel = FB_ACCEL_NONE;
1719
1720 /* screenmode */
1721
1722 fb->var.nonstd = 0;
1723 fb->var.activate = FB_ACTIVATE_NOW;
1724 fb->var.accel_flags = 0;
1725 fb->var.vmode = FB_VMODE_NONINTERLACED;
1726 fb->var.bits_per_pixel = 16;
1727
1728 if (enable && (pd->flags & SM501FB_FLAG_USE_INIT_MODE) && 0) {
1729 /* TODO read the mode from the current display */
1730
1731 } else {
1732 if (pd->def_mode) {
1733 dev_info(info->dev, "using supplied mode\n");
1734 fb_videomode_to_var(&fb->var, pd->def_mode);
1735
1736 fb->var.bits_per_pixel = pd->def_bpp ? pd->def_bpp : 8;
1737 fb->var.xres_virtual = fb->var.xres;
1738 fb->var.yres_virtual = fb->var.yres;
1739 } else {
1740 ret = fb_find_mode(&fb->var, fb,
1741 NULL, NULL, 0, NULL, 8);
1742
1743 if (ret == 0 || ret == 4) {
1744 dev_err(info->dev,
1745 "failed to get initial mode\n");
1746 return -EINVAL;
1747 }
1748 }
1749 }
1750
1751 /* initialise and set the palette */
Andres Salomon0a5d9242009-03-31 15:25:24 -07001752 if (fb_alloc_cmap(&fb->cmap, NR_PALETTE, 0)) {
1753 dev_err(info->dev, "failed to allocate cmap memory\n");
1754 return -ENOMEM;
1755 }
Ben Dooks5fc404e2007-02-20 13:58:21 -08001756 fb_set_cmap(&fb->cmap, fb);
1757
1758 ret = (fb->fbops->fb_check_var)(&fb->var, fb);
1759 if (ret)
1760 dev_err(info->dev, "check_var() failed on initial setup?\n");
1761
Ben Dooks5fc404e2007-02-20 13:58:21 -08001762 return 0;
1763}
1764
1765/* default platform data if none is supplied (ie, PCI device) */
1766
1767static struct sm501_platdata_fbsub sm501fb_pdata_crt = {
1768 .flags = (SM501FB_FLAG_USE_INIT_MODE |
1769 SM501FB_FLAG_USE_HWCURSOR |
1770 SM501FB_FLAG_USE_HWACCEL |
1771 SM501FB_FLAG_DISABLE_AT_EXIT),
1772
1773};
1774
1775static struct sm501_platdata_fbsub sm501fb_pdata_pnl = {
1776 .flags = (SM501FB_FLAG_USE_INIT_MODE |
1777 SM501FB_FLAG_USE_HWCURSOR |
1778 SM501FB_FLAG_USE_HWACCEL |
1779 SM501FB_FLAG_DISABLE_AT_EXIT),
1780};
1781
1782static struct sm501_platdata_fb sm501fb_def_pdata = {
1783 .fb_route = SM501_FB_OWN,
1784 .fb_crt = &sm501fb_pdata_crt,
1785 .fb_pnl = &sm501fb_pdata_pnl,
1786};
1787
1788static char driver_name_crt[] = "sm501fb-crt";
1789static char driver_name_pnl[] = "sm501fb-panel";
1790
Ben Dooks9b599fb2008-07-23 21:31:36 -07001791static int __devinit sm501fb_probe_one(struct sm501fb_info *info,
1792 enum sm501_controller head)
Ben Dooks5fc404e2007-02-20 13:58:21 -08001793{
Ben Dooks9b599fb2008-07-23 21:31:36 -07001794 unsigned char *name = (head == HEAD_CRT) ? "crt" : "panel";
1795 struct sm501_platdata_fbsub *pd;
1796 struct sm501fb_par *par;
1797 struct fb_info *fbi;
Ben Dooks5fc404e2007-02-20 13:58:21 -08001798
Ben Dooks9b599fb2008-07-23 21:31:36 -07001799 pd = (head == HEAD_CRT) ? info->pdata->fb_crt : info->pdata->fb_pnl;
Ben Dooks5fc404e2007-02-20 13:58:21 -08001800
Ben Dooks9b599fb2008-07-23 21:31:36 -07001801 /* Do not initialise if we've not been given any platform data */
1802 if (pd == NULL) {
1803 dev_info(info->dev, "no data for fb %s (disabled)\n", name);
1804 return 0;
1805 }
1806
1807 fbi = framebuffer_alloc(sizeof(struct sm501fb_par), info->dev);
1808 if (fbi == NULL) {
1809 dev_err(info->dev, "cannot allocate %s framebuffer\n", name);
Ben Dooks5fc404e2007-02-20 13:58:21 -08001810 return -ENOMEM;
1811 }
1812
Ben Dooks9b599fb2008-07-23 21:31:36 -07001813 par = fbi->par;
1814 par->info = info;
1815 par->head = head;
1816 fbi->pseudo_palette = &par->pseudo_palette;
1817
1818 info->fb[head] = fbi;
1819
1820 return 0;
1821}
1822
1823/* Free up anything allocated by sm501fb_init_fb */
1824
1825static void sm501_free_init_fb(struct sm501fb_info *info,
1826 enum sm501_controller head)
1827{
1828 struct fb_info *fbi = info->fb[head];
1829
1830 fb_dealloc_cmap(&fbi->cmap);
1831}
1832
1833static int __devinit sm501fb_start_one(struct sm501fb_info *info,
1834 enum sm501_controller head,
1835 const char *drvname)
1836{
1837 struct fb_info *fbi = info->fb[head];
1838 int ret;
1839
1840 if (!fbi)
1841 return 0;
1842
Linus Torvalds6c968952009-07-08 09:20:11 -07001843 mutex_init(&info->fb[head]->mm_lock);
1844
Ben Dooks9b599fb2008-07-23 21:31:36 -07001845 ret = sm501fb_init_fb(info->fb[head], head, drvname);
1846 if (ret) {
1847 dev_err(info->dev, "cannot initialise fb %s\n", drvname);
1848 return ret;
Ben Dooks5fc404e2007-02-20 13:58:21 -08001849 }
1850
Ben Dooks9b599fb2008-07-23 21:31:36 -07001851 ret = register_framebuffer(info->fb[head]);
1852 if (ret) {
1853 dev_err(info->dev, "failed to register fb %s\n", drvname);
1854 sm501_free_init_fb(info, head);
1855 return ret;
Ben Dooks5fc404e2007-02-20 13:58:21 -08001856 }
1857
Ben Dooks9b599fb2008-07-23 21:31:36 -07001858 dev_info(info->dev, "fb%d: %s frame buffer\n", fbi->node, fbi->fix.id);
1859
1860 return 0;
1861}
1862
1863static int __devinit sm501fb_probe(struct platform_device *pdev)
1864{
1865 struct sm501fb_info *info;
1866 struct device *dev = &pdev->dev;
1867 int ret;
1868
1869 /* allocate our framebuffers */
1870
1871 info = kzalloc(sizeof(struct sm501fb_info), GFP_KERNEL);
1872 if (!info) {
1873 dev_err(dev, "failed to allocate state\n");
1874 return -ENOMEM;
1875 }
1876
1877 info->dev = dev = &pdev->dev;
1878 platform_set_drvdata(pdev, info);
1879
Ben Dooks5fc404e2007-02-20 13:58:21 -08001880 if (dev->parent->platform_data) {
1881 struct sm501_platdata *pd = dev->parent->platform_data;
1882 info->pdata = pd->fb;
1883 }
1884
1885 if (info->pdata == NULL) {
1886 dev_info(dev, "using default configuration data\n");
1887 info->pdata = &sm501fb_def_pdata;
1888 }
1889
Ben Dooks9b599fb2008-07-23 21:31:36 -07001890 /* probe for the presence of each panel */
1891
1892 ret = sm501fb_probe_one(info, HEAD_CRT);
1893 if (ret < 0) {
1894 dev_err(dev, "failed to probe CRT\n");
1895 goto err_alloc;
1896 }
1897
1898 ret = sm501fb_probe_one(info, HEAD_PANEL);
1899 if (ret < 0) {
1900 dev_err(dev, "failed to probe PANEL\n");
1901 goto err_probed_crt;
1902 }
1903
1904 if (info->fb[HEAD_PANEL] == NULL &&
1905 info->fb[HEAD_CRT] == NULL) {
1906 dev_err(dev, "no framebuffers found\n");
1907 goto err_alloc;
1908 }
1909
1910 /* get the resources for both of the framebuffers */
Ben Dooks5fc404e2007-02-20 13:58:21 -08001911
1912 ret = sm501fb_start(info, pdev);
1913 if (ret) {
1914 dev_err(dev, "cannot initialise SM501\n");
Ben Dooks9b599fb2008-07-23 21:31:36 -07001915 goto err_probed_panel;
Ben Dooks5fc404e2007-02-20 13:58:21 -08001916 }
1917
Ben Dooks9b599fb2008-07-23 21:31:36 -07001918 ret = sm501fb_start_one(info, HEAD_CRT, driver_name_crt);
Ben Dooks5fc404e2007-02-20 13:58:21 -08001919 if (ret) {
Ben Dooks9b599fb2008-07-23 21:31:36 -07001920 dev_err(dev, "failed to start CRT\n");
1921 goto err_started;
Ben Dooks5fc404e2007-02-20 13:58:21 -08001922 }
1923
Ben Dooks9b599fb2008-07-23 21:31:36 -07001924 ret = sm501fb_start_one(info, HEAD_PANEL, driver_name_pnl);
Ben Dooks5fc404e2007-02-20 13:58:21 -08001925 if (ret) {
Ben Dooks9b599fb2008-07-23 21:31:36 -07001926 dev_err(dev, "failed to start Panel\n");
1927 goto err_started_crt;
Ben Dooks5fc404e2007-02-20 13:58:21 -08001928 }
1929
Ben Dooks5fc404e2007-02-20 13:58:21 -08001930 /* create device files */
1931
1932 ret = device_create_file(dev, &dev_attr_crt_src);
1933 if (ret)
Ben Dooks9b599fb2008-07-23 21:31:36 -07001934 goto err_started_panel;
Ben Dooks5fc404e2007-02-20 13:58:21 -08001935
1936 ret = device_create_file(dev, &dev_attr_fbregs_pnl);
1937 if (ret)
Ben Dooks9b599fb2008-07-23 21:31:36 -07001938 goto err_attached_crtsrc_file;
Ben Dooks5fc404e2007-02-20 13:58:21 -08001939
1940 ret = device_create_file(dev, &dev_attr_fbregs_crt);
1941 if (ret)
Ben Dooks9b599fb2008-07-23 21:31:36 -07001942 goto err_attached_pnlregs_file;
Ben Dooks5fc404e2007-02-20 13:58:21 -08001943
1944 /* we registered, return ok */
1945 return 0;
1946
Ben Dooks9b599fb2008-07-23 21:31:36 -07001947err_attached_pnlregs_file:
Ben Dooks5fc404e2007-02-20 13:58:21 -08001948 device_remove_file(dev, &dev_attr_fbregs_pnl);
1949
Ben Dooks9b599fb2008-07-23 21:31:36 -07001950err_attached_crtsrc_file:
Ben Dooks5fc404e2007-02-20 13:58:21 -08001951 device_remove_file(dev, &dev_attr_crt_src);
1952
Ben Dooks9b599fb2008-07-23 21:31:36 -07001953err_started_panel:
1954 unregister_framebuffer(info->fb[HEAD_PANEL]);
1955 sm501_free_init_fb(info, HEAD_PANEL);
Ben Dooks5fc404e2007-02-20 13:58:21 -08001956
Ben Dooks9b599fb2008-07-23 21:31:36 -07001957err_started_crt:
1958 unregister_framebuffer(info->fb[HEAD_CRT]);
1959 sm501_free_init_fb(info, HEAD_CRT);
Ben Dooks5fc404e2007-02-20 13:58:21 -08001960
Ben Dooks9b599fb2008-07-23 21:31:36 -07001961err_started:
Ben Dooks5fc404e2007-02-20 13:58:21 -08001962 sm501fb_stop(info);
1963
Ben Dooks9b599fb2008-07-23 21:31:36 -07001964err_probed_panel:
1965 framebuffer_release(info->fb[HEAD_PANEL]);
Ben Dooks5fc404e2007-02-20 13:58:21 -08001966
Ben Dooks9b599fb2008-07-23 21:31:36 -07001967err_probed_crt:
1968 framebuffer_release(info->fb[HEAD_CRT]);
Ben Dooks5fc404e2007-02-20 13:58:21 -08001969
Ben Dooks9b599fb2008-07-23 21:31:36 -07001970err_alloc:
1971 kfree(info);
Ben Dooks5fc404e2007-02-20 13:58:21 -08001972
1973 return ret;
1974}
1975
1976
1977/*
1978 * Cleanup
1979 */
1980static int sm501fb_remove(struct platform_device *pdev)
1981{
1982 struct sm501fb_info *info = platform_get_drvdata(pdev);
1983 struct fb_info *fbinfo_crt = info->fb[0];
1984 struct fb_info *fbinfo_pnl = info->fb[1];
1985
1986 device_remove_file(&pdev->dev, &dev_attr_fbregs_crt);
1987 device_remove_file(&pdev->dev, &dev_attr_fbregs_pnl);
1988 device_remove_file(&pdev->dev, &dev_attr_crt_src);
1989
Ben Dooks9b599fb2008-07-23 21:31:36 -07001990 sm501_free_init_fb(info, HEAD_CRT);
1991 sm501_free_init_fb(info, HEAD_PANEL);
1992
Ben Dooks5fc404e2007-02-20 13:58:21 -08001993 unregister_framebuffer(fbinfo_crt);
1994 unregister_framebuffer(fbinfo_pnl);
1995
1996 sm501fb_stop(info);
Ben Dooks9b599fb2008-07-23 21:31:36 -07001997 kfree(info);
Ben Dooks5fc404e2007-02-20 13:58:21 -08001998
1999 framebuffer_release(fbinfo_pnl);
2000 framebuffer_release(fbinfo_crt);
2001
2002 return 0;
2003}
2004
2005#ifdef CONFIG_PM
2006
2007static int sm501fb_suspend_fb(struct sm501fb_info *info,
2008 enum sm501_controller head)
2009{
2010 struct fb_info *fbi = info->fb[head];
2011 struct sm501fb_par *par = fbi->par;
2012
2013 if (par->screen.size == 0)
2014 return 0;
2015
Ben Dooks40488db2008-02-06 01:39:38 -08002016 /* blank the relevant interface to ensure unit power minimised */
2017 (par->ops.fb_blank)(FB_BLANK_POWERDOWN, fbi);
2018
2019 /* tell console/fb driver we are suspending */
2020
Torben Hohnac751ef2011-01-25 15:07:35 -08002021 console_lock();
Ben Dooks40488db2008-02-06 01:39:38 -08002022 fb_set_suspend(fbi, 1);
Torben Hohnac751ef2011-01-25 15:07:35 -08002023 console_unlock();
Ben Dooks40488db2008-02-06 01:39:38 -08002024
Ben Dooks5fc404e2007-02-20 13:58:21 -08002025 /* backup copies in case chip is powered down over suspend */
2026
2027 par->store_fb = vmalloc(par->screen.size);
2028 if (par->store_fb == NULL) {
2029 dev_err(info->dev, "no memory to store screen\n");
2030 return -ENOMEM;
2031 }
2032
2033 par->store_cursor = vmalloc(par->cursor.size);
2034 if (par->store_cursor == NULL) {
2035 dev_err(info->dev, "no memory to store cursor\n");
2036 goto err_nocursor;
2037 }
2038
Ben Dooksc1f303b2007-10-16 01:28:37 -07002039 dev_dbg(info->dev, "suspending screen to %p\n", par->store_fb);
2040 dev_dbg(info->dev, "suspending cursor to %p\n", par->store_cursor);
2041
Ben Dooks5fc404e2007-02-20 13:58:21 -08002042 memcpy_fromio(par->store_fb, par->screen.k_addr, par->screen.size);
2043 memcpy_fromio(par->store_cursor, par->cursor.k_addr, par->cursor.size);
Ben Dooksf22e5212007-10-16 01:28:38 -07002044
Ben Dooks5fc404e2007-02-20 13:58:21 -08002045 return 0;
2046
2047 err_nocursor:
2048 vfree(par->store_fb);
Ben Dooksc1f303b2007-10-16 01:28:37 -07002049 par->store_fb = NULL;
Ben Dooks5fc404e2007-02-20 13:58:21 -08002050
2051 return -ENOMEM;
Ben Dooks5fc404e2007-02-20 13:58:21 -08002052}
2053
2054static void sm501fb_resume_fb(struct sm501fb_info *info,
2055 enum sm501_controller head)
2056{
2057 struct fb_info *fbi = info->fb[head];
2058 struct sm501fb_par *par = fbi->par;
2059
2060 if (par->screen.size == 0)
2061 return;
2062
2063 /* re-activate the configuration */
2064
2065 (par->ops.fb_set_par)(fbi);
2066
2067 /* restore the data */
2068
Ben Dooksc1f303b2007-10-16 01:28:37 -07002069 dev_dbg(info->dev, "restoring screen from %p\n", par->store_fb);
2070 dev_dbg(info->dev, "restoring cursor from %p\n", par->store_cursor);
2071
2072 if (par->store_fb)
2073 memcpy_toio(par->screen.k_addr, par->store_fb,
2074 par->screen.size);
2075
2076 if (par->store_cursor)
2077 memcpy_toio(par->cursor.k_addr, par->store_cursor,
2078 par->cursor.size);
Ben Dooks5fc404e2007-02-20 13:58:21 -08002079
Torben Hohnac751ef2011-01-25 15:07:35 -08002080 console_lock();
Ben Dooksf22e5212007-10-16 01:28:38 -07002081 fb_set_suspend(fbi, 0);
Torben Hohnac751ef2011-01-25 15:07:35 -08002082 console_unlock();
Ben Dooksf22e5212007-10-16 01:28:38 -07002083
Ben Dooks5fc404e2007-02-20 13:58:21 -08002084 vfree(par->store_fb);
2085 vfree(par->store_cursor);
2086}
2087
2088
2089/* suspend and resume support */
2090
2091static int sm501fb_suspend(struct platform_device *pdev, pm_message_t state)
2092{
2093 struct sm501fb_info *info = platform_get_drvdata(pdev);
2094
Ben Dooksc1f303b2007-10-16 01:28:37 -07002095 /* store crt control to resume with */
Heiko Schocherbf5f0012011-01-24 09:57:20 +00002096 info->pm_crt_ctrl = smc501_readl(info->regs + SM501_DC_CRT_CONTROL);
Ben Dooksc1f303b2007-10-16 01:28:37 -07002097
Ben Dooks5fc404e2007-02-20 13:58:21 -08002098 sm501fb_suspend_fb(info, HEAD_CRT);
2099 sm501fb_suspend_fb(info, HEAD_PANEL);
2100
2101 /* turn off the clocks, in case the device is not powered down */
2102 sm501_unit_power(info->dev->parent, SM501_GATE_DISPLAY, 0);
2103
2104 return 0;
2105}
2106
Ben Dooksc1f303b2007-10-16 01:28:37 -07002107#define SM501_CRT_CTRL_SAVE (SM501_DC_CRT_CONTROL_TVP | \
2108 SM501_DC_CRT_CONTROL_SEL)
2109
2110
Ben Dooks5fc404e2007-02-20 13:58:21 -08002111static int sm501fb_resume(struct platform_device *pdev)
2112{
2113 struct sm501fb_info *info = platform_get_drvdata(pdev);
Ben Dooksc1f303b2007-10-16 01:28:37 -07002114 unsigned long crt_ctrl;
Ben Dooks5fc404e2007-02-20 13:58:21 -08002115
2116 sm501_unit_power(info->dev->parent, SM501_GATE_DISPLAY, 1);
2117
Ben Dooksc1f303b2007-10-16 01:28:37 -07002118 /* restore the items we want to be saved for crt control */
2119
Heiko Schocherbf5f0012011-01-24 09:57:20 +00002120 crt_ctrl = smc501_readl(info->regs + SM501_DC_CRT_CONTROL);
Ben Dooksc1f303b2007-10-16 01:28:37 -07002121 crt_ctrl &= ~SM501_CRT_CTRL_SAVE;
2122 crt_ctrl |= info->pm_crt_ctrl & SM501_CRT_CTRL_SAVE;
Heiko Schocherbf5f0012011-01-24 09:57:20 +00002123 smc501_writel(crt_ctrl, info->regs + SM501_DC_CRT_CONTROL);
Ben Dooksc1f303b2007-10-16 01:28:37 -07002124
Ben Dooks5fc404e2007-02-20 13:58:21 -08002125 sm501fb_resume_fb(info, HEAD_CRT);
2126 sm501fb_resume_fb(info, HEAD_PANEL);
2127
2128 return 0;
2129}
2130
2131#else
2132#define sm501fb_suspend NULL
2133#define sm501fb_resume NULL
2134#endif
2135
2136static struct platform_driver sm501fb_driver = {
2137 .probe = sm501fb_probe,
2138 .remove = sm501fb_remove,
2139 .suspend = sm501fb_suspend,
2140 .resume = sm501fb_resume,
2141 .driver = {
2142 .name = "sm501-fb",
2143 .owner = THIS_MODULE,
2144 },
2145};
2146
Adrian Bunk9540f752007-02-28 20:11:06 -08002147static int __devinit sm501fb_init(void)
Ben Dooks5fc404e2007-02-20 13:58:21 -08002148{
2149 return platform_driver_register(&sm501fb_driver);
2150}
2151
2152static void __exit sm501fb_cleanup(void)
2153{
2154 platform_driver_unregister(&sm501fb_driver);
2155}
2156
2157module_init(sm501fb_init);
2158module_exit(sm501fb_cleanup);
2159
2160MODULE_AUTHOR("Ben Dooks, Vincent Sanders");
2161MODULE_DESCRIPTION("SM501 Framebuffer driver");
2162MODULE_LICENSE("GPL v2");