2 * Linux driver for digital TV devices equipped with B2C2 FlexcopII(b)/III
3 * flexcop-sram.c - functions for controlling the SRAM
4 * see flexcop.c for copyright information
8 static void flexcop_sram_set_chip(struct flexcop_device
*fc
,
9 flexcop_sram_type_t type
)
11 flexcop_set_ibi_value(wan_ctrl_reg_71c
, sram_chip
, type
);
14 int flexcop_sram_init(struct flexcop_device
*fc
)
19 flexcop_sram_set_chip(fc
, FC_SRAM_1_32KB
);
22 flexcop_sram_set_chip(fc
, FC_SRAM_1_48KB
);
30 int flexcop_sram_set_dest(struct flexcop_device
*fc
, flexcop_sram_dest_t dest
,
31 flexcop_sram_dest_target_t target
)
34 v
= fc
->read_ibi_reg(fc
, sram_dest_reg_714
);
36 if (fc
->rev
!= FLEXCOP_III
&& target
== FC_SRAM_DEST_TARGET_FC3_CA
) {
37 err("SRAM destination target to available on FlexCopII(b)\n");
40 deb_sram("sram dest: %x target: %x\n", dest
, target
);
42 if (dest
& FC_SRAM_DEST_NET
)
43 v
.sram_dest_reg_714
.NET_Dest
= target
;
44 if (dest
& FC_SRAM_DEST_CAI
)
45 v
.sram_dest_reg_714
.CAI_Dest
= target
;
46 if (dest
& FC_SRAM_DEST_CAO
)
47 v
.sram_dest_reg_714
.CAO_Dest
= target
;
48 if (dest
& FC_SRAM_DEST_MEDIA
)
49 v
.sram_dest_reg_714
.MEDIA_Dest
= target
;
51 fc
->write_ibi_reg(fc
,sram_dest_reg_714
,v
);
52 udelay(1000); /* TODO delay really necessary */
56 EXPORT_SYMBOL(flexcop_sram_set_dest
);
58 void flexcop_wan_set_speed(struct flexcop_device
*fc
, flexcop_wan_speed_t s
)
60 flexcop_set_ibi_value(wan_ctrl_reg_71c
,wan_speed_sig
,s
);
62 EXPORT_SYMBOL(flexcop_wan_set_speed
);
64 void flexcop_sram_ctrl(struct flexcop_device
*fc
, int usb_wan
, int sramdma
, int maximumfill
)
66 flexcop_ibi_value v
= fc
->read_ibi_reg(fc
,sram_dest_reg_714
);
67 v
.sram_dest_reg_714
.ctrl_usb_wan
= usb_wan
;
68 v
.sram_dest_reg_714
.ctrl_sramdma
= sramdma
;
69 v
.sram_dest_reg_714
.ctrl_maximumfill
= maximumfill
;
70 fc
->write_ibi_reg(fc
,sram_dest_reg_714
,v
);
72 EXPORT_SYMBOL(flexcop_sram_ctrl
);
75 static void flexcop_sram_write(struct adapter
*adapter
, u32 bank
, u32 addr
, u8
*buf
, u32 len
)
80 for (i
= 0; i
< len
; i
++) {
81 command
= bank
| addr
| 0x04000000 | (*buf
<< 0x10);
85 while (((read_reg_dw(adapter
, 0x700) & 0x80000000) != 0) && (retries
> 0)) {
91 printk("%s: SRAM timeout\n", __func__
);
93 write_reg_dw(adapter
, 0x700, command
);
100 static void flex_sram_read(struct adapter
*adapter
, u32 bank
, u32 addr
, u8
*buf
, u32 len
)
105 for (i
= 0; i
< len
; i
++) {
106 command
= bank
| addr
| 0x04008000;
110 while (((read_reg_dw(adapter
, 0x700) & 0x80000000) != 0) && (retries
> 0)) {
116 printk("%s: SRAM timeout\n", __func__
);
118 write_reg_dw(adapter
, 0x700, command
);
122 while (((read_reg_dw(adapter
, 0x700) & 0x80000000) != 0) && (retries
> 0)) {
128 printk("%s: SRAM timeout\n", __func__
);
130 value
= read_reg_dw(adapter
, 0x700) >> 0x10;
132 *buf
= (value
& 0xff);
139 static void sram_write_chunk(struct adapter
*adapter
, u32 addr
, u8
*buf
, u16 len
)
145 if (adapter
->dw_sram_type
== 0x20000) {
146 bank
= (addr
& 0x18000) << 0x0d;
149 if (adapter
->dw_sram_type
== 0x00000) {
150 if ((addr
>> 0x0f) == 0)
155 flex_sram_write(adapter
, bank
, addr
& 0x7fff, buf
, len
);
158 static void sram_read_chunk(struct adapter
*adapter
, u32 addr
, u8
*buf
, u16 len
)
163 if (adapter
->dw_sram_type
== 0x20000) {
164 bank
= (addr
& 0x18000) << 0x0d;
167 if (adapter
->dw_sram_type
== 0x00000) {
168 if ((addr
>> 0x0f) == 0)
173 flex_sram_read(adapter
, bank
, addr
& 0x7fff, buf
, len
);
176 static void sram_read(struct adapter
*adapter
, u32 addr
, u8
*buf
, u32 len
)
181 /* check if the address range belongs to the same
182 * 32K memory chip. If not, the data is read
183 * from one chip at a time */
184 if ((addr
>> 0x0f) != ((addr
+ len
- 1) >> 0x0f)) {
185 length
= (((addr
>> 0x0f) + 1) << 0x0f) - addr
;
188 sram_read_chunk(adapter
, addr
, buf
, length
);
189 addr
= addr
+ length
;
195 static void sram_write(struct adapter
*adapter
, u32 addr
, u8
*buf
, u32 len
)
201 /* check if the address range belongs to the same
202 * 32K memory chip. If not, the data is
203 * written to one chip at a time */
204 if ((addr
>> 0x0f) != ((addr
+ len
- 1) >> 0x0f)) {
205 length
= (((addr
>> 0x0f) + 1) << 0x0f) - addr
;
208 sram_write_chunk(adapter
, addr
, buf
, length
);
209 addr
= addr
+ length
;
215 static void sram_set_size(struct adapter
*adapter
, u32 mask
)
217 write_reg_dw(adapter
, 0x71c,
218 (mask
| (~0x30000 & read_reg_dw(adapter
, 0x71c))));
221 static void sram_init(struct adapter
*adapter
)
224 tmp
= read_reg_dw(adapter
, 0x71c);
225 write_reg_dw(adapter
, 0x71c, 1);
227 if (read_reg_dw(adapter
, 0x71c) != 0) {
228 write_reg_dw(adapter
, 0x71c, tmp
);
229 adapter
->dw_sram_type
= tmp
& 0x30000;
230 ddprintk("%s: dw_sram_type = %x\n", __func__
, adapter
->dw_sram_type
);
232 adapter
->dw_sram_type
= 0x10000;
233 ddprintk("%s: dw_sram_type = %x\n", __func__
, adapter
->dw_sram_type
);
237 static int sram_test_location(struct adapter
*adapter
, u32 mask
, u32 addr
)
240 dprintk("%s: mask = %x, addr = %x\n", __func__
, mask
, addr
);
242 sram_set_size(adapter
, mask
);
248 sram_write(adapter
, addr
, &tmp2
, 1);
249 sram_write(adapter
, addr
+ 4, &tmp1
, 1);
254 sram_read(adapter
, addr
, &tmp2
, 1);
255 sram_read(adapter
, addr
, &tmp2
, 1);
257 dprintk("%s: wrote 0xa5, read 0x%2x\n", __func__
, tmp2
);
265 sram_write(adapter
, addr
, &tmp2
, 1);
266 sram_write(adapter
, addr
+ 4, &tmp1
, 1);
271 sram_read(adapter
, addr
, &tmp2
, 1);
272 sram_read(adapter
, addr
, &tmp2
, 1);
274 dprintk("%s: wrote 0x5a, read 0x%2x\n", __func__
, tmp2
);
281 static u32
sram_length(struct adapter
*adapter
)
283 if (adapter
->dw_sram_type
== 0x10000)
284 return 32768; /* 32K */
285 if (adapter
->dw_sram_type
== 0x00000)
286 return 65536; /* 64K */
287 if (adapter
->dw_sram_type
== 0x20000)
288 return 131072; /* 128K */
289 return 32768; /* 32K */
292 /* FlexcopII can work with 32K, 64K or 128K of external SRAM memory.
293 - for 128K there are 4x32K chips at bank 0,1,2,3.
294 - for 64K there are 2x32K chips at bank 1,2.
295 - for 32K there is one 32K chip at bank 0.
297 FlexCop works only with one bank at a time. The bank is selected
298 by bits 28-29 of the 0x700 register.
300 bank 0 covers addresses 0x00000-0x07fff
301 bank 1 covers addresses 0x08000-0x0ffff
302 bank 2 covers addresses 0x10000-0x17fff
303 bank 3 covers addresses 0x18000-0x1ffff */
305 static int flexcop_sram_detect(struct flexcop_device
*fc
)
307 flexcop_ibi_value r208
, r71c_0
, vr71c_1
;
308 r208
= fc
->read_ibi_reg(fc
, ctrl_208
);
309 fc
->write_ibi_reg(fc
, ctrl_208
, ibi_zero
);
311 r71c_0
= fc
->read_ibi_reg(fc
, wan_ctrl_reg_71c
);
312 write_reg_dw(adapter
, 0x71c, 1);
313 tmp3
= read_reg_dw(adapter
, 0x71c);
314 dprintk("%s: tmp3 = %x\n", __func__
, tmp3
);
315 write_reg_dw(adapter
, 0x71c, tmp2
);
317 // check for internal SRAM ???
320 sram_set_size(adapter
, 0x10000);
322 write_reg_dw(adapter
, 0x208, tmp
);
323 dprintk("%s: sram size = 32K\n", __func__
);
327 if (sram_test_location(adapter
, 0x20000, 0x18000) != 0) {
328 sram_set_size(adapter
, 0x20000);
330 write_reg_dw(adapter
, 0x208, tmp
);
331 dprintk("%s: sram size = 128K\n", __func__
);
335 if (sram_test_location(adapter
, 0x00000, 0x10000) != 0) {
336 sram_set_size(adapter
, 0x00000);
338 write_reg_dw(adapter
, 0x208, tmp
);
339 dprintk("%s: sram size = 64K\n", __func__
);
343 if (sram_test_location(adapter
, 0x10000, 0x00000) != 0) {
344 sram_set_size(adapter
, 0x10000);
346 write_reg_dw(adapter
, 0x208, tmp
);
347 dprintk("%s: sram size = 32K\n", __func__
);
351 sram_set_size(adapter
, 0x10000);
353 write_reg_dw(adapter
, 0x208, tmp
);
354 dprintk("%s: SRAM detection failed. Set to 32K \n", __func__
);
358 static void sll_detect_sram_size(struct adapter
*adapter
)
360 sram_detect_for_flex2(adapter
);