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__); \
65 #define RESSIZE(ressource) (((ressource)->end - (ressource)->start)+1)
67 struct glamofb_handle {
71 struct resource *fb_res;
73 struct glamofb_platform_data *mach_info;
74 char __iomem *cursor_addr;
76 u_int32_t pseudo_pal[16];
78 int angle; /* Current rotation angle */
82 /* 'sibling' spi device for lcm init */
83 static struct platform_device glamo_spi_dev = {
84 .name = "glamo-lcm-spi",
88 static int reg_read(struct glamofb_handle *glamo,
93 for (i = 0; i != 2; i++)
96 return readw(glamo->base + reg);
99 static void reg_write(struct glamofb_handle *glamo,
100 u_int16_t reg, u_int16_t val)
104 for (i = 0; i != 2; i++)
107 writew(val, glamo->base + reg);
110 static struct glamo_script glamo_regs[] = {
111 { GLAMO_REG_LCD_MODE1, 0x0020 },
112 /* no display rotation, no hardware cursor, no dither, no gamma,
113 * no retrace flip, vsync low-active, hsync low active,
114 * no TVCLK, no partial display, hw dest color from fb,
115 * no partial display mode, LCD1, software flip, */
116 { GLAMO_REG_LCD_MODE2, 0x9020 },
117 /* video flip, no ptr, no ptr, dhclk off,
118 * normal mode, no cpuif,
119 * res, serial msb first, single fb, no fr ctrl,
120 * cpu if bits all zero, no crc
121 * 0000 0000 0010 0000 */
122 { GLAMO_REG_LCD_MODE3, 0x0b40 },
123 /* src data rgb565, res, 18bit rgb666
124 * 000 01 011 0100 0000 */
125 { GLAMO_REG_LCD_POLARITY, 0x440c },
126 /* DE high active, no cpu/lcd if, cs0 force low, a0 low active,
127 * np cpu if, 9bit serial data, sclk rising edge latch data
128 * 01 00 0 100 0 000 01 0 0 */
129 /* The following values assume 640*480@16bpp */
130 { GLAMO_REG_LCD_A_BASE1, 0x0000 }, /* display A base address 15:0 */
131 { GLAMO_REG_LCD_A_BASE2, 0x0000 }, /* display A base address 22:16 */
132 { GLAMO_REG_LCD_B_BASE1, 0x6000 }, /* display B base address 15:0 */
133 { GLAMO_REG_LCD_B_BASE2, 0x0009 }, /* display B base address 22:16 */
134 { GLAMO_REG_LCD_CURSOR_BASE1, 0xC000 }, /* cursor base address 15:0 */
135 { GLAMO_REG_LCD_CURSOR_BASE2, 0x0012 }, /* cursor base address 22:16 */
136 { GLAMO_REG_LCD_COMMAND2, 0x0000 }, /* display page A */
139 static int glamofb_run_script(struct glamofb_handle *glamo,
140 struct glamo_script *script, int len)
144 if (glamo->mach_info->glamo->suspending) {
145 dev_err(&glamo->mach_info->glamo->pdev->dev,
146 "IGNORING glamofb_run_script while "
151 for (i = 0; i < len; i++) {
152 struct glamo_script *line = &script[i];
154 if (line->reg == 0xffff)
156 else if (line->reg == 0xfffe)
159 reg_write(glamo, script[i].reg, script[i].val);
165 static int glamofb_check_var(struct fb_var_screeninfo *var,
166 struct fb_info *info)
168 struct glamofb_handle *glamo = info->par;
170 if (glamo->mach_info->glamo->suspending) {
171 dev_err(&glamo->mach_info->glamo->pdev->dev,
172 "IGNORING glamofb_check_var while "
177 if (var->yres > glamo->mach_info->yres.max)
178 var->yres = glamo->mach_info->yres.max;
179 else if (var->yres < glamo->mach_info->yres.min)
180 var->yres = glamo->mach_info->yres.min;
182 if (var->xres > glamo->mach_info->xres.max)
183 var->xres = glamo->mach_info->xres.max;
184 else if (var->xres < glamo->mach_info->xres.min)
185 var->xres = glamo->mach_info->xres.min;
187 if (var->bits_per_pixel > glamo->mach_info->bpp.max)
188 var->bits_per_pixel = glamo->mach_info->bpp.max;
189 else if (var->bits_per_pixel < glamo->mach_info->bpp.min)
190 var->bits_per_pixel = glamo->mach_info->bpp.min;
192 /* FIXME: set rgb positions */
193 switch (var->bits_per_pixel) {
195 switch (reg_read(glamo, GLAMO_REG_LCD_MODE3) & 0xc000) {
196 case GLAMO_LCD_SRC_RGB565:
197 var->red.offset = 11;
198 var->green.offset = 5;
199 var->blue.offset = 0;
201 var->green.length = 6;
202 var->blue.length = 5;
203 var->transp.length = 0;
205 case GLAMO_LCD_SRC_ARGB1555:
206 var->transp.offset = 15;
207 var->red.offset = 10;
208 var->green.offset = 5;
209 var->blue.offset = 0;
210 var->transp.length = 1;
212 var->green.length = 5;
213 var->blue.length = 5;
215 case GLAMO_LCD_SRC_ARGB4444:
216 var->transp.offset = 12;
218 var->green.offset = 4;
219 var->blue.offset = 0;
220 var->transp.length = 4;
222 var->green.length = 4;
223 var->blue.length = 4;
230 /* The Smedia Glamo doesn't support anything but 16bit color */
232 "Smedia driver does not [yet?] support 24/32bpp\n");
239 static void reg_set_bit_mask(struct glamofb_handle *glamo,
240 u_int16_t reg, u_int16_t mask,
247 tmp = reg_read(glamo, reg);
250 reg_write(glamo, reg, tmp);
253 #define GLAMO_LCD_WIDTH_MASK 0x03FF
254 #define GLAMO_LCD_HEIGHT_MASK 0x03FF
255 #define GLAMO_LCD_PITCH_MASK 0x07FE
256 #define GLAMO_LCD_HV_TOTAL_MASK 0x03FF
257 #define GLAMO_LCD_HV_RETR_START_MASK 0x03FF
258 #define GLAMO_LCD_HV_RETR_END_MASK 0x03FF
259 #define GLAMO_LCD_HV_RETR_DISP_START_MASK 0x03FF
260 #define GLAMO_LCD_HV_RETR_DISP_END_MASK 0x03FF
262 enum orientation {ORIENTATION_PORTRAIT, ORIENTATION_LANDSCAPE};
264 /* the caller has to enxure lock_cmd is held and we are in cmd mode */
265 static void __rotate_lcd(struct glamofb_handle *glamo, __u32 rotation)
269 if (glamo->mach_info->glamo->suspending) {
270 dev_err(&glamo->mach_info->glamo->pdev->dev,
271 "IGNORING rotate_lcd while "
278 glamo_rot = GLAMO_LCD_ROT_MODE_0;
282 glamo_rot = GLAMO_LCD_ROT_MODE_90;
286 glamo_rot = GLAMO_LCD_ROT_MODE_180;
290 glamo_rot = GLAMO_LCD_ROT_MODE_270;
295 glamo_rot = GLAMO_LCD_ROT_MODE_0;
299 reg_set_bit_mask(glamo,
301 GLAMO_LCD_ROT_MODE_MASK,
303 reg_set_bit_mask(glamo,
305 GLAMO_LCD_MODE1_ROTATE_EN,
306 (glamo_rot != GLAMO_LCD_ROT_MODE_0) ?
307 GLAMO_LCD_MODE1_ROTATE_EN : 0);
310 static enum orientation get_orientation(struct fb_var_screeninfo *var)
312 if (var->xres <= var->yres)
313 return ORIENTATION_PORTRAIT;
315 return ORIENTATION_LANDSCAPE;
318 static int will_orientation_change(struct fb_var_screeninfo *var)
320 enum orientation orient = get_orientation(var);
323 case ORIENTATION_LANDSCAPE:
324 if (var->rotate == FB_ROTATE_UR || var->rotate == FB_ROTATE_UD)
327 case ORIENTATION_PORTRAIT:
328 if (var->rotate == FB_ROTATE_CW || var->rotate == FB_ROTATE_CCW)
335 static void glamofb_update_lcd_controller(struct glamofb_handle *glamo,
336 struct fb_var_screeninfo *var)
338 int sync, bp, disp, fp, total, xres, yres, pitch;
339 int uninitialized_var(orientation_changing);
345 if (glamo->mach_info->glamo->suspending) {
346 dev_err(&glamo->mach_info->glamo->pdev->dev,
347 "IGNORING glamofb_update_lcd_controller while "
352 dev_dbg(&glamo->mach_info->glamo->pdev->dev,
353 "glamofb_update_lcd_controller spin_lock_irqsave\n");
354 spin_lock_irqsave(&glamo->lock_cmd, flags);
356 if (glamofb_cmd_mode(glamo, 1))
359 /* if (var->pixclock)
360 glamo_engine_reclock(glamo->mach_info->glamo,
367 orientation_changing = will_orientation_change(var);
368 /* Adjust the pitch according to new orientation to come. */
369 if (orientation_changing)
370 pitch = var->yres * var->bits_per_pixel / 8;
372 pitch = var->xres * var->bits_per_pixel / 8;
374 reg_set_bit_mask(glamo,
376 GLAMO_LCD_WIDTH_MASK,
378 reg_set_bit_mask(glamo,
379 GLAMO_REG_LCD_HEIGHT,
380 GLAMO_LCD_HEIGHT_MASK,
382 reg_set_bit_mask(glamo,
384 GLAMO_LCD_PITCH_MASK,
387 /* honour the rotation request */
388 __rotate_lcd(glamo, var->rotate);
390 if (orientation_changing) {
391 var->xres_virtual = yres;
393 var->xres_virtual *= 2;
394 var->yres_virtual = xres;
397 var->xres_virtual = xres;
398 var->yres_virtual = yres;
399 var->yres_virtual *= 2;
402 /* update scannout timings */
404 bp = sync + var->hsync_len;
405 disp = bp + var->left_margin;
407 total = fp + var->right_margin;
409 reg_set_bit_mask(glamo, GLAMO_REG_LCD_HORIZ_TOTAL,
410 GLAMO_LCD_HV_TOTAL_MASK, total);
411 reg_set_bit_mask(glamo, GLAMO_REG_LCD_HORIZ_RETR_START,
412 GLAMO_LCD_HV_RETR_START_MASK, sync);
413 reg_set_bit_mask(glamo, GLAMO_REG_LCD_HORIZ_RETR_END,
414 GLAMO_LCD_HV_RETR_END_MASK, bp);
415 reg_set_bit_mask(glamo, GLAMO_REG_LCD_HORIZ_DISP_START,
416 GLAMO_LCD_HV_RETR_DISP_START_MASK, disp);
417 reg_set_bit_mask(glamo, GLAMO_REG_LCD_HORIZ_DISP_END,
418 GLAMO_LCD_HV_RETR_DISP_END_MASK, fp);
421 bp = sync + var->vsync_len;
422 disp = bp + var->upper_margin;
424 total = fp + var->lower_margin;
426 reg_set_bit_mask(glamo, GLAMO_REG_LCD_VERT_TOTAL,
427 GLAMO_LCD_HV_TOTAL_MASK, total);
428 reg_set_bit_mask(glamo, GLAMO_REG_LCD_VERT_RETR_START,
429 GLAMO_LCD_HV_RETR_START_MASK, sync);
430 reg_set_bit_mask(glamo, GLAMO_REG_LCD_VERT_RETR_END,
431 GLAMO_LCD_HV_RETR_END_MASK, bp);
432 reg_set_bit_mask(glamo, GLAMO_REG_LCD_VERT_DISP_START,
433 GLAMO_LCD_HV_RETR_DISP_START_MASK, disp);
434 reg_set_bit_mask(glamo, GLAMO_REG_LCD_VERT_DISP_END,
435 GLAMO_LCD_HV_RETR_DISP_END_MASK, fp);
437 glamofb_cmd_mode(glamo, 0);
440 dev_dbg(&glamo->mach_info->glamo->pdev->dev,
441 "glamofb_update_lcd_controller spin_unlock_irqrestore\n");
442 spin_unlock_irqrestore(&glamo->lock_cmd, flags);
445 static int glamofb_pan_display(struct fb_var_screeninfo *var,
446 struct fb_info *info)
448 struct glamofb_handle *glamo = info->par;
449 u_int16_t page = var->yoffset / glamo->mach_info->yres.defval;
450 reg_write(glamo, GLAMO_REG_LCD_COMMAND2, page);
455 static int glamofb_set_par(struct fb_info *info)
457 struct glamofb_handle *glamo = info->par;
458 struct fb_var_screeninfo *var = &info->var;
460 if (glamo->mach_info->glamo->suspending) {
461 dev_err(&glamo->mach_info->glamo->pdev->dev,
462 "IGNORING glamofb_set_par while "
467 switch (var->bits_per_pixel) {
469 info->fix.visual = FB_VISUAL_TRUECOLOR;
472 printk("Smedia driver doesn't support != 16bpp\n");
476 info->fix.line_length = (var->xres * var->bits_per_pixel) / 8;
478 glamofb_update_lcd_controller(glamo, var);
484 static void notify_blank(struct fb_info *info, int blank_mode)
486 struct fb_event event;
489 event.data = &blank_mode;
490 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
494 static int glamofb_blank(int blank_mode, struct fb_info *info)
496 struct glamofb_handle *gfb = info->par;
497 struct glamo_core *gcore = gfb->mach_info->glamo;
499 dev_dbg(gfb->dev, "glamofb_blank(%u)\n", blank_mode);
501 switch (blank_mode) {
502 case FB_BLANK_VSYNC_SUSPEND:
503 case FB_BLANK_HSYNC_SUSPEND:
504 /* FIXME: add pdata hook/flag to indicate whether
505 * we should already switch off pixel clock here */
507 case FB_BLANK_POWERDOWN:
508 /* Simulating FB_BLANK_NORMAL allow turning off backlight */
509 if (gfb->blank_mode != FB_BLANK_NORMAL)
510 notify_blank(info, FB_BLANK_NORMAL);
512 /* LCM need notification before pixel clock is stopped */
513 notify_blank(info, blank_mode);
515 /* disable the pixel clock */
516 glamo_engine_clkreg_set(gcore, GLAMO_ENGINE_LCD,
517 GLAMO_CLOCK_LCD_EN_DCLK, 0);
518 gfb->blank_mode = blank_mode;
520 case FB_BLANK_UNBLANK:
521 case FB_BLANK_NORMAL:
522 /* enable the pixel clock if off */
523 if (gfb->blank_mode == FB_BLANK_POWERDOWN)
524 glamo_engine_clkreg_set(gcore,
526 GLAMO_CLOCK_LCD_EN_DCLK,
527 GLAMO_CLOCK_LCD_EN_DCLK);
529 notify_blank(info, blank_mode);
530 gfb->blank_mode = blank_mode;
534 /* FIXME: once we have proper clock management in glamo-core,
535 * we can determine if other units need MCLK1 or the PLL, and
536 * disable it if not used. */
540 static inline unsigned int chan_to_field(unsigned int chan,
541 struct fb_bitfield *bf)
544 chan >>= 16 - bf->length;
545 return chan << bf->offset;
548 static int glamofb_setcolreg(unsigned regno,
549 unsigned red, unsigned green, unsigned blue,
550 unsigned transp, struct fb_info *info)
552 struct glamofb_handle *glamo = info->par;
555 if (glamo->mach_info->glamo->suspending) {
556 dev_err(&glamo->mach_info->glamo->pdev->dev,
557 "IGNORING glamofb_set_par while "
562 switch (glamo->fb->fix.visual) {
563 case FB_VISUAL_TRUECOLOR:
564 case FB_VISUAL_DIRECTCOLOR:
565 /* true-colour, use pseuo-palette */
568 u32 *pal = glamo->fb->pseudo_palette;
570 val = chan_to_field(red, &glamo->fb->var.red);
571 val |= chan_to_field(green, &glamo->fb->var.green);
572 val |= chan_to_field(blue, &glamo->fb->var.blue);
578 return 1; /* unknown type */
584 #ifdef CONFIG_MFD_GLAMO_HWACCEL
585 static inline void glamofb_vsync_wait(struct glamofb_handle *glamo,
586 int line, int size, int range)
591 count[0] = reg_read(glamo, GLAMO_REG_LCD_STATUS2) & 0x3ff;
592 count[1] = reg_read(glamo, GLAMO_REG_LCD_STATUS2) & 0x3ff;
593 } while (count[0] != count[1] ||
594 (line < count[0] + range &&
595 size > count[0] - range) ||
596 count[0] < range * 2);
600 * Enable/disable the hardware cursor mode altogether
601 * (for blinking and such, use glamofb_cursor()).
603 static void glamofb_cursor_onoff(struct glamofb_handle *glamo, int on)
607 if (glamo->cursor_on) {
608 y = reg_read(glamo, GLAMO_REG_LCD_CURSOR_Y_POS);
609 size = reg_read(glamo, GLAMO_REG_LCD_CURSOR_Y_SIZE);
611 glamofb_vsync_wait(glamo, y, size, 30);
614 reg_set_bit_mask(glamo, GLAMO_REG_LCD_MODE1,
615 GLAMO_LCD_MODE1_CURSOR_EN,
616 on ? GLAMO_LCD_MODE1_CURSOR_EN : 0);
617 glamo->cursor_on = on;
619 /* Hide the cursor by default */
620 reg_write(glamo, GLAMO_REG_LCD_CURSOR_X_SIZE, 0);
623 static int glamofb_cursor(struct fb_info *info, struct fb_cursor *cursor)
625 struct glamofb_handle *glamo = info->par;
628 spin_lock_irqsave(&glamo->lock_cmd, flags);
630 reg_write(glamo, GLAMO_REG_LCD_CURSOR_X_SIZE,
631 cursor->enable ? cursor->image.width : 0);
633 if (cursor->set & FB_CUR_SETPOS) {
634 reg_write(glamo, GLAMO_REG_LCD_CURSOR_X_POS,
636 reg_write(glamo, GLAMO_REG_LCD_CURSOR_Y_POS,
640 if (cursor->set & FB_CUR_SETCMAP) {
641 uint16_t fg = glamo->pseudo_pal[cursor->image.fg_color];
642 uint16_t bg = glamo->pseudo_pal[cursor->image.bg_color];
644 reg_write(glamo, GLAMO_REG_LCD_CURSOR_FG_COLOR, fg);
645 reg_write(glamo, GLAMO_REG_LCD_CURSOR_BG_COLOR, bg);
646 reg_write(glamo, GLAMO_REG_LCD_CURSOR_DST_COLOR, fg);
649 if (cursor->set & FB_CUR_SETHOT)
650 reg_write(glamo, GLAMO_REG_LCD_CURSOR_PRESET,
651 (cursor->hot.x << 8) | cursor->hot.y);
653 if ((cursor->set & FB_CUR_SETSIZE) ||
654 (cursor->set & (FB_CUR_SETIMAGE | FB_CUR_SETSHAPE))) {
656 const uint8_t *pcol = cursor->image.data;
657 const uint8_t *pmsk = cursor->mask;
658 uint8_t __iomem *dst = glamo->cursor_addr;
663 if (cursor->image.depth > 1) {
664 spin_unlock_irqrestore(&glamo->lock_cmd, flags);
668 pitch = ((cursor->image.width + 7) >> 2) & ~1;
669 reg_write(glamo, GLAMO_REG_LCD_CURSOR_PITCH,
671 reg_write(glamo, GLAMO_REG_LCD_CURSOR_Y_SIZE,
672 cursor->image.height);
674 for (y = 0; y < cursor->image.height; y++) {
676 for (x = 0; x < cursor->image.width; x++) {
685 if (cursor->rop == ROP_COPY)
687 (dcol & 1) ? 1 : 3 : 0;
689 op = ((dmsk & 1) << 1) |
691 byte |= op << ((x & 3) << 1);
694 writeb(byte, dst + x / 4);
699 writeb(byte, dst + x / 4);
707 spin_unlock_irqrestore(&glamo->lock_cmd, flags);
713 static inline int glamofb_cmdq_empty(struct glamofb_handle *gfb)
715 /* DGCMdQempty -- 1 == command queue is empty */
716 return reg_read(gfb, GLAMO_REG_LCD_STATUS1) & (1 << 15);
719 /* call holding gfb->lock_cmd when locking, until you unlock */
720 int glamofb_cmd_mode(struct glamofb_handle *gfb, int on)
722 int timeout = 2000000;
724 if (gfb->mach_info->glamo->suspending) {
725 dev_err(&gfb->mach_info->glamo->pdev->dev,
726 "IGNORING glamofb_cmd_mode while "
731 dev_dbg(gfb->dev, "glamofb_cmd_mode(gfb=%p, on=%d)\n", gfb, on);
733 dev_dbg(gfb->dev, "%s: waiting for cmdq empty: ",
735 while ((!glamofb_cmdq_empty(gfb)) && (timeout--))
738 printk(KERN_ERR"*************"
739 "glamofb cmd_queue never got empty"
743 dev_dbg(gfb->dev, "empty!\n");
745 /* display the entire frame then switch to command */
746 reg_write(gfb, GLAMO_REG_LCD_COMMAND1,
747 GLAMO_LCD_CMD_TYPE_DISP |
748 GLAMO_LCD_CMD_DATA_FIRE_VSYNC);
750 /* wait until lcd idle */
751 dev_dbg(gfb->dev, "waiting for lcd idle: ");
753 while ((!reg_read(gfb, GLAMO_REG_LCD_STATUS2) & (1 << 12)) &&
757 printk(KERN_ERR"*************"
758 "glamofb lcd never idle"
765 dev_dbg(gfb->dev, "cmd mode entered\n");
768 /* RGB interface needs vsync/hsync */
769 if (reg_read(gfb, GLAMO_REG_LCD_MODE3) & GLAMO_LCD_MODE3_RGB)
770 reg_write(gfb, GLAMO_REG_LCD_COMMAND1,
771 GLAMO_LCD_CMD_TYPE_DISP |
772 GLAMO_LCD_CMD_DATA_DISP_SYNC);
774 reg_write(gfb, GLAMO_REG_LCD_COMMAND1,
775 GLAMO_LCD_CMD_TYPE_DISP |
776 GLAMO_LCD_CMD_DATA_DISP_FIRE);
781 EXPORT_SYMBOL_GPL(glamofb_cmd_mode);
784 int glamofb_cmd_write(struct glamofb_handle *gfb, u_int16_t val)
786 int timeout = 200000;
788 if (gfb->mach_info->glamo->suspending) {
789 dev_err(&gfb->mach_info->glamo->pdev->dev,
790 "IGNORING glamofb_cmd_write while "
795 dev_dbg(gfb->dev, "%s: waiting for cmdq empty\n", __func__);
796 while ((!glamofb_cmdq_empty(gfb)) && (timeout--))
799 printk(KERN_ERR"*************"
800 "glamofb cmd_queue never got empty"
804 dev_dbg(gfb->dev, "idle, writing 0x%04x\n", val);
806 reg_write(gfb, GLAMO_REG_LCD_COMMAND1, val);
810 EXPORT_SYMBOL_GPL(glamofb_cmd_write);
812 static struct fb_ops glamofb_ops = {
813 .owner = THIS_MODULE,
814 .fb_check_var = glamofb_check_var,
815 .fb_pan_display = glamofb_pan_display,
816 .fb_set_par = glamofb_set_par,
817 .fb_blank = glamofb_blank,
818 .fb_setcolreg = glamofb_setcolreg,
819 #ifdef CONFIG_MFD_GLAMO_HWACCEL
820 .fb_cursor = glamofb_cursor,
822 .fb_fillrect = cfb_fillrect,
823 .fb_copyarea = cfb_copyarea,
824 .fb_imageblit = cfb_imageblit,
827 static int glamofb_init_regs(struct glamofb_handle *glamo)
829 struct fb_info *info = glamo->fb;
831 glamofb_check_var(&info->var, info);
832 glamofb_run_script(glamo, glamo_regs, ARRAY_SIZE(glamo_regs));
833 glamofb_set_par(info);
838 static int __init glamofb_probe(struct platform_device *pdev)
841 struct fb_info *fbinfo;
842 struct glamofb_handle *glamofb;
843 struct glamofb_platform_data *mach_info = pdev->dev.platform_data;
845 printk(KERN_INFO "SMEDIA Glamo frame buffer driver (C) 2007 "
848 fbinfo = framebuffer_alloc(sizeof(struct glamofb_handle), &pdev->dev);
852 glamofb = fbinfo->par;
853 glamofb->fb = fbinfo;
854 glamofb->dev = &pdev->dev;
857 glamofb->blank_mode = FB_BLANK_POWERDOWN;
859 strcpy(fbinfo->fix.id, "SMedia Glamo");
861 glamofb->reg = platform_get_resource_byname(pdev, IORESOURCE_MEM,
864 dev_err(&pdev->dev, "platform device with no registers?\n");
869 glamofb->fb_res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
871 if (!glamofb->fb_res) {
872 dev_err(&pdev->dev, "platform device with no memory ?\n");
877 glamofb->reg = request_mem_region(glamofb->reg->start,
878 RESSIZE(glamofb->reg), pdev->name);
880 dev_err(&pdev->dev, "failed to request mmio region\n");
884 glamofb->fb_res = request_mem_region(glamofb->fb_res->start,
885 mach_info->fb_mem_size,
887 if (!glamofb->fb_res) {
888 dev_err(&pdev->dev, "failed to request vram region\n");
889 goto out_release_reg;
892 /* we want to remap only the registers required for this core
894 glamofb->base = ioremap(glamofb->reg->start, RESSIZE(glamofb->reg));
895 if (!glamofb->base) {
896 dev_err(&pdev->dev, "failed to ioremap() mmio memory\n");
899 fbinfo->fix.smem_start = (unsigned long) glamofb->fb_res->start;
900 fbinfo->fix.smem_len = mach_info->fb_mem_size;
902 fbinfo->screen_base = ioremap(glamofb->fb_res->start,
903 RESSIZE(glamofb->fb_res));
904 if (!fbinfo->screen_base) {
905 dev_err(&pdev->dev, "failed to ioremap() vram memory\n");
908 glamofb->cursor_addr = fbinfo->screen_base + 0x12C000;
910 platform_set_drvdata(pdev, glamofb);
912 glamofb->mach_info = pdev->dev.platform_data;
914 fbinfo->fix.visual = FB_VISUAL_TRUECOLOR;
915 fbinfo->fix.type = FB_TYPE_PACKED_PIXELS;
916 fbinfo->fix.type_aux = 0;
917 fbinfo->fix.xpanstep = 0;
918 fbinfo->fix.ypanstep = mach_info->yres.defval;
919 fbinfo->fix.ywrapstep = 0;
920 fbinfo->fix.accel = FB_ACCEL_GLAMO;
922 fbinfo->var.nonstd = 0;
923 fbinfo->var.activate = FB_ACTIVATE_NOW;
924 fbinfo->var.height = mach_info->height;
925 fbinfo->var.width = mach_info->width;
926 fbinfo->var.accel_flags = 0; /* FIXME */
927 fbinfo->var.vmode = FB_VMODE_NONINTERLACED;
929 fbinfo->fbops = &glamofb_ops;
930 fbinfo->flags = FBINFO_FLAG_DEFAULT;
931 fbinfo->pseudo_palette = &glamofb->pseudo_pal;
933 fbinfo->var.xres = mach_info->xres.defval;
934 fbinfo->var.xres_virtual = mach_info->xres.defval;
935 fbinfo->var.yres = mach_info->yres.defval;
936 fbinfo->var.yres_virtual = mach_info->yres.defval * 2;
937 fbinfo->var.bits_per_pixel = mach_info->bpp.defval;
939 fbinfo->var.pixclock = mach_info->pixclock;
940 fbinfo->var.left_margin = mach_info->left_margin;
941 fbinfo->var.right_margin = mach_info->right_margin;
942 fbinfo->var.upper_margin = mach_info->upper_margin;
943 fbinfo->var.lower_margin = mach_info->lower_margin;
944 fbinfo->var.hsync_len = mach_info->hsync_len;
945 fbinfo->var.vsync_len = mach_info->vsync_len;
947 memset(fbinfo->screen_base, 0,
948 mach_info->xres.max *
949 mach_info->yres.max *
950 mach_info->bpp.max / 8);
952 glamo_engine_enable(mach_info->glamo, GLAMO_ENGINE_LCD);
953 glamo_engine_reset(mach_info->glamo, GLAMO_ENGINE_LCD);
955 dev_info(&pdev->dev, "spin_lock_init\n");
956 spin_lock_init(&glamofb->lock_cmd);
957 glamofb_init_regs(glamofb);
958 #ifdef CONFIG_MFD_GLAMO_HWACCEL
959 glamofb_cursor_onoff(glamofb, 1);
962 #ifdef CONFIG_MFD_GLAMO_FB_XGLAMO_WORKAROUND
964 rc = sysfs_create_group(&pdev->dev.kobj, &glamo_fb_attr_group);
966 dev_err(&pdev->dev, "cannot create sysfs group\n");
971 rc = register_framebuffer(fbinfo);
973 dev_err(&pdev->dev, "failed to register framebuffer\n");
977 if (mach_info->spi_info) {
978 /* register the sibling spi device */
979 mach_info->spi_info->glamofb_handle = glamofb;
980 glamo_spi_dev.dev.parent = &pdev->dev;
981 glamo_spi_dev.dev.platform_data = mach_info->spi_info;
982 platform_device_register(&glamo_spi_dev);
985 printk(KERN_INFO "fb%d: %s frame buffer device\n",
986 fbinfo->node, fbinfo->fix.id);
991 iounmap(fbinfo->screen_base);
992 iounmap(glamofb->base);
994 release_mem_region(glamofb->fb_res->start, RESSIZE(glamofb->fb_res));
996 release_mem_region(glamofb->reg->start, RESSIZE(glamofb->reg));
998 framebuffer_release(fbinfo);
1002 static int glamofb_remove(struct platform_device *pdev)
1004 struct glamofb_handle *glamofb = platform_get_drvdata(pdev);
1006 platform_set_drvdata(pdev, NULL);
1007 iounmap(glamofb->base);
1008 release_mem_region(glamofb->reg->start, RESSIZE(glamofb->reg));
1016 static int glamofb_suspend(struct platform_device *pdev, pm_message_t state)
1018 struct glamofb_handle *gfb = platform_get_drvdata(pdev);
1020 /* we need to stop anything touching our framebuffer */
1021 fb_set_suspend(gfb->fb, 1);
1023 /* seriously -- nobody is allowed to touch glamo memory when we
1024 * are suspended or we lock on nWAIT
1026 /* iounmap(gfb->fb->screen_base); */
1031 static int glamofb_resume(struct platform_device *pdev)
1033 struct glamofb_handle *gfb = platform_get_drvdata(pdev);
1034 struct glamofb_platform_data *mach_info = pdev->dev.platform_data;
1036 /* OK let's allow framebuffer ops again */
1037 /* gfb->fb->screen_base = ioremap(gfb->fb_res->start,
1038 RESSIZE(gfb->fb_res)); */
1039 glamo_engine_enable(mach_info->glamo, GLAMO_ENGINE_LCD);
1040 glamo_engine_reset(mach_info->glamo, GLAMO_ENGINE_LCD);
1042 printk(KERN_ERR"spin_lock_init\n");
1043 spin_lock_init(&gfb->lock_cmd);
1044 glamofb_init_regs(gfb);
1045 #ifdef CONFIG_MFD_GLAMO_HWACCEL
1046 glamofb_cursor_onoff(gfb, 1);
1049 fb_set_suspend(gfb->fb, 0);
1054 #define glamofb_suspend NULL
1055 #define glamofb_resume NULL
1058 static struct platform_driver glamofb_driver = {
1059 .probe = glamofb_probe,
1060 .remove = glamofb_remove,
1061 .suspend = glamofb_suspend,
1062 .resume = glamofb_resume,
1065 .owner = THIS_MODULE,
1069 static int __devinit glamofb_init(void)
1071 return platform_driver_register(&glamofb_driver);
1074 static void __exit glamofb_cleanup(void)
1076 platform_driver_unregister(&glamofb_driver);
1079 module_init(glamofb_init);
1080 module_exit(glamofb_cleanup);
1082 MODULE_AUTHOR("Harald Welte <laforge@openmoko.org>");
1083 MODULE_DESCRIPTION("Smedia Glamo 336x/337x framebuffer driver");
1084 MODULE_LICENSE("GPL");