1 | /* $ZEL: sis3100rem_init.c,v 1.3 2004/05/27 23:10:44 wuestner Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * Copyright (c) 2001-2004
|
---|
5 | * 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 int
|
---|
32 | sis3100_dsp_present(struct sis1100_softc* sc)
|
---|
33 | {
|
---|
34 | u_int32_t dsp_sc;
|
---|
35 | int res;
|
---|
36 |
|
---|
37 | res=sis3100readremreg(sc, dsp_sc, &dsp_sc, 0);
|
---|
38 | if (res) {
|
---|
39 | pINFO(sc, "3100: read dsp_sc: res=%d", res);
|
---|
40 | return 0;
|
---|
41 | }
|
---|
42 | return !!(dsp_sc&sis3100_dsp_available);
|
---|
43 | }
|
---|
44 |
|
---|
45 | int
|
---|
46 | sis3100_get_timeouts(struct sis1100_softc* sc, int* berr, int* arb)
|
---|
47 | {
|
---|
48 | u_int32_t stat, error;
|
---|
49 | int berr_timer, long_timer, berr_time, long_time;
|
---|
50 |
|
---|
51 | error=sis3100readremreg(sc, vme_master_sc, &stat, 0);
|
---|
52 | if (error) return error;
|
---|
53 |
|
---|
54 | berr_timer=(stat>>14)&3;
|
---|
55 | long_timer=(stat>>12)&3;
|
---|
56 | berr_time=0;
|
---|
57 | long_time=0;
|
---|
58 | switch (berr_timer) {
|
---|
59 | case 0: berr_time=1250; break;
|
---|
60 | case 1: berr_time=6250; break;
|
---|
61 | case 2: berr_time=12500; break;
|
---|
62 | case 3: berr_time=100000; break;
|
---|
63 | }
|
---|
64 | switch (long_timer) {
|
---|
65 | case 0: long_time= 1; break;
|
---|
66 | case 1: long_time= 10; break;
|
---|
67 | case 2: long_time= 50; break;
|
---|
68 | case 3: long_time=100; break;
|
---|
69 | }
|
---|
70 | *berr=berr_time;
|
---|
71 | *arb=long_time;
|
---|
72 | return 0;
|
---|
73 | }
|
---|
74 |
|
---|
75 | static void
|
---|
76 | sis3100_dump_timeouts(struct sis1100_softc* sc)
|
---|
77 | {
|
---|
78 | int berr_time, long_time;
|
---|
79 |
|
---|
80 | sis3100_get_timeouts(sc, &berr_time, &long_time);
|
---|
81 | pINFO(sc, "3100: berr_time=%d ns", berr_time);
|
---|
82 | pINFO(sc, "3100: long_time=%d ms", long_time);
|
---|
83 | }
|
---|
84 |
|
---|
85 | int
|
---|
86 | sis3100_set_timeouts(struct sis1100_softc* sc, int berr, int arb)
|
---|
87 | /* berr in terms of 10**-9 s */
|
---|
88 | /* arb in terms of 10**-3 s */
|
---|
89 | {
|
---|
90 | int berr_timer, long_timer;
|
---|
91 | u_int32_t bits;
|
---|
92 |
|
---|
93 | if (berr>12500)
|
---|
94 | berr_timer=3;
|
---|
95 | else if (berr>6250)
|
---|
96 | berr_timer=2;
|
---|
97 | else if (berr>1250)
|
---|
98 | berr_timer=1;
|
---|
99 | else
|
---|
100 | berr_timer=0;
|
---|
101 |
|
---|
102 | if (arb>50)
|
---|
103 | long_timer=3;
|
---|
104 | else if (arb>10)
|
---|
105 | long_timer=2;
|
---|
106 | else if (arb>1)
|
---|
107 | long_timer=1;
|
---|
108 | else
|
---|
109 | long_timer=0;
|
---|
110 |
|
---|
111 | bits=(long_timer|(berr_timer<<2))<<12;
|
---|
112 | bits|=(~bits<<16)&0xf0000000;
|
---|
113 | return sis3100writeremreg(sc, vme_master_sc, bits, 0);
|
---|
114 | }
|
---|
115 |
|
---|
116 | int
|
---|
117 | sis3100rem_init(struct sis1100_softc* sc)
|
---|
118 | {
|
---|
119 | #define MIN_FV 3
|
---|
120 | #define MAX_FV 6
|
---|
121 | u_int32_t hv, fk, fv, stat;
|
---|
122 |
|
---|
123 | hv=(sc->remote_ident>>8)&0xff;
|
---|
124 | fk=(sc->remote_ident>>16)&0xff;
|
---|
125 | fv=(sc->remote_ident>>24)&0xff;
|
---|
126 |
|
---|
127 | switch (sc->remote_ident&0x00ffff00) {
|
---|
128 | case 0x00010100:
|
---|
129 | if (fv<MIN_FV) {
|
---|
130 | pERROR(sc, "3100: remote firmware version too old;"
|
---|
131 | " at least version %d is required.",
|
---|
132 | MIN_FV);
|
---|
133 | return -1;
|
---|
134 | }
|
---|
135 | if (fv>MAX_FV) {
|
---|
136 | pINFO(sc, "3100: Driver not tested with"
|
---|
137 | " remote firmware versions greater than %d.",
|
---|
138 | MAX_FV);
|
---|
139 | }
|
---|
140 | break;
|
---|
141 | default:
|
---|
142 | pERROR(sc, "3100: remote hw/fw type not supported");
|
---|
143 | return -1;
|
---|
144 | }
|
---|
145 |
|
---|
146 | if (sis1100_init_sdram(sc)<0)
|
---|
147 | return -1;
|
---|
148 | pINFO(sc, "3100: size of SDRAM: 0x%llx (%lld MByte)",
|
---|
149 | sc->ram_size, sc->ram_size>>20);
|
---|
150 |
|
---|
151 | sc->dsp_present=sis3100_dsp_present(sc);
|
---|
152 | pINFO(sc, "3100: DSP is %spresent", sc->dsp_present?"":"not ");
|
---|
153 |
|
---|
154 | SEM_LOCK(sc->sem_hw);
|
---|
155 | sis3100writeremreg(sc, vme_irq_sc, 0x00fe0001, 1); /* disable VME IRQs */
|
---|
156 | sis3100readremreg(sc, vme_master_sc, &stat, 1);
|
---|
157 | SEM_UNLOCK(sc->sem_hw);
|
---|
158 | pINFO(sc, "3100: remote stat=0x%08x", stat);
|
---|
159 | if (!(stat&vme_system_controller)) {
|
---|
160 | pINFO(sc, "3100: System Controller NOT enabled!");
|
---|
161 | }
|
---|
162 | sis3100_set_timeouts(sc, 5000, 10);
|
---|
163 | sis3100_dump_timeouts(sc);
|
---|
164 |
|
---|
165 | return 0;
|
---|
166 | }
|
---|