1 | /* $ZEL: sis1100_init_remote.c,v 1.7 2004/05/27 23:10:21 wuestner Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * Copyright (c) 2001-2004
|
---|
5 | * Matthias Drochner, Peter Wuestner. All rights reserved.
|
---|
6 | *
|
---|
7 | * Redistribution and use in source and binary forms, with or without
|
---|
8 | * modification, are permitted provided that the following conditions
|
---|
9 | * are met:
|
---|
10 | * 1. Redistributions of source code must retain the above copyright
|
---|
11 | * notice, this list of conditions, and the following disclaimer.
|
---|
12 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
13 | * notice, this list of conditions and the following disclaimer in the
|
---|
14 | * documentation and/or other materials provided with the distribution.
|
---|
15 | *
|
---|
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
|
---|
17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
---|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
---|
20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
---|
22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
---|
23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
---|
24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
---|
25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
26 | * SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | #include "sis1100_sc.h"
|
---|
30 |
|
---|
31 | static char* rnames[]= {
|
---|
32 | "PCI",
|
---|
33 | "VME",
|
---|
34 | "CAMAC",
|
---|
35 | "f1",
|
---|
36 | "VERTEX",
|
---|
37 | };
|
---|
38 |
|
---|
39 | void
|
---|
40 | sis1100_init_remote(struct sis1100_softc* sc)
|
---|
41 | {
|
---|
42 | u_int32_t ident, error, balance, typ, hv, fk, fv;
|
---|
43 | int res;
|
---|
44 |
|
---|
45 | SEM_LOCK(sc->sem_hw);
|
---|
46 |
|
---|
47 | /*sis1100writereg(sc, cr, cr_rem_reset);*/ /* reset remote */
|
---|
48 | if (sis1100_flush_fifo(sc, "init_remote" , 0)) return; /* clear local fifo */
|
---|
49 | sis1100writereg(sc, p_balance, 0);
|
---|
50 | sis1100readreg(sc, prot_error);
|
---|
51 |
|
---|
52 | ident=plxreadlocal0(sc, 0x800);
|
---|
53 | error=sis1100readreg(sc, prot_error);
|
---|
54 | balance=sis1100readreg(sc, p_balance);
|
---|
55 | SEM_UNLOCK(sc->sem_hw);
|
---|
56 |
|
---|
57 | if (error || balance) {
|
---|
58 | pERROR(sc, "error reading remote ident");
|
---|
59 | pERROR(sc, "error=0x%x balance=%d", error, balance);
|
---|
60 | sis1100_flush_fifo(sc, "after reading ident" , 0); /* clear local fifo */
|
---|
61 | /*sis1100_dump_glink_status(sc, "init remote");*/
|
---|
62 | return;
|
---|
63 | }
|
---|
64 |
|
---|
65 | typ=ident&0xff;
|
---|
66 | hv=(ident>>8)&0xff;
|
---|
67 | fk=(ident>>16)&0xff;
|
---|
68 | fv=(ident>>24)&0xff;
|
---|
69 | pINFO(sc, "remote ident: 0x%08x", ident);
|
---|
70 | if ((typ>0) && (typ<=sizeof(rnames)/sizeof(char*)))
|
---|
71 | pINFO(sc, "remote is %s", rnames[typ-1]);
|
---|
72 | else
|
---|
73 | pERROR(sc, "unknown remote type %d", ident&0xff);
|
---|
74 | pINFO(sc, "remote HW_ver %d FW_code %d FW_ver %d", hv, fk, fv);
|
---|
75 | sc->remote_ident=ident;
|
---|
76 |
|
---|
77 | /* swapping is undefind here; it even would depend on arbitrary user settings */
|
---|
78 | switch (typ) {
|
---|
79 | case sis1100_hw_pci: /* PCI */
|
---|
80 | res=sis1100rem_init(sc);
|
---|
81 | sc->remote_endian=1; /* big endian; the remote side has to swap */
|
---|
82 | break;
|
---|
83 | case sis1100_hw_vme: /* VME */
|
---|
84 | res=sis3100rem_init(sc);
|
---|
85 | sc->remote_endian=1; /* big endian */
|
---|
86 | break;
|
---|
87 | case sis1100_hw_camac: /* CAMAC */
|
---|
88 | res=sis5100rem_init(sc);
|
---|
89 | sc->remote_endian=1; /* CAMAC is not yet known */
|
---|
90 | break;
|
---|
91 | case sis1100_hw_f1: /* (ACAM TDC-F1) */
|
---|
92 | res=f1_rem_init(sc);
|
---|
93 | sc->remote_endian=0; /* Willi always uses little endian */
|
---|
94 | break;
|
---|
95 | case sis1100_hw_vertex: /* VERTEX (COSY-ANKE) */
|
---|
96 | res=vertex_rem_init(sc);
|
---|
97 | sc->remote_endian=0; /* Willi always uses little endian */
|
---|
98 | break;
|
---|
99 | default:
|
---|
100 | pINFO(sc, "remote device type not (yet) supported.");
|
---|
101 | sc->remote_endian=1; /* just a default */
|
---|
102 | res=-1;
|
---|
103 | break;
|
---|
104 | }
|
---|
105 | if (res) return;
|
---|
106 | sis1100_update_swapping(sc, "init_remote");
|
---|
107 |
|
---|
108 | sc->old_remote_hw=sc->remote_hw;
|
---|
109 | sc->remote_hw=typ;
|
---|
110 | }
|
---|