summaryrefslogtreecommitdiff
path: root/drivers/dahdi/wct4xxp/base.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/dahdi/wct4xxp/base.c')
-rw-r--r--drivers/dahdi/wct4xxp/base.c115
1 files changed, 59 insertions, 56 deletions
diff --git a/drivers/dahdi/wct4xxp/base.c b/drivers/dahdi/wct4xxp/base.c
index 97a1f3c..b4a4206 100644
--- a/drivers/dahdi/wct4xxp/base.c
+++ b/drivers/dahdi/wct4xxp/base.c
@@ -43,6 +43,8 @@
#include <dahdi/kernel.h>
+#include <stdbool.h>
+
#include "wct4xxp.h"
#include "vpm450m.h"
@@ -339,6 +341,7 @@ struct t4 {
int t1e1; /* T1/E1 select pins */
int globalconfig; /* Whether global setup has been done */
int syncsrc; /* active sync source */
+ struct dahdi_device *ddev;
struct t4_span *tspans[4]; /* Individual spans */
int numspans; /* Number of spans on the card */
int blinktimer;
@@ -2015,23 +2018,27 @@ static int t4_close(struct dahdi_chan *chan)
return 0;
}
-static void set_span_devicetype(struct t4 *wc)
+static int set_span_devicetype(struct t4 *wc)
{
- int x;
- struct t4_span *ts;
+ const char *vpmstring;
- for (x = 0; x < wc->numspans; x++) {
- ts = wc->tspans[x];
- strlcpy(ts->span.devicetype, wc->variety,
- sizeof(ts->span.devicetype));
- if (wc->vpm == T4_VPM_PRESENT) {
- if (!wc->vpm450m)
- strncat(ts->span.devicetype, " (VPM400M)", sizeof(ts->span.devicetype) - 1);
- else
- strncat(ts->span.devicetype, (wc->numspans > 2) ? " (VPMOCT128)" : " (VPMOCT064)",
- sizeof(ts->span.devicetype) - 1);
- }
+ if (wc->vpm == T4_VPM_PRESENT) {
+ if (!wc->vpm450m)
+ vpmstring = "400M";
+ else if (wc->numspans > 2)
+ vpmstring = "OCT128";
+ else
+ vpmstring = "OCT064";
+
+ wc->ddev->devicetype = kasprintf(GFP_KERNEL, "%s (VPM%s)",
+ wc->variety, vpmstring);
+ } else {
+ wc->ddev->devicetype = kasprintf(GFP_KERNEL, wc->variety);
}
+
+ if (!wc->ddev->devicetype)
+ return -ENOMEM;
+ return 0;
}
/* The number of cards we have seen with each
@@ -2111,13 +2118,6 @@ static void init_spans(struct t4 *wc)
sprintf(ts->span.name, "TE%d/%d/%d", wc->numspans, wc->num, x + 1);
snprintf(ts->span.desc, sizeof(ts->span.desc) - 1,
"T%dXXP (PCI) Card %d Span %d", wc->numspans, wc->num, x+1);
- ts->span.manufacturer = "Digium";
- if (order_index[wc->order] == 1)
- snprintf(ts->span.location, sizeof(ts->span.location) - 1, "Board ID Switch %d", wc->order);
- else
- snprintf(ts->span.location, sizeof(ts->span.location) - 1,
- "PCI%s Bus %02d Slot %02d", (ts->spanflags & FLAG_EXPRESS) ? " Express" : " ",
- wc->dev->bus->number, PCI_SLOT(wc->dev->devfn) + 1);
switch (ts->spantype) {
case TYPE_T1:
ts->span.spantype = "T1";
@@ -4579,9 +4579,12 @@ static int t4_hardware_init_2(struct t4 *wc)
static int __devinit t4_launch(struct t4 *wc)
{
int x;
+ int res;
unsigned long flags;
+
if (test_bit(DAHDI_FLAGBIT_REGISTERED, &wc->tspans[0]->span.flags))
return 0;
+
dev_info(&wc->dev->dev, "TE%dXXP: Launching card: %d\n", wc->numspans,
wc->order);
@@ -4589,35 +4592,33 @@ static int __devinit t4_launch(struct t4 *wc)
for (x=0;x<PORTS_PER_FRAMER;x++)
t4_serial_setup(wc, x);
- if (dahdi_register(&wc->tspans[0]->span, 0)) {
- dev_err(&wc->dev->dev, "Unable to register span %s\n",
- wc->tspans[0]->span.name);
- return -1;
+ wc->ddev->manufacturer = "Digium";
+ if (order_index[wc->order] == 1) {
+ wc->ddev->location = kasprintf(GFP_KERNEL,
+ "Board ID Switch %d", wc->order);
+ } else {
+ bool express = ((wc->tspans[0]->spanflags & FLAG_EXPRESS) > 0);
+ wc->ddev->location = kasprintf(GFP_KERNEL,
+ "PCI%s Bus %02d Slot %02d",
+ (express) ? " Express" : " ",
+ wc->dev->bus->number,
+ PCI_SLOT(wc->dev->devfn) + 1);
}
- if (dahdi_register(&wc->tspans[1]->span, 0)) {
- dev_err(&wc->dev->dev, "Unable to register span %s\n",
- wc->tspans[1]->span.name);
- dahdi_unregister(&wc->tspans[0]->span);
- return -1;
+
+ if (!wc->ddev->location)
+ return -ENOMEM;
+
+ for (x = 0; x < wc->numspans; ++x) {
+ list_add_tail(&wc->tspans[x]->span.device_node,
+ &wc->ddev->spans);
}
- if (wc->numspans == 4) {
- if (dahdi_register(&wc->tspans[2]->span, 0)) {
- dev_err(&wc->dev->dev, "Unable to register span %s\n",
- wc->tspans[2]->span.name);
- dahdi_unregister(&wc->tspans[0]->span);
- dahdi_unregister(&wc->tspans[1]->span);
- return -1;
- }
- if (dahdi_register(&wc->tspans[3]->span, 0)) {
- dev_err(&wc->dev->dev, "Unable to register span %s\n",
- wc->tspans[3]->span.name);
- dahdi_unregister(&wc->tspans[0]->span);
- dahdi_unregister(&wc->tspans[1]->span);
- dahdi_unregister(&wc->tspans[2]->span);
- return -1;
- }
+ res = dahdi_register_device(wc->ddev, &wc->dev->dev);
+ if (res) {
+ dev_err(&wc->dev->dev, "Failed to register with DAHDI.\n");
+ return res;
}
+
set_bit(T4_CHECK_TIMING, &wc->checkflag);
spin_lock_irqsave(&wc->reglock, flags);
__t4_set_sclk_src(wc, WC_SELF, 0, 0);
@@ -4644,6 +4645,10 @@ static void free_wc(struct t4 *wc)
}
kfree(wc->tspans[x]);
}
+
+ kfree(wc->ddev->devicetype);
+ kfree(wc->ddev->location);
+ dahdi_free_device(wc->ddev);
kfree(wc);
}
@@ -4658,11 +4663,11 @@ static int __devinit t4_init_one(struct pci_dev *pdev, const struct pci_device_i
return -EIO;
}
- if (!(wc = kmalloc(sizeof(*wc), GFP_KERNEL))) {
+ wc = kzalloc(sizeof(*wc), GFP_KERNEL);
+ if (!wc)
return -ENOMEM;
- }
- memset(wc, 0x0, sizeof(*wc));
+ wc->ddev = dahdi_create_device();
spin_lock_init(&wc->reglock);
dt = (struct devtype *) (ent->driver_data);
@@ -4884,9 +4889,12 @@ static int t4_hardware_stop(struct t4 *wc)
static void _t4_remove_one(struct t4 *wc)
{
- struct dahdi_span *span;
int basesize;
- int i;
+
+ if (!wc)
+ return;
+
+ dahdi_unregister_device(wc->ddev);
remove_sysfs_files(wc);
@@ -4903,11 +4911,6 @@ static void _t4_remove_one(struct t4 *wc)
if (!(wc->tspans[0]->spanflags & FLAG_2NDGEN))
basesize = basesize * 2;
- for (i = 0; i < wc->numspans; ++i) {
- span = &wc->tspans[i]->span;
- if (test_bit(DAHDI_FLAGBIT_REGISTERED, &span->flags))
- dahdi_unregister(span);
- }
#ifdef ENABLE_WORKQUEUES
if (wc->workq) {
flush_workqueue(wc->workq);