Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/video/offb.c -- Open Firmware based frame buffer device |
| 3 | * |
| 4 | * Copyright (C) 1997 Geert Uytterhoeven |
| 5 | * |
| 6 | * This driver is partly based on the PowerMac console driver: |
| 7 | * |
| 8 | * Copyright (C) 1996 Paul Mackerras |
| 9 | * |
| 10 | * This file is subject to the terms and conditions of the GNU General Public |
| 11 | * License. See the file COPYING in the main directory of this archive for |
| 12 | * more details. |
| 13 | */ |
| 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/module.h> |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/errno.h> |
| 18 | #include <linux/string.h> |
| 19 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/vmalloc.h> |
| 21 | #include <linux/delay.h> |
Grant Likely | 22ae782 | 2010-07-29 11:49:01 -0600 | [diff] [blame] | 22 | #include <linux/of.h> |
| 23 | #include <linux/of_address.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/interrupt.h> |
| 25 | #include <linux/fb.h> |
| 26 | #include <linux/init.h> |
| 27 | #include <linux/ioport.h> |
Paul Mackerras | f365cfd | 2005-11-18 16:41:49 +1100 | [diff] [blame] | 28 | #include <linux/pci.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
| 31 | #ifdef CONFIG_PPC64 |
| 32 | #include <asm/pci-bridge.h> |
| 33 | #endif |
| 34 | |
| 35 | #ifdef CONFIG_PPC32 |
| 36 | #include <asm/bootx.h> |
| 37 | #endif |
| 38 | |
| 39 | #include "macmodes.h" |
| 40 | |
| 41 | /* Supported palette hacks */ |
| 42 | enum { |
| 43 | cmap_unknown, |
Benjamin Herrenschmidt | 9b961ed | 2011-12-14 13:58:29 +0000 | [diff] [blame] | 44 | cmap_simple, /* ATI Mach64 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | cmap_r128, /* ATI Rage128 */ |
| 46 | cmap_M3A, /* ATI Rage Mobility M3 Head A */ |
| 47 | cmap_M3B, /* ATI Rage Mobility M3 Head B */ |
| 48 | cmap_radeon, /* ATI Radeon */ |
| 49 | cmap_gxt2000, /* IBM GXT2000 */ |
Benjamin Herrenschmidt | 57a20d8 | 2008-07-17 15:05:22 +1000 | [diff] [blame] | 50 | cmap_avivo, /* ATI R5xx */ |
Benjamin Herrenschmidt | 9b961ed | 2011-12-14 13:58:29 +0000 | [diff] [blame] | 51 | cmap_qemu, /* qemu vga */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | struct offb_par { |
| 55 | volatile void __iomem *cmap_adr; |
| 56 | volatile void __iomem *cmap_data; |
| 57 | int cmap_type; |
| 58 | int blanked; |
| 59 | }; |
| 60 | |
| 61 | struct offb_par default_par; |
| 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | #ifdef CONFIG_PPC32 |
| 64 | extern boot_infos_t *boot_infos; |
| 65 | #endif |
| 66 | |
Benjamin Herrenschmidt | 57a20d8 | 2008-07-17 15:05:22 +1000 | [diff] [blame] | 67 | /* Definitions used by the Avivo palette hack */ |
| 68 | #define AVIVO_DC_LUT_RW_SELECT 0x6480 |
| 69 | #define AVIVO_DC_LUT_RW_MODE 0x6484 |
| 70 | #define AVIVO_DC_LUT_RW_INDEX 0x6488 |
| 71 | #define AVIVO_DC_LUT_SEQ_COLOR 0x648c |
| 72 | #define AVIVO_DC_LUT_PWL_DATA 0x6490 |
| 73 | #define AVIVO_DC_LUT_30_COLOR 0x6494 |
| 74 | #define AVIVO_DC_LUT_READ_PIPE_SELECT 0x6498 |
| 75 | #define AVIVO_DC_LUT_WRITE_EN_MASK 0x649c |
| 76 | #define AVIVO_DC_LUT_AUTOFILL 0x64a0 |
| 77 | |
| 78 | #define AVIVO_DC_LUTA_CONTROL 0x64c0 |
| 79 | #define AVIVO_DC_LUTA_BLACK_OFFSET_BLUE 0x64c4 |
| 80 | #define AVIVO_DC_LUTA_BLACK_OFFSET_GREEN 0x64c8 |
| 81 | #define AVIVO_DC_LUTA_BLACK_OFFSET_RED 0x64cc |
| 82 | #define AVIVO_DC_LUTA_WHITE_OFFSET_BLUE 0x64d0 |
| 83 | #define AVIVO_DC_LUTA_WHITE_OFFSET_GREEN 0x64d4 |
| 84 | #define AVIVO_DC_LUTA_WHITE_OFFSET_RED 0x64d8 |
| 85 | |
| 86 | #define AVIVO_DC_LUTB_CONTROL 0x6cc0 |
| 87 | #define AVIVO_DC_LUTB_BLACK_OFFSET_BLUE 0x6cc4 |
| 88 | #define AVIVO_DC_LUTB_BLACK_OFFSET_GREEN 0x6cc8 |
| 89 | #define AVIVO_DC_LUTB_BLACK_OFFSET_RED 0x6ccc |
| 90 | #define AVIVO_DC_LUTB_WHITE_OFFSET_BLUE 0x6cd0 |
| 91 | #define AVIVO_DC_LUTB_WHITE_OFFSET_GREEN 0x6cd4 |
| 92 | #define AVIVO_DC_LUTB_WHITE_OFFSET_RED 0x6cd8 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
| 94 | /* |
| 95 | * Set a single color register. The values supplied are already |
| 96 | * rounded down to the hardware's capabilities (according to the |
| 97 | * entries in the var structure). Return != 0 for invalid regno. |
| 98 | */ |
| 99 | |
| 100 | static int offb_setcolreg(u_int regno, u_int red, u_int green, u_int blue, |
| 101 | u_int transp, struct fb_info *info) |
| 102 | { |
| 103 | struct offb_par *par = (struct offb_par *) info->par; |
| 104 | |
Benjamin Herrenschmidt | 1bb0b7d | 2011-12-28 00:10:16 +0000 | [diff] [blame] | 105 | if (info->fix.visual == FB_VISUAL_TRUECOLOR) { |
| 106 | u32 *pal = info->pseudo_palette; |
| 107 | u32 cr = red >> (16 - info->var.red.length); |
| 108 | u32 cg = green >> (16 - info->var.green.length); |
| 109 | u32 cb = blue >> (16 - info->var.blue.length); |
| 110 | u32 value; |
Benjamin Herrenschmidt | ab13446 | 2006-07-03 17:19:48 +1000 | [diff] [blame] | 111 | |
Benjamin Herrenschmidt | 1bb0b7d | 2011-12-28 00:10:16 +0000 | [diff] [blame] | 112 | if (regno >= 16) |
| 113 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
Benjamin Herrenschmidt | 1bb0b7d | 2011-12-28 00:10:16 +0000 | [diff] [blame] | 115 | value = (cr << info->var.red.offset) | |
| 116 | (cg << info->var.green.offset) | |
| 117 | (cb << info->var.blue.offset); |
| 118 | if (info->var.transp.length > 0) { |
| 119 | u32 mask = (1 << info->var.transp.length) - 1; |
| 120 | mask <<= info->var.transp.offset; |
| 121 | value |= mask; |
Benjamin Herrenschmidt | ab13446 | 2006-07-03 17:19:48 +1000 | [diff] [blame] | 122 | } |
Benjamin Herrenschmidt | 1bb0b7d | 2011-12-28 00:10:16 +0000 | [diff] [blame] | 123 | pal[regno] = value; |
| 124 | return 0; |
Benjamin Herrenschmidt | ab13446 | 2006-07-03 17:19:48 +1000 | [diff] [blame] | 125 | } |
| 126 | |
Benjamin Herrenschmidt | 1bb0b7d | 2011-12-28 00:10:16 +0000 | [diff] [blame] | 127 | if (regno > 255) |
| 128 | return -EINVAL; |
| 129 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | red >>= 8; |
| 131 | green >>= 8; |
| 132 | blue >>= 8; |
| 133 | |
Benjamin Herrenschmidt | ab13446 | 2006-07-03 17:19:48 +1000 | [diff] [blame] | 134 | if (!par->cmap_adr) |
| 135 | return 0; |
| 136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | switch (par->cmap_type) { |
Benjamin Herrenschmidt | 9b961ed | 2011-12-14 13:58:29 +0000 | [diff] [blame] | 138 | case cmap_simple: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | writeb(regno, par->cmap_adr); |
| 140 | writeb(red, par->cmap_data); |
| 141 | writeb(green, par->cmap_data); |
| 142 | writeb(blue, par->cmap_data); |
| 143 | break; |
| 144 | case cmap_M3A: |
| 145 | /* Clear PALETTE_ACCESS_CNTL in DAC_CNTL */ |
| 146 | out_le32(par->cmap_adr + 0x58, |
| 147 | in_le32(par->cmap_adr + 0x58) & ~0x20); |
| 148 | case cmap_r128: |
| 149 | /* Set palette index & data */ |
| 150 | out_8(par->cmap_adr + 0xb0, regno); |
| 151 | out_le32(par->cmap_adr + 0xb4, |
| 152 | (red << 16 | green << 8 | blue)); |
| 153 | break; |
| 154 | case cmap_M3B: |
| 155 | /* Set PALETTE_ACCESS_CNTL in DAC_CNTL */ |
| 156 | out_le32(par->cmap_adr + 0x58, |
| 157 | in_le32(par->cmap_adr + 0x58) | 0x20); |
| 158 | /* Set palette index & data */ |
| 159 | out_8(par->cmap_adr + 0xb0, regno); |
| 160 | out_le32(par->cmap_adr + 0xb4, (red << 16 | green << 8 | blue)); |
| 161 | break; |
| 162 | case cmap_radeon: |
| 163 | /* Set palette index & data (could be smarter) */ |
| 164 | out_8(par->cmap_adr + 0xb0, regno); |
| 165 | out_le32(par->cmap_adr + 0xb4, (red << 16 | green << 8 | blue)); |
| 166 | break; |
| 167 | case cmap_gxt2000: |
Benjamin Herrenschmidt | 441cbd8 | 2006-10-26 15:38:10 +1000 | [diff] [blame] | 168 | out_le32(((unsigned __iomem *) par->cmap_adr) + regno, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | (red << 16 | green << 8 | blue)); |
| 170 | break; |
Benjamin Herrenschmidt | 57a20d8 | 2008-07-17 15:05:22 +1000 | [diff] [blame] | 171 | case cmap_avivo: |
| 172 | /* Write to both LUTs for now */ |
| 173 | writel(1, par->cmap_adr + AVIVO_DC_LUT_RW_SELECT); |
| 174 | writeb(regno, par->cmap_adr + AVIVO_DC_LUT_RW_INDEX); |
| 175 | writel(((red) << 22) | ((green) << 12) | ((blue) << 2), |
| 176 | par->cmap_adr + AVIVO_DC_LUT_30_COLOR); |
| 177 | writel(0, par->cmap_adr + AVIVO_DC_LUT_RW_SELECT); |
| 178 | writeb(regno, par->cmap_adr + AVIVO_DC_LUT_RW_INDEX); |
| 179 | writel(((red) << 22) | ((green) << 12) | ((blue) << 2), |
| 180 | par->cmap_adr + AVIVO_DC_LUT_30_COLOR); |
| 181 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | } |
| 183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | /* |
| 188 | * Blank the display. |
| 189 | */ |
| 190 | |
| 191 | static int offb_blank(int blank, struct fb_info *info) |
| 192 | { |
| 193 | struct offb_par *par = (struct offb_par *) info->par; |
| 194 | int i, j; |
| 195 | |
| 196 | if (!par->cmap_adr) |
| 197 | return 0; |
| 198 | |
| 199 | if (!par->blanked) |
| 200 | if (!blank) |
| 201 | return 0; |
| 202 | |
| 203 | par->blanked = blank; |
| 204 | |
| 205 | if (blank) |
| 206 | for (i = 0; i < 256; i++) { |
| 207 | switch (par->cmap_type) { |
Benjamin Herrenschmidt | 9b961ed | 2011-12-14 13:58:29 +0000 | [diff] [blame] | 208 | case cmap_simple: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | writeb(i, par->cmap_adr); |
| 210 | for (j = 0; j < 3; j++) |
| 211 | writeb(0, par->cmap_data); |
| 212 | break; |
| 213 | case cmap_M3A: |
| 214 | /* Clear PALETTE_ACCESS_CNTL in DAC_CNTL */ |
| 215 | out_le32(par->cmap_adr + 0x58, |
| 216 | in_le32(par->cmap_adr + 0x58) & ~0x20); |
| 217 | case cmap_r128: |
| 218 | /* Set palette index & data */ |
| 219 | out_8(par->cmap_adr + 0xb0, i); |
| 220 | out_le32(par->cmap_adr + 0xb4, 0); |
| 221 | break; |
| 222 | case cmap_M3B: |
| 223 | /* Set PALETTE_ACCESS_CNTL in DAC_CNTL */ |
| 224 | out_le32(par->cmap_adr + 0x58, |
| 225 | in_le32(par->cmap_adr + 0x58) | 0x20); |
| 226 | /* Set palette index & data */ |
| 227 | out_8(par->cmap_adr + 0xb0, i); |
| 228 | out_le32(par->cmap_adr + 0xb4, 0); |
| 229 | break; |
| 230 | case cmap_radeon: |
| 231 | out_8(par->cmap_adr + 0xb0, i); |
| 232 | out_le32(par->cmap_adr + 0xb4, 0); |
| 233 | break; |
| 234 | case cmap_gxt2000: |
Benjamin Herrenschmidt | 441cbd8 | 2006-10-26 15:38:10 +1000 | [diff] [blame] | 235 | out_le32(((unsigned __iomem *) par->cmap_adr) + i, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | 0); |
| 237 | break; |
Benjamin Herrenschmidt | 57a20d8 | 2008-07-17 15:05:22 +1000 | [diff] [blame] | 238 | case cmap_avivo: |
| 239 | writel(1, par->cmap_adr + AVIVO_DC_LUT_RW_SELECT); |
| 240 | writeb(i, par->cmap_adr + AVIVO_DC_LUT_RW_INDEX); |
| 241 | writel(0, par->cmap_adr + AVIVO_DC_LUT_30_COLOR); |
| 242 | writel(0, par->cmap_adr + AVIVO_DC_LUT_RW_SELECT); |
| 243 | writeb(i, par->cmap_adr + AVIVO_DC_LUT_RW_INDEX); |
| 244 | writel(0, par->cmap_adr + AVIVO_DC_LUT_30_COLOR); |
| 245 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | } |
| 247 | } else |
| 248 | fb_set_cmap(&info->cmap, info); |
| 249 | return 0; |
| 250 | } |
| 251 | |
Benjamin Herrenschmidt | 57a20d8 | 2008-07-17 15:05:22 +1000 | [diff] [blame] | 252 | static int offb_set_par(struct fb_info *info) |
| 253 | { |
| 254 | struct offb_par *par = (struct offb_par *) info->par; |
| 255 | |
| 256 | /* On avivo, initialize palette control */ |
| 257 | if (par->cmap_type == cmap_avivo) { |
| 258 | writel(0, par->cmap_adr + AVIVO_DC_LUTA_CONTROL); |
| 259 | writel(0, par->cmap_adr + AVIVO_DC_LUTA_BLACK_OFFSET_BLUE); |
| 260 | writel(0, par->cmap_adr + AVIVO_DC_LUTA_BLACK_OFFSET_GREEN); |
| 261 | writel(0, par->cmap_adr + AVIVO_DC_LUTA_BLACK_OFFSET_RED); |
| 262 | writel(0x0000ffff, par->cmap_adr + AVIVO_DC_LUTA_WHITE_OFFSET_BLUE); |
| 263 | writel(0x0000ffff, par->cmap_adr + AVIVO_DC_LUTA_WHITE_OFFSET_GREEN); |
| 264 | writel(0x0000ffff, par->cmap_adr + AVIVO_DC_LUTA_WHITE_OFFSET_RED); |
| 265 | writel(0, par->cmap_adr + AVIVO_DC_LUTB_CONTROL); |
| 266 | writel(0, par->cmap_adr + AVIVO_DC_LUTB_BLACK_OFFSET_BLUE); |
| 267 | writel(0, par->cmap_adr + AVIVO_DC_LUTB_BLACK_OFFSET_GREEN); |
| 268 | writel(0, par->cmap_adr + AVIVO_DC_LUTB_BLACK_OFFSET_RED); |
| 269 | writel(0x0000ffff, par->cmap_adr + AVIVO_DC_LUTB_WHITE_OFFSET_BLUE); |
| 270 | writel(0x0000ffff, par->cmap_adr + AVIVO_DC_LUTB_WHITE_OFFSET_GREEN); |
| 271 | writel(0x0000ffff, par->cmap_adr + AVIVO_DC_LUTB_WHITE_OFFSET_RED); |
| 272 | writel(1, par->cmap_adr + AVIVO_DC_LUT_RW_SELECT); |
| 273 | writel(0, par->cmap_adr + AVIVO_DC_LUT_RW_MODE); |
| 274 | writel(0x0000003f, par->cmap_adr + AVIVO_DC_LUT_WRITE_EN_MASK); |
| 275 | writel(0, par->cmap_adr + AVIVO_DC_LUT_RW_SELECT); |
| 276 | writel(0, par->cmap_adr + AVIVO_DC_LUT_RW_MODE); |
| 277 | writel(0x0000003f, par->cmap_adr + AVIVO_DC_LUT_WRITE_EN_MASK); |
| 278 | } |
| 279 | return 0; |
| 280 | } |
| 281 | |
Dave Airlie | ceae8cb | 2009-12-06 20:01:26 +0000 | [diff] [blame] | 282 | static void offb_destroy(struct fb_info *info) |
| 283 | { |
| 284 | if (info->screen_base) |
| 285 | iounmap(info->screen_base); |
Marcin Slusarz | 1471ca9 | 2010-05-16 17:27:03 +0200 | [diff] [blame] | 286 | release_mem_region(info->apertures->ranges[0].base, info->apertures->ranges[0].size); |
Dave Airlie | ceae8cb | 2009-12-06 20:01:26 +0000 | [diff] [blame] | 287 | framebuffer_release(info); |
| 288 | } |
| 289 | |
Benjamin Herrenschmidt | 57a20d8 | 2008-07-17 15:05:22 +1000 | [diff] [blame] | 290 | static struct fb_ops offb_ops = { |
| 291 | .owner = THIS_MODULE, |
Dave Airlie | ceae8cb | 2009-12-06 20:01:26 +0000 | [diff] [blame] | 292 | .fb_destroy = offb_destroy, |
Benjamin Herrenschmidt | 57a20d8 | 2008-07-17 15:05:22 +1000 | [diff] [blame] | 293 | .fb_setcolreg = offb_setcolreg, |
| 294 | .fb_set_par = offb_set_par, |
| 295 | .fb_blank = offb_blank, |
| 296 | .fb_fillrect = cfb_fillrect, |
| 297 | .fb_copyarea = cfb_copyarea, |
| 298 | .fb_imageblit = cfb_imageblit, |
| 299 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
Benjamin Herrenschmidt | 73ea695 | 2006-07-04 17:07:18 +1000 | [diff] [blame] | 301 | static void __iomem *offb_map_reg(struct device_node *np, int index, |
| 302 | unsigned long offset, unsigned long size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | { |
Benjamin Herrenschmidt | 441cbd8 | 2006-10-26 15:38:10 +1000 | [diff] [blame] | 304 | const u32 *addrp; |
| 305 | u64 asize, taddr; |
| 306 | unsigned int flags; |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 307 | |
Benjamin Herrenschmidt | 441cbd8 | 2006-10-26 15:38:10 +1000 | [diff] [blame] | 308 | addrp = of_get_pci_address(np, index, &asize, &flags); |
| 309 | if (addrp == NULL) |
| 310 | addrp = of_get_address(np, index, &asize, &flags); |
| 311 | if (addrp == NULL) |
| 312 | return NULL; |
| 313 | if ((flags & (IORESOURCE_IO | IORESOURCE_MEM)) == 0) |
| 314 | return NULL; |
| 315 | if ((offset + size) > asize) |
| 316 | return NULL; |
| 317 | taddr = of_translate_address(np, addrp); |
| 318 | if (taddr == OF_BAD_ADDR) |
| 319 | return NULL; |
| 320 | return ioremap(taddr + offset, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Benjamin Herrenschmidt | 57a20d8 | 2008-07-17 15:05:22 +1000 | [diff] [blame] | 323 | static void offb_init_palette_hacks(struct fb_info *info, struct device_node *dp, |
| 324 | const char *name, unsigned long address) |
| 325 | { |
| 326 | struct offb_par *par = (struct offb_par *) info->par; |
| 327 | |
| 328 | if (dp && !strncmp(name, "ATY,Rage128", 11)) { |
| 329 | par->cmap_adr = offb_map_reg(dp, 2, 0, 0x1fff); |
| 330 | if (par->cmap_adr) |
| 331 | par->cmap_type = cmap_r128; |
| 332 | } else if (dp && (!strncmp(name, "ATY,RageM3pA", 12) |
| 333 | || !strncmp(name, "ATY,RageM3p12A", 14))) { |
| 334 | par->cmap_adr = offb_map_reg(dp, 2, 0, 0x1fff); |
| 335 | if (par->cmap_adr) |
| 336 | par->cmap_type = cmap_M3A; |
| 337 | } else if (dp && !strncmp(name, "ATY,RageM3pB", 12)) { |
| 338 | par->cmap_adr = offb_map_reg(dp, 2, 0, 0x1fff); |
| 339 | if (par->cmap_adr) |
| 340 | par->cmap_type = cmap_M3B; |
| 341 | } else if (dp && !strncmp(name, "ATY,Rage6", 9)) { |
| 342 | par->cmap_adr = offb_map_reg(dp, 1, 0, 0x1fff); |
| 343 | if (par->cmap_adr) |
| 344 | par->cmap_type = cmap_radeon; |
| 345 | } else if (!strncmp(name, "ATY,", 4)) { |
| 346 | unsigned long base = address & 0xff000000UL; |
| 347 | par->cmap_adr = |
| 348 | ioremap(base + 0x7ff000, 0x1000) + 0xcc0; |
| 349 | par->cmap_data = par->cmap_adr + 1; |
Benjamin Herrenschmidt | 9b961ed | 2011-12-14 13:58:29 +0000 | [diff] [blame] | 350 | par->cmap_type = cmap_simple; |
Benjamin Herrenschmidt | 57a20d8 | 2008-07-17 15:05:22 +1000 | [diff] [blame] | 351 | } else if (dp && (of_device_is_compatible(dp, "pci1014,b7") || |
| 352 | of_device_is_compatible(dp, "pci1014,21c"))) { |
| 353 | par->cmap_adr = offb_map_reg(dp, 0, 0x6000, 0x1000); |
| 354 | if (par->cmap_adr) |
| 355 | par->cmap_type = cmap_gxt2000; |
| 356 | } else if (dp && !strncmp(name, "vga,Display-", 12)) { |
| 357 | /* Look for AVIVO initialized by SLOF */ |
| 358 | struct device_node *pciparent = of_get_parent(dp); |
| 359 | const u32 *vid, *did; |
| 360 | vid = of_get_property(pciparent, "vendor-id", NULL); |
| 361 | did = of_get_property(pciparent, "device-id", NULL); |
| 362 | /* This will match most R5xx */ |
| 363 | if (vid && did && *vid == 0x1002 && |
| 364 | ((*did >= 0x7100 && *did < 0x7800) || |
| 365 | (*did >= 0x9400))) { |
| 366 | par->cmap_adr = offb_map_reg(pciparent, 2, 0, 0x10000); |
| 367 | if (par->cmap_adr) |
| 368 | par->cmap_type = cmap_avivo; |
| 369 | } |
| 370 | of_node_put(pciparent); |
Benjamin Herrenschmidt | 9b961ed | 2011-12-14 13:58:29 +0000 | [diff] [blame] | 371 | } else if (dp && of_device_is_compatible(dp, "qemu,std-vga")) { |
| 372 | const u32 io_of_addr[3] = { 0x01000000, 0x0, 0x0 }; |
| 373 | u64 io_addr = of_translate_address(dp, io_of_addr); |
| 374 | if (io_addr != OF_BAD_ADDR) { |
| 375 | par->cmap_adr = ioremap(io_addr + 0x3c8, 2); |
| 376 | if (par->cmap_adr) { |
| 377 | par->cmap_type = cmap_simple; |
| 378 | par->cmap_data = par->cmap_adr + 1; |
| 379 | } |
| 380 | } |
Benjamin Herrenschmidt | 57a20d8 | 2008-07-17 15:05:22 +1000 | [diff] [blame] | 381 | } |
| 382 | info->fix.visual = (par->cmap_type != cmap_unknown) ? |
| 383 | FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_STATIC_PSEUDOCOLOR; |
| 384 | } |
| 385 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | static void __init offb_init_fb(const char *name, const char *full_name, |
| 387 | int width, int height, int depth, |
| 388 | int pitch, unsigned long address, |
Anton Vorontsov | 7f29b87 | 2008-04-28 02:14:50 -0700 | [diff] [blame] | 389 | int foreign_endian, struct device_node *dp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | { |
Benjamin Herrenschmidt | c055fe07 | 2012-01-03 12:09:15 +1100 | [diff] [blame] | 391 | unsigned long res_size = pitch * height; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | struct offb_par *par = &default_par; |
| 393 | unsigned long res_start = address; |
| 394 | struct fb_fix_screeninfo *fix; |
| 395 | struct fb_var_screeninfo *var; |
| 396 | struct fb_info *info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | |
| 398 | if (!request_mem_region(res_start, res_size, "offb")) |
| 399 | return; |
| 400 | |
| 401 | printk(KERN_INFO |
| 402 | "Using unsupported %dx%d %s at %lx, depth=%d, pitch=%d\n", |
| 403 | width, height, name, address, depth, pitch); |
Benjamin Herrenschmidt | ab13446 | 2006-07-03 17:19:48 +1000 | [diff] [blame] | 404 | if (depth != 8 && depth != 15 && depth != 16 && depth != 32) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | printk(KERN_ERR "%s: can't use depth = %d\n", full_name, |
| 406 | depth); |
| 407 | release_mem_region(res_start, res_size); |
| 408 | return; |
| 409 | } |
| 410 | |
Krzysztof Helt | 4113819 | 2009-06-16 15:34:23 -0700 | [diff] [blame] | 411 | info = framebuffer_alloc(sizeof(u32) * 16, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | |
| 413 | if (info == 0) { |
| 414 | release_mem_region(res_start, res_size); |
| 415 | return; |
| 416 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | |
| 418 | fix = &info->fix; |
| 419 | var = &info->var; |
Benjamin Herrenschmidt | 57a20d8 | 2008-07-17 15:05:22 +1000 | [diff] [blame] | 420 | info->par = par; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | |
| 422 | strcpy(fix->id, "OFfb "); |
| 423 | strncat(fix->id, name, sizeof(fix->id) - sizeof("OFfb ")); |
| 424 | fix->id[sizeof(fix->id) - 1] = '\0'; |
| 425 | |
| 426 | var->xres = var->xres_virtual = width; |
| 427 | var->yres = var->yres_virtual = height; |
| 428 | fix->line_length = pitch; |
| 429 | |
| 430 | fix->smem_start = address; |
| 431 | fix->smem_len = pitch * height; |
| 432 | fix->type = FB_TYPE_PACKED_PIXELS; |
| 433 | fix->type_aux = 0; |
| 434 | |
| 435 | par->cmap_type = cmap_unknown; |
Benjamin Herrenschmidt | 57a20d8 | 2008-07-17 15:05:22 +1000 | [diff] [blame] | 436 | if (depth == 8) |
| 437 | offb_init_palette_hacks(info, dp, name, address); |
| 438 | else |
Benjamin Herrenschmidt | 73ea695 | 2006-07-04 17:07:18 +1000 | [diff] [blame] | 439 | fix->visual = FB_VISUAL_TRUECOLOR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | |
| 441 | var->xoffset = var->yoffset = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | switch (depth) { |
| 443 | case 8: |
| 444 | var->bits_per_pixel = 8; |
| 445 | var->red.offset = 0; |
| 446 | var->red.length = 8; |
| 447 | var->green.offset = 0; |
| 448 | var->green.length = 8; |
| 449 | var->blue.offset = 0; |
| 450 | var->blue.length = 8; |
| 451 | var->transp.offset = 0; |
| 452 | var->transp.length = 0; |
| 453 | break; |
Benjamin Herrenschmidt | ab13446 | 2006-07-03 17:19:48 +1000 | [diff] [blame] | 454 | case 15: /* RGB 555 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | var->bits_per_pixel = 16; |
| 456 | var->red.offset = 10; |
| 457 | var->red.length = 5; |
| 458 | var->green.offset = 5; |
| 459 | var->green.length = 5; |
| 460 | var->blue.offset = 0; |
| 461 | var->blue.length = 5; |
| 462 | var->transp.offset = 0; |
| 463 | var->transp.length = 0; |
| 464 | break; |
Benjamin Herrenschmidt | ab13446 | 2006-07-03 17:19:48 +1000 | [diff] [blame] | 465 | case 16: /* RGB 565 */ |
| 466 | var->bits_per_pixel = 16; |
| 467 | var->red.offset = 11; |
| 468 | var->red.length = 5; |
| 469 | var->green.offset = 5; |
| 470 | var->green.length = 6; |
| 471 | var->blue.offset = 0; |
| 472 | var->blue.length = 5; |
| 473 | var->transp.offset = 0; |
| 474 | var->transp.length = 0; |
| 475 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | case 32: /* RGB 888 */ |
| 477 | var->bits_per_pixel = 32; |
| 478 | var->red.offset = 16; |
| 479 | var->red.length = 8; |
| 480 | var->green.offset = 8; |
| 481 | var->green.length = 8; |
| 482 | var->blue.offset = 0; |
| 483 | var->blue.length = 8; |
| 484 | var->transp.offset = 24; |
| 485 | var->transp.length = 8; |
| 486 | break; |
| 487 | } |
| 488 | var->red.msb_right = var->green.msb_right = var->blue.msb_right = |
| 489 | var->transp.msb_right = 0; |
| 490 | var->grayscale = 0; |
| 491 | var->nonstd = 0; |
| 492 | var->activate = 0; |
| 493 | var->height = var->width = -1; |
| 494 | var->pixclock = 10000; |
| 495 | var->left_margin = var->right_margin = 16; |
| 496 | var->upper_margin = var->lower_margin = 16; |
| 497 | var->hsync_len = var->vsync_len = 8; |
| 498 | var->sync = 0; |
| 499 | var->vmode = FB_VMODE_NONINTERLACED; |
| 500 | |
Dave Airlie | ceae8cb | 2009-12-06 20:01:26 +0000 | [diff] [blame] | 501 | /* set offb aperture size for generic probing */ |
Marcin Slusarz | 1471ca9 | 2010-05-16 17:27:03 +0200 | [diff] [blame] | 502 | info->apertures = alloc_apertures(1); |
| 503 | if (!info->apertures) |
| 504 | goto out_aper; |
| 505 | info->apertures->ranges[0].base = address; |
| 506 | info->apertures->ranges[0].size = fix->smem_len; |
Dave Airlie | ceae8cb | 2009-12-06 20:01:26 +0000 | [diff] [blame] | 507 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | info->fbops = &offb_ops; |
| 509 | info->screen_base = ioremap(address, fix->smem_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | info->pseudo_palette = (void *) (info + 1); |
Dave Airlie | ceae8cb | 2009-12-06 20:01:26 +0000 | [diff] [blame] | 511 | info->flags = FBINFO_DEFAULT | FBINFO_MISC_FIRMWARE | foreign_endian; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | |
| 513 | fb_alloc_cmap(&info->cmap, 256, 0); |
| 514 | |
Marcin Slusarz | 1471ca9 | 2010-05-16 17:27:03 +0200 | [diff] [blame] | 515 | if (register_framebuffer(info) < 0) |
| 516 | goto out_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | |
| 518 | printk(KERN_INFO "fb%d: Open Firmware frame buffer device on %s\n", |
| 519 | info->node, full_name); |
Marcin Slusarz | 1471ca9 | 2010-05-16 17:27:03 +0200 | [diff] [blame] | 520 | return; |
| 521 | |
| 522 | out_err: |
| 523 | iounmap(info->screen_base); |
| 524 | out_aper: |
| 525 | iounmap(par->cmap_adr); |
| 526 | par->cmap_adr = NULL; |
| 527 | framebuffer_release(info); |
| 528 | release_mem_region(res_start, res_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | } |
| 530 | |
Benjamin Herrenschmidt | 73ea695 | 2006-07-04 17:07:18 +1000 | [diff] [blame] | 531 | |
| 532 | static void __init offb_init_nodriver(struct device_node *dp, int no_real_node) |
| 533 | { |
| 534 | unsigned int len; |
| 535 | int i, width = 640, height = 480, depth = 8, pitch = 640; |
| 536 | unsigned int flags, rsize, addr_prop = 0; |
| 537 | unsigned long max_size = 0; |
| 538 | u64 rstart, address = OF_BAD_ADDR; |
Jeremy Kerr | b04e3dd | 2006-07-12 15:40:40 +1000 | [diff] [blame] | 539 | const u32 *pp, *addrp, *up; |
Benjamin Herrenschmidt | 73ea695 | 2006-07-04 17:07:18 +1000 | [diff] [blame] | 540 | u64 asize; |
Anton Vorontsov | 7f29b87 | 2008-04-28 02:14:50 -0700 | [diff] [blame] | 541 | int foreign_endian = 0; |
| 542 | |
| 543 | #ifdef __BIG_ENDIAN |
| 544 | if (of_get_property(dp, "little-endian", NULL)) |
| 545 | foreign_endian = FBINFO_FOREIGN_ENDIAN; |
| 546 | #else |
| 547 | if (of_get_property(dp, "big-endian", NULL)) |
| 548 | foreign_endian = FBINFO_FOREIGN_ENDIAN; |
| 549 | #endif |
Benjamin Herrenschmidt | 73ea695 | 2006-07-04 17:07:18 +1000 | [diff] [blame] | 550 | |
Stephen Rothwell | 40cd3a4 | 2007-05-01 13:54:02 +1000 | [diff] [blame] | 551 | pp = of_get_property(dp, "linux,bootx-depth", &len); |
Benjamin Herrenschmidt | 73ea695 | 2006-07-04 17:07:18 +1000 | [diff] [blame] | 552 | if (pp == NULL) |
Stephen Rothwell | 40cd3a4 | 2007-05-01 13:54:02 +1000 | [diff] [blame] | 553 | pp = of_get_property(dp, "depth", &len); |
Benjamin Herrenschmidt | 73ea695 | 2006-07-04 17:07:18 +1000 | [diff] [blame] | 554 | if (pp && len == sizeof(u32)) |
| 555 | depth = *pp; |
| 556 | |
Stephen Rothwell | 40cd3a4 | 2007-05-01 13:54:02 +1000 | [diff] [blame] | 557 | pp = of_get_property(dp, "linux,bootx-width", &len); |
Benjamin Herrenschmidt | 73ea695 | 2006-07-04 17:07:18 +1000 | [diff] [blame] | 558 | if (pp == NULL) |
Stephen Rothwell | 40cd3a4 | 2007-05-01 13:54:02 +1000 | [diff] [blame] | 559 | pp = of_get_property(dp, "width", &len); |
Benjamin Herrenschmidt | 73ea695 | 2006-07-04 17:07:18 +1000 | [diff] [blame] | 560 | if (pp && len == sizeof(u32)) |
| 561 | width = *pp; |
| 562 | |
Stephen Rothwell | 40cd3a4 | 2007-05-01 13:54:02 +1000 | [diff] [blame] | 563 | pp = of_get_property(dp, "linux,bootx-height", &len); |
Benjamin Herrenschmidt | 73ea695 | 2006-07-04 17:07:18 +1000 | [diff] [blame] | 564 | if (pp == NULL) |
Stephen Rothwell | 40cd3a4 | 2007-05-01 13:54:02 +1000 | [diff] [blame] | 565 | pp = of_get_property(dp, "height", &len); |
Benjamin Herrenschmidt | 73ea695 | 2006-07-04 17:07:18 +1000 | [diff] [blame] | 566 | if (pp && len == sizeof(u32)) |
| 567 | height = *pp; |
| 568 | |
Stephen Rothwell | 40cd3a4 | 2007-05-01 13:54:02 +1000 | [diff] [blame] | 569 | pp = of_get_property(dp, "linux,bootx-linebytes", &len); |
Benjamin Herrenschmidt | 73ea695 | 2006-07-04 17:07:18 +1000 | [diff] [blame] | 570 | if (pp == NULL) |
Stephen Rothwell | 40cd3a4 | 2007-05-01 13:54:02 +1000 | [diff] [blame] | 571 | pp = of_get_property(dp, "linebytes", &len); |
Benjamin Herrenschmidt | 441cbd8 | 2006-10-26 15:38:10 +1000 | [diff] [blame] | 572 | if (pp && len == sizeof(u32) && (*pp != 0xffffffffu)) |
Benjamin Herrenschmidt | 73ea695 | 2006-07-04 17:07:18 +1000 | [diff] [blame] | 573 | pitch = *pp; |
| 574 | else |
| 575 | pitch = width * ((depth + 7) / 8); |
| 576 | |
| 577 | rsize = (unsigned long)pitch * (unsigned long)height; |
| 578 | |
| 579 | /* Ok, now we try to figure out the address of the framebuffer. |
| 580 | * |
| 581 | * Unfortunately, Open Firmware doesn't provide a standard way to do |
| 582 | * so. All we can do is a dodgy heuristic that happens to work in |
| 583 | * practice. On most machines, the "address" property contains what |
| 584 | * we need, though not on Matrox cards found in IBM machines. What I've |
| 585 | * found that appears to give good results is to go through the PCI |
| 586 | * ranges and pick one that is both big enough and if possible encloses |
| 587 | * the "address" property. If none match, we pick the biggest |
| 588 | */ |
Stephen Rothwell | 40cd3a4 | 2007-05-01 13:54:02 +1000 | [diff] [blame] | 589 | up = of_get_property(dp, "linux,bootx-addr", &len); |
Benjamin Herrenschmidt | 73ea695 | 2006-07-04 17:07:18 +1000 | [diff] [blame] | 590 | if (up == NULL) |
Stephen Rothwell | 40cd3a4 | 2007-05-01 13:54:02 +1000 | [diff] [blame] | 591 | up = of_get_property(dp, "address", &len); |
Benjamin Herrenschmidt | 73ea695 | 2006-07-04 17:07:18 +1000 | [diff] [blame] | 592 | if (up && len == sizeof(u32)) |
| 593 | addr_prop = *up; |
| 594 | |
| 595 | /* Hack for when BootX is passing us */ |
| 596 | if (no_real_node) |
| 597 | goto skip_addr; |
| 598 | |
| 599 | for (i = 0; (addrp = of_get_address(dp, i, &asize, &flags)) |
| 600 | != NULL; i++) { |
| 601 | int match_addrp = 0; |
| 602 | |
| 603 | if (!(flags & IORESOURCE_MEM)) |
| 604 | continue; |
| 605 | if (asize < rsize) |
| 606 | continue; |
| 607 | rstart = of_translate_address(dp, addrp); |
| 608 | if (rstart == OF_BAD_ADDR) |
| 609 | continue; |
| 610 | if (addr_prop && (rstart <= addr_prop) && |
| 611 | ((rstart + asize) >= (addr_prop + rsize))) |
| 612 | match_addrp = 1; |
| 613 | if (match_addrp) { |
| 614 | address = addr_prop; |
| 615 | break; |
| 616 | } |
| 617 | if (rsize > max_size) { |
| 618 | max_size = rsize; |
| 619 | address = OF_BAD_ADDR; |
| 620 | } |
| 621 | |
| 622 | if (address == OF_BAD_ADDR) |
| 623 | address = rstart; |
| 624 | } |
| 625 | skip_addr: |
| 626 | if (address == OF_BAD_ADDR && addr_prop) |
| 627 | address = (u64)addr_prop; |
| 628 | if (address != OF_BAD_ADDR) { |
| 629 | /* kludge for valkyrie */ |
| 630 | if (strcmp(dp->name, "valkyrie") == 0) |
| 631 | address += 0x1000; |
| 632 | offb_init_fb(no_real_node ? "bootx" : dp->name, |
| 633 | no_real_node ? "display" : dp->full_name, |
| 634 | width, height, depth, pitch, address, |
Anton Vorontsov | 7f29b87 | 2008-04-28 02:14:50 -0700 | [diff] [blame] | 635 | foreign_endian, no_real_node ? NULL : dp); |
Benjamin Herrenschmidt | 73ea695 | 2006-07-04 17:07:18 +1000 | [diff] [blame] | 636 | } |
| 637 | } |
| 638 | |
| 639 | static int __init offb_init(void) |
| 640 | { |
| 641 | struct device_node *dp = NULL, *boot_disp = NULL; |
| 642 | |
| 643 | if (fb_get_options("offb", NULL)) |
| 644 | return -ENODEV; |
| 645 | |
| 646 | /* Check if we have a MacOS display without a node spec */ |
Stephen Rothwell | 40cd3a4 | 2007-05-01 13:54:02 +1000 | [diff] [blame] | 647 | if (of_get_property(of_chosen, "linux,bootx-noscreen", NULL) != NULL) { |
Benjamin Herrenschmidt | 73ea695 | 2006-07-04 17:07:18 +1000 | [diff] [blame] | 648 | /* The old code tried to work out which node was the MacOS |
| 649 | * display based on the address. I'm dropping that since the |
| 650 | * lack of a node spec only happens with old BootX versions |
| 651 | * (users can update) and with this code, they'll still get |
| 652 | * a display (just not the palette hacks). |
| 653 | */ |
| 654 | offb_init_nodriver(of_chosen, 1); |
| 655 | } |
| 656 | |
| 657 | for (dp = NULL; (dp = of_find_node_by_type(dp, "display"));) { |
Stephen Rothwell | 40cd3a4 | 2007-05-01 13:54:02 +1000 | [diff] [blame] | 658 | if (of_get_property(dp, "linux,opened", NULL) && |
| 659 | of_get_property(dp, "linux,boot-display", NULL)) { |
Benjamin Herrenschmidt | 73ea695 | 2006-07-04 17:07:18 +1000 | [diff] [blame] | 660 | boot_disp = dp; |
| 661 | offb_init_nodriver(dp, 0); |
| 662 | } |
| 663 | } |
| 664 | for (dp = NULL; (dp = of_find_node_by_type(dp, "display"));) { |
Stephen Rothwell | 40cd3a4 | 2007-05-01 13:54:02 +1000 | [diff] [blame] | 665 | if (of_get_property(dp, "linux,opened", NULL) && |
Benjamin Herrenschmidt | 73ea695 | 2006-07-04 17:07:18 +1000 | [diff] [blame] | 666 | dp != boot_disp) |
| 667 | offb_init_nodriver(dp, 0); |
| 668 | } |
| 669 | |
| 670 | return 0; |
| 671 | } |
| 672 | |
| 673 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | module_init(offb_init); |
| 675 | MODULE_LICENSE("GPL"); |