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