Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* $Id: timer.c,v 1.3.6.1 2001/09/23 22:24:59 kai Exp $ |
| 2 | * |
| 3 | * Copyright (C) 1996 SpellCaster Telecommunications Inc. |
| 4 | * |
| 5 | * This software may be used and distributed according to the terms |
| 6 | * of the GNU General Public License, incorporated herein by reference. |
| 7 | * |
| 8 | * For more information, please contact gpl-info@spellcast.com or write: |
| 9 | * |
| 10 | * SpellCaster Telecommunications Inc. |
| 11 | * 5621 Finch Avenue East, Unit #3 |
| 12 | * Scarborough, Ontario Canada |
| 13 | * M1B 2T9 |
| 14 | * +1 (416) 297-8565 |
| 15 | * +1 (416) 297-6433 Facsimile |
| 16 | */ |
| 17 | |
| 18 | #include "includes.h" |
| 19 | #include "hardware.h" |
| 20 | #include "message.h" |
| 21 | #include "card.h" |
| 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
| 24 | /* |
| 25 | * Write the proper values into the I/O ports following a reset |
| 26 | */ |
Adrian Bunk | e3ca5e7 | 2005-06-25 14:58:34 -0700 | [diff] [blame] | 27 | static void setup_ports(int card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | { |
| 29 | |
| 30 | outb((sc_adapter[card]->rambase >> 12), sc_adapter[card]->ioport[EXP_BASE]); |
| 31 | |
| 32 | /* And the IRQ */ |
| 33 | outb((sc_adapter[card]->interrupt | 0x80), |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 34 | sc_adapter[card]->ioport[IRQ_SELECT]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | /* |
| 38 | * Timed function to check the status of a previous reset |
| 39 | * Must be very fast as this function runs in the context of |
| 40 | * an interrupt handler. |
| 41 | * |
| 42 | * Setup the ioports for the board that were cleared by the reset. |
| 43 | * Then, check to see if the signate has been set. Next, set the |
| 44 | * signature to a known value and issue a startproc if needed. |
| 45 | */ |
Alexey Dobriyan | e3aded3 | 2007-07-19 01:49:10 -0700 | [diff] [blame] | 46 | void sc_check_reset(unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | { |
| 48 | unsigned long flags; |
| 49 | unsigned long sig; |
| 50 | int card = (unsigned int) data; |
| 51 | |
| 52 | pr_debug("%s: check_timer timer called\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 53 | sc_adapter[card]->devicename); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | /* Setup the io ports */ |
| 56 | setup_ports(card); |
| 57 | |
| 58 | spin_lock_irqsave(&sc_adapter[card]->lock, flags); |
| 59 | outb(sc_adapter[card]->ioport[sc_adapter[card]->shmem_pgport], |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 60 | (sc_adapter[card]->shmem_magic >> 14) | 0x80); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | sig = (unsigned long) *((unsigned long *)(sc_adapter[card]->rambase + SIG_OFFSET)); |
| 62 | |
| 63 | /* check the signature */ |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 64 | if (sig == SIGNATURE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | flushreadfifo(card); |
| 66 | spin_unlock_irqrestore(&sc_adapter[card]->lock, flags); |
| 67 | /* See if we need to do a startproc */ |
| 68 | if (sc_adapter[card]->StartOnReset) |
| 69 | startproc(card); |
| 70 | } else { |
Andrew Morton | 3879b6b | 2006-10-03 01:16:15 -0700 | [diff] [blame] | 71 | pr_debug("%s: No signature yet, waiting another %lu jiffies.\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 72 | sc_adapter[card]->devicename, CHECKRESET_TIME); |
| 73 | mod_timer(&sc_adapter[card]->reset_timer, jiffies + CHECKRESET_TIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | spin_unlock_irqrestore(&sc_adapter[card]->lock, flags); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | /* |
| 79 | * Timed function to check the status of a previous reset |
| 80 | * Must be very fast as this function runs in the context of |
| 81 | * an interrupt handler. |
| 82 | * |
| 83 | * Send check sc_adapter->phystat to see if the channels are up |
| 84 | * If they are, tell ISDN4Linux that the board is up. If not, |
| 85 | * tell IADN4Linux that it is up. Always reset the timer to |
| 86 | * fire again (endless loop). |
| 87 | */ |
| 88 | void check_phystat(unsigned long data) |
| 89 | { |
| 90 | unsigned long flags; |
| 91 | int card = (unsigned int) data; |
| 92 | |
| 93 | pr_debug("%s: Checking status...\n", sc_adapter[card]->devicename); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 94 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | * check the results of the last PhyStat and change only if |
| 96 | * has changed drastically |
| 97 | */ |
| 98 | if (sc_adapter[card]->nphystat && !sc_adapter[card]->phystat) { /* All is well */ |
| 99 | pr_debug("PhyStat transition to RUN\n"); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 100 | pr_info("%s: Switch contacted, transmitter enabled\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | sc_adapter[card]->devicename); |
| 102 | indicate_status(card, ISDN_STAT_RUN, 0, NULL); |
| 103 | } |
| 104 | else if (!sc_adapter[card]->nphystat && sc_adapter[card]->phystat) { /* All is not well */ |
| 105 | pr_debug("PhyStat transition to STOP\n"); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 106 | pr_info("%s: Switch connection lost, transmitter disabled\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | sc_adapter[card]->devicename); |
| 108 | |
| 109 | indicate_status(card, ISDN_STAT_STOP, 0, NULL); |
| 110 | } |
| 111 | |
| 112 | sc_adapter[card]->phystat = sc_adapter[card]->nphystat; |
| 113 | |
| 114 | /* Reinitialize the timer */ |
| 115 | spin_lock_irqsave(&sc_adapter[card]->lock, flags); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 116 | mod_timer(&sc_adapter[card]->stat_timer, jiffies + CHECKSTAT_TIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | spin_unlock_irqrestore(&sc_adapter[card]->lock, flags); |
| 118 | |
| 119 | /* Send a new cePhyStatus message */ |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 120 | sendmessage(card, CEPID, ceReqTypePhy, ceReqClass2, |
| 121 | ceReqPhyStatus, 0, 0, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | } |