1
0
mirror of git://projects.qi-hardware.com/openwrt-xburst.git synced 2024-11-24 04:56:14 +02:00

generic: rtl8366: move mii bus handling to the rtl8366_smi code

git-svn-id: svn://svn.openwrt.org/openwrt/trunk@21911 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
juhosg 2010-06-26 19:16:01 +00:00
parent d2c03b9bff
commit 5e66606678
4 changed files with 75 additions and 108 deletions

View File

@ -14,6 +14,7 @@
#include <linux/delay.h>
#include <linux/gpio.h>
#include <linux/spinlock.h>
#include <linux/skbuff.h>
#include "rtl8366_smi.h"
@ -265,6 +266,47 @@ int rtl8366_smi_write_reg(struct rtl8366_smi *smi, u32 addr, u32 data)
}
EXPORT_SYMBOL_GPL(rtl8366_smi_write_reg);
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;
}
smi->mii_bus->priv = (void *) smi;
smi->mii_bus->name = dev_name(smi->parent);
smi->mii_bus->read = smi->ops->mii_read;
smi->mii_bus->write = smi->ops->mii_write;
snprintf(smi->mii_bus->id, MII_BUS_ID_SIZE, "%s",
dev_name(smi->parent));
smi->mii_bus->parent = smi->parent;
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);
}
int rtl8366_smi_init(struct rtl8366_smi *smi)
{
int err;
@ -300,6 +342,10 @@ int rtl8366_smi_init(struct rtl8366_smi *smi)
goto err_free_sck;
}
err = rtl8366_smi_mii_init(smi);
if (err)
goto err_free_sck;
return 0;
err_free_sck:
@ -313,6 +359,7 @@ EXPORT_SYMBOL_GPL(rtl8366_smi_init);
void rtl8366_smi_cleanup(struct rtl8366_smi *smi)
{
rtl8366_smi_mii_cleanup(smi);
gpio_free(smi->gpio_sck);
gpio_free(smi->gpio_sda);
}

View File

@ -11,19 +11,27 @@
#ifndef _RTL8366_SMI_H
#define _RTL8366_SMI_H
#include <linux/phy.h>
struct rtl8366_smi_ops;
struct mii_bus;
struct rtl8366_smi {
struct device *parent;
unsigned int gpio_sda;
unsigned int gpio_sck;
spinlock_t lock;
struct mii_bus *mii_bus;
int mii_irq[PHY_MAX_ADDR];
struct rtl8366_smi_ops *ops;
};
struct rtl8366_smi_ops {
int (*detect)(struct rtl8366_smi *smi);
int (*mii_read)(struct mii_bus *bus, int addr, int reg);
int (*mii_write)(struct mii_bus *bus, int addr, int reg, u16 val);
};
int rtl8366_smi_init(struct rtl8366_smi *smi);

View File

@ -16,7 +16,6 @@
#include <linux/delay.h>
#include <linux/skbuff.h>
#include <linux/switch.h>
#include <linux/phy.h>
#include <linux/rtl8366rb.h>
#include "rtl8366_smi.h"
@ -148,8 +147,6 @@
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
@ -225,6 +222,11 @@ static struct mib_counter rtl8366rb_mib_counters[RTL8366S_MIB_COUNT] = {
{ 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);
@ -1500,7 +1502,7 @@ static void rtl8366rb_switch_cleanup(struct rtl8366rb *rtl)
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;
@ -1513,7 +1515,7 @@ static int rtl8366rb_mii_read(struct mii_bus *bus, int addr, int reg)
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;
@ -1524,47 +1526,6 @@ static int rtl8366rb_mii_write(struct mii_bus *bus, int addr, int reg, u16 val)
return err;
}
static int rtl8366rb_mii_init(struct rtl8366rb *rtl)
{
int ret;
int i;
rtl->mii_bus = mdiobus_alloc();
if (rtl->mii_bus == NULL) {
ret = -ENOMEM;
goto err;
}
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);
if (ret)
goto err_free;
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)
{
return (bus->read == rtl8366rb_mii_read &&
@ -1618,6 +1579,8 @@ static int rtl8366rb_detect(struct rtl8366_smi *smi)
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)
@ -1664,18 +1627,12 @@ static int __init rtl8366rb_probe(struct platform_device *pdev)
if (err)
goto err_clear_drvdata;
err = rtl8366rb_mii_init(rtl);
err = rtl8366rb_switch_init(rtl);
if (err)
goto err_clear_drvdata;
err = rtl8366rb_switch_init(rtl);
if (err)
goto err_mii_cleanup;
return 0;
err_mii_cleanup:
rtl8366rb_mii_cleanup(rtl);
err_clear_drvdata:
platform_set_drvdata(pdev, NULL);
rtl8366_smi_cleanup(smi);
@ -1718,7 +1675,6 @@ static int __devexit rtl8366rb_remove(struct platform_device *pdev)
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);

View File

@ -16,7 +16,6 @@
#include <linux/delay.h>
#include <linux/skbuff.h>
#include <linux/switch.h>
#include <linux/phy.h>
#include <linux/rtl8366s.h>
#include "rtl8366_smi.h"
@ -149,8 +148,6 @@
struct rtl8366s {
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
@ -225,6 +222,11 @@ static struct mib_counter rtl8366s_mib_counters[RTL8366S_MIB_COUNT] = {
{ 70, 2, "IfOutBroadcastPkts " },
};
static inline struct rtl8366s *smi_to_rtl8366s(struct rtl8366_smi *smi)
{
return container_of(smi, struct rtl8366s, smi);
}
static inline struct rtl8366s *sw_to_rtl8366s(struct switch_dev *sw)
{
return container_of(sw, struct rtl8366s, dev);
@ -1469,7 +1471,7 @@ static void rtl8366s_switch_cleanup(struct rtl8366s *rtl)
static int rtl8366s_mii_read(struct mii_bus *bus, int addr, int reg)
{
struct rtl8366s *rtl = bus->priv;
struct rtl8366s *rtl = smi_to_rtl8366s(bus->priv);
u32 val = 0;
int err;
@ -1482,7 +1484,7 @@ static int rtl8366s_mii_read(struct mii_bus *bus, int addr, int reg)
static int rtl8366s_mii_write(struct mii_bus *bus, int addr, int reg, u16 val)
{
struct rtl8366s *rtl = bus->priv;
struct rtl8366s *rtl = smi_to_rtl8366s(bus->priv);
u32 t;
int err;
@ -1493,47 +1495,6 @@ static int rtl8366s_mii_write(struct mii_bus *bus, int addr, int reg, u16 val)
return err;
}
static int rtl8366s_mii_init(struct rtl8366s *rtl)
{
int ret;
int i;
rtl->mii_bus = mdiobus_alloc();
if (rtl->mii_bus == NULL) {
ret = -ENOMEM;
goto err;
}
rtl->mii_bus->priv = (void *) rtl;
rtl->mii_bus->name = "rtl8366-rtl";
rtl->mii_bus->read = rtl8366s_mii_read;
rtl->mii_bus->write = rtl8366s_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);
if (ret)
goto err_free;
return 0;
err_free:
mdiobus_free(rtl->mii_bus);
err:
return ret;
}
static void rtl8366s_mii_cleanup(struct rtl8366s *rtl)
{
mdiobus_unregister(rtl->mii_bus);
mdiobus_free(rtl->mii_bus);
}
static int rtl8366s_mii_bus_match(struct mii_bus *bus)
{
return (bus->read == rtl8366s_mii_read &&
@ -1587,6 +1548,8 @@ static int rtl8366s_detect(struct rtl8366_smi *smi)
static struct rtl8366_smi_ops rtl8366s_smi_ops = {
.detect = rtl8366s_detect,
.mii_read = rtl8366s_mii_read,
.mii_write = rtl8366s_mii_write,
};
static int __init rtl8366s_probe(struct platform_device *pdev)
@ -1633,18 +1596,12 @@ static int __init rtl8366s_probe(struct platform_device *pdev)
if (err)
goto err_clear_drvdata;
err = rtl8366s_mii_init(rtl);
err = rtl8366s_switch_init(rtl);
if (err)
goto err_clear_drvdata;
err = rtl8366s_switch_init(rtl);
if (err)
goto err_mii_cleanup;
return 0;
err_mii_cleanup:
rtl8366s_mii_cleanup(rtl);
err_clear_drvdata:
platform_set_drvdata(pdev, NULL);
rtl8366_smi_cleanup(smi);
@ -1687,7 +1644,6 @@ static int __devexit rtl8366s_remove(struct platform_device *pdev)
if (rtl) {
rtl8366s_switch_cleanup(rtl);
rtl8366s_debugfs_remove(rtl);
rtl8366s_mii_cleanup(rtl);
platform_set_drvdata(pdev, NULL);
rtl8366_smi_cleanup(&rtl->smi);
kfree(rtl);