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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/delay.h> |
| 18 | #include <linux/interrupt.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 19 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
| 21 | #include <asm/uaccess.h> |
| 22 | #include <asm/setup.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <asm/q40_master.h> |
| 24 | #include <linux/fb.h> |
| 25 | #include <linux/module.h> |
| 26 | #include <asm/pgtable.h> |
| 27 | |
| 28 | #define Q40_PHYS_SCREEN_ADDR 0xFE800000 |
| 29 | |
Henrik Kretzschmar | 0c37dd7c | 2010-08-20 19:13:24 +0200 | [diff] [blame] | 30 | static struct fb_fix_screeninfo q40fb_fix __devinitdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | .id = "Q40", |
| 32 | .smem_len = 1024*1024, |
| 33 | .type = FB_TYPE_PACKED_PIXELS, |
| 34 | .visual = FB_VISUAL_TRUECOLOR, |
| 35 | .line_length = 1024*2, |
| 36 | .accel = FB_ACCEL_NONE, |
| 37 | }; |
| 38 | |
Henrik Kretzschmar | 0c37dd7c | 2010-08-20 19:13:24 +0200 | [diff] [blame] | 39 | static struct fb_var_screeninfo q40fb_var __devinitdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | .xres = 1024, |
| 41 | .yres = 512, |
| 42 | .xres_virtual = 1024, |
| 43 | .yres_virtual = 512, |
| 44 | .bits_per_pixel = 16, |
| 45 | .red = {6, 5, 0}, |
| 46 | .green = {11, 5, 0}, |
| 47 | .blue = {0, 6, 0}, |
| 48 | .activate = FB_ACTIVATE_NOW, |
| 49 | .height = 230, |
| 50 | .width = 300, |
| 51 | .vmode = FB_VMODE_NONINTERLACED, |
| 52 | }; |
| 53 | |
| 54 | static int q40fb_setcolreg(unsigned regno, unsigned red, unsigned green, |
| 55 | unsigned blue, unsigned transp, |
| 56 | struct fb_info *info) |
| 57 | { |
| 58 | /* |
| 59 | * Set a single color register. The values supplied have a 16 bit |
| 60 | * magnitude. |
| 61 | * Return != 0 for invalid regno. |
| 62 | */ |
| 63 | |
| 64 | if (regno > 255) |
| 65 | return 1; |
| 66 | red>>=11; |
| 67 | green>>=11; |
| 68 | blue>>=10; |
| 69 | |
| 70 | if (regno < 16) { |
| 71 | ((u32 *)info->pseudo_palette)[regno] = ((red & 31) <<6) | |
| 72 | ((green & 31) << 11) | |
| 73 | (blue & 63); |
| 74 | } |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | static struct fb_ops q40fb_ops = { |
| 79 | .owner = THIS_MODULE, |
| 80 | .fb_setcolreg = q40fb_setcolreg, |
| 81 | .fb_fillrect = cfb_fillrect, |
| 82 | .fb_copyarea = cfb_copyarea, |
| 83 | .fb_imageblit = cfb_imageblit, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | }; |
| 85 | |
Uwe Kleine-König | c2e1303 | 2010-02-04 20:56:51 +0100 | [diff] [blame] | 86 | static int __devinit q40fb_probe(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | struct fb_info *info; |
| 89 | |
| 90 | if (!MACH_IS_Q40) |
| 91 | return -ENXIO; |
| 92 | |
| 93 | /* mapped in q40/config.c */ |
| 94 | q40fb_fix.smem_start = Q40_PHYS_SCREEN_ADDR; |
| 95 | |
Antonino A. Daplas | ce303c0 | 2007-07-17 04:05:40 -0700 | [diff] [blame] | 96 | info = framebuffer_alloc(sizeof(u32) * 16, &dev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | if (!info) |
| 98 | return -ENOMEM; |
| 99 | |
| 100 | info->var = q40fb_var; |
| 101 | info->fix = q40fb_fix; |
| 102 | info->fbops = &q40fb_ops; |
| 103 | info->flags = FBINFO_DEFAULT; /* not as module for now */ |
| 104 | info->pseudo_palette = info->par; |
| 105 | info->par = NULL; |
| 106 | info->screen_base = (char *) q40fb_fix.smem_start; |
| 107 | |
| 108 | if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) { |
| 109 | framebuffer_release(info); |
| 110 | return -ENOMEM; |
| 111 | } |
| 112 | |
| 113 | master_outb(3, DISPLAY_CONTROL_REG); |
| 114 | |
| 115 | if (register_framebuffer(info) < 0) { |
| 116 | printk(KERN_ERR "Unable to register Q40 frame buffer\n"); |
| 117 | fb_dealloc_cmap(&info->cmap); |
| 118 | framebuffer_release(info); |
| 119 | return -EINVAL; |
| 120 | } |
| 121 | |
| 122 | printk(KERN_INFO "fb%d: Q40 frame buffer alive and kicking !\n", |
| 123 | info->node); |
| 124 | return 0; |
| 125 | } |
| 126 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 127 | static struct platform_driver q40fb_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | .probe = q40fb_probe, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 129 | .driver = { |
| 130 | .name = "q40fb", |
| 131 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | static struct platform_device q40fb_device = { |
| 135 | .name = "q40fb", |
| 136 | }; |
| 137 | |
| 138 | int __init q40fb_init(void) |
| 139 | { |
| 140 | int ret = 0; |
| 141 | |
| 142 | if (fb_get_options("q40fb", NULL)) |
| 143 | return -ENODEV; |
| 144 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 145 | ret = platform_driver_register(&q40fb_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | |
| 147 | if (!ret) { |
| 148 | ret = platform_device_register(&q40fb_device); |
| 149 | if (ret) |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 150 | platform_driver_unregister(&q40fb_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | } |
| 152 | return ret; |
| 153 | } |
| 154 | |
| 155 | module_init(q40fb_init); |
| 156 | MODULE_LICENSE("GPL"); |