| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* bw2.c: BWTWO frame buffer driver | 
|  | 2 | * | 
| David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 3 | * Copyright (C) 2003, 2006 David S. Miller (davem@davemloft.net) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * Copyright (C) 1996,1998 Jakub Jelinek (jj@ultra.linux.cz) | 
|  | 5 | * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx) | 
|  | 6 | * Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be) | 
|  | 7 | * | 
|  | 8 | * Driver layout based loosely on tgafb.c, see that file for credits. | 
|  | 9 | */ | 
|  | 10 |  | 
|  | 11 | #include <linux/module.h> | 
|  | 12 | #include <linux/kernel.h> | 
|  | 13 | #include <linux/errno.h> | 
|  | 14 | #include <linux/string.h> | 
|  | 15 | #include <linux/slab.h> | 
|  | 16 | #include <linux/delay.h> | 
|  | 17 | #include <linux/init.h> | 
|  | 18 | #include <linux/fb.h> | 
|  | 19 | #include <linux/mm.h> | 
| Robert Reif | 6cd5a86 | 2008-05-08 21:37:30 -0700 | [diff] [blame] | 20 | #include <linux/of_device.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 |  | 
|  | 22 | #include <asm/io.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <asm/fbio.h> | 
|  | 24 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include "sbuslib.h" | 
|  | 26 |  | 
|  | 27 | /* | 
|  | 28 | * Local functions. | 
|  | 29 | */ | 
|  | 30 |  | 
|  | 31 | static int bw2_blank(int, struct fb_info *); | 
|  | 32 |  | 
| Christoph Hellwig | 216d526 | 2006-01-14 13:21:25 -0800 | [diff] [blame] | 33 | static int bw2_mmap(struct fb_info *, struct vm_area_struct *); | 
| Christoph Hellwig | 67a6680 | 2006-01-14 13:21:25 -0800 | [diff] [blame] | 34 | static int bw2_ioctl(struct fb_info *, unsigned int, unsigned long); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 |  | 
|  | 36 | /* | 
|  | 37 | *  Frame buffer operations | 
|  | 38 | */ | 
|  | 39 |  | 
|  | 40 | static struct fb_ops bw2_ops = { | 
|  | 41 | .owner			= THIS_MODULE, | 
|  | 42 | .fb_blank		= bw2_blank, | 
|  | 43 | .fb_fillrect		= cfb_fillrect, | 
|  | 44 | .fb_copyarea		= cfb_copyarea, | 
|  | 45 | .fb_imageblit		= cfb_imageblit, | 
|  | 46 | .fb_mmap		= bw2_mmap, | 
|  | 47 | .fb_ioctl		= bw2_ioctl, | 
| Christoph Hellwig | 9ffb83b | 2005-11-12 12:11:12 -0800 | [diff] [blame] | 48 | #ifdef CONFIG_COMPAT | 
|  | 49 | .fb_compat_ioctl	= sbusfb_compat_ioctl, | 
|  | 50 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | }; | 
|  | 52 |  | 
|  | 53 | /* OBio addresses for the bwtwo registers */ | 
|  | 54 | #define BWTWO_REGISTER_OFFSET 0x400000 | 
|  | 55 |  | 
|  | 56 | struct bt_regs { | 
| David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 57 | u32 addr; | 
|  | 58 | u32 color_map; | 
|  | 59 | u32 control; | 
|  | 60 | u32 cursor; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | }; | 
|  | 62 |  | 
|  | 63 | struct bw2_regs { | 
|  | 64 | struct bt_regs	cmap; | 
| David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 65 | u8	control; | 
|  | 66 | u8	status; | 
|  | 67 | u8	cursor_start; | 
|  | 68 | u8	cursor_end; | 
|  | 69 | u8	h_blank_start; | 
|  | 70 | u8	h_blank_end; | 
|  | 71 | u8	h_sync_start; | 
|  | 72 | u8	h_sync_end; | 
|  | 73 | u8	comp_sync_end; | 
|  | 74 | u8	v_blank_start_high; | 
|  | 75 | u8	v_blank_start_low; | 
|  | 76 | u8	v_blank_end; | 
|  | 77 | u8	v_sync_start; | 
|  | 78 | u8	v_sync_end; | 
|  | 79 | u8	xfer_holdoff_start; | 
|  | 80 | u8	xfer_holdoff_end; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | }; | 
|  | 82 |  | 
|  | 83 | /* Status Register Constants */ | 
|  | 84 | #define BWTWO_SR_RES_MASK	0x70 | 
|  | 85 | #define BWTWO_SR_1600_1280	0x50 | 
|  | 86 | #define BWTWO_SR_1152_900_76_A	0x40 | 
|  | 87 | #define BWTWO_SR_1152_900_76_B	0x60 | 
|  | 88 | #define BWTWO_SR_ID_MASK	0x0f | 
|  | 89 | #define BWTWO_SR_ID_MONO	0x02 | 
|  | 90 | #define BWTWO_SR_ID_MONO_ECL	0x03 | 
|  | 91 | #define BWTWO_SR_ID_MSYNC	0x04 | 
|  | 92 | #define BWTWO_SR_ID_NOCONN	0x0a | 
|  | 93 |  | 
|  | 94 | /* Control Register Constants */ | 
|  | 95 | #define BWTWO_CTL_ENABLE_INTS   0x80 | 
|  | 96 | #define BWTWO_CTL_ENABLE_VIDEO  0x40 | 
|  | 97 | #define BWTWO_CTL_ENABLE_TIMING 0x20 | 
|  | 98 | #define BWTWO_CTL_ENABLE_CURCMP 0x10 | 
|  | 99 | #define BWTWO_CTL_XTAL_MASK     0x0C | 
|  | 100 | #define BWTWO_CTL_DIVISOR_MASK  0x03 | 
|  | 101 |  | 
|  | 102 | /* Status Register Constants */ | 
|  | 103 | #define BWTWO_STAT_PENDING_INT  0x80 | 
|  | 104 | #define BWTWO_STAT_MSENSE_MASK  0x70 | 
|  | 105 | #define BWTWO_STAT_ID_MASK      0x0f | 
|  | 106 |  | 
|  | 107 | struct bw2_par { | 
|  | 108 | spinlock_t		lock; | 
|  | 109 | struct bw2_regs		__iomem *regs; | 
|  | 110 |  | 
|  | 111 | u32			flags; | 
|  | 112 | #define BW2_FLAG_BLANKED	0x00000001 | 
|  | 113 |  | 
|  | 114 | unsigned long		physbase; | 
| David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 115 | unsigned long		which_io; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | unsigned long		fbsize; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | }; | 
|  | 118 |  | 
|  | 119 | /** | 
|  | 120 | *      bw2_blank - Optional function.  Blanks the display. | 
|  | 121 | *      @blank_mode: the blank mode we want. | 
|  | 122 | *      @info: frame buffer structure that represents a single frame buffer | 
|  | 123 | */ | 
|  | 124 | static int | 
|  | 125 | bw2_blank(int blank, struct fb_info *info) | 
|  | 126 | { | 
|  | 127 | struct bw2_par *par = (struct bw2_par *) info->par; | 
|  | 128 | struct bw2_regs __iomem *regs = par->regs; | 
|  | 129 | unsigned long flags; | 
|  | 130 | u8 val; | 
|  | 131 |  | 
|  | 132 | spin_lock_irqsave(&par->lock, flags); | 
|  | 133 |  | 
|  | 134 | switch (blank) { | 
|  | 135 | case FB_BLANK_UNBLANK: /* Unblanking */ | 
|  | 136 | val = sbus_readb(®s->control); | 
|  | 137 | val |= BWTWO_CTL_ENABLE_VIDEO; | 
|  | 138 | sbus_writeb(val, ®s->control); | 
|  | 139 | par->flags &= ~BW2_FLAG_BLANKED; | 
|  | 140 | break; | 
|  | 141 |  | 
|  | 142 | case FB_BLANK_NORMAL: /* Normal blanking */ | 
|  | 143 | case FB_BLANK_VSYNC_SUSPEND: /* VESA blank (vsync off) */ | 
|  | 144 | case FB_BLANK_HSYNC_SUSPEND: /* VESA blank (hsync off) */ | 
|  | 145 | case FB_BLANK_POWERDOWN: /* Poweroff */ | 
|  | 146 | val = sbus_readb(®s->control); | 
|  | 147 | val &= ~BWTWO_CTL_ENABLE_VIDEO; | 
|  | 148 | sbus_writeb(val, ®s->control); | 
|  | 149 | par->flags |= BW2_FLAG_BLANKED; | 
|  | 150 | break; | 
|  | 151 | } | 
|  | 152 |  | 
|  | 153 | spin_unlock_irqrestore(&par->lock, flags); | 
|  | 154 |  | 
|  | 155 | return 0; | 
|  | 156 | } | 
|  | 157 |  | 
|  | 158 | static struct sbus_mmap_map bw2_mmap_map[] = { | 
|  | 159 | { | 
|  | 160 | .size = SBUS_MMAP_FBSIZE(1) | 
|  | 161 | }, | 
|  | 162 | { .size = 0 } | 
|  | 163 | }; | 
|  | 164 |  | 
| Christoph Hellwig | 216d526 | 2006-01-14 13:21:25 -0800 | [diff] [blame] | 165 | static int bw2_mmap(struct fb_info *info, struct vm_area_struct *vma) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | { | 
|  | 167 | struct bw2_par *par = (struct bw2_par *)info->par; | 
|  | 168 |  | 
|  | 169 | return sbusfb_mmap_helper(bw2_mmap_map, | 
|  | 170 | par->physbase, par->fbsize, | 
| David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 171 | par->which_io, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | vma); | 
|  | 173 | } | 
|  | 174 |  | 
| Christoph Hellwig | 67a6680 | 2006-01-14 13:21:25 -0800 | [diff] [blame] | 175 | static int bw2_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | { | 
|  | 177 | struct bw2_par *par = (struct bw2_par *) info->par; | 
|  | 178 |  | 
|  | 179 | return sbusfb_ioctl_helper(cmd, arg, info, | 
|  | 180 | FBTYPE_SUN2BW, 1, par->fbsize); | 
|  | 181 | } | 
|  | 182 |  | 
|  | 183 | /* | 
|  | 184 | *  Initialisation | 
|  | 185 | */ | 
|  | 186 |  | 
| Robert Reif | 63abdcd | 2007-03-08 21:22:35 -0800 | [diff] [blame] | 187 | static void __devinit bw2_init_fix(struct fb_info *info, int linebytes) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | { | 
|  | 189 | strlcpy(info->fix.id, "bwtwo", sizeof(info->fix.id)); | 
|  | 190 |  | 
|  | 191 | info->fix.type = FB_TYPE_PACKED_PIXELS; | 
|  | 192 | info->fix.visual = FB_VISUAL_MONO01; | 
|  | 193 |  | 
|  | 194 | info->fix.line_length = linebytes; | 
|  | 195 |  | 
|  | 196 | info->fix.accel = FB_ACCEL_SUN_BWTWO; | 
|  | 197 | } | 
|  | 198 |  | 
| Robert Reif | 63abdcd | 2007-03-08 21:22:35 -0800 | [diff] [blame] | 199 | static u8 bw2regs_1600[] __devinitdata = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | 0x14, 0x8b,	0x15, 0x28,	0x16, 0x03,	0x17, 0x13, | 
|  | 201 | 0x18, 0x7b,	0x19, 0x05,	0x1a, 0x34,	0x1b, 0x2e, | 
|  | 202 | 0x1c, 0x00,	0x1d, 0x0a,	0x1e, 0xff,	0x1f, 0x01, | 
|  | 203 | 0x10, 0x21,	0 | 
|  | 204 | }; | 
|  | 205 |  | 
| Robert Reif | 63abdcd | 2007-03-08 21:22:35 -0800 | [diff] [blame] | 206 | static u8 bw2regs_ecl[] __devinitdata = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | 0x14, 0x65,	0x15, 0x1e,	0x16, 0x04,	0x17, 0x0c, | 
|  | 208 | 0x18, 0x5e,	0x19, 0x03,	0x1a, 0xa7,	0x1b, 0x23, | 
|  | 209 | 0x1c, 0x00,	0x1d, 0x08,	0x1e, 0xff,	0x1f, 0x01, | 
|  | 210 | 0x10, 0x20,	0 | 
|  | 211 | }; | 
|  | 212 |  | 
| Robert Reif | 63abdcd | 2007-03-08 21:22:35 -0800 | [diff] [blame] | 213 | static u8 bw2regs_analog[] __devinitdata = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | 0x14, 0xbb,	0x15, 0x2b,	0x16, 0x03,	0x17, 0x13, | 
|  | 215 | 0x18, 0xb0,	0x19, 0x03,	0x1a, 0xa6,	0x1b, 0x22, | 
|  | 216 | 0x1c, 0x01,	0x1d, 0x05,	0x1e, 0xff,	0x1f, 0x01, | 
|  | 217 | 0x10, 0x20,	0 | 
|  | 218 | }; | 
|  | 219 |  | 
| Robert Reif | 63abdcd | 2007-03-08 21:22:35 -0800 | [diff] [blame] | 220 | static u8 bw2regs_76hz[] __devinitdata = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | 0x14, 0xb7,	0x15, 0x27,	0x16, 0x03,	0x17, 0x0f, | 
|  | 222 | 0x18, 0xae,	0x19, 0x03,	0x1a, 0xae,	0x1b, 0x2a, | 
|  | 223 | 0x1c, 0x01,	0x1d, 0x09,	0x1e, 0xff,	0x1f, 0x01, | 
|  | 224 | 0x10, 0x24,	0 | 
|  | 225 | }; | 
|  | 226 |  | 
| Robert Reif | 63abdcd | 2007-03-08 21:22:35 -0800 | [diff] [blame] | 227 | static u8 bw2regs_66hz[] __devinitdata = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | 0x14, 0xbb,	0x15, 0x2b,	0x16, 0x04,	0x17, 0x14, | 
|  | 229 | 0x18, 0xae,	0x19, 0x03,	0x1a, 0xa8,	0x1b, 0x24, | 
|  | 230 | 0x1c, 0x01,	0x1d, 0x05,	0x1e, 0xff,	0x1f, 0x01, | 
|  | 231 | 0x10, 0x20,	0 | 
|  | 232 | }; | 
|  | 233 |  | 
| David S. Miller | 6c8f5b9 | 2007-08-24 22:33:15 -0700 | [diff] [blame] | 234 | static int __devinit bw2_do_default_mode(struct bw2_par *par, | 
|  | 235 | struct fb_info *info, | 
|  | 236 | int *linebytes) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | { | 
|  | 238 | u8 status, mon; | 
|  | 239 | u8 *p; | 
|  | 240 |  | 
|  | 241 | status = sbus_readb(&par->regs->status); | 
|  | 242 | mon = status & BWTWO_SR_RES_MASK; | 
|  | 243 | switch (status & BWTWO_SR_ID_MASK) { | 
|  | 244 | case BWTWO_SR_ID_MONO_ECL: | 
|  | 245 | if (mon == BWTWO_SR_1600_1280) { | 
|  | 246 | p = bw2regs_1600; | 
|  | 247 | info->var.xres = info->var.xres_virtual = 1600; | 
|  | 248 | info->var.yres = info->var.yres_virtual = 1280; | 
|  | 249 | *linebytes = 1600 / 8; | 
|  | 250 | } else | 
|  | 251 | p = bw2regs_ecl; | 
|  | 252 | break; | 
|  | 253 |  | 
|  | 254 | case BWTWO_SR_ID_MONO: | 
|  | 255 | p = bw2regs_analog; | 
|  | 256 | break; | 
|  | 257 |  | 
|  | 258 | case BWTWO_SR_ID_MSYNC: | 
|  | 259 | if (mon == BWTWO_SR_1152_900_76_A || | 
|  | 260 | mon == BWTWO_SR_1152_900_76_B) | 
|  | 261 | p = bw2regs_76hz; | 
|  | 262 | else | 
|  | 263 | p = bw2regs_66hz; | 
|  | 264 | break; | 
|  | 265 |  | 
|  | 266 | case BWTWO_SR_ID_NOCONN: | 
| David S. Miller | 6c8f5b9 | 2007-08-24 22:33:15 -0700 | [diff] [blame] | 267 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 |  | 
|  | 269 | default: | 
| David S. Miller | 6c8f5b9 | 2007-08-24 22:33:15 -0700 | [diff] [blame] | 270 | printk(KERN_ERR "bw2: can't handle SR %02x\n", | 
|  | 271 | status); | 
|  | 272 | return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | } | 
|  | 274 | for ( ; *p; p += 2) { | 
|  | 275 | u8 __iomem *regp = &((u8 __iomem *)par->regs)[p[0]]; | 
|  | 276 | sbus_writeb(p[1], regp); | 
|  | 277 | } | 
| David S. Miller | 6c8f5b9 | 2007-08-24 22:33:15 -0700 | [diff] [blame] | 278 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | } | 
|  | 280 |  | 
| David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame] | 281 | static int __devinit bw2_probe(struct of_device *op, const struct of_device_id *match) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | { | 
| David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 283 | struct device_node *dp = op->node; | 
| David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame] | 284 | struct fb_info *info; | 
|  | 285 | struct bw2_par *par; | 
| David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 286 | int linebytes, err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 |  | 
| David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame] | 288 | info = framebuffer_alloc(sizeof(struct bw2_par), &op->dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 |  | 
| David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame] | 290 | err = -ENOMEM; | 
|  | 291 | if (!info) | 
|  | 292 | goto out_err; | 
|  | 293 | par = info->par; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 |  | 
| David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame] | 295 | spin_lock_init(&par->lock); | 
| David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 296 |  | 
| David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame] | 297 | par->physbase = op->resource[0].start; | 
|  | 298 | par->which_io = op->resource[0].flags & IORESOURCE_BITS; | 
|  | 299 |  | 
| Robert Reif | 6cd5a86 | 2008-05-08 21:37:30 -0700 | [diff] [blame] | 300 | sbusfb_fill_var(&info->var, dp, 1); | 
| David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 301 | linebytes = of_getintprop_default(dp, "linebytes", | 
| David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame] | 302 | info->var.xres); | 
| David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 303 |  | 
| David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame] | 304 | info->var.red.length = info->var.green.length = | 
|  | 305 | info->var.blue.length = info->var.bits_per_pixel; | 
|  | 306 | info->var.red.offset = info->var.green.offset = | 
|  | 307 | info->var.blue.offset = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 |  | 
| David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame] | 309 | par->regs = of_ioremap(&op->resource[0], BWTWO_REGISTER_OFFSET, | 
|  | 310 | sizeof(struct bw2_regs), "bw2 regs"); | 
|  | 311 | if (!par->regs) | 
|  | 312 | goto out_release_fb; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 |  | 
| David S. Miller | 6c8f5b9 | 2007-08-24 22:33:15 -0700 | [diff] [blame] | 314 | if (!of_find_property(dp, "width", NULL)) { | 
|  | 315 | err = bw2_do_default_mode(par, info, &linebytes); | 
|  | 316 | if (err) | 
|  | 317 | goto out_unmap_regs; | 
|  | 318 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 |  | 
| David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame] | 320 | par->fbsize = PAGE_ALIGN(linebytes * info->var.yres); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 |  | 
| David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame] | 322 | info->flags = FBINFO_DEFAULT; | 
|  | 323 | info->fbops = &bw2_ops; | 
| David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 324 |  | 
| David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame] | 325 | info->screen_base = of_ioremap(&op->resource[0], 0, | 
|  | 326 | par->fbsize, "bw2 ram"); | 
|  | 327 | if (!info->screen_base) | 
|  | 328 | goto out_unmap_regs; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 |  | 
| Robert Reif | 59f7137 | 2008-05-03 21:12:00 -0700 | [diff] [blame] | 330 | bw2_blank(FB_BLANK_UNBLANK, info); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 |  | 
| David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame] | 332 | bw2_init_fix(info, linebytes); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 |  | 
| David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame] | 334 | err = register_framebuffer(info); | 
|  | 335 | if (err < 0) | 
|  | 336 | goto out_unmap_screen; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 |  | 
| David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame] | 338 | dev_set_drvdata(&op->dev, info); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 |  | 
| Robert Reif | 194f1a6 | 2008-04-27 15:18:57 -0700 | [diff] [blame] | 340 | printk(KERN_INFO "%s: bwtwo at %lx:%lx\n", | 
| David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame] | 341 | dp->full_name, par->which_io, par->physbase); | 
| David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 342 |  | 
|  | 343 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 |  | 
| David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame] | 345 | out_unmap_screen: | 
|  | 346 | of_iounmap(&op->resource[0], info->screen_base, par->fbsize); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 |  | 
| David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame] | 348 | out_unmap_regs: | 
|  | 349 | of_iounmap(&op->resource[0], par->regs, sizeof(struct bw2_regs)); | 
|  | 350 |  | 
|  | 351 | out_release_fb: | 
|  | 352 | framebuffer_release(info); | 
|  | 353 |  | 
|  | 354 | out_err: | 
|  | 355 | return err; | 
| David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 356 | } | 
|  | 357 |  | 
| David S. Miller | e3a411a | 2006-12-28 21:01:32 -0800 | [diff] [blame] | 358 | static int __devexit bw2_remove(struct of_device *op) | 
| David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 359 | { | 
| David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame] | 360 | struct fb_info *info = dev_get_drvdata(&op->dev); | 
|  | 361 | struct bw2_par *par = info->par; | 
| David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 362 |  | 
| David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame] | 363 | unregister_framebuffer(info); | 
| David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 364 |  | 
| David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame] | 365 | of_iounmap(&op->resource[0], par->regs, sizeof(struct bw2_regs)); | 
|  | 366 | of_iounmap(&op->resource[0], info->screen_base, par->fbsize); | 
| David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 367 |  | 
| David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame] | 368 | framebuffer_release(info); | 
| David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 369 |  | 
| David S. Miller | e3a411a | 2006-12-28 21:01:32 -0800 | [diff] [blame] | 370 | dev_set_drvdata(&op->dev, NULL); | 
| David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 371 |  | 
|  | 372 | return 0; | 
|  | 373 | } | 
|  | 374 |  | 
|  | 375 | static struct of_device_id bw2_match[] = { | 
|  | 376 | { | 
|  | 377 | .name = "bwtwo", | 
|  | 378 | }, | 
|  | 379 | {}, | 
|  | 380 | }; | 
|  | 381 | MODULE_DEVICE_TABLE(of, bw2_match); | 
|  | 382 |  | 
|  | 383 | static struct of_platform_driver bw2_driver = { | 
|  | 384 | .name		= "bw2", | 
|  | 385 | .match_table	= bw2_match, | 
|  | 386 | .probe		= bw2_probe, | 
|  | 387 | .remove		= __devexit_p(bw2_remove), | 
|  | 388 | }; | 
|  | 389 |  | 
|  | 390 | static int __init bw2_init(void) | 
|  | 391 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | if (fb_get_options("bw2fb", NULL)) | 
|  | 393 | return -ENODEV; | 
|  | 394 |  | 
| David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 395 | return of_register_driver(&bw2_driver, &of_bus_type); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | } | 
|  | 397 |  | 
| David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 398 | static void __exit bw2_exit(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | { | 
| Robert Reif | 2556bf1 | 2008-04-27 15:16:59 -0700 | [diff] [blame] | 400 | of_unregister_driver(&bw2_driver); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | } | 
|  | 402 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | module_init(bw2_init); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | module_exit(bw2_exit); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 |  | 
|  | 406 | MODULE_DESCRIPTION("framebuffer driver for BWTWO chipsets"); | 
| David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 407 | MODULE_AUTHOR("David S. Miller <davem@davemloft.net>"); | 
|  | 408 | MODULE_VERSION("2.0"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | MODULE_LICENSE("GPL"); |