char buf[80];
};
+#define get_state(_dev) container_of((_dev), struct ip17xx_state, dev)
static int ip_phy_read(struct ip17xx_state *state, int port, int reg)
{
err = ip_phy_write(state, mii.p, mii.m, value);
if (err < 0)
return err;
+ mdelay(2);
getPhy(state, mii);
return 0;
}
static int ip17xx_get_enable_vlan(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
{
- struct ip17xx_state *state = dev->priv;
+ struct ip17xx_state *state = get_state(dev);
val->value.i = state->vlan_enabled;
return 0;
static int ip17xx_set_enable_vlan(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
{
- struct ip17xx_state *state = dev->priv;
+ struct ip17xx_state *state = get_state(dev);
int enable;
enable = val->value.i;
static int ip17xx_get_ports(struct switch_dev *dev, struct switch_val *val)
{
- struct ip17xx_state *state = dev->priv;
+ struct ip17xx_state *state = get_state(dev);
int b;
int ind;
unsigned int ports;
static int ip17xx_set_ports(struct switch_dev *dev, struct switch_val *val)
{
- struct ip17xx_state *state = dev->priv;
+ struct ip17xx_state *state = get_state(dev);
int i;
if (val->port_vlan >= dev->vlans || val->port_vlan < 0)
static int ip17xx_apply(struct switch_dev *dev)
{
- struct ip17xx_state *state = dev->priv;
+ struct ip17xx_state *state = get_state(dev);
if (REG_SUPP(state->regs->MII_REGISTER_EN)) {
int val = getPhy(state, state->regs->MII_REGISTER_EN);
static int ip17xx_reset(struct switch_dev *dev)
{
- struct ip17xx_state *state = dev->priv;
+ struct ip17xx_state *state = get_state(dev);
int i, err;
if (REG_SUPP(state->regs->RESET_REG)) {
static int ip17xx_get_tagged(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
{
- struct ip17xx_state *state = dev->priv;
+ struct ip17xx_state *state = get_state(dev);
if (state->add_tag & (1<<val->port_vlan)) {
if (state->remove_tag & (1<<val->port_vlan))
static int ip17xx_set_tagged(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
{
- struct ip17xx_state *state = dev->priv;
+ struct ip17xx_state *state = get_state(dev);
state->add_tag &= ~(1<<val->port_vlan);
state->remove_tag &= ~(1<<val->port_vlan);
/** Get the current phy address */
static int ip17xx_get_phy(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
{
- struct ip17xx_state *state = dev->priv;
+ struct ip17xx_state *state = get_state(dev);
val->value.i = state->proc_mii.p;
return 0;
/** Set a new phy address for low level access to registers */
static int ip17xx_set_phy(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
{
- struct ip17xx_state *state = dev->priv;
+ struct ip17xx_state *state = get_state(dev);
int new_reg = val->value.i;
if (new_reg < 0 || new_reg > 31)
/** Get the current register number */
static int ip17xx_get_reg(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
{
- struct ip17xx_state *state = dev->priv;
+ struct ip17xx_state *state = get_state(dev);
val->value.i = state->proc_mii.m;
return 0;
/** Set a new register address for low level access to registers */
static int ip17xx_set_reg(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
{
- struct ip17xx_state *state = dev->priv;
+ struct ip17xx_state *state = get_state(dev);
int new_reg = val->value.i;
if (new_reg < 0 || new_reg > 31)
/** Get the register content of state->proc_mii */
static int ip17xx_get_val(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
{
- struct ip17xx_state *state = dev->priv;
+ struct ip17xx_state *state = get_state(dev);
int retval = -EINVAL;
if (REG_SUPP(state->proc_mii))
retval = getPhy(state, state->proc_mii);
/** Write a value to the register defined by phy/reg above */
static int ip17xx_set_val(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
{
- struct ip17xx_state *state = dev->priv;
+ struct ip17xx_state *state = get_state(dev);
int myval, err = -EINVAL;
myval = val->value.i;
static int ip17xx_read_name(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
{
- struct ip17xx_state *state = dev->priv;
+ struct ip17xx_state *state = get_state(dev);
val->value.s = state->regs->NAME; // Just a const pointer, won't be freed by swconfig.
return 0;
}
static int ip17xx_get_tag(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
{
- struct ip17xx_state *state = dev->priv;
+ struct ip17xx_state *state = get_state(dev);
int vlan = val->port_vlan;
if (vlan < 0 || vlan >= MAX_VLANS)
static int ip17xx_set_tag(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
{
- struct ip17xx_state *state = dev->priv;
+ struct ip17xx_state *state = get_state(dev);
int vlan = val->port_vlan;
int tag = val->value.i;
static int ip17xx_set_port_speed(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
{
- struct ip17xx_state *state = dev->priv;
+ struct ip17xx_state *state = get_state(dev);
int nr = val->port_vlan;
int ctrl;
int autoneg;
static int ip17xx_get_port_speed(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
{
- struct ip17xx_state *state = dev->priv;
+ struct ip17xx_state *state = get_state(dev);
int nr = val->port_vlan;
int speed, status;
static int ip17xx_get_port_status(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
{
- struct ip17xx_state *state = dev->priv;
+ struct ip17xx_state *state = get_state(dev);
int ctrl, speed, status;
int nr = val->port_vlan;
int len;
static int ip17xx_get_pvid(struct switch_dev *dev, int port, int *val)
{
- struct ip17xx_state *state = dev->priv;
+ struct ip17xx_state *state = get_state(dev);
*val = state->ports[port].pvid;
return 0;
static int ip17xx_set_pvid(struct switch_dev *dev, int port, int val)
{
- struct ip17xx_state *state = dev->priv;
+ struct ip17xx_state *state = get_state(dev);
if (val < 0 || val >= MAX_VLANS)
return -EINVAL;
[IP17XX_VLAN_TAG] = {
.id = IP17XX_VLAN_TAG,
.type = SWITCH_TYPE_INT,
- .description = "VLAN tag (0-4095) [IP175D only]",
- .name = "tag",
+ .description = "VLAN ID (0-4095) [IP175D only]",
+ .name = "vid",
.get = ip17xx_get_tag,
.set = ip17xx_set_tag,
}
},
};
+static const struct switch_dev_ops ip17xx_ops = {
+ .attr_global = {
+ .attr = ip17xx_global,
+ .n_attr = ARRAY_SIZE(ip17xx_global),
+ },
+ .attr_port = {
+ .attr = ip17xx_port,
+ .n_attr = ARRAY_SIZE(ip17xx_port),
+ },
+ .attr_vlan = {
+ .attr = ip17xx_vlan,
+ .n_attr = ARRAY_SIZE(ip17xx_vlan),
+ },
+
+ .get_port_pvid = ip17xx_get_pvid,
+ .set_port_pvid = ip17xx_set_pvid,
+ .get_vlan_ports = ip17xx_get_ports,
+ .set_vlan_ports = ip17xx_set_ports,
+ .apply_config = ip17xx_apply,
+ .reset_switch = ip17xx_reset,
+};
+
static int ip17xx_probe(struct phy_device *pdev)
{
struct ip17xx_state *state;
return -ENOMEM;
dev = &state->dev;
- dev->attr_global.attr = ip17xx_global;
- dev->attr_global.n_attr = ARRAY_SIZE(ip17xx_global);
- dev->attr_port.attr = ip17xx_port;
- dev->attr_port.n_attr = ARRAY_SIZE(ip17xx_port);
- dev->attr_vlan.attr = ip17xx_vlan;
- dev->attr_vlan.n_attr = ARRAY_SIZE(ip17xx_vlan);
-
- dev->get_port_pvid = ip17xx_get_pvid;
- dev->set_port_pvid = ip17xx_set_pvid;
- dev->get_vlan_ports = ip17xx_get_ports;
- dev->set_vlan_ports = ip17xx_set_ports;
- dev->apply_config = ip17xx_apply;
- dev->reset_switch = ip17xx_reset;
-
- dev->priv = state;
+
pdev->priv = state;
state->mii_bus = pdev->bus;
dev->cpu_port = state->regs->CPU_PORT;
dev->ports = state->regs->NUM_PORTS;
dev->name = state->regs->NAME;
+ dev->ops = &ip17xx_ops;
pr_info("IP17xx: Found %s at %s\n", dev->name, dev_name(&pdev->dev));
return 0;