diff options
author | Tomi Orava <tomimo@ncircle.nullnet.fi> | 2008-09-18 23:48:31 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2008-10-12 07:37:14 -0400 |
commit | 986bd1e58b18c09b753f797df19251804bfe3e84 (patch) | |
tree | 35bef912485680a527d01339dccda3ce62fbf7a7 /drivers/media/dvb/dvb-usb | |
parent | 07c6bb9e6e5c9b8d0f697493cdd3978fc193ca90 (diff) |
V4L/DVB (9107): Alternative version of Terratec Cinergy T2 driver
Alternative version of the Terratec Cinergy T2 driver that uses the dvb framework.
Signed-off-by: Tomi Orava <tomimo@ncircle.nullnet.fi>
Signed-off-by: Thierry MERLE <thierry.merle@free.fr>
[mchehab@redhat.com: fix dvb Makefile]
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/dvb/dvb-usb')
-rw-r--r-- | drivers/media/dvb/dvb-usb/Kconfig | 8 | ||||
-rw-r--r-- | drivers/media/dvb/dvb-usb/Makefile | 4 | ||||
-rw-r--r-- | drivers/media/dvb/dvb-usb/cinergyT2-core.c | 230 | ||||
-rw-r--r-- | drivers/media/dvb/dvb-usb/cinergyT2-fe.c | 351 | ||||
-rw-r--r-- | drivers/media/dvb/dvb-usb/cinergyT2.h | 95 |
5 files changed, 688 insertions, 0 deletions
diff --git a/drivers/media/dvb/dvb-usb/Kconfig b/drivers/media/dvb/dvb-usb/Kconfig index 241c9ab54b1b..57bb470bd064 100644 --- a/drivers/media/dvb/dvb-usb/Kconfig +++ b/drivers/media/dvb/dvb-usb/Kconfig | |||
@@ -259,6 +259,14 @@ config DVB_USB_DW2102 | |||
259 | Say Y here to support the DvbWorld DVB-S/S2 USB2.0 receivers | 259 | Say Y here to support the DvbWorld DVB-S/S2 USB2.0 receivers |
260 | and the TeVii S650. | 260 | and the TeVii S650. |
261 | 261 | ||
262 | config DVB_USB_CINERGY_T2 | ||
263 | tristate "Terratec CinergyT2/qanu USB 2.0 DVB-T receiver" | ||
264 | depends on DVB_USB | ||
265 | help | ||
266 | Support for "TerraTec CinergyT2" USB2.0 Highspeed DVB Receivers | ||
267 | |||
268 | Say Y if you own such a device and want to use it. | ||
269 | |||
262 | config DVB_USB_ANYSEE | 270 | config DVB_USB_ANYSEE |
263 | tristate "Anysee DVB-T/C USB2.0 support" | 271 | tristate "Anysee DVB-T/C USB2.0 support" |
264 | depends on DVB_USB | 272 | depends on DVB_USB |
diff --git a/drivers/media/dvb/dvb-usb/Makefile b/drivers/media/dvb/dvb-usb/Makefile index ece8c9dfed18..3122b7cc2c23 100644 --- a/drivers/media/dvb/dvb-usb/Makefile +++ b/drivers/media/dvb/dvb-usb/Makefile | |||
@@ -73,6 +73,10 @@ obj-$(CONFIG_DVB_USB_DTV5100) += dvb-usb-dtv5100.o | |||
73 | dvb-usb-af9015-objs = af9015.o | 73 | dvb-usb-af9015-objs = af9015.o |
74 | obj-$(CONFIG_DVB_USB_AF9015) += dvb-usb-af9015.o | 74 | obj-$(CONFIG_DVB_USB_AF9015) += dvb-usb-af9015.o |
75 | 75 | ||
76 | dvb-usb-cinergyT2-objs = cinergyT2-core.o cinergyT2-fe.o | ||
77 | obj-$(CONFIG_DVB_USB_CINERGY_T2) += dvb-usb-cinergyT2.o | ||
78 | |||
79 | |||
76 | EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/ | 80 | EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/ |
77 | # due to tuner-xc3028 | 81 | # due to tuner-xc3028 |
78 | EXTRA_CFLAGS += -Idrivers/media/common/tuners | 82 | EXTRA_CFLAGS += -Idrivers/media/common/tuners |
diff --git a/drivers/media/dvb/dvb-usb/cinergyT2-core.c b/drivers/media/dvb/dvb-usb/cinergyT2-core.c new file mode 100644 index 000000000000..25863033c480 --- /dev/null +++ b/drivers/media/dvb/dvb-usb/cinergyT2-core.c | |||
@@ -0,0 +1,230 @@ | |||
1 | /* | ||
2 | * TerraTec Cinergy T2/qanu USB2 DVB-T adapter. | ||
3 | * | ||
4 | * Copyright (C) 2007 Tomi Orava (tomimo@ncircle.nullnet.fi) | ||
5 | * | ||
6 | * Based on the dvb-usb-framework code and the | ||
7 | * original Terratec Cinergy T2 driver by: | ||
8 | * | ||
9 | * Copyright (C) 2004 Daniel Mack <daniel@qanu.de> and | ||
10 | * Holger Waechtler <holger@qanu.de> | ||
11 | * | ||
12 | * Protocol Spec published on http://qanu.de/specs/terratec_cinergyT2.pdf | ||
13 | * | ||
14 | * This program is free software; you can redistribute it and/or modify | ||
15 | * it under the terms of the GNU General Public License as published by | ||
16 | * the Free Software Foundation; either version 2 of the License, or | ||
17 | * (at your option) any later version. | ||
18 | * | ||
19 | * This program is distributed in the hope that it will be useful, | ||
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
22 | * GNU General Public License for more details. | ||
23 | * | ||
24 | * You should have received a copy of the GNU General Public License | ||
25 | * along with this program; if not, write to the Free Software | ||
26 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
27 | * | ||
28 | */ | ||
29 | |||
30 | #include "cinergyT2.h" | ||
31 | |||
32 | |||
33 | /* debug */ | ||
34 | int dvb_usb_cinergyt2_debug; | ||
35 | int disable_remote; | ||
36 | |||
37 | module_param_named(debug, dvb_usb_cinergyt2_debug, int, 0644); | ||
38 | MODULE_PARM_DESC(debug, "set debugging level (1=info, xfer=2, rc=4 " | ||
39 | "(or-able))."); | ||
40 | |||
41 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); | ||
42 | |||
43 | |||
44 | /* We are missing a release hook with usb_device data */ | ||
45 | struct dvb_usb_device *cinergyt2_usb_device; | ||
46 | |||
47 | static struct dvb_usb_device_properties cinergyt2_properties; | ||
48 | |||
49 | static int cinergyt2_streaming_ctrl(struct dvb_usb_adapter *adap, int enable) | ||
50 | { | ||
51 | char buf[] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER, enable ? 1 : 0 }; | ||
52 | char result[64]; | ||
53 | return dvb_usb_generic_rw(adap->dev, buf, sizeof(buf), result, | ||
54 | sizeof(result), 0); | ||
55 | } | ||
56 | |||
57 | static int cinergyt2_power_ctrl(struct dvb_usb_device *d, int enable) | ||
58 | { | ||
59 | char buf[] = { CINERGYT2_EP1_SLEEP_MODE, enable ? 0 : 1 }; | ||
60 | char state[3]; | ||
61 | return dvb_usb_generic_rw(d, buf, sizeof(buf), state, sizeof(state), 0); | ||
62 | } | ||
63 | |||
64 | static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap) | ||
65 | { | ||
66 | char query[] = { CINERGYT2_EP1_GET_FIRMWARE_VERSION }; | ||
67 | char state[3]; | ||
68 | int ret; | ||
69 | |||
70 | adap->fe = cinergyt2_fe_attach(adap->dev); | ||
71 | |||
72 | ret = dvb_usb_generic_rw(adap->dev, query, sizeof(query), state, | ||
73 | sizeof(state), 0); | ||
74 | if (ret < 0) { | ||
75 | deb_rc("cinergyt2_power_ctrl() Failed to retrieve sleep " | ||
76 | "state info\n"); | ||
77 | } | ||
78 | |||
79 | /* Copy this pointer as we are gonna need it in the release phase */ | ||
80 | cinergyt2_usb_device = adap->dev; | ||
81 | |||
82 | return 0; | ||
83 | } | ||
84 | |||
85 | static struct dvb_usb_rc_key cinergyt2_rc_keys[] = { | ||
86 | { 0x04, 0x01, KEY_POWER }, | ||
87 | { 0x04, 0x02, KEY_1 }, | ||
88 | { 0x04, 0x03, KEY_2 }, | ||
89 | { 0x04, 0x04, KEY_3 }, | ||
90 | { 0x04, 0x05, KEY_4 }, | ||
91 | { 0x04, 0x06, KEY_5 }, | ||
92 | { 0x04, 0x07, KEY_6 }, | ||
93 | { 0x04, 0x08, KEY_7 }, | ||
94 | { 0x04, 0x09, KEY_8 }, | ||
95 | { 0x04, 0x0a, KEY_9 }, | ||
96 | { 0x04, 0x0c, KEY_0 }, | ||
97 | { 0x04, 0x0b, KEY_VIDEO }, | ||
98 | { 0x04, 0x0d, KEY_REFRESH }, | ||
99 | { 0x04, 0x0e, KEY_SELECT }, | ||
100 | { 0x04, 0x0f, KEY_EPG }, | ||
101 | { 0x04, 0x10, KEY_UP }, | ||
102 | { 0x04, 0x14, KEY_DOWN }, | ||
103 | { 0x04, 0x11, KEY_LEFT }, | ||
104 | { 0x04, 0x13, KEY_RIGHT }, | ||
105 | { 0x04, 0x12, KEY_OK }, | ||
106 | { 0x04, 0x15, KEY_TEXT }, | ||
107 | { 0x04, 0x16, KEY_INFO }, | ||
108 | { 0x04, 0x17, KEY_RED }, | ||
109 | { 0x04, 0x18, KEY_GREEN }, | ||
110 | { 0x04, 0x19, KEY_YELLOW }, | ||
111 | { 0x04, 0x1a, KEY_BLUE }, | ||
112 | { 0x04, 0x1c, KEY_VOLUMEUP }, | ||
113 | { 0x04, 0x1e, KEY_VOLUMEDOWN }, | ||
114 | { 0x04, 0x1d, KEY_MUTE }, | ||
115 | { 0x04, 0x1b, KEY_CHANNELUP }, | ||
116 | { 0x04, 0x1f, KEY_CHANNELDOWN }, | ||
117 | { 0x04, 0x40, KEY_PAUSE }, | ||
118 | { 0x04, 0x4c, KEY_PLAY }, | ||
119 | { 0x04, 0x58, KEY_RECORD }, | ||
120 | { 0x04, 0x54, KEY_PREVIOUS }, | ||
121 | { 0x04, 0x48, KEY_STOP }, | ||
122 | { 0x04, 0x5c, KEY_NEXT } | ||
123 | }; | ||
124 | |||
125 | static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state) | ||
126 | { | ||
127 | u8 key[5] = {0, 0, 0, 0, 0}, cmd = CINERGYT2_EP1_GET_RC_EVENTS; | ||
128 | *state = REMOTE_NO_KEY_PRESSED; | ||
129 | |||
130 | dvb_usb_generic_rw(d, &cmd, 1, key, sizeof(key), 0); | ||
131 | if (key[4] == 0xff) | ||
132 | return 0; | ||
133 | |||
134 | /* hack to pass checksum on the custom field (is set to 0xeb) */ | ||
135 | key[2] = ~0x04; | ||
136 | dvb_usb_nec_rc_key_to_event(d, key, event, state); | ||
137 | if (key[0] != 0) | ||
138 | deb_info("key: %x %x %x %x %x\n", | ||
139 | key[0], key[1], key[2], key[3], key[4]); | ||
140 | |||
141 | return 0; | ||
142 | } | ||
143 | |||
144 | static int cinergyt2_usb_probe(struct usb_interface *intf, | ||
145 | const struct usb_device_id *id) | ||
146 | { | ||
147 | return dvb_usb_device_init(intf, &cinergyt2_properties, | ||
148 | THIS_MODULE, NULL, adapter_nr); | ||
149 | } | ||
150 | |||
151 | |||
152 | static struct usb_device_id cinergyt2_usb_table[] = { | ||
153 | { USB_DEVICE(USB_VID_TERRATEC, 0x0038) }, | ||
154 | { 0 } | ||
155 | }; | ||
156 | |||
157 | MODULE_DEVICE_TABLE(usb, cinergyt2_usb_table); | ||
158 | |||
159 | static struct dvb_usb_device_properties cinergyt2_properties = { | ||
160 | |||
161 | .num_adapters = 1, | ||
162 | .adapter = { | ||
163 | { | ||
164 | .streaming_ctrl = cinergyt2_streaming_ctrl, | ||
165 | .frontend_attach = cinergyt2_frontend_attach, | ||
166 | |||
167 | /* parameter for the MPEG2-data transfer */ | ||
168 | .stream = { | ||
169 | .type = USB_BULK, | ||
170 | .count = 5, | ||
171 | .endpoint = 0x02, | ||
172 | .u = { | ||
173 | .bulk = { | ||
174 | .buffersize = 512, | ||
175 | } | ||
176 | } | ||
177 | }, | ||
178 | } | ||
179 | }, | ||
180 | |||
181 | .power_ctrl = cinergyt2_power_ctrl, | ||
182 | |||
183 | .rc_interval = 50, | ||
184 | .rc_key_map = cinergyt2_rc_keys, | ||
185 | .rc_key_map_size = ARRAY_SIZE(cinergyt2_rc_keys), | ||
186 | .rc_query = cinergyt2_rc_query, | ||
187 | |||
188 | .generic_bulk_ctrl_endpoint = 1, | ||
189 | |||
190 | .num_device_descs = 1, | ||
191 | .devices = { | ||
192 | { .name = "TerraTec/qanu USB2.0 Highspeed DVB-T Receiver", | ||
193 | .cold_ids = {NULL}, | ||
194 | .warm_ids = { &cinergyt2_usb_table[0], NULL }, | ||
195 | }, | ||
196 | { NULL }, | ||
197 | } | ||
198 | }; | ||
199 | |||
200 | |||
201 | static struct usb_driver cinergyt2_driver = { | ||
202 | .name = "cinergyT2", | ||
203 | .probe = cinergyt2_usb_probe, | ||
204 | .disconnect = dvb_usb_device_exit, | ||
205 | .id_table = cinergyt2_usb_table | ||
206 | }; | ||
207 | |||
208 | static int __init cinergyt2_usb_init(void) | ||
209 | { | ||
210 | int err; | ||
211 | |||
212 | err = usb_register(&cinergyt2_driver); | ||
213 | if (err) { | ||
214 | err("usb_register() failed! (err %i)\n", err); | ||
215 | return err; | ||
216 | } | ||
217 | return 0; | ||
218 | } | ||
219 | |||
220 | static void __exit cinergyt2_usb_exit(void) | ||
221 | { | ||
222 | usb_deregister(&cinergyt2_driver); | ||
223 | } | ||
224 | |||
225 | module_init(cinergyt2_usb_init); | ||
226 | module_exit(cinergyt2_usb_exit); | ||
227 | |||
228 | MODULE_DESCRIPTION("Terratec Cinergy T2 DVB-T driver"); | ||
229 | MODULE_LICENSE("GPL"); | ||
230 | MODULE_AUTHOR("Tomi Orava"); | ||
diff --git a/drivers/media/dvb/dvb-usb/cinergyT2-fe.c b/drivers/media/dvb/dvb-usb/cinergyT2-fe.c new file mode 100644 index 000000000000..649f25cca49e --- /dev/null +++ b/drivers/media/dvb/dvb-usb/cinergyT2-fe.c | |||
@@ -0,0 +1,351 @@ | |||
1 | /* | ||
2 | * TerraTec Cinergy T2/qanu USB2 DVB-T adapter. | ||
3 | * | ||
4 | * Copyright (C) 2007 Tomi Orava (tomimo@ncircle.nullnet.fi) | ||
5 | * | ||
6 | * Based on the dvb-usb-framework code and the | ||
7 | * original Terratec Cinergy T2 driver by: | ||
8 | * | ||
9 | * Copyright (C) 2004 Daniel Mack <daniel@qanu.de> and | ||
10 | * Holger Waechtler <holger@qanu.de> | ||
11 | * | ||
12 | * Protocol Spec published on http://qanu.de/specs/terratec_cinergyT2.pdf | ||
13 | * | ||
14 | * This program is free software; you can redistribute it and/or modify | ||
15 | * it under the terms of the GNU General Public License as published by | ||
16 | * the Free Software Foundation; either version 2 of the License, or | ||
17 | * (at your option) any later version. | ||
18 | * | ||
19 | * This program is distributed in the hope that it will be useful, | ||
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
22 | * GNU General Public License for more details. | ||
23 | * | ||
24 | * You should have received a copy of the GNU General Public License | ||
25 | * along with this program; if not, write to the Free Software | ||
26 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
27 | * | ||
28 | */ | ||
29 | |||
30 | #include "cinergyT2.h" | ||
31 | |||
32 | |||
33 | /** | ||
34 | * convert linux-dvb frontend parameter set into TPS. | ||
35 | * See ETSI ETS-300744, section 4.6.2, table 9 for details. | ||
36 | * | ||
37 | * This function is probably reusable and may better get placed in a support | ||
38 | * library. | ||
39 | * | ||
40 | * We replace errornous fields by default TPS fields (the ones with value 0). | ||
41 | */ | ||
42 | |||
43 | static uint16_t compute_tps(struct dvb_frontend_parameters *p) | ||
44 | { | ||
45 | struct dvb_ofdm_parameters *op = &p->u.ofdm; | ||
46 | uint16_t tps = 0; | ||
47 | |||
48 | switch (op->code_rate_HP) { | ||
49 | case FEC_2_3: | ||
50 | tps |= (1 << 7); | ||
51 | break; | ||
52 | case FEC_3_4: | ||
53 | tps |= (2 << 7); | ||
54 | break; | ||
55 | case FEC_5_6: | ||
56 | tps |= (3 << 7); | ||
57 | break; | ||
58 | case FEC_7_8: | ||
59 | tps |= (4 << 7); | ||
60 | break; | ||
61 | case FEC_1_2: | ||
62 | case FEC_AUTO: | ||
63 | default: | ||
64 | /* tps |= (0 << 7) */; | ||
65 | } | ||
66 | |||
67 | switch (op->code_rate_LP) { | ||
68 | case FEC_2_3: | ||
69 | tps |= (1 << 4); | ||
70 | break; | ||
71 | case FEC_3_4: | ||
72 | tps |= (2 << 4); | ||
73 | break; | ||
74 | case FEC_5_6: | ||
75 | tps |= (3 << 4); | ||
76 | break; | ||
77 | case FEC_7_8: | ||
78 | tps |= (4 << 4); | ||
79 | break; | ||
80 | case FEC_1_2: | ||
81 | case FEC_AUTO: | ||
82 | default: | ||
83 | /* tps |= (0 << 4) */; | ||
84 | } | ||
85 | |||
86 | switch (op->constellation) { | ||
87 | case QAM_16: | ||
88 | tps |= (1 << 13); | ||
89 | break; | ||
90 | case QAM_64: | ||
91 | tps |= (2 << 13); | ||
92 | break; | ||
93 | case QPSK: | ||
94 | default: | ||
95 | /* tps |= (0 << 13) */; | ||
96 | } | ||
97 | |||
98 | switch (op->transmission_mode) { | ||
99 | case TRANSMISSION_MODE_8K: | ||
100 | tps |= (1 << 0); | ||
101 | break; | ||
102 | case TRANSMISSION_MODE_2K: | ||
103 | default: | ||
104 | /* tps |= (0 << 0) */; | ||
105 | } | ||
106 | |||
107 | switch (op->guard_interval) { | ||
108 | case GUARD_INTERVAL_1_16: | ||
109 | tps |= (1 << 2); | ||
110 | break; | ||
111 | case GUARD_INTERVAL_1_8: | ||
112 | tps |= (2 << 2); | ||
113 | break; | ||
114 | case GUARD_INTERVAL_1_4: | ||
115 | tps |= (3 << 2); | ||
116 | break; | ||
117 | case GUARD_INTERVAL_1_32: | ||
118 | default: | ||
119 | /* tps |= (0 << 2) */; | ||
120 | } | ||
121 | |||
122 | switch (op->hierarchy_information) { | ||
123 | case HIERARCHY_1: | ||
124 | tps |= (1 << 10); | ||
125 | break; | ||
126 | case HIERARCHY_2: | ||
127 | tps |= (2 << 10); | ||
128 | break; | ||
129 | case HIERARCHY_4: | ||
130 | tps |= (3 << 10); | ||
131 | break; | ||
132 | case HIERARCHY_NONE: | ||
133 | default: | ||
134 | /* tps |= (0 << 10) */; | ||
135 | } | ||
136 | |||
137 | return tps; | ||
138 | } | ||
139 | |||
140 | struct cinergyt2_fe_state { | ||
141 | struct dvb_frontend fe; | ||
142 | struct dvb_usb_device *d; | ||
143 | }; | ||
144 | |||
145 | static int cinergyt2_fe_read_status(struct dvb_frontend *fe, | ||
146 | fe_status_t *status) | ||
147 | { | ||
148 | struct cinergyt2_fe_state *state = fe->demodulator_priv; | ||
149 | struct dvbt_get_status_msg result; | ||
150 | u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS }; | ||
151 | int ret; | ||
152 | |||
153 | ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&result, | ||
154 | sizeof(result), 0); | ||
155 | if (ret < 0) | ||
156 | return ret; | ||
157 | |||
158 | *status = 0; | ||
159 | |||
160 | if (0xffff - le16_to_cpu(result.gain) > 30) | ||
161 | *status |= FE_HAS_SIGNAL; | ||
162 | if (result.lock_bits & (1 << 6)) | ||
163 | *status |= FE_HAS_LOCK; | ||
164 | if (result.lock_bits & (1 << 5)) | ||
165 | *status |= FE_HAS_SYNC; | ||
166 | if (result.lock_bits & (1 << 4)) | ||
167 | *status |= FE_HAS_CARRIER; | ||
168 | if (result.lock_bits & (1 << 1)) | ||
169 | *status |= FE_HAS_VITERBI; | ||
170 | |||
171 | if ((*status & (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC)) != | ||
172 | (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC)) | ||
173 | *status &= ~FE_HAS_LOCK; | ||
174 | |||
175 | return 0; | ||
176 | } | ||
177 | |||
178 | static int cinergyt2_fe_read_ber(struct dvb_frontend *fe, u32 *ber) | ||
179 | { | ||
180 | struct cinergyt2_fe_state *state = fe->demodulator_priv; | ||
181 | struct dvbt_get_status_msg status; | ||
182 | char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS }; | ||
183 | int ret; | ||
184 | |||
185 | ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status, | ||
186 | sizeof(status), 0); | ||
187 | if (ret < 0) | ||
188 | return ret; | ||
189 | |||
190 | *ber = le32_to_cpu(status.viterbi_error_rate); | ||
191 | return 0; | ||
192 | } | ||
193 | |||
194 | static int cinergyt2_fe_read_unc_blocks(struct dvb_frontend *fe, u32 *unc) | ||
195 | { | ||
196 | struct cinergyt2_fe_state *state = fe->demodulator_priv; | ||
197 | struct dvbt_get_status_msg status; | ||
198 | u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS }; | ||
199 | int ret; | ||
200 | |||
201 | ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&status, | ||
202 | sizeof(status), 0); | ||
203 | if (ret < 0) { | ||
204 | err("cinergyt2_fe_read_unc_blocks() Failed! (Error=%d)\n", | ||
205 | ret); | ||
206 | return ret; | ||
207 | } | ||
208 | *unc = le32_to_cpu(status.uncorrected_block_count); | ||
209 | return 0; | ||
210 | } | ||
211 | |||
212 | static int cinergyt2_fe_read_signal_strength(struct dvb_frontend *fe, | ||
213 | u16 *strength) | ||
214 | { | ||
215 | struct cinergyt2_fe_state *state = fe->demodulator_priv; | ||
216 | struct dvbt_get_status_msg status; | ||
217 | char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS }; | ||
218 | int ret; | ||
219 | |||
220 | ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status, | ||
221 | sizeof(status), 0); | ||
222 | if (ret < 0) { | ||
223 | err("cinergyt2_fe_read_signal_strength() Failed!" | ||
224 | " (Error=%d)\n", ret); | ||
225 | return ret; | ||
226 | } | ||
227 | *strength = (0xffff - le16_to_cpu(status.gain)); | ||
228 | return 0; | ||
229 | } | ||
230 | |||
231 | static int cinergyt2_fe_read_snr(struct dvb_frontend *fe, u16 *snr) | ||
232 | { | ||
233 | struct cinergyt2_fe_state *state = fe->demodulator_priv; | ||
234 | struct dvbt_get_status_msg status; | ||
235 | char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS }; | ||
236 | int ret; | ||
237 | |||
238 | ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status, | ||
239 | sizeof(status), 0); | ||
240 | if (ret < 0) { | ||
241 | err("cinergyt2_fe_read_snr() Failed! (Error=%d)\n", ret); | ||
242 | return ret; | ||
243 | } | ||
244 | *snr = (status.snr << 8) | status.snr; | ||
245 | return 0; | ||
246 | } | ||
247 | |||
248 | static int cinergyt2_fe_init(struct dvb_frontend *fe) | ||
249 | { | ||
250 | return 0; | ||
251 | } | ||
252 | |||
253 | static int cinergyt2_fe_sleep(struct dvb_frontend *fe) | ||
254 | { | ||
255 | deb_info("cinergyt2_fe_sleep() Called\n"); | ||
256 | return 0; | ||
257 | } | ||
258 | |||
259 | static int cinergyt2_fe_get_tune_settings(struct dvb_frontend *fe, | ||
260 | struct dvb_frontend_tune_settings *tune) | ||
261 | { | ||
262 | tune->min_delay_ms = 800; | ||
263 | return 0; | ||
264 | } | ||
265 | |||
266 | static int cinergyt2_fe_set_frontend(struct dvb_frontend *fe, | ||
267 | struct dvb_frontend_parameters *fep) | ||
268 | { | ||
269 | struct cinergyt2_fe_state *state = fe->demodulator_priv; | ||
270 | struct dvbt_set_parameters_msg param; | ||
271 | char result[2]; | ||
272 | int err; | ||
273 | |||
274 | param.cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS; | ||
275 | param.tps = cpu_to_le16(compute_tps(fep)); | ||
276 | param.freq = cpu_to_le32(fep->frequency / 1000); | ||
277 | param.bandwidth = 8 - fep->u.ofdm.bandwidth - BANDWIDTH_8_MHZ; | ||
278 | |||
279 | err = dvb_usb_generic_rw(state->d, | ||
280 | (char *)¶m, sizeof(param), | ||
281 | result, sizeof(result), 0); | ||
282 | if (err < 0) | ||
283 | err("cinergyt2_fe_set_frontend() Failed! err=%d\n", err); | ||
284 | |||
285 | return (err < 0) ? err : 0; | ||
286 | } | ||
287 | |||
288 | static int cinergyt2_fe_get_frontend(struct dvb_frontend *fe, | ||
289 | struct dvb_frontend_parameters *fep) | ||
290 | { | ||
291 | return 0; | ||
292 | } | ||
293 | |||
294 | static void cinergyt2_fe_release(struct dvb_frontend *fe) | ||
295 | { | ||
296 | struct cinergyt2_fe_state *state = fe->demodulator_priv; | ||
297 | if (state != NULL) | ||
298 | kfree(state); | ||
299 | } | ||
300 | |||
301 | static struct dvb_frontend_ops cinergyt2_fe_ops; | ||
302 | |||
303 | struct dvb_frontend *cinergyt2_fe_attach(struct dvb_usb_device *d) | ||
304 | { | ||
305 | struct cinergyt2_fe_state *s = kzalloc(sizeof( | ||
306 | struct cinergyt2_fe_state), GFP_KERNEL); | ||
307 | if (s == NULL) | ||
308 | return NULL; | ||
309 | |||
310 | s->d = d; | ||
311 | memcpy(&s->fe.ops, &cinergyt2_fe_ops, sizeof(struct dvb_frontend_ops)); | ||
312 | s->fe.demodulator_priv = s; | ||
313 | return &s->fe; | ||
314 | } | ||
315 | |||
316 | |||
317 | static struct dvb_frontend_ops cinergyt2_fe_ops = { | ||
318 | .info = { | ||
319 | .name = DRIVER_NAME, | ||
320 | .type = FE_OFDM, | ||
321 | .frequency_min = 174000000, | ||
322 | .frequency_max = 862000000, | ||
323 | .frequency_stepsize = 166667, | ||
324 | .caps = FE_CAN_INVERSION_AUTO | FE_CAN_FEC_1_2 | ||
325 | | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 | ||
326 | | FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | ||
327 | | FE_CAN_FEC_AUTO | FE_CAN_QPSK | ||
328 | | FE_CAN_QAM_16 | FE_CAN_QAM_64 | ||
329 | | FE_CAN_QAM_AUTO | ||
330 | | FE_CAN_TRANSMISSION_MODE_AUTO | ||
331 | | FE_CAN_GUARD_INTERVAL_AUTO | ||
332 | | FE_CAN_HIERARCHY_AUTO | ||
333 | | FE_CAN_RECOVER | ||
334 | | FE_CAN_MUTE_TS | ||
335 | }, | ||
336 | |||
337 | .release = cinergyt2_fe_release, | ||
338 | |||
339 | .init = cinergyt2_fe_init, | ||
340 | .sleep = cinergyt2_fe_sleep, | ||
341 | |||
342 | .set_frontend = cinergyt2_fe_set_frontend, | ||
343 | .get_frontend = cinergyt2_fe_get_frontend, | ||
344 | .get_tune_settings = cinergyt2_fe_get_tune_settings, | ||
345 | |||
346 | .read_status = cinergyt2_fe_read_status, | ||
347 | .read_ber = cinergyt2_fe_read_ber, | ||
348 | .read_signal_strength = cinergyt2_fe_read_signal_strength, | ||
349 | .read_snr = cinergyt2_fe_read_snr, | ||
350 | .read_ucblocks = cinergyt2_fe_read_unc_blocks, | ||
351 | }; | ||
diff --git a/drivers/media/dvb/dvb-usb/cinergyT2.h b/drivers/media/dvb/dvb-usb/cinergyT2.h new file mode 100644 index 000000000000..11d79eb384c8 --- /dev/null +++ b/drivers/media/dvb/dvb-usb/cinergyT2.h | |||
@@ -0,0 +1,95 @@ | |||
1 | /* | ||
2 | * TerraTec Cinergy T2/qanu USB2 DVB-T adapter. | ||
3 | * | ||
4 | * Copyright (C) 2007 Tomi Orava (tomimo@ncircle.nullnet.fi) | ||
5 | * | ||
6 | * Based on the dvb-usb-framework code and the | ||
7 | * original Terratec Cinergy T2 driver by: | ||
8 | * | ||
9 | * Copyright (C) 2004 Daniel Mack <daniel@qanu.de> and | ||
10 | * Holger Waechtler <holger@qanu.de> | ||
11 | * | ||
12 | * Protocol Spec published on http://qanu.de/specs/terratec_cinergyT2.pdf | ||
13 | * | ||
14 | * This program is free software; you can redistribute it and/or modify | ||
15 | * it under the terms of the GNU General Public License as published by | ||
16 | * the Free Software Foundation; either version 2 of the License, or | ||
17 | * (at your option) any later version. | ||
18 | * | ||
19 | * This program is distributed in the hope that it will be useful, | ||
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
22 | * GNU General Public License for more details. | ||
23 | * | ||
24 | * You should have received a copy of the GNU General Public License | ||
25 | * along with this program; if not, write to the Free Software | ||
26 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
27 | * | ||
28 | */ | ||
29 | |||
30 | #ifndef _DVB_USB_CINERGYT2_H_ | ||
31 | #define _DVB_USB_CINERGYT2_H_ | ||
32 | |||
33 | #include <linux/usb/input.h> | ||
34 | |||
35 | #define DVB_USB_LOG_PREFIX "cinergyT2" | ||
36 | #include "dvb-usb.h" | ||
37 | |||
38 | #define DRIVER_NAME "TerraTec/qanu USB2.0 Highspeed DVB-T Receiver" | ||
39 | |||
40 | extern int dvb_usb_cinergyt2_debug; | ||
41 | |||
42 | #define deb_info(args...) dprintk(dvb_usb_cinergyt2_debug, 0x001, args) | ||
43 | #define deb_xfer(args...) dprintk(dvb_usb_cinergyt2_debug, 0x002, args) | ||
44 | #define deb_pll(args...) dprintk(dvb_usb_cinergyt2_debug, 0x004, args) | ||
45 | #define deb_ts(args...) dprintk(dvb_usb_cinergyt2_debug, 0x008, args) | ||
46 | #define deb_err(args...) dprintk(dvb_usb_cinergyt2_debug, 0x010, args) | ||
47 | #define deb_rc(args...) dprintk(dvb_usb_cinergyt2_debug, 0x020, args) | ||
48 | #define deb_fw(args...) dprintk(dvb_usb_cinergyt2_debug, 0x040, args) | ||
49 | #define deb_mem(args...) dprintk(dvb_usb_cinergyt2_debug, 0x080, args) | ||
50 | #define deb_uxfer(args...) dprintk(dvb_usb_cinergyt2_debug, 0x100, args) | ||
51 | |||
52 | |||
53 | |||
54 | enum cinergyt2_ep1_cmd { | ||
55 | CINERGYT2_EP1_PID_TABLE_RESET = 0x01, | ||
56 | CINERGYT2_EP1_PID_SETUP = 0x02, | ||
57 | CINERGYT2_EP1_CONTROL_STREAM_TRANSFER = 0x03, | ||
58 | CINERGYT2_EP1_SET_TUNER_PARAMETERS = 0x04, | ||
59 | CINERGYT2_EP1_GET_TUNER_STATUS = 0x05, | ||
60 | CINERGYT2_EP1_START_SCAN = 0x06, | ||
61 | CINERGYT2_EP1_CONTINUE_SCAN = 0x07, | ||
62 | CINERGYT2_EP1_GET_RC_EVENTS = 0x08, | ||
63 | CINERGYT2_EP1_SLEEP_MODE = 0x09, | ||
64 | CINERGYT2_EP1_GET_FIRMWARE_VERSION = 0x0A | ||
65 | }; | ||
66 | |||
67 | |||
68 | struct dvbt_get_status_msg { | ||
69 | uint32_t freq; | ||
70 | uint8_t bandwidth; | ||
71 | uint16_t tps; | ||
72 | uint8_t flags; | ||
73 | uint16_t gain; | ||
74 | uint8_t snr; | ||
75 | uint32_t viterbi_error_rate; | ||
76 | uint32_t rs_error_rate; | ||
77 | uint32_t uncorrected_block_count; | ||
78 | uint8_t lock_bits; | ||
79 | uint8_t prev_lock_bits; | ||
80 | } __attribute__((packed)); | ||
81 | |||
82 | |||
83 | struct dvbt_set_parameters_msg { | ||
84 | uint8_t cmd; | ||
85 | uint32_t freq; | ||
86 | uint8_t bandwidth; | ||
87 | uint16_t tps; | ||
88 | uint8_t flags; | ||
89 | } __attribute__((packed)); | ||
90 | |||
91 | |||
92 | extern struct dvb_frontend *cinergyt2_fe_attach(struct dvb_usb_device *d); | ||
93 | |||
94 | #endif /* _DVB_USB_CINERGYT2_H_ */ | ||
95 | |||