offb.c 19 KB

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