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