blob: f5361cd8ccce1359cd706d0e081a873b77235955 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Ralf Baechleaf690a92005-09-03 15:56:09 -07002 * linux/drivers/video/pmag-ba-fb.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Ralf Baechleaf690a92005-09-03 15:56:09 -07004 * PMAG-BA TURBOchannel Color Frame Buffer (CFB) card support,
5 * derived from:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * "HP300 Topcat framebuffer support (derived from macfb of all things)
7 * Phil Blundell <philb@gnu.org> 1998", the original code can be
Ralf Baechleaf690a92005-09-03 15:56:09 -07008 * found in the file hpfb.c in the same directory.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 *
10 * Based on digital document:
11 * "PMAG-BA TURBOchannel Color Frame Buffer
12 * Functional Specification", Revision 1.2, August 27, 1990
13 *
Ralf Baechleaf690a92005-09-03 15:56:09 -070014 * DECstation related code Copyright (C) 1999, 2000, 2001 by
15 * Michael Engel <engel@unix-ag.org>,
16 * Karsten Merker <merker@linuxtag.org> and
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 * Harald Koerfgen.
Ralf Baechleaf690a92005-09-03 15:56:09 -070018 * Copyright (c) 2005 Maciej W. Rozycki
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 *
Ralf Baechleaf690a92005-09-03 15:56:09 -070020 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 */
Ralf Baechleaf690a92005-09-03 15:56:09 -070024
25#include <linux/compiler.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/errno.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/fb.h>
Ralf Baechleaf690a92005-09-03 15:56:09 -070028#include <linux/init.h>
29#include <linux/kernel.h>
30#include <linux/module.h>
31#include <linux/types.h>
32
Ralf Baechleaf690a92005-09-03 15:56:09 -070033#include <asm/io.h>
34#include <asm/system.h>
35
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <asm/dec/tc.h>
Ralf Baechleaf690a92005-09-03 15:56:09 -070037
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <video/pmag-ba-fb.h>
39
Ralf Baechleaf690a92005-09-03 15:56:09 -070040
41struct pmagbafb_par {
42 struct fb_info *next;
43 volatile void __iomem *mmio;
44 volatile u32 __iomem *dac;
45 int slot;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046};
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Ralf Baechleaf690a92005-09-03 15:56:09 -070049static struct fb_info *root_pmagbafb_dev;
50
51static struct fb_var_screeninfo pmagbafb_defined __initdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 .xres = 1024,
53 .yres = 864,
54 .xres_virtual = 1024,
55 .yres_virtual = 864,
56 .bits_per_pixel = 8,
57 .red.length = 8,
58 .green.length = 8,
59 .blue.length = 8,
60 .activate = FB_ACTIVATE_NOW,
Ralf Baechleaf690a92005-09-03 15:56:09 -070061 .height = -1,
62 .width = -1,
63 .accel_flags = FB_ACCEL_NONE,
64 .pixclock = 14452,
65 .left_margin = 116,
66 .right_margin = 12,
67 .upper_margin = 34,
68 .lower_margin = 12,
69 .hsync_len = 128,
70 .vsync_len = 3,
71 .sync = FB_SYNC_ON_GREEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 .vmode = FB_VMODE_NONINTERLACED,
73};
74
Ralf Baechleaf690a92005-09-03 15:56:09 -070075static struct fb_fix_screeninfo pmagbafb_fix __initdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 .id = "PMAG-BA",
Ralf Baechleaf690a92005-09-03 15:56:09 -070077 .smem_len = (1024 * 1024),
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 .type = FB_TYPE_PACKED_PIXELS,
79 .visual = FB_VISUAL_PSEUDOCOLOR,
80 .line_length = 1024,
Ralf Baechleaf690a92005-09-03 15:56:09 -070081 .mmio_len = PMAG_BA_SIZE - PMAG_BA_BT459,
Linus Torvalds1da177e2005-04-16 15:20:36 -070082};
83
Ralf Baechleaf690a92005-09-03 15:56:09 -070084
85static inline void dac_write(struct pmagbafb_par *par, unsigned int reg, u8 v)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086{
Ralf Baechleaf690a92005-09-03 15:56:09 -070087 writeb(v, par->dac + reg / 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088}
89
Ralf Baechleaf690a92005-09-03 15:56:09 -070090static inline u8 dac_read(struct pmagbafb_par *par, unsigned int reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091{
Ralf Baechleaf690a92005-09-03 15:56:09 -070092 return readb(par->dac + reg / 4);
93}
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Ralf Baechleaf690a92005-09-03 15:56:09 -070095
96/*
97 * Set the palette.
98 */
99static int pmagbafb_setcolreg(unsigned int regno, unsigned int red,
100 unsigned int green, unsigned int blue,
101 unsigned int transp, struct fb_info *info)
102{
103 struct pmagbafb_par *par = info->par;
104
105 BUG_ON(regno >= info->cmap.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
107 red >>= 8; /* The cmap fields are 16 bits */
Ralf Baechleaf690a92005-09-03 15:56:09 -0700108 green >>= 8; /* wide, but the hardware colormap */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 blue >>= 8; /* registers are only 8 bits wide */
110
Ralf Baechleaf690a92005-09-03 15:56:09 -0700111 mb();
112 dac_write(par, BT459_ADDR_LO, regno);
113 dac_write(par, BT459_ADDR_HI, 0x00);
114 wmb();
115 dac_write(par, BT459_CMAP, red);
116 wmb();
117 dac_write(par, BT459_CMAP, green);
118 wmb();
119 dac_write(par, BT459_CMAP, blue);
120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 return 0;
122}
123
124static struct fb_ops pmagbafb_ops = {
125 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 .fb_setcolreg = pmagbafb_setcolreg,
127 .fb_fillrect = cfb_fillrect,
128 .fb_copyarea = cfb_copyarea,
129 .fb_imageblit = cfb_imageblit,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130};
131
Ralf Baechleaf690a92005-09-03 15:56:09 -0700132
133/*
134 * Turn the hardware cursor off.
135 */
136static void __init pmagbafb_erase_cursor(struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137{
Ralf Baechleaf690a92005-09-03 15:56:09 -0700138 struct pmagbafb_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Ralf Baechleaf690a92005-09-03 15:56:09 -0700140 mb();
141 dac_write(par, BT459_ADDR_LO, 0x00);
142 dac_write(par, BT459_ADDR_HI, 0x03);
143 wmb();
144 dac_write(par, BT459_DATA, 0x00);
145}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Ralf Baechleaf690a92005-09-03 15:56:09 -0700148static int __init pmagbafb_init_one(int slot)
149{
150 struct fb_info *info;
151 struct pmagbafb_par *par;
152 unsigned long base_addr;
153
154 info = framebuffer_alloc(sizeof(struct pmagbafb_par), NULL);
155 if (!info)
156 return -ENOMEM;
157
158 par = info->par;
159 par->slot = slot;
160 claim_tc_card(par->slot);
161
162 base_addr = get_tc_base_addr(par->slot);
163
164 par->next = root_pmagbafb_dev;
165 root_pmagbafb_dev = info;
166
167 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0)
168 goto err_alloc;
169
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 info->fbops = &pmagbafb_ops;
Ralf Baechleaf690a92005-09-03 15:56:09 -0700171 info->fix = pmagbafb_fix;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 info->var = pmagbafb_defined;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 info->flags = FBINFO_DEFAULT;
174
Ralf Baechleaf690a92005-09-03 15:56:09 -0700175 /* MMIO mapping setup. */
176 info->fix.mmio_start = base_addr;
177 par->mmio = ioremap_nocache(info->fix.mmio_start, info->fix.mmio_len);
178 if (!par->mmio)
179 goto err_cmap;
180 par->dac = par->mmio + PMAG_BA_BT459;
181
182 /* Frame buffer mapping setup. */
183 info->fix.smem_start = base_addr + PMAG_BA_FBMEM;
184 info->screen_base = ioremap_nocache(info->fix.smem_start,
185 info->fix.smem_len);
186 if (!info->screen_base)
187 goto err_mmio_map;
188 info->screen_size = info->fix.smem_len;
189
190 pmagbafb_erase_cursor(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
192 if (register_framebuffer(info) < 0)
Ralf Baechleaf690a92005-09-03 15:56:09 -0700193 goto err_smem_map;
194
195 pr_info("fb%d: %s frame buffer device in slot %d\n",
196 info->node, info->fix.id, par->slot);
197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 return 0;
Ralf Baechleaf690a92005-09-03 15:56:09 -0700199
200
201err_smem_map:
202 iounmap(info->screen_base);
203
204err_mmio_map:
205 iounmap(par->mmio);
206
207err_cmap:
208 fb_dealloc_cmap(&info->cmap);
209
210err_alloc:
211 root_pmagbafb_dev = par->next;
212 release_tc_card(par->slot);
213 framebuffer_release(info);
214 return -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215}
216
Ralf Baechleaf690a92005-09-03 15:56:09 -0700217static void __exit pmagbafb_exit_one(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218{
Ralf Baechleaf690a92005-09-03 15:56:09 -0700219 struct fb_info *info = root_pmagbafb_dev;
220 struct pmagbafb_par *par = info->par;
221
222 unregister_framebuffer(info);
223 iounmap(info->screen_base);
224 iounmap(par->mmio);
225 fb_dealloc_cmap(&info->cmap);
226 root_pmagbafb_dev = par->next;
227 release_tc_card(par->slot);
228 framebuffer_release(info);
229}
230
231
232/*
233 * Initialise the framebuffer.
234 */
235static int __init pmagbafb_init(void)
236{
237 int count = 0;
238 int slot;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
240 if (fb_get_options("pmagbafb", NULL))
Ralf Baechleaf690a92005-09-03 15:56:09 -0700241 return -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
Ralf Baechleaf690a92005-09-03 15:56:09 -0700243 while ((slot = search_tc_card("PMAG-BA")) >= 0) {
244 if (pmagbafb_init_one(slot) < 0)
245 break;
246 count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 }
Ralf Baechleaf690a92005-09-03 15:56:09 -0700248 return (count > 0) ? 0 : -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249}
250
Ralf Baechleaf690a92005-09-03 15:56:09 -0700251static void __exit pmagbafb_exit(void)
252{
253 while (root_pmagbafb_dev)
254 pmagbafb_exit_one();
255}
256
257
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258module_init(pmagbafb_init);
Ralf Baechleaf690a92005-09-03 15:56:09 -0700259module_exit(pmagbafb_exit);
260
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261MODULE_LICENSE("GPL");