Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
af690a94 | 2 | * linux/drivers/video/pmag-ba-fb.c |
1da177e4 | 3 | * |
af690a94 RB |
4 | * PMAG-BA TURBOchannel Color Frame Buffer (CFB) card support, |
5 | * derived from: | |
1da177e4 LT |
6 | * "HP300 Topcat framebuffer support (derived from macfb of all things) |
7 | * Phil Blundell <philb@gnu.org> 1998", the original code can be | |
af690a94 | 8 | * found in the file hpfb.c in the same directory. |
1da177e4 LT |
9 | * |
10 | * Based on digital document: | |
11 | * "PMAG-BA TURBOchannel Color Frame Buffer | |
12 | * Functional Specification", Revision 1.2, August 27, 1990 | |
13 | * | |
af690a94 RB |
14 | * DECstation related code Copyright (C) 1999, 2000, 2001 by |
15 | * Michael Engel <engel@unix-ag.org>, | |
16 | * Karsten Merker <merker@linuxtag.org> and | |
1da177e4 | 17 | * Harald Koerfgen. |
335dc50c MR |
18 | * Copyright (c) 2005, 2006 Maciej W. Rozycki |
19 | * Copyright (c) 2005 James Simmons | |
1da177e4 | 20 | * |
af690a94 RB |
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. | |
1da177e4 | 24 | */ |
af690a94 RB |
25 | |
26 | #include <linux/compiler.h> | |
1da177e4 | 27 | #include <linux/errno.h> |
1da177e4 | 28 | #include <linux/fb.h> |
af690a94 RB |
29 | #include <linux/init.h> |
30 | #include <linux/kernel.h> | |
31 | #include <linux/module.h> | |
335dc50c | 32 | #include <linux/tc.h> |
af690a94 RB |
33 | #include <linux/types.h> |
34 | ||
af690a94 RB |
35 | #include <asm/io.h> |
36 | #include <asm/system.h> | |
37 | ||
1da177e4 LT |
38 | #include <video/pmag-ba-fb.h> |
39 | ||
af690a94 RB |
40 | |
41 | struct pmagbafb_par { | |
af690a94 RB |
42 | volatile void __iomem *mmio; |
43 | volatile u32 __iomem *dac; | |
1da177e4 LT |
44 | }; |
45 | ||
1da177e4 | 46 | |
9625b513 | 47 | static struct fb_var_screeninfo pmagbafb_defined __devinitdata = { |
1da177e4 LT |
48 | .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, | |
af690a94 RB |
57 | .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, | |
1da177e4 LT |
68 | .vmode = FB_VMODE_NONINTERLACED, |
69 | }; | |
70 | ||
9625b513 | 71 | static struct fb_fix_screeninfo pmagbafb_fix __devinitdata = { |
1da177e4 | 72 | .id = "PMAG-BA", |
af690a94 | 73 | .smem_len = (1024 * 1024), |
1da177e4 LT |
74 | .type = FB_TYPE_PACKED_PIXELS, |
75 | .visual = FB_VISUAL_PSEUDOCOLOR, | |
76 | .line_length = 1024, | |
af690a94 | 77 | .mmio_len = PMAG_BA_SIZE - PMAG_BA_BT459, |
1da177e4 LT |
78 | }; |
79 | ||
af690a94 RB |
80 | |
81 | static inline void dac_write(struct pmagbafb_par *par, unsigned int reg, u8 v) | |
1da177e4 | 82 | { |
af690a94 | 83 | writeb(v, par->dac + reg / 4); |
1da177e4 LT |
84 | } |
85 | ||
af690a94 RB |
86 | static inline u8 dac_read(struct pmagbafb_par *par, unsigned int reg) |
87 | { | |
88 | return readb(par->dac + reg / 4); | |
89 | } | |
90 | ||
91 | ||
1da177e4 | 92 | /* |
af690a94 | 93 | * Set the palette. |
1da177e4 | 94 | */ |
af690a94 RB |
95 | static int pmagbafb_setcolreg(unsigned int regno, unsigned int red, |
96 | unsigned int green, unsigned int blue, | |
97 | unsigned int transp, struct fb_info *info) | |
1da177e4 | 98 | { |
af690a94 | 99 | struct pmagbafb_par *par = info->par; |
1da177e4 | 100 | |
2f390380 KH |
101 | if (regno >= info->cmap.len) |
102 | return 1; | |
1da177e4 LT |
103 | |
104 | red >>= 8; /* The cmap fields are 16 bits */ | |
af690a94 | 105 | green >>= 8; /* wide, but the hardware colormap */ |
1da177e4 LT |
106 | blue >>= 8; /* registers are only 8 bits wide */ |
107 | ||
af690a94 RB |
108 | 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 | ||
1da177e4 LT |
118 | return 0; |
119 | } | |
120 | ||
121 | static struct fb_ops pmagbafb_ops = { | |
122 | .owner = THIS_MODULE, | |
1da177e4 LT |
123 | .fb_setcolreg = pmagbafb_setcolreg, |
124 | .fb_fillrect = cfb_fillrect, | |
125 | .fb_copyarea = cfb_copyarea, | |
126 | .fb_imageblit = cfb_imageblit, | |
1da177e4 LT |
127 | }; |
128 | ||
af690a94 RB |
129 | |
130 | /* | |
131 | * Turn the hardware cursor off. | |
132 | */ | |
133 | static void __init pmagbafb_erase_cursor(struct fb_info *info) | |
134 | { | |
135 | struct pmagbafb_par *par = info->par; | |
136 | ||
137 | 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 | } | |
143 | ||
144 | ||
9625b513 | 145 | static int __devinit pmagbafb_probe(struct device *dev) |
1da177e4 | 146 | { |
335dc50c MR |
147 | struct tc_dev *tdev = to_tc_dev(dev); |
148 | resource_size_t start, len; | |
af690a94 RB |
149 | struct fb_info *info; |
150 | struct pmagbafb_par *par; | |
53ee1b5b | 151 | int err; |
af690a94 | 152 | |
335dc50c | 153 | info = framebuffer_alloc(sizeof(struct pmagbafb_par), dev); |
53ee1b5b | 154 | if (!info) { |
7ad33e74 | 155 | printk(KERN_ERR "%s: Cannot allocate memory\n", dev_name(dev)); |
af690a94 | 156 | return -ENOMEM; |
53ee1b5b | 157 | } |
af690a94 RB |
158 | |
159 | par = info->par; | |
335dc50c | 160 | dev_set_drvdata(dev, info); |
af690a94 | 161 | |
53ee1b5b MR |
162 | if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) { |
163 | printk(KERN_ERR "%s: Cannot allocate color map\n", | |
7ad33e74 | 164 | dev_name(dev)); |
53ee1b5b | 165 | err = -ENOMEM; |
af690a94 | 166 | goto err_alloc; |
53ee1b5b | 167 | } |
af690a94 | 168 | |
1da177e4 | 169 | info->fbops = &pmagbafb_ops; |
af690a94 | 170 | info->fix = pmagbafb_fix; |
1da177e4 | 171 | info->var = pmagbafb_defined; |
1da177e4 LT |
172 | info->flags = FBINFO_DEFAULT; |
173 | ||
335dc50c MR |
174 | /* Request the I/O MEM resource. */ |
175 | start = tdev->resource.start; | |
176 | len = tdev->resource.end - start + 1; | |
7ad33e74 KS |
177 | if (!request_mem_region(start, len, dev_name(dev))) { |
178 | printk(KERN_ERR "%s: Cannot reserve FB region\n", | |
179 | dev_name(dev)); | |
53ee1b5b | 180 | err = -EBUSY; |
335dc50c | 181 | goto err_cmap; |
53ee1b5b | 182 | } |
335dc50c | 183 | |
af690a94 | 184 | /* MMIO mapping setup. */ |
335dc50c | 185 | info->fix.mmio_start = start; |
af690a94 | 186 | par->mmio = ioremap_nocache(info->fix.mmio_start, info->fix.mmio_len); |
53ee1b5b | 187 | if (!par->mmio) { |
7ad33e74 | 188 | printk(KERN_ERR "%s: Cannot map MMIO\n", dev_name(dev)); |
53ee1b5b | 189 | err = -ENOMEM; |
335dc50c | 190 | goto err_resource; |
53ee1b5b | 191 | } |
af690a94 RB |
192 | par->dac = par->mmio + PMAG_BA_BT459; |
193 | ||
194 | /* Frame buffer mapping setup. */ | |
335dc50c | 195 | info->fix.smem_start = start + PMAG_BA_FBMEM; |
af690a94 RB |
196 | info->screen_base = ioremap_nocache(info->fix.smem_start, |
197 | info->fix.smem_len); | |
53ee1b5b | 198 | if (!info->screen_base) { |
7ad33e74 | 199 | printk(KERN_ERR "%s: Cannot map FB\n", dev_name(dev)); |
53ee1b5b | 200 | err = -ENOMEM; |
af690a94 | 201 | goto err_mmio_map; |
53ee1b5b | 202 | } |
af690a94 RB |
203 | info->screen_size = info->fix.smem_len; |
204 | ||
205 | pmagbafb_erase_cursor(info); | |
1da177e4 | 206 | |
53ee1b5b MR |
207 | err = register_framebuffer(info); |
208 | if (err < 0) { | |
209 | printk(KERN_ERR "%s: Cannot register framebuffer\n", | |
7ad33e74 | 210 | dev_name(dev)); |
af690a94 | 211 | goto err_smem_map; |
53ee1b5b | 212 | } |
af690a94 | 213 | |
335dc50c MR |
214 | get_device(dev); |
215 | ||
216 | pr_info("fb%d: %s frame buffer device at %s\n", | |
7ad33e74 | 217 | info->node, info->fix.id, dev_name(dev)); |
af690a94 | 218 | |
1da177e4 | 219 | return 0; |
af690a94 RB |
220 | |
221 | ||
222 | err_smem_map: | |
223 | iounmap(info->screen_base); | |
224 | ||
225 | err_mmio_map: | |
226 | iounmap(par->mmio); | |
227 | ||
335dc50c MR |
228 | err_resource: |
229 | release_mem_region(start, len); | |
230 | ||
af690a94 RB |
231 | err_cmap: |
232 | fb_dealloc_cmap(&info->cmap); | |
233 | ||
234 | err_alloc: | |
af690a94 | 235 | framebuffer_release(info); |
53ee1b5b | 236 | return err; |
1da177e4 LT |
237 | } |
238 | ||
335dc50c | 239 | static int __exit pmagbafb_remove(struct device *dev) |
af690a94 | 240 | { |
335dc50c MR |
241 | struct tc_dev *tdev = to_tc_dev(dev); |
242 | struct fb_info *info = dev_get_drvdata(dev); | |
af690a94 | 243 | struct pmagbafb_par *par = info->par; |
335dc50c | 244 | resource_size_t start, len; |
1da177e4 | 245 | |
335dc50c | 246 | put_device(dev); |
af690a94 RB |
247 | unregister_framebuffer(info); |
248 | iounmap(info->screen_base); | |
249 | iounmap(par->mmio); | |
335dc50c MR |
250 | start = tdev->resource.start; |
251 | len = tdev->resource.end - start + 1; | |
252 | release_mem_region(start, len); | |
af690a94 | 253 | fb_dealloc_cmap(&info->cmap); |
af690a94 | 254 | framebuffer_release(info); |
335dc50c | 255 | return 0; |
af690a94 RB |
256 | } |
257 | ||
258 | ||
259 | /* | |
335dc50c | 260 | * Initialize the framebuffer. |
af690a94 | 261 | */ |
335dc50c MR |
262 | static const struct tc_device_id pmagbafb_tc_table[] = { |
263 | { "DEC ", "PMAG-BA " }, | |
264 | { } | |
265 | }; | |
266 | MODULE_DEVICE_TABLE(tc, pmagbafb_tc_table); | |
267 | ||
268 | static 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 | ||
af690a94 | 278 | static int __init pmagbafb_init(void) |
1da177e4 | 279 | { |
335dc50c | 280 | #ifndef MODULE |
1da177e4 | 281 | if (fb_get_options("pmagbafb", NULL)) |
af690a94 | 282 | return -ENXIO; |
335dc50c MR |
283 | #endif |
284 | return tc_register_driver(&pmagbafb_driver); | |
1da177e4 LT |
285 | } |
286 | ||
af690a94 RB |
287 | static void __exit pmagbafb_exit(void) |
288 | { | |
335dc50c | 289 | tc_unregister_driver(&pmagbafb_driver); |
af690a94 RB |
290 | } |
291 | ||
292 | ||
1da177e4 | 293 | module_init(pmagbafb_init); |
af690a94 RB |
294 | module_exit(pmagbafb_exit); |
295 | ||
1da177e4 | 296 | MODULE_LICENSE("GPL"); |