source: drsdaq/VME/struck/sis1100/V2.02/dev/pci/#sis1100_init_sdram.c#@ 23

Last change on this file since 23 was 22, checked in by ogrimm, 16 years ago
First commit of drsdaq program
File size: 5.8 KB
Line 
1/* $ZEL: sis1100_init_sdram.c,v 1.2 2004/05/27 23:10:21 wuestner Exp $ */
2
3/*
4 * Copyright (c) 2001-2004
5 * Matthias Kirsch, 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#define SDRAM_EEPROM_CTRL_STAT 0x40000400
32
33#define SDRAM_SCL 0x1
34#define SDRAM_SDA 0x2
35#define SDRAM_SDA_OE 0x4
36
37static int
38sis1100_spd_write(struct sis1100_softc* sc, u_int32_t val)
39{
40 u_int32_t error;
41
42 SEM_LOCK(sc->sem_hw);
43 sis1100writereg(sc, t_hdr, 0x0f060402);
44 wmb_reg();
45 sis1100writereg(sc, t_dal, val);
46 wmb_reg();
47 sis1100writereg(sc, t_adl, SDRAM_EEPROM_CTRL_STAT);
48 mb_reg();
49 do {
50 error=sis1100readreg(sc, prot_error);
51 } while (error==0x005);
52 SEM_UNLOCK(sc->sem_hw);
53 return error;
54}
55
56static int
57sis1100_spd_read(struct sis1100_softc* sc, u_int32_t* val)
58{
59 u_int32_t error;
60
61 SEM_LOCK(sc->sem_hw);
62 sis1100writereg(sc, t_hdr, 0x0f060002);
63 wmb_reg();
64 sis1100writereg(sc, t_adl, SDRAM_EEPROM_CTRL_STAT);
65 mb_reg();
66 do {
67 error=sis1100readreg(sc, prot_error);
68 } while (error==0x005);
69 rmb_reg();
70 *val=sis1100readreg(sc, tc_dal);
71 SEM_UNLOCK(sc->sem_hw);
72 return error;
73}
74
75static int
76sdram_eeprom_start(struct sis1100_softc* sc)
77{
78 sis1100_spd_write(sc, 0);
79 sis1100_spd_write(sc, SDRAM_SDA_OE|SDRAM_SDA);
80 sis1100_spd_write(sc, SDRAM_SDA_OE|SDRAM_SDA|SDRAM_SCL);
81 sis1100_spd_write(sc, SDRAM_SDA_OE|SDRAM_SCL);
82 sis1100_spd_write(sc, SDRAM_SDA_OE);
83 sis1100_spd_write(sc, 0) ;
84 return 0;
85}
86
87static int
88sdram_eeprom_stop(struct sis1100_softc* sc)
89{
90 sis1100_spd_write(sc, 0);
91 sis1100_spd_write(sc, SDRAM_SDA_OE);
92 sis1100_spd_write(sc, SDRAM_SDA_OE|SDRAM_SCL);
93 sis1100_spd_write(sc, SDRAM_SDA_OE|SDRAM_SDA|SDRAM_SCL);
94 sis1100_spd_write(sc, SDRAM_SDA_OE|SDRAM_SDA);
95 sis1100_spd_write(sc, 0);
96 return 0;
97}
98
99static int
100sdram_eeprom_read(struct sis1100_softc* sc, int noack, u_int8_t* val)
101{
102 u_int32_t d;
103 u_int8_t data;
104 int i;
105
106 data=0;
107 for (i=0; i<8; i++) {
108 sis1100_spd_write(sc, 0);
109 sis1100_spd_write(sc, SDRAM_SCL);
110 sis1100_spd_write(sc, SDRAM_SCL);
111 sis1100_spd_read(sc, &d);
112
113 data<<=1;
114 data|=((d & 0x100)>>8);
115 }
116
117 *val=data;
118
119 sis1100_spd_write(sc, noack?SDRAM_SDA_OE|SDRAM_SDA:SDRAM_SDA_OE);
120 sis1100_spd_write(sc, noack?SDRAM_SDA_OE|SDRAM_SDA|SDRAM_SCL:SDRAM_SDA_OE|SDRAM_SCL);
121 sis1100_spd_write(sc, noack?SDRAM_SDA_OE|SDRAM_SDA|SDRAM_SCL:SDRAM_SDA_OE|SDRAM_SCL);
122 sis1100_spd_write(sc, noack?SDRAM_SDA_OE|SDRAM_SDA:SDRAM_SDA_OE);
123 sis1100_spd_write(sc, 0);
124 return 0 ;
125}
126
127static int
128sdram_eeprom_write(struct sis1100_softc* sc, u_int8_t val)
129{
130 u_int32_t data ;
131 int i ;
132
133 for (i=0; i<8; i++) {
134 data=(val&0x80)?SDRAM_SDA_OE|SDRAM_SDA:SDRAM_SDA_OE;
135 sis1100_spd_write(sc, data);
136 sis1100_spd_write(sc, data);
137
138 sis1100_spd_write(sc, data|SDRAM_SCL);
139
140 sis1100_spd_write(sc, data);
141 val<<=1;
142 }
143
144 sis1100_spd_write(sc, 0);
145 sis1100_spd_write(sc, 0);
146 sis1100_spd_write(sc, SDRAM_SCL);
147 sis1100_spd_write(sc, SDRAM_SCL);
148 sis1100_spd_write(sc, 0);
149 return 0 ;
150}
151
152int
153sis1100_init_sdram(struct sis1100_softc* sc)
154{
155 u_int32_t eeprom_signature;
156 u_int8_t eeprom_bytes[8];
157 u_int8_t dummy;
158 int i;
159
160 sdram_eeprom_start(sc) ;
161 sdram_eeprom_write(sc, 0xA0); /* device Write cmd */
162 sdram_eeprom_write(sc, 0x00); /* write address */
163
164 sdram_eeprom_start(sc) ;
165
166 sdram_eeprom_write(sc, 0xA1); /* device Read cmd */
167
168 for (i=0; i<8; i++) sdram_eeprom_read(sc, 0, eeprom_bytes+i);
169
170 sdram_eeprom_read(sc, 1, &dummy);
171 sdram_eeprom_stop(sc);
172/*
173 for (i=0; i<8; i++)
174 printk(KERN_INFO "eeprom[%d]=0x%03x\n", i, eeprom_bytes[i]);
175*/
176 eeprom_signature=(eeprom_bytes[3]<<16)|(eeprom_bytes[4]<<8)|(eeprom_bytes[5]);
177/*
178 printk(KERN_INFO "eeprom_signature=0x%04x\n", eeprom_signature);
179*/
180 switch (eeprom_signature) {
181 case 0x0c0901:
182 sc->ram_size=64*1024*1024;
183 break;
184 case 0x0c0902:
185 sc->ram_size=128*1024*1024;
186 break;
187 case 0x0d0a01:
188 sc->ram_size=256*1024*1024;
189 sis1100_spd_write(sc, 1<<16);
190 break;
191 case 0x0d0a02:
192 sc->ram_size=512*1024*1024;
193 sis1100_spd_write(sc, 1<<16);
194 break;
195 case 0xffffff:
196 sc->ram_size=0;
197 pINFO(sc, "no SDRAM installed");
198 break;
199 default:
200 pERROR(sc, "SDRAM not supported: row=%d col=%d banks=%d",
201 eeprom_bytes[3], eeprom_bytes[4], eeprom_bytes[5]);
202 sc->ram_size=0;
203 }
204 return 0;
205}
Note: See TracBrowser for help on using the repository browser.