Changeset 14c3cb6 in rtems


Ignore:
Timestamp:
Feb 21, 2014, 1:59:57 PM (6 years ago)
Author:
Pavel Pisa <ppisa@…>
Branches:
4.11, master
Children:
fac9da63
Parents:
369bb13b
git-author:
Pavel Pisa <ppisa@…> (02/21/14 13:59:57)
git-committer:
Sebastian Huber <sebastian.huber@…> (03/14/14 07:56:33)
Message:

bsps/arm: Add PHY detection to LPC Ethernet

File:
1 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/arm/shared/lpc/network/lpc-ethernet.c

    r369bb13b r14c3cb6  
    337337  unsigned transmit_fatal_errors;
    338338  uint32_t phy_id;
     339  int phy;
    339340  rtems_vector_number interrupt_number;
    340341  rtems_id control_task;
     
    10921093  }
    10931094
     1095  LPC_ETH_PRINTK("tx: lpc_eth_mdio_wait %s after %d\n",
     1096                 i != one_second? "succeed": "timeout", i);
     1097
    10941098  return i != one_second ? 0 : ETIMEDOUT;
    10951099}
    10961100
    1097 static uint32_t lpc_eth_mdio_read_anlpar(void)
    1098 {
    1099   uint32_t madr = ETH_MADR_REG(MII_ANLPAR) | ETH_MADR_PHY(DEFAULT_PHY);
     1101static uint32_t lpc_eth_mdio_read_anlpar(int phy)
     1102{
     1103  uint32_t madr = ETH_MADR_REG(MII_ANLPAR) | ETH_MADR_PHY(phy);
    11001104  uint32_t anlpar = 0;
    11011105  int eno = 0;
     
    11311135  int eno = 0;
    11321136
    1133   if (phy == -1 || phy == 0) {
    1134     lpc_eth->madr = ETH_MADR_REG(reg) | ETH_MADR_PHY(DEFAULT_PHY);
     1137  if (0 <= phy && phy <= 31) {
     1138    lpc_eth->madr = ETH_MADR_REG(reg) | ETH_MADR_PHY(phy);
    11351139    lpc_eth->mcmd = 0;
    11361140    lpc_eth->mcmd = ETH_MCMD_READ;
     
    11561160  int eno = 0;
    11571161
    1158   if (phy == -1 || phy == 0) {
    1159     lpc_eth->madr = ETH_MADR_REG(reg) | ETH_MADR_PHY(DEFAULT_PHY);
     1162  if (0 <= phy && phy <= 31) {
     1163    lpc_eth->madr = ETH_MADR_REG(reg) | ETH_MADR_PHY(phy);
    11601164    lpc_eth->mwtd = val;
    11611165    eno = lpc_eth_mdio_wait_for_not_busy();
     
    11671171}
    11681172
    1169 static int lpc_eth_phy_get_id(uint32_t *id)
     1173static int lpc_eth_phy_get_id(int phy, uint32_t *id)
    11701174{
    11711175  uint32_t id1 = 0;
    1172   int eno = lpc_eth_mdio_read(DEFAULT_PHY, NULL, MII_PHYIDR1, &id1);
     1176  int eno = lpc_eth_mdio_read(phy, NULL, MII_PHYIDR1, &id1);
    11731177
    11741178  if (eno == 0) {
    11751179    uint32_t id2 = 0;
    11761180
    1177     eno = lpc_eth_mdio_read(DEFAULT_PHY, NULL, MII_PHYIDR2, &id2);
     1181    eno = lpc_eth_mdio_read(phy, NULL, MII_PHYIDR2, &id2);
    11781182    if (eno == 0) {
    11791183      *id = (id1 << 16) | (id2 & 0xfff0);
     
    11931197
    11941198static int lpc_eth_phy_set_and_clear(
     1199  lpc_eth_driver_entry *e,
    11951200  const lpc_eth_phy_action *actions,
    11961201  size_t n
     
    12041209    uint32_t val;
    12051210
    1206     eno = lpc_eth_mdio_read(DEFAULT_PHY, NULL, action->reg, &val);
     1211    eno = lpc_eth_mdio_read(e->phy, NULL, action->reg, &val);
    12071212    if (eno == 0) {
    12081213      val |= action->set;
    12091214      val &= ~action->clear;
    1210       eno = lpc_eth_mdio_write(DEFAULT_PHY, NULL, action->reg, val);
     1215      eno = lpc_eth_mdio_write(e->phy, NULL, action->reg, val);
    12111216    }
    12121217  }
     
    12351240static int lpc_eth_phy_up(lpc_eth_driver_entry *e)
    12361241{
    1237   int eno = lpc_eth_phy_get_id(&e->phy_id);
     1242  int eno;
     1243  int retries = 64;
     1244  uint32_t val;
     1245
     1246  e->phy = DEFAULT_PHY - 1;
     1247  while (true) {
     1248    e->phy = (e->phy + 1) % 32;
     1249
     1250    --retries;
     1251    eno = lpc_eth_phy_get_id(e->phy, &e->phy_id);
     1252    if (
     1253      (eno == 0 && e->phy_id != 0xfffffff0 && e->phy_id != 0)
     1254        || retries <= 0
     1255    ) {
     1256      break;
     1257    }
     1258
     1259    rtems_task_wake_after(1);
     1260  }
     1261
     1262  LPC_ETH_PRINTF("lpc_eth_phy_get_id: 0x%08" PRIx32 " from phy %d retries %d\n",
     1263                 e->phy_id, e->phy, retries);
    12381264
    12391265  if (eno == 0) {
     
    12411267      case PHY_KSZ80X1RNL:
    12421268        eno = lpc_eth_phy_set_and_clear(
     1269          e,
    12431270          &lpc_eth_phy_up_pre_action_KSZ80X1RNL [0],
    12441271          RTEMS_ARRAY_SIZE(lpc_eth_phy_up_pre_action_KSZ80X1RNL)
     
    12481275      case 0xfffffff0:
    12491276        eno = EIO;
     1277        e->phy = DEFAULT_PHY;
    12501278        break;
    12511279      default:
     
    12551283    if (eno == 0) {
    12561284      eno = lpc_eth_phy_set_and_clear(
     1285        e,
    12571286        &lpc_eth_phy_up_action_default [0],
    12581287        RTEMS_ARRAY_SIZE(lpc_eth_phy_up_action_default)
     
    12641293        case PHY_KSZ80X1RNL:
    12651294          eno = lpc_eth_phy_set_and_clear(
     1295            e,
    12661296            &lpc_eth_phy_up_post_action_KSZ80X1RNL [0],
    12671297            RTEMS_ARRAY_SIZE(lpc_eth_phy_up_post_action_KSZ80X1RNL)
     
    12911321{
    12921322  int eno = lpc_eth_phy_set_and_clear(
     1323    e,
    12931324    &lpc_eth_phy_down_action_default [0],
    12941325    RTEMS_ARRAY_SIZE(lpc_eth_phy_down_action_default)
     
    12991330      case PHY_KSZ80X1RNL:
    13001331        eno = lpc_eth_phy_set_and_clear(
     1332          e,
    13011333          &lpc_eth_phy_down_post_action_KSZ80X1RNL [0],
    13021334          RTEMS_ARRAY_SIZE(lpc_eth_phy_down_post_action_KSZ80X1RNL)
     
    15781610
    15791611  if (e->state == LPC_ETH_STATE_UP) {
    1580     uint32_t anlpar = lpc_eth_mdio_read_anlpar();
     1612    uint32_t anlpar = lpc_eth_mdio_read_anlpar(e->phy);
    15811613
    15821614    if (e->anlpar != anlpar) {
Note: See TracChangeset for help on using the changeset viewer.