gsw_mt7620.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* This program is free software; you can redistribute it and/or modify
  2. * it under the terms of the GNU General Public License as published by
  3. * the Free Software Foundation; version 2 of the License
  4. *
  5. * This program is distributed in the hope that it will be useful,
  6. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. * GNU General Public License for more details.
  9. *
  10. * Copyright (C) 2009-2015 John Crispin <[email protected]>
  11. * Copyright (C) 2009-2015 Felix Fietkau <[email protected]>
  12. * Copyright (C) 2013-2015 Michael Lee <[email protected]>
  13. */
  14. #include <linux/reset.h>
  15. #ifndef _RALINK_GSW_MT7620_H__
  16. #define _RALINK_GSW_MT7620_H__
  17. #define GSW_REG_PHY_TIMEOUT (5 * HZ)
  18. #define MT7620A_GSW_REG_PIAC 0x7004
  19. #define GSW_NUM_VLANS 16
  20. #define GSW_NUM_VIDS 4096
  21. #define GSW_NUM_PORTS 7
  22. #define GSW_PORT6 6
  23. #define GSW_MDIO_ACCESS BIT(31)
  24. #define GSW_MDIO_READ BIT(19)
  25. #define GSW_MDIO_WRITE BIT(18)
  26. #define GSW_MDIO_START BIT(16)
  27. #define GSW_MDIO_ADDR_SHIFT 20
  28. #define GSW_MDIO_REG_SHIFT 25
  29. #define GSW_REG_MIB_CNT_EN 0x4000
  30. #define GSW_REG_PORT_PMCR(x) (0x3000 + (x * 0x100))
  31. #define GSW_REG_PORT_STATUS(x) (0x3008 + (x * 0x100))
  32. #define GSW_REG_SMACCR0 0x3fE4
  33. #define GSW_REG_SMACCR1 0x3fE8
  34. #define GSW_REG_CKGCR 0x3ff0
  35. #define GSW_REG_IMR 0x7008
  36. #define GSW_REG_ISR 0x700c
  37. #define GSW_REG_GPC1 0x7014
  38. #define GSW_REG_GPC2 0x701c
  39. #define GSW_REG_GPCx_TXDELAY BIT(3)
  40. #define GSW_REG_GPCx_RXDELAY BIT(2)
  41. #define GSW_REG_MAC_P0_MCR 0x100
  42. #define GSW_REG_MAC_P1_MCR 0x200
  43. // Global MAC control register
  44. #define GSW_REG_GMACCR 0x30E0
  45. #define SYSC_REG_CHIP_REV_ID 0x0c
  46. #define SYSC_REG_CFG1 0x14
  47. #define PCIE_RC_MODE BIT(8)
  48. #define SYSC_PAD_RGMII2_MDIO 0x58
  49. #define SYSC_GPIO_MODE 0x60
  50. #define PORT_IRQ_ST_CHG 0x7f
  51. #define ESW_PHY_POLLING 0x7000
  52. #define PMCR_IPG BIT(18)
  53. #define PMCR_MAC_MODE BIT(16)
  54. #define PMCR_FORCE BIT(15)
  55. #define PMCR_TX_EN BIT(14)
  56. #define PMCR_RX_EN BIT(13)
  57. #define PMCR_BACKOFF BIT(9)
  58. #define PMCR_BACKPRES BIT(8)
  59. #define PMCR_RX_FC BIT(5)
  60. #define PMCR_TX_FC BIT(4)
  61. #define PMCR_SPEED(_x) (_x << 2)
  62. #define PMCR_DUPLEX BIT(1)
  63. #define PMCR_LINK BIT(0)
  64. #define PHY_AN_EN BIT(31)
  65. #define PHY_PRE_EN BIT(30)
  66. #define PMY_MDC_CONF(_x) ((_x & 0x3f) << 24)
  67. enum {
  68. /* Global attributes. */
  69. GSW_ATTR_ENABLE_VLAN,
  70. /* Port attributes. */
  71. GSW_ATTR_PORT_UNTAG,
  72. };
  73. struct mt7620_gsw {
  74. struct device *dev;
  75. struct reset_control *rst_ephy;
  76. void __iomem *base;
  77. int irq;
  78. bool ephy_disable;
  79. bool port4_ephy;
  80. unsigned long int autopoll;
  81. u16 ephy_base;
  82. };
  83. void mtk_switch_w32(struct mt7620_gsw *gsw, u32 val, unsigned reg);
  84. u32 mtk_switch_r32(struct mt7620_gsw *gsw, unsigned reg);
  85. int mtk_gsw_init(struct fe_priv *priv);
  86. int mt7620_mdio_write(struct mii_bus *bus, int phy_addr, int phy_reg, u16 val);
  87. int mt7620_mdio_read(struct mii_bus *bus, int phy_addr, int phy_reg);
  88. void mt7620_mdio_link_adjust(struct fe_priv *priv, int port);
  89. int mt7620_has_carrier(struct fe_priv *priv);
  90. void mt7620_print_link_state(struct fe_priv *priv, int port, int link,
  91. int speed, int duplex);
  92. void mt7530_mdio_w32(struct mt7620_gsw *gsw, u32 reg, u32 val);
  93. u32 mt7530_mdio_r32(struct mt7620_gsw *gsw, u32 reg);
  94. u32 _mt7620_mii_write(struct mt7620_gsw *gsw, u32 phy_addr,
  95. u32 phy_register, u32 write_data);
  96. u32 _mt7620_mii_read(struct mt7620_gsw *gsw, int phy_addr, int phy_reg);
  97. void mt7620_handle_carrier(struct fe_priv *priv);
  98. #endif