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 /* 'sibling' spi device for lcm init */
83 static struct platform_device glamo_spi_dev
= {
84 .name
= "glamo-lcm-spi",
87 static void glamo_output_enable(struct glamofb_handle
*gfb
) {
88 struct glamo_core
*gcore
= gfb
->mach_info
->glamo
;
90 if (gfb
->output_enabled
)
93 /* enable the pixel clock if off */
94 glamo_engine_clkreg_set(gcore
,
96 GLAMO_CLOCK_LCD_EN_DCLK
,
97 GLAMO_CLOCK_LCD_EN_DCLK
);
99 gfb
->output_enabled
= 1;
101 glamofb_program_mode(gfb
);
104 static void glamo_output_disable(struct glamofb_handle
*gfb
) {
105 struct glamo_core
*gcore
= gfb
->mach_info
->glamo
;
107 if (!gfb
->output_enabled
)
110 /* enable the pixel clock if off */
111 glamo_engine_clkreg_set(gcore
,
113 GLAMO_CLOCK_LCD_EN_DCLK
,
116 gfb
->output_enabled
= 0;
120 static int reg_read(struct glamofb_handle
*glamo
,
125 for (i
= 0; i
!= 2; i
++)
128 return readw(glamo
->base
+ reg
);
131 static void reg_write(struct glamofb_handle
*glamo
,
132 u_int16_t reg
, u_int16_t val
)
136 for (i
= 0; i
!= 2; i
++)
139 writew(val
, glamo
->base
+ reg
);
142 static struct glamo_script glamo_regs
[] = {
143 { GLAMO_REG_LCD_MODE1
, 0x0020 },
144 /* no display rotation, no hardware cursor, no dither, no gamma,
145 * no retrace flip, vsync low-active, hsync low active,
146 * no TVCLK, no partial display, hw dest color from fb,
147 * no partial display mode, LCD1, software flip, */
148 { GLAMO_REG_LCD_MODE2
, 0x9020 },
149 /* video flip, no ptr, no ptr, dhclk off,
150 * normal mode, no cpuif,
151 * res, serial msb first, single fb, no fr ctrl,
152 * cpu if bits all zero, no crc
153 * 0000 0000 0010 0000 */
154 { GLAMO_REG_LCD_MODE3
, 0x0b40 },
155 /* src data rgb565, res, 18bit rgb666
156 * 000 01 011 0100 0000 */
157 { GLAMO_REG_LCD_POLARITY
, 0x440c },
158 /* DE high active, no cpu/lcd if, cs0 force low, a0 low active,
159 * np cpu if, 9bit serial data, sclk rising edge latch data
160 * 01 00 0 100 0 000 01 0 0 */
161 /* The following values assume 640*480@16bpp */
162 { GLAMO_REG_LCD_A_BASE1
, 0x0000 }, /* display A base address 15:0 */
163 { GLAMO_REG_LCD_A_BASE2
, 0x0000 }, /* display A base address 22:16 */
164 { GLAMO_REG_LCD_CURSOR_BASE1
, 0xC000 }, /* cursor base address 15:0 */
165 { GLAMO_REG_LCD_CURSOR_BASE2
, 0x0012 }, /* cursor base address 22:16 */
166 { GLAMO_REG_LCD_COMMAND2
, 0x0000 }, /* display page A */
169 static int glamofb_run_script(struct glamofb_handle
*glamo
,
170 struct glamo_script
*script
, int len
)
174 if (glamo
->mach_info
->glamo
->suspending
) {
175 dev_err(&glamo
->mach_info
->glamo
->pdev
->dev
,
176 "IGNORING glamofb_run_script while "
181 for (i
= 0; i
< len
; i
++) {
182 struct glamo_script
*line
= &script
[i
];
184 if (line
->reg
== 0xffff)
186 else if (line
->reg
== 0xfffe)
189 reg_write(glamo
, script
[i
].reg
, script
[i
].val
);
195 static int glamofb_check_var(struct fb_var_screeninfo
*var
,
196 struct fb_info
*info
)
198 struct glamofb_handle
*glamo
= info
->par
;
200 if (glamo
->mach_info
->glamo
->suspending
) {
201 dev_err(&glamo
->mach_info
->glamo
->pdev
->dev
,
202 "IGNORING glamofb_check_var while "
207 if (var
->bits_per_pixel
!= 16)
208 var
->bits_per_pixel
= 16;
210 var
->height
= glamo
->mach_info
->height
;
211 var
->width
= glamo
->mach_info
->width
;
213 /* FIXME: set rgb positions */
214 switch (var
->bits_per_pixel
) {
216 switch (reg_read(glamo
, GLAMO_REG_LCD_MODE3
) & 0xc000) {
217 case GLAMO_LCD_SRC_RGB565
:
218 var
->red
.offset
= 11;
219 var
->green
.offset
= 5;
220 var
->blue
.offset
= 0;
222 var
->green
.length
= 6;
223 var
->blue
.length
= 5;
224 var
->transp
.length
= 0;
226 case GLAMO_LCD_SRC_ARGB1555
:
227 var
->transp
.offset
= 15;
228 var
->red
.offset
= 10;
229 var
->green
.offset
= 5;
230 var
->blue
.offset
= 0;
231 var
->transp
.length
= 1;
233 var
->green
.length
= 5;
234 var
->blue
.length
= 5;
236 case GLAMO_LCD_SRC_ARGB4444
:
237 var
->transp
.offset
= 12;
239 var
->green
.offset
= 4;
240 var
->blue
.offset
= 0;
241 var
->transp
.length
= 4;
243 var
->green
.length
= 4;
244 var
->blue
.length
= 4;
251 /* The Smedia Glamo doesn't support anything but 16bit color */
253 "Smedia driver does not [yet?] support 24/32bpp\n");
260 static void reg_set_bit_mask(struct glamofb_handle
*glamo
,
261 u_int16_t reg
, u_int16_t mask
,
268 tmp
= reg_read(glamo
, reg
);
271 reg_write(glamo
, reg
, tmp
);
274 #define GLAMO_LCD_WIDTH_MASK 0x03FF
275 #define GLAMO_LCD_HEIGHT_MASK 0x03FF
276 #define GLAMO_LCD_PITCH_MASK 0x07FE
277 #define GLAMO_LCD_HV_TOTAL_MASK 0x03FF
278 #define GLAMO_LCD_HV_RETR_START_MASK 0x03FF
279 #define GLAMO_LCD_HV_RETR_END_MASK 0x03FF
280 #define GLAMO_LCD_HV_RETR_DISP_START_MASK 0x03FF
281 #define GLAMO_LCD_HV_RETR_DISP_END_MASK 0x03FF
283 /* the caller has to enxure lock_cmd is held and we are in cmd mode */
284 static void __rotate_lcd(struct glamofb_handle
*glamo
, __u32 rotation
)
288 if (glamo
->mach_info
->glamo
->suspending
) {
289 dev_err(&glamo
->mach_info
->glamo
->pdev
->dev
,
290 "IGNORING rotate_lcd while "
297 glamo_rot
= GLAMO_LCD_ROT_MODE_90
;
300 glamo_rot
= GLAMO_LCD_ROT_MODE_180
;
303 glamo_rot
= GLAMO_LCD_ROT_MODE_270
;
306 glamo_rot
= GLAMO_LCD_ROT_MODE_0
;
310 reg_set_bit_mask(glamo
,
312 GLAMO_LCD_ROT_MODE_MASK
,
314 reg_set_bit_mask(glamo
,
316 GLAMO_LCD_MODE1_ROTATE_EN
,
317 (glamo_rot
!= GLAMO_LCD_ROT_MODE_0
) ?
318 GLAMO_LCD_MODE1_ROTATE_EN
: 0);
321 static void glamofb_program_mode(struct glamofb_handle
* gfb
) {
322 int sync
, bp
, disp
, fp
, total
;
324 struct glamo_core
*gcore
= gfb
->mach_info
->glamo
;
325 struct fb_var_screeninfo
*var
= &gfb
->fb
->var
;
327 dev_dbg(&gcore
->pdev
->dev
,
328 "glamofb_program_mode spin_lock_irqsave\n");
329 spin_lock_irqsave(&gfb
->lock_cmd
, flags
);
331 if (glamofb_cmd_mode(gfb
, 1))
335 glamo_engine_reclock(gcore
,
337 gfb
->fb
->var
.pixclock
);
339 reg_set_bit_mask(gfb
,
341 GLAMO_LCD_WIDTH_MASK
,
343 reg_set_bit_mask(gfb
,
344 GLAMO_REG_LCD_HEIGHT
,
345 GLAMO_LCD_HEIGHT_MASK
,
347 reg_set_bit_mask(gfb
,
349 GLAMO_LCD_PITCH_MASK
,
350 gfb
->fb
->fix
.line_length
);
352 /* honour the rotation request */
353 __rotate_lcd(gfb
, var
->rotate
);
355 /* update scannout timings */
357 bp
= sync
+ var
->hsync_len
;
358 disp
= bp
+ var
->left_margin
;
359 fp
= disp
+ var
->xres
;
360 total
= fp
+ var
->right_margin
;
362 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_HORIZ_TOTAL
,
363 GLAMO_LCD_HV_TOTAL_MASK
, total
);
364 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_HORIZ_RETR_START
,
365 GLAMO_LCD_HV_RETR_START_MASK
, sync
);
366 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_HORIZ_RETR_END
,
367 GLAMO_LCD_HV_RETR_END_MASK
, bp
);
368 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_HORIZ_DISP_START
,
369 GLAMO_LCD_HV_RETR_DISP_START_MASK
, disp
);
370 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_HORIZ_DISP_END
,
371 GLAMO_LCD_HV_RETR_DISP_END_MASK
, fp
);
374 bp
= sync
+ var
->vsync_len
;
375 disp
= bp
+ var
->upper_margin
;
376 fp
= disp
+ var
->yres
;
377 total
= fp
+ var
->lower_margin
;
379 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_VERT_TOTAL
,
380 GLAMO_LCD_HV_TOTAL_MASK
, total
);
381 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_VERT_RETR_START
,
382 GLAMO_LCD_HV_RETR_START_MASK
, sync
);
383 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_VERT_RETR_END
,
384 GLAMO_LCD_HV_RETR_END_MASK
, bp
);
385 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_VERT_DISP_START
,
386 GLAMO_LCD_HV_RETR_DISP_START_MASK
, disp
);
387 reg_set_bit_mask(gfb
, GLAMO_REG_LCD_VERT_DISP_END
,
388 GLAMO_LCD_HV_RETR_DISP_END_MASK
, fp
);
390 glamofb_cmd_mode(gfb
, 0);
395 dev_dbg(&gcore
->pdev
->dev
,
396 "glamofb_program_mode spin_unlock_irqrestore\n");
397 spin_unlock_irqrestore(&gfb
->lock_cmd
, flags
);
401 static int glamofb_pan_display(struct fb_var_screeninfo
*var
,
402 struct fb_info
*info
)
407 static struct fb_videomode
*glamofb_find_mode(struct fb_info
*info
,
408 struct fb_var_screeninfo
*var
) {
409 struct glamofb_handle
*glamo
= info
->par
;
410 struct glamofb_platform_data
*mach_info
= glamo
->mach_info
;
411 struct fb_videomode
*mode
;
414 for(i
= mach_info
->num_modes
, mode
= mach_info
->modes
; i
> 0; --i
, ++mode
) {
415 if (mode
->xres
== var
->xres
&&
416 mode
->yres
== var
->yres
)
423 static int glamofb_set_par(struct fb_info
*info
)
425 struct glamofb_handle
*glamo
= info
->par
;
426 struct fb_var_screeninfo
*var
= &info
->var
;
427 struct fb_videomode
*mode
;
429 if (glamo
->mach_info
->glamo
->suspending
) {
430 dev_err(&glamo
->mach_info
->glamo
->pdev
->dev
,
431 "IGNORING glamofb_set_par while "
436 mode
= glamofb_find_mode(info
, var
);
440 fb_videomode_to_var(var
, mode
);
446 switch(var
->rotate
) {
449 info
->fix
.line_length
= (var
->yres
* var
->bits_per_pixel
) / 8;
450 /* FIXME: Limit pixelclock */
454 info
->fix
.line_length
= (var
->xres
* var
->bits_per_pixel
) / 8;
458 if(glamo
->output_enabled
)
459 glamofb_program_mode(glamo
);
464 static int glamofb_blank(int blank_mode
, struct fb_info
*info
)
466 struct glamofb_handle
*gfb
= info
->par
;
468 dev_dbg(gfb
->dev
, "glamofb_blank(%u)\n", blank_mode
);
470 switch (blank_mode
) {
471 case FB_BLANK_VSYNC_SUSPEND
:
472 case FB_BLANK_HSYNC_SUSPEND
:
473 /* FIXME: add pdata hook/flag to indicate whether
474 * we should already switch off pixel clock here */
476 case FB_BLANK_POWERDOWN
:
477 /* disable the pixel clock */
478 glamo_output_disable(gfb
);
479 gfb
->blank_mode
= blank_mode
;
481 case FB_BLANK_UNBLANK
:
482 case FB_BLANK_NORMAL
:
483 glamo_output_enable(gfb
);
484 gfb
->blank_mode
= blank_mode
;
488 /* FIXME: once we have proper clock management in glamo-core,
489 * we can determine if other units need MCLK1 or the PLL, and
490 * disable it if not used. */
494 static inline unsigned int chan_to_field(unsigned int chan
,
495 struct fb_bitfield
*bf
)
498 chan
>>= 16 - bf
->length
;
499 return chan
<< bf
->offset
;
502 static int glamofb_setcolreg(unsigned regno
,
503 unsigned red
, unsigned green
, unsigned blue
,
504 unsigned transp
, struct fb_info
*info
)
506 struct glamofb_handle
*glamo
= info
->par
;
509 if (glamo
->mach_info
->glamo
->suspending
) {
510 dev_err(&glamo
->mach_info
->glamo
->pdev
->dev
,
511 "IGNORING glamofb_set_par while "
516 switch (glamo
->fb
->fix
.visual
) {
517 case FB_VISUAL_TRUECOLOR
:
518 case FB_VISUAL_DIRECTCOLOR
:
519 /* true-colour, use pseuo-palette */
522 u32
*pal
= glamo
->fb
->pseudo_palette
;
524 val
= chan_to_field(red
, &glamo
->fb
->var
.red
);
525 val
|= chan_to_field(green
, &glamo
->fb
->var
.green
);
526 val
|= chan_to_field(blue
, &glamo
->fb
->var
.blue
);
532 return 1; /* unknown type */
538 #ifdef CONFIG_MFD_GLAMO_HWACCEL
539 static inline void glamofb_vsync_wait(struct glamofb_handle
*glamo
,
540 int line
, int size
, int range
)
545 count
[0] = reg_read(glamo
, GLAMO_REG_LCD_STATUS2
) & 0x3ff;
546 count
[1] = reg_read(glamo
, GLAMO_REG_LCD_STATUS2
) & 0x3ff;
547 } while (count
[0] != count
[1] ||
548 (line
< count
[0] + range
&&
549 size
> count
[0] - range
) ||
550 count
[0] < range
* 2);
554 * Enable/disable the hardware cursor mode altogether
555 * (for blinking and such, use glamofb_cursor()).
557 static void glamofb_cursor_onoff(struct glamofb_handle
*glamo
, int on
)
561 if (glamo
->cursor_on
) {
562 y
= reg_read(glamo
, GLAMO_REG_LCD_CURSOR_Y_POS
);
563 size
= reg_read(glamo
, GLAMO_REG_LCD_CURSOR_Y_SIZE
);
565 glamofb_vsync_wait(glamo
, y
, size
, 30);
568 reg_set_bit_mask(glamo
, GLAMO_REG_LCD_MODE1
,
569 GLAMO_LCD_MODE1_CURSOR_EN
,
570 on
? GLAMO_LCD_MODE1_CURSOR_EN
: 0);
571 glamo
->cursor_on
= on
;
573 /* Hide the cursor by default */
574 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_X_SIZE
, 0);
577 static int glamofb_cursor(struct fb_info
*info
, struct fb_cursor
*cursor
)
579 struct glamofb_handle
*glamo
= info
->par
;
582 spin_lock_irqsave(&glamo
->lock_cmd
, flags
);
584 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_X_SIZE
,
585 cursor
->enable
? cursor
->image
.width
: 0);
587 if (cursor
->set
& FB_CUR_SETPOS
) {
588 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_X_POS
,
590 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_Y_POS
,
594 if (cursor
->set
& FB_CUR_SETCMAP
) {
595 uint16_t fg
= glamo
->pseudo_pal
[cursor
->image
.fg_color
];
596 uint16_t bg
= glamo
->pseudo_pal
[cursor
->image
.bg_color
];
598 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_FG_COLOR
, fg
);
599 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_BG_COLOR
, bg
);
600 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_DST_COLOR
, fg
);
603 if (cursor
->set
& FB_CUR_SETHOT
)
604 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_PRESET
,
605 (cursor
->hot
.x
<< 8) | cursor
->hot
.y
);
607 if ((cursor
->set
& FB_CUR_SETSIZE
) ||
608 (cursor
->set
& (FB_CUR_SETIMAGE
| FB_CUR_SETSHAPE
))) {
610 const uint8_t *pcol
= cursor
->image
.data
;
611 const uint8_t *pmsk
= cursor
->mask
;
612 uint8_t __iomem
*dst
= glamo
->cursor_addr
;
617 if (cursor
->image
.depth
> 1) {
618 spin_unlock_irqrestore(&glamo
->lock_cmd
, flags
);
622 pitch
= ((cursor
->image
.width
+ 7) >> 2) & ~1;
623 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_PITCH
,
625 reg_write(glamo
, GLAMO_REG_LCD_CURSOR_Y_SIZE
,
626 cursor
->image
.height
);
628 for (y
= 0; y
< cursor
->image
.height
; y
++) {
630 for (x
= 0; x
< cursor
->image
.width
; x
++) {
639 if (cursor
->rop
== ROP_COPY
)
641 (dcol
& 1) ? 1 : 3 : 0;
643 op
= ((dmsk
& 1) << 1) |
645 byte
|= op
<< ((x
& 3) << 1);
648 writeb(byte
, dst
+ x
/ 4);
653 writeb(byte
, dst
+ x
/ 4);
661 spin_unlock_irqrestore(&glamo
->lock_cmd
, flags
);
667 static inline int glamofb_cmdq_empty(struct glamofb_handle
*gfb
)
669 /* DGCMdQempty -- 1 == command queue is empty */
670 return reg_read(gfb
, GLAMO_REG_LCD_STATUS1
) & (1 << 15);
673 /* call holding gfb->lock_cmd when locking, until you unlock */
674 int glamofb_cmd_mode(struct glamofb_handle
*gfb
, int on
)
676 int timeout
= 2000000;
678 if (gfb
->mach_info
->glamo
->suspending
) {
679 dev_err(&gfb
->mach_info
->glamo
->pdev
->dev
,
680 "IGNORING glamofb_cmd_mode while "
685 dev_dbg(gfb
->dev
, "glamofb_cmd_mode(gfb=%p, on=%d)\n", gfb
, on
);
687 dev_dbg(gfb
->dev
, "%s: waiting for cmdq empty: ",
689 while ((!glamofb_cmdq_empty(gfb
)) && (timeout
--))
692 printk(KERN_ERR
"*************"
693 "glamofb cmd_queue never got empty"
697 dev_dbg(gfb
->dev
, "empty!\n");
699 /* display the entire frame then switch to command */
700 reg_write(gfb
, GLAMO_REG_LCD_COMMAND1
,
701 GLAMO_LCD_CMD_TYPE_DISP
|
702 GLAMO_LCD_CMD_DATA_FIRE_VSYNC
);
704 /* wait until lcd idle */
705 dev_dbg(gfb
->dev
, "waiting for lcd idle: ");
707 while ((!reg_read(gfb
, GLAMO_REG_LCD_STATUS2
) & (1 << 12)) &&
711 printk(KERN_ERR
"*************"
712 "glamofb lcd never idle"
719 dev_dbg(gfb
->dev
, "cmd mode entered\n");
722 /* RGB interface needs vsync/hsync */
723 if (reg_read(gfb
, GLAMO_REG_LCD_MODE3
) & GLAMO_LCD_MODE3_RGB
)
724 reg_write(gfb
, GLAMO_REG_LCD_COMMAND1
,
725 GLAMO_LCD_CMD_TYPE_DISP
|
726 GLAMO_LCD_CMD_DATA_DISP_SYNC
);
728 reg_write(gfb
, GLAMO_REG_LCD_COMMAND1
,
729 GLAMO_LCD_CMD_TYPE_DISP
|
730 GLAMO_LCD_CMD_DATA_DISP_FIRE
);
735 EXPORT_SYMBOL_GPL(glamofb_cmd_mode
);
738 int glamofb_cmd_write(struct glamofb_handle
*gfb
, u_int16_t val
)
740 int timeout
= 200000;
742 if (gfb
->mach_info
->glamo
->suspending
) {
743 dev_err(&gfb
->mach_info
->glamo
->pdev
->dev
,
744 "IGNORING glamofb_cmd_write while "
749 dev_dbg(gfb
->dev
, "%s: waiting for cmdq empty\n", __func__
);
750 while ((!glamofb_cmdq_empty(gfb
)) && (timeout
--))
753 printk(KERN_ERR
"*************"
754 "glamofb cmd_queue never got empty"
758 dev_dbg(gfb
->dev
, "idle, writing 0x%04x\n", val
);
760 reg_write(gfb
, GLAMO_REG_LCD_COMMAND1
, val
);
764 EXPORT_SYMBOL_GPL(glamofb_cmd_write
);
766 static struct fb_ops glamofb_ops
= {
767 .owner
= THIS_MODULE
,
768 .fb_check_var
= glamofb_check_var
,
769 .fb_pan_display
= glamofb_pan_display
,
770 .fb_set_par
= glamofb_set_par
,
771 .fb_blank
= glamofb_blank
,
772 .fb_setcolreg
= glamofb_setcolreg
,
773 #ifdef CONFIG_MFD_GLAMO_HWACCEL
774 .fb_cursor
= glamofb_cursor
,
776 .fb_fillrect
= cfb_fillrect
,
777 .fb_copyarea
= cfb_copyarea
,
778 .fb_imageblit
= cfb_imageblit
,
781 static int glamofb_init_regs(struct glamofb_handle
*glamo
)
783 struct fb_info
*info
= glamo
->fb
;
785 glamofb_check_var(&info
->var
, info
);
786 glamofb_run_script(glamo
, glamo_regs
, ARRAY_SIZE(glamo_regs
));
787 glamofb_set_par(info
);
792 static int __init
glamofb_probe(struct platform_device
*pdev
)
795 struct fb_info
*fbinfo
;
796 struct glamofb_handle
*glamofb
;
797 struct glamofb_platform_data
*mach_info
= pdev
->dev
.platform_data
;
799 printk(KERN_INFO
"SMEDIA Glamo frame buffer driver (C) 2007 "
802 fbinfo
= framebuffer_alloc(sizeof(struct glamofb_handle
), &pdev
->dev
);
806 glamofb
= fbinfo
->par
;
807 glamofb
->fb
= fbinfo
;
808 glamofb
->dev
= &pdev
->dev
;
810 glamofb
->blank_mode
= FB_BLANK_POWERDOWN
;
812 strcpy(fbinfo
->fix
.id
, "SMedia Glamo");
814 glamofb
->reg
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
,
817 dev_err(&pdev
->dev
, "platform device with no registers?\n");
822 glamofb
->fb_res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
,
824 if (!glamofb
->fb_res
) {
825 dev_err(&pdev
->dev
, "platform device with no memory ?\n");
830 glamofb
->reg
= request_mem_region(glamofb
->reg
->start
,
831 resource_size(glamofb
->reg
), pdev
->name
);
833 dev_err(&pdev
->dev
, "failed to request mmio region\n");
837 glamofb
->fb_res
= request_mem_region(glamofb
->fb_res
->start
,
838 mach_info
->fb_mem_size
,
840 if (!glamofb
->fb_res
) {
841 dev_err(&pdev
->dev
, "failed to request vram region\n");
842 goto out_release_reg
;
845 /* we want to remap only the registers required for this core
847 glamofb
->base
= ioremap_nocache(glamofb
->reg
->start
, resource_size(glamofb
->reg
));
848 if (!glamofb
->base
) {
849 dev_err(&pdev
->dev
, "failed to ioremap() mmio memory\n");
852 fbinfo
->fix
.smem_start
= (unsigned long) glamofb
->fb_res
->start
;
853 fbinfo
->fix
.smem_len
= (__u32
) resource_size(glamofb
->fb_res
);
855 fbinfo
->screen_base
= ioremap(glamofb
->fb_res
->start
,
856 resource_size(glamofb
->fb_res
));
857 if (!fbinfo
->screen_base
) {
858 dev_err(&pdev
->dev
, "failed to ioremap() vram memory\n");
861 glamofb
->cursor_addr
= fbinfo
->screen_base
+ 0x12C000;
863 platform_set_drvdata(pdev
, glamofb
);
865 glamofb
->mach_info
= pdev
->dev
.platform_data
;
867 fbinfo
->fix
.visual
= FB_VISUAL_TRUECOLOR
;
868 fbinfo
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
869 fbinfo
->fix
.type_aux
= 0;
870 fbinfo
->fix
.xpanstep
= 0;
871 fbinfo
->fix
.ypanstep
= 0;
872 fbinfo
->fix
.ywrapstep
= 0;
873 fbinfo
->fix
.accel
= FB_ACCEL_GLAMO
;
876 fbinfo
->fbops
= &glamofb_ops
;
877 fbinfo
->flags
= FBINFO_FLAG_DEFAULT
;
878 fbinfo
->pseudo_palette
= &glamofb
->pseudo_pal
;
880 fbinfo
->mode
= mach_info
->modes
;
881 fb_videomode_to_var(&fbinfo
->var
, fbinfo
->mode
);
882 fbinfo
->var
.bits_per_pixel
= 16;
883 fbinfo
->var
.nonstd
= 0;
884 fbinfo
->var
.activate
= FB_ACTIVATE_NOW
;
885 fbinfo
->var
.height
= mach_info
->height
;
886 fbinfo
->var
.width
= mach_info
->width
;
887 fbinfo
->var
.accel_flags
= 0;
888 fbinfo
->var
.vmode
= FB_VMODE_NONINTERLACED
;
890 glamo_engine_enable(mach_info
->glamo
, GLAMO_ENGINE_LCD
);
891 glamo_engine_reset(mach_info
->glamo
, GLAMO_ENGINE_LCD
);
892 glamofb
->output_enabled
= 1;
893 glamofb
->mode_set
= 1;
895 dev_info(&pdev
->dev
, "spin_lock_init\n");
896 spin_lock_init(&glamofb
->lock_cmd
);
897 glamofb_init_regs(glamofb
);
898 #ifdef CONFIG_MFD_GLAMO_HWACCEL
899 glamofb_cursor_onoff(glamofb
, 1);
902 fb_videomode_to_modelist(mach_info
->modes
, mach_info
->num_modes
,
905 rc
= register_framebuffer(fbinfo
);
907 dev_err(&pdev
->dev
, "failed to register framebuffer\n");
911 if (mach_info
->spi_info
) {
912 /* register the sibling spi device */
913 mach_info
->spi_info
->glamofb_handle
= glamofb
;
914 glamo_spi_dev
.dev
.parent
= &pdev
->dev
;
915 glamo_spi_dev
.dev
.platform_data
= mach_info
->spi_info
;
916 platform_device_register(&glamo_spi_dev
);
919 printk(KERN_INFO
"fb%d: %s frame buffer device\n",
920 fbinfo
->node
, fbinfo
->fix
.id
);
925 iounmap(fbinfo
->screen_base
);
926 iounmap(glamofb
->base
);
928 release_mem_region(glamofb
->fb_res
->start
, resource_size(glamofb
->fb_res
));
930 release_mem_region(glamofb
->reg
->start
, resource_size(glamofb
->reg
));
932 framebuffer_release(fbinfo
);
936 static int glamofb_remove(struct platform_device
*pdev
)
938 struct glamofb_handle
*glamofb
= platform_get_drvdata(pdev
);
940 platform_set_drvdata(pdev
, NULL
);
941 iounmap(glamofb
->base
);
942 release_mem_region(glamofb
->reg
->start
, resource_size(glamofb
->reg
));
950 static int glamofb_suspend(struct platform_device
*pdev
, pm_message_t state
)
952 struct glamofb_handle
*gfb
= platform_get_drvdata(pdev
);
954 /* we need to stop anything touching our framebuffer */
955 fb_set_suspend(gfb
->fb
, 1);
957 /* seriously -- nobody is allowed to touch glamo memory when we
958 * are suspended or we lock on nWAIT
960 /* iounmap(gfb->fb->screen_base); */
965 static int glamofb_resume(struct platform_device
*pdev
)
967 struct glamofb_handle
*gfb
= platform_get_drvdata(pdev
);
968 struct glamofb_platform_data
*mach_info
= pdev
->dev
.platform_data
;
970 /* OK let's allow framebuffer ops again */
971 /* gfb->fb->screen_base = ioremap(gfb->fb_res->start,
972 resource_size(gfb->fb_res)); */
973 glamo_engine_enable(mach_info
->glamo
, GLAMO_ENGINE_LCD
);
974 glamo_engine_reset(mach_info
->glamo
, GLAMO_ENGINE_LCD
);
976 printk(KERN_ERR
"spin_lock_init\n");
977 spin_lock_init(&gfb
->lock_cmd
);
978 glamofb_init_regs(gfb
);
979 #ifdef CONFIG_MFD_GLAMO_HWACCEL
980 glamofb_cursor_onoff(gfb
, 1);
983 fb_set_suspend(gfb
->fb
, 0);
988 #define glamofb_suspend NULL
989 #define glamofb_resume NULL
992 static struct platform_driver glamofb_driver
= {
993 .probe
= glamofb_probe
,
994 .remove
= glamofb_remove
,
995 .suspend
= glamofb_suspend
,
996 .resume
= glamofb_resume
,
999 .owner
= THIS_MODULE
,
1003 static int __devinit
glamofb_init(void)
1005 return platform_driver_register(&glamofb_driver
);
1008 static void __exit
glamofb_cleanup(void)
1010 platform_driver_unregister(&glamofb_driver
);
1013 module_init(glamofb_init
);
1014 module_exit(glamofb_cleanup
);
1016 MODULE_AUTHOR("Harald Welte <laforge@openmoko.org>");
1017 MODULE_DESCRIPTION("Smedia Glamo 336x/337x framebuffer driver");
1018 MODULE_LICENSE("GPL");