Date:2010-06-26 21:16:01 (8 years 5 months ago)
Author:juhosg
Commit:5e66606678426ebb01fbd81d6212fb6fff2f896c
Message: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
Files: target/linux/generic-2.6/files/drivers/net/phy/rtl8366_smi.c (4 diffs)
target/linux/generic-2.6/files/drivers/net/phy/rtl8366_smi.h (1 diff)
target/linux/generic-2.6/files/drivers/net/phy/rtl8366rb.c (9 diffs)
target/linux/generic-2.6/files/drivers/net/phy/rtl8366s.c (9 diffs)

Change Details

target/linux/generic-2.6/files/drivers/net/phy/rtl8366_smi.c
1414#include <linux/delay.h>
1515#include <linux/gpio.h>
1616#include <linux/spinlock.h>
17#include <linux/skbuff.h>
1718
1819#include "rtl8366_smi.h"
1920
...... 
265266}
266267EXPORT_SYMBOL_GPL(rtl8366_smi_write_reg);
267268
269static int rtl8366_smi_mii_init(struct rtl8366_smi *smi)
270{
271    int ret;
272    int i;
273
274    smi->mii_bus = mdiobus_alloc();
275    if (smi->mii_bus == NULL) {
276        ret = -ENOMEM;
277        goto err;
278    }
279
280    smi->mii_bus->priv = (void *) smi;
281    smi->mii_bus->name = dev_name(smi->parent);
282    smi->mii_bus->read = smi->ops->mii_read;
283    smi->mii_bus->write = smi->ops->mii_write;
284    snprintf(smi->mii_bus->id, MII_BUS_ID_SIZE, "%s",
285         dev_name(smi->parent));
286    smi->mii_bus->parent = smi->parent;
287    smi->mii_bus->phy_mask = ~(0x1f);
288    smi->mii_bus->irq = smi->mii_irq;
289    for (i = 0; i < PHY_MAX_ADDR; i++)
290        smi->mii_irq[i] = PHY_POLL;
291
292    ret = mdiobus_register(smi->mii_bus);
293    if (ret)
294        goto err_free;
295
296    return 0;
297
298 err_free:
299    mdiobus_free(smi->mii_bus);
300 err:
301    return ret;
302}
303
304static void rtl8366_smi_mii_cleanup(struct rtl8366_smi *smi)
305{
306    mdiobus_unregister(smi->mii_bus);
307    mdiobus_free(smi->mii_bus);
308}
309
268310int rtl8366_smi_init(struct rtl8366_smi *smi)
269311{
270312    int err;
...... 
300342        goto err_free_sck;
301343    }
302344
345    err = rtl8366_smi_mii_init(smi);
346    if (err)
347        goto err_free_sck;
348
303349    return 0;
304350
305351 err_free_sck:
...... 
313359
314360void rtl8366_smi_cleanup(struct rtl8366_smi *smi)
315361{
362    rtl8366_smi_mii_cleanup(smi);
316363    gpio_free(smi->gpio_sck);
317364    gpio_free(smi->gpio_sda);
318365}
target/linux/generic-2.6/files/drivers/net/phy/rtl8366_smi.h
1111#ifndef _RTL8366_SMI_H
1212#define _RTL8366_SMI_H
1313
14#include <linux/phy.h>
15
1416struct rtl8366_smi_ops;
17struct mii_bus;
1518
1619struct rtl8366_smi {
1720    struct device *parent;
1821    unsigned int gpio_sda;
1922    unsigned int gpio_sck;
2023    spinlock_t lock;
24    struct mii_bus *mii_bus;
25    int mii_irq[PHY_MAX_ADDR];
2126
2227    struct rtl8366_smi_ops *ops;
2328};
2429
2530struct rtl8366_smi_ops {
2631    int (*detect)(struct rtl8366_smi *smi);
32
33    int (*mii_read)(struct mii_bus *bus, int addr, int reg);
34    int (*mii_write)(struct mii_bus *bus, int addr, int reg, u16 val);
2735};
2836
2937int rtl8366_smi_init(struct rtl8366_smi *smi);
target/linux/generic-2.6/files/drivers/net/phy/rtl8366rb.c
1616#include <linux/delay.h>
1717#include <linux/skbuff.h>
1818#include <linux/switch.h>
19#include <linux/phy.h>
2019#include <linux/rtl8366rb.h>
2120
2221#include "rtl8366_smi.h"
...... 
148147struct rtl8366rb {
149148    struct device *parent;
150149    struct rtl8366_smi smi;
151    struct mii_bus *mii_bus;
152    int mii_irq[PHY_MAX_ADDR];
153150    struct switch_dev dev;
154151    char buf[4096];
155152#ifdef CONFIG_RTL8366S_PHY_DEBUG_FS
...... 
225222    { 70, 2, "IfOutBroadcastPkts " },
226223};
227224
225static inline struct rtl8366rb *smi_to_rtl8366rb(struct rtl8366_smi *smi)
226{
227    return container_of(smi, struct rtl8366rb, smi);
228}
229
228230static inline struct rtl8366rb *sw_to_rtl8366rb(struct switch_dev *sw)
229231{
230232    return container_of(sw, struct rtl8366rb, dev);
...... 
15001502
15011503static int rtl8366rb_mii_read(struct mii_bus *bus, int addr, int reg)
15021504{
1503    struct rtl8366rb *rtl = bus->priv;
1505    struct rtl8366rb *rtl = smi_to_rtl8366rb(bus->priv);
15041506    u32 val = 0;
15051507    int err;
15061508
...... 
15131515
15141516static int rtl8366rb_mii_write(struct mii_bus *bus, int addr, int reg, u16 val)
15151517{
1516    struct rtl8366rb *rtl = bus->priv;
1518    struct rtl8366rb *rtl = smi_to_rtl8366rb(bus->priv);
15171519    u32 t;
15181520    int err;
15191521
...... 
15241526    return err;
15251527}
15261528
1527static int rtl8366rb_mii_init(struct rtl8366rb *rtl)
1528{
1529    int ret;
1530    int i;
1531
1532    rtl->mii_bus = mdiobus_alloc();
1533    if (rtl->mii_bus == NULL) {
1534        ret = -ENOMEM;
1535        goto err;
1536    }
1537
1538    rtl->mii_bus->priv = (void *) rtl;
1539    rtl->mii_bus->name = "rtl8366-rtl";
1540    rtl->mii_bus->read = rtl8366rb_mii_read;
1541    rtl->mii_bus->write = rtl8366rb_mii_write;
1542    snprintf(rtl->mii_bus->id, MII_BUS_ID_SIZE, "%s",
1543         dev_name(rtl->parent));
1544    rtl->mii_bus->parent = rtl->parent;
1545    rtl->mii_bus->phy_mask = ~(0x1f);
1546    rtl->mii_bus->irq = rtl->mii_irq;
1547    for (i = 0; i < PHY_MAX_ADDR; i++)
1548        rtl->mii_irq[i] = PHY_POLL;
1549
1550    ret = mdiobus_register(rtl->mii_bus);
1551    if (ret)
1552        goto err_free;
1553
1554    return 0;
1555
1556 err_free:
1557    mdiobus_free(rtl->mii_bus);
1558 err:
1559    return ret;
1560}
1561
1562static void rtl8366rb_mii_cleanup(struct rtl8366rb *rtl)
1563{
1564    mdiobus_unregister(rtl->mii_bus);
1565    mdiobus_free(rtl->mii_bus);
1566}
1567
15681529static int rtl8366rb_mii_bus_match(struct mii_bus *bus)
15691530{
15701531    return (bus->read == rtl8366rb_mii_read &&
...... 
16181579
16191580static struct rtl8366_smi_ops rtl8366rb_smi_ops = {
16201581    .detect = rtl8366rb_detect,
1582    .mii_read = rtl8366rb_mii_read,
1583    .mii_write = rtl8366rb_mii_write,
16211584};
16221585
16231586static int __init rtl8366rb_probe(struct platform_device *pdev)
...... 
16641627    if (err)
16651628        goto err_clear_drvdata;
16661629
1667    err = rtl8366rb_mii_init(rtl);
1668    if (err)
1669        goto err_clear_drvdata;
1670
16711630    err = rtl8366rb_switch_init(rtl);
16721631    if (err)
1673        goto err_mii_cleanup;
1632        goto err_clear_drvdata;
16741633
16751634    return 0;
16761635
1677 err_mii_cleanup:
1678    rtl8366rb_mii_cleanup(rtl);
16791636 err_clear_drvdata:
16801637    platform_set_drvdata(pdev, NULL);
16811638    rtl8366_smi_cleanup(smi);
...... 
17181675    if (rtl) {
17191676        rtl8366rb_switch_cleanup(rtl);
17201677        rtl8366rb_debugfs_remove(rtl);
1721        rtl8366rb_mii_cleanup(rtl);
17221678        platform_set_drvdata(pdev, NULL);
17231679        rtl8366_smi_cleanup(&rtl->smi);
17241680        kfree(rtl);
target/linux/generic-2.6/files/drivers/net/phy/rtl8366s.c
1616#include <linux/delay.h>
1717#include <linux/skbuff.h>
1818#include <linux/switch.h>
19#include <linux/phy.h>
2019#include <linux/rtl8366s.h>
2120
2221#include "rtl8366_smi.h"
...... 
149148struct rtl8366s {
150149    struct device *parent;
151150    struct rtl8366_smi smi;
152    struct mii_bus *mii_bus;
153    int mii_irq[PHY_MAX_ADDR];
154151    struct switch_dev dev;
155152    char buf[4096];
156153#ifdef CONFIG_RTL8366S_PHY_DEBUG_FS
...... 
225222    { 70, 2, "IfOutBroadcastPkts " },
226223};
227224
225static inline struct rtl8366s *smi_to_rtl8366s(struct rtl8366_smi *smi)
226{
227    return container_of(smi, struct rtl8366s, smi);
228}
229
228230static inline struct rtl8366s *sw_to_rtl8366s(struct switch_dev *sw)
229231{
230232    return container_of(sw, struct rtl8366s, dev);
...... 
14691471
14701472static int rtl8366s_mii_read(struct mii_bus *bus, int addr, int reg)
14711473{
1472    struct rtl8366s *rtl = bus->priv;
1474    struct rtl8366s *rtl = smi_to_rtl8366s(bus->priv);
14731475    u32 val = 0;
14741476    int err;
14751477
...... 
14821484
14831485static int rtl8366s_mii_write(struct mii_bus *bus, int addr, int reg, u16 val)
14841486{
1485    struct rtl8366s *rtl = bus->priv;
1487    struct rtl8366s *rtl = smi_to_rtl8366s(bus->priv);
14861488    u32 t;
14871489    int err;
14881490
...... 
14931495    return err;
14941496}
14951497
1496static int rtl8366s_mii_init(struct rtl8366s *rtl)
1497{
1498    int ret;
1499    int i;
1500
1501    rtl->mii_bus = mdiobus_alloc();
1502    if (rtl->mii_bus == NULL) {
1503        ret = -ENOMEM;
1504        goto err;
1505    }
1506
1507    rtl->mii_bus->priv = (void *) rtl;
1508    rtl->mii_bus->name = "rtl8366-rtl";
1509    rtl->mii_bus->read = rtl8366s_mii_read;
1510    rtl->mii_bus->write = rtl8366s_mii_write;
1511    snprintf(rtl->mii_bus->id, MII_BUS_ID_SIZE, "%s",
1512         dev_name(rtl->parent));
1513    rtl->mii_bus->parent = rtl->parent;
1514    rtl->mii_bus->phy_mask = ~(0x1f);
1515    rtl->mii_bus->irq = rtl->mii_irq;
1516    for (i = 0; i < PHY_MAX_ADDR; i++)
1517        rtl->mii_irq[i] = PHY_POLL;
1518
1519    ret = mdiobus_register(rtl->mii_bus);
1520    if (ret)
1521        goto err_free;
1522
1523    return 0;
1524
1525 err_free:
1526    mdiobus_free(rtl->mii_bus);
1527 err:
1528    return ret;
1529}
1530
1531static void rtl8366s_mii_cleanup(struct rtl8366s *rtl)
1532{
1533    mdiobus_unregister(rtl->mii_bus);
1534    mdiobus_free(rtl->mii_bus);
1535}
1536
15371498static int rtl8366s_mii_bus_match(struct mii_bus *bus)
15381499{
15391500    return (bus->read == rtl8366s_mii_read &&
...... 
15871548
15881549static struct rtl8366_smi_ops rtl8366s_smi_ops = {
15891550    .detect = rtl8366s_detect,
1551    .mii_read = rtl8366s_mii_read,
1552    .mii_write = rtl8366s_mii_write,
15901553};
15911554
15921555static int __init rtl8366s_probe(struct platform_device *pdev)
...... 
16331596    if (err)
16341597        goto err_clear_drvdata;
16351598
1636    err = rtl8366s_mii_init(rtl);
1637    if (err)
1638        goto err_clear_drvdata;
1639
16401599    err = rtl8366s_switch_init(rtl);
16411600    if (err)
1642        goto err_mii_cleanup;
1601        goto err_clear_drvdata;
16431602
16441603    return 0;
16451604
1646 err_mii_cleanup:
1647    rtl8366s_mii_cleanup(rtl);
16481605 err_clear_drvdata:
16491606    platform_set_drvdata(pdev, NULL);
16501607    rtl8366_smi_cleanup(smi);
...... 
16871644    if (rtl) {
16881645        rtl8366s_switch_cleanup(rtl);
16891646        rtl8366s_debugfs_remove(rtl);
1690        rtl8366s_mii_cleanup(rtl);
16911647        platform_set_drvdata(pdev, NULL);
16921648        rtl8366_smi_cleanup(&rtl->smi);
16931649        kfree(rtl);

Archive Download the corresponding diff file



interactive