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

📄 smc91c92_cs.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 5 页
字号:
		return i;	return pcmcia_parse_tuple(handle, tuple, parse);}static int next_tuple(client_handle_t handle, tuple_t *tuple,		cisparse_t *parse){	int i;	if ((i = pcmcia_get_next_tuple(handle, tuple)) != CS_SUCCESS ||			(i = pcmcia_get_tuple_data(handle, tuple)) != CS_SUCCESS)		return i;	return pcmcia_parse_tuple(handle, tuple, parse);}/*======================================================================    Configuration stuff for Megahertz cards    mhz_3288_power() is used to power up a 3288's ethernet chip.    mhz_mfc_config() handles socket setup for multifunction (1144    and 3288) cards.  mhz_setup() gets a card's hardware ethernet    address.======================================================================*/static int mhz_3288_power(dev_link_t *link){    struct net_device *dev = link->priv;    struct smc_private *smc = netdev_priv(dev);    u_char tmp;    /* Read the ISR twice... */    readb(smc->base+MEGAHERTZ_ISR);    udelay(5);    readb(smc->base+MEGAHERTZ_ISR);    /* Pause 200ms... */    mdelay(200);    /* Now read and write the COR... */    tmp = readb(smc->base + link->conf.ConfigBase + CISREG_COR);    udelay(5);    writeb(tmp, smc->base + link->conf.ConfigBase + CISREG_COR);    return 0;}static int mhz_mfc_config(dev_link_t *link){    struct net_device *dev = link->priv;    struct smc_private *smc = netdev_priv(dev);    struct smc_cfg_mem *cfg_mem;    tuple_t *tuple;    cisparse_t *parse;    cistpl_cftable_entry_t *cf;    u_char *buf;    win_req_t req;    memreq_t mem;    int i, k;    cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);    if (!cfg_mem)        return CS_OUT_OF_RESOURCE;    tuple = &cfg_mem->tuple;    parse = &cfg_mem->parse;    cf = &parse->cftable_entry;    buf = cfg_mem->buf;    link->conf.Attributes |= CONF_ENABLE_SPKR;    link->conf.Status = CCSR_AUDIO_ENA;    link->irq.Attributes =	IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED|IRQ_HANDLE_PRESENT;    link->io.IOAddrLines = 16;    link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;    link->io.NumPorts2 = 8;    tuple->Attributes = tuple->TupleOffset = 0;    tuple->TupleData = (cisdata_t *)buf;    tuple->TupleDataMax = 255;    tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;    i = first_tuple(link->handle, tuple, parse);    /* The Megahertz combo cards have modem-like CIS entries, so       we have to explicitly try a bunch of port combinations. */    while (i == CS_SUCCESS) {	link->conf.ConfigIndex = cf->index;	link->io.BasePort2 = cf->io.win[0].base;	for (k = 0; k < 0x400; k += 0x10) {	    if (k & 0x80) continue;	    link->io.BasePort1 = k ^ 0x300;	    i = pcmcia_request_io(link->handle, &link->io);	    if (i == CS_SUCCESS) break;	}	if (i == CS_SUCCESS) break;	i = next_tuple(link->handle, tuple, parse);    }    if (i != CS_SUCCESS)	goto free_cfg_mem;    dev->base_addr = link->io.BasePort1;    /* Allocate a memory window, for accessing the ISR */    req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;    req.Base = req.Size = 0;    req.AccessSpeed = 0;    i = pcmcia_request_window(&link->handle, &req, &link->win);    if (i != CS_SUCCESS)	goto free_cfg_mem;    smc->base = ioremap(req.Base, req.Size);    mem.CardOffset = mem.Page = 0;    if (smc->manfid == MANFID_MOTOROLA)	mem.CardOffset = link->conf.ConfigBase;    i = pcmcia_map_mem_page(link->win, &mem);    if ((i == CS_SUCCESS)	&& (smc->manfid == MANFID_MEGAHERTZ)	&& (smc->cardid == PRODID_MEGAHERTZ_EM3288))	mhz_3288_power(link);free_cfg_mem:    kfree(cfg_mem);    return i;}static int mhz_setup(dev_link_t *link){    client_handle_t handle = link->handle;    struct net_device *dev = link->priv;    struct smc_cfg_mem *cfg_mem;    tuple_t *tuple;    cisparse_t *parse;    u_char *buf, *station_addr;    int rc;    cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);    if (!cfg_mem)	return -1;    tuple = &cfg_mem->tuple;    parse = &cfg_mem->parse;    buf = cfg_mem->buf;    tuple->Attributes = tuple->TupleOffset = 0;    tuple->TupleData = (cisdata_t *)buf;    tuple->TupleDataMax = 255;    /* Read the station address from the CIS.  It is stored as the last       (fourth) string in the Version 1 Version/ID tuple. */    tuple->DesiredTuple = CISTPL_VERS_1;    if (first_tuple(handle, tuple, parse) != CS_SUCCESS) {	rc = -1;	goto free_cfg_mem;    }    /* Ugh -- the EM1144 card has two VERS_1 tuples!?! */    if (next_tuple(handle, tuple, parse) != CS_SUCCESS)	first_tuple(handle, tuple, parse);    if (parse->version_1.ns > 3) {	station_addr = parse->version_1.str + parse->version_1.ofs[3];	if (cvt_ascii_address(dev, station_addr) == 0) {		rc = 0;		goto free_cfg_mem;	}    }    /* Another possibility: for the EM3288, in a special tuple */    tuple->DesiredTuple = 0x81;    if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS) {	rc = -1;	goto free_cfg_mem;    }    if (pcmcia_get_tuple_data(handle, tuple) != CS_SUCCESS) {	rc = -1;	goto free_cfg_mem;    }    buf[12] = '\0';    if (cvt_ascii_address(dev, buf) == 0) {	rc = 0;	goto free_cfg_mem;   }    rc = -1;free_cfg_mem:   kfree(cfg_mem);   return rc;}/*======================================================================    Configuration stuff for the Motorola Mariner    mot_config() writes directly to the Mariner configuration    registers because the CIS is just bogus.======================================================================*/static void mot_config(dev_link_t *link){    struct net_device *dev = link->priv;    struct smc_private *smc = netdev_priv(dev);    kio_addr_t ioaddr = dev->base_addr;    kio_addr_t iouart = link->io.BasePort2;    /* Set UART base address and force map with COR bit 1 */    writeb(iouart & 0xff,        smc->base + MOT_UART + CISREG_IOBASE_0);    writeb((iouart >> 8) & 0xff, smc->base + MOT_UART + CISREG_IOBASE_1);    writeb(MOT_NORMAL,           smc->base + MOT_UART + CISREG_COR);    /* Set SMC base address and force map with COR bit 1 */    writeb(ioaddr & 0xff,        smc->base + MOT_LAN + CISREG_IOBASE_0);    writeb((ioaddr >> 8) & 0xff, smc->base + MOT_LAN + CISREG_IOBASE_1);    writeb(MOT_NORMAL,           smc->base + MOT_LAN + CISREG_COR);    /* Wait for things to settle down */    mdelay(100);}static int mot_setup(dev_link_t *link){    struct net_device *dev = link->priv;    kio_addr_t ioaddr = dev->base_addr;    int i, wait, loop;    u_int addr;    /* Read Ethernet address from Serial EEPROM */    for (i = 0; i < 3; i++) {	SMC_SELECT_BANK(2);	outw(MOT_EEPROM + i, ioaddr + POINTER);	SMC_SELECT_BANK(1);	outw((CTL_RELOAD | CTL_EE_SELECT), ioaddr + CONTROL);	for (loop = wait = 0; loop < 200; loop++) {	    udelay(10);	    wait = ((CTL_RELOAD | CTL_STORE) & inw(ioaddr + CONTROL));	    if (wait == 0) break;	}		if (wait)	    return -1;		addr = inw(ioaddr + GENERAL);	dev->dev_addr[2*i]   = addr & 0xff;	dev->dev_addr[2*i+1] = (addr >> 8) & 0xff;    }    return 0;}/*====================================================================*/static int smc_config(dev_link_t *link){    struct net_device *dev = link->priv;    struct smc_cfg_mem *cfg_mem;    tuple_t *tuple;    cisparse_t *parse;    cistpl_cftable_entry_t *cf;    u_char *buf;    int i;    cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);    if (!cfg_mem)	return CS_OUT_OF_RESOURCE;    tuple = &cfg_mem->tuple;    parse = &cfg_mem->parse;    cf = &parse->cftable_entry;    buf = cfg_mem->buf;    tuple->Attributes = tuple->TupleOffset = 0;    tuple->TupleData = (cisdata_t *)buf;    tuple->TupleDataMax = 255;    tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;    link->io.NumPorts1 = 16;    i = first_tuple(link->handle, tuple, parse);    while (i != CS_NO_MORE_ITEMS) {	if (i == CS_SUCCESS) {	    link->conf.ConfigIndex = cf->index;	    link->io.BasePort1 = cf->io.win[0].base;	    link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK;	    i = pcmcia_request_io(link->handle, &link->io);	    if (i == CS_SUCCESS) break;	}	i = next_tuple(link->handle, tuple, parse);    }    if (i == CS_SUCCESS)	dev->base_addr = link->io.BasePort1;    kfree(cfg_mem);    return i;}static int smc_setup(dev_link_t *link){    client_handle_t handle = link->handle;    struct net_device *dev = link->priv;    struct smc_cfg_mem *cfg_mem;    tuple_t *tuple;    cisparse_t *parse;    cistpl_lan_node_id_t *node_id;    u_char *buf, *station_addr;    int i, rc;    cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);    if (!cfg_mem)	return CS_OUT_OF_RESOURCE;    tuple = &cfg_mem->tuple;    parse = &cfg_mem->parse;    buf = cfg_mem->buf;    tuple->Attributes = tuple->TupleOffset = 0;    tuple->TupleData = (cisdata_t *)buf;    tuple->TupleDataMax = 255;    /* Check for a LAN function extension tuple */    tuple->DesiredTuple = CISTPL_FUNCE;    i = first_tuple(handle, tuple, parse);    while (i == CS_SUCCESS) {	if (parse->funce.type == CISTPL_FUNCE_LAN_NODE_ID)	    break;	i = next_tuple(handle, tuple, parse);    }    if (i == CS_SUCCESS) {	node_id = (cistpl_lan_node_id_t *)parse->funce.data;	if (node_id->nb == 6) {	    for (i = 0; i < 6; i++)		dev->dev_addr[i] = node_id->id[i];	    rc = 0;	    goto free_cfg_mem;	}    }    /* Try the third string in the Version 1 Version/ID tuple. */    tuple->DesiredTuple = CISTPL_VERS_1;    if (first_tuple(handle, tuple, parse) != CS_SUCCESS) {	rc = -1;	goto free_cfg_mem;    }    station_addr = parse->version_1.str + parse->version_1.ofs[2];    if (cvt_ascii_address(dev, station_addr) == 0) {	rc = 0;	goto free_cfg_mem;    }    rc = -1;free_cfg_mem:    kfree(cfg_mem);    return rc;}/*====================================================================*/static int osi_config(dev_link_t *link){    struct net_device *dev = link->priv;    static kio_addr_t com[4] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };    int i, j;    link->conf.Attributes |= CONF_ENABLE_SPKR;    link->conf.Status = CCSR_AUDIO_ENA;    link->irq.Attributes =	IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED|IRQ_HANDLE_PRESENT;    link->io.NumPorts1 = 64;    link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;    link->io.NumPorts2 = 8;    link->io.IOAddrLines = 16;    /* Enable Hard Decode, LAN, Modem */    link->conf.ConfigIndex = 0x23;    for (i = j = 0; j < 4; j++) {	link->io.BasePort2 = com[j];	i = pcmcia_request_io(link->handle, &link->io);	if (i == CS_SUCCESS) break;    }    if (i != CS_SUCCESS) {	/* Fallback: turn off hard decode */	link->conf.ConfigIndex = 0x03;	link->io.NumPorts2 = 0;	i = pcmcia_request_io(link->handle, &link->io);    }    dev->base_addr = link->io.BasePort1 + 0x10;    return i;}static int osi_setup(dev_link_t *link, u_short manfid, u_short cardid){    client_handle_t handle = link->handle;    struct net_device *dev = link->priv;    struct smc_cfg_mem *cfg_mem;    tuple_t *tuple;    u_char *buf;    int i, rc;    cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);    if (!cfg_mem)        return -1;    tuple = &cfg_mem->tuple;    buf = cfg_mem->buf;    tuple->Attributes = TUPLE_RETURN_COMMON;    tuple->TupleData = (cisdata_t *)buf;    tuple->TupleDataMax = 255;    tuple->TupleOffset = 0;    /* Read the station address from tuple 0x90, subtuple 0x04 */    tuple->DesiredTuple = 0x90;    i = pcmcia_get_first_tuple(handle, tuple);    while (i == CS_SUCCESS) {	i = pcmcia_get_tuple_data(handle, tuple);	if ((i != CS_SUCCESS) || (buf[0] == 0x04))	    break;	i = pcmcia_get_next_tuple(handle, tuple);    }    if (i != CS_SUCCESS) {	rc = -1;	goto free_cfg_mem;    }    for (i = 0; i < 6; i++)	dev->dev_addr[i] = buf[i+2];    if (((manfid == MANFID_OSITECH) &&	 (cardid == PRODID_OSITECH_SEVEN)) ||	((manfid == MANFID_PSION) &&	 (cardid == PRODID_PSION_NET100))) {	/* Download the Seven of Diamonds firmware */	for (i = 0; i < sizeof(__Xilinx7OD); i++) {	    outb(__Xilinx7OD[i], link->io.BasePort1+2);	    udelay(50);	}    } else if (manfid == MANFID_OSITECH) {	/* Make sure both functions are powered up */	set_bits(0x300, link->io.BasePort1 + OSITECH_AUI_PWR);	/* Now, turn on the interrupt for both card functions */	set_bits(0x300, link->io.BasePort1 + OSITECH_RESET_ISR);	DEBUG(2, "AUI/PWR: %4.4x RESET/ISR: %4.4x\n",	      inw(link->io.BasePort1 + OSITECH_AUI_PWR),	      inw(link->io.BasePort1 + OSITECH_RESET_ISR));    }    rc = 0;free_cfg_mem:   kfree(cfg_mem);   return rc;}/*======================================================================    This verifies that the chip is some SMC91cXX variant, and returns

⌨️ 快捷键说明

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