offb.c 20 KB

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