blob: 1296f9b370c2e50c29fee335b3d5a00758ae311a [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>
Ralf Baechleaf690a92005-09-03 15:56:09 -070036
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <video/pmag-ba-fb.h>
38
Ralf Baechleaf690a92005-09-03 15:56:09 -070039
40struct pmagbafb_par {
Ralf Baechleaf690a92005-09-03 15:56:09 -070041 volatile void __iomem *mmio;
42 volatile u32 __iomem *dac;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043};
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Bhumika Goyala7582732017-09-04 16:00:50 +020046static const struct fb_var_screeninfo pmagbafb_defined = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 .xres = 1024,
48 .yres = 864,
49 .xres_virtual = 1024,
50 .yres_virtual = 864,
51 .bits_per_pixel = 8,
52 .red.length = 8,
53 .green.length = 8,
54 .blue.length = 8,
55 .activate = FB_ACTIVATE_NOW,
Ralf Baechleaf690a92005-09-03 15:56:09 -070056 .height = -1,
57 .width = -1,
58 .accel_flags = FB_ACCEL_NONE,
59 .pixclock = 14452,
60 .left_margin = 116,
61 .right_margin = 12,
62 .upper_margin = 34,
Maciej W. Rozyckiaf22f642016-02-22 01:54:46 +000063 .lower_margin = 0,
Ralf Baechleaf690a92005-09-03 15:56:09 -070064 .hsync_len = 128,
65 .vsync_len = 3,
66 .sync = FB_SYNC_ON_GREEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 .vmode = FB_VMODE_NONINTERLACED,
68};
69
Bhumika Goyal799b88d2017-09-04 16:00:49 +020070static const struct fb_fix_screeninfo pmagbafb_fix = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 .id = "PMAG-BA",
Ralf Baechleaf690a92005-09-03 15:56:09 -070072 .smem_len = (1024 * 1024),
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 .type = FB_TYPE_PACKED_PIXELS,
74 .visual = FB_VISUAL_PSEUDOCOLOR,
75 .line_length = 1024,
Ralf Baechleaf690a92005-09-03 15:56:09 -070076 .mmio_len = PMAG_BA_SIZE - PMAG_BA_BT459,
Linus Torvalds1da177e2005-04-16 15:20:36 -070077};
78
Ralf Baechleaf690a92005-09-03 15:56:09 -070079
80static inline void dac_write(struct pmagbafb_par *par, unsigned int reg, u8 v)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081{
Ralf Baechleaf690a92005-09-03 15:56:09 -070082 writeb(v, par->dac + reg / 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083}
84
Ralf Baechleaf690a92005-09-03 15:56:09 -070085static inline u8 dac_read(struct pmagbafb_par *par, unsigned int reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086{
Ralf Baechleaf690a92005-09-03 15:56:09 -070087 return readb(par->dac + reg / 4);
88}
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Ralf Baechleaf690a92005-09-03 15:56:09 -070090
91/*
92 * Set the palette.
93 */
94static int pmagbafb_setcolreg(unsigned int regno, unsigned int red,
95 unsigned int green, unsigned int blue,
96 unsigned int transp, struct fb_info *info)
97{
98 struct pmagbafb_par *par = info->par;
99
Krzysztof Helt2f390382009-12-15 16:46:25 -0800100 if (regno >= info->cmap.len)
101 return 1;
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
Jani Nikula8a48ac332019-12-03 18:38:50 +0200120static const struct fb_ops pmagbafb_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 .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 */
Maciej W. Rozycki879e5a02017-01-30 17:39:48 +0100132static void 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
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800144static int 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;
Maciej W. Rozycki53ee1b52007-10-16 01:29:30 -0700150 int err;
Ralf Baechleaf690a92005-09-03 15:56:09 -0700151
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800152 info = framebuffer_alloc(sizeof(struct pmagbafb_par), dev);
Bartlomiej Zolnierkiewicz0adcdbc2019-06-28 12:30:08 +0200153 if (!info)
Ralf Baechleaf690a92005-09-03 15:56:09 -0700154 return -ENOMEM;
155
156 par = info->par;
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800157 dev_set_drvdata(dev, info);
Ralf Baechleaf690a92005-09-03 15:56:09 -0700158
Maciej W. Rozycki53ee1b52007-10-16 01:29:30 -0700159 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
160 printk(KERN_ERR "%s: Cannot allocate color map\n",
Kay Sievers7ad33e72009-03-24 16:38:21 -0700161 dev_name(dev));
Maciej W. Rozycki53ee1b52007-10-16 01:29:30 -0700162 err = -ENOMEM;
Ralf Baechleaf690a92005-09-03 15:56:09 -0700163 goto err_alloc;
Maciej W. Rozycki53ee1b52007-10-16 01:29:30 -0700164 }
Ralf Baechleaf690a92005-09-03 15:56:09 -0700165
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 info->fbops = &pmagbafb_ops;
Ralf Baechleaf690a92005-09-03 15:56:09 -0700167 info->fix = pmagbafb_fix;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 info->var = pmagbafb_defined;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 info->flags = FBINFO_DEFAULT;
170
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800171 /* Request the I/O MEM resource. */
172 start = tdev->resource.start;
173 len = tdev->resource.end - start + 1;
Kay Sievers7ad33e72009-03-24 16:38:21 -0700174 if (!request_mem_region(start, len, dev_name(dev))) {
175 printk(KERN_ERR "%s: Cannot reserve FB region\n",
176 dev_name(dev));
Maciej W. Rozycki53ee1b52007-10-16 01:29:30 -0700177 err = -EBUSY;
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800178 goto err_cmap;
Maciej W. Rozycki53ee1b52007-10-16 01:29:30 -0700179 }
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800180
Ralf Baechleaf690a92005-09-03 15:56:09 -0700181 /* MMIO mapping setup. */
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800182 info->fix.mmio_start = start;
Christoph Hellwig4bdc0d62020-01-06 09:43:50 +0100183 par->mmio = ioremap(info->fix.mmio_start, info->fix.mmio_len);
Maciej W. Rozycki53ee1b52007-10-16 01:29:30 -0700184 if (!par->mmio) {
Kay Sievers7ad33e72009-03-24 16:38:21 -0700185 printk(KERN_ERR "%s: Cannot map MMIO\n", dev_name(dev));
Maciej W. Rozycki53ee1b52007-10-16 01:29:30 -0700186 err = -ENOMEM;
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800187 goto err_resource;
Maciej W. Rozycki53ee1b52007-10-16 01:29:30 -0700188 }
Ralf Baechleaf690a92005-09-03 15:56:09 -0700189 par->dac = par->mmio + PMAG_BA_BT459;
190
191 /* Frame buffer mapping setup. */
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800192 info->fix.smem_start = start + PMAG_BA_FBMEM;
Christoph Hellwig4bdc0d62020-01-06 09:43:50 +0100193 info->screen_base = ioremap(info->fix.smem_start,
Ralf Baechleaf690a92005-09-03 15:56:09 -0700194 info->fix.smem_len);
Maciej W. Rozycki53ee1b52007-10-16 01:29:30 -0700195 if (!info->screen_base) {
Kay Sievers7ad33e72009-03-24 16:38:21 -0700196 printk(KERN_ERR "%s: Cannot map FB\n", dev_name(dev));
Maciej W. Rozycki53ee1b52007-10-16 01:29:30 -0700197 err = -ENOMEM;
Ralf Baechleaf690a92005-09-03 15:56:09 -0700198 goto err_mmio_map;
Maciej W. Rozycki53ee1b52007-10-16 01:29:30 -0700199 }
Ralf Baechleaf690a92005-09-03 15:56:09 -0700200 info->screen_size = info->fix.smem_len;
201
202 pmagbafb_erase_cursor(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
Maciej W. Rozycki53ee1b52007-10-16 01:29:30 -0700204 err = register_framebuffer(info);
205 if (err < 0) {
206 printk(KERN_ERR "%s: Cannot register framebuffer\n",
Kay Sievers7ad33e72009-03-24 16:38:21 -0700207 dev_name(dev));
Ralf Baechleaf690a92005-09-03 15:56:09 -0700208 goto err_smem_map;
Maciej W. Rozycki53ee1b52007-10-16 01:29:30 -0700209 }
Ralf Baechleaf690a92005-09-03 15:56:09 -0700210
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800211 get_device(dev);
212
Joe Perches31b67802013-09-19 18:35:55 -0700213 fb_info(info, "%s frame buffer device at %s\n",
214 info->fix.id, dev_name(dev));
Ralf Baechleaf690a92005-09-03 15:56:09 -0700215
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 return 0;
Ralf Baechleaf690a92005-09-03 15:56:09 -0700217
218
219err_smem_map:
220 iounmap(info->screen_base);
221
222err_mmio_map:
223 iounmap(par->mmio);
224
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800225err_resource:
226 release_mem_region(start, len);
227
Ralf Baechleaf690a92005-09-03 15:56:09 -0700228err_cmap:
229 fb_dealloc_cmap(&info->cmap);
230
231err_alloc:
Ralf Baechleaf690a92005-09-03 15:56:09 -0700232 framebuffer_release(info);
Maciej W. Rozycki53ee1b52007-10-16 01:29:30 -0700233 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234}
235
Dmitry Torokhov982711c2017-03-20 18:30:59 +0100236static int pmagbafb_remove(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237{
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800238 struct tc_dev *tdev = to_tc_dev(dev);
239 struct fb_info *info = dev_get_drvdata(dev);
Ralf Baechleaf690a92005-09-03 15:56:09 -0700240 struct pmagbafb_par *par = info->par;
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800241 resource_size_t start, len;
Ralf Baechleaf690a92005-09-03 15:56:09 -0700242
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800243 put_device(dev);
Ralf Baechleaf690a92005-09-03 15:56:09 -0700244 unregister_framebuffer(info);
245 iounmap(info->screen_base);
246 iounmap(par->mmio);
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800247 start = tdev->resource.start;
248 len = tdev->resource.end - start + 1;
249 release_mem_region(start, len);
Ralf Baechleaf690a92005-09-03 15:56:09 -0700250 fb_dealloc_cmap(&info->cmap);
Ralf Baechleaf690a92005-09-03 15:56:09 -0700251 framebuffer_release(info);
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800252 return 0;
Ralf Baechleaf690a92005-09-03 15:56:09 -0700253}
254
255
256/*
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800257 * Initialize the framebuffer.
Ralf Baechleaf690a92005-09-03 15:56:09 -0700258 */
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800259static const struct tc_device_id pmagbafb_tc_table[] = {
260 { "DEC ", "PMAG-BA " },
261 { }
262};
263MODULE_DEVICE_TABLE(tc, pmagbafb_tc_table);
264
265static struct tc_driver pmagbafb_driver = {
266 .id_table = pmagbafb_tc_table,
267 .driver = {
268 .name = "pmagbafb",
269 .bus = &tc_bus_type,
270 .probe = pmagbafb_probe,
Dmitry Torokhov982711c2017-03-20 18:30:59 +0100271 .remove = pmagbafb_remove,
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800272 },
273};
274
Ralf Baechleaf690a92005-09-03 15:56:09 -0700275static int __init pmagbafb_init(void)
276{
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800277#ifndef MODULE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 if (fb_get_options("pmagbafb", NULL))
Ralf Baechleaf690a92005-09-03 15:56:09 -0700279 return -ENXIO;
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800280#endif
281 return tc_register_driver(&pmagbafb_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282}
283
Ralf Baechleaf690a92005-09-03 15:56:09 -0700284static void __exit pmagbafb_exit(void)
285{
Maciej W. Rozycki335dc502007-02-05 16:28:28 -0800286 tc_unregister_driver(&pmagbafb_driver);
Ralf Baechleaf690a92005-09-03 15:56:09 -0700287}
288
289
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290module_init(pmagbafb_init);
Ralf Baechleaf690a92005-09-03 15:56:09 -0700291module_exit(pmagbafb_exit);
292
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293MODULE_LICENSE("GPL");