ip17xx: Fix use of MODE_VAL
[openwrt.git] / target / linux / generic-2.6 / files / drivers / net / phy / ip175c.c
index 7c44783..716f6a1 100644 (file)
@@ -28,6 +28,7 @@
 
 #define MAX_VLANS 16
 #define MAX_PORTS 9
+#undef DUMP_MII_IO
 
 typedef struct ip175c_reg {
        u16 p;                  // phy
@@ -42,7 +43,7 @@ typedef char bitnum;
 /*********** CONSTANTS ***********/
 struct register_mappings {
        char *NAME;
-       u16 MODEL_NO;                   // compare to bits 4-9 of MII register 0,3.
+       u16 MODEL_NO;                   // Compare to bits 4-9 of MII register 0,3.
        bitnum NUM_PORTS;
        bitnum CPU_PORT;
 
@@ -195,20 +196,20 @@ static const struct register_mappings IP175A = {
 
        .ADD_TAG_REG = {0,23},
        .REMOVE_TAG_REG = {0,23},
-       .ADD_TAG_BIT = {11,12,13,14,15,1,-1,-1,-1},
-       .REMOVE_TAG_BIT = {6,7,8,9,10,0,-1,-1,-1},
+       .ADD_TAG_BIT = {11,12,13,14,15,-1,-1,-1,-1},
+       .REMOVE_TAG_BIT = {6,7,8,9,10,-1,-1,-1,-1},
 
-       .SIMPLE_VLAN_REGISTERS = 1,
+       .SIMPLE_VLAN_REGISTERS = 0,
 
-       // Only programmable via. EEPROM
+       // Only programmable via EEPROM
        .VLAN_LOOKUP_REG = NOTSUPPORTED,// +N/2
        .VLAN_LOOKUP_REG_5 = NOTSUPPORTED,
-       .VLAN_LOOKUP_EVEN_BIT = {8,9,10,11,12,15,-1,-1,-1},
-       .VLAN_LOOKUP_ODD_BIT = {0,1,2,3,4,7,-1,-1,-1},
+       .VLAN_LOOKUP_EVEN_BIT = {8,9,10,11,12,-1,-1,-1,-1},
+       .VLAN_LOOKUP_ODD_BIT = {0,1,2,3,4,-1,-1,-1,-1},
 
-       .TAG_VLAN_MASK_REG = NOTSUPPORTED, // +N/2
-       .TAG_VLAN_MASK_EVEN_BIT = {0,1,2,3,4,5,-1,-1,-1},
-       .TAG_VLAN_MASK_ODD_BIT = {8,9,10,11,12,13,-1,-1,-1},
+       .TAG_VLAN_MASK_REG = NOTSUPPORTED, // +N/2,
+       .TAG_VLAN_MASK_EVEN_BIT = {-1,-1,-1,-1,-1,-1,-1,-1,-1},
+       .TAG_VLAN_MASK_ODD_BIT = {-1,-1,-1,-1,-1,-1,-1,-1,-1},
 
        .RESET_VAL = -1,
        .RESET_REG = NOTSUPPORTED,
@@ -222,13 +223,14 @@ static const struct register_mappings IP175A = {
        .NUMLAN_GROUPS_MAX = -1,
        .NUMLAN_GROUPS_BIT = -1, // {0-2}
 
-       .NUM_PORTS = 6,
-       .CPU_PORT = 5,
+       .NUM_PORTS = 5,
+       .CPU_PORT = 4,
 
-       .MII_REGISTER_EN = {0, 12},
+       .MII_REGISTER_EN = {0, 18},
        .MII_REGISTER_EN_BIT = 7,
 };
 
+
 struct ip175c_state {
        struct switch_dev dev;
        struct mii_bus *mii_bus;
@@ -237,62 +239,74 @@ struct ip175c_state {
        int router_mode;                // ROUTER_EN
        int vlan_enabled;               // TAG_VLAN_EN
        struct port_state {
-               struct phy_device *phy;
+               u16 pvid;
                unsigned int shareports;
-               u16 vlan_tag;
        } ports[MAX_PORTS];
        unsigned int add_tag;
        unsigned int remove_tag;
        int num_vlans;
        unsigned int vlan_ports[MAX_VLANS];
        const struct register_mappings *regs;
-       reg proc_mii; /*!< phy/reg for the low level register access via /proc */
-       int proc_errno; /*!< error code of the last read/write to "val" */
+       reg proc_mii;   // phy/reg for the low level register access via swconfig
 
        char buf[80];
 };
 
-static int getPhy (struct ip175c_state *state, reg mii)
+
+static int ip_phy_read(struct ip175c_state *state, int port, int reg)
+{
+       int val = mdiobus_read(state->mii_bus, port, reg);
+       if (val < 0)
+               pr_warning("IP175C: Unable to get MII register %d,%d: error %d\n", port, reg, -val);
+#ifdef DUMP_MII_IO
+       else
+               pr_debug("IP175C: Read MII(%d,%d) -> %04x\n", port, reg, val);
+#endif
+       return val;
+}
+
+static int ip_phy_write(struct ip175c_state *state, int port, int reg, u16 val)
 {
-       struct mii_bus *bus = state->mii_bus;
        int err;
 
+#ifdef DUMP_MII_IO
+       pr_debug("IP175C: Write MII(%d,%d) <- %04x\n", port, reg, val);
+#endif
+       err = mdiobus_write(state->mii_bus, port, reg, val);
+       if (err < 0)
+               pr_warning("IP175C: Unable to write MII register %d,%d: error %d\n", port, reg, -err);
+       return err;
+}
+
+static int ip_phy_write_masked(struct ip175c_state *state, int port, int reg, unsigned int mask, unsigned int data)
+{
+       int val = ip_phy_read(state, port, reg);
+       if (val < 0)
+               return 0;
+       return ip_phy_write(state, port, reg, (val & ~mask) | data);
+}
+
+static int getPhy(struct ip175c_state *state, reg mii)
+{
        if (!REG_SUPP(mii))
                return -EFAULT;
-       mutex_lock(&bus->mdio_lock);
-       err = bus->read(bus, mii.p, mii.m);
-       mutex_unlock(&bus->mdio_lock);
-       if (err < 0) {
-               state->proc_errno = err;
-               pr_warning("IP175C: Unable to get MII register %d,%d: error %d\n", mii.p,mii.m,-err);
-               return err;
-       }
-
-       pr_debug("IP175C: Read MII register %d,%d -> %04x\n", mii.p, mii.m, err);
-       return err;
+       return ip_phy_read(state, mii.p, mii.m);
 }
 
-static int setPhy (struct ip175c_state *state, reg mii, u16 value)
+static int setPhy(struct ip175c_state *state, reg mii, u16 value)
 {
-       struct mii_bus *bus = state->mii_bus;
        int err;
 
        if (!REG_SUPP(mii))
                return -EFAULT;
-       mutex_lock(&bus->mdio_lock);
-       err = bus->write(bus, mii.p, mii.m, value);
-       mutex_unlock(&bus->mdio_lock);
-       if (err < 0) {
-               state->proc_errno = err;
-               pr_warning("IP175C: Unable to set MII register %d,%d to %d: error %d\n", mii.p,mii.m,value,-err);
+       err = ip_phy_write(state, mii.p, mii.m, value);
+       if (err < 0)
                return err;
-       }
-       mdelay(2);
        getPhy(state, mii);
-       pr_debug("IP175C: Set MII register %d,%d to %04x\n", mii.p, mii.m, value);
        return 0;
 }
 
+
 /**
  * These two macros are to simplify the mapping of logical bits to the bits in hardware.
  * NOTE: these macros will return if there is an error!
@@ -327,6 +341,7 @@ static int setPhy (struct ip175c_state *state, reg mii, u16 value)
                        return val;                             \
        } while (0)
 
+
 static int get_model(struct ip175c_state *state)
 {
        reg oui_id_reg = {0, 2};
@@ -395,7 +410,6 @@ static int get_flags(struct ip175c_state *state)
                state->num_vlans+=1; // does not include WAN.
        }
 
-
        val = getPhy(state, state->regs->VLAN_CONTROL_REG);
        if (val < 0) {
                return 0;
@@ -405,7 +419,8 @@ static int get_flags(struct ip175c_state *state)
 
        return  0;
 }
-/** Get all state variables for VLAN mappings and port-based tagging. **/
+
+/** Get all state variables for VLAN mappings and port-based tagging **/
 static int get_state(struct ip175c_state *state)
 {
        int i, j;
@@ -421,43 +436,43 @@ static int get_state(struct ip175c_state *state)
 
        if (state->vlan_enabled == -1) {
                // not sure how to get this...
-               state->vlan_enabled = (!state->remove_tag && !state->add_tag);
+               state->vlan_enabled = (state->remove_tag || state->add_tag);
        }
 
        if (REG_SUPP(state->regs->VLAN_LOOKUP_REG)) {
-       for (j=0; j<MAX_PORTS; j++) {
-               state->ports[j].shareports = 0; // initialize them in case.
-       }
-       for (j=0; j<state->regs->NUM_PORTS; j++) {
-               reg addr;
-               const bitnum *bit_lookup = (j%2==0)?
-                       state->regs->VLAN_LOOKUP_EVEN_BIT:
-                       state->regs->VLAN_LOOKUP_ODD_BIT;
-               addr = state->regs->VLAN_LOOKUP_REG;
-               if (state->regs->SIMPLE_VLAN_REGISTERS) {
-                       addr.m += j;
-               } else {
-                       switch (j) {
-                       case 0:
-                       case 1:
-                               break;
-                       case 2:
-                       case 3:
-                               addr.m+=1;
-                               break;
-                       case 4:
-                               addr.m+=2;
-                               break;
-                       case 5:
-                               addr = state->regs->VLAN_LOOKUP_REG_5;
-                               break;
-                       }
+               for (j=0; j<MAX_PORTS; j++) {
+                       state->ports[j].shareports = 0; // initialize them in case.
                }
+               for (j=0; j<state->regs->NUM_PORTS; j++) {
+                       reg addr;
+                       const bitnum *bit_lookup = (j%2==0)?
+                               state->regs->VLAN_LOOKUP_EVEN_BIT:
+                               state->regs->VLAN_LOOKUP_ODD_BIT;
+                       addr = state->regs->VLAN_LOOKUP_REG;
+                       if (state->regs->SIMPLE_VLAN_REGISTERS) {
+                               addr.m += j;
+                       } else {
+                               switch (j) {
+                               case 0:
+                               case 1:
+                                       break;
+                               case 2:
+                               case 3:
+                                       addr.m+=1;
+                                       break;
+                               case 4:
+                                       addr.m+=2;
+                                       break;
+                               case 5:
+                                       addr = state->regs->VLAN_LOOKUP_REG_5;
+                                       break;
+                               }
+                       }
 
-               if (REG_SUPP(addr)) {
-                       GET_PORT_BITS(state, state->ports[j].shareports, addr, bit_lookup);
+                       if (REG_SUPP(addr)) {
+                               GET_PORT_BITS(state, state->ports[j].shareports, addr, bit_lookup);
+                       }
                }
-       }
        } else {
                for (j=0; j<MAX_PORTS; j++) {
                        state->ports[j].shareports = 0xff;
@@ -470,9 +485,9 @@ static int get_state(struct ip175c_state *state)
                        if (val < 0) {
                                return val;
                        }
-                       state->ports[i].vlan_tag = val;
+                       state->ports[i].pvid = val;
                } else {
-                       state->ports[i].vlan_tag = 0;
+                       state->ports[i].pvid = 0;
                }
        }
 
@@ -493,8 +508,8 @@ static int get_state(struct ip175c_state *state)
                for (j=0; j<MAX_VLANS; j++) {
                        state->vlan_ports[j] = 0;
                        for (i=0; i<state->regs->NUM_PORTS; i++) {
-                               if ((state->ports[i].vlan_tag == j) ||
-                                               (state->ports[i].vlan_tag == 0)) {
+                               if ((state->ports[i].pvid == j) ||
+                                               (state->ports[i].pvid == 0)) {
                                        state->vlan_ports[j] |= (1<<i);
                                }
                        }
@@ -504,7 +519,6 @@ static int get_state(struct ip175c_state *state)
        return 0;
 }
 
-
 /** Only update vlan and router flags in the switch **/
 static int update_flags(struct ip175c_state *state)
 {
@@ -554,63 +568,63 @@ static int update_state(struct ip175c_state *state)
                                  state->regs->REMOVE_TAG_REG, state->regs->REMOVE_TAG_BIT);
 
        if (REG_SUPP(state->regs->VLAN_LOOKUP_REG)) {
-       for (j=0; j<state->regs->NUM_PORTS; j++) {
-               reg addr;
-               const bitnum *bit_lookup = (j%2==0)?
-                       state->regs->VLAN_LOOKUP_EVEN_BIT:
-                       state->regs->VLAN_LOOKUP_ODD_BIT;
-
-               // duplicate code -- sorry
-               addr = state->regs->VLAN_LOOKUP_REG;
-               if (state->regs->SIMPLE_VLAN_REGISTERS) {
-                       addr.m += j;
-               } else {
-                       switch (j) {
-                       case 0:
-                       case 1:
-                               break;
-                       case 2:
-                       case 3:
-                               addr.m+=1;
-                               break;
-                       case 4:
-                               addr.m+=2;
-                               break;
-                       case 5:
-                               addr = state->regs->VLAN_LOOKUP_REG_5;
-                               break;
-                       default:
-                               addr.m = -1; // shouldn't get here, but...
-                               break;
+               for (j=0; j<state->regs->NUM_PORTS; j++) {
+                       reg addr;
+                       const bitnum *bit_lookup = (j%2==0)?
+                               state->regs->VLAN_LOOKUP_EVEN_BIT:
+                               state->regs->VLAN_LOOKUP_ODD_BIT;
+
+                       // duplicate code -- sorry
+                       addr = state->regs->VLAN_LOOKUP_REG;
+                       if (state->regs->SIMPLE_VLAN_REGISTERS) {
+                               addr.m += j;
+                       } else {
+                               switch (j) {
+                               case 0:
+                               case 1:
+                                       break;
+                               case 2:
+                               case 3:
+                                       addr.m+=1;
+                                       break;
+                               case 4:
+                                       addr.m+=2;
+                                       break;
+                               case 5:
+                                       addr = state->regs->VLAN_LOOKUP_REG_5;
+                                       break;
+                               default:
+                                       addr.m = -1; // shouldn't get here, but...
+                                       break;
+                               }
+                       }
+                       //printf("shareports for %d is %02X\n",j,state->ports[j].shareports);
+                       if (REG_SUPP(addr)) {
+                               SET_PORT_BITS(state, state->ports[j].shareports, addr, bit_lookup);
                        }
-               }
-               //printf("shareports for %d is %02X\n",j,state->ports[j].shareports);
-               if (REG_SUPP(addr)) {
-                       SET_PORT_BITS(state, state->ports[j].shareports, addr, bit_lookup);
                }
        }
-       }
        if (REG_SUPP(state->regs->TAG_VLAN_MASK_REG)) {
-       for (j=0; j<MAX_VLANS; j++) {
-               reg addr = state->regs->TAG_VLAN_MASK_REG;
-               const bitnum *bit_lookup = (j%2==0)?
-                       state->regs->TAG_VLAN_MASK_EVEN_BIT:
-                       state->regs->TAG_VLAN_MASK_ODD_BIT;
-               unsigned int vlan_mask;
-               if (state->regs->SIMPLE_VLAN_REGISTERS) {
-                       addr.m += j;
-               } else {
-                       addr.m += j/2;
+               for (j=0; j<MAX_VLANS; j++) {
+                       reg addr = state->regs->TAG_VLAN_MASK_REG;
+                       const bitnum *bit_lookup = (j%2==0)?
+                               state->regs->TAG_VLAN_MASK_EVEN_BIT:
+                               state->regs->TAG_VLAN_MASK_ODD_BIT;
+                       unsigned int vlan_mask;
+                       if (state->regs->SIMPLE_VLAN_REGISTERS) {
+                               addr.m += j;
+                       } else {
+                               addr.m += j/2;
+                       }
+                       vlan_mask = state->vlan_ports[j];
+                       SET_PORT_BITS(state, vlan_mask, addr, bit_lookup);
                }
-               vlan_mask = state->vlan_ports[j];
-               SET_PORT_BITS(state, vlan_mask, addr, bit_lookup);
-       }
        }
 
        for (i=0; i<MAX_PORTS; i++) {
                if (REG_SUPP(state->regs->VLAN_DEFAULT_TAG_REG[i])) {
                        int err = setPhy(state, state->regs->VLAN_DEFAULT_TAG_REG[i],
-                                       state->ports[i].vlan_tag);
+                                       state->ports[i].pvid);
                        if (err < 0) {
                                return err;
                        }
@@ -618,15 +632,11 @@ static int update_state(struct ip175c_state *state)
        }
 
        return update_flags(state);
-
-       // software reset: 30.0 = 0x175C
-       // wait 2ms
-       // reset ports 0,1,2,3,4
 }
 
-/*
-  Uses only the VLAN port mask and the add tag mask to generate the other fields:
-  which ports are part of the same VLAN, removing vlan tags, and VLAN tag ids.
+/**
 Uses only the VLAN port mask and the add tag mask to generate the other fields:
 which ports are part of the same VLAN, removing vlan tags, and VLAN tag ids.
  */
 static void correct_vlan_state(struct ip175c_state *state)
 {
@@ -634,34 +644,21 @@ static void correct_vlan_state(struct ip175c_state *state)
        state->num_vlans = 0;
        for (i=0; i<MAX_VLANS; i++) {
                if (state->vlan_ports[i] != 0) {
-                       state->num_vlans = i+1; //hack -- we need to store the "set" vlans somewhere...
+                       state->num_vlans = i+1; // Hack -- we need to store the "set" vlans somewhere...
                }
        }
 
-       for (i=0; i<state->regs->NUM_PORTS; i++) {
-               int oldtag = state->ports[i].vlan_tag;
-               if (oldtag >= 0 && oldtag < MAX_VLANS) {
-                       if (state->vlan_ports[oldtag] & (1<<i)) {
-                               continue; // primary vlan is valid.
-                       }
-               }
-               state->ports[i].vlan_tag = 0;
-       }
-
        for (i=0; i<state->regs->NUM_PORTS; i++) {
                unsigned int portmask = (1<<i);
+               if (!state->vlan_enabled) {
+                       // Share with everybody!
+                       state->ports[i].shareports = (1<<state->regs->NUM_PORTS)-1;
+                       continue;
+               }
                state->ports[i].shareports = portmask;
                for (j=0; j<MAX_VLANS; j++) {
-                       if (state->vlan_ports[j] & portmask) {
+                       if (state->vlan_ports[j] & portmask)
                                state->ports[i].shareports |= state->vlan_ports[j];
-                               if (state->ports[i].vlan_tag == 0) {
-                                       state->ports[i].vlan_tag = j;
-                               }
-                       }
-               }
-               if (!state->vlan_enabled) {
-                       // share with everybody!
-                       state->ports[i].shareports = (1<<state->regs->NUM_PORTS)-1;
                }
        }
        state->remove_tag = ((~state->add_tag) & ((1<<state->regs->NUM_PORTS)-1));
@@ -672,7 +669,7 @@ static int ip175c_get_enable_vlan(struct switch_dev *dev, const struct switch_at
        struct ip175c_state *state = dev->priv;
        int err;
 
-       err = get_state(state); // may be set in get_state.
+       err = get_state(state); // May be set in get_state.
        if (err < 0)
                return err;
        val->value.i = state->vlan_enabled;
@@ -692,7 +689,7 @@ static int ip175c_set_enable_vlan(struct switch_dev *dev, const struct switch_at
        enable = val->value.i;
 
        if (state->vlan_enabled == enable) {
-               // do not change any state.
+               // Do not change any state.
                return 0;
        }
        state->vlan_enabled = enable;
@@ -700,20 +697,18 @@ static int ip175c_set_enable_vlan(struct switch_dev *dev, const struct switch_at
        // Otherwise, if we are switching state, set fields to a known default.
        state->remove_tag = 0x0000;
        state->add_tag = 0x0000;
-       for (i = 0; i < MAX_PORTS; i++) {
-               state->ports[i].vlan_tag = 0;
+       for (i = 0; i < MAX_PORTS; i++)
                state->ports[i].shareports = 0xffff;
-       }
-       for (i = 0; i < MAX_VLANS; i++) {
+
+       for (i = 0; i < MAX_VLANS; i++)
                state->vlan_ports[i] = 0x0;
-       }
 
        if (state->vlan_enabled) {
-               // updates other fields only based off vlan_ports and add_tag fields.
+               // Updates other fields only based off vlan_ports and add_tag fields.
                // Note that by default, no ports are in any vlans.
                correct_vlan_state(state);
        }
-       // ensure sane defaults?
+       // Ensure sane defaults?
        return update_state(state);
 }
 
@@ -773,15 +768,6 @@ static int ip175c_set_ports(struct switch_dev *dev, struct switch_val *val)
                        state->add_tag &= (~bitmask);
                }
        }
-       /*
-       // no primary vlan id support in swconfig?
-       // primary vlan will be set to the first non-zero vlan a port is a member of.
-       for (i = 0; i< state->regs->NUM_PORTS; i++) {
-               if (vlan_config->pvid & (1<<i)) {
-                       state->ports[i].vlan_tag = nr;
-               }
-       }
-       */
 
        correct_vlan_state(state);
        err = update_state(state);
@@ -798,7 +784,7 @@ static int ip175c_apply(struct switch_dev *dev)
        if (err < 0)
                return err;
 
-       if (REG_SUPP(state->regs->MII_REGISTER_EN)){
+       if (REG_SUPP(state->regs->MII_REGISTER_EN)) {
                int val = getPhy(state, state->regs->MII_REGISTER_EN);
                if (val < 0) {
                        return val;
@@ -809,7 +795,7 @@ static int ip175c_apply(struct switch_dev *dev)
        return 0;
 }
 
-static int ip175c_reset(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
+static int ip175c_reset(struct switch_dev *dev)
 {
        struct ip175c_state *state = dev->priv;
        int i, err;
@@ -824,23 +810,24 @@ static int ip175c_reset(struct switch_dev *dev, const struct switch_attr *attr,
                        return err;
                err = getPhy(state, state->regs->RESET_REG);
 
-               /* data sheet specifies reset period is 2 msec
-                  (don't see any mention of the 2ms delay in the IP178C spec, only
-                   in IP175C, but it can't hurt.) */
+               /*
+                *  Data sheet specifies reset period to be 2 msec.
+                *  (I don't see any mention of the 2ms delay in the IP178C spec, only
+                *  in IP175C, but it can't hurt.)
+                */
                mdelay(2);
        }
 
        if (REG_SUPP(state->regs->MODE_REG)) {
-               err = setPhy(state, state->regs->MODE_REG, state->regs->RESET_VAL);
+               err = setPhy(state, state->regs->MODE_REG, state->regs->MODE_VAL);
                if (err < 0)
                        return err;
                err = getPhy(state, state->regs->MODE_REG);
        }
 
        /* reset switch ports */
-       for (i = 0; i < 5; i++) {
-               err = state->mii_bus->write(state->mii_bus, i,
-                                        MII_BMCR, BMCR_RESET);
+       for (i = 0; i < state->regs->NUM_PORTS-1; i++) {
+               err = ip_phy_write(state, i, MII_BMCR, BMCR_RESET);
                if (err < 0)
                        return err;
        }
@@ -848,7 +835,6 @@ static int ip175c_reset(struct switch_dev *dev, const struct switch_attr *attr,
        return 0;
 }
 
-/*! get the current register number */
 static int ip175c_get_tagged(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
 {
        struct ip175c_state *state = dev->priv;
@@ -872,7 +858,6 @@ static int ip175c_get_tagged(struct switch_dev *dev, const struct switch_attr *a
        return 0;
 }
 
-/*! set a new register address for low level access to registers */
 static int ip175c_set_tagged(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
 {
        struct ip175c_state *state = dev->priv;
@@ -898,10 +883,7 @@ static int ip175c_set_tagged(struct switch_dev *dev, const struct switch_attr *a
        return err;
 }
 
-
-/* low level /proc procedures */
-
-/*! get the current phy address */
+/** Get the current phy address */
 static int ip175c_get_phy(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
 {
        struct ip175c_state *state = dev->priv;
@@ -910,7 +892,7 @@ static int ip175c_get_phy(struct switch_dev *dev, const struct switch_attr *attr
        return 0;
 }
 
-/*! set a new phy address for low level access to registers */
+/** Set a new phy address for low level access to registers */
 static int ip175c_set_phy(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
 {
        struct ip175c_state *state = dev->priv;
@@ -923,7 +905,7 @@ static int ip175c_set_phy(struct switch_dev *dev, const struct switch_attr *attr
        return 0;
 }
 
-/*! get the current register number */
+/** Get the current register number */
 static int ip175c_get_reg(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
 {
        struct ip175c_state *state = dev->priv;
@@ -932,7 +914,7 @@ static int ip175c_get_reg(struct switch_dev *dev, const struct switch_attr *attr
        return 0;
 }
 
-/*! set a new register address for low level access to registers */
+/** Set a new register address for low level access to registers */
 static int ip175c_set_reg(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
 {
        struct ip175c_state *state = dev->priv;
@@ -945,7 +927,7 @@ static int ip175c_set_reg(struct switch_dev *dev, const struct switch_attr *attr
        return 0;
 }
 
-/*! get the register content of state->proc_mii */
+/** Get the register content of state->proc_mii */
 static int ip175c_get_val(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
 {
        struct ip175c_state *state = dev->priv;
@@ -954,51 +936,37 @@ static int ip175c_get_val(struct switch_dev *dev, const struct switch_attr *attr
                retval = getPhy(state, state->proc_mii);
 
        if (retval < 0) {
-               state->proc_errno = retval;
                return retval;
        } else {
-               state->proc_errno = 0;
                val->value.i = retval;
                return 0;
        }
 }
 
-/*! write a value to the register defined by phy/reg above */
+/** Write a value to the register defined by phy/reg above */
 static int ip175c_set_val(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
 {
        struct ip175c_state *state = dev->priv;
-       int myval;
+       int myval, err = -EINVAL;
 
        myval = val->value.i;
        if (myval <= 0xffff && myval >= 0 && REG_SUPP(state->proc_mii)) {
-               state->proc_errno = setPhy(state, state->proc_mii, (u16)myval);
-       } else {
-               state->proc_errno = -EINVAL;
+               err = setPhy(state, state->proc_mii, (u16)myval);
        }
-       return state->proc_errno;
-}
-
-/*! get the errno of the last read/write of "val" */
-static int ip175c_get_errno(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
-{
-       struct ip175c_state *state = dev->priv;
-       val->value.i = state->proc_errno;
-       return 0;
+       return err;
 }
 
 static int ip175c_read_name(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
 {
        struct ip175c_state *state = dev->priv;
-       val->value.s = state->regs->NAME; // just a const pointer, won't be freed by swconfig.
+       val->value.s = state->regs->NAME; // Just a const pointer, won't be freed by swconfig.
        return 0;
 }
 
-
 static int ip175c_set_port_speed(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
 {
-       int nr = val->port_vlan;
        struct ip175c_state *state = dev->priv;
-       struct phy_device *phy;
+       int nr = val->port_vlan;
        int ctrl;
        int autoneg;
        int speed;
@@ -1013,17 +981,14 @@ static int ip175c_set_port_speed(struct switch_dev *dev, const struct switch_att
                speed = 1;
        }
 
-       if (nr == state->regs->CPU_PORT) {
-               return -EINVAL; // can't set speed for cpu port!
-       }
+       /* Can't set speed for cpu port */
+       if (nr == state->regs->CPU_PORT)
+               return -EINVAL;
 
        if (nr >= dev->ports || nr < 0)
                return -EINVAL;
-       phy = state->ports[nr].phy;
-       if (!phy)
-               return -EINVAL;
 
-       ctrl = phy_read(phy, 0);
+       ctrl = ip_phy_read(state, nr, 0);
        if (ctrl < 0)
                return -EIO;
 
@@ -1032,14 +997,13 @@ static int ip175c_set_port_speed(struct switch_dev *dev, const struct switch_att
        ctrl |= (autoneg<<12);
        ctrl |= (speed<<13);
 
-       return phy_write(phy, 0, ctrl);
+       return ip_phy_write(state, nr, 0, ctrl);
 }
 
 static int ip175c_get_port_speed(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
 {
-       int nr = val->port_vlan;
        struct ip175c_state *state = dev->priv;
-       struct phy_device *phy;
+       int nr = val->port_vlan;
        int speed, status;
 
        if (nr == state->regs->CPU_PORT) {
@@ -1049,12 +1013,9 @@ static int ip175c_get_port_speed(struct switch_dev *dev, const struct switch_att
 
        if (nr >= dev->ports || nr < 0)
                return -EINVAL;
-       phy = state->ports[nr].phy;
-       if (!phy)
-               return -EINVAL;
 
-       status = phy_read(phy, 1);
-       speed = phy_read(phy, 18);
+       status = ip_phy_read(state, nr, 1);
+       speed = ip_phy_read(state, nr, 18);
        if (status < 0 || speed < 0)
                return -EIO;
 
@@ -1066,13 +1027,11 @@ static int ip175c_get_port_speed(struct switch_dev *dev, const struct switch_att
        return 0;
 }
 
-
 static int ip175c_get_port_status(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
 {
-       int nr = val->port_vlan;
        struct ip175c_state *state = dev->priv;
-       struct phy_device *phy;
        int ctrl, speed, status;
+       int nr = val->port_vlan;
        int len;
        char *buf = state->buf; // fixed-length at 80.
 
@@ -1084,13 +1043,10 @@ static int ip175c_get_port_status(struct switch_dev *dev, const struct switch_at
 
        if (nr >= dev->ports || nr < 0)
                return -EINVAL;
-       phy = state->ports[nr].phy;
-       if (!phy)
-               return -EINVAL;
 
-       ctrl = phy_read(phy, 0);
-       status = phy_read(phy, 1);
-       speed = phy_read(phy, 18);
+       ctrl = ip_phy_read(state, nr, 0);
+       status = ip_phy_read(state, nr, 1);
+       speed = ip_phy_read(state, nr, 18);
        if (ctrl < 0 || status < 0 || speed < 0)
                return -EIO;
 
@@ -1115,14 +1071,35 @@ static int ip175c_get_port_status(struct switch_dev *dev, const struct switch_at
        return 0;
 }
 
+static int ip175c_get_pvid(struct switch_dev *dev, int port, int *val)
+{
+       struct ip175c_state *state = dev->priv;
+
+       *val = state->ports[port].pvid;
+       return 0;
+}
+
+static int ip175c_set_pvid(struct switch_dev *dev, int port, int val)
+{
+       struct ip175c_state *state = dev->priv;
+
+       state->ports[port].pvid = val;
+
+       if (!REG_SUPP(state->regs->VLAN_DEFAULT_TAG_REG[port]))
+               return 0;
+
+       return setPhy(state, state->regs->VLAN_DEFAULT_TAG_REG[port], val);
+}
+
+
 enum Ports {
        IP175C_PORT_STATUS,
        IP175C_PORT_LINK,
        IP175C_PORT_TAGGED,
+       IP175C_PORT_PVID,
 };
 
 enum Globals {
-       IP175C_RESET,
        IP175C_ENABLE_VLAN,
        IP175C_GET_NAME,
        IP175C_REGISTER_PHY,
@@ -1132,14 +1109,6 @@ enum Globals {
 };
 
 static const struct switch_attr ip175c_global[] = {
-       [IP175C_RESET] = {
-               .id = IP175C_RESET,
-               .type = SWITCH_TYPE_NOVAL,
-               .name  = "reset",
-               .get = NULL,
-               .description = "Resets the switch but does not clear vlan configuration",
-               .set = ip175c_reset,
-       },
        [IP175C_ENABLE_VLAN] = {
                .id = IP175C_ENABLE_VLAN,
                .type = SWITCH_TYPE_INT,
@@ -1160,7 +1129,7 @@ static const struct switch_attr ip175c_global[] = {
        [IP175C_REGISTER_PHY] = {
                .id = IP175C_REGISTER_PHY,
                .type = SWITCH_TYPE_INT,
-               .description = "Direct register access: set phy (0-4, or 29,30,31)",
+               .description = "Direct register access: set PHY (0-4, or 29,30,31)",
                .name  = "phy",
                .get  = ip175c_get_phy,
                .set = ip175c_set_phy,
@@ -1168,7 +1137,7 @@ static const struct switch_attr ip175c_global[] = {
        [IP175C_REGISTER_MII] = {
                .id = IP175C_REGISTER_MII,
                .type = SWITCH_TYPE_INT,
-               .description = "Direct register access: set mii number (0-31)",
+               .description = "Direct register access: set MII register number (0-31)",
                .name  = "reg",
                .get  = ip175c_get_reg,
                .set = ip175c_set_reg,
@@ -1181,15 +1150,6 @@ static const struct switch_attr ip175c_global[] = {
                .get  = ip175c_get_val,
                .set = ip175c_set_val,
        },
-       [IP175C_REGISTER_ERRNO] = {
-               .id = IP175C_REGISTER_ERRNO,
-               .type = SWITCH_TYPE_INT,
-               .description = "Direct register access: returns last read or write error",
-               .name  = "errno",
-               .get  = ip175c_get_errno,
-               .set = NULL,
-       },
-
 };
 
 static const struct switch_attr ip175c_vlan[] = {
@@ -1228,7 +1188,7 @@ static int ip175c_probe(struct phy_device *pdev)
        struct switch_dev *dev;
        int err;
 
-       /* we only attach to PHY 0, but use all available PHYs */
+       /* We only attach to PHY 0, but use all available PHYs */
        if (pdev->addr != 0)
                return -ENODEV;
 
@@ -1244,9 +1204,12 @@ static int ip175c_probe(struct phy_device *pdev)
        dev->attr_vlan.attr = ip175c_vlan;
        dev->attr_vlan.n_attr = ARRAY_SIZE(ip175c_vlan);
 
+       dev->get_port_pvid = ip175c_get_pvid;
+       dev->set_port_pvid = ip175c_set_pvid;
        dev->get_vlan_ports = ip175c_get_ports;
        dev->set_vlan_ports = ip175c_set_ports;
        dev->apply_config = ip175c_apply;
+       dev->reset_switch = ip175c_reset;
 
        dev->priv = state;
        pdev->priv = state;
@@ -1279,7 +1242,7 @@ static int ip175c_config_init(struct phy_device *pdev)
        if (err < 0)
                return err;
 
-       ip175c_reset(&state->dev, NULL, NULL);
+       ip175c_reset(&state->dev);
 
        state->registered = true;
        netif_carrier_on(pdev->attached_dev);
@@ -1322,15 +1285,35 @@ static struct phy_driver ip175c_driver = {
        .driver         = { .owner = THIS_MODULE },
 };
 
+static struct phy_driver ip175a_driver = {
+       .name           = "IC+ IP175A",
+       .phy_id         = 0x02430c50,
+       .phy_id_mask    = 0x0ffffff0,
+       .features       = PHY_BASIC_FEATURES,
+       .probe          = ip175c_probe,
+       .remove         = ip175c_remove,
+       .config_init    = ip175c_config_init,
+       .config_aneg    = ip175c_config_aneg,
+       .read_status    = ip175c_read_status,
+       .driver         = { .owner = THIS_MODULE },
+};
+
 
 int __init ip175c_init(void)
 {
+       int ret;
+
+       ret = phy_driver_register(&ip175a_driver);
+       if (ret < 0)
+               return ret;
+
        return phy_driver_register(&ip175c_driver);
 }
 
 void __exit ip175c_exit(void)
 {
        phy_driver_unregister(&ip175c_driver);
+       phy_driver_unregister(&ip175a_driver);
 }
 
 MODULE_AUTHOR("Patrick Horn <patrick.horn@gmail.com>");
@@ -1339,4 +1322,3 @@ MODULE_LICENSE("GPL");
 
 module_init(ip175c_init);
 module_exit(ip175c_exit);
-
This page took 0.052185 seconds and 4 git commands to generate.