diff options
author | Tzafrir Cohen <tzafrir.cohen@xorcom.com> | 2011-10-26 18:58:14 +0000 |
---|---|---|
committer | Tzafrir Cohen <tzafrir.cohen@xorcom.com> | 2011-10-26 18:58:14 +0000 |
commit | 003582d221276735233c1155d5d64e3ee7eec4ac (patch) | |
tree | 66494feaba4f8cec822069d61c1ff46f136764ca /drivers/dahdi/tor2.c | |
parent | 2ee9529e22a0c0ba57f01afebe86cdf2e6c72566 (diff) |
dahdi: Register devices instead of individual spans.
Increasingly, spans are implemented by devices that support more than a
single span. Introduce a 'struct dahdi_device' object which explicitly
contains multiple spans. This will allow a cleaner representation of
spans and devices in sysfs since order of arrival will not determine the
layout of the devices. This also gives the core of dahdi a way to know
the relationship between spans.
This generalizes similar concepts that were previously xpp specific. The
conversion of the xpp code was almost entirely done by Oron and Tzafrir.
Signed-off-by: Shaun Ruffell <sruffell@digium.com>
Signed-off-by: Oron Peled <oron.peled@xorcom.com>
Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
git-svn-id: http://svn.asterisk.org/svn/dahdi/linux/trunk@10273 a0bf4364-ded3-4de4-8d8a-66a801d63aff
Diffstat (limited to 'drivers/dahdi/tor2.c')
-rw-r--r-- | drivers/dahdi/tor2.c | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/drivers/dahdi/tor2.c b/drivers/dahdi/tor2.c index 969f569..6fc8930 100644 --- a/drivers/dahdi/tor2.c +++ b/drivers/dahdi/tor2.c @@ -97,6 +97,7 @@ struct tor2 { unsigned long xilinx8_region; /* 8 bit Region allocated to Xilinx */ unsigned long xilinx8_len; /* Length of 8 bit Xilinx region */ __iomem volatile unsigned char *mem8; /* Virtual representation of 8 bit Xilinx memory area */ + struct dahdi_device *ddev; struct tor2_span tspans[SPANS_PER_CARD]; /* Span data */ struct dahdi_chan **chans[SPANS_PER_CARD]; /* Pointers to card channels */ struct tor2_chan tchans[32 * SPANS_PER_CARD]; /* Channel user data */ @@ -285,10 +286,6 @@ static void init_spans(struct tor2 *tor) snprintf(s->desc, sizeof(s->desc) - 1, "Tormenta 2 (PCI) Quad %s Card %d Span %d", (tor->cardtype == TYPE_T1) ? "T1" : "E1", tor->num, x + 1); - s->manufacturer = "Digium"; - strlcpy(s->devicetype, tor->type, sizeof(s->devicetype)); - snprintf(s->location, sizeof(s->location) - 1, - "PCI Bus %02d Slot %02d", tor->pci->bus->number, PCI_SLOT(tor->pci->devfn) + 1); if (tor->cardtype == TYPE_T1) { s->channels = 24; s->deflaw = DAHDI_LAW_MULAW; @@ -322,19 +319,31 @@ static void init_spans(struct tor2 *tor) static int __devinit tor2_launch(struct tor2 *tor) { + int res; struct dahdi_span *s; int i; if (test_bit(DAHDI_FLAGBIT_REGISTERED, &tor->tspans[0].dahdi_span.flags)) return 0; + tor->ddev = dahdi_create_device(); + tor->ddev->location = kasprintf(GFP_KERNEL, "PCI Bus %02d Slot %02d", + tor->pci->bus->number, + PCI_SLOT(tor->pci->devfn) + 1); + + if (!tor->ddev->location) + return -ENOMEM; + printk(KERN_INFO "Tor2: Launching card: %d\n", tor->order); for (i = 0; i < SPANS_PER_CARD; ++i) { s = &tor->tspans[i].dahdi_span; - if (dahdi_register(s, 0)) { - printk(KERN_ERR "Unable to register span %s\n", s->name); - goto error_exit; - } + list_add_tail(&s->device_node, &tor->ddev->spans); + } + + res = dahdi_register_device(tor->ddev, &tor->pci->dev); + if (res) { + dev_err(&tor->pci->dev, "Unable to register with DAHDI.\n"); + return res; } writew(PLX_INTENA, &tor->plx[INTCSR]); /* enable PLX interrupt */ @@ -342,14 +351,6 @@ static int __devinit tor2_launch(struct tor2 *tor) tasklet_init(&tor->tor2_tlet, tor2_tasklet, (unsigned long)tor); #endif return 0; - -error_exit: - for (i = 0; i < SPANS_PER_CARD; ++i) { - s = &tor->tspans[i].dahdi_span; - if (test_bit(DAHDI_FLAGBIT_REGISTERED, &s->flags)) - dahdi_unregister(s); - } - return -1; } static void free_tor(struct tor2 *tor) @@ -365,6 +366,8 @@ static void free_tor(struct tor2 *tor) if (tor->chans[x]) kfree(tor->chans[x]); } + kfree(tor->ddev->location); + dahdi_free_device(tor->ddev); kfree(tor); } @@ -631,7 +634,6 @@ static struct pci_driver tor2_driver; static void __devexit tor2_remove(struct pci_dev *pdev) { struct tor2 *tor; - int i; tor = pci_get_drvdata(pdev); if (!tor) @@ -641,11 +643,7 @@ static void __devexit tor2_remove(struct pci_dev *pdev) writeb(0, &tor->mem8[LEDREG]); writew(0, &tor->plx[INTCSR]); free_irq(tor->irq, tor); - for (i = 0; i < SPANS_PER_CARD; ++i) { - struct dahdi_span *s = &tor->tspans[i].dahdi_span; - if (test_bit(DAHDI_FLAGBIT_REGISTERED, &s->flags)) - dahdi_unregister(s); - } + dahdi_unregister_device(tor->ddev); release_mem_region(tor->plx_region, tor->plx_len); release_mem_region(tor->xilinx32_region, tor->xilinx32_len); release_mem_region(tor->xilinx8_region, tor->xilinx8_len); |