1/*
2 * This file is part of linux driver the digital TV devices equipped with B2C2 FlexcopII(b)/III
3 *
4 * flexcop-sram.c - functions for controlling the SRAM.
5 *
6 * see flexcop.c for copyright information.
7 */
8#include "flexcop.h"
9
10static void flexcop_sram_set_chip (struct flexcop_device *fc, flexcop_sram_type_t type)
11{
12	flexcop_set_ibi_value(wan_ctrl_reg_71c,sram_chip,type);
13}
14
15int flexcop_sram_init(struct flexcop_device *fc)
16{
17	switch (fc->rev) {
18		case FLEXCOP_II:
19		case FLEXCOP_IIB:
20			flexcop_sram_set_chip(fc,FC_SRAM_1_32KB);
21			break;
22		case FLEXCOP_III:
23			flexcop_sram_set_chip(fc,FC_SRAM_1_48KB);
24			break;
25		default:
26			return -EINVAL;
27	}
28	return 0;
29}
30
31int flexcop_sram_set_dest(struct flexcop_device *fc, flexcop_sram_dest_t dest, flexcop_sram_dest_target_t target)
32{
33	flexcop_ibi_value v;
34
35	v = fc->read_ibi_reg(fc,sram_dest_reg_714);
36
37	if (fc->rev != FLEXCOP_III && target == FC_SRAM_DEST_TARGET_FC3_CA) {
38		err("SRAM destination target to available on FlexCopII(b)\n");
39		return -EINVAL;
40	}
41
42	deb_sram("sram dest: %x target: %x\n",dest, target);
43
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;
52
53	fc->write_ibi_reg(fc,sram_dest_reg_714,v);
54	udelay(1000); /* TODO delay really necessary */
55
56	return 0;
57}
58EXPORT_SYMBOL(flexcop_sram_set_dest);
59
60void flexcop_wan_set_speed(struct flexcop_device *fc, flexcop_wan_speed_t s)
61{
62	flexcop_set_ibi_value(wan_ctrl_reg_71c,wan_speed_sig,s);
63}
64EXPORT_SYMBOL(flexcop_wan_set_speed);
65
66void flexcop_sram_ctrl(struct flexcop_device *fc, int usb_wan, int sramdma, int maximumfill)
67{
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);
73}
74EXPORT_SYMBOL(flexcop_sram_ctrl);
75