offb.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  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 u32 *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. const u32 io_of_addr[3] = { 0x01000000, 0x0, 0x0 };
  338. u64 io_addr = of_translate_address(dp, io_of_addr);
  339. if (io_addr != OF_BAD_ADDR) {
  340. par->cmap_adr = ioremap(io_addr + 0x3c8, 2);
  341. if (par->cmap_adr) {
  342. par->cmap_type = cmap_simple;
  343. par->cmap_data = par->cmap_adr + 1;
  344. }
  345. }
  346. }
  347. info->fix.visual = (par->cmap_type != cmap_unknown) ?
  348. FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_STATIC_PSEUDOCOLOR;
  349. }
  350. static void __init offb_init_fb(const char *name, const char *full_name,
  351. int width, int height, int depth,
  352. int pitch, unsigned long address,
  353. int foreign_endian, struct device_node *dp)
  354. {
  355. unsigned long res_size = pitch * height;
  356. struct offb_par *par = &default_par;
  357. unsigned long res_start = address;
  358. struct fb_fix_screeninfo *fix;
  359. struct fb_var_screeninfo *var;
  360. struct fb_info *info;
  361. if (!request_mem_region(res_start, res_size, "offb"))
  362. return;
  363. printk(KERN_INFO
  364. "Using unsupported %dx%d %s at %lx, depth=%d, pitch=%d\n",
  365. width, height, name, address, depth, pitch);
  366. if (depth != 8 && depth != 15 && depth != 16 && depth != 32) {
  367. printk(KERN_ERR "%s: can't use depth = %d\n", full_name,
  368. depth);
  369. release_mem_region(res_start, res_size);
  370. return;
  371. }
  372. info = framebuffer_alloc(sizeof(u32) * 16, NULL);
  373. if (info == 0) {
  374. release_mem_region(res_start, res_size);
  375. return;
  376. }
  377. fix = &info->fix;
  378. var = &info->var;
  379. info->par = par;
  380. strcpy(fix->id, "OFfb ");
  381. strncat(fix->id, name, sizeof(fix->id) - sizeof("OFfb "));
  382. fix->id[sizeof(fix->id) - 1] = '\0';
  383. var->xres = var->xres_virtual = width;
  384. var->yres = var->yres_virtual = height;
  385. fix->line_length = pitch;
  386. fix->smem_start = address;
  387. fix->smem_len = pitch * height;
  388. fix->type = FB_TYPE_PACKED_PIXELS;
  389. fix->type_aux = 0;
  390. par->cmap_type = cmap_unknown;
  391. if (depth == 8)
  392. offb_init_palette_hacks(info, dp, name, address);
  393. else
  394. fix->visual = FB_VISUAL_TRUECOLOR;
  395. var->xoffset = var->yoffset = 0;
  396. switch (depth) {
  397. case 8:
  398. var->bits_per_pixel = 8;
  399. var->red.offset = 0;
  400. var->red.length = 8;
  401. var->green.offset = 0;
  402. var->green.length = 8;
  403. var->blue.offset = 0;
  404. var->blue.length = 8;
  405. var->transp.offset = 0;
  406. var->transp.length = 0;
  407. break;
  408. case 15: /* RGB 555 */
  409. var->bits_per_pixel = 16;
  410. var->red.offset = 10;
  411. var->red.length = 5;
  412. var->green.offset = 5;
  413. var->green.length = 5;
  414. var->blue.offset = 0;
  415. var->blue.length = 5;
  416. var->transp.offset = 0;
  417. var->transp.length = 0;
  418. break;
  419. case 16: /* RGB 565 */
  420. var->bits_per_pixel = 16;
  421. var->red.offset = 11;
  422. var->red.length = 5;
  423. var->green.offset = 5;
  424. var->green.length = 6;
  425. var->blue.offset = 0;
  426. var->blue.length = 5;
  427. var->transp.offset = 0;
  428. var->transp.length = 0;
  429. break;
  430. case 32: /* RGB 888 */
  431. var->bits_per_pixel = 32;
  432. var->red.offset = 16;
  433. var->red.length = 8;
  434. var->green.offset = 8;
  435. var->green.length = 8;
  436. var->blue.offset = 0;
  437. var->blue.length = 8;
  438. var->transp.offset = 24;
  439. var->transp.length = 8;
  440. break;
  441. }
  442. var->red.msb_right = var->green.msb_right = var->blue.msb_right =
  443. var->transp.msb_right = 0;
  444. var->grayscale = 0;
  445. var->nonstd = 0;
  446. var->activate = 0;
  447. var->height = var->width = -1;
  448. var->pixclock = 10000;
  449. var->left_margin = var->right_margin = 16;
  450. var->upper_margin = var->lower_margin = 16;
  451. var->hsync_len = var->vsync_len = 8;
  452. var->sync = 0;
  453. var->vmode = FB_VMODE_NONINTERLACED;
  454. /* set offb aperture size for generic probing */
  455. info->apertures = alloc_apertures(1);
  456. if (!info->apertures)
  457. goto out_aper;
  458. info->apertures->ranges[0].base = address;
  459. info->apertures->ranges[0].size = fix->smem_len;
  460. info->fbops = &offb_ops;
  461. info->screen_base = ioremap(address, fix->smem_len);
  462. info->pseudo_palette = (void *) (info + 1);
  463. info->flags = FBINFO_DEFAULT | FBINFO_MISC_FIRMWARE | foreign_endian;
  464. fb_alloc_cmap(&info->cmap, 256, 0);
  465. if (register_framebuffer(info) < 0)
  466. goto out_err;
  467. printk(KERN_INFO "fb%d: Open Firmware frame buffer device on %s\n",
  468. info->node, full_name);
  469. return;
  470. out_err:
  471. iounmap(info->screen_base);
  472. out_aper:
  473. iounmap(par->cmap_adr);
  474. par->cmap_adr = NULL;
  475. framebuffer_release(info);
  476. release_mem_region(res_start, res_size);
  477. }
  478. static void __init offb_init_nodriver(struct device_node *dp, int no_real_node)
  479. {
  480. unsigned int len;
  481. int i, width = 640, height = 480, depth = 8, pitch = 640;
  482. unsigned int flags, rsize, addr_prop = 0;
  483. unsigned long max_size = 0;
  484. u64 rstart, address = OF_BAD_ADDR;
  485. const u32 *pp, *addrp, *up;
  486. u64 asize;
  487. int foreign_endian = 0;
  488. #ifdef __BIG_ENDIAN
  489. if (of_get_property(dp, "little-endian", NULL))
  490. foreign_endian = FBINFO_FOREIGN_ENDIAN;
  491. #else
  492. if (of_get_property(dp, "big-endian", NULL))
  493. foreign_endian = FBINFO_FOREIGN_ENDIAN;
  494. #endif
  495. pp = of_get_property(dp, "linux,bootx-depth", &len);
  496. if (pp == NULL)
  497. pp = of_get_property(dp, "depth", &len);
  498. if (pp && len == sizeof(u32))
  499. depth = *pp;
  500. pp = of_get_property(dp, "linux,bootx-width", &len);
  501. if (pp == NULL)
  502. pp = of_get_property(dp, "width", &len);
  503. if (pp && len == sizeof(u32))
  504. width = *pp;
  505. pp = of_get_property(dp, "linux,bootx-height", &len);
  506. if (pp == NULL)
  507. pp = of_get_property(dp, "height", &len);
  508. if (pp && len == sizeof(u32))
  509. height = *pp;
  510. pp = of_get_property(dp, "linux,bootx-linebytes", &len);
  511. if (pp == NULL)
  512. pp = of_get_property(dp, "linebytes", &len);
  513. if (pp && len == sizeof(u32) && (*pp != 0xffffffffu))
  514. pitch = *pp;
  515. else
  516. pitch = width * ((depth + 7) / 8);
  517. rsize = (unsigned long)pitch * (unsigned long)height;
  518. /* Ok, now we try to figure out the address of the framebuffer.
  519. *
  520. * Unfortunately, Open Firmware doesn't provide a standard way to do
  521. * so. All we can do is a dodgy heuristic that happens to work in
  522. * practice. On most machines, the "address" property contains what
  523. * we need, though not on Matrox cards found in IBM machines. What I've
  524. * found that appears to give good results is to go through the PCI
  525. * ranges and pick one that is both big enough and if possible encloses
  526. * the "address" property. If none match, we pick the biggest
  527. */
  528. up = of_get_property(dp, "linux,bootx-addr", &len);
  529. if (up == NULL)
  530. up = of_get_property(dp, "address", &len);
  531. if (up && len == sizeof(u32))
  532. addr_prop = *up;
  533. /* Hack for when BootX is passing us */
  534. if (no_real_node)
  535. goto skip_addr;
  536. for (i = 0; (addrp = of_get_address(dp, i, &asize, &flags))
  537. != NULL; i++) {
  538. int match_addrp = 0;
  539. if (!(flags & IORESOURCE_MEM))
  540. continue;
  541. if (asize < rsize)
  542. continue;
  543. rstart = of_translate_address(dp, addrp);
  544. if (rstart == OF_BAD_ADDR)
  545. continue;
  546. if (addr_prop && (rstart <= addr_prop) &&
  547. ((rstart + asize) >= (addr_prop + rsize)))
  548. match_addrp = 1;
  549. if (match_addrp) {
  550. address = addr_prop;
  551. break;
  552. }
  553. if (rsize > max_size) {
  554. max_size = rsize;
  555. address = OF_BAD_ADDR;
  556. }
  557. if (address == OF_BAD_ADDR)
  558. address = rstart;
  559. }
  560. skip_addr:
  561. if (address == OF_BAD_ADDR && addr_prop)
  562. address = (u64)addr_prop;
  563. if (address != OF_BAD_ADDR) {
  564. /* kludge for valkyrie */
  565. if (strcmp(dp->name, "valkyrie") == 0)
  566. address += 0x1000;
  567. offb_init_fb(no_real_node ? "bootx" : dp->name,
  568. no_real_node ? "display" : dp->full_name,
  569. width, height, depth, pitch, address,
  570. foreign_endian, no_real_node ? NULL : dp);
  571. }
  572. }
  573. static int __init offb_init(void)
  574. {
  575. struct device_node *dp = NULL, *boot_disp = NULL;
  576. if (fb_get_options("offb", NULL))
  577. return -ENODEV;
  578. /* Check if we have a MacOS display without a node spec */
  579. if (of_get_property(of_chosen, "linux,bootx-noscreen", NULL) != NULL) {
  580. /* The old code tried to work out which node was the MacOS
  581. * display based on the address. I'm dropping that since the
  582. * lack of a node spec only happens with old BootX versions
  583. * (users can update) and with this code, they'll still get
  584. * a display (just not the palette hacks).
  585. */
  586. offb_init_nodriver(of_chosen, 1);
  587. }
  588. for (dp = NULL; (dp = of_find_node_by_type(dp, "display"));) {
  589. if (of_get_property(dp, "linux,opened", NULL) &&
  590. of_get_property(dp, "linux,boot-display", NULL)) {
  591. boot_disp = dp;
  592. offb_init_nodriver(dp, 0);
  593. }
  594. }
  595. for (dp = NULL; (dp = of_find_node_by_type(dp, "display"));) {
  596. if (of_get_property(dp, "linux,opened", NULL) &&
  597. dp != boot_disp)
  598. offb_init_nodriver(dp, 0);
  599. }
  600. return 0;
  601. }
  602. module_init(offb_init);
  603. MODULE_LICENSE("GPL");