1 /* Smedia Glamo 336x/337x driver
3 * (C) 2007-2008 by Openmoko, Inc.
4 * Author: Harald Welte <laforge@openmoko.org>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 #include <linux/module.h>
24 #include <linux/kernel.h>
25 #include <linux/string.h>
27 #include <linux/delay.h>
29 #include <linux/init.h>
30 #include <linux/platform_device.h>
31 #include <linux/spinlock.h>
33 #include <linux/mfd/glamo.h>
35 #include <asm/div64.h>
41 #include <linux/glamofb.h>
43 #include "glamo-regs.h"
44 #include "glamo-core.h"
46 static void glamofb_program_mode(struct glamofb_handle
* glamo
);
48 struct glamofb_handle
{
49 struct glamo_core
*core
;
53 struct resource
*fb_res
;
55 struct glamo_fb_platform_data
*mach_info
;
56 char __iomem
*cursor_addr
;
58 u_int32_t pseudo_pal
[16];
61 int mode_set
; /* 0 if the current display mode hasn't been set on the glamo */
62 int output_enabled
; /* 0 if the video output is disabled */
65 static void glamo_output_enable(struct glamofb_handle
*gfb
) {
66 struct glamo_core
*gcore
= gfb
->core
;
68 if (gfb
->output_enabled
)
71 /* enable the pixel clock if off */
72 glamo_engine_clkreg_set(gcore
,
74 GLAMO_CLOCK_LCD_EN_DCLK
,
75 GLAMO_CLOCK_LCD_EN_DCLK
);
77 gfb
->output_enabled
= 1;
79 glamofb_program_mode(gfb
);
82 static void glamo_output_disable(struct glamofb_handle
*gfb
) {
83 struct glamo_core
*gcore
= gfb
->core
;
85 if (!gfb
->output_enabled
)
88 /* enable the pixel clock if off */
89 glamo_engine_clkreg_set(gcore
,
91 GLAMO_CLOCK_LCD_EN_DCLK
,
94 gfb
->output_enabled
= 0;
98 static int reg_read(struct glamofb_handle
*glamo
,
103 for (i
= 0; i
!= 2; i
++)
106 return readw(glamo
->base
+ reg
);
109 static void reg_write(struct glamofb_handle
*glamo
,
110 u_int16_t reg
, u_int16_t val
)
114 for (i
= 0; i
!= 2; i
++)
117 writew(val
, glamo
->base
+ reg
);
120 static struct glamo_script glamo_regs
[] = {
121 { GLAMO_REG_LCD_MODE1
, 0x0020 },
122 /* no display rotation, no hardware cursor, no dither, no gamma,
123 * no retrace flip, vsync low-active, hsync low active,
124 * no TVCLK, no partial display, hw dest color from fb,
125 * no partial display mode, LCD1, software flip, */
126 { GLAMO_REG_LCD_MODE2
, 0x9020 },
127 /* video flip, no ptr, no ptr, dhclk off,
128 * normal mode, no cpuif,
129 * res, serial msb first, single fb, no fr ctrl,
130 * cpu if bits all zero, no crc
131 * 0000 0000 0010 0000 */
132 { GLAMO_REG_LCD_MODE3
, 0x0b40 },
133 /* src data rgb565, res, 18bit rgb666
134 * 000 01 011 0100 0000 */
135 { GLAMO_REG_LCD_POLARITY
, 0x440c },
136 /* DE high active, no cpu/lcd if, cs0 force low, a0 low active,
137 * np cpu if, 9bit serial data, sclk rising edge latch data
138 * 01 00 0 100 0 000 01 0 0 */
139 /* The following values assume 640*480@16bpp */
140 { GLAMO_REG_LCD_A_BASE1
, 0x0000 }, /* display A base address 15:0 */
141 { GLAMO_REG_LCD_A_BASE2
, 0x0000 }, /* display A base address 22:16 */
142 { GLAMO_REG_LCD_CURSOR_BASE1
, 0xC000 }, /* cursor base address 15:0 */
143 { GLAMO_REG_LCD_CURSOR_BASE2
, 0x0012 }, /* cursor base address 22:16 */
144 { GLAMO_REG_LCD_COMMAND2
, 0x0000 }, /* display page A */
147 static int glamofb_run_script(struct glamofb_handle
*glamo
,
148 struct glamo_script
*script
, int len
)
152 if (glamo
->core
->suspending
) {
153 dev_err(&glamo
->core
->pdev
->dev
,
154 "IGNORING glamofb_run_script while "
159 for (i
= 0; i
< len
; i
++) {
160 struct glamo_script
*line
= &script
[i
];
162 if (line
->reg
== 0xffff)
164 else if (line
->reg
== 0xfffe)
167 reg_write(glamo
, script
[i
].reg
, script
[i
].val
);
173 static int glamofb_check_var(struct fb_var_screeninfo
*var
,
174 struct fb_info
*info
)
176 struct glamofb_handle
*glamo
= info
->par
;
178 if (glamo
->core
->suspending
) {
179 dev_err(&glamo
->core
->pdev
->dev
,
180 "IGNORING glamofb_check_var while "
185 if (var
->bits_per_pixel
!= 16)
186 var
->bits_per_pixel
= 16;
188 var
->height
= glamo
->mach_info
->height
;
189 var
->width
= glamo
->mach_info
->width
;
191 /* FIXME: set rgb positions */
192 switch (var
->bits_per_pixel
) {
194 switch (reg_read(glamo
, GLAMO_REG_LCD_MODE3
) & 0xc000) {
195 case GLAMO_LCD_SRC_RGB565
:
196 var
->red
.offset
= 11;
197 var
->green
.offset
= 5;
198 var
->blue
.offset
= 0;
200 var
->green
.length
= 6;
201 var
->blue
.length
= 5;
202 var
->transp
.length
= 0;
204 case GLAMO_LCD_SRC_ARGB1555
:
205 var
->transp
.offset
= 15;
206 var
->red
.offset
= 10;
207 var
->green
.offset
= 5;
208 var
->blue
.offset
= 0;
209 var
->transp
.length
= 1;
211 var
->green
.length
= 5;
212 var
->blue
.length
= 5;
214 case GLAMO_LCD_SRC_ARGB4444
:
215 var
->transp
.offset
= 12;
217 var
->green
.offset
= 4;
218 var
->blue
.offset
= 0;
219 var
->transp
.length
= 4;
221 var
->green
.length
= 4;
222 var
->blue
.length
= 4;
229 /* The Smedia Glamo doesn't support anything but 16bit color */
231 "Smedia driver does not [yet?] support 24/32bpp\n");
238 static void reg_set_bit_mask(struct glamofb_handle
*glamo
,
239 u_int16_t reg
, u_int16_t mask
,
246 tmp
= reg_read(glamo
, reg
);
249 reg_write(glamo
, reg
, tmp
);
252 #define GLAMO_LCD_WIDTH_MASK 0x03FF
253 #define GLAMO_LCD_HEIGHT_MASK 0x03FF
254 #define GLAMO_LCD_PITCH_MASK 0x07FE
255 #define GLAMO_LCD_HV_TOTAL_MASK 0x03FF
256 #define GLAMO_LCD_HV_RETR_START_MASK 0x03FF
257 #define GLAMO_LCD_HV_RETR_END_MASK 0x03FF
258 #define GLAMO_LCD_HV_RETR_DISP_START_MASK 0x03FF
259 #define GLAMO_LCD_HV_RETR_DISP_END_MASK 0x03FF
261 /* the caller has to enxure lock_cmd is held and we are in cmd mode */
262 static void __rotate_lcd(struct glamofb_handle
*glamo
, __u32 rotation
)
266 if (glamo
->core
->suspending
) {
267 dev_err(&glamo
->core
->pdev
->dev
,
268 "IGNORING rotate_lcd while "
275 glamo_rot
= GLAMO_LCD_ROT_MODE_90
;
278 glamo_rot
= GLAMO_LCD_ROT_MODE_180
;
281 glamo_rot
= GLAMO_LCD_ROT_MODE_270
;
284 glamo_rot
= GLAMO_LCD_ROT_MODE_0
;
288 reg_set_bit_mask(glamo
,
290 GLAMO_LCD_ROT_MODE_MASK
,
292 reg_set_bit_mask(glamo
,
294 GLAMO_LCD_MODE1_ROTATE_EN
,
295 (glamo_rot
!= GLAMO_LCD_ROT_MODE_0
) ?
296 GLAMO_LCD_MODE1_ROTATE_EN
: 0);
299 static void glamofb_program_mode(struct glamofb_handle
* gfb
) {
300 int sync
, bp
, disp
, fp
, total
;
302 struct glamo_core
*gcore
= gfb
->core
;
303 struct fb_var_screeninfo
*var
= &gfb
->fb
->var
;
305 dev_dbg(&gcore
->pdev
->dev
,
306 "glamofb_program_mode spin_lock_irqsave\n");
307 spin_lock_irqsave(&gfb
->lock_cmd
, flags
);
309 if (glamofb_cmd_mode(gfb
, 1))
313 glamo_engine_reclock(gcore
,
315 (1000000000UL / gfb
->fb
->var
.pixclock
) * 1000);
317 reg_set_bit_mask(gfb
,
319 GLAMO_LCD_WIDTH_MASK
,
321 reg_set_bit_mask(gfb
,
322 GLAMO_REG_LCD_HEIGHT
,
323 GLAMO_LCD_HEIGHT_MASK
,
325 reg_set_bit_mask(gfb
,
327 GLAMO_LCD_PITCH_MASK
,
328 gfb
->fb
->fix
.line_length
);
330 /* honour the rotation request */
331 __rotate_lcd(gfb
, var
->rotate
);
333 /* update scannout timings */
335 bp
= sync
+ var
->hsync_len
;
336 disp
= bp
+ var
->left_margin
;
337 fp
= disp
+ var
->xres
;
338 total
= fp
+ var
->right_margin
;
340 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_HORIZ_TOTAL
,
341 GLAMO_LCD_HV_TOTAL_MASK
, total
);
342 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_HORIZ_RETR_START
,
343 GLAMO_LCD_HV_RETR_START_MASK
, sync
);
344 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_HORIZ_RETR_END
,
345 GLAMO_LCD_HV_RETR_END_MASK
, bp
);
346 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_HORIZ_DISP_START
,
347 GLAMO_LCD_HV_RETR_DISP_START_MASK
, disp
);
348 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_HORIZ_DISP_END
,
349 GLAMO_LCD_HV_RETR_DISP_END_MASK
, fp
);
352 bp
= sync
+ var
->vsync_len
;
353 disp
= bp
+ var
->upper_margin
;
354 fp
= disp
+ var
->yres
;
355 total
= fp
+ var
->lower_margin
;
357 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_VERT_TOTAL
,
358 GLAMO_LCD_HV_TOTAL_MASK
, total
);
359 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_VERT_RETR_START
,
360 GLAMO_LCD_HV_RETR_START_MASK
, sync
);
361 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_VERT_RETR_END
,
362 GLAMO_LCD_HV_RETR_END_MASK
, bp
);
363 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_VERT_DISP_START
,
364 GLAMO_LCD_HV_RETR_DISP_START_MASK
, disp
);
365 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_VERT_DISP_END
,
366 GLAMO_LCD_HV_RETR_DISP_END_MASK
, fp
);
368 glamofb_cmd_mode(gfb
, 0);
373 dev_dbg(&gcore
->pdev
->dev
,
374 "glamofb_program_mode spin_unlock_irqrestore\n");
375 spin_unlock_irqrestore(&gfb
->lock_cmd
, flags
);
379 static int glamofb_pan_display(struct fb_var_screeninfo
*var
,
380 struct fb_info
*info
)
385 static struct fb_videomode
*glamofb_find_mode(struct fb_info
*info
,
386 struct fb_var_screeninfo
*var
) {
387 struct glamofb_handle
*glamo
= info
->par
;
388 struct glamo_fb_platform_data
*mach_info
= glamo
->mach_info
;
389 struct fb_videomode
*mode
;
392 for(i
= mach_info
->num_modes
, mode
= mach_info
->modes
; i
> 0; --i
, ++mode
) {
393 if (mode
->xres
== var
->xres
&&
394 mode
->yres
== var
->yres
)
401 static int glamofb_set_par(struct fb_info
*info
)
403 struct glamofb_handle
*glamo
= info
->par
;
404 struct fb_var_screeninfo
*var
= &info
->var
;
405 struct fb_videomode
*mode
;
407 if (glamo
->core
->suspending
) {
408 dev_err(&glamo
->core
->pdev
->dev
,
409 "IGNORING glamofb_set_par while "
414 mode
= glamofb_find_mode(info
, var
);
418 fb_videomode_to_var(var
, mode
);
424 switch(var
->rotate
) {
427 info
->fix
.line_length
= (var
->yres
* var
->bits_per_pixel
) / 8;
428 /* FIXME: Limit pixelclock */
432 info
->fix
.line_length
= (var
->xres
* var
->bits_per_pixel
) / 8;
436 if(glamo
->output_enabled
)
437 glamofb_program_mode(glamo
);
442 static int glamofb_blank(int blank_mode
, struct fb_info
*info
)
444 struct glamofb_handle
*gfb
= info
->par
;
446 dev_dbg(gfb
->dev
, "glamofb_blank(%u)\n", blank_mode
);
448 switch (blank_mode
) {
449 case FB_BLANK_VSYNC_SUSPEND
:
450 case FB_BLANK_HSYNC_SUSPEND
:
451 /* FIXME: add pdata hook/flag to indicate whether
452 * we should already switch off pixel clock here */
454 case FB_BLANK_POWERDOWN
:
455 /* disable the pixel clock */
456 glamo_output_disable(gfb
);
457 gfb
->blank_mode
= blank_mode
;
459 case FB_BLANK_UNBLANK
:
460 case FB_BLANK_NORMAL
:
461 glamo_output_enable(gfb
);
462 gfb
->blank_mode
= blank_mode
;
466 /* FIXME: once we have proper clock management in glamo-core,
467 * we can determine if other units need MCLK1 or the PLL, and
468 * disable it if not used. */
472 static inline unsigned int chan_to_field(unsigned int chan
,
473 struct fb_bitfield
*bf
)
476 chan
>>= 16 - bf
->length
;
477 return chan
<< bf
->offset
;
480 static int glamofb_setcolreg(unsigned regno
,
481 unsigned red
, unsigned green
, unsigned blue
,
482 unsigned transp
, struct fb_info
*info
)
484 struct glamofb_handle
*glamo
= info
->par
;
487 if (glamo
->core
->suspending
) {
488 dev_err(&glamo
->core
->pdev
->dev
,
489 "IGNORING glamofb_set_par while "
494 switch (glamo
->fb
->fix
.visual
) {
495 case FB_VISUAL_TRUECOLOR
:
496 case FB_VISUAL_DIRECTCOLOR
:
497 /* true-colour, use pseuo-palette */
500 u32
*pal
= glamo
->fb
->pseudo_palette
;
502 val
= chan_to_field(red
, &glamo
->fb
->var
.red
);
503 val
|= chan_to_field(green
, &glamo
->fb
->var
.green
);
504 val
|= chan_to_field(blue
, &glamo
->fb
->var
.blue
);
510 return 1; /* unknown type */
516 static int glamofb_ioctl(struct fb_info
*info
, unsigned int cmd
,
518 struct glamofb_handle
*gfb
= (struct glamofb_handle
*)info
->par
;
519 struct glamo_core
*gcore
= gfb
->core
;
520 int retval
= -ENOTTY
;
523 case GLAMOFB_ENGINE_ENABLE
:
524 retval
= glamo_engine_enable(gcore
, arg
);
526 case GLAMOFB_ENGINE_DISABLE
:
527 retval
= glamo_engine_disable(gcore
, arg
);
529 case GLAMOFB_ENGINE_RESET
:
530 glamo_engine_reset(gcore
, arg
);
541 #ifdef CONFIG_MFD_GLAMO_HWACCEL
542 static inline void glamofb_vsync_wait(struct glamofb_handle
*glamo
,
543 int line
, int size
, int range
)
548 count
[0] = reg_read(glamo
, GLAMO_REG_LCD_STATUS2
) & 0x3ff;
549 count
[1] = reg_read(glamo
, GLAMO_REG_LCD_STATUS2
) & 0x3ff;
550 } while (count
[0] != count
[1] ||
551 (line
< count
[0] + range
&&
552 size
> count
[0] - range
) ||
553 count
[0] < range
* 2);
557 * Enable/disable the hardware cursor mode altogether
558 * (for blinking and such, use glamofb_cursor()).
560 static void glamofb_cursor_onoff(struct glamofb_handle
*glamo
, int on
)
564 if (glamo
->cursor_on
) {
565 y
= reg_read(glamo
, GLAMO_REG_LCD_CURSOR_Y_POS
);
566 size
= reg_read(glamo
, GLAMO_REG_LCD_CURSOR_Y_SIZE
);
568 glamofb_vsync_wait(glamo
, y
, size
, 30);
571 reg_set_bit_mask(glamo
, GLAMO_REG_LCD_MODE1
,
572 GLAMO_LCD_MODE1_CURSOR_EN
,
573 on
? GLAMO_LCD_MODE1_CURSOR_EN
: 0);
574 glamo
->cursor_on
= on
;
576 /* Hide the cursor by default */
577 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_X_SIZE
, 0);
580 static int glamofb_cursor(struct fb_info
*info
, struct fb_cursor
*cursor
)
582 struct glamofb_handle
*glamo
= info
->par
;
585 spin_lock_irqsave(&glamo
->lock_cmd
, flags
);
587 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_X_SIZE
,
588 cursor
->enable
? cursor
->image
.width
: 0);
590 if (cursor
->set
& FB_CUR_SETPOS
) {
591 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_X_POS
,
593 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_Y_POS
,
597 if (cursor
->set
& FB_CUR_SETCMAP
) {
598 uint16_t fg
= glamo
->pseudo_pal
[cursor
->image
.fg_color
];
599 uint16_t bg
= glamo
->pseudo_pal
[cursor
->image
.bg_color
];
601 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_FG_COLOR
, fg
);
602 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_BG_COLOR
, bg
);
603 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_DST_COLOR
, fg
);
606 if (cursor
->set
& FB_CUR_SETHOT
)
607 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_PRESET
,
608 (cursor
->hot
.x
<< 8) | cursor
->hot
.y
);
610 if ((cursor
->set
& FB_CUR_SETSIZE
) ||
611 (cursor
->set
& (FB_CUR_SETIMAGE
| FB_CUR_SETSHAPE
))) {
613 const uint8_t *pcol
= cursor
->image
.data
;
614 const uint8_t *pmsk
= cursor
->mask
;
615 uint8_t __iomem
*dst
= glamo
->cursor_addr
;
620 if (cursor
->image
.depth
> 1) {
621 spin_unlock_irqrestore(&glamo
->lock_cmd
, flags
);
625 pitch
= ((cursor
->image
.width
+ 7) >> 2) & ~1;
626 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_PITCH
,
628 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_Y_SIZE
,
629 cursor
->image
.height
);
631 for (y
= 0; y
< cursor
->image
.height
; y
++) {
633 for (x
= 0; x
< cursor
->image
.width
; x
++) {
642 if (cursor
->rop
== ROP_COPY
)
644 (dcol
& 1) ? 1 : 3 : 0;
646 op
= ((dmsk
& 1) << 1) |
648 byte
|= op
<< ((x
& 3) << 1);
651 writeb(byte
, dst
+ x
/ 4);
656 writeb(byte
, dst
+ x
/ 4);
664 spin_unlock_irqrestore(&glamo
->lock_cmd
, flags
);
670 static inline int glamofb_cmdq_empty(struct glamofb_handle
*gfb
)
672 /* DGCMdQempty -- 1 == command queue is empty */
673 return reg_read(gfb
, GLAMO_REG_LCD_STATUS1
) & (1 << 15);
676 /* call holding gfb->lock_cmd when locking, until you unlock */
677 int glamofb_cmd_mode(struct glamofb_handle
*gfb
, int on
)
679 int timeout
= 2000000;
681 if (gfb
->core
->suspending
) {
682 dev_err(&gfb
->core
->pdev
->dev
,
683 "IGNORING glamofb_cmd_mode while "
688 dev_dbg(gfb
->dev
, "glamofb_cmd_mode(gfb=%p, on=%d)\n", gfb
, on
);
690 dev_dbg(gfb
->dev
, "%s: waiting for cmdq empty: ",
692 while ((!glamofb_cmdq_empty(gfb
)) && (timeout
--))
695 printk(KERN_ERR
"*************"
696 "glamofb cmd_queue never got empty"
700 dev_dbg(gfb
->dev
, "empty!\n");
702 /* display the entire frame then switch to command */
703 reg_write(gfb
, GLAMO_REG_LCD_COMMAND1
,
704 GLAMO_LCD_CMD_TYPE_DISP
|
705 GLAMO_LCD_CMD_DATA_FIRE_VSYNC
);
707 /* wait until lcd idle */
708 dev_dbg(gfb
->dev
, "waiting for lcd idle: ");
710 while ((!reg_read(gfb
, GLAMO_REG_LCD_STATUS2
) & (1 << 12)) &&
714 printk(KERN_ERR
"*************"
715 "glamofb lcd never idle"
722 dev_dbg(gfb
->dev
, "cmd mode entered\n");
725 /* RGB interface needs vsync/hsync */
726 if (reg_read(gfb
, GLAMO_REG_LCD_MODE3
) & GLAMO_LCD_MODE3_RGB
)
727 reg_write(gfb
, GLAMO_REG_LCD_COMMAND1
,
728 GLAMO_LCD_CMD_TYPE_DISP
|
729 GLAMO_LCD_CMD_DATA_DISP_SYNC
);
731 reg_write(gfb
, GLAMO_REG_LCD_COMMAND1
,
732 GLAMO_LCD_CMD_TYPE_DISP
|
733 GLAMO_LCD_CMD_DATA_DISP_FIRE
);
738 EXPORT_SYMBOL_GPL(glamofb_cmd_mode
);
741 int glamofb_cmd_write(struct glamofb_handle
*gfb
, u_int16_t val
)
743 int timeout
= 200000;
745 if (gfb
->core
->suspending
) {
746 dev_err(&gfb
->core
->pdev
->dev
,
747 "IGNORING glamofb_cmd_write while "
752 dev_dbg(gfb
->dev
, "%s: waiting for cmdq empty\n", __func__
);
753 while ((!glamofb_cmdq_empty(gfb
)) && (timeout
--))
756 printk(KERN_ERR
"*************"
757 "glamofb cmd_queue never got empty"
761 dev_dbg(gfb
->dev
, "idle, writing 0x%04x\n", val
);
763 reg_write(gfb
, GLAMO_REG_LCD_COMMAND1
, val
);
767 EXPORT_SYMBOL_GPL(glamofb_cmd_write
);
769 static struct fb_ops glamofb_ops
= {
770 .owner
= THIS_MODULE
,
771 .fb_check_var
= glamofb_check_var
,
772 .fb_pan_display
= glamofb_pan_display
,
773 .fb_set_par
= glamofb_set_par
,
774 .fb_blank
= glamofb_blank
,
775 .fb_setcolreg
= glamofb_setcolreg
,
776 .fb_ioctl
= glamofb_ioctl
,
777 #ifdef CONFIG_MFD_GLAMO_HWACCEL
778 .fb_cursor
= glamofb_cursor
,
780 .fb_fillrect
= cfb_fillrect
,
781 .fb_copyarea
= cfb_copyarea
,
782 .fb_imageblit
= cfb_imageblit
,
785 static int glamofb_init_regs(struct glamofb_handle
*glamo
)
787 struct fb_info
*info
= glamo
->fb
;
789 glamofb_check_var(&info
->var
, info
);
790 glamofb_run_script(glamo
, glamo_regs
, ARRAY_SIZE(glamo_regs
));
791 glamofb_set_par(info
);
796 static int __init
glamofb_probe(struct platform_device
*pdev
)
799 struct fb_info
*fbinfo
;
800 struct glamofb_handle
*glamofb
;
801 struct glamo_core
*core
= dev_get_drvdata(pdev
->dev
.parent
);
802 struct glamo_fb_platform_data
*mach_info
;
804 printk(KERN_INFO
"SMEDIA Glamo frame buffer driver (C) 2007 "
807 if (!core
->pdata
|| !core
->pdata
->fb_data
)
811 fbinfo
= framebuffer_alloc(sizeof(struct glamofb_handle
), &pdev
->dev
);
816 glamofb
= fbinfo
->par
;
817 glamofb
->fb
= fbinfo
;
818 glamofb
->dev
= &pdev
->dev
;
820 glamofb
->blank_mode
= FB_BLANK_POWERDOWN
;
822 strcpy(fbinfo
->fix
.id
, "SMedia Glamo");
824 glamofb
->reg
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
,
827 dev_err(&pdev
->dev
, "platform device with no registers?\n");
832 glamofb
->fb_res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
,
834 if (!glamofb
->fb_res
) {
835 dev_err(&pdev
->dev
, "platform device with no memory ?\n");
840 glamofb
->reg
= request_mem_region(glamofb
->reg
->start
,
841 resource_size(glamofb
->reg
), pdev
->name
);
843 dev_err(&pdev
->dev
, "failed to request mmio region\n");
847 glamofb
->fb_res
= request_mem_region(glamofb
->fb_res
->start
,
848 resource_size(glamofb
->fb_res
),
850 if (!glamofb
->fb_res
) {
851 dev_err(&pdev
->dev
, "failed to request vram region\n");
852 goto out_release_reg
;
855 /* we want to remap only the registers required for this core
857 glamofb
->base
= ioremap_nocache(glamofb
->reg
->start
, resource_size(glamofb
->reg
));
858 if (!glamofb
->base
) {
859 dev_err(&pdev
->dev
, "failed to ioremap() mmio memory\n");
863 fbinfo
->fix
.smem_start
= (unsigned long) glamofb
->fb_res
->start
;
864 fbinfo
->fix
.smem_len
= (__u32
) resource_size(glamofb
->fb_res
);
866 fbinfo
->screen_base
= ioremap(glamofb
->fb_res
->start
,
867 resource_size(glamofb
->fb_res
));
868 if (!fbinfo
->screen_base
) {
869 dev_err(&pdev
->dev
, "failed to ioremap() vram memory\n");
872 glamofb
->cursor_addr
= fbinfo
->screen_base
+ 0x12C000;
874 platform_set_drvdata(pdev
, glamofb
);
876 mach_info
= core
->pdata
->fb_data
;
877 glamofb
->core
= core
;
878 glamofb
->mach_info
= mach_info
;
880 fbinfo
->fix
.visual
= FB_VISUAL_TRUECOLOR
;
881 fbinfo
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
882 fbinfo
->fix
.type_aux
= 0;
883 fbinfo
->fix
.xpanstep
= 0;
884 fbinfo
->fix
.ypanstep
= 0;
885 fbinfo
->fix
.ywrapstep
= 0;
886 fbinfo
->fix
.accel
= FB_ACCEL_GLAMO
;
889 fbinfo
->fbops
= &glamofb_ops
;
890 fbinfo
->flags
= FBINFO_FLAG_DEFAULT
;
891 fbinfo
->pseudo_palette
= &glamofb
->pseudo_pal
;
893 fbinfo
->mode
= mach_info
->modes
;
894 fb_videomode_to_var(&fbinfo
->var
, fbinfo
->mode
);
895 fbinfo
->var
.bits_per_pixel
= 16;
896 fbinfo
->var
.nonstd
= 0;
897 fbinfo
->var
.activate
= FB_ACTIVATE_NOW
;
898 fbinfo
->var
.height
= mach_info
->height
;
899 fbinfo
->var
.width
= mach_info
->width
;
900 fbinfo
->var
.accel_flags
= 0;
901 fbinfo
->var
.vmode
= FB_VMODE_NONINTERLACED
;
903 glamo_engine_enable(core
, GLAMO_ENGINE_LCD
);
904 glamo_engine_reset(core
, GLAMO_ENGINE_LCD
);
905 glamofb
->output_enabled
= 1;
906 glamofb
->mode_set
= 1;
908 dev_info(&pdev
->dev
, "spin_lock_init\n");
909 spin_lock_init(&glamofb
->lock_cmd
);
910 glamofb_init_regs(glamofb
);
911 #ifdef CONFIG_MFD_GLAMO_HWACCEL
912 glamofb_cursor_onoff(glamofb
, 1);
915 fb_videomode_to_modelist(mach_info
->modes
, mach_info
->num_modes
,
918 rc
= register_framebuffer(fbinfo
);
920 dev_err(&pdev
->dev
, "failed to register framebuffer\n");
924 printk(KERN_INFO
"fb%d: %s frame buffer device\n",
925 fbinfo
->node
, fbinfo
->fix
.id
);
930 iounmap(fbinfo
->screen_base
);
931 iounmap(glamofb
->base
);
933 release_mem_region(glamofb
->fb_res
->start
, resource_size(glamofb
->fb_res
));
935 release_mem_region(glamofb
->reg
->start
, resource_size(glamofb
->reg
));
937 framebuffer_release(fbinfo
);
941 static int glamofb_remove(struct platform_device
*pdev
)
943 struct glamofb_handle
*glamofb
= platform_get_drvdata(pdev
);
945 platform_set_drvdata(pdev
, NULL
);
946 iounmap(glamofb
->base
);
947 release_mem_region(glamofb
->reg
->start
, resource_size(glamofb
->reg
));
955 static int glamofb_suspend(struct device
*dev
)
957 struct glamofb_handle
*gfb
= dev_get_drvdata(dev
);
959 /* we need to stop anything touching our framebuffer */
960 fb_set_suspend(gfb
->fb
, 1);
962 /* seriously -- nobody is allowed to touch glamo memory when we
963 * are suspended or we lock on nWAIT
965 /* iounmap(gfb->fb->screen_base); */
970 static int glamofb_resume(struct device
*dev
)
972 struct glamofb_handle
*gfb
= dev_get_drvdata(dev
);
974 /* OK let's allow framebuffer ops again */
975 /* gfb->fb->screen_base = ioremap(gfb->fb_res->start,
976 resource_size(gfb->fb_res)); */
977 glamo_engine_enable(gfb
->core
, GLAMO_ENGINE_LCD
);
978 glamo_engine_reset(gfb
->core
, GLAMO_ENGINE_LCD
);
980 glamofb_init_regs(gfb
);
981 #ifdef CONFIG_MFD_GLAMO_HWACCEL
982 glamofb_cursor_onoff(gfb
, 1);
985 fb_set_suspend(gfb
->fb
, 0);
990 static struct dev_pm_ops glamofb_pm_ops
= {
991 .suspend
= glamofb_suspend
,
992 .resume
= glamofb_resume
,
995 #define GLAMOFB_PM_OPS (&glamofb_pm_ops)
998 #define GLAMOFB_PM_OPS NULL
1001 static struct platform_driver glamofb_driver
= {
1002 .probe
= glamofb_probe
,
1003 .remove
= glamofb_remove
,
1006 .owner
= THIS_MODULE
,
1007 .pm
= GLAMOFB_PM_OPS
1011 static int __devinit
glamofb_init(void)
1013 return platform_driver_register(&glamofb_driver
);
1016 static void __exit
glamofb_cleanup(void)
1018 platform_driver_unregister(&glamofb_driver
);
1021 module_init(glamofb_init
);
1022 module_exit(glamofb_cleanup
);
1024 MODULE_AUTHOR("Harald Welte <laforge@openmoko.org>");
1025 MODULE_DESCRIPTION("Smedia Glamo 336x/337x framebuffer driver");
1026 MODULE_LICENSE("GPL");