Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 1 | /* |
| 2 | * FireDTV driver (formerly known as FireSAT) |
| 3 | * |
| 4 | * Copyright (C) 2004 Andreas Monitzer <andy@monitzer.com> |
| 5 | * Copyright (C) 2008 Henrik Kurelid <henrik@kurelid.se> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License as |
| 9 | * published by the Free Software Foundation; either version 2 of |
| 10 | * the License, or (at your option) any later version. |
| 11 | */ |
| 12 | |
Stefan Richter | 1549079 | 2009-02-23 14:21:10 +0100 | [diff] [blame] | 13 | #include <linux/device.h> |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 14 | #include <linux/errno.h> |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/string.h> |
| 17 | #include <linux/types.h> |
| 18 | |
| 19 | #include <dvb_frontend.h> |
| 20 | |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 21 | #include "firedtv.h" |
| 22 | |
| 23 | static int fdtv_dvb_init(struct dvb_frontend *fe) |
| 24 | { |
| 25 | struct firedtv *fdtv = fe->sec_priv; |
| 26 | int err; |
| 27 | |
| 28 | /* FIXME - allocate free channel at IRM */ |
| 29 | fdtv->isochannel = fdtv->adapter.num; |
| 30 | |
| 31 | err = cmp_establish_pp_connection(fdtv, fdtv->subunit, |
| 32 | fdtv->isochannel); |
| 33 | if (err) { |
Stefan Richter | 1549079 | 2009-02-23 14:21:10 +0100 | [diff] [blame] | 34 | dev_err(fdtv->device, |
| 35 | "could not establish point to point connection\n"); |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 36 | return err; |
| 37 | } |
| 38 | |
Stefan Richter | 1549079 | 2009-02-23 14:21:10 +0100 | [diff] [blame] | 39 | return fdtv->backend->start_iso(fdtv); |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | static int fdtv_sleep(struct dvb_frontend *fe) |
| 43 | { |
| 44 | struct firedtv *fdtv = fe->sec_priv; |
| 45 | |
Stefan Richter | 1549079 | 2009-02-23 14:21:10 +0100 | [diff] [blame] | 46 | fdtv->backend->stop_iso(fdtv); |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 47 | cmp_break_pp_connection(fdtv, fdtv->subunit, fdtv->isochannel); |
| 48 | fdtv->isochannel = -1; |
| 49 | return 0; |
| 50 | } |
| 51 | |
Stefan Richter | 1549079 | 2009-02-23 14:21:10 +0100 | [diff] [blame] | 52 | #define LNBCONTROL_DONTCARE 0xff |
| 53 | |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 54 | static int fdtv_diseqc_send_master_cmd(struct dvb_frontend *fe, |
Stefan Richter | 1549079 | 2009-02-23 14:21:10 +0100 | [diff] [blame] | 55 | struct dvb_diseqc_master_cmd *cmd) |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 56 | { |
| 57 | struct firedtv *fdtv = fe->sec_priv; |
| 58 | |
Stefan Richter | 1549079 | 2009-02-23 14:21:10 +0100 | [diff] [blame] | 59 | return avc_lnb_control(fdtv, LNBCONTROL_DONTCARE, LNBCONTROL_DONTCARE, |
| 60 | LNBCONTROL_DONTCARE, 1, cmd); |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | static int fdtv_diseqc_send_burst(struct dvb_frontend *fe, |
Stefan Richter | 1549079 | 2009-02-23 14:21:10 +0100 | [diff] [blame] | 64 | fe_sec_mini_cmd_t minicmd) |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 65 | { |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | static int fdtv_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone) |
| 70 | { |
| 71 | struct firedtv *fdtv = fe->sec_priv; |
| 72 | |
| 73 | fdtv->tone = tone; |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | static int fdtv_set_voltage(struct dvb_frontend *fe, |
Stefan Richter | 1549079 | 2009-02-23 14:21:10 +0100 | [diff] [blame] | 78 | fe_sec_voltage_t voltage) |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 79 | { |
| 80 | struct firedtv *fdtv = fe->sec_priv; |
| 81 | |
| 82 | fdtv->voltage = voltage; |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | static int fdtv_read_status(struct dvb_frontend *fe, fe_status_t *status) |
| 87 | { |
| 88 | struct firedtv *fdtv = fe->sec_priv; |
Stefan Richter | 1549079 | 2009-02-23 14:21:10 +0100 | [diff] [blame] | 89 | struct firedtv_tuner_status stat; |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 90 | |
Stefan Richter | 1549079 | 2009-02-23 14:21:10 +0100 | [diff] [blame] | 91 | if (avc_tuner_status(fdtv, &stat)) |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 92 | return -EINVAL; |
| 93 | |
Stefan Richter | 1549079 | 2009-02-23 14:21:10 +0100 | [diff] [blame] | 94 | if (stat.no_rf) |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 95 | *status = 0; |
| 96 | else |
| 97 | *status = FE_HAS_SIGNAL | FE_HAS_VITERBI | FE_HAS_SYNC | |
| 98 | FE_HAS_CARRIER | FE_HAS_LOCK; |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | static int fdtv_read_ber(struct dvb_frontend *fe, u32 *ber) |
| 103 | { |
| 104 | struct firedtv *fdtv = fe->sec_priv; |
Stefan Richter | 1549079 | 2009-02-23 14:21:10 +0100 | [diff] [blame] | 105 | struct firedtv_tuner_status stat; |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 106 | |
Stefan Richter | 1549079 | 2009-02-23 14:21:10 +0100 | [diff] [blame] | 107 | if (avc_tuner_status(fdtv, &stat)) |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 108 | return -EINVAL; |
| 109 | |
Stefan Richter | 1549079 | 2009-02-23 14:21:10 +0100 | [diff] [blame] | 110 | *ber = stat.ber; |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 111 | return 0; |
| 112 | } |
| 113 | |
Stefan Richter | 1549079 | 2009-02-23 14:21:10 +0100 | [diff] [blame] | 114 | static int fdtv_read_signal_strength(struct dvb_frontend *fe, u16 *strength) |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 115 | { |
| 116 | struct firedtv *fdtv = fe->sec_priv; |
Stefan Richter | 1549079 | 2009-02-23 14:21:10 +0100 | [diff] [blame] | 117 | struct firedtv_tuner_status stat; |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 118 | |
Stefan Richter | 1549079 | 2009-02-23 14:21:10 +0100 | [diff] [blame] | 119 | if (avc_tuner_status(fdtv, &stat)) |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 120 | return -EINVAL; |
| 121 | |
Stefan Richter | 1549079 | 2009-02-23 14:21:10 +0100 | [diff] [blame] | 122 | *strength = stat.signal_strength << 8; |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | static int fdtv_read_snr(struct dvb_frontend *fe, u16 *snr) |
| 127 | { |
| 128 | struct firedtv *fdtv = fe->sec_priv; |
Stefan Richter | 1549079 | 2009-02-23 14:21:10 +0100 | [diff] [blame] | 129 | struct firedtv_tuner_status stat; |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 130 | |
Stefan Richter | 1549079 | 2009-02-23 14:21:10 +0100 | [diff] [blame] | 131 | if (avc_tuner_status(fdtv, &stat)) |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 132 | return -EINVAL; |
| 133 | |
| 134 | /* C/N[dB] = -10 * log10(snr / 65535) */ |
Stefan Richter | 1549079 | 2009-02-23 14:21:10 +0100 | [diff] [blame] | 135 | *snr = stat.carrier_noise_ratio * 257; |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 136 | return 0; |
| 137 | } |
| 138 | |
| 139 | static int fdtv_read_uncorrected_blocks(struct dvb_frontend *fe, u32 *ucblocks) |
| 140 | { |
| 141 | return -EOPNOTSUPP; |
| 142 | } |
| 143 | |
Stefan Richter | 1549079 | 2009-02-23 14:21:10 +0100 | [diff] [blame] | 144 | #define ACCEPTED 0x9 |
| 145 | |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 146 | static int fdtv_set_frontend(struct dvb_frontend *fe, |
Stefan Richter | 1549079 | 2009-02-23 14:21:10 +0100 | [diff] [blame] | 147 | struct dvb_frontend_parameters *params) |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 148 | { |
| 149 | struct firedtv *fdtv = fe->sec_priv; |
| 150 | |
| 151 | /* FIXME: avc_tuner_dsd never returns ACCEPTED. Check status? */ |
| 152 | if (avc_tuner_dsd(fdtv, params) != ACCEPTED) |
| 153 | return -EINVAL; |
| 154 | else |
| 155 | return 0; /* not sure of this... */ |
| 156 | } |
| 157 | |
| 158 | static int fdtv_get_frontend(struct dvb_frontend *fe, |
Stefan Richter | 1549079 | 2009-02-23 14:21:10 +0100 | [diff] [blame] | 159 | struct dvb_frontend_parameters *params) |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 160 | { |
| 161 | return -EOPNOTSUPP; |
| 162 | } |
| 163 | |
| 164 | void fdtv_frontend_init(struct firedtv *fdtv) |
| 165 | { |
| 166 | struct dvb_frontend_ops *ops = &fdtv->fe.ops; |
| 167 | struct dvb_frontend_info *fi = &ops->info; |
| 168 | |
| 169 | ops->init = fdtv_dvb_init; |
| 170 | ops->sleep = fdtv_sleep; |
| 171 | |
| 172 | ops->set_frontend = fdtv_set_frontend; |
| 173 | ops->get_frontend = fdtv_get_frontend; |
| 174 | |
| 175 | ops->read_status = fdtv_read_status; |
| 176 | ops->read_ber = fdtv_read_ber; |
| 177 | ops->read_signal_strength = fdtv_read_signal_strength; |
| 178 | ops->read_snr = fdtv_read_snr; |
| 179 | ops->read_ucblocks = fdtv_read_uncorrected_blocks; |
| 180 | |
| 181 | ops->diseqc_send_master_cmd = fdtv_diseqc_send_master_cmd; |
| 182 | ops->diseqc_send_burst = fdtv_diseqc_send_burst; |
| 183 | ops->set_tone = fdtv_set_tone; |
| 184 | ops->set_voltage = fdtv_set_voltage; |
| 185 | |
| 186 | switch (fdtv->type) { |
| 187 | case FIREDTV_DVB_S: |
Beat Michel Liechti | e73bf9f | 2009-02-24 15:52:49 +0100 | [diff] [blame] | 188 | case FIREDTV_DVB_S2: |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 189 | fi->type = FE_QPSK; |
| 190 | |
| 191 | fi->frequency_min = 950000; |
| 192 | fi->frequency_max = 2150000; |
| 193 | fi->frequency_stepsize = 125; |
| 194 | fi->symbol_rate_min = 1000000; |
| 195 | fi->symbol_rate_max = 40000000; |
| 196 | |
| 197 | fi->caps = FE_CAN_INVERSION_AUTO | |
| 198 | FE_CAN_FEC_1_2 | |
| 199 | FE_CAN_FEC_2_3 | |
| 200 | FE_CAN_FEC_3_4 | |
| 201 | FE_CAN_FEC_5_6 | |
| 202 | FE_CAN_FEC_7_8 | |
| 203 | FE_CAN_FEC_AUTO | |
| 204 | FE_CAN_QPSK; |
| 205 | break; |
| 206 | |
| 207 | case FIREDTV_DVB_C: |
| 208 | fi->type = FE_QAM; |
| 209 | |
| 210 | fi->frequency_min = 47000000; |
| 211 | fi->frequency_max = 866000000; |
| 212 | fi->frequency_stepsize = 62500; |
| 213 | fi->symbol_rate_min = 870000; |
| 214 | fi->symbol_rate_max = 6900000; |
| 215 | |
| 216 | fi->caps = FE_CAN_INVERSION_AUTO | |
| 217 | FE_CAN_QAM_16 | |
| 218 | FE_CAN_QAM_32 | |
| 219 | FE_CAN_QAM_64 | |
| 220 | FE_CAN_QAM_128 | |
| 221 | FE_CAN_QAM_256 | |
| 222 | FE_CAN_QAM_AUTO; |
| 223 | break; |
| 224 | |
| 225 | case FIREDTV_DVB_T: |
| 226 | fi->type = FE_OFDM; |
| 227 | |
| 228 | fi->frequency_min = 49000000; |
| 229 | fi->frequency_max = 861000000; |
| 230 | fi->frequency_stepsize = 62500; |
| 231 | |
| 232 | fi->caps = FE_CAN_INVERSION_AUTO | |
| 233 | FE_CAN_FEC_2_3 | |
| 234 | FE_CAN_TRANSMISSION_MODE_AUTO | |
| 235 | FE_CAN_GUARD_INTERVAL_AUTO | |
| 236 | FE_CAN_HIERARCHY_AUTO; |
| 237 | break; |
| 238 | |
| 239 | default: |
Stefan Richter | 1549079 | 2009-02-23 14:21:10 +0100 | [diff] [blame] | 240 | dev_err(fdtv->device, "no frontend for model type %d\n", |
| 241 | fdtv->type); |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 242 | } |
| 243 | strcpy(fi->name, fdtv_model_names[fdtv->type]); |
| 244 | |
| 245 | fdtv->fe.dvb = &fdtv->adapter; |
| 246 | fdtv->fe.sec_priv = fdtv; |
| 247 | } |