2 * DVB USB Linux driver for Afatech AF9015 DVB-T USB2.0 receiver
4 * Copyright (C) 2007 Antti Palosaari <crope@iki.fi>
6 * Thanks to Afatech who kindly provided information.
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.
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.
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.
27 #include <linux/hash.h>
39 #define DVB_USB_LOG_PREFIX "af9015"
41 #ifdef CONFIG_DVB_USB_DEBUG
42 #define dprintk(var, level, args...) \
43 do { if ((var & level)) printk(args); } while (0)
44 #define DVB_USB_DEBUG_STATUS
46 #define dprintk(args...)
47 #define DVB_USB_DEBUG_STATUS " (debugging is not enabled)"
50 #define deb_info(args...) dprintk(dvb_usb_af9015_debug, 0x01, args)
51 #define deb_rc(args...) dprintk(dvb_usb_af9015_debug, 0x02, args)
54 #define err(format, arg...) \
55 printk(KERN_ERR DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
57 #define warn(format, arg...) \
58 printk(KERN_WARNING DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
60 /* Windows driver uses packet count 21 for USB1.1 and 348 for USB2.0.
61 We use smaller - about 1/4 from the original, 5 and 87. */
62 #define TS_PACKET_SIZE 188
64 #define TS_USB20_PACKET_COUNT 87
65 #define TS_USB20_FRAME_SIZE (TS_PACKET_SIZE*TS_USB20_PACKET_COUNT)
67 #define TS_USB11_PACKET_COUNT 5
68 #define TS_USB11_FRAME_SIZE (TS_PACKET_SIZE*TS_USB11_PACKET_COUNT)
70 #define TS_USB20_MAX_PACKET_SIZE 512
71 #define TS_USB11_MAX_PACKET_SIZE 64
73 #define AF9015_I2C_EEPROM 0xa0
74 #define AF9015_I2C_DEMOD 0x38
75 #define AF9015_USB_TIMEOUT 2000
77 /* EEPROM locations */
78 #define AF9015_EEPROM_IR_MODE 0x18
79 #define AF9015_EEPROM_IR_REMOTE_TYPE 0x34
80 #define AF9015_EEPROM_TS_MODE 0x31
81 #define AF9015_EEPROM_DEMOD2_I2C 0x32
83 #define AF9015_EEPROM_SAW_BW1 0x35
84 #define AF9015_EEPROM_XTAL_TYPE1 0x36
85 #define AF9015_EEPROM_SPEC_INV1 0x37
86 #define AF9015_EEPROM_IF1L 0x38
87 #define AF9015_EEPROM_IF1H 0x39
88 #define AF9015_EEPROM_MT2060_IF1L 0x3a
89 #define AF9015_EEPROM_MT2060_IF1H 0x3b
90 #define AF9015_EEPROM_TUNER_ID1 0x3c
92 #define AF9015_EEPROM_SAW_BW2 0x45
93 #define AF9015_EEPROM_XTAL_TYPE2 0x46
94 #define AF9015_EEPROM_SPEC_INV2 0x47
95 #define AF9015_EEPROM_IF2L 0x48
96 #define AF9015_EEPROM_IF2H 0x49
97 #define AF9015_EEPROM_MT2060_IF2L 0x4a
98 #define AF9015_EEPROM_MT2060_IF2H 0x4b
99 #define AF9015_EEPROM_TUNER_ID2 0x4c
101 #define AF9015_EEPROM_OFFSET (AF9015_EEPROM_SAW_BW2 - AF9015_EEPROM_SAW_BW1)
106 u8 i2c_addr
; /* [2] */
107 u16 addr
; /* [3|4] */
109 u8 addr_len
; /* [6] */
110 u8 data_len
; /* [7] */
116 DOWNLOAD_FIRMWARE
= 0x11,
120 READ_WRITE_I2C
= 0x22,
121 COPY_FIRMWARE
= 0x23,
122 RECONNECT_USB
= 0x5a,
123 WRITE_VIRTUAL_MEMORY
= 0x26,
129 enum af9015_ir_mode
{
130 AF9015_IR_MODE_DISABLED
= 0,
134 AF9015_IR_MODE_POLLING
, /* just guess */
137 struct af9015_state
{
143 u8 seq
; /* packet sequence number */
146 u16 firmware_checksum
;
148 struct af9013_config af9013_config
[2];
150 /* for demod callback override */
151 int (*set_frontend
[2]) (struct dvb_frontend
*fe
);
152 int (*read_status
[2]) (struct dvb_frontend
*fe
, fe_status_t
*status
);
153 int (*init
[2]) (struct dvb_frontend
*fe
);
154 int (*sleep
[2]) (struct dvb_frontend
*fe
);
155 int (*tuner_init
[2]) (struct dvb_frontend
*fe
);
156 int (*tuner_sleep
[2]) (struct dvb_frontend
*fe
);
157 struct mutex fe_mutex
;
161 AF9015_REMOTE_NONE
= 0,
162 /* 1 */ AF9015_REMOTE_A_LINK_DTU_M
,
163 AF9015_REMOTE_MSI_DIGIVOX_MINI_II_V3
,
164 AF9015_REMOTE_MYGICTV_U718
,
165 AF9015_REMOTE_DIGITTRADE_DVB_T
,
166 /* 5 */ AF9015_REMOTE_AVERMEDIA_KS
,