video: fbdev: don't print error message on framebuffer_alloc() failure
[linux-block.git] / drivers / video / fbdev / pmag-ba-fb.c
CommitLineData
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 35#include <asm/io.h>
af690a94 36
1da177e4
LT
37#include <video/pmag-ba-fb.h>
38
af690a94
RB
39
40struct pmagbafb_par {
af690a94
RB
41 volatile void __iomem *mmio;
42 volatile u32 __iomem *dac;
1da177e4
LT
43};
44
1da177e4 45
a7582733 46static const struct fb_var_screeninfo pmagbafb_defined = {
1da177e4
LT
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,
af690a94
RB
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,
af22f647 63 .lower_margin = 0,
af690a94
RB
64 .hsync_len = 128,
65 .vsync_len = 3,
66 .sync = FB_SYNC_ON_GREEN,
1da177e4
LT
67 .vmode = FB_VMODE_NONINTERLACED,
68};
69
799b88de 70static const struct fb_fix_screeninfo pmagbafb_fix = {
1da177e4 71 .id = "PMAG-BA",
af690a94 72 .smem_len = (1024 * 1024),
1da177e4
LT
73 .type = FB_TYPE_PACKED_PIXELS,
74 .visual = FB_VISUAL_PSEUDOCOLOR,
75 .line_length = 1024,
af690a94 76 .mmio_len = PMAG_BA_SIZE - PMAG_BA_BT459,
1da177e4
LT
77};
78
af690a94
RB
79
80static inline void dac_write(struct pmagbafb_par *par, unsigned int reg, u8 v)
1da177e4 81{
af690a94 82 writeb(v, par->dac + reg / 4);
1da177e4
LT
83}
84
af690a94
RB
85static inline u8 dac_read(struct pmagbafb_par *par, unsigned int reg)
86{
87 return readb(par->dac + reg / 4);
88}
89
90
1da177e4 91/*
af690a94 92 * Set the palette.
1da177e4 93 */
af690a94
RB
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)
1da177e4 97{
af690a94 98 struct pmagbafb_par *par = info->par;
1da177e4 99
2f390380
KH
100 if (regno >= info->cmap.len)
101 return 1;
1da177e4
LT
102
103 red >>= 8; /* The cmap fields are 16 bits */
af690a94 104 green >>= 8; /* wide, but the hardware colormap */
1da177e4
LT
105 blue >>= 8; /* registers are only 8 bits wide */
106
af690a94
RB
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);
116
1da177e4
LT
117 return 0;
118}
119
120static struct fb_ops pmagbafb_ops = {
121 .owner = THIS_MODULE,
1da177e4
LT
122 .fb_setcolreg = pmagbafb_setcolreg,
123 .fb_fillrect = cfb_fillrect,
124 .fb_copyarea = cfb_copyarea,
125 .fb_imageblit = cfb_imageblit,
1da177e4
LT
126};
127
af690a94
RB
128
129/*
130 * Turn the hardware cursor off.
131 */
879e5a0d 132static void pmagbafb_erase_cursor(struct fb_info *info)
af690a94
RB
133{
134 struct pmagbafb_par *par = info->par;
135
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);
141}
142
143
48c68c4f 144static int pmagbafb_probe(struct device *dev)
1da177e4 145{
335dc50c
MR
146 struct tc_dev *tdev = to_tc_dev(dev);
147 resource_size_t start, len;
af690a94
RB
148 struct fb_info *info;
149 struct pmagbafb_par *par;
53ee1b5b 150 int err;
af690a94 151
335dc50c 152 info = framebuffer_alloc(sizeof(struct pmagbafb_par), dev);
0adcdbcb 153 if (!info)
af690a94
RB
154 return -ENOMEM;
155
156 par = info->par;
335dc50c 157 dev_set_drvdata(dev, info);
af690a94 158
53ee1b5b
MR
159 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
160 printk(KERN_ERR "%s: Cannot allocate color map\n",
7ad33e74 161 dev_name(dev));
53ee1b5b 162 err = -ENOMEM;
af690a94 163 goto err_alloc;
53ee1b5b 164 }
af690a94 165
1da177e4 166 info->fbops = &pmagbafb_ops;
af690a94 167 info->fix = pmagbafb_fix;
1da177e4 168 info->var = pmagbafb_defined;
1da177e4
LT
169 info->flags = FBINFO_DEFAULT;
170
335dc50c
MR
171 /* Request the I/O MEM resource. */
172 start = tdev->resource.start;
173 len = tdev->resource.end - start + 1;
7ad33e74
KS
174 if (!request_mem_region(start, len, dev_name(dev))) {
175 printk(KERN_ERR "%s: Cannot reserve FB region\n",
176 dev_name(dev));
53ee1b5b 177 err = -EBUSY;
335dc50c 178 goto err_cmap;
53ee1b5b 179 }
335dc50c 180
af690a94 181 /* MMIO mapping setup. */
335dc50c 182 info->fix.mmio_start = start;
af690a94 183 par->mmio = ioremap_nocache(info->fix.mmio_start, info->fix.mmio_len);
53ee1b5b 184 if (!par->mmio) {
7ad33e74 185 printk(KERN_ERR "%s: Cannot map MMIO\n", dev_name(dev));
53ee1b5b 186 err = -ENOMEM;
335dc50c 187 goto err_resource;
53ee1b5b 188 }
af690a94
RB
189 par->dac = par->mmio + PMAG_BA_BT459;
190
191 /* Frame buffer mapping setup. */
335dc50c 192 info->fix.smem_start = start + PMAG_BA_FBMEM;
af690a94
RB
193 info->screen_base = ioremap_nocache(info->fix.smem_start,
194 info->fix.smem_len);
53ee1b5b 195 if (!info->screen_base) {
7ad33e74 196 printk(KERN_ERR "%s: Cannot map FB\n", dev_name(dev));
53ee1b5b 197 err = -ENOMEM;
af690a94 198 goto err_mmio_map;
53ee1b5b 199 }
af690a94
RB
200 info->screen_size = info->fix.smem_len;
201
202 pmagbafb_erase_cursor(info);
1da177e4 203
53ee1b5b
MR
204 err = register_framebuffer(info);
205 if (err < 0) {
206 printk(KERN_ERR "%s: Cannot register framebuffer\n",
7ad33e74 207 dev_name(dev));
af690a94 208 goto err_smem_map;
53ee1b5b 209 }
af690a94 210
335dc50c
MR
211 get_device(dev);
212
31b6780c
JP
213 fb_info(info, "%s frame buffer device at %s\n",
214 info->fix.id, dev_name(dev));
af690a94 215
1da177e4 216 return 0;
af690a94
RB
217
218
219err_smem_map:
220 iounmap(info->screen_base);
221
222err_mmio_map:
223 iounmap(par->mmio);
224
335dc50c
MR
225err_resource:
226 release_mem_region(start, len);
227
af690a94
RB
228err_cmap:
229 fb_dealloc_cmap(&info->cmap);
230
231err_alloc:
af690a94 232 framebuffer_release(info);
53ee1b5b 233 return err;
1da177e4
LT
234}
235
982711cc 236static int pmagbafb_remove(struct device *dev)
af690a94 237{
335dc50c
MR
238 struct tc_dev *tdev = to_tc_dev(dev);
239 struct fb_info *info = dev_get_drvdata(dev);
af690a94 240 struct pmagbafb_par *par = info->par;
335dc50c 241 resource_size_t start, len;
1da177e4 242
335dc50c 243 put_device(dev);
af690a94
RB
244 unregister_framebuffer(info);
245 iounmap(info->screen_base);
246 iounmap(par->mmio);
335dc50c
MR
247 start = tdev->resource.start;
248 len = tdev->resource.end - start + 1;
249 release_mem_region(start, len);
af690a94 250 fb_dealloc_cmap(&info->cmap);
af690a94 251 framebuffer_release(info);
335dc50c 252 return 0;
af690a94
RB
253}
254
255
256/*
335dc50c 257 * Initialize the framebuffer.
af690a94 258 */
335dc50c
MR
259static 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,
982711cc 271 .remove = pmagbafb_remove,
335dc50c
MR
272 },
273};
274
af690a94 275static int __init pmagbafb_init(void)
1da177e4 276{
335dc50c 277#ifndef MODULE
1da177e4 278 if (fb_get_options("pmagbafb", NULL))
af690a94 279 return -ENXIO;
335dc50c
MR
280#endif
281 return tc_register_driver(&pmagbafb_driver);
1da177e4
LT
282}
283
af690a94
RB
284static void __exit pmagbafb_exit(void)
285{
335dc50c 286 tc_unregister_driver(&pmagbafb_driver);
af690a94
RB
287}
288
289
1da177e4 290module_init(pmagbafb_init);
af690a94
RB
291module_exit(pmagbafb_exit);
292
1da177e4 293MODULE_LICENSE("GPL");