sm501.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. * (C) Copyright 2002
  3. * Stäubli Faverges - <www.staubli.com>
  4. * Pierre AUBERT p.aubert@staubli.com
  5. *
  6. * (C) Copyright 2005
  7. * Martin Krause TQ-Systems GmbH martin.krause@tqs.de
  8. *
  9. * SPDX-License-Identifier: GPL-2.0+
  10. */
  11. /*
  12. * Basic video support for SMI SM501 "Voyager" graphic controller
  13. */
  14. #include <common.h>
  15. #include <asm/io.h>
  16. #include <video_fb.h>
  17. #include <sm501.h>
  18. #define read8(ptrReg) \
  19. *(volatile unsigned char *)(sm501.isaBase + ptrReg)
  20. #define write8(ptrReg,value) \
  21. *(volatile unsigned char *)(sm501.isaBase + ptrReg) = value
  22. #define read16(ptrReg) \
  23. (*(volatile unsigned short *)(sm501.isaBase + ptrReg))
  24. #define write16(ptrReg,value) \
  25. (*(volatile unsigned short *)(sm501.isaBase + ptrReg) = value)
  26. #define read32(ptrReg) \
  27. (*(volatile unsigned int *)(sm501.isaBase + ptrReg))
  28. #define write32(ptrReg, value) \
  29. (*(volatile unsigned int *)(sm501.isaBase + ptrReg) = value)
  30. GraphicDevice sm501;
  31. void write_be32(int off, unsigned int val)
  32. {
  33. out_be32((unsigned __iomem *)(sm501.isaBase + off), val);
  34. }
  35. void write_le32(int off, unsigned int val)
  36. {
  37. out_le32((unsigned __iomem *)(sm501.isaBase + off), val);
  38. }
  39. void (*write_reg32)(int off, unsigned int val) = write_be32;
  40. /*-----------------------------------------------------------------------------
  41. * SmiSetRegs --
  42. *-----------------------------------------------------------------------------
  43. */
  44. static void SmiSetRegs (void)
  45. {
  46. /*
  47. * The content of the chipset register depends on the board (clocks,
  48. * ...)
  49. */
  50. const SMI_REGS *preg = board_get_regs ();
  51. while (preg->Index) {
  52. write_reg32 (preg->Index, preg->Value);
  53. /*
  54. * Insert a delay between
  55. */
  56. udelay (1000);
  57. preg ++;
  58. }
  59. }
  60. #ifdef CONFIG_VIDEO_SM501_PCI
  61. static struct pci_device_id sm501_pci_tbl[] = {
  62. { PCI_VENDOR_ID_SMI, PCI_DEVICE_ID_SMI_501 },
  63. {}
  64. };
  65. #endif
  66. /*
  67. * We do not enforce board code to provide empty/unused
  68. * functions for this driver and define weak default
  69. * functions here.
  70. */
  71. unsigned int __board_video_init (void)
  72. {
  73. return 0;
  74. }
  75. unsigned int board_video_init (void)
  76. __attribute__((weak, alias("__board_video_init")));
  77. unsigned int __board_video_get_fb (void)
  78. {
  79. return 0;
  80. }
  81. unsigned int board_video_get_fb (void)
  82. __attribute__((weak, alias("__board_video_get_fb")));
  83. void __board_validate_screen (unsigned int base)
  84. {
  85. }
  86. void board_validate_screen (unsigned int base)
  87. __attribute__((weak, alias("__board_validate_screen")));
  88. /*-----------------------------------------------------------------------------
  89. * video_hw_init --
  90. *-----------------------------------------------------------------------------
  91. */
  92. void *video_hw_init (void)
  93. {
  94. #ifdef CONFIG_VIDEO_SM501_PCI
  95. unsigned int pci_mem_base, pci_mmio_base;
  96. unsigned int id;
  97. unsigned short device_id;
  98. pci_dev_t devbusfn;
  99. int mem;
  100. #endif
  101. unsigned int *vm, i;
  102. memset (&sm501, 0, sizeof (GraphicDevice));
  103. #ifdef CONFIG_VIDEO_SM501_PCI
  104. printf("Video: ");
  105. /* Look for SM501/SM502 chips */
  106. devbusfn = pci_find_devices(sm501_pci_tbl, 0);
  107. if (devbusfn < 0) {
  108. printf ("PCI Controller not found.\n");
  109. goto not_pci;
  110. }
  111. /* Setup */
  112. pci_write_config_dword (devbusfn, PCI_COMMAND,
  113. (PCI_COMMAND_MEMORY | PCI_COMMAND_IO));
  114. pci_read_config_word (devbusfn, PCI_DEVICE_ID, &device_id);
  115. pci_read_config_dword (devbusfn, PCI_REVISION_ID, &id);
  116. pci_read_config_dword (devbusfn, PCI_BASE_ADDRESS_0, &pci_mem_base);
  117. pci_read_config_dword (devbusfn, PCI_BASE_ADDRESS_1, &pci_mmio_base);
  118. sm501.frameAdrs = pci_mem_to_phys (devbusfn, pci_mem_base);
  119. sm501.isaBase = pci_mem_to_phys (devbusfn, pci_mmio_base);
  120. if (sm501.isaBase)
  121. write_reg32 = write_le32;
  122. mem = in_le32 ((unsigned __iomem *)(sm501.isaBase + 0x10));
  123. mem = (mem & 0x0000e000) >> 13;
  124. switch (mem) {
  125. case 1:
  126. mem = 8;
  127. break;
  128. case 2:
  129. mem = 16;
  130. break;
  131. case 3:
  132. mem = 32;
  133. break;
  134. case 4:
  135. mem = 64;
  136. break;
  137. case 5:
  138. mem = 2;
  139. break;
  140. case 0:
  141. default:
  142. mem = 4;
  143. }
  144. printf ("PCI SM50%d %d MB\n", ((id & 0xff) == 0xC0) ? 2 : 1, mem);
  145. not_pci:
  146. #endif
  147. /*
  148. * Initialization of the access to the graphic chipset Retreive base
  149. * address of the chipset (see board/RPXClassic/eccx.c)
  150. */
  151. if (!sm501.isaBase) {
  152. sm501.isaBase = board_video_init ();
  153. if (!sm501.isaBase)
  154. return NULL;
  155. }
  156. if (!sm501.frameAdrs) {
  157. sm501.frameAdrs = board_video_get_fb ();
  158. if (!sm501.frameAdrs)
  159. return NULL;
  160. }
  161. sm501.winSizeX = board_get_width ();
  162. sm501.winSizeY = board_get_height ();
  163. #if defined(CONFIG_VIDEO_SM501_8BPP)
  164. sm501.gdfIndex = GDF__8BIT_INDEX;
  165. sm501.gdfBytesPP = 1;
  166. #elif defined(CONFIG_VIDEO_SM501_16BPP)
  167. sm501.gdfIndex = GDF_16BIT_565RGB;
  168. sm501.gdfBytesPP = 2;
  169. #elif defined(CONFIG_VIDEO_SM501_32BPP)
  170. sm501.gdfIndex = GDF_32BIT_X888RGB;
  171. sm501.gdfBytesPP = 4;
  172. #else
  173. #error Unsupported SM501 BPP
  174. #endif
  175. sm501.memSize = sm501.winSizeX * sm501.winSizeY * sm501.gdfBytesPP;
  176. /* Load Smi registers */
  177. SmiSetRegs ();
  178. /* (see board/RPXClassic/RPXClassic.c) */
  179. board_validate_screen (sm501.isaBase);
  180. /* Clear video memory */
  181. i = sm501.memSize/4;
  182. vm = (unsigned int *)sm501.frameAdrs;
  183. while(i--)
  184. *vm++ = 0;
  185. return (&sm501);
  186. }