2 * This file is part of linux driver the digital TV devices equipped with B2C2 FlexcopII(b)/III
4 * flexcop-sram.c - functions for controlling the SRAM.
6 * see flexcop.c for copyright information.
10 static void flexcop_sram_set_chip (struct flexcop_device *fc, flexcop_sram_type_t type)
12 flexcop_set_ibi_value(wan_ctrl_reg_71c,sram_chip,type);
15 int flexcop_sram_init(struct flexcop_device *fc)
20 flexcop_sram_set_chip(fc,FC_SRAM_1_32KB);
23 flexcop_sram_set_chip(fc,FC_SRAM_1_48KB);
31 int flexcop_sram_set_dest(struct flexcop_device *fc, flexcop_sram_dest_t dest, flexcop_sram_dest_target_t target)
35 v = fc->read_ibi_reg(fc,sram_dest_reg_714);
37 if (fc->rev != FLEXCOP_III && target == FC_SRAM_DEST_TARGET_FC3_CA) {
38 err("SRAM destination target to available on FlexCopII(b)\n");
42 deb_sram("sram dest: %x target: %x\n",dest, target);
44 if (dest & FC_SRAM_DEST_NET)
45 v.sram_dest_reg_714.NET_Dest = target;
46 if (dest & FC_SRAM_DEST_CAI)
47 v.sram_dest_reg_714.CAI_Dest = target;
48 if (dest & FC_SRAM_DEST_CAO)
49 v.sram_dest_reg_714.CAO_Dest = target;
50 if (dest & FC_SRAM_DEST_MEDIA)
51 v.sram_dest_reg_714.MEDIA_Dest = target;
53 fc->write_ibi_reg(fc,sram_dest_reg_714,v);
54 udelay(1000); /* TODO delay really necessary */
58 EXPORT_SYMBOL(flexcop_sram_set_dest);
60 void flexcop_wan_set_speed(struct flexcop_device *fc, flexcop_wan_speed_t s)
62 flexcop_set_ibi_value(wan_ctrl_reg_71c,wan_speed_sig,s);
64 EXPORT_SYMBOL(flexcop_wan_set_speed);
66 void flexcop_sram_ctrl(struct flexcop_device *fc, int usb_wan, int sramdma, int maximumfill)
68 flexcop_ibi_value v = fc->read_ibi_reg(fc,sram_dest_reg_714);
69 v.sram_dest_reg_714.ctrl_usb_wan = usb_wan;
70 v.sram_dest_reg_714.ctrl_sramdma = sramdma;
71 v.sram_dest_reg_714.ctrl_maximumfill = maximumfill;
72 fc->write_ibi_reg(fc,sram_dest_reg_714,v);
74 EXPORT_SYMBOL(flexcop_sram_ctrl);
77 static void flexcop_sram_write(struct adapter *adapter, u32 bank, u32 addr, u8 *buf, u32 len)
82 for (i = 0; i < len; i++) {
83 command = bank | addr | 0x04000000 | (*buf << 0x10);
87 while (((read_reg_dw(adapter, 0x700) & 0x80000000) != 0) && (retries > 0)) {
93 printk("%s: SRAM timeout\n", __func__);
95 write_reg_dw(adapter, 0x700, command);
102 static void flex_sram_read(struct adapter *adapter, u32 bank, u32 addr, u8 *buf, u32 len)
107 for (i = 0; i < len; i++) {
108 command = bank | addr | 0x04008000;
112 while (((read_reg_dw(adapter, 0x700) & 0x80000000) != 0) && (retries > 0)) {
118 printk("%s: SRAM timeout\n", __func__);
120 write_reg_dw(adapter, 0x700, command);
124 while (((read_reg_dw(adapter, 0x700) & 0x80000000) != 0) && (retries > 0)) {
130 printk("%s: SRAM timeout\n", __func__);
132 value = read_reg_dw(adapter, 0x700) >> 0x10;
134 *buf = (value & 0xff);
141 static void sram_write_chunk(struct adapter *adapter, u32 addr, u8 *buf, u16 len)
147 if (adapter->dw_sram_type == 0x20000) {
148 bank = (addr & 0x18000) << 0x0d;
151 if (adapter->dw_sram_type == 0x00000) {
152 if ((addr >> 0x0f) == 0)
158 flex_sram_write(adapter, bank, addr & 0x7fff, buf, len);
161 static void sram_read_chunk(struct adapter *adapter, u32 addr, u8 *buf, u16 len)
167 if (adapter->dw_sram_type == 0x20000) {
168 bank = (addr & 0x18000) << 0x0d;
171 if (adapter->dw_sram_type == 0x00000) {
172 if ((addr >> 0x0f) == 0)
178 flex_sram_read(adapter, bank, addr & 0x7fff, buf, len);
181 static void sram_read(struct adapter *adapter, u32 addr, u8 *buf, u32 len)
188 // check if the address range belongs to the same
189 // 32K memory chip. If not, the data is read from
190 // one chip at a time.
191 if ((addr >> 0x0f) != ((addr + len - 1) >> 0x0f)) {
192 length = (((addr >> 0x0f) + 1) << 0x0f) - addr;
195 sram_read_chunk(adapter, addr, buf, length);
197 addr = addr + length;
203 static void sram_write(struct adapter *adapter, u32 addr, u8 *buf, u32 len)
210 // check if the address range belongs to the same
211 // 32K memory chip. If not, the data is written to
212 // one chip at a time.
213 if ((addr >> 0x0f) != ((addr + len - 1) >> 0x0f)) {
214 length = (((addr >> 0x0f) + 1) << 0x0f) - addr;
217 sram_write_chunk(adapter, addr, buf, length);
219 addr = addr + length;
225 static void sram_set_size(struct adapter *adapter, u32 mask)
227 write_reg_dw(adapter, 0x71c, (mask | (~0x30000 & read_reg_dw(adapter, 0x71c))));
230 static void sram_init(struct adapter *adapter)
234 tmp = read_reg_dw(adapter, 0x71c);
236 write_reg_dw(adapter, 0x71c, 1);
238 if (read_reg_dw(adapter, 0x71c) != 0) {
239 write_reg_dw(adapter, 0x71c, tmp);
241 adapter->dw_sram_type = tmp & 0x30000;
243 ddprintk("%s: dw_sram_type = %x\n", __func__, adapter->dw_sram_type);
247 adapter->dw_sram_type = 0x10000;
249 ddprintk("%s: dw_sram_type = %x\n", __func__, adapter->dw_sram_type);
252 /* return value is never used? */
253 /* return adapter->dw_sram_type; */
256 static int sram_test_location(struct adapter *adapter, u32 mask, u32 addr)
260 dprintk("%s: mask = %x, addr = %x\n", __func__, mask, addr);
262 sram_set_size(adapter, mask);
268 sram_write(adapter, addr, &tmp2, 1);
269 sram_write(adapter, addr + 4, &tmp1, 1);
275 sram_read(adapter, addr, &tmp2, 1);
276 sram_read(adapter, addr, &tmp2, 1);
278 dprintk("%s: wrote 0xa5, read 0x%2x\n", __func__, tmp2);
286 sram_write(adapter, addr, &tmp2, 1);
287 sram_write(adapter, addr + 4, &tmp1, 1);
293 sram_read(adapter, addr, &tmp2, 1);
294 sram_read(adapter, addr, &tmp2, 1);
296 dprintk("%s: wrote 0x5a, read 0x%2x\n", __func__, tmp2);
304 static u32 sram_length(struct adapter *adapter)
306 if (adapter->dw_sram_type == 0x10000)
308 if (adapter->dw_sram_type == 0x00000)
310 if (adapter->dw_sram_type == 0x20000)
311 return 131072; // 128K
316 /* FlexcopII can work with 32K, 64K or 128K of external SRAM memory.
317 - for 128K there are 4x32K chips at bank 0,1,2,3.
318 - for 64K there are 2x32K chips at bank 1,2.
319 - for 32K there is one 32K chip at bank 0.
321 FlexCop works only with one bank at a time. The bank is selected
322 by bits 28-29 of the 0x700 register.
324 bank 0 covers addresses 0x00000-0x07fff
325 bank 1 covers addresses 0x08000-0x0ffff
326 bank 2 covers addresses 0x10000-0x17fff
327 bank 3 covers addresses 0x18000-0x1ffff
330 static int flexcop_sram_detect(struct flexcop_device *fc)
332 flexcop_ibi_value r208,r71c_0,vr71c_1;
334 r208 = fc->read_ibi_reg(fc, ctrl_208);
335 fc->write_ibi_reg(fc, ctrl_208, ibi_zero);
337 r71c_0 = fc->read_ibi_reg(fc, wan_ctrl_reg_71c);
339 write_reg_dw(adapter, 0x71c, 1);
341 tmp3 = read_reg_dw(adapter, 0x71c);
343 dprintk("%s: tmp3 = %x\n", __func__, tmp3);
345 write_reg_dw(adapter, 0x71c, tmp2);
347 // check for internal SRAM ???
350 sram_set_size(adapter, 0x10000);
352 write_reg_dw(adapter, 0x208, tmp);
354 dprintk("%s: sram size = 32K\n", __func__);
359 if (sram_test_location(adapter, 0x20000, 0x18000) != 0) {
360 sram_set_size(adapter, 0x20000);
362 write_reg_dw(adapter, 0x208, tmp);
364 dprintk("%s: sram size = 128K\n", __func__);
369 if (sram_test_location(adapter, 0x00000, 0x10000) != 0) {
370 sram_set_size(adapter, 0x00000);
372 write_reg_dw(adapter, 0x208, tmp);
374 dprintk("%s: sram size = 64K\n", __func__);
379 if (sram_test_location(adapter, 0x10000, 0x00000) != 0) {
380 sram_set_size(adapter, 0x10000);
382 write_reg_dw(adapter, 0x208, tmp);
384 dprintk("%s: sram size = 32K\n", __func__);
389 sram_set_size(adapter, 0x10000);
391 write_reg_dw(adapter, 0x208, tmp);
393 dprintk("%s: SRAM detection failed. Set to 32K \n", __func__);
398 static void sll_detect_sram_size(struct adapter *adapter)
400 sram_detect_for_flex2(adapter);