74d98dfb5ae74615d1c933cf382c3d07f62c2ed1
[linux-2.6.git] / drivers / media / dvb / dvb-usb / dib0700_devices.c
1 /* Linux driver for devices based on the DiBcom DiB0700 USB bridge
2  *
3  *      This program is free software; you can redistribute it and/or modify it
4  *      under the terms of the GNU General Public License as published by the Free
5  *      Software Foundation, version 2.
6  *
7  *  Copyright (C) 2005-6 DiBcom, SA
8  */
9 #include "dib0700.h"
10
11 #include "dib3000mc.h"
12 #include "dib7000m.h"
13 #include "mt2060.h"
14
15 /* Hauppauge Nova-T 500
16  *  has a LNA on GPIO0 which is enabled by setting 1 */
17 static struct mt2060_config bristol_mt2060_config[2] = {
18         {
19                 .i2c_address = 0x60,
20                 .clock_out   = 1,
21         }, {
22                 .i2c_address = 0x61,
23         }
24 };
25
26 static struct dibx000_agc_config bristol_dib3000p_mt2060_agc_config = {
27         .band_caps = BAND_VHF | BAND_UHF,
28         .setup     = (0 << 15) | (0 << 14) | (1 << 13) | (1 << 12) | (29 << 0),
29
30         .agc1_max = 48497,
31         .agc1_min = 23593,
32         .agc2_max = 46531,
33         .agc2_min = 24904,
34
35         .agc1_pt1 = 0x65,
36         .agc1_pt2 = 0x69,
37
38         .agc1_slope1 = 0x51,
39         .agc1_slope2 = 0x27,
40
41         .agc2_pt1 = 0,
42         .agc2_pt2 = 0x33,
43
44         .agc2_slope1 = 0x35,
45         .agc2_slope2 = 0x37,
46 };
47
48 static struct dib3000mc_config bristol_dib3000mc_config[2] = {
49         {       .agc          = &bristol_dib3000p_mt2060_agc_config,
50                 .max_time     = 0x196,
51                 .ln_adc_level = 0x1cc7,
52                 .output_mpeg2_in_188_bytes = 1,
53         },
54         {       .agc          = &bristol_dib3000p_mt2060_agc_config,
55                 .max_time     = 0x196,
56                 .ln_adc_level = 0x1cc7,
57                 .output_mpeg2_in_188_bytes = 1,
58         }
59 };
60
61 static int bristol_frontend_attach(struct dvb_usb_adapter *adap)
62 {
63         if (adap->id == 0) {
64                 dib0700_set_gpio(adap->dev, GPIO6,  GPIO_OUT, 0); msleep(10);
65                 dib0700_set_gpio(adap->dev, GPIO6,  GPIO_OUT, 1); msleep(10);
66                 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0); msleep(10);
67                 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1); msleep(10);
68
69                 if (dib3000mc_i2c_enumeration(&adap->dev->i2c_adap, 2, DEFAULT_DIB3000P_I2C_ADDRESS, bristol_dib3000mc_config) != 0) {
70                         dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0); msleep(10);
71                         return -ENODEV;
72                 }
73         }
74         return (adap->fe = dvb_attach(dib3000mc_attach, &adap->dev->i2c_adap, 10 + adap->id, &bristol_dib3000mc_config[adap->id])) == NULL ? -ENODEV : 0;
75 }
76
77 static int bristol_tuner_attach(struct dvb_usb_adapter *adap)
78 {
79         struct dib0700_state *st = adap->dev->priv;
80         struct i2c_adapter *tun_i2c = dib3000mc_get_tuner_i2c_master(adap->fe, 1);
81         return mt2060_attach(adap->fe, tun_i2c, &bristol_mt2060_config[adap->id], st->mt2060_if1[adap->id]);
82 }
83
84 /* STK7700P: Hauppauge Nova-T Stick, AVerMedia Volar */
85 static struct mt2060_config stk7000p_mt2060_config = {
86         0x60
87 };
88
89 static int stk7700p_frontend_attach(struct dvb_usb_adapter *adap)
90 {
91         /* unless there is no real power management in DVB - we leave the device on GPIO6 */
92         dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0); msleep(10);
93         dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1); msleep(10);
94         dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1); msleep(10);
95         dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0); msleep(10);
96
97 //      adap->fe = dib7000m_attach(&adap->dev->i2c_adap, &stk7700p_dib7000m_config, 18);
98         return 0;
99 }
100
101 static int stk7700p_tuner_attach(struct dvb_usb_adapter *adap)
102 {
103 //      tun_i2c = dib7000m_get_tuner_i2c_master(adap->fe, 1);
104 //      return mt2060_attach(adap->fe, tun_i2c, &stk3000p_mt2060_config, if1);
105         return 0;
106 }
107
108 struct usb_device_id dib0700_usb_id_table[] = {
109                 { USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_STK7700P) },
110                 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_500) },
111                 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_STICK) },
112                 { USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR) },
113                 { }             /* Terminating entry */
114 };
115 MODULE_DEVICE_TABLE(usb, dib0700_usb_id_table);
116
117 #define DIB0700_DEFAULT_DEVICE_PROPERTIES \
118         .caps              = DVB_USB_IS_AN_I2C_ADAPTER, \
119         .usb_ctrl          = DEVICE_SPECIFIC, \
120         .firmware          = "dvb-usb-dib0700-01.fw", \
121         .download_firmware = dib0700_download_firmware, \
122         .size_of_priv      = sizeof(struct dib0700_state), \
123         .i2c_algo          = &dib0700_i2c_algo
124
125 #define DIB0700_DEFAULT_STREAMING_CONFIG(ep) \
126         .streaming_ctrl   = dib0700_streaming_ctrl, \
127         .stream = { \
128                 .type = USB_BULK, \
129                 .count = 4, \
130                 .endpoint = ep, \
131                 .u = { \
132                         .bulk = { \
133                                 .buffersize = 39480, \
134                         } \
135                 } \
136         }
137
138 struct dvb_usb_device_properties dib0700_devices[] = {
139         {
140                 DIB0700_DEFAULT_DEVICE_PROPERTIES,
141
142                 .num_adapters = 1,
143                 .adapter = {
144                         {
145                                 .frontend_attach  = stk7700p_frontend_attach,
146                                 .tuner_attach     = stk7700p_tuner_attach,
147
148                                 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
149                         },
150                 },
151
152                 .num_device_descs = 3,
153                 .devices = {
154                         {   "DiBcom STK7700P reference design",
155                                 { &dib0700_usb_id_table[0], NULL },
156                                 { NULL },
157                         },
158                         {   "Hauppauge Nova-T Stick",
159                                 { &dib0700_usb_id_table[2], NULL },
160                                 { NULL },
161                         },
162                         {   "AVerMedia AVerTV DVB-T Volar",
163                                 { &dib0700_usb_id_table[3], NULL },
164                                 { NULL },
165                         },
166                 }
167         }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
168
169                 .num_adapters = 2,
170                 .adapter = {
171                         {
172                                 .frontend_attach  = bristol_frontend_attach,
173                                 .tuner_attach     = bristol_tuner_attach,
174
175                                 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
176                         }, {
177                                 .frontend_attach  = bristol_frontend_attach,
178                                 .tuner_attach     = bristol_tuner_attach,
179
180                                 DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
181                         }
182                 },
183
184                 .num_device_descs = 1,
185                 .devices = {
186                         {   "Hauppauge Nova-T 500 Dual DVB-T",
187                                 { &dib0700_usb_id_table[1], NULL },
188                                 { NULL },
189                         },
190                 }
191         }
192 };
193
194 int dib0700_device_count = ARRAY_SIZE(dib0700_devices);