diff options
Diffstat (limited to 'drivers/video/tcx.c')
-rw-r--r-- | drivers/video/tcx.c | 224 |
1 files changed, 128 insertions, 96 deletions
diff --git a/drivers/video/tcx.c b/drivers/video/tcx.c index 95b918229d9b..6990ab11cd06 100644 --- a/drivers/video/tcx.c +++ b/drivers/video/tcx.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* tcx.c: TCX frame buffer driver | 1 | /* tcx.c: TCX frame buffer driver |
2 | * | 2 | * |
3 | * Copyright (C) 2003 David S. Miller (davem@redhat.com) | 3 | * Copyright (C) 2003, 2006 David S. Miller (davem@davemloft.net) |
4 | * Copyright (C) 1996,1998 Jakub Jelinek (jj@ultra.linux.cz) | 4 | * Copyright (C) 1996,1998 Jakub Jelinek (jj@ultra.linux.cz) |
5 | * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx) | 5 | * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx) |
6 | * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be) | 6 | * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be) |
@@ -19,8 +19,8 @@ | |||
19 | #include <linux/mm.h> | 19 | #include <linux/mm.h> |
20 | 20 | ||
21 | #include <asm/io.h> | 21 | #include <asm/io.h> |
22 | #include <asm/sbus.h> | 22 | #include <asm/prom.h> |
23 | #include <asm/oplib.h> | 23 | #include <asm/of_device.h> |
24 | #include <asm/fbio.h> | 24 | #include <asm/fbio.h> |
25 | 25 | ||
26 | #include "sbuslib.h" | 26 | #include "sbuslib.h" |
@@ -77,32 +77,32 @@ static struct fb_ops tcx_ops = { | |||
77 | 77 | ||
78 | /* The contents are unknown */ | 78 | /* The contents are unknown */ |
79 | struct tcx_tec { | 79 | struct tcx_tec { |
80 | volatile u32 tec_matrix; | 80 | u32 tec_matrix; |
81 | volatile u32 tec_clip; | 81 | u32 tec_clip; |
82 | volatile u32 tec_vdc; | 82 | u32 tec_vdc; |
83 | }; | 83 | }; |
84 | 84 | ||
85 | struct tcx_thc { | 85 | struct tcx_thc { |
86 | volatile u32 thc_rev; | 86 | u32 thc_rev; |
87 | u32 thc_pad0[511]; | 87 | u32 thc_pad0[511]; |
88 | volatile u32 thc_hs; /* hsync timing */ | 88 | u32 thc_hs; /* hsync timing */ |
89 | volatile u32 thc_hsdvs; | 89 | u32 thc_hsdvs; |
90 | volatile u32 thc_hd; | 90 | u32 thc_hd; |
91 | volatile u32 thc_vs; /* vsync timing */ | 91 | u32 thc_vs; /* vsync timing */ |
92 | volatile u32 thc_vd; | 92 | u32 thc_vd; |
93 | volatile u32 thc_refresh; | 93 | u32 thc_refresh; |
94 | volatile u32 thc_misc; | 94 | u32 thc_misc; |
95 | u32 thc_pad1[56]; | 95 | u32 thc_pad1[56]; |
96 | volatile u32 thc_cursxy; /* cursor x,y position (16 bits each) */ | 96 | u32 thc_cursxy; /* cursor x,y position (16 bits each) */ |
97 | volatile u32 thc_cursmask[32]; /* cursor mask bits */ | 97 | u32 thc_cursmask[32]; /* cursor mask bits */ |
98 | volatile u32 thc_cursbits[32]; /* what to show where mask enabled */ | 98 | u32 thc_cursbits[32]; /* what to show where mask enabled */ |
99 | }; | 99 | }; |
100 | 100 | ||
101 | struct bt_regs { | 101 | struct bt_regs { |
102 | volatile u32 addr; | 102 | u32 addr; |
103 | volatile u32 color_map; | 103 | u32 color_map; |
104 | volatile u32 control; | 104 | u32 control; |
105 | volatile u32 cursor; | 105 | u32 cursor; |
106 | }; | 106 | }; |
107 | 107 | ||
108 | #define TCX_MMAP_ENTRIES 14 | 108 | #define TCX_MMAP_ENTRIES 14 |
@@ -112,24 +112,23 @@ struct tcx_par { | |||
112 | struct bt_regs __iomem *bt; | 112 | struct bt_regs __iomem *bt; |
113 | struct tcx_thc __iomem *thc; | 113 | struct tcx_thc __iomem *thc; |
114 | struct tcx_tec __iomem *tec; | 114 | struct tcx_tec __iomem *tec; |
115 | volatile u32 __iomem *cplane; | 115 | u32 __iomem *cplane; |
116 | 116 | ||
117 | u32 flags; | 117 | u32 flags; |
118 | #define TCX_FLAG_BLANKED 0x00000001 | 118 | #define TCX_FLAG_BLANKED 0x00000001 |
119 | 119 | ||
120 | unsigned long physbase; | 120 | unsigned long physbase; |
121 | unsigned long which_io; | ||
121 | unsigned long fbsize; | 122 | unsigned long fbsize; |
122 | 123 | ||
123 | struct sbus_mmap_map mmap_map[TCX_MMAP_ENTRIES]; | 124 | struct sbus_mmap_map mmap_map[TCX_MMAP_ENTRIES]; |
124 | int lowdepth; | 125 | int lowdepth; |
125 | |||
126 | struct sbus_dev *sdev; | ||
127 | }; | 126 | }; |
128 | 127 | ||
129 | /* Reset control plane so that WID is 8-bit plane. */ | 128 | /* Reset control plane so that WID is 8-bit plane. */ |
130 | static void __tcx_set_control_plane (struct tcx_par *par) | 129 | static void __tcx_set_control_plane (struct tcx_par *par) |
131 | { | 130 | { |
132 | volatile u32 __iomem *p, *pend; | 131 | u32 __iomem *p, *pend; |
133 | 132 | ||
134 | if (par->lowdepth) | 133 | if (par->lowdepth) |
135 | return; | 134 | return; |
@@ -307,8 +306,7 @@ static int tcx_mmap(struct fb_info *info, struct vm_area_struct *vma) | |||
307 | 306 | ||
308 | return sbusfb_mmap_helper(par->mmap_map, | 307 | return sbusfb_mmap_helper(par->mmap_map, |
309 | par->physbase, par->fbsize, | 308 | par->physbase, par->fbsize, |
310 | par->sdev->reg_addrs[0].which_io, | 309 | par->which_io, vma); |
311 | vma); | ||
312 | } | 310 | } |
313 | 311 | ||
314 | static int tcx_ioctl(struct fb_info *info, unsigned int cmd, | 312 | static int tcx_ioctl(struct fb_info *info, unsigned int cmd, |
@@ -350,48 +348,71 @@ tcx_init_fix(struct fb_info *info, int linebytes) | |||
350 | struct all_info { | 348 | struct all_info { |
351 | struct fb_info info; | 349 | struct fb_info info; |
352 | struct tcx_par par; | 350 | struct tcx_par par; |
353 | struct list_head list; | ||
354 | }; | 351 | }; |
355 | static LIST_HEAD(tcx_list); | ||
356 | 352 | ||
357 | static void tcx_init_one(struct sbus_dev *sdev) | 353 | static void tcx_unmap_regs(struct all_info *all) |
358 | { | 354 | { |
359 | struct all_info *all; | 355 | if (all->par.tec) |
360 | int linebytes, i; | 356 | of_iounmap(all->par.tec, sizeof(struct tcx_tec)); |
357 | if (all->par.thc) | ||
358 | of_iounmap(all->par.thc, sizeof(struct tcx_thc)); | ||
359 | if (all->par.bt) | ||
360 | of_iounmap(all->par.bt, sizeof(struct bt_regs)); | ||
361 | if (all->par.cplane) | ||
362 | of_iounmap(all->par.cplane, all->par.fbsize * sizeof(u32)); | ||
363 | if (all->info.screen_base) | ||
364 | of_iounmap(all->info.screen_base, all->par.fbsize); | ||
365 | } | ||
361 | 366 | ||
362 | all = kmalloc(sizeof(*all), GFP_KERNEL); | 367 | static int __devinit tcx_init_one(struct of_device *op) |
363 | if (!all) { | 368 | { |
364 | printk(KERN_ERR "tcx: Cannot allocate memory.\n"); | 369 | struct device_node *dp = op->node; |
365 | return; | 370 | struct all_info *all; |
366 | } | 371 | int linebytes, i, err; |
367 | memset(all, 0, sizeof(*all)); | ||
368 | 372 | ||
369 | INIT_LIST_HEAD(&all->list); | 373 | all = kzalloc(sizeof(*all), GFP_KERNEL); |
374 | if (!all) | ||
375 | return -ENOMEM; | ||
370 | 376 | ||
371 | spin_lock_init(&all->par.lock); | 377 | spin_lock_init(&all->par.lock); |
372 | all->par.sdev = sdev; | ||
373 | 378 | ||
374 | all->par.lowdepth = prom_getbool(sdev->prom_node, "tcx-8-bit"); | 379 | all->par.lowdepth = |
380 | (of_find_property(dp, "tcx-8-bit", NULL) != NULL); | ||
375 | 381 | ||
376 | sbusfb_fill_var(&all->info.var, sdev->prom_node, 8); | 382 | sbusfb_fill_var(&all->info.var, dp->node, 8); |
377 | all->info.var.red.length = 8; | 383 | all->info.var.red.length = 8; |
378 | all->info.var.green.length = 8; | 384 | all->info.var.green.length = 8; |
379 | all->info.var.blue.length = 8; | 385 | all->info.var.blue.length = 8; |
380 | 386 | ||
381 | linebytes = prom_getintdefault(sdev->prom_node, "linebytes", | 387 | linebytes = of_getintprop_default(dp, "linebytes", |
382 | all->info.var.xres); | 388 | all->info.var.xres); |
383 | all->par.fbsize = PAGE_ALIGN(linebytes * all->info.var.yres); | 389 | all->par.fbsize = PAGE_ALIGN(linebytes * all->info.var.yres); |
384 | 390 | ||
385 | all->par.tec = sbus_ioremap(&sdev->resource[7], 0, | 391 | all->par.tec = of_ioremap(&op->resource[7], 0, |
386 | sizeof(struct tcx_tec), "tcx tec"); | 392 | sizeof(struct tcx_tec), "tcx tec"); |
387 | all->par.thc = sbus_ioremap(&sdev->resource[9], 0, | 393 | all->par.thc = of_ioremap(&op->resource[9], 0, |
388 | sizeof(struct tcx_thc), "tcx thc"); | 394 | sizeof(struct tcx_thc), "tcx thc"); |
389 | all->par.bt = sbus_ioremap(&sdev->resource[8], 0, | 395 | all->par.bt = of_ioremap(&op->resource[8], 0, |
390 | sizeof(struct bt_regs), "tcx dac"); | 396 | sizeof(struct bt_regs), "tcx dac"); |
397 | all->info.screen_base = of_ioremap(&op->resource[0], 0, | ||
398 | all->par.fbsize, "tcx ram"); | ||
399 | if (!all->par.tec || !all->par.thc || | ||
400 | !all->par.bt || !all->info.screen_base) { | ||
401 | tcx_unmap_regs(all); | ||
402 | kfree(all); | ||
403 | return -ENOMEM; | ||
404 | } | ||
405 | |||
391 | memcpy(&all->par.mmap_map, &__tcx_mmap_map, sizeof(all->par.mmap_map)); | 406 | memcpy(&all->par.mmap_map, &__tcx_mmap_map, sizeof(all->par.mmap_map)); |
392 | if (!all->par.lowdepth) { | 407 | if (!all->par.lowdepth) { |
393 | all->par.cplane = sbus_ioremap(&sdev->resource[4], 0, | 408 | all->par.cplane = of_ioremap(&op->resource[4], 0, |
394 | all->par.fbsize * sizeof(u32), "tcx cplane"); | 409 | all->par.fbsize * sizeof(u32), |
410 | "tcx cplane"); | ||
411 | if (!all->par.cplane) { | ||
412 | tcx_unmap_regs(all); | ||
413 | kfree(all); | ||
414 | return -ENOMEM; | ||
415 | } | ||
395 | } else { | 416 | } else { |
396 | all->par.mmap_map[1].size = SBUS_MMAP_EMPTY; | 417 | all->par.mmap_map[1].size = SBUS_MMAP_EMPTY; |
397 | all->par.mmap_map[4].size = SBUS_MMAP_EMPTY; | 418 | all->par.mmap_map[4].size = SBUS_MMAP_EMPTY; |
@@ -400,6 +421,8 @@ static void tcx_init_one(struct sbus_dev *sdev) | |||
400 | } | 421 | } |
401 | 422 | ||
402 | all->par.physbase = 0; | 423 | all->par.physbase = 0; |
424 | all->par.which_io = op->resource[0].flags & IORESOURCE_BITS; | ||
425 | |||
403 | for (i = 0; i < TCX_MMAP_ENTRIES; i++) { | 426 | for (i = 0; i < TCX_MMAP_ENTRIES; i++) { |
404 | int j; | 427 | int j; |
405 | 428 | ||
@@ -416,18 +439,11 @@ static void tcx_init_one(struct sbus_dev *sdev) | |||
416 | j = i; | 439 | j = i; |
417 | break; | 440 | break; |
418 | }; | 441 | }; |
419 | all->par.mmap_map[i].poff = sdev->reg_addrs[j].phys_addr; | 442 | all->par.mmap_map[i].poff = op->resource[j].start; |
420 | } | 443 | } |
421 | 444 | ||
422 | all->info.flags = FBINFO_DEFAULT; | 445 | all->info.flags = FBINFO_DEFAULT; |
423 | all->info.fbops = &tcx_ops; | 446 | all->info.fbops = &tcx_ops; |
424 | #ifdef CONFIG_SPARC32 | ||
425 | all->info.screen_base = (char __iomem *) | ||
426 | prom_getintdefault(sdev->prom_node, "address", 0); | ||
427 | #endif | ||
428 | if (!all->info.screen_base) | ||
429 | all->info.screen_base = sbus_ioremap(&sdev->resource[0], 0, | ||
430 | all->par.fbsize, "tcx ram"); | ||
431 | all->info.par = &all->par; | 447 | all->info.par = &all->par; |
432 | 448 | ||
433 | /* Initialize brooktree DAC. */ | 449 | /* Initialize brooktree DAC. */ |
@@ -445,72 +461,88 @@ static void tcx_init_one(struct sbus_dev *sdev) | |||
445 | tcx_blank(FB_BLANK_UNBLANK, &all->info); | 461 | tcx_blank(FB_BLANK_UNBLANK, &all->info); |
446 | 462 | ||
447 | if (fb_alloc_cmap(&all->info.cmap, 256, 0)) { | 463 | if (fb_alloc_cmap(&all->info.cmap, 256, 0)) { |
448 | printk(KERN_ERR "tcx: Could not allocate color map.\n"); | 464 | tcx_unmap_regs(all); |
449 | kfree(all); | 465 | kfree(all); |
450 | return; | 466 | return -ENOMEM; |
451 | } | 467 | } |
452 | 468 | ||
453 | fb_set_cmap(&all->info.cmap, &all->info); | 469 | fb_set_cmap(&all->info.cmap, &all->info); |
454 | tcx_init_fix(&all->info, linebytes); | 470 | tcx_init_fix(&all->info, linebytes); |
455 | 471 | ||
456 | if (register_framebuffer(&all->info) < 0) { | 472 | err = register_framebuffer(&all->info); |
457 | printk(KERN_ERR "tcx: Could not register framebuffer.\n"); | 473 | if (err < 0) { |
458 | fb_dealloc_cmap(&all->info.cmap); | 474 | fb_dealloc_cmap(&all->info.cmap); |
475 | tcx_unmap_regs(all); | ||
459 | kfree(all); | 476 | kfree(all); |
460 | return; | 477 | return err; |
461 | } | 478 | } |
462 | 479 | ||
463 | list_add(&all->list, &tcx_list); | 480 | dev_set_drvdata(&op->dev, all); |
464 | 481 | ||
465 | printk("tcx: %s at %lx:%lx, %s\n", | 482 | printk("%s: TCX at %lx:%lx, %s\n", |
466 | sdev->prom_name, | 483 | dp->full_name, |
467 | (long) sdev->reg_addrs[0].which_io, | 484 | all->par.which_io, |
468 | (long) sdev->reg_addrs[0].phys_addr, | 485 | op->resource[0].start, |
469 | all->par.lowdepth ? "8-bit only" : "24-bit depth"); | 486 | all->par.lowdepth ? "8-bit only" : "24-bit depth"); |
487 | |||
488 | return 0; | ||
470 | } | 489 | } |
471 | 490 | ||
472 | int __init tcx_init(void) | 491 | static int __devinit tcx_probe(struct of_device *dev, const struct of_device_id *match) |
473 | { | 492 | { |
474 | struct sbus_bus *sbus; | 493 | struct of_device *op = to_of_device(&dev->dev); |
475 | struct sbus_dev *sdev; | ||
476 | 494 | ||
477 | if (fb_get_options("tcxfb", NULL)) | 495 | return tcx_init_one(op); |
478 | return -ENODEV; | 496 | } |
479 | 497 | ||
480 | for_all_sbusdev(sdev, sbus) { | 498 | static int __devexit tcx_remove(struct of_device *dev) |
481 | if (!strcmp(sdev->prom_name, "SUNW,tcx")) | 499 | { |
482 | tcx_init_one(sdev); | 500 | struct all_info *all = dev_get_drvdata(&dev->dev); |
483 | } | 501 | |
502 | unregister_framebuffer(&all->info); | ||
503 | fb_dealloc_cmap(&all->info.cmap); | ||
504 | |||
505 | tcx_unmap_regs(all); | ||
506 | |||
507 | kfree(all); | ||
508 | |||
509 | dev_set_drvdata(&dev->dev, NULL); | ||
484 | 510 | ||
485 | return 0; | 511 | return 0; |
486 | } | 512 | } |
487 | 513 | ||
488 | void __exit tcx_exit(void) | 514 | static struct of_device_id tcx_match[] = { |
489 | { | 515 | { |
490 | struct list_head *pos, *tmp; | 516 | .name = "SUNW,tcx", |
517 | }, | ||
518 | {}, | ||
519 | }; | ||
520 | MODULE_DEVICE_TABLE(of, tcx_match); | ||
491 | 521 | ||
492 | list_for_each_safe(pos, tmp, &tcx_list) { | 522 | static struct of_platform_driver tcx_driver = { |
493 | struct all_info *all = list_entry(pos, typeof(*all), list); | 523 | .name = "tcx", |
524 | .match_table = tcx_match, | ||
525 | .probe = tcx_probe, | ||
526 | .remove = __devexit_p(tcx_remove), | ||
527 | }; | ||
494 | 528 | ||
495 | unregister_framebuffer(&all->info); | 529 | int __init tcx_init(void) |
496 | fb_dealloc_cmap(&all->info.cmap); | 530 | { |
497 | kfree(all); | 531 | if (fb_get_options("tcxfb", NULL)) |
498 | } | 532 | return -ENODEV; |
533 | |||
534 | return of_register_driver(&tcx_driver, &of_bus_type); | ||
499 | } | 535 | } |
500 | 536 | ||
501 | int __init | 537 | void __exit tcx_exit(void) |
502 | tcx_setup(char *arg) | ||
503 | { | 538 | { |
504 | /* No cmdline options yet... */ | 539 | of_unregister_driver(&tcx_driver); |
505 | return 0; | ||
506 | } | 540 | } |
507 | 541 | ||
508 | module_init(tcx_init); | 542 | module_init(tcx_init); |
509 | |||
510 | #ifdef MODULE | ||
511 | module_exit(tcx_exit); | 543 | module_exit(tcx_exit); |
512 | #endif | ||
513 | 544 | ||
514 | MODULE_DESCRIPTION("framebuffer driver for TCX chipsets"); | 545 | MODULE_DESCRIPTION("framebuffer driver for TCX chipsets"); |
515 | MODULE_AUTHOR("David S. Miller <davem@redhat.com>"); | 546 | MODULE_AUTHOR("David S. Miller <davem@davemloft.net>"); |
547 | MODULE_VERSION("2.0"); | ||
516 | MODULE_LICENSE("GPL"); | 548 | MODULE_LICENSE("GPL"); |