Commit b6091b87 authored by Stephen Hemminger's avatar Stephen Hemminger

[PATCH] (3/6) proteon -- probe2

Convert proteon token ring driver to new probing.
parent edf697a0
...@@ -411,10 +411,13 @@ static void __init ethif_probe2(int unit) ...@@ -411,10 +411,13 @@ static void __init ethif_probe2(int unit)
/* Token-ring device probe */ /* Token-ring device probe */
extern int ibmtr_probe(struct net_device *); extern int ibmtr_probe(struct net_device *);
extern int sk_isa_probe(struct net_device *); extern int sk_isa_probe(struct net_device *);
extern int proteon_probe(struct net_device *); extern struct net_device *proteon_probe(int unit);
extern struct net_device *smctr_probe(int unit); extern struct net_device *smctr_probe(int unit);
static struct devprobe2 tr_probes2[] __initdata = { static struct devprobe2 tr_probes2[] __initdata = {
#ifdef CONFIG_PROTEON
{proteon_probe, 0},
#endif
#ifdef CONFIG_SMCTR #ifdef CONFIG_SMCTR
{smctr_probe, 0}, {smctr_probe, 0},
#endif #endif
...@@ -438,9 +441,6 @@ static __init int trif_probe(int unit) ...@@ -438,9 +441,6 @@ static __init int trif_probe(int unit)
#endif #endif
#ifdef CONFIG_SKISA #ifdef CONFIG_SKISA
sk_isa_probe(dev) == 0 || sk_isa_probe(dev) == 0 ||
#endif
#ifdef CONFIG_PROTEON
proteon_probe(dev) == 0 ||
#endif #endif
0 ) 0 )
err = register_netdev(dev); err = register_netdev(dev);
......
...@@ -63,7 +63,7 @@ static int dmalist[] __initdata = { ...@@ -63,7 +63,7 @@ static int dmalist[] __initdata = {
static char cardname[] = "Proteon 1392\0"; static char cardname[] = "Proteon 1392\0";
int proteon_probe(struct net_device *dev); struct net_device *proteon_probe(int unit);
static int proteon_open(struct net_device *dev); static int proteon_open(struct net_device *dev);
static int proteon_close(struct net_device *dev); static int proteon_close(struct net_device *dev);
static void proteon_read_eeprom(struct net_device *dev); static void proteon_read_eeprom(struct net_device *dev);
...@@ -89,80 +89,69 @@ static void proteon_sifwritew(struct net_device *dev, unsigned short val, unsign ...@@ -89,80 +89,69 @@ static void proteon_sifwritew(struct net_device *dev, unsigned short val, unsign
outw(val, dev->base_addr + reg); outw(val, dev->base_addr + reg);
} }
struct proteon_card { static int __init proteon_probe1(struct net_device *dev, int ioaddr)
struct net_device *dev;
struct proteon_card *next;
};
static struct proteon_card *proteon_card_list;
static int __init proteon_probe1(int ioaddr)
{ {
unsigned char chk1, chk2; unsigned char chk1, chk2;
int i; int i;
if (!request_region(ioaddr, PROTEON_IO_EXTENT, cardname))
return -ENODEV;
chk1 = inb(ioaddr + 0x1f); /* Get Proteon ID reg 1 */ chk1 = inb(ioaddr + 0x1f); /* Get Proteon ID reg 1 */
if (chk1 != 0x1f) if (chk1 != 0x1f)
return (-1); goto nodev;
chk1 = inb(ioaddr + 0x1e) & 0x07; /* Get Proteon ID reg 0 */ chk1 = inb(ioaddr + 0x1e) & 0x07; /* Get Proteon ID reg 0 */
for (i=0; i<16; i++) { for (i=0; i<16; i++) {
chk2 = inb(ioaddr + 0x1e) & 0x07; chk2 = inb(ioaddr + 0x1e) & 0x07;
if (((chk1 + 1) & 0x07) != chk2) if (((chk1 + 1) & 0x07) != chk2)
return (-1); goto nodev;
chk1 = chk2; chk1 = chk2;
} }
dev->base_addr = ioaddr;
return (0); return (0);
nodev:
release_region(ioaddr, PROTEON_IO_EXTENT);
return -ENODEV;
} }
int __init proteon_probe(struct net_device *dev) struct net_device * __init proteon_probe(int unit)
{ {
static int versionprinted; struct net_device *dev = alloc_trdev(sizeof(struct net_local));
struct net_local *tp; struct net_local *tp;
int i,j; static int versionprinted;
struct proteon_card *card; const unsigned *port;
int j,err = 0;
#ifndef MODULE if (!dev)
netdev_boot_setup_check(dev); return ERR_PTR(-ENOMEM);
tr_setup(dev);
#endif
SET_MODULE_OWNER(dev); if (unit >= 0) {
if (!dev->base_addr) sprintf(dev->name, "tr%d", unit);
{ netdev_boot_setup_check(dev);
for(i = 0; portlist[i]; i++) }
{
if (!request_region(portlist[i], PROTEON_IO_EXTENT, cardname))
continue;
if(proteon_probe1(portlist[i]))
{
release_region(dev->base_addr, PROTEON_IO_EXTENT);
continue;
}
dev->base_addr = portlist[i]; SET_MODULE_OWNER(dev);
break; if (dev->base_addr) /* probe specific location */
err = proteon_probe1(dev, dev->base_addr);
else {
for (port = portlist; *port; port++) {
err = proteon_probe1(dev, *port);
if (!err)
break;
} }
if(!dev->base_addr)
return -1;
} }
else if (err)
{ goto out4;
if (!request_region(dev->base_addr, PROTEON_IO_EXTENT, cardname))
return -1;
if(proteon_probe1(dev->base_addr))
{
release_region(dev->base_addr, PROTEON_IO_EXTENT);
return -1;
}
}
/* At this point we have found a valid card. */ /* At this point we have found a valid card. */
if (versionprinted++ == 0) if (versionprinted++ == 0)
printk(KERN_DEBUG "%s", version); printk(KERN_DEBUG "%s", version);
err = -EIO;
if (tmsdev_init(dev, ISA_MAX_ADDRESS, NULL)) if (tmsdev_init(dev, ISA_MAX_ADDRESS, NULL))
goto out4; goto out4;
...@@ -264,14 +253,11 @@ int __init proteon_probe(struct net_device *dev) ...@@ -264,14 +253,11 @@ int __init proteon_probe(struct net_device *dev)
printk(KERN_DEBUG "%s: IO: %#4lx IRQ: %d DMA: %d\n", printk(KERN_DEBUG "%s: IO: %#4lx IRQ: %d DMA: %d\n",
dev->name, dev->base_addr, dev->irq, dev->dma); dev->name, dev->base_addr, dev->irq, dev->dma);
/* Enlist in the card list */ err = register_netdev(dev);
card = kmalloc(sizeof(struct proteon_card), GFP_KERNEL); if (err)
if (!card)
goto out; goto out;
card->next = proteon_card_list;
proteon_card_list = card; return dev;
card->dev = dev;
return 0;
out: out:
free_dma(dev->dma); free_dma(dev->dma);
out2: out2:
...@@ -280,7 +266,8 @@ int __init proteon_probe(struct net_device *dev) ...@@ -280,7 +266,8 @@ int __init proteon_probe(struct net_device *dev)
tmsdev_term(dev); tmsdev_term(dev);
out4: out4:
release_region(dev->base_addr, PROTEON_IO_EXTENT); release_region(dev->base_addr, PROTEON_IO_EXTENT);
return -1; free_netdev(dev);
return ERR_PTR(err);
} }
/* /*
...@@ -370,50 +357,50 @@ MODULE_PARM(io, "1-" __MODULE_STRING(ISATR_MAX_ADAPTERS) "i"); ...@@ -370,50 +357,50 @@ MODULE_PARM(io, "1-" __MODULE_STRING(ISATR_MAX_ADAPTERS) "i");
MODULE_PARM(irq, "1-" __MODULE_STRING(ISATR_MAX_ADAPTERS) "i"); MODULE_PARM(irq, "1-" __MODULE_STRING(ISATR_MAX_ADAPTERS) "i");
MODULE_PARM(dma, "1-" __MODULE_STRING(ISATR_MAX_ADAPTERS) "i"); MODULE_PARM(dma, "1-" __MODULE_STRING(ISATR_MAX_ADAPTERS) "i");
static int __init setup_card(unsigned long io, unsigned irq, unsigned char dma) static struct net_device *proteon_dev[ISATR_MAX_ADAPTERS];
static struct net_device * __init setup_card(unsigned long io, unsigned irq, unsigned char dma)
{ {
int res = -ENOMEM; struct net_device *dev = alloc_trdev(sizeof(struct net_local));
struct proteon_card *this_card; int err;
struct net_device *dev = alloc_trdev(0);
if (!dev)
if (dev) { return ERR_PTR(-ENOMEM);
dev->base_addr = io;
dev->irq = irq; dev->irq = irq;
dev->dma = dma; dev->dma = dma;
res = -ENODEV; err = proteon_probe1(dev, io);
if (proteon_probe(dev) == 0) { if (err)
res = register_netdev(dev); goto out;
if (!res)
return 0; err = register_netdev(dev);
release_region(dev->base_addr, PROTEON_IO_EXTENT); if (err)
free_irq(dev->irq, dev); goto out1;
free_dma(dev->dma); return dev;
tmsdev_term(dev); out1:
this_card = proteon_card_list; release_region(dev->base_addr, PROTEON_IO_EXTENT);
proteon_card_list = this_card->next; free_irq(dev->irq, dev);
kfree(this_card); free_dma(dev->dma);
} tmsdev_term(dev);
kfree(dev); out:
} free_netdev(dev);
return res; return ERR_PTR(err);
} }
int init_module(void) int init_module(void)
{ {
int i, num; struct net_device *dev;
int i, num = 0;
num = 0;
if (io[0]) { /* Only probe addresses from command line */ for (i = 0; i < ISATR_MAX_ADAPTERS ; i++) {
for (i = 0; i < ISATR_MAX_ADAPTERS ; i++) { dev = io[0] ? setup_card(io[i], irq[i], dma[i])
if (io[i] && setup_card(io[i], irq[i], dma[i]) == 0) : proteon_probe(-1);
num++; if (!IS_ERR(dev)) {
} proteon_dev[i] = dev;
} else { ++num;
for(i = 0; num < ISATR_MAX_ADAPTERS && portlist[i]; i++) {
if (setup_card(portlist[i], irq[num], dma[num]) == 0)
num++;
} }
} }
printk(KERN_NOTICE "proteon.c: %d cards found.\n", num); printk(KERN_NOTICE "proteon.c: %d cards found.\n", num);
/* Probe for cards. */ /* Probe for cards. */
if (num == 0) { if (num == 0) {
...@@ -425,11 +412,13 @@ int init_module(void) ...@@ -425,11 +412,13 @@ int init_module(void)
void cleanup_module(void) void cleanup_module(void)
{ {
struct net_device *dev; int i;
struct proteon_card *this_card;
while (proteon_card_list) { for (i = 0; i < ISATR_MAX_ADAPTERS ; i++) {
dev = proteon_card_list->dev; struct net_device *dev = proteon_dev[i];
if (!dev)
continue;
unregister_netdev(dev); unregister_netdev(dev);
release_region(dev->base_addr, PROTEON_IO_EXTENT); release_region(dev->base_addr, PROTEON_IO_EXTENT);
...@@ -437,9 +426,6 @@ void cleanup_module(void) ...@@ -437,9 +426,6 @@ void cleanup_module(void)
free_dma(dev->dma); free_dma(dev->dma);
tmsdev_term(dev); tmsdev_term(dev);
free_netdev(dev); free_netdev(dev);
this_card = proteon_card_list;
proteon_card_list = this_card->next;
kfree(this_card);
} }
} }
#endif /* MODULE */ #endif /* MODULE */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment