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/console.h>
30 #include <linux/init.h>
31 #include <linux/platform_device.h>
32 #include <linux/spinlock.h>
34 #include <linux/mfd/glamo.h>
36 #include <asm/div64.h>
42 #include <linux/glamofb.h>
44 #include "glamo-regs.h"
45 #include "glamo-core.h"
47 static void glamofb_program_mode(struct glamofb_handle
* glamo
);
49 struct glamofb_handle
{
50 struct glamo_core
*core
;
54 struct resource
*fb_res
;
56 struct glamo_fb_platform_data
*mach_info
;
57 char __iomem
*cursor_addr
;
59 u_int32_t pseudo_pal
[16];
62 int mode_set
; /* 0 if the current display mode hasn't been set on the glamo */
63 int output_enabled
; /* 0 if the video output is disabled */
66 static void glamo_output_enable(struct glamofb_handle
*gfb
) {
67 struct glamo_core
*gcore
= gfb
->core
;
69 if (gfb
->output_enabled
)
72 /* enable the pixel clock if off */
73 glamo_engine_enable(gcore
, GLAMO_ENGINE_LCD
);
75 gfb
->output_enabled
= 1;
77 glamofb_program_mode(gfb
);
80 static void glamo_output_disable(struct glamofb_handle
*gfb
) {
81 struct glamo_core
*gcore
= gfb
->core
;
83 if (!gfb
->output_enabled
)
86 /* enable the pixel clock if off */
87 glamo_engine_suspend(gcore
, GLAMO_ENGINE_LCD
);
89 gfb
->output_enabled
= 0;
93 static int reg_read(struct glamofb_handle
*glamo
,
98 for (i
= 0; i
!= 2; i
++)
101 return readw(glamo
->base
+ reg
);
104 static void reg_write(struct glamofb_handle
*glamo
,
105 u_int16_t reg
, u_int16_t val
)
109 for (i
= 0; i
!= 2; i
++)
112 writew(val
, glamo
->base
+ reg
);
115 static struct glamo_script glamo_regs
[] = {
116 { GLAMO_REG_LCD_MODE1
, 0x0020 },
117 /* no display rotation, no hardware cursor, no dither, no gamma,
118 * no retrace flip, vsync low-active, hsync low active,
119 * no TVCLK, no partial display, hw dest color from fb,
120 * no partial display mode, LCD1, software flip, */
121 { GLAMO_REG_LCD_MODE2
, 0x9020 },
122 /* video flip, no ptr, no ptr, dhclk off,
123 * normal mode, no cpuif,
124 * res, serial msb first, single fb, no fr ctrl,
125 * cpu if bits all zero, no crc
126 * 0000 0000 0010 0000 */
127 { GLAMO_REG_LCD_MODE3
, 0x0b40 },
128 /* src data rgb565, res, 18bit rgb666
129 * 000 01 011 0100 0000 */
130 { GLAMO_REG_LCD_POLARITY
, 0x440c },
131 /* DE high active, no cpu/lcd if, cs0 force low, a0 low active,
132 * np cpu if, 9bit serial data, sclk rising edge latch data
133 * 01 00 0 100 0 000 01 0 0 */
134 /* The following values assume 640*480@16bpp */
135 { GLAMO_REG_LCD_A_BASE1
, 0x0000 }, /* display A base address 15:0 */
136 { GLAMO_REG_LCD_A_BASE2
, 0x0000 }, /* display A base address 22:16 */
137 { GLAMO_REG_LCD_CURSOR_BASE1
, 0xC000 }, /* cursor base address 15:0 */
138 { GLAMO_REG_LCD_CURSOR_BASE2
, 0x0012 }, /* cursor base address 22:16 */
139 { GLAMO_REG_LCD_COMMAND2
, 0x0000 }, /* display page A */
142 static int glamofb_run_script(struct glamofb_handle
*glamo
,
143 struct glamo_script
*script
, int len
)
147 for (i
= 0; i
< len
; i
++) {
148 struct glamo_script
*line
= &script
[i
];
150 if (line
->reg
== 0xffff)
152 else if (line
->reg
== 0xfffe)
155 reg_write(glamo
, script
[i
].reg
, script
[i
].val
);
161 static int glamofb_check_var(struct fb_var_screeninfo
*var
,
162 struct fb_info
*info
)
164 struct glamofb_handle
*glamo
= info
->par
;
166 if (var
->bits_per_pixel
!= 16)
167 var
->bits_per_pixel
= 16;
169 var
->height
= glamo
->mach_info
->height
;
170 var
->width
= glamo
->mach_info
->width
;
172 /* FIXME: set rgb positions */
173 switch (var
->bits_per_pixel
) {
175 switch (reg_read(glamo
, GLAMO_REG_LCD_MODE3
) & 0xc000) {
176 case GLAMO_LCD_SRC_RGB565
:
177 var
->red
.offset
= 11;
178 var
->green
.offset
= 5;
179 var
->blue
.offset
= 0;
181 var
->green
.length
= 6;
182 var
->blue
.length
= 5;
183 var
->transp
.length
= 0;
185 case GLAMO_LCD_SRC_ARGB1555
:
186 var
->transp
.offset
= 15;
187 var
->red
.offset
= 10;
188 var
->green
.offset
= 5;
189 var
->blue
.offset
= 0;
190 var
->transp
.length
= 1;
192 var
->green
.length
= 5;
193 var
->blue
.length
= 5;
195 case GLAMO_LCD_SRC_ARGB4444
:
196 var
->transp
.offset
= 12;
198 var
->green
.offset
= 4;
199 var
->blue
.offset
= 0;
200 var
->transp
.length
= 4;
202 var
->green
.length
= 4;
203 var
->blue
.length
= 4;
210 /* The Smedia Glamo doesn't support anything but 16bit color */
212 "Smedia driver does not [yet?] support 24/32bpp\n");
219 static void reg_set_bit_mask(struct glamofb_handle
*glamo
,
220 u_int16_t reg
, u_int16_t mask
,
227 tmp
= reg_read(glamo
, reg
);
230 reg_write(glamo
, reg
, tmp
);
233 #define GLAMO_LCD_WIDTH_MASK 0x03FF
234 #define GLAMO_LCD_HEIGHT_MASK 0x03FF
235 #define GLAMO_LCD_PITCH_MASK 0x07FE
236 #define GLAMO_LCD_HV_TOTAL_MASK 0x03FF
237 #define GLAMO_LCD_HV_RETR_START_MASK 0x03FF
238 #define GLAMO_LCD_HV_RETR_END_MASK 0x03FF
239 #define GLAMO_LCD_HV_RETR_DISP_START_MASK 0x03FF
240 #define GLAMO_LCD_HV_RETR_DISP_END_MASK 0x03FF
242 /* the caller has to enxure lock_cmd is held and we are in cmd mode */
243 static void __rotate_lcd(struct glamofb_handle
*glamo
, __u32 rotation
)
249 glamo_rot
= GLAMO_LCD_ROT_MODE_90
;
252 glamo_rot
= GLAMO_LCD_ROT_MODE_180
;
255 glamo_rot
= GLAMO_LCD_ROT_MODE_270
;
258 glamo_rot
= GLAMO_LCD_ROT_MODE_0
;
262 reg_set_bit_mask(glamo
,
264 GLAMO_LCD_ROT_MODE_MASK
,
266 reg_set_bit_mask(glamo
,
268 GLAMO_LCD_MODE1_ROTATE_EN
,
269 (glamo_rot
!= GLAMO_LCD_ROT_MODE_0
) ?
270 GLAMO_LCD_MODE1_ROTATE_EN
: 0);
273 static void glamofb_program_mode(struct glamofb_handle
* gfb
) {
274 int sync
, bp
, disp
, fp
, total
;
276 struct glamo_core
*gcore
= gfb
->core
;
277 struct fb_var_screeninfo
*var
= &gfb
->fb
->var
;
279 dev_dbg(&gcore
->pdev
->dev
,
280 "glamofb_program_mode spin_lock_irqsave\n");
281 spin_lock_irqsave(&gfb
->lock_cmd
, flags
);
283 if (glamofb_cmd_mode(gfb
, 1))
287 glamo_engine_reclock(gcore
,
289 (1000000000UL / gfb
->fb
->var
.pixclock
) * 1000);
291 reg_set_bit_mask(gfb
,
293 GLAMO_LCD_WIDTH_MASK
,
295 reg_set_bit_mask(gfb
,
296 GLAMO_REG_LCD_HEIGHT
,
297 GLAMO_LCD_HEIGHT_MASK
,
299 reg_set_bit_mask(gfb
,
301 GLAMO_LCD_PITCH_MASK
,
302 gfb
->fb
->fix
.line_length
);
304 /* honour the rotation request */
305 __rotate_lcd(gfb
, var
->rotate
);
307 /* update scannout timings */
309 bp
= sync
+ var
->hsync_len
;
310 disp
= bp
+ var
->left_margin
;
311 fp
= disp
+ var
->xres
;
312 total
= fp
+ var
->right_margin
;
314 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_HORIZ_TOTAL
,
315 GLAMO_LCD_HV_TOTAL_MASK
, total
);
316 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_HORIZ_RETR_START
,
317 GLAMO_LCD_HV_RETR_START_MASK
, sync
);
318 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_HORIZ_RETR_END
,
319 GLAMO_LCD_HV_RETR_END_MASK
, bp
);
320 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_HORIZ_DISP_START
,
321 GLAMO_LCD_HV_RETR_DISP_START_MASK
, disp
);
322 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_HORIZ_DISP_END
,
323 GLAMO_LCD_HV_RETR_DISP_END_MASK
, fp
);
326 bp
= sync
+ var
->vsync_len
;
327 disp
= bp
+ var
->upper_margin
;
328 fp
= disp
+ var
->yres
;
329 total
= fp
+ var
->lower_margin
;
331 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_VERT_TOTAL
,
332 GLAMO_LCD_HV_TOTAL_MASK
, total
);
333 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_VERT_RETR_START
,
334 GLAMO_LCD_HV_RETR_START_MASK
, sync
);
335 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_VERT_RETR_END
,
336 GLAMO_LCD_HV_RETR_END_MASK
, bp
);
337 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_VERT_DISP_START
,
338 GLAMO_LCD_HV_RETR_DISP_START_MASK
, disp
);
339 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_VERT_DISP_END
,
340 GLAMO_LCD_HV_RETR_DISP_END_MASK
, fp
);
342 glamofb_cmd_mode(gfb
, 0);
347 dev_dbg(&gcore
->pdev
->dev
,
348 "glamofb_program_mode spin_unlock_irqrestore\n");
349 spin_unlock_irqrestore(&gfb
->lock_cmd
, flags
);
353 static int glamofb_pan_display(struct fb_var_screeninfo
*var
,
354 struct fb_info
*info
)
359 static struct fb_videomode
*glamofb_find_mode(struct fb_info
*info
,
360 struct fb_var_screeninfo
*var
) {
361 struct glamofb_handle
*glamo
= info
->par
;
362 struct glamo_fb_platform_data
*mach_info
= glamo
->mach_info
;
363 struct fb_videomode
*mode
;
366 for(i
= mach_info
->num_modes
, mode
= mach_info
->modes
; i
> 0; --i
, ++mode
) {
367 if (mode
->xres
== var
->xres
&&
368 mode
->yres
== var
->yres
)
375 static int glamofb_set_par(struct fb_info
*info
)
377 struct glamofb_handle
*glamo
= info
->par
;
378 struct fb_var_screeninfo
*var
= &info
->var
;
379 struct fb_videomode
*mode
;
381 mode
= glamofb_find_mode(info
, var
);
385 fb_videomode_to_var(var
, mode
);
391 switch(var
->rotate
) {
394 info
->fix
.line_length
= (var
->yres
* var
->bits_per_pixel
) / 8;
395 /* FIXME: Limit pixelclock */
399 info
->fix
.line_length
= (var
->xres
* var
->bits_per_pixel
) / 8;
403 if(glamo
->output_enabled
)
404 glamofb_program_mode(glamo
);
409 static int glamofb_blank(int blank_mode
, struct fb_info
*info
)
411 struct glamofb_handle
*gfb
= info
->par
;
413 dev_dbg(gfb
->dev
, "glamofb_blank(%u)\n", blank_mode
);
415 switch (blank_mode
) {
416 case FB_BLANK_VSYNC_SUSPEND
:
417 case FB_BLANK_HSYNC_SUSPEND
:
418 /* FIXME: add pdata hook/flag to indicate whether
419 * we should already switch off pixel clock here */
421 case FB_BLANK_POWERDOWN
:
422 /* disable the pixel clock */
423 glamo_output_disable(gfb
);
424 gfb
->blank_mode
= blank_mode
;
426 case FB_BLANK_UNBLANK
:
427 case FB_BLANK_NORMAL
:
428 glamo_output_enable(gfb
);
429 gfb
->blank_mode
= blank_mode
;
433 /* FIXME: once we have proper clock management in glamo-core,
434 * we can determine if other units need MCLK1 or the PLL, and
435 * disable it if not used. */
439 static inline unsigned int chan_to_field(unsigned int chan
,
440 struct fb_bitfield
*bf
)
443 chan
>>= 16 - bf
->length
;
444 return chan
<< bf
->offset
;
447 static int glamofb_setcolreg(unsigned regno
,
448 unsigned red
, unsigned green
, unsigned blue
,
449 unsigned transp
, struct fb_info
*info
)
451 struct glamofb_handle
*glamo
= info
->par
;
454 switch (glamo
->fb
->fix
.visual
) {
455 case FB_VISUAL_TRUECOLOR
:
456 case FB_VISUAL_DIRECTCOLOR
:
457 /* true-colour, use pseuo-palette */
460 u32
*pal
= glamo
->fb
->pseudo_palette
;
462 val
= chan_to_field(red
, &glamo
->fb
->var
.red
);
463 val
|= chan_to_field(green
, &glamo
->fb
->var
.green
);
464 val
|= chan_to_field(blue
, &glamo
->fb
->var
.blue
);
470 return 1; /* unknown type */
476 static int glamofb_ioctl(struct fb_info
*info
, unsigned int cmd
,
478 struct glamofb_handle
*gfb
= (struct glamofb_handle
*)info
->par
;
479 struct glamo_core
*gcore
= gfb
->core
;
480 int retval
= -ENOTTY
;
483 case GLAMOFB_ENGINE_ENABLE
:
484 retval
= glamo_engine_enable(gcore
, arg
);
486 case GLAMOFB_ENGINE_DISABLE
:
487 retval
= glamo_engine_disable(gcore
, arg
);
489 case GLAMOFB_ENGINE_RESET
:
490 glamo_engine_reset(gcore
, arg
);
501 #ifdef CONFIG_MFD_GLAMO_HWACCEL
502 static inline void glamofb_vsync_wait(struct glamofb_handle
*glamo
,
503 int line
, int size
, int range
)
508 count
[0] = reg_read(glamo
, GLAMO_REG_LCD_STATUS2
) & 0x3ff;
509 count
[1] = reg_read(glamo
, GLAMO_REG_LCD_STATUS2
) & 0x3ff;
510 } while (count
[0] != count
[1] ||
511 (line
< count
[0] + range
&&
512 size
> count
[0] - range
) ||
513 count
[0] < range
* 2);
517 * Enable/disable the hardware cursor mode altogether
518 * (for blinking and such, use glamofb_cursor()).
520 static void glamofb_cursor_onoff(struct glamofb_handle
*glamo
, int on
)
524 if (glamo
->cursor_on
) {
525 y
= reg_read(glamo
, GLAMO_REG_LCD_CURSOR_Y_POS
);
526 size
= reg_read(glamo
, GLAMO_REG_LCD_CURSOR_Y_SIZE
);
528 glamofb_vsync_wait(glamo
, y
, size
, 30);
531 reg_set_bit_mask(glamo
, GLAMO_REG_LCD_MODE1
,
532 GLAMO_LCD_MODE1_CURSOR_EN
,
533 on
? GLAMO_LCD_MODE1_CURSOR_EN
: 0);
534 glamo
->cursor_on
= on
;
536 /* Hide the cursor by default */
537 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_X_SIZE
, 0);
540 static int glamofb_cursor(struct fb_info
*info
, struct fb_cursor
*cursor
)
542 struct glamofb_handle
*glamo
= info
->par
;
545 spin_lock_irqsave(&glamo
->lock_cmd
, flags
);
547 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_X_SIZE
,
548 cursor
->enable
? cursor
->image
.width
: 0);
550 if (cursor
->set
& FB_CUR_SETPOS
) {
551 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_X_POS
,
553 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_Y_POS
,
557 if (cursor
->set
& FB_CUR_SETCMAP
) {
558 uint16_t fg
= glamo
->pseudo_pal
[cursor
->image
.fg_color
];
559 uint16_t bg
= glamo
->pseudo_pal
[cursor
->image
.bg_color
];
561 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_FG_COLOR
, fg
);
562 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_BG_COLOR
, bg
);
563 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_DST_COLOR
, fg
);
566 if (cursor
->set
& FB_CUR_SETHOT
)
567 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_PRESET
,
568 (cursor
->hot
.x
<< 8) | cursor
->hot
.y
);
570 if ((cursor
->set
& FB_CUR_SETSIZE
) ||
571 (cursor
->set
& (FB_CUR_SETIMAGE
| FB_CUR_SETSHAPE
))) {
573 const uint8_t *pcol
= cursor
->image
.data
;
574 const uint8_t *pmsk
= cursor
->mask
;
575 uint8_t __iomem
*dst
= glamo
->cursor_addr
;
580 if (cursor
->image
.depth
> 1) {
581 spin_unlock_irqrestore(&glamo
->lock_cmd
, flags
);
585 pitch
= ((cursor
->image
.width
+ 7) >> 2) & ~1;
586 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_PITCH
,
588 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_Y_SIZE
,
589 cursor
->image
.height
);
591 for (y
= 0; y
< cursor
->image
.height
; y
++) {
593 for (x
= 0; x
< cursor
->image
.width
; x
++) {
602 if (cursor
->rop
== ROP_COPY
)
604 (dcol
& 1) ? 1 : 3 : 0;
606 op
= ((dmsk
& 1) << 1) |
608 byte
|= op
<< ((x
& 3) << 1);
611 writeb(byte
, dst
+ x
/ 4);
616 writeb(byte
, dst
+ x
/ 4);
624 spin_unlock_irqrestore(&glamo
->lock_cmd
, flags
);
630 static inline int glamofb_cmdq_empty(struct glamofb_handle
*gfb
)
632 /* DGCMdQempty -- 1 == command queue is empty */
633 return reg_read(gfb
, GLAMO_REG_LCD_STATUS1
) & (1 << 15);
636 /* call holding gfb->lock_cmd when locking, until you unlock */
637 int glamofb_cmd_mode(struct glamofb_handle
*gfb
, int on
)
639 int timeout
= 2000000;
641 dev_dbg(gfb
->dev
, "glamofb_cmd_mode(gfb=%p, on=%d)\n", gfb
, on
);
643 dev_dbg(gfb
->dev
, "%s: waiting for cmdq empty: ",
645 while ((!glamofb_cmdq_empty(gfb
)) && (timeout
--))
648 printk(KERN_ERR
"*************"
649 "glamofb cmd_queue never got empty"
653 dev_dbg(gfb
->dev
, "empty!\n");
655 /* display the entire frame then switch to command */
656 reg_write(gfb
, GLAMO_REG_LCD_COMMAND1
,
657 GLAMO_LCD_CMD_TYPE_DISP
|
658 GLAMO_LCD_CMD_DATA_FIRE_VSYNC
);
660 /* wait until lcd idle */
661 dev_dbg(gfb
->dev
, "waiting for lcd idle: ");
663 while ((!reg_read(gfb
, GLAMO_REG_LCD_STATUS2
) & (1 << 12)) &&
667 printk(KERN_ERR
"*************"
668 "glamofb lcd never idle"
675 dev_dbg(gfb
->dev
, "cmd mode entered\n");
678 /* RGB interface needs vsync/hsync */
679 if (reg_read(gfb
, GLAMO_REG_LCD_MODE3
) & GLAMO_LCD_MODE3_RGB
)
680 reg_write(gfb
, GLAMO_REG_LCD_COMMAND1
,
681 GLAMO_LCD_CMD_TYPE_DISP
|
682 GLAMO_LCD_CMD_DATA_DISP_SYNC
);
684 reg_write(gfb
, GLAMO_REG_LCD_COMMAND1
,
685 GLAMO_LCD_CMD_TYPE_DISP
|
686 GLAMO_LCD_CMD_DATA_DISP_FIRE
);
691 EXPORT_SYMBOL_GPL(glamofb_cmd_mode
);
694 int glamofb_cmd_write(struct glamofb_handle
*gfb
, u_int16_t val
)
696 int timeout
= 200000;
698 dev_dbg(gfb
->dev
, "%s: waiting for cmdq empty\n", __func__
);
699 while ((!glamofb_cmdq_empty(gfb
)) && (timeout
--))
702 printk(KERN_ERR
"*************"
703 "glamofb cmd_queue never got empty"
707 dev_dbg(gfb
->dev
, "idle, writing 0x%04x\n", val
);
709 reg_write(gfb
, GLAMO_REG_LCD_COMMAND1
, val
);
713 EXPORT_SYMBOL_GPL(glamofb_cmd_write
);
715 static struct fb_ops glamofb_ops
= {
716 .owner
= THIS_MODULE
,
717 .fb_check_var
= glamofb_check_var
,
718 .fb_pan_display
= glamofb_pan_display
,
719 .fb_set_par
= glamofb_set_par
,
720 .fb_blank
= glamofb_blank
,
721 .fb_setcolreg
= glamofb_setcolreg
,
722 .fb_ioctl
= glamofb_ioctl
,
723 #ifdef CONFIG_MFD_GLAMO_HWACCEL
724 .fb_cursor
= glamofb_cursor
,
726 .fb_fillrect
= cfb_fillrect
,
727 .fb_copyarea
= cfb_copyarea
,
728 .fb_imageblit
= cfb_imageblit
,
731 static int glamofb_init_regs(struct glamofb_handle
*glamo
)
733 struct fb_info
*info
= glamo
->fb
;
735 glamofb_check_var(&info
->var
, info
);
736 glamofb_run_script(glamo
, glamo_regs
, ARRAY_SIZE(glamo_regs
));
737 glamofb_set_par(info
);
742 static int __init
glamofb_probe(struct platform_device
*pdev
)
745 struct fb_info
*fbinfo
;
746 struct glamofb_handle
*glamofb
;
747 struct glamo_core
*core
= dev_get_drvdata(pdev
->dev
.parent
);
748 struct glamo_fb_platform_data
*mach_info
;
750 printk(KERN_INFO
"SMEDIA Glamo frame buffer driver (C) 2007 "
753 if (!core
->pdata
|| !core
->pdata
->fb_data
)
757 fbinfo
= framebuffer_alloc(sizeof(struct glamofb_handle
), &pdev
->dev
);
762 glamofb
= fbinfo
->par
;
763 glamofb
->fb
= fbinfo
;
764 glamofb
->dev
= &pdev
->dev
;
766 glamofb
->blank_mode
= FB_BLANK_POWERDOWN
;
768 strcpy(fbinfo
->fix
.id
, "SMedia Glamo");
770 glamofb
->reg
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
,
773 dev_err(&pdev
->dev
, "platform device with no registers?\n");
778 glamofb
->fb_res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
,
780 if (!glamofb
->fb_res
) {
781 dev_err(&pdev
->dev
, "platform device with no memory ?\n");
786 glamofb
->reg
= request_mem_region(glamofb
->reg
->start
,
787 resource_size(glamofb
->reg
), pdev
->name
);
789 dev_err(&pdev
->dev
, "failed to request mmio region\n");
793 glamofb
->fb_res
= request_mem_region(glamofb
->fb_res
->start
,
794 resource_size(glamofb
->fb_res
),
796 if (!glamofb
->fb_res
) {
797 dev_err(&pdev
->dev
, "failed to request vram region\n");
798 goto out_release_reg
;
801 /* we want to remap only the registers required for this core
803 glamofb
->base
= ioremap_nocache(glamofb
->reg
->start
, resource_size(glamofb
->reg
));
804 if (!glamofb
->base
) {
805 dev_err(&pdev
->dev
, "failed to ioremap() mmio memory\n");
809 fbinfo
->fix
.smem_start
= (unsigned long) glamofb
->fb_res
->start
;
810 fbinfo
->fix
.smem_len
= (__u32
) resource_size(glamofb
->fb_res
);
812 fbinfo
->screen_base
= ioremap(glamofb
->fb_res
->start
,
813 resource_size(glamofb
->fb_res
));
814 if (!fbinfo
->screen_base
) {
815 dev_err(&pdev
->dev
, "failed to ioremap() vram memory\n");
818 glamofb
->cursor_addr
= fbinfo
->screen_base
+ 0x12C000;
820 platform_set_drvdata(pdev
, glamofb
);
822 mach_info
= core
->pdata
->fb_data
;
823 glamofb
->core
= core
;
824 glamofb
->mach_info
= mach_info
;
826 fbinfo
->fix
.visual
= FB_VISUAL_TRUECOLOR
;
827 fbinfo
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
828 fbinfo
->fix
.type_aux
= 0;
829 fbinfo
->fix
.xpanstep
= 0;
830 fbinfo
->fix
.ypanstep
= 0;
831 fbinfo
->fix
.ywrapstep
= 0;
832 fbinfo
->fix
.accel
= FB_ACCEL_GLAMO
;
835 fbinfo
->fbops
= &glamofb_ops
;
836 fbinfo
->flags
= FBINFO_FLAG_DEFAULT
;
837 fbinfo
->pseudo_palette
= &glamofb
->pseudo_pal
;
839 fbinfo
->mode
= mach_info
->modes
;
840 fb_videomode_to_var(&fbinfo
->var
, fbinfo
->mode
);
841 fbinfo
->var
.bits_per_pixel
= 16;
842 fbinfo
->var
.nonstd
= 0;
843 fbinfo
->var
.activate
= FB_ACTIVATE_NOW
;
844 fbinfo
->var
.height
= mach_info
->height
;
845 fbinfo
->var
.width
= mach_info
->width
;
846 fbinfo
->var
.accel_flags
= 0;
847 fbinfo
->var
.vmode
= FB_VMODE_NONINTERLACED
;
849 glamo_engine_enable(core
, GLAMO_ENGINE_LCD
);
850 glamo_engine_reset(core
, GLAMO_ENGINE_LCD
);
851 glamofb
->output_enabled
= 1;
852 glamofb
->mode_set
= 1;
854 dev_info(&pdev
->dev
, "spin_lock_init\n");
855 spin_lock_init(&glamofb
->lock_cmd
);
856 glamofb_init_regs(glamofb
);
857 #ifdef CONFIG_MFD_GLAMO_HWACCEL
858 glamofb_cursor_onoff(glamofb
, 1);
861 fb_videomode_to_modelist(mach_info
->modes
, mach_info
->num_modes
,
864 rc
= register_framebuffer(fbinfo
);
866 dev_err(&pdev
->dev
, "failed to register framebuffer\n");
870 printk(KERN_INFO
"fb%d: %s frame buffer device\n",
871 fbinfo
->node
, fbinfo
->fix
.id
);
876 iounmap(fbinfo
->screen_base
);
877 iounmap(glamofb
->base
);
879 release_mem_region(glamofb
->fb_res
->start
, resource_size(glamofb
->fb_res
));
881 release_mem_region(glamofb
->reg
->start
, resource_size(glamofb
->reg
));
883 framebuffer_release(fbinfo
);
887 static int glamofb_remove(struct platform_device
*pdev
)
889 struct glamofb_handle
*glamofb
= platform_get_drvdata(pdev
);
891 platform_set_drvdata(pdev
, NULL
);
892 iounmap(glamofb
->base
);
893 release_mem_region(glamofb
->reg
->start
, resource_size(glamofb
->reg
));
901 static int glamofb_suspend(struct device
*dev
)
903 struct glamofb_handle
*gfb
= dev_get_drvdata(dev
);
905 acquire_console_sem();
906 fb_set_suspend(gfb
->fb
, 1);
907 release_console_sem();
909 /* seriously -- nobody is allowed to touch glamo memory when we
910 * are suspended or we lock on nWAIT
912 /* iounmap(gfb->fb->screen_base); */
917 static int glamofb_resume(struct device
*dev
)
919 struct glamofb_handle
*gfb
= dev_get_drvdata(dev
);
921 /* OK let's allow framebuffer ops again */
922 /* gfb->fb->screen_base = ioremap(gfb->fb_res->start,
923 resource_size(gfb->fb_res)); */
924 glamo_engine_enable(gfb
->core
, GLAMO_ENGINE_LCD
);
925 glamo_engine_reset(gfb
->core
, GLAMO_ENGINE_LCD
);
927 glamofb_init_regs(gfb
);
928 #ifdef CONFIG_MFD_GLAMO_HWACCEL
929 glamofb_cursor_onoff(gfb
, 1);
932 acquire_console_sem();
933 fb_set_suspend(gfb
->fb
, 0);
934 release_console_sem();
939 static struct dev_pm_ops glamofb_pm_ops
= {
940 .suspend
= glamofb_suspend
,
941 .resume
= glamofb_resume
,
944 #define GLAMOFB_PM_OPS (&glamofb_pm_ops)
947 #define GLAMOFB_PM_OPS NULL
950 static struct platform_driver glamofb_driver
= {
951 .probe
= glamofb_probe
,
952 .remove
= glamofb_remove
,
955 .owner
= THIS_MODULE
,
960 static int __devinit
glamofb_init(void)
962 return platform_driver_register(&glamofb_driver
);
965 static void __exit
glamofb_cleanup(void)
967 platform_driver_unregister(&glamofb_driver
);
970 module_init(glamofb_init
);
971 module_exit(glamofb_cleanup
);
973 MODULE_AUTHOR("Harald Welte <laforge@openmoko.org>");
974 MODULE_DESCRIPTION("Smedia Glamo 336x/337x framebuffer driver");
975 MODULE_LICENSE("GPL");