Merge branch 'fix/pcm-hwptr' into for-linus
[linux/fpc-iii.git] / drivers / media / dvb / dvb-usb / vp7045-fe.c
blob8452eef90322be8d97e9a08c81881cc47f6cf311
1 /* DVB frontend part of the Linux driver for TwinhanDTV Alpha/MagicBoxII USB2.0
2 * DVB-T receiver.
4 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
6 * Thanks to Twinhan who kindly provided hardware and information.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation, version 2.
12 * see Documentation/dvb/README.dvb-usb for more information
15 #include "vp7045.h"
17 /* It is a Zarlink MT352 within a Samsung Tuner (DNOS404ZH102A) - 040929 - AAT
19 * Programming is hidden inside the firmware, so set_frontend is very easy.
20 * Even though there is a Firmware command that one can use to access the demod
21 * via its registers. This is used for status information.
24 struct vp7045_fe_state {
25 struct dvb_frontend fe;
26 struct dvb_usb_device *d;
29 static int vp7045_fe_read_status(struct dvb_frontend* fe, fe_status_t *status)
31 struct vp7045_fe_state *state = fe->demodulator_priv;
32 u8 s0 = vp7045_read_reg(state->d,0x00),
33 s1 = vp7045_read_reg(state->d,0x01),
34 s3 = vp7045_read_reg(state->d,0x03);
36 *status = 0;
37 if (s0 & (1 << 4))
38 *status |= FE_HAS_CARRIER;
39 if (s0 & (1 << 1))
40 *status |= FE_HAS_VITERBI;
41 if (s0 & (1 << 5))
42 *status |= FE_HAS_LOCK;
43 if (s1 & (1 << 1))
44 *status |= FE_HAS_SYNC;
45 if (s3 & (1 << 6))
46 *status |= FE_HAS_SIGNAL;
48 if ((*status & (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC)) !=
49 (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC))
50 *status &= ~FE_HAS_LOCK;
52 return 0;
55 static int vp7045_fe_read_ber(struct dvb_frontend* fe, u32 *ber)
57 struct vp7045_fe_state *state = fe->demodulator_priv;
58 *ber = (vp7045_read_reg(state->d, 0x0D) << 16) |
59 (vp7045_read_reg(state->d, 0x0E) << 8) |
60 vp7045_read_reg(state->d, 0x0F);
61 return 0;
64 static int vp7045_fe_read_unc_blocks(struct dvb_frontend* fe, u32 *unc)
66 struct vp7045_fe_state *state = fe->demodulator_priv;
67 *unc = (vp7045_read_reg(state->d, 0x10) << 8) |
68 vp7045_read_reg(state->d, 0x11);
69 return 0;
72 static int vp7045_fe_read_signal_strength(struct dvb_frontend* fe, u16 *strength)
74 struct vp7045_fe_state *state = fe->demodulator_priv;
75 u16 signal = (vp7045_read_reg(state->d, 0x14) << 8) |
76 vp7045_read_reg(state->d, 0x15);
78 *strength = ~signal;
79 return 0;
82 static int vp7045_fe_read_snr(struct dvb_frontend* fe, u16 *snr)
84 struct vp7045_fe_state *state = fe->demodulator_priv;
85 u8 _snr = vp7045_read_reg(state->d, 0x09);
86 *snr = (_snr << 8) | _snr;
87 return 0;
90 static int vp7045_fe_init(struct dvb_frontend* fe)
92 return 0;
95 static int vp7045_fe_sleep(struct dvb_frontend* fe)
97 return 0;
100 static int vp7045_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune)
102 tune->min_delay_ms = 800;
103 return 0;
106 static int vp7045_fe_set_frontend(struct dvb_frontend* fe,
107 struct dvb_frontend_parameters *fep)
109 struct vp7045_fe_state *state = fe->demodulator_priv;
110 u8 buf[5];
111 u32 freq = fep->frequency / 1000;
113 buf[0] = (freq >> 16) & 0xff;
114 buf[1] = (freq >> 8) & 0xff;
115 buf[2] = freq & 0xff;
116 buf[3] = 0;
118 switch (fep->u.ofdm.bandwidth) {
119 case BANDWIDTH_8_MHZ: buf[4] = 8; break;
120 case BANDWIDTH_7_MHZ: buf[4] = 7; break;
121 case BANDWIDTH_6_MHZ: buf[4] = 6; break;
122 case BANDWIDTH_AUTO: return -EOPNOTSUPP;
123 default:
124 return -EINVAL;
127 vp7045_usb_op(state->d,LOCK_TUNER_COMMAND,buf,5,NULL,0,200);
128 return 0;
131 static int vp7045_fe_get_frontend(struct dvb_frontend* fe,
132 struct dvb_frontend_parameters *fep)
134 return 0;
137 static void vp7045_fe_release(struct dvb_frontend* fe)
139 struct vp7045_fe_state *state = fe->demodulator_priv;
140 kfree(state);
143 static struct dvb_frontend_ops vp7045_fe_ops;
145 struct dvb_frontend * vp7045_fe_attach(struct dvb_usb_device *d)
147 struct vp7045_fe_state *s = kzalloc(sizeof(struct vp7045_fe_state), GFP_KERNEL);
148 if (s == NULL)
149 goto error;
151 s->d = d;
152 memcpy(&s->fe.ops, &vp7045_fe_ops, sizeof(struct dvb_frontend_ops));
153 s->fe.demodulator_priv = s;
155 return &s->fe;
156 error:
157 return NULL;
161 static struct dvb_frontend_ops vp7045_fe_ops = {
162 .info = {
163 .name = "Twinhan VP7045/46 USB DVB-T",
164 .type = FE_OFDM,
165 .frequency_min = 44250000,
166 .frequency_max = 867250000,
167 .frequency_stepsize = 1000,
168 .caps = FE_CAN_INVERSION_AUTO |
169 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
170 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
171 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
172 FE_CAN_TRANSMISSION_MODE_AUTO |
173 FE_CAN_GUARD_INTERVAL_AUTO |
174 FE_CAN_RECOVER |
175 FE_CAN_HIERARCHY_AUTO,
178 .release = vp7045_fe_release,
180 .init = vp7045_fe_init,
181 .sleep = vp7045_fe_sleep,
183 .set_frontend = vp7045_fe_set_frontend,
184 .get_frontend = vp7045_fe_get_frontend,
185 .get_tune_settings = vp7045_fe_get_tune_settings,
187 .read_status = vp7045_fe_read_status,
188 .read_ber = vp7045_fe_read_ber,
189 .read_signal_strength = vp7045_fe_read_signal_strength,
190 .read_snr = vp7045_fe_read_snr,
191 .read_ucblocks = vp7045_fe_read_unc_blocks,