misc.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. * (C) Copyright 2002 Wolfgang Grandegger <wg@denx.de>
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <common.h>
  23. #include <mpc824x.h>
  24. #include <asm/io.h>
  25. #include <pci.h>
  26. #include "pn62.h"
  27. typedef struct {
  28. pci_dev_t devno;
  29. volatile u32 *csr;
  30. } i2155x_t;
  31. static i2155x_t i2155x = { 0, NULL };
  32. static struct pci_device_id i2155x_ids[] = {
  33. { 0x1011, 0x0046 }, /* i21554 */
  34. { 0x8086, 0xb555 } /* i21555 */
  35. };
  36. int i2155x_init(void)
  37. {
  38. pci_dev_t devno;
  39. u32 val;
  40. int i;
  41. /*
  42. * Find the Intel bridge.
  43. */
  44. if ((devno = pci_find_devices(i2155x_ids, 0)) < 0) {
  45. printf("Error: Intel bridge 2155x not found!\n");
  46. return -1;
  47. }
  48. i2155x.devno = devno;
  49. /*
  50. * Get auto-configured base address for CSR access.
  51. */
  52. pci_read_config_dword(devno, PCI_BASE_ADDRESS_1, &val);
  53. if (val & PCI_BASE_ADDRESS_SPACE_IO) {
  54. val &= PCI_BASE_ADDRESS_IO_MASK;
  55. i2155x.csr = (volatile u32 *)(_IO_BASE + val);
  56. } else {
  57. val &= PCI_BASE_ADDRESS_MEM_MASK;
  58. i2155x.csr = (volatile u32 *)val;
  59. }
  60. /*
  61. * Translate downstream memory 2 (bar3) to base of shared memory.
  62. */
  63. i2155x_set_bar_base(3, PN62_SMEM_DEFAULT);
  64. /*
  65. * Enable memory space, I/O space and bus master bits
  66. * in both Primary and Secondary command registers.
  67. */
  68. val = PCI_COMMAND_MEMORY|PCI_COMMAND_MASTER|PCI_COMMAND_IO;
  69. pci_write_config_word(devno, 0x44, val);
  70. pci_write_config_word(devno, 0x04, val);
  71. /*
  72. * Clear scratchpad registers.
  73. */
  74. for (i = 0; i < (I2155X_SCRAPAD_MAX - 1); i++) {
  75. i2155x_write_scrapad(i, 0x0);
  76. }
  77. /*
  78. * Set interrupt line for Linux.
  79. */
  80. pci_write_config_byte(devno, PCI_INTERRUPT_LINE, 3);
  81. return 0;
  82. }
  83. /*
  84. * Access the Scratchpad registers 0..7 of the Intel bridge.
  85. */
  86. void i2155x_write_scrapad(int idx, u32 val)
  87. {
  88. if (idx >= 0 && idx < I2155X_SCRAPAD_MAX)
  89. out_le32(i2155x.csr + (I2155X_SCRAPAD_ADDR/4) + idx, val);
  90. else
  91. printf("i2155x_write_scrapad: invalid index\n");
  92. }
  93. u32 i2155x_read_scrapad(int idx)
  94. {
  95. if (idx >= 0 && idx < I2155X_SCRAPAD_MAX)
  96. return in_le32(i2155x.csr + (I2155X_SCRAPAD_ADDR/4) + idx);
  97. else
  98. printf("i2155x_read_scrapad: invalid index\n");
  99. return -1;
  100. }
  101. void i2155x_set_bar_base(int bar, u32 base)
  102. {
  103. if (bar >= 2 && bar <= 4) {
  104. pci_write_config_dword(i2155x.devno,
  105. I2155X_BAR2_BASE + (bar - 2) * 4,
  106. base);
  107. }
  108. }
  109. /*
  110. * Read Vital Product Data (VPD) from the Serial EPROM attached
  111. * to the Intel bridge.
  112. */
  113. int i2155x_read_vpd(int offset, int size, unsigned char *data)
  114. {
  115. int i, n;
  116. u16 val16;
  117. for (i = 0; i < size; i++) {
  118. pci_write_config_word(i2155x.devno, I2155X_VPD_ADDR,
  119. offset + i - I2155X_VPD_START);
  120. for (n = 10000; n > 0; n--) {
  121. pci_read_config_word(i2155x.devno, I2155X_VPD_ADDR, &val16);
  122. if ((val16 & 0x8000) != 0) /* wait for completion */
  123. break;
  124. udelay(100);
  125. }
  126. if (n == 0) {
  127. printf("i2155x_read_vpd: TIMEOUT\n");
  128. return -1;
  129. }
  130. pci_read_config_byte(i2155x.devno, I2155X_VPD_DATA, &data[i]);
  131. }
  132. return i;
  133. }
  134. static struct pci_device_id am79c95x_ids [] = {
  135. { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_LANCE },
  136. { }
  137. };
  138. /*
  139. * Initialize the AMD ethernet controllers.
  140. */
  141. int am79c95x_init(void)
  142. {
  143. pci_dev_t devno;
  144. int i;
  145. /*
  146. * Set interrupt line for Linux.
  147. */
  148. for (i = 0; i < 2; i++) {
  149. if ((devno = pci_find_devices(am79c95x_ids, i)) < 0)
  150. break;
  151. pci_write_config_byte(devno, PCI_INTERRUPT_LINE, 2+i);
  152. }
  153. if (i < 2)
  154. printf("Error: Only %d AMD Ethernet Controller found!\n", i);
  155. return 0;
  156. }
  157. void set_led(unsigned int number, unsigned int function)
  158. {
  159. volatile u8 *addr;
  160. if ((number >= 0) && (number < PN62_LED_MAX) &&
  161. (function >= 0) && (function <= LED_LAST_FUNCTION)) {
  162. addr = (volatile u8 *)(PN62_LED_BASE + number * 8);
  163. out_8(addr, function&0xff);
  164. }
  165. }
  166. /*
  167. * Show fatal error indicated by Kinght Rider(tm) effect
  168. * in LEDS 0-7. LEDS 8-11 contain 4 bit error code.
  169. * Note: this function will not terminate.
  170. */
  171. void fatal_error(unsigned int error_code)
  172. {
  173. int i, d;
  174. for (i = 0; i < 12; i++) {
  175. set_led(i, LED_0);
  176. }
  177. /*
  178. * Write error code.
  179. */
  180. set_led(8, (error_code & 0x01) ? LED_1 : LED_0);
  181. set_led(9, (error_code & 0x02) ? LED_1 : LED_0);
  182. set_led(10, (error_code & 0x04) ? LED_1 : LED_0);
  183. set_led(11, (error_code & 0x08) ? LED_1 : LED_0);
  184. /*
  185. * Yay - Knight Rider effect!
  186. */
  187. while(1) {
  188. unsigned int delay = 2000;
  189. for (i = 0; i < 8; i++) {
  190. set_led(i, LED_1);
  191. for (d = 0; d < delay; d++);
  192. set_led(i, LED_0);
  193. }
  194. for (i = 7; i > 0; i--) {
  195. set_led(i, LED_1);
  196. for (d = 0; d < delay; d++);
  197. set_led(i, LED_0);
  198. }
  199. }
  200. }