- len += snprintf(buf, sizeof(buf),
- "Read failed (reg: 0x%04x)\n", reg);
- return simple_read_from_buffer(user_buf, count, ppos, buf, len);
- }
-
- len += snprintf(buf, sizeof(buf), "reg = 0x%04x, val = 0x%04x\n",
- reg, t);
-
- return simple_read_from_buffer(user_buf, count, ppos, buf, len);
-}
-
-static ssize_t rtl8366_write_debugfs_reg(struct file *file,
- const char __user *user_buf,
- size_t count, loff_t *ppos)
-{
- unsigned long data;
- u32 reg = g_dbg_reg;
- int err;
- char buf[50];
- size_t len;
- struct rtl8366_smi *smi = (struct rtl8366_smi *)file->private_data;
-
- len = min(count, sizeof(buf) - 1);
- if (copy_from_user(buf, user_buf, len)) {
- dev_err(&smi->pdev->dev, "copy from user failed\n");
- return -EFAULT;
- }
-
- buf[len] = '\0';
- if (len > 0 && buf[len - 1] == '\n')
- buf[len - 1] = '\0';
-
-
- if (strict_strtoul(buf, 16, &data)) {
- dev_err(&smi->pdev->dev, "Invalid reg value %s\n", buf);
- } else {
- err = rtl8366_smi_write_reg(smi, reg, data);
- if (err) {
- dev_err(&smi->pdev->dev,
- "writing reg 0x%04x val 0x%04lx failed\n",
- reg, data);
- }
- }
-
- return count;
-}
-
-static const struct file_operations fops_rtl8366_regs = {
- .read = rtl8366_read_debugfs_reg,
- .write = rtl8366_write_debugfs_reg,
- .open = rtl8366_debugfs_open,
- .owner = THIS_MODULE
-};
-
-static const struct file_operations fops_rtl8366_vlan = {
- .read = rtl8366_read_debugfs_vlan,
- .open = rtl8366_debugfs_open,
- .owner = THIS_MODULE
-};
-
-static const struct file_operations fops_rtl8366_mibs = {
- .read = rtl8366_read_debugfs_mibs,
- .open = rtl8366_debugfs_open,
- .owner = THIS_MODULE
-};
-
-static void rtl8366_debugfs_init(struct rtl8366_smi *smi)
-{
- struct dentry *node;
- struct dentry *root;
-
- if (!smi->debugfs_root)
- smi->debugfs_root = debugfs_create_dir("rtl8366s", NULL);
-
- if (!smi->debugfs_root) {
- dev_err(&smi->pdev->dev, "Unable to create debugfs dir\n");
- return;
- }
- root = smi->debugfs_root;
-
- node = debugfs_create_x16("reg", S_IRUGO | S_IWUSR, root, &g_dbg_reg);
- if (!node) {
- dev_err(&smi->pdev->dev, "Creating debugfs file reg failed\n");
- return;
- }
-
- node = debugfs_create_file("val", S_IRUGO | S_IWUSR, root, smi,
- &fops_rtl8366_regs);
- if (!node) {
- dev_err(&smi->pdev->dev, "Creating debugfs file val failed\n");
- return;
- }
-
- node = debugfs_create_file("vlan", S_IRUSR, root, smi,
- &fops_rtl8366_vlan);
- if (!node) {
- dev_err(&smi->pdev->dev, "Creating debugfs file vlan "
- "failed\n");
- return;
- }
-
- node = debugfs_create_file("mibs", S_IRUSR, root, smi,
- &fops_rtl8366_mibs);
- if (!node) {
- dev_err(&smi->pdev->dev, "Creating debugfs file mibs "
- "xfailed\n");
- return;
- }
-}
-
-static void rtl8366_debugfs_remove(struct rtl8366_smi *smi)
-{
- if (smi->debugfs_root) {
- debugfs_remove_recursive(smi->debugfs_root);
- smi->debugfs_root = NULL;
- }
-}
-
-#else
-static inline void rtl8366_debugfs_init(struct rtl8366_smi *smi) {}
-static inline void rtl8366_debugfs_remove(struct rtl8366_smi *smi) {}
-#endif
-
-static int rtl8366_global_reset_mibs(struct switch_dev *dev,
- const struct switch_attr *attr,
- struct switch_val *val)
-{
- u32 data = 0;
- struct rtl8366_smi *smi = to_rtl8366(dev);
-
- if (val->value.i == 1) {
- rtl8366_smi_read_reg(smi, RTL8366S_MIB_CTRL_REG, &data);
- data |= (1 << 2);
- rtl8366_smi_write_reg(smi, RTL8366S_MIB_CTRL_REG, data);
- }
-
- return 0;
-}
-
-static int rtl8366_get_vlan(struct switch_dev *dev,
- const struct switch_attr *attr,
- struct switch_val *val)
-{
- u32 data;
- struct rtl8366_smi *smi = to_rtl8366(dev);
-
- if (attr->ofs == 1) {
- rtl8366_smi_read_reg(smi, RTL8366_CHIP_GLOBAL_CTRL_REG, &data);
-
- if (data & RTL8366_CHIP_CTRL_VLAN)
- val->value.i = 1;
- else
- val->value.i = 0;
- } else if (attr->ofs == 2) {
- rtl8366_smi_read_reg(smi, RTL8366S_VLAN_TB_CTRL_REG, &data);
-
- if (data & 0x0001)
- val->value.i = 1;
- else
- val->value.i = 0;
- }
-
- return 0;
-}
-
-static int rtl8366_global_get_blinkrate(struct switch_dev *dev,
- const struct switch_attr *attr,
- struct switch_val *val)
-{
- u32 data;
- struct rtl8366_smi *smi = to_rtl8366(dev);
- rtl8366_smi_read_reg(smi, RTL8366_LED_BLINKRATE_REG, &data);
-
- val->value.i = (data & (RTL8366_LED_BLINKRATE_MASK));
-
- return 0;
-}
-
-static int rtl8366_global_set_blinkrate(struct switch_dev *dev,
- const struct switch_attr *attr,
- struct switch_val *val)
-{
- u32 data;
- struct rtl8366_smi *smi = to_rtl8366(dev);
-
- if (val->value.i >= 6)
- return -EINVAL;
-
- rtl8366_smi_read_reg(smi, RTL8366_LED_BLINKRATE_REG, &data);
-
- data &= ~(data & RTL8366_LED_BLINKRATE_MASK);
- data |= val->value.i;
-
- rtl8366_smi_write_reg(smi, RTL8366_LED_BLINKRATE_REG, data);
-
- return 0;
-}
-
-static int rtl8366_set_vlan(struct switch_dev *dev,
- const struct switch_attr *attr,
- struct switch_val *val)
-{
- struct rtl8366_smi *smi = to_rtl8366(dev);
-
- if (attr->ofs == 1)
- return rtl8366_vlan_set_vlan(smi, val->value.i);
- else
- return rtl8366_vlan_set_4ktable(smi, val->value.i);
-}
-
-static int rtl8366_init_vlan(struct switch_dev *dev,
- const struct switch_attr *attr,
- struct switch_val *val)
-{
- struct rtl8366_smi *smi = to_rtl8366(dev);
- return rtl8366s_reset_vlan(smi);
-}
-
-static int rtl8366_attr_get_port_link(struct switch_dev *dev,
- const struct switch_attr *attr,
- struct switch_val *val)
-{
- char buf[1024];
- u32 len = 0, data = 0;
- int speed, duplex, link, txpause, rxpause, nway;
- struct rtl8366_smi *smi = to_rtl8366(dev);
-
- if (val->port_vlan >= RTL8366_NUM_PORTS)
- return -EINVAL;
-
- memset(buf, '\0', sizeof(buf));
- rtl8366_smi_read_reg(smi, RTL8366S_PORT_LINK_STATUS_BASE +
- (val->port_vlan >> 1),
- &data);
-
- if (val->port_vlan & 0x1)
- data = data >> 8;
-
- speed = (data & RTL8366S_PORT_STATUS_SPEED_MASK);
- duplex = (data & RTL8366S_PORT_STATUS_DUPLEX_MASK) >> 2;
- link = (data & RTL8366S_PORT_STATUS_LINK_MASK) >> 4;
- txpause = (data & RTL8366S_PORT_STATUS_TXPAUSE_MASK) >> 5;
- rxpause = (data & RTL8366S_PORT_STATUS_RXPAUSE_MASK) >> 6;
- nway = (data & RTL8366S_PORT_STATUS_AN_MASK) >> 7;
-
- len += snprintf(buf + len, sizeof(buf) - len, "Port %d: ",
- val->port_vlan);
-
- if (link)
- len += snprintf(buf + len, sizeof(buf) - len,
- "Link UP, Speed: ");
- else
- len += snprintf(buf + len, sizeof(buf) - len,
- "Link DOWN, Speed: ");
-
- if (speed == 0)
- len += snprintf(buf + len, sizeof(buf) - len, "10Base-TX ");
- else if (speed == 1)
- len += snprintf(buf + len, sizeof(buf) - len, "100Base-TX ");
- else if (speed == 2)
- len += snprintf(buf + len, sizeof(buf) - len, "1000Base-TX ");
-
- if (duplex)
- len += snprintf(buf + len, sizeof(buf) - len, "Full-Duplex, ");
- else
- len += snprintf(buf + len, sizeof(buf) - len, "Half-Duplex, ");
-
- if (txpause)
- len += snprintf(buf + len, sizeof(buf) - len, "TX-Pause ");
- if (rxpause)
- len += snprintf(buf + len, sizeof(buf) - len, "RX-Pause ");
- if (nway)
- len += snprintf(buf + len, sizeof(buf) - len, "nway ");
-
- val->value.s = buf;
- val->len = len;
-
- return 0;
-}
-
-static int rtl8366_attr_get_vlan_info(struct switch_dev *dev,
- const struct switch_attr *attr,
- struct switch_val *val)
-{
- int i;
- char buf[1024];
- u32 len = 0;
- struct rtl8366s_vlanconfig vlanMC;
- struct rtl8366s_vlan4kentry vlan4K;
- struct rtl8366_smi *smi = to_rtl8366(dev);
-
- if (val->port_vlan >= RTL8366_NUM_PORTS)
- return -EINVAL;
-
- memset(buf, '\0', sizeof(buf));
- memset(&vlanMC, '\0', sizeof(struct rtl8366s_vlanconfig));
- memset(&vlan4K, '\0', sizeof(struct rtl8366s_vlan4kentry));
-
- rtl8366s_get_vlan_member_config(smi, val->port_vlan, &vlanMC);
- rtl8366s_get_vlan_4k_entry(smi, vlanMC.vid, &vlan4K);
-
- len += snprintf(buf + len, sizeof(buf) - len, "VLAN %d: Ports: ",
- val->port_vlan);
-
- for (i = 0; i < RTL8366_NUM_PORTS; ++i) {
- int index = 0;
- if (!rtl8366_get_port_vlan_index(smi, i, &index) &&
- index == val->port_vlan)
- len += snprintf(buf + len, sizeof(buf) - len, "%d", i);
- }
- len += snprintf(buf + len, sizeof(buf) - len, "\n");
-
- len += snprintf(buf + len, sizeof(buf) - len,
- "\t\t vid \t prio \t member \t untag \t fid\n");
- len += snprintf(buf + len, sizeof(buf) - len, "\tMC:\t");
- len += snprintf(buf + len, sizeof(buf) - len,
- "%d \t %d \t 0x%04x \t 0x%04x \t %d\n",
- vlanMC.vid, vlanMC.priority, vlanMC.member,
- vlanMC.untag, vlanMC.fid);
- len += snprintf(buf + len, sizeof(buf) - len, "\t4K:\t");
- len += snprintf(buf + len, sizeof(buf) - len,
- "%d \t \t 0x%04x \t 0x%04x \t %d",
- vlan4K.vid, vlan4K.member, vlan4K.untag, vlan4K.fid);
-
- val->value.s = buf;
- val->len = len;
-
- return 0;
-}
-
-static int rtl8366_set_port_led(struct switch_dev *dev,
- const struct switch_attr *attr,
- struct switch_val *val)
-{
- u32 data = 0;
- struct rtl8366_smi *smi = to_rtl8366(dev);
- if (val->port_vlan >= RTL8366_NUM_PORTS ||
- (1 << val->port_vlan) == RTL8366_PORT_UNKNOWN)
- return -EINVAL;
-
- if (val->port_vlan == RTL8366_PORT_NUM_CPU) {
- rtl8366_smi_read_reg(smi, RTL8366_LED_BLINKRATE_REG, &data);
- data = (data & (~(0xF << 4))) | (val->value.i << 4);
- rtl8366_smi_write_reg(smi, RTL8366_LED_BLINKRATE_REG, data);
- } else {
- rtl8366_smi_read_reg(smi, RTL8366_LED_CTRL_REG, &data);
- data = (data & (~(0xF << (val->port_vlan * 4)))) |
- (val->value.i << (val->port_vlan * 4));
- rtl8366_smi_write_reg(smi, RTL8366_LED_CTRL_REG, data);
- }
-
- return 0;
-}
-
-static int rtl8366_get_port_led(struct switch_dev *dev,
- const struct switch_attr *attr,
- struct switch_val *val)
-{
- u32 data = 0;
- struct rtl8366_smi *smi = to_rtl8366(dev);
- if (val->port_vlan >= RTL8366_NUM_LEDGROUPS)
- return -EINVAL;
-
- rtl8366_smi_read_reg(smi, RTL8366_LED_CTRL_REG, &data);
- val->value.i = (data >> (val->port_vlan * 4)) & 0x000F;
-
- return 0;
-}
-
-static int rtl8366_reset_port_mibs(struct switch_dev *dev,
- const struct switch_attr *attr,
- struct switch_val *val)
-{
- u32 data = 0;
- struct rtl8366_smi *smi = to_rtl8366(dev);
- if (val->port_vlan >= RTL8366_NUM_PORTS)
- return -EINVAL;
-
- rtl8366_smi_read_reg(smi, RTL8366S_MIB_CTRL_REG, &data);
- data |= (1 << (val->port_vlan + 3));
- rtl8366_smi_write_reg(smi, RTL8366S_MIB_CTRL_REG, data);
-
- return 0;
-}
-
-static int rtl8366_get_port_mib(struct switch_dev *dev,
- const struct switch_attr *attr,
- struct switch_val *val)
-{
- char buf[2048];
- int i, len = 0;
- unsigned long long counter = 0;
- struct rtl8366_smi *smi = to_rtl8366(dev);
- if (val->port_vlan >= RTL8366_NUM_PORTS)
- return -EINVAL;
-
- len += snprintf(buf + len, sizeof(buf) - len, "Port %d MIB counters\n",
- val->port_vlan);
- for (i = 0; i < RTL8366S_MIB_COUNT; ++i) {
-
- len += snprintf(buf + len, sizeof(buf) - len,
- "%d:%s\t", i, MIBCOUNTERS[i]);
- if (!rtl8366_get_mib_counter(smi, i, val->port_vlan, &counter))
- len += snprintf(buf + len, sizeof(buf) - len,
- "[%llu]\n", counter);
- else
- len += snprintf(buf + len, sizeof(buf) - len,
- "[error]\n");
- }
-
- val->value.s = buf;
- val->len = len;
- return 0;
-}
-
-static int rtl8366_set_member(struct switch_dev *dev,
- const struct switch_attr *attr,
- struct switch_val *val)
-{
- struct rtl8366s_vlanconfig vlanMC;
- struct rtl8366s_vlan4kentry vlan4K;
- struct rtl8366_smi *smi = to_rtl8366(dev);
- memset(&vlanMC, '\0', sizeof(struct rtl8366s_vlanconfig));
- memset(&vlan4K, '\0', sizeof(struct rtl8366s_vlan4kentry));
-
- if (val->port_vlan >= RTL8366_NUM_VLANS)
- return -EINVAL;
-
- rtl8366s_get_vlan_member_config(smi, val->port_vlan, &vlanMC);
-
- rtl8366s_get_vlan_4k_entry(smi, vlanMC.vid, &vlan4K);
-
- vlan4K.member = vlanMC.member = val->value.i;
- rtl8366s_set_vlan_member_config(smi, val->port_vlan, &vlanMC);
- rtl8366s_set_vlan_4k_entry(smi, &vlan4K);
-
- return 0;
-}
-
-static int rtl8366_get_member(struct switch_dev *dev,
- const struct switch_attr *attr,
- struct switch_val *val)
-{
- struct rtl8366s_vlanconfig vlanMC;
- struct rtl8366s_vlan4kentry vlan4K;
- struct rtl8366_smi *smi = to_rtl8366(dev);
- memset(&vlanMC, '\0', sizeof(struct rtl8366s_vlanconfig));
- memset(&vlan4K, '\0', sizeof(struct rtl8366s_vlan4kentry));
-
- if (val->port_vlan >= RTL8366_NUM_VLANS)
- return -EINVAL;
-
- rtl8366s_get_vlan_member_config(smi, val->port_vlan, &vlanMC);
-
- rtl8366s_get_vlan_4k_entry(smi, vlanMC.vid, &vlan4K);
-
- val->value.i = vlanMC.member;
-
- return 0;
-}
-
-static int rtl8366_set_untag(struct switch_dev *dev,
- const struct switch_attr *attr,
- struct switch_val *val)
-{
- struct rtl8366s_vlanconfig vlanMC;
- struct rtl8366s_vlan4kentry vlan4K;
- struct rtl8366_smi *smi = to_rtl8366(dev);
- memset(&vlanMC, '\0', sizeof(struct rtl8366s_vlanconfig));
- memset(&vlan4K, '\0', sizeof(struct rtl8366s_vlan4kentry));
-
- if (val->port_vlan >= RTL8366_NUM_VLANS)
- return -EINVAL;
-
- rtl8366s_get_vlan_member_config(smi, val->port_vlan, &vlanMC);
- rtl8366s_get_vlan_4k_entry(smi, vlanMC.vid, &vlan4K);
-
- vlan4K.untag = vlanMC.untag = val->value.i;
- rtl8366s_set_vlan_member_config(smi, val->port_vlan, &vlanMC);
- rtl8366s_set_vlan_4k_entry(smi, &vlan4K);
-
- return 0;
-}
-
-static int rtl8366_get_untag(struct switch_dev *dev,
- const struct switch_attr *attr,
- struct switch_val *val)
-{
- struct rtl8366s_vlanconfig vlanMC;
- struct rtl8366s_vlan4kentry vlan4K;
- struct rtl8366_smi *smi = to_rtl8366(dev);
- memset(&vlanMC, '\0', sizeof(struct rtl8366s_vlanconfig));
- memset(&vlan4K, '\0', sizeof(struct rtl8366s_vlan4kentry));
-
- if (val->port_vlan >= RTL8366_NUM_VLANS)
- return -EINVAL;
-
- rtl8366s_get_vlan_member_config(smi, val->port_vlan, &vlanMC);
- rtl8366s_get_vlan_4k_entry(smi, vlanMC.vid, &vlan4K);
-
-
- val->value.i = vlanMC.untag;
-
- return 0;
-}
-
-static int rtl8366_get_port_pvid(struct switch_dev *dev, int port, int *val)
-{
- struct rtl8366_smi *smi = to_rtl8366(dev);
- return rtl8366_get_vlan_port_pvid(smi, port, val);
-}
-
-static int rtl8366_set_port_pvid(struct switch_dev *dev, int port, int val)
-{
- struct rtl8366_smi *smi = to_rtl8366(dev);
- return rtl8366_set_vlan_port_pvid(smi, port, val);
-}
-
-static int rtl8366_reset_switch(struct switch_dev *dev)
-{
- struct rtl8366_smi *smi = to_rtl8366(dev);
- rtl8366_smi_write_reg(smi, RTL8366_RESET_CTRL_REG,
- RTL8366_CHIP_CTRL_RESET_HW);
- return 0;
-}
-
-static struct switch_attr rtl8366_globals[] = {
- {
- .type = SWITCH_TYPE_INT,
- .name = "enable_vlan",
- .description = "Enable VLAN mode",
- .set = rtl8366_set_vlan,
- .get = rtl8366_get_vlan,
- .max = 1,
- .ofs = 1
- },
- {
- .type = SWITCH_TYPE_INT,
- .name = "enable_vlan4k",
- .description = "Enable VLAN 4K mode",
- .set = rtl8366_set_vlan,
- .get = rtl8366_get_vlan,
- .max = 1,
- .ofs = 2
- },
- {
- .type = SWITCH_TYPE_INT,
- .name = "init_vlan",
- .description = "Initialize VLAN tables to defaults",
- .set = rtl8366_init_vlan,
- .get = NULL,
- .max = 1
- },
-
- {
- .type = SWITCH_TYPE_INT,
- .name = "reset_mibs",
- .description = "Reset all MIB counters",
- .set = rtl8366_global_reset_mibs,
- .get = NULL,
- .max = 1
- },
- {
- .type = SWITCH_TYPE_INT,
- .name = "blinkrate",
- .description = "Get/Set LED blinking rate (0 = 43ms, 1 = 84ms,"
- " 2 = 120ms, 3 = 170ms, 4 = 340ms, 5 = 670ms)",
- .set = rtl8366_global_set_blinkrate,
- .get = rtl8366_global_get_blinkrate,
- .max = 5
- },
-};
-
-static struct switch_attr rtl8366_port[] = {
- {
- .type = SWITCH_TYPE_STRING,
- .name = "link",
- .description = "Get port link information",
- .max = 1,
- .set = NULL,
- .get = rtl8366_attr_get_port_link
- },
- {
- .type = SWITCH_TYPE_INT,
- .name = "reset_mib",
- .description = "Reset single port MIB counters",
- .max = 1,
- .set = rtl8366_reset_port_mibs,
- .get = NULL
- },
- {
- .type = SWITCH_TYPE_STRING,
- .name = "mib",
- .description = "Get MIB counters for port",
- .max = 33,
- .set = NULL,
- .get = rtl8366_get_port_mib
- },
- {
- .type = SWITCH_TYPE_INT,
- .name = "led",
- .description = "Get/Set port group (0 - 3) led mode (0 - 15)",
- .max = 15,
- .set = rtl8366_set_port_led,
- .get = rtl8366_get_port_led
- },
-};
-
-static struct switch_attr rtl8366_vlan[] = {
- {
- .type = SWITCH_TYPE_INT,
- .name = "untag",
- .description = "Get/Set VLAN untag port set (bitmask)",
- .set = rtl8366_set_untag,
- .get = rtl8366_get_untag,
- .max = 63,
- },
- {
- .type = SWITCH_TYPE_INT,
- .name = "member",
- .description = "Get/Set VLAN member port set (bitmask)",
- .set = rtl8366_set_member,
- .get = rtl8366_get_member,
- .max = 63,
- },
- {
- .type = SWITCH_TYPE_STRING,
- .name = "info",
- .description = "Get vlan information",
- .max = 1,
- .set = NULL,
- .get = rtl8366_attr_get_vlan_info
- },
-};
-
-
-/* template */
-static struct switch_dev rtldev = {
- .name = "RTL8366S",
- .cpu_port = RTL8366_PORT_NUM_CPU,
- .ports = RTL8366_NUM_PORTS,
- .vlans = RTL8366_NUM_VLANS,
- .attr_global = {
- .attr = rtl8366_globals,
- .n_attr = ARRAY_SIZE(rtl8366_globals),
- },
- .attr_port = {
- .attr = rtl8366_port,
- .n_attr = ARRAY_SIZE(rtl8366_port),
- },
- .attr_vlan = {
- .attr = rtl8366_vlan,
- .n_attr = ARRAY_SIZE(rtl8366_vlan),
- },
-
- .get_port_pvid = rtl8366_get_port_pvid,
- .set_port_pvid = rtl8366_set_port_pvid,
- .reset_switch = rtl8366_reset_switch,
-};
-
-static int rtl8366_smi_mii_read(struct mii_bus *bus, int addr, int reg)
-{
- struct rtl8366_smi *smi = bus->priv;
- u32 val = 0;
- int err;
-
- err = rtl8366_smi_read_phy_reg(smi, addr, 0, reg, &val);
- if (err)
- return 0xffff;
-
- return val;
-}
-
-static int rtl8366_smi_mii_write(struct mii_bus *bus, int addr, int reg,
- u16 val)
-{
- struct rtl8366_smi *smi = bus->priv;
- u32 t;
- int err;
-
- err = rtl8366_smi_write_phy_reg(smi, addr, 0, reg, val);
- /* flush write */
- (void) rtl8366_smi_read_phy_reg(smi, addr, 0, reg, &t);
-
- return err;
-}
-
-static int rtl8366_smi_mii_init(struct rtl8366_smi *smi)
-{
- int ret;
- int i;
-
- smi->mii_bus = mdiobus_alloc();
- if (smi->mii_bus == NULL) {
- ret = -ENOMEM;
- goto err;
- }
-
- spin_lock_init(&smi->lock);
- smi->mii_bus->priv = (void *) smi;
- smi->mii_bus->name = "rtl8366-smi";
- smi->mii_bus->read = rtl8366_smi_mii_read;
- smi->mii_bus->write = rtl8366_smi_mii_write;
- snprintf(smi->mii_bus->id, MII_BUS_ID_SIZE, "%s",
- dev_name(&smi->pdev->dev));
- smi->mii_bus->parent = &smi->pdev->dev;
- smi->mii_bus->phy_mask = ~(0x1f);
- smi->mii_bus->irq = smi->mii_irq;
- for (i = 0; i < PHY_MAX_ADDR; i++)
- smi->mii_irq[i] = PHY_POLL;
-
- ret = mdiobus_register(smi->mii_bus);
- if (ret)
- goto err_free;
-
- return 0;
-
- err_free:
- mdiobus_free(smi->mii_bus);
- err:
- return ret;
-}
-
-static void rtl8366_smi_mii_cleanup(struct rtl8366_smi *smi)
-{
- mdiobus_unregister(smi->mii_bus);
- mdiobus_free(smi->mii_bus);
-}
-
-static int rtl8366_smi_setup(struct rtl8366_smi *smi)
-{
- u32 chip_id = 0;
- u32 chip_ver = 0;
- int ret;
-
- ret = rtl8366_smi_read_reg(smi, RTL8366S_CHIP_ID_REG, &chip_id);
- if (ret) {
- dev_err(&smi->pdev->dev, "unable to read chip id\n");
- return ret;
- }
-
- switch (chip_id) {
- case RTL8366S_CHIP_ID_8366:
- break;
- default:
- dev_err(&smi->pdev->dev, "unknown chip id (%04x)\n", chip_id);
- return -ENODEV;
- }
-
- ret = rtl8366_smi_read_reg(smi, RTL8366S_CHIP_VERSION_CTRL_REG,
- &chip_ver);
- if (ret) {
- dev_err(&smi->pdev->dev, "unable to read chip version\n");
- return ret;
- }
-
- dev_info(&smi->pdev->dev, "RTL%04x ver. %u chip found\n",
- chip_id, chip_ver & RTL8366S_CHIP_VERSION_MASK);
-
- rtl8366_debugfs_init(smi);
-
- return 0;
-}
-
-static int __init rtl8366_smi_probe(struct platform_device *pdev)
-{
- static int rtl8366_smi_version_printed;
- struct rtl8366_smi_platform_data *pdata;
- struct rtl8366_smi *smi;
- int err;
-
- if (!rtl8366_smi_version_printed++)
- printk(KERN_NOTICE RTL8366_SMI_DRIVER_DESC
- " version " RTL8366_SMI_DRIVER_VER"\n");
-
- pdata = pdev->dev.platform_data;
- if (!pdata) {
- dev_err(&pdev->dev, "no platform data specified\n");
- err = -EINVAL;
- goto err_out;
- }
-
- smi = kzalloc(sizeof(struct rtl8366_smi), GFP_KERNEL);
- if (!smi) {
- dev_err(&pdev->dev, "no memory for private data\n");
- err = -ENOMEM;