Commit | Line | Data |
---|---|---|
fb41f5a7 PB |
1 | /* Frontend part of the Linux driver for the WideView/ Yakumo/ Hama/ |
2 | * Typhoon/ Yuan DVB-T USB2.0 receiver. | |
776338e1 JS |
3 | * |
4 | * Copyright (C) 2005 Patrick Boettcher <patrick.boettcher@desy.de> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify it | |
7 | * under the terms of the GNU General Public License as published by the Free | |
8 | * Software Foundation, version 2. | |
9 | * | |
10 | * see Documentation/dvb/README.dvb-usb for more information | |
11 | */ | |
12 | #include "dtt200u.h" | |
13 | ||
14 | struct dtt200u_fe_state { | |
15 | struct dvb_usb_device *d; | |
16 | ||
0df289a2 | 17 | enum fe_status stat; |
d590f9c2 | 18 | |
adcc8f0e | 19 | struct dtv_frontend_properties fep; |
776338e1 JS |
20 | struct dvb_frontend frontend; |
21 | }; | |
22 | ||
0df289a2 MCC |
23 | static int dtt200u_fe_read_status(struct dvb_frontend *fe, |
24 | enum fe_status *stat) | |
776338e1 JS |
25 | { |
26 | struct dtt200u_fe_state *state = fe->demodulator_priv; | |
d590f9c2 PB |
27 | u8 st = GET_TUNE_STATUS, b[3]; |
28 | ||
29 | dvb_usb_generic_rw(state->d,&st,1,b,3,0); | |
776338e1 | 30 | |
d590f9c2 | 31 | switch (b[0]) { |
776338e1 | 32 | case 0x01: |
d590f9c2 PB |
33 | *stat = FE_HAS_SIGNAL | FE_HAS_CARRIER | |
34 | FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK; | |
776338e1 | 35 | break; |
d590f9c2 PB |
36 | case 0x00: /* pending */ |
37 | *stat = FE_TIMEDOUT; /* during set_frontend */ | |
776338e1 JS |
38 | break; |
39 | default: | |
d590f9c2 PB |
40 | case 0x02: /* failed */ |
41 | *stat = 0; | |
776338e1 JS |
42 | break; |
43 | } | |
776338e1 JS |
44 | return 0; |
45 | } | |
d590f9c2 | 46 | |
776338e1 JS |
47 | static int dtt200u_fe_read_ber(struct dvb_frontend* fe, u32 *ber) |
48 | { | |
49 | struct dtt200u_fe_state *state = fe->demodulator_priv; | |
d590f9c2 PB |
50 | u8 bw = GET_VIT_ERR_CNT,b[3]; |
51 | dvb_usb_generic_rw(state->d,&bw,1,b,3,0); | |
52 | *ber = (b[0] << 16) | (b[1] << 8) | b[2]; | |
776338e1 JS |
53 | return 0; |
54 | } | |
55 | ||
56 | static int dtt200u_fe_read_unc_blocks(struct dvb_frontend* fe, u32 *unc) | |
57 | { | |
58 | struct dtt200u_fe_state *state = fe->demodulator_priv; | |
d590f9c2 PB |
59 | u8 bw = GET_RS_UNCOR_BLK_CNT,b[2]; |
60 | ||
61 | dvb_usb_generic_rw(state->d,&bw,1,b,2,0); | |
62 | *unc = (b[0] << 8) | b[1]; | |
776338e1 JS |
63 | return 0; |
64 | } | |
65 | ||
66 | static int dtt200u_fe_read_signal_strength(struct dvb_frontend* fe, u16 *strength) | |
67 | { | |
68 | struct dtt200u_fe_state *state = fe->demodulator_priv; | |
d590f9c2 | 69 | u8 bw = GET_AGC, b; |
776338e1 JS |
70 | dvb_usb_generic_rw(state->d,&bw,1,&b,1,0); |
71 | *strength = (b << 8) | b; | |
72 | return 0; | |
73 | } | |
74 | ||
75 | static int dtt200u_fe_read_snr(struct dvb_frontend* fe, u16 *snr) | |
76 | { | |
77 | struct dtt200u_fe_state *state = fe->demodulator_priv; | |
78 | u8 bw = GET_SNR,br; | |
79 | dvb_usb_generic_rw(state->d,&bw,1,&br,1,0); | |
80 | *snr = ~((br << 8) | br); | |
81 | return 0; | |
82 | } | |
83 | ||
84 | static int dtt200u_fe_init(struct dvb_frontend* fe) | |
85 | { | |
86 | struct dtt200u_fe_state *state = fe->demodulator_priv; | |
d590f9c2 | 87 | u8 b = SET_INIT; |
776338e1 JS |
88 | return dvb_usb_generic_write(state->d,&b,1); |
89 | } | |
90 | ||
91 | static int dtt200u_fe_sleep(struct dvb_frontend* fe) | |
92 | { | |
93 | return dtt200u_fe_init(fe); | |
94 | } | |
95 | ||
96 | static int dtt200u_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune) | |
97 | { | |
98 | tune->min_delay_ms = 1500; | |
d590f9c2 PB |
99 | tune->step_size = 0; |
100 | tune->max_drift = 0; | |
776338e1 JS |
101 | return 0; |
102 | } | |
103 | ||
adcc8f0e | 104 | static int dtt200u_fe_set_frontend(struct dvb_frontend *fe) |
776338e1 | 105 | { |
adcc8f0e | 106 | struct dtv_frontend_properties *fep = &fe->dtv_property_cache; |
776338e1 | 107 | struct dtt200u_fe_state *state = fe->demodulator_priv; |
d590f9c2 | 108 | int i; |
0df289a2 | 109 | enum fe_status st; |
776338e1 | 110 | u16 freq = fep->frequency / 250000; |
d590f9c2 | 111 | u8 bwbuf[2] = { SET_BANDWIDTH, 0 },freqbuf[3] = { SET_RF_FREQ, 0, 0 }; |
776338e1 | 112 | |
adcc8f0e MCC |
113 | switch (fep->bandwidth_hz) { |
114 | case 8000000: | |
115 | bwbuf[1] = 8; | |
116 | break; | |
117 | case 7000000: | |
118 | bwbuf[1] = 7; | |
119 | break; | |
120 | case 6000000: | |
121 | bwbuf[1] = 6; | |
122 | break; | |
123 | default: | |
124 | return -EINVAL; | |
776338e1 | 125 | } |
776338e1 | 126 | |
776338e1 JS |
127 | dvb_usb_generic_write(state->d,bwbuf,2); |
128 | ||
129 | freqbuf[1] = freq & 0xff; | |
130 | freqbuf[2] = (freq >> 8) & 0xff; | |
131 | dvb_usb_generic_write(state->d,freqbuf,3); | |
132 | ||
d590f9c2 PB |
133 | for (i = 0; i < 30; i++) { |
134 | msleep(20); | |
135 | dtt200u_fe_read_status(fe, &st); | |
136 | if (st & FE_TIMEDOUT) | |
137 | continue; | |
138 | } | |
776338e1 JS |
139 | |
140 | return 0; | |
141 | } | |
142 | ||
7c61d80a | 143 | static int dtt200u_fe_get_frontend(struct dvb_frontend* fe) |
776338e1 | 144 | { |
7c61d80a | 145 | struct dtv_frontend_properties *fep = &fe->dtv_property_cache; |
776338e1 | 146 | struct dtt200u_fe_state *state = fe->demodulator_priv; |
adcc8f0e | 147 | memcpy(fep, &state->fep, sizeof(struct dtv_frontend_properties)); |
776338e1 JS |
148 | return 0; |
149 | } | |
150 | ||
151 | static void dtt200u_fe_release(struct dvb_frontend* fe) | |
152 | { | |
153 | struct dtt200u_fe_state *state = (struct dtt200u_fe_state*) fe->demodulator_priv; | |
154 | kfree(state); | |
155 | } | |
156 | ||
157 | static struct dvb_frontend_ops dtt200u_fe_ops; | |
158 | ||
159 | struct dvb_frontend* dtt200u_fe_attach(struct dvb_usb_device *d) | |
160 | { | |
161 | struct dtt200u_fe_state* state = NULL; | |
162 | ||
163 | /* allocate memory for the internal state */ | |
7408187d | 164 | state = kzalloc(sizeof(struct dtt200u_fe_state), GFP_KERNEL); |
776338e1 JS |
165 | if (state == NULL) |
166 | goto error; | |
776338e1 JS |
167 | |
168 | deb_info("attaching frontend dtt200u\n"); | |
169 | ||
170 | state->d = d; | |
171 | ||
dea74869 | 172 | memcpy(&state->frontend.ops,&dtt200u_fe_ops,sizeof(struct dvb_frontend_ops)); |
776338e1 JS |
173 | state->frontend.demodulator_priv = state; |
174 | ||
8397703e | 175 | return &state->frontend; |
776338e1 JS |
176 | error: |
177 | return NULL; | |
776338e1 JS |
178 | } |
179 | ||
180 | static struct dvb_frontend_ops dtt200u_fe_ops = { | |
adcc8f0e | 181 | .delsys = { SYS_DVBT }, |
776338e1 | 182 | .info = { |
d590f9c2 | 183 | .name = "WideView USB DVB-T", |
776338e1 JS |
184 | .frequency_min = 44250000, |
185 | .frequency_max = 867250000, | |
186 | .frequency_stepsize = 250000, | |
187 | .caps = FE_CAN_INVERSION_AUTO | | |
188 | FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 | | |
189 | FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO | | |
190 | FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO | | |
191 | FE_CAN_TRANSMISSION_MODE_AUTO | | |
192 | FE_CAN_GUARD_INTERVAL_AUTO | | |
193 | FE_CAN_RECOVER | | |
194 | FE_CAN_HIERARCHY_AUTO, | |
195 | }, | |
196 | ||
197 | .release = dtt200u_fe_release, | |
198 | ||
199 | .init = dtt200u_fe_init, | |
200 | .sleep = dtt200u_fe_sleep, | |
201 | ||
adcc8f0e MCC |
202 | .set_frontend = dtt200u_fe_set_frontend, |
203 | .get_frontend = dtt200u_fe_get_frontend, | |
776338e1 JS |
204 | .get_tune_settings = dtt200u_fe_get_tune_settings, |
205 | ||
206 | .read_status = dtt200u_fe_read_status, | |
207 | .read_ber = dtt200u_fe_read_ber, | |
208 | .read_signal_strength = dtt200u_fe_read_signal_strength, | |
209 | .read_snr = dtt200u_fe_read_snr, | |
210 | .read_ucblocks = dtt200u_fe_read_unc_blocks, | |
211 | }; |