Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/video/q40fb.c -- Q40 frame buffer device |
| 3 | * |
| 4 | * Copyright (C) 2001 |
| 5 | * |
| 6 | * Richard Zidlicky <rz@linux-m68k.org> |
| 7 | * |
| 8 | * This file is subject to the terms and conditions of the GNU General Public |
| 9 | * License. See the file COPYING in the main directory of this archive for |
| 10 | * more details. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/errno.h> |
| 15 | #include <linux/string.h> |
| 16 | #include <linux/mm.h> |
| 17 | #include <linux/tty.h> |
| 18 | #include <linux/slab.h> |
| 19 | #include <linux/delay.h> |
| 20 | #include <linux/interrupt.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame^] | 21 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
| 23 | #include <asm/uaccess.h> |
| 24 | #include <asm/setup.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <asm/system.h> |
| 26 | #include <asm/q40_master.h> |
| 27 | #include <linux/fb.h> |
| 28 | #include <linux/module.h> |
| 29 | #include <asm/pgtable.h> |
| 30 | |
| 31 | #define Q40_PHYS_SCREEN_ADDR 0xFE800000 |
| 32 | |
| 33 | static struct fb_fix_screeninfo q40fb_fix __initdata = { |
| 34 | .id = "Q40", |
| 35 | .smem_len = 1024*1024, |
| 36 | .type = FB_TYPE_PACKED_PIXELS, |
| 37 | .visual = FB_VISUAL_TRUECOLOR, |
| 38 | .line_length = 1024*2, |
| 39 | .accel = FB_ACCEL_NONE, |
| 40 | }; |
| 41 | |
| 42 | static struct fb_var_screeninfo q40fb_var __initdata = { |
| 43 | .xres = 1024, |
| 44 | .yres = 512, |
| 45 | .xres_virtual = 1024, |
| 46 | .yres_virtual = 512, |
| 47 | .bits_per_pixel = 16, |
| 48 | .red = {6, 5, 0}, |
| 49 | .green = {11, 5, 0}, |
| 50 | .blue = {0, 6, 0}, |
| 51 | .activate = FB_ACTIVATE_NOW, |
| 52 | .height = 230, |
| 53 | .width = 300, |
| 54 | .vmode = FB_VMODE_NONINTERLACED, |
| 55 | }; |
| 56 | |
| 57 | static int q40fb_setcolreg(unsigned regno, unsigned red, unsigned green, |
| 58 | unsigned blue, unsigned transp, |
| 59 | struct fb_info *info) |
| 60 | { |
| 61 | /* |
| 62 | * Set a single color register. The values supplied have a 16 bit |
| 63 | * magnitude. |
| 64 | * Return != 0 for invalid regno. |
| 65 | */ |
| 66 | |
| 67 | if (regno > 255) |
| 68 | return 1; |
| 69 | red>>=11; |
| 70 | green>>=11; |
| 71 | blue>>=10; |
| 72 | |
| 73 | if (regno < 16) { |
| 74 | ((u32 *)info->pseudo_palette)[regno] = ((red & 31) <<6) | |
| 75 | ((green & 31) << 11) | |
| 76 | (blue & 63); |
| 77 | } |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | static struct fb_ops q40fb_ops = { |
| 82 | .owner = THIS_MODULE, |
| 83 | .fb_setcolreg = q40fb_setcolreg, |
| 84 | .fb_fillrect = cfb_fillrect, |
| 85 | .fb_copyarea = cfb_copyarea, |
| 86 | .fb_imageblit = cfb_imageblit, |
| 87 | .fb_cursor = soft_cursor, |
| 88 | }; |
| 89 | |
| 90 | static int __init q40fb_probe(struct device *device) |
| 91 | { |
| 92 | struct platform_device *dev = to_platform_device(device); |
| 93 | struct fb_info *info; |
| 94 | |
| 95 | if (!MACH_IS_Q40) |
| 96 | return -ENXIO; |
| 97 | |
| 98 | /* mapped in q40/config.c */ |
| 99 | q40fb_fix.smem_start = Q40_PHYS_SCREEN_ADDR; |
| 100 | |
| 101 | info = framebuffer_alloc(sizeof(u32) * 256, &dev->dev); |
| 102 | if (!info) |
| 103 | return -ENOMEM; |
| 104 | |
| 105 | info->var = q40fb_var; |
| 106 | info->fix = q40fb_fix; |
| 107 | info->fbops = &q40fb_ops; |
| 108 | info->flags = FBINFO_DEFAULT; /* not as module for now */ |
| 109 | info->pseudo_palette = info->par; |
| 110 | info->par = NULL; |
| 111 | info->screen_base = (char *) q40fb_fix.smem_start; |
| 112 | |
| 113 | if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) { |
| 114 | framebuffer_release(info); |
| 115 | return -ENOMEM; |
| 116 | } |
| 117 | |
| 118 | master_outb(3, DISPLAY_CONTROL_REG); |
| 119 | |
| 120 | if (register_framebuffer(info) < 0) { |
| 121 | printk(KERN_ERR "Unable to register Q40 frame buffer\n"); |
| 122 | fb_dealloc_cmap(&info->cmap); |
| 123 | framebuffer_release(info); |
| 124 | return -EINVAL; |
| 125 | } |
| 126 | |
| 127 | printk(KERN_INFO "fb%d: Q40 frame buffer alive and kicking !\n", |
| 128 | info->node); |
| 129 | return 0; |
| 130 | } |
| 131 | |
| 132 | static struct device_driver q40fb_driver = { |
| 133 | .name = "q40fb", |
| 134 | .bus = &platform_bus_type, |
| 135 | .probe = q40fb_probe, |
| 136 | }; |
| 137 | |
| 138 | static struct platform_device q40fb_device = { |
| 139 | .name = "q40fb", |
| 140 | }; |
| 141 | |
| 142 | int __init q40fb_init(void) |
| 143 | { |
| 144 | int ret = 0; |
| 145 | |
| 146 | if (fb_get_options("q40fb", NULL)) |
| 147 | return -ENODEV; |
| 148 | |
| 149 | ret = driver_register(&q40fb_driver); |
| 150 | |
| 151 | if (!ret) { |
| 152 | ret = platform_device_register(&q40fb_device); |
| 153 | if (ret) |
| 154 | driver_unregister(&q40fb_driver); |
| 155 | } |
| 156 | return ret; |
| 157 | } |
| 158 | |
| 159 | module_init(q40fb_init); |
| 160 | MODULE_LICENSE("GPL"); |