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