Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / video / fbdev / pmag-ba-fb.c
blob1296f9b370c2e50c29fee335b3d5a00758ae311a
1 /*
2 * linux/drivers/video/pmag-ba-fb.c
4 * PMAG-BA TURBOchannel Color Frame Buffer (CFB) card support,
5 * derived from:
6 * "HP300 Topcat framebuffer support (derived from macfb of all things)
7 * Phil Blundell <philb@gnu.org> 1998", the original code can be
8 * found in the file hpfb.c in the same directory.
10 * Based on digital document:
11 * "PMAG-BA TURBOchannel Color Frame Buffer
12 * Functional Specification", Revision 1.2, August 27, 1990
14 * DECstation related code Copyright (C) 1999, 2000, 2001 by
15 * Michael Engel <engel@unix-ag.org>,
16 * Karsten Merker <merker@linuxtag.org> and
17 * Harald Koerfgen.
18 * Copyright (c) 2005, 2006 Maciej W. Rozycki
19 * Copyright (c) 2005 James Simmons
21 * 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.
26 #include <linux/compiler.h>
27 #include <linux/errno.h>
28 #include <linux/fb.h>
29 #include <linux/init.h>
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/tc.h>
33 #include <linux/types.h>
35 #include <asm/io.h>
37 #include <video/pmag-ba-fb.h>
40 struct pmagbafb_par {
41 volatile void __iomem *mmio;
42 volatile u32 __iomem *dac;
46 static const struct fb_var_screeninfo pmagbafb_defined = {
47 .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,
56 .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,
63 .lower_margin = 0,
64 .hsync_len = 128,
65 .vsync_len = 3,
66 .sync = FB_SYNC_ON_GREEN,
67 .vmode = FB_VMODE_NONINTERLACED,
70 static const struct fb_fix_screeninfo pmagbafb_fix = {
71 .id = "PMAG-BA",
72 .smem_len = (1024 * 1024),
73 .type = FB_TYPE_PACKED_PIXELS,
74 .visual = FB_VISUAL_PSEUDOCOLOR,
75 .line_length = 1024,
76 .mmio_len = PMAG_BA_SIZE - PMAG_BA_BT459,
80 static inline void dac_write(struct pmagbafb_par *par, unsigned int reg, u8 v)
82 writeb(v, par->dac + reg / 4);
85 static inline u8 dac_read(struct pmagbafb_par *par, unsigned int reg)
87 return readb(par->dac + reg / 4);
92 * Set the palette.
94 static int pmagbafb_setcolreg(unsigned int regno, unsigned int red,
95 unsigned int green, unsigned int blue,
96 unsigned int transp, struct fb_info *info)
98 struct pmagbafb_par *par = info->par;
100 if (regno >= info->cmap.len)
101 return 1;
103 red >>= 8; /* The cmap fields are 16 bits */
104 green >>= 8; /* wide, but the hardware colormap */
105 blue >>= 8; /* registers are only 8 bits wide */
107 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);
117 return 0;
120 static const struct fb_ops pmagbafb_ops = {
121 .owner = THIS_MODULE,
122 .fb_setcolreg = pmagbafb_setcolreg,
123 .fb_fillrect = cfb_fillrect,
124 .fb_copyarea = cfb_copyarea,
125 .fb_imageblit = cfb_imageblit,
130 * Turn the hardware cursor off.
132 static void pmagbafb_erase_cursor(struct fb_info *info)
134 struct pmagbafb_par *par = info->par;
136 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);
144 static int pmagbafb_probe(struct device *dev)
146 struct tc_dev *tdev = to_tc_dev(dev);
147 resource_size_t start, len;
148 struct fb_info *info;
149 struct pmagbafb_par *par;
150 int err;
152 info = framebuffer_alloc(sizeof(struct pmagbafb_par), dev);
153 if (!info)
154 return -ENOMEM;
156 par = info->par;
157 dev_set_drvdata(dev, info);
159 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
160 printk(KERN_ERR "%s: Cannot allocate color map\n",
161 dev_name(dev));
162 err = -ENOMEM;
163 goto err_alloc;
166 info->fbops = &pmagbafb_ops;
167 info->fix = pmagbafb_fix;
168 info->var = pmagbafb_defined;
169 info->flags = FBINFO_DEFAULT;
171 /* Request the I/O MEM resource. */
172 start = tdev->resource.start;
173 len = tdev->resource.end - start + 1;
174 if (!request_mem_region(start, len, dev_name(dev))) {
175 printk(KERN_ERR "%s: Cannot reserve FB region\n",
176 dev_name(dev));
177 err = -EBUSY;
178 goto err_cmap;
181 /* MMIO mapping setup. */
182 info->fix.mmio_start = start;
183 par->mmio = ioremap(info->fix.mmio_start, info->fix.mmio_len);
184 if (!par->mmio) {
185 printk(KERN_ERR "%s: Cannot map MMIO\n", dev_name(dev));
186 err = -ENOMEM;
187 goto err_resource;
189 par->dac = par->mmio + PMAG_BA_BT459;
191 /* Frame buffer mapping setup. */
192 info->fix.smem_start = start + PMAG_BA_FBMEM;
193 info->screen_base = ioremap(info->fix.smem_start,
194 info->fix.smem_len);
195 if (!info->screen_base) {
196 printk(KERN_ERR "%s: Cannot map FB\n", dev_name(dev));
197 err = -ENOMEM;
198 goto err_mmio_map;
200 info->screen_size = info->fix.smem_len;
202 pmagbafb_erase_cursor(info);
204 err = register_framebuffer(info);
205 if (err < 0) {
206 printk(KERN_ERR "%s: Cannot register framebuffer\n",
207 dev_name(dev));
208 goto err_smem_map;
211 get_device(dev);
213 fb_info(info, "%s frame buffer device at %s\n",
214 info->fix.id, dev_name(dev));
216 return 0;
219 err_smem_map:
220 iounmap(info->screen_base);
222 err_mmio_map:
223 iounmap(par->mmio);
225 err_resource:
226 release_mem_region(start, len);
228 err_cmap:
229 fb_dealloc_cmap(&info->cmap);
231 err_alloc:
232 framebuffer_release(info);
233 return err;
236 static int pmagbafb_remove(struct device *dev)
238 struct tc_dev *tdev = to_tc_dev(dev);
239 struct fb_info *info = dev_get_drvdata(dev);
240 struct pmagbafb_par *par = info->par;
241 resource_size_t start, len;
243 put_device(dev);
244 unregister_framebuffer(info);
245 iounmap(info->screen_base);
246 iounmap(par->mmio);
247 start = tdev->resource.start;
248 len = tdev->resource.end - start + 1;
249 release_mem_region(start, len);
250 fb_dealloc_cmap(&info->cmap);
251 framebuffer_release(info);
252 return 0;
257 * Initialize the framebuffer.
259 static const struct tc_device_id pmagbafb_tc_table[] = {
260 { "DEC ", "PMAG-BA " },
263 MODULE_DEVICE_TABLE(tc, pmagbafb_tc_table);
265 static 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,
271 .remove = pmagbafb_remove,
275 static int __init pmagbafb_init(void)
277 #ifndef MODULE
278 if (fb_get_options("pmagbafb", NULL))
279 return -ENXIO;
280 #endif
281 return tc_register_driver(&pmagbafb_driver);
284 static void __exit pmagbafb_exit(void)
286 tc_unregister_driver(&pmagbafb_driver);
290 module_init(pmagbafb_init);
291 module_exit(pmagbafb_exit);
293 MODULE_LICENSE("GPL");