aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/dvb/b2c2/flexcop-sram.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/dvb/b2c2/flexcop-sram.c')
-rw-r--r--drivers/media/dvb/b2c2/flexcop-sram.c112
1 files changed, 36 insertions, 76 deletions
diff --git a/drivers/media/dvb/b2c2/flexcop-sram.c b/drivers/media/dvb/b2c2/flexcop-sram.c
index cda69528548a..f2199e43e803 100644
--- a/drivers/media/dvb/b2c2/flexcop-sram.c
+++ b/drivers/media/dvb/b2c2/flexcop-sram.c
@@ -1,45 +1,43 @@
1/* 1/*
2 * This file is part of linux driver the digital TV devices equipped with B2C2 FlexcopII(b)/III 2 * Linux driver for digital TV devices equipped with B2C2 FlexcopII(b)/III
3 * 3 * flexcop-sram.c - functions for controlling the SRAM
4 * flexcop-sram.c - functions for controlling the SRAM. 4 * see flexcop.c for copyright information
5 *
6 * see flexcop.c for copyright information.
7 */ 5 */
8#include "flexcop.h" 6#include "flexcop.h"
9 7
10static void flexcop_sram_set_chip (struct flexcop_device *fc, flexcop_sram_type_t type) 8static void flexcop_sram_set_chip(struct flexcop_device *fc,
9 flexcop_sram_type_t type)
11{ 10{
12 flexcop_set_ibi_value(wan_ctrl_reg_71c,sram_chip,type); 11 flexcop_set_ibi_value(wan_ctrl_reg_71c, sram_chip, type);
13} 12}
14 13
15int flexcop_sram_init(struct flexcop_device *fc) 14int flexcop_sram_init(struct flexcop_device *fc)
16{ 15{
17 switch (fc->rev) { 16 switch (fc->rev) {
18 case FLEXCOP_II: 17 case FLEXCOP_II:
19 case FLEXCOP_IIB: 18 case FLEXCOP_IIB:
20 flexcop_sram_set_chip(fc,FC_SRAM_1_32KB); 19 flexcop_sram_set_chip(fc, FC_SRAM_1_32KB);
21 break; 20 break;
22 case FLEXCOP_III: 21 case FLEXCOP_III:
23 flexcop_sram_set_chip(fc,FC_SRAM_1_48KB); 22 flexcop_sram_set_chip(fc, FC_SRAM_1_48KB);
24 break; 23 break;
25 default: 24 default:
26 return -EINVAL; 25 return -EINVAL;
27 } 26 }
28 return 0; 27 return 0;
29} 28}
30 29
31int flexcop_sram_set_dest(struct flexcop_device *fc, flexcop_sram_dest_t dest, flexcop_sram_dest_target_t target) 30int flexcop_sram_set_dest(struct flexcop_device *fc, flexcop_sram_dest_t dest,
31 flexcop_sram_dest_target_t target)
32{ 32{
33 flexcop_ibi_value v; 33 flexcop_ibi_value v;
34 34 v = fc->read_ibi_reg(fc, sram_dest_reg_714);
35 v = fc->read_ibi_reg(fc,sram_dest_reg_714);
36 35
37 if (fc->rev != FLEXCOP_III && target == FC_SRAM_DEST_TARGET_FC3_CA) { 36 if (fc->rev != FLEXCOP_III && target == FC_SRAM_DEST_TARGET_FC3_CA) {
38 err("SRAM destination target to available on FlexCopII(b)\n"); 37 err("SRAM destination target to available on FlexCopII(b)\n");
39 return -EINVAL; 38 return -EINVAL;
40 } 39 }
41 40 deb_sram("sram dest: %x target: %x\n", dest, target);
42 deb_sram("sram dest: %x target: %x\n",dest, target);
43 41
44 if (dest & FC_SRAM_DEST_NET) 42 if (dest & FC_SRAM_DEST_NET)
45 v.sram_dest_reg_714.NET_Dest = target; 43 v.sram_dest_reg_714.NET_Dest = target;
@@ -154,14 +152,12 @@ static void sram_write_chunk(struct adapter *adapter, u32 addr, u8 *buf, u16 len
154 else 152 else
155 bank = 0x10000000; 153 bank = 0x10000000;
156 } 154 }
157
158 flex_sram_write(adapter, bank, addr & 0x7fff, buf, len); 155 flex_sram_write(adapter, bank, addr & 0x7fff, buf, len);
159} 156}
160 157
161static void sram_read_chunk(struct adapter *adapter, u32 addr, u8 *buf, u16 len) 158static void sram_read_chunk(struct adapter *adapter, u32 addr, u8 *buf, u16 len)
162{ 159{
163 u32 bank; 160 u32 bank;
164
165 bank = 0; 161 bank = 0;
166 162
167 if (adapter->dw_sram_type == 0x20000) { 163 if (adapter->dw_sram_type == 0x20000) {
@@ -174,26 +170,22 @@ static void sram_read_chunk(struct adapter *adapter, u32 addr, u8 *buf, u16 len)
174 else 170 else
175 bank = 0x10000000; 171 bank = 0x10000000;
176 } 172 }
177
178 flex_sram_read(adapter, bank, addr & 0x7fff, buf, len); 173 flex_sram_read(adapter, bank, addr & 0x7fff, buf, len);
179} 174}
180 175
181static void sram_read(struct adapter *adapter, u32 addr, u8 *buf, u32 len) 176static void sram_read(struct adapter *adapter, u32 addr, u8 *buf, u32 len)
182{ 177{
183 u32 length; 178 u32 length;
184
185 while (len != 0) { 179 while (len != 0) {
186 length = len; 180 length = len;
187 181 /* check if the address range belongs to the same
188 // check if the address range belongs to the same 182 * 32K memory chip. If not, the data is read
189 // 32K memory chip. If not, the data is read from 183 * from one chip at a time */
190 // one chip at a time.
191 if ((addr >> 0x0f) != ((addr + len - 1) >> 0x0f)) { 184 if ((addr >> 0x0f) != ((addr + len - 1) >> 0x0f)) {
192 length = (((addr >> 0x0f) + 1) << 0x0f) - addr; 185 length = (((addr >> 0x0f) + 1) << 0x0f) - addr;
193 } 186 }
194 187
195 sram_read_chunk(adapter, addr, buf, length); 188 sram_read_chunk(adapter, addr, buf, length);
196
197 addr = addr + length; 189 addr = addr + length;
198 buf = buf + length; 190 buf = buf + length;
199 len = len - length; 191 len = len - length;
@@ -203,19 +195,17 @@ static void sram_read(struct adapter *adapter, u32 addr, u8 *buf, u32 len)
203static void sram_write(struct adapter *adapter, u32 addr, u8 *buf, u32 len) 195static void sram_write(struct adapter *adapter, u32 addr, u8 *buf, u32 len)
204{ 196{
205 u32 length; 197 u32 length;
206
207 while (len != 0) { 198 while (len != 0) {
208 length = len; 199 length = len;
209 200
210 // check if the address range belongs to the same 201 /* check if the address range belongs to the same
211 // 32K memory chip. If not, the data is written to 202 * 32K memory chip. If not, the data is
212 // one chip at a time. 203 * written to one chip at a time */
213 if ((addr >> 0x0f) != ((addr + len - 1) >> 0x0f)) { 204 if ((addr >> 0x0f) != ((addr + len - 1) >> 0x0f)) {
214 length = (((addr >> 0x0f) + 1) << 0x0f) - addr; 205 length = (((addr >> 0x0f) + 1) << 0x0f) - addr;
215 } 206 }
216 207
217 sram_write_chunk(adapter, addr, buf, length); 208 sram_write_chunk(adapter, addr, buf, length);
218
219 addr = addr + length; 209 addr = addr + length;
220 buf = buf + length; 210 buf = buf + length;
221 len = len - length; 211 len = len - length;
@@ -224,39 +214,29 @@ static void sram_write(struct adapter *adapter, u32 addr, u8 *buf, u32 len)
224 214
225static void sram_set_size(struct adapter *adapter, u32 mask) 215static void sram_set_size(struct adapter *adapter, u32 mask)
226{ 216{
227 write_reg_dw(adapter, 0x71c, (mask | (~0x30000 & read_reg_dw(adapter, 0x71c)))); 217 write_reg_dw(adapter, 0x71c,
218 (mask | (~0x30000 & read_reg_dw(adapter, 0x71c))));
228} 219}
229 220
230static void sram_init(struct adapter *adapter) 221static void sram_init(struct adapter *adapter)
231{ 222{
232 u32 tmp; 223 u32 tmp;
233
234 tmp = read_reg_dw(adapter, 0x71c); 224 tmp = read_reg_dw(adapter, 0x71c);
235
236 write_reg_dw(adapter, 0x71c, 1); 225 write_reg_dw(adapter, 0x71c, 1);
237 226
238 if (read_reg_dw(adapter, 0x71c) != 0) { 227 if (read_reg_dw(adapter, 0x71c) != 0) {
239 write_reg_dw(adapter, 0x71c, tmp); 228 write_reg_dw(adapter, 0x71c, tmp);
240
241 adapter->dw_sram_type = tmp & 0x30000; 229 adapter->dw_sram_type = tmp & 0x30000;
242
243 ddprintk("%s: dw_sram_type = %x\n", __func__, adapter->dw_sram_type); 230 ddprintk("%s: dw_sram_type = %x\n", __func__, adapter->dw_sram_type);
244
245 } else { 231 } else {
246
247 adapter->dw_sram_type = 0x10000; 232 adapter->dw_sram_type = 0x10000;
248
249 ddprintk("%s: dw_sram_type = %x\n", __func__, adapter->dw_sram_type); 233 ddprintk("%s: dw_sram_type = %x\n", __func__, adapter->dw_sram_type);
250 } 234 }
251
252 /* return value is never used? */
253/* return adapter->dw_sram_type; */
254} 235}
255 236
256static int sram_test_location(struct adapter *adapter, u32 mask, u32 addr) 237static int sram_test_location(struct adapter *adapter, u32 mask, u32 addr)
257{ 238{
258 u8 tmp1, tmp2; 239 u8 tmp1, tmp2;
259
260 dprintk("%s: mask = %x, addr = %x\n", __func__, mask, addr); 240 dprintk("%s: mask = %x, addr = %x\n", __func__, mask, addr);
261 241
262 sram_set_size(adapter, mask); 242 sram_set_size(adapter, mask);
@@ -269,7 +249,6 @@ static int sram_test_location(struct adapter *adapter, u32 mask, u32 addr)
269 sram_write(adapter, addr + 4, &tmp1, 1); 249 sram_write(adapter, addr + 4, &tmp1, 1);
270 250
271 tmp2 = 0; 251 tmp2 = 0;
272
273 mdelay(20); 252 mdelay(20);
274 253
275 sram_read(adapter, addr, &tmp2, 1); 254 sram_read(adapter, addr, &tmp2, 1);
@@ -287,7 +266,6 @@ static int sram_test_location(struct adapter *adapter, u32 mask, u32 addr)
287 sram_write(adapter, addr + 4, &tmp1, 1); 266 sram_write(adapter, addr + 4, &tmp1, 1);
288 267
289 tmp2 = 0; 268 tmp2 = 0;
290
291 mdelay(20); 269 mdelay(20);
292 270
293 sram_read(adapter, addr, &tmp2, 1); 271 sram_read(adapter, addr, &tmp2, 1);
@@ -297,26 +275,24 @@ static int sram_test_location(struct adapter *adapter, u32 mask, u32 addr)
297 275
298 if (tmp2 != 0x5a) 276 if (tmp2 != 0x5a)
299 return 0; 277 return 0;
300
301 return 1; 278 return 1;
302} 279}
303 280
304static u32 sram_length(struct adapter *adapter) 281static u32 sram_length(struct adapter *adapter)
305{ 282{
306 if (adapter->dw_sram_type == 0x10000) 283 if (adapter->dw_sram_type == 0x10000)
307 return 32768; // 32K 284 return 32768; /* 32K */
308 if (adapter->dw_sram_type == 0x00000) 285 if (adapter->dw_sram_type == 0x00000)
309 return 65536; // 64K 286 return 65536; /* 64K */
310 if (adapter->dw_sram_type == 0x20000) 287 if (adapter->dw_sram_type == 0x20000)
311 return 131072; // 128K 288 return 131072; /* 128K */
312 289 return 32768; /* 32K */
313 return 32768; // 32K
314} 290}
315 291
316/* FlexcopII can work with 32K, 64K or 128K of external SRAM memory. 292/* 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. 293 - for 128K there are 4x32K chips at bank 0,1,2,3.
318 - for 64K there are 2x32K chips at bank 1,2. 294 - for 64K there are 2x32K chips at bank 1,2.
319 - for 32K there is one 32K chip at bank 0. 295 - for 32K there is one 32K chip at bank 0.
320 296
321 FlexCop works only with one bank at a time. The bank is selected 297 FlexCop works only with one bank at a time. The bank is selected
322 by bits 28-29 of the 0x700 register. 298 by bits 28-29 of the 0x700 register.
@@ -324,24 +300,18 @@ static u32 sram_length(struct adapter *adapter)
324 bank 0 covers addresses 0x00000-0x07fff 300 bank 0 covers addresses 0x00000-0x07fff
325 bank 1 covers addresses 0x08000-0x0ffff 301 bank 1 covers addresses 0x08000-0x0ffff
326 bank 2 covers addresses 0x10000-0x17fff 302 bank 2 covers addresses 0x10000-0x17fff
327 bank 3 covers addresses 0x18000-0x1ffff 303 bank 3 covers addresses 0x18000-0x1ffff */
328*/
329 304
330static int flexcop_sram_detect(struct flexcop_device *fc) 305static int flexcop_sram_detect(struct flexcop_device *fc)
331{ 306{
332 flexcop_ibi_value r208,r71c_0,vr71c_1; 307 flexcop_ibi_value r208, r71c_0, vr71c_1;
333
334 r208 = fc->read_ibi_reg(fc, ctrl_208); 308 r208 = fc->read_ibi_reg(fc, ctrl_208);
335 fc->write_ibi_reg(fc, ctrl_208, ibi_zero); 309 fc->write_ibi_reg(fc, ctrl_208, ibi_zero);
336 310
337 r71c_0 = fc->read_ibi_reg(fc, wan_ctrl_reg_71c); 311 r71c_0 = fc->read_ibi_reg(fc, wan_ctrl_reg_71c);
338
339 write_reg_dw(adapter, 0x71c, 1); 312 write_reg_dw(adapter, 0x71c, 1);
340
341 tmp3 = read_reg_dw(adapter, 0x71c); 313 tmp3 = read_reg_dw(adapter, 0x71c);
342
343 dprintk("%s: tmp3 = %x\n", __func__, tmp3); 314 dprintk("%s: tmp3 = %x\n", __func__, tmp3);
344
345 write_reg_dw(adapter, 0x71c, tmp2); 315 write_reg_dw(adapter, 0x71c, tmp2);
346 316
347 // check for internal SRAM ??? 317 // check for internal SRAM ???
@@ -350,9 +320,7 @@ static int flexcop_sram_detect(struct flexcop_device *fc)
350 sram_set_size(adapter, 0x10000); 320 sram_set_size(adapter, 0x10000);
351 sram_init(adapter); 321 sram_init(adapter);
352 write_reg_dw(adapter, 0x208, tmp); 322 write_reg_dw(adapter, 0x208, tmp);
353
354 dprintk("%s: sram size = 32K\n", __func__); 323 dprintk("%s: sram size = 32K\n", __func__);
355
356 return 32; 324 return 32;
357 } 325 }
358 326
@@ -360,9 +328,7 @@ static int flexcop_sram_detect(struct flexcop_device *fc)
360 sram_set_size(adapter, 0x20000); 328 sram_set_size(adapter, 0x20000);
361 sram_init(adapter); 329 sram_init(adapter);
362 write_reg_dw(adapter, 0x208, tmp); 330 write_reg_dw(adapter, 0x208, tmp);
363
364 dprintk("%s: sram size = 128K\n", __func__); 331 dprintk("%s: sram size = 128K\n", __func__);
365
366 return 128; 332 return 128;
367 } 333 }
368 334
@@ -370,9 +336,7 @@ static int flexcop_sram_detect(struct flexcop_device *fc)
370 sram_set_size(adapter, 0x00000); 336 sram_set_size(adapter, 0x00000);
371 sram_init(adapter); 337 sram_init(adapter);
372 write_reg_dw(adapter, 0x208, tmp); 338 write_reg_dw(adapter, 0x208, tmp);
373
374 dprintk("%s: sram size = 64K\n", __func__); 339 dprintk("%s: sram size = 64K\n", __func__);
375
376 return 64; 340 return 64;
377 } 341 }
378 342
@@ -380,18 +344,14 @@ static int flexcop_sram_detect(struct flexcop_device *fc)
380 sram_set_size(adapter, 0x10000); 344 sram_set_size(adapter, 0x10000);
381 sram_init(adapter); 345 sram_init(adapter);
382 write_reg_dw(adapter, 0x208, tmp); 346 write_reg_dw(adapter, 0x208, tmp);
383
384 dprintk("%s: sram size = 32K\n", __func__); 347 dprintk("%s: sram size = 32K\n", __func__);
385
386 return 32; 348 return 32;
387 } 349 }
388 350
389 sram_set_size(adapter, 0x10000); 351 sram_set_size(adapter, 0x10000);
390 sram_init(adapter); 352 sram_init(adapter);
391 write_reg_dw(adapter, 0x208, tmp); 353 write_reg_dw(adapter, 0x208, tmp);
392
393 dprintk("%s: SRAM detection failed. Set to 32K \n", __func__); 354 dprintk("%s: SRAM detection failed. Set to 32K \n", __func__);
394
395 return 0; 355 return 0;
396} 356}
397 357