my3126.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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_delayed_work_sync(&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. cphy_mdio_read(cphy, MDIO_MMD_PMAPMD, MDIO_STAT1, &val);
  40. val16 = (u16) val;
  41. status = cphy->bmsr ^ val16;
  42. if (status & MDIO_STAT1_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(struct work_struct *work)
  81. {
  82. struct cphy *cphy = container_of(work, struct cphy, phy_update.work);
  83. my3126_interrupt_handler(cphy);
  84. }
  85. static int my3126_set_loopback(struct cphy *cphy, int on)
  86. {
  87. return 0;
  88. }
  89. /* To check the activity LED */
  90. static int my3126_get_link_status(struct cphy *cphy,
  91. int *link_ok, int *speed, int *duplex, int *fc)
  92. {
  93. u32 val;
  94. u16 val16;
  95. adapter_t *adapter;
  96. adapter = cphy->adapter;
  97. cphy_mdio_read(cphy, MDIO_MMD_PMAPMD, MDIO_STAT1, &val);
  98. val16 = (u16) val;
  99. /* Populate elmer_gpo with the register value */
  100. t1_tpi_read(adapter, A_ELMER0_GPO, &val);
  101. cphy->elmer_gpo = val;
  102. *link_ok = (val16 & MDIO_STAT1_LSTATUS);
  103. if (*link_ok) {
  104. /* Turn on the LED. */
  105. if (is_T2(adapter))
  106. val &= ~(1 << 8);
  107. else if (t1_is_T1B(adapter))
  108. val &= ~(1 << 19);
  109. } else {
  110. /* Turn off the LED. */
  111. if (is_T2(adapter))
  112. val |= (1 << 8);
  113. else if (t1_is_T1B(adapter))
  114. val |= (1 << 19);
  115. }
  116. t1_tpi_write(adapter, A_ELMER0_GPO, val);
  117. cphy->elmer_gpo = val;
  118. *speed = SPEED_10000;
  119. *duplex = DUPLEX_FULL;
  120. /* need to add flow control */
  121. if (fc)
  122. *fc = PAUSE_RX | PAUSE_TX;
  123. return 0;
  124. }
  125. static void my3126_destroy(struct cphy *cphy)
  126. {
  127. kfree(cphy);
  128. }
  129. static const struct cphy_ops my3126_ops = {
  130. .destroy = my3126_destroy,
  131. .reset = my3126_reset,
  132. .interrupt_enable = my3126_interrupt_enable,
  133. .interrupt_disable = my3126_interrupt_disable,
  134. .interrupt_clear = my3126_interrupt_clear,
  135. .interrupt_handler = my3126_interrupt_handler,
  136. .get_link_status = my3126_get_link_status,
  137. .set_loopback = my3126_set_loopback,
  138. .mmds = (MDIO_DEVS_PMAPMD | MDIO_DEVS_PCS |
  139. MDIO_DEVS_PHYXS),
  140. };
  141. static struct cphy *my3126_phy_create(struct net_device *dev,
  142. int phy_addr, const struct mdio_ops *mdio_ops)
  143. {
  144. struct cphy *cphy = kzalloc(sizeof (*cphy), GFP_KERNEL);
  145. if (!cphy)
  146. return NULL;
  147. cphy_init(cphy, dev, phy_addr, &my3126_ops, mdio_ops);
  148. INIT_DELAYED_WORK(&cphy->phy_update, my3216_poll);
  149. cphy->bmsr = 0;
  150. return cphy;
  151. }
  152. /* Chip Reset */
  153. static int my3126_phy_reset(adapter_t * adapter)
  154. {
  155. u32 val;
  156. t1_tpi_read(adapter, A_ELMER0_GPO, &val);
  157. val &= ~4;
  158. t1_tpi_write(adapter, A_ELMER0_GPO, val);
  159. msleep(100);
  160. t1_tpi_write(adapter, A_ELMER0_GPO, val | 4);
  161. msleep(1000);
  162. /* Now lets enable the Laser. Delay 100us */
  163. t1_tpi_read(adapter, A_ELMER0_GPO, &val);
  164. val |= 0x8000;
  165. t1_tpi_write(adapter, A_ELMER0_GPO, val);
  166. udelay(100);
  167. return 0;
  168. }
  169. const struct gphy t1_my3126_ops = {
  170. .create = my3126_phy_create,
  171. .reset = my3126_phy_reset
  172. };