caleb.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Helper functions for the SPI-3 bridge FPGA on the Radisys ENP2611
  3. * Copyright (C) 2004, 2005 Lennert Buytenhek <buytenh@wantstofly.org>
  4. * Dedicated to Marija Kulikova.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. */
  11. #include <linux/config.h>
  12. #include <linux/module.h>
  13. #include <linux/delay.h>
  14. #include <asm/io.h>
  15. #include "caleb.h"
  16. #define CALEB_IDLO 0x00
  17. #define CALEB_IDHI 0x01
  18. #define CALEB_RID 0x02
  19. #define CALEB_RESET 0x03
  20. #define CALEB_INTREN0 0x04
  21. #define CALEB_INTREN1 0x05
  22. #define CALEB_INTRSTAT0 0x06
  23. #define CALEB_INTRSTAT1 0x07
  24. #define CALEB_PORTEN 0x08
  25. #define CALEB_BURST 0x09
  26. #define CALEB_PORTPAUS 0x0A
  27. #define CALEB_PORTPAUSD 0x0B
  28. #define CALEB_PHY0RX 0x10
  29. #define CALEB_PHY1RX 0x11
  30. #define CALEB_PHY0TX 0x12
  31. #define CALEB_PHY1TX 0x13
  32. #define CALEB_IXPRX_HI_CNTR 0x15
  33. #define CALEB_PHY0RX_HI_CNTR 0x16
  34. #define CALEB_PHY1RX_HI_CNTR 0x17
  35. #define CALEB_IXPRX_CNTR 0x18
  36. #define CALEB_PHY0RX_CNTR 0x19
  37. #define CALEB_PHY1RX_CNTR 0x1A
  38. #define CALEB_IXPTX_CNTR 0x1B
  39. #define CALEB_PHY0TX_CNTR 0x1C
  40. #define CALEB_PHY1TX_CNTR 0x1D
  41. #define CALEB_DEBUG0 0x1E
  42. #define CALEB_DEBUG1 0x1F
  43. static u8 caleb_reg_read(int reg)
  44. {
  45. u8 value;
  46. value = *((volatile u8 *)(ENP2611_CALEB_VIRT_BASE + reg));
  47. // printk(KERN_INFO "caleb_reg_read(%d) = %.2x\n", reg, value);
  48. return value;
  49. }
  50. static void caleb_reg_write(int reg, u8 value)
  51. {
  52. u8 dummy;
  53. // printk(KERN_INFO "caleb_reg_write(%d, %.2x)\n", reg, value);
  54. *((volatile u8 *)(ENP2611_CALEB_VIRT_BASE + reg)) = value;
  55. dummy = *((volatile u8 *)ENP2611_CALEB_VIRT_BASE);
  56. __asm__ __volatile__("mov %0, %0" : "+r" (dummy));
  57. }
  58. void caleb_reset(void)
  59. {
  60. /*
  61. * Perform a chip reset.
  62. */
  63. caleb_reg_write(CALEB_RESET, 0x02);
  64. udelay(1);
  65. /*
  66. * Enable all interrupt sources. This is needed to get
  67. * meaningful results out of the status bits (register 6
  68. * and 7.)
  69. */
  70. caleb_reg_write(CALEB_INTREN0, 0xff);
  71. caleb_reg_write(CALEB_INTREN1, 0x07);
  72. /*
  73. * Set RX and TX FIFO thresholds to 1.5kb.
  74. */
  75. caleb_reg_write(CALEB_PHY0RX, 0x11);
  76. caleb_reg_write(CALEB_PHY1RX, 0x11);
  77. caleb_reg_write(CALEB_PHY0TX, 0x11);
  78. caleb_reg_write(CALEB_PHY1TX, 0x11);
  79. /*
  80. * Program SPI-3 burst size.
  81. */
  82. caleb_reg_write(CALEB_BURST, 0); // 64-byte RBUF mpackets
  83. // caleb_reg_write(CALEB_BURST, 1); // 128-byte RBUF mpackets
  84. // caleb_reg_write(CALEB_BURST, 2); // 256-byte RBUF mpackets
  85. }
  86. void caleb_enable_rx(int port)
  87. {
  88. u8 temp;
  89. temp = caleb_reg_read(CALEB_PORTEN);
  90. temp |= 1 << port;
  91. caleb_reg_write(CALEB_PORTEN, temp);
  92. }
  93. void caleb_disable_rx(int port)
  94. {
  95. u8 temp;
  96. temp = caleb_reg_read(CALEB_PORTEN);
  97. temp &= ~(1 << port);
  98. caleb_reg_write(CALEB_PORTEN, temp);
  99. }
  100. void caleb_enable_tx(int port)
  101. {
  102. u8 temp;
  103. temp = caleb_reg_read(CALEB_PORTEN);
  104. temp |= 1 << (port + 4);
  105. caleb_reg_write(CALEB_PORTEN, temp);
  106. }
  107. void caleb_disable_tx(int port)
  108. {
  109. u8 temp;
  110. temp = caleb_reg_read(CALEB_PORTEN);
  111. temp &= ~(1 << (port + 4));
  112. caleb_reg_write(CALEB_PORTEN, temp);
  113. }