my3126.c 4.6 KB

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