xref: /linux/drivers/media/common/b2c2/flexcop-sram.c (revision 3785bc170f79ef04129731582b468c28e1326d6d)
1*3785bc17SMauro Carvalho Chehab /*
2*3785bc17SMauro Carvalho Chehab  * Linux driver for digital TV devices equipped with B2C2 FlexcopII(b)/III
3*3785bc17SMauro Carvalho Chehab  * flexcop-sram.c - functions for controlling the SRAM
4*3785bc17SMauro Carvalho Chehab  * see flexcop.c for copyright information
5*3785bc17SMauro Carvalho Chehab  */
6*3785bc17SMauro Carvalho Chehab #include "flexcop.h"
7*3785bc17SMauro Carvalho Chehab 
8*3785bc17SMauro Carvalho Chehab static void flexcop_sram_set_chip(struct flexcop_device *fc,
9*3785bc17SMauro Carvalho Chehab 		flexcop_sram_type_t type)
10*3785bc17SMauro Carvalho Chehab {
11*3785bc17SMauro Carvalho Chehab 	flexcop_set_ibi_value(wan_ctrl_reg_71c, sram_chip, type);
12*3785bc17SMauro Carvalho Chehab }
13*3785bc17SMauro Carvalho Chehab 
14*3785bc17SMauro Carvalho Chehab int flexcop_sram_init(struct flexcop_device *fc)
15*3785bc17SMauro Carvalho Chehab {
16*3785bc17SMauro Carvalho Chehab 	switch (fc->rev) {
17*3785bc17SMauro Carvalho Chehab 	case FLEXCOP_II:
18*3785bc17SMauro Carvalho Chehab 	case FLEXCOP_IIB:
19*3785bc17SMauro Carvalho Chehab 		flexcop_sram_set_chip(fc, FC_SRAM_1_32KB);
20*3785bc17SMauro Carvalho Chehab 		break;
21*3785bc17SMauro Carvalho Chehab 	case FLEXCOP_III:
22*3785bc17SMauro Carvalho Chehab 		flexcop_sram_set_chip(fc, FC_SRAM_1_48KB);
23*3785bc17SMauro Carvalho Chehab 		break;
24*3785bc17SMauro Carvalho Chehab 	default:
25*3785bc17SMauro Carvalho Chehab 		return -EINVAL;
26*3785bc17SMauro Carvalho Chehab 	}
27*3785bc17SMauro Carvalho Chehab 	return 0;
28*3785bc17SMauro Carvalho Chehab }
29*3785bc17SMauro Carvalho Chehab 
30*3785bc17SMauro Carvalho Chehab int flexcop_sram_set_dest(struct flexcop_device *fc, flexcop_sram_dest_t dest,
31*3785bc17SMauro Carvalho Chehab 		 flexcop_sram_dest_target_t target)
32*3785bc17SMauro Carvalho Chehab {
33*3785bc17SMauro Carvalho Chehab 	flexcop_ibi_value v;
34*3785bc17SMauro Carvalho Chehab 	v = fc->read_ibi_reg(fc, sram_dest_reg_714);
35*3785bc17SMauro Carvalho Chehab 
36*3785bc17SMauro Carvalho Chehab 	if (fc->rev != FLEXCOP_III && target == FC_SRAM_DEST_TARGET_FC3_CA) {
37*3785bc17SMauro Carvalho Chehab 		err("SRAM destination target to available on FlexCopII(b)\n");
38*3785bc17SMauro Carvalho Chehab 		return -EINVAL;
39*3785bc17SMauro Carvalho Chehab 	}
40*3785bc17SMauro Carvalho Chehab 	deb_sram("sram dest: %x target: %x\n", dest, target);
41*3785bc17SMauro Carvalho Chehab 
42*3785bc17SMauro Carvalho Chehab 	if (dest & FC_SRAM_DEST_NET)
43*3785bc17SMauro Carvalho Chehab 		v.sram_dest_reg_714.NET_Dest = target;
44*3785bc17SMauro Carvalho Chehab 	if (dest & FC_SRAM_DEST_CAI)
45*3785bc17SMauro Carvalho Chehab 		v.sram_dest_reg_714.CAI_Dest = target;
46*3785bc17SMauro Carvalho Chehab 	if (dest & FC_SRAM_DEST_CAO)
47*3785bc17SMauro Carvalho Chehab 		v.sram_dest_reg_714.CAO_Dest = target;
48*3785bc17SMauro Carvalho Chehab 	if (dest & FC_SRAM_DEST_MEDIA)
49*3785bc17SMauro Carvalho Chehab 		v.sram_dest_reg_714.MEDIA_Dest = target;
50*3785bc17SMauro Carvalho Chehab 
51*3785bc17SMauro Carvalho Chehab 	fc->write_ibi_reg(fc,sram_dest_reg_714,v);
52*3785bc17SMauro Carvalho Chehab 	udelay(1000); /* TODO delay really necessary */
53*3785bc17SMauro Carvalho Chehab 
54*3785bc17SMauro Carvalho Chehab 	return 0;
55*3785bc17SMauro Carvalho Chehab }
56*3785bc17SMauro Carvalho Chehab EXPORT_SYMBOL(flexcop_sram_set_dest);
57*3785bc17SMauro Carvalho Chehab 
58*3785bc17SMauro Carvalho Chehab void flexcop_wan_set_speed(struct flexcop_device *fc, flexcop_wan_speed_t s)
59*3785bc17SMauro Carvalho Chehab {
60*3785bc17SMauro Carvalho Chehab 	flexcop_set_ibi_value(wan_ctrl_reg_71c,wan_speed_sig,s);
61*3785bc17SMauro Carvalho Chehab }
62*3785bc17SMauro Carvalho Chehab EXPORT_SYMBOL(flexcop_wan_set_speed);
63*3785bc17SMauro Carvalho Chehab 
64*3785bc17SMauro Carvalho Chehab void flexcop_sram_ctrl(struct flexcop_device *fc, int usb_wan, int sramdma, int maximumfill)
65*3785bc17SMauro Carvalho Chehab {
66*3785bc17SMauro Carvalho Chehab 	flexcop_ibi_value v = fc->read_ibi_reg(fc,sram_dest_reg_714);
67*3785bc17SMauro Carvalho Chehab 	v.sram_dest_reg_714.ctrl_usb_wan = usb_wan;
68*3785bc17SMauro Carvalho Chehab 	v.sram_dest_reg_714.ctrl_sramdma = sramdma;
69*3785bc17SMauro Carvalho Chehab 	v.sram_dest_reg_714.ctrl_maximumfill = maximumfill;
70*3785bc17SMauro Carvalho Chehab 	fc->write_ibi_reg(fc,sram_dest_reg_714,v);
71*3785bc17SMauro Carvalho Chehab }
72*3785bc17SMauro Carvalho Chehab EXPORT_SYMBOL(flexcop_sram_ctrl);
73*3785bc17SMauro Carvalho Chehab 
74*3785bc17SMauro Carvalho Chehab #if 0
75*3785bc17SMauro Carvalho Chehab static void flexcop_sram_write(struct adapter *adapter, u32 bank, u32 addr, u8 *buf, u32 len)
76*3785bc17SMauro Carvalho Chehab {
77*3785bc17SMauro Carvalho Chehab 	int i, retries;
78*3785bc17SMauro Carvalho Chehab 	u32 command;
79*3785bc17SMauro Carvalho Chehab 
80*3785bc17SMauro Carvalho Chehab 	for (i = 0; i < len; i++) {
81*3785bc17SMauro Carvalho Chehab 		command = bank | addr | 0x04000000 | (*buf << 0x10);
82*3785bc17SMauro Carvalho Chehab 
83*3785bc17SMauro Carvalho Chehab 		retries = 2;
84*3785bc17SMauro Carvalho Chehab 
85*3785bc17SMauro Carvalho Chehab 		while (((read_reg_dw(adapter, 0x700) & 0x80000000) != 0) && (retries > 0)) {
86*3785bc17SMauro Carvalho Chehab 			mdelay(1);
87*3785bc17SMauro Carvalho Chehab 			retries--;
88*3785bc17SMauro Carvalho Chehab 		};
89*3785bc17SMauro Carvalho Chehab 
90*3785bc17SMauro Carvalho Chehab 		if (retries == 0)
91*3785bc17SMauro Carvalho Chehab 			printk("%s: SRAM timeout\n", __func__);
92*3785bc17SMauro Carvalho Chehab 
93*3785bc17SMauro Carvalho Chehab 		write_reg_dw(adapter, 0x700, command);
94*3785bc17SMauro Carvalho Chehab 
95*3785bc17SMauro Carvalho Chehab 		buf++;
96*3785bc17SMauro Carvalho Chehab 		addr++;
97*3785bc17SMauro Carvalho Chehab 	}
98*3785bc17SMauro Carvalho Chehab }
99*3785bc17SMauro Carvalho Chehab 
100*3785bc17SMauro Carvalho Chehab static void flex_sram_read(struct adapter *adapter, u32 bank, u32 addr, u8 *buf, u32 len)
101*3785bc17SMauro Carvalho Chehab {
102*3785bc17SMauro Carvalho Chehab 	int i, retries;
103*3785bc17SMauro Carvalho Chehab 	u32 command, value;
104*3785bc17SMauro Carvalho Chehab 
105*3785bc17SMauro Carvalho Chehab 	for (i = 0; i < len; i++) {
106*3785bc17SMauro Carvalho Chehab 		command = bank | addr | 0x04008000;
107*3785bc17SMauro Carvalho Chehab 
108*3785bc17SMauro Carvalho Chehab 		retries = 10000;
109*3785bc17SMauro Carvalho Chehab 
110*3785bc17SMauro Carvalho Chehab 		while (((read_reg_dw(adapter, 0x700) & 0x80000000) != 0) && (retries > 0)) {
111*3785bc17SMauro Carvalho Chehab 			mdelay(1);
112*3785bc17SMauro Carvalho Chehab 			retries--;
113*3785bc17SMauro Carvalho Chehab 		};
114*3785bc17SMauro Carvalho Chehab 
115*3785bc17SMauro Carvalho Chehab 		if (retries == 0)
116*3785bc17SMauro Carvalho Chehab 			printk("%s: SRAM timeout\n", __func__);
117*3785bc17SMauro Carvalho Chehab 
118*3785bc17SMauro Carvalho Chehab 		write_reg_dw(adapter, 0x700, command);
119*3785bc17SMauro Carvalho Chehab 
120*3785bc17SMauro Carvalho Chehab 		retries = 10000;
121*3785bc17SMauro Carvalho Chehab 
122*3785bc17SMauro Carvalho Chehab 		while (((read_reg_dw(adapter, 0x700) & 0x80000000) != 0) && (retries > 0)) {
123*3785bc17SMauro Carvalho Chehab 			mdelay(1);
124*3785bc17SMauro Carvalho Chehab 			retries--;
125*3785bc17SMauro Carvalho Chehab 		};
126*3785bc17SMauro Carvalho Chehab 
127*3785bc17SMauro Carvalho Chehab 		if (retries == 0)
128*3785bc17SMauro Carvalho Chehab 			printk("%s: SRAM timeout\n", __func__);
129*3785bc17SMauro Carvalho Chehab 
130*3785bc17SMauro Carvalho Chehab 		value = read_reg_dw(adapter, 0x700) >> 0x10;
131*3785bc17SMauro Carvalho Chehab 
132*3785bc17SMauro Carvalho Chehab 		*buf = (value & 0xff);
133*3785bc17SMauro Carvalho Chehab 
134*3785bc17SMauro Carvalho Chehab 		addr++;
135*3785bc17SMauro Carvalho Chehab 		buf++;
136*3785bc17SMauro Carvalho Chehab 	}
137*3785bc17SMauro Carvalho Chehab }
138*3785bc17SMauro Carvalho Chehab 
139*3785bc17SMauro Carvalho Chehab static void sram_write_chunk(struct adapter *adapter, u32 addr, u8 *buf, u16 len)
140*3785bc17SMauro Carvalho Chehab {
141*3785bc17SMauro Carvalho Chehab 	u32 bank;
142*3785bc17SMauro Carvalho Chehab 
143*3785bc17SMauro Carvalho Chehab 	bank = 0;
144*3785bc17SMauro Carvalho Chehab 
145*3785bc17SMauro Carvalho Chehab 	if (adapter->dw_sram_type == 0x20000) {
146*3785bc17SMauro Carvalho Chehab 		bank = (addr & 0x18000) << 0x0d;
147*3785bc17SMauro Carvalho Chehab 	}
148*3785bc17SMauro Carvalho Chehab 
149*3785bc17SMauro Carvalho Chehab 	if (adapter->dw_sram_type == 0x00000) {
150*3785bc17SMauro Carvalho Chehab 		if ((addr >> 0x0f) == 0)
151*3785bc17SMauro Carvalho Chehab 			bank = 0x20000000;
152*3785bc17SMauro Carvalho Chehab 		else
153*3785bc17SMauro Carvalho Chehab 			bank = 0x10000000;
154*3785bc17SMauro Carvalho Chehab 	}
155*3785bc17SMauro Carvalho Chehab 	flex_sram_write(adapter, bank, addr & 0x7fff, buf, len);
156*3785bc17SMauro Carvalho Chehab }
157*3785bc17SMauro Carvalho Chehab 
158*3785bc17SMauro Carvalho Chehab static void sram_read_chunk(struct adapter *adapter, u32 addr, u8 *buf, u16 len)
159*3785bc17SMauro Carvalho Chehab {
160*3785bc17SMauro Carvalho Chehab 	u32 bank;
161*3785bc17SMauro Carvalho Chehab 	bank = 0;
162*3785bc17SMauro Carvalho Chehab 
163*3785bc17SMauro Carvalho Chehab 	if (adapter->dw_sram_type == 0x20000) {
164*3785bc17SMauro Carvalho Chehab 		bank = (addr & 0x18000) << 0x0d;
165*3785bc17SMauro Carvalho Chehab 	}
166*3785bc17SMauro Carvalho Chehab 
167*3785bc17SMauro Carvalho Chehab 	if (adapter->dw_sram_type == 0x00000) {
168*3785bc17SMauro Carvalho Chehab 		if ((addr >> 0x0f) == 0)
169*3785bc17SMauro Carvalho Chehab 			bank = 0x20000000;
170*3785bc17SMauro Carvalho Chehab 		else
171*3785bc17SMauro Carvalho Chehab 			bank = 0x10000000;
172*3785bc17SMauro Carvalho Chehab 	}
173*3785bc17SMauro Carvalho Chehab 	flex_sram_read(adapter, bank, addr & 0x7fff, buf, len);
174*3785bc17SMauro Carvalho Chehab }
175*3785bc17SMauro Carvalho Chehab 
176*3785bc17SMauro Carvalho Chehab static void sram_read(struct adapter *adapter, u32 addr, u8 *buf, u32 len)
177*3785bc17SMauro Carvalho Chehab {
178*3785bc17SMauro Carvalho Chehab 	u32 length;
179*3785bc17SMauro Carvalho Chehab 	while (len != 0) {
180*3785bc17SMauro Carvalho Chehab 		length = len;
181*3785bc17SMauro Carvalho Chehab 		/* check if the address range belongs to the same
182*3785bc17SMauro Carvalho Chehab 		 * 32K memory chip. If not, the data is read
183*3785bc17SMauro Carvalho Chehab 		 * from one chip at a time */
184*3785bc17SMauro Carvalho Chehab 		if ((addr >> 0x0f) != ((addr + len - 1) >> 0x0f)) {
185*3785bc17SMauro Carvalho Chehab 			length = (((addr >> 0x0f) + 1) << 0x0f) - addr;
186*3785bc17SMauro Carvalho Chehab 		}
187*3785bc17SMauro Carvalho Chehab 
188*3785bc17SMauro Carvalho Chehab 		sram_read_chunk(adapter, addr, buf, length);
189*3785bc17SMauro Carvalho Chehab 		addr = addr + length;
190*3785bc17SMauro Carvalho Chehab 		buf = buf + length;
191*3785bc17SMauro Carvalho Chehab 		len = len - length;
192*3785bc17SMauro Carvalho Chehab 	}
193*3785bc17SMauro Carvalho Chehab }
194*3785bc17SMauro Carvalho Chehab 
195*3785bc17SMauro Carvalho Chehab static void sram_write(struct adapter *adapter, u32 addr, u8 *buf, u32 len)
196*3785bc17SMauro Carvalho Chehab {
197*3785bc17SMauro Carvalho Chehab 	u32 length;
198*3785bc17SMauro Carvalho Chehab 	while (len != 0) {
199*3785bc17SMauro Carvalho Chehab 		length = len;
200*3785bc17SMauro Carvalho Chehab 
201*3785bc17SMauro Carvalho Chehab 		/* check if the address range belongs to the same
202*3785bc17SMauro Carvalho Chehab 		 * 32K memory chip. If not, the data is
203*3785bc17SMauro Carvalho Chehab 		 * written to one chip at a time */
204*3785bc17SMauro Carvalho Chehab 		if ((addr >> 0x0f) != ((addr + len - 1) >> 0x0f)) {
205*3785bc17SMauro Carvalho Chehab 			length = (((addr >> 0x0f) + 1) << 0x0f) - addr;
206*3785bc17SMauro Carvalho Chehab 		}
207*3785bc17SMauro Carvalho Chehab 
208*3785bc17SMauro Carvalho Chehab 		sram_write_chunk(adapter, addr, buf, length);
209*3785bc17SMauro Carvalho Chehab 		addr = addr + length;
210*3785bc17SMauro Carvalho Chehab 		buf = buf + length;
211*3785bc17SMauro Carvalho Chehab 		len = len - length;
212*3785bc17SMauro Carvalho Chehab 	}
213*3785bc17SMauro Carvalho Chehab }
214*3785bc17SMauro Carvalho Chehab 
215*3785bc17SMauro Carvalho Chehab static void sram_set_size(struct adapter *adapter, u32 mask)
216*3785bc17SMauro Carvalho Chehab {
217*3785bc17SMauro Carvalho Chehab 	write_reg_dw(adapter, 0x71c,
218*3785bc17SMauro Carvalho Chehab 			(mask | (~0x30000 & read_reg_dw(adapter, 0x71c))));
219*3785bc17SMauro Carvalho Chehab }
220*3785bc17SMauro Carvalho Chehab 
221*3785bc17SMauro Carvalho Chehab static void sram_init(struct adapter *adapter)
222*3785bc17SMauro Carvalho Chehab {
223*3785bc17SMauro Carvalho Chehab 	u32 tmp;
224*3785bc17SMauro Carvalho Chehab 	tmp = read_reg_dw(adapter, 0x71c);
225*3785bc17SMauro Carvalho Chehab 	write_reg_dw(adapter, 0x71c, 1);
226*3785bc17SMauro Carvalho Chehab 
227*3785bc17SMauro Carvalho Chehab 	if (read_reg_dw(adapter, 0x71c) != 0) {
228*3785bc17SMauro Carvalho Chehab 		write_reg_dw(adapter, 0x71c, tmp);
229*3785bc17SMauro Carvalho Chehab 		adapter->dw_sram_type = tmp & 0x30000;
230*3785bc17SMauro Carvalho Chehab 		ddprintk("%s: dw_sram_type = %x\n", __func__, adapter->dw_sram_type);
231*3785bc17SMauro Carvalho Chehab 	} else {
232*3785bc17SMauro Carvalho Chehab 		adapter->dw_sram_type = 0x10000;
233*3785bc17SMauro Carvalho Chehab 		ddprintk("%s: dw_sram_type = %x\n", __func__, adapter->dw_sram_type);
234*3785bc17SMauro Carvalho Chehab 	}
235*3785bc17SMauro Carvalho Chehab }
236*3785bc17SMauro Carvalho Chehab 
237*3785bc17SMauro Carvalho Chehab static int sram_test_location(struct adapter *adapter, u32 mask, u32 addr)
238*3785bc17SMauro Carvalho Chehab {
239*3785bc17SMauro Carvalho Chehab 	u8 tmp1, tmp2;
240*3785bc17SMauro Carvalho Chehab 	dprintk("%s: mask = %x, addr = %x\n", __func__, mask, addr);
241*3785bc17SMauro Carvalho Chehab 
242*3785bc17SMauro Carvalho Chehab 	sram_set_size(adapter, mask);
243*3785bc17SMauro Carvalho Chehab 	sram_init(adapter);
244*3785bc17SMauro Carvalho Chehab 
245*3785bc17SMauro Carvalho Chehab 	tmp2 = 0xa5;
246*3785bc17SMauro Carvalho Chehab 	tmp1 = 0x4f;
247*3785bc17SMauro Carvalho Chehab 
248*3785bc17SMauro Carvalho Chehab 	sram_write(adapter, addr, &tmp2, 1);
249*3785bc17SMauro Carvalho Chehab 	sram_write(adapter, addr + 4, &tmp1, 1);
250*3785bc17SMauro Carvalho Chehab 
251*3785bc17SMauro Carvalho Chehab 	tmp2 = 0;
252*3785bc17SMauro Carvalho Chehab 	mdelay(20);
253*3785bc17SMauro Carvalho Chehab 
254*3785bc17SMauro Carvalho Chehab 	sram_read(adapter, addr, &tmp2, 1);
255*3785bc17SMauro Carvalho Chehab 	sram_read(adapter, addr, &tmp2, 1);
256*3785bc17SMauro Carvalho Chehab 
257*3785bc17SMauro Carvalho Chehab 	dprintk("%s: wrote 0xa5, read 0x%2x\n", __func__, tmp2);
258*3785bc17SMauro Carvalho Chehab 
259*3785bc17SMauro Carvalho Chehab 	if (tmp2 != 0xa5)
260*3785bc17SMauro Carvalho Chehab 		return 0;
261*3785bc17SMauro Carvalho Chehab 
262*3785bc17SMauro Carvalho Chehab 	tmp2 = 0x5a;
263*3785bc17SMauro Carvalho Chehab 	tmp1 = 0xf4;
264*3785bc17SMauro Carvalho Chehab 
265*3785bc17SMauro Carvalho Chehab 	sram_write(adapter, addr, &tmp2, 1);
266*3785bc17SMauro Carvalho Chehab 	sram_write(adapter, addr + 4, &tmp1, 1);
267*3785bc17SMauro Carvalho Chehab 
268*3785bc17SMauro Carvalho Chehab 	tmp2 = 0;
269*3785bc17SMauro Carvalho Chehab 	mdelay(20);
270*3785bc17SMauro Carvalho Chehab 
271*3785bc17SMauro Carvalho Chehab 	sram_read(adapter, addr, &tmp2, 1);
272*3785bc17SMauro Carvalho Chehab 	sram_read(adapter, addr, &tmp2, 1);
273*3785bc17SMauro Carvalho Chehab 
274*3785bc17SMauro Carvalho Chehab 	dprintk("%s: wrote 0x5a, read 0x%2x\n", __func__, tmp2);
275*3785bc17SMauro Carvalho Chehab 
276*3785bc17SMauro Carvalho Chehab 	if (tmp2 != 0x5a)
277*3785bc17SMauro Carvalho Chehab 		return 0;
278*3785bc17SMauro Carvalho Chehab 	return 1;
279*3785bc17SMauro Carvalho Chehab }
280*3785bc17SMauro Carvalho Chehab 
281*3785bc17SMauro Carvalho Chehab static u32 sram_length(struct adapter *adapter)
282*3785bc17SMauro Carvalho Chehab {
283*3785bc17SMauro Carvalho Chehab 	if (adapter->dw_sram_type == 0x10000)
284*3785bc17SMauro Carvalho Chehab 		return 32768; /* 32K */
285*3785bc17SMauro Carvalho Chehab 	if (adapter->dw_sram_type == 0x00000)
286*3785bc17SMauro Carvalho Chehab 		return 65536; /* 64K */
287*3785bc17SMauro Carvalho Chehab 	if (adapter->dw_sram_type == 0x20000)
288*3785bc17SMauro Carvalho Chehab 		return 131072; /* 128K */
289*3785bc17SMauro Carvalho Chehab 	return 32768; /* 32K */
290*3785bc17SMauro Carvalho Chehab }
291*3785bc17SMauro Carvalho Chehab 
292*3785bc17SMauro Carvalho Chehab /* FlexcopII can work with 32K, 64K or 128K of external SRAM memory.
293*3785bc17SMauro Carvalho Chehab    - for 128K there are 4x32K chips at bank 0,1,2,3.
294*3785bc17SMauro Carvalho Chehab    - for  64K there are 2x32K chips at bank 1,2.
295*3785bc17SMauro Carvalho Chehab    - for  32K there is one 32K chip at bank 0.
296*3785bc17SMauro Carvalho Chehab 
297*3785bc17SMauro Carvalho Chehab    FlexCop works only with one bank at a time. The bank is selected
298*3785bc17SMauro Carvalho Chehab    by bits 28-29 of the 0x700 register.
299*3785bc17SMauro Carvalho Chehab 
300*3785bc17SMauro Carvalho Chehab    bank 0 covers addresses 0x00000-0x07fff
301*3785bc17SMauro Carvalho Chehab    bank 1 covers addresses 0x08000-0x0ffff
302*3785bc17SMauro Carvalho Chehab    bank 2 covers addresses 0x10000-0x17fff
303*3785bc17SMauro Carvalho Chehab    bank 3 covers addresses 0x18000-0x1ffff */
304*3785bc17SMauro Carvalho Chehab 
305*3785bc17SMauro Carvalho Chehab static int flexcop_sram_detect(struct flexcop_device *fc)
306*3785bc17SMauro Carvalho Chehab {
307*3785bc17SMauro Carvalho Chehab 	flexcop_ibi_value r208, r71c_0, vr71c_1;
308*3785bc17SMauro Carvalho Chehab 	r208 = fc->read_ibi_reg(fc, ctrl_208);
309*3785bc17SMauro Carvalho Chehab 	fc->write_ibi_reg(fc, ctrl_208, ibi_zero);
310*3785bc17SMauro Carvalho Chehab 
311*3785bc17SMauro Carvalho Chehab 	r71c_0 = fc->read_ibi_reg(fc, wan_ctrl_reg_71c);
312*3785bc17SMauro Carvalho Chehab 	write_reg_dw(adapter, 0x71c, 1);
313*3785bc17SMauro Carvalho Chehab 	tmp3 = read_reg_dw(adapter, 0x71c);
314*3785bc17SMauro Carvalho Chehab 	dprintk("%s: tmp3 = %x\n", __func__, tmp3);
315*3785bc17SMauro Carvalho Chehab 	write_reg_dw(adapter, 0x71c, tmp2);
316*3785bc17SMauro Carvalho Chehab 
317*3785bc17SMauro Carvalho Chehab 	// check for internal SRAM ???
318*3785bc17SMauro Carvalho Chehab 	tmp3--;
319*3785bc17SMauro Carvalho Chehab 	if (tmp3 != 0) {
320*3785bc17SMauro Carvalho Chehab 		sram_set_size(adapter, 0x10000);
321*3785bc17SMauro Carvalho Chehab 		sram_init(adapter);
322*3785bc17SMauro Carvalho Chehab 		write_reg_dw(adapter, 0x208, tmp);
323*3785bc17SMauro Carvalho Chehab 		dprintk("%s: sram size = 32K\n", __func__);
324*3785bc17SMauro Carvalho Chehab 		return 32;
325*3785bc17SMauro Carvalho Chehab 	}
326*3785bc17SMauro Carvalho Chehab 
327*3785bc17SMauro Carvalho Chehab 	if (sram_test_location(adapter, 0x20000, 0x18000) != 0) {
328*3785bc17SMauro Carvalho Chehab 		sram_set_size(adapter, 0x20000);
329*3785bc17SMauro Carvalho Chehab 		sram_init(adapter);
330*3785bc17SMauro Carvalho Chehab 		write_reg_dw(adapter, 0x208, tmp);
331*3785bc17SMauro Carvalho Chehab 		dprintk("%s: sram size = 128K\n", __func__);
332*3785bc17SMauro Carvalho Chehab 		return 128;
333*3785bc17SMauro Carvalho Chehab 	}
334*3785bc17SMauro Carvalho Chehab 
335*3785bc17SMauro Carvalho Chehab 	if (sram_test_location(adapter, 0x00000, 0x10000) != 0) {
336*3785bc17SMauro Carvalho Chehab 		sram_set_size(adapter, 0x00000);
337*3785bc17SMauro Carvalho Chehab 		sram_init(adapter);
338*3785bc17SMauro Carvalho Chehab 		write_reg_dw(adapter, 0x208, tmp);
339*3785bc17SMauro Carvalho Chehab 		dprintk("%s: sram size = 64K\n", __func__);
340*3785bc17SMauro Carvalho Chehab 		return 64;
341*3785bc17SMauro Carvalho Chehab 	}
342*3785bc17SMauro Carvalho Chehab 
343*3785bc17SMauro Carvalho Chehab 	if (sram_test_location(adapter, 0x10000, 0x00000) != 0) {
344*3785bc17SMauro Carvalho Chehab 		sram_set_size(adapter, 0x10000);
345*3785bc17SMauro Carvalho Chehab 		sram_init(adapter);
346*3785bc17SMauro Carvalho Chehab 		write_reg_dw(adapter, 0x208, tmp);
347*3785bc17SMauro Carvalho Chehab 		dprintk("%s: sram size = 32K\n", __func__);
348*3785bc17SMauro Carvalho Chehab 		return 32;
349*3785bc17SMauro Carvalho Chehab 	}
350*3785bc17SMauro Carvalho Chehab 
351*3785bc17SMauro Carvalho Chehab 	sram_set_size(adapter, 0x10000);
352*3785bc17SMauro Carvalho Chehab 	sram_init(adapter);
353*3785bc17SMauro Carvalho Chehab 	write_reg_dw(adapter, 0x208, tmp);
354*3785bc17SMauro Carvalho Chehab 	dprintk("%s: SRAM detection failed. Set to 32K \n", __func__);
355*3785bc17SMauro Carvalho Chehab 	return 0;
356*3785bc17SMauro Carvalho Chehab }
357*3785bc17SMauro Carvalho Chehab 
358*3785bc17SMauro Carvalho Chehab static void sll_detect_sram_size(struct adapter *adapter)
359*3785bc17SMauro Carvalho Chehab {
360*3785bc17SMauro Carvalho Chehab 	sram_detect_for_flex2(adapter);
361*3785bc17SMauro Carvalho Chehab }
362*3785bc17SMauro Carvalho Chehab 
363*3785bc17SMauro Carvalho Chehab #endif
364