wcte11xp.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637
  1. /*
  2. * Digium, Inc. Wildcard TE110P T1/PRI card Driver
  3. *
  4. * Written by Mark Spencer <markster@digium.com>
  5. * Matthew Fredrickson <creslin@digium.com>
  6. * William Meadows <wmeadows@digium.com>
  7. *
  8. * Copyright (C) 2004, Digium, Inc.
  9. *
  10. * All rights reserved.
  11. */
  12. /*
  13. * See http://www.asterisk.org for more information about
  14. * the Asterisk project. Please do not directly contact
  15. * any of the maintainers of this project for assistance;
  16. * the project provides a web site, mailing lists and IRC
  17. * channels for your use.
  18. *
  19. * This program is free software, distributed under the terms of
  20. * the GNU General Public License Version 2 as published by the
  21. * Free Software Foundation. See the LICENSE file included with
  22. * this program for more details.
  23. */
  24. #include <linux/kernel.h>
  25. #include <linux/errno.h>
  26. #include <linux/module.h>
  27. #include <linux/init.h>
  28. #include <linux/usb.h>
  29. #include <linux/errno.h>
  30. #include <linux/pci.h>
  31. #include <linux/spinlock.h>
  32. #include <linux/moduleparam.h>
  33. #include <dahdi/kernel.h>
  34. /* XXX: fix this */
  35. #include "wct4xxp/wct4xxp.h" /* For certain definitions */
  36. #define WC_MAX_CARDS 32
  37. /*
  38. #define TEST_REGS
  39. */
  40. /* Define to get more attention-grabbing but slightly more I/O using
  41. alarm status */
  42. #define FANCY_ALARM
  43. /* Define to enable the V2.1 errata register settings */
  44. #if 0
  45. #define TRUST_INFINEON_ERRATA
  46. #endif
  47. #define DELAY 0x0 /* 30 = 15 cycles, 10 = 8 cycles, 0 = 3 cycles */
  48. #define WC_CNTL 0x00
  49. #define WC_OPER 0x01
  50. #define WC_AUXC 0x02
  51. #define WC_AUXD 0x03
  52. #define WC_MASK0 0x04
  53. #define WC_MASK1 0x05
  54. #define WC_INTSTAT 0x06
  55. #define WC_DMAWS 0x08
  56. #define WC_DMAWI 0x0c
  57. #define WC_DMAWE 0x10
  58. #define WC_DMARS 0x18
  59. #define WC_DMARI 0x1c
  60. #define WC_DMARE 0x20
  61. #define WC_CURPOS 0x24
  62. #define WC_SERC 0x2d
  63. #define WC_FSCDELAY 0x2f
  64. #define WC_USERREG 0xc0
  65. #define WC_CLOCK 0x0
  66. #define WC_LEDTEST 0x1
  67. #define WC_VERSION 0x2
  68. /* Offset between transmit and receive */
  69. #define WC_OFFSET 4
  70. #define BIT_CS (1 << 7)
  71. #define BIT_ADDR (0xf << 3)
  72. #define BIT_LED1 (1 << 0)
  73. #define BIT_LED0 (1 << 1)
  74. #define BIT_TEST (1 << 2)
  75. #define FLAG_STARTED (1 << 0)
  76. #define FLAG_NMF (1 << 1)
  77. #define FLAG_SENDINGYELLOW (1 << 2)
  78. #define FLAG_FALC12 (1 << 3)
  79. #define TYPE_T1 1 /* is a T1 card */
  80. #define TYPE_E1 2 /* is an E1 card */
  81. static int chanmap_t1[] =
  82. { 2,1,0,
  83. 6,5,4,
  84. 10,9,8,
  85. 14,13,12,
  86. 18,17,16,
  87. 22,21,20,
  88. 26,25,24,
  89. 30,29,28 };
  90. static int chanmap_e1[] =
  91. { 2,1,0,
  92. 7,6,5,4,
  93. 11,10,9,8,
  94. 15,14,13,12,
  95. 19,18,17,16,
  96. 23,22,21,20,
  97. 27,26,25,24,
  98. 31,30,29,28 };
  99. static int chanmap_e1uc[] =
  100. { 3,2,1,0,
  101. 7,6,5,4,
  102. 11,10,9,8,
  103. 15,14,13,12,
  104. 19,18,17,16,
  105. 23,22,21,20,
  106. 27,26,25,24,
  107. 31,30,29,28 };
  108. #ifdef FANCY_ALARM
  109. static int altab[] = {
  110. 0, 0, 0, 1, 2, 3, 4, 6, 8, 9, 11, 13, 16, 18, 20, 22, 24, 25, 27, 28, 29, 30, 31, 31, 32, 31, 31, 30, 29, 28, 27, 25, 23, 22, 20, 18, 16, 13, 11, 9, 8, 6, 4, 3, 2, 1, 0, 0,
  111. };
  112. #endif
  113. struct t1 {
  114. struct pci_dev *dev;
  115. spinlock_t lock;
  116. int spantype;
  117. int spanflags; /* Span flags */
  118. unsigned char txsigs[16]; /* Copy of tx sig registers */
  119. int num;
  120. int alarmcount; /* How much red alarm we've seen */
  121. int alarmdebounce;
  122. /* Our offset for finding channel 1 */
  123. int offset;
  124. char *variety;
  125. unsigned int intcount;
  126. int usecount;
  127. int clocktimeout;
  128. int sync;
  129. int dead;
  130. int blinktimer;
  131. int alarmtimer;
  132. int checktiming; /* Set >0 to cause the timing source to be checked */
  133. int loopupcnt;
  134. int loopdowncnt;
  135. int miss;
  136. int misslast;
  137. int *chanmap;
  138. #ifdef FANCY_ALARM
  139. int alarmpos;
  140. #endif
  141. unsigned char ledtestreg;
  142. unsigned char outbyte;
  143. unsigned long ioaddr;
  144. unsigned short canary;
  145. /* T1 signalling */
  146. dma_addr_t readdma;
  147. dma_addr_t writedma;
  148. volatile unsigned char *writechunk; /* Double-word aligned write memory */
  149. volatile unsigned char *readchunk; /* Double-word aligned read memory */
  150. unsigned char ec_chunk1[32][DAHDI_CHUNKSIZE];
  151. unsigned char ec_chunk2[32][DAHDI_CHUNKSIZE];
  152. unsigned char tempo[33];
  153. struct dahdi_span span; /* Span */
  154. struct dahdi_chan *chans[32]; /* Channels */
  155. };
  156. #define CANARY 0xca1e
  157. static int debug = 0; /* doesnt do anything */
  158. static int j1mode = 0;
  159. static int alarmdebounce = 0;
  160. static int loopback = 0;
  161. static int clockextra = 0;
  162. static int t1e1override = -1;
  163. static int unchannelized = 0;
  164. static struct t1 *cards[WC_MAX_CARDS];
  165. static inline void start_alarm(struct t1 *wc)
  166. {
  167. #ifdef FANCY_ALARM
  168. wc->alarmpos = 0;
  169. #endif
  170. wc->blinktimer = 0;
  171. }
  172. static inline void stop_alarm(struct t1 *wc)
  173. {
  174. #ifdef FANCY_ALARM
  175. wc->alarmpos = 0;
  176. #endif
  177. wc->blinktimer = 0;
  178. }
  179. static inline void __select_framer(struct t1 *wc, int reg)
  180. {
  181. /* Top four bits of address from AUX 6-3 */
  182. wc->outbyte &= ~BIT_CS;
  183. wc->outbyte &= ~BIT_ADDR;
  184. wc->outbyte |= (reg & 0xf0) >> 1;
  185. outb(wc->outbyte, wc->ioaddr + WC_AUXD);
  186. }
  187. static inline void __select_control(struct t1 *wc)
  188. {
  189. if (!(wc->outbyte & BIT_CS)) {
  190. wc->outbyte |= BIT_CS;
  191. outb(wc->outbyte, wc->ioaddr + WC_AUXD);
  192. }
  193. }
  194. static int t1xxp_open(struct dahdi_chan *chan)
  195. {
  196. struct t1 *wc = chan->pvt;
  197. if (wc->dead)
  198. return -ENODEV;
  199. wc->usecount++;
  200. return 0;
  201. }
  202. static int __control_set_reg(struct t1 *wc, int reg, unsigned char val)
  203. {
  204. __select_control(wc);
  205. outb(val, wc->ioaddr + WC_USERREG + ((reg & 0xf) << 2));
  206. return 0;
  207. }
  208. static int control_set_reg(struct t1 *wc, int reg, unsigned char val)
  209. {
  210. unsigned long flags;
  211. int res;
  212. spin_lock_irqsave(&wc->lock, flags);
  213. res = __control_set_reg(wc, reg, val);
  214. spin_unlock_irqrestore(&wc->lock, flags);
  215. return res;
  216. }
  217. static int __control_get_reg(struct t1 *wc, int reg)
  218. {
  219. unsigned char res;
  220. /* The following makes UTTERLY no sense, but what was happening
  221. was that reads in some cases were not actually happening
  222. on the physical bus. Why, we dunno. But in debugging, we found
  223. that writing before reading (in this case to an unused position)
  224. seems to get rid of the problem */
  225. __control_set_reg(wc,3,0x69); /* do magic here */
  226. /* now get the read byte from the Xilinx part */
  227. res = inb(wc->ioaddr + WC_USERREG + ((reg & 0xf) << 2));
  228. return res;
  229. }
  230. static int control_get_reg(struct t1 *wc, int reg)
  231. {
  232. unsigned long flags;
  233. int res;
  234. spin_lock_irqsave(&wc->lock, flags);
  235. res = __control_get_reg(wc, reg);
  236. spin_unlock_irqrestore(&wc->lock, flags);
  237. return res;
  238. }
  239. static inline unsigned int __t1_framer_in(struct t1 *wc, const unsigned int reg)
  240. {
  241. unsigned char res;
  242. __select_framer(wc, reg);
  243. /* Get value */
  244. res = inb(wc->ioaddr + WC_USERREG + ((reg & 0xf) << 2));
  245. return res;
  246. #if 0
  247. unsigned int ret;
  248. __t1_pci_out(wc, WC_LADDR, (unit << 8) | (addr & 0xff));
  249. __t1_pci_out(wc, WC_LADDR, (unit << 8) | (addr & 0xff) | ( 1 << 10) | WC_LREAD);
  250. ret = __t1_pci_in(wc, WC_LDATA);
  251. __t1_pci_out(wc, WC_LADDR, 0);
  252. return ret & 0xff;
  253. #endif
  254. }
  255. static inline unsigned int t1_framer_in(struct t1 *wc, const unsigned int addr)
  256. {
  257. unsigned long flags;
  258. unsigned int ret;
  259. spin_lock_irqsave(&wc->lock, flags);
  260. ret = __t1_framer_in(wc, addr);
  261. spin_unlock_irqrestore(&wc->lock, flags);
  262. return ret;
  263. }
  264. static inline void __t1_framer_out(struct t1 *wc, const unsigned int reg, const unsigned int val)
  265. {
  266. if (debug > 1)
  267. printk(KERN_DEBUG "Writing %02x to address %02x\n", val, reg);
  268. __select_framer(wc, reg);
  269. /* Send address */
  270. outb(val, wc->ioaddr + WC_USERREG + ((reg & 0xf) << 2));
  271. #if 0
  272. __t1_pci_out(wc, WC_LADDR, (unit << 8) | (addr & 0xff));
  273. __t1_pci_out(wc, WC_LDATA, value);
  274. __t1_pci_out(wc, WC_LADDR, (unit << 8) | (addr & 0xff) | (1 << 10));
  275. __t1_pci_out(wc, WC_LADDR, (unit << 8) | (addr & 0xff) | (1 << 10) | WC_LWRITE);
  276. __t1_pci_out(wc, WC_LADDR, (unit << 8) | (addr & 0xff) | (1 << 10));
  277. __t1_pci_out(wc, WC_LADDR, (unit << 8) | (addr & 0xff));
  278. __t1_pci_out(wc, WC_LADDR, 0);
  279. if (debug) printk(KERN_DEBUG "Write complete\n");
  280. #endif
  281. #if 0
  282. { unsigned int tmp;
  283. tmp = t1_framer_in(wc, unit, addr);
  284. if (tmp != value) {
  285. printk(KERN_DEBUG "Expected %d from unit %d register %d but got %d instead\n", value, unit, addr, tmp);
  286. } }
  287. #endif
  288. }
  289. static inline void t1_framer_out(struct t1 *wc, const unsigned int addr, const unsigned int value)
  290. {
  291. unsigned long flags;
  292. spin_lock_irqsave(&wc->lock, flags);
  293. __t1_framer_out(wc, addr, value);
  294. spin_unlock_irqrestore(&wc->lock, flags);
  295. }
  296. static void t1xxp_release(struct t1 *wc)
  297. {
  298. unsigned int x;
  299. dahdi_unregister(&wc->span);
  300. for (x = 0; x < (wc->spantype == TYPE_E1 ? 31 : 24); x++) {
  301. kfree(wc->chans[x]);
  302. }
  303. kfree(wc);
  304. printk(KERN_INFO "Freed a Wildcard\n");
  305. }
  306. static int t1xxp_close(struct dahdi_chan *chan)
  307. {
  308. struct t1 *wc = chan->pvt;
  309. wc->usecount--;
  310. /* If we're dead, release us now */
  311. if (!wc->usecount && wc->dead)
  312. t1xxp_release(wc);
  313. return 0;
  314. }
  315. static void t1xxp_enable_interrupts(struct t1 *wc)
  316. {
  317. /* Clear interrupts */
  318. outb(0xff, wc->ioaddr + WC_INTSTAT);
  319. /* Enable interrupts (we care about all of them) */
  320. outb(0x3c /* 0x3f */, wc->ioaddr + WC_MASK0);
  321. /* No external interrupts */
  322. outb(0x00, wc->ioaddr + WC_MASK1);
  323. if (debug) printk(KERN_DEBUG "Enabled interrupts!\n");
  324. }
  325. static void t1xxp_start_dma(struct t1 *wc)
  326. {
  327. /* Reset Master and TDM */
  328. outb(DELAY | 0x0f, wc->ioaddr + WC_CNTL);
  329. set_current_state(TASK_INTERRUPTIBLE);
  330. schedule_timeout(1);
  331. outb(DELAY | 0x01, wc->ioaddr + WC_CNTL);
  332. outb(0x01, wc->ioaddr + WC_OPER);
  333. if (debug) printk(KERN_DEBUG "Started DMA\n");
  334. outb(0x03, wc->ioaddr + WC_OPER);
  335. outb(0x01, wc->ioaddr + WC_OPER);
  336. }
  337. static void __t1xxp_stop_dma(struct t1 *wc)
  338. {
  339. outb(0x00, wc->ioaddr + WC_OPER);
  340. }
  341. static void __t1xxp_disable_interrupts(struct t1 *wc)
  342. {
  343. outb(0x00, wc->ioaddr + WC_MASK0);
  344. outb(0x00, wc->ioaddr + WC_MASK1);
  345. }
  346. static void __t1xxp_set_clear(struct t1 *wc)
  347. {
  348. int i,j;
  349. unsigned short val=0;
  350. for (i=0;i<24;i++) {
  351. j = (i/8);
  352. if (wc->span.chans[i]->flags & DAHDI_FLAG_CLEAR)
  353. val |= 1 << (7 - (i % 8));
  354. if ((i % 8)==7) {
  355. if (debug > 1)
  356. printk(KERN_DEBUG "Putting %d in register %02x\n",
  357. val, 0x2f + j);
  358. __t1_framer_out(wc, 0x2f + j, val);
  359. val = 0;
  360. }
  361. }
  362. }
  363. static int t1xxp_ioctl(struct dahdi_chan *chan, unsigned int cmd, unsigned long data)
  364. {
  365. struct t4_regs regs;
  366. int x;
  367. struct t1 *wc;
  368. switch(cmd) {
  369. case WCT4_GET_REGS:
  370. wc = chan->pvt;
  371. for (x=0;x<NUM_PCI;x++)
  372. #if 1
  373. regs.pci[x] = (inb(wc->ioaddr + (x << 2))) |
  374. (inb(wc->ioaddr + (x << 2) + 1) << 8) |
  375. (inb(wc->ioaddr + (x << 2) + 2) << 16) |
  376. (inb(wc->ioaddr + (x << 2) + 3) << 24);
  377. #else
  378. regs.pci[x] = (inb(wc->ioaddr + x));
  379. #endif
  380. for (x=0;x<NUM_REGS;x++)
  381. regs.regs[x] = t1_framer_in(wc, x);
  382. if (copy_to_user((__user void *)data, &regs, sizeof(regs)))
  383. return -EFAULT;
  384. break;
  385. default:
  386. return -ENOTTY;
  387. }
  388. return 0;
  389. }
  390. static inline struct t1 *t1_from_span(struct dahdi_span *span)
  391. {
  392. return container_of(span, struct t1, span);
  393. }
  394. static int t1xxp_maint(struct dahdi_span *span, int cmd)
  395. {
  396. struct t1 *wc = t1_from_span(span);
  397. if (wc->spantype == TYPE_E1) {
  398. switch(cmd) {
  399. case DAHDI_MAINT_NONE:
  400. printk(KERN_INFO "XXX Turn off local and remote loops E1 XXX\n");
  401. break;
  402. case DAHDI_MAINT_LOCALLOOP:
  403. printk(KERN_INFO "XXX Turn on local loopback E1 XXX\n");
  404. break;
  405. case DAHDI_MAINT_REMOTELOOP:
  406. printk(KERN_INFO "XXX Turn on remote loopback E1 XXX\n");
  407. break;
  408. case DAHDI_MAINT_LOOPUP:
  409. printk(KERN_INFO "XXX Send loopup code E1 XXX\n");
  410. break;
  411. case DAHDI_MAINT_LOOPDOWN:
  412. printk(KERN_INFO "XXX Send loopdown code E1 XXX\n");
  413. break;
  414. case DAHDI_MAINT_LOOPSTOP:
  415. printk(KERN_INFO "XXX Stop sending loop codes E1 XXX\n");
  416. break;
  417. default:
  418. printk(KERN_NOTICE "TE110P: Unknown E1 maint command: %d\n", cmd);
  419. break;
  420. }
  421. } else {
  422. switch(cmd) {
  423. case DAHDI_MAINT_NONE:
  424. printk(KERN_INFO "XXX Turn off local and remote loops T1 XXX\n");
  425. break;
  426. case DAHDI_MAINT_LOCALLOOP:
  427. printk(KERN_INFO "XXX Turn on local loop and no remote loop XXX\n");
  428. break;
  429. case DAHDI_MAINT_REMOTELOOP:
  430. printk(KERN_INFO "XXX Turn on remote loopup XXX\n");
  431. break;
  432. case DAHDI_MAINT_LOOPUP:
  433. t1_framer_out(wc, 0x21, 0x50); /* FMR5: Nothing but RBS mode */
  434. break;
  435. case DAHDI_MAINT_LOOPDOWN:
  436. t1_framer_out(wc, 0x21, 0x60); /* FMR5: Nothing but RBS mode */
  437. break;
  438. case DAHDI_MAINT_LOOPSTOP:
  439. t1_framer_out(wc, 0x21, 0x40); /* FMR5: Nothing but RBS mode */
  440. break;
  441. default:
  442. printk(KERN_NOTICE "TE110P: Unknown T1 maint command: %d\n", cmd);
  443. break;
  444. }
  445. }
  446. return 0;
  447. }
  448. static int t1xxp_rbsbits(struct dahdi_chan *chan, int bits)
  449. {
  450. u_char m,c;
  451. int n,b;
  452. struct t1 *wc = chan->pvt;
  453. unsigned long flags;
  454. if(debug > 1) printk(KERN_DEBUG "Setting bits to %d on channel %s\n", bits, chan->name);
  455. spin_lock_irqsave(&wc->lock, flags);
  456. if (wc->spantype == TYPE_E1) { /* do it E1 way */
  457. if (chan->chanpos == 16) {
  458. spin_unlock_irqrestore(&wc->lock, flags);
  459. return 0;
  460. }
  461. n = chan->chanpos - 1;
  462. if (chan->chanpos > 15) n--;
  463. b = (n % 15);
  464. c = wc->txsigs[b];
  465. m = (n / 15) << 2; /* nibble selector */
  466. c &= (0xf << m); /* keep the other nibble */
  467. c |= (bits & 0xf) << (4 - m); /* put our new nibble here */
  468. wc->txsigs[b] = c;
  469. /* output them to the chip */
  470. __t1_framer_out(wc,0x71 + b,c);
  471. } else if (wc->span.lineconfig & DAHDI_CONFIG_D4) {
  472. n = chan->chanpos - 1;
  473. b = (n/4);
  474. c = wc->txsigs[b];
  475. m = ((3 - (n % 4)) << 1); /* nibble selector */
  476. c &= ~(0x3 << m); /* keep the other nibble */
  477. c |= ((bits >> 2) & 0x3) << m; /* put our new nibble here */
  478. wc->txsigs[b] = c;
  479. /* output them to the chip */
  480. __t1_framer_out(wc,0x70 + b,c);
  481. __t1_framer_out(wc,0x70 + b + 6,c);
  482. } else if (wc->span.lineconfig & DAHDI_CONFIG_ESF) {
  483. n = chan->chanpos - 1;
  484. b = (n/2);
  485. c = wc->txsigs[b];
  486. m = ((n % 2) << 2); /* nibble selector */
  487. c &= (0xf << m); /* keep the other nibble */
  488. c |= (bits & 0xf) << (4 - m); /* put our new nibble here */
  489. wc->txsigs[b] = c;
  490. /* output them to the chip */
  491. __t1_framer_out(wc,0x70 + b,c);
  492. }
  493. spin_unlock_irqrestore(&wc->lock, flags);
  494. if (debug > 1)
  495. printk(KERN_DEBUG "Finished setting RBS bits\n");
  496. return 0;
  497. }
  498. static void t1_check_sigbits(struct t1 *wc)
  499. {
  500. int a,i,rxs;
  501. unsigned long flags;
  502. if (!(wc->span.flags & DAHDI_FLAG_RUNNING))
  503. return;
  504. spin_lock_irqsave(&wc->lock, flags);
  505. if (wc->spantype == TYPE_E1) {
  506. for (i = 0; i < 15; i++) {
  507. a = __t1_framer_in(wc, 0x71 + i);
  508. /* Get high channel in low bits */
  509. rxs = (a & 0xf);
  510. if (!(wc->span.chans[i+16]->sig & DAHDI_SIG_CLEAR)) {
  511. if (wc->span.chans[i+16]->rxsig != rxs) {
  512. spin_unlock_irqrestore(&wc->lock, flags);
  513. dahdi_rbsbits(wc->span.chans[i+16], rxs);
  514. spin_lock_irqsave(&wc->lock, flags);
  515. }
  516. }
  517. rxs = (a >> 4) & 0xf;
  518. if (!(wc->span.chans[i]->sig & DAHDI_SIG_CLEAR)) {
  519. if (wc->span.chans[i]->rxsig != rxs) {
  520. spin_unlock_irqrestore(&wc->lock, flags);
  521. dahdi_rbsbits(wc->span.chans[i], rxs);
  522. spin_lock_irqsave(&wc->lock, flags);
  523. }
  524. }
  525. }
  526. } else if (wc->span.lineconfig & DAHDI_CONFIG_D4) {
  527. for (i = 0; i < 24; i+=4) {
  528. a = __t1_framer_in(wc, 0x70 + (i>>2));
  529. /* Get high channel in low bits */
  530. rxs = (a & 0x3) << 2;
  531. if (!(wc->span.chans[i+3]->sig & DAHDI_SIG_CLEAR)) {
  532. if (wc->span.chans[i+3]->rxsig != rxs) {
  533. spin_unlock_irqrestore(&wc->lock, flags);
  534. dahdi_rbsbits(wc->span.chans[i+3], rxs);
  535. spin_lock_irqsave(&wc->lock, flags);
  536. }
  537. }
  538. rxs = (a & 0xc);
  539. if (!(wc->span.chans[i+2]->sig & DAHDI_SIG_CLEAR)) {
  540. if (wc->span.chans[i+2]->rxsig != rxs) {
  541. spin_unlock_irqrestore(&wc->lock, flags);
  542. dahdi_rbsbits(wc->span.chans[i+2], rxs);
  543. spin_lock_irqsave(&wc->lock, flags);
  544. }
  545. }
  546. rxs = (a >> 2) & 0xc;
  547. if (!(wc->span.chans[i+1]->sig & DAHDI_SIG_CLEAR)) {
  548. if (wc->span.chans[i+1]->rxsig != rxs) {
  549. spin_unlock_irqrestore(&wc->lock, flags);
  550. dahdi_rbsbits(wc->span.chans[i+1], rxs);
  551. spin_lock_irqsave(&wc->lock, flags);
  552. }
  553. }
  554. rxs = (a >> 4) & 0xc;
  555. if (!(wc->span.chans[i]->sig & DAHDI_SIG_CLEAR)) {
  556. if (wc->span.chans[i]->rxsig != rxs) {
  557. spin_unlock_irqrestore(&wc->lock, flags);
  558. dahdi_rbsbits(wc->span.chans[i], rxs);
  559. spin_lock_irqsave(&wc->lock, flags);
  560. }
  561. }
  562. }
  563. } else {
  564. for (i = 0; i < 24; i+=2) {
  565. a = __t1_framer_in(wc, 0x70 + (i>>1));
  566. /* Get high channel in low bits */
  567. rxs = (a & 0xf);
  568. if (!(wc->span.chans[i+1]->sig & DAHDI_SIG_CLEAR)) {
  569. if (wc->span.chans[i+1]->rxsig != rxs) {
  570. spin_unlock_irqrestore(&wc->lock, flags);
  571. dahdi_rbsbits(wc->span.chans[i+1], rxs);
  572. spin_lock_irqsave(&wc->lock, flags);
  573. }
  574. }
  575. rxs = (a >> 4) & 0xf;
  576. if (!(wc->span.chans[i]->sig & DAHDI_SIG_CLEAR)) {
  577. if (wc->span.chans[i]->rxsig != rxs) {
  578. spin_unlock_irqrestore(&wc->lock, flags);
  579. dahdi_rbsbits(wc->span.chans[i], rxs);
  580. spin_lock_irqsave(&wc->lock, flags);
  581. }
  582. }
  583. }
  584. }
  585. spin_unlock_irqrestore(&wc->lock, flags);
  586. }
  587. static void t4_serial_setup(struct t1 *wc)
  588. {
  589. printk(KERN_INFO "TE110P: Setting up global serial parameters for %s %s\n",
  590. wc->spantype == TYPE_E1 ? (unchannelized ? "Unchannelized E1" : "E1") : "T1",
  591. wc->spanflags & FLAG_FALC12 ? "FALC V1.2" : "FALC V2.2");
  592. t1_framer_out(wc, 0x85, 0xe0); /* GPC1: Multiplex mode enabled, FSC is output, active low, RCLK from channel 0 */
  593. t1_framer_out(wc, 0x08, 0x05); /* IPC: Interrupt push/pull active low */
  594. if (wc->spanflags & FLAG_FALC12) {
  595. t1_framer_out(wc, 0x92, 0x00);
  596. t1_framer_out(wc, 0x93, 0x58);
  597. t1_framer_out(wc, 0x94, 0xd2);
  598. t1_framer_out(wc, 0x95, 0xc2);
  599. t1_framer_out(wc, 0x96, 0x03);
  600. t1_framer_out(wc, 0x97, 0x10);
  601. } else {
  602. /* Global clocks (8.192 Mhz CLK) */
  603. t1_framer_out(wc, 0x92, 0x00);
  604. t1_framer_out(wc, 0x93, 0x18);
  605. t1_framer_out(wc, 0x94, 0xfb);
  606. t1_framer_out(wc, 0x95, 0x0b);
  607. t1_framer_out(wc, 0x96, 0x00);
  608. t1_framer_out(wc, 0x97, 0x0b);
  609. t1_framer_out(wc, 0x98, 0xdb);
  610. t1_framer_out(wc, 0x99, 0xdf);
  611. }
  612. /* Configure interrupts */
  613. t1_framer_out(wc, 0x46, 0x40); /* GCR: Interrupt on Activation/Deactivation of AIX, LOS */
  614. /* Configure system interface */
  615. t1_framer_out(wc, 0x3e, 0x02); /* SIC1: 4.096 Mhz clock/bus, double buffer receive / transmit, byte interleaved */
  616. t1_framer_out(wc, 0x3f, 0x00); /* SIC2: No FFS, no center receive eliastic buffer, phase 0 */
  617. t1_framer_out(wc, 0x40, 0x04); /* SIC3: Edges for capture */
  618. t1_framer_out(wc, 0x44, 0x30); /* CMR1: RCLK is at 8.192 Mhz dejittered */
  619. t1_framer_out(wc, 0x45, 0x00); /* CMR2: We provide sync and clock for tx and rx. */
  620. t1_framer_out(wc, 0x22, 0x00); /* XC0: Normal operation of Sa-bits */
  621. t1_framer_out(wc, 0x23, 0x04); /* XC1: 0 offset */
  622. t1_framer_out(wc, 0x24, 0x07); /* RC0: Just shy of 255 */
  623. if (wc->spanflags & FLAG_FALC12)
  624. t1_framer_out(wc, 0x25, 0x04); /* RC1: The rest of RC0 */
  625. else
  626. t1_framer_out(wc, 0x25, 0x05); /* RC1: The rest of RC0 */
  627. /* Configure ports */
  628. t1_framer_out(wc, 0x80, 0x00); /* PC1: SPYR/SPYX input on RPA/XPA */
  629. t1_framer_out(wc, 0x81, 0x22); /* PC2: RMFB/XSIG output/input on RPB/XPB */
  630. t1_framer_out(wc, 0x82, 0x65); /* PC3: Some unused stuff */
  631. t1_framer_out(wc, 0x83, 0x35); /* PC4: Some more unused stuff */
  632. t1_framer_out(wc, 0x84, 0x31); /* PC5: XMFS active low, SCLKR is input, RCLK is output */
  633. t1_framer_out(wc, 0x86, 0x03); /* PC6: CLK1 is Tx Clock output, CLK2 is 8.192 Mhz from DCO-R */
  634. t1_framer_out(wc, 0x3b, 0x00); /* Clear LCR1 */
  635. printk(KERN_INFO "TE110P: Successfully initialized serial bus for card\n");
  636. }
  637. static void __t1_configure_t1(struct t1 *wc, int lineconfig, int txlevel)
  638. {
  639. unsigned int fmr4, fmr2, fmr1, fmr0, lim2;
  640. char *framing, *line;
  641. int mytxlevel;
  642. if ((txlevel > 7) || (txlevel < 4))
  643. mytxlevel = 0;
  644. else
  645. mytxlevel = txlevel - 4;
  646. fmr1 = 0x1c; /* FMR1: Mode 0, T1 mode, CRC on for ESF, 2.048 Mhz system data rate, no XAIS */
  647. fmr2 = 0x22; /* FMR2: no payload loopback, auto send yellow alarm */
  648. if (loopback)
  649. fmr2 |= 0x4;
  650. if (j1mode)
  651. fmr4 = 0x1c;
  652. else
  653. fmr4 = 0x0c; /* FMR4: Lose sync on 2 out of 5 framing bits, auto resync */
  654. lim2 = 0x21; /* LIM2: 50% peak is a "1", Advanced Loss recovery */
  655. lim2 |= (mytxlevel << 6); /* LIM2: Add line buildout */
  656. __t1_framer_out(wc, 0x1d, fmr1);
  657. __t1_framer_out(wc, 0x1e, fmr2);
  658. /* Configure line interface */
  659. if (lineconfig & DAHDI_CONFIG_AMI) {
  660. line = "AMI";
  661. fmr0 = 0xa0;
  662. } else {
  663. line = "B8ZS";
  664. fmr0 = 0xf0;
  665. }
  666. if (lineconfig & DAHDI_CONFIG_D4) {
  667. framing = "D4";
  668. } else {
  669. framing = "ESF";
  670. fmr4 |= 0x2;
  671. fmr2 |= 0xc0;
  672. }
  673. __t1_framer_out(wc, 0x1c, fmr0);
  674. __t1_framer_out(wc, 0x20, fmr4);
  675. __t1_framer_out(wc, 0x21, 0x40); /* FMR5: Enable RBS mode */
  676. __t1_framer_out(wc, 0x37, 0xf8); /* LIM1: Clear data in case of LOS, Set receiver threshold (0.5V), No remote loop, no DRS */
  677. __t1_framer_out(wc, 0x36, 0x08); /* LIM0: Enable auto long haul mode, no local loop (must be after LIM1) */
  678. __t1_framer_out(wc, 0x02, 0x50); /* CMDR: Reset the receiver and transmitter line interface */
  679. __t1_framer_out(wc, 0x02, 0x00); /* CMDR: Reset the receiver and transmitter line interface */
  680. __t1_framer_out(wc, 0x3a, lim2); /* LIM2: 50% peak amplitude is a "1" */
  681. __t1_framer_out(wc, 0x38, 0x0a); /* PCD: LOS after 176 consecutive "zeros" */
  682. __t1_framer_out(wc, 0x39, 0x15); /* PCR: 22 "ones" clear LOS */
  683. if (j1mode)
  684. __t1_framer_out(wc, 0x24, 0x80); /* J1 overide */
  685. /* Generate pulse mask for T1 */
  686. switch(mytxlevel) {
  687. case 3:
  688. __t1_framer_out(wc, 0x26, 0x07); /* XPM0 */
  689. __t1_framer_out(wc, 0x27, 0x01); /* XPM1 */
  690. __t1_framer_out(wc, 0x28, 0x00); /* XPM2 */
  691. break;
  692. case 2:
  693. __t1_framer_out(wc, 0x26, 0x8c); /* XPM0 */
  694. __t1_framer_out(wc, 0x27, 0x11); /* XPM1 */
  695. __t1_framer_out(wc, 0x28, 0x01); /* XPM2 */
  696. break;
  697. case 1:
  698. __t1_framer_out(wc, 0x26, 0x8c); /* XPM0 */
  699. __t1_framer_out(wc, 0x27, 0x01); /* XPM1 */
  700. __t1_framer_out(wc, 0x28, 0x00); /* XPM2 */
  701. break;
  702. case 0:
  703. default:
  704. __t1_framer_out(wc, 0x26, 0xd7); /* XPM0 */
  705. __t1_framer_out(wc, 0x27, 0x22); /* XPM1 */
  706. __t1_framer_out(wc, 0x28, 0x01); /* XPM2 */
  707. break;
  708. }
  709. printk(KERN_INFO "TE110P: Span configured for %s/%s\n", framing, line);
  710. }
  711. static void __t1_configure_e1(struct t1 *wc, int lineconfig)
  712. {
  713. unsigned int fmr2, fmr1, fmr0;
  714. unsigned int cas = 0;
  715. char *crc4 = "";
  716. char *framing, *line;
  717. fmr1 = 0x44; /* FMR1: E1 mode, Automatic force resync, PCM30 mode, 8.192 Mhz backplane, no XAIS */
  718. fmr2 = 0x03; /* FMR2: Auto transmit remote alarm, auto loss of multiframe recovery, no payload loopback */
  719. if (unchannelized)
  720. fmr2 |= 0x30;
  721. if (loopback)
  722. fmr2 |= 0x4;
  723. if (lineconfig & DAHDI_CONFIG_CRC4) {
  724. fmr1 |= 0x08; /* CRC4 transmit */
  725. fmr2 |= 0xc0; /* CRC4 receive */
  726. crc4 = "/CRC4";
  727. }
  728. __t1_framer_out(wc, 0x1d, fmr1);
  729. __t1_framer_out(wc, 0x1e, fmr2);
  730. /* Configure line interface */
  731. if (lineconfig & DAHDI_CONFIG_AMI) {
  732. line = "AMI";
  733. fmr0 = 0xa0;
  734. } else {
  735. line = "HDB3";
  736. fmr0 = 0xf0;
  737. }
  738. if (lineconfig & DAHDI_CONFIG_CCS) {
  739. framing = "CCS";
  740. } else {
  741. framing = "CAS";
  742. cas = 0x40;
  743. }
  744. __t1_framer_out(wc, 0x1c, fmr0);
  745. if (unchannelized)
  746. __t1_framer_out(wc, 0x1f, 0x40);
  747. __t1_framer_out(wc, 0x37, 0xf0 /*| 0x6 */ ); /* LIM1: Clear data in case of LOS, Set receiver threshold (0.5V), No remote loop, no DRS */
  748. __t1_framer_out(wc, 0x36, 0x08); /* LIM0: Enable auto long haul mode, no local loop (must be after LIM1) */
  749. __t1_framer_out(wc, 0x02, 0x50); /* CMDR: Reset the receiver and transmitter line interface */
  750. __t1_framer_out(wc, 0x02, 0x00); /* CMDR: Reset the receiver and transmitter line interface */
  751. /* Condition receive line interface for E1 after reset */
  752. __t1_framer_out(wc, 0xbb, 0x17);
  753. __t1_framer_out(wc, 0xbc, 0x55);
  754. __t1_framer_out(wc, 0xbb, 0x97);
  755. __t1_framer_out(wc, 0xbb, 0x11);
  756. __t1_framer_out(wc, 0xbc, 0xaa);
  757. __t1_framer_out(wc, 0xbb, 0x91);
  758. __t1_framer_out(wc, 0xbb, 0x12);
  759. __t1_framer_out(wc, 0xbc, 0x55);
  760. __t1_framer_out(wc, 0xbb, 0x92);
  761. __t1_framer_out(wc, 0xbb, 0x0c);
  762. __t1_framer_out(wc, 0xbb, 0x00);
  763. __t1_framer_out(wc, 0xbb, 0x8c);
  764. __t1_framer_out(wc, 0x3a, 0x20); /* LIM2: 50% peak amplitude is a "1" */
  765. __t1_framer_out(wc, 0x38, 0x0a); /* PCD: LOS after 176 consecutive "zeros" */
  766. __t1_framer_out(wc, 0x39, 0x15); /* PCR: 22 "ones" clear LOS */
  767. __t1_framer_out(wc, 0x20, 0x9f); /* XSW: Spare bits all to 1 */
  768. if (unchannelized)
  769. __t1_framer_out(wc, 0x21, 0x3c);
  770. else
  771. __t1_framer_out(wc, 0x21, 0x1c|cas); /* XSP: E-bit set when async. AXS auto, XSIF to 1 */
  772. /* Generate pulse mask for E1 */
  773. __t1_framer_out(wc, 0x26, 0x54); /* XPM0 */
  774. __t1_framer_out(wc, 0x27, 0x02); /* XPM1 */
  775. __t1_framer_out(wc, 0x28, 0x00); /* XPM2 */
  776. printk(KERN_INFO "TE110P: Span configured for %s/%s%s\n", framing, line, crc4);
  777. }
  778. static void t1xxp_framer_start(struct t1 *wc, struct dahdi_span *span)
  779. {
  780. int alreadyrunning = wc->span.flags & DAHDI_FLAG_RUNNING;
  781. unsigned long flags;
  782. spin_lock_irqsave(&wc->lock, flags);
  783. if (wc->spantype == TYPE_E1) { /* if this is an E1 card */
  784. __t1_configure_e1(wc, span->lineconfig);
  785. } else { /* is a T1 card */
  786. __t1_configure_t1(wc, span->lineconfig, span->txlevel);
  787. __t1xxp_set_clear(wc);
  788. }
  789. if (!alreadyrunning)
  790. wc->span.flags |= DAHDI_FLAG_RUNNING;
  791. spin_unlock_irqrestore(&wc->lock, flags);
  792. }
  793. static int t1xxp_startup(struct dahdi_span *span)
  794. {
  795. struct t1 *wc = t1_from_span(span);
  796. int i,alreadyrunning = span->flags & DAHDI_FLAG_RUNNING;
  797. /* initialize the start value for the entire chunk of last ec buffer */
  798. for(i = 0; i < span->channels; i++)
  799. {
  800. memset(wc->ec_chunk1[i],
  801. DAHDI_LIN2X(0,span->chans[i]),DAHDI_CHUNKSIZE);
  802. memset(wc->ec_chunk2[i],
  803. DAHDI_LIN2X(0,span->chans[i]),DAHDI_CHUNKSIZE);
  804. }
  805. /* Reset framer with proper parameters and start */
  806. t1xxp_framer_start(wc, span);
  807. printk(KERN_INFO "Calling startup (flags is %lu)\n", span->flags);
  808. if (!alreadyrunning) {
  809. /* Only if we're not already going */
  810. t1xxp_enable_interrupts(wc);
  811. t1xxp_start_dma(wc);
  812. span->flags |= DAHDI_FLAG_RUNNING;
  813. }
  814. return 0;
  815. }
  816. static int t1xxp_shutdown(struct dahdi_span *span)
  817. {
  818. struct t1 *wc = t1_from_span(span);
  819. unsigned long flags;
  820. spin_lock_irqsave(&wc->lock, flags);
  821. __t1xxp_stop_dma(wc);
  822. __t1xxp_disable_interrupts(wc);
  823. span->flags &= ~DAHDI_FLAG_RUNNING;
  824. spin_unlock_irqrestore(&wc->lock, flags);
  825. return 0;
  826. }
  827. static int t1xxp_chanconfig(struct dahdi_chan *chan, int sigtype)
  828. {
  829. struct t1 *wc = chan->pvt;
  830. unsigned long flags;
  831. int alreadyrunning = chan->span->flags & DAHDI_FLAG_RUNNING;
  832. spin_lock_irqsave(&wc->lock, flags);
  833. if (alreadyrunning && (wc->spantype != TYPE_E1))
  834. __t1xxp_set_clear(wc);
  835. spin_unlock_irqrestore(&wc->lock, flags);
  836. return 0;
  837. }
  838. static int t1xxp_spanconfig(struct dahdi_span *span, struct dahdi_lineconfig *lc)
  839. {
  840. struct t1 *wc = t1_from_span(span);
  841. /* Do we want to SYNC on receive or not */
  842. wc->sync = (lc->sync) ? 1 : 0;
  843. /* If already running, apply changes immediately */
  844. if (span->flags & DAHDI_FLAG_RUNNING)
  845. return t1xxp_startup(span);
  846. return 0;
  847. }
  848. static const struct dahdi_span_ops t1xxp_span_ops = {
  849. .owner = THIS_MODULE,
  850. .startup = t1xxp_startup,
  851. .shutdown = t1xxp_shutdown,
  852. .rbsbits = t1xxp_rbsbits,
  853. .maint = t1xxp_maint,
  854. .open = t1xxp_open,
  855. .close = t1xxp_close,
  856. .spanconfig = t1xxp_spanconfig,
  857. .chanconfig = t1xxp_chanconfig,
  858. .ioctl = t1xxp_ioctl,
  859. };
  860. static int t1xxp_software_init(struct t1 *wc)
  861. {
  862. int x;
  863. /* Find position */
  864. for (x=0;x<WC_MAX_CARDS;x++) {
  865. if (!cards[x]) {
  866. cards[x] = wc;
  867. break;
  868. }
  869. }
  870. if (x >= WC_MAX_CARDS)
  871. return -1;
  872. t4_serial_setup(wc);
  873. wc->num = x;
  874. sprintf(wc->span.name, "WCT1/%d", wc->num);
  875. snprintf(wc->span.desc, sizeof(wc->span.desc) - 1, "%s Card %d", wc->variety, wc->num);
  876. wc->span.manufacturer = "Digium";
  877. dahdi_copy_string(wc->span.devicetype, wc->variety, sizeof(wc->span.devicetype));
  878. snprintf(wc->span.location, sizeof(wc->span.location) - 1,
  879. "PCI Bus %02d Slot %02d", wc->dev->bus->number, PCI_SLOT(wc->dev->devfn) + 1);
  880. wc->span.irq = wc->dev->irq;
  881. if (wc->spantype == TYPE_E1) {
  882. if (unchannelized)
  883. wc->span.channels = 32;
  884. else
  885. wc->span.channels = 31;
  886. wc->span.deflaw = DAHDI_LAW_ALAW;
  887. wc->span.spantype = "E1";
  888. wc->span.linecompat = DAHDI_CONFIG_HDB3 | DAHDI_CONFIG_CCS | DAHDI_CONFIG_CRC4;
  889. } else {
  890. wc->span.channels = 24;
  891. wc->span.deflaw = DAHDI_LAW_MULAW;
  892. wc->span.spantype = "T1";
  893. wc->span.linecompat = DAHDI_CONFIG_AMI | DAHDI_CONFIG_B8ZS | DAHDI_CONFIG_D4 | DAHDI_CONFIG_ESF;
  894. }
  895. wc->span.chans = wc->chans;
  896. wc->span.flags = DAHDI_FLAG_RBS;
  897. init_waitqueue_head(&wc->span.maintq);
  898. for (x=0;x<wc->span.channels;x++) {
  899. sprintf(wc->chans[x]->name, "WCT1/%d/%d", wc->num, x + 1);
  900. wc->chans[x]->sigcap = DAHDI_SIG_EM | DAHDI_SIG_CLEAR | DAHDI_SIG_EM_E1 |
  901. DAHDI_SIG_FXSLS | DAHDI_SIG_FXSGS | DAHDI_SIG_MTP2 |
  902. DAHDI_SIG_FXSKS | DAHDI_SIG_FXOLS | DAHDI_SIG_DACS_RBS |
  903. DAHDI_SIG_FXOGS | DAHDI_SIG_FXOKS | DAHDI_SIG_CAS | DAHDI_SIG_SF;
  904. wc->chans[x]->pvt = wc;
  905. wc->chans[x]->chanpos = x + 1;
  906. }
  907. wc->span.ops = &t1xxp_span_ops;
  908. if (dahdi_register(&wc->span, 0)) {
  909. printk(KERN_NOTICE "Unable to register span with DAHDI\n");
  910. return -1;
  911. }
  912. return 0;
  913. }
  914. static inline void __handle_leds(struct t1 *wc)
  915. {
  916. int oldreg;
  917. if (wc->span.alarms & (DAHDI_ALARM_RED | DAHDI_ALARM_BLUE)) {
  918. /* Red/Blue alarm */
  919. wc->blinktimer++;
  920. #ifdef FANCY_ALARM
  921. if (wc->blinktimer == (altab[wc->alarmpos] >> 1)) {
  922. wc->ledtestreg = (wc->ledtestreg | BIT_LED1) & ~BIT_LED0;
  923. __control_set_reg(wc, WC_LEDTEST, wc->ledtestreg);
  924. }
  925. if (wc->blinktimer >= 0xf) {
  926. wc->ledtestreg = wc->ledtestreg & ~(BIT_LED0 | BIT_LED1);
  927. __control_set_reg(wc, WC_LEDTEST, wc->ledtestreg);
  928. wc->blinktimer = -1;
  929. wc->alarmpos++;
  930. if (wc->alarmpos >= (sizeof(altab) / sizeof(altab[0])))
  931. wc->alarmpos = 0;
  932. }
  933. #else
  934. if (wc->blinktimer == 160) {
  935. wc->ledtestreg = (wc->ledtestreg | BIT_LED1) & ~BIT_LED0;
  936. __control_set_reg(wc, WC_LEDTEST, wc->ledtestreg);
  937. } else if (wc->blinktimer == 480) {
  938. wc->ledtestreg = wc->ledtestreg & ~(BIT_LED0 | BIT_LED1);
  939. __control_set_reg(wc, WC_LEDTEST, wc->ledtestreg);
  940. wc->blinktimer = 0;
  941. }
  942. #endif
  943. } else if (wc->span.alarms & DAHDI_ALARM_YELLOW) {
  944. /* Yellow Alarm */
  945. if (!(wc->blinktimer % 2))
  946. wc->ledtestreg = (wc->ledtestreg | BIT_LED1) & ~BIT_LED0;
  947. else
  948. wc->ledtestreg = (wc->ledtestreg | BIT_LED0) & ~BIT_LED1;
  949. __control_set_reg(wc, WC_LEDTEST, wc->ledtestreg);
  950. } else {
  951. /* No Alarm */
  952. oldreg = wc->ledtestreg;
  953. if (wc->span.maintstat != DAHDI_MAINT_NONE)
  954. wc->ledtestreg |= BIT_TEST;
  955. else
  956. wc->ledtestreg &= ~BIT_TEST;
  957. if (wc->span.flags & DAHDI_FLAG_RUNNING)
  958. wc->ledtestreg = (wc->ledtestreg | BIT_LED0) & ~BIT_LED1;
  959. else
  960. wc->ledtestreg = wc->ledtestreg & ~(BIT_LED0 | BIT_LED1);
  961. if (oldreg != wc->ledtestreg)
  962. __control_set_reg(wc, WC_LEDTEST, wc->ledtestreg);
  963. }
  964. }
  965. static void t1xxp_transmitprep(struct t1 *wc, int ints)
  966. {
  967. volatile unsigned char *txbuf;
  968. int x,y;
  969. int pos;
  970. if (ints & 0x04 /* 0x01 */) {
  971. /* We just finished sending the first buffer, start filling it
  972. now */
  973. txbuf = wc->writechunk;
  974. } else {
  975. /* Just finished sending second buffer, fill it now */
  976. txbuf = wc->writechunk + 32 * DAHDI_CHUNKSIZE;
  977. }
  978. dahdi_transmit(&wc->span);
  979. for (x=0;x<wc->offset;x++)
  980. txbuf[x] = wc->tempo[x];
  981. for (y=0;y<DAHDI_CHUNKSIZE;y++) {
  982. for (x=0;x<wc->span.channels;x++) {
  983. pos = y * 32 + wc->chanmap[x] + wc->offset;
  984. /* Put channel number as outgoing data */
  985. if (pos < 32 * DAHDI_CHUNKSIZE)
  986. txbuf[pos] = wc->chans[x]->writechunk[y];
  987. else
  988. wc->tempo[pos - 32 * DAHDI_CHUNKSIZE] = wc->chans[x]->writechunk[y];
  989. }
  990. }
  991. }
  992. static void t1xxp_receiveprep(struct t1 *wc, int ints)
  993. {
  994. volatile unsigned char *rxbuf;
  995. volatile unsigned int *canary;
  996. int x;
  997. int y;
  998. unsigned int oldcan;
  999. if (ints & 0x04) {
  1000. /* Just received first buffer */
  1001. rxbuf = wc->readchunk;
  1002. canary = (unsigned int *)(wc->readchunk + DAHDI_CHUNKSIZE * 64 - 4);
  1003. } else {
  1004. rxbuf = wc->readchunk + DAHDI_CHUNKSIZE * 32;
  1005. canary = (unsigned int *)(wc->readchunk + DAHDI_CHUNKSIZE * 32 - 4);
  1006. }
  1007. oldcan = *canary;
  1008. if (((oldcan & 0xffff0000) >> 16) != CANARY) {
  1009. /* Check top part */
  1010. if (debug) printk(KERN_DEBUG "Expecting top %04x, got %04x\n", CANARY, (oldcan & 0xffff0000) >> 16);
  1011. wc->span.irqmisses++;
  1012. } else if ((oldcan & 0xffff) != ((wc->canary - 1) & 0xffff)) {
  1013. if (debug) printk(KERN_DEBUG "Expecting bottom %d, got %d\n", wc->canary - 1, oldcan & 0xffff);
  1014. wc->span.irqmisses++;
  1015. }
  1016. for (y=0;y<DAHDI_CHUNKSIZE;y++) {
  1017. for (x=0;x<wc->span.channels;x++) {
  1018. /* XXX Optimize, remove * and + XXX */
  1019. /* Must map received channels into appropriate data */
  1020. wc->chans[x]->readchunk[y] =
  1021. rxbuf[32 * y + ((wc->chanmap[x] + WC_OFFSET + wc->offset) & 0x1f)];
  1022. }
  1023. if (wc->spantype != TYPE_E1) {
  1024. for (x=3;x<32;x+=4) {
  1025. if (rxbuf[32 * y + ((x + WC_OFFSET) & 0x1f)] == 0x7f) {
  1026. if (wc->offset != (x-3)) {
  1027. /* Resync */
  1028. control_set_reg(wc, WC_CLOCK, 0x06 | wc->sync | clockextra);
  1029. wc->clocktimeout = 100;
  1030. #if 1
  1031. if (debug) printk(KERN_DEBUG "T1: Lost our place, resyncing\n");
  1032. #endif
  1033. }
  1034. }
  1035. }
  1036. } else if (!unchannelized) {
  1037. if (!wc->clocktimeout && !wc->span.alarms) {
  1038. if ((rxbuf[32 * y + ((3 + WC_OFFSET + wc->offset) & 0x1f)] & 0x7f) != 0x1b) {
  1039. if (wc->miss) {
  1040. if (debug) printk(KERN_DEBUG "Double miss (%d, %d)...\n", wc->misslast, rxbuf[32 * y + ((3 + WC_OFFSET + wc->offset) & 0x1f)]);
  1041. control_set_reg(wc, WC_CLOCK, 0x06 | wc->sync | clockextra);
  1042. wc->clocktimeout = 100;
  1043. } else {
  1044. wc->miss = 1;
  1045. wc->misslast = rxbuf[32 * y + ((3 + WC_OFFSET + wc->offset) & 0x1f)];
  1046. }
  1047. } else {
  1048. wc->miss = 0;
  1049. }
  1050. } else {
  1051. wc->miss = 0;
  1052. }
  1053. }
  1054. }
  1055. /* Store the next canary */
  1056. canary = (unsigned int *)(rxbuf + DAHDI_CHUNKSIZE * 32 - 4);
  1057. *canary = (wc->canary++) | (CANARY << 16);
  1058. for (x=0;x<wc->span.channels;x++) {
  1059. dahdi_ec_chunk(wc->chans[x], wc->chans[x]->readchunk, wc->ec_chunk2[x]);
  1060. memcpy(wc->ec_chunk2[x],wc->ec_chunk1[x],DAHDI_CHUNKSIZE);
  1061. memcpy(wc->ec_chunk1[x],wc->chans[x]->writechunk,DAHDI_CHUNKSIZE);
  1062. }
  1063. dahdi_receive(&wc->span);
  1064. }
  1065. static void t1_check_alarms(struct t1 *wc)
  1066. {
  1067. unsigned char c,d;
  1068. int alarms;
  1069. int x,j;
  1070. unsigned long flags;
  1071. if (!(wc->span.flags & DAHDI_FLAG_RUNNING))
  1072. return;
  1073. spin_lock_irqsave(&wc->lock, flags);
  1074. c = __t1_framer_in(wc, 0x4c);
  1075. if (wc->spanflags & FLAG_FALC12)
  1076. d = __t1_framer_in(wc, 0x4f);
  1077. else
  1078. d = __t1_framer_in(wc, 0x4d);
  1079. /* Assume no alarms */
  1080. alarms = 0;
  1081. /* And consider only carrier alarms */
  1082. wc->span.alarms &= (DAHDI_ALARM_RED | DAHDI_ALARM_BLUE | DAHDI_ALARM_NOTOPEN);
  1083. if (wc->spantype == TYPE_E1) {
  1084. if (c & 0x04) {
  1085. /* No multiframe found, force RAI high after 400ms only if
  1086. we haven't found a multiframe since last loss
  1087. of frame */
  1088. if (!(wc->spanflags & FLAG_NMF)) {
  1089. __t1_framer_out(wc, 0x20, 0x9f | 0x20); /* LIM0: Force RAI High */
  1090. wc->spanflags |= FLAG_NMF;
  1091. printk(KERN_DEBUG "NMF workaround on!\n");
  1092. }
  1093. __t1_framer_out(wc, 0x1e, 0xc3); /* Reset to CRC4 mode */
  1094. __t1_framer_out(wc, 0x1c, 0xf2); /* Force Resync */
  1095. __t1_framer_out(wc, 0x1c, 0xf0); /* Force Resync */
  1096. } else if (!(c & 0x02)) {
  1097. if ((wc->spanflags & FLAG_NMF)) {
  1098. __t1_framer_out(wc, 0x20, 0x9f); /* LIM0: Clear forced RAI */
  1099. wc->spanflags &= ~FLAG_NMF;
  1100. printk(KERN_DEBUG "NMF workaround off!\n");
  1101. }
  1102. }
  1103. } else {
  1104. /* Detect loopup code if we're not sending one */
  1105. if ((!wc->span.mainttimer) && (d & 0x08)) {
  1106. /* Loop-up code detected */
  1107. if ((wc->loopupcnt++ > 80) && (wc->span.maintstat != DAHDI_MAINT_REMOTELOOP)) {
  1108. __t1_framer_out(wc, 0x36, 0x08); /* LIM0: Disable any local loop */
  1109. __t1_framer_out(wc, 0x37, 0xf6 ); /* LIM1: Enable remote loop */
  1110. wc->span.maintstat = DAHDI_MAINT_REMOTELOOP;
  1111. }
  1112. } else
  1113. wc->loopupcnt = 0;
  1114. /* Same for loopdown code */
  1115. if ((!wc->span.mainttimer) && (d & 0x10)) {
  1116. /* Loop-down code detected */
  1117. if ((wc->loopdowncnt++ > 80) && (wc->span.maintstat == DAHDI_MAINT_REMOTELOOP)) {
  1118. __t1_framer_out(wc, 0x36, 0x08); /* LIM0: Disable any local loop */
  1119. __t1_framer_out(wc, 0x37, 0xf0 ); /* LIM1: Disable remote loop */
  1120. wc->span.maintstat = DAHDI_MAINT_NONE;
  1121. }
  1122. } else
  1123. wc->loopdowncnt = 0;
  1124. }
  1125. if (wc->span.lineconfig & DAHDI_CONFIG_NOTOPEN) {
  1126. for (x=0,j=0;x < wc->span.channels;x++)
  1127. if ((wc->span.chans[x]->flags & DAHDI_FLAG_OPEN) ||
  1128. (wc->span.chans[x]->flags & DAHDI_FLAG_NETDEV))
  1129. j++;
  1130. if (!j)
  1131. alarms |= DAHDI_ALARM_NOTOPEN;
  1132. }
  1133. if (c & 0xa0) {
  1134. if (wc->alarmcount >= alarmdebounce) {
  1135. if (!unchannelized)
  1136. alarms |= DAHDI_ALARM_RED;
  1137. } else
  1138. wc->alarmcount++;
  1139. } else
  1140. wc->alarmcount = 0;
  1141. if (c & 0x4)
  1142. alarms |= DAHDI_ALARM_BLUE;
  1143. if (((!wc->span.alarms) && alarms) ||
  1144. (wc->span.alarms && (!alarms)))
  1145. wc->checktiming = 1;
  1146. /* Keep track of recovering */
  1147. if ((!alarms) && wc->span.alarms)
  1148. wc->alarmtimer = DAHDI_ALARMSETTLE_TIME;
  1149. if (wc->alarmtimer)
  1150. alarms |= DAHDI_ALARM_RECOVER;
  1151. /* If receiving alarms, go into Yellow alarm state */
  1152. if (alarms && !(wc->spanflags & FLAG_SENDINGYELLOW)) {
  1153. unsigned char fmr4;
  1154. #if 1
  1155. printk(KERN_INFO "wcte1xxp: Setting yellow alarm\n");
  1156. #endif
  1157. /* We manually do yellow alarm to handle RECOVER and NOTOPEN, otherwise it's auto anyway */
  1158. fmr4 = __t1_framer_in(wc, 0x20);
  1159. __t1_framer_out(wc, 0x20, fmr4 | 0x20);
  1160. wc->spanflags |= FLAG_SENDINGYELLOW;
  1161. } else if ((!alarms) && (wc->spanflags & FLAG_SENDINGYELLOW)) {
  1162. unsigned char fmr4;
  1163. #if 1
  1164. printk(KERN_INFO "wcte1xxp: Clearing yellow alarm\n");
  1165. #endif
  1166. /* We manually do yellow alarm to handle RECOVER */
  1167. fmr4 = __t1_framer_in(wc, 0x20);
  1168. __t1_framer_out(wc, 0x20, fmr4 & ~0x20);
  1169. wc->spanflags &= ~FLAG_SENDINGYELLOW;
  1170. }
  1171. /* Re-check the timing source when we enter/leave alarm, not withstanding
  1172. yellow alarm */
  1173. if ((c & 0x10) && !unchannelized)
  1174. alarms |= DAHDI_ALARM_YELLOW;
  1175. if (wc->span.mainttimer || wc->span.maintstat)
  1176. alarms |= DAHDI_ALARM_LOOPBACK;
  1177. wc->span.alarms = alarms;
  1178. spin_unlock_irqrestore(&wc->lock, flags);
  1179. dahdi_alarm_notify(&wc->span);
  1180. }
  1181. static void t1_do_counters(struct t1 *wc)
  1182. {
  1183. unsigned long flags;
  1184. spin_lock_irqsave(&wc->lock, flags);
  1185. if (wc->alarmtimer) {
  1186. if (!--wc->alarmtimer) {
  1187. wc->span.alarms &= ~(DAHDI_ALARM_RECOVER);
  1188. spin_unlock_irqrestore(&wc->lock, flags);
  1189. dahdi_alarm_notify(&wc->span);
  1190. spin_lock_irqsave(&wc->lock, flags);
  1191. }
  1192. }
  1193. spin_unlock_irqrestore(&wc->lock, flags);
  1194. }
  1195. DAHDI_IRQ_HANDLER(t1xxp_interrupt)
  1196. {
  1197. struct t1 *wc = dev_id;
  1198. unsigned char ints;
  1199. unsigned long flags;
  1200. int x;
  1201. ints = inb(wc->ioaddr + WC_INTSTAT);
  1202. if (!ints)
  1203. return IRQ_NONE;
  1204. outb(ints, wc->ioaddr + WC_INTSTAT);
  1205. if (!wc->intcount) {
  1206. if (debug) printk(KERN_DEBUG "Got interrupt: 0x%04x\n", ints);
  1207. }
  1208. wc->intcount++;
  1209. if (wc->clocktimeout && !--wc->clocktimeout)
  1210. control_set_reg(wc, WC_CLOCK, 0x04 | wc->sync | clockextra);
  1211. if (ints & 0x0f) {
  1212. t1xxp_receiveprep(wc, ints);
  1213. t1xxp_transmitprep(wc, ints);
  1214. }
  1215. spin_lock_irqsave(&wc->lock, flags);
  1216. #if 1
  1217. __handle_leds(wc);
  1218. #endif
  1219. spin_unlock_irqrestore(&wc->lock, flags);
  1220. /* Count down timers */
  1221. t1_do_counters(wc);
  1222. /* Do some things that we don't have to do very often */
  1223. x = wc->intcount & 15 /* 63 */;
  1224. switch(x) {
  1225. case 0:
  1226. case 1:
  1227. break;
  1228. case 2:
  1229. t1_check_sigbits(wc);
  1230. break;
  1231. case 4:
  1232. /* Check alarms 1/4 as frequently */
  1233. if (!(wc->intcount & 0x30))
  1234. t1_check_alarms(wc);
  1235. break;
  1236. }
  1237. if (ints & 0x10)
  1238. printk(KERN_NOTICE "PCI Master abort\n");
  1239. if (ints & 0x20)
  1240. printk(KERN_NOTICE "PCI Target abort\n");
  1241. return IRQ_RETVAL(1);
  1242. }
  1243. static int t1xxp_hardware_init(struct t1 *wc)
  1244. {
  1245. unsigned int falcver;
  1246. unsigned int x;
  1247. /* Hardware PCI stuff */
  1248. /* Reset chip and registers */
  1249. outb(DELAY | 0x0e, wc->ioaddr + WC_CNTL);
  1250. /* Set all outputs to 0 */
  1251. outb(0x00, wc->ioaddr + WC_AUXD);
  1252. /* Set all to outputs except AUX1 (TDO). */
  1253. outb(0xfd, wc->ioaddr + WC_AUXC);
  1254. /* Configure the serial port: double clock, 20ns width, no inversion,
  1255. MSB first */
  1256. outb(0xc8, wc->ioaddr + WC_SERC);
  1257. /* Internally delay FSC by one */
  1258. outb(0x01, wc->ioaddr + WC_FSCDELAY);
  1259. /* Back to normal, with automatic DMA wrap around */
  1260. outb(DELAY | 0x01, wc->ioaddr + WC_CNTL);
  1261. /* Make sure serial port and DMA are out of reset */
  1262. outb(inb(wc->ioaddr + WC_CNTL) & 0xf9, WC_CNTL);
  1263. /* Setup DMA Addresses */
  1264. /* Start at writedma */
  1265. outl(wc->writedma, wc->ioaddr + WC_DMAWS); /* Write start */
  1266. /* First frame */
  1267. outl(wc->writedma + DAHDI_CHUNKSIZE * 32 - 4, wc->ioaddr + WC_DMAWI); /* Middle (interrupt) */
  1268. /* Second frame */
  1269. outl(wc->writedma + DAHDI_CHUNKSIZE * 32 * 2 - 4, wc->ioaddr + WC_DMAWE); /* End */
  1270. outl(wc->readdma, wc->ioaddr + WC_DMARS); /* Read start */
  1271. /* First frame */
  1272. outl(wc->readdma + DAHDI_CHUNKSIZE * 32 - 4, wc->ioaddr + WC_DMARI); /* Middle (interrupt) */
  1273. /* Second frame */
  1274. outl(wc->readdma + DAHDI_CHUNKSIZE * 32 * 2 - 4, wc->ioaddr + WC_DMARE); /* End */
  1275. if (debug) printk(KERN_DEBUG "Setting up DMA (write/read = %08lx/%08lx)\n", (long)wc->writedma, (long)wc->readdma);
  1276. if (t1e1override > -1) {
  1277. if (t1e1override)
  1278. wc->spantype = TYPE_E1;
  1279. else
  1280. wc->spantype = TYPE_T1;
  1281. } else {
  1282. if (control_get_reg(wc, WC_CLOCK) & 0x20)
  1283. wc->spantype = TYPE_T1;
  1284. else
  1285. wc->spantype = TYPE_E1;
  1286. }
  1287. /* Check out the controller */
  1288. if (debug) printk(KERN_DEBUG "Controller version: %02x\n", control_get_reg(wc, WC_VERSION));
  1289. control_set_reg(wc, WC_LEDTEST, 0x00);
  1290. if (wc->spantype == TYPE_E1) {
  1291. if (unchannelized)
  1292. wc->chanmap = chanmap_e1uc;
  1293. else
  1294. wc->chanmap = chanmap_e1;
  1295. } else
  1296. wc->chanmap = chanmap_t1;
  1297. /* Setup clock appropriately */
  1298. control_set_reg(wc, WC_CLOCK, 0x06 | wc->sync | clockextra);
  1299. wc->clocktimeout = 100;
  1300. /* Perform register test on FALC */
  1301. for (x=0;x<256;x++) {
  1302. t1_framer_out(wc, 0x14, x);
  1303. if ((falcver = t1_framer_in(wc, 0x14)) != x)
  1304. printk(KERN_DEBUG "Wrote '%x' but read '%x'\n", x, falcver);
  1305. }
  1306. t1_framer_out(wc, 0x4a, 0xaa);
  1307. falcver = t1_framer_in(wc ,0x4a);
  1308. printk(KERN_INFO "FALC version: %08x\n", falcver);
  1309. if (!falcver)
  1310. wc->spanflags |= FLAG_FALC12;
  1311. start_alarm(wc);
  1312. return 0;
  1313. }
  1314. static int __devinit t1xxp_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  1315. {
  1316. struct t1 *wc;
  1317. unsigned int *canary;
  1318. unsigned int x;
  1319. if (pci_enable_device(pdev)) {
  1320. return -EIO;
  1321. }
  1322. if (!(wc = kmalloc(sizeof(*wc), GFP_KERNEL))) {
  1323. return -ENOMEM;
  1324. }
  1325. memset(wc, 0x0, sizeof(*wc));
  1326. spin_lock_init(&wc->lock);
  1327. wc->ioaddr = pci_resource_start(pdev, 0);
  1328. wc->dev = pdev;
  1329. wc->offset = 28; /* And you thought 42 was the answer */
  1330. wc->writechunk =
  1331. /* 32 channels, Double-buffer, Read/Write */
  1332. (unsigned char *)pci_alloc_consistent(pdev, DAHDI_MAX_CHUNKSIZE * 32 * 2 * 2, &wc->writedma);
  1333. if (!wc->writechunk) {
  1334. printk(KERN_NOTICE "wcte11xp: Unable to allocate DMA-able memory\n");
  1335. return -ENOMEM;
  1336. }
  1337. /* Read is after the whole write piece (in bytes) */
  1338. wc->readchunk = wc->writechunk + DAHDI_CHUNKSIZE * 32 * 2;
  1339. /* Same thing... */
  1340. wc->readdma = wc->writedma + DAHDI_CHUNKSIZE * 32 * 2;
  1341. /* Initialize Write/Buffers to all blank data */
  1342. memset((void *)wc->writechunk,0x00,DAHDI_MAX_CHUNKSIZE * 2 * 2 * 32);
  1343. /* Initialize canary */
  1344. canary = (unsigned int *)(wc->readchunk + DAHDI_CHUNKSIZE * 64 - 4);
  1345. *canary = (CANARY << 16) | (0xffff);
  1346. /* Enable bus mastering */
  1347. pci_set_master(pdev);
  1348. /* Keep track of which device we are */
  1349. pci_set_drvdata(pdev, wc);
  1350. if (request_irq(pdev->irq, t1xxp_interrupt, DAHDI_IRQ_SHARED_DISABLED, "wcte11xp", wc)) {
  1351. printk(KERN_NOTICE "wcte11xp: Unable to request IRQ %d\n", pdev->irq);
  1352. kfree(wc);
  1353. return -EIO;
  1354. }
  1355. /* Initialize hardware */
  1356. t1xxp_hardware_init(wc);
  1357. /* We now know which version of card we have */
  1358. wc->variety = "Digium Wildcard TE110P T1/E1";
  1359. for (x = 0; x < (wc->spantype == TYPE_E1 ? 31 : 24); x++) {
  1360. if (!(wc->chans[x] = kmalloc(sizeof(*wc->chans[x]), GFP_KERNEL))) {
  1361. while (x) {
  1362. kfree(wc->chans[--x]);
  1363. }
  1364. kfree(wc);
  1365. return -ENOMEM;
  1366. }
  1367. memset(wc->chans[x], 0, sizeof(*wc->chans[x]));
  1368. }
  1369. /* Misc. software stuff */
  1370. t1xxp_software_init(wc);
  1371. printk(KERN_INFO "Found a Wildcard: %s\n", wc->variety);
  1372. return 0;
  1373. }
  1374. static void t1xxp_stop_stuff(struct t1 *wc)
  1375. {
  1376. /* Kill clock */
  1377. control_set_reg(wc, WC_CLOCK, 0);
  1378. /* Turn off LED's */
  1379. control_set_reg(wc, WC_LEDTEST, 0);
  1380. }
  1381. static void __devexit t1xxp_remove_one(struct pci_dev *pdev)
  1382. {
  1383. struct t1 *wc = pci_get_drvdata(pdev);
  1384. if (wc) {
  1385. /* Stop any DMA */
  1386. __t1xxp_stop_dma(wc);
  1387. /* In case hardware is still there */
  1388. __t1xxp_disable_interrupts(wc);
  1389. t1xxp_stop_stuff(wc);
  1390. /* Immediately free resources */
  1391. pci_free_consistent(pdev, DAHDI_MAX_CHUNKSIZE * 2 * 2 * 32 * 4, (void *)wc->writechunk, wc->writedma);
  1392. free_irq(pdev->irq, wc);
  1393. /* Reset PCI chip and registers */
  1394. outb(DELAY | 0x0e, wc->ioaddr + WC_CNTL);
  1395. /* Release span, possibly delayed */
  1396. if (!wc->usecount)
  1397. t1xxp_release(wc);
  1398. else
  1399. wc->dead = 1;
  1400. }
  1401. }
  1402. static DEFINE_PCI_DEVICE_TABLE(t1xxp_pci_tbl) = {
  1403. { 0xe159, 0x0001, 0x71fe, PCI_ANY_ID, 0, 0, (unsigned long) "Digium Wildcard TE110P T1/E1 Board" },
  1404. { 0xe159, 0x0001, 0x79fe, PCI_ANY_ID, 0, 0, (unsigned long) "Digium Wildcard TE110P T1/E1 Board" },
  1405. { 0xe159, 0x0001, 0x795e, PCI_ANY_ID, 0, 0, (unsigned long) "Digium Wildcard TE110P T1/E1 Board" },
  1406. { 0xe159, 0x0001, 0x79de, PCI_ANY_ID, 0, 0, (unsigned long) "Digium Wildcard TE110P T1/E1 Board" },
  1407. { 0xe159, 0x0001, 0x797e, PCI_ANY_ID, 0, 0, (unsigned long) "Digium Wildcard TE110P T1/E1 Board" },
  1408. { 0 }
  1409. };
  1410. MODULE_DEVICE_TABLE(pci,t1xxp_pci_tbl);
  1411. static struct pci_driver t1xxp_driver = {
  1412. .name = "wcte11xp",
  1413. .probe = t1xxp_init_one,
  1414. .remove = __devexit_p(t1xxp_remove_one),
  1415. .suspend = NULL,
  1416. .resume = NULL,
  1417. .id_table = t1xxp_pci_tbl,
  1418. };
  1419. static int __init t1xxp_init(void)
  1420. {
  1421. int res;
  1422. res = dahdi_pci_module(&t1xxp_driver);
  1423. if (res)
  1424. return -ENODEV;
  1425. return 0;
  1426. }
  1427. static void __exit t1xxp_cleanup(void)
  1428. {
  1429. pci_unregister_driver(&t1xxp_driver);
  1430. }
  1431. module_param(alarmdebounce, int, 0600);
  1432. module_param(loopback, int, 0600);
  1433. module_param(t1e1override, int, 0600);
  1434. module_param(unchannelized, int, 0600);
  1435. module_param(clockextra, int, 0600);
  1436. module_param(debug, int, 0600);
  1437. module_param(j1mode, int, 0600);
  1438. MODULE_DESCRIPTION("Wildcard TE110P Driver");
  1439. MODULE_AUTHOR("Mark Spencer <markster@digium.com>");
  1440. MODULE_LICENSE("GPL v2");
  1441. module_init(t1xxp_init);
  1442. module_exit(t1xxp_cleanup);