Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * platinumfb.c -- frame buffer device for the PowerMac 'platinum' display |
| 3 | * |
| 4 | * Copyright (C) 1998 Franz Sirl |
| 5 | * |
| 6 | * Frame buffer structure from: |
| 7 | * drivers/video/controlfb.c -- frame buffer device for |
| 8 | * Apple 'control' display chip. |
| 9 | * Copyright (C) 1998 Dan Jacobowitz |
| 10 | * |
| 11 | * Hardware information from: |
| 12 | * platinum.c: Console support for PowerMac "platinum" display adaptor. |
| 13 | * Copyright (C) 1996 Paul Mackerras and Mark Abene |
| 14 | * |
| 15 | * This file is subject to the terms and conditions of the GNU General Public |
| 16 | * License. See the file COPYING in the main directory of this archive for |
| 17 | * more details. |
| 18 | */ |
| 19 | |
Benjamin Herrenschmidt | 4c2a54b | 2007-09-19 14:50:22 +1000 | [diff] [blame] | 20 | #undef DEBUG |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/module.h> |
| 23 | #include <linux/kernel.h> |
| 24 | #include <linux/errno.h> |
| 25 | #include <linux/string.h> |
| 26 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/vmalloc.h> |
| 28 | #include <linux/delay.h> |
| 29 | #include <linux/interrupt.h> |
| 30 | #include <linux/fb.h> |
| 31 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <linux/nvram.h> |
Stephen Rothwell | cec0dd9 | 2008-05-23 16:39:58 +1000 | [diff] [blame] | 33 | #include <linux/of_device.h> |
| 34 | #include <linux/of_platform.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <asm/io.h> |
| 36 | #include <asm/prom.h> |
| 37 | #include <asm/pgtable.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 39 | #include "macmodes.h" |
| 40 | #include "platinumfb.h" |
| 41 | |
| 42 | static int default_vmode = VMODE_NVRAM; |
| 43 | static int default_cmode = CMODE_NVRAM; |
| 44 | |
| 45 | struct fb_info_platinum { |
| 46 | struct fb_info *info; |
| 47 | |
| 48 | int vmode, cmode; |
| 49 | int xres, yres; |
| 50 | int vxres, vyres; |
| 51 | int xoffset, yoffset; |
| 52 | |
| 53 | struct { |
| 54 | __u8 red, green, blue; |
| 55 | } palette[256]; |
Antonino A. Daplas | 02c2c20 | 2007-07-17 04:05:38 -0700 | [diff] [blame] | 56 | u32 pseudo_palette[16]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
| 58 | volatile struct cmap_regs __iomem *cmap_regs; |
| 59 | unsigned long cmap_regs_phys; |
| 60 | |
| 61 | volatile struct platinum_regs __iomem *platinum_regs; |
| 62 | unsigned long platinum_regs_phys; |
| 63 | |
| 64 | __u8 __iomem *frame_buffer; |
| 65 | volatile __u8 __iomem *base_frame_buffer; |
| 66 | unsigned long frame_buffer_phys; |
| 67 | |
| 68 | unsigned long total_vram; |
| 69 | int clktype; |
| 70 | int dactype; |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 71 | |
| 72 | struct resource rsrc_fb, rsrc_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | /* |
| 76 | * Frame buffer device API |
| 77 | */ |
| 78 | |
| 79 | static int platinumfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue, |
| 80 | u_int transp, struct fb_info *info); |
| 81 | static int platinumfb_blank(int blank_mode, struct fb_info *info); |
| 82 | static int platinumfb_set_par (struct fb_info *info); |
| 83 | static int platinumfb_check_var (struct fb_var_screeninfo *var, struct fb_info *info); |
| 84 | |
| 85 | /* |
| 86 | * internal functions |
| 87 | */ |
| 88 | |
| 89 | static inline int platinum_vram_reqd(int video_mode, int color_mode); |
| 90 | static int read_platinum_sense(struct fb_info_platinum *pinfo); |
| 91 | static void set_platinum_clock(struct fb_info_platinum *pinfo); |
| 92 | static void platinum_set_hardware(struct fb_info_platinum *pinfo); |
| 93 | static int platinum_var_to_par(struct fb_var_screeninfo *var, |
| 94 | struct fb_info_platinum *pinfo, |
| 95 | int check_only); |
| 96 | |
| 97 | /* |
| 98 | * Interface used by the world |
| 99 | */ |
| 100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | static struct fb_ops platinumfb_ops = { |
| 102 | .owner = THIS_MODULE, |
| 103 | .fb_check_var = platinumfb_check_var, |
| 104 | .fb_set_par = platinumfb_set_par, |
| 105 | .fb_setcolreg = platinumfb_setcolreg, |
| 106 | .fb_blank = platinumfb_blank, |
| 107 | .fb_fillrect = cfb_fillrect, |
| 108 | .fb_copyarea = cfb_copyarea, |
| 109 | .fb_imageblit = cfb_imageblit, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | /* |
| 113 | * Checks a var structure |
| 114 | */ |
| 115 | static int platinumfb_check_var (struct fb_var_screeninfo *var, struct fb_info *info) |
| 116 | { |
| 117 | return platinum_var_to_par(var, info->par, 1); |
| 118 | } |
| 119 | |
| 120 | /* |
| 121 | * Applies current var to display |
| 122 | */ |
| 123 | static int platinumfb_set_par (struct fb_info *info) |
| 124 | { |
| 125 | struct fb_info_platinum *pinfo = info->par; |
| 126 | struct platinum_regvals *init; |
| 127 | int err, offset = 0x20; |
| 128 | |
| 129 | if((err = platinum_var_to_par(&info->var, pinfo, 0))) { |
| 130 | printk (KERN_ERR "platinumfb_set_par: error calling" |
| 131 | " platinum_var_to_par: %d.\n", err); |
| 132 | return err; |
| 133 | } |
| 134 | |
| 135 | platinum_set_hardware(pinfo); |
| 136 | |
| 137 | init = platinum_reg_init[pinfo->vmode-1]; |
| 138 | |
Benjamin Herrenschmidt | 9cf84d7 | 2005-12-13 17:48:35 +1100 | [diff] [blame] | 139 | if ((pinfo->vmode == VMODE_832_624_75) && (pinfo->cmode > CMODE_8)) |
| 140 | offset = 0x10; |
| 141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | info->screen_base = pinfo->frame_buffer + init->fb_offset + offset; |
Krzysztof Helt | 537a1bf | 2009-06-30 11:41:29 -0700 | [diff] [blame] | 143 | mutex_lock(&info->mm_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | info->fix.smem_start = (pinfo->frame_buffer_phys) + init->fb_offset + offset; |
Krzysztof Helt | 537a1bf | 2009-06-30 11:41:29 -0700 | [diff] [blame] | 145 | mutex_unlock(&info->mm_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | info->fix.visual = (pinfo->cmode == CMODE_8) ? |
| 147 | FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR; |
Benjamin Herrenschmidt | 9cf84d7 | 2005-12-13 17:48:35 +1100 | [diff] [blame] | 148 | info->fix.line_length = vmode_attrs[pinfo->vmode-1].hres * (1<<pinfo->cmode) |
| 149 | + offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | printk("line_length: %x\n", info->fix.line_length); |
| 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | static int platinumfb_blank(int blank, struct fb_info *fb) |
| 155 | { |
| 156 | /* |
| 157 | * Blank the screen if blank_mode != 0, else unblank. If blank == NULL |
| 158 | * then the caller blanks by setting the CLUT (Color Look Up Table) to all |
| 159 | * black. Return 0 if blanking succeeded, != 0 if un-/blanking failed due |
| 160 | * to e.g. a video mode which doesn't support it. Implements VESA suspend |
| 161 | * and powerdown modes on hardware that supports disabling hsync/vsync: |
| 162 | * blank_mode == 2: suspend vsync |
| 163 | * blank_mode == 3: suspend hsync |
| 164 | * blank_mode == 4: powerdown |
| 165 | */ |
| 166 | /* [danj] I think there's something fishy about those constants... */ |
| 167 | /* |
| 168 | struct fb_info_platinum *info = (struct fb_info_platinum *) fb; |
| 169 | int ctrl; |
| 170 | |
| 171 | ctrl = ld_le32(&info->platinum_regs->ctrl.r) | 0x33; |
| 172 | if (blank) |
| 173 | --blank_mode; |
| 174 | if (blank & VESA_VSYNC_SUSPEND) |
| 175 | ctrl &= ~3; |
| 176 | if (blank & VESA_HSYNC_SUSPEND) |
| 177 | ctrl &= ~0x30; |
| 178 | out_le32(&info->platinum_regs->ctrl.r, ctrl); |
| 179 | */ |
| 180 | /* TODO: Figure out how the heck to powerdown this thing! */ |
| 181 | return 0; |
| 182 | } |
| 183 | |
| 184 | static int platinumfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue, |
| 185 | u_int transp, struct fb_info *info) |
| 186 | { |
| 187 | struct fb_info_platinum *pinfo = info->par; |
| 188 | volatile struct cmap_regs __iomem *cmap_regs = pinfo->cmap_regs; |
| 189 | |
| 190 | if (regno > 255) |
| 191 | return 1; |
| 192 | |
| 193 | red >>= 8; |
| 194 | green >>= 8; |
| 195 | blue >>= 8; |
| 196 | |
| 197 | pinfo->palette[regno].red = red; |
| 198 | pinfo->palette[regno].green = green; |
| 199 | pinfo->palette[regno].blue = blue; |
| 200 | |
| 201 | out_8(&cmap_regs->addr, regno); /* tell clut what addr to fill */ |
| 202 | out_8(&cmap_regs->lut, red); /* send one color channel at */ |
| 203 | out_8(&cmap_regs->lut, green); /* a time... */ |
| 204 | out_8(&cmap_regs->lut, blue); |
| 205 | |
| 206 | if (regno < 16) { |
| 207 | int i; |
| 208 | u32 *pal = info->pseudo_palette; |
| 209 | switch (pinfo->cmode) { |
| 210 | case CMODE_16: |
| 211 | pal[regno] = (regno << 10) | (regno << 5) | regno; |
| 212 | break; |
| 213 | case CMODE_32: |
| 214 | i = (regno << 8) | regno; |
| 215 | pal[regno] = (i << 16) | i; |
| 216 | break; |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | return 0; |
| 221 | } |
| 222 | |
| 223 | static inline int platinum_vram_reqd(int video_mode, int color_mode) |
| 224 | { |
Roel Kluin | 6e3658f | 2009-09-22 16:47:04 -0700 | [diff] [blame] | 225 | int baseval = vmode_attrs[video_mode-1].hres * (1<<color_mode); |
| 226 | |
| 227 | if ((video_mode == VMODE_832_624_75) && (color_mode > CMODE_8)) |
| 228 | baseval += 0x10; |
| 229 | else |
| 230 | baseval += 0x20; |
| 231 | |
| 232 | return vmode_attrs[video_mode-1].vres * baseval + 0x1000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | #define STORE_D2(a, d) { \ |
| 236 | out_8(&cmap_regs->addr, (a+32)); \ |
| 237 | out_8(&cmap_regs->d2, (d)); \ |
| 238 | } |
| 239 | |
| 240 | static void set_platinum_clock(struct fb_info_platinum *pinfo) |
| 241 | { |
| 242 | volatile struct cmap_regs __iomem *cmap_regs = pinfo->cmap_regs; |
| 243 | struct platinum_regvals *init; |
| 244 | |
| 245 | init = platinum_reg_init[pinfo->vmode-1]; |
| 246 | |
| 247 | STORE_D2(6, 0xc6); |
| 248 | out_8(&cmap_regs->addr,3+32); |
| 249 | |
| 250 | if (in_8(&cmap_regs->d2) == 2) { |
| 251 | STORE_D2(7, init->clock_params[pinfo->clktype][0]); |
| 252 | STORE_D2(8, init->clock_params[pinfo->clktype][1]); |
| 253 | STORE_D2(3, 3); |
| 254 | } else { |
| 255 | STORE_D2(4, init->clock_params[pinfo->clktype][0]); |
| 256 | STORE_D2(5, init->clock_params[pinfo->clktype][1]); |
| 257 | STORE_D2(3, 2); |
| 258 | } |
| 259 | |
| 260 | __delay(5000); |
| 261 | STORE_D2(9, 0xa6); |
| 262 | } |
| 263 | |
| 264 | |
| 265 | /* Now how about actually saying, Make it so! */ |
| 266 | /* Some things in here probably don't need to be done each time. */ |
| 267 | static void platinum_set_hardware(struct fb_info_platinum *pinfo) |
| 268 | { |
| 269 | volatile struct platinum_regs __iomem *platinum_regs = pinfo->platinum_regs; |
| 270 | volatile struct cmap_regs __iomem *cmap_regs = pinfo->cmap_regs; |
| 271 | struct platinum_regvals *init; |
| 272 | int i; |
| 273 | int vmode, cmode; |
| 274 | |
| 275 | vmode = pinfo->vmode; |
| 276 | cmode = pinfo->cmode; |
| 277 | |
| 278 | init = platinum_reg_init[vmode - 1]; |
| 279 | |
| 280 | /* Initialize display timing registers */ |
| 281 | out_be32(&platinum_regs->reg[24].r, 7); /* turn display off */ |
| 282 | |
| 283 | for (i = 0; i < 26; ++i) |
| 284 | out_be32(&platinum_regs->reg[i+32].r, init->regs[i]); |
| 285 | |
| 286 | out_be32(&platinum_regs->reg[26+32].r, (pinfo->total_vram == 0x100000 ? |
| 287 | init->offset[cmode] + 4 - cmode : |
| 288 | init->offset[cmode])); |
| 289 | out_be32(&platinum_regs->reg[16].r, (unsigned) pinfo->frame_buffer_phys+init->fb_offset+0x10); |
| 290 | out_be32(&platinum_regs->reg[18].r, init->pitch[cmode]); |
| 291 | out_be32(&platinum_regs->reg[19].r, (pinfo->total_vram == 0x100000 ? |
| 292 | init->mode[cmode+1] : |
| 293 | init->mode[cmode])); |
| 294 | out_be32(&platinum_regs->reg[20].r, (pinfo->total_vram == 0x100000 ? 0x11 : 0x1011)); |
| 295 | out_be32(&platinum_regs->reg[21].r, 0x100); |
| 296 | out_be32(&platinum_regs->reg[22].r, 1); |
| 297 | out_be32(&platinum_regs->reg[23].r, 1); |
| 298 | out_be32(&platinum_regs->reg[26].r, 0xc00); |
| 299 | out_be32(&platinum_regs->reg[27].r, 0x235); |
| 300 | /* out_be32(&platinum_regs->reg[27].r, 0x2aa); */ |
| 301 | |
| 302 | STORE_D2(0, (pinfo->total_vram == 0x100000 ? |
| 303 | init->dacula_ctrl[cmode] & 0xf : |
| 304 | init->dacula_ctrl[cmode])); |
| 305 | STORE_D2(1, 4); |
| 306 | STORE_D2(2, 0); |
| 307 | |
| 308 | set_platinum_clock(pinfo); |
| 309 | |
| 310 | out_be32(&platinum_regs->reg[24].r, 0); /* turn display on */ |
| 311 | } |
| 312 | |
| 313 | /* |
| 314 | * Set misc info vars for this driver |
| 315 | */ |
| 316 | static void __devinit platinum_init_info(struct fb_info *info, struct fb_info_platinum *pinfo) |
| 317 | { |
| 318 | /* Fill fb_info */ |
| 319 | info->fbops = &platinumfb_ops; |
| 320 | info->pseudo_palette = pinfo->pseudo_palette; |
| 321 | info->flags = FBINFO_DEFAULT; |
| 322 | info->screen_base = pinfo->frame_buffer + 0x20; |
| 323 | |
| 324 | fb_alloc_cmap(&info->cmap, 256, 0); |
| 325 | |
| 326 | /* Fill fix common fields */ |
| 327 | strcpy(info->fix.id, "platinum"); |
| 328 | info->fix.mmio_start = pinfo->platinum_regs_phys; |
| 329 | info->fix.mmio_len = 0x1000; |
| 330 | info->fix.type = FB_TYPE_PACKED_PIXELS; |
| 331 | info->fix.smem_start = pinfo->frame_buffer_phys + 0x20; /* will be updated later */ |
| 332 | info->fix.smem_len = pinfo->total_vram - 0x20; |
| 333 | info->fix.ywrapstep = 0; |
| 334 | info->fix.xpanstep = 0; |
| 335 | info->fix.ypanstep = 0; |
| 336 | info->fix.type_aux = 0; |
| 337 | info->fix.accel = FB_ACCEL_NONE; |
| 338 | } |
| 339 | |
| 340 | |
| 341 | static int __devinit platinum_init_fb(struct fb_info *info) |
| 342 | { |
| 343 | struct fb_info_platinum *pinfo = info->par; |
| 344 | struct fb_var_screeninfo var; |
| 345 | int sense, rc; |
| 346 | |
| 347 | sense = read_platinum_sense(pinfo); |
| 348 | printk(KERN_INFO "platinumfb: Monitor sense value = 0x%x, ", sense); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | if (default_vmode == VMODE_NVRAM) { |
Ben Collins | f3f6f9a | 2006-10-18 08:52:48 -0400 | [diff] [blame] | 350 | #ifdef CONFIG_NVRAM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | default_vmode = nvram_read_byte(NV_VMODE); |
| 352 | if (default_vmode <= 0 || default_vmode > VMODE_MAX || |
| 353 | !platinum_reg_init[default_vmode-1]) |
Ben Collins | f3f6f9a | 2006-10-18 08:52:48 -0400 | [diff] [blame] | 354 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | default_vmode = VMODE_CHOOSE; |
| 356 | } |
| 357 | if (default_vmode == VMODE_CHOOSE) { |
| 358 | default_vmode = mac_map_monitor_sense(sense); |
| 359 | } |
| 360 | if (default_vmode <= 0 || default_vmode > VMODE_MAX) |
| 361 | default_vmode = VMODE_640_480_60; |
Ben Collins | f3f6f9a | 2006-10-18 08:52:48 -0400 | [diff] [blame] | 362 | #ifdef CONFIG_NVRAM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | if (default_cmode == CMODE_NVRAM) |
| 364 | default_cmode = nvram_read_byte(NV_CMODE); |
Ben Collins | f3f6f9a | 2006-10-18 08:52:48 -0400 | [diff] [blame] | 365 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | if (default_cmode < CMODE_8 || default_cmode > CMODE_32) |
| 367 | default_cmode = CMODE_8; |
| 368 | /* |
| 369 | * Reduce the pixel size if we don't have enough VRAM. |
| 370 | */ |
| 371 | while(default_cmode > CMODE_8 && |
| 372 | platinum_vram_reqd(default_vmode, default_cmode) > pinfo->total_vram) |
| 373 | default_cmode--; |
| 374 | |
| 375 | printk("platinumfb: Using video mode %d and color mode %d.\n", default_vmode, default_cmode); |
| 376 | |
| 377 | /* Setup default var */ |
| 378 | if (mac_vmode_to_var(default_vmode, default_cmode, &var) < 0) { |
| 379 | /* This shouldn't happen! */ |
| 380 | printk("mac_vmode_to_var(%d, %d,) failed\n", default_vmode, default_cmode); |
| 381 | try_again: |
| 382 | default_vmode = VMODE_640_480_60; |
| 383 | default_cmode = CMODE_8; |
| 384 | if (mac_vmode_to_var(default_vmode, default_cmode, &var) < 0) { |
| 385 | printk(KERN_ERR "platinumfb: mac_vmode_to_var() failed\n"); |
| 386 | return -ENXIO; |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | /* Initialize info structure */ |
| 391 | platinum_init_info(info, pinfo); |
| 392 | |
| 393 | /* Apply default var */ |
| 394 | info->var = var; |
| 395 | var.activate = FB_ACTIVATE_NOW; |
| 396 | rc = fb_set_var(info, &var); |
| 397 | if (rc && (default_vmode != VMODE_640_480_60 || default_cmode != CMODE_8)) |
| 398 | goto try_again; |
| 399 | |
| 400 | /* Register with fbdev layer */ |
| 401 | rc = register_framebuffer(info); |
| 402 | if (rc < 0) |
| 403 | return rc; |
| 404 | |
| 405 | printk(KERN_INFO "fb%d: Apple Platinum frame buffer device\n", info->node); |
| 406 | |
| 407 | return 0; |
| 408 | } |
| 409 | |
| 410 | /* |
| 411 | * Get the monitor sense value. |
| 412 | * Note that this can be called before calibrate_delay, |
| 413 | * so we can't use udelay. |
| 414 | */ |
| 415 | static int read_platinum_sense(struct fb_info_platinum *info) |
| 416 | { |
| 417 | volatile struct platinum_regs __iomem *platinum_regs = info->platinum_regs; |
| 418 | int sense; |
| 419 | |
| 420 | out_be32(&platinum_regs->reg[23].r, 7); /* turn off drivers */ |
| 421 | __delay(2000); |
| 422 | sense = (~in_be32(&platinum_regs->reg[23].r) & 7) << 8; |
| 423 | |
| 424 | /* drive each sense line low in turn and collect the other 2 */ |
| 425 | out_be32(&platinum_regs->reg[23].r, 3); /* drive A low */ |
| 426 | __delay(2000); |
| 427 | sense |= (~in_be32(&platinum_regs->reg[23].r) & 3) << 4; |
| 428 | out_be32(&platinum_regs->reg[23].r, 5); /* drive B low */ |
| 429 | __delay(2000); |
| 430 | sense |= (~in_be32(&platinum_regs->reg[23].r) & 4) << 1; |
| 431 | sense |= (~in_be32(&platinum_regs->reg[23].r) & 1) << 2; |
| 432 | out_be32(&platinum_regs->reg[23].r, 6); /* drive C low */ |
| 433 | __delay(2000); |
| 434 | sense |= (~in_be32(&platinum_regs->reg[23].r) & 6) >> 1; |
| 435 | |
| 436 | out_be32(&platinum_regs->reg[23].r, 7); /* turn off drivers */ |
| 437 | |
| 438 | return sense; |
| 439 | } |
| 440 | |
| 441 | /* |
| 442 | * This routine takes a user-supplied var, and picks the best vmode/cmode from it. |
| 443 | * It also updates the var structure to the actual mode data obtained |
| 444 | */ |
| 445 | static int platinum_var_to_par(struct fb_var_screeninfo *var, |
| 446 | struct fb_info_platinum *pinfo, |
| 447 | int check_only) |
| 448 | { |
| 449 | int vmode, cmode; |
| 450 | |
| 451 | if (mac_var_to_vmode(var, &vmode, &cmode) != 0) { |
| 452 | printk(KERN_ERR "platinum_var_to_par: mac_var_to_vmode unsuccessful.\n"); |
| 453 | printk(KERN_ERR "platinum_var_to_par: var->xres = %d\n", var->xres); |
| 454 | printk(KERN_ERR "platinum_var_to_par: var->yres = %d\n", var->yres); |
| 455 | printk(KERN_ERR "platinum_var_to_par: var->xres_virtual = %d\n", var->xres_virtual); |
| 456 | printk(KERN_ERR "platinum_var_to_par: var->yres_virtual = %d\n", var->yres_virtual); |
| 457 | printk(KERN_ERR "platinum_var_to_par: var->bits_per_pixel = %d\n", var->bits_per_pixel); |
| 458 | printk(KERN_ERR "platinum_var_to_par: var->pixclock = %d\n", var->pixclock); |
| 459 | printk(KERN_ERR "platinum_var_to_par: var->vmode = %d\n", var->vmode); |
| 460 | return -EINVAL; |
| 461 | } |
| 462 | |
| 463 | if (!platinum_reg_init[vmode-1]) { |
| 464 | printk(KERN_ERR "platinum_var_to_par, vmode %d not valid.\n", vmode); |
| 465 | return -EINVAL; |
| 466 | } |
| 467 | |
| 468 | if (platinum_vram_reqd(vmode, cmode) > pinfo->total_vram) { |
| 469 | printk(KERN_ERR "platinum_var_to_par, not enough ram for vmode %d, cmode %d.\n", vmode, cmode); |
| 470 | return -EINVAL; |
| 471 | } |
| 472 | |
| 473 | if (mac_vmode_to_var(vmode, cmode, var)) |
| 474 | return -EINVAL; |
| 475 | |
| 476 | if (check_only) |
| 477 | return 0; |
| 478 | |
| 479 | pinfo->vmode = vmode; |
| 480 | pinfo->cmode = cmode; |
| 481 | pinfo->xres = vmode_attrs[vmode-1].hres; |
| 482 | pinfo->yres = vmode_attrs[vmode-1].vres; |
| 483 | pinfo->xoffset = 0; |
| 484 | pinfo->yoffset = 0; |
| 485 | pinfo->vxres = pinfo->xres; |
| 486 | pinfo->vyres = pinfo->yres; |
| 487 | |
| 488 | return 0; |
| 489 | } |
| 490 | |
| 491 | |
| 492 | /* |
| 493 | * Parse user speficied options (`video=platinumfb:') |
| 494 | */ |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 495 | static int __init platinumfb_setup(char *options) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | { |
| 497 | char *this_opt; |
| 498 | |
| 499 | if (!options || !*options) |
| 500 | return 0; |
| 501 | |
| 502 | while ((this_opt = strsep(&options, ",")) != NULL) { |
| 503 | if (!strncmp(this_opt, "vmode:", 6)) { |
| 504 | int vmode = simple_strtoul(this_opt+6, NULL, 0); |
| 505 | if (vmode > 0 && vmode <= VMODE_MAX) |
| 506 | default_vmode = vmode; |
| 507 | } else if (!strncmp(this_opt, "cmode:", 6)) { |
| 508 | int depth = simple_strtoul(this_opt+6, NULL, 0); |
| 509 | switch (depth) { |
| 510 | case 0: |
| 511 | case 8: |
| 512 | default_cmode = CMODE_8; |
| 513 | break; |
| 514 | case 15: |
| 515 | case 16: |
| 516 | default_cmode = CMODE_16; |
| 517 | break; |
| 518 | case 24: |
| 519 | case 32: |
| 520 | default_cmode = CMODE_32; |
| 521 | break; |
| 522 | } |
| 523 | } |
| 524 | } |
| 525 | return 0; |
| 526 | } |
| 527 | |
| 528 | #ifdef __powerpc__ |
| 529 | #define invalidate_cache(addr) \ |
| 530 | asm volatile("eieio; dcbf 0,%1" \ |
| 531 | : "=m" (*(addr)) : "r" (addr) : "memory"); |
| 532 | #else |
| 533 | #define invalidate_cache(addr) |
| 534 | #endif |
| 535 | |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 536 | static int __devinit platinumfb_probe(struct platform_device* odev, |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 537 | const struct of_device_id *match) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | { |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 539 | struct device_node *dp = odev->dev.of_node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | struct fb_info *info; |
| 541 | struct fb_info_platinum *pinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | volatile __u8 *fbuffer; |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 543 | int bank0, bank1, bank2, bank3, rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | |
Benjamin Herrenschmidt | 4c2a54b | 2007-09-19 14:50:22 +1000 | [diff] [blame] | 545 | dev_info(&odev->dev, "Found Apple Platinum video hardware\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | |
| 547 | info = framebuffer_alloc(sizeof(*pinfo), &odev->dev); |
Benjamin Herrenschmidt | 4c2a54b | 2007-09-19 14:50:22 +1000 | [diff] [blame] | 548 | if (info == NULL) { |
| 549 | dev_err(&odev->dev, "Failed to allocate fbdev !\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | return -ENOMEM; |
Benjamin Herrenschmidt | 4c2a54b | 2007-09-19 14:50:22 +1000 | [diff] [blame] | 551 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | pinfo = info->par; |
| 553 | |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 554 | if (of_address_to_resource(dp, 0, &pinfo->rsrc_reg) || |
| 555 | of_address_to_resource(dp, 1, &pinfo->rsrc_fb)) { |
Benjamin Herrenschmidt | 4c2a54b | 2007-09-19 14:50:22 +1000 | [diff] [blame] | 556 | dev_err(&odev->dev, "Can't get resources\n"); |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 557 | framebuffer_release(info); |
| 558 | return -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | } |
Benjamin Herrenschmidt | 4c2a54b | 2007-09-19 14:50:22 +1000 | [diff] [blame] | 560 | dev_dbg(&odev->dev, " registers : 0x%llx...0x%llx\n", |
| 561 | (unsigned long long)pinfo->rsrc_reg.start, |
| 562 | (unsigned long long)pinfo->rsrc_reg.end); |
| 563 | dev_dbg(&odev->dev, " framebuffer: 0x%llx...0x%llx\n", |
| 564 | (unsigned long long)pinfo->rsrc_fb.start, |
| 565 | (unsigned long long)pinfo->rsrc_fb.end); |
| 566 | |
| 567 | /* Do not try to request register space, they overlap with the |
| 568 | * northbridge and that can fail. Only request framebuffer |
| 569 | */ |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 570 | if (!request_mem_region(pinfo->rsrc_fb.start, |
Benjamin Herrenschmidt | 4c2a54b | 2007-09-19 14:50:22 +1000 | [diff] [blame] | 571 | pinfo->rsrc_fb.end - pinfo->rsrc_fb.start + 1, |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 572 | "platinumfb framebuffer")) { |
Benjamin Herrenschmidt | 4c2a54b | 2007-09-19 14:50:22 +1000 | [diff] [blame] | 573 | printk(KERN_ERR "platinumfb: Can't request framebuffer !\n"); |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 574 | framebuffer_release(info); |
| 575 | return -ENXIO; |
| 576 | } |
| 577 | |
| 578 | /* frame buffer - map only 4MB */ |
| 579 | pinfo->frame_buffer_phys = pinfo->rsrc_fb.start; |
| 580 | pinfo->frame_buffer = __ioremap(pinfo->rsrc_fb.start, 0x400000, |
| 581 | _PAGE_WRITETHRU); |
| 582 | pinfo->base_frame_buffer = pinfo->frame_buffer; |
| 583 | |
| 584 | /* registers */ |
| 585 | pinfo->platinum_regs_phys = pinfo->rsrc_reg.start; |
| 586 | pinfo->platinum_regs = ioremap(pinfo->rsrc_reg.start, 0x1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | |
| 588 | pinfo->cmap_regs_phys = 0xf301b000; /* XXX not in prom? */ |
| 589 | request_mem_region(pinfo->cmap_regs_phys, 0x1000, "platinumfb cmap"); |
| 590 | pinfo->cmap_regs = ioremap(pinfo->cmap_regs_phys, 0x1000); |
| 591 | |
| 592 | /* Grok total video ram */ |
| 593 | out_be32(&pinfo->platinum_regs->reg[16].r, (unsigned)pinfo->frame_buffer_phys); |
| 594 | out_be32(&pinfo->platinum_regs->reg[20].r, 0x1011); /* select max vram */ |
| 595 | out_be32(&pinfo->platinum_regs->reg[24].r, 0); /* switch in vram */ |
| 596 | |
| 597 | fbuffer = pinfo->base_frame_buffer; |
| 598 | fbuffer[0x100000] = 0x34; |
| 599 | fbuffer[0x100008] = 0x0; |
| 600 | invalidate_cache(&fbuffer[0x100000]); |
| 601 | fbuffer[0x200000] = 0x56; |
| 602 | fbuffer[0x200008] = 0x0; |
| 603 | invalidate_cache(&fbuffer[0x200000]); |
| 604 | fbuffer[0x300000] = 0x78; |
| 605 | fbuffer[0x300008] = 0x0; |
| 606 | invalidate_cache(&fbuffer[0x300000]); |
| 607 | bank0 = 1; /* builtin 1MB vram, always there */ |
| 608 | bank1 = fbuffer[0x100000] == 0x34; |
| 609 | bank2 = fbuffer[0x200000] == 0x56; |
| 610 | bank3 = fbuffer[0x300000] == 0x78; |
| 611 | pinfo->total_vram = (bank0 + bank1 + bank2 + bank3) * 0x100000; |
Benjamin Herrenschmidt | 4c2a54b | 2007-09-19 14:50:22 +1000 | [diff] [blame] | 612 | printk(KERN_INFO "platinumfb: Total VRAM = %dMB (%d%d%d%d)\n", |
| 613 | (unsigned int) (pinfo->total_vram / 1024 / 1024), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | bank3, bank2, bank1, bank0); |
| 615 | |
| 616 | /* |
| 617 | * Try to determine whether we have an old or a new DACula. |
| 618 | */ |
| 619 | out_8(&pinfo->cmap_regs->addr, 0x40); |
| 620 | pinfo->dactype = in_8(&pinfo->cmap_regs->d2); |
| 621 | switch (pinfo->dactype) { |
| 622 | case 0x3c: |
| 623 | pinfo->clktype = 1; |
| 624 | printk(KERN_INFO "platinumfb: DACula type 0x3c\n"); |
| 625 | break; |
| 626 | case 0x84: |
| 627 | pinfo->clktype = 0; |
| 628 | printk(KERN_INFO "platinumfb: DACula type 0x84\n"); |
| 629 | break; |
| 630 | default: |
| 631 | pinfo->clktype = 0; |
| 632 | printk(KERN_INFO "platinumfb: Unknown DACula type: %x\n", pinfo->dactype); |
| 633 | break; |
| 634 | } |
| 635 | dev_set_drvdata(&odev->dev, info); |
| 636 | |
| 637 | rc = platinum_init_fb(info); |
| 638 | if (rc != 0) { |
Amol Lad | 2b7574d | 2006-12-08 02:40:07 -0800 | [diff] [blame] | 639 | iounmap(pinfo->frame_buffer); |
| 640 | iounmap(pinfo->platinum_regs); |
| 641 | iounmap(pinfo->cmap_regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | dev_set_drvdata(&odev->dev, NULL); |
| 643 | framebuffer_release(info); |
| 644 | } |
| 645 | |
| 646 | return rc; |
| 647 | } |
| 648 | |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 649 | static int __devexit platinumfb_remove(struct platform_device* odev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | { |
| 651 | struct fb_info *info = dev_get_drvdata(&odev->dev); |
| 652 | struct fb_info_platinum *pinfo = info->par; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | |
| 654 | unregister_framebuffer (info); |
| 655 | |
| 656 | /* Unmap frame buffer and registers */ |
Benjamin Herrenschmidt | 4c2a54b | 2007-09-19 14:50:22 +1000 | [diff] [blame] | 657 | iounmap(pinfo->frame_buffer); |
| 658 | iounmap(pinfo->platinum_regs); |
| 659 | iounmap(pinfo->cmap_regs); |
| 660 | |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 661 | release_mem_region(pinfo->rsrc_fb.start, |
| 662 | pinfo->rsrc_fb.end - |
| 663 | pinfo->rsrc_fb.start + 1); |
Benjamin Herrenschmidt | 4c2a54b | 2007-09-19 14:50:22 +1000 | [diff] [blame] | 664 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | release_mem_region(pinfo->cmap_regs_phys, 0x1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | |
| 667 | framebuffer_release(info); |
| 668 | |
| 669 | return 0; |
| 670 | } |
| 671 | |
Jeff Mahoney | 5e65577 | 2005-07-06 15:44:41 -0400 | [diff] [blame] | 672 | static struct of_device_id platinumfb_match[] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | { |
| 674 | { |
| 675 | .name = "platinum", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | }, |
| 677 | {}, |
| 678 | }; |
| 679 | |
| 680 | static struct of_platform_driver platinum_driver = |
| 681 | { |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 682 | .driver = { |
| 683 | .name = "platinumfb", |
| 684 | .owner = THIS_MODULE, |
| 685 | .of_match_table = platinumfb_match, |
| 686 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | .probe = platinumfb_probe, |
| 688 | .remove = platinumfb_remove, |
| 689 | }; |
| 690 | |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 691 | static int __init platinumfb_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | { |
| 693 | #ifndef MODULE |
| 694 | char *option = NULL; |
| 695 | |
| 696 | if (fb_get_options("platinumfb", &option)) |
| 697 | return -ENODEV; |
| 698 | platinumfb_setup(option); |
| 699 | #endif |
Benjamin Herrenschmidt | 7eebde7 | 2006-11-11 17:24:59 +1100 | [diff] [blame] | 700 | of_register_platform_driver(&platinum_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | |
| 702 | return 0; |
| 703 | } |
| 704 | |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 705 | static void __exit platinumfb_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | { |
Benjamin Herrenschmidt | 7eebde7 | 2006-11-11 17:24:59 +1100 | [diff] [blame] | 707 | of_unregister_platform_driver(&platinum_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | MODULE_LICENSE("GPL"); |
| 711 | MODULE_DESCRIPTION("framebuffer driver for Apple Platinum video"); |
| 712 | module_init(platinumfb_init); |
| 713 | |
| 714 | #ifdef MODULE |
| 715 | module_exit(platinumfb_exit); |
| 716 | #endif |