blob: f3927b6cda9d4d7f6edc8c29a65be8249577e5fc [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
33#include <asm/bug.h>
34#include <asm/io.h>
35#include <asm/system.h>
36
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <asm/dec/tc.h>
Ralf Baechleaf690a92005-09-03 15:56:09 -070038
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <video/pmag-ba-fb.h>
40
Ralf Baechleaf690a92005-09-03 15:56:09 -070041
42struct pmagbafb_par {
43 struct fb_info *next;
44 volatile void __iomem *mmio;
45 volatile u32 __iomem *dac;
46 int slot;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047};
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Ralf Baechleaf690a92005-09-03 15:56:09 -070050static struct fb_info *root_pmagbafb_dev;
51
52static struct fb_var_screeninfo pmagbafb_defined __initdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 .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,
Ralf Baechleaf690a92005-09-03 15:56:09 -070062 .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,
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 .vmode = FB_VMODE_NONINTERLACED,
74};
75
Ralf Baechleaf690a92005-09-03 15:56:09 -070076static struct fb_fix_screeninfo pmagbafb_fix __initdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 .id = "PMAG-BA",
Ralf Baechleaf690a92005-09-03 15:56:09 -070078 .smem_len = (1024 * 1024),
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 .type = FB_TYPE_PACKED_PIXELS,
80 .visual = FB_VISUAL_PSEUDOCOLOR,
81 .line_length = 1024,
Ralf Baechleaf690a92005-09-03 15:56:09 -070082 .mmio_len = PMAG_BA_SIZE - PMAG_BA_BT459,
Linus Torvalds1da177e2005-04-16 15:20:36 -070083};
84
Ralf Baechleaf690a92005-09-03 15:56:09 -070085
86static inline void dac_write(struct pmagbafb_par *par, unsigned int reg, u8 v)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087{
Ralf Baechleaf690a92005-09-03 15:56:09 -070088 writeb(v, par->dac + reg / 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089}
90
Ralf Baechleaf690a92005-09-03 15:56:09 -070091static inline u8 dac_read(struct pmagbafb_par *par, unsigned int reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070092{
Ralf Baechleaf690a92005-09-03 15:56:09 -070093 return readb(par->dac + reg / 4);
94}
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
Ralf Baechleaf690a92005-09-03 15:56:09 -070096
97/*
98 * Set the palette.
99 */
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)
103{
104 struct pmagbafb_par *par = info->par;
105
106 BUG_ON(regno >= info->cmap.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108 red >>= 8; /* The cmap fields are 16 bits */
Ralf Baechleaf690a92005-09-03 15:56:09 -0700109 green >>= 8; /* wide, but the hardware colormap */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 blue >>= 8; /* registers are only 8 bits wide */
111
Ralf Baechleaf690a92005-09-03 15:56:09 -0700112 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 return 0;
123}
124
125static struct fb_ops pmagbafb_ops = {
126 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 .fb_setcolreg = pmagbafb_setcolreg,
128 .fb_fillrect = cfb_fillrect,
129 .fb_copyarea = cfb_copyarea,
130 .fb_imageblit = cfb_imageblit,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131};
132
Ralf Baechleaf690a92005-09-03 15:56:09 -0700133
134/*
135 * Turn the hardware cursor off.
136 */
137static void __init pmagbafb_erase_cursor(struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138{
Ralf Baechleaf690a92005-09-03 15:56:09 -0700139 struct pmagbafb_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
Ralf Baechleaf690a92005-09-03 15:56:09 -0700141 mb();
142 dac_write(par, BT459_ADDR_LO, 0x00);
143 dac_write(par, BT459_ADDR_HI, 0x03);
144 wmb();
145 dac_write(par, BT459_DATA, 0x00);
146}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Ralf Baechleaf690a92005-09-03 15:56:09 -0700149static int __init pmagbafb_init_one(int slot)
150{
151 struct fb_info *info;
152 struct pmagbafb_par *par;
153 unsigned long base_addr;
154
155 info = framebuffer_alloc(sizeof(struct pmagbafb_par), NULL);
156 if (!info)
157 return -ENOMEM;
158
159 par = info->par;
160 par->slot = slot;
161 claim_tc_card(par->slot);
162
163 base_addr = get_tc_base_addr(par->slot);
164
165 par->next = root_pmagbafb_dev;
166 root_pmagbafb_dev = info;
167
168 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0)
169 goto err_alloc;
170
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 info->fbops = &pmagbafb_ops;
Ralf Baechleaf690a92005-09-03 15:56:09 -0700172 info->fix = pmagbafb_fix;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 info->var = pmagbafb_defined;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 info->flags = FBINFO_DEFAULT;
175
Ralf Baechleaf690a92005-09-03 15:56:09 -0700176 /* MMIO mapping setup. */
177 info->fix.mmio_start = base_addr;
178 par->mmio = ioremap_nocache(info->fix.mmio_start, info->fix.mmio_len);
179 if (!par->mmio)
180 goto err_cmap;
181 par->dac = par->mmio + PMAG_BA_BT459;
182
183 /* Frame buffer mapping setup. */
184 info->fix.smem_start = base_addr + PMAG_BA_FBMEM;
185 info->screen_base = ioremap_nocache(info->fix.smem_start,
186 info->fix.smem_len);
187 if (!info->screen_base)
188 goto err_mmio_map;
189 info->screen_size = info->fix.smem_len;
190
191 pmagbafb_erase_cursor(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
193 if (register_framebuffer(info) < 0)
Ralf Baechleaf690a92005-09-03 15:56:09 -0700194 goto err_smem_map;
195
196 pr_info("fb%d: %s frame buffer device in slot %d\n",
197 info->node, info->fix.id, par->slot);
198
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 return 0;
Ralf Baechleaf690a92005-09-03 15:56:09 -0700200
201
202err_smem_map:
203 iounmap(info->screen_base);
204
205err_mmio_map:
206 iounmap(par->mmio);
207
208err_cmap:
209 fb_dealloc_cmap(&info->cmap);
210
211err_alloc:
212 root_pmagbafb_dev = par->next;
213 release_tc_card(par->slot);
214 framebuffer_release(info);
215 return -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216}
217
Ralf Baechleaf690a92005-09-03 15:56:09 -0700218static void __exit pmagbafb_exit_one(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219{
Ralf Baechleaf690a92005-09-03 15:56:09 -0700220 struct fb_info *info = root_pmagbafb_dev;
221 struct pmagbafb_par *par = info->par;
222
223 unregister_framebuffer(info);
224 iounmap(info->screen_base);
225 iounmap(par->mmio);
226 fb_dealloc_cmap(&info->cmap);
227 root_pmagbafb_dev = par->next;
228 release_tc_card(par->slot);
229 framebuffer_release(info);
230}
231
232
233/*
234 * Initialise the framebuffer.
235 */
236static int __init pmagbafb_init(void)
237{
238 int count = 0;
239 int slot;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
241 if (fb_get_options("pmagbafb", NULL))
Ralf Baechleaf690a92005-09-03 15:56:09 -0700242 return -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
Ralf Baechleaf690a92005-09-03 15:56:09 -0700244 while ((slot = search_tc_card("PMAG-BA")) >= 0) {
245 if (pmagbafb_init_one(slot) < 0)
246 break;
247 count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 }
Ralf Baechleaf690a92005-09-03 15:56:09 -0700249 return (count > 0) ? 0 : -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250}
251
Ralf Baechleaf690a92005-09-03 15:56:09 -0700252static void __exit pmagbafb_exit(void)
253{
254 while (root_pmagbafb_dev)
255 pmagbafb_exit_one();
256}
257
258
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259module_init(pmagbafb_init);
Ralf Baechleaf690a92005-09-03 15:56:09 -0700260module_exit(pmagbafb_exit);
261
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262MODULE_LICENSE("GPL");