Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1 | /* |
| 2 | * DVB USB Linux driver for Afatech AF9015 DVB-T USB2.0 receiver |
| 3 | * |
| 4 | * Copyright (C) 2007 Antti Palosaari <crope@iki.fi> |
| 5 | * |
| 6 | * Thanks to Afatech who kindly provided information. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 21 | * |
| 22 | */ |
| 23 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 24 | #ifndef AF9015_H |
| 25 | #define AF9015_H |
| 26 | |
| 27 | #include <linux/hash.h> |
| 28 | #include "dvb_usb.h" |
| 29 | #include "af9013.h" |
| 30 | #include "dvb-pll.h" |
| 31 | #include "mt2060.h" |
| 32 | #include "qt1010.h" |
| 33 | #include "tda18271.h" |
| 34 | #include "mxl5005s.h" |
| 35 | #include "mc44s803.h" |
| 36 | #include "tda18218.h" |
| 37 | #include "mxl5007t.h" |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 38 | |
Antti Palosaari | bab9b4f | 2012-09-12 11:37:25 -0300 | [diff] [blame] | 39 | #define AF9015_FIRMWARE "dvb-usb-af9015.fw" |
| 40 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 41 | /* Windows driver uses packet count 21 for USB1.1 and 348 for USB2.0. |
| 42 | We use smaller - about 1/4 from the original, 5 and 87. */ |
| 43 | #define TS_PACKET_SIZE 188 |
| 44 | |
| 45 | #define TS_USB20_PACKET_COUNT 87 |
| 46 | #define TS_USB20_FRAME_SIZE (TS_PACKET_SIZE*TS_USB20_PACKET_COUNT) |
| 47 | |
| 48 | #define TS_USB11_PACKET_COUNT 5 |
| 49 | #define TS_USB11_FRAME_SIZE (TS_PACKET_SIZE*TS_USB11_PACKET_COUNT) |
| 50 | |
| 51 | #define TS_USB20_MAX_PACKET_SIZE 512 |
| 52 | #define TS_USB11_MAX_PACKET_SIZE 64 |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 53 | |
| 54 | #define AF9015_I2C_EEPROM 0xa0 |
| 55 | #define AF9015_I2C_DEMOD 0x38 |
| 56 | #define AF9015_USB_TIMEOUT 2000 |
| 57 | |
| 58 | /* EEPROM locations */ |
| 59 | #define AF9015_EEPROM_IR_MODE 0x18 |
| 60 | #define AF9015_EEPROM_IR_REMOTE_TYPE 0x34 |
| 61 | #define AF9015_EEPROM_TS_MODE 0x31 |
| 62 | #define AF9015_EEPROM_DEMOD2_I2C 0x32 |
| 63 | |
| 64 | #define AF9015_EEPROM_SAW_BW1 0x35 |
| 65 | #define AF9015_EEPROM_XTAL_TYPE1 0x36 |
| 66 | #define AF9015_EEPROM_SPEC_INV1 0x37 |
| 67 | #define AF9015_EEPROM_IF1L 0x38 |
| 68 | #define AF9015_EEPROM_IF1H 0x39 |
| 69 | #define AF9015_EEPROM_MT2060_IF1L 0x3a |
| 70 | #define AF9015_EEPROM_MT2060_IF1H 0x3b |
| 71 | #define AF9015_EEPROM_TUNER_ID1 0x3c |
| 72 | |
| 73 | #define AF9015_EEPROM_SAW_BW2 0x45 |
| 74 | #define AF9015_EEPROM_XTAL_TYPE2 0x46 |
| 75 | #define AF9015_EEPROM_SPEC_INV2 0x47 |
| 76 | #define AF9015_EEPROM_IF2L 0x48 |
| 77 | #define AF9015_EEPROM_IF2H 0x49 |
| 78 | #define AF9015_EEPROM_MT2060_IF2L 0x4a |
| 79 | #define AF9015_EEPROM_MT2060_IF2H 0x4b |
| 80 | #define AF9015_EEPROM_TUNER_ID2 0x4c |
| 81 | |
| 82 | #define AF9015_EEPROM_OFFSET (AF9015_EEPROM_SAW_BW2 - AF9015_EEPROM_SAW_BW1) |
| 83 | |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 84 | struct req_t { |
| 85 | u8 cmd; /* [0] */ |
| 86 | /* seq */ /* [1] */ |
| 87 | u8 i2c_addr; /* [2] */ |
| 88 | u16 addr; /* [3|4] */ |
| 89 | u8 mbox; /* [5] */ |
| 90 | u8 addr_len; /* [6] */ |
| 91 | u8 data_len; /* [7] */ |
| 92 | u8 *data; |
| 93 | }; |
| 94 | |
| 95 | enum af9015_cmd { |
| 96 | GET_CONFIG = 0x10, |
| 97 | DOWNLOAD_FIRMWARE = 0x11, |
| 98 | BOOT = 0x13, |
| 99 | READ_MEMORY = 0x20, |
| 100 | WRITE_MEMORY = 0x21, |
| 101 | READ_WRITE_I2C = 0x22, |
| 102 | COPY_FIRMWARE = 0x23, |
| 103 | RECONNECT_USB = 0x5a, |
| 104 | WRITE_VIRTUAL_MEMORY = 0x26, |
| 105 | GET_IR_CODE = 0x27, |
| 106 | READ_I2C, |
| 107 | WRITE_I2C, |
| 108 | }; |
| 109 | |
| 110 | enum af9015_ir_mode { |
| 111 | AF9015_IR_MODE_DISABLED = 0, |
| 112 | AF9015_IR_MODE_HID, |
| 113 | AF9015_IR_MODE_RLC, |
| 114 | AF9015_IR_MODE_RC6, |
Antti Palosaari | 0f01721 | 2009-09-21 21:26:37 -0300 | [diff] [blame] | 115 | AF9015_IR_MODE_POLLING, /* just guess */ |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 116 | }; |
| 117 | |
Antti Palosaari | aff8c2d | 2013-02-26 13:25:19 -0300 | [diff] [blame] | 118 | #define BUF_LEN 63 |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 119 | struct af9015_state { |
Antti Palosaari | aff8c2d | 2013-02-26 13:25:19 -0300 | [diff] [blame] | 120 | u8 buf[BUF_LEN]; /* bulk USB control message */ |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 121 | u8 ir_mode; |
Antti Palosaari | d3bb73d | 2010-09-12 13:31:56 -0300 | [diff] [blame] | 122 | u8 rc_repeat; |
Antti Palosaari | 1cd7278 | 2010-10-12 17:22:32 -0300 | [diff] [blame] | 123 | u32 rc_keycode; |
Ian Armstrong | c1e1397 | 2011-03-18 19:23:05 -0300 | [diff] [blame] | 124 | u8 rc_last[4]; |
Antti Palosaari | eb29fbe | 2012-07-24 21:21:04 -0300 | [diff] [blame] | 125 | bool rc_failed; |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 126 | u8 dual_mode; |
| 127 | u8 seq; /* packet sequence number */ |
| 128 | u16 mt2060_if1[2]; |
| 129 | u16 firmware_size; |
| 130 | u16 firmware_checksum; |
| 131 | u32 eeprom_sum; |
| 132 | struct af9013_config af9013_config[2]; |
Antti Palosaari | e90ab84 | 2011-11-12 22:33:30 -0300 | [diff] [blame] | 133 | |
| 134 | /* for demod callback override */ |
Mauro Carvalho Chehab | 0009e0e | 2011-12-31 07:03:36 -0300 | [diff] [blame] | 135 | int (*set_frontend[2]) (struct dvb_frontend *fe); |
Antti Palosaari | e90ab84 | 2011-11-12 22:33:30 -0300 | [diff] [blame] | 136 | int (*read_status[2]) (struct dvb_frontend *fe, fe_status_t *status); |
| 137 | int (*init[2]) (struct dvb_frontend *fe); |
| 138 | int (*sleep[2]) (struct dvb_frontend *fe); |
Antti Palosaari | 6d535bd | 2012-03-14 10:27:31 -0300 | [diff] [blame] | 139 | int (*tuner_init[2]) (struct dvb_frontend *fe); |
| 140 | int (*tuner_sleep[2]) (struct dvb_frontend *fe); |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 141 | struct mutex fe_mutex; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | enum af9015_remote { |
| 145 | AF9015_REMOTE_NONE = 0, |
Marc Schneider | 2614484 | 2009-03-26 21:07:18 -0300 | [diff] [blame] | 146 | /* 1 */ AF9015_REMOTE_A_LINK_DTU_M, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 147 | AF9015_REMOTE_MSI_DIGIVOX_MINI_II_V3, |
| 148 | AF9015_REMOTE_MYGICTV_U718, |
Alain Kalker | 0537156 | 2008-11-17 17:20:38 -0300 | [diff] [blame] | 149 | AF9015_REMOTE_DIGITTRADE_DVB_T, |
Marc Schneider | 2614484 | 2009-03-26 21:07:18 -0300 | [diff] [blame] | 150 | /* 5 */ AF9015_REMOTE_AVERMEDIA_KS, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 151 | }; |
| 152 | |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 153 | #endif |