Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* leo.c: LEO 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-1999 Jakub Jelinek (jj@ultra.linux.cz) |
| 5 | * Copyright (C) 1997 Michal Rehacek (Michal.Rehacek@st.mff.cuni.cz) |
| 6 | * |
| 7 | * Driver layout based loosely on tgafb.c, see that file for credits. |
| 8 | */ |
| 9 | |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/errno.h> |
| 13 | #include <linux/string.h> |
| 14 | #include <linux/slab.h> |
| 15 | #include <linux/delay.h> |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/fb.h> |
| 18 | #include <linux/mm.h> |
| 19 | |
| 20 | #include <asm/io.h> |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 21 | #include <asm/prom.h> |
| 22 | #include <asm/of_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <asm/fbio.h> |
| 24 | |
| 25 | #include "sbuslib.h" |
| 26 | |
| 27 | /* |
| 28 | * Local functions. |
| 29 | */ |
| 30 | |
| 31 | static int leo_setcolreg(unsigned, unsigned, unsigned, unsigned, |
| 32 | unsigned, struct fb_info *); |
| 33 | static int leo_blank(int, struct fb_info *); |
| 34 | |
Christoph Hellwig | 216d526 | 2006-01-14 13:21:25 -0800 | [diff] [blame] | 35 | static int leo_mmap(struct fb_info *, struct vm_area_struct *); |
Christoph Hellwig | 67a6680 | 2006-01-14 13:21:25 -0800 | [diff] [blame] | 36 | static int leo_ioctl(struct fb_info *, unsigned int, unsigned long); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | static int leo_pan_display(struct fb_var_screeninfo *, struct fb_info *); |
| 38 | |
| 39 | /* |
| 40 | * Frame buffer operations |
| 41 | */ |
| 42 | |
| 43 | static struct fb_ops leo_ops = { |
| 44 | .owner = THIS_MODULE, |
| 45 | .fb_setcolreg = leo_setcolreg, |
| 46 | .fb_blank = leo_blank, |
| 47 | .fb_pan_display = leo_pan_display, |
| 48 | .fb_fillrect = cfb_fillrect, |
| 49 | .fb_copyarea = cfb_copyarea, |
| 50 | .fb_imageblit = cfb_imageblit, |
| 51 | .fb_mmap = leo_mmap, |
| 52 | .fb_ioctl = leo_ioctl, |
Christoph Hellwig | 9ffb83b | 2005-11-12 12:11:12 -0800 | [diff] [blame] | 53 | #ifdef CONFIG_COMPAT |
| 54 | .fb_compat_ioctl = sbusfb_compat_ioctl, |
| 55 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | #define LEO_OFF_LC_SS0_KRN 0x00200000UL |
| 59 | #define LEO_OFF_LC_SS0_USR 0x00201000UL |
| 60 | #define LEO_OFF_LC_SS1_KRN 0x01200000UL |
| 61 | #define LEO_OFF_LC_SS1_USR 0x01201000UL |
| 62 | #define LEO_OFF_LD_SS0 0x00400000UL |
| 63 | #define LEO_OFF_LD_SS1 0x01400000UL |
| 64 | #define LEO_OFF_LD_GBL 0x00401000UL |
| 65 | #define LEO_OFF_LX_KRN 0x00600000UL |
| 66 | #define LEO_OFF_LX_CURSOR 0x00601000UL |
| 67 | #define LEO_OFF_SS0 0x00800000UL |
| 68 | #define LEO_OFF_SS1 0x01800000UL |
| 69 | #define LEO_OFF_UNK 0x00602000UL |
| 70 | #define LEO_OFF_UNK2 0x00000000UL |
| 71 | |
| 72 | #define LEO_CUR_ENABLE 0x00000080 |
| 73 | #define LEO_CUR_UPDATE 0x00000030 |
| 74 | #define LEO_CUR_PROGRESS 0x00000006 |
| 75 | #define LEO_CUR_UPDATECMAP 0x00000003 |
| 76 | |
| 77 | #define LEO_CUR_TYPE_MASK 0x00000000 |
| 78 | #define LEO_CUR_TYPE_IMAGE 0x00000020 |
| 79 | #define LEO_CUR_TYPE_CMAP 0x00000050 |
| 80 | |
| 81 | struct leo_cursor { |
| 82 | u8 xxx0[16]; |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 83 | u32 cur_type; |
| 84 | u32 cur_misc; |
| 85 | u32 cur_cursxy; |
| 86 | u32 cur_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | #define LEO_KRN_TYPE_CLUT0 0x00001000 |
| 90 | #define LEO_KRN_TYPE_CLUT1 0x00001001 |
| 91 | #define LEO_KRN_TYPE_CLUT2 0x00001002 |
| 92 | #define LEO_KRN_TYPE_WID 0x00001003 |
| 93 | #define LEO_KRN_TYPE_UNK 0x00001006 |
| 94 | #define LEO_KRN_TYPE_VIDEO 0x00002003 |
| 95 | #define LEO_KRN_TYPE_CLUTDATA 0x00004000 |
| 96 | #define LEO_KRN_CSR_ENABLE 0x00000008 |
| 97 | #define LEO_KRN_CSR_PROGRESS 0x00000004 |
| 98 | #define LEO_KRN_CSR_UNK 0x00000002 |
| 99 | #define LEO_KRN_CSR_UNK2 0x00000001 |
| 100 | |
| 101 | struct leo_lx_krn { |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 102 | u32 krn_type; |
| 103 | u32 krn_csr; |
| 104 | u32 krn_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | struct leo_lc_ss0_krn { |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 108 | u32 misc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | u8 xxx0[0x800-4]; |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 110 | u32 rev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | struct leo_lc_ss0_usr { |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 114 | u32 csr; |
| 115 | u32 addrspace; |
| 116 | u32 fontmsk; |
| 117 | u32 fontt; |
| 118 | u32 extent; |
| 119 | u32 src; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | u32 dst; |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 121 | u32 copy; |
| 122 | u32 fill; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | struct leo_lc_ss1_krn { |
| 126 | u8 unknown; |
| 127 | }; |
| 128 | |
| 129 | struct leo_lc_ss1_usr { |
| 130 | u8 unknown; |
| 131 | }; |
| 132 | |
| 133 | struct leo_ld { |
| 134 | u8 xxx0[0xe00]; |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 135 | u32 csr; |
| 136 | u32 wid; |
| 137 | u32 wmask; |
| 138 | u32 widclip; |
| 139 | u32 vclipmin; |
| 140 | u32 vclipmax; |
| 141 | u32 pickmin; /* SS1 only */ |
| 142 | u32 pickmax; /* SS1 only */ |
| 143 | u32 fg; |
| 144 | u32 bg; |
| 145 | u32 src; /* Copy/Scroll (SS0 only) */ |
| 146 | u32 dst; /* Copy/Scroll/Fill (SS0 only) */ |
| 147 | u32 extent; /* Copy/Scroll/Fill size (SS0 only) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | u32 xxx1[3]; |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 149 | u32 setsem; /* SS1 only */ |
| 150 | u32 clrsem; /* SS1 only */ |
| 151 | u32 clrpick; /* SS1 only */ |
| 152 | u32 clrdat; /* SS1 only */ |
| 153 | u32 alpha; /* SS1 only */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | u8 xxx2[0x2c]; |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 155 | u32 winbg; |
| 156 | u32 planemask; |
| 157 | u32 rop; |
| 158 | u32 z; |
| 159 | u32 dczf; /* SS1 only */ |
| 160 | u32 dczb; /* SS1 only */ |
| 161 | u32 dcs; /* SS1 only */ |
| 162 | u32 dczs; /* SS1 only */ |
| 163 | u32 pickfb; /* SS1 only */ |
| 164 | u32 pickbb; /* SS1 only */ |
| 165 | u32 dcfc; /* SS1 only */ |
| 166 | u32 forcecol; /* SS1 only */ |
| 167 | u32 door[8]; /* SS1 only */ |
| 168 | u32 pick[5]; /* SS1 only */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | }; |
| 170 | |
| 171 | #define LEO_SS1_MISC_ENABLE 0x00000001 |
| 172 | #define LEO_SS1_MISC_STEREO 0x00000002 |
| 173 | struct leo_ld_ss1 { |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 174 | u8 xxx0[0xef4]; |
| 175 | u32 ss1_misc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | }; |
| 177 | |
| 178 | struct leo_ld_gbl { |
| 179 | u8 unknown; |
| 180 | }; |
| 181 | |
| 182 | struct leo_par { |
| 183 | spinlock_t lock; |
| 184 | struct leo_lx_krn __iomem *lx_krn; |
| 185 | struct leo_lc_ss0_usr __iomem *lc_ss0_usr; |
| 186 | struct leo_ld_ss0 __iomem *ld_ss0; |
| 187 | struct leo_ld_ss1 __iomem *ld_ss1; |
| 188 | struct leo_cursor __iomem *cursor; |
| 189 | u32 extent; |
| 190 | u32 clut_data[256]; |
| 191 | |
| 192 | u32 flags; |
| 193 | #define LEO_FLAG_BLANKED 0x00000001 |
| 194 | |
| 195 | unsigned long physbase; |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 196 | unsigned long which_io; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | unsigned long fbsize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | }; |
| 199 | |
| 200 | static void leo_wait(struct leo_lx_krn __iomem *lx_krn) |
| 201 | { |
| 202 | int i; |
| 203 | |
| 204 | for (i = 0; |
| 205 | (sbus_readl(&lx_krn->krn_csr) & LEO_KRN_CSR_PROGRESS) && i < 300000; |
| 206 | i++) |
| 207 | udelay (1); /* Busy wait at most 0.3 sec */ |
| 208 | return; |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * leo_setcolreg - Optional function. Sets a color register. |
| 213 | * @regno: boolean, 0 copy local, 1 get_user() function |
| 214 | * @red: frame buffer colormap structure |
| 215 | * @green: The green value which can be up to 16 bits wide |
| 216 | * @blue: The blue value which can be up to 16 bits wide. |
| 217 | * @transp: If supported the alpha value which can be up to 16 bits wide. |
| 218 | * @info: frame buffer info structure |
| 219 | */ |
| 220 | static int leo_setcolreg(unsigned regno, |
| 221 | unsigned red, unsigned green, unsigned blue, |
| 222 | unsigned transp, struct fb_info *info) |
| 223 | { |
| 224 | struct leo_par *par = (struct leo_par *) info->par; |
| 225 | struct leo_lx_krn __iomem *lx_krn = par->lx_krn; |
| 226 | unsigned long flags; |
| 227 | u32 val; |
| 228 | int i; |
| 229 | |
| 230 | if (regno >= 256) |
| 231 | return 1; |
| 232 | |
| 233 | red >>= 8; |
| 234 | green >>= 8; |
| 235 | blue >>= 8; |
| 236 | |
| 237 | par->clut_data[regno] = red | (green << 8) | (blue << 16); |
| 238 | |
| 239 | spin_lock_irqsave(&par->lock, flags); |
| 240 | |
| 241 | leo_wait(lx_krn); |
| 242 | |
| 243 | sbus_writel(LEO_KRN_TYPE_CLUTDATA, &lx_krn->krn_type); |
| 244 | for (i = 0; i < 256; i++) |
| 245 | sbus_writel(par->clut_data[i], &lx_krn->krn_value); |
| 246 | sbus_writel(LEO_KRN_TYPE_CLUT0, &lx_krn->krn_type); |
| 247 | |
| 248 | val = sbus_readl(&lx_krn->krn_csr); |
| 249 | val |= (LEO_KRN_CSR_UNK | LEO_KRN_CSR_UNK2); |
| 250 | sbus_writel(val, &lx_krn->krn_csr); |
| 251 | |
| 252 | spin_unlock_irqrestore(&par->lock, flags); |
| 253 | |
| 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * leo_blank - Optional function. Blanks the display. |
| 259 | * @blank_mode: the blank mode we want. |
| 260 | * @info: frame buffer structure that represents a single frame buffer |
| 261 | */ |
| 262 | static int leo_blank(int blank, struct fb_info *info) |
| 263 | { |
| 264 | struct leo_par *par = (struct leo_par *) info->par; |
| 265 | struct leo_lx_krn __iomem *lx_krn = par->lx_krn; |
| 266 | unsigned long flags; |
| 267 | u32 val; |
| 268 | |
| 269 | spin_lock_irqsave(&par->lock, flags); |
| 270 | |
| 271 | switch (blank) { |
| 272 | case FB_BLANK_UNBLANK: /* Unblanking */ |
| 273 | val = sbus_readl(&lx_krn->krn_csr); |
| 274 | val |= LEO_KRN_CSR_ENABLE; |
| 275 | sbus_writel(val, &lx_krn->krn_csr); |
| 276 | par->flags &= ~LEO_FLAG_BLANKED; |
| 277 | break; |
| 278 | |
| 279 | case FB_BLANK_NORMAL: /* Normal blanking */ |
| 280 | case FB_BLANK_VSYNC_SUSPEND: /* VESA blank (vsync off) */ |
| 281 | case FB_BLANK_HSYNC_SUSPEND: /* VESA blank (hsync off) */ |
| 282 | case FB_BLANK_POWERDOWN: /* Poweroff */ |
| 283 | val = sbus_readl(&lx_krn->krn_csr); |
| 284 | val &= ~LEO_KRN_CSR_ENABLE; |
| 285 | sbus_writel(val, &lx_krn->krn_csr); |
| 286 | par->flags |= LEO_FLAG_BLANKED; |
| 287 | break; |
| 288 | } |
| 289 | |
| 290 | spin_unlock_irqrestore(&par->lock, flags); |
| 291 | |
| 292 | return 0; |
| 293 | } |
| 294 | |
| 295 | static struct sbus_mmap_map leo_mmap_map[] = { |
| 296 | { |
| 297 | .voff = LEO_SS0_MAP, |
| 298 | .poff = LEO_OFF_SS0, |
| 299 | .size = 0x800000 |
| 300 | }, |
| 301 | { |
| 302 | .voff = LEO_LC_SS0_USR_MAP, |
| 303 | .poff = LEO_OFF_LC_SS0_USR, |
| 304 | .size = 0x1000 |
| 305 | }, |
| 306 | { |
| 307 | .voff = LEO_LD_SS0_MAP, |
| 308 | .poff = LEO_OFF_LD_SS0, |
| 309 | .size = 0x1000 |
| 310 | }, |
| 311 | { |
| 312 | .voff = LEO_LX_CURSOR_MAP, |
| 313 | .poff = LEO_OFF_LX_CURSOR, |
| 314 | .size = 0x1000 |
| 315 | }, |
| 316 | { |
| 317 | .voff = LEO_SS1_MAP, |
| 318 | .poff = LEO_OFF_SS1, |
| 319 | .size = 0x800000 |
| 320 | }, |
| 321 | { |
| 322 | .voff = LEO_LC_SS1_USR_MAP, |
| 323 | .poff = LEO_OFF_LC_SS1_USR, |
| 324 | .size = 0x1000 |
| 325 | }, |
| 326 | { |
| 327 | .voff = LEO_LD_SS1_MAP, |
| 328 | .poff = LEO_OFF_LD_SS1, |
| 329 | .size = 0x1000 |
| 330 | }, |
| 331 | { |
| 332 | .voff = LEO_UNK_MAP, |
| 333 | .poff = LEO_OFF_UNK, |
| 334 | .size = 0x1000 |
| 335 | }, |
| 336 | { |
| 337 | .voff = LEO_LX_KRN_MAP, |
| 338 | .poff = LEO_OFF_LX_KRN, |
| 339 | .size = 0x1000 |
| 340 | }, |
| 341 | { |
| 342 | .voff = LEO_LC_SS0_KRN_MAP, |
| 343 | .poff = LEO_OFF_LC_SS0_KRN, |
| 344 | .size = 0x1000 |
| 345 | }, |
| 346 | { |
| 347 | .voff = LEO_LC_SS1_KRN_MAP, |
| 348 | .poff = LEO_OFF_LC_SS1_KRN, |
| 349 | .size = 0x1000 |
| 350 | }, |
| 351 | { |
| 352 | .voff = LEO_LD_GBL_MAP, |
| 353 | .poff = LEO_OFF_LD_GBL, |
| 354 | .size = 0x1000 |
| 355 | }, |
| 356 | { |
| 357 | .voff = LEO_UNK2_MAP, |
| 358 | .poff = LEO_OFF_UNK2, |
| 359 | .size = 0x100000 |
| 360 | }, |
| 361 | { .size = 0 } |
| 362 | }; |
| 363 | |
Christoph Hellwig | 216d526 | 2006-01-14 13:21:25 -0800 | [diff] [blame] | 364 | static int leo_mmap(struct fb_info *info, struct vm_area_struct *vma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | { |
| 366 | struct leo_par *par = (struct leo_par *)info->par; |
| 367 | |
| 368 | return sbusfb_mmap_helper(leo_mmap_map, |
| 369 | par->physbase, par->fbsize, |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 370 | par->which_io, vma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | } |
| 372 | |
Christoph Hellwig | 67a6680 | 2006-01-14 13:21:25 -0800 | [diff] [blame] | 373 | static int leo_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | { |
| 375 | struct leo_par *par = (struct leo_par *) info->par; |
| 376 | |
| 377 | return sbusfb_ioctl_helper(cmd, arg, info, |
| 378 | FBTYPE_SUNLEO, 32, par->fbsize); |
| 379 | } |
| 380 | |
| 381 | /* |
| 382 | * Initialisation |
| 383 | */ |
| 384 | |
| 385 | static void |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 386 | leo_init_fix(struct fb_info *info, struct device_node *dp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | { |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 388 | strlcpy(info->fix.id, dp->name, sizeof(info->fix.id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | |
| 390 | info->fix.type = FB_TYPE_PACKED_PIXELS; |
| 391 | info->fix.visual = FB_VISUAL_TRUECOLOR; |
| 392 | |
| 393 | info->fix.line_length = 8192; |
| 394 | |
| 395 | info->fix.accel = FB_ACCEL_SUN_LEO; |
| 396 | } |
| 397 | |
| 398 | static void leo_wid_put(struct fb_info *info, struct fb_wid_list *wl) |
| 399 | { |
| 400 | struct leo_par *par = (struct leo_par *) info->par; |
| 401 | struct leo_lx_krn __iomem *lx_krn = par->lx_krn; |
| 402 | struct fb_wid_item *wi; |
| 403 | unsigned long flags; |
| 404 | u32 val; |
| 405 | int i, j; |
| 406 | |
| 407 | spin_lock_irqsave(&par->lock, flags); |
| 408 | |
| 409 | leo_wait(lx_krn); |
| 410 | |
| 411 | for (i = 0, wi = wl->wl_list; i < wl->wl_count; i++, wi++) { |
| 412 | switch(wi->wi_type) { |
| 413 | case FB_WID_DBL_8: |
| 414 | j = (wi->wi_index & 0xf) + 0x40; |
| 415 | break; |
| 416 | |
| 417 | case FB_WID_DBL_24: |
| 418 | j = wi->wi_index & 0x3f; |
| 419 | break; |
| 420 | |
| 421 | default: |
| 422 | continue; |
| 423 | }; |
| 424 | sbus_writel(0x5800 + j, &lx_krn->krn_type); |
| 425 | sbus_writel(wi->wi_values[0], &lx_krn->krn_value); |
| 426 | } |
| 427 | sbus_writel(LEO_KRN_TYPE_WID, &lx_krn->krn_type); |
| 428 | |
| 429 | val = sbus_readl(&lx_krn->krn_csr); |
| 430 | val |= (LEO_KRN_CSR_UNK | LEO_KRN_CSR_UNK2); |
| 431 | sbus_writel(val, &lx_krn->krn_csr); |
| 432 | |
| 433 | spin_unlock_irqrestore(&par->lock, flags); |
| 434 | } |
| 435 | |
| 436 | static void leo_init_wids(struct fb_info *info) |
| 437 | { |
| 438 | struct fb_wid_item wi; |
| 439 | struct fb_wid_list wl; |
| 440 | |
| 441 | wl.wl_count = 1; |
| 442 | wl.wl_list = &wi; |
| 443 | wi.wi_type = FB_WID_DBL_8; |
| 444 | wi.wi_index = 0; |
| 445 | wi.wi_values [0] = 0x2c0; |
| 446 | leo_wid_put(info, &wl); |
| 447 | wi.wi_index = 1; |
| 448 | wi.wi_values [0] = 0x30; |
| 449 | leo_wid_put(info, &wl); |
| 450 | wi.wi_index = 2; |
| 451 | wi.wi_values [0] = 0x20; |
| 452 | leo_wid_put(info, &wl); |
| 453 | wi.wi_type = FB_WID_DBL_24; |
| 454 | wi.wi_index = 1; |
| 455 | wi.wi_values [0] = 0x30; |
| 456 | leo_wid_put(info, &wl); |
| 457 | |
| 458 | } |
| 459 | |
| 460 | static void leo_switch_from_graph(struct fb_info *info) |
| 461 | { |
| 462 | struct leo_par *par = (struct leo_par *) info->par; |
| 463 | struct leo_ld __iomem *ss = (struct leo_ld __iomem *) par->ld_ss0; |
| 464 | unsigned long flags; |
| 465 | u32 val; |
| 466 | |
| 467 | spin_lock_irqsave(&par->lock, flags); |
| 468 | |
| 469 | par->extent = ((info->var.xres - 1) | |
| 470 | ((info->var.yres - 1) << 16)); |
| 471 | |
| 472 | sbus_writel(0xffffffff, &ss->wid); |
| 473 | sbus_writel(0xffff, &ss->wmask); |
| 474 | sbus_writel(0, &ss->vclipmin); |
| 475 | sbus_writel(par->extent, &ss->vclipmax); |
| 476 | sbus_writel(0, &ss->fg); |
| 477 | sbus_writel(0xff000000, &ss->planemask); |
| 478 | sbus_writel(0x310850, &ss->rop); |
| 479 | sbus_writel(0, &ss->widclip); |
| 480 | sbus_writel((info->var.xres-1) | ((info->var.yres-1) << 11), |
| 481 | &par->lc_ss0_usr->extent); |
| 482 | sbus_writel(4, &par->lc_ss0_usr->addrspace); |
| 483 | sbus_writel(0x80000000, &par->lc_ss0_usr->fill); |
| 484 | sbus_writel(0, &par->lc_ss0_usr->fontt); |
| 485 | do { |
| 486 | val = sbus_readl(&par->lc_ss0_usr->csr); |
| 487 | } while (val & 0x20000000); |
| 488 | |
| 489 | spin_unlock_irqrestore(&par->lock, flags); |
| 490 | } |
| 491 | |
| 492 | static int leo_pan_display(struct fb_var_screeninfo *var, struct fb_info *info) |
| 493 | { |
| 494 | /* We just use this to catch switches out of |
| 495 | * graphics mode. |
| 496 | */ |
| 497 | leo_switch_from_graph(info); |
| 498 | |
| 499 | if (var->xoffset || var->yoffset || var->vmode) |
| 500 | return -EINVAL; |
| 501 | return 0; |
| 502 | } |
| 503 | |
| 504 | static void leo_init_hw(struct fb_info *info) |
| 505 | { |
| 506 | struct leo_par *par = (struct leo_par *) info->par; |
| 507 | u32 val; |
| 508 | |
| 509 | val = sbus_readl(&par->ld_ss1->ss1_misc); |
| 510 | val |= LEO_SS1_MISC_ENABLE; |
| 511 | sbus_writel(val, &par->ld_ss1->ss1_misc); |
| 512 | |
| 513 | leo_switch_from_graph(info); |
| 514 | } |
| 515 | |
| 516 | static void leo_fixup_var_rgb(struct fb_var_screeninfo *var) |
| 517 | { |
| 518 | var->red.offset = 0; |
| 519 | var->red.length = 8; |
| 520 | var->green.offset = 8; |
| 521 | var->green.length = 8; |
| 522 | var->blue.offset = 16; |
| 523 | var->blue.length = 8; |
| 524 | var->transp.offset = 0; |
| 525 | var->transp.length = 0; |
| 526 | } |
| 527 | |
David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame^] | 528 | static void leo_unmap_regs(struct of_device *op, struct fb_info *info, |
| 529 | struct leo_par *par) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | { |
David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame^] | 531 | if (par->lc_ss0_usr) |
| 532 | of_iounmap(&op->resource[0], par->lc_ss0_usr, 0x1000); |
| 533 | if (par->ld_ss0) |
| 534 | of_iounmap(&op->resource[0], par->ld_ss0, 0x1000); |
| 535 | if (par->ld_ss1) |
| 536 | of_iounmap(&op->resource[0], par->ld_ss1, 0x1000); |
| 537 | if (par->lx_krn) |
| 538 | of_iounmap(&op->resource[0], par->lx_krn, 0x1000); |
| 539 | if (par->cursor) |
David S. Miller | e3a411a3 | 2006-12-28 21:01:32 -0800 | [diff] [blame] | 540 | of_iounmap(&op->resource[0], |
David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame^] | 541 | par->cursor, sizeof(struct leo_cursor)); |
| 542 | if (info->screen_base) |
| 543 | of_iounmap(&op->resource[0], info->screen_base, 0x800000); |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 544 | } |
| 545 | |
David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame^] | 546 | static int __devinit leo_probe(struct of_device *op, const struct of_device_id *match) |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 547 | { |
| 548 | struct device_node *dp = op->node; |
David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame^] | 549 | struct fb_info *info; |
| 550 | struct leo_par *par; |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 551 | int linebytes, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | |
David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame^] | 553 | info = framebuffer_alloc(sizeof(struct leo_par), &op->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | |
David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame^] | 555 | err = -ENOMEM; |
| 556 | if (!info) |
| 557 | goto out_err; |
| 558 | par = info->par; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | |
David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame^] | 560 | spin_lock_init(&par->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | |
David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame^] | 562 | par->physbase = op->resource[0].start; |
| 563 | par->which_io = op->resource[0].flags & IORESOURCE_BITS; |
| 564 | |
| 565 | sbusfb_fill_var(&info->var, dp->node, 32); |
| 566 | leo_fixup_var_rgb(&info->var); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 568 | linebytes = of_getintprop_default(dp, "linebytes", |
David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame^] | 569 | info->var.xres); |
| 570 | par->fbsize = PAGE_ALIGN(linebytes * info->var.yres); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | |
David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame^] | 572 | par->lc_ss0_usr = |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 573 | of_ioremap(&op->resource[0], LEO_OFF_LC_SS0_USR, |
| 574 | 0x1000, "leolc ss0usr"); |
David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame^] | 575 | par->ld_ss0 = |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 576 | of_ioremap(&op->resource[0], LEO_OFF_LD_SS0, |
| 577 | 0x1000, "leold ss0"); |
David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame^] | 578 | par->ld_ss1 = |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 579 | of_ioremap(&op->resource[0], LEO_OFF_LD_SS1, |
| 580 | 0x1000, "leold ss1"); |
David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame^] | 581 | par->lx_krn = |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 582 | of_ioremap(&op->resource[0], LEO_OFF_LX_KRN, |
| 583 | 0x1000, "leolx krn"); |
David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame^] | 584 | par->cursor = |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 585 | of_ioremap(&op->resource[0], LEO_OFF_LX_CURSOR, |
| 586 | sizeof(struct leo_cursor), "leolx cursor"); |
David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame^] | 587 | info->screen_base = |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 588 | of_ioremap(&op->resource[0], LEO_OFF_SS0, |
| 589 | 0x800000, "leo ram"); |
David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame^] | 590 | if (!par->lc_ss0_usr || |
| 591 | !par->ld_ss0 || |
| 592 | !par->ld_ss1 || |
| 593 | !par->lx_krn || |
| 594 | !par->cursor || |
| 595 | !info->screen_base) |
| 596 | goto out_unmap_regs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | |
David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame^] | 598 | info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN; |
| 599 | info->fbops = &leo_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | |
David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame^] | 601 | leo_init_wids(info); |
| 602 | leo_init_hw(info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | |
David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame^] | 604 | leo_blank(0, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | |
David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame^] | 606 | if (fb_alloc_cmap(&info->cmap, 256, 0)) |
| 607 | goto out_unmap_regs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | |
David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame^] | 609 | leo_init_fix(info, dp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | |
David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame^] | 611 | err = register_framebuffer(info); |
| 612 | if (err < 0) |
| 613 | goto out_dealloc_cmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | |
David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame^] | 615 | dev_set_drvdata(&op->dev, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 617 | printk("%s: leo at %lx:%lx\n", |
| 618 | dp->full_name, |
David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame^] | 619 | par->which_io, par->physbase); |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 620 | |
| 621 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | |
David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame^] | 623 | out_dealloc_cmap: |
| 624 | fb_dealloc_cmap(&info->cmap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | |
David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame^] | 626 | out_unmap_regs: |
| 627 | leo_unmap_regs(op, info, par); |
| 628 | framebuffer_release(info); |
| 629 | |
| 630 | out_err: |
| 631 | return err; |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 632 | } |
| 633 | |
David S. Miller | e3a411a3 | 2006-12-28 21:01:32 -0800 | [diff] [blame] | 634 | static int __devexit leo_remove(struct of_device *op) |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 635 | { |
David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame^] | 636 | struct fb_info *info = dev_get_drvdata(&op->dev); |
| 637 | struct leo_par *par = info->par; |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 638 | |
David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame^] | 639 | unregister_framebuffer(info); |
| 640 | fb_dealloc_cmap(&info->cmap); |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 641 | |
David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame^] | 642 | leo_unmap_regs(op, info, par); |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 643 | |
David S. Miller | c7f439b | 2007-07-27 22:31:46 -0700 | [diff] [blame^] | 644 | framebuffer_release(info); |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 645 | |
David S. Miller | e3a411a3 | 2006-12-28 21:01:32 -0800 | [diff] [blame] | 646 | dev_set_drvdata(&op->dev, NULL); |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 647 | |
| 648 | return 0; |
| 649 | } |
| 650 | |
| 651 | static struct of_device_id leo_match[] = { |
| 652 | { |
| 653 | .name = "leo", |
| 654 | }, |
| 655 | {}, |
| 656 | }; |
| 657 | MODULE_DEVICE_TABLE(of, leo_match); |
| 658 | |
| 659 | static struct of_platform_driver leo_driver = { |
| 660 | .name = "leo", |
| 661 | .match_table = leo_match, |
| 662 | .probe = leo_probe, |
| 663 | .remove = __devexit_p(leo_remove), |
| 664 | }; |
| 665 | |
| 666 | static int __init leo_init(void) |
| 667 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | if (fb_get_options("leofb", NULL)) |
| 669 | return -ENODEV; |
| 670 | |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 671 | return of_register_driver(&leo_driver, &of_bus_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | } |
| 673 | |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 674 | static void __exit leo_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | { |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 676 | of_unregister_driver(&leo_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | module_init(leo_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | module_exit(leo_exit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | |
| 682 | MODULE_DESCRIPTION("framebuffer driver for LEO chipsets"); |
David S. Miller | 50312ce | 2006-06-29 14:35:52 -0700 | [diff] [blame] | 683 | MODULE_AUTHOR("David S. Miller <davem@davemloft.net>"); |
| 684 | MODULE_VERSION("2.0"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | MODULE_LICENSE("GPL"); |