sm501.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. /*
  28. * Basic video support for SMI SM501 "Voyager" graphic controller
  29. */
  30. #include <common.h>
  31. #include <asm/io.h>
  32. #include <video_fb.h>
  33. #include <sm501.h>
  34. #define read8(ptrReg) \
  35. *(volatile unsigned char *)(sm501.isaBase + ptrReg)
  36. #define write8(ptrReg,value) \
  37. *(volatile unsigned char *)(sm501.isaBase + ptrReg) = value
  38. #define read16(ptrReg) \
  39. (*(volatile unsigned short *)(sm501.isaBase + ptrReg))
  40. #define write16(ptrReg,value) \
  41. (*(volatile unsigned short *)(sm501.isaBase + ptrReg) = value)
  42. #define read32(ptrReg) \
  43. (*(volatile unsigned int *)(sm501.isaBase + ptrReg))
  44. #define write32(ptrReg, value) \
  45. (*(volatile unsigned int *)(sm501.isaBase + ptrReg) = value)
  46. GraphicDevice sm501;
  47. void write_be32(int off, unsigned int val)
  48. {
  49. out_be32((unsigned __iomem *)(sm501.isaBase + off), val);
  50. }
  51. void write_le32(int off, unsigned int val)
  52. {
  53. out_le32((unsigned __iomem *)(sm501.isaBase + off), val);
  54. }
  55. void (*write_reg32)(int off, unsigned int val) = write_be32;
  56. /*-----------------------------------------------------------------------------
  57. * SmiSetRegs --
  58. *-----------------------------------------------------------------------------
  59. */
  60. static void SmiSetRegs (void)
  61. {
  62. /*
  63. * The content of the chipset register depends on the board (clocks,
  64. * ...)
  65. */
  66. const SMI_REGS *preg = board_get_regs ();
  67. while (preg->Index) {
  68. write_reg32 (preg->Index, preg->Value);
  69. /*
  70. * Insert a delay between
  71. */
  72. udelay (1000);
  73. preg ++;
  74. }
  75. }
  76. #ifdef CONFIG_VIDEO_SM501_PCI
  77. static struct pci_device_id sm501_pci_tbl[] = {
  78. { PCI_VENDOR_ID_SMI, PCI_DEVICE_ID_SMI_501 },
  79. {}
  80. };
  81. #endif
  82. /*
  83. * We do not enforce board code to provide empty/unused
  84. * functions for this driver and define weak default
  85. * functions here.
  86. */
  87. unsigned int __board_video_init (void)
  88. {
  89. return 0;
  90. }
  91. unsigned int board_video_init (void)
  92. __attribute__((weak, alias("__board_video_init")));
  93. unsigned int __board_video_get_fb (void)
  94. {
  95. return 0;
  96. }
  97. unsigned int board_video_get_fb (void)
  98. __attribute__((weak, alias("__board_video_get_fb")));
  99. void __board_validate_screen (unsigned int base)
  100. {
  101. }
  102. void board_validate_screen (unsigned int base)
  103. __attribute__((weak, alias("__board_validate_screen")));
  104. /*-----------------------------------------------------------------------------
  105. * video_hw_init --
  106. *-----------------------------------------------------------------------------
  107. */
  108. void *video_hw_init (void)
  109. {
  110. #ifdef CONFIG_VIDEO_SM501_PCI
  111. unsigned int pci_mem_base, pci_mmio_base;
  112. unsigned int id;
  113. unsigned short device_id;
  114. pci_dev_t devbusfn;
  115. int mem;
  116. #endif
  117. unsigned int *vm, i;
  118. memset (&sm501, 0, sizeof (GraphicDevice));
  119. #ifdef CONFIG_VIDEO_SM501_PCI
  120. printf("Video: ");
  121. /* Look for SM501/SM502 chips */
  122. devbusfn = pci_find_devices(sm501_pci_tbl, 0);
  123. if (devbusfn < 0) {
  124. printf ("PCI Controller not found.\n");
  125. goto not_pci;
  126. }
  127. /* Setup */
  128. pci_write_config_dword (devbusfn, PCI_COMMAND,
  129. (PCI_COMMAND_MEMORY | PCI_COMMAND_IO));
  130. pci_read_config_word (devbusfn, PCI_DEVICE_ID, &device_id);
  131. pci_read_config_dword (devbusfn, PCI_REVISION_ID, &id);
  132. pci_read_config_dword (devbusfn, PCI_BASE_ADDRESS_0, &pci_mem_base);
  133. pci_read_config_dword (devbusfn, PCI_BASE_ADDRESS_1, &pci_mmio_base);
  134. sm501.frameAdrs = pci_mem_to_phys (devbusfn, pci_mem_base);
  135. sm501.isaBase = pci_mem_to_phys (devbusfn, pci_mmio_base);
  136. if (sm501.isaBase)
  137. write_reg32 = write_le32;
  138. mem = in_le32 ((unsigned __iomem *)(sm501.isaBase + 0x10));
  139. mem = (mem & 0x0000e000) >> 13;
  140. switch (mem) {
  141. case 1:
  142. mem = 8;
  143. break;
  144. case 2:
  145. mem = 16;
  146. break;
  147. case 3:
  148. mem = 32;
  149. break;
  150. case 4:
  151. mem = 64;
  152. break;
  153. case 5:
  154. mem = 2;
  155. break;
  156. case 0:
  157. default:
  158. mem = 4;
  159. }
  160. printf ("PCI SM50%d %d MB\n", ((id & 0xff) == 0xC0) ? 2 : 1, mem);
  161. not_pci:
  162. #endif
  163. /*
  164. * Initialization of the access to the graphic chipset Retreive base
  165. * address of the chipset (see board/RPXClassic/eccx.c)
  166. */
  167. if (!sm501.isaBase) {
  168. sm501.isaBase = board_video_init ();
  169. if (!sm501.isaBase)
  170. return NULL;
  171. }
  172. if (!sm501.frameAdrs) {
  173. sm501.frameAdrs = board_video_get_fb ();
  174. if (!sm501.frameAdrs)
  175. return NULL;
  176. }
  177. sm501.winSizeX = board_get_width ();
  178. sm501.winSizeY = board_get_height ();
  179. #if defined(CONFIG_VIDEO_SM501_8BPP)
  180. sm501.gdfIndex = GDF__8BIT_INDEX;
  181. sm501.gdfBytesPP = 1;
  182. #elif defined(CONFIG_VIDEO_SM501_16BPP)
  183. sm501.gdfIndex = GDF_16BIT_565RGB;
  184. sm501.gdfBytesPP = 2;
  185. #elif defined(CONFIG_VIDEO_SM501_32BPP)
  186. sm501.gdfIndex = GDF_32BIT_X888RGB;
  187. sm501.gdfBytesPP = 4;
  188. #else
  189. #error Unsupported SM501 BPP
  190. #endif
  191. sm501.memSize = sm501.winSizeX * sm501.winSizeY * sm501.gdfBytesPP;
  192. /* Load Smi registers */
  193. SmiSetRegs ();
  194. /* (see board/RPXClassic/RPXClassic.c) */
  195. board_validate_screen (sm501.isaBase);
  196. /* Clear video memory */
  197. i = sm501.memSize/4;
  198. vm = (unsigned int *)sm501.frameAdrs;
  199. while(i--)
  200. *vm++ = 0;
  201. return (&sm501);
  202. }