Commit 58936d8d authored by Jiri Slaby's avatar Jiri Slaby Committed by Linus Torvalds

Char: cyclades, create cy_pci_probe

Move probing code to separate function for easy pci probing conversion.
Signed-off-by: default avatarJiri Slaby <jirislaby@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 2b1da41f
......@@ -4698,7 +4698,8 @@ static int __init cy_detect_isa(void)
#endif /* CONFIG_ISA */
} /* cy_detect_isa */
static void plx_init(void __iomem * addr, __u32 initctl)
#ifdef CONFIG_PCI
static void __devinit plx_init(void __iomem * addr, __u32 initctl)
{
/* Reset PLX */
cy_writel(addr + initctl, readl(addr + initctl) | 0x40000000);
......@@ -4800,50 +4801,30 @@ static int __devinit cy_init_Ze(unsigned long cy_pci_phys0,
return 0;
}
/*
* ---------------------------------------------------------------------
* cy_detect_pci() - Test PCI bus presence and Cyclom-Ye/PCI.
* sets global variables and return the number of PCI boards found.
* ---------------------------------------------------------------------
*/
static int __init cy_detect_pci(void)
static int __devinit cy_pci_probe(struct pci_dev *pdev,
const struct pci_device_id *ent)
{
#ifdef CONFIG_PCI
struct pci_dev *pdev = NULL;
unsigned char cyy_rev_id;
unsigned char cy_pci_irq = 0;
__u32 cy_pci_phys0, cy_pci_phys2;
unsigned char cy_pci_irq;
__u32 cy_pci_phys0, cy_pci_phys2, mailbox;
void __iomem *cy_pci_addr0, *cy_pci_addr2;
unsigned short i, j, cy_pci_nchan, plx_ver;
unsigned short device_id, dev_index = 0;
__u32 mailbox;
unsigned int device_id;
unsigned short j, cy_pci_nchan, plx_ver;
int retval;
for (i = 0; i < NR_CARDS; i++) {
/* look for a Cyclades card by vendor and device id */
while ((device_id = cy_pci_dev_id[dev_index].device) != 0) {
if ((pdev = pci_get_device(PCI_VENDOR_ID_CYCLADES,
device_id, pdev)) == NULL) {
dev_index++; /* try next device id */
} else {
break; /* found a board */
}
retval = pci_enable_device(pdev);
if (retval) {
dev_err(&pdev->dev, "cannot enable device\n");
return retval;
}
if (device_id == 0)
break;
if (pci_enable_device(pdev))
continue;
/* read PCI configuration area */
cy_pci_irq = pdev->irq;
cy_pci_phys0 = pci_resource_start(pdev, 0);
cy_pci_phys2 = pci_resource_start(pdev, 2);
pci_read_config_byte(pdev, PCI_REVISION_ID, &cyy_rev_id);
device_id &= ~PCI_DEVICE_ID_MASK;
device_id = pdev->device & ~PCI_DEVICE_ID_MASK;
if (device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo ||
device_id == PCI_DEVICE_ID_CYCLOM_Y_Hi) {
......@@ -4866,10 +4847,11 @@ static int __init cy_detect_pci(void)
/* Although we don't use this I/O region, we should
request it from the kernel anyway, to avoid problems
with other drivers accessing it. */
if (pci_request_regions(pdev, "Cyclom-Y") != 0) {
retval = pci_request_regions(pdev, "Cyclom-Y");
if (retval) {
printk(KERN_ERR "cyclades: failed to reserve "
"PCI resources\n");
continue;
return retval;
}
#if defined(__alpha__)
if (device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo) { /* below 1M? */
......@@ -4883,8 +4865,7 @@ static int __init cy_detect_pci(void)
(ulong)cy_pci_phys0);
printk("Cyclom-Y/PCI not supported for low "
"addresses in Alpha systems.\n");
i--;
continue;
return -EIO;
}
#endif
cy_pci_addr0 = pci_iomap(pdev, 0, CyPCI_Yctl);
......@@ -4901,8 +4882,7 @@ static int __init cy_detect_pci(void)
printk("Cyclom-Y PCI host card with ");
printk("no Serial-Modules at 0x%lx.\n",
(ulong) cy_pci_phys2);
i--;
continue;
return -EIO;
}
if ((cy_next_channel + cy_pci_nchan) > NR_PORTS) {
printk("Cyclom-Y/PCI found at 0x%lx ",
......@@ -4910,7 +4890,7 @@ static int __init cy_detect_pci(void)
printk("but no channels are available.\n");
printk("Change NR_PORTS in cyclades.c and "
"recompile kernel.\n");
return i;
return -EIO;
}
/* fill the next cy_card structure available */
for (j = 0; j < NR_CARDS; j++) {
......@@ -4923,17 +4903,18 @@ static int __init cy_detect_pci(void)
printk("but no more cards can be used.\n");
printk("Change NR_CARDS in cyclades.c and "
"recompile kernel.\n");
return i;
return -EIO;
}
/* allocate IRQ */
if (request_irq(cy_pci_irq, cyy_interrupt,
IRQF_SHARED, "Cyclom-Y", &cy_card[j])) {
retval = request_irq(cy_pci_irq, cyy_interrupt,
IRQF_SHARED, "Cyclom-Y", &cy_card[j]);
if (retval) {
printk("Cyclom-Y/PCI found at 0x%lx ",
(ulong) cy_pci_phys2);
printk("but could not allocate IRQ%d.\n",
cy_pci_irq);
return i;
return retval;
}
/* set cy_card */
......@@ -4994,7 +4975,7 @@ static int __init cy_detect_pci(void)
(ulong)cy_pci_phys2, (ulong)cy_pci_phys0);
printk("Cyclades-Z/PCI not supported for low "
"addresses\n");
break;
return -EIO;
} else if (device_id == PCI_DEVICE_ID_CYCLOM_Z_Hi) {
#ifdef CY_PCI_DEBUG
printk("Cyclades-Z/PCI (bus=0x0%x, pci_id=0x%x, ",
......@@ -5032,18 +5013,17 @@ static int __init cy_detect_pci(void)
/* Although we don't use this I/O region, we should
request it from the kernel anyway, to avoid problems
with other drivers accessing it. */
if (pci_request_regions(pdev, "Cyclades-Z") != 0) {
retval = pci_request_regions(pdev, "Cyclades-Z");
if (retval) {
printk(KERN_ERR "cyclades: failed to reserve "
"PCI resources\n");
continue;
return retval;
}
if (mailbox == ZE_V1) {
retval = cy_init_Ze(cy_pci_phys0, cy_pci_phys2,
cy_pci_addr0, cy_pci_irq, pdev);
if (retval < 0)
i--;
continue;
return retval;
} else {
cy_pci_addr2 = pci_iomap(pdev, 2, CyPCI_Zwin);
}
......@@ -5089,7 +5069,7 @@ static int __init cy_detect_pci(void)
"no channels are available.\nChange "
"NR_PORTS in cyclades.c and recompile "
"kernel.\n", (ulong)cy_pci_phys2);
return i;
return -EIO;
}
/* fill the next cy_card structure available */
......@@ -5102,19 +5082,20 @@ static int __init cy_detect_pci(void)
"no more cards can be used.\nChange "
"NR_CARDS in cyclades.c and recompile "
"kernel.\n", (ulong)cy_pci_phys2);
return i;
return -EIO;
}
#ifdef CONFIG_CYZ_INTR
/* allocate IRQ only if board has an IRQ */
if ((cy_pci_irq != 0) && (cy_pci_irq != 255)) {
if (request_irq(cy_pci_irq, cyz_interrupt,
retval = request_irq(cy_pci_irq, cyz_interrupt,
IRQF_SHARED, "Cyclades-Z",
&cy_card[j])) {
&cy_card[j]);
if (retval) {
printk("Cyclom-8Zo/PCI found at 0x%lx "
"but could not allocate "
"IRQ%d.\n", (ulong)cy_pci_phys2,
cy_pci_irq);
return i;
return retval;
}
}
#endif /* CONFIG_CYZ_INTR */
......@@ -5149,6 +5130,38 @@ static int __init cy_detect_pci(void)
cy_pci_nchan, cy_next_channel);
cy_next_channel += cy_pci_nchan;
}
return 0;
}
#endif
/*
* ---------------------------------------------------------------------
* cy_detect_pci() - Test PCI bus presence and Cyclom-Ye/PCI.
* sets global variables and return the number of PCI boards found.
* ---------------------------------------------------------------------
*/
static int __init cy_detect_pci(void)
{
#ifdef CONFIG_PCI
struct pci_dev *pdev = NULL;
unsigned int i, device_id, dev_index = 0;
for (i = 0; i < NR_CARDS; i++) {
/* look for a Cyclades card by vendor and device id */
while ((device_id = cy_pci_dev_id[dev_index].device) != 0) {
if ((pdev = pci_get_device(PCI_VENDOR_ID_CYCLADES,
device_id, pdev)) == NULL) {
dev_index++; /* try next device id */
} else {
break; /* found a board */
}
}
if (device_id == 0)
break;
i -= !!cy_pci_probe(pdev, &cy_pci_dev_id[dev_index]);
}
return i;
......
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