Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v2.6.15-rc6 667 lines 16 kB view raw
1/* leo.c: LEO frame buffer driver 2 * 3 * Copyright (C) 2003 David S. Miller (davem@redhat.com) 4 * Copyright (C) 1996-1999 Jakub Jelinek (jj@ultra.linux.cz) 5 * Copyright (C) 1997 Michal Rehacek (Michal.Rehacek@st.mff.cuni.cz) 6 * 7 * Driver layout based loosely on tgafb.c, see that file for credits. 8 */ 9 10#include <linux/module.h> 11#include <linux/kernel.h> 12#include <linux/errno.h> 13#include <linux/string.h> 14#include <linux/slab.h> 15#include <linux/delay.h> 16#include <linux/init.h> 17#include <linux/fb.h> 18#include <linux/mm.h> 19 20#include <asm/io.h> 21#include <asm/sbus.h> 22#include <asm/oplib.h> 23#include <asm/fbio.h> 24 25#include "sbuslib.h" 26 27/* 28 * Local functions. 29 */ 30 31static int leo_setcolreg(unsigned, unsigned, unsigned, unsigned, 32 unsigned, struct fb_info *); 33static int leo_blank(int, struct fb_info *); 34 35static int leo_mmap(struct fb_info *, struct file *, struct vm_area_struct *); 36static int leo_ioctl(struct inode *, struct file *, unsigned int, 37 unsigned long, struct fb_info *); 38static int leo_pan_display(struct fb_var_screeninfo *, struct fb_info *); 39 40/* 41 * Frame buffer operations 42 */ 43 44static struct fb_ops leo_ops = { 45 .owner = THIS_MODULE, 46 .fb_setcolreg = leo_setcolreg, 47 .fb_blank = leo_blank, 48 .fb_pan_display = leo_pan_display, 49 .fb_fillrect = cfb_fillrect, 50 .fb_copyarea = cfb_copyarea, 51 .fb_imageblit = cfb_imageblit, 52 .fb_mmap = leo_mmap, 53 .fb_ioctl = leo_ioctl, 54#ifdef CONFIG_COMPAT 55 .fb_compat_ioctl = sbusfb_compat_ioctl, 56#endif 57}; 58 59#define LEO_OFF_LC_SS0_KRN 0x00200000UL 60#define LEO_OFF_LC_SS0_USR 0x00201000UL 61#define LEO_OFF_LC_SS1_KRN 0x01200000UL 62#define LEO_OFF_LC_SS1_USR 0x01201000UL 63#define LEO_OFF_LD_SS0 0x00400000UL 64#define LEO_OFF_LD_SS1 0x01400000UL 65#define LEO_OFF_LD_GBL 0x00401000UL 66#define LEO_OFF_LX_KRN 0x00600000UL 67#define LEO_OFF_LX_CURSOR 0x00601000UL 68#define LEO_OFF_SS0 0x00800000UL 69#define LEO_OFF_SS1 0x01800000UL 70#define LEO_OFF_UNK 0x00602000UL 71#define LEO_OFF_UNK2 0x00000000UL 72 73#define LEO_CUR_ENABLE 0x00000080 74#define LEO_CUR_UPDATE 0x00000030 75#define LEO_CUR_PROGRESS 0x00000006 76#define LEO_CUR_UPDATECMAP 0x00000003 77 78#define LEO_CUR_TYPE_MASK 0x00000000 79#define LEO_CUR_TYPE_IMAGE 0x00000020 80#define LEO_CUR_TYPE_CMAP 0x00000050 81 82struct leo_cursor { 83 u8 xxx0[16]; 84 volatile u32 cur_type; 85 volatile u32 cur_misc; 86 volatile u32 cur_cursxy; 87 volatile u32 cur_data; 88}; 89 90#define LEO_KRN_TYPE_CLUT0 0x00001000 91#define LEO_KRN_TYPE_CLUT1 0x00001001 92#define LEO_KRN_TYPE_CLUT2 0x00001002 93#define LEO_KRN_TYPE_WID 0x00001003 94#define LEO_KRN_TYPE_UNK 0x00001006 95#define LEO_KRN_TYPE_VIDEO 0x00002003 96#define LEO_KRN_TYPE_CLUTDATA 0x00004000 97#define LEO_KRN_CSR_ENABLE 0x00000008 98#define LEO_KRN_CSR_PROGRESS 0x00000004 99#define LEO_KRN_CSR_UNK 0x00000002 100#define LEO_KRN_CSR_UNK2 0x00000001 101 102struct leo_lx_krn { 103 volatile u32 krn_type; 104 volatile u32 krn_csr; 105 volatile u32 krn_value; 106}; 107 108struct leo_lc_ss0_krn { 109 volatile u32 misc; 110 u8 xxx0[0x800-4]; 111 volatile u32 rev; 112}; 113 114struct leo_lc_ss0_usr { 115 volatile u32 csr; 116 volatile u32 addrspace; 117 volatile u32 fontmsk; 118 volatile u32 fontt; 119 volatile u32 extent; 120 volatile u32 src; 121 u32 dst; 122 volatile u32 copy; 123 volatile u32 fill; 124}; 125 126struct leo_lc_ss1_krn { 127 u8 unknown; 128}; 129 130struct leo_lc_ss1_usr { 131 u8 unknown; 132}; 133 134struct leo_ld { 135 u8 xxx0[0xe00]; 136 volatile u32 csr; 137 volatile u32 wid; 138 volatile u32 wmask; 139 volatile u32 widclip; 140 volatile u32 vclipmin; 141 volatile u32 vclipmax; 142 volatile u32 pickmin; /* SS1 only */ 143 volatile u32 pickmax; /* SS1 only */ 144 volatile u32 fg; 145 volatile u32 bg; 146 volatile u32 src; /* Copy/Scroll (SS0 only) */ 147 volatile u32 dst; /* Copy/Scroll/Fill (SS0 only) */ 148 volatile u32 extent; /* Copy/Scroll/Fill size (SS0 only) */ 149 u32 xxx1[3]; 150 volatile u32 setsem; /* SS1 only */ 151 volatile u32 clrsem; /* SS1 only */ 152 volatile u32 clrpick; /* SS1 only */ 153 volatile u32 clrdat; /* SS1 only */ 154 volatile u32 alpha; /* SS1 only */ 155 u8 xxx2[0x2c]; 156 volatile u32 winbg; 157 volatile u32 planemask; 158 volatile u32 rop; 159 volatile u32 z; 160 volatile u32 dczf; /* SS1 only */ 161 volatile u32 dczb; /* SS1 only */ 162 volatile u32 dcs; /* SS1 only */ 163 volatile u32 dczs; /* SS1 only */ 164 volatile u32 pickfb; /* SS1 only */ 165 volatile u32 pickbb; /* SS1 only */ 166 volatile u32 dcfc; /* SS1 only */ 167 volatile u32 forcecol; /* SS1 only */ 168 volatile u32 door[8]; /* SS1 only */ 169 volatile u32 pick[5]; /* SS1 only */ 170}; 171 172#define LEO_SS1_MISC_ENABLE 0x00000001 173#define LEO_SS1_MISC_STEREO 0x00000002 174struct leo_ld_ss1 { 175 u8 xxx0[0xef4]; 176 volatile u32 ss1_misc; 177}; 178 179struct leo_ld_gbl { 180 u8 unknown; 181}; 182 183struct leo_par { 184 spinlock_t lock; 185 struct leo_lx_krn __iomem *lx_krn; 186 struct leo_lc_ss0_usr __iomem *lc_ss0_usr; 187 struct leo_ld_ss0 __iomem *ld_ss0; 188 struct leo_ld_ss1 __iomem *ld_ss1; 189 struct leo_cursor __iomem *cursor; 190 u32 extent; 191 u32 clut_data[256]; 192 193 u32 flags; 194#define LEO_FLAG_BLANKED 0x00000001 195 196 unsigned long physbase; 197 unsigned long fbsize; 198 199 struct sbus_dev *sdev; 200}; 201 202static void leo_wait(struct leo_lx_krn __iomem *lx_krn) 203{ 204 int i; 205 206 for (i = 0; 207 (sbus_readl(&lx_krn->krn_csr) & LEO_KRN_CSR_PROGRESS) && i < 300000; 208 i++) 209 udelay (1); /* Busy wait at most 0.3 sec */ 210 return; 211} 212 213/** 214 * leo_setcolreg - Optional function. Sets a color register. 215 * @regno: boolean, 0 copy local, 1 get_user() function 216 * @red: frame buffer colormap structure 217 * @green: The green value which can be up to 16 bits wide 218 * @blue: The blue value which can be up to 16 bits wide. 219 * @transp: If supported the alpha value which can be up to 16 bits wide. 220 * @info: frame buffer info structure 221 */ 222static int leo_setcolreg(unsigned regno, 223 unsigned red, unsigned green, unsigned blue, 224 unsigned transp, struct fb_info *info) 225{ 226 struct leo_par *par = (struct leo_par *) info->par; 227 struct leo_lx_krn __iomem *lx_krn = par->lx_krn; 228 unsigned long flags; 229 u32 val; 230 int i; 231 232 if (regno >= 256) 233 return 1; 234 235 red >>= 8; 236 green >>= 8; 237 blue >>= 8; 238 239 par->clut_data[regno] = red | (green << 8) | (blue << 16); 240 241 spin_lock_irqsave(&par->lock, flags); 242 243 leo_wait(lx_krn); 244 245 sbus_writel(LEO_KRN_TYPE_CLUTDATA, &lx_krn->krn_type); 246 for (i = 0; i < 256; i++) 247 sbus_writel(par->clut_data[i], &lx_krn->krn_value); 248 sbus_writel(LEO_KRN_TYPE_CLUT0, &lx_krn->krn_type); 249 250 val = sbus_readl(&lx_krn->krn_csr); 251 val |= (LEO_KRN_CSR_UNK | LEO_KRN_CSR_UNK2); 252 sbus_writel(val, &lx_krn->krn_csr); 253 254 spin_unlock_irqrestore(&par->lock, flags); 255 256 return 0; 257} 258 259/** 260 * leo_blank - Optional function. Blanks the display. 261 * @blank_mode: the blank mode we want. 262 * @info: frame buffer structure that represents a single frame buffer 263 */ 264static int leo_blank(int blank, struct fb_info *info) 265{ 266 struct leo_par *par = (struct leo_par *) info->par; 267 struct leo_lx_krn __iomem *lx_krn = par->lx_krn; 268 unsigned long flags; 269 u32 val; 270 271 spin_lock_irqsave(&par->lock, flags); 272 273 switch (blank) { 274 case FB_BLANK_UNBLANK: /* Unblanking */ 275 val = sbus_readl(&lx_krn->krn_csr); 276 val |= LEO_KRN_CSR_ENABLE; 277 sbus_writel(val, &lx_krn->krn_csr); 278 par->flags &= ~LEO_FLAG_BLANKED; 279 break; 280 281 case FB_BLANK_NORMAL: /* Normal blanking */ 282 case FB_BLANK_VSYNC_SUSPEND: /* VESA blank (vsync off) */ 283 case FB_BLANK_HSYNC_SUSPEND: /* VESA blank (hsync off) */ 284 case FB_BLANK_POWERDOWN: /* Poweroff */ 285 val = sbus_readl(&lx_krn->krn_csr); 286 val &= ~LEO_KRN_CSR_ENABLE; 287 sbus_writel(val, &lx_krn->krn_csr); 288 par->flags |= LEO_FLAG_BLANKED; 289 break; 290 } 291 292 spin_unlock_irqrestore(&par->lock, flags); 293 294 return 0; 295} 296 297static struct sbus_mmap_map leo_mmap_map[] = { 298 { 299 .voff = LEO_SS0_MAP, 300 .poff = LEO_OFF_SS0, 301 .size = 0x800000 302 }, 303 { 304 .voff = LEO_LC_SS0_USR_MAP, 305 .poff = LEO_OFF_LC_SS0_USR, 306 .size = 0x1000 307 }, 308 { 309 .voff = LEO_LD_SS0_MAP, 310 .poff = LEO_OFF_LD_SS0, 311 .size = 0x1000 312 }, 313 { 314 .voff = LEO_LX_CURSOR_MAP, 315 .poff = LEO_OFF_LX_CURSOR, 316 .size = 0x1000 317 }, 318 { 319 .voff = LEO_SS1_MAP, 320 .poff = LEO_OFF_SS1, 321 .size = 0x800000 322 }, 323 { 324 .voff = LEO_LC_SS1_USR_MAP, 325 .poff = LEO_OFF_LC_SS1_USR, 326 .size = 0x1000 327 }, 328 { 329 .voff = LEO_LD_SS1_MAP, 330 .poff = LEO_OFF_LD_SS1, 331 .size = 0x1000 332 }, 333 { 334 .voff = LEO_UNK_MAP, 335 .poff = LEO_OFF_UNK, 336 .size = 0x1000 337 }, 338 { 339 .voff = LEO_LX_KRN_MAP, 340 .poff = LEO_OFF_LX_KRN, 341 .size = 0x1000 342 }, 343 { 344 .voff = LEO_LC_SS0_KRN_MAP, 345 .poff = LEO_OFF_LC_SS0_KRN, 346 .size = 0x1000 347 }, 348 { 349 .voff = LEO_LC_SS1_KRN_MAP, 350 .poff = LEO_OFF_LC_SS1_KRN, 351 .size = 0x1000 352 }, 353 { 354 .voff = LEO_LD_GBL_MAP, 355 .poff = LEO_OFF_LD_GBL, 356 .size = 0x1000 357 }, 358 { 359 .voff = LEO_UNK2_MAP, 360 .poff = LEO_OFF_UNK2, 361 .size = 0x100000 362 }, 363 { .size = 0 } 364}; 365 366static int leo_mmap(struct fb_info *info, struct file *file, struct vm_area_struct *vma) 367{ 368 struct leo_par *par = (struct leo_par *)info->par; 369 370 return sbusfb_mmap_helper(leo_mmap_map, 371 par->physbase, par->fbsize, 372 par->sdev->reg_addrs[0].which_io, 373 vma); 374} 375 376static int leo_ioctl(struct inode *inode, struct file *file, unsigned int cmd, 377 unsigned long arg, struct fb_info *info) 378{ 379 struct leo_par *par = (struct leo_par *) info->par; 380 381 return sbusfb_ioctl_helper(cmd, arg, info, 382 FBTYPE_SUNLEO, 32, par->fbsize); 383} 384 385/* 386 * Initialisation 387 */ 388 389static void 390leo_init_fix(struct fb_info *info) 391{ 392 struct leo_par *par = (struct leo_par *)info->par; 393 394 strlcpy(info->fix.id, par->sdev->prom_name, sizeof(info->fix.id)); 395 396 info->fix.type = FB_TYPE_PACKED_PIXELS; 397 info->fix.visual = FB_VISUAL_TRUECOLOR; 398 399 info->fix.line_length = 8192; 400 401 info->fix.accel = FB_ACCEL_SUN_LEO; 402} 403 404static void leo_wid_put(struct fb_info *info, struct fb_wid_list *wl) 405{ 406 struct leo_par *par = (struct leo_par *) info->par; 407 struct leo_lx_krn __iomem *lx_krn = par->lx_krn; 408 struct fb_wid_item *wi; 409 unsigned long flags; 410 u32 val; 411 int i, j; 412 413 spin_lock_irqsave(&par->lock, flags); 414 415 leo_wait(lx_krn); 416 417 for (i = 0, wi = wl->wl_list; i < wl->wl_count; i++, wi++) { 418 switch(wi->wi_type) { 419 case FB_WID_DBL_8: 420 j = (wi->wi_index & 0xf) + 0x40; 421 break; 422 423 case FB_WID_DBL_24: 424 j = wi->wi_index & 0x3f; 425 break; 426 427 default: 428 continue; 429 }; 430 sbus_writel(0x5800 + j, &lx_krn->krn_type); 431 sbus_writel(wi->wi_values[0], &lx_krn->krn_value); 432 } 433 sbus_writel(LEO_KRN_TYPE_WID, &lx_krn->krn_type); 434 435 val = sbus_readl(&lx_krn->krn_csr); 436 val |= (LEO_KRN_CSR_UNK | LEO_KRN_CSR_UNK2); 437 sbus_writel(val, &lx_krn->krn_csr); 438 439 spin_unlock_irqrestore(&par->lock, flags); 440} 441 442static void leo_init_wids(struct fb_info *info) 443{ 444 struct fb_wid_item wi; 445 struct fb_wid_list wl; 446 447 wl.wl_count = 1; 448 wl.wl_list = &wi; 449 wi.wi_type = FB_WID_DBL_8; 450 wi.wi_index = 0; 451 wi.wi_values [0] = 0x2c0; 452 leo_wid_put(info, &wl); 453 wi.wi_index = 1; 454 wi.wi_values [0] = 0x30; 455 leo_wid_put(info, &wl); 456 wi.wi_index = 2; 457 wi.wi_values [0] = 0x20; 458 leo_wid_put(info, &wl); 459 wi.wi_type = FB_WID_DBL_24; 460 wi.wi_index = 1; 461 wi.wi_values [0] = 0x30; 462 leo_wid_put(info, &wl); 463 464} 465 466static void leo_switch_from_graph(struct fb_info *info) 467{ 468 struct leo_par *par = (struct leo_par *) info->par; 469 struct leo_ld __iomem *ss = (struct leo_ld __iomem *) par->ld_ss0; 470 unsigned long flags; 471 u32 val; 472 473 spin_lock_irqsave(&par->lock, flags); 474 475 par->extent = ((info->var.xres - 1) | 476 ((info->var.yres - 1) << 16)); 477 478 sbus_writel(0xffffffff, &ss->wid); 479 sbus_writel(0xffff, &ss->wmask); 480 sbus_writel(0, &ss->vclipmin); 481 sbus_writel(par->extent, &ss->vclipmax); 482 sbus_writel(0, &ss->fg); 483 sbus_writel(0xff000000, &ss->planemask); 484 sbus_writel(0x310850, &ss->rop); 485 sbus_writel(0, &ss->widclip); 486 sbus_writel((info->var.xres-1) | ((info->var.yres-1) << 11), 487 &par->lc_ss0_usr->extent); 488 sbus_writel(4, &par->lc_ss0_usr->addrspace); 489 sbus_writel(0x80000000, &par->lc_ss0_usr->fill); 490 sbus_writel(0, &par->lc_ss0_usr->fontt); 491 do { 492 val = sbus_readl(&par->lc_ss0_usr->csr); 493 } while (val & 0x20000000); 494 495 spin_unlock_irqrestore(&par->lock, flags); 496} 497 498static int leo_pan_display(struct fb_var_screeninfo *var, struct fb_info *info) 499{ 500 /* We just use this to catch switches out of 501 * graphics mode. 502 */ 503 leo_switch_from_graph(info); 504 505 if (var->xoffset || var->yoffset || var->vmode) 506 return -EINVAL; 507 return 0; 508} 509 510static void leo_init_hw(struct fb_info *info) 511{ 512 struct leo_par *par = (struct leo_par *) info->par; 513 u32 val; 514 515 val = sbus_readl(&par->ld_ss1->ss1_misc); 516 val |= LEO_SS1_MISC_ENABLE; 517 sbus_writel(val, &par->ld_ss1->ss1_misc); 518 519 leo_switch_from_graph(info); 520} 521 522static void leo_fixup_var_rgb(struct fb_var_screeninfo *var) 523{ 524 var->red.offset = 0; 525 var->red.length = 8; 526 var->green.offset = 8; 527 var->green.length = 8; 528 var->blue.offset = 16; 529 var->blue.length = 8; 530 var->transp.offset = 0; 531 var->transp.length = 0; 532} 533 534struct all_info { 535 struct fb_info info; 536 struct leo_par par; 537 struct list_head list; 538}; 539static LIST_HEAD(leo_list); 540 541static void leo_init_one(struct sbus_dev *sdev) 542{ 543 struct all_info *all; 544 int linebytes; 545 546 all = kmalloc(sizeof(*all), GFP_KERNEL); 547 if (!all) { 548 printk(KERN_ERR "leo: Cannot allocate memory.\n"); 549 return; 550 } 551 memset(all, 0, sizeof(*all)); 552 553 INIT_LIST_HEAD(&all->list); 554 555 spin_lock_init(&all->par.lock); 556 all->par.sdev = sdev; 557 558 all->par.physbase = sdev->reg_addrs[0].phys_addr; 559 560 sbusfb_fill_var(&all->info.var, sdev->prom_node, 32); 561 leo_fixup_var_rgb(&all->info.var); 562 563 linebytes = prom_getintdefault(sdev->prom_node, "linebytes", 564 all->info.var.xres); 565 all->par.fbsize = PAGE_ALIGN(linebytes * all->info.var.yres); 566 567#ifdef CONFIG_SPARC32 568 all->info.screen_base = (char __iomem *) 569 prom_getintdefault(sdev->prom_node, "address", 0); 570#endif 571 if (!all->info.screen_base) 572 all->info.screen_base = 573 sbus_ioremap(&sdev->resource[0], LEO_OFF_SS0, 574 0x800000, "leo ram"); 575 576 all->par.lc_ss0_usr = 577 sbus_ioremap(&sdev->resource[0], LEO_OFF_LC_SS0_USR, 578 0x1000, "leolc ss0usr"); 579 all->par.ld_ss0 = 580 sbus_ioremap(&sdev->resource[0], LEO_OFF_LD_SS0, 581 0x1000, "leold ss0"); 582 all->par.ld_ss1 = 583 sbus_ioremap(&sdev->resource[0], LEO_OFF_LD_SS1, 584 0x1000, "leold ss1"); 585 all->par.lx_krn = 586 sbus_ioremap(&sdev->resource[0], LEO_OFF_LX_KRN, 587 0x1000, "leolx krn"); 588 all->par.cursor = 589 sbus_ioremap(&sdev->resource[0], LEO_OFF_LX_CURSOR, 590 sizeof(struct leo_cursor), "leolx cursor"); 591 592 all->info.flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN; 593 all->info.fbops = &leo_ops; 594 all->info.par = &all->par; 595 596 leo_init_wids(&all->info); 597 leo_init_hw(&all->info); 598 599 leo_blank(0, &all->info); 600 601 if (fb_alloc_cmap(&all->info.cmap, 256, 0)) { 602 printk(KERN_ERR "leo: Could not allocate color map.\n"); 603 kfree(all); 604 return; 605 } 606 607 leo_init_fix(&all->info); 608 609 if (register_framebuffer(&all->info) < 0) { 610 printk(KERN_ERR "leo: Could not register framebuffer.\n"); 611 fb_dealloc_cmap(&all->info.cmap); 612 kfree(all); 613 return; 614 } 615 616 list_add(&all->list, &leo_list); 617 618 printk("leo: %s at %lx:%lx\n", 619 sdev->prom_name, 620 (long) sdev->reg_addrs[0].which_io, 621 (long) sdev->reg_addrs[0].phys_addr); 622} 623 624int __init leo_init(void) 625{ 626 struct sbus_bus *sbus; 627 struct sbus_dev *sdev; 628 629 if (fb_get_options("leofb", NULL)) 630 return -ENODEV; 631 632 for_all_sbusdev(sdev, sbus) { 633 if (!strcmp(sdev->prom_name, "leo")) 634 leo_init_one(sdev); 635 } 636 637 return 0; 638} 639 640void __exit leo_exit(void) 641{ 642 struct list_head *pos, *tmp; 643 644 list_for_each_safe(pos, tmp, &leo_list) { 645 struct all_info *all = list_entry(pos, typeof(*all), list); 646 647 unregister_framebuffer(&all->info); 648 fb_dealloc_cmap(&all->info.cmap); 649 kfree(all); 650 } 651} 652 653int __init 654leo_setup(char *arg) 655{ 656 /* No cmdline options yet... */ 657 return 0; 658} 659 660module_init(leo_init); 661#ifdef MODULE 662module_exit(leo_exit); 663#endif 664 665MODULE_DESCRIPTION("framebuffer driver for LEO chipsets"); 666MODULE_AUTHOR("David S. Miller <davem@redhat.com>"); 667MODULE_LICENSE("GPL");