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/errno.h>
26 #include <linux/string.h>
28 #include <linux/slab.h>
29 #include <linux/delay.h>
31 #include <linux/init.h>
32 #include <linux/vmalloc.h>
33 #include <linux/dma-mapping.h>
34 #include <linux/interrupt.h>
35 #include <linux/workqueue.h>
36 #include <linux/wait.h>
37 #include <linux/platform_device.h>
38 #include <linux/clk.h>
39 #include <linux/spinlock.h>
41 #include <linux/uaccess.h>
43 #include <asm/div64.h>
49 #include <linux/glamofb.h>
51 #include "glamo-regs.h"
52 #include "glamo-core.h"
55 #define GLAMO_LOG(...)
57 #define GLAMO_LOG(...) \
59 printk(KERN_DEBUG "in %s:%s:%d", __FILE__, __func__, __LINE__); \
60 printk(KERN_DEBUG __VA_ARGS__); \
64 static void glamofb_program_mode(struct glamofb_handle
* glamo
);
66 struct glamofb_handle
{
70 struct resource
*fb_res
;
72 struct glamofb_platform_data
*mach_info
;
73 char __iomem
*cursor_addr
;
75 u_int32_t pseudo_pal
[16];
78 int mode_set
; /* 0 if the current display mode hasn't been set on the glamo */
79 int output_enabled
; /* 0 if the video output is disabled */
82 static void glamo_output_enable(struct glamofb_handle
*gfb
) {
83 struct glamo_core
*gcore
= gfb
->mach_info
->glamo
;
85 if (gfb
->output_enabled
)
88 /* enable the pixel clock if off */
89 glamo_engine_clkreg_set(gcore
,
91 GLAMO_CLOCK_LCD_EN_DCLK
,
92 GLAMO_CLOCK_LCD_EN_DCLK
);
94 gfb
->output_enabled
= 1;
96 glamofb_program_mode(gfb
);
99 static void glamo_output_disable(struct glamofb_handle
*gfb
) {
100 struct glamo_core
*gcore
= gfb
->mach_info
->glamo
;
102 if (!gfb
->output_enabled
)
105 /* enable the pixel clock if off */
106 glamo_engine_clkreg_set(gcore
,
108 GLAMO_CLOCK_LCD_EN_DCLK
,
111 gfb
->output_enabled
= 0;
115 static int reg_read(struct glamofb_handle
*glamo
,
120 for (i
= 0; i
!= 2; i
++)
123 return readw(glamo
->base
+ reg
);
126 static void reg_write(struct glamofb_handle
*glamo
,
127 u_int16_t reg
, u_int16_t val
)
131 for (i
= 0; i
!= 2; i
++)
134 writew(val
, glamo
->base
+ reg
);
137 static struct glamo_script glamo_regs
[] = {
138 { GLAMO_REG_LCD_MODE1
, 0x0020 },
139 /* no display rotation, no hardware cursor, no dither, no gamma,
140 * no retrace flip, vsync low-active, hsync low active,
141 * no TVCLK, no partial display, hw dest color from fb,
142 * no partial display mode, LCD1, software flip, */
143 { GLAMO_REG_LCD_MODE2
, 0x9020 },
144 /* video flip, no ptr, no ptr, dhclk off,
145 * normal mode, no cpuif,
146 * res, serial msb first, single fb, no fr ctrl,
147 * cpu if bits all zero, no crc
148 * 0000 0000 0010 0000 */
149 { GLAMO_REG_LCD_MODE3
, 0x0b40 },
150 /* src data rgb565, res, 18bit rgb666
151 * 000 01 011 0100 0000 */
152 { GLAMO_REG_LCD_POLARITY
, 0x440c },
153 /* DE high active, no cpu/lcd if, cs0 force low, a0 low active,
154 * np cpu if, 9bit serial data, sclk rising edge latch data
155 * 01 00 0 100 0 000 01 0 0 */
156 /* The following values assume 640*480@16bpp */
157 { GLAMO_REG_LCD_A_BASE1
, 0x0000 }, /* display A base address 15:0 */
158 { GLAMO_REG_LCD_A_BASE2
, 0x0000 }, /* display A base address 22:16 */
159 { GLAMO_REG_LCD_CURSOR_BASE1
, 0xC000 }, /* cursor base address 15:0 */
160 { GLAMO_REG_LCD_CURSOR_BASE2
, 0x0012 }, /* cursor base address 22:16 */
161 { GLAMO_REG_LCD_COMMAND2
, 0x0000 }, /* display page A */
164 static int glamofb_run_script(struct glamofb_handle
*glamo
,
165 struct glamo_script
*script
, int len
)
169 if (glamo
->mach_info
->glamo
->suspending
) {
170 dev_err(&glamo
->mach_info
->glamo
->pdev
->dev
,
171 "IGNORING glamofb_run_script while "
176 for (i
= 0; i
< len
; i
++) {
177 struct glamo_script
*line
= &script
[i
];
179 if (line
->reg
== 0xffff)
181 else if (line
->reg
== 0xfffe)
184 reg_write(glamo
, script
[i
].reg
, script
[i
].val
);
190 static int glamofb_check_var(struct fb_var_screeninfo
*var
,
191 struct fb_info
*info
)
193 struct glamofb_handle
*glamo
= info
->par
;
195 if (glamo
->mach_info
->glamo
->suspending
) {
196 dev_err(&glamo
->mach_info
->glamo
->pdev
->dev
,
197 "IGNORING glamofb_check_var while "
202 if (var
->bits_per_pixel
!= 16)
203 var
->bits_per_pixel
= 16;
205 var
->height
= glamo
->mach_info
->height
;
206 var
->width
= glamo
->mach_info
->width
;
208 /* FIXME: set rgb positions */
209 switch (var
->bits_per_pixel
) {
211 switch (reg_read(glamo
, GLAMO_REG_LCD_MODE3
) & 0xc000) {
212 case GLAMO_LCD_SRC_RGB565
:
213 var
->red
.offset
= 11;
214 var
->green
.offset
= 5;
215 var
->blue
.offset
= 0;
217 var
->green
.length
= 6;
218 var
->blue
.length
= 5;
219 var
->transp
.length
= 0;
221 case GLAMO_LCD_SRC_ARGB1555
:
222 var
->transp
.offset
= 15;
223 var
->red
.offset
= 10;
224 var
->green
.offset
= 5;
225 var
->blue
.offset
= 0;
226 var
->transp
.length
= 1;
228 var
->green
.length
= 5;
229 var
->blue
.length
= 5;
231 case GLAMO_LCD_SRC_ARGB4444
:
232 var
->transp
.offset
= 12;
234 var
->green
.offset
= 4;
235 var
->blue
.offset
= 0;
236 var
->transp
.length
= 4;
238 var
->green
.length
= 4;
239 var
->blue
.length
= 4;
246 /* The Smedia Glamo doesn't support anything but 16bit color */
248 "Smedia driver does not [yet?] support 24/32bpp\n");
255 static void reg_set_bit_mask(struct glamofb_handle
*glamo
,
256 u_int16_t reg
, u_int16_t mask
,
263 tmp
= reg_read(glamo
, reg
);
266 reg_write(glamo
, reg
, tmp
);
269 #define GLAMO_LCD_WIDTH_MASK 0x03FF
270 #define GLAMO_LCD_HEIGHT_MASK 0x03FF
271 #define GLAMO_LCD_PITCH_MASK 0x07FE
272 #define GLAMO_LCD_HV_TOTAL_MASK 0x03FF
273 #define GLAMO_LCD_HV_RETR_START_MASK 0x03FF
274 #define GLAMO_LCD_HV_RETR_END_MASK 0x03FF
275 #define GLAMO_LCD_HV_RETR_DISP_START_MASK 0x03FF
276 #define GLAMO_LCD_HV_RETR_DISP_END_MASK 0x03FF
278 /* the caller has to enxure lock_cmd is held and we are in cmd mode */
279 static void __rotate_lcd(struct glamofb_handle
*glamo
, __u32 rotation
)
283 if (glamo
->mach_info
->glamo
->suspending
) {
284 dev_err(&glamo
->mach_info
->glamo
->pdev
->dev
,
285 "IGNORING rotate_lcd while "
292 glamo_rot
= GLAMO_LCD_ROT_MODE_90
;
295 glamo_rot
= GLAMO_LCD_ROT_MODE_180
;
298 glamo_rot
= GLAMO_LCD_ROT_MODE_270
;
301 glamo_rot
= GLAMO_LCD_ROT_MODE_0
;
305 reg_set_bit_mask(glamo
,
307 GLAMO_LCD_ROT_MODE_MASK
,
309 reg_set_bit_mask(glamo
,
311 GLAMO_LCD_MODE1_ROTATE_EN
,
312 (glamo_rot
!= GLAMO_LCD_ROT_MODE_0
) ?
313 GLAMO_LCD_MODE1_ROTATE_EN
: 0);
316 static void glamofb_program_mode(struct glamofb_handle
* gfb
) {
317 int sync
, bp
, disp
, fp
, total
;
319 struct glamo_core
*gcore
= gfb
->mach_info
->glamo
;
320 struct fb_var_screeninfo
*var
= &gfb
->fb
->var
;
322 dev_dbg(&gcore
->pdev
->dev
,
323 "glamofb_program_mode spin_lock_irqsave\n");
324 spin_lock_irqsave(&gfb
->lock_cmd
, flags
);
326 if (glamofb_cmd_mode(gfb
, 1))
330 glamo_engine_reclock(gcore
,
332 gfb
->fb
->var
.pixclock
);
334 reg_set_bit_mask(gfb
,
336 GLAMO_LCD_WIDTH_MASK
,
338 reg_set_bit_mask(gfb
,
339 GLAMO_REG_LCD_HEIGHT
,
340 GLAMO_LCD_HEIGHT_MASK
,
342 reg_set_bit_mask(gfb
,
344 GLAMO_LCD_PITCH_MASK
,
345 gfb
->fb
->fix
.line_length
);
347 /* honour the rotation request */
348 __rotate_lcd(gfb
, var
->rotate
);
350 /* update scannout timings */
352 bp
= sync
+ var
->hsync_len
;
353 disp
= bp
+ var
->left_margin
;
354 fp
= disp
+ var
->xres
;
355 total
= fp
+ var
->right_margin
;
357 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_HORIZ_TOTAL
,
358 GLAMO_LCD_HV_TOTAL_MASK
, total
);
359 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_HORIZ_RETR_START
,
360 GLAMO_LCD_HV_RETR_START_MASK
, sync
);
361 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_HORIZ_RETR_END
,
362 GLAMO_LCD_HV_RETR_END_MASK
, bp
);
363 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_HORIZ_DISP_START
,
364 GLAMO_LCD_HV_RETR_DISP_START_MASK
, disp
);
365 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_HORIZ_DISP_END
,
366 GLAMO_LCD_HV_RETR_DISP_END_MASK
, fp
);
369 bp
= sync
+ var
->vsync_len
;
370 disp
= bp
+ var
->upper_margin
;
371 fp
= disp
+ var
->yres
;
372 total
= fp
+ var
->lower_margin
;
374 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_VERT_TOTAL
,
375 GLAMO_LCD_HV_TOTAL_MASK
, total
);
376 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_VERT_RETR_START
,
377 GLAMO_LCD_HV_RETR_START_MASK
, sync
);
378 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_VERT_RETR_END
,
379 GLAMO_LCD_HV_RETR_END_MASK
, bp
);
380 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_VERT_DISP_START
,
381 GLAMO_LCD_HV_RETR_DISP_START_MASK
, disp
);
382 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_VERT_DISP_END
,
383 GLAMO_LCD_HV_RETR_DISP_END_MASK
, fp
);
385 glamofb_cmd_mode(gfb
, 0);
390 dev_dbg(&gcore
->pdev
->dev
,
391 "glamofb_program_mode spin_unlock_irqrestore\n");
392 spin_unlock_irqrestore(&gfb
->lock_cmd
, flags
);
396 static int glamofb_pan_display(struct fb_var_screeninfo
*var
,
397 struct fb_info
*info
)
402 static struct fb_videomode
*glamofb_find_mode(struct fb_info
*info
,
403 struct fb_var_screeninfo
*var
) {
404 struct glamofb_handle
*glamo
= info
->par
;
405 struct glamofb_platform_data
*mach_info
= glamo
->mach_info
;
406 struct fb_videomode
*mode
;
409 for(i
= mach_info
->num_modes
, mode
= mach_info
->modes
; i
> 0; --i
, ++mode
) {
410 if (mode
->xres
== var
->xres
&&
411 mode
->yres
== var
->yres
)
418 static int glamofb_set_par(struct fb_info
*info
)
420 struct glamofb_handle
*glamo
= info
->par
;
421 struct fb_var_screeninfo
*var
= &info
->var
;
422 struct fb_videomode
*mode
;
424 if (glamo
->mach_info
->glamo
->suspending
) {
425 dev_err(&glamo
->mach_info
->glamo
->pdev
->dev
,
426 "IGNORING glamofb_set_par while "
431 mode
= glamofb_find_mode(info
, var
);
435 fb_videomode_to_var(var
, mode
);
441 switch(var
->rotate
) {
444 info
->fix
.line_length
= (var
->yres
* var
->bits_per_pixel
) / 8;
445 /* FIXME: Limit pixelclock */
449 info
->fix
.line_length
= (var
->xres
* var
->bits_per_pixel
) / 8;
453 if(glamo
->output_enabled
)
454 glamofb_program_mode(glamo
);
459 static int glamofb_blank(int blank_mode
, struct fb_info
*info
)
461 struct glamofb_handle
*gfb
= info
->par
;
463 dev_dbg(gfb
->dev
, "glamofb_blank(%u)\n", blank_mode
);
465 switch (blank_mode
) {
466 case FB_BLANK_VSYNC_SUSPEND
:
467 case FB_BLANK_HSYNC_SUSPEND
:
468 /* FIXME: add pdata hook/flag to indicate whether
469 * we should already switch off pixel clock here */
471 case FB_BLANK_POWERDOWN
:
472 /* disable the pixel clock */
473 glamo_output_disable(gfb
);
474 gfb
->blank_mode
= blank_mode
;
476 case FB_BLANK_UNBLANK
:
477 case FB_BLANK_NORMAL
:
478 glamo_output_enable(gfb
);
479 gfb
->blank_mode
= blank_mode
;
483 /* FIXME: once we have proper clock management in glamo-core,
484 * we can determine if other units need MCLK1 or the PLL, and
485 * disable it if not used. */
489 static inline unsigned int chan_to_field(unsigned int chan
,
490 struct fb_bitfield
*bf
)
493 chan
>>= 16 - bf
->length
;
494 return chan
<< bf
->offset
;
497 static int glamofb_setcolreg(unsigned regno
,
498 unsigned red
, unsigned green
, unsigned blue
,
499 unsigned transp
, struct fb_info
*info
)
501 struct glamofb_handle
*glamo
= info
->par
;
504 if (glamo
->mach_info
->glamo
->suspending
) {
505 dev_err(&glamo
->mach_info
->glamo
->pdev
->dev
,
506 "IGNORING glamofb_set_par while "
511 switch (glamo
->fb
->fix
.visual
) {
512 case FB_VISUAL_TRUECOLOR
:
513 case FB_VISUAL_DIRECTCOLOR
:
514 /* true-colour, use pseuo-palette */
517 u32
*pal
= glamo
->fb
->pseudo_palette
;
519 val
= chan_to_field(red
, &glamo
->fb
->var
.red
);
520 val
|= chan_to_field(green
, &glamo
->fb
->var
.green
);
521 val
|= chan_to_field(blue
, &glamo
->fb
->var
.blue
);
527 return 1; /* unknown type */
533 static int glamofb_ioctl(struct fb_info
*info
, unsigned int cmd
,
535 struct glamofb_handle
*gfb
= (struct glamofb_handle
*)info
->par
;
536 struct glamo_core
*gcore
= gfb
->mach_info
->glamo
;
537 int retval
= -ENOTTY
;
540 case GLAMOFB_ENGINE_ENABLE
:
541 retval
= glamo_engine_enable(gcore
, arg
);
543 case GLAMOFB_ENGINE_DISABLE
:
544 retval
= glamo_engine_disable(gcore
, arg
);
546 case GLAMOFB_ENGINE_RESET
:
547 glamo_engine_reset(gcore
, arg
);
558 #ifdef CONFIG_MFD_GLAMO_HWACCEL
559 static inline void glamofb_vsync_wait(struct glamofb_handle
*glamo
,
560 int line
, int size
, int range
)
565 count
[0] = reg_read(glamo
, GLAMO_REG_LCD_STATUS2
) & 0x3ff;
566 count
[1] = reg_read(glamo
, GLAMO_REG_LCD_STATUS2
) & 0x3ff;
567 } while (count
[0] != count
[1] ||
568 (line
< count
[0] + range
&&
569 size
> count
[0] - range
) ||
570 count
[0] < range
* 2);
574 * Enable/disable the hardware cursor mode altogether
575 * (for blinking and such, use glamofb_cursor()).
577 static void glamofb_cursor_onoff(struct glamofb_handle
*glamo
, int on
)
581 if (glamo
->cursor_on
) {
582 y
= reg_read(glamo
, GLAMO_REG_LCD_CURSOR_Y_POS
);
583 size
= reg_read(glamo
, GLAMO_REG_LCD_CURSOR_Y_SIZE
);
585 glamofb_vsync_wait(glamo
, y
, size
, 30);
588 reg_set_bit_mask(glamo
, GLAMO_REG_LCD_MODE1
,
589 GLAMO_LCD_MODE1_CURSOR_EN
,
590 on
? GLAMO_LCD_MODE1_CURSOR_EN
: 0);
591 glamo
->cursor_on
= on
;
593 /* Hide the cursor by default */
594 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_X_SIZE
, 0);
597 static int glamofb_cursor(struct fb_info
*info
, struct fb_cursor
*cursor
)
599 struct glamofb_handle
*glamo
= info
->par
;
602 spin_lock_irqsave(&glamo
->lock_cmd
, flags
);
604 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_X_SIZE
,
605 cursor
->enable
? cursor
->image
.width
: 0);
607 if (cursor
->set
& FB_CUR_SETPOS
) {
608 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_X_POS
,
610 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_Y_POS
,
614 if (cursor
->set
& FB_CUR_SETCMAP
) {
615 uint16_t fg
= glamo
->pseudo_pal
[cursor
->image
.fg_color
];
616 uint16_t bg
= glamo
->pseudo_pal
[cursor
->image
.bg_color
];
618 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_FG_COLOR
, fg
);
619 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_BG_COLOR
, bg
);
620 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_DST_COLOR
, fg
);
623 if (cursor
->set
& FB_CUR_SETHOT
)
624 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_PRESET
,
625 (cursor
->hot
.x
<< 8) | cursor
->hot
.y
);
627 if ((cursor
->set
& FB_CUR_SETSIZE
) ||
628 (cursor
->set
& (FB_CUR_SETIMAGE
| FB_CUR_SETSHAPE
))) {
630 const uint8_t *pcol
= cursor
->image
.data
;
631 const uint8_t *pmsk
= cursor
->mask
;
632 uint8_t __iomem
*dst
= glamo
->cursor_addr
;
637 if (cursor
->image
.depth
> 1) {
638 spin_unlock_irqrestore(&glamo
->lock_cmd
, flags
);
642 pitch
= ((cursor
->image
.width
+ 7) >> 2) & ~1;
643 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_PITCH
,
645 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_Y_SIZE
,
646 cursor
->image
.height
);
648 for (y
= 0; y
< cursor
->image
.height
; y
++) {
650 for (x
= 0; x
< cursor
->image
.width
; x
++) {
659 if (cursor
->rop
== ROP_COPY
)
661 (dcol
& 1) ? 1 : 3 : 0;
663 op
= ((dmsk
& 1) << 1) |
665 byte
|= op
<< ((x
& 3) << 1);
668 writeb(byte
, dst
+ x
/ 4);
673 writeb(byte
, dst
+ x
/ 4);
681 spin_unlock_irqrestore(&glamo
->lock_cmd
, flags
);
687 static inline int glamofb_cmdq_empty(struct glamofb_handle
*gfb
)
689 /* DGCMdQempty -- 1 == command queue is empty */
690 return reg_read(gfb
, GLAMO_REG_LCD_STATUS1
) & (1 << 15);
693 /* call holding gfb->lock_cmd when locking, until you unlock */
694 int glamofb_cmd_mode(struct glamofb_handle
*gfb
, int on
)
696 int timeout
= 2000000;
698 if (gfb
->mach_info
->glamo
->suspending
) {
699 dev_err(&gfb
->mach_info
->glamo
->pdev
->dev
,
700 "IGNORING glamofb_cmd_mode while "
705 dev_dbg(gfb
->dev
, "glamofb_cmd_mode(gfb=%p, on=%d)\n", gfb
, on
);
707 dev_dbg(gfb
->dev
, "%s: waiting for cmdq empty: ",
709 while ((!glamofb_cmdq_empty(gfb
)) && (timeout
--))
712 printk(KERN_ERR
"*************"
713 "glamofb cmd_queue never got empty"
717 dev_dbg(gfb
->dev
, "empty!\n");
719 /* display the entire frame then switch to command */
720 reg_write(gfb
, GLAMO_REG_LCD_COMMAND1
,
721 GLAMO_LCD_CMD_TYPE_DISP
|
722 GLAMO_LCD_CMD_DATA_FIRE_VSYNC
);
724 /* wait until lcd idle */
725 dev_dbg(gfb
->dev
, "waiting for lcd idle: ");
727 while ((!reg_read(gfb
, GLAMO_REG_LCD_STATUS2
) & (1 << 12)) &&
731 printk(KERN_ERR
"*************"
732 "glamofb lcd never idle"
739 dev_dbg(gfb
->dev
, "cmd mode entered\n");
742 /* RGB interface needs vsync/hsync */
743 if (reg_read(gfb
, GLAMO_REG_LCD_MODE3
) & GLAMO_LCD_MODE3_RGB
)
744 reg_write(gfb
, GLAMO_REG_LCD_COMMAND1
,
745 GLAMO_LCD_CMD_TYPE_DISP
|
746 GLAMO_LCD_CMD_DATA_DISP_SYNC
);
748 reg_write(gfb
, GLAMO_REG_LCD_COMMAND1
,
749 GLAMO_LCD_CMD_TYPE_DISP
|
750 GLAMO_LCD_CMD_DATA_DISP_FIRE
);
755 EXPORT_SYMBOL_GPL(glamofb_cmd_mode
);
758 int glamofb_cmd_write(struct glamofb_handle
*gfb
, u_int16_t val
)
760 int timeout
= 200000;
762 if (gfb
->mach_info
->glamo
->suspending
) {
763 dev_err(&gfb
->mach_info
->glamo
->pdev
->dev
,
764 "IGNORING glamofb_cmd_write while "
769 dev_dbg(gfb
->dev
, "%s: waiting for cmdq empty\n", __func__
);
770 while ((!glamofb_cmdq_empty(gfb
)) && (timeout
--))
773 printk(KERN_ERR
"*************"
774 "glamofb cmd_queue never got empty"
778 dev_dbg(gfb
->dev
, "idle, writing 0x%04x\n", val
);
780 reg_write(gfb
, GLAMO_REG_LCD_COMMAND1
, val
);
784 EXPORT_SYMBOL_GPL(glamofb_cmd_write
);
786 static struct fb_ops glamofb_ops
= {
787 .owner
= THIS_MODULE
,
788 .fb_check_var
= glamofb_check_var
,
789 .fb_pan_display
= glamofb_pan_display
,
790 .fb_set_par
= glamofb_set_par
,
791 .fb_blank
= glamofb_blank
,
792 .fb_setcolreg
= glamofb_setcolreg
,
793 .fb_ioctl
= glamofb_ioctl
,
794 #ifdef CONFIG_MFD_GLAMO_HWACCEL
795 .fb_cursor
= glamofb_cursor
,
797 .fb_fillrect
= cfb_fillrect
,
798 .fb_copyarea
= cfb_copyarea
,
799 .fb_imageblit
= cfb_imageblit
,
802 static int glamofb_init_regs(struct glamofb_handle
*glamo
)
804 struct fb_info
*info
= glamo
->fb
;
806 glamofb_check_var(&info
->var
, info
);
807 glamofb_run_script(glamo
, glamo_regs
, ARRAY_SIZE(glamo_regs
));
808 glamofb_set_par(info
);
813 static int __init
glamofb_probe(struct platform_device
*pdev
)
816 struct fb_info
*fbinfo
;
817 struct glamofb_handle
*glamofb
;
818 struct glamofb_platform_data
*mach_info
= pdev
->dev
.platform_data
;
820 printk(KERN_INFO
"SMEDIA Glamo frame buffer driver (C) 2007 "
823 fbinfo
= framebuffer_alloc(sizeof(struct glamofb_handle
), &pdev
->dev
);
827 glamofb
= fbinfo
->par
;
828 glamofb
->fb
= fbinfo
;
829 glamofb
->dev
= &pdev
->dev
;
831 glamofb
->blank_mode
= FB_BLANK_POWERDOWN
;
833 strcpy(fbinfo
->fix
.id
, "SMedia Glamo");
835 glamofb
->reg
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
,
838 dev_err(&pdev
->dev
, "platform device with no registers?\n");
843 glamofb
->fb_res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
,
845 if (!glamofb
->fb_res
) {
846 dev_err(&pdev
->dev
, "platform device with no memory ?\n");
851 glamofb
->reg
= request_mem_region(glamofb
->reg
->start
,
852 resource_size(glamofb
->reg
), pdev
->name
);
854 dev_err(&pdev
->dev
, "failed to request mmio region\n");
858 glamofb
->fb_res
= request_mem_region(glamofb
->fb_res
->start
,
859 resource_size(glamofb
->fb_res
),
861 if (!glamofb
->fb_res
) {
862 dev_err(&pdev
->dev
, "failed to request vram region\n");
863 goto out_release_reg
;
866 /* we want to remap only the registers required for this core
868 glamofb
->base
= ioremap_nocache(glamofb
->reg
->start
, resource_size(glamofb
->reg
));
869 if (!glamofb
->base
) {
870 dev_err(&pdev
->dev
, "failed to ioremap() mmio memory\n");
874 fbinfo
->fix
.smem_start
= (unsigned long) glamofb
->fb_res
->start
;
875 fbinfo
->fix
.smem_len
= (__u32
) resource_size(glamofb
->fb_res
);
877 fbinfo
->screen_base
= ioremap(glamofb
->fb_res
->start
,
878 resource_size(glamofb
->fb_res
));
879 if (!fbinfo
->screen_base
) {
880 dev_err(&pdev
->dev
, "failed to ioremap() vram memory\n");
883 glamofb
->cursor_addr
= fbinfo
->screen_base
+ 0x12C000;
885 platform_set_drvdata(pdev
, glamofb
);
887 glamofb
->mach_info
= pdev
->dev
.platform_data
;
889 fbinfo
->fix
.visual
= FB_VISUAL_TRUECOLOR
;
890 fbinfo
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
891 fbinfo
->fix
.type_aux
= 0;
892 fbinfo
->fix
.xpanstep
= 0;
893 fbinfo
->fix
.ypanstep
= 0;
894 fbinfo
->fix
.ywrapstep
= 0;
895 fbinfo
->fix
.accel
= FB_ACCEL_GLAMO
;
898 fbinfo
->fbops
= &glamofb_ops
;
899 fbinfo
->flags
= FBINFO_FLAG_DEFAULT
;
900 fbinfo
->pseudo_palette
= &glamofb
->pseudo_pal
;
902 fbinfo
->mode
= mach_info
->modes
;
903 fb_videomode_to_var(&fbinfo
->var
, fbinfo
->mode
);
904 fbinfo
->var
.bits_per_pixel
= 16;
905 fbinfo
->var
.nonstd
= 0;
906 fbinfo
->var
.activate
= FB_ACTIVATE_NOW
;
907 fbinfo
->var
.height
= mach_info
->height
;
908 fbinfo
->var
.width
= mach_info
->width
;
909 fbinfo
->var
.accel_flags
= 0;
910 fbinfo
->var
.vmode
= FB_VMODE_NONINTERLACED
;
912 glamo_engine_enable(mach_info
->glamo
, GLAMO_ENGINE_LCD
);
913 glamo_engine_reset(mach_info
->glamo
, GLAMO_ENGINE_LCD
);
914 glamofb
->output_enabled
= 1;
915 glamofb
->mode_set
= 1;
917 dev_info(&pdev
->dev
, "spin_lock_init\n");
918 spin_lock_init(&glamofb
->lock_cmd
);
919 glamofb_init_regs(glamofb
);
920 #ifdef CONFIG_MFD_GLAMO_HWACCEL
921 glamofb_cursor_onoff(glamofb
, 1);
924 fb_videomode_to_modelist(mach_info
->modes
, mach_info
->num_modes
,
927 rc
= register_framebuffer(fbinfo
);
929 dev_err(&pdev
->dev
, "failed to register framebuffer\n");
933 printk(KERN_INFO
"fb%d: %s frame buffer device\n",
934 fbinfo
->node
, fbinfo
->fix
.id
);
939 iounmap(fbinfo
->screen_base
);
940 iounmap(glamofb
->base
);
942 release_mem_region(glamofb
->fb_res
->start
, resource_size(glamofb
->fb_res
));
944 release_mem_region(glamofb
->reg
->start
, resource_size(glamofb
->reg
));
946 framebuffer_release(fbinfo
);
950 static int glamofb_remove(struct platform_device
*pdev
)
952 struct glamofb_handle
*glamofb
= platform_get_drvdata(pdev
);
954 platform_set_drvdata(pdev
, NULL
);
955 iounmap(glamofb
->base
);
956 release_mem_region(glamofb
->reg
->start
, resource_size(glamofb
->reg
));
964 static int glamofb_suspend(struct platform_device
*pdev
, pm_message_t state
)
966 struct glamofb_handle
*gfb
= platform_get_drvdata(pdev
);
968 /* we need to stop anything touching our framebuffer */
969 fb_set_suspend(gfb
->fb
, 1);
971 /* seriously -- nobody is allowed to touch glamo memory when we
972 * are suspended or we lock on nWAIT
974 /* iounmap(gfb->fb->screen_base); */
979 static int glamofb_resume(struct platform_device
*pdev
)
981 struct glamofb_handle
*gfb
= platform_get_drvdata(pdev
);
982 struct glamofb_platform_data
*mach_info
= pdev
->dev
.platform_data
;
984 /* OK let's allow framebuffer ops again */
985 /* gfb->fb->screen_base = ioremap(gfb->fb_res->start,
986 resource_size(gfb->fb_res)); */
987 glamo_engine_enable(mach_info
->glamo
, GLAMO_ENGINE_LCD
);
988 glamo_engine_reset(mach_info
->glamo
, GLAMO_ENGINE_LCD
);
990 printk(KERN_ERR
"spin_lock_init\n");
991 spin_lock_init(&gfb
->lock_cmd
);
992 glamofb_init_regs(gfb
);
993 #ifdef CONFIG_MFD_GLAMO_HWACCEL
994 glamofb_cursor_onoff(gfb
, 1);
997 fb_set_suspend(gfb
->fb
, 0);
1002 #define glamofb_suspend NULL
1003 #define glamofb_resume NULL
1006 static struct platform_driver glamofb_driver
= {
1007 .probe
= glamofb_probe
,
1008 .remove
= glamofb_remove
,
1009 .suspend
= glamofb_suspend
,
1010 .resume
= glamofb_resume
,
1013 .owner
= THIS_MODULE
,
1017 static int __devinit
glamofb_init(void)
1019 return platform_driver_register(&glamofb_driver
);
1022 static void __exit
glamofb_cleanup(void)
1024 platform_driver_unregister(&glamofb_driver
);
1027 module_init(glamofb_init
);
1028 module_exit(glamofb_cleanup
);
1030 MODULE_AUTHOR("Harald Welte <laforge@openmoko.org>");
1031 MODULE_DESCRIPTION("Smedia Glamo 336x/337x framebuffer driver");
1032 MODULE_LICENSE("GPL");