⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 921x_4_linux.c

📁 ethernet device driver for smsc9115
💻 C
📖 第 1 页 / 共 5 页
字号:
        SMSC_TRACE("This may mean the chip is set for 32 bit while "
               "the bus is reading as 16 bit");
        return -ENODEV;
    }
    switch (pdata->idrev & 0xFFFF0000) {
    case 0x01180000:
        switch (pdata->idrev & 0x0000FFFF) {
        case 0UL:
            SMSC_TRACE("LAN9118 Beacon identified, idrev: 0x%08X",
                   pdata->idrev);
            pdata->generation = 0;
            break;
        case 1UL:
            SMSC_TRACE
                ("LAN9118 Concord A0 identified, idrev: 0x%08X",
                 pdata->idrev);
            pdata->generation = 1;
            break;
        case 2UL:
            SMSC_TRACE
                ("LAN9118 Concord A1 identified, idrev: 0x%08X",
                 pdata->idrev);
            pdata->generation = 2;
            break;
        default:
            SMSC_TRACE
                ("LAN9118 Concord A1 identified (NEW), idrev: 0x%08X",
                 pdata->idrev);
            pdata->generation = 2;
            break;
        }
        break;

    case 0x01170000:
        switch (pdata->idrev & 0x0000FFFF) {
        case 0UL:
            SMSC_TRACE("LAN9117 Beacon identified, idrev: 0x%08X",
                   pdata->idrev);
            pdata->generation = 0;
            break;
        case 1UL:
            SMSC_TRACE
                ("LAN9117 Concord A0 identified, idrev: 0x%08X",
                 pdata->idrev);
            pdata->generation = 1;
            break;
        case 2UL:
            SMSC_TRACE
                ("LAN9117 Concord A1 identified, idrev: 0x%08X",
                 pdata->idrev);
            pdata->generation = 2;
            break;
        default:
            SMSC_TRACE
                ("LAN9117 Concord A1 identified (NEW), idrev: 0x%08X",
                 pdata->idrev);
            pdata->generation = 2;
            break;
        }
        break;

    case 0x01160000:
        switch (pdata->idrev & 0x0000FFFF) {
        case 0UL:
            SMSC_WARNING("LAN911x not identified, idrev: 0x%08X",
                     pdata->idrev);
            return -ENODEV;
        case 1UL:
            SMSC_TRACE
                ("LAN9116 Concord A0 identified, idrev: 0x%08X",
                 pdata->idrev);
            pdata->generation = 1;
            break;
        case 2UL:
            SMSC_TRACE
                ("LAN9116 Concord A1 identified, idrev: 0x%08X",
                 pdata->idrev);
            pdata->generation = 2;
            break;
        default:
            SMSC_TRACE
                ("LAN9116 Concord A1 identified (NEW), idrev: 0x%08X",
                 pdata->idrev);
            pdata->generation = 2;
            break;
        }
        break;

    case 0x01150000:
        switch (pdata->idrev & 0x0000FFFF) {
        case 0UL:
            SMSC_WARNING("LAN911x not identified, idrev: 0x%08X",
                     pdata->idrev);
            return -ENODEV;
        case 1UL:
            SMSC_TRACE
                ("LAN9115 Concord A0 identified, idrev: 0x%08X",
                 pdata->idrev);
            pdata->generation = 1;
            break;
        case 2UL:
            SMSC_TRACE
                ("LAN9115 Concord A1 identified, idrev: 0x%08X",
                 pdata->idrev);
            pdata->generation = 2;
            break;
        default:
            SMSC_TRACE
                ("LAN9115 Concord A1 identified (NEW), idrev: 0x%08X",
                 pdata->idrev);
            pdata->generation = 2;
            break;
        }
        break;

    case 0x118A0000:
        switch (pdata->idrev & 0x0000FFFF) {
        case 0UL:
            SMSC_TRACE
                ("LAN9218 Boylston identified, idrev: 0x%08X",
                 pdata->idrev);
            pdata->generation = 3;
            break;
        default:
            SMSC_TRACE
                ("LAN9218 Boylston identified (NEW), idrev: 0x%08X",
                 pdata->idrev);
            pdata->generation = 3;
            break;
        }
        break;

    case 0x117A0000:
        switch (pdata->idrev & 0x0000FFFF) {
        case 0UL:
            SMSC_TRACE
                ("LAN9217 Boylston identified, idrev: 0x%08X",
                 pdata->idrev);
            pdata->generation = 3;
            break;
        default:
            SMSC_TRACE
                ("LAN9217 Boylston identified (NEW), idrev: 0x%08X",
                 pdata->idrev);
            pdata->generation = 3;
            break;
        }
        break;

    case 0x116A0000:
        switch (pdata->idrev & 0x0000FFFF) {
        case 0UL:
            SMSC_TRACE
                ("LAN9216 Boylston identified, idrev: 0x%08X",
                 pdata->idrev);
            pdata->generation = 3;
            break;
        default:
            SMSC_TRACE
                ("LAN9216 Boylston identified (NEW), idrev: 0x%08X",
                 pdata->idrev);
            pdata->generation = 3;
            break;
        }
        break;

    case 0x115A0000:
        switch (pdata->idrev & 0x0000FFFF) {
        case 0UL:
            SMSC_TRACE
                ("LAN9215 Boylston identified, idrev: 0x%08X",
                 pdata->idrev);
            pdata->generation = 3;
            break;
        default:
            SMSC_TRACE
                ("LAN9215 Boylston identified (NEW), idrev: 0x%08X",
                 pdata->idrev);
            pdata->generation = 3;
            break;
        }
        break;

    default:
        SMSC_WARNING("LAN911x not identified, idrev: 0x%08X",
                 pdata->idrev);
        return -ENODEV;
    }

    if (pdata->generation == 0)
        SMSC_WARNING("This driver is not intended "
                 "for this chip revision");

    /* Reset the LAN911x */
    if (smsc911x_soft_reset(pdata))
        return -ENODEV;

    /* Disable all interrupt sources until we bring the device up */
    smsc911x_reg_write(0, pdata, INT_EN);

    ether_setup(dev);
    dev->open = smsc911x_open;
    dev->stop = smsc911x_stop;
    dev->hard_start_xmit = smsc911x_hard_start_xmit;
    dev->get_stats = smsc911x_get_stats;
    dev->set_multicast_list = smsc911x_set_multicast_list;
    dev->flags |= IFF_MULTICAST;
    dev->do_ioctl = smsc911x_do_ioctl;
    dev->poll = smsc911x_poll;
    dev->weight = 64;
    //dev->ethtool_ops = &smsc911x_ethtool_ops;
#ifdef CONFIG_NET_POLL_CONTROLLER
    dev->poll_controller = smsc911x_poll_controller;
#endif                /* CONFIG_NET_POLL_CONTROLLER */

    pdata->mii.phy_id_mask = 0x1f;
    pdata->mii.reg_num_mask = 0x1f;
    pdata->mii.force_media = 0;
    pdata->mii.full_duplex = 0;
    pdata->mii.dev = dev;
    pdata->mii.mdio_read = smsc911x_mdio_read;
    pdata->mii.mdio_write = smsc911x_mdio_write;

    pdata->msg_enable = NETIF_MSG_LINK;

    return 0;
}
/*
static int smsc911x_drv_remove(struct platform_device *pdev)
{
    struct net_device *dev;
    struct smsc911x_data *pdata;
    struct resource *res;

    dev = platform_get_drvdata(pdev);
    BUG_ON(!dev);
    pdata = netdev_priv(dev);
    BUG_ON(!pdata);
    BUG_ON(!pdata->ioaddr);

    SMSC_TRACE("Stopping driver.");
    platform_set_drvdata(pdev, NULL);
    unregister_netdev(dev);
    free_irq(dev->irq, dev);
    res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
                       "smsc911x-memory");
    if (!res)
        platform_get_resource(pdev, IORESOURCE_MEM, 0);

    release_mem_region(res->start, res->end - res->start);

    iounmap(pdata->ioaddr);

    free_netdev(dev);

    return 0;
}
*/
int __init smsc911x_drv_probe(struct net_device *dev)
{
    struct smsc911x_data *pdata;
    int retval;

/* when not module
    if ( strcmp("eth1" , dev->name) == 0  )
        return -ENODEV;
    dev = init_etherdev(dev, 0);
*/
    if (!request_mem_region(LAN9215_IO_BASE, LAN9215_IO_SIZE, SMSC_CHIPNAME)) {
        retval = -EBUSY;
        goto out_0;
    }
    pdata->ioaddr = ioremap_nocache(LAN9215_IO_BASE, LAN9215_IO_SIZE);
    if (pdata->ioaddr == NULL)
    {
        SMSC_WARNING("Error smsc911x base address invalid");
        retval = -ENOMEM;
        goto out_free_netdev_2;
    }

    /* HW ID detect */
    if( smsc911x_reg_read( pdata, ID_REV ) == LAN9215_PHY_ID )
    {
        printk("OK,LAN9215 Found!!\n");
    }

    pdata = (void *)(kmalloc(sizeof(*pdata), GFP_KERNEL));
    memset(pdata, 0, sizeof(struct smsc911x_data));
    dev->priv = pdata;
    if ((retval = smsc911x_init(dev)) < 0) // call ether_setup here
        goto out_unmap_io_3;
    SET_MODULE_OWNER(dev);
    dev->irq = 0;
    retval = request_irq(dev->irq, smsc911x_irqhandler, SA_INTERRUPT,
                 SMSC_CHIPNAME, dev);
    if (retval) {
        SMSC_WARNING("Unable to claim requested irq: %d", dev->irq);
        goto out_unmap_io_3;
    }

    return 0;

out_unmap_io_3:
    iounmap(pdata->ioaddr);
    kree( pdata );
out_free_netdev_2:
    release_mem_region(LAN9215_IO_BASE, LAN9215_IO_SIZE);
out_0:
    kfree(dev);
    return retval;
}
/*
static struct platform_driver smsc911x_driver = {
    .probe = smsc911x_drv_probe,
    .remove = smsc911x_drv_remove,
    .suspend = 0,    
    .resume = 0,
    .driver = {.name = SMSC_CHIPNAME,},
};
*/

/* Entry point for loading the module */
int smsc911x_init_module(void)
{
    int retval;

    gl_dev = alloc_etherdev(sizeof(struct smsc911x_data));
    if (!gl_dev) {
        printk(KERN_WARNING "%s: Could not allocate device.\n",
               SMSC_CHIPNAME);
        return -ENOMEM;
    }

    smsc911x_drv_probe(gl_dev);

    retval = register_netdev(gl_dev);
    if (retval) {
        printk("Error %i registering device", retval);
    } else {
        printk("Network interface: \"%s\"", gl_dev->name);
    }
    return retval;
}

/* entry point for unloading the module */
void smsc911x_cleanup_module(void)
{
    printk("smsc911x cleanup module\n");
}

module_init(smsc911x_init_module);
module_exit(smsc911x_cleanup_module);

 

 
 发表于: 2007-03-26,修改于: 2007-03-26 17:07 已浏览665次,有评论1条 推荐 投诉  
 
 

  网友评论 
  kf701  时间:2007-03-26 17:23:29 IP地址:218.22.45.★ 
 
 /***************************************************************************
 *
 * Copyright (C) 2004-2006 SMSC
 * Copyright (C) 2005-2006 ARM
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */
#ifndef __SMSC911X_H__
#define __SMSC911X_H__

#define SMSC_CAN_USE_32BIT    1
#define TX_FIFO_LOW_THRESHOLD    ((u32)1600)
#define SMSC911X_EEPROM_SIZE    ((u32)7)
#define USE_DEBUG         3

/* implements a PHY loopback test at initialisation time, to ensure a packet
 * can be succesfully looped back */
#define USE_PHY_WORK_AROUND

/* 10/100 LED link-state inversion when media is disconnected */
#define USE_LED1_WORK_AROUND

#if USE_DEBUG >= 1
#define SMSC_WARNING(fmt, args...) \
        printk(KERN_EMERG "SMSC_WARNING: %s: " fmt "\n", \
            __FUNCTION__ , ## args)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -