blob: 0f361b6100d2b6dc671c1ff1297718e2e47735fc [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
Krzysztof Helt2f390382009-12-15 16:46:25 -0800101 if (regno >= info->cmap.len)
102 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
104 red >>= 8; /* The cmap fields are 16 bits */
Ralf Baechleaf690a92005-09-03 15:56:09 -0700105 green >>= 8; /* wide, but the hardware colormap */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 blue >>= 8; /* registers are only 8 bits wide */
107
Ralf Baechleaf690a92005-09-03 15:56:09 -0700108 mb();
109 dac_write(par, BT459_ADDR_LO, regno);
110 dac_write(par, BT459_ADDR_HI, 0x00);
111 wmb();
112 dac_write(par, BT459_CMAP, red);
113 wmb();
114 dac_write(par, BT459_CMAP, green);
115 wmb();
116 dac_write(par, BT459_CMAP, blue);
117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 return 0;
119}
120
121static struct fb_ops pmagbafb_ops = {
122 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 .fb_setcolreg = pmagbafb_setcolreg,
124 .fb_fillrect = cfb_fillrect,
125 .fb_copyarea = cfb_copyarea,
126 .fb_imageblit = cfb_imageblit,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127};
128
Ralf Baechleaf690a92005-09-03 15:56:09 -0700129
130/*
131 * Turn the hardware cursor off.
132 */
133static void __init pmagbafb_erase_cursor(struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134{
Ralf Baechleaf690a92005-09-03 15:56:09 -0700135 struct pmagbafb_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Ralf Baechleaf690a92005-09-03 15:56:09 -0700137 mb();
138 dac_write(par, BT459_ADDR_LO, 0x00);
139 dac_write(par, BT459_ADDR_HI, 0x03);
140 wmb();
141 dac_write(par, BT459_DATA, 0x00);
142}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800145static int __init pmagbafb_probe(struct device *dev)
Ralf Baechleaf690a92005-09-03 15:56:09 -0700146{
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800147 struct tc_dev *tdev = to_tc_dev(dev);
148 resource_size_t start, len;
Ralf Baechleaf690a92005-09-03 15:56:09 -0700149 struct fb_info *info;
150 struct pmagbafb_par *par;
Maciej W. Rozycki53ee1b52007-10-16 01:29:30 -0700151 int err;
Ralf Baechleaf690a92005-09-03 15:56:09 -0700152
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800153 info = framebuffer_alloc(sizeof(struct pmagbafb_par), dev);
Maciej W. Rozycki53ee1b52007-10-16 01:29:30 -0700154 if (!info) {
Kay Sievers7ad33e72009-03-24 16:38:21 -0700155 printk(KERN_ERR "%s: Cannot allocate memory\n", dev_name(dev));
Ralf Baechleaf690a92005-09-03 15:56:09 -0700156 return -ENOMEM;
Maciej W. Rozycki53ee1b52007-10-16 01:29:30 -0700157 }
Ralf Baechleaf690a92005-09-03 15:56:09 -0700158
159 par = info->par;
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800160 dev_set_drvdata(dev, info);
Ralf Baechleaf690a92005-09-03 15:56:09 -0700161
Maciej W. Rozycki53ee1b52007-10-16 01:29:30 -0700162 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
163 printk(KERN_ERR "%s: Cannot allocate color map\n",
Kay Sievers7ad33e72009-03-24 16:38:21 -0700164 dev_name(dev));
Maciej W. Rozycki53ee1b52007-10-16 01:29:30 -0700165 err = -ENOMEM;
Ralf Baechleaf690a92005-09-03 15:56:09 -0700166 goto err_alloc;
Maciej W. Rozycki53ee1b52007-10-16 01:29:30 -0700167 }
Ralf Baechleaf690a92005-09-03 15:56:09 -0700168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 info->fbops = &pmagbafb_ops;
Ralf Baechleaf690a92005-09-03 15:56:09 -0700170 info->fix = pmagbafb_fix;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 info->var = pmagbafb_defined;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 info->flags = FBINFO_DEFAULT;
173
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800174 /* Request the I/O MEM resource. */
175 start = tdev->resource.start;
176 len = tdev->resource.end - start + 1;
Kay Sievers7ad33e72009-03-24 16:38:21 -0700177 if (!request_mem_region(start, len, dev_name(dev))) {
178 printk(KERN_ERR "%s: Cannot reserve FB region\n",
179 dev_name(dev));
Maciej W. Rozycki53ee1b52007-10-16 01:29:30 -0700180 err = -EBUSY;
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800181 goto err_cmap;
Maciej W. Rozycki53ee1b52007-10-16 01:29:30 -0700182 }
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800183
Ralf Baechleaf690a92005-09-03 15:56:09 -0700184 /* MMIO mapping setup. */
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800185 info->fix.mmio_start = start;
Ralf Baechleaf690a92005-09-03 15:56:09 -0700186 par->mmio = ioremap_nocache(info->fix.mmio_start, info->fix.mmio_len);
Maciej W. Rozycki53ee1b52007-10-16 01:29:30 -0700187 if (!par->mmio) {
Kay Sievers7ad33e72009-03-24 16:38:21 -0700188 printk(KERN_ERR "%s: Cannot map MMIO\n", dev_name(dev));
Maciej W. Rozycki53ee1b52007-10-16 01:29:30 -0700189 err = -ENOMEM;
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800190 goto err_resource;
Maciej W. Rozycki53ee1b52007-10-16 01:29:30 -0700191 }
Ralf Baechleaf690a92005-09-03 15:56:09 -0700192 par->dac = par->mmio + PMAG_BA_BT459;
193
194 /* Frame buffer mapping setup. */
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800195 info->fix.smem_start = start + PMAG_BA_FBMEM;
Ralf Baechleaf690a92005-09-03 15:56:09 -0700196 info->screen_base = ioremap_nocache(info->fix.smem_start,
197 info->fix.smem_len);
Maciej W. Rozycki53ee1b52007-10-16 01:29:30 -0700198 if (!info->screen_base) {
Kay Sievers7ad33e72009-03-24 16:38:21 -0700199 printk(KERN_ERR "%s: Cannot map FB\n", dev_name(dev));
Maciej W. Rozycki53ee1b52007-10-16 01:29:30 -0700200 err = -ENOMEM;
Ralf Baechleaf690a92005-09-03 15:56:09 -0700201 goto err_mmio_map;
Maciej W. Rozycki53ee1b52007-10-16 01:29:30 -0700202 }
Ralf Baechleaf690a92005-09-03 15:56:09 -0700203 info->screen_size = info->fix.smem_len;
204
205 pmagbafb_erase_cursor(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Maciej W. Rozycki53ee1b52007-10-16 01:29:30 -0700207 err = register_framebuffer(info);
208 if (err < 0) {
209 printk(KERN_ERR "%s: Cannot register framebuffer\n",
Kay Sievers7ad33e72009-03-24 16:38:21 -0700210 dev_name(dev));
Ralf Baechleaf690a92005-09-03 15:56:09 -0700211 goto err_smem_map;
Maciej W. Rozycki53ee1b52007-10-16 01:29:30 -0700212 }
Ralf Baechleaf690a92005-09-03 15:56:09 -0700213
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800214 get_device(dev);
215
216 pr_info("fb%d: %s frame buffer device at %s\n",
Kay Sievers7ad33e72009-03-24 16:38:21 -0700217 info->node, info->fix.id, dev_name(dev));
Ralf Baechleaf690a92005-09-03 15:56:09 -0700218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 return 0;
Ralf Baechleaf690a92005-09-03 15:56:09 -0700220
221
222err_smem_map:
223 iounmap(info->screen_base);
224
225err_mmio_map:
226 iounmap(par->mmio);
227
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800228err_resource:
229 release_mem_region(start, len);
230
Ralf Baechleaf690a92005-09-03 15:56:09 -0700231err_cmap:
232 fb_dealloc_cmap(&info->cmap);
233
234err_alloc:
Ralf Baechleaf690a92005-09-03 15:56:09 -0700235 framebuffer_release(info);
Maciej W. Rozycki53ee1b52007-10-16 01:29:30 -0700236 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237}
238
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800239static int __exit pmagbafb_remove(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240{
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800241 struct tc_dev *tdev = to_tc_dev(dev);
242 struct fb_info *info = dev_get_drvdata(dev);
Ralf Baechleaf690a92005-09-03 15:56:09 -0700243 struct pmagbafb_par *par = info->par;
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800244 resource_size_t start, len;
Ralf Baechleaf690a92005-09-03 15:56:09 -0700245
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800246 put_device(dev);
Ralf Baechleaf690a92005-09-03 15:56:09 -0700247 unregister_framebuffer(info);
248 iounmap(info->screen_base);
249 iounmap(par->mmio);
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800250 start = tdev->resource.start;
251 len = tdev->resource.end - start + 1;
252 release_mem_region(start, len);
Ralf Baechleaf690a92005-09-03 15:56:09 -0700253 fb_dealloc_cmap(&info->cmap);
Ralf Baechleaf690a92005-09-03 15:56:09 -0700254 framebuffer_release(info);
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800255 return 0;
Ralf Baechleaf690a92005-09-03 15:56:09 -0700256}
257
258
259/*
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800260 * Initialize the framebuffer.
Ralf Baechleaf690a92005-09-03 15:56:09 -0700261 */
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800262static const struct tc_device_id pmagbafb_tc_table[] = {
263 { "DEC ", "PMAG-BA " },
264 { }
265};
266MODULE_DEVICE_TABLE(tc, pmagbafb_tc_table);
267
268static struct tc_driver pmagbafb_driver = {
269 .id_table = pmagbafb_tc_table,
270 .driver = {
271 .name = "pmagbafb",
272 .bus = &tc_bus_type,
273 .probe = pmagbafb_probe,
274 .remove = __exit_p(pmagbafb_remove),
275 },
276};
277
Ralf Baechleaf690a92005-09-03 15:56:09 -0700278static int __init pmagbafb_init(void)
279{
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800280#ifndef MODULE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 if (fb_get_options("pmagbafb", NULL))
Ralf Baechleaf690a92005-09-03 15:56:09 -0700282 return -ENXIO;
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800283#endif
284 return tc_register_driver(&pmagbafb_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285}
286
Ralf Baechleaf690a92005-09-03 15:56:09 -0700287static void __exit pmagbafb_exit(void)
288{
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800289 tc_unregister_driver(&pmagbafb_driver);
Ralf Baechleaf690a92005-09-03 15:56:09 -0700290}
291
292
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293module_init(pmagbafb_init);
Ralf Baechleaf690a92005-09-03 15:56:09 -0700294module_exit(pmagbafb_exit);
295
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296MODULE_LICENSE("GPL");