summaryrefslogtreecommitdiffstats
path: root/src/af903x-devices.c
blob: e7ecfd4494fdc2d1c5931bf3292e5774ba4c47e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include "af903x.h"

bool  DevicePower;
static int af903x_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
{
    int ret =0;
    deb_data("%s: onoff:%d\n", __func__, onoff);

	if ( PDC->fc[adap->id].bEnPID !=  onoff )
		DL_ResetPID((BYTE)adap->id);

	PDC->fc[adap->id].bEnPID =  onoff;
	
	DL_PIDOnOff((BYTE)adap->id,onoff);

    return ret;
}

static int af903x_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pidnum,
    int onoff)
{
    int ret = 0;
    Pid pid;
    deb_data("- %s: set pid filter, index %d, pid %x, onoff %d, now_onoff %d.\n",
	__func__, index, pidnum, onoff, PDC->fc[adap->id].bEnPID);

	if (onoff && !PDC->fc[adap->id].bEnPID)
	{
		DL_ResetPID((BYTE)adap->id);
		PDC->fc[adap->id].bEnPID =  onoff;
		DL_PIDOnOff((BYTE)adap->id,onoff);
		pid.sectionType = SectionType_TABLE;
    		pid.table = 0x00;
    		pid.duration = 0xFF;
	}
	
    	pid.value = (Word)pidnum;
	if (onoff){
		ret = DL_AddPID((BYTE)adap->id, index, pid);
	}else{
		ret = DL_RemovePID((BYTE)adap->id, index, pid);
	}
    return ret;
}

static int af903x_download_firmware(struct usb_device *udev, const struct firmware *fw)
{
	int ret=0;
	deb_data("- Enter %s Function -\n",__FUNCTION__);
	
	return ret;
}

static int af903x_powerctrl(struct dvb_usb_device *d, int onoff)
{

	int ret;
	DevicePower = onoff;

	deb_data("- Enter %s Function - chip=%d:%s\n",__FUNCTION__, d->adapter->id, onoff?"ON":"OFF");
	ret = DL_ApCtrl(d->adapter->id, onoff);
	if(ret) deb_data("	af903x_powerctrl Fail: 0x%04X\n", ret);
	return ret;
}

static int af903x_identify_state(struct usb_device *udev, struct dvb_usb_device_properties *props,
			struct dvb_usb_device_description **desc, int *cold)
{
	deb_data("- Enter %s Function -\n",__FUNCTION__);
	*cold = 0;

	return 0;
}

static int af903x_frontend_attach(struct dvb_usb_adapter *adap)
{
	deb_data("- Enter %s Function - chip=%d\n", __FUNCTION__, adap->id);
	adap->fe_adap[0].fe = af903x_attach(1);	
	return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
}

static int af903x_tuner_attach(struct dvb_usb_adapter *adap)
{
	deb_data("- Enter %s Function - chip=%d\n",__FUNCTION__, adap->id);
	tuner_attach(adap->fe_adap[0].fe);
	return  0;
}

static int af903x_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
{
	deb_data("- Enter %s Function - (%s) streaming state for chip=%d\n",__FUNCTION__, onoff?"ON":"OFF", adap->id);
	//PID off
	DL_ResetPID((BYTE)adap->id);
	PDC->fc[adap->id].bEnPID =  0;
	DL_PIDOnOff((BYTE)adap->id,0);
	return 0;
}


struct usb_device_id af903x_usb_id_table[] = {
	{ USB_DEVICE(0x15A4,0x1000) },
	{ USB_DEVICE(0x15A4,0x1001) },
	{ USB_DEVICE(0x15A4,0x1002) },
	{ USB_DEVICE(0x15A4,0x1003) },
	{ USB_DEVICE(0x15A4,0x9035) },
	{ USB_DEVICE(USB_VID_ASUS, USB_PID_ASUS_U3100MINI_PLUS) },
	{ 0},           /* Terminating entry */
};

MODULE_DEVICE_TABLE(usb, af903x_usb_id_table);

struct dvb_usb_device_properties af903x_properties[] = {
	{
		.usb_ctrl = DEVICE_SPECIFIC,
		.download_firmware = af903x_download_firmware,
		.no_reconnect = 1,
		.power_ctrl = af903x_powerctrl,
		.identify_state = af903x_identify_state,
		.num_adapters = 1,
		.adapter = {
			{
				.fe[0].caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
				.fe[0].pid_filter_count = 32,
				.fe[0].pid_filter = af903x_pid_filter,
				.fe[0].pid_filter_ctrl = af903x_pid_filter_ctrl,
				.fe[0].frontend_attach = af903x_frontend_attach,
				.fe[0].tuner_attach = af903x_tuner_attach,
				.fe[0].streaming_ctrl = af903x_streaming_ctrl,
				.fe[0].stream = {
					.type = USB_BULK,
					.count = 4,
					.endpoint = 0x84,
					.u = {
						.bulk = {
							.buffersize = 65424,
						}
					}
				}
			}
		},
		.num_device_descs = 2,
		.devices = {
			{
				"ITEtech USB2.0 DVB-T Receiver", {
					&af903x_usb_id_table[0],
					&af903x_usb_id_table[1],
					&af903x_usb_id_table[2],
					&af903x_usb_id_table[3],
					&af903x_usb_id_table[4],
					NULL
				}, {
					NULL
				}
			}, {
				"Asus U3100MINI_PLUS/T/RC Receiver", {
					&af903x_usb_id_table[5],
					NULL
				}, {
					NULL
				}
			}, {
				NULL
			}
		}
	}
};

int af903x_device_count = ARRAY_SIZE(af903x_properties);