[PATCH] DEC PMAG BA frame buffer update
[deliverable/linux.git] / drivers / video / pmag-ba-fb.c
CommitLineData
1da177e4 1/*
af690a94 2 * linux/drivers/video/pmag-ba-fb.c
1da177e4 3 *
af690a94
RB
4 * PMAG-BA TURBOchannel Color Frame Buffer (CFB) card support,
5 * derived from:
1da177e4
LT
6 * "HP300 Topcat framebuffer support (derived from macfb of all things)
7 * Phil Blundell <philb@gnu.org> 1998", the original code can be
af690a94 8 * found in the file hpfb.c in the same directory.
1da177e4
LT
9 *
10 * Based on digital document:
11 * "PMAG-BA TURBOchannel Color Frame Buffer
12 * Functional Specification", Revision 1.2, August 27, 1990
13 *
af690a94
RB
14 * DECstation related code Copyright (C) 1999, 2000, 2001 by
15 * Michael Engel <engel@unix-ag.org>,
16 * Karsten Merker <merker@linuxtag.org> and
1da177e4 17 * Harald Koerfgen.
af690a94 18 * Copyright (c) 2005 Maciej W. Rozycki
1da177e4 19 *
af690a94
RB
20 * This file is subject to the terms and conditions of the GNU General
21 * Public License. See the file COPYING in the main directory of this
22 * archive for more details.
1da177e4 23 */
af690a94
RB
24
25#include <linux/compiler.h>
1da177e4 26#include <linux/errno.h>
1da177e4 27#include <linux/fb.h>
af690a94
RB
28#include <linux/init.h>
29#include <linux/kernel.h>
30#include <linux/module.h>
31#include <linux/types.h>
32
33#include <asm/bug.h>
34#include <asm/io.h>
35#include <asm/system.h>
36
1da177e4 37#include <asm/dec/tc.h>
af690a94 38
1da177e4
LT
39#include <video/pmag-ba-fb.h>
40
af690a94
RB
41
42struct pmagbafb_par {
43 struct fb_info *next;
44 volatile void __iomem *mmio;
45 volatile u32 __iomem *dac;
46 int slot;
1da177e4
LT
47};
48
1da177e4 49
af690a94
RB
50static struct fb_info *root_pmagbafb_dev;
51
52static struct fb_var_screeninfo pmagbafb_defined __initdata = {
1da177e4
LT
53 .xres = 1024,
54 .yres = 864,
55 .xres_virtual = 1024,
56 .yres_virtual = 864,
57 .bits_per_pixel = 8,
58 .red.length = 8,
59 .green.length = 8,
60 .blue.length = 8,
61 .activate = FB_ACTIVATE_NOW,
af690a94
RB
62 .height = -1,
63 .width = -1,
64 .accel_flags = FB_ACCEL_NONE,
65 .pixclock = 14452,
66 .left_margin = 116,
67 .right_margin = 12,
68 .upper_margin = 34,
69 .lower_margin = 12,
70 .hsync_len = 128,
71 .vsync_len = 3,
72 .sync = FB_SYNC_ON_GREEN,
1da177e4
LT
73 .vmode = FB_VMODE_NONINTERLACED,
74};
75
af690a94 76static struct fb_fix_screeninfo pmagbafb_fix __initdata = {
1da177e4 77 .id = "PMAG-BA",
af690a94 78 .smem_len = (1024 * 1024),
1da177e4
LT
79 .type = FB_TYPE_PACKED_PIXELS,
80 .visual = FB_VISUAL_PSEUDOCOLOR,
81 .line_length = 1024,
af690a94 82 .mmio_len = PMAG_BA_SIZE - PMAG_BA_BT459,
1da177e4
LT
83};
84
af690a94
RB
85
86static inline void dac_write(struct pmagbafb_par *par, unsigned int reg, u8 v)
1da177e4 87{
af690a94 88 writeb(v, par->dac + reg / 4);
1da177e4
LT
89}
90
af690a94
RB
91static inline u8 dac_read(struct pmagbafb_par *par, unsigned int reg)
92{
93 return readb(par->dac + reg / 4);
94}
95
96
1da177e4 97/*
af690a94 98 * Set the palette.
1da177e4 99 */
af690a94
RB
100static int pmagbafb_setcolreg(unsigned int regno, unsigned int red,
101 unsigned int green, unsigned int blue,
102 unsigned int transp, struct fb_info *info)
1da177e4 103{
af690a94 104 struct pmagbafb_par *par = info->par;
1da177e4 105
af690a94 106 BUG_ON(regno >= info->cmap.len);
1da177e4
LT
107
108 red >>= 8; /* The cmap fields are 16 bits */
af690a94 109 green >>= 8; /* wide, but the hardware colormap */
1da177e4
LT
110 blue >>= 8; /* registers are only 8 bits wide */
111
af690a94
RB
112 mb();
113 dac_write(par, BT459_ADDR_LO, regno);
114 dac_write(par, BT459_ADDR_HI, 0x00);
115 wmb();
116 dac_write(par, BT459_CMAP, red);
117 wmb();
118 dac_write(par, BT459_CMAP, green);
119 wmb();
120 dac_write(par, BT459_CMAP, blue);
121
1da177e4
LT
122 return 0;
123}
124
125static struct fb_ops pmagbafb_ops = {
126 .owner = THIS_MODULE,
1da177e4
LT
127 .fb_setcolreg = pmagbafb_setcolreg,
128 .fb_fillrect = cfb_fillrect,
129 .fb_copyarea = cfb_copyarea,
130 .fb_imageblit = cfb_imageblit,
131 .fb_cursor = soft_cursor,
132};
133
af690a94
RB
134
135/*
136 * Turn the hardware cursor off.
137 */
138static void __init pmagbafb_erase_cursor(struct fb_info *info)
139{
140 struct pmagbafb_par *par = info->par;
141
142 mb();
143 dac_write(par, BT459_ADDR_LO, 0x00);
144 dac_write(par, BT459_ADDR_HI, 0x03);
145 wmb();
146 dac_write(par, BT459_DATA, 0x00);
147}
148
149
150static int __init pmagbafb_init_one(int slot)
1da177e4 151{
af690a94
RB
152 struct fb_info *info;
153 struct pmagbafb_par *par;
154 unsigned long base_addr;
155
156 info = framebuffer_alloc(sizeof(struct pmagbafb_par), NULL);
157 if (!info)
158 return -ENOMEM;
159
160 par = info->par;
161 par->slot = slot;
162 claim_tc_card(par->slot);
163
164 base_addr = get_tc_base_addr(par->slot);
165
166 par->next = root_pmagbafb_dev;
167 root_pmagbafb_dev = info;
168
169 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0)
170 goto err_alloc;
171
1da177e4 172 info->fbops = &pmagbafb_ops;
af690a94 173 info->fix = pmagbafb_fix;
1da177e4 174 info->var = pmagbafb_defined;
1da177e4
LT
175 info->flags = FBINFO_DEFAULT;
176
af690a94
RB
177 /* MMIO mapping setup. */
178 info->fix.mmio_start = base_addr;
179 par->mmio = ioremap_nocache(info->fix.mmio_start, info->fix.mmio_len);
180 if (!par->mmio)
181 goto err_cmap;
182 par->dac = par->mmio + PMAG_BA_BT459;
183
184 /* Frame buffer mapping setup. */
185 info->fix.smem_start = base_addr + PMAG_BA_FBMEM;
186 info->screen_base = ioremap_nocache(info->fix.smem_start,
187 info->fix.smem_len);
188 if (!info->screen_base)
189 goto err_mmio_map;
190 info->screen_size = info->fix.smem_len;
191
192 pmagbafb_erase_cursor(info);
1da177e4
LT
193
194 if (register_framebuffer(info) < 0)
af690a94
RB
195 goto err_smem_map;
196
197 pr_info("fb%d: %s frame buffer device in slot %d\n",
198 info->node, info->fix.id, par->slot);
199
1da177e4 200 return 0;
af690a94
RB
201
202
203err_smem_map:
204 iounmap(info->screen_base);
205
206err_mmio_map:
207 iounmap(par->mmio);
208
209err_cmap:
210 fb_dealloc_cmap(&info->cmap);
211
212err_alloc:
213 root_pmagbafb_dev = par->next;
214 release_tc_card(par->slot);
215 framebuffer_release(info);
216 return -ENXIO;
1da177e4
LT
217}
218
af690a94
RB
219static void __exit pmagbafb_exit_one(void)
220{
221 struct fb_info *info = root_pmagbafb_dev;
222 struct pmagbafb_par *par = info->par;
1da177e4 223
af690a94
RB
224 unregister_framebuffer(info);
225 iounmap(info->screen_base);
226 iounmap(par->mmio);
227 fb_dealloc_cmap(&info->cmap);
228 root_pmagbafb_dev = par->next;
229 release_tc_card(par->slot);
230 framebuffer_release(info);
231}
232
233
234/*
235 * Initialise the framebuffer.
236 */
237static int __init pmagbafb_init(void)
1da177e4 238{
af690a94
RB
239 int count = 0;
240 int slot;
1da177e4
LT
241
242 if (fb_get_options("pmagbafb", NULL))
af690a94
RB
243 return -ENXIO;
244
245 while ((slot = search_tc_card("PMAG-BA")) >= 0) {
246 if (pmagbafb_init_one(slot) < 0)
247 break;
248 count++;
1da177e4 249 }
af690a94 250 return (count > 0) ? 0 : -ENXIO;
1da177e4
LT
251}
252
af690a94
RB
253static void __exit pmagbafb_exit(void)
254{
255 while (root_pmagbafb_dev)
256 pmagbafb_exit_one();
257}
258
259
1da177e4 260module_init(pmagbafb_init);
af690a94
RB
261module_exit(pmagbafb_exit);
262
1da177e4 263MODULE_LICENSE("GPL");
This page took 0.06088 seconds and 5 git commands to generate.