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"
47 #define GLAMO_LOG(...)
49 #define GLAMO_LOG(...) \
51 printk(KERN_DEBUG "in %s:%s:%d", __FILE__, __func__, __LINE__); \
52 printk(KERN_DEBUG __VA_ARGS__); \
56 static void glamofb_program_mode(struct glamofb_handle
* glamo
);
58 struct glamofb_handle
{
62 struct resource
*fb_res
;
64 struct glamo_fb_platform_data
*mach_info
;
65 char __iomem
*cursor_addr
;
67 u_int32_t pseudo_pal
[16];
70 int mode_set
; /* 0 if the current display mode hasn't been set on the glamo */
71 int output_enabled
; /* 0 if the video output is disabled */
74 static void glamo_output_enable(struct glamofb_handle
*gfb
) {
75 struct glamo_core
*gcore
= gfb
->mach_info
->core
;
77 if (gfb
->output_enabled
)
80 /* enable the pixel clock if off */
81 glamo_engine_clkreg_set(gcore
,
83 GLAMO_CLOCK_LCD_EN_DCLK
,
84 GLAMO_CLOCK_LCD_EN_DCLK
);
86 gfb
->output_enabled
= 1;
88 glamofb_program_mode(gfb
);
91 static void glamo_output_disable(struct glamofb_handle
*gfb
) {
92 struct glamo_core
*gcore
= gfb
->mach_info
->core
;
94 if (!gfb
->output_enabled
)
97 /* enable the pixel clock if off */
98 glamo_engine_clkreg_set(gcore
,
100 GLAMO_CLOCK_LCD_EN_DCLK
,
103 gfb
->output_enabled
= 0;
107 static int reg_read(struct glamofb_handle
*glamo
,
112 for (i
= 0; i
!= 2; i
++)
115 return readw(glamo
->base
+ reg
);
118 static void reg_write(struct glamofb_handle
*glamo
,
119 u_int16_t reg
, u_int16_t val
)
123 for (i
= 0; i
!= 2; i
++)
126 writew(val
, glamo
->base
+ reg
);
129 static struct glamo_script glamo_regs
[] = {
130 { GLAMO_REG_LCD_MODE1
, 0x0020 },
131 /* no display rotation, no hardware cursor, no dither, no gamma,
132 * no retrace flip, vsync low-active, hsync low active,
133 * no TVCLK, no partial display, hw dest color from fb,
134 * no partial display mode, LCD1, software flip, */
135 { GLAMO_REG_LCD_MODE2
, 0x9020 },
136 /* video flip, no ptr, no ptr, dhclk off,
137 * normal mode, no cpuif,
138 * res, serial msb first, single fb, no fr ctrl,
139 * cpu if bits all zero, no crc
140 * 0000 0000 0010 0000 */
141 { GLAMO_REG_LCD_MODE3
, 0x0b40 },
142 /* src data rgb565, res, 18bit rgb666
143 * 000 01 011 0100 0000 */
144 { GLAMO_REG_LCD_POLARITY
, 0x440c },
145 /* DE high active, no cpu/lcd if, cs0 force low, a0 low active,
146 * np cpu if, 9bit serial data, sclk rising edge latch data
147 * 01 00 0 100 0 000 01 0 0 */
148 /* The following values assume 640*480@16bpp */
149 { GLAMO_REG_LCD_A_BASE1
, 0x0000 }, /* display A base address 15:0 */
150 { GLAMO_REG_LCD_A_BASE2
, 0x0000 }, /* display A base address 22:16 */
151 { GLAMO_REG_LCD_CURSOR_BASE1
, 0xC000 }, /* cursor base address 15:0 */
152 { GLAMO_REG_LCD_CURSOR_BASE2
, 0x0012 }, /* cursor base address 22:16 */
153 { GLAMO_REG_LCD_COMMAND2
, 0x0000 }, /* display page A */
156 static int glamofb_run_script(struct glamofb_handle
*glamo
,
157 struct glamo_script
*script
, int len
)
161 if (glamo
->mach_info
->core
->suspending
) {
162 dev_err(&glamo
->mach_info
->core
->pdev
->dev
,
163 "IGNORING glamofb_run_script while "
168 for (i
= 0; i
< len
; i
++) {
169 struct glamo_script
*line
= &script
[i
];
171 if (line
->reg
== 0xffff)
173 else if (line
->reg
== 0xfffe)
176 reg_write(glamo
, script
[i
].reg
, script
[i
].val
);
182 static int glamofb_check_var(struct fb_var_screeninfo
*var
,
183 struct fb_info
*info
)
185 struct glamofb_handle
*glamo
= info
->par
;
187 if (glamo
->mach_info
->core
->suspending
) {
188 dev_err(&glamo
->mach_info
->core
->pdev
->dev
,
189 "IGNORING glamofb_check_var while "
194 if (var
->bits_per_pixel
!= 16)
195 var
->bits_per_pixel
= 16;
197 var
->height
= glamo
->mach_info
->height
;
198 var
->width
= glamo
->mach_info
->width
;
200 /* FIXME: set rgb positions */
201 switch (var
->bits_per_pixel
) {
203 switch (reg_read(glamo
, GLAMO_REG_LCD_MODE3
) & 0xc000) {
204 case GLAMO_LCD_SRC_RGB565
:
205 var
->red
.offset
= 11;
206 var
->green
.offset
= 5;
207 var
->blue
.offset
= 0;
209 var
->green
.length
= 6;
210 var
->blue
.length
= 5;
211 var
->transp
.length
= 0;
213 case GLAMO_LCD_SRC_ARGB1555
:
214 var
->transp
.offset
= 15;
215 var
->red
.offset
= 10;
216 var
->green
.offset
= 5;
217 var
->blue
.offset
= 0;
218 var
->transp
.length
= 1;
220 var
->green
.length
= 5;
221 var
->blue
.length
= 5;
223 case GLAMO_LCD_SRC_ARGB4444
:
224 var
->transp
.offset
= 12;
226 var
->green
.offset
= 4;
227 var
->blue
.offset
= 0;
228 var
->transp
.length
= 4;
230 var
->green
.length
= 4;
231 var
->blue
.length
= 4;
238 /* The Smedia Glamo doesn't support anything but 16bit color */
240 "Smedia driver does not [yet?] support 24/32bpp\n");
247 static void reg_set_bit_mask(struct glamofb_handle
*glamo
,
248 u_int16_t reg
, u_int16_t mask
,
255 tmp
= reg_read(glamo
, reg
);
258 reg_write(glamo
, reg
, tmp
);
261 #define GLAMO_LCD_WIDTH_MASK 0x03FF
262 #define GLAMO_LCD_HEIGHT_MASK 0x03FF
263 #define GLAMO_LCD_PITCH_MASK 0x07FE
264 #define GLAMO_LCD_HV_TOTAL_MASK 0x03FF
265 #define GLAMO_LCD_HV_RETR_START_MASK 0x03FF
266 #define GLAMO_LCD_HV_RETR_END_MASK 0x03FF
267 #define GLAMO_LCD_HV_RETR_DISP_START_MASK 0x03FF
268 #define GLAMO_LCD_HV_RETR_DISP_END_MASK 0x03FF
270 /* the caller has to enxure lock_cmd is held and we are in cmd mode */
271 static void __rotate_lcd(struct glamofb_handle
*glamo
, __u32 rotation
)
275 if (glamo
->mach_info
->core
->suspending
) {
276 dev_err(&glamo
->mach_info
->core
->pdev
->dev
,
277 "IGNORING rotate_lcd while "
284 glamo_rot
= GLAMO_LCD_ROT_MODE_90
;
287 glamo_rot
= GLAMO_LCD_ROT_MODE_180
;
290 glamo_rot
= GLAMO_LCD_ROT_MODE_270
;
293 glamo_rot
= GLAMO_LCD_ROT_MODE_0
;
297 reg_set_bit_mask(glamo
,
299 GLAMO_LCD_ROT_MODE_MASK
,
301 reg_set_bit_mask(glamo
,
303 GLAMO_LCD_MODE1_ROTATE_EN
,
304 (glamo_rot
!= GLAMO_LCD_ROT_MODE_0
) ?
305 GLAMO_LCD_MODE1_ROTATE_EN
: 0);
308 static void glamofb_program_mode(struct glamofb_handle
* gfb
) {
309 int sync
, bp
, disp
, fp
, total
;
311 struct glamo_core
*gcore
= gfb
->mach_info
->core
;
312 struct fb_var_screeninfo
*var
= &gfb
->fb
->var
;
314 dev_dbg(&gcore
->pdev
->dev
,
315 "glamofb_program_mode spin_lock_irqsave\n");
316 spin_lock_irqsave(&gfb
->lock_cmd
, flags
);
318 if (glamofb_cmd_mode(gfb
, 1))
322 glamo_engine_reclock(gcore
,
324 gfb
->fb
->var
.pixclock
);
326 reg_set_bit_mask(gfb
,
328 GLAMO_LCD_WIDTH_MASK
,
330 reg_set_bit_mask(gfb
,
331 GLAMO_REG_LCD_HEIGHT
,
332 GLAMO_LCD_HEIGHT_MASK
,
334 reg_set_bit_mask(gfb
,
336 GLAMO_LCD_PITCH_MASK
,
337 gfb
->fb
->fix
.line_length
);
339 /* honour the rotation request */
340 __rotate_lcd(gfb
, var
->rotate
);
342 /* update scannout timings */
344 bp
= sync
+ var
->hsync_len
;
345 disp
= bp
+ var
->left_margin
;
346 fp
= disp
+ var
->xres
;
347 total
= fp
+ var
->right_margin
;
349 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_HORIZ_TOTAL
,
350 GLAMO_LCD_HV_TOTAL_MASK
, total
);
351 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_HORIZ_RETR_START
,
352 GLAMO_LCD_HV_RETR_START_MASK
, sync
);
353 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_HORIZ_RETR_END
,
354 GLAMO_LCD_HV_RETR_END_MASK
, bp
);
355 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_HORIZ_DISP_START
,
356 GLAMO_LCD_HV_RETR_DISP_START_MASK
, disp
);
357 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_HORIZ_DISP_END
,
358 GLAMO_LCD_HV_RETR_DISP_END_MASK
, fp
);
361 bp
= sync
+ var
->vsync_len
;
362 disp
= bp
+ var
->upper_margin
;
363 fp
= disp
+ var
->yres
;
364 total
= fp
+ var
->lower_margin
;
366 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_VERT_TOTAL
,
367 GLAMO_LCD_HV_TOTAL_MASK
, total
);
368 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_VERT_RETR_START
,
369 GLAMO_LCD_HV_RETR_START_MASK
, sync
);
370 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_VERT_RETR_END
,
371 GLAMO_LCD_HV_RETR_END_MASK
, bp
);
372 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_VERT_DISP_START
,
373 GLAMO_LCD_HV_RETR_DISP_START_MASK
, disp
);
374 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_VERT_DISP_END
,
375 GLAMO_LCD_HV_RETR_DISP_END_MASK
, fp
);
377 glamofb_cmd_mode(gfb
, 0);
382 dev_dbg(&gcore
->pdev
->dev
,
383 "glamofb_program_mode spin_unlock_irqrestore\n");
384 spin_unlock_irqrestore(&gfb
->lock_cmd
, flags
);
388 static int glamofb_pan_display(struct fb_var_screeninfo
*var
,
389 struct fb_info
*info
)
394 static struct fb_videomode
*glamofb_find_mode(struct fb_info
*info
,
395 struct fb_var_screeninfo
*var
) {
396 struct glamofb_handle
*glamo
= info
->par
;
397 struct glamo_fb_platform_data
*mach_info
= glamo
->mach_info
;
398 struct fb_videomode
*mode
;
401 for(i
= mach_info
->num_modes
, mode
= mach_info
->modes
; i
> 0; --i
, ++mode
) {
402 if (mode
->xres
== var
->xres
&&
403 mode
->yres
== var
->yres
)
410 static int glamofb_set_par(struct fb_info
*info
)
412 struct glamofb_handle
*glamo
= info
->par
;
413 struct fb_var_screeninfo
*var
= &info
->var
;
414 struct fb_videomode
*mode
;
416 if (glamo
->mach_info
->core
->suspending
) {
417 dev_err(&glamo
->mach_info
->core
->pdev
->dev
,
418 "IGNORING glamofb_set_par while "
423 mode
= glamofb_find_mode(info
, var
);
427 fb_videomode_to_var(var
, mode
);
433 switch(var
->rotate
) {
436 info
->fix
.line_length
= (var
->yres
* var
->bits_per_pixel
) / 8;
437 /* FIXME: Limit pixelclock */
441 info
->fix
.line_length
= (var
->xres
* var
->bits_per_pixel
) / 8;
445 if(glamo
->output_enabled
)
446 glamofb_program_mode(glamo
);
451 static int glamofb_blank(int blank_mode
, struct fb_info
*info
)
453 struct glamofb_handle
*gfb
= info
->par
;
455 dev_dbg(gfb
->dev
, "glamofb_blank(%u)\n", blank_mode
);
457 switch (blank_mode
) {
458 case FB_BLANK_VSYNC_SUSPEND
:
459 case FB_BLANK_HSYNC_SUSPEND
:
460 /* FIXME: add pdata hook/flag to indicate whether
461 * we should already switch off pixel clock here */
463 case FB_BLANK_POWERDOWN
:
464 /* disable the pixel clock */
465 glamo_output_disable(gfb
);
466 gfb
->blank_mode
= blank_mode
;
468 case FB_BLANK_UNBLANK
:
469 case FB_BLANK_NORMAL
:
470 glamo_output_enable(gfb
);
471 gfb
->blank_mode
= blank_mode
;
475 /* FIXME: once we have proper clock management in glamo-core,
476 * we can determine if other units need MCLK1 or the PLL, and
477 * disable it if not used. */
481 static inline unsigned int chan_to_field(unsigned int chan
,
482 struct fb_bitfield
*bf
)
485 chan
>>= 16 - bf
->length
;
486 return chan
<< bf
->offset
;
489 static int glamofb_setcolreg(unsigned regno
,
490 unsigned red
, unsigned green
, unsigned blue
,
491 unsigned transp
, struct fb_info
*info
)
493 struct glamofb_handle
*glamo
= info
->par
;
496 if (glamo
->mach_info
->core
->suspending
) {
497 dev_err(&glamo
->mach_info
->core
->pdev
->dev
,
498 "IGNORING glamofb_set_par while "
503 switch (glamo
->fb
->fix
.visual
) {
504 case FB_VISUAL_TRUECOLOR
:
505 case FB_VISUAL_DIRECTCOLOR
:
506 /* true-colour, use pseuo-palette */
509 u32
*pal
= glamo
->fb
->pseudo_palette
;
511 val
= chan_to_field(red
, &glamo
->fb
->var
.red
);
512 val
|= chan_to_field(green
, &glamo
->fb
->var
.green
);
513 val
|= chan_to_field(blue
, &glamo
->fb
->var
.blue
);
519 return 1; /* unknown type */
525 static int glamofb_ioctl(struct fb_info
*info
, unsigned int cmd
,
527 struct glamofb_handle
*gfb
= (struct glamofb_handle
*)info
->par
;
528 struct glamo_core
*gcore
= gfb
->mach_info
->core
;
529 int retval
= -ENOTTY
;
532 case GLAMOFB_ENGINE_ENABLE
:
533 retval
= glamo_engine_enable(gcore
, arg
);
535 case GLAMOFB_ENGINE_DISABLE
:
536 retval
= glamo_engine_disable(gcore
, arg
);
538 case GLAMOFB_ENGINE_RESET
:
539 glamo_engine_reset(gcore
, arg
);
550 #ifdef CONFIG_MFD_GLAMO_HWACCEL
551 static inline void glamofb_vsync_wait(struct glamofb_handle
*glamo
,
552 int line
, int size
, int range
)
557 count
[0] = reg_read(glamo
, GLAMO_REG_LCD_STATUS2
) & 0x3ff;
558 count
[1] = reg_read(glamo
, GLAMO_REG_LCD_STATUS2
) & 0x3ff;
559 } while (count
[0] != count
[1] ||
560 (line
< count
[0] + range
&&
561 size
> count
[0] - range
) ||
562 count
[0] < range
* 2);
566 * Enable/disable the hardware cursor mode altogether
567 * (for blinking and such, use glamofb_cursor()).
569 static void glamofb_cursor_onoff(struct glamofb_handle
*glamo
, int on
)
573 if (glamo
->cursor_on
) {
574 y
= reg_read(glamo
, GLAMO_REG_LCD_CURSOR_Y_POS
);
575 size
= reg_read(glamo
, GLAMO_REG_LCD_CURSOR_Y_SIZE
);
577 glamofb_vsync_wait(glamo
, y
, size
, 30);
580 reg_set_bit_mask(glamo
, GLAMO_REG_LCD_MODE1
,
581 GLAMO_LCD_MODE1_CURSOR_EN
,
582 on
? GLAMO_LCD_MODE1_CURSOR_EN
: 0);
583 glamo
->cursor_on
= on
;
585 /* Hide the cursor by default */
586 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_X_SIZE
, 0);
589 static int glamofb_cursor(struct fb_info
*info
, struct fb_cursor
*cursor
)
591 struct glamofb_handle
*glamo
= info
->par
;
594 spin_lock_irqsave(&glamo
->lock_cmd
, flags
);
596 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_X_SIZE
,
597 cursor
->enable
? cursor
->image
.width
: 0);
599 if (cursor
->set
& FB_CUR_SETPOS
) {
600 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_X_POS
,
602 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_Y_POS
,
606 if (cursor
->set
& FB_CUR_SETCMAP
) {
607 uint16_t fg
= glamo
->pseudo_pal
[cursor
->image
.fg_color
];
608 uint16_t bg
= glamo
->pseudo_pal
[cursor
->image
.bg_color
];
610 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_FG_COLOR
, fg
);
611 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_BG_COLOR
, bg
);
612 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_DST_COLOR
, fg
);
615 if (cursor
->set
& FB_CUR_SETHOT
)
616 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_PRESET
,
617 (cursor
->hot
.x
<< 8) | cursor
->hot
.y
);
619 if ((cursor
->set
& FB_CUR_SETSIZE
) ||
620 (cursor
->set
& (FB_CUR_SETIMAGE
| FB_CUR_SETSHAPE
))) {
622 const uint8_t *pcol
= cursor
->image
.data
;
623 const uint8_t *pmsk
= cursor
->mask
;
624 uint8_t __iomem
*dst
= glamo
->cursor_addr
;
629 if (cursor
->image
.depth
> 1) {
630 spin_unlock_irqrestore(&glamo
->lock_cmd
, flags
);
634 pitch
= ((cursor
->image
.width
+ 7) >> 2) & ~1;
635 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_PITCH
,
637 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_Y_SIZE
,
638 cursor
->image
.height
);
640 for (y
= 0; y
< cursor
->image
.height
; y
++) {
642 for (x
= 0; x
< cursor
->image
.width
; x
++) {
651 if (cursor
->rop
== ROP_COPY
)
653 (dcol
& 1) ? 1 : 3 : 0;
655 op
= ((dmsk
& 1) << 1) |
657 byte
|= op
<< ((x
& 3) << 1);
660 writeb(byte
, dst
+ x
/ 4);
665 writeb(byte
, dst
+ x
/ 4);
673 spin_unlock_irqrestore(&glamo
->lock_cmd
, flags
);
679 static inline int glamofb_cmdq_empty(struct glamofb_handle
*gfb
)
681 /* DGCMdQempty -- 1 == command queue is empty */
682 return reg_read(gfb
, GLAMO_REG_LCD_STATUS1
) & (1 << 15);
685 /* call holding gfb->lock_cmd when locking, until you unlock */
686 int glamofb_cmd_mode(struct glamofb_handle
*gfb
, int on
)
688 int timeout
= 2000000;
690 if (gfb
->mach_info
->core
->suspending
) {
691 dev_err(&gfb
->mach_info
->core
->pdev
->dev
,
692 "IGNORING glamofb_cmd_mode while "
697 dev_dbg(gfb
->dev
, "glamofb_cmd_mode(gfb=%p, on=%d)\n", gfb
, on
);
699 dev_dbg(gfb
->dev
, "%s: waiting for cmdq empty: ",
701 while ((!glamofb_cmdq_empty(gfb
)) && (timeout
--))
704 printk(KERN_ERR
"*************"
705 "glamofb cmd_queue never got empty"
709 dev_dbg(gfb
->dev
, "empty!\n");
711 /* display the entire frame then switch to command */
712 reg_write(gfb
, GLAMO_REG_LCD_COMMAND1
,
713 GLAMO_LCD_CMD_TYPE_DISP
|
714 GLAMO_LCD_CMD_DATA_FIRE_VSYNC
);
716 /* wait until lcd idle */
717 dev_dbg(gfb
->dev
, "waiting for lcd idle: ");
719 while ((!reg_read(gfb
, GLAMO_REG_LCD_STATUS2
) & (1 << 12)) &&
723 printk(KERN_ERR
"*************"
724 "glamofb lcd never idle"
731 dev_dbg(gfb
->dev
, "cmd mode entered\n");
734 /* RGB interface needs vsync/hsync */
735 if (reg_read(gfb
, GLAMO_REG_LCD_MODE3
) & GLAMO_LCD_MODE3_RGB
)
736 reg_write(gfb
, GLAMO_REG_LCD_COMMAND1
,
737 GLAMO_LCD_CMD_TYPE_DISP
|
738 GLAMO_LCD_CMD_DATA_DISP_SYNC
);
740 reg_write(gfb
, GLAMO_REG_LCD_COMMAND1
,
741 GLAMO_LCD_CMD_TYPE_DISP
|
742 GLAMO_LCD_CMD_DATA_DISP_FIRE
);
747 EXPORT_SYMBOL_GPL(glamofb_cmd_mode
);
750 int glamofb_cmd_write(struct glamofb_handle
*gfb
, u_int16_t val
)
752 int timeout
= 200000;
754 if (gfb
->mach_info
->core
->suspending
) {
755 dev_err(&gfb
->mach_info
->core
->pdev
->dev
,
756 "IGNORING glamofb_cmd_write while "
761 dev_dbg(gfb
->dev
, "%s: waiting for cmdq empty\n", __func__
);
762 while ((!glamofb_cmdq_empty(gfb
)) && (timeout
--))
765 printk(KERN_ERR
"*************"
766 "glamofb cmd_queue never got empty"
770 dev_dbg(gfb
->dev
, "idle, writing 0x%04x\n", val
);
772 reg_write(gfb
, GLAMO_REG_LCD_COMMAND1
, val
);
776 EXPORT_SYMBOL_GPL(glamofb_cmd_write
);
778 static struct fb_ops glamofb_ops
= {
779 .owner
= THIS_MODULE
,
780 .fb_check_var
= glamofb_check_var
,
781 .fb_pan_display
= glamofb_pan_display
,
782 .fb_set_par
= glamofb_set_par
,
783 .fb_blank
= glamofb_blank
,
784 .fb_setcolreg
= glamofb_setcolreg
,
785 .fb_ioctl
= glamofb_ioctl
,
786 #ifdef CONFIG_MFD_GLAMO_HWACCEL
787 .fb_cursor
= glamofb_cursor
,
789 .fb_fillrect
= cfb_fillrect
,
790 .fb_copyarea
= cfb_copyarea
,
791 .fb_imageblit
= cfb_imageblit
,
794 static int glamofb_init_regs(struct glamofb_handle
*glamo
)
796 struct fb_info
*info
= glamo
->fb
;
798 glamofb_check_var(&info
->var
, info
);
799 glamofb_run_script(glamo
, glamo_regs
, ARRAY_SIZE(glamo_regs
));
800 glamofb_set_par(info
);
805 static int __init
glamofb_probe(struct platform_device
*pdev
)
808 struct fb_info
*fbinfo
;
809 struct glamofb_handle
*glamofb
;
810 struct glamo_fb_platform_data
*mach_info
= pdev
->dev
.platform_data
;
812 printk(KERN_INFO
"SMEDIA Glamo frame buffer driver (C) 2007 "
815 fbinfo
= framebuffer_alloc(sizeof(struct glamofb_handle
), &pdev
->dev
);
819 glamofb
= fbinfo
->par
;
820 glamofb
->fb
= fbinfo
;
821 glamofb
->dev
= &pdev
->dev
;
823 glamofb
->blank_mode
= FB_BLANK_POWERDOWN
;
825 strcpy(fbinfo
->fix
.id
, "SMedia Glamo");
827 glamofb
->reg
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
,
830 dev_err(&pdev
->dev
, "platform device with no registers?\n");
835 glamofb
->fb_res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
,
837 if (!glamofb
->fb_res
) {
838 dev_err(&pdev
->dev
, "platform device with no memory ?\n");
843 glamofb
->reg
= request_mem_region(glamofb
->reg
->start
,
844 resource_size(glamofb
->reg
), pdev
->name
);
846 dev_err(&pdev
->dev
, "failed to request mmio region\n");
850 glamofb
->fb_res
= request_mem_region(glamofb
->fb_res
->start
,
851 resource_size(glamofb
->fb_res
),
853 if (!glamofb
->fb_res
) {
854 dev_err(&pdev
->dev
, "failed to request vram region\n");
855 goto out_release_reg
;
858 /* we want to remap only the registers required for this core
860 glamofb
->base
= ioremap_nocache(glamofb
->reg
->start
, resource_size(glamofb
->reg
));
861 if (!glamofb
->base
) {
862 dev_err(&pdev
->dev
, "failed to ioremap() mmio memory\n");
866 fbinfo
->fix
.smem_start
= (unsigned long) glamofb
->fb_res
->start
;
867 fbinfo
->fix
.smem_len
= (__u32
) resource_size(glamofb
->fb_res
);
869 fbinfo
->screen_base
= ioremap(glamofb
->fb_res
->start
,
870 resource_size(glamofb
->fb_res
));
871 if (!fbinfo
->screen_base
) {
872 dev_err(&pdev
->dev
, "failed to ioremap() vram memory\n");
875 glamofb
->cursor_addr
= fbinfo
->screen_base
+ 0x12C000;
877 platform_set_drvdata(pdev
, glamofb
);
879 glamofb
->mach_info
= pdev
->dev
.platform_data
;
881 fbinfo
->fix
.visual
= FB_VISUAL_TRUECOLOR
;
882 fbinfo
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
883 fbinfo
->fix
.type_aux
= 0;
884 fbinfo
->fix
.xpanstep
= 0;
885 fbinfo
->fix
.ypanstep
= 0;
886 fbinfo
->fix
.ywrapstep
= 0;
887 fbinfo
->fix
.accel
= FB_ACCEL_GLAMO
;
890 fbinfo
->fbops
= &glamofb_ops
;
891 fbinfo
->flags
= FBINFO_FLAG_DEFAULT
;
892 fbinfo
->pseudo_palette
= &glamofb
->pseudo_pal
;
894 fbinfo
->mode
= mach_info
->modes
;
895 fb_videomode_to_var(&fbinfo
->var
, fbinfo
->mode
);
896 fbinfo
->var
.bits_per_pixel
= 16;
897 fbinfo
->var
.nonstd
= 0;
898 fbinfo
->var
.activate
= FB_ACTIVATE_NOW
;
899 fbinfo
->var
.height
= mach_info
->height
;
900 fbinfo
->var
.width
= mach_info
->width
;
901 fbinfo
->var
.accel_flags
= 0;
902 fbinfo
->var
.vmode
= FB_VMODE_NONINTERLACED
;
904 glamo_engine_enable(mach_info
->core
, GLAMO_ENGINE_LCD
);
905 glamo_engine_reset(mach_info
->core
, GLAMO_ENGINE_LCD
);
906 glamofb
->output_enabled
= 1;
907 glamofb
->mode_set
= 1;
909 dev_info(&pdev
->dev
, "spin_lock_init\n");
910 spin_lock_init(&glamofb
->lock_cmd
);
911 glamofb_init_regs(glamofb
);
912 #ifdef CONFIG_MFD_GLAMO_HWACCEL
913 glamofb_cursor_onoff(glamofb
, 1);
916 fb_videomode_to_modelist(mach_info
->modes
, mach_info
->num_modes
,
919 rc
= register_framebuffer(fbinfo
);
921 dev_err(&pdev
->dev
, "failed to register framebuffer\n");
925 printk(KERN_INFO
"fb%d: %s frame buffer device\n",
926 fbinfo
->node
, fbinfo
->fix
.id
);
931 iounmap(fbinfo
->screen_base
);
932 iounmap(glamofb
->base
);
934 release_mem_region(glamofb
->fb_res
->start
, resource_size(glamofb
->fb_res
));
936 release_mem_region(glamofb
->reg
->start
, resource_size(glamofb
->reg
));
938 framebuffer_release(fbinfo
);
942 static int glamofb_remove(struct platform_device
*pdev
)
944 struct glamofb_handle
*glamofb
= platform_get_drvdata(pdev
);
946 platform_set_drvdata(pdev
, NULL
);
947 iounmap(glamofb
->base
);
948 release_mem_region(glamofb
->reg
->start
, resource_size(glamofb
->reg
));
956 static int glamofb_suspend(struct platform_device
*pdev
, pm_message_t state
)
958 struct glamofb_handle
*gfb
= platform_get_drvdata(pdev
);
960 /* we need to stop anything touching our framebuffer */
961 fb_set_suspend(gfb
->fb
, 1);
963 /* seriously -- nobody is allowed to touch glamo memory when we
964 * are suspended or we lock on nWAIT
966 /* iounmap(gfb->fb->screen_base); */
971 static int glamofb_resume(struct platform_device
*pdev
)
973 struct glamofb_handle
*gfb
= platform_get_drvdata(pdev
);
974 struct glamo_fb_platform_data
*mach_info
= pdev
->dev
.platform_data
;
976 /* OK let's allow framebuffer ops again */
977 /* gfb->fb->screen_base = ioremap(gfb->fb_res->start,
978 resource_size(gfb->fb_res)); */
979 glamo_engine_enable(mach_info
->core
, GLAMO_ENGINE_LCD
);
980 glamo_engine_reset(mach_info
->core
, GLAMO_ENGINE_LCD
);
982 printk(KERN_ERR
"spin_lock_init\n");
983 spin_lock_init(&gfb
->lock_cmd
);
984 glamofb_init_regs(gfb
);
985 #ifdef CONFIG_MFD_GLAMO_HWACCEL
986 glamofb_cursor_onoff(gfb
, 1);
989 fb_set_suspend(gfb
->fb
, 0);
994 #define glamofb_suspend NULL
995 #define glamofb_resume NULL
998 static struct platform_driver glamofb_driver
= {
999 .probe
= glamofb_probe
,
1000 .remove
= glamofb_remove
,
1001 .suspend
= glamofb_suspend
,
1002 .resume
= glamofb_resume
,
1005 .owner
= THIS_MODULE
,
1009 static int __devinit
glamofb_init(void)
1011 return platform_driver_register(&glamofb_driver
);
1014 static void __exit
glamofb_cleanup(void)
1016 platform_driver_unregister(&glamofb_driver
);
1019 module_init(glamofb_init
);
1020 module_exit(glamofb_cleanup
);
1022 MODULE_AUTHOR("Harald Welte <laforge@openmoko.org>");
1023 MODULE_DESCRIPTION("Smedia Glamo 336x/337x framebuffer driver");
1024 MODULE_LICENSE("GPL");