diff options
author | Johannes Stezenbach <js@linuxtv.org> | 2005-06-24 01:02:35 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-06-24 03:05:30 -0400 |
commit | 776338e121b9db3156bfb4e21622a0219bbab9d4 (patch) | |
tree | 5102272b708a9e8ff81165714870d3d38363cc23 /drivers/media/dvb/dvb-usb/dtt200u-fe.c | |
parent | b6a235b1186dda0800c8bedc2526830a4a36b44e (diff) |
[PATCH] dvb: Add generalized dvb-usb driver
Add generalized dvb-usb driver which supports a wide variety of devices.
Signed-off-by: Patrick Boettcher <pb@linuxtv.org>
Signed-off-by: Johannes Stezenbach <js@linuxtv.org>
Signed-off-by: Randy Dunlap <rdunlap@xenotime.net>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers/media/dvb/dvb-usb/dtt200u-fe.c')
-rw-r--r-- | drivers/media/dvb/dvb-usb/dtt200u-fe.c | 206 |
1 files changed, 206 insertions, 0 deletions
diff --git a/drivers/media/dvb/dvb-usb/dtt200u-fe.c b/drivers/media/dvb/dvb-usb/dtt200u-fe.c new file mode 100644 index 000000000000..d17d768038c6 --- /dev/null +++ b/drivers/media/dvb/dvb-usb/dtt200u-fe.c | |||
@@ -0,0 +1,206 @@ | |||
1 | /* Frontend part of the Linux driver for the Yakumo/Hama/Typhoon DVB-T | ||
2 | * USB2.0 receiver. | ||
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 | |||
17 | struct dvb_frontend_parameters fep; | ||
18 | struct dvb_frontend frontend; | ||
19 | }; | ||
20 | |||
21 | #define moan(which,what) info("unexpected value in '%s' for cmd '%02x' - please report to linux-dvb@linuxtv.org",which,what) | ||
22 | |||
23 | static int dtt200u_fe_read_status(struct dvb_frontend* fe, fe_status_t *stat) | ||
24 | { | ||
25 | struct dtt200u_fe_state *state = fe->demodulator_priv; | ||
26 | u8 bw = GET_TUNE_STAT; | ||
27 | u8 br[3] = { 0 }; | ||
28 | // u8 bdeb[5] = { 0 }; | ||
29 | |||
30 | dvb_usb_generic_rw(state->d,&bw,1,br,3,0); | ||
31 | switch (br[0]) { | ||
32 | case 0x01: | ||
33 | *stat = FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK; | ||
34 | break; | ||
35 | case 0x00: | ||
36 | *stat = 0; | ||
37 | break; | ||
38 | default: | ||
39 | moan("br[0]",GET_TUNE_STAT); | ||
40 | break; | ||
41 | } | ||
42 | |||
43 | // bw[0] = 0x88; | ||
44 | // dvb_usb_generic_rw(state->d,bw,1,bdeb,5,0); | ||
45 | |||
46 | // deb_info("%02x: %02x %02x %02x %02x %02x\n",bw[0],bdeb[0],bdeb[1],bdeb[2],bdeb[3],bdeb[4]); | ||
47 | |||
48 | return 0; | ||
49 | } | ||
50 | static int dtt200u_fe_read_ber(struct dvb_frontend* fe, u32 *ber) | ||
51 | { | ||
52 | struct dtt200u_fe_state *state = fe->demodulator_priv; | ||
53 | u8 bw = GET_BER; | ||
54 | *ber = 0; | ||
55 | dvb_usb_generic_rw(state->d,&bw,1,(u8*) ber,3,0); | ||
56 | return 0; | ||
57 | } | ||
58 | |||
59 | static int dtt200u_fe_read_unc_blocks(struct dvb_frontend* fe, u32 *unc) | ||
60 | { | ||
61 | struct dtt200u_fe_state *state = fe->demodulator_priv; | ||
62 | u8 bw = GET_UNK; | ||
63 | *unc = 0; | ||
64 | dvb_usb_generic_rw(state->d,&bw,1,(u8*) unc,3,0); | ||
65 | return 0; | ||
66 | } | ||
67 | |||
68 | static int dtt200u_fe_read_signal_strength(struct dvb_frontend* fe, u16 *strength) | ||
69 | { | ||
70 | struct dtt200u_fe_state *state = fe->demodulator_priv; | ||
71 | u8 bw = GET_SIG_STRENGTH, b; | ||
72 | dvb_usb_generic_rw(state->d,&bw,1,&b,1,0); | ||
73 | *strength = (b << 8) | b; | ||
74 | return 0; | ||
75 | } | ||
76 | |||
77 | static int dtt200u_fe_read_snr(struct dvb_frontend* fe, u16 *snr) | ||
78 | { | ||
79 | struct dtt200u_fe_state *state = fe->demodulator_priv; | ||
80 | u8 bw = GET_SNR,br; | ||
81 | dvb_usb_generic_rw(state->d,&bw,1,&br,1,0); | ||
82 | *snr = ~((br << 8) | br); | ||
83 | return 0; | ||
84 | } | ||
85 | |||
86 | static int dtt200u_fe_init(struct dvb_frontend* fe) | ||
87 | { | ||
88 | struct dtt200u_fe_state *state = fe->demodulator_priv; | ||
89 | u8 b = RESET_DEMOD; | ||
90 | return dvb_usb_generic_write(state->d,&b,1); | ||
91 | } | ||
92 | |||
93 | static int dtt200u_fe_sleep(struct dvb_frontend* fe) | ||
94 | { | ||
95 | return dtt200u_fe_init(fe); | ||
96 | } | ||
97 | |||
98 | static int dtt200u_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune) | ||
99 | { | ||
100 | tune->min_delay_ms = 1500; | ||
101 | tune->step_size = 166667; | ||
102 | tune->max_drift = 166667 * 2; | ||
103 | return 0; | ||
104 | } | ||
105 | |||
106 | static int dtt200u_fe_set_frontend(struct dvb_frontend* fe, | ||
107 | struct dvb_frontend_parameters *fep) | ||
108 | { | ||
109 | struct dtt200u_fe_state *state = fe->demodulator_priv; | ||
110 | u16 freq = fep->frequency / 250000; | ||
111 | u8 bw,bwbuf[2] = { SET_BANDWIDTH, 0 }, freqbuf[3] = { SET_FREQUENCY, 0, 0 }; | ||
112 | |||
113 | switch (fep->u.ofdm.bandwidth) { | ||
114 | case BANDWIDTH_8_MHZ: bw = 8; break; | ||
115 | case BANDWIDTH_7_MHZ: bw = 7; break; | ||
116 | case BANDWIDTH_6_MHZ: bw = 6; break; | ||
117 | case BANDWIDTH_AUTO: return -EOPNOTSUPP; | ||
118 | default: | ||
119 | return -EINVAL; | ||
120 | } | ||
121 | deb_info("set_frontend\n"); | ||
122 | |||
123 | bwbuf[1] = bw; | ||
124 | dvb_usb_generic_write(state->d,bwbuf,2); | ||
125 | |||
126 | freqbuf[1] = freq & 0xff; | ||
127 | freqbuf[2] = (freq >> 8) & 0xff; | ||
128 | dvb_usb_generic_write(state->d,freqbuf,3); | ||
129 | |||
130 | memcpy(&state->fep,fep,sizeof(struct dvb_frontend_parameters)); | ||
131 | |||
132 | return 0; | ||
133 | } | ||
134 | |||
135 | static int dtt200u_fe_get_frontend(struct dvb_frontend* fe, | ||
136 | struct dvb_frontend_parameters *fep) | ||
137 | { | ||
138 | struct dtt200u_fe_state *state = fe->demodulator_priv; | ||
139 | memcpy(fep,&state->fep,sizeof(struct dvb_frontend_parameters)); | ||
140 | return 0; | ||
141 | } | ||
142 | |||
143 | static void dtt200u_fe_release(struct dvb_frontend* fe) | ||
144 | { | ||
145 | struct dtt200u_fe_state *state = (struct dtt200u_fe_state*) fe->demodulator_priv; | ||
146 | kfree(state); | ||
147 | } | ||
148 | |||
149 | static struct dvb_frontend_ops dtt200u_fe_ops; | ||
150 | |||
151 | struct dvb_frontend* dtt200u_fe_attach(struct dvb_usb_device *d) | ||
152 | { | ||
153 | struct dtt200u_fe_state* state = NULL; | ||
154 | |||
155 | /* allocate memory for the internal state */ | ||
156 | state = (struct dtt200u_fe_state*) kmalloc(sizeof(struct dtt200u_fe_state), GFP_KERNEL); | ||
157 | if (state == NULL) | ||
158 | goto error; | ||
159 | memset(state,0,sizeof(struct dtt200u_fe_state)); | ||
160 | |||
161 | deb_info("attaching frontend dtt200u\n"); | ||
162 | |||
163 | state->d = d; | ||
164 | |||
165 | state->frontend.ops = &dtt200u_fe_ops; | ||
166 | state->frontend.demodulator_priv = state; | ||
167 | |||
168 | goto success; | ||
169 | error: | ||
170 | return NULL; | ||
171 | success: | ||
172 | return &state->frontend; | ||
173 | } | ||
174 | |||
175 | static struct dvb_frontend_ops dtt200u_fe_ops = { | ||
176 | .info = { | ||
177 | .name = "DTT200U (Yakumo/Typhoon/Hama) DVB-T", | ||
178 | .type = FE_OFDM, | ||
179 | .frequency_min = 44250000, | ||
180 | .frequency_max = 867250000, | ||
181 | .frequency_stepsize = 250000, | ||
182 | .caps = FE_CAN_INVERSION_AUTO | | ||
183 | FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 | | ||
184 | FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO | | ||
185 | FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO | | ||
186 | FE_CAN_TRANSMISSION_MODE_AUTO | | ||
187 | FE_CAN_GUARD_INTERVAL_AUTO | | ||
188 | FE_CAN_RECOVER | | ||
189 | FE_CAN_HIERARCHY_AUTO, | ||
190 | }, | ||
191 | |||
192 | .release = dtt200u_fe_release, | ||
193 | |||
194 | .init = dtt200u_fe_init, | ||
195 | .sleep = dtt200u_fe_sleep, | ||
196 | |||
197 | .set_frontend = dtt200u_fe_set_frontend, | ||
198 | .get_frontend = dtt200u_fe_get_frontend, | ||
199 | .get_tune_settings = dtt200u_fe_get_tune_settings, | ||
200 | |||
201 | .read_status = dtt200u_fe_read_status, | ||
202 | .read_ber = dtt200u_fe_read_ber, | ||
203 | .read_signal_strength = dtt200u_fe_read_signal_strength, | ||
204 | .read_snr = dtt200u_fe_read_snr, | ||
205 | .read_ucblocks = dtt200u_fe_read_unc_blocks, | ||
206 | }; | ||