tgec.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2009-2011 Freescale Semiconductor, Inc.
  4. * Dave Liu <daveliu@freescale.com>
  5. */
  6. /* MAXFRM - maximum frame length */
  7. #define MAXFRM_MASK 0x0000ffff
  8. #include <common.h>
  9. #include <phy.h>
  10. #include <asm/types.h>
  11. #include <asm/io.h>
  12. #include <fsl_tgec.h>
  13. #include <linux/delay.h>
  14. #include "fm.h"
  15. #define TGEC_CMD_CFG_INIT (TGEC_CMD_CFG_NO_LEN_CHK | \
  16. TGEC_CMD_CFG_RX_ER_DISC | \
  17. TGEC_CMD_CFG_STAT_CLR | \
  18. TGEC_CMD_CFG_PAUSE_IGNORE | \
  19. TGEC_CMD_CFG_CRC_FWD)
  20. #define TGEC_CMD_CFG_FINAL (TGEC_CMD_CFG_NO_LEN_CHK | \
  21. TGEC_CMD_CFG_RX_ER_DISC | \
  22. TGEC_CMD_CFG_PAUSE_IGNORE | \
  23. TGEC_CMD_CFG_CRC_FWD)
  24. static void tgec_init_mac(struct fsl_enet_mac *mac)
  25. {
  26. struct tgec *regs = mac->base;
  27. /* mask all interrupt */
  28. out_be32(&regs->imask, IMASK_MASK_ALL);
  29. /* clear all events */
  30. out_be32(&regs->ievent, IEVENT_CLEAR_ALL);
  31. /* set the max receive length */
  32. out_be32(&regs->maxfrm, mac->max_rx_len & MAXFRM_MASK);
  33. /*
  34. * 1588 disable, insert second mac disable payload length check
  35. * disable, normal operation, any rx error frame is discarded, clear
  36. * counters, pause frame ignore, no promiscuous, LAN mode Rx CRC no
  37. * strip, Tx CRC append, Rx disable and Tx disable
  38. */
  39. out_be32(&regs->command_config, TGEC_CMD_CFG_INIT);
  40. udelay(1000);
  41. out_be32(&regs->command_config, TGEC_CMD_CFG_FINAL);
  42. /* multicast frame reception for the hash entry disable */
  43. out_be32(&regs->hashtable_ctrl, 0);
  44. }
  45. static void tgec_enable_mac(struct fsl_enet_mac *mac)
  46. {
  47. struct tgec *regs = mac->base;
  48. setbits_be32(&regs->command_config, TGEC_CMD_CFG_RXTX_EN);
  49. }
  50. static void tgec_disable_mac(struct fsl_enet_mac *mac)
  51. {
  52. struct tgec *regs = mac->base;
  53. clrbits_be32(&regs->command_config, TGEC_CMD_CFG_RXTX_EN);
  54. }
  55. static void tgec_set_mac_addr(struct fsl_enet_mac *mac, u8 *mac_addr)
  56. {
  57. struct tgec *regs = mac->base;
  58. u32 mac_addr0, mac_addr1;
  59. /*
  60. * if a station address of 0x12345678ABCD, perform a write to
  61. * MAC_ADDR0 of 0x78563412, MAC_ADDR1 of 0x0000CDAB
  62. */
  63. mac_addr0 = (mac_addr[3] << 24) | (mac_addr[2] << 16) | \
  64. (mac_addr[1] << 8) | (mac_addr[0]);
  65. out_be32(&regs->mac_addr_0, mac_addr0);
  66. mac_addr1 = ((mac_addr[5] << 8) | mac_addr[4]) & 0x0000ffff;
  67. out_be32(&regs->mac_addr_1, mac_addr1);
  68. }
  69. static void tgec_set_interface_mode(struct fsl_enet_mac *mac,
  70. phy_interface_t type, int speed)
  71. {
  72. /* nothing right now */
  73. return;
  74. }
  75. void init_tgec(struct fsl_enet_mac *mac, void *base,
  76. void *phyregs, int max_rx_len)
  77. {
  78. mac->base = base;
  79. mac->phyregs = phyregs;
  80. mac->max_rx_len = max_rx_len;
  81. mac->init_mac = tgec_init_mac;
  82. mac->enable_mac = tgec_enable_mac;
  83. mac->disable_mac = tgec_disable_mac;
  84. mac->set_mac_addr = tgec_set_mac_addr;
  85. mac->set_if_mode = tgec_set_interface_mode;
  86. }