my3126.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /* $Date: 2005/11/12 02:13:49 $ $RCSfile: my3126.c,v $ $Revision: 1.15 $ */
  2. #include "cphy.h"
  3. #include "elmer0.h"
  4. #include "suni1x10gexp_regs.h"
  5. /* Port Reset */
  6. static int my3126_reset(struct cphy *cphy, int wait)
  7. {
  8. /*
  9. * This can be done through registers. It is not required since
  10. * a full chip reset is used.
  11. */
  12. return (0);
  13. }
  14. static int my3126_interrupt_enable(struct cphy *cphy)
  15. {
  16. schedule_delayed_work(&cphy->phy_update, HZ/30);
  17. t1_tpi_read(cphy->adapter, A_ELMER0_GPO, &cphy->elmer_gpo);
  18. return (0);
  19. }
  20. static int my3126_interrupt_disable(struct cphy *cphy)
  21. {
  22. cancel_rearming_delayed_work(&cphy->phy_update);
  23. return (0);
  24. }
  25. static int my3126_interrupt_clear(struct cphy *cphy)
  26. {
  27. return (0);
  28. }
  29. #define OFFSET(REG_ADDR) (REG_ADDR << 2)
  30. static int my3126_interrupt_handler(struct cphy *cphy)
  31. {
  32. u32 val;
  33. u16 val16;
  34. u16 status;
  35. u32 act_count;
  36. adapter_t *adapter;
  37. adapter = cphy->adapter;
  38. if (cphy->count == 50) {
  39. mdio_read(cphy, 0x1, 0x1, &val);
  40. val16 = (u16) val;
  41. status = cphy->bmsr ^ val16;
  42. if (status & BMSR_LSTATUS)
  43. t1_link_changed(adapter, 0);
  44. cphy->bmsr = val16;
  45. /* We have only enabled link change interrupts so it
  46. must be that
  47. */
  48. cphy->count = 0;
  49. }
  50. t1_tpi_write(adapter, OFFSET(SUNI1x10GEXP_REG_MSTAT_CONTROL),
  51. SUNI1x10GEXP_BITMSK_MSTAT_SNAP);
  52. t1_tpi_read(adapter,
  53. OFFSET(SUNI1x10GEXP_REG_MSTAT_COUNTER_1_LOW), &act_count);
  54. t1_tpi_read(adapter,
  55. OFFSET(SUNI1x10GEXP_REG_MSTAT_COUNTER_33_LOW), &val);
  56. act_count += val;
  57. /* Populate elmer_gpo with the register value */
  58. t1_tpi_read(adapter, A_ELMER0_GPO, &val);
  59. cphy->elmer_gpo = val;
  60. if ( (val & (1 << 8)) || (val & (1 << 19)) ||
  61. (cphy->act_count == act_count) || cphy->act_on ) {
  62. if (is_T2(adapter))
  63. val |= (1 << 9);
  64. else if (t1_is_T1B(adapter))
  65. val |= (1 << 20);
  66. cphy->act_on = 0;
  67. } else {
  68. if (is_T2(adapter))
  69. val &= ~(1 << 9);
  70. else if (t1_is_T1B(adapter))
  71. val &= ~(1 << 20);
  72. cphy->act_on = 1;
  73. }
  74. t1_tpi_write(adapter, A_ELMER0_GPO, val);
  75. cphy->elmer_gpo = val;
  76. cphy->act_count = act_count;
  77. cphy->count++;
  78. return cphy_cause_link_change;
  79. }
  80. static void my3216_poll(void *arg)
  81. {
  82. my3126_interrupt_handler(arg);
  83. }
  84. static int my3126_set_loopback(struct cphy *cphy, int on)
  85. {
  86. return (0);
  87. }
  88. /* To check the activity LED */
  89. static int my3126_get_link_status(struct cphy *cphy,
  90. int *link_ok, int *speed, int *duplex, int *fc)
  91. {
  92. u32 val;
  93. u16 val16;
  94. adapter_t *adapter;
  95. adapter = cphy->adapter;
  96. mdio_read(cphy, 0x1, 0x1, &val);
  97. val16 = (u16) val;
  98. /* Populate elmer_gpo with the register value */
  99. t1_tpi_read(adapter, A_ELMER0_GPO, &val);
  100. cphy->elmer_gpo = val;
  101. *link_ok = (val16 & BMSR_LSTATUS);
  102. if (*link_ok) {
  103. /* Turn on the LED. */
  104. if (is_T2(adapter))
  105. val &= ~(1 << 8);
  106. else if (t1_is_T1B(adapter))
  107. val &= ~(1 << 19);
  108. } else {
  109. /* Turn off the LED. */
  110. if (is_T2(adapter))
  111. val |= (1 << 8);
  112. else if (t1_is_T1B(adapter))
  113. val |= (1 << 19);
  114. }
  115. t1_tpi_write(adapter, A_ELMER0_GPO, val);
  116. cphy->elmer_gpo = val;
  117. *speed = SPEED_10000;
  118. *duplex = DUPLEX_FULL;
  119. /* need to add flow control */
  120. if (fc)
  121. *fc = PAUSE_RX | PAUSE_TX;
  122. return (0);
  123. }
  124. static void my3126_destroy(struct cphy *cphy)
  125. {
  126. kfree(cphy);
  127. }
  128. static struct cphy_ops my3126_ops = {
  129. .destroy = my3126_destroy,
  130. .reset = my3126_reset,
  131. .interrupt_enable = my3126_interrupt_enable,
  132. .interrupt_disable = my3126_interrupt_disable,
  133. .interrupt_clear = my3126_interrupt_clear,
  134. .interrupt_handler = my3126_interrupt_handler,
  135. .get_link_status = my3126_get_link_status,
  136. .set_loopback = my3126_set_loopback,
  137. };
  138. static struct cphy *my3126_phy_create(adapter_t *adapter,
  139. int phy_addr, struct mdio_ops *mdio_ops)
  140. {
  141. struct cphy *cphy = kzalloc(sizeof (*cphy), GFP_KERNEL);
  142. if (cphy)
  143. cphy_init(cphy, adapter, phy_addr, &my3126_ops, mdio_ops);
  144. INIT_WORK(&cphy->phy_update, my3216_poll, cphy);
  145. cphy->bmsr = 0;
  146. return (cphy);
  147. }
  148. /* Chip Reset */
  149. static int my3126_phy_reset(adapter_t * adapter)
  150. {
  151. u32 val;
  152. t1_tpi_read(adapter, A_ELMER0_GPO, &val);
  153. val &= ~4;
  154. t1_tpi_write(adapter, A_ELMER0_GPO, val);
  155. msleep(100);
  156. t1_tpi_write(adapter, A_ELMER0_GPO, val | 4);
  157. msleep(1000);
  158. /* Now lets enable the Laser. Delay 100us */
  159. t1_tpi_read(adapter, A_ELMER0_GPO, &val);
  160. val |= 0x8000;
  161. t1_tpi_write(adapter, A_ELMER0_GPO, val);
  162. udelay(100);
  163. return (0);
  164. }
  165. struct gphy t1_my3126_ops = {
  166. my3126_phy_create,
  167. my3126_phy_reset
  168. };