| 1 |
/* |
| 2 |
* PCI RADIO Card DAHDI Telephony PCI Quad Radio Interface driver |
| 3 |
* |
| 4 |
* Written by Jim Dixon <[email protected]> |
| 5 |
* Based on previous work by Mark Spencer <[email protected]> |
| 6 |
* Based on previous works, designs, and archetectures conceived and |
| 7 |
* written by Jim Dixon <[email protected]>. |
| 8 |
* |
| 9 |
* Copyright (C) 2001-2007 Jim Dixon / Zapata Telephony. |
| 10 |
* |
| 11 |
* All rights reserved. |
| 12 |
* |
| 13 |
* |
| 14 |
*/ |
| 15 |
|
| 16 |
/* |
| 17 |
* See http://www.asterisk.org for more information about |
| 18 |
* the Asterisk project. Please do not directly contact |
| 19 |
* any of the maintainers of this project for assistance; |
| 20 |
* the project provides a web site, mailing lists and IRC |
| 21 |
* channels for your use. |
| 22 |
* |
| 23 |
* This program is free software, distributed under the terms of |
| 24 |
* the GNU General Public License Version 2 as published by the |
| 25 |
* Free Software Foundation. See the LICENSE file included with |
| 26 |
* this program for more details. |
| 27 |
*/ |
| 28 |
|
| 29 |
/* |
| 30 |
The PCI Radio Interface card interfaces up to 4 two-way radios (either |
| 31 |
a base/mobile radio or repeater system) to DAHDI channels. The driver |
| 32 |
may work either independent of an application, or with it, through |
| 33 |
the driver;s ioctl() interface. This file gives you access to specify |
| 34 |
load-time parameters for Radio channels, so that the driver may run |
| 35 |
by itself, and just act like a generic DAHDI radio interface. |
| 36 |
*/ |
| 37 |
|
| 38 |
/* Latency tests: |
| 39 |
|
| 40 |
Without driver: 308496 |
| 41 |
With driver: 303826 (1.5 %) |
| 42 |
|
| 43 |
*/ |
| 44 |
|
| 45 |
|
| 46 |
#include <linux/kernel.h> |
| 47 |
#include <linux/errno.h> |
| 48 |
#include <linux/module.h> |
| 49 |
#include <linux/init.h> |
| 50 |
#include <linux/pci.h> |
| 51 |
#include <linux/interrupt.h> |
| 52 |
#include <linux/moduleparam.h> |
| 53 |
#include <linux/sched.h> |
| 54 |
#include <linux/slab.h> |
| 55 |
#include <linux/delay.h> |
| 56 |
#include <asm/io.h> |
| 57 |
#include <asm/delay.h> |
| 58 |
|
| 59 |
#include <dahdi/kernel.h> |
| 60 |
|
| 61 |
#define RAD_MAX_IFACES 128 |
| 62 |
|
| 63 |
#define NUM_CODES 15 |
| 64 |
|
| 65 |
#define SERIAL_BUFLEN 128 |
| 66 |
|
| 67 |
#define SRX_TIMEOUT 300 |
| 68 |
|
| 69 |
#define RAD_CNTL 0x00 |
| 70 |
#define RAD_OPER 0x01 |
| 71 |
#define RAD_AUXC 0x02 |
| 72 |
#define RAD_AUXD 0x03 |
| 73 |
#define XPGM 4 |
| 74 |
#define XCS 2 |
| 75 |
|
| 76 |
#define RAD_MASK0 0x04 |
| 77 |
#define RAD_MASK1 0x05 |
| 78 |
#define RAD_INTSTAT 0x06 |
| 79 |
#define RAD_AUXR 0x07 |
| 80 |
#define XINIT 8 |
| 81 |
#define XDONE 0x10 |
| 82 |
|
| 83 |
#define RAD_DMAWS 0x08 |
| 84 |
#define RAD_DMAWI 0x0c |
| 85 |
#define RAD_DMAWE 0x10 |
| 86 |
#define RAD_DMARS 0x18 |
| 87 |
#define RAD_DMARI 0x1c |
| 88 |
#define RAD_DMARE 0x20 |
| 89 |
|
| 90 |
#define RAD_AUXFUNC 0x2b |
| 91 |
#define RAD_SERCTL 0x2d |
| 92 |
#define RAD_FSCDELAY 0x2f |
| 93 |
|
| 94 |
#define RAD_REGBASE 0xc0 |
| 95 |
|
| 96 |
#define RAD_CTCSSMASK 0xf |
| 97 |
#define RAD_CTCSSOTHER 0xf |
| 98 |
#define RAD_CTCSSVALID 0x10 |
| 99 |
|
| 100 |
#define NUM_CHANS 4 |
| 101 |
|
| 102 |
#define RAD_GOTRX_DEBOUNCE_TIME 75 |
| 103 |
#define RAD_CTCSS_ACQUIRE_TIME 10 |
| 104 |
#define RAD_CTCSS_TALKOFF_TIME 1000 |
| 105 |
|
| 106 |
#define DAHDI_RADPAR_CTCSSACQUIRETIME 18 /* DEBUG only, this belongs in dahdi.h */ |
| 107 |
#define DAHDI_RADPAR_CTCSSTALKOFFTIME 19 /* DEBUG only, this belongs in dahdi.h */ |
| 108 |
|
| 109 |
/* |
| 110 |
* MX828 Commands |
| 111 |
*/ |
| 112 |
|
| 113 |
#define MX828_GEN_RESET 0x01 /* W */ |
| 114 |
#define MX828_SAUDIO_CTRL 0x80 /* W */ |
| 115 |
#define MX828_SAUDIO_STATUS 0x81 /* R */ |
| 116 |
#define MX828_SAUDIO_SETUP 0x82 /* W */ |
| 117 |
#define MX828_TX_TONE 0x83 /* W16 */ |
| 118 |
#define MX828_RX_TONE 0x84 /* W16 */ |
| 119 |
#define MX828_DCS3 0x85 /* W */ |
| 120 |
#define MX828_DCS2 0x86 /* W */ |
| 121 |
#define MX828_DCS1 0x87 /* W */ |
| 122 |
#define MX828_GEN_CTRL 0x88 /* W */ |
| 123 |
#define MX828_GPT 0x8B /* W */ |
| 124 |
#define MX828_IRQ_MASK 0x8E /* W */ |
| 125 |
#define MX828_SELCALL 0x8D /* W16 */ |
| 126 |
#define MX828_AUD_CTRL 0x8A /* W16 */ |
| 127 |
#define MX828_IRQ_FLAG 0x8F /* R */ |
| 128 |
|
| 129 |
|
| 130 |
struct encdec |
| 131 |
{ |
| 132 |
unsigned char state; /* 0 = idle */ |
| 133 |
int chan; |
| 134 |
unsigned char req[NUM_CHANS]; |
| 135 |
unsigned char dcsrx[NUM_CHANS]; |
| 136 |
unsigned char ctrx[NUM_CHANS]; |
| 137 |
unsigned char dcstx[NUM_CHANS]; |
| 138 |
unsigned char cttx[NUM_CHANS]; |
| 139 |
unsigned char saudio_ctrl[NUM_CHANS]; |
| 140 |
unsigned char saudio_setup[NUM_CHANS]; |
| 141 |
unsigned char txcode[NUM_CHANS]; |
| 142 |
unsigned long lastcmd; |
| 143 |
int myindex[NUM_CHANS]; |
| 144 |
unsigned long waittime; |
| 145 |
unsigned char retstate; |
| 146 |
} ; |
| 147 |
|
| 148 |
|
| 149 |
struct pciradio { |
| 150 |
struct pci_dev *dev; |
| 151 |
struct dahdi_device *ddev; |
| 152 |
struct dahdi_span span; |
| 153 |
unsigned char ios; |
| 154 |
int usecount; |
| 155 |
unsigned int intcount; |
| 156 |
int dead; |
| 157 |
int pos; |
| 158 |
int freeregion; |
| 159 |
int nchans; |
| 160 |
spinlock_t lock; |
| 161 |
int remote_locked; |
| 162 |
unsigned char rxbuf[SERIAL_BUFLEN]; |
| 163 |
unsigned short rxindex; |
| 164 |
unsigned long srxtimer; |
| 165 |
unsigned char txbuf[SERIAL_BUFLEN]; |
| 166 |
unsigned short txindex; |
| 167 |
unsigned short txlen; |
| 168 |
unsigned char pasave; |
| 169 |
unsigned char pfsave; |
| 170 |
volatile unsigned long ioaddr; |
| 171 |
dma_addr_t readdma; |
| 172 |
dma_addr_t writedma; |
| 173 |
volatile unsigned int *writechunk; /* Double-word aligned write memory */ |
| 174 |
volatile unsigned int *readchunk; /* Double-word aligned read memory */ |
| 175 |
unsigned char saudio_status[NUM_CHANS]; |
| 176 |
char gotcor[NUM_CHANS]; |
| 177 |
char gotct[NUM_CHANS]; |
| 178 |
char newctcssstate[NUM_CHANS]; |
| 179 |
char ctcssstate[NUM_CHANS]; |
| 180 |
char gotrx[NUM_CHANS]; |
| 181 |
char gotrx1[NUM_CHANS]; |
| 182 |
char gottx[NUM_CHANS]; |
| 183 |
char lasttx[NUM_CHANS]; |
| 184 |
int gotrxtimer[NUM_CHANS]; |
| 185 |
int ctcsstimer[NUM_CHANS]; |
| 186 |
int debouncetime[NUM_CHANS]; |
| 187 |
int ctcssacquiretime[NUM_CHANS]; |
| 188 |
int ctcsstalkofftime[NUM_CHANS]; |
| 189 |
int bursttime[NUM_CHANS]; |
| 190 |
int bursttimer[NUM_CHANS]; |
| 191 |
unsigned char remmode[NUM_CHANS]; |
| 192 |
unsigned short present_code[NUM_CHANS]; |
| 193 |
unsigned short last_code[NUM_CHANS]; |
| 194 |
unsigned short rxcode[NUM_CHANS][NUM_CODES + 1]; |
| 195 |
unsigned short rxclass[NUM_CHANS][NUM_CODES + 1]; |
| 196 |
unsigned short txcode[NUM_CHANS][NUM_CODES + 1];; |
| 197 |
unsigned char radmode[NUM_CHANS]; |
| 198 |
#define RADMODE_INVERTCOR 1 |
| 199 |
#define RADMODE_IGNORECOR 2 |
| 200 |
#define RADMODE_EXTTONE 4 |
| 201 |
#define RADMODE_EXTINVERT 8 |
| 202 |
#define RADMODE_IGNORECT 16 |
| 203 |
#define RADMODE_NOENCODE 32 |
| 204 |
unsigned char corthresh[NUM_CHANS]; |
| 205 |
struct dahdi_chan _chans[NUM_CHANS]; |
| 206 |
struct dahdi_chan *chans; |
| 207 |
unsigned char mx828_addr; |
| 208 |
struct encdec encdec; |
| 209 |
unsigned long lastremcmd; |
| 210 |
}; |
| 211 |
|
| 212 |
|
| 213 |
static struct pciradio *ifaces[RAD_MAX_IFACES]; |
| 214 |
|
| 215 |
static void pciradio_release(struct pciradio *rad); |
| 216 |
|
| 217 |
static int debug = 0; |
| 218 |
|
| 219 |
struct tonedef { |
| 220 |
int code; |
| 221 |
unsigned char b1; |
| 222 |
unsigned char b2; |
| 223 |
} ; |
| 224 |
|
| 225 |
#include "radfw.h" |
| 226 |
|
| 227 |
static struct tonedef cttable_tx [] = { |
| 228 |
{0,0,0}, |
| 229 |
{670,0xE,0xB1}, |
| 230 |
{693,0xE,0x34}, |
| 231 |
{719,0xD,0xB1}, |
| 232 |
{744,0xD,0x3B}, |
| 233 |
{770,0xC,0xC9}, |
| 234 |
{797,0xC,0x5A}, |
| 235 |
{825,0xB,0xEF}, |
| 236 |
{854,0xB,0x87}, |
| 237 |
{885,0xB,0x1F}, |
| 238 |
{915,0xA,0xC2}, |
| 239 |
{948,0xA,0x62}, |
| 240 |
{974,0xA,0x1B}, |
| 241 |
{1000,0x9,0xD8}, |
| 242 |
{1035,0x9,0x83}, |
| 243 |
{1072,0x9,0x2F}, |
| 244 |
{1109,0x8,0xE0}, |
| 245 |
{1148,0x8,0x93}, |
| 246 |
{1188,0x8,0x49}, |
| 247 |
{1230,0x8,0x1}, |
| 248 |
{1273,0x7,0xBC}, |
| 249 |
{1318,0x7,0x78}, |
| 250 |
{1365,0x7,0x36}, |
| 251 |
{1413,0x6,0xF7}, |
| 252 |
{1462,0x6,0xBC}, |
| 253 |
{1514,0x6,0x80}, |
| 254 |
{1567,0x6,0x48}, |
| 255 |
{1598,0x6,0x29}, |
| 256 |
{1622,0x6,0x12}, |
| 257 |
{1679,0x5,0xDD}, |
| 258 |
{1738,0x5,0xAA}, |
| 259 |
{1799,0x5,0x79}, |
| 260 |
{1835,0x5,0x5D}, |
| 261 |
{1862,0x5,0x49}, |
| 262 |
{1899,0x5,0x2F}, |
| 263 |
{1928,0x5,0x1B}, |
| 264 |
{1966,0x5,0x2}, |
| 265 |
{1995,0x4,0xEF}, |
| 266 |
{2035,0x4,0xD6}, |
| 267 |
{2065,0x4,0xC4}, |
| 268 |
{2107,0x4,0xAC}, |
| 269 |
{2181,0x4,0x83}, |
| 270 |
{2257,0x4,0x5D}, |
| 271 |
{2291,0x4,0x4C}, |
| 272 |
{2336,0x4,0x37}, |
| 273 |
{2418,0x4,0x12}, |
| 274 |
{2503,0x3,0xEF}, |
| 275 |
{2541,0x3,0xE0}, |
| 276 |
{0,0,0} |
| 277 |
} ; |
| 278 |
|
| 279 |
static struct tonedef cttable_rx [] = { |
| 280 |
{0,0,0}, |
| 281 |
{670,0x3,0xD8}, |
| 282 |
{693,0x4,0x9}, |
| 283 |
{719,0x4,0x1B}, |
| 284 |
{744,0x4,0x4E}, |
| 285 |
{770,0x4,0x83}, |
| 286 |
{797,0x4,0x94}, |
| 287 |
{825,0x4,0xCB}, |
| 288 |
{854,0x5,0x2}, |
| 289 |
{885,0x5,0x14}, |
| 290 |
{915,0x5,0x4C}, |
| 291 |
{948,0x5,0x87}, |
| 292 |
{974,0x5,0x94}, |
| 293 |
{1000,0x5,0xCB}, |
| 294 |
{1035,0x6,0x7}, |
| 295 |
{1072,0x6,0x45}, |
| 296 |
{1109,0x6,0x82}, |
| 297 |
{1148,0x6,0xC0}, |
| 298 |
{1188,0x6,0xD1}, |
| 299 |
{1230,0x7,0x10}, |
| 300 |
{1273,0x7,0x50}, |
| 301 |
{1318,0x7,0xC0}, |
| 302 |
{1365,0x8,0x2}, |
| 303 |
{1413,0x8,0x44}, |
| 304 |
{1462,0x8,0x86}, |
| 305 |
{1514,0x8,0xC9}, |
| 306 |
{1567,0x9,0xC}, |
| 307 |
{1598,0x9,0x48}, |
| 308 |
{1622,0x9,0x82}, |
| 309 |
{1679,0x9,0xC6}, |
| 310 |
{1738,0xA,0xB}, |
| 311 |
{1799,0xA,0x84}, |
| 312 |
{1835,0xA,0xC2}, |
| 313 |
{1862,0xA,0xC9}, |
| 314 |
{1899,0xB,0x8}, |
| 315 |
{1928,0xB,0x44}, |
| 316 |
{1966,0xB,0x83}, |
| 317 |
{1995,0xB,0x8A}, |
| 318 |
{2035,0xB,0xC9}, |
| 319 |
{2065,0xC,0x6}, |
| 320 |
{2107,0xC,0x46}, |
| 321 |
{2181,0xC,0xC3}, |
| 322 |
{2257,0xD,0x41}, |
| 323 |
{2291,0xD,0x48}, |
| 324 |
{2336,0xD,0x89}, |
| 325 |
{2418,0xE,0x8}, |
| 326 |
{2503,0xE,0x88}, |
| 327 |
{2541,0xE,0xC7}, |
| 328 |
{0,0,0} |
| 329 |
}; |
| 330 |
|
| 331 |
static struct { |
| 332 |
int code; |
| 333 |
char b3; |
| 334 |
char b2; |
| 335 |
char b1; |
| 336 |
} dcstable[] = { |
| 337 |
{0,0,0,0}, |
| 338 |
{23,0x76,0x38,0x13}, |
| 339 |
{25,0x6B,0x78,0x15}, |
| 340 |
{26,0x65,0xD8,0x16}, |
| 341 |
{31,0x51,0xF8,0x19}, |
| 342 |
{32,0x5F,0x58,0x1A}, |
| 343 |
{43,0x5B,0x68,0x23}, |
| 344 |
{47,0x0F,0xD8,0x27}, |
| 345 |
{51,0x7C,0xA8,0x29}, |
| 346 |
{54,0x6F,0x48,0x2C}, |
| 347 |
{65,0x5D,0x18,0x35}, |
| 348 |
{71,0x67,0x98,0x39}, |
| 349 |
{72,0x69,0x38,0x3A}, |
| 350 |
{73,0x2E,0x68,0x3B}, |
| 351 |
{74,0x74,0x78,0x3C}, |
| 352 |
{114,0x35,0xE8,0x4C}, |
| 353 |
{115,0x72,0xB8,0x4D}, |
| 354 |
{116,0x7C,0x18,0x4E}, |
| 355 |
{125,0x07,0xB8,0x55}, |
| 356 |
{131,0x3D,0x38,0x59}, |
| 357 |
{132,0x33,0x98,0x5A}, |
| 358 |
{134,0x2E,0xD8,0x5C}, |
| 359 |
{143,0x37,0xA8,0x63}, |
| 360 |
{152,0x1E,0xC8,0x6A}, |
| 361 |
{155,0x44,0xD8,0x6D}, |
| 362 |
{156,0x4A,0x78,0x6E}, |
| 363 |
{162,0x6B,0xC8,0x72}, |
| 364 |
{165,0x31,0xD8,0x75}, |
| 365 |
{172,0x05,0xF8,0x7A}, |
| 366 |
{174,0x18,0xB8,0x7C}, |
| 367 |
{205,0x6E,0x98,0x85}, |
| 368 |
{223,0x68,0xE8,0x93}, |
| 369 |
{226,0x7B,0x08,0x96}, |
| 370 |
{243,0x45,0xB8,0xA3}, |
| 371 |
{244,0x1F,0xA8,0xA4}, |
| 372 |
{245,0x58,0xF8,0xA5}, |
| 373 |
{251,0x62,0x78,0xA9}, |
| 374 |
{261,0x17,0x78,0xB1}, |
| 375 |
{263,0x5E,0x88,0xB3}, |
| 376 |
{265,0x43,0xC8,0xB5}, |
| 377 |
{271,0x79,0x48,0xB9}, |
| 378 |
{306,0x0C,0xF8,0xC6}, |
| 379 |
{311,0x38,0xD8,0xC9}, |
| 380 |
{315,0x6C,0x68,0xCD}, |
| 381 |
{331,0x23,0xE8,0xD9}, |
| 382 |
{343,0x29,0x78,0xE3}, |
| 383 |
{346,0x3A,0x98,0xE6}, |
| 384 |
{351,0x0E,0xB8,0xE9}, |
| 385 |
{364,0x68,0x58,0xF4}, |
| 386 |
{365,0x2F,0x08,0xF5}, |
| 387 |
{371,0x15,0x88,0xF9}, |
| 388 |
{411,0x77,0x69,0x09}, |
| 389 |
{412,0x79,0xC9,0x0A}, |
| 390 |
{413,0x3E,0x99,0x0B}, |
| 391 |
{423,0x4B,0x99,0x13}, |
| 392 |
{431,0x6C,0x59,0x19}, |
| 393 |
{432,0x62,0xF9,0x1A}, |
| 394 |
{445,0x7B,0x89,0x25}, |
| 395 |
{464,0x27,0xE9,0x34}, |
| 396 |
{465,0x60,0xB9,0x35}, |
| 397 |
{466,0x6E,0x19,0x36}, |
| 398 |
{503,0x3C,0x69,0x43}, |
| 399 |
{506,0x2F,0x89,0x46}, |
| 400 |
{516,0x41,0xB9,0x4E}, |
| 401 |
{532,0x0E,0x39,0x5A}, |
| 402 |
{546,0x19,0xE9,0x66}, |
| 403 |
{565,0x0C,0x79,0x75}, |
| 404 |
{606,0x5D,0x99,0x86}, |
| 405 |
{612,0x67,0x19,0x8A}, |
| 406 |
{624,0x0F,0x59,0x94}, |
| 407 |
{627,0x01,0xF9,0x97}, |
| 408 |
{631,0x72,0x89,0x99}, |
| 409 |
{632,0x7C,0x29,0x9A}, |
| 410 |
{654,0x4C,0x39,0xAC}, |
| 411 |
{662,0x24,0x79,0xB2}, |
| 412 |
{664,0x39,0x39,0xB4}, |
| 413 |
{703,0x22,0xB9,0xC3}, |
| 414 |
{712,0x0B,0xD9,0xCA}, |
| 415 |
{723,0x39,0x89,0xD3}, |
| 416 |
{731,0x1E,0x49,0xD9}, |
| 417 |
{732,0x10,0xE9,0xDA}, |
| 418 |
{734,0x0D,0xA9,0xDC}, |
| 419 |
{743,0x14,0xD9,0xE3}, |
| 420 |
{754,0x20,0xF9,0xEC}, |
| 421 |
{0,0,0,0} |
| 422 |
}; |
| 423 |
|
| 424 |
static int gettxtone(int code) |
| 425 |
{ |
| 426 |
int i; |
| 427 |
|
| 428 |
if (!code) return(0); |
| 429 |
for(i = 0; cttable_tx[i].code || (!i); i++) |
| 430 |
{ |
| 431 |
if (cttable_tx[i].code == code) |
| 432 |
{ |
| 433 |
return (i); |
| 434 |
} |
| 435 |
} |
| 436 |
return(-1); |
| 437 |
} |
| 438 |
|
| 439 |
static int getrxtone(int code) |
| 440 |
{ |
| 441 |
int i; |
| 442 |
|
| 443 |
if (!code) return(0); |
| 444 |
for(i = 0; cttable_rx[i].code || (!i); i++) |
| 445 |
{ |
| 446 |
if (cttable_rx[i].code == code) |
| 447 |
{ |
| 448 |
return (i); |
| 449 |
} |
| 450 |
} |
| 451 |
return(-1); |
| 452 |
} |
| 453 |
|
| 454 |
|
| 455 |
static int getdcstone(int code) |
| 456 |
{ |
| 457 |
int i; |
| 458 |
|
| 459 |
if (!code) return(0); |
| 460 |
for(i = 0; dcstable[i].code || (!i); i++) |
| 461 |
{ |
| 462 |
if (dcstable[i].code == code) |
| 463 |
{ |
| 464 |
return (i); |
| 465 |
} |
| 466 |
} |
| 467 |
return(-1); |
| 468 |
} |
| 469 |
|
| 470 |
|
| 471 |
static void __pciradio_setcreg(struct pciradio *rad, unsigned char reg, unsigned char val) |
| 472 |
{ |
| 473 |
outb(val, rad->ioaddr + RAD_REGBASE + ((reg & 0xf) << 2)); |
| 474 |
} |
| 475 |
|
| 476 |
static unsigned char __pciradio_getcreg(struct pciradio *rad, unsigned char reg) |
| 477 |
{ |
| 478 |
return inb(rad->ioaddr + RAD_REGBASE + ((reg & 0xf) << 2)); |
| 479 |
} |
| 480 |
|
| 481 |
static void rbi_out(struct pciradio *rad, int n, unsigned char *rbicmd) |
| 482 |
{ |
| 483 |
unsigned long flags; |
| 484 |
int x; |
| 485 |
|
| 486 |
for(;;) |
| 487 |
{ |
| 488 |
spin_lock_irqsave(&rad->lock,flags); |
| 489 |
x = rad->remote_locked || (__pciradio_getcreg(rad,0xc) & 2); |
| 490 |
if (!x) rad->remote_locked = 1; |
| 491 |
spin_unlock_irqrestore(&rad->lock,flags); |
| 492 |
if (x) |
| 493 |
msleep_interruptible(20); |
| 494 |
else break; |
| 495 |
} |
| 496 |
spin_lock_irqsave(&rad->lock,flags); |
| 497 |
/* enable and address RBI serializer */ |
| 498 |
__pciradio_setcreg(rad,0xf,rad->pfsave | (n << 4) | 0x40); |
| 499 |
/* output commands */ |
| 500 |
for(x = 0; x < 5; x++) __pciradio_setcreg(rad,0xc,rbicmd[x]); |
| 501 |
/* output it */ |
| 502 |
__pciradio_setcreg(rad,0xb,1); |
| 503 |
rad->remote_locked = 0; |
| 504 |
spin_unlock_irqrestore(&rad->lock,flags); |
| 505 |
return; |
| 506 |
} |
| 507 |
|
| 508 |
|
| 509 |
/* |
| 510 |
* Output a command to the MX828 over the serial bus |
| 511 |
*/ |
| 512 |
|
| 513 |
|
| 514 |
static void mx828_command(struct pciradio *rad,int channel, unsigned char command, unsigned char *byte1, unsigned char *byte2) |
| 515 |
{ |
| 516 |
|
| 517 |
if(channel > 3) |
| 518 |
return; |
| 519 |
|
| 520 |
rad->mx828_addr = channel; |
| 521 |
__pciradio_setcreg(rad,0,channel); |
| 522 |
if (byte1) __pciradio_setcreg(rad,1,*byte1); |
| 523 |
if (byte2) __pciradio_setcreg(rad,2,*byte2); |
| 524 |
__pciradio_setcreg(rad,3,command); |
| 525 |
|
| 526 |
} |
| 527 |
|
| 528 |
static void mx828_command_wait(struct pciradio *rad,int channel, unsigned char command, unsigned char *byte1, unsigned char *byte2) |
| 529 |
{ |
| 530 |
unsigned long flags; |
| 531 |
|
| 532 |
|
| 533 |
spin_lock_irqsave(&rad->lock,flags); |
| 534 |
while(rad->encdec.state) |
| 535 |
{ |
| 536 |
spin_unlock_irqrestore(&rad->lock,flags); |
| 537 |
msleep_interruptible(20); |
| 538 |
spin_lock_irqsave(&rad->lock,flags); |
| 539 |
} |
| 540 |
rad->encdec.lastcmd = jiffies + 1000; |
| 541 |
spin_unlock_irqrestore(&rad->lock,flags); |
| 542 |
while(__pciradio_getcreg(rad,0xc) & 1); |
| 543 |
rad->encdec.lastcmd = jiffies + 1000; |
| 544 |
spin_lock_irqsave(&rad->lock,flags); |
| 545 |
rad->encdec.lastcmd = jiffies + 1000; |
| 546 |
mx828_command(rad,channel,command,byte1,byte2); |
| 547 |
spin_unlock_irqrestore(&rad->lock,flags); |
| 548 |
rad->encdec.lastcmd = jiffies + 1000; |
| 549 |
while(__pciradio_getcreg(rad,0xc) & 1); |
| 550 |
rad->encdec.lastcmd = jiffies; |
| 551 |
} |
| 552 |
|
| 553 |
static void _do_encdec(struct pciradio *rad) |
| 554 |
{ |
| 555 |
int i,n; |
| 556 |
unsigned char byte1 = 0,byte2 = 0; |
| 557 |
|
| 558 |
/* return doing nothing if busy */ |
| 559 |
if ((rad->encdec.lastcmd + 2) > jiffies) return; |
| 560 |
if (__pciradio_getcreg(rad,0xc) & 1) return; |
| 561 |
n = 0; |
| 562 |
byte2 = 0; |
| 563 |
switch(rad->encdec.state) |
| 564 |
{ |
| 565 |
case 0: |
| 566 |
for(i = 0; i < rad->nchans; i++) |
| 567 |
{ |
| 568 |
n = (unsigned)(i - rad->intcount) % rad->nchans; |
| 569 |
if (rad->encdec.req[n]) break; |
| 570 |
} |
| 571 |
if (i >= rad->nchans) return; |
| 572 |
rad->encdec.req[n] = 0; |
| 573 |
rad->encdec.dcsrx[n] = 0; |
| 574 |
rad->encdec.ctrx[n] = 0; |
| 575 |
rad->encdec.dcstx[n] = 0; |
| 576 |
rad->encdec.cttx[n] = 0; |
| 577 |
rad->encdec.myindex[n] = 0; |
| 578 |
rad->encdec.req[n] = 0; |
| 579 |
rad->encdec.chan = n; |
| 580 |
|
| 581 |
/* if something in code 0 for rx, is DCS */ |
| 582 |
if (rad->rxcode[n][0]) rad->encdec.dcsrx[n] = 1; |
| 583 |
else { /* otherwise, if something in other codes, is CT rx */ |
| 584 |
for(i = 1; i <= NUM_CODES; i++) |
| 585 |
{ |
| 586 |
if (rad->rxcode[n][1]) rad->encdec.ctrx[n] = 1; |
| 587 |
} |
| 588 |
} |
| 589 |
/* get index for tx code. Will be 0 if not receiving a CT */ |
| 590 |
rad->encdec.myindex[n] = 0; |
| 591 |
if (rad->gotrx[n] && rad->encdec.ctrx[n] && (rad->present_code[n])) |
| 592 |
rad->encdec.myindex[n] = rad->present_code[n]; |
| 593 |
/* get actual tx code from array */ |
| 594 |
rad->encdec.txcode[n] = rad->txcode[n][rad->encdec.myindex[n]]; |
| 595 |
if (rad->encdec.txcode[n] & 0x8000) rad->encdec.dcstx[n] = 1; |
| 596 |
else if (rad->encdec.txcode[n]) rad->encdec.cttx[n] = 1; |
| 597 |
if (rad->radmode[n] & RADMODE_NOENCODE) |
| 598 |
rad->encdec.dcstx[n] = rad->encdec.cttx[n] = 0; |
| 599 |
if ((!rad->gottx[n]) || rad->bursttimer[n]) |
| 600 |
rad->encdec.dcstx[n] = rad->encdec.cttx[n] = 0; |
| 601 |
rad->encdec.saudio_ctrl[n] = 0; |
| 602 |
rad->encdec.saudio_setup[n] = 0; |
| 603 |
rad->encdec.state = 1; |
| 604 |
break; |
| 605 |
case 1: |
| 606 |
if (rad->encdec.dcstx[rad->encdec.chan] && (!rad->encdec.dcsrx[rad->encdec.chan])) /* if to transmit DCS */ |
| 607 |
{ |
| 608 |
rad->encdec.saudio_setup[rad->encdec.chan] |= 3; |
| 609 |
rad->encdec.saudio_ctrl[rad->encdec.chan] |= 0x80; |
| 610 |
byte1 = dcstable[rad->encdec.txcode[rad->encdec.chan] & 0x7fff].b1; |
| 611 |
mx828_command(rad,rad->encdec.chan, MX828_DCS1, &byte1, &byte2 ); |
| 612 |
rad->encdec.state = 2; |
| 613 |
break; |
| 614 |
} |
| 615 |
rad->encdec.state = 4; |
| 616 |
break; |
| 617 |
case 2: |
| 618 |
byte1 = dcstable[rad->encdec.txcode[rad->encdec.chan] & 0x7fff].b2; |
| 619 |
mx828_command(rad,rad->encdec.chan, MX828_DCS2, &byte1, &byte2 ); |
| 620 |
rad->encdec.state = 3; |
| 621 |
break; |
| 622 |
case 3: |
| 623 |
byte1 = dcstable[rad->encdec.txcode[rad->encdec.chan] & 0x7fff].b3; |
| 624 |
mx828_command(rad,rad->encdec.chan, MX828_DCS3, &byte1, &byte2 ); |
| 625 |
rad->encdec.state = 4; |
| 626 |
break; |
| 627 |
case 4: |
| 628 |
if (rad->encdec.cttx[rad->encdec.chan]) |
| 629 |
{ |
| 630 |
rad->encdec.saudio_ctrl[rad->encdec.chan] |= 0x80; |
| 631 |
byte1 = cttable_tx[rad->encdec.txcode[rad->encdec.chan]].b1; |
| 632 |
byte2 = cttable_tx[rad->encdec.txcode[rad->encdec.chan]].b2; |
| 633 |
mx828_command(rad,rad->encdec.chan, MX828_TX_TONE, &byte1, &byte2 ); |
| 634 |
} |
| 635 |
rad->encdec.state = 5; |
| 636 |
break; |
| 637 |
case 5: |
| 638 |
if (rad->encdec.dcsrx[rad->encdec.chan]) |
| 639 |
{ |
| 640 |
rad->encdec.saudio_setup[rad->encdec.chan] |= 1; |
| 641 |
rad->encdec.saudio_ctrl[rad->encdec.chan] |= 0x41; |
| 642 |
byte1 = dcstable[rad->rxcode[rad->encdec.chan][0]].b1; |
| 643 |
mx828_command(rad,rad->encdec.chan, MX828_DCS1, &byte1, &byte2 ); |
| 644 |
rad->encdec.state = 6; |
| 645 |
break; |
| 646 |
} |
| 647 |
rad->encdec.state = 8; |
| 648 |
break; |
| 649 |
case 6: |
| 650 |
byte1 = dcstable[rad->rxcode[rad->encdec.chan][0]].b2; |
| 651 |
mx828_command(rad,rad->encdec.chan, MX828_DCS2, &byte1, &byte2 ); |
| 652 |
rad->encdec.state = 7; |
| 653 |
break; |
| 654 |
case 7: |
| 655 |
byte1 = dcstable[rad->rxcode[rad->encdec.chan][0]].b3; |
| 656 |
mx828_command(rad,rad->encdec.chan, MX828_DCS3, &byte1, &byte2 ); |
| 657 |
rad->encdec.state = 8; |
| 658 |
break; |
| 659 |
case 8: |
| 660 |
if (rad->encdec.ctrx[rad->encdec.chan]) |
| 661 |
{ |
| 662 |
rad->encdec.saudio_setup[rad->encdec.chan] |= 0x80; |
| 663 |
rad->encdec.saudio_ctrl[rad->encdec.chan] |= 0x60; |
| 664 |
} |
| 665 |
byte1 = rad->encdec.saudio_setup[rad->encdec.chan]; |
| 666 |
mx828_command(rad,rad->encdec.chan, MX828_SAUDIO_SETUP, &byte1, &byte2 ); |
| 667 |
rad->encdec.state = 9; |
| 668 |
break; |
| 669 |
case 9: |
| 670 |
byte1 = rad->encdec.saudio_ctrl[rad->encdec.chan]; |
| 671 |
mx828_command(rad,rad->encdec.chan, MX828_SAUDIO_CTRL, &byte1, &byte2 ); |
| 672 |
rad->encdec.state = 10; |
| 673 |
break; |
| 674 |
case 10: |
| 675 |
rad->encdec.chan = 0; |
| 676 |
rad->encdec.state = 0; |
| 677 |
break; |
| 678 |
} |
| 679 |
} |
| 680 |
|
| 681 |
static inline void pciradio_transmitprep(struct pciradio *rad, unsigned char ints) |
| 682 |
{ |
| 683 |
volatile unsigned int *writechunk; |
| 684 |
int x; |
| 685 |
if (ints & 0x01) |
| 686 |
/* Write is at interrupt address. Start writing from normal offset */ |
| 687 |
writechunk = rad->writechunk; |
| 688 |
else |
| 689 |
writechunk = rad->writechunk + DAHDI_CHUNKSIZE; |
| 690 |
|
| 691 |
/* Calculate Transmission */ |
| 692 |
dahdi_transmit(&rad->span); |
| 693 |
|
| 694 |
for (x=0;x<DAHDI_CHUNKSIZE;x++) { |
| 695 |
/* Send a sample, as a 32-bit word */ |
| 696 |
writechunk[x] = 0; |
| 697 |
writechunk[x] |= (rad->chans[0].writechunk[x] << 24); |
| 698 |
writechunk[x] |= (rad->chans[1].writechunk[x] << 16); |
| 699 |
writechunk[x] |= (rad->chans[2].writechunk[x] << 8); |
| 700 |
writechunk[x] |= (rad->chans[3].writechunk[x]); |
| 701 |
} |
| 702 |
} |
| 703 |
|
| 704 |
static inline void pciradio_receiveprep(struct pciradio *rad, unsigned char ints) |
| 705 |
{ |
| 706 |
volatile unsigned int *readchunk; |
| 707 |
int x; |
| 708 |
|
| 709 |
if (ints & 0x08) |
| 710 |
readchunk = rad->readchunk + DAHDI_CHUNKSIZE; |
| 711 |
else |
| 712 |
/* Read is at interrupt address. Valid data is available at normal offset */ |
| 713 |
readchunk = rad->readchunk; |
| 714 |
for (x=0;x<DAHDI_CHUNKSIZE;x++) { |
| 715 |
rad->chans[0].readchunk[x] = (readchunk[x] >> 24) & 0xff; |
| 716 |
rad->chans[1].readchunk[x] = (readchunk[x] >> 16) & 0xff; |
| 717 |
rad->chans[2].readchunk[x] = (readchunk[x] >> 8) & 0xff; |
| 718 |
rad->chans[3].readchunk[x] = (readchunk[x]) & 0xff; |
| 719 |
} |
| 720 |
for (x=0;x<rad->nchans;x++) { |
| 721 |
dahdi_ec_chunk(&rad->chans[x], rad->chans[x].readchunk, rad->chans[x].writechunk); |
| 722 |
} |
| 723 |
dahdi_receive(&rad->span); |
| 724 |
} |
| 725 |
|
| 726 |
static void pciradio_stop_dma(struct pciradio *rad); |
| 727 |
static void pciradio_reset_serial(struct pciradio *rad); |
| 728 |
static void pciradio_restart_dma(struct pciradio *rad); |
| 729 |
|
| 730 |
#ifdef LEAVE_THIS_COMMENTED_OUT |
| 731 |
static irqreturn_t pciradio_interrupt(int irq, void *dev_id, struct pt_regs *regs) |
| 732 |
#endif |
| 733 |
|
| 734 |
DAHDI_IRQ_HANDLER(pciradio_interrupt) |
| 735 |
{ |
| 736 |
struct pciradio *rad = dev_id; |
| 737 |
unsigned char ints,byte1,byte2,gotcor,gotctcss,gotslowctcss,ctcss; |
| 738 |
int i,x,gotrx; |
| 739 |
|
| 740 |
ints = inb(rad->ioaddr + RAD_INTSTAT); |
| 741 |
outb(ints, rad->ioaddr + RAD_INTSTAT); |
| 742 |
|
| 743 |
if (!ints) |
| 744 |
return IRQ_NONE; |
| 745 |
|
| 746 |
if (ints & 0x10) { |
| 747 |
/* Stop DMA, wait for watchdog */ |
| 748 |
printk(KERN_INFO "RADIO PCI Master abort\n"); |
| 749 |
pciradio_stop_dma(rad); |
| 750 |
return IRQ_RETVAL(1); |
| 751 |
} |
| 752 |
|
| 753 |
if (ints & 0x20) { |
| 754 |
printk(KERN_INFO "RADIO PCI Target abort\n"); |
| 755 |
return IRQ_RETVAL(1); |
| 756 |
} |
| 757 |
|
| 758 |
if (ints & 0x0f) { |
| 759 |
|
| 760 |
rad->intcount++; |
| 761 |
x = rad->intcount % rad->nchans; |
| 762 |
/* freeze */ |
| 763 |
__pciradio_setcreg(rad,0,rad->mx828_addr | 4); |
| 764 |
/* read SAUDIO_STATUS for the proper channel */ |
| 765 |
byte1 = rad->saudio_status[x] = __pciradio_getcreg(rad,x); |
| 766 |
/* thaw */ |
| 767 |
__pciradio_setcreg(rad,0,rad->mx828_addr); |
| 768 |
/* get COR input */ |
| 769 |
byte2 = __pciradio_getcreg(rad,9); |
| 770 |
/* get bit for this channel */ |
| 771 |
gotcor = byte2 & (1 << x); |
| 772 |
if (rad->radmode[x] & RADMODE_INVERTCOR) gotcor = !gotcor; |
| 773 |
rad->gotcor[x] = gotcor; |
| 774 |
if (rad->radmode[x] & RADMODE_IGNORECOR) gotcor = 1; |
| 775 |
gotslowctcss = 0; |
| 776 |
if ((byte1 & RAD_CTCSSVALID) && |
| 777 |
((byte1 & RAD_CTCSSMASK) != RAD_CTCSSOTHER)) gotslowctcss = 1; |
| 778 |
gotctcss = 1; |
| 779 |
ctcss = 0; |
| 780 |
/* set ctcss to 1 if decoding ctcss */ |
| 781 |
if (!rad->rxcode[x][0]) |
| 782 |
{ |
| 783 |
for(i = 1; i <= NUM_CODES; i++) |
| 784 |
{ |
| 785 |
if (rad->rxcode[x][i]) |
| 786 |
{ |
| 787 |
ctcss = 1; |
| 788 |
break; |
| 789 |
} |
| 790 |
} |
| 791 |
} |
| 792 |
if (ctcss) |
| 793 |
{ |
| 794 |
if ((!(byte1 & 0x40)) || |
| 795 |
((!rad->gotrx[x]) && (!gotslowctcss))) gotctcss = 0; |
| 796 |
} |
| 797 |
rad->present_code[x] = 0; |
| 798 |
if (rad->rxcode[x][0]) |
| 799 |
{ |
| 800 |
if (byte1 & 0x80) gotctcss = gotslowctcss = 1; else gotctcss = 0; |
| 801 |
} else if (gotslowctcss) rad->present_code[x] = (byte1 & RAD_CTCSSMASK) + 1; |
| 802 |
if (rad->radmode[x] & RADMODE_EXTTONE) |
| 803 |
{ |
| 804 |
unsigned mask = 1 << (x + 4); /* they're on the UIOB's */ |
| 805 |
unsigned char byteuio; |
| 806 |
|
| 807 |
/* set UIOB as input */ |
| 808 |
byteuio = __pciradio_getcreg(rad,0xe); |
| 809 |
byteuio |= mask; |
| 810 |
__pciradio_setcreg(rad,0xe,byteuio); |
| 811 |
/* get UIO input */ |
| 812 |
byteuio = __pciradio_getcreg(rad,8); |
| 813 |
if (rad->radmode[x] & RADMODE_EXTINVERT) |
| 814 |
gotctcss = gotslowctcss = ((byteuio & mask) == 0); |
| 815 |
else |
| 816 |
gotctcss = gotslowctcss = ((byteuio & mask) != 0); |
| 817 |
} |
| 818 |
rad->gotct[x] = gotslowctcss; |
| 819 |
if ((rad->radmode[x] & RADMODE_IGNORECT) || |
| 820 |
((!(rad->radmode[x] & RADMODE_EXTTONE)) && (!ctcss))) |
| 821 |
{ |
| 822 |
gotctcss = 1; |
| 823 |
gotslowctcss = 1; |
| 824 |
rad->present_code[x] = 0; |
| 825 |
} |
| 826 |
if(rad->newctcssstate[x] != gotctcss){ |
| 827 |
rad->newctcssstate[x] = gotctcss; |
| 828 |
if(rad->newctcssstate[x]) |
| 829 |
rad->ctcsstimer[x]=rad->ctcssacquiretime[x]; |
| 830 |
else |
| 831 |
rad->ctcsstimer[x]=rad->ctcsstalkofftime[x]; |
| 832 |
} |
| 833 |
else{ |
| 834 |
if(!rad->ctcsstimer[x]) |
| 835 |
rad->ctcssstate[x] = rad->newctcssstate[x]; |
| 836 |
else |
| 837 |
rad->ctcsstimer[x]--; |
| 838 |
} |
| 839 |
gotrx = gotcor && rad->ctcssstate[x]; |
| 840 |
if (gotrx != rad->gotrx[x]) |
| 841 |
{ |
| 842 |
rad->gotrxtimer[x] = rad->debouncetime[x]; |
| 843 |
} |
| 844 |
rad->gotrx[x] = gotrx; |
| 845 |
if (rad->present_code[x] != rad->last_code[x]) |
| 846 |
{ |
| 847 |
rad->encdec.req[x] = 1; |
| 848 |
rad->last_code[x] = rad->present_code[x]; |
| 849 |
} |
| 850 |
_do_encdec(rad); |
| 851 |
for(x = 0; x < rad->nchans; x++) |
| 852 |
{ |
| 853 |
unsigned char mask = 1 << x; |
| 854 |
|
| 855 |
if (rad->gottx[x] != rad->lasttx[x]) |
| 856 |
{ |
| 857 |
if (rad->gottx[x]) |
| 858 |
{ |
| 859 |
rad->bursttimer[x] = 0; |
| 860 |
rad->pasave |= mask; |
| 861 |
__pciradio_setcreg(rad, 0xa, rad->pasave); |
| 862 |
} |
| 863 |
else |
| 864 |
{ |
| 865 |
if (!rad->bursttime[x]) |
| 866 |
{ |
| 867 |
rad->pasave &= ~mask; |
| 868 |
__pciradio_setcreg(rad, 0xa, rad->pasave); |
| 869 |
} |
| 870 |
else |
| 871 |
{ |
| 872 |
rad->bursttimer[x] = rad->bursttime[x]; |
| 873 |
} |
| 874 |
} |
| 875 |
rad->encdec.req[x] = 1; |
| 876 |
rad->lasttx[x] = rad->gottx[x]; |
| 877 |
} |
| 878 |
if (rad->bursttimer[x]) |
| 879 |
{ |
| 880 |
/* if just getting to zero */ |
| 881 |
if (!(--rad->bursttimer[x])) |
| 882 |
{ |
| 883 |
rad->pasave &= ~mask; |
| 884 |
__pciradio_setcreg(rad, 0xa, rad->pasave); |
| 885 |
} |
| 886 |
} |
| 887 |
|
| 888 |
/* if timer active */ |
| 889 |
if (rad->gotrxtimer[x]) |
| 890 |
{ |
| 891 |
/* if just getting to zero */ |
| 892 |
if (!(--rad->gotrxtimer[x])) |
| 893 |
{ |
| 894 |
mask = 1 << (x + 4); |
| 895 |
rad->pasave &= ~mask; |
| 896 |
if (gotctcss) rad->pasave |= mask; |
| 897 |
__pciradio_setcreg(rad, 0xa, rad->pasave); |
| 898 |
|
| 899 |
if (rad->gotrx[x] != rad->gotrx1[x]) |
| 900 |
{ |
| 901 |
if (rad->gotrx[x]) { |
| 902 |
if (debug) |
| 903 |
{ |
| 904 |
if (rad->present_code[x]) |
| 905 |
printk(KERN_DEBUG "Chan %d got rx (ctcss code %d)\n",x + 1, |
| 906 |
cttable_rx[rad->rxcode[x][rad->present_code[x]]].code); |
| 907 |
else |
| 908 |
printk(KERN_DEBUG "Chan %d got rx\n",x + 1); |
| 909 |
} |
| 910 |
dahdi_hooksig(&rad->chans[x],DAHDI_RXSIG_OFFHOOK); |
| 911 |
} else { |
| 912 |
if (debug) printk(KERN_DEBUG "Chan %d lost rx\n",x + 1); |
| 913 |
dahdi_hooksig(&rad->chans[x],DAHDI_RXSIG_ONHOOK); |
| 914 |
} |
| 915 |
rad->encdec.req[x] = 1; |
| 916 |
} |
| 917 |
rad->gotrx1[x] = rad->gotrx[x]; |
| 918 |
} |
| 919 |
} |
| 920 |
} |
| 921 |
/* process serial if any */ |
| 922 |
/* send byte if there is one in buffer to send */ |
| 923 |
if (rad->txlen && (rad->txlen != rad->txindex)) |
| 924 |
{ |
| 925 |
/* if tx not busy */ |
| 926 |
if (!(__pciradio_getcreg(rad,9) & 0x80)) |
| 927 |
{ |
| 928 |
__pciradio_setcreg(rad, 4, rad->txbuf[rad->txindex++]); |
| 929 |
} |
| 930 |
} |
| 931 |
rad->srxtimer++; |
| 932 |
/* if something in rx to read */ |
| 933 |
while(__pciradio_getcreg(rad,9) & 0x10) |
| 934 |
{ |
| 935 |
unsigned char c = __pciradio_getcreg(rad,4); |
| 936 |
rad->srxtimer = 0; |
| 937 |
if (rad->rxindex < RAD_SERIAL_BUFLEN) |
| 938 |
{ |
| 939 |
rad->rxbuf[rad->rxindex++] = c; |
| 940 |
} |
| 941 |
udelay(1); |
| 942 |
} |
| 943 |
pciradio_receiveprep(rad, ints); |
| 944 |
pciradio_transmitprep(rad, ints); |
| 945 |
i = 0; |
| 946 |
for(x = 0; x < 4; x++) |
| 947 |
{ |
| 948 |
if (rad->gottx[x]) i |= (1 << (x * 2)); |
| 949 |
if (rad->gotrx[x]) i |= (2 << (x * 2)); |
| 950 |
} |
| 951 |
/* output LED's */ |
| 952 |
__pciradio_setcreg(rad, 9, i); |
| 953 |
} |
| 954 |
|
| 955 |
return IRQ_RETVAL(1); |
| 956 |
} |
| 957 |
|
| 958 |
static int pciradio_ioctl(struct dahdi_chan *chan, unsigned int cmd, unsigned long data) |
| 959 |
{ |
| 960 |
int i,mycode; |
| 961 |
unsigned long flags; |
| 962 |
unsigned char byte1,byte2,mask; |
| 963 |
union { |
| 964 |
struct dahdi_radio_stat s; |
| 965 |
struct dahdi_radio_param p; |
| 966 |
} stack; |
| 967 |
|
| 968 |
struct pciradio *rad = chan->pvt; |
| 969 |
|
| 970 |
switch (cmd) { |
| 971 |
case DAHDI_RADIO_GETPARAM: |
| 972 |
if (copy_from_user(&stack.p, (__user void *) data, sizeof(stack.p))) return -EFAULT; |
| 973 |
spin_lock_irqsave(&rad->lock,flags); |
| 974 |
stack.p.data = 0; /* start with 0 value in output */ |
| 975 |
switch(stack.p.radpar) { |
| 976 |
case DAHDI_RADPAR_INVERTCOR: |
| 977 |
if (rad->radmode[chan->chanpos - 1] & RADMODE_INVERTCOR) |
| 978 |
stack.p.data = 1; |
| 979 |
break; |
| 980 |
case DAHDI_RADPAR_IGNORECOR: |
| 981 |
if (rad->radmode[chan->chanpos - 1] & RADMODE_IGNORECOR) |
| 982 |
stack.p.data = 1; |
| 983 |
break; |
| 984 |
case DAHDI_RADPAR_IGNORECT: |
| 985 |
if (rad->radmode[chan->chanpos - 1] & RADMODE_IGNORECT) |
| 986 |
stack.p.data = 1; |
| 987 |
break; |
| 988 |
case DAHDI_RADPAR_NOENCODE: |
| 989 |
if (rad->radmode[chan->chanpos - 1] & RADMODE_NOENCODE) |
| 990 |
stack.p.data = 1; |
| 991 |
break; |
| 992 |
case DAHDI_RADPAR_CORTHRESH: |
| 993 |
stack.p.data = rad->corthresh[chan->chanpos - 1] & 7; |
| 994 |
break; |
| 995 |
case DAHDI_RADPAR_EXTRXTONE: |
| 996 |
if (rad->radmode[chan->chanpos - 1] & RADMODE_EXTTONE) |
| 997 |
{ |
| 998 |
stack.p.data = 1; |
| 999 |
if (rad->radmode[chan->chanpos - 1] & RADMODE_EXTINVERT) |
| 1000 |
{ |
| 1001 |
stack.p.data = 2; |
| 1002 |
} |
| 1003 |
} |
| 1004 |
break; |
| 1005 |
case DAHDI_RADPAR_NUMTONES: |
| 1006 |
stack.p.data = NUM_CODES; |
| 1007 |
break; |
| 1008 |
case DAHDI_RADPAR_RXTONE: |
| 1009 |
if ((stack.p.index < 1) || (stack.p.index > NUM_CODES)) { |
| 1010 |
spin_unlock_irqrestore(&rad->lock,flags); |
| 1011 |
return -EINVAL; |
| 1012 |
} |
| 1013 |
stack.p.data = |
| 1014 |
cttable_rx[rad->rxcode[chan->chanpos - 1][stack.p.index] & 0x7fff].code; |
| 1015 |
break; |
| 1016 |
case DAHDI_RADPAR_RXTONECLASS: |
| 1017 |
if ((stack.p.index < 1) || (stack.p.index > NUM_CODES)) { |
| 1018 |
spin_unlock_irqrestore(&rad->lock,flags); |
| 1019 |
return -EINVAL; |
| 1020 |
} |
| 1021 |
stack.p.data = rad->rxclass[chan->chanpos - 1][stack.p.index] & 0xffff; |
| 1022 |
break; |
| 1023 |
case DAHDI_RADPAR_TXTONE: |
| 1024 |
if (stack.p.index > NUM_CODES) { |
| 1025 |
spin_unlock_irqrestore(&rad->lock,flags); |
| 1026 |
return -EINVAL; |
| 1027 |
} |
| 1028 |
stack.p.data = cttable_tx[rad->txcode[chan->chanpos - 1][stack.p.index] & 0x7fff].code; |
| 1029 |
/* if a DCS tone, return as such */ |
| 1030 |
if (rad->txcode[chan->chanpos - 1][stack.p.index] & 0x8000) |
| 1031 |
stack.p.data |= 0x8000; |
| 1032 |
break; |
| 1033 |
case DAHDI_RADPAR_DEBOUNCETIME: |
| 1034 |
stack.p.data = rad->debouncetime[chan->chanpos - 1]; |
| 1035 |
break; |
| 1036 |
|
| 1037 |
case DAHDI_RADPAR_CTCSSACQUIRETIME: |
| 1038 |
stack.p.data = rad->ctcssacquiretime[chan->chanpos - 1]; |
| 1039 |
break; |
| 1040 |
|
| 1041 |
case DAHDI_RADPAR_CTCSSTALKOFFTIME: |
| 1042 |
stack.p.data = rad->ctcsstalkofftime[chan->chanpos - 1]; |
| 1043 |
break; |
| 1044 |
|
| 1045 |
case DAHDI_RADPAR_BURSTTIME: |
| 1046 |
stack.p.data = rad->bursttime[chan->chanpos - 1]; |
| 1047 |
break; |
| 1048 |
case DAHDI_RADPAR_UIODATA: |
| 1049 |
stack.p.data = 0; |
| 1050 |
byte1 = __pciradio_getcreg(rad,8); |
| 1051 |
if (byte1 & (1 << (chan->chanpos - 1))) stack.p.data |= 1; |
| 1052 |
if (byte1 & (1 << (chan->chanpos + 3))) stack.p.data |= 2; |
| 1053 |
break; |
| 1054 |
case DAHDI_RADPAR_UIOMODE: |
| 1055 |
stack.p.data = 0; |
| 1056 |
byte1 = __pciradio_getcreg(rad,0xe); |
| 1057 |
if (byte1 & (1 << (chan->chanpos - 1))) stack.p.data |= 1; |
| 1058 |
if (byte1 & (1 << (chan->chanpos + 3))) stack.p.data |= 2; |
| 1059 |
break; |
| 1060 |
case DAHDI_RADPAR_REMMODE: |
| 1061 |
stack.p.data = rad->remmode[chan->chanpos - 1]; |
| 1062 |
break; |
| 1063 |
default: |
| 1064 |
spin_unlock_irqrestore(&rad->lock,flags); |
| 1065 |
return -EINVAL; |
| 1066 |
} |
| 1067 |
spin_unlock_irqrestore(&rad->lock,flags); |
| 1068 |
if (copy_to_user((__user void *) data, &stack.p, sizeof(stack.p))) return -EFAULT; |
| 1069 |
break; |
| 1070 |
case DAHDI_RADIO_SETPARAM: |
| 1071 |
if (copy_from_user(&stack.p, (__user void *) data, sizeof(stack.p))) return -EFAULT; |
| 1072 |
spin_lock_irqsave(&rad->lock,flags); |
| 1073 |
switch(stack.p.radpar) { |
| 1074 |
case DAHDI_RADPAR_INVERTCOR: |
| 1075 |
if (stack.p.data) |
| 1076 |
rad->radmode[chan->chanpos - 1] |= RADMODE_INVERTCOR; |
| 1077 |
else |
| 1078 |
rad->radmode[chan->chanpos - 1] &= ~RADMODE_INVERTCOR; |
| 1079 |
break; |
| 1080 |
case DAHDI_RADPAR_IGNORECOR: |
| 1081 |
if (stack.p.data) |
| 1082 |
rad->radmode[chan->chanpos - 1] |= RADMODE_IGNORECOR; |
| 1083 |
else |
| 1084 |
rad->radmode[chan->chanpos - 1] &= ~RADMODE_IGNORECOR; |
| 1085 |
break; |
| 1086 |
case DAHDI_RADPAR_IGNORECT: |
| 1087 |
if (stack.p.data) |
| 1088 |
rad->radmode[chan->chanpos - 1] |= RADMODE_IGNORECT; |
| 1089 |
else |
| 1090 |
rad->radmode[chan->chanpos - 1] &= ~RADMODE_IGNORECT; |
| 1091 |
break; |
| 1092 |
case DAHDI_RADPAR_NOENCODE: |
| 1093 |
if (stack.p.data) |
| 1094 |
rad->radmode[chan->chanpos - 1] |= RADMODE_NOENCODE; |
| 1095 |
else |
| 1096 |
rad->radmode[chan->chanpos - 1] &= ~RADMODE_NOENCODE; |
| 1097 |
break; |
| 1098 |
case DAHDI_RADPAR_CORTHRESH: |
| 1099 |
if ((stack.p.data < 0) || (stack.p.data > 7)) { |
| 1100 |
spin_unlock_irqrestore(&rad->lock,flags); |
| 1101 |
return -EINVAL; |
| 1102 |
} |
| 1103 |
rad->corthresh[chan->chanpos - 1] = stack.p.data; |
| 1104 |
byte1 = 0xc0 | (rad->corthresh[chan->chanpos - 1] << 2); |
| 1105 |
spin_unlock_irqrestore(&rad->lock,flags); |
| 1106 |
mx828_command_wait(rad,chan->chanpos - 1, MX828_GEN_CTRL, &byte1, &byte2); |
| 1107 |
spin_lock_irqsave(&rad->lock,flags); |
| 1108 |
break; |
| 1109 |
case DAHDI_RADPAR_EXTRXTONE: |
| 1110 |
if (stack.p.data) |
| 1111 |
rad->radmode[chan->chanpos - 1] |= RADMODE_EXTTONE; |
| 1112 |
else |
| 1113 |
rad->radmode[chan->chanpos - 1] &= ~RADMODE_EXTTONE; |
| 1114 |
if (stack.p.data > 1) |
| 1115 |
rad->radmode[chan->chanpos - 1] |= RADMODE_EXTINVERT; |
| 1116 |
else |
| 1117 |
rad->radmode[chan->chanpos - 1] &= ~RADMODE_EXTINVERT; |
| 1118 |
break; |
| 1119 |
case DAHDI_RADPAR_INITTONE: |
| 1120 |
for(i = 0; i <= NUM_CODES; i++) |
| 1121 |
{ |
| 1122 |
rad->rxcode[chan->chanpos - 1][i] = 0; |
| 1123 |
rad->rxclass[chan->chanpos - 1][i] = 0; |
| 1124 |
rad->txcode[chan->chanpos - 1][i] = 0; |
| 1125 |
} |
| 1126 |
spin_unlock_irqrestore(&rad->lock,flags); |
| 1127 |
for(i = 0; i < NUM_CODES; i++) |
| 1128 |
{ |
| 1129 |
/* set to no encode/decode */ |
| 1130 |
byte1 = 0; |
| 1131 |
mx828_command_wait(rad,chan->chanpos - 1, MX828_SAUDIO_CTRL, &byte1, &byte2 ); |
| 1132 |
/* set rx tone to none */ |
| 1133 |
byte1 = i << 4; |
| 1134 |
byte2 = 0; |
| 1135 |
mx828_command_wait(rad,chan->chanpos - 1, MX828_RX_TONE, &byte1, &byte2 ); |
| 1136 |
} |
| 1137 |
spin_lock_irqsave(&rad->lock,flags); |
| 1138 |
break; |
| 1139 |
case DAHDI_RADPAR_RXTONE: |
| 1140 |
if (!stack.p.index) /* if RX DCS mode */ |
| 1141 |
{ |
| 1142 |
if ((stack.p.data < 0) || (stack.p.data > 777)) { |
| 1143 |
spin_unlock_irqrestore(&rad->lock,flags); |
| 1144 |
return -EINVAL; |
| 1145 |
} |
| 1146 |
mycode = getdcstone(stack.p.data); |
| 1147 |
if (mycode < 0) { |
| 1148 |
spin_unlock_irqrestore(&rad->lock,flags); |
| 1149 |
return -EINVAL; |
| 1150 |
} |
| 1151 |
rad->rxcode[chan->chanpos - 1][0] = mycode; |
| 1152 |
rad->encdec.req[chan->chanpos - 1] = 1; |
| 1153 |
break; |
| 1154 |
} |
| 1155 |
if ((stack.p.index < 1) || (stack.p.index > NUM_CODES)) { |
| 1156 |
spin_unlock_irqrestore(&rad->lock,flags); |
| 1157 |
return -EINVAL; |
| 1158 |
} |
| 1159 |
mycode = getrxtone(stack.p.data); |
| 1160 |
if (mycode < 0) { |
| 1161 |
spin_unlock_irqrestore(&rad->lock,flags); |
| 1162 |
return -EINVAL; |
| 1163 |
} |
| 1164 |
rad->rxcode[chan->chanpos - 1][stack.p.index] = mycode; |
| 1165 |
byte1 = cttable_rx[mycode].b1 | ((stack.p.index - 1) << 4); |
| 1166 |
byte2 = cttable_rx[mycode].b2; |
| 1167 |
spin_unlock_irqrestore(&rad->lock,flags); |
| 1168 |
mx828_command_wait(rad,chan->chanpos - 1, MX828_RX_TONE, &byte1, &byte2 ); |
| 1169 |
spin_lock_irqsave(&rad->lock,flags); |
| 1170 |
/* zot out DCS one if there */ |
| 1171 |
rad->rxcode[chan->chanpos - 1][0] = 0; |
| 1172 |
rad->encdec.req[chan->chanpos - 1] = 1; |
| 1173 |
break; |
| 1174 |
case DAHDI_RADPAR_RXTONECLASS: |
| 1175 |
if ((stack.p.index < 1) || (stack.p.index > NUM_CODES)) { |
| 1176 |
spin_unlock_irqrestore(&rad->lock,flags); |
| 1177 |
return -EINVAL; |
| 1178 |
} |
| 1179 |
rad->rxclass[chan->chanpos - 1][stack.p.index] = stack.p.data & 0xffff; |
| 1180 |
break; |
| 1181 |
case DAHDI_RADPAR_TXTONE: |
| 1182 |
if (stack.p.index > NUM_CODES) { |
| 1183 |
spin_unlock_irqrestore(&rad->lock,flags); |
| 1184 |
return -EINVAL; |
| 1185 |
} |
| 1186 |
if (stack.p.data & 0x8000) /* if dcs */ |
| 1187 |
mycode = getdcstone(stack.p.data & 0x7fff); |
| 1188 |
else |
| 1189 |
mycode = gettxtone(stack.p.data); |
| 1190 |
if (mycode < 0) { |
| 1191 |
spin_unlock_irqrestore(&rad->lock,flags); |
| 1192 |
return -EINVAL; |
| 1193 |
} |
| 1194 |
if (stack.p.data & 0x8000) mycode |= 0x8000; |
| 1195 |
rad->txcode[chan->chanpos - 1][stack.p.index] = mycode; |
| 1196 |
rad->encdec.req[chan->chanpos - 1] = 1; |
| 1197 |
break; |
| 1198 |
case DAHDI_RADPAR_DEBOUNCETIME: |
| 1199 |
rad->debouncetime[chan->chanpos - 1] = stack.p.data; |
| 1200 |
break; |
| 1201 |
|
| 1202 |
case DAHDI_RADPAR_CTCSSACQUIRETIME: |
| 1203 |
rad->ctcssacquiretime[chan->chanpos - 1] = stack.p.data; |
| 1204 |
break; |
| 1205 |
|
| 1206 |
case DAHDI_RADPAR_CTCSSTALKOFFTIME: |
| 1207 |
rad->ctcsstalkofftime[chan->chanpos - 1] = stack.p.data; |
| 1208 |
break; |
| 1209 |
|
| 1210 |
case DAHDI_RADPAR_BURSTTIME: |
| 1211 |
rad->bursttime[chan->chanpos - 1] = stack.p.data; |
| 1212 |
break; |
| 1213 |
case DAHDI_RADPAR_UIODATA: |
| 1214 |
byte1 = __pciradio_getcreg(rad,8); |
| 1215 |
byte1 &= ~(1 << (chan->chanpos - 1)); |
| 1216 |
byte1 &= ~(1 << (chan->chanpos + 3)); |
| 1217 |
if (stack.p.data & 1) byte1 |= (1 << (chan->chanpos - 1)); |
| 1218 |
if (stack.p.data & 2) byte1 |= (1 << (chan->chanpos + 3)); |
| 1219 |
__pciradio_setcreg(rad,8,byte1); |
| 1220 |
break; |
| 1221 |
case DAHDI_RADPAR_UIOMODE: |
| 1222 |
byte1 = __pciradio_getcreg(rad,0xe); |
| 1223 |
byte1 &= ~(1 << (chan->chanpos - 1)); |
| 1224 |
byte1 &= ~(1 << (chan->chanpos + 3)); |
| 1225 |
if (stack.p.data & 1) byte1 |= (1 << (chan->chanpos - 1)); |
| 1226 |
if (stack.p.data & 2) byte1 |= (1 << (chan->chanpos + 3)); |
| 1227 |
__pciradio_setcreg(rad,0xe,byte1); |
| 1228 |
break; |
| 1229 |
case DAHDI_RADPAR_REMMODE: |
| 1230 |
rad->remmode[chan->chanpos - 1] = stack.p.data; |
| 1231 |
break; |
| 1232 |
case DAHDI_RADPAR_REMCOMMAND: |
| 1233 |
/* if no remote mode, return an error */ |
| 1234 |
if (rad->remmode[chan->chanpos - 1] == DAHDI_RADPAR_REM_NONE) |
| 1235 |
{ |
| 1236 |
spin_unlock_irqrestore(&rad->lock,flags); |
| 1237 |
return -EINVAL; |
| 1238 |
} |
| 1239 |
i = 0; |
| 1240 |
if (rad->remmode[chan->chanpos - 1] == DAHDI_RADPAR_REM_RBI1) |
| 1241 |
{ |
| 1242 |
/* set UIOA and UIOB for output */ |
| 1243 |
byte1 = __pciradio_getcreg(rad,0xe); |
| 1244 |
mask = (1 << (chan->chanpos - 1)) | |
| 1245 |
(1 << (chan->chanpos + 3)); |
| 1246 |
byte2 = byte1 & (~mask); |
| 1247 |
i = (byte2 != byte1); |
| 1248 |
__pciradio_setcreg(rad,0xe,byte2); |
| 1249 |
byte1 = __pciradio_getcreg(rad,8); |
| 1250 |
mask = 1 << (chan->chanpos - 1); |
| 1251 |
byte2 = byte1 | mask; |
| 1252 |
i = (byte2 != byte1); |
| 1253 |
__pciradio_setcreg(rad,8,byte2); |
| 1254 |
spin_unlock_irqrestore(&rad->lock,flags); |
| 1255 |
if (i || (jiffies < rad->lastremcmd + 10)) |
| 1256 |
msleep_interruptible(100); |
| 1257 |
rad->lastremcmd = jiffies; |
| 1258 |
rbi_out(rad,chan->chanpos - 1,(unsigned char *)&stack.p.data); |
| 1259 |
spin_lock_irqsave(&rad->lock,flags); |
| 1260 |
break; |
| 1261 |
} |
| 1262 |
spin_unlock_irqrestore(&rad->lock,flags); |
| 1263 |
for(;;) |
| 1264 |
{ |
| 1265 |
int x; |
| 1266 |
|
| 1267 |
spin_lock_irqsave(&rad->lock,flags); |
| 1268 |
x = rad->remote_locked || (__pciradio_getcreg(rad,0xc) & 2); |
| 1269 |
if (!x) rad->remote_locked = 1; |
| 1270 |
spin_unlock_irqrestore(&rad->lock,flags); |
| 1271 |
if (x) |
| 1272 |
msleep_interruptible(20); |
| 1273 |
else break; |
| 1274 |
} |
| 1275 |
spin_lock_irqsave(&rad->lock,flags); |
| 1276 |
/* set UIOA for input and UIOB for output */ |
| 1277 |
byte1 = __pciradio_getcreg(rad,0xe); |
| 1278 |
mask = 1 << (chan->chanpos + 3); /* B an output */ |
| 1279 |
byte2 = byte1 & (~mask); |
| 1280 |
byte2 |= 1 << (chan->chanpos - 1); /* A in input */ |
| 1281 |
__pciradio_setcreg(rad,0xe,byte2); |
| 1282 |
byte1 = __pciradio_getcreg(rad,8); |
| 1283 |
byte2 = byte1 | mask; |
| 1284 |
byte2 |= 1 << (chan->chanpos - 1); |
| 1285 |
byte2 |= 1 << (chan->chanpos + 3); |
| 1286 |
__pciradio_setcreg(rad,8,byte2); |
| 1287 |
spin_unlock_irqrestore(&rad->lock,flags); |
| 1288 |
if (byte1 != byte2) |
| 1289 |
msleep_interruptible(30); |
| 1290 |
while (jiffies < rad->lastremcmd + 10) |
| 1291 |
msleep_interruptible(100); |
| 1292 |
rad->lastremcmd = jiffies; |
| 1293 |
for(;;) |
| 1294 |
{ |
| 1295 |
if (!(__pciradio_getcreg(rad,0xc) & 2)) break; |
| 1296 |
msleep_interruptible(20); |
| 1297 |
} |
| 1298 |
spin_lock_irqsave(&rad->lock,flags); |
| 1299 |
/* enable and address async serializer */ |
| 1300 |
__pciradio_setcreg(rad,0xf,rad->pfsave | ((chan->chanpos - 1) << 4) | 0x80); |
| 1301 |
/* copy tx buffer */ |
| 1302 |
memcpy(rad->txbuf,stack.p.buf,stack.p.index); |
| 1303 |
rad->txlen = stack.p.index; |
| 1304 |
rad->txindex = 0; |
| 1305 |
rad->rxindex = 0; |
| 1306 |
rad->srxtimer = 0; |
| 1307 |
memset(stack.p.buf,0,SERIAL_BUFLEN); |
| 1308 |
stack.p.index = 0; |
| 1309 |
if (stack.p.data) for(;;) |
| 1310 |
{ |
| 1311 |
rad->rxbuf[rad->rxindex] = 0; |
| 1312 |
if ((rad->rxindex < stack.p.data) && |
| 1313 |
(rad->srxtimer < SRX_TIMEOUT) && |
| 1314 |
((rad->remmode[chan->chanpos - 1] == DAHDI_RADPAR_REM_SERIAL) || |
| 1315 |
(!strchr((char *)rad->rxbuf,'\r')))) |
| 1316 |
{ |
| 1317 |
spin_unlock_irqrestore(&rad->lock,flags); |
| 1318 |
msleep_interruptible(20); |
| 1319 |
spin_lock_irqsave(&rad->lock,flags); |
| 1320 |
continue; |
| 1321 |
} |
| 1322 |
memset(stack.p.buf,0,SERIAL_BUFLEN); |
| 1323 |
if (stack.p.data && (rad->rxindex > stack.p.data)) |
| 1324 |
rad->rxindex = stack.p.data; |
| 1325 |
if (rad->rxindex) |
| 1326 |
memcpy(stack.p.buf,rad->rxbuf,rad->rxindex); |
| 1327 |
stack.p.index = rad->rxindex; |
| 1328 |
break; |
| 1329 |
} |
| 1330 |
/* wait for done if in SERIAL_ASCII mode, or if no Rx aftwards */ |
| 1331 |
if ((rad->remmode[chan->chanpos - 1] == DAHDI_RADPAR_REM_SERIAL_ASCII) || |
| 1332 |
(!stack.p.data)) |
| 1333 |
{ |
| 1334 |
/* wait for TX to be done if not already */ |
| 1335 |
while(rad->txlen && (rad->txindex < rad->txlen)) |
| 1336 |
{ |
| 1337 |
spin_unlock_irqrestore(&rad->lock,flags); |
| 1338 |
msleep_interruptible(20); |
| 1339 |
spin_lock_irqsave(&rad->lock,flags); |
| 1340 |
} |
| 1341 |
/* disable and un-address async serializer */ |
| 1342 |
__pciradio_setcreg(rad,0xf,rad->pfsave); |
| 1343 |
} |
| 1344 |
rad->remote_locked = 0; |
| 1345 |
spin_unlock_irqrestore(&rad->lock,flags); |
| 1346 |
if (rad->remmode[chan->chanpos - 1] == DAHDI_RADPAR_REM_SERIAL_ASCII) |
| 1347 |
msleep_interruptible(1000); |
| 1348 |
if (copy_to_user((__user void *) data, &stack.p, sizeof(stack.p))) return -EFAULT; |
| 1349 |
return 0; |
| 1350 |
default: |
| 1351 |
spin_unlock_irqrestore(&rad->lock,flags); |
| 1352 |
return -EINVAL; |
| 1353 |
} |
| 1354 |
spin_unlock_irqrestore(&rad->lock,flags); |
| 1355 |
break; |
| 1356 |
case DAHDI_RADIO_GETSTAT: |
| 1357 |
spin_lock_irqsave(&rad->lock,flags); |
| 1358 |
/* start with clean object */ |
| 1359 |
memset(&stack.s, 0, sizeof(stack.s)); |
| 1360 |
/* if we have rx */ |
| 1361 |
if (rad->gotrx[chan->chanpos - 1]) |
| 1362 |
{ |
| 1363 |
stack.s.radstat |= DAHDI_RADSTAT_RX; |
| 1364 |
if (rad->rxcode[chan->chanpos - 1][0]) |
| 1365 |
stack.s.ctcode_rx = |
| 1366 |
dcstable[rad->rxcode[chan->chanpos - 1][0]].code | 0x8000; |
| 1367 |
else { |
| 1368 |
stack.s.ctcode_rx = |
| 1369 |
cttable_rx[rad->rxcode[chan->chanpos - 1][rad->present_code[chan->chanpos - 1]]].code; |
| 1370 |
stack.s.ctclass = |
| 1371 |
rad->rxclass[chan->chanpos - 1][rad->present_code[chan->chanpos - 1]]; |
| 1372 |
} |
| 1373 |
} |
| 1374 |
/* if we have tx */ |
| 1375 |
if (rad->gottx[chan->chanpos - 1]) |
| 1376 |
{ |
| 1377 |
unsigned short x,myindex; |
| 1378 |
|
| 1379 |
stack.s.radstat |= DAHDI_RADSTAT_TX; |
| 1380 |
stack.s.radstat |= DAHDI_RADSTAT_TX; |
| 1381 |
|
| 1382 |
myindex = 0; |
| 1383 |
if ((!rad->rxcode[chan->chanpos - 1][0]) |
| 1384 |
&& (rad->present_code[chan->chanpos - 1])) |
| 1385 |
myindex = rad->present_code[chan->chanpos - 1]; |
| 1386 |
x = rad->txcode[chan->chanpos - 1][myindex]; |
| 1387 |
if (x & 0x8000) |
| 1388 |
stack.s.ctcode_tx = dcstable[x & 0x7fff].code | 0x8000; |
| 1389 |
else |
| 1390 |
stack.s.ctcode_tx = cttable_tx[x].code; |
| 1391 |
|
| 1392 |
} |
| 1393 |
|
| 1394 |
if (rad->radmode[chan->chanpos - 1] & RADMODE_IGNORECOR) |
| 1395 |
stack.s.radstat |= DAHDI_RADSTAT_IGNCOR; |
| 1396 |
if (rad->radmode[chan->chanpos - 1] & RADMODE_IGNORECT) |
| 1397 |
stack.s.radstat |= DAHDI_RADSTAT_IGNCT; |
| 1398 |
if (rad->radmode[chan->chanpos - 1] & RADMODE_NOENCODE) |
| 1399 |
stack.s.radstat |= DAHDI_RADSTAT_NOENCODE; |
| 1400 |
if (rad->gotcor[chan->chanpos - 1]) |
| 1401 |
stack.s.radstat |= DAHDI_RADSTAT_RXCOR; |
| 1402 |
if (rad->gotct[chan->chanpos - 1]) |
| 1403 |
stack.s.radstat |= DAHDI_RADSTAT_RXCT; |
| 1404 |
spin_unlock_irqrestore(&rad->lock,flags); |
| 1405 |
if (copy_to_user((__user void *) data, &stack.s, sizeof(stack.s))) return -EFAULT; |
| 1406 |
break; |
| 1407 |
default: |
| 1408 |
return -ENOTTY; |
| 1409 |
} |
| 1410 |
return 0; |
| 1411 |
|
| 1412 |
} |
| 1413 |
|
| 1414 |
static int pciradio_open(struct dahdi_chan *chan) |
| 1415 |
{ |
| 1416 |
struct pciradio *rad = chan->pvt; |
| 1417 |
if (rad->dead) |
| 1418 |
return -ENODEV; |
| 1419 |
rad->usecount++; |
| 1420 |
return 0; |
| 1421 |
} |
| 1422 |
|
| 1423 |
static int pciradio_watchdog(struct dahdi_span *span, int event) |
| 1424 |
{ |
| 1425 |
printk(KERN_INFO "PCI RADIO: Restarting DMA\n"); |
| 1426 |
pciradio_restart_dma(container_of(span, struct pciradio, span)); |
| 1427 |
return 0; |
| 1428 |
} |
| 1429 |
|
| 1430 |
static int pciradio_close(struct dahdi_chan *chan) |
| 1431 |
{ |
| 1432 |
struct pciradio *rad = chan->pvt; |
| 1433 |
rad->usecount--; |
| 1434 |
/* If we're dead, release us now */ |
| 1435 |
if (!rad->usecount && rad->dead) |
| 1436 |
pciradio_release(rad); |
| 1437 |
return 0; |
| 1438 |
} |
| 1439 |
|
| 1440 |
static int pciradio_hooksig(struct dahdi_chan *chan, enum dahdi_txsig txsig) |
| 1441 |
{ |
| 1442 |
struct pciradio *rad = chan->pvt; |
| 1443 |
|
| 1444 |
switch(txsig) { |
| 1445 |
case DAHDI_TXSIG_START: |
| 1446 |
case DAHDI_TXSIG_OFFHOOK: |
| 1447 |
rad->gottx[chan->chanpos - 1] = 1; |
| 1448 |
break; |
| 1449 |
case DAHDI_TXSIG_ONHOOK: |
| 1450 |
rad->gottx[chan->chanpos - 1] = 0; |
| 1451 |
break; |
| 1452 |
default: |
| 1453 |
printk(KERN_DEBUG "pciradio: Can't set tx state to %d\n", txsig); |
| 1454 |
break; |
| 1455 |
} |
| 1456 |
if (debug) |
| 1457 |
printk(KERN_DEBUG "pciradio: Setting Radio hook state to %d on chan %d\n", txsig, chan->chanpos); |
| 1458 |
return 0; |
| 1459 |
} |
| 1460 |
|
| 1461 |
static const struct dahdi_span_ops pciradio_span_ops = { |
| 1462 |
.owner = THIS_MODULE, |
| 1463 |
.hooksig = pciradio_hooksig, |
| 1464 |
.open = pciradio_open, |
| 1465 |
.close = pciradio_close, |
| 1466 |
.ioctl = pciradio_ioctl, |
| 1467 |
.watchdog = pciradio_watchdog, |
| 1468 |
}; |
| 1469 |
|
| 1470 |
static int pciradio_initialize(struct pciradio *rad) |
| 1471 |
{ |
| 1472 |
int x; |
| 1473 |
|
| 1474 |
/* DAHDI stuff */ |
| 1475 |
sprintf(rad->span.name, "PCIRADIO/%d", rad->pos); |
| 1476 |
sprintf(rad->span.desc, "Board %d", rad->pos + 1); |
| 1477 |
rad->span.deflaw = DAHDI_LAW_MULAW; |
| 1478 |
for (x=0;x<rad->nchans;x++) { |
| 1479 |
sprintf(rad->chans[x].name, "PCIRADIO/%d/%d", rad->pos, x); |
| 1480 |
rad->chans[x].sigcap = DAHDI_SIG_SF | DAHDI_SIG_EM; |
| 1481 |
rad->chans[x].chanpos = x+1; |
| 1482 |
rad->chans[x].pvt = rad; |
| 1483 |
rad->debouncetime[x] = RAD_GOTRX_DEBOUNCE_TIME; |
| 1484 |
rad->ctcssacquiretime[x] = RAD_CTCSS_ACQUIRE_TIME; |
| 1485 |
rad->ctcsstalkofftime[x] = RAD_CTCSS_TALKOFF_TIME; |
| 1486 |
} |
| 1487 |
rad->span.chans = &rad->chans; |
| 1488 |
rad->span.channels = rad->nchans; |
| 1489 |
rad->span.flags = DAHDI_FLAG_RBS; |
| 1490 |
rad->span.ops = &pciradio_span_ops; |
| 1491 |
|
| 1492 |
if (dahdi_register_device(rad->ddev, &rad->dev->dev)) { |
| 1493 |
printk(KERN_NOTICE "Unable to register span with DAHDI\n"); |
| 1494 |
return -1; |
| 1495 |
} |
| 1496 |
return 0; |
| 1497 |
} |
| 1498 |
|
| 1499 |
static void wait_just_a_bit(int foo) |
| 1500 |
{ |
| 1501 |
long newjiffies; |
| 1502 |
newjiffies = jiffies + foo; |
| 1503 |
while(jiffies < newjiffies); |
| 1504 |
} |
| 1505 |
|
| 1506 |
static int pciradio_hardware_init(struct pciradio *rad) |
| 1507 |
{ |
| 1508 |
unsigned char byte1,byte2; |
| 1509 |
int x; |
| 1510 |
unsigned long endjif; |
| 1511 |
|
| 1512 |
/* Signal Reset */ |
| 1513 |
outb(0x01, rad->ioaddr + RAD_CNTL); |
| 1514 |
|
| 1515 |
/* Reset PCI Interface chip and registers (and serial) */ |
| 1516 |
outb(0x06, rad->ioaddr + RAD_CNTL); |
| 1517 |
/* Setup our proper outputs */ |
| 1518 |
rad->ios = 0xfe; |
| 1519 |
outb(rad->ios, rad->ioaddr + RAD_AUXD); |
| 1520 |
|
| 1521 |
/* Set all to outputs except AUX 3 & 4, which are inputs */ |
| 1522 |
outb(0x67, rad->ioaddr + RAD_AUXC); |
| 1523 |
|
| 1524 |
/* Select alternate function for AUX0 */ |
| 1525 |
outb(0x4, rad->ioaddr + RAD_AUXFUNC); |
| 1526 |
|
| 1527 |
/* Wait 1/4 of a sec */ |
| 1528 |
wait_just_a_bit(HZ/4); |
| 1529 |
|
| 1530 |
/* attempt to load the Xilinx Chip */ |
| 1531 |
/* De-assert CS+Write */ |
| 1532 |
rad->ios |= XCS; |
| 1533 |
outb(rad->ios, rad->ioaddr + RAD_AUXD); |
| 1534 |
/* Assert PGM */ |
| 1535 |
rad->ios &= ~XPGM; |
| 1536 |
outb(rad->ios, rad->ioaddr + RAD_AUXD); |
| 1537 |
/* wait for INIT and DONE to go low */ |
| 1538 |
endjif = jiffies + 10; |
| 1539 |
while (inb(rad->ioaddr + RAD_AUXR) & (XINIT | XDONE) && (jiffies <= endjif)); |
| 1540 |
if (endjif < jiffies) { |
| 1541 |
printk(KERN_DEBUG "Timeout waiting for INIT and DONE to go low\n"); |
| 1542 |
return -1; |
| 1543 |
} |
| 1544 |
if (debug) printk(KERN_DEBUG "fwload: Init and done gone to low\n"); |
| 1545 |
/* De-assert PGM */ |
| 1546 |
rad->ios |= XPGM; |
| 1547 |
outb(rad->ios, rad->ioaddr + RAD_AUXD); |
| 1548 |
/* wait for INIT to go high (clearing done */ |
| 1549 |
endjif = jiffies + 10; |
| 1550 |
while (!(inb(rad->ioaddr + RAD_AUXR) & XINIT) && (jiffies <= endjif)); |
| 1551 |
if (endjif < jiffies) { |
| 1552 |
printk(KERN_DEBUG "Timeout waiting for INIT to go high\n"); |
| 1553 |
return -1; |
| 1554 |
} |
| 1555 |
if (debug) printk(KERN_DEBUG "fwload: Init went high (clearing done)\nNow loading...\n"); |
| 1556 |
/* Assert CS+Write */ |
| 1557 |
rad->ios &= ~XCS; |
| 1558 |
outb(rad->ios, rad->ioaddr + RAD_AUXD); |
| 1559 |
for (x = 0; x < sizeof(radfw); x++) |
| 1560 |
{ |
| 1561 |
/* write the byte */ |
| 1562 |
outb(radfw[x],rad->ioaddr + RAD_REGBASE); |
| 1563 |
/* if DONE signal, we're done, exit */ |
| 1564 |
if (inb(rad->ioaddr + RAD_AUXR) & XDONE) break; |
| 1565 |
/* if INIT drops, we're screwed, exit */ |
| 1566 |
if (!(inb(rad->ioaddr + RAD_AUXR) & XINIT)) break; |
| 1567 |
} |
| 1568 |
if (debug) printk(KERN_DEBUG "fwload: Transferred %d bytes into chip\n",x); |
| 1569 |
/* Wait for FIFO to clear */ |
| 1570 |
endjif = jiffies + 2; |
| 1571 |
while (jiffies < endjif); /* wait */ |
| 1572 |
printk(KERN_DEBUG "Transfered %d bytes into chip\n",x); |
| 1573 |
/* De-assert CS+Write */ |
| 1574 |
rad->ios |= XCS; |
| 1575 |
outb(rad->ios, rad->ioaddr + RAD_AUXD); |
| 1576 |
if (debug) printk(KERN_INFO "fwload: Loading done!\n"); |
| 1577 |
/* Wait for FIFO to clear */ |
| 1578 |
endjif = jiffies + 2; |
| 1579 |
while (jiffies < endjif); /* wait */ |
| 1580 |
if (!(inb(rad->ioaddr + RAD_AUXR) & XINIT)) |
| 1581 |
{ |
| 1582 |
printk(KERN_NOTICE "Drove Init low!! CRC Error!!!\n"); |
| 1583 |
return -1; |
| 1584 |
} |
| 1585 |
if (!(inb(rad->ioaddr + RAD_AUXR) & XDONE)) |
| 1586 |
{ |
| 1587 |
printk(KERN_INFO "Did not get DONE signal. Short file maybe??\n"); |
| 1588 |
return -1; |
| 1589 |
} |
| 1590 |
wait_just_a_bit(2); |
| 1591 |
/* get the thingy started */ |
| 1592 |
outb(0,rad->ioaddr + RAD_REGBASE); |
| 1593 |
outb(0,rad->ioaddr + RAD_REGBASE); |
| 1594 |
printk(KERN_INFO "Xilinx Chip successfully loaded, configured and started!!\n"); |
| 1595 |
|
| 1596 |
wait_just_a_bit(HZ/4); |
| 1597 |
|
| 1598 |
|
| 1599 |
/* Back to normal, with automatic DMA wrap around */ |
| 1600 |
outb(0x30 | 0x01, rad->ioaddr + RAD_CNTL); |
| 1601 |
|
| 1602 |
/* Configure serial port for MSB->LSB operation */ |
| 1603 |
outb(0xc1, rad->ioaddr + RAD_SERCTL); /* DEBUG set double dlck to 0 SR */ |
| 1604 |
|
| 1605 |
rad->pasave = 0; |
| 1606 |
__pciradio_setcreg(rad,0xa,rad->pasave); |
| 1607 |
|
| 1608 |
__pciradio_setcreg(rad,0xf,rad->pfsave); |
| 1609 |
__pciradio_setcreg(rad,8,0xff); |
| 1610 |
__pciradio_setcreg(rad,0xe,0xff); |
| 1611 |
__pciradio_setcreg(rad,9,0); |
| 1612 |
rad->pfsave = 0; |
| 1613 |
|
| 1614 |
/* Delay FSC by 0 so it's properly aligned */ |
| 1615 |
outb(/* 1 */ 0, rad->ioaddr + RAD_FSCDELAY); |
| 1616 |
|
| 1617 |
/* Setup DMA Addresses */ |
| 1618 |
outl(rad->writedma, rad->ioaddr + RAD_DMAWS); /* Write start */ |
| 1619 |
outl(rad->writedma + DAHDI_CHUNKSIZE * 4 - 4, rad->ioaddr + RAD_DMAWI); /* Middle (interrupt) */ |
| 1620 |
outl(rad->writedma + DAHDI_CHUNKSIZE * 8 - 4, rad->ioaddr + RAD_DMAWE); /* End */ |
| 1621 |
|
| 1622 |
outl(rad->readdma, rad->ioaddr + RAD_DMARS); /* Read start */ |
| 1623 |
outl(rad->readdma + DAHDI_CHUNKSIZE * 4 - 4, rad->ioaddr + RAD_DMARI); /* Middle (interrupt) */ |
| 1624 |
outl(rad->readdma + DAHDI_CHUNKSIZE * 8 - 4, rad->ioaddr + RAD_DMARE); /* End */ |
| 1625 |
|
| 1626 |
/* Clear interrupts */ |
| 1627 |
outb(0xff, rad->ioaddr + RAD_INTSTAT); |
| 1628 |
|
| 1629 |
/* Wait 1/4 of a second more */ |
| 1630 |
wait_just_a_bit(HZ/4); |
| 1631 |
|
| 1632 |
for(x = 0; x < rad->nchans; x++) |
| 1633 |
{ |
| 1634 |
mx828_command_wait(rad,x, MX828_GEN_RESET, &byte1, &byte2 ); |
| 1635 |
byte1 = 0x3f; |
| 1636 |
byte2 = 0x3f; |
| 1637 |
mx828_command_wait(rad,x, MX828_AUD_CTRL, &byte1, &byte2 ); |
| 1638 |
byte1 = 0; |
| 1639 |
mx828_command_wait(rad,x, MX828_SAUDIO_SETUP, &byte1, &byte2 ); |
| 1640 |
byte1 = 0; |
| 1641 |
mx828_command_wait(rad,x, MX828_SAUDIO_CTRL, &byte1, &byte2 ); |
| 1642 |
byte1 = 0xc8; /* default COR thresh is 2 */ |
| 1643 |
mx828_command_wait(rad,x, MX828_GEN_CTRL, &byte1, &byte2); |
| 1644 |
rad->corthresh[x] = 2; |
| 1645 |
} |
| 1646 |
/* Wait 1/4 of a sec */ |
| 1647 |
wait_just_a_bit(HZ/4); |
| 1648 |
|
| 1649 |
return 0; |
| 1650 |
} |
| 1651 |
|
| 1652 |
static void pciradio_enable_interrupts(struct pciradio *rad) |
| 1653 |
{ |
| 1654 |
/* Enable interrupts (we care about all of them) */ |
| 1655 |
outb(0x3f, rad->ioaddr + RAD_MASK0); |
| 1656 |
/* No external interrupts */ |
| 1657 |
outb(0x00, rad->ioaddr + RAD_MASK1); |
| 1658 |
} |
| 1659 |
|
| 1660 |
static void pciradio_restart_dma(struct pciradio *rad) |
| 1661 |
{ |
| 1662 |
/* Reset Master and serial */ |
| 1663 |
outb(0x31, rad->ioaddr + RAD_CNTL); |
| 1664 |
outb(0x01, rad->ioaddr + RAD_OPER); |
| 1665 |
} |
| 1666 |
|
| 1667 |
static void pciradio_start_dma(struct pciradio *rad) |
| 1668 |
{ |
| 1669 |
/* Reset Master and serial */ |
| 1670 |
outb(0x3f, rad->ioaddr + RAD_CNTL); |
| 1671 |
set_current_state(TASK_INTERRUPTIBLE); |
| 1672 |
schedule_timeout(1); |
| 1673 |
outb(0x31, rad->ioaddr + RAD_CNTL); |
| 1674 |
outb(0x01, rad->ioaddr + RAD_OPER); |
| 1675 |
} |
| 1676 |
|
| 1677 |
static void pciradio_stop_dma(struct pciradio *rad) |
| 1678 |
{ |
| 1679 |
outb(0x00, rad->ioaddr + RAD_OPER); |
| 1680 |
} |
| 1681 |
|
| 1682 |
static void pciradio_reset_serial(struct pciradio *rad) |
| 1683 |
{ |
| 1684 |
/* Reset serial */ |
| 1685 |
outb(0x3f, rad->ioaddr + RAD_CNTL); |
| 1686 |
} |
| 1687 |
|
| 1688 |
static void pciradio_disable_interrupts(struct pciradio *rad) |
| 1689 |
{ |
| 1690 |
outb(0x00, rad->ioaddr + RAD_MASK0); |
| 1691 |
outb(0x00, rad->ioaddr + RAD_MASK1); |
| 1692 |
} |
| 1693 |
|
| 1694 |
static int __devinit pciradio_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 1695 |
{ |
| 1696 |
int res; |
| 1697 |
struct pciradio *rad; |
| 1698 |
int x; |
| 1699 |
static int initd_ifaces=0; |
| 1700 |
|
| 1701 |
if(initd_ifaces){ |
| 1702 |
memset((void *)ifaces,0,(sizeof(struct pciradio *))*RAD_MAX_IFACES); |
| 1703 |
initd_ifaces=1; |
| 1704 |
} |
| 1705 |
for (x=0;x<RAD_MAX_IFACES;x++) |
| 1706 |
if (!ifaces[x]) break; |
| 1707 |
if (x >= RAD_MAX_IFACES) { |
| 1708 |
printk(KERN_NOTICE "Too many interfaces\n"); |
| 1709 |
return -EIO; |
| 1710 |
} |
| 1711 |
|
| 1712 |
if (pci_enable_device(pdev)) { |
| 1713 |
res = -EIO; |
| 1714 |
} else { |
| 1715 |
rad = kmalloc(sizeof(struct pciradio), GFP_KERNEL); |
| 1716 |
if (rad) { |
| 1717 |
int i; |
| 1718 |
|
| 1719 |
ifaces[x] = rad; |
| 1720 |
rad->chans = rad->_chans; |
| 1721 |
memset(rad, 0, sizeof(struct pciradio)); |
| 1722 |
spin_lock_init(&rad->lock); |
| 1723 |
rad->nchans = 4; |
| 1724 |
rad->ioaddr = pci_resource_start(pdev, 0); |
| 1725 |
rad->dev = pdev; |
| 1726 |
rad->pos = x; |
| 1727 |
for(i = 0; i < rad->nchans; i++) rad->lasttx[x] = rad->gotrx1[i] = -1; |
| 1728 |
/* Keep track of whether we need to free the region */ |
| 1729 |
if (request_region(rad->ioaddr, 0xff, "pciradio")) |
| 1730 |
rad->freeregion = 1; |
| 1731 |
|
| 1732 |
/* Allocate enough memory for two zt chunks, receive and transmit. Each sample uses |
| 1733 |
32 bits. Allocate an extra set just for control too */ |
| 1734 |
rad->writechunk = pci_alloc_consistent(pdev, DAHDI_MAX_CHUNKSIZE * 2 * 2 * 2 * 4, &rad->writedma); |
| 1735 |
if (!rad->writechunk) { |
| 1736 |
printk(KERN_NOTICE "pciradio: Unable to allocate DMA-able memory\n"); |
| 1737 |
if (rad->freeregion) |
| 1738 |
release_region(rad->ioaddr, 0xff); |
| 1739 |
return -ENOMEM; |
| 1740 |
} |
| 1741 |
|
| 1742 |
rad->readchunk = rad->writechunk + DAHDI_MAX_CHUNKSIZE * 2; /* in doublewords */ |
| 1743 |
rad->readdma = rad->writedma + DAHDI_MAX_CHUNKSIZE * 8; /* in bytes */ |
| 1744 |
|
| 1745 |
if (pciradio_initialize(rad)) { |
| 1746 |
printk(KERN_INFO "pciradio: Unable to intialize\n"); |
| 1747 |
/* Set Reset Low */ |
| 1748 |
x=inb(rad->ioaddr + RAD_CNTL); |
| 1749 |
outb((~0x1)&x, rad->ioaddr + RAD_CNTL); |
| 1750 |
outb(x, rad->ioaddr + RAD_CNTL); |
| 1751 |
__pciradio_setcreg(rad,8,0xff); |
| 1752 |
__pciradio_setcreg(rad,0xe,0xff); |
| 1753 |
/* Free Resources */ |
| 1754 |
free_irq(pdev->irq, rad); |
| 1755 |
if (rad->freeregion) |
| 1756 |
release_region(rad->ioaddr, 0xff); |
| 1757 |
pci_free_consistent(pdev, DAHDI_MAX_CHUNKSIZE * 2 * 2 * 2 * 4, (void *)rad->writechunk, rad->writedma); |
| 1758 |
kfree(rad); |
| 1759 |
return -EIO; |
| 1760 |
} |
| 1761 |
|
| 1762 |
/* Enable bus mastering */ |
| 1763 |
pci_set_master(pdev); |
| 1764 |
|
| 1765 |
/* Keep track of which device we are */ |
| 1766 |
pci_set_drvdata(pdev, rad); |
| 1767 |
|
| 1768 |
if (pciradio_hardware_init(rad)) { |
| 1769 |
/* Set Reset Low */ |
| 1770 |
x=inb(rad->ioaddr + RAD_CNTL); |
| 1771 |
outb((~0x1)&x, rad->ioaddr + RAD_CNTL); |
| 1772 |
outb(x, rad->ioaddr + RAD_CNTL); |
| 1773 |
__pciradio_setcreg(rad,8,0xff); |
| 1774 |
__pciradio_setcreg(rad,0xe,0xff); |
| 1775 |
/* Free Resources */ |
| 1776 |
free_irq(pdev->irq, rad); |
| 1777 |
if (rad->freeregion) |
| 1778 |
release_region(rad->ioaddr, 0xff); |
| 1779 |
pci_free_consistent(pdev, DAHDI_MAX_CHUNKSIZE * 2 * 2 * 2 * 4, (void *)rad->writechunk, rad->writedma); |
| 1780 |
pci_set_drvdata(pdev, NULL); |
| 1781 |
dahdi_free_device(rad->ddev); |
| 1782 |
kfree(rad); |
| 1783 |
return -EIO; |
| 1784 |
|
| 1785 |
} |
| 1786 |
|
| 1787 |
if (request_irq(pdev->irq, pciradio_interrupt, |
| 1788 |
IRQF_SHARED, "pciradio", rad)) { |
| 1789 |
printk(KERN_NOTICE "pciradio: Unable to request IRQ %d\n", pdev->irq); |
| 1790 |
if (rad->freeregion) |
| 1791 |
release_region(rad->ioaddr, 0xff); |
| 1792 |
pci_free_consistent(pdev, DAHDI_MAX_CHUNKSIZE * 2 * 2 * 2 * 4, (void *)rad->writechunk, rad->writedma); |
| 1793 |
pci_set_drvdata(pdev, NULL); |
| 1794 |
kfree(rad); |
| 1795 |
return -EIO; |
| 1796 |
} |
| 1797 |
|
| 1798 |
/* Enable interrupts */ |
| 1799 |
pciradio_enable_interrupts(rad); |
| 1800 |
/* Initialize Write/Buffers to all blank data */ |
| 1801 |
memset((void *)rad->writechunk,0,DAHDI_MAX_CHUNKSIZE * 2 * 2 * 4); |
| 1802 |
|
| 1803 |
/* Start DMA */ |
| 1804 |
pciradio_start_dma(rad); |
| 1805 |
printk(KERN_INFO "Found a PCI Radio Card\n"); |
| 1806 |
res = 0; |
| 1807 |
} else |
| 1808 |
res = -ENOMEM; |
| 1809 |
} |
| 1810 |
return res; |
| 1811 |
} |
| 1812 |
|
| 1813 |
static void pciradio_release(struct pciradio *rad) |
| 1814 |
{ |
| 1815 |
dahdi_unregister_device(rad->ddev); |
| 1816 |
if (rad->freeregion) |
| 1817 |
release_region(rad->ioaddr, 0xff); |
| 1818 |
kfree(rad); |
| 1819 |
printk(KERN_INFO "Freed a PCI RADIO card\n"); |
| 1820 |
} |
| 1821 |
|
| 1822 |
static void __devexit pciradio_remove_one(struct pci_dev *pdev) |
| 1823 |
{ |
| 1824 |
struct pciradio *rad = pci_get_drvdata(pdev); |
| 1825 |
if (rad) { |
| 1826 |
|
| 1827 |
/* Stop any DMA */ |
| 1828 |
pciradio_stop_dma(rad); |
| 1829 |
pciradio_reset_serial(rad); |
| 1830 |
|
| 1831 |
/* In case hardware is still there */ |
| 1832 |
pciradio_disable_interrupts(rad); |
| 1833 |
|
| 1834 |
/* Immediately free resources */ |
| 1835 |
pci_free_consistent(pdev, DAHDI_MAX_CHUNKSIZE * 2 * 2 * 2 * 4, (void *)rad->writechunk, rad->writedma); |
| 1836 |
free_irq(pdev->irq, rad); |
| 1837 |
|
| 1838 |
/* Reset PCI chip and registers */ |
| 1839 |
outb(0x3e, rad->ioaddr + RAD_CNTL); |
| 1840 |
|
| 1841 |
/* Clear Reset Line */ |
| 1842 |
outb(0x3f, rad->ioaddr + RAD_CNTL); |
| 1843 |
|
| 1844 |
__pciradio_setcreg(rad,8,0xff); |
| 1845 |
__pciradio_setcreg(rad,0xe,0xff); |
| 1846 |
|
| 1847 |
/* Release span, possibly delayed */ |
| 1848 |
if (!rad->usecount) |
| 1849 |
pciradio_release(rad); |
| 1850 |
else |
| 1851 |
rad->dead = 1; |
| 1852 |
} |
| 1853 |
} |
| 1854 |
|
| 1855 |
static DEFINE_PCI_DEVICE_TABLE(pciradio_pci_tbl) = { |
| 1856 |
{ 0xe159, 0x0001, 0xe16b, PCI_ANY_ID, 0, 0, (unsigned long)"PCIRADIO" }, |
| 1857 |
{ 0 } |
| 1858 |
}; |
| 1859 |
|
| 1860 |
MODULE_DEVICE_TABLE(pci, pciradio_pci_tbl); |
| 1861 |
|
| 1862 |
static struct pci_driver pciradio_driver = { |
| 1863 |
.name = "pciradio", |
| 1864 |
.probe = pciradio_init_one, |
| 1865 |
.remove = __devexit_p(pciradio_remove_one), |
| 1866 |
.id_table = pciradio_pci_tbl, |
| 1867 |
}; |
| 1868 |
|
| 1869 |
static int __init pciradio_init(void) |
| 1870 |
{ |
| 1871 |
int res; |
| 1872 |
|
| 1873 |
res = dahdi_pci_module(&pciradio_driver); |
| 1874 |
if (res) |
| 1875 |
return -ENODEV; |
| 1876 |
return 0; |
| 1877 |
} |
| 1878 |
|
| 1879 |
static void __exit pciradio_cleanup(void) |
| 1880 |
{ |
| 1881 |
pci_unregister_driver(&pciradio_driver); |
| 1882 |
} |
| 1883 |
|
| 1884 |
module_param(debug, int, 0600); |
| 1885 |
|
| 1886 |
MODULE_DESCRIPTION("DAHDI Telephony PCI Radio Card Driver"); |
| 1887 |
MODULE_AUTHOR("Jim Dixon <[email protected]>"); |
| 1888 |
MODULE_LICENSE("GPL v2"); |
| 1889 |
|
| 1890 |
module_init(pciradio_init); |
| 1891 |
module_exit(pciradio_cleanup); |