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