tgec.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Copyright 2009-2011 Freescale Semiconductor, Inc.
  3. * Dave Liu <daveliu@freescale.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  18. * MA 02111-1307 USA
  19. */
  20. /* MAXFRM - maximum frame length */
  21. #define MAXFRM_MASK 0x0000ffff
  22. #include <common.h>
  23. #include <phy.h>
  24. #include <asm/types.h>
  25. #include <asm/io.h>
  26. #include <asm/fsl_enet.h>
  27. #include <asm/fsl_tgec.h>
  28. #include "fm.h"
  29. #define TGEC_CMD_CFG_INIT (TGEC_CMD_CFG_NO_LEN_CHK | \
  30. TGEC_CMD_CFG_RX_ER_DISC | \
  31. TGEC_CMD_CFG_STAT_CLR | \
  32. TGEC_CMD_CFG_PAUSE_IGNORE | \
  33. TGEC_CMD_CFG_CRC_FWD)
  34. #define TGEC_CMD_CFG_FINAL (TGEC_CMD_CFG_NO_LEN_CHK | \
  35. TGEC_CMD_CFG_RX_ER_DISC | \
  36. TGEC_CMD_CFG_PAUSE_IGNORE | \
  37. TGEC_CMD_CFG_CRC_FWD)
  38. static void tgec_init_mac(struct fsl_enet_mac *mac)
  39. {
  40. struct tgec *regs = mac->base;
  41. /* mask all interrupt */
  42. out_be32(&regs->imask, IMASK_MASK_ALL);
  43. /* clear all events */
  44. out_be32(&regs->ievent, IEVENT_CLEAR_ALL);
  45. /* set the max receive length */
  46. out_be32(&regs->maxfrm, mac->max_rx_len & MAXFRM_MASK);
  47. /*
  48. * 1588 disable, insert second mac disable payload length check
  49. * disable, normal operation, any rx error frame is discarded, clear
  50. * counters, pause frame ignore, no promiscuous, LAN mode Rx CRC no
  51. * strip, Tx CRC append, Rx disable and Tx disable
  52. */
  53. out_be32(&regs->command_config, TGEC_CMD_CFG_INIT);
  54. udelay(1000);
  55. out_be32(&regs->command_config, TGEC_CMD_CFG_FINAL);
  56. /* multicast frame reception for the hash entry disable */
  57. out_be32(&regs->hashtable_ctrl, 0);
  58. }
  59. static void tgec_enable_mac(struct fsl_enet_mac *mac)
  60. {
  61. struct tgec *regs = mac->base;
  62. setbits_be32(&regs->command_config, TGEC_CMD_CFG_RXTX_EN);
  63. }
  64. static void tgec_disable_mac(struct fsl_enet_mac *mac)
  65. {
  66. struct tgec *regs = mac->base;
  67. clrbits_be32(&regs->command_config, TGEC_CMD_CFG_RXTX_EN);
  68. }
  69. static void tgec_set_mac_addr(struct fsl_enet_mac *mac, u8 *mac_addr)
  70. {
  71. struct tgec *regs = mac->base;
  72. u32 mac_addr0, mac_addr1;
  73. /*
  74. * if a station address of 0x12345678ABCD, perform a write to
  75. * MAC_ADDR0 of 0x78563412, MAC_ADDR1 of 0x0000CDAB
  76. */
  77. mac_addr0 = (mac_addr[3] << 24) | (mac_addr[2] << 16) | \
  78. (mac_addr[1] << 8) | (mac_addr[0]);
  79. out_be32(&regs->mac_addr_0, mac_addr0);
  80. mac_addr1 = ((mac_addr[5] << 8) | mac_addr[4]) & 0x0000ffff;
  81. out_be32(&regs->mac_addr_1, mac_addr1);
  82. }
  83. static void tgec_set_interface_mode(struct fsl_enet_mac *mac,
  84. phy_interface_t type, int speed)
  85. {
  86. /* nothing right now */
  87. return;
  88. }
  89. void init_tgec(struct fsl_enet_mac *mac, void *base,
  90. void *phyregs, int max_rx_len)
  91. {
  92. mac->base = base;
  93. mac->phyregs = phyregs;
  94. mac->max_rx_len = max_rx_len;
  95. mac->init_mac = tgec_init_mac;
  96. mac->enable_mac = tgec_enable_mac;
  97. mac->disable_mac = tgec_disable_mac;
  98. mac->set_mac_addr = tgec_set_mac_addr;
  99. mac->set_if_mode = tgec_set_interface_mode;
  100. }