#include <linux/delay.h>
#include <linux/skbuff.h>
#include <linux/switch.h>
-#include <linux/phy.h>
#include <linux/rtl8366rb.h>
#include "rtl8366_smi.h"
#endif
#define RTL8366S_DRIVER_DESC "Realtek RTL8366RB ethernet switch driver"
-#define RTL8366S_DRIVER_VER "0.2.0"
+#define RTL8366S_DRIVER_VER "0.2.2"
#define RTL8366S_PHY_NO_MAX 4
#define RTL8366S_PHY_PAGE_MAX 7
struct rtl8366rb {
struct device *parent;
struct rtl8366_smi smi;
- struct mii_bus *mii_bus;
- int mii_irq[PHY_MAX_ADDR];
struct switch_dev dev;
char buf[4096];
#ifdef CONFIG_RTL8366S_PHY_DEBUG_FS
{ 70, 2, "IfOutBroadcastPkts " },
};
+static inline struct rtl8366rb *smi_to_rtl8366rb(struct rtl8366_smi *smi)
+{
+ return container_of(smi, struct rtl8366rb, smi);
+}
+
static inline struct rtl8366rb *sw_to_rtl8366rb(struct switch_dev *sw)
{
return container_of(sw, struct rtl8366rb, dev);
node = debugfs_create_x16("reg", S_IRUGO | S_IWUSR, root, &gl_dbg_reg);
if (!node) {
- dev_err(rtl->parent, "Creating debugfs file reg failed\n");
+ dev_err(rtl->parent, "Creating debugfs file '%s' failed\n",
+ "reg");
return;
}
node = debugfs_create_file("val", S_IRUGO | S_IWUSR, root, rtl,
&fops_rtl8366rb_regs);
if (!node) {
- dev_err(rtl->parent, "Creating debugfs file val failed\n");
+ dev_err(rtl->parent, "Creating debugfs file '%s' failed\n",
+ "val");
return;
}
node = debugfs_create_file("vlan", S_IRUSR, root, rtl,
&fops_rtl8366rb_vlan);
if (!node) {
- dev_err(rtl->parent,
- "Creating debugfs file vlan failed\n");
+ dev_err(rtl->parent, "Creating debugfs file '%s' failed\n",
+ "vlan");
return;
}
node = debugfs_create_file("mibs", S_IRUSR, root, rtl,
&fops_rtl8366rb_mibs);
if (!node) {
- dev_err(rtl->parent,
- "Creating debugfs file mibs failed\n");
+ dev_err(rtl->parent, "Creating debugfs file '%s' failed\n",
+ "mibs");
return;
}
}
if (val->port_vlan % 2)
data = data >> 8;
- len = snprintf(rtl->buf, sizeof(rtl->buf),
- "port:%d link:%s speed:%s %s-duplex %s%s%s",
- val->port_vlan,
- (data & RTL8366S_PORT_STATUS_LINK_MASK) ? "up" : "down",
- rtl8366rb_speed_str(data &
+ if (data & RTL8366S_PORT_STATUS_LINK_MASK) {
+ len = snprintf(rtl->buf, sizeof(rtl->buf),
+ "port:%d link:up speed:%s %s-duplex %s%s%s",
+ val->port_vlan,
+ rtl8366rb_speed_str(data &
RTL8366S_PORT_STATUS_SPEED_MASK),
- (data & RTL8366S_PORT_STATUS_DUPLEX_MASK) ?
- "full" : "half",
- (data & RTL8366S_PORT_STATUS_TXPAUSE_MASK) ?
- "tx-pause ": "",
- (data & RTL8366S_PORT_STATUS_RXPAUSE_MASK) ?
- "rx-pause " : "",
- (data & RTL8366S_PORT_STATUS_AN_MASK) ? "nway ": "");
+ (data & RTL8366S_PORT_STATUS_DUPLEX_MASK) ?
+ "full" : "half",
+ (data & RTL8366S_PORT_STATUS_TXPAUSE_MASK) ?
+ "tx-pause ": "",
+ (data & RTL8366S_PORT_STATUS_RXPAUSE_MASK) ?
+ "rx-pause " : "",
+ (data & RTL8366S_PORT_STATUS_AN_MASK) ?
+ "nway ": "");
+ } else {
+ len = snprintf(rtl->buf, sizeof(rtl->buf), "port:%d link: down",
+ val->port_vlan);
+ }
val->value.s = rtl->buf;
val->len = len;
static int rtl8366rb_mii_read(struct mii_bus *bus, int addr, int reg)
{
- struct rtl8366rb *rtl = bus->priv;
+ struct rtl8366rb *rtl = smi_to_rtl8366rb(bus->priv);
u32 val = 0;
int err;
static int rtl8366rb_mii_write(struct mii_bus *bus, int addr, int reg, u16 val)
{
- struct rtl8366rb *rtl = bus->priv;
+ struct rtl8366rb *rtl = smi_to_rtl8366rb(bus->priv);
u32 t;
int err;
return err;
}
-static int rtl8366rb_mii_init(struct rtl8366rb *rtl)
+static int rtl8366rb_mii_bus_match(struct mii_bus *bus)
{
- int ret;
- int i;
+ return (bus->read == rtl8366rb_mii_read &&
+ bus->write == rtl8366rb_mii_write);
+}
- rtl->mii_bus = mdiobus_alloc();
- if (rtl->mii_bus == NULL) {
- ret = -ENOMEM;
- goto err;
- }
+static int rtl8366rb_setup(struct rtl8366rb *rtl)
+{
+ int ret;
- rtl->mii_bus->priv = (void *) rtl;
- rtl->mii_bus->name = "rtl8366-rtl";
- rtl->mii_bus->read = rtl8366rb_mii_read;
- rtl->mii_bus->write = rtl8366rb_mii_write;
- snprintf(rtl->mii_bus->id, MII_BUS_ID_SIZE, "%s",
- dev_name(rtl->parent));
- rtl->mii_bus->parent = rtl->parent;
- rtl->mii_bus->phy_mask = ~(0x1f);
- rtl->mii_bus->irq = rtl->mii_irq;
- for (i = 0; i < PHY_MAX_ADDR; i++)
- rtl->mii_irq[i] = PHY_POLL;
-
- ret = mdiobus_register(rtl->mii_bus);
+ ret = rtl8366rb_reset_chip(rtl);
if (ret)
- goto err_free;
+ return ret;
+ rtl8366rb_debugfs_init(rtl);
return 0;
-
- err_free:
- mdiobus_free(rtl->mii_bus);
- err:
- return ret;
-}
-
-static void rtl8366rb_mii_cleanup(struct rtl8366rb *rtl)
-{
- mdiobus_unregister(rtl->mii_bus);
- mdiobus_free(rtl->mii_bus);
}
-static int rtl8366rb_mii_bus_match(struct mii_bus *bus)
+static int rtl8366rb_detect(struct rtl8366_smi *smi)
{
- return (bus->read == rtl8366rb_mii_read &&
- bus->write == rtl8366rb_mii_write);
-}
-
-static int rtl8366rb_setup(struct rtl8366rb *rtl)
-{
- struct rtl8366_smi *smi = &rtl->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(rtl->parent, "unable to read chip id\n");
+ dev_err(smi->parent, "unable to read chip id\n");
return ret;
}
case RTL8366S_CHIP_ID_8366:
break;
default:
- dev_err(rtl->parent, "unknown chip id (%04x)\n", chip_id);
+ dev_err(smi->parent, "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(rtl->parent, "unable to read chip version\n");
+ dev_err(smi->parent, "unable to read chip version\n");
return ret;
}
- dev_info(rtl->parent, "RTL%04x ver. %u chip found\n",
+ dev_info(smi->parent, "RTL%04x ver. %u chip found\n",
chip_id, chip_ver & RTL8366S_CHIP_VERSION_MASK);
- ret = rtl8366rb_reset_chip(rtl);
- if (ret)
- return ret;
-
- rtl8366rb_debugfs_init(rtl);
return 0;
}
+static struct rtl8366_smi_ops rtl8366rb_smi_ops = {
+ .detect = rtl8366rb_detect,
+ .mii_read = rtl8366rb_mii_read,
+ .mii_write = rtl8366rb_mii_write,
+};
+
static int __init rtl8366rb_probe(struct platform_device *pdev)
{
static int rtl8366_smi_version_printed;
smi->parent = &pdev->dev;
smi->gpio_sda = pdata->gpio_sda;
smi->gpio_sck = pdata->gpio_sck;
+ smi->ops = &rtl8366rb_smi_ops;
err = rtl8366_smi_init(smi);
if (err)
if (err)
goto err_clear_drvdata;
- err = rtl8366rb_mii_init(rtl);
- if (err)
- goto err_clear_drvdata;
-
err = rtl8366rb_switch_init(rtl);
if (err)
- goto err_mii_cleanup;
+ goto err_clear_drvdata;
return 0;
- err_mii_cleanup:
- rtl8366rb_mii_cleanup(rtl);
err_clear_drvdata:
platform_set_drvdata(pdev, NULL);
rtl8366_smi_cleanup(smi);
if (rtl) {
rtl8366rb_switch_cleanup(rtl);
rtl8366rb_debugfs_remove(rtl);
- rtl8366rb_mii_cleanup(rtl);
platform_set_drvdata(pdev, NULL);
rtl8366_smi_cleanup(&rtl->smi);
kfree(rtl);