Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * BRIEF MODULE DESCRIPTION |
| 3 | * Au1100 LCD Driver. |
| 4 | * |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 5 | * Rewritten for 2.6 by Embedded Alley Solutions |
| 6 | * <source@embeddedalley.com>, based on submissions by |
| 7 | * Karl Lessard <klessard@sunrisetelecom.com> |
| 8 | * <c.pellegrin@exadron.com> |
| 9 | * |
Rodolfo Giometti | f77f50c | 2006-06-26 00:26:49 -0700 | [diff] [blame] | 10 | * PM support added by Rodolfo Giometti <giometti@linux.it> |
| 11 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | * Copyright 2002 MontaVista Software |
| 13 | * Author: MontaVista Software, Inc. |
| 14 | * ppopov@mvista.com or source@mvista.com |
| 15 | * |
| 16 | * Copyright 2002 Alchemy Semiconductor |
| 17 | * Author: Alchemy Semiconductor |
| 18 | * |
| 19 | * Based on: |
| 20 | * linux/drivers/video/skeletonfb.c -- Skeleton for a frame buffer device |
| 21 | * Created 28 Dec 1997 by Geert Uytterhoeven |
| 22 | * |
| 23 | * This program is free software; you can redistribute it and/or modify it |
| 24 | * under the terms of the GNU General Public License as published by the |
| 25 | * Free Software Foundation; either version 2 of the License, or (at your |
| 26 | * option) any later version. |
| 27 | * |
| 28 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 29 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 30 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN |
| 31 | * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 32 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 33 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
| 34 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
| 35 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 36 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 37 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 38 | * |
| 39 | * You should have received a copy of the GNU General Public License along |
| 40 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 41 | * 675 Mass Ave, Cambridge, MA 02139, USA. |
| 42 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <linux/module.h> |
| 44 | #include <linux/kernel.h> |
| 45 | #include <linux/errno.h> |
| 46 | #include <linux/string.h> |
| 47 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #include <linux/fb.h> |
| 49 | #include <linux/init.h> |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 50 | #include <linux/interrupt.h> |
| 51 | #include <linux/ctype.h> |
| 52 | #include <linux/dma-mapping.h> |
Freddy Spierenburg | cacfc8c | 2006-02-24 13:04:17 -0800 | [diff] [blame] | 53 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 55 | #include <asm/mach-au1x00/au1000.h> |
| 56 | |
| 57 | #define DEBUG 0 |
| 58 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | #include "au1100fb.h" |
| 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | /* |
| 62 | * Sanity check. If this is a new Au1100 based board, search for |
| 63 | * the PB1100 ifdefs to make sure you modify the code accordingly. |
| 64 | */ |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 65 | #if defined(CONFIG_MIPS_PB1100) |
| 66 | #include <asm/mach-pb1x00/pb1100.h> |
| 67 | #elif defined(CONFIG_MIPS_DB1100) |
| 68 | #include <asm/mach-db1x00/db1x00.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | #else |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 70 | #error "Unknown Au1100 board, Au1100 FB driver not supported" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #endif |
| 72 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 73 | #define DRIVER_NAME "au1100fb" |
| 74 | #define DRIVER_DESC "LCD controller driver for AU1100 processors" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 76 | #define to_au1100fb_device(_info) \ |
| 77 | (_info ? container_of(_info, struct au1100fb_device, info) : NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 79 | /* Bitfields format supported by the controller. Note that the order of formats |
| 80 | * SHOULD be the same as in the LCD_CONTROL_SBPPF field, so we can retrieve the |
| 81 | * right pixel format by doing rgb_bitfields[LCD_CONTROL_SBPPF_XXX >> LCD_CONTROL_SBPPF] |
| 82 | */ |
| 83 | struct fb_bitfield rgb_bitfields[][4] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | { |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 85 | /* Red, Green, Blue, Transp */ |
| 86 | { { 10, 6, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } }, |
| 87 | { { 11, 5, 0 }, { 5, 6, 0 }, { 0, 5, 0 }, { 0, 0, 0 } }, |
| 88 | { { 11, 5, 0 }, { 6, 5, 0 }, { 0, 6, 0 }, { 0, 0, 0 } }, |
| 89 | { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 15, 1, 0 } }, |
| 90 | { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 1, 0 } }, |
| 91 | |
| 92 | /* The last is used to describe 12bpp format */ |
| 93 | { { 8, 4, 0 }, { 4, 4, 0 }, { 0, 4, 0 }, { 0, 0, 0 } }, |
| 94 | }; |
| 95 | |
| 96 | static struct fb_fix_screeninfo au1100fb_fix __initdata = { |
| 97 | .id = "AU1100 FB", |
| 98 | .xpanstep = 1, |
| 99 | .ypanstep = 1, |
| 100 | .type = FB_TYPE_PACKED_PIXELS, |
| 101 | .accel = FB_ACCEL_NONE, |
| 102 | }; |
| 103 | |
| 104 | static struct fb_var_screeninfo au1100fb_var __initdata = { |
| 105 | .activate = FB_ACTIVATE_NOW, |
| 106 | .height = -1, |
| 107 | .width = -1, |
| 108 | .vmode = FB_VMODE_NONINTERLACED, |
| 109 | }; |
| 110 | |
| 111 | static struct au1100fb_drv_info drv_info; |
| 112 | |
| 113 | /* |
| 114 | * Set hardware with var settings. This will enable the controller with a specific |
| 115 | * mode, normally validated with the fb_check_var method |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | */ |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 117 | int au1100fb_setmode(struct au1100fb_device *fbdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | { |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 119 | struct fb_info *info = &fbdev->info; |
| 120 | u32 words; |
| 121 | int index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 123 | if (!fbdev) |
| 124 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 126 | /* Update var-dependent FB info */ |
| 127 | if (panel_is_active(fbdev->panel) || panel_is_color(fbdev->panel)) { |
| 128 | if (info->var.bits_per_pixel <= 8) { |
| 129 | /* palettized */ |
| 130 | info->var.red.offset = 0; |
| 131 | info->var.red.length = info->var.bits_per_pixel; |
| 132 | info->var.red.msb_right = 0; |
| 133 | |
| 134 | info->var.green.offset = 0; |
| 135 | info->var.green.length = info->var.bits_per_pixel; |
| 136 | info->var.green.msb_right = 0; |
| 137 | |
| 138 | info->var.blue.offset = 0; |
| 139 | info->var.blue.length = info->var.bits_per_pixel; |
| 140 | info->var.blue.msb_right = 0; |
| 141 | |
| 142 | info->var.transp.offset = 0; |
| 143 | info->var.transp.length = 0; |
| 144 | info->var.transp.msb_right = 0; |
| 145 | |
| 146 | info->fix.visual = FB_VISUAL_PSEUDOCOLOR; |
| 147 | info->fix.line_length = info->var.xres_virtual / |
| 148 | (8/info->var.bits_per_pixel); |
| 149 | } else { |
| 150 | /* non-palettized */ |
| 151 | index = (fbdev->panel->control_base & LCD_CONTROL_SBPPF_MASK) >> LCD_CONTROL_SBPPF_BIT; |
| 152 | info->var.red = rgb_bitfields[index][0]; |
| 153 | info->var.green = rgb_bitfields[index][1]; |
| 154 | info->var.blue = rgb_bitfields[index][2]; |
| 155 | info->var.transp = rgb_bitfields[index][3]; |
| 156 | |
| 157 | info->fix.visual = FB_VISUAL_TRUECOLOR; |
| 158 | info->fix.line_length = info->var.xres_virtual << 1; /* depth=16 */ |
| 159 | } |
| 160 | } else { |
| 161 | /* mono */ |
| 162 | info->fix.visual = FB_VISUAL_MONO10; |
| 163 | info->fix.line_length = info->var.xres_virtual / 8; |
| 164 | } |
| 165 | |
| 166 | info->screen_size = info->fix.line_length * info->var.yres_virtual; |
Rodolfo Giometti | fd2d543 | 2006-08-05 12:14:19 -0700 | [diff] [blame^] | 167 | info->var.rotate = ((fbdev->panel->control_base&LCD_CONTROL_SM_MASK) \ |
| 168 | >> LCD_CONTROL_SM_BIT) * 90; |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 169 | |
| 170 | /* Determine BPP mode and format */ |
Rodolfo Giometti | fd2d543 | 2006-08-05 12:14:19 -0700 | [diff] [blame^] | 171 | fbdev->regs->lcd_control = fbdev->panel->control_base; |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 172 | |
| 173 | fbdev->regs->lcd_intenable = 0; |
| 174 | fbdev->regs->lcd_intstatus = 0; |
| 175 | |
| 176 | fbdev->regs->lcd_horztiming = fbdev->panel->horztiming; |
| 177 | |
| 178 | fbdev->regs->lcd_verttiming = fbdev->panel->verttiming; |
| 179 | |
| 180 | fbdev->regs->lcd_clkcontrol = fbdev->panel->clkcontrol_base; |
| 181 | |
| 182 | fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(fbdev->fb_phys); |
| 183 | |
| 184 | if (panel_is_dual(fbdev->panel)) { |
| 185 | /* Second panel display seconf half of screen if possible, |
| 186 | * otherwise display the same as the first panel */ |
| 187 | if (info->var.yres_virtual >= (info->var.yres << 1)) { |
| 188 | fbdev->regs->lcd_dmaaddr1 = LCD_DMA_SA_N(fbdev->fb_phys + |
| 189 | (info->fix.line_length * |
| 190 | (info->var.yres_virtual >> 1))); |
| 191 | } else { |
| 192 | fbdev->regs->lcd_dmaaddr1 = LCD_DMA_SA_N(fbdev->fb_phys); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | words = info->fix.line_length / sizeof(u32); |
| 197 | if (!info->var.rotate || (info->var.rotate == 180)) { |
| 198 | words *= info->var.yres_virtual; |
| 199 | if (info->var.rotate /* 180 */) { |
| 200 | words -= (words % 8); /* should be divisable by 8 */ |
| 201 | } |
| 202 | } |
| 203 | fbdev->regs->lcd_words = LCD_WRD_WRDS_N(words); |
| 204 | |
| 205 | fbdev->regs->lcd_pwmdiv = 0; |
| 206 | fbdev->regs->lcd_pwmhi = 0; |
| 207 | |
| 208 | /* Resume controller */ |
| 209 | fbdev->regs->lcd_control |= LCD_CONTROL_GO; |
| 210 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | return 0; |
| 212 | } |
| 213 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 214 | /* fb_setcolreg |
| 215 | * Set color in LCD palette. |
| 216 | */ |
| 217 | int au1100fb_fb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue, unsigned transp, struct fb_info *fbi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | { |
Rodolfo Giometti | c05b7f3 | 2006-05-30 21:26:57 -0700 | [diff] [blame] | 219 | struct au1100fb_device *fbdev; |
| 220 | u32 *palette; |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 221 | u32 value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | |
Rodolfo Giometti | c05b7f3 | 2006-05-30 21:26:57 -0700 | [diff] [blame] | 223 | fbdev = to_au1100fb_device(fbi); |
| 224 | palette = fbdev->regs->lcd_pallettebase; |
| 225 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 226 | if (regno > (AU1100_LCD_NBR_PALETTE_ENTRIES - 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | return -EINVAL; |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 228 | |
| 229 | if (fbi->var.grayscale) { |
| 230 | /* Convert color to grayscale */ |
| 231 | red = green = blue = |
| 232 | (19595 * red + 38470 * green + 7471 * blue) >> 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | } |
| 234 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 235 | if (fbi->fix.visual == FB_VISUAL_TRUECOLOR) { |
| 236 | /* Place color in the pseudopalette */ |
| 237 | if (regno > 16) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | return -EINVAL; |
| 239 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 240 | palette = (u32*)fbi->pseudo_palette; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 242 | red >>= (16 - fbi->var.red.length); |
| 243 | green >>= (16 - fbi->var.green.length); |
| 244 | blue >>= (16 - fbi->var.blue.length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 246 | value = (red << fbi->var.red.offset) | |
| 247 | (green << fbi->var.green.offset)| |
| 248 | (blue << fbi->var.blue.offset); |
| 249 | value &= 0xFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 251 | } else if (panel_is_active(fbdev->panel)) { |
| 252 | /* COLOR TFT PALLETTIZED (use RGB 565) */ |
| 253 | value = (red & 0xF800)|((green >> 5) & 0x07E0)|((blue >> 11) & 0x001F); |
| 254 | value &= 0xFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 256 | } else if (panel_is_color(fbdev->panel)) { |
| 257 | /* COLOR STN MODE */ |
| 258 | value = (((panel_swap_rgb(fbdev->panel) ? blue : red) >> 12) & 0x000F) | |
| 259 | ((green >> 8) & 0x00F0) | |
| 260 | (((panel_swap_rgb(fbdev->panel) ? red : blue) >> 4) & 0x0F00); |
| 261 | value &= 0xFFF; |
| 262 | } else { |
| 263 | /* MONOCHROME MODE */ |
| 264 | value = (green >> 12) & 0x000F; |
| 265 | value &= 0xF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 268 | palette[regno] = value; |
| 269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | return 0; |
| 271 | } |
| 272 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 273 | /* fb_blank |
| 274 | * Blank the screen. Depending on the mode, the screen will be |
| 275 | * activated with the backlight color, or desactivated |
| 276 | */ |
| 277 | int au1100fb_fb_blank(int blank_mode, struct fb_info *fbi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | { |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 279 | struct au1100fb_device *fbdev = to_au1100fb_device(fbi); |
| 280 | |
| 281 | print_dbg("fb_blank %d %p", blank_mode, fbi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | |
| 283 | switch (blank_mode) { |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 284 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | case VESA_NO_BLANKING: |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 286 | /* Turn on panel */ |
| 287 | fbdev->regs->lcd_control |= LCD_CONTROL_GO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | #ifdef CONFIG_MIPS_PB1100 |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 289 | if (drv_info.panel_idx == 1) { |
| 290 | au_writew(au_readw(PB1100_G_CONTROL) |
| 291 | | (PB1100_G_CONTROL_BL | PB1100_G_CONTROL_VDD), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | PB1100_G_CONTROL); |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 293 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | #endif |
| 295 | au_sync(); |
| 296 | break; |
| 297 | |
| 298 | case VESA_VSYNC_SUSPEND: |
| 299 | case VESA_HSYNC_SUSPEND: |
| 300 | case VESA_POWERDOWN: |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 301 | /* Turn off panel */ |
| 302 | fbdev->regs->lcd_control &= ~LCD_CONTROL_GO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | #ifdef CONFIG_MIPS_PB1100 |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 304 | if (drv_info.panel_idx == 1) { |
| 305 | au_writew(au_readw(PB1100_G_CONTROL) |
| 306 | & ~(PB1100_G_CONTROL_BL | PB1100_G_CONTROL_VDD), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | PB1100_G_CONTROL); |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 308 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | #endif |
| 310 | au_sync(); |
| 311 | break; |
| 312 | default: |
| 313 | break; |
| 314 | |
| 315 | } |
| 316 | return 0; |
| 317 | } |
| 318 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 319 | /* fb_pan_display |
| 320 | * Pan display in x and/or y as specified |
| 321 | */ |
| 322 | int au1100fb_fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *fbi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | { |
Rodolfo Giometti | c05b7f3 | 2006-05-30 21:26:57 -0700 | [diff] [blame] | 324 | struct au1100fb_device *fbdev; |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 325 | int dy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | |
Rodolfo Giometti | c05b7f3 | 2006-05-30 21:26:57 -0700 | [diff] [blame] | 327 | fbdev = to_au1100fb_device(fbi); |
| 328 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 329 | print_dbg("fb_pan_display %p %p", var, fbi); |
| 330 | |
| 331 | if (!var || !fbdev) { |
| 332 | return -EINVAL; |
| 333 | } |
| 334 | |
| 335 | if (var->xoffset - fbi->var.xoffset) { |
| 336 | /* No support for X panning for now! */ |
| 337 | return -EINVAL; |
| 338 | } |
| 339 | |
| 340 | print_dbg("fb_pan_display 2 %p %p", var, fbi); |
| 341 | dy = var->yoffset - fbi->var.yoffset; |
| 342 | if (dy) { |
| 343 | |
| 344 | u32 dmaaddr; |
| 345 | |
| 346 | print_dbg("Panning screen of %d lines", dy); |
| 347 | |
| 348 | dmaaddr = fbdev->regs->lcd_dmaaddr0; |
| 349 | dmaaddr += (fbi->fix.line_length * dy); |
| 350 | |
| 351 | /* TODO: Wait for current frame to finished */ |
| 352 | fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(dmaaddr); |
| 353 | |
| 354 | if (panel_is_dual(fbdev->panel)) { |
| 355 | dmaaddr = fbdev->regs->lcd_dmaaddr1; |
| 356 | dmaaddr += (fbi->fix.line_length * dy); |
| 357 | fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(dmaaddr); |
| 358 | } |
| 359 | } |
| 360 | print_dbg("fb_pan_display 3 %p %p", var, fbi); |
| 361 | |
| 362 | return 0; |
| 363 | } |
| 364 | |
| 365 | /* fb_rotate |
| 366 | * Rotate the display of this angle. This doesn't seems to be used by the core, |
| 367 | * but as our hardware supports it, so why not implementing it... |
| 368 | */ |
| 369 | void au1100fb_fb_rotate(struct fb_info *fbi, int angle) |
| 370 | { |
| 371 | struct au1100fb_device *fbdev = to_au1100fb_device(fbi); |
| 372 | |
| 373 | print_dbg("fb_rotate %p %d", fbi, angle); |
| 374 | |
| 375 | if (fbdev && (angle > 0) && !(angle % 90)) { |
| 376 | |
| 377 | fbdev->regs->lcd_control &= ~LCD_CONTROL_GO; |
| 378 | |
| 379 | fbdev->regs->lcd_control &= ~(LCD_CONTROL_SM_MASK); |
| 380 | fbdev->regs->lcd_control |= ((angle/90) << LCD_CONTROL_SM_BIT); |
| 381 | |
| 382 | fbdev->regs->lcd_control |= LCD_CONTROL_GO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | } |
| 384 | } |
| 385 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 386 | /* fb_mmap |
| 387 | * Map video memory in user space. We don't use the generic fb_mmap method mainly |
| 388 | * to allow the use of the TLB streaming flag (CCA=6) |
| 389 | */ |
Christoph Hellwig | 216d526 | 2006-01-14 13:21:25 -0800 | [diff] [blame] | 390 | int au1100fb_fb_mmap(struct fb_info *fbi, struct vm_area_struct *vma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | { |
Rodolfo Giometti | c05b7f3 | 2006-05-30 21:26:57 -0700 | [diff] [blame] | 392 | struct au1100fb_device *fbdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | unsigned int len; |
| 394 | unsigned long start=0, off; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | |
Rodolfo Giometti | c05b7f3 | 2006-05-30 21:26:57 -0700 | [diff] [blame] | 396 | fbdev = to_au1100fb_device(fbi); |
| 397 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) { |
| 399 | return -EINVAL; |
| 400 | } |
| 401 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 402 | start = fbdev->fb_phys & PAGE_MASK; |
| 403 | len = PAGE_ALIGN((start & ~PAGE_MASK) + fbdev->fb_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | |
| 405 | off = vma->vm_pgoff << PAGE_SHIFT; |
| 406 | |
| 407 | if ((vma->vm_end - vma->vm_start + off) > len) { |
| 408 | return -EINVAL; |
| 409 | } |
| 410 | |
| 411 | off += start; |
| 412 | vma->vm_pgoff = off >> PAGE_SHIFT; |
| 413 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 414 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | pgprot_val(vma->vm_page_prot) |= (6 << 9); //CCA=6 |
| 416 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | vma->vm_flags |= VM_IO; |
| 418 | |
Freddy Spierenburg | cacfc8c | 2006-02-24 13:04:17 -0800 | [diff] [blame] | 419 | if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | vma->vm_end - vma->vm_start, |
| 421 | vma->vm_page_prot)) { |
| 422 | return -EAGAIN; |
| 423 | } |
| 424 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | return 0; |
| 426 | } |
| 427 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 428 | static struct fb_ops au1100fb_ops = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | { |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 430 | .owner = THIS_MODULE, |
| 431 | .fb_setcolreg = au1100fb_fb_setcolreg, |
| 432 | .fb_blank = au1100fb_fb_blank, |
| 433 | .fb_pan_display = au1100fb_fb_pan_display, |
| 434 | .fb_fillrect = cfb_fillrect, |
| 435 | .fb_copyarea = cfb_copyarea, |
| 436 | .fb_imageblit = cfb_imageblit, |
| 437 | .fb_rotate = au1100fb_fb_rotate, |
| 438 | .fb_mmap = au1100fb_fb_mmap, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | }; |
| 440 | |
| 441 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 442 | /*-------------------------------------------------------------------------*/ |
| 443 | |
| 444 | /* AU1100 LCD controller device driver */ |
| 445 | |
| 446 | int au1100fb_drv_probe(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | { |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 448 | struct au1100fb_device *fbdev = NULL; |
| 449 | struct resource *regs_res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | unsigned long page; |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 451 | u32 sys_clksrc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 453 | if (!dev) |
| 454 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 456 | /* Allocate new device private */ |
| 457 | if (!(fbdev = kmalloc(sizeof(struct au1100fb_device), GFP_KERNEL))) { |
| 458 | print_err("fail to allocate device private record"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | return -ENOMEM; |
| 460 | } |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 461 | memset((void*)fbdev, 0, sizeof(struct au1100fb_device)); |
| 462 | |
| 463 | fbdev->panel = &known_lcd_panels[drv_info.panel_idx]; |
| 464 | |
| 465 | dev_set_drvdata(dev, (void*)fbdev); |
| 466 | |
| 467 | /* Allocate region for our registers and map them */ |
| 468 | if (!(regs_res = platform_get_resource(to_platform_device(dev), |
| 469 | IORESOURCE_MEM, 0))) { |
| 470 | print_err("fail to retrieve registers resource"); |
| 471 | return -EFAULT; |
| 472 | } |
| 473 | |
| 474 | au1100fb_fix.mmio_start = regs_res->start; |
| 475 | au1100fb_fix.mmio_len = regs_res->end - regs_res->start + 1; |
| 476 | |
| 477 | if (!request_mem_region(au1100fb_fix.mmio_start, au1100fb_fix.mmio_len, |
| 478 | DRIVER_NAME)) { |
Rodolfo Giometti | c05b7f3 | 2006-05-30 21:26:57 -0700 | [diff] [blame] | 479 | print_err("fail to lock memory region at 0x%08lx", |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 480 | au1100fb_fix.mmio_start); |
| 481 | return -EBUSY; |
| 482 | } |
| 483 | |
| 484 | fbdev->regs = (struct au1100fb_regs*)KSEG1ADDR(au1100fb_fix.mmio_start); |
| 485 | |
| 486 | print_dbg("Register memory map at %p", fbdev->regs); |
| 487 | print_dbg("phys=0x%08x, size=%d", fbdev->regs_phys, fbdev->regs_len); |
| 488 | |
| 489 | |
| 490 | |
| 491 | /* Allocate the framebuffer to the maximum screen size * nbr of video buffers */ |
| 492 | fbdev->fb_len = fbdev->panel->xres * fbdev->panel->yres * |
| 493 | (fbdev->panel->bpp >> 3) * AU1100FB_NBR_VIDEO_BUFFERS; |
| 494 | |
| 495 | fbdev->fb_mem = dma_alloc_coherent(dev, PAGE_ALIGN(fbdev->fb_len), |
| 496 | &fbdev->fb_phys, GFP_KERNEL); |
| 497 | if (!fbdev->fb_mem) { |
| 498 | print_err("fail to allocate frambuffer (size: %dK))", |
| 499 | fbdev->fb_len / 1024); |
| 500 | return -ENOMEM; |
| 501 | } |
| 502 | |
| 503 | au1100fb_fix.smem_start = fbdev->fb_phys; |
| 504 | au1100fb_fix.smem_len = fbdev->fb_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | |
| 506 | /* |
| 507 | * Set page reserved so that mmap will work. This is necessary |
| 508 | * since we'll be remapping normal memory. |
| 509 | */ |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 510 | for (page = (unsigned long)fbdev->fb_mem; |
| 511 | page < PAGE_ALIGN((unsigned long)fbdev->fb_mem + fbdev->fb_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | page += PAGE_SIZE) { |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 513 | #if CONFIG_DMA_NONCOHERENT |
| 514 | SetPageReserved(virt_to_page(CAC_ADDR(page))); |
| 515 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | SetPageReserved(virt_to_page(page)); |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 517 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | } |
| 519 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 520 | print_dbg("Framebuffer memory map at %p", fbdev->fb_mem); |
| 521 | print_dbg("phys=0x%08x, size=%dK", fbdev->fb_phys, fbdev->fb_len / 1024); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 523 | /* Setup LCD clock to AUX (48 MHz) */ |
| 524 | sys_clksrc = au_readl(SYS_CLKSRC) & ~(SYS_CS_ML_MASK | SYS_CS_DL | SYS_CS_CL); |
| 525 | au_writel((sys_clksrc | (1 << SYS_CS_ML_BIT)), SYS_CLKSRC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 527 | /* load the panel info into the var struct */ |
| 528 | au1100fb_var.bits_per_pixel = fbdev->panel->bpp; |
| 529 | au1100fb_var.xres = fbdev->panel->xres; |
| 530 | au1100fb_var.xres_virtual = au1100fb_var.xres; |
| 531 | au1100fb_var.yres = fbdev->panel->yres; |
| 532 | au1100fb_var.yres_virtual = au1100fb_var.yres; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 534 | fbdev->info.screen_base = fbdev->fb_mem; |
| 535 | fbdev->info.fbops = &au1100fb_ops; |
| 536 | fbdev->info.fix = au1100fb_fix; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 538 | if (!(fbdev->info.pseudo_palette = kmalloc(sizeof(u32) * 16, GFP_KERNEL))) { |
| 539 | return -ENOMEM; |
| 540 | } |
| 541 | memset(fbdev->info.pseudo_palette, 0, sizeof(u32) * 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 543 | if (fb_alloc_cmap(&fbdev->info.cmap, AU1100_LCD_NBR_PALETTE_ENTRIES, 0) < 0) { |
| 544 | print_err("Fail to allocate colormap (%d entries)", |
| 545 | AU1100_LCD_NBR_PALETTE_ENTRIES); |
| 546 | kfree(fbdev->info.pseudo_palette); |
| 547 | return -EFAULT; |
| 548 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 550 | fbdev->info.var = au1100fb_var; |
| 551 | |
| 552 | /* Set h/w registers */ |
| 553 | au1100fb_setmode(fbdev); |
| 554 | |
| 555 | /* Register new framebuffer */ |
| 556 | if (register_framebuffer(&fbdev->info) < 0) { |
| 557 | print_err("cannot register new framebuffer"); |
| 558 | goto failed; |
| 559 | } |
| 560 | |
| 561 | return 0; |
| 562 | |
| 563 | failed: |
| 564 | if (fbdev->regs) { |
| 565 | release_mem_region(fbdev->regs_phys, fbdev->regs_len); |
| 566 | } |
| 567 | if (fbdev->fb_mem) { |
| 568 | dma_free_noncoherent(dev, fbdev->fb_len, fbdev->fb_mem, fbdev->fb_phys); |
| 569 | } |
| 570 | if (fbdev->info.cmap.len != 0) { |
| 571 | fb_dealloc_cmap(&fbdev->info.cmap); |
| 572 | } |
| 573 | kfree(fbdev); |
| 574 | dev_set_drvdata(dev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | |
| 576 | return 0; |
| 577 | } |
| 578 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 579 | int au1100fb_drv_remove(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | { |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 581 | struct au1100fb_device *fbdev = NULL; |
| 582 | |
| 583 | if (!dev) |
| 584 | return -ENODEV; |
| 585 | |
| 586 | fbdev = (struct au1100fb_device*) dev_get_drvdata(dev); |
| 587 | |
| 588 | #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO) |
| 589 | au1100fb_fb_blank(VESA_POWERDOWN, &fbdev->info); |
| 590 | #endif |
| 591 | fbdev->regs->lcd_control &= ~LCD_CONTROL_GO; |
| 592 | |
| 593 | /* Clean up all probe data */ |
| 594 | unregister_framebuffer(&fbdev->info); |
| 595 | |
| 596 | release_mem_region(fbdev->regs_phys, fbdev->regs_len); |
| 597 | |
| 598 | dma_free_coherent(dev, PAGE_ALIGN(fbdev->fb_len), fbdev->fb_mem, fbdev->fb_phys); |
| 599 | |
| 600 | fb_dealloc_cmap(&fbdev->info.cmap); |
| 601 | kfree(fbdev->info.pseudo_palette); |
| 602 | kfree((void*)fbdev); |
| 603 | |
| 604 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | } |
| 606 | |
Rodolfo Giometti | f77f50c | 2006-06-26 00:26:49 -0700 | [diff] [blame] | 607 | #ifdef CONFIG_PM |
| 608 | static u32 sys_clksrc; |
| 609 | static struct au1100fb_regs fbregs; |
| 610 | |
Rodolfo Giometti | c05b7f3 | 2006-05-30 21:26:57 -0700 | [diff] [blame] | 611 | int au1100fb_drv_suspend(struct device *dev, pm_message_t state) |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 612 | { |
Rodolfo Giometti | f77f50c | 2006-06-26 00:26:49 -0700 | [diff] [blame] | 613 | struct au1100fb_device *fbdev = dev_get_drvdata(dev); |
| 614 | |
| 615 | if (!fbdev) |
| 616 | return 0; |
| 617 | |
| 618 | /* Save the clock source state */ |
| 619 | sys_clksrc = au_readl(SYS_CLKSRC); |
| 620 | |
| 621 | /* Blank the LCD */ |
| 622 | au1100fb_fb_blank(VESA_POWERDOWN, &fbdev->info); |
| 623 | |
| 624 | /* Stop LCD clocking */ |
| 625 | au_writel(sys_clksrc & ~SYS_CS_ML_MASK, SYS_CLKSRC); |
| 626 | |
| 627 | memcpy(&fbregs, fbdev->regs, sizeof(struct au1100fb_regs)); |
| 628 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 629 | return 0; |
| 630 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | |
Rodolfo Giometti | c05b7f3 | 2006-05-30 21:26:57 -0700 | [diff] [blame] | 632 | int au1100fb_drv_resume(struct device *dev) |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 633 | { |
Rodolfo Giometti | f77f50c | 2006-06-26 00:26:49 -0700 | [diff] [blame] | 634 | struct au1100fb_device *fbdev = dev_get_drvdata(dev); |
| 635 | |
| 636 | if (!fbdev) |
| 637 | return 0; |
| 638 | |
| 639 | memcpy(fbdev->regs, &fbregs, sizeof(struct au1100fb_regs)); |
| 640 | |
| 641 | /* Restart LCD clocking */ |
| 642 | au_writel(sys_clksrc, SYS_CLKSRC); |
| 643 | |
| 644 | /* Unblank the LCD */ |
| 645 | au1100fb_fb_blank(VESA_NO_BLANKING, &fbdev->info); |
| 646 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 647 | return 0; |
| 648 | } |
Rodolfo Giometti | f77f50c | 2006-06-26 00:26:49 -0700 | [diff] [blame] | 649 | #else |
| 650 | #define au1100fb_drv_suspend NULL |
| 651 | #define au1100fb_drv_resume NULL |
| 652 | #endif |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 653 | |
| 654 | static struct device_driver au1100fb_driver = { |
| 655 | .name = "au1100-lcd", |
| 656 | .bus = &platform_bus_type, |
| 657 | |
| 658 | .probe = au1100fb_drv_probe, |
| 659 | .remove = au1100fb_drv_remove, |
| 660 | .suspend = au1100fb_drv_suspend, |
| 661 | .resume = au1100fb_drv_resume, |
| 662 | }; |
| 663 | |
| 664 | /*-------------------------------------------------------------------------*/ |
| 665 | |
| 666 | /* Kernel driver */ |
| 667 | |
| 668 | int au1100fb_setup(char *options) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | { |
| 670 | char* this_opt; |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 671 | int num_panels = ARRAY_SIZE(known_lcd_panels); |
| 672 | char* mode = NULL; |
| 673 | int panel_idx = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 675 | if (num_panels <= 0) { |
| 676 | print_err("No LCD panels supported by driver!"); |
| 677 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | } |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 679 | |
| 680 | if (options) { |
| 681 | while ((this_opt = strsep(&options,",")) != NULL) { |
| 682 | /* Panel option */ |
| 683 | if (!strncmp(this_opt, "panel:", 6)) { |
| 684 | int i; |
| 685 | this_opt += 6; |
| 686 | for (i = 0; i < num_panels; i++) { |
| 687 | if (!strncmp(this_opt, |
| 688 | known_lcd_panels[i].name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | strlen(this_opt))) { |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 690 | panel_idx = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | break; |
| 692 | } |
| 693 | } |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 694 | if (i >= num_panels) { |
| 695 | print_warn("Panel %s not supported!", this_opt); |
| 696 | } |
| 697 | } |
| 698 | /* Mode option (only option that start with digit) */ |
| 699 | else if (isdigit(this_opt[0])) { |
| 700 | mode = kmalloc(strlen(this_opt) + 1, GFP_KERNEL); |
| 701 | strncpy(mode, this_opt, strlen(this_opt) + 1); |
| 702 | } |
| 703 | /* Unsupported option */ |
| 704 | else { |
| 705 | print_warn("Unsupported option \"%s\"", this_opt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | } |
| 708 | } |
| 709 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 710 | drv_info.panel_idx = panel_idx; |
| 711 | drv_info.opt_mode = mode; |
| 712 | |
| 713 | print_info("Panel=%s Mode=%s", |
| 714 | known_lcd_panels[drv_info.panel_idx].name, |
| 715 | drv_info.opt_mode ? drv_info.opt_mode : "default"); |
| 716 | |
| 717 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | } |
| 719 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 720 | int __init au1100fb_init(void) |
| 721 | { |
| 722 | char* options; |
| 723 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 725 | print_info("" DRIVER_DESC ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 727 | memset(&drv_info, 0, sizeof(drv_info)); |
| 728 | |
| 729 | if (fb_get_options(DRIVER_NAME, &options)) |
| 730 | return -ENODEV; |
| 731 | |
| 732 | /* Setup driver with options */ |
| 733 | ret = au1100fb_setup(options); |
| 734 | if (ret < 0) { |
| 735 | print_err("Fail to setup driver"); |
| 736 | return ret; |
| 737 | } |
| 738 | |
| 739 | return driver_register(&au1100fb_driver); |
| 740 | } |
| 741 | |
| 742 | void __exit au1100fb_cleanup(void) |
| 743 | { |
| 744 | driver_unregister(&au1100fb_driver); |
| 745 | |
Jesper Juhl | 8f76078 | 2006-06-27 02:55:06 -0700 | [diff] [blame] | 746 | kfree(drv_info.opt_mode); |
Pete Popov | 3b495f2 | 2005-04-04 01:06:19 +0000 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | module_init(au1100fb_init); |
| 750 | module_exit(au1100fb_cleanup); |
| 751 | |
| 752 | MODULE_DESCRIPTION(DRIVER_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | MODULE_LICENSE("GPL"); |