blob: 264d37243fadfde02a2952839d77cdd53697cb1f [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.
Maciej W. Rozycki335dc502007-02-05 16:28:28 -080018 * Copyright (c) 2005, 2006 Maciej W. Rozycki
19 * Copyright (c) 2005 James Simmons
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 *
Ralf Baechleaf690a92005-09-03 15:56:09 -070021 * This file is subject to the terms and conditions of the GNU General
22 * Public License. See the file COPYING in the main directory of this
23 * archive for more details.
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 */
Ralf Baechleaf690a92005-09-03 15:56:09 -070025
26#include <linux/compiler.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/errno.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/fb.h>
Ralf Baechleaf690a92005-09-03 15:56:09 -070029#include <linux/init.h>
30#include <linux/kernel.h>
31#include <linux/module.h>
Maciej W. Rozycki335dc502007-02-05 16:28:28 -080032#include <linux/tc.h>
Ralf Baechleaf690a92005-09-03 15:56:09 -070033#include <linux/types.h>
34
Ralf Baechleaf690a92005-09-03 15:56:09 -070035#include <asm/io.h>
36#include <asm/system.h>
37
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 {
Ralf Baechleaf690a92005-09-03 15:56:09 -070042 volatile void __iomem *mmio;
43 volatile u32 __iomem *dac;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044};
45
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Ralf Baechleaf690a92005-09-03 15:56:09 -070047static struct fb_var_screeninfo pmagbafb_defined __initdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 .xres = 1024,
49 .yres = 864,
50 .xres_virtual = 1024,
51 .yres_virtual = 864,
52 .bits_per_pixel = 8,
53 .red.length = 8,
54 .green.length = 8,
55 .blue.length = 8,
56 .activate = FB_ACTIVATE_NOW,
Ralf Baechleaf690a92005-09-03 15:56:09 -070057 .height = -1,
58 .width = -1,
59 .accel_flags = FB_ACCEL_NONE,
60 .pixclock = 14452,
61 .left_margin = 116,
62 .right_margin = 12,
63 .upper_margin = 34,
64 .lower_margin = 12,
65 .hsync_len = 128,
66 .vsync_len = 3,
67 .sync = FB_SYNC_ON_GREEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 .vmode = FB_VMODE_NONINTERLACED,
69};
70
Ralf Baechleaf690a92005-09-03 15:56:09 -070071static struct fb_fix_screeninfo pmagbafb_fix __initdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 .id = "PMAG-BA",
Ralf Baechleaf690a92005-09-03 15:56:09 -070073 .smem_len = (1024 * 1024),
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 .type = FB_TYPE_PACKED_PIXELS,
75 .visual = FB_VISUAL_PSEUDOCOLOR,
76 .line_length = 1024,
Ralf Baechleaf690a92005-09-03 15:56:09 -070077 .mmio_len = PMAG_BA_SIZE - PMAG_BA_BT459,
Linus Torvalds1da177e2005-04-16 15:20:36 -070078};
79
Ralf Baechleaf690a92005-09-03 15:56:09 -070080
81static inline void dac_write(struct pmagbafb_par *par, unsigned int reg, u8 v)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082{
Ralf Baechleaf690a92005-09-03 15:56:09 -070083 writeb(v, par->dac + reg / 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084}
85
Ralf Baechleaf690a92005-09-03 15:56:09 -070086static inline u8 dac_read(struct pmagbafb_par *par, unsigned int reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087{
Ralf Baechleaf690a92005-09-03 15:56:09 -070088 return readb(par->dac + reg / 4);
89}
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Ralf Baechleaf690a92005-09-03 15:56:09 -070091
92/*
93 * Set the palette.
94 */
95static int pmagbafb_setcolreg(unsigned int regno, unsigned int red,
96 unsigned int green, unsigned int blue,
97 unsigned int transp, struct fb_info *info)
98{
99 struct pmagbafb_par *par = info->par;
100
101 BUG_ON(regno >= info->cmap.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
103 red >>= 8; /* The cmap fields are 16 bits */
Ralf Baechleaf690a92005-09-03 15:56:09 -0700104 green >>= 8; /* wide, but the hardware colormap */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 blue >>= 8; /* registers are only 8 bits wide */
106
Ralf Baechleaf690a92005-09-03 15:56:09 -0700107 mb();
108 dac_write(par, BT459_ADDR_LO, regno);
109 dac_write(par, BT459_ADDR_HI, 0x00);
110 wmb();
111 dac_write(par, BT459_CMAP, red);
112 wmb();
113 dac_write(par, BT459_CMAP, green);
114 wmb();
115 dac_write(par, BT459_CMAP, blue);
116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 return 0;
118}
119
120static struct fb_ops pmagbafb_ops = {
121 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 .fb_setcolreg = pmagbafb_setcolreg,
123 .fb_fillrect = cfb_fillrect,
124 .fb_copyarea = cfb_copyarea,
125 .fb_imageblit = cfb_imageblit,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126};
127
Ralf Baechleaf690a92005-09-03 15:56:09 -0700128
129/*
130 * Turn the hardware cursor off.
131 */
132static void __init pmagbafb_erase_cursor(struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133{
Ralf Baechleaf690a92005-09-03 15:56:09 -0700134 struct pmagbafb_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
Ralf Baechleaf690a92005-09-03 15:56:09 -0700136 mb();
137 dac_write(par, BT459_ADDR_LO, 0x00);
138 dac_write(par, BT459_ADDR_HI, 0x03);
139 wmb();
140 dac_write(par, BT459_DATA, 0x00);
141}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800144static int __init pmagbafb_probe(struct device *dev)
Ralf Baechleaf690a92005-09-03 15:56:09 -0700145{
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800146 struct tc_dev *tdev = to_tc_dev(dev);
147 resource_size_t start, len;
Ralf Baechleaf690a92005-09-03 15:56:09 -0700148 struct fb_info *info;
149 struct pmagbafb_par *par;
Ralf Baechleaf690a92005-09-03 15:56:09 -0700150
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800151 info = framebuffer_alloc(sizeof(struct pmagbafb_par), dev);
Ralf Baechleaf690a92005-09-03 15:56:09 -0700152 if (!info)
153 return -ENOMEM;
154
155 par = info->par;
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800156 dev_set_drvdata(dev, info);
Ralf Baechleaf690a92005-09-03 15:56:09 -0700157
158 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0)
159 goto err_alloc;
160
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 info->fbops = &pmagbafb_ops;
Ralf Baechleaf690a92005-09-03 15:56:09 -0700162 info->fix = pmagbafb_fix;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 info->var = pmagbafb_defined;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 info->flags = FBINFO_DEFAULT;
165
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800166 /* Request the I/O MEM resource. */
167 start = tdev->resource.start;
168 len = tdev->resource.end - start + 1;
169 if (!request_mem_region(start, len, dev->bus_id))
170 goto err_cmap;
171
Ralf Baechleaf690a92005-09-03 15:56:09 -0700172 /* MMIO mapping setup. */
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800173 info->fix.mmio_start = start;
Ralf Baechleaf690a92005-09-03 15:56:09 -0700174 par->mmio = ioremap_nocache(info->fix.mmio_start, info->fix.mmio_len);
175 if (!par->mmio)
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800176 goto err_resource;
Ralf Baechleaf690a92005-09-03 15:56:09 -0700177 par->dac = par->mmio + PMAG_BA_BT459;
178
179 /* Frame buffer mapping setup. */
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800180 info->fix.smem_start = start + PMAG_BA_FBMEM;
Ralf Baechleaf690a92005-09-03 15:56:09 -0700181 info->screen_base = ioremap_nocache(info->fix.smem_start,
182 info->fix.smem_len);
183 if (!info->screen_base)
184 goto err_mmio_map;
185 info->screen_size = info->fix.smem_len;
186
187 pmagbafb_erase_cursor(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
189 if (register_framebuffer(info) < 0)
Ralf Baechleaf690a92005-09-03 15:56:09 -0700190 goto err_smem_map;
191
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800192 get_device(dev);
193
194 pr_info("fb%d: %s frame buffer device at %s\n",
195 info->node, info->fix.id, dev->bus_id);
Ralf Baechleaf690a92005-09-03 15:56:09 -0700196
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 return 0;
Ralf Baechleaf690a92005-09-03 15:56:09 -0700198
199
200err_smem_map:
201 iounmap(info->screen_base);
202
203err_mmio_map:
204 iounmap(par->mmio);
205
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800206err_resource:
207 release_mem_region(start, len);
208
Ralf Baechleaf690a92005-09-03 15:56:09 -0700209err_cmap:
210 fb_dealloc_cmap(&info->cmap);
211
212err_alloc:
Ralf Baechleaf690a92005-09-03 15:56:09 -0700213 framebuffer_release(info);
214 return -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215}
216
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800217static int __exit pmagbafb_remove(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218{
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800219 struct tc_dev *tdev = to_tc_dev(dev);
220 struct fb_info *info = dev_get_drvdata(dev);
Ralf Baechleaf690a92005-09-03 15:56:09 -0700221 struct pmagbafb_par *par = info->par;
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800222 resource_size_t start, len;
Ralf Baechleaf690a92005-09-03 15:56:09 -0700223
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800224 put_device(dev);
Ralf Baechleaf690a92005-09-03 15:56:09 -0700225 unregister_framebuffer(info);
226 iounmap(info->screen_base);
227 iounmap(par->mmio);
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800228 start = tdev->resource.start;
229 len = tdev->resource.end - start + 1;
230 release_mem_region(start, len);
Ralf Baechleaf690a92005-09-03 15:56:09 -0700231 fb_dealloc_cmap(&info->cmap);
Ralf Baechleaf690a92005-09-03 15:56:09 -0700232 framebuffer_release(info);
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800233 return 0;
Ralf Baechleaf690a92005-09-03 15:56:09 -0700234}
235
236
237/*
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800238 * Initialize the framebuffer.
Ralf Baechleaf690a92005-09-03 15:56:09 -0700239 */
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800240static const struct tc_device_id pmagbafb_tc_table[] = {
241 { "DEC ", "PMAG-BA " },
242 { }
243};
244MODULE_DEVICE_TABLE(tc, pmagbafb_tc_table);
245
246static struct tc_driver pmagbafb_driver = {
247 .id_table = pmagbafb_tc_table,
248 .driver = {
249 .name = "pmagbafb",
250 .bus = &tc_bus_type,
251 .probe = pmagbafb_probe,
252 .remove = __exit_p(pmagbafb_remove),
253 },
254};
255
Ralf Baechleaf690a92005-09-03 15:56:09 -0700256static int __init pmagbafb_init(void)
257{
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800258#ifndef MODULE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 if (fb_get_options("pmagbafb", NULL))
Ralf Baechleaf690a92005-09-03 15:56:09 -0700260 return -ENXIO;
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800261#endif
262 return tc_register_driver(&pmagbafb_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263}
264
Ralf Baechleaf690a92005-09-03 15:56:09 -0700265static void __exit pmagbafb_exit(void)
266{
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800267 tc_unregister_driver(&pmagbafb_driver);
Ralf Baechleaf690a92005-09-03 15:56:09 -0700268}
269
270
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271module_init(pmagbafb_init);
Ralf Baechleaf690a92005-09-03 15:56:09 -0700272module_exit(pmagbafb_exit);
273
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274MODULE_LICENSE("GPL");